int elev_get_floor_sensor_signal(void) { if (io_read_bit(SENSOR_FLOOR1)) return 0; else if (io_read_bit(SENSOR_FLOOR2)) return 1; else if (io_read_bit(SENSOR_FLOOR3)) return 2; else if (io_read_bit(SENSOR_FLOOR4)) return 3; else return -1; }
int ElevInterface::get_floor_sensor_signal(void) { if (io_read_bit(SENSOR_FLOOR1)) { return 0; } else if (io_read_bit(SENSOR_FLOOR2)) { return 1; } else if (io_read_bit(SENSOR_FLOOR3)) { return 2; } else if (io_read_bit(SENSOR_FLOOR4)) { return 3; } else { return -1; } }
int elev_get_button_signal(elev_button_type_t button, int floor) { assert(floor >= 0); assert(floor < N_FLOORS); assert(button >= 0); assert(button < N_BUTTONS); return io_read_bit(button_channel_matrix[floor][button]); }
static void *polling_thread(void *p) { // Store previous values of inputs, raise signal if changed between // two polls. static int prev_values[N_FLOORS][N_SIGNALS]; memset(prev_values, 0, sizeof(prev_values)); while (1) { int type, floor; for (type = 0; type < N_SIGNALS; type++){ for (floor = 0; floor < N_FLOORS; floor++){ int value = io_read_bit(signal_channel_matrix[floor][type]); // If no associated callback: ignore. if (callbacks_g[type] == NULL) { ; } // If value has not changed, ignore. else if (value == prev_values[floor][type]) { ; } // Obstruction is raised on any edge, with new value as param. else if (type == SIGNAL_TYPE_OBSTR) { callbacks_g[type](0, value); } // STOP is called with no arguments, only when pushed (not when // released). else if (type == SIGNAL_TYPE_STOP && value == 1) { callbacks_g[type](0, 0); } // Floor sensor is raised on any edge, entering and leaving floor, // with floor and value (edge) as param. else if (type == SIGNAL_TYPE_SENSOR) { callbacks_g[type](floor, value); } // Other signals (CALL_UP, CALL_DOWN, COMMAND) are raised on // rising edge only, with floor and type as parameters. else if (value == 1) { callbacks_g[type](floor, type); } // Store current value of signal to avoid multiple calls on the // same signal. prev_values[floor][type] = value; // Obstr and stop is not floor dependent, so only loop once. if (type == SIGNAL_TYPE_OBSTR || type == SIGNAL_TYPE_STOP) break; } } usleep(POLLING_INTERVAL); } return NULL; }
int elev_get_button_signal(elev_button_type_t button, int floor) { assert(floor >= 0); assert(floor < N_FLOORS); assert(!(button == BUTTON_CALL_UP && floor == N_FLOORS - 1)); assert(!(button == BUTTON_CALL_DOWN && floor == 0)); assert(button == BUTTON_CALL_UP || button == BUTTON_CALL_DOWN || button == BUTTON_COMMAND); if (io_read_bit(button_channel_matrix[floor][button])) return 1; else return 0; }
//own added function reads FLOOR_IND1 and FLOOR_IND2 and returns the floor number which the elevator was at. //returns previous floor from 0 to 3 int ui_get_floor_indicator(void) { //int bit1 =io_read_bit(FLOOR_IND1); //int bit2 =io_read_bit(FLOOR_IND2); if (io_read_bit(FLOOR_IND1)==0 && io_read_bit(FLOOR_IND2)==0) return 0; if(io_read_bit(FLOOR_IND1) == 0 && io_read_bit(FLOOR_IND2) == 1) return 1; if(io_read_bit(FLOOR_IND1) == 1 && io_read_bit(FLOOR_IND2) == 0) return 2; if(io_read_bit(FLOOR_IND1) == 1 && io_read_bit(FLOOR_IND2) == 1) return 3; // else return -1; //for debugging purposes }
int ui_get_button_signal(int button, int floor) { // assert crashes the program deliberately if it's condition does not hold, // and prints an informative error message. Useful for debugging. assert(floor >= 0); assert(floor < N_FLOORS); assert(!(button == BUTTON_CALL_UP && floor == N_FLOORS-1)); assert(!(button == BUTTON_CALL_DOWN && floor == 0)); assert(button == BUTTON_CALL_UP || button == BUTTON_CALL_DOWN || button == BUTTON_COMMAND); if (io_read_bit(button_channel_matrix[floor][button])) return 1; else return 0; }
int elev_get_stop_signal(void) { return io_read_bit(STOP); }
int elev_get_obstruction_signal(void) { return io_read_bit(OBSTRUCTION); }
int elev_get_motor_dir(void){ return io_read_bit(MOTORDIR); }
void elev_toggle_stop_lamp() { if(io_read_bit(LIGHT_STOP)) io_clear_bit(LIGHT_STOP); else io_set_bit(LIGHT_STOP); }
int elev_if_emergency() { return io_read_bit(LIGHT_STOP); }
CallBack events_swi_cm920iap_handler (int swi_number, SwiRegs *r) { switch (swi_number) { /********************************************************************** * SLOS SWI's **********************************************************************/ case /* SWI */ SLOS: switch (r->r[0]) { /* ----------------------------------------------------------------- * Low level Debug SWI for debugging before the operating system is * up and running. The following register hold the debug information. * * r8fiq - fatal error * r9fiq - trace entry value * r10fiq - trace exit value * * ----------------------------------------------------------------- */ case /* SWI */ BringUp_Trace: switch (r->r[1]) { case 123: /* ENTRY into routine ...................... */ bringupSetR9fiq (r->r[2]); break; case 321: /* EXIT into routine ....................... */ bringupSetR10fiq (r->r[2]); break; } break; case /* SWI */ BringUp_FatalError: bringupSetR8fiq (r->r[1]); fatalerror: goto fatalerror; /* setup infinite loop ... */ break; /* ----------------------------------------------------------------- * Device Driver SWI's for controlling and initializing device * drivers * ----------------------------------------------------------------- */ case /* SWI */ Event_IODeviceInit: io_initialize_drivers (); break; default: /* ---------------------------------------------------------------- * switch to SYSTEM mode and switch ON IRQ interrupts. * ---------------------------------------------------------------- */ if (STATE!=1) {modifyControlCPSR (SYSTEM|IRQoN);} switch (r->r[0]) { case /* SWI */ Event_IODeviceOpen: r->r[0] = (unsigned int) io_open_driver ((UID *)r->r[1],r->r[2],r->r[3]); break; case /* SWI */ Event_IODeviceClose: r->r[0] = (unsigned int) io_close_driver ((device_treestr *)r->r[1],(UID)r->r[2]); break; case /* SWI */ Event_IODeviceWriteByte: io_write_byte ((device_treestr *)r->r[1],(UID)r->r[2],(BYTE)r->r[3]); break; case /* SWI */ Event_IODeviceReadByte: r->r[0] = (unsigned int) io_read_byte ((device_treestr *)r->r[1],(UID)r->r[2]); break; case /* SWI */ Event_IODeviceWriteBit: io_write_bit ((device_treestr *)r->r[1],(UID)r->r[2],(UINT)r->r[3]); break; case /* SWI */ Event_IODeviceReadBit: r->r[0] = (unsigned int) io_read_bit ((device_treestr *)r->r[1],(UID)r->r[2]); break; case /* SWI */ Event_IODeviceWriteBlock: io_write_block ((device_treestr *)r->r[1],(UID)r->r[2],(void *)r->r[3]); break; case /* SWI */ Event_IODeviceReadBlock: r->r[0] = (unsigned int) io_read_block ((device_treestr *)r->r[1],(UID)r->r[2]); break; } if (STATE!=1) {modifyControlCPSR (SVC|IRQoFF);} } } return ReportOK(); }
int elev_get_motor_direction(){ return io_read_bit(MOTORDIR); }