jlh@loral.UUCP (Jim Vaxkiller) (11/04/86)
Is there a 'good' way to map C to hardware? Some specific examples are: 1) In my hardware both pointers and ints are 16 bits. I'm setting up data structures to be traversed by microcode and whether it's a pointer or data depends on where it is and how the microcode got there. The way I'm doing it now is typedef union { int *ptr; /* might be a pointer */ int data; /* but then again, could be data */ } bsptr; /* be nice, it's bit slice pointer */ 2) How about mapping bit fields into words? For example, I have typedef struct { cmd : 5; /* command word, bits 15-11 */ type : 1; /* xmit/receive, bit 10 */ subaddr : 5; /* subaddress, bits 9-5 */ words : 5; /* word count, bits 4-0 */ } data1553; The individual fields MUST be in the bits specified. I could just OR the data into the word but it would be 'cleaner' to use bit fields. 3) There are instances where I have 2 eight bit datums and I need to store them together in 1 16 bit word. Now I do a *stash = (word) (hibyte << 8) + (lobyte & 0xf); Is there a better way? Also, I have some 16 bit counters and need to be sure the data is stored with the hi byte in bits 15-8. 4) I have some 32 bit counters that need to be stored with bits 31-16 in one word, then bits 15-0 in the next word. Now I have a union, one entry being a long and the other 2 ints. Byte ordering is very important here, see the previous question. Probably the most important thing here is the results must be portable. I'll probably write and debug most of it on a PC clone and VAX, then download it into the actual hardware. The target microprocessor is a 68010, which gives 3 widely differing architectures I need to work in. Also, we may change compilers sometime down the road. Please don't flame my syntax, I don't use typedefs and bit fields every day and don't feel like digging out my K&R book.