diff --git a/FSW-qt/Makefile b/FSW-qt/Makefile --- a/FSW-qt/Makefile +++ b/FSW-qt/Makefile @@ -1,6 +1,6 @@ ############################################################################# # Makefile for building: bin/fsw -# Generated by qmake (2.01a) (Qt 4.8.5) on: Tue Mar 11 15:58:37 2014 +# Generated by qmake (2.01a) (Qt 4.8.5) on: Tue Mar 25 09:47:02 2014 # Project: fsw-qt.pro # Template: app # Command: /usr/bin/qmake-qt4 -spec /usr/lib64/qt4/mkspecs/linux-g++ -o Makefile fsw-qt.pro @@ -10,7 +10,7 @@ CC = sparc-rtems-gcc CXX = sparc-rtems-g++ -DEFINES = -DSW_VERSION_N1=1 -DSW_VERSION_N2=0 -DSW_VERSION_N3=0 -DSW_VERSION_N4=3 -DPRINT_MESSAGES_ON_CONSOLE -DDEBUG_MESSAGES +DEFINES = -DSW_VERSION_N1=1 -DSW_VERSION_N2=0 -DSW_VERSION_N3=0 -DSW_VERSION_N4=3 -DVHDL_DEV -DPRINT_MESSAGES_ON_CONSOLE CFLAGS = -pipe -O3 -Wall $(DEFINES) CXXFLAGS = -pipe -O3 -Wall $(DEFINES) INCPATH = -I/usr/lib64/qt4/mkspecs/linux-g++ -I. -I../src -I../header -I../../LFR_basic-parameters diff --git a/FSW-qt/bin/LEON3_RELOAD_SPW.py b/FSW-qt/bin/LEON3_RELOAD_SPW.py --- a/FSW-qt/bin/LEON3_RELOAD_SPW.py +++ b/FSW-qt/bin/LEON3_RELOAD_SPW.py @@ -1,5 +1,8 @@ #!/usr/bin/lppmon -e +RMAPPlugin0.setValueSpaceWireLinkNumber( 1 ) +RMAPPlugin0.setValueTargetLogicalAddress( 254 ) + dsu3plugin0.openFile("/opt/DEV_PLE/FSW-qt/bin/fsw") dsu3plugin0.loadFile() dsu3plugin0.run() diff --git a/FSW-qt/fsw-qt.pro b/FSW-qt/fsw-qt.pro --- a/FSW-qt/fsw-qt.pro +++ b/FSW-qt/fsw-qt.pro @@ -1,7 +1,7 @@ TEMPLATE = app # CONFIG += console v8 sim -# CONFIG options = verbose *** boot_messages *** debug_messages *** cpu_usage_report *** stack_report *** vhdl_dev -CONFIG += console verbose debug_messages +# CONFIG options = verbose *** boot_messages *** debug_messages *** cpu_usage_report *** stack_report *** vhdl_dev *** debug_tch +CONFIG += console verbose vhdl_dev CONFIG -= qt include(./sparc.pri) @@ -13,6 +13,10 @@ DEFINES += SW_VERSION_N2=0 # minor DEFINES += SW_VERSION_N3=0 # patch DEFINES += SW_VERSION_N4=3 # internal +contains( CONFIG, debug_tch ) { + DEFINES += DEBUG_TCH +} + contains( CONFIG, vhdl_dev ) { DEFINES += VHDL_DEV } diff --git a/FSW-qt/fsw-qt.pro.user b/FSW-qt/fsw-qt.pro.user --- a/FSW-qt/fsw-qt.pro.user +++ b/FSW-qt/fsw-qt.pro.user @@ -1,6 +1,6 @@ - + ProjectExplorer.Project.ActiveTarget diff --git a/TimeGenerator-qt/header/timegen_init.h b/TimeGenerator-qt/header/timegen_init.h new file mode 100644 --- /dev/null +++ b/TimeGenerator-qt/header/timegen_init.h @@ -0,0 +1,41 @@ +#ifndef TIMEGEN_INIT_H_INCLUDED +#define TIMEGEN_INIT_H_INCLUDED + +#include +#include + +#include "fsw_params.h" +#include "fsw_misc.h" +#include "fsw_processing.h" +#include "wf_handler.h" + +#include "timegen_spacewire.h" +#include "timegen_misc.h" + +extern rtems_name Task_name[20]; /* array of task names */ +extern rtems_id Task_id[20]; /* array of task ids */ + +// RTEMS TASKS +rtems_task Init( rtems_task_argument argument); + +// OTHER functions +void create_names( void ); +int create_all_tasks( void ); +int start_all_tasks( void ); +// +rtems_status_code create_message_queues( void ); +rtems_status_code get_message_queue_id_send( rtems_id *queue_id ); +rtems_status_code get_message_queue_id_recv( rtems_id *queue_id ); +// +int start_recv_send_tasks( void ); +// +void init_local_mode_parameters( void ); +void reset_local_time( void ); + +extern int rtems_cpu_usage_report( void ); +extern int rtems_cpu_usage_reset( void ); +extern void rtems_stack_checker_report_usage( void ); + +extern int sched_yield( void ); + +#endif // TIMEGEN_INIT_H_INCLUDED diff --git a/TimeGenerator-qt/header/timegen_misc.h b/TimeGenerator-qt/header/timegen_misc.h new file mode 100644 --- /dev/null +++ b/TimeGenerator-qt/header/timegen_misc.h @@ -0,0 +1,39 @@ +#ifndef TIMEGEN_MISC_H_INCLUDED +#define TIMEGEN_MISC_H_INCLUDED + +#include +#include + +#include "fsw_params.h" +#include "TC_types.h" +#include "tc_acceptance.h" +#include "timegen_init.h" + +#define TASK_PRIORITY_UPDT 40 + +typedef struct { + unsigned char targetLogicalAddress; + unsigned char protocolIdentifier; + unsigned char reserved; + unsigned char userApplication; + // PACKET HEADER + Packet_TC_LFR_UPDATE_TIME_t update_time; +} Packet_TC_LFR_UPDATE_TIME_WITH_OVERHEAD_t; + +unsigned int coarseTime; + +rtems_name rtems_name_updt; +rtems_id rtems_id_updt; + +void timegen_timecode_irq_handler( void *pDev, void *regs, int minor, unsigned int tc ); + +void initCoarseTime( void ); + +rtems_task updt_task( rtems_task_argument unused ); + +int send_tc_lfr_update_time( rtems_id queue_id ); + +#endif // TIMEGEN_MISC_H_INCLUDED + + + diff --git a/TimeGenerator-qt/header/timegen_spacewire.h b/TimeGenerator-qt/header/timegen_spacewire.h new file mode 100644 --- /dev/null +++ b/TimeGenerator-qt/header/timegen_spacewire.h @@ -0,0 +1,48 @@ +#ifndef TIMEGEN_SPACEWIRE_H_INCLUDED +#define TIMEGEN_SPACEWIRE_H_INCLUDED + +#include +#include + +#include // for O_RDWR +#include // for the read call +#include // for the ioctl call +#include + +#include "fsw_params.h" +#include "tc_acceptance.h" +#include "timegen_tc_handler.h" + +#define DESTINATION_ID_LFR 0xfe +#define DESTINATION_ID_DPU 0x01 +#define SPACEWIRE_LINK_LFR 0x01 +#define NODEADDR_TIMEGEN 0xfd + +extern rtems_id Task_id[20]; /* array of task ids */ +extern int fdSPW; + +extern spw_stats spacewire_stats; +extern spw_stats spacewire_stats_backup; + +// RTEMS TASK +rtems_task spiq_task( rtems_task_argument argument ); +rtems_task recv_task( rtems_task_argument unused ); +rtems_task send_task( rtems_task_argument argument ); +rtems_task wtdg_task( rtems_task_argument argument ); + +int spacewire_open_link( void ); +int spacewire_start_link( int fd ); +int spacewire_stop_start_link( int fd ); +int spacewire_configure_link(int fd ); +int spacewire_reset_link( void ); +void spacewire_set_NP( unsigned char val, unsigned int regAddr ); // No Port force +void spacewire_set_RE( unsigned char val, unsigned int regAddr ); // RMAP Enable +void spacewire_compute_stats_offsets( void ); +void spacewire_update_statistics( void ); + +void timecode_irq_handler( void *pDev, void *regs, int minor, unsigned int tc ); +rtems_timer_service_routine user_routine( rtems_id timer_id, void *user_data ); + +void (*grspw_timecode_callback) ( void *pDev, void *regs, int minor, unsigned int tc ); + +#endif // TIMEGEN_SPACEWIRE_H_INCLUDED diff --git a/TimeGenerator-qt/header/timegen_tc_handler.h b/TimeGenerator-qt/header/timegen_tc_handler.h new file mode 100644 --- /dev/null +++ b/TimeGenerator-qt/header/timegen_tc_handler.h @@ -0,0 +1,56 @@ +#ifndef TIMEGEN_TC_HANDLER_H_INCLUDED +#define TIMEGEN_TC_HANDLER_H_INCLUDED + +#include +#include + +#include "tc_load_dump_parameters.h" +#include "tc_acceptance.h" +#include "tm_lfr_tc_exe.h" + +// MODE PARAMETERS +extern unsigned int maxCount; + +//**** +// ISR +rtems_isr commutation_isr1( rtems_vector_number vector ); +rtems_isr commutation_isr2( rtems_vector_number vector ); + +//*********** +// RTEMS TASK +rtems_task actn_task( rtems_task_argument unused ); + +//*********** +// TC ACTIONS +int action_reset(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time); +int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time); +int action_update_info(ccsdsTelecommandPacket_t *TC, rtems_id queue_id); +int action_enable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time); +int action_disable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time); +int action_update_time(ccsdsTelecommandPacket_t *TC); + +// mode transition +int transition_validation(unsigned char requestedMode); +int stop_current_mode( void ); +int enter_mode(unsigned char mode); +int restart_science_tasks(); +int suspend_science_tasks(); +void launch_waveform_picker( unsigned char mode ); +void launch_spectral_matrix( unsigned char mode ); +void set_irq_on_new_ready_matrix(unsigned char value ); +void set_run_matrix_spectral( unsigned char value ); +void launch_spectral_matrix_simu( unsigned char mode ); + +// other functions +void updateLFRCurrentMode(); +void update_last_TC_exe(ccsdsTelecommandPacket_t *TC ); +void update_last_TC_rej(ccsdsTelecommandPacket_t *TC ); +void close_action(ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id ); + +extern rtems_status_code get_message_queue_id_send( rtems_id *queue_id ); +extern rtems_status_code get_message_queue_id_recv( rtems_id *queue_id ); + +#endif // TIMEGEN_TC_HANDLER_H_INCLUDED + + + diff --git a/TimeGenerator-qt/src/timegen_init.c b/TimeGenerator-qt/src/timegen_init.c new file mode 100644 --- /dev/null +++ b/TimeGenerator-qt/src/timegen_init.c @@ -0,0 +1,476 @@ +/** This is the RTEMS initialization module. + * + * @file + * @author P. LEROY + * + * This module contains two very different information: + * - specific instructions to configure the compilation of the RTEMS executive + * - functions related to the fligth softwre initialization, especially the INIT RTEMS task + * + */ + +//************************* +// GPL reminder to be added +//************************* + +#include + +/* configuration information */ + +#define CONFIGURE_INIT + +#include /* for device driver prototypes */ + +/* configuration information */ + +#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER +#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER + +#define CONFIGURE_MAXIMUM_TASKS 20 +#define CONFIGURE_RTEMS_INIT_TASKS_TABLE +#define CONFIGURE_EXTRA_TASK_STACKS (3 * RTEMS_MINIMUM_STACK_SIZE) +#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 32 +#define CONFIGURE_INIT_TASK_PRIORITY 1 // instead of 100 +#define CONFIGURE_INIT_TASK_MODE (RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT) +#define CONFIGURE_MAXIMUM_DRIVERS 16 +#define CONFIGURE_MAXIMUM_PERIODS 5 +#define CONFIGURE_MAXIMUM_TIMERS 5 // STAT (1s), send SWF (0.3s), send CWF3 (1s) +#define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 2 +#ifdef PRINT_STACK_REPORT + #define CONFIGURE_STACK_CHECKER_ENABLED +#endif + +#include + +/* If --drvmgr was enabled during the configuration of the RTEMS kernel */ +#ifdef RTEMS_DRVMGR_STARTUP + #ifdef LEON3 + /* Add Timer and UART Driver */ + #ifdef CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER + #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GPTIMER + #endif + #ifdef CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER + #define CONFIGURE_DRIVER_AMBAPP_GAISLER_APBUART + #endif + #endif + #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GRSPW /* GRSPW Driver */ + #include +#endif + +#include "timegen_init.h" +#include "fsw_config.c" + +rtems_task Init( rtems_task_argument ignored ) +{ + /** This is the RTEMS INIT taks, it the first task launched by the system. + * + * @param unused is the starting argument of the RTEMS task + * + * The INIT task create and run all other RTEMS tasks. + * + */ + + rtems_status_code status; + rtems_status_code status_spw; + +// initCoarseTime(); + + // UART settings + send_console_outputs_on_apbuart_port(); + set_apbuart_scaler_reload_register(REGS_ADDR_APBUART, APBUART_SCALER_RELOAD_VALUE); + enable_apbuart_transmitter(); + DEBUG_PRINTF("\n\n\n\n\nIn INIT *** Now the console is on port COM1\n") + + PRINTF("\n\n\n\n\n") + PRINTF("*************************\n") + PRINTF("** Time Generator **\n") + PRINTF1("** %d.", SW_VERSION_N1) + PRINTF1("%d.", SW_VERSION_N2) + PRINTF1("%d.", SW_VERSION_N3) + PRINTF1("%d **\n", SW_VERSION_N4) + PRINTF("*************************\n") + PRINTF("\n\n") + +// init_local_mode_parameters(); +// init_housekeeping_parameters(); + +// updateLFRCurrentMode(); + +// BOOT_PRINTF1("in INIT *** lfrCurrentMode is %d\n", lfrCurrentMode) + + create_names(); // create all names + + status = create_message_queues(); // create message queues + if (status != RTEMS_SUCCESSFUL) + { + PRINTF1("in INIT *** ERR in create_message_queues, code %d", status) + } + + status = create_all_tasks(); // create all tasks + if (status != RTEMS_SUCCESSFUL) + { + PRINTF1("in INIT *** ERR in create_all_tasks, code %d", status) + } + + // ************************** + // + grspw_timecode_callback = &timegen_timecode_irq_handler; + + status_spw = spacewire_open_link(); // (1) open the link + if ( status_spw != RTEMS_SUCCESSFUL ) + { + PRINTF1("in INIT *** ERR spacewire_open_link code %d\n", status_spw ) + } + + if ( status_spw == RTEMS_SUCCESSFUL ) // (2) configure the link + { + status_spw = spacewire_configure_link( fdSPW ); + if ( status_spw != RTEMS_SUCCESSFUL ) + { + PRINTF1("in INIT *** ERR spacewire_configure_link code %d\n", status_spw ) + } + } + + if ( status_spw == RTEMS_SUCCESSFUL) // (3) start the link + { + status_spw = spacewire_start_link( fdSPW ); + if ( status_spw != RTEMS_SUCCESSFUL ) + { + PRINTF1("in INIT *** ERR spacewire_start_link code %d\n", status_spw ) + } + } + // + // *************************** + + status = start_all_tasks(); // start all tasks + if (status != RTEMS_SUCCESSFUL) + { + PRINTF1("in INIT *** ERR in start_all_tasks, code %d", status) + } + + // start RECV and SEND *AFTER* SpaceWire Initialization, due to the timeout of the start call during the initialization + status = start_recv_send_tasks(); + if ( status != RTEMS_SUCCESSFUL ) + { + PRINTF1("in INIT *** ERR start_recv_send_tasks code %d\n", status ) + } + + // suspend science tasks. they will be restarted later depending on the mode + status = suspend_science_tasks(); // suspend science tasks (not done in stop_current_mode if current mode = STANDBY) + if (status != RTEMS_SUCCESSFUL) + { + PRINTF1("in INIT *** in suspend_science_tasks *** ERR code: %d\n", status) + } + + // if the spacewire link is not up then send an event to the SPIQ task for link recovery + if ( status_spw != RTEMS_SUCCESSFUL ) + { + status = rtems_event_send( Task_id[TASKID_SPIQ], SPW_LINKERR_EVENT ); + if ( status != RTEMS_SUCCESSFUL ) { + PRINTF1("in INIT *** ERR rtems_event_send to SPIQ code %d\n", status ) + } + } + + BOOT_PRINTF("delete INIT\n") + + status = rtems_task_delete(RTEMS_SELF); + +} + +void init_local_mode_parameters( void ) +{ + /** This function initialize the param_local global variable with default values. + * + */ + + unsigned int i; + + // LOCAL PARAMETERS +// set_local_nb_interrupt_f0_MAX(); + + BOOT_PRINTF1("local_sbm1_nb_cwf_max %d \n", param_local.local_sbm1_nb_cwf_max) + BOOT_PRINTF1("local_sbm2_nb_cwf_max %d \n", param_local.local_sbm2_nb_cwf_max) + BOOT_PRINTF1("nb_interrupt_f0_MAX = %d\n", param_local.local_nb_interrupt_f0_MAX) + + // init sequence counters + + for(i = 0; i + +void timegen_timecode_irq_handler( void *pDev, void *regs, int minor, unsigned int tc ) +{ + struct grgpio_regs_str *grgpio_regs = (struct grgpio_regs_str *) REGS_ADDR_GRGPIO; + + grgpio_regs->io_port_direction_register = + grgpio_regs->io_port_direction_register | 0x08; // [0001 1000], 0 = output disabled, 1 = output enabled + + if ( (grgpio_regs->io_port_output_register & 0x08) == 0x08 ) + { + grgpio_regs->io_port_output_register = grgpio_regs->io_port_output_register & 0xf7; + } + else + { + grgpio_regs->io_port_output_register = grgpio_regs->io_port_output_register | 0x08; + } + + rtems_event_send( rtems_id_updt, RTEMS_EVENT_0 ); +} + +void initCoarseTime() +{ + coarseTime = 0x00; +} + +rtems_task updt_task( rtems_task_argument unused ) +{ + rtems_event_set event_out; + rtems_id send_queue_id; + + get_message_queue_id_send( &send_queue_id ); + + BOOT_PRINTF("in UPDT *** waiting for SpaceWire ticks\n") + + while(1) + { + // wait for an RTEMS_EVENT + rtems_event_receive( RTEMS_EVENT_0, + RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); + // increment the coarse time + coarseTime = coarseTime + 1; + PRINTF2("next valid coarseTime = 0x%x *** %d s\n", coarseTime, coarseTime) + rtems_task_wake_after(70); // 10 ms * 70 = 700 ms + send_tc_lfr_update_time( send_queue_id ); + } +} + +int send_tc_lfr_update_time(rtems_id queue_id ) +{ + + rtems_status_code status; + unsigned char messageSize; + + Packet_TC_LFR_UPDATE_TIME_WITH_OVERHEAD_t packet; + unsigned char crcAsTwoBytes[2]; + + // OVERHEAD + packet.targetLogicalAddress = DESTINATION_ID_LFR; + packet.protocolIdentifier = CCSDS_PROTOCOLE_ID; + packet.reserved = DEFAULT_RESERVED; + packet.userApplication = CCSDS_USER_APP; + + // TIME PACKET + packet.update_time.packetID[0] = (unsigned char) (TC_LFR_PACKET_ID >> 8); + packet.update_time.packetID[1] = (unsigned char) (TC_LFR_PACKET_ID ); + packet.update_time.packetSequenceControl[0] = (unsigned char) (TC_LFR_PACKET_SEQUENCE_CONTROL >> 8); + packet.update_time.packetSequenceControl[1] = (unsigned char) (TC_LFR_PACKET_SEQUENCE_CONTROL ); + packet.update_time.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_LFR_UPDATE_TIME >> 8); + packet.update_time.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_LFR_UPDATE_TIME ); + + packet.update_time.ccsdsSecHeaderFlag_pusVersion_ack = 0x19; + packet.update_time.serviceType = TC_TYPE_LFR_UPDATE_TIME; + packet.update_time.serviceSubType = TC_SUBTYPE_UPDATE_TIME; + packet.update_time.sourceID = SID_TC_RPW_INTERNAL; + packet.update_time.cp_rpw_time[0] = (unsigned char) (coarseTime >> 24); + packet.update_time.cp_rpw_time[1] = (unsigned char) (coarseTime >> 16); + packet.update_time.cp_rpw_time[2] = (unsigned char) (coarseTime >> 8); + packet.update_time.cp_rpw_time[3] = (unsigned char) (coarseTime); + packet.update_time.cp_rpw_time[4] = 0; // fine time MSB + packet.update_time.cp_rpw_time[5] = 0; // fine time LSB + + GetCRCAsTwoBytes((unsigned char*) &packet.update_time, crcAsTwoBytes, + PACKET_LENGTH_TC_LFR_UPDATE_TIME + CCSDS_TC_TM_PACKET_OFFSET - 2); + packet.update_time.crc[0] = crcAsTwoBytes[0]; + packet.update_time.crc[1] = crcAsTwoBytes[1]; + + messageSize = PACKET_LENGTH_TC_LFR_UPDATE_TIME + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES; + + // SEND DATA + status = rtems_message_queue_send( queue_id, &packet, messageSize); + if (status != RTEMS_SUCCESSFUL) { + PRINTF("in send_tm_lfr_tc_exe_success *** ERR\n") + } + + return status; +} diff --git a/TimeGenerator-qt/src/timegen_spacewire.c b/TimeGenerator-qt/src/timegen_spacewire.c new file mode 100644 --- /dev/null +++ b/TimeGenerator-qt/src/timegen_spacewire.c @@ -0,0 +1,601 @@ +/** Functions related to the SpaceWire interface. + * + * @file + * @author P. LEROY + * + * A group of functions to handle SpaceWire transmissions: + * - configuration of the SpaceWire link + * - SpaceWire related interruption requests processing + * - transmission of TeleMetry packets by a dedicated RTEMS task + * - reception of TeleCommands by a dedicated RTEMS task + * + */ + +#include "timegen_spacewire.h" + +rtems_name semq_name; +rtems_id semq_id; + +//*********** +// RTEMS TASK +rtems_task spiq_task(rtems_task_argument unused) +{ + /** This RTEMS task is awaken by an rtems_event sent by the interruption subroutine of the SpaceWire driver. + * + * @param unused is the starting argument of the RTEMS task + * + */ + + rtems_event_set event_out; + rtems_status_code status; + int linkStatus; + + BOOT_PRINTF("in SPIQ *** \n") + + while(true){ + rtems_event_receive(SPW_LINKERR_EVENT, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an SPW_LINKERR_EVENT + PRINTF("in SPIQ *** got SPW_LINKERR_EVENT\n") + + // [0] SUSPEND RECV AND SEND TASKS + status = rtems_task_suspend( Task_id[ TASKID_RECV ] ); + if ( status != RTEMS_SUCCESSFUL ) { + PRINTF("in SPIQ *** ERR suspending RECV Task\n") + } + status = rtems_task_suspend( Task_id[ TASKID_SEND ] ); + if ( status != RTEMS_SUCCESSFUL ) { + PRINTF("in SPIQ *** ERR suspending SEND Task\n") + } + + // [1] CHECK THE LINK + status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (1) + if ( linkStatus != 5) { + PRINTF1("in SPIQ *** linkStatus %d, wait...\n", linkStatus) + status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms + } + + // [2] RECHECK THE LINK AFTER SY_LFR_DPU_CONNECT_TIMEOUT + status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (2) + if ( linkStatus != 5 ) // [2.a] not in run state, reset the link + { + spacewire_compute_stats_offsets(); + status = spacewire_reset_link( ); + } + else // [2.b] in run state, start the link + { + status = spacewire_stop_start_link( fdSPW ); // start the link + if ( status != RTEMS_SUCCESSFUL) + { + PRINTF1("in SPIQ *** ERR spacewire_start_link %d\n", status) + } + } + + // [3] COMPLETE RECOVERY ACTION AFTER SY_LFR_DPU_CONNECT_ATTEMPTS + if ( status == RTEMS_SUCCESSFUL ) // [3.a] the link is in run state and has been started successfully + { + status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 ); + if ( status != RTEMS_SUCCESSFUL ) { + PRINTF("in SPIQ *** ERR resuming SEND Task\n") + } + status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 ); + if ( status != RTEMS_SUCCESSFUL ) { + PRINTF("in SPIQ *** ERR resuming RECV Task\n") + } + } + else // [3.b] the link is not in run state, go in STANDBY mode + { + status = stop_current_mode(); + if ( status != RTEMS_SUCCESSFUL ) { + PRINTF1("in SPIQ *** ERR stop_current_mode *** code %d\n", status) + } + status = enter_mode( LFR_MODE_STANDBY ); + if ( status != RTEMS_SUCCESSFUL ) { + PRINTF1("in SPIQ *** ERR enter_standby_mode *** code %d\n", status) + } + // wake the WTDG task up to wait for the link recovery + status = rtems_event_send ( Task_id[TASKID_WTDG], RTEMS_EVENT_0 ); + status = rtems_task_suspend( RTEMS_SELF ); + } + } +} + +rtems_task recv_task( rtems_task_argument unused ) +{ + /** This RTEMS task is dedicated to the reception of incoming TeleCommands. + * + * @param unused is the starting argument of the RTEMS task + * + * The RECV task blocks on a call to the read system call, waiting for incoming SpaceWire data. When unblocked: + * 1. It reads the incoming data. + * 2. Launches the acceptance procedure. + * 3. If the Telecommand is valid, sends it to a dedicated RTEMS message queue. + * + */ + + int len; + ccsdsTelecommandPacket_t currentTC; + unsigned char computed_CRC[ 2 ]; + unsigned char currentTC_LEN_RCV[ 2 ]; + unsigned char destinationID; + unsigned int currentTC_LEN_RCV_AsUnsignedInt; + unsigned int parserCode; + unsigned char time[6]; + rtems_status_code status; + rtems_id queue_recv_id; + rtems_id queue_send_id; + + initLookUpTableForCRC(); // the table is used to compute Cyclic Redundancy Codes + + status = get_message_queue_id_recv( &queue_recv_id ); + if (status != RTEMS_SUCCESSFUL) + { + PRINTF1("in RECV *** ERR get_message_queue_id_recv %d\n", status) + } + + status = get_message_queue_id_send( &queue_send_id ); + if (status != RTEMS_SUCCESSFUL) + { + PRINTF1("in RECV *** ERR get_message_queue_id_send %d\n", status) + } + + BOOT_PRINTF("in RECV *** \n") + + while(1) + { + len = read( fdSPW, (char*) ¤tTC, CCSDS_TC_PKT_MAX_SIZE ); // the call to read is blocking + if (len == -1){ // error during the read call + PRINTF1("in RECV *** last read call returned -1, ERRNO %d\n", errno) + } + else { + if ( (len+1) < CCSDS_TC_PKT_MIN_SIZE ) { + PRINTF("in RECV *** packet lenght too short\n") + } + else { + currentTC_LEN_RCV_AsUnsignedInt = (unsigned int) (len - CCSDS_TC_TM_PACKET_OFFSET - 3); // => -3 is for Prot ID, Reserved and User App bytes + currentTC_LEN_RCV[ 0 ] = (unsigned char) (currentTC_LEN_RCV_AsUnsignedInt >> 8); + currentTC_LEN_RCV[ 1 ] = (unsigned char) (currentTC_LEN_RCV_AsUnsignedInt ); + // CHECK THE TC + parserCode = tc_parser( ¤tTC, currentTC_LEN_RCV_AsUnsignedInt, computed_CRC ) ; + if ( (parserCode == ILLEGAL_APID) || (parserCode == WRONG_LEN_PKT) + || (parserCode == INCOR_CHECKSUM) || (parserCode == ILL_TYPE) + || (parserCode == ILL_SUBTYPE) || (parserCode == WRONG_APP_DATA) + || (parserCode == WRONG_SRC_ID) ) + { // send TM_LFR_TC_EXE_CORRUPTED + if ( !( (currentTC.serviceType==TC_TYPE_TIME) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_TIME) ) + && + !( (currentTC.serviceType==TC_TYPE_GEN) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_INFO)) + ) + { + if ( parserCode == WRONG_SRC_ID ) + { + destinationID = SID_TC_GROUND; + } + else + { + destinationID = currentTC.sourceID; + } + getTime( time ); + close_action( ¤tTC, LFR_DEFAULT, queue_send_id ); + send_tm_lfr_tc_exe_corrupted( ¤tTC, queue_send_id, + computed_CRC, currentTC_LEN_RCV, + destinationID ); + } + } + else + { // send valid TC to the action launcher + status = rtems_message_queue_send( queue_recv_id, ¤tTC, + currentTC_LEN_RCV_AsUnsignedInt + CCSDS_TC_TM_PACKET_OFFSET + 3); + } + } + } + } +} + +rtems_task send_task( rtems_task_argument argument) +{ + /** This RTEMS task is dedicated to the transmission of TeleMetry packets. + * + * @param unused is the starting argument of the RTEMS task + * + * The SEND task waits for a message to become available in the dedicated RTEMS queue. When a message arrives: + * - if the first byte is equal to CCSDS_DESTINATION_ID, the message is sent as is using the write system call. + * - if the first byte is not equal to CCSDS_DESTINATION_ID, the message is handled as a spw_ioctl_pkt_send. After + * analyzis, the packet is sent either using the write system call or using the ioctl call SPACEWIRE_IOCTRL_SEND, depending on the + * data it contains. + * + */ + + rtems_status_code status; // RTEMS status code + char incomingData[ACTION_MSG_PKTS_MAX_SIZE]; // incoming data buffer + size_t size; // size of the incoming TC packet + u_int32_t count; + rtems_id queue_id; + + status = get_message_queue_id_send( &queue_id ); + if (status != RTEMS_SUCCESSFUL) + { + PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status) + } + + BOOT_PRINTF("in SEND *** \n") + + while(1) + { + status = rtems_message_queue_receive( queue_id, incomingData, &size, + RTEMS_WAIT, RTEMS_NO_TIMEOUT ); + + if (status!=RTEMS_SUCCESSFUL) + { + PRINTF1("in SEND *** (1) ERR = %d\n", status) + } + else + { + status = write( fdSPW, incomingData, size ); + if (status == -1){ + PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size) + } + } + + status = rtems_message_queue_get_number_pending( queue_id, &count ); + if (status != RTEMS_SUCCESSFUL) + { + PRINTF1("in SEND *** (3) ERR = %d\n", status) + } + else + { + if (count > maxCount) + { + maxCount = count; + } + } + } +} + +rtems_task wtdg_task( rtems_task_argument argument ) +{ + rtems_event_set event_out; + rtems_status_code status; + int linkStatus; + + BOOT_PRINTF("in WTDG ***\n") + + while(1) + { + // wait for an RTEMS_EVENT + rtems_event_receive( RTEMS_EVENT_0, + RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); + PRINTF("in WTDG *** wait for the link\n") + status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status + while( linkStatus != 5) // wait for the link + { + rtems_task_wake_after( 10 ); + status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status + } + + status = spacewire_stop_start_link( fdSPW ); + + if (status != RTEMS_SUCCESSFUL) + { + PRINTF1("in WTDG *** ERR link not started %d\n", status) + } + else + { + PRINTF("in WTDG *** OK link started\n") + } + + // restart the SPIQ task + status = rtems_task_restart( Task_id[TASKID_SPIQ], 1 ); + if ( status != RTEMS_SUCCESSFUL ) { + PRINTF("in SPIQ *** ERR restarting SPIQ Task\n") + } + + // restart RECV and SEND + status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 ); + if ( status != RTEMS_SUCCESSFUL ) { + PRINTF("in SPIQ *** ERR restarting SEND Task\n") + } + status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 ); + if ( status != RTEMS_SUCCESSFUL ) { + PRINTF("in SPIQ *** ERR restarting RECV Task\n") + } + } +} + +//**************** +// OTHER FUNCTIONS +int spacewire_open_link( void ) +{ + /** This function opens the SpaceWire link. + * + * @return a valid file descriptor in case of success, -1 in case of a failure + * + */ + rtems_status_code status; + + fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call resets the hardware + if ( fdSPW < 0 ) { + PRINTF1("ERR *** in configure_spw_link *** error opening "GRSPW_DEVICE_NAME" with ERR %d\n", errno) + } + else + { + status = RTEMS_SUCCESSFUL; + } + + return status; +} + +int spacewire_start_link( int fd ) +{ + rtems_status_code status; + + status = ioctl( fdSPW, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started + // -1 default hardcoded driver timeout + + return status; +} + +int spacewire_stop_start_link( int fd ) +{ + rtems_status_code status; + + status = ioctl( fdSPW, SPACEWIRE_IOCTRL_STOP); // start fails if link pDev->running != 0 + status = ioctl( fdSPW, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started + // -1 default hardcoded driver timeout + + return status; +} + +int spacewire_configure_link( int fd ) +{ + /** This function configures the SpaceWire link. + * + * @return GR-RTEMS-DRIVER directive status codes: + * - 22 EINVAL - Null pointer or an out of range value was given as the argument. + * - 16 EBUSY - Only used for SEND. Returned when no descriptors are avialble in non-blocking mode. + * - 88 ENOSYS - Returned for SET_DESTKEY if RMAP command handler is not available or if a non-implemented call is used. + * - 116 ETIMEDOUT - REturned for SET_PACKET_SIZE and START if the link could not be brought up. + * - 12 ENOMEM - Returned for SET_PACKETSIZE if it was unable to allocate the new buffers. + * - 5 EIO - Error when writing to grswp hardware registers. + * - 2 ENOENT - No such file or directory + */ + + rtems_status_code status; + + spacewire_set_NP(1, REGS_ADDR_GRSPW); // [N]o [P]ort force + spacewire_set_RE(1, REGS_ADDR_GRSPW); // [R]MAP [E]nable, the dedicated call seems to break the no port force configuration + + status = ioctl(fd, SPACEWIRE_IOCTRL_SET_RXBLOCK, 1); // sets the blocking mode for reception + if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_RXBLOCK\n") + // + status = ioctl(fd, SPACEWIRE_IOCTRL_SET_EVENT_ID, Task_id[TASKID_SPIQ]); // sets the task ID to which an event is sent when a + if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_EVENT_ID\n") // link-error interrupt occurs + // + status = ioctl(fd, SPACEWIRE_IOCTRL_SET_DISABLE_ERR, 0); // automatic link-disabling due to link-error interrupts + if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_DISABLE_ERR\n") + // + status = ioctl(fd, SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ, 1); // sets the link-error interrupt bit + if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n") + // + status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK, 0); // transmission blocks + if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK\n") + // + status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL, 1); // transmission blocks when no transmission descriptor is available + if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL\n") + // + status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TCODE_CTRL, 0x0909); // [Time Rx : Time Tx : Link error : Tick-out IRQ] + if (status!=RTEMS_SUCCESSFUL) PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TCODE_CTRL\n") + + return status; +} + +int spacewire_reset_link( void ) +{ + /** This function is executed by the SPIQ rtems_task wehn it has been awaken by an interruption raised by the SpaceWire driver. + * + * @return RTEMS directive status code: + * - RTEMS_UNSATISFIED is returned is the link is not in the running state after 10 s. + * - RTEMS_SUCCESSFUL is returned if the link is up before the timeout. + * + */ + + rtems_status_code status_spw; + int i; + + for ( i=0; i> 8); + housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[1] = (unsigned char) (spacewire_stats.packets_received); + housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[0] = (unsigned char) (spacewire_stats.packets_sent >> 8); + housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[1] = (unsigned char) (spacewire_stats.packets_sent); + //housekeeping_packet.hk_lfr_dpu_spw_tick_out_cnt; + //housekeeping_packet.hk_lfr_dpu_spw_last_timc; + + //****************************************** + // ERROR COUNTERS / SPACEWIRE / LOW SEVERITY + housekeeping_packet.hk_lfr_dpu_spw_parity = (unsigned char) spacewire_stats.parity_err; + housekeeping_packet.hk_lfr_dpu_spw_disconnect = (unsigned char) spacewire_stats.disconnect_err; + housekeeping_packet.hk_lfr_dpu_spw_escape = (unsigned char) spacewire_stats.escape_err; + housekeeping_packet.hk_lfr_dpu_spw_credit = (unsigned char) spacewire_stats.credit_err; + housekeeping_packet.hk_lfr_dpu_spw_write_sync = (unsigned char) spacewire_stats.write_sync_err; + + //********************************************* + // ERROR COUNTERS / SPACEWIRE / MEDIUM SEVERITY + housekeeping_packet.hk_lfr_dpu_spw_early_eop = (unsigned char) spacewire_stats.early_ep; + housekeeping_packet.hk_lfr_dpu_spw_invalid_addr = (unsigned char) spacewire_stats.invalid_address; + housekeeping_packet.hk_lfr_dpu_spw_eep = (unsigned char) spacewire_stats.rx_eep_err; + housekeeping_packet.hk_lfr_dpu_spw_rx_too_big = (unsigned char) spacewire_stats.rx_truncated; +} + +void timecode_irq_handler( void *pDev, void *regs, int minor, unsigned int tc ) +{ +// rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_1 ); + struct grgpio_regs_str *grgpio_regs = (struct grgpio_regs_str *) REGS_ADDR_GRGPIO; + + grgpio_regs->io_port_direction_register = + grgpio_regs->io_port_direction_register | 0x08; // [0001 1000], 0 = output disabled, 1 = output enabled + + if ( (grgpio_regs->io_port_output_register & 0x08) == 0x08 ) + { + grgpio_regs->io_port_output_register = grgpio_regs->io_port_output_register & 0xf7; + } + else + { + grgpio_regs->io_port_output_register = grgpio_regs->io_port_output_register | 0x08; + } + +} + +rtems_timer_service_routine user_routine( rtems_id timer_id, void *user_data ) +{ + int linkStatus; + rtems_status_code status; + + status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status + + if ( linkStatus == 5) { + PRINTF("in spacewire_reset_link *** link is running\n") + status = RTEMS_SUCCESSFUL; + } +} diff --git a/TimeGenerator-qt/src/timegen_tc_handler.c b/TimeGenerator-qt/src/timegen_tc_handler.c new file mode 100644 --- /dev/null +++ b/TimeGenerator-qt/src/timegen_tc_handler.c @@ -0,0 +1,793 @@ +/** 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 "timegen_tc_handler.h" + +//*********** +// RTEMS TASK + +rtems_task actn_task( rtems_task_argument unused ) +{ + /** 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. + * + */ + + 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 + unsigned char time[6]; + rtems_id queue_rcv_id; + rtems_id queue_snd_id; + + status = get_message_queue_id_recv( &queue_rcv_id ); + if (status != RTEMS_SUCCESSFUL) + { + PRINTF1("in ACTN *** ERR get_message_queue_id_recv %d\n", status) + } + + status = get_message_queue_id_send( &queue_snd_id ); + if (status != RTEMS_SUCCESSFUL) + { + PRINTF1("in ACTN *** ERR get_message_queue_id_send %d\n", status) + } + + result = LFR_SUCCESSFUL; + subtype = 0; // subtype of the current TC packet + + BOOT_PRINTF("in ACTN *** \n") + + while(1) + { + status = rtems_message_queue_receive( queue_rcv_id, (char*) &TC, &size, + RTEMS_WAIT, RTEMS_NO_TIMEOUT); + getTime( time ); // set time to the current time + if (status!=RTEMS_SUCCESSFUL) + { + PRINTF1("ERR *** in task ACTN *** error receiving a message, code %d \n", status) + } + else + { + subtype = TC.serviceSubType; + switch(subtype) + { + 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, time ); + 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_UPDT_TIME: + result = action_update_time( &TC ); + close_action( &TC, result, queue_snd_id ); + break; + // + default: + break; + } + } + } +} + +//*********** +// TC ACTIONS + +int action_reset(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) +{ + /** 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 + * + */ + + send_tm_lfr_tc_exe_not_implemented( TC, queue_id, time ); + return LFR_DEFAULT; +} + +int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) +{ + /** 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 + * + */ + + rtems_status_code status; + unsigned char requestedMode; + + requestedMode = TC->dataAndCRC[1]; + + if ( (requestedMode != LFR_MODE_STANDBY) + && (requestedMode != LFR_MODE_NORMAL) && (requestedMode != LFR_MODE_BURST) + && (requestedMode != LFR_MODE_SBM1) && (requestedMode != LFR_MODE_SBM2) ) + { + status = RTEMS_UNSATISFIED; + send_tm_lfr_tc_exe_inconsistent( TC, queue_id, BYTE_POS_CP_LFR_MODE, requestedMode ); + } + else + { + printf("in action_enter_mode *** enter mode %d\n", requestedMode); + + status = transition_validation(requestedMode); + + if ( status == LFR_SUCCESSFUL ) { + if ( lfrCurrentMode != LFR_MODE_STANDBY) + { + status = stop_current_mode(); + } + if (status != RTEMS_SUCCESSFUL) + { + PRINTF("ERR *** in action_enter *** stop_current_mode\n") + } + status = enter_mode( requestedMode ); + } + else + { + PRINTF("ERR *** in action_enter *** transition rejected\n") + send_tm_lfr_tc_exe_not_executable( TC, queue_id ); + } + } + + return status; +} + +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 +// * +// * @return LFR directive status code: +// * - LFR_DEFAULT +// * - LFR_SUCCESSFUL +// * +// */ + +// unsigned int val; + int result; + + result = LFR_DEFAULT; +// unsigned int status; +// unsigned char mode; + +// // check LFR MODE +// mode = (TC->dataAndCRC[ BYTE_POS_HK_UPDATE_INFO_PAR_SET5 ] & 0x1e) >> 1; +// status = check_update_info_hk_lfr_mode( mode ); +// if (status != LFR_DEFAULT) // check TDS mode +// { +// mode = (TC->dataAndCRC[ BYTE_POS_HK_UPDATE_INFO_PAR_SET6 ] & 0xf0) >> 4; +// status = check_update_info_hk_tds_mode( mode ); +// } +// if (status != LFR_DEFAULT) // check THR mode +// { +// mode = (TC->dataAndCRC[ BYTE_POS_HK_UPDATE_INFO_PAR_SET6 ] & 0x0f); +// status = check_update_info_hk_thr_mode( mode ); +// } +// if (status != LFR_DEFAULT) // if the parameter check is successful +// { +// 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; + + return result; +} + +int action_enable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) +{ + /** 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 + * + */ + + int result; + unsigned char lfrMode; + + result = LFR_DEFAULT; + lfrMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4; + + send_tm_lfr_tc_exe_not_implemented( TC, queue_id, time ); + result = LFR_DEFAULT; + + return result; +} + +int action_disable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) +{ + /** 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 + * + */ + + int result; + unsigned char lfrMode; + + result = LFR_DEFAULT; + lfrMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4; + + send_tm_lfr_tc_exe_not_implemented( TC, queue_id, time ); + result = LFR_DEFAULT; + + return result; +} + +int action_update_time(ccsdsTelecommandPacket_t *TC) +{ + /** 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 + * + * @return LFR_SUCCESSFUL + * + */ + + unsigned int val; + + time_management_regs->coarse_time_load = (TC->dataAndCRC[0] << 24) + + (TC->dataAndCRC[1] << 16) + + (TC->dataAndCRC[2] << 8) + + TC->dataAndCRC[3]; + 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); +// time_management_regs->ctrl = time_management_regs->ctrl | 1; // force tick + + return LFR_SUCCESSFUL; +} + +//******************* +// ENTERING THE MODES + +int transition_validation(unsigned char requestedMode) +{ + /** 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 + * + */ + + int status; + + switch (requestedMode) + { + case LFR_MODE_STANDBY: + if ( lfrCurrentMode == LFR_MODE_STANDBY ) { + status = LFR_DEFAULT; + } + else + { + status = LFR_SUCCESSFUL; + } + break; + case LFR_MODE_NORMAL: + if ( lfrCurrentMode == LFR_MODE_NORMAL ) { + status = LFR_DEFAULT; + } + else { + status = LFR_SUCCESSFUL; + } + break; + case LFR_MODE_BURST: + if ( lfrCurrentMode == LFR_MODE_BURST ) { + status = LFR_DEFAULT; + } + else { + status = LFR_SUCCESSFUL; + } + break; + case LFR_MODE_SBM1: + if ( lfrCurrentMode == LFR_MODE_SBM1 ) { + status = LFR_DEFAULT; + } + else { + status = LFR_SUCCESSFUL; + } + break; + case LFR_MODE_SBM2: + if ( lfrCurrentMode == LFR_MODE_SBM2 ) { + status = LFR_DEFAULT; + } + else { + status = LFR_SUCCESSFUL; + } + break; + default: + status = LFR_DEFAULT; + break; + } + + return status; +} + +int stop_current_mode(void) +{ + /** 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 + * + */ + + rtems_status_code status; + + status = RTEMS_SUCCESSFUL; + + // (1) mask interruptions + LEON_Mask_interrupt( IRQ_WAVEFORM_PICKER ); // mask waveform picker interrupt + LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt + + // (2) clear interruptions + LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER ); // clear waveform picker interrupt + LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt + + // (3) reset registers + // waveform picker +// reset_wfp_burst_enable(); // reset burst and enable bits +// reset_wfp_status(); // reset all the status bits + // spectral matrices + set_irq_on_new_ready_matrix( 0 ); // stop the spectral matrices + set_run_matrix_spectral( 0 ); // run_matrix_spectral is set to 0 +// reset_extractSWF(); // reset the extractSWF flag to false + + // + 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 + // + + // suspend several tasks + if (lfrCurrentMode != LFR_MODE_STANDBY) { + status = suspend_science_tasks(); + } + + if (status != RTEMS_SUCCESSFUL) + { + PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status) + } + + return status; +} + +int enter_mode(unsigned char mode ) +{ + /** 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 + * + */ + + rtems_status_code status; + + status = RTEMS_UNSATISFIED; + + housekeeping_packet.lfr_status_word[0] = (unsigned char) ((mode << 4) + 0x0d); + updateLFRCurrentMode(); + + if ( (mode == LFR_MODE_NORMAL) || (mode == LFR_MODE_BURST) + || (mode == LFR_MODE_SBM1) || (mode == LFR_MODE_SBM2) ) + { +#ifdef PRINT_TASK_STATISTICS + rtems_cpu_usage_reset(); + maxCount = 0; +#endif + status = restart_science_tasks(); +// launch_waveform_picker( mode ); +// launch_spectral_matrix( mode ); + } + else if ( mode == LFR_MODE_STANDBY ) + { +#ifdef PRINT_TASK_STATISTICS + rtems_cpu_usage_report(); +#endif + +#ifdef PRINT_STACK_REPORT + rtems_stack_checker_report_usage(); +#endif + status = stop_current_mode(); + PRINTF1("maxCount = %d\n", maxCount) + } + else + { + status = RTEMS_UNSATISFIED; + } + + if (status != RTEMS_SUCCESSFUL) + { + PRINTF1("in enter_mode *** ERR = %d\n", status) + status = RTEMS_UNSATISFIED; + } + + return status; +} + +int restart_science_tasks() +{ + /** 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 + * + * Science tasks are AVF0, BPF0, WFRM, CWF3, CW2, CWF1 + * + */ + + rtems_status_code status[6]; + rtems_status_code ret; + + ret = RTEMS_SUCCESSFUL; + + status[0] = rtems_task_restart( Task_id[TASKID_AVF0], 1 ); + if (status[0] != RTEMS_SUCCESSFUL) + { + PRINTF1("in restart_science_task *** 0 ERR %d\n", status[0]) + } + + status[2] = rtems_task_restart( Task_id[TASKID_WFRM],1 ); + if (status[2] != RTEMS_SUCCESSFUL) + { + PRINTF1("in restart_science_task *** 2 ERR %d\n", status[2]) + } + + status[3] = rtems_task_restart( Task_id[TASKID_CWF3],1 ); + if (status[3] != RTEMS_SUCCESSFUL) + { + PRINTF1("in restart_science_task *** 3 ERR %d\n", status[3]) + } + + status[4] = rtems_task_restart( Task_id[TASKID_CWF2],1 ); + if (status[4] != RTEMS_SUCCESSFUL) + { + PRINTF1("in restart_science_task *** 4 ERR %d\n", status[4]) + } + + status[5] = rtems_task_restart( Task_id[TASKID_CWF1],1 ); + if (status[5] != RTEMS_SUCCESSFUL) + { + PRINTF1("in restart_science_task *** 5 ERR %d\n", status[5]) + } + + if ( (status[0] != RTEMS_SUCCESSFUL) || (status[2] != RTEMS_SUCCESSFUL) || + (status[3] != RTEMS_SUCCESSFUL) || (status[4] != RTEMS_SUCCESSFUL) || (status[5] != RTEMS_SUCCESSFUL) ) + { + ret = RTEMS_UNSATISFIED; + } + + return ret; +} + +int suspend_science_tasks() +{ + /** 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; + + status = rtems_task_suspend( Task_id[TASKID_AVF0] ); + if (status != RTEMS_SUCCESSFUL) + { + PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status) + } + + if (status == RTEMS_SUCCESSFUL) // suspend WFRM + { + status = rtems_task_suspend( Task_id[TASKID_WFRM] ); + if (status != RTEMS_SUCCESSFUL) + { + PRINTF1("in suspend_science_task *** WFRM ERR %d\n", status) + } + } + + if (status == RTEMS_SUCCESSFUL) // suspend CWF3 + { + status = rtems_task_suspend( Task_id[TASKID_CWF3] ); + if (status != RTEMS_SUCCESSFUL) + { + PRINTF1("in suspend_science_task *** CWF3 ERR %d\n", status) + } + } + + if (status == RTEMS_SUCCESSFUL) // suspend CWF2 + { + status = rtems_task_suspend( Task_id[TASKID_CWF2] ); + if (status != RTEMS_SUCCESSFUL) + { + PRINTF1("in suspend_science_task *** CWF2 ERR %d\n", status) + } + } + + if (status == RTEMS_SUCCESSFUL) // suspend CWF1 + { + status = rtems_task_suspend( Task_id[TASKID_CWF1] ); + if (status != RTEMS_SUCCESSFUL) + { + PRINTF1("in suspend_science_task *** CWF1 ERR %d\n", status) + } + } + + return status; +} + +void launch_waveform_picker( unsigned char mode ) +{ +// int startDate; + +// reset_current_ring_nodes(); +// reset_waveform_picker_regs(); +// set_wfp_burst_enable_register( mode ); + +// LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER ); +// LEON_Unmask_interrupt( IRQ_WAVEFORM_PICKER ); + +// startDate = time_management_regs->coarse_time + 2; +// waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | 0x80; // [1000 0000] +// waveform_picker_regs->start_date = startDate; +} + +void launch_spectral_matrix( unsigned char mode ) +{ +// reset_nb_sm_f0(); +// reset_current_sm_ring_nodes(); +// reset_spectral_matrix_regs(); + +//#ifdef VHDL_DEV +// set_irq_on_new_ready_matrix( 1 ); +// LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); +// LEON_Unmask_interrupt( IRQ_SPECTRAL_MATRIX ); +// set_run_matrix_spectral( 1 ); +//#else +// // 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 ); +//#endif +} + +void set_irq_on_new_ready_matrix( unsigned char value ) +{ + if (value == 1) + { + spectral_matrix_regs->config = spectral_matrix_regs->config | 0x01; + } + else + { + spectral_matrix_regs->config = spectral_matrix_regs->config & 0xfffffffe; // 1110 + } +} + +void set_run_matrix_spectral( unsigned char value ) +{ + if (value == 1) + { + spectral_matrix_regs->config = spectral_matrix_regs->config | 0x4; // 0100 set run_matrix spectral to 1 + } + else + { + spectral_matrix_regs->config = spectral_matrix_regs->config & 0xfffffffb; // 1011 set run_matrix spectral to 0 + } +} + +void launch_spectral_matrix_simu( unsigned char mode ) +{ +// reset_nb_sm_f0(); +// reset_current_sm_ring_nodes(); +// reset_spectral_matrix_regs(); + +// // 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 ); +// set_local_nb_interrupt_f0_MAX(); +} + +//**************** +// CLOSING ACTIONS +void update_last_TC_exe(ccsdsTelecommandPacket_t *TC) +{ + /** 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 + * + */ + + 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; + housekeeping_packet.hk_lfr_last_exe_tc_type[1] = TC->serviceType; + housekeeping_packet.hk_lfr_last_exe_tc_subtype[0] = 0x00; + housekeeping_packet.hk_lfr_last_exe_tc_subtype[1] = TC->serviceSubType; + housekeeping_packet.hk_lfr_last_exe_tc_time[0] = (unsigned char) (time_management_regs->coarse_time>>24); + housekeeping_packet.hk_lfr_last_exe_tc_time[1] = (unsigned char) (time_management_regs->coarse_time>>16); + housekeeping_packet.hk_lfr_last_exe_tc_time[2] = (unsigned char) (time_management_regs->coarse_time>>8); + housekeeping_packet.hk_lfr_last_exe_tc_time[3] = (unsigned char) (time_management_regs->coarse_time); + housekeeping_packet.hk_lfr_last_exe_tc_time[4] = (unsigned char) (time_management_regs->fine_time>>8); + housekeeping_packet.hk_lfr_last_exe_tc_time[5] = (unsigned char) (time_management_regs->fine_time); +} + +void update_last_TC_rej(ccsdsTelecommandPacket_t *TC ) +{ + /** 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 + * + */ + + 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; + housekeeping_packet.hk_lfr_last_rej_tc_type[1] = TC->serviceType; + housekeeping_packet.hk_lfr_last_rej_tc_subtype[0] = 0x00; + housekeeping_packet.hk_lfr_last_rej_tc_subtype[1] = TC->serviceSubType; + housekeeping_packet.hk_lfr_last_rej_tc_time[0] = (unsigned char) (time_management_regs->coarse_time>>24); + housekeeping_packet.hk_lfr_last_rej_tc_time[1] = (unsigned char) (time_management_regs->coarse_time>>16); + housekeeping_packet.hk_lfr_last_rej_tc_time[2] = (unsigned char) (time_management_regs->coarse_time>>8); + housekeeping_packet.hk_lfr_last_rej_tc_time[3] = (unsigned char) (time_management_regs->coarse_time); + housekeeping_packet.hk_lfr_last_rej_tc_time[4] = (unsigned char) (time_management_regs->fine_time>>8); + housekeeping_packet.hk_lfr_last_rej_tc_time[5] = (unsigned char) (time_management_regs->fine_time); +} + +void close_action(ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id ) +{ + /** 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 + * + */ + + unsigned int val = 0; + + if (result == LFR_SUCCESSFUL) + { + if ( !( (TC->serviceType==TC_TYPE_TIME) && (TC->serviceSubType==TC_SUBTYPE_UPDT_TIME) ) + && + !( (TC->serviceType==TC_TYPE_GEN) && (TC->serviceSubType==TC_SUBTYPE_UPDT_INFO)) + ) + { + send_tm_lfr_tc_exe_success( TC, queue_id ); + } + update_last_TC_exe( TC ); + 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); + } + else + { + update_last_TC_rej( TC ); + 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); + } +} + +//*************************** +// Interrupt Service Routines +rtems_isr commutation_isr1( rtems_vector_number vector ) +{ + if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) { + printf("In commutation_isr1 *** Error sending event to DUMB\n"); + } +} + +rtems_isr commutation_isr2( rtems_vector_number vector ) +{ + if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) { + printf("In commutation_isr2 *** Error sending event to DUMB\n"); + } +} + +//**************** +// 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; +} + diff --git a/header/ccsds_types.h b/header/ccsds_types.h --- a/header/ccsds_types.h +++ b/header/ccsds_types.h @@ -31,6 +31,7 @@ #define TM_PACKET_CAT_HK 4 #define TM_PACKET_CAT_PARAMETER_DUMP 9 #define TM_PACKET_CAT_SCIENCE 12 +#define TC_PACKET_CAT 12 // PACKET SEQUENCE CONTROL #define TM_PACKET_SEQ_CTRL_CONTINUATION 0x00 // [0000 0000] diff --git a/header/fsw_params.h b/header/fsw_params.h --- a/header/fsw_params.h +++ b/header/fsw_params.h @@ -104,6 +104,7 @@ typedef struct ring_node #define REGS_ADDR_GPTIMER 0x80000300 #define REGS_ADDR_GRSPW 0x80000500 #define REGS_ADDR_TIME_MANAGEMENT 0x80000600 +#define REGS_ADDR_GRGPIO 0x80000b00 #ifdef VHDL_DEV #define REGS_ADDR_SPECTRAL_MATRIX 0x80000f00 diff --git a/header/fsw_params_processing.h b/header/fsw_params_processing.h --- a/header/fsw_params_processing.h +++ b/header/fsw_params_processing.h @@ -4,6 +4,9 @@ #define NB_BINS_PER_SM 128 #define NB_VALUES_PER_SM 25 #define TOTAL_SIZE_SM 3200 // 25 * 128 +#define TOTAL_SIZE_BP1_F0 99 // 11 * 9 = 99 +#define TOTAL_SIZE_BP1_F1 117 // 13 * 9 = 117 +#define TOTAL_SIZE_BP1_F2 108 // 12 * 9 = 108 // #define NB_RING_NODES_ASM_F0 12 // AT LEAST 3 #define NB_RING_NODES_ASM_F1 2 // AT LEAST 3 diff --git a/header/fsw_processing.h b/header/fsw_processing.h --- a/header/fsw_processing.h +++ b/header/fsw_processing.h @@ -10,7 +10,6 @@ #include "fsw_params.h" #include "fsw_spacewire.h" -#include "basic_parameters.h" extern volatile int sm_f0[ ]; extern volatile int sm_f1[ ]; diff --git a/header/grlib_regs.h b/header/grlib_regs.h --- a/header/grlib_regs.h +++ b/header/grlib_regs.h @@ -11,11 +11,16 @@ struct apbuart_regs_str{ volatile unsigned int fifoDebug; }; -struct ahbuart_regs_str{ - volatile unsigned int unused; - volatile unsigned int status; - volatile unsigned int ctrl; - volatile unsigned int scaler; +struct grgpio_regs_str{ + volatile int io_port_data_register; + int io_port_output_register; + int io_port_direction_register; + int interrupt_mak_register; + int interrupt_polarity_register; + int interrupt_edge_register; + int bypass_register; + int reserved; + // 0x20-0x3c interrupt map register(s) }; typedef struct { diff --git a/header/tc_handler.h b/header/tc_handler.h --- a/header/tc_handler.h +++ b/header/tc_handler.h @@ -45,9 +45,9 @@ void launch_spectral_matrix_simu( unsign // other functions void updateLFRCurrentMode(); -void update_last_TC_exe(ccsdsTelecommandPacket_t *TC ); -void update_last_TC_rej(ccsdsTelecommandPacket_t *TC ); -void close_action(ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id ); +void update_last_TC_exe( ccsdsTelecommandPacket_t *TC , unsigned char *time ); +void update_last_TC_rej(ccsdsTelecommandPacket_t *TC , unsigned char *time ); +void close_action( ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id ); extern rtems_status_code get_message_queue_id_send( rtems_id *queue_id ); extern rtems_status_code get_message_queue_id_recv( rtems_id *queue_id ); diff --git a/src/fsw_processing.c b/src/fsw_processing.c --- a/src/fsw_processing.c +++ b/src/fsw_processing.c @@ -24,9 +24,13 @@ ring_node *current_ring_node_sm_f2; BP1_t data_BP1[ NB_BINS_COMPRESSED_SM_F0 ]; float averaged_sm_f0 [ TIME_OFFSET + TOTAL_SIZE_SM ]; float averaged_sm_f0_reorganized[ TIME_OFFSET + TOTAL_SIZE_SM ]; -char averaged_sm_f0_char [ TIME_OFFSET_IN_BYTES + TOTAL_SIZE_SM * 2 ]; +char averaged_sm_f0_char [ TIME_OFFSET_IN_BYTES + TOTAL_SIZE_SM ]; float compressed_sm_f0 [ TOTAL_SIZE_COMPRESSED_ASM_F0 ]; +unsigned char LFR_BP1_F0[ TIME_OFFSET_IN_BYTES + TOTAL_SIZE_BP1_F0 * 2 ]; +unsigned char LFR_BP1_F1[ TIME_OFFSET_IN_BYTES + TOTAL_SIZE_BP1_F1 ]; +unsigned char LFR_BP1_F2[ TIME_OFFSET_IN_BYTES + TOTAL_SIZE_BP1_F2 ]; + unsigned int nb_sm_f0; void init_sm_rings( void ) @@ -258,7 +262,7 @@ rtems_task matr_task(rtems_task_argument // 1) compress the matrix for Basic Parameters calculation ASM_compress( averaged_sm_f0, 0, compressed_sm_f0 ); // 2) - //BP1_set(compressed_sm_f0, NB_BINS_COMPRESSED_SM_F0, LFR_BP1_F0); +// BP1_set( (float *) &compressed_sm_f0[TIME_OFFSET], NB_BINS_COMPRESSED_SM_F0, (unsigned char *) &LFR_BP1_F0[TIME_OFFSET_IN_BYTES] ); // 3) convert the float array in a char array ASM_reorganize( averaged_sm_f0, averaged_sm_f0_reorganized ); ASM_convert( averaged_sm_f0_reorganized, averaged_sm_f0_char); @@ -311,11 +315,13 @@ void ASM_compress( float *averaged_spec_ { for( frequencyBin = 0; frequencyBin < NB_BINS_COMPRESSED_SM_F0; frequencyBin++ ) { - offsetASM = asmComponent * NB_BINS_PER_SM + offsetCompressed = TIME_OFFSET + + frequencyBin * NB_VALUES_PER_SM + + asmComponent; + offsetASM = TIME_OFFSET + + asmComponent * NB_BINS_PER_SM + ASM_F0_INDICE_START + frequencyBin * NB_BINS_TO_AVERAGE_ASM_F0; - offsetCompressed = frequencyBin * NB_VALUES_PER_SM - + asmComponent; compressed_spec_mat[ offsetCompressed ] = 0; for ( k = 0; k < NB_BINS_TO_AVERAGE_ASM_F0; k++ ) { diff --git a/src/fsw_spacewire.c b/src/fsw_spacewire.c --- a/src/fsw_spacewire.c +++ b/src/fsw_spacewire.c @@ -118,7 +118,6 @@ rtems_task recv_task( rtems_task_argumen unsigned char destinationID; unsigned int currentTC_LEN_RCV_AsUnsignedInt; unsigned int parserCode; - unsigned char time[6]; rtems_status_code status; rtems_id queue_recv_id; rtems_id queue_send_id; @@ -160,6 +159,7 @@ rtems_task recv_task( rtems_task_argumen || (parserCode == ILL_SUBTYPE) || (parserCode == WRONG_APP_DATA) || (parserCode == WRONG_SRC_ID) ) { // send TM_LFR_TC_EXE_CORRUPTED + PRINTF1("TC corrupted received, with code: %d\n", parserCode) if ( !( (currentTC.serviceType==TC_TYPE_TIME) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_TIME) ) && !( (currentTC.serviceType==TC_TYPE_GEN) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_INFO)) @@ -173,8 +173,6 @@ rtems_task recv_task( rtems_task_argumen { destinationID = currentTC.sourceID; } - getTime( time ); - close_action( ¤tTC, LFR_DEFAULT, queue_send_id ); send_tm_lfr_tc_exe_corrupted( ¤tTC, queue_send_id, computed_CRC, currentTC_LEN_RCV, destinationID ); @@ -582,9 +580,21 @@ void spacewire_update_statistics( void ) void timecode_irq_handler( void *pDev, void *regs, int minor, unsigned int tc ) { - //if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_1 ) != RTEMS_SUCCESSFUL) { - // printf("In timecode_irq_handler *** Error sending event to DUMB\n"); - //} +// rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_1 ); + struct grgpio_regs_str *grgpio_regs = (struct grgpio_regs_str *) REGS_ADDR_GRGPIO; + + grgpio_regs->io_port_direction_register = + grgpio_regs->io_port_direction_register | 0x08; // [0001 1000], 0 = output disabled, 1 = output enabled + + if ( (grgpio_regs->io_port_output_register & 0x08) == 0x08 ) + { + grgpio_regs->io_port_output_register = grgpio_regs->io_port_output_register & 0xf7; + } + else + { + grgpio_regs->io_port_output_register = grgpio_regs->io_port_output_register | 0x08; + } + } rtems_timer_service_routine user_routine( rtems_id timer_id, void *user_data ) diff --git a/src/tc_handler.c b/src/tc_handler.c --- a/src/tc_handler.c +++ b/src/tc_handler.c @@ -215,20 +215,20 @@ int action_update_info(ccsdsTelecommandP unsigned int status; unsigned char mode; - // check LFR MODE + // check LFR mode mode = (TC->dataAndCRC[ BYTE_POS_HK_UPDATE_INFO_PAR_SET5 ] & 0x1e) >> 1; status = check_update_info_hk_lfr_mode( mode ); - if (status != LFR_DEFAULT) // check TDS mode + if (status == LFR_SUCCESSFUL) // check TDS mode { mode = (TC->dataAndCRC[ BYTE_POS_HK_UPDATE_INFO_PAR_SET6 ] & 0xf0) >> 4; status = check_update_info_hk_tds_mode( mode ); } - if (status != LFR_DEFAULT) // check THR mode + if (status == LFR_SUCCESSFUL) // check THR mode { mode = (TC->dataAndCRC[ BYTE_POS_HK_UPDATE_INFO_PAR_SET6 ] & 0x0f); status = check_update_info_hk_thr_mode( mode ); } - if (status != LFR_DEFAULT) // if the parameter check is successful + if (status == LFR_SUCCESSFUL) // if the parameter check is successful { val = housekeeping_packet.hk_lfr_update_info_tc_cnt[0] * 256 + housekeeping_packet.hk_lfr_update_info_tc_cnt[1]; @@ -306,7 +306,7 @@ int action_update_time(ccsdsTelecommandP 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); - time_management_regs->ctrl = time_management_regs->ctrl | 1; +// time_management_regs->ctrl = time_management_regs->ctrl | 1; // force tick return LFR_SUCCESSFUL; } @@ -653,11 +653,11 @@ void set_run_matrix_spectral( unsigned c { if (value == 1) { - spectral_matrix_regs->config = spectral_matrix_regs->config | 0x4; // 0100 set run_matrix spectral to 1 + spectral_matrix_regs->config = spectral_matrix_regs->config | 0x4; // [0100] set run_matrix spectral to 1 } else { - spectral_matrix_regs->config = spectral_matrix_regs->config & 0xfffffffb; // 1011 set run_matrix spectral to 0 + spectral_matrix_regs->config = spectral_matrix_regs->config & 0xfffffffb; // [1011] set run_matrix spectral to 0 } } @@ -676,7 +676,7 @@ void launch_spectral_matrix_simu( unsign //**************** // CLOSING ACTIONS -void update_last_TC_exe(ccsdsTelecommandPacket_t *TC) +void update_last_TC_exe( ccsdsTelecommandPacket_t *TC, unsigned char * time ) { /** This function is used to update the HK packets statistics after a successful TC execution. * @@ -685,21 +685,28 @@ void update_last_TC_exe(ccsdsTelecommand * */ + unsigned int val; + 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; housekeeping_packet.hk_lfr_last_exe_tc_type[1] = TC->serviceType; housekeeping_packet.hk_lfr_last_exe_tc_subtype[0] = 0x00; housekeeping_packet.hk_lfr_last_exe_tc_subtype[1] = TC->serviceSubType; - housekeeping_packet.hk_lfr_last_exe_tc_time[0] = (unsigned char) (time_management_regs->coarse_time>>24); - housekeeping_packet.hk_lfr_last_exe_tc_time[1] = (unsigned char) (time_management_regs->coarse_time>>16); - housekeeping_packet.hk_lfr_last_exe_tc_time[2] = (unsigned char) (time_management_regs->coarse_time>>8); - housekeeping_packet.hk_lfr_last_exe_tc_time[3] = (unsigned char) (time_management_regs->coarse_time); - housekeeping_packet.hk_lfr_last_exe_tc_time[4] = (unsigned char) (time_management_regs->fine_time>>8); - housekeeping_packet.hk_lfr_last_exe_tc_time[5] = (unsigned char) (time_management_regs->fine_time); + 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); } -void update_last_TC_rej(ccsdsTelecommandPacket_t *TC ) +void update_last_TC_rej(ccsdsTelecommandPacket_t *TC, unsigned char * time ) { /** This function is used to update the HK packets statistics after a TC rejection. * @@ -708,18 +715,25 @@ void update_last_TC_rej(ccsdsTelecommand * */ + unsigned int val; + 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; housekeeping_packet.hk_lfr_last_rej_tc_type[1] = TC->serviceType; housekeeping_packet.hk_lfr_last_rej_tc_subtype[0] = 0x00; housekeeping_packet.hk_lfr_last_rej_tc_subtype[1] = TC->serviceSubType; - housekeeping_packet.hk_lfr_last_rej_tc_time[0] = (unsigned char) (time_management_regs->coarse_time>>24); - housekeeping_packet.hk_lfr_last_rej_tc_time[1] = (unsigned char) (time_management_regs->coarse_time>>16); - housekeeping_packet.hk_lfr_last_rej_tc_time[2] = (unsigned char) (time_management_regs->coarse_time>>8); - housekeeping_packet.hk_lfr_last_rej_tc_time[3] = (unsigned char) (time_management_regs->coarse_time); - housekeeping_packet.hk_lfr_last_rej_tc_time[4] = (unsigned char) (time_management_regs->fine_time>>8); - housekeeping_packet.hk_lfr_last_rej_tc_time[5] = (unsigned char) (time_management_regs->fine_time); + 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); } void close_action(ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id ) @@ -733,30 +747,15 @@ void close_action(ccsdsTelecommandPacket * */ - unsigned int val = 0; - if (result == LFR_SUCCESSFUL) { - if ( !( (TC->serviceType==TC_TYPE_TIME) && (TC->serviceSubType==TC_SUBTYPE_UPDT_TIME) ) - && - !( (TC->serviceType==TC_TYPE_GEN) && (TC->serviceSubType==TC_SUBTYPE_UPDT_INFO)) + if ( !( (TC->serviceType==TC_TYPE_TIME) & (TC->serviceSubType==TC_SUBTYPE_UPDT_TIME) ) + & + !( (TC->serviceType==TC_TYPE_GEN) & (TC->serviceSubType==TC_SUBTYPE_UPDT_INFO)) ) { send_tm_lfr_tc_exe_success( TC, queue_id ); } - update_last_TC_exe( TC ); - 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); - } - else - { - update_last_TC_rej( TC ); - 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); } } diff --git a/src/tc_load_dump_parameters.c b/src/tc_load_dump_parameters.c --- a/src/tc_load_dump_parameters.c +++ b/src/tc_load_dump_parameters.c @@ -417,7 +417,7 @@ unsigned int check_update_info_hk_lfr_mo unsigned int status; if ( (mode == LFR_MODE_STANDBY) || (mode == LFR_MODE_NORMAL) - || (mode = LFR_MODE_BURST) + || (mode == LFR_MODE_BURST) || (mode == LFR_MODE_SBM1) || (mode == LFR_MODE_SBM2)) { status = LFR_SUCCESSFUL; @@ -435,7 +435,7 @@ unsigned int check_update_info_hk_tds_mo unsigned int status; if ( (mode == TDS_MODE_STANDBY) || (mode == TDS_MODE_NORMAL) - || (mode = TDS_MODE_BURST) + || (mode == TDS_MODE_BURST) || (mode == TDS_MODE_SBM1) || (mode == TDS_MODE_SBM2) || (mode == TDS_MODE_LFM)) { @@ -454,7 +454,7 @@ unsigned int check_update_info_hk_thr_mo unsigned int status; if ( (mode == THR_MODE_STANDBY) || (mode == THR_MODE_NORMAL) - || (mode = THR_MODE_BURST)) + || (mode == THR_MODE_BURST)) { status = LFR_SUCCESSFUL; } diff --git a/src/tm_lfr_tc_exe.c b/src/tm_lfr_tc_exe.c --- a/src/tm_lfr_tc_exe.c +++ b/src/tm_lfr_tc_exe.c @@ -71,6 +71,9 @@ int send_tm_lfr_tc_exe_success( ccsdsTel PRINTF("in send_tm_lfr_tc_exe_success *** ERR\n") } + // UPDATE HK FIELDS + update_last_TC_exe( TC, TM.time ); + return status; } @@ -139,6 +142,9 @@ int send_tm_lfr_tc_exe_inconsistent( ccs PRINTF("in send_tm_lfr_tc_exe_inconsistent *** ERR\n") } + // UPDATE HK FIELDS + update_last_TC_rej( TC, TM.time ); + return status; } @@ -204,6 +210,9 @@ int send_tm_lfr_tc_exe_not_executable( c PRINTF("in send_tm_lfr_tc_exe_not_executable *** ERR\n") } + // UPDATE HK FIELDS + update_last_TC_rej( TC, TM.time ); + return status; } @@ -267,6 +276,9 @@ int send_tm_lfr_tc_exe_not_implemented( PRINTF("in send_tm_lfr_tc_exe_not_implemented *** ERR\n") } + // UPDATE HK FIELDS + update_last_TC_rej( TC, TM.time ); + return status; } @@ -330,6 +342,9 @@ int send_tm_lfr_tc_exe_error( ccsdsTelec PRINTF("in send_tm_lfr_tc_exe_error *** ERR\n") } + // UPDATE HK FIELDS + update_last_TC_rej( TC, TM.time ); + return status; } @@ -410,6 +425,9 @@ int send_tm_lfr_tc_exe_corrupted(ccsdsTe PRINTF("in send_tm_lfr_tc_exe_error *** ERR\n") } + // UPDATE HK FIELDS + update_last_TC_rej( TC, TM.time ); + return status; } diff --git a/src/wf_handler.c b/src/wf_handler.c --- a/src/wf_handler.c +++ b/src/wf_handler.c @@ -1015,11 +1015,9 @@ void build_snapshot_from_ring( ring_node // get the f0 acquisition time build_acquisition_time( &acquisitionTimeF0_asLong, current_ring_node_f0 ); - PRINTF1("acquisitionTimeF0_asLong %llx \n", acquisitionTimeF0_asLong) // compute the central reference time centerTime_asLong = acquisitionTimeF0_asLong + deltaT_F0; - PRINTF1("centerTime_asLong %llx \n", centerTime_asLong) // compute the acquisition time of the current snapshot switch(frequencyChannel) @@ -1042,7 +1040,6 @@ void build_snapshot_from_ring( ring_node nbTicksPerSample_asLong = 256; break; } - PRINTF1("acquisitionTime_asLong %llx\n", acquisitionTime_asLong) //**************************************************************************** // 1) search the ring_node with the acquisition time <= acquisitionTime_asLong @@ -1064,12 +1061,10 @@ void build_snapshot_from_ring( ring_node // compute the number of samples to take in the current buffer sampleOffset_asLong = ((acquisitionTime_asLong - bufferAcquisitionTime_asLong) * frequency_asLong ) >> 16; nbSamplesPart1_asLong = NB_SAMPLES_PER_SNAPSHOT - sampleOffset_asLong; - PRINTF2("sampleOffset_asLong = %lld, nbSamplesPart1 = %lld\n", sampleOffset_asLong, nbSamplesPart1_asLong) // compute the final acquisition time acquisitionTime_asLong = bufferAcquisitionTime_asLong + sampleOffset_asLong * nbTicksPerSample_asLong; - PRINTF1("FINAL acquisitionTime_asLong %llx\n\n", acquisitionTime_asLong) // copy the acquisition time at the beginning of the extrated snapshot ptr1 = (unsigned char*) &acquisitionTime_asLong; @@ -1162,7 +1157,7 @@ void reset_waveform_picker_regs(void) * */ - waveform_picker_regs->data_shaping = 0x01; // 0x00 *** R1 R0 SP1 SP0 BW +// waveform_picker_regs->data_shaping = 0x01; // 0x00 *** R1 R0 SP1 SP0 BW waveform_picker_regs->run_burst_enable = 0x00; // 0x04 *** [run *** burst f2, f1, f0 *** enable f3, f2, f1, f0 ] waveform_picker_regs->addr_data_f0 = current_ring_node_f0->buffer_address; // 0x08 waveform_picker_regs->addr_data_f1 = current_ring_node_f1->buffer_address; // 0x0c