void execute() { if(!back)//perform user commands given { if(strcmp(command[0],"quit")==0) exit(0); else if(strcmp(command[0],"cd")==0) cd(); else if(strcmp(command[0],"fg")==0) { int com=(int)(command[1][0]-'0'); fg(com); } else if(strcmp(command[0],"overkill")==0) overkill(); else if(strcmp(command[0],"pinfo")==0) { if(!ch) { strcpy(list[p5].process,"pinfo"); list[p5].back=0; } if(command[1][0]==0)//if only single argument given with pinfo command pinfo(); else { int i=0,comm1,number=0,num1; int len1=strlen(command[1]); if(len1==4) num1=10*10*10; else if(len1==3) num1=10*10; else if(len1==2) num1=10; else if(len1==1) num1=1; while(i<len1) { comm1=(int)(command[1][i]-'0'); number=num1*comm1+number; num1=num1/10; i++; } pid1(number); } } else if(strcmp(command[0],"jobs")==0) { if(!ch) { strcpy(list[p5].process,"jobs"); list[p5].back=0; } jobs(); } else if(strcmp(command[0],"grep")==0) grep(); else if(strcmp(command[0],"kjob")==0) { int comm=command[1][0]-'0'; int comm2=(int)(command[2][0]-'0'); char *c1=command[1][0]; char *c2=command[2][0]; kjob((c1),(c2)); } else if(strcmp(command[0],"exit")==0) fprintf(stderr,"The command is quit\n"); else//for system defined commands { if(!ch) { strcpy(list[p5].process,command[0]); list[p5].back=0; } int returnval=fork(); if(returnval) { list[p5++].pid=returnval; waitpid(returnval,&returnval,0); } else { int i2=0; char arguments[101]; char *args[argvals+1]; while(i2<argvals) { args[i2]=(char*)malloc(101*sizeof(char)); strcpy(args[i2],command[i2]); i2++; } args[i2]=NULL; int flag2=1; if(redir_in)//incase of redirection { if(redir_in<argvals -1) { freopen(command[redir_in + 1],"r",stdin); args[redir_in]=NULL; } else { fprintf(stderr,"Give filename for redirection\n"); exit(0); } } if(redir_out) { if(redir_out < argvals -1) { freopen(command[redir_out + 1],"w",stdout); args[redir_out]=NULL; } else { fprintf(stderr,"Give filename for redirection\n"); exit(0); } } printf("%s",*args); flag2=0; execvp(args[0],args);//execute the command in arg fprintf(stderr,"Not a valid shell command\n"); exit(0); } } } else { if(!ch) { strcpy(list[p5].process,command[0]); list[p5].back=1; } int returnval=fork(); if(returnval) { if(!ch) list[p5++].pid=returnval; printf("Command %s\t Pid %d\n",command[0],returnval); } else { int i2=0; int flag3=0; char *args[argvals]; while(i2<back) { args[i2]=(char*)malloc(101*sizeof(char)); strcpy(args[i2],command[i2]); i2++; flag3=1; } args[i2]=NULL; execvp(args[0],args);//execute the command in args fprintf(stderr,"Not a valid Shell command\n"); exit(0); } } }
void TIM8_UP_TIM13_IRQHandler(void) { float I1 = 0, I2 = 0, power = 0; static float percent = 0, percent1 = 0 ; float error_pid = 0; static uint16_t interrupt_times = 0; // static uint8_t flag_modbus = 0; // rt_enter_critical();/*调度器上锁*/ rt_interrupt_enter(); logic_out(1,1); I1 = adc_get(0);//电流值 // I2 = adc_get(1); power = adc_get(2);//功率百分比 trig_adc(); if(interrupt_times < 500) { p_get[interrupt_times] = power; i_get[interrupt_times] = I1; } if(TIM_GetITStatus(TIM8, TIM_IT_Update) != RESET) { TIM_ClearITPendingBit(TIM8, TIM_IT_Update); if(pwm_struct[select_pwm].mode == 0) { // TIM_SetCompare1(TIM8, (uint16_t)(percent * pwm_period)); if(interrupt_times < pwm_struct[select_pwm]. positive_pulse) { pwm_struct[select_pwm].busy_flag = 1; pwm_ena(1); { error_pid = pwm_struct[select_pwm].p_array[interrupt_times] \ * program_data[select_pwm].current_max - I1; // logic_out(1,1); percent = pid3(error_pid); // logic_out(1,0); if(percent > 0.98f) percent = 0.98f; if(percent < 0.0f) percent = 0.0f; // percent = 0.3f; interrupt_times++; } } else { interrupt_times++; percent = 0; if( interrupt_times > pwm_struct[select_pwm].positive_pulse + pwm_struct[select_pwm].negative_pulse) { TIM_Cmd(TIM8, DISABLE); TIM_ClearITPendingBit(TIM8, TIM_IT_Update); pwm_ena(0); interrupt_times = 0; pwm_struct[select_pwm].busy_flag = 0; IntTerm_C3 = 0; PrevError_C3 = 0; } } } else { if(interrupt_times < pwm_struct[select_pwm]. positive_pulse) { pwm_struct[select_pwm].busy_flag = 1; pwm_ena(1); { // logic_out(1,1); error_pid = pwm_struct[select_pwm].p_array[interrupt_times] - power; percent1 = pid1(error_pid);//percent1为计算得出的电流值 if(percent1 > program_data[select_pwm].current_max) percent1 = program_data[select_pwm].current_max; if(percent1 < 0.0f) percent1 = 0.0f; error_pid = percent1 - I1; percent = pid3(error_pid); // logic_out(1,0); if(percent > 0.98f) percent = 0.98f; if(percent < 0.0f) percent = 0.0f; // percent = 0.3f; interrupt_times++; } } else { interrupt_times++; percent = 0; if( interrupt_times > pwm_struct[select_pwm].positive_pulse + pwm_struct[select_pwm].negative_pulse) { TIM_Cmd(TIM8, DISABLE); TIM_ClearITPendingBit(TIM8, TIM_IT_Update); pwm_ena(0); interrupt_times = 0; pwm_struct[select_pwm].busy_flag = 0; IntTerm_C3 = 0; PrevError_C3 = 0; IntTerm_C1 = 0; PrevError_C1 = 0; } } } TIM_SetCompare1(TIM8, (uint16_t)(pwm_period * percent)); if(interrupt_times < 500) { pid_out[interrupt_times] = percent; code[interrupt_times] = TIM8->CCR1; } } logic_out(1,0); rt_interrupt_leave(); // rt_exit_critical();/* 退出临界区*/ }