MTS_SPI_Slave unfinished

Fork of MTS-Serial by Scott Hoppe

Files at this revision

API Documentation at this revision

Comitter:
ScottHoppeMultitech
Date:
Thu Dec 28 21:10:02 2017 +0000
Parent:
14:d5a86071845e
Commit message:
Changes to allow for API communication

Changed in this revision

MTS_SPI_Slave.cpp Show annotated file Show diff for this revision Revisions of this file
MTS_SPI_Slave.h Show annotated file Show diff for this revision Revisions of this file
--- a/MTS_SPI_Slave.cpp	Thu Nov 16 17:02:41 2017 +0000
+++ b/MTS_SPI_Slave.cpp	Thu Dec 28 21:10:02 2017 +0000
@@ -2,40 +2,32 @@
 #include "MTS_SPI_Slave.h"
 #include "MTSLog.h"
 #include <Thread.h>
+Serial mts_debug(USBTX, USBRX); //DEBUG
 
 using namespace mts;
-Serial debug(USBTX, USBRX); //DELETE
-
 MTS_SPI_Slave::MTS_SPI_Slave(PinName mosi, PinName miso, PinName sclk, PinName ssel, int txBufferSize, int rxBufferSize)
     : MTSBufferedIO(txBufferSize, rxBufferSize)
     , spi(mosi,miso,sclk,ssel)
-    , _thread(new Thread)
+    , thread()
 
 {
-   //this is where you are going to have a thread that is constantly polling to see if data has been sent, having the thread go to sleep in the time inbetween the polling
+   mts_debug.baud(115200); //DEBUG
+   thread.start(this, &MTS_SPI_Slave::polling_Read);
 
    
-   debug.baud(115200); //DELETE
-  // _thread->start(this, &MTS_SPI_Slave::recieved_Read);
-   osStatus status = _thread->start(this, &MTS_SPI_Slave::recieved_Read);
-        if (status != osOK) {
-            debug.printf("Thread is not OK");
-        }
-   debug.printf("Thread state:  %d\n\r",_thread->get_state());
+   
 }
 
 MTS_SPI_Slave::~MTS_SPI_Slave()
 {
 }
 
-void MTS_SPI_Slave::recieved_Read(){
-            debug.printf("Outside While\n\r");
+ void MTS_SPI_Slave::polling_Read(){
         while(true){
-           // debug.printf("Within While\n\r");
             if(this->receive()){
-                 debug.printf("Recieved\n\r");
                 this->handleRead();
                 }
+            thread.wait(2000); // 2 micro seconds
             }
     }
 
@@ -55,9 +47,9 @@
 
 void MTS_SPI_Slave::handleRead(){
     
-    int byte = spi.read();
-    debug.printf("handleRead() executed with byte: %c \n\r",byte);
-    if(rxBuffer.write((char)byte) != 1) {
+    char byte = spi.read();
+    mts_debug.printf("MTS - handleRead() executed, recieved byte: %c \n\r",byte);
+    if(rxBuffer.write(byte) != 1) {
         logError("SPI Rx Byte Dropped [%c][0x%02X]", byte, byte);
     }
 }
--- a/MTS_SPI_Slave.h	Thu Nov 16 17:02:41 2017 +0000
+++ b/MTS_SPI_Slave.h	Thu Dec 28 21:10:02 2017 +0000
@@ -14,8 +14,8 @@
     MTS_SPI_Slave(PinName mosi, PinName miso, PinName sclk, PinName ssel, int txBufferSize = 256, int rxBufferSize = 256);
 
     ~MTS_SPI_Slave();
-
-    void recieved_Read();
+    
+    void polling_Read();
     
     void frequency(int frequency);
 
@@ -23,12 +23,14 @@
 
 protected:
     SPISlave spi; 
+    Thread thread;
 
 private: 
     virtual int receive();
     virtual void handleRead();
     virtual void handleWrite(); 
-    Thread* _thread;
+
+
 };
 
 }