tc_handler.c
1702 lines
| 54.5 KiB
| text/x-c
|
CLexer
/ src / tc_handler.c
r390 | /*------------------------------------------------------------------------------ | |||
-- Solar Orbiter's Low Frequency Receiver Flight Software (LFR FSW), | ||||
-- This file is a part of the LFR FSW | ||||
-- Copyright (C) 2012-2018, Plasma Physics Laboratory - CNRS | ||||
-- | ||||
-- This program is free software; you can redistribute it and/or modify | ||||
-- it under the terms of the GNU General Public License as published by | ||||
-- the Free Software Foundation; either version 2 of the License, or | ||||
-- (at your option) any later version. | ||||
-- | ||||
-- This program is distributed in the hope that it will be useful, | ||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
-- GNU General Public License for more details. | ||||
-- | ||||
-- You should have received a copy of the GNU General Public License | ||||
-- along with this program; if not, write to the Free Software | ||||
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||||
-------------------------------------------------------------------------------*/ | ||||
/*-- Author : Paul Leroy | ||||
-- Contact : Alexis Jeandet | ||||
-- Mail : alexis.jeandet@lpp.polytechnique.fr | ||||
----------------------------------------------------------------------------*/ | ||||
|
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" | ||||
|
r187 | #include "math.h" | ||
|
r5 | |||
|
r7 | //*********** | ||
// RTEMS TASK | ||||
|
r5 | |||
|
r9 | rtems_task actn_task( rtems_task_argument unused ) | ||
{ | ||||
|
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. | ||||
* | ||||
*/ | ||||
|
r23 | int result; | ||
rtems_status_code status; // RTEMS status code | ||||
|
r338 | ccsdsTelecommandPacket_t __attribute__((aligned(4))) TC; // TC sent to the ACTN task | ||
|
r23 | size_t size; // size of the incoming TC packet | ||
unsigned char subtype; // subtype of the current TC packet | ||||
|
r318 | unsigned char time[BYTES_PER_TIME]; | ||
|
r35 | rtems_id queue_rcv_id; | ||
rtems_id queue_snd_id; | ||||
|
r320 | memset(&TC, 0, sizeof(ccsdsTelecommandPacket_t)); | ||
size = 0; | ||||
queue_rcv_id = RTEMS_ID_NONE; | ||||
queue_snd_id = RTEMS_ID_NONE; | ||||
|
r82 | status = get_message_queue_id_recv( &queue_rcv_id ); | ||
|
r35 | if (status != RTEMS_SUCCESSFUL) | ||
{ | ||||
|
r82 | PRINTF1("in ACTN *** ERR get_message_queue_id_recv %d\n", status) | ||
|
r35 | } | ||
|
r82 | status = get_message_queue_id_send( &queue_snd_id ); | ||
|
r35 | if (status != RTEMS_SUCCESSFUL) | ||
{ | ||||
|
r82 | PRINTF1("in ACTN *** ERR get_message_queue_id_send %d\n", status) | ||
|
r35 | } | ||
|
r23 | |||
result = LFR_SUCCESSFUL; | ||||
subtype = 0; // subtype of the current TC packet | ||||
|
r5 | |||
|
r285 | BOOT_PRINTF("in ACTN *** \n"); | ||
|
r11 | |||
|
r285 | while(1) | ||
|
r9 | { | ||
|
r35 | status = rtems_message_queue_receive( queue_rcv_id, (char*) &TC, &size, | ||
|
r237 | RTEMS_WAIT, RTEMS_NO_TIMEOUT); | ||
|
r75 | getTime( time ); // set time to the current time | ||
|
r77 | if (status!=RTEMS_SUCCESSFUL) | ||
{ | ||||
PRINTF1("ERR *** in task ACTN *** error receiving a message, code %d \n", status) | ||||
} | ||||
|
r9 | else | ||
{ | ||||
|
r23 | subtype = TC.serviceSubType; | ||
|
r9 | switch(subtype) | ||
{ | ||||
|
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: | ||||
|
r222 | result = action_dump_par( &TC, queue_snd_id ); | ||
|
r192 | 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; | ||||
|
r283 | case TC_SUBTYPE_LOAD_FILTER_PAR: | ||
result = action_load_filter_par( &TC, queue_snd_id, time ); | ||||
|
r282 | close_action( &TC, result, queue_snd_id ); | ||
break; | ||||
|
r192 | case TC_SUBTYPE_UPDT_TIME: | ||
result = action_update_time( &TC ); | ||||
close_action( &TC, result, queue_snd_id ); | ||||
break; | ||||
default: | ||||
break; | ||||
|
r9 | } | ||
} | ||||
} | ||||
} | ||||
//*********** | ||||
// TC ACTIONS | ||||
|
r15 | |||
|
r75 | int action_reset(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) | ||
|
r9 | { | ||
|
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 | ||||
* | ||||
*/ | ||||
|
r258 | PRINTF("this is the end!!!\n"); | ||
r400 | #ifdef GCOV_ENABLED | |||
#ifndef GCOV_USE_EXIT | ||||
extern void gcov_exit (void); | ||||
gcov_exit(); | ||||
#endif | ||||
#endif | ||||
|
r258 | exit(0); | ||
|
r75 | send_tm_lfr_tc_exe_not_implemented( TC, queue_id, time ); | ||
|
r258 | |||
|
r21 | return LFR_DEFAULT; | ||
|
r9 | } | ||
|
r111 | int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id ) | ||
|
r33 | { | ||
|
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 | ||||
* | ||||
*/ | ||||
|
r33 | rtems_status_code status; | ||
unsigned char requestedMode; | ||||
|
r111 | unsigned int transitionCoarseTime; | ||
|
r112 | unsigned char * bytePosPtr; | ||
|
r33 | |||
|
r112 | bytePosPtr = (unsigned char *) &TC->packetID; | ||
requestedMode = bytePosPtr[ BYTE_POS_CP_MODE_LFR_SET ]; | ||||
|
r339 | copyInt32ByChar( (char*) &transitionCoarseTime, &bytePosPtr[ BYTE_POS_CP_LFR_ENTER_MODE_TIME ] ); | ||
|
r338 | transitionCoarseTime = transitionCoarseTime & COARSE_TIME_MASK; | ||
|
r109 | status = check_mode_value( requestedMode ); | ||
|
r110 | |||
|
r112 | if ( status != LFR_SUCCESSFUL ) // the mode value is inconsistent | ||
|
r33 | { | ||
|
r112 | send_tm_lfr_tc_exe_inconsistent( TC, queue_id, BYTE_POS_CP_MODE_LFR_SET, requestedMode ); | ||
|
r33 | } | ||
|
r240 | |||
|
r219 | else // the mode value is valid, check the transition | ||
|
r33 | { | ||
|
r109 | status = check_mode_transition(requestedMode); | ||
|
r111 | if (status != LFR_SUCCESSFUL) | ||
|
r109 | { | ||
|
r111 | PRINTF("ERR *** in action_enter_mode *** check_mode_transition\n") | ||
|
r237 | send_tm_lfr_tc_exe_not_executable( TC, queue_id ); | ||
|
r37 | } | ||
|
r33 | } | ||
|
r219 | if ( status == LFR_SUCCESSFUL ) // the transition is valid, check the date | ||
|
r111 | { | ||
status = check_transition_date( transitionCoarseTime ); | ||||
if (status != LFR_SUCCESSFUL) | ||||
{ | ||||
|
r254 | PRINTF("ERR *** in action_enter_mode *** check_transition_date\n"); | ||
send_tm_lfr_tc_exe_not_executable(TC, queue_id ); | ||||
|
r111 | } | ||
} | ||||
if ( status == LFR_SUCCESSFUL ) // the date is valid, enter the mode | ||||
{ | ||||
PRINTF1("OK *** in action_enter_mode *** enter mode %d\n", requestedMode); | ||||
|
r237 | |||
switch(requestedMode) | ||||
{ | ||||
case LFR_MODE_STANDBY: | ||||
status = enter_mode_standby(); | ||||
break; | ||||
case LFR_MODE_NORMAL: | ||||
status = enter_mode_normal( transitionCoarseTime ); | ||||
break; | ||||
case LFR_MODE_BURST: | ||||
status = enter_mode_burst( transitionCoarseTime ); | ||||
break; | ||||
case LFR_MODE_SBM1: | ||||
status = enter_mode_sbm1( transitionCoarseTime ); | ||||
break; | ||||
case LFR_MODE_SBM2: | ||||
status = enter_mode_sbm2( transitionCoarseTime ); | ||||
break; | ||||
default: | ||||
break; | ||||
} | ||||
|
r111 | |||
|
r259 | if (status != RTEMS_SUCCESSFUL) | ||
{ | ||||
status = LFR_EXE_ERROR; | ||||
} | ||||
|
r258 | } | ||
|
r33 | return status; | ||
} | ||||
|
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 | ||||
* | ||||
|
r46 | * @return LFR directive status code: | ||
* - LFR_DEFAULT | ||||
* - LFR_SUCCESSFUL | ||||
* | ||||
|
r40 | */ | ||
|
r23 | unsigned int val; | ||
|
r104 | unsigned int status; | ||
unsigned char mode; | ||||
|
r112 | unsigned char * bytePosPtr; | ||
|
r352 | int pos; | ||
float value; | ||||
pos = INIT_CHAR; | ||||
value = INIT_FLOAT; | ||||
status = LFR_DEFAULT; | ||||
|
r112 | |||
bytePosPtr = (unsigned char *) &TC->packetID; | ||||
|
r18 | |||
|
r107 | // check LFR mode | ||
|
r318 | mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET5 ] & BITS_LFR_MODE) >> SHIFT_LFR_MODE; | ||
|
r104 | status = check_update_info_hk_lfr_mode( mode ); | ||
|
r107 | if (status == LFR_SUCCESSFUL) // check TDS mode | ||
|
r104 | { | ||
|
r318 | mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & BITS_TDS_MODE) >> SHIFT_TDS_MODE; | ||
|
r104 | status = check_update_info_hk_tds_mode( mode ); | ||
} | ||||
|
r107 | if (status == LFR_SUCCESSFUL) // check THR mode | ||
|
r104 | { | ||
|
r318 | mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & BITS_THR_MODE); | ||
|
r104 | status = check_update_info_hk_thr_mode( mode ); | ||
} | ||||
|
r352 | if (status == LFR_SUCCESSFUL) // check reaction wheels frequencies | ||
|
r104 | { | ||
|
r352 | status = check_all_sy_lfr_rw_f(TC, &pos, &value); | ||
|
r104 | } | ||
|
r352 | // if the parameters checking succeeds, udpate all parameters | ||
if (status == LFR_SUCCESSFUL) | ||||
{ | ||||
// pa_bia_status_info | ||||
// => pa_bia_mode_mux_set 3 bits | ||||
// => pa_bia_mode_hv_enabled 1 bit | ||||
// => pa_bia_mode_bias1_enabled 1 bit | ||||
// => pa_bia_mode_bias2_enabled 1 bit | ||||
// => pa_bia_mode_bias3_enabled 1 bit | ||||
// => pa_bia_on_off (cp_dpu_bias_on_off) | ||||
pa_bia_status_info = bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET2 ] & BITS_BIA; // [1111 1110] | ||||
pa_bia_status_info = pa_bia_status_info | ||||
| (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET1 ] & 1); | ||||
|
r224 | |||
|
r352 | // REACTION_WHEELS_FREQUENCY, copy the incoming parameters in the local variable (to be copied in HK packets) | ||
getReactionWheelsFrequencies( TC ); | ||||
set_hk_lfr_sc_rw_f_flags(); | ||||
build_sy_lfr_rw_masks(); | ||||
// once the masks are built, they have to be merged with the fbins_mask | ||||
merge_fbins_masks(); | ||||
|
r283 | |||
|
r352 | // increase the TC_LFR_UPDATE_INFO counter | ||
if (status == LFR_SUCCESSFUL) // if the parameter check is successful | ||||
{ | ||||
val = (housekeeping_packet.hk_lfr_update_info_tc_cnt[0] * CONST_256) | ||||
+ housekeeping_packet.hk_lfr_update_info_tc_cnt[1]; | ||||
val++; | ||||
housekeeping_packet.hk_lfr_update_info_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE); | ||||
housekeeping_packet.hk_lfr_update_info_tc_cnt[1] = (unsigned char) (val); | ||||
} | ||||
} | ||||
|
r316 | |||
|
r352 | return status; | ||
|
r23 | } | ||
|
r75 | int action_enable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) | ||
|
r23 | { | ||
|
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 | ||||
* | ||||
*/ | ||||
|
r23 | int result; | ||
result = LFR_DEFAULT; | ||||
|
r206 | setCalibration( true ); | ||
|
r187 | |||
result = LFR_SUCCESSFUL; | ||||
|
r104 | |||
|
r23 | return result; | ||
} | ||||
|
r75 | int action_disable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) | ||
|
r23 | { | ||
|
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 | ||||
* | ||||
*/ | ||||
|
r23 | int result; | ||
result = LFR_DEFAULT; | ||||
|
r206 | setCalibration( false ); | ||
|
r187 | |||
result = LFR_SUCCESSFUL; | ||||
|
r104 | |||
|
r23 | return result; | ||
} | ||||
|
r33 | int action_update_time(ccsdsTelecommandPacket_t *TC) | ||
|
r23 | { | ||
|
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 | ||||
* | ||||
|
r46 | * @return LFR_SUCCESSFUL | ||
* | ||||
|
r40 | */ | ||
|
r23 | unsigned int val; | ||
|
r19 | |||
|
r318 | time_management_regs->coarse_time_load = (TC->dataAndCRC[BYTE_0] << SHIFT_3_BYTES) | ||
+ (TC->dataAndCRC[BYTE_1] << SHIFT_2_BYTES) | ||||
+ (TC->dataAndCRC[BYTE_2] << SHIFT_1_BYTE) | ||||
+ TC->dataAndCRC[BYTE_3]; | ||||
|
r109 | |||
|
r318 | val = (housekeeping_packet.hk_lfr_update_time_tc_cnt[0] * CONST_256) | ||
|
r23 | + housekeeping_packet.hk_lfr_update_time_tc_cnt[1]; | ||
val++; | ||||
|
r318 | housekeeping_packet.hk_lfr_update_time_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE); | ||
|
r23 | housekeeping_packet.hk_lfr_update_time_tc_cnt[1] = (unsigned char) (val); | ||
|
r271 | oneTcLfrUpdateTimeReceived = 1; | ||
|
r23 | return LFR_SUCCESSFUL; | ||
} | ||||
//******************* | ||||
// ENTERING THE MODES | ||||
|
r109 | int check_mode_value( unsigned char requestedMode ) | ||
{ | ||||
int status; | ||||
|
r23 | |||
|
r320 | status = LFR_DEFAULT; | ||
|
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 ) | ||||
|
r23 | { | ||
|
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 | ||||
* | ||||
*/ | ||||
|
r23 | int status; | ||
|
r19 | |||
|
r23 | switch (requestedMode) | ||
{ | ||||
case LFR_MODE_STANDBY: | ||||
|
r33 | if ( lfrCurrentMode == LFR_MODE_STANDBY ) { | ||
|
r23 | status = LFR_DEFAULT; | ||
} | ||||
else | ||||
{ | ||||
status = LFR_SUCCESSFUL; | ||||
} | ||||
break; | ||||
case LFR_MODE_NORMAL: | ||||
|
r33 | if ( lfrCurrentMode == LFR_MODE_NORMAL ) { | ||
|
r23 | status = LFR_DEFAULT; | ||
} | ||||
else { | ||||
status = LFR_SUCCESSFUL; | ||||
} | ||||
break; | ||||
case LFR_MODE_BURST: | ||||
|
r33 | if ( lfrCurrentMode == LFR_MODE_BURST ) { | ||
|
r23 | status = LFR_DEFAULT; | ||
} | ||||
else { | ||||
status = LFR_SUCCESSFUL; | ||||
} | ||||
break; | ||||
case LFR_MODE_SBM1: | ||||
|
r33 | if ( lfrCurrentMode == LFR_MODE_SBM1 ) { | ||
|
r23 | status = LFR_DEFAULT; | ||
} | ||||
else { | ||||
status = LFR_SUCCESSFUL; | ||||
} | ||||
break; | ||||
case LFR_MODE_SBM2: | ||||
|
r33 | if ( lfrCurrentMode == LFR_MODE_SBM2 ) { | ||
|
r23 | status = LFR_DEFAULT; | ||
} | ||||
else { | ||||
status = LFR_SUCCESSFUL; | ||||
} | ||||
break; | ||||
default: | ||||
status = LFR_DEFAULT; | ||||
break; | ||||
} | ||||
|
r19 | |||
|
r21 | return status; | ||
|
r10 | } | ||
|
r245 | void update_last_valid_transition_date( unsigned int transitionCoarseTime ) | ||
|
r240 | { | ||
|
r257 | if (transitionCoarseTime == 0) | ||
{ | ||||
lastValidEnterModeTime = time_management_regs->coarse_time + 1; | ||||
|
r271 | PRINTF1("lastValidEnterModeTime = 0x%x (transitionCoarseTime = 0 => coarse_time+1)\n", lastValidEnterModeTime); | ||
|
r257 | } | ||
else | ||||
{ | ||||
lastValidEnterModeTime = transitionCoarseTime; | ||||
PRINTF1("lastValidEnterModeTime = 0x%x\n", transitionCoarseTime); | ||||
} | ||||
|
r240 | } | ||
|
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 | ||||
{ | ||||
|
r318 | localCoarseTime = time_management_regs->coarse_time & COARSE_TIME_MASK; | ||
|
r111 | |||
|
r253 | PRINTF2("localTime = %x, transitionTime = %x\n", localCoarseTime, transitionCoarseTime); | ||
|
r191 | |||
|
r253 | if ( transitionCoarseTime <= localCoarseTime ) // SSS-CP-EQS-322 | ||
|
r111 | { | ||
status = LFR_DEFAULT; | ||||
|
r253 | PRINTF("ERR *** in check_transition_date *** transitionCoarseTime <= localCoarseTime\n"); | ||
|
r111 | } | ||
if (status == LFR_SUCCESSFUL) | ||||
{ | ||||
deltaCoarseTime = transitionCoarseTime - localCoarseTime; | ||||
|
r318 | if ( deltaCoarseTime > MAX_DELTA_COARSE_TIME ) // SSS-CP-EQS-323 | ||
|
r111 | { | ||
status = LFR_DEFAULT; | ||||
PRINTF1("ERR *** in check_transition_date *** deltaCoarseTime = %x\n", deltaCoarseTime) | ||||
} | ||||
} | ||||
} | ||||
return status; | ||||
} | ||||
|
r238 | int restart_asm_activities( unsigned char lfrRequestedMode ) | ||
{ | ||||
rtems_status_code status; | ||||
status = stop_spectral_matrices(); | ||||
|
r259 | thisIsAnASMRestart = 1; | ||
|
r238 | status = restart_asm_tasks( lfrRequestedMode ); | ||
launch_spectral_matrix(); | ||||
return status; | ||||
} | ||||
int stop_spectral_matrices( void ) | ||||
{ | ||||
/** This function stops and restarts the current mode average spectral matrices activities. | ||||
* | ||||
* @return RTEMS directive status codes: | ||||
* - RTEMS_SUCCESSFUL - task restarted successfully | ||||
* - RTEMS_INVALID_ID - task id invalid | ||||
* - RTEMS_ALREADY_SUSPENDED - task already suspended | ||||
* | ||||
*/ | ||||
rtems_status_code status; | ||||
status = RTEMS_SUCCESSFUL; | ||||
// (1) mask interruptions | ||||
|
r259 | LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // mask spectral matrix interrupt | ||
|
r238 | |||
// (2) reset spectral matrices registers | ||||
set_sm_irq_onNewMatrix( 0 ); // stop the spectral matrices | ||||
reset_sm_status(); | ||||
// (3) clear interruptions | ||||
LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt | ||||
// suspend several tasks | ||||
if (lfrCurrentMode != LFR_MODE_STANDBY) { | ||||
status = suspend_asm_tasks(); | ||||
} | ||||
if (status != RTEMS_SUCCESSFUL) | ||||
{ | ||||
PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status) | ||||
} | ||||
return status; | ||||
} | ||||
|
r109 | int stop_current_mode( void ) | ||
|
r20 | { | ||
|
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 | ||||
* | ||||
*/ | ||||
|
r21 | rtems_status_code status; | ||
|
r23 | |||
status = RTEMS_SUCCESSFUL; | ||||
|
r22 | |||
|
r99 | // (1) mask interruptions | ||
|
r31 | LEON_Mask_interrupt( IRQ_WAVEFORM_PICKER ); // mask waveform picker interrupt | ||
|
r238 | LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt | ||
|
r99 | |||
|
r171 | // (2) reset waveform picker registers | ||
|
r47 | reset_wfp_burst_enable(); // reset burst and enable bits | ||
reset_wfp_status(); // reset all the status bits | ||||
|
r110 | |||
|
r171 | // (3) reset spectral matrices registers | ||
|
r238 | set_sm_irq_onNewMatrix( 0 ); // stop the spectral matrices | ||
|
r171 | reset_sm_status(); | ||
|
r179 | // reset lfr VHDL module | ||
reset_lfr(); | ||||
|
r106 | reset_extractSWF(); // reset the extractSWF flag to false | ||
|
r99 | |||
|
r171 | // (4) clear interruptions | ||
LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER ); // clear waveform picker interrupt | ||||
LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt | ||||
|
r20 | // suspend several tasks | ||
|
r35 | if (lfrCurrentMode != LFR_MODE_STANDBY) { | ||
|
r40 | status = suspend_science_tasks(); | ||
|
r21 | } | ||
|
r20 | |||
|
r22 | if (status != RTEMS_SUCCESSFUL) | ||
{ | ||||
|
r40 | PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status) | ||
|
r22 | } | ||
|
r21 | return status; | ||
|
r20 | } | ||
|
r254 | int enter_mode_standby( void ) | ||
|
r20 | { | ||
|
r240 | /** This function is used to put LFR in the STANDBY mode. | ||
* | ||||
* @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE | ||||
* | ||||
* @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 | ||||
* | ||||
* The STANDBY mode does not depends on a specific transition date, the effect of the TC_LFR_ENTER_MODE | ||||
* is immediate. | ||||
* | ||||
*/ | ||||
|
r237 | int status; | ||
|
r33 | |||
|
r237 | status = stop_current_mode(); // STOP THE CURRENT MODE | ||
|
r99 | #ifdef PRINT_TASK_STATISTICS | ||
|
r237 | rtems_cpu_usage_report(); | ||
|
r98 | #endif | ||
#ifdef PRINT_STACK_REPORT | ||||
|
r237 | PRINTF("stack report selected\n") | ||
rtems_stack_checker_report_usage(); | ||||
#endif | ||||
return status; | ||||
} | ||||
int enter_mode_normal( unsigned int transitionCoarseTime ) | ||||
{ | ||||
|
r240 | /** This function is used to start the NORMAL mode. | ||
* | ||||
* @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE | ||||
* | ||||
* @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 | ||||
* | ||||
* The way the NORMAL mode is started depends on the LFR current mode. If LFR is in SBM1 or SBM2, | ||||
* the snapshots are not restarted, only ASM, BP and CWF data generation are affected. | ||||
* | ||||
*/ | ||||
|
r237 | int status; | ||
#ifdef PRINT_TASK_STATISTICS | ||||
rtems_cpu_usage_reset(); | ||||
|
r98 | #endif | ||
|
r237 | |||
status = RTEMS_UNSATISFIED; | ||||
switch( lfrCurrentMode ) | ||||
{ | ||||
case LFR_MODE_STANDBY: | ||||
status = restart_science_tasks( LFR_MODE_NORMAL ); // restart science tasks | ||||
if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules | ||||
{ | ||||
launch_spectral_matrix( ); | ||||
launch_waveform_picker( LFR_MODE_NORMAL, transitionCoarseTime ); | ||||
} | ||||
break; | ||||
case LFR_MODE_BURST: | ||||
status = stop_current_mode(); // stop the current mode | ||||
status = restart_science_tasks( LFR_MODE_NORMAL ); // restart the science tasks | ||||
if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules | ||||
{ | ||||
launch_spectral_matrix( ); | ||||
launch_waveform_picker( LFR_MODE_NORMAL, transitionCoarseTime ); | ||||
|
r219 | } | ||
|
r237 | break; | ||
case LFR_MODE_SBM1: | ||||
|
r271 | status = restart_asm_activities( LFR_MODE_NORMAL ); // this is necessary to restart ASM tasks to update the parameters | ||
|
r240 | status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action | ||
|
r271 | update_last_valid_transition_date( transitionCoarseTime ); | ||
|
r237 | break; | ||
case LFR_MODE_SBM2: | ||||
|
r271 | status = restart_asm_activities( LFR_MODE_NORMAL ); // this is necessary to restart ASM tasks to update the parameters | ||
|
r240 | status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action | ||
|
r271 | update_last_valid_transition_date( transitionCoarseTime ); | ||
|
r237 | break; | ||
default: | ||||
break; | ||||
} | ||||
if (status != RTEMS_SUCCESSFUL) | ||||
{ | ||||
PRINTF1("ERR *** in enter_mode_normal *** status = %d\n", status) | ||||
status = RTEMS_UNSATISFIED; | ||||
} | ||||
return status; | ||||
} | ||||
int enter_mode_burst( unsigned int transitionCoarseTime ) | ||||
{ | ||||
|
r240 | /** This function is used to start the BURST mode. | ||
* | ||||
* @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE | ||||
* | ||||
* @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 | ||||
* | ||||
* The way the BURST mode is started does not depend on the LFR current mode. | ||||
* | ||||
*/ | ||||
|
r237 | int status; | ||
#ifdef PRINT_TASK_STATISTICS | ||||
rtems_cpu_usage_reset(); | ||||
#endif | ||||
status = stop_current_mode(); // stop the current mode | ||||
status = restart_science_tasks( LFR_MODE_BURST ); // restart the science tasks | ||||
if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules | ||||
{ | ||||
launch_spectral_matrix( ); | ||||
launch_waveform_picker( LFR_MODE_BURST, transitionCoarseTime ); | ||||
|
r98 | } | ||
|
r33 | if (status != RTEMS_SUCCESSFUL) | ||
|
r23 | { | ||
|
r237 | PRINTF1("ERR *** in enter_mode_burst *** status = %d\n", status) | ||
status = RTEMS_UNSATISFIED; | ||||
} | ||||
return status; | ||||
} | ||||
int enter_mode_sbm1( unsigned int transitionCoarseTime ) | ||||
{ | ||||
|
r240 | /** This function is used to start the SBM1 mode. | ||
* | ||||
* @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE | ||||
* | ||||
* @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 | ||||
* | ||||
* The way the SBM1 mode is started depends on the LFR current mode. If LFR is in NORMAL or SBM2, | ||||
* the snapshots are not restarted, only ASM, BP and CWF data generation are affected. In other | ||||
* cases, the acquisition is completely restarted. | ||||
* | ||||
*/ | ||||
|
r237 | int status; | ||
#ifdef PRINT_TASK_STATISTICS | ||||
rtems_cpu_usage_reset(); | ||||
#endif | ||||
status = RTEMS_UNSATISFIED; | ||||
switch( lfrCurrentMode ) | ||||
{ | ||||
case LFR_MODE_STANDBY: | ||||
status = restart_science_tasks( LFR_MODE_SBM1 ); // restart science tasks | ||||
if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules | ||||
{ | ||||
launch_spectral_matrix( ); | ||||
launch_waveform_picker( LFR_MODE_SBM1, transitionCoarseTime ); | ||||
} | ||||
break; | ||||
case LFR_MODE_NORMAL: // lfrCurrentMode will be updated after the execution of close_action | ||||
|
r271 | status = restart_asm_activities( LFR_MODE_SBM1 ); | ||
|
r237 | status = LFR_SUCCESSFUL; | ||
|
r271 | update_last_valid_transition_date( transitionCoarseTime ); | ||
|
r237 | break; | ||
case LFR_MODE_BURST: | ||||
status = stop_current_mode(); // stop the current mode | ||||
status = restart_science_tasks( LFR_MODE_SBM1 ); // restart the science tasks | ||||
if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules | ||||
{ | ||||
launch_spectral_matrix( ); | ||||
launch_waveform_picker( LFR_MODE_SBM1, transitionCoarseTime ); | ||||
} | ||||
break; | ||||
case LFR_MODE_SBM2: | ||||
|
r271 | status = restart_asm_activities( LFR_MODE_SBM1 ); | ||
|
r237 | status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action | ||
|
r271 | update_last_valid_transition_date( transitionCoarseTime ); | ||
|
r237 | break; | ||
default: | ||||
break; | ||||
} | ||||
if (status != RTEMS_SUCCESSFUL) | ||||
{ | ||||
|
r258 | PRINTF1("ERR *** in enter_mode_sbm1 *** status = %d\n", status); | ||
status = RTEMS_UNSATISFIED; | ||||
|
r237 | } | ||
return status; | ||||
} | ||||
int enter_mode_sbm2( unsigned int transitionCoarseTime ) | ||||
{ | ||||
|
r240 | /** This function is used to start the SBM2 mode. | ||
* | ||||
* @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE | ||||
* | ||||
* @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 | ||||
* | ||||
* The way the SBM2 mode is started depends on the LFR current mode. If LFR is in NORMAL or SBM1, | ||||
* the snapshots are not restarted, only ASM, BP and CWF data generation are affected. In other | ||||
* cases, the acquisition is completely restarted. | ||||
* | ||||
*/ | ||||
|
r237 | int status; | ||
#ifdef PRINT_TASK_STATISTICS | ||||
rtems_cpu_usage_reset(); | ||||
#endif | ||||
status = RTEMS_UNSATISFIED; | ||||
switch( lfrCurrentMode ) | ||||
{ | ||||
case LFR_MODE_STANDBY: | ||||
status = restart_science_tasks( LFR_MODE_SBM2 ); // restart science tasks | ||||
if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules | ||||
{ | ||||
launch_spectral_matrix( ); | ||||
launch_waveform_picker( LFR_MODE_SBM2, transitionCoarseTime ); | ||||
} | ||||
break; | ||||
case LFR_MODE_NORMAL: | ||||
|
r271 | status = restart_asm_activities( LFR_MODE_SBM2 ); | ||
|
r237 | status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action | ||
|
r271 | update_last_valid_transition_date( transitionCoarseTime ); | ||
|
r237 | break; | ||
case LFR_MODE_BURST: | ||||
status = stop_current_mode(); // stop the current mode | ||||
status = restart_science_tasks( LFR_MODE_SBM2 ); // restart the science tasks | ||||
if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules | ||||
{ | ||||
launch_spectral_matrix( ); | ||||
launch_waveform_picker( LFR_MODE_SBM2, transitionCoarseTime ); | ||||
} | ||||
break; | ||||
case LFR_MODE_SBM1: | ||||
|
r271 | status = restart_asm_activities( LFR_MODE_SBM2 ); | ||
|
r237 | status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action | ||
|
r271 | update_last_valid_transition_date( transitionCoarseTime ); | ||
|
r237 | break; | ||
default: | ||||
break; | ||||
} | ||||
if (status != RTEMS_SUCCESSFUL) | ||||
{ | ||||
PRINTF1("ERR *** in enter_mode_sbm2 *** status = %d\n", status) | ||||
status = RTEMS_UNSATISFIED; | ||||
|
r23 | } | ||
|
r21 | |||
return status; | ||||
|
r20 | } | ||
|
r238 | int restart_science_tasks( unsigned char lfrRequestedMode ) | ||
|
r32 | { | ||
|
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 | ||||
* | ||||
|
r121 | * Science tasks are AVF0, PRC0, WFRM, CWF3, CW2, CWF1 | ||
|
r77 | * | ||
*/ | ||||
|
r318 | rtems_status_code status[NB_SCIENCE_TASKS]; | ||
|
r33 | rtems_status_code ret; | ||
|
r32 | |||
|
r33 | ret = RTEMS_SUCCESSFUL; | ||
|
r32 | |||
|
r318 | status[STATUS_0] = rtems_task_restart( Task_id[TASKID_AVF0], lfrRequestedMode ); | ||
if (status[STATUS_0] != RTEMS_SUCCESSFUL) | ||||
|
r35 | { | ||
|
r318 | PRINTF1("in restart_science_task *** AVF0 ERR %d\n", status[STATUS_0]) | ||
|
r121 | } | ||
|
r318 | status[STATUS_1] = rtems_task_restart( Task_id[TASKID_PRC0], lfrRequestedMode ); | ||
if (status[STATUS_1] != RTEMS_SUCCESSFUL) | ||||
|
r121 | { | ||
|
r318 | PRINTF1("in restart_science_task *** PRC0 ERR %d\n", status[STATUS_1]) | ||
|
r35 | } | ||
|
r318 | status[STATUS_2] = rtems_task_restart( Task_id[TASKID_WFRM],1 ); | ||
if (status[STATUS_2] != RTEMS_SUCCESSFUL) | ||||
|
r35 | { | ||
|
r318 | PRINTF1("in restart_science_task *** WFRM ERR %d\n", status[STATUS_2]) | ||
|
r35 | } | ||
|
r318 | status[STATUS_3] = rtems_task_restart( Task_id[TASKID_CWF3],1 ); | ||
if (status[STATUS_3] != RTEMS_SUCCESSFUL) | ||||
|
r35 | { | ||
|
r318 | PRINTF1("in restart_science_task *** CWF3 ERR %d\n", status[STATUS_3]) | ||
|
r35 | } | ||
|
r318 | status[STATUS_4] = rtems_task_restart( Task_id[TASKID_CWF2],1 ); | ||
if (status[STATUS_4] != RTEMS_SUCCESSFUL) | ||||
|
r35 | { | ||
|
r318 | PRINTF1("in restart_science_task *** CWF2 ERR %d\n", status[STATUS_4]) | ||
|
r35 | } | ||
|
r318 | status[STATUS_5] = rtems_task_restart( Task_id[TASKID_CWF1],1 ); | ||
if (status[STATUS_5] != RTEMS_SUCCESSFUL) | ||||
|
r35 | { | ||
|
r318 | PRINTF1("in restart_science_task *** CWF1 ERR %d\n", status[STATUS_5]) | ||
|
r35 | } | ||
|
r33 | |||
|
r318 | status[STATUS_6] = rtems_task_restart( Task_id[TASKID_AVF1], lfrRequestedMode ); | ||
if (status[STATUS_6] != RTEMS_SUCCESSFUL) | ||||
|
r117 | { | ||
|
r318 | PRINTF1("in restart_science_task *** AVF1 ERR %d\n", status[STATUS_6]) | ||
|
r117 | } | ||
|
r318 | status[STATUS_7] = rtems_task_restart( Task_id[TASKID_PRC1],lfrRequestedMode ); | ||
if (status[STATUS_7] != RTEMS_SUCCESSFUL) | ||||
|
r121 | { | ||
|
r318 | PRINTF1("in restart_science_task *** PRC1 ERR %d\n", status[STATUS_7]) | ||
|
r121 | } | ||
|
r318 | status[STATUS_8] = rtems_task_restart( Task_id[TASKID_AVF2], 1 ); | ||
if (status[STATUS_8] != RTEMS_SUCCESSFUL) | ||||
|
r126 | { | ||
|
r318 | PRINTF1("in restart_science_task *** AVF2 ERR %d\n", status[STATUS_8]) | ||
|
r126 | } | ||
|
r124 | |||
|
r318 | status[STATUS_9] = rtems_task_restart( Task_id[TASKID_PRC2], 1 ); | ||
if (status[STATUS_9] != RTEMS_SUCCESSFUL) | ||||
|
r126 | { | ||
|
r318 | PRINTF1("in restart_science_task *** PRC2 ERR %d\n", status[STATUS_9]) | ||
|
r126 | } | ||
|
r124 | |||
|
r318 | if ( (status[STATUS_0] != RTEMS_SUCCESSFUL) || (status[STATUS_1] != RTEMS_SUCCESSFUL) || | ||
(status[STATUS_2] != RTEMS_SUCCESSFUL) || (status[STATUS_3] != RTEMS_SUCCESSFUL) || | ||||
(status[STATUS_4] != RTEMS_SUCCESSFUL) || (status[STATUS_5] != RTEMS_SUCCESSFUL) || | ||||
(status[STATUS_6] != RTEMS_SUCCESSFUL) || (status[STATUS_7] != RTEMS_SUCCESSFUL) || | ||||
(status[STATUS_8] != RTEMS_SUCCESSFUL) || (status[STATUS_9] != RTEMS_SUCCESSFUL) ) | ||||
|
r33 | { | ||
ret = RTEMS_UNSATISFIED; | ||||
|
r32 | } | ||
|
r33 | return ret; | ||
|
r32 | } | ||
|
r238 | int restart_asm_tasks( unsigned char lfrRequestedMode ) | ||
{ | ||||
/** This function is used to restart average spectral matrices 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 | ||||
* | ||||
* ASM tasks are AVF0, PRC0, AVF1, PRC1, AVF2 and PRC2 | ||||
* | ||||
*/ | ||||
|
r318 | rtems_status_code status[NB_ASM_TASKS]; | ||
|
r238 | rtems_status_code ret; | ||
ret = RTEMS_SUCCESSFUL; | ||||
|
r318 | status[STATUS_0] = rtems_task_restart( Task_id[TASKID_AVF0], lfrRequestedMode ); | ||
if (status[STATUS_0] != RTEMS_SUCCESSFUL) | ||||
|
r238 | { | ||
|
r318 | PRINTF1("in restart_science_task *** AVF0 ERR %d\n", status[STATUS_0]) | ||
|
r238 | } | ||
|
r318 | status[STATUS_1] = rtems_task_restart( Task_id[TASKID_PRC0], lfrRequestedMode ); | ||
if (status[STATUS_1] != RTEMS_SUCCESSFUL) | ||||
|
r238 | { | ||
|
r318 | PRINTF1("in restart_science_task *** PRC0 ERR %d\n", status[STATUS_1]) | ||
|
r238 | } | ||
|
r318 | status[STATUS_2] = rtems_task_restart( Task_id[TASKID_AVF1], lfrRequestedMode ); | ||
if (status[STATUS_2] != RTEMS_SUCCESSFUL) | ||||
|
r238 | { | ||
|
r318 | PRINTF1("in restart_science_task *** AVF1 ERR %d\n", status[STATUS_2]) | ||
|
r238 | } | ||
|
r318 | status[STATUS_3] = rtems_task_restart( Task_id[TASKID_PRC1],lfrRequestedMode ); | ||
if (status[STATUS_3] != RTEMS_SUCCESSFUL) | ||||
|
r238 | { | ||
|
r318 | PRINTF1("in restart_science_task *** PRC1 ERR %d\n", status[STATUS_3]) | ||
|
r238 | } | ||
|
r318 | status[STATUS_4] = rtems_task_restart( Task_id[TASKID_AVF2], 1 ); | ||
if (status[STATUS_4] != RTEMS_SUCCESSFUL) | ||||
|
r238 | { | ||
|
r318 | PRINTF1("in restart_science_task *** AVF2 ERR %d\n", status[STATUS_4]) | ||
|
r238 | } | ||
|
r318 | status[STATUS_5] = rtems_task_restart( Task_id[TASKID_PRC2], 1 ); | ||
if (status[STATUS_5] != RTEMS_SUCCESSFUL) | ||||
|
r238 | { | ||
|
r318 | PRINTF1("in restart_science_task *** PRC2 ERR %d\n", status[STATUS_5]) | ||
|
r238 | } | ||
|
r318 | if ( (status[STATUS_0] != RTEMS_SUCCESSFUL) || (status[STATUS_1] != RTEMS_SUCCESSFUL) || | ||
(status[STATUS_2] != RTEMS_SUCCESSFUL) || (status[STATUS_3] != RTEMS_SUCCESSFUL) || | ||||
(status[STATUS_4] != RTEMS_SUCCESSFUL) || (status[STATUS_5] != RTEMS_SUCCESSFUL) ) | ||||
|
r238 | { | ||
ret = RTEMS_UNSATISFIED; | ||||
} | ||||
return ret; | ||||
} | ||||
int suspend_science_tasks( void ) | ||||
|
r32 | { | ||
|
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 | ||||
* | ||||
*/ | ||||
|
r32 | |||
|
r40 | rtems_status_code status; | ||
|
r35 | |||
|
r227 | PRINTF("in suspend_science_tasks\n") | ||
|
r192 | |||
|
r237 | status = rtems_task_suspend( Task_id[TASKID_AVF0] ); // suspend AVF0 | ||
|
r197 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | ||
|
r35 | { | ||
|
r40 | PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status) | ||
|
r35 | } | ||
|
r197 | else | ||
{ | ||||
status = RTEMS_SUCCESSFUL; | ||||
} | ||||
|
r121 | if (status == RTEMS_SUCCESSFUL) // suspend PRC0 | ||
{ | ||||
status = rtems_task_suspend( Task_id[TASKID_PRC0] ); | ||||
|
r197 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | ||
|
r121 | { | ||
PRINTF1("in suspend_science_task *** PRC0 ERR %d\n", status) | ||||
} | ||||
|
r197 | else | ||
{ | ||||
status = RTEMS_SUCCESSFUL; | ||||
} | ||||
|
r121 | } | ||
if (status == RTEMS_SUCCESSFUL) // suspend AVF1 | ||||
{ | ||||
status = rtems_task_suspend( Task_id[TASKID_AVF1] ); | ||||
|
r197 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | ||
|
r121 | { | ||
PRINTF1("in suspend_science_task *** AVF1 ERR %d\n", status) | ||||
} | ||||
|
r197 | else | ||
{ | ||||
status = RTEMS_SUCCESSFUL; | ||||
} | ||||
|
r121 | } | ||
if (status == RTEMS_SUCCESSFUL) // suspend PRC1 | ||||
{ | ||||
status = rtems_task_suspend( Task_id[TASKID_PRC1] ); | ||||
|
r197 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | ||
|
r121 | { | ||
PRINTF1("in suspend_science_task *** PRC1 ERR %d\n", status) | ||||
} | ||||
|
r197 | else | ||
{ | ||||
status = RTEMS_SUCCESSFUL; | ||||
} | ||||
|
r121 | } | ||
|
r126 | if (status == RTEMS_SUCCESSFUL) // suspend AVF2 | ||
{ | ||||
status = rtems_task_suspend( Task_id[TASKID_AVF2] ); | ||||
|
r197 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | ||
|
r126 | { | ||
PRINTF1("in suspend_science_task *** AVF2 ERR %d\n", status) | ||||
} | ||||
|
r197 | else | ||
{ | ||||
status = RTEMS_SUCCESSFUL; | ||||
} | ||||
|
r126 | } | ||
if (status == RTEMS_SUCCESSFUL) // suspend PRC2 | ||||
{ | ||||
status = rtems_task_suspend( Task_id[TASKID_PRC2] ); | ||||
|
r197 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | ||
|
r126 | { | ||
PRINTF1("in suspend_science_task *** PRC2 ERR %d\n", status) | ||||
} | ||||
|
r197 | else | ||
{ | ||||
status = RTEMS_SUCCESSFUL; | ||||
} | ||||
|
r126 | } | ||
|
r40 | if (status == RTEMS_SUCCESSFUL) // suspend WFRM | ||
{ | ||||
status = rtems_task_suspend( Task_id[TASKID_WFRM] ); | ||||
|
r197 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | ||
|
r40 | { | ||
PRINTF1("in suspend_science_task *** WFRM ERR %d\n", status) | ||||
} | ||||
|
r197 | else | ||
{ | ||||
status = RTEMS_SUCCESSFUL; | ||||
} | ||||
|
r35 | } | ||
|
r40 | if (status == RTEMS_SUCCESSFUL) // suspend CWF3 | ||
|
r35 | { | ||
|
r40 | status = rtems_task_suspend( Task_id[TASKID_CWF3] ); | ||
|
r197 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | ||
|
r40 | { | ||
PRINTF1("in suspend_science_task *** CWF3 ERR %d\n", status) | ||||
} | ||||
|
r197 | else | ||
{ | ||||
status = RTEMS_SUCCESSFUL; | ||||
} | ||||
|
r35 | } | ||
|
r40 | if (status == RTEMS_SUCCESSFUL) // suspend CWF2 | ||
|
r35 | { | ||
|
r40 | status = rtems_task_suspend( Task_id[TASKID_CWF2] ); | ||
|
r197 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | ||
|
r40 | { | ||
PRINTF1("in suspend_science_task *** CWF2 ERR %d\n", status) | ||||
} | ||||
|
r197 | else | ||
{ | ||||
status = RTEMS_SUCCESSFUL; | ||||
} | ||||
|
r40 | } | ||
if (status == RTEMS_SUCCESSFUL) // suspend CWF1 | ||||
{ | ||||
status = rtems_task_suspend( Task_id[TASKID_CWF1] ); | ||||
|
r197 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | ||
|
r40 | { | ||
PRINTF1("in suspend_science_task *** CWF1 ERR %d\n", status) | ||||
} | ||||
|
r197 | else | ||
{ | ||||
status = RTEMS_SUCCESSFUL; | ||||
} | ||||
|
r35 | } | ||
|
r40 | return status; | ||
|
r32 | } | ||
|
r238 | int suspend_asm_tasks( void ) | ||
{ | ||||
/** 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 | ||||
* | ||||
*/ | ||||
rtems_status_code status; | ||||
PRINTF("in suspend_science_tasks\n") | ||||
status = rtems_task_suspend( Task_id[TASKID_AVF0] ); // suspend AVF0 | ||||
if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | ||||
{ | ||||
PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status) | ||||
} | ||||
else | ||||
{ | ||||
status = RTEMS_SUCCESSFUL; | ||||
} | ||||
if (status == RTEMS_SUCCESSFUL) // suspend PRC0 | ||||
{ | ||||
status = rtems_task_suspend( Task_id[TASKID_PRC0] ); | ||||
if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | ||||
{ | ||||
PRINTF1("in suspend_science_task *** PRC0 ERR %d\n", status) | ||||
} | ||||
else | ||||
{ | ||||
status = RTEMS_SUCCESSFUL; | ||||
} | ||||
} | ||||
if (status == RTEMS_SUCCESSFUL) // suspend AVF1 | ||||
{ | ||||
status = rtems_task_suspend( Task_id[TASKID_AVF1] ); | ||||
if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | ||||
{ | ||||
PRINTF1("in suspend_science_task *** AVF1 ERR %d\n", status) | ||||
} | ||||
else | ||||
{ | ||||
status = RTEMS_SUCCESSFUL; | ||||
} | ||||
} | ||||
if (status == RTEMS_SUCCESSFUL) // suspend PRC1 | ||||
{ | ||||
status = rtems_task_suspend( Task_id[TASKID_PRC1] ); | ||||
if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | ||||
{ | ||||
PRINTF1("in suspend_science_task *** PRC1 ERR %d\n", status) | ||||
} | ||||
else | ||||
{ | ||||
status = RTEMS_SUCCESSFUL; | ||||
} | ||||
} | ||||
if (status == RTEMS_SUCCESSFUL) // suspend AVF2 | ||||
{ | ||||
status = rtems_task_suspend( Task_id[TASKID_AVF2] ); | ||||
if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | ||||
{ | ||||
PRINTF1("in suspend_science_task *** AVF2 ERR %d\n", status) | ||||
} | ||||
else | ||||
{ | ||||
status = RTEMS_SUCCESSFUL; | ||||
} | ||||
} | ||||
if (status == RTEMS_SUCCESSFUL) // suspend PRC2 | ||||
{ | ||||
status = rtems_task_suspend( Task_id[TASKID_PRC2] ); | ||||
if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | ||||
{ | ||||
PRINTF1("in suspend_science_task *** PRC2 ERR %d\n", status) | ||||
} | ||||
else | ||||
{ | ||||
status = RTEMS_SUCCESSFUL; | ||||
} | ||||
} | ||||
return status; | ||||
} | ||||
|
r111 | void launch_waveform_picker( unsigned char mode, unsigned int transitionCoarseTime ) | ||
|
r90 | { | ||
|
r257 | |||
|
r139 | WFP_reset_current_ring_nodes(); | ||
|
r171 | |||
|
r97 | reset_waveform_picker_regs(); | ||
|
r171 | |||
|
r90 | set_wfp_burst_enable_register( mode ); | ||
|
r106 | |||
|
r90 | LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER ); | ||
LEON_Unmask_interrupt( IRQ_WAVEFORM_PICKER ); | ||||
|
r106 | |||
|
r111 | if (transitionCoarseTime == 0) | ||
{ | ||||
|
r247 | // instant transition means transition on the next valid date | ||
|
r271 | // this is mandatory to have a good snapshot period and a good correction of the snapshot period | ||
|
r247 | waveform_picker_regs->start_date = time_management_regs->coarse_time + 1; | ||
|
r111 | } | ||
else | ||||
{ | ||||
waveform_picker_regs->start_date = transitionCoarseTime; | ||||
} | ||||
|
r166 | |||
|
r257 | update_last_valid_transition_date(waveform_picker_regs->start_date); | ||
|
r95 | } | ||
|
r118 | void launch_spectral_matrix( void ) | ||
|
r95 | { | ||
|
r117 | SM_reset_current_ring_nodes(); | ||
|
r171 | |||
|
r95 | reset_spectral_matrix_regs(); | ||
|
r171 | |||
|
r124 | reset_nb_sm(); | ||
|
r99 | |||
|
r171 | set_sm_irq_onNewMatrix( 1 ); | ||
|
r103 | LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); | ||
LEON_Unmask_interrupt( IRQ_SPECTRAL_MATRIX ); | ||||
|
r171 | |||
|
r103 | } | ||
|
r171 | void set_sm_irq_onNewMatrix( unsigned char value ) | ||
|
r103 | { | ||
|
r106 | if (value == 1) | ||
{ | ||||
|
r318 | spectral_matrix_regs->config = spectral_matrix_regs->config | BIT_IRQ_ON_NEW_MATRIX; | ||
|
r106 | } | ||
else | ||||
{ | ||||
|
r318 | spectral_matrix_regs->config = spectral_matrix_regs->config & MASK_IRQ_ON_NEW_MATRIX; // 1110 | ||
|
r106 | } | ||
|
r103 | } | ||
|
r171 | void set_sm_irq_onError( unsigned char value ) | ||
|
r103 | { | ||
|
r106 | if (value == 1) | ||
{ | ||||
|
r318 | spectral_matrix_regs->config = spectral_matrix_regs->config | BIT_IRQ_ON_ERROR; | ||
|
r106 | } | ||
else | ||||
{ | ||||
|
r318 | spectral_matrix_regs->config = spectral_matrix_regs->config & MASK_IRQ_ON_ERROR; // 1101 | ||
|
r106 | } | ||
|
r103 | } | ||
|
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; | ||||
} | ||||
|
r318 | void setCalibrationData( void ) | ||
{ | ||||
/** This function is used to store the values used to drive the DAC in order to generate the SCM calibration signal | ||||
* | ||||
* @param void | ||||
* | ||||
* @return void | ||||
* | ||||
*/ | ||||
|
r187 | unsigned int k; | ||
unsigned short data; | ||||
float val; | ||||
float Ts; | ||||
|
r318 | time_management_regs->calDataPtr = INIT_CHAR; | ||
|
r187 | |||
|
r322 | Ts = 1 / CAL_FS; | ||
|
r187 | // build the signal for the SCM calibration | ||
|
r318 | for (k = 0; k < CAL_NB_PTS; k++) | ||
|
r187 | { | ||
|
r339 | val = CAL_A0 * sin( CAL_W0 * k * Ts ) | ||
+ CAL_A1 * sin( CAL_W1 * k * Ts ); | ||||
|
r318 | data = (unsigned short) ((val * CAL_SCALE_FACTOR) + CONST_2048); | ||
time_management_regs->calData = data & CAL_DATA_MASK; | ||||
|
r187 | } | ||
} | ||||
|
r318 | void setCalibrationDataInterleaved( void ) | ||
{ | ||||
/** This function is used to store the values used to drive the DAC in order to generate the SCM calibration signal | ||||
* | ||||
* @param void | ||||
* | ||||
* @return void | ||||
* | ||||
* In interleaved mode, one can store more values than in normal mode. | ||||
* The data are stored in bunch of 18 bits, 12 bits from one sample and 6 bits from another sample. | ||||
* T store 3 values, one need two write operations. | ||||
* s1 [ b11 b10 b9 b8 b7 b6 ] s0 [ b11 b10 b9 b8 b7 b6 b5 b3 b2 b1 b0 ] | ||||
* s1 [ b5 b4 b3 b2 b1 b0 ] s2 [ b11 b10 b9 b8 b7 b6 b5 b3 b2 b1 b0 ] | ||||
* | ||||
*/ | ||||
|
r187 | unsigned int k; | ||
float val; | ||||
float Ts; | ||||
|
r318 | unsigned short data[CAL_NB_PTS_INTER]; | ||
|
r187 | unsigned char *dataPtr; | ||
|
r322 | Ts = 1 / CAL_FS_INTER; | ||
|
r187 | |||
|
r318 | time_management_regs->calDataPtr = INIT_CHAR; | ||
|
r187 | |||
// build the signal for the SCM calibration | ||||
|
r318 | for (k=0; k<CAL_NB_PTS_INTER; k++) | ||
|
r187 | { | ||
|
r318 | val = sin( 2 * pi * CAL_F0 * k * Ts ) | ||
+ sin( 2 * pi * CAL_F1 * k * Ts ); | ||||
data[k] = (unsigned short) ((val * CONST_512) + CONST_2048); | ||||
|
r187 | } | ||
// write the signal in interleaved mode | ||||
|
r318 | for (k=0; k < STEPS_FOR_STORAGE_INTER; k++) | ||
|
r187 | { | ||
|
r318 | dataPtr = (unsigned char*) &data[ (k * BYTES_FOR_2_SAMPLES) + 2 ]; | ||
time_management_regs->calData = ( data[ k * BYTES_FOR_2_SAMPLES ] & CAL_DATA_MASK ) | ||||
+ ( (dataPtr[0] & CAL_DATA_MASK_INTER) << CAL_DATA_SHIFT_INTER); | ||||
time_management_regs->calData = ( data[(k * BYTES_FOR_2_SAMPLES) + 1] & CAL_DATA_MASK ) | ||||
+ ( (dataPtr[1] & CAL_DATA_MASK_INTER) << CAL_DATA_SHIFT_INTER); | ||||
|
r187 | } | ||
} | ||||
void setCalibrationReload( bool state) | ||||
{ | ||||
if (state == true) | ||||
{ | ||||
|
r318 | time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | BIT_CAL_RELOAD; // [0001 0000] | ||
|
r187 | } | ||
else | ||||
{ | ||||
|
r318 | time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & MASK_CAL_RELOAD; // [1110 1111] | ||
|
r187 | } | ||
} | ||||
void setCalibrationEnable( bool state ) | ||||
{ | ||||
// this bit drives the multiplexer | ||||
if (state == true) | ||||
{ | ||||
|
r318 | time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | BIT_CAL_ENABLE; // [0100 0000] | ||
|
r187 | } | ||
else | ||||
{ | ||||
|
r318 | time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & MASK_CAL_ENABLE; // [1011 1111] | ||
|
r187 | } | ||
} | ||||
void setCalibrationInterleaved( bool state ) | ||||
{ | ||||
// this bit drives the multiplexer | ||||
if (state == true) | ||||
{ | ||||
|
r318 | time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | BIT_SET_INTERLEAVED; // [0010 0000] | ||
|
r187 | } | ||
else | ||||
{ | ||||
|
r318 | time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & MASK_SET_INTERLEAVED; // [1101 1111] | ||
|
r187 | } | ||
} | ||||
|
r206 | void setCalibration( bool state ) | ||
|
r187 | { | ||
|
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 ); | ||||
} | ||||
|
r187 | } | ||
void configureCalibration( bool interleaved ) | ||||
{ | ||||
|
r206 | setCalibration( false ); | ||
|
r187 | if ( interleaved == true ) | ||
{ | ||||
setCalibrationInterleaved( true ); | ||||
|
r318 | setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000 | ||
setCalibrationDivisor( CAL_F_DIVISOR_INTER ); // => 240 384 | ||||
|
r187 | setCalibrationDataInterleaved(); | ||
} | ||||
else | ||||
{ | ||||
|
r318 | setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000 | ||
setCalibrationDivisor( CAL_F_DIVISOR ); // => 160 256 (39 - 1) | ||||
|
r187 | setCalibrationData(); | ||
} | ||||
} | ||||
|
r23 | //**************** | ||
// CLOSING ACTIONS | ||||
|
r107 | void update_last_TC_exe( ccsdsTelecommandPacket_t *TC, unsigned char * time ) | ||
|
r21 | { | ||
|
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 | ||||
* | ||||
*/ | ||||
|
r107 | unsigned int val; | ||
|
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]; | ||||
|
r318 | housekeeping_packet.hk_lfr_last_exe_tc_type[0] = INIT_CHAR; | ||
|
r23 | housekeeping_packet.hk_lfr_last_exe_tc_type[1] = TC->serviceType; | ||
|
r318 | housekeeping_packet.hk_lfr_last_exe_tc_subtype[0] = INIT_CHAR; | ||
|
r23 | housekeeping_packet.hk_lfr_last_exe_tc_subtype[1] = TC->serviceSubType; | ||
|
r318 | housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_0] = time[BYTE_0]; | ||
housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_1] = time[BYTE_1]; | ||||
housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_2] = time[BYTE_2]; | ||||
housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_3] = time[BYTE_3]; | ||||
housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_4] = time[BYTE_4]; | ||||
housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_5] = time[BYTE_5]; | ||||
|
r107 | |||
|
r318 | val = (housekeeping_packet.hk_lfr_exe_tc_cnt[0] * CONST_256) + housekeeping_packet.hk_lfr_exe_tc_cnt[1]; | ||
|
r107 | val++; | ||
|
r318 | housekeeping_packet.hk_lfr_exe_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE); | ||
|
r107 | housekeeping_packet.hk_lfr_exe_tc_cnt[1] = (unsigned char) (val); | ||
|
r21 | } | ||
|
r107 | void update_last_TC_rej(ccsdsTelecommandPacket_t *TC, unsigned char * time ) | ||
|
r21 | { | ||
|
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 | ||||
* | ||||
*/ | ||||
|
r107 | unsigned int val; | ||
|
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]; | ||||
|
r318 | housekeeping_packet.hk_lfr_last_rej_tc_type[0] = INIT_CHAR; | ||
|
r23 | housekeeping_packet.hk_lfr_last_rej_tc_type[1] = TC->serviceType; | ||
|
r318 | housekeeping_packet.hk_lfr_last_rej_tc_subtype[0] = INIT_CHAR; | ||
|
r23 | housekeeping_packet.hk_lfr_last_rej_tc_subtype[1] = TC->serviceSubType; | ||
|
r318 | housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_0] = time[BYTE_0]; | ||
housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_1] = time[BYTE_1]; | ||||
housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_2] = time[BYTE_2]; | ||||
housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_3] = time[BYTE_3]; | ||||
housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_4] = time[BYTE_4]; | ||||
housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_5] = time[BYTE_5]; | ||||
|
r107 | |||
|
r318 | val = (housekeeping_packet.hk_lfr_rej_tc_cnt[0] * CONST_256) + housekeeping_packet.hk_lfr_rej_tc_cnt[1]; | ||
|
r107 | val++; | ||
|
r318 | housekeeping_packet.hk_lfr_rej_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE); | ||
|
r107 | housekeeping_packet.hk_lfr_rej_tc_cnt[1] = (unsigned char) (val); | ||
|
r21 | } | ||
|
r104 | void close_action(ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id ) | ||
|
r21 | { | ||
|
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 | ||||
* | ||||
*/ | ||||
|
r109 | unsigned char requestedMode; | ||
|
r21 | if (result == LFR_SUCCESSFUL) | ||
{ | ||||
|
r107 | if ( !( (TC->serviceType==TC_TYPE_TIME) & (TC->serviceSubType==TC_SUBTYPE_UPDT_TIME) ) | ||
& | ||||
!( (TC->serviceType==TC_TYPE_GEN) & (TC->serviceSubType==TC_SUBTYPE_UPDT_INFO)) | ||||
|
r46 | ) | ||
|
r33 | { | ||
|
r104 | send_tm_lfr_tc_exe_success( TC, queue_id ); | ||
|
r33 | } | ||
|
r109 | if ( (TC->serviceType == TC_TYPE_GEN) & (TC->serviceSubType == TC_SUBTYPE_ENTER) ) | ||
{ | ||||
//********************************** | ||||
// UPDATE THE LFRMODE LOCAL VARIABLE | ||||
requestedMode = TC->dataAndCRC[1]; | ||||
|
r254 | updateLFRCurrentMode( requestedMode ); | ||
|
r109 | } | ||
|
r21 | } | ||
|
r115 | else if (result == LFR_EXE_ERROR) | ||
|
r112 | { | ||
send_tm_lfr_tc_exe_error( TC, queue_id ); | ||||
} | ||||
|
r21 | } | ||
|
r12 | //*************************** | ||
// Interrupt Service Routines | ||||
rtems_isr commutation_isr1( rtems_vector_number vector ) | ||||
{ | ||||
|
r18 | if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) { | ||
|
r227 | PRINTF("In commutation_isr1 *** Error sending event to DUMB\n") | ||
|
r18 | } | ||
|
r12 | } | ||
|
r9 | |||
|
r12 | rtems_isr commutation_isr2( rtems_vector_number vector ) | ||
{ | ||||
|
r18 | if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) { | ||
|
r227 | PRINTF("In commutation_isr2 *** Error sending event to DUMB\n") | ||
|
r18 | } | ||
|
r12 | } | ||
|
r45 | //**************** | ||
// OTHER FUNCTIONS | ||||
|
r254 | void updateLFRCurrentMode( unsigned char requestedMode ) | ||
|
r45 | { | ||
/** 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. | ||||
* | ||||
*/ | ||||
|
r254 | |||
|
r45 | // update the local value of lfrCurrentMode with the value contained in the housekeeping_packet structure | ||
|
r318 | housekeeping_packet.lfr_status_word[0] = (housekeeping_packet.lfr_status_word[0] & STATUS_WORD_LFR_MODE_MASK) | ||
+ (unsigned char) ( requestedMode << STATUS_WORD_LFR_MODE_SHIFT ); | ||||
|
r254 | lfrCurrentMode = requestedMode; | ||
|
r45 | } | ||
|
r12 | |||
|
r171 | void set_lfr_soft_reset( unsigned char value ) | ||
{ | ||||
if (value == 1) | ||||
{ | ||||
|
r318 | time_management_regs->ctrl = time_management_regs->ctrl | BIT_SOFT_RESET; // [0100] | ||
|
r171 | } | ||
else | ||||
{ | ||||
|
r318 | time_management_regs->ctrl = time_management_regs->ctrl & MASK_SOFT_RESET; // [1011] | ||
|
r171 | } | ||
} | ||||
void reset_lfr( void ) | ||||
{ | ||||
set_lfr_soft_reset( 1 ); | ||||
set_lfr_soft_reset( 0 ); | ||||
|
r212 | |||
set_hk_lfr_sc_potential_flag( true ); | ||||
|
r171 | } | ||