app.c
来自「tinyos blink with debugging using serial」· C语言 代码 · 共 1,946 行 · 第 1/3 页
C
1,946 行
{ uint8_t scratch[16]; uint8_t format_flag; uint16_t u_val = 0;#line 44 uint16_t base; uint8_t *ptr; va_list ap; __builtin_va_start(ap, format); for (; ; ) { while ((format_flag = * format++) != '%') { if (!format_flag) {#line 51 __builtin_va_end(ap);#line 51 return 0; }#line 52 *buf = format_flag;#line 52 buf++;#line 52 *buf = 0; } switch ((format_flag = * format++)) { case 'c': format_flag = (__builtin_va_arg(ap, int )); default: *buf = format_flag;#line 60 buf++;#line 60 *buf = 0; continue; case 'S': case 's': ptr = (__builtin_va_arg(ap, char *)); strcat(buf, ptr); continue; case 'o': base = 8; *buf = '0';#line 69 buf++;#line 69 *buf = 0; goto CONVERSION_LOOP; case 'i': if ((int )u_val < 0) { u_val = -u_val; *buf = '-';#line 74 buf++;#line 74 *buf = 0; } case 'u': base = 10; goto CONVERSION_LOOP; case 'x': base = 16; CONVERSION_LOOP: u_val = (__builtin_va_arg(ap, int )); ptr = scratch + 16; * --ptr = 0; do { char ch = u_val % base + '0';#line 89 if (ch > '9') { ch += 'a' - '9' - 1; }#line 91 * --ptr = ch; u_val /= base; } while (#line 93 u_val); strcat(buf, ptr); buf += strlen(ptr); } }}static inline # 69 "BlinkM.nc"result_t BlinkM$StdControl$start(void)#line 69{ {#line 70 char bStatus;#line 70 bStatus = * (volatile unsigned char *)(unsigned int )& * (volatile unsigned char *)(0x3F + 0x20) & (1 << 7);#line 70 __asm volatile ("cli");sprintf(debugbuf, "i=#:%i \n", BlinkM$i);#line 70 writedebug();#line 70 if (bStatus) {#line 70 __asm volatile ("sei"); } }#line 70 ; return BlinkM$Timer$start(TIMER_REPEAT, 1000);}static inline # 82 "D:/PROGRA~1/UCB/cygwin/opt/tinyos-1.x/tos/system/TimerM.nc"result_t TimerM$StdControl$start(void)#line 82{ return SUCCESS;}# 70 "D:/PROGRA~1/UCB/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 70static inline # 63 "D:/PROGRA~1/UCB/cygwin/opt/tinyos-1.x/tos/platform/mica2/HPLPowerManagementM.nc"uint8_t HPLPowerManagementM$getPowerLevel(void)#line 63{ uint8_t diff;#line 65 if (* (volatile unsigned char *)(unsigned int )& * (volatile unsigned char *)(0x37 + 0x20) & ~((1 << 1) | (1 << 0))) { return HPLPowerManagementM$IDLE; } else {#line 68 if (* (volatile unsigned char *)(unsigned int )& * (volatile unsigned char *)(0x0D + 0x20) & (1 << 7)) { return HPLPowerManagementM$IDLE; } else { if (* (volatile unsigned char *)(unsigned int )& * (volatile unsigned char *)(0x06 + 0x20) & (1 << 7)) { return HPLPowerManagementM$ADC_NR; } else {#line 74 if (* (volatile unsigned char *)(unsigned int )& * (volatile unsigned char *)(0x37 + 0x20) & ((1 << 1) | (1 << 0))) { diff = * (volatile unsigned char *)(unsigned int )& * (volatile unsigned char *)(0x31 + 0x20) - * (volatile unsigned char *)(unsigned int )& * (volatile unsigned char *)(0x32 + 0x20); if (diff < 16) { return HPLPowerManagementM$EXT_STANDBY; }#line 78 return HPLPowerManagementM$POWER_SAVE; } else #line 79 { return HPLPowerManagementM$POWER_DOWN; } } } }}static inline #line 84void HPLPowerManagementM$doAdjustment(void)#line 84{ uint8_t foo;#line 85 uint8_t mcu;#line 86 foo = HPLPowerManagementM$getPowerLevel(); mcu = * (volatile unsigned char *)(unsigned int )& * (volatile unsigned char *)(0x35 + 0x20); mcu &= 0xe3; if (foo == HPLPowerManagementM$EXT_STANDBY || foo == HPLPowerManagementM$POWER_SAVE) { mcu |= HPLPowerManagementM$IDLE; while ((* (volatile unsigned char *)(unsigned int )& * (volatile unsigned char *)(0x30 + 0x20) & 0x7) != 0) { __asm volatile ("nop");} mcu &= 0xe3; } mcu |= foo; * (volatile unsigned char *)(unsigned int )& * (volatile unsigned char *)(0x35 + 0x20) = mcu; * (volatile unsigned char *)(unsigned int )& * (volatile unsigned char *)(0x35 + 0x20) |= 1 << 5;}static # 165 "D:/PROGRA~1/UCB/cygwin/opt/tinyos-1.x/tos/platform/avrmote/avrhardware.h"__inline void __nesc_enable_interrupt(void)#line 165{ __asm volatile ("sei");}static inline #line 135void TOSH_wait(void){ __asm volatile ("nop"); __asm volatile ("nop");}static inline void TOSH_sleep(void){ * (volatile unsigned char *)(unsigned int )& * (volatile unsigned char *)(0x35 + 0x20) |= 1 << 5; __asm volatile ("sleep");}#line 160__inline void __nesc_atomic_end(__nesc_atomic_t oldSreg){ * (volatile unsigned char *)(unsigned int )& * (volatile unsigned char *)(0x3F + 0x20) = oldSreg;}#line 153__inline __nesc_atomic_t __nesc_atomic_start(void ){ __nesc_atomic_t result = * (volatile unsigned char *)(unsigned int )& * (volatile unsigned char *)(0x3F + 0x20);#line 156 __asm volatile ("cli"); return result;}static inline # 132 "D:/PROGRA~1/UCB/cygwin/opt/tinyos-1.x/tos/system/sched.c"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_end(fInterruptFlags); 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 155{ while (TOSH_run_next_task()) ; TOSH_sleep(); TOSH_wait();}# 116 "D:/PROGRA~1/UCB/cygwin/opt/tinyos-1.x/tos/system/TimerM.nc"static void TimerM$adjustInterval(void)#line 116{ uint8_t i;#line 117 uint8_t val = TimerM$maxTimerInterval;#line 118 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; } } { __nesc_atomic_t __nesc_atomic = __nesc_atomic_start();#line 124 { TimerM$mInterval = val; TimerM$Clock$setInterval(TimerM$mInterval); TimerM$setIntervalFlag = 0; }#line 128 __nesc_atomic_end(__nesc_atomic); } } else { { __nesc_atomic_t __nesc_atomic = __nesc_atomic_start();#line 131 { TimerM$mInterval = TimerM$maxTimerInterval; TimerM$Clock$setInterval(TimerM$mInterval); TimerM$setIntervalFlag = 0; }#line 135 __nesc_atomic_end(__nesc_atomic); } } TimerM$PowerManagement$adjustPower();}# 116 "D:/PROGRA~1/UCB/cygwin/opt/tinyos-1.x/tos/platform/mica2/hardware.h"static __inline void TOSH_CLR_RED_LED_PIN(void)#line 116{#line 116 * (volatile unsigned char *)(unsigned int )& * (volatile unsigned char *)(0x1B + 0x20) &= ~(1 << 2);}static inline # 72 "D:/PROGRA~1/UCB/cygwin/opt/tinyos-1.x/tos/system/LedsC.nc"result_t LedsC$Leds$redOn(void)#line 72{ { }#line 73 ; { __nesc_atomic_t __nesc_atomic = __nesc_atomic_start();#line 74 { TOSH_CLR_RED_LED_PIN(); LedsC$ledsOn |= LedsC$RED_BIT; }#line 77 __nesc_atomic_end(__nesc_atomic); } return SUCCESS;}static inline result_t LedsC$Leds$redOff(void)#line 81{ { }#line 82 ; { __nesc_atomic_t __nesc_atomic = __nesc_atomic_start();#line 83 { TOSH_SET_RED_LED_PIN(); LedsC$ledsOn &= ~LedsC$RED_BIT; }#line 86 __nesc_atomic_end(__nesc_atomic); } return SUCCESS;}static inline result_t LedsC$Leds$redToggle(void)#line 90{ result_t rval;#line 92 { __nesc_atomic_t __nesc_atomic = __nesc_atomic_start();#line 92 { if (LedsC$ledsOn & LedsC$RED_BIT) { rval = LedsC$Leds$redOff(); } else {#line 96 rval = LedsC$Leds$redOn(); } }#line 98 __nesc_atomic_end(__nesc_atomic); }#line 98 return rval;}# 81 "D:/PROGRA~1/UCB/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 81static inline # 91 "BlinkM.nc"result_t BlinkM$Timer$fired(void){ BlinkM$i++; BlinkM$Leds$redToggle(); return SUCCESS;}static inline # 154 "D:/PROGRA~1/UCB/cygwin/opt/tinyos-1.x/tos/system/TimerM.nc"result_t TimerM$Timer$default$fired(uint8_t id)#line 154{ return SUCCESS;}# 73 "D:/PROGRA~1/UCB/cygwin/opt/tinyos-1.x/tos/interfaces/Timer.nc"inline static result_t TimerM$Timer$fired(uint8_t arg_0xa338850){#line 73 unsigned char result;#line 73#line 73 switch (arg_0xa338850) {#line 73 case 0:#line 73 result = BlinkM$Timer$fired();#line 73 break;#line 73 default:#line 73 result = TimerM$Timer$default$fired(arg_0xa338850);#line 73 }#line 73#line 73 return result;#line 73}#line 73static inline # 166 "D:/PROGRA~1/UCB/cygwin/opt/tinyos-1.x/tos/system/TimerM.nc"uint8_t TimerM$dequeue(void)#line 166{ if (TimerM$queue_size == 0) { return NUM_TIMERS; }#line 169 if (TimerM$queue_head == NUM_TIMERS - 1) { TimerM$queue_head = -1; }#line 171 TimerM$queue_head++; TimerM$queue_size--; return TimerM$queue[(uint8_t )TimerM$queue_head];}static inline void TimerM$signalOneTimer(void)#line 176{ uint8_t itimer = TimerM$dequeue();#line 178 if (itimer < NUM_TIMERS) { TimerM$Timer$fired(itimer); }}static inline #line 158void TimerM$enqueue(uint8_t value)#line 158{ if (TimerM$queue_tail == NUM_TIMERS - 1) { TimerM$queue_tail = -1; }#line 161 TimerM$queue_tail++; TimerM$queue_size++; TimerM$queue[(uint8_t )TimerM$queue_tail] = value;}static inline #line 182void TimerM$HandleFire(void)#line 182{ uint8_t i;#line 184 TimerM$setIntervalFlag = 1; if (TimerM$mState) { for (i = 0; i < NUM_TIMERS; i++) { if (TimerM$mState & (0x1L << 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 192 { TimerM$mState &= ~(0x1L << i); } TimerM$enqueue(i); TOS_post(TimerM$signalOneTimer); } } } } TimerM$adjustInterval();}static inline result_t TimerM$Clock$fire(void)#line 204{ TOS_post(TimerM$HandleFire); return SUCCESS;}# 180 "D:/PROGRA~1/UCB/cygwin/opt/tinyos-1.x/tos/interfaces/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# 100 "D:/PROGRA~1/UCB/cygwin/opt/tinyos-1.x/tos/system/sched.c"bool TOS_post(void (*tp)(void))#line 100{ __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; }}# 54 "D:/PROGRA~1/UCB/cygwin/opt/tinyos-1.x/tos/system/RealMain.nc"int main(void)#line 54{ RealMain$hardwareInit(); RealMain$Pot$init(10); TOSH_sched_init(); RealMain$StdControl$init(); RealMain$StdControl$start(); __nesc_enable_interrupt(); while (1) { TOSH_run_task(); }}static # 23 "SOdebug.h"void UARTPutChar(char c)#line 23{ if (c == '\n') { UARTPutChar('\r'); }#line 26 do { } while (#line 26 !(* (volatile unsigned char *)(unsigned int )& * (volatile unsigned char *)(0x0B + 0x20) & (1 << 5))); * (volatile unsigned char *)(unsigned int )& * (volatile unsigned char *)(0x0C + 0x20) = c;}static # 101 "D:/PROGRA~1/UCB/cygwin/opt/tinyos-1.x/tos/platform/mica2/HPLPowerManagementM.nc"uint8_t HPLPowerManagementM$PowerManagement$adjustPower(void)#line 101{ uint8_t mcu;#line 103 if (!HPLPowerManagementM$disabled) { TOS_post(HPLPowerManagementM$doAdjustment); } else #line 105 { mcu = * (volatile unsigned char *)(unsigned int )& * (volatile unsigned char *)(0x35 + 0x20); mcu &= 0xe3; mcu |= HPLPowerManagementM$IDLE; * (volatile unsigned char *)(unsigned int )& * (volatile unsigned char *)(0x35 + 0x20) = mcu; * (volatile unsigned char *)(unsigned int )& * (volatile unsigned char *)(0x35 + 0x20) |= 1 << 5; } return 0;}# 167 "D:/PROGRA~1/UCB/cygwin/opt/tinyos-1.x/tos/platform/mica/HPLClock.nc"void __attribute((interrupt)) __vector_15(void)#line 167{ { __nesc_atomic_t __nesc_atomic = __nesc_atomic_start();#line 168 { if (HPLClock$set_flag) { HPLClock$mscale = HPLClock$nextScale; HPLClock$nextScale |= 0x8; * (volatile unsigned char *)(unsigned int )& * (volatile unsigned char *)(0x33 + 0x20) = HPLClock$nextScale; * (volatile unsigned char *)(unsigned int )& * (volatile unsigned char *)(0x31 + 0x20) = HPLClock$minterval; HPLClock$set_flag = 0; } }#line 177 __nesc_atomic_end(__nesc_atomic); } HPLClock$Clock$fire();}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?