![](/media/cache/profiles/cff02a74da64d145a4aed3a577a106ab.jpg.50x50_q85.jpg)
test
main.cpp@6:fa9df9f03bfa, 2014-06-13 (annotated)
- Committer:
- fblanc
- Date:
- Fri Jun 13 13:55:50 2014 +0000
- Revision:
- 6:fa9df9f03bfa
- Parent:
- 5:832b59a73dec
- Child:
- 7:de5b1bc07eb5
USB 64b
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
fblanc | 0:92dd9611bf80 | 1 | #include "mbed.h" |
fblanc | 4:75077e05de3e | 2 | #include "USBSerial.h" |
fblanc | 6:fa9df9f03bfa | 3 | #define VERSION "13_06_2014" |
fblanc | 6:fa9df9f03bfa | 4 | #define SPEED 1000 //µs |
fblanc | 6:fa9df9f03bfa | 5 | #define BLOCUSB 64 //64 |
fblanc | 6:fa9df9f03bfa | 6 | #define NBCHAN 2 |
fblanc | 6:fa9df9f03bfa | 7 | #define NBSAMPLE BLOCUSB/NBCHAN // 2 samples 16bit |
fblanc | 6:fa9df9f03bfa | 8 | #define __KL25 |
fblanc | 4:75077e05de3e | 9 | #if defined( __LPC1768) |
fblanc | 5:832b59a73dec | 10 | Serial debug(USBTX, USBRX); |
fblanc | 4:75077e05de3e | 11 | USBSerial pc; |
fblanc | 0:92dd9611bf80 | 12 | DigitalOut led2(LED2); |
fblanc | 0:92dd9611bf80 | 13 | DigitalOut led3(LED3); |
fblanc | 0:92dd9611bf80 | 14 | DigitalOut led4(LED4); |
fblanc | 3:7acf6d1a6b1e | 15 | AnalogIn adc_1(p16); |
fblanc | 3:7acf6d1a6b1e | 16 | AnalogIn adc_2(p17); |
fblanc | 4:75077e05de3e | 17 | #endif |
fblanc | 4:75077e05de3e | 18 | #if defined( __KL25) |
fblanc | 4:75077e05de3e | 19 | USBSerial pc; |
fblanc | 4:75077e05de3e | 20 | DigitalOut led2(LED_GREEN); |
fblanc | 4:75077e05de3e | 21 | DigitalOut led3(LED_RED); |
fblanc | 4:75077e05de3e | 22 | DigitalOut led4(LED_BLUE); |
fblanc | 6:fa9df9f03bfa | 23 | AnalogIn adc_1(PTB0); |
fblanc | 6:fa9df9f03bfa | 24 | AnalogIn adc_2(PTB1); |
fblanc | 4:75077e05de3e | 25 | #endif |
fblanc | 4:75077e05de3e | 26 | |
fblanc | 6:fa9df9f03bfa | 27 | uint16_t T_hma_u16[2][BLOCUSB]; |
fblanc | 0:92dd9611bf80 | 28 | uint16_t index_hma_write=0; |
fblanc | 0:92dd9611bf80 | 29 | |
fblanc | 0:92dd9611bf80 | 30 | uint16_t index_hma_read=0; |
fblanc | 0:92dd9611bf80 | 31 | bool t_write=0; |
fblanc | 5:832b59a73dec | 32 | |
fblanc | 5:832b59a73dec | 33 | |
fblanc | 0:92dd9611bf80 | 34 | bool flag_write_USB=0; |
fblanc | 0:92dd9611bf80 | 35 | Ticker flipperADC; |
fblanc | 0:92dd9611bf80 | 36 | |
fblanc | 0:92dd9611bf80 | 37 | void flipADC() |
fblanc | 0:92dd9611bf80 | 38 | { |
fblanc | 4:75077e05de3e | 39 | |
fblanc | 3:7acf6d1a6b1e | 40 | T_hma_u16[t_write][index_hma_write++]=adc_1.read_u16(); //read ADC |
fblanc | 3:7acf6d1a6b1e | 41 | T_hma_u16[t_write][index_hma_write++]=adc_2.read_u16(); //read ADC |
fblanc | 5:832b59a73dec | 42 | |
fblanc | 5:832b59a73dec | 43 | |
fblanc | 6:fa9df9f03bfa | 44 | if(index_hma_write>NBSAMPLE) { |
fblanc | 0:92dd9611bf80 | 45 | flag_write_USB=1; |
fblanc | 0:92dd9611bf80 | 46 | t_write=!t_write; //toggel buffer |
fblanc | 6:fa9df9f03bfa | 47 | index_hma_read=index_hma_write-NBCHAN; |
fblanc | 0:92dd9611bf80 | 48 | index_hma_write=0; |
fblanc | 0:92dd9611bf80 | 49 | } |
fblanc | 4:75077e05de3e | 50 | |
fblanc | 0:92dd9611bf80 | 51 | } |
fblanc | 0:92dd9611bf80 | 52 | |
fblanc | 0:92dd9611bf80 | 53 | Ticker flipperUSB; |
fblanc | 0:92dd9611bf80 | 54 | void flipUSB() |
fblanc | 0:92dd9611bf80 | 55 | { |
fblanc | 0:92dd9611bf80 | 56 | |
fblanc | 0:92dd9611bf80 | 57 | flag_write_USB=1; |
fblanc | 0:92dd9611bf80 | 58 | |
fblanc | 0:92dd9611bf80 | 59 | } |
fblanc | 0:92dd9611bf80 | 60 | |
fblanc | 0:92dd9611bf80 | 61 | void pc_rx(void) |
fblanc | 0:92dd9611bf80 | 62 | { |
fblanc | 5:832b59a73dec | 63 | char str[32]; |
fblanc | 0:92dd9611bf80 | 64 | |
fblanc | 5:832b59a73dec | 65 | |
fblanc | 5:832b59a73dec | 66 | for(int start_str=0; pc.readable()!=0; ++start_str) { |
fblanc | 0:92dd9611bf80 | 67 | str[start_str]=pc.getc(); |
fblanc | 0:92dd9611bf80 | 68 | } |
fblanc | 5:832b59a73dec | 69 | if( strncmp(str,"ABORt",strlen("ABORt"))==0 ) { |
fblanc | 0:92dd9611bf80 | 70 | flipperADC.detach(); |
fblanc | 0:92dd9611bf80 | 71 | t_write=0; |
fblanc | 0:92dd9611bf80 | 72 | index_hma_read=0; |
fblanc | 0:92dd9611bf80 | 73 | index_hma_write=0; |
fblanc | 4:75077e05de3e | 74 | |
fblanc | 5:832b59a73dec | 75 | } else if( strncmp(str,"*IDN?",strlen("*IDN?"))==0 ) { |
fblanc | 5:832b59a73dec | 76 | pc.printf("LAAS-CNRS ,HMA serial, %s\r",VERSION); |
fblanc | 5:832b59a73dec | 77 | |
fblanc | 0:92dd9611bf80 | 78 | |
fblanc | 5:832b59a73dec | 79 | } else if( strncmp(str,"MEASure",strlen("MEASure"))==0 ) { |
fblanc | 5:832b59a73dec | 80 | flipperADC.attach_us(&flipADC, SPEED); |
fblanc | 5:832b59a73dec | 81 | } else if( strncmp(str,"TIME",strlen("TIME"))==0 ) { |
fblanc | 5:832b59a73dec | 82 | |
fblanc | 5:832b59a73dec | 83 | //... |
fblanc | 5:832b59a73dec | 84 | |
fblanc | 0:92dd9611bf80 | 85 | } |
fblanc | 0:92dd9611bf80 | 86 | } |
fblanc | 0:92dd9611bf80 | 87 | |
fblanc | 0:92dd9611bf80 | 88 | int main() |
fblanc | 0:92dd9611bf80 | 89 | { |
fblanc | 5:832b59a73dec | 90 | led2=0; |
fblanc | 5:832b59a73dec | 91 | led3=0; |
fblanc | 5:832b59a73dec | 92 | led4=0; |
fblanc | 5:832b59a73dec | 93 | while(1) { |
fblanc | 0:92dd9611bf80 | 94 | |
fblanc | 0:92dd9611bf80 | 95 | if (pc.readable()) { |
fblanc | 0:92dd9611bf80 | 96 | pc_rx(); |
fblanc | 0:92dd9611bf80 | 97 | } |
fblanc | 5:832b59a73dec | 98 | |
fblanc | 0:92dd9611bf80 | 99 | if(flag_write_USB==1) { |
fblanc | 0:92dd9611bf80 | 100 | flag_write_USB=0; |
fblanc | 5:832b59a73dec | 101 | led4=1; |
fblanc | 2:88f866289381 | 102 | pc.printf("%04d%c\r",index_hma_read,'\0'); //'\0'fin de chaine ASCII '\r' fin de transmission |
fblanc | 6:fa9df9f03bfa | 103 | for(unsigned int i=0; i<index_hma_read*NBCHAN; i+=BLOCUSB ) { // 2 cannaux de 16bits |
fblanc | 6:fa9df9f03bfa | 104 | pc.writeBlock((uint8_t*)&T_hma_u16[!t_write][i/NBCHAN],BLOCUSB );//For more efficiency, a block of size 64 (maximum size of a bulk endpoint) has to be written. |
fblanc | 0:92dd9611bf80 | 105 | } |
fblanc | 0:92dd9611bf80 | 106 | |
fblanc | 5:832b59a73dec | 107 | led4=0; |
fblanc | 0:92dd9611bf80 | 108 | } |
fblanc | 0:92dd9611bf80 | 109 | |
fblanc | 0:92dd9611bf80 | 110 | |
fblanc | 0:92dd9611bf80 | 111 | |
fblanc | 0:92dd9611bf80 | 112 | } |
fblanc | 0:92dd9611bf80 | 113 | } |