⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 iarapp.c

📁 tinyos的硬件闪灯例子代码
💻 C
📖 第 1 页 / 共 2 页
字号:
  return SUCCESS;
}

//# 56 "C:/tinyos/cygwin/opt/tinyos-1.x/tos/interfaces/Leds.nc"
/*inline*/ static   result_t BlinkM__Leds__init(void){
//#line 56
  unsigned char result;
//#line 56

//#line 56
  result = LedsC__Leds__init();
//#line 56

//#line 56
  return result;
//#line 56
}
//#line 56
static /*inline*/
//# 52 "BlinkM.nc"
result_t BlinkM__StdControl__init(void)
//#line 52
{
  BlinkM__Leds__init();
  return SUCCESS;
}

static /*inline*/
//# 118 "C:/tinyos/cygwin/opt/tinyos-1.x/tos/platform/CC2430/HPLClock.nc"
result_t HPLClock__Clock__setRate(uint16_t interval, uint8_t scale)
//#line 118
{
  scale &= 0x3;

  { __nesc_atomic_t __nesc_atomic = __nesc_atomic_start();
//#line 121
    {

      T1CTL |= scale << 2;
      T1CC0L = (uint8_t )interval;
      T1CC0H = (uint8_t )(interval >> 8);
      T1IE = 1;
    }
//#line 127
    __nesc_atomic_end(__nesc_atomic); }
  return SUCCESS;
}

//# 96 "C:/tinyos/cygwin/opt/tinyos-1.x/tos/platform/CC2430/Clock.nc"
/*inline*/ static   result_t TimerM__Clock__setRate(uint16_t arg_0xa27da28, uint8_t arg_0xa27db70){
//#line 96
  unsigned char result;
//#line 96

//#line 96
  result = HPLClock__Clock__setRate(arg_0xa27da28, arg_0xa27db70);
//#line 96

//#line 96
  return result;
//#line 96
}
//#line 96
static /*inline*/
//# 34 "C:/tinyos/cygwin/opt/tinyos-1.x/tos/platform/CC2430/TimerM.nc"
result_t TimerM__StdControl__init(void)
//#line 34
{
  TimerM__mState = 0;
  TimerM__setIntervalFlag = 0;
  TimerM__queue_head = TimerM__queue_tail = -1;
  TimerM__queue_size = 0;
  TimerM__mScale = 3;
  TimerM__mInterval = 0xffff;
//#line 40
  ;
  return TimerM__Clock__setRate(TimerM__mInterval, TimerM__mScale);
}

//# 63 "C:/tinyos/cygwin/opt/tinyos-1.x/tos/interfaces/StdControl.nc"
/*inline*/ static  result_t RealMain__StdControl__init(void){
//#line 63
  unsigned char result;
//#line 63

//#line 63
  result = TimerM__StdControl__init();
//#line 63
  result = rcombine(result, BlinkM__StdControl__init());
//#line 63

//#line 63
  return result;
//#line 63
}
//#line 63
//# 41 "C:/tinyos/cygwin/opt/tinyos-1.x/tos/interfaces/PowerManagement.nc"
/*inline*/ static   uint8_t TimerM__PowerManagement__adjustPower(void){
//#line 41
  unsigned char result;
//#line 41

//#line 41
  result = HPLPowerManagementM__PowerManagement__adjustPower();
//#line 41

//#line 41
  return result;
//#line 41
}
//#line 41
static /*inline*/
//# 45 "C:/tinyos/cygwin/opt/tinyos-1.x/tos/platform/CC2430/HPLClock.nc"
void HPLClock__Clock__setInterval(uint16_t value)
//#line 45
{
  T1CC0L = (uint8_t )value;
  T1CC0H = (uint8_t )(value >> 8);
}

