EmbeddedRelated.com
Forums

TI hal timer code or TimerA confusion

Started by Craig Campbell March 18, 2010
I'm trying to port the TI hardware abstraction layer (HAL) code in the
CC2480 application to a different processor.
The confusion I'm having is with the timers. This code initializes the
TimerA by measuring the counts for 1 second, in the halTimerInit routine:
static void halTimerInit(void)
{
uint8 loop = 128; // Count 8mHz by 65536 timer overflow.
if (halEventFlags & HAL_EVT_NO_8MHz)
{
loop = 16; // Count 1mHz by 65536 timer overflow.
}
BCSCTL1 |= DIVA_3; // ACLK/8
BCSCTL3 |= LFXT1S_2; // ACLK = VLO
// Setup TimerB to calibrate TimerA.
TBCCR0 = 65535;
// Setup TimerA to be calibrated.
TACCR0 = 65535;
TACTL = TASSEL_1 + MC_1; // ACLK, up count mode.
// Calibrate TimerA.
TBCTL = TBSSEL_2 + MC_1; // SMCLK, up count mode.
do {
while ((TBCTL & TBIFG) == 0);
TBCTL &= ~TBIFG;
} while (--loop);
TBCTL = TBCLR; // Clear TimerB configuration.
TACTL &= ~MC_1; // Stop TimerA.
TACCR0_INIT = TAR;
TACTL |= MC_1; // Resume TimerA.
// Configure TimerA for 1-msec ISR for driving the HAL S/W timers, timing
key press+hold, etc.
TACCR0 = TACCR0_INIT; // 1 second by 12kHz / 8 -> 1.5kHz
// TACTL = TASSEL_1 + MC_1; // ACLK, up count mode.
TACCTL0 = CCIE; // TACCR0 interrupt enabled
}

My problem is that this says it's configuring the timer for a 1msec
interrupt, but as far as I can tell it's really doing a 1 second interrupt.

This is further confused by the halDelay routine, which says it sleeps for a
number of msec, but has a very cryptic comment with a calculation
that almost makes sense, but then does things that make no sense at all to
me.
void halDelay(uint8 msecs, uint8 sleep)
{
// Expected scaling for msecs is 3/2, but depends on result of TimerA
calibration.
// TBD - not enough code space: uint16 stop = msecs * (TACCR0_INIT / 10) /
(1000 / 10);
uint16 stop = msecs * 3 / 2;
HAL_DISABLE_INTERRUPTS();
TACTL &= ~MC_1; // Stop the timer.
if (TAR != TACCR0_INIT)
{
stop += TAR;
if (stop == TACCR0_INIT)
{
stop++;
}
}
TACCR0 = stop;
TACTL |= MC_1; // Re-start the timer.
HAL_ENABLE_INTERRUPTS();
if (sleep)
{
do {
HAL_LOW_POWER_MODE();
} while (TACCR0 != TACCR0_INIT);
}
}

Is there a better source for hal code that has already been ported to other
parts, or am I just missing something that should be obvious here? I looked
for a 1000x clock speedup, but didn't find it anywhere.

Thanks,
Craig
--
R. Craig Campbell
Lead Engineer
Daedalus

note our new address: 4923 Centre Avenue, Pittsburgh, PA 15213

voice 412.687.7000 ext.16
fax 412.687.7500
website http://www.daed.com
directions http://www.daed.com/contact_maps.tt2

This message may contain private or proprietary information. Do not
forward this message without my permission. If it appears that I sent
you this message by mistake, please let me know and delete this
message.


Beginning Microcontrollers with the MSP430