/******* Standard includes *******/ #include #include #include #include /******* Libary includes *******/ #include "linux_lib.h" #include "audio_ctrl_1.h" /******* All IPCs *******/ int ipc_id[3]; /******* All Device IOs *******/ int devio_id[5]; /************************************************** * Function: main * Date : Sun Jun 22 17:21:52 2003 **************************************************/ int main( int argc, char *argv[] ) { int pid[3]; int devpid[5]; int i; struct timespec ts, rmt; int dummy[2]; /******* Linux_lib initialization *******/ sys_init(); /******* IPC channel initialization *******/ ipc_id[0] = ipc_init(LINUX_PIPE, 1); ipc_id[1] = ipc_init(LINUX_PIPE, 1); ipc_id[2] = ipc_init(LINUX_PIPE, 1); pipe(dummy); /******* Device IO initialization *******/ devio_id[0] = timer_init(DEVICE_DEFAULT, 1); devio_id[1] = tape_init(DEVICE_DEFAULT, 1); devio_id[2] = audio_sw_init(DEVICE_DEFAULT, 1); devio_id[3] = cd_init(DEVICE_DEFAULT, 1); devio_id[4] = speaker_init(DEVICE_DEFAULT, 1); /******* active device emulation process creation *******/ devpid[0] = fork() ; if (devpid[0] == 0) { device_timer_process(devio_id[0]); } devpid[1] = -1 ; devpid[2] = -1 ; devpid[3] = -1 ; devpid[4] = -1 ; /******* process creation *******/ pid[0] = fork() ; if (pid[0] == 0) { process_read_cd(); } pid[1] = fork() ; if (pid[1] == 0) { process_read_tape(); } pid[2] = fork() ; if (pid[2] == 0) { process_amplify_audio(); } ts.tv_sec = 2; ts.tv_nsec = 0; nanosleep(&ts, &rmt); #ifndef SIM_ONLY kill(pid[0], SIGKILL); kill(pid[1], SIGKILL); kill(pid[2], SIGKILL); kill(devpid[0], SIGKILL); #endif sys_end(); } /************************************************** * Function: read_cd * Date : Sun Jun 22 17:21:52 2003 **************************************************/ void process_read_cd() { /******* local variables and constants *******/ int _state_ = 0; char all_var[2049]; char *edge0 = all_var + 0; char *edge1 = all_var + 1; char *edge2 = all_var + 1025; /******* process loop *******/ while(1) { switch (_state_) { // State ID : state_0 case 0: ipc_read(LINUX_PIPE, ipc_id[2], edge0, 1); cd_read(devio_id[3], edge1, 1024); read_cd(edge0, edge1, edge2); ipc_write(LINUX_PIPE, ipc_id[1], edge2, 1024); _state_ = 0; break; } /* end switch */ } /* end while */ } /************************************************** * Function: read_tape * Date : Sun Jun 22 17:21:52 2003 **************************************************/ void process_read_tape() { /******* local variables and constants *******/ int _state_ = 0; char all_var[2050]; char *edge0 = all_var + 0; char *edge2 = all_var + 1; char *edge1 = all_var + 1025; char *edge3 = all_var + 1026; /******* process loop *******/ while(1) { switch (_state_) { // State ID : state_0 case 0: timer_read(devio_id[0], edge0, 1); tape_read(devio_id[1], edge2, 1024); main_upsem(edge0, edge1); ipc_write(LINUX_PIPE, ipc_id[2], edge1, 1); read_tape(edge1, edge2, edge3); ipc_write(LINUX_PIPE, ipc_id[0], edge3, 1024); _state_ = 0; break; } /* end switch */ } /* end while */ } /************************************************** * Function: amplify_audio * Date : Sun Jun 22 17:21:52 2003 **************************************************/ void process_amplify_audio() { /******* local variables and constants *******/ int _state_ = 0; char all_var[3073]; char *edge0 = all_var + 0; char *edge1 = all_var + 1; char *edge2 = all_var + 1025; char *edge4 = all_var + 2049; char edge3[1024]; /******* process loop *******/ while(1) { switch (_state_) { // State ID : state_0 case 0: audio_sw_read(devio_id[2], edge0, 1); ipc_read(LINUX_PIPE, ipc_id[0], edge1, 1024); ipc_read(LINUX_PIPE, ipc_id[1], edge2, 1024); choose(edge0, edge1, edge2, edge3); amplify_audio(edge3, edge4); speaker_write(devio_id[4], edge4, 1024); _state_ = 0; break; } /* end switch */ } /* end while */ }