//# 105 "C:/tinyos/cygwin/opt/tinyos-1.x/tos/platform/CC2430/Clock.nc"
/*inline*/ static   void TimerM__Clock__setInterval(uint16_t arg_0xa2768d0){
//#line 105
  HPLClock__Clock__setInterval(arg_0xa2768d0);
//#line 105
}
//#line 105
static /*inline*/
//# 55 "C:/tinyos/cygwin/opt/tinyos-1.x/tos/platform/CC2430/TimerM.nc"
result_t TimerM__Timer__start(uint8_t id, char type,
uint16_t interval)
//#line 56
{
  uint16_t diff;

//#line 58
  if (id >= NUM_TIMERS) {
//#line 58
    return FAIL;
    }
//#line 59
  if (type > 1) {
//#line 59
    return FAIL;
    }
//#line 60
  TimerM__mTimerList[id].ticks = interval;
  TimerM__mTimerList[id].type = type;

  { __nesc_atomic_t __nesc_atomic = __nesc_atomic_start();
//#line 63
    {
      diff = T1CNTH;
      diff = diff << 8;
      diff += T1CNTL;
      interval += diff;
      TimerM__mTimerList[id].ticksLeft = interval;
      TimerM__mState |= 0x1 << id;
      if (interval < TimerM__mInterval) {
          TimerM__mInterval = interval;
          TimerM__Clock__setInterval(TimerM__mInterval);
          TimerM__setIntervalFlag = 0;
          T1CTL |= 0x2;
          T1IE = 1;
          TimerM__PowerManagement__adjustPower();
        }
    }
//#line 78
    __nesc_atomic_end(__nesc_atomic); }
  return SUCCESS;
}

//# 59 "C:/tinyos/cygwin/opt/tinyos-1.x/tos/platform/CC2430/Timer.nc"
/*inline*/ static  result_t BlinkM__Timer__start(char arg_0xa254a38, uint16_t arg_0xa254b90){
//#line 59
  unsigned char result;
//#line 59

//#line 59
  result = TimerM__Timer__start(0, arg_0xa254a38, arg_0xa254b90);
//#line 59

//#line 59
  return result;
//#line 59
}
//#line 59
static /*inline*/
//# 63 "BlinkM.nc"
result_t BlinkM__StdControl__start(void)
//#line 63
{

  return BlinkM__Timer__start(TIMER_REPEAT, 65534);
}

static /*inline*/
//# 44 "C:/tinyos/cygwin/opt/tinyos-1.x/tos/platform/CC2430/TimerM.nc"
result_t TimerM__StdControl__start(void)
//#line 44
{
  return SUCCESS;
}

//# 70 "C:/tinyos/cygwin/opt/tinyos-1.x/tos/interfaces/StdControl.nc"
/*inline*/ static  result_t RealMain__StdControl__start(void){
//#line 70
  unsigned char result;
//#line 70

//#line 70
  result = TimerM__StdControl__start();
//#line 70
  result = rcombine(result, BlinkM__StdControl__start());
//#line 70

//#line 70
  return result;
//#line 70
}
//#line 70
static /*inline*/
//# 27 "C:/tinyos/cygwin/opt/tinyos-1.x/tos/platform/CC2430/HPLPowerManagementM.nc"
uint8_t HPLPowerManagementM__getPowerLevel(void)
//#line 27
{

  if ((T1IE | T3IE) | T4IE) {
      return HPLPowerManagementM__IDLE;
    }
  else {
//#line 32
    if (((
//#line 31
    (unsigned char volatile __xdata  *)0)[0xDF62] & 0x10)
     & (((unsigned char volatile __xdata  *)0)[0xDF62] & 0x08)) {
        return HPLPowerManagementM__IDLE;
      }
    else {


      if (T2IE) {



          return HPLPowerManagementM__POWER_SAVE;
        }
      else
//#line 43
        {
          return HPLPowerManagementM__POWER_DOWN;
        }
      }
    }
}

static /*inline*/
//#line 48
void HPLPowerManagementM__doAdjustment(void)
//#line 48
{
  uint8_t foo;
//#line 49
  uint8_t mcu;

//#line 50
  foo = HPLPowerManagementM__getPowerLevel();
  mcu = SLEEP;
  mcu &= 0xfc;
  if (foo == HPLPowerManagementM__IDLE || foo == HPLPowerManagementM__ADC_NR) {
    return;
    }
  else {
//#line 55
    if (foo == HPLPowerManagementM__EXT_STANDBY || foo == HPLPowerManagementM__POWER_SAVE) {
        mcu |= HPLPowerManagementM__IDLE;



        mcu &= 0xfc;
      }
    }
//#line 62
  mcu |= foo;
  SLEEP = mcu;
  PCON |= 1 << 0;
}

