int NRF24L01_Reset() { NRF24L01_FlushTx(); NRF24L01_FlushRx(); u8 status1 = Strobe(NOP); u8 status2 = NRF24L01_ReadReg(0x07); NRF24L01_SetTxRxMode(TXRX_OFF); return (status1 == status2 && (status1 & 0x0f) == 0x0e); }
// ************************************************************************************************* // @fn radio_reset // @brief Reset radio core. // @param none // @return none // ************************************************************************************************* void radio_reset(void) { volatile u16 i; u8 x; // Reset radio core Strobe(RF_SRES); // Wait before checking IDLE for (i = 0; i < 100; i++) ; do { x = Strobe(RF_SIDLE); } while ((x & 0x70) != 0x00); // Clear radio error register RF1AIFERR = 0; }
void ReceiveOn(void) { RF1AIES |= BIT9; // Falling edge of RFIFG9 RF1AIFG &= ~BIT9; // Clear a pending interrupt RF1AIE |= BIT9; // Enable the interrupt // Radio is in IDLE following a TX, so strobe SRX to enter Receive Mode Strobe( RF_SRX ); }
void rxtx_finish_isr() { //Disable interrupts radioDisableGDO0Interrupt(); radioDisableGDO2Interrupt(); if (init_and_close_radio) { //Flush FIFOs and go to sleep Strobe(RF_SIDLE); Strobe(RF_SFRX); Strobe(RF_SFTX); Strobe(RF_SPWD); //Set radio state state = Idle; } }
void Joystick::write(unsigned char value) { if (((value & 1) == 1) && (StrobeOnNext == false)) StrobeOnNext = true; else if (((value & 1) == 0) && (StrobeOnNext == true)) { Strobe(); StrobeOnNext = false; } }
void Transmit(unsigned char *buffer, unsigned char length) { RF1AIES |= BIT9; RF1AIFG &= ~BIT9; // Clear pending interrupts RF1AIE |= BIT9; // Enable TX end-of-packet interrupt WriteBurstReg(RF_TXFIFOWR, buffer, length); Strobe( RF_STX ); // Strobe STX }
void ReceiveOn(void) { RF1AIES &= ~BIT9; RF1AIFG = 0; // Clear pending RFIFG interrupts RF1AIE |= BIT9; // Enable the sync word received interrupt // Radio is in IDLE following a TX, so strobe SRX to enter Receive Mode Strobe( RF_SRX ); __no_operation(); }
bool phy_init_tx() { if(get_radiostate() != Idle) { #ifdef LOG_PHY_ENABLED log_print_stack_string(LOG_PHY, "PHY radio not idle"); #endif return false; } //Set radio state state = Transmit; //Go to idle and flush the txfifo Strobe(RF_SIDLE); Strobe(RF_SFTX); return true; }
void ReceiveOn(void) { RF1AIES |= BIT9; // Falling edge of RFIFG9 RF1AIFG &= ~BIT9; // Clear a pending interrupt RF1AIE |= BIT9; // Enable the interrupt // P3OUT |= BIT1; // Radio is in IDLE following a TX, so strobe SRX to enter Receive Mode while( !(RF1AIFCTL1 & RFINSTRIFG)); Strobe( RF_SRX ); }
byte RADIOClass::ReceiveData(byte *rxBuffer) { byte size; byte status[2]; if(ReadStatusReg(RADIO_RXBYTES) & BURST_BYTES_IN_TXFIFO) // 0x7F MULTIPLE TRY PRESENT BF { size=ReadSingleReg(RADIO_RXFIFO); ReadBurstReg(RADIO_RXFIFO,rxBuffer,size); ReadBurstReg(RADIO_RXFIFO,status,2); Strobe(RADIO_SFRX); return size; } else { Strobe(RADIO_SFRX); return 0; } }
unsigned char Joystick::read() { char BitReturn = BitStream[BitIndex]; BitIndex++; // Check to see if read past the joysticks data. Not likely that this // will happen but its possible. if (BitIndex >= 24) Strobe(); return BitReturn; }
void Init_RF(void){ // Increase PMMCOREV level to 2 in order to avoid low voltage error // when the RF core is enabled SetVCore(2); ResetRadioCore(); WriteBurstReg(IOCFG2, (unsigned char*)RF1A_REGISTER_CONFIG, CONF_REG_SIZE); WritePATable(); InitButtonLed(); ReceiveOn(); //Wait for RX status to be reached while((Strobe(RF_SNOP) & 0x70) != 0x10); }
//------------------------------------------------------------------------------ // void pktRxHandler(void) // // DESCRIPTION: // This function is called every time a timer interrupt occurs. The // function starts by retreiving the status byte. Every time the status // byte indicates that there are available bytes in the RX FIFO, bytes are // read from the RX FIFO and written to RxBuffer. This is done until the // whole packet is received. If the status byte indicates that there has // been an RX FIFO overflow the RX FIFO is flushed. Please see the // EM430F5137RF900 RF Examples User Manual for a flow chart describing this // function. //------------------------------------------------------------------------------ void pktRxHandler(void) { unsigned char RxStatus; unsigned char bytesInFifo; // Which state? RxStatus = Strobe(RF_SNOP); switch(RxStatus & CC430_STATE_MASK) { case CC430_STATE_RX: // If there's anything in the RX FIFO.... if (bytesInFifo = MIN(rxBytesLeft, RxStatus & CC430_FIFO_BYTES_AVAILABLE_MASK)) { if((rxBytesLeft == PACKET_LEN + 2) && !lengthByteRead) { rxBytesLeft = ReadSingleReg(RXFIFO) + 2; // For appended bytes lengthByteRead = 1; } // Update how many bytes are left to be received rxBytesLeft -= bytesInFifo; // Read from RX FIFO and store the data in rxBuffer while (bytesInFifo--) { RxBuffer[rxPosition] = ReadSingleReg(RXFIFO); rxPosition++; } if (!rxBytesLeft){ packetReceived = 1; receiving = 0; lengthByteRead = 0; ReceiveOff(); P1OUT ^= BIT0; // Toggle LED1 } } break; default: if(!packetReceived) { packetReceived = 1; } rxBytesLeft = 0; receiving = 0; ReceiveOff(); break; } } // pktRxHandler
// send data extern bool phy_tx_data(phy_tx_cfg_t* cfg) { //TODO Return error if fec not enabled but requested #ifdef D7_PHY_USE_FEC if (fec) { //Initialize fec encoding fec_init_encode(cfg->data); //Configure length settings set_length_infinite(true); fec_set_length(cfg->length); remainingBytes = ((cfg->length & 0xFE) + 2) << 1; WriteSingleReg(PKTLEN, (uint8_t)(remainingBytes & 0x00FF)); } else { #endif //Set buffer position bufferPosition = cfg->data; //Configure length settings set_length_infinite(false); remainingBytes = cfg->length; WriteSingleReg(PKTLEN, (uint8_t)remainingBytes); #ifdef D7_PHY_USE_FEC } #endif //Write initial data to txfifo tx_data_isr(); //Configure txfifo threshold WriteSingleReg(FIFOTHR, RADIO_FIFOTHR_FIFO_THR_17_48); //Enable interrupts radioClearInterruptPendingLines(); phy_set_gdo_values(GDOLine2, GDO_EDGE_TXBelowThresh, GDO_SETTING_TXBelowThresh); // phy_set_gdo_values(GDOLine2, GDO_EDGE_TXUnderflow, GDO_SETTING_TXUnderflow); phy_set_gdo_values(GDOLine0, GDO_EDGE_EndOfPacket, GDO_SETTING_EndOfPacket); radioEnableGDO2Interrupt(); radioEnableGDO0Interrupt(); //Start transmitting Strobe(RF_STX); return true; }
extern int16_t phy_get_rssi(uint8_t spectrum_id, uint8_t sync_word_class) { uint8_t rssi_raw = 0; if (!phy_translate_and_set_settings(spectrum_id, sync_word_class)) return false; //Start receiving Strobe(RF_SRX); //FIXME wait for RSSI VALID!!! // Is this possible with CC1101? rssi_raw = ReadSingleReg(RSSI); rxtx_finish_isr(); return calculate_rssi(rssi_raw); }
void TransmitPacket(void) { P3OUT |= BIT6; // Pulse LED during Transmit txBytesLeft = PACKET_LEN; txPosition = 0; packetTransmit = 0; transmitting = 1; Strobe( RF_STX ); // Strobe STX TA0CCR1 = TX_TIMER_PERIOD; // x cycles * 1/32768 = y us TA0CCTL1 |= CCIE; TA0CTL |= MC_2 + TACLR; // Start the timer- continuous mode __bis_SR_register(LPM3_bits + GIE); __no_operation(); TA0CCR1 = TX_TIMER_PERIOD; // x cycles * 1/32768 = y us TA0CCTL1 &= ~(CCIE); TA0CTL &= ~(MC_3); // Turn off timer P3OUT &= ~BIT6; // Turn off LED after Transmit }
u8 NRF24L01_FlushRx() { return Strobe(FLUSH_RX); }
void main() { system_init(buffer, sizeof(buffer), buffer, sizeof(buffer)); #if RF == CC1101 || RF == CC1120 spi_init(); #endif ResetRadioCore(); int p = ReadSingleReg(PARTNUM); log_print_string("PARTNUM 0x%x", p); p = ReadSingleReg(VERSION); log_print_string("VERSION 0x%x", p); log_print_string("started"); WriteRfSettings(&rfSettings); // WriteSingleReg(IOCFG2,0x0B); //GDO2 Output Pin Configuration // WriteSingleReg(IOCFG0,0x0C); //GDO0 Output Pin Configuration // WriteSingleReg(FIFOTHR,0x47); //RX FIFO and TX FIFO Thresholds // WriteSingleReg(PKTCTRL0,0x22); //Packet Automation Control // WriteSingleReg(FSCTRL1,0x08); //Frequency Synthesizer Control // WriteSingleReg(FREQ2,0x10); //Frequency Control Word, High Byte // WriteSingleReg(FREQ1,0xB1); //Frequency Control Word, Middle Byte // WriteSingleReg(FREQ0,0x3A); //Frequency Control Word, Low Byte // WriteSingleReg(MDMCFG4,0xCA); //Modem Configuration // WriteSingleReg(MDMCFG3,0x83); //Modem Configuration // WriteSingleReg(MDMCFG2,0xB0); //Modem Configuration // WriteSingleReg(DEVIATN,0x35); //Modem Deviation Setting // WriteSingleReg(MCSM0,0x18); //Main Radio Control State Machine Configuration // WriteSingleReg(FOCCFG,0x16); //Frequency Offset Compensation Configuration // WriteSingleReg(AGCCTRL2,0x43); //AGC Control // WriteSingleReg(WORCTRL,0xFB); //Wake On Radio Control // WriteSingleReg(FREND0,0x11); //Front End TX Configuration // WriteSingleReg(FSCAL3,0xE9); //Frequency Synthesizer Calibration // WriteSingleReg(FSCAL2,0x2A); //Frequency Synthesizer Calibration // WriteSingleReg(FSCAL1,0x00); //Frequency Synthesizer Calibration // WriteSingleReg(FSCAL0,0x1F); //Frequency Synthesizer Calibration // WriteSingleReg(TEST2,0x81); //Various Test Settings // WriteSingleReg(TEST1,0x35); //Various Test Settings // WriteSingleReg(TEST0,0x09); //Various Test Settings // WriteSingleReg(RSSI,0x80); //Received Signal Strength Indication // WriteSingleReg(MARCSTATE,0x01); //Main Radio Control State Machine State // WriteSingleReg(VCO_VC_DAC,0x94);//Current Setting from PLL Calibration Module //phy_keep_radio_on(true); Strobe(RF_SIDLE); Strobe(RF_SFTX); //uint8_t spectrum_id[2] = { 4, 0 }; //phy_translate_and_set_settings(spectrum_id, 0); //set_length_infinite(false); //WriteSingleReg(PKTLEN, 7); Strobe(RF_STX); //WriteSingleReg(PKTCTRL0, 0x22); //WriteSingleReg(FIFOTHR, RADIO_FIFOTHR_FIFO_THR_17_48); //WriteBurstReg(RF_TXFIFOWR, packet, 7); /* ResetRadioCore(); log_state(); Strobe(RF_SIDLE); WriteRfSettings(&rfSettings); log_print_string("wrote settings"); log_state(); Strobe(RF_STX); log_print_string("strobed TX"); */ int i; for(i = 0; i < 50;i++) { log_state(); } while(1); }
u8 NRF24L01_FlushTx() { return Strobe(FLUSH_TX); }
bool phy_rx(phy_rx_cfg_t* cfg) { #ifdef LOG_PHY_ENABLED log_print_stack_string(LOG_PHY, "phy_rx"); #endif RadioState current_state = get_radiostate(); if(current_state != Idle && current_state != Receive) { #ifdef LOG_PHY_ENABLED log_print_stack_string(LOG_PHY, "PHY Cannot RX, PHy not idle"); #endif return false; } //Set radio state state = Receive; //Flush the txfifo Strobe(RF_SIDLE); Strobe(RF_SFRX); //Set configuration if (!phy_translate_and_set_settings(cfg->spectrum_id, cfg->sync_word_class)) return false; set_timeout(cfg->timeout); //TODO Return error if fec not enabled but requested #ifdef D7_PHY_USE_FEC if (fec) { //Disable hardware data whitening set_data_whitening(false); //Initialize fec encoding fec_init_decode(buffer); //Configure length settings set_length_infinite(true); if(cfg->length == 0) { packetLength = 0; remainingBytes = 0; WriteSingleReg(PKTLEN, 0xFF); WriteSingleReg(FIFOTHR, RADIO_FIFOTHR_FIFO_THR_61_4); } else { fec_set_length(cfg->length); packetLength = ((cfg->length & 0xFE) + 2) << 1; remainingBytes = packetLength; WriteSingleReg(PKTLEN, (uint8_t)(packetLength & 0x00FF)); WriteSingleReg(FIFOTHR, RADIO_FIFOTHR_FIFO_THR_17_48); } } else { #endif //Enable hardware data whitening set_data_whitening(true); //Set buffer position bufferPosition = buffer; //Configure length settings and txfifo threshold set_length_infinite(false); if(cfg->length == 0) { packetLength = 0; remainingBytes = 0; WriteSingleReg(PKTLEN, 0xFF); WriteSingleReg(FIFOTHR, RADIO_FIFOTHR_FIFO_THR_61_4); } else { packetLength = cfg->length; remainingBytes = packetLength; WriteSingleReg(PKTLEN, packetLength); WriteSingleReg(FIFOTHR, RADIO_FIFOTHR_FIFO_THR_17_48); } #ifdef D7_PHY_USE_FEC } #endif //TODO: set minimum sync word rss to scan minimum energy //Enable interrupts phy_set_gdo_values(GDOLine2, GDO_EDGE_RXFilled, GDO_SETTING_RXFilled); phy_set_gdo_values(GDOLine0, GDO_EDGE_EndOfPacket, GDO_SETTING_EndOfPacket); radioClearInterruptPendingLines(); radioEnableGDO2Interrupt(); radioEnableGDO0Interrupt(); //Start receiving Strobe(RF_SRX); return true; }
int main(void) { //TURN OFF POWER TO THINGS I DON'T NEED ADCSRA = 0; //DISABLE ADC PRR0 = _BV(PRTWI) | _BV(PRADC) | _BV(PRSPI); //TURN OFF POWER TO ADC, TWI, SPI //SET UP GP TIMER TCCR2A = _BV(WGM21); //CTC MODE TCCR2B = _BV(CS20) | _BV(CS21) | _BV(CS22); // /1024 prescale TIMSK2 = _BV(OCIE2A); // CTCIE OCR2A = 155; //100.16026 Hz (~10mS) //SET UP STATUS LED CONFIG_LED(); ///////////////////////////////////////// //SET UP STATE ENUMS enum D_State {SERIAL_DEBUG, NORMAL}; enum V_State {INIT, WAIT, RUN, ERROR}; enum V_NextState {LOWER, HEADLOWER, BODYTWITCH, INTERMISSION1, RAISE, HEADRAISE, HEADTILT, LOWERTILTROD, \ LOWERHOIST, INTERMISSION2}; //SET UP TIMING CONSTANTS //*_LONG = 0.5 SECONDS //*_SHORT = 10mS const uint16_t CHOP_PAUSE_LONG = SETTIMERSEC(20); //pause between intermission and blade lower const uint16_t HEAD_DROP_PAUSE_LONG = 1; ///////////turn to short const uint16_t BODY_TWITCH_START_PAUSE_LONG = 0; //////////turn to short const uint16_t INTERMISSION1_PAUSE_LONG = SETTIMERMIN(1); //pause between reset and lower const uint16_t RAISE_PAUSE_LONG = SETTIMERSEC(30); //pause after blade lower to raise again const uint16_t HEAD_RAISE_PAUSE_LONG = SETTIMERSEC(15); //pause after blade raised to raise head const uint16_t HEAD_TILT_PAUSE_LONG = SETTIMERSEC(1); //pause after head raise to tilt head into lock const uint16_t LOWER_TILT_ROD_PAUSE_LONG = SETTIMERSEC(1); //pause between reset and lower const uint16_t LOWER_HOIST_PAUSE_LONG = 0; //pause between reset and lower const uint16_t INTERMISSION2_PAUSE_LONG = SETTIMERMIN(1); //pause between reset and lower //SET UP GUILLOTINE OBJECTS DebugSerial DBSerial = DebugSerial(115200); MusicSerial myMusic = MusicSerial(38400); Blade myBlade = Blade(ptr_Timer); Head myHead = Head(ptr_Timer); Button myButton = Button(ptr_Timer); Strobe myStrobe = Strobe(ptr_Timer); Body myBody = Body(ptr_Timer); //Guy myGuy = Guy(ptr_Timer); //Music myMusic = Music(); //SET UP LOCAL (MAIN SCOPED) VARIABLES D_State debugMode = NORMAL; //STARTS UP IN NORMAL MODE V_State state = INIT; //INITIAL MAIN STATE V_NextState nextState = LOWER; //HOLDS NEXT RUN STATE uint16_t longTime = 0; //HOLDS SECONDS uint8_t forceNextState = 0; //FLAG THAT BUTTON PRESS WHILE IN WAIT STATE uint8_t pollState = 0; //HOLDS POLLING INFO (WORKING, COMPLETE, ERROR) uint16_t nextWaitTime = 0; //HOLDS PAUSE TO NEXT RUN STATE uint8_t errorTry = 0; sei(); if (myButton.read()) debugMode = SERIAL_DEBUG; #ifdef DEBUG debugMode = SERIAL_DEBUG; #endif // DEBUG #ifdef SND_STARTUP myMusic.playHold(SND_STARTUP, &myButton); #endif // SND_STARTUP while(1) { if (DBSerial.available()) { if (DBSerial.read() == 'D') debugMode = SERIAL_DEBUG; } switch (debugMode) { case NORMAL: switch (state) { //INIT: SET GUILLOTINE TO DEFAULT POSITIONS // BLADE UP, HEAD UP, HEAD TILT UP case INIT: { LED_OFF(); #ifdef SND_ENTERINIT myMusic.playHold(SND_ENTERINIT, &myButton); #endif // SND_ENTERINIT if (myBlade.init() == Blade::ERROR) //MOVE BLADE TO UP POSITION { state = ERROR; break; } else if (myHead.init() == Head::ERROR) //MOVE HEAD TILT ROD TO HOME POSITION { state = ERROR; break; } else if (myBody.init() == Body::ERROR) //MAKE SURE LEGS WORKING { state = ERROR; break; } //if (myGuy.isGuyHere()) myGuy.init(); myStrobe.init(); #ifdef SND_LEAVEINIT myMusic.playHold(SND_LEAVEINIT, &myButton); #endif // SND_LEAVEINIT state = WAIT; nextState = LOWER; nextWaitTime = CHOP_PAUSE_LONG; #ifdef SND_LOWER_BEFORE myMusic.playHold(SND_LOWER_BEFORE, &myButton); #endif // SND_LOWER_BEFORE setTimer(); //SO WAIT STATE STARTS WITH TIMER AT 0 break; } //WAIT: WAIT UNTIL TIME TO DO nextState // IF BUTTON PRESS, MOVE TO NEXT STATE NOW case WAIT: if (getTimer() >= 50) //Increment longTime at 1/2 second interval { longTime++; setTimer(); } forceNextState = myButton.read(); if (longTime >= nextWaitTime || forceNextState) { state = RUN; longTime = 0; } break; case RUN: { switch (nextState) { case LOWER: #ifdef SND_LOWER_ON myMusic.trigger(SND_LOWER_ON); #endif // SND_LOWER_ON /* pollState = Guy::WORKING; * myGuy.pullLeverPoll(Guy::RESET); * while (pollState != Guy::COMPLETE && pollState != Guy::ERROR) * { * pollState = myGuy.pullLeverPoll(); * if(myButton.read()) * { * break; * } * } */ pollState = Blade::WORKING; myBlade.lowerBladePoll(Blade::RESET); while (pollState != Blade::COMPLETE && pollState != Blade::ERROR) { pollState = myBlade.lowerBladePoll(); if(myButton.read()) { pollState = Blade::ERROR; break; } } if (pollState == Blade::ERROR) { state = ERROR; } ////GOTO NEXT STATE AND SETUP NEXT EVENT else { #ifdef SND_LOWER_AFTER myMusic.trigger(SND_LOWER_AFTER); #endif // SND_LOWER_AFTER state = WAIT; nextState = HEADLOWER; nextWaitTime = HEAD_DROP_PAUSE_LONG; #ifdef SND_HEAD_LOWER_BEFORE myMusic.trigger(SND_HEAD_LOWER_BEFORE); #endif // SND_HEAD_LOWER_BEFORE } break; case HEADLOWER: #ifdef SND_HEAD_LOWER_ON myMusic.playHold(SND_HEAD_LOWER_ON, &myButton); #endif // SND_HEAD_LOWER_ON pollState = Head::WORKING; myHead.lowerHeadPoll(Head::RESET); while (pollState != Head::COMPLETE && pollState != Head::ERROR) { pollState = myHead.lowerHeadPoll(); if(myButton.read()) { pollState = Head::ERROR; break; } } if (pollState == Head::ERROR) state = ERROR; ////GOTO NEXT STATE AND SETUP NEXT EVENT else { #ifdef SND_HEAD_LOWER_AFTER myMusic.playHold(SND_HEAD_LOWER_AFTER, &myButton); #endif // SND_HEAD_LOWER_AFTER state = WAIT; nextState = BODYTWITCH; nextWaitTime = BODY_TWITCH_START_PAUSE_LONG; #ifdef SND_BODY_BEFORE myMusic.trigger(SND_BODY_BEFORE); #endif // SND_BODY_BEFORE } break; case BODYTWITCH: #ifdef SND_BODY_ON myMusic.trigger(SND_BODY_ON); #endif // SND_BODY_ON //myBody.bodyTwitch(); pollState = Body::WORKING; myBody.bodyKickPoll(Body::RESET); while (pollState != Body::COMPLETE && pollState != Body::ERROR) { pollState = myBody.bodyKickPoll(); if(myButton.read()) { pollState = Body::ERROR; break; } } if (pollState == Body::ERROR) state = ERROR; ////GOTO NEXT STATE AND SETUP NEXT EVENT else { #ifdef SND_BODY_AFTER myMusic.trigger(SND_BODY_AFTER); #endif // SND_BODY_AFTER state = WAIT; nextState = INTERMISSION1; nextWaitTime = INTERMISSION1_PAUSE_LONG; #ifdef SND_INT1_BEFORE myMusic.trigger(SND_INT1_BEFORE); #endif // SND_INT1_BEFORE } break; case INTERMISSION1: #ifdef SND_INT1_ON myMusic.trigger(SND_INT1_ON); #endif // SND_INT1_ON myStrobe.strobeOn(); pollState = Body::WORKING; myBody.bodyKickPoll(Body::RESET); while (pollState != Body::COMPLETE && pollState != Body::ERROR) { pollState = myBody.bodyKickPoll(); if(myButton.read()) { pollState = Body::ERROR; break; } } myStrobe.strobeOff(); #ifdef SND_INT1_AFTER myMusic.trigger(SND_INT1_AFTER); #endif // SND_INT1_AFTER state = WAIT; nextState = RAISE; nextWaitTime = RAISE_PAUSE_LONG; #ifdef SND_RAISE_BEFORE myMusic.trigger(SND_RAISE_BEFORE); #endif // SND_RAISE_BEFORE break; case RAISE: #ifdef SND_RAISE_ON myMusic.trigger(SND_RAISE_ON); #endif // SND_RAISE_ON /* pollState = Guy::WORKING; * myGuy.resetLeverPoll(Guy::RESET); * while (pollState != Guy::COMPLETE && pollState != Guy::ERROR) * { * pollState = myGuy.resetLeverPoll(); * if(myButton.read()) * { * break; * } * } */ pollState = Blade::WORKING; myBlade.raiseBladePoll(Blade::RESET); while (pollState != Blade::COMPLETE && pollState != Blade::ERROR) { pollState = myBlade.raiseBladePoll(); if(myButton.read()) { pollState = Head::ERROR; break; } } if (pollState == Blade::ERROR) state = ERROR; ////GOTO NEXT STATE AND SETUP NEXT EVENT else { #ifdef SND_RAISE_AFTER myMusic.trigger(SND_RAISE_AFTER); #endif // SND_RAISE_AFTER state = WAIT; nextState = HEADRAISE; nextWaitTime = HEAD_RAISE_PAUSE_LONG; #ifdef SND_HEAD_RAISE_BEFORE myMusic.trigger(SND_HEAD_RAISE_BEFORE); #endif // SND_HEAD_RAISE_BEFORE } break; case HEADRAISE: #ifdef SND_HEAD_RAISE_ON myMusic.trigger(SND_HEAD_RAISE_ON); #endif // SND_HEAD_RAISE_ON pollState = Head::WORKING; myHead.raiseHeadPoll(Head::RESET); while (pollState != Head::COMPLETE && pollState != Head::ERROR) { pollState = myHead.raiseHeadPoll(); if(myButton.read()) { pollState = Head::ERROR; break; } } if (pollState == Head::ERROR) state = ERROR; ////GOTO NEXT STATE AND SETUP NEXT EVENT else { #ifdef SND_HEAD_RAISE_AFTER myMusic.trigger(SND_HEAD_RAISE_AFTER); #endif // SND_HEAD_RAISE_AFTER state = WAIT; nextState = HEADTILT; nextWaitTime = HEAD_TILT_PAUSE_LONG; #ifdef SND_HEAD_TILT_BEFORE myMusic.trigger(SND_HEAD_TILT_BEFORE); #endif // SND_HEAD_TILT_BEFORE } break; case HEADTILT: #ifdef SND_HEAD_TILT_ON myMusic.trigger(SND_HEAD_TILT_ON); #endif // SND_HEAD_TILT_ON pollState = Head::WORKING; myHead.tiltHeadUpPoll(Head::RESET); while (pollState != Head::COMPLETE && pollState != Head::ERROR) { pollState = myHead.tiltHeadUpPoll(); if(myButton.read()) { pollState = Head::ERROR; break; } } if (pollState == Head::ERROR) state = ERROR; ////GOTO NEXT STATE AND SETUP NEXT EVENT else { #ifdef SND_HEAD_TILT_AFTER myMusic.playHold(SND_HEAD_TILT_AFTER, &myButton); #endif // SND_HEAD_TILT_AFTER state = WAIT; nextState = LOWERTILTROD; nextWaitTime = LOWER_TILT_ROD_PAUSE_LONG; #ifdef SND_LOWER_TILT_BEFORE myMusic.trigger(SND_LOWER_TILT_BEFORE); #endif // SND_LOWER_TILT_BEFORE } break; case LOWERTILTROD: #ifdef SND_LOWER_TILT_ON myMusic.trigger(SND_LOWER_TILT_ON); #endif // SND_LOWER_TILT_ON pollState = Head::WORKING; myHead.tiltRodDownPoll(Head::RESET); while (pollState != Head::COMPLETE && pollState != Head::ERROR) { pollState = myHead.tiltRodDownPoll(); if(myButton.read()) { pollState = Head::ERROR; break; } } if (pollState == Head::ERROR) state = ERROR; ////GOTO NEXT STATE AND SETUP NEXT EVENT else { #ifdef SND_LOWER_TILT_AFTER myMusic.trigger(SND_LOWER_TILT_AFTER); #endif // SND_LOWER_TILT_AFTER state = WAIT; nextState = LOWERHOIST; nextWaitTime = LOWER_HOIST_PAUSE_LONG; #ifdef SND_LOWER_HOIST_BEFORE myMusic.trigger(SND_LOWER_HOIST_BEFORE); #endif // SND_LOWER_HOIST_BEFORE } break; case LOWERHOIST: #ifdef SND_LOWER_HOIST_ON myMusic.trigger(SND_LOWER_HOIST_ON); #endif // SND_LOWER_HOIST_ON pollState = Head::WORKING; myHead.lowerHoistPoll(Head::RESET); while (pollState != Head::COMPLETE && pollState != Head::ERROR) { pollState = myHead.lowerHoistPoll(); if(myButton.read()) { pollState = Head::ERROR; break; } } if (pollState == Head::ERROR) state = ERROR; ////GOTO NEXT STATE AND SETUP NEXT EVENT else { #ifdef SND_LOWER_HOIST_AFTER myMusic.trigger(SND_LOWER_HOIST_AFTER); #endif // SND_LOWER_HOIST_AFTER state = WAIT; nextState = INTERMISSION2; nextWaitTime = INTERMISSION2_PAUSE_LONG; #ifdef SND_INT2_BEFORE myMusic.trigger(SND_INT2_BEFORE); #endif // SND_INT2_BEFORE } break; case INTERMISSION2: #ifdef SND_INT2_ON myMusic.trigger(SND_INT2_ON); #endif // SND_INT2_ON myStrobe.strobeOn(); myStrobe.strobeOn(); pollState = Body::WORKING; myBody.bodyKickPoll(Body::RESET); while (pollState != Body::COMPLETE && pollState != Body::ERROR) { pollState = myBody.bodyKickPoll(); if(myButton.read()) { pollState = Body::ERROR; break; } } myStrobe.strobeOff(); #ifdef SND_INT2_AFTER myMusic.trigger(SND_INT2_AFTER); #endif // SND_INT2_AFTER state = WAIT; nextState = LOWER; nextWaitTime = CHOP_PAUSE_LONG; #ifdef SND_LOWER_BEFORE myMusic.playHold(SND_LOWER_BEFORE, &myButton); #endif // SND_LOWER_BEFORE break; } break; } case ERROR: if (errorTry <= NUM_OF_ERROR_TRY) { errorTry++; #ifdef SND_OOPS myMusic.playHold(SND_OOPS, &myButton); #endif // SND_OOPS state = RUN; break; } else { errorTry = 0; LED_ON(); myMusic.stop(); myBlade.turnOff(); myHead.turnOff(); myBody.turnOff(); myStrobe.strobeOff(); #ifdef SND_ENTERERROR myMusic.playHold(SND_ENTERERROR, &myButton); #endif // SND_ENTERERROR uint8_t checkSerial = 0; while (!myButton.read() && checkSerial != 'D') { if (DBSerial.available()) { checkSerial = DBSerial.read(); } } if (checkSerial == 'D') debugMode = SERIAL_DEBUG; else state = INIT; #ifdef SND_LEAVEERROR myMusic.playHold(SND_LEAVEERROR, &myButton); #endif // SND_LEAVEERROR } break; } break; case SERIAL_DEBUG: LED_OFF(); #ifdef SND_ENTERDEBUG myMusic.playHold(SND_ENTERDEBUG, &myButton); #endif // SND_ENTERDEBUG DBSerial.println(const_cast <char*> ("\n\r[--DBMode--]")); myBlade.printDebug(&DBSerial); myHead.printDebug(&DBSerial); myBody.printDebug(&DBSerial); DBSerial.println(const_cast <char*> ("\n\r---")); while (debugMode == SERIAL_DEBUG && !myButton.read()) { if (DBSerial.available()) { switch (DBSerial.read()) { case 'd': debugMode = NORMAL; break; case 'e': myBlade.printDebug(&DBSerial); myHead.printDebug(&DBSerial); myBody.printDebug(&DBSerial); DBSerial.println(const_cast <char*> ("\n\r---")); break; case 32: //SPACEBAR DBSerial.println(const_cast <char*> ("[B]lade up / [b]lade down")); DBSerial.println(const_cast <char*> ("[M]ag on / [m]ag off")); DBSerial.println(const_cast <char*> ("[H]ead up / [h]ead down")); DBSerial.println(const_cast <char*> ("h[O]ist down")); DBSerial.println(const_cast <char*> ("[T]ilt up / [t]ilt down")); DBSerial.println(const_cast <char*> ("head [R]elease on / [r]elease off")); DBSerial.println(const_cast <char*> ("bod[Y] on / bod[y] off")); DBSerial.println(const_cast <char*> ("[S]trobe on / [s]trobe off")); DBSerial.println(const_cast <char*> ("[L]ed on / [l]ed off")); DBSerial.println(const_cast <char*> ("m[U]sic on / off")); DBSerial.println(const_cast <char*> ("[N]ext track / [P]rev track")); //DBSerial.println(const_cast <char*> ("[A]rm Pull / [a]reset arm")); DBSerial.println(const_cast <char*> ("d[e]bug info")); break; /* case 'A': * DBSerial.print(const_cast <char*> ("Arm Pull..")); * pollState = Guy::WORKING; * myGuy.pullLeverPoll(Guy::RESET); * while (pollState != Guy::COMPLETE && pollState != Guy::ERROR) pollState = myGuy.pullLeverPoll(); * if (pollState == Guy::COMPLETE) DBSerial.println(const_cast <char*> ("Good")); * else DBSerial.println(const_cast <char*> ("Error")); * break; * * case 'a': * DBSerial.print(const_cast <char*> ("Arm Reset..")); * pollState = Guy::WORKING; * myGuy.resetLeverPoll(Guy::RESET); * while (pollState != Guy::COMPLETE && pollState != Guy::ERROR) pollState = myGuy.resetLeverPoll(); * if (pollState == Guy::COMPLETE) DBSerial.println(const_cast <char*> ("Good")); * else DBSerial.println(const_cast <char*> ("Error")); * break; */ case 'B': DBSerial.print(const_cast <char*> ("Blade Up..")); pollState = Blade::WORKING; myBlade.raiseBladePoll(Blade::RESET); while (pollState != Blade::COMPLETE && pollState != Blade::ERROR) pollState = myBlade.raiseBladePoll(); if (pollState == Blade::COMPLETE) DBSerial.println(const_cast <char*> ("Good")); else DBSerial.println(const_cast <char*> ("Error")); break; case 'b': DBSerial.print(const_cast <char*> ("Blade Down..")); pollState = Blade::WORKING; myBlade.lowerBladePoll(Blade::RESET); while (pollState != Blade::COMPLETE && pollState != Blade::ERROR) pollState = myBlade.lowerBladePoll(); if (pollState == Blade::COMPLETE) DBSerial.println(const_cast <char*> ("Good")); else DBSerial.println(const_cast <char*> ("Error")); break; case 'M': DBSerial.println(const_cast <char*> ("Mag On")); myBlade.mag(1); break; case 'm': DBSerial.println(const_cast <char*> ("Mag Off")); myBlade.mag(0); break; case 'H': DBSerial.print(const_cast <char*> ("Head Up..")); pollState = Head::WORKING; myHead.raiseHeadPoll(Head::RESET); while (pollState != Head::COMPLETE && pollState != Head::ERROR) pollState = myHead.raiseHeadPoll(); if (pollState == Head::COMPLETE) DBSerial.println(const_cast <char*> ("Good")); else DBSerial.println(const_cast <char*> ("Error")); break; case 'h': DBSerial.print(const_cast <char*> ("Head Down..")); pollState = Head::WORKING; myHead.lowerHeadPoll(Head::RESET); while (pollState != Head::COMPLETE && pollState != Head::ERROR) pollState = myHead.lowerHeadPoll(); if (pollState == Head::COMPLETE) DBSerial.println(const_cast <char*> ("Good")); else DBSerial.println(const_cast <char*> ("Error")); break; case 'O': DBSerial.print(const_cast <char*> ("Hoist Down..")); pollState = Head::WORKING; myHead.lowerHoistPoll(Head::RESET); while (pollState != Head::COMPLETE && pollState != Head::ERROR) pollState = myHead.lowerHoistPoll(); if (pollState == Head::COMPLETE) DBSerial.println(const_cast <char*> ("Good")); else DBSerial.println(const_cast <char*> ("Error")); break; case 'T': DBSerial.print(const_cast <char*> ("Tilt Up..")); pollState = Head::WORKING; myHead.tiltHeadUpPoll(Head::RESET); while (pollState != Head::COMPLETE && pollState != Head::ERROR) pollState = myHead.tiltHeadUpPoll(); if (pollState == Head::COMPLETE) DBSerial.println(const_cast <char*> ("Good")); else DBSerial.println(const_cast <char*> ("Error")); break; case 't': DBSerial.print(const_cast <char*> ("Tilt Down..")); pollState = Head::WORKING; myHead.tiltRodDownPoll(Head::RESET); while (pollState != Head::COMPLETE && pollState != Head::ERROR) pollState = myHead.tiltRodDownPoll(); if (pollState == Head::COMPLETE) DBSerial.println(const_cast <char*> ("Good")); else DBSerial.println(const_cast <char*> ("Error")); break; case 'R': DBSerial.println(const_cast <char*> ("Solenoid On")); myHead.sol(1); break; case 'r': DBSerial.println(const_cast <char*> ("Solenoid Off")); myHead.sol(0); break; case 'Y': DBSerial.println(const_cast <char*> ("Body On..")); //myBody.bodyTwitch(); myBody.bodyOn(); break; case 'y': DBSerial.println(const_cast <char*> ("Body Off..")); myBody.turnOff(); break; case 'S': DBSerial.println(const_cast <char*> ("Strobe On")); myStrobe.strobeOn(); break; case 's': DBSerial.println(const_cast <char*> ("Strobe Off")); myStrobe.strobeOff(); break; case 'L': DBSerial.println(const_cast <char*> ("LED On")); LED_ON(); break; case 'l': DBSerial.println(const_cast <char*> ("LED Off")); LED_OFF(); break; case 'U': DBSerial.println(const_cast <char*> ("Music Toggle")); myMusic.togglePlay(); break; case 'N': DBSerial.println(const_cast <char*> ("Next Track")); myMusic.nextTrack(); break; case 'P': DBSerial.println(const_cast <char*> ("Prev Track")); myMusic.prevTrack(); break; } } } #ifdef SND_LEAVEDEBUG myMusic.playHold(SND_LEAVEDEBUG, &myButton); #endif // SND_LEAVEDEBUG state = INIT; debugMode = NORMAL; DBSerial.println(const_cast <char*> ("Exit")); break; } } }
// ************************************************************************************************* // @fn ResetRadioCore // @brief Software reset radio core. // @param none // @return none // ************************************************************************************************* void ResetRadioCore(void) { Strobe(RF_SRES); // Reset the Radio Core Strobe(RF_SNOP); // Reset Radio Pointer }
void RADIOClass::SetReceive(void) { Strobe(RADIO_SRX); }
int main(void) { // Stop watchdog timer DoWatchdog(0); // sET UP aclk BCSCTL3 |= LFXT1S_2; // Set all pins to output to stop floating P1DIR = 0xFF; P2DIR = 0xFF; P3DIR = 0xFF; DoPWM(); _EINT(); // Determine pulse direction RX_PORT_DIR &= ~(RX_PIN); // leave two rx inputs P2DIR = (BIT1 | BIT3 | BIT4 | BIT5 | BIT6 | BIT7); P2OUT = 0xff; // red light P3OUT = BIT2; nR = nG = nB = 0x2FFF; // green light P3OUT = BIT3; while (1) { DelayMS(90); DoWatchdog(1); unsigned int nSig = GetWidth(); if (nSig == 1) { P3OUT = BIT2; if (nCount > 10) { nMode++; if (nCount > 140) { nMode = 0; } } nCount = 0; } else { P3OUT = BIT3; nCount++; } if (nMode > 11) { nMode = 1; } switch (nMode) { case 0: nR = nG = nB = 50; Headlight(0); break; case 1: Light(0xfe00, 0xfe00, 0xfe00, 1); break; case 2: Light(0xfe00, 50, 50, 0); break; case 3: Light(50, 0xfe00, 50, 0); break; case 4: Light(50, 50, 0xfe00, 0); break; case 5: LoopColour(); break; case 6: ColourChange(); break; case 7: Police(); break; case 8: Strobe(); break; case 9: Strobe2(); break; case 10: GoMental(); break; case 11: Chase(); break; } } }
void main( void ) { // Stop watchdog timer to prevent time out reset WDTCTL = WDTPW + WDTHOLD; // Increase PMMCOREV level to 2 in order to avoid low voltage error // when the RF core is enabled SetVCore(2); InitRadio(); InitButtonLeds(); Strobe( RF_SIDLE ); Strobe(RF_SRX); P2DIR |= BIT6; // P2.6 output P2SEL |= BIT6; // P2.6 select //add P2.0 for GD02 - clock sync to TXDATA P2DIR |= BIT0; // P2.0 output P2SEL |= BIT0; // P2.6 select //map P1.0 to GDO1 - high if RSSI above threshold P1DIR |= BIT0; // P1.0 output P1SEL |= BIT0; // P1. select PMAPPWD = 0x02D52; // Get write-access to port mapping regs P2MAP6 = PM_RFGDO0; // Map GDO0 to P2.6 // P2MAP0 = PM_RFGDO2; // Map GDO2 to P2.0 // P1MAP0 = PM_RFGDO1; // Map GDO1 to P1.0 PMAPPWD = 0x00; // Lock Port mapping // Enable timer interrupts to see if input is visible TA1CTL = TASSEL__SMCLK + MC_2 + TACLR; TA1CCTL0 = CM_3 + CCIS_1 + CAP + CCIE; __bis_SR_register(GIE); while(1); #elif defined TEST_ASYNC_TX_MODE // Should serve as internal timer output (toggle rate 19.2 kHz) // to Radio TX input when IOCFG0 = 0x2E (high-Z) // NOTE: SMARTF_CC430 IOCFG0 should = 0x2E so asynchronous signal is taken from // the timer and not GDO0 // TA1CCR0 = 27; // TA1CCR1 = 27; TA1CCR0 = 26; TA1CCR1 = 26; TA1CCTL0 = OUTMOD_4; TA1CCTL1 = OUTMOD_4; TA1CTL = TASSEL__SMCLK + MC_1 + TACLR; P2SEL |= BIT2; P2DIR |= BIT2; PMAPPWD = 0x02D52; // Get write-access to port mapping regs P2MAP2 = PM_TA1CCR0A; // Map CBOUT output to P2.2 PMAPPWD = 0x00; // Lock Port mapping Strobe( RF_SIDLE ); Strobe( RF_STX ); //Transmit the TX waveform asynchronously while(1); #endif // ************NOT USED IN THIS LAB***************************** // Using function generator to generate asynchronous TX signal /* P2OUT |= BIT0; P2DIR |= BIT0; P2SEL |= BIT6; //add P2.0 for GD02 - clock sync to TXDATA P2DIR |= BIT0; // P2.0 output P2SEL |= BIT0; // P2.6 select PMAPPWD = 0x02D52; // Get write-access to port mapping regs P2MAP6 = PM_RFGDO0; // Map CBOUT output to P1.6 P2MAP0 = PM_RFGDO2; // Map GDO2 to P2.0 PMAPPWD = 0x00; // Lock Port mapping // NOTE: SMARTRF_CC430 IOCFG0 shoud = 0x2D so asynchronous signal is taken from // GDO0 and not the internal timer connection */ }