/* *Complete the shutdown and place the processor offline. * * Called at splsched in the shutdown context. */ void processor_offline( processor_t processor) { thread_t new_thread, old_thread = processor->active_thread; new_thread = processor->idle_thread; processor->active_thread = new_thread; processor->current_pri = IDLEPRI; processor->current_thmode = TH_MODE_NONE; processor->deadline = UINT64_MAX; new_thread->last_processor = processor; processor->last_dispatch = mach_absolute_time(); timer_stop(PROCESSOR_DATA(processor, thread_timer), processor->last_dispatch); machine_set_current_thread(new_thread); thread_dispatch(old_thread, new_thread); PMAP_DEACTIVATE_KERNEL(processor->cpu_id); cpu_sleep(); panic("zombie processor"); /*NOTREACHED*/ }
void powermac_sleep(platform_t platform) { *(unsigned long *)0x80 = 0x100; cpu_sleep(); }
void default_idle(void) { set_bl_bit(); local_irq_enable(); /* Isn't this racy ? */ cpu_sleep(); clear_bl_bit(); }
void stop_this_cpu(void *unused) { local_irq_disable(); set_cpu_online(smp_processor_id(), false); for (;;) cpu_sleep(); }
void low_power_mode() { // Turn off GPIO A and B RCC_IOPENR &= ~(BIT1+BIT0); // Turn off ADC haltADC(); RCC_CFGR |= 0xf0; // drop AHB bus speed by a factor of 512 PWR_CR |= BIT0; // switch voltage regulator to low power mode SCR |= BIT2; // enable deep sleep for the cortex M0+ cpu_sleep(); // stop cpu (wfi) }
static void sdk7786_power_off(void) { fpga_write_reg(fpga_read_reg(PWRCR) | PWRCR_PDWNREQ, PWRCR); /* * It can take up to 20us for the R8C to do its job, back off and * wait a bit until we've been shut off. Even though newer FPGA * versions don't set the ACK bit, the latency issue remains. */ while ((fpga_read_reg(PWRCR) & PWRCR_PDWNACK) == 0) cpu_sleep(); }
// ------------------------------------------------------------------------ // main // ------------------------------------------------------------------------ void c_main() { io_printf (IO_STD, "starting dumped packet bouncer\n"); timer_init (TICK_PERIOD); // setup timer to maybe turn on bouncing cc_init (); // setup comms. cont. interrupt when not full router_init (); // setup router to interrupt when dumping #ifdef DEBUG timer2_init (); // setup timer2 for profiling #endif cpu_sleep (); // Send core to sleep }
void default_idle(void) { if (likely(hlt_counter)) { local_irq_disable(); stop_critical_timings(); cpu_relax(); start_critical_timings(); local_irq_enable(); } else { clear_thread_flag(TIF_POLLING_NRFLAG); smp_mb__after_clear_bit(); local_irq_disable(); while (!need_resched()) cpu_sleep(); local_irq_enable(); set_thread_flag(TIF_POLLING_NRFLAG); } }
static void default_idle(void) { if (!hlt_counter) { clear_thread_flag(TIF_POLLING_NRFLAG); smp_mb__after_clear_bit(); set_bl_bit(); stop_critical_timings(); while (!need_resched()) cpu_sleep(); start_critical_timings(); clear_bl_bit(); set_thread_flag(TIF_POLLING_NRFLAG); } else while (!need_resched()) cpu_relax(); }
void default_idle(void) { if (hlt_works()) { clear_thread_flag(TIF_POLLING_NRFLAG); smp_mb__after_clear_bit(); set_bl_bit(); if (!need_resched()) { local_irq_enable(); cpu_sleep(); } else local_irq_enable(); set_thread_flag(TIF_POLLING_NRFLAG); clear_bl_bit(); } else poll_idle(); }
/* * Complete the shutdown and place the processor offline. * * Called at splsched in the shutdown context. * This performs a minimal thread_invoke() to the idle thread, * so it needs to be kept in sync with what thread_invoke() does. * * The onlining half of this is done in load_context(). */ void processor_offline( processor_t processor) { assert(processor == current_processor()); assert(processor->active_thread == current_thread()); thread_t old_thread = processor->active_thread; thread_t new_thread = processor->idle_thread; processor->active_thread = new_thread; processor->current_pri = IDLEPRI; processor->current_thmode = TH_MODE_NONE; processor->starting_pri = IDLEPRI; processor->current_sfi_class = SFI_CLASS_KERNEL; processor->deadline = UINT64_MAX; new_thread->last_processor = processor; uint64_t ctime = mach_absolute_time(); processor->last_dispatch = ctime; old_thread->last_run_time = ctime; /* Update processor->thread_timer and ->kernel_timer to point to the new thread */ thread_timer_event(ctime, &new_thread->system_timer); PROCESSOR_DATA(processor, kernel_timer) = &new_thread->system_timer; timer_stop(PROCESSOR_DATA(processor, current_state), ctime); KERNEL_DEBUG_CONSTANT_IST(KDEBUG_TRACE, MACHDBG_CODE(DBG_MACH_SCHED, MACH_SCHED) | DBG_FUNC_NONE, old_thread->reason, (uintptr_t)thread_tid(new_thread), old_thread->sched_pri, new_thread->sched_pri, 0); machine_set_current_thread(new_thread); thread_dispatch(old_thread, new_thread); PMAP_DEACTIVATE_KERNEL(processor->cpu_id); cpu_sleep(); panic("zombie processor"); /*NOTREACHED*/ }
void naiboard_sleep(void) { if (naiboard_state.usb_vendor_enabled) // If we're not connected we won't go to sleep. return; // We're only using the IDLE sleep level because USB doesn't work below that. // Not much power saving though... SLEEP.CTRL = SLEEP_SMODE_IDLE_gc; sysclk_disable_peripheral_clock(&RTC); //printf_P(PSTR("sleep\n")); WDT_Disable(); sleep_enable(); cpu_sleep(); // Waking up sleep_disable(); WDT_Enable(); sysclk_enable_peripheral_clock(&RTC); //printf_P(PSTR("wake\n")); }
int uart_write (void *_u, const char *ptr, int sz) { struct uart_dev *u = _u; if (sz == 0) return 0; for (u->written=0; u->written < sz; u->written++){ u->tx_tail = (u->tx_tail+1) & (UART_RX_BUFF_SZ-1); u->tx_buff[u->tx_tail] = *ptr++; } if (tx_is_ready (u->u)){ /* Send the first byte. */ u->tx_head = (u->tx_head+1) & (UART_RX_BUFF_SZ-1); u->u->udr = u->tx_buff[u->tx_head]; } while (u->tx_head != u->tx_tail){ cpu_sleep (sleep_mode_iddle); } return u->written; }
static void native_machine_restart(char * __unused) { local_irq_disable(); /* Destroy all of the TLBs in preparation for reset by MMU */ __flush_tlb_global(); /* Address error with SR.BL=1 first. */ trigger_address_error(); #ifdef CONFIG_SUPERH32 /* If that fails or is unsupported, go for the watchdog next. */ watchdog_trigger_immediate(); #endif /* * Give up and sleep. */ while (1) cpu_sleep(); }
int main(void) { uint8_t vbat_status; chip_init(); vbat_status = vbat_system_check(true); /* * Depending on the VBAT system check appropriate actions need to * be taken. * In this example we re-initialize the VBAT system in all * error cases. */ switch (vbat_status) { case VBAT_STATUS_OK: // Interrupts must be re-enabled RTC32_SetCompareIntLevel(RTC32_COMPINTLVL_LO_gc); break; case VBAT_STATUS_NO_POWER: // fall through case VBAT_STATUS_BBPOR: // fall through case VBAT_STATUS_BBBOD: // fall through case VBAT_STATUS_XOSCFAIL: // fall through default: vbat_init(); break; } sei(); while (true) { RTC32_SetAlarm(2); PORTA.OUTTGL = 0x02; SLEEP.CTRL = SLEEP_SMODE_PSAVE_gc | SLEEP_SEN_bm; cpu_sleep(); } }
bool cpu_thread::check_state() { #ifdef WITH_GDB_DEBUGGER if (test(state, cpu_flag::dbg_pause)) { fxm::get<GDBDebugServer>()->notify(); } #endif bool cpu_sleep_called = false; bool cpu_flag_memory = false; while (true) { if (test(state, cpu_flag::memory) && state.test_and_reset(cpu_flag::memory)) { cpu_flag_memory = true; if (auto& ptr = vm::g_tls_locked) { ptr->compare_and_swap(this, nullptr); ptr = nullptr; } } if (test(state, cpu_flag::exit + cpu_flag::dbg_global_stop)) { return true; } if (test(state & cpu_flag::signal) && state.test_and_reset(cpu_flag::signal)) { cpu_sleep_called = false; } if (!test(state, cpu_state_pause)) { if (cpu_flag_memory) vm::passive_lock(*this); break; } else if (!cpu_sleep_called && test(state, cpu_flag::suspend)) { cpu_sleep(); cpu_sleep_called = true; continue; } thread_ctrl::wait(); } const auto state_ = state.load(); if (test(state_, cpu_flag::ret + cpu_flag::stop)) { return true; } if (test(state_, cpu_flag::dbg_step)) { state += cpu_flag::dbg_pause; state -= cpu_flag::dbg_step; } return false; }
void cpu_reset() { cpu_sleep(1); }
/*============================================================================== * MODULE : main * FUNCTION : IR Remocon リモコンメイン関数 * ARGUMENT : none * RETURN : none * NOTE : none *===============================================================================*/ void main() { unsigned char i; /* LED 点滅回数カウンタ */ unsigned char ir_state; /* 受信状態 (成功/不明/ノイズ) */ unsigned char key_code; /* キーコード取得用 */ unsigned char func_key_type; /* ファンクションキー種別 */ unsigned char eep_offset; /* EEPROM保存先 オフセット */ /* PORT A/B/C 入出力設定 (1b:Input 0b:Output) */ TRISA = 0xCF; /* Port A 入出力設定 */ TRISB = 0x00; /* Port B 入出力設定 */ /* masa すべてのPORTをOUTPUTにする。*/ //TRISB = 0xC1; /* Port B 入出力設定 */ TRISC = 0x81; /* Port C 入出力設定 */ /* A/Dコンバータ設定 */ ADCON0 = 0x00; /* ADコンバータ電源OFF(未使用) */ ANSEL = 0x00; /* AN0~AN7 Pin Digital I/O */ ANSELH = 0x00; /* AN8~AN13 Pin Digital I/O */ /* コンパレータ設定 */ CM1CON0 = 0x07; /* Comparator 1 Disable */ CM2CON0 = 0x07; /* Comparator 2 Disable */ /* キャリア周波数設定 (PWM用 TIMER2 の設定) */ PR2 = 0x19; /* 38KHz (1cycle = 25~26us) */ T2CON = 0x0C; /* Postscaler -> 1:2 */ /* Timer2 -> ON */ /* Prescaler -> 1 */ CCPR2L = 0x0C; /* Duty -> 50% (0x32) */ /* CCPR2L:1100b */ /* CCP2CON(bit5~4):10b->110010b */ CCP2CON = PWM_STOP; /* PWM -> OFF */ /* 2LSB of duty cycle->10b */ /* 受信データ解析用 TIMER1 設定 */ T1CON = 0x01; /* Prescaler -> 1:1 (65ms) */ /* Clock Source -> Internal */ /* Timer1 -> Start */ TMR1L = 0; /* Timer1 Value MSB 8bit Clear */ TMR1H = 0; /* Timer1 Value LSB 8bit Clear */ TMR1IF = 0; /* Timer1 Interrupt Flag Clear */ TMR1IE = 1; /* Timer1 Interrupt Enable */ /* Port 初期化 */ PORTA = 0x00; /* PortA RA7~0:Lo */ PORTB = 0x00; /* PortB RB7~1:Lo RB0:Hi */ /* masa */ //PORTB = 0x01; /* PortB RB7~1:Lo RB0:Hi */ PORTC = 0x01; /* PortC RC7~1:Lo RC0:Hi */ /****************************************************************/ /* Dip SW が両方 Hi ⇒ 送信モード */ /****************************************************************/ if ((PORTA & MODE_MASK) == RUN_MODE_1) { /* Function Type Init (Function 1 で初期化) */ func_key_type = KEY_CODE01; /* Function1 LED On */ led_control(LED_MASK); for (;;) { /* Key Check */ key_code = key_input_check(); /* Key 押下なし -> CPU Sleep */ if (key_code == KEY_OFF) { /* CPU Sleep -> Wake Up */ cpu_sleep(); } /* Key 押下あり -> 何れかの動作 */ else { /* Function Key 押下された */ if (key_code <= KEY_CODE04) { /* Function Type 保持 */ func_key_type = key_code; /* 対応した LED On */ led_control((LED_MASK << key_code)); } /* 動作キーが押下された */ else { /* 対応したコードを送信 */ ir_out_start(func_key_type, key_code); } } } } /****************************************************************/ /* Dip SW 1:Lo Dip SW 2:Hi ⇒ 受信モード (EEPROMへの保存) */ /****************************************************************/ if ((PORTA & MODE_MASK) == RUN_MODE_2) { /* Function LED All Off */ led_control(ALL_ON); for (;;) { /* Key Check */ key_code = key_input_check(); /* Function Key が押されたら受信モードへ */ if (key_code <= KEY_CODE04) { /* Function Key Code 保持 */ func_key_type = key_code; /* Key に対応した LED 点灯 */ led_control((LED_MASK << key_code)); break; } else { /* Key 押下されるまでチェックを続ける */ ; } } /* 何か受信するまでIRチェック */ for (;;) { /* 赤外線コード受信 */ ir_state = ir_recieve(); /* 受信成功 (NEC/家電協フォーマット) */ if (ir_state == SUCCESS) { /* LED制御 & データ保存処理へ遷移 */ break; } /* 不明のフォーマットを受信 */ else if (ir_state == UNKNOWN) { for (;;) { /* 電源OFFまで 150ms 間隔で全LED点滅 */ led_control(ALL_OFF); __delay_ms(150); led_control(ALL_ON); __delay_ms(150); } } /* 何らかのノイズを受信 */ else { /* もう一度受信処理 */ ; } } /* 受信完了状態通知 */ for (i=0; i<2; i++) { /* 選択した Key に対応した LED 点滅 (2回) */ /* 150ms 間隔で点滅 */ led_control(ALL_OFF); __delay_ms(150); led_control((LED_MASK << func_key_type)); __delay_ms(150); } /* IR format 一時保持 */ eep_wdata.format = rx_format; /* 受信データ一時保持 */ memcpy(&eep_wdata.data, &rcv_data, sizeof(rcv_data)); /* EEPROM 書込み先取得 */ eep_offset = (key_code * EEPROM_DATA_SIZE); /* FormatをEEPROMへ書込み */ EEPROM_WRITE(eep_offset, eep_wdata.format); /* 書込んだ分オフセット移動 */ eep_offset++; /* DataCodeをEEPROMへ書込み */ for (i=0; i < TBL_CODE_SIZE; i++) { /* HI-TECH C 標準関数 */ /* 1byte ずつ書込み */ EEPROM_WRITE((eep_offset + i), eep_wdata.data[i]); } /* IR Data 記録後無限ループ */ for (;;); } /****************************************************************/ /* Dip SW 1:Hi Dip SW 2:Lo ⇒ 学習モード (EEPROM Data 送信) */ /****************************************************************/ if ((PORTA & MODE_MASK) == RUN_MODE_3) { /* EEPROM Data を RAM へ展開 */ for (i = 0; i < EEPROM_TABLE_SIZE; i++) { eep_rdata[i] = EEPROM_READ(i); } for (;;) { /* Key Check */ key_code = key_input_check(); /* KEYが押されてなかったらSleepにする */ if (key_code == KEY_OFF) { /* CPU Sleep -> Key INT -> Wake Up */ cpu_sleep(); } else { /* Function Key (4つ) のみ対応 */ if (key_code <= KEY_CODE04) { /* Key に対応したRAM読込先取得 */ eep_offset = (key_code * EEPROM_DATA_SIZE); /* Data存在する場合のみ送信 */ if ((eep_rdata[eep_offset] == FORM_NEC) || (eep_rdata[eep_offset] == FORM_KDN)) { /* 送信中 -> 対応したLED On */ led_control((LED_MASK << key_code)); /* フォーマット -> NEC */ if (eep_rdata[eep_offset] == FORM_NEC) { /* Keyに対応したDataを */ /* NEC formatで送信 */ /* 読込んだ分オフセット移動 */ eep_offset++; IR_NEC_format((unsigned char*)&eep_rdata[eep_offset]); } /* フォーマット -> 家電協 */ else { /* Keyに対応したDataを */ /* 家電協 formatで送信 */ /* 読込んだ分オフセット移動 */ eep_offset++; IR_KDN_format((unsigned char*)&eep_rdata[eep_offset]); } /* 送信終了 -> LED Off */ led_control(ALL_OFF); } } } } } /****************************************************************/ /* Dip SW 1:Lo Dip SW 2:Lo ⇒ LCD表示モード */ /* このモードがmainの役目を果たす */ /****************************************************************/ if ((PORTA & MODE_MASK) == RUN_MODE_4) { /* LCD Initialize */ lcd_init(); /* IR 比較データ初期化 */ memset(&pre_data, 0x00, sizeof(pre_data)); for (;;) { /* IR受信 */ ir_state = ir_recieve(); /*以下がmotion controlを制御するpart masa */ switch(rcv_data[5]){ case FORWARD: motion_control(MOVE_FORWARD); break; case BACKWARD: motion_control(MOVE_BACKWARD); break; case STOP: motion_control(MOVE_STOP); break; case LEFT: motion_control(MOVE_LEFT); break; case RIGHT: motion_control(MOVE_RIGHT); break; } /* ここまで masa */ /* 受信データと比較データが異なる場合のみ表示を更新 */ // if ((memcmp(&pre_data, &rcv_data, sizeof(rcv_data))) != 0) { /* comment out 開放 masa */ if ((memcmp(&pre_data, &rcv_data, sizeof(rcv_data))) != 0) { if (ir_state == SUCCESS) { lcd_clear(); /* LCD All Clear */ lcd_put_ir_format(rx_format); /* IR format Type 表示 */ switch (rx_format) { case FORM_NEC: /* 受信コード = NEC format */ /* NEC format の IR 受信データ表示 */ lcd_put_ir_data(&rcv_data, FORMAT_DISP_SIZE_NEC); break; case FORM_KDN: /* 受信コード = 家電協 format */ /* 家電協 format の IR 受信データ表示 */ lcd_put_ir_data(&rcv_data, FORMAT_DISP_SIZE_KDN); break; default: /* 受信コード = 未対応 format */ break; } } else if (ir_state == UNKNOWN) { /* 未対応 format の IR 受信データ表示 */ lcd_clear(); /* LCD All Clear */ lcd_put_ir_format(FORM_UKN); /* IR format Type 表示 */ // lcd_put_ir_data(&rcv_data, FORMAT_DISP_SIZE_UKN); } else { ; /* ノイズの為、もう一度受信処理 */ } /* IR 比較データ保持 */ memcpy(&pre_data, &rcv_data, sizeof(rcv_data)); } } } }
void halt() { while (1) cpu_sleep(0); }