航空研究会
/
Scarlet_relay_V4
割り込み付きjevois実装版
Fork of Scarlet_relay_V2 by
main.cpp
- Committer:
- taknokolat
- Date:
- 2018-09-22
- Revision:
- 4:c08f2e993acc
- Parent:
- 3:92c039aed84a
File content as of revision 4:c08f2e993acc:
#include "mbed.h" //#include "Serial.h" RawSerial pc(PA_2,PA_3,115200); RawSerial pc2(PB_6,PB_7,115200); //Serial MySerial1(PA_2,PA_3); void ISR_Serial_Rx() { static char SFbuf[16]; static int bufcounter=0; char g_landingcommand; SFbuf[bufcounter] = pc.getc(); if(SFbuf[0]=='S'&&bufcounter<5) bufcounter++; if(bufcounter==5 && SFbuf[4]=='F'){ g_landingcommand = SFbuf[1]; pc.printf("S"); pc.printf("%c",g_landingcommand); pc.printf("A"); pc.printf("A"); pc.printf("F"); wait_ms(31); bufcounter = 0; memset(SFbuf, 0, strlen(SFbuf)); } else if(bufcounter>=5 ){ //pc.printf("Communication Falsed.\r\n"); bufcounter = 0; memset(SFbuf, 0, strlen(SFbuf)); } } void ISR_Serial_Rx_jevois() { NVIC_DisableIRQ(USART2_IRQn); static char SFbuf2[16]; static int bufcounter2=0; char g_landingcommand2; SFbuf2[bufcounter2] = pc2.getc(); if(SFbuf2[0]=='S'&&bufcounter2<5) bufcounter2++; if(bufcounter2==5 && SFbuf2[4]=='F'){ g_landingcommand2 = SFbuf2[1]; pc.printf("S"); pc.printf("%c",g_landingcommand2); pc.printf("A"); pc.printf("A"); pc.printf("F"); wait_ms(31); bufcounter2 = 0; memset(SFbuf2, 0, strlen(SFbuf2)); } else if(bufcounter2>=5 ){ //pc.printf("Communication Falsed.\r\n"); bufcounter2 = 0; memset(SFbuf2, 0, strlen(SFbuf2)); } NVIC_EnableIRQ(USART2_IRQn); } int main() { // シリアル通信受信の割り込みイベント登録 pc.attach(ISR_Serial_Rx, Serial::RxIrq); pc2.attach(ISR_Serial_Rx_jevois, Serial::RxIrq); NVIC_SetPriority(USART1_IRQn,0); NVIC_SetPriority(USART2_IRQn,1); while (1) { NVIC_SetPriority(USART1_IRQn,0); NVIC_SetPriority(USART2_IRQn,1); // wait(1.0); } }