##// END OF EJS Templates
commit before going back to 3.1.0.2 for LESIA compilation
paul -
r295:16a2669a01ce R3_plus draft
parent child
Show More
@@ -1,2 +1,2
1 1 3081d1f9bb20b2b64a192585337a292a9804e0c5 LFR_basic-parameters
2 c378fa14eadd80b3b873ca7c8f9f387893c07692 header/lfr_common_headers
2 1ffa3d630b9ced4a87a362dafb10d9838e9cc0d9 header/lfr_common_headers
@@ -1,123 +1,125
1 1 TEMPLATE = app
2 2 # CONFIG += console v8 sim
3 3 # CONFIG options =
4 4 # verbose
5 5 # boot_messages
6 6 # debug_messages
7 7 # cpu_usage_report
8 8 # stack_report
9 9 # vhdl_dev
10 10 # debug_tch
11 11 # lpp_dpu_destid /!\ REMOVE BEFORE DELIVERY TO LESIA /!\
12 12 # debug_watchdog
13 13 CONFIG += console verbose lpp_dpu_destid cpu_usage_report
14 14 CONFIG -= qt
15 15
16 16 include(./sparc.pri)
17 17
18 INCLUDEPATH += /opt/rtems-4.10/sparc-rtems/leon3/lib/include
19
18 20 # flight software version
19 21 SWVERSION=-1-0
20 22 DEFINES += SW_VERSION_N1=3 # major
21 23 DEFINES += SW_VERSION_N2=1 # minor
22 24 DEFINES += SW_VERSION_N3=0 # patch
23 25 DEFINES += SW_VERSION_N4=2 # internal
24 26
25 27 # <GCOV>
26 28 #QMAKE_CFLAGS_RELEASE += -fprofile-arcs -ftest-coverage
27 29 #LIBS += -lgcov /opt/GCOV/01A/lib/overload.o -lc
28 30 # </GCOV>
29 31
30 32 # <CHANGE BEFORE FLIGHT>
31 33 contains( CONFIG, lpp_dpu_destid ) {
32 34 DEFINES += LPP_DPU_DESTID
33 35 }
34 36 # </CHANGE BEFORE FLIGHT>
35 37
36 38 contains( CONFIG, debug_tch ) {
37 39 DEFINES += DEBUG_TCH
38 40 }
39 41 DEFINES += MSB_FIRST_TCH
40 42
41 43 contains( CONFIG, vhdl_dev ) {
42 44 DEFINES += VHDL_DEV
43 45 }
44 46
45 47 contains( CONFIG, verbose ) {
46 48 DEFINES += PRINT_MESSAGES_ON_CONSOLE
47 49 }
48 50
49 51 contains( CONFIG, debug_messages ) {
50 52 DEFINES += DEBUG_MESSAGES
51 53 }
52 54
53 55 contains( CONFIG, cpu_usage_report ) {
54 56 DEFINES += PRINT_TASK_STATISTICS
55 57 }
56 58
57 59 contains( CONFIG, stack_report ) {
58 60 DEFINES += PRINT_STACK_REPORT
59 61 }
60 62
61 63 contains( CONFIG, boot_messages ) {
62 64 DEFINES += BOOT_MESSAGES
63 65 }
64 66
65 67 contains( CONFIG, debug_watchdog ) {
66 68 DEFINES += DEBUG_WATCHDOG
67 69 }
68 70
69 71 #doxygen.target = doxygen
70 72 #doxygen.commands = doxygen ../doc/Doxyfile
71 73 #QMAKE_EXTRA_TARGETS += doxygen
72 74
73 75 TARGET = fsw
74 76
75 77 INCLUDEPATH += \
76 78 $${PWD}/../src \
77 79 $${PWD}/../header \
78 80 $${PWD}/../header/lfr_common_headers \
79 81 $${PWD}/../header/processing \
80 82 $${PWD}/../LFR_basic-parameters
81 83
82 84 SOURCES += \
83 85 ../src/wf_handler.c \
84 86 ../src/tc_handler.c \
85 87 ../src/fsw_misc.c \
86 88 ../src/fsw_init.c \
87 89 ../src/fsw_globals.c \
88 90 ../src/fsw_spacewire.c \
89 91 ../src/tc_load_dump_parameters.c \
90 92 ../src/tm_lfr_tc_exe.c \
91 93 ../src/tc_acceptance.c \
92 94 ../src/processing/fsw_processing.c \
93 95 ../src/processing/avf0_prc0.c \
94 96 ../src/processing/avf1_prc1.c \
95 97 ../src/processing/avf2_prc2.c \
96 98 ../src/lfr_cpu_usage_report.c \
97 99 ../LFR_basic-parameters/basic_parameters.c
98 100
99 101 HEADERS += \
100 102 ../header/wf_handler.h \
101 103 ../header/tc_handler.h \
102 104 ../header/grlib_regs.h \
103 105 ../header/fsw_misc.h \
104 106 ../header/fsw_init.h \
105 107 ../header/fsw_spacewire.h \
106 108 ../header/tc_load_dump_parameters.h \
107 109 ../header/tm_lfr_tc_exe.h \
108 110 ../header/tc_acceptance.h \
109 111 ../header/processing/fsw_processing.h \
110 112 ../header/processing/avf0_prc0.h \
111 113 ../header/processing/avf1_prc1.h \
112 114 ../header/processing/avf2_prc2.h \
113 115 ../header/fsw_params_wf_handler.h \
114 116 ../header/lfr_cpu_usage_report.h \
115 117 ../header/lfr_common_headers/ccsds_types.h \
116 118 ../header/lfr_common_headers/fsw_params.h \
117 119 ../header/lfr_common_headers/fsw_params_nb_bytes.h \
118 120 ../header/lfr_common_headers/fsw_params_processing.h \
119 121 ../header/lfr_common_headers/tm_byte_positions.h \
120 122 ../LFR_basic-parameters/basic_parameters.h \
121 123 ../LFR_basic-parameters/basic_parameters_params.h \
122 124 ../header/GscMemoryLPP.hpp
123 125
@@ -1,97 +1,99
1 1 CONFIG += console
2 2 CONFIG -= qt
3 3 QMAKE_CC=sparc-rtems-gcc
4 4 message(C compiler forced to: $$QMAKE_CC)
5 5 QMAKE_CXX=sparc-rtems-g++
6 6 message(C++ compiler forced to: $$QMAKE_CXX)
7 7 QMAKE_AR=sparc-rtems-ar rcs
8 8 message(Archiver forced to: $$QMAKE_AR)
9 9 QMAKE_LINK=sparc-rtems-g++
10 10 message(Linker forced to: $$QMAKE_LINK)
11 11 QMAKE_LINK_SHLIB=sparc-rtems-g++
12 12 QMAKE_OBJCOPY= sparc-rtems-objcopy
13 13 QMAKE_STRIP=sparc-rtems-strip
14 14 QMAKE_GDB=sparc-rtems-gdb
15 15
16 INCLUDEPATH += /opt/rtems-4.10
16 #INCLUDEPATH += /opt/rtems-4.10
17 INCLUDEPATH += /opt/rtems-4.10/sparc-rtems/leon3/lib/include
17 18
18 19 QMAKE_CFLAGS_DEBUG= -g
19 20 QMAKE_CFLAGS_RELEASE=""
20 21 QMAKE_CXXFLAGS_DEBUG= -g
21 22 QMAKE_CXXFLAGS_RELEASE=""
22 23 QMAKE_LFLAGS_RELEASE=""
23 24 QMAKE_LFLAGS_DEBUG= -g
24 25 QMAKE_CXXFLAGS_DEPS =
25 26 QMAKE_CXXFLAGS_WARN_ON = -Wall
26 27 QMAKE_CXXFLAGS_WARN_OFF = -w
27 28 QMAKE_CXXFLAGS_RELEASE =
28 29 QMAKE_CXXFLAGS_DEBUG =
29 30 QMAKE_CXXFLAGS_YACC =
30 31 QMAKE_CXXFLAGS_THREAD =
31 32 QMAKE_CXXFLAGS_RTTI_ON =
32 33 QMAKE_CXXFLAGS_RTTI_OFF =
33 34 QMAKE_CXXFLAGS_EXCEPTIONS_ON =
34 35 QMAKE_CXXFLAGS_EXCEPTIONS_OFF =
35 36 QMAKE_CFLAGS_WARN_ON = -Wall
36 37 QMAKE_CFLAGS_WARN_OFF = -w
37 38 QMAKE_CFLAGS_RELEASE =
38 39 QMAKE_CFLAGS_YACC =
39 40 QMAKE_LFLAGS_EXCEPTIONS_ON =
40 41 QMAKE_LFLAGS_EXCEPTIONS_OFF =
41 42 QMAKE_LFLAGS_RELEASE = -Xlinker -Map=output.map
42 43 QMAKE_LFLAGS_CONSOLE =
43 44 QMAKE_LFLAGS_WINDOWS =
44 45 QMAKE_LFLAGS_DLL =
45 46 QMAKE_INCDIR_QT =
46 47 QMAKE_INCDIR =
47 48 QMAKE_CFLAGS_SHLIB =
48 49 QMAKE_CFLAGS_STATIC_LIB =
49 50 QMAKE_CXXFLAGS_SHLIB =
50 51 QMAKE_CXXFLAGS_STATIC_LIB =
51 52 QMAKE_LIBS=""
52 53 INCLUDEPATH=""
53 54 DEFINES=""
54 55
55 56 contains( TEMPLATE, app ) {
56 57 OBJECTS_DIR=obj
57 58 DESTDIR=bin
58 59 }
59 60
60 61 #QMAKE_CFLAGS_RELEASE += -O0
61 62 #QMAKE_CFLAGS_DEBUG += -O0
62 63 #QMAKE_CXXFLAGS_RELEASE += -O0
63 64 #QMAKE_CXXFLAGS_DEBUG += -O0
65
64 66 QMAKE_CFLAGS_RELEASE += -O3
65 67 QMAKE_CFLAGS_DEBUG += -O3
66 68 QMAKE_CXXFLAGS_RELEASE += -O3
67 69 QMAKE_CXXFLAGS_DEBUG += -O3
68 70
69 #QMAKE_CFLAGS_RELEASE+= -O3 -std=c99
70 #QMAKE_CFLAGS_DEBUG+= -O3 -std=c99
71 #QMAKE_CXXFLAGS_RELEASE+= -O3 -std=c99
72 #QMAKE_CXXFLAGS_DEBUG+= -O3 -std=c99
71 #QMAKE_CFLAGS_RELEASE += -O3 -std=c99
72 #QMAKE_CFLAGS_DEBUG += -O3 -std=c99
73 #QMAKE_CXXFLAGS_RELEASE += -O3 -std=c99
74 #QMAKE_CXXFLAGS_DEBUG += -O3 -std=c99
73 75
74 76 contains( TEMPLATE, app ) {
75 77 grmon.target = grmon
76 78 grmon.commands = cd $$DESTDIR && C:/opt/grmon-eval-2.0.29b/win32/bin/grmon.exe -uart COM4 -u
77 79 QMAKE_EXTRA_TARGETS += grmon
78 80 }
79 81
80 82
81 83
82 84
83 85
84 86
85 87
86 88
87 89
88 90
89 91
90 92
91 93
92 94
93 95
94 96
95 97
96 98
97 99
@@ -1,83 +1,84
1 1 #ifndef FSW_MISC_H_INCLUDED
2 2 #define FSW_MISC_H_INCLUDED
3 3
4 4 #include <rtems.h>
5 5 #include <stdio.h>
6 6 #include <grspw.h>
7 7 #include <grlib_regs.h>
8 8
9 9 #include "fsw_params.h"
10 10 #include "fsw_spacewire.h"
11 11 #include "lfr_cpu_usage_report.h"
12 12
13 13
14 14 enum lfr_reset_cause_t{
15 15 UNKNOWN_CAUSE,
16 16 POWER_ON,
17 17 TC_RESET,
18 18 WATCHDOG,
19 19 ERROR_RESET,
20 20 UNEXP_RESET
21 21 };
22 22
23 23 extern gptimer_regs_t *gptimer_regs;
24 24 extern void ASR16_get_FPRF_IURF_ErrorCounters( unsigned int*, unsigned int* );
25 25 extern void CCR_getInstructionAndDataErrorCounters( unsigned int*, unsigned int* );
26 26
27 27 #define LFR_RESET_CAUSE_UNKNOWN_CAUSE 0
28 28
29 29 rtems_name name_hk_rate_monotonic; // name of the HK rate monotonic
30 30 rtems_id HK_id; // id of the HK rate monotonic period
31 31
32 32 void timer_configure( unsigned char timer, unsigned int clock_divider,
33 33 unsigned char interrupt_level, rtems_isr (*timer_isr)() );
34 34 void timer_start( unsigned char timer );
35 35 void timer_stop( unsigned char timer );
36 36 void timer_set_clock_divider(unsigned char timer, unsigned int clock_divider);
37 37
38 38 // WATCHDOG
39 39 rtems_isr watchdog_isr( rtems_vector_number vector );
40 40 void watchdog_configure(void);
41 41 void watchdog_stop(void);
42 42 void watchdog_reload(void);
43 43 void watchdog_start(void);
44 44
45 45 // SERIAL LINK
46 46 int send_console_outputs_on_apbuart_port( void );
47 47 int enable_apbuart_transmitter( void );
48 48 void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value);
49 49
50 50 // RTEMS TASKS
51 51 rtems_task load_task( rtems_task_argument argument );
52 52 rtems_task hous_task( rtems_task_argument argument );
53 53 rtems_task dumb_task( rtems_task_argument unused );
54 54
55 55 void init_housekeeping_parameters( void );
56 56 void increment_seq_counter(unsigned short *packetSequenceControl);
57 57 void getTime( unsigned char *time);
58 58 unsigned long long int getTimeAsUnsignedLongLongInt( );
59 59 void send_dumb_hk( void );
60 60 void get_temperatures( unsigned char *temperatures );
61 61 void get_v_e1_e2_f3( unsigned char *spacecraft_potential );
62 62 void get_cpu_load( unsigned char *resource_statistics );
63 63 void set_hk_lfr_sc_potential_flag( bool state );
64 void set_sy_lfr_pas_filter_enabled( bool state );
64 65 void set_sy_lfr_watchdog_enabled( bool state );
65 66 void set_hk_lfr_calib_enable( bool state );
66 67 void set_hk_lfr_reset_cause( enum lfr_reset_cause_t lfr_reset_cause );
67 68 void hk_lfr_le_me_he_update();
68 69 void set_hk_lfr_time_not_synchro();
69 70
70 71 extern int sched_yield( void );
71 72 extern void rtems_cpu_usage_reset();
72 73 extern ring_node *current_ring_node_f3;
73 74 extern ring_node *ring_node_to_send_cwf_f3;
74 75 extern ring_node waveform_ring_f3[];
75 76 extern unsigned short sequenceCounterHK;
76 77
77 78 extern unsigned char hk_lfr_q_sd_fifo_size_max;
78 79 extern unsigned char hk_lfr_q_rv_fifo_size_max;
79 80 extern unsigned char hk_lfr_q_p0_fifo_size_max;
80 81 extern unsigned char hk_lfr_q_p1_fifo_size_max;
81 82 extern unsigned char hk_lfr_q_p2_fifo_size_max;
82 83
83 84 #endif // FSW_MISC_H_INCLUDED
@@ -1,25 +1,35
1 1 #include <drvmgr/ambapp_bus.h>
2 #include <drvmgr/drvmgr.h>
2 3
3 4 // GRSPW0 resources
4 struct drvmgr_key grlib_grspw_0n1_res[] = {
5 struct drvmgr_key grlib_grspw_0n1_res[] =
6 {
5 7 {"txBdCnt", KEY_TYPE_INT, {(unsigned int)50}}, // 7 SWF_F0, 7 SWF_F1, 7 SWF_F2, 7 CWF_F3, 7 CWF_F1 ou 7 CWF_F2
6 8 {"rxBdCnt", KEY_TYPE_INT, {(unsigned int)10}},
7 9 {"txDataSize", KEY_TYPE_INT, {(unsigned int)4096}},
8 10 {"txHdrSize", KEY_TYPE_INT, {(unsigned int)34}},
9 {"rxPktSize", KEY_TYPE_INT, {(unsigned int)228+4}},
11 {"rxPktSize", KEY_TYPE_INT, {(unsigned int)200}},
10 12 KEY_EMPTY
11 13 };
12 14
13 15 // If RTEMS_DRVMGR_STARTUP is defined we override the "weak defaults" that is defined by the LEON3 BSP.
14 16
15 struct drvmgr_bus_res grlib_drv_resources = {
16 .next = NULL,
17 .resource = {
17 //struct drvmgr_bus_res grlib_drv_resources =
18 //{
19 // .next = NULL,
20 // .resource = {
21 // {DRIVER_AMBAPP_GAISLER_GRSPW_ID, 0, &grlib_grspw_0n1_res[0]},
22 // {DRIVER_AMBAPP_GAISLER_GRSPW_ID, 1, &grlib_grspw_0n1_res[0]},
23 // RES_EMPTY /* Mark end of resource array */
24 // }
25 //};
26
27 struct drvmgr_bus_res grlib_drv_resources =
28 {
29 NULL,
30 {
18 31 {DRIVER_AMBAPP_GAISLER_GRSPW_ID, 0, &grlib_grspw_0n1_res[0]},
19 // {DRIVER_AMBAPP_GAISLER_APBUART_ID, 0, &grlib_drv_res_apbuart0[0]},
20 // {DRIVER_AMBAPP_GAISLER_APBUART_ID, 1, &grlib_drv_res_apbuart1[0]},
21 RES_EMPTY /* Mark end of device resource array */
32 {DRIVER_AMBAPP_GAISLER_GRSPW_ID, 1, &grlib_grspw_0n1_res[0]},
33 RES_EMPTY /* Mark end of resource array */
22 34 }
23 35 };
24
25
@@ -1,934 +1,938
1 1 /** This is the RTEMS initialization module.
2 2 *
3 3 * @file
4 4 * @author P. LEROY
5 5 *
6 6 * This module contains two very different information:
7 7 * - specific instructions to configure the compilation of the RTEMS executive
8 8 * - functions related to the fligth softwre initialization, especially the INIT RTEMS task
9 9 *
10 10 */
11 11
12 12 //*************************
13 13 // GPL reminder to be added
14 14 //*************************
15 15
16 16 #include <rtems.h>
17 17
18 18 /* configuration information */
19 19
20 20 #define CONFIGURE_INIT
21 21
22 22 #include <bsp.h> /* for device driver prototypes */
23 23
24 24 /* configuration information */
25 25
26 26 #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
27 27 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
28 28
29 29 #define CONFIGURE_MAXIMUM_TASKS 20
30 30 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
31 31 #define CONFIGURE_EXTRA_TASK_STACKS (3 * RTEMS_MINIMUM_STACK_SIZE)
32 32 #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 32
33 33 #define CONFIGURE_INIT_TASK_PRIORITY 1 // instead of 100
34 34 #define CONFIGURE_INIT_TASK_MODE (RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT)
35 35 #define CONFIGURE_INIT_TASK_ATTRIBUTES (RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT)
36 36 #define CONFIGURE_MAXIMUM_DRIVERS 16
37 37 #define CONFIGURE_MAXIMUM_PERIODS 5
38 38 #define CONFIGURE_MAXIMUM_TIMERS 5 // [spiq] [link] [spacewire_reset_link]
39 39 #define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 5
40 40 #ifdef PRINT_STACK_REPORT
41 41 #define CONFIGURE_STACK_CHECKER_ENABLED
42 42 #endif
43 43
44 44 #include <rtems/confdefs.h>
45 45
46 46 /* If --drvmgr was enabled during the configuration of the RTEMS kernel */
47 47 #ifdef RTEMS_DRVMGR_STARTUP
48 #ifdef LEON3
49 /* Add Timer and UART Driver */
50 #ifdef CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
51 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GPTIMER
52 #endif
53 #ifdef CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
54 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_APBUART
55 #endif
56 #endif
57 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GRSPW /* GRSPW Driver */
58 #include <drvmgr/drvmgr_confdefs.h>
48 #ifdef LEON3
49 /* Add Timer and UART Driver */
50
51 #ifdef CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
52 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GPTIMER
53 #endif
54
55 #ifdef CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
56 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_APBUART
57 #endif
58
59 #endif
60 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GRSPW /* GRSPW Driver */
61
62 #include <drvmgr/drvmgr_confdefs.h>
59 63 #endif
60 64
61 65 #include "fsw_init.h"
62 66 #include "fsw_config.c"
63 67 #include "GscMemoryLPP.hpp"
64 68
65 69 void initCache()
66 70 {
67 71 // ASI 2 contains a few control registers that have not been assigned as ancillary state registers.
68 72 // These should only be read and written using 32-bit LDA/STA instructions.
69 73 // All cache registers are accessed through load/store operations to the alternate address space (LDA/STA), using ASI = 2.
70 74 // The table below shows the register addresses:
71 75 // 0x00 Cache control register
72 76 // 0x04 Reserved
73 77 // 0x08 Instruction cache configuration register
74 78 // 0x0C Data cache configuration register
75 79
76 80 // Cache Control Register Leon3 / Leon3FT
77 81 // 31..30 29 28 27..24 23 22 21 20..19 18 17 16
78 82 // RFT PS TB DS FD FI FT ST IB
79 83 // 15 14 13..12 11..10 9..8 7..6 5 4 3..2 1..0
80 84 // IP DP ITE IDE DTE DDE DF IF DCS ICS
81 85
82 86 unsigned int cacheControlRegister;
83 87
84 88 CCR_resetCacheControlRegister();
85 89 ASR16_resetRegisterProtectionControlRegister();
86 90
87 91 cacheControlRegister = CCR_getValue();
88 92 PRINTF1("(0) CCR - Cache Control Register = %x\n", cacheControlRegister);
89 93 PRINTF1("(0) ASR16 = %x\n", *asr16Ptr);
90 94
91 95 CCR_enableInstructionCache(); // ICS bits
92 96 CCR_enableDataCache(); // DCS bits
93 97 CCR_enableInstructionBurstFetch(); // IB bit
94 98
95 99 faultTolerantScheme();
96 100
97 101 cacheControlRegister = CCR_getValue();
98 102 PRINTF1("(1) CCR - Cache Control Register = %x\n", cacheControlRegister);
99 103 PRINTF1("(1) ASR16 Register protection control register = %x\n", *asr16Ptr);
100 104
101 105 PRINTF("\n");
102 106 }
103 107
104 108 rtems_task Init( rtems_task_argument ignored )
105 109 {
106 110 /** This is the RTEMS INIT taks, it is the first task launched by the system.
107 111 *
108 112 * @param unused is the starting argument of the RTEMS task
109 113 *
110 114 * The INIT task create and run all other RTEMS tasks.
111 115 *
112 116 */
113 117
114 118 //***********
115 119 // INIT CACHE
116 120
117 121 unsigned char *vhdlVersion;
118 122
119 123 reset_lfr();
120 124
121 125 reset_local_time();
122 126
123 127 rtems_cpu_usage_reset();
124 128
125 129 rtems_status_code status;
126 130 rtems_status_code status_spw;
127 131 rtems_isr_entry old_isr_handler;
128 132
129 133 // UART settings
130 134 enable_apbuart_transmitter();
131 135 set_apbuart_scaler_reload_register(REGS_ADDR_APBUART, APBUART_SCALER_RELOAD_VALUE);
132 136
133 137 DEBUG_PRINTF("\n\n\n\n\nIn INIT *** Now the console is on port COM1\n")
134 138
135 139
136 140 PRINTF("\n\n\n\n\n")
137 141
138 142 initCache();
139 143
140 144 PRINTF("*************************\n")
141 145 PRINTF("** LFR Flight Software **\n")
142 146 PRINTF1("** %d.", SW_VERSION_N1)
143 147 PRINTF1("%d." , SW_VERSION_N2)
144 148 PRINTF1("%d." , SW_VERSION_N3)
145 149 PRINTF1("%d **\n", SW_VERSION_N4)
146 150
147 151 vhdlVersion = (unsigned char *) (REGS_ADDR_VHDL_VERSION);
148 152 PRINTF("** VHDL **\n")
149 153 PRINTF1("** %d.", vhdlVersion[1])
150 154 PRINTF1("%d." , vhdlVersion[2])
151 155 PRINTF1("%d **\n", vhdlVersion[3])
152 156 PRINTF("*************************\n")
153 157 PRINTF("\n\n")
154 158
155 159 init_parameter_dump();
156 160 init_kcoefficients_dump();
157 161 init_local_mode_parameters();
158 162 init_housekeeping_parameters();
159 163 init_k_coefficients_prc0();
160 164 init_k_coefficients_prc1();
161 165 init_k_coefficients_prc2();
162 166 pa_bia_status_info = 0x00;
163 167 cp_rpw_sc_rw_f_flags = 0x00;
164 168 cp_rpw_sc_rw1_f1 = 0.0;
165 169 cp_rpw_sc_rw1_f2 = 0.0;
166 170 cp_rpw_sc_rw2_f1 = 0.0;
167 171 cp_rpw_sc_rw2_f2 = 0.0;
168 172 cp_rpw_sc_rw3_f1 = 0.0;
169 173 cp_rpw_sc_rw3_f2 = 0.0;
170 174 cp_rpw_sc_rw4_f1 = 0.0;
171 175 cp_rpw_sc_rw4_f2 = 0.0;
172 176 // initialize filtering parameters
173 177 filterPar.spare_sy_lfr_pas_filter_enabled = DEFAULT_SY_LFR_PAS_FILTER_ENABLED;
174 178 filterPar.sy_lfr_pas_filter_modulus = DEFAULT_SY_LFR_PAS_FILTER_MODULUS;
175 179 filterPar.sy_lfr_pas_filter_tbad = DEFAULT_SY_LFR_PAS_FILTER_TBAD;
176 180 filterPar.sy_lfr_pas_filter_offset = DEFAULT_SY_LFR_PAS_FILTER_OFFSET;
177 181 filterPar.sy_lfr_pas_filter_shift = DEFAULT_SY_LFR_PAS_FILTER_SHIFT;
178 182 filterPar.sy_lfr_sc_rw_delta_f = DEFAULT_SY_LFR_SC_RW_DELTA_F;
179 183 update_last_valid_transition_date( DEFAULT_LAST_VALID_TRANSITION_DATE );
180 184
181 185 // waveform picker initialization
182 186 WFP_init_rings();
183 187 LEON_Clear_interrupt( IRQ_SPARC_GPTIMER_WATCHDOG ); // initialize the waveform rings
184 188 WFP_reset_current_ring_nodes();
185 189 reset_waveform_picker_regs();
186 190
187 191 // spectral matrices initialization
188 192 SM_init_rings(); // initialize spectral matrices rings
189 193 SM_reset_current_ring_nodes();
190 194 reset_spectral_matrix_regs();
191 195
192 196 // configure calibration
193 197 configureCalibration( false ); // true means interleaved mode, false is for normal mode
194 198
195 199 updateLFRCurrentMode( LFR_MODE_STANDBY );
196 200
197 201 BOOT_PRINTF1("in INIT *** lfrCurrentMode is %d\n", lfrCurrentMode)
198 202
199 203 create_names(); // create all names
200 204
201 205 status = create_timecode_timer(); // create the timer used by timecode_irq_handler
202 206 if (status != RTEMS_SUCCESSFUL)
203 207 {
204 208 PRINTF1("in INIT *** ERR in create_timer_timecode, code %d", status)
205 209 }
206 210
207 211 status = create_message_queues(); // create message queues
208 212 if (status != RTEMS_SUCCESSFUL)
209 213 {
210 214 PRINTF1("in INIT *** ERR in create_message_queues, code %d", status)
211 215 }
212 216
213 217 status = create_all_tasks(); // create all tasks
214 218 if (status != RTEMS_SUCCESSFUL)
215 219 {
216 220 PRINTF1("in INIT *** ERR in create_all_tasks, code %d\n", status)
217 221 }
218 222
219 223 // **************************
220 224 // <SPACEWIRE INITIALIZATION>
221 225 status_spw = spacewire_open_link(); // (1) open the link
222 226 if ( status_spw != RTEMS_SUCCESSFUL )
223 227 {
224 228 PRINTF1("in INIT *** ERR spacewire_open_link code %d\n", status_spw )
225 229 }
226 230
227 231 if ( status_spw == RTEMS_SUCCESSFUL ) // (2) configure the link
228 232 {
229 233 status_spw = spacewire_configure_link( fdSPW );
230 234 if ( status_spw != RTEMS_SUCCESSFUL )
231 235 {
232 236 PRINTF1("in INIT *** ERR spacewire_configure_link code %d\n", status_spw )
233 237 }
234 238 }
235 239
236 240 if ( status_spw == RTEMS_SUCCESSFUL) // (3) start the link
237 241 {
238 242 status_spw = spacewire_start_link( fdSPW );
239 243 if ( status_spw != RTEMS_SUCCESSFUL )
240 244 {
241 245 PRINTF1("in INIT *** ERR spacewire_start_link code %d\n", status_spw )
242 246 }
243 247 }
244 248 // </SPACEWIRE INITIALIZATION>
245 249 // ***************************
246 250
247 251 status = start_all_tasks(); // start all tasks
248 252 if (status != RTEMS_SUCCESSFUL)
249 253 {
250 254 PRINTF1("in INIT *** ERR in start_all_tasks, code %d", status)
251 255 }
252 256
253 257 // start RECV and SEND *AFTER* SpaceWire Initialization, due to the timeout of the start call during the initialization
254 258 status = start_recv_send_tasks();
255 259 if ( status != RTEMS_SUCCESSFUL )
256 260 {
257 261 PRINTF1("in INIT *** ERR start_recv_send_tasks code %d\n", status )
258 262 }
259 263
260 264 // suspend science tasks, they will be restarted later depending on the mode
261 265 status = suspend_science_tasks(); // suspend science tasks (not done in stop_current_mode if current mode = STANDBY)
262 266 if (status != RTEMS_SUCCESSFUL)
263 267 {
264 268 PRINTF1("in INIT *** in suspend_science_tasks *** ERR code: %d\n", status)
265 269 }
266 270
267 271 // configure IRQ handling for the waveform picker unit
268 272 status = rtems_interrupt_catch( waveforms_isr,
269 273 IRQ_SPARC_WAVEFORM_PICKER,
270 274 &old_isr_handler) ;
271 275 // configure IRQ handling for the spectral matrices unit
272 276 status = rtems_interrupt_catch( spectral_matrices_isr,
273 277 IRQ_SPARC_SPECTRAL_MATRIX,
274 278 &old_isr_handler) ;
275 279
276 280 // if the spacewire link is not up then send an event to the SPIQ task for link recovery
277 281 if ( status_spw != RTEMS_SUCCESSFUL )
278 282 {
279 283 status = rtems_event_send( Task_id[TASKID_SPIQ], SPW_LINKERR_EVENT );
280 284 if ( status != RTEMS_SUCCESSFUL ) {
281 285 PRINTF1("in INIT *** ERR rtems_event_send to SPIQ code %d\n", status )
282 286 }
283 287 }
284 288
285 289 BOOT_PRINTF("delete INIT\n")
286 290
287 291 set_hk_lfr_sc_potential_flag( true );
288 292
289 293 // start the timer to detect a missing spacewire timecode
290 294 // the timeout is larger because the spw IP needs to receive several valid timecodes before generating a tickout
291 295 // if a tickout is generated, the timer is restarted
292 296 status = rtems_timer_fire_after( timecode_timer_id, TIMECODE_TIMER_TIMEOUT_INIT, timecode_timer_routine, NULL );
293 297
294 298 grspw_timecode_callback = &timecode_irq_handler;
295 299
296 300 status = rtems_task_delete(RTEMS_SELF);
297 301
298 302 }
299 303
300 304 void init_local_mode_parameters( void )
301 305 {
302 306 /** This function initialize the param_local global variable with default values.
303 307 *
304 308 */
305 309
306 310 unsigned int i;
307 311
308 312 // LOCAL PARAMETERS
309 313
310 314 BOOT_PRINTF1("local_sbm1_nb_cwf_max %d \n", param_local.local_sbm1_nb_cwf_max)
311 315 BOOT_PRINTF1("local_sbm2_nb_cwf_max %d \n", param_local.local_sbm2_nb_cwf_max)
312 316 BOOT_PRINTF1("nb_interrupt_f0_MAX = %d\n", param_local.local_nb_interrupt_f0_MAX)
313 317
314 318 // init sequence counters
315 319
316 320 for(i = 0; i<SEQ_CNT_NB_DEST_ID; i++)
317 321 {
318 322 sequenceCounters_TC_EXE[i] = 0x00;
319 323 sequenceCounters_TM_DUMP[i] = 0x00;
320 324 }
321 325 sequenceCounters_SCIENCE_NORMAL_BURST = 0x00;
322 326 sequenceCounters_SCIENCE_SBM1_SBM2 = 0x00;
323 327 sequenceCounterHK = TM_PACKET_SEQ_CTRL_STANDALONE << 8;
324 328 }
325 329
326 330 void reset_local_time( void )
327 331 {
328 332 time_management_regs->ctrl = time_management_regs->ctrl | 0x02; // [0010] software reset, coarse time = 0x80000000
329 333 }
330 334
331 335 void create_names( void ) // create all names for tasks and queues
332 336 {
333 337 /** This function creates all RTEMS names used in the software for tasks and queues.
334 338 *
335 339 * @return RTEMS directive status codes:
336 340 * - RTEMS_SUCCESSFUL - successful completion
337 341 *
338 342 */
339 343
340 344 // task names
341 345 Task_name[TASKID_RECV] = rtems_build_name( 'R', 'E', 'C', 'V' );
342 346 Task_name[TASKID_ACTN] = rtems_build_name( 'A', 'C', 'T', 'N' );
343 347 Task_name[TASKID_SPIQ] = rtems_build_name( 'S', 'P', 'I', 'Q' );
344 348 Task_name[TASKID_LOAD] = rtems_build_name( 'L', 'O', 'A', 'D' );
345 349 Task_name[TASKID_AVF0] = rtems_build_name( 'A', 'V', 'F', '0' );
346 350 Task_name[TASKID_SWBD] = rtems_build_name( 'S', 'W', 'B', 'D' );
347 351 Task_name[TASKID_WFRM] = rtems_build_name( 'W', 'F', 'R', 'M' );
348 352 Task_name[TASKID_DUMB] = rtems_build_name( 'D', 'U', 'M', 'B' );
349 353 Task_name[TASKID_HOUS] = rtems_build_name( 'H', 'O', 'U', 'S' );
350 354 Task_name[TASKID_PRC0] = rtems_build_name( 'P', 'R', 'C', '0' );
351 355 Task_name[TASKID_CWF3] = rtems_build_name( 'C', 'W', 'F', '3' );
352 356 Task_name[TASKID_CWF2] = rtems_build_name( 'C', 'W', 'F', '2' );
353 357 Task_name[TASKID_CWF1] = rtems_build_name( 'C', 'W', 'F', '1' );
354 358 Task_name[TASKID_SEND] = rtems_build_name( 'S', 'E', 'N', 'D' );
355 359 Task_name[TASKID_LINK] = rtems_build_name( 'L', 'I', 'N', 'K' );
356 360 Task_name[TASKID_AVF1] = rtems_build_name( 'A', 'V', 'F', '1' );
357 361 Task_name[TASKID_PRC1] = rtems_build_name( 'P', 'R', 'C', '1' );
358 362 Task_name[TASKID_AVF2] = rtems_build_name( 'A', 'V', 'F', '2' );
359 363 Task_name[TASKID_PRC2] = rtems_build_name( 'P', 'R', 'C', '2' );
360 364
361 365 // rate monotonic period names
362 366 name_hk_rate_monotonic = rtems_build_name( 'H', 'O', 'U', 'S' );
363 367
364 368 misc_name[QUEUE_RECV] = rtems_build_name( 'Q', '_', 'R', 'V' );
365 369 misc_name[QUEUE_SEND] = rtems_build_name( 'Q', '_', 'S', 'D' );
366 370 misc_name[QUEUE_PRC0] = rtems_build_name( 'Q', '_', 'P', '0' );
367 371 misc_name[QUEUE_PRC1] = rtems_build_name( 'Q', '_', 'P', '1' );
368 372 misc_name[QUEUE_PRC2] = rtems_build_name( 'Q', '_', 'P', '2' );
369 373
370 374 timecode_timer_name = rtems_build_name( 'S', 'P', 'T', 'C' );
371 375 }
372 376
373 377 int create_all_tasks( void ) // create all tasks which run in the software
374 378 {
375 379 /** This function creates all RTEMS tasks used in the software.
376 380 *
377 381 * @return RTEMS directive status codes:
378 382 * - RTEMS_SUCCESSFUL - task created successfully
379 383 * - RTEMS_INVALID_ADDRESS - id is NULL
380 384 * - RTEMS_INVALID_NAME - invalid task name
381 385 * - RTEMS_INVALID_PRIORITY - invalid task priority
382 386 * - RTEMS_MP_NOT_CONFIGURED - multiprocessing not configured
383 387 * - RTEMS_TOO_MANY - too many tasks created
384 388 * - RTEMS_UNSATISFIED - not enough memory for stack/FP context
385 389 * - RTEMS_TOO_MANY - too many global objects
386 390 *
387 391 */
388 392
389 393 rtems_status_code status;
390 394
391 395 //**********
392 396 // SPACEWIRE
393 397 // RECV
394 398 status = rtems_task_create(
395 399 Task_name[TASKID_RECV], TASK_PRIORITY_RECV, RTEMS_MINIMUM_STACK_SIZE,
396 400 RTEMS_DEFAULT_MODES,
397 401 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_RECV]
398 402 );
399 403 if (status == RTEMS_SUCCESSFUL) // SEND
400 404 {
401 405 status = rtems_task_create(
402 406 Task_name[TASKID_SEND], TASK_PRIORITY_SEND, RTEMS_MINIMUM_STACK_SIZE * 2,
403 407 RTEMS_DEFAULT_MODES,
404 408 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_SEND]
405 409 );
406 410 }
407 411 if (status == RTEMS_SUCCESSFUL) // LINK
408 412 {
409 413 status = rtems_task_create(
410 414 Task_name[TASKID_LINK], TASK_PRIORITY_LINK, RTEMS_MINIMUM_STACK_SIZE,
411 415 RTEMS_DEFAULT_MODES,
412 416 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_LINK]
413 417 );
414 418 }
415 419 if (status == RTEMS_SUCCESSFUL) // ACTN
416 420 {
417 421 status = rtems_task_create(
418 422 Task_name[TASKID_ACTN], TASK_PRIORITY_ACTN, RTEMS_MINIMUM_STACK_SIZE,
419 423 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
420 424 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_ACTN]
421 425 );
422 426 }
423 427 if (status == RTEMS_SUCCESSFUL) // SPIQ
424 428 {
425 429 status = rtems_task_create(
426 430 Task_name[TASKID_SPIQ], TASK_PRIORITY_SPIQ, RTEMS_MINIMUM_STACK_SIZE,
427 431 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
428 432 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_SPIQ]
429 433 );
430 434 }
431 435
432 436 //******************
433 437 // SPECTRAL MATRICES
434 438 if (status == RTEMS_SUCCESSFUL) // AVF0
435 439 {
436 440 status = rtems_task_create(
437 441 Task_name[TASKID_AVF0], TASK_PRIORITY_AVF0, RTEMS_MINIMUM_STACK_SIZE,
438 442 RTEMS_DEFAULT_MODES,
439 443 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF0]
440 444 );
441 445 }
442 446 if (status == RTEMS_SUCCESSFUL) // PRC0
443 447 {
444 448 status = rtems_task_create(
445 449 Task_name[TASKID_PRC0], TASK_PRIORITY_PRC0, RTEMS_MINIMUM_STACK_SIZE * 2,
446 450 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
447 451 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC0]
448 452 );
449 453 }
450 454 if (status == RTEMS_SUCCESSFUL) // AVF1
451 455 {
452 456 status = rtems_task_create(
453 457 Task_name[TASKID_AVF1], TASK_PRIORITY_AVF1, RTEMS_MINIMUM_STACK_SIZE,
454 458 RTEMS_DEFAULT_MODES,
455 459 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF1]
456 460 );
457 461 }
458 462 if (status == RTEMS_SUCCESSFUL) // PRC1
459 463 {
460 464 status = rtems_task_create(
461 465 Task_name[TASKID_PRC1], TASK_PRIORITY_PRC1, RTEMS_MINIMUM_STACK_SIZE * 2,
462 466 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
463 467 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC1]
464 468 );
465 469 }
466 470 if (status == RTEMS_SUCCESSFUL) // AVF2
467 471 {
468 472 status = rtems_task_create(
469 473 Task_name[TASKID_AVF2], TASK_PRIORITY_AVF2, RTEMS_MINIMUM_STACK_SIZE,
470 474 RTEMS_DEFAULT_MODES,
471 475 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF2]
472 476 );
473 477 }
474 478 if (status == RTEMS_SUCCESSFUL) // PRC2
475 479 {
476 480 status = rtems_task_create(
477 481 Task_name[TASKID_PRC2], TASK_PRIORITY_PRC2, RTEMS_MINIMUM_STACK_SIZE * 2,
478 482 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
479 483 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC2]
480 484 );
481 485 }
482 486
483 487 //****************
484 488 // WAVEFORM PICKER
485 489 if (status == RTEMS_SUCCESSFUL) // WFRM
486 490 {
487 491 status = rtems_task_create(
488 492 Task_name[TASKID_WFRM], TASK_PRIORITY_WFRM, RTEMS_MINIMUM_STACK_SIZE,
489 493 RTEMS_DEFAULT_MODES,
490 494 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_WFRM]
491 495 );
492 496 }
493 497 if (status == RTEMS_SUCCESSFUL) // CWF3
494 498 {
495 499 status = rtems_task_create(
496 500 Task_name[TASKID_CWF3], TASK_PRIORITY_CWF3, RTEMS_MINIMUM_STACK_SIZE,
497 501 RTEMS_DEFAULT_MODES,
498 502 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF3]
499 503 );
500 504 }
501 505 if (status == RTEMS_SUCCESSFUL) // CWF2
502 506 {
503 507 status = rtems_task_create(
504 508 Task_name[TASKID_CWF2], TASK_PRIORITY_CWF2, RTEMS_MINIMUM_STACK_SIZE,
505 509 RTEMS_DEFAULT_MODES,
506 510 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF2]
507 511 );
508 512 }
509 513 if (status == RTEMS_SUCCESSFUL) // CWF1
510 514 {
511 515 status = rtems_task_create(
512 516 Task_name[TASKID_CWF1], TASK_PRIORITY_CWF1, RTEMS_MINIMUM_STACK_SIZE,
513 517 RTEMS_DEFAULT_MODES,
514 518 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF1]
515 519 );
516 520 }
517 521 if (status == RTEMS_SUCCESSFUL) // SWBD
518 522 {
519 523 status = rtems_task_create(
520 524 Task_name[TASKID_SWBD], TASK_PRIORITY_SWBD, RTEMS_MINIMUM_STACK_SIZE,
521 525 RTEMS_DEFAULT_MODES,
522 526 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_SWBD]
523 527 );
524 528 }
525 529
526 530 //*****
527 531 // MISC
528 532 if (status == RTEMS_SUCCESSFUL) // LOAD
529 533 {
530 534 status = rtems_task_create(
531 535 Task_name[TASKID_LOAD], TASK_PRIORITY_LOAD, RTEMS_MINIMUM_STACK_SIZE,
532 536 RTEMS_DEFAULT_MODES,
533 537 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_LOAD]
534 538 );
535 539 }
536 540 if (status == RTEMS_SUCCESSFUL) // DUMB
537 541 {
538 542 status = rtems_task_create(
539 543 Task_name[TASKID_DUMB], TASK_PRIORITY_DUMB, RTEMS_MINIMUM_STACK_SIZE,
540 544 RTEMS_DEFAULT_MODES,
541 545 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_DUMB]
542 546 );
543 547 }
544 548 if (status == RTEMS_SUCCESSFUL) // HOUS
545 549 {
546 550 status = rtems_task_create(
547 551 Task_name[TASKID_HOUS], TASK_PRIORITY_HOUS, RTEMS_MINIMUM_STACK_SIZE,
548 552 RTEMS_DEFAULT_MODES,
549 553 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_HOUS]
550 554 );
551 555 }
552 556
553 557 return status;
554 558 }
555 559
556 560 int start_recv_send_tasks( void )
557 561 {
558 562 rtems_status_code status;
559 563
560 564 status = rtems_task_start( Task_id[TASKID_RECV], recv_task, 1 );
561 565 if (status!=RTEMS_SUCCESSFUL) {
562 566 BOOT_PRINTF("in INIT *** Error starting TASK_RECV\n")
563 567 }
564 568
565 569 if (status == RTEMS_SUCCESSFUL) // SEND
566 570 {
567 571 status = rtems_task_start( Task_id[TASKID_SEND], send_task, 1 );
568 572 if (status!=RTEMS_SUCCESSFUL) {
569 573 BOOT_PRINTF("in INIT *** Error starting TASK_SEND\n")
570 574 }
571 575 }
572 576
573 577 return status;
574 578 }
575 579
576 580 int start_all_tasks( void ) // start all tasks except SEND RECV and HOUS
577 581 {
578 582 /** This function starts all RTEMS tasks used in the software.
579 583 *
580 584 * @return RTEMS directive status codes:
581 585 * - RTEMS_SUCCESSFUL - ask started successfully
582 586 * - RTEMS_INVALID_ADDRESS - invalid task entry point
583 587 * - RTEMS_INVALID_ID - invalid task id
584 588 * - RTEMS_INCORRECT_STATE - task not in the dormant state
585 589 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot start remote task
586 590 *
587 591 */
588 592 // starts all the tasks fot eh flight software
589 593
590 594 rtems_status_code status;
591 595
592 596 //**********
593 597 // SPACEWIRE
594 598 status = rtems_task_start( Task_id[TASKID_SPIQ], spiq_task, 1 );
595 599 if (status!=RTEMS_SUCCESSFUL) {
596 600 BOOT_PRINTF("in INIT *** Error starting TASK_SPIQ\n")
597 601 }
598 602
599 603 if (status == RTEMS_SUCCESSFUL) // LINK
600 604 {
601 605 status = rtems_task_start( Task_id[TASKID_LINK], link_task, 1 );
602 606 if (status!=RTEMS_SUCCESSFUL) {
603 607 BOOT_PRINTF("in INIT *** Error starting TASK_LINK\n")
604 608 }
605 609 }
606 610
607 611 if (status == RTEMS_SUCCESSFUL) // ACTN
608 612 {
609 613 status = rtems_task_start( Task_id[TASKID_ACTN], actn_task, 1 );
610 614 if (status!=RTEMS_SUCCESSFUL) {
611 615 BOOT_PRINTF("in INIT *** Error starting TASK_ACTN\n")
612 616 }
613 617 }
614 618
615 619 //******************
616 620 // SPECTRAL MATRICES
617 621 if (status == RTEMS_SUCCESSFUL) // AVF0
618 622 {
619 623 status = rtems_task_start( Task_id[TASKID_AVF0], avf0_task, LFR_MODE_STANDBY );
620 624 if (status!=RTEMS_SUCCESSFUL) {
621 625 BOOT_PRINTF("in INIT *** Error starting TASK_AVF0\n")
622 626 }
623 627 }
624 628 if (status == RTEMS_SUCCESSFUL) // PRC0
625 629 {
626 630 status = rtems_task_start( Task_id[TASKID_PRC0], prc0_task, LFR_MODE_STANDBY );
627 631 if (status!=RTEMS_SUCCESSFUL) {
628 632 BOOT_PRINTF("in INIT *** Error starting TASK_PRC0\n")
629 633 }
630 634 }
631 635 if (status == RTEMS_SUCCESSFUL) // AVF1
632 636 {
633 637 status = rtems_task_start( Task_id[TASKID_AVF1], avf1_task, LFR_MODE_STANDBY );
634 638 if (status!=RTEMS_SUCCESSFUL) {
635 639 BOOT_PRINTF("in INIT *** Error starting TASK_AVF1\n")
636 640 }
637 641 }
638 642 if (status == RTEMS_SUCCESSFUL) // PRC1
639 643 {
640 644 status = rtems_task_start( Task_id[TASKID_PRC1], prc1_task, LFR_MODE_STANDBY );
641 645 if (status!=RTEMS_SUCCESSFUL) {
642 646 BOOT_PRINTF("in INIT *** Error starting TASK_PRC1\n")
643 647 }
644 648 }
645 649 if (status == RTEMS_SUCCESSFUL) // AVF2
646 650 {
647 651 status = rtems_task_start( Task_id[TASKID_AVF2], avf2_task, 1 );
648 652 if (status!=RTEMS_SUCCESSFUL) {
649 653 BOOT_PRINTF("in INIT *** Error starting TASK_AVF2\n")
650 654 }
651 655 }
652 656 if (status == RTEMS_SUCCESSFUL) // PRC2
653 657 {
654 658 status = rtems_task_start( Task_id[TASKID_PRC2], prc2_task, 1 );
655 659 if (status!=RTEMS_SUCCESSFUL) {
656 660 BOOT_PRINTF("in INIT *** Error starting TASK_PRC2\n")
657 661 }
658 662 }
659 663
660 664 //****************
661 665 // WAVEFORM PICKER
662 666 if (status == RTEMS_SUCCESSFUL) // WFRM
663 667 {
664 668 status = rtems_task_start( Task_id[TASKID_WFRM], wfrm_task, 1 );
665 669 if (status!=RTEMS_SUCCESSFUL) {
666 670 BOOT_PRINTF("in INIT *** Error starting TASK_WFRM\n")
667 671 }
668 672 }
669 673 if (status == RTEMS_SUCCESSFUL) // CWF3
670 674 {
671 675 status = rtems_task_start( Task_id[TASKID_CWF3], cwf3_task, 1 );
672 676 if (status!=RTEMS_SUCCESSFUL) {
673 677 BOOT_PRINTF("in INIT *** Error starting TASK_CWF3\n")
674 678 }
675 679 }
676 680 if (status == RTEMS_SUCCESSFUL) // CWF2
677 681 {
678 682 status = rtems_task_start( Task_id[TASKID_CWF2], cwf2_task, 1 );
679 683 if (status!=RTEMS_SUCCESSFUL) {
680 684 BOOT_PRINTF("in INIT *** Error starting TASK_CWF2\n")
681 685 }
682 686 }
683 687 if (status == RTEMS_SUCCESSFUL) // CWF1
684 688 {
685 689 status = rtems_task_start( Task_id[TASKID_CWF1], cwf1_task, 1 );
686 690 if (status!=RTEMS_SUCCESSFUL) {
687 691 BOOT_PRINTF("in INIT *** Error starting TASK_CWF1\n")
688 692 }
689 693 }
690 694 if (status == RTEMS_SUCCESSFUL) // SWBD
691 695 {
692 696 status = rtems_task_start( Task_id[TASKID_SWBD], swbd_task, 1 );
693 697 if (status!=RTEMS_SUCCESSFUL) {
694 698 BOOT_PRINTF("in INIT *** Error starting TASK_SWBD\n")
695 699 }
696 700 }
697 701
698 702 //*****
699 703 // MISC
700 704 if (status == RTEMS_SUCCESSFUL) // HOUS
701 705 {
702 706 status = rtems_task_start( Task_id[TASKID_HOUS], hous_task, 1 );
703 707 if (status!=RTEMS_SUCCESSFUL) {
704 708 BOOT_PRINTF("in INIT *** Error starting TASK_HOUS\n")
705 709 }
706 710 }
707 711 if (status == RTEMS_SUCCESSFUL) // DUMB
708 712 {
709 713 status = rtems_task_start( Task_id[TASKID_DUMB], dumb_task, 1 );
710 714 if (status!=RTEMS_SUCCESSFUL) {
711 715 BOOT_PRINTF("in INIT *** Error starting TASK_DUMB\n")
712 716 }
713 717 }
714 718 if (status == RTEMS_SUCCESSFUL) // LOAD
715 719 {
716 720 status = rtems_task_start( Task_id[TASKID_LOAD], load_task, 1 );
717 721 if (status!=RTEMS_SUCCESSFUL) {
718 722 BOOT_PRINTF("in INIT *** Error starting TASK_LOAD\n")
719 723 }
720 724 }
721 725
722 726 return status;
723 727 }
724 728
725 729 rtems_status_code create_message_queues( void ) // create the two message queues used in the software
726 730 {
727 731 rtems_status_code status_recv;
728 732 rtems_status_code status_send;
729 733 rtems_status_code status_q_p0;
730 734 rtems_status_code status_q_p1;
731 735 rtems_status_code status_q_p2;
732 736 rtems_status_code ret;
733 737 rtems_id queue_id;
734 738
735 739 //****************************************
736 740 // create the queue for handling valid TCs
737 741 status_recv = rtems_message_queue_create( misc_name[QUEUE_RECV],
738 742 MSG_QUEUE_COUNT_RECV, CCSDS_TC_PKT_MAX_SIZE,
739 743 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
740 744 if ( status_recv != RTEMS_SUCCESSFUL ) {
741 745 PRINTF1("in create_message_queues *** ERR creating QUEU queue, %d\n", status_recv)
742 746 }
743 747
744 748 //************************************************
745 749 // create the queue for handling TM packet sending
746 750 status_send = rtems_message_queue_create( misc_name[QUEUE_SEND],
747 751 MSG_QUEUE_COUNT_SEND, MSG_QUEUE_SIZE_SEND,
748 752 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
749 753 if ( status_send != RTEMS_SUCCESSFUL ) {
750 754 PRINTF1("in create_message_queues *** ERR creating PKTS queue, %d\n", status_send)
751 755 }
752 756
753 757 //*****************************************************************************
754 758 // create the queue for handling averaged spectral matrices for processing @ f0
755 759 status_q_p0 = rtems_message_queue_create( misc_name[QUEUE_PRC0],
756 760 MSG_QUEUE_COUNT_PRC0, MSG_QUEUE_SIZE_PRC0,
757 761 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
758 762 if ( status_q_p0 != RTEMS_SUCCESSFUL ) {
759 763 PRINTF1("in create_message_queues *** ERR creating Q_P0 queue, %d\n", status_q_p0)
760 764 }
761 765
762 766 //*****************************************************************************
763 767 // create the queue for handling averaged spectral matrices for processing @ f1
764 768 status_q_p1 = rtems_message_queue_create( misc_name[QUEUE_PRC1],
765 769 MSG_QUEUE_COUNT_PRC1, MSG_QUEUE_SIZE_PRC1,
766 770 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
767 771 if ( status_q_p1 != RTEMS_SUCCESSFUL ) {
768 772 PRINTF1("in create_message_queues *** ERR creating Q_P1 queue, %d\n", status_q_p1)
769 773 }
770 774
771 775 //*****************************************************************************
772 776 // create the queue for handling averaged spectral matrices for processing @ f2
773 777 status_q_p2 = rtems_message_queue_create( misc_name[QUEUE_PRC2],
774 778 MSG_QUEUE_COUNT_PRC2, MSG_QUEUE_SIZE_PRC2,
775 779 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
776 780 if ( status_q_p2 != RTEMS_SUCCESSFUL ) {
777 781 PRINTF1("in create_message_queues *** ERR creating Q_P2 queue, %d\n", status_q_p2)
778 782 }
779 783
780 784 if ( status_recv != RTEMS_SUCCESSFUL )
781 785 {
782 786 ret = status_recv;
783 787 }
784 788 else if( status_send != RTEMS_SUCCESSFUL )
785 789 {
786 790 ret = status_send;
787 791 }
788 792 else if( status_q_p0 != RTEMS_SUCCESSFUL )
789 793 {
790 794 ret = status_q_p0;
791 795 }
792 796 else if( status_q_p1 != RTEMS_SUCCESSFUL )
793 797 {
794 798 ret = status_q_p1;
795 799 }
796 800 else
797 801 {
798 802 ret = status_q_p2;
799 803 }
800 804
801 805 return ret;
802 806 }
803 807
804 808 rtems_status_code create_timecode_timer( void )
805 809 {
806 810 rtems_status_code status;
807 811
808 812 status = rtems_timer_create( timecode_timer_name, &timecode_timer_id );
809 813
810 814 if ( status != RTEMS_SUCCESSFUL )
811 815 {
812 816 PRINTF1("in create_timer_timecode *** ERR creating SPTC timer, %d\n", status)
813 817 }
814 818 else
815 819 {
816 820 PRINTF("in create_timer_timecode *** OK creating SPTC timer\n")
817 821 }
818 822
819 823 return status;
820 824 }
821 825
822 826 rtems_status_code get_message_queue_id_send( rtems_id *queue_id )
823 827 {
824 828 rtems_status_code status;
825 829 rtems_name queue_name;
826 830
827 831 queue_name = rtems_build_name( 'Q', '_', 'S', 'D' );
828 832
829 833 status = rtems_message_queue_ident( queue_name, 0, queue_id );
830 834
831 835 return status;
832 836 }
833 837
834 838 rtems_status_code get_message_queue_id_recv( rtems_id *queue_id )
835 839 {
836 840 rtems_status_code status;
837 841 rtems_name queue_name;
838 842
839 843 queue_name = rtems_build_name( 'Q', '_', 'R', 'V' );
840 844
841 845 status = rtems_message_queue_ident( queue_name, 0, queue_id );
842 846
843 847 return status;
844 848 }
845 849
846 850 rtems_status_code get_message_queue_id_prc0( rtems_id *queue_id )
847 851 {
848 852 rtems_status_code status;
849 853 rtems_name queue_name;
850 854
851 855 queue_name = rtems_build_name( 'Q', '_', 'P', '0' );
852 856
853 857 status = rtems_message_queue_ident( queue_name, 0, queue_id );
854 858
855 859 return status;
856 860 }
857 861
858 862 rtems_status_code get_message_queue_id_prc1( rtems_id *queue_id )
859 863 {
860 864 rtems_status_code status;
861 865 rtems_name queue_name;
862 866
863 867 queue_name = rtems_build_name( 'Q', '_', 'P', '1' );
864 868
865 869 status = rtems_message_queue_ident( queue_name, 0, queue_id );
866 870
867 871 return status;
868 872 }
869 873
870 874 rtems_status_code get_message_queue_id_prc2( rtems_id *queue_id )
871 875 {
872 876 rtems_status_code status;
873 877 rtems_name queue_name;
874 878
875 879 queue_name = rtems_build_name( 'Q', '_', 'P', '2' );
876 880
877 881 status = rtems_message_queue_ident( queue_name, 0, queue_id );
878 882
879 883 return status;
880 884 }
881 885
882 886 void update_queue_max_count( rtems_id queue_id, unsigned char*fifo_size_max )
883 887 {
884 888 u_int32_t count;
885 889 rtems_status_code status;
886 890
887 891 status = rtems_message_queue_get_number_pending( queue_id, &count );
888 892
889 893 count = count + 1;
890 894
891 895 if (status != RTEMS_SUCCESSFUL)
892 896 {
893 897 PRINTF1("in update_queue_max_count *** ERR = %d\n", status)
894 898 }
895 899 else
896 900 {
897 901 if (count > *fifo_size_max)
898 902 {
899 903 *fifo_size_max = count;
900 904 }
901 905 }
902 906 }
903 907
904 908 void init_ring(ring_node ring[], unsigned char nbNodes, volatile int buffer[], unsigned int bufferSize )
905 909 {
906 910 unsigned char i;
907 911
908 912 //***************
909 913 // BUFFER ADDRESS
910 914 for(i=0; i<nbNodes; i++)
911 915 {
912 916 ring[i].coarseTime = 0xffffffff;
913 917 ring[i].fineTime = 0xffffffff;
914 918 ring[i].sid = 0x00;
915 919 ring[i].status = 0x00;
916 920 ring[i].buffer_address = (int) &buffer[ i * bufferSize ];
917 921 }
918 922
919 923 //*****
920 924 // NEXT
921 925 ring[ nbNodes - 1 ].next = (ring_node*) &ring[ 0 ];
922 926 for(i=0; i<nbNodes-1; i++)
923 927 {
924 928 ring[i].next = (ring_node*) &ring[ i + 1 ];
925 929 }
926 930
927 931 //*********
928 932 // PREVIOUS
929 933 ring[ 0 ].previous = (ring_node*) &ring[ nbNodes - 1 ];
930 934 for(i=1; i<nbNodes; i++)
931 935 {
932 936 ring[i].previous = (ring_node*) &ring[ i - 1 ];
933 937 }
934 938 }
@@ -1,801 +1,813
1 1 /** General usage functions and RTEMS tasks.
2 2 *
3 3 * @file
4 4 * @author P. LEROY
5 5 *
6 6 */
7 7
8 8 #include "fsw_misc.h"
9 9
10 10 void timer_configure(unsigned char timer, unsigned int clock_divider,
11 11 unsigned char interrupt_level, rtems_isr (*timer_isr)() )
12 12 {
13 13 /** This function configures a GPTIMER timer instantiated in the VHDL design.
14 14 *
15 15 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
16 16 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
17 17 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
18 18 * @param interrupt_level is the interrupt level that the timer drives.
19 19 * @param timer_isr is the interrupt subroutine that will be attached to the IRQ driven by the timer.
20 20 *
21 21 * Interrupt levels are described in the SPARC documentation sparcv8.pdf p.76
22 22 *
23 23 */
24 24
25 25 rtems_status_code status;
26 26 rtems_isr_entry old_isr_handler;
27 27
28 28 gptimer_regs->timer[timer].ctrl = 0x00; // reset the control register
29 29
30 30 status = rtems_interrupt_catch( timer_isr, interrupt_level, &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels
31 31 if (status!=RTEMS_SUCCESSFUL)
32 32 {
33 33 PRINTF("in configure_timer *** ERR rtems_interrupt_catch\n")
34 34 }
35 35
36 36 timer_set_clock_divider( timer, clock_divider);
37 37 }
38 38
39 39 void timer_start(unsigned char timer)
40 40 {
41 41 /** This function starts a GPTIMER timer.
42 42 *
43 43 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
44 44 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
45 45 *
46 46 */
47 47
48 48 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000010; // clear pending IRQ if any
49 49 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000004; // LD load value from the reload register
50 50 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000001; // EN enable the timer
51 51 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000002; // RS restart
52 52 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000008; // IE interrupt enable
53 53 }
54 54
55 55 void timer_stop(unsigned char timer)
56 56 {
57 57 /** This function stops a GPTIMER timer.
58 58 *
59 59 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
60 60 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
61 61 *
62 62 */
63 63
64 64 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & 0xfffffffe; // EN enable the timer
65 65 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & 0xffffffef; // IE interrupt enable
66 66 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000010; // clear pending IRQ if any
67 67 }
68 68
69 69 void timer_set_clock_divider(unsigned char timer, unsigned int clock_divider)
70 70 {
71 71 /** This function sets the clock divider of a GPTIMER timer.
72 72 *
73 73 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
74 74 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
75 75 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
76 76 *
77 77 */
78 78
79 79 gptimer_regs->timer[timer].reload = clock_divider; // base clock frequency is 1 MHz
80 80 }
81 81
82 82 // WATCHDOG
83 83
84 84 rtems_isr watchdog_isr( rtems_vector_number vector )
85 85 {
86 86 rtems_status_code status_code;
87 87
88 88 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_12 );
89 89
90 90 PRINTF("watchdog_isr *** this is the end, exit(0)\n");
91 91
92 92 exit(0);
93 93 }
94 94
95 95 void watchdog_configure(void)
96 96 {
97 97 /** This function configure the watchdog.
98 98 *
99 99 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
100 100 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
101 101 *
102 102 * The watchdog is a timer provided by the GPTIMER IP core of the GRLIB.
103 103 *
104 104 */
105 105
106 106 LEON_Mask_interrupt( IRQ_GPTIMER_WATCHDOG ); // mask gptimer/watchdog interrupt during configuration
107 107
108 108 timer_configure( TIMER_WATCHDOG, CLKDIV_WATCHDOG, IRQ_SPARC_GPTIMER_WATCHDOG, watchdog_isr );
109 109
110 110 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG ); // clear gptimer/watchdog interrupt
111 111 }
112 112
113 113 void watchdog_stop(void)
114 114 {
115 115 LEON_Mask_interrupt( IRQ_GPTIMER_WATCHDOG ); // mask gptimer/watchdog interrupt line
116 116 timer_stop( TIMER_WATCHDOG );
117 117 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG ); // clear gptimer/watchdog interrupt
118 118 }
119 119
120 120 void watchdog_reload(void)
121 121 {
122 122 /** This function reloads the watchdog timer counter with the timer reload value.
123 123 *
124 124 * @param void
125 125 *
126 126 * @return void
127 127 *
128 128 */
129 129
130 130 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | 0x00000004; // LD load value from the reload register
131 131 }
132 132
133 133 void watchdog_start(void)
134 134 {
135 135 /** This function starts the watchdog timer.
136 136 *
137 137 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
138 138 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
139 139 *
140 140 */
141 141
142 142 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG );
143 143
144 144 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | 0x00000010; // clear pending IRQ if any
145 145 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | 0x00000004; // LD load value from the reload register
146 146 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | 0x00000001; // EN enable the timer
147 147 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | 0x00000008; // IE interrupt enable
148 148
149 149 LEON_Unmask_interrupt( IRQ_GPTIMER_WATCHDOG );
150 150
151 151 }
152 152
153 153 int enable_apbuart_transmitter( void ) // set the bit 1, TE Transmitter Enable to 1 in the APBUART control register
154 154 {
155 155 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART;
156 156
157 157 apbuart_regs->ctrl = APBUART_CTRL_REG_MASK_TE;
158 158
159 159 return 0;
160 160 }
161 161
162 162 void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value)
163 163 {
164 164 /** This function sets the scaler reload register of the apbuart module
165 165 *
166 166 * @param regs is the address of the apbuart registers in memory
167 167 * @param value is the value that will be stored in the scaler register
168 168 *
169 169 * The value shall be set by the software to get data on the serial interface.
170 170 *
171 171 */
172 172
173 173 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) regs;
174 174
175 175 apbuart_regs->scaler = value;
176 176
177 177 BOOT_PRINTF1("OK *** apbuart port scaler reload register set to 0x%x\n", value)
178 178 }
179 179
180 180 //************
181 181 // RTEMS TASKS
182 182
183 183 rtems_task load_task(rtems_task_argument argument)
184 184 {
185 185 BOOT_PRINTF("in LOAD *** \n")
186 186
187 187 rtems_status_code status;
188 188 unsigned int i;
189 189 unsigned int j;
190 190 rtems_name name_watchdog_rate_monotonic; // name of the watchdog rate monotonic
191 191 rtems_id watchdog_period_id; // id of the watchdog rate monotonic period
192 192
193 193 name_watchdog_rate_monotonic = rtems_build_name( 'L', 'O', 'A', 'D' );
194 194
195 195 status = rtems_rate_monotonic_create( name_watchdog_rate_monotonic, &watchdog_period_id );
196 196 if( status != RTEMS_SUCCESSFUL ) {
197 197 PRINTF1( "in LOAD *** rtems_rate_monotonic_create failed with status of %d\n", status )
198 198 }
199 199
200 200 i = 0;
201 201 j = 0;
202 202
203 203 watchdog_configure();
204 204
205 205 watchdog_start();
206 206
207 207 set_sy_lfr_watchdog_enabled( true );
208 208
209 209 while(1){
210 210 status = rtems_rate_monotonic_period( watchdog_period_id, WATCHDOG_PERIOD );
211 211 watchdog_reload();
212 212 i = i + 1;
213 213 if ( i == 10 )
214 214 {
215 215 i = 0;
216 216 j = j + 1;
217 217 PRINTF1("%d\n", j)
218 218 }
219 219 #ifdef DEBUG_WATCHDOG
220 220 if (j == 3 )
221 221 {
222 222 status = rtems_task_delete(RTEMS_SELF);
223 223 }
224 224 #endif
225 225 }
226 226 }
227 227
228 228 rtems_task hous_task(rtems_task_argument argument)
229 229 {
230 230 rtems_status_code status;
231 231 rtems_status_code spare_status;
232 232 rtems_id queue_id;
233 233 rtems_rate_monotonic_period_status period_status;
234 234
235 235 status = get_message_queue_id_send( &queue_id );
236 236 if (status != RTEMS_SUCCESSFUL)
237 237 {
238 238 PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status)
239 239 }
240 240
241 241 BOOT_PRINTF("in HOUS ***\n");
242 242
243 243 if (rtems_rate_monotonic_ident( name_hk_rate_monotonic, &HK_id) != RTEMS_SUCCESSFUL) {
244 244 status = rtems_rate_monotonic_create( name_hk_rate_monotonic, &HK_id );
245 245 if( status != RTEMS_SUCCESSFUL ) {
246 246 PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status );
247 247 }
248 248 }
249 249
250 250 status = rtems_rate_monotonic_cancel(HK_id);
251 251 if( status != RTEMS_SUCCESSFUL ) {
252 252 PRINTF1( "ERR *** in HOUS *** rtems_rate_monotonic_cancel(HK_id) ***code: %d\n", status );
253 253 }
254 254 else {
255 255 DEBUG_PRINTF("OK *** in HOUS *** rtems_rate_monotonic_cancel(HK_id)\n");
256 256 }
257 257
258 258 // startup phase
259 259 status = rtems_rate_monotonic_period( HK_id, SY_LFR_TIME_SYN_TIMEOUT_in_ticks );
260 260 status = rtems_rate_monotonic_get_status( HK_id, &period_status );
261 261 DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state)
262 262 while(period_status.state != RATE_MONOTONIC_EXPIRED ) // after SY_LFR_TIME_SYN_TIMEOUT ms, starts HK anyway
263 263 {
264 264 if ((time_management_regs->coarse_time & 0x80000000) == 0x00000000) // check time synchronization
265 265 {
266 266 break; // break if LFR is synchronized
267 267 }
268 268 else
269 269 {
270 270 status = rtems_rate_monotonic_get_status( HK_id, &period_status );
271 271 // sched_yield();
272 272 status = rtems_task_wake_after( 10 ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 100 ms = 10 * 10 ms
273 273 }
274 274 }
275 275 status = rtems_rate_monotonic_cancel(HK_id);
276 276 DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state)
277 277
278 278 set_hk_lfr_reset_cause( POWER_ON );
279 279
280 280 while(1){ // launch the rate monotonic task
281 281 status = rtems_rate_monotonic_period( HK_id, HK_PERIOD );
282 282 if ( status != RTEMS_SUCCESSFUL ) {
283 283 PRINTF1( "in HOUS *** ERR period: %d\n", status);
284 284 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_6 );
285 285 }
286 286 else {
287 287 housekeeping_packet.packetSequenceControl[0] = (unsigned char) (sequenceCounterHK >> 8);
288 288 housekeeping_packet.packetSequenceControl[1] = (unsigned char) (sequenceCounterHK );
289 289 increment_seq_counter( &sequenceCounterHK );
290 290
291 291 housekeeping_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
292 292 housekeeping_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
293 293 housekeeping_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
294 294 housekeeping_packet.time[3] = (unsigned char) (time_management_regs->coarse_time);
295 295 housekeeping_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
296 296 housekeeping_packet.time[5] = (unsigned char) (time_management_regs->fine_time);
297 297
298 298 spacewire_update_hk_lfr_link_state( &housekeeping_packet.lfr_status_word[0] );
299 299
300 300 spacewire_read_statistics();
301 301
302 302 update_hk_with_grspw_stats();
303 303
304 304 set_hk_lfr_time_not_synchro();
305 305
306 306 housekeeping_packet.hk_lfr_q_sd_fifo_size_max = hk_lfr_q_sd_fifo_size_max;
307 307 housekeeping_packet.hk_lfr_q_rv_fifo_size_max = hk_lfr_q_rv_fifo_size_max;
308 308 housekeeping_packet.hk_lfr_q_p0_fifo_size_max = hk_lfr_q_p0_fifo_size_max;
309 309 housekeeping_packet.hk_lfr_q_p1_fifo_size_max = hk_lfr_q_p1_fifo_size_max;
310 310 housekeeping_packet.hk_lfr_q_p2_fifo_size_max = hk_lfr_q_p2_fifo_size_max;
311 311
312 312 housekeeping_packet.sy_lfr_common_parameters_spare = parameter_dump_packet.sy_lfr_common_parameters_spare;
313 313 housekeeping_packet.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
314 314 get_temperatures( housekeeping_packet.hk_lfr_temp_scm );
315 315 get_v_e1_e2_f3( housekeeping_packet.hk_lfr_sc_v_f3 );
316 316 get_cpu_load( (unsigned char *) &housekeeping_packet.hk_lfr_cpu_load );
317 317
318 318 hk_lfr_le_me_he_update();
319 319
320 320 housekeeping_packet.hk_lfr_sc_rw_f_flags = cp_rpw_sc_rw_f_flags;
321 321
322 322 // SEND PACKET
323 323 status = rtems_message_queue_send( queue_id, &housekeeping_packet,
324 324 PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
325 325 if (status != RTEMS_SUCCESSFUL) {
326 326 PRINTF1("in HOUS *** ERR send: %d\n", status)
327 327 }
328 328 }
329 329 }
330 330
331 331 PRINTF("in HOUS *** deleting task\n")
332 332
333 333 status = rtems_task_delete( RTEMS_SELF ); // should not return
334 334
335 335 return;
336 336 }
337 337
338 338 rtems_task dumb_task( rtems_task_argument unused )
339 339 {
340 340 /** This RTEMS taks is used to print messages without affecting the general behaviour of the software.
341 341 *
342 342 * @param unused is the starting argument of the RTEMS task
343 343 *
344 344 * The DUMB taks waits for RTEMS events and print messages depending on the incoming events.
345 345 *
346 346 */
347 347
348 348 unsigned int i;
349 349 unsigned int intEventOut;
350 350 unsigned int coarse_time = 0;
351 351 unsigned int fine_time = 0;
352 352 rtems_event_set event_out;
353 353
354 354 char *DumbMessages[15] = {"in DUMB *** default", // RTEMS_EVENT_0
355 355 "in DUMB *** timecode_irq_handler", // RTEMS_EVENT_1
356 356 "in DUMB *** f3 buffer changed", // RTEMS_EVENT_2
357 357 "in DUMB *** in SMIQ *** Error sending event to AVF0", // RTEMS_EVENT_3
358 358 "in DUMB *** spectral_matrices_isr *** Error sending event to SMIQ", // RTEMS_EVENT_4
359 359 "in DUMB *** waveforms_simulator_isr", // RTEMS_EVENT_5
360 360 "VHDL SM *** two buffers f0 ready", // RTEMS_EVENT_6
361 361 "ready for dump", // RTEMS_EVENT_7
362 362 "VHDL ERR *** spectral matrix", // RTEMS_EVENT_8
363 363 "tick", // RTEMS_EVENT_9
364 364 "VHDL ERR *** waveform picker", // RTEMS_EVENT_10
365 365 "VHDL ERR *** unexpected ready matrix values", // RTEMS_EVENT_11
366 366 "WATCHDOG timer", // RTEMS_EVENT_12
367 367 "TIMECODE timer", // RTEMS_EVENT_13
368 368 "TIMECODE ISR" // RTEMS_EVENT_14
369 369 };
370 370
371 371 BOOT_PRINTF("in DUMB *** \n")
372 372
373 373 while(1){
374 374 rtems_event_receive(RTEMS_EVENT_0 | RTEMS_EVENT_1 | RTEMS_EVENT_2 | RTEMS_EVENT_3
375 375 | RTEMS_EVENT_4 | RTEMS_EVENT_5 | RTEMS_EVENT_6 | RTEMS_EVENT_7
376 376 | RTEMS_EVENT_8 | RTEMS_EVENT_9 | RTEMS_EVENT_12 | RTEMS_EVENT_13
377 377 | RTEMS_EVENT_14,
378 378 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT
379 379 intEventOut = (unsigned int) event_out;
380 380 for ( i=0; i<32; i++)
381 381 {
382 382 if ( ((intEventOut >> i) & 0x0001) != 0)
383 383 {
384 384 coarse_time = time_management_regs->coarse_time;
385 385 fine_time = time_management_regs->fine_time;
386 386 if (i==12)
387 387 {
388 388 PRINTF1("%s\n", DumbMessages[12])
389 389 }
390 390 if (i==13)
391 391 {
392 392 PRINTF1("%s\n", DumbMessages[13])
393 393 }
394 394 if (i==14)
395 395 {
396 396 PRINTF1("%s\n", DumbMessages[1])
397 397 }
398 398 }
399 399 }
400 400 }
401 401 }
402 402
403 403 //*****************************
404 404 // init housekeeping parameters
405 405
406 406 void init_housekeeping_parameters( void )
407 407 {
408 408 /** This function initialize the housekeeping_packet global variable with default values.
409 409 *
410 410 */
411 411
412 412 unsigned int i = 0;
413 413 unsigned char *parameters;
414 414 unsigned char sizeOfHK;
415 415
416 416 sizeOfHK = sizeof( Packet_TM_LFR_HK_t );
417 417
418 418 parameters = (unsigned char*) &housekeeping_packet;
419 419
420 420 for(i = 0; i< sizeOfHK; i++)
421 421 {
422 422 parameters[i] = 0x00;
423 423 }
424 424
425 425 housekeeping_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
426 426 housekeeping_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
427 427 housekeeping_packet.reserved = DEFAULT_RESERVED;
428 428 housekeeping_packet.userApplication = CCSDS_USER_APP;
429 429 housekeeping_packet.packetID[0] = (unsigned char) (APID_TM_HK >> 8);
430 430 housekeeping_packet.packetID[1] = (unsigned char) (APID_TM_HK);
431 431 housekeeping_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
432 432 housekeeping_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
433 433 housekeeping_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> 8);
434 434 housekeeping_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK );
435 435 housekeeping_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
436 436 housekeeping_packet.serviceType = TM_TYPE_HK;
437 437 housekeeping_packet.serviceSubType = TM_SUBTYPE_HK;
438 438 housekeeping_packet.destinationID = TM_DESTINATION_ID_GROUND;
439 439 housekeeping_packet.sid = SID_HK;
440 440
441 441 // init status word
442 442 housekeeping_packet.lfr_status_word[0] = DEFAULT_STATUS_WORD_BYTE0;
443 443 housekeeping_packet.lfr_status_word[1] = DEFAULT_STATUS_WORD_BYTE1;
444 444 // init software version
445 445 housekeeping_packet.lfr_sw_version[0] = SW_VERSION_N1;
446 446 housekeeping_packet.lfr_sw_version[1] = SW_VERSION_N2;
447 447 housekeeping_packet.lfr_sw_version[2] = SW_VERSION_N3;
448 448 housekeeping_packet.lfr_sw_version[3] = SW_VERSION_N4;
449 449 // init fpga version
450 450 parameters = (unsigned char *) (REGS_ADDR_VHDL_VERSION);
451 451 housekeeping_packet.lfr_fpga_version[0] = parameters[1]; // n1
452 452 housekeeping_packet.lfr_fpga_version[1] = parameters[2]; // n2
453 453 housekeeping_packet.lfr_fpga_version[2] = parameters[3]; // n3
454 454
455 455 housekeeping_packet.hk_lfr_q_sd_fifo_size = MSG_QUEUE_COUNT_SEND;
456 456 housekeeping_packet.hk_lfr_q_rv_fifo_size = MSG_QUEUE_COUNT_RECV;
457 457 housekeeping_packet.hk_lfr_q_p0_fifo_size = MSG_QUEUE_COUNT_PRC0;
458 458 housekeeping_packet.hk_lfr_q_p1_fifo_size = MSG_QUEUE_COUNT_PRC1;
459 459 housekeeping_packet.hk_lfr_q_p2_fifo_size = MSG_QUEUE_COUNT_PRC2;
460 460 }
461 461
462 462 void increment_seq_counter( unsigned short *packetSequenceControl )
463 463 {
464 464 /** This function increment the sequence counter passes in argument.
465 465 *
466 466 * The increment does not affect the grouping flag. In case of an overflow, the counter is reset to 0.
467 467 *
468 468 */
469 469
470 470 unsigned short segmentation_grouping_flag;
471 471 unsigned short sequence_cnt;
472 472
473 473 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << 8; // keep bits 7 downto 6
474 474 sequence_cnt = (*packetSequenceControl) & 0x3fff; // [0011 1111 1111 1111]
475 475
476 476 if ( sequence_cnt < SEQ_CNT_MAX)
477 477 {
478 478 sequence_cnt = sequence_cnt + 1;
479 479 }
480 480 else
481 481 {
482 482 sequence_cnt = 0;
483 483 }
484 484
485 485 *packetSequenceControl = segmentation_grouping_flag | sequence_cnt ;
486 486 }
487 487
488 488 void getTime( unsigned char *time)
489 489 {
490 490 /** This function write the current local time in the time buffer passed in argument.
491 491 *
492 492 */
493 493
494 494 time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
495 495 time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
496 496 time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
497 497 time[3] = (unsigned char) (time_management_regs->coarse_time);
498 498 time[4] = (unsigned char) (time_management_regs->fine_time>>8);
499 499 time[5] = (unsigned char) (time_management_regs->fine_time);
500 500 }
501 501
502 502 unsigned long long int getTimeAsUnsignedLongLongInt( )
503 503 {
504 504 /** This function write the current local time in the time buffer passed in argument.
505 505 *
506 506 */
507 507 unsigned long long int time;
508 508
509 509 time = ( (unsigned long long int) (time_management_regs->coarse_time & 0x7fffffff) << 16 )
510 510 + time_management_regs->fine_time;
511 511
512 512 return time;
513 513 }
514 514
515 515 void send_dumb_hk( void )
516 516 {
517 517 Packet_TM_LFR_HK_t dummy_hk_packet;
518 518 unsigned char *parameters;
519 519 unsigned int i;
520 520 rtems_id queue_id;
521 521
522 522 dummy_hk_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
523 523 dummy_hk_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
524 524 dummy_hk_packet.reserved = DEFAULT_RESERVED;
525 525 dummy_hk_packet.userApplication = CCSDS_USER_APP;
526 526 dummy_hk_packet.packetID[0] = (unsigned char) (APID_TM_HK >> 8);
527 527 dummy_hk_packet.packetID[1] = (unsigned char) (APID_TM_HK);
528 528 dummy_hk_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
529 529 dummy_hk_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
530 530 dummy_hk_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> 8);
531 531 dummy_hk_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK );
532 532 dummy_hk_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
533 533 dummy_hk_packet.serviceType = TM_TYPE_HK;
534 534 dummy_hk_packet.serviceSubType = TM_SUBTYPE_HK;
535 535 dummy_hk_packet.destinationID = TM_DESTINATION_ID_GROUND;
536 536 dummy_hk_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
537 537 dummy_hk_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
538 538 dummy_hk_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
539 539 dummy_hk_packet.time[3] = (unsigned char) (time_management_regs->coarse_time);
540 540 dummy_hk_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
541 541 dummy_hk_packet.time[5] = (unsigned char) (time_management_regs->fine_time);
542 542 dummy_hk_packet.sid = SID_HK;
543 543
544 544 // init status word
545 545 dummy_hk_packet.lfr_status_word[0] = 0xff;
546 546 dummy_hk_packet.lfr_status_word[1] = 0xff;
547 547 // init software version
548 548 dummy_hk_packet.lfr_sw_version[0] = SW_VERSION_N1;
549 549 dummy_hk_packet.lfr_sw_version[1] = SW_VERSION_N2;
550 550 dummy_hk_packet.lfr_sw_version[2] = SW_VERSION_N3;
551 551 dummy_hk_packet.lfr_sw_version[3] = SW_VERSION_N4;
552 552 // init fpga version
553 553 parameters = (unsigned char *) (REGS_ADDR_WAVEFORM_PICKER + 0xb0);
554 554 dummy_hk_packet.lfr_fpga_version[0] = parameters[1]; // n1
555 555 dummy_hk_packet.lfr_fpga_version[1] = parameters[2]; // n2
556 556 dummy_hk_packet.lfr_fpga_version[2] = parameters[3]; // n3
557 557
558 558 parameters = (unsigned char *) &dummy_hk_packet.hk_lfr_cpu_load;
559 559
560 560 for (i=0; i<100; i++)
561 561 {
562 562 parameters[i] = 0xff;
563 563 }
564 564
565 565 get_message_queue_id_send( &queue_id );
566 566
567 567 rtems_message_queue_send( queue_id, &dummy_hk_packet,
568 568 PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
569 569 }
570 570
571 571 void get_temperatures( unsigned char *temperatures )
572 572 {
573 573 unsigned char* temp_scm_ptr;
574 574 unsigned char* temp_pcb_ptr;
575 575 unsigned char* temp_fpga_ptr;
576 576
577 577 // SEL1 SEL0
578 578 // 0 0 => PCB
579 579 // 0 1 => FPGA
580 580 // 1 0 => SCM
581 581
582 582 temp_scm_ptr = (unsigned char *) &time_management_regs->temp_scm;
583 583 temp_pcb_ptr = (unsigned char *) &time_management_regs->temp_pcb;
584 584 temp_fpga_ptr = (unsigned char *) &time_management_regs->temp_fpga;
585 585
586 586 temperatures[0] = temp_scm_ptr[2];
587 587 temperatures[1] = temp_scm_ptr[3];
588 588 temperatures[2] = temp_pcb_ptr[2];
589 589 temperatures[3] = temp_pcb_ptr[3];
590 590 temperatures[4] = temp_fpga_ptr[2];
591 591 temperatures[5] = temp_fpga_ptr[3];
592 592 }
593 593
594 594 void get_v_e1_e2_f3( unsigned char *spacecraft_potential )
595 595 {
596 596 unsigned char* v_ptr;
597 597 unsigned char* e1_ptr;
598 598 unsigned char* e2_ptr;
599 599
600 600 v_ptr = (unsigned char *) &waveform_picker_regs->v;
601 601 e1_ptr = (unsigned char *) &waveform_picker_regs->e1;
602 602 e2_ptr = (unsigned char *) &waveform_picker_regs->e2;
603 603
604 604 spacecraft_potential[0] = v_ptr[2];
605 605 spacecraft_potential[1] = v_ptr[3];
606 606 spacecraft_potential[2] = e1_ptr[2];
607 607 spacecraft_potential[3] = e1_ptr[3];
608 608 spacecraft_potential[4] = e2_ptr[2];
609 609 spacecraft_potential[5] = e2_ptr[3];
610 610 }
611 611
612 612 void get_cpu_load( unsigned char *resource_statistics )
613 613 {
614 614 unsigned char cpu_load;
615 615
616 616 cpu_load = lfr_rtems_cpu_usage_report();
617 617
618 618 // HK_LFR_CPU_LOAD
619 619 resource_statistics[0] = cpu_load;
620 620
621 621 // HK_LFR_CPU_LOAD_MAX
622 622 if (cpu_load > resource_statistics[1])
623 623 {
624 624 resource_statistics[1] = cpu_load;
625 625 }
626 626
627 627 // CPU_LOAD_AVE
628 628 resource_statistics[2] = 0;
629 629
630 630 #ifndef PRINT_TASK_STATISTICS
631 631 rtems_cpu_usage_reset();
632 632 #endif
633 633
634 634 }
635 635
636 636 void set_hk_lfr_sc_potential_flag( bool state )
637 637 {
638 638 if (state == true)
639 639 {
640 640 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] | 0x40; // [0100 0000]
641 641 }
642 642 else
643 643 {
644 644 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] & 0xbf; // [1011 1111]
645 645 }
646 646 }
647 647
648 void set_sy_lfr_pas_filter_enabled( bool state )
649 {
650 if (state == true)
651 {
652 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] | 0x20; // [0010 0000]
653 }
654 else
655 {
656 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] & 0xdf; // [1101 1111]
657 }
658 }
659
648 660 void set_sy_lfr_watchdog_enabled( bool state )
649 661 {
650 662 if (state == true)
651 663 {
652 664 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] | 0x10; // [0001 0000]
653 665 }
654 666 else
655 667 {
656 668 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] & 0xef; // [1110 1111]
657 669 }
658 670 }
659 671
660 672 void set_hk_lfr_calib_enable( bool state )
661 673 {
662 674 if (state == true)
663 675 {
664 676 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] | 0x08; // [0000 1000]
665 677 }
666 678 else
667 679 {
668 680 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] & 0xf7; // [1111 0111]
669 681 }
670 682 }
671 683
672 684 void set_hk_lfr_reset_cause( enum lfr_reset_cause_t lfr_reset_cause )
673 685 {
674 686 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] & 0xf8; // [1111 1000]
675 687
676 688 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1]
677 689 | (lfr_reset_cause & 0x07 ); // [0000 0111]
678 690
679 691 }
680 692
681 693 void hk_lfr_le_me_he_update()
682 694 {
683 695 unsigned int hk_lfr_le_cnt;
684 696 unsigned int hk_lfr_me_cnt;
685 697 unsigned int hk_lfr_he_cnt;
686 698 unsigned int current_hk_lfr_le_cnt;
687 699 unsigned int current_hk_lfr_me_cnt;
688 700 unsigned int current_hk_lfr_he_cnt;
689 701
690 702 hk_lfr_le_cnt = 0;
691 703 hk_lfr_me_cnt = 0;
692 704 hk_lfr_he_cnt = 0;
693 705 current_hk_lfr_le_cnt = ((unsigned int) housekeeping_packet.hk_lfr_le_cnt[0]) * 256 + housekeeping_packet.hk_lfr_le_cnt[1];
694 706 current_hk_lfr_me_cnt = ((unsigned int) housekeeping_packet.hk_lfr_me_cnt[0]) * 256 + housekeeping_packet.hk_lfr_me_cnt[1];
695 707 current_hk_lfr_he_cnt = ((unsigned int) housekeeping_packet.hk_lfr_he_cnt[0]) * 256 + housekeeping_packet.hk_lfr_he_cnt[1];
696 708
697 709 //update the low severity error counter
698 710 hk_lfr_le_cnt =
699 711 current_hk_lfr_le_cnt
700 712 + housekeeping_packet.hk_lfr_dpu_spw_parity
701 713 + housekeeping_packet.hk_lfr_dpu_spw_disconnect
702 714 + housekeeping_packet.hk_lfr_dpu_spw_escape
703 715 + housekeeping_packet.hk_lfr_dpu_spw_credit
704 716 + housekeeping_packet.hk_lfr_dpu_spw_write_sync
705 717 + housekeeping_packet.hk_lfr_timecode_erroneous
706 718 + housekeeping_packet.hk_lfr_timecode_missing
707 719 + housekeeping_packet.hk_lfr_timecode_invalid
708 720 + housekeeping_packet.hk_lfr_time_timecode_it
709 721 + housekeeping_packet.hk_lfr_time_not_synchro
710 722 + housekeeping_packet.hk_lfr_time_timecode_ctr
711 723 + housekeeping_packet.hk_lfr_ahb_correctable;
712 724 // housekeeping_packet.hk_lfr_dpu_spw_rx_ahb => not handled by the grspw driver
713 725 // housekeeping_packet.hk_lfr_dpu_spw_tx_ahb => not handled by the grspw driver
714 726
715 727 //update the medium severity error counter
716 728 hk_lfr_me_cnt =
717 729 current_hk_lfr_me_cnt
718 730 + housekeeping_packet.hk_lfr_dpu_spw_early_eop
719 731 + housekeeping_packet.hk_lfr_dpu_spw_invalid_addr
720 732 + housekeeping_packet.hk_lfr_dpu_spw_eep
721 733 + housekeeping_packet.hk_lfr_dpu_spw_rx_too_big;
722 734
723 735 //update the high severity error counter
724 736 hk_lfr_he_cnt = 0;
725 737
726 738 // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers
727 739 // LE
728 740 housekeeping_packet.hk_lfr_le_cnt[0] = (unsigned char) ((hk_lfr_le_cnt & 0xff00) >> 8);
729 741 housekeeping_packet.hk_lfr_le_cnt[1] = (unsigned char) (hk_lfr_le_cnt & 0x00ff);
730 742 // ME
731 743 housekeeping_packet.hk_lfr_me_cnt[0] = (unsigned char) ((hk_lfr_me_cnt & 0xff00) >> 8);
732 744 housekeeping_packet.hk_lfr_me_cnt[1] = (unsigned char) (hk_lfr_me_cnt & 0x00ff);
733 745 // HE
734 746 housekeeping_packet.hk_lfr_he_cnt[0] = (unsigned char) ((hk_lfr_he_cnt & 0xff00) >> 8);
735 747 housekeeping_packet.hk_lfr_he_cnt[1] = (unsigned char) (hk_lfr_he_cnt & 0x00ff);
736 748
737 749 }
738 750
739 751 void set_hk_lfr_time_not_synchro()
740 752 {
741 753 static unsigned char synchroLost = 1;
742 754 int synchronizationBit;
743 755
744 756 // get the synchronization bit
745 757 synchronizationBit = (time_management_regs->coarse_time & 0x80000000) >> 31; // 1000 0000 0000 0000
746 758
747 759 switch (synchronizationBit)
748 760 {
749 761 case 0:
750 762 if (synchroLost == 1)
751 763 {
752 764 synchroLost = 0;
753 765 }
754 766 break;
755 767 case 1:
756 768 if (synchroLost == 0 )
757 769 {
758 770 synchroLost = 1;
759 771 increase_unsigned_char_counter(&housekeeping_packet.hk_lfr_time_not_synchro);
760 772 update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_NOT_SYNCHRO );
761 773 }
762 774 break;
763 775 default:
764 776 PRINTF1("in hk_lfr_time_not_synchro *** unexpected value for synchronizationBit = %d\n", synchronizationBit);
765 777 break;
766 778 }
767 779
768 780 }
769 781
770 782 void set_hk_lfr_ahb_correctable() // CRITICITY L
771 783 {
772 784 /** This function builds the error counter hk_lfr_ahb_correctable using the statistics provided
773 785 * by the Cache Control Register (ASI 2, offset 0) and in the Register Protection Control Register (ASR16) on the
774 786 * detected errors in the cache, in the integer unit and in the floating point unit.
775 787 *
776 788 * @param void
777 789 *
778 790 * @return void
779 791 *
780 792 * All errors are summed to set the value of the hk_lfr_ahb_correctable counter.
781 793 *
782 794 */
783 795
784 796 unsigned int ahb_correctable;
785 797 unsigned int instructionErrorCounter;
786 798 unsigned int dataErrorCounter;
787 799 unsigned int fprfErrorCounter;
788 800 unsigned int iurfErrorCounter;
789 801
790 802 CCR_getInstructionAndDataErrorCounters( &instructionErrorCounter, &dataErrorCounter);
791 803 ASR16_get_FPRF_IURF_ErrorCounters( &fprfErrorCounter, &iurfErrorCounter);
792 804
793 805 ahb_correctable = instructionErrorCounter
794 806 + dataErrorCounter
795 807 + fprfErrorCounter
796 808 + iurfErrorCounter
797 809 + housekeeping_packet.hk_lfr_ahb_correctable;
798 810
799 811 housekeeping_packet.hk_lfr_ahb_correctable = (unsigned char) (ahb_correctable & 0xff); // [1111 1111]
800 812
801 813 }
@@ -1,1598 +1,1599
1 1 /** Functions related to the SpaceWire interface.
2 2 *
3 3 * @file
4 4 * @author P. LEROY
5 5 *
6 6 * A group of functions to handle SpaceWire transmissions:
7 7 * - configuration of the SpaceWire link
8 8 * - SpaceWire related interruption requests processing
9 9 * - transmission of TeleMetry packets by a dedicated RTEMS task
10 10 * - reception of TeleCommands by a dedicated RTEMS task
11 11 *
12 12 */
13 13
14 14 #include "fsw_spacewire.h"
15 15
16 16 rtems_name semq_name;
17 17 rtems_id semq_id;
18 18
19 19 //*****************
20 20 // waveform headers
21 21 Header_TM_LFR_SCIENCE_CWF_t headerCWF;
22 22 Header_TM_LFR_SCIENCE_SWF_t headerSWF;
23 23 Header_TM_LFR_SCIENCE_ASM_t headerASM;
24 24
25 25 unsigned char previousTimecodeCtr = 0;
26 26 unsigned int *grspwPtr = (unsigned int *) (REGS_ADDR_GRSPW + APB_OFFSET_GRSPW_TIME_REGISTER);
27 27
28 28 //***********
29 29 // RTEMS TASK
30 30 rtems_task spiq_task(rtems_task_argument unused)
31 31 {
32 32 /** This RTEMS task is awaken by an rtems_event sent by the interruption subroutine of the SpaceWire driver.
33 33 *
34 34 * @param unused is the starting argument of the RTEMS task
35 35 *
36 36 */
37 37
38 38 rtems_event_set event_out;
39 39 rtems_status_code status;
40 40 int linkStatus;
41 41
42 42 BOOT_PRINTF("in SPIQ *** \n")
43 43
44 44 while(true){
45 45 rtems_event_receive(SPW_LINKERR_EVENT, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an SPW_LINKERR_EVENT
46 46 PRINTF("in SPIQ *** got SPW_LINKERR_EVENT\n")
47 47
48 48 // [0] SUSPEND RECV AND SEND TASKS
49 49 status = rtems_task_suspend( Task_id[ TASKID_RECV ] );
50 50 if ( status != RTEMS_SUCCESSFUL ) {
51 51 PRINTF("in SPIQ *** ERR suspending RECV Task\n")
52 52 }
53 53 status = rtems_task_suspend( Task_id[ TASKID_SEND ] );
54 54 if ( status != RTEMS_SUCCESSFUL ) {
55 55 PRINTF("in SPIQ *** ERR suspending SEND Task\n")
56 56 }
57 57
58 58 // [1] CHECK THE LINK
59 59 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (1)
60 60 if ( linkStatus != 5) {
61 61 PRINTF1("in SPIQ *** linkStatus %d, wait...\n", linkStatus)
62 62 status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms
63 63 }
64 64
65 65 // [2] RECHECK THE LINK AFTER SY_LFR_DPU_CONNECT_TIMEOUT
66 66 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (2)
67 67 if ( linkStatus != 5 ) // [2.a] not in run state, reset the link
68 68 {
69 69 spacewire_read_statistics();
70 70 status = spacewire_several_connect_attemps( );
71 71 }
72 72 else // [2.b] in run state, start the link
73 73 {
74 74 status = spacewire_stop_and_start_link( fdSPW ); // start the link
75 75 if ( status != RTEMS_SUCCESSFUL)
76 76 {
77 77 PRINTF1("in SPIQ *** ERR spacewire_stop_and_start_link %d\n", status)
78 78 }
79 79 }
80 80
81 81 // [3] COMPLETE RECOVERY ACTION AFTER SY_LFR_DPU_CONNECT_ATTEMPTS
82 82 if ( status == RTEMS_SUCCESSFUL ) // [3.a] the link is in run state and has been started successfully
83 83 {
84 84 status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 );
85 85 if ( status != RTEMS_SUCCESSFUL ) {
86 86 PRINTF("in SPIQ *** ERR resuming SEND Task\n")
87 87 }
88 88 status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 );
89 89 if ( status != RTEMS_SUCCESSFUL ) {
90 90 PRINTF("in SPIQ *** ERR resuming RECV Task\n")
91 91 }
92 92 }
93 93 else // [3.b] the link is not in run state, go in STANDBY mode
94 94 {
95 95 status = enter_mode_standby();
96 96 if ( status != RTEMS_SUCCESSFUL )
97 97 {
98 98 PRINTF1("in SPIQ *** ERR enter_standby_mode *** code %d\n", status)
99 99 }
100 100 {
101 101 updateLFRCurrentMode( LFR_MODE_STANDBY );
102 102 }
103 103 // wake the LINK task up to wait for the link recovery
104 104 status = rtems_event_send ( Task_id[TASKID_LINK], RTEMS_EVENT_0 );
105 105 status = rtems_task_suspend( RTEMS_SELF );
106 106 }
107 107 }
108 108 }
109 109
110 110 rtems_task recv_task( rtems_task_argument unused )
111 111 {
112 112 /** This RTEMS task is dedicated to the reception of incoming TeleCommands.
113 113 *
114 114 * @param unused is the starting argument of the RTEMS task
115 115 *
116 116 * The RECV task blocks on a call to the read system call, waiting for incoming SpaceWire data. When unblocked:
117 117 * 1. It reads the incoming data.
118 118 * 2. Launches the acceptance procedure.
119 119 * 3. If the Telecommand is valid, sends it to a dedicated RTEMS message queue.
120 120 *
121 121 */
122 122
123 123 int len;
124 124 ccsdsTelecommandPacket_t currentTC;
125 125 unsigned char computed_CRC[ 2 ];
126 126 unsigned char currentTC_LEN_RCV[ 2 ];
127 127 unsigned char destinationID;
128 128 unsigned int estimatedPacketLength;
129 129 unsigned int parserCode;
130 130 rtems_status_code status;
131 131 rtems_id queue_recv_id;
132 132 rtems_id queue_send_id;
133 133
134 134 initLookUpTableForCRC(); // the table is used to compute Cyclic Redundancy Codes
135 135
136 136 status = get_message_queue_id_recv( &queue_recv_id );
137 137 if (status != RTEMS_SUCCESSFUL)
138 138 {
139 139 PRINTF1("in RECV *** ERR get_message_queue_id_recv %d\n", status)
140 140 }
141 141
142 142 status = get_message_queue_id_send( &queue_send_id );
143 143 if (status != RTEMS_SUCCESSFUL)
144 144 {
145 145 PRINTF1("in RECV *** ERR get_message_queue_id_send %d\n", status)
146 146 }
147 147
148 148 BOOT_PRINTF("in RECV *** \n")
149 149
150 150 while(1)
151 151 {
152 152 len = read( fdSPW, (char*) &currentTC, CCSDS_TC_PKT_MAX_SIZE ); // the call to read is blocking
153 153 if (len == -1){ // error during the read call
154 154 PRINTF1("in RECV *** last read call returned -1, ERRNO %d\n", errno)
155 155 }
156 156 else {
157 157 if ( (len+1) < CCSDS_TC_PKT_MIN_SIZE ) {
158 158 PRINTF("in RECV *** packet lenght too short\n")
159 159 }
160 160 else {
161 PRINTF1("incoming TC with len: %d\n", len);
161 162 estimatedPacketLength = (unsigned int) (len - CCSDS_TC_TM_PACKET_OFFSET - 3); // => -3 is for Prot ID, Reserved and User App bytes
162 163 currentTC_LEN_RCV[ 0 ] = (unsigned char) (estimatedPacketLength >> 8);
163 164 currentTC_LEN_RCV[ 1 ] = (unsigned char) (estimatedPacketLength );
164 165 // CHECK THE TC
165 166 parserCode = tc_parser( &currentTC, estimatedPacketLength, computed_CRC ) ;
166 167 if ( (parserCode == ILLEGAL_APID) || (parserCode == WRONG_LEN_PKT)
167 168 || (parserCode == INCOR_CHECKSUM) || (parserCode == ILL_TYPE)
168 169 || (parserCode == ILL_SUBTYPE) || (parserCode == WRONG_APP_DATA)
169 170 || (parserCode == WRONG_SRC_ID) )
170 171 { // send TM_LFR_TC_EXE_CORRUPTED
171 PRINTF1("TC corrupted received, with code: %d\n", parserCode)
172 PRINTF1("TC corrupted received, with code: %d\n", parserCode);
172 173 if ( !( (currentTC.serviceType==TC_TYPE_TIME) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_TIME) )
173 174 &&
174 175 !( (currentTC.serviceType==TC_TYPE_GEN) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_INFO))
175 176 )
176 177 {
177 178 if ( parserCode == WRONG_SRC_ID )
178 179 {
179 180 destinationID = SID_TC_GROUND;
180 181 }
181 182 else
182 183 {
183 184 destinationID = currentTC.sourceID;
184 185 }
185 186 send_tm_lfr_tc_exe_corrupted( &currentTC, queue_send_id,
186 187 computed_CRC, currentTC_LEN_RCV,
187 188 destinationID );
188 189 }
189 190 }
190 191 else
191 192 { // send valid TC to the action launcher
192 193 status = rtems_message_queue_send( queue_recv_id, &currentTC,
193 194 estimatedPacketLength + CCSDS_TC_TM_PACKET_OFFSET + 3);
194 195 }
195 196 }
196 197 }
197 198
198 199 update_queue_max_count( queue_recv_id, &hk_lfr_q_rv_fifo_size_max );
199 200
200 201 }
201 202 }
202 203
203 204 rtems_task send_task( rtems_task_argument argument)
204 205 {
205 206 /** This RTEMS task is dedicated to the transmission of TeleMetry packets.
206 207 *
207 208 * @param unused is the starting argument of the RTEMS task
208 209 *
209 210 * The SEND task waits for a message to become available in the dedicated RTEMS queue. When a message arrives:
210 211 * - if the first byte is equal to CCSDS_DESTINATION_ID, the message is sent as is using the write system call.
211 212 * - if the first byte is not equal to CCSDS_DESTINATION_ID, the message is handled as a spw_ioctl_pkt_send. After
212 213 * analyzis, the packet is sent either using the write system call or using the ioctl call SPACEWIRE_IOCTRL_SEND, depending on the
213 214 * data it contains.
214 215 *
215 216 */
216 217
217 218 rtems_status_code status; // RTEMS status code
218 219 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
219 220 ring_node *incomingRingNodePtr;
220 221 int ring_node_address;
221 222 char *charPtr;
222 223 spw_ioctl_pkt_send *spw_ioctl_send;
223 224 size_t size; // size of the incoming TC packet
224 225 rtems_id queue_send_id;
225 226 unsigned int sid;
226 227 unsigned char sidAsUnsignedChar;
227 228 unsigned char type;
228 229
229 230 incomingRingNodePtr = NULL;
230 231 ring_node_address = 0;
231 232 charPtr = (char *) &ring_node_address;
232 233 sid = 0;
233 234 sidAsUnsignedChar = 0;
234 235
235 236 init_header_cwf( &headerCWF );
236 237 init_header_swf( &headerSWF );
237 238 init_header_asm( &headerASM );
238 239
239 240 status = get_message_queue_id_send( &queue_send_id );
240 241 if (status != RTEMS_SUCCESSFUL)
241 242 {
242 243 PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status)
243 244 }
244 245
245 246 BOOT_PRINTF("in SEND *** \n")
246 247
247 248 while(1)
248 249 {
249 250 status = rtems_message_queue_receive( queue_send_id, incomingData, &size,
250 251 RTEMS_WAIT, RTEMS_NO_TIMEOUT );
251 252
252 253 if (status!=RTEMS_SUCCESSFUL)
253 254 {
254 255 PRINTF1("in SEND *** (1) ERR = %d\n", status)
255 256 }
256 257 else
257 258 {
258 259 if ( size == sizeof(ring_node*) )
259 260 {
260 261 charPtr[0] = incomingData[0];
261 262 charPtr[1] = incomingData[1];
262 263 charPtr[2] = incomingData[2];
263 264 charPtr[3] = incomingData[3];
264 265 incomingRingNodePtr = (ring_node*) ring_node_address;
265 266 sid = incomingRingNodePtr->sid;
266 267 if ( (sid==SID_NORM_CWF_LONG_F3)
267 268 || (sid==SID_BURST_CWF_F2 )
268 269 || (sid==SID_SBM1_CWF_F1 )
269 270 || (sid==SID_SBM2_CWF_F2 ))
270 271 {
271 272 spw_send_waveform_CWF( incomingRingNodePtr, &headerCWF );
272 273 }
273 274 else if ( (sid==SID_NORM_SWF_F0) || (sid== SID_NORM_SWF_F1) || (sid==SID_NORM_SWF_F2) )
274 275 {
275 276 spw_send_waveform_SWF( incomingRingNodePtr, &headerSWF );
276 277 }
277 278 else if ( (sid==SID_NORM_CWF_F3) )
278 279 {
279 280 spw_send_waveform_CWF3_light( incomingRingNodePtr, &headerCWF );
280 281 }
281 282 else if (sid==SID_NORM_ASM_F0)
282 283 {
283 284 spw_send_asm_f0( incomingRingNodePtr, &headerASM );
284 285 }
285 286 else if (sid==SID_NORM_ASM_F1)
286 287 {
287 288 spw_send_asm_f1( incomingRingNodePtr, &headerASM );
288 289 }
289 290 else if (sid==SID_NORM_ASM_F2)
290 291 {
291 292 spw_send_asm_f2( incomingRingNodePtr, &headerASM );
292 293 }
293 294 else if ( sid==TM_CODE_K_DUMP )
294 295 {
295 296 spw_send_k_dump( incomingRingNodePtr );
296 297 }
297 298 else
298 299 {
299 300 PRINTF1("unexpected sid = %d\n", sid);
300 301 }
301 302 }
302 303 else if ( incomingData[0] == CCSDS_DESTINATION_ID ) // the incoming message is a ccsds packet
303 304 {
304 305 sidAsUnsignedChar = (unsigned char) incomingData[ PACKET_POS_PA_LFR_SID_PKT ];
305 306 sid = sidAsUnsignedChar;
306 307 type = (unsigned char) incomingData[ PACKET_POS_SERVICE_TYPE ];
307 308 if (type == TM_TYPE_LFR_SCIENCE) // this is a BP packet, all other types are handled differently
308 309 // SET THE SEQUENCE_CNT PARAMETER IN CASE OF BP0 OR BP1 PACKETS
309 310 {
310 311 increment_seq_counter_source_id( (unsigned char*) &incomingData[ PACKET_POS_SEQUENCE_CNT ], sid );
311 312 }
312 313
313 314 status = write( fdSPW, incomingData, size );
314 315 if (status == -1){
315 316 PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size)
316 317 }
317 318 }
318 319 else // the incoming message is a spw_ioctl_pkt_send structure
319 320 {
320 321 spw_ioctl_send = (spw_ioctl_pkt_send*) incomingData;
321 322 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, spw_ioctl_send );
322 323 if (status == -1){
323 324 PRINTF2("in SEND *** (2.b) ERRNO = %d, RTEMS = %d\n", errno, status)
324 325 }
325 326 }
326 327 }
327 328
328 329 update_queue_max_count( queue_send_id, &hk_lfr_q_sd_fifo_size_max );
329 330
330 331 }
331 332 }
332 333
333 334 rtems_task link_task( rtems_task_argument argument )
334 335 {
335 336 rtems_event_set event_out;
336 337 rtems_status_code status;
337 338 int linkStatus;
338 339
339 340 BOOT_PRINTF("in LINK ***\n")
340 341
341 342 while(1)
342 343 {
343 344 // wait for an RTEMS_EVENT
344 345 rtems_event_receive( RTEMS_EVENT_0,
345 346 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
346 347 PRINTF("in LINK *** wait for the link\n")
347 348 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
348 349 while( linkStatus != 5) // wait for the link
349 350 {
350 351 status = rtems_task_wake_after( 10 ); // monitor the link each 100ms
351 352 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
352 353 watchdog_reload();
353 354 }
354 355
355 356 spacewire_read_statistics();
356 357 status = spacewire_stop_and_start_link( fdSPW );
357 358
358 359 if (status != RTEMS_SUCCESSFUL)
359 360 {
360 361 PRINTF1("in LINK *** ERR link not started %d\n", status)
361 362 }
362 363 else
363 364 {
364 365 PRINTF("in LINK *** OK link started\n")
365 366 }
366 367
367 368 // restart the SPIQ task
368 369 status = rtems_task_restart( Task_id[TASKID_SPIQ], 1 );
369 370 if ( status != RTEMS_SUCCESSFUL ) {
370 371 PRINTF("in SPIQ *** ERR restarting SPIQ Task\n")
371 372 }
372 373
373 374 // restart RECV and SEND
374 375 status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 );
375 376 if ( status != RTEMS_SUCCESSFUL ) {
376 377 PRINTF("in SPIQ *** ERR restarting SEND Task\n")
377 378 }
378 379 status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 );
379 380 if ( status != RTEMS_SUCCESSFUL ) {
380 381 PRINTF("in SPIQ *** ERR restarting RECV Task\n")
381 382 }
382 383 }
383 384 }
384 385
385 386 //****************
386 387 // OTHER FUNCTIONS
387 388 int spacewire_open_link( void ) // by default, the driver resets the core: [SPW_CTRL_WRITE(pDev, SPW_CTRL_RESET);]
388 389 {
389 390 /** This function opens the SpaceWire link.
390 391 *
391 392 * @return a valid file descriptor in case of success, -1 in case of a failure
392 393 *
393 394 */
394 395 rtems_status_code status;
395 396
396 397 fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call resets the hardware
397 398 if ( fdSPW < 0 ) {
398 399 PRINTF1("ERR *** in configure_spw_link *** error opening "GRSPW_DEVICE_NAME" with ERR %d\n", errno)
399 400 }
400 401 else
401 402 {
402 403 status = RTEMS_SUCCESSFUL;
403 404 }
404 405
405 406 return status;
406 407 }
407 408
408 409 int spacewire_start_link( int fd )
409 410 {
410 411 rtems_status_code status;
411 412
412 413 status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started
413 414 // -1 default hardcoded driver timeout
414 415
415 416 return status;
416 417 }
417 418
418 419 int spacewire_stop_and_start_link( int fd )
419 420 {
420 421 rtems_status_code status;
421 422
422 423 status = ioctl( fd, SPACEWIRE_IOCTRL_STOP); // start fails if link pDev->running != 0
423 424 status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started
424 425 // -1 default hardcoded driver timeout
425 426
426 427 return status;
427 428 }
428 429
429 430 int spacewire_configure_link( int fd )
430 431 {
431 432 /** This function configures the SpaceWire link.
432 433 *
433 434 * @return GR-RTEMS-DRIVER directive status codes:
434 435 * - 22 EINVAL - Null pointer or an out of range value was given as the argument.
435 436 * - 16 EBUSY - Only used for SEND. Returned when no descriptors are avialble in non-blocking mode.
436 437 * - 88 ENOSYS - Returned for SET_DESTKEY if RMAP command handler is not available or if a non-implemented call is used.
437 438 * - 116 ETIMEDOUT - REturned for SET_PACKET_SIZE and START if the link could not be brought up.
438 439 * - 12 ENOMEM - Returned for SET_PACKETSIZE if it was unable to allocate the new buffers.
439 440 * - 5 EIO - Error when writing to grswp hardware registers.
440 441 * - 2 ENOENT - No such file or directory
441 442 */
442 443
443 444 rtems_status_code status;
444 445
445 446 spacewire_set_NP(1, REGS_ADDR_GRSPW); // [N]o [P]ort force
446 447 spacewire_set_RE(1, REGS_ADDR_GRSPW); // [R]MAP [E]nable, the dedicated call seems to break the no port force configuration
447 448
448 449 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_RXBLOCK, 1); // sets the blocking mode for reception
449 450 if (status!=RTEMS_SUCCESSFUL) {
450 451 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_RXBLOCK\n")
451 452 }
452 453 //
453 454 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_EVENT_ID, Task_id[TASKID_SPIQ]); // sets the task ID to which an event is sent when a
454 455 if (status!=RTEMS_SUCCESSFUL) {
455 456 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_EVENT_ID\n") // link-error interrupt occurs
456 457 }
457 458 //
458 459 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_DISABLE_ERR, 0); // automatic link-disabling due to link-error interrupts
459 460 if (status!=RTEMS_SUCCESSFUL) {
460 461 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_DISABLE_ERR\n")
461 462 }
462 463 //
463 464 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ, 1); // sets the link-error interrupt bit
464 465 if (status!=RTEMS_SUCCESSFUL) {
465 466 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n")
466 467 }
467 468 //
468 469 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK, 1); // transmission blocks
469 470 if (status!=RTEMS_SUCCESSFUL) {
470 471 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK\n")
471 472 }
472 473 //
473 474 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL, 1); // transmission blocks when no transmission descriptor is available
474 475 if (status!=RTEMS_SUCCESSFUL) {
475 476 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL\n")
476 477 }
477 478 //
478 479 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TCODE_CTRL, 0x0909); // [Time Rx : Time Tx : Link error : Tick-out IRQ]
479 480 if (status!=RTEMS_SUCCESSFUL) {
480 481 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TCODE_CTRL,\n")
481 482 }
482 483
483 484 return status;
484 485 }
485 486
486 487 int spacewire_several_connect_attemps( void )
487 488 {
488 489 /** This function is executed by the SPIQ rtems_task wehn it has been awaken by an interruption raised by the SpaceWire driver.
489 490 *
490 491 * @return RTEMS directive status code:
491 492 * - RTEMS_UNSATISFIED is returned is the link is not in the running state after 10 s.
492 493 * - RTEMS_SUCCESSFUL is returned if the link is up before the timeout.
493 494 *
494 495 */
495 496
496 497 rtems_status_code status_spw;
497 498 rtems_status_code status;
498 499 int i;
499 500
500 501 for ( i=0; i<SY_LFR_DPU_CONNECT_ATTEMPT; i++ )
501 502 {
502 503 PRINTF1("in spacewire_reset_link *** link recovery, try %d\n", i);
503 504
504 505 // CLOSING THE DRIVER AT THIS POINT WILL MAKE THE SEND TASK BLOCK THE SYSTEM
505 506
506 507 status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms
507 508
508 509 status_spw = spacewire_stop_and_start_link( fdSPW );
509 510
510 511 if ( status_spw != RTEMS_SUCCESSFUL )
511 512 {
512 513 PRINTF1("in spacewire_reset_link *** ERR spacewire_start_link code %d\n", status_spw)
513 514 }
514 515
515 516 if ( status_spw == RTEMS_SUCCESSFUL)
516 517 {
517 518 break;
518 519 }
519 520 }
520 521
521 522 return status_spw;
522 523 }
523 524
524 525 void spacewire_set_NP( unsigned char val, unsigned int regAddr ) // [N]o [P]ort force
525 526 {
526 527 /** This function sets the [N]o [P]ort force bit of the GRSPW control register.
527 528 *
528 529 * @param val is the value, 0 or 1, used to set the value of the NP bit.
529 530 * @param regAddr is the address of the GRSPW control register.
530 531 *
531 532 * NP is the bit 20 of the GRSPW control register.
532 533 *
533 534 */
534 535
535 536 unsigned int *spwptr = (unsigned int*) regAddr;
536 537
537 538 if (val == 1) {
538 539 *spwptr = *spwptr | 0x00100000; // [NP] set the No port force bit
539 540 }
540 541 if (val== 0) {
541 542 *spwptr = *spwptr & 0xffdfffff;
542 543 }
543 544 }
544 545
545 546 void spacewire_set_RE( unsigned char val, unsigned int regAddr ) // [R]MAP [E]nable
546 547 {
547 548 /** This function sets the [R]MAP [E]nable bit of the GRSPW control register.
548 549 *
549 550 * @param val is the value, 0 or 1, used to set the value of the RE bit.
550 551 * @param regAddr is the address of the GRSPW control register.
551 552 *
552 553 * RE is the bit 16 of the GRSPW control register.
553 554 *
554 555 */
555 556
556 557 unsigned int *spwptr = (unsigned int*) regAddr;
557 558
558 559 if (val == 1)
559 560 {
560 561 *spwptr = *spwptr | 0x00010000; // [RE] set the RMAP Enable bit
561 562 }
562 563 if (val== 0)
563 564 {
564 565 *spwptr = *spwptr & 0xfffdffff;
565 566 }
566 567 }
567 568
568 569 void spacewire_read_statistics( void )
569 570 {
570 571 /** This function reads the SpaceWire statistics from the grspw RTEMS driver.
571 572 *
572 573 * @param void
573 574 *
574 575 * @return void
575 576 *
576 577 * Once they are read, the counters are stored in a global variable used during the building of the
577 578 * HK packets.
578 579 *
579 580 */
580 581
581 582 rtems_status_code status;
582 583 spw_stats current;
583 584
584 585 spacewire_get_last_error();
585 586
586 587 // read the current statistics
587 588 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &current );
588 589
589 590 // clear the counters
590 591 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_CLR_STATISTICS );
591 592
592 593 // typedef struct {
593 594 // unsigned int tx_link_err; // NOT IN HK
594 595 // unsigned int rx_rmap_header_crc_err; // NOT IN HK
595 596 // unsigned int rx_rmap_data_crc_err; // NOT IN HK
596 597 // unsigned int rx_eep_err;
597 598 // unsigned int rx_truncated;
598 599 // unsigned int parity_err;
599 600 // unsigned int escape_err;
600 601 // unsigned int credit_err;
601 602 // unsigned int write_sync_err;
602 603 // unsigned int disconnect_err;
603 604 // unsigned int early_ep;
604 605 // unsigned int invalid_address;
605 606 // unsigned int packets_sent;
606 607 // unsigned int packets_received;
607 608 // } spw_stats;
608 609
609 610 // rx_eep_err
610 611 grspw_stats.rx_eep_err = grspw_stats.rx_eep_err + current.rx_eep_err;
611 612 // rx_truncated
612 613 grspw_stats.rx_truncated = grspw_stats.rx_truncated + current.rx_truncated;
613 614 // parity_err
614 615 grspw_stats.parity_err = grspw_stats.parity_err + current.parity_err;
615 616 // escape_err
616 617 grspw_stats.escape_err = grspw_stats.escape_err + current.escape_err;
617 618 // credit_err
618 619 grspw_stats.credit_err = grspw_stats.credit_err + current.credit_err;
619 620 // write_sync_err
620 621 grspw_stats.write_sync_err = grspw_stats.write_sync_err + current.write_sync_err;
621 622 // disconnect_err
622 623 grspw_stats.disconnect_err = grspw_stats.disconnect_err + current.disconnect_err;
623 624 // early_ep
624 625 grspw_stats.early_ep = grspw_stats.early_ep + current.early_ep;
625 626 // invalid_address
626 627 grspw_stats.invalid_address = grspw_stats.invalid_address + current.invalid_address;
627 628 // packets_sent
628 629 grspw_stats.packets_sent = grspw_stats.packets_sent + current.packets_sent;
629 630 // packets_received
630 631 grspw_stats.packets_received= grspw_stats.packets_received + current.packets_received;
631 632
632 633 }
633 634
634 635 void spacewire_get_last_error( void )
635 636 {
636 637 static spw_stats previous;
637 638 spw_stats current;
638 639 rtems_status_code status;
639 640
640 641 unsigned int hk_lfr_last_er_rid;
641 642 unsigned char hk_lfr_last_er_code;
642 643 int coarseTime;
643 644 int fineTime;
644 645 unsigned char update_hk_lfr_last_er;
645 646
646 647 update_hk_lfr_last_er = 0;
647 648
648 649 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &current );
649 650
650 651 // get current time
651 652 coarseTime = time_management_regs->coarse_time;
652 653 fineTime = time_management_regs->fine_time;
653 654
654 655 // typedef struct {
655 656 // unsigned int tx_link_err; // NOT IN HK
656 657 // unsigned int rx_rmap_header_crc_err; // NOT IN HK
657 658 // unsigned int rx_rmap_data_crc_err; // NOT IN HK
658 659 // unsigned int rx_eep_err;
659 660 // unsigned int rx_truncated;
660 661 // unsigned int parity_err;
661 662 // unsigned int escape_err;
662 663 // unsigned int credit_err;
663 664 // unsigned int write_sync_err;
664 665 // unsigned int disconnect_err;
665 666 // unsigned int early_ep;
666 667 // unsigned int invalid_address;
667 668 // unsigned int packets_sent;
668 669 // unsigned int packets_received;
669 670 // } spw_stats;
670 671
671 672 // tx_link_err *** no code associated to this field
672 673 // rx_rmap_header_crc_err *** LE *** in HK
673 674 if (previous.rx_rmap_header_crc_err != current.rx_rmap_header_crc_err)
674 675 {
675 676 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
676 677 hk_lfr_last_er_code = CODE_HEADER_CRC;
677 678 update_hk_lfr_last_er = 1;
678 679 }
679 680 // rx_rmap_data_crc_err *** LE *** NOT IN HK
680 681 if (previous.rx_rmap_data_crc_err != current.rx_rmap_data_crc_err)
681 682 {
682 683 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
683 684 hk_lfr_last_er_code = CODE_DATA_CRC;
684 685 update_hk_lfr_last_er = 1;
685 686 }
686 687 // rx_eep_err
687 688 if (previous.rx_eep_err != current.rx_eep_err)
688 689 {
689 690 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
690 691 hk_lfr_last_er_code = CODE_EEP;
691 692 update_hk_lfr_last_er = 1;
692 693 }
693 694 // rx_truncated
694 695 if (previous.rx_truncated != current.rx_truncated)
695 696 {
696 697 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
697 698 hk_lfr_last_er_code = CODE_RX_TOO_BIG;
698 699 update_hk_lfr_last_er = 1;
699 700 }
700 701 // parity_err
701 702 if (previous.parity_err != current.parity_err)
702 703 {
703 704 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
704 705 hk_lfr_last_er_code = CODE_PARITY;
705 706 update_hk_lfr_last_er = 1;
706 707 }
707 708 // escape_err
708 709 if (previous.parity_err != current.parity_err)
709 710 {
710 711 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
711 712 hk_lfr_last_er_code = CODE_ESCAPE;
712 713 update_hk_lfr_last_er = 1;
713 714 }
714 715 // credit_err
715 716 if (previous.credit_err != current.credit_err)
716 717 {
717 718 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
718 719 hk_lfr_last_er_code = CODE_CREDIT;
719 720 update_hk_lfr_last_er = 1;
720 721 }
721 722 // write_sync_err
722 723 if (previous.write_sync_err != current.write_sync_err)
723 724 {
724 725 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
725 726 hk_lfr_last_er_code = CODE_WRITE_SYNC;
726 727 update_hk_lfr_last_er = 1;
727 728 }
728 729 // disconnect_err
729 730 if (previous.disconnect_err != current.disconnect_err)
730 731 {
731 732 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
732 733 hk_lfr_last_er_code = CODE_DISCONNECT;
733 734 update_hk_lfr_last_er = 1;
734 735 }
735 736 // early_ep
736 737 if (previous.early_ep != current.early_ep)
737 738 {
738 739 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
739 740 hk_lfr_last_er_code = CODE_EARLY_EOP_EEP;
740 741 update_hk_lfr_last_er = 1;
741 742 }
742 743 // invalid_address
743 744 if (previous.invalid_address != current.invalid_address)
744 745 {
745 746 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
746 747 hk_lfr_last_er_code = CODE_INVALID_ADDRESS;
747 748 update_hk_lfr_last_er = 1;
748 749 }
749 750
750 751 // if a field has changed, update the hk_last_er fields
751 752 if (update_hk_lfr_last_er == 1)
752 753 {
753 754 update_hk_lfr_last_er_fields( hk_lfr_last_er_rid, hk_lfr_last_er_code );
754 755 }
755 756
756 757 previous = current;
757 758 }
758 759
759 760 void update_hk_lfr_last_er_fields(unsigned int rid, unsigned char code)
760 761 {
761 762 unsigned char *coarseTimePtr;
762 763 unsigned char *fineTimePtr;
763 764
764 765 coarseTimePtr = (unsigned char*) &time_management_regs->coarse_time;
765 766 fineTimePtr = (unsigned char*) &time_management_regs->fine_time;
766 767
767 768 housekeeping_packet.hk_lfr_last_er_rid[0] = (unsigned char) ((rid & 0xff00) >> 8 );
768 769 housekeeping_packet.hk_lfr_last_er_rid[1] = (unsigned char) (rid & 0x00ff);
769 770 housekeeping_packet.hk_lfr_last_er_code = code;
770 771 housekeeping_packet.hk_lfr_last_er_time[0] = coarseTimePtr[0];
771 772 housekeeping_packet.hk_lfr_last_er_time[1] = coarseTimePtr[1];
772 773 housekeeping_packet.hk_lfr_last_er_time[2] = coarseTimePtr[2];
773 774 housekeeping_packet.hk_lfr_last_er_time[3] = coarseTimePtr[3];
774 775 housekeeping_packet.hk_lfr_last_er_time[4] = fineTimePtr[2];
775 776 housekeeping_packet.hk_lfr_last_er_time[5] = fineTimePtr[3];
776 777 }
777 778
778 779 void update_hk_with_grspw_stats( void )
779 780 {
780 781 //****************************
781 782 // DPU_SPACEWIRE_IF_STATISTICS
782 783 housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[0] = (unsigned char) (grspw_stats.packets_received >> 8);
783 784 housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[1] = (unsigned char) (grspw_stats.packets_received);
784 785 housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[0] = (unsigned char) (grspw_stats.packets_sent >> 8);
785 786 housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[1] = (unsigned char) (grspw_stats.packets_sent);
786 787
787 788 //******************************************
788 789 // ERROR COUNTERS / SPACEWIRE / LOW SEVERITY
789 790 housekeeping_packet.hk_lfr_dpu_spw_parity = (unsigned char) grspw_stats.parity_err;
790 791 housekeeping_packet.hk_lfr_dpu_spw_disconnect = (unsigned char) grspw_stats.disconnect_err;
791 792 housekeeping_packet.hk_lfr_dpu_spw_escape = (unsigned char) grspw_stats.escape_err;
792 793 housekeeping_packet.hk_lfr_dpu_spw_credit = (unsigned char) grspw_stats.credit_err;
793 794 housekeeping_packet.hk_lfr_dpu_spw_write_sync = (unsigned char) grspw_stats.write_sync_err;
794 795
795 796 //*********************************************
796 797 // ERROR COUNTERS / SPACEWIRE / MEDIUM SEVERITY
797 798 housekeeping_packet.hk_lfr_dpu_spw_early_eop = (unsigned char) grspw_stats.early_ep;
798 799 housekeeping_packet.hk_lfr_dpu_spw_invalid_addr = (unsigned char) grspw_stats.invalid_address;
799 800 housekeeping_packet.hk_lfr_dpu_spw_eep = (unsigned char) grspw_stats.rx_eep_err;
800 801 housekeeping_packet.hk_lfr_dpu_spw_rx_too_big = (unsigned char) grspw_stats.rx_truncated;
801 802 }
802 803
803 804 void spacewire_update_hk_lfr_link_state( unsigned char *hk_lfr_status_word_0 )
804 805 {
805 806 unsigned int *statusRegisterPtr;
806 807 unsigned char linkState;
807 808
808 809 statusRegisterPtr = (unsigned int *) (REGS_ADDR_GRSPW + APB_OFFSET_GRSPW_STATUS_REGISTER);
809 810 linkState = (unsigned char) ( ( (*statusRegisterPtr) >> 21) & 0x07); // [0000 0111]
810 811
811 812 *hk_lfr_status_word_0 = *hk_lfr_status_word_0 & 0xf8; // [1111 1000] set link state to 0
812 813
813 814 *hk_lfr_status_word_0 = *hk_lfr_status_word_0 | linkState; // update hk_lfr_dpu_spw_link_state
814 815 }
815 816
816 817 void increase_unsigned_char_counter( unsigned char *counter )
817 818 {
818 819 // update the number of valid timecodes that have been received
819 820 if (*counter == 255)
820 821 {
821 822 *counter = 0;
822 823 }
823 824 else
824 825 {
825 826 *counter = *counter + 1;
826 827 }
827 828 }
828 829
829 830 unsigned int check_timecode_and_previous_timecode_coherency(unsigned char currentTimecodeCtr)
830 831 {
831 832 /** This function checks the coherency between the incoming timecode and the last valid timecode.
832 833 *
833 834 * @param currentTimecodeCtr is the incoming timecode
834 835 *
835 836 * @return returned codes::
836 837 * - LFR_DEFAULT
837 838 * - LFR_SUCCESSFUL
838 839 *
839 840 */
840 841
841 842 static unsigned char firstTickout = 1;
842 843 unsigned char ret;
843 844
844 845 ret = LFR_DEFAULT;
845 846
846 847 if (firstTickout == 0)
847 848 {
848 849 if (currentTimecodeCtr == 0)
849 850 {
850 851 if (previousTimecodeCtr == 63)
851 852 {
852 853 ret = LFR_SUCCESSFUL;
853 854 }
854 855 else
855 856 {
856 857 ret = LFR_DEFAULT;
857 858 }
858 859 }
859 860 else
860 861 {
861 862 if (currentTimecodeCtr == (previousTimecodeCtr +1))
862 863 {
863 864 ret = LFR_SUCCESSFUL;
864 865 }
865 866 else
866 867 {
867 868 ret = LFR_DEFAULT;
868 869 }
869 870 }
870 871 }
871 872 else
872 873 {
873 874 firstTickout = 0;
874 875 ret = LFR_SUCCESSFUL;
875 876 }
876 877
877 878 return ret;
878 879 }
879 880
880 881 unsigned int check_timecode_and_internal_time_coherency(unsigned char timecode, unsigned char internalTime)
881 882 {
882 883 unsigned int ret;
883 884
884 885 ret = LFR_DEFAULT;
885 886
886 887 if (timecode == internalTime)
887 888 {
888 889 ret = LFR_SUCCESSFUL;
889 890 }
890 891 else
891 892 {
892 893 ret = LFR_DEFAULT;
893 894 }
894 895
895 896 return ret;
896 897 }
897 898
898 899 void timecode_irq_handler( void *pDev, void *regs, int minor, unsigned int tc )
899 900 {
900 901 // a tickout has been emitted, perform actions on the incoming timecode
901 902
902 903 unsigned char incomingTimecode;
903 904 unsigned char updateTime;
904 905 unsigned char internalTime;
905 906 rtems_status_code status;
906 907
907 908 incomingTimecode = (unsigned char) (grspwPtr[0] & TIMECODE_MASK);
908 909 updateTime = time_management_regs->coarse_time_load & TIMECODE_MASK;
909 910 internalTime = time_management_regs->coarse_time & TIMECODE_MASK;
910 911
911 912 housekeeping_packet.hk_lfr_dpu_spw_last_timc = incomingTimecode;
912 913
913 914 // update the number of tickout that have been generated
914 915 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_dpu_spw_tick_out_cnt );
915 916
916 917 //**************************
917 918 // HK_LFR_TIMECODE_ERRONEOUS
918 919 // MISSING and INVALID are handled by the timecode_timer_routine service routine
919 920 if (check_timecode_and_previous_timecode_coherency( incomingTimecode ) == LFR_DEFAULT)
920 921 {
921 922 // this is unexpected but a tickout could have been raised despite of the timecode being erroneous
922 923 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_erroneous );
923 924 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_ERRONEOUS );
924 925 }
925 926
926 927 //************************
927 928 // HK_LFR_TIME_TIMECODE_IT
928 929 // check the coherency between the SpaceWire timecode and the Internal Time
929 930 if (check_timecode_and_internal_time_coherency( incomingTimecode, internalTime ) == LFR_DEFAULT)
930 931 {
931 932 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_time_timecode_it );
932 933 update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_TIMECODE_IT );
933 934 }
934 935
935 936 //********************
936 937 // HK_LFR_TIMECODE_CTR
937 938 // check the value of the timecode with respect to the last TC_LFR_UPDATE_TIME => SSS-CP-FS-370
938 939 if (oneTcLfrUpdateTimeReceived == 1)
939 940 {
940 941 if ( incomingTimecode != updateTime )
941 942 {
942 943 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_time_timecode_ctr );
943 944 update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_TIMECODE_CTR );
944 945 }
945 946 }
946 947
947 948 // launch the timecode timer to detect missing or invalid timecodes
948 949 previousTimecodeCtr = incomingTimecode; // update the previousTimecodeCtr value
949 950 status = rtems_timer_fire_after( timecode_timer_id, TIMECODE_TIMER_TIMEOUT, timecode_timer_routine, NULL );
950 951 if (status != RTEMS_SUCCESSFUL)
951 952 {
952 953 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_14 );
953 954 }
954 955 }
955 956
956 957 rtems_timer_service_routine timecode_timer_routine( rtems_id timer_id, void *user_data )
957 958 {
958 959 static unsigned char initStep = 1;
959 960
960 961 unsigned char currentTimecodeCtr;
961 962
962 963 currentTimecodeCtr = (unsigned char) (grspwPtr[0] & TIMECODE_MASK);
963 964
964 965 if (initStep == 1)
965 966 {
966 967 if (currentTimecodeCtr == previousTimecodeCtr)
967 968 {
968 969 //************************
969 970 // HK_LFR_TIMECODE_MISSING
970 971 // the timecode value has not changed, no valid timecode has been received, the timecode is MISSING
971 972 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_missing );
972 973 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_MISSING );
973 974 }
974 975 else if (currentTimecodeCtr == (previousTimecodeCtr+1))
975 976 {
976 977 // the timecode value has changed and the value is valid, this is unexpected because
977 978 // the timer should not have fired, the timecode_irq_handler should have been raised
978 979 }
979 980 else
980 981 {
981 982 //************************
982 983 // HK_LFR_TIMECODE_INVALID
983 984 // the timecode value has changed and the value is not valid, no tickout has been generated
984 985 // this is why the timer has fired
985 986 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_invalid );
986 987 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_INVALID );
987 988 }
988 989 }
989 990 else
990 991 {
991 992 initStep = 1;
992 993 //************************
993 994 // HK_LFR_TIMECODE_MISSING
994 995 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_missing );
995 996 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_MISSING );
996 997 }
997 998
998 999 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_13 );
999 1000 }
1000 1001
1001 1002 void init_header_cwf( Header_TM_LFR_SCIENCE_CWF_t *header )
1002 1003 {
1003 1004 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
1004 1005 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1005 1006 header->reserved = DEFAULT_RESERVED;
1006 1007 header->userApplication = CCSDS_USER_APP;
1007 1008 header->packetSequenceControl[0]= TM_PACKET_SEQ_CTRL_STANDALONE;
1008 1009 header->packetSequenceControl[1]= TM_PACKET_SEQ_CNT_DEFAULT;
1009 1010 header->packetLength[0] = 0x00;
1010 1011 header->packetLength[1] = 0x00;
1011 1012 // DATA FIELD HEADER
1012 1013 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
1013 1014 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
1014 1015 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; // service subtype
1015 1016 header->destinationID = TM_DESTINATION_ID_GROUND;
1016 1017 header->time[0] = 0x00;
1017 1018 header->time[0] = 0x00;
1018 1019 header->time[0] = 0x00;
1019 1020 header->time[0] = 0x00;
1020 1021 header->time[0] = 0x00;
1021 1022 header->time[0] = 0x00;
1022 1023 // AUXILIARY DATA HEADER
1023 1024 header->sid = 0x00;
1024 1025 header->pa_bia_status_info = DEFAULT_HKBIA;
1025 1026 header->blkNr[0] = 0x00;
1026 1027 header->blkNr[1] = 0x00;
1027 1028 }
1028 1029
1029 1030 void init_header_swf( Header_TM_LFR_SCIENCE_SWF_t *header )
1030 1031 {
1031 1032 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
1032 1033 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1033 1034 header->reserved = DEFAULT_RESERVED;
1034 1035 header->userApplication = CCSDS_USER_APP;
1035 1036 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8);
1036 1037 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1037 1038 header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1038 1039 header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1039 1040 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> 8);
1040 1041 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 );
1041 1042 // DATA FIELD HEADER
1042 1043 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
1043 1044 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
1044 1045 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; // service subtype
1045 1046 header->destinationID = TM_DESTINATION_ID_GROUND;
1046 1047 header->time[0] = 0x00;
1047 1048 header->time[0] = 0x00;
1048 1049 header->time[0] = 0x00;
1049 1050 header->time[0] = 0x00;
1050 1051 header->time[0] = 0x00;
1051 1052 header->time[0] = 0x00;
1052 1053 // AUXILIARY DATA HEADER
1053 1054 header->sid = 0x00;
1054 1055 header->pa_bia_status_info = DEFAULT_HKBIA;
1055 1056 header->pktCnt = DEFAULT_PKTCNT; // PKT_CNT
1056 1057 header->pktNr = 0x00;
1057 1058 header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> 8);
1058 1059 header->blkNr[1] = (unsigned char) (BLK_NR_CWF );
1059 1060 }
1060 1061
1061 1062 void init_header_asm( Header_TM_LFR_SCIENCE_ASM_t *header )
1062 1063 {
1063 1064 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
1064 1065 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1065 1066 header->reserved = DEFAULT_RESERVED;
1066 1067 header->userApplication = CCSDS_USER_APP;
1067 1068 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8);
1068 1069 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1069 1070 header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1070 1071 header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1071 1072 header->packetLength[0] = 0x00;
1072 1073 header->packetLength[1] = 0x00;
1073 1074 // DATA FIELD HEADER
1074 1075 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
1075 1076 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
1076 1077 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; // service subtype
1077 1078 header->destinationID = TM_DESTINATION_ID_GROUND;
1078 1079 header->time[0] = 0x00;
1079 1080 header->time[0] = 0x00;
1080 1081 header->time[0] = 0x00;
1081 1082 header->time[0] = 0x00;
1082 1083 header->time[0] = 0x00;
1083 1084 header->time[0] = 0x00;
1084 1085 // AUXILIARY DATA HEADER
1085 1086 header->sid = 0x00;
1086 1087 header->pa_bia_status_info = 0x00;
1087 1088 header->pa_lfr_pkt_cnt_asm = 0x00;
1088 1089 header->pa_lfr_pkt_nr_asm = 0x00;
1089 1090 header->pa_lfr_asm_blk_nr[0] = 0x00;
1090 1091 header->pa_lfr_asm_blk_nr[1] = 0x00;
1091 1092 }
1092 1093
1093 1094 int spw_send_waveform_CWF( ring_node *ring_node_to_send,
1094 1095 Header_TM_LFR_SCIENCE_CWF_t *header )
1095 1096 {
1096 1097 /** This function sends CWF CCSDS packets (F2, F1 or F0).
1097 1098 *
1098 1099 * @param waveform points to the buffer containing the data that will be send.
1099 1100 * @param sid is the source identifier of the data that will be sent.
1100 1101 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
1101 1102 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
1102 1103 * contain information to setup the transmission of the data packets.
1103 1104 *
1104 1105 * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks.
1105 1106 *
1106 1107 */
1107 1108
1108 1109 unsigned int i;
1109 1110 int ret;
1110 1111 unsigned int coarseTime;
1111 1112 unsigned int fineTime;
1112 1113 rtems_status_code status;
1113 1114 spw_ioctl_pkt_send spw_ioctl_send_CWF;
1114 1115 int *dataPtr;
1115 1116 unsigned char sid;
1116 1117
1117 1118 spw_ioctl_send_CWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_CWF;
1118 1119 spw_ioctl_send_CWF.options = 0;
1119 1120
1120 1121 ret = LFR_DEFAULT;
1121 1122 sid = (unsigned char) ring_node_to_send->sid;
1122 1123
1123 1124 coarseTime = ring_node_to_send->coarseTime;
1124 1125 fineTime = ring_node_to_send->fineTime;
1125 1126 dataPtr = (int*) ring_node_to_send->buffer_address;
1126 1127
1127 1128 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> 8);
1128 1129 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 );
1129 1130 header->pa_bia_status_info = pa_bia_status_info;
1130 1131 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1131 1132 header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> 8);
1132 1133 header->blkNr[1] = (unsigned char) (BLK_NR_CWF );
1133 1134
1134 1135 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF; i++) // send waveform
1135 1136 {
1136 1137 spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF * NB_WORDS_SWF_BLK) ];
1137 1138 spw_ioctl_send_CWF.hdr = (char*) header;
1138 1139 // BUILD THE DATA
1139 1140 spw_ioctl_send_CWF.dlen = BLK_NR_CWF * NB_BYTES_SWF_BLK;
1140 1141
1141 1142 // SET PACKET SEQUENCE CONTROL
1142 1143 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1143 1144
1144 1145 // SET SID
1145 1146 header->sid = sid;
1146 1147
1147 1148 // SET PACKET TIME
1148 1149 compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime);
1149 1150 //
1150 1151 header->time[0] = header->acquisitionTime[0];
1151 1152 header->time[1] = header->acquisitionTime[1];
1152 1153 header->time[2] = header->acquisitionTime[2];
1153 1154 header->time[3] = header->acquisitionTime[3];
1154 1155 header->time[4] = header->acquisitionTime[4];
1155 1156 header->time[5] = header->acquisitionTime[5];
1156 1157
1157 1158 // SET PACKET ID
1158 1159 if ( (sid == SID_SBM1_CWF_F1) || (sid == SID_SBM2_CWF_F2) )
1159 1160 {
1160 1161 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2 >> 8);
1161 1162 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2);
1162 1163 }
1163 1164 else
1164 1165 {
1165 1166 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8);
1166 1167 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1167 1168 }
1168 1169
1169 1170 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF );
1170 1171 if (status != RTEMS_SUCCESSFUL) {
1171 1172 ret = LFR_DEFAULT;
1172 1173 }
1173 1174 }
1174 1175
1175 1176 return ret;
1176 1177 }
1177 1178
1178 1179 int spw_send_waveform_SWF( ring_node *ring_node_to_send,
1179 1180 Header_TM_LFR_SCIENCE_SWF_t *header )
1180 1181 {
1181 1182 /** This function sends SWF CCSDS packets (F2, F1 or F0).
1182 1183 *
1183 1184 * @param waveform points to the buffer containing the data that will be send.
1184 1185 * @param sid is the source identifier of the data that will be sent.
1185 1186 * @param headerSWF points to a table of headers that have been prepared for the data transmission.
1186 1187 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
1187 1188 * contain information to setup the transmission of the data packets.
1188 1189 *
1189 1190 * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks.
1190 1191 *
1191 1192 */
1192 1193
1193 1194 unsigned int i;
1194 1195 int ret;
1195 1196 unsigned int coarseTime;
1196 1197 unsigned int fineTime;
1197 1198 rtems_status_code status;
1198 1199 spw_ioctl_pkt_send spw_ioctl_send_SWF;
1199 1200 int *dataPtr;
1200 1201 unsigned char sid;
1201 1202
1202 1203 spw_ioctl_send_SWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_SWF;
1203 1204 spw_ioctl_send_SWF.options = 0;
1204 1205
1205 1206 ret = LFR_DEFAULT;
1206 1207
1207 1208 coarseTime = ring_node_to_send->coarseTime;
1208 1209 fineTime = ring_node_to_send->fineTime;
1209 1210 dataPtr = (int*) ring_node_to_send->buffer_address;
1210 1211 sid = ring_node_to_send->sid;
1211 1212
1212 1213 header->pa_bia_status_info = pa_bia_status_info;
1213 1214 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1214 1215
1215 1216 for (i=0; i<7; i++) // send waveform
1216 1217 {
1217 1218 spw_ioctl_send_SWF.data = (char*) &dataPtr[ (i * BLK_NR_304 * NB_WORDS_SWF_BLK) ];
1218 1219 spw_ioctl_send_SWF.hdr = (char*) header;
1219 1220
1220 1221 // SET PACKET SEQUENCE CONTROL
1221 1222 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1222 1223
1223 1224 // SET PACKET LENGTH AND BLKNR
1224 1225 if (i == 6)
1225 1226 {
1226 1227 spw_ioctl_send_SWF.dlen = BLK_NR_224 * NB_BYTES_SWF_BLK;
1227 1228 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_224 >> 8);
1228 1229 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_224 );
1229 1230 header->blkNr[0] = (unsigned char) (BLK_NR_224 >> 8);
1230 1231 header->blkNr[1] = (unsigned char) (BLK_NR_224 );
1231 1232 }
1232 1233 else
1233 1234 {
1234 1235 spw_ioctl_send_SWF.dlen = BLK_NR_304 * NB_BYTES_SWF_BLK;
1235 1236 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_304 >> 8);
1236 1237 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_304 );
1237 1238 header->blkNr[0] = (unsigned char) (BLK_NR_304 >> 8);
1238 1239 header->blkNr[1] = (unsigned char) (BLK_NR_304 );
1239 1240 }
1240 1241
1241 1242 // SET PACKET TIME
1242 1243 compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime );
1243 1244 //
1244 1245 header->time[0] = header->acquisitionTime[0];
1245 1246 header->time[1] = header->acquisitionTime[1];
1246 1247 header->time[2] = header->acquisitionTime[2];
1247 1248 header->time[3] = header->acquisitionTime[3];
1248 1249 header->time[4] = header->acquisitionTime[4];
1249 1250 header->time[5] = header->acquisitionTime[5];
1250 1251
1251 1252 // SET SID
1252 1253 header->sid = sid;
1253 1254
1254 1255 // SET PKTNR
1255 1256 header->pktNr = i+1; // PKT_NR
1256 1257
1257 1258 // SEND PACKET
1258 1259 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_SWF );
1259 1260 if (status != RTEMS_SUCCESSFUL) {
1260 1261 ret = LFR_DEFAULT;
1261 1262 }
1262 1263 }
1263 1264
1264 1265 return ret;
1265 1266 }
1266 1267
1267 1268 int spw_send_waveform_CWF3_light( ring_node *ring_node_to_send,
1268 1269 Header_TM_LFR_SCIENCE_CWF_t *header )
1269 1270 {
1270 1271 /** This function sends CWF_F3 CCSDS packets without the b1, b2 and b3 data.
1271 1272 *
1272 1273 * @param waveform points to the buffer containing the data that will be send.
1273 1274 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
1274 1275 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
1275 1276 * contain information to setup the transmission of the data packets.
1276 1277 *
1277 1278 * By default, CWF_F3 packet are send without the b1, b2 and b3 data. This function rebuilds a data buffer
1278 1279 * from the incoming data and sends it in 7 packets, 6 containing 340 blocks and 1 one containing 8 blocks.
1279 1280 *
1280 1281 */
1281 1282
1282 1283 unsigned int i;
1283 1284 int ret;
1284 1285 unsigned int coarseTime;
1285 1286 unsigned int fineTime;
1286 1287 rtems_status_code status;
1287 1288 spw_ioctl_pkt_send spw_ioctl_send_CWF;
1288 1289 char *dataPtr;
1289 1290 unsigned char sid;
1290 1291
1291 1292 spw_ioctl_send_CWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_CWF;
1292 1293 spw_ioctl_send_CWF.options = 0;
1293 1294
1294 1295 ret = LFR_DEFAULT;
1295 1296 sid = ring_node_to_send->sid;
1296 1297
1297 1298 coarseTime = ring_node_to_send->coarseTime;
1298 1299 fineTime = ring_node_to_send->fineTime;
1299 1300 dataPtr = (char*) ring_node_to_send->buffer_address;
1300 1301
1301 1302 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_672 >> 8);
1302 1303 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_672 );
1303 1304 header->pa_bia_status_info = pa_bia_status_info;
1304 1305 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1305 1306 header->blkNr[0] = (unsigned char) (BLK_NR_CWF_SHORT_F3 >> 8);
1306 1307 header->blkNr[1] = (unsigned char) (BLK_NR_CWF_SHORT_F3 );
1307 1308
1308 1309 //*********************
1309 1310 // SEND CWF3_light DATA
1310 1311 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF_LIGHT; i++) // send waveform
1311 1312 {
1312 1313 spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK) ];
1313 1314 spw_ioctl_send_CWF.hdr = (char*) header;
1314 1315 // BUILD THE DATA
1315 1316 spw_ioctl_send_CWF.dlen = BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK;
1316 1317
1317 1318 // SET PACKET SEQUENCE COUNTER
1318 1319 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1319 1320
1320 1321 // SET SID
1321 1322 header->sid = sid;
1322 1323
1323 1324 // SET PACKET TIME
1324 1325 compute_acquisition_time( coarseTime, fineTime, SID_NORM_CWF_F3, i, header->acquisitionTime );
1325 1326 //
1326 1327 header->time[0] = header->acquisitionTime[0];
1327 1328 header->time[1] = header->acquisitionTime[1];
1328 1329 header->time[2] = header->acquisitionTime[2];
1329 1330 header->time[3] = header->acquisitionTime[3];
1330 1331 header->time[4] = header->acquisitionTime[4];
1331 1332 header->time[5] = header->acquisitionTime[5];
1332 1333
1333 1334 // SET PACKET ID
1334 1335 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8);
1335 1336 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1336 1337
1337 1338 // SEND PACKET
1338 1339 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF );
1339 1340 if (status != RTEMS_SUCCESSFUL) {
1340 1341 ret = LFR_DEFAULT;
1341 1342 }
1342 1343 }
1343 1344
1344 1345 return ret;
1345 1346 }
1346 1347
1347 1348 void spw_send_asm_f0( ring_node *ring_node_to_send,
1348 1349 Header_TM_LFR_SCIENCE_ASM_t *header )
1349 1350 {
1350 1351 unsigned int i;
1351 1352 unsigned int length = 0;
1352 1353 rtems_status_code status;
1353 1354 unsigned int sid;
1354 1355 float *spectral_matrix;
1355 1356 int coarseTime;
1356 1357 int fineTime;
1357 1358 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1358 1359
1359 1360 sid = ring_node_to_send->sid;
1360 1361 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1361 1362 coarseTime = ring_node_to_send->coarseTime;
1362 1363 fineTime = ring_node_to_send->fineTime;
1363 1364
1364 1365 header->pa_bia_status_info = pa_bia_status_info;
1365 1366 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1366 1367
1367 1368 for (i=0; i<3; i++)
1368 1369 {
1369 1370 if ((i==0) || (i==1))
1370 1371 {
1371 1372 spw_ioctl_send_ASM.dlen = DLEN_ASM_F0_PKT_1;
1372 1373 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1373 1374 ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0_1) ) * NB_VALUES_PER_SM )
1374 1375 ];
1375 1376 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0_1;
1376 1377 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1377 1378 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0_1) >> 8 ); // BLK_NR MSB
1378 1379 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0_1); // BLK_NR LSB
1379 1380 }
1380 1381 else
1381 1382 {
1382 1383 spw_ioctl_send_ASM.dlen = DLEN_ASM_F0_PKT_2;
1383 1384 spw_ioctl_send_ASM.data = (char*) &spectral_matrix[
1384 1385 ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0_1) ) * NB_VALUES_PER_SM )
1385 1386 ];
1386 1387 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0_2;
1387 1388 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1388 1389 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0_2) >> 8 ); // BLK_NR MSB
1389 1390 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0_2); // BLK_NR LSB
1390 1391 }
1391 1392
1392 1393 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1393 1394 spw_ioctl_send_ASM.hdr = (char *) header;
1394 1395 spw_ioctl_send_ASM.options = 0;
1395 1396
1396 1397 // (2) BUILD THE HEADER
1397 1398 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1398 1399 header->packetLength[0] = (unsigned char) (length>>8);
1399 1400 header->packetLength[1] = (unsigned char) (length);
1400 1401 header->sid = (unsigned char) sid; // SID
1401 1402 header->pa_lfr_pkt_cnt_asm = 3;
1402 1403 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1403 1404
1404 1405 // (3) SET PACKET TIME
1405 1406 header->time[0] = (unsigned char) (coarseTime>>24);
1406 1407 header->time[1] = (unsigned char) (coarseTime>>16);
1407 1408 header->time[2] = (unsigned char) (coarseTime>>8);
1408 1409 header->time[3] = (unsigned char) (coarseTime);
1409 1410 header->time[4] = (unsigned char) (fineTime>>8);
1410 1411 header->time[5] = (unsigned char) (fineTime);
1411 1412 //
1412 1413 header->acquisitionTime[0] = header->time[0];
1413 1414 header->acquisitionTime[1] = header->time[1];
1414 1415 header->acquisitionTime[2] = header->time[2];
1415 1416 header->acquisitionTime[3] = header->time[3];
1416 1417 header->acquisitionTime[4] = header->time[4];
1417 1418 header->acquisitionTime[5] = header->time[5];
1418 1419
1419 1420 // (4) SEND PACKET
1420 1421 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1421 1422 if (status != RTEMS_SUCCESSFUL) {
1422 1423 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1423 1424 }
1424 1425 }
1425 1426 }
1426 1427
1427 1428 void spw_send_asm_f1( ring_node *ring_node_to_send,
1428 1429 Header_TM_LFR_SCIENCE_ASM_t *header )
1429 1430 {
1430 1431 unsigned int i;
1431 1432 unsigned int length = 0;
1432 1433 rtems_status_code status;
1433 1434 unsigned int sid;
1434 1435 float *spectral_matrix;
1435 1436 int coarseTime;
1436 1437 int fineTime;
1437 1438 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1438 1439
1439 1440 sid = ring_node_to_send->sid;
1440 1441 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1441 1442 coarseTime = ring_node_to_send->coarseTime;
1442 1443 fineTime = ring_node_to_send->fineTime;
1443 1444
1444 1445 header->pa_bia_status_info = pa_bia_status_info;
1445 1446 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1446 1447
1447 1448 for (i=0; i<3; i++)
1448 1449 {
1449 1450 if ((i==0) || (i==1))
1450 1451 {
1451 1452 spw_ioctl_send_ASM.dlen = DLEN_ASM_F1_PKT_1;
1452 1453 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1453 1454 ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1_1) ) * NB_VALUES_PER_SM )
1454 1455 ];
1455 1456 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1_1;
1456 1457 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1457 1458 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1_1) >> 8 ); // BLK_NR MSB
1458 1459 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1_1); // BLK_NR LSB
1459 1460 }
1460 1461 else
1461 1462 {
1462 1463 spw_ioctl_send_ASM.dlen = DLEN_ASM_F1_PKT_2;
1463 1464 spw_ioctl_send_ASM.data = (char*) &spectral_matrix[
1464 1465 ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1_1) ) * NB_VALUES_PER_SM )
1465 1466 ];
1466 1467 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1_2;
1467 1468 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1468 1469 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1_2) >> 8 ); // BLK_NR MSB
1469 1470 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1_2); // BLK_NR LSB
1470 1471 }
1471 1472
1472 1473 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1473 1474 spw_ioctl_send_ASM.hdr = (char *) header;
1474 1475 spw_ioctl_send_ASM.options = 0;
1475 1476
1476 1477 // (2) BUILD THE HEADER
1477 1478 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1478 1479 header->packetLength[0] = (unsigned char) (length>>8);
1479 1480 header->packetLength[1] = (unsigned char) (length);
1480 1481 header->sid = (unsigned char) sid; // SID
1481 1482 header->pa_lfr_pkt_cnt_asm = 3;
1482 1483 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1483 1484
1484 1485 // (3) SET PACKET TIME
1485 1486 header->time[0] = (unsigned char) (coarseTime>>24);
1486 1487 header->time[1] = (unsigned char) (coarseTime>>16);
1487 1488 header->time[2] = (unsigned char) (coarseTime>>8);
1488 1489 header->time[3] = (unsigned char) (coarseTime);
1489 1490 header->time[4] = (unsigned char) (fineTime>>8);
1490 1491 header->time[5] = (unsigned char) (fineTime);
1491 1492 //
1492 1493 header->acquisitionTime[0] = header->time[0];
1493 1494 header->acquisitionTime[1] = header->time[1];
1494 1495 header->acquisitionTime[2] = header->time[2];
1495 1496 header->acquisitionTime[3] = header->time[3];
1496 1497 header->acquisitionTime[4] = header->time[4];
1497 1498 header->acquisitionTime[5] = header->time[5];
1498 1499
1499 1500 // (4) SEND PACKET
1500 1501 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1501 1502 if (status != RTEMS_SUCCESSFUL) {
1502 1503 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1503 1504 }
1504 1505 }
1505 1506 }
1506 1507
1507 1508 void spw_send_asm_f2( ring_node *ring_node_to_send,
1508 1509 Header_TM_LFR_SCIENCE_ASM_t *header )
1509 1510 {
1510 1511 unsigned int i;
1511 1512 unsigned int length = 0;
1512 1513 rtems_status_code status;
1513 1514 unsigned int sid;
1514 1515 float *spectral_matrix;
1515 1516 int coarseTime;
1516 1517 int fineTime;
1517 1518 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1518 1519
1519 1520 sid = ring_node_to_send->sid;
1520 1521 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1521 1522 coarseTime = ring_node_to_send->coarseTime;
1522 1523 fineTime = ring_node_to_send->fineTime;
1523 1524
1524 1525 header->pa_bia_status_info = pa_bia_status_info;
1525 1526 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1526 1527
1527 1528 for (i=0; i<3; i++)
1528 1529 {
1529 1530
1530 1531 spw_ioctl_send_ASM.dlen = DLEN_ASM_F2_PKT;
1531 1532 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1532 1533 ( (ASM_F2_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F2) ) * NB_VALUES_PER_SM )
1533 1534 ];
1534 1535 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F2;
1535 1536 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3;
1536 1537 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F2) >> 8 ); // BLK_NR MSB
1537 1538 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F2); // BLK_NR LSB
1538 1539
1539 1540 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1540 1541 spw_ioctl_send_ASM.hdr = (char *) header;
1541 1542 spw_ioctl_send_ASM.options = 0;
1542 1543
1543 1544 // (2) BUILD THE HEADER
1544 1545 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1545 1546 header->packetLength[0] = (unsigned char) (length>>8);
1546 1547 header->packetLength[1] = (unsigned char) (length);
1547 1548 header->sid = (unsigned char) sid; // SID
1548 1549 header->pa_lfr_pkt_cnt_asm = 3;
1549 1550 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1550 1551
1551 1552 // (3) SET PACKET TIME
1552 1553 header->time[0] = (unsigned char) (coarseTime>>24);
1553 1554 header->time[1] = (unsigned char) (coarseTime>>16);
1554 1555 header->time[2] = (unsigned char) (coarseTime>>8);
1555 1556 header->time[3] = (unsigned char) (coarseTime);
1556 1557 header->time[4] = (unsigned char) (fineTime>>8);
1557 1558 header->time[5] = (unsigned char) (fineTime);
1558 1559 //
1559 1560 header->acquisitionTime[0] = header->time[0];
1560 1561 header->acquisitionTime[1] = header->time[1];
1561 1562 header->acquisitionTime[2] = header->time[2];
1562 1563 header->acquisitionTime[3] = header->time[3];
1563 1564 header->acquisitionTime[4] = header->time[4];
1564 1565 header->acquisitionTime[5] = header->time[5];
1565 1566
1566 1567 // (4) SEND PACKET
1567 1568 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1568 1569 if (status != RTEMS_SUCCESSFUL) {
1569 1570 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1570 1571 }
1571 1572 }
1572 1573 }
1573 1574
1574 1575 void spw_send_k_dump( ring_node *ring_node_to_send )
1575 1576 {
1576 1577 rtems_status_code status;
1577 1578 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump;
1578 1579 unsigned int packetLength;
1579 1580 unsigned int size;
1580 1581
1581 1582 PRINTF("spw_send_k_dump\n")
1582 1583
1583 1584 kcoefficients_dump = (Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *) ring_node_to_send->buffer_address;
1584 1585
1585 1586 packetLength = kcoefficients_dump->packetLength[0] * 256 + kcoefficients_dump->packetLength[1];
1586 1587
1587 1588 size = packetLength + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
1588 1589
1589 1590 PRINTF2("packetLength %d, size %d\n", packetLength, size )
1590 1591
1591 1592 status = write( fdSPW, (char *) ring_node_to_send->buffer_address, size );
1592 1593
1593 1594 if (status == -1){
1594 1595 PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size)
1595 1596 }
1596 1597
1597 1598 ring_node_to_send->status = 0x00;
1598 1599 }
@@ -1,1566 +1,1567
1 1 /** Functions to load and dump parameters in the LFR registers.
2 2 *
3 3 * @file
4 4 * @author P. LEROY
5 5 *
6 6 * A group of functions to handle TC related to parameter loading and dumping.\n
7 7 * TC_LFR_LOAD_COMMON_PAR\n
8 8 * TC_LFR_LOAD_NORMAL_PAR\n
9 9 * TC_LFR_LOAD_BURST_PAR\n
10 10 * TC_LFR_LOAD_SBM1_PAR\n
11 11 * TC_LFR_LOAD_SBM2_PAR\n
12 12 *
13 13 */
14 14
15 15 #include "tc_load_dump_parameters.h"
16 16
17 17 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t kcoefficients_dump_1;
18 18 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t kcoefficients_dump_2;
19 19 ring_node kcoefficient_node_1;
20 20 ring_node kcoefficient_node_2;
21 21
22 22 int action_load_common_par(ccsdsTelecommandPacket_t *TC)
23 23 {
24 24 /** This function updates the LFR registers with the incoming common parameters.
25 25 *
26 26 * @param TC points to the TeleCommand packet that is being processed
27 27 *
28 28 *
29 29 */
30 30
31 31 parameter_dump_packet.sy_lfr_common_parameters_spare = TC->dataAndCRC[0];
32 32 parameter_dump_packet.sy_lfr_common_parameters = TC->dataAndCRC[1];
33 33 set_wfp_data_shaping( );
34 34 return LFR_SUCCESSFUL;
35 35 }
36 36
37 37 int action_load_normal_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
38 38 {
39 39 /** This function updates the LFR registers with the incoming normal parameters.
40 40 *
41 41 * @param TC points to the TeleCommand packet that is being processed
42 42 * @param queue_id is the id of the queue which handles TM related to this execution step
43 43 *
44 44 */
45 45
46 46 int result;
47 47 int flag;
48 48 rtems_status_code status;
49 49
50 50 flag = LFR_SUCCESSFUL;
51 51
52 52 if ( (lfrCurrentMode == LFR_MODE_NORMAL) ||
53 53 (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) ) {
54 54 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
55 55 flag = LFR_DEFAULT;
56 56 }
57 57
58 58 // CHECK THE PARAMETERS SET CONSISTENCY
59 59 if (flag == LFR_SUCCESSFUL)
60 60 {
61 61 flag = check_normal_par_consistency( TC, queue_id );
62 62 }
63 63
64 64 // SET THE PARAMETERS IF THEY ARE CONSISTENT
65 65 if (flag == LFR_SUCCESSFUL)
66 66 {
67 67 result = set_sy_lfr_n_swf_l( TC );
68 68 result = set_sy_lfr_n_swf_p( TC );
69 69 result = set_sy_lfr_n_bp_p0( TC );
70 70 result = set_sy_lfr_n_bp_p1( TC );
71 71 result = set_sy_lfr_n_asm_p( TC );
72 72 result = set_sy_lfr_n_cwf_long_f3( TC );
73 73 }
74 74
75 75 return flag;
76 76 }
77 77
78 78 int action_load_burst_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
79 79 {
80 80 /** This function updates the LFR registers with the incoming burst parameters.
81 81 *
82 82 * @param TC points to the TeleCommand packet that is being processed
83 83 * @param queue_id is the id of the queue which handles TM related to this execution step
84 84 *
85 85 */
86 86
87 87 int flag;
88 88 rtems_status_code status;
89 89 unsigned char sy_lfr_b_bp_p0;
90 90 unsigned char sy_lfr_b_bp_p1;
91 91 float aux;
92 92
93 93 flag = LFR_SUCCESSFUL;
94 94
95 95 if ( lfrCurrentMode == LFR_MODE_BURST ) {
96 96 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
97 97 flag = LFR_DEFAULT;
98 98 }
99 99
100 100 sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
101 101 sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
102 102
103 103 // sy_lfr_b_bp_p0 shall not be lower than its default value
104 104 if (flag == LFR_SUCCESSFUL)
105 105 {
106 106 if (sy_lfr_b_bp_p0 < DEFAULT_SY_LFR_B_BP_P0 )
107 107 {
108 108 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P0+10, sy_lfr_b_bp_p0 );
109 109 flag = WRONG_APP_DATA;
110 110 }
111 111 }
112 112 // sy_lfr_b_bp_p1 shall not be lower than its default value
113 113 if (flag == LFR_SUCCESSFUL)
114 114 {
115 115 if (sy_lfr_b_bp_p1 < DEFAULT_SY_LFR_B_BP_P1 )
116 116 {
117 117 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P1+10, sy_lfr_b_bp_p1 );
118 118 flag = WRONG_APP_DATA;
119 119 }
120 120 }
121 121 //****************************************************************
122 122 // check the consistency between sy_lfr_b_bp_p0 and sy_lfr_b_bp_p1
123 123 if (flag == LFR_SUCCESSFUL)
124 124 {
125 125 sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
126 126 sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
127 127 aux = ( (float ) sy_lfr_b_bp_p1 / sy_lfr_b_bp_p0 ) - floor(sy_lfr_b_bp_p1 / sy_lfr_b_bp_p0);
128 128 if (aux > FLOAT_EQUAL_ZERO)
129 129 {
130 130 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P0+10, sy_lfr_b_bp_p0 );
131 131 flag = LFR_DEFAULT;
132 132 }
133 133 }
134 134
135 135 // SET THE PARAMETERS
136 136 if (flag == LFR_SUCCESSFUL)
137 137 {
138 138 flag = set_sy_lfr_b_bp_p0( TC );
139 139 flag = set_sy_lfr_b_bp_p1( TC );
140 140 }
141 141
142 142 return flag;
143 143 }
144 144
145 145 int action_load_sbm1_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
146 146 {
147 147 /** This function updates the LFR registers with the incoming sbm1 parameters.
148 148 *
149 149 * @param TC points to the TeleCommand packet that is being processed
150 150 * @param queue_id is the id of the queue which handles TM related to this execution step
151 151 *
152 152 */
153 153
154 154 int flag;
155 155 rtems_status_code status;
156 156 unsigned char sy_lfr_s1_bp_p0;
157 157 unsigned char sy_lfr_s1_bp_p1;
158 158 float aux;
159 159
160 160 flag = LFR_SUCCESSFUL;
161 161
162 162 if ( lfrCurrentMode == LFR_MODE_SBM1 ) {
163 163 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
164 164 flag = LFR_DEFAULT;
165 165 }
166 166
167 167 sy_lfr_s1_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P0 ];
168 168 sy_lfr_s1_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P1 ];
169 169
170 170 // sy_lfr_s1_bp_p0
171 171 if (flag == LFR_SUCCESSFUL)
172 172 {
173 173 if (sy_lfr_s1_bp_p0 < DEFAULT_SY_LFR_S1_BP_P0 )
174 174 {
175 175 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P0+10, sy_lfr_s1_bp_p0 );
176 176 flag = WRONG_APP_DATA;
177 177 }
178 178 }
179 179 // sy_lfr_s1_bp_p1
180 180 if (flag == LFR_SUCCESSFUL)
181 181 {
182 182 if (sy_lfr_s1_bp_p1 < DEFAULT_SY_LFR_S1_BP_P1 )
183 183 {
184 184 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P1+10, sy_lfr_s1_bp_p1 );
185 185 flag = WRONG_APP_DATA;
186 186 }
187 187 }
188 188 //******************************************************************
189 189 // check the consistency between sy_lfr_s1_bp_p0 and sy_lfr_s1_bp_p1
190 190 if (flag == LFR_SUCCESSFUL)
191 191 {
192 192 aux = ( (float ) sy_lfr_s1_bp_p1 / (sy_lfr_s1_bp_p0*0.25) ) - floor(sy_lfr_s1_bp_p1 / (sy_lfr_s1_bp_p0*0.25));
193 193 if (aux > FLOAT_EQUAL_ZERO)
194 194 {
195 195 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P0+10, sy_lfr_s1_bp_p0 );
196 196 flag = LFR_DEFAULT;
197 197 }
198 198 }
199 199
200 200 // SET THE PARAMETERS
201 201 if (flag == LFR_SUCCESSFUL)
202 202 {
203 203 flag = set_sy_lfr_s1_bp_p0( TC );
204 204 flag = set_sy_lfr_s1_bp_p1( TC );
205 205 }
206 206
207 207 return flag;
208 208 }
209 209
210 210 int action_load_sbm2_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
211 211 {
212 212 /** This function updates the LFR registers with the incoming sbm2 parameters.
213 213 *
214 214 * @param TC points to the TeleCommand packet that is being processed
215 215 * @param queue_id is the id of the queue which handles TM related to this execution step
216 216 *
217 217 */
218 218
219 219 int flag;
220 220 rtems_status_code status;
221 221 unsigned char sy_lfr_s2_bp_p0;
222 222 unsigned char sy_lfr_s2_bp_p1;
223 223 float aux;
224 224
225 225 flag = LFR_SUCCESSFUL;
226 226
227 227 if ( lfrCurrentMode == LFR_MODE_SBM2 ) {
228 228 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
229 229 flag = LFR_DEFAULT;
230 230 }
231 231
232 232 sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
233 233 sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
234 234
235 235 // sy_lfr_s2_bp_p0
236 236 if (flag == LFR_SUCCESSFUL)
237 237 {
238 238 if (sy_lfr_s2_bp_p0 < DEFAULT_SY_LFR_S2_BP_P0 )
239 239 {
240 240 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P0+10, sy_lfr_s2_bp_p0 );
241 241 flag = WRONG_APP_DATA;
242 242 }
243 243 }
244 244 // sy_lfr_s2_bp_p1
245 245 if (flag == LFR_SUCCESSFUL)
246 246 {
247 247 if (sy_lfr_s2_bp_p1 < DEFAULT_SY_LFR_S2_BP_P1 )
248 248 {
249 249 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P1+10, sy_lfr_s2_bp_p1 );
250 250 flag = WRONG_APP_DATA;
251 251 }
252 252 }
253 253 //******************************************************************
254 254 // check the consistency between sy_lfr_s2_bp_p0 and sy_lfr_s2_bp_p1
255 255 if (flag == LFR_SUCCESSFUL)
256 256 {
257 257 sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
258 258 sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
259 259 aux = ( (float ) sy_lfr_s2_bp_p1 / sy_lfr_s2_bp_p0 ) - floor(sy_lfr_s2_bp_p1 / sy_lfr_s2_bp_p0);
260 260 if (aux > FLOAT_EQUAL_ZERO)
261 261 {
262 262 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P0+10, sy_lfr_s2_bp_p0 );
263 263 flag = LFR_DEFAULT;
264 264 }
265 265 }
266 266
267 267 // SET THE PARAMETERS
268 268 if (flag == LFR_SUCCESSFUL)
269 269 {
270 270 flag = set_sy_lfr_s2_bp_p0( TC );
271 271 flag = set_sy_lfr_s2_bp_p1( TC );
272 272 }
273 273
274 274 return flag;
275 275 }
276 276
277 277 int action_load_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
278 278 {
279 279 /** This function updates the LFR registers with the incoming sbm2 parameters.
280 280 *
281 281 * @param TC points to the TeleCommand packet that is being processed
282 282 * @param queue_id is the id of the queue which handles TM related to this execution step
283 283 *
284 284 */
285 285
286 286 int flag;
287 287
288 288 flag = LFR_DEFAULT;
289 289
290 290 flag = set_sy_lfr_kcoeff( TC, queue_id );
291 291
292 292 return flag;
293 293 }
294 294
295 295 int action_load_fbins_mask(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
296 296 {
297 297 /** This function updates the LFR registers with the incoming sbm2 parameters.
298 298 *
299 299 * @param TC points to the TeleCommand packet that is being processed
300 300 * @param queue_id is the id of the queue which handles TM related to this execution step
301 301 *
302 302 */
303 303
304 304 int flag;
305 305
306 306 flag = LFR_DEFAULT;
307 307
308 308 flag = set_sy_lfr_fbins( TC );
309 309
310 310 return flag;
311 311 }
312 312
313 313 int action_load_filter_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
314 314 {
315 315 /** This function updates the LFR registers with the incoming sbm2 parameters.
316 316 *
317 317 * @param TC points to the TeleCommand packet that is being processed
318 318 * @param queue_id is the id of the queue which handles TM related to this execution step
319 319 *
320 320 */
321 321
322 322 int flag;
323 323
324 324 flag = LFR_DEFAULT;
325 325
326 326 flag = check_sy_lfr_filter_parameters( TC, queue_id );
327 327
328 328 if (flag == LFR_SUCCESSFUL)
329 329 {
330 330 parameter_dump_packet.spare_sy_lfr_pas_filter_enabled = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_ENABLED ];
331 331 parameter_dump_packet.sy_lfr_pas_filter_modulus = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS ];
332 332 parameter_dump_packet.sy_lfr_pas_filter_tbad[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + 0 ];
333 333 parameter_dump_packet.sy_lfr_pas_filter_tbad[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + 1 ];
334 334 parameter_dump_packet.sy_lfr_pas_filter_tbad[2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + 2 ];
335 335 parameter_dump_packet.sy_lfr_pas_filter_tbad[3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + 3 ];
336 336 parameter_dump_packet.sy_lfr_pas_filter_offset = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET ];
337 337 parameter_dump_packet.sy_lfr_pas_filter_shift[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + 0 ];
338 338 parameter_dump_packet.sy_lfr_pas_filter_shift[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + 1 ];
339 339 parameter_dump_packet.sy_lfr_pas_filter_shift[2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + 2 ];
340 340 parameter_dump_packet.sy_lfr_pas_filter_shift[3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + 3 ];
341 341 parameter_dump_packet.sy_lfr_sc_rw_delta_f[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + 0 ];
342 342 parameter_dump_packet.sy_lfr_sc_rw_delta_f[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + 1 ];
343 343 parameter_dump_packet.sy_lfr_sc_rw_delta_f[2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + 2 ];
344 344 parameter_dump_packet.sy_lfr_sc_rw_delta_f[3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + 3 ];
345 345
346 346 //****************************
347 347 // store PAS filter parameters
348 348 // sy_lfr_pas_filter_enabled
349 349 filterPar.spare_sy_lfr_pas_filter_enabled = parameter_dump_packet.spare_sy_lfr_pas_filter_enabled;
350 set_sy_lfr_pas_filter_enabled( parameter_dump_packet.spare_sy_lfr_pas_filter_enabled & 0x01 );
350 351 // sy_lfr_pas_filter_modulus
351 352 filterPar.sy_lfr_pas_filter_modulus = parameter_dump_packet.sy_lfr_pas_filter_modulus;
352 353 // sy_lfr_pas_filter_tbad
353 354 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_pas_filter_tbad,
354 355 parameter_dump_packet.sy_lfr_pas_filter_tbad );
355 356 // sy_lfr_pas_filter_offset
356 357 filterPar.sy_lfr_pas_filter_offset = parameter_dump_packet.sy_lfr_pas_filter_offset;
357 358 // sy_lfr_pas_filter_shift
358 359 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_pas_filter_shift,
359 360 parameter_dump_packet.sy_lfr_pas_filter_shift );
360 361
361 362 //****************************************************
362 363 // store the parameter sy_lfr_sc_rw_delta_f as a float
363 364 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_sc_rw_delta_f,
364 365 parameter_dump_packet.sy_lfr_sc_rw_delta_f );
365 366 }
366 367
367 368 return flag;
368 369 }
369 370
370 371 int action_dump_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
371 372 {
372 373 /** This function updates the LFR registers with the incoming sbm2 parameters.
373 374 *
374 375 * @param TC points to the TeleCommand packet that is being processed
375 376 * @param queue_id is the id of the queue which handles TM related to this execution step
376 377 *
377 378 */
378 379
379 380 unsigned int address;
380 381 rtems_status_code status;
381 382 unsigned int freq;
382 383 unsigned int bin;
383 384 unsigned int coeff;
384 385 unsigned char *kCoeffPtr;
385 386 unsigned char *kCoeffDumpPtr;
386 387
387 388 // for each sy_lfr_kcoeff_frequency there is 32 kcoeff
388 389 // F0 => 11 bins
389 390 // F1 => 13 bins
390 391 // F2 => 12 bins
391 392 // 36 bins to dump in two packets (30 bins max per packet)
392 393
393 394 //*********
394 395 // PACKET 1
395 396 // 11 F0 bins, 13 F1 bins and 6 F2 bins
396 397 kcoefficients_dump_1.destinationID = TC->sourceID;
397 398 increment_seq_counter_destination_id_dump( kcoefficients_dump_1.packetSequenceControl, TC->sourceID );
398 399 for( freq=0;
399 400 freq<NB_BINS_COMPRESSED_SM_F0;
400 401 freq++ )
401 402 {
402 403 kcoefficients_dump_1.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + 1] = freq;
403 404 bin = freq;
404 405 // printKCoefficients( freq, bin, k_coeff_intercalib_f0_norm);
405 406 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
406 407 {
407 408 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + coeff*NB_BYTES_PER_FLOAT + 2 ]; // 2 for the kcoeff_frequency
408 409 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f0_norm[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
409 410 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
410 411 }
411 412 }
412 413 for( freq=NB_BINS_COMPRESSED_SM_F0;
413 414 freq<(NB_BINS_COMPRESSED_SM_F0+NB_BINS_COMPRESSED_SM_F1);
414 415 freq++ )
415 416 {
416 417 kcoefficients_dump_1.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + 1 ] = freq;
417 418 bin = freq - NB_BINS_COMPRESSED_SM_F0;
418 419 // printKCoefficients( freq, bin, k_coeff_intercalib_f1_norm);
419 420 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
420 421 {
421 422 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + coeff*NB_BYTES_PER_FLOAT + 2 ]; // 2 for the kcoeff_frequency
422 423 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f1_norm[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
423 424 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
424 425 }
425 426 }
426 427 for( freq=(NB_BINS_COMPRESSED_SM_F0+NB_BINS_COMPRESSED_SM_F1);
427 428 freq<(NB_BINS_COMPRESSED_SM_F0+NB_BINS_COMPRESSED_SM_F1+6);
428 429 freq++ )
429 430 {
430 431 kcoefficients_dump_1.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + 1 ] = freq;
431 432 bin = freq - (NB_BINS_COMPRESSED_SM_F0+NB_BINS_COMPRESSED_SM_F1);
432 433 // printKCoefficients( freq, bin, k_coeff_intercalib_f2);
433 434 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
434 435 {
435 436 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + coeff*NB_BYTES_PER_FLOAT + 2 ]; // 2 for the kcoeff_frequency
436 437 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f2[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
437 438 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
438 439 }
439 440 }
440 441 kcoefficients_dump_1.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
441 442 kcoefficients_dump_1.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
442 443 kcoefficients_dump_1.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
443 444 kcoefficients_dump_1.time[3] = (unsigned char) (time_management_regs->coarse_time);
444 445 kcoefficients_dump_1.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
445 446 kcoefficients_dump_1.time[5] = (unsigned char) (time_management_regs->fine_time);
446 447 // SEND DATA
447 448 kcoefficient_node_1.status = 1;
448 449 address = (unsigned int) &kcoefficient_node_1;
449 450 status = rtems_message_queue_send( queue_id, &address, sizeof( ring_node* ) );
450 451 if (status != RTEMS_SUCCESSFUL) {
451 452 PRINTF1("in action_dump_kcoefficients *** ERR sending packet 1 , code %d", status)
452 453 }
453 454
454 455 //********
455 456 // PACKET 2
456 457 // 6 F2 bins
457 458 kcoefficients_dump_2.destinationID = TC->sourceID;
458 459 increment_seq_counter_destination_id_dump( kcoefficients_dump_2.packetSequenceControl, TC->sourceID );
459 460 for( freq=0; freq<6; freq++ )
460 461 {
461 462 kcoefficients_dump_2.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + 1 ] = NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 + 6 + freq;
462 463 bin = freq + 6;
463 464 // printKCoefficients( freq, bin, k_coeff_intercalib_f2);
464 465 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
465 466 {
466 467 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_2.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + coeff*NB_BYTES_PER_FLOAT + 2 ]; // 2 for the kcoeff_frequency
467 468 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f2[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
468 469 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
469 470 }
470 471 }
471 472 kcoefficients_dump_2.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
472 473 kcoefficients_dump_2.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
473 474 kcoefficients_dump_2.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
474 475 kcoefficients_dump_2.time[3] = (unsigned char) (time_management_regs->coarse_time);
475 476 kcoefficients_dump_2.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
476 477 kcoefficients_dump_2.time[5] = (unsigned char) (time_management_regs->fine_time);
477 478 // SEND DATA
478 479 kcoefficient_node_2.status = 1;
479 480 address = (unsigned int) &kcoefficient_node_2;
480 481 status = rtems_message_queue_send( queue_id, &address, sizeof( ring_node* ) );
481 482 if (status != RTEMS_SUCCESSFUL) {
482 483 PRINTF1("in action_dump_kcoefficients *** ERR sending packet 2, code %d", status)
483 484 }
484 485
485 486 return status;
486 487 }
487 488
488 489 int action_dump_par( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
489 490 {
490 491 /** This function dumps the LFR parameters by sending the appropriate TM packet to the dedicated RTEMS message queue.
491 492 *
492 493 * @param queue_id is the id of the queue which handles TM related to this execution step.
493 494 *
494 495 * @return RTEMS directive status codes:
495 496 * - RTEMS_SUCCESSFUL - message sent successfully
496 497 * - RTEMS_INVALID_ID - invalid queue id
497 498 * - RTEMS_INVALID_SIZE - invalid message size
498 499 * - RTEMS_INVALID_ADDRESS - buffer is NULL
499 500 * - RTEMS_UNSATISFIED - out of message buffers
500 501 * - RTEMS_TOO_MANY - queue s limit has been reached
501 502 *
502 503 */
503 504
504 505 int status;
505 506
506 507 increment_seq_counter_destination_id_dump( parameter_dump_packet.packetSequenceControl, TC->sourceID );
507 508 parameter_dump_packet.destinationID = TC->sourceID;
508 509
509 510 // UPDATE TIME
510 511 parameter_dump_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
511 512 parameter_dump_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
512 513 parameter_dump_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
513 514 parameter_dump_packet.time[3] = (unsigned char) (time_management_regs->coarse_time);
514 515 parameter_dump_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
515 516 parameter_dump_packet.time[5] = (unsigned char) (time_management_regs->fine_time);
516 517 // SEND DATA
517 518 status = rtems_message_queue_send( queue_id, &parameter_dump_packet,
518 519 PACKET_LENGTH_PARAMETER_DUMP + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
519 520 if (status != RTEMS_SUCCESSFUL) {
520 521 PRINTF1("in action_dump *** ERR sending packet, code %d", status)
521 522 }
522 523
523 524 return status;
524 525 }
525 526
526 527 //***********************
527 528 // NORMAL MODE PARAMETERS
528 529
529 530 int check_normal_par_consistency( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
530 531 {
531 532 unsigned char msb;
532 533 unsigned char lsb;
533 534 int flag;
534 535 float aux;
535 536 rtems_status_code status;
536 537
537 538 unsigned int sy_lfr_n_swf_l;
538 539 unsigned int sy_lfr_n_swf_p;
539 540 unsigned int sy_lfr_n_asm_p;
540 541 unsigned char sy_lfr_n_bp_p0;
541 542 unsigned char sy_lfr_n_bp_p1;
542 543 unsigned char sy_lfr_n_cwf_long_f3;
543 544
544 545 flag = LFR_SUCCESSFUL;
545 546
546 547 //***************
547 548 // get parameters
548 549 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L ];
549 550 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L+1 ];
550 551 sy_lfr_n_swf_l = msb * 256 + lsb;
551 552
552 553 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P ];
553 554 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P+1 ];
554 555 sy_lfr_n_swf_p = msb * 256 + lsb;
555 556
556 557 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P ];
557 558 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P+1 ];
558 559 sy_lfr_n_asm_p = msb * 256 + lsb;
559 560
560 561 sy_lfr_n_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P0 ];
561 562
562 563 sy_lfr_n_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P1 ];
563 564
564 565 sy_lfr_n_cwf_long_f3 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_CWF_LONG_F3 ];
565 566
566 567 //******************
567 568 // check consistency
568 569 // sy_lfr_n_swf_l
569 570 if (sy_lfr_n_swf_l != 2048)
570 571 {
571 572 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_SWF_L+10, sy_lfr_n_swf_l );
572 573 flag = WRONG_APP_DATA;
573 574 }
574 575 // sy_lfr_n_swf_p
575 576 if (flag == LFR_SUCCESSFUL)
576 577 {
577 578 if ( sy_lfr_n_swf_p < 22 )
578 579 {
579 580 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_SWF_P+10, sy_lfr_n_swf_p );
580 581 flag = WRONG_APP_DATA;
581 582 }
582 583 }
583 584 // sy_lfr_n_bp_p0
584 585 if (flag == LFR_SUCCESSFUL)
585 586 {
586 587 if (sy_lfr_n_bp_p0 < DFLT_SY_LFR_N_BP_P0)
587 588 {
588 589 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P0+10, sy_lfr_n_bp_p0 );
589 590 flag = WRONG_APP_DATA;
590 591 }
591 592 }
592 593 // sy_lfr_n_asm_p
593 594 if (flag == LFR_SUCCESSFUL)
594 595 {
595 596 if (sy_lfr_n_asm_p == 0)
596 597 {
597 598 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_ASM_P+10, sy_lfr_n_asm_p );
598 599 flag = WRONG_APP_DATA;
599 600 }
600 601 }
601 602 // sy_lfr_n_asm_p shall be a whole multiple of sy_lfr_n_bp_p0
602 603 if (flag == LFR_SUCCESSFUL)
603 604 {
604 605 aux = ( (float ) sy_lfr_n_asm_p / sy_lfr_n_bp_p0 ) - floor(sy_lfr_n_asm_p / sy_lfr_n_bp_p0);
605 606 if (aux > FLOAT_EQUAL_ZERO)
606 607 {
607 608 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_ASM_P+10, sy_lfr_n_asm_p );
608 609 flag = WRONG_APP_DATA;
609 610 }
610 611 }
611 612 // sy_lfr_n_bp_p1
612 613 if (flag == LFR_SUCCESSFUL)
613 614 {
614 615 if (sy_lfr_n_bp_p1 < DFLT_SY_LFR_N_BP_P1)
615 616 {
616 617 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P1+10, sy_lfr_n_bp_p1 );
617 618 flag = WRONG_APP_DATA;
618 619 }
619 620 }
620 621 // sy_lfr_n_bp_p1 shall be a whole multiple of sy_lfr_n_bp_p0
621 622 if (flag == LFR_SUCCESSFUL)
622 623 {
623 624 aux = ( (float ) sy_lfr_n_bp_p1 / sy_lfr_n_bp_p0 ) - floor(sy_lfr_n_bp_p1 / sy_lfr_n_bp_p0);
624 625 if (aux > FLOAT_EQUAL_ZERO)
625 626 {
626 627 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P1+10, sy_lfr_n_bp_p1 );
627 628 flag = LFR_DEFAULT;
628 629 }
629 630 }
630 631 // sy_lfr_n_cwf_long_f3
631 632
632 633 return flag;
633 634 }
634 635
635 636 int set_sy_lfr_n_swf_l( ccsdsTelecommandPacket_t *TC )
636 637 {
637 638 /** This function sets the number of points of a snapshot (sy_lfr_n_swf_l).
638 639 *
639 640 * @param TC points to the TeleCommand packet that is being processed
640 641 * @param queue_id is the id of the queue which handles TM related to this execution step
641 642 *
642 643 */
643 644
644 645 int result;
645 646
646 647 result = LFR_SUCCESSFUL;
647 648
648 649 parameter_dump_packet.sy_lfr_n_swf_l[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L ];
649 650 parameter_dump_packet.sy_lfr_n_swf_l[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L+1 ];
650 651
651 652 return result;
652 653 }
653 654
654 655 int set_sy_lfr_n_swf_p(ccsdsTelecommandPacket_t *TC )
655 656 {
656 657 /** This function sets the time between two snapshots, in s (sy_lfr_n_swf_p).
657 658 *
658 659 * @param TC points to the TeleCommand packet that is being processed
659 660 * @param queue_id is the id of the queue which handles TM related to this execution step
660 661 *
661 662 */
662 663
663 664 int result;
664 665
665 666 result = LFR_SUCCESSFUL;
666 667
667 668 parameter_dump_packet.sy_lfr_n_swf_p[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P ];
668 669 parameter_dump_packet.sy_lfr_n_swf_p[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P+1 ];
669 670
670 671 return result;
671 672 }
672 673
673 674 int set_sy_lfr_n_asm_p( ccsdsTelecommandPacket_t *TC )
674 675 {
675 676 /** This function sets the time between two full spectral matrices transmission, in s (SY_LFR_N_ASM_P).
676 677 *
677 678 * @param TC points to the TeleCommand packet that is being processed
678 679 * @param queue_id is the id of the queue which handles TM related to this execution step
679 680 *
680 681 */
681 682
682 683 int result;
683 684
684 685 result = LFR_SUCCESSFUL;
685 686
686 687 parameter_dump_packet.sy_lfr_n_asm_p[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P ];
687 688 parameter_dump_packet.sy_lfr_n_asm_p[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P+1 ];
688 689
689 690 return result;
690 691 }
691 692
692 693 int set_sy_lfr_n_bp_p0( ccsdsTelecommandPacket_t *TC )
693 694 {
694 695 /** This function sets the time between two basic parameter sets, in s (DFLT_SY_LFR_N_BP_P0).
695 696 *
696 697 * @param TC points to the TeleCommand packet that is being processed
697 698 * @param queue_id is the id of the queue which handles TM related to this execution step
698 699 *
699 700 */
700 701
701 702 int status;
702 703
703 704 status = LFR_SUCCESSFUL;
704 705
705 706 parameter_dump_packet.sy_lfr_n_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P0 ];
706 707
707 708 return status;
708 709 }
709 710
710 711 int set_sy_lfr_n_bp_p1(ccsdsTelecommandPacket_t *TC )
711 712 {
712 713 /** This function sets the time between two basic parameter sets (autocorrelation + crosscorrelation), in s (sy_lfr_n_bp_p1).
713 714 *
714 715 * @param TC points to the TeleCommand packet that is being processed
715 716 * @param queue_id is the id of the queue which handles TM related to this execution step
716 717 *
717 718 */
718 719
719 720 int status;
720 721
721 722 status = LFR_SUCCESSFUL;
722 723
723 724 parameter_dump_packet.sy_lfr_n_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P1 ];
724 725
725 726 return status;
726 727 }
727 728
728 729 int set_sy_lfr_n_cwf_long_f3(ccsdsTelecommandPacket_t *TC )
729 730 {
730 731 /** This function allows to switch from CWF_F3 packets to CWF_LONG_F3 packets.
731 732 *
732 733 * @param TC points to the TeleCommand packet that is being processed
733 734 * @param queue_id is the id of the queue which handles TM related to this execution step
734 735 *
735 736 */
736 737
737 738 int status;
738 739
739 740 status = LFR_SUCCESSFUL;
740 741
741 742 parameter_dump_packet.sy_lfr_n_cwf_long_f3 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_CWF_LONG_F3 ];
742 743
743 744 return status;
744 745 }
745 746
746 747 //**********************
747 748 // BURST MODE PARAMETERS
748 749 int set_sy_lfr_b_bp_p0(ccsdsTelecommandPacket_t *TC)
749 750 {
750 751 /** This function sets the time between two basic parameter sets, in s (SY_LFR_B_BP_P0).
751 752 *
752 753 * @param TC points to the TeleCommand packet that is being processed
753 754 * @param queue_id is the id of the queue which handles TM related to this execution step
754 755 *
755 756 */
756 757
757 758 int status;
758 759
759 760 status = LFR_SUCCESSFUL;
760 761
761 762 parameter_dump_packet.sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
762 763
763 764 return status;
764 765 }
765 766
766 767 int set_sy_lfr_b_bp_p1( ccsdsTelecommandPacket_t *TC )
767 768 {
768 769 /** This function sets the time between two basic parameter sets, in s (SY_LFR_B_BP_P1).
769 770 *
770 771 * @param TC points to the TeleCommand packet that is being processed
771 772 * @param queue_id is the id of the queue which handles TM related to this execution step
772 773 *
773 774 */
774 775
775 776 int status;
776 777
777 778 status = LFR_SUCCESSFUL;
778 779
779 780 parameter_dump_packet.sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
780 781
781 782 return status;
782 783 }
783 784
784 785 //*********************
785 786 // SBM1 MODE PARAMETERS
786 787 int set_sy_lfr_s1_bp_p0( ccsdsTelecommandPacket_t *TC )
787 788 {
788 789 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S1_BP_P0).
789 790 *
790 791 * @param TC points to the TeleCommand packet that is being processed
791 792 * @param queue_id is the id of the queue which handles TM related to this execution step
792 793 *
793 794 */
794 795
795 796 int status;
796 797
797 798 status = LFR_SUCCESSFUL;
798 799
799 800 parameter_dump_packet.sy_lfr_s1_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P0 ];
800 801
801 802 return status;
802 803 }
803 804
804 805 int set_sy_lfr_s1_bp_p1( ccsdsTelecommandPacket_t *TC )
805 806 {
806 807 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S1_BP_P1).
807 808 *
808 809 * @param TC points to the TeleCommand packet that is being processed
809 810 * @param queue_id is the id of the queue which handles TM related to this execution step
810 811 *
811 812 */
812 813
813 814 int status;
814 815
815 816 status = LFR_SUCCESSFUL;
816 817
817 818 parameter_dump_packet.sy_lfr_s1_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P1 ];
818 819
819 820 return status;
820 821 }
821 822
822 823 //*********************
823 824 // SBM2 MODE PARAMETERS
824 825 int set_sy_lfr_s2_bp_p0( ccsdsTelecommandPacket_t *TC )
825 826 {
826 827 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S2_BP_P0).
827 828 *
828 829 * @param TC points to the TeleCommand packet that is being processed
829 830 * @param queue_id is the id of the queue which handles TM related to this execution step
830 831 *
831 832 */
832 833
833 834 int status;
834 835
835 836 status = LFR_SUCCESSFUL;
836 837
837 838 parameter_dump_packet.sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
838 839
839 840 return status;
840 841 }
841 842
842 843 int set_sy_lfr_s2_bp_p1( ccsdsTelecommandPacket_t *TC )
843 844 {
844 845 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S2_BP_P1).
845 846 *
846 847 * @param TC points to the TeleCommand packet that is being processed
847 848 * @param queue_id is the id of the queue which handles TM related to this execution step
848 849 *
849 850 */
850 851
851 852 int status;
852 853
853 854 status = LFR_SUCCESSFUL;
854 855
855 856 parameter_dump_packet.sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
856 857
857 858 return status;
858 859 }
859 860
860 861 //*******************
861 862 // TC_LFR_UPDATE_INFO
862 863 unsigned int check_update_info_hk_lfr_mode( unsigned char mode )
863 864 {
864 865 unsigned int status;
865 866
866 867 if ( (mode == LFR_MODE_STANDBY) || (mode == LFR_MODE_NORMAL)
867 868 || (mode == LFR_MODE_BURST)
868 869 || (mode == LFR_MODE_SBM1) || (mode == LFR_MODE_SBM2))
869 870 {
870 871 status = LFR_SUCCESSFUL;
871 872 }
872 873 else
873 874 {
874 875 status = LFR_DEFAULT;
875 876 }
876 877
877 878 return status;
878 879 }
879 880
880 881 unsigned int check_update_info_hk_tds_mode( unsigned char mode )
881 882 {
882 883 unsigned int status;
883 884
884 885 if ( (mode == TDS_MODE_STANDBY) || (mode == TDS_MODE_NORMAL)
885 886 || (mode == TDS_MODE_BURST)
886 887 || (mode == TDS_MODE_SBM1) || (mode == TDS_MODE_SBM2)
887 888 || (mode == TDS_MODE_LFM))
888 889 {
889 890 status = LFR_SUCCESSFUL;
890 891 }
891 892 else
892 893 {
893 894 status = LFR_DEFAULT;
894 895 }
895 896
896 897 return status;
897 898 }
898 899
899 900 unsigned int check_update_info_hk_thr_mode( unsigned char mode )
900 901 {
901 902 unsigned int status;
902 903
903 904 if ( (mode == THR_MODE_STANDBY) || (mode == THR_MODE_NORMAL)
904 905 || (mode == THR_MODE_BURST))
905 906 {
906 907 status = LFR_SUCCESSFUL;
907 908 }
908 909 else
909 910 {
910 911 status = LFR_DEFAULT;
911 912 }
912 913
913 914 return status;
914 915 }
915 916
916 917 void getReactionWheelsFrequencies( ccsdsTelecommandPacket_t *TC )
917 918 {
918 919 /** This function get the reaction wheels frequencies in the incoming TC_LFR_UPDATE_INFO and copy the values locally.
919 920 *
920 921 * @param TC points to the TeleCommand packet that is being processed
921 922 *
922 923 */
923 924
924 925 unsigned char * bytePosPtr; // pointer to the beginning of the incoming TC packet
925 926
926 927 bytePosPtr = (unsigned char *) &TC->packetID;
927 928
928 929 // cp_rpw_sc_rw1_f1
929 930 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw1_f1,
930 931 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F1 ] );
931 932
932 933 // cp_rpw_sc_rw1_f2
933 934 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw1_f2,
934 935 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F2 ] );
935 936
936 937 // cp_rpw_sc_rw2_f1
937 938 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw2_f1,
938 939 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F1 ] );
939 940
940 941 // cp_rpw_sc_rw2_f2
941 942 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw2_f2,
942 943 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F2 ] );
943 944
944 945 // cp_rpw_sc_rw3_f1
945 946 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw3_f1,
946 947 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F1 ] );
947 948
948 949 // cp_rpw_sc_rw3_f2
949 950 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw3_f2,
950 951 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F2 ] );
951 952
952 953 // cp_rpw_sc_rw4_f1
953 954 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw4_f1,
954 955 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F1 ] );
955 956
956 957 // cp_rpw_sc_rw4_f2
957 958 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw4_f2,
958 959 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F2 ] );
959 960 }
960 961
961 962 void setFBinMask( unsigned char *fbins_mask, float rw_f, unsigned char deltaFreq, unsigned char flag )
962 963 {
963 964 /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received.
964 965 *
965 966 * @param fbins_mask
966 967 * @param rw_f is the reaction wheel frequency to filter
967 968 * @param delta_f is the frequency step between the frequency bins, it depends on the frequency channel
968 969 * @param flag [true] filtering enabled [false] filtering disabled
969 970 *
970 971 * @return void
971 972 *
972 973 */
973 974
974 975 float fmin;
975 976 float fMAX;
976 977 int binBelow;
977 978 int binAbove;
978 979 unsigned int whichByte;
979 980 unsigned char selectedByte;
980 981 int bin;
981 982
982 983 whichByte = 0;
983 984 bin = 0;
984 985
985 986 // compute the frequency range to filter [ rw_f - delta_f/2; rw_f + delta_f/2 ]
986 987 fmin = rw_f - filterPar.sy_lfr_sc_rw_delta_f / 2.;
987 988 fMAX = rw_f + filterPar.sy_lfr_sc_rw_delta_f / 2.;
988 989
989 990 // compute the index of the frequency bin immediately below fmin
990 991 binBelow = (int) ( floor( ((double) fmin) / ((double) deltaFreq)) );
991 992
992 993 // compute the index of the frequency bin immediately above fMAX
993 994 binAbove = (int) ( floor( ((double) fMAX) / ((double) deltaFreq)) );
994 995
995 996 for (bin = binBelow; bin <= binAbove; bin++)
996 997 {
997 998 if ( (bin >= 0) && (bin<=127) )
998 999 {
999 1000 if (flag == 1)
1000 1001 {
1001 1002 whichByte = bin >> 3; // division by 8
1002 1003 selectedByte = (unsigned char) ( 1 << (bin - (whichByte * 8)) );
1003 1004 fbins_mask[whichByte] = fbins_mask[whichByte] & (~selectedByte);
1004 1005 }
1005 1006 }
1006 1007 }
1007 1008 }
1008 1009
1009 1010 void build_sy_lfr_rw_mask( unsigned int channel )
1010 1011 {
1011 1012 unsigned char local_rw_fbins_mask[16];
1012 1013 unsigned char *maskPtr;
1013 1014 double deltaF;
1014 1015 unsigned k;
1015 1016
1016 1017 k = 0;
1017 1018
1018 1019 maskPtr = NULL;
1019 1020 deltaF = 1.;
1020 1021
1021 1022 switch (channel)
1022 1023 {
1023 1024 case 0:
1024 1025 maskPtr = parameter_dump_packet.sy_lfr_rw_mask_f0_word1;
1025 1026 deltaF = 96.;
1026 1027 break;
1027 1028 case 1:
1028 1029 maskPtr = parameter_dump_packet.sy_lfr_rw_mask_f1_word1;
1029 1030 deltaF = 16.;
1030 1031 break;
1031 1032 case 2:
1032 1033 maskPtr = parameter_dump_packet.sy_lfr_rw_mask_f2_word1;
1033 1034 deltaF = 1.;
1034 1035 break;
1035 1036 default:
1036 1037 break;
1037 1038 }
1038 1039
1039 1040 for (k = 0; k < 16; k++)
1040 1041 {
1041 1042 local_rw_fbins_mask[k] = 0xff;
1042 1043 }
1043 1044
1044 1045 // RW1 F1
1045 1046 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw1_f1, deltaF, (cp_rpw_sc_rw_f_flags & 0x80) >> 7 ); // [1000 0000]
1046 1047
1047 1048 // RW1 F2
1048 1049 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw1_f2, deltaF, (cp_rpw_sc_rw_f_flags & 0x40) >> 6 ); // [0100 0000]
1049 1050
1050 1051 // RW2 F1
1051 1052 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw2_f1, deltaF, (cp_rpw_sc_rw_f_flags & 0x20) >> 5 ); // [0010 0000]
1052 1053
1053 1054 // RW2 F2
1054 1055 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw2_f2, deltaF, (cp_rpw_sc_rw_f_flags & 0x10) >> 4 ); // [0001 0000]
1055 1056
1056 1057 // RW3 F1
1057 1058 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw3_f1, deltaF, (cp_rpw_sc_rw_f_flags & 0x08) >> 3 ); // [0000 1000]
1058 1059
1059 1060 // RW3 F2
1060 1061 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw3_f2, deltaF, (cp_rpw_sc_rw_f_flags & 0x04) >> 2 ); // [0000 0100]
1061 1062
1062 1063 // RW4 F1
1063 1064 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw4_f1, deltaF, (cp_rpw_sc_rw_f_flags & 0x02) >> 1 ); // [0000 0010]
1064 1065
1065 1066 // RW4 F2
1066 1067 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw1_f1, deltaF, (cp_rpw_sc_rw_f_flags & 0x01) ); // [0000 0001]
1067 1068
1068 1069 // update the value of the fbins related to reaction wheels frequency filtering
1069 1070 if (maskPtr != NULL)
1070 1071 {
1071 1072 for (k = 0; k < 16; k++)
1072 1073 {
1073 1074 maskPtr[k] = local_rw_fbins_mask[k];
1074 1075 }
1075 1076 }
1076 1077 }
1077 1078
1078 1079 void build_sy_lfr_rw_masks( void )
1079 1080 {
1080 1081 build_sy_lfr_rw_mask( 0 );
1081 1082 build_sy_lfr_rw_mask( 1 );
1082 1083 build_sy_lfr_rw_mask( 2 );
1083 1084
1084 1085 merge_fbins_masks();
1085 1086 }
1086 1087
1087 1088 void merge_fbins_masks( void )
1088 1089 {
1089 1090 unsigned char k;
1090 1091
1091 1092 unsigned char *fbins_f0;
1092 1093 unsigned char *fbins_f1;
1093 1094 unsigned char *fbins_f2;
1094 1095 unsigned char *rw_mask_f0;
1095 1096 unsigned char *rw_mask_f1;
1096 1097 unsigned char *rw_mask_f2;
1097 1098
1098 1099 fbins_f0 = parameter_dump_packet.sy_lfr_fbins_f0_word1;
1099 1100 fbins_f1 = parameter_dump_packet.sy_lfr_fbins_f1_word1;
1100 1101 fbins_f2 = parameter_dump_packet.sy_lfr_fbins_f2_word1;
1101 1102 rw_mask_f0 = parameter_dump_packet.sy_lfr_rw_mask_f0_word1;
1102 1103 rw_mask_f1 = parameter_dump_packet.sy_lfr_rw_mask_f1_word1;
1103 1104 rw_mask_f2 = parameter_dump_packet.sy_lfr_rw_mask_f2_word1;
1104 1105
1105 1106 for( k=0; k < 16; k++ )
1106 1107 {
1107 1108 fbins_masks.merged_fbins_mask_f0[k] = fbins_f0[k] & rw_mask_f0[k];
1108 1109 fbins_masks.merged_fbins_mask_f1[k] = fbins_f1[k] & rw_mask_f1[k];
1109 1110 fbins_masks.merged_fbins_mask_f2[k] = fbins_f2[k] & rw_mask_f2[k];
1110 1111 }
1111 1112 }
1112 1113
1113 1114 //***********
1114 1115 // FBINS MASK
1115 1116
1116 1117 int set_sy_lfr_fbins( ccsdsTelecommandPacket_t *TC )
1117 1118 {
1118 1119 int status;
1119 1120 unsigned int k;
1120 1121 unsigned char *fbins_mask_dump;
1121 1122 unsigned char *fbins_mask_TC;
1122 1123
1123 1124 status = LFR_SUCCESSFUL;
1124 1125
1125 1126 fbins_mask_dump = parameter_dump_packet.sy_lfr_fbins_f0_word1;
1126 1127 fbins_mask_TC = TC->dataAndCRC;
1127 1128
1128 1129 for (k=0; k < NB_FBINS_MASKS * NB_BYTES_PER_FBINS_MASK; k++)
1129 1130 {
1130 1131 fbins_mask_dump[k] = fbins_mask_TC[k];
1131 1132 }
1132 1133
1133 1134 return status;
1134 1135 }
1135 1136
1136 1137 //***************************
1137 1138 // TC_LFR_LOAD_PAS_FILTER_PAR
1138 1139
1139 1140 int check_sy_lfr_filter_parameters( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
1140 1141 {
1141 1142 int flag;
1142 1143 rtems_status_code status;
1143 1144
1144 1145 unsigned char sy_lfr_pas_filter_enabled;
1145 1146 unsigned char sy_lfr_pas_filter_modulus;
1146 1147 float sy_lfr_pas_filter_tbad;
1147 1148 unsigned char sy_lfr_pas_filter_offset;
1148 1149 float sy_lfr_pas_filter_shift;
1149 1150 float sy_lfr_sc_rw_delta_f;
1150 1151 char *parPtr;
1151 1152
1152 1153 flag = LFR_SUCCESSFUL;
1153 1154 sy_lfr_pas_filter_tbad = 0.0;
1154 1155 sy_lfr_pas_filter_shift = 0.0;
1155 1156 sy_lfr_sc_rw_delta_f = 0.0;
1156 1157 parPtr = NULL;
1157 1158
1158 1159 //***************
1159 1160 // get parameters
1160 1161 sy_lfr_pas_filter_enabled = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_ENABLED ] & 0x01; // [0000 0001]
1161 1162 sy_lfr_pas_filter_modulus = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS ];
1162 1163 copyFloatByChar(
1163 1164 (unsigned char*) &sy_lfr_pas_filter_tbad,
1164 1165 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD ]
1165 1166 );
1166 1167 sy_lfr_pas_filter_offset = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET ];
1167 1168 copyFloatByChar(
1168 1169 (unsigned char*) &sy_lfr_pas_filter_shift,
1169 1170 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT ]
1170 1171 );
1171 1172 copyFloatByChar(
1172 1173 (unsigned char*) &sy_lfr_sc_rw_delta_f,
1173 1174 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F ]
1174 1175 );
1175 1176
1176 1177 //******************
1177 1178 // CHECK CONSISTENCY
1178 1179
1179 1180 //**************************
1180 1181 // sy_lfr_pas_filter_enabled
1181 1182 // nothing to check, value is 0 or 1
1182 1183
1183 1184 //**************************
1184 1185 // sy_lfr_pas_filter_modulus
1185 1186 if ( (sy_lfr_pas_filter_modulus < 4) || (sy_lfr_pas_filter_modulus > 8) )
1186 1187 {
1187 1188 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS+10, sy_lfr_pas_filter_modulus );
1188 1189 flag = WRONG_APP_DATA;
1189 1190 }
1190 1191
1191 1192 //***********************
1192 1193 // sy_lfr_pas_filter_tbad
1193 1194 if ( (sy_lfr_pas_filter_tbad < 0.0) || (sy_lfr_pas_filter_tbad > 4.0) )
1194 1195 {
1195 1196 parPtr = (char*) &sy_lfr_pas_filter_tbad;
1196 1197 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD+10, parPtr[3] );
1197 1198 flag = WRONG_APP_DATA;
1198 1199 }
1199 1200
1200 1201 //*************************
1201 1202 // sy_lfr_pas_filter_offset
1202 1203 if (flag == LFR_SUCCESSFUL)
1203 1204 {
1204 1205 if ( (sy_lfr_pas_filter_offset < 0) || (sy_lfr_pas_filter_offset > 7) )
1205 1206 {
1206 1207 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET+10, sy_lfr_pas_filter_offset );
1207 1208 flag = WRONG_APP_DATA;
1208 1209 }
1209 1210 }
1210 1211
1211 1212 //************************
1212 1213 // sy_lfr_pas_filter_shift
1213 1214 if ( (sy_lfr_pas_filter_shift < 0.0) || (sy_lfr_pas_filter_shift > 1.0) )
1214 1215 {
1215 1216 parPtr = (char*) &sy_lfr_pas_filter_shift;
1216 1217 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT+10, parPtr[3] );
1217 1218 flag = WRONG_APP_DATA;
1218 1219 }
1219 1220
1220 1221 //*********************
1221 1222 // sy_lfr_sc_rw_delta_f
1222 1223 // nothing to check, no default value in the ICD
1223 1224
1224 1225 return flag;
1225 1226 }
1226 1227
1227 1228 //**************
1228 1229 // KCOEFFICIENTS
1229 1230 int set_sy_lfr_kcoeff( ccsdsTelecommandPacket_t *TC,rtems_id queue_id )
1230 1231 {
1231 1232 unsigned int kcoeff;
1232 1233 unsigned short sy_lfr_kcoeff_frequency;
1233 1234 unsigned short bin;
1234 1235 unsigned short *freqPtr;
1235 1236 float *kcoeffPtr_norm;
1236 1237 float *kcoeffPtr_sbm;
1237 1238 int status;
1238 1239 unsigned char *kcoeffLoadPtr;
1239 1240 unsigned char *kcoeffNormPtr;
1240 1241 unsigned char *kcoeffSbmPtr_a;
1241 1242 unsigned char *kcoeffSbmPtr_b;
1242 1243
1243 1244 status = LFR_SUCCESSFUL;
1244 1245
1245 1246 kcoeffPtr_norm = NULL;
1246 1247 kcoeffPtr_sbm = NULL;
1247 1248 bin = 0;
1248 1249
1249 1250 freqPtr = (unsigned short *) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY];
1250 1251 sy_lfr_kcoeff_frequency = *freqPtr;
1251 1252
1252 1253 if ( sy_lfr_kcoeff_frequency >= NB_BINS_COMPRESSED_SM )
1253 1254 {
1254 1255 PRINTF1("ERR *** in set_sy_lfr_kcoeff_frequency *** sy_lfr_kcoeff_frequency = %d\n", sy_lfr_kcoeff_frequency)
1255 1256 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY + 10 + 1,
1256 1257 TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY + 1] ); // +1 to get the LSB instead of the MSB
1257 1258 status = LFR_DEFAULT;
1258 1259 }
1259 1260 else
1260 1261 {
1261 1262 if ( ( sy_lfr_kcoeff_frequency >= 0 )
1262 1263 && ( sy_lfr_kcoeff_frequency < NB_BINS_COMPRESSED_SM_F0 ) )
1263 1264 {
1264 1265 kcoeffPtr_norm = k_coeff_intercalib_f0_norm;
1265 1266 kcoeffPtr_sbm = k_coeff_intercalib_f0_sbm;
1266 1267 bin = sy_lfr_kcoeff_frequency;
1267 1268 }
1268 1269 else if ( ( sy_lfr_kcoeff_frequency >= NB_BINS_COMPRESSED_SM_F0 )
1269 1270 && ( sy_lfr_kcoeff_frequency < (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1) ) )
1270 1271 {
1271 1272 kcoeffPtr_norm = k_coeff_intercalib_f1_norm;
1272 1273 kcoeffPtr_sbm = k_coeff_intercalib_f1_sbm;
1273 1274 bin = sy_lfr_kcoeff_frequency - NB_BINS_COMPRESSED_SM_F0;
1274 1275 }
1275 1276 else if ( ( sy_lfr_kcoeff_frequency >= (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1) )
1276 1277 && ( sy_lfr_kcoeff_frequency < (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 + NB_BINS_COMPRESSED_SM_F2) ) )
1277 1278 {
1278 1279 kcoeffPtr_norm = k_coeff_intercalib_f2;
1279 1280 kcoeffPtr_sbm = NULL;
1280 1281 bin = sy_lfr_kcoeff_frequency - (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1);
1281 1282 }
1282 1283 }
1283 1284
1284 1285 if (kcoeffPtr_norm != NULL ) // update K coefficient for NORMAL data products
1285 1286 {
1286 1287 for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++)
1287 1288 {
1288 1289 // destination
1289 1290 kcoeffNormPtr = (unsigned char*) &kcoeffPtr_norm[ (bin * NB_K_COEFF_PER_BIN) + kcoeff ];
1290 1291 // source
1291 1292 kcoeffLoadPtr = (unsigned char*) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_1 + NB_BYTES_PER_FLOAT * kcoeff];
1292 1293 // copy source to destination
1293 1294 copyFloatByChar( kcoeffNormPtr, kcoeffLoadPtr );
1294 1295 }
1295 1296 }
1296 1297
1297 1298 if (kcoeffPtr_sbm != NULL ) // update K coefficient for SBM data products
1298 1299 {
1299 1300 for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++)
1300 1301 {
1301 1302 // destination
1302 1303 kcoeffSbmPtr_a= (unsigned char*) &kcoeffPtr_sbm[ ( (bin * NB_K_COEFF_PER_BIN) + kcoeff) * 2 ];
1303 1304 kcoeffSbmPtr_b= (unsigned char*) &kcoeffPtr_sbm[ ( (bin * NB_K_COEFF_PER_BIN) + kcoeff) * 2 + 1 ];
1304 1305 // source
1305 1306 kcoeffLoadPtr = (unsigned char*) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_1 + NB_BYTES_PER_FLOAT * kcoeff];
1306 1307 // copy source to destination
1307 1308 copyFloatByChar( kcoeffSbmPtr_a, kcoeffLoadPtr );
1308 1309 copyFloatByChar( kcoeffSbmPtr_b, kcoeffLoadPtr );
1309 1310 }
1310 1311 }
1311 1312
1312 1313 // print_k_coeff();
1313 1314
1314 1315 return status;
1315 1316 }
1316 1317
1317 1318 void copyFloatByChar( unsigned char *destination, unsigned char *source )
1318 1319 {
1319 1320 destination[0] = source[0];
1320 1321 destination[1] = source[1];
1321 1322 destination[2] = source[2];
1322 1323 destination[3] = source[3];
1323 1324 }
1324 1325
1325 1326 void floatToChar( float value, unsigned char* ptr)
1326 1327 {
1327 1328 unsigned char* valuePtr;
1328 1329
1329 1330 valuePtr = (unsigned char*) &value;
1330 1331 ptr[0] = valuePtr[0];
1331 1332 ptr[1] = valuePtr[0];
1332 1333 ptr[2] = valuePtr[0];
1333 1334 ptr[3] = valuePtr[0];
1334 1335 }
1335 1336
1336 1337 //**********
1337 1338 // init dump
1338 1339
1339 1340 void init_parameter_dump( void )
1340 1341 {
1341 1342 /** This function initialize the parameter_dump_packet global variable with default values.
1342 1343 *
1343 1344 */
1344 1345
1345 1346 unsigned int k;
1346 1347
1347 1348 parameter_dump_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
1348 1349 parameter_dump_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
1349 1350 parameter_dump_packet.reserved = CCSDS_RESERVED;
1350 1351 parameter_dump_packet.userApplication = CCSDS_USER_APP;
1351 1352 parameter_dump_packet.packetID[0] = (unsigned char) (APID_TM_PARAMETER_DUMP >> 8);
1352 1353 parameter_dump_packet.packetID[1] = (unsigned char) APID_TM_PARAMETER_DUMP;
1353 1354 parameter_dump_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1354 1355 parameter_dump_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1355 1356 parameter_dump_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_PARAMETER_DUMP >> 8);
1356 1357 parameter_dump_packet.packetLength[1] = (unsigned char) PACKET_LENGTH_PARAMETER_DUMP;
1357 1358 // DATA FIELD HEADER
1358 1359 parameter_dump_packet.spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
1359 1360 parameter_dump_packet.serviceType = TM_TYPE_PARAMETER_DUMP;
1360 1361 parameter_dump_packet.serviceSubType = TM_SUBTYPE_PARAMETER_DUMP;
1361 1362 parameter_dump_packet.destinationID = TM_DESTINATION_ID_GROUND;
1362 1363 parameter_dump_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
1363 1364 parameter_dump_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
1364 1365 parameter_dump_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
1365 1366 parameter_dump_packet.time[3] = (unsigned char) (time_management_regs->coarse_time);
1366 1367 parameter_dump_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
1367 1368 parameter_dump_packet.time[5] = (unsigned char) (time_management_regs->fine_time);
1368 1369 parameter_dump_packet.sid = SID_PARAMETER_DUMP;
1369 1370
1370 1371 //******************
1371 1372 // COMMON PARAMETERS
1372 1373 parameter_dump_packet.sy_lfr_common_parameters_spare = DEFAULT_SY_LFR_COMMON0;
1373 1374 parameter_dump_packet.sy_lfr_common_parameters = DEFAULT_SY_LFR_COMMON1;
1374 1375
1375 1376 //******************
1376 1377 // NORMAL PARAMETERS
1377 1378 parameter_dump_packet.sy_lfr_n_swf_l[0] = (unsigned char) (DFLT_SY_LFR_N_SWF_L >> 8);
1378 1379 parameter_dump_packet.sy_lfr_n_swf_l[1] = (unsigned char) (DFLT_SY_LFR_N_SWF_L );
1379 1380 parameter_dump_packet.sy_lfr_n_swf_p[0] = (unsigned char) (DFLT_SY_LFR_N_SWF_P >> 8);
1380 1381 parameter_dump_packet.sy_lfr_n_swf_p[1] = (unsigned char) (DFLT_SY_LFR_N_SWF_P );
1381 1382 parameter_dump_packet.sy_lfr_n_asm_p[0] = (unsigned char) (DFLT_SY_LFR_N_ASM_P >> 8);
1382 1383 parameter_dump_packet.sy_lfr_n_asm_p[1] = (unsigned char) (DFLT_SY_LFR_N_ASM_P );
1383 1384 parameter_dump_packet.sy_lfr_n_bp_p0 = (unsigned char) DFLT_SY_LFR_N_BP_P0;
1384 1385 parameter_dump_packet.sy_lfr_n_bp_p1 = (unsigned char) DFLT_SY_LFR_N_BP_P1;
1385 1386 parameter_dump_packet.sy_lfr_n_cwf_long_f3 = (unsigned char) DFLT_SY_LFR_N_CWF_LONG_F3;
1386 1387
1387 1388 //*****************
1388 1389 // BURST PARAMETERS
1389 1390 parameter_dump_packet.sy_lfr_b_bp_p0 = (unsigned char) DEFAULT_SY_LFR_B_BP_P0;
1390 1391 parameter_dump_packet.sy_lfr_b_bp_p1 = (unsigned char) DEFAULT_SY_LFR_B_BP_P1;
1391 1392
1392 1393 //****************
1393 1394 // SBM1 PARAMETERS
1394 1395 parameter_dump_packet.sy_lfr_s1_bp_p0 = (unsigned char) DEFAULT_SY_LFR_S1_BP_P0; // min value is 0.25 s for the period
1395 1396 parameter_dump_packet.sy_lfr_s1_bp_p1 = (unsigned char) DEFAULT_SY_LFR_S1_BP_P1;
1396 1397
1397 1398 //****************
1398 1399 // SBM2 PARAMETERS
1399 1400 parameter_dump_packet.sy_lfr_s2_bp_p0 = (unsigned char) DEFAULT_SY_LFR_S2_BP_P0;
1400 1401 parameter_dump_packet.sy_lfr_s2_bp_p1 = (unsigned char) DEFAULT_SY_LFR_S2_BP_P1;
1401 1402
1402 1403 //************
1403 1404 // FBINS MASKS
1404 1405 for (k=0; k < NB_FBINS_MASKS * NB_BYTES_PER_FBINS_MASK; k++)
1405 1406 {
1406 1407 parameter_dump_packet.sy_lfr_fbins_f0_word1[k] = 0xff;
1407 1408 }
1408 1409
1409 1410 // PAS FILTER PARAMETERS
1410 1411 parameter_dump_packet.pa_rpw_spare8_2 = 0x00;
1411 1412 parameter_dump_packet.spare_sy_lfr_pas_filter_enabled = 0x00;
1412 1413 parameter_dump_packet.sy_lfr_pas_filter_modulus = DEFAULT_SY_LFR_PAS_FILTER_MODULUS;
1413 1414 floatToChar( DEFAULT_SY_LFR_PAS_FILTER_TBAD, parameter_dump_packet.sy_lfr_pas_filter_tbad );
1414 1415 parameter_dump_packet.sy_lfr_pas_filter_offset = DEFAULT_SY_LFR_PAS_FILTER_OFFSET;
1415 1416 floatToChar( DEFAULT_SY_LFR_PAS_FILTER_SHIFT, parameter_dump_packet.sy_lfr_pas_filter_shift );
1416 1417 floatToChar( DEFAULT_SY_LFR_SC_RW_DELTA_F, parameter_dump_packet.sy_lfr_sc_rw_delta_f );
1417 1418
1418 1419 // LFR_RW_MASK
1419 1420 for (k=0; k < NB_FBINS_MASKS * NB_BYTES_PER_FBINS_MASK; k++)
1420 1421 {
1421 1422 parameter_dump_packet.sy_lfr_rw_mask_f0_word1[k] = 0xff;
1422 1423 }
1423 1424 }
1424 1425
1425 1426 void init_kcoefficients_dump( void )
1426 1427 {
1427 1428 init_kcoefficients_dump_packet( &kcoefficients_dump_1, 1, 30 );
1428 1429 init_kcoefficients_dump_packet( &kcoefficients_dump_2, 2, 6 );
1429 1430
1430 1431 kcoefficient_node_1.previous = NULL;
1431 1432 kcoefficient_node_1.next = NULL;
1432 1433 kcoefficient_node_1.sid = TM_CODE_K_DUMP;
1433 1434 kcoefficient_node_1.coarseTime = 0x00;
1434 1435 kcoefficient_node_1.fineTime = 0x00;
1435 1436 kcoefficient_node_1.buffer_address = (int) &kcoefficients_dump_1;
1436 1437 kcoefficient_node_1.status = 0x00;
1437 1438
1438 1439 kcoefficient_node_2.previous = NULL;
1439 1440 kcoefficient_node_2.next = NULL;
1440 1441 kcoefficient_node_2.sid = TM_CODE_K_DUMP;
1441 1442 kcoefficient_node_2.coarseTime = 0x00;
1442 1443 kcoefficient_node_2.fineTime = 0x00;
1443 1444 kcoefficient_node_2.buffer_address = (int) &kcoefficients_dump_2;
1444 1445 kcoefficient_node_2.status = 0x00;
1445 1446 }
1446 1447
1447 1448 void init_kcoefficients_dump_packet( Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump, unsigned char pkt_nr, unsigned char blk_nr )
1448 1449 {
1449 1450 unsigned int k;
1450 1451 unsigned int packetLength;
1451 1452
1452 1453 packetLength = blk_nr * 130 + 20 - CCSDS_TC_TM_PACKET_OFFSET; // 4 bytes for the CCSDS header
1453 1454
1454 1455 kcoefficients_dump->targetLogicalAddress = CCSDS_DESTINATION_ID;
1455 1456 kcoefficients_dump->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1456 1457 kcoefficients_dump->reserved = CCSDS_RESERVED;
1457 1458 kcoefficients_dump->userApplication = CCSDS_USER_APP;
1458 1459 kcoefficients_dump->packetID[0] = (unsigned char) (APID_TM_PARAMETER_DUMP >> 8);;
1459 1460 kcoefficients_dump->packetID[1] = (unsigned char) APID_TM_PARAMETER_DUMP;;
1460 1461 kcoefficients_dump->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1461 1462 kcoefficients_dump->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1462 1463 kcoefficients_dump->packetLength[0] = (unsigned char) (packetLength >> 8);
1463 1464 kcoefficients_dump->packetLength[1] = (unsigned char) packetLength;
1464 1465 // DATA FIELD HEADER
1465 1466 kcoefficients_dump->spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
1466 1467 kcoefficients_dump->serviceType = TM_TYPE_K_DUMP;
1467 1468 kcoefficients_dump->serviceSubType = TM_SUBTYPE_K_DUMP;
1468 1469 kcoefficients_dump->destinationID= TM_DESTINATION_ID_GROUND;
1469 1470 kcoefficients_dump->time[0] = 0x00;
1470 1471 kcoefficients_dump->time[1] = 0x00;
1471 1472 kcoefficients_dump->time[2] = 0x00;
1472 1473 kcoefficients_dump->time[3] = 0x00;
1473 1474 kcoefficients_dump->time[4] = 0x00;
1474 1475 kcoefficients_dump->time[5] = 0x00;
1475 1476 kcoefficients_dump->sid = SID_K_DUMP;
1476 1477
1477 1478 kcoefficients_dump->pkt_cnt = 2;
1478 1479 kcoefficients_dump->pkt_nr = pkt_nr;
1479 1480 kcoefficients_dump->blk_nr = blk_nr;
1480 1481
1481 1482 //******************
1482 1483 // SOURCE DATA repeated N times with N in [0 .. PA_LFR_KCOEFF_BLK_NR]
1483 1484 // one blk is 2 + 4 * 32 = 130 bytes, 30 blks max in one packet (30 * 130 = 3900)
1484 1485 for (k=0; k<3900; k++)
1485 1486 {
1486 1487 kcoefficients_dump->kcoeff_blks[k] = 0x00;
1487 1488 }
1488 1489 }
1489 1490
1490 1491 void increment_seq_counter_destination_id_dump( unsigned char *packet_sequence_control, unsigned char destination_id )
1491 1492 {
1492 1493 /** This function increment the packet sequence control parameter of a TC, depending on its destination ID.
1493 1494 *
1494 1495 * @param packet_sequence_control points to the packet sequence control which will be incremented
1495 1496 * @param destination_id is the destination ID of the TM, there is one counter by destination ID
1496 1497 *
1497 1498 * If the destination ID is not known, a dedicated counter is incremented.
1498 1499 *
1499 1500 */
1500 1501
1501 1502 unsigned short sequence_cnt;
1502 1503 unsigned short segmentation_grouping_flag;
1503 1504 unsigned short new_packet_sequence_control;
1504 1505 unsigned char i;
1505 1506
1506 1507 switch (destination_id)
1507 1508 {
1508 1509 case SID_TC_GROUND:
1509 1510 i = GROUND;
1510 1511 break;
1511 1512 case SID_TC_MISSION_TIMELINE:
1512 1513 i = MISSION_TIMELINE;
1513 1514 break;
1514 1515 case SID_TC_TC_SEQUENCES:
1515 1516 i = TC_SEQUENCES;
1516 1517 break;
1517 1518 case SID_TC_RECOVERY_ACTION_CMD:
1518 1519 i = RECOVERY_ACTION_CMD;
1519 1520 break;
1520 1521 case SID_TC_BACKUP_MISSION_TIMELINE:
1521 1522 i = BACKUP_MISSION_TIMELINE;
1522 1523 break;
1523 1524 case SID_TC_DIRECT_CMD:
1524 1525 i = DIRECT_CMD;
1525 1526 break;
1526 1527 case SID_TC_SPARE_GRD_SRC1:
1527 1528 i = SPARE_GRD_SRC1;
1528 1529 break;
1529 1530 case SID_TC_SPARE_GRD_SRC2:
1530 1531 i = SPARE_GRD_SRC2;
1531 1532 break;
1532 1533 case SID_TC_OBCP:
1533 1534 i = OBCP;
1534 1535 break;
1535 1536 case SID_TC_SYSTEM_CONTROL:
1536 1537 i = SYSTEM_CONTROL;
1537 1538 break;
1538 1539 case SID_TC_AOCS:
1539 1540 i = AOCS;
1540 1541 break;
1541 1542 case SID_TC_RPW_INTERNAL:
1542 1543 i = RPW_INTERNAL;
1543 1544 break;
1544 1545 default:
1545 1546 i = GROUND;
1546 1547 break;
1547 1548 }
1548 1549
1549 1550 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << 8;
1550 1551 sequence_cnt = sequenceCounters_TM_DUMP[ i ] & 0x3fff;
1551 1552
1552 1553 new_packet_sequence_control = segmentation_grouping_flag | sequence_cnt ;
1553 1554
1554 1555 packet_sequence_control[0] = (unsigned char) (new_packet_sequence_control >> 8);
1555 1556 packet_sequence_control[1] = (unsigned char) (new_packet_sequence_control );
1556 1557
1557 1558 // increment the sequence counter
1558 1559 if ( sequenceCounters_TM_DUMP[ i ] < SEQ_CNT_MAX )
1559 1560 {
1560 1561 sequenceCounters_TM_DUMP[ i ] = sequenceCounters_TM_DUMP[ i ] + 1;
1561 1562 }
1562 1563 else
1563 1564 {
1564 1565 sequenceCounters_TM_DUMP[ i ] = 0;
1565 1566 }
1566 1567 }
General Comments 0
You need to be logged in to leave comments. Login now