![](/media/cache/profiles/71836b600dca819bddfa75726dc47442.jpg.50x50_q85.jpg)
test
Dependencies: SimpleDMA mbed-rtos mbed
Fork of spiDMAtest by
Revision 1:3cceef118195, committed 2015-07-16
- Comitter:
- shreeshas95
- Date:
- Thu Jul 16 05:19:02 2015 +0000
- Parent:
- 0:f0f5102ed9ca
- Child:
- 2:16545dbc88ae
- Commit message:
- working with tiva checked
Changed in this revision
dmaSPIslave.h | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/dmaSPIslave.h Wed Jul 15 11:16:13 2015 +0000 +++ b/dmaSPIslave.h Thu Jul 16 05:19:02 2015 +0000 @@ -14,21 +14,29 @@ read_dma.source(&_spi.spi->DL, false); } - void bulkRead(uint8_t *read_data, int length){ + 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); - - while(read_dma.isBusy()); + } - _spi.spi->C2 &= ~(SPI_C2_RXDMAE_MASK); - } private: + int length; SimpleDMA read_dma; }; #endif \ No newline at end of file
--- a/main.cpp Wed Jul 15 11:16:13 2015 +0000 +++ b/main.cpp Thu Jul 16 05:19:02 2015 +0000 @@ -3,33 +3,55 @@ #include "SimpleDMA.h" #include "dmaSPIslave.h" +#define PAYLOAD_LENGTH 1024 + dmaSPISlave spi(PTA16, PTA17, PTA15, PTA14); RawSerial pc(USBTX, USBRX); DigitalOut ledg(LED_GREEN); +bool flag = false; + +void do_this(void){ + flag = true; +} + int main(){ pc.baud(9600); pc.printf("inside main\r\n"); - spi.format(8,3); - spi.frequency(1000000); + spi.format(8,0); +// spi.frequency(16000000); - uint8_t buffer[100] = {0}; + uint8_t buffer[PAYLOAD_LENGTH] = {0}; pc.printf("welcome to dma test, start sending data now\r\n"); -// int i = 0; -// while(i < 100){ -// if(spi.receive()){ -// buffer[i] = spi.read(); -// ++i; -// ledg = !ledg; +// while(true){ +// int i = 0; +// while(i < PAYLOAD_LENGTH){ +// if(spi.receive()){ +// buffer[i] = spi.read(); +// ++i; +// ledg = !ledg; +// } // } +// for(int i = 0 ; i < PAYLOAD_LENGTH ; ++i){ +// pc.printf("%02x ", buffer[i]); +// } +// pc.printf("\r\n"); +// // } - spi.bulkRead(buffer, 100); - - for(int i = 0 ; i < 100 ; ++i){ - pc.printf("%02x ", buffer[i]); + + spi.bulkRead_init(buffer, PAYLOAD_LENGTH, &do_this); + spi.bulkRead_start(); + while(true){ + if(flag){ + flag = false; + ledg = !ledg; + for(int i = 0 ; i < PAYLOAD_LENGTH ; ++i){ + pc.printf("%02x ", buffer[i]); + } + pc.printf("\r\n"); + spi.bulkRead_start(); + } } - pc.printf("\r\n"); - return 0; } \ No newline at end of file