vasko ozo
/
TxRxService
20190816
main.cpp@25:0f1f6687333c, 2019-08-08 (annotated)
- Committer:
- VASKO
- Date:
- Thu Aug 08 17:55:16 2019 +0000
- Revision:
- 25:0f1f6687333c
- Parent:
- 24:fba9a58e6fbd
- Child:
- 26:81bb0d02ccdd
TxRxService ready for use. Start by button added.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
VASKO | 7:7aaa14391264 | 1 | #include "PrjDefs.h" |
VASKO | 0:5152e3f9df72 | 2 | |
VASKO | 0:5152e3f9df72 | 3 | DigitalOut myled(LED1); |
VASKO | 0:5152e3f9df72 | 4 | |
VASKO | 25:0f1f6687333c | 5 | #ifndef TARGET_NUCLEO_L432KC |
VASKO | 25:0f1f6687333c | 6 | InterruptIn Butt(USER_BUTTON); |
VASKO | 25:0f1f6687333c | 7 | #endif |
VASKO | 25:0f1f6687333c | 8 | |
VASKO | 19:09c21f5f0625 | 9 | Serial dpc(USBTX,USBRX); |
VASKO | 19:09c21f5f0625 | 10 | |
VASKO | 19:09c21f5f0625 | 11 | Ticker tickTx; |
VASKO | 19:09c21f5f0625 | 12 | |
VASKO | 23:39d96e160cf1 | 13 | MsgType _msg; |
VASKO | 23:39d96e160cf1 | 14 | |
VASKO | 23:39d96e160cf1 | 15 | bool tick = 0; |
VASKO | 23:39d96e160cf1 | 16 | uint32_t ctr = 0; // счетчик обменов |
VASKO | 23:39d96e160cf1 | 17 | uint32_t ctro = 0; |
VASKO | 23:39d96e160cf1 | 18 | uint32_t Ectr = 0; // счетчик ошибок |
VASKO | 23:39d96e160cf1 | 19 | |
VASKO | 25:0f1f6687333c | 20 | void dpc_func(){ (void)dpc.getc(); SendMsg(&_msg.cmd); } |
VASKO | 25:0f1f6687333c | 21 | |
VASKO | 25:0f1f6687333c | 22 | #ifndef TARGET_NUCLEO_L432KC |
VASKO | 25:0f1f6687333c | 23 | void ButtPrsd(){ SendMsg(&_msg.cmd); } |
VASKO | 25:0f1f6687333c | 24 | #endif |
VASKO | 23:39d96e160cf1 | 25 | |
VASKO | 24:fba9a58e6fbd | 26 | void tickIntrFunc(void){ tick = 1; }//tickIntrFunc |
VASKO | 19:09c21f5f0625 | 27 | |
VASKO | 0:5152e3f9df72 | 28 | int main() { |
VASKO | 23:39d96e160cf1 | 29 | |
VASKO | 23:39d96e160cf1 | 30 | _msg.cmd=0x41; |
VASKO | 23:39d96e160cf1 | 31 | _msg.pars.ui32[0]=0; |
VASKO | 23:39d96e160cf1 | 32 | |
VASKO | 11:6519744c77f9 | 33 | TxRxServiceInit(); |
VASKO | 23:39d96e160cf1 | 34 | tickTx.attach(&tickIntrFunc, 1); |
VASKO | 23:39d96e160cf1 | 35 | dpc.baud(115200); |
VASKO | 23:39d96e160cf1 | 36 | dpc.attach(dpc_func); |
VASKO | 12:6f63e376c0aa | 37 | |
VASKO | 25:0f1f6687333c | 38 | #ifndef TARGET_NUCLEO_L432KC |
VASKO | 25:0f1f6687333c | 39 | Butt.fall(&ButtPrsd); |
VASKO | 25:0f1f6687333c | 40 | #endif |
VASKO | 25:0f1f6687333c | 41 | |
VASKO | 2:56a194afd255 | 42 | //Exige Monumentum |
VASKO | 9:dcddb19ad551 | 43 | //Я дебил,потому что хотел выполнить действия,которые |
VASKO | 2:56a194afd255 | 44 | //требуются постоянно,один раз и именно здесь. |
VASKO | 0:5152e3f9df72 | 45 | |
VASKO | 12:6f63e376c0aa | 46 | //Для дебилов: в mbed типы "int" и "unsigned int" имеют размер 4 байта !!! |
VASKO | 12:6f63e376c0aa | 47 | |
VASKO | 16:459ad1bd82fd | 48 | //https://os.mbed.com/forum/bugs-suggestions/topic/4264/ проблема выравнивания данных |
VASKO | 16:459ad1bd82fd | 49 | |
VASKO | 0:5152e3f9df72 | 50 | while(1) { |
VASKO | 24:fba9a58e6fbd | 51 | TxRxStates _trs = GetMsg(&_msg.cmd); |
VASKO | 24:fba9a58e6fbd | 52 | if(_trs == RxRcvd){ |
VASKO | 24:fba9a58e6fbd | 53 | myled = !myled; |
VASKO | 24:fba9a58e6fbd | 54 | ctr++; |
VASKO | 24:fba9a58e6fbd | 55 | _msg.pars.ui32[0]++; |
VASKO | 24:fba9a58e6fbd | 56 | if(tick){ |
VASKO | 24:fba9a58e6fbd | 57 | tick = 0; |
VASKO | 24:fba9a58e6fbd | 58 | dpc.printf("ctr = %d, diff = %d, Ectr = %d\n\r", ctr, ctr - ctro, Ectr); |
VASKO | 24:fba9a58e6fbd | 59 | ctro = ctr; |
VASKO | 24:fba9a58e6fbd | 60 | } |
VASKO | 24:fba9a58e6fbd | 61 | SendMsg(&_msg.cmd); |
VASKO | 24:fba9a58e6fbd | 62 | }else if(_trs == RxCS_Err) Ectr++; |
VASKO | 8:cad966c09853 | 63 | }//while(1) |
VASKO | 9:dcddb19ad551 | 64 | }//main |
VASKO | 9:dcddb19ad551 | 65 |