static
//# 131 "C:/tinyos/cygwin/opt/tinyos-1.x/tos/platform/CC2430/CC2430hardware.h"
/*__inline*/ void __nesc_enable_interrupt(void)
//#line 131
{
  EA = 1;
}

static /*inline*/
//#line 100
void TOSH_wait(void)
{
   __asm ("NOP");
   __asm ("NOP");}

static /*inline*/ void TOSH_sleep(void)
{
}

//#line 125
/*__inline*/ void  __nesc_atomic_end(__nesc_atomic_t oldSreg)
{
  PSW = oldSreg;
  EA = 1;
}

//#line 118
/*__inline*/ __nesc_atomic_t  __nesc_atomic_start(void )
{
  __nesc_atomic_t result = PSW;

//#line 121
  EA = 0;
  return result;
}

static /*inline*/
//# 139 "C:/tinyos/cygwin/opt/tinyos-1.x/tos/system/sched.c"
bool TOSH_run_next_task(void)
//#line 139
{
  __nesc_atomic_t fInterruptFlags;
  uint8_t old_full;
  void (*func)(void );

  if (TOSH_sched_full == TOSH_sched_free) {

      return 0;
    }
  else {

      fInterruptFlags = __nesc_atomic_start();
      old_full = TOSH_sched_full;
      TOSH_sched_full++;
      TOSH_sched_full &= TOSH_TASK_BITMASK;
      func = TOSH_queue[(int )old_full].tp;
      TOSH_queue[(int )old_full].tp = 0;
      __nesc_atomic_end(fInterruptFlags);
      func();
      return 1;
    }
}

static /*inline*/ void TOSH_run_task(void)
//#line 162
{
  while (TOSH_run_next_task())
    ;
  TOSH_sleep();
  TOSH_wait();
}

//# 82 "C:/tinyos/cygwin/opt/tinyos-1.x/tos/platform/CC2430/TimerM.nc"
static void TimerM__adjustInterval(void)
//#line 82
{
  uint8_t i;
  uint16_t val = 0xffff;

//#line 84
  ;
  if (TimerM__mState) {
      for (i = 0; i < NUM_TIMERS; i++) {
          if (TimerM__mState & (0x1 << i) && TimerM__mTimerList[i].ticksLeft < val) {
              val = TimerM__mTimerList[i].ticksLeft;
            }
        }
      { __nesc_atomic_t __nesc_atomic = __nesc_atomic_start();
//#line 91
        {
          TimerM__mInterval = val;
          TimerM__Clock__setInterval(TimerM__mInterval);
          TimerM__setIntervalFlag = 0;
        }
//#line 95
        __nesc_atomic_end(__nesc_atomic); }
    }
  else {
      { __nesc_atomic_t __nesc_atomic = __nesc_atomic_start();
//#line 98
        {
          TimerM__mInterval = 0xffff;
//#line 99
          ;
          TimerM__Clock__setInterval(TimerM__mInterval);
          TimerM__setIntervalFlag = 0;
        }
//#line 102
        __nesc_atomic_end(__nesc_atomic); }
    }
  TimerM__PowerManagement__adjustPower();
}

//# 34 "C:/tinyos/cygwin/opt/tinyos-1.x/tos/platform/CC2430/hardware.h"
static /*__inline*/ void TOSH_CLR_RED_LED_PIN(void)
//#line 34
{
//#line 34
  P1 &= ~(1 << 1);
}

static /*inline*/
//# 69 "C:/tinyos/cygwin/opt/tinyos-1.x/tos/system/LedsC.nc"
result_t LedsC__Leds__redOn(void)
//#line 69
{
  {
  }
//#line 70
  ;
  { __nesc_atomic_t __nesc_atomic = __nesc_atomic_start();
//#line 71
    {
      TOSH_CLR_RED_LED_PIN();
      LedsC__ledsOn |= LedsC__RED_BIT;
    }
//#line 74
    __nesc_atomic_end(__nesc_atomic); }
  return SUCCESS;
}

