Below is a : a set of preprocessor macros and helper functions that significantly improve C30’s usability without modifying the compiler itself.
// ------------------------------------------------------------ // 2. CIRCULAR BUFFER (with DMA/DSP-friendly alignment) // ------------------------------------------------------------ typedef struct volatile unsigned int head; volatile unsigned int tail; unsigned int mask; // size-1, must be power of two unsigned char Y_DATA_SPACE *buffer; // force Y-space for DSP unsigned int len; c30_cbuf_t; mplab c30 compiler
| Problem in C30 | This feature solves it | |----------------|------------------------| | Manual bank selection leads to random PSV errors | BANKED_NEAR / BANKED_FAR macros clarify intent | | DSP circular buffers require tedious __builtin_mod setup | c30_cbuf_t uses simple bitmask, works with any Y_DATA_SPACE buffer | | ISR vector names differ across devices (e.g., _U1RXInterrupt vs _U1ErrInterrupt ) | INTERRUPT() macro hides the underscore + auto_psv requirement | | No saturated arithmetic for Q15 | mac_saturate() mimics dsPIC’s optional saturation mode | Below is a : a set of preprocessor