Hi, Trying to set up a multi dimensional array to act as a circular buffer. Will copy 8 databytes into the array and increment a write_counter. Then in different module when it comes around to service the buffer it processes each entry until the read_counter == the write counter. My code is below; PRL.c code
#define CMD_RXBUFFER_SIZE 10 //how many entries in my buffer #define CMD_RXBUFFER_WIDTH 8 //ie 8 bytes wide . . unsigned char cmd_rxbuffer[CMD_RXBUFFER_SIZE][CMD_RXBUFFER_WIDTH]; //ie from 0-->49 deep, 8 wide unsigned char rxbuff_write = 0; unsigned char rxbuff_read = 0; . . //then in a function: rxbuff_write = rxbuff_write + 1; //add 1 to current write counter if (rxbuff_write==CMD_RXBUFFER_SIZE) //dont try to allocate data to a non existent array entry { rxbuff_write=0; } memcpy(&(cmd_rxbuffer[rxbuff_write][0]),&DLL_Rx_Buffer.databytes[1],7); //copy the received data to the next available buffer
extern unsigned char cmd_rxbuffer[CMD_RXBUFFER_SIZE][CMD_RXBUFFER_WIDTH]; extern unsigned char rxbuff_read; extern unsigned char rxbuff_write; unsigned char TestData; . . . //then in a function: while (rxbuff_read != rxbuff_write) { rxbuff_read = rxbuff_read + 1; if (rxbuff_read == CMD_RXBUFFER_SIZE) {rxbuff_read=0;} TestData = cmd_rxbuffer[rxbuff_read][0];
rxbuff_write=3;
memcpy(&(cmd_rxbuffer[3][0]),&DLL_Rx_Buffer.databytes[1],7);
memcpy(&(cmd_rxbuffer[rxbuff_write][0]),&DLL_Rx_Buffer.databytes[1],7);