/*! \brief Main loop. * * Most of the action is interrupt driven. This loop only detects USB suspension. * * @return Never exits */ void main(void) { init(); for(;;){ wait100us(); suspend_timer++; if (suspend_timer>=SUSPEND_TIME) { /* host is not sending keepalive signals, time to suspend all operation */ /* BDM is in idle mode when not communicating, so nothing to do there */ U16 i; /* Acknowledge any pending interrupt and disable KBD interrupts; */ /* This will prevent RESET activity waking us up out of stop */ KBSCR = KBSCR_IMASKK_MASK | KBSCR_ACKK_MASK; led_state=LED_OFF; /* switch the LED off */ GREEN_LED_OFF(); /* do it now, the interrupt which would do it normally is not going to come */ UIR0_SUSPND=1; /* suspend USB */ while (suspend_timer) asm(STOP); /* go to sleep, wait for USB resume or reset */ for (i=0;i<RESUME_RECOVERY;i++) wait100us(); /* wait for host to recover */ led_state=LED_ON; /* Switch the LED back on */ (void)bdm_init(); /* Reinitialise the BDM after wake-up as the device might */ /* have been disconected in the meantime; assume nothing */ } }
int main(void) { int i; MAMCR = 2; // MAM functions fully enabled LED_INIT(); YELLOW_LED_OFF(); GREEN_LED_OFF(); BUTTON_INIT(); i=0; while (i<10) { YELLOW_LED_ON(); GREEN_LED_OFF(); delay(); YELLOW_LED_OFF(); GREEN_LED_ON(); delay(); i++; } while (1) { if (BUTTTON1_OFF()) { YELLOW_LED_ON(); } else { YELLOW_LED_OFF(); } if (BUTTTON2_OFF()) { GREEN_LED_ON(); } else { GREEN_LED_OFF(); } } return 0; // never reached }
void core3_main(void) { // asm volatile ("mov sp,%0" : :"r" (ram3)); while(1) { for(l=0; l < 500000; l++); //wait for some time GREEN_LED_ON(); for(l=0; l < 500000; l++); //wait for some time GREEN_LED_OFF(); } }
int main(void) { uint8_t i; bool timeout = false; RED_LED_OUT(); GREEN_LED_OUT(); RED_LED_OFF(); GREEN_LED_OFF(); usbInit(); usbDeviceDisconnect(); /* enforce re-enumeration, do this while interrupts are disabled! */ i = 0; while(--i){ /* fake USB disconnect for > 250 ms */ wdt_reset(); _delay_ms(1); } usbDeviceConnect(); sei(); for(;;){ /* main event loop */ wdt_reset(); usbPoll(); if((get_input_requested == true) || ((timeout == true) && (feature_report_buf.ucReportingState != HID_USAGE_SENSOR_PROPERTY_REPORTING_STATE_NO_EVENTS_SEL_ENUM)) ) { if(get_input_requested == true) { get_input_requested = false; input_report_buf.ucEventType = HID_USAGE_SENSOR_EVENT_POLL_RESPONSE_SEL_ENUM; } else if(timeout == true) { timeout = false; input_report_buf.ucEventType = HID_USAGE_SENSOR_EVENT_DATA_UPDATED_SEL_ENUM; input_report_buf.sGyroXValue++; } RED_LED_TOGGLE(); /* called after every poll of the interrupt endpoint */ usbSetInterrupt((void *)&input_report_buf, sizeof(input_report_buf)); } _delay_ms(2); if(i++ == 0) { timeout = true; } } }
void MusicPlayer::playList() { if(!playlistIsEmpty()) { while(1) { playOrPause = 1; playingState = PS_PLAY; unsigned int songindex = spl.songIndex[spl.currentSongNum]; playSong(songindex); switch(playingState) { case PS_STOP: playOrPause = 0;GREEN_LED_OFF();return; case PS_NEXT_SONG: if(_playmode == MODE_SHUFFLE) spl.currentSongNum = random(0,spl.songTotalNum); else if(spl.currentSongNum == spl.songTotalNum - 1) spl.currentSongNum = 0; else ++ spl.currentSongNum; playOrPause = 1; break; case PS_PREVIOUS_SONG:if(_playmode == MODE_SHUFFLE) spl.currentSongNum = random(0,spl.songTotalNum); else if(spl.currentSongNum == 0) spl.currentSongNum = spl.songTotalNum - 1; else -- spl.currentSongNum; playOrPause = 1; break; default: if(_playmode == MODE_SHUFFLE) spl.currentSongNum = random(0,spl.songTotalNum); else if(_playmode == MODE_NORMAL) { if(spl.currentSongNum == spl.songTotalNum - 1) { playingState = PS_STOP; return; } else spl.currentSongNum ++; } else if(_playmode == MODE_REPEAT_LIST) { if(spl.currentSongNum == spl.songTotalNum - 1) spl.currentSongNum = 0; else spl.currentSongNum++; } break; } } } }
void MusicPlayer::controlLED() { byte static flagOn = 1; int static count = 5000; if(playOrPause == 0)GREEN_LED_ON(); else if(--count == 0) { count = 5000; if(flagOn == 1) { GREEN_LED_ON(); flagOn = 0; } else { GREEN_LED_OFF(); flagOn = 1; } } }
/*============================================================================== * DESCRIPTION: * @param * @return * @precondition * @postcondition * @caution * @notes *============================================================================*/ void OT_GPIO_init(OT_GPIO_CB_T *cb, void *cbarg) { ot_gpio_cb = cb; ot_gpio_cbarg = cbarg; SENSOR_ON(); TRIGGER_IN_DISABLE(); TRIGGER_OUT_OFF(); GPIO_Init(GREEN_LED_PORT, GREEN_LED_PIN, GPIO_MODE_OUT_PP_LOW_SLOW); GREEN_LED_OFF(); GPIO_Init(RED_LED_PORT, RED_LED_PIN, GPIO_MODE_OUT_PP_LOW_SLOW); RED_LED_OFF(); #if defined(WAKEUP_BUTTON) BUTTON_DISABLE(); #endif // WAKEUP_BUTTON DIP_ENABLE(); return; }
void ControlLed() { static unsigned char greenOnOff = 1; if( 0 == greenFreq--) { greenOnOff = 1-greenOnOff; greenFreq = 5000; } if(greenOnOff) { GREEN_LED_ON(); } else { GREEN_LED_OFF(); } //analogWrite(9,redPwm); }