kick_scheduler_t radiotimer_isr_sfd(void) { uint16_t now; now = radiotimer_getCapturedTime(); if (P1IES & 0x20) { // high->low just happened if (radiotimer_vars.endFrameCb!=NULL) { radiotimer_vars.endFrameCb(now); } } else { // low->high just happened if (radiotimer_vars.startFrameCb!=NULL) { radiotimer_vars.startFrameCb(now); } } P1IES ^= 0x20; // arm in opposite transition return KICK_SCHEDULER; }
void board_sleep() { #if 0 uint16_t sleepTime = radiotimer_getPeriod() - radiotimer_getCapturedTime(); DBGMCU_Config(DBGMCU_STOP, ENABLE); // Enable PWR and BKP clock RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE); // Desable the SRAM and FLITF clock in Stop mode RCC_AHBPeriphClockCmd(RCC_AHBPeriph_SRAM | RCC_AHBPeriph_FLITF, DISABLE); PWR_EnterSTOPMode(PWR_Regulator_ON,PWR_STOPEntry_WFI); if(sleepTime > 0) opentimers_sleepTimeCompesation(sleepTime*2); #endif }
uint8_t radio_isr() { PORT_TIMER_WIDTH capturedTime; uint8_t irq_status; // capture the time capturedTime = radiotimer_getCapturedTime(); // reading IRQ_STATUS causes radio's IRQ pin to go low irq_status = radio_spiReadReg(RG_IRQ_STATUS); // start of frame event if (irq_status & AT_IRQ_RX_START) { // change state radio_vars.state = RADIOSTATE_RECEIVING; if (radio_vars.startFrame_cb!=NULL) { // call the callback radio_vars.startFrame_cb(capturedTime); // kick the OS return 1; } else { while(1); } } // end of frame event if (irq_status & AT_IRQ_TRX_END) { // change state radio_vars.state = RADIOSTATE_TXRX_DONE; if (radio_vars.endFrame_cb!=NULL) { // call the callback radio_vars.endFrame_cb(capturedTime); // kick the OS return 1; } else { while(1); } } return 0; }
void radio_txNow() { PORT_TIMER_WIDTH val; // change state radio_vars.state = RADIOSTATE_TRANSMITTING; // send packet by pulsing the SLP_TR_CNTL pin PORT_PIN_RADIO_SLP_TR_CNTL_HIGH(); PORT_PIN_RADIO_SLP_TR_CNTL_LOW(); // The AT86RF231 does not generate an interrupt when the radio transmits the // SFD, which messes up the MAC state machine. The danger is that, if we leave // this funtion like this, any radio watchdog timer will expire. // Instead, we cheat an mimick a start of frame event by calling // ieee154e_startOfFrame from here. This also means that software can never catch // a radio glitch by which #radio_txEnable would not be followed by a packet being // transmitted (I've never seen that). if (radio_vars.startFrame_cb!=NULL) { // call the callback val=radiotimer_getCapturedTime(); radio_vars.startFrame_cb(val); } }
kick_scheduler_t radio_isr() { volatile PORT_TIMER_WIDTH capturedTime; uint8_t irq_status0,irq_status1; // capture the time capturedTime = radiotimer_getCapturedTime(); // reading IRQ_STATUS irq_status0 = HWREG(RFCORE_SFR_RFIRQF0); irq_status1 = HWREG(RFCORE_SFR_RFIRQF1); IntPendClear(INT_RFCORERTX); //clear interrupt HWREG(RFCORE_SFR_RFIRQF0) = 0; HWREG(RFCORE_SFR_RFIRQF1) = 0; //STATUS0 Register // start of frame event if ((irq_status0 & RFCORE_SFR_RFIRQF0_SFD) == RFCORE_SFR_RFIRQF0_SFD) { // change state radio_vars.state = RADIOSTATE_RECEIVING; if (radio_vars.startFrame_cb!=NULL) { // call the callback radio_vars.startFrame_cb(capturedTime); // kick the OS return KICK_SCHEDULER; } else { while(1); } } //or RXDONE is full -- we have a packet. if (((irq_status0 & RFCORE_SFR_RFIRQF0_RXPKTDONE) == RFCORE_SFR_RFIRQF0_RXPKTDONE)) { // change state radio_vars.state = RADIOSTATE_TXRX_DONE; if (radio_vars.endFrame_cb!=NULL) { // call the callback radio_vars.endFrame_cb(capturedTime); // kick the OS return KICK_SCHEDULER; } else { while(1); } } //or FIFOP is full -- we have a packet. if (((irq_status0 & RFCORE_SFR_RFIRQF0_FIFOP) == RFCORE_SFR_RFIRQF0_FIFOP)) { // change state radio_vars.state = RADIOSTATE_TXRX_DONE; if (radio_vars.endFrame_cb!=NULL) { // call the callback radio_vars.endFrame_cb(capturedTime); // kick the OS return KICK_SCHEDULER; } else { while(1); } } //STATUS1 Register // end of frame event --either end of tx . if (((irq_status1 & RFCORE_SFR_RFIRQF1_TXDONE) == RFCORE_SFR_RFIRQF1_TXDONE)) { // change state radio_vars.state = RADIOSTATE_TXRX_DONE; if (radio_vars.endFrame_cb!=NULL) { // call the callback radio_vars.endFrame_cb(capturedTime); // kick the OS return KICK_SCHEDULER; } else { while(1); } } return DO_NOT_KICK_SCHEDULER; }
void board_sleep() { #ifdef DEBUG_RUN_MODE // nothing need to do #endif #ifdef DEBUG_SLEEP_MODE DBGMCU_Config(DBGMCU_SLEEP, ENABLE); // Enable PWR and BKP clock RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE); // Desable the SRAM and FLITF clock in sleep mode RCC_AHBPeriphClockCmd(RCC_AHBPeriph_SRAM | RCC_AHBPeriph_FLITF, DISABLE); // enter sleep mode __WFI(); #endif #ifdef DEBUG_STOP_MODE uint16_t sleepTime = radiotimer_getPeriod() - radiotimer_getCapturedTime(); DBGMCU_Config(DBGMCU_STOP, ENABLE); // Enable PWR and BKP clock RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE); // Desable the SRAM and FLITF clock in Stop mode RCC_AHBPeriphClockCmd(RCC_AHBPeriph_SRAM | RCC_AHBPeriph_FLITF, DISABLE); // enter stop mode PWR_EnterSTOPMode(PWR_Regulator_ON,PWR_STOPEntry_WFI); if(sleepTime > 0) opentimers_sleepTimeCompesation(sleepTime); #endif }