DMA for Science thread
Dependencies: SimpleDMA mbed-rtos mbed
Fork of spiDMAtest by
main.cpp@4:9cc2653d3e83, 2016-09-24 (annotated)
- Committer:
- ee12b079
- Date:
- Sat Sep 24 08:13:32 2016 +0000
- Revision:
- 4:9cc2653d3e83
- Parent:
- 2:16545dbc88ae
checking dma - 24-09-2016
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shreeshas95 | 0:f0f5102ed9ca | 1 | #include "mbed.h" |
shreeshas95 | 0:f0f5102ed9ca | 2 | #include "SimpleDMA.h" |
shreeshas95 | 0:f0f5102ed9ca | 3 | #include "dmaSPIslave.h" |
ee12b079 | 4:9cc2653d3e83 | 4 | #define PAYLOAD_LENGTH 6723 |
ee12b079 | 4:9cc2653d3e83 | 5 | #define PAY_SPI_MOSI PTE18 |
ee12b079 | 4:9cc2653d3e83 | 6 | #define PAY_SPI_MISO PTE19 |
ee12b079 | 4:9cc2653d3e83 | 7 | #define PAY_SPI_CLK PTE17 |
ee12b079 | 4:9cc2653d3e83 | 8 | #define PAY_SPI_CS PTE16 |
ee12b079 | 4:9cc2653d3e83 | 9 | Timer T; |
ee12b079 | 4:9cc2653d3e83 | 10 | dmaSPISlave spi(PAY_SPI_MOSI, PAY_SPI_MISO, PAY_SPI_CLK, PAY_SPI_CS); |
shreeshas95 | 0:f0f5102ed9ca | 11 | RawSerial pc(USBTX, USBRX); |
ee12b079 | 4:9cc2653d3e83 | 12 | DigitalOut ledg(PTB11); |
shreeshas95 | 0:f0f5102ed9ca | 13 | |
shreeshas95 | 1:3cceef118195 | 14 | bool flag = false; |
shreeshas95 | 1:3cceef118195 | 15 | |
shreeshas95 | 1:3cceef118195 | 16 | void do_this(void){ |
shreeshas95 | 1:3cceef118195 | 17 | flag = true; |
shreeshas95 | 1:3cceef118195 | 18 | } |
shreeshas95 | 1:3cceef118195 | 19 | |
shreeshas95 | 0:f0f5102ed9ca | 20 | int main(){ |
ee12b079 | 4:9cc2653d3e83 | 21 | pc.baud(1200); |
shreeshas95 | 0:f0f5102ed9ca | 22 | pc.printf("inside main\r\n"); |
shreeshas95 | 1:3cceef118195 | 23 | spi.format(8,0); |
ee12b079 | 4:9cc2653d3e83 | 24 | spi.frequency(1000000); |
shreeshas95 | 0:f0f5102ed9ca | 25 | |
shreeshas95 | 1:3cceef118195 | 26 | uint8_t buffer[PAYLOAD_LENGTH] = {0}; |
shreeshas95 | 0:f0f5102ed9ca | 27 | pc.printf("welcome to dma test, start sending data now\r\n"); |
shreeshas95 | 2:16545dbc88ae | 28 | |
shreeshas95 | 2:16545dbc88ae | 29 | // initialise the buffer for dma |
shreeshas95 | 2:16545dbc88ae | 30 | spi.bulkRead_init(buffer, PAYLOAD_LENGTH, &do_this); |
shreeshas95 | 2:16545dbc88ae | 31 | // start dma read |
shreeshas95 | 2:16545dbc88ae | 32 | spi.bulkRead_start(); |
ee12b079 | 4:9cc2653d3e83 | 33 | T.start(); |
shreeshas95 | 1:3cceef118195 | 34 | while(true){ |
shreeshas95 | 1:3cceef118195 | 35 | if(flag){ |
shreeshas95 | 1:3cceef118195 | 36 | flag = false; |
shreeshas95 | 1:3cceef118195 | 37 | ledg = !ledg; |
ee12b079 | 4:9cc2653d3e83 | 38 | pc.printf("re %f\n",T.read()); |
ee12b079 | 4:9cc2653d3e83 | 39 | /*for(int i = 0 ; i < PAYLOAD_LENGTH ; ++i){ |
ee12b079 | 4:9cc2653d3e83 | 40 | pc.printf("%02x ", buffer[i]); |
ee12b079 | 4:9cc2653d3e83 | 41 | } |
ee12b079 | 4:9cc2653d3e83 | 42 | pc.printf("\r\n");*/ |
shreeshas95 | 2:16545dbc88ae | 43 | |
shreeshas95 | 2:16545dbc88ae | 44 | // start dma again after handling the data |
shreeshas95 | 1:3cceef118195 | 45 | spi.bulkRead_start(); |
shreeshas95 | 1:3cceef118195 | 46 | } |
shreeshas95 | 0:f0f5102ed9ca | 47 | } |
shreeshas95 | 0:f0f5102ed9ca | 48 | |
shreeshas95 | 0:f0f5102ed9ca | 49 | } |