void Send_Packet_my(void) { unsigned int i; SetRFMode_my(RF_STANDBY); write_spi_con(0x1F, ((InitConfigRegs[0x1F] & 0xBF)| FIFO_STBY_ACCESS_WRITE)); write_spi_con(0x0D, (InitConfigRegs[0x0D] | IRQ1_FIFO_OVERRUN_CLEAR )); write_spi_con(0x0E, ((InitConfigRegs[0x0E]) | 0x02)); write_spi_con(0x16, 0x97); //на передачу dia(); //WriteFIFO(TxPacketLen+1); WriteFIFO(0x31); //Node_adrs WriteFIFO(0x00); for(i=0; i< packetlength; i++) { WriteFIFO(TxPacket[i]); } // INTCONbits.GIE = 0; //? //до этого момента на ноге прерывания 0 SetRFMode_my(RF_TRANSMITTER); dia(); for(i=0;i<255;i++) { _nop_();_nop_();_nop_();_nop_(); _nop_();_nop_();_nop_();_nop_(); } while(!(flag_int0)); flag_int0 = 0; //здесь должно на ноге irq1 появиться лог 1 // IT01CF = 0xFE; // IE = 0x85; ( 0x05) EX1 EX0 ) // TCON (IE1 IE0 ) 0 - к уровню 1 - к фронту // // { _nop_(); //ожидание прерывания будет заменено временной задержкой. _nop_(); _nop_(); _nop_(); } // INTCONbits.GIE = 1; //? dia(); write_spi_con(0x16, 0x68); SetRFMode_my(RF_RECEIVER); //rfmode = ресивер //Reset FIFO очистить буфер после передачи i = read_spi_con(REG_IRQPARAM0); write_spi_con(REG_IRQPARAM0, (i | 0x01)); }
/********************************************************************************************************* * Function Name: UART0_IRQHandler * Description: UART0 中断处理函数 * Input: None * Output: None * Return: None *********************************************************************************************************/ void UART0_IRQHandler (void) { RecNumCOM0 = 0; while ((LPC_UART0->IIR & 0x01) == 0){ /* 判断是否有中断挂起 */ l_COM0ConnTime = GetSysTime(); l_COM0StartFlg = 1; //l_COM0TimeOutFlg = 0; switch (LPC_UART0->IIR & 0x0E){ /* 判断中断标志 */ case 0x04: /* 接收数据中断 */ for (RecNumCOM0 = 0; RecNumCOM0 < 8; RecNumCOM0++){ /* 连续接收8个字节 */ l_COM0TempRev = LPC_UART0->RBR; //注意读U0RBR会清空接收中断标志 WriteFIFO((stcFIFO *)&sUART0RecFIFO,(uint8 *)&l_COM0TempRev,1); //printfcom0("%c",l_COM0TempRev); if(l_COM0TempRev == COM0_FRAM_END ) { l_COM0FramRecEndFlg = 1; //帧接收完成,标志位赋值 } } break; case 0x0C: /* 字符超时中断 */ while ((LPC_UART0->LSR & 0x01) == 0x01){ /* 判断数据是否接收完毕 */ l_COM0TempRev = LPC_UART0->RBR; //注意读U0RBR会清空接收中断标志 WriteFIFO((stcFIFO *)&sUART0RecFIFO,(uint8 *)&l_COM0TempRev,1); //printfcom0("%c",l_COM0TempRev); if(l_COM0TempRev == COM0_FRAM_END ) { l_COM0FramRecEndFlg = 1; //帧接收完成,标志位赋值 } } l_COM0TimeOutFlg = 1; break; default: break; } } }
/**************************************************************************** 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); }