test
Dependencies: SimpleDMA mbed-rtos mbed
Fork of spiDMAtest by
main.cpp@1:3cceef118195, 2015-07-16 (annotated)
- Committer:
- shreeshas95
- Date:
- Thu Jul 16 05:19:02 2015 +0000
- Revision:
- 1:3cceef118195
- Parent:
- 0:f0f5102ed9ca
- Child:
- 2:16545dbc88ae
working with tiva checked
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 "rtos.h" |
shreeshas95 | 0:f0f5102ed9ca | 3 | #include "SimpleDMA.h" |
shreeshas95 | 0:f0f5102ed9ca | 4 | #include "dmaSPIslave.h" |
shreeshas95 | 0:f0f5102ed9ca | 5 | |
shreeshas95 | 1:3cceef118195 | 6 | #define PAYLOAD_LENGTH 1024 |
shreeshas95 | 1:3cceef118195 | 7 | |
shreeshas95 | 0:f0f5102ed9ca | 8 | dmaSPISlave spi(PTA16, PTA17, PTA15, PTA14); |
shreeshas95 | 0:f0f5102ed9ca | 9 | RawSerial pc(USBTX, USBRX); |
shreeshas95 | 0:f0f5102ed9ca | 10 | DigitalOut ledg(LED_GREEN); |
shreeshas95 | 0:f0f5102ed9ca | 11 | |
shreeshas95 | 1:3cceef118195 | 12 | bool flag = false; |
shreeshas95 | 1:3cceef118195 | 13 | |
shreeshas95 | 1:3cceef118195 | 14 | void do_this(void){ |
shreeshas95 | 1:3cceef118195 | 15 | flag = true; |
shreeshas95 | 1:3cceef118195 | 16 | } |
shreeshas95 | 1:3cceef118195 | 17 | |
shreeshas95 | 0:f0f5102ed9ca | 18 | int main(){ |
shreeshas95 | 0:f0f5102ed9ca | 19 | pc.baud(9600); |
shreeshas95 | 0:f0f5102ed9ca | 20 | pc.printf("inside main\r\n"); |
shreeshas95 | 1:3cceef118195 | 21 | spi.format(8,0); |
shreeshas95 | 1:3cceef118195 | 22 | // spi.frequency(16000000); |
shreeshas95 | 0:f0f5102ed9ca | 23 | |
shreeshas95 | 1:3cceef118195 | 24 | uint8_t buffer[PAYLOAD_LENGTH] = {0}; |
shreeshas95 | 0:f0f5102ed9ca | 25 | pc.printf("welcome to dma test, start sending data now\r\n"); |
shreeshas95 | 0:f0f5102ed9ca | 26 | |
shreeshas95 | 1:3cceef118195 | 27 | // while(true){ |
shreeshas95 | 1:3cceef118195 | 28 | // int i = 0; |
shreeshas95 | 1:3cceef118195 | 29 | // while(i < PAYLOAD_LENGTH){ |
shreeshas95 | 1:3cceef118195 | 30 | // if(spi.receive()){ |
shreeshas95 | 1:3cceef118195 | 31 | // buffer[i] = spi.read(); |
shreeshas95 | 1:3cceef118195 | 32 | // ++i; |
shreeshas95 | 1:3cceef118195 | 33 | // ledg = !ledg; |
shreeshas95 | 1:3cceef118195 | 34 | // } |
shreeshas95 | 0:f0f5102ed9ca | 35 | // } |
shreeshas95 | 1:3cceef118195 | 36 | // for(int i = 0 ; i < PAYLOAD_LENGTH ; ++i){ |
shreeshas95 | 1:3cceef118195 | 37 | // pc.printf("%02x ", buffer[i]); |
shreeshas95 | 1:3cceef118195 | 38 | // } |
shreeshas95 | 1:3cceef118195 | 39 | // pc.printf("\r\n"); |
shreeshas95 | 1:3cceef118195 | 40 | // |
shreeshas95 | 0:f0f5102ed9ca | 41 | // } |
shreeshas95 | 1:3cceef118195 | 42 | |
shreeshas95 | 1:3cceef118195 | 43 | spi.bulkRead_init(buffer, PAYLOAD_LENGTH, &do_this); |
shreeshas95 | 1:3cceef118195 | 44 | spi.bulkRead_start(); |
shreeshas95 | 1:3cceef118195 | 45 | while(true){ |
shreeshas95 | 1:3cceef118195 | 46 | if(flag){ |
shreeshas95 | 1:3cceef118195 | 47 | flag = false; |
shreeshas95 | 1:3cceef118195 | 48 | ledg = !ledg; |
shreeshas95 | 1:3cceef118195 | 49 | for(int i = 0 ; i < PAYLOAD_LENGTH ; ++i){ |
shreeshas95 | 1:3cceef118195 | 50 | pc.printf("%02x ", buffer[i]); |
shreeshas95 | 1:3cceef118195 | 51 | } |
shreeshas95 | 1:3cceef118195 | 52 | pc.printf("\r\n"); |
shreeshas95 | 1:3cceef118195 | 53 | spi.bulkRead_start(); |
shreeshas95 | 1:3cceef118195 | 54 | } |
shreeshas95 | 0:f0f5102ed9ca | 55 | } |
shreeshas95 | 0:f0f5102ed9ca | 56 | |
shreeshas95 | 0:f0f5102ed9ca | 57 | } |