Mplab C30 Compiler Direct

// 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;

// ------------------------------------------------------------ // 1. SAFE BANKING MACROS (avoid manual BANKED/FAR typos) // ------------------------------------------------------------ #define BANKED_NEAR ((near)) // Accessible without PSV #define BANKED_FAR attribute ((far)) // Any RAM, slower access #define Y_DATA_SPACE attribute ((space(ymemory))) // For DSP #define AUTO_PSV attribute ((space(auto_psv))) // const in program memory mplab c30 compiler

// ------------------------------------------------------------ // 3. ISR MACRO (fixes C30's verbose/error-prone vector syntax) // ------------------------------------------------------------ #define INTERRUPT(vector, priority) void ((interrupt, auto_psv)) _ ## vector (void) // Initialize (buffer must be 2^N, ideally in

// Usage: INTERRUPT(_U1RXInterrupt, 6) /* code */ // Initialize (buffer must be 2^N

#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;