Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed mbed-rtos SimpleDMA FreescaleIAP eeprom
Fork of CDMS_CODE_FM_28JAN2017 by
dmaSPIslave.h
00001 #ifndef DMASPISLAVE_H // To make sure you don't declare the function more than once by including the header multiple times. 00002 #define DMASPISLAVE_H 00003 00004 #ifdef TARGET_KL46Z 00005 class dmaSPISlave : public SPISlave{ 00006 public: 00007 /* 00008 @brief: constructor : initialise the spi slave pins 00009 @param: mosi, miso, sclk, ssel 00010 @return: none 00011 */ 00012 dmaSPISlave(PinName mosi, PinName miso, PinName sclk, PinName ssel) : SPISlave(mosi, miso, sclk, ssel){ 00013 // trigger appropriate spi for dma 00014 if(_spi.spi == SPI0){ 00015 read_dma.trigger(Trigger_SPI0_RX); 00016 } 00017 else{ 00018 read_dma.trigger(Trigger_SPI1_RX); 00019 } 00020 00021 // set source for spi slave dma : mosi 00022 read_dma.source(&_spi.spi->DL, false); 00023 } 00024 00025 /* 00026 @brief: initialise the dma buffer to store the recevied data 00027 @param: read_data : pointer to the buffer 00028 len : length in bytes to store in the buffer 00029 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 00030 @return: none 00031 */ 00032 void bulkRead_init(uint8_t *read_data, int len, void (*fun)(void) ){ 00033 // acquire(); 00034 _spi.spi->C2 |= SPI_C2_RXDMAE_MASK; 00035 00036 // auto increment is true 00037 read_dma.destination(read_data, true); 00038 00039 // specify length 00040 length = len; 00041 00042 // attach interrupt function 00043 read_dma.attach(fun); 00044 00045 } 00046 00047 void bulkRead_pause(){ 00048 read_dma.attach(NULL); 00049 } 00050 00051 void bulkRead_resume(void (*fun)(void)){ 00052 read_dma.attach(fun); 00053 } 00054 /* 00055 @brief: start the dma read process : has to be done everytime the buffer gets filled, can be used repeatedly 00056 @param: none 00057 @return: none 00058 */ 00059 void bulkRead_start(){ 00060 // start the read_dma 00061 read_dma.start(length); 00062 } 00063 00064 /* 00065 @brief: end dma process and return back to normal spi mode, there should not be an unfinished 'start' when running end 00066 @param: none 00067 @return: none 00068 */ 00069 void bulkRead_end(){ 00070 // turn off dma 00071 _spi.spi->C2 &= ~(SPI_C2_RXDMAE_MASK); 00072 } 00073 00074 /* 00075 @brief: restart the dma process after 'end'ing 00076 @param: none 00077 @return: none 00078 */ 00079 void bulkRead_restart(){ 00080 _spi.spi->C2 |= SPI_C2_RXDMAE_MASK; 00081 } 00082 private: 00083 int length; 00084 SimpleDMA read_dma; 00085 }; 00086 #endif 00087 #endif
Generated on Tue Jul 12 2022 15:50:06 by
1.7.2
