LPC11U35 ADC Tick & USBSerial
Dependents: SmallDoseMeter_SingleCH_AE_lpc11u35_V1_00
main.cpp@0:871ab6846b18, 2018-02-19 (annotated)
- Committer:
- H_Tsunemoto
- Date:
- Mon Feb 19 08:51:33 2018 +0000
- Revision:
- 0:871ab6846b18
- Child:
- 1:b1a3be5f48ab
test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
H_Tsunemoto | 0:871ab6846b18 | 1 | ////////////////////////////////////////////////////////////////////////// |
H_Tsunemoto | 0:871ab6846b18 | 2 | // MBED AE-LPC11U35 Small Dose Measure Program 1CH入力 / Range固定 // |
H_Tsunemoto | 0:871ab6846b18 | 3 | // SingleCH Dose CH0:AD7 P14=P0_23 , RNG P19=P0_1 // |
H_Tsunemoto | 0:871ab6846b18 | 4 | // // CH1:AD6 P07=P0_22 , RNG P23=P0_2 (Dummy) // |
H_Tsunemoto | 0:871ab6846b18 | 5 | // Since 2018.02.14 H.Tsunemoto // |
H_Tsunemoto | 0:871ab6846b18 | 6 | // for ADC Measurement Timer(0.1mSec)Interrupt // |
H_Tsunemoto | 0:871ab6846b18 | 7 | // Sample Time 1.0msec - 1000msec // |
H_Tsunemoto | 0:871ab6846b18 | 8 | // Since 2016.05.18 H.Tsunemoto // |
H_Tsunemoto | 0:871ab6846b18 | 9 | // Sample Program Import (1) Serial_interrupt: LPC11U68_USBserial // |
H_Tsunemoto | 0:871ab6846b18 | 10 | // (2) Timer_Interrupt: LPC1114_ticker // |
H_Tsunemoto | 0:871ab6846b18 | 11 | // (3) Internal_ADC_with_interrupt // |
H_Tsunemoto | 0:871ab6846b18 | 12 | ///////////////////////////////////////////////////////////////////// |
H_Tsunemoto | 0:871ab6846b18 | 13 | #include "mbed.h" |
H_Tsunemoto | 0:871ab6846b18 | 14 | #include "LPC11Uxx.h" |
H_Tsunemoto | 0:871ab6846b18 | 15 | #include "USBSerial.h" |
H_Tsunemoto | 0:871ab6846b18 | 16 | #include "stdio.h" |
H_Tsunemoto | 0:871ab6846b18 | 17 | #include "math.h" |
H_Tsunemoto | 0:871ab6846b18 | 18 | |
H_Tsunemoto | 0:871ab6846b18 | 19 | //-------------------------------------// |
H_Tsunemoto | 0:871ab6846b18 | 20 | // --- MBED I/O Asign declaration --- // |
H_Tsunemoto | 0:871ab6846b18 | 21 | //-------------------------------------// |
H_Tsunemoto | 0:871ab6846b18 | 22 | //Virtual serial port over USB |
H_Tsunemoto | 0:871ab6846b18 | 23 | USBSerial serial; |
H_Tsunemoto | 0:871ab6846b18 | 24 | //Serial pc(USBTX, USBRX); |
H_Tsunemoto | 0:871ab6846b18 | 25 | //Serial device(P0_3,P0_1); |
H_Tsunemoto | 0:871ab6846b18 | 26 | Serial device(P0_19,P0_18); |
H_Tsunemoto | 0:871ab6846b18 | 27 | |
H_Tsunemoto | 0:871ab6846b18 | 28 | // ADC Port Asign P14: ad_ch1(AD7) P7 = ad7 |
H_Tsunemoto | 0:871ab6846b18 | 29 | AnalogIn ad_ch1(P0_23); // AD CH1 P14 MBED ADC Input |
H_Tsunemoto | 0:871ab6846b18 | 30 | //AnalogIn ad_ch1(P0_22); // AD CH2 P7 MBED ADC Input Dummy |
H_Tsunemoto | 0:871ab6846b18 | 31 | |
H_Tsunemoto | 0:871ab6846b18 | 32 | DigitalOut led1(P0_7); //P3 = P0_7 LED1); Dummy |
H_Tsunemoto | 0:871ab6846b18 | 33 | DigitalOut led2(P0_8); //P4 = P0_8 LED2); |
H_Tsunemoto | 0:871ab6846b18 | 34 | DigitalOut led3(P0_9); //P5 = P0_9 LED3); |
H_Tsunemoto | 0:871ab6846b18 | 35 | DigitalOut led4(P0_10); //P6 = P0_10 // LED 4 Dummy |
H_Tsunemoto | 0:871ab6846b18 | 36 | |
H_Tsunemoto | 0:871ab6846b18 | 37 | |
H_Tsunemoto | 0:871ab6846b18 | 38 | //DigitalOut POut_CH1_Rng(P0_1); // Pout CH1 Range Select No Control |
H_Tsunemoto | 0:871ab6846b18 | 39 | //DigitalOut POut_CH2_Rng(P0_2); // Pout CH2 Range Select No Control |
H_Tsunemoto | 0:871ab6846b18 | 40 | // Debug Led ON/Off |
H_Tsunemoto | 0:871ab6846b18 | 41 | #define Debug_LED_Active 1 |
H_Tsunemoto | 0:871ab6846b18 | 42 | #define Debug_LED_Disable 0 |
H_Tsunemoto | 0:871ab6846b18 | 43 | int i_LED_Active = Debug_LED_Active; |
H_Tsunemoto | 0:871ab6846b18 | 44 | //---------------------------------------------------------// |
H_Tsunemoto | 0:871ab6846b18 | 45 | // <<< ADC Sample Parameter & Function declaration >>> // |
H_Tsunemoto | 0:871ab6846b18 | 46 | //---------------------------------------------------------// |
H_Tsunemoto | 0:871ab6846b18 | 47 | //---- ADC Interrupt Timer -----// |
H_Tsunemoto | 0:871ab6846b18 | 48 | int main_loop_count = 0; |
H_Tsunemoto | 0:871ab6846b18 | 49 | Ticker ADC_Timer; |
H_Tsunemoto | 0:871ab6846b18 | 50 | Timer t; |
H_Tsunemoto | 0:871ab6846b18 | 51 | int ADC_Count1=0; |
H_Tsunemoto | 0:871ab6846b18 | 52 | int ADC_Count1Block=0; |
H_Tsunemoto | 0:871ab6846b18 | 53 | #define ADC_CH1 0 |
H_Tsunemoto | 0:871ab6846b18 | 54 | //#define ADC_CH2 1 |
H_Tsunemoto | 0:871ab6846b18 | 55 | volatile unsigned short Adc_inp_temp[2]; |
H_Tsunemoto | 0:871ab6846b18 | 56 | volatile unsigned long adc_CH1_Inp; |
H_Tsunemoto | 0:871ab6846b18 | 57 | //volatile unsigned long adc_CH2_Inp; |
H_Tsunemoto | 0:871ab6846b18 | 58 | // Ative Mode Status Controll |
H_Tsunemoto | 0:871ab6846b18 | 59 | #define ActiveMode_ADC_Sample_Stop 0 |
H_Tsunemoto | 0:871ab6846b18 | 60 | #define ActiveMode_ADC_Sample_Busy 1 // |
H_Tsunemoto | 0:871ab6846b18 | 61 | int i_adc_ActiveMode_status = ActiveMode_ADC_Sample_Stop; |
H_Tsunemoto | 0:871ab6846b18 | 62 | volatile int i_adc_Sample_Total_Count = 0; |
H_Tsunemoto | 0:871ab6846b18 | 63 | volatile int i_adc_Sample_Total_Time = 0; |
H_Tsunemoto | 0:871ab6846b18 | 64 | #define ADC_SAMPLE_AVE_MAX 4 |
H_Tsunemoto | 0:871ab6846b18 | 65 | volatile int adc_Sample_Ave_Count = 4; |
H_Tsunemoto | 0:871ab6846b18 | 66 | #define ADC_SAMPLE_Empty 0 |
H_Tsunemoto | 0:871ab6846b18 | 67 | #define ADC_SAMPLE_Conplete 1 |
H_Tsunemoto | 0:871ab6846b18 | 68 | volatile int i_adc_Sample_Status = ADC_SAMPLE_Empty; |
H_Tsunemoto | 0:871ab6846b18 | 69 | typedef struct st_adc_ave{ |
H_Tsunemoto | 0:871ab6846b18 | 70 | |
H_Tsunemoto | 0:871ab6846b18 | 71 | volatile unsigned long sample_Add; |
H_Tsunemoto | 0:871ab6846b18 | 72 | volatile unsigned long sample_Ave; |
H_Tsunemoto | 0:871ab6846b18 | 73 | }ST_ADC_AVE; |
H_Tsunemoto | 0:871ab6846b18 | 74 | volatile ST_ADC_AVE st_adc_sample_ave[2]; |
H_Tsunemoto | 0:871ab6846b18 | 75 | const ST_ADC_AVE const_ADC_AVE_Default= |
H_Tsunemoto | 0:871ab6846b18 | 76 | { |
H_Tsunemoto | 0:871ab6846b18 | 77 | 0 //unsigned short sample_Add; |
H_Tsunemoto | 0:871ab6846b18 | 78 | }; |
H_Tsunemoto | 0:871ab6846b18 | 79 | #define ADC_SAMPLE_RATE_MIN 1 |
H_Tsunemoto | 0:871ab6846b18 | 80 | #define ADC_SAMPLE_RATE_MAX 1000 |
H_Tsunemoto | 0:871ab6846b18 | 81 | |
H_Tsunemoto | 0:871ab6846b18 | 82 | //-------- ADC Measure Mode Parameter declaration --------// |
H_Tsunemoto | 0:871ab6846b18 | 83 | typedef struct st_adc_param{ |
H_Tsunemoto | 0:871ab6846b18 | 84 | int i_sample_interval; // DAC Output Pattern |
H_Tsunemoto | 0:871ab6846b18 | 85 | int i_CH1_Range; |
H_Tsunemoto | 0:871ab6846b18 | 86 | int i_CH2_Range; |
H_Tsunemoto | 0:871ab6846b18 | 87 | }ST_ADC_PARAM; |
H_Tsunemoto | 0:871ab6846b18 | 88 | |
H_Tsunemoto | 0:871ab6846b18 | 89 | ST_ADC_PARAM st_adc_mode_param; |
H_Tsunemoto | 0:871ab6846b18 | 90 | |
H_Tsunemoto | 0:871ab6846b18 | 91 | //-------- ADC Measure Mode Parameter Default Set --------// |
H_Tsunemoto | 0:871ab6846b18 | 92 | const ST_ADC_PARAM const_ADC_Param_Default= |
H_Tsunemoto | 0:871ab6846b18 | 93 | { |
H_Tsunemoto | 0:871ab6846b18 | 94 | 1000 //i_sample_int=1000 microS |
H_Tsunemoto | 0:871ab6846b18 | 95 | ,0 |
H_Tsunemoto | 0:871ab6846b18 | 96 | ,0 |
H_Tsunemoto | 0:871ab6846b18 | 97 | }; |
H_Tsunemoto | 0:871ab6846b18 | 98 | //int adc_sample_interval = 1000; // ADC Sample Rate 5 - 20000(20.0mSec) |
H_Tsunemoto | 0:871ab6846b18 | 99 | void ADC_ave_Init(); |
H_Tsunemoto | 0:871ab6846b18 | 100 | void Start_ADC(); |
H_Tsunemoto | 0:871ab6846b18 | 101 | int ADC_Inp2CH(); |
H_Tsunemoto | 0:871ab6846b18 | 102 | void Tick_100usec_ADC_Interrupt(); |
H_Tsunemoto | 0:871ab6846b18 | 103 | //void ADC_Stop(); // 2018.02.19 for 100μsec Timer 2=>1 共通化 |
H_Tsunemoto | 0:871ab6846b18 | 104 | // STOP時は ADC入力のみ停止 |
H_Tsunemoto | 0:871ab6846b18 | 105 | void ad_sample_send(); |
H_Tsunemoto | 0:871ab6846b18 | 106 | void adc_param_init(); |
H_Tsunemoto | 0:871ab6846b18 | 107 | |
H_Tsunemoto | 0:871ab6846b18 | 108 | |
H_Tsunemoto | 0:871ab6846b18 | 109 | |
H_Tsunemoto | 0:871ab6846b18 | 110 | |
H_Tsunemoto | 0:871ab6846b18 | 111 | |
H_Tsunemoto | 0:871ab6846b18 | 112 | //--------------------------------// |
H_Tsunemoto | 0:871ab6846b18 | 113 | // --- Serial Communication --- // |
H_Tsunemoto | 0:871ab6846b18 | 114 | //--------------------------------// |
H_Tsunemoto | 0:871ab6846b18 | 115 | //void Tx_interrupt(); |
H_Tsunemoto | 0:871ab6846b18 | 116 | //void Rx_interrupt(); |
H_Tsunemoto | 0:871ab6846b18 | 117 | //void send_line(); |
H_Tsunemoto | 0:871ab6846b18 | 118 | int read_line(); // Return Rec CHAR Count 2013.08.08 Tsunemoto Append |
H_Tsunemoto | 0:871ab6846b18 | 119 | void Rx_1char(); |
H_Tsunemoto | 0:871ab6846b18 | 120 | |
H_Tsunemoto | 0:871ab6846b18 | 121 | |
H_Tsunemoto | 0:871ab6846b18 | 122 | |
H_Tsunemoto | 0:871ab6846b18 | 123 | //---------- H.Tsunemoto Scince 2013.08.08 ---------// |
H_Tsunemoto | 0:871ab6846b18 | 124 | //-----------------------------------------------------------// |
H_Tsunemoto | 0:871ab6846b18 | 125 | //--------- Timer Innterrupt For DAC Control ---------------// |
H_Tsunemoto | 0:871ab6846b18 | 126 | //-----------------------------------------------------------// |
H_Tsunemoto | 0:871ab6846b18 | 127 | int timer_count=0; |
H_Tsunemoto | 0:871ab6846b18 | 128 | int timer_1Sec=0; |
H_Tsunemoto | 0:871ab6846b18 | 129 | |
H_Tsunemoto | 0:871ab6846b18 | 130 | //void TIMER0_IRQHandler(void); |
H_Tsunemoto | 0:871ab6846b18 | 131 | //void timer0_init(void); |
H_Tsunemoto | 0:871ab6846b18 | 132 | //--------- New Append Function ---------// |
H_Tsunemoto | 0:871ab6846b18 | 133 | |
H_Tsunemoto | 0:871ab6846b18 | 134 | void Ser_Command_Input(); |
H_Tsunemoto | 0:871ab6846b18 | 135 | ////////////////////////////////////////////////////////////////////////////////// |
H_Tsunemoto | 0:871ab6846b18 | 136 | //------------ Command Check & Set Function ---------------------------------// |
H_Tsunemoto | 0:871ab6846b18 | 137 | // ADC No.1 "SMP 1000" ADC Sample Rate 2 - 1000 msec |
H_Tsunemoto | 0:871ab6846b18 | 138 | bool com_Check_SMP(int i_RecCharCount); |
H_Tsunemoto | 0:871ab6846b18 | 139 | // ADC No.2 "RNA 0" ADC CH1 Range 0 / 1 |
H_Tsunemoto | 0:871ab6846b18 | 140 | bool com_Check_RNA(int i_RecCharCount); |
H_Tsunemoto | 0:871ab6846b18 | 141 | // ADC No.3 "RNB 1" ADC CH2 Range 0 / 1 |
H_Tsunemoto | 0:871ab6846b18 | 142 | bool com_Check_RNB(int i_RecCharCount); |
H_Tsunemoto | 0:871ab6846b18 | 143 | // ADC No.4 "START" ADC Sample Start |
H_Tsunemoto | 0:871ab6846b18 | 144 | bool com_Check_START(int i_RecCharCount); |
H_Tsunemoto | 0:871ab6846b18 | 145 | // ADC No.5 "STOP" ADC Sample Stop |
H_Tsunemoto | 0:871ab6846b18 | 146 | bool com_Check_STOP(int i_RecCharCount); |
H_Tsunemoto | 0:871ab6846b18 | 147 | // ADC No.6 // "STAT?" |
H_Tsunemoto | 0:871ab6846b18 | 148 | void com_ADC_Table_Param_Send(); |
H_Tsunemoto | 0:871ab6846b18 | 149 | // ADC No.7 // "LED0" LED Ena |
H_Tsunemoto | 0:871ab6846b18 | 150 | bool com_Check_LED(int i_RecCharCount); |
H_Tsunemoto | 0:871ab6846b18 | 151 | //----------------------------------------------------------------// |
H_Tsunemoto | 0:871ab6846b18 | 152 | |
H_Tsunemoto | 0:871ab6846b18 | 153 | // Circular buffers for serial TX and RX data - used by interrupt routines |
H_Tsunemoto | 0:871ab6846b18 | 154 | const int ser_buffer_size = 255; |
H_Tsunemoto | 0:871ab6846b18 | 155 | // might need to increase buffer size for high baud rates |
H_Tsunemoto | 0:871ab6846b18 | 156 | char tx_buffer[ser_buffer_size]; |
H_Tsunemoto | 0:871ab6846b18 | 157 | char rx_buffer[ser_buffer_size]; |
H_Tsunemoto | 0:871ab6846b18 | 158 | // Circular buffer pointers |
H_Tsunemoto | 0:871ab6846b18 | 159 | // volatile makes read-modify-write atomic |
H_Tsunemoto | 0:871ab6846b18 | 160 | volatile int tx_in=0; |
H_Tsunemoto | 0:871ab6846b18 | 161 | volatile int tx_out=0; |
H_Tsunemoto | 0:871ab6846b18 | 162 | volatile int rx_in=0; |
H_Tsunemoto | 0:871ab6846b18 | 163 | volatile int rx_out=0; |
H_Tsunemoto | 0:871ab6846b18 | 164 | // Line buffers for sprintf and sscanf |
H_Tsunemoto | 0:871ab6846b18 | 165 | char tx_line[80]; |
H_Tsunemoto | 0:871ab6846b18 | 166 | char rx_line[80]; |
H_Tsunemoto | 0:871ab6846b18 | 167 | //--- 2013.08.08 Tsunemoto ------// |
H_Tsunemoto | 0:871ab6846b18 | 168 | //-- rx Data Cr Rec Counter |
H_Tsunemoto | 0:871ab6846b18 | 169 | volatile int rx_cr_Rec = 0; |
H_Tsunemoto | 0:871ab6846b18 | 170 | //--------------------------------// |
H_Tsunemoto | 0:871ab6846b18 | 171 | |
H_Tsunemoto | 0:871ab6846b18 | 172 | // 2016.06.21 Test Thresh Up |
H_Tsunemoto | 0:871ab6846b18 | 173 | //volatile int debug_Count_Over = 0; |
H_Tsunemoto | 0:871ab6846b18 | 174 | // ---------------------------------------------------------------// |
H_Tsunemoto | 0:871ab6846b18 | 175 | // |
H_Tsunemoto | 0:871ab6846b18 | 176 | |
H_Tsunemoto | 0:871ab6846b18 | 177 | |
H_Tsunemoto | 0:871ab6846b18 | 178 | ///////////////////////////////////////////////////////////////// |
H_Tsunemoto | 0:871ab6846b18 | 179 | // <<<< Main Function >>>> // |
H_Tsunemoto | 0:871ab6846b18 | 180 | ///////////////////////////////////////////////////////////////// |
H_Tsunemoto | 0:871ab6846b18 | 181 | // ---------------------------------------------------------------// |
H_Tsunemoto | 0:871ab6846b18 | 182 | // main test program |
H_Tsunemoto | 0:871ab6846b18 | 183 | int main() { |
H_Tsunemoto | 0:871ab6846b18 | 184 | // Serial Speed Set |
H_Tsunemoto | 0:871ab6846b18 | 185 | device.baud(115200); |
H_Tsunemoto | 0:871ab6846b18 | 186 | // serial.serial_baud(device,115200); |
H_Tsunemoto | 0:871ab6846b18 | 187 | //serial.serial_baud(115200); |
H_Tsunemoto | 0:871ab6846b18 | 188 | |
H_Tsunemoto | 0:871ab6846b18 | 189 | timer_count = 0; |
H_Tsunemoto | 0:871ab6846b18 | 190 | ADC_Timer.attach_us(&Tick_100usec_ADC_Interrupt, (100)); |
H_Tsunemoto | 0:871ab6846b18 | 191 | |
H_Tsunemoto | 0:871ab6846b18 | 192 | //--- ADC Measurement Control Parameter Initial Set ---// |
H_Tsunemoto | 0:871ab6846b18 | 193 | adc_param_init(); |
H_Tsunemoto | 0:871ab6846b18 | 194 | // -- Main Loop -- // |
H_Tsunemoto | 0:871ab6846b18 | 195 | |
H_Tsunemoto | 0:871ab6846b18 | 196 | while (1) { |
H_Tsunemoto | 0:871ab6846b18 | 197 | if(i_LED_Active == Debug_LED_Active){ |
H_Tsunemoto | 0:871ab6846b18 | 198 | led3 = (led3+1) & 1; |
H_Tsunemoto | 0:871ab6846b18 | 199 | } |
H_Tsunemoto | 0:871ab6846b18 | 200 | if (i_adc_ActiveMode_status != ActiveMode_ADC_Sample_Stop){ |
H_Tsunemoto | 0:871ab6846b18 | 201 | |
H_Tsunemoto | 0:871ab6846b18 | 202 | ad_sample_send();// --- ADC Sample & Serial Data Out --- // |
H_Tsunemoto | 0:871ab6846b18 | 203 | } |
H_Tsunemoto | 0:871ab6846b18 | 204 | if(rx_cr_Rec != 0){ |
H_Tsunemoto | 0:871ab6846b18 | 205 | Ser_Command_Input(); |
H_Tsunemoto | 0:871ab6846b18 | 206 | } |
H_Tsunemoto | 0:871ab6846b18 | 207 | ///////////////////////////////// |
H_Tsunemoto | 0:871ab6846b18 | 208 | } |
H_Tsunemoto | 0:871ab6846b18 | 209 | } |
H_Tsunemoto | 0:871ab6846b18 | 210 | |
H_Tsunemoto | 0:871ab6846b18 | 211 | ////////////////////////////////////////////////////////////////////////////////// |
H_Tsunemoto | 0:871ab6846b18 | 212 | //------------------------------------------------------------------------------// |
H_Tsunemoto | 0:871ab6846b18 | 213 | //------- A/D Input & Data Send(Serial) -------// |
H_Tsunemoto | 0:871ab6846b18 | 214 | //------------------------------------------------------------------------------// |
H_Tsunemoto | 0:871ab6846b18 | 215 | // int ADC_Count1=0; // |
H_Tsunemoto | 0:871ab6846b18 | 216 | // int ADC_Count1Block=0; // |
H_Tsunemoto | 0:871ab6846b18 | 217 | /// #define ADC_CH1 0 // |
H_Tsunemoto | 0:871ab6846b18 | 218 | // #define ADC_CH2 1 // |
H_Tsunemoto | 0:871ab6846b18 | 219 | // unsigned short Adc_buff[3][ADC_BUFF_SIZE] // |
H_Tsunemoto | 0:871ab6846b18 | 220 | // int adc_buff_inp = 0; // |
H_Tsunemoto | 0:871ab6846b18 | 221 | // int adc_buff_out = 0; // |
H_Tsunemoto | 0:871ab6846b18 | 222 | // |
H_Tsunemoto | 0:871ab6846b18 | 223 | //#define ActiveMode_ADC_Sample_Stop 0 |
H_Tsunemoto | 0:871ab6846b18 | 224 | //#define ActiveMode_ADC_Sample_Ready 1 // |
H_Tsunemoto | 0:871ab6846b18 | 225 | //#define ActiveMode_ADC_Sample_Busy 2 // |
H_Tsunemoto | 0:871ab6846b18 | 226 | //int i_adc_ActiveMode_status ; |
H_Tsunemoto | 0:871ab6846b18 | 227 | // // |
H_Tsunemoto | 0:871ab6846b18 | 228 | //#define ADC_TRIGGER_START_ENABLE |
H_Tsunemoto | 0:871ab6846b18 | 229 | //#define ADC_TRIGGER__START_READY |
H_Tsunemoto | 0:871ab6846b18 | 230 | //bool b_Trigger_Start_sendFlag = ADC_TRIGGER__START_READY; |
H_Tsunemoto | 0:871ab6846b18 | 231 | //#define ADC_PULSE_END_ENABLE |
H_Tsunemoto | 0:871ab6846b18 | 232 | //#define ADC_PULSE_END_READY |
H_Tsunemoto | 0:871ab6846b18 | 233 | //bool b_Trigger_EndFlag = ADC_PULSE_END_READY; |
H_Tsunemoto | 0:871ab6846b18 | 234 | //int i_adc_Waveform_count=0 |
H_Tsunemoto | 0:871ab6846b18 | 235 | //int i_adc_Sample_Total_Count = 0; |
H_Tsunemoto | 0:871ab6846b18 | 236 | //int i_adc_Sample_Total_Time = 0; |
H_Tsunemoto | 0:871ab6846b18 | 237 | // |
H_Tsunemoto | 0:871ab6846b18 | 238 | ////////////////////////////////////////////////////////////////////////////////// |
H_Tsunemoto | 0:871ab6846b18 | 239 | void ad_sample_send(){ |
H_Tsunemoto | 0:871ab6846b18 | 240 | //float f_num; |
H_Tsunemoto | 0:871ab6846b18 | 241 | // A/D CH1(P19) / CH2(P20) => HEX SHORT |
H_Tsunemoto | 0:871ab6846b18 | 242 | if(i_adc_ActiveMode_status == ActiveMode_ADC_Sample_Busy){ |
H_Tsunemoto | 0:871ab6846b18 | 243 | if(i_adc_Sample_Status != ADC_SAMPLE_Empty){ |
H_Tsunemoto | 0:871ab6846b18 | 244 | if(i_LED_Active == Debug_LED_Active){ |
H_Tsunemoto | 0:871ab6846b18 | 245 | led4 = (led4+1) & 1; |
H_Tsunemoto | 0:871ab6846b18 | 246 | } |
H_Tsunemoto | 0:871ab6846b18 | 247 | if(st_adc_mode_param.i_sample_interval ==0){ |
H_Tsunemoto | 0:871ab6846b18 | 248 | st_adc_mode_param.i_sample_interval =1; |
H_Tsunemoto | 0:871ab6846b18 | 249 | } |
H_Tsunemoto | 0:871ab6846b18 | 250 | // 2018.02.19 for Small Dose Special Range = 0 Dummy & Duplicate 0CH Data Send |
H_Tsunemoto | 0:871ab6846b18 | 251 | // sprintf(tx_line,"%1d,%03x,%1d,%03x\r\n" |
H_Tsunemoto | 0:871ab6846b18 | 252 | serial.printf("%1d,%03x,%1d,%03x\r\n" |
H_Tsunemoto | 0:871ab6846b18 | 253 | ,0 |
H_Tsunemoto | 0:871ab6846b18 | 254 | ,(st_adc_sample_ave[0].sample_Ave / st_adc_mode_param.i_sample_interval) |
H_Tsunemoto | 0:871ab6846b18 | 255 | ,0 |
H_Tsunemoto | 0:871ab6846b18 | 256 | ,(st_adc_sample_ave[0].sample_Ave / st_adc_mode_param.i_sample_interval) |
H_Tsunemoto | 0:871ab6846b18 | 257 | ); |
H_Tsunemoto | 0:871ab6846b18 | 258 | /* |
H_Tsunemoto | 0:871ab6846b18 | 259 | serial.printf("%1d,%03x,%1d,%03x\r\n" |
H_Tsunemoto | 0:871ab6846b18 | 260 | ,st_adc_mode_param.i_CH1_Range |
H_Tsunemoto | 0:871ab6846b18 | 261 | ,(st_adc_sample_ave[0].sample_Ave / st_adc_mode_param.i_sample_interval) |
H_Tsunemoto | 0:871ab6846b18 | 262 | ,st_adc_mode_param.i_CH2_Range |
H_Tsunemoto | 0:871ab6846b18 | 263 | ,(st_adc_sample_ave[1].sample_Ave / st_adc_mode_param.i_sample_interval) |
H_Tsunemoto | 0:871ab6846b18 | 264 | ); |
H_Tsunemoto | 0:871ab6846b18 | 265 | */ |
H_Tsunemoto | 0:871ab6846b18 | 266 | i_adc_Sample_Status = ADC_SAMPLE_Empty; |
H_Tsunemoto | 0:871ab6846b18 | 267 | // send_line(); |
H_Tsunemoto | 0:871ab6846b18 | 268 | serial.Write(tx_line); |
H_Tsunemoto | 0:871ab6846b18 | 269 | if(i_LED_Active == Debug_LED_Active){ |
H_Tsunemoto | 0:871ab6846b18 | 270 | led4 = (led4+1) & 1; |
H_Tsunemoto | 0:871ab6846b18 | 271 | led4 = (led4+1) & 1; |
H_Tsunemoto | 0:871ab6846b18 | 272 | } |
H_Tsunemoto | 0:871ab6846b18 | 273 | |
H_Tsunemoto | 0:871ab6846b18 | 274 | } |
H_Tsunemoto | 0:871ab6846b18 | 275 | // led4 = 0; |
H_Tsunemoto | 0:871ab6846b18 | 276 | } |
H_Tsunemoto | 0:871ab6846b18 | 277 | } |
H_Tsunemoto | 0:871ab6846b18 | 278 | |
H_Tsunemoto | 0:871ab6846b18 | 279 | void Start_ADC() { |
H_Tsunemoto | 0:871ab6846b18 | 280 | ADC_Count1Block=0; |
H_Tsunemoto | 0:871ab6846b18 | 281 | ADC_Count1=0; |
H_Tsunemoto | 0:871ab6846b18 | 282 | |
H_Tsunemoto | 0:871ab6846b18 | 283 | t.reset(); |
H_Tsunemoto | 0:871ab6846b18 | 284 | // t.start(); |
H_Tsunemoto | 0:871ab6846b18 | 285 | //memset(Samples, 0, AANTAL_SAMPLES); |
H_Tsunemoto | 0:871ab6846b18 | 286 | //ADC_Timer.attach_us(&ADC_Interrupt, 200); |
H_Tsunemoto | 0:871ab6846b18 | 287 | // 2013_0827 Tsunemoto for 1/4Sample Average |
H_Tsunemoto | 0:871ab6846b18 | 288 | // ADC_Timer.attach_us(&ADC_Interrupt, (st_adc_mode_param.i_sample_interval>>2)); |
H_Tsunemoto | 0:871ab6846b18 | 289 | // ADC_Timer.attach_us(&Tick_100usec_ADC_Interrupt, (100)); |
H_Tsunemoto | 0:871ab6846b18 | 290 | ADC_ave_Init(); |
H_Tsunemoto | 0:871ab6846b18 | 291 | //ADC_Timer.attach_us(&ADC_Interrupt, st_adc_mode_param.i_sample_interval); |
H_Tsunemoto | 0:871ab6846b18 | 292 | // i_adc_Waveform_count = 0; |
H_Tsunemoto | 0:871ab6846b18 | 293 | t.start(); |
H_Tsunemoto | 0:871ab6846b18 | 294 | // led1 = 1; |
H_Tsunemoto | 0:871ab6846b18 | 295 | |
H_Tsunemoto | 0:871ab6846b18 | 296 | // wait(0.0005); |
H_Tsunemoto | 0:871ab6846b18 | 297 | // 2016.06.21 Test Thresh Over Count |
H_Tsunemoto | 0:871ab6846b18 | 298 | // debug_Count_Over = 0; |
H_Tsunemoto | 0:871ab6846b18 | 299 | } |
H_Tsunemoto | 0:871ab6846b18 | 300 | //********************************************* |
H_Tsunemoto | 0:871ab6846b18 | 301 | //** ADC 1/4 Sample Parameter init ** |
H_Tsunemoto | 0:871ab6846b18 | 302 | //** 2013.08.27 Tsunemoto ** |
H_Tsunemoto | 0:871ab6846b18 | 303 | //typedef struct st_adc_ave{ |
H_Tsunemoto | 0:871ab6846b18 | 304 | // unsigned short sample_Add; |
H_Tsunemoto | 0:871ab6846b18 | 305 | // unsigned short sample_Max; |
H_Tsunemoto | 0:871ab6846b18 | 306 | // unsigned short sample_Min; |
H_Tsunemoto | 0:871ab6846b18 | 307 | //}ST_ADC_AVE; |
H_Tsunemoto | 0:871ab6846b18 | 308 | //ST_ADC_AVE st_adc_sample_ave[3]; |
H_Tsunemoto | 0:871ab6846b18 | 309 | //const ST_ADC_AVE const_ADC_AVE_Default= |
H_Tsunemoto | 0:871ab6846b18 | 310 | //#define ADC_SAMPLE_AVE_MAX 4 |
H_Tsunemoto | 0:871ab6846b18 | 311 | //int adc_Sample_Ave_Count = 4; |
H_Tsunemoto | 0:871ab6846b18 | 312 | //*************************************** |
H_Tsunemoto | 0:871ab6846b18 | 313 | void ADC_ave_Init() |
H_Tsunemoto | 0:871ab6846b18 | 314 | { |
H_Tsunemoto | 0:871ab6846b18 | 315 | // int i; |
H_Tsunemoto | 0:871ab6846b18 | 316 | // for (i=ADC_CH1;i<=ADC_CH2;i++){ |
H_Tsunemoto | 0:871ab6846b18 | 317 | st_adc_sample_ave[0].sample_Add = const_ADC_AVE_Default.sample_Add; |
H_Tsunemoto | 0:871ab6846b18 | 318 | // st_adc_sample_ave[i].sample_Max = const_ADC_AVE_Default.sample_Max; |
H_Tsunemoto | 0:871ab6846b18 | 319 | // st_adc_sample_ave[i].sample_Min = const_ADC_AVE_Default.sample_Min; |
H_Tsunemoto | 0:871ab6846b18 | 320 | // } |
H_Tsunemoto | 0:871ab6846b18 | 321 | adc_Sample_Ave_Count = 0; |
H_Tsunemoto | 0:871ab6846b18 | 322 | } |
H_Tsunemoto | 0:871ab6846b18 | 323 | //**************************************************** |
H_Tsunemoto | 0:871ab6846b18 | 324 | //** ADC Sample Input for 1/4 Ave & MAX/Min Cansel ** |
H_Tsunemoto | 0:871ab6846b18 | 325 | //Adc_inp_temp |
H_Tsunemoto | 0:871ab6846b18 | 326 | // return ;0= No Buffer inc |
H_Tsunemoto | 0:871ab6846b18 | 327 | // 1= Buffer Inp & Count INC |
H_Tsunemoto | 0:871ab6846b18 | 328 | //**************************************************** |
H_Tsunemoto | 0:871ab6846b18 | 329 | int ADC_Inp2CH() |
H_Tsunemoto | 0:871ab6846b18 | 330 | { |
H_Tsunemoto | 0:871ab6846b18 | 331 | int i_ret=0; |
H_Tsunemoto | 0:871ab6846b18 | 332 | Adc_inp_temp[ADC_CH1] = ((ad_ch1.read_u16()>>4)&0xFFF); |
H_Tsunemoto | 0:871ab6846b18 | 333 | // Adc_inp_temp[ADC_CH2] = ((ad_ch2.read_u16()>>4)&0xFFF); |
H_Tsunemoto | 0:871ab6846b18 | 334 | adc_Sample_Ave_Count++; |
H_Tsunemoto | 0:871ab6846b18 | 335 | // CH1 Ave |
H_Tsunemoto | 0:871ab6846b18 | 336 | st_adc_sample_ave[ADC_CH1].sample_Add = st_adc_sample_ave[ADC_CH1].sample_Add + (unsigned long)Adc_inp_temp[ADC_CH1]; |
H_Tsunemoto | 0:871ab6846b18 | 337 | // CH2 Ave |
H_Tsunemoto | 0:871ab6846b18 | 338 | // st_adc_sample_ave[ADC_CH2].sample_Add = st_adc_sample_ave[ADC_CH2].sample_Add + (unsigned long)Adc_inp_temp[ADC_CH2]; |
H_Tsunemoto | 0:871ab6846b18 | 339 | |
H_Tsunemoto | 0:871ab6846b18 | 340 | if(adc_Sample_Ave_Count >= (st_adc_mode_param.i_sample_interval)){ |
H_Tsunemoto | 0:871ab6846b18 | 341 | |
H_Tsunemoto | 0:871ab6846b18 | 342 | st_adc_sample_ave[ADC_CH1].sample_Ave = st_adc_sample_ave[ADC_CH1].sample_Add; |
H_Tsunemoto | 0:871ab6846b18 | 343 | // st_adc_sample_ave[ADC_CH2].sample_Ave = st_adc_sample_ave[ADC_CH2].sample_Add; |
H_Tsunemoto | 0:871ab6846b18 | 344 | ADC_ave_Init(); |
H_Tsunemoto | 0:871ab6846b18 | 345 | i_adc_Sample_Status = ADC_SAMPLE_Conplete; |
H_Tsunemoto | 0:871ab6846b18 | 346 | adc_Sample_Ave_Count = 0; |
H_Tsunemoto | 0:871ab6846b18 | 347 | i_ret = 1; |
H_Tsunemoto | 0:871ab6846b18 | 348 | } |
H_Tsunemoto | 0:871ab6846b18 | 349 | return(i_ret); |
H_Tsunemoto | 0:871ab6846b18 | 350 | } |
H_Tsunemoto | 0:871ab6846b18 | 351 | void Tick_100usec_ADC_Interrupt() { |
H_Tsunemoto | 0:871ab6846b18 | 352 | int i_inp_ret; |
H_Tsunemoto | 0:871ab6846b18 | 353 | ///////////////////////////////////////////////// |
H_Tsunemoto | 0:871ab6846b18 | 354 | //2018.02.19 100μsec Interval Timer IRQ Common Control |
H_Tsunemoto | 0:871ab6846b18 | 355 | //void cyclic(void) |
H_Tsunemoto | 0:871ab6846b18 | 356 | // { |
H_Tsunemoto | 0:871ab6846b18 | 357 | if( i_LED_Active == Debug_LED_Active){ |
H_Tsunemoto | 0:871ab6846b18 | 358 | led1=1; |
H_Tsunemoto | 0:871ab6846b18 | 359 | } |
H_Tsunemoto | 0:871ab6846b18 | 360 | Rx_1char(); |
H_Tsunemoto | 0:871ab6846b18 | 361 | timer_count++; //increment timer_count |
H_Tsunemoto | 0:871ab6846b18 | 362 | if(timer_count >= 10000){ |
H_Tsunemoto | 0:871ab6846b18 | 363 | timer_count = 0; |
H_Tsunemoto | 0:871ab6846b18 | 364 | timer_1Sec++; |
H_Tsunemoto | 0:871ab6846b18 | 365 | } |
H_Tsunemoto | 0:871ab6846b18 | 366 | i_adc_Sample_Total_Time++; |
H_Tsunemoto | 0:871ab6846b18 | 367 | if( i_LED_Active == Debug_LED_Active){ |
H_Tsunemoto | 0:871ab6846b18 | 368 | led1=0; |
H_Tsunemoto | 0:871ab6846b18 | 369 | } |
H_Tsunemoto | 0:871ab6846b18 | 370 | //} |
H_Tsunemoto | 0:871ab6846b18 | 371 | |
H_Tsunemoto | 0:871ab6846b18 | 372 | /////////////////////////////////////////////////////////////////////// |
H_Tsunemoto | 0:871ab6846b18 | 373 | if(i_LED_Active == Debug_LED_Active){ |
H_Tsunemoto | 0:871ab6846b18 | 374 | led2 = 1; |
H_Tsunemoto | 0:871ab6846b18 | 375 | } |
H_Tsunemoto | 0:871ab6846b18 | 376 | ADC_Count1Block++; |
H_Tsunemoto | 0:871ab6846b18 | 377 | ADC_Count1++; |
H_Tsunemoto | 0:871ab6846b18 | 378 | if(i_adc_ActiveMode_status == ActiveMode_ADC_Sample_Busy){ |
H_Tsunemoto | 0:871ab6846b18 | 379 | i_inp_ret = ADC_Inp2CH(); |
H_Tsunemoto | 0:871ab6846b18 | 380 | } |
H_Tsunemoto | 0:871ab6846b18 | 381 | else if (i_adc_ActiveMode_status == ActiveMode_ADC_Sample_Stop){ |
H_Tsunemoto | 0:871ab6846b18 | 382 | } |
H_Tsunemoto | 0:871ab6846b18 | 383 | if(i_LED_Active == Debug_LED_Active){ |
H_Tsunemoto | 0:871ab6846b18 | 384 | led2 = 0; |
H_Tsunemoto | 0:871ab6846b18 | 385 | } |
H_Tsunemoto | 0:871ab6846b18 | 386 | |
H_Tsunemoto | 0:871ab6846b18 | 387 | } |
H_Tsunemoto | 0:871ab6846b18 | 388 | //-------------------------------------------------------// |
H_Tsunemoto | 0:871ab6846b18 | 389 | // ADC Measurement Parameter Initial Set // |
H_Tsunemoto | 0:871ab6846b18 | 390 | // 2013.08.14 H.Tsunemoto |
H_Tsunemoto | 0:871ab6846b18 | 391 | //typedef struct st_adc_param{ |
H_Tsunemoto | 0:871ab6846b18 | 392 | // int i_sample_interval; // DAC Output Pattern |
H_Tsunemoto | 0:871ab6846b18 | 393 | // float f_trigger_level; |
H_Tsunemoto | 0:871ab6846b18 | 394 | // unsigned short us_trigger_level; // (3.3f/1023) * f_trigger_level (Image) |
H_Tsunemoto | 0:871ab6846b18 | 395 | // int i_pre_trig_point; |
H_Tsunemoto | 0:871ab6846b18 | 396 | // int i_pulse_end_time; |
H_Tsunemoto | 0:871ab6846b18 | 397 | //}ST_ADC_PARAM; |
H_Tsunemoto | 0:871ab6846b18 | 398 | // |
H_Tsunemoto | 0:871ab6846b18 | 399 | //ST_ADC_PARAM st_adc_mode_param; |
H_Tsunemoto | 0:871ab6846b18 | 400 | //-------------------------------------------------------// |
H_Tsunemoto | 0:871ab6846b18 | 401 | void adc_param_init() |
H_Tsunemoto | 0:871ab6846b18 | 402 | { |
H_Tsunemoto | 0:871ab6846b18 | 403 | st_adc_mode_param.i_sample_interval = const_ADC_Param_Default.i_sample_interval; |
H_Tsunemoto | 0:871ab6846b18 | 404 | } |
H_Tsunemoto | 0:871ab6846b18 | 405 | /////////////////////////////////////////////////////////////////////////////////////////// |
H_Tsunemoto | 0:871ab6846b18 | 406 | /////////////////////////////////////////////////////////////////////////////////////////// |
H_Tsunemoto | 0:871ab6846b18 | 407 | |
H_Tsunemoto | 0:871ab6846b18 | 408 | //------------------------------------------------------------------// |
H_Tsunemoto | 0:871ab6846b18 | 409 | //----- Serial rx Commmand Input & Parameter Set Function -----// |
H_Tsunemoto | 0:871ab6846b18 | 410 | // Tsunemoto Since 2016.05.20 // |
H_Tsunemoto | 0:871ab6846b18 | 411 | // ADC No.1 "SMP 1000" ADC Sample Rate 2 - 1000 msec |
H_Tsunemoto | 0:871ab6846b18 | 412 | // ADC No.2 "RNA 0" ADC CH1 Range 0 / 1 |
H_Tsunemoto | 0:871ab6846b18 | 413 | // ADC No.3 "RNB 1" ADC CH2 Range 0 / 1 |
H_Tsunemoto | 0:871ab6846b18 | 414 | // ADC No.4 "START" ADC Sample Start |
H_Tsunemoto | 0:871ab6846b18 | 415 | // ADC No.5 "STOP" ADC Sample Stop |
H_Tsunemoto | 0:871ab6846b18 | 416 | // ADC No.6 // "?" |
H_Tsunemoto | 0:871ab6846b18 | 417 | |
H_Tsunemoto | 0:871ab6846b18 | 418 | //------------------------------------------------------------------// |
H_Tsunemoto | 0:871ab6846b18 | 419 | void Ser_Command_Input() |
H_Tsunemoto | 0:871ab6846b18 | 420 | { |
H_Tsunemoto | 0:871ab6846b18 | 421 | int i_RecCharCount; |
H_Tsunemoto | 0:871ab6846b18 | 422 | bool b_CommadERR = 0; |
H_Tsunemoto | 0:871ab6846b18 | 423 | |
H_Tsunemoto | 0:871ab6846b18 | 424 | while(rx_cr_Rec != 0){ |
H_Tsunemoto | 0:871ab6846b18 | 425 | // Read a line from the large rx buffer from rx interrupt routine |
H_Tsunemoto | 0:871ab6846b18 | 426 | |
H_Tsunemoto | 0:871ab6846b18 | 427 | if(rx_in != rx_out){ |
H_Tsunemoto | 0:871ab6846b18 | 428 | i_RecCharCount = read_line(); |
H_Tsunemoto | 0:871ab6846b18 | 429 | if(i_RecCharCount != 0){ |
H_Tsunemoto | 0:871ab6846b18 | 430 | switch(rx_line[0]){ |
H_Tsunemoto | 0:871ab6846b18 | 431 | // Header "A" ADC Control Command |
H_Tsunemoto | 0:871ab6846b18 | 432 | case 'S': |
H_Tsunemoto | 0:871ab6846b18 | 433 | if(i_RecCharCount == 1){ |
H_Tsunemoto | 0:871ab6846b18 | 434 | i_adc_ActiveMode_status = ActiveMode_ADC_Sample_Busy; |
H_Tsunemoto | 0:871ab6846b18 | 435 | Start_ADC(); |
H_Tsunemoto | 0:871ab6846b18 | 436 | } |
H_Tsunemoto | 0:871ab6846b18 | 437 | else if (rx_line[1] == 'T'){ |
H_Tsunemoto | 0:871ab6846b18 | 438 | //case 'T': |
H_Tsunemoto | 0:871ab6846b18 | 439 | if((rx_line[2] == 'A') && (rx_line[3] == 'R') && (rx_line[4] == 'T')){ |
H_Tsunemoto | 0:871ab6846b18 | 440 | i_adc_ActiveMode_status = ActiveMode_ADC_Sample_Busy; |
H_Tsunemoto | 0:871ab6846b18 | 441 | Start_ADC(); |
H_Tsunemoto | 0:871ab6846b18 | 442 | |
H_Tsunemoto | 0:871ab6846b18 | 443 | } |
H_Tsunemoto | 0:871ab6846b18 | 444 | else if((rx_line[2] == 'O') && (rx_line[3] == 'P') ){ |
H_Tsunemoto | 0:871ab6846b18 | 445 | i_adc_ActiveMode_status = ActiveMode_ADC_Sample_Stop; |
H_Tsunemoto | 0:871ab6846b18 | 446 | // 2018.02.19 for 100μsec Int Timer Continuas Enable |
H_Tsunemoto | 0:871ab6846b18 | 447 | /// ADC_Stop(); |
H_Tsunemoto | 0:871ab6846b18 | 448 | } |
H_Tsunemoto | 0:871ab6846b18 | 449 | else if ((rx_line[2] == '?')){ //{ "ST?" |
H_Tsunemoto | 0:871ab6846b18 | 450 | com_ADC_Table_Param_Send(); |
H_Tsunemoto | 0:871ab6846b18 | 451 | } |
H_Tsunemoto | 0:871ab6846b18 | 452 | else if ( (rx_line[2] == 'A')&& (rx_line[3] == '?')){ //{ "STA?" |
H_Tsunemoto | 0:871ab6846b18 | 453 | com_ADC_Table_Param_Send(); |
H_Tsunemoto | 0:871ab6846b18 | 454 | } |
H_Tsunemoto | 0:871ab6846b18 | 455 | else if ( (rx_line[2] == 'A')&& (rx_line[3] == 'T')&& (rx_line[4] == '?')){ //{ "STAT?" |
H_Tsunemoto | 0:871ab6846b18 | 456 | com_ADC_Table_Param_Send(); |
H_Tsunemoto | 0:871ab6846b18 | 457 | } |
H_Tsunemoto | 0:871ab6846b18 | 458 | else{ |
H_Tsunemoto | 0:871ab6846b18 | 459 | b_CommadERR = 1; |
H_Tsunemoto | 0:871ab6846b18 | 460 | } |
H_Tsunemoto | 0:871ab6846b18 | 461 | //break; |
H_Tsunemoto | 0:871ab6846b18 | 462 | } |
H_Tsunemoto | 0:871ab6846b18 | 463 | else if((rx_line[1] == 'M') && (rx_line[2] == 'P')){ |
H_Tsunemoto | 0:871ab6846b18 | 464 | com_Check_SMP( i_RecCharCount); |
H_Tsunemoto | 0:871ab6846b18 | 465 | } |
H_Tsunemoto | 0:871ab6846b18 | 466 | else if (rx_line[1] == '?'){ //{ case '?': |
H_Tsunemoto | 0:871ab6846b18 | 467 | com_ADC_Table_Param_Send(); |
H_Tsunemoto | 0:871ab6846b18 | 468 | //break; |
H_Tsunemoto | 0:871ab6846b18 | 469 | } |
H_Tsunemoto | 0:871ab6846b18 | 470 | else{ |
H_Tsunemoto | 0:871ab6846b18 | 471 | //default: |
H_Tsunemoto | 0:871ab6846b18 | 472 | b_CommadERR = 1; |
H_Tsunemoto | 0:871ab6846b18 | 473 | //break; |
H_Tsunemoto | 0:871ab6846b18 | 474 | } |
H_Tsunemoto | 0:871ab6846b18 | 475 | break; |
H_Tsunemoto | 0:871ab6846b18 | 476 | case 'T': // "T?" Timer Interrupt Counter Repry |
H_Tsunemoto | 0:871ab6846b18 | 477 | if (rx_line[1]=='?'){ |
H_Tsunemoto | 0:871ab6846b18 | 478 | serial.printf("Timer=%d[S}+%d[x0.1mSec] \r\n",timer_1Sec,timer_count); |
H_Tsunemoto | 0:871ab6846b18 | 479 | // sprintf(tx_line,"Timer=%d[S}+%d[x0.1mSec] \r\n",timer_1Sec,timer_count); |
H_Tsunemoto | 0:871ab6846b18 | 480 | // // Copy tx line buffer to large tx buffer for tx interrupt routine |
H_Tsunemoto | 0:871ab6846b18 | 481 | // send_line(); |
H_Tsunemoto | 0:871ab6846b18 | 482 | |
H_Tsunemoto | 0:871ab6846b18 | 483 | } |
H_Tsunemoto | 0:871ab6846b18 | 484 | else if(rx_line[1]=='C'){ |
H_Tsunemoto | 0:871ab6846b18 | 485 | timer_1Sec = timer_count = 0; |
H_Tsunemoto | 0:871ab6846b18 | 486 | } |
H_Tsunemoto | 0:871ab6846b18 | 487 | else{ |
H_Tsunemoto | 0:871ab6846b18 | 488 | b_CommadERR = 1; |
H_Tsunemoto | 0:871ab6846b18 | 489 | } |
H_Tsunemoto | 0:871ab6846b18 | 490 | break; |
H_Tsunemoto | 0:871ab6846b18 | 491 | |
H_Tsunemoto | 0:871ab6846b18 | 492 | case 'R': // RNA / RNB Range Command |
H_Tsunemoto | 0:871ab6846b18 | 493 | if(rx_line[1]=='N'){ |
H_Tsunemoto | 0:871ab6846b18 | 494 | switch(rx_line[2]){ |
H_Tsunemoto | 0:871ab6846b18 | 495 | case 'A': |
H_Tsunemoto | 0:871ab6846b18 | 496 | b_CommadERR= com_Check_RNA(i_RecCharCount); |
H_Tsunemoto | 0:871ab6846b18 | 497 | break; |
H_Tsunemoto | 0:871ab6846b18 | 498 | case 'B': |
H_Tsunemoto | 0:871ab6846b18 | 499 | b_CommadERR= com_Check_RNB(i_RecCharCount); |
H_Tsunemoto | 0:871ab6846b18 | 500 | break; |
H_Tsunemoto | 0:871ab6846b18 | 501 | default: |
H_Tsunemoto | 0:871ab6846b18 | 502 | b_CommadERR = 1; |
H_Tsunemoto | 0:871ab6846b18 | 503 | break; |
H_Tsunemoto | 0:871ab6846b18 | 504 | } |
H_Tsunemoto | 0:871ab6846b18 | 505 | } |
H_Tsunemoto | 0:871ab6846b18 | 506 | |
H_Tsunemoto | 0:871ab6846b18 | 507 | break; |
H_Tsunemoto | 0:871ab6846b18 | 508 | case '?': |
H_Tsunemoto | 0:871ab6846b18 | 509 | if(i_RecCharCount == 1){ |
H_Tsunemoto | 0:871ab6846b18 | 510 | com_ADC_Table_Param_Send(); |
H_Tsunemoto | 0:871ab6846b18 | 511 | } |
H_Tsunemoto | 0:871ab6846b18 | 512 | else{ |
H_Tsunemoto | 0:871ab6846b18 | 513 | b_CommadERR = 1; |
H_Tsunemoto | 0:871ab6846b18 | 514 | } |
H_Tsunemoto | 0:871ab6846b18 | 515 | break; |
H_Tsunemoto | 0:871ab6846b18 | 516 | //break; |
H_Tsunemoto | 0:871ab6846b18 | 517 | case 'E': |
H_Tsunemoto | 0:871ab6846b18 | 518 | if(i_RecCharCount == 1){ |
H_Tsunemoto | 0:871ab6846b18 | 519 | i_adc_ActiveMode_status = ActiveMode_ADC_Sample_Stop; |
H_Tsunemoto | 0:871ab6846b18 | 520 | // 2018.02.19 for 100μsec Int Timer Continuas Enable |
H_Tsunemoto | 0:871ab6846b18 | 521 | /// ADC_Stop(); |
H_Tsunemoto | 0:871ab6846b18 | 522 | } |
H_Tsunemoto | 0:871ab6846b18 | 523 | else{ |
H_Tsunemoto | 0:871ab6846b18 | 524 | b_CommadERR = 1; |
H_Tsunemoto | 0:871ab6846b18 | 525 | } |
H_Tsunemoto | 0:871ab6846b18 | 526 | break; |
H_Tsunemoto | 0:871ab6846b18 | 527 | case 'L': |
H_Tsunemoto | 0:871ab6846b18 | 528 | if((rx_line[1] == 'E') && (rx_line[2] == 'D') ){ |
H_Tsunemoto | 0:871ab6846b18 | 529 | b_CommadERR = com_Check_LED(i_RecCharCount); |
H_Tsunemoto | 0:871ab6846b18 | 530 | } |
H_Tsunemoto | 0:871ab6846b18 | 531 | else{ |
H_Tsunemoto | 0:871ab6846b18 | 532 | } |
H_Tsunemoto | 0:871ab6846b18 | 533 | default: |
H_Tsunemoto | 0:871ab6846b18 | 534 | b_CommadERR = 1; |
H_Tsunemoto | 0:871ab6846b18 | 535 | break; |
H_Tsunemoto | 0:871ab6846b18 | 536 | |
H_Tsunemoto | 0:871ab6846b18 | 537 | } |
H_Tsunemoto | 0:871ab6846b18 | 538 | } |
H_Tsunemoto | 0:871ab6846b18 | 539 | if(b_CommadERR == 0){ |
H_Tsunemoto | 0:871ab6846b18 | 540 | serial.printf("ACK%d \r\n",rx_cr_Rec); |
H_Tsunemoto | 0:871ab6846b18 | 541 | // sprintf(tx_line,"ACK%d \r\n",rx_cr_Rec); |
H_Tsunemoto | 0:871ab6846b18 | 542 | // // Copy tx line buffer to large tx buffer for tx interrupt routine |
H_Tsunemoto | 0:871ab6846b18 | 543 | // send_line(); |
H_Tsunemoto | 0:871ab6846b18 | 544 | } |
H_Tsunemoto | 0:871ab6846b18 | 545 | else{ |
H_Tsunemoto | 0:871ab6846b18 | 546 | serial.printf("ERR%d \r\n",rx_cr_Rec); |
H_Tsunemoto | 0:871ab6846b18 | 547 | // sprintf(tx_line,"ERR%d \r\n",rx_cr_Rec); |
H_Tsunemoto | 0:871ab6846b18 | 548 | // // Copy tx line buffer to large tx buffer for tx interrupt routine |
H_Tsunemoto | 0:871ab6846b18 | 549 | // send_line(); |
H_Tsunemoto | 0:871ab6846b18 | 550 | } |
H_Tsunemoto | 0:871ab6846b18 | 551 | rx_cr_Rec--; |
H_Tsunemoto | 0:871ab6846b18 | 552 | } |
H_Tsunemoto | 0:871ab6846b18 | 553 | else{ |
H_Tsunemoto | 0:871ab6846b18 | 554 | rx_cr_Rec = 0; |
H_Tsunemoto | 0:871ab6846b18 | 555 | break; |
H_Tsunemoto | 0:871ab6846b18 | 556 | } |
H_Tsunemoto | 0:871ab6846b18 | 557 | } |
H_Tsunemoto | 0:871ab6846b18 | 558 | } |
H_Tsunemoto | 0:871ab6846b18 | 559 | ////////////////////////////////////////////////////////////////////////////////// |
H_Tsunemoto | 0:871ab6846b18 | 560 | //------------ Command Check & Set Function ---------------------------------// |
H_Tsunemoto | 0:871ab6846b18 | 561 | // Input :i_RecCharCount :Command Stringth Length // |
H_Tsunemoto | 0:871ab6846b18 | 562 | // rx_line[80] :(Global) Rec Data Stringth // |
H_Tsunemoto | 0:871ab6846b18 | 563 | // Return :bool b_CommadERR 0= ACK // |
H_Tsunemoto | 0:871ab6846b18 | 564 | // 1= ERR // |
H_Tsunemoto | 0:871ab6846b18 | 565 | ////////////////////////////////////////////////////////////////////////////////// |
H_Tsunemoto | 0:871ab6846b18 | 566 | //------------------------------------------------------------------------------// |
H_Tsunemoto | 0:871ab6846b18 | 567 | // ADC No.1 "SMP xxxx ADC Sample Interval Set // |
H_Tsunemoto | 0:871ab6846b18 | 568 | //#define ADC_SAMPLE_RATE_MIN 2 |
H_Tsunemoto | 0:871ab6846b18 | 569 | //#define ADC_SAMPLE_RATE_MAX 1000 |
H_Tsunemoto | 0:871ab6846b18 | 570 | //int st_adc_mode_param.i_sample_interval = 200; // ADC Sample Rate 5 - 20000(20.0mSec) |
H_Tsunemoto | 0:871ab6846b18 | 571 | //------------------------------------------------------------------------------// |
H_Tsunemoto | 0:871ab6846b18 | 572 | bool com_Check_SMP(int i_RecCharCount) |
H_Tsunemoto | 0:871ab6846b18 | 573 | { |
H_Tsunemoto | 0:871ab6846b18 | 574 | bool b_CommadERR=0; |
H_Tsunemoto | 0:871ab6846b18 | 575 | int i_num=2; |
H_Tsunemoto | 0:871ab6846b18 | 576 | char *pt_comRec; |
H_Tsunemoto | 0:871ab6846b18 | 577 | |
H_Tsunemoto | 0:871ab6846b18 | 578 | if(i_RecCharCount < 4){ |
H_Tsunemoto | 0:871ab6846b18 | 579 | b_CommadERR = 1; |
H_Tsunemoto | 0:871ab6846b18 | 580 | } |
H_Tsunemoto | 0:871ab6846b18 | 581 | else{ |
H_Tsunemoto | 0:871ab6846b18 | 582 | pt_comRec = (char *)&rx_line[3]; |
H_Tsunemoto | 0:871ab6846b18 | 583 | i_num = atoi(pt_comRec); |
H_Tsunemoto | 0:871ab6846b18 | 584 | if((i_num >= ADC_SAMPLE_RATE_MIN ) && (i_num <= ADC_SAMPLE_RATE_MAX)){ |
H_Tsunemoto | 0:871ab6846b18 | 585 | st_adc_mode_param.i_sample_interval = (int)( i_num *10 ) ; |
H_Tsunemoto | 0:871ab6846b18 | 586 | } |
H_Tsunemoto | 0:871ab6846b18 | 587 | else{ |
H_Tsunemoto | 0:871ab6846b18 | 588 | b_CommadERR = 1; |
H_Tsunemoto | 0:871ab6846b18 | 589 | } |
H_Tsunemoto | 0:871ab6846b18 | 590 | |
H_Tsunemoto | 0:871ab6846b18 | 591 | } |
H_Tsunemoto | 0:871ab6846b18 | 592 | return(b_CommadERR); |
H_Tsunemoto | 0:871ab6846b18 | 593 | } |
H_Tsunemoto | 0:871ab6846b18 | 594 | //------------------------------------------------------------------------------// |
H_Tsunemoto | 0:871ab6846b18 | 595 | // ADC No.2 "RNA 0" CH AMP Range 0 / 1 |
H_Tsunemoto | 0:871ab6846b18 | 596 | //------------------------------------------------------------------------------// |
H_Tsunemoto | 0:871ab6846b18 | 597 | bool com_Check_RNA(int i_RecCharCount) |
H_Tsunemoto | 0:871ab6846b18 | 598 | { |
H_Tsunemoto | 0:871ab6846b18 | 599 | bool b_CommadERR=0; |
H_Tsunemoto | 0:871ab6846b18 | 600 | int i_num=0; |
H_Tsunemoto | 0:871ab6846b18 | 601 | char *pt_comRec; |
H_Tsunemoto | 0:871ab6846b18 | 602 | |
H_Tsunemoto | 0:871ab6846b18 | 603 | if(i_RecCharCount < 4){ |
H_Tsunemoto | 0:871ab6846b18 | 604 | b_CommadERR = 1; |
H_Tsunemoto | 0:871ab6846b18 | 605 | } |
H_Tsunemoto | 0:871ab6846b18 | 606 | else{ |
H_Tsunemoto | 0:871ab6846b18 | 607 | pt_comRec = (char *)&rx_line[3]; |
H_Tsunemoto | 0:871ab6846b18 | 608 | i_num = atoi(pt_comRec); |
H_Tsunemoto | 0:871ab6846b18 | 609 | if(i_num == 0){ |
H_Tsunemoto | 0:871ab6846b18 | 610 | st_adc_mode_param.i_CH1_Range = i_num; |
H_Tsunemoto | 0:871ab6846b18 | 611 | // POut_CH1_Rng = 0; |
H_Tsunemoto | 0:871ab6846b18 | 612 | } |
H_Tsunemoto | 0:871ab6846b18 | 613 | else if(i_num == 1){ |
H_Tsunemoto | 0:871ab6846b18 | 614 | st_adc_mode_param.i_CH1_Range = i_num; |
H_Tsunemoto | 0:871ab6846b18 | 615 | // POut_CH1_Rng = 1; |
H_Tsunemoto | 0:871ab6846b18 | 616 | } |
H_Tsunemoto | 0:871ab6846b18 | 617 | else{ |
H_Tsunemoto | 0:871ab6846b18 | 618 | b_CommadERR = 1; |
H_Tsunemoto | 0:871ab6846b18 | 619 | } |
H_Tsunemoto | 0:871ab6846b18 | 620 | } |
H_Tsunemoto | 0:871ab6846b18 | 621 | return(b_CommadERR); |
H_Tsunemoto | 0:871ab6846b18 | 622 | } |
H_Tsunemoto | 0:871ab6846b18 | 623 | //------------------------------------------------------------------------------// |
H_Tsunemoto | 0:871ab6846b18 | 624 | // ADC No.3 "RNB 0" CH AMP Range 0 / 1 |
H_Tsunemoto | 0:871ab6846b18 | 625 | //------------------------------------------------------------------------------// |
H_Tsunemoto | 0:871ab6846b18 | 626 | bool com_Check_RNB(int i_RecCharCount) |
H_Tsunemoto | 0:871ab6846b18 | 627 | { |
H_Tsunemoto | 0:871ab6846b18 | 628 | bool b_CommadERR=0; |
H_Tsunemoto | 0:871ab6846b18 | 629 | int i_num=0; |
H_Tsunemoto | 0:871ab6846b18 | 630 | char *pt_comRec; |
H_Tsunemoto | 0:871ab6846b18 | 631 | |
H_Tsunemoto | 0:871ab6846b18 | 632 | if(i_RecCharCount < 4){ |
H_Tsunemoto | 0:871ab6846b18 | 633 | b_CommadERR = 1; |
H_Tsunemoto | 0:871ab6846b18 | 634 | } |
H_Tsunemoto | 0:871ab6846b18 | 635 | else{ |
H_Tsunemoto | 0:871ab6846b18 | 636 | pt_comRec = (char *)&rx_line[3]; |
H_Tsunemoto | 0:871ab6846b18 | 637 | i_num = atoi(pt_comRec); |
H_Tsunemoto | 0:871ab6846b18 | 638 | if(i_num == 0){ |
H_Tsunemoto | 0:871ab6846b18 | 639 | st_adc_mode_param.i_CH2_Range = i_num; |
H_Tsunemoto | 0:871ab6846b18 | 640 | // POut_CH2_Rng = 0; |
H_Tsunemoto | 0:871ab6846b18 | 641 | } |
H_Tsunemoto | 0:871ab6846b18 | 642 | else if(i_num == 1){ |
H_Tsunemoto | 0:871ab6846b18 | 643 | st_adc_mode_param.i_CH2_Range = i_num; |
H_Tsunemoto | 0:871ab6846b18 | 644 | // POut_CH2_Rng = 1; |
H_Tsunemoto | 0:871ab6846b18 | 645 | } |
H_Tsunemoto | 0:871ab6846b18 | 646 | else{ |
H_Tsunemoto | 0:871ab6846b18 | 647 | b_CommadERR = 1; |
H_Tsunemoto | 0:871ab6846b18 | 648 | } |
H_Tsunemoto | 0:871ab6846b18 | 649 | } |
H_Tsunemoto | 0:871ab6846b18 | 650 | return(b_CommadERR); |
H_Tsunemoto | 0:871ab6846b18 | 651 | } |
H_Tsunemoto | 0:871ab6846b18 | 652 | |
H_Tsunemoto | 0:871ab6846b18 | 653 | //------------------------------------------------------------------------------// |
H_Tsunemoto | 0:871ab6846b18 | 654 | // ADC No.5 "A?" DAC Parameter Repry // |
H_Tsunemoto | 0:871ab6846b18 | 655 | //typedef struct st_adc_param{ |
H_Tsunemoto | 0:871ab6846b18 | 656 | // int i_sample_interval; // DAC Output Pattern |
H_Tsunemoto | 0:871ab6846b18 | 657 | // float f_trigger_level; |
H_Tsunemoto | 0:871ab6846b18 | 658 | // us_trigger_level; |
H_Tsunemoto | 0:871ab6846b18 | 659 | // int i_pre_trig_point; |
H_Tsunemoto | 0:871ab6846b18 | 660 | // int i_pulse_end_time; |
H_Tsunemoto | 0:871ab6846b18 | 661 | //}ST_ADC_PARAM; |
H_Tsunemoto | 0:871ab6846b18 | 662 | // |
H_Tsunemoto | 0:871ab6846b18 | 663 | //ST_ADC_PARAM st_adc_mode_param; |
H_Tsunemoto | 0:871ab6846b18 | 664 | // |
H_Tsunemoto | 0:871ab6846b18 | 665 | //------------------------------------------------------------------------------// |
H_Tsunemoto | 0:871ab6846b18 | 666 | void com_ADC_Table_Param_Send() |
H_Tsunemoto | 0:871ab6846b18 | 667 | { |
H_Tsunemoto | 0:871ab6846b18 | 668 | int i_num; |
H_Tsunemoto | 0:871ab6846b18 | 669 | //2016.06.21 for MBED Dose Measure 2CH_2Range Title & Ver Send Append |
H_Tsunemoto | 0:871ab6846b18 | 670 | serial.printf("AE-LPC11U35 Small Dose Measure Ver1.00\r\n"); |
H_Tsunemoto | 0:871ab6846b18 | 671 | // sprintf(tx_line,"MBED Dose Measure Ver0.45\r\n"); // 2016.06.21 for Max.Min Detect Remove & Title&Software Ver Reply Append |
H_Tsunemoto | 0:871ab6846b18 | 672 | // send_line(); |
H_Tsunemoto | 0:871ab6846b18 | 673 | |
H_Tsunemoto | 0:871ab6846b18 | 674 | i_num = ( st_adc_mode_param.i_sample_interval / 10) ; |
H_Tsunemoto | 0:871ab6846b18 | 675 | serial.printf("SMP %4d[mSec]\r\n",i_num); |
H_Tsunemoto | 0:871ab6846b18 | 676 | // sprintf(tx_line,"SMP %4d[mSec]\r\n",i_num); |
H_Tsunemoto | 0:871ab6846b18 | 677 | // send_line(); |
H_Tsunemoto | 0:871ab6846b18 | 678 | i_num = st_adc_mode_param.i_CH1_Range; |
H_Tsunemoto | 0:871ab6846b18 | 679 | serial.printf("SMP %4d[mSec]\r\n",i_num); |
H_Tsunemoto | 0:871ab6846b18 | 680 | // sprintf(tx_line,"RNA %1d\r\n",i_num); |
H_Tsunemoto | 0:871ab6846b18 | 681 | // send_line(); |
H_Tsunemoto | 0:871ab6846b18 | 682 | i_num = st_adc_mode_param.i_CH2_Range; |
H_Tsunemoto | 0:871ab6846b18 | 683 | serial.printf("RNB %1d\r\n",i_num); |
H_Tsunemoto | 0:871ab6846b18 | 684 | // sprintf(tx_line,"RNB %1d\r\n",i_num); |
H_Tsunemoto | 0:871ab6846b18 | 685 | // send_line(); |
H_Tsunemoto | 0:871ab6846b18 | 686 | // for Debug |
H_Tsunemoto | 0:871ab6846b18 | 687 | serial.printf("ADC Sample Count = %d,BuffLoop=%d\r\n",ADC_Count1,ADC_Count1Block); |
H_Tsunemoto | 0:871ab6846b18 | 688 | // sprintf(tx_line,"ADC Sample Count = %d,BuffLoop=%d\r\n",ADC_Count1,ADC_Count1Block); |
H_Tsunemoto | 0:871ab6846b18 | 689 | // send_line(); |
H_Tsunemoto | 0:871ab6846b18 | 690 | // |
H_Tsunemoto | 0:871ab6846b18 | 691 | // Ative Mode Status Controll |
H_Tsunemoto | 0:871ab6846b18 | 692 | //#define ActiveMode_ADC_Sample_Stop 0 |
H_Tsunemoto | 0:871ab6846b18 | 693 | //#define ActiveMode_ADC_Sample_Busy 1 // |
H_Tsunemoto | 0:871ab6846b18 | 694 | switch(i_adc_ActiveMode_status){ |
H_Tsunemoto | 0:871ab6846b18 | 695 | case ActiveMode_ADC_Sample_Stop: |
H_Tsunemoto | 0:871ab6846b18 | 696 | serial.printf( "ADC i_adc_ActiveMode_status = ActiveMode_ADC_Sample_Stop\r\n"); |
H_Tsunemoto | 0:871ab6846b18 | 697 | // sprintf(tx_line,"ADC i_adc_ActiveMode_status = ActiveMode_ADC_Sample_Stop\r\n"); |
H_Tsunemoto | 0:871ab6846b18 | 698 | break; |
H_Tsunemoto | 0:871ab6846b18 | 699 | case ActiveMode_ADC_Sample_Busy: |
H_Tsunemoto | 0:871ab6846b18 | 700 | serial.printf( "ADC i_adc_ActiveMode_status = ActiveMode_ADC_Sample_Busy\r\n"); |
H_Tsunemoto | 0:871ab6846b18 | 701 | // sprintf(tx_line,"ADC i_adc_ActiveMode_status = ActiveMode_ADC_Sample_Busy\r\n"); |
H_Tsunemoto | 0:871ab6846b18 | 702 | break; |
H_Tsunemoto | 0:871ab6846b18 | 703 | } |
H_Tsunemoto | 0:871ab6846b18 | 704 | // send_line(); |
H_Tsunemoto | 0:871ab6846b18 | 705 | |
H_Tsunemoto | 0:871ab6846b18 | 706 | } |
H_Tsunemoto | 0:871ab6846b18 | 707 | //------------------------------------------------------------------------------// |
H_Tsunemoto | 0:871ab6846b18 | 708 | // ADC No.7 "LED 1" Devug LED Active 0 / 1 |
H_Tsunemoto | 0:871ab6846b18 | 709 | //------------------------------------------------------------------------------// |
H_Tsunemoto | 0:871ab6846b18 | 710 | bool com_Check_LED(int i_RecCharCount) |
H_Tsunemoto | 0:871ab6846b18 | 711 | { |
H_Tsunemoto | 0:871ab6846b18 | 712 | bool b_CommadERR=0; |
H_Tsunemoto | 0:871ab6846b18 | 713 | int i_num=0; |
H_Tsunemoto | 0:871ab6846b18 | 714 | char *pt_comRec; |
H_Tsunemoto | 0:871ab6846b18 | 715 | |
H_Tsunemoto | 0:871ab6846b18 | 716 | if(i_RecCharCount < 4){ |
H_Tsunemoto | 0:871ab6846b18 | 717 | b_CommadERR = 1; |
H_Tsunemoto | 0:871ab6846b18 | 718 | } |
H_Tsunemoto | 0:871ab6846b18 | 719 | else{ |
H_Tsunemoto | 0:871ab6846b18 | 720 | pt_comRec = (char *)&rx_line[3]; |
H_Tsunemoto | 0:871ab6846b18 | 721 | i_num = atoi(pt_comRec); |
H_Tsunemoto | 0:871ab6846b18 | 722 | if(i_num == 0){ |
H_Tsunemoto | 0:871ab6846b18 | 723 | i_LED_Active = Debug_LED_Disable; // Disable |
H_Tsunemoto | 0:871ab6846b18 | 724 | led1=led2=led3=led4=0; |
H_Tsunemoto | 0:871ab6846b18 | 725 | } |
H_Tsunemoto | 0:871ab6846b18 | 726 | else if(i_num == 1){ |
H_Tsunemoto | 0:871ab6846b18 | 727 | i_LED_Active = Debug_LED_Active; // Debug LED Active |
H_Tsunemoto | 0:871ab6846b18 | 728 | led1=led2=led3=led4=0; |
H_Tsunemoto | 0:871ab6846b18 | 729 | } |
H_Tsunemoto | 0:871ab6846b18 | 730 | else{ |
H_Tsunemoto | 0:871ab6846b18 | 731 | b_CommadERR = 1; |
H_Tsunemoto | 0:871ab6846b18 | 732 | } |
H_Tsunemoto | 0:871ab6846b18 | 733 | } |
H_Tsunemoto | 0:871ab6846b18 | 734 | return(b_CommadERR); |
H_Tsunemoto | 0:871ab6846b18 | 735 | } |
H_Tsunemoto | 0:871ab6846b18 | 736 | |
H_Tsunemoto | 0:871ab6846b18 | 737 | |
H_Tsunemoto | 0:871ab6846b18 | 738 | ////////////////////////////////////////////////////////////////////////////////// |
H_Tsunemoto | 0:871ab6846b18 | 739 | ////////////////////////////////////////////////////////////////////////////////// |
H_Tsunemoto | 0:871ab6846b18 | 740 | |
H_Tsunemoto | 0:871ab6846b18 | 741 | |
H_Tsunemoto | 0:871ab6846b18 | 742 | //------------------------------------------------------------------------------// |
H_Tsunemoto | 0:871ab6846b18 | 743 | //------------------------------------------------------------------------------// |
H_Tsunemoto | 0:871ab6846b18 | 744 | //----- Serial tx/rx Communication |
H_Tsunemoto | 0:871ab6846b18 | 745 | //------------------------------------------------------------------------------// |
H_Tsunemoto | 0:871ab6846b18 | 746 | /* |
H_Tsunemoto | 0:871ab6846b18 | 747 | // Copy tx line buffer to large tx buffer for tx interrupt routine |
H_Tsunemoto | 0:871ab6846b18 | 748 | void send_line() { |
H_Tsunemoto | 0:871ab6846b18 | 749 | int i; |
H_Tsunemoto | 0:871ab6846b18 | 750 | char temp_char; |
H_Tsunemoto | 0:871ab6846b18 | 751 | bool empty; |
H_Tsunemoto | 0:871ab6846b18 | 752 | i = 0; |
H_Tsunemoto | 0:871ab6846b18 | 753 | // Start Critical Section - don't interrupt while changing global buffer variables |
H_Tsunemoto | 0:871ab6846b18 | 754 | // NVIC_DisableIRQ(UART1_IRQn); |
H_Tsunemoto | 0:871ab6846b18 | 755 | empty = (tx_in == tx_out); |
H_Tsunemoto | 0:871ab6846b18 | 756 | while ((i==0) || (tx_line[i-1] != '\n')) { |
H_Tsunemoto | 0:871ab6846b18 | 757 | // Wait if buffer full |
H_Tsunemoto | 0:871ab6846b18 | 758 | if (((tx_in + 1) % ser_buffer_size) == tx_out) { |
H_Tsunemoto | 0:871ab6846b18 | 759 | // End Critical Section - need to let interrupt routine empty buffer by sending |
H_Tsunemoto | 0:871ab6846b18 | 760 | // NVIC_EnableIRQ(UART1_IRQn); |
H_Tsunemoto | 0:871ab6846b18 | 761 | while (((tx_in + 1) % ser_buffer_size) == tx_out) { |
H_Tsunemoto | 0:871ab6846b18 | 762 | } |
H_Tsunemoto | 0:871ab6846b18 | 763 | // Start Critical Section - don't interrupt while changing global buffer variables |
H_Tsunemoto | 0:871ab6846b18 | 764 | // NVIC_DisableIRQ(UART1_IRQn); |
H_Tsunemoto | 0:871ab6846b18 | 765 | } |
H_Tsunemoto | 0:871ab6846b18 | 766 | tx_buffer[tx_in] = tx_line[i]; |
H_Tsunemoto | 0:871ab6846b18 | 767 | i++; |
H_Tsunemoto | 0:871ab6846b18 | 768 | tx_in = (tx_in + 1) % ser_buffer_size; |
H_Tsunemoto | 0:871ab6846b18 | 769 | } |
H_Tsunemoto | 0:871ab6846b18 | 770 | if (device.writeable() && (empty)) { |
H_Tsunemoto | 0:871ab6846b18 | 771 | temp_char = tx_buffer[tx_out]; |
H_Tsunemoto | 0:871ab6846b18 | 772 | tx_out = (tx_out + 1) % ser_buffer_size; |
H_Tsunemoto | 0:871ab6846b18 | 773 | // Send first character to start tx interrupts, if stopped |
H_Tsunemoto | 0:871ab6846b18 | 774 | device.putc(temp_char); |
H_Tsunemoto | 0:871ab6846b18 | 775 | } |
H_Tsunemoto | 0:871ab6846b18 | 776 | // End Critical Section |
H_Tsunemoto | 0:871ab6846b18 | 777 | // NVIC_EnableIRQ(UART1_IRQn); |
H_Tsunemoto | 0:871ab6846b18 | 778 | return; |
H_Tsunemoto | 0:871ab6846b18 | 779 | } |
H_Tsunemoto | 0:871ab6846b18 | 780 | */ |
H_Tsunemoto | 0:871ab6846b18 | 781 | // Read a line from the large rx buffer from rx interrupt routine |
H_Tsunemoto | 0:871ab6846b18 | 782 | // 2013.08.08 H.Tsunemoto |
H_Tsunemoto | 0:871ab6846b18 | 783 | // Append Return Chear Number |
H_Tsunemoto | 0:871ab6846b18 | 784 | int read_line(){ |
H_Tsunemoto | 0:871ab6846b18 | 785 | //void read_line() { |
H_Tsunemoto | 0:871ab6846b18 | 786 | int i; |
H_Tsunemoto | 0:871ab6846b18 | 787 | i = 0; |
H_Tsunemoto | 0:871ab6846b18 | 788 | // Start Critical Section - don't interrupt while changing global buffer variables |
H_Tsunemoto | 0:871ab6846b18 | 789 | // NVIC_DisableIRQ(UART1_IRQn); |
H_Tsunemoto | 0:871ab6846b18 | 790 | while(rx_in != rx_out){ |
H_Tsunemoto | 0:871ab6846b18 | 791 | rx_line[i] = rx_buffer[rx_out]; |
H_Tsunemoto | 0:871ab6846b18 | 792 | rx_out = (rx_out + 1) % ser_buffer_size; |
H_Tsunemoto | 0:871ab6846b18 | 793 | if((rx_line[i] == '\r') || (rx_line[i] == '\n')){ |
H_Tsunemoto | 0:871ab6846b18 | 794 | break; |
H_Tsunemoto | 0:871ab6846b18 | 795 | } |
H_Tsunemoto | 0:871ab6846b18 | 796 | i++; |
H_Tsunemoto | 0:871ab6846b18 | 797 | |
H_Tsunemoto | 0:871ab6846b18 | 798 | } |
H_Tsunemoto | 0:871ab6846b18 | 799 | rx_line[i] = 0; |
H_Tsunemoto | 0:871ab6846b18 | 800 | // End Critical Section |
H_Tsunemoto | 0:871ab6846b18 | 801 | // NVIC_EnableIRQ(UART1_IRQn); |
H_Tsunemoto | 0:871ab6846b18 | 802 | return(i); |
H_Tsunemoto | 0:871ab6846b18 | 803 | } |
H_Tsunemoto | 0:871ab6846b18 | 804 | ////////////////////////////////////////////////////////// |
H_Tsunemoto | 0:871ab6846b18 | 805 | // Serial Data Input USB=>Buffer // |
H_Tsunemoto | 0:871ab6846b18 | 806 | ////////////////////////////////////////////////////////// |
H_Tsunemoto | 0:871ab6846b18 | 807 | void Rx_1char() { |
H_Tsunemoto | 0:871ab6846b18 | 808 | if( i_LED_Active == Debug_LED_Active){ |
H_Tsunemoto | 0:871ab6846b18 | 809 | led1=1; |
H_Tsunemoto | 0:871ab6846b18 | 810 | } |
H_Tsunemoto | 0:871ab6846b18 | 811 | //if data is exist |
H_Tsunemoto | 0:871ab6846b18 | 812 | if (serial.available()) { |
H_Tsunemoto | 0:871ab6846b18 | 813 | ///////////////////////////////////////////////////////////////////// |
H_Tsunemoto | 0:871ab6846b18 | 814 | rx_buffer[rx_in] = serial._getc(); |
H_Tsunemoto | 0:871ab6846b18 | 815 | // rx_buffer[rx_in] = device.getc(); |
H_Tsunemoto | 0:871ab6846b18 | 816 | //-------- 小文字 => 大文字 変換-------------// |
H_Tsunemoto | 0:871ab6846b18 | 817 | if((rx_buffer[rx_in] >= 'a') && (rx_buffer[rx_in] <= 'z')){ |
H_Tsunemoto | 0:871ab6846b18 | 818 | rx_buffer[rx_in] &= 0x0DF; // 'a'0x62 => 'A'0x42 |
H_Tsunemoto | 0:871ab6846b18 | 819 | // rx_buffer[rx_in] -= 0x20; // 'a'0x62 => 'A'0x42 |
H_Tsunemoto | 0:871ab6846b18 | 820 | } |
H_Tsunemoto | 0:871ab6846b18 | 821 | // -- Char CR Rec Counter ----// |
H_Tsunemoto | 0:871ab6846b18 | 822 | if((rx_buffer[rx_in]== '\r') || (rx_buffer[rx_in]== '\n')){ |
H_Tsunemoto | 0:871ab6846b18 | 823 | rx_cr_Rec ++; |
H_Tsunemoto | 0:871ab6846b18 | 824 | } |
H_Tsunemoto | 0:871ab6846b18 | 825 | rx_in = (rx_in + 1) % ser_buffer_size; |
H_Tsunemoto | 0:871ab6846b18 | 826 | } |
H_Tsunemoto | 0:871ab6846b18 | 827 | if( i_LED_Active == Debug_LED_Active){ |
H_Tsunemoto | 0:871ab6846b18 | 828 | led1=0; |
H_Tsunemoto | 0:871ab6846b18 | 829 | } |
H_Tsunemoto | 0:871ab6846b18 | 830 | |
H_Tsunemoto | 0:871ab6846b18 | 831 | ///////////////////////////////////////////////////////////////////// |
H_Tsunemoto | 0:871ab6846b18 | 832 | } |
H_Tsunemoto | 0:871ab6846b18 | 833 | |
H_Tsunemoto | 0:871ab6846b18 | 834 | |
H_Tsunemoto | 0:871ab6846b18 | 835 | //----------------------------------------------------------------------------------// |