Refactor hw descriptors to be clearer #17

Closed
dave2 opened this Issue May 27, 2014 · 0 comments

1 participant

@dave2
Owner

The current hardware descriptors are just a numeric index. This makes it non-obvious how they are mapped into actual hardware. This also goes against the general library philosophy of not trying to hide the fact the hardware has names.

Descriptors should be based on the actual hardware names instead. It needs to be efficient in how the reverse map works, however, since the reverse map will end up being called from ISRs frequently.

Suggested approach is:

  • Define a enum type which has similar hardware names to actual hardware.
  • Use enum as the index into the array of hardware structs

For example, for usarts, the concept might be:

typedef struct {
 usart_c0 = 0, /* First usart port */
 usart_d0,
} usart_portname_t;

Then these are passed as arguments instead of numbers, so usart_conf becomes..

usart_conf(usart_d0,9600,8,none,1,0,NULL); /* configure D0 usart */

The ISR can then call the generic handler like this:

ISR(USARTD0_RXC_vect) {
 _usart_rx(ports[usart_d0]); 
}

Because this will resolve to the correct entry in the array of port structs.

To protect the definitions on multiple different xmega chips, we only need to test for the presence of the hardware:

#ifdef USARTD0
/* we have a USARTD0 on this hardware, support it */
#endif  

And we can do the same for ISRs. The chip support then only needs to define the usart_portname_t for each xmega case.

@dave2 dave2 closed this in 9d74286 May 28, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment