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