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: SimpleDMA mbed-rtos mbed eeprom
Fork of COM_MNG_TMTC_SIMPLE by
dmaSPIslave.h@266:ae588e75cfa4, 2016-07-15 (annotated)
- Committer:
- prasanthbj05
- Date:
- Fri Jul 15 14:59:27 2016 +0000
- Revision:
- 266:ae588e75cfa4
- Parent:
- 245:da9d1bd999da
- Child:
- 338:d63eb331a67d
Compression code modified and RLY_TMTC pointers managed
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| shreeshas95 | 101:bece931236a2 | 1 | #ifdef TARGET_KL46Z |
| shreeshas95 | 101:bece931236a2 | 2 | class dmaSPISlave : public SPISlave{ |
| shreeshas95 | 101:bece931236a2 | 3 | public: |
| shreeshas95 | 101:bece931236a2 | 4 | /* |
| shreeshas95 | 101:bece931236a2 | 5 | @brief: constructor : initialise the spi slave pins |
| shreeshas95 | 101:bece931236a2 | 6 | @param: mosi, miso, sclk, ssel |
| shreeshas95 | 101:bece931236a2 | 7 | @return: none |
| shreeshas95 | 101:bece931236a2 | 8 | */ |
| shreeshas95 | 101:bece931236a2 | 9 | dmaSPISlave(PinName mosi, PinName miso, PinName sclk, PinName ssel) : SPISlave(mosi, miso, sclk, ssel){ |
| shreeshas95 | 101:bece931236a2 | 10 | // trigger appropriate spi for dma |
| shreeshas95 | 101:bece931236a2 | 11 | if(_spi.spi == SPI0){ |
| shreeshas95 | 101:bece931236a2 | 12 | read_dma.trigger(Trigger_SPI0_RX); |
| shreeshas95 | 101:bece931236a2 | 13 | } |
| shreeshas95 | 101:bece931236a2 | 14 | else{ |
| shreeshas95 | 101:bece931236a2 | 15 | read_dma.trigger(Trigger_SPI1_RX); |
| shreeshas95 | 101:bece931236a2 | 16 | } |
| shreeshas95 | 101:bece931236a2 | 17 | |
| shreeshas95 | 101:bece931236a2 | 18 | // set source for spi slave dma : mosi |
| shreeshas95 | 101:bece931236a2 | 19 | read_dma.source(&_spi.spi->DL, false); |
| shreeshas95 | 101:bece931236a2 | 20 | } |
| shreeshas95 | 101:bece931236a2 | 21 | |
| shreeshas95 | 101:bece931236a2 | 22 | /* |
| shreeshas95 | 101:bece931236a2 | 23 | @brief: initialise the dma buffer to store the recevied data |
| shreeshas95 | 101:bece931236a2 | 24 | @param: read_data : pointer to the buffer |
| shreeshas95 | 101:bece931236a2 | 25 | len : length in bytes to store in the buffer |
| shreeshas95 | 101:bece931236a2 | 26 | 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 |
| shreeshas95 | 101:bece931236a2 | 27 | @return: none |
| shreeshas95 | 101:bece931236a2 | 28 | */ |
| shreeshas95 | 101:bece931236a2 | 29 | void bulkRead_init(uint8_t *read_data, int len, void (*fun)(void) ){ |
| shreeshas95 | 101:bece931236a2 | 30 | // acquire(); |
| shreeshas95 | 101:bece931236a2 | 31 | _spi.spi->C2 |= SPI_C2_RXDMAE_MASK; |
| shreeshas95 | 101:bece931236a2 | 32 | |
| shreeshas95 | 101:bece931236a2 | 33 | // auto increment is true |
| shreeshas95 | 101:bece931236a2 | 34 | read_dma.destination(read_data, true); |
| shreeshas95 | 101:bece931236a2 | 35 | |
| shreeshas95 | 101:bece931236a2 | 36 | // specify length |
| shreeshas95 | 101:bece931236a2 | 37 | length = len; |
| shreeshas95 | 101:bece931236a2 | 38 | |
| shreeshas95 | 101:bece931236a2 | 39 | // attach interrupt function |
| shreeshas95 | 101:bece931236a2 | 40 | read_dma.attach(fun); |
| shreeshas95 | 101:bece931236a2 | 41 | |
| shreeshas95 | 101:bece931236a2 | 42 | } |
| shreeshas95 | 101:bece931236a2 | 43 | |
| ee12b079 | 245:da9d1bd999da | 44 | void bulkRead_pause(){ |
| ee12b079 | 245:da9d1bd999da | 45 | read_dma.attach(NULL); |
| ee12b079 | 245:da9d1bd999da | 46 | } |
| ee12b079 | 245:da9d1bd999da | 47 | |
| ee12b079 | 245:da9d1bd999da | 48 | void bulkRead_resume(void (*fun)(void)){ |
| ee12b079 | 245:da9d1bd999da | 49 | read_dma.attach(fun); |
| ee12b079 | 245:da9d1bd999da | 50 | } |
| shreeshas95 | 101:bece931236a2 | 51 | /* |
| shreeshas95 | 101:bece931236a2 | 52 | @brief: start the dma read process : has to be done everytime the buffer gets filled, can be used repeatedly |
| shreeshas95 | 101:bece931236a2 | 53 | @param: none |
| shreeshas95 | 101:bece931236a2 | 54 | @return: none |
| shreeshas95 | 101:bece931236a2 | 55 | */ |
| shreeshas95 | 101:bece931236a2 | 56 | void bulkRead_start(){ |
| shreeshas95 | 101:bece931236a2 | 57 | // start the read_dma |
| shreeshas95 | 101:bece931236a2 | 58 | read_dma.start(length); |
| shreeshas95 | 101:bece931236a2 | 59 | } |
| shreeshas95 | 101:bece931236a2 | 60 | |
| shreeshas95 | 101:bece931236a2 | 61 | /* |
| ee12b079 | 178:5b42117b2ef1 | 62 | @brief: end dma process and return back to normal spi mode, there should not be an unfinished 'start' when running end |
| shreeshas95 | 101:bece931236a2 | 63 | @param: none |
| shreeshas95 | 101:bece931236a2 | 64 | @return: none |
| shreeshas95 | 101:bece931236a2 | 65 | */ |
| shreeshas95 | 101:bece931236a2 | 66 | void bulkRead_end(){ |
| shreeshas95 | 101:bece931236a2 | 67 | // turn off dma |
| shreeshas95 | 101:bece931236a2 | 68 | _spi.spi->C2 &= ~(SPI_C2_RXDMAE_MASK); |
| shreeshas95 | 101:bece931236a2 | 69 | } |
| shreeshas95 | 101:bece931236a2 | 70 | |
| ee12b079 | 178:5b42117b2ef1 | 71 | /* |
| ee12b079 | 178:5b42117b2ef1 | 72 | @brief: restart the dma process after 'end'ing |
| ee12b079 | 178:5b42117b2ef1 | 73 | @param: none |
| ee12b079 | 178:5b42117b2ef1 | 74 | @return: none |
| ee12b079 | 178:5b42117b2ef1 | 75 | */ |
| ee12b079 | 178:5b42117b2ef1 | 76 | void bulkRead_restart(){ |
| ee12b079 | 178:5b42117b2ef1 | 77 | _spi.spi->C2 |= SPI_C2_RXDMAE_MASK; |
| ee12b079 | 178:5b42117b2ef1 | 78 | } |
| shreeshas95 | 101:bece931236a2 | 79 | private: |
| shreeshas95 | 101:bece931236a2 | 80 | int length; |
| shreeshas95 | 101:bece931236a2 | 81 | SimpleDMA read_dma; |
| shreeshas95 | 101:bece931236a2 | 82 | }; |
| ee12b079 | 245:da9d1bd999da | 83 | #endif |
