I am using the following bit-field definition for Timer A1 control register
typedef struct
{
unsigned int iflag: 1; // interrupt flag
unsigned int ie: 1; // interrupt enable
unsigned int clr: 1; // clears count
unsigned int bit3: 1; // unused
unsigned int mode: 2; // mode
unsigned int ckdiv: 2; // input divider
unsigned int cksrc: 2; // clock source
unsigned int unused: 6; // not used
}ta1ctl_reg_t;
I also have the following definition:
extern volatile ta1cctl0_reg_t ta1cctl0;
I then initialize it as follows:
static void timera1_init(void)
{
ta1ccr0 = 32768; /* start timer counting (1s timer) */
ta1ctl.cksrc = TA_ACLK; /* set timer source */
ta1ctl.ckdiv = DIV_BY_1; /* set divisor */
ta1ctl.mode = UP; /* set mode */
ta1cctl0.ie = true; /* set interrupt enable */
}
given the following definitions:
enum{STOP, UP, CONTINUOUS, UPDOWN};
enum{TA_xCLK, TA_ACLK, TA_SMCLK, TA_TAxCLK_};
enum{DIV_BY_1, DIV_BY_2, DIV_BY_4, DIV_BY_8};
The bug that I found is the following.
- With no optimization turned on, the compiler produces the following output:
MOV.W #0x8000,&Timer1_A3_TA1CCR0
MOV.W #0x00fc,R15
AND.B &0x0381,R15
BIS.B #1,R15
MOV.B R15,&0x0381
AND.B #0x003f,&Timer1_A3_TA1CTL
MOV.W #0x00cf,R15
AND.B &Timer1_A3_TA1CTL,R15
BIS.B #0x0010,R15
MOV.B R15,&Timer1_A3_TA1CTL
MOV.W #0x00ef,R15
AND.B &Timer1_A3_TA1CCTL0,R15
BIS.B #0x0010,R15
MOV.B R15,&Timer1_A3_TA1CCTL0
RETA
- With optimization turned to 1 and optimize for speed set to 5 the compiler produces the following output:
MOV.W #0x8000,&Timer1_A3_TA1CCR0
MOV.W #0xfdff,R15
AND.W &Timer1_A3_TA1CTL,R15
BIS.W #0x0100,R15
MOV.W R15,&Timer1_A3_TA1CTL
AND.W #0xff3f,&Timer1_A3_TA1CTL
MOV.W #0xffdf,R15
AND.W &Timer1_A3_TA1CTL,R15
BIS.W #0x0010,R15
MOV.W R15,&Timer1_A3_TA1CTL
BIS.W #0x0010,&Timer1_A3_TA1CCTL0
RETA
It is the first case with no optimization that has a bug.
The line of code:
ta1ctl.cksrc = TA_ACLK; /* set timer source */
should set bit 8 and clear bit 9 of the register. Instead it is setting bit 0 and clearing bit 1.
With optimization turned on there is no problem and the correct bits are set and cleared.
I am using Code Composer Studio with version 3.3.3 of the code generation tools
Is TI aware of this?