Using eCos on AT91SAM7 family processors has generally been a positive experience, however, the absence of some important functionalities can be somewhat of a problem. One of the most striking deficiencies of eCos is the lack of an interrupt-based driver for I²C, a popular bus used especially with various sensor chips. As we had to devise such a driver in one of our projects, we publish it below. The code can be used for the eCos userspace application on both SAM7X and SAM7S and, after some modification, can successfully be used seperately from the eCos platform.
The code is released on the BSD license. We appreciate any remarks!
First we have to declare a few variables – mutex and flag handles, and some buffer structures:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | // rx_tx_struct typedef struct { cyg_int16 len; cyg_uint16 index; char *buffer; } I2C_RX_TX_STRUCT; I2C_RX_TX_STRUCT rx_data_struct, tx_data_struct; // handles, flags, mutexes cyg_flag_t rxrdy_flag; cyg_flag_t txrdy_flag; cyg_flag_t txcomp_flag; cyg_flag_t done_flag; cyg_handle_t hIntr; cyg_interrupt intr; cyg_mutex_t twi_mutex; |