for frequency correction testing

Dependencies:   FreescaleIAP SimpleDMA mbed-rtos mbed

Fork of CDMS_CODE by shubham c

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers dmaSPIslave.h Source File

dmaSPIslave.h

00001 #ifdef TARGET_KL46Z
00002 class dmaSPISlave : public SPISlave{
00003     public:
00004 /*
00005 @brief:     constructor : initialise the spi slave pins
00006 @param:     mosi, miso, sclk, ssel
00007 @return:    none
00008 */
00009         dmaSPISlave(PinName mosi, PinName miso, PinName sclk, PinName ssel) : SPISlave(mosi, miso, sclk, ssel){
00010 //            trigger appropriate spi for dma
00011             if(_spi.spi == SPI0){
00012                 read_dma.trigger(Trigger_SPI0_RX);
00013             }
00014             else{
00015                 read_dma.trigger(Trigger_SPI1_RX);
00016             }
00017             
00018 //            set source for spi slave dma : mosi
00019             read_dma.source(&_spi.spi->DL, false);
00020         }
00021         
00022 /*
00023 @brief:     initialise the dma buffer to store the recevied data
00024 @param:     read_data : pointer to the buffer
00025             len : length in bytes to store in the buffer
00026             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
00027 @return:    none
00028 */
00029         void bulkRead_init(uint8_t *read_data, int len, void (*fun)(void) ){
00030 //            acquire();
00031             _spi.spi->C2 |= SPI_C2_RXDMAE_MASK;
00032         
00033 //            auto increment is true
00034             read_dma.destination(read_data, true);
00035         
00036 //            specify length
00037             length = len;
00038             
00039 //            attach interrupt function
00040             read_dma.attach(fun);
00041 
00042         }
00043         
00044         void bulkRead_pause(){
00045             read_dma.attach(NULL);
00046             }
00047             
00048         void bulkRead_resume(void (*fun)(void)){
00049             read_dma.attach(fun);
00050             }
00051 /*
00052 @brief:     start the dma read process : has to be done everytime the buffer gets filled, can be used repeatedly
00053 @param:     none
00054 @return:    none
00055 */
00056         void bulkRead_start(){
00057 //            start the read_dma
00058             read_dma.start(length);
00059         }
00060 
00061 /*
00062 @brief:     end dma process and return back to normal spi mode, there should not be an unfinished 'start' when running end
00063 @param:     none
00064 @return:    none
00065 */
00066         void bulkRead_end(){
00067 //            turn off dma
00068             _spi.spi->C2 &= ~(SPI_C2_RXDMAE_MASK);
00069         }
00070         
00071 /*
00072 @brief:     restart the dma process after 'end'ing
00073 @param:     none
00074 @return:    none
00075 */
00076         void bulkRead_restart(){
00077             _spi.spi->C2 |= SPI_C2_RXDMAE_MASK;
00078         }
00079     private:
00080         int length;
00081         SimpleDMA read_dma;
00082 };
00083 #endif