vasko ozo
/
TxRxService
20190816
TxRxService.cpp@14:b113f676ef42, 2019-08-04 (annotated)
- Committer:
- VASKO
- Date:
- Sun Aug 04 14:09:35 2019 +0000
- Revision:
- 14:b113f676ef42
- Parent:
- 13:b9e066badefa
- Child:
- 15:30e45bd5902e
One-level Tx bufferization by "TxBuff". Tx control by "StartTx". TxInit optimization by "CopyArr_InitTx".
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
VASKO | 11:6519744c77f9 | 1 | #include "PrjDefs.h" |
VASKO | 11:6519744c77f9 | 2 | |
VASKO | 11:6519744c77f9 | 3 | Serial pc(pcTx,pcRx); |
VASKO | 11:6519744c77f9 | 4 | |
VASKO | 11:6519744c77f9 | 5 | uint8_t ArrTx[ArrTxSize] = ArrTxInitializer; |
VASKO | 11:6519744c77f9 | 6 | uint8_t ArrRx[ArrRxSize] = ArrRxInitializer; |
VASKO | 11:6519744c77f9 | 7 | uint8_t RxBuff[ArrRxSize]; |
VASKO | 11:6519744c77f9 | 8 | uint8_t TxBuff[ArrTxSize]; |
VASKO | 11:6519744c77f9 | 9 | uint8_t *pArrTx = &ArrTx[0]; |
VASKO | 11:6519744c77f9 | 10 | uint8_t *pArrRx = &ArrRx[0]; |
VASKO | 13:b9e066badefa | 11 | bool RxBuffFull = 0; |
VASKO | 11:6519744c77f9 | 12 | bool ArrTxBusy = 0; |
VASKO | 11:6519744c77f9 | 13 | bool TxBuffFull = 0; |
VASKO | 11:6519744c77f9 | 14 | |
VASKO | 14:b113f676ef42 | 15 | void IntrTx(); |
VASKO | 14:b113f676ef42 | 16 | |
VASKO | 14:b113f676ef42 | 17 | void CopyArr_InitTx(uint8_t *parr){ |
VASKO | 14:b113f676ef42 | 18 | memcpy(ArrTx, parr, ArrTxSize); |
VASKO | 14:b113f676ef42 | 19 | pArrTx = &ArrTx[0]; |
VASKO | 14:b113f676ef42 | 20 | pc.putc(*pArrTx); |
VASKO | 14:b113f676ef42 | 21 | if(!ArrTxBusy) { |
VASKO | 14:b113f676ef42 | 22 | ArrTxBusy = 1; |
VASKO | 14:b113f676ef42 | 23 | pc.attach(IntrTx, Serial::TxIrq); |
VASKO | 14:b113f676ef42 | 24 | } |
VASKO | 14:b113f676ef42 | 25 | TxBuffFull = 0; |
VASKO | 14:b113f676ef42 | 26 | } |
VASKO | 14:b113f676ef42 | 27 | |
VASKO | 11:6519744c77f9 | 28 | void IntrTx() { |
VASKO | 11:6519744c77f9 | 29 | if ( ++pArrTx <= &ArrTx[ArrTxSize-1] ) pc.putc(*pArrTx); |
VASKO | 11:6519744c77f9 | 30 | else { |
VASKO | 14:b113f676ef42 | 31 | if(TxBuffFull) CopyArr_InitTx(TxBuff); |
VASKO | 14:b113f676ef42 | 32 | else { |
VASKO | 14:b113f676ef42 | 33 | pc.attach(NULL, Serial::TxIrq); |
VASKO | 14:b113f676ef42 | 34 | ArrTxBusy = 0; |
VASKO | 14:b113f676ef42 | 35 | } |
VASKO | 11:6519744c77f9 | 36 | } |
VASKO | 11:6519744c77f9 | 37 | }//IntrTx |
VASKO | 11:6519744c77f9 | 38 | |
VASKO | 14:b113f676ef42 | 39 | StartTxStates StartTx(uint8_t *parr){ |
VASKO | 14:b113f676ef42 | 40 | if(TxBuffFull){ return TxBusy; } |
VASKO | 14:b113f676ef42 | 41 | if(ArrTxBusy) { |
VASKO | 14:b113f676ef42 | 42 | memcpy(TxBuff, parr, ArrTxSize); |
VASKO | 14:b113f676ef42 | 43 | TxBuffFull=1; |
VASKO | 14:b113f676ef42 | 44 | if(!ArrTxBusy) CopyArr_InitTx(TxBuff); |
VASKO | 14:b113f676ef42 | 45 | } else CopyArr_InitTx(parr); |
VASKO | 14:b113f676ef42 | 46 | return StartOK; |
VASKO | 11:6519744c77f9 | 47 | }//StartTx |
VASKO | 11:6519744c77f9 | 48 | |
VASKO | 11:6519744c77f9 | 49 | void IntrRx() { |
VASKO | 11:6519744c77f9 | 50 | *pArrRx = pc.getc(); |
VASKO | 11:6519744c77f9 | 51 | if ( pArrRx++ >= &ArrRx[ArrRxSize-1] ) { |
VASKO | 11:6519744c77f9 | 52 | pArrRx = &ArrRx[0]; |
VASKO | 13:b9e066badefa | 53 | RxBuffFull = 1; |
VASKO | 14:b113f676ef42 | 54 | memcpy(RxBuff, ArrRx, ArrTxSize); |
VASKO | 11:6519744c77f9 | 55 | } |
VASKO | 11:6519744c77f9 | 56 | }//IntrRx |
VASKO | 11:6519744c77f9 | 57 | |
VASKO | 11:6519744c77f9 | 58 | void TxRxServiceInit(){ |
VASKO | 14:b113f676ef42 | 59 | pc.attach(IntrRx, Serial::RxIrq); |
VASKO | 11:6519744c77f9 | 60 | pc.attach(NULL, Serial::TxIrq);//я УПЁРТЫЙ дебил |
VASKO | 11:6519744c77f9 | 61 | } |
VASKO | 11:6519744c77f9 | 62 |