@@ -1,58 +1,69 | |||||
1 | #ifndef FSW_MISC_H_INCLUDED |
|
1 | #ifndef FSW_MISC_H_INCLUDED | |
2 | #define FSW_MISC_H_INCLUDED |
|
2 | #define FSW_MISC_H_INCLUDED | |
3 |
|
3 | |||
4 | #include <rtems.h> |
|
4 | #include <rtems.h> | |
5 | #include <stdio.h> |
|
5 | #include <stdio.h> | |
6 | #include <grspw.h> |
|
6 | #include <grspw.h> | |
7 | #include <grlib_regs.h> |
|
7 | #include <grlib_regs.h> | |
8 |
|
8 | |||
9 | #include "fsw_params.h" |
|
9 | #include "fsw_params.h" | |
10 | #include "fsw_spacewire.h" |
|
10 | #include "fsw_spacewire.h" | |
11 | #include "lfr_cpu_usage_report.h" |
|
11 | #include "lfr_cpu_usage_report.h" | |
12 |
|
12 | |||
|
13 | enum lfr_reset_cause_t{ | |||
|
14 | UNKNOWN_CAUSE, | |||
|
15 | POWER_ON, | |||
|
16 | TC_RESET, | |||
|
17 | WATCHDOG, | |||
|
18 | ERROR_RESET, | |||
|
19 | UNEXP_RESET | |||
|
20 | }; | |||
|
21 | ||||
|
22 | #define LFR_RESET_CAUSE_UNKNOWN_CAUSE 0 | |||
|
23 | ||||
13 | rtems_name name_hk_rate_monotonic; // name of the HK rate monotonic |
|
24 | rtems_name name_hk_rate_monotonic; // name of the HK rate monotonic | |
14 | rtems_id HK_id; // id of the HK rate monotonic period |
|
25 | rtems_id HK_id; // id of the HK rate monotonic period | |
15 |
|
26 | |||
16 | void configure_timer(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider, |
|
27 | void configure_timer(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider, | |
17 | unsigned char interrupt_level, rtems_isr (*timer_isr)() ); |
|
28 | unsigned char interrupt_level, rtems_isr (*timer_isr)() ); | |
18 | void timer_start( gptimer_regs_t *gptimer_regs, unsigned char timer ); |
|
29 | void timer_start( gptimer_regs_t *gptimer_regs, unsigned char timer ); | |
19 | void timer_stop( gptimer_regs_t *gptimer_regs, unsigned char timer ); |
|
30 | void timer_stop( gptimer_regs_t *gptimer_regs, unsigned char timer ); | |
20 | void timer_set_clock_divider(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider); |
|
31 | void timer_set_clock_divider(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider); | |
21 |
|
32 | |||
22 | // SERIAL LINK |
|
33 | // SERIAL LINK | |
23 | int send_console_outputs_on_apbuart_port( void ); |
|
34 | int send_console_outputs_on_apbuart_port( void ); | |
24 | int enable_apbuart_transmitter( void ); |
|
35 | int enable_apbuart_transmitter( void ); | |
25 | void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value); |
|
36 | void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value); | |
26 |
|
37 | |||
27 | // RTEMS TASKS |
|
38 | // RTEMS TASKS | |
28 | rtems_task stat_task( rtems_task_argument argument ); |
|
39 | rtems_task stat_task( rtems_task_argument argument ); | |
29 | rtems_task hous_task( rtems_task_argument argument ); |
|
40 | rtems_task hous_task( rtems_task_argument argument ); | |
30 | rtems_task dumb_task( rtems_task_argument unused ); |
|
41 | rtems_task dumb_task( rtems_task_argument unused ); | |
31 |
|
42 | |||
32 | void init_housekeeping_parameters( void ); |
|
43 | void init_housekeeping_parameters( void ); | |
33 | void increment_seq_counter(unsigned short *packetSequenceControl); |
|
44 | void increment_seq_counter(unsigned short *packetSequenceControl); | |
34 | void getTime( unsigned char *time); |
|
45 | void getTime( unsigned char *time); | |
35 | unsigned long long int getTimeAsUnsignedLongLongInt( ); |
|
46 | unsigned long long int getTimeAsUnsignedLongLongInt( ); | |
36 | void send_dumb_hk( void ); |
|
47 | void send_dumb_hk( void ); | |
37 | void get_temperatures( unsigned char *temperatures ); |
|
48 | void get_temperatures( unsigned char *temperatures ); | |
38 | void get_v_e1_e2_f3( unsigned char *spacecraft_potential ); |
|
49 | void get_v_e1_e2_f3( unsigned char *spacecraft_potential ); | |
39 | void get_cpu_load( unsigned char *resource_statistics ); |
|
50 | void get_cpu_load( unsigned char *resource_statistics ); | |
40 | void set_hk_lfr_sc_potential_flag( bool state ); |
|
51 | void set_hk_lfr_sc_potential_flag( bool state ); | |
41 | void set_hk_lfr_mag_fields_flag( bool state ); |
|
52 | void set_hk_lfr_mag_fields_flag( bool state ); | |
42 | void set_hk_lfr_calib_enable( bool state ); |
|
53 | void set_hk_lfr_calib_enable( bool state ); | |
43 |
|
54 | void set_hk_lfr_reset_cause( enum lfr_reset_cause_t lfr_reset_cause ); | ||
44 |
|
55 | |||
45 | extern int sched_yield( void ); |
|
56 | extern int sched_yield( void ); | |
46 | extern void rtems_cpu_usage_reset(); |
|
57 | extern void rtems_cpu_usage_reset(); | |
47 | extern ring_node *current_ring_node_f3; |
|
58 | extern ring_node *current_ring_node_f3; | |
48 | extern ring_node *ring_node_to_send_cwf_f3; |
|
59 | extern ring_node *ring_node_to_send_cwf_f3; | |
49 | extern ring_node waveform_ring_f3[]; |
|
60 | extern ring_node waveform_ring_f3[]; | |
50 | extern unsigned short sequenceCounterHK; |
|
61 | extern unsigned short sequenceCounterHK; | |
51 |
|
62 | |||
52 | extern unsigned char hk_lfr_q_sd_fifo_size_max; |
|
63 | extern unsigned char hk_lfr_q_sd_fifo_size_max; | |
53 | extern unsigned char hk_lfr_q_rv_fifo_size_max; |
|
64 | extern unsigned char hk_lfr_q_rv_fifo_size_max; | |
54 | extern unsigned char hk_lfr_q_p0_fifo_size_max; |
|
65 | extern unsigned char hk_lfr_q_p0_fifo_size_max; | |
55 | extern unsigned char hk_lfr_q_p1_fifo_size_max; |
|
66 | extern unsigned char hk_lfr_q_p1_fifo_size_max; | |
56 | extern unsigned char hk_lfr_q_p2_fifo_size_max; |
|
67 | extern unsigned char hk_lfr_q_p2_fifo_size_max; | |
57 |
|
68 | |||
58 | #endif // FSW_MISC_H_INCLUDED |
|
69 | #endif // FSW_MISC_H_INCLUDED |
@@ -1,564 +1,571 | |||||
1 | /** General usage functions and RTEMS tasks. |
|
1 | /** General usage functions and RTEMS tasks. | |
2 | * |
|
2 | * | |
3 | * @file |
|
3 | * @file | |
4 | * @author P. LEROY |
|
4 | * @author P. LEROY | |
5 | * |
|
5 | * | |
6 | */ |
|
6 | */ | |
7 |
|
7 | |||
8 | #include "fsw_misc.h" |
|
8 | #include "fsw_misc.h" | |
9 |
|
9 | |||
10 | void configure_timer(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider, |
|
10 | void configure_timer(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider, | |
11 | unsigned char interrupt_level, rtems_isr (*timer_isr)() ) |
|
11 | unsigned char interrupt_level, rtems_isr (*timer_isr)() ) | |
12 | { |
|
12 | { | |
13 | /** This function configures a GPTIMER timer instantiated in the VHDL design. |
|
13 | /** This function configures a GPTIMER timer instantiated in the VHDL design. | |
14 | * |
|
14 | * | |
15 | * @param gptimer_regs points to the APB registers of the GPTIMER IP core. |
|
15 | * @param gptimer_regs points to the APB registers of the GPTIMER IP core. | |
16 | * @param timer is the number of the timer in the IP core (several timers can be instantiated). |
|
16 | * @param timer is the number of the timer in the IP core (several timers can be instantiated). | |
17 | * @param clock_divider is the divider of the 1 MHz clock that will be configured. |
|
17 | * @param clock_divider is the divider of the 1 MHz clock that will be configured. | |
18 | * @param interrupt_level is the interrupt level that the timer drives. |
|
18 | * @param interrupt_level is the interrupt level that the timer drives. | |
19 | * @param timer_isr is the interrupt subroutine that will be attached to the IRQ driven by the timer. |
|
19 | * @param timer_isr is the interrupt subroutine that will be attached to the IRQ driven by the timer. | |
20 | * |
|
20 | * | |
21 | * Interrupt levels are described in the SPARC documentation sparcv8.pdf p.76 |
|
21 | * Interrupt levels are described in the SPARC documentation sparcv8.pdf p.76 | |
22 | * |
|
22 | * | |
23 | */ |
|
23 | */ | |
24 |
|
24 | |||
25 | rtems_status_code status; |
|
25 | rtems_status_code status; | |
26 | rtems_isr_entry old_isr_handler; |
|
26 | rtems_isr_entry old_isr_handler; | |
27 |
|
27 | |||
28 | gptimer_regs->timer[timer].ctrl = 0x00; // reset the control register |
|
28 | gptimer_regs->timer[timer].ctrl = 0x00; // reset the control register | |
29 |
|
29 | |||
30 | status = rtems_interrupt_catch( timer_isr, interrupt_level, &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels |
|
30 | status = rtems_interrupt_catch( timer_isr, interrupt_level, &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels | |
31 | if (status!=RTEMS_SUCCESSFUL) |
|
31 | if (status!=RTEMS_SUCCESSFUL) | |
32 | { |
|
32 | { | |
33 | PRINTF("in configure_timer *** ERR rtems_interrupt_catch\n") |
|
33 | PRINTF("in configure_timer *** ERR rtems_interrupt_catch\n") | |
34 | } |
|
34 | } | |
35 |
|
35 | |||
36 | timer_set_clock_divider( gptimer_regs, timer, clock_divider); |
|
36 | timer_set_clock_divider( gptimer_regs, timer, clock_divider); | |
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | void timer_start(gptimer_regs_t *gptimer_regs, unsigned char timer) |
|
39 | void timer_start(gptimer_regs_t *gptimer_regs, unsigned char timer) | |
40 | { |
|
40 | { | |
41 | /** This function starts a GPTIMER timer. |
|
41 | /** This function starts a GPTIMER timer. | |
42 | * |
|
42 | * | |
43 | * @param gptimer_regs points to the APB registers of the GPTIMER IP core. |
|
43 | * @param gptimer_regs points to the APB registers of the GPTIMER IP core. | |
44 | * @param timer is the number of the timer in the IP core (several timers can be instantiated). |
|
44 | * @param timer is the number of the timer in the IP core (several timers can be instantiated). | |
45 | * |
|
45 | * | |
46 | */ |
|
46 | */ | |
47 |
|
47 | |||
48 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000010; // clear pending IRQ if any |
|
48 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000010; // clear pending IRQ if any | |
49 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000004; // LD load value from the reload register |
|
49 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000004; // LD load value from the reload register | |
50 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000001; // EN enable the timer |
|
50 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000001; // EN enable the timer | |
51 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000002; // RS restart |
|
51 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000002; // RS restart | |
52 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000008; // IE interrupt enable |
|
52 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000008; // IE interrupt enable | |
53 | } |
|
53 | } | |
54 |
|
54 | |||
55 | void timer_stop(gptimer_regs_t *gptimer_regs, unsigned char timer) |
|
55 | void timer_stop(gptimer_regs_t *gptimer_regs, unsigned char timer) | |
56 | { |
|
56 | { | |
57 | /** This function stops a GPTIMER timer. |
|
57 | /** This function stops a GPTIMER timer. | |
58 | * |
|
58 | * | |
59 | * @param gptimer_regs points to the APB registers of the GPTIMER IP core. |
|
59 | * @param gptimer_regs points to the APB registers of the GPTIMER IP core. | |
60 | * @param timer is the number of the timer in the IP core (several timers can be instantiated). |
|
60 | * @param timer is the number of the timer in the IP core (several timers can be instantiated). | |
61 | * |
|
61 | * | |
62 | */ |
|
62 | */ | |
63 |
|
63 | |||
64 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & 0xfffffffe; // EN enable the timer |
|
64 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & 0xfffffffe; // EN enable the timer | |
65 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & 0xffffffef; // IE interrupt enable |
|
65 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & 0xffffffef; // IE interrupt enable | |
66 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000010; // clear pending IRQ if any |
|
66 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000010; // clear pending IRQ if any | |
67 | } |
|
67 | } | |
68 |
|
68 | |||
69 | void timer_set_clock_divider(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider) |
|
69 | void timer_set_clock_divider(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider) | |
70 | { |
|
70 | { | |
71 | /** This function sets the clock divider of a GPTIMER timer. |
|
71 | /** This function sets the clock divider of a GPTIMER timer. | |
72 | * |
|
72 | * | |
73 | * @param gptimer_regs points to the APB registers of the GPTIMER IP core. |
|
73 | * @param gptimer_regs points to the APB registers of the GPTIMER IP core. | |
74 | * @param timer is the number of the timer in the IP core (several timers can be instantiated). |
|
74 | * @param timer is the number of the timer in the IP core (several timers can be instantiated). | |
75 | * @param clock_divider is the divider of the 1 MHz clock that will be configured. |
|
75 | * @param clock_divider is the divider of the 1 MHz clock that will be configured. | |
76 | * |
|
76 | * | |
77 | */ |
|
77 | */ | |
78 |
|
78 | |||
79 | gptimer_regs->timer[timer].reload = clock_divider; // base clock frequency is 1 MHz |
|
79 | gptimer_regs->timer[timer].reload = clock_divider; // base clock frequency is 1 MHz | |
80 | } |
|
80 | } | |
81 |
|
81 | |||
82 | int send_console_outputs_on_apbuart_port( void ) // Send the console outputs on the apbuart port |
|
82 | int send_console_outputs_on_apbuart_port( void ) // Send the console outputs on the apbuart port | |
83 | { |
|
83 | { | |
84 | struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART; |
|
84 | struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART; | |
85 |
|
85 | |||
86 | apbuart_regs->ctrl = APBUART_CTRL_REG_MASK_TE; |
|
86 | apbuart_regs->ctrl = APBUART_CTRL_REG_MASK_TE; | |
87 |
|
87 | |||
88 | return 0; |
|
88 | return 0; | |
89 | } |
|
89 | } | |
90 |
|
90 | |||
91 | int enable_apbuart_transmitter( void ) // set the bit 1, TE Transmitter Enable to 1 in the APBUART control register |
|
91 | int enable_apbuart_transmitter( void ) // set the bit 1, TE Transmitter Enable to 1 in the APBUART control register | |
92 | { |
|
92 | { | |
93 | struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART; |
|
93 | struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART; | |
94 |
|
94 | |||
95 | apbuart_regs->ctrl = apbuart_regs->ctrl | APBUART_CTRL_REG_MASK_TE; |
|
95 | apbuart_regs->ctrl = apbuart_regs->ctrl | APBUART_CTRL_REG_MASK_TE; | |
96 |
|
96 | |||
97 | return 0; |
|
97 | return 0; | |
98 | } |
|
98 | } | |
99 |
|
99 | |||
100 | void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value) |
|
100 | void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value) | |
101 | { |
|
101 | { | |
102 | /** This function sets the scaler reload register of the apbuart module |
|
102 | /** This function sets the scaler reload register of the apbuart module | |
103 | * |
|
103 | * | |
104 | * @param regs is the address of the apbuart registers in memory |
|
104 | * @param regs is the address of the apbuart registers in memory | |
105 | * @param value is the value that will be stored in the scaler register |
|
105 | * @param value is the value that will be stored in the scaler register | |
106 | * |
|
106 | * | |
107 | * The value shall be set by the software to get data on the serial interface. |
|
107 | * The value shall be set by the software to get data on the serial interface. | |
108 | * |
|
108 | * | |
109 | */ |
|
109 | */ | |
110 |
|
110 | |||
111 | struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) regs; |
|
111 | struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) regs; | |
112 |
|
112 | |||
113 | apbuart_regs->scaler = value; |
|
113 | apbuart_regs->scaler = value; | |
114 | BOOT_PRINTF1("OK *** apbuart port scaler reload register set to 0x%x\n", value) |
|
114 | BOOT_PRINTF1("OK *** apbuart port scaler reload register set to 0x%x\n", value) | |
115 | } |
|
115 | } | |
116 |
|
116 | |||
117 | //************ |
|
117 | //************ | |
118 | // RTEMS TASKS |
|
118 | // RTEMS TASKS | |
119 |
|
119 | |||
120 | rtems_task stat_task(rtems_task_argument argument) |
|
120 | rtems_task stat_task(rtems_task_argument argument) | |
121 | { |
|
121 | { | |
122 | int i; |
|
122 | int i; | |
123 | int j; |
|
123 | int j; | |
124 | i = 0; |
|
124 | i = 0; | |
125 | j = 0; |
|
125 | j = 0; | |
126 | BOOT_PRINTF("in STAT *** \n") |
|
126 | BOOT_PRINTF("in STAT *** \n") | |
127 | while(1){ |
|
127 | while(1){ | |
128 | rtems_task_wake_after(1000); |
|
128 | rtems_task_wake_after(1000); | |
129 | PRINTF1("%d\n", j) |
|
129 | PRINTF1("%d\n", j) | |
130 | if (i == CPU_USAGE_REPORT_PERIOD) { |
|
130 | if (i == CPU_USAGE_REPORT_PERIOD) { | |
131 | // #ifdef PRINT_TASK_STATISTICS |
|
131 | // #ifdef PRINT_TASK_STATISTICS | |
132 | // rtems_cpu_usage_report(); |
|
132 | // rtems_cpu_usage_report(); | |
133 | // rtems_cpu_usage_reset(); |
|
133 | // rtems_cpu_usage_reset(); | |
134 | // #endif |
|
134 | // #endif | |
135 | i = 0; |
|
135 | i = 0; | |
136 | } |
|
136 | } | |
137 | else i++; |
|
137 | else i++; | |
138 | j++; |
|
138 | j++; | |
139 | } |
|
139 | } | |
140 | } |
|
140 | } | |
141 |
|
141 | |||
142 | rtems_task hous_task(rtems_task_argument argument) |
|
142 | rtems_task hous_task(rtems_task_argument argument) | |
143 | { |
|
143 | { | |
144 | rtems_status_code status; |
|
144 | rtems_status_code status; | |
145 | rtems_status_code spare_status; |
|
145 | rtems_status_code spare_status; | |
146 | rtems_id queue_id; |
|
146 | rtems_id queue_id; | |
147 | rtems_rate_monotonic_period_status period_status; |
|
147 | rtems_rate_monotonic_period_status period_status; | |
148 |
|
148 | |||
149 | status = get_message_queue_id_send( &queue_id ); |
|
149 | status = get_message_queue_id_send( &queue_id ); | |
150 | if (status != RTEMS_SUCCESSFUL) |
|
150 | if (status != RTEMS_SUCCESSFUL) | |
151 | { |
|
151 | { | |
152 | PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status) |
|
152 | PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status) | |
153 | } |
|
153 | } | |
154 |
|
154 | |||
155 | BOOT_PRINTF("in HOUS ***\n") |
|
155 | BOOT_PRINTF("in HOUS ***\n") | |
156 |
|
156 | |||
157 | if (rtems_rate_monotonic_ident( name_hk_rate_monotonic, &HK_id) != RTEMS_SUCCESSFUL) { |
|
157 | if (rtems_rate_monotonic_ident( name_hk_rate_monotonic, &HK_id) != RTEMS_SUCCESSFUL) { | |
158 | status = rtems_rate_monotonic_create( name_hk_rate_monotonic, &HK_id ); |
|
158 | status = rtems_rate_monotonic_create( name_hk_rate_monotonic, &HK_id ); | |
159 | if( status != RTEMS_SUCCESSFUL ) { |
|
159 | if( status != RTEMS_SUCCESSFUL ) { | |
160 | PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status ) |
|
160 | PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status ) | |
161 | } |
|
161 | } | |
162 | } |
|
162 | } | |
163 |
|
163 | |||
164 | status = rtems_rate_monotonic_cancel(HK_id); |
|
164 | status = rtems_rate_monotonic_cancel(HK_id); | |
165 | if( status != RTEMS_SUCCESSFUL ) { |
|
165 | if( status != RTEMS_SUCCESSFUL ) { | |
166 | PRINTF1( "ERR *** in HOUS *** rtems_rate_monotonic_cancel(HK_id) ***code: %d\n", status ) |
|
166 | PRINTF1( "ERR *** in HOUS *** rtems_rate_monotonic_cancel(HK_id) ***code: %d\n", status ) | |
167 | } |
|
167 | } | |
168 | else { |
|
168 | else { | |
169 | DEBUG_PRINTF("OK *** in HOUS *** rtems_rate_monotonic_cancel(HK_id)\n") |
|
169 | DEBUG_PRINTF("OK *** in HOUS *** rtems_rate_monotonic_cancel(HK_id)\n") | |
170 | } |
|
170 | } | |
171 |
|
171 | |||
172 | // startup phase |
|
172 | // startup phase | |
173 | status = rtems_rate_monotonic_period( HK_id, SY_LFR_TIME_SYN_TIMEOUT_in_ticks ); |
|
173 | status = rtems_rate_monotonic_period( HK_id, SY_LFR_TIME_SYN_TIMEOUT_in_ticks ); | |
174 | status = rtems_rate_monotonic_get_status( HK_id, &period_status ); |
|
174 | status = rtems_rate_monotonic_get_status( HK_id, &period_status ); | |
175 | DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state) |
|
175 | DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state) | |
176 | while(period_status.state != RATE_MONOTONIC_EXPIRED ) // after SY_LFR_TIME_SYN_TIMEOUT ms, starts HK anyway |
|
176 | while(period_status.state != RATE_MONOTONIC_EXPIRED ) // after SY_LFR_TIME_SYN_TIMEOUT ms, starts HK anyway | |
177 | { |
|
177 | { | |
178 | if ((time_management_regs->coarse_time & 0x80000000) == 0x00000000) // check time synchronization |
|
178 | if ((time_management_regs->coarse_time & 0x80000000) == 0x00000000) // check time synchronization | |
179 | { |
|
179 | { | |
180 | break; // break if LFR is synchronized |
|
180 | break; // break if LFR is synchronized | |
181 | } |
|
181 | } | |
182 | else |
|
182 | else | |
183 | { |
|
183 | { | |
184 | status = rtems_rate_monotonic_get_status( HK_id, &period_status ); |
|
184 | status = rtems_rate_monotonic_get_status( HK_id, &period_status ); | |
185 | // sched_yield(); |
|
185 | // sched_yield(); | |
186 | status = rtems_task_wake_after( 10 ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 100 ms = 10 * 10 ms |
|
186 | status = rtems_task_wake_after( 10 ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 100 ms = 10 * 10 ms | |
187 | } |
|
187 | } | |
188 | } |
|
188 | } | |
189 | status = rtems_rate_monotonic_cancel(HK_id); |
|
189 | status = rtems_rate_monotonic_cancel(HK_id); | |
190 | DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state) |
|
190 | DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state) | |
191 |
|
191 | |||
|
192 | set_hk_lfr_reset_cause( POWER_ON ); | |||
|
193 | ||||
192 | while(1){ // launch the rate monotonic task |
|
194 | while(1){ // launch the rate monotonic task | |
193 | status = rtems_rate_monotonic_period( HK_id, HK_PERIOD ); |
|
195 | status = rtems_rate_monotonic_period( HK_id, HK_PERIOD ); | |
194 | if ( status != RTEMS_SUCCESSFUL ) { |
|
196 | if ( status != RTEMS_SUCCESSFUL ) { | |
195 | PRINTF1( "in HOUS *** ERR period: %d\n", status); |
|
197 | PRINTF1( "in HOUS *** ERR period: %d\n", status); | |
196 | spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_6 ); |
|
198 | spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_6 ); | |
197 | } |
|
199 | } | |
198 | else { |
|
200 | else { | |
199 | housekeeping_packet.packetSequenceControl[0] = (unsigned char) (sequenceCounterHK >> 8); |
|
201 | housekeeping_packet.packetSequenceControl[0] = (unsigned char) (sequenceCounterHK >> 8); | |
200 | housekeeping_packet.packetSequenceControl[1] = (unsigned char) (sequenceCounterHK ); |
|
202 | housekeeping_packet.packetSequenceControl[1] = (unsigned char) (sequenceCounterHK ); | |
201 | increment_seq_counter( &sequenceCounterHK ); |
|
203 | increment_seq_counter( &sequenceCounterHK ); | |
202 |
|
204 | |||
203 | housekeeping_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24); |
|
205 | housekeeping_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24); | |
204 | housekeeping_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16); |
|
206 | housekeeping_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16); | |
205 | housekeeping_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8); |
|
207 | housekeeping_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8); | |
206 | housekeeping_packet.time[3] = (unsigned char) (time_management_regs->coarse_time); |
|
208 | housekeeping_packet.time[3] = (unsigned char) (time_management_regs->coarse_time); | |
207 | housekeeping_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8); |
|
209 | housekeeping_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8); | |
208 | housekeeping_packet.time[5] = (unsigned char) (time_management_regs->fine_time); |
|
210 | housekeeping_packet.time[5] = (unsigned char) (time_management_regs->fine_time); | |
209 |
|
211 | |||
210 | spacewire_update_statistics(); |
|
212 | spacewire_update_statistics(); | |
211 |
|
213 | |||
212 | housekeeping_packet.hk_lfr_q_sd_fifo_size_max = hk_lfr_q_sd_fifo_size_max; |
|
214 | housekeeping_packet.hk_lfr_q_sd_fifo_size_max = hk_lfr_q_sd_fifo_size_max; | |
213 | housekeeping_packet.hk_lfr_q_rv_fifo_size_max = hk_lfr_q_rv_fifo_size_max; |
|
215 | housekeeping_packet.hk_lfr_q_rv_fifo_size_max = hk_lfr_q_rv_fifo_size_max; | |
214 | housekeeping_packet.hk_lfr_q_p0_fifo_size_max = hk_lfr_q_p0_fifo_size_max; |
|
216 | housekeeping_packet.hk_lfr_q_p0_fifo_size_max = hk_lfr_q_p0_fifo_size_max; | |
215 | housekeeping_packet.hk_lfr_q_p1_fifo_size_max = hk_lfr_q_p1_fifo_size_max; |
|
217 | housekeeping_packet.hk_lfr_q_p1_fifo_size_max = hk_lfr_q_p1_fifo_size_max; | |
216 | housekeeping_packet.hk_lfr_q_p2_fifo_size_max = hk_lfr_q_p2_fifo_size_max; |
|
218 | housekeeping_packet.hk_lfr_q_p2_fifo_size_max = hk_lfr_q_p2_fifo_size_max; | |
217 |
|
219 | |||
218 | housekeeping_packet.sy_lfr_common_parameters_spare = parameter_dump_packet.sy_lfr_common_parameters_spare; |
|
220 | housekeeping_packet.sy_lfr_common_parameters_spare = parameter_dump_packet.sy_lfr_common_parameters_spare; | |
219 | housekeeping_packet.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; |
|
221 | housekeeping_packet.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; | |
220 | get_temperatures( housekeeping_packet.hk_lfr_temp_scm ); |
|
222 | get_temperatures( housekeeping_packet.hk_lfr_temp_scm ); | |
221 | get_v_e1_e2_f3( housekeeping_packet.hk_lfr_sc_v_f3 ); |
|
223 | get_v_e1_e2_f3( housekeeping_packet.hk_lfr_sc_v_f3 ); | |
222 | get_cpu_load( (unsigned char *) &housekeeping_packet.hk_lfr_cpu_load ); |
|
224 | get_cpu_load( (unsigned char *) &housekeeping_packet.hk_lfr_cpu_load ); | |
223 |
|
225 | |||
224 | // SEND PACKET |
|
226 | // SEND PACKET | |
225 | status = rtems_message_queue_send( queue_id, &housekeeping_packet, |
|
227 | status = rtems_message_queue_send( queue_id, &housekeeping_packet, | |
226 | PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES); |
|
228 | PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES); | |
227 | if (status != RTEMS_SUCCESSFUL) { |
|
229 | if (status != RTEMS_SUCCESSFUL) { | |
228 | PRINTF1("in HOUS *** ERR send: %d\n", status) |
|
230 | PRINTF1("in HOUS *** ERR send: %d\n", status) | |
229 | } |
|
231 | } | |
230 | } |
|
232 | } | |
231 | } |
|
233 | } | |
232 |
|
234 | |||
233 | PRINTF("in HOUS *** deleting task\n") |
|
235 | PRINTF("in HOUS *** deleting task\n") | |
234 |
|
236 | |||
235 | status = rtems_task_delete( RTEMS_SELF ); // should not return |
|
237 | status = rtems_task_delete( RTEMS_SELF ); // should not return | |
236 | printf( "rtems_task_delete returned with status of %d.\n", status ); |
|
238 | printf( "rtems_task_delete returned with status of %d.\n", status ); | |
237 | return; |
|
239 | return; | |
238 | } |
|
240 | } | |
239 |
|
241 | |||
240 | rtems_task dumb_task( rtems_task_argument unused ) |
|
242 | rtems_task dumb_task( rtems_task_argument unused ) | |
241 | { |
|
243 | { | |
242 | /** This RTEMS taks is used to print messages without affecting the general behaviour of the software. |
|
244 | /** This RTEMS taks is used to print messages without affecting the general behaviour of the software. | |
243 | * |
|
245 | * | |
244 | * @param unused is the starting argument of the RTEMS task |
|
246 | * @param unused is the starting argument of the RTEMS task | |
245 | * |
|
247 | * | |
246 | * The DUMB taks waits for RTEMS events and print messages depending on the incoming events. |
|
248 | * The DUMB taks waits for RTEMS events and print messages depending on the incoming events. | |
247 | * |
|
249 | * | |
248 | */ |
|
250 | */ | |
249 |
|
251 | |||
250 | unsigned int i; |
|
252 | unsigned int i; | |
251 | unsigned int intEventOut; |
|
253 | unsigned int intEventOut; | |
252 | unsigned int coarse_time = 0; |
|
254 | unsigned int coarse_time = 0; | |
253 | unsigned int fine_time = 0; |
|
255 | unsigned int fine_time = 0; | |
254 | rtems_event_set event_out; |
|
256 | rtems_event_set event_out; | |
255 |
|
257 | |||
256 | char *DumbMessages[12] = {"in DUMB *** default", // RTEMS_EVENT_0 |
|
258 | char *DumbMessages[12] = {"in DUMB *** default", // RTEMS_EVENT_0 | |
257 | "in DUMB *** timecode_irq_handler", // RTEMS_EVENT_1 |
|
259 | "in DUMB *** timecode_irq_handler", // RTEMS_EVENT_1 | |
258 | "in DUMB *** f3 buffer changed", // RTEMS_EVENT_2 |
|
260 | "in DUMB *** f3 buffer changed", // RTEMS_EVENT_2 | |
259 | "in DUMB *** in SMIQ *** Error sending event to AVF0", // RTEMS_EVENT_3 |
|
261 | "in DUMB *** in SMIQ *** Error sending event to AVF0", // RTEMS_EVENT_3 | |
260 | "in DUMB *** spectral_matrices_isr *** Error sending event to SMIQ", // RTEMS_EVENT_4 |
|
262 | "in DUMB *** spectral_matrices_isr *** Error sending event to SMIQ", // RTEMS_EVENT_4 | |
261 | "in DUMB *** waveforms_simulator_isr", // RTEMS_EVENT_5 |
|
263 | "in DUMB *** waveforms_simulator_isr", // RTEMS_EVENT_5 | |
262 | "VHDL SM *** two buffers f0 ready", // RTEMS_EVENT_6 |
|
264 | "VHDL SM *** two buffers f0 ready", // RTEMS_EVENT_6 | |
263 | "ready for dump", // RTEMS_EVENT_7 |
|
265 | "ready for dump", // RTEMS_EVENT_7 | |
264 | "VHDL ERR *** spectral matrix", // RTEMS_EVENT_8 |
|
266 | "VHDL ERR *** spectral matrix", // RTEMS_EVENT_8 | |
265 | "tick", // RTEMS_EVENT_9 |
|
267 | "tick", // RTEMS_EVENT_9 | |
266 | "VHDL ERR *** waveform picker", // RTEMS_EVENT_10 |
|
268 | "VHDL ERR *** waveform picker", // RTEMS_EVENT_10 | |
267 | "VHDL ERR *** unexpected ready matrix values" // RTEMS_EVENT_11 |
|
269 | "VHDL ERR *** unexpected ready matrix values" // RTEMS_EVENT_11 | |
268 | }; |
|
270 | }; | |
269 |
|
271 | |||
270 | BOOT_PRINTF("in DUMB *** \n") |
|
272 | BOOT_PRINTF("in DUMB *** \n") | |
271 |
|
273 | |||
272 | while(1){ |
|
274 | while(1){ | |
273 | rtems_event_receive(RTEMS_EVENT_0 | RTEMS_EVENT_1 | RTEMS_EVENT_2 | RTEMS_EVENT_3 |
|
275 | rtems_event_receive(RTEMS_EVENT_0 | RTEMS_EVENT_1 | RTEMS_EVENT_2 | RTEMS_EVENT_3 | |
274 | | RTEMS_EVENT_4 | RTEMS_EVENT_5 | RTEMS_EVENT_6 | RTEMS_EVENT_7 |
|
276 | | RTEMS_EVENT_4 | RTEMS_EVENT_5 | RTEMS_EVENT_6 | RTEMS_EVENT_7 | |
275 | | RTEMS_EVENT_8 | RTEMS_EVENT_9, |
|
277 | | RTEMS_EVENT_8 | RTEMS_EVENT_9, | |
276 | RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT |
|
278 | RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT | |
277 | intEventOut = (unsigned int) event_out; |
|
279 | intEventOut = (unsigned int) event_out; | |
278 | for ( i=0; i<32; i++) |
|
280 | for ( i=0; i<32; i++) | |
279 | { |
|
281 | { | |
280 | if ( ((intEventOut >> i) & 0x0001) != 0) |
|
282 | if ( ((intEventOut >> i) & 0x0001) != 0) | |
281 | { |
|
283 | { | |
282 | coarse_time = time_management_regs->coarse_time; |
|
284 | coarse_time = time_management_regs->coarse_time; | |
283 | fine_time = time_management_regs->fine_time; |
|
285 | fine_time = time_management_regs->fine_time; | |
284 | printf("in DUMB *** coarse: %x, fine: %x, %s\n", coarse_time, fine_time, DumbMessages[i]); |
|
286 | printf("in DUMB *** coarse: %x, fine: %x, %s\n", coarse_time, fine_time, DumbMessages[i]); | |
285 | if (i==8) |
|
287 | if (i==8) | |
286 | { |
|
288 | { | |
287 | } |
|
289 | } | |
288 | if (i==10) |
|
290 | if (i==10) | |
289 | { |
|
291 | { | |
290 | } |
|
292 | } | |
291 | } |
|
293 | } | |
292 | } |
|
294 | } | |
293 | } |
|
295 | } | |
294 | } |
|
296 | } | |
295 |
|
297 | |||
296 | //***************************** |
|
298 | //***************************** | |
297 | // init housekeeping parameters |
|
299 | // init housekeeping parameters | |
298 |
|
300 | |||
299 | void init_housekeeping_parameters( void ) |
|
301 | void init_housekeeping_parameters( void ) | |
300 | { |
|
302 | { | |
301 | /** This function initialize the housekeeping_packet global variable with default values. |
|
303 | /** This function initialize the housekeeping_packet global variable with default values. | |
302 | * |
|
304 | * | |
303 | */ |
|
305 | */ | |
304 |
|
306 | |||
305 | unsigned int i = 0; |
|
307 | unsigned int i = 0; | |
306 | unsigned char *parameters; |
|
308 | unsigned char *parameters; | |
307 | unsigned char sizeOfHK; |
|
309 | unsigned char sizeOfHK; | |
308 |
|
310 | |||
309 | sizeOfHK = sizeof( Packet_TM_LFR_HK_t ); |
|
311 | sizeOfHK = sizeof( Packet_TM_LFR_HK_t ); | |
310 |
|
312 | |||
311 | parameters = (unsigned char*) &housekeeping_packet; |
|
313 | parameters = (unsigned char*) &housekeeping_packet; | |
312 |
|
314 | |||
313 | for(i = 0; i< sizeOfHK; i++) |
|
315 | for(i = 0; i< sizeOfHK; i++) | |
314 | { |
|
316 | { | |
315 | parameters[i] = 0x00; |
|
317 | parameters[i] = 0x00; | |
316 | } |
|
318 | } | |
317 |
|
319 | |||
318 | housekeeping_packet.targetLogicalAddress = CCSDS_DESTINATION_ID; |
|
320 | housekeeping_packet.targetLogicalAddress = CCSDS_DESTINATION_ID; | |
319 | housekeeping_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID; |
|
321 | housekeeping_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID; | |
320 | housekeeping_packet.reserved = DEFAULT_RESERVED; |
|
322 | housekeeping_packet.reserved = DEFAULT_RESERVED; | |
321 | housekeeping_packet.userApplication = CCSDS_USER_APP; |
|
323 | housekeeping_packet.userApplication = CCSDS_USER_APP; | |
322 | housekeeping_packet.packetID[0] = (unsigned char) (APID_TM_HK >> 8); |
|
324 | housekeeping_packet.packetID[0] = (unsigned char) (APID_TM_HK >> 8); | |
323 | housekeeping_packet.packetID[1] = (unsigned char) (APID_TM_HK); |
|
325 | housekeeping_packet.packetID[1] = (unsigned char) (APID_TM_HK); | |
324 | housekeeping_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE; |
|
326 | housekeeping_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE; | |
325 | housekeeping_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT; |
|
327 | housekeeping_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT; | |
326 | housekeeping_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> 8); |
|
328 | housekeeping_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> 8); | |
327 | housekeeping_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK ); |
|
329 | housekeeping_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK ); | |
328 | housekeeping_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; |
|
330 | housekeeping_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; | |
329 | housekeeping_packet.serviceType = TM_TYPE_HK; |
|
331 | housekeeping_packet.serviceType = TM_TYPE_HK; | |
330 | housekeeping_packet.serviceSubType = TM_SUBTYPE_HK; |
|
332 | housekeeping_packet.serviceSubType = TM_SUBTYPE_HK; | |
331 | housekeeping_packet.destinationID = TM_DESTINATION_ID_GROUND; |
|
333 | housekeeping_packet.destinationID = TM_DESTINATION_ID_GROUND; | |
332 | housekeeping_packet.sid = SID_HK; |
|
334 | housekeeping_packet.sid = SID_HK; | |
333 |
|
335 | |||
334 | // init status word |
|
336 | // init status word | |
335 | housekeeping_packet.lfr_status_word[0] = DEFAULT_STATUS_WORD_BYTE0; |
|
337 | housekeeping_packet.lfr_status_word[0] = DEFAULT_STATUS_WORD_BYTE0; | |
336 | housekeeping_packet.lfr_status_word[1] = DEFAULT_STATUS_WORD_BYTE1; |
|
338 | housekeeping_packet.lfr_status_word[1] = DEFAULT_STATUS_WORD_BYTE1; | |
337 | // init software version |
|
339 | // init software version | |
338 | housekeeping_packet.lfr_sw_version[0] = SW_VERSION_N1; |
|
340 | housekeeping_packet.lfr_sw_version[0] = SW_VERSION_N1; | |
339 | housekeeping_packet.lfr_sw_version[1] = SW_VERSION_N2; |
|
341 | housekeeping_packet.lfr_sw_version[1] = SW_VERSION_N2; | |
340 | housekeeping_packet.lfr_sw_version[2] = SW_VERSION_N3; |
|
342 | housekeeping_packet.lfr_sw_version[2] = SW_VERSION_N3; | |
341 | housekeeping_packet.lfr_sw_version[3] = SW_VERSION_N4; |
|
343 | housekeeping_packet.lfr_sw_version[3] = SW_VERSION_N4; | |
342 | // init fpga version |
|
344 | // init fpga version | |
343 | parameters = (unsigned char *) (REGS_ADDR_VHDL_VERSION); |
|
345 | parameters = (unsigned char *) (REGS_ADDR_VHDL_VERSION); | |
344 | housekeeping_packet.lfr_fpga_version[0] = parameters[1]; // n1 |
|
346 | housekeeping_packet.lfr_fpga_version[0] = parameters[1]; // n1 | |
345 | housekeeping_packet.lfr_fpga_version[1] = parameters[2]; // n2 |
|
347 | housekeeping_packet.lfr_fpga_version[1] = parameters[2]; // n2 | |
346 | housekeeping_packet.lfr_fpga_version[2] = parameters[3]; // n3 |
|
348 | housekeeping_packet.lfr_fpga_version[2] = parameters[3]; // n3 | |
347 |
|
349 | |||
348 | housekeeping_packet.hk_lfr_q_sd_fifo_size = MSG_QUEUE_COUNT_SEND; |
|
350 | housekeeping_packet.hk_lfr_q_sd_fifo_size = MSG_QUEUE_COUNT_SEND; | |
349 | housekeeping_packet.hk_lfr_q_rv_fifo_size = MSG_QUEUE_COUNT_RECV; |
|
351 | housekeeping_packet.hk_lfr_q_rv_fifo_size = MSG_QUEUE_COUNT_RECV; | |
350 | housekeeping_packet.hk_lfr_q_p0_fifo_size = MSG_QUEUE_COUNT_PRC0; |
|
352 | housekeeping_packet.hk_lfr_q_p0_fifo_size = MSG_QUEUE_COUNT_PRC0; | |
351 | housekeeping_packet.hk_lfr_q_p1_fifo_size = MSG_QUEUE_COUNT_PRC1; |
|
353 | housekeeping_packet.hk_lfr_q_p1_fifo_size = MSG_QUEUE_COUNT_PRC1; | |
352 | housekeeping_packet.hk_lfr_q_p2_fifo_size = MSG_QUEUE_COUNT_PRC2; |
|
354 | housekeeping_packet.hk_lfr_q_p2_fifo_size = MSG_QUEUE_COUNT_PRC2; | |
353 | } |
|
355 | } | |
354 |
|
356 | |||
355 | void increment_seq_counter( unsigned short *packetSequenceControl ) |
|
357 | void increment_seq_counter( unsigned short *packetSequenceControl ) | |
356 | { |
|
358 | { | |
357 | /** This function increment the sequence counter passes in argument. |
|
359 | /** This function increment the sequence counter passes in argument. | |
358 | * |
|
360 | * | |
359 | * The increment does not affect the grouping flag. In case of an overflow, the counter is reset to 0. |
|
361 | * The increment does not affect the grouping flag. In case of an overflow, the counter is reset to 0. | |
360 | * |
|
362 | * | |
361 | */ |
|
363 | */ | |
362 |
|
364 | |||
363 | unsigned short segmentation_grouping_flag; |
|
365 | unsigned short segmentation_grouping_flag; | |
364 | unsigned short sequence_cnt; |
|
366 | unsigned short sequence_cnt; | |
365 |
|
367 | |||
366 | segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << 8; // keep bits 7 downto 6 |
|
368 | segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << 8; // keep bits 7 downto 6 | |
367 | sequence_cnt = (*packetSequenceControl) & 0x3fff; // [0011 1111 1111 1111] |
|
369 | sequence_cnt = (*packetSequenceControl) & 0x3fff; // [0011 1111 1111 1111] | |
368 |
|
370 | |||
369 | if ( sequence_cnt < SEQ_CNT_MAX) |
|
371 | if ( sequence_cnt < SEQ_CNT_MAX) | |
370 | { |
|
372 | { | |
371 | sequence_cnt = sequence_cnt + 1; |
|
373 | sequence_cnt = sequence_cnt + 1; | |
372 | } |
|
374 | } | |
373 | else |
|
375 | else | |
374 | { |
|
376 | { | |
375 | sequence_cnt = 0; |
|
377 | sequence_cnt = 0; | |
376 | } |
|
378 | } | |
377 |
|
379 | |||
378 | *packetSequenceControl = segmentation_grouping_flag | sequence_cnt ; |
|
380 | *packetSequenceControl = segmentation_grouping_flag | sequence_cnt ; | |
379 | } |
|
381 | } | |
380 |
|
382 | |||
381 | void getTime( unsigned char *time) |
|
383 | void getTime( unsigned char *time) | |
382 | { |
|
384 | { | |
383 | /** This function write the current local time in the time buffer passed in argument. |
|
385 | /** This function write the current local time in the time buffer passed in argument. | |
384 | * |
|
386 | * | |
385 | */ |
|
387 | */ | |
386 |
|
388 | |||
387 | time[0] = (unsigned char) (time_management_regs->coarse_time>>24); |
|
389 | time[0] = (unsigned char) (time_management_regs->coarse_time>>24); | |
388 | time[1] = (unsigned char) (time_management_regs->coarse_time>>16); |
|
390 | time[1] = (unsigned char) (time_management_regs->coarse_time>>16); | |
389 | time[2] = (unsigned char) (time_management_regs->coarse_time>>8); |
|
391 | time[2] = (unsigned char) (time_management_regs->coarse_time>>8); | |
390 | time[3] = (unsigned char) (time_management_regs->coarse_time); |
|
392 | time[3] = (unsigned char) (time_management_regs->coarse_time); | |
391 | time[4] = (unsigned char) (time_management_regs->fine_time>>8); |
|
393 | time[4] = (unsigned char) (time_management_regs->fine_time>>8); | |
392 | time[5] = (unsigned char) (time_management_regs->fine_time); |
|
394 | time[5] = (unsigned char) (time_management_regs->fine_time); | |
393 | } |
|
395 | } | |
394 |
|
396 | |||
395 | unsigned long long int getTimeAsUnsignedLongLongInt( ) |
|
397 | unsigned long long int getTimeAsUnsignedLongLongInt( ) | |
396 | { |
|
398 | { | |
397 | /** This function write the current local time in the time buffer passed in argument. |
|
399 | /** This function write the current local time in the time buffer passed in argument. | |
398 | * |
|
400 | * | |
399 | */ |
|
401 | */ | |
400 | unsigned long long int time; |
|
402 | unsigned long long int time; | |
401 |
|
403 | |||
402 | time = ( (unsigned long long int) (time_management_regs->coarse_time & 0x7fffffff) << 16 ) |
|
404 | time = ( (unsigned long long int) (time_management_regs->coarse_time & 0x7fffffff) << 16 ) | |
403 | + time_management_regs->fine_time; |
|
405 | + time_management_regs->fine_time; | |
404 |
|
406 | |||
405 | return time; |
|
407 | return time; | |
406 | } |
|
408 | } | |
407 |
|
409 | |||
408 | void send_dumb_hk( void ) |
|
410 | void send_dumb_hk( void ) | |
409 | { |
|
411 | { | |
410 | Packet_TM_LFR_HK_t dummy_hk_packet; |
|
412 | Packet_TM_LFR_HK_t dummy_hk_packet; | |
411 | unsigned char *parameters; |
|
413 | unsigned char *parameters; | |
412 | unsigned int i; |
|
414 | unsigned int i; | |
413 | rtems_id queue_id; |
|
415 | rtems_id queue_id; | |
414 |
|
416 | |||
415 | dummy_hk_packet.targetLogicalAddress = CCSDS_DESTINATION_ID; |
|
417 | dummy_hk_packet.targetLogicalAddress = CCSDS_DESTINATION_ID; | |
416 | dummy_hk_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID; |
|
418 | dummy_hk_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID; | |
417 | dummy_hk_packet.reserved = DEFAULT_RESERVED; |
|
419 | dummy_hk_packet.reserved = DEFAULT_RESERVED; | |
418 | dummy_hk_packet.userApplication = CCSDS_USER_APP; |
|
420 | dummy_hk_packet.userApplication = CCSDS_USER_APP; | |
419 | dummy_hk_packet.packetID[0] = (unsigned char) (APID_TM_HK >> 8); |
|
421 | dummy_hk_packet.packetID[0] = (unsigned char) (APID_TM_HK >> 8); | |
420 | dummy_hk_packet.packetID[1] = (unsigned char) (APID_TM_HK); |
|
422 | dummy_hk_packet.packetID[1] = (unsigned char) (APID_TM_HK); | |
421 | dummy_hk_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE; |
|
423 | dummy_hk_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE; | |
422 | dummy_hk_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT; |
|
424 | dummy_hk_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT; | |
423 | dummy_hk_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> 8); |
|
425 | dummy_hk_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> 8); | |
424 | dummy_hk_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK ); |
|
426 | dummy_hk_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK ); | |
425 | dummy_hk_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; |
|
427 | dummy_hk_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; | |
426 | dummy_hk_packet.serviceType = TM_TYPE_HK; |
|
428 | dummy_hk_packet.serviceType = TM_TYPE_HK; | |
427 | dummy_hk_packet.serviceSubType = TM_SUBTYPE_HK; |
|
429 | dummy_hk_packet.serviceSubType = TM_SUBTYPE_HK; | |
428 | dummy_hk_packet.destinationID = TM_DESTINATION_ID_GROUND; |
|
430 | dummy_hk_packet.destinationID = TM_DESTINATION_ID_GROUND; | |
429 | dummy_hk_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24); |
|
431 | dummy_hk_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24); | |
430 | dummy_hk_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16); |
|
432 | dummy_hk_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16); | |
431 | dummy_hk_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8); |
|
433 | dummy_hk_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8); | |
432 | dummy_hk_packet.time[3] = (unsigned char) (time_management_regs->coarse_time); |
|
434 | dummy_hk_packet.time[3] = (unsigned char) (time_management_regs->coarse_time); | |
433 | dummy_hk_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8); |
|
435 | dummy_hk_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8); | |
434 | dummy_hk_packet.time[5] = (unsigned char) (time_management_regs->fine_time); |
|
436 | dummy_hk_packet.time[5] = (unsigned char) (time_management_regs->fine_time); | |
435 | dummy_hk_packet.sid = SID_HK; |
|
437 | dummy_hk_packet.sid = SID_HK; | |
436 |
|
438 | |||
437 | // init status word |
|
439 | // init status word | |
438 | dummy_hk_packet.lfr_status_word[0] = 0xff; |
|
440 | dummy_hk_packet.lfr_status_word[0] = 0xff; | |
439 | dummy_hk_packet.lfr_status_word[1] = 0xff; |
|
441 | dummy_hk_packet.lfr_status_word[1] = 0xff; | |
440 | // init software version |
|
442 | // init software version | |
441 | dummy_hk_packet.lfr_sw_version[0] = SW_VERSION_N1; |
|
443 | dummy_hk_packet.lfr_sw_version[0] = SW_VERSION_N1; | |
442 | dummy_hk_packet.lfr_sw_version[1] = SW_VERSION_N2; |
|
444 | dummy_hk_packet.lfr_sw_version[1] = SW_VERSION_N2; | |
443 | dummy_hk_packet.lfr_sw_version[2] = SW_VERSION_N3; |
|
445 | dummy_hk_packet.lfr_sw_version[2] = SW_VERSION_N3; | |
444 | dummy_hk_packet.lfr_sw_version[3] = SW_VERSION_N4; |
|
446 | dummy_hk_packet.lfr_sw_version[3] = SW_VERSION_N4; | |
445 | // init fpga version |
|
447 | // init fpga version | |
446 | parameters = (unsigned char *) (REGS_ADDR_WAVEFORM_PICKER + 0xb0); |
|
448 | parameters = (unsigned char *) (REGS_ADDR_WAVEFORM_PICKER + 0xb0); | |
447 | dummy_hk_packet.lfr_fpga_version[0] = parameters[1]; // n1 |
|
449 | dummy_hk_packet.lfr_fpga_version[0] = parameters[1]; // n1 | |
448 | dummy_hk_packet.lfr_fpga_version[1] = parameters[2]; // n2 |
|
450 | dummy_hk_packet.lfr_fpga_version[1] = parameters[2]; // n2 | |
449 | dummy_hk_packet.lfr_fpga_version[2] = parameters[3]; // n3 |
|
451 | dummy_hk_packet.lfr_fpga_version[2] = parameters[3]; // n3 | |
450 |
|
452 | |||
451 | parameters = (unsigned char *) &dummy_hk_packet.hk_lfr_cpu_load; |
|
453 | parameters = (unsigned char *) &dummy_hk_packet.hk_lfr_cpu_load; | |
452 |
|
454 | |||
453 | for (i=0; i<100; i++) |
|
455 | for (i=0; i<100; i++) | |
454 | { |
|
456 | { | |
455 | parameters[i] = 0xff; |
|
457 | parameters[i] = 0xff; | |
456 | } |
|
458 | } | |
457 |
|
459 | |||
458 | get_message_queue_id_send( &queue_id ); |
|
460 | get_message_queue_id_send( &queue_id ); | |
459 |
|
461 | |||
460 | rtems_message_queue_send( queue_id, &dummy_hk_packet, |
|
462 | rtems_message_queue_send( queue_id, &dummy_hk_packet, | |
461 | PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES); |
|
463 | PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES); | |
462 | } |
|
464 | } | |
463 |
|
465 | |||
464 | void get_temperatures( unsigned char *temperatures ) |
|
466 | void get_temperatures( unsigned char *temperatures ) | |
465 | { |
|
467 | { | |
466 | unsigned char* temp_scm_ptr; |
|
468 | unsigned char* temp_scm_ptr; | |
467 | unsigned char* temp_pcb_ptr; |
|
469 | unsigned char* temp_pcb_ptr; | |
468 | unsigned char* temp_fpga_ptr; |
|
470 | unsigned char* temp_fpga_ptr; | |
469 |
|
471 | |||
470 | // SEL1 SEL0 |
|
472 | // SEL1 SEL0 | |
471 | // 0 0 => PCB |
|
473 | // 0 0 => PCB | |
472 | // 0 1 => FPGA |
|
474 | // 0 1 => FPGA | |
473 | // 1 0 => SCM |
|
475 | // 1 0 => SCM | |
474 |
|
476 | |||
475 | temp_scm_ptr = (unsigned char *) &time_management_regs->temp_scm; |
|
477 | temp_scm_ptr = (unsigned char *) &time_management_regs->temp_scm; | |
476 | temp_pcb_ptr = (unsigned char *) &time_management_regs->temp_pcb; |
|
478 | temp_pcb_ptr = (unsigned char *) &time_management_regs->temp_pcb; | |
477 | temp_fpga_ptr = (unsigned char *) &time_management_regs->temp_fpga; |
|
479 | temp_fpga_ptr = (unsigned char *) &time_management_regs->temp_fpga; | |
478 |
|
480 | |||
479 | temperatures[0] = temp_scm_ptr[2]; |
|
481 | temperatures[0] = temp_scm_ptr[2]; | |
480 | temperatures[1] = temp_scm_ptr[3]; |
|
482 | temperatures[1] = temp_scm_ptr[3]; | |
481 | temperatures[2] = temp_pcb_ptr[2]; |
|
483 | temperatures[2] = temp_pcb_ptr[2]; | |
482 | temperatures[3] = temp_pcb_ptr[3]; |
|
484 | temperatures[3] = temp_pcb_ptr[3]; | |
483 | temperatures[4] = temp_fpga_ptr[2]; |
|
485 | temperatures[4] = temp_fpga_ptr[2]; | |
484 | temperatures[5] = temp_fpga_ptr[3]; |
|
486 | temperatures[5] = temp_fpga_ptr[3]; | |
485 | } |
|
487 | } | |
486 |
|
488 | |||
487 | void get_v_e1_e2_f3( unsigned char *spacecraft_potential ) |
|
489 | void get_v_e1_e2_f3( unsigned char *spacecraft_potential ) | |
488 | { |
|
490 | { | |
489 | unsigned char* v_ptr; |
|
491 | unsigned char* v_ptr; | |
490 | unsigned char* e1_ptr; |
|
492 | unsigned char* e1_ptr; | |
491 | unsigned char* e2_ptr; |
|
493 | unsigned char* e2_ptr; | |
492 |
|
494 | |||
493 | v_ptr = (unsigned char *) &waveform_picker_regs->v; |
|
495 | v_ptr = (unsigned char *) &waveform_picker_regs->v; | |
494 | e1_ptr = (unsigned char *) &waveform_picker_regs->e1; |
|
496 | e1_ptr = (unsigned char *) &waveform_picker_regs->e1; | |
495 | e2_ptr = (unsigned char *) &waveform_picker_regs->e2; |
|
497 | e2_ptr = (unsigned char *) &waveform_picker_regs->e2; | |
496 |
|
498 | |||
497 | spacecraft_potential[0] = v_ptr[2]; |
|
499 | spacecraft_potential[0] = v_ptr[2]; | |
498 | spacecraft_potential[1] = v_ptr[3]; |
|
500 | spacecraft_potential[1] = v_ptr[3]; | |
499 | spacecraft_potential[2] = e1_ptr[2]; |
|
501 | spacecraft_potential[2] = e1_ptr[2]; | |
500 | spacecraft_potential[3] = e1_ptr[3]; |
|
502 | spacecraft_potential[3] = e1_ptr[3]; | |
501 | spacecraft_potential[4] = e2_ptr[2]; |
|
503 | spacecraft_potential[4] = e2_ptr[2]; | |
502 | spacecraft_potential[5] = e2_ptr[3]; |
|
504 | spacecraft_potential[5] = e2_ptr[3]; | |
503 | } |
|
505 | } | |
504 |
|
506 | |||
505 | void get_cpu_load( unsigned char *resource_statistics ) |
|
507 | void get_cpu_load( unsigned char *resource_statistics ) | |
506 | { |
|
508 | { | |
507 | unsigned char cpu_load; |
|
509 | unsigned char cpu_load; | |
508 |
|
510 | |||
509 | cpu_load = lfr_rtems_cpu_usage_report(); |
|
511 | cpu_load = lfr_rtems_cpu_usage_report(); | |
510 |
|
512 | |||
511 | // HK_LFR_CPU_LOAD |
|
513 | // HK_LFR_CPU_LOAD | |
512 | resource_statistics[0] = cpu_load; |
|
514 | resource_statistics[0] = cpu_load; | |
513 |
|
515 | |||
514 | // HK_LFR_CPU_LOAD_MAX |
|
516 | // HK_LFR_CPU_LOAD_MAX | |
515 | if (cpu_load > resource_statistics[1]) |
|
517 | if (cpu_load > resource_statistics[1]) | |
516 | { |
|
518 | { | |
517 | resource_statistics[1] = cpu_load; |
|
519 | resource_statistics[1] = cpu_load; | |
518 | } |
|
520 | } | |
519 |
|
521 | |||
520 | // CPU_LOAD_AVE |
|
522 | // CPU_LOAD_AVE | |
521 | resource_statistics[2] = 0; |
|
523 | resource_statistics[2] = 0; | |
522 |
|
524 | |||
523 | #ifndef PRINT_TASK_STATISTICS |
|
525 | #ifndef PRINT_TASK_STATISTICS | |
524 | rtems_cpu_usage_reset(); |
|
526 | rtems_cpu_usage_reset(); | |
525 | #endif |
|
527 | #endif | |
526 |
|
528 | |||
527 | } |
|
529 | } | |
528 |
|
530 | |||
529 | void set_hk_lfr_sc_potential_flag( bool state ) |
|
531 | void set_hk_lfr_sc_potential_flag( bool state ) | |
530 | { |
|
532 | { | |
531 | if (state == true) |
|
533 | if (state == true) | |
532 | { |
|
534 | { | |
533 | housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] | 0x40; // [0100 0000] |
|
535 | housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] | 0x40; // [0100 0000] | |
534 | } |
|
536 | } | |
535 | else |
|
537 | else | |
536 | { |
|
538 | { | |
537 | housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] & 0xbf; // [1011 1111] |
|
539 | housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] & 0xbf; // [1011 1111] | |
538 | } |
|
540 | } | |
539 | } |
|
541 | } | |
540 |
|
542 | |||
541 | void set_hk_lfr_mag_fields_flag( bool state ) |
|
543 | void set_hk_lfr_mag_fields_flag( bool state ) | |
542 | { |
|
544 | { | |
543 | if (state == true) |
|
545 | if (state == true) | |
544 | { |
|
546 | { | |
545 | housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] | 0x20; // [0010 0000] |
|
547 | housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] | 0x20; // [0010 0000] | |
546 | } |
|
548 | } | |
547 | else |
|
549 | else | |
548 | { |
|
550 | { | |
549 | housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] & 0xd7; // [1101 1111] |
|
551 | housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] & 0xd7; // [1101 1111] | |
550 | } |
|
552 | } | |
551 | } |
|
553 | } | |
552 |
|
554 | |||
553 | void set_hk_lfr_calib_enable( bool state ) |
|
555 | void set_hk_lfr_calib_enable( bool state ) | |
554 | { |
|
556 | { | |
555 | if (state == true) |
|
557 | if (state == true) | |
556 | { |
|
558 | { | |
557 | housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] | 0x08; // [0000 1000] |
|
559 | housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] | 0x08; // [0000 1000] | |
558 | } |
|
560 | } | |
559 | else |
|
561 | else | |
560 | { |
|
562 | { | |
561 | housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] & 0xf7; // [1111 0111] |
|
563 | housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] & 0xf7; // [1111 0111] | |
562 | } |
|
564 | } | |
563 | } |
|
565 | } | |
564 |
|
566 | |||
|
567 | void set_hk_lfr_reset_cause( enum lfr_reset_cause_t lfr_reset_cause ) | |||
|
568 | { | |||
|
569 | housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] | |||
|
570 | | (lfr_reset_cause & 0x07 ); // [0000 0111] | |||
|
571 | } |
General Comments 0
You need to be logged in to leave comments.
Login now