@@ -1,107 +1,107 | |||||
1 | cmake_minimum_required (VERSION 2.6) |
|
1 | cmake_minimum_required (VERSION 2.6) | |
2 | project (fsw) |
|
2 | project (fsw) | |
3 |
|
3 | |||
4 | include(sparc-rtems) |
|
4 | include(sparc-rtems) | |
5 | include(cppcheck) |
|
5 | include(cppcheck) | |
6 |
|
6 | |||
7 | include_directories("../header" |
|
7 | include_directories("../header" | |
8 | "../header/lfr_common_headers" |
|
8 | "../header/lfr_common_headers" | |
9 | "../header/processing" |
|
9 | "../header/processing" | |
10 | "../LFR_basic-parameters" |
|
10 | "../LFR_basic-parameters" | |
11 | "../src") |
|
11 | "../src") | |
12 |
|
12 | |||
13 | set(SOURCES wf_handler.c |
|
13 | set(SOURCES wf_handler.c | |
14 | tc_handler.c |
|
14 | tc_handler.c | |
15 | fsw_misc.c |
|
15 | fsw_misc.c | |
16 | fsw_init.c |
|
16 | fsw_init.c | |
17 | fsw_globals.c |
|
17 | fsw_globals.c | |
18 | fsw_spacewire.c |
|
18 | fsw_spacewire.c | |
19 | tc_load_dump_parameters.c |
|
19 | tc_load_dump_parameters.c | |
20 | tm_lfr_tc_exe.c |
|
20 | tm_lfr_tc_exe.c | |
21 | tc_acceptance.c |
|
21 | tc_acceptance.c | |
22 | processing/fsw_processing.c |
|
22 | processing/fsw_processing.c | |
23 | processing/avf0_prc0.c |
|
23 | processing/avf0_prc0.c | |
24 | processing/avf1_prc1.c |
|
24 | processing/avf1_prc1.c | |
25 | processing/avf2_prc2.c |
|
25 | processing/avf2_prc2.c | |
26 | lfr_cpu_usage_report.c |
|
26 | lfr_cpu_usage_report.c | |
27 | ${LFR_BP_SRC} |
|
27 | ${LFR_BP_SRC} | |
28 | ../header/wf_handler.h |
|
28 | ../header/wf_handler.h | |
29 | ../header/tc_handler.h |
|
29 | ../header/tc_handler.h | |
30 | ../header/grlib_regs.h |
|
30 | ../header/grlib_regs.h | |
31 | ../header/fsw_misc.h |
|
31 | ../header/fsw_misc.h | |
32 | ../header/fsw_init.h |
|
32 | ../header/fsw_init.h | |
33 | ../header/fsw_spacewire.h |
|
33 | ../header/fsw_spacewire.h | |
34 | ../header/tc_load_dump_parameters.h |
|
34 | ../header/tc_load_dump_parameters.h | |
35 | ../header/tm_lfr_tc_exe.h |
|
35 | ../header/tm_lfr_tc_exe.h | |
36 | ../header/tc_acceptance.h |
|
36 | ../header/tc_acceptance.h | |
37 | ../header/processing/fsw_processing.h |
|
37 | ../header/processing/fsw_processing.h | |
38 | ../header/processing/avf0_prc0.h |
|
38 | ../header/processing/avf0_prc0.h | |
39 | ../header/processing/avf1_prc1.h |
|
39 | ../header/processing/avf1_prc1.h | |
40 | ../header/processing/avf2_prc2.h |
|
40 | ../header/processing/avf2_prc2.h | |
41 | ../header/fsw_params_wf_handler.h |
|
41 | ../header/fsw_params_wf_handler.h | |
42 | ../header/lfr_cpu_usage_report.h |
|
42 | ../header/lfr_cpu_usage_report.h | |
43 | ../header/lfr_common_headers/ccsds_types.h |
|
43 | ../header/lfr_common_headers/ccsds_types.h | |
44 | ../header/lfr_common_headers/fsw_params.h |
|
44 | ../header/lfr_common_headers/fsw_params.h | |
45 | ../header/lfr_common_headers/fsw_params_nb_bytes.h |
|
45 | ../header/lfr_common_headers/fsw_params_nb_bytes.h | |
46 | ../header/lfr_common_headers/fsw_params_processing.h |
|
46 | ../header/lfr_common_headers/fsw_params_processing.h | |
47 | ../header/lfr_common_headers/tm_byte_positions.h |
|
47 | ../header/lfr_common_headers/tm_byte_positions.h | |
48 | ../LFR_basic-parameters/basic_parameters.h |
|
48 | ../LFR_basic-parameters/basic_parameters.h | |
49 | ../LFR_basic-parameters/basic_parameters_params.h |
|
49 | ../LFR_basic-parameters/basic_parameters_params.h | |
50 | ../header/GscMemoryLPP.hpp |
|
50 | ../header/GscMemoryLPP.hpp | |
51 | ) |
|
51 | ) | |
52 |
|
52 | |||
53 |
|
53 | |||
54 | option(FSW_verbose "Enable verbose LFR" OFF) |
|
54 | option(FSW_verbose "Enable verbose LFR" OFF) | |
55 | option(FSW_boot_messages "Enable LFR boot messages" OFF) |
|
55 | option(FSW_boot_messages "Enable LFR boot messages" OFF) | |
56 | option(FSW_debug_messages "Enable LFR debug messages" OFF) |
|
56 | option(FSW_debug_messages "Enable LFR debug messages" OFF) | |
57 | option(FSW_cpu_usage_report "Enable LFR cpu usage report" OFF) |
|
57 | option(FSW_cpu_usage_report "Enable LFR cpu usage report" OFF) | |
58 | option(FSW_stack_report "Enable LFR stack report" OFF) |
|
58 | option(FSW_stack_report "Enable LFR stack report" OFF) | |
59 | option(FSW_vhdl_dev "?" OFF) |
|
59 | option(FSW_vhdl_dev "?" OFF) | |
60 | option(FSW_lpp_dpu_destid "Set to debug at LPP" ON) |
|
60 | option(FSW_lpp_dpu_destid "Set to debug at LPP" ON) | |
61 | option(FSW_debug_watchdog "Enable debug watchdog" OFF) |
|
61 | option(FSW_debug_watchdog "Enable debug watchdog" OFF) | |
62 | option(FSW_debug_tch "?" OFF) |
|
62 | option(FSW_debug_tch "?" OFF) | |
63 |
|
63 | |||
64 | set(SW_VERSION_N1 "3" CACHE STRING "Choose N1 FSW Version." FORCE) |
|
64 | set(SW_VERSION_N1 "3" CACHE STRING "Choose N1 FSW Version." FORCE) | |
65 | set(SW_VERSION_N2 "2" CACHE STRING "Choose N2 FSW Version." FORCE) |
|
65 | set(SW_VERSION_N2 "2" CACHE STRING "Choose N2 FSW Version." FORCE) | |
66 | set(SW_VERSION_N3 "0" CACHE STRING "Choose N3 FSW Version." FORCE) |
|
66 | set(SW_VERSION_N3 "0" CACHE STRING "Choose N3 FSW Version." FORCE) | |
67 |
set(SW_VERSION_N4 "1 |
|
67 | set(SW_VERSION_N4 "12" CACHE STRING "Choose N4 FSW Version." FORCE) | |
68 |
|
68 | |||
69 | if(FSW_verbose) |
|
69 | if(FSW_verbose) | |
70 | add_definitions(-DPRINT_MESSAGES_ON_CONSOLE) |
|
70 | add_definitions(-DPRINT_MESSAGES_ON_CONSOLE) | |
71 | endif() |
|
71 | endif() | |
72 | if(FSW_boot_messages) |
|
72 | if(FSW_boot_messages) | |
73 | add_definitions(-DBOOT_MESSAGES) |
|
73 | add_definitions(-DBOOT_MESSAGES) | |
74 | endif() |
|
74 | endif() | |
75 | if(FSW_debug_messages) |
|
75 | if(FSW_debug_messages) | |
76 | add_definitions(-DDEBUG_MESSAGES) |
|
76 | add_definitions(-DDEBUG_MESSAGES) | |
77 | endif() |
|
77 | endif() | |
78 | if(FSW_cpu_usage_report) |
|
78 | if(FSW_cpu_usage_report) | |
79 | add_definitions(-DPRINT_TASK_STATISTICS) |
|
79 | add_definitions(-DPRINT_TASK_STATISTICS) | |
80 | endif() |
|
80 | endif() | |
81 | if(FSW_stack_report) |
|
81 | if(FSW_stack_report) | |
82 | add_definitions(-DPRINT_STACK_REPORT) |
|
82 | add_definitions(-DPRINT_STACK_REPORT) | |
83 | endif() |
|
83 | endif() | |
84 | if(FSW_vhdl_dev) |
|
84 | if(FSW_vhdl_dev) | |
85 | add_definitions(-DVHDL_DEV) |
|
85 | add_definitions(-DVHDL_DEV) | |
86 | endif() |
|
86 | endif() | |
87 | if(FSW_lpp_dpu_destid) |
|
87 | if(FSW_lpp_dpu_destid) | |
88 | add_definitions(-DLPP_DPU_DESTID) |
|
88 | add_definitions(-DLPP_DPU_DESTID) | |
89 | endif() |
|
89 | endif() | |
90 | if(FSW_debug_watchdog) |
|
90 | if(FSW_debug_watchdog) | |
91 | add_definitions(-DDEBUG_WATCHDOG) |
|
91 | add_definitions(-DDEBUG_WATCHDOG) | |
92 | endif() |
|
92 | endif() | |
93 | if(FSW_debug_tch) |
|
93 | if(FSW_debug_tch) | |
94 | add_definitions(-DDEBUG_TCH) |
|
94 | add_definitions(-DDEBUG_TCH) | |
95 | endif() |
|
95 | endif() | |
96 |
|
96 | |||
97 | add_definitions(-DMSB_FIRST_TCH) |
|
97 | add_definitions(-DMSB_FIRST_TCH) | |
98 |
|
98 | |||
99 | add_definitions(-DSWVERSION=-1-0) |
|
99 | add_definitions(-DSWVERSION=-1-0) | |
100 | add_definitions(-DSW_VERSION_N1=${SW_VERSION_N1}) |
|
100 | add_definitions(-DSW_VERSION_N1=${SW_VERSION_N1}) | |
101 | add_definitions(-DSW_VERSION_N2=${SW_VERSION_N2}) |
|
101 | add_definitions(-DSW_VERSION_N2=${SW_VERSION_N2}) | |
102 | add_definitions(-DSW_VERSION_N3=${SW_VERSION_N3}) |
|
102 | add_definitions(-DSW_VERSION_N3=${SW_VERSION_N3}) | |
103 | add_definitions(-DSW_VERSION_N4=${SW_VERSION_N4}) |
|
103 | add_definitions(-DSW_VERSION_N4=${SW_VERSION_N4}) | |
104 |
|
104 | |||
105 | add_executable(fsw ${SOURCES}) |
|
105 | add_executable(fsw ${SOURCES}) | |
106 | add_test_cppcheck(fsw STYLE UNUSED_FUNCTIONS POSSIBLE_ERROR MISSING_INCLUDE) |
|
106 | add_test_cppcheck(fsw STYLE UNUSED_FUNCTIONS POSSIBLE_ERROR MISSING_INCLUDE) | |
107 |
|
107 |
@@ -1,1036 +1,1036 | |||||
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 | int16_t hk_lfr_sc_v_f3_as_int16 = 0; |
|
10 | int16_t hk_lfr_sc_v_f3_as_int16 = 0; | |
11 | int16_t hk_lfr_sc_e1_f3_as_int16 = 0; |
|
11 | int16_t hk_lfr_sc_e1_f3_as_int16 = 0; | |
12 | int16_t hk_lfr_sc_e2_f3_as_int16 = 0; |
|
12 | int16_t hk_lfr_sc_e2_f3_as_int16 = 0; | |
13 |
|
13 | |||
14 | void timer_configure(unsigned char timer, unsigned int clock_divider, |
|
14 | void timer_configure(unsigned char timer, unsigned int clock_divider, | |
15 | unsigned char interrupt_level, rtems_isr (*timer_isr)() ) |
|
15 | unsigned char interrupt_level, rtems_isr (*timer_isr)() ) | |
16 | { |
|
16 | { | |
17 | /** This function configures a GPTIMER timer instantiated in the VHDL design. |
|
17 | /** This function configures a GPTIMER timer instantiated in the VHDL design. | |
18 | * |
|
18 | * | |
19 | * @param gptimer_regs points to the APB registers of the GPTIMER IP core. |
|
19 | * @param gptimer_regs points to the APB registers of the GPTIMER IP core. | |
20 | * @param timer is the number of the timer in the IP core (several timers can be instantiated). |
|
20 | * @param timer is the number of the timer in the IP core (several timers can be instantiated). | |
21 | * @param clock_divider is the divider of the 1 MHz clock that will be configured. |
|
21 | * @param clock_divider is the divider of the 1 MHz clock that will be configured. | |
22 | * @param interrupt_level is the interrupt level that the timer drives. |
|
22 | * @param interrupt_level is the interrupt level that the timer drives. | |
23 | * @param timer_isr is the interrupt subroutine that will be attached to the IRQ driven by the timer. |
|
23 | * @param timer_isr is the interrupt subroutine that will be attached to the IRQ driven by the timer. | |
24 | * |
|
24 | * | |
25 | * Interrupt levels are described in the SPARC documentation sparcv8.pdf p.76 |
|
25 | * Interrupt levels are described in the SPARC documentation sparcv8.pdf p.76 | |
26 | * |
|
26 | * | |
27 | */ |
|
27 | */ | |
28 |
|
28 | |||
29 | rtems_status_code status; |
|
29 | rtems_status_code status; | |
30 | rtems_isr_entry old_isr_handler; |
|
30 | rtems_isr_entry old_isr_handler; | |
31 |
|
31 | |||
32 | old_isr_handler = NULL; |
|
32 | old_isr_handler = NULL; | |
33 |
|
33 | |||
34 | gptimer_regs->timer[timer].ctrl = INIT_CHAR; // reset the control register |
|
34 | gptimer_regs->timer[timer].ctrl = INIT_CHAR; // reset the control register | |
35 |
|
35 | |||
36 | status = rtems_interrupt_catch( timer_isr, interrupt_level, &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels |
|
36 | status = rtems_interrupt_catch( timer_isr, interrupt_level, &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels | |
37 | if (status!=RTEMS_SUCCESSFUL) |
|
37 | if (status!=RTEMS_SUCCESSFUL) | |
38 | { |
|
38 | { | |
39 | PRINTF("in configure_timer *** ERR rtems_interrupt_catch\n") |
|
39 | PRINTF("in configure_timer *** ERR rtems_interrupt_catch\n") | |
40 | } |
|
40 | } | |
41 |
|
41 | |||
42 | timer_set_clock_divider( timer, clock_divider); |
|
42 | timer_set_clock_divider( timer, clock_divider); | |
43 | } |
|
43 | } | |
44 |
|
44 | |||
45 | void timer_start(unsigned char timer) |
|
45 | void timer_start(unsigned char timer) | |
46 | { |
|
46 | { | |
47 | /** This function starts a GPTIMER timer. |
|
47 | /** This function starts a GPTIMER timer. | |
48 | * |
|
48 | * | |
49 | * @param gptimer_regs points to the APB registers of the GPTIMER IP core. |
|
49 | * @param gptimer_regs points to the APB registers of the GPTIMER IP core. | |
50 | * @param timer is the number of the timer in the IP core (several timers can be instantiated). |
|
50 | * @param timer is the number of the timer in the IP core (several timers can be instantiated). | |
51 | * |
|
51 | * | |
52 | */ |
|
52 | */ | |
53 |
|
53 | |||
54 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_CLEAR_IRQ; |
|
54 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_CLEAR_IRQ; | |
55 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_LD; |
|
55 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_LD; | |
56 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_EN; |
|
56 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_EN; | |
57 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_RS; |
|
57 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_RS; | |
58 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_IE; |
|
58 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_IE; | |
59 | } |
|
59 | } | |
60 |
|
60 | |||
61 | void timer_stop(unsigned char timer) |
|
61 | void timer_stop(unsigned char timer) | |
62 | { |
|
62 | { | |
63 | /** This function stops a GPTIMER timer. |
|
63 | /** This function stops a GPTIMER timer. | |
64 | * |
|
64 | * | |
65 | * @param gptimer_regs points to the APB registers of the GPTIMER IP core. |
|
65 | * @param gptimer_regs points to the APB registers of the GPTIMER IP core. | |
66 | * @param timer is the number of the timer in the IP core (several timers can be instantiated). |
|
66 | * @param timer is the number of the timer in the IP core (several timers can be instantiated). | |
67 | * |
|
67 | * | |
68 | */ |
|
68 | */ | |
69 |
|
69 | |||
70 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & GPTIMER_EN_MASK; |
|
70 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & GPTIMER_EN_MASK; | |
71 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & GPTIMER_IE_MASK; |
|
71 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & GPTIMER_IE_MASK; | |
72 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_CLEAR_IRQ; |
|
72 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_CLEAR_IRQ; | |
73 | } |
|
73 | } | |
74 |
|
74 | |||
75 | void timer_set_clock_divider(unsigned char timer, unsigned int clock_divider) |
|
75 | void timer_set_clock_divider(unsigned char timer, unsigned int clock_divider) | |
76 | { |
|
76 | { | |
77 | /** This function sets the clock divider of a GPTIMER timer. |
|
77 | /** This function sets the clock divider of a GPTIMER timer. | |
78 | * |
|
78 | * | |
79 | * @param gptimer_regs points to the APB registers of the GPTIMER IP core. |
|
79 | * @param gptimer_regs points to the APB registers of the GPTIMER IP core. | |
80 | * @param timer is the number of the timer in the IP core (several timers can be instantiated). |
|
80 | * @param timer is the number of the timer in the IP core (several timers can be instantiated). | |
81 | * @param clock_divider is the divider of the 1 MHz clock that will be configured. |
|
81 | * @param clock_divider is the divider of the 1 MHz clock that will be configured. | |
82 | * |
|
82 | * | |
83 | */ |
|
83 | */ | |
84 |
|
84 | |||
85 | gptimer_regs->timer[timer].reload = clock_divider; // base clock frequency is 1 MHz |
|
85 | gptimer_regs->timer[timer].reload = clock_divider; // base clock frequency is 1 MHz | |
86 | } |
|
86 | } | |
87 |
|
87 | |||
88 | // WATCHDOG |
|
88 | // WATCHDOG | |
89 |
|
89 | |||
90 | rtems_isr watchdog_isr( rtems_vector_number vector ) |
|
90 | rtems_isr watchdog_isr( rtems_vector_number vector ) | |
91 | { |
|
91 | { | |
92 | rtems_status_code status_code; |
|
92 | rtems_status_code status_code; | |
93 |
|
93 | |||
94 | status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_12 ); |
|
94 | status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_12 ); | |
95 |
|
95 | |||
96 | PRINTF("watchdog_isr *** this is the end, exit(0)\n"); |
|
96 | PRINTF("watchdog_isr *** this is the end, exit(0)\n"); | |
97 |
|
97 | |||
98 | exit(0); |
|
98 | exit(0); | |
99 | } |
|
99 | } | |
100 |
|
100 | |||
101 | void watchdog_configure(void) |
|
101 | void watchdog_configure(void) | |
102 | { |
|
102 | { | |
103 | /** This function configure the watchdog. |
|
103 | /** This function configure the watchdog. | |
104 | * |
|
104 | * | |
105 | * @param gptimer_regs points to the APB registers of the GPTIMER IP core. |
|
105 | * @param gptimer_regs points to the APB registers of the GPTIMER IP core. | |
106 | * @param timer is the number of the timer in the IP core (several timers can be instantiated). |
|
106 | * @param timer is the number of the timer in the IP core (several timers can be instantiated). | |
107 | * |
|
107 | * | |
108 | * The watchdog is a timer provided by the GPTIMER IP core of the GRLIB. |
|
108 | * The watchdog is a timer provided by the GPTIMER IP core of the GRLIB. | |
109 | * |
|
109 | * | |
110 | */ |
|
110 | */ | |
111 |
|
111 | |||
112 | LEON_Mask_interrupt( IRQ_GPTIMER_WATCHDOG ); // mask gptimer/watchdog interrupt during configuration |
|
112 | LEON_Mask_interrupt( IRQ_GPTIMER_WATCHDOG ); // mask gptimer/watchdog interrupt during configuration | |
113 |
|
113 | |||
114 | timer_configure( TIMER_WATCHDOG, CLKDIV_WATCHDOG, IRQ_SPARC_GPTIMER_WATCHDOG, watchdog_isr ); |
|
114 | timer_configure( TIMER_WATCHDOG, CLKDIV_WATCHDOG, IRQ_SPARC_GPTIMER_WATCHDOG, watchdog_isr ); | |
115 |
|
115 | |||
116 | LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG ); // clear gptimer/watchdog interrupt |
|
116 | LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG ); // clear gptimer/watchdog interrupt | |
117 | } |
|
117 | } | |
118 |
|
118 | |||
119 | void watchdog_stop(void) |
|
119 | void watchdog_stop(void) | |
120 | { |
|
120 | { | |
121 | LEON_Mask_interrupt( IRQ_GPTIMER_WATCHDOG ); // mask gptimer/watchdog interrupt line |
|
121 | LEON_Mask_interrupt( IRQ_GPTIMER_WATCHDOG ); // mask gptimer/watchdog interrupt line | |
122 | timer_stop( TIMER_WATCHDOG ); |
|
122 | timer_stop( TIMER_WATCHDOG ); | |
123 | LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG ); // clear gptimer/watchdog interrupt |
|
123 | LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG ); // clear gptimer/watchdog interrupt | |
124 | } |
|
124 | } | |
125 |
|
125 | |||
126 | void watchdog_reload(void) |
|
126 | void watchdog_reload(void) | |
127 | { |
|
127 | { | |
128 | /** This function reloads the watchdog timer counter with the timer reload value. |
|
128 | /** This function reloads the watchdog timer counter with the timer reload value. | |
129 | * |
|
129 | * | |
130 | * @param void |
|
130 | * @param void | |
131 | * |
|
131 | * | |
132 | * @return void |
|
132 | * @return void | |
133 | * |
|
133 | * | |
134 | */ |
|
134 | */ | |
135 |
|
135 | |||
136 | gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_LD; |
|
136 | gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_LD; | |
137 | } |
|
137 | } | |
138 |
|
138 | |||
139 | void watchdog_start(void) |
|
139 | void watchdog_start(void) | |
140 | { |
|
140 | { | |
141 | /** This function starts the watchdog timer. |
|
141 | /** This function starts the watchdog timer. | |
142 | * |
|
142 | * | |
143 | * @param gptimer_regs points to the APB registers of the GPTIMER IP core. |
|
143 | * @param gptimer_regs points to the APB registers of the GPTIMER IP core. | |
144 | * @param timer is the number of the timer in the IP core (several timers can be instantiated). |
|
144 | * @param timer is the number of the timer in the IP core (several timers can be instantiated). | |
145 | * |
|
145 | * | |
146 | */ |
|
146 | */ | |
147 |
|
147 | |||
148 | LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG ); |
|
148 | LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG ); | |
149 |
|
149 | |||
150 | gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_CLEAR_IRQ; |
|
150 | gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_CLEAR_IRQ; | |
151 | gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_LD; |
|
151 | gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_LD; | |
152 | gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_EN; |
|
152 | gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_EN; | |
153 | gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_IE; |
|
153 | gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_IE; | |
154 |
|
154 | |||
155 | LEON_Unmask_interrupt( IRQ_GPTIMER_WATCHDOG ); |
|
155 | LEON_Unmask_interrupt( IRQ_GPTIMER_WATCHDOG ); | |
156 |
|
156 | |||
157 | } |
|
157 | } | |
158 |
|
158 | |||
159 | int enable_apbuart_transmitter( void ) // set the bit 1, TE Transmitter Enable to 1 in the APBUART control register |
|
159 | int enable_apbuart_transmitter( void ) // set the bit 1, TE Transmitter Enable to 1 in the APBUART control register | |
160 | { |
|
160 | { | |
161 | struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART; |
|
161 | struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART; | |
162 |
|
162 | |||
163 | apbuart_regs->ctrl = APBUART_CTRL_REG_MASK_TE; |
|
163 | apbuart_regs->ctrl = APBUART_CTRL_REG_MASK_TE; | |
164 |
|
164 | |||
165 | return 0; |
|
165 | return 0; | |
166 | } |
|
166 | } | |
167 |
|
167 | |||
168 | void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value) |
|
168 | void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value) | |
169 | { |
|
169 | { | |
170 | /** This function sets the scaler reload register of the apbuart module |
|
170 | /** This function sets the scaler reload register of the apbuart module | |
171 | * |
|
171 | * | |
172 | * @param regs is the address of the apbuart registers in memory |
|
172 | * @param regs is the address of the apbuart registers in memory | |
173 | * @param value is the value that will be stored in the scaler register |
|
173 | * @param value is the value that will be stored in the scaler register | |
174 | * |
|
174 | * | |
175 | * The value shall be set by the software to get data on the serial interface. |
|
175 | * The value shall be set by the software to get data on the serial interface. | |
176 | * |
|
176 | * | |
177 | */ |
|
177 | */ | |
178 |
|
178 | |||
179 | struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) regs; |
|
179 | struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) regs; | |
180 |
|
180 | |||
181 | apbuart_regs->scaler = value; |
|
181 | apbuart_regs->scaler = value; | |
182 |
|
182 | |||
183 | BOOT_PRINTF1("OK *** apbuart port scaler reload register set to 0x%x\n", value) |
|
183 | BOOT_PRINTF1("OK *** apbuart port scaler reload register set to 0x%x\n", value) | |
184 | } |
|
184 | } | |
185 |
|
185 | |||
186 | //************ |
|
186 | //************ | |
187 | // RTEMS TASKS |
|
187 | // RTEMS TASKS | |
188 |
|
188 | |||
189 | rtems_task load_task(rtems_task_argument argument) |
|
189 | rtems_task load_task(rtems_task_argument argument) | |
190 | { |
|
190 | { | |
191 | BOOT_PRINTF("in LOAD *** \n") |
|
191 | BOOT_PRINTF("in LOAD *** \n") | |
192 |
|
192 | |||
193 | rtems_status_code status; |
|
193 | rtems_status_code status; | |
194 | unsigned int i; |
|
194 | unsigned int i; | |
195 | unsigned int j; |
|
195 | unsigned int j; | |
196 | rtems_name name_watchdog_rate_monotonic; // name of the watchdog rate monotonic |
|
196 | rtems_name name_watchdog_rate_monotonic; // name of the watchdog rate monotonic | |
197 | rtems_id watchdog_period_id; // id of the watchdog rate monotonic period |
|
197 | rtems_id watchdog_period_id; // id of the watchdog rate monotonic period | |
198 |
|
198 | |||
199 | watchdog_period_id = RTEMS_ID_NONE; |
|
199 | watchdog_period_id = RTEMS_ID_NONE; | |
200 |
|
200 | |||
201 | name_watchdog_rate_monotonic = rtems_build_name( 'L', 'O', 'A', 'D' ); |
|
201 | name_watchdog_rate_monotonic = rtems_build_name( 'L', 'O', 'A', 'D' ); | |
202 |
|
202 | |||
203 | status = rtems_rate_monotonic_create( name_watchdog_rate_monotonic, &watchdog_period_id ); |
|
203 | status = rtems_rate_monotonic_create( name_watchdog_rate_monotonic, &watchdog_period_id ); | |
204 | if( status != RTEMS_SUCCESSFUL ) { |
|
204 | if( status != RTEMS_SUCCESSFUL ) { | |
205 | PRINTF1( "in LOAD *** rtems_rate_monotonic_create failed with status of %d\n", status ) |
|
205 | PRINTF1( "in LOAD *** rtems_rate_monotonic_create failed with status of %d\n", status ) | |
206 | } |
|
206 | } | |
207 |
|
207 | |||
208 | i = 0; |
|
208 | i = 0; | |
209 | j = 0; |
|
209 | j = 0; | |
210 |
|
210 | |||
211 | watchdog_configure(); |
|
211 | watchdog_configure(); | |
212 |
|
212 | |||
213 | watchdog_start(); |
|
213 | watchdog_start(); | |
214 |
|
214 | |||
215 | set_sy_lfr_watchdog_enabled( true ); |
|
215 | set_sy_lfr_watchdog_enabled( true ); | |
216 |
|
216 | |||
217 | while(1){ |
|
217 | while(1){ | |
218 | status = rtems_rate_monotonic_period( watchdog_period_id, WATCHDOG_PERIOD ); |
|
218 | status = rtems_rate_monotonic_period( watchdog_period_id, WATCHDOG_PERIOD ); | |
219 | watchdog_reload(); |
|
219 | watchdog_reload(); | |
220 | i = i + 1; |
|
220 | i = i + 1; | |
221 | if ( i == WATCHDOG_LOOP_PRINTF ) |
|
221 | if ( i == WATCHDOG_LOOP_PRINTF ) | |
222 | { |
|
222 | { | |
223 | i = 0; |
|
223 | i = 0; | |
224 | j = j + 1; |
|
224 | j = j + 1; | |
225 | PRINTF1("%d\n", j) |
|
225 | PRINTF1("%d\n", j) | |
226 | } |
|
226 | } | |
227 | #ifdef DEBUG_WATCHDOG |
|
227 | #ifdef DEBUG_WATCHDOG | |
228 | if (j == WATCHDOG_LOOP_DEBUG ) |
|
228 | if (j == WATCHDOG_LOOP_DEBUG ) | |
229 | { |
|
229 | { | |
230 | status = rtems_task_delete(RTEMS_SELF); |
|
230 | status = rtems_task_delete(RTEMS_SELF); | |
231 | } |
|
231 | } | |
232 | #endif |
|
232 | #endif | |
233 | } |
|
233 | } | |
234 | } |
|
234 | } | |
235 |
|
235 | |||
236 | rtems_task hous_task(rtems_task_argument argument) |
|
236 | rtems_task hous_task(rtems_task_argument argument) | |
237 | { |
|
237 | { | |
238 | rtems_status_code status; |
|
238 | rtems_status_code status; | |
239 | rtems_status_code spare_status; |
|
239 | rtems_status_code spare_status; | |
240 | rtems_id queue_id; |
|
240 | rtems_id queue_id; | |
241 | rtems_rate_monotonic_period_status period_status; |
|
241 | rtems_rate_monotonic_period_status period_status; | |
242 | bool isSynchronized; |
|
242 | bool isSynchronized; | |
243 |
|
243 | |||
244 | queue_id = RTEMS_ID_NONE; |
|
244 | queue_id = RTEMS_ID_NONE; | |
245 | memset(&period_status, 0, sizeof(rtems_rate_monotonic_period_status)); |
|
245 | memset(&period_status, 0, sizeof(rtems_rate_monotonic_period_status)); | |
246 | isSynchronized = false; |
|
246 | isSynchronized = false; | |
247 |
|
247 | |||
248 | status = get_message_queue_id_send( &queue_id ); |
|
248 | status = get_message_queue_id_send( &queue_id ); | |
249 | if (status != RTEMS_SUCCESSFUL) |
|
249 | if (status != RTEMS_SUCCESSFUL) | |
250 | { |
|
250 | { | |
251 | PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status) |
|
251 | PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status) | |
252 | } |
|
252 | } | |
253 |
|
253 | |||
254 | BOOT_PRINTF("in HOUS ***\n"); |
|
254 | BOOT_PRINTF("in HOUS ***\n"); | |
255 |
|
255 | |||
256 | if (rtems_rate_monotonic_ident( name_hk_rate_monotonic, &HK_id) != RTEMS_SUCCESSFUL) { |
|
256 | if (rtems_rate_monotonic_ident( name_hk_rate_monotonic, &HK_id) != RTEMS_SUCCESSFUL) { | |
257 | status = rtems_rate_monotonic_create( name_hk_rate_monotonic, &HK_id ); |
|
257 | status = rtems_rate_monotonic_create( name_hk_rate_monotonic, &HK_id ); | |
258 | if( status != RTEMS_SUCCESSFUL ) { |
|
258 | if( status != RTEMS_SUCCESSFUL ) { | |
259 | PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status ); |
|
259 | PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status ); | |
260 | } |
|
260 | } | |
261 | } |
|
261 | } | |
262 |
|
262 | |||
263 | status = rtems_rate_monotonic_cancel(HK_id); |
|
263 | status = rtems_rate_monotonic_cancel(HK_id); | |
264 | if( status != RTEMS_SUCCESSFUL ) { |
|
264 | if( status != RTEMS_SUCCESSFUL ) { | |
265 | PRINTF1( "ERR *** in HOUS *** rtems_rate_monotonic_cancel(HK_id) ***code: %d\n", status ); |
|
265 | PRINTF1( "ERR *** in HOUS *** rtems_rate_monotonic_cancel(HK_id) ***code: %d\n", status ); | |
266 | } |
|
266 | } | |
267 | else { |
|
267 | else { | |
268 | DEBUG_PRINTF("OK *** in HOUS *** rtems_rate_monotonic_cancel(HK_id)\n"); |
|
268 | DEBUG_PRINTF("OK *** in HOUS *** rtems_rate_monotonic_cancel(HK_id)\n"); | |
269 | } |
|
269 | } | |
270 |
|
270 | |||
271 | // startup phase |
|
271 | // startup phase | |
272 | status = rtems_rate_monotonic_period( HK_id, SY_LFR_TIME_SYN_TIMEOUT_in_ticks ); |
|
272 | status = rtems_rate_monotonic_period( HK_id, SY_LFR_TIME_SYN_TIMEOUT_in_ticks ); | |
273 | status = rtems_rate_monotonic_get_status( HK_id, &period_status ); |
|
273 | status = rtems_rate_monotonic_get_status( HK_id, &period_status ); | |
274 | DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state) |
|
274 | DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state) | |
275 | while( (period_status.state != RATE_MONOTONIC_EXPIRED) |
|
275 | while( (period_status.state != RATE_MONOTONIC_EXPIRED) | |
276 | && (isSynchronized == false) ) // after SY_LFR_TIME_SYN_TIMEOUT ms, starts HK anyway |
|
276 | && (isSynchronized == false) ) // after SY_LFR_TIME_SYN_TIMEOUT ms, starts HK anyway | |
277 | { |
|
277 | { | |
278 | if ((time_management_regs->coarse_time & VAL_LFR_SYNCHRONIZED) == INT32_ALL_0) // check time synchronization |
|
278 | if ((time_management_regs->coarse_time & VAL_LFR_SYNCHRONIZED) == INT32_ALL_0) // check time synchronization | |
279 | { |
|
279 | { | |
280 | isSynchronized = true; |
|
280 | isSynchronized = true; | |
281 | } |
|
281 | } | |
282 | else |
|
282 | else | |
283 | { |
|
283 | { | |
284 | status = rtems_rate_monotonic_get_status( HK_id, &period_status ); |
|
284 | status = rtems_rate_monotonic_get_status( HK_id, &period_status ); | |
285 |
|
285 | |||
286 | status = rtems_task_wake_after( HK_SYNC_WAIT ); // wait HK_SYNCH_WAIT 100 ms = 10 * 10 ms |
|
286 | status = rtems_task_wake_after( HK_SYNC_WAIT ); // wait HK_SYNCH_WAIT 100 ms = 10 * 10 ms | |
287 | } |
|
287 | } | |
288 | } |
|
288 | } | |
289 | status = rtems_rate_monotonic_cancel(HK_id); |
|
289 | status = rtems_rate_monotonic_cancel(HK_id); | |
290 | DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state) |
|
290 | DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state) | |
291 |
|
291 | |||
292 | set_hk_lfr_reset_cause( POWER_ON ); |
|
292 | set_hk_lfr_reset_cause( POWER_ON ); | |
293 |
|
293 | |||
294 | while(1){ // launch the rate monotonic task |
|
294 | while(1){ // launch the rate monotonic task | |
295 | status = rtems_rate_monotonic_period( HK_id, HK_PERIOD ); |
|
295 | status = rtems_rate_monotonic_period( HK_id, HK_PERIOD ); | |
296 | if ( status != RTEMS_SUCCESSFUL ) { |
|
296 | if ( status != RTEMS_SUCCESSFUL ) { | |
297 | PRINTF1( "in HOUS *** ERR period: %d\n", status); |
|
297 | PRINTF1( "in HOUS *** ERR period: %d\n", status); | |
298 | spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_6 ); |
|
298 | spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_6 ); | |
299 | } |
|
299 | } | |
300 | else { |
|
300 | else { | |
301 | housekeeping_packet.packetSequenceControl[BYTE_0] = (unsigned char) (sequenceCounterHK >> SHIFT_1_BYTE); |
|
301 | housekeeping_packet.packetSequenceControl[BYTE_0] = (unsigned char) (sequenceCounterHK >> SHIFT_1_BYTE); | |
302 | housekeeping_packet.packetSequenceControl[BYTE_1] = (unsigned char) (sequenceCounterHK ); |
|
302 | housekeeping_packet.packetSequenceControl[BYTE_1] = (unsigned char) (sequenceCounterHK ); | |
303 | increment_seq_counter( &sequenceCounterHK ); |
|
303 | increment_seq_counter( &sequenceCounterHK ); | |
304 |
|
304 | |||
305 | housekeeping_packet.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES); |
|
305 | housekeeping_packet.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES); | |
306 | housekeeping_packet.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES); |
|
306 | housekeeping_packet.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES); | |
307 | housekeeping_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE); |
|
307 | housekeeping_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE); | |
308 | housekeeping_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time); |
|
308 | housekeeping_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time); | |
309 | housekeeping_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE); |
|
309 | housekeeping_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE); | |
310 | housekeeping_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time); |
|
310 | housekeeping_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time); | |
311 |
|
311 | |||
312 | spacewire_update_hk_lfr_link_state( &housekeeping_packet.lfr_status_word[0] ); |
|
312 | spacewire_update_hk_lfr_link_state( &housekeeping_packet.lfr_status_word[0] ); | |
313 |
|
313 | |||
314 | spacewire_read_statistics(); |
|
314 | spacewire_read_statistics(); | |
315 |
|
315 | |||
316 | update_hk_with_grspw_stats(); |
|
316 | update_hk_with_grspw_stats(); | |
317 |
|
317 | |||
318 | set_hk_lfr_time_not_synchro(); |
|
318 | set_hk_lfr_time_not_synchro(); | |
319 |
|
319 | |||
320 | housekeeping_packet.hk_lfr_q_sd_fifo_size_max = hk_lfr_q_sd_fifo_size_max; |
|
320 | housekeeping_packet.hk_lfr_q_sd_fifo_size_max = hk_lfr_q_sd_fifo_size_max; | |
321 | housekeeping_packet.hk_lfr_q_rv_fifo_size_max = hk_lfr_q_rv_fifo_size_max; |
|
321 | housekeeping_packet.hk_lfr_q_rv_fifo_size_max = hk_lfr_q_rv_fifo_size_max; | |
322 | housekeeping_packet.hk_lfr_q_p0_fifo_size_max = hk_lfr_q_p0_fifo_size_max; |
|
322 | housekeeping_packet.hk_lfr_q_p0_fifo_size_max = hk_lfr_q_p0_fifo_size_max; | |
323 | housekeeping_packet.hk_lfr_q_p1_fifo_size_max = hk_lfr_q_p1_fifo_size_max; |
|
323 | housekeeping_packet.hk_lfr_q_p1_fifo_size_max = hk_lfr_q_p1_fifo_size_max; | |
324 | housekeeping_packet.hk_lfr_q_p2_fifo_size_max = hk_lfr_q_p2_fifo_size_max; |
|
324 | housekeeping_packet.hk_lfr_q_p2_fifo_size_max = hk_lfr_q_p2_fifo_size_max; | |
325 |
|
325 | |||
326 | housekeeping_packet.sy_lfr_common_parameters_spare = parameter_dump_packet.sy_lfr_common_parameters_spare; |
|
326 | housekeeping_packet.sy_lfr_common_parameters_spare = parameter_dump_packet.sy_lfr_common_parameters_spare; | |
327 | housekeeping_packet.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; |
|
327 | housekeeping_packet.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; | |
328 | get_temperatures( housekeeping_packet.hk_lfr_temp_scm ); |
|
328 | get_temperatures( housekeeping_packet.hk_lfr_temp_scm ); | |
329 | get_v_e1_e2_f3( housekeeping_packet.hk_lfr_sc_v_f3 ); |
|
329 | get_v_e1_e2_f3( housekeeping_packet.hk_lfr_sc_v_f3 ); | |
330 | get_cpu_load( (unsigned char *) &housekeeping_packet.hk_lfr_cpu_load ); |
|
330 | get_cpu_load( (unsigned char *) &housekeeping_packet.hk_lfr_cpu_load ); | |
331 |
|
331 | |||
332 | hk_lfr_le_me_he_update(); |
|
332 | hk_lfr_le_me_he_update(); | |
333 |
|
333 | |||
334 | // SEND PACKET |
|
334 | // SEND PACKET | |
335 | status = rtems_message_queue_send( queue_id, &housekeeping_packet, |
|
335 | status = rtems_message_queue_send( queue_id, &housekeeping_packet, | |
336 | PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES); |
|
336 | PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES); | |
337 | if (status != RTEMS_SUCCESSFUL) { |
|
337 | if (status != RTEMS_SUCCESSFUL) { | |
338 | PRINTF1("in HOUS *** ERR send: %d\n", status) |
|
338 | PRINTF1("in HOUS *** ERR send: %d\n", status) | |
339 | } |
|
339 | } | |
340 | } |
|
340 | } | |
341 | } |
|
341 | } | |
342 |
|
342 | |||
343 | PRINTF("in HOUS *** deleting task\n") |
|
343 | PRINTF("in HOUS *** deleting task\n") | |
344 |
|
344 | |||
345 | status = rtems_task_delete( RTEMS_SELF ); // should not return |
|
345 | status = rtems_task_delete( RTEMS_SELF ); // should not return | |
346 |
|
346 | |||
347 | return; |
|
347 | return; | |
348 | } |
|
348 | } | |
349 |
|
349 | |||
350 | int filter( int x, filter_ctx* ctx ) |
|
350 | int filter( int x, filter_ctx* ctx ) | |
351 | { |
|
351 | { | |
352 | static const int b[NB_COEFFS][NB_COEFFS]={ {B00, B01, B02}, {B10, B11, B12}, {B20, B21, B22} }; |
|
352 | static const int b[NB_COEFFS][NB_COEFFS]={ {B00, B01, B02}, {B10, B11, B12}, {B20, B21, B22} }; | |
353 | static const int a[NB_COEFFS][NB_COEFFS]={ {A00, A01, A02}, {A10, A11, A12}, {A20, A21, A22} }; |
|
353 | static const int a[NB_COEFFS][NB_COEFFS]={ {A00, A01, A02}, {A10, A11, A12}, {A20, A21, A22} }; | |
354 | static const int b_gain[NB_COEFFS]={GAIN_B0, GAIN_B1, GAIN_B2}; |
|
354 | static const int b_gain[NB_COEFFS]={GAIN_B0, GAIN_B1, GAIN_B2}; | |
355 | static const int a_gain[NB_COEFFS]={GAIN_A0, GAIN_A1, GAIN_A2}; |
|
355 | static const int a_gain[NB_COEFFS]={GAIN_A0, GAIN_A1, GAIN_A2}; | |
356 |
|
356 | |||
357 | int_fast32_t W; |
|
357 | int_fast32_t W; | |
358 | int i; |
|
358 | int i; | |
359 |
|
359 | |||
360 | W = INIT_INT; |
|
360 | W = INIT_INT; | |
361 | i = INIT_INT; |
|
361 | i = INIT_INT; | |
362 |
|
362 | |||
363 | //Direct-Form-II |
|
363 | //Direct-Form-II | |
364 | for ( i = 0; i < NB_COEFFS; i++ ) |
|
364 | for ( i = 0; i < NB_COEFFS; i++ ) | |
365 | { |
|
365 | { | |
366 | x = x << a_gain[i]; |
|
366 | x = x << a_gain[i]; | |
367 | W = (x - ( a[i][COEFF1] * ctx->W[i][COEFF0] ) |
|
367 | W = (x - ( a[i][COEFF1] * ctx->W[i][COEFF0] ) | |
368 | - ( a[i][COEFF2] * ctx->W[i][COEFF1] ) ) >> a_gain[i]; |
|
368 | - ( a[i][COEFF2] * ctx->W[i][COEFF1] ) ) >> a_gain[i]; | |
369 | x = ( b[i][COEFF0] * W ) |
|
369 | x = ( b[i][COEFF0] * W ) | |
370 | + ( b[i][COEFF1] * ctx->W[i][COEFF0] ) |
|
370 | + ( b[i][COEFF1] * ctx->W[i][COEFF0] ) | |
371 | + ( b[i][COEFF2] * ctx->W[i][COEFF1] ); |
|
371 | + ( b[i][COEFF2] * ctx->W[i][COEFF1] ); | |
372 | x = x >> b_gain[i]; |
|
372 | x = x >> b_gain[i]; | |
373 | ctx->W[i][1] = ctx->W[i][0]; |
|
373 | ctx->W[i][1] = ctx->W[i][0]; | |
374 | ctx->W[i][0] = W; |
|
374 | ctx->W[i][0] = W; | |
375 | } |
|
375 | } | |
376 | return x; |
|
376 | return x; | |
377 | } |
|
377 | } | |
378 |
|
378 | |||
379 | rtems_task avgv_task(rtems_task_argument argument) |
|
379 | rtems_task avgv_task(rtems_task_argument argument) | |
380 | { |
|
380 | { | |
381 | #define MOVING_AVERAGE 16 |
|
381 | #define MOVING_AVERAGE 16 | |
382 | rtems_status_code status; |
|
382 | rtems_status_code status; | |
383 | static int32_t v[MOVING_AVERAGE] = {0}; |
|
383 | static int32_t v[MOVING_AVERAGE] = {0}; | |
384 | static int32_t e1[MOVING_AVERAGE] = {0}; |
|
384 | static int32_t e1[MOVING_AVERAGE] = {0}; | |
385 | static int32_t e2[MOVING_AVERAGE] = {0}; |
|
385 | static int32_t e2[MOVING_AVERAGE] = {0}; | |
386 | static int old_v = 0; |
|
386 | static int old_v = 0; | |
387 | static int old_e1 = 0; |
|
387 | static int old_e1 = 0; | |
388 | static int old_e2 = 0; |
|
388 | static int old_e2 = 0; | |
389 | int32_t current_v; |
|
389 | int32_t current_v; | |
390 | int32_t current_e1; |
|
390 | int32_t current_e1; | |
391 | int32_t current_e2; |
|
391 | int32_t current_e2; | |
392 | int32_t average_v; |
|
392 | int32_t average_v; | |
393 | int32_t average_e1; |
|
393 | int32_t average_e1; | |
394 | int32_t average_e2; |
|
394 | int32_t average_e2; | |
395 | int32_t newValue_v; |
|
395 | int32_t newValue_v; | |
396 | int32_t newValue_e1; |
|
396 | int32_t newValue_e1; | |
397 | int32_t newValue_e2; |
|
397 | int32_t newValue_e2; | |
398 | unsigned char k; |
|
398 | unsigned char k; | |
399 | unsigned char indexOfOldValue; |
|
399 | unsigned char indexOfOldValue; | |
400 |
|
400 | |||
401 | static filter_ctx ctx_v = { { {0,0,0}, {0,0,0}, {0,0,0} } }; |
|
401 | static filter_ctx ctx_v = { { {0,0,0}, {0,0,0}, {0,0,0} } }; | |
402 | static filter_ctx ctx_e1 = { { {0,0,0}, {0,0,0}, {0,0,0} } }; |
|
402 | static filter_ctx ctx_e1 = { { {0,0,0}, {0,0,0}, {0,0,0} } }; | |
403 | static filter_ctx ctx_e2 = { { {0,0,0}, {0,0,0}, {0,0,0} } }; |
|
403 | static filter_ctx ctx_e2 = { { {0,0,0}, {0,0,0}, {0,0,0} } }; | |
404 |
|
404 | |||
405 | BOOT_PRINTF("in AVGV ***\n"); |
|
405 | BOOT_PRINTF("in AVGV ***\n"); | |
406 |
|
406 | |||
407 | if (rtems_rate_monotonic_ident( name_avgv_rate_monotonic, &AVGV_id) != RTEMS_SUCCESSFUL) { |
|
407 | if (rtems_rate_monotonic_ident( name_avgv_rate_monotonic, &AVGV_id) != RTEMS_SUCCESSFUL) { | |
408 | status = rtems_rate_monotonic_create( name_avgv_rate_monotonic, &AVGV_id ); |
|
408 | status = rtems_rate_monotonic_create( name_avgv_rate_monotonic, &AVGV_id ); | |
409 | if( status != RTEMS_SUCCESSFUL ) { |
|
409 | if( status != RTEMS_SUCCESSFUL ) { | |
410 | PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status ); |
|
410 | PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status ); | |
411 | } |
|
411 | } | |
412 | } |
|
412 | } | |
413 |
|
413 | |||
414 | status = rtems_rate_monotonic_cancel(AVGV_id); |
|
414 | status = rtems_rate_monotonic_cancel(AVGV_id); | |
415 | if( status != RTEMS_SUCCESSFUL ) { |
|
415 | if( status != RTEMS_SUCCESSFUL ) { | |
416 | PRINTF1( "ERR *** in AVGV *** rtems_rate_monotonic_cancel(AVGV_id) ***code: %d\n", status ); |
|
416 | PRINTF1( "ERR *** in AVGV *** rtems_rate_monotonic_cancel(AVGV_id) ***code: %d\n", status ); | |
417 | } |
|
417 | } | |
418 | else { |
|
418 | else { | |
419 | DEBUG_PRINTF("OK *** in AVGV *** rtems_rate_monotonic_cancel(AVGV_id)\n"); |
|
419 | DEBUG_PRINTF("OK *** in AVGV *** rtems_rate_monotonic_cancel(AVGV_id)\n"); | |
420 | } |
|
420 | } | |
421 |
|
421 | |||
422 | // initialize values |
|
422 | // initialize values | |
423 | indexOfOldValue = MOVING_AVERAGE - 1; |
|
423 | indexOfOldValue = MOVING_AVERAGE - 1; | |
424 | current_v = 0; |
|
424 | current_v = 0; | |
425 | current_e1 = 0; |
|
425 | current_e1 = 0; | |
426 | current_e2 = 0; |
|
426 | current_e2 = 0; | |
427 | average_v = 0; |
|
427 | average_v = 0; | |
428 | average_e1 = 0; |
|
428 | average_e1 = 0; | |
429 | average_e2 = 0; |
|
429 | average_e2 = 0; | |
430 | newValue_v = 0; |
|
430 | newValue_v = 0; | |
431 | newValue_e1 = 0; |
|
431 | newValue_e1 = 0; | |
432 | newValue_e2 = 0; |
|
432 | newValue_e2 = 0; | |
433 |
|
433 | |||
434 | k = INIT_CHAR; |
|
434 | k = INIT_CHAR; | |
435 |
|
435 | |||
436 | while(1) |
|
436 | while(1) | |
437 | { // launch the rate monotonic task |
|
437 | { // launch the rate monotonic task | |
438 | status = rtems_rate_monotonic_period( AVGV_id, AVGV_PERIOD ); |
|
438 | status = rtems_rate_monotonic_period( AVGV_id, AVGV_PERIOD ); | |
439 | if ( status != RTEMS_SUCCESSFUL ) |
|
439 | if ( status != RTEMS_SUCCESSFUL ) | |
440 | { |
|
440 | { | |
441 | PRINTF1( "in AVGV *** ERR period: %d\n", status); |
|
441 | PRINTF1( "in AVGV *** ERR period: %d\n", status); | |
442 | } |
|
442 | } | |
443 | else |
|
443 | else | |
444 | { |
|
444 | { | |
445 | current_v = waveform_picker_regs->v; |
|
445 | current_v = waveform_picker_regs->v; | |
446 | current_e1 = waveform_picker_regs->e1; |
|
446 | current_e1 = waveform_picker_regs->e1; | |
447 | current_e2 = waveform_picker_regs->e2; |
|
447 | current_e2 = waveform_picker_regs->e2; | |
448 | if ( (current_v != old_v) |
|
448 | if ( (current_v != old_v) | |
449 | || (current_e1 != old_e1) |
|
449 | || (current_e1 != old_e1) | |
450 | || (current_e2 != old_e2)) |
|
450 | || (current_e2 != old_e2)) | |
451 | { |
|
451 | { | |
452 | average_v = filter( current_v, &ctx_v ); |
|
452 | average_v = filter( current_v, &ctx_v ); | |
453 | average_e1 = filter( current_e1, &ctx_e1 ); |
|
453 | average_e1 = filter( current_e1, &ctx_e1 ); | |
454 | average_e2 = filter( current_e2, &ctx_e2 ); |
|
454 | average_e2 = filter( current_e2, &ctx_e2 ); | |
455 |
|
455 | |||
456 | //update int16 values |
|
456 | //update int16 values | |
457 |
hk_lfr_sc_v_f3_as_int16 = (int16_t) |
|
457 | hk_lfr_sc_v_f3_as_int16 = (int16_t) average_v; | |
458 |
hk_lfr_sc_e1_f3_as_int16 = (int16_t) |
|
458 | hk_lfr_sc_e1_f3_as_int16 = (int16_t) average_e1; | |
459 |
hk_lfr_sc_e2_f3_as_int16 = (int16_t) |
|
459 | hk_lfr_sc_e2_f3_as_int16 = (int16_t) average_e2; | |
460 | } |
|
460 | } | |
461 | old_v = current_v; |
|
461 | old_v = current_v; | |
462 | old_e1 = current_e1; |
|
462 | old_e1 = current_e1; | |
463 | old_e2 = current_e2; |
|
463 | old_e2 = current_e2; | |
464 | } |
|
464 | } | |
465 | } |
|
465 | } | |
466 |
|
466 | |||
467 | PRINTF("in AVGV *** deleting task\n"); |
|
467 | PRINTF("in AVGV *** deleting task\n"); | |
468 |
|
468 | |||
469 | status = rtems_task_delete( RTEMS_SELF ); // should not return |
|
469 | status = rtems_task_delete( RTEMS_SELF ); // should not return | |
470 |
|
470 | |||
471 | return; |
|
471 | return; | |
472 | } |
|
472 | } | |
473 |
|
473 | |||
474 | rtems_task dumb_task( rtems_task_argument unused ) |
|
474 | rtems_task dumb_task( rtems_task_argument unused ) | |
475 | { |
|
475 | { | |
476 | /** This RTEMS taks is used to print messages without affecting the general behaviour of the software. |
|
476 | /** This RTEMS taks is used to print messages without affecting the general behaviour of the software. | |
477 | * |
|
477 | * | |
478 | * @param unused is the starting argument of the RTEMS task |
|
478 | * @param unused is the starting argument of the RTEMS task | |
479 | * |
|
479 | * | |
480 | * The DUMB taks waits for RTEMS events and print messages depending on the incoming events. |
|
480 | * The DUMB taks waits for RTEMS events and print messages depending on the incoming events. | |
481 | * |
|
481 | * | |
482 | */ |
|
482 | */ | |
483 |
|
483 | |||
484 | unsigned int i; |
|
484 | unsigned int i; | |
485 | unsigned int intEventOut; |
|
485 | unsigned int intEventOut; | |
486 | unsigned int coarse_time = 0; |
|
486 | unsigned int coarse_time = 0; | |
487 | unsigned int fine_time = 0; |
|
487 | unsigned int fine_time = 0; | |
488 | rtems_event_set event_out; |
|
488 | rtems_event_set event_out; | |
489 |
|
489 | |||
490 | event_out = EVENT_SETS_NONE_PENDING; |
|
490 | event_out = EVENT_SETS_NONE_PENDING; | |
491 |
|
491 | |||
492 | BOOT_PRINTF("in DUMB *** \n") |
|
492 | BOOT_PRINTF("in DUMB *** \n") | |
493 |
|
493 | |||
494 | while(1){ |
|
494 | while(1){ | |
495 | rtems_event_receive(RTEMS_EVENT_0 | RTEMS_EVENT_1 | RTEMS_EVENT_2 | RTEMS_EVENT_3 |
|
495 | rtems_event_receive(RTEMS_EVENT_0 | RTEMS_EVENT_1 | RTEMS_EVENT_2 | RTEMS_EVENT_3 | |
496 | | RTEMS_EVENT_4 | RTEMS_EVENT_5 | RTEMS_EVENT_6 | RTEMS_EVENT_7 |
|
496 | | RTEMS_EVENT_4 | RTEMS_EVENT_5 | RTEMS_EVENT_6 | RTEMS_EVENT_7 | |
497 | | RTEMS_EVENT_8 | RTEMS_EVENT_9 | RTEMS_EVENT_12 | RTEMS_EVENT_13 |
|
497 | | RTEMS_EVENT_8 | RTEMS_EVENT_9 | RTEMS_EVENT_12 | RTEMS_EVENT_13 | |
498 | | RTEMS_EVENT_14, |
|
498 | | RTEMS_EVENT_14, | |
499 | RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT |
|
499 | RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT | |
500 | intEventOut = (unsigned int) event_out; |
|
500 | intEventOut = (unsigned int) event_out; | |
501 | for ( i=0; i<NB_RTEMS_EVENTS; i++) |
|
501 | for ( i=0; i<NB_RTEMS_EVENTS; i++) | |
502 | { |
|
502 | { | |
503 | if ( ((intEventOut >> i) & 1) != 0) |
|
503 | if ( ((intEventOut >> i) & 1) != 0) | |
504 | { |
|
504 | { | |
505 | coarse_time = time_management_regs->coarse_time; |
|
505 | coarse_time = time_management_regs->coarse_time; | |
506 | fine_time = time_management_regs->fine_time; |
|
506 | fine_time = time_management_regs->fine_time; | |
507 | if (i==EVENT_12) |
|
507 | if (i==EVENT_12) | |
508 | { |
|
508 | { | |
509 | PRINTF1("%s\n", DUMB_MESSAGE_12) |
|
509 | PRINTF1("%s\n", DUMB_MESSAGE_12) | |
510 | } |
|
510 | } | |
511 | if (i==EVENT_13) |
|
511 | if (i==EVENT_13) | |
512 | { |
|
512 | { | |
513 | PRINTF1("%s\n", DUMB_MESSAGE_13) |
|
513 | PRINTF1("%s\n", DUMB_MESSAGE_13) | |
514 | } |
|
514 | } | |
515 | if (i==EVENT_14) |
|
515 | if (i==EVENT_14) | |
516 | { |
|
516 | { | |
517 | PRINTF1("%s\n", DUMB_MESSAGE_1) |
|
517 | PRINTF1("%s\n", DUMB_MESSAGE_1) | |
518 | } |
|
518 | } | |
519 | } |
|
519 | } | |
520 | } |
|
520 | } | |
521 | } |
|
521 | } | |
522 | } |
|
522 | } | |
523 |
|
523 | |||
524 | //***************************** |
|
524 | //***************************** | |
525 | // init housekeeping parameters |
|
525 | // init housekeeping parameters | |
526 |
|
526 | |||
527 | void init_housekeeping_parameters( void ) |
|
527 | void init_housekeeping_parameters( void ) | |
528 | { |
|
528 | { | |
529 | /** This function initialize the housekeeping_packet global variable with default values. |
|
529 | /** This function initialize the housekeeping_packet global variable with default values. | |
530 | * |
|
530 | * | |
531 | */ |
|
531 | */ | |
532 |
|
532 | |||
533 | unsigned int i = 0; |
|
533 | unsigned int i = 0; | |
534 | unsigned char *parameters; |
|
534 | unsigned char *parameters; | |
535 | unsigned char sizeOfHK; |
|
535 | unsigned char sizeOfHK; | |
536 |
|
536 | |||
537 | sizeOfHK = sizeof( Packet_TM_LFR_HK_t ); |
|
537 | sizeOfHK = sizeof( Packet_TM_LFR_HK_t ); | |
538 |
|
538 | |||
539 | parameters = (unsigned char*) &housekeeping_packet; |
|
539 | parameters = (unsigned char*) &housekeeping_packet; | |
540 |
|
540 | |||
541 | for(i = 0; i< sizeOfHK; i++) |
|
541 | for(i = 0; i< sizeOfHK; i++) | |
542 | { |
|
542 | { | |
543 | parameters[i] = INIT_CHAR; |
|
543 | parameters[i] = INIT_CHAR; | |
544 | } |
|
544 | } | |
545 |
|
545 | |||
546 | housekeeping_packet.targetLogicalAddress = CCSDS_DESTINATION_ID; |
|
546 | housekeeping_packet.targetLogicalAddress = CCSDS_DESTINATION_ID; | |
547 | housekeeping_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID; |
|
547 | housekeeping_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID; | |
548 | housekeeping_packet.reserved = DEFAULT_RESERVED; |
|
548 | housekeeping_packet.reserved = DEFAULT_RESERVED; | |
549 | housekeeping_packet.userApplication = CCSDS_USER_APP; |
|
549 | housekeeping_packet.userApplication = CCSDS_USER_APP; | |
550 | housekeeping_packet.packetID[0] = (unsigned char) (APID_TM_HK >> SHIFT_1_BYTE); |
|
550 | housekeeping_packet.packetID[0] = (unsigned char) (APID_TM_HK >> SHIFT_1_BYTE); | |
551 | housekeeping_packet.packetID[1] = (unsigned char) (APID_TM_HK); |
|
551 | housekeeping_packet.packetID[1] = (unsigned char) (APID_TM_HK); | |
552 | housekeeping_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE; |
|
552 | housekeeping_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE; | |
553 | housekeeping_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT; |
|
553 | housekeeping_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT; | |
554 | housekeeping_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> SHIFT_1_BYTE); |
|
554 | housekeeping_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> SHIFT_1_BYTE); | |
555 | housekeeping_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK ); |
|
555 | housekeeping_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK ); | |
556 | housekeeping_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; |
|
556 | housekeeping_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; | |
557 | housekeeping_packet.serviceType = TM_TYPE_HK; |
|
557 | housekeeping_packet.serviceType = TM_TYPE_HK; | |
558 | housekeeping_packet.serviceSubType = TM_SUBTYPE_HK; |
|
558 | housekeeping_packet.serviceSubType = TM_SUBTYPE_HK; | |
559 | housekeeping_packet.destinationID = TM_DESTINATION_ID_GROUND; |
|
559 | housekeeping_packet.destinationID = TM_DESTINATION_ID_GROUND; | |
560 | housekeeping_packet.sid = SID_HK; |
|
560 | housekeeping_packet.sid = SID_HK; | |
561 |
|
561 | |||
562 | // init status word |
|
562 | // init status word | |
563 | housekeeping_packet.lfr_status_word[0] = DEFAULT_STATUS_WORD_BYTE0; |
|
563 | housekeeping_packet.lfr_status_word[0] = DEFAULT_STATUS_WORD_BYTE0; | |
564 | housekeeping_packet.lfr_status_word[1] = DEFAULT_STATUS_WORD_BYTE1; |
|
564 | housekeeping_packet.lfr_status_word[1] = DEFAULT_STATUS_WORD_BYTE1; | |
565 | // init software version |
|
565 | // init software version | |
566 | housekeeping_packet.lfr_sw_version[0] = SW_VERSION_N1; |
|
566 | housekeeping_packet.lfr_sw_version[0] = SW_VERSION_N1; | |
567 | housekeeping_packet.lfr_sw_version[1] = SW_VERSION_N2; |
|
567 | housekeeping_packet.lfr_sw_version[1] = SW_VERSION_N2; | |
568 | housekeeping_packet.lfr_sw_version[BYTE_2] = SW_VERSION_N3; |
|
568 | housekeeping_packet.lfr_sw_version[BYTE_2] = SW_VERSION_N3; | |
569 | housekeeping_packet.lfr_sw_version[BYTE_3] = SW_VERSION_N4; |
|
569 | housekeeping_packet.lfr_sw_version[BYTE_3] = SW_VERSION_N4; | |
570 | // init fpga version |
|
570 | // init fpga version | |
571 | parameters = (unsigned char *) (REGS_ADDR_VHDL_VERSION); |
|
571 | parameters = (unsigned char *) (REGS_ADDR_VHDL_VERSION); | |
572 | housekeeping_packet.lfr_fpga_version[BYTE_0] = parameters[BYTE_1]; // n1 |
|
572 | housekeeping_packet.lfr_fpga_version[BYTE_0] = parameters[BYTE_1]; // n1 | |
573 | housekeeping_packet.lfr_fpga_version[BYTE_1] = parameters[BYTE_2]; // n2 |
|
573 | housekeeping_packet.lfr_fpga_version[BYTE_1] = parameters[BYTE_2]; // n2 | |
574 | housekeeping_packet.lfr_fpga_version[BYTE_2] = parameters[BYTE_3]; // n3 |
|
574 | housekeeping_packet.lfr_fpga_version[BYTE_2] = parameters[BYTE_3]; // n3 | |
575 |
|
575 | |||
576 | housekeeping_packet.hk_lfr_q_sd_fifo_size = MSG_QUEUE_COUNT_SEND; |
|
576 | housekeeping_packet.hk_lfr_q_sd_fifo_size = MSG_QUEUE_COUNT_SEND; | |
577 | housekeeping_packet.hk_lfr_q_rv_fifo_size = MSG_QUEUE_COUNT_RECV; |
|
577 | housekeeping_packet.hk_lfr_q_rv_fifo_size = MSG_QUEUE_COUNT_RECV; | |
578 | housekeeping_packet.hk_lfr_q_p0_fifo_size = MSG_QUEUE_COUNT_PRC0; |
|
578 | housekeeping_packet.hk_lfr_q_p0_fifo_size = MSG_QUEUE_COUNT_PRC0; | |
579 | housekeeping_packet.hk_lfr_q_p1_fifo_size = MSG_QUEUE_COUNT_PRC1; |
|
579 | housekeeping_packet.hk_lfr_q_p1_fifo_size = MSG_QUEUE_COUNT_PRC1; | |
580 | housekeeping_packet.hk_lfr_q_p2_fifo_size = MSG_QUEUE_COUNT_PRC2; |
|
580 | housekeeping_packet.hk_lfr_q_p2_fifo_size = MSG_QUEUE_COUNT_PRC2; | |
581 | } |
|
581 | } | |
582 |
|
582 | |||
583 | void increment_seq_counter( unsigned short *packetSequenceControl ) |
|
583 | void increment_seq_counter( unsigned short *packetSequenceControl ) | |
584 | { |
|
584 | { | |
585 | /** This function increment the sequence counter passes in argument. |
|
585 | /** This function increment the sequence counter passes in argument. | |
586 | * |
|
586 | * | |
587 | * The increment does not affect the grouping flag. In case of an overflow, the counter is reset to 0. |
|
587 | * The increment does not affect the grouping flag. In case of an overflow, the counter is reset to 0. | |
588 | * |
|
588 | * | |
589 | */ |
|
589 | */ | |
590 |
|
590 | |||
591 | unsigned short segmentation_grouping_flag; |
|
591 | unsigned short segmentation_grouping_flag; | |
592 | unsigned short sequence_cnt; |
|
592 | unsigned short sequence_cnt; | |
593 |
|
593 | |||
594 | segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << SHIFT_1_BYTE; // keep bits 7 downto 6 |
|
594 | segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << SHIFT_1_BYTE; // keep bits 7 downto 6 | |
595 | sequence_cnt = (*packetSequenceControl) & SEQ_CNT_MASK; // [0011 1111 1111 1111] |
|
595 | sequence_cnt = (*packetSequenceControl) & SEQ_CNT_MASK; // [0011 1111 1111 1111] | |
596 |
|
596 | |||
597 | if ( sequence_cnt < SEQ_CNT_MAX) |
|
597 | if ( sequence_cnt < SEQ_CNT_MAX) | |
598 | { |
|
598 | { | |
599 | sequence_cnt = sequence_cnt + 1; |
|
599 | sequence_cnt = sequence_cnt + 1; | |
600 | } |
|
600 | } | |
601 | else |
|
601 | else | |
602 | { |
|
602 | { | |
603 | sequence_cnt = 0; |
|
603 | sequence_cnt = 0; | |
604 | } |
|
604 | } | |
605 |
|
605 | |||
606 | *packetSequenceControl = segmentation_grouping_flag | sequence_cnt ; |
|
606 | *packetSequenceControl = segmentation_grouping_flag | sequence_cnt ; | |
607 | } |
|
607 | } | |
608 |
|
608 | |||
609 | void getTime( unsigned char *time) |
|
609 | void getTime( unsigned char *time) | |
610 | { |
|
610 | { | |
611 | /** This function write the current local time in the time buffer passed in argument. |
|
611 | /** This function write the current local time in the time buffer passed in argument. | |
612 | * |
|
612 | * | |
613 | */ |
|
613 | */ | |
614 |
|
614 | |||
615 | time[0] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_3_BYTES); |
|
615 | time[0] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_3_BYTES); | |
616 | time[1] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_2_BYTES); |
|
616 | time[1] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_2_BYTES); | |
617 | time[2] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_1_BYTE); |
|
617 | time[2] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_1_BYTE); | |
618 | time[3] = (unsigned char) (time_management_regs->coarse_time); |
|
618 | time[3] = (unsigned char) (time_management_regs->coarse_time); | |
619 | time[4] = (unsigned char) (time_management_regs->fine_time>>SHIFT_1_BYTE); |
|
619 | time[4] = (unsigned char) (time_management_regs->fine_time>>SHIFT_1_BYTE); | |
620 | time[5] = (unsigned char) (time_management_regs->fine_time); |
|
620 | time[5] = (unsigned char) (time_management_regs->fine_time); | |
621 | } |
|
621 | } | |
622 |
|
622 | |||
623 | unsigned long long int getTimeAsUnsignedLongLongInt( ) |
|
623 | unsigned long long int getTimeAsUnsignedLongLongInt( ) | |
624 | { |
|
624 | { | |
625 | /** This function write the current local time in the time buffer passed in argument. |
|
625 | /** This function write the current local time in the time buffer passed in argument. | |
626 | * |
|
626 | * | |
627 | */ |
|
627 | */ | |
628 | unsigned long long int time; |
|
628 | unsigned long long int time; | |
629 |
|
629 | |||
630 | time = ( (unsigned long long int) (time_management_regs->coarse_time & COARSE_TIME_MASK) << SHIFT_2_BYTES ) |
|
630 | time = ( (unsigned long long int) (time_management_regs->coarse_time & COARSE_TIME_MASK) << SHIFT_2_BYTES ) | |
631 | + time_management_regs->fine_time; |
|
631 | + time_management_regs->fine_time; | |
632 |
|
632 | |||
633 | return time; |
|
633 | return time; | |
634 | } |
|
634 | } | |
635 |
|
635 | |||
636 | void send_dumb_hk( void ) |
|
636 | void send_dumb_hk( void ) | |
637 | { |
|
637 | { | |
638 | Packet_TM_LFR_HK_t dummy_hk_packet; |
|
638 | Packet_TM_LFR_HK_t dummy_hk_packet; | |
639 | unsigned char *parameters; |
|
639 | unsigned char *parameters; | |
640 | unsigned int i; |
|
640 | unsigned int i; | |
641 | rtems_id queue_id; |
|
641 | rtems_id queue_id; | |
642 |
|
642 | |||
643 | queue_id = RTEMS_ID_NONE; |
|
643 | queue_id = RTEMS_ID_NONE; | |
644 |
|
644 | |||
645 | dummy_hk_packet.targetLogicalAddress = CCSDS_DESTINATION_ID; |
|
645 | dummy_hk_packet.targetLogicalAddress = CCSDS_DESTINATION_ID; | |
646 | dummy_hk_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID; |
|
646 | dummy_hk_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID; | |
647 | dummy_hk_packet.reserved = DEFAULT_RESERVED; |
|
647 | dummy_hk_packet.reserved = DEFAULT_RESERVED; | |
648 | dummy_hk_packet.userApplication = CCSDS_USER_APP; |
|
648 | dummy_hk_packet.userApplication = CCSDS_USER_APP; | |
649 | dummy_hk_packet.packetID[0] = (unsigned char) (APID_TM_HK >> SHIFT_1_BYTE); |
|
649 | dummy_hk_packet.packetID[0] = (unsigned char) (APID_TM_HK >> SHIFT_1_BYTE); | |
650 | dummy_hk_packet.packetID[1] = (unsigned char) (APID_TM_HK); |
|
650 | dummy_hk_packet.packetID[1] = (unsigned char) (APID_TM_HK); | |
651 | dummy_hk_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE; |
|
651 | dummy_hk_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE; | |
652 | dummy_hk_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT; |
|
652 | dummy_hk_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT; | |
653 | dummy_hk_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> SHIFT_1_BYTE); |
|
653 | dummy_hk_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> SHIFT_1_BYTE); | |
654 | dummy_hk_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK ); |
|
654 | dummy_hk_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK ); | |
655 | dummy_hk_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; |
|
655 | dummy_hk_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; | |
656 | dummy_hk_packet.serviceType = TM_TYPE_HK; |
|
656 | dummy_hk_packet.serviceType = TM_TYPE_HK; | |
657 | dummy_hk_packet.serviceSubType = TM_SUBTYPE_HK; |
|
657 | dummy_hk_packet.serviceSubType = TM_SUBTYPE_HK; | |
658 | dummy_hk_packet.destinationID = TM_DESTINATION_ID_GROUND; |
|
658 | dummy_hk_packet.destinationID = TM_DESTINATION_ID_GROUND; | |
659 | dummy_hk_packet.time[0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES); |
|
659 | dummy_hk_packet.time[0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES); | |
660 | dummy_hk_packet.time[1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES); |
|
660 | dummy_hk_packet.time[1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES); | |
661 | dummy_hk_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE); |
|
661 | dummy_hk_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE); | |
662 | dummy_hk_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time); |
|
662 | dummy_hk_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time); | |
663 | dummy_hk_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE); |
|
663 | dummy_hk_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE); | |
664 | dummy_hk_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time); |
|
664 | dummy_hk_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time); | |
665 | dummy_hk_packet.sid = SID_HK; |
|
665 | dummy_hk_packet.sid = SID_HK; | |
666 |
|
666 | |||
667 | // init status word |
|
667 | // init status word | |
668 | dummy_hk_packet.lfr_status_word[0] = INT8_ALL_F; |
|
668 | dummy_hk_packet.lfr_status_word[0] = INT8_ALL_F; | |
669 | dummy_hk_packet.lfr_status_word[1] = INT8_ALL_F; |
|
669 | dummy_hk_packet.lfr_status_word[1] = INT8_ALL_F; | |
670 | // init software version |
|
670 | // init software version | |
671 | dummy_hk_packet.lfr_sw_version[0] = SW_VERSION_N1; |
|
671 | dummy_hk_packet.lfr_sw_version[0] = SW_VERSION_N1; | |
672 | dummy_hk_packet.lfr_sw_version[1] = SW_VERSION_N2; |
|
672 | dummy_hk_packet.lfr_sw_version[1] = SW_VERSION_N2; | |
673 | dummy_hk_packet.lfr_sw_version[BYTE_2] = SW_VERSION_N3; |
|
673 | dummy_hk_packet.lfr_sw_version[BYTE_2] = SW_VERSION_N3; | |
674 | dummy_hk_packet.lfr_sw_version[BYTE_3] = SW_VERSION_N4; |
|
674 | dummy_hk_packet.lfr_sw_version[BYTE_3] = SW_VERSION_N4; | |
675 | // init fpga version |
|
675 | // init fpga version | |
676 | parameters = (unsigned char *) (REGS_ADDR_WAVEFORM_PICKER + APB_OFFSET_VHDL_REV); |
|
676 | parameters = (unsigned char *) (REGS_ADDR_WAVEFORM_PICKER + APB_OFFSET_VHDL_REV); | |
677 | dummy_hk_packet.lfr_fpga_version[BYTE_0] = parameters[BYTE_1]; // n1 |
|
677 | dummy_hk_packet.lfr_fpga_version[BYTE_0] = parameters[BYTE_1]; // n1 | |
678 | dummy_hk_packet.lfr_fpga_version[BYTE_1] = parameters[BYTE_2]; // n2 |
|
678 | dummy_hk_packet.lfr_fpga_version[BYTE_1] = parameters[BYTE_2]; // n2 | |
679 | dummy_hk_packet.lfr_fpga_version[BYTE_2] = parameters[BYTE_3]; // n3 |
|
679 | dummy_hk_packet.lfr_fpga_version[BYTE_2] = parameters[BYTE_3]; // n3 | |
680 |
|
680 | |||
681 | parameters = (unsigned char *) &dummy_hk_packet.hk_lfr_cpu_load; |
|
681 | parameters = (unsigned char *) &dummy_hk_packet.hk_lfr_cpu_load; | |
682 |
|
682 | |||
683 | for (i=0; i<(BYTE_POS_HK_REACTION_WHEELS_FREQUENCY - BYTE_POS_HK_LFR_CPU_LOAD); i++) |
|
683 | for (i=0; i<(BYTE_POS_HK_REACTION_WHEELS_FREQUENCY - BYTE_POS_HK_LFR_CPU_LOAD); i++) | |
684 | { |
|
684 | { | |
685 | parameters[i] = INT8_ALL_F; |
|
685 | parameters[i] = INT8_ALL_F; | |
686 | } |
|
686 | } | |
687 |
|
687 | |||
688 | get_message_queue_id_send( &queue_id ); |
|
688 | get_message_queue_id_send( &queue_id ); | |
689 |
|
689 | |||
690 | rtems_message_queue_send( queue_id, &dummy_hk_packet, |
|
690 | rtems_message_queue_send( queue_id, &dummy_hk_packet, | |
691 | PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES); |
|
691 | PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES); | |
692 | } |
|
692 | } | |
693 |
|
693 | |||
694 | void get_temperatures( unsigned char *temperatures ) |
|
694 | void get_temperatures( unsigned char *temperatures ) | |
695 | { |
|
695 | { | |
696 | unsigned char* temp_scm_ptr; |
|
696 | unsigned char* temp_scm_ptr; | |
697 | unsigned char* temp_pcb_ptr; |
|
697 | unsigned char* temp_pcb_ptr; | |
698 | unsigned char* temp_fpga_ptr; |
|
698 | unsigned char* temp_fpga_ptr; | |
699 |
|
699 | |||
700 | // SEL1 SEL0 |
|
700 | // SEL1 SEL0 | |
701 | // 0 0 => PCB |
|
701 | // 0 0 => PCB | |
702 | // 0 1 => FPGA |
|
702 | // 0 1 => FPGA | |
703 | // 1 0 => SCM |
|
703 | // 1 0 => SCM | |
704 |
|
704 | |||
705 | temp_scm_ptr = (unsigned char *) &time_management_regs->temp_scm; |
|
705 | temp_scm_ptr = (unsigned char *) &time_management_regs->temp_scm; | |
706 | temp_pcb_ptr = (unsigned char *) &time_management_regs->temp_pcb; |
|
706 | temp_pcb_ptr = (unsigned char *) &time_management_regs->temp_pcb; | |
707 | temp_fpga_ptr = (unsigned char *) &time_management_regs->temp_fpga; |
|
707 | temp_fpga_ptr = (unsigned char *) &time_management_regs->temp_fpga; | |
708 |
|
708 | |||
709 | temperatures[ BYTE_0 ] = temp_scm_ptr[ BYTE_2 ]; |
|
709 | temperatures[ BYTE_0 ] = temp_scm_ptr[ BYTE_2 ]; | |
710 | temperatures[ BYTE_1 ] = temp_scm_ptr[ BYTE_3 ]; |
|
710 | temperatures[ BYTE_1 ] = temp_scm_ptr[ BYTE_3 ]; | |
711 | temperatures[ BYTE_2 ] = temp_pcb_ptr[ BYTE_2 ]; |
|
711 | temperatures[ BYTE_2 ] = temp_pcb_ptr[ BYTE_2 ]; | |
712 | temperatures[ BYTE_3 ] = temp_pcb_ptr[ BYTE_3 ]; |
|
712 | temperatures[ BYTE_3 ] = temp_pcb_ptr[ BYTE_3 ]; | |
713 | temperatures[ BYTE_4 ] = temp_fpga_ptr[ BYTE_2 ]; |
|
713 | temperatures[ BYTE_4 ] = temp_fpga_ptr[ BYTE_2 ]; | |
714 | temperatures[ BYTE_5 ] = temp_fpga_ptr[ BYTE_3 ]; |
|
714 | temperatures[ BYTE_5 ] = temp_fpga_ptr[ BYTE_3 ]; | |
715 | } |
|
715 | } | |
716 |
|
716 | |||
717 | void get_v_e1_e2_f3( unsigned char *spacecraft_potential ) |
|
717 | void get_v_e1_e2_f3( unsigned char *spacecraft_potential ) | |
718 | { |
|
718 | { | |
719 | unsigned char* v_ptr; |
|
719 | unsigned char* v_ptr; | |
720 | unsigned char* e1_ptr; |
|
720 | unsigned char* e1_ptr; | |
721 | unsigned char* e2_ptr; |
|
721 | unsigned char* e2_ptr; | |
722 |
|
722 | |||
723 | v_ptr = (unsigned char *) &hk_lfr_sc_v_f3_as_int16; |
|
723 | v_ptr = (unsigned char *) &hk_lfr_sc_v_f3_as_int16; | |
724 | e1_ptr = (unsigned char *) &hk_lfr_sc_e1_f3_as_int16; |
|
724 | e1_ptr = (unsigned char *) &hk_lfr_sc_e1_f3_as_int16; | |
725 | e2_ptr = (unsigned char *) &hk_lfr_sc_e2_f3_as_int16; |
|
725 | e2_ptr = (unsigned char *) &hk_lfr_sc_e2_f3_as_int16; | |
726 |
|
726 | |||
727 | spacecraft_potential[BYTE_0] = v_ptr[0]; |
|
727 | spacecraft_potential[BYTE_0] = v_ptr[0]; | |
728 | spacecraft_potential[BYTE_1] = v_ptr[1]; |
|
728 | spacecraft_potential[BYTE_1] = v_ptr[1]; | |
729 | spacecraft_potential[BYTE_2] = e1_ptr[0]; |
|
729 | spacecraft_potential[BYTE_2] = e1_ptr[0]; | |
730 | spacecraft_potential[BYTE_3] = e1_ptr[1]; |
|
730 | spacecraft_potential[BYTE_3] = e1_ptr[1]; | |
731 | spacecraft_potential[BYTE_4] = e2_ptr[0]; |
|
731 | spacecraft_potential[BYTE_4] = e2_ptr[0]; | |
732 | spacecraft_potential[BYTE_5] = e2_ptr[1]; |
|
732 | spacecraft_potential[BYTE_5] = e2_ptr[1]; | |
733 | } |
|
733 | } | |
734 |
|
734 | |||
735 | void get_cpu_load( unsigned char *resource_statistics ) |
|
735 | void get_cpu_load( unsigned char *resource_statistics ) | |
736 | { |
|
736 | { | |
737 | unsigned char cpu_load; |
|
737 | unsigned char cpu_load; | |
738 |
|
738 | |||
739 | cpu_load = lfr_rtems_cpu_usage_report(); |
|
739 | cpu_load = lfr_rtems_cpu_usage_report(); | |
740 |
|
740 | |||
741 | // HK_LFR_CPU_LOAD |
|
741 | // HK_LFR_CPU_LOAD | |
742 | resource_statistics[0] = cpu_load; |
|
742 | resource_statistics[0] = cpu_load; | |
743 |
|
743 | |||
744 | // HK_LFR_CPU_LOAD_MAX |
|
744 | // HK_LFR_CPU_LOAD_MAX | |
745 | if (cpu_load > resource_statistics[1]) |
|
745 | if (cpu_load > resource_statistics[1]) | |
746 | { |
|
746 | { | |
747 | resource_statistics[1] = cpu_load; |
|
747 | resource_statistics[1] = cpu_load; | |
748 | } |
|
748 | } | |
749 |
|
749 | |||
750 | // CPU_LOAD_AVE |
|
750 | // CPU_LOAD_AVE | |
751 | resource_statistics[BYTE_2] = 0; |
|
751 | resource_statistics[BYTE_2] = 0; | |
752 |
|
752 | |||
753 | #ifndef PRINT_TASK_STATISTICS |
|
753 | #ifndef PRINT_TASK_STATISTICS | |
754 | rtems_cpu_usage_reset(); |
|
754 | rtems_cpu_usage_reset(); | |
755 | #endif |
|
755 | #endif | |
756 |
|
756 | |||
757 | } |
|
757 | } | |
758 |
|
758 | |||
759 | void set_hk_lfr_sc_potential_flag( bool state ) |
|
759 | void set_hk_lfr_sc_potential_flag( bool state ) | |
760 | { |
|
760 | { | |
761 | if (state == true) |
|
761 | if (state == true) | |
762 | { |
|
762 | { | |
763 | housekeeping_packet.lfr_status_word[1] = |
|
763 | housekeeping_packet.lfr_status_word[1] = | |
764 | housekeeping_packet.lfr_status_word[1] | STATUS_WORD_SC_POTENTIAL_FLAG_BIT; // [0100 0000] |
|
764 | housekeeping_packet.lfr_status_word[1] | STATUS_WORD_SC_POTENTIAL_FLAG_BIT; // [0100 0000] | |
765 | } |
|
765 | } | |
766 | else |
|
766 | else | |
767 | { |
|
767 | { | |
768 | housekeeping_packet.lfr_status_word[1] = |
|
768 | housekeeping_packet.lfr_status_word[1] = | |
769 | housekeeping_packet.lfr_status_word[1] & STATUS_WORD_SC_POTENTIAL_FLAG_MASK; // [1011 1111] |
|
769 | housekeeping_packet.lfr_status_word[1] & STATUS_WORD_SC_POTENTIAL_FLAG_MASK; // [1011 1111] | |
770 | } |
|
770 | } | |
771 | } |
|
771 | } | |
772 |
|
772 | |||
773 | void set_sy_lfr_pas_filter_enabled( bool state ) |
|
773 | void set_sy_lfr_pas_filter_enabled( bool state ) | |
774 | { |
|
774 | { | |
775 | if (state == true) |
|
775 | if (state == true) | |
776 | { |
|
776 | { | |
777 | housekeeping_packet.lfr_status_word[1] = |
|
777 | housekeeping_packet.lfr_status_word[1] = | |
778 | housekeeping_packet.lfr_status_word[1] | STATUS_WORD_PAS_FILTER_ENABLED_BIT; // [0010 0000] |
|
778 | housekeeping_packet.lfr_status_word[1] | STATUS_WORD_PAS_FILTER_ENABLED_BIT; // [0010 0000] | |
779 | } |
|
779 | } | |
780 | else |
|
780 | else | |
781 | { |
|
781 | { | |
782 | housekeeping_packet.lfr_status_word[1] = |
|
782 | housekeeping_packet.lfr_status_word[1] = | |
783 | housekeeping_packet.lfr_status_word[1] & STATUS_WORD_PAS_FILTER_ENABLED_MASK; // [1101 1111] |
|
783 | housekeeping_packet.lfr_status_word[1] & STATUS_WORD_PAS_FILTER_ENABLED_MASK; // [1101 1111] | |
784 | } |
|
784 | } | |
785 | } |
|
785 | } | |
786 |
|
786 | |||
787 | void set_sy_lfr_watchdog_enabled( bool state ) |
|
787 | void set_sy_lfr_watchdog_enabled( bool state ) | |
788 | { |
|
788 | { | |
789 | if (state == true) |
|
789 | if (state == true) | |
790 | { |
|
790 | { | |
791 | housekeeping_packet.lfr_status_word[1] = |
|
791 | housekeeping_packet.lfr_status_word[1] = | |
792 | housekeeping_packet.lfr_status_word[1] | STATUS_WORD_WATCHDOG_BIT; // [0001 0000] |
|
792 | housekeeping_packet.lfr_status_word[1] | STATUS_WORD_WATCHDOG_BIT; // [0001 0000] | |
793 | } |
|
793 | } | |
794 | else |
|
794 | else | |
795 | { |
|
795 | { | |
796 | housekeeping_packet.lfr_status_word[1] = |
|
796 | housekeeping_packet.lfr_status_word[1] = | |
797 | housekeeping_packet.lfr_status_word[1] & STATUS_WORD_WATCHDOG_MASK; // [1110 1111] |
|
797 | housekeeping_packet.lfr_status_word[1] & STATUS_WORD_WATCHDOG_MASK; // [1110 1111] | |
798 | } |
|
798 | } | |
799 | } |
|
799 | } | |
800 |
|
800 | |||
801 | void set_hk_lfr_calib_enable( bool state ) |
|
801 | void set_hk_lfr_calib_enable( bool state ) | |
802 | { |
|
802 | { | |
803 | if (state == true) |
|
803 | if (state == true) | |
804 | { |
|
804 | { | |
805 | housekeeping_packet.lfr_status_word[1] = |
|
805 | housekeeping_packet.lfr_status_word[1] = | |
806 | housekeeping_packet.lfr_status_word[1] | STATUS_WORD_CALIB_BIT; // [0000 1000] |
|
806 | housekeeping_packet.lfr_status_word[1] | STATUS_WORD_CALIB_BIT; // [0000 1000] | |
807 | } |
|
807 | } | |
808 | else |
|
808 | else | |
809 | { |
|
809 | { | |
810 | housekeeping_packet.lfr_status_word[1] = |
|
810 | housekeeping_packet.lfr_status_word[1] = | |
811 | housekeeping_packet.lfr_status_word[1] & STATUS_WORD_CALIB_MASK; // [1111 0111] |
|
811 | housekeeping_packet.lfr_status_word[1] & STATUS_WORD_CALIB_MASK; // [1111 0111] | |
812 | } |
|
812 | } | |
813 | } |
|
813 | } | |
814 |
|
814 | |||
815 | void set_hk_lfr_reset_cause( enum lfr_reset_cause_t lfr_reset_cause ) |
|
815 | void set_hk_lfr_reset_cause( enum lfr_reset_cause_t lfr_reset_cause ) | |
816 | { |
|
816 | { | |
817 | housekeeping_packet.lfr_status_word[1] = |
|
817 | housekeeping_packet.lfr_status_word[1] = | |
818 | housekeeping_packet.lfr_status_word[1] & STATUS_WORD_RESET_CAUSE_MASK; // [1111 1000] |
|
818 | housekeeping_packet.lfr_status_word[1] & STATUS_WORD_RESET_CAUSE_MASK; // [1111 1000] | |
819 |
|
819 | |||
820 | housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] |
|
820 | housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] | |
821 | | (lfr_reset_cause & STATUS_WORD_RESET_CAUSE_BITS ); // [0000 0111] |
|
821 | | (lfr_reset_cause & STATUS_WORD_RESET_CAUSE_BITS ); // [0000 0111] | |
822 |
|
822 | |||
823 | } |
|
823 | } | |
824 |
|
824 | |||
825 | void increment_hk_counter( unsigned char newValue, unsigned char oldValue, unsigned int *counter ) |
|
825 | void increment_hk_counter( unsigned char newValue, unsigned char oldValue, unsigned int *counter ) | |
826 | { |
|
826 | { | |
827 | int delta; |
|
827 | int delta; | |
828 |
|
828 | |||
829 | delta = 0; |
|
829 | delta = 0; | |
830 |
|
830 | |||
831 | if (newValue >= oldValue) |
|
831 | if (newValue >= oldValue) | |
832 | { |
|
832 | { | |
833 | delta = newValue - oldValue; |
|
833 | delta = newValue - oldValue; | |
834 | } |
|
834 | } | |
835 | else |
|
835 | else | |
836 | { |
|
836 | { | |
837 | delta = (CONST_256 - oldValue) + newValue; |
|
837 | delta = (CONST_256 - oldValue) + newValue; | |
838 | } |
|
838 | } | |
839 |
|
839 | |||
840 | *counter = *counter + delta; |
|
840 | *counter = *counter + delta; | |
841 | } |
|
841 | } | |
842 |
|
842 | |||
843 | void hk_lfr_le_update( void ) |
|
843 | void hk_lfr_le_update( void ) | |
844 | { |
|
844 | { | |
845 | static hk_lfr_le_t old_hk_lfr_le = {0}; |
|
845 | static hk_lfr_le_t old_hk_lfr_le = {0}; | |
846 | hk_lfr_le_t new_hk_lfr_le; |
|
846 | hk_lfr_le_t new_hk_lfr_le; | |
847 | unsigned int counter; |
|
847 | unsigned int counter; | |
848 |
|
848 | |||
849 | counter = (((unsigned int) housekeeping_packet.hk_lfr_le_cnt[0]) * CONST_256) + housekeeping_packet.hk_lfr_le_cnt[1]; |
|
849 | counter = (((unsigned int) housekeeping_packet.hk_lfr_le_cnt[0]) * CONST_256) + housekeeping_packet.hk_lfr_le_cnt[1]; | |
850 |
|
850 | |||
851 | // DPU |
|
851 | // DPU | |
852 | new_hk_lfr_le.dpu_spw_parity = housekeeping_packet.hk_lfr_dpu_spw_parity; |
|
852 | new_hk_lfr_le.dpu_spw_parity = housekeeping_packet.hk_lfr_dpu_spw_parity; | |
853 | new_hk_lfr_le.dpu_spw_disconnect= housekeeping_packet.hk_lfr_dpu_spw_disconnect; |
|
853 | new_hk_lfr_le.dpu_spw_disconnect= housekeeping_packet.hk_lfr_dpu_spw_disconnect; | |
854 | new_hk_lfr_le.dpu_spw_escape = housekeeping_packet.hk_lfr_dpu_spw_escape; |
|
854 | new_hk_lfr_le.dpu_spw_escape = housekeeping_packet.hk_lfr_dpu_spw_escape; | |
855 | new_hk_lfr_le.dpu_spw_credit = housekeeping_packet.hk_lfr_dpu_spw_credit; |
|
855 | new_hk_lfr_le.dpu_spw_credit = housekeeping_packet.hk_lfr_dpu_spw_credit; | |
856 | new_hk_lfr_le.dpu_spw_write_sync= housekeeping_packet.hk_lfr_dpu_spw_write_sync; |
|
856 | new_hk_lfr_le.dpu_spw_write_sync= housekeeping_packet.hk_lfr_dpu_spw_write_sync; | |
857 | // TIMECODE |
|
857 | // TIMECODE | |
858 | new_hk_lfr_le.timecode_erroneous= housekeeping_packet.hk_lfr_timecode_erroneous; |
|
858 | new_hk_lfr_le.timecode_erroneous= housekeeping_packet.hk_lfr_timecode_erroneous; | |
859 | new_hk_lfr_le.timecode_missing = housekeeping_packet.hk_lfr_timecode_missing; |
|
859 | new_hk_lfr_le.timecode_missing = housekeeping_packet.hk_lfr_timecode_missing; | |
860 | new_hk_lfr_le.timecode_invalid = housekeeping_packet.hk_lfr_timecode_invalid; |
|
860 | new_hk_lfr_le.timecode_invalid = housekeeping_packet.hk_lfr_timecode_invalid; | |
861 | // TIME |
|
861 | // TIME | |
862 | new_hk_lfr_le.time_timecode_it = housekeeping_packet.hk_lfr_time_timecode_it; |
|
862 | new_hk_lfr_le.time_timecode_it = housekeeping_packet.hk_lfr_time_timecode_it; | |
863 | new_hk_lfr_le.time_not_synchro = housekeeping_packet.hk_lfr_time_not_synchro; |
|
863 | new_hk_lfr_le.time_not_synchro = housekeeping_packet.hk_lfr_time_not_synchro; | |
864 | new_hk_lfr_le.time_timecode_ctr = housekeeping_packet.hk_lfr_time_timecode_ctr; |
|
864 | new_hk_lfr_le.time_timecode_ctr = housekeeping_packet.hk_lfr_time_timecode_ctr; | |
865 | //AHB |
|
865 | //AHB | |
866 | new_hk_lfr_le.ahb_correctable = housekeeping_packet.hk_lfr_ahb_correctable; |
|
866 | new_hk_lfr_le.ahb_correctable = housekeeping_packet.hk_lfr_ahb_correctable; | |
867 | // housekeeping_packet.hk_lfr_dpu_spw_rx_ahb => not handled by the grspw driver |
|
867 | // housekeeping_packet.hk_lfr_dpu_spw_rx_ahb => not handled by the grspw driver | |
868 | // housekeeping_packet.hk_lfr_dpu_spw_tx_ahb => not handled by the grspw driver |
|
868 | // housekeeping_packet.hk_lfr_dpu_spw_tx_ahb => not handled by the grspw driver | |
869 |
|
869 | |||
870 | // update the le counter |
|
870 | // update the le counter | |
871 | // DPU |
|
871 | // DPU | |
872 | increment_hk_counter( new_hk_lfr_le.dpu_spw_parity, old_hk_lfr_le.dpu_spw_parity, &counter ); |
|
872 | increment_hk_counter( new_hk_lfr_le.dpu_spw_parity, old_hk_lfr_le.dpu_spw_parity, &counter ); | |
873 | increment_hk_counter( new_hk_lfr_le.dpu_spw_disconnect,old_hk_lfr_le.dpu_spw_disconnect, &counter ); |
|
873 | increment_hk_counter( new_hk_lfr_le.dpu_spw_disconnect,old_hk_lfr_le.dpu_spw_disconnect, &counter ); | |
874 | increment_hk_counter( new_hk_lfr_le.dpu_spw_escape, old_hk_lfr_le.dpu_spw_escape, &counter ); |
|
874 | increment_hk_counter( new_hk_lfr_le.dpu_spw_escape, old_hk_lfr_le.dpu_spw_escape, &counter ); | |
875 | increment_hk_counter( new_hk_lfr_le.dpu_spw_credit, old_hk_lfr_le.dpu_spw_credit, &counter ); |
|
875 | increment_hk_counter( new_hk_lfr_le.dpu_spw_credit, old_hk_lfr_le.dpu_spw_credit, &counter ); | |
876 | increment_hk_counter( new_hk_lfr_le.dpu_spw_write_sync,old_hk_lfr_le.dpu_spw_write_sync, &counter ); |
|
876 | increment_hk_counter( new_hk_lfr_le.dpu_spw_write_sync,old_hk_lfr_le.dpu_spw_write_sync, &counter ); | |
877 | // TIMECODE |
|
877 | // TIMECODE | |
878 | increment_hk_counter( new_hk_lfr_le.timecode_erroneous,old_hk_lfr_le.timecode_erroneous, &counter ); |
|
878 | increment_hk_counter( new_hk_lfr_le.timecode_erroneous,old_hk_lfr_le.timecode_erroneous, &counter ); | |
879 | increment_hk_counter( new_hk_lfr_le.timecode_missing, old_hk_lfr_le.timecode_missing, &counter ); |
|
879 | increment_hk_counter( new_hk_lfr_le.timecode_missing, old_hk_lfr_le.timecode_missing, &counter ); | |
880 | increment_hk_counter( new_hk_lfr_le.timecode_invalid, old_hk_lfr_le.timecode_invalid, &counter ); |
|
880 | increment_hk_counter( new_hk_lfr_le.timecode_invalid, old_hk_lfr_le.timecode_invalid, &counter ); | |
881 | // TIME |
|
881 | // TIME | |
882 | increment_hk_counter( new_hk_lfr_le.time_timecode_it, old_hk_lfr_le.time_timecode_it, &counter ); |
|
882 | increment_hk_counter( new_hk_lfr_le.time_timecode_it, old_hk_lfr_le.time_timecode_it, &counter ); | |
883 | increment_hk_counter( new_hk_lfr_le.time_not_synchro, old_hk_lfr_le.time_not_synchro, &counter ); |
|
883 | increment_hk_counter( new_hk_lfr_le.time_not_synchro, old_hk_lfr_le.time_not_synchro, &counter ); | |
884 | increment_hk_counter( new_hk_lfr_le.time_timecode_ctr, old_hk_lfr_le.time_timecode_ctr, &counter ); |
|
884 | increment_hk_counter( new_hk_lfr_le.time_timecode_ctr, old_hk_lfr_le.time_timecode_ctr, &counter ); | |
885 | // AHB |
|
885 | // AHB | |
886 | increment_hk_counter( new_hk_lfr_le.ahb_correctable, old_hk_lfr_le.ahb_correctable, &counter ); |
|
886 | increment_hk_counter( new_hk_lfr_le.ahb_correctable, old_hk_lfr_le.ahb_correctable, &counter ); | |
887 |
|
887 | |||
888 | // DPU |
|
888 | // DPU | |
889 | old_hk_lfr_le.dpu_spw_parity = new_hk_lfr_le.dpu_spw_parity; |
|
889 | old_hk_lfr_le.dpu_spw_parity = new_hk_lfr_le.dpu_spw_parity; | |
890 | old_hk_lfr_le.dpu_spw_disconnect= new_hk_lfr_le.dpu_spw_disconnect; |
|
890 | old_hk_lfr_le.dpu_spw_disconnect= new_hk_lfr_le.dpu_spw_disconnect; | |
891 | old_hk_lfr_le.dpu_spw_escape = new_hk_lfr_le.dpu_spw_escape; |
|
891 | old_hk_lfr_le.dpu_spw_escape = new_hk_lfr_le.dpu_spw_escape; | |
892 | old_hk_lfr_le.dpu_spw_credit = new_hk_lfr_le.dpu_spw_credit; |
|
892 | old_hk_lfr_le.dpu_spw_credit = new_hk_lfr_le.dpu_spw_credit; | |
893 | old_hk_lfr_le.dpu_spw_write_sync= new_hk_lfr_le.dpu_spw_write_sync; |
|
893 | old_hk_lfr_le.dpu_spw_write_sync= new_hk_lfr_le.dpu_spw_write_sync; | |
894 | // TIMECODE |
|
894 | // TIMECODE | |
895 | old_hk_lfr_le.timecode_erroneous= new_hk_lfr_le.timecode_erroneous; |
|
895 | old_hk_lfr_le.timecode_erroneous= new_hk_lfr_le.timecode_erroneous; | |
896 | old_hk_lfr_le.timecode_missing = new_hk_lfr_le.timecode_missing; |
|
896 | old_hk_lfr_le.timecode_missing = new_hk_lfr_le.timecode_missing; | |
897 | old_hk_lfr_le.timecode_invalid = new_hk_lfr_le.timecode_invalid; |
|
897 | old_hk_lfr_le.timecode_invalid = new_hk_lfr_le.timecode_invalid; | |
898 | // TIME |
|
898 | // TIME | |
899 | old_hk_lfr_le.time_timecode_it = new_hk_lfr_le.time_timecode_it; |
|
899 | old_hk_lfr_le.time_timecode_it = new_hk_lfr_le.time_timecode_it; | |
900 | old_hk_lfr_le.time_not_synchro = new_hk_lfr_le.time_not_synchro; |
|
900 | old_hk_lfr_le.time_not_synchro = new_hk_lfr_le.time_not_synchro; | |
901 | old_hk_lfr_le.time_timecode_ctr = new_hk_lfr_le.time_timecode_ctr; |
|
901 | old_hk_lfr_le.time_timecode_ctr = new_hk_lfr_le.time_timecode_ctr; | |
902 | //AHB |
|
902 | //AHB | |
903 | old_hk_lfr_le.ahb_correctable = new_hk_lfr_le.ahb_correctable; |
|
903 | old_hk_lfr_le.ahb_correctable = new_hk_lfr_le.ahb_correctable; | |
904 | // housekeeping_packet.hk_lfr_dpu_spw_rx_ahb => not handled by the grspw driver |
|
904 | // housekeeping_packet.hk_lfr_dpu_spw_rx_ahb => not handled by the grspw driver | |
905 | // housekeeping_packet.hk_lfr_dpu_spw_tx_ahb => not handled by the grspw driver |
|
905 | // housekeeping_packet.hk_lfr_dpu_spw_tx_ahb => not handled by the grspw driver | |
906 |
|
906 | |||
907 | // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers |
|
907 | // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers | |
908 | // LE |
|
908 | // LE | |
909 | housekeeping_packet.hk_lfr_le_cnt[0] = (unsigned char) ((counter & BYTE0_MASK) >> SHIFT_1_BYTE); |
|
909 | housekeeping_packet.hk_lfr_le_cnt[0] = (unsigned char) ((counter & BYTE0_MASK) >> SHIFT_1_BYTE); | |
910 | housekeeping_packet.hk_lfr_le_cnt[1] = (unsigned char) (counter & BYTE1_MASK); |
|
910 | housekeeping_packet.hk_lfr_le_cnt[1] = (unsigned char) (counter & BYTE1_MASK); | |
911 | } |
|
911 | } | |
912 |
|
912 | |||
913 | void hk_lfr_me_update( void ) |
|
913 | void hk_lfr_me_update( void ) | |
914 | { |
|
914 | { | |
915 | static hk_lfr_me_t old_hk_lfr_me = {0}; |
|
915 | static hk_lfr_me_t old_hk_lfr_me = {0}; | |
916 | hk_lfr_me_t new_hk_lfr_me; |
|
916 | hk_lfr_me_t new_hk_lfr_me; | |
917 | unsigned int counter; |
|
917 | unsigned int counter; | |
918 |
|
918 | |||
919 | counter = (((unsigned int) housekeeping_packet.hk_lfr_me_cnt[0]) * CONST_256) + housekeeping_packet.hk_lfr_me_cnt[1]; |
|
919 | counter = (((unsigned int) housekeeping_packet.hk_lfr_me_cnt[0]) * CONST_256) + housekeeping_packet.hk_lfr_me_cnt[1]; | |
920 |
|
920 | |||
921 | // get the current values |
|
921 | // get the current values | |
922 | new_hk_lfr_me.dpu_spw_early_eop = housekeeping_packet.hk_lfr_dpu_spw_early_eop; |
|
922 | new_hk_lfr_me.dpu_spw_early_eop = housekeeping_packet.hk_lfr_dpu_spw_early_eop; | |
923 | new_hk_lfr_me.dpu_spw_invalid_addr = housekeeping_packet.hk_lfr_dpu_spw_invalid_addr; |
|
923 | new_hk_lfr_me.dpu_spw_invalid_addr = housekeeping_packet.hk_lfr_dpu_spw_invalid_addr; | |
924 | new_hk_lfr_me.dpu_spw_eep = housekeeping_packet.hk_lfr_dpu_spw_eep; |
|
924 | new_hk_lfr_me.dpu_spw_eep = housekeeping_packet.hk_lfr_dpu_spw_eep; | |
925 | new_hk_lfr_me.dpu_spw_rx_too_big = housekeeping_packet.hk_lfr_dpu_spw_rx_too_big; |
|
925 | new_hk_lfr_me.dpu_spw_rx_too_big = housekeeping_packet.hk_lfr_dpu_spw_rx_too_big; | |
926 |
|
926 | |||
927 | // update the me counter |
|
927 | // update the me counter | |
928 | increment_hk_counter( new_hk_lfr_me.dpu_spw_early_eop, old_hk_lfr_me.dpu_spw_early_eop, &counter ); |
|
928 | increment_hk_counter( new_hk_lfr_me.dpu_spw_early_eop, old_hk_lfr_me.dpu_spw_early_eop, &counter ); | |
929 | increment_hk_counter( new_hk_lfr_me.dpu_spw_invalid_addr, old_hk_lfr_me.dpu_spw_invalid_addr, &counter ); |
|
929 | increment_hk_counter( new_hk_lfr_me.dpu_spw_invalid_addr, old_hk_lfr_me.dpu_spw_invalid_addr, &counter ); | |
930 | increment_hk_counter( new_hk_lfr_me.dpu_spw_eep, old_hk_lfr_me.dpu_spw_eep, &counter ); |
|
930 | increment_hk_counter( new_hk_lfr_me.dpu_spw_eep, old_hk_lfr_me.dpu_spw_eep, &counter ); | |
931 | increment_hk_counter( new_hk_lfr_me.dpu_spw_rx_too_big, old_hk_lfr_me.dpu_spw_rx_too_big, &counter ); |
|
931 | increment_hk_counter( new_hk_lfr_me.dpu_spw_rx_too_big, old_hk_lfr_me.dpu_spw_rx_too_big, &counter ); | |
932 |
|
932 | |||
933 | // store the counters for the next time |
|
933 | // store the counters for the next time | |
934 | old_hk_lfr_me.dpu_spw_early_eop = new_hk_lfr_me.dpu_spw_early_eop; |
|
934 | old_hk_lfr_me.dpu_spw_early_eop = new_hk_lfr_me.dpu_spw_early_eop; | |
935 | old_hk_lfr_me.dpu_spw_invalid_addr = new_hk_lfr_me.dpu_spw_invalid_addr; |
|
935 | old_hk_lfr_me.dpu_spw_invalid_addr = new_hk_lfr_me.dpu_spw_invalid_addr; | |
936 | old_hk_lfr_me.dpu_spw_eep = new_hk_lfr_me.dpu_spw_eep; |
|
936 | old_hk_lfr_me.dpu_spw_eep = new_hk_lfr_me.dpu_spw_eep; | |
937 | old_hk_lfr_me.dpu_spw_rx_too_big = new_hk_lfr_me.dpu_spw_rx_too_big; |
|
937 | old_hk_lfr_me.dpu_spw_rx_too_big = new_hk_lfr_me.dpu_spw_rx_too_big; | |
938 |
|
938 | |||
939 | // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers |
|
939 | // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers | |
940 | // ME |
|
940 | // ME | |
941 | housekeeping_packet.hk_lfr_me_cnt[0] = (unsigned char) ((counter & BYTE0_MASK) >> SHIFT_1_BYTE); |
|
941 | housekeeping_packet.hk_lfr_me_cnt[0] = (unsigned char) ((counter & BYTE0_MASK) >> SHIFT_1_BYTE); | |
942 | housekeeping_packet.hk_lfr_me_cnt[1] = (unsigned char) (counter & BYTE1_MASK); |
|
942 | housekeeping_packet.hk_lfr_me_cnt[1] = (unsigned char) (counter & BYTE1_MASK); | |
943 | } |
|
943 | } | |
944 |
|
944 | |||
945 | void hk_lfr_le_me_he_update() |
|
945 | void hk_lfr_le_me_he_update() | |
946 | { |
|
946 | { | |
947 |
|
947 | |||
948 | unsigned int hk_lfr_he_cnt; |
|
948 | unsigned int hk_lfr_he_cnt; | |
949 |
|
949 | |||
950 | hk_lfr_he_cnt = (((unsigned int) housekeeping_packet.hk_lfr_he_cnt[0]) * 256) + housekeeping_packet.hk_lfr_he_cnt[1]; |
|
950 | hk_lfr_he_cnt = (((unsigned int) housekeeping_packet.hk_lfr_he_cnt[0]) * 256) + housekeeping_packet.hk_lfr_he_cnt[1]; | |
951 |
|
951 | |||
952 | //update the low severity error counter |
|
952 | //update the low severity error counter | |
953 | hk_lfr_le_update( ); |
|
953 | hk_lfr_le_update( ); | |
954 |
|
954 | |||
955 | //update the medium severity error counter |
|
955 | //update the medium severity error counter | |
956 | hk_lfr_me_update(); |
|
956 | hk_lfr_me_update(); | |
957 |
|
957 | |||
958 | //update the high severity error counter |
|
958 | //update the high severity error counter | |
959 | hk_lfr_he_cnt = 0; |
|
959 | hk_lfr_he_cnt = 0; | |
960 |
|
960 | |||
961 | // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers |
|
961 | // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers | |
962 | // HE |
|
962 | // HE | |
963 | housekeeping_packet.hk_lfr_he_cnt[0] = (unsigned char) ((hk_lfr_he_cnt & BYTE0_MASK) >> SHIFT_1_BYTE); |
|
963 | housekeeping_packet.hk_lfr_he_cnt[0] = (unsigned char) ((hk_lfr_he_cnt & BYTE0_MASK) >> SHIFT_1_BYTE); | |
964 | housekeeping_packet.hk_lfr_he_cnt[1] = (unsigned char) (hk_lfr_he_cnt & BYTE1_MASK); |
|
964 | housekeeping_packet.hk_lfr_he_cnt[1] = (unsigned char) (hk_lfr_he_cnt & BYTE1_MASK); | |
965 |
|
965 | |||
966 | } |
|
966 | } | |
967 |
|
967 | |||
968 | void set_hk_lfr_time_not_synchro() |
|
968 | void set_hk_lfr_time_not_synchro() | |
969 | { |
|
969 | { | |
970 | static unsigned char synchroLost = 1; |
|
970 | static unsigned char synchroLost = 1; | |
971 | int synchronizationBit; |
|
971 | int synchronizationBit; | |
972 |
|
972 | |||
973 | // get the synchronization bit |
|
973 | // get the synchronization bit | |
974 | synchronizationBit = |
|
974 | synchronizationBit = | |
975 | (time_management_regs->coarse_time & VAL_LFR_SYNCHRONIZED) >> BIT_SYNCHRONIZATION; // 1000 0000 0000 0000 |
|
975 | (time_management_regs->coarse_time & VAL_LFR_SYNCHRONIZED) >> BIT_SYNCHRONIZATION; // 1000 0000 0000 0000 | |
976 |
|
976 | |||
977 | switch (synchronizationBit) |
|
977 | switch (synchronizationBit) | |
978 | { |
|
978 | { | |
979 | case 0: |
|
979 | case 0: | |
980 | if (synchroLost == 1) |
|
980 | if (synchroLost == 1) | |
981 | { |
|
981 | { | |
982 | synchroLost = 0; |
|
982 | synchroLost = 0; | |
983 | } |
|
983 | } | |
984 | break; |
|
984 | break; | |
985 | case 1: |
|
985 | case 1: | |
986 | if (synchroLost == 0 ) |
|
986 | if (synchroLost == 0 ) | |
987 | { |
|
987 | { | |
988 | synchroLost = 1; |
|
988 | synchroLost = 1; | |
989 | increase_unsigned_char_counter(&housekeeping_packet.hk_lfr_time_not_synchro); |
|
989 | increase_unsigned_char_counter(&housekeeping_packet.hk_lfr_time_not_synchro); | |
990 | update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_NOT_SYNCHRO ); |
|
990 | update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_NOT_SYNCHRO ); | |
991 | } |
|
991 | } | |
992 | break; |
|
992 | break; | |
993 | default: |
|
993 | default: | |
994 | PRINTF1("in hk_lfr_time_not_synchro *** unexpected value for synchronizationBit = %d\n", synchronizationBit); |
|
994 | PRINTF1("in hk_lfr_time_not_synchro *** unexpected value for synchronizationBit = %d\n", synchronizationBit); | |
995 | break; |
|
995 | break; | |
996 | } |
|
996 | } | |
997 |
|
997 | |||
998 | } |
|
998 | } | |
999 |
|
999 | |||
1000 | void set_hk_lfr_ahb_correctable() // CRITICITY L |
|
1000 | void set_hk_lfr_ahb_correctable() // CRITICITY L | |
1001 | { |
|
1001 | { | |
1002 | /** This function builds the error counter hk_lfr_ahb_correctable using the statistics provided |
|
1002 | /** This function builds the error counter hk_lfr_ahb_correctable using the statistics provided | |
1003 | * by the Cache Control Register (ASI 2, offset 0) and in the Register Protection Control Register (ASR16) on the |
|
1003 | * by the Cache Control Register (ASI 2, offset 0) and in the Register Protection Control Register (ASR16) on the | |
1004 | * detected errors in the cache, in the integer unit and in the floating point unit. |
|
1004 | * detected errors in the cache, in the integer unit and in the floating point unit. | |
1005 | * |
|
1005 | * | |
1006 | * @param void |
|
1006 | * @param void | |
1007 | * |
|
1007 | * | |
1008 | * @return void |
|
1008 | * @return void | |
1009 | * |
|
1009 | * | |
1010 | * All errors are summed to set the value of the hk_lfr_ahb_correctable counter. |
|
1010 | * All errors are summed to set the value of the hk_lfr_ahb_correctable counter. | |
1011 | * |
|
1011 | * | |
1012 | */ |
|
1012 | */ | |
1013 |
|
1013 | |||
1014 | unsigned int ahb_correctable; |
|
1014 | unsigned int ahb_correctable; | |
1015 | unsigned int instructionErrorCounter; |
|
1015 | unsigned int instructionErrorCounter; | |
1016 | unsigned int dataErrorCounter; |
|
1016 | unsigned int dataErrorCounter; | |
1017 | unsigned int fprfErrorCounter; |
|
1017 | unsigned int fprfErrorCounter; | |
1018 | unsigned int iurfErrorCounter; |
|
1018 | unsigned int iurfErrorCounter; | |
1019 |
|
1019 | |||
1020 | instructionErrorCounter = 0; |
|
1020 | instructionErrorCounter = 0; | |
1021 | dataErrorCounter = 0; |
|
1021 | dataErrorCounter = 0; | |
1022 | fprfErrorCounter = 0; |
|
1022 | fprfErrorCounter = 0; | |
1023 | iurfErrorCounter = 0; |
|
1023 | iurfErrorCounter = 0; | |
1024 |
|
1024 | |||
1025 | CCR_getInstructionAndDataErrorCounters( &instructionErrorCounter, &dataErrorCounter); |
|
1025 | CCR_getInstructionAndDataErrorCounters( &instructionErrorCounter, &dataErrorCounter); | |
1026 | ASR16_get_FPRF_IURF_ErrorCounters( &fprfErrorCounter, &iurfErrorCounter); |
|
1026 | ASR16_get_FPRF_IURF_ErrorCounters( &fprfErrorCounter, &iurfErrorCounter); | |
1027 |
|
1027 | |||
1028 | ahb_correctable = instructionErrorCounter |
|
1028 | ahb_correctable = instructionErrorCounter | |
1029 | + dataErrorCounter |
|
1029 | + dataErrorCounter | |
1030 | + fprfErrorCounter |
|
1030 | + fprfErrorCounter | |
1031 | + iurfErrorCounter |
|
1031 | + iurfErrorCounter | |
1032 | + housekeeping_packet.hk_lfr_ahb_correctable; |
|
1032 | + housekeeping_packet.hk_lfr_ahb_correctable; | |
1033 |
|
1033 | |||
1034 | housekeeping_packet.hk_lfr_ahb_correctable = (unsigned char) (ahb_correctable & INT8_ALL_F); // [1111 1111] |
|
1034 | housekeeping_packet.hk_lfr_ahb_correctable = (unsigned char) (ahb_correctable & INT8_ALL_F); // [1111 1111] | |
1035 |
|
1035 | |||
1036 | } |
|
1036 | } |
@@ -1,1343 +1,1343 | |||||
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]= {0}; |
|
15 | ring_node waveform_ring_f0[NB_RING_NODES_F0]= {0}; | |
16 | ring_node *current_ring_node_f0 = NULL; |
|
16 | ring_node *current_ring_node_f0 = NULL; | |
17 | ring_node *ring_node_to_send_swf_f0 = NULL; |
|
17 | ring_node *ring_node_to_send_swf_f0 = NULL; | |
18 | // F1 |
|
18 | // F1 | |
19 | ring_node waveform_ring_f1[NB_RING_NODES_F1] = {0}; |
|
19 | ring_node waveform_ring_f1[NB_RING_NODES_F1] = {0}; | |
20 | ring_node *current_ring_node_f1 = NULL; |
|
20 | ring_node *current_ring_node_f1 = NULL; | |
21 | ring_node *ring_node_to_send_swf_f1 = NULL; |
|
21 | ring_node *ring_node_to_send_swf_f1 = NULL; | |
22 | ring_node *ring_node_to_send_cwf_f1 = NULL; |
|
22 | ring_node *ring_node_to_send_cwf_f1 = NULL; | |
23 | // F2 |
|
23 | // F2 | |
24 | ring_node waveform_ring_f2[NB_RING_NODES_F2] = {0}; |
|
24 | ring_node waveform_ring_f2[NB_RING_NODES_F2] = {0}; | |
25 | ring_node *current_ring_node_f2 = NULL; |
|
25 | ring_node *current_ring_node_f2 = NULL; | |
26 | ring_node *ring_node_to_send_swf_f2 = NULL; |
|
26 | ring_node *ring_node_to_send_swf_f2 = NULL; | |
27 | ring_node *ring_node_to_send_cwf_f2 = NULL; |
|
27 | ring_node *ring_node_to_send_cwf_f2 = NULL; | |
28 | // F3 |
|
28 | // F3 | |
29 | ring_node waveform_ring_f3[NB_RING_NODES_F3] = {0}; |
|
29 | ring_node waveform_ring_f3[NB_RING_NODES_F3] = {0}; | |
30 | ring_node *current_ring_node_f3 = NULL; |
|
30 | ring_node *current_ring_node_f3 = NULL; | |
31 | ring_node *ring_node_to_send_cwf_f3 = NULL; |
|
31 | ring_node *ring_node_to_send_cwf_f3 = NULL; | |
32 | char wf_cont_f3_light[ (NB_SAMPLES_PER_SNAPSHOT) * NB_BYTES_CWF3_LIGHT_BLK ] = {0}; |
|
32 | char wf_cont_f3_light[ (NB_SAMPLES_PER_SNAPSHOT) * NB_BYTES_CWF3_LIGHT_BLK ] = {0}; | |
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) ] = {0}; |
|
41 | int swf1_extracted[ (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK) ] = {0}; | |
42 | int swf2_extracted[ (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK) ] = {0}; |
|
42 | int swf2_extracted[ (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK) ] = {0}; | |
43 | ring_node ring_node_swf1_extracted = {0}; |
|
43 | ring_node ring_node_swf1_extracted = {0}; | |
44 | ring_node ring_node_swf2_extracted = {0}; |
|
44 | ring_node ring_node_swf2_extracted = {0}; | |
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 CHANNELF1: |
|
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 CHANNELF2: |
|
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 CHANNELF3: |
|
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 CHANNELF0: |
|
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 CHANNELF1: |
|
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 CHANNELF2: |
|
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 & BITS_WFP_STATUS_F3) != INIT_CHAR ) { // [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 & BIT_WFP_BUF_F3_0) == BIT_WFP_BUF_F3_0){ // [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 & RST_WFP_F3_0; // [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 & BIT_WFP_BUF_F3_1) == BIT_WFP_BUF_F3_1){ // [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 & RST_WFP_F3_1; // [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 & BITS_WFP_STATUS_F2) >> SHIFT_WFP_STATUS_F2; // [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 |
|
146 | |||
147 | switch(status) |
|
147 | switch(status) | |
148 | { |
|
148 | { | |
149 | case BIT_WFP_BUFFER_0: |
|
149 | case BIT_WFP_BUFFER_0: | |
150 | ring_node_to_send_cwf_f2 = current_ring_node_f2->previous; |
|
150 | ring_node_to_send_cwf_f2 = current_ring_node_f2->previous; | |
151 | ring_node_to_send_cwf_f2->sid = SID_BURST_CWF_F2; |
|
151 | ring_node_to_send_cwf_f2->sid = SID_BURST_CWF_F2; | |
152 | 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; | |
153 | 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; | |
154 | current_ring_node_f2 = current_ring_node_f2->next; |
|
154 | current_ring_node_f2 = current_ring_node_f2->next; | |
155 | 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; | |
156 | 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) { | |
157 | 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 ); | |
158 | } |
|
158 | } | |
159 | waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F2_0; // [0100 0100 0001 0000] |
|
159 | waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F2_0; // [0100 0100 0001 0000] | |
160 | break; |
|
160 | break; | |
161 | case BIT_WFP_BUFFER_1: |
|
161 | case BIT_WFP_BUFFER_1: | |
162 | ring_node_to_send_cwf_f2 = current_ring_node_f2->previous; |
|
162 | ring_node_to_send_cwf_f2 = current_ring_node_f2->previous; | |
163 | ring_node_to_send_cwf_f2->sid = SID_BURST_CWF_F2; |
|
163 | ring_node_to_send_cwf_f2->sid = SID_BURST_CWF_F2; | |
164 | 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; | |
165 | 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; | |
166 | current_ring_node_f2 = current_ring_node_f2->next; |
|
166 | current_ring_node_f2 = current_ring_node_f2->next; | |
167 | 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; | |
168 | 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) { | |
169 | 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 ); | |
170 | } |
|
170 | } | |
171 | waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F2_1; // [0100 0100 0010 0000] |
|
171 | waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F2_1; // [0100 0100 0010 0000] | |
172 | break; |
|
172 | break; | |
173 | default: |
|
173 | default: | |
174 | break; |
|
174 | break; | |
175 | } |
|
175 | } | |
176 | } |
|
176 | } | |
177 |
|
177 | |||
178 | inline void waveform_isr_normal_sbm1_sbm2( void ) |
|
178 | inline void waveform_isr_normal_sbm1_sbm2( void ) | |
179 | { |
|
179 | { | |
180 | rtems_status_code status; |
|
180 | rtems_status_code status; | |
181 |
|
181 | |||
182 | //*** |
|
182 | //*** | |
183 | // F0 |
|
183 | // F0 | |
184 | if ( (waveform_picker_regs->status & BITS_WFP_STATUS_F0) != INIT_CHAR ) // [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 | |
185 | { |
|
185 | { | |
186 | swf0_ready_flag_f1 = true; |
|
186 | swf0_ready_flag_f1 = true; | |
187 | swf0_ready_flag_f2 = true; |
|
187 | swf0_ready_flag_f2 = true; | |
188 | ring_node_to_send_swf_f0 = current_ring_node_f0->previous; |
|
188 | ring_node_to_send_swf_f0 = current_ring_node_f0->previous; | |
189 | current_ring_node_f0 = current_ring_node_f0->next; |
|
189 | current_ring_node_f0 = current_ring_node_f0->next; | |
190 | if ( (waveform_picker_regs->status & BIT_WFP_BUFFER_0) == BIT_WFP_BUFFER_0) |
|
190 | if ( (waveform_picker_regs->status & BIT_WFP_BUFFER_0) == BIT_WFP_BUFFER_0) | |
191 | { |
|
191 | { | |
192 |
|
192 | |||
193 | 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; | |
194 | 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; | |
195 | 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; | |
196 | waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F0_0; // [0001 0001 0000 0001] |
|
196 | waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F0_0; // [0001 0001 0000 0001] | |
197 | } |
|
197 | } | |
198 | else if ( (waveform_picker_regs->status & BIT_WFP_BUFFER_1) == BIT_WFP_BUFFER_1) |
|
198 | else if ( (waveform_picker_regs->status & BIT_WFP_BUFFER_1) == BIT_WFP_BUFFER_1) | |
199 | { |
|
199 | { | |
200 | 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; | |
201 | 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; | |
202 | 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; | |
203 | waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F0_1; // [0001 0001 0000 0010] |
|
203 | waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F0_1; // [0001 0001 0000 0010] | |
204 | } |
|
204 | } | |
205 | // send an event to the WFRM task for resynchro activities |
|
205 | // send an event to the WFRM task for resynchro activities | |
206 | 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 ); | |
207 | } |
|
207 | } | |
208 |
|
208 | |||
209 | //*** |
|
209 | //*** | |
210 | // F1 |
|
210 | // F1 | |
211 | if ( (waveform_picker_regs->status & BITS_WFP_STATUS_F1) != INIT_CHAR ) { // [0000 1100] check the f1 full bits |
|
211 | if ( (waveform_picker_regs->status & BITS_WFP_STATUS_F1) != INIT_CHAR ) { // [0000 1100] check the f1 full bits | |
212 | // (1) change the receiving buffer for the waveform picker |
|
212 | // (1) change the receiving buffer for the waveform picker | |
213 | ring_node_to_send_cwf_f1 = current_ring_node_f1->previous; |
|
213 | ring_node_to_send_cwf_f1 = current_ring_node_f1->previous; | |
214 | current_ring_node_f1 = current_ring_node_f1->next; |
|
214 | current_ring_node_f1 = current_ring_node_f1->next; | |
215 | if ( (waveform_picker_regs->status & BIT_WFP_BUF_F1_0) == BIT_WFP_BUF_F1_0) |
|
215 | if ( (waveform_picker_regs->status & BIT_WFP_BUF_F1_0) == BIT_WFP_BUF_F1_0) | |
216 | { |
|
216 | { | |
217 | 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; | |
218 | 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; | |
219 | 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; | |
220 | waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F1_0; // [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 | |
221 | } |
|
221 | } | |
222 | else if ( (waveform_picker_regs->status & BIT_WFP_BUF_F1_1) == BIT_WFP_BUF_F1_1) |
|
222 | else if ( (waveform_picker_regs->status & BIT_WFP_BUF_F1_1) == BIT_WFP_BUF_F1_1) | |
223 | { |
|
223 | { | |
224 | 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; | |
225 | 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; | |
226 | 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; | |
227 | waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F1_1; // [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 | |
228 | } |
|
228 | } | |
229 | // (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) | |
230 | 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 ); | |
231 | } |
|
231 | } | |
232 |
|
232 | |||
233 | //*** |
|
233 | //*** | |
234 | // F2 |
|
234 | // F2 | |
235 | if ( (waveform_picker_regs->status & BITS_WFP_STATUS_F2) != INIT_CHAR ) { // [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 | |
236 | // (1) change the receiving buffer for the waveform picker |
|
236 | // (1) change the receiving buffer for the waveform picker | |
237 | ring_node_to_send_cwf_f2 = current_ring_node_f2->previous; |
|
237 | ring_node_to_send_cwf_f2 = current_ring_node_f2->previous; | |
238 | ring_node_to_send_cwf_f2->sid = SID_SBM2_CWF_F2; |
|
238 | ring_node_to_send_cwf_f2->sid = SID_SBM2_CWF_F2; | |
239 | current_ring_node_f2 = current_ring_node_f2->next; |
|
239 | current_ring_node_f2 = current_ring_node_f2->next; | |
240 | if ( (waveform_picker_regs->status & BIT_WFP_BUF_F2_0) == BIT_WFP_BUF_F2_0) |
|
240 | if ( (waveform_picker_regs->status & BIT_WFP_BUF_F2_0) == BIT_WFP_BUF_F2_0) | |
241 | { |
|
241 | { | |
242 | 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; | |
243 | 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; | |
244 | 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; | |
245 | waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F2_0; // [0100 0100 0001 0000] |
|
245 | waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F2_0; // [0100 0100 0001 0000] | |
246 | } |
|
246 | } | |
247 | else if ( (waveform_picker_regs->status & BIT_WFP_BUF_F2_1) == BIT_WFP_BUF_F2_1) |
|
247 | else if ( (waveform_picker_regs->status & BIT_WFP_BUF_F2_1) == BIT_WFP_BUF_F2_1) | |
248 | { |
|
248 | { | |
249 | 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; | |
250 | 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; | |
251 | 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; | |
252 | waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F2_1; // [0100 0100 0010 0000] |
|
252 | waveform_picker_regs->status = waveform_picker_regs->status & RST_WFP_F2_1; // [0100 0100 0010 0000] | |
253 | } |
|
253 | } | |
254 | // (2) send an event for the waveforms transmission |
|
254 | // (2) send an event for the waveforms transmission | |
255 | 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 ); | |
256 | } |
|
256 | } | |
257 | } |
|
257 | } | |
258 |
|
258 | |||
259 | rtems_isr waveforms_isr( rtems_vector_number vector ) |
|
259 | rtems_isr waveforms_isr( rtems_vector_number vector ) | |
260 | { |
|
260 | { | |
261 | /** 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. | |
262 | * |
|
262 | * | |
263 | * 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: | |
264 | * 1. the values read in the registers of the waveform picker. |
|
264 | * 1. the values read in the registers of the waveform picker. | |
265 | * 2. the current LFR mode. |
|
265 | * 2. the current LFR mode. | |
266 | * |
|
266 | * | |
267 | */ |
|
267 | */ | |
268 |
|
268 | |||
269 | // STATUS |
|
269 | // STATUS | |
270 | // new error error buffer full |
|
270 | // new error error buffer full | |
271 | // 15 14 13 12 11 10 9 8 |
|
271 | // 15 14 13 12 11 10 9 8 | |
272 | // f3 f2 f1 f0 f3 f2 f1 f0 |
|
272 | // f3 f2 f1 f0 f3 f2 f1 f0 | |
273 | // |
|
273 | // | |
274 | // ready buffer |
|
274 | // ready buffer | |
275 | // 7 6 5 4 3 2 1 0 |
|
275 | // 7 6 5 4 3 2 1 0 | |
276 | // 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 | |
277 |
|
277 | |||
278 | rtems_status_code spare_status; |
|
278 | rtems_status_code spare_status; | |
279 |
|
279 | |||
280 | waveforms_isr_f3(); |
|
280 | waveforms_isr_f3(); | |
281 |
|
281 | |||
282 | //************************************************* |
|
282 | //************************************************* | |
283 | // copy the status bits in the housekeeping packets |
|
283 | // copy the status bits in the housekeeping packets | |
284 | housekeeping_packet.hk_lfr_vhdl_iir_cal = |
|
284 | housekeeping_packet.hk_lfr_vhdl_iir_cal = | |
285 | (unsigned char) ((waveform_picker_regs->status & BYTE0_MASK) >> SHIFT_1_BYTE); |
|
285 | (unsigned char) ((waveform_picker_regs->status & BYTE0_MASK) >> SHIFT_1_BYTE); | |
286 |
|
286 | |||
287 | if ( (waveform_picker_regs->status & BYTE0_MASK) != INIT_CHAR) // [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 | |
288 | { |
|
288 | { | |
289 | 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 ); | |
290 | } |
|
290 | } | |
291 |
|
291 | |||
292 | switch(lfrCurrentMode) |
|
292 | switch(lfrCurrentMode) | |
293 | { |
|
293 | { | |
294 | //******** |
|
294 | //******** | |
295 | // STANDBY |
|
295 | // STANDBY | |
296 | case LFR_MODE_STANDBY: |
|
296 | case LFR_MODE_STANDBY: | |
297 | break; |
|
297 | break; | |
298 | //************************** |
|
298 | //************************** | |
299 | // LFR NORMAL, SBM1 and SBM2 |
|
299 | // LFR NORMAL, SBM1 and SBM2 | |
300 | case LFR_MODE_NORMAL: |
|
300 | case LFR_MODE_NORMAL: | |
301 | case LFR_MODE_SBM1: |
|
301 | case LFR_MODE_SBM1: | |
302 | case LFR_MODE_SBM2: |
|
302 | case LFR_MODE_SBM2: | |
303 | waveform_isr_normal_sbm1_sbm2(); |
|
303 | waveform_isr_normal_sbm1_sbm2(); | |
304 | break; |
|
304 | break; | |
305 | //****** |
|
305 | //****** | |
306 | // BURST |
|
306 | // BURST | |
307 | case LFR_MODE_BURST: |
|
307 | case LFR_MODE_BURST: | |
308 | waveforms_isr_burst(); |
|
308 | waveforms_isr_burst(); | |
309 | break; |
|
309 | break; | |
310 | //******** |
|
310 | //******** | |
311 | // DEFAULT |
|
311 | // DEFAULT | |
312 | default: |
|
312 | default: | |
313 | break; |
|
313 | break; | |
314 | } |
|
314 | } | |
315 | } |
|
315 | } | |
316 |
|
316 | |||
317 | //************ |
|
317 | //************ | |
318 | // RTEMS TASKS |
|
318 | // RTEMS TASKS | |
319 |
|
319 | |||
320 | 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 | |
321 | { |
|
321 | { | |
322 | /** 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. | |
323 | * |
|
323 | * | |
324 | * @param unused is the starting argument of the RTEMS task |
|
324 | * @param unused is the starting argument of the RTEMS task | |
325 | * |
|
325 | * | |
326 | * The following data packets are sent by this task: |
|
326 | * The following data packets are sent by this task: | |
327 | * - TM_LFR_SCIENCE_NORMAL_SWF_F0 |
|
327 | * - TM_LFR_SCIENCE_NORMAL_SWF_F0 | |
328 | * - TM_LFR_SCIENCE_NORMAL_SWF_F1 |
|
328 | * - TM_LFR_SCIENCE_NORMAL_SWF_F1 | |
329 | * - TM_LFR_SCIENCE_NORMAL_SWF_F2 |
|
329 | * - TM_LFR_SCIENCE_NORMAL_SWF_F2 | |
330 | * |
|
330 | * | |
331 | */ |
|
331 | */ | |
332 |
|
332 | |||
333 | rtems_event_set event_out; |
|
333 | rtems_event_set event_out; | |
334 | rtems_id queue_id; |
|
334 | rtems_id queue_id; | |
335 | rtems_status_code status; |
|
335 | rtems_status_code status; | |
336 | ring_node *ring_node_swf1_extracted_ptr; |
|
336 | ring_node *ring_node_swf1_extracted_ptr; | |
337 | ring_node *ring_node_swf2_extracted_ptr; |
|
337 | ring_node *ring_node_swf2_extracted_ptr; | |
338 |
|
338 | |||
339 | event_out = EVENT_SETS_NONE_PENDING; |
|
339 | event_out = EVENT_SETS_NONE_PENDING; | |
340 | queue_id = RTEMS_ID_NONE; |
|
340 | queue_id = RTEMS_ID_NONE; | |
341 |
|
341 | |||
342 | ring_node_swf1_extracted_ptr = (ring_node *) &ring_node_swf1_extracted; |
|
342 | ring_node_swf1_extracted_ptr = (ring_node *) &ring_node_swf1_extracted; | |
343 | ring_node_swf2_extracted_ptr = (ring_node *) &ring_node_swf2_extracted; |
|
343 | ring_node_swf2_extracted_ptr = (ring_node *) &ring_node_swf2_extracted; | |
344 |
|
344 | |||
345 | status = get_message_queue_id_send( &queue_id ); |
|
345 | status = get_message_queue_id_send( &queue_id ); | |
346 | if (status != RTEMS_SUCCESSFUL) |
|
346 | if (status != RTEMS_SUCCESSFUL) | |
347 | { |
|
347 | { | |
348 | PRINTF1("in WFRM *** ERR get_message_queue_id_send %d\n", status); |
|
348 | PRINTF1("in WFRM *** ERR get_message_queue_id_send %d\n", status); | |
349 | } |
|
349 | } | |
350 |
|
350 | |||
351 | BOOT_PRINTF("in WFRM ***\n"); |
|
351 | BOOT_PRINTF("in WFRM ***\n"); | |
352 |
|
352 | |||
353 | while(1){ |
|
353 | while(1){ | |
354 | // wait for an RTEMS_EVENT |
|
354 | // wait for an RTEMS_EVENT | |
355 | rtems_event_receive(RTEMS_EVENT_MODE_NORMAL | RTEMS_EVENT_SWF_RESYNCH, |
|
355 | rtems_event_receive(RTEMS_EVENT_MODE_NORMAL | RTEMS_EVENT_SWF_RESYNCH, | |
356 | RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); |
|
356 | RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); | |
357 |
|
357 | |||
358 | if (event_out == RTEMS_EVENT_MODE_NORMAL) |
|
358 | if (event_out == RTEMS_EVENT_MODE_NORMAL) | |
359 | { |
|
359 | { | |
360 | DEBUG_PRINTF("WFRM received RTEMS_EVENT_MODE_SBM2\n"); |
|
360 | DEBUG_PRINTF("WFRM received RTEMS_EVENT_MODE_SBM2\n"); | |
361 | ring_node_to_send_swf_f0->sid = SID_NORM_SWF_F0; |
|
361 | ring_node_to_send_swf_f0->sid = SID_NORM_SWF_F0; | |
362 | ring_node_swf1_extracted_ptr->sid = SID_NORM_SWF_F1; |
|
362 | ring_node_swf1_extracted_ptr->sid = SID_NORM_SWF_F1; | |
363 | ring_node_swf2_extracted_ptr->sid = SID_NORM_SWF_F2; |
|
363 | ring_node_swf2_extracted_ptr->sid = SID_NORM_SWF_F2; | |
364 | status = rtems_message_queue_send( queue_id, &ring_node_to_send_swf_f0, sizeof( ring_node* ) ); |
|
364 | status = rtems_message_queue_send( queue_id, &ring_node_to_send_swf_f0, sizeof( ring_node* ) ); | |
365 | status = rtems_message_queue_send( queue_id, &ring_node_swf1_extracted_ptr, sizeof( ring_node* ) ); |
|
365 | status = rtems_message_queue_send( queue_id, &ring_node_swf1_extracted_ptr, sizeof( ring_node* ) ); | |
366 | status = rtems_message_queue_send( queue_id, &ring_node_swf2_extracted_ptr, sizeof( ring_node* ) ); |
|
366 | status = rtems_message_queue_send( queue_id, &ring_node_swf2_extracted_ptr, sizeof( ring_node* ) ); | |
367 | } |
|
367 | } | |
368 | if (event_out == RTEMS_EVENT_SWF_RESYNCH) |
|
368 | if (event_out == RTEMS_EVENT_SWF_RESYNCH) | |
369 | { |
|
369 | { | |
370 | snapshot_resynchronization( (unsigned char *) &ring_node_to_send_swf_f0->coarseTime ); |
|
370 | snapshot_resynchronization( (unsigned char *) &ring_node_to_send_swf_f0->coarseTime ); | |
371 | } |
|
371 | } | |
372 | } |
|
372 | } | |
373 | } |
|
373 | } | |
374 |
|
374 | |||
375 | rtems_task cwf3_task(rtems_task_argument argument) //used with the waveform picker VHDL IP |
|
375 | rtems_task cwf3_task(rtems_task_argument argument) //used with the waveform picker VHDL IP | |
376 | { |
|
376 | { | |
377 | /** This RTEMS task is dedicated to the transmission of continuous waveforms at f3. |
|
377 | /** This RTEMS task is dedicated to the transmission of continuous waveforms at f3. | |
378 | * |
|
378 | * | |
379 | * @param unused is the starting argument of the RTEMS task |
|
379 | * @param unused is the starting argument of the RTEMS task | |
380 | * |
|
380 | * | |
381 | * The following data packet is sent by this task: |
|
381 | * The following data packet is sent by this task: | |
382 | * - TM_LFR_SCIENCE_NORMAL_CWF_F3 |
|
382 | * - TM_LFR_SCIENCE_NORMAL_CWF_F3 | |
383 | * |
|
383 | * | |
384 | */ |
|
384 | */ | |
385 |
|
385 | |||
386 | rtems_event_set event_out; |
|
386 | rtems_event_set event_out; | |
387 | rtems_id queue_id; |
|
387 | rtems_id queue_id; | |
388 | rtems_status_code status; |
|
388 | rtems_status_code status; | |
389 | ring_node ring_node_cwf3_light; |
|
389 | ring_node ring_node_cwf3_light; | |
390 | ring_node *ring_node_to_send_cwf; |
|
390 | ring_node *ring_node_to_send_cwf; | |
391 |
|
391 | |||
392 | event_out = EVENT_SETS_NONE_PENDING; |
|
392 | event_out = EVENT_SETS_NONE_PENDING; | |
393 | queue_id = RTEMS_ID_NONE; |
|
393 | queue_id = RTEMS_ID_NONE; | |
394 |
|
394 | |||
395 | status = get_message_queue_id_send( &queue_id ); |
|
395 | status = get_message_queue_id_send( &queue_id ); | |
396 | if (status != RTEMS_SUCCESSFUL) |
|
396 | if (status != RTEMS_SUCCESSFUL) | |
397 | { |
|
397 | { | |
398 | PRINTF1("in CWF3 *** ERR get_message_queue_id_send %d\n", status) |
|
398 | PRINTF1("in CWF3 *** ERR get_message_queue_id_send %d\n", status) | |
399 | } |
|
399 | } | |
400 |
|
400 | |||
401 | ring_node_to_send_cwf_f3->sid = SID_NORM_CWF_LONG_F3; |
|
401 | ring_node_to_send_cwf_f3->sid = SID_NORM_CWF_LONG_F3; | |
402 |
|
402 | |||
403 | // init the ring_node_cwf3_light structure |
|
403 | // init the ring_node_cwf3_light structure | |
404 | ring_node_cwf3_light.buffer_address = (int) wf_cont_f3_light; |
|
404 | ring_node_cwf3_light.buffer_address = (int) wf_cont_f3_light; | |
405 | ring_node_cwf3_light.coarseTime = INIT_CHAR; |
|
405 | ring_node_cwf3_light.coarseTime = INIT_CHAR; | |
406 | ring_node_cwf3_light.fineTime = INIT_CHAR; |
|
406 | ring_node_cwf3_light.fineTime = INIT_CHAR; | |
407 | ring_node_cwf3_light.next = NULL; |
|
407 | ring_node_cwf3_light.next = NULL; | |
408 | ring_node_cwf3_light.previous = NULL; |
|
408 | ring_node_cwf3_light.previous = NULL; | |
409 | ring_node_cwf3_light.sid = SID_NORM_CWF_F3; |
|
409 | ring_node_cwf3_light.sid = SID_NORM_CWF_F3; | |
410 | ring_node_cwf3_light.status = INIT_CHAR; |
|
410 | ring_node_cwf3_light.status = INIT_CHAR; | |
411 |
|
411 | |||
412 | BOOT_PRINTF("in CWF3 ***\n"); |
|
412 | BOOT_PRINTF("in CWF3 ***\n"); | |
413 |
|
413 | |||
414 | while(1){ |
|
414 | while(1){ | |
415 | // wait for an RTEMS_EVENT |
|
415 | // wait for an RTEMS_EVENT | |
416 | rtems_event_receive( RTEMS_EVENT_0, |
|
416 | rtems_event_receive( RTEMS_EVENT_0, | |
417 | RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); |
|
417 | RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); | |
418 | if ( (lfrCurrentMode == LFR_MODE_NORMAL) |
|
418 | if ( (lfrCurrentMode == LFR_MODE_NORMAL) | |
419 | || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode==LFR_MODE_SBM2) ) |
|
419 | || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode==LFR_MODE_SBM2) ) | |
420 | { |
|
420 | { | |
421 | ring_node_to_send_cwf = getRingNodeToSendCWF( CHANNELF3 ); |
|
421 | ring_node_to_send_cwf = getRingNodeToSendCWF( CHANNELF3 ); | |
422 | if ( (parameter_dump_packet.sy_lfr_n_cwf_long_f3 & BIT_CWF_LONG_F3) == BIT_CWF_LONG_F3) |
|
422 | if ( (parameter_dump_packet.sy_lfr_n_cwf_long_f3 & BIT_CWF_LONG_F3) == BIT_CWF_LONG_F3) | |
423 | { |
|
423 | { | |
424 | PRINTF("send CWF_LONG_F3\n"); |
|
424 | PRINTF("send CWF_LONG_F3\n"); | |
425 | ring_node_to_send_cwf_f3->sid = SID_NORM_CWF_LONG_F3; |
|
425 | ring_node_to_send_cwf_f3->sid = SID_NORM_CWF_LONG_F3; | |
426 | status = rtems_message_queue_send( queue_id, &ring_node_to_send_cwf, sizeof( ring_node* ) ); |
|
426 | status = rtems_message_queue_send( queue_id, &ring_node_to_send_cwf, sizeof( ring_node* ) ); | |
427 | } |
|
427 | } | |
428 | else |
|
428 | else | |
429 | { |
|
429 | { | |
430 | PRINTF("send CWF_F3 (light)\n"); |
|
430 | PRINTF("send CWF_F3 (light)\n"); | |
431 | send_waveform_CWF3_light( ring_node_to_send_cwf, &ring_node_cwf3_light, queue_id ); |
|
431 | send_waveform_CWF3_light( ring_node_to_send_cwf, &ring_node_cwf3_light, queue_id ); | |
432 | } |
|
432 | } | |
433 |
|
433 | |||
434 | } |
|
434 | } | |
435 | else |
|
435 | else | |
436 | { |
|
436 | { | |
437 | PRINTF1("in CWF3 *** lfrCurrentMode is %d, no data will be sent\n", lfrCurrentMode) |
|
437 | PRINTF1("in CWF3 *** lfrCurrentMode is %d, no data will be sent\n", lfrCurrentMode) | |
438 | } |
|
438 | } | |
439 | } |
|
439 | } | |
440 | } |
|
440 | } | |
441 |
|
441 | |||
442 | rtems_task cwf2_task(rtems_task_argument argument) // ONLY USED IN BURST AND SBM2 |
|
442 | rtems_task cwf2_task(rtems_task_argument argument) // ONLY USED IN BURST AND SBM2 | |
443 | { |
|
443 | { | |
444 | /** This RTEMS task is dedicated to the transmission of continuous waveforms at f2. |
|
444 | /** This RTEMS task is dedicated to the transmission of continuous waveforms at f2. | |
445 | * |
|
445 | * | |
446 | * @param unused is the starting argument of the RTEMS task |
|
446 | * @param unused is the starting argument of the RTEMS task | |
447 | * |
|
447 | * | |
448 | * The following data packet is sent by this function: |
|
448 | * The following data packet is sent by this function: | |
449 | * - TM_LFR_SCIENCE_BURST_CWF_F2 |
|
449 | * - TM_LFR_SCIENCE_BURST_CWF_F2 | |
450 | * - TM_LFR_SCIENCE_SBM2_CWF_F2 |
|
450 | * - TM_LFR_SCIENCE_SBM2_CWF_F2 | |
451 | * |
|
451 | * | |
452 | */ |
|
452 | */ | |
453 |
|
453 | |||
454 | rtems_event_set event_out; |
|
454 | rtems_event_set event_out; | |
455 | rtems_id queue_id; |
|
455 | rtems_id queue_id; | |
456 | rtems_status_code status; |
|
456 | rtems_status_code status; | |
457 | ring_node *ring_node_to_send; |
|
457 | ring_node *ring_node_to_send; | |
458 | unsigned long long int acquisitionTimeF0_asLong; |
|
458 | unsigned long long int acquisitionTimeF0_asLong; | |
459 |
|
459 | |||
460 | event_out = EVENT_SETS_NONE_PENDING; |
|
460 | event_out = EVENT_SETS_NONE_PENDING; | |
461 | queue_id = RTEMS_ID_NONE; |
|
461 | queue_id = RTEMS_ID_NONE; | |
462 |
|
462 | |||
463 | acquisitionTimeF0_asLong = INIT_CHAR; |
|
463 | acquisitionTimeF0_asLong = INIT_CHAR; | |
464 |
|
464 | |||
465 | status = get_message_queue_id_send( &queue_id ); |
|
465 | status = get_message_queue_id_send( &queue_id ); | |
466 | if (status != RTEMS_SUCCESSFUL) |
|
466 | if (status != RTEMS_SUCCESSFUL) | |
467 | { |
|
467 | { | |
468 | PRINTF1("in CWF2 *** ERR get_message_queue_id_send %d\n", status) |
|
468 | PRINTF1("in CWF2 *** ERR get_message_queue_id_send %d\n", status) | |
469 | } |
|
469 | } | |
470 |
|
470 | |||
471 | BOOT_PRINTF("in CWF2 ***\n"); |
|
471 | BOOT_PRINTF("in CWF2 ***\n"); | |
472 |
|
472 | |||
473 | while(1){ |
|
473 | while(1){ | |
474 | // wait for an RTEMS_EVENT// send the snapshot when built |
|
474 | // wait for an RTEMS_EVENT// send the snapshot when built | |
475 | status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_SBM2 ); |
|
475 | status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_SBM2 ); | |
476 | rtems_event_receive( RTEMS_EVENT_MODE_NORM_S1_S2 | RTEMS_EVENT_MODE_BURST, |
|
476 | rtems_event_receive( RTEMS_EVENT_MODE_NORM_S1_S2 | RTEMS_EVENT_MODE_BURST, | |
477 | RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); |
|
477 | RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); | |
478 | ring_node_to_send = getRingNodeToSendCWF( CHANNELF2 ); |
|
478 | ring_node_to_send = getRingNodeToSendCWF( CHANNELF2 ); | |
479 | if (event_out == RTEMS_EVENT_MODE_BURST) |
|
479 | if (event_out == RTEMS_EVENT_MODE_BURST) | |
480 | { // data are sent whatever the transition time |
|
480 | { // data are sent whatever the transition time | |
481 | 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* ) ); | |
482 | } |
|
482 | } | |
483 | else if (event_out == RTEMS_EVENT_MODE_NORM_S1_S2) |
|
483 | else if (event_out == RTEMS_EVENT_MODE_NORM_S1_S2) | |
484 | { |
|
484 | { | |
485 | if ( lfrCurrentMode == LFR_MODE_SBM2 ) |
|
485 | if ( lfrCurrentMode == LFR_MODE_SBM2 ) | |
486 | { |
|
486 | { | |
487 | // data are sent depending on the transition time |
|
487 | // data are sent depending on the transition time | |
488 | if ( time_management_regs->coarse_time >= lastValidEnterModeTime) |
|
488 | if ( time_management_regs->coarse_time >= lastValidEnterModeTime) | |
489 | { |
|
489 | { | |
490 | status = rtems_message_queue_send( queue_id, &ring_node_to_send, sizeof( ring_node* ) ); |
|
490 | status = rtems_message_queue_send( queue_id, &ring_node_to_send, sizeof( ring_node* ) ); | |
491 | } |
|
491 | } | |
492 | } |
|
492 | } | |
493 | // launch snapshot extraction if needed |
|
493 | // launch snapshot extraction if needed | |
494 | if (extractSWF2 == true) |
|
494 | if (extractSWF2 == true) | |
495 | { |
|
495 | { | |
496 | ring_node_to_send_swf_f2 = ring_node_to_send_cwf_f2; |
|
496 | ring_node_to_send_swf_f2 = ring_node_to_send_cwf_f2; | |
497 | // extract the snapshot |
|
497 | // extract the snapshot | |
498 | build_snapshot_from_ring( ring_node_to_send_swf_f2, CHANNELF2, acquisitionTimeF0_asLong, |
|
498 | build_snapshot_from_ring( ring_node_to_send_swf_f2, CHANNELF2, acquisitionTimeF0_asLong, | |
499 | &ring_node_swf2_extracted, swf2_extracted ); |
|
499 | &ring_node_swf2_extracted, swf2_extracted ); | |
500 | extractSWF2 = false; |
|
500 | extractSWF2 = false; | |
501 | swf2_ready = true; // once the snapshot at f2 is ready the CWF1 task will send an event to WFRM |
|
501 | swf2_ready = true; // once the snapshot at f2 is ready the CWF1 task will send an event to WFRM | |
502 | } |
|
502 | } | |
503 | if (swf0_ready_flag_f2 == true) |
|
503 | if (swf0_ready_flag_f2 == true) | |
504 | { |
|
504 | { | |
505 | extractSWF2 = true; |
|
505 | extractSWF2 = true; | |
506 | // record the acquition time of the f0 snapshot to use to build the snapshot at f2 |
|
506 | // record the acquition time of the f0 snapshot to use to build the snapshot at f2 | |
507 | acquisitionTimeF0_asLong = get_acquisition_time( (unsigned char *) &ring_node_to_send_swf_f0->coarseTime ); |
|
507 | acquisitionTimeF0_asLong = get_acquisition_time( (unsigned char *) &ring_node_to_send_swf_f0->coarseTime ); | |
508 | swf0_ready_flag_f2 = false; |
|
508 | swf0_ready_flag_f2 = false; | |
509 | } |
|
509 | } | |
510 | } |
|
510 | } | |
511 | } |
|
511 | } | |
512 | } |
|
512 | } | |
513 |
|
513 | |||
514 | rtems_task cwf1_task(rtems_task_argument argument) // ONLY USED IN SBM1 |
|
514 | rtems_task cwf1_task(rtems_task_argument argument) // ONLY USED IN SBM1 | |
515 | { |
|
515 | { | |
516 | /** This RTEMS task is dedicated to the transmission of continuous waveforms at f1. |
|
516 | /** This RTEMS task is dedicated to the transmission of continuous waveforms at f1. | |
517 | * |
|
517 | * | |
518 | * @param unused is the starting argument of the RTEMS task |
|
518 | * @param unused is the starting argument of the RTEMS task | |
519 | * |
|
519 | * | |
520 | * The following data packet is sent by this function: |
|
520 | * The following data packet is sent by this function: | |
521 | * - TM_LFR_SCIENCE_SBM1_CWF_F1 |
|
521 | * - TM_LFR_SCIENCE_SBM1_CWF_F1 | |
522 | * |
|
522 | * | |
523 | */ |
|
523 | */ | |
524 |
|
524 | |||
525 | rtems_event_set event_out; |
|
525 | rtems_event_set event_out; | |
526 | rtems_id queue_id; |
|
526 | rtems_id queue_id; | |
527 | rtems_status_code status; |
|
527 | rtems_status_code status; | |
528 |
|
528 | |||
529 | ring_node *ring_node_to_send_cwf; |
|
529 | ring_node *ring_node_to_send_cwf; | |
530 |
|
530 | |||
531 | event_out = EVENT_SETS_NONE_PENDING; |
|
531 | event_out = EVENT_SETS_NONE_PENDING; | |
532 | queue_id = RTEMS_ID_NONE; |
|
532 | queue_id = RTEMS_ID_NONE; | |
533 |
|
533 | |||
534 | status = get_message_queue_id_send( &queue_id ); |
|
534 | status = get_message_queue_id_send( &queue_id ); | |
535 | if (status != RTEMS_SUCCESSFUL) |
|
535 | if (status != RTEMS_SUCCESSFUL) | |
536 | { |
|
536 | { | |
537 | PRINTF1("in CWF1 *** ERR get_message_queue_id_send %d\n", status) |
|
537 | PRINTF1("in CWF1 *** ERR get_message_queue_id_send %d\n", status) | |
538 | } |
|
538 | } | |
539 |
|
539 | |||
540 | BOOT_PRINTF("in CWF1 ***\n"); |
|
540 | BOOT_PRINTF("in CWF1 ***\n"); | |
541 |
|
541 | |||
542 | while(1){ |
|
542 | while(1){ | |
543 | // wait for an RTEMS_EVENT |
|
543 | // wait for an RTEMS_EVENT | |
544 | rtems_event_receive( RTEMS_EVENT_MODE_NORM_S1_S2, |
|
544 | rtems_event_receive( RTEMS_EVENT_MODE_NORM_S1_S2, | |
545 | RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); |
|
545 | RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); | |
546 | ring_node_to_send_cwf = getRingNodeToSendCWF( 1 ); |
|
546 | ring_node_to_send_cwf = getRingNodeToSendCWF( 1 ); | |
547 | ring_node_to_send_cwf_f1->sid = SID_SBM1_CWF_F1; |
|
547 | ring_node_to_send_cwf_f1->sid = SID_SBM1_CWF_F1; | |
548 | if (lfrCurrentMode == LFR_MODE_SBM1) |
|
548 | if (lfrCurrentMode == LFR_MODE_SBM1) | |
549 | { |
|
549 | { | |
550 | // data are sent depending on the transition time |
|
550 | // data are sent depending on the transition time | |
551 | if ( time_management_regs->coarse_time >= lastValidEnterModeTime ) |
|
551 | if ( time_management_regs->coarse_time >= lastValidEnterModeTime ) | |
552 | { |
|
552 | { | |
553 | status = rtems_message_queue_send( queue_id, &ring_node_to_send_cwf, sizeof( ring_node* ) ); |
|
553 | status = rtems_message_queue_send( queue_id, &ring_node_to_send_cwf, sizeof( ring_node* ) ); | |
554 | } |
|
554 | } | |
555 | } |
|
555 | } | |
556 | // launch snapshot extraction if needed |
|
556 | // launch snapshot extraction if needed | |
557 | if (extractSWF1 == true) |
|
557 | if (extractSWF1 == true) | |
558 | { |
|
558 | { | |
559 | ring_node_to_send_swf_f1 = ring_node_to_send_cwf; |
|
559 | ring_node_to_send_swf_f1 = ring_node_to_send_cwf; | |
560 | // launch the snapshot extraction |
|
560 | // launch the snapshot extraction | |
561 | status = rtems_event_send( Task_id[TASKID_SWBD], RTEMS_EVENT_MODE_NORM_S1_S2 ); |
|
561 | status = rtems_event_send( Task_id[TASKID_SWBD], RTEMS_EVENT_MODE_NORM_S1_S2 ); | |
562 | extractSWF1 = false; |
|
562 | extractSWF1 = false; | |
563 | } |
|
563 | } | |
564 | if (swf0_ready_flag_f1 == true) |
|
564 | if (swf0_ready_flag_f1 == true) | |
565 | { |
|
565 | { | |
566 | extractSWF1 = true; |
|
566 | extractSWF1 = true; | |
567 | swf0_ready_flag_f1 = false; // this step shall be executed only one time |
|
567 | swf0_ready_flag_f1 = false; // this step shall be executed only one time | |
568 | } |
|
568 | } | |
569 | if ((swf1_ready == true) && (swf2_ready == true)) // swf_f1 is ready after the extraction |
|
569 | if ((swf1_ready == true) && (swf2_ready == true)) // swf_f1 is ready after the extraction | |
570 | { |
|
570 | { | |
571 | status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_NORMAL ); |
|
571 | status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_NORMAL ); | |
572 | swf1_ready = false; |
|
572 | swf1_ready = false; | |
573 | swf2_ready = false; |
|
573 | swf2_ready = false; | |
574 | } |
|
574 | } | |
575 | } |
|
575 | } | |
576 | } |
|
576 | } | |
577 |
|
577 | |||
578 | rtems_task swbd_task(rtems_task_argument argument) |
|
578 | rtems_task swbd_task(rtems_task_argument argument) | |
579 | { |
|
579 | { | |
580 | /** This RTEMS task is dedicated to the building of snapshots from different continuous waveforms buffers. |
|
580 | /** This RTEMS task is dedicated to the building of snapshots from different continuous waveforms buffers. | |
581 | * |
|
581 | * | |
582 | * @param unused is the starting argument of the RTEMS task |
|
582 | * @param unused is the starting argument of the RTEMS task | |
583 | * |
|
583 | * | |
584 | */ |
|
584 | */ | |
585 |
|
585 | |||
586 | rtems_event_set event_out; |
|
586 | rtems_event_set event_out; | |
587 | unsigned long long int acquisitionTimeF0_asLong; |
|
587 | unsigned long long int acquisitionTimeF0_asLong; | |
588 |
|
588 | |||
589 | event_out = EVENT_SETS_NONE_PENDING; |
|
589 | event_out = EVENT_SETS_NONE_PENDING; | |
590 | acquisitionTimeF0_asLong = INIT_CHAR; |
|
590 | acquisitionTimeF0_asLong = INIT_CHAR; | |
591 |
|
591 | |||
592 | BOOT_PRINTF("in SWBD ***\n") |
|
592 | BOOT_PRINTF("in SWBD ***\n") | |
593 |
|
593 | |||
594 | while(1){ |
|
594 | while(1){ | |
595 | // wait for an RTEMS_EVENT |
|
595 | // wait for an RTEMS_EVENT | |
596 | rtems_event_receive( RTEMS_EVENT_MODE_NORM_S1_S2, |
|
596 | rtems_event_receive( RTEMS_EVENT_MODE_NORM_S1_S2, | |
597 | RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); |
|
597 | RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); | |
598 | if (event_out == RTEMS_EVENT_MODE_NORM_S1_S2) |
|
598 | if (event_out == RTEMS_EVENT_MODE_NORM_S1_S2) | |
599 | { |
|
599 | { | |
600 | acquisitionTimeF0_asLong = get_acquisition_time( (unsigned char *) &ring_node_to_send_swf_f0->coarseTime ); |
|
600 | acquisitionTimeF0_asLong = get_acquisition_time( (unsigned char *) &ring_node_to_send_swf_f0->coarseTime ); | |
601 | build_snapshot_from_ring( ring_node_to_send_swf_f1, CHANNELF1, acquisitionTimeF0_asLong, |
|
601 | build_snapshot_from_ring( ring_node_to_send_swf_f1, CHANNELF1, acquisitionTimeF0_asLong, | |
602 | &ring_node_swf1_extracted, swf1_extracted ); |
|
602 | &ring_node_swf1_extracted, swf1_extracted ); | |
603 | swf1_ready = true; // the snapshot has been extracted and is ready to be sent |
|
603 | swf1_ready = true; // the snapshot has been extracted and is ready to be sent | |
604 | } |
|
604 | } | |
605 | else |
|
605 | else | |
606 | { |
|
606 | { | |
607 | PRINTF1("in SWBD *** unexpected rtems event received %x\n", (int) event_out) |
|
607 | PRINTF1("in SWBD *** unexpected rtems event received %x\n", (int) event_out) | |
608 | } |
|
608 | } | |
609 | } |
|
609 | } | |
610 | } |
|
610 | } | |
611 |
|
611 | |||
612 | //****************** |
|
612 | //****************** | |
613 | // general functions |
|
613 | // general functions | |
614 |
|
614 | |||
615 | void WFP_init_rings( void ) |
|
615 | void WFP_init_rings( void ) | |
616 | { |
|
616 | { | |
617 | // F0 RING |
|
617 | // F0 RING | |
618 | init_ring( waveform_ring_f0, NB_RING_NODES_F0, wf_buffer_f0, WFRM_BUFFER ); |
|
618 | init_ring( waveform_ring_f0, NB_RING_NODES_F0, wf_buffer_f0, WFRM_BUFFER ); | |
619 | // F1 RING |
|
619 | // F1 RING | |
620 | init_ring( waveform_ring_f1, NB_RING_NODES_F1, wf_buffer_f1, WFRM_BUFFER ); |
|
620 | init_ring( waveform_ring_f1, NB_RING_NODES_F1, wf_buffer_f1, WFRM_BUFFER ); | |
621 | // F2 RING |
|
621 | // F2 RING | |
622 | init_ring( waveform_ring_f2, NB_RING_NODES_F2, wf_buffer_f2, WFRM_BUFFER ); |
|
622 | init_ring( waveform_ring_f2, NB_RING_NODES_F2, wf_buffer_f2, WFRM_BUFFER ); | |
623 | // F3 RING |
|
623 | // F3 RING | |
624 | init_ring( waveform_ring_f3, NB_RING_NODES_F3, wf_buffer_f3, WFRM_BUFFER ); |
|
624 | init_ring( waveform_ring_f3, NB_RING_NODES_F3, wf_buffer_f3, WFRM_BUFFER ); | |
625 |
|
625 | |||
626 | ring_node_swf1_extracted.buffer_address = (int) swf1_extracted; |
|
626 | ring_node_swf1_extracted.buffer_address = (int) swf1_extracted; | |
627 | ring_node_swf2_extracted.buffer_address = (int) swf2_extracted; |
|
627 | ring_node_swf2_extracted.buffer_address = (int) swf2_extracted; | |
628 |
|
628 | |||
629 | DEBUG_PRINTF1("waveform_ring_f0 @%x\n", (unsigned int) waveform_ring_f0) |
|
629 | DEBUG_PRINTF1("waveform_ring_f0 @%x\n", (unsigned int) waveform_ring_f0) | |
630 | DEBUG_PRINTF1("waveform_ring_f1 @%x\n", (unsigned int) waveform_ring_f1) |
|
630 | DEBUG_PRINTF1("waveform_ring_f1 @%x\n", (unsigned int) waveform_ring_f1) | |
631 | DEBUG_PRINTF1("waveform_ring_f2 @%x\n", (unsigned int) waveform_ring_f2) |
|
631 | DEBUG_PRINTF1("waveform_ring_f2 @%x\n", (unsigned int) waveform_ring_f2) | |
632 | DEBUG_PRINTF1("waveform_ring_f3 @%x\n", (unsigned int) waveform_ring_f3) |
|
632 | DEBUG_PRINTF1("waveform_ring_f3 @%x\n", (unsigned int) waveform_ring_f3) | |
633 | DEBUG_PRINTF1("wf_buffer_f0 @%x\n", (unsigned int) wf_buffer_f0) |
|
633 | DEBUG_PRINTF1("wf_buffer_f0 @%x\n", (unsigned int) wf_buffer_f0) | |
634 | DEBUG_PRINTF1("wf_buffer_f1 @%x\n", (unsigned int) wf_buffer_f1) |
|
634 | DEBUG_PRINTF1("wf_buffer_f1 @%x\n", (unsigned int) wf_buffer_f1) | |
635 | DEBUG_PRINTF1("wf_buffer_f2 @%x\n", (unsigned int) wf_buffer_f2) |
|
635 | DEBUG_PRINTF1("wf_buffer_f2 @%x\n", (unsigned int) wf_buffer_f2) | |
636 | DEBUG_PRINTF1("wf_buffer_f3 @%x\n", (unsigned int) wf_buffer_f3) |
|
636 | DEBUG_PRINTF1("wf_buffer_f3 @%x\n", (unsigned int) wf_buffer_f3) | |
637 |
|
637 | |||
638 | } |
|
638 | } | |
639 |
|
639 | |||
640 | void WFP_reset_current_ring_nodes( void ) |
|
640 | void WFP_reset_current_ring_nodes( void ) | |
641 | { |
|
641 | { | |
642 | current_ring_node_f0 = waveform_ring_f0[0].next; |
|
642 | current_ring_node_f0 = waveform_ring_f0[0].next; | |
643 | current_ring_node_f1 = waveform_ring_f1[0].next; |
|
643 | current_ring_node_f1 = waveform_ring_f1[0].next; | |
644 | current_ring_node_f2 = waveform_ring_f2[0].next; |
|
644 | current_ring_node_f2 = waveform_ring_f2[0].next; | |
645 | current_ring_node_f3 = waveform_ring_f3[0].next; |
|
645 | current_ring_node_f3 = waveform_ring_f3[0].next; | |
646 |
|
646 | |||
647 | ring_node_to_send_swf_f0 = waveform_ring_f0; |
|
647 | ring_node_to_send_swf_f0 = waveform_ring_f0; | |
648 | ring_node_to_send_swf_f1 = waveform_ring_f1; |
|
648 | ring_node_to_send_swf_f1 = waveform_ring_f1; | |
649 | ring_node_to_send_swf_f2 = waveform_ring_f2; |
|
649 | ring_node_to_send_swf_f2 = waveform_ring_f2; | |
650 |
|
650 | |||
651 | ring_node_to_send_cwf_f1 = waveform_ring_f1; |
|
651 | ring_node_to_send_cwf_f1 = waveform_ring_f1; | |
652 | ring_node_to_send_cwf_f2 = waveform_ring_f2; |
|
652 | ring_node_to_send_cwf_f2 = waveform_ring_f2; | |
653 | ring_node_to_send_cwf_f3 = waveform_ring_f3; |
|
653 | ring_node_to_send_cwf_f3 = waveform_ring_f3; | |
654 | } |
|
654 | } | |
655 |
|
655 | |||
656 | int send_waveform_CWF3_light( ring_node *ring_node_to_send, ring_node *ring_node_cwf3_light, rtems_id queue_id ) |
|
656 | int send_waveform_CWF3_light( ring_node *ring_node_to_send, ring_node *ring_node_cwf3_light, rtems_id queue_id ) | |
657 | { |
|
657 | { | |
658 | /** This function sends CWF_F3 CCSDS packets without the b1, b2 and b3 data. |
|
658 | /** This function sends CWF_F3 CCSDS packets without the b1, b2 and b3 data. | |
659 | * |
|
659 | * | |
660 | * @param waveform points to the buffer containing the data that will be send. |
|
660 | * @param waveform points to the buffer containing the data that will be send. | |
661 | * @param headerCWF points to a table of headers that have been prepared for the data transmission. |
|
661 | * @param headerCWF points to a table of headers that have been prepared for the data transmission. | |
662 | * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures |
|
662 | * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures | |
663 | * contain information to setup the transmission of the data packets. |
|
663 | * contain information to setup the transmission of the data packets. | |
664 | * |
|
664 | * | |
665 | * By default, CWF_F3 packet are send without the b1, b2 and b3 data. This function rebuilds a data buffer |
|
665 | * By default, CWF_F3 packet are send without the b1, b2 and b3 data. This function rebuilds a data buffer | |
666 | * from the incoming data and sends it in 7 packets, 6 containing 340 blocks and 1 one containing 8 blocks. |
|
666 | * from the incoming data and sends it in 7 packets, 6 containing 340 blocks and 1 one containing 8 blocks. | |
667 | * |
|
667 | * | |
668 | */ |
|
668 | */ | |
669 |
|
669 | |||
670 | unsigned int i; |
|
670 | unsigned int i; | |
671 | unsigned int j; |
|
671 | unsigned int j; | |
672 | int ret; |
|
672 | int ret; | |
673 | rtems_status_code status; |
|
673 | rtems_status_code status; | |
674 |
|
674 | |||
675 | char *sample; |
|
675 | char *sample; | |
676 | int *dataPtr; |
|
676 | int *dataPtr; | |
677 |
|
677 | |||
678 | ret = LFR_DEFAULT; |
|
678 | ret = LFR_DEFAULT; | |
679 |
|
679 | |||
680 | dataPtr = (int*) ring_node_to_send->buffer_address; |
|
680 | dataPtr = (int*) ring_node_to_send->buffer_address; | |
681 |
|
681 | |||
682 | ring_node_cwf3_light->coarseTime = ring_node_to_send->coarseTime; |
|
682 | ring_node_cwf3_light->coarseTime = ring_node_to_send->coarseTime; | |
683 | ring_node_cwf3_light->fineTime = ring_node_to_send->fineTime; |
|
683 | ring_node_cwf3_light->fineTime = ring_node_to_send->fineTime; | |
684 |
|
684 | |||
685 | //********************** |
|
685 | //********************** | |
686 | // BUILD CWF3_light DATA |
|
686 | // BUILD CWF3_light DATA | |
687 | for ( i=0; i< NB_SAMPLES_PER_SNAPSHOT; i++) |
|
687 | for ( i=0; i< NB_SAMPLES_PER_SNAPSHOT; i++) | |
688 | { |
|
688 | { | |
689 | sample = (char*) &dataPtr[ (i * NB_WORDS_SWF_BLK) ]; |
|
689 | sample = (char*) &dataPtr[ (i * NB_WORDS_SWF_BLK) ]; | |
690 | for (j=0; j < CWF_BLK_SIZE; j++) |
|
690 | for (j=0; j < CWF_BLK_SIZE; j++) | |
691 | { |
|
691 | { | |
692 | wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + j] = sample[ j ]; |
|
692 | wf_cont_f3_light[ (i * NB_BYTES_CWF3_LIGHT_BLK) + j] = sample[ j ]; | |
693 | } |
|
693 | } | |
694 | } |
|
694 | } | |
695 |
|
695 | |||
696 | // SEND PACKET |
|
696 | // SEND PACKET | |
697 | status = rtems_message_queue_send( queue_id, &ring_node_cwf3_light, sizeof( ring_node* ) ); |
|
697 | status = rtems_message_queue_send( queue_id, &ring_node_cwf3_light, sizeof( ring_node* ) ); | |
698 | if (status != RTEMS_SUCCESSFUL) { |
|
698 | if (status != RTEMS_SUCCESSFUL) { | |
699 | ret = LFR_DEFAULT; |
|
699 | ret = LFR_DEFAULT; | |
700 | } |
|
700 | } | |
701 |
|
701 | |||
702 | return ret; |
|
702 | return ret; | |
703 | } |
|
703 | } | |
704 |
|
704 | |||
705 | void compute_acquisition_time( unsigned int coarseTime, unsigned int fineTime, |
|
705 | void compute_acquisition_time( unsigned int coarseTime, unsigned int fineTime, | |
706 | unsigned int sid, unsigned char pa_lfr_pkt_nr, unsigned char * acquisitionTime ) |
|
706 | unsigned int sid, unsigned char pa_lfr_pkt_nr, unsigned char * acquisitionTime ) | |
707 | { |
|
707 | { | |
708 | unsigned long long int acquisitionTimeAsLong; |
|
708 | unsigned long long int acquisitionTimeAsLong; | |
709 | unsigned char localAcquisitionTime[BYTES_PER_TIME]; |
|
709 | unsigned char localAcquisitionTime[BYTES_PER_TIME]; | |
710 | double deltaT; |
|
710 | double deltaT; | |
711 |
|
711 | |||
712 | deltaT = INIT_FLOAT; |
|
712 | deltaT = INIT_FLOAT; | |
713 |
|
713 | |||
714 | localAcquisitionTime[BYTE_0] = (unsigned char) ( coarseTime >> SHIFT_3_BYTES ); |
|
714 | localAcquisitionTime[BYTE_0] = (unsigned char) ( coarseTime >> SHIFT_3_BYTES ); | |
715 | localAcquisitionTime[BYTE_1] = (unsigned char) ( coarseTime >> SHIFT_2_BYTES ); |
|
715 | localAcquisitionTime[BYTE_1] = (unsigned char) ( coarseTime >> SHIFT_2_BYTES ); | |
716 | localAcquisitionTime[BYTE_2] = (unsigned char) ( coarseTime >> SHIFT_1_BYTE ); |
|
716 | localAcquisitionTime[BYTE_2] = (unsigned char) ( coarseTime >> SHIFT_1_BYTE ); | |
717 | localAcquisitionTime[BYTE_3] = (unsigned char) ( coarseTime ); |
|
717 | localAcquisitionTime[BYTE_3] = (unsigned char) ( coarseTime ); | |
718 | localAcquisitionTime[BYTE_4] = (unsigned char) ( fineTime >> SHIFT_1_BYTE ); |
|
718 | localAcquisitionTime[BYTE_4] = (unsigned char) ( fineTime >> SHIFT_1_BYTE ); | |
719 | localAcquisitionTime[BYTE_5] = (unsigned char) ( fineTime ); |
|
719 | localAcquisitionTime[BYTE_5] = (unsigned char) ( fineTime ); | |
720 |
|
720 | |||
721 | acquisitionTimeAsLong = ( (unsigned long long int) localAcquisitionTime[BYTE_0] << SHIFT_5_BYTES ) |
|
721 | acquisitionTimeAsLong = ( (unsigned long long int) localAcquisitionTime[BYTE_0] << SHIFT_5_BYTES ) | |
722 | + ( (unsigned long long int) localAcquisitionTime[BYTE_1] << SHIFT_4_BYTES ) |
|
722 | + ( (unsigned long long int) localAcquisitionTime[BYTE_1] << SHIFT_4_BYTES ) | |
723 | + ( (unsigned long long int) localAcquisitionTime[BYTE_2] << SHIFT_3_BYTES ) |
|
723 | + ( (unsigned long long int) localAcquisitionTime[BYTE_2] << SHIFT_3_BYTES ) | |
724 | + ( (unsigned long long int) localAcquisitionTime[BYTE_3] << SHIFT_2_BYTES ) |
|
724 | + ( (unsigned long long int) localAcquisitionTime[BYTE_3] << SHIFT_2_BYTES ) | |
725 | + ( (unsigned long long int) localAcquisitionTime[BYTE_4] << SHIFT_1_BYTE ) |
|
725 | + ( (unsigned long long int) localAcquisitionTime[BYTE_4] << SHIFT_1_BYTE ) | |
726 | + ( (unsigned long long int) localAcquisitionTime[BYTE_5] ); |
|
726 | + ( (unsigned long long int) localAcquisitionTime[BYTE_5] ); | |
727 |
|
727 | |||
728 | switch( sid ) |
|
728 | switch( sid ) | |
729 | { |
|
729 | { | |
730 | case SID_NORM_SWF_F0: |
|
730 | case SID_NORM_SWF_F0: | |
731 | deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * T0_IN_FINETIME ; |
|
731 | deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * T0_IN_FINETIME ; | |
732 | break; |
|
732 | break; | |
733 |
|
733 | |||
734 | case SID_NORM_SWF_F1: |
|
734 | case SID_NORM_SWF_F1: | |
735 | deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * T1_IN_FINETIME ; |
|
735 | deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * T1_IN_FINETIME ; | |
736 | break; |
|
736 | break; | |
737 |
|
737 | |||
738 | case SID_NORM_SWF_F2: |
|
738 | case SID_NORM_SWF_F2: | |
739 | deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * T2_IN_FINETIME ; |
|
739 | deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * T2_IN_FINETIME ; | |
740 | break; |
|
740 | break; | |
741 |
|
741 | |||
742 | case SID_SBM1_CWF_F1: |
|
742 | case SID_SBM1_CWF_F1: | |
743 | deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * T1_IN_FINETIME ; |
|
743 | deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * T1_IN_FINETIME ; | |
744 | break; |
|
744 | break; | |
745 |
|
745 | |||
746 | case SID_SBM2_CWF_F2: |
|
746 | case SID_SBM2_CWF_F2: | |
747 | deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * T2_IN_FINETIME ; |
|
747 | deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * T2_IN_FINETIME ; | |
748 | break; |
|
748 | break; | |
749 |
|
749 | |||
750 | case SID_BURST_CWF_F2: |
|
750 | case SID_BURST_CWF_F2: | |
751 | deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * T2_IN_FINETIME ; |
|
751 | deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * T2_IN_FINETIME ; | |
752 | break; |
|
752 | break; | |
753 |
|
753 | |||
754 | case SID_NORM_CWF_F3: |
|
754 | case SID_NORM_CWF_F3: | |
755 | deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF_SHORT_F3 * T3_IN_FINETIME ; |
|
755 | deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF_SHORT_F3 * T3_IN_FINETIME ; | |
756 | break; |
|
756 | break; | |
757 |
|
757 | |||
758 | case SID_NORM_CWF_LONG_F3: |
|
758 | case SID_NORM_CWF_LONG_F3: | |
759 | deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * T3_IN_FINETIME ; |
|
759 | deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * T3_IN_FINETIME ; | |
760 | break; |
|
760 | break; | |
761 |
|
761 | |||
762 | default: |
|
762 | default: | |
763 | PRINTF1("in compute_acquisition_time *** ERR unexpected sid %d\n", sid) |
|
763 | PRINTF1("in compute_acquisition_time *** ERR unexpected sid %d\n", sid) | |
764 | deltaT = 0.; |
|
764 | deltaT = 0.; | |
765 | break; |
|
765 | break; | |
766 | } |
|
766 | } | |
767 |
|
767 | |||
768 | acquisitionTimeAsLong = acquisitionTimeAsLong + (unsigned long long int) deltaT; |
|
768 | acquisitionTimeAsLong = acquisitionTimeAsLong + (unsigned long long int) deltaT; | |
769 | // |
|
769 | // | |
770 | acquisitionTime[BYTE_0] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_5_BYTES); |
|
770 | acquisitionTime[BYTE_0] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_5_BYTES); | |
771 | acquisitionTime[BYTE_1] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_4_BYTES); |
|
771 | acquisitionTime[BYTE_1] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_4_BYTES); | |
772 | acquisitionTime[BYTE_2] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_3_BYTES); |
|
772 | acquisitionTime[BYTE_2] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_3_BYTES); | |
773 | acquisitionTime[BYTE_3] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_2_BYTES); |
|
773 | acquisitionTime[BYTE_3] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_2_BYTES); | |
774 | acquisitionTime[BYTE_4] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_1_BYTE ); |
|
774 | acquisitionTime[BYTE_4] = (unsigned char) (acquisitionTimeAsLong >> SHIFT_1_BYTE ); | |
775 | acquisitionTime[BYTE_5] = (unsigned char) (acquisitionTimeAsLong ); |
|
775 | acquisitionTime[BYTE_5] = (unsigned char) (acquisitionTimeAsLong ); | |
776 |
|
776 | |||
777 | } |
|
777 | } | |
778 |
|
778 | |||
779 | void build_snapshot_from_ring( ring_node *ring_node_to_send, |
|
779 | void build_snapshot_from_ring( ring_node *ring_node_to_send, | |
780 | unsigned char frequencyChannel, |
|
780 | unsigned char frequencyChannel, | |
781 | unsigned long long int acquisitionTimeF0_asLong, |
|
781 | unsigned long long int acquisitionTimeF0_asLong, | |
782 | ring_node *ring_node_swf_extracted, |
|
782 | ring_node *ring_node_swf_extracted, | |
783 | int *swf_extracted) |
|
783 | int *swf_extracted) | |
784 | { |
|
784 | { | |
785 | unsigned int i; |
|
785 | unsigned int i; | |
786 | unsigned int node; |
|
786 | unsigned int node; | |
787 | unsigned long long int centerTime_asLong; |
|
787 | unsigned long long int centerTime_asLong; | |
788 | unsigned long long int acquisitionTime_asLong; |
|
788 | unsigned long long int acquisitionTime_asLong; | |
789 | unsigned long long int bufferAcquisitionTime_asLong; |
|
789 | unsigned long long int bufferAcquisitionTime_asLong; | |
790 | unsigned char *ptr1; |
|
790 | unsigned char *ptr1; | |
791 | unsigned char *ptr2; |
|
791 | unsigned char *ptr2; | |
792 | unsigned char *timeCharPtr; |
|
792 | unsigned char *timeCharPtr; | |
793 | unsigned char nb_ring_nodes; |
|
793 | unsigned char nb_ring_nodes; | |
794 | unsigned long long int frequency_asLong; |
|
794 | unsigned long long int frequency_asLong; | |
795 | unsigned long long int nbTicksPerSample_asLong; |
|
795 | unsigned long long int nbTicksPerSample_asLong; | |
796 | unsigned long long int nbSamplesPart1_asLong; |
|
796 | unsigned long long int nbSamplesPart1_asLong; | |
797 | unsigned long long int sampleOffset_asLong; |
|
797 | unsigned long long int sampleOffset_asLong; | |
798 |
|
798 | |||
799 | unsigned int deltaT_F0; |
|
799 | unsigned int deltaT_F0; | |
800 | unsigned int deltaT_F1; |
|
800 | unsigned int deltaT_F1; | |
801 | unsigned long long int deltaT_F2; |
|
801 | unsigned long long int deltaT_F2; | |
802 |
|
802 | |||
803 | deltaT_F0 = DELTAT_F0; |
|
803 | deltaT_F0 = DELTAT_F0; | |
804 | deltaT_F1 = DELTAF_F1; |
|
804 | deltaT_F1 = DELTAF_F1; | |
805 | deltaT_F2 = DELTAF_F2; |
|
805 | deltaT_F2 = DELTAF_F2; | |
806 | sampleOffset_asLong = INIT_CHAR; |
|
806 | sampleOffset_asLong = INIT_CHAR; | |
807 |
|
807 | |||
808 | // (1) get the f0 acquisition time => the value is passed in argument |
|
808 | // (1) get the f0 acquisition time => the value is passed in argument | |
809 |
|
809 | |||
810 | // (2) compute the central reference time |
|
810 | // (2) compute the central reference time | |
811 | centerTime_asLong = acquisitionTimeF0_asLong + deltaT_F0; |
|
811 | centerTime_asLong = acquisitionTimeF0_asLong + deltaT_F0; | |
812 | acquisitionTime_asLong = centerTime_asLong; //set to default value (Don_Initialisation_P2) |
|
812 | acquisitionTime_asLong = centerTime_asLong; //set to default value (Don_Initialisation_P2) | |
813 | bufferAcquisitionTime_asLong = centerTime_asLong; //set to default value (Don_Initialisation_P2) |
|
813 | bufferAcquisitionTime_asLong = centerTime_asLong; //set to default value (Don_Initialisation_P2) | |
814 | nbTicksPerSample_asLong = TICKS_PER_T2; //set to default value (Don_Initialisation_P2) |
|
814 | nbTicksPerSample_asLong = TICKS_PER_T2; //set to default value (Don_Initialisation_P2) | |
815 |
|
815 | |||
816 | // (3) compute the acquisition time of the current snapshot |
|
816 | // (3) compute the acquisition time of the current snapshot | |
817 | switch(frequencyChannel) |
|
817 | switch(frequencyChannel) | |
818 | { |
|
818 | { | |
819 | case CHANNELF1: // 1 is for F1 = 4096 Hz |
|
819 | case CHANNELF1: // 1 is for F1 = 4096 Hz | |
820 | acquisitionTime_asLong = centerTime_asLong - deltaT_F1; |
|
820 | acquisitionTime_asLong = centerTime_asLong - deltaT_F1; | |
821 | nb_ring_nodes = NB_RING_NODES_F1; |
|
821 | nb_ring_nodes = NB_RING_NODES_F1; | |
822 | frequency_asLong = FREQ_F1; |
|
822 | frequency_asLong = FREQ_F1; | |
823 | nbTicksPerSample_asLong = TICKS_PER_T1; // 65536 / 4096; |
|
823 | nbTicksPerSample_asLong = TICKS_PER_T1; // 65536 / 4096; | |
824 | break; |
|
824 | break; | |
825 | case CHANNELF2: // 2 is for F2 = 256 Hz |
|
825 | case CHANNELF2: // 2 is for F2 = 256 Hz | |
826 | acquisitionTime_asLong = centerTime_asLong - deltaT_F2; |
|
826 | acquisitionTime_asLong = centerTime_asLong - deltaT_F2; | |
827 | nb_ring_nodes = NB_RING_NODES_F2; |
|
827 | nb_ring_nodes = NB_RING_NODES_F2; | |
828 | frequency_asLong = FREQ_F2; |
|
828 | frequency_asLong = FREQ_F2; | |
829 | nbTicksPerSample_asLong = TICKS_PER_T2; // 65536 / 256; |
|
829 | nbTicksPerSample_asLong = TICKS_PER_T2; // 65536 / 256; | |
830 | break; |
|
830 | break; | |
831 | default: |
|
831 | default: | |
832 | acquisitionTime_asLong = centerTime_asLong; |
|
832 | acquisitionTime_asLong = centerTime_asLong; | |
833 | nb_ring_nodes = 0; |
|
833 | nb_ring_nodes = 0; | |
834 | frequency_asLong = FREQ_F2; |
|
834 | frequency_asLong = FREQ_F2; | |
835 | nbTicksPerSample_asLong = TICKS_PER_T2; |
|
835 | nbTicksPerSample_asLong = TICKS_PER_T2; | |
836 | break; |
|
836 | break; | |
837 | } |
|
837 | } | |
838 |
|
838 | |||
839 | //***************************************************************************** |
|
839 | //***************************************************************************** | |
840 | // (4) search the ring_node with the acquisition time <= acquisitionTime_asLong |
|
840 | // (4) search the ring_node with the acquisition time <= acquisitionTime_asLong | |
841 | node = 0; |
|
841 | node = 0; | |
842 | while ( node < nb_ring_nodes) |
|
842 | while ( node < nb_ring_nodes) | |
843 | { |
|
843 | { | |
844 | //PRINTF1("%d ... ", node); |
|
844 | //PRINTF1("%d ... ", node); | |
845 | bufferAcquisitionTime_asLong = get_acquisition_time( (unsigned char *) &ring_node_to_send->coarseTime ); |
|
845 | bufferAcquisitionTime_asLong = get_acquisition_time( (unsigned char *) &ring_node_to_send->coarseTime ); | |
846 | if (bufferAcquisitionTime_asLong <= acquisitionTime_asLong) |
|
846 | if (bufferAcquisitionTime_asLong <= acquisitionTime_asLong) | |
847 | { |
|
847 | { | |
848 | //PRINTF1("buffer found with acquisition time = %llx\n", bufferAcquisitionTime_asLong); |
|
848 | //PRINTF1("buffer found with acquisition time = %llx\n", bufferAcquisitionTime_asLong); | |
849 | node = nb_ring_nodes; |
|
849 | node = nb_ring_nodes; | |
850 | } |
|
850 | } | |
851 | else |
|
851 | else | |
852 | { |
|
852 | { | |
853 | node = node + 1; |
|
853 | node = node + 1; | |
854 | ring_node_to_send = ring_node_to_send->previous; |
|
854 | ring_node_to_send = ring_node_to_send->previous; | |
855 | } |
|
855 | } | |
856 | } |
|
856 | } | |
857 |
|
857 | |||
858 | // (5) compute the number of samples to take in the current buffer |
|
858 | // (5) compute the number of samples to take in the current buffer | |
859 | sampleOffset_asLong = ((acquisitionTime_asLong - bufferAcquisitionTime_asLong) * frequency_asLong ) >> SHIFT_2_BYTES; |
|
859 | sampleOffset_asLong = ((acquisitionTime_asLong - bufferAcquisitionTime_asLong) * frequency_asLong ) >> SHIFT_2_BYTES; | |
860 | nbSamplesPart1_asLong = NB_SAMPLES_PER_SNAPSHOT - sampleOffset_asLong; |
|
860 | nbSamplesPart1_asLong = NB_SAMPLES_PER_SNAPSHOT - sampleOffset_asLong; | |
861 | //PRINTF2("sampleOffset_asLong = %lld, nbSamplesPart1_asLong = %lld\n", sampleOffset_asLong, nbSamplesPart1_asLong); |
|
861 | //PRINTF2("sampleOffset_asLong = %lld, nbSamplesPart1_asLong = %lld\n", sampleOffset_asLong, nbSamplesPart1_asLong); | |
862 |
|
862 | |||
863 | // (6) compute the final acquisition time |
|
863 | // (6) compute the final acquisition time | |
864 | acquisitionTime_asLong = bufferAcquisitionTime_asLong + |
|
864 | acquisitionTime_asLong = bufferAcquisitionTime_asLong + | |
865 | (sampleOffset_asLong * nbTicksPerSample_asLong); |
|
865 | (sampleOffset_asLong * nbTicksPerSample_asLong); | |
866 |
|
866 | |||
867 | // (7) copy the acquisition time at the beginning of the extrated snapshot |
|
867 | // (7) copy the acquisition time at the beginning of the extrated snapshot | |
868 | ptr1 = (unsigned char*) &acquisitionTime_asLong; |
|
868 | ptr1 = (unsigned char*) &acquisitionTime_asLong; | |
869 | // fine time |
|
869 | // fine time | |
870 | ptr2 = (unsigned char*) &ring_node_swf_extracted->fineTime; |
|
870 | ptr2 = (unsigned char*) &ring_node_swf_extracted->fineTime; | |
871 | ptr2[BYTE_2] = ptr1[ BYTE_4 + OFFSET_2_BYTES ]; |
|
871 | ptr2[BYTE_2] = ptr1[ BYTE_4 + OFFSET_2_BYTES ]; | |
872 | ptr2[BYTE_3] = ptr1[ BYTE_5 + OFFSET_2_BYTES ]; |
|
872 | ptr2[BYTE_3] = ptr1[ BYTE_5 + OFFSET_2_BYTES ]; | |
873 | // coarse time |
|
873 | // coarse time | |
874 | ptr2 = (unsigned char*) &ring_node_swf_extracted->coarseTime; |
|
874 | ptr2 = (unsigned char*) &ring_node_swf_extracted->coarseTime; | |
875 | ptr2[BYTE_0] = ptr1[ BYTE_0 + OFFSET_2_BYTES ]; |
|
875 | ptr2[BYTE_0] = ptr1[ BYTE_0 + OFFSET_2_BYTES ]; | |
876 | ptr2[BYTE_1] = ptr1[ BYTE_1 + OFFSET_2_BYTES ]; |
|
876 | ptr2[BYTE_1] = ptr1[ BYTE_1 + OFFSET_2_BYTES ]; | |
877 | ptr2[BYTE_2] = ptr1[ BYTE_2 + OFFSET_2_BYTES ]; |
|
877 | ptr2[BYTE_2] = ptr1[ BYTE_2 + OFFSET_2_BYTES ]; | |
878 | ptr2[BYTE_3] = ptr1[ BYTE_3 + OFFSET_2_BYTES ]; |
|
878 | ptr2[BYTE_3] = ptr1[ BYTE_3 + OFFSET_2_BYTES ]; | |
879 |
|
879 | |||
880 | // re set the synchronization bit |
|
880 | // re set the synchronization bit | |
881 | timeCharPtr = (unsigned char*) &ring_node_to_send->coarseTime; |
|
881 | timeCharPtr = (unsigned char*) &ring_node_to_send->coarseTime; | |
882 | ptr2[0] = ptr2[0] | (timeCharPtr[0] & SYNC_BIT); // [1000 0000] |
|
882 | ptr2[0] = ptr2[0] | (timeCharPtr[0] & SYNC_BIT); // [1000 0000] | |
883 |
|
883 | |||
884 | if ( (nbSamplesPart1_asLong >= NB_SAMPLES_PER_SNAPSHOT) | (nbSamplesPart1_asLong < 0) ) |
|
884 | if ( (nbSamplesPart1_asLong >= NB_SAMPLES_PER_SNAPSHOT) | (nbSamplesPart1_asLong < 0) ) | |
885 | { |
|
885 | { | |
886 | nbSamplesPart1_asLong = 0; |
|
886 | nbSamplesPart1_asLong = 0; | |
887 | } |
|
887 | } | |
888 | // copy the part 1 of the snapshot in the extracted buffer |
|
888 | // copy the part 1 of the snapshot in the extracted buffer | |
889 | for ( i = 0; i < (nbSamplesPart1_asLong * NB_WORDS_SWF_BLK); i++ ) |
|
889 | for ( i = 0; i < (nbSamplesPart1_asLong * NB_WORDS_SWF_BLK); i++ ) | |
890 | { |
|
890 | { | |
891 | swf_extracted[i] = |
|
891 | swf_extracted[i] = | |
892 | ((int*) ring_node_to_send->buffer_address)[ i + (sampleOffset_asLong * NB_WORDS_SWF_BLK) ]; |
|
892 | ((int*) ring_node_to_send->buffer_address)[ i + (sampleOffset_asLong * NB_WORDS_SWF_BLK) ]; | |
893 | } |
|
893 | } | |
894 | // copy the part 2 of the snapshot in the extracted buffer |
|
894 | // copy the part 2 of the snapshot in the extracted buffer | |
895 | ring_node_to_send = ring_node_to_send->next; |
|
895 | ring_node_to_send = ring_node_to_send->next; | |
896 | for ( i = (nbSamplesPart1_asLong * NB_WORDS_SWF_BLK); i < (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK); i++ ) |
|
896 | for ( i = (nbSamplesPart1_asLong * NB_WORDS_SWF_BLK); i < (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK); i++ ) | |
897 | { |
|
897 | { | |
898 | swf_extracted[i] = |
|
898 | swf_extracted[i] = | |
899 | ((int*) ring_node_to_send->buffer_address)[ (i-(nbSamplesPart1_asLong * NB_WORDS_SWF_BLK)) ]; |
|
899 | ((int*) ring_node_to_send->buffer_address)[ (i-(nbSamplesPart1_asLong * NB_WORDS_SWF_BLK)) ]; | |
900 | } |
|
900 | } | |
901 | } |
|
901 | } | |
902 |
|
902 | |||
903 | double computeCorrection( unsigned char *timePtr ) |
|
903 | double computeCorrection( unsigned char *timePtr ) | |
904 | { |
|
904 | { | |
905 | unsigned long long int acquisitionTime; |
|
905 | unsigned long long int acquisitionTime; | |
906 | unsigned long long int centerTime; |
|
906 | unsigned long long int centerTime; | |
907 | unsigned long long int previousTick; |
|
907 | unsigned long long int previousTick; | |
908 | unsigned long long int nextTick; |
|
908 | unsigned long long int nextTick; | |
909 | unsigned long long int deltaPreviousTick; |
|
909 | unsigned long long int deltaPreviousTick; | |
910 | unsigned long long int deltaNextTick; |
|
910 | unsigned long long int deltaNextTick; | |
911 | double deltaPrevious_ms; |
|
911 | double deltaPrevious_ms; | |
912 | double deltaNext_ms; |
|
912 | double deltaNext_ms; | |
913 | double correctionInF2; |
|
913 | double correctionInF2; | |
914 |
|
914 | |||
915 | correctionInF2 = 0; //set to default value (Don_Initialisation_P2) |
|
915 | correctionInF2 = 0; //set to default value (Don_Initialisation_P2) | |
916 |
|
916 | |||
917 | // get acquisition time in fine time ticks |
|
917 | // get acquisition time in fine time ticks | |
918 | acquisitionTime = get_acquisition_time( timePtr ); |
|
918 | acquisitionTime = get_acquisition_time( timePtr ); | |
919 |
|
919 | |||
920 | // compute center time |
|
920 | // compute center time | |
921 | centerTime = acquisitionTime + DELTAT_F0; // (2048. / 24576. / 2.) * 65536. = 2730.667; |
|
921 | centerTime = acquisitionTime + DELTAT_F0; // (2048. / 24576. / 2.) * 65536. = 2730.667; | |
922 | previousTick = centerTime - (centerTime & INT16_ALL_F); |
|
922 | previousTick = centerTime - (centerTime & INT16_ALL_F); | |
923 | nextTick = previousTick + TICKS_PER_S; |
|
923 | nextTick = previousTick + TICKS_PER_S; | |
924 |
|
924 | |||
925 | deltaPreviousTick = centerTime - previousTick; |
|
925 | deltaPreviousTick = centerTime - previousTick; | |
926 | deltaNextTick = nextTick - centerTime; |
|
926 | deltaNextTick = nextTick - centerTime; | |
927 |
|
927 | |||
928 | deltaPrevious_ms = (((double) deltaPreviousTick) / TICKS_PER_S) * MS_PER_S; |
|
928 | deltaPrevious_ms = (((double) deltaPreviousTick) / TICKS_PER_S) * MS_PER_S; | |
929 | deltaNext_ms = (((double) deltaNextTick) / TICKS_PER_S) * MS_PER_S; |
|
929 | deltaNext_ms = (((double) deltaNextTick) / TICKS_PER_S) * MS_PER_S; | |
930 |
|
930 | |||
931 | PRINTF2(" delta previous = %.3f ms, delta next = %.2f ms\n", deltaPrevious_ms, deltaNext_ms); |
|
931 | PRINTF2(" delta previous = %.3f ms, delta next = %.2f ms\n", deltaPrevious_ms, deltaNext_ms); | |
932 |
|
932 | |||
933 | // which tick is the closest? |
|
933 | // which tick is the closest? | |
934 | if (deltaPreviousTick > deltaNextTick) |
|
934 | if (deltaPreviousTick > deltaNextTick) | |
935 | { |
|
935 | { | |
936 | // the snapshot center is just before the second => increase delta_snapshot |
|
936 | // the snapshot center is just before the second => increase delta_snapshot | |
937 | correctionInF2 = + (deltaNext_ms * FREQ_F2 / MS_PER_S ); |
|
937 | correctionInF2 = + (deltaNext_ms * FREQ_F2 / MS_PER_S ); | |
938 | } |
|
938 | } | |
939 | else |
|
939 | else | |
940 | { |
|
940 | { | |
941 | // the snapshot center is just after the second => decrease delta_snapshot |
|
941 | // the snapshot center is just after the second => decrease delta_snapshot | |
942 | correctionInF2 = - (deltaPrevious_ms * FREQ_F2 / MS_PER_S ); |
|
942 | correctionInF2 = - (deltaPrevious_ms * FREQ_F2 / MS_PER_S ); | |
943 | } |
|
943 | } | |
944 |
|
944 | |||
945 | PRINTF1(" correctionInF2 = %.2f\n", correctionInF2); |
|
945 | PRINTF1(" correctionInF2 = %.2f\n", correctionInF2); | |
946 |
|
946 | |||
947 | return correctionInF2; |
|
947 | return correctionInF2; | |
948 | } |
|
948 | } | |
949 |
|
949 | |||
950 | void applyCorrection( double correction ) |
|
950 | void applyCorrection( double correction ) | |
951 | { |
|
951 | { | |
952 | int correctionInt; |
|
952 | int correctionInt; | |
953 |
|
953 | |||
954 | correctionInt = 0; |
|
954 | correctionInt = 0; | |
955 |
|
955 | |||
956 | if (correction >= 0.) |
|
956 | if (correction >= 0.) | |
957 | { |
|
957 | { | |
958 | if ( (ONE_TICK_CORR_INTERVAL_0_MIN < correction) && (correction < ONE_TICK_CORR_INTERVAL_0_MAX) ) |
|
958 | if ( (ONE_TICK_CORR_INTERVAL_0_MIN < correction) && (correction < ONE_TICK_CORR_INTERVAL_0_MAX) ) | |
959 | { |
|
959 | { | |
960 | correctionInt = ONE_TICK_CORR; |
|
960 | correctionInt = ONE_TICK_CORR; | |
961 | } |
|
961 | } | |
962 | else |
|
962 | else | |
963 | { |
|
963 | { | |
964 | correctionInt = CORR_MULT * floor(correction); |
|
964 | correctionInt = CORR_MULT * floor(correction); | |
965 | } |
|
965 | } | |
966 | } |
|
966 | } | |
967 | else |
|
967 | else | |
968 | { |
|
968 | { | |
969 | if ( (ONE_TICK_CORR_INTERVAL_1_MIN < correction) && (correction < ONE_TICK_CORR_INTERVAL_1_MAX) ) |
|
969 | if ( (ONE_TICK_CORR_INTERVAL_1_MIN < correction) && (correction < ONE_TICK_CORR_INTERVAL_1_MAX) ) | |
970 | { |
|
970 | { | |
971 | correctionInt = -ONE_TICK_CORR; |
|
971 | correctionInt = -ONE_TICK_CORR; | |
972 | } |
|
972 | } | |
973 | else |
|
973 | else | |
974 | { |
|
974 | { | |
975 | correctionInt = CORR_MULT * ceil(correction); |
|
975 | correctionInt = CORR_MULT * ceil(correction); | |
976 | } |
|
976 | } | |
977 | } |
|
977 | } | |
978 | waveform_picker_regs->delta_snapshot = waveform_picker_regs->delta_snapshot + correctionInt; |
|
978 | waveform_picker_regs->delta_snapshot = waveform_picker_regs->delta_snapshot + correctionInt; | |
979 | } |
|
979 | } | |
980 |
|
980 | |||
981 | void snapshot_resynchronization( unsigned char *timePtr ) |
|
981 | void snapshot_resynchronization( unsigned char *timePtr ) | |
982 | { |
|
982 | { | |
983 | /** This function compute a correction to apply on delta_snapshot. |
|
983 | /** This function compute a correction to apply on delta_snapshot. | |
984 | * |
|
984 | * | |
985 | * |
|
985 | * | |
986 | * @param timePtr is a pointer to the acquisition time of the snapshot being considered. |
|
986 | * @param timePtr is a pointer to the acquisition time of the snapshot being considered. | |
987 | * |
|
987 | * | |
988 | * @return void |
|
988 | * @return void | |
989 | * |
|
989 | * | |
990 | */ |
|
990 | */ | |
991 |
|
991 | |||
992 | static double correction = INIT_FLOAT; |
|
992 | static double correction = INIT_FLOAT; | |
993 | static resynchro_state state = MEASURE; |
|
993 | static resynchro_state state = MEASURE; | |
994 | static unsigned int nbSnapshots = 0; |
|
994 | static unsigned int nbSnapshots = 0; | |
995 |
|
995 | |||
996 | int correctionInt; |
|
996 | int correctionInt; | |
997 |
|
997 | |||
998 | correctionInt = 0; |
|
998 | correctionInt = 0; | |
999 |
|
999 | |||
1000 | switch (state) |
|
1000 | switch (state) | |
1001 | { |
|
1001 | { | |
1002 |
|
1002 | |||
1003 | case MEASURE: |
|
1003 | case MEASURE: | |
1004 | // ******** |
|
1004 | // ******** | |
1005 | PRINTF1("MEASURE === %d\n", nbSnapshots); |
|
1005 | PRINTF1("MEASURE === %d\n", nbSnapshots); | |
1006 | state = CORRECTION; |
|
1006 | state = CORRECTION; | |
1007 | correction = computeCorrection( timePtr ); |
|
1007 | correction = computeCorrection( timePtr ); | |
1008 | PRINTF1("MEASURE === correction = %.2f\n", correction ); |
|
1008 | PRINTF1("MEASURE === correction = %.2f\n", correction ); | |
1009 | applyCorrection( correction ); |
|
1009 | applyCorrection( correction ); | |
1010 | PRINTF1("MEASURE === delta_snapshot = %d\n", waveform_picker_regs->delta_snapshot); |
|
1010 | PRINTF1("MEASURE === delta_snapshot = %d\n", waveform_picker_regs->delta_snapshot); | |
1011 | //**** |
|
1011 | //**** | |
1012 | break; |
|
1012 | break; | |
1013 |
|
1013 | |||
1014 | case CORRECTION: |
|
1014 | case CORRECTION: | |
1015 | //************ |
|
1015 | //************ | |
1016 | PRINTF1("CORRECTION === %d\n", nbSnapshots); |
|
1016 | PRINTF1("CORRECTION === %d\n", nbSnapshots); | |
1017 | state = MEASURE; |
|
1017 | state = MEASURE; | |
1018 | computeCorrection( timePtr ); |
|
1018 | computeCorrection( timePtr ); | |
1019 | set_wfp_delta_snapshot(); |
|
1019 | set_wfp_delta_snapshot(); | |
1020 | PRINTF1("CORRECTION === delta_snapshot = %d\n", waveform_picker_regs->delta_snapshot); |
|
1020 | PRINTF1("CORRECTION === delta_snapshot = %d\n", waveform_picker_regs->delta_snapshot); | |
1021 | //**** |
|
1021 | //**** | |
1022 | break; |
|
1022 | break; | |
1023 |
|
1023 | |||
1024 | default: |
|
1024 | default: | |
1025 | break; |
|
1025 | break; | |
1026 |
|
1026 | |||
1027 | } |
|
1027 | } | |
1028 |
|
1028 | |||
1029 | nbSnapshots++; |
|
1029 | nbSnapshots++; | |
1030 | } |
|
1030 | } | |
1031 |
|
1031 | |||
1032 | //************** |
|
1032 | //************** | |
1033 | // wfp registers |
|
1033 | // wfp registers | |
1034 | void reset_wfp_burst_enable( void ) |
|
1034 | void reset_wfp_burst_enable( void ) | |
1035 | { |
|
1035 | { | |
1036 | /** This function resets the waveform picker burst_enable register. |
|
1036 | /** This function resets the waveform picker burst_enable register. | |
1037 | * |
|
1037 | * | |
1038 | * The burst bits [f2 f1 f0] and the enable bits [f3 f2 f1 f0] are set to 0. |
|
1038 | * The burst bits [f2 f1 f0] and the enable bits [f3 f2 f1 f0] are set to 0. | |
1039 | * |
|
1039 | * | |
1040 | */ |
|
1040 | */ | |
1041 |
|
1041 | |||
1042 | // [1000 000] burst f2, f1, f0 enable f3, f2, f1, f0 |
|
1042 | // [1000 000] burst f2, f1, f0 enable f3, f2, f1, f0 | |
1043 | waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable & RST_BITS_RUN_BURST_EN; |
|
1043 | waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable & RST_BITS_RUN_BURST_EN; | |
1044 | } |
|
1044 | } | |
1045 |
|
1045 | |||
1046 | void reset_wfp_status( void ) |
|
1046 | void reset_wfp_status( void ) | |
1047 | { |
|
1047 | { | |
1048 | /** This function resets the waveform picker status register. |
|
1048 | /** This function resets the waveform picker status register. | |
1049 | * |
|
1049 | * | |
1050 | * All status bits are set to 0 [new_err full_err full]. |
|
1050 | * All status bits are set to 0 [new_err full_err full]. | |
1051 | * |
|
1051 | * | |
1052 | */ |
|
1052 | */ | |
1053 |
|
1053 | |||
1054 | waveform_picker_regs->status = INT16_ALL_F; |
|
1054 | waveform_picker_regs->status = INT16_ALL_F; | |
1055 | } |
|
1055 | } | |
1056 |
|
1056 | |||
1057 | void reset_wfp_buffer_addresses( void ) |
|
1057 | void reset_wfp_buffer_addresses( void ) | |
1058 | { |
|
1058 | { | |
1059 | // F0 |
|
1059 | // F0 | |
1060 | waveform_picker_regs->addr_data_f0_0 = current_ring_node_f0->previous->buffer_address; // 0x08 |
|
1060 | waveform_picker_regs->addr_data_f0_0 = current_ring_node_f0->previous->buffer_address; // 0x08 | |
1061 | waveform_picker_regs->addr_data_f0_1 = current_ring_node_f0->buffer_address; // 0x0c |
|
1061 | waveform_picker_regs->addr_data_f0_1 = current_ring_node_f0->buffer_address; // 0x0c | |
1062 | // F1 |
|
1062 | // F1 | |
1063 | waveform_picker_regs->addr_data_f1_0 = current_ring_node_f1->previous->buffer_address; // 0x10 |
|
1063 | waveform_picker_regs->addr_data_f1_0 = current_ring_node_f1->previous->buffer_address; // 0x10 | |
1064 | waveform_picker_regs->addr_data_f1_1 = current_ring_node_f1->buffer_address; // 0x14 |
|
1064 | waveform_picker_regs->addr_data_f1_1 = current_ring_node_f1->buffer_address; // 0x14 | |
1065 | // F2 |
|
1065 | // F2 | |
1066 | waveform_picker_regs->addr_data_f2_0 = current_ring_node_f2->previous->buffer_address; // 0x18 |
|
1066 | waveform_picker_regs->addr_data_f2_0 = current_ring_node_f2->previous->buffer_address; // 0x18 | |
1067 | waveform_picker_regs->addr_data_f2_1 = current_ring_node_f2->buffer_address; // 0x1c |
|
1067 | waveform_picker_regs->addr_data_f2_1 = current_ring_node_f2->buffer_address; // 0x1c | |
1068 | // F3 |
|
1068 | // F3 | |
1069 | waveform_picker_regs->addr_data_f3_0 = current_ring_node_f3->previous->buffer_address; // 0x20 |
|
1069 | waveform_picker_regs->addr_data_f3_0 = current_ring_node_f3->previous->buffer_address; // 0x20 | |
1070 | waveform_picker_regs->addr_data_f3_1 = current_ring_node_f3->buffer_address; // 0x24 |
|
1070 | waveform_picker_regs->addr_data_f3_1 = current_ring_node_f3->buffer_address; // 0x24 | |
1071 | } |
|
1071 | } | |
1072 |
|
1072 | |||
1073 | void reset_waveform_picker_regs( void ) |
|
1073 | void reset_waveform_picker_regs( void ) | |
1074 | { |
|
1074 | { | |
1075 | /** This function resets the waveform picker module registers. |
|
1075 | /** This function resets the waveform picker module registers. | |
1076 | * |
|
1076 | * | |
1077 | * The registers affected by this function are located at the following offset addresses: |
|
1077 | * The registers affected by this function are located at the following offset addresses: | |
1078 | * - 0x00 data_shaping |
|
1078 | * - 0x00 data_shaping | |
1079 | * - 0x04 run_burst_enable |
|
1079 | * - 0x04 run_burst_enable | |
1080 | * - 0x08 addr_data_f0 |
|
1080 | * - 0x08 addr_data_f0 | |
1081 | * - 0x0C addr_data_f1 |
|
1081 | * - 0x0C addr_data_f1 | |
1082 | * - 0x10 addr_data_f2 |
|
1082 | * - 0x10 addr_data_f2 | |
1083 | * - 0x14 addr_data_f3 |
|
1083 | * - 0x14 addr_data_f3 | |
1084 | * - 0x18 status |
|
1084 | * - 0x18 status | |
1085 | * - 0x1C delta_snapshot |
|
1085 | * - 0x1C delta_snapshot | |
1086 | * - 0x20 delta_f0 |
|
1086 | * - 0x20 delta_f0 | |
1087 | * - 0x24 delta_f0_2 |
|
1087 | * - 0x24 delta_f0_2 | |
1088 | * - 0x28 delta_f1 (obsolet parameter) |
|
1088 | * - 0x28 delta_f1 (obsolet parameter) | |
1089 | * - 0x2c delta_f2 |
|
1089 | * - 0x2c delta_f2 | |
1090 | * - 0x30 nb_data_by_buffer |
|
1090 | * - 0x30 nb_data_by_buffer | |
1091 | * - 0x34 nb_snapshot_param |
|
1091 | * - 0x34 nb_snapshot_param | |
1092 | * - 0x38 start_date |
|
1092 | * - 0x38 start_date | |
1093 | * - 0x3c nb_word_in_buffer |
|
1093 | * - 0x3c nb_word_in_buffer | |
1094 | * |
|
1094 | * | |
1095 | */ |
|
1095 | */ | |
1096 |
|
1096 | |||
1097 | set_wfp_data_shaping(); // 0x00 *** R1 R0 SP1 SP0 BW |
|
1097 | set_wfp_data_shaping(); // 0x00 *** R1 R0 SP1 SP0 BW | |
1098 |
|
1098 | |||
1099 | reset_wfp_burst_enable(); // 0x04 *** [run *** burst f2, f1, f0 *** enable f3, f2, f1, f0 ] |
|
1099 | reset_wfp_burst_enable(); // 0x04 *** [run *** burst f2, f1, f0 *** enable f3, f2, f1, f0 ] | |
1100 |
|
1100 | |||
1101 | reset_wfp_buffer_addresses(); |
|
1101 | reset_wfp_buffer_addresses(); | |
1102 |
|
1102 | |||
1103 | reset_wfp_status(); // 0x18 |
|
1103 | reset_wfp_status(); // 0x18 | |
1104 |
|
1104 | |||
1105 | set_wfp_delta_snapshot(); // 0x1c *** 300 s => 0x12bff |
|
1105 | set_wfp_delta_snapshot(); // 0x1c *** 300 s => 0x12bff | |
1106 |
|
1106 | |||
1107 | set_wfp_delta_f0_f0_2(); // 0x20, 0x24 |
|
1107 | set_wfp_delta_f0_f0_2(); // 0x20, 0x24 | |
1108 |
|
1108 | |||
1109 | //the parameter delta_f1 [0x28] is not used anymore |
|
1109 | //the parameter delta_f1 [0x28] is not used anymore | |
1110 |
|
1110 | |||
1111 | set_wfp_delta_f2(); // 0x2c |
|
1111 | set_wfp_delta_f2(); // 0x2c | |
1112 |
|
1112 | |||
1113 | DEBUG_PRINTF1("delta_snapshot %x\n", waveform_picker_regs->delta_snapshot); |
|
1113 | DEBUG_PRINTF1("delta_snapshot %x\n", waveform_picker_regs->delta_snapshot); | |
1114 | DEBUG_PRINTF1("delta_f0 %x\n", waveform_picker_regs->delta_f0); |
|
1114 | DEBUG_PRINTF1("delta_f0 %x\n", waveform_picker_regs->delta_f0); | |
1115 | DEBUG_PRINTF1("delta_f0_2 %x\n", waveform_picker_regs->delta_f0_2); |
|
1115 | DEBUG_PRINTF1("delta_f0_2 %x\n", waveform_picker_regs->delta_f0_2); | |
1116 | DEBUG_PRINTF1("delta_f1 %x\n", waveform_picker_regs->delta_f1); |
|
1116 | DEBUG_PRINTF1("delta_f1 %x\n", waveform_picker_regs->delta_f1); | |
1117 | DEBUG_PRINTF1("delta_f2 %x\n", waveform_picker_regs->delta_f2); |
|
1117 | DEBUG_PRINTF1("delta_f2 %x\n", waveform_picker_regs->delta_f2); | |
1118 | // 2688 = 8 * 336 |
|
1118 | // 2688 = 8 * 336 | |
1119 | waveform_picker_regs->nb_data_by_buffer = DFLT_WFP_NB_DATA_BY_BUFFER; // 0x30 *** 2688 - 1 => nb samples -1 |
|
1119 | waveform_picker_regs->nb_data_by_buffer = DFLT_WFP_NB_DATA_BY_BUFFER; // 0x30 *** 2688 - 1 => nb samples -1 | |
1120 | waveform_picker_regs->snapshot_param = DFLT_WFP_SNAPSHOT_PARAM; // 0x34 *** 2688 => nb samples |
|
1120 | waveform_picker_regs->snapshot_param = DFLT_WFP_SNAPSHOT_PARAM; // 0x34 *** 2688 => nb samples | |
1121 | waveform_picker_regs->start_date = COARSE_TIME_MASK; |
|
1121 | waveform_picker_regs->start_date = COARSE_TIME_MASK; | |
1122 | // |
|
1122 | // | |
1123 | // coarse time and fine time registers are not initialized, they are volatile |
|
1123 | // coarse time and fine time registers are not initialized, they are volatile | |
1124 | // |
|
1124 | // | |
1125 | waveform_picker_regs->buffer_length = DFLT_WFP_BUFFER_LENGTH; // buffer length in burst = 3 * 2688 / 16 = 504 = 0x1f8 |
|
1125 | waveform_picker_regs->buffer_length = DFLT_WFP_BUFFER_LENGTH; // buffer length in burst = 3 * 2688 / 16 = 504 = 0x1f8 | |
1126 | } |
|
1126 | } | |
1127 |
|
1127 | |||
1128 | void set_wfp_data_shaping( void ) |
|
1128 | void set_wfp_data_shaping( void ) | |
1129 | { |
|
1129 | { | |
1130 | /** This function sets the data_shaping register of the waveform picker module. |
|
1130 | /** This function sets the data_shaping register of the waveform picker module. | |
1131 | * |
|
1131 | * | |
1132 | * The value is read from one field of the parameter_dump_packet structure:\n |
|
1132 | * The value is read from one field of the parameter_dump_packet structure:\n | |
1133 | * bw_sp0_sp1_r0_r1 |
|
1133 | * bw_sp0_sp1_r0_r1 | |
1134 | * |
|
1134 | * | |
1135 | */ |
|
1135 | */ | |
1136 |
|
1136 | |||
1137 | unsigned char data_shaping; |
|
1137 | unsigned char data_shaping; | |
1138 |
|
1138 | |||
1139 | // get the parameters for the data shaping [BW SP0 SP1 R0 R1] in sy_lfr_common1 and configure the register |
|
1139 | // get the parameters for the data shaping [BW SP0 SP1 R0 R1] in sy_lfr_common1 and configure the register | |
1140 | // waveform picker : [R1 R0 SP1 SP0 BW] |
|
1140 | // waveform picker : [R1 R0 SP1 SP0 BW] | |
1141 |
|
1141 | |||
1142 | data_shaping = parameter_dump_packet.sy_lfr_common_parameters; |
|
1142 | data_shaping = parameter_dump_packet.sy_lfr_common_parameters; | |
1143 |
|
1143 | |||
1144 | waveform_picker_regs->data_shaping = |
|
1144 | waveform_picker_regs->data_shaping = | |
1145 | ( (data_shaping & BIT_5) >> SHIFT_5_BITS ) // BW |
|
1145 | ( (data_shaping & BIT_5) >> SHIFT_5_BITS ) // BW | |
1146 | + ( (data_shaping & BIT_4) >> SHIFT_3_BITS ) // SP0 |
|
1146 | + ( (data_shaping & BIT_4) >> SHIFT_3_BITS ) // SP0 | |
1147 | + ( (data_shaping & BIT_3) >> 1 ) // SP1 |
|
1147 | + ( (data_shaping & BIT_3) >> 1 ) // SP1 | |
1148 | + ( (data_shaping & BIT_2) << 1 ) // R0 |
|
1148 | + ( (data_shaping & BIT_2) << 1 ) // R0 | |
1149 | + ( (data_shaping & BIT_1) << SHIFT_3_BITS ) // R1 |
|
1149 | + ( (data_shaping & BIT_1) << SHIFT_3_BITS ) // R1 | |
1150 | + ( (data_shaping & BIT_0) << SHIFT_5_BITS ); // R2 |
|
1150 | + ( (data_shaping & BIT_0) << SHIFT_5_BITS ); // R2 | |
1151 | } |
|
1151 | } | |
1152 |
|
1152 | |||
1153 | void set_wfp_burst_enable_register( unsigned char mode ) |
|
1153 | void set_wfp_burst_enable_register( unsigned char mode ) | |
1154 | { |
|
1154 | { | |
1155 | /** This function sets the waveform picker burst_enable register depending on the mode. |
|
1155 | /** This function sets the waveform picker burst_enable register depending on the mode. | |
1156 | * |
|
1156 | * | |
1157 | * @param mode is the LFR mode to launch. |
|
1157 | * @param mode is the LFR mode to launch. | |
1158 | * |
|
1158 | * | |
1159 | * The burst bits shall be before the enable bits. |
|
1159 | * The burst bits shall be before the enable bits. | |
1160 | * |
|
1160 | * | |
1161 | */ |
|
1161 | */ | |
1162 |
|
1162 | |||
1163 | // [0000 0000] burst f2, f1, f0 enable f3 f2 f1 f0 |
|
1163 | // [0000 0000] burst f2, f1, f0 enable f3 f2 f1 f0 | |
1164 | // the burst bits shall be set first, before the enable bits |
|
1164 | // the burst bits shall be set first, before the enable bits | |
1165 | switch(mode) { |
|
1165 | switch(mode) { | |
1166 | case LFR_MODE_NORMAL: |
|
1166 | case LFR_MODE_NORMAL: | |
1167 | case LFR_MODE_SBM1: |
|
1167 | case LFR_MODE_SBM1: | |
1168 | case LFR_MODE_SBM2: |
|
1168 | case LFR_MODE_SBM2: | |
1169 | waveform_picker_regs->run_burst_enable = RUN_BURST_ENABLE_SBM2; // [0110 0000] enable f2 and f1 burst |
|
1169 | waveform_picker_regs->run_burst_enable = RUN_BURST_ENABLE_SBM2; // [0110 0000] enable f2 and f1 burst | |
1170 | waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | BITS_WFP_ENABLE_ALL; // [1111] enable f3 f2 f1 f0 |
|
1170 | waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | BITS_WFP_ENABLE_ALL; // [1111] enable f3 f2 f1 f0 | |
1171 | break; |
|
1171 | break; | |
1172 | case LFR_MODE_BURST: |
|
1172 | case LFR_MODE_BURST: | |
1173 | waveform_picker_regs->run_burst_enable = RUN_BURST_ENABLE_BURST; // [0100 0000] f2 burst enabled |
|
1173 | waveform_picker_regs->run_burst_enable = RUN_BURST_ENABLE_BURST; // [0100 0000] f2 burst enabled | |
1174 | waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | BITS_WFP_ENABLE_BURST; // [1100] enable f3 and f2 |
|
1174 | waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | BITS_WFP_ENABLE_BURST; // [1100] enable f3 and f2 | |
1175 | break; |
|
1175 | break; | |
1176 | default: |
|
1176 | default: | |
1177 | waveform_picker_regs->run_burst_enable = INIT_CHAR; // [0000 0000] no burst enabled, no waveform enabled |
|
1177 | waveform_picker_regs->run_burst_enable = INIT_CHAR; // [0000 0000] no burst enabled, no waveform enabled | |
1178 | break; |
|
1178 | break; | |
1179 | } |
|
1179 | } | |
1180 | } |
|
1180 | } | |
1181 |
|
1181 | |||
1182 | void set_wfp_delta_snapshot( void ) |
|
1182 | void set_wfp_delta_snapshot( void ) | |
1183 | { |
|
1183 | { | |
1184 | /** This function sets the delta_snapshot register of the waveform picker module. |
|
1184 | /** This function sets the delta_snapshot register of the waveform picker module. | |
1185 | * |
|
1185 | * | |
1186 | * The value is read from two (unsigned char) of the parameter_dump_packet structure: |
|
1186 | * The value is read from two (unsigned char) of the parameter_dump_packet structure: | |
1187 | * - sy_lfr_n_swf_p[0] |
|
1187 | * - sy_lfr_n_swf_p[0] | |
1188 | * - sy_lfr_n_swf_p[1] |
|
1188 | * - sy_lfr_n_swf_p[1] | |
1189 | * |
|
1189 | * | |
1190 | */ |
|
1190 | */ | |
1191 |
|
1191 | |||
1192 | unsigned int delta_snapshot; |
|
1192 | unsigned int delta_snapshot; | |
1193 | unsigned int delta_snapshot_in_T2; |
|
1193 | unsigned int delta_snapshot_in_T2; | |
1194 |
|
1194 | |||
1195 | delta_snapshot = (parameter_dump_packet.sy_lfr_n_swf_p[0] * CONST_256) |
|
1195 | delta_snapshot = (parameter_dump_packet.sy_lfr_n_swf_p[0] * CONST_256) | |
1196 | + parameter_dump_packet.sy_lfr_n_swf_p[1]; |
|
1196 | + parameter_dump_packet.sy_lfr_n_swf_p[1]; | |
1197 |
|
1197 | |||
1198 | delta_snapshot_in_T2 = delta_snapshot * FREQ_F2; |
|
1198 | delta_snapshot_in_T2 = delta_snapshot * FREQ_F2; | |
1199 | waveform_picker_regs->delta_snapshot = delta_snapshot_in_T2 - 1; // max 4 bytes |
|
1199 | waveform_picker_regs->delta_snapshot = delta_snapshot_in_T2 - 1; // max 4 bytes | |
1200 | } |
|
1200 | } | |
1201 |
|
1201 | |||
1202 | void set_wfp_delta_f0_f0_2( void ) |
|
1202 | void set_wfp_delta_f0_f0_2( void ) | |
1203 | { |
|
1203 | { | |
1204 | unsigned int delta_snapshot; |
|
1204 | unsigned int delta_snapshot; | |
1205 | unsigned int nb_samples_per_snapshot; |
|
1205 | unsigned int nb_samples_per_snapshot; | |
1206 | float delta_f0_in_float; |
|
1206 | float delta_f0_in_float; | |
1207 |
|
1207 | |||
1208 | delta_snapshot = waveform_picker_regs->delta_snapshot; |
|
1208 | delta_snapshot = waveform_picker_regs->delta_snapshot; | |
1209 | 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 | nb_samples_per_snapshot = (parameter_dump_packet.sy_lfr_n_swf_l[0] * CONST_256) + parameter_dump_packet.sy_lfr_n_swf_l[1]; | |
1210 | delta_f0_in_float = (nb_samples_per_snapshot / 2.) * ( (1. / FREQ_F2) - (1. / FREQ_F0) ) * FREQ_F2; |
|
1210 | delta_f0_in_float = (nb_samples_per_snapshot / 2.) * ( (1. / FREQ_F2) - (1. / FREQ_F0) ) * FREQ_F2; | |
1211 |
|
1211 | |||
1212 | waveform_picker_regs->delta_f0 = delta_snapshot - floor( delta_f0_in_float ); |
|
1212 | waveform_picker_regs->delta_f0 = delta_snapshot - floor( delta_f0_in_float ); | |
1213 |
waveform_picker_regs->delta_f0_2 = DFLT_WFP_DELTA_F0_2; |
|
1213 | waveform_picker_regs->delta_f0_2 = DFLT_WFP_DELTA_F0_2; | |
1214 | } |
|
1214 | } | |
1215 |
|
1215 | |||
1216 | void set_wfp_delta_f1( void ) |
|
1216 | void set_wfp_delta_f1( void ) | |
1217 | { |
|
1217 | { | |
1218 | /** Sets the value of the delta_f1 parameter |
|
1218 | /** Sets the value of the delta_f1 parameter | |
1219 | * |
|
1219 | * | |
1220 | * @param void |
|
1220 | * @param void | |
1221 | * |
|
1221 | * | |
1222 | * @return void |
|
1222 | * @return void | |
1223 | * |
|
1223 | * | |
1224 | * delta_f1 is not used, the snapshots are extracted from CWF_F1 waveforms. |
|
1224 | * delta_f1 is not used, the snapshots are extracted from CWF_F1 waveforms. | |
1225 | * |
|
1225 | * | |
1226 | */ |
|
1226 | */ | |
1227 |
|
1227 | |||
1228 | unsigned int delta_snapshot; |
|
1228 | unsigned int delta_snapshot; | |
1229 | unsigned int nb_samples_per_snapshot; |
|
1229 | unsigned int nb_samples_per_snapshot; | |
1230 | float delta_f1_in_float; |
|
1230 | float delta_f1_in_float; | |
1231 |
|
1231 | |||
1232 | delta_snapshot = waveform_picker_regs->delta_snapshot; |
|
1232 | delta_snapshot = waveform_picker_regs->delta_snapshot; | |
1233 | nb_samples_per_snapshot = (parameter_dump_packet.sy_lfr_n_swf_l[0] * CONST_256) + parameter_dump_packet.sy_lfr_n_swf_l[1]; |
|
1233 | nb_samples_per_snapshot = (parameter_dump_packet.sy_lfr_n_swf_l[0] * CONST_256) + parameter_dump_packet.sy_lfr_n_swf_l[1]; | |
1234 | delta_f1_in_float = (nb_samples_per_snapshot / 2.) * ( (1. / FREQ_F2) - (1. / FREQ_F1) ) * FREQ_F2; |
|
1234 | delta_f1_in_float = (nb_samples_per_snapshot / 2.) * ( (1. / FREQ_F2) - (1. / FREQ_F1) ) * FREQ_F2; | |
1235 |
|
1235 | |||
1236 | waveform_picker_regs->delta_f1 = delta_snapshot - floor( delta_f1_in_float ); |
|
1236 | waveform_picker_regs->delta_f1 = delta_snapshot - floor( delta_f1_in_float ); | |
1237 | } |
|
1237 | } | |
1238 |
|
1238 | |||
1239 | void set_wfp_delta_f2( void ) // parameter not used, only delta_f0 and delta_f0_2 are used |
|
1239 | void set_wfp_delta_f2( void ) // parameter not used, only delta_f0 and delta_f0_2 are used | |
1240 | { |
|
1240 | { | |
1241 | /** Sets the value of the delta_f2 parameter |
|
1241 | /** Sets the value of the delta_f2 parameter | |
1242 | * |
|
1242 | * | |
1243 | * @param void |
|
1243 | * @param void | |
1244 | * |
|
1244 | * | |
1245 | * @return void |
|
1245 | * @return void | |
1246 | * |
|
1246 | * | |
1247 | * delta_f2 is used only for the first snapshot generation, even when the snapshots are extracted from CWF_F2 |
|
1247 | * delta_f2 is used only for the first snapshot generation, even when the snapshots are extracted from CWF_F2 | |
1248 | * waveforms (see lpp_waveform_snapshot_controler.vhd for details). |
|
1248 | * waveforms (see lpp_waveform_snapshot_controler.vhd for details). | |
1249 | * |
|
1249 | * | |
1250 | */ |
|
1250 | */ | |
1251 |
|
1251 | |||
1252 | unsigned int delta_snapshot; |
|
1252 | unsigned int delta_snapshot; | |
1253 | unsigned int nb_samples_per_snapshot; |
|
1253 | unsigned int nb_samples_per_snapshot; | |
1254 |
|
1254 | |||
1255 | delta_snapshot = waveform_picker_regs->delta_snapshot; |
|
1255 | delta_snapshot = waveform_picker_regs->delta_snapshot; | |
1256 | nb_samples_per_snapshot = (parameter_dump_packet.sy_lfr_n_swf_l[0] * CONST_256) + parameter_dump_packet.sy_lfr_n_swf_l[1]; |
|
1256 | nb_samples_per_snapshot = (parameter_dump_packet.sy_lfr_n_swf_l[0] * CONST_256) + parameter_dump_packet.sy_lfr_n_swf_l[1]; | |
1257 |
|
1257 | |||
1258 | waveform_picker_regs->delta_f2 = delta_snapshot - (nb_samples_per_snapshot / 2) - 1; |
|
1258 | waveform_picker_regs->delta_f2 = delta_snapshot - (nb_samples_per_snapshot / 2) - 1; | |
1259 | } |
|
1259 | } | |
1260 |
|
1260 | |||
1261 | //***************** |
|
1261 | //***************** | |
1262 | // local parameters |
|
1262 | // local parameters | |
1263 |
|
1263 | |||
1264 | void increment_seq_counter_source_id( unsigned char *packet_sequence_control, unsigned int sid ) |
|
1264 | void increment_seq_counter_source_id( unsigned char *packet_sequence_control, unsigned int sid ) | |
1265 | { |
|
1265 | { | |
1266 | /** This function increments the parameter "sequence_cnt" depending on the sid passed in argument. |
|
1266 | /** This function increments the parameter "sequence_cnt" depending on the sid passed in argument. | |
1267 | * |
|
1267 | * | |
1268 | * @param packet_sequence_control is a pointer toward the parameter sequence_cnt to update. |
|
1268 | * @param packet_sequence_control is a pointer toward the parameter sequence_cnt to update. | |
1269 | * @param sid is the source identifier of the packet being updated. |
|
1269 | * @param sid is the source identifier of the packet being updated. | |
1270 | * |
|
1270 | * | |
1271 | * REQ-LFR-SRS-5240 / SSS-CP-FS-590 |
|
1271 | * REQ-LFR-SRS-5240 / SSS-CP-FS-590 | |
1272 | * The sequence counters shall wrap around from 2^14 to zero. |
|
1272 | * The sequence counters shall wrap around from 2^14 to zero. | |
1273 | * The sequence counter shall start at zero at startup. |
|
1273 | * The sequence counter shall start at zero at startup. | |
1274 | * |
|
1274 | * | |
1275 | * REQ-LFR-SRS-5239 / SSS-CP-FS-580 |
|
1275 | * REQ-LFR-SRS-5239 / SSS-CP-FS-580 | |
1276 | * All TM_LFR_SCIENCE_ packets are sent to ground, i.e. destination id = 0 |
|
1276 | * All TM_LFR_SCIENCE_ packets are sent to ground, i.e. destination id = 0 | |
1277 | * |
|
1277 | * | |
1278 | */ |
|
1278 | */ | |
1279 |
|
1279 | |||
1280 | unsigned short *sequence_cnt; |
|
1280 | unsigned short *sequence_cnt; | |
1281 | unsigned short segmentation_grouping_flag; |
|
1281 | unsigned short segmentation_grouping_flag; | |
1282 | unsigned short new_packet_sequence_control; |
|
1282 | unsigned short new_packet_sequence_control; | |
1283 | rtems_mode initial_mode_set; |
|
1283 | rtems_mode initial_mode_set; | |
1284 | rtems_mode current_mode_set; |
|
1284 | rtems_mode current_mode_set; | |
1285 | rtems_status_code status; |
|
1285 | rtems_status_code status; | |
1286 |
|
1286 | |||
1287 | initial_mode_set = RTEMS_DEFAULT_MODES; |
|
1287 | initial_mode_set = RTEMS_DEFAULT_MODES; | |
1288 | current_mode_set = RTEMS_DEFAULT_MODES; |
|
1288 | current_mode_set = RTEMS_DEFAULT_MODES; | |
1289 | sequence_cnt = NULL; |
|
1289 | sequence_cnt = NULL; | |
1290 |
|
1290 | |||
1291 | //****************************************** |
|
1291 | //****************************************** | |
1292 | // CHANGE THE MODE OF THE CALLING RTEMS TASK |
|
1292 | // CHANGE THE MODE OF THE CALLING RTEMS TASK | |
1293 | status = rtems_task_mode( RTEMS_NO_PREEMPT, RTEMS_PREEMPT_MASK, &initial_mode_set ); |
|
1293 | status = rtems_task_mode( RTEMS_NO_PREEMPT, RTEMS_PREEMPT_MASK, &initial_mode_set ); | |
1294 |
|
1294 | |||
1295 | if ( (sid == SID_NORM_SWF_F0) || (sid == SID_NORM_SWF_F1) || (sid == SID_NORM_SWF_F2) |
|
1295 | if ( (sid == SID_NORM_SWF_F0) || (sid == SID_NORM_SWF_F1) || (sid == SID_NORM_SWF_F2) | |
1296 | || (sid == SID_NORM_CWF_F3) || (sid == SID_NORM_CWF_LONG_F3) |
|
1296 | || (sid == SID_NORM_CWF_F3) || (sid == SID_NORM_CWF_LONG_F3) | |
1297 | || (sid == SID_BURST_CWF_F2) |
|
1297 | || (sid == SID_BURST_CWF_F2) | |
1298 | || (sid == SID_NORM_ASM_F0) || (sid == SID_NORM_ASM_F1) || (sid == SID_NORM_ASM_F2) |
|
1298 | || (sid == SID_NORM_ASM_F0) || (sid == SID_NORM_ASM_F1) || (sid == SID_NORM_ASM_F2) | |
1299 | || (sid == SID_NORM_BP1_F0) || (sid == SID_NORM_BP1_F1) || (sid == SID_NORM_BP1_F2) |
|
1299 | || (sid == SID_NORM_BP1_F0) || (sid == SID_NORM_BP1_F1) || (sid == SID_NORM_BP1_F2) | |
1300 | || (sid == SID_NORM_BP2_F0) || (sid == SID_NORM_BP2_F1) || (sid == SID_NORM_BP2_F2) |
|
1300 | || (sid == SID_NORM_BP2_F0) || (sid == SID_NORM_BP2_F1) || (sid == SID_NORM_BP2_F2) | |
1301 | || (sid == SID_BURST_BP1_F0) || (sid == SID_BURST_BP2_F0) |
|
1301 | || (sid == SID_BURST_BP1_F0) || (sid == SID_BURST_BP2_F0) | |
1302 | || (sid == SID_BURST_BP1_F1) || (sid == SID_BURST_BP2_F1) ) |
|
1302 | || (sid == SID_BURST_BP1_F1) || (sid == SID_BURST_BP2_F1) ) | |
1303 | { |
|
1303 | { | |
1304 | sequence_cnt = (unsigned short *) &sequenceCounters_SCIENCE_NORMAL_BURST; |
|
1304 | sequence_cnt = (unsigned short *) &sequenceCounters_SCIENCE_NORMAL_BURST; | |
1305 | } |
|
1305 | } | |
1306 | else if ( (sid ==SID_SBM1_CWF_F1) || (sid ==SID_SBM2_CWF_F2) |
|
1306 | else if ( (sid ==SID_SBM1_CWF_F1) || (sid ==SID_SBM2_CWF_F2) | |
1307 | || (sid == SID_SBM1_BP1_F0) || (sid == SID_SBM1_BP2_F0) |
|
1307 | || (sid == SID_SBM1_BP1_F0) || (sid == SID_SBM1_BP2_F0) | |
1308 | || (sid == SID_SBM2_BP1_F0) || (sid == SID_SBM2_BP2_F0) |
|
1308 | || (sid == SID_SBM2_BP1_F0) || (sid == SID_SBM2_BP2_F0) | |
1309 | || (sid == SID_SBM2_BP1_F1) || (sid == SID_SBM2_BP2_F1) ) |
|
1309 | || (sid == SID_SBM2_BP1_F1) || (sid == SID_SBM2_BP2_F1) ) | |
1310 | { |
|
1310 | { | |
1311 | sequence_cnt = (unsigned short *) &sequenceCounters_SCIENCE_SBM1_SBM2; |
|
1311 | sequence_cnt = (unsigned short *) &sequenceCounters_SCIENCE_SBM1_SBM2; | |
1312 | } |
|
1312 | } | |
1313 | else |
|
1313 | else | |
1314 | { |
|
1314 | { | |
1315 | sequence_cnt = (unsigned short *) NULL; |
|
1315 | sequence_cnt = (unsigned short *) NULL; | |
1316 | PRINTF1("in increment_seq_counter_source_id *** ERR apid_destid %d not known\n", sid) |
|
1316 | PRINTF1("in increment_seq_counter_source_id *** ERR apid_destid %d not known\n", sid) | |
1317 | } |
|
1317 | } | |
1318 |
|
1318 | |||
1319 | if (sequence_cnt != NULL) |
|
1319 | if (sequence_cnt != NULL) | |
1320 | { |
|
1320 | { | |
1321 | segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << SHIFT_1_BYTE; |
|
1321 | segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << SHIFT_1_BYTE; | |
1322 | *sequence_cnt = (*sequence_cnt) & SEQ_CNT_MASK; |
|
1322 | *sequence_cnt = (*sequence_cnt) & SEQ_CNT_MASK; | |
1323 |
|
1323 | |||
1324 | new_packet_sequence_control = segmentation_grouping_flag | (*sequence_cnt) ; |
|
1324 | new_packet_sequence_control = segmentation_grouping_flag | (*sequence_cnt) ; | |
1325 |
|
1325 | |||
1326 | packet_sequence_control[0] = (unsigned char) (new_packet_sequence_control >> SHIFT_1_BYTE); |
|
1326 | packet_sequence_control[0] = (unsigned char) (new_packet_sequence_control >> SHIFT_1_BYTE); | |
1327 | packet_sequence_control[1] = (unsigned char) (new_packet_sequence_control ); |
|
1327 | packet_sequence_control[1] = (unsigned char) (new_packet_sequence_control ); | |
1328 |
|
1328 | |||
1329 | // increment the sequence counter |
|
1329 | // increment the sequence counter | |
1330 | if ( *sequence_cnt < SEQ_CNT_MAX) |
|
1330 | if ( *sequence_cnt < SEQ_CNT_MAX) | |
1331 | { |
|
1331 | { | |
1332 | *sequence_cnt = *sequence_cnt + 1; |
|
1332 | *sequence_cnt = *sequence_cnt + 1; | |
1333 | } |
|
1333 | } | |
1334 | else |
|
1334 | else | |
1335 | { |
|
1335 | { | |
1336 | *sequence_cnt = 0; |
|
1336 | *sequence_cnt = 0; | |
1337 | } |
|
1337 | } | |
1338 | } |
|
1338 | } | |
1339 |
|
1339 | |||
1340 | //************************************* |
|
1340 | //************************************* | |
1341 | // RESTORE THE MODE OF THE CALLING TASK |
|
1341 | // RESTORE THE MODE OF THE CALLING TASK | |
1342 | status = rtems_task_mode( initial_mode_set, RTEMS_PREEMPT_MASK, ¤t_mode_set ); |
|
1342 | status = rtems_task_mode( initial_mode_set, RTEMS_PREEMPT_MASK, ¤t_mode_set ); | |
1343 | } |
|
1343 | } |
General Comments 0
You need to be logged in to leave comments.
Login now