##// END OF EJS Templates
Many corrections, mainly related to 807 Don_Enumeration
paul -
r318:d3701d39af11 R3_plus draft
parent child
Show More
@@ -1,2 +1,2
1 3081d1f9bb20b2b64a192585337a292a9804e0c5 LFR_basic-parameters
1 3081d1f9bb20b2b64a192585337a292a9804e0c5 LFR_basic-parameters
2 3e4216a0e6981bead8bcb201012ebadb53f60dff header/lfr_common_headers
2 6bab694410c69700e3455ffba21ce58dbb4da870 header/lfr_common_headers
@@ -1,109 +1,131
1 #ifndef FSW_MISC_H_INCLUDED
1 #ifndef FSW_MISC_H_INCLUDED
2 #define FSW_MISC_H_INCLUDED
2 #define FSW_MISC_H_INCLUDED
3
3
4 #include <rtems.h>
4 #include <rtems.h>
5 #include <stdio.h>
5 #include <stdio.h>
6 #include <grspw.h>
6 #include <grspw.h>
7 #include <grlib_regs.h>
7 #include <grlib_regs.h>
8
8
9 #include "fsw_params.h"
9 #include "fsw_params.h"
10 #include "fsw_spacewire.h"
10 #include "fsw_spacewire.h"
11 #include "lfr_cpu_usage_report.h"
11 #include "lfr_cpu_usage_report.h"
12
12
13 #define LFR_RESET_CAUSE_UNKNOWN_CAUSE 0
14 #define WATCHDOG_LOOP_PRINTF 10
15 #define WATCHDOG_LOOP_DEBUG 3
16
17 #define DUMB_MESSAGE_NB 15
18 #define NB_RTEMS_EVENTS 32
19 #define EVENT_12 12
20 #define EVENT_13 13
21 #define EVENT_14 14
22 #define DUMB_MESSAGE_0 "in DUMB *** default"
23 #define DUMB_MESSAGE_1 "in DUMB *** timecode_irq_handler"
24 #define DUMB_MESSAGE_2 "in DUMB *** f3 buffer changed"
25 #define DUMB_MESSAGE_3 "in DUMB *** in SMIQ *** Error sending event to AVF0"
26 #define DUMB_MESSAGE_4 "in DUMB *** spectral_matrices_isr *** Error sending event to SMIQ"
27 #define DUMB_MESSAGE_5 "in DUMB *** waveforms_simulator_isr"
28 #define DUMB_MESSAGE_6 "VHDL SM *** two buffers f0 ready"
29 #define DUMB_MESSAGE_7 "ready for dump"
30 #define DUMB_MESSAGE_8 "VHDL ERR *** spectral matrix"
31 #define DUMB_MESSAGE_9 "tick"
32 #define DUMB_MESSAGE_10 "VHDL ERR *** waveform picker"
33 #define DUMB_MESSAGE_11 "VHDL ERR *** unexpected ready matrix values"
34 #define DUMB_MESSAGE_12 "WATCHDOG timer"
35 #define DUMB_MESSAGE_13 "TIMECODE timer"
36 #define DUMB_MESSAGE_14 "TIMECODE ISR"
13
37
14 enum lfr_reset_cause_t{
38 enum lfr_reset_cause_t{
15 UNKNOWN_CAUSE,
39 UNKNOWN_CAUSE,
16 POWER_ON,
40 POWER_ON,
17 TC_RESET,
41 TC_RESET,
18 WATCHDOG,
42 WATCHDOG,
19 ERROR_RESET,
43 ERROR_RESET,
20 UNEXP_RESET
44 UNEXP_RESET
21 };
45 };
22
46
23 typedef struct{
47 typedef struct{
24 unsigned char dpu_spw_parity;
48 unsigned char dpu_spw_parity;
25 unsigned char dpu_spw_disconnect;
49 unsigned char dpu_spw_disconnect;
26 unsigned char dpu_spw_escape;
50 unsigned char dpu_spw_escape;
27 unsigned char dpu_spw_credit;
51 unsigned char dpu_spw_credit;
28 unsigned char dpu_spw_write_sync;
52 unsigned char dpu_spw_write_sync;
29 unsigned char timecode_erroneous;
53 unsigned char timecode_erroneous;
30 unsigned char timecode_missing;
54 unsigned char timecode_missing;
31 unsigned char timecode_invalid;
55 unsigned char timecode_invalid;
32 unsigned char time_timecode_it;
56 unsigned char time_timecode_it;
33 unsigned char time_not_synchro;
57 unsigned char time_not_synchro;
34 unsigned char time_timecode_ctr;
58 unsigned char time_timecode_ctr;
35 unsigned char ahb_correctable;
59 unsigned char ahb_correctable;
36 } hk_lfr_le_t;
60 } hk_lfr_le_t;
37
61
38 typedef struct{
62 typedef struct{
39 unsigned char dpu_spw_early_eop;
63 unsigned char dpu_spw_early_eop;
40 unsigned char dpu_spw_invalid_addr;
64 unsigned char dpu_spw_invalid_addr;
41 unsigned char dpu_spw_eep;
65 unsigned char dpu_spw_eep;
42 unsigned char dpu_spw_rx_too_big;
66 unsigned char dpu_spw_rx_too_big;
43 } hk_lfr_me_t;
67 } hk_lfr_me_t;
44
68
45 extern gptimer_regs_t *gptimer_regs;
69 extern gptimer_regs_t *gptimer_regs;
46 extern void ASR16_get_FPRF_IURF_ErrorCounters( unsigned int*, unsigned int* );
70 extern void ASR16_get_FPRF_IURF_ErrorCounters( unsigned int*, unsigned int* );
47 extern void CCR_getInstructionAndDataErrorCounters( unsigned int*, unsigned int* );
71 extern void CCR_getInstructionAndDataErrorCounters( unsigned int*, unsigned int* );
48
72
49 #define LFR_RESET_CAUSE_UNKNOWN_CAUSE 0
50
51 rtems_name name_hk_rate_monotonic; // name of the HK rate monotonic
73 rtems_name name_hk_rate_monotonic; // name of the HK rate monotonic
52 rtems_id HK_id; // id of the HK rate monotonic period
74 rtems_id HK_id; // id of the HK rate monotonic period
53 rtems_name name_avgv_rate_monotonic; // name of the AVGV rate monotonic
75 rtems_name name_avgv_rate_monotonic; // name of the AVGV rate monotonic
54 rtems_id AVGV_id; // id of the AVGV rate monotonic period
76 rtems_id AVGV_id; // id of the AVGV rate monotonic period
55
77
56 void timer_configure( unsigned char timer, unsigned int clock_divider,
78 void timer_configure( unsigned char timer, unsigned int clock_divider,
57 unsigned char interrupt_level, rtems_isr (*timer_isr)() );
79 unsigned char interrupt_level, rtems_isr (*timer_isr)() );
58 void timer_start( unsigned char timer );
80 void timer_start( unsigned char timer );
59 void timer_stop( unsigned char timer );
81 void timer_stop( unsigned char timer );
60 void timer_set_clock_divider(unsigned char timer, unsigned int clock_divider);
82 void timer_set_clock_divider(unsigned char timer, unsigned int clock_divider);
61
83
62 // WATCHDOG
84 // WATCHDOG
63 rtems_isr watchdog_isr( rtems_vector_number vector );
85 rtems_isr watchdog_isr( rtems_vector_number vector );
64 void watchdog_configure(void);
86 void watchdog_configure(void);
65 void watchdog_stop(void);
87 void watchdog_stop(void);
66 void watchdog_reload(void);
88 void watchdog_reload(void);
67 void watchdog_start(void);
89 void watchdog_start(void);
68
90
69 // SERIAL LINK
91 // SERIAL LINK
70 int send_console_outputs_on_apbuart_port( void );
92 int send_console_outputs_on_apbuart_port( void );
71 int enable_apbuart_transmitter( void );
93 int enable_apbuart_transmitter( void );
72 void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value);
94 void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value);
73
95
74 // RTEMS TASKS
96 // RTEMS TASKS
75 rtems_task load_task( rtems_task_argument argument );
97 rtems_task load_task( rtems_task_argument argument );
76 rtems_task hous_task( rtems_task_argument argument );
98 rtems_task hous_task( rtems_task_argument argument );
77 rtems_task avgv_task( rtems_task_argument argument );
99 rtems_task avgv_task( rtems_task_argument argument );
78 rtems_task dumb_task( rtems_task_argument unused );
100 rtems_task dumb_task( rtems_task_argument unused );
79
101
80 void init_housekeeping_parameters( void );
102 void init_housekeeping_parameters( void );
81 void increment_seq_counter(unsigned short *packetSequenceControl);
103 void increment_seq_counter(unsigned short *packetSequenceControl);
82 void getTime( unsigned char *time);
104 void getTime( unsigned char *time);
83 unsigned long long int getTimeAsUnsignedLongLongInt( );
105 unsigned long long int getTimeAsUnsignedLongLongInt( );
84 void send_dumb_hk( void );
106 void send_dumb_hk( void );
85 void get_temperatures( unsigned char *temperatures );
107 void get_temperatures( unsigned char *temperatures );
86 void get_v_e1_e2_f3( unsigned char *spacecraft_potential );
108 void get_v_e1_e2_f3( unsigned char *spacecraft_potential );
87 void get_cpu_load( unsigned char *resource_statistics );
109 void get_cpu_load( unsigned char *resource_statistics );
88 void set_hk_lfr_sc_potential_flag( bool state );
110 void set_hk_lfr_sc_potential_flag( bool state );
89 void set_sy_lfr_pas_filter_enabled( bool state );
111 void set_sy_lfr_pas_filter_enabled( bool state );
90 void set_sy_lfr_watchdog_enabled( bool state );
112 void set_sy_lfr_watchdog_enabled( bool state );
91 void set_hk_lfr_calib_enable( bool state );
113 void set_hk_lfr_calib_enable( bool state );
92 void set_hk_lfr_reset_cause( enum lfr_reset_cause_t lfr_reset_cause );
114 void set_hk_lfr_reset_cause( enum lfr_reset_cause_t lfr_reset_cause );
93 void hk_lfr_le_me_he_update();
115 void hk_lfr_le_me_he_update();
94 void set_hk_lfr_time_not_synchro();
116 void set_hk_lfr_time_not_synchro();
95
117
96 extern int sched_yield( void );
118 extern int sched_yield( void );
97 extern void rtems_cpu_usage_reset();
119 extern void rtems_cpu_usage_reset();
98 extern ring_node *current_ring_node_f3;
120 extern ring_node *current_ring_node_f3;
99 extern ring_node *ring_node_to_send_cwf_f3;
121 extern ring_node *ring_node_to_send_cwf_f3;
100 extern ring_node waveform_ring_f3[];
122 extern ring_node waveform_ring_f3[];
101 extern unsigned short sequenceCounterHK;
123 extern unsigned short sequenceCounterHK;
102
124
103 extern unsigned char hk_lfr_q_sd_fifo_size_max;
125 extern unsigned char hk_lfr_q_sd_fifo_size_max;
104 extern unsigned char hk_lfr_q_rv_fifo_size_max;
126 extern unsigned char hk_lfr_q_rv_fifo_size_max;
105 extern unsigned char hk_lfr_q_p0_fifo_size_max;
127 extern unsigned char hk_lfr_q_p0_fifo_size_max;
106 extern unsigned char hk_lfr_q_p1_fifo_size_max;
128 extern unsigned char hk_lfr_q_p1_fifo_size_max;
107 extern unsigned char hk_lfr_q_p2_fifo_size_max;
129 extern unsigned char hk_lfr_q_p2_fifo_size_max;
108
130
109 #endif // FSW_MISC_H_INCLUDED
131 #endif // FSW_MISC_H_INCLUDED
@@ -1,59 +1,68
1 #ifndef FSW_SPACEWIRE_H_INCLUDED
1 #ifndef FSW_SPACEWIRE_H_INCLUDED
2 #define FSW_SPACEWIRE_H_INCLUDED
2 #define FSW_SPACEWIRE_H_INCLUDED
3
3
4 #include <rtems.h>
4 #include <rtems.h>
5 #include <grspw.h>
5 #include <grspw.h>
6
6
7 #include <fcntl.h> // for O_RDWR
7 #include <fcntl.h> // for O_RDWR
8 #include <unistd.h> // for the read call
8 #include <unistd.h> // for the read call
9 #include <sys/ioctl.h> // for the ioctl call
9 #include <sys/ioctl.h> // for the ioctl call
10 #include <errno.h>
10 #include <errno.h>
11
11
12 #include "fsw_params.h"
12 #include "fsw_params.h"
13 #include "tc_handler.h"
13 #include "tc_handler.h"
14 #include "fsw_init.h"
14 #include "fsw_init.h"
15
15
16 #define SPW_LINK_OK 5
17 #define CONF_TCODE_CTRL 0x0909 // [Time Rx : Time Tx : Link error : Tick-out IRQ]
18 #define SPW_BIT_NP 0x00100000 // [NP] set the No port force bit
19 #define SPW_BIT_NP_MASK 0xffdfffff
20 #define SPW_BIT_RE 0x00010000 // [RE] set the RMAP Enable bit
21 #define SPW_BIT_RE_MASK 0xfffdffff
22 #define SPW_LINK_STAT_POS 21
23 #define SPW_TIMECODE_MAX 63
24
16 extern spw_stats grspw_stats;
25 extern spw_stats grspw_stats;
17 extern rtems_name timecode_timer_name;
26 extern rtems_name timecode_timer_name;
18 extern rtems_id timecode_timer_id;
27 extern rtems_id timecode_timer_id;
19 extern unsigned char oneTcLfrUpdateTimeReceived;
28 extern unsigned char oneTcLfrUpdateTimeReceived;
20
29
21 // RTEMS TASK
30 // RTEMS TASK
22 rtems_task spiq_task( rtems_task_argument argument );
31 rtems_task spiq_task( rtems_task_argument argument );
23 rtems_task recv_task( rtems_task_argument unused );
32 rtems_task recv_task( rtems_task_argument unused );
24 rtems_task send_task( rtems_task_argument argument );
33 rtems_task send_task( rtems_task_argument argument );
25 rtems_task link_task( rtems_task_argument argument );
34 rtems_task link_task( rtems_task_argument argument );
26
35
27 int spacewire_open_link( void );
36 int spacewire_open_link( void );
28 int spacewire_start_link( int fd );
37 int spacewire_start_link( int fd );
29 int spacewire_stop_and_start_link( int fd );
38 int spacewire_stop_and_start_link( int fd );
30 int spacewire_configure_link(int fd );
39 int spacewire_configure_link(int fd );
31 int spacewire_several_connect_attemps( void );
40 int spacewire_several_connect_attemps( void );
32 void spacewire_set_NP( unsigned char val, unsigned int regAddr ); // No Port force
41 void spacewire_set_NP( unsigned char val, unsigned int regAddr ); // No Port force
33 void spacewire_set_RE( unsigned char val, unsigned int regAddr ); // RMAP Enable
42 void spacewire_set_RE( unsigned char val, unsigned int regAddr ); // RMAP Enable
34 void spacewire_read_statistics( void );
43 void spacewire_read_statistics( void );
35 void spacewire_get_last_error( void );
44 void spacewire_get_last_error( void );
36 void update_hk_lfr_last_er_fields(unsigned int rid, unsigned char code);
45 void update_hk_lfr_last_er_fields(unsigned int rid, unsigned char code);
37 void update_hk_with_grspw_stats(void );
46 void update_hk_with_grspw_stats(void );
38 void spacewire_update_hk_lfr_link_state( unsigned char *hk_lfr_status_word_0 );
47 void spacewire_update_hk_lfr_link_state( unsigned char *hk_lfr_status_word_0 );
39 void increase_unsigned_char_counter( unsigned char *counter );
48 void increase_unsigned_char_counter( unsigned char *counter );
40
49
41 void init_header_cwf( Header_TM_LFR_SCIENCE_CWF_t *header );
50 void init_header_cwf( Header_TM_LFR_SCIENCE_CWF_t *header );
42 void init_header_swf( Header_TM_LFR_SCIENCE_SWF_t *header );
51 void init_header_swf( Header_TM_LFR_SCIENCE_SWF_t *header );
43 void init_header_asm( Header_TM_LFR_SCIENCE_ASM_t *header );
52 void init_header_asm( Header_TM_LFR_SCIENCE_ASM_t *header );
44 int spw_send_waveform_CWF( ring_node *ring_node_to_send, Header_TM_LFR_SCIENCE_CWF_t *header );
53 int spw_send_waveform_CWF( ring_node *ring_node_to_send, Header_TM_LFR_SCIENCE_CWF_t *header );
45 int spw_send_waveform_SWF( ring_node *ring_node_to_send, Header_TM_LFR_SCIENCE_SWF_t *header );
54 int spw_send_waveform_SWF( ring_node *ring_node_to_send, Header_TM_LFR_SCIENCE_SWF_t *header );
46 int spw_send_waveform_CWF3_light( ring_node *ring_node_to_send, Header_TM_LFR_SCIENCE_CWF_t *header );
55 int spw_send_waveform_CWF3_light( ring_node *ring_node_to_send, Header_TM_LFR_SCIENCE_CWF_t *header );
47 void spw_send_asm_f0( ring_node *ring_node_to_send, Header_TM_LFR_SCIENCE_ASM_t *header );
56 void spw_send_asm_f0( ring_node *ring_node_to_send, Header_TM_LFR_SCIENCE_ASM_t *header );
48 void spw_send_asm_f1( ring_node *ring_node_to_send, Header_TM_LFR_SCIENCE_ASM_t *header );
57 void spw_send_asm_f1( ring_node *ring_node_to_send, Header_TM_LFR_SCIENCE_ASM_t *header );
49 void spw_send_asm_f2( ring_node *ring_node_to_send, Header_TM_LFR_SCIENCE_ASM_t *header );
58 void spw_send_asm_f2( ring_node *ring_node_to_send, Header_TM_LFR_SCIENCE_ASM_t *header );
50 void spw_send_k_dump( ring_node *ring_node_to_send );
59 void spw_send_k_dump( ring_node *ring_node_to_send );
51
60
52 unsigned int check_timecode_and_previous_timecode_coherency(unsigned char currentTimecodeCtr);
61 unsigned int check_timecode_and_previous_timecode_coherency(unsigned char currentTimecodeCtr);
53 unsigned int check_timecode_and_internal_time_coherency(unsigned char timecode, unsigned char internalTime);
62 unsigned int check_timecode_and_internal_time_coherency(unsigned char timecode, unsigned char internalTime);
54 void timecode_irq_handler( void *pDev, void *regs, int minor, unsigned int tc );
63 void timecode_irq_handler( void *pDev, void *regs, int minor, unsigned int tc );
55 rtems_timer_service_routine timecode_timer_routine( rtems_id timer_id, void *user_data );
64 rtems_timer_service_routine timecode_timer_routine( rtems_id timer_id, void *user_data );
56
65
57 void (*grspw_timecode_callback) ( void *pDev, void *regs, int minor, unsigned int tc );
66 void (*grspw_timecode_callback) ( void *pDev, void *regs, int minor, unsigned int tc );
58
67
59 #endif // FSW_SPACEWIRE_H_INCLUDED
68 #endif // FSW_SPACEWIRE_H_INCLUDED
@@ -1,138 +1,231
1 #ifndef GRLIB_REGS_H_INCLUDED
1 #ifndef GRLIB_REGS_H_INCLUDED
2 #define GRLIB_REGS_H_INCLUDED
2 #define GRLIB_REGS_H_INCLUDED
3
3
4 #define NB_GPTIMER 3
4 #define NB_GPTIMER 3
5
5
6 struct apbuart_regs_str{
6 struct apbuart_regs_str{
7 volatile unsigned int data;
7 volatile unsigned int data;
8 volatile unsigned int status;
8 volatile unsigned int status;
9 volatile unsigned int ctrl;
9 volatile unsigned int ctrl;
10 volatile unsigned int scaler;
10 volatile unsigned int scaler;
11 volatile unsigned int fifoDebug;
11 volatile unsigned int fifoDebug;
12 };
12 };
13
13
14 struct grgpio_regs_str{
14 struct grgpio_regs_str{
15 volatile int io_port_data_register;
15 volatile int io_port_data_register;
16 int io_port_output_register;
16 int io_port_output_register;
17 int io_port_direction_register;
17 int io_port_direction_register;
18 int interrupt_mak_register;
18 int interrupt_mak_register;
19 int interrupt_polarity_register;
19 int interrupt_polarity_register;
20 int interrupt_edge_register;
20 int interrupt_edge_register;
21 int bypass_register;
21 int bypass_register;
22 int reserved;
22 int reserved;
23 // 0x20-0x3c interrupt map register(s)
23 // 0x20-0x3c interrupt map register(s)
24 };
24 };
25
25
26 typedef struct {
26 typedef struct {
27 volatile unsigned int counter;
27 volatile unsigned int counter;
28 volatile unsigned int reload;
28 volatile unsigned int reload;
29 volatile unsigned int ctrl;
29 volatile unsigned int ctrl;
30 volatile unsigned int unused;
30 volatile unsigned int unused;
31 } timer_regs_t;
31 } timer_regs_t;
32
32
33 //*************
34 //*************
35 // GPTIMER_REGS
36
37 #define GPTIMER_CLEAR_IRQ 0x00000010 // clear pending IRQ if any
38 #define GPTIMER_LD 0x00000004 // LD load value from the reload register
39 #define GPTIMER_EN 0x00000001 // EN enable the timer
40 #define GPTIMER_EN_MASK 0xfffffffe // EN enable the timer
41 #define GPTIMER_RS 0x00000002 // RS restart
42 #define GPTIMER_IE 0x00000008 // IE interrupt enable
43 #define GPTIMER_IE_MASK 0xffffffef // IE interrupt enable
44
33 typedef struct {
45 typedef struct {
34 volatile unsigned int scaler_value;
46 volatile unsigned int scaler_value;
35 volatile unsigned int scaler_reload;
47 volatile unsigned int scaler_reload;
36 volatile unsigned int conf;
48 volatile unsigned int conf;
37 volatile unsigned int unused0;
49 volatile unsigned int unused0;
38 timer_regs_t timer[NB_GPTIMER];
50 timer_regs_t timer[NB_GPTIMER];
39 } gptimer_regs_t;
51 } gptimer_regs_t;
40
52
53 //*********************
54 //*********************
55 // TIME_MANAGEMENT_REGS
56
57 #define VAL_SOFTWARE_RESET 0x02 // [0010] software reset
58 #define VAL_LFR_SYNCHRONIZED 0x80000000
59 #define BIT_SYNCHRONIZATION 31
60 #define COARSE_TIME_MASK 0x7fffffff
61 #define SYNC_BIT_MASK 0x7f
62 #define SYNC_BIT 0x80
63 #define BIT_CAL_RELOAD 0x00000010
64 #define MASK_CAL_RELOAD 0xffffffef // [1110 1111]
65 #define BIT_CAL_ENABLE 0x00000040
66 #define MASK_CAL_ENABLE 0xffffffbf // [1011 1111]
67 #define BIT_SET_INTERLEAVED 0x00000020 // [0010 0000]
68 #define MASK_SET_INTERLEAVED 0xffffffdf // [1101 1111]
69 #define BIT_SOFT_RESET 0x00000004 // [0100]
70 #define MASK_SOFT_RESET 0xfffffffb // [1011]
71
41 typedef struct {
72 typedef struct {
42 volatile int ctrl; // bit 0 forces the load of the coarse_time_load value and resets the fine_time
73 volatile int ctrl; // bit 0 forces the load of the coarse_time_load value and resets the fine_time
43 // bit 1 is the soft reset for the time management module
74 // bit 1 is the soft reset for the time management module
44 // bit 2 is the soft reset for the waveform picker and the spectral matrix modules, set to 1 after HW reset
75 // bit 2 is the soft reset for the waveform picker and the spectral matrix modules, set to 1 after HW reset
45 volatile int coarse_time_load;
76 volatile int coarse_time_load;
46 volatile int coarse_time;
77 volatile int coarse_time;
47 volatile int fine_time;
78 volatile int fine_time;
48 // TEMPERATURES
79 // TEMPERATURES
49 volatile int temp_pcb; // SEL1 = 0 SEL0 = 0
80 volatile int temp_pcb; // SEL1 = 0 SEL0 = 0
50 volatile int temp_fpga; // SEL1 = 0 SEL0 = 1
81 volatile int temp_fpga; // SEL1 = 0 SEL0 = 1
51 volatile int temp_scm; // SEL1 = 1 SEL0 = 0
82 volatile int temp_scm; // SEL1 = 1 SEL0 = 0
52 // CALIBRATION
83 // CALIBRATION
53 volatile unsigned int calDACCtrl;
84 volatile unsigned int calDACCtrl;
54 volatile unsigned int calPrescaler;
85 volatile unsigned int calPrescaler;
55 volatile unsigned int calDivisor;
86 volatile unsigned int calDivisor;
56 volatile unsigned int calDataPtr;
87 volatile unsigned int calDataPtr;
57 volatile unsigned int calData;
88 volatile unsigned int calData;
58 } time_management_regs_t;
89 } time_management_regs_t;
59
90
91 //*********************
92 //*********************
93 // WAVEFORM_PICKER_REGS
94
95 #define BITS_WFP_STATUS_F3 0xc0 // [1100 0000] check the f3 full bits
96 #define BIT_WFP_BUF_F3_0 0x40 // [0100 0000] f3 buffer 0 is full
97 #define BIT_WFP_BUF_F3_1 0x80 // [1000 0000] f3 buffer 1 is full
98 #define RST_WFP_F3_0 0x00008840 // [1000 1000 0100 0000]
99 #define RST_WFP_F3_1 0x00008880 // [1000 1000 1000 0000]
100
101 #define BITS_WFP_STATUS_F2 0x30 // [0011 0000] get the status bits for f2
102 #define SHIFT_WFP_STATUS_F2 4
103 #define BIT_WFP_BUF_F2_0 0x10 // [0001 0000] f2 buffer 0 is full
104 #define BIT_WFP_BUF_F2_1 0x20 // [0010 0000] f2 buffer 1 is full
105 #define RST_WFP_F2_0 0x00004410 // [0100 0100 0001 0000]
106 #define RST_WFP_F2_1 0x00004420 // [0100 0100 0010 0000]
107
108 #define BITS_WFP_STATUS_F1 0x0c // [0000 1100] check the f1 full bits
109 #define BIT_WFP_BUF_F1_0 0x04 // [0000 0100] f1 buffer 0 is full
110 #define BIT_WFP_BUF_F1_1 0x08 // [0000 1000] f1 buffer 1 is full
111 #define RST_WFP_F1_0 0x00002204 // [0010 0010 0000 0100] f1 bits = 0
112 #define RST_WFP_F1_1 0x00002208 // [0010 0010 0000 1000] f1 bits = 0
113
114 #define BITS_WFP_STATUS_F0 0x03 // [0000 0011] check the f0 full bits
115 #define RST_WFP_F0_0 0x00001101 // [0001 0001 0000 0001]
116 #define RST_WFP_F0_1 0x00001102 // [0001 0001 0000 0010]
117
118 #define BIT_WFP_BUFFER_0 0x01
119 #define BIT_WFP_BUFFER_1 0x02
120
121 #define RST_BITS_RUN_BURST_EN 0x80 // [1000 0000] burst f2, f1, f0 enable f3, f2, f1, f0
122 #define RUN_BURST_ENABLE_SBM2 0x60 // [0110 0000] enable f2 and f1 burst
123 #define RUN_BURST_ENABLE_BURST 0x40 // [0100 0000] f2 burst enabled
124
125 #define DFLT_WFP_NB_DATA_BY_BUFFER 0xa7f // 0x30 *** 2688 - 1 => nb samples -1
126 #define DFLT_WFP_SNAPSHOT_PARAM 0xa80 // 0x34 *** 2688 => nb samples
127 #define DFLT_WFP_BUFFER_LENGTH 0x1f8 // buffer length in burst = 3 * 2688 / 16 = 504 = 0x1f8
128 #define DFLT_WFP_DELTA_F0_2 0x30 // 48 = 11 0000, max 7 bits
129
60 // PDB >= 0.1.28, 0x80000f54
130 // PDB >= 0.1.28, 0x80000f54
61 typedef struct{
131 typedef struct{
62 int data_shaping; // 0x00 00 *** R2 R1 R0 SP1 SP0 BW
132 int data_shaping; // 0x00 00 *** R2 R1 R0 SP1 SP0 BW
63 int run_burst_enable; // 0x04 01 *** [run *** burst f2, f1, f0 *** enable f3, f2, f1, f0 ]
133 int run_burst_enable; // 0x04 01 *** [run *** burst f2, f1, f0 *** enable f3, f2, f1, f0 ]
64 int addr_data_f0_0; // 0x08
134 int addr_data_f0_0; // 0x08
65 int addr_data_f0_1; // 0x0c
135 int addr_data_f0_1; // 0x0c
66 int addr_data_f1_0; // 0x10
136 int addr_data_f1_0; // 0x10
67 int addr_data_f1_1; // 0x14
137 int addr_data_f1_1; // 0x14
68 int addr_data_f2_0; // 0x18
138 int addr_data_f2_0; // 0x18
69 int addr_data_f2_1; // 0x1c
139 int addr_data_f2_1; // 0x1c
70 int addr_data_f3_0; // 0x20
140 int addr_data_f3_0; // 0x20
71 int addr_data_f3_1; // 0x24
141 int addr_data_f3_1; // 0x24
72 volatile int status; // 0x28
142 volatile int status; // 0x28
73 volatile int delta_snapshot; // 0x2c
143 volatile int delta_snapshot; // 0x2c
74 int delta_f0; // 0x30
144 int delta_f0; // 0x30
75 int delta_f0_2; // 0x34
145 int delta_f0_2; // 0x34
76 int delta_f1; // 0x38
146 int delta_f1; // 0x38
77 int delta_f2; // 0x3c
147 int delta_f2; // 0x3c
78 int nb_data_by_buffer; // 0x40 number of samples in a buffer = 2688
148 int nb_data_by_buffer; // 0x40 number of samples in a buffer = 2688
79 int snapshot_param; // 0x44
149 int snapshot_param; // 0x44
80 int start_date; // 0x48
150 int start_date; // 0x48
81 //
151 //
82 volatile unsigned int f0_0_coarse_time; // 0x4c
152 volatile unsigned int f0_0_coarse_time; // 0x4c
83 volatile unsigned int f0_0_fine_time; // 0x50
153 volatile unsigned int f0_0_fine_time; // 0x50
84 volatile unsigned int f0_1_coarse_time; // 0x54
154 volatile unsigned int f0_1_coarse_time; // 0x54
85 volatile unsigned int f0_1_fine_time; // 0x58
155 volatile unsigned int f0_1_fine_time; // 0x58
86 //
156 //
87 volatile unsigned int f1_0_coarse_time; // 0x5c
157 volatile unsigned int f1_0_coarse_time; // 0x5c
88 volatile unsigned int f1_0_fine_time; // 0x60
158 volatile unsigned int f1_0_fine_time; // 0x60
89 volatile unsigned int f1_1_coarse_time; // 0x64
159 volatile unsigned int f1_1_coarse_time; // 0x64
90 volatile unsigned int f1_1_fine_time; // 0x68
160 volatile unsigned int f1_1_fine_time; // 0x68
91 //
161 //
92 volatile unsigned int f2_0_coarse_time; // 0x6c
162 volatile unsigned int f2_0_coarse_time; // 0x6c
93 volatile unsigned int f2_0_fine_time; // 0x70
163 volatile unsigned int f2_0_fine_time; // 0x70
94 volatile unsigned int f2_1_coarse_time; // 0x74
164 volatile unsigned int f2_1_coarse_time; // 0x74
95 volatile unsigned int f2_1_fine_time; // 0x78
165 volatile unsigned int f2_1_fine_time; // 0x78
96 //
166 //
97 volatile unsigned int f3_0_coarse_time; // 0x7c => 0x7c + 0xf54 = 0xd0
167 volatile unsigned int f3_0_coarse_time; // 0x7c => 0x7c + 0xf54 = 0xd0
98 volatile unsigned int f3_0_fine_time; // 0x80
168 volatile unsigned int f3_0_fine_time; // 0x80
99 volatile unsigned int f3_1_coarse_time; // 0x84
169 volatile unsigned int f3_1_coarse_time; // 0x84
100 volatile unsigned int f3_1_fine_time; // 0x88
170 volatile unsigned int f3_1_fine_time; // 0x88
101 //
171 //
102 unsigned int buffer_length; // 0x8c = buffer length in burst 2688 / 16 = 168
172 unsigned int buffer_length; // 0x8c = buffer length in burst 2688 / 16 = 168
103 //
173 //
104 volatile unsigned int v; // 0x90
174 volatile unsigned int v; // 0x90
105 volatile unsigned int e1; // 0x94
175 volatile unsigned int e1; // 0x94
106 volatile unsigned int e2; // 0x98
176 volatile unsigned int e2; // 0x98
107 } waveform_picker_regs_0_1_18_t;
177 } waveform_picker_regs_0_1_18_t;
108
178
179 //*********************
180 //*********************
181 // SPECTRAL_MATRIX_REGS
182
183 #define BITS_STATUS_F0 0x03 // [0011]
184 #define BITS_STATUS_F1 0x0c // [1100]
185 #define BITS_STATUS_F2 0x30 // [0011 0000]
186 #define BITS_HK_AA_SM 0x780 // [0111 1000 0000]
187 #define BITS_SM_ERR 0x7c0 // [0111 1100 0000]
188 #define BITS_STATUS_REG 0x7ff // [0111 1111 1111]
189 #define BIT_READY_0 0x1 // [01]
190 #define BIT_READY_1 0x2 // [10]
191 #define BIT_READY_0_1 0x3 // [11]
192 #define BIT_STATUS_F1_0 0x04 // [0100]
193 #define BIT_STATUS_F1_1 0x08 // [1000]
194 #define BIT_STATUS_F2_0 0x10 // [0001 0000]
195 #define BIT_STATUS_F2_1 0x20 // [0010 0000]
196 #define DEFAULT_MATRIX_LENGTH 0xc8 // 25 * 128 / 16 = 200 = 0xc8
197 #define BIT_IRQ_ON_NEW_MATRIX 0x01
198 #define MASK_IRQ_ON_NEW_MATRIX 0xfffffffe
199 #define BIT_IRQ_ON_ERROR 0x02
200 #define MASK_IRQ_ON_ERROR 0xfffffffd
201
109 typedef struct {
202 typedef struct {
110 volatile int config; // 0x00
203 volatile int config; // 0x00
111 volatile int status; // 0x04
204 volatile int status; // 0x04
112 volatile int f0_0_address; // 0x08
205 volatile int f0_0_address; // 0x08
113 volatile int f0_1_address; // 0x0C
206 volatile int f0_1_address; // 0x0C
114 //
207 //
115 volatile int f1_0_address; // 0x10
208 volatile int f1_0_address; // 0x10
116 volatile int f1_1_address; // 0x14
209 volatile int f1_1_address; // 0x14
117 volatile int f2_0_address; // 0x18
210 volatile int f2_0_address; // 0x18
118 volatile int f2_1_address; // 0x1C
211 volatile int f2_1_address; // 0x1C
119 //
212 //
120 volatile unsigned int f0_0_coarse_time; // 0x20
213 volatile unsigned int f0_0_coarse_time; // 0x20
121 volatile unsigned int f0_0_fine_time; // 0x24
214 volatile unsigned int f0_0_fine_time; // 0x24
122 volatile unsigned int f0_1_coarse_time; // 0x28
215 volatile unsigned int f0_1_coarse_time; // 0x28
123 volatile unsigned int f0_1_fine_time; // 0x2C
216 volatile unsigned int f0_1_fine_time; // 0x2C
124 //
217 //
125 volatile unsigned int f1_0_coarse_time; // 0x30
218 volatile unsigned int f1_0_coarse_time; // 0x30
126 volatile unsigned int f1_0_fine_time; // 0x34
219 volatile unsigned int f1_0_fine_time; // 0x34
127 volatile unsigned int f1_1_coarse_time; // 0x38
220 volatile unsigned int f1_1_coarse_time; // 0x38
128 volatile unsigned int f1_1_fine_time; // 0x3C
221 volatile unsigned int f1_1_fine_time; // 0x3C
129 //
222 //
130 volatile unsigned int f2_0_coarse_time; // 0x40
223 volatile unsigned int f2_0_coarse_time; // 0x40
131 volatile unsigned int f2_0_fine_time; // 0x44
224 volatile unsigned int f2_0_fine_time; // 0x44
132 volatile unsigned int f2_1_coarse_time; // 0x48
225 volatile unsigned int f2_1_coarse_time; // 0x48
133 volatile unsigned int f2_1_fine_time; // 0x4C
226 volatile unsigned int f2_1_fine_time; // 0x4C
134 //
227 //
135 unsigned int matrix_length; // 0x50, length of a spectral matrix in burst 3200 / 16 = 200 = 0xc8
228 unsigned int matrix_length; // 0x50, length of a spectral matrix in burst 3200 / 16 = 200 = 0xc8
136 } spectral_matrix_regs_t;
229 } spectral_matrix_regs_t;
137
230
138 #endif // GRLIB_REGS_H_INCLUDED
231 #endif // GRLIB_REGS_H_INCLUDED
@@ -1,32 +1,36
1 #ifndef LFR_CPU_USAGE_REPORT_H
1 #ifndef LFR_CPU_USAGE_REPORT_H
2 #define LFR_CPU_USAGE_REPORT_H
2 #define LFR_CPU_USAGE_REPORT_H
3
3
4 #ifdef HAVE_CONFIG_H
4 #ifdef HAVE_CONFIG_H
5 #include "config.h"
5 #include "config.h"
6 #endif
6 #endif
7
7
8 #include <rtems.h>
8 #include <rtems.h>
9
9
10 #include <assert.h>
10 #include <assert.h>
11 #include <string.h>
11 #include <string.h>
12 #include <stdlib.h>
12 #include <stdlib.h>
13 #include <stdio.h>
13 #include <stdio.h>
14 #include <ctype.h>
14 #include <ctype.h>
15 #include <inttypes.h>
15 #include <inttypes.h>
16
16
17 #include <rtems/cpuuse.h>
17 #include <rtems/cpuuse.h>
18 #include <rtems/bspIo.h>
18 #include <rtems/bspIo.h>
19
19
20 #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
20 #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
21 #include <rtems/score/timestamp.h>
21 #include <rtems/score/timestamp.h>
22 #endif
22 #endif
23
23
24 #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
24 #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
25 extern Timestamp_Control CPU_usage_Uptime_at_last_reset;
25 extern Timestamp_Control CPU_usage_Uptime_at_last_reset;
26 #else
26 #else
27 extern uint32_t CPU_usage_Ticks_at_last_reset;
27 extern uint32_t CPU_usage_Ticks_at_last_reset;
28 #endif
28 #endif
29
29
30 unsigned char lfr_rtems_cpu_usage_report( void );
30 unsigned char lfr_rtems_cpu_usage_report( void );
31
31
32 #define CONST_100 100
33 #define CONST_1000 1000
34 #define CONST_100000 100000
35
32 #endif // LFR_CPU_USAGE_REPORT_H
36 #endif // LFR_CPU_USAGE_REPORT_H
@@ -1,361 +1,371
1 #ifndef FSW_PROCESSING_H_INCLUDED
1 #ifndef FSW_PROCESSING_H_INCLUDED
2 #define FSW_PROCESSING_H_INCLUDED
2 #define FSW_PROCESSING_H_INCLUDED
3
3
4 #include <rtems.h>
4 #include <rtems.h>
5 #include <grspw.h>
5 #include <grspw.h>
6 #include <math.h>
6 #include <math.h>
7 #include <stdlib.h> // abs() is in the stdlib
7 #include <stdlib.h> // abs() is in the stdlib
8 #include <stdio.h>
8 #include <stdio.h>
9 #include <math.h>
9 #include <math.h>
10 #include <grlib_regs.h>
10 #include <grlib_regs.h>
11
11
12 #include "fsw_params.h"
12 #include "fsw_params.h"
13
13
14 #define SBM_COEFF_PER_NORM_COEFF 2
15 #define MAX_SRC_DATA 780 // MAX size is 26 bins * 30 Bytes [TM_LFR_SCIENCE_BURST_BP2_F1]
16 #define MAX_SRC_DATA_WITH_SPARE 143 // 13 bins * 11 Bytes
17
14 typedef struct ring_node_asm
18 typedef struct ring_node_asm
15 {
19 {
16 struct ring_node_asm *next;
20 struct ring_node_asm *next;
17 float matrix[ TOTAL_SIZE_SM ];
21 float matrix[ TOTAL_SIZE_SM ];
18 unsigned int status;
22 unsigned int status;
19 } ring_node_asm;
23 } ring_node_asm;
20
24
21 typedef struct
25 typedef struct
22 {
26 {
23 unsigned char targetLogicalAddress;
27 unsigned char targetLogicalAddress;
24 unsigned char protocolIdentifier;
28 unsigned char protocolIdentifier;
25 unsigned char reserved;
29 unsigned char reserved;
26 unsigned char userApplication;
30 unsigned char userApplication;
27 unsigned char packetID[2];
31 unsigned char packetID[BYTES_PER_PACKETID];
28 unsigned char packetSequenceControl[2];
32 unsigned char packetSequenceControl[BYTES_PER_SEQ_CTRL];
29 unsigned char packetLength[2];
33 unsigned char packetLength[BYTES_PER_PKT_LEN];
30 // DATA FIELD HEADER
34 // DATA FIELD HEADER
31 unsigned char spare1_pusVersion_spare2;
35 unsigned char spare1_pusVersion_spare2;
32 unsigned char serviceType;
36 unsigned char serviceType;
33 unsigned char serviceSubType;
37 unsigned char serviceSubType;
34 unsigned char destinationID;
38 unsigned char destinationID;
35 unsigned char time[6];
39 unsigned char time[BYTES_PER_TIME];
36 // AUXILIARY HEADER
40 // AUXILIARY HEADER
37 unsigned char sid;
41 unsigned char sid;
38 unsigned char pa_bia_status_info;
42 unsigned char pa_bia_status_info;
39 unsigned char sy_lfr_common_parameters_spare;
43 unsigned char sy_lfr_common_parameters_spare;
40 unsigned char sy_lfr_common_parameters;
44 unsigned char sy_lfr_common_parameters;
41 unsigned char acquisitionTime[6];
45 unsigned char acquisitionTime[BYTES_PER_TIME];
42 unsigned char pa_lfr_bp_blk_nr[2];
46 unsigned char pa_lfr_bp_blk_nr[BYTES_PER_BLKNR];
43 // SOURCE DATA
47 // SOURCE DATA
44 unsigned char data[ 780 ]; // MAX size is 26 bins * 30 Bytes [TM_LFR_SCIENCE_BURST_BP2_F1]
48 unsigned char data[ MAX_SRC_DATA ]; // MAX size is 26 bins * 30 Bytes [TM_LFR_SCIENCE_BURST_BP2_F1]
45 } bp_packet;
49 } bp_packet;
46
50
47 typedef struct
51 typedef struct
48 {
52 {
49 unsigned char targetLogicalAddress;
53 unsigned char targetLogicalAddress;
50 unsigned char protocolIdentifier;
54 unsigned char protocolIdentifier;
51 unsigned char reserved;
55 unsigned char reserved;
52 unsigned char userApplication;
56 unsigned char userApplication;
53 unsigned char packetID[2];
57 unsigned char packetID[BYTES_PER_PACKETID];
54 unsigned char packetSequenceControl[2];
58 unsigned char packetSequenceControl[BYTES_PER_SEQ_CTRL];
55 unsigned char packetLength[2];
59 unsigned char packetLength[BYTES_PER_PKT_LEN];
56 // DATA FIELD HEADER
60 // DATA FIELD HEADER
57 unsigned char spare1_pusVersion_spare2;
61 unsigned char spare1_pusVersion_spare2;
58 unsigned char serviceType;
62 unsigned char serviceType;
59 unsigned char serviceSubType;
63 unsigned char serviceSubType;
60 unsigned char destinationID;
64 unsigned char destinationID;
61 unsigned char time[6];
65 unsigned char time[BYTES_PER_TIME];
62 // AUXILIARY HEADER
66 // AUXILIARY HEADER
63 unsigned char sid;
67 unsigned char sid;
64 unsigned char pa_bia_status_info;
68 unsigned char pa_bia_status_info;
65 unsigned char sy_lfr_common_parameters_spare;
69 unsigned char sy_lfr_common_parameters_spare;
66 unsigned char sy_lfr_common_parameters;
70 unsigned char sy_lfr_common_parameters;
67 unsigned char acquisitionTime[6];
71 unsigned char acquisitionTime[BYTES_PER_TIME];
68 unsigned char source_data_spare;
72 unsigned char source_data_spare;
69 unsigned char pa_lfr_bp_blk_nr[2];
73 unsigned char pa_lfr_bp_blk_nr[BYTES_PER_BLKNR];
70 // SOURCE DATA
74 // SOURCE DATA
71 unsigned char data[ 143 ]; // 13 bins * 11 Bytes
75 unsigned char data[ MAX_SRC_DATA_WITH_SPARE ]; // 13 bins * 11 Bytes
72 } bp_packet_with_spare; // only for TM_LFR_SCIENCE_NORMAL_BP1_F0 and F1
76 } bp_packet_with_spare; // only for TM_LFR_SCIENCE_NORMAL_BP1_F0 and F1
73
77
74 typedef struct asm_msg
78 typedef struct asm_msg
75 {
79 {
76 ring_node_asm *norm;
80 ring_node_asm *norm;
77 ring_node_asm *burst_sbm;
81 ring_node_asm *burst_sbm;
78 rtems_event_set event;
82 rtems_event_set event;
79 unsigned int coarseTimeNORM;
83 unsigned int coarseTimeNORM;
80 unsigned int fineTimeNORM;
84 unsigned int fineTimeNORM;
81 unsigned int coarseTimeSBM;
85 unsigned int coarseTimeSBM;
82 unsigned int fineTimeSBM;
86 unsigned int fineTimeSBM;
83 unsigned int numberOfSMInASMNORM;
87 unsigned int numberOfSMInASMNORM;
84 unsigned int numberOfSMInASMSBM;
88 unsigned int numberOfSMInASMSBM;
85 } asm_msg;
89 } asm_msg;
86
90
87 extern unsigned char thisIsAnASMRestart;
91 extern unsigned char thisIsAnASMRestart;
88
92
89 extern volatile int sm_f0[ ];
93 extern volatile int sm_f0[ ];
90 extern volatile int sm_f1[ ];
94 extern volatile int sm_f1[ ];
91 extern volatile int sm_f2[ ];
95 extern volatile int sm_f2[ ];
92 extern unsigned int acquisitionDurations[];
96 extern unsigned int acquisitionDurations[];
93
97
94 // parameters
98 // parameters
95 extern struct param_local_str param_local;
99 extern struct param_local_str param_local;
96 extern Packet_TM_LFR_PARAMETER_DUMP_t parameter_dump_packet;
100 extern Packet_TM_LFR_PARAMETER_DUMP_t parameter_dump_packet;
97
101
98 // registers
102 // registers
99 extern time_management_regs_t *time_management_regs;
103 extern time_management_regs_t *time_management_regs;
100 extern volatile spectral_matrix_regs_t *spectral_matrix_regs;
104 extern volatile spectral_matrix_regs_t *spectral_matrix_regs;
101
105
102 extern rtems_name misc_name[5];
106 extern rtems_name misc_name[];
103 extern rtems_id Task_id[20]; /* array of task ids */
107 extern rtems_id Task_id[]; /* array of task ids */
104
108
105 ring_node * getRingNodeForAveraging( unsigned char frequencyChannel);
109 ring_node * getRingNodeForAveraging( unsigned char frequencyChannel);
106 // ISR
110 // ISR
107 rtems_isr spectral_matrices_isr( rtems_vector_number vector );
111 rtems_isr spectral_matrices_isr( rtems_vector_number vector );
108
112
109 //******************
113 //******************
110 // Spectral Matrices
114 // Spectral Matrices
111 void reset_nb_sm( void );
115 void reset_nb_sm( void );
112 // SM
116 // SM
113 void SM_init_rings( void );
117 void SM_init_rings( void );
114 void SM_reset_current_ring_nodes( void );
118 void SM_reset_current_ring_nodes( void );
115 // ASM
119 // ASM
116 void ASM_generic_init_ring(ring_node_asm *ring, unsigned char nbNodes );
120 void ASM_generic_init_ring(ring_node_asm *ring, unsigned char nbNodes );
117
121
118 //*****************
122 //*****************
119 // Basic Parameters
123 // Basic Parameters
120
124
121 void BP_reset_current_ring_nodes( void );
125 void BP_reset_current_ring_nodes( void );
122 void BP_init_header(bp_packet *packet,
126 void BP_init_header(bp_packet *packet,
123 unsigned int apid, unsigned char sid,
127 unsigned int apid, unsigned char sid,
124 unsigned int packetLength , unsigned char blkNr);
128 unsigned int packetLength , unsigned char blkNr);
125 void BP_init_header_with_spare(bp_packet_with_spare *packet,
129 void BP_init_header_with_spare(bp_packet_with_spare *packet,
126 unsigned int apid, unsigned char sid,
130 unsigned int apid, unsigned char sid,
127 unsigned int packetLength, unsigned char blkNr );
131 unsigned int packetLength, unsigned char blkNr );
128 void BP_send( char *data,
132 void BP_send( char *data,
129 rtems_id queue_id,
133 rtems_id queue_id,
130 unsigned int nbBytesToSend , unsigned int sid );
134 unsigned int nbBytesToSend , unsigned int sid );
131 void BP_send_s1_s2(char *data,
135 void BP_send_s1_s2(char *data,
132 rtems_id queue_id,
136 rtems_id queue_id,
133 unsigned int nbBytesToSend, unsigned int sid );
137 unsigned int nbBytesToSend, unsigned int sid );
134
138
135 //******************
139 //******************
136 // general functions
140 // general functions
137 void reset_sm_status( void );
141 void reset_sm_status( void );
138 void reset_spectral_matrix_regs( void );
142 void reset_spectral_matrix_regs( void );
139 void set_time(unsigned char *time, unsigned char *timeInBuffer );
143 void set_time(unsigned char *time, unsigned char *timeInBuffer );
140 unsigned long long int get_acquisition_time( unsigned char *timePtr );
144 unsigned long long int get_acquisition_time( unsigned char *timePtr );
141 unsigned char getSID( rtems_event_set event );
145 unsigned char getSID( rtems_event_set event );
142
146
143 extern rtems_status_code get_message_queue_id_prc1( rtems_id *queue_id );
147 extern rtems_status_code get_message_queue_id_prc1( rtems_id *queue_id );
144 extern rtems_status_code get_message_queue_id_prc2( rtems_id *queue_id );
148 extern rtems_status_code get_message_queue_id_prc2( rtems_id *queue_id );
145
149
146 //***************************************
150 //***************************************
147 // DEFINITIONS OF STATIC INLINE FUNCTIONS
151 // DEFINITIONS OF STATIC INLINE FUNCTIONS
148 static inline void SM_average(float *averaged_spec_mat_NORM, float *averaged_spec_mat_SBM,
152 static inline void SM_average(float *averaged_spec_mat_NORM, float *averaged_spec_mat_SBM,
149 ring_node *ring_node_tab[],
153 ring_node *ring_node_tab[],
150 unsigned int nbAverageNORM, unsigned int nbAverageSBM,
154 unsigned int nbAverageNORM, unsigned int nbAverageSBM,
151 asm_msg *msgForMATR , unsigned char channel);
155 asm_msg *msgForMATR , unsigned char channel);
152
156
153 void ASM_patch( float *inputASM, float *outputASM );
157 void ASM_patch( float *inputASM, float *outputASM );
154
158
155 void extractReImVectors(float *inputASM, float *outputASM, unsigned int asmComponent );
159 void extractReImVectors(float *inputASM, float *outputASM, unsigned int asmComponent );
156
160
157 static inline void ASM_reorganize_and_divide(float *averaged_spec_mat, float *averaged_spec_mat_reorganized,
161 static inline void ASM_reorganize_and_divide(float *averaged_spec_mat, float *averaged_spec_mat_reorganized,
158 float divider );
162 float divider );
159
163
160 static inline void ASM_compress_reorganize_and_divide(float *averaged_spec_mat, float *compressed_spec_mat,
164 static inline void ASM_compress_reorganize_and_divide(float *averaged_spec_mat, float *compressed_spec_mat,
161 float divider,
165 float divider,
162 unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage , unsigned char ASMIndexStart);
166 unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage , unsigned char ASMIndexStart);
163
167
164 static inline void ASM_convert(volatile float *input_matrix, char *output_matrix);
168 static inline void ASM_convert(volatile float *input_matrix, char *output_matrix);
165
169
166 unsigned char acquisitionTimeIsValid(unsigned int coarseTime, unsigned int fineTime, unsigned char channel);
170 unsigned char acquisitionTimeIsValid(unsigned int coarseTime, unsigned int fineTime, unsigned char channel);
167
171
168 void SM_average( float *averaged_spec_mat_NORM, float *averaged_spec_mat_SBM,
172 void SM_average( float *averaged_spec_mat_NORM, float *averaged_spec_mat_SBM,
169 ring_node *ring_node_tab[],
173 ring_node *ring_node_tab[],
170 unsigned int nbAverageNORM, unsigned int nbAverageSBM,
174 unsigned int nbAverageNORM, unsigned int nbAverageSBM,
171 asm_msg *msgForMATR, unsigned char channel )
175 asm_msg *msgForMATR, unsigned char channel )
172 {
176 {
173 float sum;
177 float sum;
174 unsigned int i;
178 unsigned int i;
175 unsigned int k;
179 unsigned int k;
176 unsigned char incomingSMIsValid[8];
180 unsigned char incomingSMIsValid[NB_SM_BEFORE_AVF0_F1];
177 unsigned int numberOfValidSM;
181 unsigned int numberOfValidSM;
178 unsigned char isValid;
182 unsigned char isValid;
179
183
180 //**************
184 //**************
181 // PAS FILTERING
185 // PAS FILTERING
182 // check acquisitionTime of the incoming data
186 // check acquisitionTime of the incoming data
183 numberOfValidSM = 0;
187 numberOfValidSM = 0;
184 for (k=0; k<8; k++)
188 for (k=0; k<NB_SM_BEFORE_AVF0_F1; k++)
185 {
189 {
186 isValid = acquisitionTimeIsValid( ring_node_tab[k]->coarseTime, ring_node_tab[k]->fineTime, channel );
190 isValid = acquisitionTimeIsValid( ring_node_tab[k]->coarseTime, ring_node_tab[k]->fineTime, channel );
187 incomingSMIsValid[k] = isValid;
191 incomingSMIsValid[k] = isValid;
188 numberOfValidSM = numberOfValidSM + isValid;
192 numberOfValidSM = numberOfValidSM + isValid;
189 }
193 }
190
194
191 //************************
195 //************************
192 // AVERAGE SPECTRAL MATRIX
196 // AVERAGE SPECTRAL MATRIX
193 for(i=0; i<TOTAL_SIZE_SM; i++)
197 for(i=0; i<TOTAL_SIZE_SM; i++)
194 {
198 {
195 // sum = ( (int *) (ring_node_tab[0]->buffer_address) ) [ i ]
199 // sum = ( (int *) (ring_node_tab[0]->buffer_address) ) [ i ]
196 // + ( (int *) (ring_node_tab[1]->buffer_address) ) [ i ]
200 // + ( (int *) (ring_node_tab[1]->buffer_address) ) [ i ]
197 // + ( (int *) (ring_node_tab[2]->buffer_address) ) [ i ]
201 // + ( (int *) (ring_node_tab[2]->buffer_address) ) [ i ]
198 // + ( (int *) (ring_node_tab[3]->buffer_address) ) [ i ]
202 // + ( (int *) (ring_node_tab[3]->buffer_address) ) [ i ]
199 // + ( (int *) (ring_node_tab[4]->buffer_address) ) [ i ]
203 // + ( (int *) (ring_node_tab[4]->buffer_address) ) [ i ]
200 // + ( (int *) (ring_node_tab[5]->buffer_address) ) [ i ]
204 // + ( (int *) (ring_node_tab[5]->buffer_address) ) [ i ]
201 // + ( (int *) (ring_node_tab[6]->buffer_address) ) [ i ]
205 // + ( (int *) (ring_node_tab[6]->buffer_address) ) [ i ]
202 // + ( (int *) (ring_node_tab[7]->buffer_address) ) [ i ];
206 // + ( (int *) (ring_node_tab[7]->buffer_address) ) [ i ];
203
207
204 sum = ( (incomingSMIsValid[0] == 1) ? ( (int *) (ring_node_tab[0]->buffer_address) ) [ i ] : 0.0 )
208 sum = ( incomingSMIsValid[0] * ((int *)(ring_node_tab[0]->buffer_address) )[ i ] )
205 + ( (incomingSMIsValid[1] == 1) ? ( (int *) (ring_node_tab[1]->buffer_address) ) [ i ] : 0.0 )
209 + ( incomingSMIsValid[1] * ((int *)(ring_node_tab[1]->buffer_address) )[ i ] )
206 + ( (incomingSMIsValid[2] == 1) ? ( (int *) (ring_node_tab[2]->buffer_address) ) [ i ] : 0.0 )
210 + ( incomingSMIsValid[2] * ((int *)(ring_node_tab[2]->buffer_address) )[ i ] )
207 + ( (incomingSMIsValid[3] == 1) ? ( (int *) (ring_node_tab[3]->buffer_address) ) [ i ] : 0.0 )
211 + ( incomingSMIsValid[3] * ((int *)(ring_node_tab[3]->buffer_address) )[ i ] )
208 + ( (incomingSMIsValid[4] == 1) ? ( (int *) (ring_node_tab[4]->buffer_address) ) [ i ] : 0.0 )
212 + ( incomingSMIsValid[4] * ((int *)(ring_node_tab[4]->buffer_address) )[ i ] )
209 + ( (incomingSMIsValid[5] == 1) ? ( (int *) (ring_node_tab[5]->buffer_address) ) [ i ] : 0.0 )
213 + ( incomingSMIsValid[5] * ((int *)(ring_node_tab[5]->buffer_address) )[ i ] )
210 + ( (incomingSMIsValid[6] == 1) ? ( (int *) (ring_node_tab[6]->buffer_address) ) [ i ] : 0.0 )
214 + ( incomingSMIsValid[6] * ((int *)(ring_node_tab[6]->buffer_address) )[ i ] )
211 + ( (incomingSMIsValid[7] == 1) ? ( (int *) (ring_node_tab[7]->buffer_address) ) [ i ] : 0.0 );
215 + ( incomingSMIsValid[7] * ((int *)(ring_node_tab[7]->buffer_address) )[ i ] );
212
216
213 if ( (nbAverageNORM == 0) && (nbAverageSBM == 0) )
217 if ( (nbAverageNORM == 0) && (nbAverageSBM == 0) )
214 {
218 {
215 averaged_spec_mat_NORM[ i ] = sum;
219 averaged_spec_mat_NORM[ i ] = sum;
216 averaged_spec_mat_SBM[ i ] = sum;
220 averaged_spec_mat_SBM[ i ] = sum;
217 msgForMATR->coarseTimeNORM = ring_node_tab[0]->coarseTime;
221 msgForMATR->coarseTimeNORM = ring_node_tab[0]->coarseTime;
218 msgForMATR->fineTimeNORM = ring_node_tab[0]->fineTime;
222 msgForMATR->fineTimeNORM = ring_node_tab[0]->fineTime;
219 msgForMATR->coarseTimeSBM = ring_node_tab[0]->coarseTime;
223 msgForMATR->coarseTimeSBM = ring_node_tab[0]->coarseTime;
220 msgForMATR->fineTimeSBM = ring_node_tab[0]->fineTime;
224 msgForMATR->fineTimeSBM = ring_node_tab[0]->fineTime;
221 }
225 }
222 else if ( (nbAverageNORM != 0) && (nbAverageSBM != 0) )
226 else if ( (nbAverageNORM != 0) && (nbAverageSBM != 0) )
223 {
227 {
224 averaged_spec_mat_NORM[ i ] = ( averaged_spec_mat_NORM[ i ] + sum );
228 averaged_spec_mat_NORM[ i ] = ( averaged_spec_mat_NORM[ i ] + sum );
225 averaged_spec_mat_SBM[ i ] = ( averaged_spec_mat_SBM[ i ] + sum );
229 averaged_spec_mat_SBM[ i ] = ( averaged_spec_mat_SBM[ i ] + sum );
226 }
230 }
227 else if ( (nbAverageNORM != 0) && (nbAverageSBM == 0) )
231 else if ( (nbAverageNORM != 0) && (nbAverageSBM == 0) )
228 {
232 {
229 averaged_spec_mat_NORM[ i ] = ( averaged_spec_mat_NORM[ i ] + sum );
233 averaged_spec_mat_NORM[ i ] = ( averaged_spec_mat_NORM[ i ] + sum );
230 averaged_spec_mat_SBM[ i ] = sum;
234 averaged_spec_mat_SBM[ i ] = sum;
231 msgForMATR->coarseTimeSBM = ring_node_tab[0]->coarseTime;
235 msgForMATR->coarseTimeSBM = ring_node_tab[0]->coarseTime;
232 msgForMATR->fineTimeSBM = ring_node_tab[0]->fineTime;
236 msgForMATR->fineTimeSBM = ring_node_tab[0]->fineTime;
233 }
237 }
234 else
238 else
235 {
239 {
236 averaged_spec_mat_NORM[ i ] = sum;
240 averaged_spec_mat_NORM[ i ] = sum;
237 averaged_spec_mat_SBM[ i ] = ( averaged_spec_mat_SBM[ i ] + sum );
241 averaged_spec_mat_SBM[ i ] = ( averaged_spec_mat_SBM[ i ] + sum );
238 msgForMATR->coarseTimeNORM = ring_node_tab[0]->coarseTime;
242 msgForMATR->coarseTimeNORM = ring_node_tab[0]->coarseTime;
239 msgForMATR->fineTimeNORM = ring_node_tab[0]->fineTime;
243 msgForMATR->fineTimeNORM = ring_node_tab[0]->fineTime;
240 // PRINTF2("ERR *** in SM_average *** unexpected parameters %d %d\n", nbAverageNORM, nbAverageSBM)
244 // PRINTF2("ERR *** in SM_average *** unexpected parameters %d %d\n", nbAverageNORM, nbAverageSBM)
241 }
245 }
242 }
246 }
243
247
244 //*******************
248 //*******************
245 // UPDATE SM COUNTERS
249 // UPDATE SM COUNTERS
246 if ( (nbAverageNORM == 0) && (nbAverageSBM == 0) )
250 if ( (nbAverageNORM == 0) && (nbAverageSBM == 0) )
247 {
251 {
248 msgForMATR->numberOfSMInASMNORM = numberOfValidSM;
252 msgForMATR->numberOfSMInASMNORM = numberOfValidSM;
249 msgForMATR->numberOfSMInASMSBM = numberOfValidSM;
253 msgForMATR->numberOfSMInASMSBM = numberOfValidSM;
250 }
254 }
251 else if ( (nbAverageNORM != 0) && (nbAverageSBM != 0) )
255 else if ( (nbAverageNORM != 0) && (nbAverageSBM != 0) )
252 {
256 {
253 msgForMATR->numberOfSMInASMNORM = msgForMATR->numberOfSMInASMNORM + numberOfValidSM;
257 msgForMATR->numberOfSMInASMNORM = msgForMATR->numberOfSMInASMNORM + numberOfValidSM;
254 msgForMATR->numberOfSMInASMSBM = msgForMATR->numberOfSMInASMSBM + numberOfValidSM;
258 msgForMATR->numberOfSMInASMSBM = msgForMATR->numberOfSMInASMSBM + numberOfValidSM;
255 }
259 }
256 else if ( (nbAverageNORM != 0) && (nbAverageSBM == 0) )
260 else if ( (nbAverageNORM != 0) && (nbAverageSBM == 0) )
257 {
261 {
258 msgForMATR->numberOfSMInASMNORM = msgForMATR->numberOfSMInASMNORM + numberOfValidSM;
262 msgForMATR->numberOfSMInASMNORM = msgForMATR->numberOfSMInASMNORM + numberOfValidSM;
259 msgForMATR->numberOfSMInASMSBM = numberOfValidSM;
263 msgForMATR->numberOfSMInASMSBM = numberOfValidSM;
260 }
264 }
261 else
265 else
262 {
266 {
263 msgForMATR->numberOfSMInASMNORM = numberOfValidSM;
267 msgForMATR->numberOfSMInASMNORM = numberOfValidSM;
264 msgForMATR->numberOfSMInASMSBM = msgForMATR->numberOfSMInASMSBM + numberOfValidSM;
268 msgForMATR->numberOfSMInASMSBM = msgForMATR->numberOfSMInASMSBM + numberOfValidSM;
265 }
269 }
266 }
270 }
267
271
268 void ASM_reorganize_and_divide( float *averaged_spec_mat, float *averaged_spec_mat_reorganized, float divider )
272 void ASM_reorganize_and_divide( float *averaged_spec_mat, float *averaged_spec_mat_reorganized, float divider )
269 {
273 {
270 int frequencyBin;
274 int frequencyBin;
271 int asmComponent;
275 int asmComponent;
272 unsigned int offsetASM;
276 unsigned int offsetASM;
273 unsigned int offsetASMReorganized;
277 unsigned int offsetASMReorganized;
274
278
275 // BUILD DATA
279 // BUILD DATA
276 for (asmComponent = 0; asmComponent < NB_VALUES_PER_SM; asmComponent++)
280 for (asmComponent = 0; asmComponent < NB_VALUES_PER_SM; asmComponent++)
277 {
281 {
278 for( frequencyBin = 0; frequencyBin < NB_BINS_PER_SM; frequencyBin++ )
282 for( frequencyBin = 0; frequencyBin < NB_BINS_PER_SM; frequencyBin++ )
279 {
283 {
280 offsetASMReorganized =
284 offsetASMReorganized =
281 frequencyBin * NB_VALUES_PER_SM
285 (frequencyBin * NB_VALUES_PER_SM)
282 + asmComponent;
286 + asmComponent;
283 offsetASM =
287 offsetASM =
284 asmComponent * NB_BINS_PER_SM
288 (asmComponent * NB_BINS_PER_SM)
285 + frequencyBin;
289 + frequencyBin;
286 averaged_spec_mat_reorganized[offsetASMReorganized ] =
290 if ( divider != INIT_FLOAT )
287 (divider != 0.0) ? averaged_spec_mat[ offsetASM ] / divider : 0.0;
291 {
292 averaged_spec_mat_reorganized[offsetASMReorganized ] = averaged_spec_mat[ offsetASM ] / divider;
293 }
294 else
295 {
296 averaged_spec_mat_reorganized[offsetASMReorganized ] = INIT_FLOAT;
297 }
288 }
298 }
289 }
299 }
290 }
300 }
291
301
292 void ASM_compress_reorganize_and_divide(float *averaged_spec_mat, float *compressed_spec_mat , float divider,
302 void ASM_compress_reorganize_and_divide(float *averaged_spec_mat, float *compressed_spec_mat , float divider,
293 unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage, unsigned char ASMIndexStart )
303 unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage, unsigned char ASMIndexStart )
294 {
304 {
295 int frequencyBin;
305 int frequencyBin;
296 int asmComponent;
306 int asmComponent;
297 int offsetASM;
307 int offsetASM;
298 int offsetCompressed;
308 int offsetCompressed;
299 int k;
309 int k;
300
310
301 // BUILD DATA
311 // BUILD DATA
302 for (asmComponent = 0; asmComponent < NB_VALUES_PER_SM; asmComponent++)
312 for (asmComponent = 0; asmComponent < NB_VALUES_PER_SM; asmComponent++)
303 {
313 {
304 for( frequencyBin = 0; frequencyBin < nbBinsCompressedMatrix; frequencyBin++ )
314 for( frequencyBin = 0; frequencyBin < nbBinsCompressedMatrix; frequencyBin++ )
305 {
315 {
306 offsetCompressed = // NO TIME OFFSET
316 offsetCompressed = // NO TIME OFFSET
307 frequencyBin * NB_VALUES_PER_SM
317 (frequencyBin * NB_VALUES_PER_SM)
308 + asmComponent;
318 + asmComponent;
309 offsetASM = // NO TIME OFFSET
319 offsetASM = // NO TIME OFFSET
310 asmComponent * NB_BINS_PER_SM
320 (asmComponent * NB_BINS_PER_SM)
311 + ASMIndexStart
321 + ASMIndexStart
312 + frequencyBin * nbBinsToAverage;
322 + (frequencyBin * nbBinsToAverage);
313 compressed_spec_mat[ offsetCompressed ] = 0;
323 compressed_spec_mat[ offsetCompressed ] = 0;
314 for ( k = 0; k < nbBinsToAverage; k++ )
324 for ( k = 0; k < nbBinsToAverage; k++ )
315 {
325 {
316 compressed_spec_mat[offsetCompressed ] =
326 compressed_spec_mat[offsetCompressed ] =
317 ( compressed_spec_mat[ offsetCompressed ]
327 ( compressed_spec_mat[ offsetCompressed ]
318 + averaged_spec_mat[ offsetASM + k ] );
328 + averaged_spec_mat[ offsetASM + k ] );
319 }
329 }
320 compressed_spec_mat[ offsetCompressed ] =
330 compressed_spec_mat[ offsetCompressed ] =
321 compressed_spec_mat[ offsetCompressed ] / (divider * nbBinsToAverage);
331 compressed_spec_mat[ offsetCompressed ] / (divider * nbBinsToAverage);
322 }
332 }
323 }
333 }
324 }
334 }
325
335
326 void ASM_convert( volatile float *input_matrix, char *output_matrix)
336 void ASM_convert( volatile float *input_matrix, char *output_matrix)
327 {
337 {
328 unsigned int frequencyBin;
338 unsigned int frequencyBin;
329 unsigned int asmComponent;
339 unsigned int asmComponent;
330 char * pt_char_input;
340 char * pt_char_input;
331 char * pt_char_output;
341 char * pt_char_output;
332 unsigned int offsetInput;
342 unsigned int offsetInput;
333 unsigned int offsetOutput;
343 unsigned int offsetOutput;
334
344
335 pt_char_input = (char*) &input_matrix;
345 pt_char_input = (char*) &input_matrix;
336 pt_char_output = (char*) &output_matrix;
346 pt_char_output = (char*) &output_matrix;
337
347
338 // convert all other data
348 // convert all other data
339 for( frequencyBin=0; frequencyBin<NB_BINS_PER_SM; frequencyBin++)
349 for( frequencyBin=0; frequencyBin<NB_BINS_PER_SM; frequencyBin++)
340 {
350 {
341 for ( asmComponent=0; asmComponent<NB_VALUES_PER_SM; asmComponent++)
351 for ( asmComponent=0; asmComponent<NB_VALUES_PER_SM; asmComponent++)
342 {
352 {
343 offsetInput = (frequencyBin*NB_VALUES_PER_SM) + asmComponent ;
353 offsetInput = (frequencyBin*NB_VALUES_PER_SM) + asmComponent ;
344 offsetOutput = 2 * ( (frequencyBin*NB_VALUES_PER_SM) + asmComponent ) ;
354 offsetOutput = SM_BYTES_PER_VAL * ( (frequencyBin*NB_VALUES_PER_SM) + asmComponent ) ;
345 pt_char_input = (char*) &input_matrix [ offsetInput ];
355 pt_char_input = (char*) &input_matrix [ offsetInput ];
346 pt_char_output = (char*) &output_matrix[ offsetOutput ];
356 pt_char_output = (char*) &output_matrix[ offsetOutput ];
347 pt_char_output[0] = pt_char_input[0]; // bits 31 downto 24 of the float
357 pt_char_output[0] = pt_char_input[0]; // bits 31 downto 24 of the float
348 pt_char_output[1] = pt_char_input[1]; // bits 23 downto 16 of the float
358 pt_char_output[1] = pt_char_input[1]; // bits 23 downto 16 of the float
349 }
359 }
350 }
360 }
351 }
361 }
352
362
353 void ASM_compress_reorganize_and_divide_mask(float *averaged_spec_mat, float *compressed_spec_mat,
363 void ASM_compress_reorganize_and_divide_mask(float *averaged_spec_mat, float *compressed_spec_mat,
354 float divider,
364 float divider,
355 unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage , unsigned char ASMIndexStart, unsigned char channel);
365 unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage , unsigned char ASMIndexStart, unsigned char channel);
356
366
357 int getFBinMask(int k, unsigned char channel);
367 int getFBinMask(int k, unsigned char channel);
358
368
359 void init_kcoeff_sbm_from_kcoeff_norm( float *input_kcoeff, float *output_kcoeff, unsigned char nb_bins_norm);
369 void init_kcoeff_sbm_from_kcoeff_norm( float *input_kcoeff, float *output_kcoeff, unsigned char nb_bins_norm);
360
370
361 #endif // FSW_PROCESSING_H_INCLUDED
371 #endif // FSW_PROCESSING_H_INCLUDED
@@ -1,25 +1,44
1 #ifndef TC_ACCEPTANCE_H_INCLUDED
1 #ifndef TC_ACCEPTANCE_H_INCLUDED
2 #define TC_ACCEPTANCE_H_INCLUDED
2 #define TC_ACCEPTANCE_H_INCLUDED
3
3
4 //#include "tm_lfr_tc_exe.h"
5 #include "fsw_params.h"
4 #include "fsw_params.h"
6
5
6 #define BIT_0 0x01
7 #define BIT_1 0x02
8 #define BIT_2 0x04
9 #define BIT_3 0x08
10 #define BIT_4 0x10
11 #define BIT_5 0x20
12 #define BIT_6 0x40
13 #define BIT_7 0x80
14
15 #define CONST_CRC_0 0x1021
16 #define CONST_CRC_1 0x2042
17 #define CONST_CRC_2 0x4084
18 #define CONST_CRC_3 0x8108
19 #define CONST_CRC_4 0x1231
20 #define CONST_CRC_5 0x2462
21 #define CONST_CRC_6 0x48c4
22 #define CONST_CRC_7 0x9188
23
24 #define CRC_RESET 0xffff
25
7 //**********************
26 //**********************
8 // GENERAL USE FUNCTIONS
27 // GENERAL USE FUNCTIONS
9 unsigned int Crc_opt( unsigned char D, unsigned int Chk);
28 unsigned int Crc_opt( unsigned char D, unsigned int Chk);
10 void initLookUpTableForCRC( void );
29 void initLookUpTableForCRC( void );
11 void GetCRCAsTwoBytes(unsigned char* data, unsigned char* crcAsTwoBytes, unsigned int sizeOfData);
30 void GetCRCAsTwoBytes(unsigned char* data, unsigned char* crcAsTwoBytes, unsigned int sizeOfData);
12
31
13 //*********************
32 //*********************
14 // ACCEPTANCE FUNCTIONS
33 // ACCEPTANCE FUNCTIONS
15 int tc_parser( ccsdsTelecommandPacket_t * TCPacket, unsigned int estimatedPacketLength, unsigned char *computed_CRC );
34 int tc_parser( ccsdsTelecommandPacket_t * TCPacket, unsigned int estimatedPacketLength, unsigned char *computed_CRC );
16 int tc_check_type( unsigned char packetType );
35 int tc_check_type( unsigned char packetType );
17 int tc_check_type_subtype( unsigned char packetType, unsigned char packetSubType );
36 int tc_check_type_subtype( unsigned char packetType, unsigned char packetSubType );
18 int tc_check_sid( unsigned char sid );
37 int tc_check_sid( unsigned char sid );
19 int tc_check_length( unsigned char packetType, unsigned int length );
38 int tc_check_length( unsigned char packetType, unsigned int length );
20 int tc_check_crc(ccsdsTelecommandPacket_t * TCPacket, unsigned int length , unsigned char *computed_CRC);
39 int tc_check_crc(ccsdsTelecommandPacket_t * TCPacket, unsigned int length , unsigned char *computed_CRC);
21
40
22 #endif // TC_ACCEPTANCE_H_INCLUDED
41 #endif // TC_ACCEPTANCE_H_INCLUDED
23
42
24
43
25
44
@@ -1,81 +1,111
1 #ifndef TC_HANDLER_H_INCLUDED
1 #ifndef TC_HANDLER_H_INCLUDED
2 #define TC_HANDLER_H_INCLUDED
2 #define TC_HANDLER_H_INCLUDED
3
3
4 #include <rtems.h>
4 #include <rtems.h>
5 #include <leon.h>
5 #include <leon.h>
6
6
7 #include "tc_load_dump_parameters.h"
7 #include "tc_load_dump_parameters.h"
8 #include "tc_acceptance.h"
8 #include "tc_acceptance.h"
9 #include "tm_lfr_tc_exe.h"
9 #include "tm_lfr_tc_exe.h"
10 #include "wf_handler.h"
10 #include "wf_handler.h"
11 #include "fsw_processing.h"
11 #include "fsw_processing.h"
12
12
13 #include "lfr_cpu_usage_report.h"
13 #include "lfr_cpu_usage_report.h"
14
14
15 #define MAX_DELTA_COARSE_TIME 3
16 #define NB_SCIENCE_TASKS 10
17 #define NB_ASM_TASKS 6
18 #define STATUS_0 0
19 #define STATUS_1 1
20 #define STATUS_2 2
21 #define STATUS_3 3
22 #define STATUS_4 4
23 #define STATUS_5 5
24 #define STATUS_6 6
25 #define STATUS_7 7
26 #define STATUS_8 8
27 #define STATUS_9 9
28
29 #define CAL_F0 625
30 #define CAL_F1 10000
31 #define CAL_FS 160256.410
32 #define CAL_SCALE_FACTOR (0.250 / 0.000654) // 191, 500 mVpp, 2 sinus waves => 500 mVpp each, amplitude = 250 mV
33 #define CAL_NB_PTS 256
34 #define CAL_DATA_MASK 0xfff
35 #define CAL_F_DIVISOR 38 // 25 MHz => 160 256 (39 - 1)
36 // INTERLEAVED MODE
37 #define CAL_FS_INTER 240384.615
38 #define CAL_NB_PTS_INTER 384
39 #define CAL_DATA_MASK_INTER 0x3f
40 #define CAL_DATA_SHIFT_INTER 12
41 #define BYTES_FOR_2_SAMPLES 3 // one need 3 bytes = 24 bits to store 3 samples of 12 bits in interleaved mode
42 #define STEPS_FOR_STORAGE_INTER 128
43 #define CAL_F_DIVISOR_INTER 26 // 25 MHz => 240 384
44
15 extern unsigned int lastValidEnterModeTime;
45 extern unsigned int lastValidEnterModeTime;
16 extern unsigned char oneTcLfrUpdateTimeReceived;
46 extern unsigned char oneTcLfrUpdateTimeReceived;
17
47
18 //****
48 //****
19 // ISR
49 // ISR
20 rtems_isr commutation_isr1( rtems_vector_number vector );
50 rtems_isr commutation_isr1( rtems_vector_number vector );
21 rtems_isr commutation_isr2( rtems_vector_number vector );
51 rtems_isr commutation_isr2( rtems_vector_number vector );
22
52
23 //***********
53 //***********
24 // RTEMS TASK
54 // RTEMS TASK
25 rtems_task actn_task( rtems_task_argument unused );
55 rtems_task actn_task( rtems_task_argument unused );
26
56
27 //***********
57 //***********
28 // TC ACTIONS
58 // TC ACTIONS
29 int action_reset( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time );
59 int action_reset( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time );
30 int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id);
60 int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id);
31 int action_update_info( ccsdsTelecommandPacket_t *TC, rtems_id queue_id );
61 int action_update_info( ccsdsTelecommandPacket_t *TC, rtems_id queue_id );
32 int action_enable_calibration( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time );
62 int action_enable_calibration( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time );
33 int action_disable_calibration( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time );
63 int action_disable_calibration( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time );
34 int action_update_time( ccsdsTelecommandPacket_t *TC);
64 int action_update_time( ccsdsTelecommandPacket_t *TC);
35
65
36 // mode transition
66 // mode transition
37 int check_mode_value( unsigned char requestedMode );
67 int check_mode_value( unsigned char requestedMode );
38 int check_mode_transition( unsigned char requestedMode );
68 int check_mode_transition( unsigned char requestedMode );
39 void update_last_valid_transition_date( unsigned int transitionCoarseTime );
69 void update_last_valid_transition_date( unsigned int transitionCoarseTime );
40 int check_transition_date( unsigned int transitionCoarseTime );
70 int check_transition_date( unsigned int transitionCoarseTime );
41 int stop_spectral_matrices( void );
71 int stop_spectral_matrices( void );
42 int stop_current_mode( void );
72 int stop_current_mode( void );
43 int enter_mode_standby(void );
73 int enter_mode_standby(void );
44 int enter_mode_normal( unsigned int transitionCoarseTime );
74 int enter_mode_normal( unsigned int transitionCoarseTime );
45 int enter_mode_burst( unsigned int transitionCoarseTime );
75 int enter_mode_burst( unsigned int transitionCoarseTime );
46 int enter_mode_sbm1( unsigned int transitionCoarseTime );
76 int enter_mode_sbm1( unsigned int transitionCoarseTime );
47 int enter_mode_sbm2( unsigned int transitionCoarseTime );
77 int enter_mode_sbm2( unsigned int transitionCoarseTime );
48 int restart_science_tasks( unsigned char lfrRequestedMode );
78 int restart_science_tasks( unsigned char lfrRequestedMode );
49 int restart_asm_tasks(unsigned char lfrRequestedMode );
79 int restart_asm_tasks(unsigned char lfrRequestedMode );
50 int suspend_science_tasks(void);
80 int suspend_science_tasks(void);
51 int suspend_asm_tasks( void );
81 int suspend_asm_tasks( void );
52 void launch_waveform_picker( unsigned char mode , unsigned int transitionCoarseTime );
82 void launch_waveform_picker( unsigned char mode , unsigned int transitionCoarseTime );
53 void launch_spectral_matrix( void );
83 void launch_spectral_matrix( void );
54 void set_sm_irq_onNewMatrix( unsigned char value );
84 void set_sm_irq_onNewMatrix( unsigned char value );
55 void set_sm_irq_onError( unsigned char value );
85 void set_sm_irq_onError( unsigned char value );
56
86
57 // other functions
87 // other functions
58 void updateLFRCurrentMode(unsigned char requestedMode);
88 void updateLFRCurrentMode(unsigned char requestedMode);
59 void set_lfr_soft_reset( unsigned char value );
89 void set_lfr_soft_reset( unsigned char value );
60 void reset_lfr( void );
90 void reset_lfr( void );
61 // CALIBRATION
91 // CALIBRATION
62 void setCalibrationPrescaler( unsigned int prescaler );
92 void setCalibrationPrescaler( unsigned int prescaler );
63 void setCalibrationDivisor( unsigned int divisionFactor );
93 void setCalibrationDivisor( unsigned int divisionFactor );
64 void setCalibrationData( void );
94 void setCalibrationData( void );
65 void setCalibrationReload( bool state);
95 void setCalibrationReload( bool state);
66 void setCalibrationEnable( bool state );
96 void setCalibrationEnable( bool state );
67 void setCalibrationInterleaved( bool state );
97 void setCalibrationInterleaved( bool state );
68 void setCalibration( bool state );
98 void setCalibration( bool state );
69 void configureCalibration( bool interleaved );
99 void configureCalibration( bool interleaved );
70 //
100 //
71 void update_last_TC_exe( ccsdsTelecommandPacket_t *TC , unsigned char *time );
101 void update_last_TC_exe( ccsdsTelecommandPacket_t *TC , unsigned char *time );
72 void update_last_TC_rej(ccsdsTelecommandPacket_t *TC , unsigned char *time );
102 void update_last_TC_rej(ccsdsTelecommandPacket_t *TC , unsigned char *time );
73 void close_action( ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id );
103 void close_action( ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id );
74
104
75 extern rtems_status_code get_message_queue_id_send( rtems_id *queue_id );
105 extern rtems_status_code get_message_queue_id_send( rtems_id *queue_id );
76 extern rtems_status_code get_message_queue_id_recv( rtems_id *queue_id );
106 extern rtems_status_code get_message_queue_id_recv( rtems_id *queue_id );
77
107
78 #endif // TC_HANDLER_H_INCLUDED
108 #endif // TC_HANDLER_H_INCLUDED
79
109
80
110
81
111
@@ -1,83 +1,101
1 #ifndef TC_LOAD_DUMP_PARAMETERS_H
1 #ifndef TC_LOAD_DUMP_PARAMETERS_H
2 #define TC_LOAD_DUMP_PARAMETERS_H
2 #define TC_LOAD_DUMP_PARAMETERS_H
3
3
4 #include <rtems.h>
4 #include <rtems.h>
5 #include <stdio.h>
5 #include <stdio.h>
6
6
7 #include "fsw_params.h"
7 #include "fsw_params.h"
8 #include "wf_handler.h"
8 #include "wf_handler.h"
9 #include "tm_lfr_tc_exe.h"
9 #include "tm_lfr_tc_exe.h"
10 #include "fsw_misc.h"
10 #include "fsw_misc.h"
11 #include "basic_parameters_params.h"
11 #include "basic_parameters_params.h"
12 #include "avf0_prc0.h"
12 #include "avf0_prc0.h"
13
13
14 #define FLOAT_EQUAL_ZERO 0.001
14 #define FLOAT_EQUAL_ZERO 0.001
15 #define NB_BINS_TO_REMOVE 3
16 #define FI_INTERVAL_COEFF 0.285
17 #define BIN_MIN 0
18 #define BIN_MAX 127
19 #define DELTAF_F0 96.
20 #define DELTAF_F1 16.
21 #define DELTAF_F2 1.
22
23 #define BIT_RW1_F1 0x80
24 #define BIT_RW1_F2 0x40
25 #define BIT_RW2_F1 0x20
26 #define BIT_RW2_F2 0x10
27 #define BIT_RW3_F1 0x08
28 #define BIT_RW3_F2 0x04
29 #define BIT_RW4_F1 0x02
30 #define BIT_RW4_F2 0x01
31
32 #define SBM_KCOEFF_PER_NORM_KCOEFF 2
15
33
16 extern unsigned short sequenceCounterParameterDump;
34 extern unsigned short sequenceCounterParameterDump;
17 extern unsigned short sequenceCounters_TM_DUMP[];
35 extern unsigned short sequenceCounters_TM_DUMP[];
18 extern float k_coeff_intercalib_f0_norm[ ];
36 extern float k_coeff_intercalib_f0_norm[ ];
19 extern float k_coeff_intercalib_f0_sbm[ ];
37 extern float k_coeff_intercalib_f0_sbm[ ];
20 extern float k_coeff_intercalib_f1_norm[ ];
38 extern float k_coeff_intercalib_f1_norm[ ];
21 extern float k_coeff_intercalib_f1_sbm[ ];
39 extern float k_coeff_intercalib_f1_sbm[ ];
22 extern float k_coeff_intercalib_f2[ ];
40 extern float k_coeff_intercalib_f2[ ];
23 extern fbins_masks_t fbins_masks;
41 extern fbins_masks_t fbins_masks;
24
42
25 int action_load_common_par( ccsdsTelecommandPacket_t *TC );
43 int action_load_common_par( ccsdsTelecommandPacket_t *TC );
26 int action_load_normal_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id , unsigned char *time);
44 int action_load_normal_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id , unsigned char *time);
27 int action_load_burst_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id , unsigned char *time);
45 int action_load_burst_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id , unsigned char *time);
28 int action_load_sbm1_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id , unsigned char *time);
46 int action_load_sbm1_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id , unsigned char *time);
29 int action_load_sbm2_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id , unsigned char *time);
47 int action_load_sbm2_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id , unsigned char *time);
30 int action_load_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time);
48 int action_load_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time);
31 int action_load_fbins_mask(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time);
49 int action_load_fbins_mask(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time);
32 int action_load_filter_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time);
50 int action_load_filter_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time);
33 int action_dump_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time);
51 int action_dump_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time);
34 int action_dump_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id );
52 int action_dump_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id );
35
53
36 // NORMAL
54 // NORMAL
37 int check_normal_par_consistency( ccsdsTelecommandPacket_t *TC, rtems_id queue_id );
55 int check_normal_par_consistency( ccsdsTelecommandPacket_t *TC, rtems_id queue_id );
38 int set_sy_lfr_n_swf_l( ccsdsTelecommandPacket_t *TC );
56 int set_sy_lfr_n_swf_l( ccsdsTelecommandPacket_t *TC );
39 int set_sy_lfr_n_swf_p( ccsdsTelecommandPacket_t *TC );
57 int set_sy_lfr_n_swf_p( ccsdsTelecommandPacket_t *TC );
40 int set_sy_lfr_n_asm_p( ccsdsTelecommandPacket_t *TC );
58 int set_sy_lfr_n_asm_p( ccsdsTelecommandPacket_t *TC );
41 int set_sy_lfr_n_bp_p0( ccsdsTelecommandPacket_t *TC );
59 int set_sy_lfr_n_bp_p0( ccsdsTelecommandPacket_t *TC );
42 int set_sy_lfr_n_bp_p1( ccsdsTelecommandPacket_t *TC );
60 int set_sy_lfr_n_bp_p1( ccsdsTelecommandPacket_t *TC );
43 int set_sy_lfr_n_cwf_long_f3( ccsdsTelecommandPacket_t *TC );
61 int set_sy_lfr_n_cwf_long_f3( ccsdsTelecommandPacket_t *TC );
44
62
45 // BURST
63 // BURST
46 int set_sy_lfr_b_bp_p0( ccsdsTelecommandPacket_t *TC );
64 int set_sy_lfr_b_bp_p0( ccsdsTelecommandPacket_t *TC );
47 int set_sy_lfr_b_bp_p1( ccsdsTelecommandPacket_t *TC );
65 int set_sy_lfr_b_bp_p1( ccsdsTelecommandPacket_t *TC );
48
66
49 // SBM1
67 // SBM1
50 int set_sy_lfr_s1_bp_p0( ccsdsTelecommandPacket_t *TC );
68 int set_sy_lfr_s1_bp_p0( ccsdsTelecommandPacket_t *TC );
51 int set_sy_lfr_s1_bp_p1( ccsdsTelecommandPacket_t *TC );
69 int set_sy_lfr_s1_bp_p1( ccsdsTelecommandPacket_t *TC );
52
70
53 // SBM2
71 // SBM2
54 int set_sy_lfr_s2_bp_p0( ccsdsTelecommandPacket_t *TC );
72 int set_sy_lfr_s2_bp_p0( ccsdsTelecommandPacket_t *TC );
55 int set_sy_lfr_s2_bp_p1( ccsdsTelecommandPacket_t *TC );
73 int set_sy_lfr_s2_bp_p1( ccsdsTelecommandPacket_t *TC );
56
74
57 // TC_LFR_UPDATE_INFO
75 // TC_LFR_UPDATE_INFO
58 unsigned int check_update_info_hk_lfr_mode( unsigned char mode );
76 unsigned int check_update_info_hk_lfr_mode( unsigned char mode );
59 unsigned int check_update_info_hk_tds_mode( unsigned char mode );
77 unsigned int check_update_info_hk_tds_mode( unsigned char mode );
60 unsigned int check_update_info_hk_thr_mode( unsigned char mode );
78 unsigned int check_update_info_hk_thr_mode( unsigned char mode );
61 void getReactionWheelsFrequencies( ccsdsTelecommandPacket_t *TC );
79 void getReactionWheelsFrequencies( ccsdsTelecommandPacket_t *TC );
62 void setFBinMask(unsigned char *fbins_mask, float rw_f, unsigned char deltaFreq, unsigned char flag );
80 void setFBinMask(unsigned char *fbins_mask, float rw_f, unsigned char deltaFreq, unsigned char flag );
63 void build_sy_lfr_rw_mask( unsigned int channel );
81 void build_sy_lfr_rw_mask( unsigned int channel );
64 void build_sy_lfr_rw_masks();
82 void build_sy_lfr_rw_masks();
65 void merge_fbins_masks( void );
83 void merge_fbins_masks( void );
66
84
67 // FBINS_MASK
85 // FBINS_MASK
68 int set_sy_lfr_fbins( ccsdsTelecommandPacket_t *TC );
86 int set_sy_lfr_fbins( ccsdsTelecommandPacket_t *TC );
69
87
70 // TC_LFR_LOAD_PARS_FILTER_PAR
88 // TC_LFR_LOAD_PARS_FILTER_PAR
71 int check_sy_lfr_filter_parameters( ccsdsTelecommandPacket_t *TC, rtems_id queue_id );
89 int check_sy_lfr_filter_parameters( ccsdsTelecommandPacket_t *TC, rtems_id queue_id );
72
90
73 // KCOEFFICIENTS
91 // KCOEFFICIENTS
74 int set_sy_lfr_kcoeff(ccsdsTelecommandPacket_t *TC , rtems_id queue_id);
92 int set_sy_lfr_kcoeff(ccsdsTelecommandPacket_t *TC , rtems_id queue_id);
75 void copyFloatByChar( unsigned char *destination, unsigned char *source );
93 void copyFloatByChar( unsigned char *destination, unsigned char *source );
76 void floatToChar( float value, unsigned char* ptr);
94 void floatToChar( float value, unsigned char* ptr);
77
95
78 void init_parameter_dump( void );
96 void init_parameter_dump( void );
79 void init_kcoefficients_dump( void );
97 void init_kcoefficients_dump( void );
80 void init_kcoefficients_dump_packet( Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump, unsigned char pkt_nr, unsigned char blk_nr );
98 void init_kcoefficients_dump_packet( Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump, unsigned char pkt_nr, unsigned char blk_nr );
81 void increment_seq_counter_destination_id_dump( unsigned char *packet_sequence_control, unsigned char destination_id );
99 void increment_seq_counter_destination_id_dump( unsigned char *packet_sequence_control, unsigned char destination_id );
82
100
83 #endif // TC_LOAD_DUMP_PARAMETERS_H
101 #endif // TC_LOAD_DUMP_PARAMETERS_H
@@ -1,89 +1,116
1 #ifndef WF_HANDLER_H_INCLUDED
1 #ifndef WF_HANDLER_H_INCLUDED
2 #define WF_HANDLER_H_INCLUDED
2 #define WF_HANDLER_H_INCLUDED
3
3
4 #include <rtems.h>
4 #include <rtems.h>
5 #include <grspw.h>
5 #include <grspw.h>
6 #include <stdio.h>
6 #include <stdio.h>
7 #include <math.h>
7 #include <math.h>
8 #include <fsw_params.h>
8 #include <fsw_params.h>
9
9
10 #include "fsw_init.h"
10 #include "fsw_init.h"
11 #include "fsw_params_wf_handler.h"
11 #include "fsw_params_wf_handler.h"
12
12
13 #define pi 3.14159265359
13 #define pi 3.14159265359
14 #define T0_IN_FINETIME ( 65536. / 24576. )
15 #define T1_IN_FINETIME ( 65536. / 4096. )
16 #define T2_IN_FINETIME ( 65536. / 256. )
17 #define T3_IN_FINETIME ( 65536. / 16. )
18
19 #define TICKS_PER_T1 16
20 #define TICKS_PER_T2 256
21 #define TICKS_PER_S 65536.
22 #define MS_PER_S 1000.
23
24 #define FREQ_F0 24576.
25 #define FREQ_F1 4096.
26 #define FREQ_F2 256.
27 #define FREQ_F3 16.
28
29 #define DELTAT_F0 2731 // (2048. / 24576. / 2.) * 65536. = 2730.667;
30 #define DELTAT_F1 16384 // (2048. / 4096. / 2.) * 65536. = 16384;
31 #define DELTAT_F2 262144 // (2048. / 256. / 2.) * 65536. = 262144;
32
33 #define OFFSET_2_BYTES 2
34
35 #define ONE_TICK_CORR_INTERVAL_0_MIN 0.5
36 #define ONE_TICK_CORR_INTERVAL_0_MAX 1.0
37 #define ONE_TICK_CORR_INTERVAL_1_MIN -1.0
38 #define ONE_TICK_CORR_INTERVAL_1_MAX -0.5
39 #define ONE_TICK_CORR 1
40 #define CORR_MULT 2
14
41
15 extern int fdSPW;
42 extern int fdSPW;
16
43
17 //*****************
44 //*****************
18 // waveform buffers
45 // waveform buffers
19 extern volatile int wf_buffer_f0[ ];
46 extern volatile int wf_buffer_f0[ ];
20 extern volatile int wf_buffer_f1[ ];
47 extern volatile int wf_buffer_f1[ ];
21 extern volatile int wf_buffer_f2[ ];
48 extern volatile int wf_buffer_f2[ ];
22 extern volatile int wf_buffer_f3[ ];
49 extern volatile int wf_buffer_f3[ ];
23
50
24 extern waveform_picker_regs_0_1_18_t *waveform_picker_regs;
51 extern waveform_picker_regs_0_1_18_t *waveform_picker_regs;
25 extern time_management_regs_t *time_management_regs;
52 extern time_management_regs_t *time_management_regs;
26 extern Packet_TM_LFR_HK_t housekeeping_packet;
53 extern Packet_TM_LFR_HK_t housekeeping_packet;
27 extern Packet_TM_LFR_PARAMETER_DUMP_t parameter_dump_packet;
54 extern Packet_TM_LFR_PARAMETER_DUMP_t parameter_dump_packet;
28 extern struct param_local_str param_local;
55 extern struct param_local_str param_local;
29
56
30 extern unsigned short sequenceCounters_SCIENCE_NORMAL_BURST;
57 extern unsigned short sequenceCounters_SCIENCE_NORMAL_BURST;
31 extern unsigned short sequenceCounters_SCIENCE_SBM1_SBM2;
58 extern unsigned short sequenceCounters_SCIENCE_SBM1_SBM2;
32
59
33 extern rtems_id Task_id[20]; /* array of task ids */
60 extern rtems_id Task_id[]; /* array of task ids */
34
61
35 extern unsigned char lfrCurrentMode;
62 extern unsigned char lfrCurrentMode;
36
63
37 //**********
64 //**********
38 // RTEMS_ISR
65 // RTEMS_ISR
39 void reset_extractSWF( void );
66 void reset_extractSWF( void );
40 rtems_isr waveforms_isr( rtems_vector_number vector );
67 rtems_isr waveforms_isr( rtems_vector_number vector );
41
68
42 //***********
69 //***********
43 // RTEMS_TASK
70 // RTEMS_TASK
44 rtems_task wfrm_task( rtems_task_argument argument );
71 rtems_task wfrm_task( rtems_task_argument argument );
45 rtems_task cwf3_task( rtems_task_argument argument );
72 rtems_task cwf3_task( rtems_task_argument argument );
46 rtems_task cwf2_task( rtems_task_argument argument );
73 rtems_task cwf2_task( rtems_task_argument argument );
47 rtems_task cwf1_task( rtems_task_argument argument );
74 rtems_task cwf1_task( rtems_task_argument argument );
48 rtems_task swbd_task( rtems_task_argument argument );
75 rtems_task swbd_task( rtems_task_argument argument );
49
76
50 //******************
77 //******************
51 // general functions
78 // general functions
52 void WFP_init_rings( void );
79 void WFP_init_rings( void );
53 void init_ring( ring_node ring[], unsigned char nbNodes, volatile int buffer[] , unsigned int bufferSize );
80 void init_ring( ring_node ring[], unsigned char nbNodes, volatile int buffer[] , unsigned int bufferSize );
54 void WFP_reset_current_ring_nodes( void );
81 void WFP_reset_current_ring_nodes( void );
55 //
82 //
56 int init_header_continuous_cwf3_light_table( Header_TM_LFR_SCIENCE_CWF_t *headerCWF );
83 int init_header_continuous_cwf3_light_table( Header_TM_LFR_SCIENCE_CWF_t *headerCWF );
57 //
84 //
58 int send_waveform_CWF3_light(ring_node *ring_node_to_send, ring_node *ring_node_cwf3_light, rtems_id queue_id );
85 int send_waveform_CWF3_light(ring_node *ring_node_to_send, ring_node *ring_node_cwf3_light, rtems_id queue_id );
59 //
86 //
60 void compute_acquisition_time(unsigned int coarseTime, unsigned int fineTime,
87 void compute_acquisition_time(unsigned int coarseTime, unsigned int fineTime,
61 unsigned int sid, unsigned char pa_lfr_pkt_nr, unsigned char *acquisitionTime );
88 unsigned int sid, unsigned char pa_lfr_pkt_nr, unsigned char *acquisitionTime );
62 void build_snapshot_from_ring(ring_node *ring_node_to_send, unsigned char frequencyChannel ,
89 void build_snapshot_from_ring(ring_node *ring_node_to_send, unsigned char frequencyChannel ,
63 unsigned long long acquisitionTimeF0_asLong, ring_node *ring_node_swf_extracted, int *swf_extracted);
90 unsigned long long acquisitionTimeF0_asLong, ring_node *ring_node_swf_extracted, int *swf_extracted);
64 double computeCorrection( unsigned char *timePtr );
91 double computeCorrection( unsigned char *timePtr );
65 void applyCorrection( double correction );
92 void applyCorrection( double correction );
66 void snapshot_resynchronization( unsigned char *timePtr );
93 void snapshot_resynchronization( unsigned char *timePtr );
67 //
94 //
68 rtems_id get_pkts_queue_id( void );
95 rtems_id get_pkts_queue_id( void );
69
96
70 //**************
97 //**************
71 // wfp registers
98 // wfp registers
72 // RESET
99 // RESET
73 void reset_wfp_burst_enable( void );
100 void reset_wfp_burst_enable( void );
74 void reset_wfp_status( void );
101 void reset_wfp_status( void );
75 void reset_wfp_buffer_addresses( void );
102 void reset_wfp_buffer_addresses( void );
76 void reset_waveform_picker_regs( void );
103 void reset_waveform_picker_regs( void );
77 // SET
104 // SET
78 void set_wfp_data_shaping(void);
105 void set_wfp_data_shaping(void);
79 void set_wfp_burst_enable_register( unsigned char mode );
106 void set_wfp_burst_enable_register( unsigned char mode );
80 void set_wfp_delta_snapshot( void );
107 void set_wfp_delta_snapshot( void );
81 void set_wfp_delta_f0_f0_2( void );
108 void set_wfp_delta_f0_f0_2( void );
82 void set_wfp_delta_f1( void );
109 void set_wfp_delta_f1( void );
83 void set_wfp_delta_f2( void );
110 void set_wfp_delta_f2( void );
84
111
85 //*****************
112 //*****************
86 // local parameters
113 // local parameters
87 void increment_seq_counter_source_id( unsigned char *packet_sequence_control, unsigned int sid );
114 void increment_seq_counter_source_id( unsigned char *packet_sequence_control, unsigned int sid );
88
115
89 #endif // WF_HANDLER_H_INCLUDED
116 #endif // WF_HANDLER_H_INCLUDED
@@ -1,35 +1,36
1 #include <drvmgr/ambapp_bus.h>
1 #include <drvmgr/ambapp_bus.h>
2 #include <drvmgr/drvmgr.h>
2 #include <drvmgr/drvmgr.h>
3 #include <ccsds_types.h>
3
4
4 // GRSPW0 resources
5 // GRSPW0 resources
5 struct drvmgr_key grlib_grspw_0n1_res[] =
6 struct drvmgr_key grlib_grspw_0n1_res[] =
6 {
7 {
7 {"txBdCnt", KEY_TYPE_INT, {(unsigned int)50}}, // 7 SWF_F0, 7 SWF_F1, 7 SWF_F2, 7 CWF_F3, 7 CWF_F1 ou 7 CWF_F2
8 {"txBdCnt", KEY_TYPE_INT, {(unsigned int)TXBDCNT}}, // 7 SWF_F0, 7 SWF_F1, 7 SWF_F2, 7 CWF_F3, 7 CWF_F1 ou 7 CWF_F2
8 {"rxBdCnt", KEY_TYPE_INT, {(unsigned int)10}},
9 {"rxBdCnt", KEY_TYPE_INT, {(unsigned int)RXBDCNT}},
9 {"txDataSize", KEY_TYPE_INT, {(unsigned int)4096}},
10 {"txDataSize", KEY_TYPE_INT, {(unsigned int)TXDATASIZE}},
10 {"txHdrSize", KEY_TYPE_INT, {(unsigned int)34}},
11 {"txHdrSize", KEY_TYPE_INT, {(unsigned int)TXHDRSIZE}},
11 {"rxPktSize", KEY_TYPE_INT, {(unsigned int)200}},
12 {"rxPktSize", KEY_TYPE_INT, {(unsigned int)RXPKTSIZE}},
12 KEY_EMPTY
13 KEY_EMPTY
13 };
14 };
14
15
15 // If RTEMS_DRVMGR_STARTUP is defined we override the "weak defaults" that is defined by the LEON3 BSP.
16 // If RTEMS_DRVMGR_STARTUP is defined we override the "weak defaults" that is defined by the LEON3 BSP.
16
17
17 //struct drvmgr_bus_res grlib_drv_resources =
18 //struct drvmgr_bus_res grlib_drv_resources =
18 //{
19 //{
19 // .next = NULL,
20 // .next = NULL,
20 // .resource = {
21 // .resource = {
21 // {DRIVER_AMBAPP_GAISLER_GRSPW_ID, 0, &grlib_grspw_0n1_res[0]},
22 // {DRIVER_AMBAPP_GAISLER_GRSPW_ID, 0, &grlib_grspw_0n1_res[0]},
22 // {DRIVER_AMBAPP_GAISLER_GRSPW_ID, 1, &grlib_grspw_0n1_res[0]},
23 // {DRIVER_AMBAPP_GAISLER_GRSPW_ID, 1, &grlib_grspw_0n1_res[0]},
23 // RES_EMPTY /* Mark end of resource array */
24 // RES_EMPTY /* Mark end of resource array */
24 // }
25 // }
25 //};
26 //};
26
27
27 struct drvmgr_bus_res grlib_drv_resources =
28 struct drvmgr_bus_res grlib_drv_resources =
28 {
29 {
29 NULL,
30 NULL,
30 {
31 {
31 {DRIVER_AMBAPP_GAISLER_GRSPW_ID, 0, &grlib_grspw_0n1_res[0]},
32 {DRIVER_AMBAPP_GAISLER_GRSPW_ID, 0, &grlib_grspw_0n1_res[0]},
32 {DRIVER_AMBAPP_GAISLER_GRSPW_ID, 1, &grlib_grspw_0n1_res[0]},
33 {DRIVER_AMBAPP_GAISLER_GRSPW_ID, 1, &grlib_grspw_0n1_res[0]},
33 RES_EMPTY /* Mark end of resource array */
34 RES_EMPTY /* Mark end of resource array */
34 }
35 }
35 };
36 };
@@ -1,98 +1,102
1 /** Global variables of the LFR flight software.
1 /** Global variables of the LFR flight software.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 * Among global variables, there are:
6 * Among global variables, there are:
7 * - RTEMS names and id.
7 * - RTEMS names and id.
8 * - APB configuration registers.
8 * - APB configuration registers.
9 * - waveforms global buffers, used by the waveform picker hardware module to store data.
9 * - waveforms global buffers, used by the waveform picker hardware module to store data.
10 * - spectral matrices buffesr, used by the hardware module to store data.
10 * - spectral matrices buffesr, used by the hardware module to store data.
11 * - variable related to LFR modes parameters.
11 * - variable related to LFR modes parameters.
12 * - the global HK packet buffer.
12 * - the global HK packet buffer.
13 * - the global dump parameter buffer.
13 * - the global dump parameter buffer.
14 *
14 *
15 */
15 */
16
16
17 #include <rtems.h>
17 #include <rtems.h>
18 #include <grspw.h>
18 #include <grspw.h>
19
19
20 #include "ccsds_types.h"
20 #include "ccsds_types.h"
21 #include "grlib_regs.h"
21 #include "grlib_regs.h"
22 #include "fsw_params.h"
22 #include "fsw_params.h"
23 #include "fsw_params_wf_handler.h"
23 #include "fsw_params_wf_handler.h"
24
24
25 #define NB_OF_TASKS 20
26 #define NB_OF_MISC_NAMES 5
27
25 // RTEMS GLOBAL VARIABLES
28 // RTEMS GLOBAL VARIABLES
26 rtems_name misc_name[5];
29 rtems_name misc_name[NB_OF_MISC_NAMES];
27 rtems_name Task_name[20]; /* array of task names */
30 rtems_name Task_name[NB_OF_TASKS]; /* array of task names */
28 rtems_id Task_id[20]; /* array of task ids */
31 rtems_id Task_id[NB_OF_TASKS]; /* array of task ids */
29 rtems_name timecode_timer_name;
32 rtems_name timecode_timer_name;
30 rtems_id timecode_timer_id;
33 rtems_id timecode_timer_id;
31 int fdSPW = 0;
34 int fdSPW = 0;
32 int fdUART = 0;
35 int fdUART = 0;
33 unsigned char lfrCurrentMode;
36 unsigned char lfrCurrentMode;
34 unsigned char pa_bia_status_info;
37 unsigned char pa_bia_status_info;
35 unsigned char thisIsAnASMRestart = 0;
38 unsigned char thisIsAnASMRestart = 0;
36 unsigned char oneTcLfrUpdateTimeReceived = 0;
39 unsigned char oneTcLfrUpdateTimeReceived = 0;
37
40
38 // WAVEFORMS GLOBAL VARIABLES // 2048 * 3 * 4 + 2 * 4 = 24576 + 8 bytes = 24584
41 // WAVEFORMS GLOBAL VARIABLES // 2048 * 3 * 4 + 2 * 4 = 24576 + 8 bytes = 24584
39 // 97 * 256 = 24832 => delta = 248 bytes = 62 words
42 // 97 * 256 = 24832 => delta = 248 bytes = 62 words
40 // WAVEFORMS GLOBAL VARIABLES // 2688 * 3 * 4 + 2 * 4 = 32256 + 8 bytes = 32264
43 // WAVEFORMS GLOBAL VARIABLES // 2688 * 3 * 4 + 2 * 4 = 32256 + 8 bytes = 32264
41 // 127 * 256 = 32512 => delta = 248 bytes = 62 words
44 // 127 * 256 = 32512 => delta = 248 bytes = 62 words
42 // F0 F1 F2 F3
45 // F0 F1 F2 F3
43 volatile int wf_buffer_f0[ NB_RING_NODES_F0 * WFRM_BUFFER ] __attribute__((aligned(0x100)));
46 volatile int wf_buffer_f0[ NB_RING_NODES_F0 * WFRM_BUFFER ] __attribute__((aligned(0x100)));
44 volatile int wf_buffer_f1[ NB_RING_NODES_F1 * WFRM_BUFFER ] __attribute__((aligned(0x100)));
47 volatile int wf_buffer_f1[ NB_RING_NODES_F1 * WFRM_BUFFER ] __attribute__((aligned(0x100)));
45 volatile int wf_buffer_f2[ NB_RING_NODES_F2 * WFRM_BUFFER ] __attribute__((aligned(0x100)));
48 volatile int wf_buffer_f2[ NB_RING_NODES_F2 * WFRM_BUFFER ] __attribute__((aligned(0x100)));
46 volatile int wf_buffer_f3[ NB_RING_NODES_F3 * WFRM_BUFFER ] __attribute__((aligned(0x100)));
49 volatile int wf_buffer_f3[ NB_RING_NODES_F3 * WFRM_BUFFER ] __attribute__((aligned(0x100)));
47
50
48 //***********************************
51 //***********************************
49 // SPECTRAL MATRICES GLOBAL VARIABLES
52 // SPECTRAL MATRICES GLOBAL VARIABLES
50
53
51 // alignment constraints for the spectral matrices buffers => the first data after the time (8 bytes) shall be aligned on 0x00
54 // alignment constraints for the spectral matrices buffers => the first data after the time (8 bytes) shall be aligned on 0x00
52 volatile int sm_f0[ NB_RING_NODES_SM_F0 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100)));
55 volatile int sm_f0[ NB_RING_NODES_SM_F0 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100)));
53 volatile int sm_f1[ NB_RING_NODES_SM_F1 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100)));
56 volatile int sm_f1[ NB_RING_NODES_SM_F1 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100)));
54 volatile int sm_f2[ NB_RING_NODES_SM_F2 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100)));
57 volatile int sm_f2[ NB_RING_NODES_SM_F2 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100)));
55
58
56 // APB CONFIGURATION REGISTERS
59 // APB CONFIGURATION REGISTERS
57 time_management_regs_t *time_management_regs = (time_management_regs_t*) REGS_ADDR_TIME_MANAGEMENT;
60 time_management_regs_t *time_management_regs = (time_management_regs_t*) REGS_ADDR_TIME_MANAGEMENT;
58 gptimer_regs_t *gptimer_regs = (gptimer_regs_t *) REGS_ADDR_GPTIMER;
61 gptimer_regs_t *gptimer_regs = (gptimer_regs_t *) REGS_ADDR_GPTIMER;
59 waveform_picker_regs_0_1_18_t *waveform_picker_regs = (waveform_picker_regs_0_1_18_t*) REGS_ADDR_WAVEFORM_PICKER;
62 waveform_picker_regs_0_1_18_t *waveform_picker_regs = (waveform_picker_regs_0_1_18_t*) REGS_ADDR_WAVEFORM_PICKER;
60 spectral_matrix_regs_t *spectral_matrix_regs = (spectral_matrix_regs_t*) REGS_ADDR_SPECTRAL_MATRIX;
63 spectral_matrix_regs_t *spectral_matrix_regs = (spectral_matrix_regs_t*) REGS_ADDR_SPECTRAL_MATRIX;
61
64
62 // MODE PARAMETERS
65 // MODE PARAMETERS
63 Packet_TM_LFR_PARAMETER_DUMP_t parameter_dump_packet;
66 Packet_TM_LFR_PARAMETER_DUMP_t parameter_dump_packet;
64 struct param_local_str param_local;
67 struct param_local_str param_local;
65 unsigned int lastValidEnterModeTime;
68 unsigned int lastValidEnterModeTime;
66
69
67 // HK PACKETS
70 // HK PACKETS
68 Packet_TM_LFR_HK_t housekeeping_packet;
71 Packet_TM_LFR_HK_t housekeeping_packet;
69 unsigned char cp_rpw_sc_rw_f_flags;
72 unsigned char cp_rpw_sc_rw_f_flags;
70 // message queues occupancy
73 // message queues occupancy
71 unsigned char hk_lfr_q_sd_fifo_size_max;
74 unsigned char hk_lfr_q_sd_fifo_size_max;
72 unsigned char hk_lfr_q_rv_fifo_size_max;
75 unsigned char hk_lfr_q_rv_fifo_size_max;
73 unsigned char hk_lfr_q_p0_fifo_size_max;
76 unsigned char hk_lfr_q_p0_fifo_size_max;
74 unsigned char hk_lfr_q_p1_fifo_size_max;
77 unsigned char hk_lfr_q_p1_fifo_size_max;
75 unsigned char hk_lfr_q_p2_fifo_size_max;
78 unsigned char hk_lfr_q_p2_fifo_size_max;
76 // sequence counters are incremented by APID (PID + CAT) and destination ID
79 // sequence counters are incremented by APID (PID + CAT) and destination ID
77 unsigned short sequenceCounters_SCIENCE_NORMAL_BURST;
80 unsigned short sequenceCounters_SCIENCE_NORMAL_BURST;
78 unsigned short sequenceCounters_SCIENCE_SBM1_SBM2;
81 unsigned short sequenceCounters_SCIENCE_SBM1_SBM2;
79 unsigned short sequenceCounters_TC_EXE[SEQ_CNT_NB_DEST_ID];
82 unsigned short sequenceCounters_TC_EXE[SEQ_CNT_NB_DEST_ID];
80 unsigned short sequenceCounters_TM_DUMP[SEQ_CNT_NB_DEST_ID];
83 unsigned short sequenceCounters_TM_DUMP[SEQ_CNT_NB_DEST_ID];
81 unsigned short sequenceCounterHK;
84 unsigned short sequenceCounterHK;
82 spw_stats grspw_stats;
85 spw_stats grspw_stats;
83
86
84 // TC_LFR_UPDATE_INFO
87 // TC_LFR_UPDATE_INFO
85 float cp_rpw_sc_rw1_f1;
88 float cp_rpw_sc_rw1_f1;
86 float cp_rpw_sc_rw1_f2;
89 float cp_rpw_sc_rw1_f2;
87 float cp_rpw_sc_rw2_f1;
90 float cp_rpw_sc_rw2_f1;
88 float cp_rpw_sc_rw2_f2;
91 float cp_rpw_sc_rw2_f2;
89 float cp_rpw_sc_rw3_f1;
92 float cp_rpw_sc_rw3_f1;
90 float cp_rpw_sc_rw3_f2;
93 float cp_rpw_sc_rw3_f2;
91 float cp_rpw_sc_rw4_f1;
94 float cp_rpw_sc_rw4_f1;
92 float cp_rpw_sc_rw4_f2;
95 float cp_rpw_sc_rw4_f2;
93
96
94 // TC_LFR_LOAD_FILTER_PAR
97 // TC_LFR_LOAD_FILTER_PAR
95 filterPar_t filterPar;
98 filterPar_t filterPar;
96
99
97 fbins_masks_t fbins_masks;
100 fbins_masks_t fbins_masks;
98 unsigned int acquisitionDurations[3] = {ACQUISITION_DURATION_F0, ACQUISITION_DURATION_F1, ACQUISITION_DURATION_F2};
101 unsigned int acquisitionDurations[NB_ACQUISITION_DURATION]
102 = {ACQUISITION_DURATION_F0, ACQUISITION_DURATION_F1, ACQUISITION_DURATION_F2};
@@ -1,938 +1,938
1 /** This is the RTEMS initialization module.
1 /** This is the RTEMS initialization module.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 * This module contains two very different information:
6 * This module contains two very different information:
7 * - specific instructions to configure the compilation of the RTEMS executive
7 * - specific instructions to configure the compilation of the RTEMS executive
8 * - functions related to the fligth softwre initialization, especially the INIT RTEMS task
8 * - functions related to the fligth softwre initialization, especially the INIT RTEMS task
9 *
9 *
10 */
10 */
11
11
12 //*************************
12 //*************************
13 // GPL reminder to be added
13 // GPL reminder to be added
14 //*************************
14 //*************************
15
15
16 #include <rtems.h>
16 #include <rtems.h>
17
17
18 /* configuration information */
18 /* configuration information */
19
19
20 #define CONFIGURE_INIT
20 #define CONFIGURE_INIT
21
21
22 #include <bsp.h> /* for device driver prototypes */
22 #include <bsp.h> /* for device driver prototypes */
23
23
24 /* configuration information */
24 /* configuration information */
25
25
26 #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
26 #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
27 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
27 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
28
28
29 #define CONFIGURE_MAXIMUM_TASKS 20
29 #define CONFIGURE_MAXIMUM_TASKS 20
30 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
30 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
31 #define CONFIGURE_EXTRA_TASK_STACKS (3 * RTEMS_MINIMUM_STACK_SIZE)
31 #define CONFIGURE_EXTRA_TASK_STACKS (3 * RTEMS_MINIMUM_STACK_SIZE)
32 #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 32
32 #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 32
33 #define CONFIGURE_INIT_TASK_PRIORITY 1 // instead of 100
33 #define CONFIGURE_INIT_TASK_PRIORITY 1 // instead of 100
34 #define CONFIGURE_INIT_TASK_MODE (RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT)
34 #define CONFIGURE_INIT_TASK_MODE (RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT)
35 #define CONFIGURE_INIT_TASK_ATTRIBUTES (RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT)
35 #define CONFIGURE_INIT_TASK_ATTRIBUTES (RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT)
36 #define CONFIGURE_MAXIMUM_DRIVERS 16
36 #define CONFIGURE_MAXIMUM_DRIVERS 16
37 #define CONFIGURE_MAXIMUM_PERIODS 5
37 #define CONFIGURE_MAXIMUM_PERIODS 5
38 #define CONFIGURE_MAXIMUM_TIMERS 5 // [spiq] [link] [spacewire_reset_link]
38 #define CONFIGURE_MAXIMUM_TIMERS 5 // [spiq] [link] [spacewire_reset_link]
39 #define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 5
39 #define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 5
40 #ifdef PRINT_STACK_REPORT
40 #ifdef PRINT_STACK_REPORT
41 #define CONFIGURE_STACK_CHECKER_ENABLED
41 #define CONFIGURE_STACK_CHECKER_ENABLED
42 #endif
42 #endif
43
43
44 #include <rtems/confdefs.h>
44 #include <rtems/confdefs.h>
45
45
46 /* If --drvmgr was enabled during the configuration of the RTEMS kernel */
46 /* If --drvmgr was enabled during the configuration of the RTEMS kernel */
47 #ifdef RTEMS_DRVMGR_STARTUP
47 #ifdef RTEMS_DRVMGR_STARTUP
48 #ifdef LEON3
48 #ifdef LEON3
49 /* Add Timer and UART Driver */
49 /* Add Timer and UART Driver */
50
50
51 #ifdef CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
51 #ifdef CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
52 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GPTIMER
52 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GPTIMER
53 #endif
53 #endif
54
54
55 #ifdef CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
55 #ifdef CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
56 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_APBUART
56 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_APBUART
57 #endif
57 #endif
58
58
59 #endif
59 #endif
60 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GRSPW /* GRSPW Driver */
60 #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GRSPW /* GRSPW Driver */
61
61
62 #include <drvmgr/drvmgr_confdefs.h>
62 #include <drvmgr/drvmgr_confdefs.h>
63 #endif
63 #endif
64
64
65 #include "fsw_init.h"
65 #include "fsw_init.h"
66 #include "fsw_config.c"
66 #include "fsw_config.c"
67 #include "GscMemoryLPP.hpp"
67 #include "GscMemoryLPP.hpp"
68
68
69 void initCache()
69 void initCache()
70 {
70 {
71 // ASI 2 contains a few control registers that have not been assigned as ancillary state registers.
71 // ASI 2 contains a few control registers that have not been assigned as ancillary state registers.
72 // These should only be read and written using 32-bit LDA/STA instructions.
72 // These should only be read and written using 32-bit LDA/STA instructions.
73 // All cache registers are accessed through load/store operations to the alternate address space (LDA/STA), using ASI = 2.
73 // All cache registers are accessed through load/store operations to the alternate address space (LDA/STA), using ASI = 2.
74 // The table below shows the register addresses:
74 // The table below shows the register addresses:
75 // 0x00 Cache control register
75 // 0x00 Cache control register
76 // 0x04 Reserved
76 // 0x04 Reserved
77 // 0x08 Instruction cache configuration register
77 // 0x08 Instruction cache configuration register
78 // 0x0C Data cache configuration register
78 // 0x0C Data cache configuration register
79
79
80 // Cache Control Register Leon3 / Leon3FT
80 // Cache Control Register Leon3 / Leon3FT
81 // 31..30 29 28 27..24 23 22 21 20..19 18 17 16
81 // 31..30 29 28 27..24 23 22 21 20..19 18 17 16
82 // RFT PS TB DS FD FI FT ST IB
82 // RFT PS TB DS FD FI FT ST IB
83 // 15 14 13..12 11..10 9..8 7..6 5 4 3..2 1..0
83 // 15 14 13..12 11..10 9..8 7..6 5 4 3..2 1..0
84 // IP DP ITE IDE DTE DDE DF IF DCS ICS
84 // IP DP ITE IDE DTE DDE DF IF DCS ICS
85
85
86 unsigned int cacheControlRegister;
86 unsigned int cacheControlRegister;
87
87
88 CCR_resetCacheControlRegister();
88 CCR_resetCacheControlRegister();
89 ASR16_resetRegisterProtectionControlRegister();
89 ASR16_resetRegisterProtectionControlRegister();
90
90
91 cacheControlRegister = CCR_getValue();
91 cacheControlRegister = CCR_getValue();
92 PRINTF1("(0) CCR - Cache Control Register = %x\n", cacheControlRegister);
92 PRINTF1("(0) CCR - Cache Control Register = %x\n", cacheControlRegister);
93 PRINTF1("(0) ASR16 = %x\n", *asr16Ptr);
93 PRINTF1("(0) ASR16 = %x\n", *asr16Ptr);
94
94
95 CCR_enableInstructionCache(); // ICS bits
95 CCR_enableInstructionCache(); // ICS bits
96 CCR_enableDataCache(); // DCS bits
96 CCR_enableDataCache(); // DCS bits
97 CCR_enableInstructionBurstFetch(); // IB bit
97 CCR_enableInstructionBurstFetch(); // IB bit
98
98
99 faultTolerantScheme();
99 faultTolerantScheme();
100
100
101 cacheControlRegister = CCR_getValue();
101 cacheControlRegister = CCR_getValue();
102 PRINTF1("(1) CCR - Cache Control Register = %x\n", cacheControlRegister);
102 PRINTF1("(1) CCR - Cache Control Register = %x\n", cacheControlRegister);
103 PRINTF1("(1) ASR16 Register protection control register = %x\n", *asr16Ptr);
103 PRINTF1("(1) ASR16 Register protection control register = %x\n", *asr16Ptr);
104
104
105 PRINTF("\n");
105 PRINTF("\n");
106 }
106 }
107
107
108 rtems_task Init( rtems_task_argument ignored )
108 rtems_task Init( rtems_task_argument ignored )
109 {
109 {
110 /** This is the RTEMS INIT taks, it is the first task launched by the system.
110 /** This is the RTEMS INIT taks, it is the first task launched by the system.
111 *
111 *
112 * @param unused is the starting argument of the RTEMS task
112 * @param unused is the starting argument of the RTEMS task
113 *
113 *
114 * The INIT task create and run all other RTEMS tasks.
114 * The INIT task create and run all other RTEMS tasks.
115 *
115 *
116 */
116 */
117
117
118 //***********
118 //***********
119 // INIT CACHE
119 // INIT CACHE
120
120
121 unsigned char *vhdlVersion;
121 unsigned char *vhdlVersion;
122
122
123 reset_lfr();
123 reset_lfr();
124
124
125 reset_local_time();
125 reset_local_time();
126
126
127 rtems_cpu_usage_reset();
127 rtems_cpu_usage_reset();
128
128
129 rtems_status_code status;
129 rtems_status_code status;
130 rtems_status_code status_spw;
130 rtems_status_code status_spw;
131 rtems_isr_entry old_isr_handler;
131 rtems_isr_entry old_isr_handler;
132
132
133 // UART settings
133 // UART settings
134 enable_apbuart_transmitter();
134 enable_apbuart_transmitter();
135 set_apbuart_scaler_reload_register(REGS_ADDR_APBUART, APBUART_SCALER_RELOAD_VALUE);
135 set_apbuart_scaler_reload_register(REGS_ADDR_APBUART, APBUART_SCALER_RELOAD_VALUE);
136
136
137 DEBUG_PRINTF("\n\n\n\n\nIn INIT *** Now the console is on port COM1\n")
137 DEBUG_PRINTF("\n\n\n\n\nIn INIT *** Now the console is on port COM1\n")
138
138
139
139
140 PRINTF("\n\n\n\n\n")
140 PRINTF("\n\n\n\n\n")
141
141
142 initCache();
142 initCache();
143
143
144 PRINTF("*************************\n")
144 PRINTF("*************************\n")
145 PRINTF("** LFR Flight Software **\n")
145 PRINTF("** LFR Flight Software **\n")
146
146
147 PRINTF1("** %d-", SW_VERSION_N1)
147 PRINTF1("** %d-", SW_VERSION_N1)
148 PRINTF1("%d-" , SW_VERSION_N2)
148 PRINTF1("%d-" , SW_VERSION_N2)
149 PRINTF1("%d-" , SW_VERSION_N3)
149 PRINTF1("%d-" , SW_VERSION_N3)
150 PRINTF1("%d **\n", SW_VERSION_N4)
150 PRINTF1("%d **\n", SW_VERSION_N4)
151
151
152 vhdlVersion = (unsigned char *) (REGS_ADDR_VHDL_VERSION);
152 vhdlVersion = (unsigned char *) (REGS_ADDR_VHDL_VERSION);
153 PRINTF("** VHDL **\n")
153 PRINTF("** VHDL **\n")
154 PRINTF1("** %d.", vhdlVersion[1])
154 PRINTF1("** %d.", vhdlVersion[1])
155 PRINTF1("%d." , vhdlVersion[2])
155 PRINTF1("%d." , vhdlVersion[2])
156 PRINTF1("%d **\n", vhdlVersion[3])
156 PRINTF1("%d **\n", vhdlVersion[3])
157 PRINTF("*************************\n")
157 PRINTF("*************************\n")
158 PRINTF("\n\n")
158 PRINTF("\n\n")
159
159
160 init_parameter_dump();
160 init_parameter_dump();
161 init_kcoefficients_dump();
161 init_kcoefficients_dump();
162 init_local_mode_parameters();
162 init_local_mode_parameters();
163 init_housekeeping_parameters();
163 init_housekeeping_parameters();
164 init_k_coefficients_prc0();
164 init_k_coefficients_prc0();
165 init_k_coefficients_prc1();
165 init_k_coefficients_prc1();
166 init_k_coefficients_prc2();
166 init_k_coefficients_prc2();
167 pa_bia_status_info = 0x00;
167 pa_bia_status_info = INIT_CHAR;
168 cp_rpw_sc_rw_f_flags = 0x00;
168 cp_rpw_sc_rw_f_flags = INIT_CHAR;
169 cp_rpw_sc_rw1_f1 = 0.0;
169 cp_rpw_sc_rw1_f1 = INIT_FLOAT;
170 cp_rpw_sc_rw1_f2 = 0.0;
170 cp_rpw_sc_rw1_f2 = INIT_FLOAT;
171 cp_rpw_sc_rw2_f1 = 0.0;
171 cp_rpw_sc_rw2_f1 = INIT_FLOAT;
172 cp_rpw_sc_rw2_f2 = 0.0;
172 cp_rpw_sc_rw2_f2 = INIT_FLOAT;
173 cp_rpw_sc_rw3_f1 = 0.0;
173 cp_rpw_sc_rw3_f1 = INIT_FLOAT;
174 cp_rpw_sc_rw3_f2 = 0.0;
174 cp_rpw_sc_rw3_f2 = INIT_FLOAT;
175 cp_rpw_sc_rw4_f1 = 0.0;
175 cp_rpw_sc_rw4_f1 = INIT_FLOAT;
176 cp_rpw_sc_rw4_f2 = 0.0;
176 cp_rpw_sc_rw4_f2 = INIT_FLOAT;
177 // initialize filtering parameters
177 // initialize filtering parameters
178 filterPar.spare_sy_lfr_pas_filter_enabled = DEFAULT_SY_LFR_PAS_FILTER_ENABLED;
178 filterPar.spare_sy_lfr_pas_filter_enabled = DEFAULT_SY_LFR_PAS_FILTER_ENABLED;
179 filterPar.sy_lfr_pas_filter_modulus = DEFAULT_SY_LFR_PAS_FILTER_MODULUS;
179 filterPar.sy_lfr_pas_filter_modulus = DEFAULT_SY_LFR_PAS_FILTER_MODULUS;
180 filterPar.sy_lfr_pas_filter_tbad = DEFAULT_SY_LFR_PAS_FILTER_TBAD;
180 filterPar.sy_lfr_pas_filter_tbad = DEFAULT_SY_LFR_PAS_FILTER_TBAD;
181 filterPar.sy_lfr_pas_filter_offset = DEFAULT_SY_LFR_PAS_FILTER_OFFSET;
181 filterPar.sy_lfr_pas_filter_offset = DEFAULT_SY_LFR_PAS_FILTER_OFFSET;
182 filterPar.sy_lfr_pas_filter_shift = DEFAULT_SY_LFR_PAS_FILTER_SHIFT;
182 filterPar.sy_lfr_pas_filter_shift = DEFAULT_SY_LFR_PAS_FILTER_SHIFT;
183 filterPar.sy_lfr_sc_rw_delta_f = DEFAULT_SY_LFR_SC_RW_DELTA_F;
183 filterPar.sy_lfr_sc_rw_delta_f = DEFAULT_SY_LFR_SC_RW_DELTA_F;
184 update_last_valid_transition_date( DEFAULT_LAST_VALID_TRANSITION_DATE );
184 update_last_valid_transition_date( DEFAULT_LAST_VALID_TRANSITION_DATE );
185
185
186 // waveform picker initialization
186 // waveform picker initialization
187 WFP_init_rings();
187 WFP_init_rings();
188 LEON_Clear_interrupt( IRQ_SPARC_GPTIMER_WATCHDOG ); // initialize the waveform rings
188 LEON_Clear_interrupt( IRQ_SPARC_GPTIMER_WATCHDOG ); // initialize the waveform rings
189 WFP_reset_current_ring_nodes();
189 WFP_reset_current_ring_nodes();
190 reset_waveform_picker_regs();
190 reset_waveform_picker_regs();
191
191
192 // spectral matrices initialization
192 // spectral matrices initialization
193 SM_init_rings(); // initialize spectral matrices rings
193 SM_init_rings(); // initialize spectral matrices rings
194 SM_reset_current_ring_nodes();
194 SM_reset_current_ring_nodes();
195 reset_spectral_matrix_regs();
195 reset_spectral_matrix_regs();
196
196
197 // configure calibration
197 // configure calibration
198 configureCalibration( false ); // true means interleaved mode, false is for normal mode
198 configureCalibration( false ); // true means interleaved mode, false is for normal mode
199
199
200 updateLFRCurrentMode( LFR_MODE_STANDBY );
200 updateLFRCurrentMode( LFR_MODE_STANDBY );
201
201
202 BOOT_PRINTF1("in INIT *** lfrCurrentMode is %d\n", lfrCurrentMode)
202 BOOT_PRINTF1("in INIT *** lfrCurrentMode is %d\n", lfrCurrentMode)
203
203
204 create_names(); // create all names
204 create_names(); // create all names
205
205
206 status = create_timecode_timer(); // create the timer used by timecode_irq_handler
206 status = create_timecode_timer(); // create the timer used by timecode_irq_handler
207 if (status != RTEMS_SUCCESSFUL)
207 if (status != RTEMS_SUCCESSFUL)
208 {
208 {
209 PRINTF1("in INIT *** ERR in create_timer_timecode, code %d", status)
209 PRINTF1("in INIT *** ERR in create_timer_timecode, code %d", status)
210 }
210 }
211
211
212 status = create_message_queues(); // create message queues
212 status = create_message_queues(); // create message queues
213 if (status != RTEMS_SUCCESSFUL)
213 if (status != RTEMS_SUCCESSFUL)
214 {
214 {
215 PRINTF1("in INIT *** ERR in create_message_queues, code %d", status)
215 PRINTF1("in INIT *** ERR in create_message_queues, code %d", status)
216 }
216 }
217
217
218 status = create_all_tasks(); // create all tasks
218 status = create_all_tasks(); // create all tasks
219 if (status != RTEMS_SUCCESSFUL)
219 if (status != RTEMS_SUCCESSFUL)
220 {
220 {
221 PRINTF1("in INIT *** ERR in create_all_tasks, code %d\n", status)
221 PRINTF1("in INIT *** ERR in create_all_tasks, code %d\n", status)
222 }
222 }
223
223
224 // **************************
224 // **************************
225 // <SPACEWIRE INITIALIZATION>
225 // <SPACEWIRE INITIALIZATION>
226 status_spw = spacewire_open_link(); // (1) open the link
226 status_spw = spacewire_open_link(); // (1) open the link
227 if ( status_spw != RTEMS_SUCCESSFUL )
227 if ( status_spw != RTEMS_SUCCESSFUL )
228 {
228 {
229 PRINTF1("in INIT *** ERR spacewire_open_link code %d\n", status_spw )
229 PRINTF1("in INIT *** ERR spacewire_open_link code %d\n", status_spw )
230 }
230 }
231
231
232 if ( status_spw == RTEMS_SUCCESSFUL ) // (2) configure the link
232 if ( status_spw == RTEMS_SUCCESSFUL ) // (2) configure the link
233 {
233 {
234 status_spw = spacewire_configure_link( fdSPW );
234 status_spw = spacewire_configure_link( fdSPW );
235 if ( status_spw != RTEMS_SUCCESSFUL )
235 if ( status_spw != RTEMS_SUCCESSFUL )
236 {
236 {
237 PRINTF1("in INIT *** ERR spacewire_configure_link code %d\n", status_spw )
237 PRINTF1("in INIT *** ERR spacewire_configure_link code %d\n", status_spw )
238 }
238 }
239 }
239 }
240
240
241 if ( status_spw == RTEMS_SUCCESSFUL) // (3) start the link
241 if ( status_spw == RTEMS_SUCCESSFUL) // (3) start the link
242 {
242 {
243 status_spw = spacewire_start_link( fdSPW );
243 status_spw = spacewire_start_link( fdSPW );
244 if ( status_spw != RTEMS_SUCCESSFUL )
244 if ( status_spw != RTEMS_SUCCESSFUL )
245 {
245 {
246 PRINTF1("in INIT *** ERR spacewire_start_link code %d\n", status_spw )
246 PRINTF1("in INIT *** ERR spacewire_start_link code %d\n", status_spw )
247 }
247 }
248 }
248 }
249 // </SPACEWIRE INITIALIZATION>
249 // </SPACEWIRE INITIALIZATION>
250 // ***************************
250 // ***************************
251
251
252 status = start_all_tasks(); // start all tasks
252 status = start_all_tasks(); // start all tasks
253 if (status != RTEMS_SUCCESSFUL)
253 if (status != RTEMS_SUCCESSFUL)
254 {
254 {
255 PRINTF1("in INIT *** ERR in start_all_tasks, code %d", status)
255 PRINTF1("in INIT *** ERR in start_all_tasks, code %d", status)
256 }
256 }
257
257
258 // start RECV and SEND *AFTER* SpaceWire Initialization, due to the timeout of the start call during the initialization
258 // start RECV and SEND *AFTER* SpaceWire Initialization, due to the timeout of the start call during the initialization
259 status = start_recv_send_tasks();
259 status = start_recv_send_tasks();
260 if ( status != RTEMS_SUCCESSFUL )
260 if ( status != RTEMS_SUCCESSFUL )
261 {
261 {
262 PRINTF1("in INIT *** ERR start_recv_send_tasks code %d\n", status )
262 PRINTF1("in INIT *** ERR start_recv_send_tasks code %d\n", status )
263 }
263 }
264
264
265 // suspend science tasks, they will be restarted later depending on the mode
265 // suspend science tasks, they will be restarted later depending on the mode
266 status = suspend_science_tasks(); // suspend science tasks (not done in stop_current_mode if current mode = STANDBY)
266 status = suspend_science_tasks(); // suspend science tasks (not done in stop_current_mode if current mode = STANDBY)
267 if (status != RTEMS_SUCCESSFUL)
267 if (status != RTEMS_SUCCESSFUL)
268 {
268 {
269 PRINTF1("in INIT *** in suspend_science_tasks *** ERR code: %d\n", status)
269 PRINTF1("in INIT *** in suspend_science_tasks *** ERR code: %d\n", status)
270 }
270 }
271
271
272 // configure IRQ handling for the waveform picker unit
272 // configure IRQ handling for the waveform picker unit
273 status = rtems_interrupt_catch( waveforms_isr,
273 status = rtems_interrupt_catch( waveforms_isr,
274 IRQ_SPARC_WAVEFORM_PICKER,
274 IRQ_SPARC_WAVEFORM_PICKER,
275 &old_isr_handler) ;
275 &old_isr_handler) ;
276 // configure IRQ handling for the spectral matrices unit
276 // configure IRQ handling for the spectral matrices unit
277 status = rtems_interrupt_catch( spectral_matrices_isr,
277 status = rtems_interrupt_catch( spectral_matrices_isr,
278 IRQ_SPARC_SPECTRAL_MATRIX,
278 IRQ_SPARC_SPECTRAL_MATRIX,
279 &old_isr_handler) ;
279 &old_isr_handler) ;
280
280
281 // if the spacewire link is not up then send an event to the SPIQ task for link recovery
281 // if the spacewire link is not up then send an event to the SPIQ task for link recovery
282 if ( status_spw != RTEMS_SUCCESSFUL )
282 if ( status_spw != RTEMS_SUCCESSFUL )
283 {
283 {
284 status = rtems_event_send( Task_id[TASKID_SPIQ], SPW_LINKERR_EVENT );
284 status = rtems_event_send( Task_id[TASKID_SPIQ], SPW_LINKERR_EVENT );
285 if ( status != RTEMS_SUCCESSFUL ) {
285 if ( status != RTEMS_SUCCESSFUL ) {
286 PRINTF1("in INIT *** ERR rtems_event_send to SPIQ code %d\n", status )
286 PRINTF1("in INIT *** ERR rtems_event_send to SPIQ code %d\n", status )
287 }
287 }
288 }
288 }
289
289
290 BOOT_PRINTF("delete INIT\n")
290 BOOT_PRINTF("delete INIT\n")
291
291
292 set_hk_lfr_sc_potential_flag( true );
292 set_hk_lfr_sc_potential_flag( true );
293
293
294 // start the timer to detect a missing spacewire timecode
294 // start the timer to detect a missing spacewire timecode
295 // the timeout is larger because the spw IP needs to receive several valid timecodes before generating a tickout
295 // the timeout is larger because the spw IP needs to receive several valid timecodes before generating a tickout
296 // if a tickout is generated, the timer is restarted
296 // if a tickout is generated, the timer is restarted
297 status = rtems_timer_fire_after( timecode_timer_id, TIMECODE_TIMER_TIMEOUT_INIT, timecode_timer_routine, NULL );
297 status = rtems_timer_fire_after( timecode_timer_id, TIMECODE_TIMER_TIMEOUT_INIT, timecode_timer_routine, NULL );
298
298
299 grspw_timecode_callback = &timecode_irq_handler;
299 grspw_timecode_callback = &timecode_irq_handler;
300
300
301 status = rtems_task_delete(RTEMS_SELF);
301 status = rtems_task_delete(RTEMS_SELF);
302
302
303 }
303 }
304
304
305 void init_local_mode_parameters( void )
305 void init_local_mode_parameters( void )
306 {
306 {
307 /** This function initialize the param_local global variable with default values.
307 /** This function initialize the param_local global variable with default values.
308 *
308 *
309 */
309 */
310
310
311 unsigned int i;
311 unsigned int i;
312
312
313 // LOCAL PARAMETERS
313 // LOCAL PARAMETERS
314
314
315 BOOT_PRINTF1("local_sbm1_nb_cwf_max %d \n", param_local.local_sbm1_nb_cwf_max)
315 BOOT_PRINTF1("local_sbm1_nb_cwf_max %d \n", param_local.local_sbm1_nb_cwf_max)
316 BOOT_PRINTF1("local_sbm2_nb_cwf_max %d \n", param_local.local_sbm2_nb_cwf_max)
316 BOOT_PRINTF1("local_sbm2_nb_cwf_max %d \n", param_local.local_sbm2_nb_cwf_max)
317
317
318 // init sequence counters
318 // init sequence counters
319
319
320 for(i = 0; i<SEQ_CNT_NB_DEST_ID; i++)
320 for(i = 0; i<SEQ_CNT_NB_DEST_ID; i++)
321 {
321 {
322 sequenceCounters_TC_EXE[i] = 0x00;
322 sequenceCounters_TC_EXE[i] = INIT_CHAR;
323 sequenceCounters_TM_DUMP[i] = 0x00;
323 sequenceCounters_TM_DUMP[i] = INIT_CHAR;
324 }
324 }
325 sequenceCounters_SCIENCE_NORMAL_BURST = 0x00;
325 sequenceCounters_SCIENCE_NORMAL_BURST = INIT_CHAR;
326 sequenceCounters_SCIENCE_SBM1_SBM2 = 0x00;
326 sequenceCounters_SCIENCE_SBM1_SBM2 = INIT_CHAR;
327 sequenceCounterHK = TM_PACKET_SEQ_CTRL_STANDALONE << 8;
327 sequenceCounterHK = TM_PACKET_SEQ_CTRL_STANDALONE << TM_PACKET_SEQ_SHIFT;
328 }
328 }
329
329
330 void reset_local_time( void )
330 void reset_local_time( void )
331 {
331 {
332 time_management_regs->ctrl = time_management_regs->ctrl | 0x02; // [0010] software reset, coarse time = 0x80000000
332 time_management_regs->ctrl = time_management_regs->ctrl | VAL_SOFTWARE_RESET; // [0010] software reset, coarse time = 0x80000000
333 }
333 }
334
334
335 void create_names( void ) // create all names for tasks and queues
335 void create_names( void ) // create all names for tasks and queues
336 {
336 {
337 /** This function creates all RTEMS names used in the software for tasks and queues.
337 /** This function creates all RTEMS names used in the software for tasks and queues.
338 *
338 *
339 * @return RTEMS directive status codes:
339 * @return RTEMS directive status codes:
340 * - RTEMS_SUCCESSFUL - successful completion
340 * - RTEMS_SUCCESSFUL - successful completion
341 *
341 *
342 */
342 */
343
343
344 // task names
344 // task names
345 Task_name[TASKID_RECV] = rtems_build_name( 'R', 'E', 'C', 'V' );
345 Task_name[TASKID_RECV] = rtems_build_name( 'R', 'E', 'C', 'V' );
346 Task_name[TASKID_ACTN] = rtems_build_name( 'A', 'C', 'T', 'N' );
346 Task_name[TASKID_ACTN] = rtems_build_name( 'A', 'C', 'T', 'N' );
347 Task_name[TASKID_SPIQ] = rtems_build_name( 'S', 'P', 'I', 'Q' );
347 Task_name[TASKID_SPIQ] = rtems_build_name( 'S', 'P', 'I', 'Q' );
348 Task_name[TASKID_LOAD] = rtems_build_name( 'L', 'O', 'A', 'D' );
348 Task_name[TASKID_LOAD] = rtems_build_name( 'L', 'O', 'A', 'D' );
349 Task_name[TASKID_AVF0] = rtems_build_name( 'A', 'V', 'F', '0' );
349 Task_name[TASKID_AVF0] = rtems_build_name( 'A', 'V', 'F', '0' );
350 Task_name[TASKID_SWBD] = rtems_build_name( 'S', 'W', 'B', 'D' );
350 Task_name[TASKID_SWBD] = rtems_build_name( 'S', 'W', 'B', 'D' );
351 Task_name[TASKID_WFRM] = rtems_build_name( 'W', 'F', 'R', 'M' );
351 Task_name[TASKID_WFRM] = rtems_build_name( 'W', 'F', 'R', 'M' );
352 Task_name[TASKID_DUMB] = rtems_build_name( 'D', 'U', 'M', 'B' );
352 Task_name[TASKID_DUMB] = rtems_build_name( 'D', 'U', 'M', 'B' );
353 Task_name[TASKID_HOUS] = rtems_build_name( 'H', 'O', 'U', 'S' );
353 Task_name[TASKID_HOUS] = rtems_build_name( 'H', 'O', 'U', 'S' );
354 Task_name[TASKID_PRC0] = rtems_build_name( 'P', 'R', 'C', '0' );
354 Task_name[TASKID_PRC0] = rtems_build_name( 'P', 'R', 'C', '0' );
355 Task_name[TASKID_CWF3] = rtems_build_name( 'C', 'W', 'F', '3' );
355 Task_name[TASKID_CWF3] = rtems_build_name( 'C', 'W', 'F', '3' );
356 Task_name[TASKID_CWF2] = rtems_build_name( 'C', 'W', 'F', '2' );
356 Task_name[TASKID_CWF2] = rtems_build_name( 'C', 'W', 'F', '2' );
357 Task_name[TASKID_CWF1] = rtems_build_name( 'C', 'W', 'F', '1' );
357 Task_name[TASKID_CWF1] = rtems_build_name( 'C', 'W', 'F', '1' );
358 Task_name[TASKID_SEND] = rtems_build_name( 'S', 'E', 'N', 'D' );
358 Task_name[TASKID_SEND] = rtems_build_name( 'S', 'E', 'N', 'D' );
359 Task_name[TASKID_LINK] = rtems_build_name( 'L', 'I', 'N', 'K' );
359 Task_name[TASKID_LINK] = rtems_build_name( 'L', 'I', 'N', 'K' );
360 Task_name[TASKID_AVF1] = rtems_build_name( 'A', 'V', 'F', '1' );
360 Task_name[TASKID_AVF1] = rtems_build_name( 'A', 'V', 'F', '1' );
361 Task_name[TASKID_PRC1] = rtems_build_name( 'P', 'R', 'C', '1' );
361 Task_name[TASKID_PRC1] = rtems_build_name( 'P', 'R', 'C', '1' );
362 Task_name[TASKID_AVF2] = rtems_build_name( 'A', 'V', 'F', '2' );
362 Task_name[TASKID_AVF2] = rtems_build_name( 'A', 'V', 'F', '2' );
363 Task_name[TASKID_PRC2] = rtems_build_name( 'P', 'R', 'C', '2' );
363 Task_name[TASKID_PRC2] = rtems_build_name( 'P', 'R', 'C', '2' );
364
364
365 // rate monotonic period names
365 // rate monotonic period names
366 name_hk_rate_monotonic = rtems_build_name( 'H', 'O', 'U', 'S' );
366 name_hk_rate_monotonic = rtems_build_name( 'H', 'O', 'U', 'S' );
367
367
368 misc_name[QUEUE_RECV] = rtems_build_name( 'Q', '_', 'R', 'V' );
368 misc_name[QUEUE_RECV] = rtems_build_name( 'Q', '_', 'R', 'V' );
369 misc_name[QUEUE_SEND] = rtems_build_name( 'Q', '_', 'S', 'D' );
369 misc_name[QUEUE_SEND] = rtems_build_name( 'Q', '_', 'S', 'D' );
370 misc_name[QUEUE_PRC0] = rtems_build_name( 'Q', '_', 'P', '0' );
370 misc_name[QUEUE_PRC0] = rtems_build_name( 'Q', '_', 'P', '0' );
371 misc_name[QUEUE_PRC1] = rtems_build_name( 'Q', '_', 'P', '1' );
371 misc_name[QUEUE_PRC1] = rtems_build_name( 'Q', '_', 'P', '1' );
372 misc_name[QUEUE_PRC2] = rtems_build_name( 'Q', '_', 'P', '2' );
372 misc_name[QUEUE_PRC2] = rtems_build_name( 'Q', '_', 'P', '2' );
373
373
374 timecode_timer_name = rtems_build_name( 'S', 'P', 'T', 'C' );
374 timecode_timer_name = rtems_build_name( 'S', 'P', 'T', 'C' );
375 }
375 }
376
376
377 int create_all_tasks( void ) // create all tasks which run in the software
377 int create_all_tasks( void ) // create all tasks which run in the software
378 {
378 {
379 /** This function creates all RTEMS tasks used in the software.
379 /** This function creates all RTEMS tasks used in the software.
380 *
380 *
381 * @return RTEMS directive status codes:
381 * @return RTEMS directive status codes:
382 * - RTEMS_SUCCESSFUL - task created successfully
382 * - RTEMS_SUCCESSFUL - task created successfully
383 * - RTEMS_INVALID_ADDRESS - id is NULL
383 * - RTEMS_INVALID_ADDRESS - id is NULL
384 * - RTEMS_INVALID_NAME - invalid task name
384 * - RTEMS_INVALID_NAME - invalid task name
385 * - RTEMS_INVALID_PRIORITY - invalid task priority
385 * - RTEMS_INVALID_PRIORITY - invalid task priority
386 * - RTEMS_MP_NOT_CONFIGURED - multiprocessing not configured
386 * - RTEMS_MP_NOT_CONFIGURED - multiprocessing not configured
387 * - RTEMS_TOO_MANY - too many tasks created
387 * - RTEMS_TOO_MANY - too many tasks created
388 * - RTEMS_UNSATISFIED - not enough memory for stack/FP context
388 * - RTEMS_UNSATISFIED - not enough memory for stack/FP context
389 * - RTEMS_TOO_MANY - too many global objects
389 * - RTEMS_TOO_MANY - too many global objects
390 *
390 *
391 */
391 */
392
392
393 rtems_status_code status;
393 rtems_status_code status;
394
394
395 //**********
395 //**********
396 // SPACEWIRE
396 // SPACEWIRE
397 // RECV
397 // RECV
398 status = rtems_task_create(
398 status = rtems_task_create(
399 Task_name[TASKID_RECV], TASK_PRIORITY_RECV, RTEMS_MINIMUM_STACK_SIZE,
399 Task_name[TASKID_RECV], TASK_PRIORITY_RECV, RTEMS_MINIMUM_STACK_SIZE,
400 RTEMS_DEFAULT_MODES,
400 RTEMS_DEFAULT_MODES,
401 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_RECV]
401 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_RECV]
402 );
402 );
403 if (status == RTEMS_SUCCESSFUL) // SEND
403 if (status == RTEMS_SUCCESSFUL) // SEND
404 {
404 {
405 status = rtems_task_create(
405 status = rtems_task_create(
406 Task_name[TASKID_SEND], TASK_PRIORITY_SEND, RTEMS_MINIMUM_STACK_SIZE * 2,
406 Task_name[TASKID_SEND], TASK_PRIORITY_SEND, RTEMS_MINIMUM_STACK_SIZE * STACK_SIZE_MULT,
407 RTEMS_DEFAULT_MODES,
407 RTEMS_DEFAULT_MODES,
408 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_SEND]
408 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_SEND]
409 );
409 );
410 }
410 }
411 if (status == RTEMS_SUCCESSFUL) // LINK
411 if (status == RTEMS_SUCCESSFUL) // LINK
412 {
412 {
413 status = rtems_task_create(
413 status = rtems_task_create(
414 Task_name[TASKID_LINK], TASK_PRIORITY_LINK, RTEMS_MINIMUM_STACK_SIZE,
414 Task_name[TASKID_LINK], TASK_PRIORITY_LINK, RTEMS_MINIMUM_STACK_SIZE,
415 RTEMS_DEFAULT_MODES,
415 RTEMS_DEFAULT_MODES,
416 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_LINK]
416 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_LINK]
417 );
417 );
418 }
418 }
419 if (status == RTEMS_SUCCESSFUL) // ACTN
419 if (status == RTEMS_SUCCESSFUL) // ACTN
420 {
420 {
421 status = rtems_task_create(
421 status = rtems_task_create(
422 Task_name[TASKID_ACTN], TASK_PRIORITY_ACTN, RTEMS_MINIMUM_STACK_SIZE,
422 Task_name[TASKID_ACTN], TASK_PRIORITY_ACTN, RTEMS_MINIMUM_STACK_SIZE,
423 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
423 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
424 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_ACTN]
424 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_ACTN]
425 );
425 );
426 }
426 }
427 if (status == RTEMS_SUCCESSFUL) // SPIQ
427 if (status == RTEMS_SUCCESSFUL) // SPIQ
428 {
428 {
429 status = rtems_task_create(
429 status = rtems_task_create(
430 Task_name[TASKID_SPIQ], TASK_PRIORITY_SPIQ, RTEMS_MINIMUM_STACK_SIZE,
430 Task_name[TASKID_SPIQ], TASK_PRIORITY_SPIQ, RTEMS_MINIMUM_STACK_SIZE,
431 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
431 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
432 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_SPIQ]
432 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_SPIQ]
433 );
433 );
434 }
434 }
435
435
436 //******************
436 //******************
437 // SPECTRAL MATRICES
437 // SPECTRAL MATRICES
438 if (status == RTEMS_SUCCESSFUL) // AVF0
438 if (status == RTEMS_SUCCESSFUL) // AVF0
439 {
439 {
440 status = rtems_task_create(
440 status = rtems_task_create(
441 Task_name[TASKID_AVF0], TASK_PRIORITY_AVF0, RTEMS_MINIMUM_STACK_SIZE,
441 Task_name[TASKID_AVF0], TASK_PRIORITY_AVF0, RTEMS_MINIMUM_STACK_SIZE,
442 RTEMS_DEFAULT_MODES,
442 RTEMS_DEFAULT_MODES,
443 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF0]
443 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF0]
444 );
444 );
445 }
445 }
446 if (status == RTEMS_SUCCESSFUL) // PRC0
446 if (status == RTEMS_SUCCESSFUL) // PRC0
447 {
447 {
448 status = rtems_task_create(
448 status = rtems_task_create(
449 Task_name[TASKID_PRC0], TASK_PRIORITY_PRC0, RTEMS_MINIMUM_STACK_SIZE * 2,
449 Task_name[TASKID_PRC0], TASK_PRIORITY_PRC0, RTEMS_MINIMUM_STACK_SIZE * STACK_SIZE_MULT,
450 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
450 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
451 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC0]
451 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC0]
452 );
452 );
453 }
453 }
454 if (status == RTEMS_SUCCESSFUL) // AVF1
454 if (status == RTEMS_SUCCESSFUL) // AVF1
455 {
455 {
456 status = rtems_task_create(
456 status = rtems_task_create(
457 Task_name[TASKID_AVF1], TASK_PRIORITY_AVF1, RTEMS_MINIMUM_STACK_SIZE,
457 Task_name[TASKID_AVF1], TASK_PRIORITY_AVF1, RTEMS_MINIMUM_STACK_SIZE,
458 RTEMS_DEFAULT_MODES,
458 RTEMS_DEFAULT_MODES,
459 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF1]
459 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF1]
460 );
460 );
461 }
461 }
462 if (status == RTEMS_SUCCESSFUL) // PRC1
462 if (status == RTEMS_SUCCESSFUL) // PRC1
463 {
463 {
464 status = rtems_task_create(
464 status = rtems_task_create(
465 Task_name[TASKID_PRC1], TASK_PRIORITY_PRC1, RTEMS_MINIMUM_STACK_SIZE * 2,
465 Task_name[TASKID_PRC1], TASK_PRIORITY_PRC1, RTEMS_MINIMUM_STACK_SIZE * STACK_SIZE_MULT,
466 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
466 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
467 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC1]
467 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC1]
468 );
468 );
469 }
469 }
470 if (status == RTEMS_SUCCESSFUL) // AVF2
470 if (status == RTEMS_SUCCESSFUL) // AVF2
471 {
471 {
472 status = rtems_task_create(
472 status = rtems_task_create(
473 Task_name[TASKID_AVF2], TASK_PRIORITY_AVF2, RTEMS_MINIMUM_STACK_SIZE,
473 Task_name[TASKID_AVF2], TASK_PRIORITY_AVF2, RTEMS_MINIMUM_STACK_SIZE,
474 RTEMS_DEFAULT_MODES,
474 RTEMS_DEFAULT_MODES,
475 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF2]
475 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF2]
476 );
476 );
477 }
477 }
478 if (status == RTEMS_SUCCESSFUL) // PRC2
478 if (status == RTEMS_SUCCESSFUL) // PRC2
479 {
479 {
480 status = rtems_task_create(
480 status = rtems_task_create(
481 Task_name[TASKID_PRC2], TASK_PRIORITY_PRC2, RTEMS_MINIMUM_STACK_SIZE * 2,
481 Task_name[TASKID_PRC2], TASK_PRIORITY_PRC2, RTEMS_MINIMUM_STACK_SIZE * STACK_SIZE_MULT,
482 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
482 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
483 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC2]
483 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC2]
484 );
484 );
485 }
485 }
486
486
487 //****************
487 //****************
488 // WAVEFORM PICKER
488 // WAVEFORM PICKER
489 if (status == RTEMS_SUCCESSFUL) // WFRM
489 if (status == RTEMS_SUCCESSFUL) // WFRM
490 {
490 {
491 status = rtems_task_create(
491 status = rtems_task_create(
492 Task_name[TASKID_WFRM], TASK_PRIORITY_WFRM, RTEMS_MINIMUM_STACK_SIZE,
492 Task_name[TASKID_WFRM], TASK_PRIORITY_WFRM, RTEMS_MINIMUM_STACK_SIZE,
493 RTEMS_DEFAULT_MODES,
493 RTEMS_DEFAULT_MODES,
494 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_WFRM]
494 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_WFRM]
495 );
495 );
496 }
496 }
497 if (status == RTEMS_SUCCESSFUL) // CWF3
497 if (status == RTEMS_SUCCESSFUL) // CWF3
498 {
498 {
499 status = rtems_task_create(
499 status = rtems_task_create(
500 Task_name[TASKID_CWF3], TASK_PRIORITY_CWF3, RTEMS_MINIMUM_STACK_SIZE,
500 Task_name[TASKID_CWF3], TASK_PRIORITY_CWF3, RTEMS_MINIMUM_STACK_SIZE,
501 RTEMS_DEFAULT_MODES,
501 RTEMS_DEFAULT_MODES,
502 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF3]
502 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF3]
503 );
503 );
504 }
504 }
505 if (status == RTEMS_SUCCESSFUL) // CWF2
505 if (status == RTEMS_SUCCESSFUL) // CWF2
506 {
506 {
507 status = rtems_task_create(
507 status = rtems_task_create(
508 Task_name[TASKID_CWF2], TASK_PRIORITY_CWF2, RTEMS_MINIMUM_STACK_SIZE,
508 Task_name[TASKID_CWF2], TASK_PRIORITY_CWF2, RTEMS_MINIMUM_STACK_SIZE,
509 RTEMS_DEFAULT_MODES,
509 RTEMS_DEFAULT_MODES,
510 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF2]
510 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF2]
511 );
511 );
512 }
512 }
513 if (status == RTEMS_SUCCESSFUL) // CWF1
513 if (status == RTEMS_SUCCESSFUL) // CWF1
514 {
514 {
515 status = rtems_task_create(
515 status = rtems_task_create(
516 Task_name[TASKID_CWF1], TASK_PRIORITY_CWF1, RTEMS_MINIMUM_STACK_SIZE,
516 Task_name[TASKID_CWF1], TASK_PRIORITY_CWF1, RTEMS_MINIMUM_STACK_SIZE,
517 RTEMS_DEFAULT_MODES,
517 RTEMS_DEFAULT_MODES,
518 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF1]
518 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF1]
519 );
519 );
520 }
520 }
521 if (status == RTEMS_SUCCESSFUL) // SWBD
521 if (status == RTEMS_SUCCESSFUL) // SWBD
522 {
522 {
523 status = rtems_task_create(
523 status = rtems_task_create(
524 Task_name[TASKID_SWBD], TASK_PRIORITY_SWBD, RTEMS_MINIMUM_STACK_SIZE,
524 Task_name[TASKID_SWBD], TASK_PRIORITY_SWBD, RTEMS_MINIMUM_STACK_SIZE,
525 RTEMS_DEFAULT_MODES,
525 RTEMS_DEFAULT_MODES,
526 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_SWBD]
526 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_SWBD]
527 );
527 );
528 }
528 }
529
529
530 //*****
530 //*****
531 // MISC
531 // MISC
532 if (status == RTEMS_SUCCESSFUL) // LOAD
532 if (status == RTEMS_SUCCESSFUL) // LOAD
533 {
533 {
534 status = rtems_task_create(
534 status = rtems_task_create(
535 Task_name[TASKID_LOAD], TASK_PRIORITY_LOAD, RTEMS_MINIMUM_STACK_SIZE,
535 Task_name[TASKID_LOAD], TASK_PRIORITY_LOAD, RTEMS_MINIMUM_STACK_SIZE,
536 RTEMS_DEFAULT_MODES,
536 RTEMS_DEFAULT_MODES,
537 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_LOAD]
537 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_LOAD]
538 );
538 );
539 }
539 }
540 if (status == RTEMS_SUCCESSFUL) // DUMB
540 if (status == RTEMS_SUCCESSFUL) // DUMB
541 {
541 {
542 status = rtems_task_create(
542 status = rtems_task_create(
543 Task_name[TASKID_DUMB], TASK_PRIORITY_DUMB, RTEMS_MINIMUM_STACK_SIZE,
543 Task_name[TASKID_DUMB], TASK_PRIORITY_DUMB, RTEMS_MINIMUM_STACK_SIZE,
544 RTEMS_DEFAULT_MODES,
544 RTEMS_DEFAULT_MODES,
545 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_DUMB]
545 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_DUMB]
546 );
546 );
547 }
547 }
548 if (status == RTEMS_SUCCESSFUL) // HOUS
548 if (status == RTEMS_SUCCESSFUL) // HOUS
549 {
549 {
550 status = rtems_task_create(
550 status = rtems_task_create(
551 Task_name[TASKID_HOUS], TASK_PRIORITY_HOUS, RTEMS_MINIMUM_STACK_SIZE,
551 Task_name[TASKID_HOUS], TASK_PRIORITY_HOUS, RTEMS_MINIMUM_STACK_SIZE,
552 RTEMS_DEFAULT_MODES,
552 RTEMS_DEFAULT_MODES,
553 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_HOUS]
553 RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_HOUS]
554 );
554 );
555 }
555 }
556
556
557 return status;
557 return status;
558 }
558 }
559
559
560 int start_recv_send_tasks( void )
560 int start_recv_send_tasks( void )
561 {
561 {
562 rtems_status_code status;
562 rtems_status_code status;
563
563
564 status = rtems_task_start( Task_id[TASKID_RECV], recv_task, 1 );
564 status = rtems_task_start( Task_id[TASKID_RECV], recv_task, 1 );
565 if (status!=RTEMS_SUCCESSFUL) {
565 if (status!=RTEMS_SUCCESSFUL) {
566 BOOT_PRINTF("in INIT *** Error starting TASK_RECV\n")
566 BOOT_PRINTF("in INIT *** Error starting TASK_RECV\n")
567 }
567 }
568
568
569 if (status == RTEMS_SUCCESSFUL) // SEND
569 if (status == RTEMS_SUCCESSFUL) // SEND
570 {
570 {
571 status = rtems_task_start( Task_id[TASKID_SEND], send_task, 1 );
571 status = rtems_task_start( Task_id[TASKID_SEND], send_task, 1 );
572 if (status!=RTEMS_SUCCESSFUL) {
572 if (status!=RTEMS_SUCCESSFUL) {
573 BOOT_PRINTF("in INIT *** Error starting TASK_SEND\n")
573 BOOT_PRINTF("in INIT *** Error starting TASK_SEND\n")
574 }
574 }
575 }
575 }
576
576
577 return status;
577 return status;
578 }
578 }
579
579
580 int start_all_tasks( void ) // start all tasks except SEND RECV and HOUS
580 int start_all_tasks( void ) // start all tasks except SEND RECV and HOUS
581 {
581 {
582 /** This function starts all RTEMS tasks used in the software.
582 /** This function starts all RTEMS tasks used in the software.
583 *
583 *
584 * @return RTEMS directive status codes:
584 * @return RTEMS directive status codes:
585 * - RTEMS_SUCCESSFUL - ask started successfully
585 * - RTEMS_SUCCESSFUL - ask started successfully
586 * - RTEMS_INVALID_ADDRESS - invalid task entry point
586 * - RTEMS_INVALID_ADDRESS - invalid task entry point
587 * - RTEMS_INVALID_ID - invalid task id
587 * - RTEMS_INVALID_ID - invalid task id
588 * - RTEMS_INCORRECT_STATE - task not in the dormant state
588 * - RTEMS_INCORRECT_STATE - task not in the dormant state
589 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot start remote task
589 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot start remote task
590 *
590 *
591 */
591 */
592 // starts all the tasks fot eh flight software
592 // starts all the tasks fot eh flight software
593
593
594 rtems_status_code status;
594 rtems_status_code status;
595
595
596 //**********
596 //**********
597 // SPACEWIRE
597 // SPACEWIRE
598 status = rtems_task_start( Task_id[TASKID_SPIQ], spiq_task, 1 );
598 status = rtems_task_start( Task_id[TASKID_SPIQ], spiq_task, 1 );
599 if (status!=RTEMS_SUCCESSFUL) {
599 if (status!=RTEMS_SUCCESSFUL) {
600 BOOT_PRINTF("in INIT *** Error starting TASK_SPIQ\n")
600 BOOT_PRINTF("in INIT *** Error starting TASK_SPIQ\n")
601 }
601 }
602
602
603 if (status == RTEMS_SUCCESSFUL) // LINK
603 if (status == RTEMS_SUCCESSFUL) // LINK
604 {
604 {
605 status = rtems_task_start( Task_id[TASKID_LINK], link_task, 1 );
605 status = rtems_task_start( Task_id[TASKID_LINK], link_task, 1 );
606 if (status!=RTEMS_SUCCESSFUL) {
606 if (status!=RTEMS_SUCCESSFUL) {
607 BOOT_PRINTF("in INIT *** Error starting TASK_LINK\n")
607 BOOT_PRINTF("in INIT *** Error starting TASK_LINK\n")
608 }
608 }
609 }
609 }
610
610
611 if (status == RTEMS_SUCCESSFUL) // ACTN
611 if (status == RTEMS_SUCCESSFUL) // ACTN
612 {
612 {
613 status = rtems_task_start( Task_id[TASKID_ACTN], actn_task, 1 );
613 status = rtems_task_start( Task_id[TASKID_ACTN], actn_task, 1 );
614 if (status!=RTEMS_SUCCESSFUL) {
614 if (status!=RTEMS_SUCCESSFUL) {
615 BOOT_PRINTF("in INIT *** Error starting TASK_ACTN\n")
615 BOOT_PRINTF("in INIT *** Error starting TASK_ACTN\n")
616 }
616 }
617 }
617 }
618
618
619 //******************
619 //******************
620 // SPECTRAL MATRICES
620 // SPECTRAL MATRICES
621 if (status == RTEMS_SUCCESSFUL) // AVF0
621 if (status == RTEMS_SUCCESSFUL) // AVF0
622 {
622 {
623 status = rtems_task_start( Task_id[TASKID_AVF0], avf0_task, LFR_MODE_STANDBY );
623 status = rtems_task_start( Task_id[TASKID_AVF0], avf0_task, LFR_MODE_STANDBY );
624 if (status!=RTEMS_SUCCESSFUL) {
624 if (status!=RTEMS_SUCCESSFUL) {
625 BOOT_PRINTF("in INIT *** Error starting TASK_AVF0\n")
625 BOOT_PRINTF("in INIT *** Error starting TASK_AVF0\n")
626 }
626 }
627 }
627 }
628 if (status == RTEMS_SUCCESSFUL) // PRC0
628 if (status == RTEMS_SUCCESSFUL) // PRC0
629 {
629 {
630 status = rtems_task_start( Task_id[TASKID_PRC0], prc0_task, LFR_MODE_STANDBY );
630 status = rtems_task_start( Task_id[TASKID_PRC0], prc0_task, LFR_MODE_STANDBY );
631 if (status!=RTEMS_SUCCESSFUL) {
631 if (status!=RTEMS_SUCCESSFUL) {
632 BOOT_PRINTF("in INIT *** Error starting TASK_PRC0\n")
632 BOOT_PRINTF("in INIT *** Error starting TASK_PRC0\n")
633 }
633 }
634 }
634 }
635 if (status == RTEMS_SUCCESSFUL) // AVF1
635 if (status == RTEMS_SUCCESSFUL) // AVF1
636 {
636 {
637 status = rtems_task_start( Task_id[TASKID_AVF1], avf1_task, LFR_MODE_STANDBY );
637 status = rtems_task_start( Task_id[TASKID_AVF1], avf1_task, LFR_MODE_STANDBY );
638 if (status!=RTEMS_SUCCESSFUL) {
638 if (status!=RTEMS_SUCCESSFUL) {
639 BOOT_PRINTF("in INIT *** Error starting TASK_AVF1\n")
639 BOOT_PRINTF("in INIT *** Error starting TASK_AVF1\n")
640 }
640 }
641 }
641 }
642 if (status == RTEMS_SUCCESSFUL) // PRC1
642 if (status == RTEMS_SUCCESSFUL) // PRC1
643 {
643 {
644 status = rtems_task_start( Task_id[TASKID_PRC1], prc1_task, LFR_MODE_STANDBY );
644 status = rtems_task_start( Task_id[TASKID_PRC1], prc1_task, LFR_MODE_STANDBY );
645 if (status!=RTEMS_SUCCESSFUL) {
645 if (status!=RTEMS_SUCCESSFUL) {
646 BOOT_PRINTF("in INIT *** Error starting TASK_PRC1\n")
646 BOOT_PRINTF("in INIT *** Error starting TASK_PRC1\n")
647 }
647 }
648 }
648 }
649 if (status == RTEMS_SUCCESSFUL) // AVF2
649 if (status == RTEMS_SUCCESSFUL) // AVF2
650 {
650 {
651 status = rtems_task_start( Task_id[TASKID_AVF2], avf2_task, 1 );
651 status = rtems_task_start( Task_id[TASKID_AVF2], avf2_task, 1 );
652 if (status!=RTEMS_SUCCESSFUL) {
652 if (status!=RTEMS_SUCCESSFUL) {
653 BOOT_PRINTF("in INIT *** Error starting TASK_AVF2\n")
653 BOOT_PRINTF("in INIT *** Error starting TASK_AVF2\n")
654 }
654 }
655 }
655 }
656 if (status == RTEMS_SUCCESSFUL) // PRC2
656 if (status == RTEMS_SUCCESSFUL) // PRC2
657 {
657 {
658 status = rtems_task_start( Task_id[TASKID_PRC2], prc2_task, 1 );
658 status = rtems_task_start( Task_id[TASKID_PRC2], prc2_task, 1 );
659 if (status!=RTEMS_SUCCESSFUL) {
659 if (status!=RTEMS_SUCCESSFUL) {
660 BOOT_PRINTF("in INIT *** Error starting TASK_PRC2\n")
660 BOOT_PRINTF("in INIT *** Error starting TASK_PRC2\n")
661 }
661 }
662 }
662 }
663
663
664 //****************
664 //****************
665 // WAVEFORM PICKER
665 // WAVEFORM PICKER
666 if (status == RTEMS_SUCCESSFUL) // WFRM
666 if (status == RTEMS_SUCCESSFUL) // WFRM
667 {
667 {
668 status = rtems_task_start( Task_id[TASKID_WFRM], wfrm_task, 1 );
668 status = rtems_task_start( Task_id[TASKID_WFRM], wfrm_task, 1 );
669 if (status!=RTEMS_SUCCESSFUL) {
669 if (status!=RTEMS_SUCCESSFUL) {
670 BOOT_PRINTF("in INIT *** Error starting TASK_WFRM\n")
670 BOOT_PRINTF("in INIT *** Error starting TASK_WFRM\n")
671 }
671 }
672 }
672 }
673 if (status == RTEMS_SUCCESSFUL) // CWF3
673 if (status == RTEMS_SUCCESSFUL) // CWF3
674 {
674 {
675 status = rtems_task_start( Task_id[TASKID_CWF3], cwf3_task, 1 );
675 status = rtems_task_start( Task_id[TASKID_CWF3], cwf3_task, 1 );
676 if (status!=RTEMS_SUCCESSFUL) {
676 if (status!=RTEMS_SUCCESSFUL) {
677 BOOT_PRINTF("in INIT *** Error starting TASK_CWF3\n")
677 BOOT_PRINTF("in INIT *** Error starting TASK_CWF3\n")
678 }
678 }
679 }
679 }
680 if (status == RTEMS_SUCCESSFUL) // CWF2
680 if (status == RTEMS_SUCCESSFUL) // CWF2
681 {
681 {
682 status = rtems_task_start( Task_id[TASKID_CWF2], cwf2_task, 1 );
682 status = rtems_task_start( Task_id[TASKID_CWF2], cwf2_task, 1 );
683 if (status!=RTEMS_SUCCESSFUL) {
683 if (status!=RTEMS_SUCCESSFUL) {
684 BOOT_PRINTF("in INIT *** Error starting TASK_CWF2\n")
684 BOOT_PRINTF("in INIT *** Error starting TASK_CWF2\n")
685 }
685 }
686 }
686 }
687 if (status == RTEMS_SUCCESSFUL) // CWF1
687 if (status == RTEMS_SUCCESSFUL) // CWF1
688 {
688 {
689 status = rtems_task_start( Task_id[TASKID_CWF1], cwf1_task, 1 );
689 status = rtems_task_start( Task_id[TASKID_CWF1], cwf1_task, 1 );
690 if (status!=RTEMS_SUCCESSFUL) {
690 if (status!=RTEMS_SUCCESSFUL) {
691 BOOT_PRINTF("in INIT *** Error starting TASK_CWF1\n")
691 BOOT_PRINTF("in INIT *** Error starting TASK_CWF1\n")
692 }
692 }
693 }
693 }
694 if (status == RTEMS_SUCCESSFUL) // SWBD
694 if (status == RTEMS_SUCCESSFUL) // SWBD
695 {
695 {
696 status = rtems_task_start( Task_id[TASKID_SWBD], swbd_task, 1 );
696 status = rtems_task_start( Task_id[TASKID_SWBD], swbd_task, 1 );
697 if (status!=RTEMS_SUCCESSFUL) {
697 if (status!=RTEMS_SUCCESSFUL) {
698 BOOT_PRINTF("in INIT *** Error starting TASK_SWBD\n")
698 BOOT_PRINTF("in INIT *** Error starting TASK_SWBD\n")
699 }
699 }
700 }
700 }
701
701
702 //*****
702 //*****
703 // MISC
703 // MISC
704 if (status == RTEMS_SUCCESSFUL) // HOUS
704 if (status == RTEMS_SUCCESSFUL) // HOUS
705 {
705 {
706 status = rtems_task_start( Task_id[TASKID_HOUS], hous_task, 1 );
706 status = rtems_task_start( Task_id[TASKID_HOUS], hous_task, 1 );
707 if (status!=RTEMS_SUCCESSFUL) {
707 if (status!=RTEMS_SUCCESSFUL) {
708 BOOT_PRINTF("in INIT *** Error starting TASK_HOUS\n")
708 BOOT_PRINTF("in INIT *** Error starting TASK_HOUS\n")
709 }
709 }
710 }
710 }
711 if (status == RTEMS_SUCCESSFUL) // DUMB
711 if (status == RTEMS_SUCCESSFUL) // DUMB
712 {
712 {
713 status = rtems_task_start( Task_id[TASKID_DUMB], dumb_task, 1 );
713 status = rtems_task_start( Task_id[TASKID_DUMB], dumb_task, 1 );
714 if (status!=RTEMS_SUCCESSFUL) {
714 if (status!=RTEMS_SUCCESSFUL) {
715 BOOT_PRINTF("in INIT *** Error starting TASK_DUMB\n")
715 BOOT_PRINTF("in INIT *** Error starting TASK_DUMB\n")
716 }
716 }
717 }
717 }
718 if (status == RTEMS_SUCCESSFUL) // LOAD
718 if (status == RTEMS_SUCCESSFUL) // LOAD
719 {
719 {
720 status = rtems_task_start( Task_id[TASKID_LOAD], load_task, 1 );
720 status = rtems_task_start( Task_id[TASKID_LOAD], load_task, 1 );
721 if (status!=RTEMS_SUCCESSFUL) {
721 if (status!=RTEMS_SUCCESSFUL) {
722 BOOT_PRINTF("in INIT *** Error starting TASK_LOAD\n")
722 BOOT_PRINTF("in INIT *** Error starting TASK_LOAD\n")
723 }
723 }
724 }
724 }
725
725
726 return status;
726 return status;
727 }
727 }
728
728
729 rtems_status_code create_message_queues( void ) // create the two message queues used in the software
729 rtems_status_code create_message_queues( void ) // create the two message queues used in the software
730 {
730 {
731 rtems_status_code status_recv;
731 rtems_status_code status_recv;
732 rtems_status_code status_send;
732 rtems_status_code status_send;
733 rtems_status_code status_q_p0;
733 rtems_status_code status_q_p0;
734 rtems_status_code status_q_p1;
734 rtems_status_code status_q_p1;
735 rtems_status_code status_q_p2;
735 rtems_status_code status_q_p2;
736 rtems_status_code ret;
736 rtems_status_code ret;
737 rtems_id queue_id;
737 rtems_id queue_id;
738
738
739 //****************************************
739 //****************************************
740 // create the queue for handling valid TCs
740 // create the queue for handling valid TCs
741 status_recv = rtems_message_queue_create( misc_name[QUEUE_RECV],
741 status_recv = rtems_message_queue_create( misc_name[QUEUE_RECV],
742 MSG_QUEUE_COUNT_RECV, CCSDS_TC_PKT_MAX_SIZE,
742 MSG_QUEUE_COUNT_RECV, CCSDS_TC_PKT_MAX_SIZE,
743 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
743 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
744 if ( status_recv != RTEMS_SUCCESSFUL ) {
744 if ( status_recv != RTEMS_SUCCESSFUL ) {
745 PRINTF1("in create_message_queues *** ERR creating QUEU queue, %d\n", status_recv)
745 PRINTF1("in create_message_queues *** ERR creating QUEU queue, %d\n", status_recv)
746 }
746 }
747
747
748 //************************************************
748 //************************************************
749 // create the queue for handling TM packet sending
749 // create the queue for handling TM packet sending
750 status_send = rtems_message_queue_create( misc_name[QUEUE_SEND],
750 status_send = rtems_message_queue_create( misc_name[QUEUE_SEND],
751 MSG_QUEUE_COUNT_SEND, MSG_QUEUE_SIZE_SEND,
751 MSG_QUEUE_COUNT_SEND, MSG_QUEUE_SIZE_SEND,
752 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
752 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
753 if ( status_send != RTEMS_SUCCESSFUL ) {
753 if ( status_send != RTEMS_SUCCESSFUL ) {
754 PRINTF1("in create_message_queues *** ERR creating PKTS queue, %d\n", status_send)
754 PRINTF1("in create_message_queues *** ERR creating PKTS queue, %d\n", status_send)
755 }
755 }
756
756
757 //*****************************************************************************
757 //*****************************************************************************
758 // create the queue for handling averaged spectral matrices for processing @ f0
758 // create the queue for handling averaged spectral matrices for processing @ f0
759 status_q_p0 = rtems_message_queue_create( misc_name[QUEUE_PRC0],
759 status_q_p0 = rtems_message_queue_create( misc_name[QUEUE_PRC0],
760 MSG_QUEUE_COUNT_PRC0, MSG_QUEUE_SIZE_PRC0,
760 MSG_QUEUE_COUNT_PRC0, MSG_QUEUE_SIZE_PRC0,
761 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
761 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
762 if ( status_q_p0 != RTEMS_SUCCESSFUL ) {
762 if ( status_q_p0 != RTEMS_SUCCESSFUL ) {
763 PRINTF1("in create_message_queues *** ERR creating Q_P0 queue, %d\n", status_q_p0)
763 PRINTF1("in create_message_queues *** ERR creating Q_P0 queue, %d\n", status_q_p0)
764 }
764 }
765
765
766 //*****************************************************************************
766 //*****************************************************************************
767 // create the queue for handling averaged spectral matrices for processing @ f1
767 // create the queue for handling averaged spectral matrices for processing @ f1
768 status_q_p1 = rtems_message_queue_create( misc_name[QUEUE_PRC1],
768 status_q_p1 = rtems_message_queue_create( misc_name[QUEUE_PRC1],
769 MSG_QUEUE_COUNT_PRC1, MSG_QUEUE_SIZE_PRC1,
769 MSG_QUEUE_COUNT_PRC1, MSG_QUEUE_SIZE_PRC1,
770 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
770 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
771 if ( status_q_p1 != RTEMS_SUCCESSFUL ) {
771 if ( status_q_p1 != RTEMS_SUCCESSFUL ) {
772 PRINTF1("in create_message_queues *** ERR creating Q_P1 queue, %d\n", status_q_p1)
772 PRINTF1("in create_message_queues *** ERR creating Q_P1 queue, %d\n", status_q_p1)
773 }
773 }
774
774
775 //*****************************************************************************
775 //*****************************************************************************
776 // create the queue for handling averaged spectral matrices for processing @ f2
776 // create the queue for handling averaged spectral matrices for processing @ f2
777 status_q_p2 = rtems_message_queue_create( misc_name[QUEUE_PRC2],
777 status_q_p2 = rtems_message_queue_create( misc_name[QUEUE_PRC2],
778 MSG_QUEUE_COUNT_PRC2, MSG_QUEUE_SIZE_PRC2,
778 MSG_QUEUE_COUNT_PRC2, MSG_QUEUE_SIZE_PRC2,
779 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
779 RTEMS_FIFO | RTEMS_LOCAL, &queue_id );
780 if ( status_q_p2 != RTEMS_SUCCESSFUL ) {
780 if ( status_q_p2 != RTEMS_SUCCESSFUL ) {
781 PRINTF1("in create_message_queues *** ERR creating Q_P2 queue, %d\n", status_q_p2)
781 PRINTF1("in create_message_queues *** ERR creating Q_P2 queue, %d\n", status_q_p2)
782 }
782 }
783
783
784 if ( status_recv != RTEMS_SUCCESSFUL )
784 if ( status_recv != RTEMS_SUCCESSFUL )
785 {
785 {
786 ret = status_recv;
786 ret = status_recv;
787 }
787 }
788 else if( status_send != RTEMS_SUCCESSFUL )
788 else if( status_send != RTEMS_SUCCESSFUL )
789 {
789 {
790 ret = status_send;
790 ret = status_send;
791 }
791 }
792 else if( status_q_p0 != RTEMS_SUCCESSFUL )
792 else if( status_q_p0 != RTEMS_SUCCESSFUL )
793 {
793 {
794 ret = status_q_p0;
794 ret = status_q_p0;
795 }
795 }
796 else if( status_q_p1 != RTEMS_SUCCESSFUL )
796 else if( status_q_p1 != RTEMS_SUCCESSFUL )
797 {
797 {
798 ret = status_q_p1;
798 ret = status_q_p1;
799 }
799 }
800 else
800 else
801 {
801 {
802 ret = status_q_p2;
802 ret = status_q_p2;
803 }
803 }
804
804
805 return ret;
805 return ret;
806 }
806 }
807
807
808 rtems_status_code create_timecode_timer( void )
808 rtems_status_code create_timecode_timer( void )
809 {
809 {
810 rtems_status_code status;
810 rtems_status_code status;
811
811
812 status = rtems_timer_create( timecode_timer_name, &timecode_timer_id );
812 status = rtems_timer_create( timecode_timer_name, &timecode_timer_id );
813
813
814 if ( status != RTEMS_SUCCESSFUL )
814 if ( status != RTEMS_SUCCESSFUL )
815 {
815 {
816 PRINTF1("in create_timer_timecode *** ERR creating SPTC timer, %d\n", status)
816 PRINTF1("in create_timer_timecode *** ERR creating SPTC timer, %d\n", status)
817 }
817 }
818 else
818 else
819 {
819 {
820 PRINTF("in create_timer_timecode *** OK creating SPTC timer\n")
820 PRINTF("in create_timer_timecode *** OK creating SPTC timer\n")
821 }
821 }
822
822
823 return status;
823 return status;
824 }
824 }
825
825
826 rtems_status_code get_message_queue_id_send( rtems_id *queue_id )
826 rtems_status_code get_message_queue_id_send( rtems_id *queue_id )
827 {
827 {
828 rtems_status_code status;
828 rtems_status_code status;
829 rtems_name queue_name;
829 rtems_name queue_name;
830
830
831 queue_name = rtems_build_name( 'Q', '_', 'S', 'D' );
831 queue_name = rtems_build_name( 'Q', '_', 'S', 'D' );
832
832
833 status = rtems_message_queue_ident( queue_name, 0, queue_id );
833 status = rtems_message_queue_ident( queue_name, 0, queue_id );
834
834
835 return status;
835 return status;
836 }
836 }
837
837
838 rtems_status_code get_message_queue_id_recv( rtems_id *queue_id )
838 rtems_status_code get_message_queue_id_recv( rtems_id *queue_id )
839 {
839 {
840 rtems_status_code status;
840 rtems_status_code status;
841 rtems_name queue_name;
841 rtems_name queue_name;
842
842
843 queue_name = rtems_build_name( 'Q', '_', 'R', 'V' );
843 queue_name = rtems_build_name( 'Q', '_', 'R', 'V' );
844
844
845 status = rtems_message_queue_ident( queue_name, 0, queue_id );
845 status = rtems_message_queue_ident( queue_name, 0, queue_id );
846
846
847 return status;
847 return status;
848 }
848 }
849
849
850 rtems_status_code get_message_queue_id_prc0( rtems_id *queue_id )
850 rtems_status_code get_message_queue_id_prc0( rtems_id *queue_id )
851 {
851 {
852 rtems_status_code status;
852 rtems_status_code status;
853 rtems_name queue_name;
853 rtems_name queue_name;
854
854
855 queue_name = rtems_build_name( 'Q', '_', 'P', '0' );
855 queue_name = rtems_build_name( 'Q', '_', 'P', '0' );
856
856
857 status = rtems_message_queue_ident( queue_name, 0, queue_id );
857 status = rtems_message_queue_ident( queue_name, 0, queue_id );
858
858
859 return status;
859 return status;
860 }
860 }
861
861
862 rtems_status_code get_message_queue_id_prc1( rtems_id *queue_id )
862 rtems_status_code get_message_queue_id_prc1( rtems_id *queue_id )
863 {
863 {
864 rtems_status_code status;
864 rtems_status_code status;
865 rtems_name queue_name;
865 rtems_name queue_name;
866
866
867 queue_name = rtems_build_name( 'Q', '_', 'P', '1' );
867 queue_name = rtems_build_name( 'Q', '_', 'P', '1' );
868
868
869 status = rtems_message_queue_ident( queue_name, 0, queue_id );
869 status = rtems_message_queue_ident( queue_name, 0, queue_id );
870
870
871 return status;
871 return status;
872 }
872 }
873
873
874 rtems_status_code get_message_queue_id_prc2( rtems_id *queue_id )
874 rtems_status_code get_message_queue_id_prc2( rtems_id *queue_id )
875 {
875 {
876 rtems_status_code status;
876 rtems_status_code status;
877 rtems_name queue_name;
877 rtems_name queue_name;
878
878
879 queue_name = rtems_build_name( 'Q', '_', 'P', '2' );
879 queue_name = rtems_build_name( 'Q', '_', 'P', '2' );
880
880
881 status = rtems_message_queue_ident( queue_name, 0, queue_id );
881 status = rtems_message_queue_ident( queue_name, 0, queue_id );
882
882
883 return status;
883 return status;
884 }
884 }
885
885
886 void update_queue_max_count( rtems_id queue_id, unsigned char*fifo_size_max )
886 void update_queue_max_count( rtems_id queue_id, unsigned char*fifo_size_max )
887 {
887 {
888 u_int32_t count;
888 u_int32_t count;
889 rtems_status_code status;
889 rtems_status_code status;
890
890
891 status = rtems_message_queue_get_number_pending( queue_id, &count );
891 status = rtems_message_queue_get_number_pending( queue_id, &count );
892
892
893 count = count + 1;
893 count = count + 1;
894
894
895 if (status != RTEMS_SUCCESSFUL)
895 if (status != RTEMS_SUCCESSFUL)
896 {
896 {
897 PRINTF1("in update_queue_max_count *** ERR = %d\n", status)
897 PRINTF1("in update_queue_max_count *** ERR = %d\n", status)
898 }
898 }
899 else
899 else
900 {
900 {
901 if (count > *fifo_size_max)
901 if (count > *fifo_size_max)
902 {
902 {
903 *fifo_size_max = count;
903 *fifo_size_max = count;
904 }
904 }
905 }
905 }
906 }
906 }
907
907
908 void init_ring(ring_node ring[], unsigned char nbNodes, volatile int buffer[], unsigned int bufferSize )
908 void init_ring(ring_node ring[], unsigned char nbNodes, volatile int buffer[], unsigned int bufferSize )
909 {
909 {
910 unsigned char i;
910 unsigned char i;
911
911
912 //***************
912 //***************
913 // BUFFER ADDRESS
913 // BUFFER ADDRESS
914 for(i=0; i<nbNodes; i++)
914 for(i=0; i<nbNodes; i++)
915 {
915 {
916 ring[i].coarseTime = 0xffffffff;
916 ring[i].coarseTime = INT32_ALL_F;
917 ring[i].fineTime = 0xffffffff;
917 ring[i].fineTime = INT32_ALL_F;
918 ring[i].sid = 0x00;
918 ring[i].sid = INIT_CHAR;
919 ring[i].status = 0x00;
919 ring[i].status = INIT_CHAR;
920 ring[i].buffer_address = (int) &buffer[ i * bufferSize ];
920 ring[i].buffer_address = (int) &buffer[ i * bufferSize ];
921 }
921 }
922
922
923 //*****
923 //*****
924 // NEXT
924 // NEXT
925 ring[ nbNodes - 1 ].next = (ring_node*) &ring[ 0 ];
925 ring[ nbNodes - 1 ].next = (ring_node*) &ring[ 0 ];
926 for(i=0; i<nbNodes-1; i++)
926 for(i=0; i<nbNodes-1; i++)
927 {
927 {
928 ring[i].next = (ring_node*) &ring[ i + 1 ];
928 ring[i].next = (ring_node*) &ring[ i + 1 ];
929 }
929 }
930
930
931 //*********
931 //*********
932 // PREVIOUS
932 // PREVIOUS
933 ring[ 0 ].previous = (ring_node*) &ring[ nbNodes - 1 ];
933 ring[ 0 ].previous = (ring_node*) &ring[ nbNodes - 1 ];
934 for(i=1; i<nbNodes; i++)
934 for(i=1; i<nbNodes; i++)
935 {
935 {
936 ring[i].previous = (ring_node*) &ring[ i - 1 ];
936 ring[i].previous = (ring_node*) &ring[ i - 1 ];
937 }
937 }
938 }
938 }
@@ -1,983 +1,993
1 /** General usage functions and RTEMS tasks.
1 /** General usage functions and RTEMS tasks.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 */
6 */
7
7
8 #include "fsw_misc.h"
8 #include "fsw_misc.h"
9
9
10 void timer_configure(unsigned char timer, unsigned int clock_divider,
10 void timer_configure(unsigned char timer, unsigned int clock_divider,
11 unsigned char interrupt_level, rtems_isr (*timer_isr)() )
11 unsigned char interrupt_level, rtems_isr (*timer_isr)() )
12 {
12 {
13 /** This function configures a GPTIMER timer instantiated in the VHDL design.
13 /** This function configures a GPTIMER timer instantiated in the VHDL design.
14 *
14 *
15 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
15 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
16 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
16 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
17 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
17 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
18 * @param interrupt_level is the interrupt level that the timer drives.
18 * @param interrupt_level is the interrupt level that the timer drives.
19 * @param timer_isr is the interrupt subroutine that will be attached to the IRQ driven by the timer.
19 * @param timer_isr is the interrupt subroutine that will be attached to the IRQ driven by the timer.
20 *
20 *
21 * Interrupt levels are described in the SPARC documentation sparcv8.pdf p.76
21 * Interrupt levels are described in the SPARC documentation sparcv8.pdf p.76
22 *
22 *
23 */
23 */
24
24
25 rtems_status_code status;
25 rtems_status_code status;
26 rtems_isr_entry old_isr_handler;
26 rtems_isr_entry old_isr_handler;
27
27
28 gptimer_regs->timer[timer].ctrl = 0x00; // reset the control register
28 gptimer_regs->timer[timer].ctrl = INIT_CHAR; // reset the control register
29
29
30 status = rtems_interrupt_catch( timer_isr, interrupt_level, &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels
30 status = rtems_interrupt_catch( timer_isr, interrupt_level, &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels
31 if (status!=RTEMS_SUCCESSFUL)
31 if (status!=RTEMS_SUCCESSFUL)
32 {
32 {
33 PRINTF("in configure_timer *** ERR rtems_interrupt_catch\n")
33 PRINTF("in configure_timer *** ERR rtems_interrupt_catch\n")
34 }
34 }
35
35
36 timer_set_clock_divider( timer, clock_divider);
36 timer_set_clock_divider( timer, clock_divider);
37 }
37 }
38
38
39 void timer_start(unsigned char timer)
39 void timer_start(unsigned char timer)
40 {
40 {
41 /** This function starts a GPTIMER timer.
41 /** This function starts a GPTIMER timer.
42 *
42 *
43 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
43 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
44 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
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 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000010; // clear pending IRQ if any
48 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_CLEAR_IRQ;
49 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000004; // LD load value from the reload register
49 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_LD;
50 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000001; // EN enable the timer
50 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_EN;
51 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000002; // RS restart
51 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_RS;
52 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000008; // IE interrupt enable
52 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_IE;
53 }
53 }
54
54
55 void timer_stop(unsigned char timer)
55 void timer_stop(unsigned char timer)
56 {
56 {
57 /** This function stops a GPTIMER timer.
57 /** This function stops a GPTIMER timer.
58 *
58 *
59 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
59 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
60 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
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 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & 0xfffffffe; // EN enable the timer
64 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & GPTIMER_EN_MASK;
65 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & 0xffffffef; // IE interrupt enable
65 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & GPTIMER_IE_MASK;
66 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000010; // clear pending IRQ if any
66 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_CLEAR_IRQ;
67 }
67 }
68
68
69 void timer_set_clock_divider(unsigned char timer, unsigned int clock_divider)
69 void timer_set_clock_divider(unsigned char timer, unsigned int clock_divider)
70 {
70 {
71 /** This function sets the clock divider of a GPTIMER timer.
71 /** This function sets the clock divider of a GPTIMER timer.
72 *
72 *
73 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
73 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
74 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
74 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
75 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
75 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
76 *
76 *
77 */
77 */
78
78
79 gptimer_regs->timer[timer].reload = clock_divider; // base clock frequency is 1 MHz
79 gptimer_regs->timer[timer].reload = clock_divider; // base clock frequency is 1 MHz
80 }
80 }
81
81
82 // WATCHDOG
82 // WATCHDOG
83
83
84 rtems_isr watchdog_isr( rtems_vector_number vector )
84 rtems_isr watchdog_isr( rtems_vector_number vector )
85 {
85 {
86 rtems_status_code status_code;
86 rtems_status_code status_code;
87
87
88 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_12 );
88 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_12 );
89
89
90 PRINTF("watchdog_isr *** this is the end, exit(0)\n");
90 PRINTF("watchdog_isr *** this is the end, exit(0)\n");
91
91
92 exit(0);
92 exit(0);
93 }
93 }
94
94
95 void watchdog_configure(void)
95 void watchdog_configure(void)
96 {
96 {
97 /** This function configure the watchdog.
97 /** This function configure the watchdog.
98 *
98 *
99 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
99 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
100 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
100 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
101 *
101 *
102 * The watchdog is a timer provided by the GPTIMER IP core of the GRLIB.
102 * The watchdog is a timer provided by the GPTIMER IP core of the GRLIB.
103 *
103 *
104 */
104 */
105
105
106 LEON_Mask_interrupt( IRQ_GPTIMER_WATCHDOG ); // mask gptimer/watchdog interrupt during configuration
106 LEON_Mask_interrupt( IRQ_GPTIMER_WATCHDOG ); // mask gptimer/watchdog interrupt during configuration
107
107
108 timer_configure( TIMER_WATCHDOG, CLKDIV_WATCHDOG, IRQ_SPARC_GPTIMER_WATCHDOG, watchdog_isr );
108 timer_configure( TIMER_WATCHDOG, CLKDIV_WATCHDOG, IRQ_SPARC_GPTIMER_WATCHDOG, watchdog_isr );
109
109
110 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG ); // clear gptimer/watchdog interrupt
110 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG ); // clear gptimer/watchdog interrupt
111 }
111 }
112
112
113 void watchdog_stop(void)
113 void watchdog_stop(void)
114 {
114 {
115 LEON_Mask_interrupt( IRQ_GPTIMER_WATCHDOG ); // mask gptimer/watchdog interrupt line
115 LEON_Mask_interrupt( IRQ_GPTIMER_WATCHDOG ); // mask gptimer/watchdog interrupt line
116 timer_stop( TIMER_WATCHDOG );
116 timer_stop( TIMER_WATCHDOG );
117 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG ); // clear gptimer/watchdog interrupt
117 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG ); // clear gptimer/watchdog interrupt
118 }
118 }
119
119
120 void watchdog_reload(void)
120 void watchdog_reload(void)
121 {
121 {
122 /** This function reloads the watchdog timer counter with the timer reload value.
122 /** This function reloads the watchdog timer counter with the timer reload value.
123 *
123 *
124 * @param void
124 * @param void
125 *
125 *
126 * @return void
126 * @return void
127 *
127 *
128 */
128 */
129
129
130 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | 0x00000004; // LD load value from the reload register
130 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_LD;
131 }
131 }
132
132
133 void watchdog_start(void)
133 void watchdog_start(void)
134 {
134 {
135 /** This function starts the watchdog timer.
135 /** This function starts the watchdog timer.
136 *
136 *
137 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
137 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
138 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
138 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
139 *
139 *
140 */
140 */
141
141
142 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG );
142 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG );
143
143
144 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | 0x00000010; // clear pending IRQ if any
144 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_CLEAR_IRQ;
145 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | 0x00000004; // LD load value from the reload register
145 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_LD;
146 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | 0x00000001; // EN enable the timer
146 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_EN;
147 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | 0x00000008; // IE interrupt enable
147 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_IE;
148
148
149 LEON_Unmask_interrupt( IRQ_GPTIMER_WATCHDOG );
149 LEON_Unmask_interrupt( IRQ_GPTIMER_WATCHDOG );
150
150
151 }
151 }
152
152
153 int enable_apbuart_transmitter( void ) // set the bit 1, TE Transmitter Enable to 1 in the APBUART control register
153 int enable_apbuart_transmitter( void ) // set the bit 1, TE Transmitter Enable to 1 in the APBUART control register
154 {
154 {
155 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART;
155 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART;
156
156
157 apbuart_regs->ctrl = APBUART_CTRL_REG_MASK_TE;
157 apbuart_regs->ctrl = APBUART_CTRL_REG_MASK_TE;
158
158
159 return 0;
159 return 0;
160 }
160 }
161
161
162 void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value)
162 void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value)
163 {
163 {
164 /** This function sets the scaler reload register of the apbuart module
164 /** This function sets the scaler reload register of the apbuart module
165 *
165 *
166 * @param regs is the address of the apbuart registers in memory
166 * @param regs is the address of the apbuart registers in memory
167 * @param value is the value that will be stored in the scaler register
167 * @param value is the value that will be stored in the scaler register
168 *
168 *
169 * The value shall be set by the software to get data on the serial interface.
169 * The value shall be set by the software to get data on the serial interface.
170 *
170 *
171 */
171 */
172
172
173 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) regs;
173 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) regs;
174
174
175 apbuart_regs->scaler = value;
175 apbuart_regs->scaler = value;
176
176
177 BOOT_PRINTF1("OK *** apbuart port scaler reload register set to 0x%x\n", value)
177 BOOT_PRINTF1("OK *** apbuart port scaler reload register set to 0x%x\n", value)
178 }
178 }
179
179
180 //************
180 //************
181 // RTEMS TASKS
181 // RTEMS TASKS
182
182
183 rtems_task load_task(rtems_task_argument argument)
183 rtems_task load_task(rtems_task_argument argument)
184 {
184 {
185 BOOT_PRINTF("in LOAD *** \n")
185 BOOT_PRINTF("in LOAD *** \n")
186
186
187 rtems_status_code status;
187 rtems_status_code status;
188 unsigned int i;
188 unsigned int i;
189 unsigned int j;
189 unsigned int j;
190 rtems_name name_watchdog_rate_monotonic; // name of the watchdog rate monotonic
190 rtems_name name_watchdog_rate_monotonic; // name of the watchdog rate monotonic
191 rtems_id watchdog_period_id; // id of the watchdog rate monotonic period
191 rtems_id watchdog_period_id; // id of the watchdog rate monotonic period
192
192
193 name_watchdog_rate_monotonic = rtems_build_name( 'L', 'O', 'A', 'D' );
193 name_watchdog_rate_monotonic = rtems_build_name( 'L', 'O', 'A', 'D' );
194
194
195 status = rtems_rate_monotonic_create( name_watchdog_rate_monotonic, &watchdog_period_id );
195 status = rtems_rate_monotonic_create( name_watchdog_rate_monotonic, &watchdog_period_id );
196 if( status != RTEMS_SUCCESSFUL ) {
196 if( status != RTEMS_SUCCESSFUL ) {
197 PRINTF1( "in LOAD *** rtems_rate_monotonic_create failed with status of %d\n", status )
197 PRINTF1( "in LOAD *** rtems_rate_monotonic_create failed with status of %d\n", status )
198 }
198 }
199
199
200 i = 0;
200 i = 0;
201 j = 0;
201 j = 0;
202
202
203 watchdog_configure();
203 watchdog_configure();
204
204
205 watchdog_start();
205 watchdog_start();
206
206
207 set_sy_lfr_watchdog_enabled( true );
207 set_sy_lfr_watchdog_enabled( true );
208
208
209 while(1){
209 while(1){
210 status = rtems_rate_monotonic_period( watchdog_period_id, WATCHDOG_PERIOD );
210 status = rtems_rate_monotonic_period( watchdog_period_id, WATCHDOG_PERIOD );
211 watchdog_reload();
211 watchdog_reload();
212 i = i + 1;
212 i = i + 1;
213 if ( i == 10 )
213 if ( i == WATCHDOG_LOOP_PRINTF )
214 {
214 {
215 i = 0;
215 i = 0;
216 j = j + 1;
216 j = j + 1;
217 PRINTF1("%d\n", j)
217 PRINTF1("%d\n", j)
218 }
218 }
219 #ifdef DEBUG_WATCHDOG
219 #ifdef DEBUG_WATCHDOG
220 if (j == 3 )
220 if (j == WATCHDOG_LOOP_DEBUG )
221 {
221 {
222 status = rtems_task_delete(RTEMS_SELF);
222 status = rtems_task_delete(RTEMS_SELF);
223 }
223 }
224 #endif
224 #endif
225 }
225 }
226 }
226 }
227
227
228 rtems_task hous_task(rtems_task_argument argument)
228 rtems_task hous_task(rtems_task_argument argument)
229 {
229 {
230 rtems_status_code status;
230 rtems_status_code status;
231 rtems_status_code spare_status;
231 rtems_status_code spare_status;
232 rtems_id queue_id;
232 rtems_id queue_id;
233 rtems_rate_monotonic_period_status period_status;
233 rtems_rate_monotonic_period_status period_status;
234
234
235 status = get_message_queue_id_send( &queue_id );
235 status = get_message_queue_id_send( &queue_id );
236 if (status != RTEMS_SUCCESSFUL)
236 if (status != RTEMS_SUCCESSFUL)
237 {
237 {
238 PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status)
238 PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status)
239 }
239 }
240
240
241 BOOT_PRINTF("in HOUS ***\n");
241 BOOT_PRINTF("in HOUS ***\n");
242
242
243 if (rtems_rate_monotonic_ident( name_hk_rate_monotonic, &HK_id) != RTEMS_SUCCESSFUL) {
243 if (rtems_rate_monotonic_ident( name_hk_rate_monotonic, &HK_id) != RTEMS_SUCCESSFUL) {
244 status = rtems_rate_monotonic_create( name_hk_rate_monotonic, &HK_id );
244 status = rtems_rate_monotonic_create( name_hk_rate_monotonic, &HK_id );
245 if( status != RTEMS_SUCCESSFUL ) {
245 if( status != RTEMS_SUCCESSFUL ) {
246 PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status );
246 PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status );
247 }
247 }
248 }
248 }
249
249
250 status = rtems_rate_monotonic_cancel(HK_id);
250 status = rtems_rate_monotonic_cancel(HK_id);
251 if( status != RTEMS_SUCCESSFUL ) {
251 if( status != RTEMS_SUCCESSFUL ) {
252 PRINTF1( "ERR *** in HOUS *** rtems_rate_monotonic_cancel(HK_id) ***code: %d\n", status );
252 PRINTF1( "ERR *** in HOUS *** rtems_rate_monotonic_cancel(HK_id) ***code: %d\n", status );
253 }
253 }
254 else {
254 else {
255 DEBUG_PRINTF("OK *** in HOUS *** rtems_rate_monotonic_cancel(HK_id)\n");
255 DEBUG_PRINTF("OK *** in HOUS *** rtems_rate_monotonic_cancel(HK_id)\n");
256 }
256 }
257
257
258 // startup phase
258 // startup phase
259 status = rtems_rate_monotonic_period( HK_id, SY_LFR_TIME_SYN_TIMEOUT_in_ticks );
259 status = rtems_rate_monotonic_period( HK_id, SY_LFR_TIME_SYN_TIMEOUT_in_ticks );
260 status = rtems_rate_monotonic_get_status( HK_id, &period_status );
260 status = rtems_rate_monotonic_get_status( HK_id, &period_status );
261 DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state)
261 DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state)
262 while(period_status.state != RATE_MONOTONIC_EXPIRED ) // after SY_LFR_TIME_SYN_TIMEOUT ms, starts HK anyway
262 while(period_status.state != RATE_MONOTONIC_EXPIRED ) // after SY_LFR_TIME_SYN_TIMEOUT ms, starts HK anyway
263 {
263 {
264 if ((time_management_regs->coarse_time & 0x80000000) == 0x00000000) // check time synchronization
264 if ((time_management_regs->coarse_time & VAL_LFR_SYNCHRONIZED) == INT32_ALL_0) // check time synchronization
265 {
265 {
266 break; // break if LFR is synchronized
266 break; // break if LFR is synchronized
267 }
267 }
268 else
268 else
269 {
269 {
270 status = rtems_rate_monotonic_get_status( HK_id, &period_status );
270 status = rtems_rate_monotonic_get_status( HK_id, &period_status );
271 // sched_yield();
271
272 status = rtems_task_wake_after( 10 ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 100 ms = 10 * 10 ms
272 status = rtems_task_wake_after( HK_SYNC_WAIT ); // wait HK_SYNCH_WAIT 100 ms = 10 * 10 ms
273 }
273 }
274 }
274 }
275 status = rtems_rate_monotonic_cancel(HK_id);
275 status = rtems_rate_monotonic_cancel(HK_id);
276 DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state)
276 DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state)
277
277
278 set_hk_lfr_reset_cause( POWER_ON );
278 set_hk_lfr_reset_cause( POWER_ON );
279
279
280 while(1){ // launch the rate monotonic task
280 while(1){ // launch the rate monotonic task
281 status = rtems_rate_monotonic_period( HK_id, HK_PERIOD );
281 status = rtems_rate_monotonic_period( HK_id, HK_PERIOD );
282 if ( status != RTEMS_SUCCESSFUL ) {
282 if ( status != RTEMS_SUCCESSFUL ) {
283 PRINTF1( "in HOUS *** ERR period: %d\n", status);
283 PRINTF1( "in HOUS *** ERR period: %d\n", status);
284 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_6 );
284 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_6 );
285 }
285 }
286 else {
286 else {
287 housekeeping_packet.packetSequenceControl[0] = (unsigned char) (sequenceCounterHK >> 8);
287 housekeeping_packet.packetSequenceControl[BYTE_0] = (unsigned char) (sequenceCounterHK >> SHIFT_1_BYTE);
288 housekeeping_packet.packetSequenceControl[1] = (unsigned char) (sequenceCounterHK );
288 housekeeping_packet.packetSequenceControl[BYTE_1] = (unsigned char) (sequenceCounterHK );
289 increment_seq_counter( &sequenceCounterHK );
289 increment_seq_counter( &sequenceCounterHK );
290
290
291 housekeeping_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
291 housekeeping_packet.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
292 housekeeping_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
292 housekeeping_packet.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
293 housekeeping_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
293 housekeeping_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
294 housekeeping_packet.time[3] = (unsigned char) (time_management_regs->coarse_time);
294 housekeeping_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
295 housekeeping_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
295 housekeeping_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
296 housekeeping_packet.time[5] = (unsigned char) (time_management_regs->fine_time);
296 housekeeping_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
297
297
298 spacewire_update_hk_lfr_link_state( &housekeeping_packet.lfr_status_word[0] );
298 spacewire_update_hk_lfr_link_state( &housekeeping_packet.lfr_status_word[0] );
299
299
300 spacewire_read_statistics();
300 spacewire_read_statistics();
301
301
302 update_hk_with_grspw_stats();
302 update_hk_with_grspw_stats();
303
303
304 set_hk_lfr_time_not_synchro();
304 set_hk_lfr_time_not_synchro();
305
305
306 housekeeping_packet.hk_lfr_q_sd_fifo_size_max = hk_lfr_q_sd_fifo_size_max;
306 housekeeping_packet.hk_lfr_q_sd_fifo_size_max = hk_lfr_q_sd_fifo_size_max;
307 housekeeping_packet.hk_lfr_q_rv_fifo_size_max = hk_lfr_q_rv_fifo_size_max;
307 housekeeping_packet.hk_lfr_q_rv_fifo_size_max = hk_lfr_q_rv_fifo_size_max;
308 housekeeping_packet.hk_lfr_q_p0_fifo_size_max = hk_lfr_q_p0_fifo_size_max;
308 housekeeping_packet.hk_lfr_q_p0_fifo_size_max = hk_lfr_q_p0_fifo_size_max;
309 housekeeping_packet.hk_lfr_q_p1_fifo_size_max = hk_lfr_q_p1_fifo_size_max;
309 housekeeping_packet.hk_lfr_q_p1_fifo_size_max = hk_lfr_q_p1_fifo_size_max;
310 housekeeping_packet.hk_lfr_q_p2_fifo_size_max = hk_lfr_q_p2_fifo_size_max;
310 housekeeping_packet.hk_lfr_q_p2_fifo_size_max = hk_lfr_q_p2_fifo_size_max;
311
311
312 housekeeping_packet.sy_lfr_common_parameters_spare = parameter_dump_packet.sy_lfr_common_parameters_spare;
312 housekeeping_packet.sy_lfr_common_parameters_spare = parameter_dump_packet.sy_lfr_common_parameters_spare;
313 housekeeping_packet.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
313 housekeeping_packet.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
314 get_temperatures( housekeeping_packet.hk_lfr_temp_scm );
314 get_temperatures( housekeeping_packet.hk_lfr_temp_scm );
315 get_v_e1_e2_f3( housekeeping_packet.hk_lfr_sc_v_f3 );
315 get_v_e1_e2_f3( housekeeping_packet.hk_lfr_sc_v_f3 );
316 get_cpu_load( (unsigned char *) &housekeeping_packet.hk_lfr_cpu_load );
316 get_cpu_load( (unsigned char *) &housekeeping_packet.hk_lfr_cpu_load );
317
317
318 hk_lfr_le_me_he_update();
318 hk_lfr_le_me_he_update();
319
319
320 housekeeping_packet.hk_lfr_sc_rw_f_flags = cp_rpw_sc_rw_f_flags;
320 housekeeping_packet.hk_lfr_sc_rw_f_flags = cp_rpw_sc_rw_f_flags;
321
321
322 // SEND PACKET
322 // SEND PACKET
323 status = rtems_message_queue_send( queue_id, &housekeeping_packet,
323 status = rtems_message_queue_send( queue_id, &housekeeping_packet,
324 PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
324 PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
325 if (status != RTEMS_SUCCESSFUL) {
325 if (status != RTEMS_SUCCESSFUL) {
326 PRINTF1("in HOUS *** ERR send: %d\n", status)
326 PRINTF1("in HOUS *** ERR send: %d\n", status)
327 }
327 }
328 }
328 }
329 }
329 }
330
330
331 PRINTF("in HOUS *** deleting task\n")
331 PRINTF("in HOUS *** deleting task\n")
332
332
333 status = rtems_task_delete( RTEMS_SELF ); // should not return
333 status = rtems_task_delete( RTEMS_SELF ); // should not return
334
334
335 return;
335 return;
336 }
336 }
337
337
338 rtems_task avgv_task(rtems_task_argument argument)
338 rtems_task avgv_task(rtems_task_argument argument)
339 {
339 {
340 #define MOVING_AVERAGE 16
340 #define MOVING_AVERAGE 16
341 rtems_status_code status;
341 rtems_status_code status;
342 unsigned int v[MOVING_AVERAGE];
342 unsigned int v[MOVING_AVERAGE];
343 unsigned int e1[MOVING_AVERAGE];
343 unsigned int e1[MOVING_AVERAGE];
344 unsigned int e2[MOVING_AVERAGE];
344 unsigned int e2[MOVING_AVERAGE];
345 float average_v;
345 float average_v;
346 float average_e1;
346 float average_e1;
347 float average_e2;
347 float average_e2;
348 unsigned char k;
348 unsigned char k;
349 unsigned char indexOfOldValue;
349 unsigned char indexOfOldValue;
350
350
351 BOOT_PRINTF("in AVGV ***\n");
351 BOOT_PRINTF("in AVGV ***\n");
352
352
353 if (rtems_rate_monotonic_ident( name_avgv_rate_monotonic, &HK_id) != RTEMS_SUCCESSFUL) {
353 if (rtems_rate_monotonic_ident( name_avgv_rate_monotonic, &HK_id) != RTEMS_SUCCESSFUL) {
354 status = rtems_rate_monotonic_create( name_avgv_rate_monotonic, &AVGV_id );
354 status = rtems_rate_monotonic_create( name_avgv_rate_monotonic, &AVGV_id );
355 if( status != RTEMS_SUCCESSFUL ) {
355 if( status != RTEMS_SUCCESSFUL ) {
356 PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status );
356 PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status );
357 }
357 }
358 }
358 }
359
359
360 status = rtems_rate_monotonic_cancel(AVGV_id);
360 status = rtems_rate_monotonic_cancel(AVGV_id);
361 if( status != RTEMS_SUCCESSFUL ) {
361 if( status != RTEMS_SUCCESSFUL ) {
362 PRINTF1( "ERR *** in AVGV *** rtems_rate_monotonic_cancel(AVGV_id) ***code: %d\n", status );
362 PRINTF1( "ERR *** in AVGV *** rtems_rate_monotonic_cancel(AVGV_id) ***code: %d\n", status );
363 }
363 }
364 else {
364 else {
365 DEBUG_PRINTF("OK *** in AVGV *** rtems_rate_monotonic_cancel(AVGV_id)\n");
365 DEBUG_PRINTF("OK *** in AVGV *** rtems_rate_monotonic_cancel(AVGV_id)\n");
366 }
366 }
367
367
368 // initialize values
368 // initialize values
369 k = 0;
369 k = 0;
370 indexOfOldValue = MOVING_AVERAGE - 1;
370 indexOfOldValue = MOVING_AVERAGE - 1;
371 for (k = 0; k < MOVING_AVERAGE; k++)
371 for (k = 0; k < MOVING_AVERAGE; k++)
372 {
372 {
373 v[k] = 0;
373 v[k] = 0;
374 e1[k] = 0;
374 e1[k] = 0;
375 e2[k] = 0;
375 e2[k] = 0;
376 average_v = 0.;
376 average_v = 0.;
377 average_e1 = 0.;
377 average_e1 = 0.;
378 average_e2 = 0.;
378 average_e2 = 0.;
379 }
379 }
380
380
381 k = 0;
381 k = 0;
382
382
383 while(1){ // launch the rate monotonic task
383 while(1){ // launch the rate monotonic task
384 status = rtems_rate_monotonic_period( AVGV_id, AVGV_PERIOD );
384 status = rtems_rate_monotonic_period( AVGV_id, AVGV_PERIOD );
385 if ( status != RTEMS_SUCCESSFUL ) {
385 if ( status != RTEMS_SUCCESSFUL ) {
386 PRINTF1( "in AVGV *** ERR period: %d\n", status);
386 PRINTF1( "in AVGV *** ERR period: %d\n", status);
387 }
387 }
388 else {
388 else {
389 // store new value in buffer
389 // store new value in buffer
390 v[k] = waveform_picker_regs->v;
390 v[k] = waveform_picker_regs->v;
391 e1[k] = waveform_picker_regs->e1;
391 e1[k] = waveform_picker_regs->e1;
392 e2[k] = waveform_picker_regs->e2;
392 e2[k] = waveform_picker_regs->e2;
393 if (k == (MOVING_AVERAGE - 1))
393 if (k == (MOVING_AVERAGE - 1))
394 {
394 {
395 indexOfOldValue = 0;
395 indexOfOldValue = 0;
396 }
396 }
397 else
397 else
398 {
398 {
399 indexOfOldValue = k + 1;
399 indexOfOldValue = k + 1;
400 }
400 }
401 average_v = average_v + v[k] - v[indexOfOldValue];
401 average_v = average_v + v[k] - v[indexOfOldValue];
402 average_e1 = average_e1 + e1[k] - e1[indexOfOldValue];
402 average_e1 = average_e1 + e1[k] - e1[indexOfOldValue];
403 average_e2 = average_e2 + e2[k] - e2[indexOfOldValue];
403 average_e2 = average_e2 + e2[k] - e2[indexOfOldValue];
404 }
404 }
405 if (k == (MOVING_AVERAGE-1))
405 if (k == (MOVING_AVERAGE-1))
406 {
406 {
407 k = 0;
407 k = 0;
408 printf("tick\n");
408 printf("tick\n");
409 }
409 }
410 else
410 else
411 {
411 {
412 k++;
412 k++;
413 }
413 }
414 }
414 }
415
415
416 PRINTF("in AVGV *** deleting task\n")
416 PRINTF("in AVGV *** deleting task\n")
417
417
418 status = rtems_task_delete( RTEMS_SELF ); // should not return
418 status = rtems_task_delete( RTEMS_SELF ); // should not return
419
419
420 return;
420 return;
421 }
421 }
422
422
423 rtems_task dumb_task( rtems_task_argument unused )
423 rtems_task dumb_task( rtems_task_argument unused )
424 {
424 {
425 /** This RTEMS taks is used to print messages without affecting the general behaviour of the software.
425 /** This RTEMS taks is used to print messages without affecting the general behaviour of the software.
426 *
426 *
427 * @param unused is the starting argument of the RTEMS task
427 * @param unused is the starting argument of the RTEMS task
428 *
428 *
429 * The DUMB taks waits for RTEMS events and print messages depending on the incoming events.
429 * The DUMB taks waits for RTEMS events and print messages depending on the incoming events.
430 *
430 *
431 */
431 */
432
432
433 unsigned int i;
433 unsigned int i;
434 unsigned int intEventOut;
434 unsigned int intEventOut;
435 unsigned int coarse_time = 0;
435 unsigned int coarse_time = 0;
436 unsigned int fine_time = 0;
436 unsigned int fine_time = 0;
437 rtems_event_set event_out;
437 rtems_event_set event_out;
438
438
439 char *DumbMessages[15] = {"in DUMB *** default", // RTEMS_EVENT_0
439 char *DumbMessages[DUMB_MESSAGE_NB] = {DUMB_MESSAGE_0, // RTEMS_EVENT_0
440 "in DUMB *** timecode_irq_handler", // RTEMS_EVENT_1
440 DUMB_MESSAGE_1, // RTEMS_EVENT_1
441 "in DUMB *** f3 buffer changed", // RTEMS_EVENT_2
441 DUMB_MESSAGE_2, // RTEMS_EVENT_2
442 "in DUMB *** in SMIQ *** Error sending event to AVF0", // RTEMS_EVENT_3
442 DUMB_MESSAGE_3, // RTEMS_EVENT_3
443 "in DUMB *** spectral_matrices_isr *** Error sending event to SMIQ", // RTEMS_EVENT_4
443 DUMB_MESSAGE_4, // RTEMS_EVENT_4
444 "in DUMB *** waveforms_simulator_isr", // RTEMS_EVENT_5
444 DUMB_MESSAGE_5, // RTEMS_EVENT_5
445 "VHDL SM *** two buffers f0 ready", // RTEMS_EVENT_6
445 DUMB_MESSAGE_6, // RTEMS_EVENT_6
446 "ready for dump", // RTEMS_EVENT_7
446 DUMB_MESSAGE_7, // RTEMS_EVENT_7
447 "VHDL ERR *** spectral matrix", // RTEMS_EVENT_8
447 DUMB_MESSAGE_8, // RTEMS_EVENT_8
448 "tick", // RTEMS_EVENT_9
448 DUMB_MESSAGE_9, // RTEMS_EVENT_9
449 "VHDL ERR *** waveform picker", // RTEMS_EVENT_10
449 DUMB_MESSAGE_10, // RTEMS_EVENT_10
450 "VHDL ERR *** unexpected ready matrix values", // RTEMS_EVENT_11
450 DUMB_MESSAGE_11, // RTEMS_EVENT_11
451 "WATCHDOG timer", // RTEMS_EVENT_12
451 DUMB_MESSAGE_12, // RTEMS_EVENT_12
452 "TIMECODE timer", // RTEMS_EVENT_13
452 DUMB_MESSAGE_13, // RTEMS_EVENT_13
453 "TIMECODE ISR" // RTEMS_EVENT_14
453 DUMB_MESSAGE_14 // RTEMS_EVENT_14
454 };
454 };
455
455
456 BOOT_PRINTF("in DUMB *** \n")
456 BOOT_PRINTF("in DUMB *** \n")
457
457
458 while(1){
458 while(1){
459 rtems_event_receive(RTEMS_EVENT_0 | RTEMS_EVENT_1 | RTEMS_EVENT_2 | RTEMS_EVENT_3
459 rtems_event_receive(RTEMS_EVENT_0 | RTEMS_EVENT_1 | RTEMS_EVENT_2 | RTEMS_EVENT_3
460 | RTEMS_EVENT_4 | RTEMS_EVENT_5 | RTEMS_EVENT_6 | RTEMS_EVENT_7
460 | RTEMS_EVENT_4 | RTEMS_EVENT_5 | RTEMS_EVENT_6 | RTEMS_EVENT_7
461 | RTEMS_EVENT_8 | RTEMS_EVENT_9 | RTEMS_EVENT_12 | RTEMS_EVENT_13
461 | RTEMS_EVENT_8 | RTEMS_EVENT_9 | RTEMS_EVENT_12 | RTEMS_EVENT_13
462 | RTEMS_EVENT_14,
462 | RTEMS_EVENT_14,
463 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT
463 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT
464 intEventOut = (unsigned int) event_out;
464 intEventOut = (unsigned int) event_out;
465 for ( i=0; i<32; i++)
465 for ( i=0; i<NB_RTEMS_EVENTS; i++)
466 {
466 {
467 if ( ((intEventOut >> i) & 0x0001) != 0)
467 if ( ((intEventOut >> i) & 1) != 0)
468 {
468 {
469 coarse_time = time_management_regs->coarse_time;
469 coarse_time = time_management_regs->coarse_time;
470 fine_time = time_management_regs->fine_time;
470 fine_time = time_management_regs->fine_time;
471 if (i==12)
471 if (i==EVENT_12)
472 {
472 {
473 PRINTF1("%s\n", DumbMessages[12])
473 PRINTF1("%s\n", DUMB_MESSAGE_12)
474 }
474 }
475 if (i==13)
475 if (i==EVENT_13)
476 {
476 {
477 PRINTF1("%s\n", DumbMessages[13])
477 PRINTF1("%s\n", DUMB_MESSAGE_13)
478 }
478 }
479 if (i==14)
479 if (i==EVENT_14)
480 {
480 {
481 PRINTF1("%s\n", DumbMessages[1])
481 PRINTF1("%s\n", DUMB_MESSAGE_1)
482 }
482 }
483 }
483 }
484 }
484 }
485 }
485 }
486 }
486 }
487
487
488 //*****************************
488 //*****************************
489 // init housekeeping parameters
489 // init housekeeping parameters
490
490
491 void init_housekeeping_parameters( void )
491 void init_housekeeping_parameters( void )
492 {
492 {
493 /** This function initialize the housekeeping_packet global variable with default values.
493 /** This function initialize the housekeeping_packet global variable with default values.
494 *
494 *
495 */
495 */
496
496
497 unsigned int i = 0;
497 unsigned int i = 0;
498 unsigned char *parameters;
498 unsigned char *parameters;
499 unsigned char sizeOfHK;
499 unsigned char sizeOfHK;
500
500
501 sizeOfHK = sizeof( Packet_TM_LFR_HK_t );
501 sizeOfHK = sizeof( Packet_TM_LFR_HK_t );
502
502
503 parameters = (unsigned char*) &housekeeping_packet;
503 parameters = (unsigned char*) &housekeeping_packet;
504
504
505 for(i = 0; i< sizeOfHK; i++)
505 for(i = 0; i< sizeOfHK; i++)
506 {
506 {
507 parameters[i] = 0x00;
507 parameters[i] = INIT_CHAR;
508 }
508 }
509
509
510 housekeeping_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
510 housekeeping_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
511 housekeeping_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
511 housekeeping_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
512 housekeeping_packet.reserved = DEFAULT_RESERVED;
512 housekeeping_packet.reserved = DEFAULT_RESERVED;
513 housekeeping_packet.userApplication = CCSDS_USER_APP;
513 housekeeping_packet.userApplication = CCSDS_USER_APP;
514 housekeeping_packet.packetID[0] = (unsigned char) (APID_TM_HK >> 8);
514 housekeeping_packet.packetID[0] = (unsigned char) (APID_TM_HK >> SHIFT_1_BYTE);
515 housekeeping_packet.packetID[1] = (unsigned char) (APID_TM_HK);
515 housekeeping_packet.packetID[1] = (unsigned char) (APID_TM_HK);
516 housekeeping_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
516 housekeeping_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
517 housekeeping_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
517 housekeeping_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
518 housekeeping_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> 8);
518 housekeeping_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> SHIFT_1_BYTE);
519 housekeeping_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK );
519 housekeeping_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK );
520 housekeeping_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
520 housekeeping_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
521 housekeeping_packet.serviceType = TM_TYPE_HK;
521 housekeeping_packet.serviceType = TM_TYPE_HK;
522 housekeeping_packet.serviceSubType = TM_SUBTYPE_HK;
522 housekeeping_packet.serviceSubType = TM_SUBTYPE_HK;
523 housekeeping_packet.destinationID = TM_DESTINATION_ID_GROUND;
523 housekeeping_packet.destinationID = TM_DESTINATION_ID_GROUND;
524 housekeeping_packet.sid = SID_HK;
524 housekeeping_packet.sid = SID_HK;
525
525
526 // init status word
526 // init status word
527 housekeeping_packet.lfr_status_word[0] = DEFAULT_STATUS_WORD_BYTE0;
527 housekeeping_packet.lfr_status_word[0] = DEFAULT_STATUS_WORD_BYTE0;
528 housekeeping_packet.lfr_status_word[1] = DEFAULT_STATUS_WORD_BYTE1;
528 housekeeping_packet.lfr_status_word[1] = DEFAULT_STATUS_WORD_BYTE1;
529 // init software version
529 // init software version
530 housekeeping_packet.lfr_sw_version[0] = SW_VERSION_N1;
530 housekeeping_packet.lfr_sw_version[0] = SW_VERSION_N1;
531 housekeeping_packet.lfr_sw_version[1] = SW_VERSION_N2;
531 housekeeping_packet.lfr_sw_version[1] = SW_VERSION_N2;
532 housekeeping_packet.lfr_sw_version[2] = SW_VERSION_N3;
532 housekeeping_packet.lfr_sw_version[BYTE_2] = SW_VERSION_N3;
533 housekeeping_packet.lfr_sw_version[3] = SW_VERSION_N4;
533 housekeeping_packet.lfr_sw_version[BYTE_3] = SW_VERSION_N4;
534 // init fpga version
534 // init fpga version
535 parameters = (unsigned char *) (REGS_ADDR_VHDL_VERSION);
535 parameters = (unsigned char *) (REGS_ADDR_VHDL_VERSION);
536 housekeeping_packet.lfr_fpga_version[0] = parameters[1]; // n1
536 housekeeping_packet.lfr_fpga_version[BYTE_0] = parameters[BYTE_1]; // n1
537 housekeeping_packet.lfr_fpga_version[1] = parameters[2]; // n2
537 housekeeping_packet.lfr_fpga_version[BYTE_1] = parameters[BYTE_2]; // n2
538 housekeeping_packet.lfr_fpga_version[2] = parameters[3]; // n3
538 housekeeping_packet.lfr_fpga_version[BYTE_2] = parameters[BYTE_3]; // n3
539
539
540 housekeeping_packet.hk_lfr_q_sd_fifo_size = MSG_QUEUE_COUNT_SEND;
540 housekeeping_packet.hk_lfr_q_sd_fifo_size = MSG_QUEUE_COUNT_SEND;
541 housekeeping_packet.hk_lfr_q_rv_fifo_size = MSG_QUEUE_COUNT_RECV;
541 housekeeping_packet.hk_lfr_q_rv_fifo_size = MSG_QUEUE_COUNT_RECV;
542 housekeeping_packet.hk_lfr_q_p0_fifo_size = MSG_QUEUE_COUNT_PRC0;
542 housekeeping_packet.hk_lfr_q_p0_fifo_size = MSG_QUEUE_COUNT_PRC0;
543 housekeeping_packet.hk_lfr_q_p1_fifo_size = MSG_QUEUE_COUNT_PRC1;
543 housekeeping_packet.hk_lfr_q_p1_fifo_size = MSG_QUEUE_COUNT_PRC1;
544 housekeeping_packet.hk_lfr_q_p2_fifo_size = MSG_QUEUE_COUNT_PRC2;
544 housekeeping_packet.hk_lfr_q_p2_fifo_size = MSG_QUEUE_COUNT_PRC2;
545 }
545 }
546
546
547 void increment_seq_counter( unsigned short *packetSequenceControl )
547 void increment_seq_counter( unsigned short *packetSequenceControl )
548 {
548 {
549 /** This function increment the sequence counter passes in argument.
549 /** This function increment the sequence counter passes in argument.
550 *
550 *
551 * The increment does not affect the grouping flag. In case of an overflow, the counter is reset to 0.
551 * The increment does not affect the grouping flag. In case of an overflow, the counter is reset to 0.
552 *
552 *
553 */
553 */
554
554
555 unsigned short segmentation_grouping_flag;
555 unsigned short segmentation_grouping_flag;
556 unsigned short sequence_cnt;
556 unsigned short sequence_cnt;
557
557
558 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << 8; // keep bits 7 downto 6
558 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << SHIFT_1_BYTE; // keep bits 7 downto 6
559 sequence_cnt = (*packetSequenceControl) & 0x3fff; // [0011 1111 1111 1111]
559 sequence_cnt = (*packetSequenceControl) & SEQ_CNT_MASK; // [0011 1111 1111 1111]
560
560
561 if ( sequence_cnt < SEQ_CNT_MAX)
561 if ( sequence_cnt < SEQ_CNT_MAX)
562 {
562 {
563 sequence_cnt = sequence_cnt + 1;
563 sequence_cnt = sequence_cnt + 1;
564 }
564 }
565 else
565 else
566 {
566 {
567 sequence_cnt = 0;
567 sequence_cnt = 0;
568 }
568 }
569
569
570 *packetSequenceControl = segmentation_grouping_flag | sequence_cnt ;
570 *packetSequenceControl = segmentation_grouping_flag | sequence_cnt ;
571 }
571 }
572
572
573 void getTime( unsigned char *time)
573 void getTime( unsigned char *time)
574 {
574 {
575 /** This function write the current local time in the time buffer passed in argument.
575 /** This function write the current local time in the time buffer passed in argument.
576 *
576 *
577 */
577 */
578
578
579 time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
579 time[0] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_3_BYTES);
580 time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
580 time[1] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_2_BYTES);
581 time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
581 time[2] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_1_BYTE);
582 time[3] = (unsigned char) (time_management_regs->coarse_time);
582 time[3] = (unsigned char) (time_management_regs->coarse_time);
583 time[4] = (unsigned char) (time_management_regs->fine_time>>8);
583 time[4] = (unsigned char) (time_management_regs->fine_time>>SHIFT_1_BYTE);
584 time[5] = (unsigned char) (time_management_regs->fine_time);
584 time[5] = (unsigned char) (time_management_regs->fine_time);
585 }
585 }
586
586
587 unsigned long long int getTimeAsUnsignedLongLongInt( )
587 unsigned long long int getTimeAsUnsignedLongLongInt( )
588 {
588 {
589 /** This function write the current local time in the time buffer passed in argument.
589 /** This function write the current local time in the time buffer passed in argument.
590 *
590 *
591 */
591 */
592 unsigned long long int time;
592 unsigned long long int time;
593
593
594 time = ( (unsigned long long int) (time_management_regs->coarse_time & 0x7fffffff) << 16 )
594 time = ( (unsigned long long int) (time_management_regs->coarse_time & COARSE_TIME_MASK) << SHIFT_2_BYTES )
595 + time_management_regs->fine_time;
595 + time_management_regs->fine_time;
596
596
597 return time;
597 return time;
598 }
598 }
599
599
600 void send_dumb_hk( void )
600 void send_dumb_hk( void )
601 {
601 {
602 Packet_TM_LFR_HK_t dummy_hk_packet;
602 Packet_TM_LFR_HK_t dummy_hk_packet;
603 unsigned char *parameters;
603 unsigned char *parameters;
604 unsigned int i;
604 unsigned int i;
605 rtems_id queue_id;
605 rtems_id queue_id;
606
606
607 dummy_hk_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
607 dummy_hk_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
608 dummy_hk_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
608 dummy_hk_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
609 dummy_hk_packet.reserved = DEFAULT_RESERVED;
609 dummy_hk_packet.reserved = DEFAULT_RESERVED;
610 dummy_hk_packet.userApplication = CCSDS_USER_APP;
610 dummy_hk_packet.userApplication = CCSDS_USER_APP;
611 dummy_hk_packet.packetID[0] = (unsigned char) (APID_TM_HK >> 8);
611 dummy_hk_packet.packetID[0] = (unsigned char) (APID_TM_HK >> SHIFT_1_BYTE);
612 dummy_hk_packet.packetID[1] = (unsigned char) (APID_TM_HK);
612 dummy_hk_packet.packetID[1] = (unsigned char) (APID_TM_HK);
613 dummy_hk_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
613 dummy_hk_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
614 dummy_hk_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
614 dummy_hk_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
615 dummy_hk_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> 8);
615 dummy_hk_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> SHIFT_1_BYTE);
616 dummy_hk_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK );
616 dummy_hk_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK );
617 dummy_hk_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
617 dummy_hk_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
618 dummy_hk_packet.serviceType = TM_TYPE_HK;
618 dummy_hk_packet.serviceType = TM_TYPE_HK;
619 dummy_hk_packet.serviceSubType = TM_SUBTYPE_HK;
619 dummy_hk_packet.serviceSubType = TM_SUBTYPE_HK;
620 dummy_hk_packet.destinationID = TM_DESTINATION_ID_GROUND;
620 dummy_hk_packet.destinationID = TM_DESTINATION_ID_GROUND;
621 dummy_hk_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
621 dummy_hk_packet.time[0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
622 dummy_hk_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
622 dummy_hk_packet.time[1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
623 dummy_hk_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
623 dummy_hk_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
624 dummy_hk_packet.time[3] = (unsigned char) (time_management_regs->coarse_time);
624 dummy_hk_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
625 dummy_hk_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
625 dummy_hk_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
626 dummy_hk_packet.time[5] = (unsigned char) (time_management_regs->fine_time);
626 dummy_hk_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
627 dummy_hk_packet.sid = SID_HK;
627 dummy_hk_packet.sid = SID_HK;
628
628
629 // init status word
629 // init status word
630 dummy_hk_packet.lfr_status_word[0] = 0xff;
630 dummy_hk_packet.lfr_status_word[0] = INT8_ALL_F;
631 dummy_hk_packet.lfr_status_word[1] = 0xff;
631 dummy_hk_packet.lfr_status_word[1] = INT8_ALL_F;
632 // init software version
632 // init software version
633 dummy_hk_packet.lfr_sw_version[0] = SW_VERSION_N1;
633 dummy_hk_packet.lfr_sw_version[0] = SW_VERSION_N1;
634 dummy_hk_packet.lfr_sw_version[1] = SW_VERSION_N2;
634 dummy_hk_packet.lfr_sw_version[1] = SW_VERSION_N2;
635 dummy_hk_packet.lfr_sw_version[2] = SW_VERSION_N3;
635 dummy_hk_packet.lfr_sw_version[BYTE_2] = SW_VERSION_N3;
636 dummy_hk_packet.lfr_sw_version[3] = SW_VERSION_N4;
636 dummy_hk_packet.lfr_sw_version[BYTE_3] = SW_VERSION_N4;
637 // init fpga version
637 // init fpga version
638 parameters = (unsigned char *) (REGS_ADDR_WAVEFORM_PICKER + 0xb0);
638 parameters = (unsigned char *) (REGS_ADDR_WAVEFORM_PICKER + APB_OFFSET_VHDL_REV);
639 dummy_hk_packet.lfr_fpga_version[0] = parameters[1]; // n1
639 dummy_hk_packet.lfr_fpga_version[BYTE_0] = parameters[BYTE_1]; // n1
640 dummy_hk_packet.lfr_fpga_version[1] = parameters[2]; // n2
640 dummy_hk_packet.lfr_fpga_version[BYTE_1] = parameters[BYTE_2]; // n2
641 dummy_hk_packet.lfr_fpga_version[2] = parameters[3]; // n3
641 dummy_hk_packet.lfr_fpga_version[BYTE_2] = parameters[BYTE_3]; // n3
642
642
643 parameters = (unsigned char *) &dummy_hk_packet.hk_lfr_cpu_load;
643 parameters = (unsigned char *) &dummy_hk_packet.hk_lfr_cpu_load;
644
644
645 for (i=0; i<100; i++)
645 for (i=0; i<(BYTE_POS_HK_REACTION_WHEELS_FREQUENCY - BYTE_POS_HK_LFR_CPU_LOAD); i++)
646 {
646 {
647 parameters[i] = 0xff;
647 parameters[i] = INT8_ALL_F;
648 }
648 }
649
649
650 get_message_queue_id_send( &queue_id );
650 get_message_queue_id_send( &queue_id );
651
651
652 rtems_message_queue_send( queue_id, &dummy_hk_packet,
652 rtems_message_queue_send( queue_id, &dummy_hk_packet,
653 PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
653 PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
654 }
654 }
655
655
656 void get_temperatures( unsigned char *temperatures )
656 void get_temperatures( unsigned char *temperatures )
657 {
657 {
658 unsigned char* temp_scm_ptr;
658 unsigned char* temp_scm_ptr;
659 unsigned char* temp_pcb_ptr;
659 unsigned char* temp_pcb_ptr;
660 unsigned char* temp_fpga_ptr;
660 unsigned char* temp_fpga_ptr;
661
661
662 // SEL1 SEL0
662 // SEL1 SEL0
663 // 0 0 => PCB
663 // 0 0 => PCB
664 // 0 1 => FPGA
664 // 0 1 => FPGA
665 // 1 0 => SCM
665 // 1 0 => SCM
666
666
667 temp_scm_ptr = (unsigned char *) &time_management_regs->temp_scm;
667 temp_scm_ptr = (unsigned char *) &time_management_regs->temp_scm;
668 temp_pcb_ptr = (unsigned char *) &time_management_regs->temp_pcb;
668 temp_pcb_ptr = (unsigned char *) &time_management_regs->temp_pcb;
669 temp_fpga_ptr = (unsigned char *) &time_management_regs->temp_fpga;
669 temp_fpga_ptr = (unsigned char *) &time_management_regs->temp_fpga;
670
670
671 temperatures[0] = temp_scm_ptr[2];
671 temperatures[ BYTE_0 ] = temp_scm_ptr[ BYTE_2 ];
672 temperatures[1] = temp_scm_ptr[3];
672 temperatures[ BYTE_1 ] = temp_scm_ptr[ BYTE_3 ];
673 temperatures[2] = temp_pcb_ptr[2];
673 temperatures[ BYTE_2 ] = temp_pcb_ptr[ BYTE_2 ];
674 temperatures[3] = temp_pcb_ptr[3];
674 temperatures[ BYTE_3 ] = temp_pcb_ptr[ BYTE_3 ];
675 temperatures[4] = temp_fpga_ptr[2];
675 temperatures[ BYTE_4 ] = temp_fpga_ptr[ BYTE_2 ];
676 temperatures[5] = temp_fpga_ptr[3];
676 temperatures[ BYTE_5 ] = temp_fpga_ptr[ BYTE_3 ];
677 }
677 }
678
678
679 void get_v_e1_e2_f3( unsigned char *spacecraft_potential )
679 void get_v_e1_e2_f3( unsigned char *spacecraft_potential )
680 {
680 {
681 unsigned char* v_ptr;
681 unsigned char* v_ptr;
682 unsigned char* e1_ptr;
682 unsigned char* e1_ptr;
683 unsigned char* e2_ptr;
683 unsigned char* e2_ptr;
684
684
685 v_ptr = (unsigned char *) &waveform_picker_regs->v;
685 v_ptr = (unsigned char *) &waveform_picker_regs->v;
686 e1_ptr = (unsigned char *) &waveform_picker_regs->e1;
686 e1_ptr = (unsigned char *) &waveform_picker_regs->e1;
687 e2_ptr = (unsigned char *) &waveform_picker_regs->e2;
687 e2_ptr = (unsigned char *) &waveform_picker_regs->e2;
688
688
689 spacecraft_potential[0] = v_ptr[2];
689 spacecraft_potential[ BYTE_0 ] = v_ptr[ BYTE_2 ];
690 spacecraft_potential[1] = v_ptr[3];
690 spacecraft_potential[ BYTE_1 ] = v_ptr[ BYTE_3 ];
691 spacecraft_potential[2] = e1_ptr[2];
691 spacecraft_potential[ BYTE_2 ] = e1_ptr[ BYTE_2 ];
692 spacecraft_potential[3] = e1_ptr[3];
692 spacecraft_potential[ BYTE_3 ] = e1_ptr[ BYTE_3 ];
693 spacecraft_potential[4] = e2_ptr[2];
693 spacecraft_potential[ BYTE_4 ] = e2_ptr[ BYTE_2 ];
694 spacecraft_potential[5] = e2_ptr[3];
694 spacecraft_potential[ BYTE_5 ] = e2_ptr[ BYTE_3 ];
695 }
695 }
696
696
697 void get_cpu_load( unsigned char *resource_statistics )
697 void get_cpu_load( unsigned char *resource_statistics )
698 {
698 {
699 unsigned char cpu_load;
699 unsigned char cpu_load;
700
700
701 cpu_load = lfr_rtems_cpu_usage_report();
701 cpu_load = lfr_rtems_cpu_usage_report();
702
702
703 // HK_LFR_CPU_LOAD
703 // HK_LFR_CPU_LOAD
704 resource_statistics[0] = cpu_load;
704 resource_statistics[0] = cpu_load;
705
705
706 // HK_LFR_CPU_LOAD_MAX
706 // HK_LFR_CPU_LOAD_MAX
707 if (cpu_load > resource_statistics[1])
707 if (cpu_load > resource_statistics[1])
708 {
708 {
709 resource_statistics[1] = cpu_load;
709 resource_statistics[1] = cpu_load;
710 }
710 }
711
711
712 // CPU_LOAD_AVE
712 // CPU_LOAD_AVE
713 resource_statistics[2] = 0;
713 resource_statistics[BYTE_2] = 0;
714
714
715 #ifndef PRINT_TASK_STATISTICS
715 #ifndef PRINT_TASK_STATISTICS
716 rtems_cpu_usage_reset();
716 rtems_cpu_usage_reset();
717 #endif
717 #endif
718
718
719 }
719 }
720
720
721 void set_hk_lfr_sc_potential_flag( bool state )
721 void set_hk_lfr_sc_potential_flag( bool state )
722 {
722 {
723 if (state == true)
723 if (state == true)
724 {
724 {
725 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] | 0x40; // [0100 0000]
725 housekeeping_packet.lfr_status_word[1] =
726 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_SC_POTENTIAL_FLAG_BIT; // [0100 0000]
726 }
727 }
727 else
728 else
728 {
729 {
729 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] & 0xbf; // [1011 1111]
730 housekeeping_packet.lfr_status_word[1] =
731 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_SC_POTENTIAL_FLAG_MASK; // [1011 1111]
730 }
732 }
731 }
733 }
732
734
733 void set_sy_lfr_pas_filter_enabled( bool state )
735 void set_sy_lfr_pas_filter_enabled( bool state )
734 {
736 {
735 if (state == true)
737 if (state == true)
736 {
738 {
737 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] | 0x20; // [0010 0000]
739 housekeeping_packet.lfr_status_word[1] =
740 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_SC_POTENTIAL_FLAG_BIT; // [0010 0000]
738 }
741 }
739 else
742 else
740 {
743 {
741 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] & 0xdf; // [1101 1111]
744 housekeeping_packet.lfr_status_word[1] =
745 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_SC_POTENTIAL_FLAG_MASK; // [1101 1111]
742 }
746 }
743 }
747 }
744
748
745 void set_sy_lfr_watchdog_enabled( bool state )
749 void set_sy_lfr_watchdog_enabled( bool state )
746 {
750 {
747 if (state == true)
751 if (state == true)
748 {
752 {
749 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] | 0x10; // [0001 0000]
753 housekeeping_packet.lfr_status_word[1] =
754 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_WATCHDOG_BIT; // [0001 0000]
750 }
755 }
751 else
756 else
752 {
757 {
753 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] & 0xef; // [1110 1111]
758 housekeeping_packet.lfr_status_word[1] =
759 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_WATCHDOG_MASK; // [1110 1111]
754 }
760 }
755 }
761 }
756
762
757 void set_hk_lfr_calib_enable( bool state )
763 void set_hk_lfr_calib_enable( bool state )
758 {
764 {
759 if (state == true)
765 if (state == true)
760 {
766 {
761 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] | 0x08; // [0000 1000]
767 housekeeping_packet.lfr_status_word[1] =
768 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_CALIB_BIT; // [0000 1000]
762 }
769 }
763 else
770 else
764 {
771 {
765 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] & 0xf7; // [1111 0111]
772 housekeeping_packet.lfr_status_word[1] =
773 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_CALIB_MASK; // [1111 0111]
766 }
774 }
767 }
775 }
768
776
769 void set_hk_lfr_reset_cause( enum lfr_reset_cause_t lfr_reset_cause )
777 void set_hk_lfr_reset_cause( enum lfr_reset_cause_t lfr_reset_cause )
770 {
778 {
771 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] & 0xf8; // [1111 1000]
779 housekeeping_packet.lfr_status_word[1] =
780 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_RESET_CAUSE_MASK; // [1111 1000]
772
781
773 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1]
782 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1]
774 | (lfr_reset_cause & 0x07 ); // [0000 0111]
783 | (lfr_reset_cause & STATUS_WORD_RESET_CAUSE_BITS ); // [0000 0111]
775
784
776 }
785 }
777
786
778 void increment_hk_counter( unsigned char newValue, unsigned char oldValue, unsigned int *counter )
787 void increment_hk_counter( unsigned char newValue, unsigned char oldValue, unsigned int *counter )
779 {
788 {
780 int delta;
789 int delta;
781
790
782 delta = 0;
791 delta = 0;
783
792
784 if (newValue >= oldValue)
793 if (newValue >= oldValue)
785 {
794 {
786 delta = newValue - oldValue;
795 delta = newValue - oldValue;
787 }
796 }
788 else
797 else
789 {
798 {
790 delta = 255 - oldValue + newValue;
799 delta = 255 - oldValue + newValue;
791 }
800 }
792
801
793 *counter = *counter + delta;
802 *counter = *counter + delta;
794 }
803 }
795
804
796 void hk_lfr_le_update( void )
805 void hk_lfr_le_update( void )
797 {
806 {
798 static hk_lfr_le_t old_hk_lfr_le = {0};
807 static hk_lfr_le_t old_hk_lfr_le = {0};
799 hk_lfr_le_t new_hk_lfr_le;
808 hk_lfr_le_t new_hk_lfr_le;
800 unsigned int counter;
809 unsigned int counter;
801
810
802 counter = ((unsigned int) housekeeping_packet.hk_lfr_le_cnt[0]) * 256 + housekeeping_packet.hk_lfr_le_cnt[1];
811 counter = (((unsigned int) housekeeping_packet.hk_lfr_le_cnt[0]) * 256) + housekeeping_packet.hk_lfr_le_cnt[1];
803
812
804 // DPU
813 // DPU
805 new_hk_lfr_le.dpu_spw_parity = housekeeping_packet.hk_lfr_dpu_spw_parity;
814 new_hk_lfr_le.dpu_spw_parity = housekeeping_packet.hk_lfr_dpu_spw_parity;
806 new_hk_lfr_le.dpu_spw_disconnect= housekeeping_packet.hk_lfr_dpu_spw_disconnect;
815 new_hk_lfr_le.dpu_spw_disconnect= housekeeping_packet.hk_lfr_dpu_spw_disconnect;
807 new_hk_lfr_le.dpu_spw_escape = housekeeping_packet.hk_lfr_dpu_spw_escape;
816 new_hk_lfr_le.dpu_spw_escape = housekeeping_packet.hk_lfr_dpu_spw_escape;
808 new_hk_lfr_le.dpu_spw_credit = housekeeping_packet.hk_lfr_dpu_spw_credit;
817 new_hk_lfr_le.dpu_spw_credit = housekeeping_packet.hk_lfr_dpu_spw_credit;
809 new_hk_lfr_le.dpu_spw_write_sync= housekeeping_packet.hk_lfr_dpu_spw_write_sync;
818 new_hk_lfr_le.dpu_spw_write_sync= housekeeping_packet.hk_lfr_dpu_spw_write_sync;
810 // TIMECODE
819 // TIMECODE
811 new_hk_lfr_le.timecode_erroneous= housekeeping_packet.hk_lfr_timecode_erroneous;
820 new_hk_lfr_le.timecode_erroneous= housekeeping_packet.hk_lfr_timecode_erroneous;
812 new_hk_lfr_le.timecode_missing = housekeeping_packet.hk_lfr_timecode_missing;
821 new_hk_lfr_le.timecode_missing = housekeeping_packet.hk_lfr_timecode_missing;
813 new_hk_lfr_le.timecode_invalid = housekeeping_packet.hk_lfr_timecode_invalid;
822 new_hk_lfr_le.timecode_invalid = housekeeping_packet.hk_lfr_timecode_invalid;
814 // TIME
823 // TIME
815 new_hk_lfr_le.time_timecode_it = housekeeping_packet.hk_lfr_time_timecode_it;
824 new_hk_lfr_le.time_timecode_it = housekeeping_packet.hk_lfr_time_timecode_it;
816 new_hk_lfr_le.time_not_synchro = housekeeping_packet.hk_lfr_time_not_synchro;
825 new_hk_lfr_le.time_not_synchro = housekeeping_packet.hk_lfr_time_not_synchro;
817 new_hk_lfr_le.time_timecode_ctr = housekeeping_packet.hk_lfr_time_timecode_ctr;
826 new_hk_lfr_le.time_timecode_ctr = housekeeping_packet.hk_lfr_time_timecode_ctr;
818 //AHB
827 //AHB
819 new_hk_lfr_le.ahb_correctable = housekeeping_packet.hk_lfr_ahb_correctable;
828 new_hk_lfr_le.ahb_correctable = housekeeping_packet.hk_lfr_ahb_correctable;
820 // housekeeping_packet.hk_lfr_dpu_spw_rx_ahb => not handled by the grspw driver
829 // housekeeping_packet.hk_lfr_dpu_spw_rx_ahb => not handled by the grspw driver
821 // housekeeping_packet.hk_lfr_dpu_spw_tx_ahb => not handled by the grspw driver
830 // housekeeping_packet.hk_lfr_dpu_spw_tx_ahb => not handled by the grspw driver
822
831
823 // update the le counter
832 // update the le counter
824 // DPU
833 // DPU
825 increment_hk_counter( new_hk_lfr_le.dpu_spw_parity, old_hk_lfr_le.dpu_spw_parity, counter );
834 increment_hk_counter( new_hk_lfr_le.dpu_spw_parity, old_hk_lfr_le.dpu_spw_parity, &counter );
826 increment_hk_counter( new_hk_lfr_le.dpu_spw_disconnect,old_hk_lfr_le.dpu_spw_disconnect, counter );
835 increment_hk_counter( new_hk_lfr_le.dpu_spw_disconnect,old_hk_lfr_le.dpu_spw_disconnect, &counter );
827 increment_hk_counter( new_hk_lfr_le.dpu_spw_escape, old_hk_lfr_le.dpu_spw_escape, counter );
836 increment_hk_counter( new_hk_lfr_le.dpu_spw_escape, old_hk_lfr_le.dpu_spw_escape, &counter );
828 increment_hk_counter( new_hk_lfr_le.dpu_spw_credit, old_hk_lfr_le.dpu_spw_credit, counter );
837 increment_hk_counter( new_hk_lfr_le.dpu_spw_credit, old_hk_lfr_le.dpu_spw_credit, &counter );
829 increment_hk_counter( new_hk_lfr_le.dpu_spw_write_sync,old_hk_lfr_le.dpu_spw_write_sync, counter );
838 increment_hk_counter( new_hk_lfr_le.dpu_spw_write_sync,old_hk_lfr_le.dpu_spw_write_sync, &counter );
830 // TIMECODE
839 // TIMECODE
831 increment_hk_counter( new_hk_lfr_le.timecode_erroneous,old_hk_lfr_le.timecode_erroneous, counter );
840 increment_hk_counter( new_hk_lfr_le.timecode_erroneous,old_hk_lfr_le.timecode_erroneous, &counter );
832 increment_hk_counter( new_hk_lfr_le.timecode_missing, old_hk_lfr_le.timecode_missing, counter );
841 increment_hk_counter( new_hk_lfr_le.timecode_missing, old_hk_lfr_le.timecode_missing, &counter );
833 increment_hk_counter( new_hk_lfr_le.timecode_invalid, old_hk_lfr_le.timecode_invalid, counter );
842 increment_hk_counter( new_hk_lfr_le.timecode_invalid, old_hk_lfr_le.timecode_invalid, &counter );
834 // TIME
843 // TIME
835 increment_hk_counter( new_hk_lfr_le.time_timecode_it, old_hk_lfr_le.time_timecode_it, counter );
844 increment_hk_counter( new_hk_lfr_le.time_timecode_it, old_hk_lfr_le.time_timecode_it, &counter );
836 increment_hk_counter( new_hk_lfr_le.time_not_synchro, old_hk_lfr_le.time_not_synchro, counter );
845 increment_hk_counter( new_hk_lfr_le.time_not_synchro, old_hk_lfr_le.time_not_synchro, &counter );
837 increment_hk_counter( new_hk_lfr_le.time_timecode_ctr, old_hk_lfr_le.time_timecode_ctr, counter );
846 increment_hk_counter( new_hk_lfr_le.time_timecode_ctr, old_hk_lfr_le.time_timecode_ctr, &counter );
838 // AHB
847 // AHB
839 increment_hk_counter( new_hk_lfr_le.ahb_correctable, old_hk_lfr_le.ahb_correctable, counter );
848 increment_hk_counter( new_hk_lfr_le.ahb_correctable, old_hk_lfr_le.ahb_correctable, &counter );
840
849
841 // DPU
850 // DPU
842 old_hk_lfr_le.dpu_spw_parity = new_hk_lfr_le.dpu_spw_parity;
851 old_hk_lfr_le.dpu_spw_parity = new_hk_lfr_le.dpu_spw_parity;
843 old_hk_lfr_le.dpu_spw_disconnect= new_hk_lfr_le.dpu_spw_disconnect;
852 old_hk_lfr_le.dpu_spw_disconnect= new_hk_lfr_le.dpu_spw_disconnect;
844 old_hk_lfr_le.dpu_spw_escape = new_hk_lfr_le.dpu_spw_escape;
853 old_hk_lfr_le.dpu_spw_escape = new_hk_lfr_le.dpu_spw_escape;
845 old_hk_lfr_le.dpu_spw_credit = new_hk_lfr_le.dpu_spw_credit;
854 old_hk_lfr_le.dpu_spw_credit = new_hk_lfr_le.dpu_spw_credit;
846 old_hk_lfr_le.dpu_spw_write_sync= new_hk_lfr_le.dpu_spw_write_sync;
855 old_hk_lfr_le.dpu_spw_write_sync= new_hk_lfr_le.dpu_spw_write_sync;
847 // TIMECODE
856 // TIMECODE
848 old_hk_lfr_le.timecode_erroneous= new_hk_lfr_le.timecode_erroneous;
857 old_hk_lfr_le.timecode_erroneous= new_hk_lfr_le.timecode_erroneous;
849 old_hk_lfr_le.timecode_missing = new_hk_lfr_le.timecode_missing;
858 old_hk_lfr_le.timecode_missing = new_hk_lfr_le.timecode_missing;
850 old_hk_lfr_le.timecode_invalid = new_hk_lfr_le.timecode_invalid;
859 old_hk_lfr_le.timecode_invalid = new_hk_lfr_le.timecode_invalid;
851 // TIME
860 // TIME
852 old_hk_lfr_le.time_timecode_it = new_hk_lfr_le.time_timecode_it;
861 old_hk_lfr_le.time_timecode_it = new_hk_lfr_le.time_timecode_it;
853 old_hk_lfr_le.time_not_synchro = new_hk_lfr_le.time_not_synchro;
862 old_hk_lfr_le.time_not_synchro = new_hk_lfr_le.time_not_synchro;
854 old_hk_lfr_le.time_timecode_ctr = new_hk_lfr_le.time_timecode_ctr;
863 old_hk_lfr_le.time_timecode_ctr = new_hk_lfr_le.time_timecode_ctr;
855 //AHB
864 //AHB
856 old_hk_lfr_le.ahb_correctable = new_hk_lfr_le.ahb_correctable;
865 old_hk_lfr_le.ahb_correctable = new_hk_lfr_le.ahb_correctable;
857 // housekeeping_packet.hk_lfr_dpu_spw_rx_ahb => not handled by the grspw driver
866 // housekeeping_packet.hk_lfr_dpu_spw_rx_ahb => not handled by the grspw driver
858 // housekeeping_packet.hk_lfr_dpu_spw_tx_ahb => not handled by the grspw driver
867 // housekeeping_packet.hk_lfr_dpu_spw_tx_ahb => not handled by the grspw driver
859
868
860 // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers
869 // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers
861 // LE
870 // LE
862 housekeeping_packet.hk_lfr_le_cnt[0] = (unsigned char) ((hk_lfr_le_cnt & 0xff00) >> 8);
871 housekeeping_packet.hk_lfr_le_cnt[0] = (unsigned char) ((counter & BYTE0_MASK) >> SHIFT_1_BYTE);
863 housekeeping_packet.hk_lfr_le_cnt[1] = (unsigned char) (hk_lfr_le_cnt & 0x00ff);
872 housekeeping_packet.hk_lfr_le_cnt[1] = (unsigned char) (counter & BYTE1_MASK);
864 }
873 }
865
874
866 void hk_lfr_me_update( void )
875 void hk_lfr_me_update( void )
867 {
876 {
868 static hk_lfr_me_t old_hk_lfr_me = {0};
877 static hk_lfr_me_t old_hk_lfr_me = {0};
869 hk_lfr_me_t new_hk_lfr_me;
878 hk_lfr_me_t new_hk_lfr_me;
870 unsigned int counter;
879 unsigned int counter;
871
880
872 counter = ((unsigned int) housekeeping_packet.hk_lfr_me_cnt[0]) * 256 + housekeeping_packet.hk_lfr_me_cnt[1];
881 counter = (((unsigned int) housekeeping_packet.hk_lfr_me_cnt[0]) * 256) + housekeeping_packet.hk_lfr_me_cnt[1];
873
882
874 // get the current values
883 // get the current values
875 new_hk_lfr_me.dpu_spw_early_eop = housekeeping_packet.hk_lfr_dpu_spw_early_eop;
884 new_hk_lfr_me.dpu_spw_early_eop = housekeeping_packet.hk_lfr_dpu_spw_early_eop;
876 new_hk_lfr_me.dpu_spw_invalid_addr = housekeeping_packet.hk_lfr_dpu_spw_invalid_addr;
885 new_hk_lfr_me.dpu_spw_invalid_addr = housekeeping_packet.hk_lfr_dpu_spw_invalid_addr;
877 new_hk_lfr_me.dpu_spw_eep = housekeeping_packet.hk_lfr_dpu_spw_eep;
886 new_hk_lfr_me.dpu_spw_eep = housekeeping_packet.hk_lfr_dpu_spw_eep;
878 new_hk_lfr_me.dpu_spw_rx_too_big = housekeeping_packet.hk_lfr_dpu_spw_rx_too_big;
887 new_hk_lfr_me.dpu_spw_rx_too_big = housekeeping_packet.hk_lfr_dpu_spw_rx_too_big;
879
888
880 // update the me counter
889 // update the me counter
881 increment_hk_counter( new_hk_lfr_me.dpu_spw_early_eop, old_hk_lfr_me.dpu_spw_early_eop, counter );
890 increment_hk_counter( new_hk_lfr_me.dpu_spw_early_eop, old_hk_lfr_me.dpu_spw_early_eop, &counter );
882 increment_hk_counter( new_hk_lfr_me.dpu_spw_invalid_addr, old_hk_lfr_me.dpu_spw_invalid_addr, counter );
891 increment_hk_counter( new_hk_lfr_me.dpu_spw_invalid_addr, old_hk_lfr_me.dpu_spw_invalid_addr, &counter );
883 increment_hk_counter( new_hk_lfr_me.dpu_spw_eep, old_hk_lfr_me.dpu_spw_eep, counter );
892 increment_hk_counter( new_hk_lfr_me.dpu_spw_eep, old_hk_lfr_me.dpu_spw_eep, &counter );
884 increment_hk_counter( new_hk_lfr_me.dpu_spw_rx_too_big, old_hk_lfr_me.dpu_spw_rx_too_big, counter );
893 increment_hk_counter( new_hk_lfr_me.dpu_spw_rx_too_big, old_hk_lfr_me.dpu_spw_rx_too_big, &counter );
885
894
886 // store the counters for the next time
895 // store the counters for the next time
887 old_hk_lfr_me.dpu_spw_early_eop = new_hk_lfr_me.dpu_spw_early_eop;
896 old_hk_lfr_me.dpu_spw_early_eop = new_hk_lfr_me.dpu_spw_early_eop;
888 old_hk_lfr_me.dpu_spw_invalid_addr = new_hk_lfr_me.dpu_spw_invalid_addr;
897 old_hk_lfr_me.dpu_spw_invalid_addr = new_hk_lfr_me.dpu_spw_invalid_addr;
889 old_hk_lfr_me.dpu_spw_eep = new_hk_lfr_me.dpu_spw_eep;
898 old_hk_lfr_me.dpu_spw_eep = new_hk_lfr_me.dpu_spw_eep;
890 old_hk_lfr_me.dpu_spw_rx_too_big = new_hk_lfr_me.dpu_spw_rx_too_big;
899 old_hk_lfr_me.dpu_spw_rx_too_big = new_hk_lfr_me.dpu_spw_rx_too_big;
891
900
892 // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers
901 // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers
893 // ME
902 // ME
894 housekeeping_packet.hk_lfr_me_cnt[0] = (unsigned char) ((hk_lfr_me_cnt & 0xff00) >> 8);
903 housekeeping_packet.hk_lfr_me_cnt[0] = (unsigned char) ((counter & BYTE0_MASK) >> SHIFT_1_BYTE);
895 housekeeping_packet.hk_lfr_me_cnt[1] = (unsigned char) (hk_lfr_me_cnt & 0x00ff);
904 housekeeping_packet.hk_lfr_me_cnt[1] = (unsigned char) (counter & BYTE1_MASK);
896 }
905 }
897
906
898 void hk_lfr_le_me_he_update()
907 void hk_lfr_le_me_he_update()
899 {
908 {
900
909
901 unsigned int hk_lfr_he_cnt;
910 unsigned int hk_lfr_he_cnt;
902
911
903 hk_lfr_he_cnt = ((unsigned int) housekeeping_packet.hk_lfr_he_cnt[0]) * 256 + housekeeping_packet.hk_lfr_he_cnt[1];
912 hk_lfr_he_cnt = ((unsigned int) housekeeping_packet.hk_lfr_he_cnt[0]) * 256 + housekeeping_packet.hk_lfr_he_cnt[1];
904
913
905 //update the low severity error counter
914 //update the low severity error counter
906 hk_lfr_le_update( );
915 hk_lfr_le_update( );
907
916
908 //update the medium severity error counter
917 //update the medium severity error counter
909 hk_lfr_me_update();
918 hk_lfr_me_update();
910
919
911 //update the high severity error counter
920 //update the high severity error counter
912 hk_lfr_he_cnt = 0;
921 hk_lfr_he_cnt = 0;
913
922
914 // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers
923 // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers
915 // HE
924 // HE
916 housekeeping_packet.hk_lfr_he_cnt[0] = (unsigned char) ((hk_lfr_he_cnt & 0xff00) >> 8);
925 housekeeping_packet.hk_lfr_he_cnt[0] = (unsigned char) ((hk_lfr_he_cnt & BYTE0_MASK) >> SHIFT_1_BYTE);
917 housekeeping_packet.hk_lfr_he_cnt[1] = (unsigned char) (hk_lfr_he_cnt & 0x00ff);
926 housekeeping_packet.hk_lfr_he_cnt[1] = (unsigned char) (hk_lfr_he_cnt & BYTE1_MASK);
918
927
919 }
928 }
920
929
921 void set_hk_lfr_time_not_synchro()
930 void set_hk_lfr_time_not_synchro()
922 {
931 {
923 static unsigned char synchroLost = 1;
932 static unsigned char synchroLost = 1;
924 int synchronizationBit;
933 int synchronizationBit;
925
934
926 // get the synchronization bit
935 // get the synchronization bit
927 synchronizationBit = (time_management_regs->coarse_time & 0x80000000) >> 31; // 1000 0000 0000 0000
936 synchronizationBit =
937 (time_management_regs->coarse_time & VAL_LFR_SYNCHRONIZED) >> BIT_SYNCHRONIZATION; // 1000 0000 0000 0000
928
938
929 switch (synchronizationBit)
939 switch (synchronizationBit)
930 {
940 {
931 case 0:
941 case 0:
932 if (synchroLost == 1)
942 if (synchroLost == 1)
933 {
943 {
934 synchroLost = 0;
944 synchroLost = 0;
935 }
945 }
936 break;
946 break;
937 case 1:
947 case 1:
938 if (synchroLost == 0 )
948 if (synchroLost == 0 )
939 {
949 {
940 synchroLost = 1;
950 synchroLost = 1;
941 increase_unsigned_char_counter(&housekeeping_packet.hk_lfr_time_not_synchro);
951 increase_unsigned_char_counter(&housekeeping_packet.hk_lfr_time_not_synchro);
942 update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_NOT_SYNCHRO );
952 update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_NOT_SYNCHRO );
943 }
953 }
944 break;
954 break;
945 default:
955 default:
946 PRINTF1("in hk_lfr_time_not_synchro *** unexpected value for synchronizationBit = %d\n", synchronizationBit);
956 PRINTF1("in hk_lfr_time_not_synchro *** unexpected value for synchronizationBit = %d\n", synchronizationBit);
947 break;
957 break;
948 }
958 }
949
959
950 }
960 }
951
961
952 void set_hk_lfr_ahb_correctable() // CRITICITY L
962 void set_hk_lfr_ahb_correctable() // CRITICITY L
953 {
963 {
954 /** This function builds the error counter hk_lfr_ahb_correctable using the statistics provided
964 /** This function builds the error counter hk_lfr_ahb_correctable using the statistics provided
955 * by the Cache Control Register (ASI 2, offset 0) and in the Register Protection Control Register (ASR16) on the
965 * by the Cache Control Register (ASI 2, offset 0) and in the Register Protection Control Register (ASR16) on the
956 * detected errors in the cache, in the integer unit and in the floating point unit.
966 * detected errors in the cache, in the integer unit and in the floating point unit.
957 *
967 *
958 * @param void
968 * @param void
959 *
969 *
960 * @return void
970 * @return void
961 *
971 *
962 * All errors are summed to set the value of the hk_lfr_ahb_correctable counter.
972 * All errors are summed to set the value of the hk_lfr_ahb_correctable counter.
963 *
973 *
964 */
974 */
965
975
966 unsigned int ahb_correctable;
976 unsigned int ahb_correctable;
967 unsigned int instructionErrorCounter;
977 unsigned int instructionErrorCounter;
968 unsigned int dataErrorCounter;
978 unsigned int dataErrorCounter;
969 unsigned int fprfErrorCounter;
979 unsigned int fprfErrorCounter;
970 unsigned int iurfErrorCounter;
980 unsigned int iurfErrorCounter;
971
981
972 CCR_getInstructionAndDataErrorCounters( &instructionErrorCounter, &dataErrorCounter);
982 CCR_getInstructionAndDataErrorCounters( &instructionErrorCounter, &dataErrorCounter);
973 ASR16_get_FPRF_IURF_ErrorCounters( &fprfErrorCounter, &iurfErrorCounter);
983 ASR16_get_FPRF_IURF_ErrorCounters( &fprfErrorCounter, &iurfErrorCounter);
974
984
975 ahb_correctable = instructionErrorCounter
985 ahb_correctable = instructionErrorCounter
976 + dataErrorCounter
986 + dataErrorCounter
977 + fprfErrorCounter
987 + fprfErrorCounter
978 + iurfErrorCounter
988 + iurfErrorCounter
979 + housekeeping_packet.hk_lfr_ahb_correctable;
989 + housekeeping_packet.hk_lfr_ahb_correctable;
980
990
981 housekeeping_packet.hk_lfr_ahb_correctable = (unsigned char) (ahb_correctable & 0xff); // [1111 1111]
991 housekeeping_packet.hk_lfr_ahb_correctable = (unsigned char) (ahb_correctable & INT8_ALL_F); // [1111 1111]
982
992
983 }
993 }
@@ -1,1609 +1,1610
1 /** Functions related to the SpaceWire interface.
1 /** Functions related to the SpaceWire interface.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 * A group of functions to handle SpaceWire transmissions:
6 * A group of functions to handle SpaceWire transmissions:
7 * - configuration of the SpaceWire link
7 * - configuration of the SpaceWire link
8 * - SpaceWire related interruption requests processing
8 * - SpaceWire related interruption requests processing
9 * - transmission of TeleMetry packets by a dedicated RTEMS task
9 * - transmission of TeleMetry packets by a dedicated RTEMS task
10 * - reception of TeleCommands by a dedicated RTEMS task
10 * - reception of TeleCommands by a dedicated RTEMS task
11 *
11 *
12 */
12 */
13
13
14 #include "fsw_spacewire.h"
14 #include "fsw_spacewire.h"
15
15
16 rtems_name semq_name;
16 rtems_name semq_name;
17 rtems_id semq_id;
17 rtems_id semq_id;
18
18
19 //*****************
19 //*****************
20 // waveform headers
20 // waveform headers
21 Header_TM_LFR_SCIENCE_CWF_t headerCWF;
21 Header_TM_LFR_SCIENCE_CWF_t headerCWF;
22 Header_TM_LFR_SCIENCE_SWF_t headerSWF;
22 Header_TM_LFR_SCIENCE_SWF_t headerSWF;
23 Header_TM_LFR_SCIENCE_ASM_t headerASM;
23 Header_TM_LFR_SCIENCE_ASM_t headerASM;
24
24
25 unsigned char previousTimecodeCtr = 0;
25 unsigned char previousTimecodeCtr = 0;
26 unsigned int *grspwPtr = (unsigned int *) (REGS_ADDR_GRSPW + APB_OFFSET_GRSPW_TIME_REGISTER);
26 unsigned int *grspwPtr = (unsigned int *) (REGS_ADDR_GRSPW + APB_OFFSET_GRSPW_TIME_REGISTER);
27
27
28 //***********
28 //***********
29 // RTEMS TASK
29 // RTEMS TASK
30 rtems_task spiq_task(rtems_task_argument unused)
30 rtems_task spiq_task(rtems_task_argument unused)
31 {
31 {
32 /** This RTEMS task is awaken by an rtems_event sent by the interruption subroutine of the SpaceWire driver.
32 /** This RTEMS task is awaken by an rtems_event sent by the interruption subroutine of the SpaceWire driver.
33 *
33 *
34 * @param unused is the starting argument of the RTEMS task
34 * @param unused is the starting argument of the RTEMS task
35 *
35 *
36 */
36 */
37
37
38 rtems_event_set event_out;
38 rtems_event_set event_out;
39 rtems_status_code status;
39 rtems_status_code status;
40 int linkStatus;
40 int linkStatus;
41
41
42 BOOT_PRINTF("in SPIQ *** \n")
42 BOOT_PRINTF("in SPIQ *** \n")
43
43
44 while(true){
44 while(true){
45 rtems_event_receive(SPW_LINKERR_EVENT, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an SPW_LINKERR_EVENT
45 rtems_event_receive(SPW_LINKERR_EVENT, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an SPW_LINKERR_EVENT
46 PRINTF("in SPIQ *** got SPW_LINKERR_EVENT\n")
46 PRINTF("in SPIQ *** got SPW_LINKERR_EVENT\n")
47
47
48 // [0] SUSPEND RECV AND SEND TASKS
48 // [0] SUSPEND RECV AND SEND TASKS
49 status = rtems_task_suspend( Task_id[ TASKID_RECV ] );
49 status = rtems_task_suspend( Task_id[ TASKID_RECV ] );
50 if ( status != RTEMS_SUCCESSFUL ) {
50 if ( status != RTEMS_SUCCESSFUL ) {
51 PRINTF("in SPIQ *** ERR suspending RECV Task\n")
51 PRINTF("in SPIQ *** ERR suspending RECV Task\n")
52 }
52 }
53 status = rtems_task_suspend( Task_id[ TASKID_SEND ] );
53 status = rtems_task_suspend( Task_id[ TASKID_SEND ] );
54 if ( status != RTEMS_SUCCESSFUL ) {
54 if ( status != RTEMS_SUCCESSFUL ) {
55 PRINTF("in SPIQ *** ERR suspending SEND Task\n")
55 PRINTF("in SPIQ *** ERR suspending SEND Task\n")
56 }
56 }
57
57
58 // [1] CHECK THE LINK
58 // [1] CHECK THE LINK
59 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (1)
59 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (1)
60 if ( linkStatus != 5) {
60 if ( linkStatus != SPW_LINK_OK) {
61 PRINTF1("in SPIQ *** linkStatus %d, wait...\n", linkStatus)
61 PRINTF1("in SPIQ *** linkStatus %d, wait...\n", linkStatus)
62 status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms
62 status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms
63 }
63 }
64
64
65 // [2] RECHECK THE LINK AFTER SY_LFR_DPU_CONNECT_TIMEOUT
65 // [2] RECHECK THE LINK AFTER SY_LFR_DPU_CONNECT_TIMEOUT
66 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (2)
66 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (2)
67 if ( linkStatus != 5 ) // [2.a] not in run state, reset the link
67 if ( linkStatus != SPW_LINK_OK ) // [2.a] not in run state, reset the link
68 {
68 {
69 spacewire_read_statistics();
69 spacewire_read_statistics();
70 status = spacewire_several_connect_attemps( );
70 status = spacewire_several_connect_attemps( );
71 }
71 }
72 else // [2.b] in run state, start the link
72 else // [2.b] in run state, start the link
73 {
73 {
74 status = spacewire_stop_and_start_link( fdSPW ); // start the link
74 status = spacewire_stop_and_start_link( fdSPW ); // start the link
75 if ( status != RTEMS_SUCCESSFUL)
75 if ( status != RTEMS_SUCCESSFUL)
76 {
76 {
77 PRINTF1("in SPIQ *** ERR spacewire_stop_and_start_link %d\n", status)
77 PRINTF1("in SPIQ *** ERR spacewire_stop_and_start_link %d\n", status)
78 }
78 }
79 }
79 }
80
80
81 // [3] COMPLETE RECOVERY ACTION AFTER SY_LFR_DPU_CONNECT_ATTEMPTS
81 // [3] COMPLETE RECOVERY ACTION AFTER SY_LFR_DPU_CONNECT_ATTEMPTS
82 if ( status == RTEMS_SUCCESSFUL ) // [3.a] the link is in run state and has been started successfully
82 if ( status == RTEMS_SUCCESSFUL ) // [3.a] the link is in run state and has been started successfully
83 {
83 {
84 status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 );
84 status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 );
85 if ( status != RTEMS_SUCCESSFUL ) {
85 if ( status != RTEMS_SUCCESSFUL ) {
86 PRINTF("in SPIQ *** ERR resuming SEND Task\n")
86 PRINTF("in SPIQ *** ERR resuming SEND Task\n")
87 }
87 }
88 status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 );
88 status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 );
89 if ( status != RTEMS_SUCCESSFUL ) {
89 if ( status != RTEMS_SUCCESSFUL ) {
90 PRINTF("in SPIQ *** ERR resuming RECV Task\n")
90 PRINTF("in SPIQ *** ERR resuming RECV Task\n")
91 }
91 }
92 }
92 }
93 else // [3.b] the link is not in run state, go in STANDBY mode
93 else // [3.b] the link is not in run state, go in STANDBY mode
94 {
94 {
95 status = enter_mode_standby();
95 status = enter_mode_standby();
96 if ( status != RTEMS_SUCCESSFUL )
96 if ( status != RTEMS_SUCCESSFUL )
97 {
97 {
98 PRINTF1("in SPIQ *** ERR enter_standby_mode *** code %d\n", status)
98 PRINTF1("in SPIQ *** ERR enter_standby_mode *** code %d\n", status)
99 }
99 }
100 {
100 {
101 updateLFRCurrentMode( LFR_MODE_STANDBY );
101 updateLFRCurrentMode( LFR_MODE_STANDBY );
102 }
102 }
103 // wake the LINK task up to wait for the link recovery
103 // wake the LINK task up to wait for the link recovery
104 status = rtems_event_send ( Task_id[TASKID_LINK], RTEMS_EVENT_0 );
104 status = rtems_event_send ( Task_id[TASKID_LINK], RTEMS_EVENT_0 );
105 status = rtems_task_suspend( RTEMS_SELF );
105 status = rtems_task_suspend( RTEMS_SELF );
106 }
106 }
107 }
107 }
108 }
108 }
109
109
110 rtems_task recv_task( rtems_task_argument unused )
110 rtems_task recv_task( rtems_task_argument unused )
111 {
111 {
112 /** This RTEMS task is dedicated to the reception of incoming TeleCommands.
112 /** This RTEMS task is dedicated to the reception of incoming TeleCommands.
113 *
113 *
114 * @param unused is the starting argument of the RTEMS task
114 * @param unused is the starting argument of the RTEMS task
115 *
115 *
116 * The RECV task blocks on a call to the read system call, waiting for incoming SpaceWire data. When unblocked:
116 * The RECV task blocks on a call to the read system call, waiting for incoming SpaceWire data. When unblocked:
117 * 1. It reads the incoming data.
117 * 1. It reads the incoming data.
118 * 2. Launches the acceptance procedure.
118 * 2. Launches the acceptance procedure.
119 * 3. If the Telecommand is valid, sends it to a dedicated RTEMS message queue.
119 * 3. If the Telecommand is valid, sends it to a dedicated RTEMS message queue.
120 *
120 *
121 */
121 */
122
122
123 int len;
123 int len;
124 ccsdsTelecommandPacket_t currentTC;
124 ccsdsTelecommandPacket_t currentTC;
125 unsigned char computed_CRC[ 2 ];
125 unsigned char computed_CRC[ BYTES_PER_CRC ];
126 unsigned char currentTC_LEN_RCV[ 2 ];
126 unsigned char currentTC_LEN_RCV[ BYTES_PER_PKT_LEN ];
127 unsigned char destinationID;
127 unsigned char destinationID;
128 unsigned int estimatedPacketLength;
128 unsigned int estimatedPacketLength;
129 unsigned int parserCode;
129 unsigned int parserCode;
130 rtems_status_code status;
130 rtems_status_code status;
131 rtems_id queue_recv_id;
131 rtems_id queue_recv_id;
132 rtems_id queue_send_id;
132 rtems_id queue_send_id;
133
133
134 initLookUpTableForCRC(); // the table is used to compute Cyclic Redundancy Codes
134 initLookUpTableForCRC(); // the table is used to compute Cyclic Redundancy Codes
135
135
136 status = get_message_queue_id_recv( &queue_recv_id );
136 status = get_message_queue_id_recv( &queue_recv_id );
137 if (status != RTEMS_SUCCESSFUL)
137 if (status != RTEMS_SUCCESSFUL)
138 {
138 {
139 PRINTF1("in RECV *** ERR get_message_queue_id_recv %d\n", status)
139 PRINTF1("in RECV *** ERR get_message_queue_id_recv %d\n", status)
140 }
140 }
141
141
142 status = get_message_queue_id_send( &queue_send_id );
142 status = get_message_queue_id_send( &queue_send_id );
143 if (status != RTEMS_SUCCESSFUL)
143 if (status != RTEMS_SUCCESSFUL)
144 {
144 {
145 PRINTF1("in RECV *** ERR get_message_queue_id_send %d\n", status)
145 PRINTF1("in RECV *** ERR get_message_queue_id_send %d\n", status)
146 }
146 }
147
147
148 BOOT_PRINTF("in RECV *** \n")
148 BOOT_PRINTF("in RECV *** \n")
149
149
150 while(1)
150 while(1)
151 {
151 {
152 len = read( fdSPW, (char*) &currentTC, CCSDS_TC_PKT_MAX_SIZE ); // the call to read is blocking
152 len = read( fdSPW, (char*) &currentTC, CCSDS_TC_PKT_MAX_SIZE ); // the call to read is blocking
153 if (len == -1){ // error during the read call
153 if (len == -1){ // error during the read call
154 PRINTF1("in RECV *** last read call returned -1, ERRNO %d\n", errno)
154 PRINTF1("in RECV *** last read call returned -1, ERRNO %d\n", errno)
155 }
155 }
156 else {
156 else {
157 if ( (len+1) < CCSDS_TC_PKT_MIN_SIZE ) {
157 if ( (len+1) < CCSDS_TC_PKT_MIN_SIZE ) {
158 PRINTF("in RECV *** packet lenght too short\n")
158 PRINTF("in RECV *** packet lenght too short\n")
159 }
159 }
160 else {
160 else {
161 estimatedPacketLength = (unsigned int) (len - CCSDS_TC_TM_PACKET_OFFSET - 3); // => -3 is for Prot ID, Reserved and User App bytes
161 estimatedPacketLength = (unsigned int) (len - CCSDS_TC_TM_PACKET_OFFSET - PROTID_RES_APP); // => -3 is for Prot ID, Reserved and User App bytes
162 //PRINTF1("incoming TC with Length (byte): %d\n", len - 3);
162 //PRINTF1("incoming TC with Length (byte): %d\n", len - 3);
163 currentTC_LEN_RCV[ 0 ] = (unsigned char) (estimatedPacketLength >> 8);
163 currentTC_LEN_RCV[ 0 ] = (unsigned char) (estimatedPacketLength >> SHIFT_1_BYTE);
164 currentTC_LEN_RCV[ 1 ] = (unsigned char) (estimatedPacketLength );
164 currentTC_LEN_RCV[ 1 ] = (unsigned char) (estimatedPacketLength );
165 // CHECK THE TC
165 // CHECK THE TC
166 parserCode = tc_parser( &currentTC, estimatedPacketLength, computed_CRC ) ;
166 parserCode = tc_parser( &currentTC, estimatedPacketLength, computed_CRC ) ;
167 if ( (parserCode == ILLEGAL_APID) || (parserCode == WRONG_LEN_PKT)
167 if ( (parserCode == ILLEGAL_APID) || (parserCode == WRONG_LEN_PKT)
168 || (parserCode == INCOR_CHECKSUM) || (parserCode == ILL_TYPE)
168 || (parserCode == INCOR_CHECKSUM) || (parserCode == ILL_TYPE)
169 || (parserCode == ILL_SUBTYPE) || (parserCode == WRONG_APP_DATA)
169 || (parserCode == ILL_SUBTYPE) || (parserCode == WRONG_APP_DATA)
170 || (parserCode == WRONG_SRC_ID) )
170 || (parserCode == WRONG_SRC_ID) )
171 { // send TM_LFR_TC_EXE_CORRUPTED
171 { // send TM_LFR_TC_EXE_CORRUPTED
172 PRINTF1("TC corrupted received, with code: %d\n", parserCode);
172 PRINTF1("TC corrupted received, with code: %d\n", parserCode);
173 if ( !( (currentTC.serviceType==TC_TYPE_TIME) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_TIME) )
173 if ( !( (currentTC.serviceType==TC_TYPE_TIME) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_TIME) )
174 &&
174 &&
175 !( (currentTC.serviceType==TC_TYPE_GEN) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_INFO))
175 !( (currentTC.serviceType==TC_TYPE_GEN) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_INFO))
176 )
176 )
177 {
177 {
178 if ( parserCode == WRONG_SRC_ID )
178 if ( parserCode == WRONG_SRC_ID )
179 {
179 {
180 destinationID = SID_TC_GROUND;
180 destinationID = SID_TC_GROUND;
181 }
181 }
182 else
182 else
183 {
183 {
184 destinationID = currentTC.sourceID;
184 destinationID = currentTC.sourceID;
185 }
185 }
186 send_tm_lfr_tc_exe_corrupted( &currentTC, queue_send_id,
186 send_tm_lfr_tc_exe_corrupted( &currentTC, queue_send_id,
187 computed_CRC, currentTC_LEN_RCV,
187 computed_CRC, currentTC_LEN_RCV,
188 destinationID );
188 destinationID );
189 }
189 }
190 }
190 }
191 else
191 else
192 { // send valid TC to the action launcher
192 { // send valid TC to the action launcher
193 status = rtems_message_queue_send( queue_recv_id, &currentTC,
193 status = rtems_message_queue_send( queue_recv_id, &currentTC,
194 estimatedPacketLength + CCSDS_TC_TM_PACKET_OFFSET + 3);
194 estimatedPacketLength + CCSDS_TC_TM_PACKET_OFFSET + PROTID_RES_APP);
195 }
195 }
196 }
196 }
197 }
197 }
198
198
199 update_queue_max_count( queue_recv_id, &hk_lfr_q_rv_fifo_size_max );
199 update_queue_max_count( queue_recv_id, &hk_lfr_q_rv_fifo_size_max );
200
200
201 }
201 }
202 }
202 }
203
203
204 rtems_task send_task( rtems_task_argument argument)
204 rtems_task send_task( rtems_task_argument argument)
205 {
205 {
206 /** This RTEMS task is dedicated to the transmission of TeleMetry packets.
206 /** This RTEMS task is dedicated to the transmission of TeleMetry packets.
207 *
207 *
208 * @param unused is the starting argument of the RTEMS task
208 * @param unused is the starting argument of the RTEMS task
209 *
209 *
210 * The SEND task waits for a message to become available in the dedicated RTEMS queue. When a message arrives:
210 * The SEND task waits for a message to become available in the dedicated RTEMS queue. When a message arrives:
211 * - if the first byte is equal to CCSDS_DESTINATION_ID, the message is sent as is using the write system call.
211 * - if the first byte is equal to CCSDS_DESTINATION_ID, the message is sent as is using the write system call.
212 * - if the first byte is not equal to CCSDS_DESTINATION_ID, the message is handled as a spw_ioctl_pkt_send. After
212 * - if the first byte is not equal to CCSDS_DESTINATION_ID, the message is handled as a spw_ioctl_pkt_send. After
213 * analyzis, the packet is sent either using the write system call or using the ioctl call SPACEWIRE_IOCTRL_SEND, depending on the
213 * analyzis, the packet is sent either using the write system call or using the ioctl call SPACEWIRE_IOCTRL_SEND, depending on the
214 * data it contains.
214 * data it contains.
215 *
215 *
216 */
216 */
217
217
218 rtems_status_code status; // RTEMS status code
218 rtems_status_code status; // RTEMS status code
219 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
219 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
220 ring_node *incomingRingNodePtr;
220 ring_node *incomingRingNodePtr;
221 int ring_node_address;
221 int ring_node_address;
222 char *charPtr;
222 char *charPtr;
223 spw_ioctl_pkt_send *spw_ioctl_send;
223 spw_ioctl_pkt_send *spw_ioctl_send;
224 size_t size; // size of the incoming TC packet
224 size_t size; // size of the incoming TC packet
225 rtems_id queue_send_id;
225 rtems_id queue_send_id;
226 unsigned int sid;
226 unsigned int sid;
227 unsigned char sidAsUnsignedChar;
227 unsigned char sidAsUnsignedChar;
228 unsigned char type;
228 unsigned char type;
229
229
230 incomingRingNodePtr = NULL;
230 incomingRingNodePtr = NULL;
231 ring_node_address = 0;
231 ring_node_address = 0;
232 charPtr = (char *) &ring_node_address;
232 charPtr = (char *) &ring_node_address;
233 sid = 0;
233 sid = 0;
234 sidAsUnsignedChar = 0;
234 sidAsUnsignedChar = 0;
235
235
236 init_header_cwf( &headerCWF );
236 init_header_cwf( &headerCWF );
237 init_header_swf( &headerSWF );
237 init_header_swf( &headerSWF );
238 init_header_asm( &headerASM );
238 init_header_asm( &headerASM );
239
239
240 status = get_message_queue_id_send( &queue_send_id );
240 status = get_message_queue_id_send( &queue_send_id );
241 if (status != RTEMS_SUCCESSFUL)
241 if (status != RTEMS_SUCCESSFUL)
242 {
242 {
243 PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status)
243 PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status)
244 }
244 }
245
245
246 BOOT_PRINTF("in SEND *** \n")
246 BOOT_PRINTF("in SEND *** \n")
247
247
248 while(1)
248 while(1)
249 {
249 {
250 status = rtems_message_queue_receive( queue_send_id, incomingData, &size,
250 status = rtems_message_queue_receive( queue_send_id, incomingData, &size,
251 RTEMS_WAIT, RTEMS_NO_TIMEOUT );
251 RTEMS_WAIT, RTEMS_NO_TIMEOUT );
252
252
253 if (status!=RTEMS_SUCCESSFUL)
253 if (status!=RTEMS_SUCCESSFUL)
254 {
254 {
255 PRINTF1("in SEND *** (1) ERR = %d\n", status)
255 PRINTF1("in SEND *** (1) ERR = %d\n", status)
256 }
256 }
257 else
257 else
258 {
258 {
259 if ( size == sizeof(ring_node*) )
259 if ( size == sizeof(ring_node*) )
260 {
260 {
261 charPtr[0] = incomingData[0];
261 charPtr[0] = incomingData[0];
262 charPtr[1] = incomingData[1];
262 charPtr[1] = incomingData[1];
263 charPtr[2] = incomingData[2];
263 charPtr[BYTE_2] = incomingData[BYTE_2];
264 charPtr[3] = incomingData[3];
264 charPtr[BYTE_3] = incomingData[BYTE_3];
265 incomingRingNodePtr = (ring_node*) ring_node_address;
265 incomingRingNodePtr = (ring_node*) ring_node_address;
266 sid = incomingRingNodePtr->sid;
266 sid = incomingRingNodePtr->sid;
267 if ( (sid==SID_NORM_CWF_LONG_F3)
267 if ( (sid==SID_NORM_CWF_LONG_F3)
268 || (sid==SID_BURST_CWF_F2 )
268 || (sid==SID_BURST_CWF_F2 )
269 || (sid==SID_SBM1_CWF_F1 )
269 || (sid==SID_SBM1_CWF_F1 )
270 || (sid==SID_SBM2_CWF_F2 ))
270 || (sid==SID_SBM2_CWF_F2 ))
271 {
271 {
272 spw_send_waveform_CWF( incomingRingNodePtr, &headerCWF );
272 spw_send_waveform_CWF( incomingRingNodePtr, &headerCWF );
273 }
273 }
274 else if ( (sid==SID_NORM_SWF_F0) || (sid== SID_NORM_SWF_F1) || (sid==SID_NORM_SWF_F2) )
274 else if ( (sid==SID_NORM_SWF_F0) || (sid== SID_NORM_SWF_F1) || (sid==SID_NORM_SWF_F2) )
275 {
275 {
276 spw_send_waveform_SWF( incomingRingNodePtr, &headerSWF );
276 spw_send_waveform_SWF( incomingRingNodePtr, &headerSWF );
277 }
277 }
278 else if ( (sid==SID_NORM_CWF_F3) )
278 else if ( (sid==SID_NORM_CWF_F3) )
279 {
279 {
280 spw_send_waveform_CWF3_light( incomingRingNodePtr, &headerCWF );
280 spw_send_waveform_CWF3_light( incomingRingNodePtr, &headerCWF );
281 }
281 }
282 else if (sid==SID_NORM_ASM_F0)
282 else if (sid==SID_NORM_ASM_F0)
283 {
283 {
284 spw_send_asm_f0( incomingRingNodePtr, &headerASM );
284 spw_send_asm_f0( incomingRingNodePtr, &headerASM );
285 }
285 }
286 else if (sid==SID_NORM_ASM_F1)
286 else if (sid==SID_NORM_ASM_F1)
287 {
287 {
288 spw_send_asm_f1( incomingRingNodePtr, &headerASM );
288 spw_send_asm_f1( incomingRingNodePtr, &headerASM );
289 }
289 }
290 else if (sid==SID_NORM_ASM_F2)
290 else if (sid==SID_NORM_ASM_F2)
291 {
291 {
292 spw_send_asm_f2( incomingRingNodePtr, &headerASM );
292 spw_send_asm_f2( incomingRingNodePtr, &headerASM );
293 }
293 }
294 else if ( sid==TM_CODE_K_DUMP )
294 else if ( sid==TM_CODE_K_DUMP )
295 {
295 {
296 spw_send_k_dump( incomingRingNodePtr );
296 spw_send_k_dump( incomingRingNodePtr );
297 }
297 }
298 else
298 else
299 {
299 {
300 PRINTF1("unexpected sid = %d\n", sid);
300 PRINTF1("unexpected sid = %d\n", sid);
301 }
301 }
302 }
302 }
303 else if ( incomingData[0] == CCSDS_DESTINATION_ID ) // the incoming message is a ccsds packet
303 else if ( incomingData[0] == CCSDS_DESTINATION_ID ) // the incoming message is a ccsds packet
304 {
304 {
305 sidAsUnsignedChar = (unsigned char) incomingData[ PACKET_POS_PA_LFR_SID_PKT ];
305 sidAsUnsignedChar = (unsigned char) incomingData[ PACKET_POS_PA_LFR_SID_PKT ];
306 sid = sidAsUnsignedChar;
306 sid = sidAsUnsignedChar;
307 type = (unsigned char) incomingData[ PACKET_POS_SERVICE_TYPE ];
307 type = (unsigned char) incomingData[ PACKET_POS_SERVICE_TYPE ];
308 if (type == TM_TYPE_LFR_SCIENCE) // this is a BP packet, all other types are handled differently
308 if (type == TM_TYPE_LFR_SCIENCE) // this is a BP packet, all other types are handled differently
309 // SET THE SEQUENCE_CNT PARAMETER IN CASE OF BP0 OR BP1 PACKETS
309 // SET THE SEQUENCE_CNT PARAMETER IN CASE OF BP0 OR BP1 PACKETS
310 {
310 {
311 increment_seq_counter_source_id( (unsigned char*) &incomingData[ PACKET_POS_SEQUENCE_CNT ], sid );
311 increment_seq_counter_source_id( (unsigned char*) &incomingData[ PACKET_POS_SEQUENCE_CNT ], sid );
312 }
312 }
313
313
314 status = write( fdSPW, incomingData, size );
314 status = write( fdSPW, incomingData, size );
315 if (status == -1){
315 if (status == -1){
316 PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size)
316 PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size)
317 }
317 }
318 }
318 }
319 else // the incoming message is a spw_ioctl_pkt_send structure
319 else // the incoming message is a spw_ioctl_pkt_send structure
320 {
320 {
321 spw_ioctl_send = (spw_ioctl_pkt_send*) incomingData;
321 spw_ioctl_send = (spw_ioctl_pkt_send*) incomingData;
322 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, spw_ioctl_send );
322 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, spw_ioctl_send );
323 if (status == -1){
323 if (status == -1){
324 PRINTF2("in SEND *** (2.b) ERRNO = %d, RTEMS = %d\n", errno, status)
324 PRINTF2("in SEND *** (2.b) ERRNO = %d, RTEMS = %d\n", errno, status)
325 }
325 }
326 }
326 }
327 }
327 }
328
328
329 update_queue_max_count( queue_send_id, &hk_lfr_q_sd_fifo_size_max );
329 update_queue_max_count( queue_send_id, &hk_lfr_q_sd_fifo_size_max );
330
330
331 }
331 }
332 }
332 }
333
333
334 rtems_task link_task( rtems_task_argument argument )
334 rtems_task link_task( rtems_task_argument argument )
335 {
335 {
336 rtems_event_set event_out;
336 rtems_event_set event_out;
337 rtems_status_code status;
337 rtems_status_code status;
338 int linkStatus;
338 int linkStatus;
339
339
340 BOOT_PRINTF("in LINK ***\n")
340 BOOT_PRINTF("in LINK ***\n")
341
341
342 while(1)
342 while(1)
343 {
343 {
344 // wait for an RTEMS_EVENT
344 // wait for an RTEMS_EVENT
345 rtems_event_receive( RTEMS_EVENT_0,
345 rtems_event_receive( RTEMS_EVENT_0,
346 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
346 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
347 PRINTF("in LINK *** wait for the link\n")
347 PRINTF("in LINK *** wait for the link\n")
348 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
348 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
349 while( linkStatus != 5) // wait for the link
349 while( linkStatus != SPW_LINK_OK) // wait for the link
350 {
350 {
351 status = rtems_task_wake_after( 10 ); // monitor the link each 100ms
351 status = rtems_task_wake_after( SPW_LINK_WAIT ); // monitor the link each 100ms
352 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
352 status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status
353 watchdog_reload();
353 watchdog_reload();
354 }
354 }
355
355
356 spacewire_read_statistics();
356 spacewire_read_statistics();
357 status = spacewire_stop_and_start_link( fdSPW );
357 status = spacewire_stop_and_start_link( fdSPW );
358
358
359 if (status != RTEMS_SUCCESSFUL)
359 if (status != RTEMS_SUCCESSFUL)
360 {
360 {
361 PRINTF1("in LINK *** ERR link not started %d\n", status)
361 PRINTF1("in LINK *** ERR link not started %d\n", status)
362 }
362 }
363 else
363 else
364 {
364 {
365 PRINTF("in LINK *** OK link started\n")
365 PRINTF("in LINK *** OK link started\n")
366 }
366 }
367
367
368 // restart the SPIQ task
368 // restart the SPIQ task
369 status = rtems_task_restart( Task_id[TASKID_SPIQ], 1 );
369 status = rtems_task_restart( Task_id[TASKID_SPIQ], 1 );
370 if ( status != RTEMS_SUCCESSFUL ) {
370 if ( status != RTEMS_SUCCESSFUL ) {
371 PRINTF("in SPIQ *** ERR restarting SPIQ Task\n")
371 PRINTF("in SPIQ *** ERR restarting SPIQ Task\n")
372 }
372 }
373
373
374 // restart RECV and SEND
374 // restart RECV and SEND
375 status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 );
375 status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 );
376 if ( status != RTEMS_SUCCESSFUL ) {
376 if ( status != RTEMS_SUCCESSFUL ) {
377 PRINTF("in SPIQ *** ERR restarting SEND Task\n")
377 PRINTF("in SPIQ *** ERR restarting SEND Task\n")
378 }
378 }
379 status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 );
379 status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 );
380 if ( status != RTEMS_SUCCESSFUL ) {
380 if ( status != RTEMS_SUCCESSFUL ) {
381 PRINTF("in SPIQ *** ERR restarting RECV Task\n")
381 PRINTF("in SPIQ *** ERR restarting RECV Task\n")
382 }
382 }
383 }
383 }
384 }
384 }
385
385
386 //****************
386 //****************
387 // OTHER FUNCTIONS
387 // OTHER FUNCTIONS
388 int spacewire_open_link( void ) // by default, the driver resets the core: [SPW_CTRL_WRITE(pDev, SPW_CTRL_RESET);]
388 int spacewire_open_link( void ) // by default, the driver resets the core: [SPW_CTRL_WRITE(pDev, SPW_CTRL_RESET);]
389 {
389 {
390 /** This function opens the SpaceWire link.
390 /** This function opens the SpaceWire link.
391 *
391 *
392 * @return a valid file descriptor in case of success, -1 in case of a failure
392 * @return a valid file descriptor in case of success, -1 in case of a failure
393 *
393 *
394 */
394 */
395 rtems_status_code status;
395 rtems_status_code status;
396
396
397 fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call resets the hardware
397 fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call resets the hardware
398 if ( fdSPW < 0 ) {
398 if ( fdSPW < 0 ) {
399 PRINTF1("ERR *** in configure_spw_link *** error opening "GRSPW_DEVICE_NAME" with ERR %d\n", errno)
399 PRINTF1("ERR *** in configure_spw_link *** error opening "GRSPW_DEVICE_NAME" with ERR %d\n", errno)
400 }
400 }
401 else
401 else
402 {
402 {
403 status = RTEMS_SUCCESSFUL;
403 status = RTEMS_SUCCESSFUL;
404 }
404 }
405
405
406 return status;
406 return status;
407 }
407 }
408
408
409 int spacewire_start_link( int fd )
409 int spacewire_start_link( int fd )
410 {
410 {
411 rtems_status_code status;
411 rtems_status_code status;
412
412
413 status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started
413 status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started
414 // -1 default hardcoded driver timeout
414 // -1 default hardcoded driver timeout
415
415
416 return status;
416 return status;
417 }
417 }
418
418
419 int spacewire_stop_and_start_link( int fd )
419 int spacewire_stop_and_start_link( int fd )
420 {
420 {
421 rtems_status_code status;
421 rtems_status_code status;
422
422
423 status = ioctl( fd, SPACEWIRE_IOCTRL_STOP); // start fails if link pDev->running != 0
423 status = ioctl( fd, SPACEWIRE_IOCTRL_STOP); // start fails if link pDev->running != 0
424 status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started
424 status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started
425 // -1 default hardcoded driver timeout
425 // -1 default hardcoded driver timeout
426
426
427 return status;
427 return status;
428 }
428 }
429
429
430 int spacewire_configure_link( int fd )
430 int spacewire_configure_link( int fd )
431 {
431 {
432 /** This function configures the SpaceWire link.
432 /** This function configures the SpaceWire link.
433 *
433 *
434 * @return GR-RTEMS-DRIVER directive status codes:
434 * @return GR-RTEMS-DRIVER directive status codes:
435 * - 22 EINVAL - Null pointer or an out of range value was given as the argument.
435 * - 22 EINVAL - Null pointer or an out of range value was given as the argument.
436 * - 16 EBUSY - Only used for SEND. Returned when no descriptors are avialble in non-blocking mode.
436 * - 16 EBUSY - Only used for SEND. Returned when no descriptors are avialble in non-blocking mode.
437 * - 88 ENOSYS - Returned for SET_DESTKEY if RMAP command handler is not available or if a non-implemented call is used.
437 * - 88 ENOSYS - Returned for SET_DESTKEY if RMAP command handler is not available or if a non-implemented call is used.
438 * - 116 ETIMEDOUT - REturned for SET_PACKET_SIZE and START if the link could not be brought up.
438 * - 116 ETIMEDOUT - REturned for SET_PACKET_SIZE and START if the link could not be brought up.
439 * - 12 ENOMEM - Returned for SET_PACKETSIZE if it was unable to allocate the new buffers.
439 * - 12 ENOMEM - Returned for SET_PACKETSIZE if it was unable to allocate the new buffers.
440 * - 5 EIO - Error when writing to grswp hardware registers.
440 * - 5 EIO - Error when writing to grswp hardware registers.
441 * - 2 ENOENT - No such file or directory
441 * - 2 ENOENT - No such file or directory
442 */
442 */
443
443
444 rtems_status_code status;
444 rtems_status_code status;
445
445
446 spacewire_set_NP(1, REGS_ADDR_GRSPW); // [N]o [P]ort force
446 spacewire_set_NP(1, REGS_ADDR_GRSPW); // [N]o [P]ort force
447 spacewire_set_RE(1, REGS_ADDR_GRSPW); // [R]MAP [E]nable, the dedicated call seems to break the no port force configuration
447 spacewire_set_RE(1, REGS_ADDR_GRSPW); // [R]MAP [E]nable, the dedicated call seems to break the no port force configuration
448 spw_ioctl_packetsize packetsize;
448 spw_ioctl_packetsize packetsize;
449
449
450 packetsize.rxsize = 228;
450 packetsize.rxsize = SPW_RXSIZE;
451 packetsize.txdsize = 4096;
451 packetsize.txdsize = SPW_TXDSIZE;
452 packetsize.txhsize = 34;
452 packetsize.txhsize = SPW_TXHSIZE;
453
453
454 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_RXBLOCK, 1); // sets the blocking mode for reception
454 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_RXBLOCK, 1); // sets the blocking mode for reception
455 if (status!=RTEMS_SUCCESSFUL) {
455 if (status!=RTEMS_SUCCESSFUL) {
456 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_RXBLOCK\n")
456 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_RXBLOCK\n")
457 }
457 }
458 //
458 //
459 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_EVENT_ID, Task_id[TASKID_SPIQ]); // sets the task ID to which an event is sent when a
459 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_EVENT_ID, Task_id[TASKID_SPIQ]); // sets the task ID to which an event is sent when a
460 if (status!=RTEMS_SUCCESSFUL) {
460 if (status!=RTEMS_SUCCESSFUL) {
461 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_EVENT_ID\n") // link-error interrupt occurs
461 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_EVENT_ID\n") // link-error interrupt occurs
462 }
462 }
463 //
463 //
464 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_DISABLE_ERR, 0); // automatic link-disabling due to link-error interrupts
464 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_DISABLE_ERR, 0); // automatic link-disabling due to link-error interrupts
465 if (status!=RTEMS_SUCCESSFUL) {
465 if (status!=RTEMS_SUCCESSFUL) {
466 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_DISABLE_ERR\n")
466 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_DISABLE_ERR\n")
467 }
467 }
468 //
468 //
469 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ, 1); // sets the link-error interrupt bit
469 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ, 1); // sets the link-error interrupt bit
470 if (status!=RTEMS_SUCCESSFUL) {
470 if (status!=RTEMS_SUCCESSFUL) {
471 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n")
471 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n")
472 }
472 }
473 //
473 //
474 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK, 1); // transmission blocks
474 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK, 1); // transmission blocks
475 if (status!=RTEMS_SUCCESSFUL) {
475 if (status!=RTEMS_SUCCESSFUL) {
476 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK\n")
476 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK\n")
477 }
477 }
478 //
478 //
479 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL, 1); // transmission blocks when no transmission descriptor is available
479 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL, 1); // transmission blocks when no transmission descriptor is available
480 if (status!=RTEMS_SUCCESSFUL) {
480 if (status!=RTEMS_SUCCESSFUL) {
481 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL\n")
481 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL\n")
482 }
482 }
483 //
483 //
484 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TCODE_CTRL, 0x0909); // [Time Rx : Time Tx : Link error : Tick-out IRQ]
484 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TCODE_CTRL, CONF_TCODE_CTRL); // [Time Rx : Time Tx : Link error : Tick-out IRQ]
485 if (status!=RTEMS_SUCCESSFUL) {
485 if (status!=RTEMS_SUCCESSFUL) {
486 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TCODE_CTRL,\n")
486 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TCODE_CTRL,\n")
487 }
487 }
488 //
488 //
489 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_PACKETSIZE, packetsize); // set rxsize, txdsize and txhsize
489 status = ioctl(fd, SPACEWIRE_IOCTRL_SET_PACKETSIZE, packetsize); // set rxsize, txdsize and txhsize
490 if (status!=RTEMS_SUCCESSFUL) {
490 if (status!=RTEMS_SUCCESSFUL) {
491 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_PACKETSIZE,\n")
491 PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_PACKETSIZE,\n")
492 }
492 }
493
493
494 return status;
494 return status;
495 }
495 }
496
496
497 int spacewire_several_connect_attemps( void )
497 int spacewire_several_connect_attemps( void )
498 {
498 {
499 /** This function is executed by the SPIQ rtems_task wehn it has been awaken by an interruption raised by the SpaceWire driver.
499 /** This function is executed by the SPIQ rtems_task wehn it has been awaken by an interruption raised by the SpaceWire driver.
500 *
500 *
501 * @return RTEMS directive status code:
501 * @return RTEMS directive status code:
502 * - RTEMS_UNSATISFIED is returned is the link is not in the running state after 10 s.
502 * - RTEMS_UNSATISFIED is returned is the link is not in the running state after 10 s.
503 * - RTEMS_SUCCESSFUL is returned if the link is up before the timeout.
503 * - RTEMS_SUCCESSFUL is returned if the link is up before the timeout.
504 *
504 *
505 */
505 */
506
506
507 rtems_status_code status_spw;
507 rtems_status_code status_spw;
508 rtems_status_code status;
508 rtems_status_code status;
509 int i;
509 int i;
510
510
511 for ( i=0; i<SY_LFR_DPU_CONNECT_ATTEMPT; i++ )
511 for ( i=0; i<SY_LFR_DPU_CONNECT_ATTEMPT; i++ )
512 {
512 {
513 PRINTF1("in spacewire_reset_link *** link recovery, try %d\n", i);
513 PRINTF1("in spacewire_reset_link *** link recovery, try %d\n", i);
514
514
515 // CLOSING THE DRIVER AT THIS POINT WILL MAKE THE SEND TASK BLOCK THE SYSTEM
515 // CLOSING THE DRIVER AT THIS POINT WILL MAKE THE SEND TASK BLOCK THE SYSTEM
516
516
517 status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms
517 status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms
518
518
519 status_spw = spacewire_stop_and_start_link( fdSPW );
519 status_spw = spacewire_stop_and_start_link( fdSPW );
520
520
521 if ( status_spw != RTEMS_SUCCESSFUL )
521 if ( status_spw != RTEMS_SUCCESSFUL )
522 {
522 {
523 PRINTF1("in spacewire_reset_link *** ERR spacewire_start_link code %d\n", status_spw)
523 PRINTF1("in spacewire_reset_link *** ERR spacewire_start_link code %d\n", status_spw)
524 }
524 }
525
525
526 if ( status_spw == RTEMS_SUCCESSFUL)
526 if ( status_spw == RTEMS_SUCCESSFUL)
527 {
527 {
528 break;
528 break;
529 }
529 }
530 }
530 }
531
531
532 return status_spw;
532 return status_spw;
533 }
533 }
534
534
535 void spacewire_set_NP( unsigned char val, unsigned int regAddr ) // [N]o [P]ort force
535 void spacewire_set_NP( unsigned char val, unsigned int regAddr ) // [N]o [P]ort force
536 {
536 {
537 /** This function sets the [N]o [P]ort force bit of the GRSPW control register.
537 /** This function sets the [N]o [P]ort force bit of the GRSPW control register.
538 *
538 *
539 * @param val is the value, 0 or 1, used to set the value of the NP bit.
539 * @param val is the value, 0 or 1, used to set the value of the NP bit.
540 * @param regAddr is the address of the GRSPW control register.
540 * @param regAddr is the address of the GRSPW control register.
541 *
541 *
542 * NP is the bit 20 of the GRSPW control register.
542 * NP is the bit 20 of the GRSPW control register.
543 *
543 *
544 */
544 */
545
545
546 unsigned int *spwptr = (unsigned int*) regAddr;
546 unsigned int *spwptr = (unsigned int*) regAddr;
547
547
548 if (val == 1) {
548 if (val == 1) {
549 *spwptr = *spwptr | 0x00100000; // [NP] set the No port force bit
549 *spwptr = *spwptr | SPW_BIT_NP; // [NP] set the No port force bit
550 }
550 }
551 if (val== 0) {
551 if (val== 0) {
552 *spwptr = *spwptr & 0xffdfffff;
552 *spwptr = *spwptr & SPW_BIT_NP_MASK;
553 }
553 }
554 }
554 }
555
555
556 void spacewire_set_RE( unsigned char val, unsigned int regAddr ) // [R]MAP [E]nable
556 void spacewire_set_RE( unsigned char val, unsigned int regAddr ) // [R]MAP [E]nable
557 {
557 {
558 /** This function sets the [R]MAP [E]nable bit of the GRSPW control register.
558 /** This function sets the [R]MAP [E]nable bit of the GRSPW control register.
559 *
559 *
560 * @param val is the value, 0 or 1, used to set the value of the RE bit.
560 * @param val is the value, 0 or 1, used to set the value of the RE bit.
561 * @param regAddr is the address of the GRSPW control register.
561 * @param regAddr is the address of the GRSPW control register.
562 *
562 *
563 * RE is the bit 16 of the GRSPW control register.
563 * RE is the bit 16 of the GRSPW control register.
564 *
564 *
565 */
565 */
566
566
567 unsigned int *spwptr = (unsigned int*) regAddr;
567 unsigned int *spwptr = (unsigned int*) regAddr;
568
568
569 if (val == 1)
569 if (val == 1)
570 {
570 {
571 *spwptr = *spwptr | 0x00010000; // [RE] set the RMAP Enable bit
571 *spwptr = *spwptr | SPW_BIT_RE; // [RE] set the RMAP Enable bit
572 }
572 }
573 if (val== 0)
573 if (val== 0)
574 {
574 {
575 *spwptr = *spwptr & 0xfffdffff;
575 *spwptr = *spwptr & SPW_BIT_RE_MASK;
576 }
576 }
577 }
577 }
578
578
579 void spacewire_read_statistics( void )
579 void spacewire_read_statistics( void )
580 {
580 {
581 /** This function reads the SpaceWire statistics from the grspw RTEMS driver.
581 /** This function reads the SpaceWire statistics from the grspw RTEMS driver.
582 *
582 *
583 * @param void
583 * @param void
584 *
584 *
585 * @return void
585 * @return void
586 *
586 *
587 * Once they are read, the counters are stored in a global variable used during the building of the
587 * Once they are read, the counters are stored in a global variable used during the building of the
588 * HK packets.
588 * HK packets.
589 *
589 *
590 */
590 */
591
591
592 rtems_status_code status;
592 rtems_status_code status;
593 spw_stats current;
593 spw_stats current;
594
594
595 spacewire_get_last_error();
595 spacewire_get_last_error();
596
596
597 // read the current statistics
597 // read the current statistics
598 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &current );
598 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &current );
599
599
600 // clear the counters
600 // clear the counters
601 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_CLR_STATISTICS );
601 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_CLR_STATISTICS );
602
602
603 // typedef struct {
603 // typedef struct {
604 // unsigned int tx_link_err; // NOT IN HK
604 // unsigned int tx_link_err; // NOT IN HK
605 // unsigned int rx_rmap_header_crc_err; // NOT IN HK
605 // unsigned int rx_rmap_header_crc_err; // NOT IN HK
606 // unsigned int rx_rmap_data_crc_err; // NOT IN HK
606 // unsigned int rx_rmap_data_crc_err; // NOT IN HK
607 // unsigned int rx_eep_err;
607 // unsigned int rx_eep_err;
608 // unsigned int rx_truncated;
608 // unsigned int rx_truncated;
609 // unsigned int parity_err;
609 // unsigned int parity_err;
610 // unsigned int escape_err;
610 // unsigned int escape_err;
611 // unsigned int credit_err;
611 // unsigned int credit_err;
612 // unsigned int write_sync_err;
612 // unsigned int write_sync_err;
613 // unsigned int disconnect_err;
613 // unsigned int disconnect_err;
614 // unsigned int early_ep;
614 // unsigned int early_ep;
615 // unsigned int invalid_address;
615 // unsigned int invalid_address;
616 // unsigned int packets_sent;
616 // unsigned int packets_sent;
617 // unsigned int packets_received;
617 // unsigned int packets_received;
618 // } spw_stats;
618 // } spw_stats;
619
619
620 // rx_eep_err
620 // rx_eep_err
621 grspw_stats.rx_eep_err = grspw_stats.rx_eep_err + current.rx_eep_err;
621 grspw_stats.rx_eep_err = grspw_stats.rx_eep_err + current.rx_eep_err;
622 // rx_truncated
622 // rx_truncated
623 grspw_stats.rx_truncated = grspw_stats.rx_truncated + current.rx_truncated;
623 grspw_stats.rx_truncated = grspw_stats.rx_truncated + current.rx_truncated;
624 // parity_err
624 // parity_err
625 grspw_stats.parity_err = grspw_stats.parity_err + current.parity_err;
625 grspw_stats.parity_err = grspw_stats.parity_err + current.parity_err;
626 // escape_err
626 // escape_err
627 grspw_stats.escape_err = grspw_stats.escape_err + current.escape_err;
627 grspw_stats.escape_err = grspw_stats.escape_err + current.escape_err;
628 // credit_err
628 // credit_err
629 grspw_stats.credit_err = grspw_stats.credit_err + current.credit_err;
629 grspw_stats.credit_err = grspw_stats.credit_err + current.credit_err;
630 // write_sync_err
630 // write_sync_err
631 grspw_stats.write_sync_err = grspw_stats.write_sync_err + current.write_sync_err;
631 grspw_stats.write_sync_err = grspw_stats.write_sync_err + current.write_sync_err;
632 // disconnect_err
632 // disconnect_err
633 grspw_stats.disconnect_err = grspw_stats.disconnect_err + current.disconnect_err;
633 grspw_stats.disconnect_err = grspw_stats.disconnect_err + current.disconnect_err;
634 // early_ep
634 // early_ep
635 grspw_stats.early_ep = grspw_stats.early_ep + current.early_ep;
635 grspw_stats.early_ep = grspw_stats.early_ep + current.early_ep;
636 // invalid_address
636 // invalid_address
637 grspw_stats.invalid_address = grspw_stats.invalid_address + current.invalid_address;
637 grspw_stats.invalid_address = grspw_stats.invalid_address + current.invalid_address;
638 // packets_sent
638 // packets_sent
639 grspw_stats.packets_sent = grspw_stats.packets_sent + current.packets_sent;
639 grspw_stats.packets_sent = grspw_stats.packets_sent + current.packets_sent;
640 // packets_received
640 // packets_received
641 grspw_stats.packets_received= grspw_stats.packets_received + current.packets_received;
641 grspw_stats.packets_received= grspw_stats.packets_received + current.packets_received;
642
642
643 }
643 }
644
644
645 void spacewire_get_last_error( void )
645 void spacewire_get_last_error( void )
646 {
646 {
647 static spw_stats previous;
647 static spw_stats previous;
648 spw_stats current;
648 spw_stats current;
649 rtems_status_code status;
649 rtems_status_code status;
650
650
651 unsigned int hk_lfr_last_er_rid;
651 unsigned int hk_lfr_last_er_rid;
652 unsigned char hk_lfr_last_er_code;
652 unsigned char hk_lfr_last_er_code;
653 int coarseTime;
653 int coarseTime;
654 int fineTime;
654 int fineTime;
655 unsigned char update_hk_lfr_last_er;
655 unsigned char update_hk_lfr_last_er;
656
656
657 update_hk_lfr_last_er = 0;
657 update_hk_lfr_last_er = 0;
658
658
659 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &current );
659 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &current );
660
660
661 // get current time
661 // get current time
662 coarseTime = time_management_regs->coarse_time;
662 coarseTime = time_management_regs->coarse_time;
663 fineTime = time_management_regs->fine_time;
663 fineTime = time_management_regs->fine_time;
664
664
665 // typedef struct {
665 // typedef struct {
666 // unsigned int tx_link_err; // NOT IN HK
666 // unsigned int tx_link_err; // NOT IN HK
667 // unsigned int rx_rmap_header_crc_err; // NOT IN HK
667 // unsigned int rx_rmap_header_crc_err; // NOT IN HK
668 // unsigned int rx_rmap_data_crc_err; // NOT IN HK
668 // unsigned int rx_rmap_data_crc_err; // NOT IN HK
669 // unsigned int rx_eep_err;
669 // unsigned int rx_eep_err;
670 // unsigned int rx_truncated;
670 // unsigned int rx_truncated;
671 // unsigned int parity_err;
671 // unsigned int parity_err;
672 // unsigned int escape_err;
672 // unsigned int escape_err;
673 // unsigned int credit_err;
673 // unsigned int credit_err;
674 // unsigned int write_sync_err;
674 // unsigned int write_sync_err;
675 // unsigned int disconnect_err;
675 // unsigned int disconnect_err;
676 // unsigned int early_ep;
676 // unsigned int early_ep;
677 // unsigned int invalid_address;
677 // unsigned int invalid_address;
678 // unsigned int packets_sent;
678 // unsigned int packets_sent;
679 // unsigned int packets_received;
679 // unsigned int packets_received;
680 // } spw_stats;
680 // } spw_stats;
681
681
682 // tx_link_err *** no code associated to this field
682 // tx_link_err *** no code associated to this field
683 // rx_rmap_header_crc_err *** LE *** in HK
683 // rx_rmap_header_crc_err *** LE *** in HK
684 if (previous.rx_rmap_header_crc_err != current.rx_rmap_header_crc_err)
684 if (previous.rx_rmap_header_crc_err != current.rx_rmap_header_crc_err)
685 {
685 {
686 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
686 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
687 hk_lfr_last_er_code = CODE_HEADER_CRC;
687 hk_lfr_last_er_code = CODE_HEADER_CRC;
688 update_hk_lfr_last_er = 1;
688 update_hk_lfr_last_er = 1;
689 }
689 }
690 // rx_rmap_data_crc_err *** LE *** NOT IN HK
690 // rx_rmap_data_crc_err *** LE *** NOT IN HK
691 if (previous.rx_rmap_data_crc_err != current.rx_rmap_data_crc_err)
691 if (previous.rx_rmap_data_crc_err != current.rx_rmap_data_crc_err)
692 {
692 {
693 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
693 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
694 hk_lfr_last_er_code = CODE_DATA_CRC;
694 hk_lfr_last_er_code = CODE_DATA_CRC;
695 update_hk_lfr_last_er = 1;
695 update_hk_lfr_last_er = 1;
696 }
696 }
697 // rx_eep_err
697 // rx_eep_err
698 if (previous.rx_eep_err != current.rx_eep_err)
698 if (previous.rx_eep_err != current.rx_eep_err)
699 {
699 {
700 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
700 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
701 hk_lfr_last_er_code = CODE_EEP;
701 hk_lfr_last_er_code = CODE_EEP;
702 update_hk_lfr_last_er = 1;
702 update_hk_lfr_last_er = 1;
703 }
703 }
704 // rx_truncated
704 // rx_truncated
705 if (previous.rx_truncated != current.rx_truncated)
705 if (previous.rx_truncated != current.rx_truncated)
706 {
706 {
707 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
707 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
708 hk_lfr_last_er_code = CODE_RX_TOO_BIG;
708 hk_lfr_last_er_code = CODE_RX_TOO_BIG;
709 update_hk_lfr_last_er = 1;
709 update_hk_lfr_last_er = 1;
710 }
710 }
711 // parity_err
711 // parity_err
712 if (previous.parity_err != current.parity_err)
712 if (previous.parity_err != current.parity_err)
713 {
713 {
714 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
714 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
715 hk_lfr_last_er_code = CODE_PARITY;
715 hk_lfr_last_er_code = CODE_PARITY;
716 update_hk_lfr_last_er = 1;
716 update_hk_lfr_last_er = 1;
717 }
717 }
718 // escape_err
718 // escape_err
719 if (previous.parity_err != current.parity_err)
719 if (previous.parity_err != current.parity_err)
720 {
720 {
721 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
721 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
722 hk_lfr_last_er_code = CODE_ESCAPE;
722 hk_lfr_last_er_code = CODE_ESCAPE;
723 update_hk_lfr_last_er = 1;
723 update_hk_lfr_last_er = 1;
724 }
724 }
725 // credit_err
725 // credit_err
726 if (previous.credit_err != current.credit_err)
726 if (previous.credit_err != current.credit_err)
727 {
727 {
728 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
728 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
729 hk_lfr_last_er_code = CODE_CREDIT;
729 hk_lfr_last_er_code = CODE_CREDIT;
730 update_hk_lfr_last_er = 1;
730 update_hk_lfr_last_er = 1;
731 }
731 }
732 // write_sync_err
732 // write_sync_err
733 if (previous.write_sync_err != current.write_sync_err)
733 if (previous.write_sync_err != current.write_sync_err)
734 {
734 {
735 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
735 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
736 hk_lfr_last_er_code = CODE_WRITE_SYNC;
736 hk_lfr_last_er_code = CODE_WRITE_SYNC;
737 update_hk_lfr_last_er = 1;
737 update_hk_lfr_last_er = 1;
738 }
738 }
739 // disconnect_err
739 // disconnect_err
740 if (previous.disconnect_err != current.disconnect_err)
740 if (previous.disconnect_err != current.disconnect_err)
741 {
741 {
742 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
742 hk_lfr_last_er_rid = RID_LE_LFR_DPU_SPW;
743 hk_lfr_last_er_code = CODE_DISCONNECT;
743 hk_lfr_last_er_code = CODE_DISCONNECT;
744 update_hk_lfr_last_er = 1;
744 update_hk_lfr_last_er = 1;
745 }
745 }
746 // early_ep
746 // early_ep
747 if (previous.early_ep != current.early_ep)
747 if (previous.early_ep != current.early_ep)
748 {
748 {
749 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
749 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
750 hk_lfr_last_er_code = CODE_EARLY_EOP_EEP;
750 hk_lfr_last_er_code = CODE_EARLY_EOP_EEP;
751 update_hk_lfr_last_er = 1;
751 update_hk_lfr_last_er = 1;
752 }
752 }
753 // invalid_address
753 // invalid_address
754 if (previous.invalid_address != current.invalid_address)
754 if (previous.invalid_address != current.invalid_address)
755 {
755 {
756 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
756 hk_lfr_last_er_rid = RID_ME_LFR_DPU_SPW;
757 hk_lfr_last_er_code = CODE_INVALID_ADDRESS;
757 hk_lfr_last_er_code = CODE_INVALID_ADDRESS;
758 update_hk_lfr_last_er = 1;
758 update_hk_lfr_last_er = 1;
759 }
759 }
760
760
761 // if a field has changed, update the hk_last_er fields
761 // if a field has changed, update the hk_last_er fields
762 if (update_hk_lfr_last_er == 1)
762 if (update_hk_lfr_last_er == 1)
763 {
763 {
764 update_hk_lfr_last_er_fields( hk_lfr_last_er_rid, hk_lfr_last_er_code );
764 update_hk_lfr_last_er_fields( hk_lfr_last_er_rid, hk_lfr_last_er_code );
765 }
765 }
766
766
767 previous = current;
767 previous = current;
768 }
768 }
769
769
770 void update_hk_lfr_last_er_fields(unsigned int rid, unsigned char code)
770 void update_hk_lfr_last_er_fields(unsigned int rid, unsigned char code)
771 {
771 {
772 unsigned char *coarseTimePtr;
772 unsigned char *coarseTimePtr;
773 unsigned char *fineTimePtr;
773 unsigned char *fineTimePtr;
774
774
775 coarseTimePtr = (unsigned char*) &time_management_regs->coarse_time;
775 coarseTimePtr = (unsigned char*) &time_management_regs->coarse_time;
776 fineTimePtr = (unsigned char*) &time_management_regs->fine_time;
776 fineTimePtr = (unsigned char*) &time_management_regs->fine_time;
777
777
778 housekeeping_packet.hk_lfr_last_er_rid[0] = (unsigned char) ((rid & 0xff00) >> 8 );
778 housekeeping_packet.hk_lfr_last_er_rid[0] = (unsigned char) ((rid & BYTE0_MASK) >> SHIFT_1_BYTE );
779 housekeeping_packet.hk_lfr_last_er_rid[1] = (unsigned char) (rid & 0x00ff);
779 housekeeping_packet.hk_lfr_last_er_rid[1] = (unsigned char) (rid & BYTE1_MASK);
780 housekeeping_packet.hk_lfr_last_er_code = code;
780 housekeeping_packet.hk_lfr_last_er_code = code;
781 housekeeping_packet.hk_lfr_last_er_time[0] = coarseTimePtr[0];
781 housekeeping_packet.hk_lfr_last_er_time[0] = coarseTimePtr[0];
782 housekeeping_packet.hk_lfr_last_er_time[1] = coarseTimePtr[1];
782 housekeeping_packet.hk_lfr_last_er_time[1] = coarseTimePtr[1];
783 housekeeping_packet.hk_lfr_last_er_time[2] = coarseTimePtr[2];
783 housekeeping_packet.hk_lfr_last_er_time[BYTE_2] = coarseTimePtr[BYTE_2];
784 housekeeping_packet.hk_lfr_last_er_time[3] = coarseTimePtr[3];
784 housekeeping_packet.hk_lfr_last_er_time[BYTE_3] = coarseTimePtr[BYTE_3];
785 housekeeping_packet.hk_lfr_last_er_time[4] = fineTimePtr[2];
785 housekeeping_packet.hk_lfr_last_er_time[BYTE_4] = fineTimePtr[BYTE_2];
786 housekeeping_packet.hk_lfr_last_er_time[5] = fineTimePtr[3];
786 housekeeping_packet.hk_lfr_last_er_time[BYTE_5] = fineTimePtr[BYTE_3];
787 }
787 }
788
788
789 void update_hk_with_grspw_stats( void )
789 void update_hk_with_grspw_stats( void )
790 {
790 {
791 //****************************
791 //****************************
792 // DPU_SPACEWIRE_IF_STATISTICS
792 // DPU_SPACEWIRE_IF_STATISTICS
793 housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[0] = (unsigned char) (grspw_stats.packets_received >> 8);
793 housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[0] = (unsigned char) (grspw_stats.packets_received >> SHIFT_1_BYTE);
794 housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[1] = (unsigned char) (grspw_stats.packets_received);
794 housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[1] = (unsigned char) (grspw_stats.packets_received);
795 housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[0] = (unsigned char) (grspw_stats.packets_sent >> 8);
795 housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[0] = (unsigned char) (grspw_stats.packets_sent >> SHIFT_1_BYTE);
796 housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[1] = (unsigned char) (grspw_stats.packets_sent);
796 housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[1] = (unsigned char) (grspw_stats.packets_sent);
797
797
798 //******************************************
798 //******************************************
799 // ERROR COUNTERS / SPACEWIRE / LOW SEVERITY
799 // ERROR COUNTERS / SPACEWIRE / LOW SEVERITY
800 housekeeping_packet.hk_lfr_dpu_spw_parity = (unsigned char) grspw_stats.parity_err;
800 housekeeping_packet.hk_lfr_dpu_spw_parity = (unsigned char) grspw_stats.parity_err;
801 housekeeping_packet.hk_lfr_dpu_spw_disconnect = (unsigned char) grspw_stats.disconnect_err;
801 housekeeping_packet.hk_lfr_dpu_spw_disconnect = (unsigned char) grspw_stats.disconnect_err;
802 housekeeping_packet.hk_lfr_dpu_spw_escape = (unsigned char) grspw_stats.escape_err;
802 housekeeping_packet.hk_lfr_dpu_spw_escape = (unsigned char) grspw_stats.escape_err;
803 housekeeping_packet.hk_lfr_dpu_spw_credit = (unsigned char) grspw_stats.credit_err;
803 housekeeping_packet.hk_lfr_dpu_spw_credit = (unsigned char) grspw_stats.credit_err;
804 housekeeping_packet.hk_lfr_dpu_spw_write_sync = (unsigned char) grspw_stats.write_sync_err;
804 housekeeping_packet.hk_lfr_dpu_spw_write_sync = (unsigned char) grspw_stats.write_sync_err;
805
805
806 //*********************************************
806 //*********************************************
807 // ERROR COUNTERS / SPACEWIRE / MEDIUM SEVERITY
807 // ERROR COUNTERS / SPACEWIRE / MEDIUM SEVERITY
808 housekeeping_packet.hk_lfr_dpu_spw_early_eop = (unsigned char) grspw_stats.early_ep;
808 housekeeping_packet.hk_lfr_dpu_spw_early_eop = (unsigned char) grspw_stats.early_ep;
809 housekeeping_packet.hk_lfr_dpu_spw_invalid_addr = (unsigned char) grspw_stats.invalid_address;
809 housekeeping_packet.hk_lfr_dpu_spw_invalid_addr = (unsigned char) grspw_stats.invalid_address;
810 housekeeping_packet.hk_lfr_dpu_spw_eep = (unsigned char) grspw_stats.rx_eep_err;
810 housekeeping_packet.hk_lfr_dpu_spw_eep = (unsigned char) grspw_stats.rx_eep_err;
811 housekeeping_packet.hk_lfr_dpu_spw_rx_too_big = (unsigned char) grspw_stats.rx_truncated;
811 housekeeping_packet.hk_lfr_dpu_spw_rx_too_big = (unsigned char) grspw_stats.rx_truncated;
812 }
812 }
813
813
814 void spacewire_update_hk_lfr_link_state( unsigned char *hk_lfr_status_word_0 )
814 void spacewire_update_hk_lfr_link_state( unsigned char *hk_lfr_status_word_0 )
815 {
815 {
816 unsigned int *statusRegisterPtr;
816 unsigned int *statusRegisterPtr;
817 unsigned char linkState;
817 unsigned char linkState;
818
818
819 statusRegisterPtr = (unsigned int *) (REGS_ADDR_GRSPW + APB_OFFSET_GRSPW_STATUS_REGISTER);
819 statusRegisterPtr = (unsigned int *) (REGS_ADDR_GRSPW + APB_OFFSET_GRSPW_STATUS_REGISTER);
820 linkState = (unsigned char) ( ( (*statusRegisterPtr) >> 21) & 0x07); // [0000 0111]
820 linkState =
821 (unsigned char) ( ( (*statusRegisterPtr) >> SPW_LINK_STAT_POS) & STATUS_WORD_LINK_STATE_BITS); // [0000 0111]
821
822
822 *hk_lfr_status_word_0 = *hk_lfr_status_word_0 & 0xf8; // [1111 1000] set link state to 0
823 *hk_lfr_status_word_0 = *hk_lfr_status_word_0 & STATUS_WORD_LINK_STATE_MASK; // [1111 1000] set link state to 0
823
824
824 *hk_lfr_status_word_0 = *hk_lfr_status_word_0 | linkState; // update hk_lfr_dpu_spw_link_state
825 *hk_lfr_status_word_0 = *hk_lfr_status_word_0 | linkState; // update hk_lfr_dpu_spw_link_state
825 }
826 }
826
827
827 void increase_unsigned_char_counter( unsigned char *counter )
828 void increase_unsigned_char_counter( unsigned char *counter )
828 {
829 {
829 // update the number of valid timecodes that have been received
830 // update the number of valid timecodes that have been received
830 if (*counter == 255)
831 if (*counter == UINT8_MAX)
831 {
832 {
832 *counter = 0;
833 *counter = 0;
833 }
834 }
834 else
835 else
835 {
836 {
836 *counter = *counter + 1;
837 *counter = *counter + 1;
837 }
838 }
838 }
839 }
839
840
840 unsigned int check_timecode_and_previous_timecode_coherency(unsigned char currentTimecodeCtr)
841 unsigned int check_timecode_and_previous_timecode_coherency(unsigned char currentTimecodeCtr)
841 {
842 {
842 /** This function checks the coherency between the incoming timecode and the last valid timecode.
843 /** This function checks the coherency between the incoming timecode and the last valid timecode.
843 *
844 *
844 * @param currentTimecodeCtr is the incoming timecode
845 * @param currentTimecodeCtr is the incoming timecode
845 *
846 *
846 * @return returned codes::
847 * @return returned codes::
847 * - LFR_DEFAULT
848 * - LFR_DEFAULT
848 * - LFR_SUCCESSFUL
849 * - LFR_SUCCESSFUL
849 *
850 *
850 */
851 */
851
852
852 static unsigned char firstTickout = 1;
853 static unsigned char firstTickout = 1;
853 unsigned char ret;
854 unsigned char ret;
854
855
855 ret = LFR_DEFAULT;
856 ret = LFR_DEFAULT;
856
857
857 if (firstTickout == 0)
858 if (firstTickout == 0)
858 {
859 {
859 if (currentTimecodeCtr == 0)
860 if (currentTimecodeCtr == 0)
860 {
861 {
861 if (previousTimecodeCtr == 63)
862 if (previousTimecodeCtr == SPW_TIMECODE_MAX)
862 {
863 {
863 ret = LFR_SUCCESSFUL;
864 ret = LFR_SUCCESSFUL;
864 }
865 }
865 else
866 else
866 {
867 {
867 ret = LFR_DEFAULT;
868 ret = LFR_DEFAULT;
868 }
869 }
869 }
870 }
870 else
871 else
871 {
872 {
872 if (currentTimecodeCtr == (previousTimecodeCtr +1))
873 if (currentTimecodeCtr == (previousTimecodeCtr +1))
873 {
874 {
874 ret = LFR_SUCCESSFUL;
875 ret = LFR_SUCCESSFUL;
875 }
876 }
876 else
877 else
877 {
878 {
878 ret = LFR_DEFAULT;
879 ret = LFR_DEFAULT;
879 }
880 }
880 }
881 }
881 }
882 }
882 else
883 else
883 {
884 {
884 firstTickout = 0;
885 firstTickout = 0;
885 ret = LFR_SUCCESSFUL;
886 ret = LFR_SUCCESSFUL;
886 }
887 }
887
888
888 return ret;
889 return ret;
889 }
890 }
890
891
891 unsigned int check_timecode_and_internal_time_coherency(unsigned char timecode, unsigned char internalTime)
892 unsigned int check_timecode_and_internal_time_coherency(unsigned char timecode, unsigned char internalTime)
892 {
893 {
893 unsigned int ret;
894 unsigned int ret;
894
895
895 ret = LFR_DEFAULT;
896 ret = LFR_DEFAULT;
896
897
897 if (timecode == internalTime)
898 if (timecode == internalTime)
898 {
899 {
899 ret = LFR_SUCCESSFUL;
900 ret = LFR_SUCCESSFUL;
900 }
901 }
901 else
902 else
902 {
903 {
903 ret = LFR_DEFAULT;
904 ret = LFR_DEFAULT;
904 }
905 }
905
906
906 return ret;
907 return ret;
907 }
908 }
908
909
909 void timecode_irq_handler( void *pDev, void *regs, int minor, unsigned int tc )
910 void timecode_irq_handler( void *pDev, void *regs, int minor, unsigned int tc )
910 {
911 {
911 // a tickout has been emitted, perform actions on the incoming timecode
912 // a tickout has been emitted, perform actions on the incoming timecode
912
913
913 unsigned char incomingTimecode;
914 unsigned char incomingTimecode;
914 unsigned char updateTime;
915 unsigned char updateTime;
915 unsigned char internalTime;
916 unsigned char internalTime;
916 rtems_status_code status;
917 rtems_status_code status;
917
918
918 incomingTimecode = (unsigned char) (grspwPtr[0] & TIMECODE_MASK);
919 incomingTimecode = (unsigned char) (grspwPtr[0] & TIMECODE_MASK);
919 updateTime = time_management_regs->coarse_time_load & TIMECODE_MASK;
920 updateTime = time_management_regs->coarse_time_load & TIMECODE_MASK;
920 internalTime = time_management_regs->coarse_time & TIMECODE_MASK;
921 internalTime = time_management_regs->coarse_time & TIMECODE_MASK;
921
922
922 housekeeping_packet.hk_lfr_dpu_spw_last_timc = incomingTimecode;
923 housekeeping_packet.hk_lfr_dpu_spw_last_timc = incomingTimecode;
923
924
924 // update the number of tickout that have been generated
925 // update the number of tickout that have been generated
925 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_dpu_spw_tick_out_cnt );
926 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_dpu_spw_tick_out_cnt );
926
927
927 //**************************
928 //**************************
928 // HK_LFR_TIMECODE_ERRONEOUS
929 // HK_LFR_TIMECODE_ERRONEOUS
929 // MISSING and INVALID are handled by the timecode_timer_routine service routine
930 // MISSING and INVALID are handled by the timecode_timer_routine service routine
930 if (check_timecode_and_previous_timecode_coherency( incomingTimecode ) == LFR_DEFAULT)
931 if (check_timecode_and_previous_timecode_coherency( incomingTimecode ) == LFR_DEFAULT)
931 {
932 {
932 // this is unexpected but a tickout could have been raised despite of the timecode being erroneous
933 // this is unexpected but a tickout could have been raised despite of the timecode being erroneous
933 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_erroneous );
934 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_erroneous );
934 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_ERRONEOUS );
935 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_ERRONEOUS );
935 }
936 }
936
937
937 //************************
938 //************************
938 // HK_LFR_TIME_TIMECODE_IT
939 // HK_LFR_TIME_TIMECODE_IT
939 // check the coherency between the SpaceWire timecode and the Internal Time
940 // check the coherency between the SpaceWire timecode and the Internal Time
940 if (check_timecode_and_internal_time_coherency( incomingTimecode, internalTime ) == LFR_DEFAULT)
941 if (check_timecode_and_internal_time_coherency( incomingTimecode, internalTime ) == LFR_DEFAULT)
941 {
942 {
942 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_time_timecode_it );
943 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_time_timecode_it );
943 update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_TIMECODE_IT );
944 update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_TIMECODE_IT );
944 }
945 }
945
946
946 //********************
947 //********************
947 // HK_LFR_TIMECODE_CTR
948 // HK_LFR_TIMECODE_CTR
948 // check the value of the timecode with respect to the last TC_LFR_UPDATE_TIME => SSS-CP-FS-370
949 // check the value of the timecode with respect to the last TC_LFR_UPDATE_TIME => SSS-CP-FS-370
949 if (oneTcLfrUpdateTimeReceived == 1)
950 if (oneTcLfrUpdateTimeReceived == 1)
950 {
951 {
951 if ( incomingTimecode != updateTime )
952 if ( incomingTimecode != updateTime )
952 {
953 {
953 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_time_timecode_ctr );
954 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_time_timecode_ctr );
954 update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_TIMECODE_CTR );
955 update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_TIMECODE_CTR );
955 }
956 }
956 }
957 }
957
958
958 // launch the timecode timer to detect missing or invalid timecodes
959 // launch the timecode timer to detect missing or invalid timecodes
959 previousTimecodeCtr = incomingTimecode; // update the previousTimecodeCtr value
960 previousTimecodeCtr = incomingTimecode; // update the previousTimecodeCtr value
960 status = rtems_timer_fire_after( timecode_timer_id, TIMECODE_TIMER_TIMEOUT, timecode_timer_routine, NULL );
961 status = rtems_timer_fire_after( timecode_timer_id, TIMECODE_TIMER_TIMEOUT, timecode_timer_routine, NULL );
961 if (status != RTEMS_SUCCESSFUL)
962 if (status != RTEMS_SUCCESSFUL)
962 {
963 {
963 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_14 );
964 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_14 );
964 }
965 }
965 }
966 }
966
967
967 rtems_timer_service_routine timecode_timer_routine( rtems_id timer_id, void *user_data )
968 rtems_timer_service_routine timecode_timer_routine( rtems_id timer_id, void *user_data )
968 {
969 {
969 static unsigned char initStep = 1;
970 static unsigned char initStep = 1;
970
971
971 unsigned char currentTimecodeCtr;
972 unsigned char currentTimecodeCtr;
972
973
973 currentTimecodeCtr = (unsigned char) (grspwPtr[0] & TIMECODE_MASK);
974 currentTimecodeCtr = (unsigned char) (grspwPtr[0] & TIMECODE_MASK);
974
975
975 if (initStep == 1)
976 if (initStep == 1)
976 {
977 {
977 if (currentTimecodeCtr == previousTimecodeCtr)
978 if (currentTimecodeCtr == previousTimecodeCtr)
978 {
979 {
979 //************************
980 //************************
980 // HK_LFR_TIMECODE_MISSING
981 // HK_LFR_TIMECODE_MISSING
981 // the timecode value has not changed, no valid timecode has been received, the timecode is MISSING
982 // the timecode value has not changed, no valid timecode has been received, the timecode is MISSING
982 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_missing );
983 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_missing );
983 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_MISSING );
984 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_MISSING );
984 }
985 }
985 else if (currentTimecodeCtr == (previousTimecodeCtr+1))
986 else if (currentTimecodeCtr == (previousTimecodeCtr+1))
986 {
987 {
987 // the timecode value has changed and the value is valid, this is unexpected because
988 // the timecode value has changed and the value is valid, this is unexpected because
988 // the timer should not have fired, the timecode_irq_handler should have been raised
989 // the timer should not have fired, the timecode_irq_handler should have been raised
989 }
990 }
990 else
991 else
991 {
992 {
992 //************************
993 //************************
993 // HK_LFR_TIMECODE_INVALID
994 // HK_LFR_TIMECODE_INVALID
994 // the timecode value has changed and the value is not valid, no tickout has been generated
995 // the timecode value has changed and the value is not valid, no tickout has been generated
995 // this is why the timer has fired
996 // this is why the timer has fired
996 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_invalid );
997 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_invalid );
997 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_INVALID );
998 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_INVALID );
998 }
999 }
999 }
1000 }
1000 else
1001 else
1001 {
1002 {
1002 initStep = 1;
1003 initStep = 1;
1003 //************************
1004 //************************
1004 // HK_LFR_TIMECODE_MISSING
1005 // HK_LFR_TIMECODE_MISSING
1005 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_missing );
1006 increase_unsigned_char_counter( &housekeeping_packet.hk_lfr_timecode_missing );
1006 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_MISSING );
1007 update_hk_lfr_last_er_fields( RID_LE_LFR_TIMEC, CODE_MISSING );
1007 }
1008 }
1008
1009
1009 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_13 );
1010 rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_13 );
1010 }
1011 }
1011
1012
1012 void init_header_cwf( Header_TM_LFR_SCIENCE_CWF_t *header )
1013 void init_header_cwf( Header_TM_LFR_SCIENCE_CWF_t *header )
1013 {
1014 {
1014 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
1015 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
1015 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1016 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1016 header->reserved = DEFAULT_RESERVED;
1017 header->reserved = DEFAULT_RESERVED;
1017 header->userApplication = CCSDS_USER_APP;
1018 header->userApplication = CCSDS_USER_APP;
1018 header->packetSequenceControl[0]= TM_PACKET_SEQ_CTRL_STANDALONE;
1019 header->packetSequenceControl[0]= TM_PACKET_SEQ_CTRL_STANDALONE;
1019 header->packetSequenceControl[1]= TM_PACKET_SEQ_CNT_DEFAULT;
1020 header->packetSequenceControl[1]= TM_PACKET_SEQ_CNT_DEFAULT;
1020 header->packetLength[0] = 0x00;
1021 header->packetLength[0] = INIT_CHAR;
1021 header->packetLength[1] = 0x00;
1022 header->packetLength[1] = INIT_CHAR;
1022 // DATA FIELD HEADER
1023 // DATA FIELD HEADER
1023 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
1024 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
1024 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
1025 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
1025 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; // service subtype
1026 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; // service subtype
1026 header->destinationID = TM_DESTINATION_ID_GROUND;
1027 header->destinationID = TM_DESTINATION_ID_GROUND;
1027 header->time[0] = 0x00;
1028 header->time[BYTE_0] = INIT_CHAR;
1028 header->time[0] = 0x00;
1029 header->time[BYTE_1] = INIT_CHAR;
1029 header->time[0] = 0x00;
1030 header->time[BYTE_2] = INIT_CHAR;
1030 header->time[0] = 0x00;
1031 header->time[BYTE_3] = INIT_CHAR;
1031 header->time[0] = 0x00;
1032 header->time[BYTE_4] = INIT_CHAR;
1032 header->time[0] = 0x00;
1033 header->time[BYTE_5] = INIT_CHAR;
1033 // AUXILIARY DATA HEADER
1034 // AUXILIARY DATA HEADER
1034 header->sid = 0x00;
1035 header->sid = INIT_CHAR;
1035 header->pa_bia_status_info = DEFAULT_HKBIA;
1036 header->pa_bia_status_info = DEFAULT_HKBIA;
1036 header->blkNr[0] = 0x00;
1037 header->blkNr[0] = INIT_CHAR;
1037 header->blkNr[1] = 0x00;
1038 header->blkNr[1] = INIT_CHAR;
1038 }
1039 }
1039
1040
1040 void init_header_swf( Header_TM_LFR_SCIENCE_SWF_t *header )
1041 void init_header_swf( Header_TM_LFR_SCIENCE_SWF_t *header )
1041 {
1042 {
1042 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
1043 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
1043 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1044 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1044 header->reserved = DEFAULT_RESERVED;
1045 header->reserved = DEFAULT_RESERVED;
1045 header->userApplication = CCSDS_USER_APP;
1046 header->userApplication = CCSDS_USER_APP;
1046 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8);
1047 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> SHIFT_1_BYTE);
1047 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1048 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1048 header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1049 header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1049 header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1050 header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1050 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> 8);
1051 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> SHIFT_1_BYTE);
1051 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 );
1052 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 );
1052 // DATA FIELD HEADER
1053 // DATA FIELD HEADER
1053 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
1054 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
1054 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
1055 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
1055 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; // service subtype
1056 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; // service subtype
1056 header->destinationID = TM_DESTINATION_ID_GROUND;
1057 header->destinationID = TM_DESTINATION_ID_GROUND;
1057 header->time[0] = 0x00;
1058 header->time[BYTE_0] = INIT_CHAR;
1058 header->time[0] = 0x00;
1059 header->time[BYTE_1] = INIT_CHAR;
1059 header->time[0] = 0x00;
1060 header->time[BYTE_2] = INIT_CHAR;
1060 header->time[0] = 0x00;
1061 header->time[BYTE_3] = INIT_CHAR;
1061 header->time[0] = 0x00;
1062 header->time[BYTE_4] = INIT_CHAR;
1062 header->time[0] = 0x00;
1063 header->time[BYTE_5] = INIT_CHAR;
1063 // AUXILIARY DATA HEADER
1064 // AUXILIARY DATA HEADER
1064 header->sid = 0x00;
1065 header->sid = INIT_CHAR;
1065 header->pa_bia_status_info = DEFAULT_HKBIA;
1066 header->pa_bia_status_info = DEFAULT_HKBIA;
1066 header->pktCnt = DEFAULT_PKTCNT; // PKT_CNT
1067 header->pktCnt = PKTCNT_SWF; // PKT_CNT
1067 header->pktNr = 0x00;
1068 header->pktNr = INIT_CHAR;
1068 header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> 8);
1069 header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> SHIFT_1_BYTE);
1069 header->blkNr[1] = (unsigned char) (BLK_NR_CWF );
1070 header->blkNr[1] = (unsigned char) (BLK_NR_CWF );
1070 }
1071 }
1071
1072
1072 void init_header_asm( Header_TM_LFR_SCIENCE_ASM_t *header )
1073 void init_header_asm( Header_TM_LFR_SCIENCE_ASM_t *header )
1073 {
1074 {
1074 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
1075 header->targetLogicalAddress = CCSDS_DESTINATION_ID;
1075 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1076 header->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1076 header->reserved = DEFAULT_RESERVED;
1077 header->reserved = DEFAULT_RESERVED;
1077 header->userApplication = CCSDS_USER_APP;
1078 header->userApplication = CCSDS_USER_APP;
1078 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8);
1079 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> SHIFT_1_BYTE);
1079 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1080 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1080 header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1081 header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1081 header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1082 header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1082 header->packetLength[0] = 0x00;
1083 header->packetLength[0] = INIT_CHAR;
1083 header->packetLength[1] = 0x00;
1084 header->packetLength[1] = INIT_CHAR;
1084 // DATA FIELD HEADER
1085 // DATA FIELD HEADER
1085 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
1086 header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
1086 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
1087 header->serviceType = TM_TYPE_LFR_SCIENCE; // service type
1087 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; // service subtype
1088 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; // service subtype
1088 header->destinationID = TM_DESTINATION_ID_GROUND;
1089 header->destinationID = TM_DESTINATION_ID_GROUND;
1089 header->time[0] = 0x00;
1090 header->time[BYTE_0] = INIT_CHAR;
1090 header->time[0] = 0x00;
1091 header->time[BYTE_1] = INIT_CHAR;
1091 header->time[0] = 0x00;
1092 header->time[BYTE_2] = INIT_CHAR;
1092 header->time[0] = 0x00;
1093 header->time[BYTE_3] = INIT_CHAR;
1093 header->time[0] = 0x00;
1094 header->time[BYTE_4] = INIT_CHAR;
1094 header->time[0] = 0x00;
1095 header->time[BYTE_5] = INIT_CHAR;
1095 // AUXILIARY DATA HEADER
1096 // AUXILIARY DATA HEADER
1096 header->sid = 0x00;
1097 header->sid = INIT_CHAR;
1097 header->pa_bia_status_info = 0x00;
1098 header->pa_bia_status_info = INIT_CHAR;
1098 header->pa_lfr_pkt_cnt_asm = 0x00;
1099 header->pa_lfr_pkt_cnt_asm = INIT_CHAR;
1099 header->pa_lfr_pkt_nr_asm = 0x00;
1100 header->pa_lfr_pkt_nr_asm = INIT_CHAR;
1100 header->pa_lfr_asm_blk_nr[0] = 0x00;
1101 header->pa_lfr_asm_blk_nr[0] = INIT_CHAR;
1101 header->pa_lfr_asm_blk_nr[1] = 0x00;
1102 header->pa_lfr_asm_blk_nr[1] = INIT_CHAR;
1102 }
1103 }
1103
1104
1104 int spw_send_waveform_CWF( ring_node *ring_node_to_send,
1105 int spw_send_waveform_CWF( ring_node *ring_node_to_send,
1105 Header_TM_LFR_SCIENCE_CWF_t *header )
1106 Header_TM_LFR_SCIENCE_CWF_t *header )
1106 {
1107 {
1107 /** This function sends CWF CCSDS packets (F2, F1 or F0).
1108 /** This function sends CWF CCSDS packets (F2, F1 or F0).
1108 *
1109 *
1109 * @param waveform points to the buffer containing the data that will be send.
1110 * @param waveform points to the buffer containing the data that will be send.
1110 * @param sid is the source identifier of the data that will be sent.
1111 * @param sid is the source identifier of the data that will be sent.
1111 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
1112 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
1112 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
1113 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
1113 * contain information to setup the transmission of the data packets.
1114 * contain information to setup the transmission of the data packets.
1114 *
1115 *
1115 * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks.
1116 * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks.
1116 *
1117 *
1117 */
1118 */
1118
1119
1119 unsigned int i;
1120 unsigned int i;
1120 int ret;
1121 int ret;
1121 unsigned int coarseTime;
1122 unsigned int coarseTime;
1122 unsigned int fineTime;
1123 unsigned int fineTime;
1123 rtems_status_code status;
1124 rtems_status_code status;
1124 spw_ioctl_pkt_send spw_ioctl_send_CWF;
1125 spw_ioctl_pkt_send spw_ioctl_send_CWF;
1125 int *dataPtr;
1126 int *dataPtr;
1126 unsigned char sid;
1127 unsigned char sid;
1127
1128
1128 spw_ioctl_send_CWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_CWF;
1129 spw_ioctl_send_CWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_CWF;
1129 spw_ioctl_send_CWF.options = 0;
1130 spw_ioctl_send_CWF.options = 0;
1130
1131
1131 ret = LFR_DEFAULT;
1132 ret = LFR_DEFAULT;
1132 sid = (unsigned char) ring_node_to_send->sid;
1133 sid = (unsigned char) ring_node_to_send->sid;
1133
1134
1134 coarseTime = ring_node_to_send->coarseTime;
1135 coarseTime = ring_node_to_send->coarseTime;
1135 fineTime = ring_node_to_send->fineTime;
1136 fineTime = ring_node_to_send->fineTime;
1136 dataPtr = (int*) ring_node_to_send->buffer_address;
1137 dataPtr = (int*) ring_node_to_send->buffer_address;
1137
1138
1138 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> 8);
1139 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> SHIFT_1_BYTE);
1139 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 );
1140 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 );
1140 header->pa_bia_status_info = pa_bia_status_info;
1141 header->pa_bia_status_info = pa_bia_status_info;
1141 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1142 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1142 header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> 8);
1143 header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> SHIFT_1_BYTE);
1143 header->blkNr[1] = (unsigned char) (BLK_NR_CWF );
1144 header->blkNr[1] = (unsigned char) (BLK_NR_CWF );
1144
1145
1145 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF; i++) // send waveform
1146 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF; i++) // send waveform
1146 {
1147 {
1147 spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF * NB_WORDS_SWF_BLK) ];
1148 spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF * NB_WORDS_SWF_BLK) ];
1148 spw_ioctl_send_CWF.hdr = (char*) header;
1149 spw_ioctl_send_CWF.hdr = (char*) header;
1149 // BUILD THE DATA
1150 // BUILD THE DATA
1150 spw_ioctl_send_CWF.dlen = BLK_NR_CWF * NB_BYTES_SWF_BLK;
1151 spw_ioctl_send_CWF.dlen = BLK_NR_CWF * NB_BYTES_SWF_BLK;
1151
1152
1152 // SET PACKET SEQUENCE CONTROL
1153 // SET PACKET SEQUENCE CONTROL
1153 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1154 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1154
1155
1155 // SET SID
1156 // SET SID
1156 header->sid = sid;
1157 header->sid = sid;
1157
1158
1158 // SET PACKET TIME
1159 // SET PACKET TIME
1159 compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime);
1160 compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime);
1160 //
1161 //
1161 header->time[0] = header->acquisitionTime[0];
1162 header->time[0] = header->acquisitionTime[0];
1162 header->time[1] = header->acquisitionTime[1];
1163 header->time[1] = header->acquisitionTime[1];
1163 header->time[2] = header->acquisitionTime[2];
1164 header->time[BYTE_2] = header->acquisitionTime[BYTE_2];
1164 header->time[3] = header->acquisitionTime[3];
1165 header->time[BYTE_3] = header->acquisitionTime[BYTE_3];
1165 header->time[4] = header->acquisitionTime[4];
1166 header->time[BYTE_4] = header->acquisitionTime[BYTE_4];
1166 header->time[5] = header->acquisitionTime[5];
1167 header->time[BYTE_5] = header->acquisitionTime[BYTE_5];
1167
1168
1168 // SET PACKET ID
1169 // SET PACKET ID
1169 if ( (sid == SID_SBM1_CWF_F1) || (sid == SID_SBM2_CWF_F2) )
1170 if ( (sid == SID_SBM1_CWF_F1) || (sid == SID_SBM2_CWF_F2) )
1170 {
1171 {
1171 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2 >> 8);
1172 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2 >> SHIFT_1_BYTE);
1172 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2);
1173 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2);
1173 }
1174 }
1174 else
1175 else
1175 {
1176 {
1176 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8);
1177 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> SHIFT_1_BYTE);
1177 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1178 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1178 }
1179 }
1179
1180
1180 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF );
1181 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF );
1181 if (status != RTEMS_SUCCESSFUL) {
1182 if (status != RTEMS_SUCCESSFUL) {
1182 ret = LFR_DEFAULT;
1183 ret = LFR_DEFAULT;
1183 }
1184 }
1184 }
1185 }
1185
1186
1186 return ret;
1187 return ret;
1187 }
1188 }
1188
1189
1189 int spw_send_waveform_SWF( ring_node *ring_node_to_send,
1190 int spw_send_waveform_SWF( ring_node *ring_node_to_send,
1190 Header_TM_LFR_SCIENCE_SWF_t *header )
1191 Header_TM_LFR_SCIENCE_SWF_t *header )
1191 {
1192 {
1192 /** This function sends SWF CCSDS packets (F2, F1 or F0).
1193 /** This function sends SWF CCSDS packets (F2, F1 or F0).
1193 *
1194 *
1194 * @param waveform points to the buffer containing the data that will be send.
1195 * @param waveform points to the buffer containing the data that will be send.
1195 * @param sid is the source identifier of the data that will be sent.
1196 * @param sid is the source identifier of the data that will be sent.
1196 * @param headerSWF points to a table of headers that have been prepared for the data transmission.
1197 * @param headerSWF points to a table of headers that have been prepared for the data transmission.
1197 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
1198 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
1198 * contain information to setup the transmission of the data packets.
1199 * contain information to setup the transmission of the data packets.
1199 *
1200 *
1200 * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks.
1201 * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks.
1201 *
1202 *
1202 */
1203 */
1203
1204
1204 unsigned int i;
1205 unsigned int i;
1205 int ret;
1206 int ret;
1206 unsigned int coarseTime;
1207 unsigned int coarseTime;
1207 unsigned int fineTime;
1208 unsigned int fineTime;
1208 rtems_status_code status;
1209 rtems_status_code status;
1209 spw_ioctl_pkt_send spw_ioctl_send_SWF;
1210 spw_ioctl_pkt_send spw_ioctl_send_SWF;
1210 int *dataPtr;
1211 int *dataPtr;
1211 unsigned char sid;
1212 unsigned char sid;
1212
1213
1213 spw_ioctl_send_SWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_SWF;
1214 spw_ioctl_send_SWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_SWF;
1214 spw_ioctl_send_SWF.options = 0;
1215 spw_ioctl_send_SWF.options = 0;
1215
1216
1216 ret = LFR_DEFAULT;
1217 ret = LFR_DEFAULT;
1217
1218
1218 coarseTime = ring_node_to_send->coarseTime;
1219 coarseTime = ring_node_to_send->coarseTime;
1219 fineTime = ring_node_to_send->fineTime;
1220 fineTime = ring_node_to_send->fineTime;
1220 dataPtr = (int*) ring_node_to_send->buffer_address;
1221 dataPtr = (int*) ring_node_to_send->buffer_address;
1221 sid = ring_node_to_send->sid;
1222 sid = ring_node_to_send->sid;
1222
1223
1223 header->pa_bia_status_info = pa_bia_status_info;
1224 header->pa_bia_status_info = pa_bia_status_info;
1224 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1225 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1225
1226
1226 for (i=0; i<7; i++) // send waveform
1227 for (i=0; i<PKTCNT_SWF; i++) // send waveform
1227 {
1228 {
1228 spw_ioctl_send_SWF.data = (char*) &dataPtr[ (i * BLK_NR_304 * NB_WORDS_SWF_BLK) ];
1229 spw_ioctl_send_SWF.data = (char*) &dataPtr[ (i * BLK_NR_304 * NB_WORDS_SWF_BLK) ];
1229 spw_ioctl_send_SWF.hdr = (char*) header;
1230 spw_ioctl_send_SWF.hdr = (char*) header;
1230
1231
1231 // SET PACKET SEQUENCE CONTROL
1232 // SET PACKET SEQUENCE CONTROL
1232 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1233 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1233
1234
1234 // SET PACKET LENGTH AND BLKNR
1235 // SET PACKET LENGTH AND BLKNR
1235 if (i == 6)
1236 if (i == (PKTCNT_SWF-1))
1236 {
1237 {
1237 spw_ioctl_send_SWF.dlen = BLK_NR_224 * NB_BYTES_SWF_BLK;
1238 spw_ioctl_send_SWF.dlen = BLK_NR_224 * NB_BYTES_SWF_BLK;
1238 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_224 >> 8);
1239 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_224 >> SHIFT_1_BYTE);
1239 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_224 );
1240 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_224 );
1240 header->blkNr[0] = (unsigned char) (BLK_NR_224 >> 8);
1241 header->blkNr[0] = (unsigned char) (BLK_NR_224 >> SHIFT_1_BYTE);
1241 header->blkNr[1] = (unsigned char) (BLK_NR_224 );
1242 header->blkNr[1] = (unsigned char) (BLK_NR_224 );
1242 }
1243 }
1243 else
1244 else
1244 {
1245 {
1245 spw_ioctl_send_SWF.dlen = BLK_NR_304 * NB_BYTES_SWF_BLK;
1246 spw_ioctl_send_SWF.dlen = BLK_NR_304 * NB_BYTES_SWF_BLK;
1246 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_304 >> 8);
1247 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_304 >> SHIFT_1_BYTE);
1247 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_304 );
1248 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_304 );
1248 header->blkNr[0] = (unsigned char) (BLK_NR_304 >> 8);
1249 header->blkNr[0] = (unsigned char) (BLK_NR_304 >> SHIFT_1_BYTE);
1249 header->blkNr[1] = (unsigned char) (BLK_NR_304 );
1250 header->blkNr[1] = (unsigned char) (BLK_NR_304 );
1250 }
1251 }
1251
1252
1252 // SET PACKET TIME
1253 // SET PACKET TIME
1253 compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime );
1254 compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime );
1254 //
1255 //
1255 header->time[0] = header->acquisitionTime[0];
1256 header->time[BYTE_0] = header->acquisitionTime[BYTE_0];
1256 header->time[1] = header->acquisitionTime[1];
1257 header->time[BYTE_1] = header->acquisitionTime[BYTE_1];
1257 header->time[2] = header->acquisitionTime[2];
1258 header->time[BYTE_2] = header->acquisitionTime[BYTE_2];
1258 header->time[3] = header->acquisitionTime[3];
1259 header->time[BYTE_3] = header->acquisitionTime[BYTE_3];
1259 header->time[4] = header->acquisitionTime[4];
1260 header->time[BYTE_4] = header->acquisitionTime[BYTE_4];
1260 header->time[5] = header->acquisitionTime[5];
1261 header->time[BYTE_5] = header->acquisitionTime[BYTE_5];
1261
1262
1262 // SET SID
1263 // SET SID
1263 header->sid = sid;
1264 header->sid = sid;
1264
1265
1265 // SET PKTNR
1266 // SET PKTNR
1266 header->pktNr = i+1; // PKT_NR
1267 header->pktNr = i+1; // PKT_NR
1267
1268
1268 // SEND PACKET
1269 // SEND PACKET
1269 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_SWF );
1270 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_SWF );
1270 if (status != RTEMS_SUCCESSFUL) {
1271 if (status != RTEMS_SUCCESSFUL) {
1271 ret = LFR_DEFAULT;
1272 ret = LFR_DEFAULT;
1272 }
1273 }
1273 }
1274 }
1274
1275
1275 return ret;
1276 return ret;
1276 }
1277 }
1277
1278
1278 int spw_send_waveform_CWF3_light( ring_node *ring_node_to_send,
1279 int spw_send_waveform_CWF3_light( ring_node *ring_node_to_send,
1279 Header_TM_LFR_SCIENCE_CWF_t *header )
1280 Header_TM_LFR_SCIENCE_CWF_t *header )
1280 {
1281 {
1281 /** This function sends CWF_F3 CCSDS packets without the b1, b2 and b3 data.
1282 /** This function sends CWF_F3 CCSDS packets without the b1, b2 and b3 data.
1282 *
1283 *
1283 * @param waveform points to the buffer containing the data that will be send.
1284 * @param waveform points to the buffer containing the data that will be send.
1284 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
1285 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
1285 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
1286 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
1286 * contain information to setup the transmission of the data packets.
1287 * contain information to setup the transmission of the data packets.
1287 *
1288 *
1288 * By default, CWF_F3 packet are send without the b1, b2 and b3 data. This function rebuilds a data buffer
1289 * By default, CWF_F3 packet are send without the b1, b2 and b3 data. This function rebuilds a data buffer
1289 * from the incoming data and sends it in 7 packets, 6 containing 340 blocks and 1 one containing 8 blocks.
1290 * from the incoming data and sends it in 7 packets, 6 containing 340 blocks and 1 one containing 8 blocks.
1290 *
1291 *
1291 */
1292 */
1292
1293
1293 unsigned int i;
1294 unsigned int i;
1294 int ret;
1295 int ret;
1295 unsigned int coarseTime;
1296 unsigned int coarseTime;
1296 unsigned int fineTime;
1297 unsigned int fineTime;
1297 rtems_status_code status;
1298 rtems_status_code status;
1298 spw_ioctl_pkt_send spw_ioctl_send_CWF;
1299 spw_ioctl_pkt_send spw_ioctl_send_CWF;
1299 char *dataPtr;
1300 char *dataPtr;
1300 unsigned char sid;
1301 unsigned char sid;
1301
1302
1302 spw_ioctl_send_CWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_CWF;
1303 spw_ioctl_send_CWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_CWF;
1303 spw_ioctl_send_CWF.options = 0;
1304 spw_ioctl_send_CWF.options = 0;
1304
1305
1305 ret = LFR_DEFAULT;
1306 ret = LFR_DEFAULT;
1306 sid = ring_node_to_send->sid;
1307 sid = ring_node_to_send->sid;
1307
1308
1308 coarseTime = ring_node_to_send->coarseTime;
1309 coarseTime = ring_node_to_send->coarseTime;
1309 fineTime = ring_node_to_send->fineTime;
1310 fineTime = ring_node_to_send->fineTime;
1310 dataPtr = (char*) ring_node_to_send->buffer_address;
1311 dataPtr = (char*) ring_node_to_send->buffer_address;
1311
1312
1312 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_672 >> 8);
1313 header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_672 >> SHIFT_1_BYTE);
1313 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_672 );
1314 header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_672 );
1314 header->pa_bia_status_info = pa_bia_status_info;
1315 header->pa_bia_status_info = pa_bia_status_info;
1315 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1316 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1316 header->blkNr[0] = (unsigned char) (BLK_NR_CWF_SHORT_F3 >> 8);
1317 header->blkNr[0] = (unsigned char) (BLK_NR_CWF_SHORT_F3 >> SHIFT_1_BYTE);
1317 header->blkNr[1] = (unsigned char) (BLK_NR_CWF_SHORT_F3 );
1318 header->blkNr[1] = (unsigned char) (BLK_NR_CWF_SHORT_F3 );
1318
1319
1319 //*********************
1320 //*********************
1320 // SEND CWF3_light DATA
1321 // SEND CWF3_light DATA
1321 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF_LIGHT; i++) // send waveform
1322 for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF_LIGHT; i++) // send waveform
1322 {
1323 {
1323 spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK) ];
1324 spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK) ];
1324 spw_ioctl_send_CWF.hdr = (char*) header;
1325 spw_ioctl_send_CWF.hdr = (char*) header;
1325 // BUILD THE DATA
1326 // BUILD THE DATA
1326 spw_ioctl_send_CWF.dlen = BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK;
1327 spw_ioctl_send_CWF.dlen = BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK;
1327
1328
1328 // SET PACKET SEQUENCE COUNTER
1329 // SET PACKET SEQUENCE COUNTER
1329 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1330 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1330
1331
1331 // SET SID
1332 // SET SID
1332 header->sid = sid;
1333 header->sid = sid;
1333
1334
1334 // SET PACKET TIME
1335 // SET PACKET TIME
1335 compute_acquisition_time( coarseTime, fineTime, SID_NORM_CWF_F3, i, header->acquisitionTime );
1336 compute_acquisition_time( coarseTime, fineTime, SID_NORM_CWF_F3, i, header->acquisitionTime );
1336 //
1337 //
1337 header->time[0] = header->acquisitionTime[0];
1338 header->time[BYTE_0] = header->acquisitionTime[BYTE_0];
1338 header->time[1] = header->acquisitionTime[1];
1339 header->time[BYTE_1] = header->acquisitionTime[BYTE_1];
1339 header->time[2] = header->acquisitionTime[2];
1340 header->time[BYTE_2] = header->acquisitionTime[BYTE_2];
1340 header->time[3] = header->acquisitionTime[3];
1341 header->time[BYTE_3] = header->acquisitionTime[BYTE_3];
1341 header->time[4] = header->acquisitionTime[4];
1342 header->time[BYTE_4] = header->acquisitionTime[BYTE_4];
1342 header->time[5] = header->acquisitionTime[5];
1343 header->time[BYTE_5] = header->acquisitionTime[BYTE_5];
1343
1344
1344 // SET PACKET ID
1345 // SET PACKET ID
1345 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8);
1346 header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> SHIFT_1_BYTE);
1346 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1347 header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST);
1347
1348
1348 // SEND PACKET
1349 // SEND PACKET
1349 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF );
1350 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF );
1350 if (status != RTEMS_SUCCESSFUL) {
1351 if (status != RTEMS_SUCCESSFUL) {
1351 ret = LFR_DEFAULT;
1352 ret = LFR_DEFAULT;
1352 }
1353 }
1353 }
1354 }
1354
1355
1355 return ret;
1356 return ret;
1356 }
1357 }
1357
1358
1358 void spw_send_asm_f0( ring_node *ring_node_to_send,
1359 void spw_send_asm_f0( ring_node *ring_node_to_send,
1359 Header_TM_LFR_SCIENCE_ASM_t *header )
1360 Header_TM_LFR_SCIENCE_ASM_t *header )
1360 {
1361 {
1361 unsigned int i;
1362 unsigned int i;
1362 unsigned int length = 0;
1363 unsigned int length = 0;
1363 rtems_status_code status;
1364 rtems_status_code status;
1364 unsigned int sid;
1365 unsigned int sid;
1365 float *spectral_matrix;
1366 float *spectral_matrix;
1366 int coarseTime;
1367 int coarseTime;
1367 int fineTime;
1368 int fineTime;
1368 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1369 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1369
1370
1370 sid = ring_node_to_send->sid;
1371 sid = ring_node_to_send->sid;
1371 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1372 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1372 coarseTime = ring_node_to_send->coarseTime;
1373 coarseTime = ring_node_to_send->coarseTime;
1373 fineTime = ring_node_to_send->fineTime;
1374 fineTime = ring_node_to_send->fineTime;
1374
1375
1375 header->pa_bia_status_info = pa_bia_status_info;
1376 header->pa_bia_status_info = pa_bia_status_info;
1376 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1377 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1377
1378
1378 for (i=0; i<3; i++)
1379 for (i=0; i<PKTCNT_ASM; i++)
1379 {
1380 {
1380 if ((i==0) || (i==1))
1381 if ((i==0) || (i==1))
1381 {
1382 {
1382 spw_ioctl_send_ASM.dlen = DLEN_ASM_F0_PKT_1;
1383 spw_ioctl_send_ASM.dlen = DLEN_ASM_F0_PKT_1;
1383 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1384 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1384 ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0_1) ) * NB_VALUES_PER_SM )
1385 ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0_1) ) * NB_VALUES_PER_SM )
1385 ];
1386 ];
1386 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0_1;
1387 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0_1;
1387 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1388 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1388 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0_1) >> 8 ); // BLK_NR MSB
1389 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0_1) >> SHIFT_1_BYTE ); // BLK_NR MSB
1389 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0_1); // BLK_NR LSB
1390 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0_1); // BLK_NR LSB
1390 }
1391 }
1391 else
1392 else
1392 {
1393 {
1393 spw_ioctl_send_ASM.dlen = DLEN_ASM_F0_PKT_2;
1394 spw_ioctl_send_ASM.dlen = DLEN_ASM_F0_PKT_2;
1394 spw_ioctl_send_ASM.data = (char*) &spectral_matrix[
1395 spw_ioctl_send_ASM.data = (char*) &spectral_matrix[
1395 ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0_1) ) * NB_VALUES_PER_SM )
1396 ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0_1) ) * NB_VALUES_PER_SM )
1396 ];
1397 ];
1397 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0_2;
1398 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0_2;
1398 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1399 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1399 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0_2) >> 8 ); // BLK_NR MSB
1400 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0_2) >> SHIFT_1_BYTE ); // BLK_NR MSB
1400 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0_2); // BLK_NR LSB
1401 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0_2); // BLK_NR LSB
1401 }
1402 }
1402
1403
1403 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1404 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1404 spw_ioctl_send_ASM.hdr = (char *) header;
1405 spw_ioctl_send_ASM.hdr = (char *) header;
1405 spw_ioctl_send_ASM.options = 0;
1406 spw_ioctl_send_ASM.options = 0;
1406
1407
1407 // (2) BUILD THE HEADER
1408 // (2) BUILD THE HEADER
1408 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1409 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1409 header->packetLength[0] = (unsigned char) (length>>8);
1410 header->packetLength[0] = (unsigned char) (length >> SHIFT_1_BYTE);
1410 header->packetLength[1] = (unsigned char) (length);
1411 header->packetLength[1] = (unsigned char) (length);
1411 header->sid = (unsigned char) sid; // SID
1412 header->sid = (unsigned char) sid; // SID
1412 header->pa_lfr_pkt_cnt_asm = 3;
1413 header->pa_lfr_pkt_cnt_asm = PKTCNT_ASM;
1413 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1414 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1414
1415
1415 // (3) SET PACKET TIME
1416 // (3) SET PACKET TIME
1416 header->time[0] = (unsigned char) (coarseTime>>24);
1417 header->time[BYTE_0] = (unsigned char) (coarseTime >> SHIFT_3_BYTES);
1417 header->time[1] = (unsigned char) (coarseTime>>16);
1418 header->time[BYTE_1] = (unsigned char) (coarseTime >> SHIFT_2_BYTES);
1418 header->time[2] = (unsigned char) (coarseTime>>8);
1419 header->time[BYTE_2] = (unsigned char) (coarseTime >> SHIFT_1_BYTE);
1419 header->time[3] = (unsigned char) (coarseTime);
1420 header->time[BYTE_3] = (unsigned char) (coarseTime);
1420 header->time[4] = (unsigned char) (fineTime>>8);
1421 header->time[BYTE_4] = (unsigned char) (fineTime >> SHIFT_1_BYTE);
1421 header->time[5] = (unsigned char) (fineTime);
1422 header->time[BYTE_5] = (unsigned char) (fineTime);
1422 //
1423 //
1423 header->acquisitionTime[0] = header->time[0];
1424 header->acquisitionTime[BYTE_0] = header->time[BYTE_0];
1424 header->acquisitionTime[1] = header->time[1];
1425 header->acquisitionTime[BYTE_1] = header->time[BYTE_1];
1425 header->acquisitionTime[2] = header->time[2];
1426 header->acquisitionTime[BYTE_2] = header->time[BYTE_2];
1426 header->acquisitionTime[3] = header->time[3];
1427 header->acquisitionTime[BYTE_3] = header->time[BYTE_3];
1427 header->acquisitionTime[4] = header->time[4];
1428 header->acquisitionTime[BYTE_4] = header->time[BYTE_4];
1428 header->acquisitionTime[5] = header->time[5];
1429 header->acquisitionTime[BYTE_5] = header->time[BYTE_5];
1429
1430
1430 // (4) SEND PACKET
1431 // (4) SEND PACKET
1431 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1432 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1432 if (status != RTEMS_SUCCESSFUL) {
1433 if (status != RTEMS_SUCCESSFUL) {
1433 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1434 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1434 }
1435 }
1435 }
1436 }
1436 }
1437 }
1437
1438
1438 void spw_send_asm_f1( ring_node *ring_node_to_send,
1439 void spw_send_asm_f1( ring_node *ring_node_to_send,
1439 Header_TM_LFR_SCIENCE_ASM_t *header )
1440 Header_TM_LFR_SCIENCE_ASM_t *header )
1440 {
1441 {
1441 unsigned int i;
1442 unsigned int i;
1442 unsigned int length = 0;
1443 unsigned int length = 0;
1443 rtems_status_code status;
1444 rtems_status_code status;
1444 unsigned int sid;
1445 unsigned int sid;
1445 float *spectral_matrix;
1446 float *spectral_matrix;
1446 int coarseTime;
1447 int coarseTime;
1447 int fineTime;
1448 int fineTime;
1448 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1449 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1449
1450
1450 sid = ring_node_to_send->sid;
1451 sid = ring_node_to_send->sid;
1451 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1452 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1452 coarseTime = ring_node_to_send->coarseTime;
1453 coarseTime = ring_node_to_send->coarseTime;
1453 fineTime = ring_node_to_send->fineTime;
1454 fineTime = ring_node_to_send->fineTime;
1454
1455
1455 header->pa_bia_status_info = pa_bia_status_info;
1456 header->pa_bia_status_info = pa_bia_status_info;
1456 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1457 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1457
1458
1458 for (i=0; i<3; i++)
1459 for (i=0; i<PKTCNT_ASM; i++)
1459 {
1460 {
1460 if ((i==0) || (i==1))
1461 if ((i==0) || (i==1))
1461 {
1462 {
1462 spw_ioctl_send_ASM.dlen = DLEN_ASM_F1_PKT_1;
1463 spw_ioctl_send_ASM.dlen = DLEN_ASM_F1_PKT_1;
1463 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1464 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1464 ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1_1) ) * NB_VALUES_PER_SM )
1465 ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1_1) ) * NB_VALUES_PER_SM )
1465 ];
1466 ];
1466 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1_1;
1467 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1_1;
1467 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1468 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1468 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1_1) >> 8 ); // BLK_NR MSB
1469 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1_1) >> SHIFT_1_BYTE ); // BLK_NR MSB
1469 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1_1); // BLK_NR LSB
1470 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1_1); // BLK_NR LSB
1470 }
1471 }
1471 else
1472 else
1472 {
1473 {
1473 spw_ioctl_send_ASM.dlen = DLEN_ASM_F1_PKT_2;
1474 spw_ioctl_send_ASM.dlen = DLEN_ASM_F1_PKT_2;
1474 spw_ioctl_send_ASM.data = (char*) &spectral_matrix[
1475 spw_ioctl_send_ASM.data = (char*) &spectral_matrix[
1475 ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1_1) ) * NB_VALUES_PER_SM )
1476 ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1_1) ) * NB_VALUES_PER_SM )
1476 ];
1477 ];
1477 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1_2;
1478 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1_2;
1478 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1479 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6;
1479 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1_2) >> 8 ); // BLK_NR MSB
1480 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1_2) >> SHIFT_1_BYTE ); // BLK_NR MSB
1480 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1_2); // BLK_NR LSB
1481 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1_2); // BLK_NR LSB
1481 }
1482 }
1482
1483
1483 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1484 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1484 spw_ioctl_send_ASM.hdr = (char *) header;
1485 spw_ioctl_send_ASM.hdr = (char *) header;
1485 spw_ioctl_send_ASM.options = 0;
1486 spw_ioctl_send_ASM.options = 0;
1486
1487
1487 // (2) BUILD THE HEADER
1488 // (2) BUILD THE HEADER
1488 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1489 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1489 header->packetLength[0] = (unsigned char) (length>>8);
1490 header->packetLength[0] = (unsigned char) (length >> SHIFT_1_BYTE);
1490 header->packetLength[1] = (unsigned char) (length);
1491 header->packetLength[1] = (unsigned char) (length);
1491 header->sid = (unsigned char) sid; // SID
1492 header->sid = (unsigned char) sid; // SID
1492 header->pa_lfr_pkt_cnt_asm = 3;
1493 header->pa_lfr_pkt_cnt_asm = PKTCNT_ASM;
1493 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1494 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1494
1495
1495 // (3) SET PACKET TIME
1496 // (3) SET PACKET TIME
1496 header->time[0] = (unsigned char) (coarseTime>>24);
1497 header->time[BYTE_0] = (unsigned char) (coarseTime >> SHIFT_3_BYTES);
1497 header->time[1] = (unsigned char) (coarseTime>>16);
1498 header->time[BYTE_1] = (unsigned char) (coarseTime >> SHIFT_2_BYTES);
1498 header->time[2] = (unsigned char) (coarseTime>>8);
1499 header->time[BYTE_2] = (unsigned char) (coarseTime >> SHIFT_1_BYTE);
1499 header->time[3] = (unsigned char) (coarseTime);
1500 header->time[BYTE_3] = (unsigned char) (coarseTime);
1500 header->time[4] = (unsigned char) (fineTime>>8);
1501 header->time[BYTE_4] = (unsigned char) (fineTime >> SHIFT_1_BYTE);
1501 header->time[5] = (unsigned char) (fineTime);
1502 header->time[BYTE_5] = (unsigned char) (fineTime);
1502 //
1503 //
1503 header->acquisitionTime[0] = header->time[0];
1504 header->acquisitionTime[BYTE_0] = header->time[BYTE_0];
1504 header->acquisitionTime[1] = header->time[1];
1505 header->acquisitionTime[BYTE_1] = header->time[BYTE_1];
1505 header->acquisitionTime[2] = header->time[2];
1506 header->acquisitionTime[BYTE_2] = header->time[BYTE_2];
1506 header->acquisitionTime[3] = header->time[3];
1507 header->acquisitionTime[BYTE_3] = header->time[BYTE_3];
1507 header->acquisitionTime[4] = header->time[4];
1508 header->acquisitionTime[BYTE_4] = header->time[BYTE_4];
1508 header->acquisitionTime[5] = header->time[5];
1509 header->acquisitionTime[BYTE_5] = header->time[BYTE_5];
1509
1510
1510 // (4) SEND PACKET
1511 // (4) SEND PACKET
1511 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1512 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1512 if (status != RTEMS_SUCCESSFUL) {
1513 if (status != RTEMS_SUCCESSFUL) {
1513 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1514 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1514 }
1515 }
1515 }
1516 }
1516 }
1517 }
1517
1518
1518 void spw_send_asm_f2( ring_node *ring_node_to_send,
1519 void spw_send_asm_f2( ring_node *ring_node_to_send,
1519 Header_TM_LFR_SCIENCE_ASM_t *header )
1520 Header_TM_LFR_SCIENCE_ASM_t *header )
1520 {
1521 {
1521 unsigned int i;
1522 unsigned int i;
1522 unsigned int length = 0;
1523 unsigned int length = 0;
1523 rtems_status_code status;
1524 rtems_status_code status;
1524 unsigned int sid;
1525 unsigned int sid;
1525 float *spectral_matrix;
1526 float *spectral_matrix;
1526 int coarseTime;
1527 int coarseTime;
1527 int fineTime;
1528 int fineTime;
1528 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1529 spw_ioctl_pkt_send spw_ioctl_send_ASM;
1529
1530
1530 sid = ring_node_to_send->sid;
1531 sid = ring_node_to_send->sid;
1531 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1532 spectral_matrix = (float*) ring_node_to_send->buffer_address;
1532 coarseTime = ring_node_to_send->coarseTime;
1533 coarseTime = ring_node_to_send->coarseTime;
1533 fineTime = ring_node_to_send->fineTime;
1534 fineTime = ring_node_to_send->fineTime;
1534
1535
1535 header->pa_bia_status_info = pa_bia_status_info;
1536 header->pa_bia_status_info = pa_bia_status_info;
1536 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1537 header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
1537
1538
1538 for (i=0; i<3; i++)
1539 for (i=0; i<PKTCNT_ASM; i++)
1539 {
1540 {
1540
1541
1541 spw_ioctl_send_ASM.dlen = DLEN_ASM_F2_PKT;
1542 spw_ioctl_send_ASM.dlen = DLEN_ASM_F2_PKT;
1542 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1543 spw_ioctl_send_ASM.data = (char *) &spectral_matrix[
1543 ( (ASM_F2_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F2) ) * NB_VALUES_PER_SM )
1544 ( (ASM_F2_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F2) ) * NB_VALUES_PER_SM )
1544 ];
1545 ];
1545 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F2;
1546 length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F2;
1546 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3;
1547 header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3;
1547 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F2) >> 8 ); // BLK_NR MSB
1548 header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F2) >> SHIFT_1_BYTE ); // BLK_NR MSB
1548 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F2); // BLK_NR LSB
1549 header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F2); // BLK_NR LSB
1549
1550
1550 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1551 spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM;
1551 spw_ioctl_send_ASM.hdr = (char *) header;
1552 spw_ioctl_send_ASM.hdr = (char *) header;
1552 spw_ioctl_send_ASM.options = 0;
1553 spw_ioctl_send_ASM.options = 0;
1553
1554
1554 // (2) BUILD THE HEADER
1555 // (2) BUILD THE HEADER
1555 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1556 increment_seq_counter_source_id( header->packetSequenceControl, sid );
1556 header->packetLength[0] = (unsigned char) (length>>8);
1557 header->packetLength[0] = (unsigned char) (length >> SHIFT_1_BYTE);
1557 header->packetLength[1] = (unsigned char) (length);
1558 header->packetLength[1] = (unsigned char) (length);
1558 header->sid = (unsigned char) sid; // SID
1559 header->sid = (unsigned char) sid; // SID
1559 header->pa_lfr_pkt_cnt_asm = 3;
1560 header->pa_lfr_pkt_cnt_asm = PKTCNT_ASM;
1560 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1561 header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1);
1561
1562
1562 // (3) SET PACKET TIME
1563 // (3) SET PACKET TIME
1563 header->time[0] = (unsigned char) (coarseTime>>24);
1564 header->time[BYTE_0] = (unsigned char) (coarseTime >> SHIFT_3_BYTES);
1564 header->time[1] = (unsigned char) (coarseTime>>16);
1565 header->time[BYTE_1] = (unsigned char) (coarseTime >> SHIFT_2_BYTES);
1565 header->time[2] = (unsigned char) (coarseTime>>8);
1566 header->time[BYTE_2] = (unsigned char) (coarseTime >> SHIFT_1_BYTE);
1566 header->time[3] = (unsigned char) (coarseTime);
1567 header->time[BYTE_3] = (unsigned char) (coarseTime);
1567 header->time[4] = (unsigned char) (fineTime>>8);
1568 header->time[BYTE_4] = (unsigned char) (fineTime >> SHIFT_1_BYTE);
1568 header->time[5] = (unsigned char) (fineTime);
1569 header->time[BYTE_5] = (unsigned char) (fineTime);
1569 //
1570 //
1570 header->acquisitionTime[0] = header->time[0];
1571 header->acquisitionTime[BYTE_0] = header->time[BYTE_0];
1571 header->acquisitionTime[1] = header->time[1];
1572 header->acquisitionTime[BYTE_1] = header->time[BYTE_1];
1572 header->acquisitionTime[2] = header->time[2];
1573 header->acquisitionTime[BYTE_2] = header->time[BYTE_2];
1573 header->acquisitionTime[3] = header->time[3];
1574 header->acquisitionTime[BYTE_3] = header->time[BYTE_3];
1574 header->acquisitionTime[4] = header->time[4];
1575 header->acquisitionTime[BYTE_4] = header->time[BYTE_4];
1575 header->acquisitionTime[5] = header->time[5];
1576 header->acquisitionTime[BYTE_5] = header->time[BYTE_5];
1576
1577
1577 // (4) SEND PACKET
1578 // (4) SEND PACKET
1578 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1579 status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM );
1579 if (status != RTEMS_SUCCESSFUL) {
1580 if (status != RTEMS_SUCCESSFUL) {
1580 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1581 PRINTF1("in ASM_send *** ERR %d\n", (int) status)
1581 }
1582 }
1582 }
1583 }
1583 }
1584 }
1584
1585
1585 void spw_send_k_dump( ring_node *ring_node_to_send )
1586 void spw_send_k_dump( ring_node *ring_node_to_send )
1586 {
1587 {
1587 rtems_status_code status;
1588 rtems_status_code status;
1588 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump;
1589 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump;
1589 unsigned int packetLength;
1590 unsigned int packetLength;
1590 unsigned int size;
1591 unsigned int size;
1591
1592
1592 PRINTF("spw_send_k_dump\n")
1593 PRINTF("spw_send_k_dump\n")
1593
1594
1594 kcoefficients_dump = (Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *) ring_node_to_send->buffer_address;
1595 kcoefficients_dump = (Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *) ring_node_to_send->buffer_address;
1595
1596
1596 packetLength = kcoefficients_dump->packetLength[0] * 256 + kcoefficients_dump->packetLength[1];
1597 packetLength = (kcoefficients_dump->packetLength[0] * CONST_256) + kcoefficients_dump->packetLength[1];
1597
1598
1598 size = packetLength + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
1599 size = packetLength + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
1599
1600
1600 PRINTF2("packetLength %d, size %d\n", packetLength, size )
1601 PRINTF2("packetLength %d, size %d\n", packetLength, size )
1601
1602
1602 status = write( fdSPW, (char *) ring_node_to_send->buffer_address, size );
1603 status = write( fdSPW, (char *) ring_node_to_send->buffer_address, size );
1603
1604
1604 if (status == -1){
1605 if (status == -1){
1605 PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size)
1606 PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size)
1606 }
1607 }
1607
1608
1608 ring_node_to_send->status = 0x00;
1609 ring_node_to_send->status = INIT_CHAR;
1609 }
1610 }
@@ -1,115 +1,116
1 /*
1 /*
2 * CPU Usage Reporter
2 * CPU Usage Reporter
3 *
3 *
4 * COPYRIGHT (c) 1989-2009
4 * COPYRIGHT (c) 1989-2009
5 * On-Line Applications Research Corporation (OAR).
5 * On-Line Applications Research Corporation (OAR).
6 *
6 *
7 * The license and distribution terms for this file may be
7 * The license and distribution terms for this file may be
8 * found in the file LICENSE in this distribution or at
8 * found in the file LICENSE in this distribution or at
9 * http://www.rtems.com/license/LICENSE.
9 * http://www.rtems.com/license/LICENSE.
10 *
10 *
11 * $Id$
11 * $Id$
12 */
12 */
13
13
14 #include "lfr_cpu_usage_report.h"
14 #include "lfr_cpu_usage_report.h"
15
15
16 unsigned char lfr_rtems_cpu_usage_report( void )
16 unsigned char lfr_rtems_cpu_usage_report( void )
17 {
17 {
18 uint32_t api_index;
18 uint32_t api_index;
19 Thread_Control *the_thread;
19 Thread_Control *the_thread;
20 Objects_Information *information;
20 Objects_Information *information;
21 uint32_t ival, fval;
21 uint32_t ival;
22 uint32_t fval;
22 #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
23 #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
23 Timestamp_Control uptime;
24 Timestamp_Control uptime;
24 Timestamp_Control total;
25 Timestamp_Control total;
25 Timestamp_Control ran;
26 Timestamp_Control ran;
26 #else
27 #else
27 uint32_t total_units = 0;
28 uint32_t total_units = 0;
28 #endif
29 #endif
29
30
30 unsigned char cpu_load;
31 unsigned char cpu_load;
31 cpu_load = 0;
32 cpu_load = 0;
32
33
33 /*
34 /*
34 * When not using nanosecond CPU usage resolution, we have to count
35 * When not using nanosecond CPU usage resolution, we have to count
35 * the number of "ticks" we gave credit for to give the user a rough
36 * the number of "ticks" we gave credit for to give the user a rough
36 * guideline as to what each number means proportionally.
37 * guideline as to what each number means proportionally.
37 */
38 */
38 #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
39 #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
39 _TOD_Get_uptime( &uptime );
40 _TOD_Get_uptime( &uptime );
40 _Timestamp_Subtract( &CPU_usage_Uptime_at_last_reset, &uptime, &total );
41 _Timestamp_Subtract( &CPU_usage_Uptime_at_last_reset, &uptime, &total );
41 #else
42 #else
42 for ( api_index = 1 ; api_index <= OBJECTS_APIS_LAST ; api_index++ ) {
43 for ( api_index = 1 ; api_index <= OBJECTS_APIS_LAST ; api_index++ ) {
43 if ( !_Objects_Information_table[ api_index ] ) { }
44 if ( !_Objects_Information_table[ api_index ] ) { }
44 else
45 else
45 {
46 {
46 information = _Objects_Information_table[ api_index ][ 1 ];
47 information = _Objects_Information_table[ api_index ][ 1 ];
47 if ( information != NULL )
48 if ( information != NULL )
48 {
49 {
49 for ( i=1 ; i <= information->maximum ; i++ ) {
50 for ( i=1 ; i <= information->maximum ; i++ ) {
50 the_thread = (Thread_Control *)information->local_table[ i ];
51 the_thread = (Thread_Control *)information->local_table[ i ];
51
52
52 if ( the_thread != NULL ) {
53 if ( the_thread != NULL ) {
53 total_units += the_thread->cpu_time_used; }
54 total_units += the_thread->cpu_time_used; }
54 }
55 }
55 }
56 }
56 }
57 }
57 }
58 }
58 #endif
59 #endif
59
60
60 for ( api_index = 1 ; api_index <= OBJECTS_APIS_LAST ; api_index++ )
61 for ( api_index = 1 ; api_index <= OBJECTS_APIS_LAST ; api_index++ )
61 {
62 {
62 if ( !_Objects_Information_table[ api_index ] ) { }
63 if ( !_Objects_Information_table[ api_index ] ) { }
63 else
64 else
64 {
65 {
65 information = _Objects_Information_table[ api_index ][ 1 ];
66 information = _Objects_Information_table[ api_index ][ 1 ];
66 if ( information != NULL )
67 if ( information != NULL )
67 {
68 {
68 the_thread = (Thread_Control *)information->local_table[ 1 ];
69 the_thread = (Thread_Control *)information->local_table[ 1 ];
69
70
70 if ( the_thread == NULL ) { }
71 if ( the_thread == NULL ) { }
71 else
72 else
72 {
73 {
73 #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
74 #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
74 /*
75 /*
75 * If this is the currently executing thread, account for time
76 * If this is the currently executing thread, account for time
76 * since the last context switch.
77 * since the last context switch.
77 */
78 */
78 ran = the_thread->cpu_time_used;
79 ran = the_thread->cpu_time_used;
79 if ( _Thread_Executing->Object.id == the_thread->Object.id )
80 if ( _Thread_Executing->Object.id == the_thread->Object.id )
80 {
81 {
81 Timestamp_Control used;
82 Timestamp_Control used;
82 _Timestamp_Subtract(
83 _Timestamp_Subtract(
83 &_Thread_Time_of_last_context_switch, &uptime, &used
84 &_Thread_Time_of_last_context_switch, &uptime, &used
84 );
85 );
85 _Timestamp_Add_to( &ran, &used );
86 _Timestamp_Add_to( &ran, &used );
86 }
87 }
87 _Timestamp_Divide( &ran, &total, &ival, &fval );
88 _Timestamp_Divide( &ran, &total, &ival, &fval );
88
89
89 #else
90 #else
90 if (total_units != 0)
91 if (total_units != 0)
91 {
92 {
92 uint64_t ival_64;
93 uint64_t ival_64;
93
94
94 ival_64 = the_thread->cpu_time_used;
95 ival_64 = the_thread->cpu_time_used;
95 ival_64 *= 100000;
96 ival_64 *= CONST_100000;
96 ival = ival_64 / total_units;
97 ival = ival_64 / total_units;
97 }
98 }
98 else
99 else
99 {
100 {
100 ival = 0;
101 ival = 0;
101 }
102 }
102
103
103 fval = ival % 1000;
104 fval = ival % CONST_1000;
104 ival /= 1000;
105 ival /= CONST_1000;
105 #endif
106 #endif
106 }
107 }
107 }
108 }
108 }
109 }
109 }
110 }
110 cpu_load = (unsigned char) (100 - ival);
111 cpu_load = (unsigned char) (CONST_100 - ival);
111
112
112 return cpu_load;
113 return cpu_load;
113 }
114 }
114
115
115
116
@@ -1,414 +1,414
1 /** Functions related to data processing.
1 /** Functions related to data processing.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
6 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
7 *
7 *
8 */
8 */
9
9
10 #include "avf0_prc0.h"
10 #include "avf0_prc0.h"
11 #include "fsw_processing.h"
11 #include "fsw_processing.h"
12
12
13 nb_sm_before_bp_asm_f0 nb_sm_before_f0;
13 nb_sm_before_bp_asm_f0 nb_sm_before_f0;
14
14
15 //***
15 //***
16 // F0
16 // F0
17 ring_node_asm asm_ring_norm_f0 [ NB_RING_NODES_ASM_NORM_F0 ];
17 ring_node_asm asm_ring_norm_f0 [ NB_RING_NODES_ASM_NORM_F0 ];
18 ring_node_asm asm_ring_burst_sbm_f0 [ NB_RING_NODES_ASM_BURST_SBM_F0 ];
18 ring_node_asm asm_ring_burst_sbm_f0 [ NB_RING_NODES_ASM_BURST_SBM_F0 ];
19
19
20 ring_node ring_to_send_asm_f0 [ NB_RING_NODES_ASM_F0 ];
20 ring_node ring_to_send_asm_f0 [ NB_RING_NODES_ASM_F0 ];
21 int buffer_asm_f0 [ NB_RING_NODES_ASM_F0 * TOTAL_SIZE_SM ];
21 int buffer_asm_f0 [ NB_RING_NODES_ASM_F0 * TOTAL_SIZE_SM ];
22
22
23 float asm_f0_patched_norm [ TOTAL_SIZE_SM ];
23 float asm_f0_patched_norm [ TOTAL_SIZE_SM ];
24 float asm_f0_patched_burst_sbm [ TOTAL_SIZE_SM ];
24 float asm_f0_patched_burst_sbm [ TOTAL_SIZE_SM ];
25 float asm_f0_reorganized [ TOTAL_SIZE_SM ];
25 float asm_f0_reorganized [ TOTAL_SIZE_SM ];
26
26
27 char asm_f0_char [ TIME_OFFSET_IN_BYTES + (TOTAL_SIZE_SM * 2) ];
28 float compressed_sm_norm_f0[ TOTAL_SIZE_COMPRESSED_ASM_NORM_F0];
27 float compressed_sm_norm_f0[ TOTAL_SIZE_COMPRESSED_ASM_NORM_F0];
29 float compressed_sm_sbm_f0 [ TOTAL_SIZE_COMPRESSED_ASM_SBM_F0 ];
28 float compressed_sm_sbm_f0 [ TOTAL_SIZE_COMPRESSED_ASM_SBM_F0 ];
30
29
31 float k_coeff_intercalib_f0_norm[ NB_BINS_COMPRESSED_SM_F0 * NB_K_COEFF_PER_BIN ]; // 11 * 32 = 352
30 float k_coeff_intercalib_f0_norm[ NB_BINS_COMPRESSED_SM_F0 * NB_K_COEFF_PER_BIN ]; // 11 * 32 = 352
32 float k_coeff_intercalib_f0_sbm[ NB_BINS_COMPRESSED_SM_SBM_F0 * NB_K_COEFF_PER_BIN ]; // 22 * 32 = 704
31 float k_coeff_intercalib_f0_sbm[ NB_BINS_COMPRESSED_SM_SBM_F0 * NB_K_COEFF_PER_BIN ]; // 22 * 32 = 704
33
32
34 //************
33 //************
35 // RTEMS TASKS
34 // RTEMS TASKS
36
35
37 rtems_task avf0_task( rtems_task_argument lfrRequestedMode )
36 rtems_task avf0_task( rtems_task_argument lfrRequestedMode )
38 {
37 {
39 int i;
38 int i;
40
39
41 rtems_event_set event_out;
40 rtems_event_set event_out;
42 rtems_status_code status;
41 rtems_status_code status;
43 rtems_id queue_id_prc0;
42 rtems_id queue_id_prc0;
44 asm_msg msgForPRC;
43 asm_msg msgForPRC;
45 ring_node *nodeForAveraging;
44 ring_node *nodeForAveraging;
46 ring_node *ring_node_tab[8];
45 ring_node *ring_node_tab[NB_SM_BEFORE_AVF0_F1];
47 ring_node_asm *current_ring_node_asm_burst_sbm_f0;
46 ring_node_asm *current_ring_node_asm_burst_sbm_f0;
48 ring_node_asm *current_ring_node_asm_norm_f0;
47 ring_node_asm *current_ring_node_asm_norm_f0;
49
48
50 unsigned int nb_norm_bp1;
49 unsigned int nb_norm_bp1;
51 unsigned int nb_norm_bp2;
50 unsigned int nb_norm_bp2;
52 unsigned int nb_norm_asm;
51 unsigned int nb_norm_asm;
53 unsigned int nb_sbm_bp1;
52 unsigned int nb_sbm_bp1;
54 unsigned int nb_sbm_bp2;
53 unsigned int nb_sbm_bp2;
55
54
56 nb_norm_bp1 = 0;
55 nb_norm_bp1 = 0;
57 nb_norm_bp2 = 0;
56 nb_norm_bp2 = 0;
58 nb_norm_asm = 0;
57 nb_norm_asm = 0;
59 nb_sbm_bp1 = 0;
58 nb_sbm_bp1 = 0;
60 nb_sbm_bp2 = 0;
59 nb_sbm_bp2 = 0;
61
60
62 reset_nb_sm_f0( lfrRequestedMode ); // reset the sm counters that drive the BP and ASM computations / transmissions
61 reset_nb_sm_f0( lfrRequestedMode ); // reset the sm counters that drive the BP and ASM computations / transmissions
63 ASM_generic_init_ring( asm_ring_norm_f0, NB_RING_NODES_ASM_NORM_F0 );
62 ASM_generic_init_ring( asm_ring_norm_f0, NB_RING_NODES_ASM_NORM_F0 );
64 ASM_generic_init_ring( asm_ring_burst_sbm_f0, NB_RING_NODES_ASM_BURST_SBM_F0 );
63 ASM_generic_init_ring( asm_ring_burst_sbm_f0, NB_RING_NODES_ASM_BURST_SBM_F0 );
65 current_ring_node_asm_norm_f0 = asm_ring_norm_f0;
64 current_ring_node_asm_norm_f0 = asm_ring_norm_f0;
66 current_ring_node_asm_burst_sbm_f0 = asm_ring_burst_sbm_f0;
65 current_ring_node_asm_burst_sbm_f0 = asm_ring_burst_sbm_f0;
67
66
68 BOOT_PRINTF1("in AVFO *** lfrRequestedMode = %d\n", (int) lfrRequestedMode)
67 BOOT_PRINTF1("in AVFO *** lfrRequestedMode = %d\n", (int) lfrRequestedMode)
69
68
70 status = get_message_queue_id_prc0( &queue_id_prc0 );
69 status = get_message_queue_id_prc0( &queue_id_prc0 );
71 if (status != RTEMS_SUCCESSFUL)
70 if (status != RTEMS_SUCCESSFUL)
72 {
71 {
73 PRINTF1("in MATR *** ERR get_message_queue_id_prc0 %d\n", status)
72 PRINTF1("in MATR *** ERR get_message_queue_id_prc0 %d\n", status)
74 }
73 }
75
74
76 while(1){
75 while(1){
77 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
76 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
78
77
79 //****************************************
78 //****************************************
80 // initialize the mesage for the MATR task
79 // initialize the mesage for the MATR task
81 msgForPRC.norm = current_ring_node_asm_norm_f0;
80 msgForPRC.norm = current_ring_node_asm_norm_f0;
82 msgForPRC.burst_sbm = current_ring_node_asm_burst_sbm_f0;
81 msgForPRC.burst_sbm = current_ring_node_asm_burst_sbm_f0;
83 msgForPRC.event = 0x00; // this composite event will be sent to the PRC0 task
82 msgForPRC.event = EVENT_SETS_NONE_PENDING; // this composite event will be sent to the PRC0 task
84 //
83 //
85 //****************************************
84 //****************************************
86
85
87 nodeForAveraging = getRingNodeForAveraging( 0 );
86 nodeForAveraging = getRingNodeForAveraging( 0 );
88
87
89 ring_node_tab[NB_SM_BEFORE_AVF0-1] = nodeForAveraging;
88 ring_node_tab[NB_SM_BEFORE_AVF0_F1-1] = nodeForAveraging;
90 for ( i = 2; i < (NB_SM_BEFORE_AVF0+1); i++ )
89 for ( i = 1; i < (NB_SM_BEFORE_AVF0_F1); i++ )
91 {
90 {
92 nodeForAveraging = nodeForAveraging->previous;
91 nodeForAveraging = nodeForAveraging->previous;
93 ring_node_tab[NB_SM_BEFORE_AVF0-i] = nodeForAveraging;
92 ring_node_tab[NB_SM_BEFORE_AVF0_F1-i] = nodeForAveraging;
94 }
93 }
95
94
96 // compute the average and store it in the averaged_sm_f1 buffer
95 // compute the average and store it in the averaged_sm_f1 buffer
97 SM_average( current_ring_node_asm_norm_f0->matrix,
96 SM_average( current_ring_node_asm_norm_f0->matrix,
98 current_ring_node_asm_burst_sbm_f0->matrix,
97 current_ring_node_asm_burst_sbm_f0->matrix,
99 ring_node_tab,
98 ring_node_tab,
100 nb_norm_bp1, nb_sbm_bp1,
99 nb_norm_bp1, nb_sbm_bp1,
101 &msgForPRC, 0 ); // 0 => frequency channel 0
100 &msgForPRC, 0 ); // 0 => frequency channel 0
102
101
103 // update nb_average
102 // update nb_average
104 nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF0;
103 nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF0_F1;
105 nb_norm_bp2 = nb_norm_bp2 + NB_SM_BEFORE_AVF0;
104 nb_norm_bp2 = nb_norm_bp2 + NB_SM_BEFORE_AVF0_F1;
106 nb_norm_asm = nb_norm_asm + NB_SM_BEFORE_AVF0;
105 nb_norm_asm = nb_norm_asm + NB_SM_BEFORE_AVF0_F1;
107 nb_sbm_bp1 = nb_sbm_bp1 + NB_SM_BEFORE_AVF0;
106 nb_sbm_bp1 = nb_sbm_bp1 + NB_SM_BEFORE_AVF0_F1;
108 nb_sbm_bp2 = nb_sbm_bp2 + NB_SM_BEFORE_AVF0;
107 nb_sbm_bp2 = nb_sbm_bp2 + NB_SM_BEFORE_AVF0_F1;
109
108
110 if (nb_sbm_bp1 == nb_sm_before_f0.burst_sbm_bp1)
109 if (nb_sbm_bp1 == nb_sm_before_f0.burst_sbm_bp1)
111 {
110 {
112 nb_sbm_bp1 = 0;
111 nb_sbm_bp1 = 0;
113 // set another ring for the ASM storage
112 // set another ring for the ASM storage
114 current_ring_node_asm_burst_sbm_f0 = current_ring_node_asm_burst_sbm_f0->next;
113 current_ring_node_asm_burst_sbm_f0 = current_ring_node_asm_burst_sbm_f0->next;
115 if ( lfrCurrentMode == LFR_MODE_BURST )
114 if ( lfrCurrentMode == LFR_MODE_BURST )
116 {
115 {
117 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_BURST_BP1_F0;
116 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_BURST_BP1_F0;
118 }
117 }
119 else if ( (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
118 else if ( (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
120 {
119 {
121 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_SBM_BP1_F0;
120 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_SBM_BP1_F0;
122 }
121 }
123 }
122 }
124
123
125 if (nb_sbm_bp2 == nb_sm_before_f0.burst_sbm_bp2)
124 if (nb_sbm_bp2 == nb_sm_before_f0.burst_sbm_bp2)
126 {
125 {
127 nb_sbm_bp2 = 0;
126 nb_sbm_bp2 = 0;
128 if ( lfrCurrentMode == LFR_MODE_BURST )
127 if ( lfrCurrentMode == LFR_MODE_BURST )
129 {
128 {
130 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_BURST_BP2_F0;
129 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_BURST_BP2_F0;
131 }
130 }
132 else if ( (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
131 else if ( (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
133 {
132 {
134 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_SBM_BP2_F0;
133 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_SBM_BP2_F0;
135 }
134 }
136 }
135 }
137
136
138 if (nb_norm_bp1 == nb_sm_before_f0.norm_bp1)
137 if (nb_norm_bp1 == nb_sm_before_f0.norm_bp1)
139 {
138 {
140 nb_norm_bp1 = 0;
139 nb_norm_bp1 = 0;
141 // set another ring for the ASM storage
140 // set another ring for the ASM storage
142 current_ring_node_asm_norm_f0 = current_ring_node_asm_norm_f0->next;
141 current_ring_node_asm_norm_f0 = current_ring_node_asm_norm_f0->next;
143 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
142 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
144 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
143 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
145 {
144 {
146 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP1_F0;
145 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP1_F0;
147 }
146 }
148 }
147 }
149
148
150 if (nb_norm_bp2 == nb_sm_before_f0.norm_bp2)
149 if (nb_norm_bp2 == nb_sm_before_f0.norm_bp2)
151 {
150 {
152 nb_norm_bp2 = 0;
151 nb_norm_bp2 = 0;
153 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
152 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
154 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
153 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
155 {
154 {
156 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP2_F0;
155 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP2_F0;
157 }
156 }
158 }
157 }
159
158
160 if (nb_norm_asm == nb_sm_before_f0.norm_asm)
159 if (nb_norm_asm == nb_sm_before_f0.norm_asm)
161 {
160 {
162 nb_norm_asm = 0;
161 nb_norm_asm = 0;
163 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
162 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
164 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
163 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
165 {
164 {
166 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_ASM_F0;
165 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_ASM_F0;
167 }
166 }
168 }
167 }
169
168
170 //*************************
169 //*************************
171 // send the message to PRC
170 // send the message to PRC
172 if (msgForPRC.event != 0x00)
171 if (msgForPRC.event != EVENT_SETS_NONE_PENDING)
173 {
172 {
174 status = rtems_message_queue_send( queue_id_prc0, (char *) &msgForPRC, MSG_QUEUE_SIZE_PRC0);
173 status = rtems_message_queue_send( queue_id_prc0, (char *) &msgForPRC, MSG_QUEUE_SIZE_PRC0);
175 }
174 }
176
175
177 if (status != RTEMS_SUCCESSFUL) {
176 if (status != RTEMS_SUCCESSFUL) {
178 PRINTF1("in AVF0 *** Error sending message to PRC, code %d\n", status)
177 PRINTF1("in AVF0 *** Error sending message to PRC, code %d\n", status)
179 }
178 }
180 }
179 }
181 }
180 }
182
181
183 rtems_task prc0_task( rtems_task_argument lfrRequestedMode )
182 rtems_task prc0_task( rtems_task_argument lfrRequestedMode )
184 {
183 {
185 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
184 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
186 size_t size; // size of the incoming TC packet
185 size_t size; // size of the incoming TC packet
187 asm_msg *incomingMsg;
186 asm_msg *incomingMsg;
188 //
187 //
189 unsigned char sid;
188 unsigned char sid;
190 rtems_status_code status;
189 rtems_status_code status;
191 rtems_id queue_id;
190 rtems_id queue_id;
192 rtems_id queue_id_q_p0;
191 rtems_id queue_id_q_p0;
193 bp_packet_with_spare packet_norm_bp1;
192 bp_packet_with_spare packet_norm_bp1;
194 bp_packet packet_norm_bp2;
193 bp_packet packet_norm_bp2;
195 bp_packet packet_sbm_bp1;
194 bp_packet packet_sbm_bp1;
196 bp_packet packet_sbm_bp2;
195 bp_packet packet_sbm_bp2;
197 ring_node *current_ring_node_to_send_asm_f0;
196 ring_node *current_ring_node_to_send_asm_f0;
198 float nbSMInASMNORM;
197 float nbSMInASMNORM;
199 float nbSMInASMSBM;
198 float nbSMInASMSBM;
200
199
201 // init the ring of the averaged spectral matrices which will be transmitted to the DPU
200 // init the ring of the averaged spectral matrices which will be transmitted to the DPU
202 init_ring( ring_to_send_asm_f0, NB_RING_NODES_ASM_F0, (volatile int*) buffer_asm_f0, TOTAL_SIZE_SM );
201 init_ring( ring_to_send_asm_f0, NB_RING_NODES_ASM_F0, (volatile int*) buffer_asm_f0, TOTAL_SIZE_SM );
203 current_ring_node_to_send_asm_f0 = ring_to_send_asm_f0;
202 current_ring_node_to_send_asm_f0 = ring_to_send_asm_f0;
204
203
205 //*************
204 //*************
206 // NORM headers
205 // NORM headers
207 BP_init_header_with_spare( &packet_norm_bp1,
206 BP_init_header_with_spare( &packet_norm_bp1,
208 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP1_F0,
207 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP1_F0,
209 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F0, NB_BINS_COMPRESSED_SM_F0 );
208 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F0, NB_BINS_COMPRESSED_SM_F0 );
210 BP_init_header( &packet_norm_bp2,
209 BP_init_header( &packet_norm_bp2,
211 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP2_F0,
210 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP2_F0,
212 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F0, NB_BINS_COMPRESSED_SM_F0);
211 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F0, NB_BINS_COMPRESSED_SM_F0);
213
212
214 //****************************
213 //****************************
215 // BURST SBM1 and SBM2 headers
214 // BURST SBM1 and SBM2 headers
216 if ( lfrRequestedMode == LFR_MODE_BURST )
215 if ( lfrRequestedMode == LFR_MODE_BURST )
217 {
216 {
218 BP_init_header( &packet_sbm_bp1,
217 BP_init_header( &packet_sbm_bp1,
219 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP1_F0,
218 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP1_F0,
220 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
219 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
221 BP_init_header( &packet_sbm_bp2,
220 BP_init_header( &packet_sbm_bp2,
222 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP2_F0,
221 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP2_F0,
223 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
222 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
224 }
223 }
225 else if ( lfrRequestedMode == LFR_MODE_SBM1 )
224 else if ( lfrRequestedMode == LFR_MODE_SBM1 )
226 {
225 {
227 BP_init_header( &packet_sbm_bp1,
226 BP_init_header( &packet_sbm_bp1,
228 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM1_BP1_F0,
227 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM1_BP1_F0,
229 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
228 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
230 BP_init_header( &packet_sbm_bp2,
229 BP_init_header( &packet_sbm_bp2,
231 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM1_BP2_F0,
230 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM1_BP2_F0,
232 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
231 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
233 }
232 }
234 else if ( lfrRequestedMode == LFR_MODE_SBM2 )
233 else if ( lfrRequestedMode == LFR_MODE_SBM2 )
235 {
234 {
236 BP_init_header( &packet_sbm_bp1,
235 BP_init_header( &packet_sbm_bp1,
237 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP1_F0,
236 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP1_F0,
238 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
237 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
239 BP_init_header( &packet_sbm_bp2,
238 BP_init_header( &packet_sbm_bp2,
240 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP2_F0,
239 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP2_F0,
241 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
240 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0, NB_BINS_COMPRESSED_SM_SBM_F0);
242 }
241 }
243 else
242 else
244 {
243 {
245 PRINTF1("in PRC0 *** lfrRequestedMode is %d, several headers not initialized\n", (unsigned int) lfrRequestedMode)
244 PRINTF1("in PRC0 *** lfrRequestedMode is %d, several headers not initialized\n", (unsigned int) lfrRequestedMode)
246 }
245 }
247
246
248 status = get_message_queue_id_send( &queue_id );
247 status = get_message_queue_id_send( &queue_id );
249 if (status != RTEMS_SUCCESSFUL)
248 if (status != RTEMS_SUCCESSFUL)
250 {
249 {
251 PRINTF1("in PRC0 *** ERR get_message_queue_id_send %d\n", status)
250 PRINTF1("in PRC0 *** ERR get_message_queue_id_send %d\n", status)
252 }
251 }
253 status = get_message_queue_id_prc0( &queue_id_q_p0);
252 status = get_message_queue_id_prc0( &queue_id_q_p0);
254 if (status != RTEMS_SUCCESSFUL)
253 if (status != RTEMS_SUCCESSFUL)
255 {
254 {
256 PRINTF1("in PRC0 *** ERR get_message_queue_id_prc0 %d\n", status)
255 PRINTF1("in PRC0 *** ERR get_message_queue_id_prc0 %d\n", status)
257 }
256 }
258
257
259 BOOT_PRINTF1("in PRC0 *** lfrRequestedMode = %d\n", (int) lfrRequestedMode)
258 BOOT_PRINTF1("in PRC0 *** lfrRequestedMode = %d\n", (int) lfrRequestedMode)
260
259
261 while(1){
260 while(1){
262 status = rtems_message_queue_receive( queue_id_q_p0, incomingData, &size, //************************************
261 status = rtems_message_queue_receive( queue_id_q_p0, incomingData, &size, //************************************
263 RTEMS_WAIT, RTEMS_NO_TIMEOUT ); // wait for a message coming from AVF0
262 RTEMS_WAIT, RTEMS_NO_TIMEOUT ); // wait for a message coming from AVF0
264
263
265 incomingMsg = (asm_msg*) incomingData;
264 incomingMsg = (asm_msg*) incomingData;
266
265
267 ASM_patch( incomingMsg->norm->matrix, asm_f0_patched_norm );
266 ASM_patch( incomingMsg->norm->matrix, asm_f0_patched_norm );
268 ASM_patch( incomingMsg->burst_sbm->matrix, asm_f0_patched_burst_sbm );
267 ASM_patch( incomingMsg->burst_sbm->matrix, asm_f0_patched_burst_sbm );
269
268
270 nbSMInASMNORM = incomingMsg->numberOfSMInASMNORM;
269 nbSMInASMNORM = incomingMsg->numberOfSMInASMNORM;
271 nbSMInASMSBM = incomingMsg->numberOfSMInASMSBM;
270 nbSMInASMSBM = incomingMsg->numberOfSMInASMSBM;
272
271
273 //****************
272 //****************
274 //****************
273 //****************
275 // BURST SBM1 SBM2
274 // BURST SBM1 SBM2
276 //****************
275 //****************
277 //****************
276 //****************
278 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP1_F0 ) || (incomingMsg->event & RTEMS_EVENT_SBM_BP1_F0 ) )
277 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP1_F0 ) || (incomingMsg->event & RTEMS_EVENT_SBM_BP1_F0 ) )
279 {
278 {
280 sid = getSID( incomingMsg->event );
279 sid = getSID( incomingMsg->event );
281 // 1) compress the matrix for Basic Parameters calculation
280 // 1) compress the matrix for Basic Parameters calculation
282 ASM_compress_reorganize_and_divide_mask( asm_f0_patched_burst_sbm, compressed_sm_sbm_f0,
281 ASM_compress_reorganize_and_divide_mask( asm_f0_patched_burst_sbm, compressed_sm_sbm_f0,
283 nbSMInASMSBM,
282 nbSMInASMSBM,
284 NB_BINS_COMPRESSED_SM_SBM_F0, NB_BINS_TO_AVERAGE_ASM_SBM_F0,
283 NB_BINS_COMPRESSED_SM_SBM_F0, NB_BINS_TO_AVERAGE_ASM_SBM_F0,
285 ASM_F0_INDICE_START, CHANNELF0);
284 ASM_F0_INDICE_START, CHANNELF0);
286 // 2) compute the BP1 set
285 // 2) compute the BP1 set
287 BP1_set( compressed_sm_sbm_f0, k_coeff_intercalib_f0_sbm, NB_BINS_COMPRESSED_SM_SBM_F0, packet_sbm_bp1.data );
286 BP1_set( compressed_sm_sbm_f0, k_coeff_intercalib_f0_sbm, NB_BINS_COMPRESSED_SM_SBM_F0, packet_sbm_bp1.data );
288 // 3) send the BP1 set
287 // 3) send the BP1 set
289 set_time( packet_sbm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
288 set_time( packet_sbm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
290 set_time( packet_sbm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
289 set_time( packet_sbm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
291 packet_sbm_bp1.pa_bia_status_info = pa_bia_status_info;
290 packet_sbm_bp1.pa_bia_status_info = pa_bia_status_info;
292 packet_sbm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
291 packet_sbm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
293 BP_send_s1_s2( (char *) &packet_sbm_bp1, queue_id,
292 BP_send_s1_s2( (char *) &packet_sbm_bp1, queue_id,
294 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0 + PACKET_LENGTH_DELTA,
293 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0 + PACKET_LENGTH_DELTA,
295 sid);
294 sid);
296 // 4) compute the BP2 set if needed
295 // 4) compute the BP2 set if needed
297 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP2_F0) || (incomingMsg->event & RTEMS_EVENT_SBM_BP2_F0) )
296 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP2_F0) || (incomingMsg->event & RTEMS_EVENT_SBM_BP2_F0) )
298 {
297 {
299 // 1) compute the BP2 set
298 // 1) compute the BP2 set
300 BP2_set( compressed_sm_sbm_f0, NB_BINS_COMPRESSED_SM_SBM_F0, packet_sbm_bp2.data );
299 BP2_set( compressed_sm_sbm_f0, NB_BINS_COMPRESSED_SM_SBM_F0, packet_sbm_bp2.data );
301 // 2) send the BP2 set
300 // 2) send the BP2 set
302 set_time( packet_sbm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
301 set_time( packet_sbm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
303 set_time( packet_sbm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
302 set_time( packet_sbm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
304 packet_sbm_bp2.pa_bia_status_info = pa_bia_status_info;
303 packet_sbm_bp2.pa_bia_status_info = pa_bia_status_info;
305 packet_sbm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
304 packet_sbm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
306 BP_send_s1_s2( (char *) &packet_sbm_bp2, queue_id,
305 BP_send_s1_s2( (char *) &packet_sbm_bp2, queue_id,
307 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0 + PACKET_LENGTH_DELTA,
306 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0 + PACKET_LENGTH_DELTA,
308 sid);
307 sid);
309 }
308 }
310 }
309 }
311
310
312 //*****
311 //*****
313 //*****
312 //*****
314 // NORM
313 // NORM
315 //*****
314 //*****
316 //*****
315 //*****
317 if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F0)
316 if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F0)
318 {
317 {
319 // 1) compress the matrix for Basic Parameters calculation
318 // 1) compress the matrix for Basic Parameters calculation
320 ASM_compress_reorganize_and_divide_mask( asm_f0_patched_norm, compressed_sm_norm_f0,
319 ASM_compress_reorganize_and_divide_mask( asm_f0_patched_norm, compressed_sm_norm_f0,
321 nbSMInASMNORM,
320 nbSMInASMNORM,
322 NB_BINS_COMPRESSED_SM_F0, NB_BINS_TO_AVERAGE_ASM_F0,
321 NB_BINS_COMPRESSED_SM_F0, NB_BINS_TO_AVERAGE_ASM_F0,
323 ASM_F0_INDICE_START, CHANNELF0 );
322 ASM_F0_INDICE_START, CHANNELF0 );
324 // 2) compute the BP1 set
323 // 2) compute the BP1 set
325 BP1_set( compressed_sm_norm_f0, k_coeff_intercalib_f0_norm, NB_BINS_COMPRESSED_SM_F0, packet_norm_bp1.data );
324 BP1_set( compressed_sm_norm_f0, k_coeff_intercalib_f0_norm, NB_BINS_COMPRESSED_SM_F0, packet_norm_bp1.data );
326 // 3) send the BP1 set
325 // 3) send the BP1 set
327 set_time( packet_norm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
326 set_time( packet_norm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
328 set_time( packet_norm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
327 set_time( packet_norm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
329 packet_norm_bp1.pa_bia_status_info = pa_bia_status_info;
328 packet_norm_bp1.pa_bia_status_info = pa_bia_status_info;
330 packet_norm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
329 packet_norm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
331 BP_send( (char *) &packet_norm_bp1, queue_id,
330 BP_send( (char *) &packet_norm_bp1, queue_id,
332 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F0 + PACKET_LENGTH_DELTA,
331 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F0 + PACKET_LENGTH_DELTA,
333 SID_NORM_BP1_F0 );
332 SID_NORM_BP1_F0 );
334 if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F0)
333 if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F0)
335 {
334 {
336 // 1) compute the BP2 set using the same ASM as the one used for BP1
335 // 1) compute the BP2 set using the same ASM as the one used for BP1
337 BP2_set( compressed_sm_norm_f0, NB_BINS_COMPRESSED_SM_F0, packet_norm_bp2.data );
336 BP2_set( compressed_sm_norm_f0, NB_BINS_COMPRESSED_SM_F0, packet_norm_bp2.data );
338 // 2) send the BP2 set
337 // 2) send the BP2 set
339 set_time( packet_norm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
338 set_time( packet_norm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
340 set_time( packet_norm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
339 set_time( packet_norm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
341 packet_norm_bp2.pa_bia_status_info = pa_bia_status_info;
340 packet_norm_bp2.pa_bia_status_info = pa_bia_status_info;
342 packet_norm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
341 packet_norm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
343 BP_send( (char *) &packet_norm_bp2, queue_id,
342 BP_send( (char *) &packet_norm_bp2, queue_id,
344 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F0 + PACKET_LENGTH_DELTA,
343 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F0 + PACKET_LENGTH_DELTA,
345 SID_NORM_BP2_F0);
344 SID_NORM_BP2_F0);
346 }
345 }
347 }
346 }
348
347
349 if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F0)
348 if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F0)
350 {
349 {
351 // 1) reorganize the ASM and divide
350 // 1) reorganize the ASM and divide
352 ASM_reorganize_and_divide( asm_f0_patched_norm,
351 ASM_reorganize_and_divide( asm_f0_patched_norm,
353 (float*) current_ring_node_to_send_asm_f0->buffer_address,
352 (float*) current_ring_node_to_send_asm_f0->buffer_address,
354 nbSMInASMNORM );
353 nbSMInASMNORM );
355 current_ring_node_to_send_asm_f0->coarseTime = incomingMsg->coarseTimeNORM;
354 current_ring_node_to_send_asm_f0->coarseTime = incomingMsg->coarseTimeNORM;
356 current_ring_node_to_send_asm_f0->fineTime = incomingMsg->fineTimeNORM;
355 current_ring_node_to_send_asm_f0->fineTime = incomingMsg->fineTimeNORM;
357 current_ring_node_to_send_asm_f0->sid = SID_NORM_ASM_F0;
356 current_ring_node_to_send_asm_f0->sid = SID_NORM_ASM_F0;
358
357
359 // 3) send the spectral matrix packets
358 // 3) send the spectral matrix packets
360 status = rtems_message_queue_send( queue_id, &current_ring_node_to_send_asm_f0, sizeof( ring_node* ) );
359 status = rtems_message_queue_send( queue_id, &current_ring_node_to_send_asm_f0, sizeof( ring_node* ) );
361
360
362 // change asm ring node
361 // change asm ring node
363 current_ring_node_to_send_asm_f0 = current_ring_node_to_send_asm_f0->next;
362 current_ring_node_to_send_asm_f0 = current_ring_node_to_send_asm_f0->next;
364 }
363 }
365
364
366 update_queue_max_count( queue_id_q_p0, &hk_lfr_q_p0_fifo_size_max );
365 update_queue_max_count( queue_id_q_p0, &hk_lfr_q_p0_fifo_size_max );
367
366
368 }
367 }
369 }
368 }
370
369
371 //**********
370 //**********
372 // FUNCTIONS
371 // FUNCTIONS
373
372
374 void reset_nb_sm_f0( unsigned char lfrMode )
373 void reset_nb_sm_f0( unsigned char lfrMode )
375 {
374 {
376 nb_sm_before_f0.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0 * 96;
375 nb_sm_before_f0.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0 * NB_SM_PER_S_F0;
377 nb_sm_before_f0.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1 * 96;
376 nb_sm_before_f0.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1 * NB_SM_PER_S_F0;
378 nb_sm_before_f0.norm_asm = (parameter_dump_packet.sy_lfr_n_asm_p[0] * 256 + parameter_dump_packet.sy_lfr_n_asm_p[1]) * 96;
377 nb_sm_before_f0.norm_asm =
379 nb_sm_before_f0.sbm1_bp1 = parameter_dump_packet.sy_lfr_s1_bp_p0 * 24; // 0.25 s per digit
378 ( (parameter_dump_packet.sy_lfr_n_asm_p[0] * 256) + parameter_dump_packet.sy_lfr_n_asm_p[1]) * NB_SM_PER_S_F0;
380 nb_sm_before_f0.sbm1_bp2 = parameter_dump_packet.sy_lfr_s1_bp_p1 * 96;
379 nb_sm_before_f0.sbm1_bp1 = parameter_dump_packet.sy_lfr_s1_bp_p0 * NB_SM_PER_S1_BP_P0; // 0.25 s per digit
381 nb_sm_before_f0.sbm2_bp1 = parameter_dump_packet.sy_lfr_s2_bp_p0 * 96;
380 nb_sm_before_f0.sbm1_bp2 = parameter_dump_packet.sy_lfr_s1_bp_p1 * NB_SM_PER_S_F0;
382 nb_sm_before_f0.sbm2_bp2 = parameter_dump_packet.sy_lfr_s2_bp_p1 * 96;
381 nb_sm_before_f0.sbm2_bp1 = parameter_dump_packet.sy_lfr_s2_bp_p0 * NB_SM_PER_S_F0;
383 nb_sm_before_f0.burst_bp1 = parameter_dump_packet.sy_lfr_b_bp_p0 * 96;
382 nb_sm_before_f0.sbm2_bp2 = parameter_dump_packet.sy_lfr_s2_bp_p1 * NB_SM_PER_S_F0;
384 nb_sm_before_f0.burst_bp2 = parameter_dump_packet.sy_lfr_b_bp_p1 * 96;
383 nb_sm_before_f0.burst_bp1 = parameter_dump_packet.sy_lfr_b_bp_p0 * NB_SM_PER_S_F0;
384 nb_sm_before_f0.burst_bp2 = parameter_dump_packet.sy_lfr_b_bp_p1 * NB_SM_PER_S_F0;
385
385
386 if (lfrMode == LFR_MODE_SBM1)
386 if (lfrMode == LFR_MODE_SBM1)
387 {
387 {
388 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.sbm1_bp1;
388 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.sbm1_bp1;
389 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.sbm1_bp2;
389 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.sbm1_bp2;
390 }
390 }
391 else if (lfrMode == LFR_MODE_SBM2)
391 else if (lfrMode == LFR_MODE_SBM2)
392 {
392 {
393 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.sbm2_bp1;
393 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.sbm2_bp1;
394 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.sbm2_bp2;
394 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.sbm2_bp2;
395 }
395 }
396 else if (lfrMode == LFR_MODE_BURST)
396 else if (lfrMode == LFR_MODE_BURST)
397 {
397 {
398 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.burst_bp1;
398 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.burst_bp1;
399 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.burst_bp2;
399 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.burst_bp2;
400 }
400 }
401 else
401 else
402 {
402 {
403 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.burst_bp1;
403 nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.burst_bp1;
404 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.burst_bp2;
404 nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.burst_bp2;
405 }
405 }
406 }
406 }
407
407
408 void init_k_coefficients_prc0( void )
408 void init_k_coefficients_prc0( void )
409 {
409 {
410 init_k_coefficients( k_coeff_intercalib_f0_norm, NB_BINS_COMPRESSED_SM_F0 );
410 init_k_coefficients( k_coeff_intercalib_f0_norm, NB_BINS_COMPRESSED_SM_F0 );
411
411
412 init_kcoeff_sbm_from_kcoeff_norm( k_coeff_intercalib_f0_norm, k_coeff_intercalib_f0_sbm, NB_BINS_COMPRESSED_SM_F0);
412 init_kcoeff_sbm_from_kcoeff_norm( k_coeff_intercalib_f0_norm, k_coeff_intercalib_f0_sbm, NB_BINS_COMPRESSED_SM_F0);
413 }
413 }
414
414
@@ -1,398 +1,398
1 /** Functions related to data processing.
1 /** Functions related to data processing.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
6 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
7 *
7 *
8 */
8 */
9
9
10 #include "avf1_prc1.h"
10 #include "avf1_prc1.h"
11
11
12 nb_sm_before_bp_asm_f1 nb_sm_before_f1;
12 nb_sm_before_bp_asm_f1 nb_sm_before_f1;
13
13
14 extern ring_node sm_ring_f1[ ];
14 extern ring_node sm_ring_f1[ ];
15
15
16 //***
16 //***
17 // F1
17 // F1
18 ring_node_asm asm_ring_norm_f1 [ NB_RING_NODES_ASM_NORM_F1 ];
18 ring_node_asm asm_ring_norm_f1 [ NB_RING_NODES_ASM_NORM_F1 ];
19 ring_node_asm asm_ring_burst_sbm_f1 [ NB_RING_NODES_ASM_BURST_SBM_F1 ];
19 ring_node_asm asm_ring_burst_sbm_f1 [ NB_RING_NODES_ASM_BURST_SBM_F1 ];
20
20
21 ring_node ring_to_send_asm_f1 [ NB_RING_NODES_ASM_F1 ];
21 ring_node ring_to_send_asm_f1 [ NB_RING_NODES_ASM_F1 ];
22 int buffer_asm_f1 [ NB_RING_NODES_ASM_F1 * TOTAL_SIZE_SM ];
22 int buffer_asm_f1 [ NB_RING_NODES_ASM_F1 * TOTAL_SIZE_SM ];
23
23
24 float asm_f1_patched_norm [ TOTAL_SIZE_SM ];
24 float asm_f1_patched_norm [ TOTAL_SIZE_SM ];
25 float asm_f1_patched_burst_sbm [ TOTAL_SIZE_SM ];
25 float asm_f1_patched_burst_sbm [ TOTAL_SIZE_SM ];
26 float asm_f1_reorganized [ TOTAL_SIZE_SM ];
26 float asm_f1_reorganized [ TOTAL_SIZE_SM ];
27
27
28 char asm_f1_char [ TOTAL_SIZE_SM * 2 ];
29 float compressed_sm_norm_f1[ TOTAL_SIZE_COMPRESSED_ASM_NORM_F1];
28 float compressed_sm_norm_f1[ TOTAL_SIZE_COMPRESSED_ASM_NORM_F1];
30 float compressed_sm_sbm_f1 [ TOTAL_SIZE_COMPRESSED_ASM_SBM_F1 ];
29 float compressed_sm_sbm_f1 [ TOTAL_SIZE_COMPRESSED_ASM_SBM_F1 ];
31
30
32 float k_coeff_intercalib_f1_norm[ NB_BINS_COMPRESSED_SM_F1 * NB_K_COEFF_PER_BIN ]; // 13 * 32 = 416
31 float k_coeff_intercalib_f1_norm[ NB_BINS_COMPRESSED_SM_F1 * NB_K_COEFF_PER_BIN ]; // 13 * 32 = 416
33 float k_coeff_intercalib_f1_sbm[ NB_BINS_COMPRESSED_SM_SBM_F1 * NB_K_COEFF_PER_BIN ]; // 26 * 32 = 832
32 float k_coeff_intercalib_f1_sbm[ NB_BINS_COMPRESSED_SM_SBM_F1 * NB_K_COEFF_PER_BIN ]; // 26 * 32 = 832
34
33
35 //************
34 //************
36 // RTEMS TASKS
35 // RTEMS TASKS
37
36
38 rtems_task avf1_task( rtems_task_argument lfrRequestedMode )
37 rtems_task avf1_task( rtems_task_argument lfrRequestedMode )
39 {
38 {
40 int i;
39 int i;
41
40
42 rtems_event_set event_out;
41 rtems_event_set event_out;
43 rtems_status_code status;
42 rtems_status_code status;
44 rtems_id queue_id_prc1;
43 rtems_id queue_id_prc1;
45 asm_msg msgForPRC;
44 asm_msg msgForPRC;
46 ring_node *nodeForAveraging;
45 ring_node *nodeForAveraging;
47 ring_node *ring_node_tab[NB_SM_BEFORE_AVF0];
46 ring_node *ring_node_tab[NB_SM_BEFORE_AVF0_F1];
48 ring_node_asm *current_ring_node_asm_burst_sbm_f1;
47 ring_node_asm *current_ring_node_asm_burst_sbm_f1;
49 ring_node_asm *current_ring_node_asm_norm_f1;
48 ring_node_asm *current_ring_node_asm_norm_f1;
50
49
51 unsigned int nb_norm_bp1;
50 unsigned int nb_norm_bp1;
52 unsigned int nb_norm_bp2;
51 unsigned int nb_norm_bp2;
53 unsigned int nb_norm_asm;
52 unsigned int nb_norm_asm;
54 unsigned int nb_sbm_bp1;
53 unsigned int nb_sbm_bp1;
55 unsigned int nb_sbm_bp2;
54 unsigned int nb_sbm_bp2;
56
55
57 nb_norm_bp1 = 0;
56 nb_norm_bp1 = 0;
58 nb_norm_bp2 = 0;
57 nb_norm_bp2 = 0;
59 nb_norm_asm = 0;
58 nb_norm_asm = 0;
60 nb_sbm_bp1 = 0;
59 nb_sbm_bp1 = 0;
61 nb_sbm_bp2 = 0;
60 nb_sbm_bp2 = 0;
62
61
63 reset_nb_sm_f1( lfrRequestedMode ); // reset the sm counters that drive the BP and ASM computations / transmissions
62 reset_nb_sm_f1( lfrRequestedMode ); // reset the sm counters that drive the BP and ASM computations / transmissions
64 ASM_generic_init_ring( asm_ring_norm_f1, NB_RING_NODES_ASM_NORM_F1 );
63 ASM_generic_init_ring( asm_ring_norm_f1, NB_RING_NODES_ASM_NORM_F1 );
65 ASM_generic_init_ring( asm_ring_burst_sbm_f1, NB_RING_NODES_ASM_BURST_SBM_F1 );
64 ASM_generic_init_ring( asm_ring_burst_sbm_f1, NB_RING_NODES_ASM_BURST_SBM_F1 );
66 current_ring_node_asm_norm_f1 = asm_ring_norm_f1;
65 current_ring_node_asm_norm_f1 = asm_ring_norm_f1;
67 current_ring_node_asm_burst_sbm_f1 = asm_ring_burst_sbm_f1;
66 current_ring_node_asm_burst_sbm_f1 = asm_ring_burst_sbm_f1;
68
67
69 BOOT_PRINTF1("in AVF1 *** lfrRequestedMode = %d\n", (int) lfrRequestedMode)
68 BOOT_PRINTF1("in AVF1 *** lfrRequestedMode = %d\n", (int) lfrRequestedMode)
70
69
71 status = get_message_queue_id_prc1( &queue_id_prc1 );
70 status = get_message_queue_id_prc1( &queue_id_prc1 );
72 if (status != RTEMS_SUCCESSFUL)
71 if (status != RTEMS_SUCCESSFUL)
73 {
72 {
74 PRINTF1("in AVF1 *** ERR get_message_queue_id_prc1 %d\n", status)
73 PRINTF1("in AVF1 *** ERR get_message_queue_id_prc1 %d\n", status)
75 }
74 }
76
75
77 while(1){
76 while(1){
78 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
77 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
79
78
80 //****************************************
79 //****************************************
81 // initialize the mesage for the MATR task
80 // initialize the mesage for the MATR task
82 msgForPRC.norm = current_ring_node_asm_norm_f1;
81 msgForPRC.norm = current_ring_node_asm_norm_f1;
83 msgForPRC.burst_sbm = current_ring_node_asm_burst_sbm_f1;
82 msgForPRC.burst_sbm = current_ring_node_asm_burst_sbm_f1;
84 msgForPRC.event = 0x00; // this composite event will be sent to the PRC1 task
83 msgForPRC.event = EVENT_SETS_NONE_PENDING; // this composite event will be sent to the PRC1 task
85 //
84 //
86 //****************************************
85 //****************************************
87
86
88 nodeForAveraging = getRingNodeForAveraging( 1 );
87 nodeForAveraging = getRingNodeForAveraging( 1 );
89
88
90 ring_node_tab[NB_SM_BEFORE_AVF1-1] = nodeForAveraging;
89 ring_node_tab[NB_SM_BEFORE_AVF0_F1-1] = nodeForAveraging;
91 for ( i = 2; i < (NB_SM_BEFORE_AVF1+1); i++ )
90 for ( i = 1; i < (NB_SM_BEFORE_AVF0_F1); i++ )
92 {
91 {
93 nodeForAveraging = nodeForAveraging->previous;
92 nodeForAveraging = nodeForAveraging->previous;
94 ring_node_tab[NB_SM_BEFORE_AVF1-i] = nodeForAveraging;
93 ring_node_tab[NB_SM_BEFORE_AVF0_F1-i] = nodeForAveraging;
95 }
94 }
96
95
97 // compute the average and store it in the averaged_sm_f1 buffer
96 // compute the average and store it in the averaged_sm_f1 buffer
98 SM_average( current_ring_node_asm_norm_f1->matrix,
97 SM_average( current_ring_node_asm_norm_f1->matrix,
99 current_ring_node_asm_burst_sbm_f1->matrix,
98 current_ring_node_asm_burst_sbm_f1->matrix,
100 ring_node_tab,
99 ring_node_tab,
101 nb_norm_bp1, nb_sbm_bp1,
100 nb_norm_bp1, nb_sbm_bp1,
102 &msgForPRC, 1 ); // 1 => frequency channel 1
101 &msgForPRC, 1 ); // 1 => frequency channel 1
103
102
104 // update nb_average
103 // update nb_average
105 nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF1;
104 nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF0_F1;
106 nb_norm_bp2 = nb_norm_bp2 + NB_SM_BEFORE_AVF1;
105 nb_norm_bp2 = nb_norm_bp2 + NB_SM_BEFORE_AVF0_F1;
107 nb_norm_asm = nb_norm_asm + NB_SM_BEFORE_AVF1;
106 nb_norm_asm = nb_norm_asm + NB_SM_BEFORE_AVF0_F1;
108 nb_sbm_bp1 = nb_sbm_bp1 + NB_SM_BEFORE_AVF1;
107 nb_sbm_bp1 = nb_sbm_bp1 + NB_SM_BEFORE_AVF0_F1;
109 nb_sbm_bp2 = nb_sbm_bp2 + NB_SM_BEFORE_AVF1;
108 nb_sbm_bp2 = nb_sbm_bp2 + NB_SM_BEFORE_AVF0_F1;
110
109
111 if (nb_sbm_bp1 == nb_sm_before_f1.burst_sbm_bp1)
110 if (nb_sbm_bp1 == nb_sm_before_f1.burst_sbm_bp1)
112 {
111 {
113 nb_sbm_bp1 = 0;
112 nb_sbm_bp1 = 0;
114 // set another ring for the ASM storage
113 // set another ring for the ASM storage
115 current_ring_node_asm_burst_sbm_f1 = current_ring_node_asm_burst_sbm_f1->next;
114 current_ring_node_asm_burst_sbm_f1 = current_ring_node_asm_burst_sbm_f1->next;
116 if ( lfrCurrentMode == LFR_MODE_BURST )
115 if ( lfrCurrentMode == LFR_MODE_BURST )
117 {
116 {
118 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_BURST_BP1_F1;
117 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_BURST_BP1_F1;
119 }
118 }
120 else if ( lfrCurrentMode == LFR_MODE_SBM2 )
119 else if ( lfrCurrentMode == LFR_MODE_SBM2 )
121 {
120 {
122 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_SBM_BP1_F1;
121 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_SBM_BP1_F1;
123 }
122 }
124 }
123 }
125
124
126 if (nb_sbm_bp2 == nb_sm_before_f1.burst_sbm_bp2)
125 if (nb_sbm_bp2 == nb_sm_before_f1.burst_sbm_bp2)
127 {
126 {
128 nb_sbm_bp2 = 0;
127 nb_sbm_bp2 = 0;
129 if ( lfrCurrentMode == LFR_MODE_BURST )
128 if ( lfrCurrentMode == LFR_MODE_BURST )
130 {
129 {
131 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_BURST_BP2_F1;
130 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_BURST_BP2_F1;
132 }
131 }
133 else if ( lfrCurrentMode == LFR_MODE_SBM2 )
132 else if ( lfrCurrentMode == LFR_MODE_SBM2 )
134 {
133 {
135 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_SBM_BP2_F1;
134 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_SBM_BP2_F1;
136 }
135 }
137 }
136 }
138
137
139 if (nb_norm_bp1 == nb_sm_before_f1.norm_bp1)
138 if (nb_norm_bp1 == nb_sm_before_f1.norm_bp1)
140 {
139 {
141 nb_norm_bp1 = 0;
140 nb_norm_bp1 = 0;
142 // set another ring for the ASM storage
141 // set another ring for the ASM storage
143 current_ring_node_asm_norm_f1 = current_ring_node_asm_norm_f1->next;
142 current_ring_node_asm_norm_f1 = current_ring_node_asm_norm_f1->next;
144 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
143 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
145 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
144 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
146 {
145 {
147 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP1_F1;
146 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP1_F1;
148 }
147 }
149 }
148 }
150
149
151 if (nb_norm_bp2 == nb_sm_before_f1.norm_bp2)
150 if (nb_norm_bp2 == nb_sm_before_f1.norm_bp2)
152 {
151 {
153 nb_norm_bp2 = 0;
152 nb_norm_bp2 = 0;
154 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
153 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
155 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
154 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
156 {
155 {
157 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP2_F1;
156 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP2_F1;
158 }
157 }
159 }
158 }
160
159
161 if (nb_norm_asm == nb_sm_before_f1.norm_asm)
160 if (nb_norm_asm == nb_sm_before_f1.norm_asm)
162 {
161 {
163 nb_norm_asm = 0;
162 nb_norm_asm = 0;
164 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
163 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
165 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
164 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
166 {
165 {
167 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_ASM_F1;
166 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_ASM_F1;
168 }
167 }
169 }
168 }
170
169
171 //*************************
170 //*************************
172 // send the message to PRC
171 // send the message to PRC
173 if (msgForPRC.event != 0x00)
172 if (msgForPRC.event != EVENT_SETS_NONE_PENDING)
174 {
173 {
175 status = rtems_message_queue_send( queue_id_prc1, (char *) &msgForPRC, MSG_QUEUE_SIZE_PRC1);
174 status = rtems_message_queue_send( queue_id_prc1, (char *) &msgForPRC, MSG_QUEUE_SIZE_PRC1);
176 }
175 }
177
176
178 if (status != RTEMS_SUCCESSFUL) {
177 if (status != RTEMS_SUCCESSFUL) {
179 PRINTF1("in AVF1 *** Error sending message to PRC1, code %d\n", status)
178 PRINTF1("in AVF1 *** Error sending message to PRC1, code %d\n", status)
180 }
179 }
181 }
180 }
182 }
181 }
183
182
184 rtems_task prc1_task( rtems_task_argument lfrRequestedMode )
183 rtems_task prc1_task( rtems_task_argument lfrRequestedMode )
185 {
184 {
186 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
185 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
187 size_t size; // size of the incoming TC packet
186 size_t size; // size of the incoming TC packet
188 asm_msg *incomingMsg;
187 asm_msg *incomingMsg;
189 //
188 //
190 unsigned char sid;
189 unsigned char sid;
191 rtems_status_code status;
190 rtems_status_code status;
192 rtems_id queue_id_send;
191 rtems_id queue_id_send;
193 rtems_id queue_id_q_p1;
192 rtems_id queue_id_q_p1;
194 bp_packet_with_spare packet_norm_bp1;
193 bp_packet_with_spare packet_norm_bp1;
195 bp_packet packet_norm_bp2;
194 bp_packet packet_norm_bp2;
196 bp_packet packet_sbm_bp1;
195 bp_packet packet_sbm_bp1;
197 bp_packet packet_sbm_bp2;
196 bp_packet packet_sbm_bp2;
198 ring_node *current_ring_node_to_send_asm_f1;
197 ring_node *current_ring_node_to_send_asm_f1;
199 float nbSMInASMNORM;
198 float nbSMInASMNORM;
200 float nbSMInASMSBM;
199 float nbSMInASMSBM;
201
200
202 // init the ring of the averaged spectral matrices which will be transmitted to the DPU
201 // init the ring of the averaged spectral matrices which will be transmitted to the DPU
203 init_ring( ring_to_send_asm_f1, NB_RING_NODES_ASM_F1, (volatile int*) buffer_asm_f1, TOTAL_SIZE_SM );
202 init_ring( ring_to_send_asm_f1, NB_RING_NODES_ASM_F1, (volatile int*) buffer_asm_f1, TOTAL_SIZE_SM );
204 current_ring_node_to_send_asm_f1 = ring_to_send_asm_f1;
203 current_ring_node_to_send_asm_f1 = ring_to_send_asm_f1;
205
204
206 //*************
205 //*************
207 // NORM headers
206 // NORM headers
208 BP_init_header_with_spare( &packet_norm_bp1,
207 BP_init_header_with_spare( &packet_norm_bp1,
209 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP1_F1,
208 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP1_F1,
210 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F1, NB_BINS_COMPRESSED_SM_F1 );
209 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F1, NB_BINS_COMPRESSED_SM_F1 );
211 BP_init_header( &packet_norm_bp2,
210 BP_init_header( &packet_norm_bp2,
212 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP2_F1,
211 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP2_F1,
213 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F1, NB_BINS_COMPRESSED_SM_F1);
212 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F1, NB_BINS_COMPRESSED_SM_F1);
214
213
215 //***********************
214 //***********************
216 // BURST and SBM2 headers
215 // BURST and SBM2 headers
217 if ( lfrRequestedMode == LFR_MODE_BURST )
216 if ( lfrRequestedMode == LFR_MODE_BURST )
218 {
217 {
219 BP_init_header( &packet_sbm_bp1,
218 BP_init_header( &packet_sbm_bp1,
220 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP1_F1,
219 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP1_F1,
221 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
220 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
222 BP_init_header( &packet_sbm_bp2,
221 BP_init_header( &packet_sbm_bp2,
223 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP2_F1,
222 APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP2_F1,
224 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
223 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
225 }
224 }
226 else if ( lfrRequestedMode == LFR_MODE_SBM2 )
225 else if ( lfrRequestedMode == LFR_MODE_SBM2 )
227 {
226 {
228 BP_init_header( &packet_sbm_bp1,
227 BP_init_header( &packet_sbm_bp1,
229 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP1_F1,
228 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP1_F1,
230 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
229 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
231 BP_init_header( &packet_sbm_bp2,
230 BP_init_header( &packet_sbm_bp2,
232 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP2_F1,
231 APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP2_F1,
233 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
232 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1, NB_BINS_COMPRESSED_SM_SBM_F1);
234 }
233 }
235 else
234 else
236 {
235 {
237 PRINTF1("in PRC1 *** lfrRequestedMode is %d, several headers not initialized\n", (unsigned int) lfrRequestedMode)
236 PRINTF1("in PRC1 *** lfrRequestedMode is %d, several headers not initialized\n", (unsigned int) lfrRequestedMode)
238 }
237 }
239
238
240 status = get_message_queue_id_send( &queue_id_send );
239 status = get_message_queue_id_send( &queue_id_send );
241 if (status != RTEMS_SUCCESSFUL)
240 if (status != RTEMS_SUCCESSFUL)
242 {
241 {
243 PRINTF1("in PRC1 *** ERR get_message_queue_id_send %d\n", status)
242 PRINTF1("in PRC1 *** ERR get_message_queue_id_send %d\n", status)
244 }
243 }
245 status = get_message_queue_id_prc1( &queue_id_q_p1);
244 status = get_message_queue_id_prc1( &queue_id_q_p1);
246 if (status != RTEMS_SUCCESSFUL)
245 if (status != RTEMS_SUCCESSFUL)
247 {
246 {
248 PRINTF1("in PRC1 *** ERR get_message_queue_id_prc1 %d\n", status)
247 PRINTF1("in PRC1 *** ERR get_message_queue_id_prc1 %d\n", status)
249 }
248 }
250
249
251 BOOT_PRINTF1("in PRC1 *** lfrRequestedMode = %d\n", (int) lfrRequestedMode)
250 BOOT_PRINTF1("in PRC1 *** lfrRequestedMode = %d\n", (int) lfrRequestedMode)
252
251
253 while(1){
252 while(1){
254 status = rtems_message_queue_receive( queue_id_q_p1, incomingData, &size, //************************************
253 status = rtems_message_queue_receive( queue_id_q_p1, incomingData, &size, //************************************
255 RTEMS_WAIT, RTEMS_NO_TIMEOUT ); // wait for a message coming from AVF0
254 RTEMS_WAIT, RTEMS_NO_TIMEOUT ); // wait for a message coming from AVF0
256
255
257 incomingMsg = (asm_msg*) incomingData;
256 incomingMsg = (asm_msg*) incomingData;
258
257
259 ASM_patch( incomingMsg->norm->matrix, asm_f1_patched_norm );
258 ASM_patch( incomingMsg->norm->matrix, asm_f1_patched_norm );
260 ASM_patch( incomingMsg->burst_sbm->matrix, asm_f1_patched_burst_sbm );
259 ASM_patch( incomingMsg->burst_sbm->matrix, asm_f1_patched_burst_sbm );
261
260
262 nbSMInASMNORM = incomingMsg->numberOfSMInASMNORM;
261 nbSMInASMNORM = incomingMsg->numberOfSMInASMNORM;
263 nbSMInASMSBM = incomingMsg->numberOfSMInASMSBM;
262 nbSMInASMSBM = incomingMsg->numberOfSMInASMSBM;
264
263
265 //***********
264 //***********
266 //***********
265 //***********
267 // BURST SBM2
266 // BURST SBM2
268 //***********
267 //***********
269 //***********
268 //***********
270 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP1_F1) || (incomingMsg->event & RTEMS_EVENT_SBM_BP1_F1) )
269 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP1_F1) || (incomingMsg->event & RTEMS_EVENT_SBM_BP1_F1) )
271 {
270 {
272 sid = getSID( incomingMsg->event );
271 sid = getSID( incomingMsg->event );
273 // 1) compress the matrix for Basic Parameters calculation
272 // 1) compress the matrix for Basic Parameters calculation
274 ASM_compress_reorganize_and_divide_mask( asm_f1_patched_burst_sbm, compressed_sm_sbm_f1,
273 ASM_compress_reorganize_and_divide_mask( asm_f1_patched_burst_sbm, compressed_sm_sbm_f1,
275 nbSMInASMSBM,
274 nbSMInASMSBM,
276 NB_BINS_COMPRESSED_SM_SBM_F1, NB_BINS_TO_AVERAGE_ASM_SBM_F1,
275 NB_BINS_COMPRESSED_SM_SBM_F1, NB_BINS_TO_AVERAGE_ASM_SBM_F1,
277 ASM_F1_INDICE_START, CHANNELF1);
276 ASM_F1_INDICE_START, CHANNELF1);
278 // 2) compute the BP1 set
277 // 2) compute the BP1 set
279 BP1_set( compressed_sm_sbm_f1, k_coeff_intercalib_f1_sbm, NB_BINS_COMPRESSED_SM_SBM_F1, packet_sbm_bp1.data );
278 BP1_set( compressed_sm_sbm_f1, k_coeff_intercalib_f1_sbm, NB_BINS_COMPRESSED_SM_SBM_F1, packet_sbm_bp1.data );
280 // 3) send the BP1 set
279 // 3) send the BP1 set
281 set_time( packet_sbm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
280 set_time( packet_sbm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
282 set_time( packet_sbm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
281 set_time( packet_sbm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
283 packet_sbm_bp1.pa_bia_status_info = pa_bia_status_info;
282 packet_sbm_bp1.pa_bia_status_info = pa_bia_status_info;
284 packet_sbm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
283 packet_sbm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
285 BP_send_s1_s2( (char *) &packet_sbm_bp1, queue_id_send,
284 BP_send_s1_s2( (char *) &packet_sbm_bp1, queue_id_send,
286 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1 + PACKET_LENGTH_DELTA,
285 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1 + PACKET_LENGTH_DELTA,
287 sid );
286 sid );
288 // 4) compute the BP2 set if needed
287 // 4) compute the BP2 set if needed
289 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP2_F1) || (incomingMsg->event & RTEMS_EVENT_SBM_BP2_F1) )
288 if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP2_F1) || (incomingMsg->event & RTEMS_EVENT_SBM_BP2_F1) )
290 {
289 {
291 // 1) compute the BP2 set
290 // 1) compute the BP2 set
292 BP2_set( compressed_sm_sbm_f1, NB_BINS_COMPRESSED_SM_SBM_F1, packet_sbm_bp2.data );
291 BP2_set( compressed_sm_sbm_f1, NB_BINS_COMPRESSED_SM_SBM_F1, packet_sbm_bp2.data );
293 // 2) send the BP2 set
292 // 2) send the BP2 set
294 set_time( packet_sbm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
293 set_time( packet_sbm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeSBM );
295 set_time( packet_sbm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
294 set_time( packet_sbm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeSBM );
296 packet_sbm_bp2.pa_bia_status_info = pa_bia_status_info;
295 packet_sbm_bp2.pa_bia_status_info = pa_bia_status_info;
297 packet_sbm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
296 packet_sbm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
298 BP_send_s1_s2( (char *) &packet_sbm_bp2, queue_id_send,
297 BP_send_s1_s2( (char *) &packet_sbm_bp2, queue_id_send,
299 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1 + PACKET_LENGTH_DELTA,
298 PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1 + PACKET_LENGTH_DELTA,
300 sid );
299 sid );
301 }
300 }
302 }
301 }
303
302
304 //*****
303 //*****
305 //*****
304 //*****
306 // NORM
305 // NORM
307 //*****
306 //*****
308 //*****
307 //*****
309 if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F1)
308 if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F1)
310 {
309 {
311 // 1) compress the matrix for Basic Parameters calculation
310 // 1) compress the matrix for Basic Parameters calculation
312 ASM_compress_reorganize_and_divide_mask( asm_f1_patched_norm, compressed_sm_norm_f1,
311 ASM_compress_reorganize_and_divide_mask( asm_f1_patched_norm, compressed_sm_norm_f1,
313 nbSMInASMNORM,
312 nbSMInASMNORM,
314 NB_BINS_COMPRESSED_SM_F1, NB_BINS_TO_AVERAGE_ASM_F1,
313 NB_BINS_COMPRESSED_SM_F1, NB_BINS_TO_AVERAGE_ASM_F1,
315 ASM_F1_INDICE_START, CHANNELF1 );
314 ASM_F1_INDICE_START, CHANNELF1 );
316 // 2) compute the BP1 set
315 // 2) compute the BP1 set
317 BP1_set( compressed_sm_norm_f1, k_coeff_intercalib_f1_norm, NB_BINS_COMPRESSED_SM_F1, packet_norm_bp1.data );
316 BP1_set( compressed_sm_norm_f1, k_coeff_intercalib_f1_norm, NB_BINS_COMPRESSED_SM_F1, packet_norm_bp1.data );
318 // 3) send the BP1 set
317 // 3) send the BP1 set
319 set_time( packet_norm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
318 set_time( packet_norm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
320 set_time( packet_norm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
319 set_time( packet_norm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
321 packet_norm_bp1.pa_bia_status_info = pa_bia_status_info;
320 packet_norm_bp1.pa_bia_status_info = pa_bia_status_info;
322 packet_norm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
321 packet_norm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
323 BP_send( (char *) &packet_norm_bp1, queue_id_send,
322 BP_send( (char *) &packet_norm_bp1, queue_id_send,
324 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F1 + PACKET_LENGTH_DELTA,
323 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F1 + PACKET_LENGTH_DELTA,
325 SID_NORM_BP1_F1 );
324 SID_NORM_BP1_F1 );
326 if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F1)
325 if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F1)
327 {
326 {
328 // 1) compute the BP2 set
327 // 1) compute the BP2 set
329 BP2_set( compressed_sm_norm_f1, NB_BINS_COMPRESSED_SM_F1, packet_norm_bp2.data );
328 BP2_set( compressed_sm_norm_f1, NB_BINS_COMPRESSED_SM_F1, packet_norm_bp2.data );
330 // 2) send the BP2 set
329 // 2) send the BP2 set
331 set_time( packet_norm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
330 set_time( packet_norm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
332 set_time( packet_norm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
331 set_time( packet_norm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
333 packet_norm_bp2.pa_bia_status_info = pa_bia_status_info;
332 packet_norm_bp2.pa_bia_status_info = pa_bia_status_info;
334 packet_norm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
333 packet_norm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
335 BP_send( (char *) &packet_norm_bp2, queue_id_send,
334 BP_send( (char *) &packet_norm_bp2, queue_id_send,
336 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F1 + PACKET_LENGTH_DELTA,
335 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F1 + PACKET_LENGTH_DELTA,
337 SID_NORM_BP2_F1 );
336 SID_NORM_BP2_F1 );
338 }
337 }
339 }
338 }
340
339
341 if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F1)
340 if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F1)
342 {
341 {
343 // 1) reorganize the ASM and divide
342 // 1) reorganize the ASM and divide
344 ASM_reorganize_and_divide( asm_f1_patched_norm,
343 ASM_reorganize_and_divide( asm_f1_patched_norm,
345 (float*) current_ring_node_to_send_asm_f1->buffer_address,
344 (float*) current_ring_node_to_send_asm_f1->buffer_address,
346 nbSMInASMNORM );
345 nbSMInASMNORM );
347 current_ring_node_to_send_asm_f1->coarseTime = incomingMsg->coarseTimeNORM;
346 current_ring_node_to_send_asm_f1->coarseTime = incomingMsg->coarseTimeNORM;
348 current_ring_node_to_send_asm_f1->fineTime = incomingMsg->fineTimeNORM;
347 current_ring_node_to_send_asm_f1->fineTime = incomingMsg->fineTimeNORM;
349 current_ring_node_to_send_asm_f1->sid = SID_NORM_ASM_F1;
348 current_ring_node_to_send_asm_f1->sid = SID_NORM_ASM_F1;
350
349
351 // 3) send the spectral matrix packets
350 // 3) send the spectral matrix packets
352 status = rtems_message_queue_send( queue_id_send, &current_ring_node_to_send_asm_f1, sizeof( ring_node* ) );
351 status = rtems_message_queue_send( queue_id_send, &current_ring_node_to_send_asm_f1, sizeof( ring_node* ) );
353
352
354 // change asm ring node
353 // change asm ring node
355 current_ring_node_to_send_asm_f1 = current_ring_node_to_send_asm_f1->next;
354 current_ring_node_to_send_asm_f1 = current_ring_node_to_send_asm_f1->next;
356 }
355 }
357
356
358 update_queue_max_count( queue_id_q_p1, &hk_lfr_q_p1_fifo_size_max );
357 update_queue_max_count( queue_id_q_p1, &hk_lfr_q_p1_fifo_size_max );
359
358
360 }
359 }
361 }
360 }
362
361
363 //**********
362 //**********
364 // FUNCTIONS
363 // FUNCTIONS
365
364
366 void reset_nb_sm_f1( unsigned char lfrMode )
365 void reset_nb_sm_f1( unsigned char lfrMode )
367 {
366 {
368 nb_sm_before_f1.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0 * 16;
367 nb_sm_before_f1.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0 * NB_SM_PER_S_F1;
369 nb_sm_before_f1.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1 * 16;
368 nb_sm_before_f1.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1 * NB_SM_PER_S_F1;
370 nb_sm_before_f1.norm_asm = (parameter_dump_packet.sy_lfr_n_asm_p[0] * 256 + parameter_dump_packet.sy_lfr_n_asm_p[1]) * 16;
369 nb_sm_before_f1.norm_asm =
371 nb_sm_before_f1.sbm2_bp1 = parameter_dump_packet.sy_lfr_s2_bp_p0 * 16;
370 ( (parameter_dump_packet.sy_lfr_n_asm_p[0] * 256) + parameter_dump_packet.sy_lfr_n_asm_p[1]) * NB_SM_PER_S_F1;
372 nb_sm_before_f1.sbm2_bp2 = parameter_dump_packet.sy_lfr_s2_bp_p1 * 16;
371 nb_sm_before_f1.sbm2_bp1 = parameter_dump_packet.sy_lfr_s2_bp_p0 * NB_SM_PER_S_F1;
373 nb_sm_before_f1.burst_bp1 = parameter_dump_packet.sy_lfr_b_bp_p0 * 16;
372 nb_sm_before_f1.sbm2_bp2 = parameter_dump_packet.sy_lfr_s2_bp_p1 * NB_SM_PER_S_F1;
374 nb_sm_before_f1.burst_bp2 = parameter_dump_packet.sy_lfr_b_bp_p1 * 16;
373 nb_sm_before_f1.burst_bp1 = parameter_dump_packet.sy_lfr_b_bp_p0 * NB_SM_PER_S_F1;
374 nb_sm_before_f1.burst_bp2 = parameter_dump_packet.sy_lfr_b_bp_p1 * NB_SM_PER_S_F1;
375
375
376 if (lfrMode == LFR_MODE_SBM2)
376 if (lfrMode == LFR_MODE_SBM2)
377 {
377 {
378 nb_sm_before_f1.burst_sbm_bp1 = nb_sm_before_f1.sbm2_bp1;
378 nb_sm_before_f1.burst_sbm_bp1 = nb_sm_before_f1.sbm2_bp1;
379 nb_sm_before_f1.burst_sbm_bp2 = nb_sm_before_f1.sbm2_bp2;
379 nb_sm_before_f1.burst_sbm_bp2 = nb_sm_before_f1.sbm2_bp2;
380 }
380 }
381 else if (lfrMode == LFR_MODE_BURST)
381 else if (lfrMode == LFR_MODE_BURST)
382 {
382 {
383 nb_sm_before_f1.burst_sbm_bp1 = nb_sm_before_f1.burst_bp1;
383 nb_sm_before_f1.burst_sbm_bp1 = nb_sm_before_f1.burst_bp1;
384 nb_sm_before_f1.burst_sbm_bp2 = nb_sm_before_f1.burst_bp2;
384 nb_sm_before_f1.burst_sbm_bp2 = nb_sm_before_f1.burst_bp2;
385 }
385 }
386 else
386 else
387 {
387 {
388 nb_sm_before_f1.burst_sbm_bp1 = nb_sm_before_f1.burst_bp1;
388 nb_sm_before_f1.burst_sbm_bp1 = nb_sm_before_f1.burst_bp1;
389 nb_sm_before_f1.burst_sbm_bp2 = nb_sm_before_f1.burst_bp2;
389 nb_sm_before_f1.burst_sbm_bp2 = nb_sm_before_f1.burst_bp2;
390 }
390 }
391 }
391 }
392
392
393 void init_k_coefficients_prc1( void )
393 void init_k_coefficients_prc1( void )
394 {
394 {
395 init_k_coefficients( k_coeff_intercalib_f1_norm, NB_BINS_COMPRESSED_SM_F1 );
395 init_k_coefficients( k_coeff_intercalib_f1_norm, NB_BINS_COMPRESSED_SM_F1 );
396
396
397 init_kcoeff_sbm_from_kcoeff_norm( k_coeff_intercalib_f1_norm, k_coeff_intercalib_f1_sbm, NB_BINS_COMPRESSED_SM_F1);
397 init_kcoeff_sbm_from_kcoeff_norm( k_coeff_intercalib_f1_norm, k_coeff_intercalib_f1_sbm, NB_BINS_COMPRESSED_SM_F1);
398 }
398 }
@@ -1,327 +1,326
1 /** Functions related to data processing.
1 /** Functions related to data processing.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
6 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
7 *
7 *
8 */
8 */
9
9
10 #include "avf2_prc2.h"
10 #include "avf2_prc2.h"
11
11
12 nb_sm_before_bp_asm_f2 nb_sm_before_f2;
12 nb_sm_before_bp_asm_f2 nb_sm_before_f2;
13
13
14 extern ring_node sm_ring_f2[ ];
14 extern ring_node sm_ring_f2[ ];
15
15
16 //***
16 //***
17 // F2
17 // F2
18 ring_node_asm asm_ring_norm_f2 [ NB_RING_NODES_ASM_NORM_F2 ];
18 ring_node_asm asm_ring_norm_f2 [ NB_RING_NODES_ASM_NORM_F2 ];
19
19
20 ring_node ring_to_send_asm_f2 [ NB_RING_NODES_ASM_F2 ];
20 ring_node ring_to_send_asm_f2 [ NB_RING_NODES_ASM_F2 ];
21 int buffer_asm_f2 [ NB_RING_NODES_ASM_F2 * TOTAL_SIZE_SM ];
21 int buffer_asm_f2 [ NB_RING_NODES_ASM_F2 * TOTAL_SIZE_SM ];
22
22
23 float asm_f2_patched_norm [ TOTAL_SIZE_SM ];
23 float asm_f2_patched_norm [ TOTAL_SIZE_SM ];
24 float asm_f2_reorganized [ TOTAL_SIZE_SM ];
24 float asm_f2_reorganized [ TOTAL_SIZE_SM ];
25
25
26 char asm_f2_char [ TOTAL_SIZE_SM * 2 ];
27 float compressed_sm_norm_f2[ TOTAL_SIZE_COMPRESSED_ASM_NORM_F2];
26 float compressed_sm_norm_f2[ TOTAL_SIZE_COMPRESSED_ASM_NORM_F2];
28
27
29 float k_coeff_intercalib_f2[ NB_BINS_COMPRESSED_SM_F2 * NB_K_COEFF_PER_BIN ]; // 12 * 32 = 384
28 float k_coeff_intercalib_f2[ NB_BINS_COMPRESSED_SM_F2 * NB_K_COEFF_PER_BIN ]; // 12 * 32 = 384
30
29
31 //************
30 //************
32 // RTEMS TASKS
31 // RTEMS TASKS
33
32
34 //***
33 //***
35 // F2
34 // F2
36 rtems_task avf2_task( rtems_task_argument argument )
35 rtems_task avf2_task( rtems_task_argument argument )
37 {
36 {
38 rtems_event_set event_out;
37 rtems_event_set event_out;
39 rtems_status_code status;
38 rtems_status_code status;
40 rtems_id queue_id_prc2;
39 rtems_id queue_id_prc2;
41 asm_msg msgForPRC;
40 asm_msg msgForPRC;
42 ring_node *nodeForAveraging;
41 ring_node *nodeForAveraging;
43 ring_node_asm *current_ring_node_asm_norm_f2;
42 ring_node_asm *current_ring_node_asm_norm_f2;
44
43
45 unsigned int nb_norm_bp1;
44 unsigned int nb_norm_bp1;
46 unsigned int nb_norm_bp2;
45 unsigned int nb_norm_bp2;
47 unsigned int nb_norm_asm;
46 unsigned int nb_norm_asm;
48
47
49 nb_norm_bp1 = 0;
48 nb_norm_bp1 = 0;
50 nb_norm_bp2 = 0;
49 nb_norm_bp2 = 0;
51 nb_norm_asm = 0;
50 nb_norm_asm = 0;
52
51
53 reset_nb_sm_f2( ); // reset the sm counters that drive the BP and ASM computations / transmissions
52 reset_nb_sm_f2( ); // reset the sm counters that drive the BP and ASM computations / transmissions
54 ASM_generic_init_ring( asm_ring_norm_f2, NB_RING_NODES_ASM_NORM_F2 );
53 ASM_generic_init_ring( asm_ring_norm_f2, NB_RING_NODES_ASM_NORM_F2 );
55 current_ring_node_asm_norm_f2 = asm_ring_norm_f2;
54 current_ring_node_asm_norm_f2 = asm_ring_norm_f2;
56
55
57 BOOT_PRINTF("in AVF2 ***\n")
56 BOOT_PRINTF("in AVF2 ***\n")
58
57
59 status = get_message_queue_id_prc2( &queue_id_prc2 );
58 status = get_message_queue_id_prc2( &queue_id_prc2 );
60 if (status != RTEMS_SUCCESSFUL)
59 if (status != RTEMS_SUCCESSFUL)
61 {
60 {
62 PRINTF1("in AVF2 *** ERR get_message_queue_id_prc2 %d\n", status)
61 PRINTF1("in AVF2 *** ERR get_message_queue_id_prc2 %d\n", status)
63 }
62 }
64
63
65 while(1){
64 while(1){
66 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
65 rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0
67
66
68 //****************************************
67 //****************************************
69 // initialize the mesage for the MATR task
68 // initialize the mesage for the MATR task
70 msgForPRC.norm = current_ring_node_asm_norm_f2;
69 msgForPRC.norm = current_ring_node_asm_norm_f2;
71 msgForPRC.burst_sbm = NULL;
70 msgForPRC.burst_sbm = NULL;
72 msgForPRC.event = 0x00; // this composite event will be sent to the PRC2 task
71 msgForPRC.event = EVENT_SETS_NONE_PENDING; // this composite event will be sent to the PRC2 task
73 //
72 //
74 //****************************************
73 //****************************************
75
74
76 nodeForAveraging = getRingNodeForAveraging( 2 );
75 nodeForAveraging = getRingNodeForAveraging( CHANNELF2 );
77
76
78 // compute the average and store it in the averaged_sm_f2 buffer
77 // compute the average and store it in the averaged_sm_f2 buffer
79 SM_average_f2( current_ring_node_asm_norm_f2->matrix,
78 SM_average_f2( current_ring_node_asm_norm_f2->matrix,
80 nodeForAveraging,
79 nodeForAveraging,
81 nb_norm_bp1,
80 nb_norm_bp1,
82 &msgForPRC );
81 &msgForPRC );
83
82
84 // update nb_average
83 // update nb_average
85 nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF2;
84 nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF2;
86 nb_norm_bp2 = nb_norm_bp2 + NB_SM_BEFORE_AVF2;
85 nb_norm_bp2 = nb_norm_bp2 + NB_SM_BEFORE_AVF2;
87 nb_norm_asm = nb_norm_asm + NB_SM_BEFORE_AVF2;
86 nb_norm_asm = nb_norm_asm + NB_SM_BEFORE_AVF2;
88
87
89 if (nb_norm_bp1 == nb_sm_before_f2.norm_bp1)
88 if (nb_norm_bp1 == nb_sm_before_f2.norm_bp1)
90 {
89 {
91 nb_norm_bp1 = 0;
90 nb_norm_bp1 = 0;
92 // set another ring for the ASM storage
91 // set another ring for the ASM storage
93 current_ring_node_asm_norm_f2 = current_ring_node_asm_norm_f2->next;
92 current_ring_node_asm_norm_f2 = current_ring_node_asm_norm_f2->next;
94 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1)
93 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1)
95 || (lfrCurrentMode == LFR_MODE_SBM2) )
94 || (lfrCurrentMode == LFR_MODE_SBM2) )
96 {
95 {
97 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP1_F2;
96 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP1_F2;
98 }
97 }
99 }
98 }
100
99
101 if (nb_norm_bp2 == nb_sm_before_f2.norm_bp2)
100 if (nb_norm_bp2 == nb_sm_before_f2.norm_bp2)
102 {
101 {
103 nb_norm_bp2 = 0;
102 nb_norm_bp2 = 0;
104 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1)
103 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1)
105 || (lfrCurrentMode == LFR_MODE_SBM2) )
104 || (lfrCurrentMode == LFR_MODE_SBM2) )
106 {
105 {
107 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP2_F2;
106 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_BP2_F2;
108 }
107 }
109 }
108 }
110
109
111 if (nb_norm_asm == nb_sm_before_f2.norm_asm)
110 if (nb_norm_asm == nb_sm_before_f2.norm_asm)
112 {
111 {
113 nb_norm_asm = 0;
112 nb_norm_asm = 0;
114 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1)
113 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1)
115 || (lfrCurrentMode == LFR_MODE_SBM2) )
114 || (lfrCurrentMode == LFR_MODE_SBM2) )
116 {
115 {
117 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_ASM_F2;
116 msgForPRC.event = msgForPRC.event | RTEMS_EVENT_NORM_ASM_F2;
118 }
117 }
119 }
118 }
120
119
121 //*************************
120 //*************************
122 // send the message to PRC2
121 // send the message to PRC2
123 if (msgForPRC.event != 0x00)
122 if (msgForPRC.event != EVENT_SETS_NONE_PENDING)
124 {
123 {
125 status = rtems_message_queue_send( queue_id_prc2, (char *) &msgForPRC, MSG_QUEUE_SIZE_PRC2);
124 status = rtems_message_queue_send( queue_id_prc2, (char *) &msgForPRC, MSG_QUEUE_SIZE_PRC2);
126 }
125 }
127
126
128 if (status != RTEMS_SUCCESSFUL) {
127 if (status != RTEMS_SUCCESSFUL) {
129 PRINTF1("in AVF2 *** Error sending message to PRC2, code %d\n", status)
128 PRINTF1("in AVF2 *** Error sending message to PRC2, code %d\n", status)
130 }
129 }
131 }
130 }
132 }
131 }
133
132
134 rtems_task prc2_task( rtems_task_argument argument )
133 rtems_task prc2_task( rtems_task_argument argument )
135 {
134 {
136 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
135 char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer
137 size_t size; // size of the incoming TC packet
136 size_t size; // size of the incoming TC packet
138 asm_msg *incomingMsg;
137 asm_msg *incomingMsg;
139 //
138 //
140 rtems_status_code status;
139 rtems_status_code status;
141 rtems_id queue_id_send;
140 rtems_id queue_id_send;
142 rtems_id queue_id_q_p2;
141 rtems_id queue_id_q_p2;
143 bp_packet packet_norm_bp1;
142 bp_packet packet_norm_bp1;
144 bp_packet packet_norm_bp2;
143 bp_packet packet_norm_bp2;
145 ring_node *current_ring_node_to_send_asm_f2;
144 ring_node *current_ring_node_to_send_asm_f2;
146 float nbSMInASMNORM;
145 float nbSMInASMNORM;
147
146
148 unsigned long long int localTime;
147 unsigned long long int localTime;
149
148
150 // init the ring of the averaged spectral matrices which will be transmitted to the DPU
149 // init the ring of the averaged spectral matrices which will be transmitted to the DPU
151 init_ring( ring_to_send_asm_f2, NB_RING_NODES_ASM_F2, (volatile int*) buffer_asm_f2, TOTAL_SIZE_SM );
150 init_ring( ring_to_send_asm_f2, NB_RING_NODES_ASM_F2, (volatile int*) buffer_asm_f2, TOTAL_SIZE_SM );
152 current_ring_node_to_send_asm_f2 = ring_to_send_asm_f2;
151 current_ring_node_to_send_asm_f2 = ring_to_send_asm_f2;
153
152
154 //*************
153 //*************
155 // NORM headers
154 // NORM headers
156 BP_init_header( &packet_norm_bp1,
155 BP_init_header( &packet_norm_bp1,
157 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP1_F2,
156 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP1_F2,
158 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F2, NB_BINS_COMPRESSED_SM_F2 );
157 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F2, NB_BINS_COMPRESSED_SM_F2 );
159 BP_init_header( &packet_norm_bp2,
158 BP_init_header( &packet_norm_bp2,
160 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP2_F2,
159 APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP2_F2,
161 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F2, NB_BINS_COMPRESSED_SM_F2 );
160 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F2, NB_BINS_COMPRESSED_SM_F2 );
162
161
163 status = get_message_queue_id_send( &queue_id_send );
162 status = get_message_queue_id_send( &queue_id_send );
164 if (status != RTEMS_SUCCESSFUL)
163 if (status != RTEMS_SUCCESSFUL)
165 {
164 {
166 PRINTF1("in PRC2 *** ERR get_message_queue_id_send %d\n", status)
165 PRINTF1("in PRC2 *** ERR get_message_queue_id_send %d\n", status)
167 }
166 }
168 status = get_message_queue_id_prc2( &queue_id_q_p2);
167 status = get_message_queue_id_prc2( &queue_id_q_p2);
169 if (status != RTEMS_SUCCESSFUL)
168 if (status != RTEMS_SUCCESSFUL)
170 {
169 {
171 PRINTF1("in PRC2 *** ERR get_message_queue_id_prc2 %d\n", status)
170 PRINTF1("in PRC2 *** ERR get_message_queue_id_prc2 %d\n", status)
172 }
171 }
173
172
174 BOOT_PRINTF("in PRC2 ***\n")
173 BOOT_PRINTF("in PRC2 ***\n")
175
174
176 while(1){
175 while(1){
177 status = rtems_message_queue_receive( queue_id_q_p2, incomingData, &size, //************************************
176 status = rtems_message_queue_receive( queue_id_q_p2, incomingData, &size, //************************************
178 RTEMS_WAIT, RTEMS_NO_TIMEOUT ); // wait for a message coming from AVF2
177 RTEMS_WAIT, RTEMS_NO_TIMEOUT ); // wait for a message coming from AVF2
179
178
180 incomingMsg = (asm_msg*) incomingData;
179 incomingMsg = (asm_msg*) incomingData;
181
180
182 ASM_patch( incomingMsg->norm->matrix, asm_f2_patched_norm );
181 ASM_patch( incomingMsg->norm->matrix, asm_f2_patched_norm );
183
182
184 localTime = getTimeAsUnsignedLongLongInt( );
183 localTime = getTimeAsUnsignedLongLongInt( );
185
184
186 nbSMInASMNORM = incomingMsg->numberOfSMInASMNORM;
185 nbSMInASMNORM = incomingMsg->numberOfSMInASMNORM;
187
186
188 //*****
187 //*****
189 //*****
188 //*****
190 // NORM
189 // NORM
191 //*****
190 //*****
192 //*****
191 //*****
193 // 1) compress the matrix for Basic Parameters calculation
192 // 1) compress the matrix for Basic Parameters calculation
194 ASM_compress_reorganize_and_divide_mask( asm_f2_patched_norm, compressed_sm_norm_f2,
193 ASM_compress_reorganize_and_divide_mask( asm_f2_patched_norm, compressed_sm_norm_f2,
195 nbSMInASMNORM,
194 nbSMInASMNORM,
196 NB_BINS_COMPRESSED_SM_F2, NB_BINS_TO_AVERAGE_ASM_F2,
195 NB_BINS_COMPRESSED_SM_F2, NB_BINS_TO_AVERAGE_ASM_F2,
197 ASM_F2_INDICE_START, CHANNELF2 );
196 ASM_F2_INDICE_START, CHANNELF2 );
198 // BP1_F2
197 // BP1_F2
199 if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F2)
198 if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F2)
200 {
199 {
201 // 1) compute the BP1 set
200 // 1) compute the BP1 set
202 BP1_set( compressed_sm_norm_f2, k_coeff_intercalib_f2, NB_BINS_COMPRESSED_SM_F2, packet_norm_bp1.data );
201 BP1_set( compressed_sm_norm_f2, k_coeff_intercalib_f2, NB_BINS_COMPRESSED_SM_F2, packet_norm_bp1.data );
203 // 2) send the BP1 set
202 // 2) send the BP1 set
204 set_time( packet_norm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
203 set_time( packet_norm_bp1.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
205 set_time( packet_norm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
204 set_time( packet_norm_bp1.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
206 packet_norm_bp1.pa_bia_status_info = pa_bia_status_info;
205 packet_norm_bp1.pa_bia_status_info = pa_bia_status_info;
207 packet_norm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
206 packet_norm_bp1.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
208 BP_send( (char *) &packet_norm_bp1, queue_id_send,
207 BP_send( (char *) &packet_norm_bp1, queue_id_send,
209 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F2 + PACKET_LENGTH_DELTA,
208 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F2 + PACKET_LENGTH_DELTA,
210 SID_NORM_BP1_F2 );
209 SID_NORM_BP1_F2 );
211 }
210 }
212 // BP2_F2
211 // BP2_F2
213 if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F2)
212 if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F2)
214 {
213 {
215 // 1) compute the BP2 set
214 // 1) compute the BP2 set
216 BP2_set( compressed_sm_norm_f2, NB_BINS_COMPRESSED_SM_F2, packet_norm_bp2.data );
215 BP2_set( compressed_sm_norm_f2, NB_BINS_COMPRESSED_SM_F2, packet_norm_bp2.data );
217 // 2) send the BP2 set
216 // 2) send the BP2 set
218 set_time( packet_norm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
217 set_time( packet_norm_bp2.time, (unsigned char *) &incomingMsg->coarseTimeNORM );
219 set_time( packet_norm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
218 set_time( packet_norm_bp2.acquisitionTime, (unsigned char *) &incomingMsg->coarseTimeNORM );
220 packet_norm_bp2.pa_bia_status_info = pa_bia_status_info;
219 packet_norm_bp2.pa_bia_status_info = pa_bia_status_info;
221 packet_norm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
220 packet_norm_bp2.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
222 BP_send( (char *) &packet_norm_bp2, queue_id_send,
221 BP_send( (char *) &packet_norm_bp2, queue_id_send,
223 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F2 + PACKET_LENGTH_DELTA,
222 PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F2 + PACKET_LENGTH_DELTA,
224 SID_NORM_BP2_F2 );
223 SID_NORM_BP2_F2 );
225 }
224 }
226
225
227 if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F2)
226 if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F2)
228 {
227 {
229 // 1) reorganize the ASM and divide
228 // 1) reorganize the ASM and divide
230 ASM_reorganize_and_divide( asm_f2_patched_norm,
229 ASM_reorganize_and_divide( asm_f2_patched_norm,
231 (float*) current_ring_node_to_send_asm_f2->buffer_address,
230 (float*) current_ring_node_to_send_asm_f2->buffer_address,
232 nb_sm_before_f2.norm_bp1 );
231 nb_sm_before_f2.norm_bp1 );
233 current_ring_node_to_send_asm_f2->coarseTime = incomingMsg->coarseTimeNORM;
232 current_ring_node_to_send_asm_f2->coarseTime = incomingMsg->coarseTimeNORM;
234 current_ring_node_to_send_asm_f2->fineTime = incomingMsg->fineTimeNORM;
233 current_ring_node_to_send_asm_f2->fineTime = incomingMsg->fineTimeNORM;
235 current_ring_node_to_send_asm_f2->sid = SID_NORM_ASM_F2;
234 current_ring_node_to_send_asm_f2->sid = SID_NORM_ASM_F2;
236
235
237 // 3) send the spectral matrix packets
236 // 3) send the spectral matrix packets
238 status = rtems_message_queue_send( queue_id_send, &current_ring_node_to_send_asm_f2, sizeof( ring_node* ) );
237 status = rtems_message_queue_send( queue_id_send, &current_ring_node_to_send_asm_f2, sizeof( ring_node* ) );
239
238
240 // change asm ring node
239 // change asm ring node
241 current_ring_node_to_send_asm_f2 = current_ring_node_to_send_asm_f2->next;
240 current_ring_node_to_send_asm_f2 = current_ring_node_to_send_asm_f2->next;
242 }
241 }
243
242
244 update_queue_max_count( queue_id_q_p2, &hk_lfr_q_p2_fifo_size_max );
243 update_queue_max_count( queue_id_q_p2, &hk_lfr_q_p2_fifo_size_max );
245
244
246 }
245 }
247 }
246 }
248
247
249 //**********
248 //**********
250 // FUNCTIONS
249 // FUNCTIONS
251
250
252 void reset_nb_sm_f2( void )
251 void reset_nb_sm_f2( void )
253 {
252 {
254 nb_sm_before_f2.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0;
253 nb_sm_before_f2.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0;
255 nb_sm_before_f2.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1;
254 nb_sm_before_f2.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1;
256 nb_sm_before_f2.norm_asm = parameter_dump_packet.sy_lfr_n_asm_p[0] * 256 + parameter_dump_packet.sy_lfr_n_asm_p[1];
255 nb_sm_before_f2.norm_asm = (parameter_dump_packet.sy_lfr_n_asm_p[0] * CONST_256) + parameter_dump_packet.sy_lfr_n_asm_p[1];
257 }
256 }
258
257
259 void SM_average_f2( float *averaged_spec_mat_f2,
258 void SM_average_f2( float *averaged_spec_mat_f2,
260 ring_node *ring_node,
259 ring_node *ring_node,
261 unsigned int nbAverageNormF2,
260 unsigned int nbAverageNormF2,
262 asm_msg *msgForMATR )
261 asm_msg *msgForMATR )
263 {
262 {
264 float sum;
263 float sum;
265 unsigned int i;
264 unsigned int i;
266 unsigned char keepMatrix;
265 unsigned char keepMatrix;
267
266
268 // test acquisitionTime validity
267 // test acquisitionTime validity
269 keepMatrix = acquisitionTimeIsValid( ring_node->coarseTime, ring_node->fineTime, 2 );
268 keepMatrix = acquisitionTimeIsValid( ring_node->coarseTime, ring_node->fineTime, CHANNELF2 );
270
269
271 for(i=0; i<TOTAL_SIZE_SM; i++)
270 for(i=0; i<TOTAL_SIZE_SM; i++)
272 {
271 {
273 sum = ( (int *) (ring_node->buffer_address) ) [ i ];
272 sum = ( (int *) (ring_node->buffer_address) ) [ i ];
274 if ( (nbAverageNormF2 == 0) ) // average initialization
273 if ( (nbAverageNormF2 == 0) ) // average initialization
275 {
274 {
276 if (keepMatrix == 1) // keep the matrix and add it to the average
275 if (keepMatrix == 1) // keep the matrix and add it to the average
277 {
276 {
278 averaged_spec_mat_f2[ i ] = sum;
277 averaged_spec_mat_f2[ i ] = sum;
279 }
278 }
280 else // drop the matrix and initialize the average
279 else // drop the matrix and initialize the average
281 {
280 {
282 averaged_spec_mat_f2[ i ] = 0.;
281 averaged_spec_mat_f2[ i ] = INIT_FLOAT;
283 }
282 }
284 msgForMATR->coarseTimeNORM = ring_node->coarseTime;
283 msgForMATR->coarseTimeNORM = ring_node->coarseTime;
285 msgForMATR->fineTimeNORM = ring_node->fineTime;
284 msgForMATR->fineTimeNORM = ring_node->fineTime;
286 }
285 }
287 else
286 else
288 {
287 {
289 if (keepMatrix == 1) // keep the matrix and add it to the average
288 if (keepMatrix == 1) // keep the matrix and add it to the average
290 {
289 {
291 averaged_spec_mat_f2[ i ] = ( averaged_spec_mat_f2[ i ] + sum );
290 averaged_spec_mat_f2[ i ] = ( averaged_spec_mat_f2[ i ] + sum );
292 }
291 }
293 else
292 else
294 {
293 {
295 // nothing to do, the matrix is not valid
294 // nothing to do, the matrix is not valid
296 }
295 }
297 }
296 }
298 }
297 }
299
298
300 if (keepMatrix == 1)
299 if (keepMatrix == 1)
301 {
300 {
302 if ( (nbAverageNormF2 == 0) )
301 if ( (nbAverageNormF2 == 0) )
303 {
302 {
304 msgForMATR->numberOfSMInASMNORM = 1;
303 msgForMATR->numberOfSMInASMNORM = 1;
305 }
304 }
306 else
305 else
307 {
306 {
308 msgForMATR->numberOfSMInASMNORM++;
307 msgForMATR->numberOfSMInASMNORM++;
309 }
308 }
310 }
309 }
311 else
310 else
312 {
311 {
313 if ( (nbAverageNormF2 == 0) )
312 if ( (nbAverageNormF2 == 0) )
314 {
313 {
315 msgForMATR->numberOfSMInASMNORM = 0;
314 msgForMATR->numberOfSMInASMNORM = 0;
316 }
315 }
317 else
316 else
318 {
317 {
319 // nothing to do
318 // nothing to do
320 }
319 }
321 }
320 }
322 }
321 }
323
322
324 void init_k_coefficients_prc2( void )
323 void init_k_coefficients_prc2( void )
325 {
324 {
326 init_k_coefficients( k_coeff_intercalib_f2, NB_BINS_COMPRESSED_SM_F2);
325 init_k_coefficients( k_coeff_intercalib_f2, NB_BINS_COMPRESSED_SM_F2);
327 }
326 }
@@ -1,792 +1,794
1 /** Functions related to data processing.
1 /** Functions related to data processing.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
6 * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation.
7 *
7 *
8 */
8 */
9
9
10 #include "fsw_processing.h"
10 #include "fsw_processing.h"
11 #include "fsw_processing_globals.c"
11 #include "fsw_processing_globals.c"
12 #include "fsw_init.h"
12 #include "fsw_init.h"
13
13
14 unsigned int nb_sm_f0;
14 unsigned int nb_sm_f0;
15 unsigned int nb_sm_f0_aux_f1;
15 unsigned int nb_sm_f0_aux_f1;
16 unsigned int nb_sm_f1;
16 unsigned int nb_sm_f1;
17 unsigned int nb_sm_f0_aux_f2;
17 unsigned int nb_sm_f0_aux_f2;
18
18
19 typedef enum restartState_t
19 typedef enum restartState_t
20 {
20 {
21 WAIT_FOR_F2,
21 WAIT_FOR_F2,
22 WAIT_FOR_F1,
22 WAIT_FOR_F1,
23 WAIT_FOR_F0
23 WAIT_FOR_F0
24 } restartState;
24 } restartState;
25
25
26 //************************
26 //************************
27 // spectral matrices rings
27 // spectral matrices rings
28 ring_node sm_ring_f0[ NB_RING_NODES_SM_F0 ];
28 ring_node sm_ring_f0[ NB_RING_NODES_SM_F0 ];
29 ring_node sm_ring_f1[ NB_RING_NODES_SM_F1 ];
29 ring_node sm_ring_f1[ NB_RING_NODES_SM_F1 ];
30 ring_node sm_ring_f2[ NB_RING_NODES_SM_F2 ];
30 ring_node sm_ring_f2[ NB_RING_NODES_SM_F2 ];
31 ring_node *current_ring_node_sm_f0;
31 ring_node *current_ring_node_sm_f0;
32 ring_node *current_ring_node_sm_f1;
32 ring_node *current_ring_node_sm_f1;
33 ring_node *current_ring_node_sm_f2;
33 ring_node *current_ring_node_sm_f2;
34 ring_node *ring_node_for_averaging_sm_f0;
34 ring_node *ring_node_for_averaging_sm_f0;
35 ring_node *ring_node_for_averaging_sm_f1;
35 ring_node *ring_node_for_averaging_sm_f1;
36 ring_node *ring_node_for_averaging_sm_f2;
36 ring_node *ring_node_for_averaging_sm_f2;
37
37
38 //
38 //
39 ring_node * getRingNodeForAveraging( unsigned char frequencyChannel)
39 ring_node * getRingNodeForAveraging( unsigned char frequencyChannel)
40 {
40 {
41 ring_node *node;
41 ring_node *node;
42
42
43 node = NULL;
43 node = NULL;
44 switch ( frequencyChannel ) {
44 switch ( frequencyChannel ) {
45 case 0:
45 case CHANNELF0:
46 node = ring_node_for_averaging_sm_f0;
46 node = ring_node_for_averaging_sm_f0;
47 break;
47 break;
48 case 1:
48 case CHANNELF1:
49 node = ring_node_for_averaging_sm_f1;
49 node = ring_node_for_averaging_sm_f1;
50 break;
50 break;
51 case 2:
51 case CHANNELF2:
52 node = ring_node_for_averaging_sm_f2;
52 node = ring_node_for_averaging_sm_f2;
53 break;
53 break;
54 default:
54 default:
55 break;
55 break;
56 }
56 }
57
57
58 return node;
58 return node;
59 }
59 }
60
60
61 //***********************************************************
61 //***********************************************************
62 // Interrupt Service Routine for spectral matrices processing
62 // Interrupt Service Routine for spectral matrices processing
63
63
64 void spectral_matrices_isr_f0( int statusReg )
64 void spectral_matrices_isr_f0( int statusReg )
65 {
65 {
66 unsigned char status;
66 unsigned char status;
67 rtems_status_code status_code;
67 rtems_status_code status_code;
68 ring_node *full_ring_node;
68 ring_node *full_ring_node;
69
69
70 status = (unsigned char) (statusReg & 0x03); // [0011] get the status_ready_matrix_f0_x bits
70 status = (unsigned char) (statusReg & BITS_STATUS_F0); // [0011] get the status_ready_matrix_f0_x bits
71
71
72 switch(status)
72 switch(status)
73 {
73 {
74 case 0:
74 case 0:
75 break;
75 break;
76 case 3:
76 case BIT_READY_0_1:
77 // UNEXPECTED VALUE
77 // UNEXPECTED VALUE
78 spectral_matrix_regs->status = 0x03; // [0011]
78 spectral_matrix_regs->status = BIT_READY_0_1; // [0011]
79 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_11 );
79 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_11 );
80 break;
80 break;
81 case 1:
81 case BIT_READY_0:
82 full_ring_node = current_ring_node_sm_f0->previous;
82 full_ring_node = current_ring_node_sm_f0->previous;
83 full_ring_node->coarseTime = spectral_matrix_regs->f0_0_coarse_time;
83 full_ring_node->coarseTime = spectral_matrix_regs->f0_0_coarse_time;
84 full_ring_node->fineTime = spectral_matrix_regs->f0_0_fine_time;
84 full_ring_node->fineTime = spectral_matrix_regs->f0_0_fine_time;
85 current_ring_node_sm_f0 = current_ring_node_sm_f0->next;
85 current_ring_node_sm_f0 = current_ring_node_sm_f0->next;
86 spectral_matrix_regs->f0_0_address = current_ring_node_sm_f0->buffer_address;
86 spectral_matrix_regs->f0_0_address = current_ring_node_sm_f0->buffer_address;
87 // if there are enough ring nodes ready, wake up an AVFx task
87 // if there are enough ring nodes ready, wake up an AVFx task
88 nb_sm_f0 = nb_sm_f0 + 1;
88 nb_sm_f0 = nb_sm_f0 + 1;
89 if (nb_sm_f0 == NB_SM_BEFORE_AVF0)
89 if (nb_sm_f0 == NB_SM_BEFORE_AVF0_F1)
90 {
90 {
91 ring_node_for_averaging_sm_f0 = full_ring_node;
91 ring_node_for_averaging_sm_f0 = full_ring_node;
92 if (rtems_event_send( Task_id[TASKID_AVF0], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
92 if (rtems_event_send( Task_id[TASKID_AVF0], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
93 {
93 {
94 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
94 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
95 }
95 }
96 nb_sm_f0 = 0;
96 nb_sm_f0 = 0;
97 }
97 }
98 spectral_matrix_regs->status = 0x01; // [0000 0001]
98 spectral_matrix_regs->status = BIT_READY_0; // [0000 0001]
99 break;
99 break;
100 case 2:
100 case BIT_READY_1:
101 full_ring_node = current_ring_node_sm_f0->previous;
101 full_ring_node = current_ring_node_sm_f0->previous;
102 full_ring_node->coarseTime = spectral_matrix_regs->f0_1_coarse_time;
102 full_ring_node->coarseTime = spectral_matrix_regs->f0_1_coarse_time;
103 full_ring_node->fineTime = spectral_matrix_regs->f0_1_fine_time;
103 full_ring_node->fineTime = spectral_matrix_regs->f0_1_fine_time;
104 current_ring_node_sm_f0 = current_ring_node_sm_f0->next;
104 current_ring_node_sm_f0 = current_ring_node_sm_f0->next;
105 spectral_matrix_regs->f0_1_address = current_ring_node_sm_f0->buffer_address;
105 spectral_matrix_regs->f0_1_address = current_ring_node_sm_f0->buffer_address;
106 // if there are enough ring nodes ready, wake up an AVFx task
106 // if there are enough ring nodes ready, wake up an AVFx task
107 nb_sm_f0 = nb_sm_f0 + 1;
107 nb_sm_f0 = nb_sm_f0 + 1;
108 if (nb_sm_f0 == NB_SM_BEFORE_AVF0)
108 if (nb_sm_f0 == NB_SM_BEFORE_AVF0_F1)
109 {
109 {
110 ring_node_for_averaging_sm_f0 = full_ring_node;
110 ring_node_for_averaging_sm_f0 = full_ring_node;
111 if (rtems_event_send( Task_id[TASKID_AVF0], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
111 if (rtems_event_send( Task_id[TASKID_AVF0], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
112 {
112 {
113 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
113 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
114 }
114 }
115 nb_sm_f0 = 0;
115 nb_sm_f0 = 0;
116 }
116 }
117 spectral_matrix_regs->status = 0x02; // [0000 0010]
117 spectral_matrix_regs->status = BIT_READY_1; // [0000 0010]
118 break;
118 break;
119 }
119 }
120 }
120 }
121
121
122 void spectral_matrices_isr_f1( int statusReg )
122 void spectral_matrices_isr_f1( int statusReg )
123 {
123 {
124 rtems_status_code status_code;
124 rtems_status_code status_code;
125 unsigned char status;
125 unsigned char status;
126 ring_node *full_ring_node;
126 ring_node *full_ring_node;
127
127
128 status = (unsigned char) ((statusReg & 0x0c) >> 2); // [1100] get the status_ready_matrix_f1_x bits
128 status = (unsigned char) ((statusReg & BITS_STATUS_F1) >> SHIFT_2_BITS); // [1100] get the status_ready_matrix_f1_x bits
129
129
130 switch(status)
130 switch(status)
131 {
131 {
132 case 0:
132 case 0:
133 break;
133 break;
134 case 3:
134 case BIT_READY_0_1:
135 // UNEXPECTED VALUE
135 // UNEXPECTED VALUE
136 spectral_matrix_regs->status = 0xc0; // [1100]
136 spectral_matrix_regs->status = BITS_STATUS_F1; // [1100]
137 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_11 );
137 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_11 );
138 break;
138 break;
139 case 1:
139 case BIT_READY_0:
140 full_ring_node = current_ring_node_sm_f1->previous;
140 full_ring_node = current_ring_node_sm_f1->previous;
141 full_ring_node->coarseTime = spectral_matrix_regs->f1_0_coarse_time;
141 full_ring_node->coarseTime = spectral_matrix_regs->f1_0_coarse_time;
142 full_ring_node->fineTime = spectral_matrix_regs->f1_0_fine_time;
142 full_ring_node->fineTime = spectral_matrix_regs->f1_0_fine_time;
143 current_ring_node_sm_f1 = current_ring_node_sm_f1->next;
143 current_ring_node_sm_f1 = current_ring_node_sm_f1->next;
144 spectral_matrix_regs->f1_0_address = current_ring_node_sm_f1->buffer_address;
144 spectral_matrix_regs->f1_0_address = current_ring_node_sm_f1->buffer_address;
145 // if there are enough ring nodes ready, wake up an AVFx task
145 // if there are enough ring nodes ready, wake up an AVFx task
146 nb_sm_f1 = nb_sm_f1 + 1;
146 nb_sm_f1 = nb_sm_f1 + 1;
147 if (nb_sm_f1 == NB_SM_BEFORE_AVF1)
147 if (nb_sm_f1 == NB_SM_BEFORE_AVF0_F1)
148 {
148 {
149 ring_node_for_averaging_sm_f1 = full_ring_node;
149 ring_node_for_averaging_sm_f1 = full_ring_node;
150 if (rtems_event_send( Task_id[TASKID_AVF1], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
150 if (rtems_event_send( Task_id[TASKID_AVF1], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
151 {
151 {
152 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
152 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
153 }
153 }
154 nb_sm_f1 = 0;
154 nb_sm_f1 = 0;
155 }
155 }
156 spectral_matrix_regs->status = 0x04; // [0000 0100]
156 spectral_matrix_regs->status = BIT_STATUS_F1_0; // [0000 0100]
157 break;
157 break;
158 case 2:
158 case BIT_READY_1:
159 full_ring_node = current_ring_node_sm_f1->previous;
159 full_ring_node = current_ring_node_sm_f1->previous;
160 full_ring_node->coarseTime = spectral_matrix_regs->f1_1_coarse_time;
160 full_ring_node->coarseTime = spectral_matrix_regs->f1_1_coarse_time;
161 full_ring_node->fineTime = spectral_matrix_regs->f1_1_fine_time;
161 full_ring_node->fineTime = spectral_matrix_regs->f1_1_fine_time;
162 current_ring_node_sm_f1 = current_ring_node_sm_f1->next;
162 current_ring_node_sm_f1 = current_ring_node_sm_f1->next;
163 spectral_matrix_regs->f1_1_address = current_ring_node_sm_f1->buffer_address;
163 spectral_matrix_regs->f1_1_address = current_ring_node_sm_f1->buffer_address;
164 // if there are enough ring nodes ready, wake up an AVFx task
164 // if there are enough ring nodes ready, wake up an AVFx task
165 nb_sm_f1 = nb_sm_f1 + 1;
165 nb_sm_f1 = nb_sm_f1 + 1;
166 if (nb_sm_f1 == NB_SM_BEFORE_AVF1)
166 if (nb_sm_f1 == NB_SM_BEFORE_AVF0_F1)
167 {
167 {
168 ring_node_for_averaging_sm_f1 = full_ring_node;
168 ring_node_for_averaging_sm_f1 = full_ring_node;
169 if (rtems_event_send( Task_id[TASKID_AVF1], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
169 if (rtems_event_send( Task_id[TASKID_AVF1], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
170 {
170 {
171 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
171 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
172 }
172 }
173 nb_sm_f1 = 0;
173 nb_sm_f1 = 0;
174 }
174 }
175 spectral_matrix_regs->status = 0x08; // [1000 0000]
175 spectral_matrix_regs->status = BIT_STATUS_F1_1; // [1000 0000]
176 break;
176 break;
177 }
177 }
178 }
178 }
179
179
180 void spectral_matrices_isr_f2( int statusReg )
180 void spectral_matrices_isr_f2( int statusReg )
181 {
181 {
182 unsigned char status;
182 unsigned char status;
183 rtems_status_code status_code;
183 rtems_status_code status_code;
184
184
185 status = (unsigned char) ((statusReg & 0x30) >> 4); // [0011 0000] get the status_ready_matrix_f2_x bits
185 status = (unsigned char) ((statusReg & BITS_STATUS_F2) >> SHIFT_4_BITS); // [0011 0000] get the status_ready_matrix_f2_x bits
186
186
187 switch(status)
187 switch(status)
188 {
188 {
189 case 0:
189 case 0:
190 break;
190 break;
191 case 3:
191 case BIT_READY_0_1:
192 // UNEXPECTED VALUE
192 // UNEXPECTED VALUE
193 spectral_matrix_regs->status = 0x30; // [0011 0000]
193 spectral_matrix_regs->status = BITS_STATUS_F2; // [0011 0000]
194 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_11 );
194 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_11 );
195 break;
195 break;
196 case 1:
196 case BIT_READY_0:
197 ring_node_for_averaging_sm_f2 = current_ring_node_sm_f2->previous;
197 ring_node_for_averaging_sm_f2 = current_ring_node_sm_f2->previous;
198 current_ring_node_sm_f2 = current_ring_node_sm_f2->next;
198 current_ring_node_sm_f2 = current_ring_node_sm_f2->next;
199 ring_node_for_averaging_sm_f2->coarseTime = spectral_matrix_regs->f2_0_coarse_time;
199 ring_node_for_averaging_sm_f2->coarseTime = spectral_matrix_regs->f2_0_coarse_time;
200 ring_node_for_averaging_sm_f2->fineTime = spectral_matrix_regs->f2_0_fine_time;
200 ring_node_for_averaging_sm_f2->fineTime = spectral_matrix_regs->f2_0_fine_time;
201 spectral_matrix_regs->f2_0_address = current_ring_node_sm_f2->buffer_address;
201 spectral_matrix_regs->f2_0_address = current_ring_node_sm_f2->buffer_address;
202 spectral_matrix_regs->status = 0x10; // [0001 0000]
202 spectral_matrix_regs->status = BIT_STATUS_F2_0; // [0001 0000]
203 if (rtems_event_send( Task_id[TASKID_AVF2], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
203 if (rtems_event_send( Task_id[TASKID_AVF2], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
204 {
204 {
205 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
205 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
206 }
206 }
207 break;
207 break;
208 case 2:
208 case BIT_READY_1:
209 ring_node_for_averaging_sm_f2 = current_ring_node_sm_f2->previous;
209 ring_node_for_averaging_sm_f2 = current_ring_node_sm_f2->previous;
210 current_ring_node_sm_f2 = current_ring_node_sm_f2->next;
210 current_ring_node_sm_f2 = current_ring_node_sm_f2->next;
211 ring_node_for_averaging_sm_f2->coarseTime = spectral_matrix_regs->f2_1_coarse_time;
211 ring_node_for_averaging_sm_f2->coarseTime = spectral_matrix_regs->f2_1_coarse_time;
212 ring_node_for_averaging_sm_f2->fineTime = spectral_matrix_regs->f2_1_fine_time;
212 ring_node_for_averaging_sm_f2->fineTime = spectral_matrix_regs->f2_1_fine_time;
213 spectral_matrix_regs->f2_1_address = current_ring_node_sm_f2->buffer_address;
213 spectral_matrix_regs->f2_1_address = current_ring_node_sm_f2->buffer_address;
214 spectral_matrix_regs->status = 0x20; // [0010 0000]
214 spectral_matrix_regs->status = BIT_STATUS_F2_1; // [0010 0000]
215 if (rtems_event_send( Task_id[TASKID_AVF2], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
215 if (rtems_event_send( Task_id[TASKID_AVF2], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL)
216 {
216 {
217 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
217 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 );
218 }
218 }
219 break;
219 break;
220 }
220 }
221 }
221 }
222
222
223 void spectral_matrix_isr_error_handler( int statusReg )
223 void spectral_matrix_isr_error_handler( int statusReg )
224 {
224 {
225 // STATUS REGISTER
225 // STATUS REGISTER
226 // input_fifo_write(2) *** input_fifo_write(1) *** input_fifo_write(0)
226 // input_fifo_write(2) *** input_fifo_write(1) *** input_fifo_write(0)
227 // 10 9 8
227 // 10 9 8
228 // buffer_full ** [bad_component_err] ** f2_1 ** f2_0 ** f1_1 ** f1_0 ** f0_1 ** f0_0
228 // buffer_full ** [bad_component_err] ** f2_1 ** f2_0 ** f1_1 ** f1_0 ** f0_1 ** f0_0
229 // 7 6 5 4 3 2 1 0
229 // 7 6 5 4 3 2 1 0
230 // [bad_component_err] not defined in the last version of the VHDL code
230 // [bad_component_err] not defined in the last version of the VHDL code
231
231
232 rtems_status_code status_code;
232 rtems_status_code status_code;
233
233
234 //***************************************************
234 //***************************************************
235 // the ASM status register is copied in the HK packet
235 // the ASM status register is copied in the HK packet
236 housekeeping_packet.hk_lfr_vhdl_aa_sm = (unsigned char) (statusReg & 0x780 >> 7); // [0111 1000 0000]
236 housekeeping_packet.hk_lfr_vhdl_aa_sm = (unsigned char) ((statusReg & BITS_HK_AA_SM) >> SHIFT_7_BITS); // [0111 1000 0000]
237
237
238 if (statusReg & 0x7c0) // [0111 1100 0000]
238 if (statusReg & BITS_SM_ERR) // [0111 1100 0000]
239 {
239 {
240 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_8 );
240 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_8 );
241 }
241 }
242
242
243 spectral_matrix_regs->status = spectral_matrix_regs->status & 0x7c0;
243 spectral_matrix_regs->status = spectral_matrix_regs->status & BITS_SM_ERR;
244
244
245 }
245 }
246
246
247 rtems_isr spectral_matrices_isr( rtems_vector_number vector )
247 rtems_isr spectral_matrices_isr( rtems_vector_number vector )
248 {
248 {
249 // STATUS REGISTER
249 // STATUS REGISTER
250 // input_fifo_write(2) *** input_fifo_write(1) *** input_fifo_write(0)
250 // input_fifo_write(2) *** input_fifo_write(1) *** input_fifo_write(0)
251 // 10 9 8
251 // 10 9 8
252 // buffer_full ** bad_component_err ** f2_1 ** f2_0 ** f1_1 ** f1_0 ** f0_1 ** f0_0
252 // buffer_full ** bad_component_err ** f2_1 ** f2_0 ** f1_1 ** f1_0 ** f0_1 ** f0_0
253 // 7 6 5 4 3 2 1 0
253 // 7 6 5 4 3 2 1 0
254
254
255 int statusReg;
255 int statusReg;
256
256
257 static restartState state = WAIT_FOR_F2;
257 static restartState state = WAIT_FOR_F2;
258
258
259 statusReg = spectral_matrix_regs->status;
259 statusReg = spectral_matrix_regs->status;
260
260
261 if (thisIsAnASMRestart == 0)
261 if (thisIsAnASMRestart == 0)
262 { // this is not a restart sequence, process incoming matrices normally
262 { // this is not a restart sequence, process incoming matrices normally
263 spectral_matrices_isr_f0( statusReg );
263 spectral_matrices_isr_f0( statusReg );
264
264
265 spectral_matrices_isr_f1( statusReg );
265 spectral_matrices_isr_f1( statusReg );
266
266
267 spectral_matrices_isr_f2( statusReg );
267 spectral_matrices_isr_f2( statusReg );
268 }
268 }
269 else
269 else
270 { // a restart sequence has to be launched
270 { // a restart sequence has to be launched
271 switch (state) {
271 switch (state) {
272 case WAIT_FOR_F2:
272 case WAIT_FOR_F2:
273 if ((statusReg & 0x30) != 0x00) // [0011 0000] check the status_ready_matrix_f2_x bits
273 if ((statusReg & BITS_STATUS_F2) != INIT_CHAR) // [0011 0000] check the status_ready_matrix_f2_x bits
274 {
274 {
275 state = WAIT_FOR_F1;
275 state = WAIT_FOR_F1;
276 }
276 }
277 break;
277 break;
278 case WAIT_FOR_F1:
278 case WAIT_FOR_F1:
279 if ((statusReg & 0x0c) != 0x00) // [0000 1100] check the status_ready_matrix_f1_x bits
279 if ((statusReg & BITS_STATUS_F1) != INIT_CHAR) // [0000 1100] check the status_ready_matrix_f1_x bits
280 {
280 {
281 state = WAIT_FOR_F0;
281 state = WAIT_FOR_F0;
282 }
282 }
283 break;
283 break;
284 case WAIT_FOR_F0:
284 case WAIT_FOR_F0:
285 if ((statusReg & 0x03) != 0x00) // [0000 0011] check the status_ready_matrix_f0_x bits
285 if ((statusReg & BITS_STATUS_F0) != INIT_CHAR) // [0000 0011] check the status_ready_matrix_f0_x bits
286 {
286 {
287 state = WAIT_FOR_F2;
287 state = WAIT_FOR_F2;
288 thisIsAnASMRestart = 0;
288 thisIsAnASMRestart = 0;
289 }
289 }
290 break;
290 break;
291 default:
291 default:
292 break;
292 break;
293 }
293 }
294 reset_sm_status();
294 reset_sm_status();
295 }
295 }
296
296
297 spectral_matrix_isr_error_handler( statusReg );
297 spectral_matrix_isr_error_handler( statusReg );
298
298
299 }
299 }
300
300
301 //******************
301 //******************
302 // Spectral Matrices
302 // Spectral Matrices
303
303
304 void reset_nb_sm( void )
304 void reset_nb_sm( void )
305 {
305 {
306 nb_sm_f0 = 0;
306 nb_sm_f0 = 0;
307 nb_sm_f0_aux_f1 = 0;
307 nb_sm_f0_aux_f1 = 0;
308 nb_sm_f0_aux_f2 = 0;
308 nb_sm_f0_aux_f2 = 0;
309
309
310 nb_sm_f1 = 0;
310 nb_sm_f1 = 0;
311 }
311 }
312
312
313 void SM_init_rings( void )
313 void SM_init_rings( void )
314 {
314 {
315 init_ring( sm_ring_f0, NB_RING_NODES_SM_F0, sm_f0, TOTAL_SIZE_SM );
315 init_ring( sm_ring_f0, NB_RING_NODES_SM_F0, sm_f0, TOTAL_SIZE_SM );
316 init_ring( sm_ring_f1, NB_RING_NODES_SM_F1, sm_f1, TOTAL_SIZE_SM );
316 init_ring( sm_ring_f1, NB_RING_NODES_SM_F1, sm_f1, TOTAL_SIZE_SM );
317 init_ring( sm_ring_f2, NB_RING_NODES_SM_F2, sm_f2, TOTAL_SIZE_SM );
317 init_ring( sm_ring_f2, NB_RING_NODES_SM_F2, sm_f2, TOTAL_SIZE_SM );
318
318
319 DEBUG_PRINTF1("sm_ring_f0 @%x\n", (unsigned int) sm_ring_f0)
319 DEBUG_PRINTF1("sm_ring_f0 @%x\n", (unsigned int) sm_ring_f0)
320 DEBUG_PRINTF1("sm_ring_f1 @%x\n", (unsigned int) sm_ring_f1)
320 DEBUG_PRINTF1("sm_ring_f1 @%x\n", (unsigned int) sm_ring_f1)
321 DEBUG_PRINTF1("sm_ring_f2 @%x\n", (unsigned int) sm_ring_f2)
321 DEBUG_PRINTF1("sm_ring_f2 @%x\n", (unsigned int) sm_ring_f2)
322 DEBUG_PRINTF1("sm_f0 @%x\n", (unsigned int) sm_f0)
322 DEBUG_PRINTF1("sm_f0 @%x\n", (unsigned int) sm_f0)
323 DEBUG_PRINTF1("sm_f1 @%x\n", (unsigned int) sm_f1)
323 DEBUG_PRINTF1("sm_f1 @%x\n", (unsigned int) sm_f1)
324 DEBUG_PRINTF1("sm_f2 @%x\n", (unsigned int) sm_f2)
324 DEBUG_PRINTF1("sm_f2 @%x\n", (unsigned int) sm_f2)
325 }
325 }
326
326
327 void ASM_generic_init_ring( ring_node_asm *ring, unsigned char nbNodes )
327 void ASM_generic_init_ring( ring_node_asm *ring, unsigned char nbNodes )
328 {
328 {
329 unsigned char i;
329 unsigned char i;
330
330
331 ring[ nbNodes - 1 ].next
331 ring[ nbNodes - 1 ].next
332 = (ring_node_asm*) &ring[ 0 ];
332 = (ring_node_asm*) &ring[ 0 ];
333
333
334 for(i=0; i<nbNodes-1; i++)
334 for(i=0; i<nbNodes-1; i++)
335 {
335 {
336 ring[ i ].next = (ring_node_asm*) &ring[ i + 1 ];
336 ring[ i ].next = (ring_node_asm*) &ring[ i + 1 ];
337 }
337 }
338 }
338 }
339
339
340 void SM_reset_current_ring_nodes( void )
340 void SM_reset_current_ring_nodes( void )
341 {
341 {
342 current_ring_node_sm_f0 = sm_ring_f0[0].next;
342 current_ring_node_sm_f0 = sm_ring_f0[0].next;
343 current_ring_node_sm_f1 = sm_ring_f1[0].next;
343 current_ring_node_sm_f1 = sm_ring_f1[0].next;
344 current_ring_node_sm_f2 = sm_ring_f2[0].next;
344 current_ring_node_sm_f2 = sm_ring_f2[0].next;
345
345
346 ring_node_for_averaging_sm_f0 = NULL;
346 ring_node_for_averaging_sm_f0 = NULL;
347 ring_node_for_averaging_sm_f1 = NULL;
347 ring_node_for_averaging_sm_f1 = NULL;
348 ring_node_for_averaging_sm_f2 = NULL;
348 ring_node_for_averaging_sm_f2 = NULL;
349 }
349 }
350
350
351 //*****************
351 //*****************
352 // Basic Parameters
352 // Basic Parameters
353
353
354 void BP_init_header( bp_packet *packet,
354 void BP_init_header( bp_packet *packet,
355 unsigned int apid, unsigned char sid,
355 unsigned int apid, unsigned char sid,
356 unsigned int packetLength, unsigned char blkNr )
356 unsigned int packetLength, unsigned char blkNr )
357 {
357 {
358 packet->targetLogicalAddress = CCSDS_DESTINATION_ID;
358 packet->targetLogicalAddress = CCSDS_DESTINATION_ID;
359 packet->protocolIdentifier = CCSDS_PROTOCOLE_ID;
359 packet->protocolIdentifier = CCSDS_PROTOCOLE_ID;
360 packet->reserved = 0x00;
360 packet->reserved = INIT_CHAR;
361 packet->userApplication = CCSDS_USER_APP;
361 packet->userApplication = CCSDS_USER_APP;
362 packet->packetID[0] = (unsigned char) (apid >> 8);
362 packet->packetID[0] = (unsigned char) (apid >> SHIFT_1_BYTE);
363 packet->packetID[1] = (unsigned char) (apid);
363 packet->packetID[1] = (unsigned char) (apid);
364 packet->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
364 packet->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
365 packet->packetSequenceControl[1] = 0x00;
365 packet->packetSequenceControl[1] = INIT_CHAR;
366 packet->packetLength[0] = (unsigned char) (packetLength >> 8);
366 packet->packetLength[0] = (unsigned char) (packetLength >> SHIFT_1_BYTE);
367 packet->packetLength[1] = (unsigned char) (packetLength);
367 packet->packetLength[1] = (unsigned char) (packetLength);
368 // DATA FIELD HEADER
368 // DATA FIELD HEADER
369 packet->spare1_pusVersion_spare2 = 0x10;
369 packet->spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
370 packet->serviceType = TM_TYPE_LFR_SCIENCE; // service type
370 packet->serviceType = TM_TYPE_LFR_SCIENCE; // service type
371 packet->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; // service subtype
371 packet->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; // service subtype
372 packet->destinationID = TM_DESTINATION_ID_GROUND;
372 packet->destinationID = TM_DESTINATION_ID_GROUND;
373 packet->time[0] = 0x00;
373 packet->time[BYTE_0] = INIT_CHAR;
374 packet->time[1] = 0x00;
374 packet->time[BYTE_1] = INIT_CHAR;
375 packet->time[2] = 0x00;
375 packet->time[BYTE_2] = INIT_CHAR;
376 packet->time[3] = 0x00;
376 packet->time[BYTE_3] = INIT_CHAR;
377 packet->time[4] = 0x00;
377 packet->time[BYTE_4] = INIT_CHAR;
378 packet->time[5] = 0x00;
378 packet->time[BYTE_5] = INIT_CHAR;
379 // AUXILIARY DATA HEADER
379 // AUXILIARY DATA HEADER
380 packet->sid = sid;
380 packet->sid = sid;
381 packet->pa_bia_status_info = 0x00;
381 packet->pa_bia_status_info = INIT_CHAR;
382 packet->sy_lfr_common_parameters_spare = 0x00;
382 packet->sy_lfr_common_parameters_spare = INIT_CHAR;
383 packet->sy_lfr_common_parameters = 0x00;
383 packet->sy_lfr_common_parameters = INIT_CHAR;
384 packet->acquisitionTime[0] = 0x00;
384 packet->acquisitionTime[BYTE_0] = INIT_CHAR;
385 packet->acquisitionTime[1] = 0x00;
385 packet->acquisitionTime[BYTE_1] = INIT_CHAR;
386 packet->acquisitionTime[2] = 0x00;
386 packet->acquisitionTime[BYTE_2] = INIT_CHAR;
387 packet->acquisitionTime[3] = 0x00;
387 packet->acquisitionTime[BYTE_3] = INIT_CHAR;
388 packet->acquisitionTime[4] = 0x00;
388 packet->acquisitionTime[BYTE_4] = INIT_CHAR;
389 packet->acquisitionTime[5] = 0x00;
389 packet->acquisitionTime[BYTE_5] = INIT_CHAR;
390 packet->pa_lfr_bp_blk_nr[0] = 0x00; // BLK_NR MSB
390 packet->pa_lfr_bp_blk_nr[0] = INIT_CHAR; // BLK_NR MSB
391 packet->pa_lfr_bp_blk_nr[1] = blkNr; // BLK_NR LSB
391 packet->pa_lfr_bp_blk_nr[1] = blkNr; // BLK_NR LSB
392 }
392 }
393
393
394 void BP_init_header_with_spare( bp_packet_with_spare *packet,
394 void BP_init_header_with_spare( bp_packet_with_spare *packet,
395 unsigned int apid, unsigned char sid,
395 unsigned int apid, unsigned char sid,
396 unsigned int packetLength , unsigned char blkNr)
396 unsigned int packetLength , unsigned char blkNr)
397 {
397 {
398 packet->targetLogicalAddress = CCSDS_DESTINATION_ID;
398 packet->targetLogicalAddress = CCSDS_DESTINATION_ID;
399 packet->protocolIdentifier = CCSDS_PROTOCOLE_ID;
399 packet->protocolIdentifier = CCSDS_PROTOCOLE_ID;
400 packet->reserved = 0x00;
400 packet->reserved = INIT_CHAR;
401 packet->userApplication = CCSDS_USER_APP;
401 packet->userApplication = CCSDS_USER_APP;
402 packet->packetID[0] = (unsigned char) (apid >> 8);
402 packet->packetID[0] = (unsigned char) (apid >> SHIFT_1_BYTE);
403 packet->packetID[1] = (unsigned char) (apid);
403 packet->packetID[1] = (unsigned char) (apid);
404 packet->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
404 packet->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
405 packet->packetSequenceControl[1] = 0x00;
405 packet->packetSequenceControl[1] = INIT_CHAR;
406 packet->packetLength[0] = (unsigned char) (packetLength >> 8);
406 packet->packetLength[0] = (unsigned char) (packetLength >> SHIFT_1_BYTE);
407 packet->packetLength[1] = (unsigned char) (packetLength);
407 packet->packetLength[1] = (unsigned char) (packetLength);
408 // DATA FIELD HEADER
408 // DATA FIELD HEADER
409 packet->spare1_pusVersion_spare2 = 0x10;
409 packet->spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
410 packet->serviceType = TM_TYPE_LFR_SCIENCE; // service type
410 packet->serviceType = TM_TYPE_LFR_SCIENCE; // service type
411 packet->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; // service subtype
411 packet->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; // service subtype
412 packet->destinationID = TM_DESTINATION_ID_GROUND;
412 packet->destinationID = TM_DESTINATION_ID_GROUND;
413 // AUXILIARY DATA HEADER
413 // AUXILIARY DATA HEADER
414 packet->sid = sid;
414 packet->sid = sid;
415 packet->pa_bia_status_info = 0x00;
415 packet->pa_bia_status_info = INIT_CHAR;
416 packet->sy_lfr_common_parameters_spare = 0x00;
416 packet->sy_lfr_common_parameters_spare = INIT_CHAR;
417 packet->sy_lfr_common_parameters = 0x00;
417 packet->sy_lfr_common_parameters = INIT_CHAR;
418 packet->time[0] = 0x00;
418 packet->time[BYTE_0] = INIT_CHAR;
419 packet->time[0] = 0x00;
419 packet->time[BYTE_1] = INIT_CHAR;
420 packet->time[0] = 0x00;
420 packet->time[BYTE_2] = INIT_CHAR;
421 packet->time[0] = 0x00;
421 packet->time[BYTE_3] = INIT_CHAR;
422 packet->time[0] = 0x00;
422 packet->time[BYTE_4] = INIT_CHAR;
423 packet->time[0] = 0x00;
423 packet->time[BYTE_5] = INIT_CHAR;
424 packet->source_data_spare = 0x00;
424 packet->source_data_spare = INIT_CHAR;
425 packet->pa_lfr_bp_blk_nr[0] = 0x00; // BLK_NR MSB
425 packet->pa_lfr_bp_blk_nr[0] = INIT_CHAR; // BLK_NR MSB
426 packet->pa_lfr_bp_blk_nr[1] = blkNr; // BLK_NR LSB
426 packet->pa_lfr_bp_blk_nr[1] = blkNr; // BLK_NR LSB
427 }
427 }
428
428
429 void BP_send(char *data, rtems_id queue_id, unsigned int nbBytesToSend, unsigned int sid )
429 void BP_send(char *data, rtems_id queue_id, unsigned int nbBytesToSend, unsigned int sid )
430 {
430 {
431 rtems_status_code status;
431 rtems_status_code status;
432
432
433 // SEND PACKET
433 // SEND PACKET
434 status = rtems_message_queue_send( queue_id, data, nbBytesToSend);
434 status = rtems_message_queue_send( queue_id, data, nbBytesToSend);
435 if (status != RTEMS_SUCCESSFUL)
435 if (status != RTEMS_SUCCESSFUL)
436 {
436 {
437 PRINTF1("ERR *** in BP_send *** ERR %d\n", (int) status)
437 PRINTF1("ERR *** in BP_send *** ERR %d\n", (int) status)
438 }
438 }
439 }
439 }
440
440
441 void BP_send_s1_s2(char *data, rtems_id queue_id, unsigned int nbBytesToSend, unsigned int sid )
441 void BP_send_s1_s2(char *data, rtems_id queue_id, unsigned int nbBytesToSend, unsigned int sid )
442 {
442 {
443 /** This function is used to send the BP paquets when needed.
443 /** This function is used to send the BP paquets when needed.
444 *
444 *
445 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
445 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
446 *
446 *
447 * @return void
447 * @return void
448 *
448 *
449 * SBM1 and SBM2 paquets are sent depending on the type of the LFR mode transition.
449 * SBM1 and SBM2 paquets are sent depending on the type of the LFR mode transition.
450 * BURST paquets are sent everytime.
450 * BURST paquets are sent everytime.
451 *
451 *
452 */
452 */
453
453
454 rtems_status_code status;
454 rtems_status_code status;
455
455
456 // SEND PACKET
456 // SEND PACKET
457 // before lastValidTransitionDate, the data are drops even if they are ready
457 // before lastValidTransitionDate, the data are drops even if they are ready
458 // this guarantees that no SBM packets will be received before the requested enter mode time
458 // this guarantees that no SBM packets will be received before the requested enter mode time
459 if ( time_management_regs->coarse_time >= lastValidEnterModeTime)
459 if ( time_management_regs->coarse_time >= lastValidEnterModeTime)
460 {
460 {
461 status = rtems_message_queue_send( queue_id, data, nbBytesToSend);
461 status = rtems_message_queue_send( queue_id, data, nbBytesToSend);
462 if (status != RTEMS_SUCCESSFUL)
462 if (status != RTEMS_SUCCESSFUL)
463 {
463 {
464 PRINTF1("ERR *** in BP_send *** ERR %d\n", (int) status)
464 PRINTF1("ERR *** in BP_send *** ERR %d\n", (int) status)
465 }
465 }
466 }
466 }
467 }
467 }
468
468
469 //******************
469 //******************
470 // general functions
470 // general functions
471
471
472 void reset_sm_status( void )
472 void reset_sm_status( void )
473 {
473 {
474 // error
474 // error
475 // 10 --------------- 9 ---------------- 8 ---------------- 7 ---------
475 // 10 --------------- 9 ---------------- 8 ---------------- 7 ---------
476 // input_fif0_write_2 input_fifo_write_1 input_fifo_write_0 buffer_full
476 // input_fif0_write_2 input_fifo_write_1 input_fifo_write_0 buffer_full
477 // ---------- 5 -- 4 -- 3 -- 2 -- 1 -- 0 --
477 // ---------- 5 -- 4 -- 3 -- 2 -- 1 -- 0 --
478 // ready bits f2_1 f2_0 f1_1 f1_1 f0_1 f0_0
478 // ready bits f2_1 f2_0 f1_1 f1_1 f0_1 f0_0
479
479
480 spectral_matrix_regs->status = 0x7ff; // [0111 1111 1111]
480 spectral_matrix_regs->status = BITS_STATUS_REG; // [0111 1111 1111]
481 }
481 }
482
482
483 void reset_spectral_matrix_regs( void )
483 void reset_spectral_matrix_regs( void )
484 {
484 {
485 /** This function resets the spectral matrices module registers.
485 /** This function resets the spectral matrices module registers.
486 *
486 *
487 * The registers affected by this function are located at the following offset addresses:
487 * The registers affected by this function are located at the following offset addresses:
488 *
488 *
489 * - 0x00 config
489 * - 0x00 config
490 * - 0x04 status
490 * - 0x04 status
491 * - 0x08 matrixF0_Address0
491 * - 0x08 matrixF0_Address0
492 * - 0x10 matrixFO_Address1
492 * - 0x10 matrixFO_Address1
493 * - 0x14 matrixF1_Address
493 * - 0x14 matrixF1_Address
494 * - 0x18 matrixF2_Address
494 * - 0x18 matrixF2_Address
495 *
495 *
496 */
496 */
497
497
498 set_sm_irq_onError( 0 );
498 set_sm_irq_onError( 0 );
499
499
500 set_sm_irq_onNewMatrix( 0 );
500 set_sm_irq_onNewMatrix( 0 );
501
501
502 reset_sm_status();
502 reset_sm_status();
503
503
504 // F1
504 // F1
505 spectral_matrix_regs->f0_0_address = current_ring_node_sm_f0->previous->buffer_address;
505 spectral_matrix_regs->f0_0_address = current_ring_node_sm_f0->previous->buffer_address;
506 spectral_matrix_regs->f0_1_address = current_ring_node_sm_f0->buffer_address;
506 spectral_matrix_regs->f0_1_address = current_ring_node_sm_f0->buffer_address;
507 // F2
507 // F2
508 spectral_matrix_regs->f1_0_address = current_ring_node_sm_f1->previous->buffer_address;
508 spectral_matrix_regs->f1_0_address = current_ring_node_sm_f1->previous->buffer_address;
509 spectral_matrix_regs->f1_1_address = current_ring_node_sm_f1->buffer_address;
509 spectral_matrix_regs->f1_1_address = current_ring_node_sm_f1->buffer_address;
510 // F3
510 // F3
511 spectral_matrix_regs->f2_0_address = current_ring_node_sm_f2->previous->buffer_address;
511 spectral_matrix_regs->f2_0_address = current_ring_node_sm_f2->previous->buffer_address;
512 spectral_matrix_regs->f2_1_address = current_ring_node_sm_f2->buffer_address;
512 spectral_matrix_regs->f2_1_address = current_ring_node_sm_f2->buffer_address;
513
513
514 spectral_matrix_regs->matrix_length = 0xc8; // 25 * 128 / 16 = 200 = 0xc8
514 spectral_matrix_regs->matrix_length = DEFAULT_MATRIX_LENGTH; // 25 * 128 / 16 = 200 = 0xc8
515 }
515 }
516
516
517 void set_time( unsigned char *time, unsigned char * timeInBuffer )
517 void set_time( unsigned char *time, unsigned char * timeInBuffer )
518 {
518 {
519 time[0] = timeInBuffer[0];
519 time[BYTE_0] = timeInBuffer[BYTE_0];
520 time[1] = timeInBuffer[1];
520 time[BYTE_1] = timeInBuffer[BYTE_1];
521 time[2] = timeInBuffer[2];
521 time[BYTE_2] = timeInBuffer[BYTE_2];
522 time[3] = timeInBuffer[3];
522 time[BYTE_3] = timeInBuffer[BYTE_3];
523 time[4] = timeInBuffer[6];
523 time[BYTE_4] = timeInBuffer[BYTE_6];
524 time[5] = timeInBuffer[7];
524 time[BYTE_5] = timeInBuffer[BYTE_7];
525 }
525 }
526
526
527 unsigned long long int get_acquisition_time( unsigned char *timePtr )
527 unsigned long long int get_acquisition_time( unsigned char *timePtr )
528 {
528 {
529 unsigned long long int acquisitionTimeAslong;
529 unsigned long long int acquisitionTimeAslong;
530 acquisitionTimeAslong = 0x00;
530 acquisitionTimeAslong = INIT_CHAR;
531 acquisitionTimeAslong = ( (unsigned long long int) (timePtr[0] & 0x7f) << 40 ) // [0111 1111] mask the synchronization bit
531 acquisitionTimeAslong =
532 + ( (unsigned long long int) timePtr[1] << 32 )
532 ( (unsigned long long int) (timePtr[BYTE_0] & SYNC_BIT_MASK) << SHIFT_5_BYTES ) // [0111 1111] mask the synchronization bit
533 + ( (unsigned long long int) timePtr[2] << 24 )
533 + ( (unsigned long long int) timePtr[BYTE_1] << SHIFT_4_BYTES )
534 + ( (unsigned long long int) timePtr[3] << 16 )
534 + ( (unsigned long long int) timePtr[BYTE_2] << SHIFT_3_BYTES )
535 + ( (unsigned long long int) timePtr[6] << 8 )
535 + ( (unsigned long long int) timePtr[BYTE_3] << SHIFT_2_BYTES )
536 + ( (unsigned long long int) timePtr[7] );
536 + ( (unsigned long long int) timePtr[BYTE_6] << SHIFT_1_BYTE )
537 + ( (unsigned long long int) timePtr[BYTE_7] );
537 return acquisitionTimeAslong;
538 return acquisitionTimeAslong;
538 }
539 }
539
540
540 unsigned char getSID( rtems_event_set event )
541 unsigned char getSID( rtems_event_set event )
541 {
542 {
542 unsigned char sid;
543 unsigned char sid;
543
544
544 rtems_event_set eventSetBURST;
545 rtems_event_set eventSetBURST;
545 rtems_event_set eventSetSBM;
546 rtems_event_set eventSetSBM;
546
547
547 //******
548 //******
548 // BURST
549 // BURST
549 eventSetBURST = RTEMS_EVENT_BURST_BP1_F0
550 eventSetBURST = RTEMS_EVENT_BURST_BP1_F0
550 | RTEMS_EVENT_BURST_BP1_F1
551 | RTEMS_EVENT_BURST_BP1_F1
551 | RTEMS_EVENT_BURST_BP2_F0
552 | RTEMS_EVENT_BURST_BP2_F0
552 | RTEMS_EVENT_BURST_BP2_F1;
553 | RTEMS_EVENT_BURST_BP2_F1;
553
554
554 //****
555 //****
555 // SBM
556 // SBM
556 eventSetSBM = RTEMS_EVENT_SBM_BP1_F0
557 eventSetSBM = RTEMS_EVENT_SBM_BP1_F0
557 | RTEMS_EVENT_SBM_BP1_F1
558 | RTEMS_EVENT_SBM_BP1_F1
558 | RTEMS_EVENT_SBM_BP2_F0
559 | RTEMS_EVENT_SBM_BP2_F0
559 | RTEMS_EVENT_SBM_BP2_F1;
560 | RTEMS_EVENT_SBM_BP2_F1;
560
561
561 if (event & eventSetBURST)
562 if (event & eventSetBURST)
562 {
563 {
563 sid = SID_BURST_BP1_F0;
564 sid = SID_BURST_BP1_F0;
564 }
565 }
565 else if (event & eventSetSBM)
566 else if (event & eventSetSBM)
566 {
567 {
567 sid = SID_SBM1_BP1_F0;
568 sid = SID_SBM1_BP1_F0;
568 }
569 }
569 else
570 else
570 {
571 {
571 sid = 0;
572 sid = 0;
572 }
573 }
573
574
574 return sid;
575 return sid;
575 }
576 }
576
577
577 void extractReImVectors( float *inputASM, float *outputASM, unsigned int asmComponent )
578 void extractReImVectors( float *inputASM, float *outputASM, unsigned int asmComponent )
578 {
579 {
579 unsigned int i;
580 unsigned int i;
580 float re;
581 float re;
581 float im;
582 float im;
582
583
583 for (i=0; i<NB_BINS_PER_SM; i++){
584 for (i=0; i<NB_BINS_PER_SM; i++){
584 re = inputASM[ (asmComponent*NB_BINS_PER_SM) + i * 2 ];
585 re = inputASM[ (asmComponent*NB_BINS_PER_SM) + (i * SM_BYTES_PER_VAL) ];
585 im = inputASM[ (asmComponent*NB_BINS_PER_SM) + i * 2 + 1];
586 im = inputASM[ (asmComponent*NB_BINS_PER_SM) + (i * SM_BYTES_PER_VAL) + 1];
586 outputASM[ (asmComponent *NB_BINS_PER_SM) + i] = re;
587 outputASM[ ( asmComponent *NB_BINS_PER_SM) + i] = re;
587 outputASM[ (asmComponent+1)*NB_BINS_PER_SM + i] = im;
588 outputASM[ ((asmComponent+1)*NB_BINS_PER_SM) + i] = im;
588 }
589 }
589 }
590 }
590
591
591 void copyReVectors( float *inputASM, float *outputASM, unsigned int asmComponent )
592 void copyReVectors( float *inputASM, float *outputASM, unsigned int asmComponent )
592 {
593 {
593 unsigned int i;
594 unsigned int i;
594 float re;
595 float re;
595
596
596 for (i=0; i<NB_BINS_PER_SM; i++){
597 for (i=0; i<NB_BINS_PER_SM; i++){
597 re = inputASM[ (asmComponent*NB_BINS_PER_SM) + i];
598 re = inputASM[ (asmComponent*NB_BINS_PER_SM) + i];
598 outputASM[ (asmComponent*NB_BINS_PER_SM) + i] = re;
599 outputASM[ (asmComponent*NB_BINS_PER_SM) + i] = re;
599 }
600 }
600 }
601 }
601
602
602 void ASM_patch( float *inputASM, float *outputASM )
603 void ASM_patch( float *inputASM, float *outputASM )
603 {
604 {
604 extractReImVectors( inputASM, outputASM, 1); // b1b2
605 extractReImVectors( inputASM, outputASM, ASM_COMP_B1B2); // b1b2
605 extractReImVectors( inputASM, outputASM, 3 ); // b1b3
606 extractReImVectors( inputASM, outputASM, ASM_COMP_B1B3 ); // b1b3
606 extractReImVectors( inputASM, outputASM, 5 ); // b1e1
607 extractReImVectors( inputASM, outputASM, ASM_COMP_B1E1 ); // b1e1
607 extractReImVectors( inputASM, outputASM, 7 ); // b1e2
608 extractReImVectors( inputASM, outputASM, ASM_COMP_B1E2 ); // b1e2
608 extractReImVectors( inputASM, outputASM, 10 ); // b2b3
609 extractReImVectors( inputASM, outputASM, ASM_COMP_B2B3 ); // b2b3
609 extractReImVectors( inputASM, outputASM, 12 ); // b2e1
610 extractReImVectors( inputASM, outputASM, ASM_COMP_B2E1 ); // b2e1
610 extractReImVectors( inputASM, outputASM, 14 ); // b2e2
611 extractReImVectors( inputASM, outputASM, ASM_COMP_B2E2 ); // b2e2
611 extractReImVectors( inputASM, outputASM, 17 ); // b3e1
612 extractReImVectors( inputASM, outputASM, ASM_COMP_B3E1 ); // b3e1
612 extractReImVectors( inputASM, outputASM, 19 ); // b3e2
613 extractReImVectors( inputASM, outputASM, ASM_COMP_B3E2 ); // b3e2
613 extractReImVectors( inputASM, outputASM, 22 ); // e1e2
614 extractReImVectors( inputASM, outputASM, ASM_COMP_E1E2 ); // e1e2
614
615
615 copyReVectors(inputASM, outputASM, 0 ); // b1b1
616 copyReVectors(inputASM, outputASM, ASM_COMP_B1B1 ); // b1b1
616 copyReVectors(inputASM, outputASM, 9 ); // b2b2
617 copyReVectors(inputASM, outputASM, ASM_COMP_B2B2 ); // b2b2
617 copyReVectors(inputASM, outputASM, 16); // b3b3
618 copyReVectors(inputASM, outputASM, ASM_COMP_B3B3); // b3b3
618 copyReVectors(inputASM, outputASM, 21); // e1e1
619 copyReVectors(inputASM, outputASM, ASM_COMP_E1E1); // e1e1
619 copyReVectors(inputASM, outputASM, 24); // e2e2
620 copyReVectors(inputASM, outputASM, ASM_COMP_E2E2); // e2e2
620 }
621 }
621
622
622 void ASM_compress_reorganize_and_divide_mask(float *averaged_spec_mat, float *compressed_spec_mat , float divider,
623 void ASM_compress_reorganize_and_divide_mask(float *averaged_spec_mat, float *compressed_spec_mat , float divider,
623 unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage,
624 unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage,
624 unsigned char ASMIndexStart,
625 unsigned char ASMIndexStart,
625 unsigned char channel )
626 unsigned char channel )
626 {
627 {
627 //*************
628 //*************
628 // input format
629 // input format
629 // component0[0 .. 127] component1[0 .. 127] .. component24[0 .. 127]
630 // component0[0 .. 127] component1[0 .. 127] .. component24[0 .. 127]
630 //**************
631 //**************
631 // output format
632 // output format
632 // matr0[0 .. 24] matr1[0 .. 24] .. matr127[0 .. 24]
633 // matr0[0 .. 24] matr1[0 .. 24] .. matr127[0 .. 24]
633 //************
634 //************
634 // compression
635 // compression
635 // matr0[0 .. 24] matr1[0 .. 24] .. matr11[0 .. 24] => f0 NORM
636 // matr0[0 .. 24] matr1[0 .. 24] .. matr11[0 .. 24] => f0 NORM
636 // matr0[0 .. 24] matr1[0 .. 24] .. matr22[0 .. 24] => f0 BURST, SBM
637 // matr0[0 .. 24] matr1[0 .. 24] .. matr22[0 .. 24] => f0 BURST, SBM
637
638
638 int frequencyBin;
639 int frequencyBin;
639 int asmComponent;
640 int asmComponent;
640 int offsetASM;
641 int offsetASM;
641 int offsetCompressed;
642 int offsetCompressed;
642 int offsetFBin;
643 int offsetFBin;
643 int fBinMask;
644 int fBinMask;
644 int k;
645 int k;
645
646
646 // BUILD DATA
647 // BUILD DATA
647 for (asmComponent = 0; asmComponent < NB_VALUES_PER_SM; asmComponent++)
648 for (asmComponent = 0; asmComponent < NB_VALUES_PER_SM; asmComponent++)
648 {
649 {
649 for( frequencyBin = 0; frequencyBin < nbBinsCompressedMatrix; frequencyBin++ )
650 for( frequencyBin = 0; frequencyBin < nbBinsCompressedMatrix; frequencyBin++ )
650 {
651 {
651 offsetCompressed = // NO TIME OFFSET
652 offsetCompressed = // NO TIME OFFSET
652 frequencyBin * NB_VALUES_PER_SM
653 (frequencyBin * NB_VALUES_PER_SM)
653 + asmComponent;
654 + asmComponent;
654 offsetASM = // NO TIME OFFSET
655 offsetASM = // NO TIME OFFSET
655 asmComponent * NB_BINS_PER_SM
656 (asmComponent * NB_BINS_PER_SM)
656 + ASMIndexStart
657 + ASMIndexStart
657 + frequencyBin * nbBinsToAverage;
658 + (frequencyBin * nbBinsToAverage);
658 offsetFBin = ASMIndexStart
659 offsetFBin = ASMIndexStart
659 + frequencyBin * nbBinsToAverage;
660 + (frequencyBin * nbBinsToAverage);
660 compressed_spec_mat[ offsetCompressed ] = 0;
661 compressed_spec_mat[ offsetCompressed ] = 0;
661 for ( k = 0; k < nbBinsToAverage; k++ )
662 for ( k = 0; k < nbBinsToAverage; k++ )
662 {
663 {
663 fBinMask = getFBinMask( offsetFBin + k, channel );
664 fBinMask = getFBinMask( offsetFBin + k, channel );
664 compressed_spec_mat[offsetCompressed ] =
665 compressed_spec_mat[offsetCompressed ] = compressed_spec_mat[ offsetCompressed ]
665 ( compressed_spec_mat[ offsetCompressed ]
666 + (averaged_spec_mat[ offsetASM + k ] * fBinMask);
666 + averaged_spec_mat[ offsetASM + k ] * fBinMask );
667 }
667 }
668 if (divider != 0)
668 if (divider != 0)
669 {
669 {
670 compressed_spec_mat[ offsetCompressed ] = compressed_spec_mat[ offsetCompressed ] / (divider * nbBinsToAverage);
670 compressed_spec_mat[ offsetCompressed ] = compressed_spec_mat[ offsetCompressed ] / (divider * nbBinsToAverage);
671 }
671 }
672 else
672 else
673 {
673 {
674 compressed_spec_mat[ offsetCompressed ] = 0.0;
674 compressed_spec_mat[ offsetCompressed ] = INIT_FLOAT;
675 }
675 }
676 }
676 }
677 }
677 }
678
678
679 }
679 }
680
680
681 int getFBinMask( int index, unsigned char channel )
681 int getFBinMask( int index, unsigned char channel )
682 {
682 {
683 unsigned int indexInChar;
683 unsigned int indexInChar;
684 unsigned int indexInTheChar;
684 unsigned int indexInTheChar;
685 int fbin;
685 int fbin;
686 unsigned char *sy_lfr_fbins_fx_word1;
686 unsigned char *sy_lfr_fbins_fx_word1;
687
687
688 sy_lfr_fbins_fx_word1 = parameter_dump_packet.sy_lfr_fbins.fx.f0_word1;
688 sy_lfr_fbins_fx_word1 = parameter_dump_packet.sy_lfr_fbins.fx.f0_word1;
689
689
690 switch(channel)
690 switch(channel)
691 {
691 {
692 case 0:
692 case CHANNELF0:
693 sy_lfr_fbins_fx_word1 = fbins_masks.merged_fbins_mask_f0;
693 sy_lfr_fbins_fx_word1 = fbins_masks.merged_fbins_mask_f0;
694 break;
694 break;
695 case 1:
695 case CHANNELF1:
696 sy_lfr_fbins_fx_word1 = fbins_masks.merged_fbins_mask_f1;
696 sy_lfr_fbins_fx_word1 = fbins_masks.merged_fbins_mask_f1;
697 break;
697 break;
698 case 2:
698 case CHANNELF2:
699 sy_lfr_fbins_fx_word1 = fbins_masks.merged_fbins_mask_f2;
699 sy_lfr_fbins_fx_word1 = fbins_masks.merged_fbins_mask_f2;
700 break;
700 break;
701 default:
701 default:
702 PRINTF("ERR *** in getFBinMask, wrong frequency channel")
702 PRINTF("ERR *** in getFBinMask, wrong frequency channel")
703 }
703 }
704
704
705 indexInChar = index >> 3;
705 indexInChar = index >> SHIFT_3_BITS;
706 indexInTheChar = index - indexInChar * 8;
706 indexInTheChar = index - (indexInChar * BITS_PER_BYTE);
707
707
708 fbin = (int) ((sy_lfr_fbins_fx_word1[ NB_BYTES_PER_FREQ_MASK - 1 - indexInChar] >> indexInTheChar) & 0x1);
708 fbin = (int) ((sy_lfr_fbins_fx_word1[ BYTES_PER_MASK - 1 - indexInChar] >> indexInTheChar) & 1);
709
709
710 return fbin;
710 return fbin;
711 }
711 }
712
712
713 unsigned char acquisitionTimeIsValid( unsigned int coarseTime, unsigned int fineTime, unsigned char channel)
713 unsigned char acquisitionTimeIsValid( unsigned int coarseTime, unsigned int fineTime, unsigned char channel)
714 {
714 {
715 u_int64_t acquisitionTime;
715 u_int64_t acquisitionTime;
716 u_int64_t timecodeReference;
716 u_int64_t timecodeReference;
717 u_int64_t offsetInFineTime;
717 u_int64_t offsetInFineTime;
718 u_int64_t shiftInFineTime;
718 u_int64_t shiftInFineTime;
719 u_int64_t tBadInFineTime;
719 u_int64_t tBadInFineTime;
720 u_int64_t acquisitionTimeRangeMin;
720 u_int64_t acquisitionTimeRangeMin;
721 u_int64_t acquisitionTimeRangeMax;
721 u_int64_t acquisitionTimeRangeMax;
722 unsigned char pasFilteringIsEnabled;
722 unsigned char pasFilteringIsEnabled;
723 unsigned char ret;
723 unsigned char ret;
724
724
725 pasFilteringIsEnabled = (filterPar.spare_sy_lfr_pas_filter_enabled & 0x01); // [0000 0001]
725 pasFilteringIsEnabled = (filterPar.spare_sy_lfr_pas_filter_enabled & 1); // [0000 0001]
726 ret = 1;
726 ret = 1;
727
727
728 // compute acquisition time from caoarseTime and fineTime
728 // compute acquisition time from caoarseTime and fineTime
729 acquisitionTime = ( ((u_int64_t)coarseTime) << 16 )
729 acquisitionTime = ( ((u_int64_t)coarseTime) << SHIFT_2_BYTES )
730 + (u_int64_t) fineTime;
730 + (u_int64_t) fineTime;
731
731
732 // compute the timecode reference
732 // compute the timecode reference
733 timecodeReference = (u_int64_t) (floor( ((double) coarseTime) / ((double) filterPar.sy_lfr_pas_filter_modulus) )
733 timecodeReference = (u_int64_t) ( (floor( ((double) coarseTime) / ((double) filterPar.sy_lfr_pas_filter_modulus) )
734 * ((double) filterPar.sy_lfr_pas_filter_modulus)) * 65536;
734 * ((double) filterPar.sy_lfr_pas_filter_modulus)) * CONST_65536 );
735
735
736 // compute the acquitionTime range
736 // compute the acquitionTime range
737 offsetInFineTime = ((double) filterPar.sy_lfr_pas_filter_offset) * 65536;
737 offsetInFineTime = ((double) filterPar.sy_lfr_pas_filter_offset) * CONST_65536;
738 shiftInFineTime = ((double) filterPar.sy_lfr_pas_filter_shift) * 65536;
738 shiftInFineTime = ((double) filterPar.sy_lfr_pas_filter_shift) * CONST_65536;
739 tBadInFineTime = ((double) filterPar.sy_lfr_pas_filter_tbad) * 65536;
739 tBadInFineTime = ((double) filterPar.sy_lfr_pas_filter_tbad) * CONST_65536;
740
740
741 acquisitionTimeRangeMin =
741 acquisitionTimeRangeMin =
742 timecodeReference
742 timecodeReference
743 + offsetInFineTime
743 + offsetInFineTime
744 + shiftInFineTime
744 + shiftInFineTime
745 - acquisitionDurations[channel];
745 - acquisitionDurations[channel];
746 acquisitionTimeRangeMax =
746 acquisitionTimeRangeMax =
747 timecodeReference
747 timecodeReference
748 + offsetInFineTime
748 + offsetInFineTime
749 + shiftInFineTime
749 + shiftInFineTime
750 + tBadInFineTime;
750 + tBadInFineTime;
751
751
752 if ( (acquisitionTime >= acquisitionTimeRangeMin)
752 if ( (acquisitionTime >= acquisitionTimeRangeMin)
753 && (acquisitionTime <= acquisitionTimeRangeMax)
753 && (acquisitionTime <= acquisitionTimeRangeMax)
754 && (pasFilteringIsEnabled == 1) )
754 && (pasFilteringIsEnabled == 1) )
755 {
755 {
756 ret = 0; // the acquisition time is INSIDE the range, the matrix shall be ignored
756 ret = 0; // the acquisition time is INSIDE the range, the matrix shall be ignored
757 }
757 }
758 else
758 else
759 {
759 {
760 ret = 1; // the acquisition time is OUTSIDE the range, the matrix can be used for the averaging
760 ret = 1; // the acquisition time is OUTSIDE the range, the matrix can be used for the averaging
761 }
761 }
762
762
763 // printf("coarseTime = %x, fineTime = %x\n",
763 // printf("coarseTime = %x, fineTime = %x\n",
764 // coarseTime,
764 // coarseTime,
765 // fineTime);
765 // fineTime);
766
766
767 // printf("[ret = %d] *** acquisitionTime = %f, Reference = %f",
767 // printf("[ret = %d] *** acquisitionTime = %f, Reference = %f",
768 // ret,
768 // ret,
769 // acquisitionTime / 65536.,
769 // acquisitionTime / 65536.,
770 // timecodeReference / 65536.);
770 // timecodeReference / 65536.);
771
771
772 // printf(", Min = %f, Max = %f\n",
772 // printf(", Min = %f, Max = %f\n",
773 // acquisitionTimeRangeMin / 65536.,
773 // acquisitionTimeRangeMin / 65536.,
774 // acquisitionTimeRangeMax / 65536.);
774 // acquisitionTimeRangeMax / 65536.);
775
775
776 return ret;
776 return ret;
777 }
777 }
778
778
779 void init_kcoeff_sbm_from_kcoeff_norm(float *input_kcoeff, float *output_kcoeff, unsigned char nb_bins_norm)
779 void init_kcoeff_sbm_from_kcoeff_norm(float *input_kcoeff, float *output_kcoeff, unsigned char nb_bins_norm)
780 {
780 {
781 unsigned char bin;
781 unsigned char bin;
782 unsigned char kcoeff;
782 unsigned char kcoeff;
783
783
784 for (bin=0; bin<nb_bins_norm; bin++)
784 for (bin=0; bin<nb_bins_norm; bin++)
785 {
785 {
786 for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++)
786 for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++)
787 {
787 {
788 output_kcoeff[ (bin*NB_K_COEFF_PER_BIN + kcoeff)*2 ] = input_kcoeff[ bin*NB_K_COEFF_PER_BIN + kcoeff ];
788 output_kcoeff[ ( ( bin * NB_K_COEFF_PER_BIN ) + kcoeff ) * SBM_COEFF_PER_NORM_COEFF ]
789 output_kcoeff[ (bin*NB_K_COEFF_PER_BIN + kcoeff)*2 + 1 ] = input_kcoeff[ bin*NB_K_COEFF_PER_BIN + kcoeff ];
789 = input_kcoeff[ (bin*NB_K_COEFF_PER_BIN) + kcoeff ];
790 output_kcoeff[ ( ( bin * NB_K_COEFF_PER_BIN ) + kcoeff ) * SBM_COEFF_PER_NORM_COEFF + 1 ]
791 = input_kcoeff[ (bin*NB_K_COEFF_PER_BIN) + kcoeff ];
790 }
792 }
791 }
793 }
792 }
794 }
@@ -1,474 +1,475
1 /** Functions related to TeleCommand acceptance.
1 /** Functions related to TeleCommand acceptance.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 * A group of functions to handle TeleCommands parsing.\n
6 * A group of functions to handle TeleCommands parsing.\n
7 *
7 *
8 */
8 */
9
9
10 #include "tc_acceptance.h"
10 #include "tc_acceptance.h"
11 #include <stdio.h>
11 #include <stdio.h>
12
12
13 unsigned int lookUpTableForCRC[256];
13 unsigned int lookUpTableForCRC[CONST_256];
14
14
15 //**********************
15 //**********************
16 // GENERAL USE FUNCTIONS
16 // GENERAL USE FUNCTIONS
17 unsigned int Crc_opt( unsigned char D, unsigned int Chk)
17 unsigned int Crc_opt( unsigned char D, unsigned int Chk)
18 {
18 {
19 /** This function generate the CRC for one byte and returns the value of the new syndrome.
19 /** This function generate the CRC for one byte and returns the value of the new syndrome.
20 *
20 *
21 * @param D is the current byte of data.
21 * @param D is the current byte of data.
22 * @param Chk is the current syndrom value.
22 * @param Chk is the current syndrom value.
23 *
23 *
24 * @return the value of the new syndrome on two bytes.
24 * @return the value of the new syndrome on two bytes.
25 *
25 *
26 */
26 */
27
27
28 return(((Chk << 8) & 0xff00)^lookUpTableForCRC [(((Chk >> 8)^D) & 0x00ff)]);
28 return(((Chk << SHIFT_1_BYTE) & BYTE0_MASK)^lookUpTableForCRC [(((Chk >> SHIFT_1_BYTE)^D) & BYTE1_MASK)]);
29 }
29 }
30
30
31 void initLookUpTableForCRC( void )
31 void initLookUpTableForCRC( void )
32 {
32 {
33 /** This function is used to initiates the look-up table for fast CRC computation.
33 /** This function is used to initiates the look-up table for fast CRC computation.
34 *
34 *
35 * The global table lookUpTableForCRC[256] is initiated.
35 * The global table lookUpTableForCRC[256] is initiated.
36 *
36 *
37 */
37 */
38
38
39 unsigned int i;
39 unsigned int i;
40 unsigned int tmp;
40 unsigned int tmp;
41
41
42 for (i=0; i<256; i++)
42 for (i=0; i<CONST_256; i++)
43 {
43 {
44 tmp = 0;
44 tmp = 0;
45 if((i & 1) != 0) {
45 if((i & BIT_0) != 0) {
46 tmp = tmp ^ 0x1021;
46 tmp = tmp ^ CONST_CRC_0;
47 }
47 }
48 if((i & 2) != 0) {
48 if((i & BIT_1) != 0) {
49 tmp = tmp ^ 0x2042;
49 tmp = tmp ^ CONST_CRC_1;
50 }
50 }
51 if((i & 4) != 0) {
51 if((i & BIT_2) != 0) {
52 tmp = tmp ^ 0x4084;
52 tmp = tmp ^ CONST_CRC_2;
53 }
53 }
54 if((i & 8) != 0) {
54 if((i & BIT_3) != 0) {
55 tmp = tmp ^ 0x8108;
55 tmp = tmp ^ CONST_CRC_3;
56 }
56 }
57 if((i & 16) != 0) {
57 if((i & BIT_4) != 0) {
58 tmp = tmp ^ 0x1231;
58 tmp = tmp ^ CONST_CRC_4;
59 }
59 }
60 if((i & 32) != 0) {
60 if((i & BIT_5) != 0) {
61 tmp = tmp ^ 0x2462;
61 tmp = tmp ^ CONST_CRC_5;
62 }
62 }
63 if((i & 64) != 0) {
63 if((i & BIT_6) != 0) {
64 tmp = tmp ^ 0x48c4;
64 tmp = tmp ^ CONST_CRC_6;
65 }
65 }
66 if((i & 128) != 0) {
66 if((i & BIT_7) != 0) {
67 tmp = tmp ^ 0x9188;
67 tmp = tmp ^ CONST_CRC_7;
68 }
68 }
69 lookUpTableForCRC[i] = tmp;
69 lookUpTableForCRC[i] = tmp;
70 }
70 }
71 }
71 }
72
72
73 void GetCRCAsTwoBytes(unsigned char* data, unsigned char* crcAsTwoBytes, unsigned int sizeOfData)
73 void GetCRCAsTwoBytes(unsigned char* data, unsigned char* crcAsTwoBytes, unsigned int sizeOfData)
74 {
74 {
75 /** This function calculates a two bytes Cyclic Redundancy Code.
75 /** This function calculates a two bytes Cyclic Redundancy Code.
76 *
76 *
77 * @param data points to a buffer containing the data on which to compute the CRC.
77 * @param data points to a buffer containing the data on which to compute the CRC.
78 * @param crcAsTwoBytes points points to a two bytes buffer in which the CRC is stored.
78 * @param crcAsTwoBytes points points to a two bytes buffer in which the CRC is stored.
79 * @param sizeOfData is the number of bytes of *data* used to compute the CRC.
79 * @param sizeOfData is the number of bytes of *data* used to compute the CRC.
80 *
80 *
81 * The specification of the Cyclic Redundancy Code is described in the following document: ECSS-E-70-41-A.
81 * The specification of the Cyclic Redundancy Code is described in the following document: ECSS-E-70-41-A.
82 *
82 *
83 */
83 */
84
84
85 unsigned int Chk;
85 unsigned int Chk;
86 int j;
86 int j;
87 Chk = 0xffff; // reset the syndrom to all ones
87 Chk = CRC_RESET; // reset the syndrom to all ones
88 for (j=0; j<sizeOfData; j++) {
88 for (j=0; j<sizeOfData; j++) {
89 Chk = Crc_opt(data[j], Chk);
89 Chk = Crc_opt(data[j], Chk);
90 }
90 }
91 crcAsTwoBytes[0] = (unsigned char) (Chk >> 8);
91 crcAsTwoBytes[0] = (unsigned char) (Chk >> SHIFT_1_BYTE);
92 crcAsTwoBytes[1] = (unsigned char) (Chk & 0x00ff);
92 crcAsTwoBytes[1] = (unsigned char) (Chk & BYTE1_MASK);
93 }
93 }
94
94
95 //*********************
95 //*********************
96 // ACCEPTANCE FUNCTIONS
96 // ACCEPTANCE FUNCTIONS
97 int tc_parser(ccsdsTelecommandPacket_t * TCPacket, unsigned int estimatedPacketLength, unsigned char *computed_CRC)
97 int tc_parser(ccsdsTelecommandPacket_t * TCPacket, unsigned int estimatedPacketLength, unsigned char *computed_CRC)
98 {
98 {
99 /** This function parses TeleCommands.
99 /** This function parses TeleCommands.
100 *
100 *
101 * @param TC points to the TeleCommand that will be parsed.
101 * @param TC points to the TeleCommand that will be parsed.
102 * @param estimatedPacketLength is the PACKET_LENGTH field calculated from the effective length of the received packet.
102 * @param estimatedPacketLength is the PACKET_LENGTH field calculated from the effective length of the received packet.
103 *
103 *
104 * @return Status code of the parsing.
104 * @return Status code of the parsing.
105 *
105 *
106 * The parsing checks:
106 * The parsing checks:
107 * - process id
107 * - process id
108 * - category
108 * - category
109 * - length: a global check is performed and a per subtype check also
109 * - length: a global check is performed and a per subtype check also
110 * - type
110 * - type
111 * - subtype
111 * - subtype
112 * - crc
112 * - crc
113 *
113 *
114 */
114 */
115
115
116 int status;
116 int status;
117 int status_crc;
117 int status_crc;
118 unsigned char pid;
118 unsigned char pid;
119 unsigned char category;
119 unsigned char category;
120 unsigned int packetLength;
120 unsigned int packetLength;
121 unsigned char packetType;
121 unsigned char packetType;
122 unsigned char packetSubtype;
122 unsigned char packetSubtype;
123 unsigned char sid;
123 unsigned char sid;
124
124
125 status = CCSDS_TM_VALID;
125 status = CCSDS_TM_VALID;
126
126
127 // APID check *** APID on 2 bytes
127 // APID check *** APID on 2 bytes
128 pid = ((TCPacket->packetID[0] & 0x07)<<4) + ( (TCPacket->packetID[1]>>4) & 0x0f ); // PID = 11 *** 7 bits xxxxx210 7654xxxx
128 pid = ((TCPacket->packetID[0] & BITS_PID_0) << SHIFT_4_BITS)
129 category = (TCPacket->packetID[1] & 0x0f); // PACKET_CATEGORY = 12 *** 4 bits xxxxxxxx xxxx3210
129 + ( (TCPacket->packetID[1] >> SHIFT_4_BITS) & BITS_PID_1 ); // PID = 11 *** 7 bits xxxxx210 7654xxxx
130 packetLength = (TCPacket->packetLength[0] * 256) + TCPacket->packetLength[1];
130 category = (TCPacket->packetID[1] & BITS_CAT); // PACKET_CATEGORY = 12 *** 4 bits xxxxxxxx xxxx3210
131 packetLength = (TCPacket->packetLength[0] * CONST_256) + TCPacket->packetLength[1];
131 packetType = TCPacket->serviceType;
132 packetType = TCPacket->serviceType;
132 packetSubtype = TCPacket->serviceSubType;
133 packetSubtype = TCPacket->serviceSubType;
133 sid = TCPacket->sourceID;
134 sid = TCPacket->sourceID;
134
135
135 if ( pid != CCSDS_PROCESS_ID ) // CHECK THE PROCESS ID
136 if ( pid != CCSDS_PROCESS_ID ) // CHECK THE PROCESS ID
136 {
137 {
137 status = ILLEGAL_APID;
138 status = ILLEGAL_APID;
138 }
139 }
139 if (status == CCSDS_TM_VALID) // CHECK THE CATEGORY
140 if (status == CCSDS_TM_VALID) // CHECK THE CATEGORY
140 {
141 {
141 if ( category != CCSDS_PACKET_CATEGORY )
142 if ( category != CCSDS_PACKET_CATEGORY )
142 {
143 {
143 status = ILLEGAL_APID;
144 status = ILLEGAL_APID;
144 }
145 }
145 }
146 }
146 if (status == CCSDS_TM_VALID) // CHECK THE PACKET_LENGTH FIELD AND THE ESTIMATED PACKET_LENGTH COMPLIANCE
147 if (status == CCSDS_TM_VALID) // CHECK THE PACKET_LENGTH FIELD AND THE ESTIMATED PACKET_LENGTH COMPLIANCE
147 {
148 {
148 if (packetLength != estimatedPacketLength ) {
149 if (packetLength != estimatedPacketLength ) {
149 status = WRONG_LEN_PKT;
150 status = WRONG_LEN_PKT;
150 }
151 }
151 }
152 }
152 if (status == CCSDS_TM_VALID) // CHECK THAT THE PACKET DOES NOT EXCEED THE MAX SIZE
153 if (status == CCSDS_TM_VALID) // CHECK THAT THE PACKET DOES NOT EXCEED THE MAX SIZE
153 {
154 {
154 if ( packetLength > CCSDS_TC_PKT_MAX_SIZE ) {
155 if ( packetLength > CCSDS_TC_PKT_MAX_SIZE ) {
155 status = WRONG_LEN_PKT;
156 status = WRONG_LEN_PKT;
156 }
157 }
157 }
158 }
158 if (status == CCSDS_TM_VALID) // CHECK THE TYPE
159 if (status == CCSDS_TM_VALID) // CHECK THE TYPE
159 {
160 {
160 status = tc_check_type( packetType );
161 status = tc_check_type( packetType );
161 }
162 }
162 if (status == CCSDS_TM_VALID) // CHECK THE SUBTYPE
163 if (status == CCSDS_TM_VALID) // CHECK THE SUBTYPE
163 {
164 {
164 status = tc_check_type_subtype( packetType, packetSubtype );
165 status = tc_check_type_subtype( packetType, packetSubtype );
165 }
166 }
166 if (status == CCSDS_TM_VALID) // CHECK THE SID
167 if (status == CCSDS_TM_VALID) // CHECK THE SID
167 {
168 {
168 status = tc_check_sid( sid );
169 status = tc_check_sid( sid );
169 }
170 }
170 if (status == CCSDS_TM_VALID) // CHECK THE SUBTYPE AND LENGTH COMPLIANCE
171 if (status == CCSDS_TM_VALID) // CHECK THE SUBTYPE AND LENGTH COMPLIANCE
171 {
172 {
172 status = tc_check_length( packetSubtype, packetLength );
173 status = tc_check_length( packetSubtype, packetLength );
173 }
174 }
174 status_crc = tc_check_crc( TCPacket, estimatedPacketLength, computed_CRC );
175 status_crc = tc_check_crc( TCPacket, estimatedPacketLength, computed_CRC );
175 if (status == CCSDS_TM_VALID ) // CHECK CRC
176 if (status == CCSDS_TM_VALID ) // CHECK CRC
176 {
177 {
177 status = status_crc;
178 status = status_crc;
178 }
179 }
179
180
180 return status;
181 return status;
181 }
182 }
182
183
183 int tc_check_type( unsigned char packetType )
184 int tc_check_type( unsigned char packetType )
184 {
185 {
185 /** This function checks that the type of a TeleCommand is valid.
186 /** This function checks that the type of a TeleCommand is valid.
186 *
187 *
187 * @param packetType is the type to check.
188 * @param packetType is the type to check.
188 *
189 *
189 * @return Status code CCSDS_TM_VALID or ILL_TYPE.
190 * @return Status code CCSDS_TM_VALID or ILL_TYPE.
190 *
191 *
191 */
192 */
192
193
193 int status;
194 int status;
194
195
195 if ( (packetType == TC_TYPE_GEN) || (packetType == TC_TYPE_TIME))
196 if ( (packetType == TC_TYPE_GEN) || (packetType == TC_TYPE_TIME))
196 {
197 {
197 status = CCSDS_TM_VALID;
198 status = CCSDS_TM_VALID;
198 }
199 }
199 else
200 else
200 {
201 {
201 status = ILL_TYPE;
202 status = ILL_TYPE;
202 }
203 }
203
204
204 return status;
205 return status;
205 }
206 }
206
207
207 int tc_check_type_subtype( unsigned char packetType, unsigned char packetSubType )
208 int tc_check_type_subtype( unsigned char packetType, unsigned char packetSubType )
208 {
209 {
209 /** This function checks that the subtype of a TeleCommand is valid and coherent with the type.
210 /** This function checks that the subtype of a TeleCommand is valid and coherent with the type.
210 *
211 *
211 * @param packetType is the type of the TC.
212 * @param packetType is the type of the TC.
212 * @param packetSubType is the subtype to check.
213 * @param packetSubType is the subtype to check.
213 *
214 *
214 * @return Status code CCSDS_TM_VALID or ILL_SUBTYPE.
215 * @return Status code CCSDS_TM_VALID or ILL_SUBTYPE.
215 *
216 *
216 */
217 */
217
218
218 int status;
219 int status;
219
220
220 switch(packetType)
221 switch(packetType)
221 {
222 {
222 case TC_TYPE_GEN:
223 case TC_TYPE_GEN:
223 if ( (packetSubType == TC_SUBTYPE_RESET)
224 if ( (packetSubType == TC_SUBTYPE_RESET)
224 || (packetSubType == TC_SUBTYPE_LOAD_COMM)
225 || (packetSubType == TC_SUBTYPE_LOAD_COMM)
225 || (packetSubType == TC_SUBTYPE_LOAD_NORM) || (packetSubType == TC_SUBTYPE_LOAD_BURST)
226 || (packetSubType == TC_SUBTYPE_LOAD_NORM) || (packetSubType == TC_SUBTYPE_LOAD_BURST)
226 || (packetSubType == TC_SUBTYPE_LOAD_SBM1) || (packetSubType == TC_SUBTYPE_LOAD_SBM2)
227 || (packetSubType == TC_SUBTYPE_LOAD_SBM1) || (packetSubType == TC_SUBTYPE_LOAD_SBM2)
227 || (packetSubType == TC_SUBTYPE_DUMP)
228 || (packetSubType == TC_SUBTYPE_DUMP)
228 || (packetSubType == TC_SUBTYPE_ENTER)
229 || (packetSubType == TC_SUBTYPE_ENTER)
229 || (packetSubType == TC_SUBTYPE_UPDT_INFO)
230 || (packetSubType == TC_SUBTYPE_UPDT_INFO)
230 || (packetSubType == TC_SUBTYPE_EN_CAL) || (packetSubType == TC_SUBTYPE_DIS_CAL)
231 || (packetSubType == TC_SUBTYPE_EN_CAL) || (packetSubType == TC_SUBTYPE_DIS_CAL)
231 || (packetSubType == TC_SUBTYPE_LOAD_K) || (packetSubType == TC_SUBTYPE_DUMP_K)
232 || (packetSubType == TC_SUBTYPE_LOAD_K) || (packetSubType == TC_SUBTYPE_DUMP_K)
232 || (packetSubType == TC_SUBTYPE_LOAD_FBINS)
233 || (packetSubType == TC_SUBTYPE_LOAD_FBINS)
233 || (packetSubType == TC_SUBTYPE_LOAD_FILTER_PAR))
234 || (packetSubType == TC_SUBTYPE_LOAD_FILTER_PAR))
234 {
235 {
235 status = CCSDS_TM_VALID;
236 status = CCSDS_TM_VALID;
236 }
237 }
237 else
238 else
238 {
239 {
239 status = ILL_SUBTYPE;
240 status = ILL_SUBTYPE;
240 }
241 }
241 break;
242 break;
242
243
243 case TC_TYPE_TIME:
244 case TC_TYPE_TIME:
244 if (packetSubType == TC_SUBTYPE_UPDT_TIME)
245 if (packetSubType == TC_SUBTYPE_UPDT_TIME)
245 {
246 {
246 status = CCSDS_TM_VALID;
247 status = CCSDS_TM_VALID;
247 }
248 }
248 else
249 else
249 {
250 {
250 status = ILL_SUBTYPE;
251 status = ILL_SUBTYPE;
251 }
252 }
252 break;
253 break;
253
254
254 default:
255 default:
255 status = ILL_SUBTYPE;
256 status = ILL_SUBTYPE;
256 break;
257 break;
257 }
258 }
258
259
259 return status;
260 return status;
260 }
261 }
261
262
262 int tc_check_sid( unsigned char sid )
263 int tc_check_sid( unsigned char sid )
263 {
264 {
264 /** This function checks that the sid of a TeleCommand is valid.
265 /** This function checks that the sid of a TeleCommand is valid.
265 *
266 *
266 * @param sid is the sid to check.
267 * @param sid is the sid to check.
267 *
268 *
268 * @return Status code CCSDS_TM_VALID or CORRUPTED.
269 * @return Status code CCSDS_TM_VALID or CORRUPTED.
269 *
270 *
270 */
271 */
271
272
272 int status;
273 int status;
273
274
274 if ( (sid == SID_TC_MISSION_TIMELINE) || (sid == SID_TC_TC_SEQUENCES) || (sid == SID_TC_RECOVERY_ACTION_CMD)
275 if ( (sid == SID_TC_MISSION_TIMELINE) || (sid == SID_TC_TC_SEQUENCES) || (sid == SID_TC_RECOVERY_ACTION_CMD)
275 || (sid == SID_TC_BACKUP_MISSION_TIMELINE)
276 || (sid == SID_TC_BACKUP_MISSION_TIMELINE)
276 || (sid == SID_TC_DIRECT_CMD) || (sid == SID_TC_SPARE_GRD_SRC1) || (sid == SID_TC_SPARE_GRD_SRC2)
277 || (sid == SID_TC_DIRECT_CMD) || (sid == SID_TC_SPARE_GRD_SRC1) || (sid == SID_TC_SPARE_GRD_SRC2)
277 || (sid == SID_TC_OBCP) || (sid == SID_TC_SYSTEM_CONTROL) || (sid == SID_TC_AOCS)
278 || (sid == SID_TC_OBCP) || (sid == SID_TC_SYSTEM_CONTROL) || (sid == SID_TC_AOCS)
278 || (sid == SID_TC_RPW_INTERNAL))
279 || (sid == SID_TC_RPW_INTERNAL))
279 {
280 {
280 status = CCSDS_TM_VALID;
281 status = CCSDS_TM_VALID;
281 }
282 }
282 else
283 else
283 {
284 {
284 status = WRONG_SRC_ID;
285 status = WRONG_SRC_ID;
285 }
286 }
286
287
287 return status;
288 return status;
288 }
289 }
289
290
290 int tc_check_length( unsigned char packetSubType, unsigned int length )
291 int tc_check_length( unsigned char packetSubType, unsigned int length )
291 {
292 {
292 /** This function checks that the subtype and the length are compliant.
293 /** This function checks that the subtype and the length are compliant.
293 *
294 *
294 * @param packetSubType is the subtype to check.
295 * @param packetSubType is the subtype to check.
295 * @param length is the length to check.
296 * @param length is the length to check.
296 *
297 *
297 * @return Status code CCSDS_TM_VALID or ILL_TYPE.
298 * @return Status code CCSDS_TM_VALID or ILL_TYPE.
298 *
299 *
299 */
300 */
300
301
301 int status;
302 int status;
302
303
303 status = LFR_SUCCESSFUL;
304 status = LFR_SUCCESSFUL;
304
305
305 switch(packetSubType)
306 switch(packetSubType)
306 {
307 {
307 case TC_SUBTYPE_RESET:
308 case TC_SUBTYPE_RESET:
308 if (length!=(TC_LEN_RESET-CCSDS_TC_TM_PACKET_OFFSET)) {
309 if (length!=(TC_LEN_RESET-CCSDS_TC_TM_PACKET_OFFSET)) {
309 status = WRONG_LEN_PKT;
310 status = WRONG_LEN_PKT;
310 }
311 }
311 else {
312 else {
312 status = CCSDS_TM_VALID;
313 status = CCSDS_TM_VALID;
313 }
314 }
314 break;
315 break;
315 case TC_SUBTYPE_LOAD_COMM:
316 case TC_SUBTYPE_LOAD_COMM:
316 if (length!=(TC_LEN_LOAD_COMM-CCSDS_TC_TM_PACKET_OFFSET)) {
317 if (length!=(TC_LEN_LOAD_COMM-CCSDS_TC_TM_PACKET_OFFSET)) {
317 status = WRONG_LEN_PKT;
318 status = WRONG_LEN_PKT;
318 }
319 }
319 else {
320 else {
320 status = CCSDS_TM_VALID;
321 status = CCSDS_TM_VALID;
321 }
322 }
322 break;
323 break;
323 case TC_SUBTYPE_LOAD_NORM:
324 case TC_SUBTYPE_LOAD_NORM:
324 if (length!=(TC_LEN_LOAD_NORM-CCSDS_TC_TM_PACKET_OFFSET)) {
325 if (length!=(TC_LEN_LOAD_NORM-CCSDS_TC_TM_PACKET_OFFSET)) {
325 status = WRONG_LEN_PKT;
326 status = WRONG_LEN_PKT;
326 }
327 }
327 else {
328 else {
328 status = CCSDS_TM_VALID;
329 status = CCSDS_TM_VALID;
329 }
330 }
330 break;
331 break;
331 case TC_SUBTYPE_LOAD_BURST:
332 case TC_SUBTYPE_LOAD_BURST:
332 if (length!=(TC_LEN_LOAD_BURST-CCSDS_TC_TM_PACKET_OFFSET)) {
333 if (length!=(TC_LEN_LOAD_BURST-CCSDS_TC_TM_PACKET_OFFSET)) {
333 status = WRONG_LEN_PKT;
334 status = WRONG_LEN_PKT;
334 }
335 }
335 else {
336 else {
336 status = CCSDS_TM_VALID;
337 status = CCSDS_TM_VALID;
337 }
338 }
338 break;
339 break;
339 case TC_SUBTYPE_LOAD_SBM1:
340 case TC_SUBTYPE_LOAD_SBM1:
340 if (length!=(TC_LEN_LOAD_SBM1-CCSDS_TC_TM_PACKET_OFFSET)) {
341 if (length!=(TC_LEN_LOAD_SBM1-CCSDS_TC_TM_PACKET_OFFSET)) {
341 status = WRONG_LEN_PKT;
342 status = WRONG_LEN_PKT;
342 }
343 }
343 else {
344 else {
344 status = CCSDS_TM_VALID;
345 status = CCSDS_TM_VALID;
345 }
346 }
346 break;
347 break;
347 case TC_SUBTYPE_LOAD_SBM2:
348 case TC_SUBTYPE_LOAD_SBM2:
348 if (length!=(TC_LEN_LOAD_SBM2-CCSDS_TC_TM_PACKET_OFFSET)) {
349 if (length!=(TC_LEN_LOAD_SBM2-CCSDS_TC_TM_PACKET_OFFSET)) {
349 status = WRONG_LEN_PKT;
350 status = WRONG_LEN_PKT;
350 }
351 }
351 else {
352 else {
352 status = CCSDS_TM_VALID;
353 status = CCSDS_TM_VALID;
353 }
354 }
354 break;
355 break;
355 case TC_SUBTYPE_DUMP:
356 case TC_SUBTYPE_DUMP:
356 if (length!=(TC_LEN_DUMP-CCSDS_TC_TM_PACKET_OFFSET)) {
357 if (length!=(TC_LEN_DUMP-CCSDS_TC_TM_PACKET_OFFSET)) {
357 status = WRONG_LEN_PKT;
358 status = WRONG_LEN_PKT;
358 }
359 }
359 else {
360 else {
360 status = CCSDS_TM_VALID;
361 status = CCSDS_TM_VALID;
361 }
362 }
362 break;
363 break;
363 case TC_SUBTYPE_ENTER:
364 case TC_SUBTYPE_ENTER:
364 if (length!=(TC_LEN_ENTER-CCSDS_TC_TM_PACKET_OFFSET)) {
365 if (length!=(TC_LEN_ENTER-CCSDS_TC_TM_PACKET_OFFSET)) {
365 status = WRONG_LEN_PKT;
366 status = WRONG_LEN_PKT;
366 }
367 }
367 else {
368 else {
368 status = CCSDS_TM_VALID;
369 status = CCSDS_TM_VALID;
369 }
370 }
370 break;
371 break;
371 case TC_SUBTYPE_UPDT_INFO:
372 case TC_SUBTYPE_UPDT_INFO:
372 if (length!=(TC_LEN_UPDT_INFO-CCSDS_TC_TM_PACKET_OFFSET)) {
373 if (length!=(TC_LEN_UPDT_INFO-CCSDS_TC_TM_PACKET_OFFSET)) {
373 status = WRONG_LEN_PKT;
374 status = WRONG_LEN_PKT;
374 }
375 }
375 else {
376 else {
376 status = CCSDS_TM_VALID;
377 status = CCSDS_TM_VALID;
377 }
378 }
378 break;
379 break;
379 case TC_SUBTYPE_EN_CAL:
380 case TC_SUBTYPE_EN_CAL:
380 if (length!=(TC_LEN_EN_CAL-CCSDS_TC_TM_PACKET_OFFSET)) {
381 if (length!=(TC_LEN_EN_CAL-CCSDS_TC_TM_PACKET_OFFSET)) {
381 status = WRONG_LEN_PKT;
382 status = WRONG_LEN_PKT;
382 }
383 }
383 else {
384 else {
384 status = CCSDS_TM_VALID;
385 status = CCSDS_TM_VALID;
385 }
386 }
386 break;
387 break;
387 case TC_SUBTYPE_DIS_CAL:
388 case TC_SUBTYPE_DIS_CAL:
388 if (length!=(TC_LEN_DIS_CAL-CCSDS_TC_TM_PACKET_OFFSET)) {
389 if (length!=(TC_LEN_DIS_CAL-CCSDS_TC_TM_PACKET_OFFSET)) {
389 status = WRONG_LEN_PKT;
390 status = WRONG_LEN_PKT;
390 }
391 }
391 else {
392 else {
392 status = CCSDS_TM_VALID;
393 status = CCSDS_TM_VALID;
393 }
394 }
394 break;
395 break;
395 case TC_SUBTYPE_LOAD_K:
396 case TC_SUBTYPE_LOAD_K:
396 if (length!=(TC_LEN_LOAD_K-CCSDS_TC_TM_PACKET_OFFSET)) {
397 if (length!=(TC_LEN_LOAD_K-CCSDS_TC_TM_PACKET_OFFSET)) {
397 status = WRONG_LEN_PKT;
398 status = WRONG_LEN_PKT;
398 }
399 }
399 else {
400 else {
400 status = CCSDS_TM_VALID;
401 status = CCSDS_TM_VALID;
401 }
402 }
402 break;
403 break;
403 case TC_SUBTYPE_DUMP_K:
404 case TC_SUBTYPE_DUMP_K:
404 if (length!=(TC_LEN_DUMP_K-CCSDS_TC_TM_PACKET_OFFSET)) {
405 if (length!=(TC_LEN_DUMP_K-CCSDS_TC_TM_PACKET_OFFSET)) {
405 status = WRONG_LEN_PKT;
406 status = WRONG_LEN_PKT;
406 }
407 }
407 else {
408 else {
408 status = CCSDS_TM_VALID;
409 status = CCSDS_TM_VALID;
409 }
410 }
410 break;
411 break;
411 case TC_SUBTYPE_LOAD_FBINS:
412 case TC_SUBTYPE_LOAD_FBINS:
412 if (length!=(TC_LEN_LOAD_FBINS-CCSDS_TC_TM_PACKET_OFFSET)) {
413 if (length!=(TC_LEN_LOAD_FBINS-CCSDS_TC_TM_PACKET_OFFSET)) {
413 status = WRONG_LEN_PKT;
414 status = WRONG_LEN_PKT;
414 }
415 }
415 else {
416 else {
416 status = CCSDS_TM_VALID;
417 status = CCSDS_TM_VALID;
417 }
418 }
418 break;
419 break;
419 case TC_SUBTYPE_LOAD_FILTER_PAR:
420 case TC_SUBTYPE_LOAD_FILTER_PAR:
420 if (length!=(TC_LEN_LOAD_FILTER_PAR-CCSDS_TC_TM_PACKET_OFFSET)) {
421 if (length!=(TC_LEN_LOAD_FILTER_PAR-CCSDS_TC_TM_PACKET_OFFSET)) {
421 status = WRONG_LEN_PKT;
422 status = WRONG_LEN_PKT;
422 }
423 }
423 else {
424 else {
424 status = CCSDS_TM_VALID;
425 status = CCSDS_TM_VALID;
425 }
426 }
426 break;
427 break;
427 case TC_SUBTYPE_UPDT_TIME:
428 case TC_SUBTYPE_UPDT_TIME:
428 if (length!=(TC_LEN_UPDT_TIME-CCSDS_TC_TM_PACKET_OFFSET)) {
429 if (length!=(TC_LEN_UPDT_TIME-CCSDS_TC_TM_PACKET_OFFSET)) {
429 status = WRONG_LEN_PKT;
430 status = WRONG_LEN_PKT;
430 }
431 }
431 else {
432 else {
432 status = CCSDS_TM_VALID;
433 status = CCSDS_TM_VALID;
433 }
434 }
434 break;
435 break;
435 default: // if the subtype is not a legal value, return ILL_SUBTYPE
436 default: // if the subtype is not a legal value, return ILL_SUBTYPE
436 status = ILL_SUBTYPE;
437 status = ILL_SUBTYPE;
437 break ;
438 break ;
438 }
439 }
439
440
440 return status;
441 return status;
441 }
442 }
442
443
443 int tc_check_crc( ccsdsTelecommandPacket_t * TCPacket, unsigned int length, unsigned char *computed_CRC )
444 int tc_check_crc( ccsdsTelecommandPacket_t * TCPacket, unsigned int length, unsigned char *computed_CRC )
444 {
445 {
445 /** This function checks the CRC validity of the corresponding TeleCommand packet.
446 /** This function checks the CRC validity of the corresponding TeleCommand packet.
446 *
447 *
447 * @param TCPacket points to the TeleCommand packet to check.
448 * @param TCPacket points to the TeleCommand packet to check.
448 * @param length is the length of the TC packet.
449 * @param length is the length of the TC packet.
449 *
450 *
450 * @return Status code CCSDS_TM_VALID or INCOR_CHECKSUM.
451 * @return Status code CCSDS_TM_VALID or INCOR_CHECKSUM.
451 *
452 *
452 */
453 */
453
454
454 int status;
455 int status;
455 unsigned char * CCSDSContent;
456 unsigned char * CCSDSContent;
456
457
457 CCSDSContent = (unsigned char*) TCPacket->packetID;
458 CCSDSContent = (unsigned char*) TCPacket->packetID;
458 GetCRCAsTwoBytes(CCSDSContent, computed_CRC, length + CCSDS_TC_TM_PACKET_OFFSET - 2); // 2 CRC bytes removed from the calculation of the CRC
459 GetCRCAsTwoBytes(CCSDSContent, computed_CRC, length + CCSDS_TC_TM_PACKET_OFFSET - BYTES_PER_CRC); // 2 CRC bytes removed from the calculation of the CRC
459
460
460 if (computed_CRC[0] != CCSDSContent[length + CCSDS_TC_TM_PACKET_OFFSET -2]) {
461 if (computed_CRC[0] != CCSDSContent[length + CCSDS_TC_TM_PACKET_OFFSET - BYTES_PER_CRC]) {
461 status = INCOR_CHECKSUM;
462 status = INCOR_CHECKSUM;
462 }
463 }
463 else if (computed_CRC[1] != CCSDSContent[length + CCSDS_TC_TM_PACKET_OFFSET -1]) {
464 else if (computed_CRC[1] != CCSDSContent[length + CCSDS_TC_TM_PACKET_OFFSET -1]) {
464 status = INCOR_CHECKSUM;
465 status = INCOR_CHECKSUM;
465 }
466 }
466 else {
467 else {
467 status = CCSDS_TM_VALID;
468 status = CCSDS_TM_VALID;
468 }
469 }
469
470
470 return status;
471 return status;
471 }
472 }
472
473
473
474
474
475
@@ -1,1645 +1,1654
1 /** Functions and tasks related to TeleCommand handling.
1 /** Functions and tasks related to TeleCommand handling.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 * A group of functions to handle TeleCommands:\n
6 * A group of functions to handle TeleCommands:\n
7 * action launching\n
7 * action launching\n
8 * TC parsing\n
8 * TC parsing\n
9 * ...
9 * ...
10 *
10 *
11 */
11 */
12
12
13 #include "tc_handler.h"
13 #include "tc_handler.h"
14 #include "math.h"
14 #include "math.h"
15
15
16 //***********
16 //***********
17 // RTEMS TASK
17 // RTEMS TASK
18
18
19 rtems_task actn_task( rtems_task_argument unused )
19 rtems_task actn_task( rtems_task_argument unused )
20 {
20 {
21 /** This RTEMS task is responsible for launching actions upton the reception of valid TeleCommands.
21 /** This RTEMS task is responsible for launching actions upton the reception of valid TeleCommands.
22 *
22 *
23 * @param unused is the starting argument of the RTEMS task
23 * @param unused is the starting argument of the RTEMS task
24 *
24 *
25 * The ACTN task waits for data coming from an RTEMS msesage queue. When data arrives, it launches specific actions depending
25 * The ACTN task waits for data coming from an RTEMS msesage queue. When data arrives, it launches specific actions depending
26 * on the incoming TeleCommand.
26 * on the incoming TeleCommand.
27 *
27 *
28 */
28 */
29
29
30 int result;
30 int result;
31 rtems_status_code status; // RTEMS status code
31 rtems_status_code status; // RTEMS status code
32 ccsdsTelecommandPacket_t TC; // TC sent to the ACTN task
32 ccsdsTelecommandPacket_t TC; // TC sent to the ACTN task
33 size_t size; // size of the incoming TC packet
33 size_t size; // size of the incoming TC packet
34 unsigned char subtype; // subtype of the current TC packet
34 unsigned char subtype; // subtype of the current TC packet
35 unsigned char time[6];
35 unsigned char time[BYTES_PER_TIME];
36 rtems_id queue_rcv_id;
36 rtems_id queue_rcv_id;
37 rtems_id queue_snd_id;
37 rtems_id queue_snd_id;
38
38
39 status = get_message_queue_id_recv( &queue_rcv_id );
39 status = get_message_queue_id_recv( &queue_rcv_id );
40 if (status != RTEMS_SUCCESSFUL)
40 if (status != RTEMS_SUCCESSFUL)
41 {
41 {
42 PRINTF1("in ACTN *** ERR get_message_queue_id_recv %d\n", status)
42 PRINTF1("in ACTN *** ERR get_message_queue_id_recv %d\n", status)
43 }
43 }
44
44
45 status = get_message_queue_id_send( &queue_snd_id );
45 status = get_message_queue_id_send( &queue_snd_id );
46 if (status != RTEMS_SUCCESSFUL)
46 if (status != RTEMS_SUCCESSFUL)
47 {
47 {
48 PRINTF1("in ACTN *** ERR get_message_queue_id_send %d\n", status)
48 PRINTF1("in ACTN *** ERR get_message_queue_id_send %d\n", status)
49 }
49 }
50
50
51 result = LFR_SUCCESSFUL;
51 result = LFR_SUCCESSFUL;
52 subtype = 0; // subtype of the current TC packet
52 subtype = 0; // subtype of the current TC packet
53
53
54 BOOT_PRINTF("in ACTN *** \n");
54 BOOT_PRINTF("in ACTN *** \n");
55
55
56 while(1)
56 while(1)
57 {
57 {
58 status = rtems_message_queue_receive( queue_rcv_id, (char*) &TC, &size,
58 status = rtems_message_queue_receive( queue_rcv_id, (char*) &TC, &size,
59 RTEMS_WAIT, RTEMS_NO_TIMEOUT);
59 RTEMS_WAIT, RTEMS_NO_TIMEOUT);
60 getTime( time ); // set time to the current time
60 getTime( time ); // set time to the current time
61 if (status!=RTEMS_SUCCESSFUL)
61 if (status!=RTEMS_SUCCESSFUL)
62 {
62 {
63 PRINTF1("ERR *** in task ACTN *** error receiving a message, code %d \n", status)
63 PRINTF1("ERR *** in task ACTN *** error receiving a message, code %d \n", status)
64 }
64 }
65 else
65 else
66 {
66 {
67 subtype = TC.serviceSubType;
67 subtype = TC.serviceSubType;
68 switch(subtype)
68 switch(subtype)
69 {
69 {
70 case TC_SUBTYPE_RESET:
70 case TC_SUBTYPE_RESET:
71 result = action_reset( &TC, queue_snd_id, time );
71 result = action_reset( &TC, queue_snd_id, time );
72 close_action( &TC, result, queue_snd_id );
72 close_action( &TC, result, queue_snd_id );
73 break;
73 break;
74 case TC_SUBTYPE_LOAD_COMM:
74 case TC_SUBTYPE_LOAD_COMM:
75 result = action_load_common_par( &TC );
75 result = action_load_common_par( &TC );
76 close_action( &TC, result, queue_snd_id );
76 close_action( &TC, result, queue_snd_id );
77 break;
77 break;
78 case TC_SUBTYPE_LOAD_NORM:
78 case TC_SUBTYPE_LOAD_NORM:
79 result = action_load_normal_par( &TC, queue_snd_id, time );
79 result = action_load_normal_par( &TC, queue_snd_id, time );
80 close_action( &TC, result, queue_snd_id );
80 close_action( &TC, result, queue_snd_id );
81 break;
81 break;
82 case TC_SUBTYPE_LOAD_BURST:
82 case TC_SUBTYPE_LOAD_BURST:
83 result = action_load_burst_par( &TC, queue_snd_id, time );
83 result = action_load_burst_par( &TC, queue_snd_id, time );
84 close_action( &TC, result, queue_snd_id );
84 close_action( &TC, result, queue_snd_id );
85 break;
85 break;
86 case TC_SUBTYPE_LOAD_SBM1:
86 case TC_SUBTYPE_LOAD_SBM1:
87 result = action_load_sbm1_par( &TC, queue_snd_id, time );
87 result = action_load_sbm1_par( &TC, queue_snd_id, time );
88 close_action( &TC, result, queue_snd_id );
88 close_action( &TC, result, queue_snd_id );
89 break;
89 break;
90 case TC_SUBTYPE_LOAD_SBM2:
90 case TC_SUBTYPE_LOAD_SBM2:
91 result = action_load_sbm2_par( &TC, queue_snd_id, time );
91 result = action_load_sbm2_par( &TC, queue_snd_id, time );
92 close_action( &TC, result, queue_snd_id );
92 close_action( &TC, result, queue_snd_id );
93 break;
93 break;
94 case TC_SUBTYPE_DUMP:
94 case TC_SUBTYPE_DUMP:
95 result = action_dump_par( &TC, queue_snd_id );
95 result = action_dump_par( &TC, queue_snd_id );
96 close_action( &TC, result, queue_snd_id );
96 close_action( &TC, result, queue_snd_id );
97 break;
97 break;
98 case TC_SUBTYPE_ENTER:
98 case TC_SUBTYPE_ENTER:
99 result = action_enter_mode( &TC, queue_snd_id );
99 result = action_enter_mode( &TC, queue_snd_id );
100 close_action( &TC, result, queue_snd_id );
100 close_action( &TC, result, queue_snd_id );
101 break;
101 break;
102 case TC_SUBTYPE_UPDT_INFO:
102 case TC_SUBTYPE_UPDT_INFO:
103 result = action_update_info( &TC, queue_snd_id );
103 result = action_update_info( &TC, queue_snd_id );
104 close_action( &TC, result, queue_snd_id );
104 close_action( &TC, result, queue_snd_id );
105 break;
105 break;
106 case TC_SUBTYPE_EN_CAL:
106 case TC_SUBTYPE_EN_CAL:
107 result = action_enable_calibration( &TC, queue_snd_id, time );
107 result = action_enable_calibration( &TC, queue_snd_id, time );
108 close_action( &TC, result, queue_snd_id );
108 close_action( &TC, result, queue_snd_id );
109 break;
109 break;
110 case TC_SUBTYPE_DIS_CAL:
110 case TC_SUBTYPE_DIS_CAL:
111 result = action_disable_calibration( &TC, queue_snd_id, time );
111 result = action_disable_calibration( &TC, queue_snd_id, time );
112 close_action( &TC, result, queue_snd_id );
112 close_action( &TC, result, queue_snd_id );
113 break;
113 break;
114 case TC_SUBTYPE_LOAD_K:
114 case TC_SUBTYPE_LOAD_K:
115 result = action_load_kcoefficients( &TC, queue_snd_id, time );
115 result = action_load_kcoefficients( &TC, queue_snd_id, time );
116 close_action( &TC, result, queue_snd_id );
116 close_action( &TC, result, queue_snd_id );
117 break;
117 break;
118 case TC_SUBTYPE_DUMP_K:
118 case TC_SUBTYPE_DUMP_K:
119 result = action_dump_kcoefficients( &TC, queue_snd_id, time );
119 result = action_dump_kcoefficients( &TC, queue_snd_id, time );
120 close_action( &TC, result, queue_snd_id );
120 close_action( &TC, result, queue_snd_id );
121 break;
121 break;
122 case TC_SUBTYPE_LOAD_FBINS:
122 case TC_SUBTYPE_LOAD_FBINS:
123 result = action_load_fbins_mask( &TC, queue_snd_id, time );
123 result = action_load_fbins_mask( &TC, queue_snd_id, time );
124 close_action( &TC, result, queue_snd_id );
124 close_action( &TC, result, queue_snd_id );
125 break;
125 break;
126 case TC_SUBTYPE_LOAD_FILTER_PAR:
126 case TC_SUBTYPE_LOAD_FILTER_PAR:
127 result = action_load_filter_par( &TC, queue_snd_id, time );
127 result = action_load_filter_par( &TC, queue_snd_id, time );
128 close_action( &TC, result, queue_snd_id );
128 close_action( &TC, result, queue_snd_id );
129 break;
129 break;
130 case TC_SUBTYPE_UPDT_TIME:
130 case TC_SUBTYPE_UPDT_TIME:
131 result = action_update_time( &TC );
131 result = action_update_time( &TC );
132 close_action( &TC, result, queue_snd_id );
132 close_action( &TC, result, queue_snd_id );
133 break;
133 break;
134 default:
134 default:
135 break;
135 break;
136 }
136 }
137 }
137 }
138 }
138 }
139 }
139 }
140
140
141 //***********
141 //***********
142 // TC ACTIONS
142 // TC ACTIONS
143
143
144 int action_reset(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
144 int action_reset(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
145 {
145 {
146 /** This function executes specific actions when a TC_LFR_RESET TeleCommand has been received.
146 /** This function executes specific actions when a TC_LFR_RESET TeleCommand has been received.
147 *
147 *
148 * @param TC points to the TeleCommand packet that is being processed
148 * @param TC points to the TeleCommand packet that is being processed
149 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
149 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
150 *
150 *
151 */
151 */
152
152
153 PRINTF("this is the end!!!\n");
153 PRINTF("this is the end!!!\n");
154 exit(0);
154 exit(0);
155
155
156 send_tm_lfr_tc_exe_not_implemented( TC, queue_id, time );
156 send_tm_lfr_tc_exe_not_implemented( TC, queue_id, time );
157
157
158 return LFR_DEFAULT;
158 return LFR_DEFAULT;
159 }
159 }
160
160
161 int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
161 int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
162 {
162 {
163 /** This function executes specific actions when a TC_LFR_ENTER_MODE TeleCommand has been received.
163 /** This function executes specific actions when a TC_LFR_ENTER_MODE TeleCommand has been received.
164 *
164 *
165 * @param TC points to the TeleCommand packet that is being processed
165 * @param TC points to the TeleCommand packet that is being processed
166 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
166 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
167 *
167 *
168 */
168 */
169
169
170 rtems_status_code status;
170 rtems_status_code status;
171 unsigned char requestedMode;
171 unsigned char requestedMode;
172 unsigned int *transitionCoarseTime_ptr;
172 unsigned int *transitionCoarseTime_ptr;
173 unsigned int transitionCoarseTime;
173 unsigned int transitionCoarseTime;
174 unsigned char * bytePosPtr;
174 unsigned char * bytePosPtr;
175
175
176 bytePosPtr = (unsigned char *) &TC->packetID;
176 bytePosPtr = (unsigned char *) &TC->packetID;
177
177
178 requestedMode = bytePosPtr[ BYTE_POS_CP_MODE_LFR_SET ];
178 requestedMode = bytePosPtr[ BYTE_POS_CP_MODE_LFR_SET ];
179 transitionCoarseTime_ptr = (unsigned int *) ( &bytePosPtr[ BYTE_POS_CP_LFR_ENTER_MODE_TIME ] );
179 transitionCoarseTime_ptr = (unsigned int *) ( &bytePosPtr[ BYTE_POS_CP_LFR_ENTER_MODE_TIME ] );
180 transitionCoarseTime = (*transitionCoarseTime_ptr) & 0x7fffffff;
180 transitionCoarseTime = (*transitionCoarseTime_ptr) & COARSE_TIME_MASK;
181
181
182 status = check_mode_value( requestedMode );
182 status = check_mode_value( requestedMode );
183
183
184 if ( status != LFR_SUCCESSFUL ) // the mode value is inconsistent
184 if ( status != LFR_SUCCESSFUL ) // the mode value is inconsistent
185 {
185 {
186 send_tm_lfr_tc_exe_inconsistent( TC, queue_id, BYTE_POS_CP_MODE_LFR_SET, requestedMode );
186 send_tm_lfr_tc_exe_inconsistent( TC, queue_id, BYTE_POS_CP_MODE_LFR_SET, requestedMode );
187 }
187 }
188
188
189 else // the mode value is valid, check the transition
189 else // the mode value is valid, check the transition
190 {
190 {
191 status = check_mode_transition(requestedMode);
191 status = check_mode_transition(requestedMode);
192 if (status != LFR_SUCCESSFUL)
192 if (status != LFR_SUCCESSFUL)
193 {
193 {
194 PRINTF("ERR *** in action_enter_mode *** check_mode_transition\n")
194 PRINTF("ERR *** in action_enter_mode *** check_mode_transition\n")
195 send_tm_lfr_tc_exe_not_executable( TC, queue_id );
195 send_tm_lfr_tc_exe_not_executable( TC, queue_id );
196 }
196 }
197 }
197 }
198
198
199 if ( status == LFR_SUCCESSFUL ) // the transition is valid, check the date
199 if ( status == LFR_SUCCESSFUL ) // the transition is valid, check the date
200 {
200 {
201 status = check_transition_date( transitionCoarseTime );
201 status = check_transition_date( transitionCoarseTime );
202 if (status != LFR_SUCCESSFUL)
202 if (status != LFR_SUCCESSFUL)
203 {
203 {
204 PRINTF("ERR *** in action_enter_mode *** check_transition_date\n");
204 PRINTF("ERR *** in action_enter_mode *** check_transition_date\n");
205 send_tm_lfr_tc_exe_not_executable(TC, queue_id );
205 send_tm_lfr_tc_exe_not_executable(TC, queue_id );
206 }
206 }
207 }
207 }
208
208
209 if ( status == LFR_SUCCESSFUL ) // the date is valid, enter the mode
209 if ( status == LFR_SUCCESSFUL ) // the date is valid, enter the mode
210 {
210 {
211 PRINTF1("OK *** in action_enter_mode *** enter mode %d\n", requestedMode);
211 PRINTF1("OK *** in action_enter_mode *** enter mode %d\n", requestedMode);
212
212
213 switch(requestedMode)
213 switch(requestedMode)
214 {
214 {
215 case LFR_MODE_STANDBY:
215 case LFR_MODE_STANDBY:
216 status = enter_mode_standby();
216 status = enter_mode_standby();
217 break;
217 break;
218 case LFR_MODE_NORMAL:
218 case LFR_MODE_NORMAL:
219 status = enter_mode_normal( transitionCoarseTime );
219 status = enter_mode_normal( transitionCoarseTime );
220 break;
220 break;
221 case LFR_MODE_BURST:
221 case LFR_MODE_BURST:
222 status = enter_mode_burst( transitionCoarseTime );
222 status = enter_mode_burst( transitionCoarseTime );
223 break;
223 break;
224 case LFR_MODE_SBM1:
224 case LFR_MODE_SBM1:
225 status = enter_mode_sbm1( transitionCoarseTime );
225 status = enter_mode_sbm1( transitionCoarseTime );
226 break;
226 break;
227 case LFR_MODE_SBM2:
227 case LFR_MODE_SBM2:
228 status = enter_mode_sbm2( transitionCoarseTime );
228 status = enter_mode_sbm2( transitionCoarseTime );
229 break;
229 break;
230 default:
230 default:
231 break;
231 break;
232 }
232 }
233
233
234 if (status != RTEMS_SUCCESSFUL)
234 if (status != RTEMS_SUCCESSFUL)
235 {
235 {
236 status = LFR_EXE_ERROR;
236 status = LFR_EXE_ERROR;
237 }
237 }
238 }
238 }
239
239
240 return status;
240 return status;
241 }
241 }
242
242
243 int action_update_info(ccsdsTelecommandPacket_t *TC, rtems_id queue_id)
243 int action_update_info(ccsdsTelecommandPacket_t *TC, rtems_id queue_id)
244 {
244 {
245 /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received.
245 /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received.
246 *
246 *
247 * @param TC points to the TeleCommand packet that is being processed
247 * @param TC points to the TeleCommand packet that is being processed
248 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
248 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
249 *
249 *
250 * @return LFR directive status code:
250 * @return LFR directive status code:
251 * - LFR_DEFAULT
251 * - LFR_DEFAULT
252 * - LFR_SUCCESSFUL
252 * - LFR_SUCCESSFUL
253 *
253 *
254 */
254 */
255
255
256 unsigned int val;
256 unsigned int val;
257 int result;
257 int result;
258 unsigned int status;
258 unsigned int status;
259 unsigned char mode;
259 unsigned char mode;
260 unsigned char * bytePosPtr;
260 unsigned char * bytePosPtr;
261
261
262 bytePosPtr = (unsigned char *) &TC->packetID;
262 bytePosPtr = (unsigned char *) &TC->packetID;
263
263
264 // check LFR mode
264 // check LFR mode
265 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET5 ] & 0x1e) >> 1;
265 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET5 ] & BITS_LFR_MODE) >> SHIFT_LFR_MODE;
266 status = check_update_info_hk_lfr_mode( mode );
266 status = check_update_info_hk_lfr_mode( mode );
267 if (status == LFR_SUCCESSFUL) // check TDS mode
267 if (status == LFR_SUCCESSFUL) // check TDS mode
268 {
268 {
269 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & 0xf0) >> 4;
269 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & BITS_TDS_MODE) >> SHIFT_TDS_MODE;
270 status = check_update_info_hk_tds_mode( mode );
270 status = check_update_info_hk_tds_mode( mode );
271 }
271 }
272 if (status == LFR_SUCCESSFUL) // check THR mode
272 if (status == LFR_SUCCESSFUL) // check THR mode
273 {
273 {
274 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & 0x0f);
274 mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & BITS_THR_MODE);
275 status = check_update_info_hk_thr_mode( mode );
275 status = check_update_info_hk_thr_mode( mode );
276 }
276 }
277 if (status == LFR_SUCCESSFUL) // if the parameter check is successful
277 if (status == LFR_SUCCESSFUL) // if the parameter check is successful
278 {
278 {
279 val = housekeeping_packet.hk_lfr_update_info_tc_cnt[0] * 256
279 val = (housekeeping_packet.hk_lfr_update_info_tc_cnt[0] * CONST_256)
280 + housekeeping_packet.hk_lfr_update_info_tc_cnt[1];
280 + housekeeping_packet.hk_lfr_update_info_tc_cnt[1];
281 val++;
281 val++;
282 housekeeping_packet.hk_lfr_update_info_tc_cnt[0] = (unsigned char) (val >> 8);
282 housekeeping_packet.hk_lfr_update_info_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE);
283 housekeeping_packet.hk_lfr_update_info_tc_cnt[1] = (unsigned char) (val);
283 housekeeping_packet.hk_lfr_update_info_tc_cnt[1] = (unsigned char) (val);
284 }
284 }
285
285
286 // pa_bia_status_info
286 // pa_bia_status_info
287 // => pa_bia_mode_mux_set 3 bits
287 // => pa_bia_mode_mux_set 3 bits
288 // => pa_bia_mode_hv_enabled 1 bit
288 // => pa_bia_mode_hv_enabled 1 bit
289 // => pa_bia_mode_bias1_enabled 1 bit
289 // => pa_bia_mode_bias1_enabled 1 bit
290 // => pa_bia_mode_bias2_enabled 1 bit
290 // => pa_bia_mode_bias2_enabled 1 bit
291 // => pa_bia_mode_bias3_enabled 1 bit
291 // => pa_bia_mode_bias3_enabled 1 bit
292 // => pa_bia_on_off (cp_dpu_bias_on_off)
292 // => pa_bia_on_off (cp_dpu_bias_on_off)
293 pa_bia_status_info = bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET2 ] & 0xfe; // [1111 1110]
293 pa_bia_status_info = bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET2 ] & BITS_BIA; // [1111 1110]
294 pa_bia_status_info = pa_bia_status_info
294 pa_bia_status_info = pa_bia_status_info
295 | (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET1 ] & 0x1);
295 | (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET1 ] & 1);
296
296
297 // REACTION_WHEELS_FREQUENCY, copy the incoming parameters in the local variable (to be copied in HK packets)
297 // REACTION_WHEELS_FREQUENCY, copy the incoming parameters in the local variable (to be copied in HK packets)
298
298
299 cp_rpw_sc_rw_f_flags = bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW_F_FLAGS ];
299 cp_rpw_sc_rw_f_flags = bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW_F_FLAGS ];
300 getReactionWheelsFrequencies( TC );
300 getReactionWheelsFrequencies( TC );
301 build_sy_lfr_rw_masks();
301 build_sy_lfr_rw_masks();
302
302
303 // once the masks are built, they have to be merged with the fbins_mask
303 // once the masks are built, they have to be merged with the fbins_mask
304 merge_fbins_masks();
304 merge_fbins_masks();
305
305
306 result = status;
306 result = status;
307
307
308 return result;
308 return result;
309 }
309 }
310
310
311 int action_enable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
311 int action_enable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
312 {
312 {
313 /** This function executes specific actions when a TC_LFR_ENABLE_CALIBRATION TeleCommand has been received.
313 /** This function executes specific actions when a TC_LFR_ENABLE_CALIBRATION TeleCommand has been received.
314 *
314 *
315 * @param TC points to the TeleCommand packet that is being processed
315 * @param TC points to the TeleCommand packet that is being processed
316 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
316 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
317 *
317 *
318 */
318 */
319
319
320 int result;
320 int result;
321
321
322 result = LFR_DEFAULT;
322 result = LFR_DEFAULT;
323
323
324 setCalibration( true );
324 setCalibration( true );
325
325
326 result = LFR_SUCCESSFUL;
326 result = LFR_SUCCESSFUL;
327
327
328 return result;
328 return result;
329 }
329 }
330
330
331 int action_disable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
331 int action_disable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
332 {
332 {
333 /** This function executes specific actions when a TC_LFR_DISABLE_CALIBRATION TeleCommand has been received.
333 /** This function executes specific actions when a TC_LFR_DISABLE_CALIBRATION TeleCommand has been received.
334 *
334 *
335 * @param TC points to the TeleCommand packet that is being processed
335 * @param TC points to the TeleCommand packet that is being processed
336 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
336 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
337 *
337 *
338 */
338 */
339
339
340 int result;
340 int result;
341
341
342 result = LFR_DEFAULT;
342 result = LFR_DEFAULT;
343
343
344 setCalibration( false );
344 setCalibration( false );
345
345
346 result = LFR_SUCCESSFUL;
346 result = LFR_SUCCESSFUL;
347
347
348 return result;
348 return result;
349 }
349 }
350
350
351 int action_update_time(ccsdsTelecommandPacket_t *TC)
351 int action_update_time(ccsdsTelecommandPacket_t *TC)
352 {
352 {
353 /** This function executes specific actions when a TC_LFR_UPDATE_TIME TeleCommand has been received.
353 /** This function executes specific actions when a TC_LFR_UPDATE_TIME TeleCommand has been received.
354 *
354 *
355 * @param TC points to the TeleCommand packet that is being processed
355 * @param TC points to the TeleCommand packet that is being processed
356 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
356 * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver
357 *
357 *
358 * @return LFR_SUCCESSFUL
358 * @return LFR_SUCCESSFUL
359 *
359 *
360 */
360 */
361
361
362 unsigned int val;
362 unsigned int val;
363
363
364 time_management_regs->coarse_time_load = (TC->dataAndCRC[0] << 24)
364 time_management_regs->coarse_time_load = (TC->dataAndCRC[BYTE_0] << SHIFT_3_BYTES)
365 + (TC->dataAndCRC[1] << 16)
365 + (TC->dataAndCRC[BYTE_1] << SHIFT_2_BYTES)
366 + (TC->dataAndCRC[2] << 8)
366 + (TC->dataAndCRC[BYTE_2] << SHIFT_1_BYTE)
367 + TC->dataAndCRC[3];
367 + TC->dataAndCRC[BYTE_3];
368
368
369 val = housekeeping_packet.hk_lfr_update_time_tc_cnt[0] * 256
369 val = (housekeeping_packet.hk_lfr_update_time_tc_cnt[0] * CONST_256)
370 + housekeeping_packet.hk_lfr_update_time_tc_cnt[1];
370 + housekeeping_packet.hk_lfr_update_time_tc_cnt[1];
371 val++;
371 val++;
372 housekeeping_packet.hk_lfr_update_time_tc_cnt[0] = (unsigned char) (val >> 8);
372 housekeeping_packet.hk_lfr_update_time_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE);
373 housekeeping_packet.hk_lfr_update_time_tc_cnt[1] = (unsigned char) (val);
373 housekeeping_packet.hk_lfr_update_time_tc_cnt[1] = (unsigned char) (val);
374
374
375 oneTcLfrUpdateTimeReceived = 1;
375 oneTcLfrUpdateTimeReceived = 1;
376
376
377 return LFR_SUCCESSFUL;
377 return LFR_SUCCESSFUL;
378 }
378 }
379
379
380 //*******************
380 //*******************
381 // ENTERING THE MODES
381 // ENTERING THE MODES
382 int check_mode_value( unsigned char requestedMode )
382 int check_mode_value( unsigned char requestedMode )
383 {
383 {
384 int status;
384 int status;
385
385
386 if ( (requestedMode != LFR_MODE_STANDBY)
386 if ( (requestedMode != LFR_MODE_STANDBY)
387 && (requestedMode != LFR_MODE_NORMAL) && (requestedMode != LFR_MODE_BURST)
387 && (requestedMode != LFR_MODE_NORMAL) && (requestedMode != LFR_MODE_BURST)
388 && (requestedMode != LFR_MODE_SBM1) && (requestedMode != LFR_MODE_SBM2) )
388 && (requestedMode != LFR_MODE_SBM1) && (requestedMode != LFR_MODE_SBM2) )
389 {
389 {
390 status = LFR_DEFAULT;
390 status = LFR_DEFAULT;
391 }
391 }
392 else
392 else
393 {
393 {
394 status = LFR_SUCCESSFUL;
394 status = LFR_SUCCESSFUL;
395 }
395 }
396
396
397 return status;
397 return status;
398 }
398 }
399
399
400 int check_mode_transition( unsigned char requestedMode )
400 int check_mode_transition( unsigned char requestedMode )
401 {
401 {
402 /** This function checks the validity of the transition requested by the TC_LFR_ENTER_MODE.
402 /** This function checks the validity of the transition requested by the TC_LFR_ENTER_MODE.
403 *
403 *
404 * @param requestedMode is the mode requested by the TC_LFR_ENTER_MODE
404 * @param requestedMode is the mode requested by the TC_LFR_ENTER_MODE
405 *
405 *
406 * @return LFR directive status codes:
406 * @return LFR directive status codes:
407 * - LFR_SUCCESSFUL - the transition is authorized
407 * - LFR_SUCCESSFUL - the transition is authorized
408 * - LFR_DEFAULT - the transition is not authorized
408 * - LFR_DEFAULT - the transition is not authorized
409 *
409 *
410 */
410 */
411
411
412 int status;
412 int status;
413
413
414 switch (requestedMode)
414 switch (requestedMode)
415 {
415 {
416 case LFR_MODE_STANDBY:
416 case LFR_MODE_STANDBY:
417 if ( lfrCurrentMode == LFR_MODE_STANDBY ) {
417 if ( lfrCurrentMode == LFR_MODE_STANDBY ) {
418 status = LFR_DEFAULT;
418 status = LFR_DEFAULT;
419 }
419 }
420 else
420 else
421 {
421 {
422 status = LFR_SUCCESSFUL;
422 status = LFR_SUCCESSFUL;
423 }
423 }
424 break;
424 break;
425 case LFR_MODE_NORMAL:
425 case LFR_MODE_NORMAL:
426 if ( lfrCurrentMode == LFR_MODE_NORMAL ) {
426 if ( lfrCurrentMode == LFR_MODE_NORMAL ) {
427 status = LFR_DEFAULT;
427 status = LFR_DEFAULT;
428 }
428 }
429 else {
429 else {
430 status = LFR_SUCCESSFUL;
430 status = LFR_SUCCESSFUL;
431 }
431 }
432 break;
432 break;
433 case LFR_MODE_BURST:
433 case LFR_MODE_BURST:
434 if ( lfrCurrentMode == LFR_MODE_BURST ) {
434 if ( lfrCurrentMode == LFR_MODE_BURST ) {
435 status = LFR_DEFAULT;
435 status = LFR_DEFAULT;
436 }
436 }
437 else {
437 else {
438 status = LFR_SUCCESSFUL;
438 status = LFR_SUCCESSFUL;
439 }
439 }
440 break;
440 break;
441 case LFR_MODE_SBM1:
441 case LFR_MODE_SBM1:
442 if ( lfrCurrentMode == LFR_MODE_SBM1 ) {
442 if ( lfrCurrentMode == LFR_MODE_SBM1 ) {
443 status = LFR_DEFAULT;
443 status = LFR_DEFAULT;
444 }
444 }
445 else {
445 else {
446 status = LFR_SUCCESSFUL;
446 status = LFR_SUCCESSFUL;
447 }
447 }
448 break;
448 break;
449 case LFR_MODE_SBM2:
449 case LFR_MODE_SBM2:
450 if ( lfrCurrentMode == LFR_MODE_SBM2 ) {
450 if ( lfrCurrentMode == LFR_MODE_SBM2 ) {
451 status = LFR_DEFAULT;
451 status = LFR_DEFAULT;
452 }
452 }
453 else {
453 else {
454 status = LFR_SUCCESSFUL;
454 status = LFR_SUCCESSFUL;
455 }
455 }
456 break;
456 break;
457 default:
457 default:
458 status = LFR_DEFAULT;
458 status = LFR_DEFAULT;
459 break;
459 break;
460 }
460 }
461
461
462 return status;
462 return status;
463 }
463 }
464
464
465 void update_last_valid_transition_date( unsigned int transitionCoarseTime )
465 void update_last_valid_transition_date( unsigned int transitionCoarseTime )
466 {
466 {
467 if (transitionCoarseTime == 0)
467 if (transitionCoarseTime == 0)
468 {
468 {
469 lastValidEnterModeTime = time_management_regs->coarse_time + 1;
469 lastValidEnterModeTime = time_management_regs->coarse_time + 1;
470 PRINTF1("lastValidEnterModeTime = 0x%x (transitionCoarseTime = 0 => coarse_time+1)\n", lastValidEnterModeTime);
470 PRINTF1("lastValidEnterModeTime = 0x%x (transitionCoarseTime = 0 => coarse_time+1)\n", lastValidEnterModeTime);
471 }
471 }
472 else
472 else
473 {
473 {
474 lastValidEnterModeTime = transitionCoarseTime;
474 lastValidEnterModeTime = transitionCoarseTime;
475 PRINTF1("lastValidEnterModeTime = 0x%x\n", transitionCoarseTime);
475 PRINTF1("lastValidEnterModeTime = 0x%x\n", transitionCoarseTime);
476 }
476 }
477 }
477 }
478
478
479 int check_transition_date( unsigned int transitionCoarseTime )
479 int check_transition_date( unsigned int transitionCoarseTime )
480 {
480 {
481 int status;
481 int status;
482 unsigned int localCoarseTime;
482 unsigned int localCoarseTime;
483 unsigned int deltaCoarseTime;
483 unsigned int deltaCoarseTime;
484
484
485 status = LFR_SUCCESSFUL;
485 status = LFR_SUCCESSFUL;
486
486
487 if (transitionCoarseTime == 0) // transition time = 0 means an instant transition
487 if (transitionCoarseTime == 0) // transition time = 0 means an instant transition
488 {
488 {
489 status = LFR_SUCCESSFUL;
489 status = LFR_SUCCESSFUL;
490 }
490 }
491 else
491 else
492 {
492 {
493 localCoarseTime = time_management_regs->coarse_time & 0x7fffffff;
493 localCoarseTime = time_management_regs->coarse_time & COARSE_TIME_MASK;
494
494
495 PRINTF2("localTime = %x, transitionTime = %x\n", localCoarseTime, transitionCoarseTime);
495 PRINTF2("localTime = %x, transitionTime = %x\n", localCoarseTime, transitionCoarseTime);
496
496
497 if ( transitionCoarseTime <= localCoarseTime ) // SSS-CP-EQS-322
497 if ( transitionCoarseTime <= localCoarseTime ) // SSS-CP-EQS-322
498 {
498 {
499 status = LFR_DEFAULT;
499 status = LFR_DEFAULT;
500 PRINTF("ERR *** in check_transition_date *** transitionCoarseTime <= localCoarseTime\n");
500 PRINTF("ERR *** in check_transition_date *** transitionCoarseTime <= localCoarseTime\n");
501 }
501 }
502
502
503 if (status == LFR_SUCCESSFUL)
503 if (status == LFR_SUCCESSFUL)
504 {
504 {
505 deltaCoarseTime = transitionCoarseTime - localCoarseTime;
505 deltaCoarseTime = transitionCoarseTime - localCoarseTime;
506 if ( deltaCoarseTime > 3 ) // SSS-CP-EQS-323
506 if ( deltaCoarseTime > MAX_DELTA_COARSE_TIME ) // SSS-CP-EQS-323
507 {
507 {
508 status = LFR_DEFAULT;
508 status = LFR_DEFAULT;
509 PRINTF1("ERR *** in check_transition_date *** deltaCoarseTime = %x\n", deltaCoarseTime)
509 PRINTF1("ERR *** in check_transition_date *** deltaCoarseTime = %x\n", deltaCoarseTime)
510 }
510 }
511 }
511 }
512 }
512 }
513
513
514 return status;
514 return status;
515 }
515 }
516
516
517 int restart_asm_activities( unsigned char lfrRequestedMode )
517 int restart_asm_activities( unsigned char lfrRequestedMode )
518 {
518 {
519 rtems_status_code status;
519 rtems_status_code status;
520
520
521 status = stop_spectral_matrices();
521 status = stop_spectral_matrices();
522
522
523 thisIsAnASMRestart = 1;
523 thisIsAnASMRestart = 1;
524
524
525 status = restart_asm_tasks( lfrRequestedMode );
525 status = restart_asm_tasks( lfrRequestedMode );
526
526
527 launch_spectral_matrix();
527 launch_spectral_matrix();
528
528
529 return status;
529 return status;
530 }
530 }
531
531
532 int stop_spectral_matrices( void )
532 int stop_spectral_matrices( void )
533 {
533 {
534 /** This function stops and restarts the current mode average spectral matrices activities.
534 /** This function stops and restarts the current mode average spectral matrices activities.
535 *
535 *
536 * @return RTEMS directive status codes:
536 * @return RTEMS directive status codes:
537 * - RTEMS_SUCCESSFUL - task restarted successfully
537 * - RTEMS_SUCCESSFUL - task restarted successfully
538 * - RTEMS_INVALID_ID - task id invalid
538 * - RTEMS_INVALID_ID - task id invalid
539 * - RTEMS_ALREADY_SUSPENDED - task already suspended
539 * - RTEMS_ALREADY_SUSPENDED - task already suspended
540 *
540 *
541 */
541 */
542
542
543 rtems_status_code status;
543 rtems_status_code status;
544
544
545 status = RTEMS_SUCCESSFUL;
545 status = RTEMS_SUCCESSFUL;
546
546
547 // (1) mask interruptions
547 // (1) mask interruptions
548 LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // mask spectral matrix interrupt
548 LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // mask spectral matrix interrupt
549
549
550 // (2) reset spectral matrices registers
550 // (2) reset spectral matrices registers
551 set_sm_irq_onNewMatrix( 0 ); // stop the spectral matrices
551 set_sm_irq_onNewMatrix( 0 ); // stop the spectral matrices
552 reset_sm_status();
552 reset_sm_status();
553
553
554 // (3) clear interruptions
554 // (3) clear interruptions
555 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
555 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
556
556
557 // suspend several tasks
557 // suspend several tasks
558 if (lfrCurrentMode != LFR_MODE_STANDBY) {
558 if (lfrCurrentMode != LFR_MODE_STANDBY) {
559 status = suspend_asm_tasks();
559 status = suspend_asm_tasks();
560 }
560 }
561
561
562 if (status != RTEMS_SUCCESSFUL)
562 if (status != RTEMS_SUCCESSFUL)
563 {
563 {
564 PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status)
564 PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status)
565 }
565 }
566
566
567 return status;
567 return status;
568 }
568 }
569
569
570 int stop_current_mode( void )
570 int stop_current_mode( void )
571 {
571 {
572 /** This function stops the current mode by masking interrupt lines and suspending science tasks.
572 /** This function stops the current mode by masking interrupt lines and suspending science tasks.
573 *
573 *
574 * @return RTEMS directive status codes:
574 * @return RTEMS directive status codes:
575 * - RTEMS_SUCCESSFUL - task restarted successfully
575 * - RTEMS_SUCCESSFUL - task restarted successfully
576 * - RTEMS_INVALID_ID - task id invalid
576 * - RTEMS_INVALID_ID - task id invalid
577 * - RTEMS_ALREADY_SUSPENDED - task already suspended
577 * - RTEMS_ALREADY_SUSPENDED - task already suspended
578 *
578 *
579 */
579 */
580
580
581 rtems_status_code status;
581 rtems_status_code status;
582
582
583 status = RTEMS_SUCCESSFUL;
583 status = RTEMS_SUCCESSFUL;
584
584
585 // (1) mask interruptions
585 // (1) mask interruptions
586 LEON_Mask_interrupt( IRQ_WAVEFORM_PICKER ); // mask waveform picker interrupt
586 LEON_Mask_interrupt( IRQ_WAVEFORM_PICKER ); // mask waveform picker interrupt
587 LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
587 LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
588
588
589 // (2) reset waveform picker registers
589 // (2) reset waveform picker registers
590 reset_wfp_burst_enable(); // reset burst and enable bits
590 reset_wfp_burst_enable(); // reset burst and enable bits
591 reset_wfp_status(); // reset all the status bits
591 reset_wfp_status(); // reset all the status bits
592
592
593 // (3) reset spectral matrices registers
593 // (3) reset spectral matrices registers
594 set_sm_irq_onNewMatrix( 0 ); // stop the spectral matrices
594 set_sm_irq_onNewMatrix( 0 ); // stop the spectral matrices
595 reset_sm_status();
595 reset_sm_status();
596
596
597 // reset lfr VHDL module
597 // reset lfr VHDL module
598 reset_lfr();
598 reset_lfr();
599
599
600 reset_extractSWF(); // reset the extractSWF flag to false
600 reset_extractSWF(); // reset the extractSWF flag to false
601
601
602 // (4) clear interruptions
602 // (4) clear interruptions
603 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER ); // clear waveform picker interrupt
603 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER ); // clear waveform picker interrupt
604 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
604 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt
605
605
606 // suspend several tasks
606 // suspend several tasks
607 if (lfrCurrentMode != LFR_MODE_STANDBY) {
607 if (lfrCurrentMode != LFR_MODE_STANDBY) {
608 status = suspend_science_tasks();
608 status = suspend_science_tasks();
609 }
609 }
610
610
611 if (status != RTEMS_SUCCESSFUL)
611 if (status != RTEMS_SUCCESSFUL)
612 {
612 {
613 PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status)
613 PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status)
614 }
614 }
615
615
616 return status;
616 return status;
617 }
617 }
618
618
619 int enter_mode_standby( void )
619 int enter_mode_standby( void )
620 {
620 {
621 /** This function is used to put LFR in the STANDBY mode.
621 /** This function is used to put LFR in the STANDBY mode.
622 *
622 *
623 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
623 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
624 *
624 *
625 * @return RTEMS directive status codes:
625 * @return RTEMS directive status codes:
626 * - RTEMS_SUCCESSFUL - task restarted successfully
626 * - RTEMS_SUCCESSFUL - task restarted successfully
627 * - RTEMS_INVALID_ID - task id invalid
627 * - RTEMS_INVALID_ID - task id invalid
628 * - RTEMS_INCORRECT_STATE - task never started
628 * - RTEMS_INCORRECT_STATE - task never started
629 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
629 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
630 *
630 *
631 * The STANDBY mode does not depends on a specific transition date, the effect of the TC_LFR_ENTER_MODE
631 * The STANDBY mode does not depends on a specific transition date, the effect of the TC_LFR_ENTER_MODE
632 * is immediate.
632 * is immediate.
633 *
633 *
634 */
634 */
635
635
636 int status;
636 int status;
637
637
638 status = stop_current_mode(); // STOP THE CURRENT MODE
638 status = stop_current_mode(); // STOP THE CURRENT MODE
639
639
640 #ifdef PRINT_TASK_STATISTICS
640 #ifdef PRINT_TASK_STATISTICS
641 rtems_cpu_usage_report();
641 rtems_cpu_usage_report();
642 #endif
642 #endif
643
643
644 #ifdef PRINT_STACK_REPORT
644 #ifdef PRINT_STACK_REPORT
645 PRINTF("stack report selected\n")
645 PRINTF("stack report selected\n")
646 rtems_stack_checker_report_usage();
646 rtems_stack_checker_report_usage();
647 #endif
647 #endif
648
648
649 return status;
649 return status;
650 }
650 }
651
651
652 int enter_mode_normal( unsigned int transitionCoarseTime )
652 int enter_mode_normal( unsigned int transitionCoarseTime )
653 {
653 {
654 /** This function is used to start the NORMAL mode.
654 /** This function is used to start the NORMAL mode.
655 *
655 *
656 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
656 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
657 *
657 *
658 * @return RTEMS directive status codes:
658 * @return RTEMS directive status codes:
659 * - RTEMS_SUCCESSFUL - task restarted successfully
659 * - RTEMS_SUCCESSFUL - task restarted successfully
660 * - RTEMS_INVALID_ID - task id invalid
660 * - RTEMS_INVALID_ID - task id invalid
661 * - RTEMS_INCORRECT_STATE - task never started
661 * - RTEMS_INCORRECT_STATE - task never started
662 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
662 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
663 *
663 *
664 * The way the NORMAL mode is started depends on the LFR current mode. If LFR is in SBM1 or SBM2,
664 * The way the NORMAL mode is started depends on the LFR current mode. If LFR is in SBM1 or SBM2,
665 * the snapshots are not restarted, only ASM, BP and CWF data generation are affected.
665 * the snapshots are not restarted, only ASM, BP and CWF data generation are affected.
666 *
666 *
667 */
667 */
668
668
669 int status;
669 int status;
670
670
671 #ifdef PRINT_TASK_STATISTICS
671 #ifdef PRINT_TASK_STATISTICS
672 rtems_cpu_usage_reset();
672 rtems_cpu_usage_reset();
673 #endif
673 #endif
674
674
675 status = RTEMS_UNSATISFIED;
675 status = RTEMS_UNSATISFIED;
676
676
677 switch( lfrCurrentMode )
677 switch( lfrCurrentMode )
678 {
678 {
679 case LFR_MODE_STANDBY:
679 case LFR_MODE_STANDBY:
680 status = restart_science_tasks( LFR_MODE_NORMAL ); // restart science tasks
680 status = restart_science_tasks( LFR_MODE_NORMAL ); // restart science tasks
681 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
681 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
682 {
682 {
683 launch_spectral_matrix( );
683 launch_spectral_matrix( );
684 launch_waveform_picker( LFR_MODE_NORMAL, transitionCoarseTime );
684 launch_waveform_picker( LFR_MODE_NORMAL, transitionCoarseTime );
685 }
685 }
686 break;
686 break;
687 case LFR_MODE_BURST:
687 case LFR_MODE_BURST:
688 status = stop_current_mode(); // stop the current mode
688 status = stop_current_mode(); // stop the current mode
689 status = restart_science_tasks( LFR_MODE_NORMAL ); // restart the science tasks
689 status = restart_science_tasks( LFR_MODE_NORMAL ); // restart the science tasks
690 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
690 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
691 {
691 {
692 launch_spectral_matrix( );
692 launch_spectral_matrix( );
693 launch_waveform_picker( LFR_MODE_NORMAL, transitionCoarseTime );
693 launch_waveform_picker( LFR_MODE_NORMAL, transitionCoarseTime );
694 }
694 }
695 break;
695 break;
696 case LFR_MODE_SBM1:
696 case LFR_MODE_SBM1:
697 status = restart_asm_activities( LFR_MODE_NORMAL ); // this is necessary to restart ASM tasks to update the parameters
697 status = restart_asm_activities( LFR_MODE_NORMAL ); // this is necessary to restart ASM tasks to update the parameters
698 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
698 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
699 update_last_valid_transition_date( transitionCoarseTime );
699 update_last_valid_transition_date( transitionCoarseTime );
700 break;
700 break;
701 case LFR_MODE_SBM2:
701 case LFR_MODE_SBM2:
702 status = restart_asm_activities( LFR_MODE_NORMAL ); // this is necessary to restart ASM tasks to update the parameters
702 status = restart_asm_activities( LFR_MODE_NORMAL ); // this is necessary to restart ASM tasks to update the parameters
703 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
703 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
704 update_last_valid_transition_date( transitionCoarseTime );
704 update_last_valid_transition_date( transitionCoarseTime );
705 break;
705 break;
706 default:
706 default:
707 break;
707 break;
708 }
708 }
709
709
710 if (status != RTEMS_SUCCESSFUL)
710 if (status != RTEMS_SUCCESSFUL)
711 {
711 {
712 PRINTF1("ERR *** in enter_mode_normal *** status = %d\n", status)
712 PRINTF1("ERR *** in enter_mode_normal *** status = %d\n", status)
713 status = RTEMS_UNSATISFIED;
713 status = RTEMS_UNSATISFIED;
714 }
714 }
715
715
716 return status;
716 return status;
717 }
717 }
718
718
719 int enter_mode_burst( unsigned int transitionCoarseTime )
719 int enter_mode_burst( unsigned int transitionCoarseTime )
720 {
720 {
721 /** This function is used to start the BURST mode.
721 /** This function is used to start the BURST mode.
722 *
722 *
723 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
723 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
724 *
724 *
725 * @return RTEMS directive status codes:
725 * @return RTEMS directive status codes:
726 * - RTEMS_SUCCESSFUL - task restarted successfully
726 * - RTEMS_SUCCESSFUL - task restarted successfully
727 * - RTEMS_INVALID_ID - task id invalid
727 * - RTEMS_INVALID_ID - task id invalid
728 * - RTEMS_INCORRECT_STATE - task never started
728 * - RTEMS_INCORRECT_STATE - task never started
729 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
729 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
730 *
730 *
731 * The way the BURST mode is started does not depend on the LFR current mode.
731 * The way the BURST mode is started does not depend on the LFR current mode.
732 *
732 *
733 */
733 */
734
734
735
735
736 int status;
736 int status;
737
737
738 #ifdef PRINT_TASK_STATISTICS
738 #ifdef PRINT_TASK_STATISTICS
739 rtems_cpu_usage_reset();
739 rtems_cpu_usage_reset();
740 #endif
740 #endif
741
741
742 status = stop_current_mode(); // stop the current mode
742 status = stop_current_mode(); // stop the current mode
743 status = restart_science_tasks( LFR_MODE_BURST ); // restart the science tasks
743 status = restart_science_tasks( LFR_MODE_BURST ); // restart the science tasks
744 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
744 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
745 {
745 {
746 launch_spectral_matrix( );
746 launch_spectral_matrix( );
747 launch_waveform_picker( LFR_MODE_BURST, transitionCoarseTime );
747 launch_waveform_picker( LFR_MODE_BURST, transitionCoarseTime );
748 }
748 }
749
749
750 if (status != RTEMS_SUCCESSFUL)
750 if (status != RTEMS_SUCCESSFUL)
751 {
751 {
752 PRINTF1("ERR *** in enter_mode_burst *** status = %d\n", status)
752 PRINTF1("ERR *** in enter_mode_burst *** status = %d\n", status)
753 status = RTEMS_UNSATISFIED;
753 status = RTEMS_UNSATISFIED;
754 }
754 }
755
755
756 return status;
756 return status;
757 }
757 }
758
758
759 int enter_mode_sbm1( unsigned int transitionCoarseTime )
759 int enter_mode_sbm1( unsigned int transitionCoarseTime )
760 {
760 {
761 /** This function is used to start the SBM1 mode.
761 /** This function is used to start the SBM1 mode.
762 *
762 *
763 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
763 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
764 *
764 *
765 * @return RTEMS directive status codes:
765 * @return RTEMS directive status codes:
766 * - RTEMS_SUCCESSFUL - task restarted successfully
766 * - RTEMS_SUCCESSFUL - task restarted successfully
767 * - RTEMS_INVALID_ID - task id invalid
767 * - RTEMS_INVALID_ID - task id invalid
768 * - RTEMS_INCORRECT_STATE - task never started
768 * - RTEMS_INCORRECT_STATE - task never started
769 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
769 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
770 *
770 *
771 * The way the SBM1 mode is started depends on the LFR current mode. If LFR is in NORMAL or SBM2,
771 * The way the SBM1 mode is started depends on the LFR current mode. If LFR is in NORMAL or SBM2,
772 * the snapshots are not restarted, only ASM, BP and CWF data generation are affected. In other
772 * the snapshots are not restarted, only ASM, BP and CWF data generation are affected. In other
773 * cases, the acquisition is completely restarted.
773 * cases, the acquisition is completely restarted.
774 *
774 *
775 */
775 */
776
776
777 int status;
777 int status;
778
778
779 #ifdef PRINT_TASK_STATISTICS
779 #ifdef PRINT_TASK_STATISTICS
780 rtems_cpu_usage_reset();
780 rtems_cpu_usage_reset();
781 #endif
781 #endif
782
782
783 status = RTEMS_UNSATISFIED;
783 status = RTEMS_UNSATISFIED;
784
784
785 switch( lfrCurrentMode )
785 switch( lfrCurrentMode )
786 {
786 {
787 case LFR_MODE_STANDBY:
787 case LFR_MODE_STANDBY:
788 status = restart_science_tasks( LFR_MODE_SBM1 ); // restart science tasks
788 status = restart_science_tasks( LFR_MODE_SBM1 ); // restart science tasks
789 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
789 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
790 {
790 {
791 launch_spectral_matrix( );
791 launch_spectral_matrix( );
792 launch_waveform_picker( LFR_MODE_SBM1, transitionCoarseTime );
792 launch_waveform_picker( LFR_MODE_SBM1, transitionCoarseTime );
793 }
793 }
794 break;
794 break;
795 case LFR_MODE_NORMAL: // lfrCurrentMode will be updated after the execution of close_action
795 case LFR_MODE_NORMAL: // lfrCurrentMode will be updated after the execution of close_action
796 status = restart_asm_activities( LFR_MODE_SBM1 );
796 status = restart_asm_activities( LFR_MODE_SBM1 );
797 status = LFR_SUCCESSFUL;
797 status = LFR_SUCCESSFUL;
798 update_last_valid_transition_date( transitionCoarseTime );
798 update_last_valid_transition_date( transitionCoarseTime );
799 break;
799 break;
800 case LFR_MODE_BURST:
800 case LFR_MODE_BURST:
801 status = stop_current_mode(); // stop the current mode
801 status = stop_current_mode(); // stop the current mode
802 status = restart_science_tasks( LFR_MODE_SBM1 ); // restart the science tasks
802 status = restart_science_tasks( LFR_MODE_SBM1 ); // restart the science tasks
803 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
803 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
804 {
804 {
805 launch_spectral_matrix( );
805 launch_spectral_matrix( );
806 launch_waveform_picker( LFR_MODE_SBM1, transitionCoarseTime );
806 launch_waveform_picker( LFR_MODE_SBM1, transitionCoarseTime );
807 }
807 }
808 break;
808 break;
809 case LFR_MODE_SBM2:
809 case LFR_MODE_SBM2:
810 status = restart_asm_activities( LFR_MODE_SBM1 );
810 status = restart_asm_activities( LFR_MODE_SBM1 );
811 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
811 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
812 update_last_valid_transition_date( transitionCoarseTime );
812 update_last_valid_transition_date( transitionCoarseTime );
813 break;
813 break;
814 default:
814 default:
815 break;
815 break;
816 }
816 }
817
817
818 if (status != RTEMS_SUCCESSFUL)
818 if (status != RTEMS_SUCCESSFUL)
819 {
819 {
820 PRINTF1("ERR *** in enter_mode_sbm1 *** status = %d\n", status);
820 PRINTF1("ERR *** in enter_mode_sbm1 *** status = %d\n", status);
821 status = RTEMS_UNSATISFIED;
821 status = RTEMS_UNSATISFIED;
822 }
822 }
823
823
824 return status;
824 return status;
825 }
825 }
826
826
827 int enter_mode_sbm2( unsigned int transitionCoarseTime )
827 int enter_mode_sbm2( unsigned int transitionCoarseTime )
828 {
828 {
829 /** This function is used to start the SBM2 mode.
829 /** This function is used to start the SBM2 mode.
830 *
830 *
831 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
831 * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE
832 *
832 *
833 * @return RTEMS directive status codes:
833 * @return RTEMS directive status codes:
834 * - RTEMS_SUCCESSFUL - task restarted successfully
834 * - RTEMS_SUCCESSFUL - task restarted successfully
835 * - RTEMS_INVALID_ID - task id invalid
835 * - RTEMS_INVALID_ID - task id invalid
836 * - RTEMS_INCORRECT_STATE - task never started
836 * - RTEMS_INCORRECT_STATE - task never started
837 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
837 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
838 *
838 *
839 * The way the SBM2 mode is started depends on the LFR current mode. If LFR is in NORMAL or SBM1,
839 * The way the SBM2 mode is started depends on the LFR current mode. If LFR is in NORMAL or SBM1,
840 * the snapshots are not restarted, only ASM, BP and CWF data generation are affected. In other
840 * the snapshots are not restarted, only ASM, BP and CWF data generation are affected. In other
841 * cases, the acquisition is completely restarted.
841 * cases, the acquisition is completely restarted.
842 *
842 *
843 */
843 */
844
844
845 int status;
845 int status;
846
846
847 #ifdef PRINT_TASK_STATISTICS
847 #ifdef PRINT_TASK_STATISTICS
848 rtems_cpu_usage_reset();
848 rtems_cpu_usage_reset();
849 #endif
849 #endif
850
850
851 status = RTEMS_UNSATISFIED;
851 status = RTEMS_UNSATISFIED;
852
852
853 switch( lfrCurrentMode )
853 switch( lfrCurrentMode )
854 {
854 {
855 case LFR_MODE_STANDBY:
855 case LFR_MODE_STANDBY:
856 status = restart_science_tasks( LFR_MODE_SBM2 ); // restart science tasks
856 status = restart_science_tasks( LFR_MODE_SBM2 ); // restart science tasks
857 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
857 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
858 {
858 {
859 launch_spectral_matrix( );
859 launch_spectral_matrix( );
860 launch_waveform_picker( LFR_MODE_SBM2, transitionCoarseTime );
860 launch_waveform_picker( LFR_MODE_SBM2, transitionCoarseTime );
861 }
861 }
862 break;
862 break;
863 case LFR_MODE_NORMAL:
863 case LFR_MODE_NORMAL:
864 status = restart_asm_activities( LFR_MODE_SBM2 );
864 status = restart_asm_activities( LFR_MODE_SBM2 );
865 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
865 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
866 update_last_valid_transition_date( transitionCoarseTime );
866 update_last_valid_transition_date( transitionCoarseTime );
867 break;
867 break;
868 case LFR_MODE_BURST:
868 case LFR_MODE_BURST:
869 status = stop_current_mode(); // stop the current mode
869 status = stop_current_mode(); // stop the current mode
870 status = restart_science_tasks( LFR_MODE_SBM2 ); // restart the science tasks
870 status = restart_science_tasks( LFR_MODE_SBM2 ); // restart the science tasks
871 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
871 if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules
872 {
872 {
873 launch_spectral_matrix( );
873 launch_spectral_matrix( );
874 launch_waveform_picker( LFR_MODE_SBM2, transitionCoarseTime );
874 launch_waveform_picker( LFR_MODE_SBM2, transitionCoarseTime );
875 }
875 }
876 break;
876 break;
877 case LFR_MODE_SBM1:
877 case LFR_MODE_SBM1:
878 status = restart_asm_activities( LFR_MODE_SBM2 );
878 status = restart_asm_activities( LFR_MODE_SBM2 );
879 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
879 status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action
880 update_last_valid_transition_date( transitionCoarseTime );
880 update_last_valid_transition_date( transitionCoarseTime );
881 break;
881 break;
882 default:
882 default:
883 break;
883 break;
884 }
884 }
885
885
886 if (status != RTEMS_SUCCESSFUL)
886 if (status != RTEMS_SUCCESSFUL)
887 {
887 {
888 PRINTF1("ERR *** in enter_mode_sbm2 *** status = %d\n", status)
888 PRINTF1("ERR *** in enter_mode_sbm2 *** status = %d\n", status)
889 status = RTEMS_UNSATISFIED;
889 status = RTEMS_UNSATISFIED;
890 }
890 }
891
891
892 return status;
892 return status;
893 }
893 }
894
894
895 int restart_science_tasks( unsigned char lfrRequestedMode )
895 int restart_science_tasks( unsigned char lfrRequestedMode )
896 {
896 {
897 /** This function is used to restart all science tasks.
897 /** This function is used to restart all science tasks.
898 *
898 *
899 * @return RTEMS directive status codes:
899 * @return RTEMS directive status codes:
900 * - RTEMS_SUCCESSFUL - task restarted successfully
900 * - RTEMS_SUCCESSFUL - task restarted successfully
901 * - RTEMS_INVALID_ID - task id invalid
901 * - RTEMS_INVALID_ID - task id invalid
902 * - RTEMS_INCORRECT_STATE - task never started
902 * - RTEMS_INCORRECT_STATE - task never started
903 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
903 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
904 *
904 *
905 * Science tasks are AVF0, PRC0, WFRM, CWF3, CW2, CWF1
905 * Science tasks are AVF0, PRC0, WFRM, CWF3, CW2, CWF1
906 *
906 *
907 */
907 */
908
908
909 rtems_status_code status[10];
909 rtems_status_code status[NB_SCIENCE_TASKS];
910 rtems_status_code ret;
910 rtems_status_code ret;
911
911
912 ret = RTEMS_SUCCESSFUL;
912 ret = RTEMS_SUCCESSFUL;
913
913
914 status[0] = rtems_task_restart( Task_id[TASKID_AVF0], lfrRequestedMode );
914 status[STATUS_0] = rtems_task_restart( Task_id[TASKID_AVF0], lfrRequestedMode );
915 if (status[0] != RTEMS_SUCCESSFUL)
915 if (status[STATUS_0] != RTEMS_SUCCESSFUL)
916 {
916 {
917 PRINTF1("in restart_science_task *** AVF0 ERR %d\n", status[0])
917 PRINTF1("in restart_science_task *** AVF0 ERR %d\n", status[STATUS_0])
918 }
918 }
919
919
920 status[1] = rtems_task_restart( Task_id[TASKID_PRC0], lfrRequestedMode );
920 status[STATUS_1] = rtems_task_restart( Task_id[TASKID_PRC0], lfrRequestedMode );
921 if (status[1] != RTEMS_SUCCESSFUL)
921 if (status[STATUS_1] != RTEMS_SUCCESSFUL)
922 {
922 {
923 PRINTF1("in restart_science_task *** PRC0 ERR %d\n", status[1])
923 PRINTF1("in restart_science_task *** PRC0 ERR %d\n", status[STATUS_1])
924 }
924 }
925
925
926 status[2] = rtems_task_restart( Task_id[TASKID_WFRM],1 );
926 status[STATUS_2] = rtems_task_restart( Task_id[TASKID_WFRM],1 );
927 if (status[2] != RTEMS_SUCCESSFUL)
927 if (status[STATUS_2] != RTEMS_SUCCESSFUL)
928 {
928 {
929 PRINTF1("in restart_science_task *** WFRM ERR %d\n", status[2])
929 PRINTF1("in restart_science_task *** WFRM ERR %d\n", status[STATUS_2])
930 }
930 }
931
931
932 status[3] = rtems_task_restart( Task_id[TASKID_CWF3],1 );
932 status[STATUS_3] = rtems_task_restart( Task_id[TASKID_CWF3],1 );
933 if (status[3] != RTEMS_SUCCESSFUL)
933 if (status[STATUS_3] != RTEMS_SUCCESSFUL)
934 {
934 {
935 PRINTF1("in restart_science_task *** CWF3 ERR %d\n", status[3])
935 PRINTF1("in restart_science_task *** CWF3 ERR %d\n", status[STATUS_3])
936 }
936 }
937
937
938 status[4] = rtems_task_restart( Task_id[TASKID_CWF2],1 );
938 status[STATUS_4] = rtems_task_restart( Task_id[TASKID_CWF2],1 );
939 if (status[4] != RTEMS_SUCCESSFUL)
939 if (status[STATUS_4] != RTEMS_SUCCESSFUL)
940 {
940 {
941 PRINTF1("in restart_science_task *** CWF2 ERR %d\n", status[4])
941 PRINTF1("in restart_science_task *** CWF2 ERR %d\n", status[STATUS_4])
942 }
942 }
943
943
944 status[5] = rtems_task_restart( Task_id[TASKID_CWF1],1 );
944 status[STATUS_5] = rtems_task_restart( Task_id[TASKID_CWF1],1 );
945 if (status[5] != RTEMS_SUCCESSFUL)
945 if (status[STATUS_5] != RTEMS_SUCCESSFUL)
946 {
946 {
947 PRINTF1("in restart_science_task *** CWF1 ERR %d\n", status[5])
947 PRINTF1("in restart_science_task *** CWF1 ERR %d\n", status[STATUS_5])
948 }
948 }
949
949
950 status[6] = rtems_task_restart( Task_id[TASKID_AVF1], lfrRequestedMode );
950 status[STATUS_6] = rtems_task_restart( Task_id[TASKID_AVF1], lfrRequestedMode );
951 if (status[6] != RTEMS_SUCCESSFUL)
951 if (status[STATUS_6] != RTEMS_SUCCESSFUL)
952 {
952 {
953 PRINTF1("in restart_science_task *** AVF1 ERR %d\n", status[6])
953 PRINTF1("in restart_science_task *** AVF1 ERR %d\n", status[STATUS_6])
954 }
954 }
955
955
956 status[7] = rtems_task_restart( Task_id[TASKID_PRC1],lfrRequestedMode );
956 status[STATUS_7] = rtems_task_restart( Task_id[TASKID_PRC1],lfrRequestedMode );
957 if (status[7] != RTEMS_SUCCESSFUL)
957 if (status[STATUS_7] != RTEMS_SUCCESSFUL)
958 {
958 {
959 PRINTF1("in restart_science_task *** PRC1 ERR %d\n", status[7])
959 PRINTF1("in restart_science_task *** PRC1 ERR %d\n", status[STATUS_7])
960 }
960 }
961
961
962 status[8] = rtems_task_restart( Task_id[TASKID_AVF2], 1 );
962 status[STATUS_8] = rtems_task_restart( Task_id[TASKID_AVF2], 1 );
963 if (status[8] != RTEMS_SUCCESSFUL)
963 if (status[STATUS_8] != RTEMS_SUCCESSFUL)
964 {
964 {
965 PRINTF1("in restart_science_task *** AVF2 ERR %d\n", status[8])
965 PRINTF1("in restart_science_task *** AVF2 ERR %d\n", status[STATUS_8])
966 }
966 }
967
967
968 status[9] = rtems_task_restart( Task_id[TASKID_PRC2], 1 );
968 status[STATUS_9] = rtems_task_restart( Task_id[TASKID_PRC2], 1 );
969 if (status[9] != RTEMS_SUCCESSFUL)
969 if (status[STATUS_9] != RTEMS_SUCCESSFUL)
970 {
970 {
971 PRINTF1("in restart_science_task *** PRC2 ERR %d\n", status[9])
971 PRINTF1("in restart_science_task *** PRC2 ERR %d\n", status[STATUS_9])
972 }
972 }
973
973
974 if ( (status[0] != RTEMS_SUCCESSFUL) || (status[1] != RTEMS_SUCCESSFUL) ||
974 if ( (status[STATUS_0] != RTEMS_SUCCESSFUL) || (status[STATUS_1] != RTEMS_SUCCESSFUL) ||
975 (status[2] != RTEMS_SUCCESSFUL) || (status[3] != RTEMS_SUCCESSFUL) ||
975 (status[STATUS_2] != RTEMS_SUCCESSFUL) || (status[STATUS_3] != RTEMS_SUCCESSFUL) ||
976 (status[4] != RTEMS_SUCCESSFUL) || (status[5] != RTEMS_SUCCESSFUL) ||
976 (status[STATUS_4] != RTEMS_SUCCESSFUL) || (status[STATUS_5] != RTEMS_SUCCESSFUL) ||
977 (status[6] != RTEMS_SUCCESSFUL) || (status[7] != RTEMS_SUCCESSFUL) ||
977 (status[STATUS_6] != RTEMS_SUCCESSFUL) || (status[STATUS_7] != RTEMS_SUCCESSFUL) ||
978 (status[8] != RTEMS_SUCCESSFUL) || (status[9] != RTEMS_SUCCESSFUL) )
978 (status[STATUS_8] != RTEMS_SUCCESSFUL) || (status[STATUS_9] != RTEMS_SUCCESSFUL) )
979 {
979 {
980 ret = RTEMS_UNSATISFIED;
980 ret = RTEMS_UNSATISFIED;
981 }
981 }
982
982
983 return ret;
983 return ret;
984 }
984 }
985
985
986 int restart_asm_tasks( unsigned char lfrRequestedMode )
986 int restart_asm_tasks( unsigned char lfrRequestedMode )
987 {
987 {
988 /** This function is used to restart average spectral matrices tasks.
988 /** This function is used to restart average spectral matrices tasks.
989 *
989 *
990 * @return RTEMS directive status codes:
990 * @return RTEMS directive status codes:
991 * - RTEMS_SUCCESSFUL - task restarted successfully
991 * - RTEMS_SUCCESSFUL - task restarted successfully
992 * - RTEMS_INVALID_ID - task id invalid
992 * - RTEMS_INVALID_ID - task id invalid
993 * - RTEMS_INCORRECT_STATE - task never started
993 * - RTEMS_INCORRECT_STATE - task never started
994 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
994 * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task
995 *
995 *
996 * ASM tasks are AVF0, PRC0, AVF1, PRC1, AVF2 and PRC2
996 * ASM tasks are AVF0, PRC0, AVF1, PRC1, AVF2 and PRC2
997 *
997 *
998 */
998 */
999
999
1000 rtems_status_code status[6];
1000 rtems_status_code status[NB_ASM_TASKS];
1001 rtems_status_code ret;
1001 rtems_status_code ret;
1002
1002
1003 ret = RTEMS_SUCCESSFUL;
1003 ret = RTEMS_SUCCESSFUL;
1004
1004
1005 status[0] = rtems_task_restart( Task_id[TASKID_AVF0], lfrRequestedMode );
1005 status[STATUS_0] = rtems_task_restart( Task_id[TASKID_AVF0], lfrRequestedMode );
1006 if (status[0] != RTEMS_SUCCESSFUL)
1006 if (status[STATUS_0] != RTEMS_SUCCESSFUL)
1007 {
1007 {
1008 PRINTF1("in restart_science_task *** AVF0 ERR %d\n", status[0])
1008 PRINTF1("in restart_science_task *** AVF0 ERR %d\n", status[STATUS_0])
1009 }
1009 }
1010
1010
1011 status[1] = rtems_task_restart( Task_id[TASKID_PRC0], lfrRequestedMode );
1011 status[STATUS_1] = rtems_task_restart( Task_id[TASKID_PRC0], lfrRequestedMode );
1012 if (status[1] != RTEMS_SUCCESSFUL)
1012 if (status[STATUS_1] != RTEMS_SUCCESSFUL)
1013 {
1013 {
1014 PRINTF1("in restart_science_task *** PRC0 ERR %d\n", status[1])
1014 PRINTF1("in restart_science_task *** PRC0 ERR %d\n", status[STATUS_1])
1015 }
1015 }
1016
1016
1017 status[2] = rtems_task_restart( Task_id[TASKID_AVF1], lfrRequestedMode );
1017 status[STATUS_2] = rtems_task_restart( Task_id[TASKID_AVF1], lfrRequestedMode );
1018 if (status[2] != RTEMS_SUCCESSFUL)
1018 if (status[STATUS_2] != RTEMS_SUCCESSFUL)
1019 {
1019 {
1020 PRINTF1("in restart_science_task *** AVF1 ERR %d\n", status[2])
1020 PRINTF1("in restart_science_task *** AVF1 ERR %d\n", status[STATUS_2])
1021 }
1021 }
1022
1022
1023 status[3] = rtems_task_restart( Task_id[TASKID_PRC1],lfrRequestedMode );
1023 status[STATUS_3] = rtems_task_restart( Task_id[TASKID_PRC1],lfrRequestedMode );
1024 if (status[3] != RTEMS_SUCCESSFUL)
1024 if (status[STATUS_3] != RTEMS_SUCCESSFUL)
1025 {
1025 {
1026 PRINTF1("in restart_science_task *** PRC1 ERR %d\n", status[3])
1026 PRINTF1("in restart_science_task *** PRC1 ERR %d\n", status[STATUS_3])
1027 }
1027 }
1028
1028
1029 status[4] = rtems_task_restart( Task_id[TASKID_AVF2], 1 );
1029 status[STATUS_4] = rtems_task_restart( Task_id[TASKID_AVF2], 1 );
1030 if (status[4] != RTEMS_SUCCESSFUL)
1030 if (status[STATUS_4] != RTEMS_SUCCESSFUL)
1031 {
1031 {
1032 PRINTF1("in restart_science_task *** AVF2 ERR %d\n", status[4])
1032 PRINTF1("in restart_science_task *** AVF2 ERR %d\n", status[STATUS_4])
1033 }
1033 }
1034
1034
1035 status[5] = rtems_task_restart( Task_id[TASKID_PRC2], 1 );
1035 status[STATUS_5] = rtems_task_restart( Task_id[TASKID_PRC2], 1 );
1036 if (status[5] != RTEMS_SUCCESSFUL)
1036 if (status[STATUS_5] != RTEMS_SUCCESSFUL)
1037 {
1037 {
1038 PRINTF1("in restart_science_task *** PRC2 ERR %d\n", status[5])
1038 PRINTF1("in restart_science_task *** PRC2 ERR %d\n", status[STATUS_5])
1039 }
1039 }
1040
1040
1041 if ( (status[0] != RTEMS_SUCCESSFUL) || (status[1] != RTEMS_SUCCESSFUL) ||
1041 if ( (status[STATUS_0] != RTEMS_SUCCESSFUL) || (status[STATUS_1] != RTEMS_SUCCESSFUL) ||
1042 (status[2] != RTEMS_SUCCESSFUL) || (status[3] != RTEMS_SUCCESSFUL) ||
1042 (status[STATUS_2] != RTEMS_SUCCESSFUL) || (status[STATUS_3] != RTEMS_SUCCESSFUL) ||
1043 (status[4] != RTEMS_SUCCESSFUL) || (status[5] != RTEMS_SUCCESSFUL) )
1043 (status[STATUS_4] != RTEMS_SUCCESSFUL) || (status[STATUS_5] != RTEMS_SUCCESSFUL) )
1044 {
1044 {
1045 ret = RTEMS_UNSATISFIED;
1045 ret = RTEMS_UNSATISFIED;
1046 }
1046 }
1047
1047
1048 return ret;
1048 return ret;
1049 }
1049 }
1050
1050
1051 int suspend_science_tasks( void )
1051 int suspend_science_tasks( void )
1052 {
1052 {
1053 /** This function suspends the science tasks.
1053 /** This function suspends the science tasks.
1054 *
1054 *
1055 * @return RTEMS directive status codes:
1055 * @return RTEMS directive status codes:
1056 * - RTEMS_SUCCESSFUL - task restarted successfully
1056 * - RTEMS_SUCCESSFUL - task restarted successfully
1057 * - RTEMS_INVALID_ID - task id invalid
1057 * - RTEMS_INVALID_ID - task id invalid
1058 * - RTEMS_ALREADY_SUSPENDED - task already suspended
1058 * - RTEMS_ALREADY_SUSPENDED - task already suspended
1059 *
1059 *
1060 */
1060 */
1061
1061
1062 rtems_status_code status;
1062 rtems_status_code status;
1063
1063
1064 PRINTF("in suspend_science_tasks\n")
1064 PRINTF("in suspend_science_tasks\n")
1065
1065
1066 status = rtems_task_suspend( Task_id[TASKID_AVF0] ); // suspend AVF0
1066 status = rtems_task_suspend( Task_id[TASKID_AVF0] ); // suspend AVF0
1067 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1067 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1068 {
1068 {
1069 PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status)
1069 PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status)
1070 }
1070 }
1071 else
1071 else
1072 {
1072 {
1073 status = RTEMS_SUCCESSFUL;
1073 status = RTEMS_SUCCESSFUL;
1074 }
1074 }
1075 if (status == RTEMS_SUCCESSFUL) // suspend PRC0
1075 if (status == RTEMS_SUCCESSFUL) // suspend PRC0
1076 {
1076 {
1077 status = rtems_task_suspend( Task_id[TASKID_PRC0] );
1077 status = rtems_task_suspend( Task_id[TASKID_PRC0] );
1078 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1078 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1079 {
1079 {
1080 PRINTF1("in suspend_science_task *** PRC0 ERR %d\n", status)
1080 PRINTF1("in suspend_science_task *** PRC0 ERR %d\n", status)
1081 }
1081 }
1082 else
1082 else
1083 {
1083 {
1084 status = RTEMS_SUCCESSFUL;
1084 status = RTEMS_SUCCESSFUL;
1085 }
1085 }
1086 }
1086 }
1087 if (status == RTEMS_SUCCESSFUL) // suspend AVF1
1087 if (status == RTEMS_SUCCESSFUL) // suspend AVF1
1088 {
1088 {
1089 status = rtems_task_suspend( Task_id[TASKID_AVF1] );
1089 status = rtems_task_suspend( Task_id[TASKID_AVF1] );
1090 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1090 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1091 {
1091 {
1092 PRINTF1("in suspend_science_task *** AVF1 ERR %d\n", status)
1092 PRINTF1("in suspend_science_task *** AVF1 ERR %d\n", status)
1093 }
1093 }
1094 else
1094 else
1095 {
1095 {
1096 status = RTEMS_SUCCESSFUL;
1096 status = RTEMS_SUCCESSFUL;
1097 }
1097 }
1098 }
1098 }
1099 if (status == RTEMS_SUCCESSFUL) // suspend PRC1
1099 if (status == RTEMS_SUCCESSFUL) // suspend PRC1
1100 {
1100 {
1101 status = rtems_task_suspend( Task_id[TASKID_PRC1] );
1101 status = rtems_task_suspend( Task_id[TASKID_PRC1] );
1102 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1102 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1103 {
1103 {
1104 PRINTF1("in suspend_science_task *** PRC1 ERR %d\n", status)
1104 PRINTF1("in suspend_science_task *** PRC1 ERR %d\n", status)
1105 }
1105 }
1106 else
1106 else
1107 {
1107 {
1108 status = RTEMS_SUCCESSFUL;
1108 status = RTEMS_SUCCESSFUL;
1109 }
1109 }
1110 }
1110 }
1111 if (status == RTEMS_SUCCESSFUL) // suspend AVF2
1111 if (status == RTEMS_SUCCESSFUL) // suspend AVF2
1112 {
1112 {
1113 status = rtems_task_suspend( Task_id[TASKID_AVF2] );
1113 status = rtems_task_suspend( Task_id[TASKID_AVF2] );
1114 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1114 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1115 {
1115 {
1116 PRINTF1("in suspend_science_task *** AVF2 ERR %d\n", status)
1116 PRINTF1("in suspend_science_task *** AVF2 ERR %d\n", status)
1117 }
1117 }
1118 else
1118 else
1119 {
1119 {
1120 status = RTEMS_SUCCESSFUL;
1120 status = RTEMS_SUCCESSFUL;
1121 }
1121 }
1122 }
1122 }
1123 if (status == RTEMS_SUCCESSFUL) // suspend PRC2
1123 if (status == RTEMS_SUCCESSFUL) // suspend PRC2
1124 {
1124 {
1125 status = rtems_task_suspend( Task_id[TASKID_PRC2] );
1125 status = rtems_task_suspend( Task_id[TASKID_PRC2] );
1126 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1126 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1127 {
1127 {
1128 PRINTF1("in suspend_science_task *** PRC2 ERR %d\n", status)
1128 PRINTF1("in suspend_science_task *** PRC2 ERR %d\n", status)
1129 }
1129 }
1130 else
1130 else
1131 {
1131 {
1132 status = RTEMS_SUCCESSFUL;
1132 status = RTEMS_SUCCESSFUL;
1133 }
1133 }
1134 }
1134 }
1135 if (status == RTEMS_SUCCESSFUL) // suspend WFRM
1135 if (status == RTEMS_SUCCESSFUL) // suspend WFRM
1136 {
1136 {
1137 status = rtems_task_suspend( Task_id[TASKID_WFRM] );
1137 status = rtems_task_suspend( Task_id[TASKID_WFRM] );
1138 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1138 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1139 {
1139 {
1140 PRINTF1("in suspend_science_task *** WFRM ERR %d\n", status)
1140 PRINTF1("in suspend_science_task *** WFRM ERR %d\n", status)
1141 }
1141 }
1142 else
1142 else
1143 {
1143 {
1144 status = RTEMS_SUCCESSFUL;
1144 status = RTEMS_SUCCESSFUL;
1145 }
1145 }
1146 }
1146 }
1147 if (status == RTEMS_SUCCESSFUL) // suspend CWF3
1147 if (status == RTEMS_SUCCESSFUL) // suspend CWF3
1148 {
1148 {
1149 status = rtems_task_suspend( Task_id[TASKID_CWF3] );
1149 status = rtems_task_suspend( Task_id[TASKID_CWF3] );
1150 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1150 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1151 {
1151 {
1152 PRINTF1("in suspend_science_task *** CWF3 ERR %d\n", status)
1152 PRINTF1("in suspend_science_task *** CWF3 ERR %d\n", status)
1153 }
1153 }
1154 else
1154 else
1155 {
1155 {
1156 status = RTEMS_SUCCESSFUL;
1156 status = RTEMS_SUCCESSFUL;
1157 }
1157 }
1158 }
1158 }
1159 if (status == RTEMS_SUCCESSFUL) // suspend CWF2
1159 if (status == RTEMS_SUCCESSFUL) // suspend CWF2
1160 {
1160 {
1161 status = rtems_task_suspend( Task_id[TASKID_CWF2] );
1161 status = rtems_task_suspend( Task_id[TASKID_CWF2] );
1162 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1162 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1163 {
1163 {
1164 PRINTF1("in suspend_science_task *** CWF2 ERR %d\n", status)
1164 PRINTF1("in suspend_science_task *** CWF2 ERR %d\n", status)
1165 }
1165 }
1166 else
1166 else
1167 {
1167 {
1168 status = RTEMS_SUCCESSFUL;
1168 status = RTEMS_SUCCESSFUL;
1169 }
1169 }
1170 }
1170 }
1171 if (status == RTEMS_SUCCESSFUL) // suspend CWF1
1171 if (status == RTEMS_SUCCESSFUL) // suspend CWF1
1172 {
1172 {
1173 status = rtems_task_suspend( Task_id[TASKID_CWF1] );
1173 status = rtems_task_suspend( Task_id[TASKID_CWF1] );
1174 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1174 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1175 {
1175 {
1176 PRINTF1("in suspend_science_task *** CWF1 ERR %d\n", status)
1176 PRINTF1("in suspend_science_task *** CWF1 ERR %d\n", status)
1177 }
1177 }
1178 else
1178 else
1179 {
1179 {
1180 status = RTEMS_SUCCESSFUL;
1180 status = RTEMS_SUCCESSFUL;
1181 }
1181 }
1182 }
1182 }
1183
1183
1184 return status;
1184 return status;
1185 }
1185 }
1186
1186
1187 int suspend_asm_tasks( void )
1187 int suspend_asm_tasks( void )
1188 {
1188 {
1189 /** This function suspends the science tasks.
1189 /** This function suspends the science tasks.
1190 *
1190 *
1191 * @return RTEMS directive status codes:
1191 * @return RTEMS directive status codes:
1192 * - RTEMS_SUCCESSFUL - task restarted successfully
1192 * - RTEMS_SUCCESSFUL - task restarted successfully
1193 * - RTEMS_INVALID_ID - task id invalid
1193 * - RTEMS_INVALID_ID - task id invalid
1194 * - RTEMS_ALREADY_SUSPENDED - task already suspended
1194 * - RTEMS_ALREADY_SUSPENDED - task already suspended
1195 *
1195 *
1196 */
1196 */
1197
1197
1198 rtems_status_code status;
1198 rtems_status_code status;
1199
1199
1200 PRINTF("in suspend_science_tasks\n")
1200 PRINTF("in suspend_science_tasks\n")
1201
1201
1202 status = rtems_task_suspend( Task_id[TASKID_AVF0] ); // suspend AVF0
1202 status = rtems_task_suspend( Task_id[TASKID_AVF0] ); // suspend AVF0
1203 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1203 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1204 {
1204 {
1205 PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status)
1205 PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status)
1206 }
1206 }
1207 else
1207 else
1208 {
1208 {
1209 status = RTEMS_SUCCESSFUL;
1209 status = RTEMS_SUCCESSFUL;
1210 }
1210 }
1211
1211
1212 if (status == RTEMS_SUCCESSFUL) // suspend PRC0
1212 if (status == RTEMS_SUCCESSFUL) // suspend PRC0
1213 {
1213 {
1214 status = rtems_task_suspend( Task_id[TASKID_PRC0] );
1214 status = rtems_task_suspend( Task_id[TASKID_PRC0] );
1215 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1215 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1216 {
1216 {
1217 PRINTF1("in suspend_science_task *** PRC0 ERR %d\n", status)
1217 PRINTF1("in suspend_science_task *** PRC0 ERR %d\n", status)
1218 }
1218 }
1219 else
1219 else
1220 {
1220 {
1221 status = RTEMS_SUCCESSFUL;
1221 status = RTEMS_SUCCESSFUL;
1222 }
1222 }
1223 }
1223 }
1224
1224
1225 if (status == RTEMS_SUCCESSFUL) // suspend AVF1
1225 if (status == RTEMS_SUCCESSFUL) // suspend AVF1
1226 {
1226 {
1227 status = rtems_task_suspend( Task_id[TASKID_AVF1] );
1227 status = rtems_task_suspend( Task_id[TASKID_AVF1] );
1228 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1228 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1229 {
1229 {
1230 PRINTF1("in suspend_science_task *** AVF1 ERR %d\n", status)
1230 PRINTF1("in suspend_science_task *** AVF1 ERR %d\n", status)
1231 }
1231 }
1232 else
1232 else
1233 {
1233 {
1234 status = RTEMS_SUCCESSFUL;
1234 status = RTEMS_SUCCESSFUL;
1235 }
1235 }
1236 }
1236 }
1237
1237
1238 if (status == RTEMS_SUCCESSFUL) // suspend PRC1
1238 if (status == RTEMS_SUCCESSFUL) // suspend PRC1
1239 {
1239 {
1240 status = rtems_task_suspend( Task_id[TASKID_PRC1] );
1240 status = rtems_task_suspend( Task_id[TASKID_PRC1] );
1241 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1241 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1242 {
1242 {
1243 PRINTF1("in suspend_science_task *** PRC1 ERR %d\n", status)
1243 PRINTF1("in suspend_science_task *** PRC1 ERR %d\n", status)
1244 }
1244 }
1245 else
1245 else
1246 {
1246 {
1247 status = RTEMS_SUCCESSFUL;
1247 status = RTEMS_SUCCESSFUL;
1248 }
1248 }
1249 }
1249 }
1250
1250
1251 if (status == RTEMS_SUCCESSFUL) // suspend AVF2
1251 if (status == RTEMS_SUCCESSFUL) // suspend AVF2
1252 {
1252 {
1253 status = rtems_task_suspend( Task_id[TASKID_AVF2] );
1253 status = rtems_task_suspend( Task_id[TASKID_AVF2] );
1254 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1254 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1255 {
1255 {
1256 PRINTF1("in suspend_science_task *** AVF2 ERR %d\n", status)
1256 PRINTF1("in suspend_science_task *** AVF2 ERR %d\n", status)
1257 }
1257 }
1258 else
1258 else
1259 {
1259 {
1260 status = RTEMS_SUCCESSFUL;
1260 status = RTEMS_SUCCESSFUL;
1261 }
1261 }
1262 }
1262 }
1263
1263
1264 if (status == RTEMS_SUCCESSFUL) // suspend PRC2
1264 if (status == RTEMS_SUCCESSFUL) // suspend PRC2
1265 {
1265 {
1266 status = rtems_task_suspend( Task_id[TASKID_PRC2] );
1266 status = rtems_task_suspend( Task_id[TASKID_PRC2] );
1267 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1267 if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED))
1268 {
1268 {
1269 PRINTF1("in suspend_science_task *** PRC2 ERR %d\n", status)
1269 PRINTF1("in suspend_science_task *** PRC2 ERR %d\n", status)
1270 }
1270 }
1271 else
1271 else
1272 {
1272 {
1273 status = RTEMS_SUCCESSFUL;
1273 status = RTEMS_SUCCESSFUL;
1274 }
1274 }
1275 }
1275 }
1276
1276
1277 return status;
1277 return status;
1278 }
1278 }
1279
1279
1280 void launch_waveform_picker( unsigned char mode, unsigned int transitionCoarseTime )
1280 void launch_waveform_picker( unsigned char mode, unsigned int transitionCoarseTime )
1281 {
1281 {
1282
1282
1283 WFP_reset_current_ring_nodes();
1283 WFP_reset_current_ring_nodes();
1284
1284
1285 reset_waveform_picker_regs();
1285 reset_waveform_picker_regs();
1286
1286
1287 set_wfp_burst_enable_register( mode );
1287 set_wfp_burst_enable_register( mode );
1288
1288
1289 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER );
1289 LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER );
1290 LEON_Unmask_interrupt( IRQ_WAVEFORM_PICKER );
1290 LEON_Unmask_interrupt( IRQ_WAVEFORM_PICKER );
1291
1291
1292 if (transitionCoarseTime == 0)
1292 if (transitionCoarseTime == 0)
1293 {
1293 {
1294 // instant transition means transition on the next valid date
1294 // instant transition means transition on the next valid date
1295 // this is mandatory to have a good snapshot period and a good correction of the snapshot period
1295 // this is mandatory to have a good snapshot period and a good correction of the snapshot period
1296 waveform_picker_regs->start_date = time_management_regs->coarse_time + 1;
1296 waveform_picker_regs->start_date = time_management_regs->coarse_time + 1;
1297 }
1297 }
1298 else
1298 else
1299 {
1299 {
1300 waveform_picker_regs->start_date = transitionCoarseTime;
1300 waveform_picker_regs->start_date = transitionCoarseTime;
1301 }
1301 }
1302
1302
1303 update_last_valid_transition_date(waveform_picker_regs->start_date);
1303 update_last_valid_transition_date(waveform_picker_regs->start_date);
1304
1304
1305 }
1305 }
1306
1306
1307 void launch_spectral_matrix( void )
1307 void launch_spectral_matrix( void )
1308 {
1308 {
1309 SM_reset_current_ring_nodes();
1309 SM_reset_current_ring_nodes();
1310
1310
1311 reset_spectral_matrix_regs();
1311 reset_spectral_matrix_regs();
1312
1312
1313 reset_nb_sm();
1313 reset_nb_sm();
1314
1314
1315 set_sm_irq_onNewMatrix( 1 );
1315 set_sm_irq_onNewMatrix( 1 );
1316
1316
1317 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX );
1317 LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX );
1318 LEON_Unmask_interrupt( IRQ_SPECTRAL_MATRIX );
1318 LEON_Unmask_interrupt( IRQ_SPECTRAL_MATRIX );
1319
1319
1320 }
1320 }
1321
1321
1322 void set_sm_irq_onNewMatrix( unsigned char value )
1322 void set_sm_irq_onNewMatrix( unsigned char value )
1323 {
1323 {
1324 if (value == 1)
1324 if (value == 1)
1325 {
1325 {
1326 spectral_matrix_regs->config = spectral_matrix_regs->config | 0x01;
1326 spectral_matrix_regs->config = spectral_matrix_regs->config | BIT_IRQ_ON_NEW_MATRIX;
1327 }
1327 }
1328 else
1328 else
1329 {
1329 {
1330 spectral_matrix_regs->config = spectral_matrix_regs->config & 0xfffffffe; // 1110
1330 spectral_matrix_regs->config = spectral_matrix_regs->config & MASK_IRQ_ON_NEW_MATRIX; // 1110
1331 }
1331 }
1332 }
1332 }
1333
1333
1334 void set_sm_irq_onError( unsigned char value )
1334 void set_sm_irq_onError( unsigned char value )
1335 {
1335 {
1336 if (value == 1)
1336 if (value == 1)
1337 {
1337 {
1338 spectral_matrix_regs->config = spectral_matrix_regs->config | 0x02;
1338 spectral_matrix_regs->config = spectral_matrix_regs->config | BIT_IRQ_ON_ERROR;
1339 }
1339 }
1340 else
1340 else
1341 {
1341 {
1342 spectral_matrix_regs->config = spectral_matrix_regs->config & 0xfffffffd; // 1101
1342 spectral_matrix_regs->config = spectral_matrix_regs->config & MASK_IRQ_ON_ERROR; // 1101
1343 }
1343 }
1344 }
1344 }
1345
1345
1346 //*****************************
1346 //*****************************
1347 // CONFIGURE CALIBRATION SIGNAL
1347 // CONFIGURE CALIBRATION SIGNAL
1348 void setCalibrationPrescaler( unsigned int prescaler )
1348 void setCalibrationPrescaler( unsigned int prescaler )
1349 {
1349 {
1350 // prescaling of the master clock (25 MHz)
1350 // prescaling of the master clock (25 MHz)
1351 // master clock is divided by 2^prescaler
1351 // master clock is divided by 2^prescaler
1352 time_management_regs->calPrescaler = prescaler;
1352 time_management_regs->calPrescaler = prescaler;
1353 }
1353 }
1354
1354
1355 void setCalibrationDivisor( unsigned int divisionFactor )
1355 void setCalibrationDivisor( unsigned int divisionFactor )
1356 {
1356 {
1357 // division of the prescaled clock by the division factor
1357 // division of the prescaled clock by the division factor
1358 time_management_regs->calDivisor = divisionFactor;
1358 time_management_regs->calDivisor = divisionFactor;
1359 }
1359 }
1360
1360
1361 void setCalibrationData( void ){
1361 void setCalibrationData( void )
1362 {
1363 /** This function is used to store the values used to drive the DAC in order to generate the SCM calibration signal
1364 *
1365 * @param void
1366 *
1367 * @return void
1368 *
1369 */
1370
1362 unsigned int k;
1371 unsigned int k;
1363 unsigned short data;
1372 unsigned short data;
1364 float val;
1373 float val;
1365 float f0;
1366 float f1;
1367 float fs;
1368 float Ts;
1374 float Ts;
1369 float scaleFactor;
1370
1375
1371 f0 = 625;
1376 time_management_regs->calDataPtr = INIT_CHAR;
1372 f1 = 10000;
1373 fs = 160256.410;
1374 Ts = 1. / fs;
1375 scaleFactor = 0.250 / 0.000654; // 191, 500 mVpp, 2 sinus waves => 500 mVpp each, amplitude = 250 mV
1376
1377 time_management_regs->calDataPtr = 0x00;
1378
1377
1379 // build the signal for the SCM calibration
1378 // build the signal for the SCM calibration
1380 for (k=0; k<256; k++)
1379 for (k = 0; k < CAL_NB_PTS; k++)
1381 {
1380 {
1382 val = sin( 2 * pi * f0 * k * Ts )
1381 val = sin( 2 * pi * CAL_F0 * k * Ts )
1383 + sin( 2 * pi * f1 * k * Ts );
1382 + sin( 2 * pi * CAL_F1 * k * Ts );
1384 data = (unsigned short) ((val * scaleFactor) + 2048);
1383 data = (unsigned short) ((val * CAL_SCALE_FACTOR) + CONST_2048);
1385 time_management_regs->calData = data & 0xfff;
1384 time_management_regs->calData = data & CAL_DATA_MASK;
1386 }
1385 }
1387 }
1386 }
1388
1387
1389 void setCalibrationDataInterleaved( void ){
1388 void setCalibrationDataInterleaved( void )
1389 {
1390 /** This function is used to store the values used to drive the DAC in order to generate the SCM calibration signal
1391 *
1392 * @param void
1393 *
1394 * @return void
1395 *
1396 * In interleaved mode, one can store more values than in normal mode.
1397 * The data are stored in bunch of 18 bits, 12 bits from one sample and 6 bits from another sample.
1398 * T store 3 values, one need two write operations.
1399 * s1 [ b11 b10 b9 b8 b7 b6 ] s0 [ b11 b10 b9 b8 b7 b6 b5 b3 b2 b1 b0 ]
1400 * s1 [ b5 b4 b3 b2 b1 b0 ] s2 [ b11 b10 b9 b8 b7 b6 b5 b3 b2 b1 b0 ]
1401 *
1402 */
1403
1390 unsigned int k;
1404 unsigned int k;
1391 float val;
1405 float val;
1392 float f0;
1393 float f1;
1394 float fs;
1395 float Ts;
1406 float Ts;
1396 unsigned short data[384];
1407 unsigned short data[CAL_NB_PTS_INTER];
1397 unsigned char *dataPtr;
1408 unsigned char *dataPtr;
1398
1409
1399 f0 = 625;
1410 Ts = 1. / CAL_FS_INTER;
1400 f1 = 10000;
1401 fs = 240384.615;
1402 Ts = 1. / fs;
1403
1411
1404 time_management_regs->calDataPtr = 0x00;
1412 time_management_regs->calDataPtr = INIT_CHAR;
1405
1413
1406 // build the signal for the SCM calibration
1414 // build the signal for the SCM calibration
1407 for (k=0; k<384; k++)
1415 for (k=0; k<CAL_NB_PTS_INTER; k++)
1408 {
1416 {
1409 val = sin( 2 * pi * f0 * k * Ts )
1417 val = sin( 2 * pi * CAL_F0 * k * Ts )
1410 + sin( 2 * pi * f1 * k * Ts );
1418 + sin( 2 * pi * CAL_F1 * k * Ts );
1411 data[k] = (unsigned short) (val * 512 + 2048);
1419 data[k] = (unsigned short) ((val * CONST_512) + CONST_2048);
1412 }
1420 }
1413
1421
1414 // write the signal in interleaved mode
1422 // write the signal in interleaved mode
1415 for (k=0; k<128; k++)
1423 for (k=0; k < STEPS_FOR_STORAGE_INTER; k++)
1416 {
1424 {
1417 dataPtr = (unsigned char*) &data[k*3 + 2];
1425 dataPtr = (unsigned char*) &data[ (k * BYTES_FOR_2_SAMPLES) + 2 ];
1418 time_management_regs->calData = (data[k*3] & 0xfff)
1426 time_management_regs->calData = ( data[ k * BYTES_FOR_2_SAMPLES ] & CAL_DATA_MASK )
1419 + ( (dataPtr[0] & 0x3f) << 12);
1427 + ( (dataPtr[0] & CAL_DATA_MASK_INTER) << CAL_DATA_SHIFT_INTER);
1420 time_management_regs->calData = (data[k*3 + 1] & 0xfff)
1428 time_management_regs->calData = ( data[(k * BYTES_FOR_2_SAMPLES) + 1] & CAL_DATA_MASK )
1421 + ( (dataPtr[1] & 0x3f) << 12);
1429 + ( (dataPtr[1] & CAL_DATA_MASK_INTER) << CAL_DATA_SHIFT_INTER);
1422 }
1430 }
1423 }
1431 }
1424
1432
1425 void setCalibrationReload( bool state)
1433 void setCalibrationReload( bool state)
1426 {
1434 {
1427 if (state == true)
1435 if (state == true)
1428 {
1436 {
1429 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | 0x00000010; // [0001 0000]
1437 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | BIT_CAL_RELOAD; // [0001 0000]
1430 }
1438 }
1431 else
1439 else
1432 {
1440 {
1433 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & 0xffffffef; // [1110 1111]
1441 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & MASK_CAL_RELOAD; // [1110 1111]
1434 }
1442 }
1435 }
1443 }
1436
1444
1437 void setCalibrationEnable( bool state )
1445 void setCalibrationEnable( bool state )
1438 {
1446 {
1439 // this bit drives the multiplexer
1447 // this bit drives the multiplexer
1440 if (state == true)
1448 if (state == true)
1441 {
1449 {
1442 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | 0x00000040; // [0100 0000]
1450 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | BIT_CAL_ENABLE; // [0100 0000]
1443 }
1451 }
1444 else
1452 else
1445 {
1453 {
1446 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & 0xffffffbf; // [1011 1111]
1454 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & MASK_CAL_ENABLE; // [1011 1111]
1447 }
1455 }
1448 }
1456 }
1449
1457
1450 void setCalibrationInterleaved( bool state )
1458 void setCalibrationInterleaved( bool state )
1451 {
1459 {
1452 // this bit drives the multiplexer
1460 // this bit drives the multiplexer
1453 if (state == true)
1461 if (state == true)
1454 {
1462 {
1455 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | 0x00000020; // [0010 0000]
1463 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | BIT_SET_INTERLEAVED; // [0010 0000]
1456 }
1464 }
1457 else
1465 else
1458 {
1466 {
1459 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & 0xffffffdf; // [1101 1111]
1467 time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & MASK_SET_INTERLEAVED; // [1101 1111]
1460 }
1468 }
1461 }
1469 }
1462
1470
1463 void setCalibration( bool state )
1471 void setCalibration( bool state )
1464 {
1472 {
1465 if (state == true)
1473 if (state == true)
1466 {
1474 {
1467 setCalibrationEnable( true );
1475 setCalibrationEnable( true );
1468 setCalibrationReload( false );
1476 setCalibrationReload( false );
1469 set_hk_lfr_calib_enable( true );
1477 set_hk_lfr_calib_enable( true );
1470 }
1478 }
1471 else
1479 else
1472 {
1480 {
1473 setCalibrationEnable( false );
1481 setCalibrationEnable( false );
1474 setCalibrationReload( true );
1482 setCalibrationReload( true );
1475 set_hk_lfr_calib_enable( false );
1483 set_hk_lfr_calib_enable( false );
1476 }
1484 }
1477 }
1485 }
1478
1486
1479 void configureCalibration( bool interleaved )
1487 void configureCalibration( bool interleaved )
1480 {
1488 {
1481 setCalibration( false );
1489 setCalibration( false );
1482 if ( interleaved == true )
1490 if ( interleaved == true )
1483 {
1491 {
1484 setCalibrationInterleaved( true );
1492 setCalibrationInterleaved( true );
1485 setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000
1493 setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000
1486 setCalibrationDivisor( 26 ); // => 240 384
1494 setCalibrationDivisor( CAL_F_DIVISOR_INTER ); // => 240 384
1487 setCalibrationDataInterleaved();
1495 setCalibrationDataInterleaved();
1488 }
1496 }
1489 else
1497 else
1490 {
1498 {
1491 setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000
1499 setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000
1492 setCalibrationDivisor( 38 ); // => 160 256 (39 - 1)
1500 setCalibrationDivisor( CAL_F_DIVISOR ); // => 160 256 (39 - 1)
1493 setCalibrationData();
1501 setCalibrationData();
1494 }
1502 }
1495 }
1503 }
1496
1504
1497 //****************
1505 //****************
1498 // CLOSING ACTIONS
1506 // CLOSING ACTIONS
1499 void update_last_TC_exe( ccsdsTelecommandPacket_t *TC, unsigned char * time )
1507 void update_last_TC_exe( ccsdsTelecommandPacket_t *TC, unsigned char * time )
1500 {
1508 {
1501 /** This function is used to update the HK packets statistics after a successful TC execution.
1509 /** This function is used to update the HK packets statistics after a successful TC execution.
1502 *
1510 *
1503 * @param TC points to the TC being processed
1511 * @param TC points to the TC being processed
1504 * @param time is the time used to date the TC execution
1512 * @param time is the time used to date the TC execution
1505 *
1513 *
1506 */
1514 */
1507
1515
1508 unsigned int val;
1516 unsigned int val;
1509
1517
1510 housekeeping_packet.hk_lfr_last_exe_tc_id[0] = TC->packetID[0];
1518 housekeeping_packet.hk_lfr_last_exe_tc_id[0] = TC->packetID[0];
1511 housekeeping_packet.hk_lfr_last_exe_tc_id[1] = TC->packetID[1];
1519 housekeeping_packet.hk_lfr_last_exe_tc_id[1] = TC->packetID[1];
1512 housekeeping_packet.hk_lfr_last_exe_tc_type[0] = 0x00;
1520 housekeeping_packet.hk_lfr_last_exe_tc_type[0] = INIT_CHAR;
1513 housekeeping_packet.hk_lfr_last_exe_tc_type[1] = TC->serviceType;
1521 housekeeping_packet.hk_lfr_last_exe_tc_type[1] = TC->serviceType;
1514 housekeeping_packet.hk_lfr_last_exe_tc_subtype[0] = 0x00;
1522 housekeeping_packet.hk_lfr_last_exe_tc_subtype[0] = INIT_CHAR;
1515 housekeeping_packet.hk_lfr_last_exe_tc_subtype[1] = TC->serviceSubType;
1523 housekeeping_packet.hk_lfr_last_exe_tc_subtype[1] = TC->serviceSubType;
1516 housekeeping_packet.hk_lfr_last_exe_tc_time[0] = time[0];
1524 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_0] = time[BYTE_0];
1517 housekeeping_packet.hk_lfr_last_exe_tc_time[1] = time[1];
1525 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_1] = time[BYTE_1];
1518 housekeeping_packet.hk_lfr_last_exe_tc_time[2] = time[2];
1526 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_2] = time[BYTE_2];
1519 housekeeping_packet.hk_lfr_last_exe_tc_time[3] = time[3];
1527 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_3] = time[BYTE_3];
1520 housekeeping_packet.hk_lfr_last_exe_tc_time[4] = time[4];
1528 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_4] = time[BYTE_4];
1521 housekeeping_packet.hk_lfr_last_exe_tc_time[5] = time[5];
1529 housekeeping_packet.hk_lfr_last_exe_tc_time[BYTE_5] = time[BYTE_5];
1522
1530
1523 val = housekeeping_packet.hk_lfr_exe_tc_cnt[0] * 256 + housekeeping_packet.hk_lfr_exe_tc_cnt[1];
1531 val = (housekeeping_packet.hk_lfr_exe_tc_cnt[0] * CONST_256) + housekeeping_packet.hk_lfr_exe_tc_cnt[1];
1524 val++;
1532 val++;
1525 housekeeping_packet.hk_lfr_exe_tc_cnt[0] = (unsigned char) (val >> 8);
1533 housekeeping_packet.hk_lfr_exe_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE);
1526 housekeeping_packet.hk_lfr_exe_tc_cnt[1] = (unsigned char) (val);
1534 housekeeping_packet.hk_lfr_exe_tc_cnt[1] = (unsigned char) (val);
1527 }
1535 }
1528
1536
1529 void update_last_TC_rej(ccsdsTelecommandPacket_t *TC, unsigned char * time )
1537 void update_last_TC_rej(ccsdsTelecommandPacket_t *TC, unsigned char * time )
1530 {
1538 {
1531 /** This function is used to update the HK packets statistics after a TC rejection.
1539 /** This function is used to update the HK packets statistics after a TC rejection.
1532 *
1540 *
1533 * @param TC points to the TC being processed
1541 * @param TC points to the TC being processed
1534 * @param time is the time used to date the TC rejection
1542 * @param time is the time used to date the TC rejection
1535 *
1543 *
1536 */
1544 */
1537
1545
1538 unsigned int val;
1546 unsigned int val;
1539
1547
1540 housekeeping_packet.hk_lfr_last_rej_tc_id[0] = TC->packetID[0];
1548 housekeeping_packet.hk_lfr_last_rej_tc_id[0] = TC->packetID[0];
1541 housekeeping_packet.hk_lfr_last_rej_tc_id[1] = TC->packetID[1];
1549 housekeeping_packet.hk_lfr_last_rej_tc_id[1] = TC->packetID[1];
1542 housekeeping_packet.hk_lfr_last_rej_tc_type[0] = 0x00;
1550 housekeeping_packet.hk_lfr_last_rej_tc_type[0] = INIT_CHAR;
1543 housekeeping_packet.hk_lfr_last_rej_tc_type[1] = TC->serviceType;
1551 housekeeping_packet.hk_lfr_last_rej_tc_type[1] = TC->serviceType;
1544 housekeeping_packet.hk_lfr_last_rej_tc_subtype[0] = 0x00;
1552 housekeeping_packet.hk_lfr_last_rej_tc_subtype[0] = INIT_CHAR;
1545 housekeeping_packet.hk_lfr_last_rej_tc_subtype[1] = TC->serviceSubType;
1553 housekeeping_packet.hk_lfr_last_rej_tc_subtype[1] = TC->serviceSubType;
1546 housekeeping_packet.hk_lfr_last_rej_tc_time[0] = time[0];
1554 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_0] = time[BYTE_0];
1547 housekeeping_packet.hk_lfr_last_rej_tc_time[1] = time[1];
1555 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_1] = time[BYTE_1];
1548 housekeeping_packet.hk_lfr_last_rej_tc_time[2] = time[2];
1556 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_2] = time[BYTE_2];
1549 housekeeping_packet.hk_lfr_last_rej_tc_time[3] = time[3];
1557 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_3] = time[BYTE_3];
1550 housekeeping_packet.hk_lfr_last_rej_tc_time[4] = time[4];
1558 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_4] = time[BYTE_4];
1551 housekeeping_packet.hk_lfr_last_rej_tc_time[5] = time[5];
1559 housekeeping_packet.hk_lfr_last_rej_tc_time[BYTE_5] = time[BYTE_5];
1552
1560
1553 val = housekeeping_packet.hk_lfr_rej_tc_cnt[0] * 256 + housekeeping_packet.hk_lfr_rej_tc_cnt[1];
1561 val = (housekeeping_packet.hk_lfr_rej_tc_cnt[0] * CONST_256) + housekeeping_packet.hk_lfr_rej_tc_cnt[1];
1554 val++;
1562 val++;
1555 housekeeping_packet.hk_lfr_rej_tc_cnt[0] = (unsigned char) (val >> 8);
1563 housekeeping_packet.hk_lfr_rej_tc_cnt[0] = (unsigned char) (val >> SHIFT_1_BYTE);
1556 housekeeping_packet.hk_lfr_rej_tc_cnt[1] = (unsigned char) (val);
1564 housekeeping_packet.hk_lfr_rej_tc_cnt[1] = (unsigned char) (val);
1557 }
1565 }
1558
1566
1559 void close_action(ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id )
1567 void close_action(ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id )
1560 {
1568 {
1561 /** This function is the last step of the TC execution workflow.
1569 /** This function is the last step of the TC execution workflow.
1562 *
1570 *
1563 * @param TC points to the TC being processed
1571 * @param TC points to the TC being processed
1564 * @param result is the result of the TC execution (LFR_SUCCESSFUL / LFR_DEFAULT)
1572 * @param result is the result of the TC execution (LFR_SUCCESSFUL / LFR_DEFAULT)
1565 * @param queue_id is the id of the RTEMS message queue used to send TM packets
1573 * @param queue_id is the id of the RTEMS message queue used to send TM packets
1566 * @param time is the time used to date the TC execution
1574 * @param time is the time used to date the TC execution
1567 *
1575 *
1568 */
1576 */
1569
1577
1570 unsigned char requestedMode;
1578 unsigned char requestedMode;
1571
1579
1572 if (result == LFR_SUCCESSFUL)
1580 if (result == LFR_SUCCESSFUL)
1573 {
1581 {
1574 if ( !( (TC->serviceType==TC_TYPE_TIME) & (TC->serviceSubType==TC_SUBTYPE_UPDT_TIME) )
1582 if ( !( (TC->serviceType==TC_TYPE_TIME) & (TC->serviceSubType==TC_SUBTYPE_UPDT_TIME) )
1575 &
1583 &
1576 !( (TC->serviceType==TC_TYPE_GEN) & (TC->serviceSubType==TC_SUBTYPE_UPDT_INFO))
1584 !( (TC->serviceType==TC_TYPE_GEN) & (TC->serviceSubType==TC_SUBTYPE_UPDT_INFO))
1577 )
1585 )
1578 {
1586 {
1579 send_tm_lfr_tc_exe_success( TC, queue_id );
1587 send_tm_lfr_tc_exe_success( TC, queue_id );
1580 }
1588 }
1581 if ( (TC->serviceType == TC_TYPE_GEN) & (TC->serviceSubType == TC_SUBTYPE_ENTER) )
1589 if ( (TC->serviceType == TC_TYPE_GEN) & (TC->serviceSubType == TC_SUBTYPE_ENTER) )
1582 {
1590 {
1583 //**********************************
1591 //**********************************
1584 // UPDATE THE LFRMODE LOCAL VARIABLE
1592 // UPDATE THE LFRMODE LOCAL VARIABLE
1585 requestedMode = TC->dataAndCRC[1];
1593 requestedMode = TC->dataAndCRC[1];
1586 updateLFRCurrentMode( requestedMode );
1594 updateLFRCurrentMode( requestedMode );
1587 }
1595 }
1588 }
1596 }
1589 else if (result == LFR_EXE_ERROR)
1597 else if (result == LFR_EXE_ERROR)
1590 {
1598 {
1591 send_tm_lfr_tc_exe_error( TC, queue_id );
1599 send_tm_lfr_tc_exe_error( TC, queue_id );
1592 }
1600 }
1593 }
1601 }
1594
1602
1595 //***************************
1603 //***************************
1596 // Interrupt Service Routines
1604 // Interrupt Service Routines
1597 rtems_isr commutation_isr1( rtems_vector_number vector )
1605 rtems_isr commutation_isr1( rtems_vector_number vector )
1598 {
1606 {
1599 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
1607 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
1600 PRINTF("In commutation_isr1 *** Error sending event to DUMB\n")
1608 PRINTF("In commutation_isr1 *** Error sending event to DUMB\n")
1601 }
1609 }
1602 }
1610 }
1603
1611
1604 rtems_isr commutation_isr2( rtems_vector_number vector )
1612 rtems_isr commutation_isr2( rtems_vector_number vector )
1605 {
1613 {
1606 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
1614 if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
1607 PRINTF("In commutation_isr2 *** Error sending event to DUMB\n")
1615 PRINTF("In commutation_isr2 *** Error sending event to DUMB\n")
1608 }
1616 }
1609 }
1617 }
1610
1618
1611 //****************
1619 //****************
1612 // OTHER FUNCTIONS
1620 // OTHER FUNCTIONS
1613 void updateLFRCurrentMode( unsigned char requestedMode )
1621 void updateLFRCurrentMode( unsigned char requestedMode )
1614 {
1622 {
1615 /** This function updates the value of the global variable lfrCurrentMode.
1623 /** This function updates the value of the global variable lfrCurrentMode.
1616 *
1624 *
1617 * lfrCurrentMode is a parameter used by several functions to know in which mode LFR is running.
1625 * lfrCurrentMode is a parameter used by several functions to know in which mode LFR is running.
1618 *
1626 *
1619 */
1627 */
1620
1628
1621 // update the local value of lfrCurrentMode with the value contained in the housekeeping_packet structure
1629 // update the local value of lfrCurrentMode with the value contained in the housekeeping_packet structure
1622 housekeeping_packet.lfr_status_word[0] = (unsigned char) ((requestedMode << 4) + 0x0d);
1630 housekeeping_packet.lfr_status_word[0] = (housekeeping_packet.lfr_status_word[0] & STATUS_WORD_LFR_MODE_MASK)
1631 + (unsigned char) ( requestedMode << STATUS_WORD_LFR_MODE_SHIFT );
1623 lfrCurrentMode = requestedMode;
1632 lfrCurrentMode = requestedMode;
1624 }
1633 }
1625
1634
1626 void set_lfr_soft_reset( unsigned char value )
1635 void set_lfr_soft_reset( unsigned char value )
1627 {
1636 {
1628 if (value == 1)
1637 if (value == 1)
1629 {
1638 {
1630 time_management_regs->ctrl = time_management_regs->ctrl | 0x00000004; // [0100]
1639 time_management_regs->ctrl = time_management_regs->ctrl | BIT_SOFT_RESET; // [0100]
1631 }
1640 }
1632 else
1641 else
1633 {
1642 {
1634 time_management_regs->ctrl = time_management_regs->ctrl & 0xfffffffb; // [1011]
1643 time_management_regs->ctrl = time_management_regs->ctrl & MASK_SOFT_RESET; // [1011]
1635 }
1644 }
1636 }
1645 }
1637
1646
1638 void reset_lfr( void )
1647 void reset_lfr( void )
1639 {
1648 {
1640 set_lfr_soft_reset( 1 );
1649 set_lfr_soft_reset( 1 );
1641
1650
1642 set_lfr_soft_reset( 0 );
1651 set_lfr_soft_reset( 0 );
1643
1652
1644 set_hk_lfr_sc_potential_flag( true );
1653 set_hk_lfr_sc_potential_flag( true );
1645 }
1654 }
@@ -1,1623 +1,1650
1 /** Functions to load and dump parameters in the LFR registers.
1 /** Functions to load and dump parameters in the LFR registers.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 * A group of functions to handle TC related to parameter loading and dumping.\n
6 * A group of functions to handle TC related to parameter loading and dumping.\n
7 * TC_LFR_LOAD_COMMON_PAR\n
7 * TC_LFR_LOAD_COMMON_PAR\n
8 * TC_LFR_LOAD_NORMAL_PAR\n
8 * TC_LFR_LOAD_NORMAL_PAR\n
9 * TC_LFR_LOAD_BURST_PAR\n
9 * TC_LFR_LOAD_BURST_PAR\n
10 * TC_LFR_LOAD_SBM1_PAR\n
10 * TC_LFR_LOAD_SBM1_PAR\n
11 * TC_LFR_LOAD_SBM2_PAR\n
11 * TC_LFR_LOAD_SBM2_PAR\n
12 *
12 *
13 */
13 */
14
14
15 #include "tc_load_dump_parameters.h"
15 #include "tc_load_dump_parameters.h"
16
16
17 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t kcoefficients_dump_1;
17 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t kcoefficients_dump_1;
18 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t kcoefficients_dump_2;
18 Packet_TM_LFR_KCOEFFICIENTS_DUMP_t kcoefficients_dump_2;
19 ring_node kcoefficient_node_1;
19 ring_node kcoefficient_node_1;
20 ring_node kcoefficient_node_2;
20 ring_node kcoefficient_node_2;
21
21
22 int action_load_common_par(ccsdsTelecommandPacket_t *TC)
22 int action_load_common_par(ccsdsTelecommandPacket_t *TC)
23 {
23 {
24 /** This function updates the LFR registers with the incoming common parameters.
24 /** This function updates the LFR registers with the incoming common parameters.
25 *
25 *
26 * @param TC points to the TeleCommand packet that is being processed
26 * @param TC points to the TeleCommand packet that is being processed
27 *
27 *
28 *
28 *
29 */
29 */
30
30
31 parameter_dump_packet.sy_lfr_common_parameters_spare = TC->dataAndCRC[0];
31 parameter_dump_packet.sy_lfr_common_parameters_spare = TC->dataAndCRC[0];
32 parameter_dump_packet.sy_lfr_common_parameters = TC->dataAndCRC[1];
32 parameter_dump_packet.sy_lfr_common_parameters = TC->dataAndCRC[1];
33 set_wfp_data_shaping( );
33 set_wfp_data_shaping( );
34 return LFR_SUCCESSFUL;
34 return LFR_SUCCESSFUL;
35 }
35 }
36
36
37 int action_load_normal_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
37 int action_load_normal_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
38 {
38 {
39 /** This function updates the LFR registers with the incoming normal parameters.
39 /** This function updates the LFR registers with the incoming normal parameters.
40 *
40 *
41 * @param TC points to the TeleCommand packet that is being processed
41 * @param TC points to the TeleCommand packet that is being processed
42 * @param queue_id is the id of the queue which handles TM related to this execution step
42 * @param queue_id is the id of the queue which handles TM related to this execution step
43 *
43 *
44 */
44 */
45
45
46 int result;
46 int result;
47 int flag;
47 int flag;
48 rtems_status_code status;
48 rtems_status_code status;
49
49
50 flag = LFR_SUCCESSFUL;
50 flag = LFR_SUCCESSFUL;
51
51
52 if ( (lfrCurrentMode == LFR_MODE_NORMAL) ||
52 if ( (lfrCurrentMode == LFR_MODE_NORMAL) ||
53 (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) ) {
53 (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) ) {
54 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
54 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
55 flag = LFR_DEFAULT;
55 flag = LFR_DEFAULT;
56 }
56 }
57
57
58 // CHECK THE PARAMETERS SET CONSISTENCY
58 // CHECK THE PARAMETERS SET CONSISTENCY
59 if (flag == LFR_SUCCESSFUL)
59 if (flag == LFR_SUCCESSFUL)
60 {
60 {
61 flag = check_normal_par_consistency( TC, queue_id );
61 flag = check_normal_par_consistency( TC, queue_id );
62 }
62 }
63
63
64 // SET THE PARAMETERS IF THEY ARE CONSISTENT
64 // SET THE PARAMETERS IF THEY ARE CONSISTENT
65 if (flag == LFR_SUCCESSFUL)
65 if (flag == LFR_SUCCESSFUL)
66 {
66 {
67 result = set_sy_lfr_n_swf_l( TC );
67 result = set_sy_lfr_n_swf_l( TC );
68 result = set_sy_lfr_n_swf_p( TC );
68 result = set_sy_lfr_n_swf_p( TC );
69 result = set_sy_lfr_n_bp_p0( TC );
69 result = set_sy_lfr_n_bp_p0( TC );
70 result = set_sy_lfr_n_bp_p1( TC );
70 result = set_sy_lfr_n_bp_p1( TC );
71 result = set_sy_lfr_n_asm_p( TC );
71 result = set_sy_lfr_n_asm_p( TC );
72 result = set_sy_lfr_n_cwf_long_f3( TC );
72 result = set_sy_lfr_n_cwf_long_f3( TC );
73 }
73 }
74
74
75 return flag;
75 return flag;
76 }
76 }
77
77
78 int action_load_burst_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
78 int action_load_burst_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
79 {
79 {
80 /** This function updates the LFR registers with the incoming burst parameters.
80 /** This function updates the LFR registers with the incoming burst parameters.
81 *
81 *
82 * @param TC points to the TeleCommand packet that is being processed
82 * @param TC points to the TeleCommand packet that is being processed
83 * @param queue_id is the id of the queue which handles TM related to this execution step
83 * @param queue_id is the id of the queue which handles TM related to this execution step
84 *
84 *
85 */
85 */
86
86
87 int flag;
87 int flag;
88 rtems_status_code status;
88 rtems_status_code status;
89 unsigned char sy_lfr_b_bp_p0;
89 unsigned char sy_lfr_b_bp_p0;
90 unsigned char sy_lfr_b_bp_p1;
90 unsigned char sy_lfr_b_bp_p1;
91 float aux;
91 float aux;
92
92
93 flag = LFR_SUCCESSFUL;
93 flag = LFR_SUCCESSFUL;
94
94
95 if ( lfrCurrentMode == LFR_MODE_BURST ) {
95 if ( lfrCurrentMode == LFR_MODE_BURST ) {
96 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
96 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
97 flag = LFR_DEFAULT;
97 flag = LFR_DEFAULT;
98 }
98 }
99
99
100 sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
100 sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
101 sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
101 sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
102
102
103 // sy_lfr_b_bp_p0 shall not be lower than its default value
103 // sy_lfr_b_bp_p0 shall not be lower than its default value
104 if (flag == LFR_SUCCESSFUL)
104 if (flag == LFR_SUCCESSFUL)
105 {
105 {
106 if (sy_lfr_b_bp_p0 < DEFAULT_SY_LFR_B_BP_P0 )
106 if (sy_lfr_b_bp_p0 < DEFAULT_SY_LFR_B_BP_P0 )
107 {
107 {
108 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P0+10, sy_lfr_b_bp_p0 );
108 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P0 + DATAFIELD_OFFSET, sy_lfr_b_bp_p0 );
109 flag = WRONG_APP_DATA;
109 flag = WRONG_APP_DATA;
110 }
110 }
111 }
111 }
112 // sy_lfr_b_bp_p1 shall not be lower than its default value
112 // sy_lfr_b_bp_p1 shall not be lower than its default value
113 if (flag == LFR_SUCCESSFUL)
113 if (flag == LFR_SUCCESSFUL)
114 {
114 {
115 if (sy_lfr_b_bp_p1 < DEFAULT_SY_LFR_B_BP_P1 )
115 if (sy_lfr_b_bp_p1 < DEFAULT_SY_LFR_B_BP_P1 )
116 {
116 {
117 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P1+10, sy_lfr_b_bp_p1 );
117 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P1 + DATAFIELD_OFFSET, sy_lfr_b_bp_p1 );
118 flag = WRONG_APP_DATA;
118 flag = WRONG_APP_DATA;
119 }
119 }
120 }
120 }
121 //****************************************************************
121 //****************************************************************
122 // check the consistency between sy_lfr_b_bp_p0 and sy_lfr_b_bp_p1
122 // check the consistency between sy_lfr_b_bp_p0 and sy_lfr_b_bp_p1
123 if (flag == LFR_SUCCESSFUL)
123 if (flag == LFR_SUCCESSFUL)
124 {
124 {
125 sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
125 sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
126 sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
126 sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
127 aux = ( (float ) sy_lfr_b_bp_p1 / sy_lfr_b_bp_p0 ) - floor(sy_lfr_b_bp_p1 / sy_lfr_b_bp_p0);
127 aux = ( (float ) sy_lfr_b_bp_p1 / sy_lfr_b_bp_p0 ) - floor(sy_lfr_b_bp_p1 / sy_lfr_b_bp_p0);
128 if (aux > FLOAT_EQUAL_ZERO)
128 if (aux > FLOAT_EQUAL_ZERO)
129 {
129 {
130 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P0+10, sy_lfr_b_bp_p0 );
130 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P0 + DATAFIELD_OFFSET, sy_lfr_b_bp_p0 );
131 flag = LFR_DEFAULT;
131 flag = LFR_DEFAULT;
132 }
132 }
133 }
133 }
134
134
135 // SET THE PARAMETERS
135 // SET THE PARAMETERS
136 if (flag == LFR_SUCCESSFUL)
136 if (flag == LFR_SUCCESSFUL)
137 {
137 {
138 flag = set_sy_lfr_b_bp_p0( TC );
138 flag = set_sy_lfr_b_bp_p0( TC );
139 flag = set_sy_lfr_b_bp_p1( TC );
139 flag = set_sy_lfr_b_bp_p1( TC );
140 }
140 }
141
141
142 return flag;
142 return flag;
143 }
143 }
144
144
145 int action_load_sbm1_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
145 int action_load_sbm1_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
146 {
146 {
147 /** This function updates the LFR registers with the incoming sbm1 parameters.
147 /** This function updates the LFR registers with the incoming sbm1 parameters.
148 *
148 *
149 * @param TC points to the TeleCommand packet that is being processed
149 * @param TC points to the TeleCommand packet that is being processed
150 * @param queue_id is the id of the queue which handles TM related to this execution step
150 * @param queue_id is the id of the queue which handles TM related to this execution step
151 *
151 *
152 */
152 */
153
153
154 int flag;
154 int flag;
155 rtems_status_code status;
155 rtems_status_code status;
156 unsigned char sy_lfr_s1_bp_p0;
156 unsigned char sy_lfr_s1_bp_p0;
157 unsigned char sy_lfr_s1_bp_p1;
157 unsigned char sy_lfr_s1_bp_p1;
158 float aux;
158 float aux;
159
159
160 flag = LFR_SUCCESSFUL;
160 flag = LFR_SUCCESSFUL;
161
161
162 if ( lfrCurrentMode == LFR_MODE_SBM1 ) {
162 if ( lfrCurrentMode == LFR_MODE_SBM1 ) {
163 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
163 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
164 flag = LFR_DEFAULT;
164 flag = LFR_DEFAULT;
165 }
165 }
166
166
167 sy_lfr_s1_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P0 ];
167 sy_lfr_s1_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P0 ];
168 sy_lfr_s1_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P1 ];
168 sy_lfr_s1_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P1 ];
169
169
170 // sy_lfr_s1_bp_p0
170 // sy_lfr_s1_bp_p0
171 if (flag == LFR_SUCCESSFUL)
171 if (flag == LFR_SUCCESSFUL)
172 {
172 {
173 if (sy_lfr_s1_bp_p0 < DEFAULT_SY_LFR_S1_BP_P0 )
173 if (sy_lfr_s1_bp_p0 < DEFAULT_SY_LFR_S1_BP_P0 )
174 {
174 {
175 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P0+10, sy_lfr_s1_bp_p0 );
175 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P0 + DATAFIELD_OFFSET, sy_lfr_s1_bp_p0 );
176 flag = WRONG_APP_DATA;
176 flag = WRONG_APP_DATA;
177 }
177 }
178 }
178 }
179 // sy_lfr_s1_bp_p1
179 // sy_lfr_s1_bp_p1
180 if (flag == LFR_SUCCESSFUL)
180 if (flag == LFR_SUCCESSFUL)
181 {
181 {
182 if (sy_lfr_s1_bp_p1 < DEFAULT_SY_LFR_S1_BP_P1 )
182 if (sy_lfr_s1_bp_p1 < DEFAULT_SY_LFR_S1_BP_P1 )
183 {
183 {
184 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P1+10, sy_lfr_s1_bp_p1 );
184 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P1 + DATAFIELD_OFFSET, sy_lfr_s1_bp_p1 );
185 flag = WRONG_APP_DATA;
185 flag = WRONG_APP_DATA;
186 }
186 }
187 }
187 }
188 //******************************************************************
188 //******************************************************************
189 // check the consistency between sy_lfr_s1_bp_p0 and sy_lfr_s1_bp_p1
189 // check the consistency between sy_lfr_s1_bp_p0 and sy_lfr_s1_bp_p1
190 if (flag == LFR_SUCCESSFUL)
190 if (flag == LFR_SUCCESSFUL)
191 {
191 {
192 aux = ( (float ) sy_lfr_s1_bp_p1 / (sy_lfr_s1_bp_p0*0.25) ) - floor(sy_lfr_s1_bp_p1 / (sy_lfr_s1_bp_p0*0.25));
192 aux = ( (float ) sy_lfr_s1_bp_p1 / (sy_lfr_s1_bp_p0 * S1_BP_P0_SCALE) )
193 - floor(sy_lfr_s1_bp_p1 / (sy_lfr_s1_bp_p0 * S1_BP_P0_SCALE));
193 if (aux > FLOAT_EQUAL_ZERO)
194 if (aux > FLOAT_EQUAL_ZERO)
194 {
195 {
195 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P0+10, sy_lfr_s1_bp_p0 );
196 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P0 + DATAFIELD_OFFSET, sy_lfr_s1_bp_p0 );
196 flag = LFR_DEFAULT;
197 flag = LFR_DEFAULT;
197 }
198 }
198 }
199 }
199
200
200 // SET THE PARAMETERS
201 // SET THE PARAMETERS
201 if (flag == LFR_SUCCESSFUL)
202 if (flag == LFR_SUCCESSFUL)
202 {
203 {
203 flag = set_sy_lfr_s1_bp_p0( TC );
204 flag = set_sy_lfr_s1_bp_p0( TC );
204 flag = set_sy_lfr_s1_bp_p1( TC );
205 flag = set_sy_lfr_s1_bp_p1( TC );
205 }
206 }
206
207
207 return flag;
208 return flag;
208 }
209 }
209
210
210 int action_load_sbm2_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
211 int action_load_sbm2_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
211 {
212 {
212 /** This function updates the LFR registers with the incoming sbm2 parameters.
213 /** This function updates the LFR registers with the incoming sbm2 parameters.
213 *
214 *
214 * @param TC points to the TeleCommand packet that is being processed
215 * @param TC points to the TeleCommand packet that is being processed
215 * @param queue_id is the id of the queue which handles TM related to this execution step
216 * @param queue_id is the id of the queue which handles TM related to this execution step
216 *
217 *
217 */
218 */
218
219
219 int flag;
220 int flag;
220 rtems_status_code status;
221 rtems_status_code status;
221 unsigned char sy_lfr_s2_bp_p0;
222 unsigned char sy_lfr_s2_bp_p0;
222 unsigned char sy_lfr_s2_bp_p1;
223 unsigned char sy_lfr_s2_bp_p1;
223 float aux;
224 float aux;
224
225
225 flag = LFR_SUCCESSFUL;
226 flag = LFR_SUCCESSFUL;
226
227
227 if ( lfrCurrentMode == LFR_MODE_SBM2 ) {
228 if ( lfrCurrentMode == LFR_MODE_SBM2 ) {
228 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
229 status = send_tm_lfr_tc_exe_not_executable( TC, queue_id );
229 flag = LFR_DEFAULT;
230 flag = LFR_DEFAULT;
230 }
231 }
231
232
232 sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
233 sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
233 sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
234 sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
234
235
235 // sy_lfr_s2_bp_p0
236 // sy_lfr_s2_bp_p0
236 if (flag == LFR_SUCCESSFUL)
237 if (flag == LFR_SUCCESSFUL)
237 {
238 {
238 if (sy_lfr_s2_bp_p0 < DEFAULT_SY_LFR_S2_BP_P0 )
239 if (sy_lfr_s2_bp_p0 < DEFAULT_SY_LFR_S2_BP_P0 )
239 {
240 {
240 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P0+10, sy_lfr_s2_bp_p0 );
241 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P0 + DATAFIELD_OFFSET, sy_lfr_s2_bp_p0 );
241 flag = WRONG_APP_DATA;
242 flag = WRONG_APP_DATA;
242 }
243 }
243 }
244 }
244 // sy_lfr_s2_bp_p1
245 // sy_lfr_s2_bp_p1
245 if (flag == LFR_SUCCESSFUL)
246 if (flag == LFR_SUCCESSFUL)
246 {
247 {
247 if (sy_lfr_s2_bp_p1 < DEFAULT_SY_LFR_S2_BP_P1 )
248 if (sy_lfr_s2_bp_p1 < DEFAULT_SY_LFR_S2_BP_P1 )
248 {
249 {
249 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P1+10, sy_lfr_s2_bp_p1 );
250 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P1 + DATAFIELD_OFFSET, sy_lfr_s2_bp_p1 );
250 flag = WRONG_APP_DATA;
251 flag = WRONG_APP_DATA;
251 }
252 }
252 }
253 }
253 //******************************************************************
254 //******************************************************************
254 // check the consistency between sy_lfr_s2_bp_p0 and sy_lfr_s2_bp_p1
255 // check the consistency between sy_lfr_s2_bp_p0 and sy_lfr_s2_bp_p1
255 if (flag == LFR_SUCCESSFUL)
256 if (flag == LFR_SUCCESSFUL)
256 {
257 {
257 sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
258 sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
258 sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
259 sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
259 aux = ( (float ) sy_lfr_s2_bp_p1 / sy_lfr_s2_bp_p0 ) - floor(sy_lfr_s2_bp_p1 / sy_lfr_s2_bp_p0);
260 aux = ( (float ) sy_lfr_s2_bp_p1 / sy_lfr_s2_bp_p0 ) - floor(sy_lfr_s2_bp_p1 / sy_lfr_s2_bp_p0);
260 if (aux > FLOAT_EQUAL_ZERO)
261 if (aux > FLOAT_EQUAL_ZERO)
261 {
262 {
262 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P0+10, sy_lfr_s2_bp_p0 );
263 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P0 + DATAFIELD_OFFSET, sy_lfr_s2_bp_p0 );
263 flag = LFR_DEFAULT;
264 flag = LFR_DEFAULT;
264 }
265 }
265 }
266 }
266
267
267 // SET THE PARAMETERS
268 // SET THE PARAMETERS
268 if (flag == LFR_SUCCESSFUL)
269 if (flag == LFR_SUCCESSFUL)
269 {
270 {
270 flag = set_sy_lfr_s2_bp_p0( TC );
271 flag = set_sy_lfr_s2_bp_p0( TC );
271 flag = set_sy_lfr_s2_bp_p1( TC );
272 flag = set_sy_lfr_s2_bp_p1( TC );
272 }
273 }
273
274
274 return flag;
275 return flag;
275 }
276 }
276
277
277 int action_load_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
278 int action_load_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
278 {
279 {
279 /** This function updates the LFR registers with the incoming sbm2 parameters.
280 /** This function updates the LFR registers with the incoming sbm2 parameters.
280 *
281 *
281 * @param TC points to the TeleCommand packet that is being processed
282 * @param TC points to the TeleCommand packet that is being processed
282 * @param queue_id is the id of the queue which handles TM related to this execution step
283 * @param queue_id is the id of the queue which handles TM related to this execution step
283 *
284 *
284 */
285 */
285
286
286 int flag;
287 int flag;
287
288
288 flag = LFR_DEFAULT;
289 flag = LFR_DEFAULT;
289
290
290 flag = set_sy_lfr_kcoeff( TC, queue_id );
291 flag = set_sy_lfr_kcoeff( TC, queue_id );
291
292
292 return flag;
293 return flag;
293 }
294 }
294
295
295 int action_load_fbins_mask(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
296 int action_load_fbins_mask(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
296 {
297 {
297 /** This function updates the LFR registers with the incoming sbm2 parameters.
298 /** This function updates the LFR registers with the incoming sbm2 parameters.
298 *
299 *
299 * @param TC points to the TeleCommand packet that is being processed
300 * @param TC points to the TeleCommand packet that is being processed
300 * @param queue_id is the id of the queue which handles TM related to this execution step
301 * @param queue_id is the id of the queue which handles TM related to this execution step
301 *
302 *
302 */
303 */
303
304
304 int flag;
305 int flag;
305
306
306 flag = LFR_DEFAULT;
307 flag = LFR_DEFAULT;
307
308
308 flag = set_sy_lfr_fbins( TC );
309 flag = set_sy_lfr_fbins( TC );
309
310
310 // once the fbins masks have been stored, they have to be merged with the masks which handle the reaction wheels frequencies filtering
311 // once the fbins masks have been stored, they have to be merged with the masks which handle the reaction wheels frequencies filtering
311 merge_fbins_masks();
312 merge_fbins_masks();
312
313
313 return flag;
314 return flag;
314 }
315 }
315
316
316 int action_load_filter_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
317 int action_load_filter_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
317 {
318 {
318 /** This function updates the LFR registers with the incoming sbm2 parameters.
319 /** This function updates the LFR registers with the incoming sbm2 parameters.
319 *
320 *
320 * @param TC points to the TeleCommand packet that is being processed
321 * @param TC points to the TeleCommand packet that is being processed
321 * @param queue_id is the id of the queue which handles TM related to this execution step
322 * @param queue_id is the id of the queue which handles TM related to this execution step
322 *
323 *
323 */
324 */
324
325
325 int flag;
326 int flag;
326
327
327 flag = LFR_DEFAULT;
328 flag = LFR_DEFAULT;
328
329
329 flag = check_sy_lfr_filter_parameters( TC, queue_id );
330 flag = check_sy_lfr_filter_parameters( TC, queue_id );
330
331
331 if (flag == LFR_SUCCESSFUL)
332 if (flag == LFR_SUCCESSFUL)
332 {
333 {
333 parameter_dump_packet.spare_sy_lfr_pas_filter_enabled = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_ENABLED ];
334 parameter_dump_packet.spare_sy_lfr_pas_filter_enabled = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_ENABLED ];
334 parameter_dump_packet.sy_lfr_pas_filter_modulus = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS ];
335 parameter_dump_packet.sy_lfr_pas_filter_modulus = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS ];
335 parameter_dump_packet.sy_lfr_pas_filter_tbad[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + 0 ];
336 parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_0 ];
336 parameter_dump_packet.sy_lfr_pas_filter_tbad[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + 1 ];
337 parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_1 ];
337 parameter_dump_packet.sy_lfr_pas_filter_tbad[2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + 2 ];
338 parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_2 ];
338 parameter_dump_packet.sy_lfr_pas_filter_tbad[3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + 3 ];
339 parameter_dump_packet.sy_lfr_pas_filter_tbad[BYTE_3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + BYTE_3 ];
339 parameter_dump_packet.sy_lfr_pas_filter_offset = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET ];
340 parameter_dump_packet.sy_lfr_pas_filter_offset = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET ];
340 parameter_dump_packet.sy_lfr_pas_filter_shift[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + 0 ];
341 parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_0 ];
341 parameter_dump_packet.sy_lfr_pas_filter_shift[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + 1 ];
342 parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_1 ];
342 parameter_dump_packet.sy_lfr_pas_filter_shift[2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + 2 ];
343 parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_2 ];
343 parameter_dump_packet.sy_lfr_pas_filter_shift[3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + 3 ];
344 parameter_dump_packet.sy_lfr_pas_filter_shift[BYTE_3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + BYTE_3 ];
344 parameter_dump_packet.sy_lfr_sc_rw_delta_f[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + 0 ];
345 parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_0 ];
345 parameter_dump_packet.sy_lfr_sc_rw_delta_f[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + 1 ];
346 parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_1 ];
346 parameter_dump_packet.sy_lfr_sc_rw_delta_f[2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + 2 ];
347 parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_2] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_2 ];
347 parameter_dump_packet.sy_lfr_sc_rw_delta_f[3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + 3 ];
348 parameter_dump_packet.sy_lfr_sc_rw_delta_f[BYTE_3] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F + BYTE_3 ];
348
349
349 //****************************
350 //****************************
350 // store PAS filter parameters
351 // store PAS filter parameters
351 // sy_lfr_pas_filter_enabled
352 // sy_lfr_pas_filter_enabled
352 filterPar.spare_sy_lfr_pas_filter_enabled = parameter_dump_packet.spare_sy_lfr_pas_filter_enabled;
353 filterPar.spare_sy_lfr_pas_filter_enabled = parameter_dump_packet.spare_sy_lfr_pas_filter_enabled;
353 set_sy_lfr_pas_filter_enabled( parameter_dump_packet.spare_sy_lfr_pas_filter_enabled & 0x01 );
354 set_sy_lfr_pas_filter_enabled( parameter_dump_packet.spare_sy_lfr_pas_filter_enabled & BIT_PAS_FILTER_ENABLED );
354 // sy_lfr_pas_filter_modulus
355 // sy_lfr_pas_filter_modulus
355 filterPar.sy_lfr_pas_filter_modulus = parameter_dump_packet.sy_lfr_pas_filter_modulus;
356 filterPar.sy_lfr_pas_filter_modulus = parameter_dump_packet.sy_lfr_pas_filter_modulus;
356 // sy_lfr_pas_filter_tbad
357 // sy_lfr_pas_filter_tbad
357 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_pas_filter_tbad,
358 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_pas_filter_tbad,
358 parameter_dump_packet.sy_lfr_pas_filter_tbad );
359 parameter_dump_packet.sy_lfr_pas_filter_tbad );
359 // sy_lfr_pas_filter_offset
360 // sy_lfr_pas_filter_offset
360 filterPar.sy_lfr_pas_filter_offset = parameter_dump_packet.sy_lfr_pas_filter_offset;
361 filterPar.sy_lfr_pas_filter_offset = parameter_dump_packet.sy_lfr_pas_filter_offset;
361 // sy_lfr_pas_filter_shift
362 // sy_lfr_pas_filter_shift
362 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_pas_filter_shift,
363 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_pas_filter_shift,
363 parameter_dump_packet.sy_lfr_pas_filter_shift );
364 parameter_dump_packet.sy_lfr_pas_filter_shift );
364
365
365 //****************************************************
366 //****************************************************
366 // store the parameter sy_lfr_sc_rw_delta_f as a float
367 // store the parameter sy_lfr_sc_rw_delta_f as a float
367 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_sc_rw_delta_f,
368 copyFloatByChar( (unsigned char*) &filterPar.sy_lfr_sc_rw_delta_f,
368 parameter_dump_packet.sy_lfr_sc_rw_delta_f );
369 parameter_dump_packet.sy_lfr_sc_rw_delta_f );
369 }
370 }
370
371
371 return flag;
372 return flag;
372 }
373 }
373
374
374 int action_dump_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
375 int action_dump_kcoefficients(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time)
375 {
376 {
376 /** This function updates the LFR registers with the incoming sbm2 parameters.
377 /** This function updates the LFR registers with the incoming sbm2 parameters.
377 *
378 *
378 * @param TC points to the TeleCommand packet that is being processed
379 * @param TC points to the TeleCommand packet that is being processed
379 * @param queue_id is the id of the queue which handles TM related to this execution step
380 * @param queue_id is the id of the queue which handles TM related to this execution step
380 *
381 *
381 */
382 */
382
383
383 unsigned int address;
384 unsigned int address;
384 rtems_status_code status;
385 rtems_status_code status;
385 unsigned int freq;
386 unsigned int freq;
386 unsigned int bin;
387 unsigned int bin;
387 unsigned int coeff;
388 unsigned int coeff;
388 unsigned char *kCoeffPtr;
389 unsigned char *kCoeffPtr;
389 unsigned char *kCoeffDumpPtr;
390 unsigned char *kCoeffDumpPtr;
390
391
391 // for each sy_lfr_kcoeff_frequency there is 32 kcoeff
392 // for each sy_lfr_kcoeff_frequency there is 32 kcoeff
392 // F0 => 11 bins
393 // F0 => 11 bins
393 // F1 => 13 bins
394 // F1 => 13 bins
394 // F2 => 12 bins
395 // F2 => 12 bins
395 // 36 bins to dump in two packets (30 bins max per packet)
396 // 36 bins to dump in two packets (30 bins max per packet)
396
397
397 //*********
398 //*********
398 // PACKET 1
399 // PACKET 1
399 // 11 F0 bins, 13 F1 bins and 6 F2 bins
400 // 11 F0 bins, 13 F1 bins and 6 F2 bins
400 kcoefficients_dump_1.destinationID = TC->sourceID;
401 kcoefficients_dump_1.destinationID = TC->sourceID;
401 increment_seq_counter_destination_id_dump( kcoefficients_dump_1.packetSequenceControl, TC->sourceID );
402 increment_seq_counter_destination_id_dump( kcoefficients_dump_1.packetSequenceControl, TC->sourceID );
402 for( freq=0;
403 for( freq = 0;
403 freq<NB_BINS_COMPRESSED_SM_F0;
404 freq < NB_BINS_COMPRESSED_SM_F0;
404 freq++ )
405 freq++ )
405 {
406 {
406 kcoefficients_dump_1.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + 1] = freq;
407 kcoefficients_dump_1.kcoeff_blks[ (freq*KCOEFF_BLK_SIZE) + 1] = freq;
407 bin = freq;
408 bin = freq;
408 // printKCoefficients( freq, bin, k_coeff_intercalib_f0_norm);
409 // printKCoefficients( freq, bin, k_coeff_intercalib_f0_norm);
409 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
410 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
410 {
411 {
411 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + coeff*NB_BYTES_PER_FLOAT + 2 ]; // 2 for the kcoeff_frequency
412 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[
413 (freq*KCOEFF_BLK_SIZE) + (coeff*NB_BYTES_PER_FLOAT) + KCOEFF_FREQ
414 ]; // 2 for the kcoeff_frequency
412 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f0_norm[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
415 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f0_norm[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
413 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
416 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
414 }
417 }
415 }
418 }
416 for( freq=NB_BINS_COMPRESSED_SM_F0;
419 for( freq = NB_BINS_COMPRESSED_SM_F0;
417 freq<(NB_BINS_COMPRESSED_SM_F0+NB_BINS_COMPRESSED_SM_F1);
420 freq < ( NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 );
418 freq++ )
421 freq++ )
419 {
422 {
420 kcoefficients_dump_1.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + 1 ] = freq;
423 kcoefficients_dump_1.kcoeff_blks[ (freq*KCOEFF_BLK_SIZE) + 1 ] = freq;
421 bin = freq - NB_BINS_COMPRESSED_SM_F0;
424 bin = freq - NB_BINS_COMPRESSED_SM_F0;
422 // printKCoefficients( freq, bin, k_coeff_intercalib_f1_norm);
425 // printKCoefficients( freq, bin, k_coeff_intercalib_f1_norm);
423 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
426 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
424 {
427 {
425 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + coeff*NB_BYTES_PER_FLOAT + 2 ]; // 2 for the kcoeff_frequency
428 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[
429 (freq*KCOEFF_BLK_SIZE) + (coeff*NB_BYTES_PER_FLOAT) + KCOEFF_FREQ
430 ]; // 2 for the kcoeff_frequency
426 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f1_norm[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
431 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f1_norm[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
427 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
432 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
428 }
433 }
429 }
434 }
430 for( freq=(NB_BINS_COMPRESSED_SM_F0+NB_BINS_COMPRESSED_SM_F1);
435 for( freq = ( NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 );
431 freq<(NB_BINS_COMPRESSED_SM_F0+NB_BINS_COMPRESSED_SM_F1+6);
436 freq < KCOEFF_BLK_NR_PKT1 ;
432 freq++ )
437 freq++ )
433 {
438 {
434 kcoefficients_dump_1.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + 1 ] = freq;
439 kcoefficients_dump_1.kcoeff_blks[ (freq * KCOEFF_BLK_SIZE) + 1 ] = freq;
435 bin = freq - (NB_BINS_COMPRESSED_SM_F0+NB_BINS_COMPRESSED_SM_F1);
440 bin = freq - (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1);
436 // printKCoefficients( freq, bin, k_coeff_intercalib_f2);
441 // printKCoefficients( freq, bin, k_coeff_intercalib_f2);
437 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
442 for ( coeff = 0; coeff <NB_K_COEFF_PER_BIN; coeff++ )
438 {
443 {
439 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + coeff*NB_BYTES_PER_FLOAT + 2 ]; // 2 for the kcoeff_frequency
444 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_1.kcoeff_blks[
445 (freq * KCOEFF_BLK_SIZE) + (coeff * NB_BYTES_PER_FLOAT) + KCOEFF_FREQ
446 ]; // 2 for the kcoeff_frequency
440 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f2[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
447 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f2[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
441 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
448 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
442 }
449 }
443 }
450 }
444 kcoefficients_dump_1.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
451 kcoefficients_dump_1.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
445 kcoefficients_dump_1.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
452 kcoefficients_dump_1.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
446 kcoefficients_dump_1.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
453 kcoefficients_dump_1.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
447 kcoefficients_dump_1.time[3] = (unsigned char) (time_management_regs->coarse_time);
454 kcoefficients_dump_1.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
448 kcoefficients_dump_1.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
455 kcoefficients_dump_1.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
449 kcoefficients_dump_1.time[5] = (unsigned char) (time_management_regs->fine_time);
456 kcoefficients_dump_1.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
450 // SEND DATA
457 // SEND DATA
451 kcoefficient_node_1.status = 1;
458 kcoefficient_node_1.status = 1;
452 address = (unsigned int) &kcoefficient_node_1;
459 address = (unsigned int) &kcoefficient_node_1;
453 status = rtems_message_queue_send( queue_id, &address, sizeof( ring_node* ) );
460 status = rtems_message_queue_send( queue_id, &address, sizeof( ring_node* ) );
454 if (status != RTEMS_SUCCESSFUL) {
461 if (status != RTEMS_SUCCESSFUL) {
455 PRINTF1("in action_dump_kcoefficients *** ERR sending packet 1 , code %d", status)
462 PRINTF1("in action_dump_kcoefficients *** ERR sending packet 1 , code %d", status)
456 }
463 }
457
464
458 //********
465 //********
459 // PACKET 2
466 // PACKET 2
460 // 6 F2 bins
467 // 6 F2 bins
461 kcoefficients_dump_2.destinationID = TC->sourceID;
468 kcoefficients_dump_2.destinationID = TC->sourceID;
462 increment_seq_counter_destination_id_dump( kcoefficients_dump_2.packetSequenceControl, TC->sourceID );
469 increment_seq_counter_destination_id_dump( kcoefficients_dump_2.packetSequenceControl, TC->sourceID );
463 for( freq=0; freq<6; freq++ )
470 for( freq = 0;
471 freq < KCOEFF_BLK_NR_PKT2;
472 freq++ )
464 {
473 {
465 kcoefficients_dump_2.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + 1 ] = NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 + 6 + freq;
474 kcoefficients_dump_2.kcoeff_blks[ (freq*KCOEFF_BLK_SIZE) + 1 ] = KCOEFF_BLK_NR_PKT1 + freq;
466 bin = freq + 6;
475 bin = freq + KCOEFF_BLK_NR_PKT2;
467 // printKCoefficients( freq, bin, k_coeff_intercalib_f2);
476 // printKCoefficients( freq, bin, k_coeff_intercalib_f2);
468 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
477 for ( coeff=0; coeff<NB_K_COEFF_PER_BIN; coeff++ )
469 {
478 {
470 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_2.kcoeff_blks[ freq*KCOEFF_BLK_SIZE + coeff*NB_BYTES_PER_FLOAT + 2 ]; // 2 for the kcoeff_frequency
479 kCoeffDumpPtr = (unsigned char*) &kcoefficients_dump_2.kcoeff_blks[
480 (freq*KCOEFF_BLK_SIZE) + (coeff*NB_BYTES_PER_FLOAT) + KCOEFF_FREQ ]; // 2 for the kcoeff_frequency
471 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f2[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
481 kCoeffPtr = (unsigned char*) &k_coeff_intercalib_f2[ (bin*NB_K_COEFF_PER_BIN) + coeff ];
472 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
482 copyFloatByChar( kCoeffDumpPtr, kCoeffPtr );
473 }
483 }
474 }
484 }
475 kcoefficients_dump_2.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
485 kcoefficients_dump_2.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
476 kcoefficients_dump_2.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
486 kcoefficients_dump_2.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
477 kcoefficients_dump_2.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
487 kcoefficients_dump_2.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
478 kcoefficients_dump_2.time[3] = (unsigned char) (time_management_regs->coarse_time);
488 kcoefficients_dump_2.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
479 kcoefficients_dump_2.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
489 kcoefficients_dump_2.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
480 kcoefficients_dump_2.time[5] = (unsigned char) (time_management_regs->fine_time);
490 kcoefficients_dump_2.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
481 // SEND DATA
491 // SEND DATA
482 kcoefficient_node_2.status = 1;
492 kcoefficient_node_2.status = 1;
483 address = (unsigned int) &kcoefficient_node_2;
493 address = (unsigned int) &kcoefficient_node_2;
484 status = rtems_message_queue_send( queue_id, &address, sizeof( ring_node* ) );
494 status = rtems_message_queue_send( queue_id, &address, sizeof( ring_node* ) );
485 if (status != RTEMS_SUCCESSFUL) {
495 if (status != RTEMS_SUCCESSFUL) {
486 PRINTF1("in action_dump_kcoefficients *** ERR sending packet 2, code %d", status)
496 PRINTF1("in action_dump_kcoefficients *** ERR sending packet 2, code %d", status)
487 }
497 }
488
498
489 return status;
499 return status;
490 }
500 }
491
501
492 int action_dump_par( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
502 int action_dump_par( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
493 {
503 {
494 /** This function dumps the LFR parameters by sending the appropriate TM packet to the dedicated RTEMS message queue.
504 /** This function dumps the LFR parameters by sending the appropriate TM packet to the dedicated RTEMS message queue.
495 *
505 *
496 * @param queue_id is the id of the queue which handles TM related to this execution step.
506 * @param queue_id is the id of the queue which handles TM related to this execution step.
497 *
507 *
498 * @return RTEMS directive status codes:
508 * @return RTEMS directive status codes:
499 * - RTEMS_SUCCESSFUL - message sent successfully
509 * - RTEMS_SUCCESSFUL - message sent successfully
500 * - RTEMS_INVALID_ID - invalid queue id
510 * - RTEMS_INVALID_ID - invalid queue id
501 * - RTEMS_INVALID_SIZE - invalid message size
511 * - RTEMS_INVALID_SIZE - invalid message size
502 * - RTEMS_INVALID_ADDRESS - buffer is NULL
512 * - RTEMS_INVALID_ADDRESS - buffer is NULL
503 * - RTEMS_UNSATISFIED - out of message buffers
513 * - RTEMS_UNSATISFIED - out of message buffers
504 * - RTEMS_TOO_MANY - queue s limit has been reached
514 * - RTEMS_TOO_MANY - queue s limit has been reached
505 *
515 *
506 */
516 */
507
517
508 int status;
518 int status;
509
519
510 increment_seq_counter_destination_id_dump( parameter_dump_packet.packetSequenceControl, TC->sourceID );
520 increment_seq_counter_destination_id_dump( parameter_dump_packet.packetSequenceControl, TC->sourceID );
511 parameter_dump_packet.destinationID = TC->sourceID;
521 parameter_dump_packet.destinationID = TC->sourceID;
512
522
513 // UPDATE TIME
523 // UPDATE TIME
514 parameter_dump_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
524 parameter_dump_packet.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
515 parameter_dump_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
525 parameter_dump_packet.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
516 parameter_dump_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
526 parameter_dump_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
517 parameter_dump_packet.time[3] = (unsigned char) (time_management_regs->coarse_time);
527 parameter_dump_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
518 parameter_dump_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
528 parameter_dump_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
519 parameter_dump_packet.time[5] = (unsigned char) (time_management_regs->fine_time);
529 parameter_dump_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
520 // SEND DATA
530 // SEND DATA
521 status = rtems_message_queue_send( queue_id, &parameter_dump_packet,
531 status = rtems_message_queue_send( queue_id, &parameter_dump_packet,
522 PACKET_LENGTH_PARAMETER_DUMP + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
532 PACKET_LENGTH_PARAMETER_DUMP + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
523 if (status != RTEMS_SUCCESSFUL) {
533 if (status != RTEMS_SUCCESSFUL) {
524 PRINTF1("in action_dump *** ERR sending packet, code %d", status)
534 PRINTF1("in action_dump *** ERR sending packet, code %d", status)
525 }
535 }
526
536
527 return status;
537 return status;
528 }
538 }
529
539
530 //***********************
540 //***********************
531 // NORMAL MODE PARAMETERS
541 // NORMAL MODE PARAMETERS
532
542
533 int check_normal_par_consistency( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
543 int check_normal_par_consistency( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
534 {
544 {
535 unsigned char msb;
545 unsigned char msb;
536 unsigned char lsb;
546 unsigned char lsb;
537 int flag;
547 int flag;
538 float aux;
548 float aux;
539 rtems_status_code status;
549 rtems_status_code status;
540
550
541 unsigned int sy_lfr_n_swf_l;
551 unsigned int sy_lfr_n_swf_l;
542 unsigned int sy_lfr_n_swf_p;
552 unsigned int sy_lfr_n_swf_p;
543 unsigned int sy_lfr_n_asm_p;
553 unsigned int sy_lfr_n_asm_p;
544 unsigned char sy_lfr_n_bp_p0;
554 unsigned char sy_lfr_n_bp_p0;
545 unsigned char sy_lfr_n_bp_p1;
555 unsigned char sy_lfr_n_bp_p1;
546 unsigned char sy_lfr_n_cwf_long_f3;
556 unsigned char sy_lfr_n_cwf_long_f3;
547
557
548 flag = LFR_SUCCESSFUL;
558 flag = LFR_SUCCESSFUL;
549
559
550 //***************
560 //***************
551 // get parameters
561 // get parameters
552 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L ];
562 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L ];
553 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L+1 ];
563 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L+1 ];
554 sy_lfr_n_swf_l = msb * 256 + lsb;
564 sy_lfr_n_swf_l = (msb * CONST_256) + lsb;
555
565
556 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P ];
566 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P ];
557 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P+1 ];
567 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P+1 ];
558 sy_lfr_n_swf_p = msb * 256 + lsb;
568 sy_lfr_n_swf_p = (msb * CONST_256) + lsb;
559
569
560 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P ];
570 msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P ];
561 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P+1 ];
571 lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P+1 ];
562 sy_lfr_n_asm_p = msb * 256 + lsb;
572 sy_lfr_n_asm_p = (msb * CONST_256) + lsb;
563
573
564 sy_lfr_n_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P0 ];
574 sy_lfr_n_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P0 ];
565
575
566 sy_lfr_n_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P1 ];
576 sy_lfr_n_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P1 ];
567
577
568 sy_lfr_n_cwf_long_f3 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_CWF_LONG_F3 ];
578 sy_lfr_n_cwf_long_f3 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_CWF_LONG_F3 ];
569
579
570 //******************
580 //******************
571 // check consistency
581 // check consistency
572 // sy_lfr_n_swf_l
582 // sy_lfr_n_swf_l
573 if (sy_lfr_n_swf_l != 2048)
583 if (sy_lfr_n_swf_l != DFLT_SY_LFR_N_SWF_L)
574 {
584 {
575 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_SWF_L+10, sy_lfr_n_swf_l );
585 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_SWF_L + DATAFIELD_OFFSET, sy_lfr_n_swf_l );
576 flag = WRONG_APP_DATA;
586 flag = WRONG_APP_DATA;
577 }
587 }
578 // sy_lfr_n_swf_p
588 // sy_lfr_n_swf_p
579 if (flag == LFR_SUCCESSFUL)
589 if (flag == LFR_SUCCESSFUL)
580 {
590 {
581 if ( sy_lfr_n_swf_p < 22 )
591 if ( sy_lfr_n_swf_p < MIN_SY_LFR_N_SWF_P )
582 {
592 {
583 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_SWF_P+10, sy_lfr_n_swf_p );
593 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_SWF_P + DATAFIELD_OFFSET, sy_lfr_n_swf_p );
584 flag = WRONG_APP_DATA;
594 flag = WRONG_APP_DATA;
585 }
595 }
586 }
596 }
587 // sy_lfr_n_bp_p0
597 // sy_lfr_n_bp_p0
588 if (flag == LFR_SUCCESSFUL)
598 if (flag == LFR_SUCCESSFUL)
589 {
599 {
590 if (sy_lfr_n_bp_p0 < DFLT_SY_LFR_N_BP_P0)
600 if (sy_lfr_n_bp_p0 < DFLT_SY_LFR_N_BP_P0)
591 {
601 {
592 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P0+10, sy_lfr_n_bp_p0 );
602 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P0 + DATAFIELD_OFFSET, sy_lfr_n_bp_p0 );
593 flag = WRONG_APP_DATA;
603 flag = WRONG_APP_DATA;
594 }
604 }
595 }
605 }
596 // sy_lfr_n_asm_p
606 // sy_lfr_n_asm_p
597 if (flag == LFR_SUCCESSFUL)
607 if (flag == LFR_SUCCESSFUL)
598 {
608 {
599 if (sy_lfr_n_asm_p == 0)
609 if (sy_lfr_n_asm_p == 0)
600 {
610 {
601 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_ASM_P+10, sy_lfr_n_asm_p );
611 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_ASM_P + DATAFIELD_OFFSET, sy_lfr_n_asm_p );
602 flag = WRONG_APP_DATA;
612 flag = WRONG_APP_DATA;
603 }
613 }
604 }
614 }
605 // sy_lfr_n_asm_p shall be a whole multiple of sy_lfr_n_bp_p0
615 // sy_lfr_n_asm_p shall be a whole multiple of sy_lfr_n_bp_p0
606 if (flag == LFR_SUCCESSFUL)
616 if (flag == LFR_SUCCESSFUL)
607 {
617 {
608 aux = ( (float ) sy_lfr_n_asm_p / sy_lfr_n_bp_p0 ) - floor(sy_lfr_n_asm_p / sy_lfr_n_bp_p0);
618 aux = ( (float ) sy_lfr_n_asm_p / sy_lfr_n_bp_p0 ) - floor(sy_lfr_n_asm_p / sy_lfr_n_bp_p0);
609 if (aux > FLOAT_EQUAL_ZERO)
619 if (aux > FLOAT_EQUAL_ZERO)
610 {
620 {
611 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_ASM_P+10, sy_lfr_n_asm_p );
621 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_ASM_P + DATAFIELD_OFFSET, sy_lfr_n_asm_p );
612 flag = WRONG_APP_DATA;
622 flag = WRONG_APP_DATA;
613 }
623 }
614 }
624 }
615 // sy_lfr_n_bp_p1
625 // sy_lfr_n_bp_p1
616 if (flag == LFR_SUCCESSFUL)
626 if (flag == LFR_SUCCESSFUL)
617 {
627 {
618 if (sy_lfr_n_bp_p1 < DFLT_SY_LFR_N_BP_P1)
628 if (sy_lfr_n_bp_p1 < DFLT_SY_LFR_N_BP_P1)
619 {
629 {
620 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P1+10, sy_lfr_n_bp_p1 );
630 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P1 + DATAFIELD_OFFSET, sy_lfr_n_bp_p1 );
621 flag = WRONG_APP_DATA;
631 flag = WRONG_APP_DATA;
622 }
632 }
623 }
633 }
624 // sy_lfr_n_bp_p1 shall be a whole multiple of sy_lfr_n_bp_p0
634 // sy_lfr_n_bp_p1 shall be a whole multiple of sy_lfr_n_bp_p0
625 if (flag == LFR_SUCCESSFUL)
635 if (flag == LFR_SUCCESSFUL)
626 {
636 {
627 aux = ( (float ) sy_lfr_n_bp_p1 / sy_lfr_n_bp_p0 ) - floor(sy_lfr_n_bp_p1 / sy_lfr_n_bp_p0);
637 aux = ( (float ) sy_lfr_n_bp_p1 / sy_lfr_n_bp_p0 ) - floor(sy_lfr_n_bp_p1 / sy_lfr_n_bp_p0);
628 if (aux > FLOAT_EQUAL_ZERO)
638 if (aux > FLOAT_EQUAL_ZERO)
629 {
639 {
630 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P1+10, sy_lfr_n_bp_p1 );
640 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P1 + DATAFIELD_OFFSET, sy_lfr_n_bp_p1 );
631 flag = LFR_DEFAULT;
641 flag = LFR_DEFAULT;
632 }
642 }
633 }
643 }
634 // sy_lfr_n_cwf_long_f3
644 // sy_lfr_n_cwf_long_f3
635
645
636 return flag;
646 return flag;
637 }
647 }
638
648
639 int set_sy_lfr_n_swf_l( ccsdsTelecommandPacket_t *TC )
649 int set_sy_lfr_n_swf_l( ccsdsTelecommandPacket_t *TC )
640 {
650 {
641 /** This function sets the number of points of a snapshot (sy_lfr_n_swf_l).
651 /** This function sets the number of points of a snapshot (sy_lfr_n_swf_l).
642 *
652 *
643 * @param TC points to the TeleCommand packet that is being processed
653 * @param TC points to the TeleCommand packet that is being processed
644 * @param queue_id is the id of the queue which handles TM related to this execution step
654 * @param queue_id is the id of the queue which handles TM related to this execution step
645 *
655 *
646 */
656 */
647
657
648 int result;
658 int result;
649
659
650 result = LFR_SUCCESSFUL;
660 result = LFR_SUCCESSFUL;
651
661
652 parameter_dump_packet.sy_lfr_n_swf_l[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L ];
662 parameter_dump_packet.sy_lfr_n_swf_l[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L ];
653 parameter_dump_packet.sy_lfr_n_swf_l[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L+1 ];
663 parameter_dump_packet.sy_lfr_n_swf_l[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L+1 ];
654
664
655 return result;
665 return result;
656 }
666 }
657
667
658 int set_sy_lfr_n_swf_p(ccsdsTelecommandPacket_t *TC )
668 int set_sy_lfr_n_swf_p(ccsdsTelecommandPacket_t *TC )
659 {
669 {
660 /** This function sets the time between two snapshots, in s (sy_lfr_n_swf_p).
670 /** This function sets the time between two snapshots, in s (sy_lfr_n_swf_p).
661 *
671 *
662 * @param TC points to the TeleCommand packet that is being processed
672 * @param TC points to the TeleCommand packet that is being processed
663 * @param queue_id is the id of the queue which handles TM related to this execution step
673 * @param queue_id is the id of the queue which handles TM related to this execution step
664 *
674 *
665 */
675 */
666
676
667 int result;
677 int result;
668
678
669 result = LFR_SUCCESSFUL;
679 result = LFR_SUCCESSFUL;
670
680
671 parameter_dump_packet.sy_lfr_n_swf_p[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P ];
681 parameter_dump_packet.sy_lfr_n_swf_p[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P ];
672 parameter_dump_packet.sy_lfr_n_swf_p[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P+1 ];
682 parameter_dump_packet.sy_lfr_n_swf_p[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P+1 ];
673
683
674 return result;
684 return result;
675 }
685 }
676
686
677 int set_sy_lfr_n_asm_p( ccsdsTelecommandPacket_t *TC )
687 int set_sy_lfr_n_asm_p( ccsdsTelecommandPacket_t *TC )
678 {
688 {
679 /** This function sets the time between two full spectral matrices transmission, in s (SY_LFR_N_ASM_P).
689 /** This function sets the time between two full spectral matrices transmission, in s (SY_LFR_N_ASM_P).
680 *
690 *
681 * @param TC points to the TeleCommand packet that is being processed
691 * @param TC points to the TeleCommand packet that is being processed
682 * @param queue_id is the id of the queue which handles TM related to this execution step
692 * @param queue_id is the id of the queue which handles TM related to this execution step
683 *
693 *
684 */
694 */
685
695
686 int result;
696 int result;
687
697
688 result = LFR_SUCCESSFUL;
698 result = LFR_SUCCESSFUL;
689
699
690 parameter_dump_packet.sy_lfr_n_asm_p[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P ];
700 parameter_dump_packet.sy_lfr_n_asm_p[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P ];
691 parameter_dump_packet.sy_lfr_n_asm_p[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P+1 ];
701 parameter_dump_packet.sy_lfr_n_asm_p[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P+1 ];
692
702
693 return result;
703 return result;
694 }
704 }
695
705
696 int set_sy_lfr_n_bp_p0( ccsdsTelecommandPacket_t *TC )
706 int set_sy_lfr_n_bp_p0( ccsdsTelecommandPacket_t *TC )
697 {
707 {
698 /** This function sets the time between two basic parameter sets, in s (DFLT_SY_LFR_N_BP_P0).
708 /** This function sets the time between two basic parameter sets, in s (DFLT_SY_LFR_N_BP_P0).
699 *
709 *
700 * @param TC points to the TeleCommand packet that is being processed
710 * @param TC points to the TeleCommand packet that is being processed
701 * @param queue_id is the id of the queue which handles TM related to this execution step
711 * @param queue_id is the id of the queue which handles TM related to this execution step
702 *
712 *
703 */
713 */
704
714
705 int status;
715 int status;
706
716
707 status = LFR_SUCCESSFUL;
717 status = LFR_SUCCESSFUL;
708
718
709 parameter_dump_packet.sy_lfr_n_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P0 ];
719 parameter_dump_packet.sy_lfr_n_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P0 ];
710
720
711 return status;
721 return status;
712 }
722 }
713
723
714 int set_sy_lfr_n_bp_p1(ccsdsTelecommandPacket_t *TC )
724 int set_sy_lfr_n_bp_p1(ccsdsTelecommandPacket_t *TC )
715 {
725 {
716 /** This function sets the time between two basic parameter sets (autocorrelation + crosscorrelation), in s (sy_lfr_n_bp_p1).
726 /** This function sets the time between two basic parameter sets (autocorrelation + crosscorrelation), in s (sy_lfr_n_bp_p1).
717 *
727 *
718 * @param TC points to the TeleCommand packet that is being processed
728 * @param TC points to the TeleCommand packet that is being processed
719 * @param queue_id is the id of the queue which handles TM related to this execution step
729 * @param queue_id is the id of the queue which handles TM related to this execution step
720 *
730 *
721 */
731 */
722
732
723 int status;
733 int status;
724
734
725 status = LFR_SUCCESSFUL;
735 status = LFR_SUCCESSFUL;
726
736
727 parameter_dump_packet.sy_lfr_n_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P1 ];
737 parameter_dump_packet.sy_lfr_n_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P1 ];
728
738
729 return status;
739 return status;
730 }
740 }
731
741
732 int set_sy_lfr_n_cwf_long_f3(ccsdsTelecommandPacket_t *TC )
742 int set_sy_lfr_n_cwf_long_f3(ccsdsTelecommandPacket_t *TC )
733 {
743 {
734 /** This function allows to switch from CWF_F3 packets to CWF_LONG_F3 packets.
744 /** This function allows to switch from CWF_F3 packets to CWF_LONG_F3 packets.
735 *
745 *
736 * @param TC points to the TeleCommand packet that is being processed
746 * @param TC points to the TeleCommand packet that is being processed
737 * @param queue_id is the id of the queue which handles TM related to this execution step
747 * @param queue_id is the id of the queue which handles TM related to this execution step
738 *
748 *
739 */
749 */
740
750
741 int status;
751 int status;
742
752
743 status = LFR_SUCCESSFUL;
753 status = LFR_SUCCESSFUL;
744
754
745 parameter_dump_packet.sy_lfr_n_cwf_long_f3 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_CWF_LONG_F3 ];
755 parameter_dump_packet.sy_lfr_n_cwf_long_f3 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_CWF_LONG_F3 ];
746
756
747 return status;
757 return status;
748 }
758 }
749
759
750 //**********************
760 //**********************
751 // BURST MODE PARAMETERS
761 // BURST MODE PARAMETERS
752 int set_sy_lfr_b_bp_p0(ccsdsTelecommandPacket_t *TC)
762 int set_sy_lfr_b_bp_p0(ccsdsTelecommandPacket_t *TC)
753 {
763 {
754 /** This function sets the time between two basic parameter sets, in s (SY_LFR_B_BP_P0).
764 /** This function sets the time between two basic parameter sets, in s (SY_LFR_B_BP_P0).
755 *
765 *
756 * @param TC points to the TeleCommand packet that is being processed
766 * @param TC points to the TeleCommand packet that is being processed
757 * @param queue_id is the id of the queue which handles TM related to this execution step
767 * @param queue_id is the id of the queue which handles TM related to this execution step
758 *
768 *
759 */
769 */
760
770
761 int status;
771 int status;
762
772
763 status = LFR_SUCCESSFUL;
773 status = LFR_SUCCESSFUL;
764
774
765 parameter_dump_packet.sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
775 parameter_dump_packet.sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ];
766
776
767 return status;
777 return status;
768 }
778 }
769
779
770 int set_sy_lfr_b_bp_p1( ccsdsTelecommandPacket_t *TC )
780 int set_sy_lfr_b_bp_p1( ccsdsTelecommandPacket_t *TC )
771 {
781 {
772 /** This function sets the time between two basic parameter sets, in s (SY_LFR_B_BP_P1).
782 /** This function sets the time between two basic parameter sets, in s (SY_LFR_B_BP_P1).
773 *
783 *
774 * @param TC points to the TeleCommand packet that is being processed
784 * @param TC points to the TeleCommand packet that is being processed
775 * @param queue_id is the id of the queue which handles TM related to this execution step
785 * @param queue_id is the id of the queue which handles TM related to this execution step
776 *
786 *
777 */
787 */
778
788
779 int status;
789 int status;
780
790
781 status = LFR_SUCCESSFUL;
791 status = LFR_SUCCESSFUL;
782
792
783 parameter_dump_packet.sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
793 parameter_dump_packet.sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ];
784
794
785 return status;
795 return status;
786 }
796 }
787
797
788 //*********************
798 //*********************
789 // SBM1 MODE PARAMETERS
799 // SBM1 MODE PARAMETERS
790 int set_sy_lfr_s1_bp_p0( ccsdsTelecommandPacket_t *TC )
800 int set_sy_lfr_s1_bp_p0( ccsdsTelecommandPacket_t *TC )
791 {
801 {
792 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S1_BP_P0).
802 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S1_BP_P0).
793 *
803 *
794 * @param TC points to the TeleCommand packet that is being processed
804 * @param TC points to the TeleCommand packet that is being processed
795 * @param queue_id is the id of the queue which handles TM related to this execution step
805 * @param queue_id is the id of the queue which handles TM related to this execution step
796 *
806 *
797 */
807 */
798
808
799 int status;
809 int status;
800
810
801 status = LFR_SUCCESSFUL;
811 status = LFR_SUCCESSFUL;
802
812
803 parameter_dump_packet.sy_lfr_s1_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P0 ];
813 parameter_dump_packet.sy_lfr_s1_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P0 ];
804
814
805 return status;
815 return status;
806 }
816 }
807
817
808 int set_sy_lfr_s1_bp_p1( ccsdsTelecommandPacket_t *TC )
818 int set_sy_lfr_s1_bp_p1( ccsdsTelecommandPacket_t *TC )
809 {
819 {
810 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S1_BP_P1).
820 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S1_BP_P1).
811 *
821 *
812 * @param TC points to the TeleCommand packet that is being processed
822 * @param TC points to the TeleCommand packet that is being processed
813 * @param queue_id is the id of the queue which handles TM related to this execution step
823 * @param queue_id is the id of the queue which handles TM related to this execution step
814 *
824 *
815 */
825 */
816
826
817 int status;
827 int status;
818
828
819 status = LFR_SUCCESSFUL;
829 status = LFR_SUCCESSFUL;
820
830
821 parameter_dump_packet.sy_lfr_s1_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P1 ];
831 parameter_dump_packet.sy_lfr_s1_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P1 ];
822
832
823 return status;
833 return status;
824 }
834 }
825
835
826 //*********************
836 //*********************
827 // SBM2 MODE PARAMETERS
837 // SBM2 MODE PARAMETERS
828 int set_sy_lfr_s2_bp_p0( ccsdsTelecommandPacket_t *TC )
838 int set_sy_lfr_s2_bp_p0( ccsdsTelecommandPacket_t *TC )
829 {
839 {
830 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S2_BP_P0).
840 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S2_BP_P0).
831 *
841 *
832 * @param TC points to the TeleCommand packet that is being processed
842 * @param TC points to the TeleCommand packet that is being processed
833 * @param queue_id is the id of the queue which handles TM related to this execution step
843 * @param queue_id is the id of the queue which handles TM related to this execution step
834 *
844 *
835 */
845 */
836
846
837 int status;
847 int status;
838
848
839 status = LFR_SUCCESSFUL;
849 status = LFR_SUCCESSFUL;
840
850
841 parameter_dump_packet.sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
851 parameter_dump_packet.sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ];
842
852
843 return status;
853 return status;
844 }
854 }
845
855
846 int set_sy_lfr_s2_bp_p1( ccsdsTelecommandPacket_t *TC )
856 int set_sy_lfr_s2_bp_p1( ccsdsTelecommandPacket_t *TC )
847 {
857 {
848 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S2_BP_P1).
858 /** This function sets the time between two basic parameter sets, in s (SY_LFR_S2_BP_P1).
849 *
859 *
850 * @param TC points to the TeleCommand packet that is being processed
860 * @param TC points to the TeleCommand packet that is being processed
851 * @param queue_id is the id of the queue which handles TM related to this execution step
861 * @param queue_id is the id of the queue which handles TM related to this execution step
852 *
862 *
853 */
863 */
854
864
855 int status;
865 int status;
856
866
857 status = LFR_SUCCESSFUL;
867 status = LFR_SUCCESSFUL;
858
868
859 parameter_dump_packet.sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
869 parameter_dump_packet.sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ];
860
870
861 return status;
871 return status;
862 }
872 }
863
873
864 //*******************
874 //*******************
865 // TC_LFR_UPDATE_INFO
875 // TC_LFR_UPDATE_INFO
866 unsigned int check_update_info_hk_lfr_mode( unsigned char mode )
876 unsigned int check_update_info_hk_lfr_mode( unsigned char mode )
867 {
877 {
868 unsigned int status;
878 unsigned int status;
869
879
870 if ( (mode == LFR_MODE_STANDBY) || (mode == LFR_MODE_NORMAL)
880 if ( (mode == LFR_MODE_STANDBY) || (mode == LFR_MODE_NORMAL)
871 || (mode == LFR_MODE_BURST)
881 || (mode == LFR_MODE_BURST)
872 || (mode == LFR_MODE_SBM1) || (mode == LFR_MODE_SBM2))
882 || (mode == LFR_MODE_SBM1) || (mode == LFR_MODE_SBM2))
873 {
883 {
874 status = LFR_SUCCESSFUL;
884 status = LFR_SUCCESSFUL;
875 }
885 }
876 else
886 else
877 {
887 {
878 status = LFR_DEFAULT;
888 status = LFR_DEFAULT;
879 }
889 }
880
890
881 return status;
891 return status;
882 }
892 }
883
893
884 unsigned int check_update_info_hk_tds_mode( unsigned char mode )
894 unsigned int check_update_info_hk_tds_mode( unsigned char mode )
885 {
895 {
886 unsigned int status;
896 unsigned int status;
887
897
888 if ( (mode == TDS_MODE_STANDBY) || (mode == TDS_MODE_NORMAL)
898 if ( (mode == TDS_MODE_STANDBY) || (mode == TDS_MODE_NORMAL)
889 || (mode == TDS_MODE_BURST)
899 || (mode == TDS_MODE_BURST)
890 || (mode == TDS_MODE_SBM1) || (mode == TDS_MODE_SBM2)
900 || (mode == TDS_MODE_SBM1) || (mode == TDS_MODE_SBM2)
891 || (mode == TDS_MODE_LFM))
901 || (mode == TDS_MODE_LFM))
892 {
902 {
893 status = LFR_SUCCESSFUL;
903 status = LFR_SUCCESSFUL;
894 }
904 }
895 else
905 else
896 {
906 {
897 status = LFR_DEFAULT;
907 status = LFR_DEFAULT;
898 }
908 }
899
909
900 return status;
910 return status;
901 }
911 }
902
912
903 unsigned int check_update_info_hk_thr_mode( unsigned char mode )
913 unsigned int check_update_info_hk_thr_mode( unsigned char mode )
904 {
914 {
905 unsigned int status;
915 unsigned int status;
906
916
907 if ( (mode == THR_MODE_STANDBY) || (mode == THR_MODE_NORMAL)
917 if ( (mode == THR_MODE_STANDBY) || (mode == THR_MODE_NORMAL)
908 || (mode == THR_MODE_BURST))
918 || (mode == THR_MODE_BURST))
909 {
919 {
910 status = LFR_SUCCESSFUL;
920 status = LFR_SUCCESSFUL;
911 }
921 }
912 else
922 else
913 {
923 {
914 status = LFR_DEFAULT;
924 status = LFR_DEFAULT;
915 }
925 }
916
926
917 return status;
927 return status;
918 }
928 }
919
929
920 void getReactionWheelsFrequencies( ccsdsTelecommandPacket_t *TC )
930 void getReactionWheelsFrequencies( ccsdsTelecommandPacket_t *TC )
921 {
931 {
922 /** This function get the reaction wheels frequencies in the incoming TC_LFR_UPDATE_INFO and copy the values locally.
932 /** This function get the reaction wheels frequencies in the incoming TC_LFR_UPDATE_INFO and copy the values locally.
923 *
933 *
924 * @param TC points to the TeleCommand packet that is being processed
934 * @param TC points to the TeleCommand packet that is being processed
925 *
935 *
926 */
936 */
927
937
928 unsigned char * bytePosPtr; // pointer to the beginning of the incoming TC packet
938 unsigned char * bytePosPtr; // pointer to the beginning of the incoming TC packet
929
939
930 bytePosPtr = (unsigned char *) &TC->packetID;
940 bytePosPtr = (unsigned char *) &TC->packetID;
931
941
932 // cp_rpw_sc_rw1_f1
942 // cp_rpw_sc_rw1_f1
933 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw1_f1,
943 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw1_f1,
934 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F1 ] );
944 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F1 ] );
935
945
936 // cp_rpw_sc_rw1_f2
946 // cp_rpw_sc_rw1_f2
937 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw1_f2,
947 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw1_f2,
938 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F2 ] );
948 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW1_F2 ] );
939
949
940 // cp_rpw_sc_rw2_f1
950 // cp_rpw_sc_rw2_f1
941 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw2_f1,
951 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw2_f1,
942 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F1 ] );
952 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F1 ] );
943
953
944 // cp_rpw_sc_rw2_f2
954 // cp_rpw_sc_rw2_f2
945 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw2_f2,
955 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw2_f2,
946 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F2 ] );
956 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW2_F2 ] );
947
957
948 // cp_rpw_sc_rw3_f1
958 // cp_rpw_sc_rw3_f1
949 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw3_f1,
959 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw3_f1,
950 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F1 ] );
960 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F1 ] );
951
961
952 // cp_rpw_sc_rw3_f2
962 // cp_rpw_sc_rw3_f2
953 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw3_f2,
963 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw3_f2,
954 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F2 ] );
964 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW3_F2 ] );
955
965
956 // cp_rpw_sc_rw4_f1
966 // cp_rpw_sc_rw4_f1
957 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw4_f1,
967 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw4_f1,
958 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F1 ] );
968 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F1 ] );
959
969
960 // cp_rpw_sc_rw4_f2
970 // cp_rpw_sc_rw4_f2
961 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw4_f2,
971 copyFloatByChar( (unsigned char*) &cp_rpw_sc_rw4_f2,
962 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F2 ] );
972 (unsigned char*) &bytePosPtr[ BYTE_POS_UPDATE_INFO_CP_RPW_SC_RW4_F2 ] );
963 }
973 }
964
974
965 void setFBinMask( unsigned char *fbins_mask, float rw_f, unsigned char deltaFreq, unsigned char flag )
975 void setFBinMask( unsigned char *fbins_mask, float rw_f, unsigned char deltaFreq, unsigned char flag )
966 {
976 {
967 /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received.
977 /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received.
968 *
978 *
969 * @param fbins_mask
979 * @param fbins_mask
970 * @param rw_f is the reaction wheel frequency to filter
980 * @param rw_f is the reaction wheel frequency to filter
971 * @param delta_f is the frequency step between the frequency bins, it depends on the frequency channel
981 * @param delta_f is the frequency step between the frequency bins, it depends on the frequency channel
972 * @param flag [true] filtering enabled [false] filtering disabled
982 * @param flag [true] filtering enabled [false] filtering disabled
973 *
983 *
974 * @return void
984 * @return void
975 *
985 *
976 */
986 */
977
987
978 float f_RW_min;
988 float f_RW_min;
979 float f_RW_MAX;
989 float f_RW_MAX;
980 float fi_min;
990 float fi_min;
981 float fi_MAX;
991 float fi_MAX;
982 float fi;
992 float fi;
983 float deltaBelow;
993 float deltaBelow;
984 float deltaAbove;
994 float deltaAbove;
985 int binBelow;
995 int binBelow;
986 int binAbove;
996 int binAbove;
987 int closestBin;
997 int closestBin;
988 unsigned int whichByte;
998 unsigned int whichByte;
989 int selectedByte;
999 int selectedByte;
990 int bin;
1000 int bin;
991 int binToRemove[3];
1001 int binToRemove[NB_BINS_TO_REMOVE];
992 int k;
1002 int k;
993
1003
994 whichByte = 0;
1004 whichByte = 0;
995 bin = 0;
1005 bin = 0;
996
1006
997 binToRemove[0] = -1;
1007 for (k = 0; k < NB_BINS_TO_REMOVE; k++)
998 binToRemove[1] = -1;
1008 {
999 binToRemove[2] = -1;
1009 binToRemove[k] = -1;
1010 }
1000
1011
1001 // compute the frequency range to filter [ rw_f - delta_f/2; rw_f + delta_f/2 ]
1012 // compute the frequency range to filter [ rw_f - delta_f/2; rw_f + delta_f/2 ]
1002 f_RW_min = rw_f - filterPar.sy_lfr_sc_rw_delta_f / 2.;
1013 f_RW_min = rw_f - (filterPar.sy_lfr_sc_rw_delta_f / 2.);
1003 f_RW_MAX = rw_f + filterPar.sy_lfr_sc_rw_delta_f / 2.;
1014 f_RW_MAX = rw_f + (filterPar.sy_lfr_sc_rw_delta_f / 2.);
1004
1015
1005 // compute the index of the frequency bin immediately below rw_f
1016 // compute the index of the frequency bin immediately below rw_f
1006 binBelow = (int) ( floor( ((double) rw_f) / ((double) deltaFreq)) );
1017 binBelow = (int) ( floor( ((double) rw_f) / ((double) deltaFreq)) );
1007 deltaBelow = rw_f - binBelow * deltaFreq;
1018 deltaBelow = rw_f - binBelow * deltaFreq;
1008
1019
1009 // compute the index of the frequency bin immediately above rw_f
1020 // compute the index of the frequency bin immediately above rw_f
1010 binAbove = (int) ( ceil( ((double) rw_f) / ((double) deltaFreq)) );
1021 binAbove = (int) ( ceil( ((double) rw_f) / ((double) deltaFreq)) );
1011 deltaAbove = binAbove * deltaFreq - rw_f;
1022 deltaAbove = binAbove * deltaFreq - rw_f;
1012
1023
1013 // search the closest bin
1024 // search the closest bin
1014 if (deltaAbove > deltaBelow)
1025 if (deltaAbove > deltaBelow)
1015 {
1026 {
1016 closestBin = binBelow;
1027 closestBin = binBelow;
1017 }
1028 }
1018 else
1029 else
1019 {
1030 {
1020 closestBin = binAbove;
1031 closestBin = binAbove;
1021 }
1032 }
1022
1033
1023 // compute the fi interval [fi - deltaFreq * 0.285, fi + deltaFreq * 0.285]
1034 // compute the fi interval [fi - deltaFreq * 0.285, fi + deltaFreq * 0.285]
1024 fi = closestBin * deltaFreq;
1035 fi = closestBin * deltaFreq;
1025 fi_min = fi - (deltaFreq * 0.285);
1036 fi_min = fi - (deltaFreq * FI_INTERVAL_COEFF);
1026 fi_MAX = fi + (deltaFreq * 0.285);
1037 fi_MAX = fi + (deltaFreq * FI_INTERVAL_COEFF);
1027
1038
1028 //**************************************************************************************
1039 //**************************************************************************************
1029 // be careful here, one shall take into account that the bin 0 IS DROPPED in the spectra
1040 // be careful here, one shall take into account that the bin 0 IS DROPPED in the spectra
1030 // thus, the index 0 in a mask corresponds to the bin 1 of the spectrum
1041 // thus, the index 0 in a mask corresponds to the bin 1 of the spectrum
1031 //**************************************************************************************
1042 //**************************************************************************************
1032
1043
1033 // 1. IF [ f_RW_min, f_RW_MAX] is included in [ fi_min; fi_MAX ]
1044 // 1. IF [ f_RW_min, f_RW_MAX] is included in [ fi_min; fi_MAX ]
1034 // => remove f_(i), f_(i-1) and f_(i+1)
1045 // => remove f_(i), f_(i-1) and f_(i+1)
1035 if ( ( f_RW_min > fi_min ) && ( f_RW_MAX < fi_MAX ) )
1046 if ( ( f_RW_min > fi_min ) && ( f_RW_MAX < fi_MAX ) )
1036 {
1047 {
1037 binToRemove[0] = (closestBin - 1) - 1;
1048 binToRemove[0] = (closestBin - 1) - 1;
1038 binToRemove[1] = (closestBin) - 1;
1049 binToRemove[1] = (closestBin) - 1;
1039 binToRemove[2] = (closestBin + 1) - 1;
1050 binToRemove[2] = (closestBin + 1) - 1;
1040 }
1051 }
1041 // 2. ELSE
1052 // 2. ELSE
1042 // => remove the two f_(i) which are around f_RW
1053 // => remove the two f_(i) which are around f_RW
1043 else
1054 else
1044 {
1055 {
1045 binToRemove[0] = (binBelow) - 1;
1056 binToRemove[0] = (binBelow) - 1;
1046 binToRemove[1] = (binAbove) - 1;
1057 binToRemove[1] = (binAbove) - 1;
1047 binToRemove[2] = (-1);
1058 binToRemove[2] = (-1);
1048 }
1059 }
1049
1060
1050 for (k = 0; k < 3; k++)
1061 for (k = 0; k < NB_BINS_TO_REMOVE; k++)
1051 {
1062 {
1052 bin = binToRemove[k];
1063 bin = binToRemove[k];
1053 if ( (bin >= 0) && (bin <= 127) )
1064 if ( (bin >= BIN_MIN) && (bin <= BIN_MAX) )
1054 {
1065 {
1055 if (flag == 1)
1066 if (flag == 1)
1056 {
1067 {
1057 whichByte = (bin >> 3); // division by 8
1068 whichByte = (bin >> SHIFT_3_BITS); // division by 8
1058 selectedByte = ( 1 << (bin - (whichByte * 8)) );
1069 selectedByte = ( 1 << (bin - (whichByte * BITS_PER_BYTE)) );
1059 fbins_mask[15 - whichByte] = fbins_mask[15 - whichByte] & ((unsigned char) (~selectedByte)); // bytes are ordered MSB first in the packets
1070 fbins_mask[BYTES_PER_MASK - 1 - whichByte] =
1071 fbins_mask[BYTES_PER_MASK - 1 - whichByte] & ((unsigned char) (~selectedByte)); // bytes are ordered MSB first in the packets
1060 }
1072 }
1061 }
1073 }
1062 }
1074 }
1063 }
1075 }
1064
1076
1065 void build_sy_lfr_rw_mask( unsigned int channel )
1077 void build_sy_lfr_rw_mask( unsigned int channel )
1066 {
1078 {
1067 unsigned char local_rw_fbins_mask[16];
1079 unsigned char local_rw_fbins_mask[BYTES_PER_MASK];
1068 unsigned char *maskPtr;
1080 unsigned char *maskPtr;
1069 double deltaF;
1081 double deltaF;
1070 unsigned k;
1082 unsigned k;
1071
1083
1072 k = 0;
1084 k = 0;
1073
1085
1074 maskPtr = NULL;
1086 maskPtr = NULL;
1075 deltaF = 1.;
1087 deltaF = DELTAF_F2;
1076
1088
1077 switch (channel)
1089 switch (channel)
1078 {
1090 {
1079 case 0:
1091 case CHANNELF0:
1080 maskPtr = parameter_dump_packet.sy_lfr_rw_mask.fx.f0_word1;
1092 maskPtr = parameter_dump_packet.sy_lfr_rw_mask.fx.f0_word1;
1081 deltaF = 96.;
1093 deltaF = DELTAF_F0;
1082 break;
1094 break;
1083 case 1:
1095 case CHANNELF1:
1084 maskPtr = parameter_dump_packet.sy_lfr_rw_mask.fx.f1_word1;
1096 maskPtr = parameter_dump_packet.sy_lfr_rw_mask.fx.f1_word1;
1085 deltaF = 16.;
1097 deltaF = DELTAF_F1;
1086 break;
1098 break;
1087 case 2:
1099 case CHANNELF2:
1088 maskPtr = parameter_dump_packet.sy_lfr_rw_mask.fx.f2_word1;
1100 maskPtr = parameter_dump_packet.sy_lfr_rw_mask.fx.f2_word1;
1089 deltaF = 1.;
1101 deltaF = DELTAF_F2;
1090 break;
1102 break;
1091 default:
1103 default:
1092 break;
1104 break;
1093 }
1105 }
1094
1106
1095 for (k = 0; k < 16; k++)
1107 for (k = 0; k < BYTES_PER_MASK; k++)
1096 {
1108 {
1097 local_rw_fbins_mask[k] = 0xff;
1109 local_rw_fbins_mask[k] = INT8_ALL_F;
1098 }
1110 }
1099
1111
1100 // RW1 F1
1112 // RW1 F1
1101 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw1_f1, deltaF, (cp_rpw_sc_rw_f_flags & 0x80) >> 7 ); // [1000 0000]
1113 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw1_f1, deltaF, (cp_rpw_sc_rw_f_flags & BIT_RW1_F1) >> SHIFT_7_BITS ); // [1000 0000]
1102
1114
1103 // RW1 F2
1115 // RW1 F2
1104 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw1_f2, deltaF, (cp_rpw_sc_rw_f_flags & 0x40) >> 6 ); // [0100 0000]
1116 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw1_f2, deltaF, (cp_rpw_sc_rw_f_flags & BIT_RW1_F2) >> SHIFT_6_BITS ); // [0100 0000]
1105
1117
1106 // RW2 F1
1118 // RW2 F1
1107 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw2_f1, deltaF, (cp_rpw_sc_rw_f_flags & 0x20) >> 5 ); // [0010 0000]
1119 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw2_f1, deltaF, (cp_rpw_sc_rw_f_flags & BIT_RW2_F1) >> SHIFT_5_BITS ); // [0010 0000]
1108
1120
1109 // RW2 F2
1121 // RW2 F2
1110 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw2_f2, deltaF, (cp_rpw_sc_rw_f_flags & 0x10) >> 4 ); // [0001 0000]
1122 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw2_f2, deltaF, (cp_rpw_sc_rw_f_flags & BIT_RW2_F2) >> SHIFT_4_BITS ); // [0001 0000]
1111
1123
1112 // RW3 F1
1124 // RW3 F1
1113 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw3_f1, deltaF, (cp_rpw_sc_rw_f_flags & 0x08) >> 3 ); // [0000 1000]
1125 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw3_f1, deltaF, (cp_rpw_sc_rw_f_flags & BIT_RW3_F1) >> SHIFT_3_BITS ); // [0000 1000]
1114
1126
1115 // RW3 F2
1127 // RW3 F2
1116 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw3_f2, deltaF, (cp_rpw_sc_rw_f_flags & 0x04) >> 2 ); // [0000 0100]
1128 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw3_f2, deltaF, (cp_rpw_sc_rw_f_flags & BIT_RW3_F2) >> SHIFT_2_BITS ); // [0000 0100]
1117
1129
1118 // RW4 F1
1130 // RW4 F1
1119 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw4_f1, deltaF, (cp_rpw_sc_rw_f_flags & 0x02) >> 1 ); // [0000 0010]
1131 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw4_f1, deltaF, (cp_rpw_sc_rw_f_flags & BIT_RW4_F1) >> 1 ); // [0000 0010]
1120
1132
1121 // RW4 F2
1133 // RW4 F2
1122 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw4_f2, deltaF, (cp_rpw_sc_rw_f_flags & 0x01) ); // [0000 0001]
1134 setFBinMask( local_rw_fbins_mask, cp_rpw_sc_rw4_f2, deltaF, (cp_rpw_sc_rw_f_flags & BIT_RW4_F2) ); // [0000 0001]
1123
1135
1124 // update the value of the fbins related to reaction wheels frequency filtering
1136 // update the value of the fbins related to reaction wheels frequency filtering
1125 if (maskPtr != NULL)
1137 if (maskPtr != NULL)
1126 {
1138 {
1127 for (k = 0; k < 16; k++)
1139 for (k = 0; k < BYTES_PER_MASK; k++)
1128 {
1140 {
1129 maskPtr[k] = local_rw_fbins_mask[k];
1141 maskPtr[k] = local_rw_fbins_mask[k];
1130 }
1142 }
1131 }
1143 }
1132 }
1144 }
1133
1145
1134 void build_sy_lfr_rw_masks( void )
1146 void build_sy_lfr_rw_masks( void )
1135 {
1147 {
1136 build_sy_lfr_rw_mask( 0 );
1148 build_sy_lfr_rw_mask( CHANNELF0 );
1137 build_sy_lfr_rw_mask( 1 );
1149 build_sy_lfr_rw_mask( CHANNELF1 );
1138 build_sy_lfr_rw_mask( 2 );
1150 build_sy_lfr_rw_mask( CHANNELF2 );
1139 }
1151 }
1140
1152
1141 void merge_fbins_masks( void )
1153 void merge_fbins_masks( void )
1142 {
1154 {
1143 unsigned char k;
1155 unsigned char k;
1144
1156
1145 unsigned char *fbins_f0;
1157 unsigned char *fbins_f0;
1146 unsigned char *fbins_f1;
1158 unsigned char *fbins_f1;
1147 unsigned char *fbins_f2;
1159 unsigned char *fbins_f2;
1148 unsigned char *rw_mask_f0;
1160 unsigned char *rw_mask_f0;
1149 unsigned char *rw_mask_f1;
1161 unsigned char *rw_mask_f1;
1150 unsigned char *rw_mask_f2;
1162 unsigned char *rw_mask_f2;
1151
1163
1152 fbins_f0 = parameter_dump_packet.sy_lfr_fbins.fx.f0_word1;
1164 fbins_f0 = parameter_dump_packet.sy_lfr_fbins.fx.f0_word1;
1153 fbins_f1 = parameter_dump_packet.sy_lfr_fbins.fx.f1_word1;
1165 fbins_f1 = parameter_dump_packet.sy_lfr_fbins.fx.f1_word1;
1154 fbins_f2 = parameter_dump_packet.sy_lfr_fbins.fx.f2_word1;
1166 fbins_f2 = parameter_dump_packet.sy_lfr_fbins.fx.f2_word1;
1155 rw_mask_f0 = parameter_dump_packet.sy_lfr_rw_mask.fx.f0_word1;
1167 rw_mask_f0 = parameter_dump_packet.sy_lfr_rw_mask.fx.f0_word1;
1156 rw_mask_f1 = parameter_dump_packet.sy_lfr_rw_mask.fx.f1_word1;
1168 rw_mask_f1 = parameter_dump_packet.sy_lfr_rw_mask.fx.f1_word1;
1157 rw_mask_f2 = parameter_dump_packet.sy_lfr_rw_mask.fx.f2_word1;
1169 rw_mask_f2 = parameter_dump_packet.sy_lfr_rw_mask.fx.f2_word1;
1158
1170
1159 for( k=0; k < 16; k++ )
1171 for( k=0; k < BYTES_PER_MASK; k++ )
1160 {
1172 {
1161 fbins_masks.merged_fbins_mask_f0[k] = fbins_f0[k] & rw_mask_f0[k];
1173 fbins_masks.merged_fbins_mask_f0[k] = fbins_f0[k] & rw_mask_f0[k];
1162 fbins_masks.merged_fbins_mask_f1[k] = fbins_f1[k] & rw_mask_f1[k];
1174 fbins_masks.merged_fbins_mask_f1[k] = fbins_f1[k] & rw_mask_f1[k];
1163 fbins_masks.merged_fbins_mask_f2[k] = fbins_f2[k] & rw_mask_f2[k];
1175 fbins_masks.merged_fbins_mask_f2[k] = fbins_f2[k] & rw_mask_f2[k];
1164 }
1176 }
1165 }
1177 }
1166
1178
1167 //***********
1179 //***********
1168 // FBINS MASK
1180 // FBINS MASK
1169
1181
1170 int set_sy_lfr_fbins( ccsdsTelecommandPacket_t *TC )
1182 int set_sy_lfr_fbins( ccsdsTelecommandPacket_t *TC )
1171 {
1183 {
1172 int status;
1184 int status;
1173 unsigned int k;
1185 unsigned int k;
1174 unsigned char *fbins_mask_dump;
1186 unsigned char *fbins_mask_dump;
1175 unsigned char *fbins_mask_TC;
1187 unsigned char *fbins_mask_TC;
1176
1188
1177 status = LFR_SUCCESSFUL;
1189 status = LFR_SUCCESSFUL;
1178
1190
1179 fbins_mask_dump = parameter_dump_packet.sy_lfr_fbins.raw;
1191 fbins_mask_dump = parameter_dump_packet.sy_lfr_fbins.raw;
1180 fbins_mask_TC = TC->dataAndCRC;
1192 fbins_mask_TC = TC->dataAndCRC;
1181
1193
1182 for (k=0; k < NB_FBINS_MASKS * NB_BYTES_PER_FBINS_MASK; k++)
1194 for (k=0; k < BYTES_PER_MASKS_SET; k++)
1183 {
1195 {
1184 fbins_mask_dump[k] = fbins_mask_TC[k];
1196 fbins_mask_dump[k] = fbins_mask_TC[k];
1185 }
1197 }
1186
1198
1187 return status;
1199 return status;
1188 }
1200 }
1189
1201
1190 //***************************
1202 //***************************
1191 // TC_LFR_LOAD_PAS_FILTER_PAR
1203 // TC_LFR_LOAD_PAS_FILTER_PAR
1192
1204
1193 int check_sy_lfr_filter_parameters( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
1205 int check_sy_lfr_filter_parameters( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
1194 {
1206 {
1195 int flag;
1207 int flag;
1196 rtems_status_code status;
1208 rtems_status_code status;
1197
1209
1198 unsigned char sy_lfr_pas_filter_enabled;
1210 unsigned char sy_lfr_pas_filter_enabled;
1199 unsigned char sy_lfr_pas_filter_modulus;
1211 unsigned char sy_lfr_pas_filter_modulus;
1200 float sy_lfr_pas_filter_tbad;
1212 float sy_lfr_pas_filter_tbad;
1201 unsigned char sy_lfr_pas_filter_offset;
1213 unsigned char sy_lfr_pas_filter_offset;
1202 float sy_lfr_pas_filter_shift;
1214 float sy_lfr_pas_filter_shift;
1203 float sy_lfr_sc_rw_delta_f;
1215 float sy_lfr_sc_rw_delta_f;
1204 char *parPtr;
1216 char *parPtr;
1205
1217
1206 flag = LFR_SUCCESSFUL;
1218 flag = LFR_SUCCESSFUL;
1207 sy_lfr_pas_filter_tbad = 0.0;
1219 sy_lfr_pas_filter_tbad = INIT_FLOAT;
1208 sy_lfr_pas_filter_shift = 0.0;
1220 sy_lfr_pas_filter_shift = INIT_FLOAT;
1209 sy_lfr_sc_rw_delta_f = 0.0;
1221 sy_lfr_sc_rw_delta_f = INIT_FLOAT;
1210 parPtr = NULL;
1222 parPtr = NULL;
1211
1223
1212 //***************
1224 //***************
1213 // get parameters
1225 // get parameters
1214 sy_lfr_pas_filter_enabled = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_ENABLED ] & 0x01; // [0000 0001]
1226 sy_lfr_pas_filter_enabled = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_ENABLED ] & BIT_PAS_FILTER_ENABLED; // [0000 0001]
1215 sy_lfr_pas_filter_modulus = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS ];
1227 sy_lfr_pas_filter_modulus = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS ];
1216 copyFloatByChar(
1228 copyFloatByChar(
1217 (unsigned char*) &sy_lfr_pas_filter_tbad,
1229 (unsigned char*) &sy_lfr_pas_filter_tbad,
1218 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD ]
1230 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD ]
1219 );
1231 );
1220 sy_lfr_pas_filter_offset = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET ];
1232 sy_lfr_pas_filter_offset = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET ];
1221 copyFloatByChar(
1233 copyFloatByChar(
1222 (unsigned char*) &sy_lfr_pas_filter_shift,
1234 (unsigned char*) &sy_lfr_pas_filter_shift,
1223 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT ]
1235 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT ]
1224 );
1236 );
1225 copyFloatByChar(
1237 copyFloatByChar(
1226 (unsigned char*) &sy_lfr_sc_rw_delta_f,
1238 (unsigned char*) &sy_lfr_sc_rw_delta_f,
1227 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F ]
1239 (unsigned char*) &TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_SC_RW_DELTA_F ]
1228 );
1240 );
1229
1241
1230 //******************
1242 //******************
1231 // CHECK CONSISTENCY
1243 // CHECK CONSISTENCY
1232
1244
1233 //**************************
1245 //**************************
1234 // sy_lfr_pas_filter_enabled
1246 // sy_lfr_pas_filter_enabled
1235 // nothing to check, value is 0 or 1
1247 // nothing to check, value is 0 or 1
1236
1248
1237 //**************************
1249 //**************************
1238 // sy_lfr_pas_filter_modulus
1250 // sy_lfr_pas_filter_modulus
1239 if ( (sy_lfr_pas_filter_modulus < 4) || (sy_lfr_pas_filter_modulus > 8) )
1251 if ( (sy_lfr_pas_filter_modulus < MIN_PAS_FILTER_MODULUS) || (sy_lfr_pas_filter_modulus > MAX_PAS_FILTER_MODULUS) )
1240 {
1252 {
1241 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS+10, sy_lfr_pas_filter_modulus );
1253 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS + DATAFIELD_OFFSET, sy_lfr_pas_filter_modulus );
1242 flag = WRONG_APP_DATA;
1254 flag = WRONG_APP_DATA;
1243 }
1255 }
1244
1256
1245 //***********************
1257 //***********************
1246 // sy_lfr_pas_filter_tbad
1258 // sy_lfr_pas_filter_tbad
1247 if ( (sy_lfr_pas_filter_tbad < 0.0) || (sy_lfr_pas_filter_tbad > 4.0) )
1259 if ( (sy_lfr_pas_filter_tbad < MIN_PAS_FILTER_TBAD) || (sy_lfr_pas_filter_tbad > MAX_PAS_FILTER_TBAD) )
1248 {
1260 {
1249 parPtr = (char*) &sy_lfr_pas_filter_tbad;
1261 parPtr = (char*) &sy_lfr_pas_filter_tbad;
1250 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD+10, parPtr[3] );
1262 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_TBAD + DATAFIELD_OFFSET, parPtr[FLOAT_LSBYTE] );
1251 flag = WRONG_APP_DATA;
1263 flag = WRONG_APP_DATA;
1252 }
1264 }
1253
1265
1254 //*************************
1266 //*************************
1255 // sy_lfr_pas_filter_offset
1267 // sy_lfr_pas_filter_offset
1256 if (flag == LFR_SUCCESSFUL)
1268 if (flag == LFR_SUCCESSFUL)
1257 {
1269 {
1258 if ( (sy_lfr_pas_filter_offset < 0) || (sy_lfr_pas_filter_offset > 7) )
1270 if ( (sy_lfr_pas_filter_offset < MIN_PAS_FILTER_OFFSET) || (sy_lfr_pas_filter_offset > MAX_PAS_FILTER_OFFSET) )
1259 {
1271 {
1260 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET+10, sy_lfr_pas_filter_offset );
1272 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_OFFSET + DATAFIELD_OFFSET, sy_lfr_pas_filter_offset );
1261 flag = WRONG_APP_DATA;
1273 flag = WRONG_APP_DATA;
1262 }
1274 }
1263 }
1275 }
1264
1276
1265 //************************
1277 //************************
1266 // sy_lfr_pas_filter_shift
1278 // sy_lfr_pas_filter_shift
1267 if ( (sy_lfr_pas_filter_shift < 0.0) || (sy_lfr_pas_filter_shift > 1.0) )
1279 if (flag == LFR_SUCCESSFUL)
1280 {
1281 if ( (sy_lfr_pas_filter_shift < MIN_PAS_FILTER_SHIFT) || (sy_lfr_pas_filter_shift > MAX_PAS_FILTER_SHIFT) )
1268 {
1282 {
1269 parPtr = (char*) &sy_lfr_pas_filter_shift;
1283 parPtr = (char*) &sy_lfr_pas_filter_shift;
1270 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT+10, parPtr[3] );
1284 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_SHIFT + DATAFIELD_OFFSET, parPtr[FLOAT_LSBYTE] );
1271 flag = WRONG_APP_DATA;
1285 flag = WRONG_APP_DATA;
1272 }
1286 }
1287 }
1288
1289 //*************************************
1290 // check global coherency of the values
1291 if (flag == LFR_SUCCESSFUL)
1292 {
1293 if ( (sy_lfr_pas_filter_tbad + sy_lfr_pas_filter_offset + sy_lfr_pas_filter_shift) > sy_lfr_pas_filter_modulus )
1294 {
1295 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_PAS_FILTER_MODULUS + DATAFIELD_OFFSET, sy_lfr_pas_filter_modulus );
1296 flag = WRONG_APP_DATA;
1297 }
1298 }
1273
1299
1274 //*********************
1300 //*********************
1275 // sy_lfr_sc_rw_delta_f
1301 // sy_lfr_sc_rw_delta_f
1276 // nothing to check, no default value in the ICD
1302 // nothing to check, no default value in the ICD
1277
1303
1278 return flag;
1304 return flag;
1279 }
1305 }
1280
1306
1281 //**************
1307 //**************
1282 // KCOEFFICIENTS
1308 // KCOEFFICIENTS
1283 int set_sy_lfr_kcoeff( ccsdsTelecommandPacket_t *TC,rtems_id queue_id )
1309 int set_sy_lfr_kcoeff( ccsdsTelecommandPacket_t *TC,rtems_id queue_id )
1284 {
1310 {
1285 unsigned int kcoeff;
1311 unsigned int kcoeff;
1286 unsigned short sy_lfr_kcoeff_frequency;
1312 unsigned short sy_lfr_kcoeff_frequency;
1287 unsigned short bin;
1313 unsigned short bin;
1288 unsigned short *freqPtr;
1314 unsigned short *freqPtr;
1289 float *kcoeffPtr_norm;
1315 float *kcoeffPtr_norm;
1290 float *kcoeffPtr_sbm;
1316 float *kcoeffPtr_sbm;
1291 int status;
1317 int status;
1292 unsigned char *kcoeffLoadPtr;
1318 unsigned char *kcoeffLoadPtr;
1293 unsigned char *kcoeffNormPtr;
1319 unsigned char *kcoeffNormPtr;
1294 unsigned char *kcoeffSbmPtr_a;
1320 unsigned char *kcoeffSbmPtr_a;
1295 unsigned char *kcoeffSbmPtr_b;
1321 unsigned char *kcoeffSbmPtr_b;
1296
1322
1297 status = LFR_SUCCESSFUL;
1323 status = LFR_SUCCESSFUL;
1298
1324
1299 kcoeffPtr_norm = NULL;
1325 kcoeffPtr_norm = NULL;
1300 kcoeffPtr_sbm = NULL;
1326 kcoeffPtr_sbm = NULL;
1301 bin = 0;
1327 bin = 0;
1302
1328
1303 freqPtr = (unsigned short *) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY];
1329 freqPtr = (unsigned short *) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY];
1304 sy_lfr_kcoeff_frequency = *freqPtr;
1330 sy_lfr_kcoeff_frequency = *freqPtr;
1305
1331
1306 if ( sy_lfr_kcoeff_frequency >= NB_BINS_COMPRESSED_SM )
1332 if ( sy_lfr_kcoeff_frequency >= NB_BINS_COMPRESSED_SM )
1307 {
1333 {
1308 PRINTF1("ERR *** in set_sy_lfr_kcoeff_frequency *** sy_lfr_kcoeff_frequency = %d\n", sy_lfr_kcoeff_frequency)
1334 PRINTF1("ERR *** in set_sy_lfr_kcoeff_frequency *** sy_lfr_kcoeff_frequency = %d\n", sy_lfr_kcoeff_frequency)
1309 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY + 10 + 1,
1335 status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY + DATAFIELD_OFFSET + 1,
1310 TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY + 1] ); // +1 to get the LSB instead of the MSB
1336 TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_FREQUENCY + 1] ); // +1 to get the LSB instead of the MSB
1311 status = LFR_DEFAULT;
1337 status = LFR_DEFAULT;
1312 }
1338 }
1313 else
1339 else
1314 {
1340 {
1315 if ( ( sy_lfr_kcoeff_frequency >= 0 )
1341 if ( ( sy_lfr_kcoeff_frequency >= 0 )
1316 && ( sy_lfr_kcoeff_frequency < NB_BINS_COMPRESSED_SM_F0 ) )
1342 && ( sy_lfr_kcoeff_frequency < NB_BINS_COMPRESSED_SM_F0 ) )
1317 {
1343 {
1318 kcoeffPtr_norm = k_coeff_intercalib_f0_norm;
1344 kcoeffPtr_norm = k_coeff_intercalib_f0_norm;
1319 kcoeffPtr_sbm = k_coeff_intercalib_f0_sbm;
1345 kcoeffPtr_sbm = k_coeff_intercalib_f0_sbm;
1320 bin = sy_lfr_kcoeff_frequency;
1346 bin = sy_lfr_kcoeff_frequency;
1321 }
1347 }
1322 else if ( ( sy_lfr_kcoeff_frequency >= NB_BINS_COMPRESSED_SM_F0 )
1348 else if ( ( sy_lfr_kcoeff_frequency >= NB_BINS_COMPRESSED_SM_F0 )
1323 && ( sy_lfr_kcoeff_frequency < (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1) ) )
1349 && ( sy_lfr_kcoeff_frequency < (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1) ) )
1324 {
1350 {
1325 kcoeffPtr_norm = k_coeff_intercalib_f1_norm;
1351 kcoeffPtr_norm = k_coeff_intercalib_f1_norm;
1326 kcoeffPtr_sbm = k_coeff_intercalib_f1_sbm;
1352 kcoeffPtr_sbm = k_coeff_intercalib_f1_sbm;
1327 bin = sy_lfr_kcoeff_frequency - NB_BINS_COMPRESSED_SM_F0;
1353 bin = sy_lfr_kcoeff_frequency - NB_BINS_COMPRESSED_SM_F0;
1328 }
1354 }
1329 else if ( ( sy_lfr_kcoeff_frequency >= (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1) )
1355 else if ( ( sy_lfr_kcoeff_frequency >= (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1) )
1330 && ( sy_lfr_kcoeff_frequency < (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 + NB_BINS_COMPRESSED_SM_F2) ) )
1356 && ( sy_lfr_kcoeff_frequency < (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1 + NB_BINS_COMPRESSED_SM_F2) ) )
1331 {
1357 {
1332 kcoeffPtr_norm = k_coeff_intercalib_f2;
1358 kcoeffPtr_norm = k_coeff_intercalib_f2;
1333 kcoeffPtr_sbm = NULL;
1359 kcoeffPtr_sbm = NULL;
1334 bin = sy_lfr_kcoeff_frequency - (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1);
1360 bin = sy_lfr_kcoeff_frequency - (NB_BINS_COMPRESSED_SM_F0 + NB_BINS_COMPRESSED_SM_F1);
1335 }
1361 }
1336 }
1362 }
1337
1363
1338 if (kcoeffPtr_norm != NULL ) // update K coefficient for NORMAL data products
1364 if (kcoeffPtr_norm != NULL ) // update K coefficient for NORMAL data products
1339 {
1365 {
1340 for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++)
1366 for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++)
1341 {
1367 {
1342 // destination
1368 // destination
1343 kcoeffNormPtr = (unsigned char*) &kcoeffPtr_norm[ (bin * NB_K_COEFF_PER_BIN) + kcoeff ];
1369 kcoeffNormPtr = (unsigned char*) &kcoeffPtr_norm[ (bin * NB_K_COEFF_PER_BIN) + kcoeff ];
1344 // source
1370 // source
1345 kcoeffLoadPtr = (unsigned char*) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_1 + NB_BYTES_PER_FLOAT * kcoeff];
1371 kcoeffLoadPtr = (unsigned char*) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_1 + (NB_BYTES_PER_FLOAT * kcoeff)];
1346 // copy source to destination
1372 // copy source to destination
1347 copyFloatByChar( kcoeffNormPtr, kcoeffLoadPtr );
1373 copyFloatByChar( kcoeffNormPtr, kcoeffLoadPtr );
1348 }
1374 }
1349 }
1375 }
1350
1376
1351 if (kcoeffPtr_sbm != NULL ) // update K coefficient for SBM data products
1377 if (kcoeffPtr_sbm != NULL ) // update K coefficient for SBM data products
1352 {
1378 {
1353 for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++)
1379 for (kcoeff=0; kcoeff<NB_K_COEFF_PER_BIN; kcoeff++)
1354 {
1380 {
1355 // destination
1381 // destination
1356 kcoeffSbmPtr_a= (unsigned char*) &kcoeffPtr_sbm[ ( (bin * NB_K_COEFF_PER_BIN) + kcoeff) * 2 ];
1382 kcoeffSbmPtr_a= (unsigned char*) &kcoeffPtr_sbm[ ( (bin * NB_K_COEFF_PER_BIN) + kcoeff) * SBM_COEFF_PER_NORM_COEFF ];
1357 kcoeffSbmPtr_b= (unsigned char*) &kcoeffPtr_sbm[ ( (bin * NB_K_COEFF_PER_BIN) + kcoeff) * 2 + 1 ];
1383 kcoeffSbmPtr_b= (unsigned char*) &kcoeffPtr_sbm[ (((bin * NB_K_COEFF_PER_BIN) + kcoeff) * SBM_KCOEFF_PER_NORM_KCOEFF) + 1 ];
1358 // source
1384 // source
1359 kcoeffLoadPtr = (unsigned char*) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_1 + NB_BYTES_PER_FLOAT * kcoeff];
1385 kcoeffLoadPtr = (unsigned char*) &TC->dataAndCRC[DATAFIELD_POS_SY_LFR_KCOEFF_1 + (NB_BYTES_PER_FLOAT * kcoeff)];
1360 // copy source to destination
1386 // copy source to destination
1361 copyFloatByChar( kcoeffSbmPtr_a, kcoeffLoadPtr );
1387 copyFloatByChar( kcoeffSbmPtr_a, kcoeffLoadPtr );
1362 copyFloatByChar( kcoeffSbmPtr_b, kcoeffLoadPtr );
1388 copyFloatByChar( kcoeffSbmPtr_b, kcoeffLoadPtr );
1363 }
1389 }
1364 }
1390 }
1365
1391
1366 // print_k_coeff();
1392 // print_k_coeff();
1367
1393
1368 return status;
1394 return status;
1369 }
1395 }
1370
1396
1371 void copyFloatByChar( unsigned char *destination, unsigned char *source )
1397 void copyFloatByChar( unsigned char *destination, unsigned char *source )
1372 {
1398 {
1373 destination[0] = source[0];
1399 destination[BYTE_0] = source[BYTE_0];
1374 destination[1] = source[1];
1400 destination[BYTE_1] = source[BYTE_1];
1375 destination[2] = source[2];
1401 destination[BYTE_2] = source[BYTE_2];
1376 destination[3] = source[3];
1402 destination[BYTE_3] = source[BYTE_3];
1377 }
1403 }
1378
1404
1379 void floatToChar( float value, unsigned char* ptr)
1405 void floatToChar( float value, unsigned char* ptr)
1380 {
1406 {
1381 unsigned char* valuePtr;
1407 unsigned char* valuePtr;
1382
1408
1383 valuePtr = (unsigned char*) &value;
1409 valuePtr = (unsigned char*) &value;
1384 ptr[0] = valuePtr[0];
1410 ptr[BYTE_0] = valuePtr[BYTE_0];
1385 ptr[1] = valuePtr[1];
1411 ptr[BYTE_1] = valuePtr[BYTE_1];
1386 ptr[2] = valuePtr[2];
1412 ptr[BYTE_2] = valuePtr[BYTE_2];
1387 ptr[3] = valuePtr[3];
1413 ptr[BYTE_3] = valuePtr[BYTE_3];
1388 }
1414 }
1389
1415
1390 //**********
1416 //**********
1391 // init dump
1417 // init dump
1392
1418
1393 void init_parameter_dump( void )
1419 void init_parameter_dump( void )
1394 {
1420 {
1395 /** This function initialize the parameter_dump_packet global variable with default values.
1421 /** This function initialize the parameter_dump_packet global variable with default values.
1396 *
1422 *
1397 */
1423 */
1398
1424
1399 unsigned int k;
1425 unsigned int k;
1400
1426
1401 parameter_dump_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
1427 parameter_dump_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
1402 parameter_dump_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
1428 parameter_dump_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
1403 parameter_dump_packet.reserved = CCSDS_RESERVED;
1429 parameter_dump_packet.reserved = CCSDS_RESERVED;
1404 parameter_dump_packet.userApplication = CCSDS_USER_APP;
1430 parameter_dump_packet.userApplication = CCSDS_USER_APP;
1405 parameter_dump_packet.packetID[0] = (unsigned char) (APID_TM_PARAMETER_DUMP >> 8);
1431 parameter_dump_packet.packetID[0] = (unsigned char) (APID_TM_PARAMETER_DUMP >> SHIFT_1_BYTE);
1406 parameter_dump_packet.packetID[1] = (unsigned char) APID_TM_PARAMETER_DUMP;
1432 parameter_dump_packet.packetID[1] = (unsigned char) APID_TM_PARAMETER_DUMP;
1407 parameter_dump_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1433 parameter_dump_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1408 parameter_dump_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1434 parameter_dump_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1409 parameter_dump_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_PARAMETER_DUMP >> 8);
1435 parameter_dump_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_PARAMETER_DUMP >> SHIFT_1_BYTE);
1410 parameter_dump_packet.packetLength[1] = (unsigned char) PACKET_LENGTH_PARAMETER_DUMP;
1436 parameter_dump_packet.packetLength[1] = (unsigned char) PACKET_LENGTH_PARAMETER_DUMP;
1411 // DATA FIELD HEADER
1437 // DATA FIELD HEADER
1412 parameter_dump_packet.spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
1438 parameter_dump_packet.spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
1413 parameter_dump_packet.serviceType = TM_TYPE_PARAMETER_DUMP;
1439 parameter_dump_packet.serviceType = TM_TYPE_PARAMETER_DUMP;
1414 parameter_dump_packet.serviceSubType = TM_SUBTYPE_PARAMETER_DUMP;
1440 parameter_dump_packet.serviceSubType = TM_SUBTYPE_PARAMETER_DUMP;
1415 parameter_dump_packet.destinationID = TM_DESTINATION_ID_GROUND;
1441 parameter_dump_packet.destinationID = TM_DESTINATION_ID_GROUND;
1416 parameter_dump_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
1442 parameter_dump_packet.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
1417 parameter_dump_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
1443 parameter_dump_packet.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
1418 parameter_dump_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
1444 parameter_dump_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
1419 parameter_dump_packet.time[3] = (unsigned char) (time_management_regs->coarse_time);
1445 parameter_dump_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
1420 parameter_dump_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
1446 parameter_dump_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
1421 parameter_dump_packet.time[5] = (unsigned char) (time_management_regs->fine_time);
1447 parameter_dump_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
1422 parameter_dump_packet.sid = SID_PARAMETER_DUMP;
1448 parameter_dump_packet.sid = SID_PARAMETER_DUMP;
1423
1449
1424 //******************
1450 //******************
1425 // COMMON PARAMETERS
1451 // COMMON PARAMETERS
1426 parameter_dump_packet.sy_lfr_common_parameters_spare = DEFAULT_SY_LFR_COMMON0;
1452 parameter_dump_packet.sy_lfr_common_parameters_spare = DEFAULT_SY_LFR_COMMON0;
1427 parameter_dump_packet.sy_lfr_common_parameters = DEFAULT_SY_LFR_COMMON1;
1453 parameter_dump_packet.sy_lfr_common_parameters = DEFAULT_SY_LFR_COMMON1;
1428
1454
1429 //******************
1455 //******************
1430 // NORMAL PARAMETERS
1456 // NORMAL PARAMETERS
1431 parameter_dump_packet.sy_lfr_n_swf_l[0] = (unsigned char) (DFLT_SY_LFR_N_SWF_L >> 8);
1457 parameter_dump_packet.sy_lfr_n_swf_l[0] = (unsigned char) (DFLT_SY_LFR_N_SWF_L >> SHIFT_1_BYTE);
1432 parameter_dump_packet.sy_lfr_n_swf_l[1] = (unsigned char) (DFLT_SY_LFR_N_SWF_L );
1458 parameter_dump_packet.sy_lfr_n_swf_l[1] = (unsigned char) (DFLT_SY_LFR_N_SWF_L );
1433 parameter_dump_packet.sy_lfr_n_swf_p[0] = (unsigned char) (DFLT_SY_LFR_N_SWF_P >> 8);
1459 parameter_dump_packet.sy_lfr_n_swf_p[0] = (unsigned char) (DFLT_SY_LFR_N_SWF_P >> SHIFT_1_BYTE);
1434 parameter_dump_packet.sy_lfr_n_swf_p[1] = (unsigned char) (DFLT_SY_LFR_N_SWF_P );
1460 parameter_dump_packet.sy_lfr_n_swf_p[1] = (unsigned char) (DFLT_SY_LFR_N_SWF_P );
1435 parameter_dump_packet.sy_lfr_n_asm_p[0] = (unsigned char) (DFLT_SY_LFR_N_ASM_P >> 8);
1461 parameter_dump_packet.sy_lfr_n_asm_p[0] = (unsigned char) (DFLT_SY_LFR_N_ASM_P >> SHIFT_1_BYTE);
1436 parameter_dump_packet.sy_lfr_n_asm_p[1] = (unsigned char) (DFLT_SY_LFR_N_ASM_P );
1462 parameter_dump_packet.sy_lfr_n_asm_p[1] = (unsigned char) (DFLT_SY_LFR_N_ASM_P );
1437 parameter_dump_packet.sy_lfr_n_bp_p0 = (unsigned char) DFLT_SY_LFR_N_BP_P0;
1463 parameter_dump_packet.sy_lfr_n_bp_p0 = (unsigned char) DFLT_SY_LFR_N_BP_P0;
1438 parameter_dump_packet.sy_lfr_n_bp_p1 = (unsigned char) DFLT_SY_LFR_N_BP_P1;
1464 parameter_dump_packet.sy_lfr_n_bp_p1 = (unsigned char) DFLT_SY_LFR_N_BP_P1;
1439 parameter_dump_packet.sy_lfr_n_cwf_long_f3 = (unsigned char) DFLT_SY_LFR_N_CWF_LONG_F3;
1465 parameter_dump_packet.sy_lfr_n_cwf_long_f3 = (unsigned char) DFLT_SY_LFR_N_CWF_LONG_F3;
1440
1466
1441 //*****************
1467 //*****************
1442 // BURST PARAMETERS
1468 // BURST PARAMETERS
1443 parameter_dump_packet.sy_lfr_b_bp_p0 = (unsigned char) DEFAULT_SY_LFR_B_BP_P0;
1469 parameter_dump_packet.sy_lfr_b_bp_p0 = (unsigned char) DEFAULT_SY_LFR_B_BP_P0;
1444 parameter_dump_packet.sy_lfr_b_bp_p1 = (unsigned char) DEFAULT_SY_LFR_B_BP_P1;
1470 parameter_dump_packet.sy_lfr_b_bp_p1 = (unsigned char) DEFAULT_SY_LFR_B_BP_P1;
1445
1471
1446 //****************
1472 //****************
1447 // SBM1 PARAMETERS
1473 // SBM1 PARAMETERS
1448 parameter_dump_packet.sy_lfr_s1_bp_p0 = (unsigned char) DEFAULT_SY_LFR_S1_BP_P0; // min value is 0.25 s for the period
1474 parameter_dump_packet.sy_lfr_s1_bp_p0 = (unsigned char) DEFAULT_SY_LFR_S1_BP_P0; // min value is 0.25 s for the period
1449 parameter_dump_packet.sy_lfr_s1_bp_p1 = (unsigned char) DEFAULT_SY_LFR_S1_BP_P1;
1475 parameter_dump_packet.sy_lfr_s1_bp_p1 = (unsigned char) DEFAULT_SY_LFR_S1_BP_P1;
1450
1476
1451 //****************
1477 //****************
1452 // SBM2 PARAMETERS
1478 // SBM2 PARAMETERS
1453 parameter_dump_packet.sy_lfr_s2_bp_p0 = (unsigned char) DEFAULT_SY_LFR_S2_BP_P0;
1479 parameter_dump_packet.sy_lfr_s2_bp_p0 = (unsigned char) DEFAULT_SY_LFR_S2_BP_P0;
1454 parameter_dump_packet.sy_lfr_s2_bp_p1 = (unsigned char) DEFAULT_SY_LFR_S2_BP_P1;
1480 parameter_dump_packet.sy_lfr_s2_bp_p1 = (unsigned char) DEFAULT_SY_LFR_S2_BP_P1;
1455
1481
1456 //************
1482 //************
1457 // FBINS MASKS
1483 // FBINS MASKS
1458 for (k=0; k < NB_FBINS_MASKS * NB_BYTES_PER_FBINS_MASK; k++)
1484 for (k=0; k < BYTES_PER_MASKS_SET; k++)
1459 {
1485 {
1460 parameter_dump_packet.sy_lfr_fbins.raw[k] = 0xff;
1486 parameter_dump_packet.sy_lfr_fbins.raw[k] = INT8_ALL_F;
1461 }
1487 }
1462
1488
1463 // PAS FILTER PARAMETERS
1489 // PAS FILTER PARAMETERS
1464 parameter_dump_packet.pa_rpw_spare8_2 = 0x00;
1490 parameter_dump_packet.pa_rpw_spare8_2 = INIT_CHAR;
1465 parameter_dump_packet.spare_sy_lfr_pas_filter_enabled = 0x00;
1491 parameter_dump_packet.spare_sy_lfr_pas_filter_enabled = INIT_CHAR;
1466 parameter_dump_packet.sy_lfr_pas_filter_modulus = DEFAULT_SY_LFR_PAS_FILTER_MODULUS;
1492 parameter_dump_packet.sy_lfr_pas_filter_modulus = DEFAULT_SY_LFR_PAS_FILTER_MODULUS;
1467 floatToChar( DEFAULT_SY_LFR_PAS_FILTER_TBAD, parameter_dump_packet.sy_lfr_pas_filter_tbad );
1493 floatToChar( DEFAULT_SY_LFR_PAS_FILTER_TBAD, parameter_dump_packet.sy_lfr_pas_filter_tbad );
1468 parameter_dump_packet.sy_lfr_pas_filter_offset = DEFAULT_SY_LFR_PAS_FILTER_OFFSET;
1494 parameter_dump_packet.sy_lfr_pas_filter_offset = DEFAULT_SY_LFR_PAS_FILTER_OFFSET;
1469 floatToChar( DEFAULT_SY_LFR_PAS_FILTER_SHIFT, parameter_dump_packet.sy_lfr_pas_filter_shift );
1495 floatToChar( DEFAULT_SY_LFR_PAS_FILTER_SHIFT, parameter_dump_packet.sy_lfr_pas_filter_shift );
1470 floatToChar( DEFAULT_SY_LFR_SC_RW_DELTA_F, parameter_dump_packet.sy_lfr_sc_rw_delta_f );
1496 floatToChar( DEFAULT_SY_LFR_SC_RW_DELTA_F, parameter_dump_packet.sy_lfr_sc_rw_delta_f );
1471
1497
1472 // LFR_RW_MASK
1498 // LFR_RW_MASK
1473 for (k=0; k < NB_FBINS_MASKS * NB_BYTES_PER_FBINS_MASK; k++)
1499 for (k=0; k < BYTES_PER_MASKS_SET; k++)
1474 {
1500 {
1475 parameter_dump_packet.sy_lfr_rw_mask.raw[k] = 0xff;
1501 parameter_dump_packet.sy_lfr_rw_mask.raw[k] = INT8_ALL_F;
1476 }
1502 }
1477
1503
1478 // once the reaction wheels masks have been initialized, they have to be merged with the fbins masks
1504 // once the reaction wheels masks have been initialized, they have to be merged with the fbins masks
1479 merge_fbins_masks();
1505 merge_fbins_masks();
1480 }
1506 }
1481
1507
1482 void init_kcoefficients_dump( void )
1508 void init_kcoefficients_dump( void )
1483 {
1509 {
1484 init_kcoefficients_dump_packet( &kcoefficients_dump_1, 1, 30 );
1510 init_kcoefficients_dump_packet( &kcoefficients_dump_1, PKTNR_1, KCOEFF_BLK_NR_PKT1 );
1485 init_kcoefficients_dump_packet( &kcoefficients_dump_2, 2, 6 );
1511 init_kcoefficients_dump_packet( &kcoefficients_dump_2, PKTNR_2, KCOEFF_BLK_NR_PKT2 );
1486
1512
1487 kcoefficient_node_1.previous = NULL;
1513 kcoefficient_node_1.previous = NULL;
1488 kcoefficient_node_1.next = NULL;
1514 kcoefficient_node_1.next = NULL;
1489 kcoefficient_node_1.sid = TM_CODE_K_DUMP;
1515 kcoefficient_node_1.sid = TM_CODE_K_DUMP;
1490 kcoefficient_node_1.coarseTime = 0x00;
1516 kcoefficient_node_1.coarseTime = INIT_CHAR;
1491 kcoefficient_node_1.fineTime = 0x00;
1517 kcoefficient_node_1.fineTime = INIT_CHAR;
1492 kcoefficient_node_1.buffer_address = (int) &kcoefficients_dump_1;
1518 kcoefficient_node_1.buffer_address = (int) &kcoefficients_dump_1;
1493 kcoefficient_node_1.status = 0x00;
1519 kcoefficient_node_1.status = INIT_CHAR;
1494
1520
1495 kcoefficient_node_2.previous = NULL;
1521 kcoefficient_node_2.previous = NULL;
1496 kcoefficient_node_2.next = NULL;
1522 kcoefficient_node_2.next = NULL;
1497 kcoefficient_node_2.sid = TM_CODE_K_DUMP;
1523 kcoefficient_node_2.sid = TM_CODE_K_DUMP;
1498 kcoefficient_node_2.coarseTime = 0x00;
1524 kcoefficient_node_2.coarseTime = INIT_CHAR;
1499 kcoefficient_node_2.fineTime = 0x00;
1525 kcoefficient_node_2.fineTime = INIT_CHAR;
1500 kcoefficient_node_2.buffer_address = (int) &kcoefficients_dump_2;
1526 kcoefficient_node_2.buffer_address = (int) &kcoefficients_dump_2;
1501 kcoefficient_node_2.status = 0x00;
1527 kcoefficient_node_2.status = INIT_CHAR;
1502 }
1528 }
1503
1529
1504 void init_kcoefficients_dump_packet( Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump, unsigned char pkt_nr, unsigned char blk_nr )
1530 void init_kcoefficients_dump_packet( Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump, unsigned char pkt_nr, unsigned char blk_nr )
1505 {
1531 {
1506 unsigned int k;
1532 unsigned int k;
1507 unsigned int packetLength;
1533 unsigned int packetLength;
1508
1534
1509 packetLength = blk_nr * 130 + 20 - CCSDS_TC_TM_PACKET_OFFSET; // 4 bytes for the CCSDS header
1535 packetLength =
1536 ((blk_nr * KCOEFF_BLK_SIZE) + BYTE_POS_KCOEFFICIENTS_PARAMETES) - CCSDS_TC_TM_PACKET_OFFSET; // 4 bytes for the CCSDS header
1510
1537
1511 kcoefficients_dump->targetLogicalAddress = CCSDS_DESTINATION_ID;
1538 kcoefficients_dump->targetLogicalAddress = CCSDS_DESTINATION_ID;
1512 kcoefficients_dump->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1539 kcoefficients_dump->protocolIdentifier = CCSDS_PROTOCOLE_ID;
1513 kcoefficients_dump->reserved = CCSDS_RESERVED;
1540 kcoefficients_dump->reserved = CCSDS_RESERVED;
1514 kcoefficients_dump->userApplication = CCSDS_USER_APP;
1541 kcoefficients_dump->userApplication = CCSDS_USER_APP;
1515 kcoefficients_dump->packetID[0] = (unsigned char) (APID_TM_PARAMETER_DUMP >> 8);;
1542 kcoefficients_dump->packetID[0] = (unsigned char) (APID_TM_PARAMETER_DUMP >> SHIFT_1_BYTE);
1516 kcoefficients_dump->packetID[1] = (unsigned char) APID_TM_PARAMETER_DUMP;;
1543 kcoefficients_dump->packetID[1] = (unsigned char) APID_TM_PARAMETER_DUMP;
1517 kcoefficients_dump->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1544 kcoefficients_dump->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
1518 kcoefficients_dump->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1545 kcoefficients_dump->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
1519 kcoefficients_dump->packetLength[0] = (unsigned char) (packetLength >> 8);
1546 kcoefficients_dump->packetLength[0] = (unsigned char) (packetLength >> SHIFT_1_BYTE);
1520 kcoefficients_dump->packetLength[1] = (unsigned char) packetLength;
1547 kcoefficients_dump->packetLength[1] = (unsigned char) packetLength;
1521 // DATA FIELD HEADER
1548 // DATA FIELD HEADER
1522 kcoefficients_dump->spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
1549 kcoefficients_dump->spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2;
1523 kcoefficients_dump->serviceType = TM_TYPE_K_DUMP;
1550 kcoefficients_dump->serviceType = TM_TYPE_K_DUMP;
1524 kcoefficients_dump->serviceSubType = TM_SUBTYPE_K_DUMP;
1551 kcoefficients_dump->serviceSubType = TM_SUBTYPE_K_DUMP;
1525 kcoefficients_dump->destinationID= TM_DESTINATION_ID_GROUND;
1552 kcoefficients_dump->destinationID= TM_DESTINATION_ID_GROUND;
1526 kcoefficients_dump->time[0] = 0x00;
1553 kcoefficients_dump->time[BYTE_0] = INIT_CHAR;
1527 kcoefficients_dump->time[1] = 0x00;
1554 kcoefficients_dump->time[BYTE_1] = INIT_CHAR;
1528 kcoefficients_dump->time[2] = 0x00;
1555 kcoefficients_dump->time[BYTE_2] = INIT_CHAR;
1529 kcoefficients_dump->time[3] = 0x00;
1556 kcoefficients_dump->time[BYTE_3] = INIT_CHAR;
1530 kcoefficients_dump->time[4] = 0x00;
1557 kcoefficients_dump->time[BYTE_4] = INIT_CHAR;
1531 kcoefficients_dump->time[5] = 0x00;
1558 kcoefficients_dump->time[BYTE_5] = INIT_CHAR;
1532 kcoefficients_dump->sid = SID_K_DUMP;
1559 kcoefficients_dump->sid = SID_K_DUMP;
1533
1560
1534 kcoefficients_dump->pkt_cnt = 2;
1561 kcoefficients_dump->pkt_cnt = KCOEFF_PKTCNT;
1535 kcoefficients_dump->pkt_nr = pkt_nr;
1562 kcoefficients_dump->pkt_nr = PKTNR_1;
1536 kcoefficients_dump->blk_nr = blk_nr;
1563 kcoefficients_dump->blk_nr = blk_nr;
1537
1564
1538 //******************
1565 //******************
1539 // SOURCE DATA repeated N times with N in [0 .. PA_LFR_KCOEFF_BLK_NR]
1566 // SOURCE DATA repeated N times with N in [0 .. PA_LFR_KCOEFF_BLK_NR]
1540 // one blk is 2 + 4 * 32 = 130 bytes, 30 blks max in one packet (30 * 130 = 3900)
1567 // one blk is 2 + 4 * 32 = 130 bytes, 30 blks max in one packet (30 * 130 = 3900)
1541 for (k=0; k<3900; k++)
1568 for (k=0; k<(KCOEFF_BLK_NR_PKT1 * KCOEFF_BLK_SIZE); k++)
1542 {
1569 {
1543 kcoefficients_dump->kcoeff_blks[k] = 0x00;
1570 kcoefficients_dump->kcoeff_blks[k] = INIT_CHAR;
1544 }
1571 }
1545 }
1572 }
1546
1573
1547 void increment_seq_counter_destination_id_dump( unsigned char *packet_sequence_control, unsigned char destination_id )
1574 void increment_seq_counter_destination_id_dump( unsigned char *packet_sequence_control, unsigned char destination_id )
1548 {
1575 {
1549 /** This function increment the packet sequence control parameter of a TC, depending on its destination ID.
1576 /** This function increment the packet sequence control parameter of a TC, depending on its destination ID.
1550 *
1577 *
1551 * @param packet_sequence_control points to the packet sequence control which will be incremented
1578 * @param packet_sequence_control points to the packet sequence control which will be incremented
1552 * @param destination_id is the destination ID of the TM, there is one counter by destination ID
1579 * @param destination_id is the destination ID of the TM, there is one counter by destination ID
1553 *
1580 *
1554 * If the destination ID is not known, a dedicated counter is incremented.
1581 * If the destination ID is not known, a dedicated counter is incremented.
1555 *
1582 *
1556 */
1583 */
1557
1584
1558 unsigned short sequence_cnt;
1585 unsigned short sequence_cnt;
1559 unsigned short segmentation_grouping_flag;
1586 unsigned short segmentation_grouping_flag;
1560 unsigned short new_packet_sequence_control;
1587 unsigned short new_packet_sequence_control;
1561 unsigned char i;
1588 unsigned char i;
1562
1589
1563 switch (destination_id)
1590 switch (destination_id)
1564 {
1591 {
1565 case SID_TC_GROUND:
1592 case SID_TC_GROUND:
1566 i = GROUND;
1593 i = GROUND;
1567 break;
1594 break;
1568 case SID_TC_MISSION_TIMELINE:
1595 case SID_TC_MISSION_TIMELINE:
1569 i = MISSION_TIMELINE;
1596 i = MISSION_TIMELINE;
1570 break;
1597 break;
1571 case SID_TC_TC_SEQUENCES:
1598 case SID_TC_TC_SEQUENCES:
1572 i = TC_SEQUENCES;
1599 i = TC_SEQUENCES;
1573 break;
1600 break;
1574 case SID_TC_RECOVERY_ACTION_CMD:
1601 case SID_TC_RECOVERY_ACTION_CMD:
1575 i = RECOVERY_ACTION_CMD;
1602 i = RECOVERY_ACTION_CMD;
1576 break;
1603 break;
1577 case SID_TC_BACKUP_MISSION_TIMELINE:
1604 case SID_TC_BACKUP_MISSION_TIMELINE:
1578 i = BACKUP_MISSION_TIMELINE;
1605 i = BACKUP_MISSION_TIMELINE;
1579 break;
1606 break;
1580 case SID_TC_DIRECT_CMD:
1607 case SID_TC_DIRECT_CMD:
1581 i = DIRECT_CMD;
1608 i = DIRECT_CMD;
1582 break;
1609 break;
1583 case SID_TC_SPARE_GRD_SRC1:
1610 case SID_TC_SPARE_GRD_SRC1:
1584 i = SPARE_GRD_SRC1;
1611 i = SPARE_GRD_SRC1;
1585 break;
1612 break;
1586 case SID_TC_SPARE_GRD_SRC2:
1613 case SID_TC_SPARE_GRD_SRC2:
1587 i = SPARE_GRD_SRC2;
1614 i = SPARE_GRD_SRC2;
1588 break;
1615 break;
1589 case SID_TC_OBCP:
1616 case SID_TC_OBCP:
1590 i = OBCP;
1617 i = OBCP;
1591 break;
1618 break;
1592 case SID_TC_SYSTEM_CONTROL:
1619 case SID_TC_SYSTEM_CONTROL:
1593 i = SYSTEM_CONTROL;
1620 i = SYSTEM_CONTROL;
1594 break;
1621 break;
1595 case SID_TC_AOCS:
1622 case SID_TC_AOCS:
1596 i = AOCS;
1623 i = AOCS;
1597 break;
1624 break;
1598 case SID_TC_RPW_INTERNAL:
1625 case SID_TC_RPW_INTERNAL:
1599 i = RPW_INTERNAL;
1626 i = RPW_INTERNAL;
1600 break;
1627 break;
1601 default:
1628 default:
1602 i = GROUND;
1629 i = GROUND;
1603 break;
1630 break;
1604 }
1631 }
1605
1632
1606 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << 8;
1633 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << SHIFT_1_BYTE;
1607 sequence_cnt = sequenceCounters_TM_DUMP[ i ] & 0x3fff;
1634 sequence_cnt = sequenceCounters_TM_DUMP[ i ] & SEQ_CNT_MASK;
1608
1635
1609 new_packet_sequence_control = segmentation_grouping_flag | sequence_cnt ;
1636 new_packet_sequence_control = segmentation_grouping_flag | sequence_cnt ;
1610
1637
1611 packet_sequence_control[0] = (unsigned char) (new_packet_sequence_control >> 8);
1638 packet_sequence_control[0] = (unsigned char) (new_packet_sequence_control >> SHIFT_1_BYTE);
1612 packet_sequence_control[1] = (unsigned char) (new_packet_sequence_control );
1639 packet_sequence_control[1] = (unsigned char) (new_packet_sequence_control );
1613
1640
1614 // increment the sequence counter
1641 // increment the sequence counter
1615 if ( sequenceCounters_TM_DUMP[ i ] < SEQ_CNT_MAX )
1642 if ( sequenceCounters_TM_DUMP[ i ] < SEQ_CNT_MAX )
1616 {
1643 {
1617 sequenceCounters_TM_DUMP[ i ] = sequenceCounters_TM_DUMP[ i ] + 1;
1644 sequenceCounters_TM_DUMP[ i ] = sequenceCounters_TM_DUMP[ i ] + 1;
1618 }
1645 }
1619 else
1646 else
1620 {
1647 {
1621 sequenceCounters_TM_DUMP[ i ] = 0;
1648 sequenceCounters_TM_DUMP[ i ] = 0;
1622 }
1649 }
1623 }
1650 }
@@ -1,514 +1,514
1 /** Functions to send TM packets related to TC parsing and execution.
1 /** Functions to send TM packets related to TC parsing and execution.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 * A group of functions to send appropriate TM packets after parsing and execution:
6 * A group of functions to send appropriate TM packets after parsing and execution:
7 * - TM_LFR_TC_EXE_SUCCESS
7 * - TM_LFR_TC_EXE_SUCCESS
8 * - TM_LFR_TC_EXE_INCONSISTENT
8 * - TM_LFR_TC_EXE_INCONSISTENT
9 * - TM_LFR_TC_EXE_NOT_EXECUTABLE
9 * - TM_LFR_TC_EXE_NOT_EXECUTABLE
10 * - TM_LFR_TC_EXE_NOT_IMPLEMENTED
10 * - TM_LFR_TC_EXE_NOT_IMPLEMENTED
11 * - TM_LFR_TC_EXE_ERROR
11 * - TM_LFR_TC_EXE_ERROR
12 * - TM_LFR_TC_EXE_CORRUPTED
12 * - TM_LFR_TC_EXE_CORRUPTED
13 *
13 *
14 */
14 */
15
15
16 #include "tm_lfr_tc_exe.h"
16 #include "tm_lfr_tc_exe.h"
17
17
18 int send_tm_lfr_tc_exe_success( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
18 int send_tm_lfr_tc_exe_success( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
19 {
19 {
20 /** This function sends a TM_LFR_TC_EXE_SUCCESS packet in the dedicated RTEMS message queue.
20 /** This function sends a TM_LFR_TC_EXE_SUCCESS packet in the dedicated RTEMS message queue.
21 *
21 *
22 * @param TC points to the TeleCommand packet that is being processed
22 * @param TC points to the TeleCommand packet that is being processed
23 * @param queue_id is the id of the queue which handles TM
23 * @param queue_id is the id of the queue which handles TM
24 *
24 *
25 * @return RTEMS directive status code:
25 * @return RTEMS directive status code:
26 * - RTEMS_SUCCESSFUL - message sent successfully
26 * - RTEMS_SUCCESSFUL - message sent successfully
27 * - RTEMS_INVALID_ID - invalid queue id
27 * - RTEMS_INVALID_ID - invalid queue id
28 * - RTEMS_INVALID_SIZE - invalid message size
28 * - RTEMS_INVALID_SIZE - invalid message size
29 * - RTEMS_INVALID_ADDRESS - buffer is NULL
29 * - RTEMS_INVALID_ADDRESS - buffer is NULL
30 * - RTEMS_UNSATISFIED - out of message buffers
30 * - RTEMS_UNSATISFIED - out of message buffers
31 * - RTEMS_TOO_MANY - queue s limit has been reached
31 * - RTEMS_TOO_MANY - queue s limit has been reached
32 *
32 *
33 */
33 */
34
34
35 rtems_status_code status;
35 rtems_status_code status;
36 Packet_TM_LFR_TC_EXE_SUCCESS_t TM;
36 Packet_TM_LFR_TC_EXE_SUCCESS_t TM;
37 unsigned char messageSize;
37 unsigned char messageSize;
38
38
39 TM.targetLogicalAddress = CCSDS_DESTINATION_ID;
39 TM.targetLogicalAddress = CCSDS_DESTINATION_ID;
40 TM.protocolIdentifier = CCSDS_PROTOCOLE_ID;
40 TM.protocolIdentifier = CCSDS_PROTOCOLE_ID;
41 TM.reserved = DEFAULT_RESERVED;
41 TM.reserved = DEFAULT_RESERVED;
42 TM.userApplication = CCSDS_USER_APP;
42 TM.userApplication = CCSDS_USER_APP;
43 // PACKET HEADER
43 // PACKET HEADER
44 TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> 8);
44 TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> SHIFT_1_BYTE);
45 TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE );
45 TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE );
46 increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID );
46 increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID );
47 TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_SUCCESS >> 8);
47 TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_SUCCESS >> SHIFT_1_BYTE);
48 TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_SUCCESS );
48 TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_SUCCESS );
49 // DATA FIELD HEADER
49 // DATA FIELD HEADER
50 TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
50 TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
51 TM.serviceType = TM_TYPE_TC_EXE;
51 TM.serviceType = TM_TYPE_TC_EXE;
52 TM.serviceSubType = TM_SUBTYPE_EXE_OK;
52 TM.serviceSubType = TM_SUBTYPE_EXE_OK;
53 TM.destinationID = TC->sourceID;
53 TM.destinationID = TC->sourceID;
54 TM.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
54 TM.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
55 TM.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
55 TM.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
56 TM.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
56 TM.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
57 TM.time[3] = (unsigned char) (time_management_regs->coarse_time);
57 TM.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
58 TM.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
58 TM.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
59 TM.time[5] = (unsigned char) (time_management_regs->fine_time);
59 TM.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
60 //
60 //
61 TM.telecommand_pkt_id[0] = TC->packetID[0];
61 TM.telecommand_pkt_id[0] = TC->packetID[0];
62 TM.telecommand_pkt_id[1] = TC->packetID[1];
62 TM.telecommand_pkt_id[1] = TC->packetID[1];
63 TM.pkt_seq_control[0] = TC->packetSequenceControl[0];
63 TM.pkt_seq_control[0] = TC->packetSequenceControl[0];
64 TM.pkt_seq_control[1] = TC->packetSequenceControl[1];
64 TM.pkt_seq_control[1] = TC->packetSequenceControl[1];
65
65
66 messageSize = PACKET_LENGTH_TC_EXE_SUCCESS + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
66 messageSize = PACKET_LENGTH_TC_EXE_SUCCESS + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
67
67
68 // SEND DATA
68 // SEND DATA
69 status = rtems_message_queue_send( queue_id, &TM, messageSize);
69 status = rtems_message_queue_send( queue_id, &TM, messageSize);
70 if (status != RTEMS_SUCCESSFUL) {
70 if (status != RTEMS_SUCCESSFUL) {
71 PRINTF("in send_tm_lfr_tc_exe_success *** ERR\n")
71 PRINTF("in send_tm_lfr_tc_exe_success *** ERR\n")
72 }
72 }
73
73
74 // UPDATE HK FIELDS
74 // UPDATE HK FIELDS
75 update_last_TC_exe( TC, TM.time );
75 update_last_TC_exe( TC, TM.time );
76
76
77 return status;
77 return status;
78 }
78 }
79
79
80 int send_tm_lfr_tc_exe_inconsistent( ccsdsTelecommandPacket_t *TC, rtems_id queue_id,
80 int send_tm_lfr_tc_exe_inconsistent( ccsdsTelecommandPacket_t *TC, rtems_id queue_id,
81 unsigned char byte_position, unsigned char rcv_value )
81 unsigned char byte_position, unsigned char rcv_value )
82 {
82 {
83 /** This function sends a TM_LFR_TC_EXE_INCONSISTENT packet in the dedicated RTEMS message queue.
83 /** This function sends a TM_LFR_TC_EXE_INCONSISTENT packet in the dedicated RTEMS message queue.
84 *
84 *
85 * @param TC points to the TeleCommand packet that is being processed
85 * @param TC points to the TeleCommand packet that is being processed
86 * @param queue_id is the id of the queue which handles TM
86 * @param queue_id is the id of the queue which handles TM
87 * @param byte_position is the byte position of the MSB of the parameter that has been seen as inconsistent
87 * @param byte_position is the byte position of the MSB of the parameter that has been seen as inconsistent
88 * @param rcv_value is the value of the LSB of the parameter that has been detected as inconsistent
88 * @param rcv_value is the value of the LSB of the parameter that has been detected as inconsistent
89 *
89 *
90 * @return RTEMS directive status code:
90 * @return RTEMS directive status code:
91 * - RTEMS_SUCCESSFUL - message sent successfully
91 * - RTEMS_SUCCESSFUL - message sent successfully
92 * - RTEMS_INVALID_ID - invalid queue id
92 * - RTEMS_INVALID_ID - invalid queue id
93 * - RTEMS_INVALID_SIZE - invalid message size
93 * - RTEMS_INVALID_SIZE - invalid message size
94 * - RTEMS_INVALID_ADDRESS - buffer is NULL
94 * - RTEMS_INVALID_ADDRESS - buffer is NULL
95 * - RTEMS_UNSATISFIED - out of message buffers
95 * - RTEMS_UNSATISFIED - out of message buffers
96 * - RTEMS_TOO_MANY - queue s limit has been reached
96 * - RTEMS_TOO_MANY - queue s limit has been reached
97 *
97 *
98 */
98 */
99
99
100 rtems_status_code status;
100 rtems_status_code status;
101 Packet_TM_LFR_TC_EXE_INCONSISTENT_t TM;
101 Packet_TM_LFR_TC_EXE_INCONSISTENT_t TM;
102 unsigned char messageSize;
102 unsigned char messageSize;
103
103
104 TM.targetLogicalAddress = CCSDS_DESTINATION_ID;
104 TM.targetLogicalAddress = CCSDS_DESTINATION_ID;
105 TM.protocolIdentifier = CCSDS_PROTOCOLE_ID;
105 TM.protocolIdentifier = CCSDS_PROTOCOLE_ID;
106 TM.reserved = DEFAULT_RESERVED;
106 TM.reserved = DEFAULT_RESERVED;
107 TM.userApplication = CCSDS_USER_APP;
107 TM.userApplication = CCSDS_USER_APP;
108 // PACKET HEADER
108 // PACKET HEADER
109 TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> 8);
109 TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> SHIFT_1_BYTE);
110 TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE );
110 TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE );
111 increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID );
111 increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID );
112 TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_INCONSISTENT >> 8);
112 TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_INCONSISTENT >> SHIFT_1_BYTE);
113 TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_INCONSISTENT );
113 TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_INCONSISTENT );
114 // DATA FIELD HEADER
114 // DATA FIELD HEADER
115 TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
115 TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
116 TM.serviceType = TM_TYPE_TC_EXE;
116 TM.serviceType = TM_TYPE_TC_EXE;
117 TM.serviceSubType = TM_SUBTYPE_EXE_NOK;
117 TM.serviceSubType = TM_SUBTYPE_EXE_NOK;
118 TM.destinationID = TC->sourceID;
118 TM.destinationID = TC->sourceID;
119 TM.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
119 TM.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
120 TM.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
120 TM.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
121 TM.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
121 TM.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
122 TM.time[3] = (unsigned char) (time_management_regs->coarse_time);
122 TM.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
123 TM.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
123 TM.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
124 TM.time[5] = (unsigned char) (time_management_regs->fine_time);
124 TM.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
125 //
125 //
126 TM.tc_failure_code[0] = (char) (WRONG_APP_DATA >> 8);
126 TM.tc_failure_code[0] = (char) (WRONG_APP_DATA >> SHIFT_1_BYTE);
127 TM.tc_failure_code[1] = (char) (WRONG_APP_DATA );
127 TM.tc_failure_code[1] = (char) (WRONG_APP_DATA );
128 TM.telecommand_pkt_id[0] = TC->packetID[0];
128 TM.telecommand_pkt_id[0] = TC->packetID[0];
129 TM.telecommand_pkt_id[1] = TC->packetID[1];
129 TM.telecommand_pkt_id[1] = TC->packetID[1];
130 TM.pkt_seq_control[0] = TC->packetSequenceControl[0];
130 TM.pkt_seq_control[0] = TC->packetSequenceControl[0];
131 TM.pkt_seq_control[1] = TC->packetSequenceControl[1];
131 TM.pkt_seq_control[1] = TC->packetSequenceControl[1];
132 TM.tc_service = TC->serviceType; // type of the rejected TC
132 TM.tc_service = TC->serviceType; // type of the rejected TC
133 TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC
133 TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC
134 TM.byte_position = byte_position;
134 TM.byte_position = byte_position;
135 TM.rcv_value = (unsigned char) rcv_value;
135 TM.rcv_value = (unsigned char) rcv_value;
136
136
137 messageSize = PACKET_LENGTH_TC_EXE_INCONSISTENT + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
137 messageSize = PACKET_LENGTH_TC_EXE_INCONSISTENT + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
138
138
139 // SEND DATA
139 // SEND DATA
140 status = rtems_message_queue_send( queue_id, &TM, messageSize);
140 status = rtems_message_queue_send( queue_id, &TM, messageSize);
141 if (status != RTEMS_SUCCESSFUL) {
141 if (status != RTEMS_SUCCESSFUL) {
142 PRINTF("in send_tm_lfr_tc_exe_inconsistent *** ERR\n")
142 PRINTF("in send_tm_lfr_tc_exe_inconsistent *** ERR\n")
143 }
143 }
144
144
145 // UPDATE HK FIELDS
145 // UPDATE HK FIELDS
146 update_last_TC_rej( TC, TM.time );
146 update_last_TC_rej( TC, TM.time );
147
147
148 return status;
148 return status;
149 }
149 }
150
150
151 int send_tm_lfr_tc_exe_not_executable( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
151 int send_tm_lfr_tc_exe_not_executable( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
152 {
152 {
153 /** This function sends a TM_LFR_TC_EXE_NOT_EXECUTABLE packet in the dedicated RTEMS message queue.
153 /** This function sends a TM_LFR_TC_EXE_NOT_EXECUTABLE packet in the dedicated RTEMS message queue.
154 *
154 *
155 * @param TC points to the TeleCommand packet that is being processed
155 * @param TC points to the TeleCommand packet that is being processed
156 * @param queue_id is the id of the queue which handles TM
156 * @param queue_id is the id of the queue which handles TM
157 *
157 *
158 * @return RTEMS directive status code:
158 * @return RTEMS directive status code:
159 * - RTEMS_SUCCESSFUL - message sent successfully
159 * - RTEMS_SUCCESSFUL - message sent successfully
160 * - RTEMS_INVALID_ID - invalid queue id
160 * - RTEMS_INVALID_ID - invalid queue id
161 * - RTEMS_INVALID_SIZE - invalid message size
161 * - RTEMS_INVALID_SIZE - invalid message size
162 * - RTEMS_INVALID_ADDRESS - buffer is NULL
162 * - RTEMS_INVALID_ADDRESS - buffer is NULL
163 * - RTEMS_UNSATISFIED - out of message buffers
163 * - RTEMS_UNSATISFIED - out of message buffers
164 * - RTEMS_TOO_MANY - queue s limit has been reached
164 * - RTEMS_TOO_MANY - queue s limit has been reached
165 *
165 *
166 */
166 */
167
167
168 rtems_status_code status;
168 rtems_status_code status;
169 Packet_TM_LFR_TC_EXE_NOT_EXECUTABLE_t TM;
169 Packet_TM_LFR_TC_EXE_NOT_EXECUTABLE_t TM;
170 unsigned char messageSize;
170 unsigned char messageSize;
171
171
172 TM.targetLogicalAddress = CCSDS_DESTINATION_ID;
172 TM.targetLogicalAddress = CCSDS_DESTINATION_ID;
173 TM.protocolIdentifier = CCSDS_PROTOCOLE_ID;
173 TM.protocolIdentifier = CCSDS_PROTOCOLE_ID;
174 TM.reserved = DEFAULT_RESERVED;
174 TM.reserved = DEFAULT_RESERVED;
175 TM.userApplication = CCSDS_USER_APP;
175 TM.userApplication = CCSDS_USER_APP;
176 // PACKET HEADER
176 // PACKET HEADER
177 TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> 8);
177 TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> SHIFT_1_BYTE);
178 TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE );
178 TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE );
179 increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID );
179 increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID );
180 TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_NOT_EXECUTABLE >> 8);
180 TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_NOT_EXECUTABLE >> SHIFT_1_BYTE);
181 TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_NOT_EXECUTABLE );
181 TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_NOT_EXECUTABLE );
182 // DATA FIELD HEADER
182 // DATA FIELD HEADER
183 TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
183 TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
184 TM.serviceType = TM_TYPE_TC_EXE;
184 TM.serviceType = TM_TYPE_TC_EXE;
185 TM.serviceSubType = TM_SUBTYPE_EXE_NOK;
185 TM.serviceSubType = TM_SUBTYPE_EXE_NOK;
186 TM.destinationID = TC->sourceID; // default destination id
186 TM.destinationID = TC->sourceID; // default destination id
187 TM.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
187 TM.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
188 TM.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
188 TM.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
189 TM.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
189 TM.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
190 TM.time[3] = (unsigned char) (time_management_regs->coarse_time);
190 TM.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
191 TM.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
191 TM.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
192 TM.time[5] = (unsigned char) (time_management_regs->fine_time);
192 TM.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
193 //
193 //
194 TM.tc_failure_code[0] = (char) (TC_NOT_EXE >> 8);
194 TM.tc_failure_code[0] = (char) (TC_NOT_EXE >> SHIFT_1_BYTE);
195 TM.tc_failure_code[1] = (char) (TC_NOT_EXE );
195 TM.tc_failure_code[1] = (char) (TC_NOT_EXE );
196 TM.telecommand_pkt_id[0] = TC->packetID[0];
196 TM.telecommand_pkt_id[0] = TC->packetID[0];
197 TM.telecommand_pkt_id[1] = TC->packetID[1];
197 TM.telecommand_pkt_id[1] = TC->packetID[1];
198 TM.pkt_seq_control[0] = TC->packetSequenceControl[0];
198 TM.pkt_seq_control[0] = TC->packetSequenceControl[0];
199 TM.pkt_seq_control[1] = TC->packetSequenceControl[1];
199 TM.pkt_seq_control[1] = TC->packetSequenceControl[1];
200 TM.tc_service = TC->serviceType; // type of the rejected TC
200 TM.tc_service = TC->serviceType; // type of the rejected TC
201 TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC
201 TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC
202 TM.lfr_status_word[0] = housekeeping_packet.lfr_status_word[0];
202 TM.lfr_status_word[0] = housekeeping_packet.lfr_status_word[0];
203 TM.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1];
203 TM.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1];
204
204
205 messageSize = PACKET_LENGTH_TC_EXE_NOT_EXECUTABLE + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
205 messageSize = PACKET_LENGTH_TC_EXE_NOT_EXECUTABLE + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
206
206
207 // SEND DATA
207 // SEND DATA
208 status = rtems_message_queue_send( queue_id, &TM, messageSize);
208 status = rtems_message_queue_send( queue_id, &TM, messageSize);
209 if (status != RTEMS_SUCCESSFUL) {
209 if (status != RTEMS_SUCCESSFUL) {
210 PRINTF("in send_tm_lfr_tc_exe_not_executable *** ERR\n")
210 PRINTF("in send_tm_lfr_tc_exe_not_executable *** ERR\n")
211 }
211 }
212
212
213 // UPDATE HK FIELDS
213 // UPDATE HK FIELDS
214 update_last_TC_rej( TC, TM.time );
214 update_last_TC_rej( TC, TM.time );
215
215
216 return status;
216 return status;
217 }
217 }
218
218
219 int send_tm_lfr_tc_exe_not_implemented( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time )
219 int send_tm_lfr_tc_exe_not_implemented( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time )
220 {
220 {
221 /** This function sends a TM_LFR_TC_EXE_NOT_IMPLEMENTED packet in the dedicated RTEMS message queue.
221 /** This function sends a TM_LFR_TC_EXE_NOT_IMPLEMENTED packet in the dedicated RTEMS message queue.
222 *
222 *
223 * @param TC points to the TeleCommand packet that is being processed
223 * @param TC points to the TeleCommand packet that is being processed
224 * @param queue_id is the id of the queue which handles TM
224 * @param queue_id is the id of the queue which handles TM
225 *
225 *
226 * @return RTEMS directive status code:
226 * @return RTEMS directive status code:
227 * - RTEMS_SUCCESSFUL - message sent successfully
227 * - RTEMS_SUCCESSFUL - message sent successfully
228 * - RTEMS_INVALID_ID - invalid queue id
228 * - RTEMS_INVALID_ID - invalid queue id
229 * - RTEMS_INVALID_SIZE - invalid message size
229 * - RTEMS_INVALID_SIZE - invalid message size
230 * - RTEMS_INVALID_ADDRESS - buffer is NULL
230 * - RTEMS_INVALID_ADDRESS - buffer is NULL
231 * - RTEMS_UNSATISFIED - out of message buffers
231 * - RTEMS_UNSATISFIED - out of message buffers
232 * - RTEMS_TOO_MANY - queue s limit has been reached
232 * - RTEMS_TOO_MANY - queue s limit has been reached
233 *
233 *
234 */
234 */
235
235
236 rtems_status_code status;
236 rtems_status_code status;
237 Packet_TM_LFR_TC_EXE_NOT_IMPLEMENTED_t TM;
237 Packet_TM_LFR_TC_EXE_NOT_IMPLEMENTED_t TM;
238 unsigned char messageSize;
238 unsigned char messageSize;
239
239
240 TM.targetLogicalAddress = CCSDS_DESTINATION_ID;
240 TM.targetLogicalAddress = CCSDS_DESTINATION_ID;
241 TM.protocolIdentifier = CCSDS_PROTOCOLE_ID;
241 TM.protocolIdentifier = CCSDS_PROTOCOLE_ID;
242 TM.reserved = DEFAULT_RESERVED;
242 TM.reserved = DEFAULT_RESERVED;
243 TM.userApplication = CCSDS_USER_APP;
243 TM.userApplication = CCSDS_USER_APP;
244 // PACKET HEADER
244 // PACKET HEADER
245 TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> 8);
245 TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> SHIFT_1_BYTE);
246 TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE );
246 TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE );
247 increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID );
247 increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID );
248 TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_NOT_IMPLEMENTED >> 8);
248 TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_NOT_IMPLEMENTED >> SHIFT_1_BYTE);
249 TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_NOT_IMPLEMENTED );
249 TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_NOT_IMPLEMENTED );
250 // DATA FIELD HEADER
250 // DATA FIELD HEADER
251 TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
251 TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
252 TM.serviceType = TM_TYPE_TC_EXE;
252 TM.serviceType = TM_TYPE_TC_EXE;
253 TM.serviceSubType = TM_SUBTYPE_EXE_NOK;
253 TM.serviceSubType = TM_SUBTYPE_EXE_NOK;
254 TM.destinationID = TC->sourceID; // default destination id
254 TM.destinationID = TC->sourceID; // default destination id
255 TM.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
255 TM.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
256 TM.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
256 TM.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
257 TM.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
257 TM.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
258 TM.time[3] = (unsigned char) (time_management_regs->coarse_time);
258 TM.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
259 TM.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
259 TM.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
260 TM.time[5] = (unsigned char) (time_management_regs->fine_time);
260 TM.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
261 //
261 //
262 TM.tc_failure_code[0] = (char) (FUNCT_NOT_IMPL >> 8);
262 TM.tc_failure_code[0] = (char) (FUNCT_NOT_IMPL >> SHIFT_1_BYTE);
263 TM.tc_failure_code[1] = (char) (FUNCT_NOT_IMPL );
263 TM.tc_failure_code[1] = (char) (FUNCT_NOT_IMPL );
264 TM.telecommand_pkt_id[0] = TC->packetID[0];
264 TM.telecommand_pkt_id[0] = TC->packetID[0];
265 TM.telecommand_pkt_id[1] = TC->packetID[1];
265 TM.telecommand_pkt_id[1] = TC->packetID[1];
266 TM.pkt_seq_control[0] = TC->packetSequenceControl[0];
266 TM.pkt_seq_control[0] = TC->packetSequenceControl[0];
267 TM.pkt_seq_control[1] = TC->packetSequenceControl[1];
267 TM.pkt_seq_control[1] = TC->packetSequenceControl[1];
268 TM.tc_service = TC->serviceType; // type of the rejected TC
268 TM.tc_service = TC->serviceType; // type of the rejected TC
269 TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC
269 TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC
270
270
271 messageSize = PACKET_LENGTH_TC_EXE_NOT_IMPLEMENTED + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
271 messageSize = PACKET_LENGTH_TC_EXE_NOT_IMPLEMENTED + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
272
272
273 // SEND DATA
273 // SEND DATA
274 status = rtems_message_queue_send( queue_id, &TM, messageSize);
274 status = rtems_message_queue_send( queue_id, &TM, messageSize);
275 if (status != RTEMS_SUCCESSFUL) {
275 if (status != RTEMS_SUCCESSFUL) {
276 PRINTF("in send_tm_lfr_tc_exe_not_implemented *** ERR\n")
276 PRINTF("in send_tm_lfr_tc_exe_not_implemented *** ERR\n")
277 }
277 }
278
278
279 // UPDATE HK FIELDS
279 // UPDATE HK FIELDS
280 update_last_TC_rej( TC, TM.time );
280 update_last_TC_rej( TC, TM.time );
281
281
282 return status;
282 return status;
283 }
283 }
284
284
285 int send_tm_lfr_tc_exe_error( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
285 int send_tm_lfr_tc_exe_error( ccsdsTelecommandPacket_t *TC, rtems_id queue_id )
286 {
286 {
287 /** This function sends a TM_LFR_TC_EXE_ERROR packet in the dedicated RTEMS message queue.
287 /** This function sends a TM_LFR_TC_EXE_ERROR packet in the dedicated RTEMS message queue.
288 *
288 *
289 * @param TC points to the TeleCommand packet that is being processed
289 * @param TC points to the TeleCommand packet that is being processed
290 * @param queue_id is the id of the queue which handles TM
290 * @param queue_id is the id of the queue which handles TM
291 *
291 *
292 * @return RTEMS directive status code:
292 * @return RTEMS directive status code:
293 * - RTEMS_SUCCESSFUL - message sent successfully
293 * - RTEMS_SUCCESSFUL - message sent successfully
294 * - RTEMS_INVALID_ID - invalid queue id
294 * - RTEMS_INVALID_ID - invalid queue id
295 * - RTEMS_INVALID_SIZE - invalid message size
295 * - RTEMS_INVALID_SIZE - invalid message size
296 * - RTEMS_INVALID_ADDRESS - buffer is NULL
296 * - RTEMS_INVALID_ADDRESS - buffer is NULL
297 * - RTEMS_UNSATISFIED - out of message buffers
297 * - RTEMS_UNSATISFIED - out of message buffers
298 * - RTEMS_TOO_MANY - queue s limit has been reached
298 * - RTEMS_TOO_MANY - queue s limit has been reached
299 *
299 *
300 */
300 */
301
301
302 rtems_status_code status;
302 rtems_status_code status;
303 Packet_TM_LFR_TC_EXE_ERROR_t TM;
303 Packet_TM_LFR_TC_EXE_ERROR_t TM;
304 unsigned char messageSize;
304 unsigned char messageSize;
305
305
306 TM.targetLogicalAddress = CCSDS_DESTINATION_ID;
306 TM.targetLogicalAddress = CCSDS_DESTINATION_ID;
307 TM.protocolIdentifier = CCSDS_PROTOCOLE_ID;
307 TM.protocolIdentifier = CCSDS_PROTOCOLE_ID;
308 TM.reserved = DEFAULT_RESERVED;
308 TM.reserved = DEFAULT_RESERVED;
309 TM.userApplication = CCSDS_USER_APP;
309 TM.userApplication = CCSDS_USER_APP;
310 // PACKET HEADER
310 // PACKET HEADER
311 TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> 8);
311 TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> SHIFT_1_BYTE);
312 TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE );
312 TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE );
313 increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID );
313 increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID );
314 TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_ERROR >> 8);
314 TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_ERROR >> SHIFT_1_BYTE);
315 TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_ERROR );
315 TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_ERROR );
316 // DATA FIELD HEADER
316 // DATA FIELD HEADER
317 TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
317 TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
318 TM.serviceType = TM_TYPE_TC_EXE;
318 TM.serviceType = TM_TYPE_TC_EXE;
319 TM.serviceSubType = TM_SUBTYPE_EXE_NOK;
319 TM.serviceSubType = TM_SUBTYPE_EXE_NOK;
320 TM.destinationID = TC->sourceID; // default destination id
320 TM.destinationID = TC->sourceID; // default destination id
321 TM.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
321 TM.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
322 TM.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
322 TM.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
323 TM.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
323 TM.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
324 TM.time[3] = (unsigned char) (time_management_regs->coarse_time);
324 TM.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
325 TM.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
325 TM.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
326 TM.time[5] = (unsigned char) (time_management_regs->fine_time);
326 TM.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
327 //
327 //
328 TM.tc_failure_code[0] = (char) (FAIL_DETECTED >> 8);
328 TM.tc_failure_code[0] = (char) (FAIL_DETECTED >> SHIFT_1_BYTE);
329 TM.tc_failure_code[1] = (char) (FAIL_DETECTED );
329 TM.tc_failure_code[1] = (char) (FAIL_DETECTED );
330 TM.telecommand_pkt_id[0] = TC->packetID[0];
330 TM.telecommand_pkt_id[0] = TC->packetID[0];
331 TM.telecommand_pkt_id[1] = TC->packetID[1];
331 TM.telecommand_pkt_id[1] = TC->packetID[1];
332 TM.pkt_seq_control[0] = TC->packetSequenceControl[0];
332 TM.pkt_seq_control[0] = TC->packetSequenceControl[0];
333 TM.pkt_seq_control[1] = TC->packetSequenceControl[1];
333 TM.pkt_seq_control[1] = TC->packetSequenceControl[1];
334 TM.tc_service = TC->serviceType; // type of the rejected TC
334 TM.tc_service = TC->serviceType; // type of the rejected TC
335 TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC
335 TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC
336
336
337 messageSize = PACKET_LENGTH_TC_EXE_ERROR + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
337 messageSize = PACKET_LENGTH_TC_EXE_ERROR + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
338
338
339 // SEND DATA
339 // SEND DATA
340 status = rtems_message_queue_send( queue_id, &TM, messageSize);
340 status = rtems_message_queue_send( queue_id, &TM, messageSize);
341 if (status != RTEMS_SUCCESSFUL) {
341 if (status != RTEMS_SUCCESSFUL) {
342 PRINTF("in send_tm_lfr_tc_exe_error *** ERR\n")
342 PRINTF("in send_tm_lfr_tc_exe_error *** ERR\n")
343 }
343 }
344
344
345 // UPDATE HK FIELDS
345 // UPDATE HK FIELDS
346 update_last_TC_rej( TC, TM.time );
346 update_last_TC_rej( TC, TM.time );
347
347
348 return status;
348 return status;
349 }
349 }
350
350
351 int send_tm_lfr_tc_exe_corrupted(ccsdsTelecommandPacket_t *TC, rtems_id queue_id,
351 int send_tm_lfr_tc_exe_corrupted(ccsdsTelecommandPacket_t *TC, rtems_id queue_id,
352 unsigned char *computed_CRC, unsigned char *currentTC_LEN_RCV,
352 unsigned char *computed_CRC, unsigned char *currentTC_LEN_RCV,
353 unsigned char destinationID )
353 unsigned char destinationID )
354 {
354 {
355 /** This function sends a TM_LFR_TC_EXE_CORRUPTED packet in the dedicated RTEMS message queue.
355 /** This function sends a TM_LFR_TC_EXE_CORRUPTED packet in the dedicated RTEMS message queue.
356 *
356 *
357 * @param TC points to the TeleCommand packet that is being processed
357 * @param TC points to the TeleCommand packet that is being processed
358 * @param queue_id is the id of the queue which handles TM
358 * @param queue_id is the id of the queue which handles TM
359 * @param computed_CRC points to a buffer of two bytes containing the CRC computed during the parsing of the TeleCommand
359 * @param computed_CRC points to a buffer of two bytes containing the CRC computed during the parsing of the TeleCommand
360 * @param currentTC_LEN_RCV points to a buffer of two bytes containing a packet size field computed on the received data
360 * @param currentTC_LEN_RCV points to a buffer of two bytes containing a packet size field computed on the received data
361 *
361 *
362 * @return RTEMS directive status code:
362 * @return RTEMS directive status code:
363 * - RTEMS_SUCCESSFUL - message sent successfully
363 * - RTEMS_SUCCESSFUL - message sent successfully
364 * - RTEMS_INVALID_ID - invalid queue id
364 * - RTEMS_INVALID_ID - invalid queue id
365 * - RTEMS_INVALID_SIZE - invalid message size
365 * - RTEMS_INVALID_SIZE - invalid message size
366 * - RTEMS_INVALID_ADDRESS - buffer is NULL
366 * - RTEMS_INVALID_ADDRESS - buffer is NULL
367 * - RTEMS_UNSATISFIED - out of message buffers
367 * - RTEMS_UNSATISFIED - out of message buffers
368 * - RTEMS_TOO_MANY - queue s limit has been reached
368 * - RTEMS_TOO_MANY - queue s limit has been reached
369 *
369 *
370 */
370 */
371
371
372 rtems_status_code status;
372 rtems_status_code status;
373 Packet_TM_LFR_TC_EXE_CORRUPTED_t TM;
373 Packet_TM_LFR_TC_EXE_CORRUPTED_t TM;
374 unsigned char messageSize;
374 unsigned char messageSize;
375 unsigned int packetLength;
375 unsigned int packetLength;
376 unsigned int estimatedPacketLength;
376 unsigned int estimatedPacketLength;
377 unsigned char *packetDataField;
377 unsigned char *packetDataField;
378
378
379 packetLength = (TC->packetLength[0] * 256) + TC->packetLength[1]; // compute the packet length parameter written in the TC
379 packetLength = (TC->packetLength[0] * CONST_256) + TC->packetLength[1]; // compute the packet length parameter written in the TC
380 estimatedPacketLength = (unsigned int) (currentTC_LEN_RCV[0] * 256 + currentTC_LEN_RCV[1]);
380 estimatedPacketLength = (unsigned int) ((currentTC_LEN_RCV[0] * CONST_256) + currentTC_LEN_RCV[1]);
381 packetDataField = (unsigned char *) &TC->headerFlag_pusVersion_Ack; // get the beginning of the data field
381 packetDataField = (unsigned char *) &TC->headerFlag_pusVersion_Ack; // get the beginning of the data field
382
382
383 TM.targetLogicalAddress = CCSDS_DESTINATION_ID;
383 TM.targetLogicalAddress = CCSDS_DESTINATION_ID;
384 TM.protocolIdentifier = CCSDS_PROTOCOLE_ID;
384 TM.protocolIdentifier = CCSDS_PROTOCOLE_ID;
385 TM.reserved = DEFAULT_RESERVED;
385 TM.reserved = DEFAULT_RESERVED;
386 TM.userApplication = CCSDS_USER_APP;
386 TM.userApplication = CCSDS_USER_APP;
387 // PACKET HEADER
387 // PACKET HEADER
388 TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> 8);
388 TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> SHIFT_1_BYTE);
389 TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE );
389 TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE );
390 increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID );
390 increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID );
391 TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_CORRUPTED >> 8);
391 TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_CORRUPTED >> SHIFT_1_BYTE);
392 TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_CORRUPTED );
392 TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_CORRUPTED );
393 // DATA FIELD HEADER
393 // DATA FIELD HEADER
394 TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
394 TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
395 TM.serviceType = TM_TYPE_TC_EXE;
395 TM.serviceType = TM_TYPE_TC_EXE;
396 TM.serviceSubType = TM_SUBTYPE_EXE_NOK;
396 TM.serviceSubType = TM_SUBTYPE_EXE_NOK;
397 TM.destinationID = destinationID;
397 TM.destinationID = destinationID;
398 TM.time[0] = (unsigned char) (time_management_regs->coarse_time>>24);
398 TM.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
399 TM.time[1] = (unsigned char) (time_management_regs->coarse_time>>16);
399 TM.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
400 TM.time[2] = (unsigned char) (time_management_regs->coarse_time>>8);
400 TM.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
401 TM.time[3] = (unsigned char) (time_management_regs->coarse_time);
401 TM.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
402 TM.time[4] = (unsigned char) (time_management_regs->fine_time>>8);
402 TM.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
403 TM.time[5] = (unsigned char) (time_management_regs->fine_time);
403 TM.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
404 //
404 //
405 TM.tc_failure_code[0] = (unsigned char) (CORRUPTED >> 8);
405 TM.tc_failure_code[0] = (unsigned char) (CORRUPTED >> SHIFT_1_BYTE);
406 TM.tc_failure_code[1] = (unsigned char) (CORRUPTED );
406 TM.tc_failure_code[1] = (unsigned char) (CORRUPTED );
407 TM.telecommand_pkt_id[0] = TC->packetID[0];
407 TM.telecommand_pkt_id[0] = TC->packetID[0];
408 TM.telecommand_pkt_id[1] = TC->packetID[1];
408 TM.telecommand_pkt_id[1] = TC->packetID[1];
409 TM.pkt_seq_control[0] = TC->packetSequenceControl[0];
409 TM.pkt_seq_control[0] = TC->packetSequenceControl[0];
410 TM.pkt_seq_control[1] = TC->packetSequenceControl[1];
410 TM.pkt_seq_control[1] = TC->packetSequenceControl[1];
411 TM.tc_service = TC->serviceType; // type of the rejected TC
411 TM.tc_service = TC->serviceType; // type of the rejected TC
412 TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC
412 TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC
413 TM.pkt_len_rcv_value[0] = TC->packetLength[0];
413 TM.pkt_len_rcv_value[0] = TC->packetLength[0];
414 TM.pkt_len_rcv_value[1] = TC->packetLength[1];
414 TM.pkt_len_rcv_value[1] = TC->packetLength[1];
415 TM.pkt_datafieldsize_cnt[0] = currentTC_LEN_RCV[0];
415 TM.pkt_datafieldsize_cnt[0] = currentTC_LEN_RCV[0];
416 TM.pkt_datafieldsize_cnt[1] = currentTC_LEN_RCV[1];
416 TM.pkt_datafieldsize_cnt[1] = currentTC_LEN_RCV[1];
417 // TM.rcv_crc[0] = packetDataField[ packetLength - 1 ];
417 // TM.rcv_crc[0] = packetDataField[ packetLength - 1 ];
418 // TM.rcv_crc[1] = packetDataField[ packetLength ];
418 // TM.rcv_crc[1] = packetDataField[ packetLength ];
419 TM.rcv_crc[0] = packetDataField[ estimatedPacketLength - 1 ];
419 TM.rcv_crc[0] = packetDataField[ estimatedPacketLength - 1 ];
420 TM.rcv_crc[1] = packetDataField[ estimatedPacketLength ];
420 TM.rcv_crc[1] = packetDataField[ estimatedPacketLength ];
421 TM.computed_crc[0] = computed_CRC[0];
421 TM.computed_crc[0] = computed_CRC[0];
422 TM.computed_crc[1] = computed_CRC[1];
422 TM.computed_crc[1] = computed_CRC[1];
423
423
424 messageSize = PACKET_LENGTH_TC_EXE_CORRUPTED + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
424 messageSize = PACKET_LENGTH_TC_EXE_CORRUPTED + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES;
425
425
426 // SEND DATA
426 // SEND DATA
427 status = rtems_message_queue_send( queue_id, &TM, messageSize);
427 status = rtems_message_queue_send( queue_id, &TM, messageSize);
428 if (status != RTEMS_SUCCESSFUL) {
428 if (status != RTEMS_SUCCESSFUL) {
429 PRINTF("in send_tm_lfr_tc_exe_error *** ERR\n")
429 PRINTF("in send_tm_lfr_tc_exe_error *** ERR\n")
430 }
430 }
431
431
432 // UPDATE HK FIELDS
432 // UPDATE HK FIELDS
433 update_last_TC_rej( TC, TM.time );
433 update_last_TC_rej( TC, TM.time );
434
434
435 return status;
435 return status;
436 }
436 }
437
437
438 void increment_seq_counter_destination_id( unsigned char *packet_sequence_control, unsigned char destination_id )
438 void increment_seq_counter_destination_id( unsigned char *packet_sequence_control, unsigned char destination_id )
439 {
439 {
440 /** This function increment the packet sequence control parameter of a TC, depending on its destination ID.
440 /** This function increment the packet sequence control parameter of a TC, depending on its destination ID.
441 *
441 *
442 * @param packet_sequence_control points to the packet sequence control which will be incremented
442 * @param packet_sequence_control points to the packet sequence control which will be incremented
443 * @param destination_id is the destination ID of the TM, there is one counter by destination ID
443 * @param destination_id is the destination ID of the TM, there is one counter by destination ID
444 *
444 *
445 * If the destination ID is not known, a dedicated counter is incremented.
445 * If the destination ID is not known, a dedicated counter is incremented.
446 *
446 *
447 */
447 */
448
448
449 unsigned short sequence_cnt;
449 unsigned short sequence_cnt;
450 unsigned short segmentation_grouping_flag;
450 unsigned short segmentation_grouping_flag;
451 unsigned short new_packet_sequence_control;
451 unsigned short new_packet_sequence_control;
452 unsigned char i;
452 unsigned char i;
453
453
454 switch (destination_id)
454 switch (destination_id)
455 {
455 {
456 case SID_TC_GROUND:
456 case SID_TC_GROUND:
457 i = GROUND;
457 i = GROUND;
458 break;
458 break;
459 case SID_TC_MISSION_TIMELINE:
459 case SID_TC_MISSION_TIMELINE:
460 i = MISSION_TIMELINE;
460 i = MISSION_TIMELINE;
461 break;
461 break;
462 case SID_TC_TC_SEQUENCES:
462 case SID_TC_TC_SEQUENCES:
463 i = TC_SEQUENCES;
463 i = TC_SEQUENCES;
464 break;
464 break;
465 case SID_TC_RECOVERY_ACTION_CMD:
465 case SID_TC_RECOVERY_ACTION_CMD:
466 i = RECOVERY_ACTION_CMD;
466 i = RECOVERY_ACTION_CMD;
467 break;
467 break;
468 case SID_TC_BACKUP_MISSION_TIMELINE:
468 case SID_TC_BACKUP_MISSION_TIMELINE:
469 i = BACKUP_MISSION_TIMELINE;
469 i = BACKUP_MISSION_TIMELINE;
470 break;
470 break;
471 case SID_TC_DIRECT_CMD:
471 case SID_TC_DIRECT_CMD:
472 i = DIRECT_CMD;
472 i = DIRECT_CMD;
473 break;
473 break;
474 case SID_TC_SPARE_GRD_SRC1:
474 case SID_TC_SPARE_GRD_SRC1:
475 i = SPARE_GRD_SRC1;
475 i = SPARE_GRD_SRC1;
476 break;
476 break;
477 case SID_TC_SPARE_GRD_SRC2:
477 case SID_TC_SPARE_GRD_SRC2:
478 i = SPARE_GRD_SRC2;
478 i = SPARE_GRD_SRC2;
479 break;
479 break;
480 case SID_TC_OBCP:
480 case SID_TC_OBCP:
481 i = OBCP;
481 i = OBCP;
482 break;
482 break;
483 case SID_TC_SYSTEM_CONTROL:
483 case SID_TC_SYSTEM_CONTROL:
484 i = SYSTEM_CONTROL;
484 i = SYSTEM_CONTROL;
485 break;
485 break;
486 case SID_TC_AOCS:
486 case SID_TC_AOCS:
487 i = AOCS;
487 i = AOCS;
488 break;
488 break;
489 case SID_TC_RPW_INTERNAL:
489 case SID_TC_RPW_INTERNAL:
490 i = RPW_INTERNAL;
490 i = RPW_INTERNAL;
491 break;
491 break;
492 default:
492 default:
493 i = GROUND;
493 i = GROUND;
494 break;
494 break;
495 }
495 }
496
496
497 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << 8;
497 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << SHIFT_1_BYTE;
498 sequence_cnt = sequenceCounters_TC_EXE[ i ] & 0x3fff;
498 sequence_cnt = sequenceCounters_TC_EXE[ i ] & SEQ_CNT_MASK;
499
499
500 new_packet_sequence_control = segmentation_grouping_flag | sequence_cnt ;
500 new_packet_sequence_control = segmentation_grouping_flag | sequence_cnt ;
501
501
502 packet_sequence_control[0] = (unsigned char) (new_packet_sequence_control >> 8);
502 packet_sequence_control[0] = (unsigned char) (new_packet_sequence_control >> SHIFT_1_BYTE);
503 packet_sequence_control[1] = (unsigned char) (new_packet_sequence_control );
503 packet_sequence_control[1] = (unsigned char) (new_packet_sequence_control );
504
504
505 // increment the sequence counter
505 // increment the sequence counter
506 if ( sequenceCounters_TC_EXE[ i ] < SEQ_CNT_MAX )
506 if ( sequenceCounters_TC_EXE[ i ] < SEQ_CNT_MAX )
507 {
507 {
508 sequenceCounters_TC_EXE[ i ] = sequenceCounters_TC_EXE[ i ] + 1;
508 sequenceCounters_TC_EXE[ i ] = sequenceCounters_TC_EXE[ i ] + 1;
509 }
509 }
510 else
510 else
511 {
511 {
512 sequenceCounters_TC_EXE[ i ] = 0;
512 sequenceCounters_TC_EXE[ i ] = 0;
513 }
513 }
514 }
514 }
@@ -1,1314 +1,1312
1 /** Functions and tasks related to waveform packet generation.
1 /** Functions and tasks related to waveform packet generation.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 * A group of functions to handle waveforms, in snapshot or continuous format.\n
6 * A group of functions to handle waveforms, in snapshot or continuous format.\n
7 *
7 *
8 */
8 */
9
9
10 #include "wf_handler.h"
10 #include "wf_handler.h"
11
11
12 //***************
12 //***************
13 // waveform rings
13 // waveform rings
14 // F0
14 // F0
15 ring_node waveform_ring_f0[NB_RING_NODES_F0];
15 ring_node waveform_ring_f0[NB_RING_NODES_F0];
16 ring_node *current_ring_node_f0;
16 ring_node *current_ring_node_f0;
17 ring_node *ring_node_to_send_swf_f0;
17 ring_node *ring_node_to_send_swf_f0;
18 // F1
18 // F1
19 ring_node waveform_ring_f1[NB_RING_NODES_F1];
19 ring_node waveform_ring_f1[NB_RING_NODES_F1];
20 ring_node *current_ring_node_f1;
20 ring_node *current_ring_node_f1;
21 ring_node *ring_node_to_send_swf_f1;
21 ring_node *ring_node_to_send_swf_f1;
22 ring_node *ring_node_to_send_cwf_f1;
22 ring_node *ring_node_to_send_cwf_f1;
23 // F2
23 // F2
24 ring_node waveform_ring_f2[NB_RING_NODES_F2];
24 ring_node waveform_ring_f2[NB_RING_NODES_F2];
25 ring_node *current_ring_node_f2;
25 ring_node *current_ring_node_f2;
26 ring_node *ring_node_to_send_swf_f2;
26 ring_node *ring_node_to_send_swf_f2;
27 ring_node *ring_node_to_send_cwf_f2;
27 ring_node *ring_node_to_send_cwf_f2;
28 // F3
28 // F3
29 ring_node waveform_ring_f3[NB_RING_NODES_F3];
29 ring_node waveform_ring_f3[NB_RING_NODES_F3];
30 ring_node *current_ring_node_f3;
30 ring_node *current_ring_node_f3;
31 ring_node *ring_node_to_send_cwf_f3;
31 ring_node *ring_node_to_send_cwf_f3;
32 char wf_cont_f3_light[ (NB_SAMPLES_PER_SNAPSHOT) * NB_BYTES_CWF3_LIGHT_BLK ];
32 char wf_cont_f3_light[ (NB_SAMPLES_PER_SNAPSHOT) * NB_BYTES_CWF3_LIGHT_BLK ];
33
33
34 bool extractSWF1 = false;
34 bool extractSWF1 = false;
35 bool extractSWF2 = false;
35 bool extractSWF2 = false;
36 bool swf0_ready_flag_f1 = false;
36 bool swf0_ready_flag_f1 = false;
37 bool swf0_ready_flag_f2 = false;
37 bool swf0_ready_flag_f2 = false;
38 bool swf1_ready = false;
38 bool swf1_ready = false;
39 bool swf2_ready = false;
39 bool swf2_ready = false;
40
40
41 int swf1_extracted[ (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK) ];
41 int swf1_extracted[ (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK) ];
42 int swf2_extracted[ (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK) ];
42 int swf2_extracted[ (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK) ];
43 ring_node ring_node_swf1_extracted;
43 ring_node ring_node_swf1_extracted;
44 ring_node ring_node_swf2_extracted;
44 ring_node ring_node_swf2_extracted;
45
45
46 typedef enum resynchro_state_t
46 typedef enum resynchro_state_t
47 {
47 {
48 MEASURE,
48 MEASURE,
49 CORRECTION
49 CORRECTION
50 } resynchro_state;
50 } resynchro_state;
51
51
52 //*********************
52 //*********************
53 // Interrupt SubRoutine
53 // Interrupt SubRoutine
54
54
55 ring_node * getRingNodeToSendCWF( unsigned char frequencyChannel)
55 ring_node * getRingNodeToSendCWF( unsigned char frequencyChannel)
56 {
56 {
57 ring_node *node;
57 ring_node *node;
58
58
59 node = NULL;
59 node = NULL;
60 switch ( frequencyChannel ) {
60 switch ( frequencyChannel ) {
61 case 1:
61 case CHANNELF1:
62 node = ring_node_to_send_cwf_f1;
62 node = ring_node_to_send_cwf_f1;
63 break;
63 break;
64 case 2:
64 case CHANNELF2:
65 node = ring_node_to_send_cwf_f2;
65 node = ring_node_to_send_cwf_f2;
66 break;
66 break;
67 case 3:
67 case CHANNELF3:
68 node = ring_node_to_send_cwf_f3;
68 node = ring_node_to_send_cwf_f3;
69 break;
69 break;
70 default:
70 default:
71 break;
71 break;
72 }
72 }
73
73
74 return node;
74 return node;
75 }
75 }
76
76
77 ring_node * getRingNodeToSendSWF( unsigned char frequencyChannel)
77 ring_node * getRingNodeToSendSWF( unsigned char frequencyChannel)
78 {
78 {
79 ring_node *node;
79 ring_node *node;
80
80
81 node = NULL;
81 node = NULL;
82 switch ( frequencyChannel ) {
82 switch ( frequencyChannel ) {
83 case 0:
83 case CHANNELF0:
84 node = ring_node_to_send_swf_f0;
84 node = ring_node_to_send_swf_f0;
85 break;
85 break;
86 case 1:
86 case CHANNELF1:
87 node = ring_node_to_send_swf_f1;
87 node = ring_node_to_send_swf_f1;
88 break;
88 break;
89 case 2:
89 case CHANNELF2:
90 node = ring_node_to_send_swf_f2;
90 node = ring_node_to_send_swf_f2;
91 break;
91 break;
92 default:
92 default:
93 break;
93 break;
94 }
94 }
95
95
96 return node;
96 return node;
97 }
97 }
98
98
99 void reset_extractSWF( void )
99 void reset_extractSWF( void )
100 {
100 {
101 extractSWF1 = false;
101 extractSWF1 = false;
102 extractSWF2 = false;
102 extractSWF2 = false;
103 swf0_ready_flag_f1 = false;
103 swf0_ready_flag_f1 = false;
104 swf0_ready_flag_f2 = false;
104 swf0_ready_flag_f2 = false;
105 swf1_ready = false;
105 swf1_ready = false;
106 swf2_ready = false;
106 swf2_ready = false;
107 }
107 }
108
108
109 inline void waveforms_isr_f3( void )
109 inline void waveforms_isr_f3( void )
110 {
110 {
111 rtems_status_code spare_status;
111 rtems_status_code spare_status;
112
112
113 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_BURST) // in BURST the data are used to place v, e1 and e2 in the HK packet
113 if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_BURST) // in BURST the data are used to place v, e1 and e2 in the HK packet
114 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
114 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) )
115 { // in modes other than STANDBY and BURST, send the CWF_F3 data
115 { // in modes other than STANDBY and BURST, send the CWF_F3 data
116 //***
116 //***
117 // F3
117 // F3
118 if ( (waveform_picker_regs->status & 0xc0) != 0x00 ) { // [1100 0000] check the f3 full bits
118 if ( (waveform_picker_regs->status & BITS_WFP_STATUS_F3) != INIT_CHAR ) { // [1100 0000] check the f3 full bits
119 ring_node_to_send_cwf_f3 = current_ring_node_f3->previous;
119 ring_node_to_send_cwf_f3 = current_ring_node_f3->previous;
120 current_ring_node_f3 = current_ring_node_f3->next;
120 current_ring_node_f3 = current_ring_node_f3->next;
121 if ((waveform_picker_regs->status & 0x40) == 0x40){ // [0100 0000] f3 buffer 0 is full
121 if ((waveform_picker_regs->status & BIT_WFP_BUF_F3_0) == BIT_WFP_BUF_F3_0){ // [0100 0000] f3 buffer 0 is full
122 ring_node_to_send_cwf_f3->coarseTime = waveform_picker_regs->f3_0_coarse_time;
122 ring_node_to_send_cwf_f3->coarseTime = waveform_picker_regs->f3_0_coarse_time;
123 ring_node_to_send_cwf_f3->fineTime = waveform_picker_regs->f3_0_fine_time;
123 ring_node_to_send_cwf_f3->fineTime = waveform_picker_regs->f3_0_fine_time;
124 waveform_picker_regs->addr_data_f3_0 = current_ring_node_f3->buffer_address;
124 waveform_picker_regs->addr_data_f3_0 = current_ring_node_f3->buffer_address;
125 waveform_picker_regs->status = waveform_picker_regs->status & 0x00008840; // [1000 1000 0100 0000]
125 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F3_0; // [1000 1000 0100 0000]
126 }
126 }
127 else if ((waveform_picker_regs->status & 0x80) == 0x80){ // [1000 0000] f3 buffer 1 is full
127 else if ((waveform_picker_regs->status & BIT_WFP_BUF_F3_1) == BIT_WFP_BUF_F3_1){ // [1000 0000] f3 buffer 1 is full
128 ring_node_to_send_cwf_f3->coarseTime = waveform_picker_regs->f3_1_coarse_time;
128 ring_node_to_send_cwf_f3->coarseTime = waveform_picker_regs->f3_1_coarse_time;
129 ring_node_to_send_cwf_f3->fineTime = waveform_picker_regs->f3_1_fine_time;
129 ring_node_to_send_cwf_f3->fineTime = waveform_picker_regs->f3_1_fine_time;
130 waveform_picker_regs->addr_data_f3_1 = current_ring_node_f3->buffer_address;
130 waveform_picker_regs->addr_data_f3_1 = current_ring_node_f3->buffer_address;
131 waveform_picker_regs->status = waveform_picker_regs->status & 0x00008880; // [1000 1000 1000 0000]
131 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F3_1; // [1000 1000 1000 0000]
132 }
132 }
133 if (rtems_event_send( Task_id[TASKID_CWF3], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
133 if (rtems_event_send( Task_id[TASKID_CWF3], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) {
134 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 );
134 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 );
135 }
135 }
136 }
136 }
137 }
137 }
138 }
138 }
139
139
140 inline void waveforms_isr_burst( void )
140 inline void waveforms_isr_burst( void )
141 {
141 {
142 unsigned char status;
142 unsigned char status;
143 rtems_status_code spare_status;
143 rtems_status_code spare_status;
144
144
145 status = (waveform_picker_regs->status & 0x30) >> 4; // [0011 0000] get the status bits for f2
145 status = (waveform_picker_regs->status & BITS_WFP_STATUS_F2) >> SHIFT_WFP_STATUS_F2; // [0011 0000] get the status bits for f2
146
147
146
148 switch(status)
147 switch(status)
149 {
148 {
150 case 1:
149 case BIT_WFP_BUFFER_0:
151 ring_node_to_send_cwf_f2 = current_ring_node_f2->previous;
150 ring_node_to_send_cwf_f2 = current_ring_node_f2->previous;
152 ring_node_to_send_cwf_f2->sid = SID_BURST_CWF_F2;
151 ring_node_to_send_cwf_f2->sid = SID_BURST_CWF_F2;
153 ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_0_coarse_time;
152 ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_0_coarse_time;
154 ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_0_fine_time;
153 ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_0_fine_time;
155 current_ring_node_f2 = current_ring_node_f2->next;
154 current_ring_node_f2 = current_ring_node_f2->next;
156 waveform_picker_regs->addr_data_f2_0 = current_ring_node_f2->buffer_address;
155 waveform_picker_regs->addr_data_f2_0 = current_ring_node_f2->buffer_address;
157 if (rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_BURST ) != RTEMS_SUCCESSFUL) {
156 if (rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_BURST ) != RTEMS_SUCCESSFUL) {
158 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 );
157 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 );
159 }
158 }
160 waveform_picker_regs->status = waveform_picker_regs->status & 0x00004410; // [0100 0100 0001 0000]
159 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F2_0; // [0100 0100 0001 0000]
161 break;
160 break;
162 case 2:
161 case BIT_WFP_BUFFER_1:
163 ring_node_to_send_cwf_f2 = current_ring_node_f2->previous;
162 ring_node_to_send_cwf_f2 = current_ring_node_f2->previous;
164 ring_node_to_send_cwf_f2->sid = SID_BURST_CWF_F2;
163 ring_node_to_send_cwf_f2->sid = SID_BURST_CWF_F2;
165 ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_1_coarse_time;
164 ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_1_coarse_time;
166 ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_1_fine_time;
165 ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_1_fine_time;
167 current_ring_node_f2 = current_ring_node_f2->next;
166 current_ring_node_f2 = current_ring_node_f2->next;
168 waveform_picker_regs->addr_data_f2_1 = current_ring_node_f2->buffer_address;
167 waveform_picker_regs->addr_data_f2_1 = current_ring_node_f2->buffer_address;
169 if (rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_BURST ) != RTEMS_SUCCESSFUL) {
168 if (rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_BURST ) != RTEMS_SUCCESSFUL) {
170 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 );
169 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 );
171 }
170 }
172 waveform_picker_regs->status = waveform_picker_regs->status & 0x00004420; // [0100 0100 0010 0000]
171 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F2_1; // [0100 0100 0010 0000]
173 break;
172 break;
174 default:
173 default:
175 break;
174 break;
176 }
175 }
177 }
176 }
178
177
179 inline void waveform_isr_normal_sbm1_sbm2( void )
178 inline void waveform_isr_normal_sbm1_sbm2( void )
180 {
179 {
181 rtems_status_code status;
180 rtems_status_code status;
182
181
183 //***
182 //***
184 // F0
183 // F0
185 if ( (waveform_picker_regs->status & 0x03) != 0x00 ) // [0000 0011] check the f0 full bits
184 if ( (waveform_picker_regs->status & BITS_WFP_STATUS_F0) != INIT_CHAR ) // [0000 0011] check the f0 full bits
186 {
185 {
187 swf0_ready_flag_f1 = true;
186 swf0_ready_flag_f1 = true;
188 swf0_ready_flag_f2 = true;
187 swf0_ready_flag_f2 = true;
189 ring_node_to_send_swf_f0 = current_ring_node_f0->previous;
188 ring_node_to_send_swf_f0 = current_ring_node_f0->previous;
190 current_ring_node_f0 = current_ring_node_f0->next;
189 current_ring_node_f0 = current_ring_node_f0->next;
191 if ( (waveform_picker_regs->status & 0x01) == 0x01)
190 if ( (waveform_picker_regs->status & BIT_WFP_BUFFER_0) == BIT_WFP_BUFFER_0)
192 {
191 {
193
192
194 ring_node_to_send_swf_f0->coarseTime = waveform_picker_regs->f0_0_coarse_time;
193 ring_node_to_send_swf_f0->coarseTime = waveform_picker_regs->f0_0_coarse_time;
195 ring_node_to_send_swf_f0->fineTime = waveform_picker_regs->f0_0_fine_time;
194 ring_node_to_send_swf_f0->fineTime = waveform_picker_regs->f0_0_fine_time;
196 waveform_picker_regs->addr_data_f0_0 = current_ring_node_f0->buffer_address;
195 waveform_picker_regs->addr_data_f0_0 = current_ring_node_f0->buffer_address;
197 waveform_picker_regs->status = waveform_picker_regs->status & 0x00001101; // [0001 0001 0000 0001]
196 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F0_0; // [0001 0001 0000 0001]
198 }
197 }
199 else if ( (waveform_picker_regs->status & 0x02) == 0x02)
198 else if ( (waveform_picker_regs->status & BIT_WFP_BUFFER_1) == BIT_WFP_BUFFER_1)
200 {
199 {
201 ring_node_to_send_swf_f0->coarseTime = waveform_picker_regs->f0_1_coarse_time;
200 ring_node_to_send_swf_f0->coarseTime = waveform_picker_regs->f0_1_coarse_time;
202 ring_node_to_send_swf_f0->fineTime = waveform_picker_regs->f0_1_fine_time;
201 ring_node_to_send_swf_f0->fineTime = waveform_picker_regs->f0_1_fine_time;
203 waveform_picker_regs->addr_data_f0_1 = current_ring_node_f0->buffer_address;
202 waveform_picker_regs->addr_data_f0_1 = current_ring_node_f0->buffer_address;
204 waveform_picker_regs->status = waveform_picker_regs->status & 0x00001102; // [0001 0001 0000 0010]
203 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F0_1; // [0001 0001 0000 0010]
205 }
204 }
206 // send an event to the WFRM task for resynchro activities
205 // send an event to the WFRM task for resynchro activities
207 status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_SWF_RESYNCH );
206 status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_SWF_RESYNCH );
208 }
207 }
209
208
210 //***
209 //***
211 // F1
210 // F1
212 if ( (waveform_picker_regs->status & 0x0c) != 0x00 ) { // [0000 1100] check the f1 full bits
211 if ( (waveform_picker_regs->status & 0x0c) != INIT_CHAR ) { // [0000 1100] check the f1 full bits
213 // (1) change the receiving buffer for the waveform picker
212 // (1) change the receiving buffer for the waveform picker
214 ring_node_to_send_cwf_f1 = current_ring_node_f1->previous;
213 ring_node_to_send_cwf_f1 = current_ring_node_f1->previous;
215 current_ring_node_f1 = current_ring_node_f1->next;
214 current_ring_node_f1 = current_ring_node_f1->next;
216 if ( (waveform_picker_regs->status & 0x04) == 0x04)
215 if ( (waveform_picker_regs->status & BIT_WFP_BUF_F1_0) == BIT_WFP_BUF_F1_0)
217 {
216 {
218 ring_node_to_send_cwf_f1->coarseTime = waveform_picker_regs->f1_0_coarse_time;
217 ring_node_to_send_cwf_f1->coarseTime = waveform_picker_regs->f1_0_coarse_time;
219 ring_node_to_send_cwf_f1->fineTime = waveform_picker_regs->f1_0_fine_time;
218 ring_node_to_send_cwf_f1->fineTime = waveform_picker_regs->f1_0_fine_time;
220 waveform_picker_regs->addr_data_f1_0 = current_ring_node_f1->buffer_address;
219 waveform_picker_regs->addr_data_f1_0 = current_ring_node_f1->buffer_address;
221 waveform_picker_regs->status = waveform_picker_regs->status & 0x00002204; // [0010 0010 0000 0100] f1 bits = 0
220 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F1_0; // [0010 0010 0000 0100] f1 bits = 0
222 }
221 }
223 else if ( (waveform_picker_regs->status & 0x08) == 0x08)
222 else if ( (waveform_picker_regs->status & BIT_WFP_BUF_F1_1) == BIT_WFP_BUF_F1_1)
224 {
223 {
225 ring_node_to_send_cwf_f1->coarseTime = waveform_picker_regs->f1_1_coarse_time;
224 ring_node_to_send_cwf_f1->coarseTime = waveform_picker_regs->f1_1_coarse_time;
226 ring_node_to_send_cwf_f1->fineTime = waveform_picker_regs->f1_1_fine_time;
225 ring_node_to_send_cwf_f1->fineTime = waveform_picker_regs->f1_1_fine_time;
227 waveform_picker_regs->addr_data_f1_1 = current_ring_node_f1->buffer_address;
226 waveform_picker_regs->addr_data_f1_1 = current_ring_node_f1->buffer_address;
228 waveform_picker_regs->status = waveform_picker_regs->status & 0x00002208; // [0010 0010 0000 1000] f1 bits = 0
227 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F1_1; // [0010 0010 0000 1000] f1 bits = 0
229 }
228 }
230 // (2) send an event for the the CWF1 task for transmission (and snapshot extraction if needed)
229 // (2) send an event for the the CWF1 task for transmission (and snapshot extraction if needed)
231 status = rtems_event_send( Task_id[TASKID_CWF1], RTEMS_EVENT_MODE_NORM_S1_S2 );
230 status = rtems_event_send( Task_id[TASKID_CWF1], RTEMS_EVENT_MODE_NORM_S1_S2 );
232 }
231 }
233
232
234 //***
233 //***
235 // F2
234 // F2
236 if ( (waveform_picker_regs->status & 0x30) != 0x00 ) { // [0011 0000] check the f2 full bit
235 if ( (waveform_picker_regs->status & BITS_WFP_STATUS_F2) != INIT_CHAR ) { // [0011 0000] check the f2 full bit
237 // (1) change the receiving buffer for the waveform picker
236 // (1) change the receiving buffer for the waveform picker
238 ring_node_to_send_cwf_f2 = current_ring_node_f2->previous;
237 ring_node_to_send_cwf_f2 = current_ring_node_f2->previous;
239 ring_node_to_send_cwf_f2->sid = SID_SBM2_CWF_F2;
238 ring_node_to_send_cwf_f2->sid = SID_SBM2_CWF_F2;
240 current_ring_node_f2 = current_ring_node_f2->next;
239 current_ring_node_f2 = current_ring_node_f2->next;
241 if ( (waveform_picker_regs->status & 0x10) == 0x10)
240 if ( (waveform_picker_regs->status & BIT_WFP_BUF_F2_0) == BIT_WFP_BUF_F2_0)
242 {
241 {
243 ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_0_coarse_time;
242 ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_0_coarse_time;
244 ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_0_fine_time;
243 ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_0_fine_time;
245 waveform_picker_regs->addr_data_f2_0 = current_ring_node_f2->buffer_address;
244 waveform_picker_regs->addr_data_f2_0 = current_ring_node_f2->buffer_address;
246 waveform_picker_regs->status = waveform_picker_regs->status & 0x00004410; // [0100 0100 0001 0000]
245 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F2_0; // [0100 0100 0001 0000]
247 }
246 }
248 else if ( (waveform_picker_regs->status & 0x20) == 0x20)
247 else if ( (waveform_picker_regs->status & BIT_WFP_BUF_F2_1) == BIT_WFP_BUF_F2_1)
249 {
248 {
250 ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_1_coarse_time;
249 ring_node_to_send_cwf_f2->coarseTime = waveform_picker_regs->f2_1_coarse_time;
251 ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_1_fine_time;
250 ring_node_to_send_cwf_f2->fineTime = waveform_picker_regs->f2_1_fine_time;
252 waveform_picker_regs->addr_data_f2_1 = current_ring_node_f2->buffer_address;
251 waveform_picker_regs->addr_data_f2_1 = current_ring_node_f2->buffer_address;
253 waveform_picker_regs->status = waveform_picker_regs->status & 0x00004420; // [0100 0100 0010 0000]
252 waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F2_1; // [0100 0100 0010 0000]
254 }
253 }
255 // (2) send an event for the waveforms transmission
254 // (2) send an event for the waveforms transmission
256 status = rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_NORM_S1_S2 );
255 status = rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_NORM_S1_S2 );
257 }
256 }
258 }
257 }
259
258
260 rtems_isr waveforms_isr( rtems_vector_number vector )
259 rtems_isr waveforms_isr( rtems_vector_number vector )
261 {
260 {
262 /** This is the interrupt sub routine called by the waveform picker core.
261 /** This is the interrupt sub routine called by the waveform picker core.
263 *
262 *
264 * This ISR launch different actions depending mainly on two pieces of information:
263 * This ISR launch different actions depending mainly on two pieces of information:
265 * 1. the values read in the registers of the waveform picker.
264 * 1. the values read in the registers of the waveform picker.
266 * 2. the current LFR mode.
265 * 2. the current LFR mode.
267 *
266 *
268 */
267 */
269
268
270 // STATUS
269 // STATUS
271 // new error error buffer full
270 // new error error buffer full
272 // 15 14 13 12 11 10 9 8
271 // 15 14 13 12 11 10 9 8
273 // f3 f2 f1 f0 f3 f2 f1 f0
272 // f3 f2 f1 f0 f3 f2 f1 f0
274 //
273 //
275 // ready buffer
274 // ready buffer
276 // 7 6 5 4 3 2 1 0
275 // 7 6 5 4 3 2 1 0
277 // f3_1 f3_0 f2_1 f2_0 f1_1 f1_0 f0_1 f0_0
276 // f3_1 f3_0 f2_1 f2_0 f1_1 f1_0 f0_1 f0_0
278
277
279 rtems_status_code spare_status;
278 rtems_status_code spare_status;
280
279
281 waveforms_isr_f3();
280 waveforms_isr_f3();
282
281
283 //*************************************************
282 //*************************************************
284 // copy the status bits in the housekeeping packets
283 // copy the status bits in the housekeeping packets
285 housekeeping_packet.hk_lfr_vhdl_iir_cal =
284 housekeeping_packet.hk_lfr_vhdl_iir_cal =
286 (unsigned char) ((waveform_picker_regs->status & 0xff00) >> 8);
285 (unsigned char) ((waveform_picker_regs->status & BYTE0_MASK) >> SHIFT_1_BYTE);
287
286
288 if ( (waveform_picker_regs->status & 0xff00) != 0x00) // [1111 1111 0000 0000] check the error bits
287 if ( (waveform_picker_regs->status & BYTE0_MASK) != INIT_CHAR) // [1111 1111 0000 0000] check the error bits
289 {
288 {
290 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_10 );
289 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_10 );
291 }
290 }
292
291
293 switch(lfrCurrentMode)
292 switch(lfrCurrentMode)
294 {
293 {
295 //********
294 //********
296 // STANDBY
295 // STANDBY
297 case LFR_MODE_STANDBY:
296 case LFR_MODE_STANDBY:
298 break;
297 break;
299 //**************************
298 //**************************
300 // LFR NORMAL, SBM1 and SBM2
299 // LFR NORMAL, SBM1 and SBM2
301 case LFR_MODE_NORMAL:
300 case LFR_MODE_NORMAL:
302 case LFR_MODE_SBM1:
301 case LFR_MODE_SBM1:
303 case LFR_MODE_SBM2:
302 case LFR_MODE_SBM2:
304 waveform_isr_normal_sbm1_sbm2();
303 waveform_isr_normal_sbm1_sbm2();
305 break;
304 break;
306 //******
305 //******
307 // BURST
306 // BURST
308 case LFR_MODE_BURST:
307 case LFR_MODE_BURST:
309 waveforms_isr_burst();
308 waveforms_isr_burst();
310 break;
309 break;
311 //********
310 //********
312 // DEFAULT
311 // DEFAULT
313 default:
312 default:
314 break;
313 break;
315 }
314 }
316 }
315 }
317
316
318 //************
317 //************
319 // RTEMS TASKS
318 // RTEMS TASKS
320
319
321 rtems_task wfrm_task(rtems_task_argument argument) //used with the waveform picker VHDL IP
320 rtems_task wfrm_task(rtems_task_argument argument) //used with the waveform picker VHDL IP
322 {
321 {
323 /** This RTEMS task is dedicated to the transmission of snapshots of the NORMAL mode.
322 /** This RTEMS task is dedicated to the transmission of snapshots of the NORMAL mode.
324 *
323 *
325 * @param unused is the starting argument of the RTEMS task
324 * @param unused is the starting argument of the RTEMS task
326 *
325 *
327 * The following data packets are sent by this task:
326 * The following data packets are sent by this task:
328 * - TM_LFR_SCIENCE_NORMAL_SWF_F0
327 * - TM_LFR_SCIENCE_NORMAL_SWF_F0
329 * - TM_LFR_SCIENCE_NORMAL_SWF_F1
328 * - TM_LFR_SCIENCE_NORMAL_SWF_F1
330 * - TM_LFR_SCIENCE_NORMAL_SWF_F2
329 * - TM_LFR_SCIENCE_NORMAL_SWF_F2
331 *
330 *
332 */
331 */
333
332
334 rtems_event_set event_out;
333 rtems_event_set event_out;
335 rtems_id queue_id;
334 rtems_id queue_id;
336 rtems_status_code status;
335 rtems_status_code status;
337 ring_node *ring_node_swf1_extracted_ptr;
336 ring_node *ring_node_swf1_extracted_ptr;
338 ring_node *ring_node_swf2_extracted_ptr;
337 ring_node *ring_node_swf2_extracted_ptr;
339
338
340 ring_node_swf1_extracted_ptr = (ring_node *) &ring_node_swf1_extracted;
339 ring_node_swf1_extracted_ptr = (ring_node *) &ring_node_swf1_extracted;
341 ring_node_swf2_extracted_ptr = (ring_node *) &ring_node_swf2_extracted;
340 ring_node_swf2_extracted_ptr = (ring_node *) &ring_node_swf2_extracted;
342
341
343 status = get_message_queue_id_send( &queue_id );
342 status = get_message_queue_id_send( &queue_id );
344 if (status != RTEMS_SUCCESSFUL)
343 if (status != RTEMS_SUCCESSFUL)
345 {
344 {
346 PRINTF1("in WFRM *** ERR get_message_queue_id_send %d\n", status);
345 PRINTF1("in WFRM *** ERR get_message_queue_id_send %d\n", status);
347 }
346 }
348
347
349 BOOT_PRINTF("in WFRM ***\n");
348 BOOT_PRINTF("in WFRM ***\n");
350
349
351 while(1){
350 while(1){
352 // wait for an RTEMS_EVENT
351 // wait for an RTEMS_EVENT
353 rtems_event_receive(RTEMS_EVENT_MODE_NORMAL | RTEMS_EVENT_SWF_RESYNCH,
352 rtems_event_receive(RTEMS_EVENT_MODE_NORMAL | RTEMS_EVENT_SWF_RESYNCH,
354 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
353 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
355
354
356 if (event_out == RTEMS_EVENT_MODE_NORMAL)
355 if (event_out == RTEMS_EVENT_MODE_NORMAL)
357 {
356 {
358 DEBUG_PRINTF("WFRM received RTEMS_EVENT_MODE_SBM2\n");
357 DEBUG_PRINTF("WFRM received RTEMS_EVENT_MODE_SBM2\n");
359 ring_node_to_send_swf_f0->sid = SID_NORM_SWF_F0;
358 ring_node_to_send_swf_f0->sid = SID_NORM_SWF_F0;
360 ring_node_swf1_extracted_ptr->sid = SID_NORM_SWF_F1;
359 ring_node_swf1_extracted_ptr->sid = SID_NORM_SWF_F1;
361 ring_node_swf2_extracted_ptr->sid = SID_NORM_SWF_F2;
360 ring_node_swf2_extracted_ptr->sid = SID_NORM_SWF_F2;
362 status = rtems_message_queue_send( queue_id, &ring_node_to_send_swf_f0, sizeof( ring_node* ) );
361 status = rtems_message_queue_send( queue_id, &ring_node_to_send_swf_f0, sizeof( ring_node* ) );
363 status = rtems_message_queue_send( queue_id, &ring_node_swf1_extracted_ptr, sizeof( ring_node* ) );
362 status = rtems_message_queue_send( queue_id, &ring_node_swf1_extracted_ptr, sizeof( ring_node* ) );
364 status = rtems_message_queue_send( queue_id, &ring_node_swf2_extracted_ptr, sizeof( ring_node* ) );
363 status = rtems_message_queue_send( queue_id, &ring_node_swf2_extracted_ptr, sizeof( ring_node* ) );
365 }
364 }
366 if (event_out == RTEMS_EVENT_SWF_RESYNCH)
365 if (event_out == RTEMS_EVENT_SWF_RESYNCH)
367 {
366 {
368 snapshot_resynchronization( (unsigned char *) &ring_node_to_send_swf_f0->coarseTime );
367 snapshot_resynchronization( (unsigned char *) &ring_node_to_send_swf_f0->coarseTime );
369 }
368 }
370 }
369 }
371 }
370 }
372
371
373 rtems_task cwf3_task(rtems_task_argument argument) //used with the waveform picker VHDL IP
372 rtems_task cwf3_task(rtems_task_argument argument) //used with the waveform picker VHDL IP
374 {
373 {
375 /** This RTEMS task is dedicated to the transmission of continuous waveforms at f3.
374 /** This RTEMS task is dedicated to the transmission of continuous waveforms at f3.
376 *
375 *
377 * @param unused is the starting argument of the RTEMS task
376 * @param unused is the starting argument of the RTEMS task
378 *
377 *
379 * The following data packet is sent by this task:
378 * The following data packet is sent by this task:
380 * - TM_LFR_SCIENCE_NORMAL_CWF_F3
379 * - TM_LFR_SCIENCE_NORMAL_CWF_F3
381 *
380 *
382 */
381 */
383
382
384 rtems_event_set event_out;
383 rtems_event_set event_out;
385 rtems_id queue_id;
384 rtems_id queue_id;
386 rtems_status_code status;
385 rtems_status_code status;
387 ring_node ring_node_cwf3_light;
386 ring_node ring_node_cwf3_light;
388 ring_node *ring_node_to_send_cwf;
387 ring_node *ring_node_to_send_cwf;
389
388
390 status = get_message_queue_id_send( &queue_id );
389 status = get_message_queue_id_send( &queue_id );
391 if (status != RTEMS_SUCCESSFUL)
390 if (status != RTEMS_SUCCESSFUL)
392 {
391 {
393 PRINTF1("in CWF3 *** ERR get_message_queue_id_send %d\n", status)
392 PRINTF1("in CWF3 *** ERR get_message_queue_id_send %d\n", status)
394 }
393 }
395
394
396 ring_node_to_send_cwf_f3->sid = SID_NORM_CWF_LONG_F3;
395 ring_node_to_send_cwf_f3->sid = SID_NORM_CWF_LONG_F3;
397
396
398 // init the ring_node_cwf3_light structure
397 // init the ring_node_cwf3_light structure
399 ring_node_cwf3_light.buffer_address = (int) wf_cont_f3_light;
398 ring_node_cwf3_light.buffer_address = (int) wf_cont_f3_light;
400 ring_node_cwf3_light.coarseTime = 0x00;
399 ring_node_cwf3_light.coarseTime = INIT_CHAR;
401 ring_node_cwf3_light.fineTime = 0x00;
400 ring_node_cwf3_light.fineTime = INIT_CHAR;
402 ring_node_cwf3_light.next = NULL;
401 ring_node_cwf3_light.next = NULL;
403 ring_node_cwf3_light.previous = NULL;
402 ring_node_cwf3_light.previous = NULL;
404 ring_node_cwf3_light.sid = SID_NORM_CWF_F3;
403 ring_node_cwf3_light.sid = SID_NORM_CWF_F3;
405 ring_node_cwf3_light.status = 0x00;
404 ring_node_cwf3_light.status = INIT_CHAR;
406
405
407 BOOT_PRINTF("in CWF3 ***\n");
406 BOOT_PRINTF("in CWF3 ***\n");
408
407
409 while(1){
408 while(1){
410 // wait for an RTEMS_EVENT
409 // wait for an RTEMS_EVENT
411 rtems_event_receive( RTEMS_EVENT_0,
410 rtems_event_receive( RTEMS_EVENT_0,
412 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
411 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
413 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
412 if ( (lfrCurrentMode == LFR_MODE_NORMAL)
414 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode==LFR_MODE_SBM2) )
413 || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode==LFR_MODE_SBM2) )
415 {
414 {
416 ring_node_to_send_cwf = getRingNodeToSendCWF( 3 );
415 ring_node_to_send_cwf = getRingNodeToSendCWF( CHANNELF3 );
417 if ( (parameter_dump_packet.sy_lfr_n_cwf_long_f3 & 0x01) == 0x01)
416 if ( (parameter_dump_packet.sy_lfr_n_cwf_long_f3 & BIT_CWF_LONG_F3) == BIT_CWF_LONG_F3)
418 {
417 {
419 PRINTF("send CWF_LONG_F3\n");
418 PRINTF("send CWF_LONG_F3\n");
420 ring_node_to_send_cwf_f3->sid = SID_NORM_CWF_LONG_F3;
419 ring_node_to_send_cwf_f3->sid = SID_NORM_CWF_LONG_F3;
421 status = rtems_message_queue_send( queue_id, &ring_node_to_send_cwf, sizeof( ring_node* ) );
420 status = rtems_message_queue_send( queue_id, &ring_node_to_send_cwf, sizeof( ring_node* ) );
422 }
421 }
423 else
422 else
424 {
423 {
425 PRINTF("send CWF_F3 (light)\n");
424 PRINTF("send CWF_F3 (light)\n");
426 send_waveform_CWF3_light( ring_node_to_send_cwf, &ring_node_cwf3_light, queue_id );
425 send_waveform_CWF3_light( ring_node_to_send_cwf, &ring_node_cwf3_light, queue_id );
427 }
426 }
428
427
429 }
428 }
430 else
429 else
431 {
430 {
432 PRINTF1("in CWF3 *** lfrCurrentMode is %d, no data will be sent\n", lfrCurrentMode)
431 PRINTF1("in CWF3 *** lfrCurrentMode is %d, no data will be sent\n", lfrCurrentMode)
433 }
432 }
434 }
433 }
435 }
434 }
436
435
437 rtems_task cwf2_task(rtems_task_argument argument) // ONLY USED IN BURST AND SBM2
436 rtems_task cwf2_task(rtems_task_argument argument) // ONLY USED IN BURST AND SBM2
438 {
437 {
439 /** This RTEMS task is dedicated to the transmission of continuous waveforms at f2.
438 /** This RTEMS task is dedicated to the transmission of continuous waveforms at f2.
440 *
439 *
441 * @param unused is the starting argument of the RTEMS task
440 * @param unused is the starting argument of the RTEMS task
442 *
441 *
443 * The following data packet is sent by this function:
442 * The following data packet is sent by this function:
444 * - TM_LFR_SCIENCE_BURST_CWF_F2
443 * - TM_LFR_SCIENCE_BURST_CWF_F2
445 * - TM_LFR_SCIENCE_SBM2_CWF_F2
444 * - TM_LFR_SCIENCE_SBM2_CWF_F2
446 *
445 *
447 */
446 */
448
447
449 rtems_event_set event_out;
448 rtems_event_set event_out;
450 rtems_id queue_id;
449 rtems_id queue_id;
451 rtems_status_code status;
450 rtems_status_code status;
452 ring_node *ring_node_to_send;
451 ring_node *ring_node_to_send;
453 unsigned long long int acquisitionTimeF0_asLong;
452 unsigned long long int acquisitionTimeF0_asLong;
454
453
455 acquisitionTimeF0_asLong = 0x00;
454 acquisitionTimeF0_asLong = INIT_CHAR;
456
455
457 status = get_message_queue_id_send( &queue_id );
456 status = get_message_queue_id_send( &queue_id );
458 if (status != RTEMS_SUCCESSFUL)
457 if (status != RTEMS_SUCCESSFUL)
459 {
458 {
460 PRINTF1("in CWF2 *** ERR get_message_queue_id_send %d\n", status)
459 PRINTF1("in CWF2 *** ERR get_message_queue_id_send %d\n", status)
461 }
460 }
462
461
463 BOOT_PRINTF("in CWF2 ***\n");
462 BOOT_PRINTF("in CWF2 ***\n");
464
463
465 while(1){
464 while(1){
466 // wait for an RTEMS_EVENT// send the snapshot when built
465 // wait for an RTEMS_EVENT// send the snapshot when built
467 status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_SBM2 );
466 status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_SBM2 );
468 rtems_event_receive( RTEMS_EVENT_MODE_NORM_S1_S2 | RTEMS_EVENT_MODE_BURST,
467 rtems_event_receive( RTEMS_EVENT_MODE_NORM_S1_S2 | RTEMS_EVENT_MODE_BURST,
469 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
468 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
470 ring_node_to_send = getRingNodeToSendCWF( 2 );
469 ring_node_to_send = getRingNodeToSendCWF( CHANNELF2 );
471 if (event_out == RTEMS_EVENT_MODE_BURST)
470 if (event_out == RTEMS_EVENT_MODE_BURST)
472 { // data are sent whatever the transition time
471 { // data are sent whatever the transition time
473 status = rtems_message_queue_send( queue_id, &ring_node_to_send, sizeof( ring_node* ) );
472 status = rtems_message_queue_send( queue_id, &ring_node_to_send, sizeof( ring_node* ) );
474 }
473 }
475 else if (event_out == RTEMS_EVENT_MODE_NORM_S1_S2)
474 else if (event_out == RTEMS_EVENT_MODE_NORM_S1_S2)
476 {
475 {
477 if ( lfrCurrentMode == LFR_MODE_SBM2 )
476 if ( lfrCurrentMode == LFR_MODE_SBM2 )
478 {
477 {
479 // data are sent depending on the transition time
478 // data are sent depending on the transition time
480 if ( time_management_regs->coarse_time >= lastValidEnterModeTime)
479 if ( time_management_regs->coarse_time >= lastValidEnterModeTime)
481 {
480 {
482 status = rtems_message_queue_send( queue_id, &ring_node_to_send, sizeof( ring_node* ) );
481 status = rtems_message_queue_send( queue_id, &ring_node_to_send, sizeof( ring_node* ) );
483 }
482 }
484 }
483 }
485 // launch snapshot extraction if needed
484 // launch snapshot extraction if needed
486 if (extractSWF2 == true)
485 if (extractSWF2 == true)
487 {
486 {
488 ring_node_to_send_swf_f2 = ring_node_to_send_cwf_f2;
487 ring_node_to_send_swf_f2 = ring_node_to_send_cwf_f2;
489 // extract the snapshot
488 // extract the snapshot
490 build_snapshot_from_ring( ring_node_to_send_swf_f2, 2, acquisitionTimeF0_asLong,
489 build_snapshot_from_ring( ring_node_to_send_swf_f2, CHANNELF2, acquisitionTimeF0_asLong,
491 &ring_node_swf2_extracted, swf2_extracted );
490 &ring_node_swf2_extracted, swf2_extracted );
492 extractSWF2 = false;
491 extractSWF2 = false;
493 swf2_ready = true; // once the snapshot at f2 is ready the CWF1 task will send an event to WFRM
492 swf2_ready = true; // once the snapshot at f2 is ready the CWF1 task will send an event to WFRM
494 }
493 }
495 if (swf0_ready_flag_f2 == true)
494 if (swf0_ready_flag_f2 == true)
496 {
495 {
497 extractSWF2 = true;
496 extractSWF2 = true;
498 // record the acquition time of the f0 snapshot to use to build the snapshot at f2
497 // record the acquition time of the f0 snapshot to use to build the snapshot at f2
499 acquisitionTimeF0_asLong = get_acquisition_time( (unsigned char *) &ring_node_to_send_swf_f0->coarseTime );
498 acquisitionTimeF0_asLong = get_acquisition_time( (unsigned char *) &ring_node_to_send_swf_f0->coarseTime );
500 swf0_ready_flag_f2 = false;
499 swf0_ready_flag_f2 = false;
501 }
500 }
502 }
501 }
503 }
502 }
504 }
503 }
505
504
506 rtems_task cwf1_task(rtems_task_argument argument) // ONLY USED IN SBM1
505 rtems_task cwf1_task(rtems_task_argument argument) // ONLY USED IN SBM1
507 {
506 {
508 /** This RTEMS task is dedicated to the transmission of continuous waveforms at f1.
507 /** This RTEMS task is dedicated to the transmission of continuous waveforms at f1.
509 *
508 *
510 * @param unused is the starting argument of the RTEMS task
509 * @param unused is the starting argument of the RTEMS task
511 *
510 *
512 * The following data packet is sent by this function:
511 * The following data packet is sent by this function:
513 * - TM_LFR_SCIENCE_SBM1_CWF_F1
512 * - TM_LFR_SCIENCE_SBM1_CWF_F1
514 *
513 *
515 */
514 */
516
515
517 rtems_event_set event_out;
516 rtems_event_set event_out;
518 rtems_id queue_id;
517 rtems_id queue_id;
519 rtems_status_code status;
518 rtems_status_code status;
520
519
521 ring_node *ring_node_to_send_cwf;
520 ring_node *ring_node_to_send_cwf;
522
521
523 status = get_message_queue_id_send( &queue_id );
522 status = get_message_queue_id_send( &queue_id );
524 if (status != RTEMS_SUCCESSFUL)
523 if (status != RTEMS_SUCCESSFUL)
525 {
524 {
526 PRINTF1("in CWF1 *** ERR get_message_queue_id_send %d\n", status)
525 PRINTF1("in CWF1 *** ERR get_message_queue_id_send %d\n", status)
527 }
526 }
528
527
529 BOOT_PRINTF("in CWF1 ***\n");
528 BOOT_PRINTF("in CWF1 ***\n");
530
529
531 while(1){
530 while(1){
532 // wait for an RTEMS_EVENT
531 // wait for an RTEMS_EVENT
533 rtems_event_receive( RTEMS_EVENT_MODE_NORM_S1_S2,
532 rtems_event_receive( RTEMS_EVENT_MODE_NORM_S1_S2,
534 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
533 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
535 ring_node_to_send_cwf = getRingNodeToSendCWF( 1 );
534 ring_node_to_send_cwf = getRingNodeToSendCWF( 1 );
536 ring_node_to_send_cwf_f1->sid = SID_SBM1_CWF_F1;
535 ring_node_to_send_cwf_f1->sid = SID_SBM1_CWF_F1;
537 if (lfrCurrentMode == LFR_MODE_SBM1)
536 if (lfrCurrentMode == LFR_MODE_SBM1)
538 {
537 {
539 // data are sent depending on the transition time
538 // data are sent depending on the transition time
540 if ( time_management_regs->coarse_time >= lastValidEnterModeTime )
539 if ( time_management_regs->coarse_time >= lastValidEnterModeTime )
541 {
540 {
542 status = rtems_message_queue_send( queue_id, &ring_node_to_send_cwf, sizeof( ring_node* ) );
541 status = rtems_message_queue_send( queue_id, &ring_node_to_send_cwf, sizeof( ring_node* ) );
543 }
542 }
544 }
543 }
545 // launch snapshot extraction if needed
544 // launch snapshot extraction if needed
546 if (extractSWF1 == true)
545 if (extractSWF1 == true)
547 {
546 {
548 ring_node_to_send_swf_f1 = ring_node_to_send_cwf;
547 ring_node_to_send_swf_f1 = ring_node_to_send_cwf;
549 // launch the snapshot extraction
548 // launch the snapshot extraction
550 status = rtems_event_send( Task_id[TASKID_SWBD], RTEMS_EVENT_MODE_NORM_S1_S2 );
549 status = rtems_event_send( Task_id[TASKID_SWBD], RTEMS_EVENT_MODE_NORM_S1_S2 );
551 extractSWF1 = false;
550 extractSWF1 = false;
552 }
551 }
553 if (swf0_ready_flag_f1 == true)
552 if (swf0_ready_flag_f1 == true)
554 {
553 {
555 extractSWF1 = true;
554 extractSWF1 = true;
556 swf0_ready_flag_f1 = false; // this step shall be executed only one time
555 swf0_ready_flag_f1 = false; // this step shall be executed only one time
557 }
556 }
558 if ((swf1_ready == true) && (swf2_ready == true)) // swf_f1 is ready after the extraction
557 if ((swf1_ready == true) && (swf2_ready == true)) // swf_f1 is ready after the extraction
559 {
558 {
560 status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_NORMAL );
559 status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_NORMAL );
561 swf1_ready = false;
560 swf1_ready = false;
562 swf2_ready = false;
561 swf2_ready = false;
563 }
562 }
564 }
563 }
565 }
564 }
566
565
567 rtems_task swbd_task(rtems_task_argument argument)
566 rtems_task swbd_task(rtems_task_argument argument)
568 {
567 {
569 /** This RTEMS task is dedicated to the building of snapshots from different continuous waveforms buffers.
568 /** This RTEMS task is dedicated to the building of snapshots from different continuous waveforms buffers.
570 *
569 *
571 * @param unused is the starting argument of the RTEMS task
570 * @param unused is the starting argument of the RTEMS task
572 *
571 *
573 */
572 */
574
573
575 rtems_event_set event_out;
574 rtems_event_set event_out;
576 unsigned long long int acquisitionTimeF0_asLong;
575 unsigned long long int acquisitionTimeF0_asLong;
577
576
578 acquisitionTimeF0_asLong = 0x00;
577 acquisitionTimeF0_asLong = INIT_CHAR;
579
578
580 BOOT_PRINTF("in SWBD ***\n")
579 BOOT_PRINTF("in SWBD ***\n")
581
580
582 while(1){
581 while(1){
583 // wait for an RTEMS_EVENT
582 // wait for an RTEMS_EVENT
584 rtems_event_receive( RTEMS_EVENT_MODE_NORM_S1_S2,
583 rtems_event_receive( RTEMS_EVENT_MODE_NORM_S1_S2,
585 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
584 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out);
586 if (event_out == RTEMS_EVENT_MODE_NORM_S1_S2)
585 if (event_out == RTEMS_EVENT_MODE_NORM_S1_S2)
587 {
586 {
588 acquisitionTimeF0_asLong = get_acquisition_time( (unsigned char *) &ring_node_to_send_swf_f0->coarseTime );
587 acquisitionTimeF0_asLong = get_acquisition_time( (unsigned char *) &ring_node_to_send_swf_f0->coarseTime );
589 build_snapshot_from_ring( ring_node_to_send_swf_f1, 1, acquisitionTimeF0_asLong,
588 build_snapshot_from_ring( ring_node_to_send_swf_f1, 1, acquisitionTimeF0_asLong,
590 &ring_node_swf1_extracted, swf1_extracted );
589 &ring_node_swf1_extracted, swf1_extracted );
591 swf1_ready = true; // the snapshot has been extracted and is ready to be sent
590 swf1_ready = true; // the snapshot has been extracted and is ready to be sent
592 }
591 }
593 else
592 else
594 {
593 {
595 PRINTF1("in SWBD *** unexpected rtems event received %x\n", (int) event_out)
594 PRINTF1("in SWBD *** unexpected rtems event received %x\n", (int) event_out)
596 }
595 }
597 }
596 }
598 }
597 }
599
598
600 //******************
599 //******************
601 // general functions
600 // general functions
602
601
603 void WFP_init_rings( void )
602 void WFP_init_rings( void )
604 {
603 {
605 // F0 RING
604 // F0 RING
606 init_ring( waveform_ring_f0, NB_RING_NODES_F0, wf_buffer_f0, WFRM_BUFFER );
605 init_ring( waveform_ring_f0, NB_RING_NODES_F0, wf_buffer_f0, WFRM_BUFFER );
607 // F1 RING
606 // F1 RING
608 init_ring( waveform_ring_f1, NB_RING_NODES_F1, wf_buffer_f1, WFRM_BUFFER );
607 init_ring( waveform_ring_f1, NB_RING_NODES_F1, wf_buffer_f1, WFRM_BUFFER );
609 // F2 RING
608 // F2 RING
610 init_ring( waveform_ring_f2, NB_RING_NODES_F2, wf_buffer_f2, WFRM_BUFFER );
609 init_ring( waveform_ring_f2, NB_RING_NODES_F2, wf_buffer_f2, WFRM_BUFFER );
611 // F3 RING
610 // F3 RING
612 init_ring( waveform_ring_f3, NB_RING_NODES_F3, wf_buffer_f3, WFRM_BUFFER );
611 init_ring( waveform_ring_f3, NB_RING_NODES_F3, wf_buffer_f3, WFRM_BUFFER );
613
612
614 ring_node_swf1_extracted.buffer_address = (int) swf1_extracted;
613 ring_node_swf1_extracted.buffer_address = (int) swf1_extracted;
615 ring_node_swf2_extracted.buffer_address = (int) swf2_extracted;
614 ring_node_swf2_extracted.buffer_address = (int) swf2_extracted;
616
615
617 DEBUG_PRINTF1("waveform_ring_f0 @%x\n", (unsigned int) waveform_ring_f0)
616 DEBUG_PRINTF1("waveform_ring_f0 @%x\n", (unsigned int) waveform_ring_f0)
618 DEBUG_PRINTF1("waveform_ring_f1 @%x\n", (unsigned int) waveform_ring_f1)
617 DEBUG_PRINTF1("waveform_ring_f1 @%x\n", (unsigned int) waveform_ring_f1)
619 DEBUG_PRINTF1("waveform_ring_f2 @%x\n", (unsigned int) waveform_ring_f2)
618 DEBUG_PRINTF1("waveform_ring_f2 @%x\n", (unsigned int) waveform_ring_f2)
620 DEBUG_PRINTF1("waveform_ring_f3 @%x\n", (unsigned int) waveform_ring_f3)
619 DEBUG_PRINTF1("waveform_ring_f3 @%x\n", (unsigned int) waveform_ring_f3)
621 DEBUG_PRINTF1("wf_buffer_f0 @%x\n", (unsigned int) wf_buffer_f0)
620 DEBUG_PRINTF1("wf_buffer_f0 @%x\n", (unsigned int) wf_buffer_f0)
622 DEBUG_PRINTF1("wf_buffer_f1 @%x\n", (unsigned int) wf_buffer_f1)
621 DEBUG_PRINTF1("wf_buffer_f1 @%x\n", (unsigned int) wf_buffer_f1)
623 DEBUG_PRINTF1("wf_buffer_f2 @%x\n", (unsigned int) wf_buffer_f2)
622 DEBUG_PRINTF1("wf_buffer_f2 @%x\n", (unsigned int) wf_buffer_f2)
624 DEBUG_PRINTF1("wf_buffer_f3 @%x\n", (unsigned int) wf_buffer_f3)
623 DEBUG_PRINTF1("wf_buffer_f3 @%x\n", (unsigned int) wf_buffer_f3)
625
624
626 }
625 }
627
626
628 void WFP_reset_current_ring_nodes( void )
627 void WFP_reset_current_ring_nodes( void )
629 {
628 {
630 current_ring_node_f0 = waveform_ring_f0[0].next;
629 current_ring_node_f0 = waveform_ring_f0[0].next;
631 current_ring_node_f1 = waveform_ring_f1[0].next;
630 current_ring_node_f1 = waveform_ring_f1[0].next;
632 current_ring_node_f2 = waveform_ring_f2[0].next;
631 current_ring_node_f2 = waveform_ring_f2[0].next;
633 current_ring_node_f3 = waveform_ring_f3[0].next;
632 current_ring_node_f3 = waveform_ring_f3[0].next;
634
633
635 ring_node_to_send_swf_f0 = waveform_ring_f0;
634 ring_node_to_send_swf_f0 = waveform_ring_f0;
636 ring_node_to_send_swf_f1 = waveform_ring_f1;
635 ring_node_to_send_swf_f1 = waveform_ring_f1;
637 ring_node_to_send_swf_f2 = waveform_ring_f2;
636 ring_node_to_send_swf_f2 = waveform_ring_f2;
638
637
639 ring_node_to_send_cwf_f1 = waveform_ring_f1;
638 ring_node_to_send_cwf_f1 = waveform_ring_f1;
640 ring_node_to_send_cwf_f2 = waveform_ring_f2;
639 ring_node_to_send_cwf_f2 = waveform_ring_f2;
641 ring_node_to_send_cwf_f3 = waveform_ring_f3;
640 ring_node_to_send_cwf_f3 = waveform_ring_f3;
642 }
641 }
643
642
644 int send_waveform_CWF3_light( ring_node *ring_node_to_send, ring_node *ring_node_cwf3_light, rtems_id queue_id )
643 int send_waveform_CWF3_light( ring_node *ring_node_to_send, ring_node *ring_node_cwf3_light, rtems_id queue_id )
645 {
644 {
646 /** This function sends CWF_F3 CCSDS packets without the b1, b2 and b3 data.
645 /** This function sends CWF_F3 CCSDS packets without the b1, b2 and b3 data.
647 *
646 *
648 * @param waveform points to the buffer containing the data that will be send.
647 * @param waveform points to the buffer containing the data that will be send.
649 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
648 * @param headerCWF points to a table of headers that have been prepared for the data transmission.
650 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
649 * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures
651 * contain information to setup the transmission of the data packets.
650 * contain information to setup the transmission of the data packets.
652 *
651 *
653 * By default, CWF_F3 packet are send without the b1, b2 and b3 data. This function rebuilds a data buffer
652 * By default, CWF_F3 packet are send without the b1, b2 and b3 data. This function rebuilds a data buffer
654 * from the incoming data and sends it in 7 packets, 6 containing 340 blocks and 1 one containing 8 blocks.
653 * from the incoming data and sends it in 7 packets, 6 containing 340 blocks and 1 one containing 8 blocks.
655 *
654 *
656 */
655 */
657
656
658 unsigned int i;
657 unsigned int i;
658 unsigned int j;
659 int ret;
659 int ret;
660 rtems_status_code status;
660 rtems_status_code status;
661
661
662 char *sample;
662 char *sample;
663 int *dataPtr;
663 int *dataPtr;
664
664
665 ret = LFR_DEFAULT;
665 ret = LFR_DEFAULT;
666
666
667 dataPtr = (int*) ring_node_to_send->buffer_address;
667 dataPtr = (int*) ring_node_to_send->buffer_address;
668
668
669 ring_node_cwf3_light->coarseTime = ring_node_to_send->coarseTime;
669 ring_node_cwf3_light->coarseTime = ring_node_to_send->coarseTime;
670 ring_node_cwf3_light->fineTime = ring_node_to_send->fineTime;
670 ring_node_cwf3_light->fineTime = ring_node_to_send->fineTime;
671
671
672 //**********************
672 //**********************
673 // BUILD CWF3_light DATA
673 // BUILD CWF3_light DATA
674 for ( i=0; i< NB_SAMPLES_PER_SNAPSHOT; i++)
674 for ( i=0; i< NB_SAMPLES_PER_SNAPSHOT; i++)
675 {
675 {
676 sample = (char*) &dataPtr[ (i * NB_WORDS_SWF_BLK) ];
676 sample = (char*) &dataPtr[ (i * NB_WORDS_SWF_BLK) ];
677 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) ] = sample[ 0 ];
677 for (j=0; j < CWF_BLK_SIZE; j++)
678 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 1 ] = sample[ 1 ];
678 {
679 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 2 ] = sample[ 2 ];
679 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + j] = sample[ j ];
680 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 3 ] = sample[ 3 ];
680 }
681 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 4 ] = sample[ 4 ];
682 wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + 5 ] = sample[ 5 ];
683 }
681 }
684
682
685 // SEND PACKET
683 // SEND PACKET
686 status = rtems_message_queue_send( queue_id, &ring_node_cwf3_light, sizeof( ring_node* ) );
684 status = rtems_message_queue_send( queue_id, &ring_node_cwf3_light, sizeof( ring_node* ) );
687 if (status != RTEMS_SUCCESSFUL) {
685 if (status != RTEMS_SUCCESSFUL) {
688 ret = LFR_DEFAULT;
686 ret = LFR_DEFAULT;
689 }
687 }
690
688
691 return ret;
689 return ret;
692 }
690 }
693
691
694 void compute_acquisition_time( unsigned int coarseTime, unsigned int fineTime,
692 void compute_acquisition_time( unsigned int coarseTime, unsigned int fineTime,
695 unsigned int sid, unsigned char pa_lfr_pkt_nr, unsigned char * acquisitionTime )
693 unsigned int sid, unsigned char pa_lfr_pkt_nr, unsigned char * acquisitionTime )
696 {
694 {
697 unsigned long long int acquisitionTimeAsLong;
695 unsigned long long int acquisitionTimeAsLong;
698 unsigned char localAcquisitionTime[6];
696 unsigned char localAcquisitionTime[BYTES_PER_TIME];
699 double deltaT;
697 double deltaT;
700
698
701 deltaT = 0.;
699 deltaT = INIT_FLOAT;
702
700
703 localAcquisitionTime[0] = (unsigned char) ( coarseTime >> 24 );
701 localAcquisitionTime[BYTE_0] = (unsigned char) ( coarseTime >> SHIFT_3_BYTES );
704 localAcquisitionTime[1] = (unsigned char) ( coarseTime >> 16 );
702 localAcquisitionTime[BYTE_1] = (unsigned char) ( coarseTime >> SHIFT_2_BYTES );
705 localAcquisitionTime[2] = (unsigned char) ( coarseTime >> 8 );
703 localAcquisitionTime[BYTE_2] = (unsigned char) ( coarseTime >> SHIFT_1_BYTE );
706 localAcquisitionTime[3] = (unsigned char) ( coarseTime );
704 localAcquisitionTime[BYTE_3] = (unsigned char) ( coarseTime );
707 localAcquisitionTime[4] = (unsigned char) ( fineTime >> 8 );
705 localAcquisitionTime[BYTE_4] = (unsigned char) ( fineTime >> SHIFT_1_BYTE );
708 localAcquisitionTime[5] = (unsigned char) ( fineTime );
706 localAcquisitionTime[BYTE_5] = (unsigned char) ( fineTime );
709
707
710 acquisitionTimeAsLong = ( (unsigned long long int) localAcquisitionTime[0] << 40 )
708 acquisitionTimeAsLong = ( (unsigned long long int) localAcquisitionTime[BYTE_0] << SHIFT_5_BYTES )
711 + ( (unsigned long long int) localAcquisitionTime[1] << 32 )
709 + ( (unsigned long long int) localAcquisitionTime[BYTE_1] << SHIFT_4_BYTES )
712 + ( (unsigned long long int) localAcquisitionTime[2] << 24 )
710 + ( (unsigned long long int) localAcquisitionTime[BYTE_2] << SHIFT_3_BYTES )
713 + ( (unsigned long long int) localAcquisitionTime[3] << 16 )
711 + ( (unsigned long long int) localAcquisitionTime[BYTE_3] << SHIFT_2_BYTES )
714 + ( (unsigned long long int) localAcquisitionTime[4] << 8 )
712 + ( (unsigned long long int) localAcquisitionTime[BYTE_4] << SHIFT_1_BYTE )
715 + ( (unsigned long long int) localAcquisitionTime[5] );
713 + ( (unsigned long long int) localAcquisitionTime[BYTE_5] );
716
714
717 switch( sid )
715 switch( sid )
718 {
716 {
719 case SID_NORM_SWF_F0:
717 case SID_NORM_SWF_F0:
720 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * 65536. / 24576. ;
718 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * T0_IN_FINETIME ;
721 break;
719 break;
722
720
723 case SID_NORM_SWF_F1:
721 case SID_NORM_SWF_F1:
724 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * 65536. / 4096. ;
722 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * T1_IN_FINETIME ;
725 break;
723 break;
726
724
727 case SID_NORM_SWF_F2:
725 case SID_NORM_SWF_F2:
728 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * 65536. / 256. ;
726 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * T2_IN_FINETIME ;
729 break;
727 break;
730
728
731 case SID_SBM1_CWF_F1:
729 case SID_SBM1_CWF_F1:
732 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * 65536. / 4096. ;
730 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * T1_IN_FINETIME ;
733 break;
731 break;
734
732
735 case SID_SBM2_CWF_F2:
733 case SID_SBM2_CWF_F2:
736 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * 65536. / 256. ;
734 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * T2_IN_FINETIME ;
737 break;
735 break;
738
736
739 case SID_BURST_CWF_F2:
737 case SID_BURST_CWF_F2:
740 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * 65536. / 256. ;
738 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * T2_IN_FINETIME ;
741 break;
739 break;
742
740
743 case SID_NORM_CWF_F3:
741 case SID_NORM_CWF_F3:
744 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF_SHORT_F3 * 65536. / 16. ;
742 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF_SHORT_F3 * T3_IN_FINETIME ;
745 break;
743 break;
746
744
747 case SID_NORM_CWF_LONG_F3:
745 case SID_NORM_CWF_LONG_F3:
748 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * 65536. / 16. ;
746 deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * T3_IN_FINETIME ;
749 break;
747 break;
750
748
751 default:
749 default:
752 PRINTF1("in compute_acquisition_time *** ERR unexpected sid %d\n", sid)
750 PRINTF1("in compute_acquisition_time *** ERR unexpected sid %d\n", sid)
753 deltaT = 0.;
751 deltaT = 0.;
754 break;
752 break;
755 }
753 }
756
754
757 acquisitionTimeAsLong = acquisitionTimeAsLong + (unsigned long long int) deltaT;
755 acquisitionTimeAsLong = acquisitionTimeAsLong + (unsigned long long int) deltaT;
758 //
756 //
759 acquisitionTime[0] = (unsigned char) (acquisitionTimeAsLong >> 40);
757 acquisitionTime[BYTE_0] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_5_BYTES);
760 acquisitionTime[1] = (unsigned char) (acquisitionTimeAsLong >> 32);
758 acquisitionTime[BYTE_1] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_4_BYTES);
761 acquisitionTime[2] = (unsigned char) (acquisitionTimeAsLong >> 24);
759 acquisitionTime[BYTE_2] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_3_BYTES);
762 acquisitionTime[3] = (unsigned char) (acquisitionTimeAsLong >> 16);
760 acquisitionTime[BYTE_3] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_2_BYTES);
763 acquisitionTime[4] = (unsigned char) (acquisitionTimeAsLong >> 8 );
761 acquisitionTime[BYTE_4] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_1_BYTE );
764 acquisitionTime[5] = (unsigned char) (acquisitionTimeAsLong );
762 acquisitionTime[BYTE_5] = (unsigned char) (acquisitionTimeAsLong );
765
763
766 }
764 }
767
765
768 void build_snapshot_from_ring( ring_node *ring_node_to_send,
766 void build_snapshot_from_ring( ring_node *ring_node_to_send,
769 unsigned char frequencyChannel,
767 unsigned char frequencyChannel,
770 unsigned long long int acquisitionTimeF0_asLong,
768 unsigned long long int acquisitionTimeF0_asLong,
771 ring_node *ring_node_swf_extracted,
769 ring_node *ring_node_swf_extracted,
772 int *swf_extracted)
770 int *swf_extracted)
773 {
771 {
774 unsigned int i;
772 unsigned int i;
775 unsigned long long int centerTime_asLong;
773 unsigned long long int centerTime_asLong;
776 unsigned long long int acquisitionTime_asLong;
774 unsigned long long int acquisitionTime_asLong;
777 unsigned long long int bufferAcquisitionTime_asLong;
775 unsigned long long int bufferAcquisitionTime_asLong;
778 unsigned char *ptr1;
776 unsigned char *ptr1;
779 unsigned char *ptr2;
777 unsigned char *ptr2;
780 unsigned char *timeCharPtr;
778 unsigned char *timeCharPtr;
781 unsigned char nb_ring_nodes;
779 unsigned char nb_ring_nodes;
782 unsigned long long int frequency_asLong;
780 unsigned long long int frequency_asLong;
783 unsigned long long int nbTicksPerSample_asLong;
781 unsigned long long int nbTicksPerSample_asLong;
784 unsigned long long int nbSamplesPart1_asLong;
782 unsigned long long int nbSamplesPart1_asLong;
785 unsigned long long int sampleOffset_asLong;
783 unsigned long long int sampleOffset_asLong;
786
784
787 unsigned int deltaT_F0;
785 unsigned int deltaT_F0;
788 unsigned int deltaT_F1;
786 unsigned int deltaT_F1;
789 unsigned long long int deltaT_F2;
787 unsigned long long int deltaT_F2;
790
788
791 deltaT_F0 = 2731; // (2048. / 24576. / 2.) * 65536. = 2730.667;
789 deltaT_F0 = DELTAT_F0;
792 deltaT_F1 = 16384; // (2048. / 4096. / 2.) * 65536. = 16384;
790 deltaT_F1 = DELTAF_F1;
793 deltaT_F2 = 262144; // (2048. / 256. / 2.) * 65536. = 262144;
791 deltaT_F2 = DELTAF_F2;
794 sampleOffset_asLong = 0x00;
792 sampleOffset_asLong = INIT_CHAR;
795
793
796 // (1) get the f0 acquisition time => the value is passed in argument
794 // (1) get the f0 acquisition time => the value is passed in argument
797
795
798 // (2) compute the central reference time
796 // (2) compute the central reference time
799 centerTime_asLong = acquisitionTimeF0_asLong + deltaT_F0;
797 centerTime_asLong = acquisitionTimeF0_asLong + deltaT_F0;
800
798
801 // (3) compute the acquisition time of the current snapshot
799 // (3) compute the acquisition time of the current snapshot
802 switch(frequencyChannel)
800 switch(frequencyChannel)
803 {
801 {
804 case 1: // 1 is for F1 = 4096 Hz
802 case CHANNELF1: // 1 is for F1 = 4096 Hz
805 acquisitionTime_asLong = centerTime_asLong - deltaT_F1;
803 acquisitionTime_asLong = centerTime_asLong - deltaT_F1;
806 nb_ring_nodes = NB_RING_NODES_F1;
804 nb_ring_nodes = NB_RING_NODES_F1;
807 frequency_asLong = 4096;
805 frequency_asLong = FREQ_F1;
808 nbTicksPerSample_asLong = 16; // 65536 / 4096;
806 nbTicksPerSample_asLong = TICKS_PER_T1; // 65536 / 4096;
809 break;
807 break;
810 case 2: // 2 is for F2 = 256 Hz
808 case CHANNELF2: // 2 is for F2 = 256 Hz
811 acquisitionTime_asLong = centerTime_asLong - deltaT_F2;
809 acquisitionTime_asLong = centerTime_asLong - deltaT_F2;
812 nb_ring_nodes = NB_RING_NODES_F2;
810 nb_ring_nodes = NB_RING_NODES_F2;
813 frequency_asLong = 256;
811 frequency_asLong = FREQ_F2;
814 nbTicksPerSample_asLong = 256; // 65536 / 256;
812 nbTicksPerSample_asLong = TICKS_PER_T2; // 65536 / 256;
815 break;
813 break;
816 default:
814 default:
817 acquisitionTime_asLong = centerTime_asLong;
815 acquisitionTime_asLong = centerTime_asLong;
818 frequency_asLong = 256;
816 frequency_asLong = FREQ_F2;
819 nbTicksPerSample_asLong = 256;
817 nbTicksPerSample_asLong = TICKS_PER_T2;
820 break;
818 break;
821 }
819 }
822
820
823 //****************************************************************************
821 //****************************************************************************
824 // (4) search the ring_node with the acquisition time <= acquisitionTime_asLong
822 // (4) search the ring_node with the acquisition time <= acquisitionTime_asLong
825 for (i=0; i<nb_ring_nodes; i++)
823 for (i=0; i<nb_ring_nodes; i++)
826 {
824 {
827 //PRINTF1("%d ... ", i);
825 //PRINTF1("%d ... ", i);
828 bufferAcquisitionTime_asLong = get_acquisition_time( (unsigned char *) &ring_node_to_send->coarseTime );
826 bufferAcquisitionTime_asLong = get_acquisition_time( (unsigned char *) &ring_node_to_send->coarseTime );
829 if (bufferAcquisitionTime_asLong <= acquisitionTime_asLong)
827 if (bufferAcquisitionTime_asLong <= acquisitionTime_asLong)
830 {
828 {
831 //PRINTF1("buffer found with acquisition time = %llx\n", bufferAcquisitionTime_asLong);
829 //PRINTF1("buffer found with acquisition time = %llx\n", bufferAcquisitionTime_asLong);
832 break;
830 break;
833 }
831 }
834 ring_node_to_send = ring_node_to_send->previous;
832 ring_node_to_send = ring_node_to_send->previous;
835 }
833 }
836
834
837 // (5) compute the number of samples to take in the current buffer
835 // (5) compute the number of samples to take in the current buffer
838 sampleOffset_asLong = ((acquisitionTime_asLong - bufferAcquisitionTime_asLong) * frequency_asLong ) >> 16;
836 sampleOffset_asLong = ((acquisitionTime_asLong - bufferAcquisitionTime_asLong) * frequency_asLong ) >> SHIFT_2_BYTES;
839 nbSamplesPart1_asLong = NB_SAMPLES_PER_SNAPSHOT - sampleOffset_asLong;
837 nbSamplesPart1_asLong = NB_SAMPLES_PER_SNAPSHOT - sampleOffset_asLong;
840 //PRINTF2("sampleOffset_asLong = %lld, nbSamplesPart1_asLong = %lld\n", sampleOffset_asLong, nbSamplesPart1_asLong);
838 //PRINTF2("sampleOffset_asLong = %lld, nbSamplesPart1_asLong = %lld\n", sampleOffset_asLong, nbSamplesPart1_asLong);
841
839
842 // (6) compute the final acquisition time
840 // (6) compute the final acquisition time
843 acquisitionTime_asLong = bufferAcquisitionTime_asLong +
841 acquisitionTime_asLong = bufferAcquisitionTime_asLong +
844 sampleOffset_asLong * nbTicksPerSample_asLong;
842 (sampleOffset_asLong * nbTicksPerSample_asLong);
845
843
846 // (7) copy the acquisition time at the beginning of the extrated snapshot
844 // (7) copy the acquisition time at the beginning of the extrated snapshot
847 ptr1 = (unsigned char*) &acquisitionTime_asLong;
845 ptr1 = (unsigned char*) &acquisitionTime_asLong;
848 // fine time
846 // fine time
849 ptr2 = (unsigned char*) &ring_node_swf_extracted->fineTime;
847 ptr2 = (unsigned char*) &ring_node_swf_extracted->fineTime;
850 ptr2[2] = ptr1[ 4 + 2 ];
848 ptr2[BYTE_2] = ptr1[ BYTE_4 + OFFSET_2_BYTES ];
851 ptr2[3] = ptr1[ 5 + 2 ];
849 ptr2[BYTE_3] = ptr1[ BYTE_5 + OFFSET_2_BYTES ];
852 // coarse time
850 // coarse time
853 ptr2 = (unsigned char*) &ring_node_swf_extracted->coarseTime;
851 ptr2 = (unsigned char*) &ring_node_swf_extracted->coarseTime;
854 ptr2[0] = ptr1[ 0 + 2 ];
852 ptr2[BYTE_0] = ptr1[ BYTE_0 + OFFSET_2_BYTES ];
855 ptr2[1] = ptr1[ 1 + 2 ];
853 ptr2[BYTE_1] = ptr1[ BYTE_1 + OFFSET_2_BYTES ];
856 ptr2[2] = ptr1[ 2 + 2 ];
854 ptr2[BYTE_2] = ptr1[ BYTE_2 + OFFSET_2_BYTES ];
857 ptr2[3] = ptr1[ 3 + 2 ];
855 ptr2[BYTE_3] = ptr1[ BYTE_3 + OFFSET_2_BYTES ];
858
856
859 // re set the synchronization bit
857 // re set the synchronization bit
860 timeCharPtr = (unsigned char*) &ring_node_to_send->coarseTime;
858 timeCharPtr = (unsigned char*) &ring_node_to_send->coarseTime;
861 ptr2[0] = ptr2[0] | (timeCharPtr[0] & 0x80); // [1000 0000]
859 ptr2[0] = ptr2[0] | (timeCharPtr[0] & SYNC_BIT); // [1000 0000]
862
860
863 if ( (nbSamplesPart1_asLong >= NB_SAMPLES_PER_SNAPSHOT) | (nbSamplesPart1_asLong < 0) )
861 if ( (nbSamplesPart1_asLong >= NB_SAMPLES_PER_SNAPSHOT) | (nbSamplesPart1_asLong < 0) )
864 {
862 {
865 nbSamplesPart1_asLong = 0;
863 nbSamplesPart1_asLong = 0;
866 }
864 }
867 // copy the part 1 of the snapshot in the extracted buffer
865 // copy the part 1 of the snapshot in the extracted buffer
868 for ( i = 0; i < (nbSamplesPart1_asLong * NB_WORDS_SWF_BLK); i++ )
866 for ( i = 0; i < (nbSamplesPart1_asLong * NB_WORDS_SWF_BLK); i++ )
869 {
867 {
870 swf_extracted[i] =
868 swf_extracted[i] =
871 ((int*) ring_node_to_send->buffer_address)[ i + (sampleOffset_asLong * NB_WORDS_SWF_BLK) ];
869 ((int*) ring_node_to_send->buffer_address)[ i + (sampleOffset_asLong * NB_WORDS_SWF_BLK) ];
872 }
870 }
873 // copy the part 2 of the snapshot in the extracted buffer
871 // copy the part 2 of the snapshot in the extracted buffer
874 ring_node_to_send = ring_node_to_send->next;
872 ring_node_to_send = ring_node_to_send->next;
875 for ( i = (nbSamplesPart1_asLong * NB_WORDS_SWF_BLK); i < (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK); i++ )
873 for ( i = (nbSamplesPart1_asLong * NB_WORDS_SWF_BLK); i < (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK); i++ )
876 {
874 {
877 swf_extracted[i] =
875 swf_extracted[i] =
878 ((int*) ring_node_to_send->buffer_address)[ (i-(nbSamplesPart1_asLong * NB_WORDS_SWF_BLK)) ];
876 ((int*) ring_node_to_send->buffer_address)[ (i-(nbSamplesPart1_asLong * NB_WORDS_SWF_BLK)) ];
879 }
877 }
880 }
878 }
881
879
882 double computeCorrection( unsigned char *timePtr )
880 double computeCorrection( unsigned char *timePtr )
883 {
881 {
884 unsigned long long int acquisitionTime;
882 unsigned long long int acquisitionTime;
885 unsigned long long int centerTime;
883 unsigned long long int centerTime;
886 unsigned long long int previousTick;
884 unsigned long long int previousTick;
887 unsigned long long int nextTick;
885 unsigned long long int nextTick;
888 unsigned long long int deltaPreviousTick;
886 unsigned long long int deltaPreviousTick;
889 unsigned long long int deltaNextTick;
887 unsigned long long int deltaNextTick;
890 double deltaPrevious_ms;
888 double deltaPrevious_ms;
891 double deltaNext_ms;
889 double deltaNext_ms;
892 double correctionInF2;
890 double correctionInF2;
893
891
894 // get acquisition time in fine time ticks
892 // get acquisition time in fine time ticks
895 acquisitionTime = get_acquisition_time( timePtr );
893 acquisitionTime = get_acquisition_time( timePtr );
896
894
897 // compute center time
895 // compute center time
898 centerTime = acquisitionTime + 2731; // (2048. / 24576. / 2.) * 65536. = 2730.667;
896 centerTime = acquisitionTime + DELTAT_F0; // (2048. / 24576. / 2.) * 65536. = 2730.667;
899 previousTick = centerTime - (centerTime & 0xffff);
897 previousTick = centerTime - (centerTime & INT16_ALL_F);
900 nextTick = previousTick + 65536;
898 nextTick = previousTick + TICKS_PER_S;
901
899
902 deltaPreviousTick = centerTime - previousTick;
900 deltaPreviousTick = centerTime - previousTick;
903 deltaNextTick = nextTick - centerTime;
901 deltaNextTick = nextTick - centerTime;
904
902
905 deltaPrevious_ms = ((double) deltaPreviousTick) / 65536. * 1000.;
903 deltaPrevious_ms = (((double) deltaPreviousTick) / TICKS_PER_S) * MS_PER_S;
906 deltaNext_ms = ((double) deltaNextTick) / 65536. * 1000.;
904 deltaNext_ms = (((double) deltaNextTick) / TICKS_PER_S) * MS_PER_S;
907
905
908 PRINTF2(" delta previous = %.3f ms, delta next = %.2f ms\n", deltaPrevious_ms, deltaNext_ms);
906 PRINTF2(" delta previous = %.3f ms, delta next = %.2f ms\n", deltaPrevious_ms, deltaNext_ms);
909
907
910 // which tick is the closest?
908 // which tick is the closest?
911 if (deltaPreviousTick > deltaNextTick)
909 if (deltaPreviousTick > deltaNextTick)
912 {
910 {
913 // the snapshot center is just before the second => increase delta_snapshot
911 // the snapshot center is just before the second => increase delta_snapshot
914 correctionInF2 = + (deltaNext_ms * 256. / 1000. );
912 correctionInF2 = + (deltaNext_ms * FREQ_F2 / MS_PER_S );
915 }
913 }
916 else
914 else
917 {
915 {
918 // the snapshot center is just after the second => decrease delta_snapshot
916 // the snapshot center is just after the second => decrease delta_snapshot
919 correctionInF2 = - (deltaPrevious_ms * 256. / 1000. );
917 correctionInF2 = - (deltaPrevious_ms * FREQ_F2 / MS_PER_S );
920 }
918 }
921
919
922 PRINTF1(" correctionInF2 = %.2f\n", correctionInF2);
920 PRINTF1(" correctionInF2 = %.2f\n", correctionInF2);
923
921
924 return correctionInF2;
922 return correctionInF2;
925 }
923 }
926
924
927 void applyCorrection( double correction )
925 void applyCorrection( double correction )
928 {
926 {
929 int correctionInt;
927 int correctionInt;
930
928
931 if (correction >= 0.)
929 if (correction >= 0.)
932 {
930 {
933 if ( (1. > correction) && (correction > 0.5) )
931 if ( (ONE_TICK_CORR_INTERVAL_0_MIN < correction) && (correction < ONE_TICK_CORR_INTERVAL_0_MAX) )
934 {
932 {
935 correctionInt = 1;
933 correctionInt = ONE_TICK_CORR;
936 }
934 }
937 else
935 else
938 {
936 {
939 correctionInt = 2 * floor(correction);
937 correctionInt = CORR_MULT * floor(correction);
940 }
938 }
941 }
939 }
942 else
940 else
943 {
941 {
944 if ( (-1. < correction) && (correction < -0.5) )
942 if ( (ONE_TICK_CORR_INTERVAL_1_MIN < correction) && (correction < ONE_TICK_CORR_INTERVAL_1_MAX) )
945 {
943 {
946 correctionInt = -1;
944 correctionInt = -ONE_TICK_CORR;
947 }
945 }
948 else
946 else
949 {
947 {
950 correctionInt = 2 * ceil(correction);
948 correctionInt = CORR_MULT * ceil(correction);
951 }
949 }
952 }
950 }
953 waveform_picker_regs->delta_snapshot = waveform_picker_regs->delta_snapshot + correctionInt;
951 waveform_picker_regs->delta_snapshot = waveform_picker_regs->delta_snapshot + correctionInt;
954 }
952 }
955
953
956 void snapshot_resynchronization( unsigned char *timePtr )
954 void snapshot_resynchronization( unsigned char *timePtr )
957 {
955 {
958 /** This function compute a correction to apply on delta_snapshot.
956 /** This function compute a correction to apply on delta_snapshot.
959 *
957 *
960 *
958 *
961 * @param timePtr is a pointer to the acquisition time of the snapshot being considered.
959 * @param timePtr is a pointer to the acquisition time of the snapshot being considered.
962 *
960 *
963 * @return void
961 * @return void
964 *
962 *
965 */
963 */
966
964
967 static double correction = 0.;
965 static double correction = INIT_FLOAT;
968 static resynchro_state state = MEASURE;
966 static resynchro_state state = MEASURE;
969 static unsigned int nbSnapshots = 0;
967 static unsigned int nbSnapshots = 0;
970
968
971 int correctionInt;
969 int correctionInt;
972
970
973 correctionInt = 0;
971 correctionInt = 0;
974
972
975 switch (state)
973 switch (state)
976 {
974 {
977
975
978 case MEASURE:
976 case MEASURE:
979 // ********
977 // ********
980 PRINTF1("MEASURE === %d\n", nbSnapshots);
978 PRINTF1("MEASURE === %d\n", nbSnapshots);
981 state = CORRECTION;
979 state = CORRECTION;
982 correction = computeCorrection( timePtr );
980 correction = computeCorrection( timePtr );
983 PRINTF1("MEASURE === correction = %.2f\n", correction );
981 PRINTF1("MEASURE === correction = %.2f\n", correction );
984 applyCorrection( correction );
982 applyCorrection( correction );
985 PRINTF1("MEASURE === delta_snapshot = %d\n", waveform_picker_regs->delta_snapshot);
983 PRINTF1("MEASURE === delta_snapshot = %d\n", waveform_picker_regs->delta_snapshot);
986 //****
984 //****
987 break;
985 break;
988
986
989 case CORRECTION:
987 case CORRECTION:
990 //************
988 //************
991 PRINTF1("CORRECTION === %d\n", nbSnapshots);
989 PRINTF1("CORRECTION === %d\n", nbSnapshots);
992 state = MEASURE;
990 state = MEASURE;
993 computeCorrection( timePtr );
991 computeCorrection( timePtr );
994 set_wfp_delta_snapshot();
992 set_wfp_delta_snapshot();
995 PRINTF1("CORRECTION === delta_snapshot = %d\n", waveform_picker_regs->delta_snapshot);
993 PRINTF1("CORRECTION === delta_snapshot = %d\n", waveform_picker_regs->delta_snapshot);
996 //****
994 //****
997 break;
995 break;
998
996
999 default:
997 default:
1000 break;
998 break;
1001
999
1002 }
1000 }
1003
1001
1004 nbSnapshots++;
1002 nbSnapshots++;
1005 }
1003 }
1006
1004
1007 //**************
1005 //**************
1008 // wfp registers
1006 // wfp registers
1009 void reset_wfp_burst_enable( void )
1007 void reset_wfp_burst_enable( void )
1010 {
1008 {
1011 /** This function resets the waveform picker burst_enable register.
1009 /** This function resets the waveform picker burst_enable register.
1012 *
1010 *
1013 * The burst bits [f2 f1 f0] and the enable bits [f3 f2 f1 f0] are set to 0.
1011 * The burst bits [f2 f1 f0] and the enable bits [f3 f2 f1 f0] are set to 0.
1014 *
1012 *
1015 */
1013 */
1016
1014
1017 // [1000 000] burst f2, f1, f0 enable f3, f2, f1, f0
1015 // [1000 000] burst f2, f1, f0 enable f3, f2, f1, f0
1018 waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable & 0x80;
1016 waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable & RST_BITS_RUN_BURST_EN;
1019 }
1017 }
1020
1018
1021 void reset_wfp_status( void )
1019 void reset_wfp_status( void )
1022 {
1020 {
1023 /** This function resets the waveform picker status register.
1021 /** This function resets the waveform picker status register.
1024 *
1022 *
1025 * All status bits are set to 0 [new_err full_err full].
1023 * All status bits are set to 0 [new_err full_err full].
1026 *
1024 *
1027 */
1025 */
1028
1026
1029 waveform_picker_regs->status = 0xffff;
1027 waveform_picker_regs->status = INT16_ALL_F;
1030 }
1028 }
1031
1029
1032 void reset_wfp_buffer_addresses( void )
1030 void reset_wfp_buffer_addresses( void )
1033 {
1031 {
1034 // F0
1032 // F0
1035 waveform_picker_regs->addr_data_f0_0 = current_ring_node_f0->previous->buffer_address; // 0x08
1033 waveform_picker_regs->addr_data_f0_0 = current_ring_node_f0->previous->buffer_address; // 0x08
1036 waveform_picker_regs->addr_data_f0_1 = current_ring_node_f0->buffer_address; // 0x0c
1034 waveform_picker_regs->addr_data_f0_1 = current_ring_node_f0->buffer_address; // 0x0c
1037 // F1
1035 // F1
1038 waveform_picker_regs->addr_data_f1_0 = current_ring_node_f1->previous->buffer_address; // 0x10
1036 waveform_picker_regs->addr_data_f1_0 = current_ring_node_f1->previous->buffer_address; // 0x10
1039 waveform_picker_regs->addr_data_f1_1 = current_ring_node_f1->buffer_address; // 0x14
1037 waveform_picker_regs->addr_data_f1_1 = current_ring_node_f1->buffer_address; // 0x14
1040 // F2
1038 // F2
1041 waveform_picker_regs->addr_data_f2_0 = current_ring_node_f2->previous->buffer_address; // 0x18
1039 waveform_picker_regs->addr_data_f2_0 = current_ring_node_f2->previous->buffer_address; // 0x18
1042 waveform_picker_regs->addr_data_f2_1 = current_ring_node_f2->buffer_address; // 0x1c
1040 waveform_picker_regs->addr_data_f2_1 = current_ring_node_f2->buffer_address; // 0x1c
1043 // F3
1041 // F3
1044 waveform_picker_regs->addr_data_f3_0 = current_ring_node_f3->previous->buffer_address; // 0x20
1042 waveform_picker_regs->addr_data_f3_0 = current_ring_node_f3->previous->buffer_address; // 0x20
1045 waveform_picker_regs->addr_data_f3_1 = current_ring_node_f3->buffer_address; // 0x24
1043 waveform_picker_regs->addr_data_f3_1 = current_ring_node_f3->buffer_address; // 0x24
1046 }
1044 }
1047
1045
1048 void reset_waveform_picker_regs( void )
1046 void reset_waveform_picker_regs( void )
1049 {
1047 {
1050 /** This function resets the waveform picker module registers.
1048 /** This function resets the waveform picker module registers.
1051 *
1049 *
1052 * The registers affected by this function are located at the following offset addresses:
1050 * The registers affected by this function are located at the following offset addresses:
1053 * - 0x00 data_shaping
1051 * - 0x00 data_shaping
1054 * - 0x04 run_burst_enable
1052 * - 0x04 run_burst_enable
1055 * - 0x08 addr_data_f0
1053 * - 0x08 addr_data_f0
1056 * - 0x0C addr_data_f1
1054 * - 0x0C addr_data_f1
1057 * - 0x10 addr_data_f2
1055 * - 0x10 addr_data_f2
1058 * - 0x14 addr_data_f3
1056 * - 0x14 addr_data_f3
1059 * - 0x18 status
1057 * - 0x18 status
1060 * - 0x1C delta_snapshot
1058 * - 0x1C delta_snapshot
1061 * - 0x20 delta_f0
1059 * - 0x20 delta_f0
1062 * - 0x24 delta_f0_2
1060 * - 0x24 delta_f0_2
1063 * - 0x28 delta_f1 (obsolet parameter)
1061 * - 0x28 delta_f1 (obsolet parameter)
1064 * - 0x2c delta_f2
1062 * - 0x2c delta_f2
1065 * - 0x30 nb_data_by_buffer
1063 * - 0x30 nb_data_by_buffer
1066 * - 0x34 nb_snapshot_param
1064 * - 0x34 nb_snapshot_param
1067 * - 0x38 start_date
1065 * - 0x38 start_date
1068 * - 0x3c nb_word_in_buffer
1066 * - 0x3c nb_word_in_buffer
1069 *
1067 *
1070 */
1068 */
1071
1069
1072 set_wfp_data_shaping(); // 0x00 *** R1 R0 SP1 SP0 BW
1070 set_wfp_data_shaping(); // 0x00 *** R1 R0 SP1 SP0 BW
1073
1071
1074 reset_wfp_burst_enable(); // 0x04 *** [run *** burst f2, f1, f0 *** enable f3, f2, f1, f0 ]
1072 reset_wfp_burst_enable(); // 0x04 *** [run *** burst f2, f1, f0 *** enable f3, f2, f1, f0 ]
1075
1073
1076 reset_wfp_buffer_addresses();
1074 reset_wfp_buffer_addresses();
1077
1075
1078 reset_wfp_status(); // 0x18
1076 reset_wfp_status(); // 0x18
1079
1077
1080 set_wfp_delta_snapshot(); // 0x1c *** 300 s => 0x12bff
1078 set_wfp_delta_snapshot(); // 0x1c *** 300 s => 0x12bff
1081
1079
1082 set_wfp_delta_f0_f0_2(); // 0x20, 0x24
1080 set_wfp_delta_f0_f0_2(); // 0x20, 0x24
1083
1081
1084 //the parameter delta_f1 [0x28] is not used anymore
1082 //the parameter delta_f1 [0x28] is not used anymore
1085
1083
1086 set_wfp_delta_f2(); // 0x2c
1084 set_wfp_delta_f2(); // 0x2c
1087
1085
1088 DEBUG_PRINTF1("delta_snapshot %x\n", waveform_picker_regs->delta_snapshot);
1086 DEBUG_PRINTF1("delta_snapshot %x\n", waveform_picker_regs->delta_snapshot);
1089 DEBUG_PRINTF1("delta_f0 %x\n", waveform_picker_regs->delta_f0);
1087 DEBUG_PRINTF1("delta_f0 %x\n", waveform_picker_regs->delta_f0);
1090 DEBUG_PRINTF1("delta_f0_2 %x\n", waveform_picker_regs->delta_f0_2);
1088 DEBUG_PRINTF1("delta_f0_2 %x\n", waveform_picker_regs->delta_f0_2);
1091 DEBUG_PRINTF1("delta_f1 %x\n", waveform_picker_regs->delta_f1);
1089 DEBUG_PRINTF1("delta_f1 %x\n", waveform_picker_regs->delta_f1);
1092 DEBUG_PRINTF1("delta_f2 %x\n", waveform_picker_regs->delta_f2);
1090 DEBUG_PRINTF1("delta_f2 %x\n", waveform_picker_regs->delta_f2);
1093 // 2688 = 8 * 336
1091 // 2688 = 8 * 336
1094 waveform_picker_regs->nb_data_by_buffer = 0xa7f; // 0x30 *** 2688 - 1 => nb samples -1
1092 waveform_picker_regs->nb_data_by_buffer = DFLT_WFP_NB_DATA_BY_BUFFER; // 0x30 *** 2688 - 1 => nb samples -1
1095 waveform_picker_regs->snapshot_param = 0xa80; // 0x34 *** 2688 => nb samples
1093 waveform_picker_regs->snapshot_param = DFLT_WFP_SNAPSHOT_PARAM; // 0x34 *** 2688 => nb samples
1096 waveform_picker_regs->start_date = 0x7fffffff; // 0x38
1094 waveform_picker_regs->start_date = COARSE_TIME_MASK;
1097 //
1095 //
1098 // coarse time and fine time registers are not initialized, they are volatile
1096 // coarse time and fine time registers are not initialized, they are volatile
1099 //
1097 //
1100 waveform_picker_regs->buffer_length = 0x1f8;// buffer length in burst = 3 * 2688 / 16 = 504 = 0x1f8
1098 waveform_picker_regs->buffer_length = DFLT_WFP_BUFFER_LENGTH; // buffer length in burst = 3 * 2688 / 16 = 504 = 0x1f8
1101 }
1099 }
1102
1100
1103 void set_wfp_data_shaping( void )
1101 void set_wfp_data_shaping( void )
1104 {
1102 {
1105 /** This function sets the data_shaping register of the waveform picker module.
1103 /** This function sets the data_shaping register of the waveform picker module.
1106 *
1104 *
1107 * The value is read from one field of the parameter_dump_packet structure:\n
1105 * The value is read from one field of the parameter_dump_packet structure:\n
1108 * bw_sp0_sp1_r0_r1
1106 * bw_sp0_sp1_r0_r1
1109 *
1107 *
1110 */
1108 */
1111
1109
1112 unsigned char data_shaping;
1110 unsigned char data_shaping;
1113
1111
1114 // get the parameters for the data shaping [BW SP0 SP1 R0 R1] in sy_lfr_common1 and configure the register
1112 // get the parameters for the data shaping [BW SP0 SP1 R0 R1] in sy_lfr_common1 and configure the register
1115 // waveform picker : [R1 R0 SP1 SP0 BW]
1113 // waveform picker : [R1 R0 SP1 SP0 BW]
1116
1114
1117 data_shaping = parameter_dump_packet.sy_lfr_common_parameters;
1115 data_shaping = parameter_dump_packet.sy_lfr_common_parameters;
1118
1116
1119 waveform_picker_regs->data_shaping =
1117 waveform_picker_regs->data_shaping =
1120 ( (data_shaping & 0x20) >> 5 ) // BW
1118 ( (data_shaping & BIT_5) >> SHIFT_5_BITS ) // BW
1121 + ( (data_shaping & 0x10) >> 3 ) // SP0
1119 + ( (data_shaping & BIT_4) >> SHIFT_3_BITS ) // SP0
1122 + ( (data_shaping & 0x08) >> 1 ) // SP1
1120 + ( (data_shaping & BIT_3) >> 1 ) // SP1
1123 + ( (data_shaping & 0x04) << 1 ) // R0
1121 + ( (data_shaping & BIT_2) << 1 ) // R0
1124 + ( (data_shaping & 0x02) << 3 ) // R1
1122 + ( (data_shaping & BIT_1) << SHIFT_3_BITS ) // R1
1125 + ( (data_shaping & 0x01) << 5 ); // R2
1123 + ( (data_shaping & BIT_0) << SHIFT_5_BITS ); // R2
1126 }
1124 }
1127
1125
1128 void set_wfp_burst_enable_register( unsigned char mode )
1126 void set_wfp_burst_enable_register( unsigned char mode )
1129 {
1127 {
1130 /** This function sets the waveform picker burst_enable register depending on the mode.
1128 /** This function sets the waveform picker burst_enable register depending on the mode.
1131 *
1129 *
1132 * @param mode is the LFR mode to launch.
1130 * @param mode is the LFR mode to launch.
1133 *
1131 *
1134 * The burst bits shall be before the enable bits.
1132 * The burst bits shall be before the enable bits.
1135 *
1133 *
1136 */
1134 */
1137
1135
1138 // [0000 0000] burst f2, f1, f0 enable f3 f2 f1 f0
1136 // [0000 0000] burst f2, f1, f0 enable f3 f2 f1 f0
1139 // the burst bits shall be set first, before the enable bits
1137 // the burst bits shall be set first, before the enable bits
1140 switch(mode) {
1138 switch(mode) {
1141 case LFR_MODE_NORMAL:
1139 case LFR_MODE_NORMAL:
1142 case LFR_MODE_SBM1:
1140 case LFR_MODE_SBM1:
1143 case LFR_MODE_SBM2:
1141 case LFR_MODE_SBM2:
1144 waveform_picker_regs->run_burst_enable = 0x60; // [0110 0000] enable f2 and f1 burst
1142 waveform_picker_regs->run_burst_enable = RUN_BURST_ENABLE_SBM2; // [0110 0000] enable f2 and f1 burst
1145 waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | 0x0f; // [1111] enable f3 f2 f1 f0
1143 waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | 0x0f; // [1111] enable f3 f2 f1 f0
1146 break;
1144 break;
1147 case LFR_MODE_BURST:
1145 case LFR_MODE_BURST:
1148 waveform_picker_regs->run_burst_enable = 0x40; // [0100 0000] f2 burst enabled
1146 waveform_picker_regs->run_burst_enable = RUN_BURST_ENABLE_BURST; // [0100 0000] f2 burst enabled
1149 waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | 0x0c; // [1100] enable f3 and f2
1147 waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | 0x0c; // [1100] enable f3 and f2
1150 break;
1148 break;
1151 default:
1149 default:
1152 waveform_picker_regs->run_burst_enable = 0x00; // [0000 0000] no burst enabled, no waveform enabled
1150 waveform_picker_regs->run_burst_enable = INIT_CHAR; // [0000 0000] no burst enabled, no waveform enabled
1153 break;
1151 break;
1154 }
1152 }
1155 }
1153 }
1156
1154
1157 void set_wfp_delta_snapshot( void )
1155 void set_wfp_delta_snapshot( void )
1158 {
1156 {
1159 /** This function sets the delta_snapshot register of the waveform picker module.
1157 /** This function sets the delta_snapshot register of the waveform picker module.
1160 *
1158 *
1161 * The value is read from two (unsigned char) of the parameter_dump_packet structure:
1159 * The value is read from two (unsigned char) of the parameter_dump_packet structure:
1162 * - sy_lfr_n_swf_p[0]
1160 * - sy_lfr_n_swf_p[0]
1163 * - sy_lfr_n_swf_p[1]
1161 * - sy_lfr_n_swf_p[1]
1164 *
1162 *
1165 */
1163 */
1166
1164
1167 unsigned int delta_snapshot;
1165 unsigned int delta_snapshot;
1168 unsigned int delta_snapshot_in_T2;
1166 unsigned int delta_snapshot_in_T2;
1169
1167
1170 delta_snapshot = parameter_dump_packet.sy_lfr_n_swf_p[0]*256
1168 delta_snapshot = (parameter_dump_packet.sy_lfr_n_swf_p[0] * CONST_256)
1171 + parameter_dump_packet.sy_lfr_n_swf_p[1];
1169 + parameter_dump_packet.sy_lfr_n_swf_p[1];
1172
1170
1173 delta_snapshot_in_T2 = delta_snapshot * 256;
1171 delta_snapshot_in_T2 = delta_snapshot * FREQ_F2;
1174 waveform_picker_regs->delta_snapshot = delta_snapshot_in_T2 - 1; // max 4 bytes
1172 waveform_picker_regs->delta_snapshot = delta_snapshot_in_T2 - 1; // max 4 bytes
1175 }
1173 }
1176
1174
1177 void set_wfp_delta_f0_f0_2( void )
1175 void set_wfp_delta_f0_f0_2( void )
1178 {
1176 {
1179 unsigned int delta_snapshot;
1177 unsigned int delta_snapshot;
1180 unsigned int nb_samples_per_snapshot;
1178 unsigned int nb_samples_per_snapshot;
1181 float delta_f0_in_float;
1179 float delta_f0_in_float;
1182
1180
1183 delta_snapshot = waveform_picker_regs->delta_snapshot;
1181 delta_snapshot = waveform_picker_regs->delta_snapshot;
1184 nb_samples_per_snapshot = parameter_dump_packet.sy_lfr_n_swf_l[0] * 256 + parameter_dump_packet.sy_lfr_n_swf_l[1];
1182 nb_samples_per_snapshot = (parameter_dump_packet.sy_lfr_n_swf_l[0] * CONST_256) + parameter_dump_packet.sy_lfr_n_swf_l[1];
1185 delta_f0_in_float = nb_samples_per_snapshot / 2. * ( 1. / 256. - 1. / 24576.) * 256.;
1183 delta_f0_in_float = (nb_samples_per_snapshot / 2.) * ( (1. / FREQ_F2) - (1. / FREQ_F0) ) * FREQ_F2;
1186
1184
1187 waveform_picker_regs->delta_f0 = delta_snapshot - floor( delta_f0_in_float );
1185 waveform_picker_regs->delta_f0 = delta_snapshot - floor( delta_f0_in_float );
1188 waveform_picker_regs->delta_f0_2 = 0x30; // 48 = 11 0000, max 7 bits
1186 waveform_picker_regs->delta_f0_2 = DFLT_WFP_DELTA_F0_2; // 48 = 11 0000, max 7 bits
1189 }
1187 }
1190
1188
1191 void set_wfp_delta_f1( void )
1189 void set_wfp_delta_f1( void )
1192 {
1190 {
1193 /** Sets the value of the delta_f1 parameter
1191 /** Sets the value of the delta_f1 parameter
1194 *
1192 *
1195 * @param void
1193 * @param void
1196 *
1194 *
1197 * @return void
1195 * @return void
1198 *
1196 *
1199 * delta_f1 is not used, the snapshots are extracted from CWF_F1 waveforms.
1197 * delta_f1 is not used, the snapshots are extracted from CWF_F1 waveforms.
1200 *
1198 *
1201 */
1199 */
1202
1200
1203 unsigned int delta_snapshot;
1201 unsigned int delta_snapshot;
1204 unsigned int nb_samples_per_snapshot;
1202 unsigned int nb_samples_per_snapshot;
1205 float delta_f1_in_float;
1203 float delta_f1_in_float;
1206
1204
1207 delta_snapshot = waveform_picker_regs->delta_snapshot;
1205 delta_snapshot = waveform_picker_regs->delta_snapshot;
1208 nb_samples_per_snapshot = parameter_dump_packet.sy_lfr_n_swf_l[0] * 256 + parameter_dump_packet.sy_lfr_n_swf_l[1];
1206 nb_samples_per_snapshot = (parameter_dump_packet.sy_lfr_n_swf_l[0] * CONST_256) + parameter_dump_packet.sy_lfr_n_swf_l[1];
1209 delta_f1_in_float = nb_samples_per_snapshot / 2. * ( 1. / 256. - 1. / 4096.) * 256.;
1207 delta_f1_in_float = (nb_samples_per_snapshot / 2.) * ( (1. / FREQ_F2) - (1. / FREQ_F1) ) * FREQ_F2;
1210
1208
1211 waveform_picker_regs->delta_f1 = delta_snapshot - floor( delta_f1_in_float );
1209 waveform_picker_regs->delta_f1 = delta_snapshot - floor( delta_f1_in_float );
1212 }
1210 }
1213
1211
1214 void set_wfp_delta_f2( void ) // parameter not used, only delta_f0 and delta_f0_2 are used
1212 void set_wfp_delta_f2( void ) // parameter not used, only delta_f0 and delta_f0_2 are used
1215 {
1213 {
1216 /** Sets the value of the delta_f2 parameter
1214 /** Sets the value of the delta_f2 parameter
1217 *
1215 *
1218 * @param void
1216 * @param void
1219 *
1217 *
1220 * @return void
1218 * @return void
1221 *
1219 *
1222 * delta_f2 is used only for the first snapshot generation, even when the snapshots are extracted from CWF_F2
1220 * delta_f2 is used only for the first snapshot generation, even when the snapshots are extracted from CWF_F2
1223 * waveforms (see lpp_waveform_snapshot_controler.vhd for details).
1221 * waveforms (see lpp_waveform_snapshot_controler.vhd for details).
1224 *
1222 *
1225 */
1223 */
1226
1224
1227 unsigned int delta_snapshot;
1225 unsigned int delta_snapshot;
1228 unsigned int nb_samples_per_snapshot;
1226 unsigned int nb_samples_per_snapshot;
1229
1227
1230 delta_snapshot = waveform_picker_regs->delta_snapshot;
1228 delta_snapshot = waveform_picker_regs->delta_snapshot;
1231 nb_samples_per_snapshot = parameter_dump_packet.sy_lfr_n_swf_l[0] * 256 + parameter_dump_packet.sy_lfr_n_swf_l[1];
1229 nb_samples_per_snapshot = (parameter_dump_packet.sy_lfr_n_swf_l[0] * CONST_256) + parameter_dump_packet.sy_lfr_n_swf_l[1];
1232
1230
1233 waveform_picker_regs->delta_f2 = delta_snapshot - nb_samples_per_snapshot / 2 - 1;
1231 waveform_picker_regs->delta_f2 = delta_snapshot - (nb_samples_per_snapshot / 2) - 1;
1234 }
1232 }
1235
1233
1236 //*****************
1234 //*****************
1237 // local parameters
1235 // local parameters
1238
1236
1239 void increment_seq_counter_source_id( unsigned char *packet_sequence_control, unsigned int sid )
1237 void increment_seq_counter_source_id( unsigned char *packet_sequence_control, unsigned int sid )
1240 {
1238 {
1241 /** This function increments the parameter "sequence_cnt" depending on the sid passed in argument.
1239 /** This function increments the parameter "sequence_cnt" depending on the sid passed in argument.
1242 *
1240 *
1243 * @param packet_sequence_control is a pointer toward the parameter sequence_cnt to update.
1241 * @param packet_sequence_control is a pointer toward the parameter sequence_cnt to update.
1244 * @param sid is the source identifier of the packet being updated.
1242 * @param sid is the source identifier of the packet being updated.
1245 *
1243 *
1246 * REQ-LFR-SRS-5240 / SSS-CP-FS-590
1244 * REQ-LFR-SRS-5240 / SSS-CP-FS-590
1247 * The sequence counters shall wrap around from 2^14 to zero.
1245 * The sequence counters shall wrap around from 2^14 to zero.
1248 * The sequence counter shall start at zero at startup.
1246 * The sequence counter shall start at zero at startup.
1249 *
1247 *
1250 * REQ-LFR-SRS-5239 / SSS-CP-FS-580
1248 * REQ-LFR-SRS-5239 / SSS-CP-FS-580
1251 * All TM_LFR_SCIENCE_ packets are sent to ground, i.e. destination id = 0
1249 * All TM_LFR_SCIENCE_ packets are sent to ground, i.e. destination id = 0
1252 *
1250 *
1253 */
1251 */
1254
1252
1255 unsigned short *sequence_cnt;
1253 unsigned short *sequence_cnt;
1256 unsigned short segmentation_grouping_flag;
1254 unsigned short segmentation_grouping_flag;
1257 unsigned short new_packet_sequence_control;
1255 unsigned short new_packet_sequence_control;
1258 rtems_mode initial_mode_set;
1256 rtems_mode initial_mode_set;
1259 rtems_mode current_mode_set;
1257 rtems_mode current_mode_set;
1260 rtems_status_code status;
1258 rtems_status_code status;
1261
1259
1262 //******************************************
1260 //******************************************
1263 // CHANGE THE MODE OF THE CALLING RTEMS TASK
1261 // CHANGE THE MODE OF THE CALLING RTEMS TASK
1264 status = rtems_task_mode( RTEMS_NO_PREEMPT, RTEMS_PREEMPT_MASK, &initial_mode_set );
1262 status = rtems_task_mode( RTEMS_NO_PREEMPT, RTEMS_PREEMPT_MASK, &initial_mode_set );
1265
1263
1266 if ( (sid == SID_NORM_SWF_F0) || (sid == SID_NORM_SWF_F1) || (sid == SID_NORM_SWF_F2)
1264 if ( (sid == SID_NORM_SWF_F0) || (sid == SID_NORM_SWF_F1) || (sid == SID_NORM_SWF_F2)
1267 || (sid == SID_NORM_CWF_F3) || (sid == SID_NORM_CWF_LONG_F3)
1265 || (sid == SID_NORM_CWF_F3) || (sid == SID_NORM_CWF_LONG_F3)
1268 || (sid == SID_BURST_CWF_F2)
1266 || (sid == SID_BURST_CWF_F2)
1269 || (sid == SID_NORM_ASM_F0) || (sid == SID_NORM_ASM_F1) || (sid == SID_NORM_ASM_F2)
1267 || (sid == SID_NORM_ASM_F0) || (sid == SID_NORM_ASM_F1) || (sid == SID_NORM_ASM_F2)
1270 || (sid == SID_NORM_BP1_F0) || (sid == SID_NORM_BP1_F1) || (sid == SID_NORM_BP1_F2)
1268 || (sid == SID_NORM_BP1_F0) || (sid == SID_NORM_BP1_F1) || (sid == SID_NORM_BP1_F2)
1271 || (sid == SID_NORM_BP2_F0) || (sid == SID_NORM_BP2_F1) || (sid == SID_NORM_BP2_F2)
1269 || (sid == SID_NORM_BP2_F0) || (sid == SID_NORM_BP2_F1) || (sid == SID_NORM_BP2_F2)
1272 || (sid == SID_BURST_BP1_F0) || (sid == SID_BURST_BP2_F0)
1270 || (sid == SID_BURST_BP1_F0) || (sid == SID_BURST_BP2_F0)
1273 || (sid == SID_BURST_BP1_F1) || (sid == SID_BURST_BP2_F1) )
1271 || (sid == SID_BURST_BP1_F1) || (sid == SID_BURST_BP2_F1) )
1274 {
1272 {
1275 sequence_cnt = (unsigned short *) &sequenceCounters_SCIENCE_NORMAL_BURST;
1273 sequence_cnt = (unsigned short *) &sequenceCounters_SCIENCE_NORMAL_BURST;
1276 }
1274 }
1277 else if ( (sid ==SID_SBM1_CWF_F1) || (sid ==SID_SBM2_CWF_F2)
1275 else if ( (sid ==SID_SBM1_CWF_F1) || (sid ==SID_SBM2_CWF_F2)
1278 || (sid == SID_SBM1_BP1_F0) || (sid == SID_SBM1_BP2_F0)
1276 || (sid == SID_SBM1_BP1_F0) || (sid == SID_SBM1_BP2_F0)
1279 || (sid == SID_SBM2_BP1_F0) || (sid == SID_SBM2_BP2_F0)
1277 || (sid == SID_SBM2_BP1_F0) || (sid == SID_SBM2_BP2_F0)
1280 || (sid == SID_SBM2_BP1_F1) || (sid == SID_SBM2_BP2_F1) )
1278 || (sid == SID_SBM2_BP1_F1) || (sid == SID_SBM2_BP2_F1) )
1281 {
1279 {
1282 sequence_cnt = (unsigned short *) &sequenceCounters_SCIENCE_SBM1_SBM2;
1280 sequence_cnt = (unsigned short *) &sequenceCounters_SCIENCE_SBM1_SBM2;
1283 }
1281 }
1284 else
1282 else
1285 {
1283 {
1286 sequence_cnt = (unsigned short *) NULL;
1284 sequence_cnt = (unsigned short *) NULL;
1287 PRINTF1("in increment_seq_counter_source_id *** ERR apid_destid %d not known\n", sid)
1285 PRINTF1("in increment_seq_counter_source_id *** ERR apid_destid %d not known\n", sid)
1288 }
1286 }
1289
1287
1290 if (sequence_cnt != NULL)
1288 if (sequence_cnt != NULL)
1291 {
1289 {
1292 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << 8;
1290 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << SHIFT_1_BYTE;
1293 *sequence_cnt = (*sequence_cnt) & 0x3fff;
1291 *sequence_cnt = (*sequence_cnt) & SEQ_CNT_MASK;
1294
1292
1295 new_packet_sequence_control = segmentation_grouping_flag | (*sequence_cnt) ;
1293 new_packet_sequence_control = segmentation_grouping_flag | (*sequence_cnt) ;
1296
1294
1297 packet_sequence_control[0] = (unsigned char) (new_packet_sequence_control >> 8);
1295 packet_sequence_control[0] = (unsigned char) (new_packet_sequence_control >> SHIFT_1_BYTE);
1298 packet_sequence_control[1] = (unsigned char) (new_packet_sequence_control );
1296 packet_sequence_control[1] = (unsigned char) (new_packet_sequence_control );
1299
1297
1300 // increment the sequence counter
1298 // increment the sequence counter
1301 if ( *sequence_cnt < SEQ_CNT_MAX)
1299 if ( *sequence_cnt < SEQ_CNT_MAX)
1302 {
1300 {
1303 *sequence_cnt = *sequence_cnt + 1;
1301 *sequence_cnt = *sequence_cnt + 1;
1304 }
1302 }
1305 else
1303 else
1306 {
1304 {
1307 *sequence_cnt = 0;
1305 *sequence_cnt = 0;
1308 }
1306 }
1309 }
1307 }
1310
1308
1311 //*************************************
1309 //*************************************
1312 // RESTORE THE MODE OF THE CALLING TASK
1310 // RESTORE THE MODE OF THE CALLING TASK
1313 status = rtems_task_mode( initial_mode_set, RTEMS_PREEMPT_MASK, &current_mode_set );
1311 status = rtems_task_mode( initial_mode_set, RTEMS_PREEMPT_MASK, &current_mode_set );
1314 }
1312 }
General Comments 0
You need to be logged in to leave comments. Login now