20190816

Dependencies:   mbed

TxRxService.cpp

Committer:
VASKO
Date:
2019-08-04
Revision:
13:b9e066badefa
Parent:
11:6519744c77f9
Child:
14:b113f676ef42

File content as of revision 13:b9e066badefa:

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

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