20190816

Dependencies:   mbed

TxRxService.cpp

Committer:
VASKO
Date:
2019-08-03
Revision:
11:6519744c77f9
Child:
13:b9e066badefa

File content as of revision 11:6519744c77f9:

#include "PrjDefs.h"

Serial pc(pcTx,pcRx);

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);
        ArrTxBusy = 0;
        }
    }//IntrTx

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;
        memcpy(&RxBuff, &ArrRx, ArrTxSize); 
        }
    }//IntrRx

void TxRxServiceInit(){
    pc.attach(&IntrRx, Serial::RxIrq);
    pc.attach(NULL, Serial::TxIrq);//я УПЁРТЫЙ дебил
    }