tc_handler.c
1164 lines
| 35.5 KiB
| text/x-c
|
CLexer
/ src / tc_handler.c
paul
|
r40 | /** Functions and tasks related to TeleCommand handling. | ||
* | ||||
* @file | ||||
* @author P. LEROY | ||||
* | ||||
* A group of functions to handle TeleCommands:\n | ||||
* action launching\n | ||||
* TC parsing\n | ||||
* ... | ||||
* | ||||
*/ | ||||
#include "tc_handler.h" | ||||
paul
|
r187 | #include "math.h" | ||
paul@pc-solar1.lab-lpp.local
|
r5 | |||
paul@pc-solar1.lab-lpp.local
|
r7 | //*********** | ||
// RTEMS TASK | ||||
paul@pc-solar1.lab-lpp.local
|
r5 | |||
paul@pc-solar1.lab-lpp.local
|
r9 | rtems_task actn_task( rtems_task_argument unused ) | ||
{ | ||||
paul
|
r40 | /** This RTEMS task is responsible for launching actions upton the reception of valid TeleCommands. | ||
* | ||||
* @param unused is the starting argument of the RTEMS task | ||||
* | ||||
* The ACTN task waits for data coming from an RTEMS msesage queue. When data arrives, it launches specific actions depending | ||||
* on the incoming TeleCommand. | ||||
* | ||||
*/ | ||||
paul@pc-solar1.lab-lpp.local
|
r23 | int result; | ||
rtems_status_code status; // RTEMS status code | ||||
ccsdsTelecommandPacket_t TC; // TC sent to the ACTN task | ||||
size_t size; // size of the incoming TC packet | ||||
unsigned char subtype; // subtype of the current TC packet | ||||
paul
|
r75 | unsigned char time[6]; | ||
paul
|
r35 | rtems_id queue_rcv_id; | ||
rtems_id queue_snd_id; | ||||
paul
|
r82 | status = get_message_queue_id_recv( &queue_rcv_id ); | ||
paul
|
r35 | if (status != RTEMS_SUCCESSFUL) | ||
{ | ||||
paul
|
r82 | PRINTF1("in ACTN *** ERR get_message_queue_id_recv %d\n", status) | ||
paul
|
r35 | } | ||
paul
|
r82 | status = get_message_queue_id_send( &queue_snd_id ); | ||
paul
|
r35 | if (status != RTEMS_SUCCESSFUL) | ||
{ | ||||
paul
|
r82 | PRINTF1("in ACTN *** ERR get_message_queue_id_send %d\n", status) | ||
paul
|
r35 | } | ||
paul@pc-solar1.lab-lpp.local
|
r23 | |||
result = LFR_SUCCESSFUL; | ||||
subtype = 0; // subtype of the current TC packet | ||||
paul@pc-solar1.lab-lpp.local
|
r5 | |||
paul
|
r35 | BOOT_PRINTF("in ACTN *** \n") | ||
paul@pc-solar1.lab-lpp.local
|
r11 | |||
paul@pc-solar1.lab-lpp.local
|
r9 | while(1) | ||
{ | ||||
paul
|
r35 | status = rtems_message_queue_receive( queue_rcv_id, (char*) &TC, &size, | ||
paul@pc-solar1.lab-lpp.local
|
r9 | RTEMS_WAIT, RTEMS_NO_TIMEOUT); | ||
paul
|
r75 | getTime( time ); // set time to the current time | ||
paul
|
r77 | if (status!=RTEMS_SUCCESSFUL) | ||
{ | ||||
PRINTF1("ERR *** in task ACTN *** error receiving a message, code %d \n", status) | ||||
} | ||||
paul@pc-solar1.lab-lpp.local
|
r9 | else | ||
{ | ||||
paul@pc-solar1.lab-lpp.local
|
r23 | subtype = TC.serviceSubType; | ||
paul@pc-solar1.lab-lpp.local
|
r9 | switch(subtype) | ||
{ | ||||
paul
|
r192 | case TC_SUBTYPE_RESET: | ||
result = action_reset( &TC, queue_snd_id, time ); | ||||
close_action( &TC, result, queue_snd_id ); | ||||
break; | ||||
case TC_SUBTYPE_LOAD_COMM: | ||||
result = action_load_common_par( &TC ); | ||||
close_action( &TC, result, queue_snd_id ); | ||||
break; | ||||
case TC_SUBTYPE_LOAD_NORM: | ||||
result = action_load_normal_par( &TC, queue_snd_id, time ); | ||||
close_action( &TC, result, queue_snd_id ); | ||||
break; | ||||
case TC_SUBTYPE_LOAD_BURST: | ||||
result = action_load_burst_par( &TC, queue_snd_id, time ); | ||||
close_action( &TC, result, queue_snd_id ); | ||||
break; | ||||
case TC_SUBTYPE_LOAD_SBM1: | ||||
result = action_load_sbm1_par( &TC, queue_snd_id, time ); | ||||
close_action( &TC, result, queue_snd_id ); | ||||
break; | ||||
case TC_SUBTYPE_LOAD_SBM2: | ||||
result = action_load_sbm2_par( &TC, queue_snd_id, time ); | ||||
close_action( &TC, result, queue_snd_id ); | ||||
break; | ||||
case TC_SUBTYPE_DUMP: | ||||
result = action_dump_par( queue_snd_id ); | ||||
close_action( &TC, result, queue_snd_id ); | ||||
break; | ||||
case TC_SUBTYPE_ENTER: | ||||
result = action_enter_mode( &TC, queue_snd_id ); | ||||
close_action( &TC, result, queue_snd_id ); | ||||
break; | ||||
case TC_SUBTYPE_UPDT_INFO: | ||||
result = action_update_info( &TC, queue_snd_id ); | ||||
close_action( &TC, result, queue_snd_id ); | ||||
break; | ||||
case TC_SUBTYPE_EN_CAL: | ||||
result = action_enable_calibration( &TC, queue_snd_id, time ); | ||||
close_action( &TC, result, queue_snd_id ); | ||||
break; | ||||
case TC_SUBTYPE_DIS_CAL: | ||||
result = action_disable_calibration( &TC, queue_snd_id, time ); | ||||
close_action( &TC, result, queue_snd_id ); | ||||
break; | ||||
case TC_SUBTYPE_LOAD_K: | ||||
result = action_load_kcoefficients( &TC, queue_snd_id, time ); | ||||
close_action( &TC, result, queue_snd_id ); | ||||
break; | ||||
case TC_SUBTYPE_DUMP_K: | ||||
result = action_dump_kcoefficients( &TC, queue_snd_id, time ); | ||||
close_action( &TC, result, queue_snd_id ); | ||||
break; | ||||
case TC_SUBTYPE_LOAD_FBINS: | ||||
result = action_load_fbins_mask( &TC, queue_snd_id, time ); | ||||
close_action( &TC, result, queue_snd_id ); | ||||
break; | ||||
case TC_SUBTYPE_UPDT_TIME: | ||||
result = action_update_time( &TC ); | ||||
close_action( &TC, result, queue_snd_id ); | ||||
break; | ||||
default: | ||||
break; | ||||
paul@pc-solar1.lab-lpp.local
|
r9 | } | ||
} | ||||
} | ||||
} | ||||
//*********** | ||||
// TC ACTIONS | ||||
paul@pc-solar1.lab-lpp.local
|
r15 | |||
paul
|
r75 | int action_reset(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) | ||
paul@pc-solar1.lab-lpp.local
|
r9 | { | ||
paul
|
r40 | /** This function executes specific actions when a TC_LFR_RESET TeleCommand has been received. | ||
* | ||||
* @param TC points to the TeleCommand packet that is being processed | ||||
* @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver | ||||
* | ||||
*/ | ||||
paul
|
r168 | printf("this is the end!!!\n"); | ||
exit(0); | ||||
paul
|
r75 | send_tm_lfr_tc_exe_not_implemented( TC, queue_id, time ); | ||
paul@pc-solar1.lab-lpp.local
|
r21 | return LFR_DEFAULT; | ||
paul@pc-solar1.lab-lpp.local
|
r9 | } | ||
paul
|
r111 | int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id ) | ||
paul
|
r33 | { | ||
paul
|
r40 | /** This function executes specific actions when a TC_LFR_ENTER_MODE TeleCommand has been received. | ||
* | ||||
* @param TC points to the TeleCommand packet that is being processed | ||||
* @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver | ||||
* | ||||
*/ | ||||
paul
|
r33 | rtems_status_code status; | ||
unsigned char requestedMode; | ||||
paul
|
r111 | unsigned int *transitionCoarseTime_ptr; | ||
unsigned int transitionCoarseTime; | ||||
paul
|
r112 | unsigned char * bytePosPtr; | ||
paul
|
r33 | |||
paul
|
r112 | bytePosPtr = (unsigned char *) &TC->packetID; | ||
requestedMode = bytePosPtr[ BYTE_POS_CP_MODE_LFR_SET ]; | ||||
transitionCoarseTime_ptr = (unsigned int *) ( &bytePosPtr[ BYTE_POS_CP_LFR_ENTER_MODE_TIME ] ); | ||||
paul
|
r111 | transitionCoarseTime = (*transitionCoarseTime_ptr) & 0x7fffffff; | ||
paul
|
r33 | |||
paul
|
r109 | status = check_mode_value( requestedMode ); | ||
paul
|
r110 | |||
paul
|
r112 | if ( status != LFR_SUCCESSFUL ) // the mode value is inconsistent | ||
paul
|
r33 | { | ||
paul
|
r112 | send_tm_lfr_tc_exe_inconsistent( TC, queue_id, BYTE_POS_CP_MODE_LFR_SET, requestedMode ); | ||
paul
|
r33 | } | ||
paul
|
r111 | else // the mode value is consistent, check the transition | ||
paul
|
r33 | { | ||
paul
|
r109 | status = check_mode_transition(requestedMode); | ||
paul
|
r111 | if (status != LFR_SUCCESSFUL) | ||
paul
|
r109 | { | ||
paul
|
r111 | PRINTF("ERR *** in action_enter_mode *** check_mode_transition\n") | ||
paul
|
r104 | send_tm_lfr_tc_exe_not_executable( TC, queue_id ); | ||
paul
|
r37 | } | ||
paul
|
r33 | } | ||
paul
|
r111 | if ( status == LFR_SUCCESSFUL ) // the transition is valid, enter the mode | ||
{ | ||||
status = check_transition_date( transitionCoarseTime ); | ||||
if (status != LFR_SUCCESSFUL) | ||||
{ | ||||
PRINTF("ERR *** in action_enter_mode *** check_transition_date\n") | ||||
paul
|
r112 | send_tm_lfr_tc_exe_inconsistent( TC, queue_id, | ||
BYTE_POS_CP_LFR_ENTER_MODE_TIME, | ||||
bytePosPtr[ BYTE_POS_CP_LFR_ENTER_MODE_TIME + 3 ] ); | ||||
paul
|
r111 | } | ||
} | ||||
if ( status == LFR_SUCCESSFUL ) // the date is valid, enter the mode | ||||
{ | ||||
PRINTF1("OK *** in action_enter_mode *** enter mode %d\n", requestedMode); | ||||
status = enter_mode( requestedMode, transitionCoarseTime ); | ||||
} | ||||
paul
|
r33 | return status; | ||
} | ||||
paul
|
r40 | int action_update_info(ccsdsTelecommandPacket_t *TC, rtems_id queue_id) | ||
{ | ||||
/** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received. | ||||
* | ||||
* @param TC points to the TeleCommand packet that is being processed | ||||
* @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver | ||||
* | ||||
paul
|
r46 | * @return LFR directive status code: | ||
* - LFR_DEFAULT | ||||
* - LFR_SUCCESSFUL | ||||
* | ||||
paul
|
r40 | */ | ||
paul@pc-solar1.lab-lpp.local
|
r23 | unsigned int val; | ||
int result; | ||||
paul
|
r104 | unsigned int status; | ||
unsigned char mode; | ||||
paul
|
r112 | unsigned char * bytePosPtr; | ||
bytePosPtr = (unsigned char *) &TC->packetID; | ||||
paul@pc-solar1.lab-lpp.local
|
r18 | |||
paul
|
r107 | // check LFR mode | ||
paul
|
r112 | mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET5 ] & 0x1e) >> 1; | ||
paul
|
r104 | status = check_update_info_hk_lfr_mode( mode ); | ||
paul
|
r107 | if (status == LFR_SUCCESSFUL) // check TDS mode | ||
paul
|
r104 | { | ||
paul
|
r112 | mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & 0xf0) >> 4; | ||
paul
|
r104 | status = check_update_info_hk_tds_mode( mode ); | ||
} | ||||
paul
|
r107 | if (status == LFR_SUCCESSFUL) // check THR mode | ||
paul
|
r104 | { | ||
paul
|
r112 | mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & 0x0f); | ||
paul
|
r104 | status = check_update_info_hk_thr_mode( mode ); | ||
} | ||||
paul
|
r107 | if (status == LFR_SUCCESSFUL) // if the parameter check is successful | ||
paul
|
r104 | { | ||
val = housekeeping_packet.hk_lfr_update_info_tc_cnt[0] * 256 | ||||
+ housekeeping_packet.hk_lfr_update_info_tc_cnt[1]; | ||||
val++; | ||||
housekeeping_packet.hk_lfr_update_info_tc_cnt[0] = (unsigned char) (val >> 8); | ||||
housekeeping_packet.hk_lfr_update_info_tc_cnt[1] = (unsigned char) (val); | ||||
} | ||||
result = status; | ||||
paul@pc-solar1.lab-lpp.local
|
r23 | |||
return result; | ||||
} | ||||
paul
|
r75 | int action_enable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) | ||
paul@pc-solar1.lab-lpp.local
|
r23 | { | ||
paul
|
r40 | /** This function executes specific actions when a TC_LFR_ENABLE_CALIBRATION TeleCommand has been received. | ||
* | ||||
* @param TC points to the TeleCommand packet that is being processed | ||||
* @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver | ||||
* | ||||
*/ | ||||
paul@pc-solar1.lab-lpp.local
|
r23 | int result; | ||
result = LFR_DEFAULT; | ||||
paul
|
r206 | setCalibration( true ); | ||
paul
|
r187 | |||
result = LFR_SUCCESSFUL; | ||||
paul
|
r104 | |||
paul@pc-solar1.lab-lpp.local
|
r23 | return result; | ||
} | ||||
paul
|
r75 | int action_disable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) | ||
paul@pc-solar1.lab-lpp.local
|
r23 | { | ||
paul
|
r40 | /** This function executes specific actions when a TC_LFR_DISABLE_CALIBRATION TeleCommand has been received. | ||
* | ||||
* @param TC points to the TeleCommand packet that is being processed | ||||
* @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver | ||||
* | ||||
*/ | ||||
paul@pc-solar1.lab-lpp.local
|
r23 | int result; | ||
result = LFR_DEFAULT; | ||||
paul
|
r206 | setCalibration( false ); | ||
paul
|
r187 | |||
result = LFR_SUCCESSFUL; | ||||
paul
|
r104 | |||
paul@pc-solar1.lab-lpp.local
|
r23 | return result; | ||
} | ||||
paul
|
r33 | int action_update_time(ccsdsTelecommandPacket_t *TC) | ||
paul@pc-solar1.lab-lpp.local
|
r23 | { | ||
paul
|
r40 | /** This function executes specific actions when a TC_LFR_UPDATE_TIME TeleCommand has been received. | ||
* | ||||
* @param TC points to the TeleCommand packet that is being processed | ||||
* @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver | ||||
* | ||||
paul
|
r46 | * @return LFR_SUCCESSFUL | ||
* | ||||
paul
|
r40 | */ | ||
paul@pc-solar1.lab-lpp.local
|
r23 | unsigned int val; | ||
paul@pc-solar1.lab-lpp.local
|
r19 | |||
paul@pc-solar1.lab-lpp.local
|
r23 | time_management_regs->coarse_time_load = (TC->dataAndCRC[0] << 24) | ||
+ (TC->dataAndCRC[1] << 16) | ||||
+ (TC->dataAndCRC[2] << 8) | ||||
+ TC->dataAndCRC[3]; | ||||
paul
|
r109 | |||
paul@pc-solar1.lab-lpp.local
|
r23 | val = housekeeping_packet.hk_lfr_update_time_tc_cnt[0] * 256 | ||
+ housekeeping_packet.hk_lfr_update_time_tc_cnt[1]; | ||||
val++; | ||||
housekeeping_packet.hk_lfr_update_time_tc_cnt[0] = (unsigned char) (val >> 8); | ||||
housekeeping_packet.hk_lfr_update_time_tc_cnt[1] = (unsigned char) (val); | ||||
return LFR_SUCCESSFUL; | ||||
} | ||||
//******************* | ||||
// ENTERING THE MODES | ||||
paul
|
r109 | int check_mode_value( unsigned char requestedMode ) | ||
{ | ||||
int status; | ||||
paul@pc-solar1.lab-lpp.local
|
r23 | |||
paul
|
r109 | if ( (requestedMode != LFR_MODE_STANDBY) | ||
&& (requestedMode != LFR_MODE_NORMAL) && (requestedMode != LFR_MODE_BURST) | ||||
&& (requestedMode != LFR_MODE_SBM1) && (requestedMode != LFR_MODE_SBM2) ) | ||||
{ | ||||
status = LFR_DEFAULT; | ||||
} | ||||
else | ||||
{ | ||||
status = LFR_SUCCESSFUL; | ||||
} | ||||
return status; | ||||
} | ||||
int check_mode_transition( unsigned char requestedMode ) | ||||
paul@pc-solar1.lab-lpp.local
|
r23 | { | ||
paul
|
r77 | /** This function checks the validity of the transition requested by the TC_LFR_ENTER_MODE. | ||
* | ||||
* @param requestedMode is the mode requested by the TC_LFR_ENTER_MODE | ||||
* | ||||
* @return LFR directive status codes: | ||||
* - LFR_SUCCESSFUL - the transition is authorized | ||||
* - LFR_DEFAULT - the transition is not authorized | ||||
* | ||||
*/ | ||||
paul@pc-solar1.lab-lpp.local
|
r23 | int status; | ||
paul@pc-solar1.lab-lpp.local
|
r19 | |||
paul@pc-solar1.lab-lpp.local
|
r23 | switch (requestedMode) | ||
{ | ||||
case LFR_MODE_STANDBY: | ||||
paul
|
r33 | if ( lfrCurrentMode == LFR_MODE_STANDBY ) { | ||
paul@pc-solar1.lab-lpp.local
|
r23 | status = LFR_DEFAULT; | ||
} | ||||
else | ||||
{ | ||||
status = LFR_SUCCESSFUL; | ||||
} | ||||
break; | ||||
case LFR_MODE_NORMAL: | ||||
paul
|
r33 | if ( lfrCurrentMode == LFR_MODE_NORMAL ) { | ||
paul@pc-solar1.lab-lpp.local
|
r23 | status = LFR_DEFAULT; | ||
} | ||||
else { | ||||
status = LFR_SUCCESSFUL; | ||||
} | ||||
break; | ||||
case LFR_MODE_BURST: | ||||
paul
|
r33 | if ( lfrCurrentMode == LFR_MODE_BURST ) { | ||
paul@pc-solar1.lab-lpp.local
|
r23 | status = LFR_DEFAULT; | ||
} | ||||
else { | ||||
status = LFR_SUCCESSFUL; | ||||
} | ||||
break; | ||||
case LFR_MODE_SBM1: | ||||
paul
|
r33 | if ( lfrCurrentMode == LFR_MODE_SBM1 ) { | ||
paul@pc-solar1.lab-lpp.local
|
r23 | status = LFR_DEFAULT; | ||
} | ||||
else { | ||||
status = LFR_SUCCESSFUL; | ||||
} | ||||
break; | ||||
case LFR_MODE_SBM2: | ||||
paul
|
r33 | if ( lfrCurrentMode == LFR_MODE_SBM2 ) { | ||
paul@pc-solar1.lab-lpp.local
|
r23 | status = LFR_DEFAULT; | ||
} | ||||
else { | ||||
status = LFR_SUCCESSFUL; | ||||
} | ||||
break; | ||||
default: | ||||
status = LFR_DEFAULT; | ||||
break; | ||||
} | ||||
paul@pc-solar1.lab-lpp.local
|
r19 | |||
paul@pc-solar1.lab-lpp.local
|
r21 | return status; | ||
admin@pc-p-leroy3.LAB-LPP.LOCAL
|
r10 | } | ||
paul
|
r111 | int check_transition_date( unsigned int transitionCoarseTime ) | ||
{ | ||||
int status; | ||||
unsigned int localCoarseTime; | ||||
unsigned int deltaCoarseTime; | ||||
status = LFR_SUCCESSFUL; | ||||
if (transitionCoarseTime == 0) // transition time = 0 means an instant transition | ||||
{ | ||||
status = LFR_SUCCESSFUL; | ||||
} | ||||
else | ||||
{ | ||||
localCoarseTime = time_management_regs->coarse_time & 0x7fffffff; | ||||
paul
|
r191 | PRINTF2("localTime = %x, transitionTime = %x\n", localCoarseTime, transitionCoarseTime) | ||
paul
|
r112 | if ( transitionCoarseTime <= localCoarseTime ) // SSS-CP-EQS-322 | ||
paul
|
r111 | { | ||
status = LFR_DEFAULT; | ||||
paul
|
r191 | PRINTF("ERR *** in check_transition_date *** transitionCoarseTime <= localCoarseTime\n") | ||
paul
|
r111 | } | ||
if (status == LFR_SUCCESSFUL) | ||||
{ | ||||
deltaCoarseTime = transitionCoarseTime - localCoarseTime; | ||||
if ( deltaCoarseTime > 3 ) // SSS-CP-EQS-323 | ||||
{ | ||||
status = LFR_DEFAULT; | ||||
PRINTF1("ERR *** in check_transition_date *** deltaCoarseTime = %x\n", deltaCoarseTime) | ||||
} | ||||
} | ||||
} | ||||
return status; | ||||
} | ||||
paul
|
r109 | int stop_current_mode( void ) | ||
paul@pc-solar1.lab-lpp.local
|
r20 | { | ||
paul
|
r40 | /** This function stops the current mode by masking interrupt lines and suspending science tasks. | ||
* | ||||
* @return RTEMS directive status codes: | ||||
* - RTEMS_SUCCESSFUL - task restarted successfully | ||||
* - RTEMS_INVALID_ID - task id invalid | ||||
* - RTEMS_ALREADY_SUSPENDED - task already suspended | ||||
* | ||||
*/ | ||||
paul@pc-solar1.lab-lpp.local
|
r21 | rtems_status_code status; | ||
paul@pc-solar1.lab-lpp.local
|
r23 | |||
status = RTEMS_SUCCESSFUL; | ||||
paul@pc-solar1.lab-lpp.local
|
r22 | |||
paul
|
r99 | // (1) mask interruptions | ||
paul
|
r31 | LEON_Mask_interrupt( IRQ_WAVEFORM_PICKER ); // mask waveform picker interrupt | ||
paul
|
r103 | LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt | ||
paul
|
r99 | |||
paul
|
r171 | // (2) reset waveform picker registers | ||
paul
|
r47 | reset_wfp_burst_enable(); // reset burst and enable bits | ||
reset_wfp_status(); // reset all the status bits | ||||
paul
|
r110 | |||
paul
|
r171 | // (3) reset spectral matrices registers | ||
set_sm_irq_onNewMatrix( 0 ); // stop the spectral matrices | ||||
reset_sm_status(); | ||||
paul
|
r179 | // reset lfr VHDL module | ||
reset_lfr(); | ||||
paul
|
r106 | reset_extractSWF(); // reset the extractSWF flag to false | ||
paul
|
r99 | |||
paul
|
r171 | // (4) clear interruptions | ||
LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER ); // clear waveform picker interrupt | ||||
LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt | ||||
paul
|
r99 | // <Spectral Matrices simulator> | ||
LEON_Mask_interrupt( IRQ_SM_SIMULATOR ); // mask spectral matrix interrupt simulator | ||||
timer_stop( (gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_SM_SIMULATOR ); | ||||
LEON_Clear_interrupt( IRQ_SM_SIMULATOR ); // clear spectral matrix interrupt simulator | ||||
// </Spectral Matrices simulator> | ||||
paul@pc-solar1.lab-lpp.local
|
r20 | // suspend several tasks | ||
paul
|
r35 | if (lfrCurrentMode != LFR_MODE_STANDBY) { | ||
paul
|
r40 | status = suspend_science_tasks(); | ||
paul@pc-solar1.lab-lpp.local
|
r21 | } | ||
paul@pc-solar1.lab-lpp.local
|
r20 | |||
paul@pc-solar1.lab-lpp.local
|
r22 | if (status != RTEMS_SUCCESSFUL) | ||
{ | ||||
paul
|
r40 | PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status) | ||
paul@pc-solar1.lab-lpp.local
|
r22 | } | ||
paul@pc-solar1.lab-lpp.local
|
r21 | return status; | ||
paul@pc-solar1.lab-lpp.local
|
r20 | } | ||
paul
|
r111 | int enter_mode( unsigned char mode, unsigned int transitionCoarseTime ) | ||
paul@pc-solar1.lab-lpp.local
|
r20 | { | ||
paul
|
r77 | /** This function is launched after a mode transition validation. | ||
* | ||||
* @param mode is the mode in which LFR will be put. | ||||
* | ||||
* @return RTEMS directive status codes: | ||||
* - RTEMS_SUCCESSFUL - the mode has been entered successfully | ||||
* - RTEMS_NOT_SATISFIED - the mode has not been entered successfully | ||||
* | ||||
*/ | ||||
paul@pc-solar1.lab-lpp.local
|
r21 | rtems_status_code status; | ||
paul@pc-solar1.lab-lpp.local
|
r20 | |||
paul
|
r109 | //********************** | ||
// STOP THE CURRENT MODE | ||||
status = stop_current_mode(); | ||||
if (status != RTEMS_SUCCESSFUL) | ||||
{ | ||||
PRINTF1("ERR *** in enter_mode *** stop_current_mode with mode = %d\n", mode) | ||||
} | ||||
paul
|
r33 | |||
paul
|
r109 | //************************* | ||
// ENTER THE REQUESTED MODE | ||||
paul
|
r98 | if ( (mode == LFR_MODE_NORMAL) || (mode == LFR_MODE_BURST) | ||
|| (mode == LFR_MODE_SBM1) || (mode == LFR_MODE_SBM2) ) | ||||
{ | ||||
paul
|
r99 | #ifdef PRINT_TASK_STATISTICS | ||
rtems_cpu_usage_reset(); | ||||
#endif | ||||
paul
|
r117 | status = restart_science_tasks( mode ); | ||
paul
|
r170 | launch_spectral_matrix( ); | ||
paul
|
r111 | launch_waveform_picker( mode, transitionCoarseTime ); | ||
paul
|
r150 | // launch_spectral_matrix_simu( ); | ||
paul
|
r98 | } | ||
else if ( mode == LFR_MODE_STANDBY ) | ||||
{ | ||||
#ifdef PRINT_TASK_STATISTICS | ||||
rtems_cpu_usage_report(); | ||||
#endif | ||||
#ifdef PRINT_STACK_REPORT | ||||
paul
|
r118 | PRINTF("stack report selected\n") | ||
paul
|
r98 | rtems_stack_checker_report_usage(); | ||
#endif | ||||
paul
|
r99 | } | ||
else | ||||
{ | ||||
status = RTEMS_UNSATISFIED; | ||||
paul
|
r98 | } | ||
paul
|
r33 | if (status != RTEMS_SUCCESSFUL) | ||
paul@pc-solar1.lab-lpp.local
|
r23 | { | ||
paul
|
r109 | PRINTF1("ERR *** in enter_mode *** status = %d\n", status) | ||
paul
|
r33 | status = RTEMS_UNSATISFIED; | ||
paul@pc-solar1.lab-lpp.local
|
r23 | } | ||
paul@pc-solar1.lab-lpp.local
|
r21 | |||
return status; | ||||
paul@pc-solar1.lab-lpp.local
|
r20 | } | ||
paul
|
r117 | int restart_science_tasks(unsigned char lfrRequestedMode ) | ||
paul
|
r32 | { | ||
paul
|
r77 | /** This function is used to restart all science tasks. | ||
* | ||||
* @return RTEMS directive status codes: | ||||
* - RTEMS_SUCCESSFUL - task restarted successfully | ||||
* - RTEMS_INVALID_ID - task id invalid | ||||
* - RTEMS_INCORRECT_STATE - task never started | ||||
* - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task | ||||
* | ||||
paul
|
r121 | * Science tasks are AVF0, PRC0, WFRM, CWF3, CW2, CWF1 | ||
paul
|
r77 | * | ||
*/ | ||||
paul
|
r124 | rtems_status_code status[10]; | ||
paul
|
r33 | rtems_status_code ret; | ||
paul
|
r32 | |||
paul
|
r33 | ret = RTEMS_SUCCESSFUL; | ||
paul
|
r32 | |||
paul
|
r117 | status[0] = rtems_task_restart( Task_id[TASKID_AVF0], lfrRequestedMode ); | ||
paul
|
r35 | if (status[0] != RTEMS_SUCCESSFUL) | ||
{ | ||||
paul
|
r121 | PRINTF1("in restart_science_task *** AVF0 ERR %d\n", status[0]) | ||
} | ||||
status[1] = rtems_task_restart( Task_id[TASKID_PRC0], lfrRequestedMode ); | ||||
if (status[1] != RTEMS_SUCCESSFUL) | ||||
{ | ||||
PRINTF1("in restart_science_task *** PRC0 ERR %d\n", status[1]) | ||||
paul
|
r35 | } | ||
paul
|
r33 | status[2] = rtems_task_restart( Task_id[TASKID_WFRM],1 ); | ||
paul
|
r35 | if (status[2] != RTEMS_SUCCESSFUL) | ||
{ | ||||
paul
|
r121 | PRINTF1("in restart_science_task *** WFRM ERR %d\n", status[2]) | ||
paul
|
r35 | } | ||
paul
|
r33 | status[3] = rtems_task_restart( Task_id[TASKID_CWF3],1 ); | ||
paul
|
r35 | if (status[3] != RTEMS_SUCCESSFUL) | ||
{ | ||||
paul
|
r121 | PRINTF1("in restart_science_task *** CWF3 ERR %d\n", status[3]) | ||
paul
|
r35 | } | ||
paul
|
r33 | status[4] = rtems_task_restart( Task_id[TASKID_CWF2],1 ); | ||
paul
|
r35 | if (status[4] != RTEMS_SUCCESSFUL) | ||
{ | ||||
paul
|
r121 | PRINTF1("in restart_science_task *** CWF2 ERR %d\n", status[4]) | ||
paul
|
r35 | } | ||
paul
|
r33 | status[5] = rtems_task_restart( Task_id[TASKID_CWF1],1 ); | ||
paul
|
r35 | if (status[5] != RTEMS_SUCCESSFUL) | ||
{ | ||||
paul
|
r121 | PRINTF1("in restart_science_task *** CWF1 ERR %d\n", status[5]) | ||
paul
|
r35 | } | ||
paul
|
r33 | |||
paul
|
r121 | status[6] = rtems_task_restart( Task_id[TASKID_AVF1], lfrRequestedMode ); | ||
paul
|
r117 | if (status[6] != RTEMS_SUCCESSFUL) | ||
{ | ||||
paul
|
r121 | PRINTF1("in restart_science_task *** AVF1 ERR %d\n", status[6]) | ||
paul
|
r117 | } | ||
paul
|
r121 | status[7] = rtems_task_restart( Task_id[TASKID_PRC1],lfrRequestedMode ); | ||
if (status[7] != RTEMS_SUCCESSFUL) | ||||
{ | ||||
PRINTF1("in restart_science_task *** PRC1 ERR %d\n", status[7]) | ||||
} | ||||
paul
|
r126 | status[8] = rtems_task_restart( Task_id[TASKID_AVF2], 1 ); | ||
if (status[8] != RTEMS_SUCCESSFUL) | ||||
{ | ||||
PRINTF1("in restart_science_task *** AVF2 ERR %d\n", status[8]) | ||||
} | ||||
paul
|
r124 | |||
paul
|
r126 | status[9] = rtems_task_restart( Task_id[TASKID_PRC2], 1 ); | ||
if (status[9] != RTEMS_SUCCESSFUL) | ||||
{ | ||||
PRINTF1("in restart_science_task *** PRC2 ERR %d\n", status[9]) | ||||
} | ||||
paul
|
r124 | |||
paul
|
r121 | if ( (status[0] != RTEMS_SUCCESSFUL) || (status[1] != RTEMS_SUCCESSFUL) || | ||
(status[2] != RTEMS_SUCCESSFUL) || (status[3] != RTEMS_SUCCESSFUL) || | ||||
(status[4] != RTEMS_SUCCESSFUL) || (status[5] != RTEMS_SUCCESSFUL) || | ||||
paul
|
r126 | (status[6] != RTEMS_SUCCESSFUL) || (status[7] != RTEMS_SUCCESSFUL) || | ||
(status[8] != RTEMS_SUCCESSFUL) || (status[9] != RTEMS_SUCCESSFUL) ) | ||||
paul
|
r33 | { | ||
ret = RTEMS_UNSATISFIED; | ||||
paul
|
r32 | } | ||
paul
|
r33 | return ret; | ||
paul
|
r32 | } | ||
int suspend_science_tasks() | ||||
{ | ||||
paul
|
r40 | /** This function suspends the science tasks. | ||
* | ||||
* @return RTEMS directive status codes: | ||||
* - RTEMS_SUCCESSFUL - task restarted successfully | ||||
* - RTEMS_INVALID_ID - task id invalid | ||||
* - RTEMS_ALREADY_SUSPENDED - task already suspended | ||||
* | ||||
*/ | ||||
paul
|
r32 | |||
paul
|
r40 | rtems_status_code status; | ||
paul
|
r35 | |||
paul
|
r192 | printf("in suspend_science_tasks\n"); | ||
paul
|
r121 | status = rtems_task_suspend( Task_id[TASKID_AVF0] ); // suspend AVF0 | ||
paul
|
r197 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | ||
paul
|
r35 | { | ||
paul
|
r40 | PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status) | ||
paul
|
r35 | } | ||
paul
|
r197 | else | ||
{ | ||||
status = RTEMS_SUCCESSFUL; | ||||
} | ||||
paul
|
r121 | if (status == RTEMS_SUCCESSFUL) // suspend PRC0 | ||
{ | ||||
status = rtems_task_suspend( Task_id[TASKID_PRC0] ); | ||||
paul
|
r197 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | ||
paul
|
r121 | { | ||
PRINTF1("in suspend_science_task *** PRC0 ERR %d\n", status) | ||||
} | ||||
paul
|
r197 | else | ||
{ | ||||
status = RTEMS_SUCCESSFUL; | ||||
} | ||||
paul
|
r121 | } | ||
if (status == RTEMS_SUCCESSFUL) // suspend AVF1 | ||||
{ | ||||
status = rtems_task_suspend( Task_id[TASKID_AVF1] ); | ||||
paul
|
r197 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | ||
paul
|
r121 | { | ||
PRINTF1("in suspend_science_task *** AVF1 ERR %d\n", status) | ||||
} | ||||
paul
|
r197 | else | ||
{ | ||||
status = RTEMS_SUCCESSFUL; | ||||
} | ||||
paul
|
r121 | } | ||
if (status == RTEMS_SUCCESSFUL) // suspend PRC1 | ||||
{ | ||||
status = rtems_task_suspend( Task_id[TASKID_PRC1] ); | ||||
paul
|
r197 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | ||
paul
|
r121 | { | ||
PRINTF1("in suspend_science_task *** PRC1 ERR %d\n", status) | ||||
} | ||||
paul
|
r197 | else | ||
{ | ||||
status = RTEMS_SUCCESSFUL; | ||||
} | ||||
paul
|
r121 | } | ||
paul
|
r126 | if (status == RTEMS_SUCCESSFUL) // suspend AVF2 | ||
{ | ||||
status = rtems_task_suspend( Task_id[TASKID_AVF2] ); | ||||
paul
|
r197 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | ||
paul
|
r126 | { | ||
PRINTF1("in suspend_science_task *** AVF2 ERR %d\n", status) | ||||
} | ||||
paul
|
r197 | else | ||
{ | ||||
status = RTEMS_SUCCESSFUL; | ||||
} | ||||
paul
|
r126 | } | ||
if (status == RTEMS_SUCCESSFUL) // suspend PRC2 | ||||
{ | ||||
status = rtems_task_suspend( Task_id[TASKID_PRC2] ); | ||||
paul
|
r197 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | ||
paul
|
r126 | { | ||
PRINTF1("in suspend_science_task *** PRC2 ERR %d\n", status) | ||||
} | ||||
paul
|
r197 | else | ||
{ | ||||
status = RTEMS_SUCCESSFUL; | ||||
} | ||||
paul
|
r126 | } | ||
paul
|
r40 | if (status == RTEMS_SUCCESSFUL) // suspend WFRM | ||
{ | ||||
status = rtems_task_suspend( Task_id[TASKID_WFRM] ); | ||||
paul
|
r197 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | ||
paul
|
r40 | { | ||
PRINTF1("in suspend_science_task *** WFRM ERR %d\n", status) | ||||
} | ||||
paul
|
r197 | else | ||
{ | ||||
status = RTEMS_SUCCESSFUL; | ||||
} | ||||
paul
|
r35 | } | ||
paul
|
r40 | if (status == RTEMS_SUCCESSFUL) // suspend CWF3 | ||
paul
|
r35 | { | ||
paul
|
r40 | status = rtems_task_suspend( Task_id[TASKID_CWF3] ); | ||
paul
|
r197 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | ||
paul
|
r40 | { | ||
PRINTF1("in suspend_science_task *** CWF3 ERR %d\n", status) | ||||
} | ||||
paul
|
r197 | else | ||
{ | ||||
status = RTEMS_SUCCESSFUL; | ||||
} | ||||
paul
|
r35 | } | ||
paul
|
r40 | if (status == RTEMS_SUCCESSFUL) // suspend CWF2 | ||
paul
|
r35 | { | ||
paul
|
r40 | status = rtems_task_suspend( Task_id[TASKID_CWF2] ); | ||
paul
|
r197 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | ||
paul
|
r40 | { | ||
PRINTF1("in suspend_science_task *** CWF2 ERR %d\n", status) | ||||
} | ||||
paul
|
r197 | else | ||
{ | ||||
status = RTEMS_SUCCESSFUL; | ||||
} | ||||
paul
|
r40 | } | ||
if (status == RTEMS_SUCCESSFUL) // suspend CWF1 | ||||
{ | ||||
status = rtems_task_suspend( Task_id[TASKID_CWF1] ); | ||||
paul
|
r197 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | ||
paul
|
r40 | { | ||
PRINTF1("in suspend_science_task *** CWF1 ERR %d\n", status) | ||||
} | ||||
paul
|
r197 | else | ||
{ | ||||
status = RTEMS_SUCCESSFUL; | ||||
} | ||||
paul
|
r35 | } | ||
paul
|
r40 | return status; | ||
paul
|
r32 | } | ||
paul
|
r111 | void launch_waveform_picker( unsigned char mode, unsigned int transitionCoarseTime ) | ||
paul
|
r90 | { | ||
paul
|
r139 | WFP_reset_current_ring_nodes(); | ||
paul
|
r171 | |||
paul
|
r97 | reset_waveform_picker_regs(); | ||
paul
|
r171 | |||
paul
|
r90 | set_wfp_burst_enable_register( mode ); | ||
paul
|
r106 | |||
paul
|
r90 | LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER ); | ||
LEON_Unmask_interrupt( IRQ_WAVEFORM_PICKER ); | ||||
paul
|
r106 | |||
paul
|
r111 | if (transitionCoarseTime == 0) | ||
{ | ||||
waveform_picker_regs->start_date = time_management_regs->coarse_time; | ||||
} | ||||
else | ||||
{ | ||||
waveform_picker_regs->start_date = transitionCoarseTime; | ||||
} | ||||
paul
|
r166 | |||
paul
|
r95 | } | ||
paul
|
r118 | void launch_spectral_matrix( void ) | ||
paul
|
r95 | { | ||
paul
|
r117 | SM_reset_current_ring_nodes(); | ||
paul
|
r171 | |||
paul
|
r95 | reset_spectral_matrix_regs(); | ||
paul
|
r171 | |||
paul
|
r124 | reset_nb_sm(); | ||
paul
|
r99 | |||
paul
|
r171 | set_sm_irq_onNewMatrix( 1 ); | ||
paul
|
r103 | LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); | ||
LEON_Unmask_interrupt( IRQ_SPECTRAL_MATRIX ); | ||||
paul
|
r171 | |||
paul
|
r103 | } | ||
paul
|
r118 | void launch_spectral_matrix_simu( void ) | ||
{ | ||||
SM_reset_current_ring_nodes(); | ||||
reset_spectral_matrix_regs(); | ||||
paul
|
r124 | reset_nb_sm(); | ||
paul
|
r118 | |||
// Spectral Matrices simulator | ||||
timer_start( (gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_SM_SIMULATOR ); | ||||
LEON_Clear_interrupt( IRQ_SM_SIMULATOR ); | ||||
LEON_Unmask_interrupt( IRQ_SM_SIMULATOR ); | ||||
} | ||||
paul
|
r171 | void set_sm_irq_onNewMatrix( unsigned char value ) | ||
paul
|
r103 | { | ||
paul
|
r106 | if (value == 1) | ||
{ | ||||
spectral_matrix_regs->config = spectral_matrix_regs->config | 0x01; | ||||
} | ||||
else | ||||
{ | ||||
spectral_matrix_regs->config = spectral_matrix_regs->config & 0xfffffffe; // 1110 | ||||
} | ||||
paul
|
r103 | } | ||
paul
|
r171 | void set_sm_irq_onError( unsigned char value ) | ||
paul
|
r103 | { | ||
paul
|
r106 | if (value == 1) | ||
{ | ||||
paul
|
r171 | spectral_matrix_regs->config = spectral_matrix_regs->config | 0x02; | ||
paul
|
r106 | } | ||
else | ||||
{ | ||||
paul
|
r171 | spectral_matrix_regs->config = spectral_matrix_regs->config & 0xfffffffd; // 1101 | ||
paul
|
r106 | } | ||
paul
|
r103 | } | ||
paul
|
r187 | //***************************** | ||
// CONFIGURE CALIBRATION SIGNAL | ||||
void setCalibrationPrescaler( unsigned int prescaler ) | ||||
{ | ||||
// prescaling of the master clock (25 MHz) | ||||
// master clock is divided by 2^prescaler | ||||
time_management_regs->calPrescaler = prescaler; | ||||
} | ||||
void setCalibrationDivisor( unsigned int divisionFactor ) | ||||
{ | ||||
// division of the prescaled clock by the division factor | ||||
time_management_regs->calDivisor = divisionFactor; | ||||
} | ||||
void setCalibrationData( void ){ | ||||
unsigned int k; | ||||
unsigned short data; | ||||
float val; | ||||
float f0; | ||||
float f1; | ||||
float fs; | ||||
float Ts; | ||||
float scaleFactor; | ||||
f0 = 625; | ||||
f1 = 10000; | ||||
fs = 160256.410; | ||||
Ts = 1. / fs; | ||||
scaleFactor = 0.125 / 0.000654; // 191, 500 mVpp, 2 sinus waves => 250 mVpp each, amplitude = 125 mV | ||||
time_management_regs->calDataPtr = 0x00; | ||||
// build the signal for the SCM calibration | ||||
for (k=0; k<256; k++) | ||||
{ | ||||
val = sin( 2 * pi * f0 * k * Ts ) | ||||
+ sin( 2 * pi * f1 * k * Ts ); | ||||
data = (unsigned short) ((val * scaleFactor) + 2048); | ||||
time_management_regs->calData = data & 0xfff; | ||||
} | ||||
} | ||||
void setCalibrationDataInterleaved( void ){ | ||||
unsigned int k; | ||||
float val; | ||||
float f0; | ||||
float f1; | ||||
float fs; | ||||
float Ts; | ||||
unsigned short data[384]; | ||||
unsigned char *dataPtr; | ||||
f0 = 625; | ||||
f1 = 10000; | ||||
fs = 240384.615; | ||||
Ts = 1. / fs; | ||||
time_management_regs->calDataPtr = 0x00; | ||||
// build the signal for the SCM calibration | ||||
for (k=0; k<384; k++) | ||||
{ | ||||
val = sin( 2 * pi * f0 * k * Ts ) | ||||
+ sin( 2 * pi * f1 * k * Ts ); | ||||
data[k] = (unsigned short) (val * 512 + 2048); | ||||
} | ||||
// write the signal in interleaved mode | ||||
for (k=0; k<128; k++) | ||||
{ | ||||
dataPtr = (unsigned char*) &data[k*3 + 2]; | ||||
time_management_regs->calData = (data[k*3] & 0xfff) | ||||
+ ( (dataPtr[0] & 0x3f) << 12); | ||||
time_management_regs->calData = (data[k*3 + 1] & 0xfff) | ||||
+ ( (dataPtr[1] & 0x3f) << 12); | ||||
} | ||||
} | ||||
void setCalibrationReload( bool state) | ||||
{ | ||||
if (state == true) | ||||
{ | ||||
time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | 0x00000010; // [0001 0000] | ||||
} | ||||
else | ||||
{ | ||||
time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & 0xffffffef; // [1110 1111] | ||||
} | ||||
} | ||||
void setCalibrationEnable( bool state ) | ||||
{ | ||||
// this bit drives the multiplexer | ||||
if (state == true) | ||||
{ | ||||
time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | 0x00000040; // [0100 0000] | ||||
} | ||||
else | ||||
{ | ||||
time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & 0xffffffbf; // [1011 1111] | ||||
} | ||||
} | ||||
void setCalibrationInterleaved( bool state ) | ||||
{ | ||||
// this bit drives the multiplexer | ||||
if (state == true) | ||||
{ | ||||
time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | 0x00000020; // [0010 0000] | ||||
} | ||||
else | ||||
{ | ||||
time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & 0xffffffdf; // [1101 1111] | ||||
} | ||||
} | ||||
paul
|
r206 | void setCalibration( bool state ) | ||
paul
|
r187 | { | ||
paul
|
r206 | if (state == true) | ||
{ | ||||
setCalibrationEnable( true ); | ||||
setCalibrationReload( false ); | ||||
set_hk_lfr_calib_enable( true ); | ||||
} | ||||
else | ||||
{ | ||||
setCalibrationEnable( false ); | ||||
setCalibrationReload( true ); | ||||
set_hk_lfr_calib_enable( false ); | ||||
} | ||||
paul
|
r187 | } | ||
void configureCalibration( bool interleaved ) | ||||
{ | ||||
paul
|
r206 | setCalibration( false ); | ||
paul
|
r187 | if ( interleaved == true ) | ||
{ | ||||
setCalibrationInterleaved( true ); | ||||
setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000 | ||||
setCalibrationDivisor( 26 ); // => 240 384 | ||||
setCalibrationDataInterleaved(); | ||||
} | ||||
else | ||||
{ | ||||
setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000 | ||||
setCalibrationDivisor( 38 ); // => 160 256 (39 - 1) | ||||
setCalibrationData(); | ||||
} | ||||
} | ||||
paul@pc-solar1.lab-lpp.local
|
r23 | //**************** | ||
// CLOSING ACTIONS | ||||
paul
|
r107 | void update_last_TC_exe( ccsdsTelecommandPacket_t *TC, unsigned char * time ) | ||
paul@pc-solar1.lab-lpp.local
|
r21 | { | ||
paul
|
r77 | /** This function is used to update the HK packets statistics after a successful TC execution. | ||
* | ||||
* @param TC points to the TC being processed | ||||
* @param time is the time used to date the TC execution | ||||
* | ||||
*/ | ||||
paul
|
r107 | unsigned int val; | ||
paul@pc-solar1.lab-lpp.local
|
r21 | housekeeping_packet.hk_lfr_last_exe_tc_id[0] = TC->packetID[0]; | ||
housekeeping_packet.hk_lfr_last_exe_tc_id[1] = TC->packetID[1]; | ||||
housekeeping_packet.hk_lfr_last_exe_tc_type[0] = 0x00; | ||||
paul@pc-solar1.lab-lpp.local
|
r23 | housekeeping_packet.hk_lfr_last_exe_tc_type[1] = TC->serviceType; | ||
paul@pc-solar1.lab-lpp.local
|
r21 | housekeeping_packet.hk_lfr_last_exe_tc_subtype[0] = 0x00; | ||
paul@pc-solar1.lab-lpp.local
|
r23 | housekeeping_packet.hk_lfr_last_exe_tc_subtype[1] = TC->serviceSubType; | ||
paul
|
r107 | housekeeping_packet.hk_lfr_last_exe_tc_time[0] = time[0]; | ||
housekeeping_packet.hk_lfr_last_exe_tc_time[1] = time[1]; | ||||
housekeeping_packet.hk_lfr_last_exe_tc_time[2] = time[2]; | ||||
housekeeping_packet.hk_lfr_last_exe_tc_time[3] = time[3]; | ||||
housekeeping_packet.hk_lfr_last_exe_tc_time[4] = time[4]; | ||||
housekeeping_packet.hk_lfr_last_exe_tc_time[5] = time[5]; | ||||
val = housekeeping_packet.hk_lfr_exe_tc_cnt[0] * 256 + housekeeping_packet.hk_lfr_exe_tc_cnt[1]; | ||||
val++; | ||||
housekeeping_packet.hk_lfr_exe_tc_cnt[0] = (unsigned char) (val >> 8); | ||||
housekeeping_packet.hk_lfr_exe_tc_cnt[1] = (unsigned char) (val); | ||||
paul@pc-solar1.lab-lpp.local
|
r21 | } | ||
paul
|
r107 | void update_last_TC_rej(ccsdsTelecommandPacket_t *TC, unsigned char * time ) | ||
paul@pc-solar1.lab-lpp.local
|
r21 | { | ||
paul
|
r77 | /** This function is used to update the HK packets statistics after a TC rejection. | ||
* | ||||
* @param TC points to the TC being processed | ||||
* @param time is the time used to date the TC rejection | ||||
* | ||||
*/ | ||||
paul
|
r107 | unsigned int val; | ||
paul@pc-solar1.lab-lpp.local
|
r21 | housekeeping_packet.hk_lfr_last_rej_tc_id[0] = TC->packetID[0]; | ||
housekeeping_packet.hk_lfr_last_rej_tc_id[1] = TC->packetID[1]; | ||||
housekeeping_packet.hk_lfr_last_rej_tc_type[0] = 0x00; | ||||
paul@pc-solar1.lab-lpp.local
|
r23 | housekeeping_packet.hk_lfr_last_rej_tc_type[1] = TC->serviceType; | ||
paul@pc-solar1.lab-lpp.local
|
r21 | housekeeping_packet.hk_lfr_last_rej_tc_subtype[0] = 0x00; | ||
paul@pc-solar1.lab-lpp.local
|
r23 | housekeeping_packet.hk_lfr_last_rej_tc_subtype[1] = TC->serviceSubType; | ||
paul
|
r107 | housekeeping_packet.hk_lfr_last_rej_tc_time[0] = time[0]; | ||
housekeeping_packet.hk_lfr_last_rej_tc_time[1] = time[1]; | ||||
housekeeping_packet.hk_lfr_last_rej_tc_time[2] = time[2]; | ||||
housekeeping_packet.hk_lfr_last_rej_tc_time[3] = time[3]; | ||||
housekeeping_packet.hk_lfr_last_rej_tc_time[4] = time[4]; | ||||
housekeeping_packet.hk_lfr_last_rej_tc_time[5] = time[5]; | ||||
val = housekeeping_packet.hk_lfr_rej_tc_cnt[0] * 256 + housekeeping_packet.hk_lfr_rej_tc_cnt[1]; | ||||
val++; | ||||
housekeeping_packet.hk_lfr_rej_tc_cnt[0] = (unsigned char) (val >> 8); | ||||
housekeeping_packet.hk_lfr_rej_tc_cnt[1] = (unsigned char) (val); | ||||
paul@pc-solar1.lab-lpp.local
|
r21 | } | ||
paul
|
r104 | void close_action(ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id ) | ||
paul@pc-solar1.lab-lpp.local
|
r21 | { | ||
paul
|
r77 | /** This function is the last step of the TC execution workflow. | ||
* | ||||
* @param TC points to the TC being processed | ||||
* @param result is the result of the TC execution (LFR_SUCCESSFUL / LFR_DEFAULT) | ||||
* @param queue_id is the id of the RTEMS message queue used to send TM packets | ||||
* @param time is the time used to date the TC execution | ||||
* | ||||
*/ | ||||
paul
|
r109 | unsigned char requestedMode; | ||
paul@pc-solar1.lab-lpp.local
|
r21 | if (result == LFR_SUCCESSFUL) | ||
{ | ||||
paul
|
r107 | if ( !( (TC->serviceType==TC_TYPE_TIME) & (TC->serviceSubType==TC_SUBTYPE_UPDT_TIME) ) | ||
& | ||||
!( (TC->serviceType==TC_TYPE_GEN) & (TC->serviceSubType==TC_SUBTYPE_UPDT_INFO)) | ||||
paul
|
r46 | ) | ||
paul
|
r33 | { | ||
paul
|
r104 | send_tm_lfr_tc_exe_success( TC, queue_id ); | ||
paul
|
r33 | } | ||
paul
|
r109 | if ( (TC->serviceType == TC_TYPE_GEN) & (TC->serviceSubType == TC_SUBTYPE_ENTER) ) | ||
{ | ||||
//********************************** | ||||
// UPDATE THE LFRMODE LOCAL VARIABLE | ||||
requestedMode = TC->dataAndCRC[1]; | ||||
housekeeping_packet.lfr_status_word[0] = (unsigned char) ((requestedMode << 4) + 0x0d); | ||||
updateLFRCurrentMode(); | ||||
} | ||||
paul@pc-solar1.lab-lpp.local
|
r21 | } | ||
paul
|
r115 | else if (result == LFR_EXE_ERROR) | ||
paul
|
r112 | { | ||
send_tm_lfr_tc_exe_error( TC, queue_id ); | ||||
} | ||||
paul@pc-solar1.lab-lpp.local
|
r21 | } | ||
paul@pc-solar1.lab-lpp.local
|
r12 | //*************************** | ||
// Interrupt Service Routines | ||||
rtems_isr commutation_isr1( rtems_vector_number vector ) | ||||
{ | ||||
paul@pc-solar1.lab-lpp.local
|
r18 | if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) { | ||
paul@pc-solar1.lab-lpp.local
|
r15 | printf("In commutation_isr1 *** Error sending event to DUMB\n"); | ||
paul@pc-solar1.lab-lpp.local
|
r18 | } | ||
paul@pc-solar1.lab-lpp.local
|
r12 | } | ||
paul@pc-solar1.lab-lpp.local
|
r9 | |||
paul@pc-solar1.lab-lpp.local
|
r12 | rtems_isr commutation_isr2( rtems_vector_number vector ) | ||
{ | ||||
paul@pc-solar1.lab-lpp.local
|
r18 | if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) { | ||
paul@pc-solar1.lab-lpp.local
|
r15 | printf("In commutation_isr2 *** Error sending event to DUMB\n"); | ||
paul@pc-solar1.lab-lpp.local
|
r18 | } | ||
paul@pc-solar1.lab-lpp.local
|
r12 | } | ||
paul
|
r45 | //**************** | ||
// OTHER FUNCTIONS | ||||
void updateLFRCurrentMode() | ||||
{ | ||||
/** This function updates the value of the global variable lfrCurrentMode. | ||||
* | ||||
* lfrCurrentMode is a parameter used by several functions to know in which mode LFR is running. | ||||
* | ||||
*/ | ||||
// update the local value of lfrCurrentMode with the value contained in the housekeeping_packet structure | ||||
lfrCurrentMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4; | ||||
} | ||||
paul@pc-solar1.lab-lpp.local
|
r12 | |||
paul
|
r171 | void set_lfr_soft_reset( unsigned char value ) | ||
{ | ||||
if (value == 1) | ||||
{ | ||||
time_management_regs->ctrl = time_management_regs->ctrl | 0x00000004; // [0100] | ||||
} | ||||
else | ||||
{ | ||||
time_management_regs->ctrl = time_management_regs->ctrl & 0xfffffffb; // [1011] | ||||
} | ||||
} | ||||
void reset_lfr( void ) | ||||
{ | ||||
set_lfr_soft_reset( 1 ); | ||||
set_lfr_soft_reset( 0 ); | ||||
paul
|
r212 | |||
set_hk_lfr_sc_potential_flag( true ); | ||||
paul
|
r171 | } | ||