I’m not very experienced with ARM7 and am using the YAGARTO toolchain. I’m looking for some tips on creating a circular data buffer to store parallel data (8 bit) being read off the PIO that needs to be sent out RS232 on UART0.
I’m using the AT91SAM7S64 with 16,384 bytes of ram, of which I would like to use as much as possible as a buffer. If i’m not mistaken, RAM starts at 0x00200000 and ends at 0x00204000. In looking at the main.map file from the program I have already constructed the _end = . is 0x0020001c. Can a buffer safely be constructed after this address to the last ram address?
Also, what’s the best way to write a circular buffer in C? Thanks for any help!
/* Queue structure */
typedef struct {
/** Pointer to the queue buffer (base).*/
uint8_t *q_buffer;
/** Pointer to the first location after the buffer (top).*/
uint8_t *q_top;
/** Write pointer.*/
uint8_t *q_wrptr;
/** Read pointer.*/
uint8_t *q_rdptr;
/** Counter, number of bytes in the queue.*/
uint32_t q_cnt;
} Queue;
If you want to see the full code you can follow the link in my signature, look into the chqueues.c file. Probably you will not need all of it but you can use it as a starting point.
Thanks for the replies. I forgot about not having to address the buffer, i’m used to ASM . One thing I did notice thought, is I can make the buffer larger that the available RAM and there is no error generated.
The best way to make a circular buffer is to make it’s size a power of two, so you don’t have to test for overflow at all. Here’s my implementation; I use only 16 bytes buffer here (it’s the AVR implementation) but the principle is the same for bigger ones.