/* void ReceiveFrame() { unsigned char data, node_adrs; unsigned char i = 0; while(!(flag_int1)); { RxPacketLen = ReadFIFO(); flag_int0 = 0; node_adrs = ReadFIFO(); RxPacketLen = (RxPacketLen-1); while(RxPacketLen--) { flag_int0 = 0; data = ReadFIFO(); RxPacket[i] = data; i++; }; RxPacketLen = i; } flag_int1 = 0; //hasPacket = TRUE; //Reset FIFO i = RegisterRead(REG_IRQPARAM0); RegisterSet(REG_IRQPARAM0, (i | 0x01)); } */ unsigned char ReceiveFrame_my(void) { unsigned char dat, node_adrs; unsigned char i = 0; while(!(flag_int1)); RxPacketLen = ReadFIFO(); flag_int0 = 0; node_adrs = ReadFIFO(); RxPacketLen = (RxPacketLen-1); while(RxPacketLen--) { flag_int0 = 0; dat = ReadFIFO(); RxPacket[i] = dat; i++; }; RxPacketLen = i; flag_int1 = 0; //write_spi_con(0x0D, (0x0a)); //перезагрузить фифо i = read_spi_con(REG_IRQPARAM0); write_spi_con(REG_IRQPARAM0, (i | 0x01)); return node_adrs; }
void di_(void) { unsigned char dat, a; unsigned char i = 0; i =read_spi_con(RF_STANDBY); a = 0; while (a<32) { dat = ReadFIFO(); RxPacket[a] = dat; a++; } SetRFMode_my(RF_RECEIVER); }
// Enter RX mode and wait reception for Timeout_ms. uint8_t cc1101_t::ReceiveSync(uint32_t Timeout_ms, void *Ptr, int8_t *PRssi) { FlushRxFIFO(); chSysLock(); PWaitingThread = chThdSelf(); EnterRX(); msg_t Rslt = chSchGoSleepTimeoutS(THD_STATE_SUSPENDED, MS2ST(Timeout_ms)); chSysUnlock(); // Will be here when IRQ will fire, or timeout occur - with appropriate message if(Rslt == RDY_TIMEOUT) { // Nothing received, timeout occured EnterIdle(); // Get out of RX mode return TIMEOUT; } else return ReadFIFO(Ptr, PRssi); }
// Enter RX mode and wait reception for Timeout_st. uint8_t cc1101_t::Receive_st(systime_t Timeout_st, void *Ptr, int8_t *PRssi) { FlushRxFIFO(); chSysLock(); EnterRX(); msg_t Rslt = chThdSuspendTimeoutS(&ThdRef, Timeout_st); // Wait IRQ chSysUnlock(); // Will be here when IRQ will fire, or timeout occur - with appropriate message if(Rslt == MSG_TIMEOUT) { // Nothing received, timeout occured EnterIdle(); // Get out of RX mode return TIMEOUT; } else return ReadFIFO(Ptr, PRssi); return OK; }
/* * Enter RX mode and wait reception for Timeout_ms. */ uint8_t cc1101_t::ReceiveSync(uint32_t Timeout_ms, rPkt_t *pPkt) { FlushRxFIFO(); EnterRX(); // After that, some time will be wasted to recalibrate chSysLock(); PWaitingThread = chThdSelf(); msg_t Rslt = chSchGoSleepTimeoutS(THD_STATE_SUSPENDED, MS2ST(Timeout_ms)); chSysUnlock(); // Will be here when IRQ will fire, or timeout occur - with appropriate message if(Rslt == RDY_TIMEOUT) { // Nothing received, timeout occured EnterIdle(); // Get out of RX mode return TIMEOUT; } // IRQ occured: something received, or CRC error else return ReadFIFO(pPkt); }
uint32 ReadCOM0(uint8 *buf,uint32 len) { uint32 RealLen; //实际读的长度 uint32 RevBufLen; //读、写间差值,即读缓冲区的总长度 RevBufLen = GetNoReadSizeFIFO((stcFIFO *)&sUART0RecFIFO); //求还没有读取空间数据个数 if(RevBufLen > len) { RealLen = len; //读取想要求的数据长度 } else { RealLen = RevBufLen; //读取实际数据长度 } ReadFIFO((stcFIFO *)&sUART0RecFIFO,buf,RealLen); return RealLen; }
/**************************************************************************** Function RunSendBytesStatus Parameters ES_Event: the event to process Returns ES_Event: an event to return Description add your description here Notes uses nested switch/case to implement the machine. Author J. Edward Carryer, 2/11/05, 10:45AM ****************************************************************************/ ES_Event RunSendBytesStatus( ES_Event CurrentEvent ) { bool MakeTransition = false;/* are we making a state transition? */ SendBytesState_t NextState = CurrentState; ES_Event EntryEventKind = { ES_ENTRY, 0 };// default to normal entry to new state ES_Event ReturnEvent = CurrentEvent; // assume we are not consuming event switch ( CurrentState ) { case WAITING_SENDBYTES : // If current state is WAITING // Execute During function for WAITING. ES_ENTRY & ES_EXIT are // processed here allow the lower level state machines to re-map // or consume the event CurrentEvent = DuringWaiting(CurrentEvent); //process any events if ( CurrentEvent.EventType != ES_NO_EVENT ) //If an event is active { switch (CurrentEvent.EventType) { case RETURN_STATUS : //If event is RETURN_STATUS // Execute action function for state one : event one NextState = SENDING_SENDBYTES;//Decide what the next state will be // for internal transitions, skip changing MakeTransition MakeTransition = true; //mark that we are taking a transition // if transitioning to a state with history change kind of entry EntryEventKind.EventType = ES_ENTRY; // optionally, consume or re-map this event for the upper // level state machine ReturnEvent.EventType = ES_NO_EVENT; //This is a status request isStatus = true; PostStatusPAC(CurrentEvent); break; case RETURN_REQUEST : //If event is RETURN_STATUS // Execute action function for state one : event one NextState = SENDING_SENDBYTES;//Decide what the next state will be // for internal transitions, skip changing MakeTransition MakeTransition = true; //mark that we are taking a transition // if transitioning to a state with history change kind of entry EntryEventKind.EventType = ES_ENTRY; // optionally, consume or re-map this event for the upper // level state machine ReturnEvent.EventType = ES_NO_EVENT; PostStatusPAC(CurrentEvent); break; case RETURN_QUERY : //If event is RETURN_STATUS // Execute action function for state one : event one NextState = SENDING_SENDBYTES;//Decide what the next state will be // for internal transitions, skip changing MakeTransition MakeTransition = true; //mark that we are taking a transition // if transitioning to a state with history change kind of entry EntryEventKind.EventType = ES_ENTRY; // optionally, consume or re-map this event for the upper // level state machine ReturnEvent.EventType = ES_NO_EVENT; PostStatusPAC(CurrentEvent); break; case RETURN_PSEUDO_QUERY : //If event is RETURN_STATUS // Execute action function for state one : event one NextState = SENDING_SENDBYTES;//Decide what the next state will be // for internal transitions, skip changing MakeTransition MakeTransition = true; //mark that we are taking a transition // if transitioning to a state with history change kind of entry EntryEventKind.EventType = ES_ENTRY; // optionally, consume or re-map this event for the upper // level state machine ReturnEvent.EventType = ES_NO_EVENT; isPseudo = true; PostStatusPAC(CurrentEvent); break; } } break; case SENDING_SENDBYTES: // If current state is SENDING // Execute During function for SENDING. ES_ENTRY & ES_EXIT are // processed here allow the lower level state machines to re-map // or consume the event CurrentEvent = DuringSending(CurrentEvent); uint8_t freqCode; //process any events if ( CurrentEvent.EventType != ES_NO_EVENT ) //If an event is active { switch (CurrentEvent.EventType) { case RETURN_STATUS : //If event is GET_STATUS #ifdef DEBUG_SENDBYTES printf("\rSending status\r\n"); #endif for (uint8_t i = 0; i < 5; i++) { WriteFIFO(getStatus[i]); #ifdef DEBUG_SENDBYTES printf("%x\r\n",getStatus[i]); #endif } //Enable the NVIC interrupt for the SSI when starting to transmit (or receive?) HWREG(NVIC_BASE+EN0) |= BIT7HI; //Interrupt 7 for SSI0 // Execute action function for state one : event one NextState = WAITING4EOT;//Decide what the next state will be // for internal transitions, skip changing MakeTransition MakeTransition = true; //mark that we are taking a transition // if transitioning to a state with history change kind of entry EntryEventKind.EventType = ES_ENTRY; // optionally, consume or re-map this event for the upper // level state machine ReturnEvent.EventType = ES_NO_EVENT; break; case RETURN_REQUEST : //If event is GET_STATUS freqCode = (uint8_t)CurrentEvent.EventParam; uint8_t myColor = getMyColor(); uint8_t colorCode = ((myColor << 4) | (myColor << 5)); getRequest[0] = 0x80 | freqCode | colorCode; #ifdef DEBUG_SENDBYTES printf("\rCurrent Request\r\n"); #endif for (uint8_t i = 0; i < 5; i++) { WriteFIFO(getRequest[i]); #ifdef DEBUG_SENDBYTES printf("%x\r\n",getRequest[i]); #endif } //Enable the NVIC interrupt for the SSI when starting to transmit (or receive?) HWREG(NVIC_BASE+EN0) |= BIT7HI; //Interrupt 7 for SSI0 // Execute action function for state one : event one NextState = WAITING4EOT;//Decide what the next state will be // for internal transitions, skip changing MakeTransition MakeTransition = true; //mark that we are taking a transition // if transitioning to a state with history change kind of entry EntryEventKind.EventType = ES_ENTRY; // optionally, consume or re-map this event for the upper // level state machine ReturnEvent.EventType = ES_NO_EVENT; break; case RETURN_QUERY : //If event is GET_STATUS #ifdef DEBUG_SENDBYTES printf("\rSending\r\n"); #endif for (uint8_t i = 0; i < 5; i++) { WriteFIFO(getQuery[i]); #ifdef DEBUG_SENDBYTES printf("%x\r\n",getQuery[i]); #endif } //Enable the NVIC interrupt for the SSI when starting to transmit (or receive?) HWREG(NVIC_BASE+EN0) |= BIT7HI; //Interrupt 7 for SSI0 // Execute action function for state one : event one NextState = WAITING4EOT;//Decide what the next state will be // for internal transitions, skip changing MakeTransition MakeTransition = true; //mark that we are taking a transition // if transitioning to a state with history change kind of entry EntryEventKind.EventType = ES_ENTRY; // optionally, consume or re-map this event for the upper // level state machine ReturnEvent.EventType = ES_NO_EVENT; break; case RETURN_PSEUDO_QUERY : //If event is GET_STATUS #ifdef DEBUG_SENDBYTES printf("\rSending\r\n"); #endif for (uint8_t i = 0; i < 5; i++) { WriteFIFO(getQuery[i]); #ifdef DEBUG_SENDBYTES printf("%x\r\n",getQuery[i]); #endif } //Enable the NVIC interrupt for the SSI when starting to transmit (or receive?) HWREG(NVIC_BASE+EN0) |= BIT7HI; //Interrupt 7 for SSI0 // Execute action function for state one : event one NextState = WAITING4EOT;//Decide what the next state will be // for internal transitions, skip changing MakeTransition MakeTransition = true; //mark that we are taking a transition // if transitioning to a state with history change kind of entry EntryEventKind.EventType = ES_ENTRY; // optionally, consume or re-map this event for the upper // level state machine ReturnEvent.EventType = ES_NO_EVENT; break; } } break; case WAITING4EOT : // If current state is WAITING4EOT // Execute During function for SENDING. ES_ENTRY & ES_EXIT are // processed here allow the lower level state machines to re-map // or consume the event CurrentEvent = DuringWaiting4EOT(CurrentEvent); //process any events if ( CurrentEvent.EventType != ES_NO_EVENT ) //If an event is active { switch (CurrentEvent.EventType) { case EOT_TIMEOUT : //If event is GET_STATUS #ifdef DEBUG_SENDBYTES if(!isStatus) {printf("\rReading result\r\n"); } #endif for (uint8_t i = 0; i < 5; i++) { readdata[i] = ReadFIFO(); #ifdef DEBUG_SENDBYTES if(!isStatus){printf("\r%x\r\n",readdata[i]);} #endif } // Execute action function for state one : event one NextState = WAITING4TIMEOUT;//Decide what the next state will be // for internal transitions, skip changing MakeTransition MakeTransition = true; //mark that we are taking a transition // if transitioning to a state with history change kind of entry EntryEventKind.EventType = ES_ENTRY; // optionally, consume or re-map this event for the upper // level state machine ReturnEvent.EventType = ES_NO_EVENT; ES_Timer_InitTimer(EOTTimer,2); break; } } break; case WAITING4TIMEOUT : // If current state is WAITING4TIMEOUT // Execute During function for SENDING. ES_ENTRY & ES_EXIT are // processed here allow the lower level state machines to re-map // or consume the event CurrentEvent = DuringWaiting4Timeout(CurrentEvent); //process any events if ( CurrentEvent.EventType != ES_NO_EVENT ) //If an event is active { switch (CurrentEvent.EventType) { case ES_TIMEOUT: // Execute action function for state one : event one NextState = WAITING_SENDBYTES;//Decide what the next state will be // for internal transitions, skip changing MakeTransition MakeTransition = true; //mark that we are taking a transition // if transitioning to a state with history change kind of entry EntryEventKind.EventType = ES_ENTRY; // optionally, consume or re-map this event for the upper // level state machine ES_Event CompletedEvent; CompletedEvent.EventType = PAC_COMM_COMPLETE; for (uint8_t i= 0; i < 5; i++) { CompletedEvent.EventArray[i] = readdata[i]; } //If this is a status request, send back to only Strategy //Otherwise, send to only campaigning if(isStatus) { PostStrategySM(CompletedEvent); isStatus = false; } else if(isPseudo) { isPseudo = false; } else { //return or query request returned to //campagin PostCampaigningSM(CompletedEvent); } break; } } break; // repeat state pattern as required for other states } // If we are making a state transition if (MakeTransition == true) { // Execute exit function for current state CurrentEvent.EventType = ES_EXIT; RunSendBytesStatus(CurrentEvent); CurrentState = NextState; //Modify state variable // Execute entry function for new state // this defaults to ES_ENTRY RunSendBytesStatus(EntryEventKind); } return(ReturnEvent); }