##// END OF EJS Templates
2.0.2.2...
paul -
r187:87f7d2226935 VHDL_0_1_28
parent child
Show More
@@ -1,2 +1,2
1 1 a586fe639ac179e95bdc150ebdbab0312f31dc30 LFR_basic-parameters
2 6d02d4b02291d2b25c387fa74037dc7929cd92b5 header/lfr_common_headers
2 be0dc1c1876987307ddfc0fb47044f6d41815866 header/lfr_common_headers
@@ -1,112 +1,112
1 1 TEMPLATE = app
2 2 # CONFIG += console v8 sim
3 3 # CONFIG options = verbose *** boot_messages *** debug_messages *** cpu_usage_report *** stack_report *** vhdl_dev *** debug_tch
4 4 # lpp_dpu_destid
5 5 CONFIG += console verbose lpp_dpu_destid
6 6 CONFIG -= qt
7 7
8 8 include(./sparc.pri)
9 9
10 10 # flight software version
11 11 SWVERSION=-1-0
12 12 DEFINES += SW_VERSION_N1=2 # major
13 13 DEFINES += SW_VERSION_N2=0 # minor
14 14 DEFINES += SW_VERSION_N3=2 # patch
15 DEFINES += SW_VERSION_N4=1 # internal
15 DEFINES += SW_VERSION_N4=2 # internal
16 16
17 17 # <GCOV>
18 18 #QMAKE_CFLAGS_RELEASE += -fprofile-arcs -ftest-coverage
19 19 #LIBS += -lgcov /opt/GCOV/01A/lib/overload.o -lc
20 20 # </GCOV>
21 21
22 22 # <CHANGE BEFORE FLIGHT>
23 23 contains( CONFIG, lpp_dpu_destid ) {
24 24 DEFINES += LPP_DPU_DESTID
25 25 }
26 26 # </CHANGE BEFORE FLIGHT>
27 27
28 28 contains( CONFIG, debug_tch ) {
29 29 DEFINES += DEBUG_TCH
30 30 }
31 31 DEFINES += MSB_FIRST_TCH
32 32
33 33 contains( CONFIG, vhdl_dev ) {
34 34 DEFINES += VHDL_DEV
35 35 }
36 36
37 37 contains( CONFIG, verbose ) {
38 38 DEFINES += PRINT_MESSAGES_ON_CONSOLE
39 39 }
40 40
41 41 contains( CONFIG, debug_messages ) {
42 42 DEFINES += DEBUG_MESSAGES
43 43 }
44 44
45 45 contains( CONFIG, cpu_usage_report ) {
46 46 DEFINES += PRINT_TASK_STATISTICS
47 47 }
48 48
49 49 contains( CONFIG, stack_report ) {
50 50 DEFINES += PRINT_STACK_REPORT
51 51 }
52 52
53 53 contains( CONFIG, boot_messages ) {
54 54 DEFINES += BOOT_MESSAGES
55 55 }
56 56
57 57 #doxygen.target = doxygen
58 58 #doxygen.commands = doxygen ../doc/Doxyfile
59 59 #QMAKE_EXTRA_TARGETS += doxygen
60 60
61 61 TARGET = fsw
62 62
63 63 INCLUDEPATH += \
64 64 $${PWD}/../src \
65 65 $${PWD}/../header \
66 66 $${PWD}/../header/lfr_common_headers \
67 67 $${PWD}/../header/processing \
68 68 $${PWD}/../LFR_basic-parameters
69 69
70 70 SOURCES += \
71 71 ../src/wf_handler.c \
72 72 ../src/tc_handler.c \
73 73 ../src/fsw_misc.c \
74 74 ../src/fsw_init.c \
75 75 ../src/fsw_globals.c \
76 76 ../src/fsw_spacewire.c \
77 77 ../src/tc_load_dump_parameters.c \
78 78 ../src/tm_lfr_tc_exe.c \
79 79 ../src/tc_acceptance.c \
80 80 ../src/processing/fsw_processing.c \
81 81 ../src/processing/avf0_prc0.c \
82 82 ../src/processing/avf1_prc1.c \
83 83 ../src/processing/avf2_prc2.c \
84 84 ../src/lfr_cpu_usage_report.c \
85 85 ../LFR_basic-parameters/basic_parameters.c
86 86
87 87 HEADERS += \
88 88 ../header/wf_handler.h \
89 89 ../header/tc_handler.h \
90 90 ../header/grlib_regs.h \
91 91 ../header/fsw_misc.h \
92 92 ../header/fsw_init.h \
93 93 ../header/fsw_spacewire.h \
94 94 ../header/tc_load_dump_parameters.h \
95 95 ../header/tm_lfr_tc_exe.h \
96 96 ../header/tc_acceptance.h \
97 97 ../header/processing/fsw_processing.h \
98 98 ../header/processing/avf0_prc0.h \
99 99 ../header/processing/avf1_prc1.h \
100 100 ../header/processing/avf2_prc2.h \
101 101 ../header/fsw_params_wf_handler.h \
102 102 ../header/lfr_cpu_usage_report.h \
103 103 ../header/lfr_common_headers/ccsds_types.h \
104 104 ../header/lfr_common_headers/fsw_params.h \
105 105 ../header/lfr_common_headers/fsw_params_nb_bytes.h \
106 106 ../header/lfr_common_headers/fsw_params_processing.h \
107 107 ../header/lfr_common_headers/TC_types.h \
108 108 ../header/lfr_common_headers/tm_byte_positions.h \
109 109 ../LFR_basic-parameters/basic_parameters.h \
110 110 ../LFR_basic-parameters/basic_parameters_params.h \
111 111 ../header/GscMemoryLPP.hpp
112 112
@@ -1,66 +1,62
1 1 #ifndef GSCMEMORY_HPP_
2 2 #define GSCMEMORY_HPP_
3 3
4 static unsigned int getCacheControlRegister(){
5
6 4 #ifndef LEON3
7 5 #define LEON3
8 6 #endif
9 7
8 static unsigned int getCacheControlRegister(){
10 9 #ifdef LEON3
11 10 unsigned int cacheControlRegister = 0;
12 11 __asm__ __volatile__("lda [%%g0] 2, %0" : "=r"(cacheControlRegister) : );
13 12 return cacheControlRegister;
14 13 #endif
15 14 }
16 15
17 static void setCacheControlRegister(unsigned int cacheControlRegister){
18
16 static void setCacheControlRegister(unsigned int cacheControlRegister)
17 {
19 18 #ifdef LEON3
20 19 __asm__ __volatile__("sta %0, [%%g0] 2" : : "r"(cacheControlRegister));
21 20 #endif
22 21 }
23 22
24 23
25 24 /**
26 * Flush the data cache and the instruction cache.
27 *
28 * @return
29 */
25 * Flush the data cache and the instruction cache.
26 *
27 * @return
28 */
30 29 static inline void flushCache() {
31 30 asm("flush");
32 31 }
33 32
34 33
35 34 static void enableInstructionCache() {
36
37 35 #ifdef LEON3
38 36 unsigned int cacheControlRegister;
39 37 cacheControlRegister = getCacheControlRegister();
40 38 cacheControlRegister = (cacheControlRegister | 0x3);
41 39 setCacheControlRegister(cacheControlRegister);
42 40 #endif
43 41 }
44 42
45 43 static void enableDataCache() {
46
47 44 #ifdef LEON3
48 45 unsigned int cacheControlRegister;
49 46 cacheControlRegister = getCacheControlRegister();
50 47 cacheControlRegister = (cacheControlRegister | 0xc);
51 48 setCacheControlRegister(cacheControlRegister);
52 49 #endif
53 50 }
54 51
55 52 static void enableInstructionBurstFetch() {
56
57 53 #ifdef LEON3
58 54 unsigned int cacheControlRegister;
59 55 cacheControlRegister = getCacheControlRegister();
60 56 // set the bit IB to 1
61 57 cacheControlRegister = (cacheControlRegister | 0x10000);
62 58 setCacheControlRegister(cacheControlRegister);
63 59 #endif
64 60 }
65 61
66 62 #endif /* GSCMEMORY_HPP_ */
@@ -1,131 +1,138
1 1 #ifndef GRLIB_REGS_H_INCLUDED
2 2 #define GRLIB_REGS_H_INCLUDED
3 3
4 4 #define NB_GPTIMER 3
5 5
6 6 struct apbuart_regs_str{
7 7 volatile unsigned int data;
8 8 volatile unsigned int status;
9 9 volatile unsigned int ctrl;
10 10 volatile unsigned int scaler;
11 11 volatile unsigned int fifoDebug;
12 12 };
13 13
14 14 struct grgpio_regs_str{
15 15 volatile int io_port_data_register;
16 16 int io_port_output_register;
17 17 int io_port_direction_register;
18 18 int interrupt_mak_register;
19 19 int interrupt_polarity_register;
20 20 int interrupt_edge_register;
21 21 int bypass_register;
22 22 int reserved;
23 23 // 0x20-0x3c interrupt map register(s)
24 24 };
25 25
26 26 typedef struct {
27 27 volatile unsigned int counter;
28 28 volatile unsigned int reload;
29 29 volatile unsigned int ctrl;
30 30 volatile unsigned int unused;
31 31 } timer_regs_t;
32 32
33 33 typedef struct {
34 34 volatile unsigned int scaler_value;
35 35 volatile unsigned int scaler_reload;
36 36 volatile unsigned int conf;
37 37 volatile unsigned int unused0;
38 38 timer_regs_t timer[NB_GPTIMER];
39 39 } gptimer_regs_t;
40 40
41 41 typedef struct {
42 42 volatile int ctrl; // bit 0 forces the load of the coarse_time_load value and resets the fine_time
43 43 // bit 1 is the soft reset for the time management module
44 44 // bit 2 is the soft reset for the waveform picker and the spectral matrix modules, set to 1 after HW reset
45 45 volatile int coarse_time_load;
46 46 volatile int coarse_time;
47 47 volatile int fine_time;
48 volatile int temp_scm;
49 volatile int temp_pcb;
50 volatile int temp_fpga;
48 // TEMPERATURES
49 volatile int temp_pcb; // SEL1 = 0 SEL0 = 0
50 volatile int temp_fpga; // SEL1 = 0 SEL0 = 1
51 volatile int temp_scm; // SEL1 = 1 SEL0 = 0
52 // CALIBRATION
53 volatile unsigned int calDACCtrl;
54 volatile unsigned int calPrescaler;
55 volatile unsigned int calDivisor;
56 volatile unsigned int calDataPtr;
57 volatile unsigned int calData;
51 58 } time_management_regs_t;
52 59
53 60 // PDB >= 0.1.28
54 61 typedef struct{
55 62 int data_shaping; // 0x00 00 *** R1 R0 SP1 SP0 BW
56 63 int run_burst_enable; // 0x04 01 *** [run *** burst f2, f1, f0 *** enable f3, f2, f1, f0 ]
57 64 int addr_data_f0_0; // 0x08
58 65 int addr_data_f0_1; // 0x0c
59 66 int addr_data_f1_0; // 0x10
60 67 int addr_data_f1_1; // 0x14
61 68 int addr_data_f2_0; // 0x18
62 69 int addr_data_f2_1; // 0x1c
63 70 int addr_data_f3_0; // 0x20
64 71 int addr_data_f3_1; // 0x24
65 72 volatile int status; // 0x28
66 73 int delta_snapshot; // 0x2c
67 74 int delta_f0; // 0x30
68 75 int delta_f0_2; // 0x34
69 76 int delta_f1; // 0x38
70 77 int delta_f2; // 0x3c
71 78 int nb_data_by_buffer; // 0x40 number of samples in a buffer = 2688
72 79 int snapshot_param; // 0x44
73 80 int start_date; // 0x48
74 81 //
75 82 volatile unsigned int f0_0_coarse_time; // 0x4c
76 83 volatile unsigned int f0_0_fine_time; // 0x50
77 84 volatile unsigned int f0_1_coarse_time; // 0x54
78 85 volatile unsigned int f0_1_fine_time; // 0x58
79 86 //
80 87 volatile unsigned int f1_0_coarse_time; // 0x5c
81 88 volatile unsigned int f1_0_fine_time; // 0x60
82 89 volatile unsigned int f1_1_coarse_time; // 0x64
83 90 volatile unsigned int f1_1_fine_time; // 0x68
84 91 //
85 92 volatile unsigned int f2_0_coarse_time; // 0x6c
86 93 volatile unsigned int f2_0_fine_time; // 0x70
87 94 volatile unsigned int f2_1_coarse_time; // 0x74
88 95 volatile unsigned int f2_1_fine_time; // 0x78
89 96 //
90 97 volatile unsigned int f3_0_coarse_time; // 0x7c
91 98 volatile unsigned int f3_0_fine_time; // 0x80
92 99 volatile unsigned int f3_1_coarse_time; // 0x84
93 100 volatile unsigned int f3_1_fine_time; // 0x88
94 101 //
95 102 unsigned int buffer_length; // 0x8c = buffer length in burst 2688 / 16 = 168
96 103 //
97 104 volatile unsigned int v; // 0x90
98 105 volatile unsigned int e1; // 0x94
99 106 volatile unsigned int e2; // 0x98
100 107 } waveform_picker_regs_0_1_18_t;
101 108
102 109 typedef struct {
103 110 volatile int config; // 0x00
104 111 volatile int status; // 0x04
105 112 volatile int f0_0_address; // 0x08
106 113 volatile int f0_1_address; // 0x0C
107 114 //
108 115 volatile int f1_0_address; // 0x10
109 116 volatile int f1_1_address; // 0x14
110 117 volatile int f2_0_address; // 0x18
111 118 volatile int f2_1_address; // 0x1C
112 119 //
113 120 volatile unsigned int f0_0_coarse_time; // 0x20
114 121 volatile unsigned int f0_0_fine_time; // 0x24
115 122 volatile unsigned int f0_1_coarse_time; // 0x28
116 123 volatile unsigned int f0_1_fine_time; // 0x2C
117 124 //
118 125 volatile unsigned int f1_0_coarse_time; // 0x30
119 126 volatile unsigned int f1_0_fine_time; // 0x34
120 127 volatile unsigned int f1_1_coarse_time; // 0x38
121 128 volatile unsigned int f1_1_fine_time; // 0x3C
122 129 //
123 130 volatile unsigned int f2_0_coarse_time; // 0x40
124 131 volatile unsigned int f2_0_fine_time; // 0x44
125 132 volatile unsigned int f2_1_coarse_time; // 0x48
126 133 volatile unsigned int f2_1_fine_time; // 0x4C
127 134 //
128 135 unsigned int matrix_length; // 0x50, length of a spectral matrix in burst 3200 / 16 = 200 = 0xc8
129 136 } spectral_matrix_regs_t;
130 137
131 138 #endif // GRLIB_REGS_H_INCLUDED
@@ -1,64 +1,75
1 1 #ifndef TC_HANDLER_H_INCLUDED
2 2 #define TC_HANDLER_H_INCLUDED
3 3
4 4 #include <rtems.h>
5 5 #include <leon.h>
6 6
7 7 #include "tc_load_dump_parameters.h"
8 8 #include "tc_acceptance.h"
9 9 #include "tm_lfr_tc_exe.h"
10 10 #include "wf_handler.h"
11 11 #include "fsw_processing.h"
12 12
13 13 #include "lfr_cpu_usage_report.h"
14 14
15 15 // MODE PARAMETERS
16 16 extern unsigned int maxCount;
17 17
18 18 //****
19 19 // ISR
20 20 rtems_isr commutation_isr1( rtems_vector_number vector );
21 21 rtems_isr commutation_isr2( rtems_vector_number vector );
22 22
23 23 //***********
24 24 // RTEMS TASK
25 25 rtems_task actn_task( rtems_task_argument unused );
26 26
27 27 //***********
28 28 // TC ACTIONS
29 29 int action_reset( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time );
30 30 int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id);
31 31 int action_update_info( ccsdsTelecommandPacket_t *TC, rtems_id queue_id );
32 32 int action_enable_calibration( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time );
33 33 int action_disable_calibration( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time );
34 34 int action_update_time( ccsdsTelecommandPacket_t *TC);
35 35
36 36 // mode transition
37 37 int check_mode_value( unsigned char requestedMode );
38 38 int check_mode_transition( unsigned char requestedMode );
39 39 int check_transition_date( unsigned int transitionCoarseTime );
40 40 int stop_current_mode( void );
41 41 int enter_mode( unsigned char mode , unsigned int transitionCoarseTime );
42 42 int restart_science_tasks( unsigned char lfrRequestedMode );
43 43 int suspend_science_tasks();
44 44 void launch_waveform_picker( unsigned char mode , unsigned int transitionCoarseTime );
45 45 void launch_spectral_matrix( void );
46 46 void launch_spectral_matrix_simu( void );
47 47 void set_sm_irq_onNewMatrix( unsigned char value );
48 48 void set_sm_irq_onError( unsigned char value );
49 49
50 50 // other functions
51 51 void updateLFRCurrentMode();
52 52 void set_lfr_soft_reset( unsigned char value );
53 53 void reset_lfr( void );
54 // CALIBRATION
55 void setCalibrationPrescaler( unsigned int prescaler );
56 void setCalibrationDivisor( unsigned int divisionFactor );
57 void setCalibrationData( void );
58 void setCalibrationReload( bool state);
59 void setCalibrationEnable( bool state );
60 void setCalibrationInterleaved( bool state );
61 void startCalibration( void );
62 void stopCalibration( void );
63 void configureCalibration( bool interleaved );
64 //
54 65 void update_last_TC_exe( ccsdsTelecommandPacket_t *TC , unsigned char *time );
55 66 void update_last_TC_rej(ccsdsTelecommandPacket_t *TC , unsigned char *time );
56 67 void close_action( ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id );
57 68
58 69 extern rtems_status_code get_message_queue_id_send( rtems_id *queue_id );
59 70 extern rtems_status_code get_message_queue_id_recv( rtems_id *queue_id );
60 71
61 72 #endif // TC_HANDLER_H_INCLUDED
62 73
63 74
64 75
@@ -1,87 +1,87
1 1 #ifndef WF_HANDLER_H_INCLUDED
2 2 #define WF_HANDLER_H_INCLUDED
3 3
4 4 #include <rtems.h>
5 5 #include <grspw.h>
6 6 #include <stdio.h>
7 7 #include <math.h>
8 8 #include <fsw_params.h>
9 9
10 10 #include "fsw_spacewire.h"
11 11 #include "fsw_misc.h"
12 12 #include "fsw_params_wf_handler.h"
13 13
14 #define pi 3.1415
14 #define pi 3.14159265359
15 15
16 16 extern int fdSPW;
17 17
18 18 //*****************
19 19 // waveform buffers
20 20 extern volatile int wf_buffer_f0[ ];
21 21 extern volatile int wf_buffer_f1[ ];
22 22 extern volatile int wf_buffer_f2[ ];
23 23 extern volatile int wf_buffer_f3[ ];
24 24
25 25 extern waveform_picker_regs_0_1_18_t *waveform_picker_regs;
26 26 extern time_management_regs_t *time_management_regs;
27 27 extern Packet_TM_LFR_HK_t housekeeping_packet;
28 28 extern Packet_TM_LFR_PARAMETER_DUMP_t parameter_dump_packet;
29 29 extern struct param_local_str param_local;
30 30
31 31 extern unsigned short sequenceCounters_SCIENCE_NORMAL_BURST;
32 32 extern unsigned short sequenceCounters_SCIENCE_SBM1_SBM2;
33 33
34 34 extern rtems_id Task_id[20]; /* array of task ids */
35 35
36 36 extern unsigned char lfrCurrentMode;
37 37
38 38 //**********
39 39 // RTEMS_ISR
40 40 void reset_extractSWF( void );
41 41 rtems_isr waveforms_isr( rtems_vector_number vector );
42 42
43 43 //***********
44 44 // RTEMS_TASK
45 45 rtems_task wfrm_task( rtems_task_argument argument );
46 46 rtems_task cwf3_task( rtems_task_argument argument );
47 47 rtems_task cwf2_task( rtems_task_argument argument );
48 48 rtems_task cwf1_task( rtems_task_argument argument );
49 49 rtems_task swbd_task( rtems_task_argument argument );
50 50
51 51 //******************
52 52 // general functions
53 53 void WFP_init_rings( void );
54 54 void init_ring( ring_node ring[], unsigned char nbNodes, volatile int buffer[] , unsigned int bufferSize );
55 55 void WFP_reset_current_ring_nodes( void );
56 56 //
57 57 int init_header_continuous_cwf3_light_table( Header_TM_LFR_SCIENCE_CWF_t *headerCWF );
58 58 //
59 59 int send_waveform_CWF3_light(ring_node *ring_node_to_send, ring_node *ring_node_cwf3_light, rtems_id queue_id );
60 60 //
61 61 void compute_acquisition_time(unsigned int coarseTime, unsigned int fineTime,
62 62 unsigned int sid, unsigned char pa_lfr_pkt_nr, unsigned char *acquisitionTime );
63 63 void build_snapshot_from_ring(ring_node *ring_node_to_send, unsigned char frequencyChannel , unsigned long long acquisitionTimeF0_asLong);
64 64 void snapshot_resynchronization( unsigned char *timePtr );
65 65 //
66 66 rtems_id get_pkts_queue_id( void );
67 67
68 68 //**************
69 69 // wfp registers
70 70 // RESET
71 71 void reset_wfp_burst_enable( void );
72 72 void reset_wfp_status( void );
73 73 void reset_wfp_buffer_addresses( void );
74 74 void reset_waveform_picker_regs( void );
75 75 // SET
76 76 void set_wfp_data_shaping(void);
77 77 void set_wfp_burst_enable_register( unsigned char mode );
78 78 void set_wfp_delta_snapshot( void );
79 79 void set_wfp_delta_f0_f0_2( void );
80 80 void set_wfp_delta_f1( void );
81 81 void set_wfp_delta_f2( void );
82 82
83 83 //*****************
84 84 // local parameters
85 85 void increment_seq_counter_source_id( unsigned char *packet_sequence_control, unsigned int sid );
86 86
87 87 #endif // WF_HANDLER_H_INCLUDED
@@ -1,810 +1,813
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 // STAT (1s), send SWF (0.3s), send CWF3 (1s)
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 48 #ifdef LEON3
49 49 /* Add Timer and UART Driver */
50 50 #ifdef CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
51 51 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GPTIMER
52 52 #endif
53 53 #ifdef CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
54 54 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_APBUART
55 55 #endif
56 56 #endif
57 57 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GRSPW /* GRSPW Driver */
58 58 #include <drvmgr/drvmgr_confdefs.h>
59 59 #endif
60 60
61 61 #include "fsw_init.h"
62 62 #include "fsw_config.c"
63 63
64 64 void initCache()
65 65 {
66 66 // unsigned int cacheControlRegister;
67 67
68 68 // cacheControlRegister = getCacheControlRegister();
69 69 // printf("(0) cacheControlRegister = %x\n", cacheControlRegister);
70 70
71 71 enableInstructionCache();
72 72 enableDataCache();
73 73 enableInstructionBurstFetch();
74 74
75 75 // cacheControlRegister = getCacheControlRegister();
76 76 // printf("(1) cacheControlRegister = %x\n", cacheControlRegister);
77 77 }
78 78
79 79 rtems_task Init( rtems_task_argument ignored )
80 80 {
81 81 /** This is the RTEMS INIT taks, it the first task launched by the system.
82 82 *
83 83 * @param unused is the starting argument of the RTEMS task
84 84 *
85 85 * The INIT task create and run all other RTEMS tasks.
86 86 *
87 87 */
88 88
89 89 //***********
90 90 // INIT CACHE
91 91
92 92 unsigned char *vhdlVersion;
93 93
94 94 reset_lfr();
95 95
96 96 reset_local_time();
97 97
98 98 rtems_cpu_usage_reset();
99 99
100 100 rtems_status_code status;
101 101 rtems_status_code status_spw;
102 102 rtems_isr_entry old_isr_handler;
103 103
104 104 // UART settings
105 105 send_console_outputs_on_apbuart_port();
106 106 set_apbuart_scaler_reload_register(REGS_ADDR_APBUART, APBUART_SCALER_RELOAD_VALUE);
107 107 enable_apbuart_transmitter();
108 108
109 109 DEBUG_PRINTF("\n\n\n\n\nIn INIT *** Now the console is on port COM1\n")
110 110
111 111
112 112 PRINTF("\n\n\n\n\n")
113 113
114 114 initCache();
115 115
116 116 PRINTF("*************************\n")
117 117 PRINTF("** LFR Flight Software **\n")
118 118 PRINTF1("** %d.", SW_VERSION_N1)
119 119 PRINTF1("%d." , SW_VERSION_N2)
120 120 PRINTF1("%d." , SW_VERSION_N3)
121 121 PRINTF1("%d **\n", SW_VERSION_N4)
122 122
123 123 vhdlVersion = (unsigned char *) (REGS_ADDR_VHDL_VERSION);
124 124 PRINTF("** VHDL **\n")
125 125 PRINTF1("** %d.", vhdlVersion[1])
126 126 PRINTF1("%d." , vhdlVersion[2])
127 127 PRINTF1("%d **\n", vhdlVersion[3])
128 128 PRINTF("*************************\n")
129 129 PRINTF("\n\n")
130 130
131 131 init_parameter_dump();
132 132 init_local_mode_parameters();
133 133 init_housekeeping_parameters();
134 134 init_k_coefficients_f0();
135 135 init_k_coefficients_f1();
136 136 init_k_coefficients_f2();
137 137
138 138 // waveform picker initialization
139 139 WFP_init_rings(); // initialize the waveform rings
140 140 WFP_reset_current_ring_nodes();
141 141 reset_waveform_picker_regs();
142 142
143 143 // spectral matrices initialization
144 144 SM_init_rings(); // initialize spectral matrices rings
145 145 SM_reset_current_ring_nodes();
146 146 reset_spectral_matrix_regs();
147 147
148 // configure calibration
149 configureCalibration( false ); // true means interleaved mode, false is for normal mode
150
148 151 updateLFRCurrentMode();
149 152
150 153 BOOT_PRINTF1("in INIT *** lfrCurrentMode is %d\n", lfrCurrentMode)
151 154
152 155 create_names(); // create all names
153 156
154 157 status = create_message_queues(); // create message queues
155 158 if (status != RTEMS_SUCCESSFUL)
156 159 {
157 160 PRINTF1("in INIT *** ERR in create_message_queues, code %d", status)
158 161 }
159 162
160 163 status = create_all_tasks(); // create all tasks
161 164 if (status != RTEMS_SUCCESSFUL)
162 165 {
163 166 PRINTF1("in INIT *** ERR in create_all_tasks, code %d\n", status)
164 167 }
165 168
166 169 // **************************
167 170 // <SPACEWIRE INITIALIZATION>
168 171 grspw_timecode_callback = &timecode_irq_handler;
169 172
170 173 status_spw = spacewire_open_link(); // (1) open the link
171 174 if ( status_spw != RTEMS_SUCCESSFUL )
172 175 {
173 176 PRINTF1("in INIT *** ERR spacewire_open_link code %d\n", status_spw )
174 177 }
175 178
176 179 if ( status_spw == RTEMS_SUCCESSFUL ) // (2) configure the link
177 180 {
178 181 status_spw = spacewire_configure_link( fdSPW );
179 182 if ( status_spw != RTEMS_SUCCESSFUL )
180 183 {
181 184 PRINTF1("in INIT *** ERR spacewire_configure_link code %d\n", status_spw )
182 185 }
183 186 }
184 187
185 188 if ( status_spw == RTEMS_SUCCESSFUL) // (3) start the link
186 189 {
187 190 status_spw = spacewire_start_link( fdSPW );
188 191 if ( status_spw != RTEMS_SUCCESSFUL )
189 192 {
190 193 PRINTF1("in INIT *** ERR spacewire_start_link code %d\n", status_spw )
191 194 }
192 195 }
193 196 // </SPACEWIRE INITIALIZATION>
194 197 // ***************************
195 198
196 199 status = start_all_tasks(); // start all tasks
197 200 if (status != RTEMS_SUCCESSFUL)
198 201 {
199 202 PRINTF1("in INIT *** ERR in start_all_tasks, code %d", status)
200 203 }
201 204
202 205 // start RECV and SEND *AFTER* SpaceWire Initialization, due to the timeout of the start call during the initialization
203 206 status = start_recv_send_tasks();
204 207 if ( status != RTEMS_SUCCESSFUL )
205 208 {
206 209 PRINTF1("in INIT *** ERR start_recv_send_tasks code %d\n", status )
207 210 }
208 211
209 212 // suspend science tasks, they will be restarted later depending on the mode
210 213 status = suspend_science_tasks(); // suspend science tasks (not done in stop_current_mode if current mode = STANDBY)
211 214 if (status != RTEMS_SUCCESSFUL)
212 215 {
213 216 PRINTF1("in INIT *** in suspend_science_tasks *** ERR code: %d\n", status)
214 217 }
215 218
216 219 //******************************
217 220 // <SPECTRAL MATRICES SIMULATOR>
218 221 LEON_Mask_interrupt( IRQ_SM_SIMULATOR );
219 222 configure_timer((gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_SM_SIMULATOR, CLKDIV_SM_SIMULATOR,
220 223 IRQ_SPARC_SM_SIMULATOR, spectral_matrices_isr_simu );
221 224 // </SPECTRAL MATRICES SIMULATOR>
222 225 //*******************************
223 226
224 227 // configure IRQ handling for the waveform picker unit
225 228 status = rtems_interrupt_catch( waveforms_isr,
226 229 IRQ_SPARC_WAVEFORM_PICKER,
227 230 &old_isr_handler) ;
228 231 // configure IRQ handling for the spectral matrices unit
229 232 status = rtems_interrupt_catch( spectral_matrices_isr,
230 233 IRQ_SPARC_SPECTRAL_MATRIX,
231 234 &old_isr_handler) ;
232 235
233 236 // if the spacewire link is not up then send an event to the SPIQ task for link recovery
234 237 if ( status_spw != RTEMS_SUCCESSFUL )
235 238 {
236 239 status = rtems_event_send( Task_id[TASKID_SPIQ], SPW_LINKERR_EVENT );
237 240 if ( status != RTEMS_SUCCESSFUL ) {
238 241 PRINTF1("in INIT *** ERR rtems_event_send to SPIQ code %d\n", status )
239 242 }
240 243 }
241 244
242 245 BOOT_PRINTF("delete INIT\n")
243 246
244 247 // test_TCH();
245 248
246 249 status = rtems_task_delete(RTEMS_SELF);
247 250
248 251 }
249 252
250 253 void init_local_mode_parameters( void )
251 254 {
252 255 /** This function initialize the param_local global variable with default values.
253 256 *
254 257 */
255 258
256 259 unsigned int i;
257 260
258 261 // LOCAL PARAMETERS
259 262
260 263 BOOT_PRINTF1("local_sbm1_nb_cwf_max %d \n", param_local.local_sbm1_nb_cwf_max)
261 264 BOOT_PRINTF1("local_sbm2_nb_cwf_max %d \n", param_local.local_sbm2_nb_cwf_max)
262 265 BOOT_PRINTF1("nb_interrupt_f0_MAX = %d\n", param_local.local_nb_interrupt_f0_MAX)
263 266
264 267 // init sequence counters
265 268
266 269 for(i = 0; i<SEQ_CNT_NB_DEST_ID; i++)
267 270 {
268 271 sequenceCounters_TC_EXE[i] = 0x00;
269 272 }
270 273 sequenceCounters_SCIENCE_NORMAL_BURST = 0x00;
271 274 sequenceCounters_SCIENCE_SBM1_SBM2 = 0x00;
272 275 sequenceCounterHK = TM_PACKET_SEQ_CTRL_STANDALONE << 8;
273 276 sequenceCounterParameterDump = TM_PACKET_SEQ_CTRL_STANDALONE << 8;
274 277 }
275 278
276 279 void reset_local_time( void )
277 280 {
278 281 time_management_regs->ctrl = time_management_regs->ctrl | 0x02; // [0010] software reset, coarse time = 0x80000000
279 282 }
280 283
281 284 void create_names( void ) // create all names for tasks and queues
282 285 {
283 286 /** This function creates all RTEMS names used in the software for tasks and queues.
284 287 *
285 288 * @return RTEMS directive status codes:
286 289 * - RTEMS_SUCCESSFUL - successful completion
287 290 *
288 291 */
289 292
290 293 // task names
291 294 Task_name[TASKID_RECV] = rtems_build_name( 'R', 'E', 'C', 'V' );
292 295 Task_name[TASKID_ACTN] = rtems_build_name( 'A', 'C', 'T', 'N' );
293 296 Task_name[TASKID_SPIQ] = rtems_build_name( 'S', 'P', 'I', 'Q' );
294 297 Task_name[TASKID_STAT] = rtems_build_name( 'S', 'T', 'A', 'T' );
295 298 Task_name[TASKID_AVF0] = rtems_build_name( 'A', 'V', 'F', '0' );
296 299 Task_name[TASKID_SWBD] = rtems_build_name( 'S', 'W', 'B', 'D' );
297 300 Task_name[TASKID_WFRM] = rtems_build_name( 'W', 'F', 'R', 'M' );
298 301 Task_name[TASKID_DUMB] = rtems_build_name( 'D', 'U', 'M', 'B' );
299 302 Task_name[TASKID_HOUS] = rtems_build_name( 'H', 'O', 'U', 'S' );
300 303 Task_name[TASKID_PRC0] = rtems_build_name( 'P', 'R', 'C', '0' );
301 304 Task_name[TASKID_CWF3] = rtems_build_name( 'C', 'W', 'F', '3' );
302 305 Task_name[TASKID_CWF2] = rtems_build_name( 'C', 'W', 'F', '2' );
303 306 Task_name[TASKID_CWF1] = rtems_build_name( 'C', 'W', 'F', '1' );
304 307 Task_name[TASKID_SEND] = rtems_build_name( 'S', 'E', 'N', 'D' );
305 308 Task_name[TASKID_WTDG] = rtems_build_name( 'W', 'T', 'D', 'G' );
306 309 Task_name[TASKID_AVF1] = rtems_build_name( 'A', 'V', 'F', '1' );
307 310 Task_name[TASKID_PRC1] = rtems_build_name( 'P', 'R', 'C', '1' );
308 311 Task_name[TASKID_AVF2] = rtems_build_name( 'A', 'V', 'F', '2' );
309 312 Task_name[TASKID_PRC2] = rtems_build_name( 'P', 'R', 'C', '2' );
310 313
311 314 // rate monotonic period names
312 315 name_hk_rate_monotonic = rtems_build_name( 'H', 'O', 'U', 'S' );
313 316
314 317 misc_name[QUEUE_RECV] = rtems_build_name( 'Q', '_', 'R', 'V' );
315 318 misc_name[QUEUE_SEND] = rtems_build_name( 'Q', '_', 'S', 'D' );
316 319 misc_name[QUEUE_PRC0] = rtems_build_name( 'Q', '_', 'P', '0' );
317 320 misc_name[QUEUE_PRC1] = rtems_build_name( 'Q', '_', 'P', '1' );
318 321 misc_name[QUEUE_PRC2] = rtems_build_name( 'Q', '_', 'P', '2' );
319 322 }
320 323
321 324 int create_all_tasks( void ) // create all tasks which run in the software
322 325 {
323 326 /** This function creates all RTEMS tasks used in the software.
324 327 *
325 328 * @return RTEMS directive status codes:
326 329 * - RTEMS_SUCCESSFUL - task created successfully
327 330 * - RTEMS_INVALID_ADDRESS - id is NULL
328 331 * - RTEMS_INVALID_NAME - invalid task name
329 332 * - RTEMS_INVALID_PRIORITY - invalid task priority
330 333 * - RTEMS_MP_NOT_CONFIGURED - multiprocessing not configured
331 334 * - RTEMS_TOO_MANY - too many tasks created
332 335 * - RTEMS_UNSATISFIED - not enough memory for stack/FP context
333 336 * - RTEMS_TOO_MANY - too many global objects
334 337 *
335 338 */
336 339
337 340 rtems_status_code status;
338 341
339 342 //**********
340 343 // SPACEWIRE
341 344 // RECV
342 345 status = rtems_task_create(
343 346 Task_name[TASKID_RECV], TASK_PRIORITY_RECV, RTEMS_MINIMUM_STACK_SIZE,
344 347 RTEMS_DEFAULT_MODES,
345 348 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_RECV]
346 349 );
347 350 if (status == RTEMS_SUCCESSFUL) // SEND
348 351 {
349 352 status = rtems_task_create(
350 353 Task_name[TASKID_SEND], TASK_PRIORITY_SEND, RTEMS_MINIMUM_STACK_SIZE * 2,
351 354 RTEMS_DEFAULT_MODES,
352 355 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_SEND]
353 356 );
354 357 }
355 358 if (status == RTEMS_SUCCESSFUL) // WTDG
356 359 {
357 360 status = rtems_task_create(
358 361 Task_name[TASKID_WTDG], TASK_PRIORITY_WTDG, RTEMS_MINIMUM_STACK_SIZE,
359 362 RTEMS_DEFAULT_MODES,
360 363 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_WTDG]
361 364 );
362 365 }
363 366 if (status == RTEMS_SUCCESSFUL) // ACTN
364 367 {
365 368 status = rtems_task_create(
366 369 Task_name[TASKID_ACTN], TASK_PRIORITY_ACTN, RTEMS_MINIMUM_STACK_SIZE,
367 370 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
368 371 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_ACTN]
369 372 );
370 373 }
371 374 if (status == RTEMS_SUCCESSFUL) // SPIQ
372 375 {
373 376 status = rtems_task_create(
374 377 Task_name[TASKID_SPIQ], TASK_PRIORITY_SPIQ, RTEMS_MINIMUM_STACK_SIZE,
375 378 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
376 379 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_SPIQ]
377 380 );
378 381 }
379 382
380 383 //******************
381 384 // SPECTRAL MATRICES
382 385 if (status == RTEMS_SUCCESSFUL) // AVF0
383 386 {
384 387 status = rtems_task_create(
385 388 Task_name[TASKID_AVF0], TASK_PRIORITY_AVF0, RTEMS_MINIMUM_STACK_SIZE,
386 389 RTEMS_DEFAULT_MODES,
387 390 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF0]
388 391 );
389 392 }
390 393 if (status == RTEMS_SUCCESSFUL) // PRC0
391 394 {
392 395 status = rtems_task_create(
393 396 Task_name[TASKID_PRC0], TASK_PRIORITY_PRC0, RTEMS_MINIMUM_STACK_SIZE * 2,
394 397 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
395 398 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC0]
396 399 );
397 400 }
398 401 if (status == RTEMS_SUCCESSFUL) // AVF1
399 402 {
400 403 status = rtems_task_create(
401 404 Task_name[TASKID_AVF1], TASK_PRIORITY_AVF1, RTEMS_MINIMUM_STACK_SIZE,
402 405 RTEMS_DEFAULT_MODES,
403 406 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF1]
404 407 );
405 408 }
406 409 if (status == RTEMS_SUCCESSFUL) // PRC1
407 410 {
408 411 status = rtems_task_create(
409 412 Task_name[TASKID_PRC1], TASK_PRIORITY_PRC1, RTEMS_MINIMUM_STACK_SIZE * 2,
410 413 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
411 414 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC1]
412 415 );
413 416 }
414 417 if (status == RTEMS_SUCCESSFUL) // AVF2
415 418 {
416 419 status = rtems_task_create(
417 420 Task_name[TASKID_AVF2], TASK_PRIORITY_AVF2, RTEMS_MINIMUM_STACK_SIZE,
418 421 RTEMS_DEFAULT_MODES,
419 422 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF2]
420 423 );
421 424 }
422 425 if (status == RTEMS_SUCCESSFUL) // PRC2
423 426 {
424 427 status = rtems_task_create(
425 428 Task_name[TASKID_PRC2], TASK_PRIORITY_PRC2, RTEMS_MINIMUM_STACK_SIZE * 2,
426 429 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
427 430 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC2]
428 431 );
429 432 }
430 433
431 434 //****************
432 435 // WAVEFORM PICKER
433 436 if (status == RTEMS_SUCCESSFUL) // WFRM
434 437 {
435 438 status = rtems_task_create(
436 439 Task_name[TASKID_WFRM], TASK_PRIORITY_WFRM, RTEMS_MINIMUM_STACK_SIZE,
437 440 RTEMS_DEFAULT_MODES,
438 441 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_WFRM]
439 442 );
440 443 }
441 444 if (status == RTEMS_SUCCESSFUL) // CWF3
442 445 {
443 446 status = rtems_task_create(
444 447 Task_name[TASKID_CWF3], TASK_PRIORITY_CWF3, RTEMS_MINIMUM_STACK_SIZE,
445 448 RTEMS_DEFAULT_MODES,
446 449 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF3]
447 450 );
448 451 }
449 452 if (status == RTEMS_SUCCESSFUL) // CWF2
450 453 {
451 454 status = rtems_task_create(
452 455 Task_name[TASKID_CWF2], TASK_PRIORITY_CWF2, RTEMS_MINIMUM_STACK_SIZE,
453 456 RTEMS_DEFAULT_MODES,
454 457 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF2]
455 458 );
456 459 }
457 460 if (status == RTEMS_SUCCESSFUL) // CWF1
458 461 {
459 462 status = rtems_task_create(
460 463 Task_name[TASKID_CWF1], TASK_PRIORITY_CWF1, RTEMS_MINIMUM_STACK_SIZE,
461 464 RTEMS_DEFAULT_MODES,
462 465 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF1]
463 466 );
464 467 }
465 468 if (status == RTEMS_SUCCESSFUL) // SWBD
466 469 {
467 470 status = rtems_task_create(
468 471 Task_name[TASKID_SWBD], TASK_PRIORITY_SWBD, RTEMS_MINIMUM_STACK_SIZE,
469 472 RTEMS_DEFAULT_MODES,
470 473 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_SWBD]
471 474 );
472 475 }
473 476
474 477 //*****
475 478 // MISC
476 479 if (status == RTEMS_SUCCESSFUL) // STAT
477 480 {
478 481 status = rtems_task_create(
479 482 Task_name[TASKID_STAT], TASK_PRIORITY_STAT, RTEMS_MINIMUM_STACK_SIZE,
480 483 RTEMS_DEFAULT_MODES,
481 484 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_STAT]
482 485 );
483 486 }
484 487 if (status == RTEMS_SUCCESSFUL) // DUMB
485 488 {
486 489 status = rtems_task_create(
487 490 Task_name[TASKID_DUMB], TASK_PRIORITY_DUMB, RTEMS_MINIMUM_STACK_SIZE,
488 491 RTEMS_DEFAULT_MODES,
489 492 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_DUMB]
490 493 );
491 494 }
492 495 if (status == RTEMS_SUCCESSFUL) // HOUS
493 496 {
494 497 status = rtems_task_create(
495 498 Task_name[TASKID_HOUS], TASK_PRIORITY_HOUS, RTEMS_MINIMUM_STACK_SIZE,
496 499 RTEMS_DEFAULT_MODES,
497 500 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_HOUS]
498 501 );
499 502 }
500 503
501 504 return status;
502 505 }
503 506
504 507 int start_recv_send_tasks( void )
505 508 {
506 509 rtems_status_code status;
507 510
508 511 status = rtems_task_start( Task_id[TASKID_RECV], recv_task, 1 );
509 512 if (status!=RTEMS_SUCCESSFUL) {
510 513 BOOT_PRINTF("in INIT *** Error starting TASK_RECV\n")
511 514 }
512 515
513 516 if (status == RTEMS_SUCCESSFUL) // SEND
514 517 {
515 518 status = rtems_task_start( Task_id[TASKID_SEND], send_task, 1 );
516 519 if (status!=RTEMS_SUCCESSFUL) {
517 520 BOOT_PRINTF("in INIT *** Error starting TASK_SEND\n")
518 521 }
519 522 }
520 523
521 524 return status;
522 525 }
523 526
524 527 int start_all_tasks( void ) // start all tasks except SEND RECV and HOUS
525 528 {
526 529 /** This function starts all RTEMS tasks used in the software.
527 530 *
528 531 * @return RTEMS directive status codes:
529 532 * - RTEMS_SUCCESSFUL - ask started successfully
530 533 * - RTEMS_INVALID_ADDRESS - invalid task entry point
531 534 * - RTEMS_INVALID_ID - invalid task id
532 535 * - RTEMS_INCORRECT_STATE - task not in the dormant state
533 536 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot start remote task
534 537 *
535 538 */
536 539 // starts all the tasks fot eh flight software
537 540
538 541 rtems_status_code status;
539 542
540 543 //**********
541 544 // SPACEWIRE
542 545 status = rtems_task_start( Task_id[TASKID_SPIQ], spiq_task, 1 );
543 546 if (status!=RTEMS_SUCCESSFUL) {
544 547 BOOT_PRINTF("in INIT *** Error starting TASK_SPIQ\n")
545 548 }
546 549
547 550 if (status == RTEMS_SUCCESSFUL) // WTDG
548 551 {
549 552 status = rtems_task_start( Task_id[TASKID_WTDG], wtdg_task, 1 );
550 553 if (status!=RTEMS_SUCCESSFUL) {
551 554 BOOT_PRINTF("in INIT *** Error starting TASK_WTDG\n")
552 555 }
553 556 }
554 557
555 558 if (status == RTEMS_SUCCESSFUL) // ACTN
556 559 {
557 560 status = rtems_task_start( Task_id[TASKID_ACTN], actn_task, 1 );
558 561 if (status!=RTEMS_SUCCESSFUL) {
559 562 BOOT_PRINTF("in INIT *** Error starting TASK_ACTN\n")
560 563 }
561 564 }
562 565
563 566 //******************
564 567 // SPECTRAL MATRICES
565 568 if (status == RTEMS_SUCCESSFUL) // AVF0
566 569 {
567 570 status = rtems_task_start( Task_id[TASKID_AVF0], avf0_task, LFR_MODE_STANDBY );
568 571 if (status!=RTEMS_SUCCESSFUL) {
569 572 BOOT_PRINTF("in INIT *** Error starting TASK_AVF0\n")
570 573 }
571 574 }
572 575 if (status == RTEMS_SUCCESSFUL) // PRC0
573 576 {
574 577 status = rtems_task_start( Task_id[TASKID_PRC0], prc0_task, LFR_MODE_STANDBY );
575 578 if (status!=RTEMS_SUCCESSFUL) {
576 579 BOOT_PRINTF("in INIT *** Error starting TASK_PRC0\n")
577 580 }
578 581 }
579 582 if (status == RTEMS_SUCCESSFUL) // AVF1
580 583 {
581 584 status = rtems_task_start( Task_id[TASKID_AVF1], avf1_task, LFR_MODE_STANDBY );
582 585 if (status!=RTEMS_SUCCESSFUL) {
583 586 BOOT_PRINTF("in INIT *** Error starting TASK_AVF1\n")
584 587 }
585 588 }
586 589 if (status == RTEMS_SUCCESSFUL) // PRC1
587 590 {
588 591 status = rtems_task_start( Task_id[TASKID_PRC1], prc1_task, LFR_MODE_STANDBY );
589 592 if (status!=RTEMS_SUCCESSFUL) {
590 593 BOOT_PRINTF("in INIT *** Error starting TASK_PRC1\n")
591 594 }
592 595 }
593 596 if (status == RTEMS_SUCCESSFUL) // AVF2
594 597 {
595 598 status = rtems_task_start( Task_id[TASKID_AVF2], avf2_task, 1 );
596 599 if (status!=RTEMS_SUCCESSFUL) {
597 600 BOOT_PRINTF("in INIT *** Error starting TASK_AVF2\n")
598 601 }
599 602 }
600 603 if (status == RTEMS_SUCCESSFUL) // PRC2
601 604 {
602 605 status = rtems_task_start( Task_id[TASKID_PRC2], prc2_task, 1 );
603 606 if (status!=RTEMS_SUCCESSFUL) {
604 607 BOOT_PRINTF("in INIT *** Error starting TASK_PRC2\n")
605 608 }
606 609 }
607 610
608 611 //****************
609 612 // WAVEFORM PICKER
610 613 if (status == RTEMS_SUCCESSFUL) // WFRM
611 614 {
612 615 status = rtems_task_start( Task_id[TASKID_WFRM], wfrm_task, 1 );
613 616 if (status!=RTEMS_SUCCESSFUL) {
614 617 BOOT_PRINTF("in INIT *** Error starting TASK_WFRM\n")
615 618 }
616 619 }
617 620 if (status == RTEMS_SUCCESSFUL) // CWF3
618 621 {
619 622 status = rtems_task_start( Task_id[TASKID_CWF3], cwf3_task, 1 );
620 623 if (status!=RTEMS_SUCCESSFUL) {
621 624 BOOT_PRINTF("in INIT *** Error starting TASK_CWF3\n")
622 625 }
623 626 }
624 627 if (status == RTEMS_SUCCESSFUL) // CWF2
625 628 {
626 629 status = rtems_task_start( Task_id[TASKID_CWF2], cwf2_task, 1 );
627 630 if (status!=RTEMS_SUCCESSFUL) {
628 631 BOOT_PRINTF("in INIT *** Error starting TASK_CWF2\n")
629 632 }
630 633 }
631 634 if (status == RTEMS_SUCCESSFUL) // CWF1
632 635 {
633 636 status = rtems_task_start( Task_id[TASKID_CWF1], cwf1_task, 1 );
634 637 if (status!=RTEMS_SUCCESSFUL) {
635 638 BOOT_PRINTF("in INIT *** Error starting TASK_CWF1\n")
636 639 }
637 640 }
638 641 if (status == RTEMS_SUCCESSFUL) // SWBD
639 642 {
640 643 status = rtems_task_start( Task_id[TASKID_SWBD], swbd_task, 1 );
641 644 if (status!=RTEMS_SUCCESSFUL) {
642 645 BOOT_PRINTF("in INIT *** Error starting TASK_SWBD\n")
643 646 }
644 647 }
645 648
646 649 //*****
647 650 // MISC
648 651 if (status == RTEMS_SUCCESSFUL) // HOUS
649 652 {
650 653 status = rtems_task_start( Task_id[TASKID_HOUS], hous_task, 1 );
651 654 if (status!=RTEMS_SUCCESSFUL) {
652 655 BOOT_PRINTF("in INIT *** Error starting TASK_HOUS\n")
653 656 }
654 657 }
655 658 if (status == RTEMS_SUCCESSFUL) // DUMB
656 659 {
657 660 status = rtems_task_start( Task_id[TASKID_DUMB], dumb_task, 1 );
658 661 if (status!=RTEMS_SUCCESSFUL) {
659 662 BOOT_PRINTF("in INIT *** Error starting TASK_DUMB\n")
660 663 }
661 664 }
662 665 if (status == RTEMS_SUCCESSFUL) // STAT
663 666 {
664 667 status = rtems_task_start( Task_id[TASKID_STAT], stat_task, 1 );
665 668 if (status!=RTEMS_SUCCESSFUL) {
666 669 BOOT_PRINTF("in INIT *** Error starting TASK_STAT\n")
667 670 }
668 671 }
669 672
670 673 return status;
671 674 }
672 675
673 676 rtems_status_code create_message_queues( void ) // create the two message queues used in the software
674 677 {
675 678 rtems_status_code status_recv;
676 679 rtems_status_code status_send;
677 680 rtems_status_code status_q_p0;
678 681 rtems_status_code status_q_p1;
679 682 rtems_status_code status_q_p2;
680 683 rtems_status_code ret;
681 684 rtems_id queue_id;
682 685
683 686 //****************************************
684 687 // create the queue for handling valid TCs
685 688 status_recv = rtems_message_queue_create( misc_name[QUEUE_RECV],
686 689 MSG_QUEUE_COUNT_RECV, CCSDS_TC_PKT_MAX_SIZE,
687 690 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
688 691 if ( status_recv != RTEMS_SUCCESSFUL ) {
689 692 PRINTF1("in create_message_queues *** ERR creating QUEU queue, %d\n", status_recv)
690 693 }
691 694
692 695 //************************************************
693 696 // create the queue for handling TM packet sending
694 697 status_send = rtems_message_queue_create( misc_name[QUEUE_SEND],
695 698 MSG_QUEUE_COUNT_SEND, MSG_QUEUE_SIZE_SEND,
696 699 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
697 700 if ( status_send != RTEMS_SUCCESSFUL ) {
698 701 PRINTF1("in create_message_queues *** ERR creating PKTS queue, %d\n", status_send)
699 702 }
700 703
701 704 //*****************************************************************************
702 705 // create the queue for handling averaged spectral matrices for processing @ f0
703 706 status_q_p0 = rtems_message_queue_create( misc_name[QUEUE_PRC0],
704 707 MSG_QUEUE_COUNT_PRC0, MSG_QUEUE_SIZE_PRC0,
705 708 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
706 709 if ( status_q_p0 != RTEMS_SUCCESSFUL ) {
707 710 PRINTF1("in create_message_queues *** ERR creating Q_P0 queue, %d\n", status_q_p0)
708 711 }
709 712
710 713 //*****************************************************************************
711 714 // create the queue for handling averaged spectral matrices for processing @ f1
712 715 status_q_p1 = rtems_message_queue_create( misc_name[QUEUE_PRC1],
713 716 MSG_QUEUE_COUNT_PRC1, MSG_QUEUE_SIZE_PRC1,
714 717 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
715 718 if ( status_q_p1 != RTEMS_SUCCESSFUL ) {
716 719 PRINTF1("in create_message_queues *** ERR creating Q_P1 queue, %d\n", status_q_p1)
717 720 }
718 721
719 722 //*****************************************************************************
720 723 // create the queue for handling averaged spectral matrices for processing @ f2
721 724 status_q_p2 = rtems_message_queue_create( misc_name[QUEUE_PRC2],
722 725 MSG_QUEUE_COUNT_PRC2, MSG_QUEUE_SIZE_PRC2,
723 726 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
724 727 if ( status_q_p2 != RTEMS_SUCCESSFUL ) {
725 728 PRINTF1("in create_message_queues *** ERR creating Q_P2 queue, %d\n", status_q_p2)
726 729 }
727 730
728 731 if ( status_recv != RTEMS_SUCCESSFUL )
729 732 {
730 733 ret = status_recv;
731 734 }
732 735 else if( status_send != RTEMS_SUCCESSFUL )
733 736 {
734 737 ret = status_send;
735 738 }
736 739 else if( status_q_p0 != RTEMS_SUCCESSFUL )
737 740 {
738 741 ret = status_q_p0;
739 742 }
740 743 else if( status_q_p1 != RTEMS_SUCCESSFUL )
741 744 {
742 745 ret = status_q_p1;
743 746 }
744 747 else
745 748 {
746 749 ret = status_q_p2;
747 750 }
748 751
749 752 return ret;
750 753 }
751 754
752 755 rtems_status_code get_message_queue_id_send( rtems_id *queue_id )
753 756 {
754 757 rtems_status_code status;
755 758 rtems_name queue_name;
756 759
757 760 queue_name = rtems_build_name( 'Q', '_', 'S', 'D' );
758 761
759 762 status = rtems_message_queue_ident( queue_name, 0, queue_id );
760 763
761 764 return status;
762 765 }
763 766
764 767 rtems_status_code get_message_queue_id_recv( rtems_id *queue_id )
765 768 {
766 769 rtems_status_code status;
767 770 rtems_name queue_name;
768 771
769 772 queue_name = rtems_build_name( 'Q', '_', 'R', 'V' );
770 773
771 774 status = rtems_message_queue_ident( queue_name, 0, queue_id );
772 775
773 776 return status;
774 777 }
775 778
776 779 rtems_status_code get_message_queue_id_prc0( rtems_id *queue_id )
777 780 {
778 781 rtems_status_code status;
779 782 rtems_name queue_name;
780 783
781 784 queue_name = rtems_build_name( 'Q', '_', 'P', '0' );
782 785
783 786 status = rtems_message_queue_ident( queue_name, 0, queue_id );
784 787
785 788 return status;
786 789 }
787 790
788 791 rtems_status_code get_message_queue_id_prc1( rtems_id *queue_id )
789 792 {
790 793 rtems_status_code status;
791 794 rtems_name queue_name;
792 795
793 796 queue_name = rtems_build_name( 'Q', '_', 'P', '1' );
794 797
795 798 status = rtems_message_queue_ident( queue_name, 0, queue_id );
796 799
797 800 return status;
798 801 }
799 802
800 803 rtems_status_code get_message_queue_id_prc2( rtems_id *queue_id )
801 804 {
802 805 rtems_status_code status;
803 806 rtems_name queue_name;
804 807
805 808 queue_name = rtems_build_name( 'Q', '_', 'P', '2' );
806 809
807 810 status = rtems_message_queue_ident( queue_name, 0, queue_id );
808 811
809 812 return status;
810 813 }
@@ -1,506 +1,511
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 configure_timer(gptimer_regs_t *gptimer_regs, 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( gptimer_regs, timer, clock_divider);
37 37 }
38 38
39 39 void timer_start(gptimer_regs_t *gptimer_regs, 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(gptimer_regs_t *gptimer_regs, 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(gptimer_regs_t *gptimer_regs, 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 int send_console_outputs_on_apbuart_port( void ) // Send the console outputs on the apbuart port
83 83 {
84 84 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART;
85 85
86 86 apbuart_regs->ctrl = APBUART_CTRL_REG_MASK_TE;
87 87
88 88 return 0;
89 89 }
90 90
91 91 int enable_apbuart_transmitter( void ) // set the bit 1, TE Transmitter Enable to 1 in the APBUART control register
92 92 {
93 93 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART;
94 94
95 95 apbuart_regs->ctrl = apbuart_regs->ctrl | APBUART_CTRL_REG_MASK_TE;
96 96
97 97 return 0;
98 98 }
99 99
100 100 void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value)
101 101 {
102 102 /** This function sets the scaler reload register of the apbuart module
103 103 *
104 104 * @param regs is the address of the apbuart registers in memory
105 105 * @param value is the value that will be stored in the scaler register
106 106 *
107 107 * The value shall be set by the software to get data on the serial interface.
108 108 *
109 109 */
110 110
111 111 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) regs;
112 112
113 113 apbuart_regs->scaler = value;
114 114 BOOT_PRINTF1("OK *** apbuart port scaler reload register set to 0x%x\n", value)
115 115 }
116 116
117 117 //************
118 118 // RTEMS TASKS
119 119
120 120 rtems_task stat_task(rtems_task_argument argument)
121 121 {
122 122 int i;
123 123 int j;
124 124 i = 0;
125 125 j = 0;
126 126 BOOT_PRINTF("in STAT *** \n")
127 127 while(1){
128 128 rtems_task_wake_after(1000);
129 129 PRINTF1("%d\n", j)
130 130 if (i == CPU_USAGE_REPORT_PERIOD) {
131 131 // #ifdef PRINT_TASK_STATISTICS
132 132 // rtems_cpu_usage_report();
133 133 // rtems_cpu_usage_reset();
134 134 // #endif
135 135 i = 0;
136 136 }
137 137 else i++;
138 138 j++;
139 139 }
140 140 }
141 141
142 142 rtems_task hous_task(rtems_task_argument argument)
143 143 {
144 144 rtems_status_code status;
145 145 rtems_status_code spare_status;
146 146 rtems_id queue_id;
147 147 rtems_rate_monotonic_period_status period_status;
148 148
149 149 status = get_message_queue_id_send( &queue_id );
150 150 if (status != RTEMS_SUCCESSFUL)
151 151 {
152 152 PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status)
153 153 }
154 154
155 155 BOOT_PRINTF("in HOUS ***\n")
156 156
157 157 if (rtems_rate_monotonic_ident( name_hk_rate_monotonic, &HK_id) != RTEMS_SUCCESSFUL) {
158 158 status = rtems_rate_monotonic_create( name_hk_rate_monotonic, &HK_id );
159 159 if( status != RTEMS_SUCCESSFUL ) {
160 160 PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status )
161 161 }
162 162 }
163 163
164 164 housekeeping_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
165 165 housekeeping_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
166 166 housekeeping_packet.reserved = DEFAULT_RESERVED;
167 167 housekeeping_packet.userApplication = CCSDS_USER_APP;
168 168 housekeeping_packet.packetID[0] = (unsigned char) (APID_TM_HK >> 8);
169 169 housekeeping_packet.packetID[1] = (unsigned char) (APID_TM_HK);
170 170 housekeeping_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
171 171 housekeeping_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
172 172 housekeeping_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> 8);
173 173 housekeeping_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK );
174 174 housekeeping_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
175 175 housekeeping_packet.serviceType = TM_TYPE_HK;
176 176 housekeeping_packet.serviceSubType = TM_SUBTYPE_HK;
177 177 housekeeping_packet.destinationID = TM_DESTINATION_ID_GROUND;
178 178 housekeeping_packet.sid = SID_HK;
179 179
180 180 status = rtems_rate_monotonic_cancel(HK_id);
181 181 if( status != RTEMS_SUCCESSFUL ) {
182 182 PRINTF1( "ERR *** in HOUS *** rtems_rate_monotonic_cancel(HK_id) ***code: %d\n", status )
183 183 }
184 184 else {
185 185 DEBUG_PRINTF("OK *** in HOUS *** rtems_rate_monotonic_cancel(HK_id)\n")
186 186 }
187 187
188 188 // startup phase
189 189 status = rtems_rate_monotonic_period( HK_id, SY_LFR_TIME_SYN_TIMEOUT_in_ticks );
190 190 status = rtems_rate_monotonic_get_status( HK_id, &period_status );
191 191 DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state)
192 192 while(period_status.state != RATE_MONOTONIC_EXPIRED ) // after SY_LFR_TIME_SYN_TIMEOUT ms, starts HK anyway
193 193 {
194 194 if ((time_management_regs->coarse_time & 0x80000000) == 0x00000000) // check time synchronization
195 195 {
196 196 break; // break if LFR is synchronized
197 197 }
198 198 else
199 199 {
200 200 status = rtems_rate_monotonic_get_status( HK_id, &period_status );
201 201 // sched_yield();
202 202 status = rtems_task_wake_after( 10 ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 100 ms = 10 * 10 ms
203 203 }
204 204 }
205 205 status = rtems_rate_monotonic_cancel(HK_id);
206 206 DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state)
207 207
208 208 while(1){ // launch the rate monotonic task
209 209 status = rtems_rate_monotonic_period( HK_id, HK_PERIOD );
210 210 if ( status != RTEMS_SUCCESSFUL ) {
211 211 PRINTF1( "in HOUS *** ERR period: %d\n", status);
212 212 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_6 );
213 213 }
214 214 else {
215 215 housekeeping_packet.packetSequenceControl[0] = (unsigned char) (sequenceCounterHK >> 8);
216 216 housekeeping_packet.packetSequenceControl[1] = (unsigned char) (sequenceCounterHK );
217 217 increment_seq_counter( &sequenceCounterHK );
218 218
219 219 housekeeping_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
220 220 housekeeping_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
221 221 housekeeping_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
222 222 housekeeping_packet.time[3] = (unsigned char) (time_management_regs->coarse_time);
223 223 housekeeping_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
224 224 housekeeping_packet.time[5] = (unsigned char) (time_management_regs->fine_time);
225 225
226 226 spacewire_update_statistics();
227 227
228 228 get_temperatures( housekeeping_packet.hk_lfr_temp_scm );
229 229 get_v_e1_e2_f3( housekeeping_packet.hk_lfr_sc_v_f3 );
230 230 get_cpu_load( (unsigned char *) &housekeeping_packet.hk_lfr_cpu_load );
231 231
232 232 // SEND PACKET
233 233 status = rtems_message_queue_send( queue_id, &housekeeping_packet,
234 234 PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
235 235 if (status != RTEMS_SUCCESSFUL) {
236 236 PRINTF1("in HOUS *** ERR send: %d\n", status)
237 237 }
238 238 }
239 239 }
240 240
241 241 PRINTF("in HOUS *** deleting task\n")
242 242
243 243 status = rtems_task_delete( RTEMS_SELF ); // should not return
244 244 printf( "rtems_task_delete returned with status of %d.\n", status );
245 245 return;
246 246 }
247 247
248 248 rtems_task dumb_task( rtems_task_argument unused )
249 249 {
250 250 /** This RTEMS taks is used to print messages without affecting the general behaviour of the software.
251 251 *
252 252 * @param unused is the starting argument of the RTEMS task
253 253 *
254 254 * The DUMB taks waits for RTEMS events and print messages depending on the incoming events.
255 255 *
256 256 */
257 257
258 258 unsigned int i;
259 259 unsigned int intEventOut;
260 260 unsigned int coarse_time = 0;
261 261 unsigned int fine_time = 0;
262 262 rtems_event_set event_out;
263 263
264 264 char *DumbMessages[12] = {"in DUMB *** default", // RTEMS_EVENT_0
265 265 "in DUMB *** timecode_irq_handler", // RTEMS_EVENT_1
266 266 "in DUMB *** f3 buffer changed", // RTEMS_EVENT_2
267 267 "in DUMB *** in SMIQ *** Error sending event to AVF0", // RTEMS_EVENT_3
268 268 "in DUMB *** spectral_matrices_isr *** Error sending event to SMIQ", // RTEMS_EVENT_4
269 269 "in DUMB *** waveforms_simulator_isr", // RTEMS_EVENT_5
270 270 "VHDL SM *** two buffers f0 ready", // RTEMS_EVENT_6
271 271 "ready for dump", // RTEMS_EVENT_7
272 272 "VHDL ERR *** spectral matrix", // RTEMS_EVENT_8
273 273 "tick", // RTEMS_EVENT_9
274 274 "VHDL ERR *** waveform picker", // RTEMS_EVENT_10
275 275 "VHDL ERR *** unexpected ready matrix values" // RTEMS_EVENT_11
276 276 };
277 277
278 278 BOOT_PRINTF("in DUMB *** \n")
279 279
280 280 while(1){
281 281 rtems_event_receive(RTEMS_EVENT_0 | RTEMS_EVENT_1 | RTEMS_EVENT_2 | RTEMS_EVENT_3
282 282 | RTEMS_EVENT_4 | RTEMS_EVENT_5 | RTEMS_EVENT_6 | RTEMS_EVENT_7
283 283 | RTEMS_EVENT_8 | RTEMS_EVENT_9,
284 284 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT
285 285 intEventOut = (unsigned int) event_out;
286 286 for ( i=0; i<32; i++)
287 287 {
288 288 if ( ((intEventOut >> i) & 0x0001) != 0)
289 289 {
290 290 coarse_time = time_management_regs->coarse_time;
291 291 fine_time = time_management_regs->fine_time;
292 292 printf("in DUMB *** coarse: %x, fine: %x, %s\n", coarse_time, fine_time, DumbMessages[i]);
293 293 if (i==8)
294 294 {
295 295 }
296 296 if (i==10)
297 297 {
298 298 }
299 299 }
300 300 }
301 301 }
302 302 }
303 303
304 304 //*****************************
305 305 // init housekeeping parameters
306 306
307 307 void init_housekeeping_parameters( void )
308 308 {
309 309 /** This function initialize the housekeeping_packet global variable with default values.
310 310 *
311 311 */
312 312
313 313 unsigned int i = 0;
314 314 unsigned char *parameters;
315 315
316 316 parameters = (unsigned char*) &housekeeping_packet.lfr_status_word;
317 317 for(i = 0; i< SIZE_HK_PARAMETERS; i++)
318 318 {
319 319 parameters[i] = 0x00;
320 320 }
321 321 // init status word
322 322 housekeeping_packet.lfr_status_word[0] = DEFAULT_STATUS_WORD_BYTE0;
323 323 housekeeping_packet.lfr_status_word[1] = DEFAULT_STATUS_WORD_BYTE1;
324 324 // init software version
325 325 housekeeping_packet.lfr_sw_version[0] = SW_VERSION_N1;
326 326 housekeeping_packet.lfr_sw_version[1] = SW_VERSION_N2;
327 327 housekeeping_packet.lfr_sw_version[2] = SW_VERSION_N3;
328 328 housekeeping_packet.lfr_sw_version[3] = SW_VERSION_N4;
329 329 // init fpga version
330 330 parameters = (unsigned char *) (REGS_ADDR_VHDL_VERSION);
331 331 housekeeping_packet.lfr_fpga_version[0] = parameters[1]; // n1
332 332 housekeeping_packet.lfr_fpga_version[1] = parameters[2]; // n2
333 333 housekeeping_packet.lfr_fpga_version[2] = parameters[3]; // n3
334 334 }
335 335
336 336 void increment_seq_counter( unsigned short *packetSequenceControl )
337 337 {
338 338 /** This function increment the sequence counter psased in argument.
339 339 *
340 340 * The increment does not affect the grouping flag. In case of an overflow, the counter is reset to 0.
341 341 *
342 342 */
343 343
344 344 unsigned short segmentation_grouping_flag;
345 345 unsigned short sequence_cnt;
346 346
347 347 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << 8; // keep bits 7 downto 6
348 348 sequence_cnt = (*packetSequenceControl) & 0x3fff; // [0011 1111 1111 1111]
349 349
350 350 if ( sequence_cnt < SEQ_CNT_MAX)
351 351 {
352 352 sequence_cnt = sequence_cnt + 1;
353 353 }
354 354 else
355 355 {
356 356 sequence_cnt = 0;
357 357 }
358 358
359 359 *packetSequenceControl = segmentation_grouping_flag | sequence_cnt ;
360 360 }
361 361
362 362 void getTime( unsigned char *time)
363 363 {
364 364 /** This function write the current local time in the time buffer passed in argument.
365 365 *
366 366 */
367 367
368 368 time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
369 369 time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
370 370 time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
371 371 time[3] = (unsigned char) (time_management_regs->coarse_time);
372 372 time[4] = (unsigned char) (time_management_regs->fine_time>>8);
373 373 time[5] = (unsigned char) (time_management_regs->fine_time);
374 374 }
375 375
376 376 unsigned long long int getTimeAsUnsignedLongLongInt( )
377 377 {
378 378 /** This function write the current local time in the time buffer passed in argument.
379 379 *
380 380 */
381 381 unsigned long long int time;
382 382
383 383 time = ( (unsigned long long int) (time_management_regs->coarse_time & 0x7fffffff) << 16 )
384 384 + time_management_regs->fine_time;
385 385
386 386 return time;
387 387 }
388 388
389 389 void send_dumb_hk( void )
390 390 {
391 391 Packet_TM_LFR_HK_t dummy_hk_packet;
392 392 unsigned char *parameters;
393 393 unsigned int i;
394 394 rtems_id queue_id;
395 395
396 396 dummy_hk_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
397 397 dummy_hk_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
398 398 dummy_hk_packet.reserved = DEFAULT_RESERVED;
399 399 dummy_hk_packet.userApplication = CCSDS_USER_APP;
400 400 dummy_hk_packet.packetID[0] = (unsigned char) (APID_TM_HK >> 8);
401 401 dummy_hk_packet.packetID[1] = (unsigned char) (APID_TM_HK);
402 402 dummy_hk_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
403 403 dummy_hk_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
404 404 dummy_hk_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> 8);
405 405 dummy_hk_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK );
406 406 dummy_hk_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
407 407 dummy_hk_packet.serviceType = TM_TYPE_HK;
408 408 dummy_hk_packet.serviceSubType = TM_SUBTYPE_HK;
409 409 dummy_hk_packet.destinationID = TM_DESTINATION_ID_GROUND;
410 410 dummy_hk_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
411 411 dummy_hk_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
412 412 dummy_hk_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
413 413 dummy_hk_packet.time[3] = (unsigned char) (time_management_regs->coarse_time);
414 414 dummy_hk_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
415 415 dummy_hk_packet.time[5] = (unsigned char) (time_management_regs->fine_time);
416 416 dummy_hk_packet.sid = SID_HK;
417 417
418 418 // init status word
419 419 dummy_hk_packet.lfr_status_word[0] = 0xff;
420 420 dummy_hk_packet.lfr_status_word[1] = 0xff;
421 421 // init software version
422 422 dummy_hk_packet.lfr_sw_version[0] = SW_VERSION_N1;
423 423 dummy_hk_packet.lfr_sw_version[1] = SW_VERSION_N2;
424 424 dummy_hk_packet.lfr_sw_version[2] = SW_VERSION_N3;
425 425 dummy_hk_packet.lfr_sw_version[3] = SW_VERSION_N4;
426 426 // init fpga version
427 427 parameters = (unsigned char *) (REGS_ADDR_WAVEFORM_PICKER + 0xb0);
428 428 dummy_hk_packet.lfr_fpga_version[0] = parameters[1]; // n1
429 429 dummy_hk_packet.lfr_fpga_version[1] = parameters[2]; // n2
430 430 dummy_hk_packet.lfr_fpga_version[2] = parameters[3]; // n3
431 431
432 432 parameters = (unsigned char *) &dummy_hk_packet.hk_lfr_cpu_load;
433 433
434 434 for (i=0; i<100; i++)
435 435 {
436 436 parameters[i] = 0xff;
437 437 }
438 438
439 439 get_message_queue_id_send( &queue_id );
440 440
441 441 rtems_message_queue_send( queue_id, &dummy_hk_packet,
442 442 PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
443 443 }
444 444
445 445 void get_temperatures( unsigned char *temperatures )
446 446 {
447 447 unsigned char* temp_scm_ptr;
448 448 unsigned char* temp_pcb_ptr;
449 449 unsigned char* temp_fpga_ptr;
450 450
451 // SEL1 SEL0
452 // 0 0 => PCB
453 // 0 1 => FPGA
454 // 1 0 => SCM
455
451 456 temp_scm_ptr = (unsigned char *) &time_management_regs->temp_scm;
452 457 temp_pcb_ptr = (unsigned char *) &time_management_regs->temp_pcb;
453 458 temp_fpga_ptr = (unsigned char *) &time_management_regs->temp_fpga;
454 459
455 460 temperatures[0] = temp_scm_ptr[2];
456 461 temperatures[1] = temp_scm_ptr[3];
457 462 temperatures[2] = temp_pcb_ptr[2];
458 463 temperatures[3] = temp_pcb_ptr[3];
459 464 temperatures[4] = temp_fpga_ptr[2];
460 465 temperatures[5] = temp_fpga_ptr[3];
461 466 }
462 467
463 468 void get_v_e1_e2_f3( unsigned char *spacecraft_potential )
464 469 {
465 470 unsigned char* v_ptr;
466 471 unsigned char* e1_ptr;
467 472 unsigned char* e2_ptr;
468 473
469 474 v_ptr = (unsigned char *) &waveform_picker_regs->v;
470 475 e1_ptr = (unsigned char *) &waveform_picker_regs->e1;
471 476 e2_ptr = (unsigned char *) &waveform_picker_regs->e2;
472 477
473 478 spacecraft_potential[0] = v_ptr[2];
474 479 spacecraft_potential[1] = v_ptr[3];
475 480 spacecraft_potential[2] = e1_ptr[2];
476 481 spacecraft_potential[3] = e1_ptr[3];
477 482 spacecraft_potential[4] = e2_ptr[2];
478 483 spacecraft_potential[5] = e2_ptr[3];
479 484 }
480 485
481 486 void get_cpu_load( unsigned char *resource_statistics )
482 487 {
483 488 unsigned char cpu_load;
484 489
485 490 cpu_load = lfr_rtems_cpu_usage_report();
486 491
487 492 // HK_LFR_CPU_LOAD
488 493 resource_statistics[0] = cpu_load;
489 494
490 495 // HK_LFR_CPU_LOAD_MAX
491 496 if (cpu_load > resource_statistics[1])
492 497 {
493 498 resource_statistics[1] = cpu_load;
494 499 }
495 500
496 501 // CPU_LOAD_AVE
497 502 resource_statistics[2] = 0;
498 503
499 504 #ifndef PRINT_TASK_STATISTICS
500 505 rtems_cpu_usage_reset();
501 506 #endif
502 507
503 508 }
504 509
505 510
506 511
@@ -1,971 +1,1117
1 1 /** Functions and tasks related to TeleCommand handling.
2 2 *
3 3 * @file
4 4 * @author P. LEROY
5 5 *
6 6 * A group of functions to handle TeleCommands:\n
7 7 * action launching\n
8 8 * TC parsing\n
9 9 * ...
10 10 *
11 11 */
12 12
13 13 #include "tc_handler.h"
14 #include "math.h"
14 15
15 16 //***********
16 17 // RTEMS TASK
17 18
18 19 rtems_task actn_task( rtems_task_argument unused )
19 20 {
20 21 /** This RTEMS task is responsible for launching actions upton the reception of valid TeleCommands.
21 22 *
22 23 * @param unused is the starting argument of the RTEMS task
23 24 *
24 25 * The ACTN task waits for data coming from an RTEMS msesage queue. When data arrives, it launches specific actions depending
25 26 * on the incoming TeleCommand.
26 27 *
27 28 */
28 29
29 30 int result;
30 31 rtems_status_code status; // RTEMS status code
31 32 ccsdsTelecommandPacket_t TC; // TC sent to the ACTN task
32 33 size_t size; // size of the incoming TC packet
33 34 unsigned char subtype; // subtype of the current TC packet
34 35 unsigned char time[6];
35 36 rtems_id queue_rcv_id;
36 37 rtems_id queue_snd_id;
37 38
38 39 status = get_message_queue_id_recv( &queue_rcv_id );
39 40 if (status != RTEMS_SUCCESSFUL)
40 41 {
41 42 PRINTF1("in ACTN *** ERR get_message_queue_id_recv %d\n", status)
42 43 }
43 44
44 45 status = get_message_queue_id_send( &queue_snd_id );
45 46 if (status != RTEMS_SUCCESSFUL)
46 47 {
47 48 PRINTF1("in ACTN *** ERR get_message_queue_id_send %d\n", status)
48 49 }
49 50
50 51 result = LFR_SUCCESSFUL;
51 52 subtype = 0; // subtype of the current TC packet
52 53
53 54 BOOT_PRINTF("in ACTN *** \n")
54 55
55 56 while(1)
56 57 {
57 58 status = rtems_message_queue_receive( queue_rcv_id, (char*) &TC, &size,
58 59 RTEMS_WAIT, RTEMS_NO_TIMEOUT);
59 60 getTime( time ); // set time to the current time
60 61 if (status!=RTEMS_SUCCESSFUL)
61 62 {
62 63 PRINTF1("ERR *** in task ACTN *** error receiving a message, code %d \n", status)
63 64 }
64 65 else
65 66 {
66 67 subtype = TC.serviceSubType;
67 68 switch(subtype)
68 69 {
69 70 case TC_SUBTYPE_RESET:
70 71 result = action_reset( &TC, queue_snd_id, time );
71 72 close_action( &TC, result, queue_snd_id );
72 73 break;
73 74 //
74 75 case TC_SUBTYPE_LOAD_COMM:
75 76 result = action_load_common_par( &TC );
76 77 close_action( &TC, result, queue_snd_id );
77 78 break;
78 79 //
79 80 case TC_SUBTYPE_LOAD_NORM:
80 81 result = action_load_normal_par( &TC, queue_snd_id, time );
81 82 close_action( &TC, result, queue_snd_id );
82 83 break;
83 84 //
84 85 case TC_SUBTYPE_LOAD_BURST:
85 86 result = action_load_burst_par( &TC, queue_snd_id, time );
86 87 close_action( &TC, result, queue_snd_id );
87 88 break;
88 89 //
89 90 case TC_SUBTYPE_LOAD_SBM1:
90 91 result = action_load_sbm1_par( &TC, queue_snd_id, time );
91 92 close_action( &TC, result, queue_snd_id );
92 93 break;
93 94 //
94 95 case TC_SUBTYPE_LOAD_SBM2:
95 96 result = action_load_sbm2_par( &TC, queue_snd_id, time );
96 97 close_action( &TC, result, queue_snd_id );
97 98 break;
98 99 //
99 100 case TC_SUBTYPE_DUMP:
100 101 result = action_dump_par( queue_snd_id );
101 102 close_action( &TC, result, queue_snd_id );
102 103 break;
103 104 //
104 105 case TC_SUBTYPE_ENTER:
105 106 result = action_enter_mode( &TC, queue_snd_id );
106 107 close_action( &TC, result, queue_snd_id );
107 108 break;
108 109 //
109 110 case TC_SUBTYPE_UPDT_INFO:
110 111 result = action_update_info( &TC, queue_snd_id );
111 112 close_action( &TC, result, queue_snd_id );
112 113 break;
113 114 //
114 115 case TC_SUBTYPE_EN_CAL:
115 116 result = action_enable_calibration( &TC, queue_snd_id, time );
116 117 close_action( &TC, result, queue_snd_id );
117 118 break;
118 119 //
119 120 case TC_SUBTYPE_DIS_CAL:
120 121 result = action_disable_calibration( &TC, queue_snd_id, time );
121 122 close_action( &TC, result, queue_snd_id );
122 123 break;
123 124 //
124 125 case TC_SUBTYPE_UPDT_TIME:
125 126 result = action_update_time( &TC );
126 127 close_action( &TC, result, queue_snd_id );
127 128 break;
128 129 //
129 130 default:
130 131 break;
131 132 }
132 133 }
133 134 }
134 135 }
135 136
136 137 //***********
137 138 // TC ACTIONS
138 139
139 140 int action_reset(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
140 141 {
141 142 /** This function executes specific actions when a TC_LFR_RESET TeleCommand has been received.
142 143 *
143 144 * @param TC points to the TeleCommand packet that is being processed
144 145 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
145 146 *
146 147 */
147 148
148 149 printf("this is the end!!!\n");
149 150 exit(0);
150 151 send_tm_lfr_tc_exe_not_implemented( TC, queue_id, time );
151 152 return LFR_DEFAULT;
152 153 }
153 154
154 155 int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
155 156 {
156 157 /** This function executes specific actions when a TC_LFR_ENTER_MODE TeleCommand has been received.
157 158 *
158 159 * @param TC points to the TeleCommand packet that is being processed
159 160 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
160 161 *
161 162 */
162 163
163 164 rtems_status_code status;
164 165 unsigned char requestedMode;
165 166 unsigned int *transitionCoarseTime_ptr;
166 167 unsigned int transitionCoarseTime;
167 168 unsigned char * bytePosPtr;
168 169
169 170 bytePosPtr = (unsigned char *) &TC->packetID;
170 171
171 172 requestedMode = bytePosPtr[ BYTE_POS_CP_MODE_LFR_SET ];
172 173 transitionCoarseTime_ptr = (unsigned int *) ( &bytePosPtr[ BYTE_POS_CP_LFR_ENTER_MODE_TIME ] );
173 174 transitionCoarseTime = (*transitionCoarseTime_ptr) & 0x7fffffff;
174 175
175 176 status = check_mode_value( requestedMode );
176 177
177 178 if ( status != LFR_SUCCESSFUL ) // the mode value is inconsistent
178 179 {
179 180 send_tm_lfr_tc_exe_inconsistent( TC, queue_id, BYTE_POS_CP_MODE_LFR_SET, requestedMode );
180 181 }
181 182 else // the mode value is consistent, check the transition
182 183 {
183 184 status = check_mode_transition(requestedMode);
184 185 if (status != LFR_SUCCESSFUL)
185 186 {
186 187 PRINTF("ERR *** in action_enter_mode *** check_mode_transition\n")
187 188 send_tm_lfr_tc_exe_not_executable( TC, queue_id );
188 189 }
189 190 }
190 191
191 192 if ( status == LFR_SUCCESSFUL ) // the transition is valid, enter the mode
192 193 {
193 194 status = check_transition_date( transitionCoarseTime );
194 195 if (status != LFR_SUCCESSFUL)
195 196 {
196 197 PRINTF("ERR *** in action_enter_mode *** check_transition_date\n")
197 198 send_tm_lfr_tc_exe_inconsistent( TC, queue_id,
198 199 BYTE_POS_CP_LFR_ENTER_MODE_TIME,
199 200 bytePosPtr[ BYTE_POS_CP_LFR_ENTER_MODE_TIME + 3 ] );
200 201 }
201 202 }
202 203
203 204 if ( status == LFR_SUCCESSFUL ) // the date is valid, enter the mode
204 205 {
205 206 PRINTF1("OK *** in action_enter_mode *** enter mode %d\n", requestedMode);
206 207 status = enter_mode( requestedMode, transitionCoarseTime );
207 208 }
208 209
209 210 return status;
210 211 }
211 212
212 213 int action_update_info(ccsdsTelecommandPacket_t *TC, rtems_id queue_id)
213 214 {
214 215 /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received.
215 216 *
216 217 * @param TC points to the TeleCommand packet that is being processed
217 218 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
218 219 *
219 220 * @return LFR directive status code:
220 221 * - LFR_DEFAULT
221 222 * - LFR_SUCCESSFUL
222 223 *
223 224 */
224 225
225 226 unsigned int val;
226 227 int result;
227 228 unsigned int status;
228 229 unsigned char mode;
229 230 unsigned char * bytePosPtr;
230 231
231 232 bytePosPtr = (unsigned char *) &TC->packetID;
232 233
233 234 // check LFR mode
234 235 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET5 ] & 0x1e) >> 1;
235 236 status = check_update_info_hk_lfr_mode( mode );
236 237 if (status == LFR_SUCCESSFUL) // check TDS mode
237 238 {
238 239 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & 0xf0) >> 4;
239 240 status = check_update_info_hk_tds_mode( mode );
240 241 }
241 242 if (status == LFR_SUCCESSFUL) // check THR mode
242 243 {
243 244 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & 0x0f);
244 245 status = check_update_info_hk_thr_mode( mode );
245 246 }
246 247 if (status == LFR_SUCCESSFUL) // if the parameter check is successful
247 248 {
248 249 val = housekeeping_packet.hk_lfr_update_info_tc_cnt[0] * 256
249 250 + housekeeping_packet.hk_lfr_update_info_tc_cnt[1];
250 251 val++;
251 252 housekeeping_packet.hk_lfr_update_info_tc_cnt[0] = (unsigned char) (val >> 8);
252 253 housekeeping_packet.hk_lfr_update_info_tc_cnt[1] = (unsigned char) (val);
253 254 }
254 255
255 256 result = status;
256 257
257 258 return result;
258 259 }
259 260
260 261 int action_enable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
261 262 {
262 263 /** This function executes specific actions when a TC_LFR_ENABLE_CALIBRATION TeleCommand has been received.
263 264 *
264 265 * @param TC points to the TeleCommand packet that is being processed
265 266 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
266 267 *
267 268 */
268 269
269 270 int result;
270 unsigned char lfrMode;
271 271
272 272 result = LFR_DEFAULT;
273 lfrMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4;
274 273
275 send_tm_lfr_tc_exe_not_implemented( TC, queue_id, time );
276 result = LFR_DEFAULT;
274 startCalibration();
275
276 result = LFR_SUCCESSFUL;
277 277
278 278 return result;
279 279 }
280 280
281 281 int action_disable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
282 282 {
283 283 /** This function executes specific actions when a TC_LFR_DISABLE_CALIBRATION TeleCommand has been received.
284 284 *
285 285 * @param TC points to the TeleCommand packet that is being processed
286 286 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
287 287 *
288 288 */
289 289
290 290 int result;
291 unsigned char lfrMode;
292 291
293 292 result = LFR_DEFAULT;
294 lfrMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4;
295 293
296 send_tm_lfr_tc_exe_not_implemented( TC, queue_id, time );
297 result = LFR_DEFAULT;
294 stopCalibration();
295
296 result = LFR_SUCCESSFUL;
298 297
299 298 return result;
300 299 }
301 300
302 301 int action_update_time(ccsdsTelecommandPacket_t *TC)
303 302 {
304 303 /** This function executes specific actions when a TC_LFR_UPDATE_TIME TeleCommand has been received.
305 304 *
306 305 * @param TC points to the TeleCommand packet that is being processed
307 306 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
308 307 *
309 308 * @return LFR_SUCCESSFUL
310 309 *
311 310 */
312 311
313 312 unsigned int val;
314 313
315 314 time_management_regs->coarse_time_load = (TC->dataAndCRC[0] << 24)
316 315 + (TC->dataAndCRC[1] << 16)
317 316 + (TC->dataAndCRC[2] << 8)
318 317 + TC->dataAndCRC[3];
319 318
320 319 val = housekeeping_packet.hk_lfr_update_time_tc_cnt[0] * 256
321 320 + housekeeping_packet.hk_lfr_update_time_tc_cnt[1];
322 321 val++;
323 322 housekeeping_packet.hk_lfr_update_time_tc_cnt[0] = (unsigned char) (val >> 8);
324 323 housekeeping_packet.hk_lfr_update_time_tc_cnt[1] = (unsigned char) (val);
325 324
326 325 return LFR_SUCCESSFUL;
327 326 }
328 327
329 328 //*******************
330 329 // ENTERING THE MODES
331 330 int check_mode_value( unsigned char requestedMode )
332 331 {
333 332 int status;
334 333
335 334 if ( (requestedMode != LFR_MODE_STANDBY)
336 335 && (requestedMode != LFR_MODE_NORMAL) && (requestedMode != LFR_MODE_BURST)
337 336 && (requestedMode != LFR_MODE_SBM1) && (requestedMode != LFR_MODE_SBM2) )
338 337 {
339 338 status = LFR_DEFAULT;
340 339 }
341 340 else
342 341 {
343 342 status = LFR_SUCCESSFUL;
344 343 }
345 344
346 345 return status;
347 346 }
348 347
349 348 int check_mode_transition( unsigned char requestedMode )
350 349 {
351 350 /** This function checks the validity of the transition requested by the TC_LFR_ENTER_MODE.
352 351 *
353 352 * @param requestedMode is the mode requested by the TC_LFR_ENTER_MODE
354 353 *
355 354 * @return LFR directive status codes:
356 355 * - LFR_SUCCESSFUL - the transition is authorized
357 356 * - LFR_DEFAULT - the transition is not authorized
358 357 *
359 358 */
360 359
361 360 int status;
362 361
363 362 switch (requestedMode)
364 363 {
365 364 case LFR_MODE_STANDBY:
366 365 if ( lfrCurrentMode == LFR_MODE_STANDBY ) {
367 366 status = LFR_DEFAULT;
368 367 }
369 368 else
370 369 {
371 370 status = LFR_SUCCESSFUL;
372 371 }
373 372 break;
374 373 case LFR_MODE_NORMAL:
375 374 if ( lfrCurrentMode == LFR_MODE_NORMAL ) {
376 375 status = LFR_DEFAULT;
377 376 }
378 377 else {
379 378 status = LFR_SUCCESSFUL;
380 379 }
381 380 break;
382 381 case LFR_MODE_BURST:
383 382 if ( lfrCurrentMode == LFR_MODE_BURST ) {
384 383 status = LFR_DEFAULT;
385 384 }
386 385 else {
387 386 status = LFR_SUCCESSFUL;
388 387 }
389 388 break;
390 389 case LFR_MODE_SBM1:
391 390 if ( lfrCurrentMode == LFR_MODE_SBM1 ) {
392 391 status = LFR_DEFAULT;
393 392 }
394 393 else {
395 394 status = LFR_SUCCESSFUL;
396 395 }
397 396 break;
398 397 case LFR_MODE_SBM2:
399 398 if ( lfrCurrentMode == LFR_MODE_SBM2 ) {
400 399 status = LFR_DEFAULT;
401 400 }
402 401 else {
403 402 status = LFR_SUCCESSFUL;
404 403 }
405 404 break;
406 405 default:
407 406 status = LFR_DEFAULT;
408 407 break;
409 408 }
410 409
411 410 return status;
412 411 }
413 412
414 413 int check_transition_date( unsigned int transitionCoarseTime )
415 414 {
416 415 int status;
417 416 unsigned int localCoarseTime;
418 417 unsigned int deltaCoarseTime;
419 418
420 419 status = LFR_SUCCESSFUL;
421 420
422 421 if (transitionCoarseTime == 0) // transition time = 0 means an instant transition
423 422 {
424 423 status = LFR_SUCCESSFUL;
425 424 }
426 425 else
427 426 {
428 427 localCoarseTime = time_management_regs->coarse_time & 0x7fffffff;
429 428
430 429 if ( transitionCoarseTime <= localCoarseTime ) // SSS-CP-EQS-322
431 430 {
432 431 status = LFR_DEFAULT;
433 432 PRINTF2("ERR *** in check_transition_date *** transition = %x, local = %x\n", transitionCoarseTime, localCoarseTime)
434 433 }
435 434
436 435 if (status == LFR_SUCCESSFUL)
437 436 {
438 437 deltaCoarseTime = transitionCoarseTime - localCoarseTime;
439 438 if ( deltaCoarseTime > 3 ) // SSS-CP-EQS-323
440 439 {
441 440 status = LFR_DEFAULT;
442 441 PRINTF1("ERR *** in check_transition_date *** deltaCoarseTime = %x\n", deltaCoarseTime)
443 442 }
444 443 }
445 444 }
446 445
447 446 return status;
448 447 }
449 448
450 449 int stop_current_mode( void )
451 450 {
452 451 /** This function stops the current mode by masking interrupt lines and suspending science tasks.
453 452 *
454 453 * @return RTEMS directive status codes:
455 454 * - RTEMS_SUCCESSFUL - task restarted successfully
456 455 * - RTEMS_INVALID_ID - task id invalid
457 456 * - RTEMS_ALREADY_SUSPENDED - task already suspended
458 457 *
459 458 */
460 459
461 460 rtems_status_code status;
462 461
463 462 status = RTEMS_SUCCESSFUL;
464 463
465 464 // (1) mask interruptions
466 465 LEON_Mask_interrupt( IRQ_WAVEFORM_PICKER ); // mask waveform picker interrupt
467 466 LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
468 467
469 468 // (2) reset waveform picker registers
470 469 reset_wfp_burst_enable(); // reset burst and enable bits
471 470 reset_wfp_status(); // reset all the status bits
472 471
473 472 // (3) reset spectral matrices registers
474 473 set_sm_irq_onNewMatrix( 0 ); // stop the spectral matrices
475 474 reset_sm_status();
476 475
477 476 // reset lfr VHDL module
478 477 reset_lfr();
479 478
480 479 reset_extractSWF(); // reset the extractSWF flag to false
481 480
482 481 // (4) clear interruptions
483 482 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER ); // clear waveform picker interrupt
484 483 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
485 484
486 485 // <Spectral Matrices simulator>
487 486 LEON_Mask_interrupt( IRQ_SM_SIMULATOR ); // mask spectral matrix interrupt simulator
488 487 timer_stop( (gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_SM_SIMULATOR );
489 488 LEON_Clear_interrupt( IRQ_SM_SIMULATOR ); // clear spectral matrix interrupt simulator
490 489 // </Spectral Matrices simulator>
491 490
492 491 // suspend several tasks
493 492 if (lfrCurrentMode != LFR_MODE_STANDBY) {
494 493 status = suspend_science_tasks();
495 494 }
496 495
497 496 if (status != RTEMS_SUCCESSFUL)
498 497 {
499 498 PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status)
500 499 }
501 500
502 501 return status;
503 502 }
504 503
505 504 int enter_mode( unsigned char mode, unsigned int transitionCoarseTime )
506 505 {
507 506 /** This function is launched after a mode transition validation.
508 507 *
509 508 * @param mode is the mode in which LFR will be put.
510 509 *
511 510 * @return RTEMS directive status codes:
512 511 * - RTEMS_SUCCESSFUL - the mode has been entered successfully
513 512 * - RTEMS_NOT_SATISFIED - the mode has not been entered successfully
514 513 *
515 514 */
516 515
517 516 rtems_status_code status;
518 517
519 518 //**********************
520 519 // STOP THE CURRENT MODE
521 520 status = stop_current_mode();
522 521 if (status != RTEMS_SUCCESSFUL)
523 522 {
524 523 PRINTF1("ERR *** in enter_mode *** stop_current_mode with mode = %d\n", mode)
525 524 }
526 525
527 526 //*************************
528 527 // ENTER THE REQUESTED MODE
529 528 if ( (mode == LFR_MODE_NORMAL) || (mode == LFR_MODE_BURST)
530 529 || (mode == LFR_MODE_SBM1) || (mode == LFR_MODE_SBM2) )
531 530 {
532 531 #ifdef PRINT_TASK_STATISTICS
533 532 rtems_cpu_usage_reset();
534 533 maxCount = 0;
535 534 #endif
536 535 status = restart_science_tasks( mode );
537 536 launch_spectral_matrix( );
538 537 launch_waveform_picker( mode, transitionCoarseTime );
539 538 // launch_spectral_matrix_simu( );
540 539 }
541 540 else if ( mode == LFR_MODE_STANDBY )
542 541 {
543 542 #ifdef PRINT_TASK_STATISTICS
544 543 rtems_cpu_usage_report();
545 544 #endif
546 545
547 546 #ifdef PRINT_STACK_REPORT
548 547 PRINTF("stack report selected\n")
549 548 rtems_stack_checker_report_usage();
550 549 #endif
551 550 PRINTF1("maxCount = %d\n", maxCount)
552 551 }
553 552 else
554 553 {
555 554 status = RTEMS_UNSATISFIED;
556 555 }
557 556
558 557 if (status != RTEMS_SUCCESSFUL)
559 558 {
560 559 PRINTF1("ERR *** in enter_mode *** status = %d\n", status)
561 560 status = RTEMS_UNSATISFIED;
562 561 }
563 562
564 563 return status;
565 564 }
566 565
567 566 int restart_science_tasks(unsigned char lfrRequestedMode )
568 567 {
569 568 /** This function is used to restart all science tasks.
570 569 *
571 570 * @return RTEMS directive status codes:
572 571 * - RTEMS_SUCCESSFUL - task restarted successfully
573 572 * - RTEMS_INVALID_ID - task id invalid
574 573 * - RTEMS_INCORRECT_STATE - task never started
575 574 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
576 575 *
577 576 * Science tasks are AVF0, PRC0, WFRM, CWF3, CW2, CWF1
578 577 *
579 578 */
580 579
581 580 rtems_status_code status[10];
582 581 rtems_status_code ret;
583 582
584 583 ret = RTEMS_SUCCESSFUL;
585 584
586 585 status[0] = rtems_task_restart( Task_id[TASKID_AVF0], lfrRequestedMode );
587 586 if (status[0] != RTEMS_SUCCESSFUL)
588 587 {
589 588 PRINTF1("in restart_science_task *** AVF0 ERR %d\n", status[0])
590 589 }
591 590
592 591 status[1] = rtems_task_restart( Task_id[TASKID_PRC0], lfrRequestedMode );
593 592 if (status[1] != RTEMS_SUCCESSFUL)
594 593 {
595 594 PRINTF1("in restart_science_task *** PRC0 ERR %d\n", status[1])
596 595 }
597 596
598 597 status[2] = rtems_task_restart( Task_id[TASKID_WFRM],1 );
599 598 if (status[2] != RTEMS_SUCCESSFUL)
600 599 {
601 600 PRINTF1("in restart_science_task *** WFRM ERR %d\n", status[2])
602 601 }
603 602
604 603 status[3] = rtems_task_restart( Task_id[TASKID_CWF3],1 );
605 604 if (status[3] != RTEMS_SUCCESSFUL)
606 605 {
607 606 PRINTF1("in restart_science_task *** CWF3 ERR %d\n", status[3])
608 607 }
609 608
610 609 status[4] = rtems_task_restart( Task_id[TASKID_CWF2],1 );
611 610 if (status[4] != RTEMS_SUCCESSFUL)
612 611 {
613 612 PRINTF1("in restart_science_task *** CWF2 ERR %d\n", status[4])
614 613 }
615 614
616 615 status[5] = rtems_task_restart( Task_id[TASKID_CWF1],1 );
617 616 if (status[5] != RTEMS_SUCCESSFUL)
618 617 {
619 618 PRINTF1("in restart_science_task *** CWF1 ERR %d\n", status[5])
620 619 }
621 620
622 621 status[6] = rtems_task_restart( Task_id[TASKID_AVF1], lfrRequestedMode );
623 622 if (status[6] != RTEMS_SUCCESSFUL)
624 623 {
625 624 PRINTF1("in restart_science_task *** AVF1 ERR %d\n", status[6])
626 625 }
627 626
628 627 status[7] = rtems_task_restart( Task_id[TASKID_PRC1],lfrRequestedMode );
629 628 if (status[7] != RTEMS_SUCCESSFUL)
630 629 {
631 630 PRINTF1("in restart_science_task *** PRC1 ERR %d\n", status[7])
632 631 }
633 632
634 633 status[8] = rtems_task_restart( Task_id[TASKID_AVF2], 1 );
635 634 if (status[8] != RTEMS_SUCCESSFUL)
636 635 {
637 636 PRINTF1("in restart_science_task *** AVF2 ERR %d\n", status[8])
638 637 }
639 638
640 639 status[9] = rtems_task_restart( Task_id[TASKID_PRC2], 1 );
641 640 if (status[9] != RTEMS_SUCCESSFUL)
642 641 {
643 642 PRINTF1("in restart_science_task *** PRC2 ERR %d\n", status[9])
644 643 }
645 644
646 645 if ( (status[0] != RTEMS_SUCCESSFUL) || (status[1] != RTEMS_SUCCESSFUL) ||
647 646 (status[2] != RTEMS_SUCCESSFUL) || (status[3] != RTEMS_SUCCESSFUL) ||
648 647 (status[4] != RTEMS_SUCCESSFUL) || (status[5] != RTEMS_SUCCESSFUL) ||
649 648 (status[6] != RTEMS_SUCCESSFUL) || (status[7] != RTEMS_SUCCESSFUL) ||
650 649 (status[8] != RTEMS_SUCCESSFUL) || (status[9] != RTEMS_SUCCESSFUL) )
651 650 {
652 651 ret = RTEMS_UNSATISFIED;
653 652 }
654 653
655 654 return ret;
656 655 }
657 656
658 657 int suspend_science_tasks()
659 658 {
660 659 /** This function suspends the science tasks.
661 660 *
662 661 * @return RTEMS directive status codes:
663 662 * - RTEMS_SUCCESSFUL - task restarted successfully
664 663 * - RTEMS_INVALID_ID - task id invalid
665 664 * - RTEMS_ALREADY_SUSPENDED - task already suspended
666 665 *
667 666 */
668 667
669 668 rtems_status_code status;
670 669
671 670 status = rtems_task_suspend( Task_id[TASKID_AVF0] ); // suspend AVF0
672 671 if (status != RTEMS_SUCCESSFUL)
673 672 {
674 673 PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status)
675 674 }
676 675 if (status == RTEMS_SUCCESSFUL) // suspend PRC0
677 676 {
678 677 status = rtems_task_suspend( Task_id[TASKID_PRC0] );
679 678 if (status != RTEMS_SUCCESSFUL)
680 679 {
681 680 PRINTF1("in suspend_science_task *** PRC0 ERR %d\n", status)
682 681 }
683 682 }
684 683 if (status == RTEMS_SUCCESSFUL) // suspend AVF1
685 684 {
686 685 status = rtems_task_suspend( Task_id[TASKID_AVF1] );
687 686 if (status != RTEMS_SUCCESSFUL)
688 687 {
689 688 PRINTF1("in suspend_science_task *** AVF1 ERR %d\n", status)
690 689 }
691 690 }
692 691 if (status == RTEMS_SUCCESSFUL) // suspend PRC1
693 692 {
694 693 status = rtems_task_suspend( Task_id[TASKID_PRC1] );
695 694 if (status != RTEMS_SUCCESSFUL)
696 695 {
697 696 PRINTF1("in suspend_science_task *** PRC1 ERR %d\n", status)
698 697 }
699 698 }
700 699 if (status == RTEMS_SUCCESSFUL) // suspend AVF2
701 700 {
702 701 status = rtems_task_suspend( Task_id[TASKID_AVF2] );
703 702 if (status != RTEMS_SUCCESSFUL)
704 703 {
705 704 PRINTF1("in suspend_science_task *** AVF2 ERR %d\n", status)
706 705 }
707 706 }
708 707 if (status == RTEMS_SUCCESSFUL) // suspend PRC2
709 708 {
710 709 status = rtems_task_suspend( Task_id[TASKID_PRC2] );
711 710 if (status != RTEMS_SUCCESSFUL)
712 711 {
713 712 PRINTF1("in suspend_science_task *** PRC2 ERR %d\n", status)
714 713 }
715 714 }
716 715 if (status == RTEMS_SUCCESSFUL) // suspend WFRM
717 716 {
718 717 status = rtems_task_suspend( Task_id[TASKID_WFRM] );
719 718 if (status != RTEMS_SUCCESSFUL)
720 719 {
721 720 PRINTF1("in suspend_science_task *** WFRM ERR %d\n", status)
722 721 }
723 722 }
724 723 if (status == RTEMS_SUCCESSFUL) // suspend CWF3
725 724 {
726 725 status = rtems_task_suspend( Task_id[TASKID_CWF3] );
727 726 if (status != RTEMS_SUCCESSFUL)
728 727 {
729 728 PRINTF1("in suspend_science_task *** CWF3 ERR %d\n", status)
730 729 }
731 730 }
732 731 if (status == RTEMS_SUCCESSFUL) // suspend CWF2
733 732 {
734 733 status = rtems_task_suspend( Task_id[TASKID_CWF2] );
735 734 if (status != RTEMS_SUCCESSFUL)
736 735 {
737 736 PRINTF1("in suspend_science_task *** CWF2 ERR %d\n", status)
738 737 }
739 738 }
740 739 if (status == RTEMS_SUCCESSFUL) // suspend CWF1
741 740 {
742 741 status = rtems_task_suspend( Task_id[TASKID_CWF1] );
743 742 if (status != RTEMS_SUCCESSFUL)
744 743 {
745 744 PRINTF1("in suspend_science_task *** CWF1 ERR %d\n", status)
746 745 }
747 746 }
748 747
749 748 return status;
750 749 }
751 750
752 751 void launch_waveform_picker( unsigned char mode, unsigned int transitionCoarseTime )
753 752 {
754 753 WFP_reset_current_ring_nodes();
755 754
756 755 reset_waveform_picker_regs();
757 756
758 757 set_wfp_burst_enable_register( mode );
759 758
760 759 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER );
761 760 LEON_Unmask_interrupt( IRQ_WAVEFORM_PICKER );
762 761
763 762 if (transitionCoarseTime == 0)
764 763 {
765 764 waveform_picker_regs->start_date = time_management_regs->coarse_time;
766 765 }
767 766 else
768 767 {
769 768 waveform_picker_regs->start_date = transitionCoarseTime;
770 769 }
771 770
772 771 PRINTF1("commutation coarse time = %x\n", transitionCoarseTime)
773 772 }
774 773
775 774 void launch_spectral_matrix( void )
776 775 {
777 776 SM_reset_current_ring_nodes();
778 777
779 778 reset_spectral_matrix_regs();
780 779
781 780 reset_nb_sm();
782 781
783 782 set_sm_irq_onNewMatrix( 1 );
784 783
785 784 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX );
786 785 LEON_Unmask_interrupt( IRQ_SPECTRAL_MATRIX );
787 786
788 787 }
789 788
790 789 void launch_spectral_matrix_simu( void )
791 790 {
792 791 SM_reset_current_ring_nodes();
793 792 reset_spectral_matrix_regs();
794 793 reset_nb_sm();
795 794
796 795 // Spectral Matrices simulator
797 796 timer_start( (gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_SM_SIMULATOR );
798 797 LEON_Clear_interrupt( IRQ_SM_SIMULATOR );
799 798 LEON_Unmask_interrupt( IRQ_SM_SIMULATOR );
800 799 }
801 800
802 801 void set_sm_irq_onNewMatrix( unsigned char value )
803 802 {
804 803 if (value == 1)
805 804 {
806 805 spectral_matrix_regs->config = spectral_matrix_regs->config | 0x01;
807 806 }
808 807 else
809 808 {
810 809 spectral_matrix_regs->config = spectral_matrix_regs->config & 0xfffffffe; // 1110
811 810 }
812 811 }
813 812
814 813 void set_sm_irq_onError( unsigned char value )
815 814 {
816 815 if (value == 1)
817 816 {
818 817 spectral_matrix_regs->config = spectral_matrix_regs->config | 0x02;
819 818 }
820 819 else
821 820 {
822 821 spectral_matrix_regs->config = spectral_matrix_regs->config & 0xfffffffd; // 1101
823 822 }
824 823 }
825 824
825 //*****************************
826 // CONFIGURE CALIBRATION SIGNAL
827 void setCalibrationPrescaler( unsigned int prescaler )
828 {
829 // prescaling of the master clock (25 MHz)
830 // master clock is divided by 2^prescaler
831 time_management_regs->calPrescaler = prescaler;
832 }
833
834 void setCalibrationDivisor( unsigned int divisionFactor )
835 {
836 // division of the prescaled clock by the division factor
837 time_management_regs->calDivisor = divisionFactor;
838 }
839
840 void setCalibrationData( void ){
841 unsigned int k;
842 unsigned short data;
843 float val;
844 float f0;
845 float f1;
846 float fs;
847 float Ts;
848 float scaleFactor;
849
850 f0 = 625;
851 f1 = 10000;
852 fs = 160256.410;
853 Ts = 1. / fs;
854 scaleFactor = 0.125 / 0.000654; // 191, 500 mVpp, 2 sinus waves => 250 mVpp each, amplitude = 125 mV
855
856 time_management_regs->calDataPtr = 0x00;
857
858 // build the signal for the SCM calibration
859 for (k=0; k<256; k++)
860 {
861 val = sin( 2 * pi * f0 * k * Ts )
862 + sin( 2 * pi * f1 * k * Ts );
863 data = (unsigned short) ((val * scaleFactor) + 2048);
864 time_management_regs->calData = data & 0xfff;
865 }
866 }
867
868 void setCalibrationDataInterleaved( void ){
869 unsigned int k;
870 float val;
871 float f0;
872 float f1;
873 float fs;
874 float Ts;
875 unsigned short data[384];
876 unsigned char *dataPtr;
877
878 f0 = 625;
879 f1 = 10000;
880 fs = 240384.615;
881 Ts = 1. / fs;
882
883 time_management_regs->calDataPtr = 0x00;
884
885 // build the signal for the SCM calibration
886 for (k=0; k<384; k++)
887 {
888 val = sin( 2 * pi * f0 * k * Ts )
889 + sin( 2 * pi * f1 * k * Ts );
890 data[k] = (unsigned short) (val * 512 + 2048);
891 }
892
893 // write the signal in interleaved mode
894 for (k=0; k<128; k++)
895 {
896 dataPtr = (unsigned char*) &data[k*3 + 2];
897 time_management_regs->calData = (data[k*3] & 0xfff)
898 + ( (dataPtr[0] & 0x3f) << 12);
899 time_management_regs->calData = (data[k*3 + 1] & 0xfff)
900 + ( (dataPtr[1] & 0x3f) << 12);
901 }
902 }
903
904 void setCalibrationReload( bool state)
905 {
906 if (state == true)
907 {
908 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | 0x00000010; // [0001 0000]
909 }
910 else
911 {
912 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & 0xffffffef; // [1110 1111]
913 }
914 }
915
916 void setCalibrationEnable( bool state )
917 {
918 // this bit drives the multiplexer
919 if (state == true)
920 {
921 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | 0x00000040; // [0100 0000]
922 }
923 else
924 {
925 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & 0xffffffbf; // [1011 1111]
926 }
927 }
928
929 void setCalibrationInterleaved( bool state )
930 {
931 // this bit drives the multiplexer
932 if (state == true)
933 {
934 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | 0x00000020; // [0010 0000]
935 }
936 else
937 {
938 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & 0xffffffdf; // [1101 1111]
939 }
940 }
941
942 void startCalibration( void )
943 {
944 setCalibrationEnable( true );
945 setCalibrationReload( false );
946 }
947
948 void stopCalibration( void )
949 {
950 setCalibrationEnable( false );
951 setCalibrationReload( true );
952 }
953
954 void configureCalibration( bool interleaved )
955 {
956 stopCalibration();
957 if ( interleaved == true )
958 {
959 setCalibrationInterleaved( true );
960 setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000
961 setCalibrationDivisor( 26 ); // => 240 384
962 setCalibrationDataInterleaved();
963 }
964 else
965 {
966 setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000
967 setCalibrationDivisor( 38 ); // => 160 256 (39 - 1)
968 setCalibrationData();
969 }
970 }
971
826 972 //****************
827 973 // CLOSING ACTIONS
828 974 void update_last_TC_exe( ccsdsTelecommandPacket_t *TC, unsigned char * time )
829 975 {
830 976 /** This function is used to update the HK packets statistics after a successful TC execution.
831 977 *
832 978 * @param TC points to the TC being processed
833 979 * @param time is the time used to date the TC execution
834 980 *
835 981 */
836 982
837 983 unsigned int val;
838 984
839 985 housekeeping_packet.hk_lfr_last_exe_tc_id[0] = TC->packetID[0];
840 986 housekeeping_packet.hk_lfr_last_exe_tc_id[1] = TC->packetID[1];
841 987 housekeeping_packet.hk_lfr_last_exe_tc_type[0] = 0x00;
842 988 housekeeping_packet.hk_lfr_last_exe_tc_type[1] = TC->serviceType;
843 989 housekeeping_packet.hk_lfr_last_exe_tc_subtype[0] = 0x00;
844 990 housekeeping_packet.hk_lfr_last_exe_tc_subtype[1] = TC->serviceSubType;
845 991 housekeeping_packet.hk_lfr_last_exe_tc_time[0] = time[0];
846 992 housekeeping_packet.hk_lfr_last_exe_tc_time[1] = time[1];
847 993 housekeeping_packet.hk_lfr_last_exe_tc_time[2] = time[2];
848 994 housekeeping_packet.hk_lfr_last_exe_tc_time[3] = time[3];
849 995 housekeeping_packet.hk_lfr_last_exe_tc_time[4] = time[4];
850 996 housekeeping_packet.hk_lfr_last_exe_tc_time[5] = time[5];
851 997
852 998 val = housekeeping_packet.hk_lfr_exe_tc_cnt[0] * 256 + housekeeping_packet.hk_lfr_exe_tc_cnt[1];
853 999 val++;
854 1000 housekeeping_packet.hk_lfr_exe_tc_cnt[0] = (unsigned char) (val >> 8);
855 1001 housekeeping_packet.hk_lfr_exe_tc_cnt[1] = (unsigned char) (val);
856 1002 }
857 1003
858 1004 void update_last_TC_rej(ccsdsTelecommandPacket_t *TC, unsigned char * time )
859 1005 {
860 1006 /** This function is used to update the HK packets statistics after a TC rejection.
861 1007 *
862 1008 * @param TC points to the TC being processed
863 1009 * @param time is the time used to date the TC rejection
864 1010 *
865 1011 */
866 1012
867 1013 unsigned int val;
868 1014
869 1015 housekeeping_packet.hk_lfr_last_rej_tc_id[0] = TC->packetID[0];
870 1016 housekeeping_packet.hk_lfr_last_rej_tc_id[1] = TC->packetID[1];
871 1017 housekeeping_packet.hk_lfr_last_rej_tc_type[0] = 0x00;
872 1018 housekeeping_packet.hk_lfr_last_rej_tc_type[1] = TC->serviceType;
873 1019 housekeeping_packet.hk_lfr_last_rej_tc_subtype[0] = 0x00;
874 1020 housekeeping_packet.hk_lfr_last_rej_tc_subtype[1] = TC->serviceSubType;
875 1021 housekeeping_packet.hk_lfr_last_rej_tc_time[0] = time[0];
876 1022 housekeeping_packet.hk_lfr_last_rej_tc_time[1] = time[1];
877 1023 housekeeping_packet.hk_lfr_last_rej_tc_time[2] = time[2];
878 1024 housekeeping_packet.hk_lfr_last_rej_tc_time[3] = time[3];
879 1025 housekeeping_packet.hk_lfr_last_rej_tc_time[4] = time[4];
880 1026 housekeeping_packet.hk_lfr_last_rej_tc_time[5] = time[5];
881 1027
882 1028 val = housekeeping_packet.hk_lfr_rej_tc_cnt[0] * 256 + housekeeping_packet.hk_lfr_rej_tc_cnt[1];
883 1029 val++;
884 1030 housekeeping_packet.hk_lfr_rej_tc_cnt[0] = (unsigned char) (val >> 8);
885 1031 housekeeping_packet.hk_lfr_rej_tc_cnt[1] = (unsigned char) (val);
886 1032 }
887 1033
888 1034 void close_action(ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id )
889 1035 {
890 1036 /** This function is the last step of the TC execution workflow.
891 1037 *
892 1038 * @param TC points to the TC being processed
893 1039 * @param result is the result of the TC execution (LFR_SUCCESSFUL / LFR_DEFAULT)
894 1040 * @param queue_id is the id of the RTEMS message queue used to send TM packets
895 1041 * @param time is the time used to date the TC execution
896 1042 *
897 1043 */
898 1044
899 1045 unsigned char requestedMode;
900 1046
901 1047 if (result == LFR_SUCCESSFUL)
902 1048 {
903 1049 if ( !( (TC->serviceType==TC_TYPE_TIME) & (TC->serviceSubType==TC_SUBTYPE_UPDT_TIME) )
904 1050 &
905 1051 !( (TC->serviceType==TC_TYPE_GEN) & (TC->serviceSubType==TC_SUBTYPE_UPDT_INFO))
906 1052 )
907 1053 {
908 1054 send_tm_lfr_tc_exe_success( TC, queue_id );
909 1055 }
910 1056 if ( (TC->serviceType == TC_TYPE_GEN) & (TC->serviceSubType == TC_SUBTYPE_ENTER) )
911 1057 {
912 1058 //**********************************
913 1059 // UPDATE THE LFRMODE LOCAL VARIABLE
914 1060 requestedMode = TC->dataAndCRC[1];
915 1061 housekeeping_packet.lfr_status_word[0] = (unsigned char) ((requestedMode << 4) + 0x0d);
916 1062 updateLFRCurrentMode();
917 1063 }
918 1064 }
919 1065 else if (result == LFR_EXE_ERROR)
920 1066 {
921 1067 send_tm_lfr_tc_exe_error( TC, queue_id );
922 1068 }
923 1069 }
924 1070
925 1071 //***************************
926 1072 // Interrupt Service Routines
927 1073 rtems_isr commutation_isr1( rtems_vector_number vector )
928 1074 {
929 1075 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
930 1076 printf("In commutation_isr1 *** Error sending event to DUMB\n");
931 1077 }
932 1078 }
933 1079
934 1080 rtems_isr commutation_isr2( rtems_vector_number vector )
935 1081 {
936 1082 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
937 1083 printf("In commutation_isr2 *** Error sending event to DUMB\n");
938 1084 }
939 1085 }
940 1086
941 1087 //****************
942 1088 // OTHER FUNCTIONS
943 1089 void updateLFRCurrentMode()
944 1090 {
945 1091 /** This function updates the value of the global variable lfrCurrentMode.
946 1092 *
947 1093 * lfrCurrentMode is a parameter used by several functions to know in which mode LFR is running.
948 1094 *
949 1095 */
950 1096 // update the local value of lfrCurrentMode with the value contained in the housekeeping_packet structure
951 1097 lfrCurrentMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4;
952 1098 }
953 1099
954 1100 void set_lfr_soft_reset( unsigned char value )
955 1101 {
956 1102 if (value == 1)
957 1103 {
958 1104 time_management_regs->ctrl = time_management_regs->ctrl | 0x00000004; // [0100]
959 1105 }
960 1106 else
961 1107 {
962 1108 time_management_regs->ctrl = time_management_regs->ctrl & 0xfffffffb; // [1011]
963 1109 }
964 1110 }
965 1111
966 1112 void reset_lfr( void )
967 1113 {
968 1114 set_lfr_soft_reset( 1 );
969 1115
970 1116 set_lfr_soft_reset( 0 );
971 1117 }
General Comments 0
You need to be logged in to leave comments. Login now