static /*inline*/   result_t LedsC__Leds__redOff(void)
//#line 78
{
  {
  }
//#line 79
  ;
  { __nesc_atomic_t __nesc_atomic = __nesc_atomic_start();
//#line 80
    {
      TOSH_SET_RED_LED_PIN();
      LedsC__ledsOn &= ~LedsC__RED_BIT;
    }
//#line 83
    __nesc_atomic_end(__nesc_atomic); }
  return SUCCESS;
}

static /*inline*/   result_t LedsC__Leds__redToggle(void)
//#line 87
{
  result_t rval;

//#line 89
  { __nesc_atomic_t __nesc_atomic = __nesc_atomic_start();
//#line 89
    {
      if (LedsC__ledsOn & LedsC__RED_BIT) {
        rval = LedsC__Leds__redOff();
        }
      else {
//#line 93
        rval = LedsC__Leds__redOn();
        }
    }
//#line 95
    __nesc_atomic_end(__nesc_atomic); }
//#line 95
  return rval;
}

//# 81 "C:/tinyos/cygwin/opt/tinyos-1.x/tos/interfaces/Leds.nc"
/*inline*/ static   result_t BlinkM__Leds__redToggle(void){
//#line 81
  unsigned char result;
//#line 81

//#line 81
  result = LedsC__Leds__redToggle();
//#line 81

//#line 81
  return result;
//#line 81
}
//#line 81
static /*inline*/
//# 84 "BlinkM.nc"
result_t BlinkM__Timer__fired(void)
{
  BlinkM__Leds__redToggle();
  return SUCCESS;
}

static /*inline*/
//# 122 "C:/tinyos/cygwin/opt/tinyos-1.x/tos/platform/CC2430/TimerM.nc"
result_t TimerM__Timer__default__fired(uint8_t id)
//#line 122
{
  return SUCCESS;
}

//# 73 "C:/tinyos/cygwin/opt/tinyos-1.x/tos/platform/CC2430/Timer.nc"
/*inline*/ static  result_t TimerM__Timer__fired(uint8_t arg_0xa25ea88){
//#line 73
  unsigned char result;
//#line 73

//#line 73
  switch (arg_0xa25ea88) {
//#line 73
    case 0:
//#line 73
      result = BlinkM__Timer__fired();
//#line 73
      break;
//#line 73
    default:
//#line 73
      result = TimerM__Timer__default__fired(arg_0xa25ea88);
//#line 73
    }
//#line 73

//#line 73
  return result;
//#line 73
}
//#line 73
static /*inline*/
//# 134 "C:/tinyos/cygwin/opt/tinyos-1.x/tos/platform/CC2430/TimerM.nc"
uint8_t TimerM__dequeue(void)
//#line 134
{
  if (TimerM__queue_size == 0) {
    return NUM_TIMERS;
    }
//#line 137
  if (TimerM__queue_head == NUM_TIMERS - 1) {
    TimerM__queue_head = -1;
    }
//#line 139
  TimerM__queue_head++;
  TimerM__queue_size--;
  return TimerM__queue[(uint8_t )TimerM__queue_head];
}

static /*inline*/  void TimerM__signalOneTimer(void)
//#line 144
{
  uint8_t itimer = TimerM__dequeue();

//#line 146
  if (itimer < NUM_TIMERS) {
    TimerM__Timer__fired(itimer);
    }
}

static /*inline*/
//#line 126
void TimerM__enqueue(uint8_t value)
//#line 126
{
  if (TimerM__queue_tail == NUM_TIMERS - 1) {
    TimerM__queue_tail = -1;
    }
//#line 129
  TimerM__queue_tail++;
  TimerM__queue_size++;
  TimerM__queue[(uint8_t )TimerM__queue_tail] = value;
}

