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

📄 app.c

📁 这是在tinyos中用nesC语言编程示例
💻 C
📖 第 1 页 / 共 3 页
字号:
#line 132  unsigned char result;#line 132#line 132  result = HPLClock$Clock$readCounter();#line 132#line 132  return result;#line 132}#line 132# 75 "D:\\Crossbow\\cygwin\\opt\\MoteWorks\\tos\\system\\TimerM.nc"static inline  result_t TimerM$Timer$start(uint8_t id, char type, uint32_t interval)#line 76{  uint8_t diff;#line 78  if (id >= NUM_TIMERS) {#line 78    return FAIL;    }#line 79  if (type > TIMER_ONE_SHOT) {#line 79    return FAIL;    }  if (type == TIMER_REPEAT && interval <= 2) {#line 86    return FAIL;    }  TimerM$mTimerList[id].ticks = interval;  TimerM$mTimerList[id].type = type;  { __nesc_atomic_t __nesc_atomic = __nesc_atomic_start();#line 91    {      diff = TimerM$Clock$readCounter();      interval += diff;      TimerM$mTimerList[id].ticksLeft = interval;      TimerM$mState |= 0x1L << id;      if (interval < TimerM$mInterval) {          TimerM$mInterval = interval;          TimerM$Clock$setInterval(TimerM$mInterval);          TimerM$setIntervalFlag = 0;          TimerM$PowerManagement$adjustPower();        }    }#line 102    __nesc_atomic_end(__nesc_atomic); }  return SUCCESS;}# 37 "D:\\Crossbow\\cygwin\\opt\\MoteWorks\\tos\\interfaces\\Timer.nc"inline static  result_t MyAppM$Timer$start(char arg_0x1a6216e8, uint32_t arg_0x1a621880){#line 37  unsigned char result;#line 37#line 37  result = TimerM$Timer$start(0U, arg_0x1a6216e8, arg_0x1a621880);#line 37#line 37  return result;#line 37}#line 37# 39 "D:\\Crossbow\\cygwin\\opt\\MoteWorks\\apps\\tutorials\\lesson_1\\MyAppM.nc"static inline  result_t MyAppM$StdControl$start(void)#line 39{  return MyAppM$Timer$start(TIMER_REPEAT, 1000);}# 64 "D:\\Crossbow\\cygwin\\opt\\MoteWorks\\tos\\system\\TimerM.nc"static inline  result_t TimerM$StdControl$start(void)#line 64{  return SUCCESS;}# 48 "D:\\Crossbow\\cygwin\\opt\\MoteWorks\\tos\\interfaces\\StdControl.nc"inline static  result_t RealMain$StdControl$start(void){#line 48  unsigned char result;#line 48#line 48  result = TimerM$StdControl$start();#line 48  result = rcombine(result, MyAppM$StdControl$start());#line 48#line 48  return result;#line 48}#line 48# 41 "D:\\Crossbow\\cygwin\\opt\\MoteWorks\\tos\\platform\\mica2\\HPLPowerManagementM.nc"static inline uint8_t HPLPowerManagementM$getPowerLevel(void)#line 41{  uint8_t diff;  if (* (volatile uint8_t *)(0x37 + 0x20) & ~((1 << 1) | (1 << 0))) {      return HPLPowerManagementM$IDLE;    }  else {#line 46    if (* (volatile uint8_t *)(uint16_t )& * (volatile uint8_t *)(0x0D + 0x20) & (1 << 7)) {        return HPLPowerManagementM$IDLE;      }    else {#line 62      if (* (volatile uint8_t *)(uint16_t )& * (volatile uint8_t *)(0x06 + 0x20) & (1 << 7)) {          return HPLPowerManagementM$ADC_NR;        }      else {#line 64        if (* (volatile uint8_t *)(0x37 + 0x20) & ((1 << 1) | (1 << 0))) {            diff = * (volatile uint8_t *)(0x31 + 0x20) - * (volatile uint8_t *)(0x32 + 0x20);            if (diff < 16) {              return HPLPowerManagementM$EXT_STANDBY;              }#line 68            return HPLPowerManagementM$POWER_SAVE;          }        else #line 69          {            return HPLPowerManagementM$POWER_DOWN;          }        }      }    }}#line 74static inline  void HPLPowerManagementM$doAdjustment(void)#line 74{  uint8_t foo;#line 75  uint8_t mcu;#line 76  foo = HPLPowerManagementM$getPowerLevel();  mcu = * (volatile uint8_t *)(0x35 + 0x20);  mcu &= 0xe3;  if (foo == HPLPowerManagementM$EXT_STANDBY || foo == HPLPowerManagementM$POWER_SAVE) {      mcu |= HPLPowerManagementM$IDLE;      while ((* (volatile uint8_t *)(0x30 + 0x20) & 0x7) != 0) {           __asm volatile ("nop");}      mcu &= 0xe3;    }  mcu |= foo;  * (volatile uint8_t *)(0x35 + 0x20) = mcu;  * (volatile uint8_t *)(0x35 + 0x20) |= 1 << 5;}# 165 "D:\\Crossbow\\cygwin\\opt\\MoteWorks\\tos\\platform\\atm128\\avrhardware.h"static __inline void __nesc_enable_interrupt(void)#line 165{   __asm volatile ("sei");}#line 150 __inline void __nesc_atomic_end(__nesc_atomic_t oldSreg){  * (volatile uint8_t *)(0x3F + 0x20) = oldSreg;}#line 128static inline void TOSH_wait(void){   __asm volatile ("nop");   __asm volatile ("nop");}#line 155static __inline void __nesc_atomic_sleep(void){   __asm volatile ("sei");   __asm volatile ("sleep");  TOSH_wait();}#line 143 __inline __nesc_atomic_t __nesc_atomic_start(void ){  __nesc_atomic_t result = * (volatile uint8_t *)(0x3F + 0x20);#line 146   __asm volatile ("cli");  return result;}# 116 "D:\\Crossbow\\cygwin\\opt\\MoteWorks\\tos\\system\\sched.c"static inline bool TOSH_run_next_task(void){  __nesc_atomic_t fInterruptFlags;  uint8_t old_full;  void (*func)(void );  fInterruptFlags = __nesc_atomic_start();  old_full = TOSH_sched_full;  func = TOSH_queue[old_full].tp;  if (func == (void *)0)     {      __nesc_atomic_sleep();      return 0;    }  TOSH_queue[old_full].tp = (void *)0;  TOSH_sched_full = (old_full + 1) & TOSH_TASK_BITMASK;  __nesc_atomic_end(fInterruptFlags);  func();  return 1;}static inline void TOSH_run_task(void)#line 139{  for (; ; )     TOSH_run_next_task();}# 76 "D:\\Crossbow\\cygwin\\opt\\MoteWorks\\tos\\platform\\atm128\\HPLClock.nc"static inline   uint8_t HPLClock$Clock$getInterval(void)#line 76{  return * (volatile uint8_t *)(0x31 + 0x20);}# 100 "D:\\Crossbow\\cygwin\\opt\\MoteWorks\\tos\\interfaces\\Clock.nc"inline static   uint8_t TimerM$Clock$getInterval(void){#line 100  unsigned char result;#line 100#line 100  result = HPLClock$Clock$getInterval();#line 100#line 100  return result;#line 100}#line 100# 106 "D:\\Crossbow\\cygwin\\opt\\MoteWorks\\tos\\system\\TimerM.nc"inline static void TimerM$adjustInterval(void)#line 106{  uint8_t i;#line 107  uint8_t val = TimerM$maxTimerInterval;#line 108  if (TimerM$mState) {      for (i = 0; i < NUM_TIMERS; i++) {          if (TimerM$mState & (0x1L << i) && TimerM$mTimerList[i].ticksLeft < val) {              val = TimerM$mTimerList[i].ticksLeft;            }        }#line 125      { __nesc_atomic_t __nesc_atomic = __nesc_atomic_start();#line 125        {          i = TimerM$Clock$readCounter() + 3;          if (val < i) {              val = i;            }          TimerM$mInterval = val;          TimerM$Clock$setInterval(TimerM$mInterval);          TimerM$setIntervalFlag = 0;        }#line 133        __nesc_atomic_end(__nesc_atomic); }    }  else {      { __nesc_atomic_t __nesc_atomic = __nesc_atomic_start();#line 136        {          TimerM$mInterval = TimerM$maxTimerInterval;          TimerM$Clock$setInterval(TimerM$mInterval);          TimerM$setIntervalFlag = 0;        }#line 140        __nesc_atomic_end(__nesc_atomic); }    }  TimerM$PowerManagement$adjustPower();}#line 163static inline void TimerM$enqueue(uint8_t value)#line 163{  if (TimerM$queue_tail == NUM_TIMERS - 1) {    TimerM$queue_tail = -1;    }#line 166  TimerM$queue_tail++;  TimerM$queue_size++;  TimerM$queue[(uint8_t )TimerM$queue_tail] = value;}# 52 "D:\\Crossbow\\cygwin\\opt\\MoteWorks\\tos\\platform\\mica2\\hardware.h"static __inline void TOSH_CLR_RED_LED_PIN(void)#line 52{#line 52  * (volatile uint8_t *)(0x1B + 0x20) &= ~(1 << 2);}# 50 "D:\\Crossbow\\cygwin\\opt\\MoteWorks\\tos\\system\\LedsC.nc"static inline   result_t LedsC$Leds$redOn(void)#line 50{  {  }#line 51  ;  /* atomic removed: atomic calls only */#line 52  {    TOSH_CLR_RED_LED_PIN();    LedsC$ledsOn |= LedsC$RED_BIT;  }  return SUCCESS;}static inline   result_t LedsC$Leds$redOff(void)#line 59{  {  }#line 60  ;  /* atomic removed: atomic calls only */#line 61  {    TOSH_SET_RED_LED_PIN();    LedsC$ledsOn &= ~LedsC$RED_BIT;  }  return SUCCESS;}static inline   result_t LedsC$Leds$redToggle(void)#line 68{  result_t rval;#line 70  { __nesc_atomic_t __nesc_atomic = __nesc_atomic_start();#line 70    {      if (LedsC$ledsOn & LedsC$RED_BIT) {        rval = LedsC$Leds$redOff();        }      else {#line 74        rval = LedsC$Leds$redOn();        }    }#line 76    __nesc_atomic_end(__nesc_atomic); }#line 76  return rval;}# 60 "D:\\Crossbow\\cygwin\\opt\\MoteWorks\\tos\\interfaces\\Leds.nc"inline static   result_t MyAppM$Leds$redToggle(void){#line 60  unsigned char result;#line 60#line 60  result = LedsC$Leds$redToggle();#line 60#line 60  return result;#line 60}#line 60# 59 "D:\\Crossbow\\cygwin\\opt\\MoteWorks\\apps\\tutorials\\lesson_1\\MyAppM.nc"static inline  result_t MyAppM$Timer$fired(void){  MyAppM$Leds$redToggle();  return SUCCESS;}# 159 "D:\\Crossbow\\cygwin\\opt\\MoteWorks\\tos\\system\\TimerM.nc"static inline   result_t TimerM$Timer$default$fired(uint8_t id)#line 159{  return SUCCESS;}# 51 "D:\\Crossbow\\cygwin\\opt\\MoteWorks\\tos\\interfaces\\Timer.nc"inline static  result_t TimerM$Timer$fired(uint8_t arg_0x1a651010){#line 51  unsigned char result;#line 51#line 51  switch (arg_0x1a651010) {#line 51    case 0U:#line 51      result = MyAppM$Timer$fired();#line 51      break;#line 51    default:#line 51      result = TimerM$Timer$default$fired(arg_0x1a651010);#line 51      break;#line 51    }#line 51#line 51  return result;#line 51}#line 51# 171 "D:\\Crossbow\\cygwin\\opt\\MoteWorks\\tos\\system\\TimerM.nc"static inline uint8_t TimerM$dequeue(void)#line 171{  if (TimerM$queue_size == 0) {    return NUM_TIMERS;    }#line 174  if (TimerM$queue_head == NUM_TIMERS - 1) {    TimerM$queue_head = -1;    }#line 176  TimerM$queue_head++;  TimerM$queue_size--;  return TimerM$queue[(uint8_t )TimerM$queue_head];}static inline  void TimerM$signalOneTimer(void)#line 181{  uint8_t itimer = TimerM$dequeue();#line 183  if (itimer < NUM_TIMERS) {    TimerM$Timer$fired(itimer);    }}#line 187static inline  void TimerM$HandleFire(void)#line 187{  uint8_t i;  uint16_t int_out;#line 190  TimerM$setIntervalFlag = 1;  { __nesc_atomic_t __nesc_atomic = __nesc_atomic_start();#line 193    {      int_out = TimerM$interval_outstanding;      TimerM$interval_outstanding = 0;    }#line 196    __nesc_atomic_end(__nesc_atomic); }  if (TimerM$mState) {      for (i = 0; i < NUM_TIMERS; i++) {          if (TimerM$mState & (0x1L << i)) {              TimerM$mTimerList[i].ticksLeft -= int_out;              if (TimerM$mTimerList[i].ticksLeft <= 2) {                  if (TOS_post(TimerM$signalOneTimer)) {                      if (TimerM$mTimerList[i].type == TIMER_REPEAT) {                          TimerM$mTimerList[i].ticksLeft += TimerM$mTimerList[i].ticks;                        }                      else #line 207                        {                          TimerM$mState &= ~(0x1L << i);                        }                      TimerM$enqueue(i);                    }                  else {                      {                      }#line 213                      ;                      TimerM$mTimerList[i].ticksLeft = TimerM$mInterval;                    }                }            }        }    }  { __nesc_atomic_t __nesc_atomic = __nesc_atomic_start();#line 224    int_out = TimerM$interval_outstanding;#line 224    __nesc_atomic_end(__nesc_atomic); }  if (int_out == 0) {    TimerM$adjustInterval();    }}static inline   result_t TimerM$Clock$fire(void)#line 230{  { __nesc_atomic_t __nesc_atomic = __nesc_atomic_start();#line 231    {      if (TimerM$interval_outstanding == 0) {        TOS_post(TimerM$HandleFire);        }      else {        }#line 238      ;      TimerM$interval_outstanding += TimerM$Clock$getInterval() + 1;    }#line 241    __nesc_atomic_end(__nesc_atomic); }  return SUCCESS;}# 159 "D:\\Crossbow\\cygwin\\opt\\MoteWorks\\tos\\interfaces\\Clock.nc"inline static   result_t HPLClock$Clock$fire(void){#line 159  unsigned char result;#line 159#line 159  result = TimerM$Clock$fire();#line 159#line 159  return result;#line 159}#line 159# 82 "D:\\Crossbow\\cygwin\\opt\\MoteWorks\\tos\\system\\sched.c" bool TOS_post(void (*tp)(void))#line 82{  __nesc_atomic_t fInterruptFlags;  uint8_t tmp;  fInterruptFlags = __nesc_atomic_start();  tmp = TOSH_sched_free;  if (TOSH_queue[tmp].tp == (void *)0) {      TOSH_sched_free = (tmp + 1) & TOSH_TASK_BITMASK;      TOSH_queue[tmp].tp = tp;      __nesc_atomic_end(fInterruptFlags);      return TRUE;    }  else {      __nesc_atomic_end(fInterruptFlags);      return FALSE;    }}# 34 "D:\\Crossbow\\cygwin\\opt\\MoteWorks\\tos\\system\\RealMain.nc"  int main(void)#line 34{  uint8_t local_symbol_ref;  local_symbol_ref = TOS_PLATFORM;  local_symbol_ref = TOS_BASE_STATION;  local_symbol_ref = TOS_DATA_LENGTH;  local_symbol_ref = TOS_ROUTE_PROTOCOL;  RealMain$hardwareInit();  RealMain$Pot$init(10);  TOSH_sched_init();  RealMain$StdControl$init();  RealMain$StdControl$start();  __nesc_enable_interrupt();  while (1) {      TOSH_run_task();    }}# 91 "D:\\Crossbow\\cygwin\\opt\\MoteWorks\\tos\\platform\\mica2\\HPLPowerManagementM.nc"static   uint8_t HPLPowerManagementM$PowerManagement$adjustPower(void)#line 91{  uint8_t mcu;#line 93  if (!HPLPowerManagementM$disabled) {    TOS_post(HPLPowerManagementM$doAdjustment);    }  else #line 95    {      mcu = * (volatile uint8_t *)(0x35 + 0x20);      mcu &= 0xe3;      mcu |= HPLPowerManagementM$IDLE;      * (volatile uint8_t *)(0x35 + 0x20) = mcu;      * (volatile uint8_t *)(0x35 + 0x20) |= 1 << 5;    }  return 0;}# 146 "D:\\Crossbow\\cygwin\\opt\\MoteWorks\\tos\\platform\\atm128\\HPLClock.nc"  __attribute((interrupt)) void __vector_15(void)#line 146{  { __nesc_atomic_t __nesc_atomic = __nesc_atomic_start();#line 147    {      if (HPLClock$set_flag) {          HPLClock$mscale = HPLClock$nextScale;          HPLClock$nextScale |= 0x8;          * (volatile uint8_t *)(0x33 + 0x20) = HPLClock$nextScale;          * (volatile uint8_t *)(0x31 + 0x20) = HPLClock$minterval;          HPLClock$set_flag = 0;        }    }#line 156    __nesc_atomic_end(__nesc_atomic); }  HPLClock$Clock$fire();}

⌨️ 快捷键说明

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