Part Number: TMS320F280049
Other Parts Discussed in Thread: C2000WARE
I just got a F280049 control card and was starting to tinker with the epwm_ex2_updown_aq driverlib project that came with C2000Ware. In it I find that configuration of the peripherals is handled via nice API functions provided in epwm.h. For example to change the TBP register I can use:
static inline void EPWM_setTimeBasePeriod(uint32_t base, uint16_t periodCount)
{
ASSERT(EPWM_isBaseValid(base));
// write to TBPRD bit
HWREGH(base + EPWM_O_TBPRD) = periodCount;
}
But the way the peripheral registers are accessed is very bizarre. I'm used to peripherals being mapped into structures, and having various typedefs for bitfields and so on. But now all I see is HWREG(base+register) everywhere and it feels very... clumsy.
A more severe example:
static inline void EPWM_setActionQualifierShadowLoadMode(uint32_t base,
EPWM_ActionQualifierModule aqModule,
EPWM_ActionQualifierLoadMode loadMode)
{
uint16_t syncModeOffset;
uint16_t shadowModeOffset;
syncModeOffset = 8U + (uint16_t)aqModule;
shadowModeOffset = 4U + (uint16_t)aqModule;
// Set the appropriate sync and load mode bits and also enable shadow
// load mode. Shadow to active load can also be frozen.
HWREGH(base + EPWM_O_AQCTL) = ((HWREGH(base + EPWM_O_AQCTL) &
(~((0x3U << (uint16_t)aqModule) | // Clear AQ mode selection
(0x3U << (uint16_t)syncModeOffset))) | // Clear Sync mode
(0x1U << shadowModeOffset)) | // Enable Shadow mode
((((uint16_t)loadMode >> 2U) << syncModeOffset) | // sync mode
(((uint16_t)loadMode & 0x3U) << (uint16_t)aqModule))); // AQ mode
}
I'm sure that when used properly, these functions compile fine, but there are times when I'd rather bypass these functions and access a register directly. It would usually look something like this:
EPwm1Regs.TBPRD = 600; // Period = 601 TBCLK counts EPwm1Regs.CMPA.half.CMPA = 350; // Compare A = 350 TBCLK counts EPwm1Regs.CMPB = 200; // Compare B = 200 TBCLK counts EPwm1Regs.TBPHS = 0; // Set Phase register to zero EPwm1Regs.TBCTR = 0; // clear TB counter
In fact, that code came straight from a TI document on the piccolo ePWM. But it doesn't compile when I add it to my project, since those structures are not defined. Did I miss something?
Basically I'm asking the same question as in this thread, but with less snark.