20190816

Dependencies:   mbed

Revision:
10:f7a320faef76
Parent:
9:dcddb19ad551
Child:
11:6519744c77f9
--- a/main.cpp	Sat Aug 03 15:29:28 2019 +0000
+++ b/main.cpp	Sat Aug 03 16:31:12 2019 +0000
@@ -6,24 +6,37 @@
 
 uint8_t ArrTx[ArrTxSize] = ArrTxInitializer;
 uint8_t ArrRx[ArrRxSize] = ArrRxInitializer;
+uint8_t RxBuff[ArrRxSize];
+uint8_t TxBuff[ArrTxSize];
 uint8_t *pArrTx = &ArrTx[0];
 uint8_t *pArrRx = &ArrRx[0];
 bool ArrRxCmplt = 0;
+bool ArrTxBusy = 0;
+bool TxBuffFull = 0;
 
 void IntrTx() {
     if ( ++pArrTx <= &ArrTx[ArrTxSize-1] ) pc.putc(*pArrTx);
-    else pc.attach(NULL, Serial::TxIrq);
+    else {
+        pc.attach(NULL, Serial::TxIrq);
+        ArrTxBusy = 0;
+        }
     }
 
 void StartTx(){
+        memcpy(&ArrTx, &TxBuff, ArrTxSize);
         pArrTx = &ArrTx[0];
         pc.putc(*pArrTx);
         pc.attach(&IntrTx, Serial::TxIrq);
+        ArrTxBusy = 1;
     }//StartTx
 
 void IntrRx() {
     *pArrRx = pc.getc();
-    if ( pArrRx++ >= &ArrRx[ArrRxSize-1] ) { pArrRx = &ArrRx[0]; ArrRxCmplt = 1; }
+    if ( pArrRx++ >= &ArrRx[ArrRxSize-1] ) {
+        pArrRx = &ArrRx[0]; 
+        ArrRxCmplt = 1;
+        memcpy(&RxBuff, &ArrRx, ArrTxSize); 
+        }
     }//IntrRx
 
 int main() {
@@ -36,10 +49,15 @@
             
     while(1) {
         if ( ArrRxCmplt == 1 ){
-            memcpy(&ArrTx[0], &ArrRx[0], ArrTxSize);
-            StartTx();
+            memcpy(&TxBuff, &RxBuff, ArrTxSize);
+            TxBuffFull = 1;
             ArrRxCmplt = 0;
             }
+        if( !ArrTxBusy && TxBuffFull ) {
+            StartTx();
+            TxBuffFull = 0;
+            }
+        // 
         }//while(1)
 }//main