int getSensorValues() { int iSensors = 0; sysOutByte(0x184,0x00); /* Disable outputs */ iSensors = (sysInByte(0x182) << 8) | (sysInByte(0x180)); sysOutByte(0x184,0x01); /* Re enable outputs */ return iSensors; }
/*Get the current sensor values by receiving the value from a port*/ int getSensorValues() { int iSensors = 0; sysOutByte(0x184,0x00); /* Disable outputs */ iSensors = (sysInByte(0x180)); /*Receive value from 0x180 as we only need 2 bytes*/ sysOutByte(0x184,0x01); /* Re enable outputs */ return iSensors; }
void initiateProcess() { sysOutByte(0x180,0x00); /* Zero out the four channels */ sysOutByte(0x181,0x00); sysOutByte(0x182,0x00); sysOutByte(0x183,0x00); sysOutByte(0x184,0x01); /* Enable Output */ iActuators = 0; }
void main (void) { unsigned char tempOut; /* Connect interrupt service routine to vector and all stuff */ intConnect (INUM_TO_IVEC(aioIntNum), my_ISR, aioIntNum); sysIntEnablePIC (aioIRQNum); /* Enable interrupts on the aio: * All interrupts and interrupt from counter 1 too */ tempOut = 0x24; sysOutByte (aioBase + intEnAddress, tempOut); /* Start counter 1 as timer with 50 ms period * It has a clock input of 1 MHz = 1 µs * Therefore the load value is 0xC350 = 50000 */ tempOut = 0x74; sysOutByte (aioBase + cntCntrlReg, tempOut); tempOut = 0x50; sysOutByte (aioBase + cnt1Address, tempOut); tempOut = 0xC3; sysOutByte (aioBase + cnt1Address, tempOut); /* Add your code here: create tasks, semaphores, ... */ //printf("Hello World!"); /*The second task shall do the following: * - It starts counter a as an auto-reload timer with a period of 50 ms. * - The interrupt generated by this counter activates the task. * This shall be done with a semaphore. * - The task reads the analog inputs of both the potentiometer and the temperature. * - If the values have changed compared to the previous ones, these shall be written into global * variables (AIn). * - A hysteresis of e.g. 10 – 20 bit is necessary due to the noise of the analog inputs. * * */ initHardware(0); int readTask; readTask = taskSpawn("tRead", 101, 0, 0x1000, (FUNCPTR) tRead,0,0,0,0,0,0,0,0,0,0); timIntSem = semBCreate(SEM_Q_PRIORITY, SEM_EMPTY); /* The third task shall do the following: * - It writes the values of the global variables (AIn) onto the display. * - This shall happen approx. each 100 ms */ int writeTask; writeTask = taskSpawn("tWrite",102,0,0x1000, (FUNCPTR) tWrite,0,0,0,0,0,0,0,0,0,0); /* Suspend own task */ taskSuspend (0); //suspended sich selber } /* main */
/*Set all ports to 0 and set actuators to both lights red*/ void initiateProcess() { sysOutByte(0x180,0x00); /* Zero out the four channels */ sysOutByte(0x181,0x00); sysOutByte(0x182,0x00); sysOutByte(0x183,0x00); sysOutByte(0x184,0x01); /* Enable Output */ /*set actuators to both lights red*/ iActuators = (IN_RED | OUT_RED); setActuatorValues(iActuators); /*the first sensor values, considered old, are obtained*/ oldSensors = getSensorValues(); }
LOCAL STATUS i8042Write( u_int32_t statReg, u_int32_t dataReg, u_int8_t data ) { STATUS status = ERROR; /* Start watchdog */ i8042Timeout = FALSE; wdStart(i8042Wdid, sysClockRateGet() * I8042_WAIT_SEC, (FUNCPTR) i8042Wd, 0); /* Wait for output buffer to be ready */ while ((sysInByte(statReg) & I8042_KBD_IBFULL) && (i8042Timeout == FALSE)); wdCancel(i8042Wdid); /* Write data */ sysOutByte(dataReg, data); if (i8042Timeout == FALSE) { status = OK; } return status; }
LOCAL STATUS i8042Command( u_int32_t cmdReg, u_int8_t cmd ) { STATUS status = ERROR; /* Start watchdog */ i8042Timeout = FALSE; wdStart(i8042Wdid, sysClockRateGet() * I8042_WAIT_SEC, (FUNCPTR) i8042Wd, 0); /* Wait for input buffer */ while ((sysInByte(cmdReg) & I8042_KBD_IBFULL) && (i8042Timeout == FALSE)); /* Send command */ sysOutByte(cmdReg, cmd); /* Wait for command completion */ while ((sysInByte(cmdReg) & I8042_KBD_IBFULL) && (i8042Timeout == FALSE)); wdCancel(i8042Wdid); if (i8042Timeout == FALSE) { status = OK; } return status; }
void my_ISR (void) { /* Add your code here! */ //printf("."); semGive (analogInputs); /* Clear AIO interrupts by writing anything to a specified address */ sysOutByte (aioBase + intClearAddress, 0); }
void my_ISR (void) { /* Add your code here! */ //printf("."); /* ISR soll Semaphore geben */ semGive (timIntSem); /* Clear AIO interrupts by writing anything to a specified address */ sysOutByte (aioBase + intClearAddress, 0); }
int readInputs (void) { unsigned char tempOut; /* Connect interrupt service routine to vector and all stuff */ intConnect (INUM_TO_IVEC(aioIntNum), my_ISR, aioIntNum); sysIntEnablePIC (aioIRQNum); /* Enable interrupts on the aio: * All interrupts and interrupt from counter 1 too */ tempOut = 0x24; sysOutByte (aioBase + intEnAddress, tempOut); /* Start counter 1 as timer with 50 ms period * It has a clock input of 1 MHz = 1 µs * Therefore the load value is 0xC350 = 50000 */ tempOut = 0x74; sysOutByte (aioBase + cntCntrlReg, tempOut); tempOut = 0x50; sysOutByte (aioBase + cnt1Address, tempOut); tempOut = 0xC3; sysOutByte (aioBase + cnt1Address, tempOut); int poti; int temp; int hyst = 15; while(1){ semTake (analogInputs, WAIT_FOREVER); poti = readAnalog (2, 0); temp = readAnalog (5, 2); //printf ("Werte %d %d \n", poti, temp); if ((poti > globalPoti+hyst) | (poti < globalPoti-hyst)) { globalPoti = poti; } if ((temp > globalTemp+hyst) | (temp < globalTemp-hyst)) { globalTemp = temp; } } }
/*Set the actuator values by sending the current actuator values to a port*/ void setActuatorValues(int iActuators) { sysOutByte(0x184,0x01); /* Re enable outputs */ sysOutByte(0x181,(iActuators & 0x003F)); /*send the lowest 6 bits of iActuators to memory location 0x181*/ }
void setActuatorValues(int iActuators) { sysOutByte(0x184,0x01); /* Re enable outputs */ sysOutByte(0x181,(iActuators & 0x007F)); /*We only have 6 actuators*/ }