cc2x3x clock driver cleanup

* Bit-Addressable SFRs are now accessed as such,
  instead of (N)OR-ing the byte
* A routine was declared as CCIF but not defined as such. Fixed
* Deleted a leftover duplicate define
* Formatting
* Comment updates and clarifications
This commit is contained in:
George Oikonomou 2012-04-02 16:00:45 +01:00
parent 1fd7dcd2ef
commit ffa3a1c4c3
2 changed files with 31 additions and 52 deletions

View file

@ -27,28 +27,21 @@
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
* $Id: clock.c,v 1.1 2009/09/08 20:07:35 zdshelby Exp $
*/
/**
* \file
* Implementation of the clock functions for the 8051 CPU
* Implementation of the clock functions for the cc243x
* \author
* Zach Shelby (zach@sensinode.com)
* Zach Shelby (zach@sensinode.com) - original
* George Oikonomou - <oikonomou@users.sourceforge.net>
*/
/**
* TODO: Implement clock_fine() and clock_fine_max_ticks() using another timer?
*/
#include <stdio.h> /*for debug printf*/
#include "sys/clock.h"
#include "sys/etimer.h"
#include "cc2430_sfr.h"
#include "sys/energest.h"
/*Sleep timer runs on the 32k RC osc. */
/* Sleep timer runs on the 32k RC osc. */
/* One clock tick is 7.8 ms */
#define TICK_VAL (32768/128) /* 256 */
@ -63,8 +56,7 @@ volatile __data clock_time_t count = 0;
volatile __bit sleep_flag;
#endif
/*calculates seconds*/
static volatile __data clock_time_t seconds = 0;
static volatile __data clock_time_t seconds = 0; /* Uptime in secs */
/*---------------------------------------------------------------------------*/
/**
* One delay is about 0.6 us, so this function delays for len * 0.6 us
@ -92,7 +84,7 @@ clock_wait(int i)
while(clock_time() - start < (clock_time_t)i);
}
/*---------------------------------------------------------------------------*/
clock_time_t
CCIF clock_time_t
clock_time(void)
{
return count;
@ -107,24 +99,24 @@ clock_seconds(void)
void
clock_init(void)
{
CLKCON = OSC32K | TICKSPD2|TICKSPD1; /*tickspeed 500 kHz for timers[1-4]*/
CLKCON = OSC32K | TICKSPD2 | TICKSPD1; /* tickspeed 500 kHz for timers[1-4] */
/*Initialize tick value*/
timer_value = ST0; /*sleep timer 0. low bits [7:0]*/
timer_value += ((unsigned long int)ST1) << 8; /*middle bits [15:8]*/
timer_value += ((unsigned long int)ST2) << 16; /*high bits [23:16]*/
timer_value += TICK_VAL; /*init value 256*/
/* Initialize tick value */
timer_value = ST0; /* ST low bits [7:0] */
timer_value += ((unsigned long int) ST1) << 8; /* middle bits [15:8] */
timer_value += ((unsigned long int) ST2) << 16; /* high bits [23:16] */
timer_value += TICK_VAL; /* Init value 256 */
ST2 = (unsigned char) (timer_value >> 16);
ST1 = (unsigned char) (timer_value >> 8);
ST0 = (unsigned char) timer_value;
IEN0 |= STIE; /*interrupt enable for sleep timers. STIE=Interrupt mask, CPU. */
IEN0_STIE = 1; /* IEN0.STIE acknowledge Sleep Timer Interrupt */
}
/*---------------------------------------------------------------------------*/
void
clock_ISR( void ) __interrupt (ST_VECTOR)
clock_ISR(void) __interrupt(ST_VECTOR)
{
IEN0_EA = 0; /*interrupt disable*/
DISABLE_INTERRUPTS();
ENERGEST_ON(ENERGEST_TYPE_IRQ);
/*
@ -134,14 +126,13 @@ clock_ISR( void ) __interrupt (ST_VECTOR)
*/
SLEEP &= 0xFC;
/* When using the cooperative scheduler the timer 2 ISR is only
required to increment the RTOS tick count. */
/*Read value of the ST0,ST1,ST2 and then add TICK_VAL and write it back.
Next interrupt occurs after the current time + TICK_VAL*/
/*
* Read value of the ST0:ST1:ST2, add TICK_VAL and write it back.
* Next interrupt occurs after the current time + TICK_VAL
*/
timer_value = ST0;
timer_value += ((unsigned long int)ST1) << 8;
timer_value += ((unsigned long int)ST2) << 16;
timer_value += ((unsigned long int) ST1) << 8;
timer_value += ((unsigned long int) ST2) << 16;
timer_value += TICK_VAL;
ST2 = (unsigned char) (timer_value >> 16);
ST1 = (unsigned char) (timer_value >> 8);
@ -162,16 +153,16 @@ clock_ISR( void ) __interrupt (ST_VECTOR)
}
#if CLOCK_CONF_ACCURATE
if(etimer_pending() &&
(etimer_next_expiration_time() - count - 1) > MAX_TICKS) { /*core/sys/etimer.c*/
if(etimer_pending()
&& (etimer_next_expiration_time() - count - 1) > MAX_TICKS) {
etimer_request_poll();
}
#else
sleep_flag = 1;
#endif
IRCON &= ~STIF; /*IRCON.STIF=Sleep timer interrupt flag. This flag called this interrupt func, now reset it*/
IRCON_STIF = 0;
ENERGEST_OFF(ENERGEST_TYPE_IRQ);
IEN0_EA = 1; /*interrupt enable*/
ENABLE_INTERRUPTS();
}
/*---------------------------------------------------------------------------*/

View file

@ -27,15 +27,14 @@
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
* $Id: clock.c,v 1.1 2009/09/08 20:07:35 zdshelby Exp $
*/
/**
* \file
* Implementation of the clock functions for the 8051 CPU
* Implementation of the clock functions for the cc253x.
* Ported over from the cc243x original.
* \author
* Zach Shelby (zach@sensinode.com) - original
* Zach Shelby (zach@sensinode.com) - original (cc243x)
* George Oikonomou - <oikonomou@users.sourceforge.net> - cc2530 port
*/
#include "sfr-bits.h"
@ -47,8 +46,6 @@
/* Sleep timer runs on the 32k RC osc. */
/* One clock tick is 7.8 ms */
#define TICK_VAL (32768/128) /* 256 */
#define MAX_TICKS (~((clock_time_t)0) / 2)
/*---------------------------------------------------------------------------*/
/* Do NOT remove the absolute address and do NOT remove the initialiser here */
__xdata __at(0x0000) static unsigned long timer_value = 0;
@ -117,7 +114,7 @@ clock_init(void)
CLKCONCMD |= CLKCONCMD_TICKSPD2 | CLKCONCMD_TICKSPD1;
while(CLKCONSTA != CLKCONCMD);
/*Initialize tick value*/
/* Initialize tick value */
timer_value = ST0;
timer_value += ((unsigned long int) ST1) << 8;
timer_value += ((unsigned long int) ST2) << 16;
@ -126,7 +123,7 @@ clock_init(void)
ST1 = (unsigned char) (timer_value >> 8);
ST0 = (unsigned char) timer_value;
STIE = 1; /* IEN0.STIE interrupt enable */
STIE = 1; /* IEN0.STIE interrupt enable */
}
/*---------------------------------------------------------------------------*/
void
@ -135,15 +132,6 @@ clock_isr(void) __interrupt(ST_VECTOR)
DISABLE_INTERRUPTS();
ENERGEST_ON(ENERGEST_TYPE_IRQ);
/*
* If the Sleep timer throws an interrupt while we are powering down to
* PM1, we need to abort the power down. Clear SLEEP.MODE, this will signal
* main() to abort the PM1 transition
*
* On cc2430 this would be:
* SLEEPCMD &= 0xFC;
*/
/*
* Read value of the ST0:ST1:ST2, add TICK_VAL and write it back.
* Next interrupt occurs after the current time + TICK_VAL