test

Dependencies:   SimpleDMA mbed-rtos mbed

Fork of spiDMAtest by Shreesha S

Files at this revision

API Documentation at this revision

Comitter:
shreeshas95
Date:
Thu Jul 16 05:40:25 2015 +0000
Parent:
1:3cceef118195
Child:
3:972fa06ef0aa
Commit message:
SPI slave DMA read program for FRDMKL46Z , verified, working

Changed in this revision

dmaSPIslave.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/dmaSPIslave.h	Thu Jul 16 05:19:02 2015 +0000
+++ b/dmaSPIslave.h	Thu Jul 16 05:40:25 2015 +0000
@@ -1,6 +1,11 @@
 #ifdef TARGET_KL46Z
 class dmaSPISlave : public SPISlave{
     public:
+/*
+@brief:     constructor : initialise the spi slave pins
+@param:     mosi, miso, sclk, ssel
+@return:    none
+*/
         dmaSPISlave(PinName mosi, PinName miso, PinName sclk, PinName ssel) : SPISlave(mosi, miso, sclk, ssel){
 //            trigger appropriate spi for dma
             if(_spi.spi == SPI0){
@@ -14,6 +19,13 @@
             read_dma.source(&_spi.spi->DL, false);
         }
         
+/*
+@brief:     initialise the dma buffer to store the recevied data
+@param:     read_data : pointer to the buffer
+            len : length in bytes to store in the buffer
+            fun : address of the function to attach to the dma interrupt, interrupt is called when the len num of bytes are written to the buffer
+@return:    none
+*/
         void bulkRead_init(uint8_t *read_data, int len, void (*fun)(void) ){
 //            acquire();
             _spi.spi->C2 |= SPI_C2_RXDMAE_MASK;
@@ -27,13 +39,27 @@
 //            attach interrupt function
             read_dma.attach(fun);
 
-//            _spi.spi->C2 &= ~(SPI_C2_RXDMAE_MASK);
         }
         
+/*
+@brief:     start the dma read process : has to be done everytime the buffer gets filled, can be used repeatedly
+@param:     none
+@return:    none
+*/
         void bulkRead_start(){
 //            start the read_dma
             read_dma.start(length);
         }
+
+/*
+@brief:     end dma process and return back to normal spi mode
+@param:     none
+@return:    none
+*/
+        void bulkRead_end(){
+//            turn off dma
+            _spi.spi->C2 &= ~(SPI_C2_RXDMAE_MASK);
+        }
         
     private:
         int length;
--- a/main.cpp	Thu Jul 16 05:19:02 2015 +0000
+++ b/main.cpp	Thu Jul 16 05:40:25 2015 +0000
@@ -1,5 +1,4 @@
 #include "mbed.h"
-#include "rtos.h"
 #include "SimpleDMA.h"
 #include "dmaSPIslave.h"
 
@@ -19,37 +18,27 @@
     pc.baud(9600);
     pc.printf("inside main\r\n");
     spi.format(8,0);
-//    spi.frequency(16000000);
+    spi.frequency(10000000);
     
     uint8_t buffer[PAYLOAD_LENGTH] = {0};
     pc.printf("welcome to dma test, start sending data now\r\n");
+
+//    initialise the buffer for dma
+    spi.bulkRead_init(buffer, PAYLOAD_LENGTH, &do_this);
+//    start dma read
+    spi.bulkRead_start();
     
-//    while(true){
-//        int i = 0;
-//        while(i < PAYLOAD_LENGTH){
-//            if(spi.receive()){
-//                buffer[i] = spi.read();
-//                ++i;
-//                ledg = !ledg;
-//            }
-//        }
-//        for(int i = 0 ; i < PAYLOAD_LENGTH ; ++i){
-//            pc.printf("%02x ", buffer[i]);
-//        }
-//        pc.printf("\r\n");
-//
-//    }
-
-    spi.bulkRead_init(buffer, PAYLOAD_LENGTH, &do_this);
-    spi.bulkRead_start();
     while(true){
         if(flag){
             flag = false;
             ledg = !ledg;
-            for(int i = 0 ; i < PAYLOAD_LENGTH ; ++i){
-                pc.printf("%02x ", buffer[i]);
-            }
-            pc.printf("\r\n");
+
+//            for(int i = 0 ; i < PAYLOAD_LENGTH ; ++i){
+//                pc.printf("%02x ", buffer[i]);
+//            }
+//            pc.printf("\r\n");
+
+//            start dma again after handling the data
             spi.bulkRead_start();
         }
     }