test

Dependencies:   SimpleDMA mbed-rtos mbed

Fork of spiDMAtest by Siva ram

dmaSPIslave.h

Committer:
shreeshas95
Date:
2015-07-16
Revision:
1:3cceef118195
Parent:
0:f0f5102ed9ca
Child:
2:16545dbc88ae

File content as of revision 1:3cceef118195:

#ifdef TARGET_KL46Z
class dmaSPISlave : public SPISlave{
    public:
        dmaSPISlave(PinName mosi, PinName miso, PinName sclk, PinName ssel) : SPISlave(mosi, miso, sclk, ssel){
//            trigger appropriate spi for dma
            if(_spi.spi == SPI0){
                read_dma.trigger(Trigger_SPI0_RX);
            }
            else{
                read_dma.trigger(Trigger_SPI1_RX);
            }
            
//            set source for spi slave dma : mosi
            read_dma.source(&_spi.spi->DL, false);
        }
        
        void bulkRead_init(uint8_t *read_data, int len, void (*fun)(void) ){
//            acquire();
            _spi.spi->C2 |= SPI_C2_RXDMAE_MASK;
        
//            auto increment is true
            read_dma.destination(read_data, true);
        
//            specify length
            length = len;
            
//            attach interrupt function
            read_dma.attach(fun);

//            _spi.spi->C2 &= ~(SPI_C2_RXDMAE_MASK);
        }
        
        void bulkRead_start(){
//            start the read_dma
            read_dma.start(length);
        }
        
    private:
        int length;
        SimpleDMA read_dma;
};
#endif