diff --git a/libraries/ComRingBuf/ComRingBuf.cpp b/libraries/ComRingBuf/ComRingBuf.cpp index 66a9784b5507d680cc700b0f7fe5e68379da7e3e..16f5fc5edc4ccff61ecaa48b23bb8d7a0b79743b 100644 --- a/libraries/ComRingBuf/ComRingBuf.cpp +++ b/libraries/ComRingBuf/ComRingBuf.cpp @@ -41,7 +41,7 @@ // -------------------------------------------------------------------------- - // Schnittstellen + // Schnittstellen zur Übertragung // -------------------------------------------------------------------------- // // Byte aus dem Sendepuffer lesen @@ -62,7 +62,12 @@ void ComRingBuf::putByteRec(byte b) { int space = rbReadIdx - rbWriteIdx - 1; + if(space < 0) space += sbSize; if(space == 0) return; + recBuffer[rbWriteIdx] = b; + rbWriteIdx++; + if(rbWriteIdx >= rbSize) + rbWriteIdx = 0; } @@ -658,6 +663,42 @@ int ComRingBuf::putChr(int chr) return(chr); } +int ComRingBuf::putStrExt(char *msg, char addC1, char addC2) +{ + int size; + int sIdx = 0; + + if(sndBuffer == NULL) return(EOF); + if(serIf == NULL) return(EOF); + + int space = getSpace(); + int len = strlen(msg); + if(addC1 != '\0') size = len + 1; + else size = len; + if(addC2 !='\0') size++; + + if(space < size) + { + serIf->resuSend(); + return(EOF); + } + + if(sbReadIdx == sbWriteIdx) + { + // Wenn der Sendepuffer leer ist, dann kann das erste Zeichen evt. + // direkt gesendet werden. + if(serIf->condSend(msg[0])) + sIdx = 1; + } + + for (int i = sIdx; i < len; i++) + putBufB(msg[i]); + + if(addC1 != '\0') putBufB(addC1); + if(addC2 != '\0') putBufB(addC2); + return(size); +} + int ComRingBuf::putStr(char *msg) { int sIdx = 0; @@ -692,6 +733,7 @@ int ComRingBuf::putStr(char *msg) return(len); } + int ComRingBuf::putSeq(byte *msg, int n) { int sIdx = 0; @@ -748,23 +790,20 @@ int ComRingBuf::putNL() int ComRingBuf::putLine(char *msg) { - int retv, nl; + char addC1,addC2; - retv = putStr(msg); - if(retv < 0) - return(retv); + addC1 = addC2 = '\0'; - nl = putNL(); - return(retv); + if(newLineMode & NewLineModeCR) + addC1 = '\r'; + + if(newLineMode & NewLineModeNL) + addC2 = '\n'; + + return(putStrExt(msg,addC1,addC2)); } -//int ComRingBuf::putLine(char *msg, char c) -//{ -//} -//int ComRingBuf::putLine(char *msg, int n) -//{ -//} // -------------------------------------------------------------------------- @@ -772,6 +811,14 @@ int ComRingBuf::putLine(char *msg) // -------------------------------------------------------------------------- // +int ComRingBuf::dbGetBufValues(pDbBufValues valPtr) +{ + valPtr->rbRdIdx = rbReadIdx; + valPtr->rbWrIdx = rbWriteIdx; + valPtr->tbRdIdx = sbReadIdx; + valPtr->tbWrIdx = sbWriteIdx; + return(0); +} diff --git a/libraries/ComRingBuf/ComRingBuf.h b/libraries/ComRingBuf/ComRingBuf.h index bd8ee0c8e604ac8ca5a6c344ca9966bb856f365b..bb14070712a43eaeb144eaf7f163e3fd115e1d0e 100644 --- a/libraries/ComRingBuf/ComRingBuf.h +++ b/libraries/ComRingBuf/ComRingBuf.h @@ -90,6 +90,12 @@ private: return(space); } + // -------------------------------------------------------------------------- + // Hilfs- und Vereinfachungsfunktionen + // -------------------------------------------------------------------------- + // + int putStrExt(char *msg, char addC1, char addC2); + public: // -------------------------------------------------------------------------- @@ -117,9 +123,13 @@ public: // void setReadBuffer(int size, byte *bufPtr); + // Zuweisen eines Speichers (*bufPtr) der Größe size für den Schreibpuffer + // + void setWriteBuffer(int size, byte *bufPtr); + // -------------------------------------------------------------------------- - // Steuerung + // Steuerung und Nutzung (Anwenderschnittstelle) // -------------------------------------------------------------------------- // @@ -207,10 +217,32 @@ public: int getRestStr(char *tagStr, int len, byte *buffer); int reqChkLine(char *req, char *rsp); - void setWriteBuffer(int size, byte *bufPtr); + // -------------------------------------------------- + // Ein einzelnes Zeichen in den Ringpuffer schreiben + // -------------------------------------------------- + // Rückgabe EOF (-1), wenn der Sendepuffer voll ist + // sonst das übergebene Zeichen + // int putChr(int chr); + + // ------------------------------------------------------- + // Einen 0-terminierten String in den Ringpuffer schreiben + // ------------------------------------------------------- + // Rückgabe EOF (-1), wenn im Sendepuffer nicht genug + // Platz für den String ist, + // sonst die Anzahl der Zeichen im String + // int putStr(char *msg); + + // ------------------------------------------------------- + // Eine Bytefolge der Länge n in den Ringpuffer schreiben + // ------------------------------------------------------- + // Rückgabe EOF (-1), wenn im Sendepuffer nicht genug + // Platz für die Bytefolge ist, + // sonst die Länge der Bytefolge + // int putSeq(byte *msg, int n); + int putLine(char *msg); //int putLine(char *msg, char c); //int putLine(char *msg, int n); @@ -219,6 +251,15 @@ public: // Debugging // -------------------------------------------------------------------------- // + typedef struct _DbBufValues + { + int rbRdIdx; + int rbWrIdx; + int tbRdIdx; + int tbWrIdx; + } DbBufValues, *pDbBufValues; + + int dbGetBufValues(pDbBufValues valPtr); }; diff --git a/libraries/StateMachine/StateMachine.h b/libraries/StateMachine/StateMachine.h index b5a6ecea89a1a4a81795bf2992e52dd58bb350d2..2b08bf9a19fae2406e2314c6bd8ecb03f95d15b7 100644 --- a/libraries/StateMachine/StateMachine.h +++ b/libraries/StateMachine/StateMachine.h @@ -83,6 +83,7 @@ public: int cycleTime; // Cycle time in milliseconds int frequency; // Frequency in Hertz (1/s) int userStatus; // A number presenting the visible state + int userVar; // Variable for random usage // statistic information // diff --git a/libraries/environment/IntrfSerial.h b/libraries/environment/IntrfSerial.h index 909a810a3282ef0e1ee36e79286bd5c4df0bb929..00fe6321b7e2040a395a36717bc82b22a8390c7b 100644 --- a/libraries/environment/IntrfSerial.h +++ b/libraries/environment/IntrfSerial.h @@ -47,9 +47,18 @@ typedef enum _SerType stCur // Open Collector/Drain ca. 10 mA Stromschleife } SerType; +typedef enum _SerNumber +{ + SerCom1, + SerCom2, + SerCom3, + SerCom4, + SerCom5 +} SerNumber; + typedef struct _SerParams { - int inst; // Nummer (Index) der Ser-Instanz + SerNumber inst; // Nummer (Index) der Ser-Instanz int txdPort; // Nummer (Index) des Port fuer TX int txdPin; // Nummer (Index) des Pin fuer TX int rxdPort; // Nummer (Index) des Port fuer RX diff --git a/libraries/environment/environment.h b/libraries/environment/environment.h index 311c3331bd39a97884ba12b85375b08a418813d0..38fd910350dfb99f787fd2a5caf8a204e61dba53 100644 --- a/libraries/environment/environment.h +++ b/libraries/environment/environment.h @@ -78,6 +78,13 @@ #define smnSerial SerialUSB #endif + #ifdef smnRASPI + #define smnSimLinux + #define smnLINUX + #define smnDebugLinuxConsole + #define smnSerial SerialTerm + #endif + #else // Die Definitionen werden hier in den meisten Fällen grundsetzlich ausgewertet, diff --git a/libraries/environment/socManNetUser.h b/libraries/environment/socManNetUser.h index 4809a3b98de3da0b84f1f25ba7cda8af91bb2672..ed173b7939f03dc05d47429df4e7e0271a883627 100644 --- a/libraries/environment/socManNetUser.h +++ b/libraries/environment/socManNetUser.h @@ -303,10 +303,15 @@ #else // *************************************************************************** #undef _socManNetUser_h + + #ifdef smnRASPI + #include "smnMfpAmes.h" + #else #include MyNetFile // Define MyNetFile in Project-Properties with -DMyNetFile=\"xxxxx\" // and xxxxx being your filename. // Define also smnMyNet with -DsmnMyNet to enter this include directive + #endif #endif // smnMyNet // *************************************************************************** diff --git a/libraries/nRF52840SerE/nRF52840SerE.cpp b/libraries/nRF52840SerE/nRF52840SerE.cpp new file mode 100644 index 0000000000000000000000000000000000000000..808be7877aecafa169305990cff38a58a1b5ddff --- /dev/null +++ b/libraries/nRF52840SerE/nRF52840SerE.cpp @@ -0,0 +1,372 @@ +//----------------------------------------------------------------------------- +// Thema: Social Manufacturing Network / Development Environment +// Datei: nRF52840SerE.cpp +// Editor: Robert Patzke +// URI/URL: www.mfp-portal.de +//----------------------------------------------------------------------------- +// Lizenz: CC-BY-SA (wikipedia: Creative Commons) +// + +#include "nRF52840SerE.h" +#include <string.h> + +// ---------------------------------------------------------------------------- +// Initialisierungen +// ---------------------------------------------------------------------------- + +nRF52840SerE::nRF52840SerE() +{ + serPtr = NULL; + instPtr0 = NULL; + bufIf = NULL; + + irqCounter = 0; + curIntEn = 0; + curIRQ = 0; + lastError = 0; + cntError = 0; + anyError = 0; + txdFin = false; + + irqIdx = 0; + firstRead = false; + extraValue = 0; +} + +dword speedArr[18] = +{ + 0x0004F000, 0x0009D000, 0x0013B000, + 0x00275000, 0x003B0000, 0x004EA000, + 0x0075F000, 0x00800000, 0x009D5000, + 0x00E50000, 0x00EBF000, 0x013A9000, + 0x01D7E000, 0x03AFB000, 0x04000000, + 0x075F7000, 0x0EBED000, 0x10000000 +}; + +// ---------------------------------------------------------------------------- +// Konfiguration +// ---------------------------------------------------------------------------- +// +void nRF52840SerE::begin(SerParamsPtr inParPtr, IntrfBuf *bufferIf) +{ + nrfGpioPtr gpioPtr; + dword regVal; + + if(inParPtr->inst == SerCom1) + { + // Setzen des Peripheriezeigers anhand der Instanz + // und Initialisieren weiterer Variablen/Zeiger + // + serPtr = NrfSerPtr0; + clrAllEvents(); + instPtr0 = this; + curIRQ = 2; + + // Interruptvektor setzen + // + __NVIC_SetVector((IRQn_Type) 2, (dword) nRF52840SerE::irqHandler0); + __NVIC_SetPriority((IRQn_Type) 2, 1); + __NVIC_EnableIRQ((IRQn_Type) 2); + } + else + { + // Setzen des Peripheriezeigers anhand der Instanz + // und Initialisieren weiterer Variablen/Zeiger + // + serPtr = NrfSerPtr1; + clrAllEvents(); + instPtr1 = this; + curIRQ = 40; + + // Interruptvektor setzen + // + __NVIC_SetVector((IRQn_Type) 40, (dword) nRF52840SerE::irqHandler1); + __NVIC_SetPriority((IRQn_Type) 40, 1); + __NVIC_EnableIRQ((IRQn_Type) 40); + } + + + // Alternative Peripherie (gleiche ID, also Alles) abschalten + // + serPtr->ENABLE = SerDisable; + + + // TxD + // ------------------------------------------------- + // + // Pins zuweisen und initialisieren + // + if(inParPtr->txdPort == 1) + { + regVal = 32 + inParPtr->txdPin; + gpioPtr = NrfGpioPtr1; + } + else + { + regVal = inParPtr->txdPin; + gpioPtr = NrfGpioPtr0; + } + + + // Connect (hoechstwertiges Bit) beruecksichtigen + // + serPtr->PSEL_TXD = regVal | 0x7FFFFFC0; + + // Zugewiesenen Pin als Ausgang schalten und Treibermodus setzen + // Laut Datenblatt ist das entsprechende Bit im Konfigurationsregister + // mit dem DIR-Register physikalisch verbunden + // + if(inParPtr->type == stStd) + regVal = GpioPinCnf_DRIVE(GpioDriveS0S1); + else if(inParPtr->type == stPow) + regVal = GpioPinCnf_DRIVE(GpioDriveH0H1); + else + regVal = GpioPinCnf_DRIVE(GpioDriveH0D1); + + gpioPtr->PIN_CNF[inParPtr->txdPin] = regVal | GpioPinCnf_DIROUT; + + serPtr->TXD_PTR = (dword) txdEdmaBuf; + serPtr->TXD_MAXCNT = 1; + + // RXD + // ------------------------------------------------- + // + if(inParPtr->rxdPort == 1) + { + regVal = 32 + inParPtr->rxdPin; + gpioPtr = NrfGpioPtr1; + } + else + { + regVal = inParPtr->rxdPin; + gpioPtr = NrfGpioPtr0; + } + + // Connect (hoechstwertiges Bit) beruecksichtigen + // + serPtr->PSEL_RXD = regVal | 0x7FFFFFC0; + + // Zugewiesenen Pin als Eingang schalten und Treibermodus setzen + // Laut Datenblatt ist das entsprechende Bit im Konfigurationsregister + // mit dem DIR-Register physikalisch verbunden + // + gpioPtr->PIN_CNF[inParPtr->rxdPin] = GpioPinCnf_PULL(GpioPullUp); + + serPtr->RXD_PTR = (dword) rxdEdmaBuf; + serPtr->RXD_MAXCNT = 1; + + + // Bitrate einstellen + // + regVal = speedArr[inParPtr->speed]; + serPtr->BAUDRATE = regVal; + + // Verkopplungen einstellen + // + serPtr->SHORTS = Short_ENDRX_STARTRX; // Empfang durchgehend + + // Interrupts freischalten + // + curIntEn = (SerInt_ENDTX | SerInt_ENDRX | SerInt_ERROR); + serPtr->INTENSET = curIntEn; + + // Und bereit machen + // + serPtr->ENABLE = SerEnable; + txdFin = true; + + bufIf = bufferIf; + delay(10); +} + + +// ---------------------------------------------------------------------------- +// Steuerfunktionen, gezielte Prozessorzugriffe und Hilfsfunktionen +// ---------------------------------------------------------------------------- +// +void nRF52840SerE::clrAllEvents() +{ + serPtr->EVENTS_ENDRX = 0; + serPtr->EVENTS_ENDTX = 0; + serPtr->EVENTS_ERROR = 0; +} + +// Fortsetzen des Interrupt-Sendebetriebs +// +void nRF52840SerE::resuSend() +{ + byte td; + + if(!txdFin) return; + if(bufIf == NULL) return; + if(!bufIf->getByteSnd(&td)) return; + + txdFin = false; + serPtr->EVENTS_ENDTX = 0; + txdEdmaBuf[0] = td; + serPtr->TASKS_STARTTX = 1; +} + +// Starten des Sendebetriebs +// +void nRF52840SerE::startSend() +{ + resuSend(); +} + +// Anhalten des Sendebetriebs +// +void nRF52840SerE::stopSend() +{ + serPtr->TASKS_STOPTX = 1; +} + +// Starten des Empfangsbetriebs +// +void nRF52840SerE::startRec() +{ + serPtr->TASKS_STARTRX = 1; +} + +// Anhalten des Empfangsbetriebs +// +void nRF52840SerE::stopRec() +{ + serPtr->TASKS_STOPRX = 1; +} + + +// Bedingtes Ausgeben eines Zeichens +// +bool nRF52840SerE::condSend(byte c) +{ + if(!txdFin) return(false); + + txdFin = false; + serPtr->EVENTS_ENDTX = 0; + txdEdmaBuf[0] = c; + serPtr->TASKS_STARTTX = 1; + return(true); +} + +// ---------------------------------------------------------------------------- +// Ereignisbearbeitung und Interrupts +// ---------------------------------------------------------------------------- +// +nRF52840SerE *nRF52840SerE::instPtr0 = NULL; + +void nRF52840SerE::irqHandler0() +{ + if(instPtr0 == NULL) return; + instPtr0->irqCounter++; + instPtr0->irqHandler(); +} + +nRF52840SerE *nRF52840SerE::instPtr1 = NULL; + +void nRF52840SerE::irqHandler1() +{ + if(instPtr1 == NULL) return; + instPtr1->irqCounter++; + instPtr1->irqHandler(); +} + + + // -------------------------------------------------------------------------- + // Interrupts (Ereignisbehandlung) + // -------------------------------------------------------------------------- + // +void nRF52840SerE::irqHandler() +{ + byte b; + + if(serPtr->EVENTS_ENDTX != 0) + { + serPtr->EVENTS_ENDTX = 0; + if(bufIf == NULL) return; + + if(!bufIf->getByteSnd(&b)) + txdFin = true; + else + { + txdEdmaBuf[0] = b; + serPtr->TASKS_STARTTX = 1; + } + } + else if(serPtr->EVENTS_ENDRX != 0) + { + serPtr->EVENTS_ENDRX = 0; + if(bufIf == NULL) return; + b = rxdEdmaBuf[0]; + bufIf->putByteRec(b); + } + else if(serPtr->EVENTS_ERROR != 0) + { + serPtr->EVENTS_ERROR = 0; + cntError++; + lastError = serPtr->ERRORSRC; + anyError |= lastError; + } +} + +// -------------------------------------------------------------------------- +// Datenzugriffe +// -------------------------------------------------------------------------- +// +// Letzten Fehler lesen (Bits) +// +int nRF52840SerE::getLastError() +{ + return(lastError); +} + +// Alle vorgekommenen Fehlerbits +// +int nRF52840SerE::getAnyError() +{ + return(anyError); +} + +// Anzahl der Fehler lesen +// +dword nRF52840SerE::getErrCount() +{ + return(cntError); +} + + + +// ---------------------------------------------------------------------------- +// D e b u g - H i l f e n +// ---------------------------------------------------------------------------- +// +dword nRF52840SerE::getIrqCount() +{ + return(irqCounter); +} + +void nRF52840SerE::resetIrqList() +{ + irqIdx = 0; + firstRead = true; + + for(int i = 0; i < 8; i++) + irqList[i] = 0; +} + +void nRF52840SerE::getIrqList(char *dest) +{ + int destIdx = 0; + + for(int i = 0; i < 8; i++) + { + if(irqList[i] == 0) break; + + dest[destIdx++] = ' '; + dest[destIdx++] = irqList[i] + 0x30; + } + + dest[destIdx] = '\0'; +} + + diff --git a/libraries/nRF52840SerE/nRF52840SerE.h b/libraries/nRF52840SerE/nRF52840SerE.h new file mode 100644 index 0000000000000000000000000000000000000000..005ac48c3f75ed652ef538fd962bc557944052a8 --- /dev/null +++ b/libraries/nRF52840SerE/nRF52840SerE.h @@ -0,0 +1,288 @@ +//----------------------------------------------------------------------------- +// Thema: Social Manufacturing Network / Development Environment +// Datei: nRF52840SerE.h +// Editor: Robert Patzke +// URI/URL: www.mfp-portal.de +//----------------------------------------------------------------------------- +// Lizenz: CC-BY-SA (wikipedia: Creative Commons) +// + +#ifndef NRF52840SERE_H +#define NRF52840SERE_H + +#include "Arduino.h" +#include "arduinoDefs.h" +#include "IntrfBuf.h" +#include "IntrfSerial.h" + +// ---------------------------------------------------------------------------- + +typedef struct _nrfSer +{ + volatile dword TASKS_STARTRX; // 000 + volatile dword TASKS_STOPRX; // 004 + volatile dword TASKS_STARTTX; // 008 + volatile dword TASKS_STOPTX; // 00C + volatile dword Reserve01[3]; // 010 + volatile dword TASKS_SUSPEND; // 01C + volatile dword Reserve01a[3]; // 020 + volatile dword TASKS_FLUSHRX; // 02C + volatile dword Reserve02[52]; // 030 + volatile dword EVENTS_CTS; // 100 + volatile dword EVENTS_NCTS; // 104 + volatile dword EVENTS_RXDRDY; // 108 + volatile dword Reserve03; // 10C + volatile dword EVENTS_ENDRX; // 110 + volatile dword Reserve04[2]; // 114 + volatile dword EVENTS_TXDRDY; // 11C + volatile dword EVENTS_ENDTX; // 120 + volatile dword EVENTS_ERROR; // 124 + volatile dword Reserve05[7]; // 128 + volatile dword EVENTS_RXTO; // 144 + volatile dword Reserve05a; // 148 + volatile dword EVENTS_RXSTARTED; // 14C + volatile dword EVENTS_TXSTARTED; // 150 + volatile dword Reserve05b; // 154 + volatile dword EVENTS_TXSTOPPED; // 158 + volatile dword Reserve06[41]; // 15C + volatile dword SHORTS; // 200 + volatile dword Reserve07[63]; // 204 + volatile dword INTEN; // 300 + volatile dword INTENSET; // 304 + volatile dword INTENCLR; // 308 + volatile dword Reserve08[93]; // 30C + volatile dword ERRORSRC; // 480 + volatile dword Reserve09[31]; // 484 + volatile dword ENABLE; // 500 + volatile dword Reserve10; // 504 + volatile dword PSEL_RTS; // 508 + volatile dword PSEL_TXD; // 50C + volatile dword PSEL_CTS; // 510 + volatile dword PSEL_RXD; // 514 + volatile dword RXD; // 518 + volatile dword TXD; // 51C + volatile dword Reserve11; // 520 + volatile dword BAUDRATE; // 524 + volatile dword Reserve12[3]; // 528 + volatile dword RXD_PTR; // 534 + volatile dword RXD_MAXCNT; // 538 + volatile dword RXD_AMOUNT; // 53C + volatile dword Reserve13; // 540 + volatile dword TXD_PTR; // 544 + volatile dword TXD_MAXCNT; // 548 + volatile dword TXD_AMOUNT; // 54C + volatile dword Reserve14[7]; // 550 + volatile dword CONFIG; // 56C +} nrfSer, *nrfSerPtr; + +#define NrfSerBase0 0x40002000 +#define NrfSerPtr0 ((nrfSerPtr) NrfSerBase0) +#define NrfSerBase1 0x40028000 +#define NrfSerPtr1 ((nrfSerPtr) NrfSerBase1) + +#ifndef nrfGpioDef + +typedef struct _nrfGpio +{ + volatile dword Reserve01; // 000 + volatile dword OUT; // 004 + volatile dword OUTSET; // 008 + volatile dword OUTCLR; // 00C + volatile dword IN; // 010 + volatile dword DIR; // 014 + volatile dword DIRSET; // 018 + volatile dword DIRCLR; // 01C + volatile dword LATCH; // 020 + volatile dword DETECTMODE; // 024 + volatile dword Reserve02[118]; // 026 + volatile dword PIN_CNF[32]; // 200 +} nrfGpio, *nrfGpioPtr; + +#define NrfGpioBase 0x50000000 +#define NrfGpioBase0 0x50000500 +#define NrfGpioPtr0 ((nrfGpioPtr) NrfGpioBase0) +#define NrfGpioBase1 0x50000800 +#define NrfGpioPtr1 ((nrfGpioPtr) NrfGpioBase1) + +#define GpioPinCnf_DIROUT ((dword) 0x00000001) + +#define GpioPinCnf_DISBUF ((dword) 0x00000002) + +#define GpioPinCnf_PULL(x) ((dword) x << 2) +#define GpioPullDown 1 +#define GpioPullUp 3 + +#define GpioPinCnf_DRIVE(x) ((dword) x << 8) +#define GpioDriveS0S1 0 +#define GpioDriveH0S1 1 +#define GpioDriveS0H1 2 +#define GpioDriveH0H1 3 +#define GpioDriveD0S1 4 +#define GpioDriveD0H1 5 +#define GpioDriveS0D1 6 +#define GpioDriveH0D1 7 + +#define GpioPinCnf_SENSE(x) ((dword) x << 16) +#define GpioSenseHigh 2 +#define GpioSenseLow 3 + +#define nrfGpioDef +#endif + +// Festlegungen für die Interruptverwaltung +// + +#define SerInt_RXDRDY ((dword) 0x00000001 << 2) +// Interrupt für Event RXDRDY + +#define SerInt_ENDRX ((dword) 0x00000001 << 4) +// Interrupt für Event ENDRX + +#define SerInt_TXDRDY ((dword) 0x00000001 << 7) +// Interrupt für Event TXDRDY + +#define SerInt_ENDTX ((dword) 0x00000001 << 8) +// Interrupt für Event ENDTX + +#define SerInt_ERROR ((dword) 0x00000001 << 9) +// Interrupt für Event ERROR + +#define SerInt_RXTO ((dword) 0x00000001 << 17) +// Interrupt für Event RXTO + +#define SerInt_RXSTARTED ((dword) 0x00000001 << 19) +// Interrupt für Event RXSTARTED + +#define SerInt_TXSTARTED ((dword) 0x00000001 << 20) +// Interrupt für Event TXSTARTED + +#define SerInt_TXSTOPPED ((dword) 0x00000001 << 22) +// Interrupt für Event TXSTOPPED + + +// Festlegungen für die Direktsteuerung (SHORTS) +// + +#define Short_ENDRX_STARTRX ((dword) 0x00000001 << 5) +// Event ENDRX started automatisch Task STARTRX + +#define Short_ENDRX_STOPRX ((dword) 0x00000001 << 6) +// Event ENDRX started automatisch Task STOPRX + + +// Kodierung der Inbetriebnahme +// +#define SerEnable 8 +#define SerDisable 0 + +// Bit-Masken fuer Kommunikationsbedingungen +// +#define BM_REC_NOT_COND 0x00 +// Keine Bedingungen beim Empfang +#define BM_REC_END_CHR 0x01 +// Empfang Stoppen beim Eintreffen des vorgegebenen Zeichens +#define BM_REC_RINGBUF 0x02 +// Receive characters in ring buffer +#define BM_SND_RINGBUF 0x04 +// Transmit characters via ring buffer + + + +// ---------------------------------------------------------------------------- + +class nRF52840SerE : IntrfSerial +{ +private: + // -------------------------------------------------------------------------- + // Lokale Daten und Funktionen + // -------------------------------------------------------------------------- + // + nrfSerPtr serPtr; + dword irqCounter; + + int lastError; + int anyError; + dword cntError; + + int curIRQ; + dword curIntEn; + + IntrfBuf *bufIf; + bool txdFin; // TRUE = Sendevorgang beendet + byte txdEdmaBuf[4]; // Zur Zeit nur 1 Platz genutzt + byte rxdEdmaBuf[4]; // Zur Zeit nur 1 Platz genutzt + + void clrAllEvents(); + +public: + // -------------------------------------------------------------------------- + // Initialisierungen der Basis-Klasse + // -------------------------------------------------------------------------- + + nRF52840SerE(); + + // -------------------------------------------------------------------------- + // Konfigurationen + // -------------------------------------------------------------------------- + // + void begin(SerParamsPtr serParPtr, IntrfBuf *bufferIf); + + + // -------------------------------------------------------------------------- + // Steuerfunktionen + // -------------------------------------------------------------------------- + // + void resuSend(); // Fortsetzen des Interrupt-Sendebetriebs + void startSend(); // Starten des Sendebetriebs + void stopSend(); // Anhalten des Sendebetriebs + + void startRec(); // Starten des Empfangsbetriebs + void stopRec(); // Anhalten des Empfangsbetriebs + + + // -------------------------------------------------------------------------- + // Datenzugriffe + // -------------------------------------------------------------------------- + // + bool condSend(byte c); // Bedingtes Senden eines Zeichens + + int getLastError(); // Letzten Fehler lesen (Bits) + int getAnyError(); // Alle vorgekommenen Fehlerbits + dword getErrCount(); // Anzahl der Fehler lesen + + + // ---------------------------------------------------------------------------- + // Ereignisbearbeitung und Interrupts + // ---------------------------------------------------------------------------- + // + static nRF52840SerE *instPtr0; + static void irqHandler0(); + static nRF52840SerE *instPtr1; + static void irqHandler1(); + + void irqHandler(); + + // -------------------------------------------------------------------------- + // lokale Variablen + // -------------------------------------------------------------------------- + // + + + // ---------------------------------------------------------------------------- + // D e b u g - H i l f e n + // ---------------------------------------------------------------------------- + // + int irqIdx; + int irqList[8]; + + byte extraValue; + bool firstRead; + + dword getIrqCount(); + void resetIrqList(); + void getIrqList(char *dest); + +}; + +#endif // NRF52840SERE_H +