static /*inline*/
//#line 150
void TimerM__HandleFire(void)
//#line 150
{
  uint8_t i;

//#line 152
  TimerM__setIntervalFlag = 1;
  if (TimerM__mState) {
      for (i = 0; i < NUM_TIMERS; i++) {
          if (TimerM__mState & (0x1 << i)) {
              TimerM__mTimerList[i].ticksLeft -= TimerM__mInterval + 1;
              if (TimerM__mTimerList[i].ticksLeft <= 2) {
                  if (TimerM__mTimerList[i].type == TIMER_REPEAT) {
                      TimerM__mTimerList[i].ticksLeft += TimerM__mTimerList[i].ticks;
                    }
                  else
//#line 160
                    {
                      TimerM__mState &= ~(0x1 << i);
                    }
                  TimerM__enqueue(i);
                  TOS_post(TimerM__signalOneTimer);
                }
            }
        }
    }
  TimerM__adjustInterval();
}

static /*inline*/   result_t TimerM__Clock__fire(void)
//#line 172
{
  TOS_post(TimerM__HandleFire);
  return SUCCESS;
}

//# 180 "C:/tinyos/cygwin/opt/tinyos-1.x/tos/platform/CC2430/Clock.nc"
/*inline*/ static   result_t HPLClock__Clock__fire(void){
//#line 180
  unsigned char result;
//#line 180

//#line 180
  result = TimerM__Clock__fire();
//#line 180

//#line 180
  return result;
//#line 180
}
//#line 180
//# 98 "C:/tinyos/cygwin/opt/tinyos-1.x/tos/system/sched.c"
bool  TOS_post(void (*tp)(void))
//#line 98
{
  __nesc_atomic_t fInterruptFlags;
  uint8_t tmp;



  fInterruptFlags = __nesc_atomic_start();

  tmp = TOSH_sched_free;
  TOSH_sched_free++;
  TOSH_sched_free &= TOSH_TASK_BITMASK;

  if (TOSH_sched_free != TOSH_sched_full) {
      __nesc_atomic_end(fInterruptFlags);

      TOSH_queue[tmp].tp = tp;
      return 1;
    }
  else {
      TOSH_sched_free = tmp;
      __nesc_atomic_end(fInterruptFlags);

      return 0;
    }
}

//# 57 "C:/tinyos/cygwin/opt/tinyos-1.x/tos/platform/CC2430/RealMain.nc"
int   main(void)
{
  RealMain__hardwareInit();
  TOSH_sched_init();

  RealMain__StdControl__init();
  RealMain__StdControl__start();
  __nesc_enable_interrupt();

  while (1) {
      TOSH_run_task();
    }
}

static
//# 67 "C:/tinyos/cygwin/opt/tinyos-1.x/tos/platform/CC2430/HPLPowerManagementM.nc"
uint8_t HPLPowerManagementM__PowerManagement__adjustPower(void)
//#line 67
{
  uint8_t mcu;

//#line 69
  if (!HPLPowerManagementM__disabled) {
    TOS_post(HPLPowerManagementM__doAdjustment);
    }
  else
//#line 71
    {
      mcu = SLEEP;
      mcu &= 0xfc;
      mcu |= HPLPowerManagementM__IDLE;
      SLEEP = mcu;
    }

  return 0;
}

//# 138 "C:/tinyos/cygwin/opt/tinyos-1.x/tos/platform/CC2430/HPLClock.nc"
#pragma vector=T1_VECTOR
  __interrupt void T1_IRQ(void)
//#line 138
{

  { __nesc_atomic_t __nesc_atomic = __nesc_atomic_start();
//#line 140
    {
      if (HPLClock__set_flag) {
          HPLClock__mscale = HPLClock__nextScale;
          T1CTL |= HPLClock__nextScale << 2;
          T1CC0L = (uint8_t )HPLClock__minterval;
          T1CC0H = (uint8_t )(HPLClock__minterval >> 8);
          HPLClock__set_flag = 0;
        }
      T1IF = 0;
    }
//#line 149
    __nesc_atomic_end(__nesc_atomic); }
  HPLClock__Clock__fire();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -