frederic blanc
/
HMA_HelloWord
test
Diff: main.cpp
- Revision:
- 5:832b59a73dec
- Parent:
- 4:75077e05de3e
- Child:
- 6:fa9df9f03bfa
--- a/main.cpp Fri Jun 06 13:10:57 2014 +0000 +++ b/main.cpp Tue Jun 10 14:44:07 2014 +0000 @@ -1,11 +1,11 @@ #include "mbed.h" #include "USBSerial.h" -//#define BAUD 460800 -//#define BAUD 9600 - +#define VERSION "10_06_2014" +#define SPEED 1000 +#define BLOCUSB 40 //64 #define __LPC1768 #if defined( __LPC1768) -//Serial pc(USBTX, USBRX); +Serial debug(USBTX, USBRX); USBSerial pc; DigitalOut led2(LED2); DigitalOut led3(LED3); @@ -27,8 +27,8 @@ uint16_t index_hma_read=0; bool t_write=0; -char str[256]; -uint8_t start_str=0; + + bool flag_write_USB=0; Ticker flipperADC; @@ -37,8 +37,8 @@ T_hma_u16[t_write][index_hma_write++]=adc_1.read_u16(); //read ADC T_hma_u16[t_write][index_hma_write++]=adc_2.read_u16(); //read ADC - //T_hma_u16[t_write][index_hma_write++]=0x00FF; - + + if(index_hma_write>2000) { flag_write_USB=1; t_write=!t_write; //toggel buffer @@ -58,87 +58,56 @@ void pc_rx(void) { + char str[32]; -led4=1; - for(; pc.readable()==true; ++start_str) { + + for(int start_str=0; pc.readable()!=0; ++start_str) { str[start_str]=pc.getc(); } -//pc.printf("recv:%s",str); - if( strncmp(str,"*IDN?",strlen("*IDN?"))==0 ) { - //pc.printf("HMA\r"); - led3=1; - pc.printf("HMA serial\r"); - start_str=0; - for(int i=0; i<256; ++i) { - str[i]='\0'; - - } - - } else if( strncmp(str,"MEASure",strlen("MEASure"))==0 ) { - for(int i=0; i<256; ++i) { - str[i]='\0'; - - } - flipperADC.attach_us(&flipADC, 1000); //500us - - - } else if( strncmp(str,"ABORt",strlen("ABORt"))==0 ) { - for(int i=0; i<256; ++i) { - str[i]='\0'; - - } + if( strncmp(str,"ABORt",strlen("ABORt"))==0 ) { flipperADC.detach(); t_write=0; index_hma_read=0; index_hma_write=0; - } - for(int i=0; i<start_str; ++i) { - if(str[i]=='\r') { - for(int j=0; j<256; ++j) { - str[j]='\0'; + } else if( strncmp(str,"*IDN?",strlen("*IDN?"))==0 ) { + pc.printf("LAAS-CNRS ,HMA serial, %s\r",VERSION); + - } - start_str=0; - - } - + } else if( strncmp(str,"MEASure",strlen("MEASure"))==0 ) { + flipperADC.attach_us(&flipADC, SPEED); + } else if( strncmp(str,"TIME",strlen("TIME"))==0 ) { + + //... + } + + + } int main() { -led2=0; -led3=0; -led4=0; -// pc.baud(BAUD); - pc.printf("HMA serial\r"); - for(int i=0; i<256; ++i) { - str[i]='\0'; + led2=0; + led3=0; + led4=0; + while(1) { - } - - - while(1) { - if (pc.readable()) { pc_rx(); } + if(flag_write_USB==1) { flag_write_USB=0; - - + led4=1; pc.printf("%04d%c\r",index_hma_read,'\0'); //'\0'fin de chaine ASCII '\r' fin de transmission - - char* ptr=(char*)&T_hma_u16[!t_write][0]; - - for(uint16_t i=0; i<index_hma_read; ++i) { - pc.putc(*ptr++); - pc.putc(*ptr++); + for(unsigned int i=0; i<index_hma_read*2; i+=BLOCUSB ) { // 2 cannaux de 16bits + 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. } + led4=0; }