Mplab C30 Compiler | Cross-Platform |

*data = cb->buffer[cb->tail]; cb->tail = (cb->tail + 1) & cb->mask; return 0;

// Usage: INTERRUPT(_U1RXInterrupt, 6) /* code */

cb->buffer[cb->head] = data; cb->head = next_head; return 0; mplab c30 compiler

// Example: MAC with saturation inline int mac_saturate(int acc, int a, int b) acc += a * b; if (acc > 32767) acc = 32767; if (acc < -32768) acc = -32768; return acc;

int main() init_uart_buffer(); unsigned char ch; while (1) if (c30_cbuf_get(&uart_rx, &ch) == 0) // process byte *data = cb-&gt

#endif // C30_UTILS_H #include "c30_utils.h" // Force buffer into Y data space for faster DSP-style UART processing unsigned char Y_DATA_SPACE uart_rx_buf[64]; // 64 bytes, must be power of two c30_cbuf_t uart_rx;

// Interrupt-safe put (disables interrupts) inline int c30_cbuf_put(c30_cbuf_t *cb, unsigned char data) unsigned int next_head = (cb->head + 1) & cb->mask; if (next_head == cb->tail) return -1; // full tail = (cb-&gt

// Initialize (buffer must be 2^N, ideally in Y data space) void c30_cbuf_init(c30_cbuf_t *cb, unsigned char *buf, unsigned int size) cb->head = 0; cb->tail = 0; cb->mask = size - 1; cb->buffer = buf; cb->len = size;