@@ -1,1095 +1,1103 | |||||
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) average_v; |
|
457 | hk_lfr_sc_v_f3_as_int16 = (int16_t) average_v; | |
458 | hk_lfr_sc_e1_f3_as_int16 = (int16_t) average_e1; |
|
458 | hk_lfr_sc_e1_f3_as_int16 = (int16_t) average_e1; | |
459 | hk_lfr_sc_e2_f3_as_int16 = (int16_t) average_e2; |
|
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 | rtems_task scrubbing_task( rtems_task_argument unused ) |
|
524 | rtems_task scrubbing_task( rtems_task_argument unused ) | |
525 | { |
|
525 | { | |
526 | /** This RTEMS taks is used to avoid entering IDLE task and also scrub memory to increase scubbing frequency. |
|
526 | /** This RTEMS taks is used to avoid entering IDLE task and also scrub memory to increase scubbing frequency. | |
527 | * |
|
527 | * | |
528 | * @param unused is the starting argument of the RTEMS task |
|
528 | * @param unused is the starting argument of the RTEMS task | |
529 | * |
|
529 | * | |
530 | * The scrubbing reads continuously memory when no other tasks are ready. |
|
530 | * The scrubbing reads continuously memory when no other tasks are ready. | |
531 | * |
|
531 | * | |
532 | */ |
|
532 | */ | |
533 |
|
533 | |||
534 | BOOT_PRINTF("in SCRUBBING *** \n"); |
|
534 | BOOT_PRINTF("in SCRUBBING *** \n"); | |
535 | volatile int i=0; |
|
535 | volatile int i=0; | |
536 | volatile float valuef = 1.; |
|
536 | volatile float valuef = 1.; | |
537 | volatile uint32_t* RAM=(uint32_t*)0x40000000; |
|
537 | volatile uint32_t* RAM=(uint32_t*)0x40000000; | |
538 | volatile uint32_t value; |
|
538 | volatile uint32_t value; | |
539 | while(1){ |
|
539 | while(1){ | |
540 | i=(i+1)%(1024*1024); |
|
540 | i=(i+1)%(1024*1024); | |
541 | valuef += 10.f*(float)RAM[i]; |
|
541 | valuef += 10.f*(float)RAM[i]; | |
542 | } |
|
542 | } | |
543 | } |
|
543 | } | |
544 |
|
544 | |||
545 | rtems_task calibration_sweep_task( rtems_task_argument unused ) |
|
545 | rtems_task calibration_sweep_task( rtems_task_argument unused ) | |
546 | { |
|
546 | { | |
547 | /** This RTEMS taks is used to change calibration signal smapling frequency between snapshots. |
|
547 | /** This RTEMS taks is used to change calibration signal smapling frequency between snapshots. | |
548 | * |
|
548 | * | |
549 | * @param unused is the starting argument of the RTEMS task |
|
549 | * @param unused is the starting argument of the RTEMS task | |
550 | * |
|
550 | * | |
551 | * If calibration is enabled, this task will divide by two the calibration signal smapling frequency between snapshots. |
|
551 | * If calibration is enabled, this task will divide by two the calibration signal smapling frequency between snapshots. | |
552 | * When minimum sampling frequency is reach it will jump to maximum sampling frequency to loop indefinitely. |
|
552 | * When minimum sampling frequency is reach it will jump to maximum sampling frequency to loop indefinitely. | |
553 | * |
|
553 | * | |
554 | */ |
|
554 | */ | |
555 | rtems_event_set event_out; |
|
555 | rtems_event_set event_out; | |
556 | BOOT_PRINTF("in calibration sweep *** \n"); |
|
556 | BOOT_PRINTF("in calibration sweep *** \n"); | |
557 | rtems_interval ticks_per_seconds = rtems_clock_get_ticks_per_second(); |
|
557 | rtems_interval ticks_per_seconds = rtems_clock_get_ticks_per_second(); | |
558 | while(1){ |
|
558 | while(1){ | |
559 | // Waiting for next F0 snapshot |
|
559 | // Waiting for next F0 snapshot | |
560 | rtems_event_receive(RTEMS_EVENT_CAL_SWEEP_WAKE, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); |
|
560 | rtems_event_receive(RTEMS_EVENT_CAL_SWEEP_WAKE, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); | |
561 | if(time_management_regs->calDACCtrl & BIT_CAL_ENABLE) |
|
561 | if(time_management_regs->calDACCtrl & BIT_CAL_ENABLE) | |
562 | { |
|
562 | { | |
563 | unsigned int delta_snapshot; |
|
563 | unsigned int delta_snapshot; | |
564 | delta_snapshot = (parameter_dump_packet.sy_lfr_n_swf_p[0] * CONST_256) |
|
564 | delta_snapshot = (parameter_dump_packet.sy_lfr_n_swf_p[0] * CONST_256) | |
565 | + parameter_dump_packet.sy_lfr_n_swf_p[1]; |
|
565 | + parameter_dump_packet.sy_lfr_n_swf_p[1]; | |
566 | // We are woken almost in the center of a snapshot -> let's wait for sy_lfr_n_swf_p / 2 |
|
566 | // We are woken almost in the center of a snapshot -> let's wait for sy_lfr_n_swf_p / 2 | |
567 | rtems_task_wake_after( ticks_per_seconds * delta_snapshot / 2); |
|
567 | rtems_task_wake_after( ticks_per_seconds * delta_snapshot / 2); | |
568 | if(time_management_regs->calDivisor >= CAL_F_DIVISOR_MAX){ |
|
568 | if(time_management_regs->calDivisor >= CAL_F_DIVISOR_MAX){ | |
569 | time_management_regs->calDivisor = CAL_F_DIVISOR_MIN; |
|
569 | time_management_regs->calDivisor = CAL_F_DIVISOR_MIN; | |
570 | } |
|
570 | } | |
571 | else{ |
|
571 | else{ | |
572 | time_management_regs->calDivisor *= 2; |
|
572 | time_management_regs->calDivisor *= 2; | |
573 | } |
|
573 | } | |
574 | } |
|
574 | } | |
575 |
|
575 | |||
576 |
|
576 | |||
577 |
|
577 | |||
578 | } |
|
578 | } | |
579 |
|
579 | |||
580 | } |
|
580 | } | |
581 |
|
581 | |||
582 |
|
582 | |||
583 | //***************************** |
|
583 | //***************************** | |
584 | // init housekeeping parameters |
|
584 | // init housekeeping parameters | |
585 |
|
585 | |||
586 | void init_housekeeping_parameters( void ) |
|
586 | void init_housekeeping_parameters( void ) | |
587 | { |
|
587 | { | |
588 | /** This function initialize the housekeeping_packet global variable with default values. |
|
588 | /** This function initialize the housekeeping_packet global variable with default values. | |
589 | * |
|
589 | * | |
590 | */ |
|
590 | */ | |
591 |
|
591 | |||
592 | unsigned int i = 0; |
|
592 | unsigned int i = 0; | |
593 | unsigned char *parameters; |
|
593 | unsigned char *parameters; | |
594 | unsigned char sizeOfHK; |
|
594 | unsigned char sizeOfHK; | |
595 |
|
595 | |||
596 | sizeOfHK = sizeof( Packet_TM_LFR_HK_t ); |
|
596 | sizeOfHK = sizeof( Packet_TM_LFR_HK_t ); | |
597 |
|
597 | |||
598 | parameters = (unsigned char*) &housekeeping_packet; |
|
598 | parameters = (unsigned char*) &housekeeping_packet; | |
599 |
|
599 | |||
600 | for(i = 0; i< sizeOfHK; i++) |
|
600 | for(i = 0; i< sizeOfHK; i++) | |
601 | { |
|
601 | { | |
602 | parameters[i] = INIT_CHAR; |
|
602 | parameters[i] = INIT_CHAR; | |
603 | } |
|
603 | } | |
604 |
|
604 | |||
605 | housekeeping_packet.targetLogicalAddress = CCSDS_DESTINATION_ID; |
|
605 | housekeeping_packet.targetLogicalAddress = CCSDS_DESTINATION_ID; | |
606 | housekeeping_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID; |
|
606 | housekeeping_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID; | |
607 | housekeeping_packet.reserved = DEFAULT_RESERVED; |
|
607 | housekeeping_packet.reserved = DEFAULT_RESERVED; | |
608 | housekeeping_packet.userApplication = CCSDS_USER_APP; |
|
608 | housekeeping_packet.userApplication = CCSDS_USER_APP; | |
609 | housekeeping_packet.packetID[0] = (unsigned char) (APID_TM_HK >> SHIFT_1_BYTE); |
|
609 | housekeeping_packet.packetID[0] = (unsigned char) (APID_TM_HK >> SHIFT_1_BYTE); | |
610 | housekeeping_packet.packetID[1] = (unsigned char) (APID_TM_HK); |
|
610 | housekeeping_packet.packetID[1] = (unsigned char) (APID_TM_HK); | |
611 | housekeeping_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE; |
|
611 | housekeeping_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE; | |
612 | housekeeping_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT; |
|
612 | housekeeping_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT; | |
613 | housekeeping_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> SHIFT_1_BYTE); |
|
613 | housekeeping_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> SHIFT_1_BYTE); | |
614 | housekeeping_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK ); |
|
614 | housekeeping_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK ); | |
615 | housekeeping_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; |
|
615 | housekeeping_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; | |
616 | housekeeping_packet.serviceType = TM_TYPE_HK; |
|
616 | housekeeping_packet.serviceType = TM_TYPE_HK; | |
617 | housekeeping_packet.serviceSubType = TM_SUBTYPE_HK; |
|
617 | housekeeping_packet.serviceSubType = TM_SUBTYPE_HK; | |
618 | housekeeping_packet.destinationID = TM_DESTINATION_ID_GROUND; |
|
618 | housekeeping_packet.destinationID = TM_DESTINATION_ID_GROUND; | |
619 | housekeeping_packet.sid = SID_HK; |
|
619 | housekeeping_packet.sid = SID_HK; | |
620 |
|
620 | |||
621 | // init status word |
|
621 | // init status word | |
622 | housekeeping_packet.lfr_status_word[0] = DEFAULT_STATUS_WORD_BYTE0; |
|
622 | housekeeping_packet.lfr_status_word[0] = DEFAULT_STATUS_WORD_BYTE0; | |
623 | housekeeping_packet.lfr_status_word[1] = DEFAULT_STATUS_WORD_BYTE1; |
|
623 | housekeeping_packet.lfr_status_word[1] = DEFAULT_STATUS_WORD_BYTE1; | |
624 | // init software version |
|
624 | // init software version | |
625 | housekeeping_packet.lfr_sw_version[0] = SW_VERSION_N1; |
|
625 | housekeeping_packet.lfr_sw_version[0] = SW_VERSION_N1; | |
626 | housekeeping_packet.lfr_sw_version[1] = SW_VERSION_N2; |
|
626 | housekeeping_packet.lfr_sw_version[1] = SW_VERSION_N2; | |
627 | housekeeping_packet.lfr_sw_version[BYTE_2] = SW_VERSION_N3; |
|
627 | housekeeping_packet.lfr_sw_version[BYTE_2] = SW_VERSION_N3; | |
628 | housekeeping_packet.lfr_sw_version[BYTE_3] = SW_VERSION_N4; |
|
628 | housekeeping_packet.lfr_sw_version[BYTE_3] = SW_VERSION_N4; | |
629 | // init fpga version |
|
629 | // init fpga version | |
630 | parameters = (unsigned char *) (REGS_ADDR_VHDL_VERSION); |
|
630 | parameters = (unsigned char *) (REGS_ADDR_VHDL_VERSION); | |
631 | housekeeping_packet.lfr_fpga_version[BYTE_0] = parameters[BYTE_1]; // n1 |
|
631 | housekeeping_packet.lfr_fpga_version[BYTE_0] = parameters[BYTE_1]; // n1 | |
632 | housekeeping_packet.lfr_fpga_version[BYTE_1] = parameters[BYTE_2]; // n2 |
|
632 | housekeeping_packet.lfr_fpga_version[BYTE_1] = parameters[BYTE_2]; // n2 | |
633 | housekeeping_packet.lfr_fpga_version[BYTE_2] = parameters[BYTE_3]; // n3 |
|
633 | housekeeping_packet.lfr_fpga_version[BYTE_2] = parameters[BYTE_3]; // n3 | |
634 |
|
634 | |||
635 | housekeeping_packet.hk_lfr_q_sd_fifo_size = MSG_QUEUE_COUNT_SEND; |
|
635 | housekeeping_packet.hk_lfr_q_sd_fifo_size = MSG_QUEUE_COUNT_SEND; | |
636 | housekeeping_packet.hk_lfr_q_rv_fifo_size = MSG_QUEUE_COUNT_RECV; |
|
636 | housekeeping_packet.hk_lfr_q_rv_fifo_size = MSG_QUEUE_COUNT_RECV; | |
637 | housekeeping_packet.hk_lfr_q_p0_fifo_size = MSG_QUEUE_COUNT_PRC0; |
|
637 | housekeeping_packet.hk_lfr_q_p0_fifo_size = MSG_QUEUE_COUNT_PRC0; | |
638 | housekeeping_packet.hk_lfr_q_p1_fifo_size = MSG_QUEUE_COUNT_PRC1; |
|
638 | housekeeping_packet.hk_lfr_q_p1_fifo_size = MSG_QUEUE_COUNT_PRC1; | |
639 | housekeeping_packet.hk_lfr_q_p2_fifo_size = MSG_QUEUE_COUNT_PRC2; |
|
639 | housekeeping_packet.hk_lfr_q_p2_fifo_size = MSG_QUEUE_COUNT_PRC2; | |
640 | } |
|
640 | } | |
641 |
|
641 | |||
642 | void increment_seq_counter( unsigned short *packetSequenceControl ) |
|
642 | void increment_seq_counter( unsigned short *packetSequenceControl ) | |
643 | { |
|
643 | { | |
644 | /** This function increment the sequence counter passes in argument. |
|
644 | /** This function increment the sequence counter passes in argument. | |
645 | * |
|
645 | * | |
646 | * The increment does not affect the grouping flag. In case of an overflow, the counter is reset to 0. |
|
646 | * The increment does not affect the grouping flag. In case of an overflow, the counter is reset to 0. | |
647 | * |
|
647 | * | |
648 | */ |
|
648 | */ | |
649 |
|
649 | |||
650 | unsigned short segmentation_grouping_flag; |
|
650 | unsigned short segmentation_grouping_flag; | |
651 | unsigned short sequence_cnt; |
|
651 | unsigned short sequence_cnt; | |
652 |
|
652 | |||
653 | segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << SHIFT_1_BYTE; // keep bits 7 downto 6 |
|
653 | segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << SHIFT_1_BYTE; // keep bits 7 downto 6 | |
654 | sequence_cnt = (*packetSequenceControl) & SEQ_CNT_MASK; // [0011 1111 1111 1111] |
|
654 | sequence_cnt = (*packetSequenceControl) & SEQ_CNT_MASK; // [0011 1111 1111 1111] | |
655 |
|
655 | |||
656 | if ( sequence_cnt < SEQ_CNT_MAX) |
|
656 | if ( sequence_cnt < SEQ_CNT_MAX) | |
657 | { |
|
657 | { | |
658 | sequence_cnt = sequence_cnt + 1; |
|
658 | sequence_cnt = sequence_cnt + 1; | |
659 | } |
|
659 | } | |
660 | else |
|
660 | else | |
661 | { |
|
661 | { | |
662 | sequence_cnt = 0; |
|
662 | sequence_cnt = 0; | |
663 | } |
|
663 | } | |
664 |
|
664 | |||
665 | *packetSequenceControl = segmentation_grouping_flag | sequence_cnt ; |
|
665 | *packetSequenceControl = segmentation_grouping_flag | sequence_cnt ; | |
666 | } |
|
666 | } | |
667 |
|
667 | |||
668 | void getTime( unsigned char *time) |
|
668 | void getTime( unsigned char *time) | |
669 | { |
|
669 | { | |
670 | /** This function write the current local time in the time buffer passed in argument. |
|
670 | /** This function write the current local time in the time buffer passed in argument. | |
671 | * |
|
671 | * | |
672 | */ |
|
672 | */ | |
673 |
|
673 | |||
674 | time[0] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_3_BYTES); |
|
674 | time[0] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_3_BYTES); | |
675 | time[1] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_2_BYTES); |
|
675 | time[1] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_2_BYTES); | |
676 | time[2] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_1_BYTE); |
|
676 | time[2] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_1_BYTE); | |
677 | time[3] = (unsigned char) (time_management_regs->coarse_time); |
|
677 | time[3] = (unsigned char) (time_management_regs->coarse_time); | |
678 | time[4] = (unsigned char) (time_management_regs->fine_time>>SHIFT_1_BYTE); |
|
678 | time[4] = (unsigned char) (time_management_regs->fine_time>>SHIFT_1_BYTE); | |
679 | time[5] = (unsigned char) (time_management_regs->fine_time); |
|
679 | time[5] = (unsigned char) (time_management_regs->fine_time); | |
680 | } |
|
680 | } | |
681 |
|
681 | |||
682 | unsigned long long int getTimeAsUnsignedLongLongInt( ) |
|
682 | unsigned long long int getTimeAsUnsignedLongLongInt( ) | |
683 | { |
|
683 | { | |
684 | /** This function write the current local time in the time buffer passed in argument. |
|
684 | /** This function write the current local time in the time buffer passed in argument. | |
685 | * |
|
685 | * | |
686 | */ |
|
686 | */ | |
687 | unsigned long long int time; |
|
687 | unsigned long long int time; | |
688 |
|
688 | |||
689 | time = ( (unsigned long long int) (time_management_regs->coarse_time & COARSE_TIME_MASK) << SHIFT_2_BYTES ) |
|
689 | time = ( (unsigned long long int) (time_management_regs->coarse_time & COARSE_TIME_MASK) << SHIFT_2_BYTES ) | |
690 | + time_management_regs->fine_time; |
|
690 | + time_management_regs->fine_time; | |
691 |
|
691 | |||
692 | return time; |
|
692 | return time; | |
693 | } |
|
693 | } | |
694 |
|
694 | |||
695 | void send_dumb_hk( void ) |
|
695 | void send_dumb_hk( void ) | |
696 | { |
|
696 | { | |
697 | Packet_TM_LFR_HK_t dummy_hk_packet; |
|
697 | Packet_TM_LFR_HK_t dummy_hk_packet; | |
698 | unsigned char *parameters; |
|
698 | unsigned char *parameters; | |
699 | unsigned int i; |
|
699 | unsigned int i; | |
700 | rtems_id queue_id; |
|
700 | rtems_id queue_id; | |
701 |
|
701 | |||
702 | queue_id = RTEMS_ID_NONE; |
|
702 | queue_id = RTEMS_ID_NONE; | |
703 |
|
703 | |||
704 | dummy_hk_packet.targetLogicalAddress = CCSDS_DESTINATION_ID; |
|
704 | dummy_hk_packet.targetLogicalAddress = CCSDS_DESTINATION_ID; | |
705 | dummy_hk_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID; |
|
705 | dummy_hk_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID; | |
706 | dummy_hk_packet.reserved = DEFAULT_RESERVED; |
|
706 | dummy_hk_packet.reserved = DEFAULT_RESERVED; | |
707 | dummy_hk_packet.userApplication = CCSDS_USER_APP; |
|
707 | dummy_hk_packet.userApplication = CCSDS_USER_APP; | |
708 | dummy_hk_packet.packetID[0] = (unsigned char) (APID_TM_HK >> SHIFT_1_BYTE); |
|
708 | dummy_hk_packet.packetID[0] = (unsigned char) (APID_TM_HK >> SHIFT_1_BYTE); | |
709 | dummy_hk_packet.packetID[1] = (unsigned char) (APID_TM_HK); |
|
709 | dummy_hk_packet.packetID[1] = (unsigned char) (APID_TM_HK); | |
710 | dummy_hk_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE; |
|
710 | dummy_hk_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE; | |
711 | dummy_hk_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT; |
|
711 | dummy_hk_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT; | |
712 | dummy_hk_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> SHIFT_1_BYTE); |
|
712 | dummy_hk_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> SHIFT_1_BYTE); | |
713 | dummy_hk_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK ); |
|
713 | dummy_hk_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK ); | |
714 | dummy_hk_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; |
|
714 | dummy_hk_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; | |
715 | dummy_hk_packet.serviceType = TM_TYPE_HK; |
|
715 | dummy_hk_packet.serviceType = TM_TYPE_HK; | |
716 | dummy_hk_packet.serviceSubType = TM_SUBTYPE_HK; |
|
716 | dummy_hk_packet.serviceSubType = TM_SUBTYPE_HK; | |
717 | dummy_hk_packet.destinationID = TM_DESTINATION_ID_GROUND; |
|
717 | dummy_hk_packet.destinationID = TM_DESTINATION_ID_GROUND; | |
718 | dummy_hk_packet.time[0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES); |
|
718 | dummy_hk_packet.time[0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES); | |
719 | dummy_hk_packet.time[1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES); |
|
719 | dummy_hk_packet.time[1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES); | |
720 | dummy_hk_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE); |
|
720 | dummy_hk_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE); | |
721 | dummy_hk_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time); |
|
721 | dummy_hk_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time); | |
722 | dummy_hk_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE); |
|
722 | dummy_hk_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE); | |
723 | dummy_hk_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time); |
|
723 | dummy_hk_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time); | |
724 | dummy_hk_packet.sid = SID_HK; |
|
724 | dummy_hk_packet.sid = SID_HK; | |
725 |
|
725 | |||
726 | // init status word |
|
726 | // init status word | |
727 | dummy_hk_packet.lfr_status_word[0] = INT8_ALL_F; |
|
727 | dummy_hk_packet.lfr_status_word[0] = INT8_ALL_F; | |
728 | dummy_hk_packet.lfr_status_word[1] = INT8_ALL_F; |
|
728 | dummy_hk_packet.lfr_status_word[1] = INT8_ALL_F; | |
729 | // init software version |
|
729 | // init software version | |
730 | dummy_hk_packet.lfr_sw_version[0] = SW_VERSION_N1; |
|
730 | dummy_hk_packet.lfr_sw_version[0] = SW_VERSION_N1; | |
731 | dummy_hk_packet.lfr_sw_version[1] = SW_VERSION_N2; |
|
731 | dummy_hk_packet.lfr_sw_version[1] = SW_VERSION_N2; | |
732 | dummy_hk_packet.lfr_sw_version[BYTE_2] = SW_VERSION_N3; |
|
732 | dummy_hk_packet.lfr_sw_version[BYTE_2] = SW_VERSION_N3; | |
733 | dummy_hk_packet.lfr_sw_version[BYTE_3] = SW_VERSION_N4; |
|
733 | dummy_hk_packet.lfr_sw_version[BYTE_3] = SW_VERSION_N4; | |
734 | // init fpga version |
|
734 | // init fpga version | |
735 | parameters = (unsigned char *) (REGS_ADDR_WAVEFORM_PICKER + APB_OFFSET_VHDL_REV); |
|
735 | parameters = (unsigned char *) (REGS_ADDR_WAVEFORM_PICKER + APB_OFFSET_VHDL_REV); | |
736 | dummy_hk_packet.lfr_fpga_version[BYTE_0] = parameters[BYTE_1]; // n1 |
|
736 | dummy_hk_packet.lfr_fpga_version[BYTE_0] = parameters[BYTE_1]; // n1 | |
737 | dummy_hk_packet.lfr_fpga_version[BYTE_1] = parameters[BYTE_2]; // n2 |
|
737 | dummy_hk_packet.lfr_fpga_version[BYTE_1] = parameters[BYTE_2]; // n2 | |
738 | dummy_hk_packet.lfr_fpga_version[BYTE_2] = parameters[BYTE_3]; // n3 |
|
738 | dummy_hk_packet.lfr_fpga_version[BYTE_2] = parameters[BYTE_3]; // n3 | |
739 |
|
739 | |||
740 | parameters = (unsigned char *) &dummy_hk_packet.hk_lfr_cpu_load; |
|
740 | parameters = (unsigned char *) &dummy_hk_packet.hk_lfr_cpu_load; | |
741 |
|
741 | |||
742 | for (i=0; i<(BYTE_POS_HK_REACTION_WHEELS_FREQUENCY - BYTE_POS_HK_LFR_CPU_LOAD); i++) |
|
742 | for (i=0; i<(BYTE_POS_HK_REACTION_WHEELS_FREQUENCY - BYTE_POS_HK_LFR_CPU_LOAD); i++) | |
743 | { |
|
743 | { | |
744 | parameters[i] = INT8_ALL_F; |
|
744 | parameters[i] = INT8_ALL_F; | |
745 | } |
|
745 | } | |
746 |
|
746 | |||
747 | get_message_queue_id_send( &queue_id ); |
|
747 | get_message_queue_id_send( &queue_id ); | |
748 |
|
748 | |||
749 | rtems_message_queue_send( queue_id, &dummy_hk_packet, |
|
749 | rtems_message_queue_send( queue_id, &dummy_hk_packet, | |
750 | PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES); |
|
750 | PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES); | |
751 | } |
|
751 | } | |
752 |
|
752 | |||
753 | void get_temperatures( unsigned char *temperatures ) |
|
753 | void get_temperatures( unsigned char *temperatures ) | |
754 | { |
|
754 | { | |
755 | unsigned char* temp_scm_ptr; |
|
755 | unsigned char* temp_scm_ptr; | |
756 | unsigned char* temp_pcb_ptr; |
|
756 | unsigned char* temp_pcb_ptr; | |
757 | unsigned char* temp_fpga_ptr; |
|
757 | unsigned char* temp_fpga_ptr; | |
758 |
|
758 | |||
759 | // SEL1 SEL0 |
|
759 | // SEL1 SEL0 | |
760 | // 0 0 => PCB |
|
760 | // 0 0 => PCB | |
761 | // 0 1 => FPGA |
|
761 | // 0 1 => FPGA | |
762 | // 1 0 => SCM |
|
762 | // 1 0 => SCM | |
763 |
|
763 | |||
764 | temp_scm_ptr = (unsigned char *) &time_management_regs->temp_scm; |
|
764 | temp_scm_ptr = (unsigned char *) &time_management_regs->temp_scm; | |
765 | temp_pcb_ptr = (unsigned char *) &time_management_regs->temp_pcb; |
|
765 | temp_pcb_ptr = (unsigned char *) &time_management_regs->temp_pcb; | |
766 | temp_fpga_ptr = (unsigned char *) &time_management_regs->temp_fpga; |
|
766 | temp_fpga_ptr = (unsigned char *) &time_management_regs->temp_fpga; | |
767 |
|
767 | |||
768 | temperatures[ BYTE_0 ] = temp_scm_ptr[ BYTE_2 ]; |
|
768 | temperatures[ BYTE_0 ] = temp_scm_ptr[ BYTE_2 ]; | |
769 | temperatures[ BYTE_1 ] = temp_scm_ptr[ BYTE_3 ]; |
|
769 | temperatures[ BYTE_1 ] = temp_scm_ptr[ BYTE_3 ]; | |
770 | temperatures[ BYTE_2 ] = temp_pcb_ptr[ BYTE_2 ]; |
|
770 | temperatures[ BYTE_2 ] = temp_pcb_ptr[ BYTE_2 ]; | |
771 | temperatures[ BYTE_3 ] = temp_pcb_ptr[ BYTE_3 ]; |
|
771 | temperatures[ BYTE_3 ] = temp_pcb_ptr[ BYTE_3 ]; | |
772 | temperatures[ BYTE_4 ] = temp_fpga_ptr[ BYTE_2 ]; |
|
772 | temperatures[ BYTE_4 ] = temp_fpga_ptr[ BYTE_2 ]; | |
773 | temperatures[ BYTE_5 ] = temp_fpga_ptr[ BYTE_3 ]; |
|
773 | temperatures[ BYTE_5 ] = temp_fpga_ptr[ BYTE_3 ]; | |
774 | } |
|
774 | } | |
775 |
|
775 | |||
776 | void get_v_e1_e2_f3( unsigned char *spacecraft_potential ) |
|
776 | void get_v_e1_e2_f3( unsigned char *spacecraft_potential ) | |
777 | { |
|
777 | { | |
778 | unsigned char* v_ptr; |
|
778 | unsigned char* v_ptr; | |
779 | unsigned char* e1_ptr; |
|
779 | unsigned char* e1_ptr; | |
780 | unsigned char* e2_ptr; |
|
780 | unsigned char* e2_ptr; | |
781 |
|
781 | |||
782 | v_ptr = (unsigned char *) &hk_lfr_sc_v_f3_as_int16; |
|
782 | v_ptr = (unsigned char *) &hk_lfr_sc_v_f3_as_int16; | |
783 | e1_ptr = (unsigned char *) &hk_lfr_sc_e1_f3_as_int16; |
|
783 | e1_ptr = (unsigned char *) &hk_lfr_sc_e1_f3_as_int16; | |
784 | e2_ptr = (unsigned char *) &hk_lfr_sc_e2_f3_as_int16; |
|
784 | e2_ptr = (unsigned char *) &hk_lfr_sc_e2_f3_as_int16; | |
785 |
|
785 | |||
786 | spacecraft_potential[BYTE_0] = v_ptr[0]; |
|
786 | spacecraft_potential[BYTE_0] = v_ptr[0]; | |
787 | spacecraft_potential[BYTE_1] = v_ptr[1]; |
|
787 | spacecraft_potential[BYTE_1] = v_ptr[1]; | |
788 | spacecraft_potential[BYTE_2] = e1_ptr[0]; |
|
788 | spacecraft_potential[BYTE_2] = e1_ptr[0]; | |
789 | spacecraft_potential[BYTE_3] = e1_ptr[1]; |
|
789 | spacecraft_potential[BYTE_3] = e1_ptr[1]; | |
790 | spacecraft_potential[BYTE_4] = e2_ptr[0]; |
|
790 | spacecraft_potential[BYTE_4] = e2_ptr[0]; | |
791 | spacecraft_potential[BYTE_5] = e2_ptr[1]; |
|
791 | spacecraft_potential[BYTE_5] = e2_ptr[1]; | |
792 | } |
|
792 | } | |
793 |
|
793 | |||
794 | void get_cpu_load( unsigned char *resource_statistics ) |
|
794 | void get_cpu_load( unsigned char *resource_statistics ) | |
795 | { |
|
795 | { | |
|
796 | #define LOAD_AVG_SIZE 60 | |||
|
797 | static unsigned char cpu_load_hist[LOAD_AVG_SIZE]={0}; | |||
|
798 | static char old_avg_pos=0; | |||
|
799 | static unsigned int cpu_load_avg; | |||
796 | unsigned char cpu_load; |
|
800 | unsigned char cpu_load; | |
797 |
|
801 | |||
798 | cpu_load = lfr_rtems_cpu_usage_report(); |
|
802 | cpu_load = lfr_rtems_cpu_usage_report(); | |
799 |
|
803 | |||
800 | // HK_LFR_CPU_LOAD |
|
804 | // HK_LFR_CPU_LOAD | |
801 | resource_statistics[0] = cpu_load; |
|
805 | resource_statistics[0] = cpu_load; | |
802 |
|
806 | |||
803 | // HK_LFR_CPU_LOAD_MAX |
|
807 | // HK_LFR_CPU_LOAD_MAX | |
804 | if (cpu_load > resource_statistics[1]) |
|
808 | if (cpu_load > resource_statistics[1]) | |
805 | { |
|
809 | { | |
806 | resource_statistics[1] = cpu_load; |
|
810 | resource_statistics[1] = cpu_load; | |
807 | } |
|
811 | } | |
808 |
|
812 | |||
|
813 | cpu_load_avg = cpu_load_avg - (unsigned int)cpu_load_hist[(int)old_avg_pos] + (unsigned int)cpu_load; | |||
|
814 | cpu_load_hist[(int)old_avg_pos] = cpu_load; | |||
|
815 | old_avg_pos += 1; | |||
|
816 | old_avg_pos %= LOAD_AVG_SIZE; | |||
809 | // CPU_LOAD_AVE |
|
817 | // CPU_LOAD_AVE | |
810 |
resource_statistics[BYTE_2] = |
|
818 | resource_statistics[BYTE_2] = (unsigned char)(cpu_load_avg / LOAD_AVG_SIZE); | |
811 |
|
819 | |||
812 | #ifndef PRINT_TASK_STATISTICS |
|
820 | #ifndef PRINT_TASK_STATISTICS | |
813 | rtems_cpu_usage_reset(); |
|
821 | rtems_cpu_usage_reset(); | |
814 | #endif |
|
822 | #endif | |
815 |
|
823 | |||
816 | } |
|
824 | } | |
817 |
|
825 | |||
818 | void set_hk_lfr_sc_potential_flag( bool state ) |
|
826 | void set_hk_lfr_sc_potential_flag( bool state ) | |
819 | { |
|
827 | { | |
820 | if (state == true) |
|
828 | if (state == true) | |
821 | { |
|
829 | { | |
822 | housekeeping_packet.lfr_status_word[1] = |
|
830 | housekeeping_packet.lfr_status_word[1] = | |
823 | housekeeping_packet.lfr_status_word[1] | STATUS_WORD_SC_POTENTIAL_FLAG_BIT; // [0100 0000] |
|
831 | housekeeping_packet.lfr_status_word[1] | STATUS_WORD_SC_POTENTIAL_FLAG_BIT; // [0100 0000] | |
824 | } |
|
832 | } | |
825 | else |
|
833 | else | |
826 | { |
|
834 | { | |
827 | housekeeping_packet.lfr_status_word[1] = |
|
835 | housekeeping_packet.lfr_status_word[1] = | |
828 | housekeeping_packet.lfr_status_word[1] & STATUS_WORD_SC_POTENTIAL_FLAG_MASK; // [1011 1111] |
|
836 | housekeeping_packet.lfr_status_word[1] & STATUS_WORD_SC_POTENTIAL_FLAG_MASK; // [1011 1111] | |
829 | } |
|
837 | } | |
830 | } |
|
838 | } | |
831 |
|
839 | |||
832 | void set_sy_lfr_pas_filter_enabled( bool state ) |
|
840 | void set_sy_lfr_pas_filter_enabled( bool state ) | |
833 | { |
|
841 | { | |
834 | if (state == true) |
|
842 | if (state == true) | |
835 | { |
|
843 | { | |
836 | housekeeping_packet.lfr_status_word[1] = |
|
844 | housekeeping_packet.lfr_status_word[1] = | |
837 | housekeeping_packet.lfr_status_word[1] | STATUS_WORD_PAS_FILTER_ENABLED_BIT; // [0010 0000] |
|
845 | housekeeping_packet.lfr_status_word[1] | STATUS_WORD_PAS_FILTER_ENABLED_BIT; // [0010 0000] | |
838 | } |
|
846 | } | |
839 | else |
|
847 | else | |
840 | { |
|
848 | { | |
841 | housekeeping_packet.lfr_status_word[1] = |
|
849 | housekeeping_packet.lfr_status_word[1] = | |
842 | housekeeping_packet.lfr_status_word[1] & STATUS_WORD_PAS_FILTER_ENABLED_MASK; // [1101 1111] |
|
850 | housekeeping_packet.lfr_status_word[1] & STATUS_WORD_PAS_FILTER_ENABLED_MASK; // [1101 1111] | |
843 | } |
|
851 | } | |
844 | } |
|
852 | } | |
845 |
|
853 | |||
846 | void set_sy_lfr_watchdog_enabled( bool state ) |
|
854 | void set_sy_lfr_watchdog_enabled( bool state ) | |
847 | { |
|
855 | { | |
848 | if (state == true) |
|
856 | if (state == true) | |
849 | { |
|
857 | { | |
850 | housekeeping_packet.lfr_status_word[1] = |
|
858 | housekeeping_packet.lfr_status_word[1] = | |
851 | housekeeping_packet.lfr_status_word[1] | STATUS_WORD_WATCHDOG_BIT; // [0001 0000] |
|
859 | housekeeping_packet.lfr_status_word[1] | STATUS_WORD_WATCHDOG_BIT; // [0001 0000] | |
852 | } |
|
860 | } | |
853 | else |
|
861 | else | |
854 | { |
|
862 | { | |
855 | housekeeping_packet.lfr_status_word[1] = |
|
863 | housekeeping_packet.lfr_status_word[1] = | |
856 | housekeeping_packet.lfr_status_word[1] & STATUS_WORD_WATCHDOG_MASK; // [1110 1111] |
|
864 | housekeeping_packet.lfr_status_word[1] & STATUS_WORD_WATCHDOG_MASK; // [1110 1111] | |
857 | } |
|
865 | } | |
858 | } |
|
866 | } | |
859 |
|
867 | |||
860 | void set_hk_lfr_calib_enable( bool state ) |
|
868 | void set_hk_lfr_calib_enable( bool state ) | |
861 | { |
|
869 | { | |
862 | if (state == true) |
|
870 | if (state == true) | |
863 | { |
|
871 | { | |
864 | housekeeping_packet.lfr_status_word[1] = |
|
872 | housekeeping_packet.lfr_status_word[1] = | |
865 | housekeeping_packet.lfr_status_word[1] | STATUS_WORD_CALIB_BIT; // [0000 1000] |
|
873 | housekeeping_packet.lfr_status_word[1] | STATUS_WORD_CALIB_BIT; // [0000 1000] | |
866 | } |
|
874 | } | |
867 | else |
|
875 | else | |
868 | { |
|
876 | { | |
869 | housekeeping_packet.lfr_status_word[1] = |
|
877 | housekeeping_packet.lfr_status_word[1] = | |
870 | housekeeping_packet.lfr_status_word[1] & STATUS_WORD_CALIB_MASK; // [1111 0111] |
|
878 | housekeeping_packet.lfr_status_word[1] & STATUS_WORD_CALIB_MASK; // [1111 0111] | |
871 | } |
|
879 | } | |
872 | } |
|
880 | } | |
873 |
|
881 | |||
874 | void set_hk_lfr_reset_cause( enum lfr_reset_cause_t lfr_reset_cause ) |
|
882 | void set_hk_lfr_reset_cause( enum lfr_reset_cause_t lfr_reset_cause ) | |
875 | { |
|
883 | { | |
876 | housekeeping_packet.lfr_status_word[1] = |
|
884 | housekeeping_packet.lfr_status_word[1] = | |
877 | housekeeping_packet.lfr_status_word[1] & STATUS_WORD_RESET_CAUSE_MASK; // [1111 1000] |
|
885 | housekeeping_packet.lfr_status_word[1] & STATUS_WORD_RESET_CAUSE_MASK; // [1111 1000] | |
878 |
|
886 | |||
879 | housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] |
|
887 | housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] | |
880 | | (lfr_reset_cause & STATUS_WORD_RESET_CAUSE_BITS ); // [0000 0111] |
|
888 | | (lfr_reset_cause & STATUS_WORD_RESET_CAUSE_BITS ); // [0000 0111] | |
881 |
|
889 | |||
882 | } |
|
890 | } | |
883 |
|
891 | |||
884 | void increment_hk_counter( unsigned char newValue, unsigned char oldValue, unsigned int *counter ) |
|
892 | void increment_hk_counter( unsigned char newValue, unsigned char oldValue, unsigned int *counter ) | |
885 | { |
|
893 | { | |
886 | int delta; |
|
894 | int delta; | |
887 |
|
895 | |||
888 | delta = 0; |
|
896 | delta = 0; | |
889 |
|
897 | |||
890 | if (newValue >= oldValue) |
|
898 | if (newValue >= oldValue) | |
891 | { |
|
899 | { | |
892 | delta = newValue - oldValue; |
|
900 | delta = newValue - oldValue; | |
893 | } |
|
901 | } | |
894 | else |
|
902 | else | |
895 | { |
|
903 | { | |
896 | delta = (CONST_256 - oldValue) + newValue; |
|
904 | delta = (CONST_256 - oldValue) + newValue; | |
897 | } |
|
905 | } | |
898 |
|
906 | |||
899 | *counter = *counter + delta; |
|
907 | *counter = *counter + delta; | |
900 | } |
|
908 | } | |
901 |
|
909 | |||
902 | void hk_lfr_le_update( void ) |
|
910 | void hk_lfr_le_update( void ) | |
903 | { |
|
911 | { | |
904 | static hk_lfr_le_t old_hk_lfr_le = {0}; |
|
912 | static hk_lfr_le_t old_hk_lfr_le = {0}; | |
905 | hk_lfr_le_t new_hk_lfr_le; |
|
913 | hk_lfr_le_t new_hk_lfr_le; | |
906 | unsigned int counter; |
|
914 | unsigned int counter; | |
907 |
|
915 | |||
908 | counter = (((unsigned int) housekeeping_packet.hk_lfr_le_cnt[0]) * CONST_256) + housekeeping_packet.hk_lfr_le_cnt[1]; |
|
916 | counter = (((unsigned int) housekeeping_packet.hk_lfr_le_cnt[0]) * CONST_256) + housekeeping_packet.hk_lfr_le_cnt[1]; | |
909 |
|
917 | |||
910 | // DPU |
|
918 | // DPU | |
911 | new_hk_lfr_le.dpu_spw_parity = housekeeping_packet.hk_lfr_dpu_spw_parity; |
|
919 | new_hk_lfr_le.dpu_spw_parity = housekeeping_packet.hk_lfr_dpu_spw_parity; | |
912 | new_hk_lfr_le.dpu_spw_disconnect= housekeeping_packet.hk_lfr_dpu_spw_disconnect; |
|
920 | new_hk_lfr_le.dpu_spw_disconnect= housekeeping_packet.hk_lfr_dpu_spw_disconnect; | |
913 | new_hk_lfr_le.dpu_spw_escape = housekeeping_packet.hk_lfr_dpu_spw_escape; |
|
921 | new_hk_lfr_le.dpu_spw_escape = housekeeping_packet.hk_lfr_dpu_spw_escape; | |
914 | new_hk_lfr_le.dpu_spw_credit = housekeeping_packet.hk_lfr_dpu_spw_credit; |
|
922 | new_hk_lfr_le.dpu_spw_credit = housekeeping_packet.hk_lfr_dpu_spw_credit; | |
915 | new_hk_lfr_le.dpu_spw_write_sync= housekeeping_packet.hk_lfr_dpu_spw_write_sync; |
|
923 | new_hk_lfr_le.dpu_spw_write_sync= housekeeping_packet.hk_lfr_dpu_spw_write_sync; | |
916 | // TIMECODE |
|
924 | // TIMECODE | |
917 | new_hk_lfr_le.timecode_erroneous= housekeeping_packet.hk_lfr_timecode_erroneous; |
|
925 | new_hk_lfr_le.timecode_erroneous= housekeeping_packet.hk_lfr_timecode_erroneous; | |
918 | new_hk_lfr_le.timecode_missing = housekeeping_packet.hk_lfr_timecode_missing; |
|
926 | new_hk_lfr_le.timecode_missing = housekeeping_packet.hk_lfr_timecode_missing; | |
919 | new_hk_lfr_le.timecode_invalid = housekeeping_packet.hk_lfr_timecode_invalid; |
|
927 | new_hk_lfr_le.timecode_invalid = housekeeping_packet.hk_lfr_timecode_invalid; | |
920 | // TIME |
|
928 | // TIME | |
921 | new_hk_lfr_le.time_timecode_it = housekeeping_packet.hk_lfr_time_timecode_it; |
|
929 | new_hk_lfr_le.time_timecode_it = housekeeping_packet.hk_lfr_time_timecode_it; | |
922 | new_hk_lfr_le.time_not_synchro = housekeeping_packet.hk_lfr_time_not_synchro; |
|
930 | new_hk_lfr_le.time_not_synchro = housekeeping_packet.hk_lfr_time_not_synchro; | |
923 | new_hk_lfr_le.time_timecode_ctr = housekeeping_packet.hk_lfr_time_timecode_ctr; |
|
931 | new_hk_lfr_le.time_timecode_ctr = housekeeping_packet.hk_lfr_time_timecode_ctr; | |
924 | //AHB |
|
932 | //AHB | |
925 | new_hk_lfr_le.ahb_correctable = housekeeping_packet.hk_lfr_ahb_correctable; |
|
933 | new_hk_lfr_le.ahb_correctable = housekeeping_packet.hk_lfr_ahb_correctable; | |
926 | // housekeeping_packet.hk_lfr_dpu_spw_rx_ahb => not handled by the grspw driver |
|
934 | // housekeeping_packet.hk_lfr_dpu_spw_rx_ahb => not handled by the grspw driver | |
927 | // housekeeping_packet.hk_lfr_dpu_spw_tx_ahb => not handled by the grspw driver |
|
935 | // housekeeping_packet.hk_lfr_dpu_spw_tx_ahb => not handled by the grspw driver | |
928 |
|
936 | |||
929 | // update the le counter |
|
937 | // update the le counter | |
930 | // DPU |
|
938 | // DPU | |
931 | increment_hk_counter( new_hk_lfr_le.dpu_spw_parity, old_hk_lfr_le.dpu_spw_parity, &counter ); |
|
939 | increment_hk_counter( new_hk_lfr_le.dpu_spw_parity, old_hk_lfr_le.dpu_spw_parity, &counter ); | |
932 | increment_hk_counter( new_hk_lfr_le.dpu_spw_disconnect,old_hk_lfr_le.dpu_spw_disconnect, &counter ); |
|
940 | increment_hk_counter( new_hk_lfr_le.dpu_spw_disconnect,old_hk_lfr_le.dpu_spw_disconnect, &counter ); | |
933 | increment_hk_counter( new_hk_lfr_le.dpu_spw_escape, old_hk_lfr_le.dpu_spw_escape, &counter ); |
|
941 | increment_hk_counter( new_hk_lfr_le.dpu_spw_escape, old_hk_lfr_le.dpu_spw_escape, &counter ); | |
934 | increment_hk_counter( new_hk_lfr_le.dpu_spw_credit, old_hk_lfr_le.dpu_spw_credit, &counter ); |
|
942 | increment_hk_counter( new_hk_lfr_le.dpu_spw_credit, old_hk_lfr_le.dpu_spw_credit, &counter ); | |
935 | increment_hk_counter( new_hk_lfr_le.dpu_spw_write_sync,old_hk_lfr_le.dpu_spw_write_sync, &counter ); |
|
943 | increment_hk_counter( new_hk_lfr_le.dpu_spw_write_sync,old_hk_lfr_le.dpu_spw_write_sync, &counter ); | |
936 | // TIMECODE |
|
944 | // TIMECODE | |
937 | increment_hk_counter( new_hk_lfr_le.timecode_erroneous,old_hk_lfr_le.timecode_erroneous, &counter ); |
|
945 | increment_hk_counter( new_hk_lfr_le.timecode_erroneous,old_hk_lfr_le.timecode_erroneous, &counter ); | |
938 | increment_hk_counter( new_hk_lfr_le.timecode_missing, old_hk_lfr_le.timecode_missing, &counter ); |
|
946 | increment_hk_counter( new_hk_lfr_le.timecode_missing, old_hk_lfr_le.timecode_missing, &counter ); | |
939 | increment_hk_counter( new_hk_lfr_le.timecode_invalid, old_hk_lfr_le.timecode_invalid, &counter ); |
|
947 | increment_hk_counter( new_hk_lfr_le.timecode_invalid, old_hk_lfr_le.timecode_invalid, &counter ); | |
940 | // TIME |
|
948 | // TIME | |
941 | increment_hk_counter( new_hk_lfr_le.time_timecode_it, old_hk_lfr_le.time_timecode_it, &counter ); |
|
949 | increment_hk_counter( new_hk_lfr_le.time_timecode_it, old_hk_lfr_le.time_timecode_it, &counter ); | |
942 | increment_hk_counter( new_hk_lfr_le.time_not_synchro, old_hk_lfr_le.time_not_synchro, &counter ); |
|
950 | increment_hk_counter( new_hk_lfr_le.time_not_synchro, old_hk_lfr_le.time_not_synchro, &counter ); | |
943 | increment_hk_counter( new_hk_lfr_le.time_timecode_ctr, old_hk_lfr_le.time_timecode_ctr, &counter ); |
|
951 | increment_hk_counter( new_hk_lfr_le.time_timecode_ctr, old_hk_lfr_le.time_timecode_ctr, &counter ); | |
944 | // AHB |
|
952 | // AHB | |
945 | increment_hk_counter( new_hk_lfr_le.ahb_correctable, old_hk_lfr_le.ahb_correctable, &counter ); |
|
953 | increment_hk_counter( new_hk_lfr_le.ahb_correctable, old_hk_lfr_le.ahb_correctable, &counter ); | |
946 |
|
954 | |||
947 | // DPU |
|
955 | // DPU | |
948 | old_hk_lfr_le.dpu_spw_parity = new_hk_lfr_le.dpu_spw_parity; |
|
956 | old_hk_lfr_le.dpu_spw_parity = new_hk_lfr_le.dpu_spw_parity; | |
949 | old_hk_lfr_le.dpu_spw_disconnect= new_hk_lfr_le.dpu_spw_disconnect; |
|
957 | old_hk_lfr_le.dpu_spw_disconnect= new_hk_lfr_le.dpu_spw_disconnect; | |
950 | old_hk_lfr_le.dpu_spw_escape = new_hk_lfr_le.dpu_spw_escape; |
|
958 | old_hk_lfr_le.dpu_spw_escape = new_hk_lfr_le.dpu_spw_escape; | |
951 | old_hk_lfr_le.dpu_spw_credit = new_hk_lfr_le.dpu_spw_credit; |
|
959 | old_hk_lfr_le.dpu_spw_credit = new_hk_lfr_le.dpu_spw_credit; | |
952 | old_hk_lfr_le.dpu_spw_write_sync= new_hk_lfr_le.dpu_spw_write_sync; |
|
960 | old_hk_lfr_le.dpu_spw_write_sync= new_hk_lfr_le.dpu_spw_write_sync; | |
953 | // TIMECODE |
|
961 | // TIMECODE | |
954 | old_hk_lfr_le.timecode_erroneous= new_hk_lfr_le.timecode_erroneous; |
|
962 | old_hk_lfr_le.timecode_erroneous= new_hk_lfr_le.timecode_erroneous; | |
955 | old_hk_lfr_le.timecode_missing = new_hk_lfr_le.timecode_missing; |
|
963 | old_hk_lfr_le.timecode_missing = new_hk_lfr_le.timecode_missing; | |
956 | old_hk_lfr_le.timecode_invalid = new_hk_lfr_le.timecode_invalid; |
|
964 | old_hk_lfr_le.timecode_invalid = new_hk_lfr_le.timecode_invalid; | |
957 | // TIME |
|
965 | // TIME | |
958 | old_hk_lfr_le.time_timecode_it = new_hk_lfr_le.time_timecode_it; |
|
966 | old_hk_lfr_le.time_timecode_it = new_hk_lfr_le.time_timecode_it; | |
959 | old_hk_lfr_le.time_not_synchro = new_hk_lfr_le.time_not_synchro; |
|
967 | old_hk_lfr_le.time_not_synchro = new_hk_lfr_le.time_not_synchro; | |
960 | old_hk_lfr_le.time_timecode_ctr = new_hk_lfr_le.time_timecode_ctr; |
|
968 | old_hk_lfr_le.time_timecode_ctr = new_hk_lfr_le.time_timecode_ctr; | |
961 | //AHB |
|
969 | //AHB | |
962 | old_hk_lfr_le.ahb_correctable = new_hk_lfr_le.ahb_correctable; |
|
970 | old_hk_lfr_le.ahb_correctable = new_hk_lfr_le.ahb_correctable; | |
963 | // housekeeping_packet.hk_lfr_dpu_spw_rx_ahb => not handled by the grspw driver |
|
971 | // housekeeping_packet.hk_lfr_dpu_spw_rx_ahb => not handled by the grspw driver | |
964 | // housekeeping_packet.hk_lfr_dpu_spw_tx_ahb => not handled by the grspw driver |
|
972 | // housekeeping_packet.hk_lfr_dpu_spw_tx_ahb => not handled by the grspw driver | |
965 |
|
973 | |||
966 | // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers |
|
974 | // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers | |
967 | // LE |
|
975 | // LE | |
968 | housekeeping_packet.hk_lfr_le_cnt[0] = (unsigned char) ((counter & BYTE0_MASK) >> SHIFT_1_BYTE); |
|
976 | housekeeping_packet.hk_lfr_le_cnt[0] = (unsigned char) ((counter & BYTE0_MASK) >> SHIFT_1_BYTE); | |
969 | housekeeping_packet.hk_lfr_le_cnt[1] = (unsigned char) (counter & BYTE1_MASK); |
|
977 | housekeeping_packet.hk_lfr_le_cnt[1] = (unsigned char) (counter & BYTE1_MASK); | |
970 | } |
|
978 | } | |
971 |
|
979 | |||
972 | void hk_lfr_me_update( void ) |
|
980 | void hk_lfr_me_update( void ) | |
973 | { |
|
981 | { | |
974 | static hk_lfr_me_t old_hk_lfr_me = {0}; |
|
982 | static hk_lfr_me_t old_hk_lfr_me = {0}; | |
975 | hk_lfr_me_t new_hk_lfr_me; |
|
983 | hk_lfr_me_t new_hk_lfr_me; | |
976 | unsigned int counter; |
|
984 | unsigned int counter; | |
977 |
|
985 | |||
978 | counter = (((unsigned int) housekeeping_packet.hk_lfr_me_cnt[0]) * CONST_256) + housekeeping_packet.hk_lfr_me_cnt[1]; |
|
986 | counter = (((unsigned int) housekeeping_packet.hk_lfr_me_cnt[0]) * CONST_256) + housekeeping_packet.hk_lfr_me_cnt[1]; | |
979 |
|
987 | |||
980 | // get the current values |
|
988 | // get the current values | |
981 | new_hk_lfr_me.dpu_spw_early_eop = housekeeping_packet.hk_lfr_dpu_spw_early_eop; |
|
989 | new_hk_lfr_me.dpu_spw_early_eop = housekeeping_packet.hk_lfr_dpu_spw_early_eop; | |
982 | new_hk_lfr_me.dpu_spw_invalid_addr = housekeeping_packet.hk_lfr_dpu_spw_invalid_addr; |
|
990 | new_hk_lfr_me.dpu_spw_invalid_addr = housekeeping_packet.hk_lfr_dpu_spw_invalid_addr; | |
983 | new_hk_lfr_me.dpu_spw_eep = housekeeping_packet.hk_lfr_dpu_spw_eep; |
|
991 | new_hk_lfr_me.dpu_spw_eep = housekeeping_packet.hk_lfr_dpu_spw_eep; | |
984 | new_hk_lfr_me.dpu_spw_rx_too_big = housekeeping_packet.hk_lfr_dpu_spw_rx_too_big; |
|
992 | new_hk_lfr_me.dpu_spw_rx_too_big = housekeeping_packet.hk_lfr_dpu_spw_rx_too_big; | |
985 |
|
993 | |||
986 | // update the me counter |
|
994 | // update the me counter | |
987 | increment_hk_counter( new_hk_lfr_me.dpu_spw_early_eop, old_hk_lfr_me.dpu_spw_early_eop, &counter ); |
|
995 | increment_hk_counter( new_hk_lfr_me.dpu_spw_early_eop, old_hk_lfr_me.dpu_spw_early_eop, &counter ); | |
988 | increment_hk_counter( new_hk_lfr_me.dpu_spw_invalid_addr, old_hk_lfr_me.dpu_spw_invalid_addr, &counter ); |
|
996 | increment_hk_counter( new_hk_lfr_me.dpu_spw_invalid_addr, old_hk_lfr_me.dpu_spw_invalid_addr, &counter ); | |
989 | increment_hk_counter( new_hk_lfr_me.dpu_spw_eep, old_hk_lfr_me.dpu_spw_eep, &counter ); |
|
997 | increment_hk_counter( new_hk_lfr_me.dpu_spw_eep, old_hk_lfr_me.dpu_spw_eep, &counter ); | |
990 | increment_hk_counter( new_hk_lfr_me.dpu_spw_rx_too_big, old_hk_lfr_me.dpu_spw_rx_too_big, &counter ); |
|
998 | increment_hk_counter( new_hk_lfr_me.dpu_spw_rx_too_big, old_hk_lfr_me.dpu_spw_rx_too_big, &counter ); | |
991 |
|
999 | |||
992 | // store the counters for the next time |
|
1000 | // store the counters for the next time | |
993 | old_hk_lfr_me.dpu_spw_early_eop = new_hk_lfr_me.dpu_spw_early_eop; |
|
1001 | old_hk_lfr_me.dpu_spw_early_eop = new_hk_lfr_me.dpu_spw_early_eop; | |
994 | old_hk_lfr_me.dpu_spw_invalid_addr = new_hk_lfr_me.dpu_spw_invalid_addr; |
|
1002 | old_hk_lfr_me.dpu_spw_invalid_addr = new_hk_lfr_me.dpu_spw_invalid_addr; | |
995 | old_hk_lfr_me.dpu_spw_eep = new_hk_lfr_me.dpu_spw_eep; |
|
1003 | old_hk_lfr_me.dpu_spw_eep = new_hk_lfr_me.dpu_spw_eep; | |
996 | old_hk_lfr_me.dpu_spw_rx_too_big = new_hk_lfr_me.dpu_spw_rx_too_big; |
|
1004 | old_hk_lfr_me.dpu_spw_rx_too_big = new_hk_lfr_me.dpu_spw_rx_too_big; | |
997 |
|
1005 | |||
998 | // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers |
|
1006 | // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers | |
999 | // ME |
|
1007 | // ME | |
1000 | housekeeping_packet.hk_lfr_me_cnt[0] = (unsigned char) ((counter & BYTE0_MASK) >> SHIFT_1_BYTE); |
|
1008 | housekeeping_packet.hk_lfr_me_cnt[0] = (unsigned char) ((counter & BYTE0_MASK) >> SHIFT_1_BYTE); | |
1001 | housekeeping_packet.hk_lfr_me_cnt[1] = (unsigned char) (counter & BYTE1_MASK); |
|
1009 | housekeeping_packet.hk_lfr_me_cnt[1] = (unsigned char) (counter & BYTE1_MASK); | |
1002 | } |
|
1010 | } | |
1003 |
|
1011 | |||
1004 | void hk_lfr_le_me_he_update() |
|
1012 | void hk_lfr_le_me_he_update() | |
1005 | { |
|
1013 | { | |
1006 |
|
1014 | |||
1007 | unsigned int hk_lfr_he_cnt; |
|
1015 | unsigned int hk_lfr_he_cnt; | |
1008 |
|
1016 | |||
1009 | hk_lfr_he_cnt = (((unsigned int) housekeeping_packet.hk_lfr_he_cnt[0]) * 256) + housekeeping_packet.hk_lfr_he_cnt[1]; |
|
1017 | hk_lfr_he_cnt = (((unsigned int) housekeeping_packet.hk_lfr_he_cnt[0]) * 256) + housekeeping_packet.hk_lfr_he_cnt[1]; | |
1010 |
|
1018 | |||
1011 | //update the low severity error counter |
|
1019 | //update the low severity error counter | |
1012 | hk_lfr_le_update( ); |
|
1020 | hk_lfr_le_update( ); | |
1013 |
|
1021 | |||
1014 | //update the medium severity error counter |
|
1022 | //update the medium severity error counter | |
1015 | hk_lfr_me_update(); |
|
1023 | hk_lfr_me_update(); | |
1016 |
|
1024 | |||
1017 | //update the high severity error counter |
|
1025 | //update the high severity error counter | |
1018 | hk_lfr_he_cnt = 0; |
|
1026 | hk_lfr_he_cnt = 0; | |
1019 |
|
1027 | |||
1020 | // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers |
|
1028 | // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers | |
1021 | // HE |
|
1029 | // HE | |
1022 | housekeeping_packet.hk_lfr_he_cnt[0] = (unsigned char) ((hk_lfr_he_cnt & BYTE0_MASK) >> SHIFT_1_BYTE); |
|
1030 | housekeeping_packet.hk_lfr_he_cnt[0] = (unsigned char) ((hk_lfr_he_cnt & BYTE0_MASK) >> SHIFT_1_BYTE); | |
1023 | housekeeping_packet.hk_lfr_he_cnt[1] = (unsigned char) (hk_lfr_he_cnt & BYTE1_MASK); |
|
1031 | housekeeping_packet.hk_lfr_he_cnt[1] = (unsigned char) (hk_lfr_he_cnt & BYTE1_MASK); | |
1024 |
|
1032 | |||
1025 | } |
|
1033 | } | |
1026 |
|
1034 | |||
1027 | void set_hk_lfr_time_not_synchro() |
|
1035 | void set_hk_lfr_time_not_synchro() | |
1028 | { |
|
1036 | { | |
1029 | static unsigned char synchroLost = 1; |
|
1037 | static unsigned char synchroLost = 1; | |
1030 | int synchronizationBit; |
|
1038 | int synchronizationBit; | |
1031 |
|
1039 | |||
1032 | // get the synchronization bit |
|
1040 | // get the synchronization bit | |
1033 | synchronizationBit = |
|
1041 | synchronizationBit = | |
1034 | (time_management_regs->coarse_time & VAL_LFR_SYNCHRONIZED) >> BIT_SYNCHRONIZATION; // 1000 0000 0000 0000 |
|
1042 | (time_management_regs->coarse_time & VAL_LFR_SYNCHRONIZED) >> BIT_SYNCHRONIZATION; // 1000 0000 0000 0000 | |
1035 |
|
1043 | |||
1036 | switch (synchronizationBit) |
|
1044 | switch (synchronizationBit) | |
1037 | { |
|
1045 | { | |
1038 | case 0: |
|
1046 | case 0: | |
1039 | if (synchroLost == 1) |
|
1047 | if (synchroLost == 1) | |
1040 | { |
|
1048 | { | |
1041 | synchroLost = 0; |
|
1049 | synchroLost = 0; | |
1042 | } |
|
1050 | } | |
1043 | break; |
|
1051 | break; | |
1044 | case 1: |
|
1052 | case 1: | |
1045 | if (synchroLost == 0 ) |
|
1053 | if (synchroLost == 0 ) | |
1046 | { |
|
1054 | { | |
1047 | synchroLost = 1; |
|
1055 | synchroLost = 1; | |
1048 | increase_unsigned_char_counter(&housekeeping_packet.hk_lfr_time_not_synchro); |
|
1056 | increase_unsigned_char_counter(&housekeeping_packet.hk_lfr_time_not_synchro); | |
1049 | update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_NOT_SYNCHRO ); |
|
1057 | update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_NOT_SYNCHRO ); | |
1050 | } |
|
1058 | } | |
1051 | break; |
|
1059 | break; | |
1052 | default: |
|
1060 | default: | |
1053 | PRINTF1("in hk_lfr_time_not_synchro *** unexpected value for synchronizationBit = %d\n", synchronizationBit); |
|
1061 | PRINTF1("in hk_lfr_time_not_synchro *** unexpected value for synchronizationBit = %d\n", synchronizationBit); | |
1054 | break; |
|
1062 | break; | |
1055 | } |
|
1063 | } | |
1056 |
|
1064 | |||
1057 | } |
|
1065 | } | |
1058 |
|
1066 | |||
1059 | void set_hk_lfr_ahb_correctable() // CRITICITY L |
|
1067 | void set_hk_lfr_ahb_correctable() // CRITICITY L | |
1060 | { |
|
1068 | { | |
1061 | /** This function builds the error counter hk_lfr_ahb_correctable using the statistics provided |
|
1069 | /** This function builds the error counter hk_lfr_ahb_correctable using the statistics provided | |
1062 | * by the Cache Control Register (ASI 2, offset 0) and in the Register Protection Control Register (ASR16) on the |
|
1070 | * by the Cache Control Register (ASI 2, offset 0) and in the Register Protection Control Register (ASR16) on the | |
1063 | * detected errors in the cache, in the integer unit and in the floating point unit. |
|
1071 | * detected errors in the cache, in the integer unit and in the floating point unit. | |
1064 | * |
|
1072 | * | |
1065 | * @param void |
|
1073 | * @param void | |
1066 | * |
|
1074 | * | |
1067 | * @return void |
|
1075 | * @return void | |
1068 | * |
|
1076 | * | |
1069 | * All errors are summed to set the value of the hk_lfr_ahb_correctable counter. |
|
1077 | * All errors are summed to set the value of the hk_lfr_ahb_correctable counter. | |
1070 | * |
|
1078 | * | |
1071 | */ |
|
1079 | */ | |
1072 |
|
1080 | |||
1073 | unsigned int ahb_correctable; |
|
1081 | unsigned int ahb_correctable; | |
1074 | unsigned int instructionErrorCounter; |
|
1082 | unsigned int instructionErrorCounter; | |
1075 | unsigned int dataErrorCounter; |
|
1083 | unsigned int dataErrorCounter; | |
1076 | unsigned int fprfErrorCounter; |
|
1084 | unsigned int fprfErrorCounter; | |
1077 | unsigned int iurfErrorCounter; |
|
1085 | unsigned int iurfErrorCounter; | |
1078 |
|
1086 | |||
1079 | instructionErrorCounter = 0; |
|
1087 | instructionErrorCounter = 0; | |
1080 | dataErrorCounter = 0; |
|
1088 | dataErrorCounter = 0; | |
1081 | fprfErrorCounter = 0; |
|
1089 | fprfErrorCounter = 0; | |
1082 | iurfErrorCounter = 0; |
|
1090 | iurfErrorCounter = 0; | |
1083 |
|
1091 | |||
1084 | CCR_getInstructionAndDataErrorCounters( &instructionErrorCounter, &dataErrorCounter); |
|
1092 | CCR_getInstructionAndDataErrorCounters( &instructionErrorCounter, &dataErrorCounter); | |
1085 | ASR16_get_FPRF_IURF_ErrorCounters( &fprfErrorCounter, &iurfErrorCounter); |
|
1093 | ASR16_get_FPRF_IURF_ErrorCounters( &fprfErrorCounter, &iurfErrorCounter); | |
1086 |
|
1094 | |||
1087 | ahb_correctable = instructionErrorCounter |
|
1095 | ahb_correctable = instructionErrorCounter | |
1088 | + dataErrorCounter |
|
1096 | + dataErrorCounter | |
1089 | + fprfErrorCounter |
|
1097 | + fprfErrorCounter | |
1090 | + iurfErrorCounter |
|
1098 | + iurfErrorCounter | |
1091 | + housekeeping_packet.hk_lfr_ahb_correctable; |
|
1099 | + housekeeping_packet.hk_lfr_ahb_correctable; | |
1092 |
|
1100 | |||
1093 | housekeeping_packet.hk_lfr_ahb_correctable = (unsigned char) (ahb_correctable & INT8_ALL_F); // [1111 1111] |
|
1101 | housekeeping_packet.hk_lfr_ahb_correctable = (unsigned char) (ahb_correctable & INT8_ALL_F); // [1111 1111] | |
1094 |
|
1102 | |||
1095 | } |
|
1103 | } |
@@ -1,118 +1,94 | |||||
1 | /* |
|
1 | /* | |
2 | * CPU Usage Reporter |
|
2 | * CPU Usage Reporter | |
3 | * |
|
3 | * | |
4 | * COPYRIGHT (c) 1989-2009 |
|
4 | * COPYRIGHT (c) 1989-2009 | |
5 | * On-Line Applications Research Corporation (OAR). |
|
5 | * On-Line Applications Research Corporation (OAR). | |
6 | * |
|
6 | * | |
7 | * The license and distribution terms for this file may be |
|
7 | * The license and distribution terms for this file may be | |
8 | * found in the file LICENSE in this distribution or at |
|
8 | * found in the file LICENSE in this distribution or at | |
9 | * http://www.rtems.com/license/LICENSE. |
|
9 | * http://www.rtems.com/license/LICENSE. | |
10 | * |
|
10 | * | |
11 | * $Id$ |
|
11 | * $Id$ | |
12 | */ |
|
12 | */ | |
13 |
|
13 | |||
14 | #include "lfr_cpu_usage_report.h" |
|
14 | #include "lfr_cpu_usage_report.h" | |
|
15 | #include "fsw_params.h" | |||
|
16 | ||||
|
17 | extern rtems_id Task_id[]; | |||
15 |
|
18 | |||
16 | unsigned char lfr_rtems_cpu_usage_report( void ) |
|
19 | unsigned char lfr_rtems_cpu_usage_report( void ) | |
17 | { |
|
20 | { | |
18 | uint32_t api_index; |
|
21 | uint32_t api_index; | |
|
22 | uint32_t information_index; | |||
19 | Thread_Control *the_thread; |
|
23 | Thread_Control *the_thread; | |
20 | Objects_Information *information; |
|
24 | Objects_Information *information; | |
21 | uint32_t ival; |
|
25 | uint32_t ival; | |
22 | uint32_t fval; |
|
26 | uint32_t fval; | |
23 | #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__ |
|
27 | #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__ | |
24 | Timestamp_Control uptime; |
|
28 | Timestamp_Control uptime; | |
25 | Timestamp_Control total; |
|
29 | Timestamp_Control total; | |
26 | Timestamp_Control ran; |
|
30 | Timestamp_Control ran; | |
|
31 | Timestamp_Control abs_total; | |||
|
32 | Timestamp_Control abs_ran; | |||
|
33 | ||||
|
34 | static Timestamp_Control last_total={0,0}; | |||
|
35 | static Timestamp_Control last_ran={0,0}; | |||
27 | #else |
|
36 | #else | |
28 | uint32_t total_units = 0; |
|
37 | #error "Can't compute CPU usage using ticks on LFR" | |
29 | #endif |
|
38 | #endif | |
30 |
|
39 | |||
31 | unsigned char cpu_load; |
|
40 | unsigned char cpu_load; | |
32 |
|
41 | |||
33 | ival = 0; |
|
42 | ival = 0; | |
34 | cpu_load = 0; |
|
43 | cpu_load = 0; | |
35 |
|
44 | |||
36 | /* |
|
|||
37 | * When not using nanosecond CPU usage resolution, we have to count |
|
|||
38 | * the number of "ticks" we gave credit for to give the user a rough |
|
|||
39 | * guideline as to what each number means proportionally. |
|
|||
40 | */ |
|
|||
41 | #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__ |
|
|||
42 | _TOD_Get_uptime( &uptime ); |
|
45 | _TOD_Get_uptime( &uptime ); | |
43 | _Timestamp_Subtract( &CPU_usage_Uptime_at_last_reset, &uptime, &total ); |
|
46 | _Timestamp_Subtract( &CPU_usage_Uptime_at_last_reset, &uptime, &abs_total ); | |
44 | #else |
|
|||
45 | for ( api_index = 1 ; api_index <= OBJECTS_APIS_LAST ; api_index++ ) { |
|
|||
46 | if ( !_Objects_Information_table[ api_index ] ) { } |
|
|||
47 | else |
|
|||
48 | { |
|
|||
49 | information = _Objects_Information_table[ api_index ][ 1 ]; |
|
|||
50 | if ( information != NULL ) |
|
|||
51 | { |
|
|||
52 | for ( i=1 ; i <= information->maximum ; i++ ) { |
|
|||
53 | the_thread = (Thread_Control *)information->local_table[ i ]; |
|
|||
54 |
|
||||
55 | if ( the_thread != NULL ) { |
|
|||
56 | total_units += the_thread->cpu_time_used; } |
|
|||
57 | } |
|
|||
58 | } |
|
|||
59 | } |
|
|||
60 | } |
|
|||
61 | #endif |
|
|||
62 |
|
||||
63 | for ( api_index = 1 ; api_index <= OBJECTS_APIS_LAST ; api_index++ ) |
|
47 | for ( api_index = 1 ; api_index <= OBJECTS_APIS_LAST ; api_index++ ) | |
64 | { |
|
48 | { | |
65 | if ( !_Objects_Information_table[ api_index ] ) { } |
|
49 | if ( !_Objects_Information_table[ api_index ] ) { } | |
66 | else |
|
50 | else | |
67 | { |
|
51 | { | |
68 | information = _Objects_Information_table[ api_index ][ 1 ]; |
|
52 | information = _Objects_Information_table[ api_index ][ 1 ]; | |
69 | if ( information != NULL ) |
|
53 | if ( information != NULL ) | |
70 | { |
|
54 | { | |
71 | the_thread = (Thread_Control *)information->local_table[ 1 ]; |
|
55 | for(information_index=1;information_index<=information->maximum;information_index++) | |
|
56 | { | |||
|
57 | the_thread = (Thread_Control *)information->local_table[ information_index ]; | |||
72 |
|
58 | |||
73 |
if ( the_thread == NULL |
|
59 | if ( the_thread == NULL) { } | |
74 | else |
|
60 | else if(the_thread->Object.id == Task_id[TASKID_SCRB]) // Only measure scrubbing task load, CPU load is 100%-Scrubbing | |
75 | { |
|
61 | { | |
76 | #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__ |
|
|||
77 | /* |
|
62 | /* | |
78 | * If this is the currently executing thread, account for time |
|
63 | * If this is the currently executing thread, account for time | |
79 | * since the last context switch. |
|
64 | * since the last context switch. | |
80 | */ |
|
65 | */ | |
81 | ran = the_thread->cpu_time_used; |
|
66 | abs_ran = the_thread->cpu_time_used; | |
82 | if ( _Thread_Executing->Object.id == the_thread->Object.id ) |
|
67 | if ( _Thread_Executing->Object.id == the_thread->Object.id ) | |
83 | { |
|
68 | { | |
84 | Timestamp_Control used; |
|
69 | Timestamp_Control used; | |
85 | _Timestamp_Subtract( |
|
70 | _Timestamp_Subtract( | |
86 | &_Thread_Time_of_last_context_switch, &uptime, &used |
|
71 | &_Thread_Time_of_last_context_switch, &uptime, &used | |
87 | ); |
|
72 | ); | |
88 | _Timestamp_Add_to( &ran, &used ); |
|
73 | _Timestamp_Add_to( &abs_ran, &used ); | |
89 | } |
|
74 | } | |
90 | _Timestamp_Divide( &ran, &total, &ival, &fval ); |
|
75 | /* | |
91 |
|
76 | * Only consider the time since last call | ||
92 | #else |
|
77 | */ | |
93 | if (total_units != 0) |
|
78 | _Timespec_Subtract(&last_ran, &abs_ran, &ran); | |
94 | { |
|
79 | _Timespec_Subtract(&last_total, &abs_total, &total); | |
95 | uint64_t ival_64; |
|
|||
96 |
|
80 | |||
97 |
|
|
81 | last_ran = abs_ran; | |
98 |
|
|
82 | last_total = abs_total; | |
99 | ival = ival_64 / total_units; |
|
|||
100 | } |
|
|||
101 | else |
|
|||
102 | { |
|
|||
103 | ival = 0; |
|
|||
104 | } |
|
|||
105 |
|
83 | |||
106 | fval = ival % CONST_1000; |
|
84 | _Timestamp_Divide( &ran, &total, &ival, &fval); | |
107 |
|
|
85 | cpu_load = (unsigned char)(CONST_100 - ival); | |
108 | #endif |
|
|||
109 | } |
|
86 | } | |
110 | } |
|
87 | } | |
111 | } |
|
88 | } | |
112 | } |
|
89 | } | |
113 | cpu_load = (unsigned char) (CONST_100 - ival); |
|
90 | } | |
114 |
|
||||
115 | return cpu_load; |
|
91 | return cpu_load; | |
116 | } |
|
92 | } | |
117 |
|
93 | |||
118 |
|
94 |
General Comments 0
You need to be logged in to leave comments.
Login now