void Inita2DSub() { // Configure the A2D pins as analog inputs Pins[11].function( PIN11_AN2 ); Pins[12].function( PIN12_AN1 ); Pins[13].function( PIN13_AN0 ); Pins[14].function( PIN14_AN3 ); Pins[15].function( PIN15_AN7 ); Pins[16].function( PIN16_AN6 ); Pins[17].function( PIN17_AN5 ); Pins[18].function( PIN18_AN4 ); /* Enable the A2D. The A2D subsystem will run in the background doing samples at 98.742Khz per channel. This is all done in hardware with no CPU overhead. */ EnableAD(); }
//=====================================System Initializations========================================// void _init (void){ int i; DWORD res = 0; //-------------------------------------General System--------------------------------------------// SimpleUart(0,SystemBaud);assign_stdio(0); // Serial port 0 for Data SimpleUart(1,SystemBaud); // Serial port 1 for Debug EnableSmartTraps(); #ifdef _DEBUG InitGDBStubNoBreak( 1, 115200 ); #endif OSChangePrio(MAIN_PRIO); //Other EnableSerialUpdate(); iprintf("\n\n\n\n\n\n\n\nINITIALIZATION\n"); putleds(8); iprintf("Version Number --> %s\n", ftos(versionNo, 3)); createVERIFY_KEY(); // Using versionNo to update Flash DDBB //--------------------------------------I2C Bus Connection---------------------------------------// I2CInit(MCF5213_I2C_ADDRESS, I2C_FREQUENCY); // Initialize I2C with Predefined Address (0x20) // Set frequency division to 768 (66Mhz CF clock --> 88,25 Khz I2C bus) iprintf(" .Initialized I2C address for MCF5213: 0x%x\r\n",MCF5213_I2C_ADDRESS); iprintf(" -Set I2C Frequency division: %x (MCF internal CLK / 1280)\r\n",I2C_FREQUENCY); //-------------------------------------SPI Bus Connection----------------------------------------// res=true; for (i = 0; i<PSU_NUMBER; i++){ res &=configureSPI( INIT_SPI_ORDER, INIT_SPI_CPOL, INIT_SPI_CPHA, INIT_SPI_CLKRATE, i2CtoSPIAddress[i]); } if(res==I2C_OK){iprintf(" .SPI bus configured\r\n");} else{iprintf(" .SPI configuration ERROR - Coudn't be configured\r\n");} //-----------------------------------RDACs with minimum value------------------------------------// res = 0; for (i = 0; i<PSU_NUMBER; i++){ setValRDAC(INITIAL_VOLTAGE, (i&0x1?UPPER_SLAVE_SPI_ADDRESS:LOWER_SLAVE_SPI_ADDRESS), i2CtoSPIAddress[i]); res |= getI2CResultRDAC(); } if(res==I2C_OK){iprintf(" .RDACs set to minimum value\r\n");} else{iprintf(" .RDAC setting ERROR - Couldn't be set to minimum value\r\n");} //----------------------------------------DataLists----------------------------------------------// initializeValuesPSUsSnIs(); // Load psuList values from RAM or set them to default for (i = 0; i<PSU_NUMBER; i++){ // Start all PSU objects in OFF status, regardless of the loaded status psuList[i].relayStatus = OFF; psuList[i].psuStatus = OFF; psuList[i].ReadyToConnect = false; } //-------------------------------------------GPIO------------------------------------------------// RESET_RHEOSTATS.function( PIN21_GPIO ); // RDAC Reset LED_OUT_ON.function( PIN7_GPIO ); // LED OUT iprintf(" .Pin 21 (TIN3) set as GPIO for RDAC Reset\r\n"); iprintf(" .Pin 7 (IRQ4) set as GPIO for LED OUT\r\n"); //----------------------------------Analog to Digital Converter----------------------------------// Pins[13].function( PIN13_AN0 ); // Configure the A2D pin nº13 as analog input EnableAD(); initMUX(); // Initializes all the Pins used for Mux control res=configureSPI( INIT_SPI_ORDER, INIT_SPI_CPOL, INIT_SPI_CPHA, INIT_SPI_CLKRATE, AGC_I2C_ADDRESS); minAGC(); // Initializes the AGC with minimum gain res = (getI2CResultAGC()==I2C_OK); if(res){iprintf(" .ADC initialized\r\n");} else{iprintf(" .ADC initialization ERROR\r\n");} //--------------------------------------Button Interruption--------------------------------------// SetUpIRQ1(); iprintf(" .Button Interruption Set\r\n"); //---------------------------------------TimerInterruptions--------------------------------------// //SetUpPITR(0, 8294, 1); //Use PITR 0, Wait 8294 clocks, Divide by 2 from table 17-3, 2KHz - NOT IN USE, messes with RTOS Tasks. Best left unused SetUpPITR(1, 16588, 1); // Use PITR 1, Wait 16588 clocks, Divide by 2 from table 17-3, 1KHz - Interrupt in charge of A2D sampling iprintf(" .Timers initialized\r\n"); //----------------------------------------- RTOS Tasks-------------------------------------------// OSSimpleTaskCreate( alarmTask, ALARM_PRIO ); iprintf(" .alarmTask initialized\r\n"); iprintf(" .MonitorSem %s\n", (allSemInit()==OS_NO_ERR?"Initialized CORRECTLY":"Initialization ERROR")); OSSimpleTaskCreate( monitorTask, MONITOR_PRIO ); iprintf(" .monitorTask initialized\r\n"); iprintf("APPLICATION INITIALIZED\n\nPress one key to begin \n\n"); WAIT_FOR_KEYBOARD putleds(0); }