![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
version with updated libs
Dependencies: F7_Ethernet mbed MbedJSONValue LCD_DISCO_F746NG mbed-rtos BSP_DISCO_F746NG CANMsg NetworkAPI SDFileSystem_Warning_Fixed GroveStreamsmodified LcdDiscoF746NgTracer JSON
ManageBufferJPA.cpp@3:2de8e4771674, 2020-09-02 (annotated)
- Committer:
- jeanpierreaulas
- Date:
- Wed Sep 02 12:54:45 2020 +0000
- Branch:
- jpa
- Revision:
- 3:2de8e4771674
- Child:
- 4:fbbf5d1785e7
Ethernet ok, Display OK, CAN Ok, SerialUSB OK
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jeanpierreaulas | 3:2de8e4771674 | 1 | #include "mbed.h" |
jeanpierreaulas | 3:2de8e4771674 | 2 | |
jeanpierreaulas | 3:2de8e4771674 | 3 | const int kMaxBufferSize = 125; |
jeanpierreaulas | 3:2de8e4771674 | 4 | volatile char bufferSerialUSB[kMaxBufferSize+3]; |
jeanpierreaulas | 3:2de8e4771674 | 5 | volatile int idxSerialIntUSB = 0; |
jeanpierreaulas | 3:2de8e4771674 | 6 | int idxSerialUserUSB = 0; |
jeanpierreaulas | 3:2de8e4771674 | 7 | volatile int msgSerialUSB = 0; |
jeanpierreaulas | 3:2de8e4771674 | 8 | |
jeanpierreaulas | 3:2de8e4771674 | 9 | //RawSerial |
jeanpierreaulas | 3:2de8e4771674 | 10 | RawSerial serialUSB(USBTX, USBRX); // serial PC |
jeanpierreaulas | 3:2de8e4771674 | 11 | Serial serial2(PC_6, PC_7); // TX, RX for udp bridge |
jeanpierreaulas | 3:2de8e4771674 | 12 | Serial serial7(PF_7, PF_6); // TX, RX for extension |
jeanpierreaulas | 3:2de8e4771674 | 13 | volatile char x; |
jeanpierreaulas | 3:2de8e4771674 | 14 | // --------------------------------------------------- |
jeanpierreaulas | 3:2de8e4771674 | 15 | void serialUSB_int_recv() |
jeanpierreaulas | 3:2de8e4771674 | 16 | { |
jeanpierreaulas | 3:2de8e4771674 | 17 | if(serialUSB.readable()) |
jeanpierreaulas | 3:2de8e4771674 | 18 | { |
jeanpierreaulas | 3:2de8e4771674 | 19 | bufferSerialUSB[idxSerialIntUSB]=(serialUSB.getc()); |
jeanpierreaulas | 3:2de8e4771674 | 20 | idxSerialIntUSB++; |
jeanpierreaulas | 3:2de8e4771674 | 21 | if (idxSerialIntUSB >= kMaxBufferSize) {idxSerialIntUSB = 0;} |
jeanpierreaulas | 3:2de8e4771674 | 22 | bufferSerialUSB[idxSerialIntUSB]= 0; |
jeanpierreaulas | 3:2de8e4771674 | 23 | msgSerialUSB = 1; |
jeanpierreaulas | 3:2de8e4771674 | 24 | } |
jeanpierreaulas | 3:2de8e4771674 | 25 | return; |
jeanpierreaulas | 3:2de8e4771674 | 26 | } |
jeanpierreaulas | 3:2de8e4771674 | 27 | |
jeanpierreaulas | 3:2de8e4771674 | 28 | void initSerial() |
jeanpierreaulas | 3:2de8e4771674 | 29 | { |
jeanpierreaulas | 3:2de8e4771674 | 30 | serialUSB.baud(115200); |
jeanpierreaulas | 3:2de8e4771674 | 31 | serialUSB.attach(&serialUSB_int_recv, Serial::RxIrq); |
jeanpierreaulas | 3:2de8e4771674 | 32 | serial2.baud(115200); // required for UDP bridge |
jeanpierreaulas | 3:2de8e4771674 | 33 | serial7.baud(115200); // required for tasmota |
jeanpierreaulas | 3:2de8e4771674 | 34 | //serial7.attach(&pc_recv, Serial::RxIrq); |
jeanpierreaulas | 3:2de8e4771674 | 35 | |
jeanpierreaulas | 3:2de8e4771674 | 36 | bufferSerialUSB[0] = '\0'; |
jeanpierreaulas | 3:2de8e4771674 | 37 | |
jeanpierreaulas | 3:2de8e4771674 | 38 | } |
jeanpierreaulas | 3:2de8e4771674 | 39 | |
jeanpierreaulas | 3:2de8e4771674 | 40 | void sendSerialUSB(char * str) |
jeanpierreaulas | 3:2de8e4771674 | 41 | { |
jeanpierreaulas | 3:2de8e4771674 | 42 | serialUSB.printf(str); |
jeanpierreaulas | 3:2de8e4771674 | 43 | } |
jeanpierreaulas | 3:2de8e4771674 | 44 | |
jeanpierreaulas | 3:2de8e4771674 | 45 | void receiveSerialUSB() |
jeanpierreaulas | 3:2de8e4771674 | 46 | { |
jeanpierreaulas | 3:2de8e4771674 | 47 | while(idxSerialIntUSB != idxSerialUserUSB) |
jeanpierreaulas | 3:2de8e4771674 | 48 | { |
jeanpierreaulas | 3:2de8e4771674 | 49 | x=bufferSerialUSB[idxSerialUserUSB]; |
jeanpierreaulas | 3:2de8e4771674 | 50 | printf("%c",x); |
jeanpierreaulas | 3:2de8e4771674 | 51 | idxSerialUserUSB = idxSerialUserUSB + 1; |
jeanpierreaulas | 3:2de8e4771674 | 52 | if (idxSerialUserUSB >= kMaxBufferSize) {idxSerialUserUSB = 0;} |
jeanpierreaulas | 3:2de8e4771674 | 53 | } |
jeanpierreaulas | 3:2de8e4771674 | 54 | msgSerialUSB = 0; |
jeanpierreaulas | 3:2de8e4771674 | 55 | } |
jeanpierreaulas | 3:2de8e4771674 | 56 | |
jeanpierreaulas | 3:2de8e4771674 | 57 | void sendserial2(char * str) |
jeanpierreaulas | 3:2de8e4771674 | 58 | { |
jeanpierreaulas | 3:2de8e4771674 | 59 | serial2.printf(str); |
jeanpierreaulas | 3:2de8e4771674 | 60 | } |
jeanpierreaulas | 3:2de8e4771674 | 61 | |
jeanpierreaulas | 3:2de8e4771674 | 62 | void sendserial7(char * str) |
jeanpierreaulas | 3:2de8e4771674 | 63 | { |
jeanpierreaulas | 3:2de8e4771674 | 64 | serial7.printf(str); |
jeanpierreaulas | 3:2de8e4771674 | 65 | } |