ruben_saz wrote on Saturday, April 03, 2010:
Well richard, I’ve implemented a I2C routine that handles reading or writing a block of N bytes of data, it has the following prototype:
unsigned int iI2CDriverTransaction( xI2CHandle xI2CResources, unsigned int iDevAddress, unsigned int iMemAddress, unsigned int iBusDirection, unsigned int iBytesToTransfer, void * pvDataBuffer )
I don’t know if that’s what you mean with the mailbox. This function basically takes a mutex, writes data to a structure (which is used by a Finite State Machine running on the I2C ISR), and generates a interrupt which causes a FSM to start working. Then the function(task) blocks and waits for a message from the ISR on what I called a ‘‘Control Queue’’. This message contains a code indicating what happened inside the FSM. When the message arrives from the ISR, the function gives back the mutex and returns with the code received from the control Queue. If data was successfully read or written this function returns E_SUCCESS, other codes are also provided, for example E_ERROR_NACK indicates that master did not received ACK from the given slave address.
What I’m trying to do now is to implement a layer of compatibility that allows me to use the MPFS(microchip file system) that is used in the TCP/IP stack and other application notes from Microchip. The TCP/IP stack I’m using includes files for SPI and I2C interface with eeprom memories. In the i2ceeprom.c file I find functions like this:
static unsigned char getcI2C( void )
I2C2CONbits.RCEN = 1; // enable master for 1 byte reception
while(I2C2CONbits.RCEN); // wait until byte received
return I2C2RCV; // return with read byte
Here for example, I’m looking for a way to replace this with a function that uses the Rtos to do something usefull instead of just checking the RCEN bit (with the bus at 400 Khz this may be too much wasted time). As we intend to receive only a byte at a time, a large queue doesn’t makes sense. But for TX a large queue would be, in theory OK. I’m still wondering how to do this and I thought that I could use a single queue for TX and RX, so the question.
Well, those are some random thoughts, of what I’m trying to do. If anyone has worked with anything similar or know about a embedded filesystem for use in small eeprom or flash memories, or have some comments, it would be cool. Meanwhile I’ll be checking in detail the MPFS implementation.
Thank you guys, have a nice day!