vasko ozo
/
TxRxService
20190816
Diff: main.cpp
- Revision:
- 4:d461cadeb702
- Parent:
- 3:7cdb20aac969
- Child:
- 5:ad4e5a078834
--- a/main.cpp Sat Aug 03 12:24:10 2019 +0000 +++ b/main.cpp Sat Aug 03 12:56:38 2019 +0000 @@ -8,7 +8,6 @@ DigitalOut myled(LED1); int nCharTx = 0; -int nCharRx = 0; uint8_t ArrTx[ArrTxSize] = {0x20,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4b,0x4c,0x4d,0x4e,0x4f}; uint8_t ArrRx[ArrRxSize] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; @@ -24,23 +23,23 @@ } } -void CopyUint8(uint8_t *src = &ArrRx[0], uint8_t *dst = &ArrTx[0], int qty = ArrTxSize){ +void CopyMemUint8(uint8_t *src = &ArrRx[0], uint8_t *dst = &ArrTx[0], int qty = ArrTxSize){ for ( ; qty > 0; src++,dst++,qty-- ) *dst = *src; } + +uint8_t *pArrRx = &ArrRx[0]; void IntrRx() { - ArrRx[nCharRx++] = pc.getc(); - if (nCharRx >= ArrRxSize ) { - CopyUint8(); + *pArrRx = pc.getc(); + if (pArrRx++ >= &ArrRx[ArrRxSize-1] ) { + pArrRx = &ArrRx[0]; + CopyMemUint8(); nCharTx = 0; pc.putc(ArrTx[nCharTx]); pc.attach(&IntrTx, Serial::TxIrq); - nCharRx = 0; myled=1; } - } - int main() { pc.attach(&IntrRx, Serial::RxIrq);