/*************************************** * hv_stop.c * * * ***************************************/ #include #include #include #include #include #include "../lib/mylib1.h" #include "a200.h" #include "../dbase/hv_dbase.h" #define STOP 1003 extern int os9forkc(); extern char **environ; char *argblk[5]; int hra[6]; int ev127_id; FILE *fp, *fopen(); main(argc,argv) int argc; char **argv; { SY127_MBOX *mod127; SY227_MBOX *mod227; PROCS_INFO *hv_procs_mod; hv_mod_struct *hv_mid; int tcp_ip_nr, cpu_nr; char *hv_config[3]; int ev127_id, ev227_id, evpro_id; int i, iev, tcycle; int still_running; char parm[20]; unsigned long pid; FILE *pipe; int sy127_crate; if (argc < 2) usage(); if (strcmp(argv[1], "ok") && strcmp(argv[1], "OK")) usage(); /* link to semaphore */ evpro_id = sem_link("hv_pr_info", argv[0]); ev127_id = sem_link("sy127mod", argv[0]); ev227_id = sem_link("sy227mod", argv[0]); if((hv_procs_mod = (PROCS_INFO *)modlink("hv_pr_info", 0)) == (PROCS_INFO *)-1) /* exit(_errmsg(errno, */ printf( "hv_stop: err. link data module hv_procs_info, errno %d\n", errno); get_config(&tcp_ip_nr, &cpu_nr, hv_config); if ((hv_mid = (hv_mod_struct *)modlink(hv_config[cpu_nr], 0)) == (hv_mod_struct *)-1) if ((hv_mid = (hv_mod_struct *)modload(hv_config[cpu_nr], 0)) == (hv_mod_struct *)-1) exit(_errmsg(errno, " %s: error loading/linking module %s\n", argv[0], hv_config[cpu_nr])); sy127_crate = hv_mid->hv_crate; sem_wait(evpro_id, argv[0]); /* stop V and I monitor sender */ if ( (pid = hv_procs_mod->sy127_vi_send_id) != 0){ if (hv_procs_mod->sy127_vi_send_active) hv_procs_mod->sy127_vi_send_com = STOP; else { if (kill(pid, STOP) == -1) exit(_errmsg(errno,"%s: error killing sy127_vi_send \n", argv[0])); } } if ( (pid = hv_procs_mod->sy227_vi_send_id) != 0){ if (hv_procs_mod->sy227_vi_send_active) hv_procs_mod->sy227_vi_send_com = STOP; else { if (kill(pid, STOP) == -1) exit(_errmsg(errno,"%s: error killing sy227_vi_send \n", argv[0])); } } /* stop V and I monitor */ if ( (pid = hv_procs_mod->sy127_vi_mon_id) != 0){ if (hv_procs_mod->sy127_vi_mon_active) hv_procs_mod->sy127_vi_mon_com = STOP; else { if (kill(pid, STOP) == -1) exit(_errmsg(errno,"%s: error killing sy127_vi_mon \n", argv[0])); } } /* stop STATUS monitor */ if ( (pid = hv_procs_mod->sy127_st_mon_id) != 0){ if (hv_procs_mod->sy127_st_mon_active) hv_procs_mod->sy127_st_mon_com = STOP; else { if (kill(pid, STOP) == -1) exit(_errmsg(errno,"%s: error killing sy127_st_mon \n", argv[0])); } } /* stop Parameter monitor */ if ( (pid = hv_procs_mod->sy127_par_mon_id) != 0){ if (hv_procs_mod->sy127_par_mon_active) hv_procs_mod->sy127_par_mon_com = STOP; else { if (kill(pid, STOP) == -1) exit(_errmsg(errno,"%s: error killing sy127_par_mon \n", argv[0])); } } /* stop SY227 STATUS monitor */ if ( (pid = hv_procs_mod->sy227_st_mon_id) != 0){ if (hv_procs_mod->sy227_st_mon_active) hv_procs_mod->sy227_st_mon_com = STOP; else { if (kill(pid, STOP) == -1) exit(_errmsg(errno,"%s: error killing sy227_st_mon \n", argv[0])); } } /* stop SY227 vmon imon monitor */ if ( (pid = hv_procs_mod->sy227_vi_mon_id) != 0){ if (hv_procs_mod->sy227_vi_mon_active) hv_procs_mod->sy227_vi_mon_com = STOP; else { if (kill(pid, STOP) == -1) exit(_errmsg(errno,"%s: error killing sy227_vi_mon \n", argv[0])); } } /* stop xxcond */ if ( (pid = hv_procs_mod->xxcond_id) != 0){ if (hv_procs_mod->xxcond_active) hv_procs_mod->xxcond_com = STOP; else { if (kill(pid, STOP) == -1) exit(_errmsg(errno,"%s: error killing xxcond\n", argv[0])); } } /* stop a200_resetter*/ if ( (pid = hv_procs_mod->a200_resetter_id) != 0){ if (hv_procs_mod->a200_resetter_active) hv_procs_mod->a200_resetter_com = STOP; else { if (kill(pid, STOP) == -1) exit(_errmsg(errno,"%s: error killing a200_resetter\n", argv[0])); } } sem_free(evpro_id, argv[0]); /* wait that all processes have finished */ do{ tsleep(BIT32 | 128); /* wait 0.5 seconds */ still_running = 0; sem_wait(evpro_id, argv[0]); if (hv_procs_mod->sy127_vi_send_id) still_running++; if (hv_procs_mod->sy227_vi_send_id) still_running++; if (hv_procs_mod->sy127_st_mon_id) still_running++; if (hv_procs_mod->sy127_vi_mon_id) still_running++; if (hv_procs_mod->sy127_par_mon_id) still_running++; if (hv_procs_mod->sy227_st_mon_id) still_running++; if (hv_procs_mod->sy227_vi_mon_id) still_running++; if (hv_procs_mod->a200_resetter_id) still_running++; sem_free(evpro_id, argv[0]); } while (still_running); /* enable keyboard */ argblk[0] = "sy127_set"; argblk[1] = "0"; /* first argument is dummy */ itoa(sy127_crate, parm); argblk[2] = parm; argblk[3] = "70"; argblk[4] = "4"; /* bit 2 = 1 */ argblk[5] = 0; if ((pid=os9exec(os9forkc,argblk[0],argblk,environ,0,0,3)) == -1) exit(_errmsg(0," error returned from os9exec(%s) \n", argblk[0])); wait(0); /* delete semaphores related to the modules */ sem_unl_del(ev127_id, "sy127mod", argv[0]); sem_unl_del(ev227_id, "sy227mod", argv[0]); sem_unl_del(evpro_id, "hv_pr_info", argv[0]); /* unlink dbase module */ munlink(hv_mid); /* unload the other modules */ while(1){ if ( (int) munload("sy127mod", 0) == -1) break; } while(1){ if ( (int) munload("sy227mod", 0) == -1) break; } while(1){ if ( (int) munload("hv_pr_info", 0) == -1) break; } } usage() { printf(" hv_stop : stops hwc system \n\n"); printf(" usage : hv_stop ok \n"); exit(0); }