struct DISK_REGISTER {
unsigned ready:1;
unsigned error_occured:1;
unsigned disk_spinning:1;
unsigned write_protect:1;
unsigned head_loaded:1;
unsigned error_code:8;
unsigned track:9;
unsigned sector:5; // 27 bits
unsigned command:5;
};
struct DISK_REGISTER *disk_reg;
void main(void)
{
char new_sector=2, new_track=3, READ=4, readOut=0;
while(1)
{
/* Define sector and track to start read */
disk_reg->sector = new_sector;
disk_reg->track = new_track;
disk_reg->command = READ; // !!!!?
/* wait until operation done, ready will be true */
while ( ! disk_reg->ready ) ;
/* check for errors */
if (disk_reg->error_occured)
{ /* interrogate disk_reg->error_code for error type */
//switch (disk_reg->error_code)
//......
}
}
}
Sorry, what you mean? I couldn't understand... can you show me example?A.Anand Srinivasan said:so you better allocate some memory and initialise it and then try again.....
Ya, the article also show this code but when i put this instruction the compiler will show error?A.Anand Srinivasan said:struct DISK_REGISTER *disk_reg= (struct DISK_REGISTER *) record;
struct DISK_REGISTER {
unsigned ready:1;
unsigned error_occured:1;
unsigned disk_spinning:1;
unsigned write_protect:1;
unsigned head_loaded:1;
unsigned error_code:8;
unsigned track:9;
unsigned sector:5; // 27 bits
unsigned command:5;
};
//struct DISK_REGISTER *disk_reg = (struct DISK_REGISTER *) DISK_REGISTER_MEMORY;
struct DISK_REGISTER *disk_reg = (struct DISK_REGISTER *) record;
struct DISK_REGISTER {
unsigned ready:1;
unsigned error_occured:1;
unsigned disk_spinning:1;
unsigned write_protect:1;
unsigned head_loaded:1;
unsigned error_code:8;
unsigned track:9;
unsigned sector:5; // 27 bits
unsigned command:5;
}record;
record DISK_REGISTER_MEMORY;
record *disk_reg = (record *) DISK_REGISTER_MEMORY;
vinseth said:Hi
record *disk_reg = (record *) DISK_REGISTER_MEMORY;
Should be in the main() function.
You need a executble part to allocate memory.
vinseth said:Yeah,the main can access it.You declare the variable outside main and should define(you create memory) it inside main.
By doing the following,I am defining a gloabl variable.
record *disk_reg = (record *) DISK_REGISTER_MEMORY;
struct packed_struct {
unsigned int f1:1;
unsigned int f2:1;
unsigned int f3:1;
unsigned int f4:1;
unsigned int type:4;
unsigned int funny_int:9;
unsigned int normal_int:8;
}
struct result {
signed char paper1;
signed char paper2;
signed char paper3;
};
struct result fileA = { 100, 98, 39 };
struct result fileB = { 70, 60, 40 };
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?