vasko ozo
/
TxRxService
20190816
main.cpp@10:f7a320faef76, 2019-08-03 (annotated)
- Committer:
- VASKO
- Date:
- Sat Aug 03 16:31:12 2019 +0000
- Revision:
- 10:f7a320faef76
- Parent:
- 9:dcddb19ad551
- Child:
- 11:6519744c77f9
Now using TxBuffer and RxBuffer.
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 | 2:56a194afd255 | 3 | Serial pc(USBTX,USBRX); |
VASKO | 0:5152e3f9df72 | 4 | |
VASKO | 0:5152e3f9df72 | 5 | DigitalOut myled(LED1); |
VASKO | 0:5152e3f9df72 | 6 | |
VASKO | 7:7aaa14391264 | 7 | uint8_t ArrTx[ArrTxSize] = ArrTxInitializer; |
VASKO | 7:7aaa14391264 | 8 | uint8_t ArrRx[ArrRxSize] = ArrRxInitializer; |
VASKO | 10:f7a320faef76 | 9 | uint8_t RxBuff[ArrRxSize]; |
VASKO | 10:f7a320faef76 | 10 | uint8_t TxBuff[ArrTxSize]; |
VASKO | 6:1364a236ee22 | 11 | uint8_t *pArrTx = &ArrTx[0]; |
VASKO | 6:1364a236ee22 | 12 | uint8_t *pArrRx = &ArrRx[0]; |
VASKO | 8:cad966c09853 | 13 | bool ArrRxCmplt = 0; |
VASKO | 10:f7a320faef76 | 14 | bool ArrTxBusy = 0; |
VASKO | 10:f7a320faef76 | 15 | bool TxBuffFull = 0; |
VASKO | 5:ad4e5a078834 | 16 | |
VASKO | 0:5152e3f9df72 | 17 | void IntrTx() { |
VASKO | 8:cad966c09853 | 18 | if ( ++pArrTx <= &ArrTx[ArrTxSize-1] ) pc.putc(*pArrTx); |
VASKO | 10:f7a320faef76 | 19 | else { |
VASKO | 10:f7a320faef76 | 20 | pc.attach(NULL, Serial::TxIrq); |
VASKO | 10:f7a320faef76 | 21 | ArrTxBusy = 0; |
VASKO | 10:f7a320faef76 | 22 | } |
VASKO | 0:5152e3f9df72 | 23 | } |
VASKO | 8:cad966c09853 | 24 | |
VASKO | 8:cad966c09853 | 25 | void StartTx(){ |
VASKO | 10:f7a320faef76 | 26 | memcpy(&ArrTx, &TxBuff, ArrTxSize); |
VASKO | 8:cad966c09853 | 27 | pArrTx = &ArrTx[0]; |
VASKO | 8:cad966c09853 | 28 | pc.putc(*pArrTx); |
VASKO | 8:cad966c09853 | 29 | pc.attach(&IntrTx, Serial::TxIrq); |
VASKO | 10:f7a320faef76 | 30 | ArrTxBusy = 1; |
VASKO | 8:cad966c09853 | 31 | }//StartTx |
VASKO | 0:5152e3f9df72 | 32 | |
VASKO | 2:56a194afd255 | 33 | void IntrRx() { |
VASKO | 4:d461cadeb702 | 34 | *pArrRx = pc.getc(); |
VASKO | 10:f7a320faef76 | 35 | if ( pArrRx++ >= &ArrRx[ArrRxSize-1] ) { |
VASKO | 10:f7a320faef76 | 36 | pArrRx = &ArrRx[0]; |
VASKO | 10:f7a320faef76 | 37 | ArrRxCmplt = 1; |
VASKO | 10:f7a320faef76 | 38 | memcpy(&RxBuff, &ArrRx, ArrTxSize); |
VASKO | 10:f7a320faef76 | 39 | } |
VASKO | 8:cad966c09853 | 40 | }//IntrRx |
VASKO | 0:5152e3f9df72 | 41 | |
VASKO | 0:5152e3f9df72 | 42 | int main() { |
VASKO | 0:5152e3f9df72 | 43 | pc.attach(&IntrRx, Serial::RxIrq); |
VASKO | 0:5152e3f9df72 | 44 | pc.attach(NULL, Serial::TxIrq);//я УПЁРТЫЙ дебил |
VASKO | 0:5152e3f9df72 | 45 | |
VASKO | 2:56a194afd255 | 46 | //Exige Monumentum |
VASKO | 9:dcddb19ad551 | 47 | //Я дебил,потому что хотел выполнить действия,которые |
VASKO | 2:56a194afd255 | 48 | //требуются постоянно,один раз и именно здесь. |
VASKO | 0:5152e3f9df72 | 49 | |
VASKO | 0:5152e3f9df72 | 50 | while(1) { |
VASKO | 8:cad966c09853 | 51 | if ( ArrRxCmplt == 1 ){ |
VASKO | 10:f7a320faef76 | 52 | memcpy(&TxBuff, &RxBuff, ArrTxSize); |
VASKO | 10:f7a320faef76 | 53 | TxBuffFull = 1; |
VASKO | 8:cad966c09853 | 54 | ArrRxCmplt = 0; |
VASKO | 8:cad966c09853 | 55 | } |
VASKO | 10:f7a320faef76 | 56 | if( !ArrTxBusy && TxBuffFull ) { |
VASKO | 10:f7a320faef76 | 57 | StartTx(); |
VASKO | 10:f7a320faef76 | 58 | TxBuffFull = 0; |
VASKO | 10:f7a320faef76 | 59 | } |
VASKO | 10:f7a320faef76 | 60 | // |
VASKO | 8:cad966c09853 | 61 | }//while(1) |
VASKO | 9:dcddb19ad551 | 62 | }//main |
VASKO | 9:dcddb19ad551 | 63 |