int sc_main(int argn,char* argc[]) { sca_tdf::sca_signal<double> sig_1, sig_2; sca_tdf::sca_signal<bool> sig_3; sin_source_with_noise sin1("sin1"); sin1.out(sig_1); prefilter prefi1("lp1"); prefi1.in(sig_1); prefi1.out(sig_2); adc_sd adc1("adc1"); adc1.in(sig_2); adc1.out(sig_3); sca_trace_file* tfp = sca_create_vcd_trace_file("tb_lab2c"); sca_trace(tfp, sig_1, "sig_1"); sca_trace(tfp, sig_2, "sig_2"); sca_trace(tfp, sig_3, "sig_3"); sc_start(5.0, SC_MS); sca_close_vcd_trace_file(tfp); tfp = sca_create_tabular_trace_file("tb_ac_lab2c.dat"); tfp->set_mode(sca_ac_format(sca_util::SCA_AC_DB_DEG)); sca_trace(tfp, sig_1, "sig_1"); sca_trace(tfp, sig_2, "sig_2"); sca_trace(tfp, sig_3, "sig_3"); sca_ac_start(1.0, 1e6, 1000, SCA_LOG); return 0; }
/* Terminal writig */ void terminal( char * string){ int retPls = 0; char string_save[200]; int n; float m,o; if(strcmp (string,"help")==0){ SendStr(" \n\r"); SendStr(" \r"); SendStr("\r\n ***********************************************************************************"); SendStr("\r\n ** help menu **"); SendStr("\r\n ***********************************************************************************"); SendStr("\r\n "); SendStr(" \r auto start automatic mode and stop manual mode \r\n"); SendStr(" \r manual start manual mode and stop automatic mode \r\n"); SendStr(" \r speed update speed value (only in manual mode) \r\n"); SendStr(" \r steering update steering value (only in manual mode) \r\n"); SendStr(" \r camera update position and voltage analog values for propulsion module \r\n"); SendStr(" \r meas print currents and voltage analog values for propulsion module \r\n"); SendStr(" \r help print supported commands \r\n"); SendStr("\r control:# "); } else if(strcmp (string,"auto")==0){ SendStr("\n\r automatic mode is running\n\r"); i2c_cgroup_function(1); SendStr("\r control:# "); } else if(strcmp (string,"manual")==0){ SendStr("\n\r manual mode is running\n\r"); SendStr("\r control:# "); } else if(strcmp (string,"speed")==0){ SendStr("\n\r enter a value between 0 (stop) and 254 (full speed), 255 (reverse, speed is fixed): \n\r"); char value[4]; int i; GetStr(value); if(value[0]=='-') SendStr("\n\r error : failed value (0 to 255) "); if ( value[0] == '2'){ if ( value[1] == '5'){ if (value[2] == '5'){ for(i=0;i<=3;i++){ SendChar(value[i]); } retPls = atoi(value); PWM_CH2_Pulse(retPls); PWM_CH1_Pulse(0); } } } else if(value[3]=='\0'){ if(value[2]!='\0'){ if(value[0] =='2'){ if(value[1]<='5'){ if(value[2]<='5'){ for(i=0;i<=3;i++){ SendChar(value[i]); } retPls = atoi(value); PWM_CH1_Pulse(retPls); PWM_CH2_Pulse(0); } else SendStr("\n\r error : failed value (0 to 255) "); } else SendStr("\n\r error : failed value (0 to 255) "); } else if (value[0]<='2'){ for(i=0;i<=3;i++){ SendChar(value[i]); } retPls = atoi(value); PWM_CH1_Pulse(retPls); PWM_CH2_Pulse(0); } else SendStr("\n\r error : failed value (0 to 255)"); } else for(i=0;i<=3;i++){ SendChar(value[i]); } retPls = atoi(value); PWM_CH1_Pulse(retPls); PWM_CH2_Pulse(0); } else SendStr("\n\r error : failed value (0 to 255) "); SendStr("\n\r control:# "); } else if(strcmp (string,"steering")==0){ SendStr("\n\r enter value between -127 (full left) and 128 (full right), 0 is the middle position : \n\r"); char value[5]; int i; GetStr(value); if(value[0]=='-'){ if(value[1]=='0') SendChar(value[1]); else if (value[3]=='\0' || value[2]=='\0'){ for(i=0;i<=3;i++){ SendChar(value[i]); } retPls = atoi(value); PWM_CH3_Pulse(retPls); HAL_Delay(500); PWM_CH3_Pulse(65499); HAL_Delay(500); } else if(value[4]=='\0'){ if(value[3]!='\0'){ if(value[1] =='1'){ if(value[2]<='2'){ if(value[3]<='7'){ for(i=0;i<=3;i++){ SendChar(value[i]); } retPls = atoi(value); PWM_CH3_Pulse(retPls); HAL_Delay(500); PWM_CH3_Pulse(65499); HAL_Delay(500); } else SendStr("\n\r error : failed value (-127 to 128) "); } else SendStr("\n\r error : failed value (-127 to 128) "); } else SendStr("\n\r error : failed value (-127 to 128) "); } else for(i=0;i<=3;i++){ SendChar(value[i]); } retPls = atoi(value); PWM_CH3_Pulse(retPls); HAL_Delay(500); PWM_CH3_Pulse(65499); HAL_Delay(500); } else { SendStr("\n\r error : failed value (-127 to 128) "); } } else{ if(value[3]=='\0'){ if(value[2]!='\0'){ if(value[0] =='1'){ if(value[1]<='2'){ if(value[2]<='8'){ for(i=0;i<=3;i++){ SendChar(value[i]); } retPls = atoi(value); PWM_CH3_Pulse(retPls); HAL_Delay(500); PWM_CH3_Pulse(65499); HAL_Delay(500); } else SendStr("\n\r error : failed value (-127 to 128) "); } else SendStr("\n\r error : failed value (-127 to 128) "); } else SendStr("\n\r error : failed value (-127 to 128) "); } else for(i=0;i<=3;i++){ SendChar(value[i]); } retPls = atoi(value); PWM_CH3_Pulse(retPls); HAL_Delay(500); PWM_CH3_Pulse(65499); HAL_Delay(500); } else{ SendStr("\n\r error : failed value (-127 to 128) "); } } SendStr("\n\r control:# "); } else if(strcmp (string,"camera")==0){ SendStr("\n\r enter value between -127 (full left) and 128 (full right), 0 is the middle position : \n\r"); char value[5]; int i; GetStr(value); if(value[0]=='-'){ if(value[1]=='0'){ SendChar(value[1]); retPls = atoi(value); PWM_CH4_Pulse(retPls); HAL_Delay(5000); } else if (value[3]=='\0' || value[2]=='\0'){ for(i=0;i<=3;i++){ SendChar(value[i]); } retPls = atoi(value); PWM_CH4_Pulse(retPls); HAL_Delay(5000); } else if(value[4]=='\0'){ if(value[3]!='\0'){ if(value[1] =='1'){ if(value[2]<='2'){ if(value[3]<='7'){ for(i=0;i<=3;i++){ SendChar(value[i]); } retPls = atoi(value); PWM_CH4_Pulse(retPls); HAL_Delay(5000); } else SendStr("\n\r error : failed value (-127 to 128) "); } else SendStr("\n\r error : failed value (-127 to 128) "); } else SendStr("\n\r error : failed value (-127 to 128) "); } else{ for(i=0;i<=3;i++){ SendChar(value[i]); } retPls = atoi(value); PWM_CH4_Pulse(retPls); HAL_Delay(5000); } } else SendStr("\n\r error : failed value (-127 to 128) "); } else{ if(value[3]=='\0'){ if(value[2]!='\0'){ if(value[0] =='1'){ if(value[1]<='2'){ if(value[2]<='8'){ for(i=0;i<=3;i++){ SendChar(value[i]); } retPls = atoi(value); PWM_CH4_Pulse(retPls); HAL_Delay(5000); } else SendStr("\n\r error : failed value (-127 to 128) "); } else SendStr("\n\r error : failed value (-127 to 128) "); } else SendStr("\n\r error : failed value (-127 to 128) "); } else{ for(i=0;i<=3;i++){ SendChar(value[i]); } retPls = atoi(value); PWM_CH4_Pulse(retPls); HAL_Delay(5000); } } else SendStr("\n\r error : failed value (-127 to 128) "); } SendStr("\n\r control:# "); } else if(strcmp (string,"meas")==0){ SendStr("\n\r currents and voltage analog values for propulsion module : \n\r"); n=adc1(); m=n*3.3/255; o=m*100/24; sprintf(string_save," ADC value: adc1=%d, V=%f, I=%f \r\n control :# ", n,m,o); SendStr(string_save); SendStr("\n\r control:# "); } else{ SendStr("\n\r ERROR : command not supported. Enter help to know the supported command \n\r"); SendStr("\r control:# "); } }