/************************************************************************* $Archive: /PACS/OnBoard/CsCtrl2.c $ $Revision: 29 $ $Date: 3/14/06 4:31p $ $Author: Pacs Egse $ $Log: /PACS/OnBoard/CsCtrl2.c $ * * 29 3/14/06 4:31p Pacs Egse * Version 6.001 * Cleaned and commented *************************************************************************/ #ifdef SIMULATOR #include "virtuosoSim.h" #else // SIMULATOR #include "v_macro.h" #include "node1.h" #include "k_struct.h" #endif #include "params.h" #include "error.h" #ifndef SIMULATOR K_ARGS gSemaCS2; #endif //SIMULATOR //**************************************************************** // MACRO //**************************************************************** //macro to signal an error in Cal Src 2 Controller Task #define SetError(newError) \ {\ SetGlobalError(newError);\ LOCK_WRITE_RES_PARAMS;\ SET_BITS(gpCS2Controller->TaskStatus, K_BMASK_TASK_STATUS_ERROR_STATUS | K_BMASK_TASK_STATUS_ERROR_CODE, K_BMASK_TASK_STATUS_TASK_IN_ERROR + newError); \ UNLOCK_WRITE_RES_PARAMS;\ }\ //**************************************************************** // LOCAL PARAMETERS //**************************************************************** //**************************************************************** // FUNCTION DECLARATION //**************************************************************** extern void* memset(void *, int, size_t); extern void ExecuteCSController(CsControllerParams* p_controller); void InitializeCS2Ctrl(); void CS2Ctrl(); // commands functions BOOL CommandSwitchOnCS2Ctrl(CommandParameter paramNotUsed); BOOL CommandSwitchOffCS2Ctrl(CommandParameter paramNotUsed); BOOL CommandEnableCS2Ctrl(CommandParameter paramNotUsed); BOOL CommandDisableCS2Ctrl(CommandParameter paramNotUsed); BOOL CommandSetCS2Temp(CommandParameter param); BOOL CommandSetCS2Voltage(CommandParameter param); //**************************************************************** // FUNCTION IMPLEMENTATION //**************************************************************** /* FUNCTION : void InitializeCS2Ctrl() *********************************** AUTHOR : AMazy USE : Initialize Calibration source 2 Controller task. */ void InitializeCS2Ctrl() { #ifndef SIMULATOR //initialize the structure that will be used to signal the semaphore to trigger the task gSemaCS2.Srce = 0; gSemaCS2.Comm = SIGNALS; gSemaCS2.Args.s1.sema = SEMA_TIMER_CS_2; #endif //SIMULATOR // initialize status LOCK_WRITE_RES_PARAMS; InitializeCsControllerParams(gpCS2Controller); UNLOCK_WRITE_RES_PARAMS; } /* TASK_FUNCTION : void CS2Ctrl() ****************************** AUTHOR : AMazy This function implements the Calibration Source 2 Controller It is triggerd by a semaphore signaled at regular interval (500ms) in the interrupt routine */ void CS2Ctrl() { InitializeCS2Ctrl(); while (1) { //wait to be awaken every 500ms if the CS Controller is switched on KS_SemaTestW(SEMA_TIMER_CS_2); if (TEST_ONE_BIT(gpCS2Controller->TaskStatus, K_BMASK_PID_CTRL_STATUS_POWER_ON)) { ExecuteCSController(gpCS2Controller); } } } /* CMD_FUNCTION : BOOL CommandSwitchOnCS2Ctrl(CommandParameter paramNotUsed) ************************************************************************* AUTHOR : Amazy USE : Switch on Calibration source 1 controller */ BOOL CommandSwitchOnCS2Ctrl(CommandParameter paramNotUsed) { int i=0; // change the status and start in 'measure only' mode LOCK_WRITE_RES_PARAMS; SET_BIT(gpCS2Controller->TaskStatus, K_BMASK_PID_CTRL_STATUS_POWER_ON | K_BMASK_CS_CTRL_STATUS_MEASURE_ONLY); UNLOCK_WRITE_RES_PARAMS; // reset variables gpCS2Controller->Output = 0; gpCS2Controller->PeriodCounter = gpCS1Controller->PeriodCounter + 2; gpCS2Controller->Accumulator = 0.0f; // validate the houskeeping related to the Calibration source VALIDATE_HK(DMC_CS2_RES_VALUE); VALIDATE_HK(DMC_CS2_OUTPUT); VALIDATE_HK(DMC_CS2_TARGET); VALIDATE_HK(DMC_CS2_VOLT_0V); for (i=DMC_CS2_VOLT_DAC_OUT; i <= DMC_CS2_CUR_BG; i++) { VALIDATE_HK(i); } SequencerSendAck(DMC_SWON_BB_2_CONT); return FALSE; } /* CMD_FUNCTION : BOOL CommandSwitchOffCS2Ctrl(CommandParameter paramNotUsed) ************************************************************************** AUTHOR : Amazy USE : Switch off Calibration source 2 controller */ BOOL CommandSwitchOffCS2Ctrl(CommandParameter paramNotUsed) { int i=0; // make sure output is zero gpCS2Controller->Output = 0; // change the status LOCK_WRITE_RES_PARAMS; CLEAR_BIT(gpCS2Controller->TaskStatus, K_BMASK_PID_CTRL_STATUS_POWER_ON | K_BMASK_CS_CTRL_STATUS_MEASURE_ONLY | K_BMASK_PID_CTRL_STATUS_PID_ENABLED); UNLOCK_WRITE_RES_PARAMS; // invalidate the houskeeping related to the Calibration source INVALIDATE_HK(DMC_CS2_RES_VALUE); INVALIDATE_HK(DMC_CS2_OUTPUT); INVALIDATE_HK(DMC_CS2_TARGET); INVALIDATE_HK(DMC_CS2_VOLT_0V); for (i=DMC_CS2_VOLT_DAC_OUT; i <= DMC_CS2_CUR_BG; i++) { INVALIDATE_HK(i); } SequencerSendAck(DMC_SWOF_BB_2_CONT); return FALSE; } /* CMD_FUNCTION : BOOL CommandSetCS2Temp(CommandParameter param) ************************************************************* AUTHOR : Amazy USE : Set the target temperature for Calibration source 2 PARAMS : Uint resistor value. units : resistor value (1 unit = 100 ľohms) */ BOOL CommandSetCS2Temp(CommandParameter param) { // change the target gpCS2Controller->Target = param.Uint; SequencerSendAck(DMC_SET_TEMP_BB_2); return FALSE; } /* CMD_FUNCTION : BOOL CommandSetCS2Voltage(CommandParameter param) **************************************************************** AUTHOR : Amazy USE : Set the voltage directly for calibration source 1 PARAMS : Int voltage. */ BOOL CommandSetCS2Voltage(CommandParameter param) { // the command is available only if the PID is disabled if (TEST_ONE_BIT(gpCS2Controller->TaskStatus, K_BMASK_PID_CTRL_STATUS_PID_ENABLED)) { SequencerSendNack(0, COULD_NOT_EXECUTE_COMMAND); SetSequencerError(ERR_SEQUENCER_COULD_NOT_EXECUTE_COMMAND); return FALSE; } // directly set the output to the value requested gpCS2Controller->Output = param.Int; if (param.Int != 0) { // if we apply a voltage, don't need to be in measure mode CLEAR_BIT(gpCS2Controller->TaskStatus, K_BMASK_CS_CTRL_STATUS_MEASURE_ONLY); } else { // if no voltage is applied, go back in measure only mode SET_BIT(gpCS2Controller->TaskStatus, K_BMASK_CS_CTRL_STATUS_MEASURE_ONLY); } SequencerSendAck(DMC_SET_BB_2_VOLTAGE); return FALSE; } /* CMD_FUNCTION : BOOL CommandEnableCS2Ctrl(CommandParameter paramNotUsed) *********************************************************************** AUTHOR : Amazy USE : Enable the CS2 controller */ BOOL CommandEnableCS2Ctrl(CommandParameter paramNotUsed) { // the CS must already be powered on if (!TEST_ONE_BIT(gpCS2Controller->TaskStatus, K_BMASK_PID_CTRL_STATUS_POWER_ON)) { SequencerSendNack(0, COULD_NOT_EXECUTE_COMMAND); SetSequencerError(ERR_SEQUENCER_COULD_NOT_EXECUTE_COMMAND); return FALSE; } // change the status SET_BIT(gpCS2Controller->TaskStatus, K_BMASK_PID_CTRL_STATUS_PID_ENABLED); SequencerSendAck(DMC_ENABLE_BB_2_CONT); return FALSE; } /* CMD_FUNCTION : BOOL CommandDisableCS2Ctrl(CommandParameter paramNotUsed) ************************************************************************ AUTHOR : Amazy USE : Disable the CS2 controller */ BOOL CommandDisableCS2Ctrl(CommandParameter paramNotUsed) { //change the status LOCK_WRITE_RES_PARAMS; CLEAR_BIT(gpCS2Controller->TaskStatus, K_BMASK_PID_CTRL_STATUS_PID_ENABLED); SET_BIT(gpCS2Controller->TaskStatus, K_BMASK_CS_CTRL_STATUS_MEASURE_ONLY); UNLOCK_WRITE_RES_PARAMS; SequencerSendAck(DMC_DISABLE_BB_2_CONT); return FALSE; }