Forking https://os.mbed.com/users/cam/code/Modbus/ to work for NUCLEO 64 boards

Fork of Cam's original FreeModbus port (https://os.mbed.com/users/cam/code/Modbus/)

Change: - Serial implementation to work for NUCLEO 64 boards and receive interrupts instead of timer. (see `portserial.cpp`)

Added: - Custom RTU mode. Allows for external implementation of packet receiving and sending. Sends and receives packets as whole frames (address + PDU) (i.e. this was added for a custom LoRa implementation). implement `xMBRTUCustGetPDU` and `xMBRTUCustSendResponse` (see `mbport.h`) and call `eMBRTUCustomInit( address )`. implementations need to be fully initialised as `eMBRTUCustomInit` only sets the address and nothing else.

Revision:
1:e2f569d323c9
Parent:
0:0453a0a7e500
Child:
4:7621103c5a40
--- a/portserial.cpp	Thu Apr 15 12:10:34 2010 +0000
+++ b/portserial.cpp	Tue Dec 03 04:20:22 2019 +0000
@@ -21,7 +21,7 @@
 
 /* ----------------------- System includes ----------------------------------*/
 #include "mbed.h"                   // Cam
-
+#include "RawSerial.h"
 /* ----------------------- Platform includes --------------------------------*/
 #include "port.h"
 
@@ -29,6 +29,14 @@
 #include "mb.h"
 #include "mbport.h"
 
+// Dan - Allow serial pins to be configurable in json config
+#ifndef MBED_CONF_APP_MODBUS_SERIAL_TX
+#define MBED_CONF_APP_MODBUS_SERIAL_TX USBTX
+#endif
+
+#ifndef MBED_CONF_APP_MODBUS_SERIAL_RX
+#define MBED_CONF_APP_MODBUS_SERIAL_RX USBRX
+#endif
 
 /* ----------------------- static functions ---------------------------------*/
 static void prvvUARTTxReadyISR( void );
@@ -36,7 +44,7 @@
 static void prvvUARTISR( void );
 
 /* ----------------------- System Variables ---------------------------------*/
-Serial pc(USBTX, USBRX);            // Cam - mbed USB serial port
+RawSerial modbus_serial(MBED_CONF_APP_MODBUS_SERIAL_TX, MBED_CONF_APP_MODBUS_SERIAL_RX); // Dan
 
 Ticker simISR;                      // Cam - mbed ticker
                                     // we don't have the TX buff empty interrupt, so
@@ -50,16 +58,13 @@
 /* ----------------------- Start implementation -----------------------------*/
 // Cam - This is called every 1mS to simulate Rx character received ISR and
 // Tx buffer empty ISR.
+// Dan - Edited to only simulate Tx buffer empty ISR.
 static void
 prvvUARTISR( void )
 {
     if (TxEnable)
-        if(pc.writeable())
-            prvvUARTTxReadyISR();
-            
-    if (RxEnable)
-        if(pc.readable())
-            prvvUARTRxISR();          
+        if(modbus_serial.writeable())
+            prvvUARTTxReadyISR();    
 }
 
 void
@@ -75,6 +80,7 @@
 BOOL
 xMBPortSerialInit( UCHAR ucPORT, ULONG ulBaudRate, UCHAR ucDataBits, eMBParity eParity )
 {
+    modbus_serial.attach(&prvvUARTRxISR, RawSerial::RxIrq); // Dan
     simISR.attach_us(&prvvUARTISR,1000);    // Cam - attach prvvUARTISR to a 1mS ticker to simulate serial interrupt behaviour
                                             // 1mS is just short of a character time at 9600 bps, so quick enough to pick
                                             // up status on a character by character basis.
@@ -87,7 +93,7 @@
     /* Put a byte in the UARTs transmit buffer. This function is called
      * by the protocol stack if pxMBFrameCBTransmitterEmpty( ) has been
      * called. */
-    pc.putc( ucByte);
+    modbus_serial.putc( ucByte);
     return TRUE;
 }
 
@@ -97,7 +103,7 @@
     /* Return the byte in the UARTs receive buffer. This function is called
      * by the protocol stack after pxMBFrameCBByteReceived( ) has been called.
      */
-    * pucByte = pc.getc();
+    *pucByte = modbus_serial.getc();
     return TRUE;
 }