MBED_LPC1768_Test Pulse msec/usec Interval Output P29/P30 & Input P21 Status Send USB Serial Log

Dependencies:   mbed

Committer:
H_Tsunemoto
Date:
Tue May 29 02:41:54 2018 +0000
Revision:
0:47c1b6a0c166
Pulse On/OFF OutPut P29/P30 & Rep Input P21 Status Output USBSerial;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
H_Tsunemoto 0:47c1b6a0c166 1 /////////////////////////////////////////////////////////////////////
H_Tsunemoto 0:47c1b6a0c166 2 // MBED Pulse Test OutPut / Input Checkfor RIX/TRIX //
H_Tsunemoto 0:47c1b6a0c166 3 // copy from SingleCH Dose Measure //
H_Tsunemoto 0:47c1b6a0c166 4 /// Since 2018.05.08 H.Tsunemoto //
H_Tsunemoto 0:47c1b6a0c166 5 // Pulse Output X-ray Off P30
H_Tsunemoto 0:47c1b6a0c166 6 /////////////////////////////////////////////////////////////////////
H_Tsunemoto 0:47c1b6a0c166 7
H_Tsunemoto 0:47c1b6a0c166 8 #include "mbed.h"
H_Tsunemoto 0:47c1b6a0c166 9 #include "stdio.h"
H_Tsunemoto 0:47c1b6a0c166 10 #include "math.h"
H_Tsunemoto 0:47c1b6a0c166 11 #include "LPC17xx.h"
H_Tsunemoto 0:47c1b6a0c166 12 // Serial TX & RX interrupt loopback test using formatted IO - sprintf and sscanf
H_Tsunemoto 0:47c1b6a0c166 13 // Connect TX to RX (p9 to p10)
H_Tsunemoto 0:47c1b6a0c166 14 // or can also use USB and type back in the number printed out in a terminal window
H_Tsunemoto 0:47c1b6a0c166 15 // Sends out ASCII numbers in a loop and reads them back
H_Tsunemoto 0:47c1b6a0c166 16 // Since 2013.08.
H_Tsunemoto 0:47c1b6a0c166 17 // If not the same number LED4 goes on
H_Tsunemoto 0:47c1b6a0c166 18 // LED1 and LED2 ADC
H_Tsunemoto 0:47c1b6a0c166 19 // LED3 changing indicate main loop running
H_Tsunemoto 0:47c1b6a0c166 20
H_Tsunemoto 0:47c1b6a0c166 21 //-------------------------------------//
H_Tsunemoto 0:47c1b6a0c166 22 // --- MBED I/O Asign declaration --- //
H_Tsunemoto 0:47c1b6a0c166 23 //-------------------------------------//
H_Tsunemoto 0:47c1b6a0c166 24 // Serial Port Asign P9:TX P10:RX
H_Tsunemoto 0:47c1b6a0c166 25 Serial device(USBTX, USBRX); // tx, rx //Serial device(p9, p10); // tx, rx
H_Tsunemoto 0:47c1b6a0c166 26 // ADC Port Asign P15: ad_ch1 P16 = ad_ch2
H_Tsunemoto 0:47c1b6a0c166 27 // 2017.02.08 H.Tsunemoto
H_Tsunemoto 0:47c1b6a0c166 28 AnalogIn ad_ch1(p20); // AD CH1 P19 MBED ADC Input
H_Tsunemoto 0:47c1b6a0c166 29 AnalogIn ad_ch2(p19); // AD CH2 P20 MBED ADC Input
H_Tsunemoto 0:47c1b6a0c166 30 //AnalogIn ad_ch3(p17); //AD CH2
H_Tsunemoto 0:47c1b6a0c166 31 AnalogOut dac_output(p18);
H_Tsunemoto 0:47c1b6a0c166 32 //DigitalOut POut_CH1_Rng(p21); // Pout CH1 Range Select
H_Tsunemoto 0:47c1b6a0c166 33 //DigitalOut POut_CH2_Rng(p22); // Pout CH2 Range Select
H_Tsunemoto 0:47c1b6a0c166 34 DigitalOut POut_P30_Pulse(p30); // Pout CH2 Range Select
H_Tsunemoto 0:47c1b6a0c166 35 DigitalOut POut_P29_Pulse(p29); // Pout CH2 Range Select
H_Tsunemoto 0:47c1b6a0c166 36 DigitalIn PInp_P21_Port(p21); // Port I/O Status Input
H_Tsunemoto 0:47c1b6a0c166 37
H_Tsunemoto 0:47c1b6a0c166 38 // Can also use USB and type back in the number printed out in a terminal window
H_Tsunemoto 0:47c1b6a0c166 39 // Serial monitor_device(USBTX, USBRX);
H_Tsunemoto 0:47c1b6a0c166 40 DigitalOut led1(LED1); // ADC Active
H_Tsunemoto 0:47c1b6a0c166 41 DigitalOut led2(LED2); // ADC Input Cycle
H_Tsunemoto 0:47c1b6a0c166 42 DigitalOut led3(LED3); // Main Loop Cycle
H_Tsunemoto 0:47c1b6a0c166 43 DigitalOut led4(LED4); // DAC Active
H_Tsunemoto 0:47c1b6a0c166 44 BusOut leds(LED4,LED3,LED2,LED1); //LED
H_Tsunemoto 0:47c1b6a0c166 45
H_Tsunemoto 0:47c1b6a0c166 46 #define Debug_LED_Active 1
H_Tsunemoto 0:47c1b6a0c166 47 #define Debug_LED_Disable 0
H_Tsunemoto 0:47c1b6a0c166 48 int i_LED_Active = Debug_LED_Disable;
H_Tsunemoto 0:47c1b6a0c166 49 //---- ADC Interrupt Timer -----//
H_Tsunemoto 0:47c1b6a0c166 50 int main_loop_count = 0;
H_Tsunemoto 0:47c1b6a0c166 51 Ticker ADC_Timer;
H_Tsunemoto 0:47c1b6a0c166 52 Timer t;
H_Tsunemoto 0:47c1b6a0c166 53
H_Tsunemoto 0:47c1b6a0c166 54 //-------- ADC Measure Mode Parameter declaration --------//
H_Tsunemoto 0:47c1b6a0c166 55 typedef struct st_PulseW_param{
H_Tsunemoto 0:47c1b6a0c166 56 int i_sample_interval; // DAC Output Pattern
H_Tsunemoto 0:47c1b6a0c166 57 int i_usec_Pulse_width;
H_Tsunemoto 0:47c1b6a0c166 58 int i_usec_Pulse_Interval;
H_Tsunemoto 0:47c1b6a0c166 59 int i_usec_Pulse_RepCnt;
H_Tsunemoto 0:47c1b6a0c166 60 int i_msec_Pulse_width;
H_Tsunemoto 0:47c1b6a0c166 61 int i_msec_Pulse_Interval;
H_Tsunemoto 0:47c1b6a0c166 62 int i_msec_Pulse_RepCnt;
H_Tsunemoto 0:47c1b6a0c166 63 int i_PulseTestEnable;
H_Tsunemoto 0:47c1b6a0c166 64 int i_msec_Pulse_OnOffWait;
H_Tsunemoto 0:47c1b6a0c166 65 int i_CH2_Range;
H_Tsunemoto 0:47c1b6a0c166 66 }ST_PulseW_PARAM;
H_Tsunemoto 0:47c1b6a0c166 67
H_Tsunemoto 0:47c1b6a0c166 68 ST_PulseW_PARAM st_p_test_mode_param;
H_Tsunemoto 0:47c1b6a0c166 69
H_Tsunemoto 0:47c1b6a0c166 70 //-------- ADC Measure Mode Parameter Default Set --------//
H_Tsunemoto 0:47c1b6a0c166 71 const ST_PulseW_PARAM const_PulseTest_Param_Default=
H_Tsunemoto 0:47c1b6a0c166 72 {
H_Tsunemoto 0:47c1b6a0c166 73 1000 //i_sample_int=1000 microS
H_Tsunemoto 0:47c1b6a0c166 74 ,5 // Pulse Width Default 1usec
H_Tsunemoto 0:47c1b6a0c166 75 ,500 // Pulse Interval Default 100usec
H_Tsunemoto 0:47c1b6a0c166 76 ,100 // Pulse Repeat Count
H_Tsunemoto 0:47c1b6a0c166 77 ,10 // i_msec_Pulse_width Default 1msec
H_Tsunemoto 0:47c1b6a0c166 78 ,1000 // i_msec_Pulse_width Default 100msec
H_Tsunemoto 0:47c1b6a0c166 79 ,100 // i_msec_Pulse_RepCnt
H_Tsunemoto 0:47c1b6a0c166 80 ,0 // Pulse Trase Log Enable Default Disable
H_Tsunemoto 0:47c1b6a0c166 81 ,50000 // i_msec_Pulse_OnOffWait Default 5000msec
H_Tsunemoto 0:47c1b6a0c166 82 ,0
H_Tsunemoto 0:47c1b6a0c166 83 };
H_Tsunemoto 0:47c1b6a0c166 84 void adc_param_init();
H_Tsunemoto 0:47c1b6a0c166 85
H_Tsunemoto 0:47c1b6a0c166 86
H_Tsunemoto 0:47c1b6a0c166 87
H_Tsunemoto 0:47c1b6a0c166 88
H_Tsunemoto 0:47c1b6a0c166 89 //--------------------------------//
H_Tsunemoto 0:47c1b6a0c166 90 // --- Serial Communication --- //
H_Tsunemoto 0:47c1b6a0c166 91 //--------------------------------//
H_Tsunemoto 0:47c1b6a0c166 92 void Tx_interrupt();
H_Tsunemoto 0:47c1b6a0c166 93 void Rx_interrupt();
H_Tsunemoto 0:47c1b6a0c166 94 void send_line();
H_Tsunemoto 0:47c1b6a0c166 95 int read_line(); // Return Rec CHAR Count 2013.08.08 Tsunemoto Append
H_Tsunemoto 0:47c1b6a0c166 96
H_Tsunemoto 0:47c1b6a0c166 97
H_Tsunemoto 0:47c1b6a0c166 98
H_Tsunemoto 0:47c1b6a0c166 99 //---------- H.Tsunemoto Scince 2013.08.08 ---------//
H_Tsunemoto 0:47c1b6a0c166 100 //-----------------------------------------------------------//
H_Tsunemoto 0:47c1b6a0c166 101 //--------- Timer Innterrupt For DAC Control ---------------//
H_Tsunemoto 0:47c1b6a0c166 102 //-----------------------------------------------------------//
H_Tsunemoto 0:47c1b6a0c166 103 int timer_count=0;
H_Tsunemoto 0:47c1b6a0c166 104 int timer_1Sec=0;
H_Tsunemoto 0:47c1b6a0c166 105
H_Tsunemoto 0:47c1b6a0c166 106 bool b_PulseTestStatus = false; // Pulse Test STatus
H_Tsunemoto 0:47c1b6a0c166 107 #define P_TESTMode_Nop 0
H_Tsunemoto 0:47c1b6a0c166 108 #define P_TESTMode_1SHOT_OFF 1
H_Tsunemoto 0:47c1b6a0c166 109 #define P_TESTMode_1SHOT_ON 2
H_Tsunemoto 0:47c1b6a0c166 110 #define P_TESTMode_Ntimes_OFF 3
H_Tsunemoto 0:47c1b6a0c166 111 #define P_TESTMode_Ntimes_ON 4
H_Tsunemoto 0:47c1b6a0c166 112 #define P_TESTMode_Ntimes_ONOFF 5
H_Tsunemoto 0:47c1b6a0c166 113
H_Tsunemoto 0:47c1b6a0c166 114 unsigned int ui_PulseTestMode = P_TESTMode_Nop; // Pulse Test Mode
H_Tsunemoto 0:47c1b6a0c166 115
H_Tsunemoto 0:47c1b6a0c166 116 #define P_TESTSEQ_Nop 0 // Test Start
H_Tsunemoto 0:47c1b6a0c166 117 #define P_TESTSEQ_START 1 // Test Start
H_Tsunemoto 0:47c1b6a0c166 118 #define P_TESTSEQ_ON 2 // Test ON ONOFFCHeck P29 ON
H_Tsunemoto 0:47c1b6a0c166 119 #define P_TESTSEQ_OFF 3 // Test OFF ONOFFCHeck P29 OFF
H_Tsunemoto 0:47c1b6a0c166 120 #define P_TESTSEQ_End 4 // Test END
H_Tsunemoto 0:47c1b6a0c166 121 #define P_TESTSEQ_ONOFF_P30_ON 5 // Test ONOFFCHeck P30 ON
H_Tsunemoto 0:47c1b6a0c166 122 #define P_TESTSEQ_ONOFF_P30_OFF 6 // Test ONOFFCHeck P30 OFF
H_Tsunemoto 0:47c1b6a0c166 123
H_Tsunemoto 0:47c1b6a0c166 124 unsigned int ui_PulseTestSequence = P_TESTSEQ_Nop; // Sequence Status
H_Tsunemoto 0:47c1b6a0c166 125
H_Tsunemoto 0:47c1b6a0c166 126 unsigned int ui_Pulse_ON_Cnt = 0;
H_Tsunemoto 0:47c1b6a0c166 127 unsigned int ui_Pulse_Interval_Cnt = 0;
H_Tsunemoto 0:47c1b6a0c166 128 unsigned int ui_Pulse_Test_Cycle_Cnt = 0;
H_Tsunemoto 0:47c1b6a0c166 129 unsigned int ui_TestTimeCount =0;
H_Tsunemoto 0:47c1b6a0c166 130 unsigned int ui_PulseAfter_Count =0;
H_Tsunemoto 0:47c1b6a0c166 131 int i_PortP21_Stat =1;
H_Tsunemoto 0:47c1b6a0c166 132 int i_PortP21_Stat_New =0;
H_Tsunemoto 0:47c1b6a0c166 133 int i_PortP21_Stat_Ave[3] ={0,0,0};
H_Tsunemoto 0:47c1b6a0c166 134
H_Tsunemoto 0:47c1b6a0c166 135
H_Tsunemoto 0:47c1b6a0c166 136 unsigned int ui_Main_Serial_Delay = 0;
H_Tsunemoto 0:47c1b6a0c166 137 #define MAIN_TEST_STAT_NOP 0
H_Tsunemoto 0:47c1b6a0c166 138 #define MAIN_TEST_STAT_START 1
H_Tsunemoto 0:47c1b6a0c166 139 #define MAIN_TEST_STAT_END 2
H_Tsunemoto 0:47c1b6a0c166 140 #define MAIN_TEST_STAT_CNT 3
H_Tsunemoto 0:47c1b6a0c166 141 unsigned int ui_Main_Test_Status = MAIN_TEST_STAT_NOP;
H_Tsunemoto 0:47c1b6a0c166 142 char c_TEST_msg[32];
H_Tsunemoto 0:47c1b6a0c166 143
H_Tsunemoto 0:47c1b6a0c166 144
H_Tsunemoto 0:47c1b6a0c166 145 //void TIMER0_IRQHandler(void);
H_Tsunemoto 0:47c1b6a0c166 146 void timer0_init(void);
H_Tsunemoto 0:47c1b6a0c166 147 //--------- New Append Function ---------//
H_Tsunemoto 0:47c1b6a0c166 148
H_Tsunemoto 0:47c1b6a0c166 149 void Ser_Command_Input();
H_Tsunemoto 0:47c1b6a0c166 150 //////////////////////////////////////////////////////////////////////////////////
H_Tsunemoto 0:47c1b6a0c166 151 //------------ Command Check & Set Function ---------------------------------//
H_Tsunemoto 0:47c1b6a0c166 152 //------------ usec Short Pulse Test ---------------//
H_Tsunemoto 0:47c1b6a0c166 153 void com_Check_usecPulseA(int i_RecCharCount);
H_Tsunemoto 0:47c1b6a0c166 154 void com_Check_usecPulseUP1(int i_RecCharCount);
H_Tsunemoto 0:47c1b6a0c166 155 void com_Check_usecPulseUPN(int i_RecCharCount);
H_Tsunemoto 0:47c1b6a0c166 156 void com_Check_usecPulseB(int i_RecCharCount);
H_Tsunemoto 0:47c1b6a0c166 157 void com_Check_usecPulseUX1(int i_RecCharCount);
H_Tsunemoto 0:47c1b6a0c166 158 void com_Check_usecPulseUXN(int i_RecCharCount);
H_Tsunemoto 0:47c1b6a0c166 159 void com_Check_usecUPW(int i_RecCharCount);
H_Tsunemoto 0:47c1b6a0c166 160 void com_Check_usecUPI(int i_RecCharCount);
H_Tsunemoto 0:47c1b6a0c166 161 void com_Check_usecUPC(int i_RecCharCount);
H_Tsunemoto 0:47c1b6a0c166 162 //------------ msec Pulse Test (Normal)---------------//
H_Tsunemoto 0:47c1b6a0c166 163 //bool com_Check_msecPulseA(int i_RecCharCount);
H_Tsunemoto 0:47c1b6a0c166 164 void com_Check_msecPulseMP1(int i_RecCharCount);
H_Tsunemoto 0:47c1b6a0c166 165 void com_Check_msecPulseMPN(int i_RecCharCount);
H_Tsunemoto 0:47c1b6a0c166 166 //bool com_Check_msecPulseB(int i_RecCharCount);
H_Tsunemoto 0:47c1b6a0c166 167 void com_Check_msecPulseMX1(int i_RecCharCount);
H_Tsunemoto 0:47c1b6a0c166 168 void com_Check_msecPulseMXN(int i_RecCharCount);
H_Tsunemoto 0:47c1b6a0c166 169 void com_Check_msecPulseMTN(int i_RecCharCount);
H_Tsunemoto 0:47c1b6a0c166 170 void com_Check_msecPulseMTW(int i_RecCharCount);
H_Tsunemoto 0:47c1b6a0c166 171 void com_Check_msecMPW(int i_RecCharCount);
H_Tsunemoto 0:47c1b6a0c166 172 void com_Check_msecMPI(int i_RecCharCount);
H_Tsunemoto 0:47c1b6a0c166 173 void com_Check_msecMPC(int i_RecCharCount);
H_Tsunemoto 0:47c1b6a0c166 174 void com_Check_msecMPT(int i_RecCharCount);
H_Tsunemoto 0:47c1b6a0c166 175 //bool com_Check_usecPRC(int i_RecCharCount);
H_Tsunemoto 0:47c1b6a0c166 176 /// ADC No.1 "SMP 1000" ADC Sample Rate 2 - 1000 msec
H_Tsunemoto 0:47c1b6a0c166 177 bool com_Check_SMP(int i_RecCharCount);
H_Tsunemoto 0:47c1b6a0c166 178 /// ADC No.4 "START" ADC Sample Start
H_Tsunemoto 0:47c1b6a0c166 179 bool com_Check_START(int i_RecCharCount);
H_Tsunemoto 0:47c1b6a0c166 180 // ADC No.5 "STOP" ADC Sample Stop
H_Tsunemoto 0:47c1b6a0c166 181 bool com_Check_STOP(int i_RecCharCount);
H_Tsunemoto 0:47c1b6a0c166 182 // ADC No.6 // "STAT?"
H_Tsunemoto 0:47c1b6a0c166 183 void com_ADC_Table_Param_Send();
H_Tsunemoto 0:47c1b6a0c166 184 // ADC No.7 // "LED0" LED Ena
H_Tsunemoto 0:47c1b6a0c166 185 bool com_Check_LED(int i_RecCharCount);
H_Tsunemoto 0:47c1b6a0c166 186 //----------------------------------------------------------------//
H_Tsunemoto 0:47c1b6a0c166 187
H_Tsunemoto 0:47c1b6a0c166 188 // Circular buffers for serial TX and RX data - used by interrupt routines
H_Tsunemoto 0:47c1b6a0c166 189 const int ser_buffer_size = 255;
H_Tsunemoto 0:47c1b6a0c166 190 // might need to increase buffer size for high baud rates
H_Tsunemoto 0:47c1b6a0c166 191 char tx_buffer[ser_buffer_size];
H_Tsunemoto 0:47c1b6a0c166 192 char rx_buffer[ser_buffer_size];
H_Tsunemoto 0:47c1b6a0c166 193 // Circular buffer pointers
H_Tsunemoto 0:47c1b6a0c166 194 // volatile makes read-modify-write atomic
H_Tsunemoto 0:47c1b6a0c166 195 volatile int tx_in=0;
H_Tsunemoto 0:47c1b6a0c166 196 volatile int tx_out=0;
H_Tsunemoto 0:47c1b6a0c166 197 volatile int rx_in=0;
H_Tsunemoto 0:47c1b6a0c166 198 volatile int rx_out=0;
H_Tsunemoto 0:47c1b6a0c166 199 // Line buffers for sprintf and sscanf
H_Tsunemoto 0:47c1b6a0c166 200 char tx_line[80];
H_Tsunemoto 0:47c1b6a0c166 201 char rx_line[80];
H_Tsunemoto 0:47c1b6a0c166 202 //--- 2013.08.08 Tsunemoto ------//
H_Tsunemoto 0:47c1b6a0c166 203 //-- rx Data Cr Rec Counter
H_Tsunemoto 0:47c1b6a0c166 204 volatile int rx_cr_Rec = 0;
H_Tsunemoto 0:47c1b6a0c166 205 //
H_Tsunemoto 0:47c1b6a0c166 206
H_Tsunemoto 0:47c1b6a0c166 207 /////////////////////////////////////////////////////////////////
H_Tsunemoto 0:47c1b6a0c166 208 // <<<< Main Function >>>> //
H_Tsunemoto 0:47c1b6a0c166 209 /////////////////////////////////////////////////////////////////
H_Tsunemoto 0:47c1b6a0c166 210 // ---------------------------------------------------------------//
H_Tsunemoto 0:47c1b6a0c166 211 // main test program
H_Tsunemoto 0:47c1b6a0c166 212 int main() {
H_Tsunemoto 0:47c1b6a0c166 213 // Serial Speed Set
H_Tsunemoto 0:47c1b6a0c166 214 device.baud(115200);
H_Tsunemoto 0:47c1b6a0c166 215
H_Tsunemoto 0:47c1b6a0c166 216 // Setup a serial interrupt function to receive data
H_Tsunemoto 0:47c1b6a0c166 217 device.attach(&Rx_interrupt, Serial::RxIrq);
H_Tsunemoto 0:47c1b6a0c166 218 // Setup a serial interrupt function to transmit data
H_Tsunemoto 0:47c1b6a0c166 219 device.attach(&Tx_interrupt, Serial::TxIrq);
H_Tsunemoto 0:47c1b6a0c166 220 POut_P30_Pulse.write(0);
H_Tsunemoto 0:47c1b6a0c166 221 POut_P29_Pulse.write(0);
H_Tsunemoto 0:47c1b6a0c166 222
H_Tsunemoto 0:47c1b6a0c166 223 // Formatted IO test using send and receive serial interrupts
H_Tsunemoto 0:47c1b6a0c166 224 // Timer 0 Interrupt Initial Set //
H_Tsunemoto 0:47c1b6a0c166 225 timer0_init();
H_Tsunemoto 0:47c1b6a0c166 226 timer_count = 0;
H_Tsunemoto 0:47c1b6a0c166 227
H_Tsunemoto 0:47c1b6a0c166 228 //--- ADC Measurement Control Parameter Initial Set ---//
H_Tsunemoto 0:47c1b6a0c166 229 adc_param_init();
H_Tsunemoto 0:47c1b6a0c166 230 // PInp_P21 Port Status Initial Set
H_Tsunemoto 0:47c1b6a0c166 231 while (i_PortP21_Stat != i_PortP21_Stat_New)
H_Tsunemoto 0:47c1b6a0c166 232 {
H_Tsunemoto 0:47c1b6a0c166 233
H_Tsunemoto 0:47c1b6a0c166 234 i_PortP21_Stat_Ave[0] = i_PortP21_Stat_Ave[1];
H_Tsunemoto 0:47c1b6a0c166 235 i_PortP21_Stat_Ave[1] = i_PortP21_Stat_Ave[2];
H_Tsunemoto 0:47c1b6a0c166 236 i_PortP21_Stat_Ave[2] = PInp_P21_Port.read();
H_Tsunemoto 0:47c1b6a0c166 237 if((i_PortP21_Stat_Ave[0] == i_PortP21_Stat_Ave[1])
H_Tsunemoto 0:47c1b6a0c166 238 && (i_PortP21_Stat_Ave[0] == i_PortP21_Stat_Ave[2])){
H_Tsunemoto 0:47c1b6a0c166 239 i_PortP21_Stat_New = i_PortP21_Stat_Ave[0];
H_Tsunemoto 0:47c1b6a0c166 240 i_PortP21_Stat = i_PortP21_Stat_New;
H_Tsunemoto 0:47c1b6a0c166 241 }
H_Tsunemoto 0:47c1b6a0c166 242
H_Tsunemoto 0:47c1b6a0c166 243 }
H_Tsunemoto 0:47c1b6a0c166 244 //--- DAC Control Parameter Init --- //
H_Tsunemoto 0:47c1b6a0c166 245 // dac1_param_init();
H_Tsunemoto 0:47c1b6a0c166 246 // -- Main Loop -- //
H_Tsunemoto 0:47c1b6a0c166 247 while (1) {
H_Tsunemoto 0:47c1b6a0c166 248 if(i_LED_Active == Debug_LED_Active){
H_Tsunemoto 0:47c1b6a0c166 249 led3 = (led3+1) & 1;
H_Tsunemoto 0:47c1b6a0c166 250 }
H_Tsunemoto 0:47c1b6a0c166 251 if(st_p_test_mode_param.i_PulseTestEnable >0){
H_Tsunemoto 0:47c1b6a0c166 252 led4 =1;
H_Tsunemoto 0:47c1b6a0c166 253 i_PortP21_Stat_Ave[0] = i_PortP21_Stat_Ave[1];
H_Tsunemoto 0:47c1b6a0c166 254 i_PortP21_Stat_Ave[1] = i_PortP21_Stat_Ave[2];
H_Tsunemoto 0:47c1b6a0c166 255 i_PortP21_Stat_Ave[2] = PInp_P21_Port.read();
H_Tsunemoto 0:47c1b6a0c166 256 if((i_PortP21_Stat_Ave[0] == i_PortP21_Stat_Ave[1])
H_Tsunemoto 0:47c1b6a0c166 257 && (i_PortP21_Stat_Ave[0] == i_PortP21_Stat_Ave[2])){
H_Tsunemoto 0:47c1b6a0c166 258 i_PortP21_Stat_New = i_PortP21_Stat_Ave[0];
H_Tsunemoto 0:47c1b6a0c166 259 }
H_Tsunemoto 0:47c1b6a0c166 260 if((ui_Main_Serial_Delay == 0) && (tx_in == tx_out)){
H_Tsunemoto 0:47c1b6a0c166 261 if(i_PortP21_Stat != i_PortP21_Stat_New){
H_Tsunemoto 0:47c1b6a0c166 262 i_PortP21_Stat = i_PortP21_Stat_New;
H_Tsunemoto 0:47c1b6a0c166 263 // i_num = ( st_p_test_mode_param.st_p_test_mode_param.i_PulseTestEnable ) ;
H_Tsunemoto 0:47c1b6a0c166 264 sprintf(tx_line,"C:,%4d,P:,%4d,P21=,%1d\r\n"
H_Tsunemoto 0:47c1b6a0c166 265 ,ui_TestTimeCount,ui_PulseAfter_Count,i_PortP21_Stat);
H_Tsunemoto 0:47c1b6a0c166 266 send_line();
H_Tsunemoto 0:47c1b6a0c166 267 ui_Main_Serial_Delay=10; // Send Check 1.0msec Delay
H_Tsunemoto 0:47c1b6a0c166 268 }
H_Tsunemoto 0:47c1b6a0c166 269 if(ui_Main_Test_Status != MAIN_TEST_STAT_NOP){
H_Tsunemoto 0:47c1b6a0c166 270 ui_Main_Test_Status = MAIN_TEST_STAT_NOP;
H_Tsunemoto 0:47c1b6a0c166 271 if(c_TEST_msg[0] >0){
H_Tsunemoto 0:47c1b6a0c166 272 sprintf(tx_line,"%s\r\n",c_TEST_msg);
H_Tsunemoto 0:47c1b6a0c166 273 send_line();
H_Tsunemoto 0:47c1b6a0c166 274 // c_TEST_msg[0]=0;
H_Tsunemoto 0:47c1b6a0c166 275 }
H_Tsunemoto 0:47c1b6a0c166 276 ui_Main_Serial_Delay=10; // Send Check 1.0msec Delay
H_Tsunemoto 0:47c1b6a0c166 277 }
H_Tsunemoto 0:47c1b6a0c166 278 }
H_Tsunemoto 0:47c1b6a0c166 279 led4 =0;
H_Tsunemoto 0:47c1b6a0c166 280 }
H_Tsunemoto 0:47c1b6a0c166 281 // if (i_adc_ActiveMode_status != ActiveMode_ADC_Sample_Stop){
H_Tsunemoto 0:47c1b6a0c166 282
H_Tsunemoto 0:47c1b6a0c166 283 // ad_sample_send();// --- ADC Sample & Serial Data Out --- //
H_Tsunemoto 0:47c1b6a0c166 284 // }
H_Tsunemoto 0:47c1b6a0c166 285 if(rx_cr_Rec != 0){
H_Tsunemoto 0:47c1b6a0c166 286 Ser_Command_Input();
H_Tsunemoto 0:47c1b6a0c166 287 }
H_Tsunemoto 0:47c1b6a0c166 288 /* main_loop_count++;
H_Tsunemoto 0:47c1b6a0c166 289 if(main_loop_count>=100000){
H_Tsunemoto 0:47c1b6a0c166 290 led3 = (led3+1) & 1;
H_Tsunemoto 0:47c1b6a0c166 291 main_loop_count = 0;
H_Tsunemoto 0:47c1b6a0c166 292 }
H_Tsunemoto 0:47c1b6a0c166 293 */ /////////////////////////////////
H_Tsunemoto 0:47c1b6a0c166 294 }
H_Tsunemoto 0:47c1b6a0c166 295 }
H_Tsunemoto 0:47c1b6a0c166 296
H_Tsunemoto 0:47c1b6a0c166 297
H_Tsunemoto 0:47c1b6a0c166 298 //-------------------------------------------------------//
H_Tsunemoto 0:47c1b6a0c166 299 // ADC Measurement Parameter Initial Set //
H_Tsunemoto 0:47c1b6a0c166 300 // 2013.08.14 H.Tsunemoto
H_Tsunemoto 0:47c1b6a0c166 301 //typedef struct st_PulseW_param{
H_Tsunemoto 0:47c1b6a0c166 302 // int i_sample_interval; // DAC Output Pattern
H_Tsunemoto 0:47c1b6a0c166 303 // float f_trigger_level;
H_Tsunemoto 0:47c1b6a0c166 304 // unsigned short us_trigger_level; // (3.3f/1023) * f_trigger_level (Image)
H_Tsunemoto 0:47c1b6a0c166 305 // int i_pre_trig_point;
H_Tsunemoto 0:47c1b6a0c166 306 // int i_usec_Pulse_end_time;
H_Tsunemoto 0:47c1b6a0c166 307 //}ST_PulseW_PARAM;
H_Tsunemoto 0:47c1b6a0c166 308 //
H_Tsunemoto 0:47c1b6a0c166 309 //ST_PulseW_PARAM st_p_test_mode_param;
H_Tsunemoto 0:47c1b6a0c166 310 //-------------------------------------------------------//
H_Tsunemoto 0:47c1b6a0c166 311 void adc_param_init()
H_Tsunemoto 0:47c1b6a0c166 312 {
H_Tsunemoto 0:47c1b6a0c166 313 st_p_test_mode_param.i_sample_interval = const_PulseTest_Param_Default.i_sample_interval;
H_Tsunemoto 0:47c1b6a0c166 314
H_Tsunemoto 0:47c1b6a0c166 315 st_p_test_mode_param.i_usec_Pulse_width = const_PulseTest_Param_Default.i_usec_Pulse_width;
H_Tsunemoto 0:47c1b6a0c166 316 st_p_test_mode_param.i_usec_Pulse_Interval = const_PulseTest_Param_Default.i_usec_Pulse_Interval;
H_Tsunemoto 0:47c1b6a0c166 317 st_p_test_mode_param.i_usec_Pulse_RepCnt = const_PulseTest_Param_Default.i_usec_Pulse_RepCnt;
H_Tsunemoto 0:47c1b6a0c166 318
H_Tsunemoto 0:47c1b6a0c166 319 st_p_test_mode_param.i_msec_Pulse_width = const_PulseTest_Param_Default.i_msec_Pulse_width;
H_Tsunemoto 0:47c1b6a0c166 320 st_p_test_mode_param.i_msec_Pulse_Interval = const_PulseTest_Param_Default.i_msec_Pulse_Interval;
H_Tsunemoto 0:47c1b6a0c166 321 st_p_test_mode_param.i_msec_Pulse_RepCnt = const_PulseTest_Param_Default.i_msec_Pulse_RepCnt;
H_Tsunemoto 0:47c1b6a0c166 322 st_p_test_mode_param.i_msec_Pulse_OnOffWait = const_PulseTest_Param_Default.i_msec_Pulse_OnOffWait;
H_Tsunemoto 0:47c1b6a0c166 323 st_p_test_mode_param.i_PulseTestEnable = const_PulseTest_Param_Default.i_PulseTestEnable;
H_Tsunemoto 0:47c1b6a0c166 324
H_Tsunemoto 0:47c1b6a0c166 325 /*
H_Tsunemoto 0:47c1b6a0c166 326 int i_sample_interval; // DAC Output Pattern
H_Tsunemoto 0:47c1b6a0c166 327 int i_usec_Pulse_width;
H_Tsunemoto 0:47c1b6a0c166 328 int i_usec_Pulse_Interval;
H_Tsunemoto 0:47c1b6a0c166 329 int i_usec_Pulse_RepCnt;
H_Tsunemoto 0:47c1b6a0c166 330 int i_msec_Pulse_width;
H_Tsunemoto 0:47c1b6a0c166 331 int i_msec_Pulse_Interval;
H_Tsunemoto 0:47c1b6a0c166 332 int i_msec_Pulse_RepCnt;
H_Tsunemoto 0:47c1b6a0c166 333 int i_PulseTestEnable;
H_Tsunemoto 0:47c1b6a0c166 334 int i_msec_Pulse_OnOffWait;
H_Tsunemoto 0:47c1b6a0c166 335 int i_CH2_Range;
H_Tsunemoto 0:47c1b6a0c166 336
H_Tsunemoto 0:47c1b6a0c166 337 */
H_Tsunemoto 0:47c1b6a0c166 338 }
H_Tsunemoto 0:47c1b6a0c166 339 ///////////////////////////////////////////////////////////////////////////////////////////
H_Tsunemoto 0:47c1b6a0c166 340 ///////////////////////////////////////////////////////////////////////////////////////////
H_Tsunemoto 0:47c1b6a0c166 341 /////////////////////////////////////////////////////////
H_Tsunemoto 0:47c1b6a0c166 342 // --- 0.1msec Interrupt Timer Pulse Test Sequence --- //
H_Tsunemoto 0:47c1b6a0c166 343 // #define P_TESTMode_OFF 0
H_Tsunemoto 0:47c1b6a0c166 344 // #define P_TESTMode_1SHOT_OFF 1
H_Tsunemoto 0:47c1b6a0c166 345 // #define P_TESTMode_1SHOT_ON 2
H_Tsunemoto 0:47c1b6a0c166 346 // #define P_TESTMode_Ntimes_OFF 3
H_Tsunemoto 0:47c1b6a0c166 347 // #define P_TESTMode_Ntimes_ON 4
H_Tsunemoto 0:47c1b6a0c166 348 // unsigned int ui_PulseTestMode = P_TESTMode_OFF; // Pulse Test Mode
H_Tsunemoto 0:47c1b6a0c166 349 //
H_Tsunemoto 0:47c1b6a0c166 350 // #define P_TESTSEQ_Nop 0 // Test Start
H_Tsunemoto 0:47c1b6a0c166 351 // #define P_TESTSEQ_START 1 // Test Start
H_Tsunemoto 0:47c1b6a0c166 352 // #define P_TESTSEQ_ON 2 // Test Start
H_Tsunemoto 0:47c1b6a0c166 353 // #define P_TESTSEQ_OFF 3 // Test Start
H_Tsunemoto 0:47c1b6a0c166 354 // #define P_TESTSEQ_End 4 // Test Start
H_Tsunemoto 0:47c1b6a0c166 355 // unsigned int ui_PulseTestSequence = P_TESTSEQ_Nop; // Sequence Status
H_Tsunemoto 0:47c1b6a0c166 356 // unsigned int ui_Pulse_ON_Cnt = 0;
H_Tsunemoto 0:47c1b6a0c166 357 // unsigned int ui_Pulse_Interval_Cnt = 0;
H_Tsunemoto 0:47c1b6a0c166 358 // unsigned int ui_Pulse_Test_Cycle_Cnt = 0;
H_Tsunemoto 0:47c1b6a0c166 359 /////////////////////////////////////////////////////////
H_Tsunemoto 0:47c1b6a0c166 360 void PulseTestSequence(void)
H_Tsunemoto 0:47c1b6a0c166 361 {
H_Tsunemoto 0:47c1b6a0c166 362 /////////////////////////////////////////////////////////
H_Tsunemoto 0:47c1b6a0c166 363 ////////// ------------------------- //////////////
H_Tsunemoto 0:47c1b6a0c166 364 ////////// Pulse Test Sequence //////////////
H_Tsunemoto 0:47c1b6a0c166 365 ////////// ------------------------- //////////////
H_Tsunemoto 0:47c1b6a0c166 366 /////////////////////////////////////////////////////////
H_Tsunemoto 0:47c1b6a0c166 367 switch (ui_PulseTestMode){
H_Tsunemoto 0:47c1b6a0c166 368 case P_TESTMode_Nop:
H_Tsunemoto 0:47c1b6a0c166 369 break;
H_Tsunemoto 0:47c1b6a0c166 370 /////////////////////////////////////////////////////////
H_Tsunemoto 0:47c1b6a0c166 371 ////////// -------------------------- //////////////
H_Tsunemoto 0:47c1b6a0c166 372 ////////// -- XRay OFF 1Shot -- //////////////
H_Tsunemoto 0:47c1b6a0c166 373 ////////// -------------------------- //////////////
H_Tsunemoto 0:47c1b6a0c166 374 /////////////////////////////////////////////////////////
H_Tsunemoto 0:47c1b6a0c166 375 case P_TESTMode_1SHOT_OFF:
H_Tsunemoto 0:47c1b6a0c166 376 // ----------- X ray OFF 1Shot Test ----------//
H_Tsunemoto 0:47c1b6a0c166 377 switch (ui_PulseTestSequence){
H_Tsunemoto 0:47c1b6a0c166 378 case P_TESTSEQ_Nop:
H_Tsunemoto 0:47c1b6a0c166 379 break;
H_Tsunemoto 0:47c1b6a0c166 380 case P_TESTSEQ_START:
H_Tsunemoto 0:47c1b6a0c166 381 // sprintf(c_TEST_msg,"START,P30,P1Shot\n");
H_Tsunemoto 0:47c1b6a0c166 382 // ui_Main_Test_Status = MAIN_TEST_STAT_START;
H_Tsunemoto 0:47c1b6a0c166 383 POut_P30_Pulse.write(1);
H_Tsunemoto 0:47c1b6a0c166 384 // i_PortP21_Stat = PInp_P21_Port.read();
H_Tsunemoto 0:47c1b6a0c166 385 ui_PulseAfter_Count =0;
H_Tsunemoto 0:47c1b6a0c166 386 ui_TestTimeCount=1;
H_Tsunemoto 0:47c1b6a0c166 387 ui_PulseTestSequence = P_TESTSEQ_ON;
H_Tsunemoto 0:47c1b6a0c166 388 ui_Pulse_ON_Cnt = st_p_test_mode_param.i_msec_Pulse_width;
H_Tsunemoto 0:47c1b6a0c166 389 break;
H_Tsunemoto 0:47c1b6a0c166 390 case P_TESTSEQ_ON:
H_Tsunemoto 0:47c1b6a0c166 391 if(ui_Pulse_ON_Cnt >0){
H_Tsunemoto 0:47c1b6a0c166 392 ui_Pulse_ON_Cnt--;
H_Tsunemoto 0:47c1b6a0c166 393 }
H_Tsunemoto 0:47c1b6a0c166 394 else{
H_Tsunemoto 0:47c1b6a0c166 395 POut_P30_Pulse.write(0);
H_Tsunemoto 0:47c1b6a0c166 396 ui_PulseTestSequence = P_TESTSEQ_End;
H_Tsunemoto 0:47c1b6a0c166 397 sprintf(c_TEST_msg,"END,P30,P1Shot\n");
H_Tsunemoto 0:47c1b6a0c166 398 ui_Main_Test_Status = MAIN_TEST_STAT_END;
H_Tsunemoto 0:47c1b6a0c166 399 }
H_Tsunemoto 0:47c1b6a0c166 400 break;
H_Tsunemoto 0:47c1b6a0c166 401 case P_TESTSEQ_End:
H_Tsunemoto 0:47c1b6a0c166 402 break;
H_Tsunemoto 0:47c1b6a0c166 403 default:
H_Tsunemoto 0:47c1b6a0c166 404 break;
H_Tsunemoto 0:47c1b6a0c166 405 }
H_Tsunemoto 0:47c1b6a0c166 406 //--------------------------------------------------//
H_Tsunemoto 0:47c1b6a0c166 407 break;
H_Tsunemoto 0:47c1b6a0c166 408 /////////////////////////////////////////////////////////
H_Tsunemoto 0:47c1b6a0c166 409 ////////// -------------------------- //////////////
H_Tsunemoto 0:47c1b6a0c166 410 ////////// -- XRay ON(P29) 1Shot -- //////////////
H_Tsunemoto 0:47c1b6a0c166 411 ////////// -------------------------- //////////////
H_Tsunemoto 0:47c1b6a0c166 412 /////////////////////////////////////////////////////////
H_Tsunemoto 0:47c1b6a0c166 413 case P_TESTMode_1SHOT_ON:
H_Tsunemoto 0:47c1b6a0c166 414 // ----------- X ray OFF 1Shot Test ----------//
H_Tsunemoto 0:47c1b6a0c166 415 switch (ui_PulseTestSequence){
H_Tsunemoto 0:47c1b6a0c166 416 case P_TESTSEQ_Nop:
H_Tsunemoto 0:47c1b6a0c166 417 break;
H_Tsunemoto 0:47c1b6a0c166 418 case P_TESTSEQ_START:
H_Tsunemoto 0:47c1b6a0c166 419 // sprintf(c_TEST_msg,"START,P29,P1Shot\n");
H_Tsunemoto 0:47c1b6a0c166 420 // ui_Main_Test_Status = MAIN_TEST_STAT_START;
H_Tsunemoto 0:47c1b6a0c166 421 POut_P29_Pulse.write(1);
H_Tsunemoto 0:47c1b6a0c166 422 // i_PortP21_Stat = PInp_P21_Port.read();
H_Tsunemoto 0:47c1b6a0c166 423 ui_PulseAfter_Count =0;
H_Tsunemoto 0:47c1b6a0c166 424 ui_TestTimeCount++;
H_Tsunemoto 0:47c1b6a0c166 425
H_Tsunemoto 0:47c1b6a0c166 426 ui_PulseTestSequence = P_TESTSEQ_ON;
H_Tsunemoto 0:47c1b6a0c166 427 ui_Pulse_ON_Cnt = st_p_test_mode_param.i_msec_Pulse_width;
H_Tsunemoto 0:47c1b6a0c166 428 break;
H_Tsunemoto 0:47c1b6a0c166 429 case P_TESTSEQ_ON:
H_Tsunemoto 0:47c1b6a0c166 430 if(ui_Pulse_ON_Cnt >0){
H_Tsunemoto 0:47c1b6a0c166 431 ui_Pulse_ON_Cnt--;
H_Tsunemoto 0:47c1b6a0c166 432 }
H_Tsunemoto 0:47c1b6a0c166 433 else{
H_Tsunemoto 0:47c1b6a0c166 434 POut_P29_Pulse.write(0);
H_Tsunemoto 0:47c1b6a0c166 435 ui_PulseTestSequence = P_TESTSEQ_End;
H_Tsunemoto 0:47c1b6a0c166 436 sprintf(c_TEST_msg,"END,P29,P1Shot\n");
H_Tsunemoto 0:47c1b6a0c166 437 ui_Main_Test_Status = MAIN_TEST_STAT_END;
H_Tsunemoto 0:47c1b6a0c166 438 }
H_Tsunemoto 0:47c1b6a0c166 439 break;
H_Tsunemoto 0:47c1b6a0c166 440 case P_TESTSEQ_End:
H_Tsunemoto 0:47c1b6a0c166 441 break;
H_Tsunemoto 0:47c1b6a0c166 442 default:
H_Tsunemoto 0:47c1b6a0c166 443 break;
H_Tsunemoto 0:47c1b6a0c166 444 }
H_Tsunemoto 0:47c1b6a0c166 445 //--------------------------------------------------//
H_Tsunemoto 0:47c1b6a0c166 446 break;
H_Tsunemoto 0:47c1b6a0c166 447 /////////////////////////////////////////////////////////
H_Tsunemoto 0:47c1b6a0c166 448 ////////// -------------------------------------- //////////////
H_Tsunemoto 0:47c1b6a0c166 449 ////////// -- XRay OFF(P30) N Times Test -- //////////////
H_Tsunemoto 0:47c1b6a0c166 450 ////////// -------------------------------------- //////////////
H_Tsunemoto 0:47c1b6a0c166 451 /////////////////////////////////////////////////////////
H_Tsunemoto 0:47c1b6a0c166 452 case P_TESTMode_Ntimes_OFF:
H_Tsunemoto 0:47c1b6a0c166 453 // ----------- X ray OFF Cycle N Test ----------//
H_Tsunemoto 0:47c1b6a0c166 454 switch (ui_PulseTestSequence){
H_Tsunemoto 0:47c1b6a0c166 455 case P_TESTSEQ_Nop:
H_Tsunemoto 0:47c1b6a0c166 456 break;
H_Tsunemoto 0:47c1b6a0c166 457 case P_TESTSEQ_START:
H_Tsunemoto 0:47c1b6a0c166 458 // sprintf(c_TEST_msg,"START,P30,PN:,%4d,Times\n",st_p_test_mode_param.i_msec_Pulse_RepCnt);
H_Tsunemoto 0:47c1b6a0c166 459 // ui_Main_Test_Status = MAIN_TEST_STAT_START;
H_Tsunemoto 0:47c1b6a0c166 460 ui_TestTimeCount=1;
H_Tsunemoto 0:47c1b6a0c166 461 sprintf(c_TEST_msg,"TEST_N,%4d,OFF\n",ui_TestTimeCount);
H_Tsunemoto 0:47c1b6a0c166 462 ui_Main_Test_Status = MAIN_TEST_STAT_CNT;
H_Tsunemoto 0:47c1b6a0c166 463 POut_P30_Pulse.write(1);
H_Tsunemoto 0:47c1b6a0c166 464 // i_PortP21_Stat = PInp_P21_Port.read();
H_Tsunemoto 0:47c1b6a0c166 465 ui_PulseAfter_Count =0;
H_Tsunemoto 0:47c1b6a0c166 466 ui_PulseTestSequence = P_TESTSEQ_ON;
H_Tsunemoto 0:47c1b6a0c166 467 ui_Pulse_ON_Cnt = st_p_test_mode_param.i_msec_Pulse_width;
H_Tsunemoto 0:47c1b6a0c166 468 if(st_p_test_mode_param.i_msec_Pulse_RepCnt > 0){
H_Tsunemoto 0:47c1b6a0c166 469 ui_Pulse_Test_Cycle_Cnt = st_p_test_mode_param.i_msec_Pulse_RepCnt-1;
H_Tsunemoto 0:47c1b6a0c166 470 }
H_Tsunemoto 0:47c1b6a0c166 471 else{
H_Tsunemoto 0:47c1b6a0c166 472 ui_Pulse_Test_Cycle_Cnt = 0;
H_Tsunemoto 0:47c1b6a0c166 473 }
H_Tsunemoto 0:47c1b6a0c166 474 break;
H_Tsunemoto 0:47c1b6a0c166 475 case P_TESTSEQ_ON:
H_Tsunemoto 0:47c1b6a0c166 476 if(ui_Pulse_ON_Cnt >0){
H_Tsunemoto 0:47c1b6a0c166 477 ui_Pulse_ON_Cnt--;
H_Tsunemoto 0:47c1b6a0c166 478 }
H_Tsunemoto 0:47c1b6a0c166 479 else{
H_Tsunemoto 0:47c1b6a0c166 480 POut_P30_Pulse.write(0);
H_Tsunemoto 0:47c1b6a0c166 481
H_Tsunemoto 0:47c1b6a0c166 482 if(ui_Pulse_Test_Cycle_Cnt >0){
H_Tsunemoto 0:47c1b6a0c166 483 ui_Pulse_Test_Cycle_Cnt--;
H_Tsunemoto 0:47c1b6a0c166 484 ui_Pulse_Interval_Cnt = st_p_test_mode_param.i_msec_Pulse_Interval;
H_Tsunemoto 0:47c1b6a0c166 485 ui_PulseTestSequence = P_TESTSEQ_OFF;
H_Tsunemoto 0:47c1b6a0c166 486 }
H_Tsunemoto 0:47c1b6a0c166 487 else{
H_Tsunemoto 0:47c1b6a0c166 488 ui_PulseTestSequence = P_TESTSEQ_End;
H_Tsunemoto 0:47c1b6a0c166 489 sprintf(c_TEST_msg,"END,P30,PN:\n");
H_Tsunemoto 0:47c1b6a0c166 490 ui_Main_Test_Status = MAIN_TEST_STAT_END;
H_Tsunemoto 0:47c1b6a0c166 491 }
H_Tsunemoto 0:47c1b6a0c166 492 }
H_Tsunemoto 0:47c1b6a0c166 493 break;
H_Tsunemoto 0:47c1b6a0c166 494 case P_TESTSEQ_OFF:
H_Tsunemoto 0:47c1b6a0c166 495 if(ui_Pulse_Interval_Cnt >0){
H_Tsunemoto 0:47c1b6a0c166 496 ui_Pulse_Interval_Cnt--;
H_Tsunemoto 0:47c1b6a0c166 497 }
H_Tsunemoto 0:47c1b6a0c166 498 else{
H_Tsunemoto 0:47c1b6a0c166 499 ui_TestTimeCount++;
H_Tsunemoto 0:47c1b6a0c166 500 sprintf(c_TEST_msg,"TEST_N,%4d,OFF\n",ui_TestTimeCount);
H_Tsunemoto 0:47c1b6a0c166 501 ui_Main_Test_Status = MAIN_TEST_STAT_CNT;
H_Tsunemoto 0:47c1b6a0c166 502 POut_P30_Pulse.write(1);
H_Tsunemoto 0:47c1b6a0c166 503 // i_PortP21_Stat = PInp_P21_Port.read();
H_Tsunemoto 0:47c1b6a0c166 504 ui_PulseAfter_Count =0;
H_Tsunemoto 0:47c1b6a0c166 505 ui_Pulse_ON_Cnt = st_p_test_mode_param.i_msec_Pulse_width;
H_Tsunemoto 0:47c1b6a0c166 506 ui_PulseTestSequence = P_TESTSEQ_ON;
H_Tsunemoto 0:47c1b6a0c166 507 }
H_Tsunemoto 0:47c1b6a0c166 508 break;
H_Tsunemoto 0:47c1b6a0c166 509 case P_TESTSEQ_End:
H_Tsunemoto 0:47c1b6a0c166 510 break;
H_Tsunemoto 0:47c1b6a0c166 511 default:
H_Tsunemoto 0:47c1b6a0c166 512 break;
H_Tsunemoto 0:47c1b6a0c166 513 }
H_Tsunemoto 0:47c1b6a0c166 514 //--------------------------------------------------//
H_Tsunemoto 0:47c1b6a0c166 515 break;
H_Tsunemoto 0:47c1b6a0c166 516 /////////////////////////////////////////////////////////
H_Tsunemoto 0:47c1b6a0c166 517 ////////// -------------------------------------- //////////////
H_Tsunemoto 0:47c1b6a0c166 518 ////////// -- XRay ON(P29) N Times Test -- //////////////
H_Tsunemoto 0:47c1b6a0c166 519 ////////// -------------------------------------- //////////////
H_Tsunemoto 0:47c1b6a0c166 520 /////////////////////////////////////////////////////////
H_Tsunemoto 0:47c1b6a0c166 521 case P_TESTMode_Ntimes_ON:
H_Tsunemoto 0:47c1b6a0c166 522 // ----------- X ray OFF Cycle N Test ----------//
H_Tsunemoto 0:47c1b6a0c166 523 switch (ui_PulseTestSequence){
H_Tsunemoto 0:47c1b6a0c166 524 case P_TESTSEQ_Nop:
H_Tsunemoto 0:47c1b6a0c166 525 break;
H_Tsunemoto 0:47c1b6a0c166 526 case P_TESTSEQ_START:
H_Tsunemoto 0:47c1b6a0c166 527 ui_TestTimeCount=1;
H_Tsunemoto 0:47c1b6a0c166 528 sprintf(c_TEST_msg,"TEST_N,%4d,ON\n",ui_TestTimeCount);
H_Tsunemoto 0:47c1b6a0c166 529 ui_Main_Test_Status = MAIN_TEST_STAT_CNT;
H_Tsunemoto 0:47c1b6a0c166 530 // sprintf(c_TEST_msg,"START,P29,PN:,%4d,Times\n",st_p_test_mode_param.i_msec_Pulse_RepCnt);
H_Tsunemoto 0:47c1b6a0c166 531 // ui_Main_Test_Status = MAIN_TEST_STAT_START;
H_Tsunemoto 0:47c1b6a0c166 532 POut_P29_Pulse.write(1);
H_Tsunemoto 0:47c1b6a0c166 533 // i_PortP21_Stat = PInp_P21_Port.read();
H_Tsunemoto 0:47c1b6a0c166 534 ui_PulseAfter_Count =0;
H_Tsunemoto 0:47c1b6a0c166 535 ui_PulseTestSequence = P_TESTSEQ_ON;
H_Tsunemoto 0:47c1b6a0c166 536 ui_Pulse_ON_Cnt = st_p_test_mode_param.i_msec_Pulse_width;
H_Tsunemoto 0:47c1b6a0c166 537 if(st_p_test_mode_param.i_msec_Pulse_RepCnt > 0){
H_Tsunemoto 0:47c1b6a0c166 538 ui_Pulse_Test_Cycle_Cnt = st_p_test_mode_param.i_msec_Pulse_RepCnt-1;
H_Tsunemoto 0:47c1b6a0c166 539 }
H_Tsunemoto 0:47c1b6a0c166 540 else{
H_Tsunemoto 0:47c1b6a0c166 541 ui_Pulse_Test_Cycle_Cnt = 0;
H_Tsunemoto 0:47c1b6a0c166 542 }
H_Tsunemoto 0:47c1b6a0c166 543 break;
H_Tsunemoto 0:47c1b6a0c166 544 case P_TESTSEQ_ON:
H_Tsunemoto 0:47c1b6a0c166 545 if(ui_Pulse_ON_Cnt >0){
H_Tsunemoto 0:47c1b6a0c166 546 ui_Pulse_ON_Cnt--;
H_Tsunemoto 0:47c1b6a0c166 547 }
H_Tsunemoto 0:47c1b6a0c166 548 else{
H_Tsunemoto 0:47c1b6a0c166 549 POut_P29_Pulse.write(0);
H_Tsunemoto 0:47c1b6a0c166 550 // ui_TestTimeCount++;
H_Tsunemoto 0:47c1b6a0c166 551 if(ui_Pulse_Test_Cycle_Cnt >0){
H_Tsunemoto 0:47c1b6a0c166 552 ui_Pulse_Test_Cycle_Cnt--;
H_Tsunemoto 0:47c1b6a0c166 553 ui_Pulse_Interval_Cnt = st_p_test_mode_param.i_msec_Pulse_Interval;
H_Tsunemoto 0:47c1b6a0c166 554 ui_PulseTestSequence = P_TESTSEQ_OFF;
H_Tsunemoto 0:47c1b6a0c166 555 }
H_Tsunemoto 0:47c1b6a0c166 556 else{
H_Tsunemoto 0:47c1b6a0c166 557 ui_PulseTestSequence = P_TESTSEQ_End;
H_Tsunemoto 0:47c1b6a0c166 558 sprintf(c_TEST_msg,"END,P29,PN:\n");
H_Tsunemoto 0:47c1b6a0c166 559 ui_Main_Test_Status = MAIN_TEST_STAT_END;
H_Tsunemoto 0:47c1b6a0c166 560 }
H_Tsunemoto 0:47c1b6a0c166 561 }
H_Tsunemoto 0:47c1b6a0c166 562 break;
H_Tsunemoto 0:47c1b6a0c166 563 case P_TESTSEQ_OFF:
H_Tsunemoto 0:47c1b6a0c166 564 if(ui_Pulse_Interval_Cnt >0){
H_Tsunemoto 0:47c1b6a0c166 565 ui_Pulse_Interval_Cnt--;
H_Tsunemoto 0:47c1b6a0c166 566 }
H_Tsunemoto 0:47c1b6a0c166 567 else{
H_Tsunemoto 0:47c1b6a0c166 568 ui_TestTimeCount++;
H_Tsunemoto 0:47c1b6a0c166 569 sprintf(c_TEST_msg,"TEST_N,%4d,ON\n",ui_TestTimeCount);
H_Tsunemoto 0:47c1b6a0c166 570 ui_Main_Test_Status = MAIN_TEST_STAT_CNT;
H_Tsunemoto 0:47c1b6a0c166 571 POut_P29_Pulse.write(1);
H_Tsunemoto 0:47c1b6a0c166 572 // i_PortP21_Stat = PInp_P21_Port.read();
H_Tsunemoto 0:47c1b6a0c166 573 ui_PulseAfter_Count =0;
H_Tsunemoto 0:47c1b6a0c166 574 ui_Pulse_ON_Cnt = st_p_test_mode_param.i_msec_Pulse_width;
H_Tsunemoto 0:47c1b6a0c166 575 ui_PulseTestSequence = P_TESTSEQ_ON;
H_Tsunemoto 0:47c1b6a0c166 576 }
H_Tsunemoto 0:47c1b6a0c166 577 break;
H_Tsunemoto 0:47c1b6a0c166 578 case P_TESTSEQ_End:
H_Tsunemoto 0:47c1b6a0c166 579 break;
H_Tsunemoto 0:47c1b6a0c166 580 default:
H_Tsunemoto 0:47c1b6a0c166 581 break;
H_Tsunemoto 0:47c1b6a0c166 582 }
H_Tsunemoto 0:47c1b6a0c166 583 //--------------------------------------------------//
H_Tsunemoto 0:47c1b6a0c166 584 break;
H_Tsunemoto 0:47c1b6a0c166 585 ////////////////////////////////////////////////////////////////////////////////
H_Tsunemoto 0:47c1b6a0c166 586 ////////// ------------------------------------------------ //////////////
H_Tsunemoto 0:47c1b6a0c166 587 ////////// -- XRay ON/OFF (P29 & P30) N Times Test -- //////////////
H_Tsunemoto 0:47c1b6a0c166 588 ////////// ------------------------------------------------ //////////////
H_Tsunemoto 0:47c1b6a0c166 589 ////////////////////////////////////////////////////////////////////////////////
H_Tsunemoto 0:47c1b6a0c166 590 case P_TESTMode_Ntimes_ONOFF:
H_Tsunemoto 0:47c1b6a0c166 591 // ----------- X ray OFF Cycle N Test ----------//
H_Tsunemoto 0:47c1b6a0c166 592 switch (ui_PulseTestSequence){
H_Tsunemoto 0:47c1b6a0c166 593 case P_TESTSEQ_Nop:
H_Tsunemoto 0:47c1b6a0c166 594 break;
H_Tsunemoto 0:47c1b6a0c166 595 case P_TESTSEQ_START:
H_Tsunemoto 0:47c1b6a0c166 596 // sprintf(c_TEST_msg,"START,ONOFF_P29_30,PN:,%4d,Times\n",st_p_test_mode_param.i_msec_Pulse_RepCnt);
H_Tsunemoto 0:47c1b6a0c166 597 // ui_Main_Test_Status = MAIN_TEST_STAT_START;
H_Tsunemoto 0:47c1b6a0c166 598 ui_TestTimeCount=1;
H_Tsunemoto 0:47c1b6a0c166 599 sprintf(c_TEST_msg,"TEST_N,%4d,ON\n",ui_TestTimeCount);
H_Tsunemoto 0:47c1b6a0c166 600 ui_Main_Test_Status = MAIN_TEST_STAT_CNT;
H_Tsunemoto 0:47c1b6a0c166 601 POut_P29_Pulse.write(1);
H_Tsunemoto 0:47c1b6a0c166 602 // i_PortP21_Stat = PInp_P21_Port.read();
H_Tsunemoto 0:47c1b6a0c166 603 ui_PulseAfter_Count =0;
H_Tsunemoto 0:47c1b6a0c166 604 ui_PulseTestSequence = P_TESTSEQ_ON;
H_Tsunemoto 0:47c1b6a0c166 605 ui_Pulse_ON_Cnt = st_p_test_mode_param.i_msec_Pulse_width;
H_Tsunemoto 0:47c1b6a0c166 606 if(st_p_test_mode_param.i_msec_Pulse_RepCnt > 0){
H_Tsunemoto 0:47c1b6a0c166 607 ui_Pulse_Test_Cycle_Cnt = st_p_test_mode_param.i_msec_Pulse_RepCnt-1;
H_Tsunemoto 0:47c1b6a0c166 608 }
H_Tsunemoto 0:47c1b6a0c166 609 else{
H_Tsunemoto 0:47c1b6a0c166 610 ui_Pulse_Test_Cycle_Cnt = 0;
H_Tsunemoto 0:47c1b6a0c166 611 }
H_Tsunemoto 0:47c1b6a0c166 612 break;
H_Tsunemoto 0:47c1b6a0c166 613 case P_TESTSEQ_ON:
H_Tsunemoto 0:47c1b6a0c166 614 if(ui_Pulse_ON_Cnt >0){
H_Tsunemoto 0:47c1b6a0c166 615 ui_Pulse_ON_Cnt--;
H_Tsunemoto 0:47c1b6a0c166 616 }
H_Tsunemoto 0:47c1b6a0c166 617 else{
H_Tsunemoto 0:47c1b6a0c166 618 POut_P29_Pulse.write(0);
H_Tsunemoto 0:47c1b6a0c166 619 ui_Pulse_Interval_Cnt = st_p_test_mode_param.i_msec_Pulse_Interval;
H_Tsunemoto 0:47c1b6a0c166 620 ui_PulseTestSequence = P_TESTSEQ_OFF;
H_Tsunemoto 0:47c1b6a0c166 621 }
H_Tsunemoto 0:47c1b6a0c166 622 break;
H_Tsunemoto 0:47c1b6a0c166 623 case P_TESTSEQ_OFF:
H_Tsunemoto 0:47c1b6a0c166 624 if(ui_Pulse_Interval_Cnt >0){
H_Tsunemoto 0:47c1b6a0c166 625 ui_Pulse_Interval_Cnt--;
H_Tsunemoto 0:47c1b6a0c166 626 }
H_Tsunemoto 0:47c1b6a0c166 627 else{
H_Tsunemoto 0:47c1b6a0c166 628 sprintf(c_TEST_msg,"TEST_N,%4d,OFF\n",ui_TestTimeCount);
H_Tsunemoto 0:47c1b6a0c166 629 ui_Main_Test_Status = MAIN_TEST_STAT_CNT;
H_Tsunemoto 0:47c1b6a0c166 630 POut_P30_Pulse.write(1);
H_Tsunemoto 0:47c1b6a0c166 631 // i_PortP21_Stat = PInp_P21_Port.read();
H_Tsunemoto 0:47c1b6a0c166 632 ui_PulseAfter_Count =0;
H_Tsunemoto 0:47c1b6a0c166 633 ui_Pulse_ON_Cnt = st_p_test_mode_param.i_msec_Pulse_width;
H_Tsunemoto 0:47c1b6a0c166 634 ui_PulseTestSequence = P_TESTSEQ_ONOFF_P30_ON;
H_Tsunemoto 0:47c1b6a0c166 635 }
H_Tsunemoto 0:47c1b6a0c166 636 break;
H_Tsunemoto 0:47c1b6a0c166 637 case P_TESTSEQ_ONOFF_P30_ON:
H_Tsunemoto 0:47c1b6a0c166 638 if(ui_Pulse_ON_Cnt >0){
H_Tsunemoto 0:47c1b6a0c166 639 ui_Pulse_ON_Cnt--;
H_Tsunemoto 0:47c1b6a0c166 640 }
H_Tsunemoto 0:47c1b6a0c166 641 else{
H_Tsunemoto 0:47c1b6a0c166 642 POut_P30_Pulse.write(0);
H_Tsunemoto 0:47c1b6a0c166 643
H_Tsunemoto 0:47c1b6a0c166 644 // ui_TestTimeCount++;
H_Tsunemoto 0:47c1b6a0c166 645 if(ui_Pulse_Test_Cycle_Cnt >0){
H_Tsunemoto 0:47c1b6a0c166 646 ui_Pulse_Test_Cycle_Cnt--;
H_Tsunemoto 0:47c1b6a0c166 647 ui_Pulse_Interval_Cnt = st_p_test_mode_param.i_msec_Pulse_OnOffWait;
H_Tsunemoto 0:47c1b6a0c166 648 ui_PulseTestSequence = P_TESTSEQ_ONOFF_P30_OFF;
H_Tsunemoto 0:47c1b6a0c166 649 }
H_Tsunemoto 0:47c1b6a0c166 650 else{
H_Tsunemoto 0:47c1b6a0c166 651 ui_PulseTestSequence = P_TESTSEQ_End;
H_Tsunemoto 0:47c1b6a0c166 652 sprintf(c_TEST_msg,"END,ONOFF_P29_30:\n");
H_Tsunemoto 0:47c1b6a0c166 653 ui_Main_Test_Status = MAIN_TEST_STAT_END;
H_Tsunemoto 0:47c1b6a0c166 654 }
H_Tsunemoto 0:47c1b6a0c166 655 }
H_Tsunemoto 0:47c1b6a0c166 656 break;
H_Tsunemoto 0:47c1b6a0c166 657 case P_TESTSEQ_ONOFF_P30_OFF:
H_Tsunemoto 0:47c1b6a0c166 658 if(ui_Pulse_Interval_Cnt >0){
H_Tsunemoto 0:47c1b6a0c166 659 ui_Pulse_Interval_Cnt--;
H_Tsunemoto 0:47c1b6a0c166 660 }
H_Tsunemoto 0:47c1b6a0c166 661 else{
H_Tsunemoto 0:47c1b6a0c166 662 ui_TestTimeCount++;
H_Tsunemoto 0:47c1b6a0c166 663 sprintf(c_TEST_msg,"TEST_N,%4d,ON\n",ui_TestTimeCount);
H_Tsunemoto 0:47c1b6a0c166 664 ui_Main_Test_Status = MAIN_TEST_STAT_CNT;
H_Tsunemoto 0:47c1b6a0c166 665 POut_P29_Pulse.write(1);
H_Tsunemoto 0:47c1b6a0c166 666 // i_PortP21_Stat = PInp_P21_Port.read();
H_Tsunemoto 0:47c1b6a0c166 667 ui_PulseAfter_Count =0;
H_Tsunemoto 0:47c1b6a0c166 668 ui_Pulse_ON_Cnt = st_p_test_mode_param.i_msec_Pulse_width;
H_Tsunemoto 0:47c1b6a0c166 669 ui_PulseTestSequence = P_TESTSEQ_ON;
H_Tsunemoto 0:47c1b6a0c166 670 }
H_Tsunemoto 0:47c1b6a0c166 671 break;
H_Tsunemoto 0:47c1b6a0c166 672 case P_TESTSEQ_End:
H_Tsunemoto 0:47c1b6a0c166 673 break;
H_Tsunemoto 0:47c1b6a0c166 674 default:
H_Tsunemoto 0:47c1b6a0c166 675 break;
H_Tsunemoto 0:47c1b6a0c166 676 }
H_Tsunemoto 0:47c1b6a0c166 677 //--------------------------------------------------//
H_Tsunemoto 0:47c1b6a0c166 678 break;
H_Tsunemoto 0:47c1b6a0c166 679 default: //
H_Tsunemoto 0:47c1b6a0c166 680 break;
H_Tsunemoto 0:47c1b6a0c166 681
H_Tsunemoto 0:47c1b6a0c166 682
H_Tsunemoto 0:47c1b6a0c166 683 }
H_Tsunemoto 0:47c1b6a0c166 684 }
H_Tsunemoto 0:47c1b6a0c166 685 //------------------------------------------------------------------------------//
H_Tsunemoto 0:47c1b6a0c166 686 //----- DAC Control Function
H_Tsunemoto 0:47c1b6a0c166 687 // H.Tsunemoto Scince 2013.08.09
H_Tsunemoto 0:47c1b6a0c166 688 // int i_pattern; // DAC Output Pattern
H_Tsunemoto 0:47c1b6a0c166 689 // float f_pulse_high;
H_Tsunemoto 0:47c1b6a0c166 690 // float f_pulse_low;
H_Tsunemoto 0:47c1b6a0c166 691 // int i_usec_Pulse_width;
H_Tsunemoto 0:47c1b6a0c166 692 // int i_usec_Pulse_interval;
H_Tsunemoto 0:47c1b6a0c166 693 // int i_Total_time;
H_Tsunemoto 0:47c1b6a0c166 694 //
H_Tsunemoto 0:47c1b6a0c166 695 //------------------------------------------------------------------------------//
H_Tsunemoto 0:47c1b6a0c166 696 //
H_Tsunemoto 0:47c1b6a0c166 697 //------------------------------------------------------------------------//
H_Tsunemoto 0:47c1b6a0c166 698 // Timer Interrupt Routine
H_Tsunemoto 0:47c1b6a0c166 699 //
H_Tsunemoto 0:47c1b6a0c166 700 //------------------------------------------------------------------------//
H_Tsunemoto 0:47c1b6a0c166 701 extern "C" void TIMER0_IRQHandler (void)
H_Tsunemoto 0:47c1b6a0c166 702 {
H_Tsunemoto 0:47c1b6a0c166 703 if((LPC_TIM0->IR & 0x01) == 0x01) // if MR0 interrupt, proceed
H_Tsunemoto 0:47c1b6a0c166 704 {
H_Tsunemoto 0:47c1b6a0c166 705 if(i_LED_Active == Debug_LED_Active){
H_Tsunemoto 0:47c1b6a0c166 706 led2 =1;
H_Tsunemoto 0:47c1b6a0c166 707 }
H_Tsunemoto 0:47c1b6a0c166 708 LPC_TIM0->IR |= 1 << 0; // Clear MR0 interrupt flag
H_Tsunemoto 0:47c1b6a0c166 709 timer_count++; //increment timer_count
H_Tsunemoto 0:47c1b6a0c166 710 if(timer_count >= 10000){
H_Tsunemoto 0:47c1b6a0c166 711 timer_count = 0;
H_Tsunemoto 0:47c1b6a0c166 712 timer_1Sec++;
H_Tsunemoto 0:47c1b6a0c166 713 }
H_Tsunemoto 0:47c1b6a0c166 714 if(ui_PulseTestMode != P_TESTMode_Nop){
H_Tsunemoto 0:47c1b6a0c166 715 ui_PulseAfter_Count ++;
H_Tsunemoto 0:47c1b6a0c166 716 PulseTestSequence();
H_Tsunemoto 0:47c1b6a0c166 717 if(ui_Main_Serial_Delay>0){
H_Tsunemoto 0:47c1b6a0c166 718 ui_Main_Serial_Delay--;
H_Tsunemoto 0:47c1b6a0c166 719 }
H_Tsunemoto 0:47c1b6a0c166 720 }
H_Tsunemoto 0:47c1b6a0c166 721 if(i_LED_Active == Debug_LED_Active){
H_Tsunemoto 0:47c1b6a0c166 722 led2 =0;
H_Tsunemoto 0:47c1b6a0c166 723 }
H_Tsunemoto 0:47c1b6a0c166 724 }
H_Tsunemoto 0:47c1b6a0c166 725 }
H_Tsunemoto 0:47c1b6a0c166 726
H_Tsunemoto 0:47c1b6a0c166 727 void timer0_init(void)
H_Tsunemoto 0:47c1b6a0c166 728 {
H_Tsunemoto 0:47c1b6a0c166 729 LPC_SC->PCONP |=1<1; //timer0 power on
H_Tsunemoto 0:47c1b6a0c166 730 // 2013.08.09 H.Tsunemoto 100mSec => 0.1mSec Change
H_Tsunemoto 0:47c1b6a0c166 731 //LPC_TIM0->MR0 = 2398000; //100 msec
H_Tsunemoto 0:47c1b6a0c166 732 LPC_TIM0->MR0 = 2398; //0.1 msec
H_Tsunemoto 0:47c1b6a0c166 733
H_Tsunemoto 0:47c1b6a0c166 734 LPC_TIM0->MCR = 3; //interrupt and reset control
H_Tsunemoto 0:47c1b6a0c166 735 //3 = Interrupt & reset timer0 on match
H_Tsunemoto 0:47c1b6a0c166 736 //1 = Interrupt only, no reset of timer0
H_Tsunemoto 0:47c1b6a0c166 737 NVIC_EnableIRQ(TIMER0_IRQn); //enable timer0 interrupt
H_Tsunemoto 0:47c1b6a0c166 738 LPC_TIM0->TCR = 1; //enable Timer0
H_Tsunemoto 0:47c1b6a0c166 739 // pc.printf("Done timer_init\n\r");
H_Tsunemoto 0:47c1b6a0c166 740 }
H_Tsunemoto 0:47c1b6a0c166 741
H_Tsunemoto 0:47c1b6a0c166 742 //------------------------------------------------------------------//
H_Tsunemoto 0:47c1b6a0c166 743 //----- Serial rx Commmand Input & Parameter Set Function -----//
H_Tsunemoto 0:47c1b6a0c166 744 // Tsunemoto Since 2016.05.20 //
H_Tsunemoto 0:47c1b6a0c166 745 // ADC No.1 "SMP 1000" ADC Sample Rate 2 - 1000 msec
H_Tsunemoto 0:47c1b6a0c166 746 // ADC No.2 "RNA 0" ADC CH1 Range 0 / 1
H_Tsunemoto 0:47c1b6a0c166 747 // ADC No.3 "RNB 1" ADC CH2 Range 0 / 1
H_Tsunemoto 0:47c1b6a0c166 748 // ADC No.4 "START" ADC Sample Start
H_Tsunemoto 0:47c1b6a0c166 749 // ADC No.5 "STOP" ADC Sample Stop
H_Tsunemoto 0:47c1b6a0c166 750 // ADC No.6 // "?"
H_Tsunemoto 0:47c1b6a0c166 751
H_Tsunemoto 0:47c1b6a0c166 752 //------------------------------------------------------------------//
H_Tsunemoto 0:47c1b6a0c166 753 void Ser_Command_Input()
H_Tsunemoto 0:47c1b6a0c166 754 {
H_Tsunemoto 0:47c1b6a0c166 755 int i_RecCharCount;
H_Tsunemoto 0:47c1b6a0c166 756 // int b_CommadERR = 0;
H_Tsunemoto 0:47c1b6a0c166 757
H_Tsunemoto 0:47c1b6a0c166 758 while(rx_cr_Rec != 0){
H_Tsunemoto 0:47c1b6a0c166 759 // Read a line from the large rx buffer from rx interrupt routine
H_Tsunemoto 0:47c1b6a0c166 760
H_Tsunemoto 0:47c1b6a0c166 761 if(rx_in != rx_out){
H_Tsunemoto 0:47c1b6a0c166 762 i_RecCharCount = read_line();
H_Tsunemoto 0:47c1b6a0c166 763 // b_CommadERR = 0;
H_Tsunemoto 0:47c1b6a0c166 764 if(i_RecCharCount != 0){
H_Tsunemoto 0:47c1b6a0c166 765 //////////////////////////////////////////
H_Tsunemoto 0:47c1b6a0c166 766 // else{
H_Tsunemoto 0:47c1b6a0c166 767 switch(rx_line[0]){
H_Tsunemoto 0:47c1b6a0c166 768 // Header "M" Pulse Test Command
H_Tsunemoto 0:47c1b6a0c166 769 // ---- msec Pulse Test Command ---- //
H_Tsunemoto 0:47c1b6a0c166 770 case 'm':
H_Tsunemoto 0:47c1b6a0c166 771 case 'M':
H_Tsunemoto 0:47c1b6a0c166 772 switch(rx_line[1]){
H_Tsunemoto 0:47c1b6a0c166 773 // Header "MP" Pulse Test Command
H_Tsunemoto 0:47c1b6a0c166 774 case 'P':
H_Tsunemoto 0:47c1b6a0c166 775 case 'p':
H_Tsunemoto 0:47c1b6a0c166 776 if((rx_line[2] == 'W') ){
H_Tsunemoto 0:47c1b6a0c166 777 com_Check_msecMPW( i_RecCharCount);
H_Tsunemoto 0:47c1b6a0c166 778 }
H_Tsunemoto 0:47c1b6a0c166 779 else if((rx_line[2] == 'I') ){
H_Tsunemoto 0:47c1b6a0c166 780 com_Check_msecMPI( i_RecCharCount);
H_Tsunemoto 0:47c1b6a0c166 781 }
H_Tsunemoto 0:47c1b6a0c166 782 else if((rx_line[2] == 'C')){
H_Tsunemoto 0:47c1b6a0c166 783 com_Check_msecMPC( i_RecCharCount);
H_Tsunemoto 0:47c1b6a0c166 784 }
H_Tsunemoto 0:47c1b6a0c166 785 else if((rx_line[2] == 'T')){
H_Tsunemoto 0:47c1b6a0c166 786 com_Check_msecMPT( i_RecCharCount);
H_Tsunemoto 0:47c1b6a0c166 787 }
H_Tsunemoto 0:47c1b6a0c166 788 break;
H_Tsunemoto 0:47c1b6a0c166 789 // Header "MF" Pulse Test Command
H_Tsunemoto 0:47c1b6a0c166 790 case 'f':
H_Tsunemoto 0:47c1b6a0c166 791 case 'F':
H_Tsunemoto 0:47c1b6a0c166 792 if((rx_line[2] == 'N')){
H_Tsunemoto 0:47c1b6a0c166 793 com_Check_msecPulseMPN( i_RecCharCount);
H_Tsunemoto 0:47c1b6a0c166 794 }
H_Tsunemoto 0:47c1b6a0c166 795 else if((rx_line[2] == '1')){
H_Tsunemoto 0:47c1b6a0c166 796 com_Check_msecPulseMP1( i_RecCharCount);
H_Tsunemoto 0:47c1b6a0c166 797 }
H_Tsunemoto 0:47c1b6a0c166 798 break;
H_Tsunemoto 0:47c1b6a0c166 799 // Header "MX" ADC Control Command
H_Tsunemoto 0:47c1b6a0c166 800 case 'X':
H_Tsunemoto 0:47c1b6a0c166 801 case 'x':
H_Tsunemoto 0:47c1b6a0c166 802 if((rx_line[2] == 'N') ){
H_Tsunemoto 0:47c1b6a0c166 803 com_Check_msecPulseMXN( i_RecCharCount);
H_Tsunemoto 0:47c1b6a0c166 804 }
H_Tsunemoto 0:47c1b6a0c166 805 else if((rx_line[2] == '1') ){
H_Tsunemoto 0:47c1b6a0c166 806 com_Check_msecPulseMX1( i_RecCharCount);
H_Tsunemoto 0:47c1b6a0c166 807 }
H_Tsunemoto 0:47c1b6a0c166 808 break;
H_Tsunemoto 0:47c1b6a0c166 809 // Header "MF" Pulse Test Command
H_Tsunemoto 0:47c1b6a0c166 810 case 't':
H_Tsunemoto 0:47c1b6a0c166 811 case 'T':
H_Tsunemoto 0:47c1b6a0c166 812 if((rx_line[2] == 'N')){
H_Tsunemoto 0:47c1b6a0c166 813 com_Check_msecPulseMTN( i_RecCharCount);
H_Tsunemoto 0:47c1b6a0c166 814 }
H_Tsunemoto 0:47c1b6a0c166 815 else if((rx_line[2] == 'W')){
H_Tsunemoto 0:47c1b6a0c166 816 com_Check_msecPulseMTW( i_RecCharCount);
H_Tsunemoto 0:47c1b6a0c166 817 }
H_Tsunemoto 0:47c1b6a0c166 818 break;
H_Tsunemoto 0:47c1b6a0c166 819 default:
H_Tsunemoto 0:47c1b6a0c166 820 break;
H_Tsunemoto 0:47c1b6a0c166 821 }
H_Tsunemoto 0:47c1b6a0c166 822 break;
H_Tsunemoto 0:47c1b6a0c166 823 // ---- usec Short Pulse Test Command ---- //
H_Tsunemoto 0:47c1b6a0c166 824 case 'u':
H_Tsunemoto 0:47c1b6a0c166 825 case 'U':
H_Tsunemoto 0:47c1b6a0c166 826 switch(rx_line[1]){
H_Tsunemoto 0:47c1b6a0c166 827 case 'P':
H_Tsunemoto 0:47c1b6a0c166 828 case 'p':
H_Tsunemoto 0:47c1b6a0c166 829 if((rx_line[2] == 'W') ){
H_Tsunemoto 0:47c1b6a0c166 830 com_Check_usecUPW(i_RecCharCount);
H_Tsunemoto 0:47c1b6a0c166 831 }
H_Tsunemoto 0:47c1b6a0c166 832 else if((rx_line[2] == 'I') ){
H_Tsunemoto 0:47c1b6a0c166 833 com_Check_usecUPI(i_RecCharCount);
H_Tsunemoto 0:47c1b6a0c166 834 }
H_Tsunemoto 0:47c1b6a0c166 835 else if((rx_line[2] == 'C')){
H_Tsunemoto 0:47c1b6a0c166 836 com_Check_usecUPC(i_RecCharCount);
H_Tsunemoto 0:47c1b6a0c166 837 }
H_Tsunemoto 0:47c1b6a0c166 838 break;
H_Tsunemoto 0:47c1b6a0c166 839 case 'f':
H_Tsunemoto 0:47c1b6a0c166 840 case 'F':
H_Tsunemoto 0:47c1b6a0c166 841 if((rx_line[2] == 'N')){
H_Tsunemoto 0:47c1b6a0c166 842 com_Check_usecPulseUPN(i_RecCharCount);
H_Tsunemoto 0:47c1b6a0c166 843 }
H_Tsunemoto 0:47c1b6a0c166 844 else if((rx_line[2] == '1')){
H_Tsunemoto 0:47c1b6a0c166 845 com_Check_usecPulseUP1(i_RecCharCount);
H_Tsunemoto 0:47c1b6a0c166 846 }
H_Tsunemoto 0:47c1b6a0c166 847 else{
H_Tsunemoto 0:47c1b6a0c166 848 com_Check_usecPulseA(i_RecCharCount);
H_Tsunemoto 0:47c1b6a0c166 849 }
H_Tsunemoto 0:47c1b6a0c166 850 break;
H_Tsunemoto 0:47c1b6a0c166 851 // Header "A" ADC Control Command
H_Tsunemoto 0:47c1b6a0c166 852 case 'X':
H_Tsunemoto 0:47c1b6a0c166 853 case 'x':
H_Tsunemoto 0:47c1b6a0c166 854 if((rx_line[2] == 'N') ){
H_Tsunemoto 0:47c1b6a0c166 855 com_Check_usecPulseUXN( i_RecCharCount);
H_Tsunemoto 0:47c1b6a0c166 856 }
H_Tsunemoto 0:47c1b6a0c166 857 else if((rx_line[2] == '1') ){
H_Tsunemoto 0:47c1b6a0c166 858 com_Check_usecPulseUX1( i_RecCharCount);
H_Tsunemoto 0:47c1b6a0c166 859 }
H_Tsunemoto 0:47c1b6a0c166 860 else{
H_Tsunemoto 0:47c1b6a0c166 861 com_Check_usecPulseB(i_RecCharCount);
H_Tsunemoto 0:47c1b6a0c166 862 }
H_Tsunemoto 0:47c1b6a0c166 863 break;
H_Tsunemoto 0:47c1b6a0c166 864 default:
H_Tsunemoto 0:47c1b6a0c166 865 break;
H_Tsunemoto 0:47c1b6a0c166 866 }
H_Tsunemoto 0:47c1b6a0c166 867 break;
H_Tsunemoto 0:47c1b6a0c166 868 case 'S':
H_Tsunemoto 0:47c1b6a0c166 869 if(i_RecCharCount == 1){
H_Tsunemoto 0:47c1b6a0c166 870 // i_adc_ActiveMode_status = ActiveMode_ADC_Sample_Busy;
H_Tsunemoto 0:47c1b6a0c166 871 // Start_ADC();
H_Tsunemoto 0:47c1b6a0c166 872 }
H_Tsunemoto 0:47c1b6a0c166 873 else if (rx_line[1] == 'T'){
H_Tsunemoto 0:47c1b6a0c166 874 //case 'T':
H_Tsunemoto 0:47c1b6a0c166 875 if((rx_line[2] == 'A') && (rx_line[3] == 'R') && (rx_line[4] == 'T')){
H_Tsunemoto 0:47c1b6a0c166 876 // i_adc_ActiveMode_status = ActiveMode_ADC_Sample_Busy;
H_Tsunemoto 0:47c1b6a0c166 877 // Start_ADC();
H_Tsunemoto 0:47c1b6a0c166 878
H_Tsunemoto 0:47c1b6a0c166 879 }
H_Tsunemoto 0:47c1b6a0c166 880 else if((rx_line[2] == 'O') && (rx_line[3] == 'P') ){
H_Tsunemoto 0:47c1b6a0c166 881 // i_adc_ActiveMode_status = ActiveMode_ADC_Sample_Stop;
H_Tsunemoto 0:47c1b6a0c166 882 // ADC_Stop();
H_Tsunemoto 0:47c1b6a0c166 883 }
H_Tsunemoto 0:47c1b6a0c166 884 else if ((rx_line[2] == '?')){ //{ "ST?"
H_Tsunemoto 0:47c1b6a0c166 885 com_ADC_Table_Param_Send();
H_Tsunemoto 0:47c1b6a0c166 886 }
H_Tsunemoto 0:47c1b6a0c166 887 else if ( (rx_line[2] == 'A')&& (rx_line[3] == '?')){ //{ "STA?"
H_Tsunemoto 0:47c1b6a0c166 888 com_ADC_Table_Param_Send();
H_Tsunemoto 0:47c1b6a0c166 889 }
H_Tsunemoto 0:47c1b6a0c166 890 else if ( (rx_line[2] == 'A')&& (rx_line[3] == 'T')&& (rx_line[4] == '?')){ //{ "STAT?"
H_Tsunemoto 0:47c1b6a0c166 891 com_ADC_Table_Param_Send();
H_Tsunemoto 0:47c1b6a0c166 892 }
H_Tsunemoto 0:47c1b6a0c166 893 else{
H_Tsunemoto 0:47c1b6a0c166 894 // b_CommadERR = 1;
H_Tsunemoto 0:47c1b6a0c166 895 }
H_Tsunemoto 0:47c1b6a0c166 896 //break;
H_Tsunemoto 0:47c1b6a0c166 897 }
H_Tsunemoto 0:47c1b6a0c166 898 else if((rx_line[1] == 'M') && (rx_line[2] == 'P')){
H_Tsunemoto 0:47c1b6a0c166 899 com_Check_SMP( i_RecCharCount);
H_Tsunemoto 0:47c1b6a0c166 900 }
H_Tsunemoto 0:47c1b6a0c166 901 else if (rx_line[1] == '?'){ //{ case '?':
H_Tsunemoto 0:47c1b6a0c166 902 com_ADC_Table_Param_Send();
H_Tsunemoto 0:47c1b6a0c166 903 //break;
H_Tsunemoto 0:47c1b6a0c166 904 }
H_Tsunemoto 0:47c1b6a0c166 905 else{
H_Tsunemoto 0:47c1b6a0c166 906 //default:
H_Tsunemoto 0:47c1b6a0c166 907 // b_CommadERR = 1;
H_Tsunemoto 0:47c1b6a0c166 908 //break;
H_Tsunemoto 0:47c1b6a0c166 909 }
H_Tsunemoto 0:47c1b6a0c166 910 break;
H_Tsunemoto 0:47c1b6a0c166 911 case 'T': // "T?" Timer Interrupt Counter Repry
H_Tsunemoto 0:47c1b6a0c166 912 if (rx_line[1]=='?'){
H_Tsunemoto 0:47c1b6a0c166 913 sprintf(tx_line,"Timer=%d[S}+%d[x0.1mSec] \r\n",timer_1Sec,timer_count);
H_Tsunemoto 0:47c1b6a0c166 914 // Copy tx line buffer to large tx buffer for tx interrupt routine
H_Tsunemoto 0:47c1b6a0c166 915 send_line();
H_Tsunemoto 0:47c1b6a0c166 916
H_Tsunemoto 0:47c1b6a0c166 917 }
H_Tsunemoto 0:47c1b6a0c166 918 else if(rx_line[1]=='C'){
H_Tsunemoto 0:47c1b6a0c166 919 timer_1Sec = timer_count = 0;
H_Tsunemoto 0:47c1b6a0c166 920 }
H_Tsunemoto 0:47c1b6a0c166 921 else{
H_Tsunemoto 0:47c1b6a0c166 922 // b_CommadERR = 1;
H_Tsunemoto 0:47c1b6a0c166 923 }
H_Tsunemoto 0:47c1b6a0c166 924 break;
H_Tsunemoto 0:47c1b6a0c166 925
H_Tsunemoto 0:47c1b6a0c166 926 case '?':
H_Tsunemoto 0:47c1b6a0c166 927 if(i_RecCharCount == 1){
H_Tsunemoto 0:47c1b6a0c166 928 com_ADC_Table_Param_Send();
H_Tsunemoto 0:47c1b6a0c166 929 }
H_Tsunemoto 0:47c1b6a0c166 930 else{
H_Tsunemoto 0:47c1b6a0c166 931 // b_CommadERR = 1;
H_Tsunemoto 0:47c1b6a0c166 932 }
H_Tsunemoto 0:47c1b6a0c166 933 break;
H_Tsunemoto 0:47c1b6a0c166 934 //break;
H_Tsunemoto 0:47c1b6a0c166 935 case 'E':
H_Tsunemoto 0:47c1b6a0c166 936 if(i_RecCharCount == 1){
H_Tsunemoto 0:47c1b6a0c166 937 // i_adc_ActiveMode_status = ActiveMode_ADC_Sample_Stop;
H_Tsunemoto 0:47c1b6a0c166 938 // ADC_Stop();
H_Tsunemoto 0:47c1b6a0c166 939 }
H_Tsunemoto 0:47c1b6a0c166 940 else{
H_Tsunemoto 0:47c1b6a0c166 941 // b_CommadERR = 1;
H_Tsunemoto 0:47c1b6a0c166 942 }
H_Tsunemoto 0:47c1b6a0c166 943 break;
H_Tsunemoto 0:47c1b6a0c166 944 case 'L':
H_Tsunemoto 0:47c1b6a0c166 945 if((rx_line[1] == 'E') && (rx_line[2] == 'D') ){
H_Tsunemoto 0:47c1b6a0c166 946 com_Check_LED(i_RecCharCount);
H_Tsunemoto 0:47c1b6a0c166 947 }
H_Tsunemoto 0:47c1b6a0c166 948 else{
H_Tsunemoto 0:47c1b6a0c166 949 }
H_Tsunemoto 0:47c1b6a0c166 950 default:
H_Tsunemoto 0:47c1b6a0c166 951 // b_CommadERR = 1;
H_Tsunemoto 0:47c1b6a0c166 952 break;
H_Tsunemoto 0:47c1b6a0c166 953
H_Tsunemoto 0:47c1b6a0c166 954 }
H_Tsunemoto 0:47c1b6a0c166 955 }
H_Tsunemoto 0:47c1b6a0c166 956 // if(rx_line[0] >= 0x20){
H_Tsunemoto 0:47c1b6a0c166 957 // if(b_CommadERR == 0){
H_Tsunemoto 0:47c1b6a0c166 958 // sprintf(tx_line,"ACK%d \r\n",rx_cr_Rec);
H_Tsunemoto 0:47c1b6a0c166 959 // // Copy tx line buffer to large tx buffer for tx interrupt routine
H_Tsunemoto 0:47c1b6a0c166 960 // send_line();
H_Tsunemoto 0:47c1b6a0c166 961 // }
H_Tsunemoto 0:47c1b6a0c166 962 // else{
H_Tsunemoto 0:47c1b6a0c166 963 // sprintf(tx_line,"ERR%d \r\n",rx_cr_Rec);
H_Tsunemoto 0:47c1b6a0c166 964 // // Copy tx line buffer to large tx buffer for tx interrupt routine
H_Tsunemoto 0:47c1b6a0c166 965 // send_line();
H_Tsunemoto 0:47c1b6a0c166 966 // }
H_Tsunemoto 0:47c1b6a0c166 967 // }
H_Tsunemoto 0:47c1b6a0c166 968 rx_cr_Rec--;
H_Tsunemoto 0:47c1b6a0c166 969 }
H_Tsunemoto 0:47c1b6a0c166 970 else{
H_Tsunemoto 0:47c1b6a0c166 971 rx_cr_Rec = 0;
H_Tsunemoto 0:47c1b6a0c166 972 break;
H_Tsunemoto 0:47c1b6a0c166 973 }
H_Tsunemoto 0:47c1b6a0c166 974 }
H_Tsunemoto 0:47c1b6a0c166 975 }
H_Tsunemoto 0:47c1b6a0c166 976
H_Tsunemoto 0:47c1b6a0c166 977 //////------------------------------------------------------------------------------/////
H_Tsunemoto 0:47c1b6a0c166 978 //////--------------- usec Short Pulse Test Command ---------------------/////
H_Tsunemoto 0:47c1b6a0c166 979 //////------------------------------------------------------------------------------/////
H_Tsunemoto 0:47c1b6a0c166 980
H_Tsunemoto 0:47c1b6a0c166 981
H_Tsunemoto 0:47c1b6a0c166 982 //////////////////////////////////////////////////////////////////////////////////
H_Tsunemoto 0:47c1b6a0c166 983 //------------ Command Check & Set Function ---------------------------------//
H_Tsunemoto 0:47c1b6a0c166 984 // Input :i_RecCharCount :Command Stringth Length //
H_Tsunemoto 0:47c1b6a0c166 985 // rx_line[80] :(Global) Rec Data Stringth //
H_Tsunemoto 0:47c1b6a0c166 986 // Return :bool b_CommadERR 0= ACK //
H_Tsunemoto 0:47c1b6a0c166 987 // 1= ERR //
H_Tsunemoto 0:47c1b6a0c166 988 //////////////////////////////////////////////////////////////////////////////////
H_Tsunemoto 0:47c1b6a0c166 989 void com_Check_usecPulseA(int i_RecCharCount)
H_Tsunemoto 0:47c1b6a0c166 990 {
H_Tsunemoto 0:47c1b6a0c166 991 // bool b_CommadERR=0;
H_Tsunemoto 0:47c1b6a0c166 992 // int i_num=2;
H_Tsunemoto 0:47c1b6a0c166 993 int i_count = st_p_test_mode_param.i_sample_interval;
H_Tsunemoto 0:47c1b6a0c166 994 int i;
H_Tsunemoto 0:47c1b6a0c166 995 if(i_count == 0){
H_Tsunemoto 0:47c1b6a0c166 996 POut_P30_Pulse.write(1);
H_Tsunemoto 0:47c1b6a0c166 997 POut_P30_Pulse.write(0);
H_Tsunemoto 0:47c1b6a0c166 998 }
H_Tsunemoto 0:47c1b6a0c166 999 else{
H_Tsunemoto 0:47c1b6a0c166 1000 POut_P30_Pulse.write(0);
H_Tsunemoto 0:47c1b6a0c166 1001 for(i=0;i<i_count;i++){
H_Tsunemoto 0:47c1b6a0c166 1002 POut_P30_Pulse.write(1);
H_Tsunemoto 0:47c1b6a0c166 1003 }
H_Tsunemoto 0:47c1b6a0c166 1004 POut_P30_Pulse.write(0);
H_Tsunemoto 0:47c1b6a0c166 1005 }
H_Tsunemoto 0:47c1b6a0c166 1006 // return(b_CommadERR);
H_Tsunemoto 0:47c1b6a0c166 1007 }
H_Tsunemoto 0:47c1b6a0c166 1008 void com_Check_usecPulseUP1(int i_RecCharCount)
H_Tsunemoto 0:47c1b6a0c166 1009 {
H_Tsunemoto 0:47c1b6a0c166 1010 // bool b_CommadERR=0;
H_Tsunemoto 0:47c1b6a0c166 1011 // int i_num=2;
H_Tsunemoto 0:47c1b6a0c166 1012 int i_count = st_p_test_mode_param.i_usec_Pulse_width;
H_Tsunemoto 0:47c1b6a0c166 1013 int i;
H_Tsunemoto 0:47c1b6a0c166 1014 if(i_count == 0){
H_Tsunemoto 0:47c1b6a0c166 1015 POut_P30_Pulse.write(1);
H_Tsunemoto 0:47c1b6a0c166 1016 POut_P30_Pulse.write(0);
H_Tsunemoto 0:47c1b6a0c166 1017 }
H_Tsunemoto 0:47c1b6a0c166 1018 else{
H_Tsunemoto 0:47c1b6a0c166 1019 POut_P30_Pulse.write(0);
H_Tsunemoto 0:47c1b6a0c166 1020 for(i=0;i<i_count;i++){
H_Tsunemoto 0:47c1b6a0c166 1021 POut_P30_Pulse.write(1);
H_Tsunemoto 0:47c1b6a0c166 1022 }
H_Tsunemoto 0:47c1b6a0c166 1023 POut_P30_Pulse.write(0);
H_Tsunemoto 0:47c1b6a0c166 1024 }
H_Tsunemoto 0:47c1b6a0c166 1025 // return(b_CommadERR);
H_Tsunemoto 0:47c1b6a0c166 1026 }
H_Tsunemoto 0:47c1b6a0c166 1027
H_Tsunemoto 0:47c1b6a0c166 1028 void com_Check_usecPulseUPN(int i_RecCharCount)
H_Tsunemoto 0:47c1b6a0c166 1029 {
H_Tsunemoto 0:47c1b6a0c166 1030 // bool b_CommadERR=0;
H_Tsunemoto 0:47c1b6a0c166 1031 // int i_num=2;
H_Tsunemoto 0:47c1b6a0c166 1032 int i_PluseWidth = st_p_test_mode_param.i_usec_Pulse_width;
H_Tsunemoto 0:47c1b6a0c166 1033 int i_usec_PulseInt = st_p_test_mode_param.i_usec_Pulse_Interval;
H_Tsunemoto 0:47c1b6a0c166 1034 int i_count = st_p_test_mode_param.i_usec_Pulse_RepCnt;
H_Tsunemoto 0:47c1b6a0c166 1035 if(i_count<0) {
H_Tsunemoto 0:47c1b6a0c166 1036 i_count = 1;
H_Tsunemoto 0:47c1b6a0c166 1037 }
H_Tsunemoto 0:47c1b6a0c166 1038 /*
H_Tsunemoto 0:47c1b6a0c166 1039 int i_usec_Pulse_width;
H_Tsunemoto 0:47c1b6a0c166 1040 int i_usec_Pulse_Interval;
H_Tsunemoto 0:47c1b6a0c166 1041 int i_usec_Pulse_RepCnt;
H_Tsunemoto 0:47c1b6a0c166 1042
H_Tsunemoto 0:47c1b6a0c166 1043 */
H_Tsunemoto 0:47c1b6a0c166 1044 int i,k;
H_Tsunemoto 0:47c1b6a0c166 1045 for (k=0;k< i_count;k++){
H_Tsunemoto 0:47c1b6a0c166 1046 if(i_PluseWidth == 0){
H_Tsunemoto 0:47c1b6a0c166 1047 POut_P30_Pulse.write(1);
H_Tsunemoto 0:47c1b6a0c166 1048 POut_P30_Pulse.write(0);
H_Tsunemoto 0:47c1b6a0c166 1049 }
H_Tsunemoto 0:47c1b6a0c166 1050 else{
H_Tsunemoto 0:47c1b6a0c166 1051 POut_P30_Pulse.write(0);
H_Tsunemoto 0:47c1b6a0c166 1052 for(i=0;i<i_PluseWidth;i++){
H_Tsunemoto 0:47c1b6a0c166 1053 POut_P30_Pulse.write(1);
H_Tsunemoto 0:47c1b6a0c166 1054 }
H_Tsunemoto 0:47c1b6a0c166 1055 POut_P30_Pulse.write(0);
H_Tsunemoto 0:47c1b6a0c166 1056 }
H_Tsunemoto 0:47c1b6a0c166 1057 if(i_usec_PulseInt == 0){
H_Tsunemoto 0:47c1b6a0c166 1058 POut_P30_Pulse.write(0);
H_Tsunemoto 0:47c1b6a0c166 1059 POut_P30_Pulse.write(0);
H_Tsunemoto 0:47c1b6a0c166 1060 }
H_Tsunemoto 0:47c1b6a0c166 1061 else{
H_Tsunemoto 0:47c1b6a0c166 1062 POut_P30_Pulse.write(0);
H_Tsunemoto 0:47c1b6a0c166 1063 for(i=0;i<i_usec_PulseInt;i++){
H_Tsunemoto 0:47c1b6a0c166 1064 POut_P30_Pulse.write(0);
H_Tsunemoto 0:47c1b6a0c166 1065 }
H_Tsunemoto 0:47c1b6a0c166 1066 POut_P30_Pulse.write(0);
H_Tsunemoto 0:47c1b6a0c166 1067 }
H_Tsunemoto 0:47c1b6a0c166 1068
H_Tsunemoto 0:47c1b6a0c166 1069 }
H_Tsunemoto 0:47c1b6a0c166 1070 // return(b_CommadERR);
H_Tsunemoto 0:47c1b6a0c166 1071 }
H_Tsunemoto 0:47c1b6a0c166 1072 void com_Check_usecPulseB(int i_RecCharCount)
H_Tsunemoto 0:47c1b6a0c166 1073 {
H_Tsunemoto 0:47c1b6a0c166 1074 // bool b_CommadERR=0;
H_Tsunemoto 0:47c1b6a0c166 1075 // int i_num=2;
H_Tsunemoto 0:47c1b6a0c166 1076 int i_count = st_p_test_mode_param.i_sample_interval;
H_Tsunemoto 0:47c1b6a0c166 1077 int i;
H_Tsunemoto 0:47c1b6a0c166 1078 if(i_count == 0){
H_Tsunemoto 0:47c1b6a0c166 1079 POut_P29_Pulse.write(1);
H_Tsunemoto 0:47c1b6a0c166 1080 POut_P29_Pulse.write(0);
H_Tsunemoto 0:47c1b6a0c166 1081 }
H_Tsunemoto 0:47c1b6a0c166 1082 else{
H_Tsunemoto 0:47c1b6a0c166 1083 POut_P29_Pulse.write(0);
H_Tsunemoto 0:47c1b6a0c166 1084 for(i=0;i<i_count;i++){
H_Tsunemoto 0:47c1b6a0c166 1085 POut_P29_Pulse.write(1);
H_Tsunemoto 0:47c1b6a0c166 1086 }
H_Tsunemoto 0:47c1b6a0c166 1087 POut_P29_Pulse.write(0);
H_Tsunemoto 0:47c1b6a0c166 1088 }
H_Tsunemoto 0:47c1b6a0c166 1089 // return(b_CommadERR);
H_Tsunemoto 0:47c1b6a0c166 1090 }
H_Tsunemoto 0:47c1b6a0c166 1091 void com_Check_usecPulseUX1(int i_RecCharCount)
H_Tsunemoto 0:47c1b6a0c166 1092 {
H_Tsunemoto 0:47c1b6a0c166 1093 // bool b_CommadERR=0;
H_Tsunemoto 0:47c1b6a0c166 1094 // int i_num=2;
H_Tsunemoto 0:47c1b6a0c166 1095 int i_count = st_p_test_mode_param.i_usec_Pulse_width;
H_Tsunemoto 0:47c1b6a0c166 1096 int i;
H_Tsunemoto 0:47c1b6a0c166 1097 if(i_count == 0){
H_Tsunemoto 0:47c1b6a0c166 1098 POut_P29_Pulse.write(1);
H_Tsunemoto 0:47c1b6a0c166 1099 POut_P29_Pulse.write(0);
H_Tsunemoto 0:47c1b6a0c166 1100 }
H_Tsunemoto 0:47c1b6a0c166 1101 else{
H_Tsunemoto 0:47c1b6a0c166 1102 POut_P29_Pulse.write(0);
H_Tsunemoto 0:47c1b6a0c166 1103 for(i=0;i<i_count;i++){
H_Tsunemoto 0:47c1b6a0c166 1104 POut_P29_Pulse.write(1);
H_Tsunemoto 0:47c1b6a0c166 1105 }
H_Tsunemoto 0:47c1b6a0c166 1106 POut_P29_Pulse.write(0);
H_Tsunemoto 0:47c1b6a0c166 1107 }
H_Tsunemoto 0:47c1b6a0c166 1108 // return(b_CommadERR);
H_Tsunemoto 0:47c1b6a0c166 1109 }
H_Tsunemoto 0:47c1b6a0c166 1110 void com_Check_usecPulseUXN(int i_RecCharCount)
H_Tsunemoto 0:47c1b6a0c166 1111 {
H_Tsunemoto 0:47c1b6a0c166 1112 // bool b_CommadERR=0;
H_Tsunemoto 0:47c1b6a0c166 1113 // int i_num=2;
H_Tsunemoto 0:47c1b6a0c166 1114 // int i_count = st_p_test_mode_param.i_sample_interval;
H_Tsunemoto 0:47c1b6a0c166 1115 int i_PluseWidth = st_p_test_mode_param.i_usec_Pulse_width;
H_Tsunemoto 0:47c1b6a0c166 1116 int i_usec_PulseInt = st_p_test_mode_param.i_usec_Pulse_Interval;
H_Tsunemoto 0:47c1b6a0c166 1117 int i_count = st_p_test_mode_param.i_usec_Pulse_RepCnt;
H_Tsunemoto 0:47c1b6a0c166 1118 if(i_count<0) {
H_Tsunemoto 0:47c1b6a0c166 1119 i_count = 1;
H_Tsunemoto 0:47c1b6a0c166 1120 }
H_Tsunemoto 0:47c1b6a0c166 1121 int i,k;
H_Tsunemoto 0:47c1b6a0c166 1122 for (k=0;k< i_count;k++){
H_Tsunemoto 0:47c1b6a0c166 1123 if(i_PluseWidth == 0){
H_Tsunemoto 0:47c1b6a0c166 1124 POut_P29_Pulse.write(1);
H_Tsunemoto 0:47c1b6a0c166 1125 POut_P29_Pulse.write(0);
H_Tsunemoto 0:47c1b6a0c166 1126 }
H_Tsunemoto 0:47c1b6a0c166 1127 else{
H_Tsunemoto 0:47c1b6a0c166 1128 POut_P29_Pulse.write(0);
H_Tsunemoto 0:47c1b6a0c166 1129 for(i=0;i<i_PluseWidth;i++){
H_Tsunemoto 0:47c1b6a0c166 1130 POut_P29_Pulse.write(1);
H_Tsunemoto 0:47c1b6a0c166 1131 }
H_Tsunemoto 0:47c1b6a0c166 1132 POut_P29_Pulse.write(0);
H_Tsunemoto 0:47c1b6a0c166 1133 }
H_Tsunemoto 0:47c1b6a0c166 1134 if(i_usec_PulseInt == 0){
H_Tsunemoto 0:47c1b6a0c166 1135 POut_P29_Pulse.write(0);
H_Tsunemoto 0:47c1b6a0c166 1136 POut_P29_Pulse.write(0);
H_Tsunemoto 0:47c1b6a0c166 1137 }
H_Tsunemoto 0:47c1b6a0c166 1138 else{
H_Tsunemoto 0:47c1b6a0c166 1139 POut_P29_Pulse.write(0);
H_Tsunemoto 0:47c1b6a0c166 1140 for(i=0;i<i_usec_PulseInt;i++){
H_Tsunemoto 0:47c1b6a0c166 1141 POut_P29_Pulse.write(0);
H_Tsunemoto 0:47c1b6a0c166 1142 }
H_Tsunemoto 0:47c1b6a0c166 1143 POut_P29_Pulse.write(0);
H_Tsunemoto 0:47c1b6a0c166 1144 }
H_Tsunemoto 0:47c1b6a0c166 1145 }
H_Tsunemoto 0:47c1b6a0c166 1146 // return(b_CommadERR);
H_Tsunemoto 0:47c1b6a0c166 1147 }
H_Tsunemoto 0:47c1b6a0c166 1148
H_Tsunemoto 0:47c1b6a0c166 1149 //------------------------------------------------------------------------------//
H_Tsunemoto 0:47c1b6a0c166 1150 // ADC No.02 "PAW xxxx Pulse WidthCount Set //
H_Tsunemoto 0:47c1b6a0c166 1151 //#define ADC_SAMPLE_RATE_MIN 2
H_Tsunemoto 0:47c1b6a0c166 1152 //#define ADC_SAMPLE_RATE_MAX 1000
H_Tsunemoto 0:47c1b6a0c166 1153 //int st_p_test_mode_param.i_sample_interval = 200; // ADC Sample Rate 5 - 20000(20.0mSec)
H_Tsunemoto 0:47c1b6a0c166 1154 //------------------------------------------------------------------------------//
H_Tsunemoto 0:47c1b6a0c166 1155 void com_Check_usecUPW(int i_RecCharCount)
H_Tsunemoto 0:47c1b6a0c166 1156 {
H_Tsunemoto 0:47c1b6a0c166 1157 //bool b_CommadERR=0;
H_Tsunemoto 0:47c1b6a0c166 1158 int i_num=2;
H_Tsunemoto 0:47c1b6a0c166 1159 char *pt_comRec;
H_Tsunemoto 0:47c1b6a0c166 1160
H_Tsunemoto 0:47c1b6a0c166 1161 if(i_RecCharCount < 4){
H_Tsunemoto 0:47c1b6a0c166 1162 // b_CommadERR = 1;
H_Tsunemoto 0:47c1b6a0c166 1163 }
H_Tsunemoto 0:47c1b6a0c166 1164 else{
H_Tsunemoto 0:47c1b6a0c166 1165 pt_comRec = (char *)&rx_line[3];
H_Tsunemoto 0:47c1b6a0c166 1166 i_num = atoi(pt_comRec);
H_Tsunemoto 0:47c1b6a0c166 1167 st_p_test_mode_param.i_usec_Pulse_width = (int)( i_num);
H_Tsunemoto 0:47c1b6a0c166 1168
H_Tsunemoto 0:47c1b6a0c166 1169 }
H_Tsunemoto 0:47c1b6a0c166 1170 // return(b_CommadERR);
H_Tsunemoto 0:47c1b6a0c166 1171 }
H_Tsunemoto 0:47c1b6a0c166 1172 //------------------------------------------------------------------------------//
H_Tsunemoto 0:47c1b6a0c166 1173 // ADC No.03 "PIW xxxx Pulse Interval Count Set //
H_Tsunemoto 0:47c1b6a0c166 1174 //#define ADC_SAMPLE_RATE_MIN 2
H_Tsunemoto 0:47c1b6a0c166 1175 //#define ADC_SAMPLE_RATE_MAX 1000
H_Tsunemoto 0:47c1b6a0c166 1176 //int st_p_test_mode_param.i_sample_interval = 200; // ADC Sample Rate 5 - 20000(20.0mSec)
H_Tsunemoto 0:47c1b6a0c166 1177 //------------------------------------------------------------------------------//
H_Tsunemoto 0:47c1b6a0c166 1178 void com_Check_usecUPI(int i_RecCharCount)
H_Tsunemoto 0:47c1b6a0c166 1179 {
H_Tsunemoto 0:47c1b6a0c166 1180 //bool b_CommadERR=0;
H_Tsunemoto 0:47c1b6a0c166 1181 int i_num=2;
H_Tsunemoto 0:47c1b6a0c166 1182 char *pt_comRec;
H_Tsunemoto 0:47c1b6a0c166 1183
H_Tsunemoto 0:47c1b6a0c166 1184 if(i_RecCharCount < 4){
H_Tsunemoto 0:47c1b6a0c166 1185 // b_CommadERR = 1;
H_Tsunemoto 0:47c1b6a0c166 1186 }
H_Tsunemoto 0:47c1b6a0c166 1187 else{
H_Tsunemoto 0:47c1b6a0c166 1188 pt_comRec = (char *)&rx_line[3];
H_Tsunemoto 0:47c1b6a0c166 1189 i_num = atoi(pt_comRec);
H_Tsunemoto 0:47c1b6a0c166 1190 st_p_test_mode_param.i_usec_Pulse_Interval = (int)( i_num);
H_Tsunemoto 0:47c1b6a0c166 1191
H_Tsunemoto 0:47c1b6a0c166 1192 }
H_Tsunemoto 0:47c1b6a0c166 1193 // return(b_CommadERR);
H_Tsunemoto 0:47c1b6a0c166 1194 }
H_Tsunemoto 0:47c1b6a0c166 1195 //------------------------------------------------------------------------------//
H_Tsunemoto 0:47c1b6a0c166 1196 // ADC No.04 "PRC xxxx Pulse Repeat Count Set //
H_Tsunemoto 0:47c1b6a0c166 1197 //#define ADC_SAMPLE_RATE_MIN 2
H_Tsunemoto 0:47c1b6a0c166 1198 //#define ADC_SAMPLE_RATE_MAX 1000
H_Tsunemoto 0:47c1b6a0c166 1199 //int st_p_test_mode_param.i_sample_interval = 200; // ADC Sample Rate 5 - 20000(20.0mSec)
H_Tsunemoto 0:47c1b6a0c166 1200 //------------------------------------------------------------------------------//
H_Tsunemoto 0:47c1b6a0c166 1201 void com_Check_usecUPC(int i_RecCharCount)
H_Tsunemoto 0:47c1b6a0c166 1202 {
H_Tsunemoto 0:47c1b6a0c166 1203 //bool b_CommadERR=0;
H_Tsunemoto 0:47c1b6a0c166 1204 int i_num=2;
H_Tsunemoto 0:47c1b6a0c166 1205 char *pt_comRec;
H_Tsunemoto 0:47c1b6a0c166 1206
H_Tsunemoto 0:47c1b6a0c166 1207 if(i_RecCharCount < 4){
H_Tsunemoto 0:47c1b6a0c166 1208 // b_CommadERR = 1;
H_Tsunemoto 0:47c1b6a0c166 1209 }
H_Tsunemoto 0:47c1b6a0c166 1210 else{
H_Tsunemoto 0:47c1b6a0c166 1211 pt_comRec = (char *)&rx_line[3];
H_Tsunemoto 0:47c1b6a0c166 1212 i_num = atoi(pt_comRec);
H_Tsunemoto 0:47c1b6a0c166 1213 st_p_test_mode_param.i_usec_Pulse_RepCnt = (int)( i_num);
H_Tsunemoto 0:47c1b6a0c166 1214
H_Tsunemoto 0:47c1b6a0c166 1215 }
H_Tsunemoto 0:47c1b6a0c166 1216 // return(b_CommadERR);
H_Tsunemoto 0:47c1b6a0c166 1217 }
H_Tsunemoto 0:47c1b6a0c166 1218 //////------------------------------------------------------------------------------/////
H_Tsunemoto 0:47c1b6a0c166 1219 //////--------------- ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ ---------------------/////
H_Tsunemoto 0:47c1b6a0c166 1220 //////------------------------------------------------------------------------------/////
H_Tsunemoto 0:47c1b6a0c166 1221
H_Tsunemoto 0:47c1b6a0c166 1222 //////------------------------------------------------------------------------------/////
H_Tsunemoto 0:47c1b6a0c166 1223 //////--------------- msec Pulse Test Command ---------------------/////
H_Tsunemoto 0:47c1b6a0c166 1224 //////------------------------------------------------------------------------------/////
H_Tsunemoto 0:47c1b6a0c166 1225
H_Tsunemoto 0:47c1b6a0c166 1226
H_Tsunemoto 0:47c1b6a0c166 1227 //////////////////////////////////////////////////////////////////////////////////
H_Tsunemoto 0:47c1b6a0c166 1228 //------------ Command Check & Set Function ---------------------------------//
H_Tsunemoto 0:47c1b6a0c166 1229 // Input :i_RecCharCount :Command Stringth Length //
H_Tsunemoto 0:47c1b6a0c166 1230 // rx_line[80] :(Global) Rec Data Stringth //
H_Tsunemoto 0:47c1b6a0c166 1231 // Return :bool b_CommadERR 0= ACK //
H_Tsunemoto 0:47c1b6a0c166 1232 // 1= ERR //
H_Tsunemoto 0:47c1b6a0c166 1233 //////////////////////////////////////////////////////////////////////////////////
H_Tsunemoto 0:47c1b6a0c166 1234 void com_Check_msecPulseMP1(int i_RecCharCount)
H_Tsunemoto 0:47c1b6a0c166 1235 {
H_Tsunemoto 0:47c1b6a0c166 1236 // bool b_CommadERR=0;
H_Tsunemoto 0:47c1b6a0c166 1237 // sprintf(c_TEST_msg,"START,P30,P1Shot\n");
H_Tsunemoto 0:47c1b6a0c166 1238 // ui_Main_Test_Status = MAIN_TEST_STAT_START;
H_Tsunemoto 0:47c1b6a0c166 1239 sprintf(tx_line,"START,P30,P1Shot\r\n");
H_Tsunemoto 0:47c1b6a0c166 1240 send_line();
H_Tsunemoto 0:47c1b6a0c166 1241 ui_PulseTestMode = P_TESTMode_Nop;
H_Tsunemoto 0:47c1b6a0c166 1242 ui_PulseTestSequence = P_TESTSEQ_START;
H_Tsunemoto 0:47c1b6a0c166 1243 ui_PulseTestMode = P_TESTMode_1SHOT_OFF;
H_Tsunemoto 0:47c1b6a0c166 1244 // return(b_CommadERR);
H_Tsunemoto 0:47c1b6a0c166 1245 }
H_Tsunemoto 0:47c1b6a0c166 1246
H_Tsunemoto 0:47c1b6a0c166 1247 void com_Check_msecPulseMPN(int i_RecCharCount)
H_Tsunemoto 0:47c1b6a0c166 1248 {
H_Tsunemoto 0:47c1b6a0c166 1249 // bool b_CommadERR=0;
H_Tsunemoto 0:47c1b6a0c166 1250 sprintf(tx_line,"START_N,%4d,Times,OFF_P30\n",st_p_test_mode_param.i_msec_Pulse_RepCnt);
H_Tsunemoto 0:47c1b6a0c166 1251 send_line();
H_Tsunemoto 0:47c1b6a0c166 1252 // ui_Main_Test_Status = MAIN_TEST_STAT_START;
H_Tsunemoto 0:47c1b6a0c166 1253 ui_PulseTestMode = P_TESTMode_Nop;
H_Tsunemoto 0:47c1b6a0c166 1254 ui_PulseTestSequence = P_TESTSEQ_START;
H_Tsunemoto 0:47c1b6a0c166 1255 ui_PulseTestMode = P_TESTMode_Ntimes_OFF;
H_Tsunemoto 0:47c1b6a0c166 1256 // return(b_CommadERR);
H_Tsunemoto 0:47c1b6a0c166 1257 }
H_Tsunemoto 0:47c1b6a0c166 1258 void com_Check_msecPulseMX1(int i_RecCharCount)
H_Tsunemoto 0:47c1b6a0c166 1259 {
H_Tsunemoto 0:47c1b6a0c166 1260 // bool b_CommadERR=0;
H_Tsunemoto 0:47c1b6a0c166 1261 sprintf(tx_line,"START,P29,P1Shot\r\n");
H_Tsunemoto 0:47c1b6a0c166 1262 send_line();
H_Tsunemoto 0:47c1b6a0c166 1263 ui_PulseTestMode = P_TESTMode_Nop;
H_Tsunemoto 0:47c1b6a0c166 1264 ui_PulseTestSequence = P_TESTSEQ_START;
H_Tsunemoto 0:47c1b6a0c166 1265 ui_PulseTestMode = P_TESTMode_1SHOT_ON;
H_Tsunemoto 0:47c1b6a0c166 1266 // return(b_CommadERR);
H_Tsunemoto 0:47c1b6a0c166 1267 }
H_Tsunemoto 0:47c1b6a0c166 1268 void com_Check_msecPulseMXN(int i_RecCharCount)
H_Tsunemoto 0:47c1b6a0c166 1269 {
H_Tsunemoto 0:47c1b6a0c166 1270 // bool b_CommadERR=0;
H_Tsunemoto 0:47c1b6a0c166 1271 sprintf(tx_line,"START_N,%4d,Times,ON_P29\n",st_p_test_mode_param.i_msec_Pulse_RepCnt);
H_Tsunemoto 0:47c1b6a0c166 1272 send_line();
H_Tsunemoto 0:47c1b6a0c166 1273 ui_PulseTestMode = P_TESTMode_Nop;
H_Tsunemoto 0:47c1b6a0c166 1274 ui_PulseTestSequence = P_TESTSEQ_START;
H_Tsunemoto 0:47c1b6a0c166 1275 ui_PulseTestMode = P_TESTMode_Ntimes_ON;
H_Tsunemoto 0:47c1b6a0c166 1276 // return(b_CommadERR);
H_Tsunemoto 0:47c1b6a0c166 1277 }
H_Tsunemoto 0:47c1b6a0c166 1278 void com_Check_msecPulseMTN(int i_RecCharCount)
H_Tsunemoto 0:47c1b6a0c166 1279 {
H_Tsunemoto 0:47c1b6a0c166 1280 // bool b_CommadERR=0;
H_Tsunemoto 0:47c1b6a0c166 1281 sprintf(tx_line,"START,%4d,Times,ONOFF_P29_30\n",st_p_test_mode_param.i_msec_Pulse_RepCnt);
H_Tsunemoto 0:47c1b6a0c166 1282 send_line();
H_Tsunemoto 0:47c1b6a0c166 1283 ui_PulseTestMode = P_TESTMode_Nop;
H_Tsunemoto 0:47c1b6a0c166 1284 ui_PulseTestSequence = P_TESTSEQ_START;
H_Tsunemoto 0:47c1b6a0c166 1285 ui_PulseTestMode = P_TESTMode_Ntimes_ONOFF;
H_Tsunemoto 0:47c1b6a0c166 1286 // return(b_CommadERR);
H_Tsunemoto 0:47c1b6a0c166 1287 }
H_Tsunemoto 0:47c1b6a0c166 1288
H_Tsunemoto 0:47c1b6a0c166 1289 void com_Check_msecPulseMTW(int i_RecCharCount)
H_Tsunemoto 0:47c1b6a0c166 1290 {
H_Tsunemoto 0:47c1b6a0c166 1291 int i_num=2;
H_Tsunemoto 0:47c1b6a0c166 1292 char *pt_comRec;
H_Tsunemoto 0:47c1b6a0c166 1293
H_Tsunemoto 0:47c1b6a0c166 1294 if(i_RecCharCount < 4){
H_Tsunemoto 0:47c1b6a0c166 1295 // b_CommadERR = 1;
H_Tsunemoto 0:47c1b6a0c166 1296 }
H_Tsunemoto 0:47c1b6a0c166 1297 else{
H_Tsunemoto 0:47c1b6a0c166 1298 pt_comRec = (char *)&rx_line[3];
H_Tsunemoto 0:47c1b6a0c166 1299 i_num = atoi(pt_comRec);
H_Tsunemoto 0:47c1b6a0c166 1300 st_p_test_mode_param.i_msec_Pulse_OnOffWait = (int)( i_num);
H_Tsunemoto 0:47c1b6a0c166 1301
H_Tsunemoto 0:47c1b6a0c166 1302 }
H_Tsunemoto 0:47c1b6a0c166 1303 // return(b_CommadERR);
H_Tsunemoto 0:47c1b6a0c166 1304 }
H_Tsunemoto 0:47c1b6a0c166 1305 //------------------------------------------------------------------------------//
H_Tsunemoto 0:47c1b6a0c166 1306 // ADC No.02 "PAW xxxx Pulse WidthCount Set //
H_Tsunemoto 0:47c1b6a0c166 1307 //#define ADC_SAMPLE_RATE_MIN 2
H_Tsunemoto 0:47c1b6a0c166 1308 //#define ADC_SAMPLE_RATE_MAX 1000
H_Tsunemoto 0:47c1b6a0c166 1309 //int st_p_test_mode_param.i_sample_interval = 200; // ADC Sample Rate 5 - 20000(20.0mSec)
H_Tsunemoto 0:47c1b6a0c166 1310 //------------------------------------------------------------------------------//
H_Tsunemoto 0:47c1b6a0c166 1311 void com_Check_msecMPW(int i_RecCharCount)
H_Tsunemoto 0:47c1b6a0c166 1312 {
H_Tsunemoto 0:47c1b6a0c166 1313 int i_num=2;
H_Tsunemoto 0:47c1b6a0c166 1314 char *pt_comRec;
H_Tsunemoto 0:47c1b6a0c166 1315
H_Tsunemoto 0:47c1b6a0c166 1316 if(i_RecCharCount < 4){
H_Tsunemoto 0:47c1b6a0c166 1317 // b_CommadERR = 1;
H_Tsunemoto 0:47c1b6a0c166 1318 }
H_Tsunemoto 0:47c1b6a0c166 1319 else{
H_Tsunemoto 0:47c1b6a0c166 1320 pt_comRec = (char *)&rx_line[3];
H_Tsunemoto 0:47c1b6a0c166 1321 i_num = atoi(pt_comRec);
H_Tsunemoto 0:47c1b6a0c166 1322 st_p_test_mode_param.i_msec_Pulse_width = (int)( i_num);
H_Tsunemoto 0:47c1b6a0c166 1323
H_Tsunemoto 0:47c1b6a0c166 1324 }
H_Tsunemoto 0:47c1b6a0c166 1325 // return(b_CommadERR);
H_Tsunemoto 0:47c1b6a0c166 1326 }
H_Tsunemoto 0:47c1b6a0c166 1327 //------------------------------------------------------------------------------//
H_Tsunemoto 0:47c1b6a0c166 1328 // ADC No.03 "PIW xxxx Pulse Interval Count Set //
H_Tsunemoto 0:47c1b6a0c166 1329 //#define ADC_SAMPLE_RATE_MIN 2
H_Tsunemoto 0:47c1b6a0c166 1330 //#define ADC_SAMPLE_RATE_MAX 1000
H_Tsunemoto 0:47c1b6a0c166 1331 //int st_p_test_mode_param.i_sample_interval = 200; // ADC Sample Rate 5 - 20000(20.0mSec)
H_Tsunemoto 0:47c1b6a0c166 1332 //------------------------------------------------------------------------------//
H_Tsunemoto 0:47c1b6a0c166 1333 void com_Check_msecMPI(int i_RecCharCount)
H_Tsunemoto 0:47c1b6a0c166 1334 {
H_Tsunemoto 0:47c1b6a0c166 1335 //bool b_CommadERR=0;
H_Tsunemoto 0:47c1b6a0c166 1336 int i_num=2;
H_Tsunemoto 0:47c1b6a0c166 1337 char *pt_comRec;
H_Tsunemoto 0:47c1b6a0c166 1338
H_Tsunemoto 0:47c1b6a0c166 1339 if(i_RecCharCount < 4){
H_Tsunemoto 0:47c1b6a0c166 1340 // b_CommadERR = 1;
H_Tsunemoto 0:47c1b6a0c166 1341 }
H_Tsunemoto 0:47c1b6a0c166 1342 else{
H_Tsunemoto 0:47c1b6a0c166 1343 pt_comRec = (char *)&rx_line[3];
H_Tsunemoto 0:47c1b6a0c166 1344 i_num = atoi(pt_comRec);
H_Tsunemoto 0:47c1b6a0c166 1345 st_p_test_mode_param.i_msec_Pulse_Interval = (int)( i_num);
H_Tsunemoto 0:47c1b6a0c166 1346
H_Tsunemoto 0:47c1b6a0c166 1347 }
H_Tsunemoto 0:47c1b6a0c166 1348 // return(b_CommadERR);
H_Tsunemoto 0:47c1b6a0c166 1349 }
H_Tsunemoto 0:47c1b6a0c166 1350 //------------------------------------------------------------------------------//
H_Tsunemoto 0:47c1b6a0c166 1351 // ADC No.04 "PRC xxxx Pulse Repeat Count Set //
H_Tsunemoto 0:47c1b6a0c166 1352 //#define ADC_SAMPLE_RATE_MIN 2
H_Tsunemoto 0:47c1b6a0c166 1353 //#define ADC_SAMPLE_RATE_MAX 1000
H_Tsunemoto 0:47c1b6a0c166 1354 //int st_p_test_mode_param.i_sample_interval = 200; // ADC Sample Rate 5 - 20000(20.0mSec)
H_Tsunemoto 0:47c1b6a0c166 1355 //------------------------------------------------------------------------------//
H_Tsunemoto 0:47c1b6a0c166 1356 void com_Check_msecMPC(int i_RecCharCount)
H_Tsunemoto 0:47c1b6a0c166 1357 {
H_Tsunemoto 0:47c1b6a0c166 1358 //bool b_CommadERR=0;
H_Tsunemoto 0:47c1b6a0c166 1359 int i_num=2;
H_Tsunemoto 0:47c1b6a0c166 1360 char *pt_comRec;
H_Tsunemoto 0:47c1b6a0c166 1361
H_Tsunemoto 0:47c1b6a0c166 1362 if(i_RecCharCount < 4){
H_Tsunemoto 0:47c1b6a0c166 1363 // b_CommadERR = 1;
H_Tsunemoto 0:47c1b6a0c166 1364 }
H_Tsunemoto 0:47c1b6a0c166 1365 else{
H_Tsunemoto 0:47c1b6a0c166 1366 pt_comRec = (char *)&rx_line[3];
H_Tsunemoto 0:47c1b6a0c166 1367 i_num = atoi(pt_comRec);
H_Tsunemoto 0:47c1b6a0c166 1368 st_p_test_mode_param.i_msec_Pulse_RepCnt = (int)( i_num);
H_Tsunemoto 0:47c1b6a0c166 1369
H_Tsunemoto 0:47c1b6a0c166 1370 }
H_Tsunemoto 0:47c1b6a0c166 1371 // return(b_CommadERR);
H_Tsunemoto 0:47c1b6a0c166 1372 }
H_Tsunemoto 0:47c1b6a0c166 1373 //------------------------------------------------------------------------------//
H_Tsunemoto 0:47c1b6a0c166 1374 // ADC No.04 "PRC xxxx Pulse Repeat Count Set //
H_Tsunemoto 0:47c1b6a0c166 1375 //#define ADC_SAMPLE_RATE_MIN 2
H_Tsunemoto 0:47c1b6a0c166 1376 //#define ADC_SAMPLE_RATE_MAX 1000
H_Tsunemoto 0:47c1b6a0c166 1377 //int st_p_test_mode_param.i_sample_interval = 200; // ADC Sample Rate 5 - 20000(20.0mSec)
H_Tsunemoto 0:47c1b6a0c166 1378 //------------------------------------------------------------------------------//
H_Tsunemoto 0:47c1b6a0c166 1379 void com_Check_msecMPT(int i_RecCharCount)
H_Tsunemoto 0:47c1b6a0c166 1380 {
H_Tsunemoto 0:47c1b6a0c166 1381 //bool b_CommadERR=0;
H_Tsunemoto 0:47c1b6a0c166 1382 int i_num=2;
H_Tsunemoto 0:47c1b6a0c166 1383 char *pt_comRec;
H_Tsunemoto 0:47c1b6a0c166 1384
H_Tsunemoto 0:47c1b6a0c166 1385 if(i_RecCharCount < 4){
H_Tsunemoto 0:47c1b6a0c166 1386 // b_CommadERR = 1;
H_Tsunemoto 0:47c1b6a0c166 1387 }
H_Tsunemoto 0:47c1b6a0c166 1388 else{
H_Tsunemoto 0:47c1b6a0c166 1389 pt_comRec = (char *)&rx_line[3];
H_Tsunemoto 0:47c1b6a0c166 1390 i_num = atoi(pt_comRec);
H_Tsunemoto 0:47c1b6a0c166 1391 if(i_num >0){
H_Tsunemoto 0:47c1b6a0c166 1392 st_p_test_mode_param.i_PulseTestEnable = 1;
H_Tsunemoto 0:47c1b6a0c166 1393 }
H_Tsunemoto 0:47c1b6a0c166 1394 else{
H_Tsunemoto 0:47c1b6a0c166 1395 st_p_test_mode_param.i_PulseTestEnable = 0;
H_Tsunemoto 0:47c1b6a0c166 1396 }
H_Tsunemoto 0:47c1b6a0c166 1397
H_Tsunemoto 0:47c1b6a0c166 1398 }
H_Tsunemoto 0:47c1b6a0c166 1399 // return(b_CommadERR);
H_Tsunemoto 0:47c1b6a0c166 1400 }
H_Tsunemoto 0:47c1b6a0c166 1401 //////------------------------------------------------------------------------------/////
H_Tsunemoto 0:47c1b6a0c166 1402 //////--------------- ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ ---------------------/////
H_Tsunemoto 0:47c1b6a0c166 1403 //////------------------------------------------------------------------------------/////
H_Tsunemoto 0:47c1b6a0c166 1404
H_Tsunemoto 0:47c1b6a0c166 1405 //------------------------------------------------------------------------------//
H_Tsunemoto 0:47c1b6a0c166 1406 // ADC No.1 "SMP xxxx ADC Sample Interval Set //
H_Tsunemoto 0:47c1b6a0c166 1407 //#define ADC_SAMPLE_RATE_MIN 2
H_Tsunemoto 0:47c1b6a0c166 1408 //#define ADC_SAMPLE_RATE_MAX 1000
H_Tsunemoto 0:47c1b6a0c166 1409 //int st_p_test_mode_param.i_sample_interval = 200; // ADC Sample Rate 5 - 20000(20.0mSec)
H_Tsunemoto 0:47c1b6a0c166 1410 //------------------------------------------------------------------------------//
H_Tsunemoto 0:47c1b6a0c166 1411 bool com_Check_SMP(int i_RecCharCount)
H_Tsunemoto 0:47c1b6a0c166 1412 {
H_Tsunemoto 0:47c1b6a0c166 1413 bool b_CommadERR=0;
H_Tsunemoto 0:47c1b6a0c166 1414 int i_num=2;
H_Tsunemoto 0:47c1b6a0c166 1415 char *pt_comRec;
H_Tsunemoto 0:47c1b6a0c166 1416
H_Tsunemoto 0:47c1b6a0c166 1417 if(i_RecCharCount < 4){
H_Tsunemoto 0:47c1b6a0c166 1418 b_CommadERR = 1;
H_Tsunemoto 0:47c1b6a0c166 1419 }
H_Tsunemoto 0:47c1b6a0c166 1420 else{
H_Tsunemoto 0:47c1b6a0c166 1421 pt_comRec = (char *)&rx_line[3];
H_Tsunemoto 0:47c1b6a0c166 1422 i_num = atoi(pt_comRec);
H_Tsunemoto 0:47c1b6a0c166 1423 st_p_test_mode_param.i_sample_interval = (int)( i_num);
H_Tsunemoto 0:47c1b6a0c166 1424
H_Tsunemoto 0:47c1b6a0c166 1425 }
H_Tsunemoto 0:47c1b6a0c166 1426 return(b_CommadERR);
H_Tsunemoto 0:47c1b6a0c166 1427 }
H_Tsunemoto 0:47c1b6a0c166 1428 //------------------------------------------------------------------------------//
H_Tsunemoto 0:47c1b6a0c166 1429 // ADC No.5 "A?" DAC Parameter Repry //
H_Tsunemoto 0:47c1b6a0c166 1430 //typedef struct st_PulseW_param{
H_Tsunemoto 0:47c1b6a0c166 1431 // int i_sample_interval; // DAC Output Pattern
H_Tsunemoto 0:47c1b6a0c166 1432 // float f_trigger_level;
H_Tsunemoto 0:47c1b6a0c166 1433 // us_trigger_level;
H_Tsunemoto 0:47c1b6a0c166 1434 // int i_pre_trig_point;
H_Tsunemoto 0:47c1b6a0c166 1435 // int i_usec_Pulse_end_time;
H_Tsunemoto 0:47c1b6a0c166 1436 //}ST_PulseW_PARAM;
H_Tsunemoto 0:47c1b6a0c166 1437 //
H_Tsunemoto 0:47c1b6a0c166 1438 //ST_PulseW_PARAM st_p_test_mode_param;
H_Tsunemoto 0:47c1b6a0c166 1439 //
H_Tsunemoto 0:47c1b6a0c166 1440 //------------------------------------------------------------------------------//
H_Tsunemoto 0:47c1b6a0c166 1441 void com_ADC_Table_Param_Send()
H_Tsunemoto 0:47c1b6a0c166 1442 {
H_Tsunemoto 0:47c1b6a0c166 1443 int i_num;
H_Tsunemoto 0:47c1b6a0c166 1444 //bool b_CommadERR=0;
H_Tsunemoto 0:47c1b6a0c166 1445
H_Tsunemoto 0:47c1b6a0c166 1446 // 2017.02.22 for Single CH Only CH0 <=> CH1 Exchange
H_Tsunemoto 0:47c1b6a0c166 1447 sprintf(tx_line,"Pulse Out Check MBED\r\n"); // 2017.02.22 for Single CH Only CH0 P,20,21 CH1= P19,22
H_Tsunemoto 0:47c1b6a0c166 1448 //2016.06.21 for MBED Dose Measure 2CH_2Range Title & Ver Send Append
H_Tsunemoto 0:47c1b6a0c166 1449 // 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:47c1b6a0c166 1450 send_line();
H_Tsunemoto 0:47c1b6a0c166 1451
H_Tsunemoto 0:47c1b6a0c166 1452 // i_num = ( st_p_test_mode_param.i_sample_interval ) ;
H_Tsunemoto 0:47c1b6a0c166 1453 // sprintf(tx_line,"SMP %4d[= x 0.2usec]\r\n",i_num);
H_Tsunemoto 0:47c1b6a0c166 1454 // send_line();
H_Tsunemoto 0:47c1b6a0c166 1455 // sprintf(tx_line," \r\n",i_num);
H_Tsunemoto 0:47c1b6a0c166 1456 // send_line();
H_Tsunemoto 0:47c1b6a0c166 1457 sprintf(tx_line,"msec Pulse Test Command & Parameter \r\n");
H_Tsunemoto 0:47c1b6a0c166 1458 send_line();
H_Tsunemoto 0:47c1b6a0c166 1459 i_num = ( st_p_test_mode_param.i_PulseTestEnable ) ;
H_Tsunemoto 0:47c1b6a0c166 1460 sprintf(tx_line," MPT: %1d[= P21 Reply Check ]\r\n",i_num);
H_Tsunemoto 0:47c1b6a0c166 1461 send_line();
H_Tsunemoto 0:47c1b6a0c166 1462
H_Tsunemoto 0:47c1b6a0c166 1463 sprintf(tx_line," MF1:P30 MX1:P29 Pulse 1shot PW=MPW x0.1msec PulseOut\r\n");
H_Tsunemoto 0:47c1b6a0c166 1464 send_line();
H_Tsunemoto 0:47c1b6a0c166 1465 sprintf(tx_line," MFN: P30 MXN: P29 Pulse Out Repeat\r\n");
H_Tsunemoto 0:47c1b6a0c166 1466 send_line();
H_Tsunemoto 0:47c1b6a0c166 1467 sprintf(tx_line," MTN: ON/OFF P29&30 Repeat Check \r\n");
H_Tsunemoto 0:47c1b6a0c166 1468 send_line();
H_Tsunemoto 0:47c1b6a0c166 1469 sprintf(tx_line," Pulse Width :MPW %4d[= x 0.1msec]\r\n",st_p_test_mode_param.i_msec_Pulse_width);
H_Tsunemoto 0:47c1b6a0c166 1470 send_line();
H_Tsunemoto 0:47c1b6a0c166 1471 sprintf(tx_line," Pulse Interval :MPI %4d[= x 0.1msec]\r\n",st_p_test_mode_param.i_msec_Pulse_Interval);
H_Tsunemoto 0:47c1b6a0c166 1472 send_line();
H_Tsunemoto 0:47c1b6a0c166 1473 sprintf(tx_line," Pulse Repeat Count :MPC %4d Count \r\n",st_p_test_mode_param.i_msec_Pulse_RepCnt);
H_Tsunemoto 0:47c1b6a0c166 1474 send_line();
H_Tsunemoto 0:47c1b6a0c166 1475 sprintf(tx_line," OFF-ONP30-P29Wait :MTW %4d Count \r\n",st_p_test_mode_param.i_msec_Pulse_OnOffWait);
H_Tsunemoto 0:47c1b6a0c166 1476 send_line();
H_Tsunemoto 0:47c1b6a0c166 1477
H_Tsunemoto 0:47c1b6a0c166 1478 sprintf(tx_line,"for Debug Test \r\n");
H_Tsunemoto 0:47c1b6a0c166 1479 send_line();
H_Tsunemoto 0:47c1b6a0c166 1480
H_Tsunemoto 0:47c1b6a0c166 1481 sprintf(tx_line,"usec Short Pulse Test Command & Parameter \r\n");
H_Tsunemoto 0:47c1b6a0c166 1482 send_line();
H_Tsunemoto 0:47c1b6a0c166 1483 sprintf(tx_line," UF1:P30 UX1:P29 Pulse 1shot PW=UPW x0.2usec PulseOut\r\n");
H_Tsunemoto 0:47c1b6a0c166 1484 send_line();
H_Tsunemoto 0:47c1b6a0c166 1485 sprintf(tx_line," UFN: P30 UXN: P29 Pulse Out Repeat n\r\n");
H_Tsunemoto 0:47c1b6a0c166 1486 send_line();
H_Tsunemoto 0:47c1b6a0c166 1487 sprintf(tx_line," Pulse Width :UPW %4d[= x 0.2usec]\r\n",st_p_test_mode_param.i_usec_Pulse_width);
H_Tsunemoto 0:47c1b6a0c166 1488 send_line();
H_Tsunemoto 0:47c1b6a0c166 1489 sprintf(tx_line," Pulse Interval :UPI %4d[= x 0.2usec]\r\n",st_p_test_mode_param.i_usec_Pulse_Interval);
H_Tsunemoto 0:47c1b6a0c166 1490 send_line();
H_Tsunemoto 0:47c1b6a0c166 1491 sprintf(tx_line," Pulse Repeat Count :UPC %4d Count \r\n",st_p_test_mode_param.i_usec_Pulse_RepCnt);
H_Tsunemoto 0:47c1b6a0c166 1492 send_line();
H_Tsunemoto 0:47c1b6a0c166 1493 // return(b_CommadERR);
H_Tsunemoto 0:47c1b6a0c166 1494
H_Tsunemoto 0:47c1b6a0c166 1495 // for Debug
H_Tsunemoto 0:47c1b6a0c166 1496
H_Tsunemoto 0:47c1b6a0c166 1497 }
H_Tsunemoto 0:47c1b6a0c166 1498 //------------------------------------------------------------------------------//
H_Tsunemoto 0:47c1b6a0c166 1499 // ADC No.7 "LED 1" Devug LED Active 0 / 1
H_Tsunemoto 0:47c1b6a0c166 1500 //------------------------------------------------------------------------------//
H_Tsunemoto 0:47c1b6a0c166 1501 bool com_Check_LED(int i_RecCharCount)
H_Tsunemoto 0:47c1b6a0c166 1502 {
H_Tsunemoto 0:47c1b6a0c166 1503 bool b_CommadERR=0;
H_Tsunemoto 0:47c1b6a0c166 1504 int i_num=0;
H_Tsunemoto 0:47c1b6a0c166 1505 char *pt_comRec;
H_Tsunemoto 0:47c1b6a0c166 1506
H_Tsunemoto 0:47c1b6a0c166 1507 if(i_RecCharCount < 4){
H_Tsunemoto 0:47c1b6a0c166 1508 b_CommadERR = 1;
H_Tsunemoto 0:47c1b6a0c166 1509 }
H_Tsunemoto 0:47c1b6a0c166 1510 else{
H_Tsunemoto 0:47c1b6a0c166 1511 pt_comRec = (char *)&rx_line[3];
H_Tsunemoto 0:47c1b6a0c166 1512 i_num = atoi(pt_comRec);
H_Tsunemoto 0:47c1b6a0c166 1513 if(i_num == 0){
H_Tsunemoto 0:47c1b6a0c166 1514 i_LED_Active = Debug_LED_Disable; // Disable
H_Tsunemoto 0:47c1b6a0c166 1515 led1=led2=led3=led4=0;
H_Tsunemoto 0:47c1b6a0c166 1516 }
H_Tsunemoto 0:47c1b6a0c166 1517 else if(i_num == 1){
H_Tsunemoto 0:47c1b6a0c166 1518 i_LED_Active = Debug_LED_Active; // Debug LED Active
H_Tsunemoto 0:47c1b6a0c166 1519 led1=led2=led3=led4=0;
H_Tsunemoto 0:47c1b6a0c166 1520 }
H_Tsunemoto 0:47c1b6a0c166 1521 else{
H_Tsunemoto 0:47c1b6a0c166 1522 b_CommadERR = 1;
H_Tsunemoto 0:47c1b6a0c166 1523 }
H_Tsunemoto 0:47c1b6a0c166 1524 }
H_Tsunemoto 0:47c1b6a0c166 1525 return(b_CommadERR);
H_Tsunemoto 0:47c1b6a0c166 1526 }
H_Tsunemoto 0:47c1b6a0c166 1527
H_Tsunemoto 0:47c1b6a0c166 1528
H_Tsunemoto 0:47c1b6a0c166 1529 //////////////////////////////////////////////////////////////////////////////////
H_Tsunemoto 0:47c1b6a0c166 1530 //////////////////////////////////////////////////////////////////////////////////
H_Tsunemoto 0:47c1b6a0c166 1531
H_Tsunemoto 0:47c1b6a0c166 1532
H_Tsunemoto 0:47c1b6a0c166 1533 //------------------------------------------------------------------------------//
H_Tsunemoto 0:47c1b6a0c166 1534 //------------------------------------------------------------------------------//
H_Tsunemoto 0:47c1b6a0c166 1535 //----- Serial tx/rx Communication
H_Tsunemoto 0:47c1b6a0c166 1536 //------------------------------------------------------------------------------//
H_Tsunemoto 0:47c1b6a0c166 1537 // Copy tx line buffer to large tx buffer for tx interrupt routine
H_Tsunemoto 0:47c1b6a0c166 1538 void send_line() {
H_Tsunemoto 0:47c1b6a0c166 1539 int i;
H_Tsunemoto 0:47c1b6a0c166 1540 char temp_char;
H_Tsunemoto 0:47c1b6a0c166 1541 bool empty;
H_Tsunemoto 0:47c1b6a0c166 1542 i = 0;
H_Tsunemoto 0:47c1b6a0c166 1543 // Start Critical Section - don't interrupt while changing global buffer variables
H_Tsunemoto 0:47c1b6a0c166 1544 NVIC_DisableIRQ(UART1_IRQn);
H_Tsunemoto 0:47c1b6a0c166 1545 empty = (tx_in == tx_out);
H_Tsunemoto 0:47c1b6a0c166 1546 while ((i==0) || (tx_line[i-1] != '\n')) {
H_Tsunemoto 0:47c1b6a0c166 1547 // Wait if buffer full
H_Tsunemoto 0:47c1b6a0c166 1548 if (((tx_in + 1) % ser_buffer_size) == tx_out) {
H_Tsunemoto 0:47c1b6a0c166 1549 // End Critical Section - need to let interrupt routine empty buffer by sending
H_Tsunemoto 0:47c1b6a0c166 1550 NVIC_EnableIRQ(UART1_IRQn);
H_Tsunemoto 0:47c1b6a0c166 1551 while (((tx_in + 1) % ser_buffer_size) == tx_out) {
H_Tsunemoto 0:47c1b6a0c166 1552 }
H_Tsunemoto 0:47c1b6a0c166 1553 // Start Critical Section - don't interrupt while changing global buffer variables
H_Tsunemoto 0:47c1b6a0c166 1554 NVIC_DisableIRQ(UART1_IRQn);
H_Tsunemoto 0:47c1b6a0c166 1555 }
H_Tsunemoto 0:47c1b6a0c166 1556 tx_buffer[tx_in] = tx_line[i];
H_Tsunemoto 0:47c1b6a0c166 1557 i++;
H_Tsunemoto 0:47c1b6a0c166 1558 tx_in = (tx_in + 1) % ser_buffer_size;
H_Tsunemoto 0:47c1b6a0c166 1559 }
H_Tsunemoto 0:47c1b6a0c166 1560 if (device.writeable() && (empty)) {
H_Tsunemoto 0:47c1b6a0c166 1561 temp_char = tx_buffer[tx_out];
H_Tsunemoto 0:47c1b6a0c166 1562 tx_out = (tx_out + 1) % ser_buffer_size;
H_Tsunemoto 0:47c1b6a0c166 1563 // Send first character to start tx interrupts, if stopped
H_Tsunemoto 0:47c1b6a0c166 1564 device.putc(temp_char);
H_Tsunemoto 0:47c1b6a0c166 1565 }
H_Tsunemoto 0:47c1b6a0c166 1566 // End Critical Section
H_Tsunemoto 0:47c1b6a0c166 1567 NVIC_EnableIRQ(UART1_IRQn);
H_Tsunemoto 0:47c1b6a0c166 1568 return;
H_Tsunemoto 0:47c1b6a0c166 1569 }
H_Tsunemoto 0:47c1b6a0c166 1570
H_Tsunemoto 0:47c1b6a0c166 1571 // Read a line from the large rx buffer from rx interrupt routine
H_Tsunemoto 0:47c1b6a0c166 1572 // 2013.08.08 H.Tsunemoto
H_Tsunemoto 0:47c1b6a0c166 1573 // Append Return Chear Number
H_Tsunemoto 0:47c1b6a0c166 1574 int read_line(){
H_Tsunemoto 0:47c1b6a0c166 1575 //void read_line() {
H_Tsunemoto 0:47c1b6a0c166 1576 int i;
H_Tsunemoto 0:47c1b6a0c166 1577 i = 0;
H_Tsunemoto 0:47c1b6a0c166 1578 // Start Critical Section - don't interrupt while changing global buffer variables
H_Tsunemoto 0:47c1b6a0c166 1579 NVIC_DisableIRQ(UART1_IRQn);
H_Tsunemoto 0:47c1b6a0c166 1580 while(rx_in != rx_out){
H_Tsunemoto 0:47c1b6a0c166 1581 rx_line[i] = rx_buffer[rx_out];
H_Tsunemoto 0:47c1b6a0c166 1582 rx_out = (rx_out + 1) % ser_buffer_size;
H_Tsunemoto 0:47c1b6a0c166 1583 if((rx_line[i] == '\r') || (rx_line[i] == '\n')){
H_Tsunemoto 0:47c1b6a0c166 1584 break;
H_Tsunemoto 0:47c1b6a0c166 1585 }
H_Tsunemoto 0:47c1b6a0c166 1586 i++;
H_Tsunemoto 0:47c1b6a0c166 1587
H_Tsunemoto 0:47c1b6a0c166 1588 }
H_Tsunemoto 0:47c1b6a0c166 1589 rx_line[i] = 0;
H_Tsunemoto 0:47c1b6a0c166 1590 // End Critical Section
H_Tsunemoto 0:47c1b6a0c166 1591 NVIC_EnableIRQ(UART1_IRQn);
H_Tsunemoto 0:47c1b6a0c166 1592 return(i);
H_Tsunemoto 0:47c1b6a0c166 1593 }
H_Tsunemoto 0:47c1b6a0c166 1594
H_Tsunemoto 0:47c1b6a0c166 1595 // Interupt Routine to read in data from serial port
H_Tsunemoto 0:47c1b6a0c166 1596 void Rx_interrupt() {
H_Tsunemoto 0:47c1b6a0c166 1597 // led1=1;
H_Tsunemoto 0:47c1b6a0c166 1598 // Loop just in case more than one character is in UART's receive FIFO buffer
H_Tsunemoto 0:47c1b6a0c166 1599 // Stop if buffer full
H_Tsunemoto 0:47c1b6a0c166 1600 while ((device.readable()) || (((rx_in + 1) % ser_buffer_size) == rx_out)) {
H_Tsunemoto 0:47c1b6a0c166 1601 rx_buffer[rx_in] = device.getc();
H_Tsunemoto 0:47c1b6a0c166 1602 // Uncomment to Echo to USB serial to watch data flow
H_Tsunemoto 0:47c1b6a0c166 1603 // monitor_device.putc(rx_buffer[rx_in]);
H_Tsunemoto 0:47c1b6a0c166 1604 //-------- 2016.05.23 Tsunemoto --------------//
H_Tsunemoto 0:47c1b6a0c166 1605 //-------- 小文字 => 大文字 変換-------------//
H_Tsunemoto 0:47c1b6a0c166 1606 if((rx_buffer[rx_in] >= 'a') && (rx_buffer[rx_in] <= 'z')){
H_Tsunemoto 0:47c1b6a0c166 1607 rx_buffer[rx_in] -= 0x20; // 'a'0x62 => 'A'0x42
H_Tsunemoto 0:47c1b6a0c166 1608 }
H_Tsunemoto 0:47c1b6a0c166 1609 //------- 2013.08.08 Tsunemoto ------------//
H_Tsunemoto 0:47c1b6a0c166 1610 // -- Char CR Rec Counter ----//
H_Tsunemoto 0:47c1b6a0c166 1611 if((rx_buffer[rx_in]== '\r') || (rx_buffer[rx_in]== '\n')){
H_Tsunemoto 0:47c1b6a0c166 1612 //led2 = 1;
H_Tsunemoto 0:47c1b6a0c166 1613 rx_cr_Rec ++;
H_Tsunemoto 0:47c1b6a0c166 1614 }
H_Tsunemoto 0:47c1b6a0c166 1615 //----------------------------//
H_Tsunemoto 0:47c1b6a0c166 1616 rx_in = (rx_in + 1) % ser_buffer_size;
H_Tsunemoto 0:47c1b6a0c166 1617 }
H_Tsunemoto 0:47c1b6a0c166 1618 // led1=0;
H_Tsunemoto 0:47c1b6a0c166 1619 return;
H_Tsunemoto 0:47c1b6a0c166 1620 }
H_Tsunemoto 0:47c1b6a0c166 1621
H_Tsunemoto 0:47c1b6a0c166 1622 // Interupt Routine to write out data to serial port
H_Tsunemoto 0:47c1b6a0c166 1623 void Tx_interrupt() {
H_Tsunemoto 0:47c1b6a0c166 1624 //led2=1;
H_Tsunemoto 0:47c1b6a0c166 1625 // Loop to fill more than one character in UART's transmit FIFO buffer
H_Tsunemoto 0:47c1b6a0c166 1626 // Stop if buffer empty
H_Tsunemoto 0:47c1b6a0c166 1627 while ((device.writeable()) && (tx_in != tx_out)) {
H_Tsunemoto 0:47c1b6a0c166 1628 device.putc(tx_buffer[tx_out]);
H_Tsunemoto 0:47c1b6a0c166 1629 tx_out = (tx_out + 1) % ser_buffer_size;
H_Tsunemoto 0:47c1b6a0c166 1630 if(i_LED_Active == Debug_LED_Active){
H_Tsunemoto 0:47c1b6a0c166 1631 led1 = 1;
H_Tsunemoto 0:47c1b6a0c166 1632 led1 = 0;
H_Tsunemoto 0:47c1b6a0c166 1633 }
H_Tsunemoto 0:47c1b6a0c166 1634 }
H_Tsunemoto 0:47c1b6a0c166 1635 //led2=0;
H_Tsunemoto 0:47c1b6a0c166 1636 return;
H_Tsunemoto 0:47c1b6a0c166 1637 }
H_Tsunemoto 0:47c1b6a0c166 1638 //----------------------------------------------------------------------------------//