##// END OF EJS Templates
Bug 657 HK_LFR_xE_CNT doesn't manage the wrap of 8bits counter error
paul -
r336:571c142ee2b3 R3_plus draft
parent child
Show More
@@ -1,988 +1,988
1 /** General usage functions and RTEMS tasks.
1 /** General usage functions and RTEMS tasks.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 */
6 */
7
7
8 #include "fsw_misc.h"
8 #include "fsw_misc.h"
9
9
10 void timer_configure(unsigned char timer, unsigned int clock_divider,
10 void timer_configure(unsigned char timer, unsigned int clock_divider,
11 unsigned char interrupt_level, rtems_isr (*timer_isr)() )
11 unsigned char interrupt_level, rtems_isr (*timer_isr)() )
12 {
12 {
13 /** This function configures a GPTIMER timer instantiated in the VHDL design.
13 /** This function configures a GPTIMER timer instantiated in the VHDL design.
14 *
14 *
15 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
15 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
16 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
16 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
17 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
17 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
18 * @param interrupt_level is the interrupt level that the timer drives.
18 * @param interrupt_level is the interrupt level that the timer drives.
19 * @param timer_isr is the interrupt subroutine that will be attached to the IRQ driven by the timer.
19 * @param timer_isr is the interrupt subroutine that will be attached to the IRQ driven by the timer.
20 *
20 *
21 * Interrupt levels are described in the SPARC documentation sparcv8.pdf p.76
21 * Interrupt levels are described in the SPARC documentation sparcv8.pdf p.76
22 *
22 *
23 */
23 */
24
24
25 rtems_status_code status;
25 rtems_status_code status;
26 rtems_isr_entry old_isr_handler;
26 rtems_isr_entry old_isr_handler;
27
27
28 old_isr_handler = NULL;
28 old_isr_handler = NULL;
29
29
30 gptimer_regs->timer[timer].ctrl = INIT_CHAR; // reset the control register
30 gptimer_regs->timer[timer].ctrl = INIT_CHAR; // reset the control register
31
31
32 status = rtems_interrupt_catch( timer_isr, interrupt_level, &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels
32 status = rtems_interrupt_catch( timer_isr, interrupt_level, &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels
33 if (status!=RTEMS_SUCCESSFUL)
33 if (status!=RTEMS_SUCCESSFUL)
34 {
34 {
35 PRINTF("in configure_timer *** ERR rtems_interrupt_catch\n")
35 PRINTF("in configure_timer *** ERR rtems_interrupt_catch\n")
36 }
36 }
37
37
38 timer_set_clock_divider( timer, clock_divider);
38 timer_set_clock_divider( timer, clock_divider);
39 }
39 }
40
40
41 void timer_start(unsigned char timer)
41 void timer_start(unsigned char timer)
42 {
42 {
43 /** This function starts a GPTIMER timer.
43 /** This function starts a GPTIMER timer.
44 *
44 *
45 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
45 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
46 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
46 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
47 *
47 *
48 */
48 */
49
49
50 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_CLEAR_IRQ;
50 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_CLEAR_IRQ;
51 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_LD;
51 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_LD;
52 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_EN;
52 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_EN;
53 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_RS;
53 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_RS;
54 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_IE;
54 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_IE;
55 }
55 }
56
56
57 void timer_stop(unsigned char timer)
57 void timer_stop(unsigned char timer)
58 {
58 {
59 /** This function stops a GPTIMER timer.
59 /** This function stops a GPTIMER timer.
60 *
60 *
61 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
61 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
62 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
62 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
63 *
63 *
64 */
64 */
65
65
66 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & GPTIMER_EN_MASK;
66 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & GPTIMER_EN_MASK;
67 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & GPTIMER_IE_MASK;
67 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & GPTIMER_IE_MASK;
68 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_CLEAR_IRQ;
68 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_CLEAR_IRQ;
69 }
69 }
70
70
71 void timer_set_clock_divider(unsigned char timer, unsigned int clock_divider)
71 void timer_set_clock_divider(unsigned char timer, unsigned int clock_divider)
72 {
72 {
73 /** This function sets the clock divider of a GPTIMER timer.
73 /** This function sets the clock divider of a GPTIMER timer.
74 *
74 *
75 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
75 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
76 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
76 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
77 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
77 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
78 *
78 *
79 */
79 */
80
80
81 gptimer_regs->timer[timer].reload = clock_divider; // base clock frequency is 1 MHz
81 gptimer_regs->timer[timer].reload = clock_divider; // base clock frequency is 1 MHz
82 }
82 }
83
83
84 // WATCHDOG
84 // WATCHDOG
85
85
86 rtems_isr watchdog_isr( rtems_vector_number vector )
86 rtems_isr watchdog_isr( rtems_vector_number vector )
87 {
87 {
88 rtems_status_code status_code;
88 rtems_status_code status_code;
89
89
90 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_12 );
90 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_12 );
91
91
92 PRINTF("watchdog_isr *** this is the end, exit(0)\n");
92 PRINTF("watchdog_isr *** this is the end, exit(0)\n");
93
93
94 exit(0);
94 exit(0);
95 }
95 }
96
96
97 void watchdog_configure(void)
97 void watchdog_configure(void)
98 {
98 {
99 /** This function configure the watchdog.
99 /** This function configure the watchdog.
100 *
100 *
101 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
101 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
102 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
102 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
103 *
103 *
104 * The watchdog is a timer provided by the GPTIMER IP core of the GRLIB.
104 * The watchdog is a timer provided by the GPTIMER IP core of the GRLIB.
105 *
105 *
106 */
106 */
107
107
108 LEON_Mask_interrupt( IRQ_GPTIMER_WATCHDOG ); // mask gptimer/watchdog interrupt during configuration
108 LEON_Mask_interrupt( IRQ_GPTIMER_WATCHDOG ); // mask gptimer/watchdog interrupt during configuration
109
109
110 timer_configure( TIMER_WATCHDOG, CLKDIV_WATCHDOG, IRQ_SPARC_GPTIMER_WATCHDOG, watchdog_isr );
110 timer_configure( TIMER_WATCHDOG, CLKDIV_WATCHDOG, IRQ_SPARC_GPTIMER_WATCHDOG, watchdog_isr );
111
111
112 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG ); // clear gptimer/watchdog interrupt
112 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG ); // clear gptimer/watchdog interrupt
113 }
113 }
114
114
115 void watchdog_stop(void)
115 void watchdog_stop(void)
116 {
116 {
117 LEON_Mask_interrupt( IRQ_GPTIMER_WATCHDOG ); // mask gptimer/watchdog interrupt line
117 LEON_Mask_interrupt( IRQ_GPTIMER_WATCHDOG ); // mask gptimer/watchdog interrupt line
118 timer_stop( TIMER_WATCHDOG );
118 timer_stop( TIMER_WATCHDOG );
119 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG ); // clear gptimer/watchdog interrupt
119 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG ); // clear gptimer/watchdog interrupt
120 }
120 }
121
121
122 void watchdog_reload(void)
122 void watchdog_reload(void)
123 {
123 {
124 /** This function reloads the watchdog timer counter with the timer reload value.
124 /** This function reloads the watchdog timer counter with the timer reload value.
125 *
125 *
126 * @param void
126 * @param void
127 *
127 *
128 * @return void
128 * @return void
129 *
129 *
130 */
130 */
131
131
132 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_LD;
132 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_LD;
133 }
133 }
134
134
135 void watchdog_start(void)
135 void watchdog_start(void)
136 {
136 {
137 /** This function starts the watchdog timer.
137 /** This function starts the watchdog timer.
138 *
138 *
139 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
139 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
140 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
140 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
141 *
141 *
142 */
142 */
143
143
144 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG );
144 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG );
145
145
146 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_CLEAR_IRQ;
146 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_CLEAR_IRQ;
147 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_LD;
147 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_LD;
148 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_EN;
148 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_EN;
149 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_IE;
149 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_IE;
150
150
151 LEON_Unmask_interrupt( IRQ_GPTIMER_WATCHDOG );
151 LEON_Unmask_interrupt( IRQ_GPTIMER_WATCHDOG );
152
152
153 }
153 }
154
154
155 int enable_apbuart_transmitter( void ) // set the bit 1, TE Transmitter Enable to 1 in the APBUART control register
155 int enable_apbuart_transmitter( void ) // set the bit 1, TE Transmitter Enable to 1 in the APBUART control register
156 {
156 {
157 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART;
157 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART;
158
158
159 apbuart_regs->ctrl = APBUART_CTRL_REG_MASK_TE;
159 apbuart_regs->ctrl = APBUART_CTRL_REG_MASK_TE;
160
160
161 return 0;
161 return 0;
162 }
162 }
163
163
164 void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value)
164 void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value)
165 {
165 {
166 /** This function sets the scaler reload register of the apbuart module
166 /** This function sets the scaler reload register of the apbuart module
167 *
167 *
168 * @param regs is the address of the apbuart registers in memory
168 * @param regs is the address of the apbuart registers in memory
169 * @param value is the value that will be stored in the scaler register
169 * @param value is the value that will be stored in the scaler register
170 *
170 *
171 * The value shall be set by the software to get data on the serial interface.
171 * The value shall be set by the software to get data on the serial interface.
172 *
172 *
173 */
173 */
174
174
175 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) regs;
175 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) regs;
176
176
177 apbuart_regs->scaler = value;
177 apbuart_regs->scaler = value;
178
178
179 BOOT_PRINTF1("OK *** apbuart port scaler reload register set to 0x%x\n", value)
179 BOOT_PRINTF1("OK *** apbuart port scaler reload register set to 0x%x\n", value)
180 }
180 }
181
181
182 //************
182 //************
183 // RTEMS TASKS
183 // RTEMS TASKS
184
184
185 rtems_task load_task(rtems_task_argument argument)
185 rtems_task load_task(rtems_task_argument argument)
186 {
186 {
187 BOOT_PRINTF("in LOAD *** \n")
187 BOOT_PRINTF("in LOAD *** \n")
188
188
189 rtems_status_code status;
189 rtems_status_code status;
190 unsigned int i;
190 unsigned int i;
191 unsigned int j;
191 unsigned int j;
192 rtems_name name_watchdog_rate_monotonic; // name of the watchdog rate monotonic
192 rtems_name name_watchdog_rate_monotonic; // name of the watchdog rate monotonic
193 rtems_id watchdog_period_id; // id of the watchdog rate monotonic period
193 rtems_id watchdog_period_id; // id of the watchdog rate monotonic period
194
194
195 watchdog_period_id = RTEMS_ID_NONE;
195 watchdog_period_id = RTEMS_ID_NONE;
196
196
197 name_watchdog_rate_monotonic = rtems_build_name( 'L', 'O', 'A', 'D' );
197 name_watchdog_rate_monotonic = rtems_build_name( 'L', 'O', 'A', 'D' );
198
198
199 status = rtems_rate_monotonic_create( name_watchdog_rate_monotonic, &watchdog_period_id );
199 status = rtems_rate_monotonic_create( name_watchdog_rate_monotonic, &watchdog_period_id );
200 if( status != RTEMS_SUCCESSFUL ) {
200 if( status != RTEMS_SUCCESSFUL ) {
201 PRINTF1( "in LOAD *** rtems_rate_monotonic_create failed with status of %d\n", status )
201 PRINTF1( "in LOAD *** rtems_rate_monotonic_create failed with status of %d\n", status )
202 }
202 }
203
203
204 i = 0;
204 i = 0;
205 j = 0;
205 j = 0;
206
206
207 watchdog_configure();
207 watchdog_configure();
208
208
209 watchdog_start();
209 watchdog_start();
210
210
211 set_sy_lfr_watchdog_enabled( true );
211 set_sy_lfr_watchdog_enabled( true );
212
212
213 while(1){
213 while(1){
214 status = rtems_rate_monotonic_period( watchdog_period_id, WATCHDOG_PERIOD );
214 status = rtems_rate_monotonic_period( watchdog_period_id, WATCHDOG_PERIOD );
215 watchdog_reload();
215 watchdog_reload();
216 i = i + 1;
216 i = i + 1;
217 if ( i == WATCHDOG_LOOP_PRINTF )
217 if ( i == WATCHDOG_LOOP_PRINTF )
218 {
218 {
219 i = 0;
219 i = 0;
220 j = j + 1;
220 j = j + 1;
221 PRINTF1("%d\n", j)
221 PRINTF1("%d\n", j)
222 }
222 }
223 #ifdef DEBUG_WATCHDOG
223 #ifdef DEBUG_WATCHDOG
224 if (j == WATCHDOG_LOOP_DEBUG )
224 if (j == WATCHDOG_LOOP_DEBUG )
225 {
225 {
226 status = rtems_task_delete(RTEMS_SELF);
226 status = rtems_task_delete(RTEMS_SELF);
227 }
227 }
228 #endif
228 #endif
229 }
229 }
230 }
230 }
231
231
232 rtems_task hous_task(rtems_task_argument argument)
232 rtems_task hous_task(rtems_task_argument argument)
233 {
233 {
234 rtems_status_code status;
234 rtems_status_code status;
235 rtems_status_code spare_status;
235 rtems_status_code spare_status;
236 rtems_id queue_id;
236 rtems_id queue_id;
237 rtems_rate_monotonic_period_status period_status;
237 rtems_rate_monotonic_period_status period_status;
238 bool isSynchronized;
238 bool isSynchronized;
239
239
240 queue_id = RTEMS_ID_NONE;
240 queue_id = RTEMS_ID_NONE;
241 memset(&period_status, 0, sizeof(rtems_rate_monotonic_period_status));
241 memset(&period_status, 0, sizeof(rtems_rate_monotonic_period_status));
242 isSynchronized = false;
242 isSynchronized = false;
243
243
244 status = get_message_queue_id_send( &queue_id );
244 status = get_message_queue_id_send( &queue_id );
245 if (status != RTEMS_SUCCESSFUL)
245 if (status != RTEMS_SUCCESSFUL)
246 {
246 {
247 PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status)
247 PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status)
248 }
248 }
249
249
250 BOOT_PRINTF("in HOUS ***\n");
250 BOOT_PRINTF("in HOUS ***\n");
251
251
252 if (rtems_rate_monotonic_ident( name_hk_rate_monotonic, &HK_id) != RTEMS_SUCCESSFUL) {
252 if (rtems_rate_monotonic_ident( name_hk_rate_monotonic, &HK_id) != RTEMS_SUCCESSFUL) {
253 status = rtems_rate_monotonic_create( name_hk_rate_monotonic, &HK_id );
253 status = rtems_rate_monotonic_create( name_hk_rate_monotonic, &HK_id );
254 if( status != RTEMS_SUCCESSFUL ) {
254 if( status != RTEMS_SUCCESSFUL ) {
255 PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status );
255 PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status );
256 }
256 }
257 }
257 }
258
258
259 status = rtems_rate_monotonic_cancel(HK_id);
259 status = rtems_rate_monotonic_cancel(HK_id);
260 if( status != RTEMS_SUCCESSFUL ) {
260 if( status != RTEMS_SUCCESSFUL ) {
261 PRINTF1( "ERR *** in HOUS *** rtems_rate_monotonic_cancel(HK_id) ***code: %d\n", status );
261 PRINTF1( "ERR *** in HOUS *** rtems_rate_monotonic_cancel(HK_id) ***code: %d\n", status );
262 }
262 }
263 else {
263 else {
264 DEBUG_PRINTF("OK *** in HOUS *** rtems_rate_monotonic_cancel(HK_id)\n");
264 DEBUG_PRINTF("OK *** in HOUS *** rtems_rate_monotonic_cancel(HK_id)\n");
265 }
265 }
266
266
267 // startup phase
267 // startup phase
268 status = rtems_rate_monotonic_period( HK_id, SY_LFR_TIME_SYN_TIMEOUT_in_ticks );
268 status = rtems_rate_monotonic_period( HK_id, SY_LFR_TIME_SYN_TIMEOUT_in_ticks );
269 status = rtems_rate_monotonic_get_status( HK_id, &period_status );
269 status = rtems_rate_monotonic_get_status( HK_id, &period_status );
270 DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state)
270 DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state)
271 while( (period_status.state != RATE_MONOTONIC_EXPIRED)
271 while( (period_status.state != RATE_MONOTONIC_EXPIRED)
272 && (isSynchronized == false) ) // after SY_LFR_TIME_SYN_TIMEOUT ms, starts HK anyway
272 && (isSynchronized == false) ) // after SY_LFR_TIME_SYN_TIMEOUT ms, starts HK anyway
273 {
273 {
274 if ((time_management_regs->coarse_time & VAL_LFR_SYNCHRONIZED) == INT32_ALL_0) // check time synchronization
274 if ((time_management_regs->coarse_time & VAL_LFR_SYNCHRONIZED) == INT32_ALL_0) // check time synchronization
275 {
275 {
276 isSynchronized = true;
276 isSynchronized = true;
277 }
277 }
278 else
278 else
279 {
279 {
280 status = rtems_rate_monotonic_get_status( HK_id, &period_status );
280 status = rtems_rate_monotonic_get_status( HK_id, &period_status );
281
281
282 status = rtems_task_wake_after( HK_SYNC_WAIT ); // wait HK_SYNCH_WAIT 100 ms = 10 * 10 ms
282 status = rtems_task_wake_after( HK_SYNC_WAIT ); // wait HK_SYNCH_WAIT 100 ms = 10 * 10 ms
283 }
283 }
284 }
284 }
285 status = rtems_rate_monotonic_cancel(HK_id);
285 status = rtems_rate_monotonic_cancel(HK_id);
286 DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state)
286 DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state)
287
287
288 set_hk_lfr_reset_cause( POWER_ON );
288 set_hk_lfr_reset_cause( POWER_ON );
289
289
290 while(1){ // launch the rate monotonic task
290 while(1){ // launch the rate monotonic task
291 status = rtems_rate_monotonic_period( HK_id, HK_PERIOD );
291 status = rtems_rate_monotonic_period( HK_id, HK_PERIOD );
292 if ( status != RTEMS_SUCCESSFUL ) {
292 if ( status != RTEMS_SUCCESSFUL ) {
293 PRINTF1( "in HOUS *** ERR period: %d\n", status);
293 PRINTF1( "in HOUS *** ERR period: %d\n", status);
294 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_6 );
294 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_6 );
295 }
295 }
296 else {
296 else {
297 housekeeping_packet.packetSequenceControl[BYTE_0] = (unsigned char) (sequenceCounterHK >> SHIFT_1_BYTE);
297 housekeeping_packet.packetSequenceControl[BYTE_0] = (unsigned char) (sequenceCounterHK >> SHIFT_1_BYTE);
298 housekeeping_packet.packetSequenceControl[BYTE_1] = (unsigned char) (sequenceCounterHK );
298 housekeeping_packet.packetSequenceControl[BYTE_1] = (unsigned char) (sequenceCounterHK );
299 increment_seq_counter( &sequenceCounterHK );
299 increment_seq_counter( &sequenceCounterHK );
300
300
301 housekeeping_packet.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
301 housekeeping_packet.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
302 housekeeping_packet.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
302 housekeeping_packet.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
303 housekeeping_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
303 housekeeping_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
304 housekeeping_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
304 housekeeping_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
305 housekeeping_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
305 housekeeping_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
306 housekeeping_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
306 housekeeping_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
307
307
308 spacewire_update_hk_lfr_link_state( &housekeeping_packet.lfr_status_word[0] );
308 spacewire_update_hk_lfr_link_state( &housekeeping_packet.lfr_status_word[0] );
309
309
310 spacewire_read_statistics();
310 spacewire_read_statistics();
311
311
312 update_hk_with_grspw_stats();
312 update_hk_with_grspw_stats();
313
313
314 set_hk_lfr_time_not_synchro();
314 set_hk_lfr_time_not_synchro();
315
315
316 housekeeping_packet.hk_lfr_q_sd_fifo_size_max = hk_lfr_q_sd_fifo_size_max;
316 housekeeping_packet.hk_lfr_q_sd_fifo_size_max = hk_lfr_q_sd_fifo_size_max;
317 housekeeping_packet.hk_lfr_q_rv_fifo_size_max = hk_lfr_q_rv_fifo_size_max;
317 housekeeping_packet.hk_lfr_q_rv_fifo_size_max = hk_lfr_q_rv_fifo_size_max;
318 housekeeping_packet.hk_lfr_q_p0_fifo_size_max = hk_lfr_q_p0_fifo_size_max;
318 housekeeping_packet.hk_lfr_q_p0_fifo_size_max = hk_lfr_q_p0_fifo_size_max;
319 housekeeping_packet.hk_lfr_q_p1_fifo_size_max = hk_lfr_q_p1_fifo_size_max;
319 housekeeping_packet.hk_lfr_q_p1_fifo_size_max = hk_lfr_q_p1_fifo_size_max;
320 housekeeping_packet.hk_lfr_q_p2_fifo_size_max = hk_lfr_q_p2_fifo_size_max;
320 housekeeping_packet.hk_lfr_q_p2_fifo_size_max = hk_lfr_q_p2_fifo_size_max;
321
321
322 housekeeping_packet.sy_lfr_common_parameters_spare = parameter_dump_packet.sy_lfr_common_parameters_spare;
322 housekeeping_packet.sy_lfr_common_parameters_spare = parameter_dump_packet.sy_lfr_common_parameters_spare;
323 housekeeping_packet.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
323 housekeeping_packet.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
324 get_temperatures( housekeeping_packet.hk_lfr_temp_scm );
324 get_temperatures( housekeeping_packet.hk_lfr_temp_scm );
325 get_v_e1_e2_f3( housekeeping_packet.hk_lfr_sc_v_f3 );
325 get_v_e1_e2_f3( housekeeping_packet.hk_lfr_sc_v_f3 );
326 get_cpu_load( (unsigned char *) &housekeeping_packet.hk_lfr_cpu_load );
326 get_cpu_load( (unsigned char *) &housekeeping_packet.hk_lfr_cpu_load );
327
327
328 hk_lfr_le_me_he_update();
328 hk_lfr_le_me_he_update();
329
329
330 housekeeping_packet.hk_lfr_sc_rw_f_flags = cp_rpw_sc_rw_f_flags;
330 housekeeping_packet.hk_lfr_sc_rw_f_flags = cp_rpw_sc_rw_f_flags;
331
331
332 // SEND PACKET
332 // SEND PACKET
333 status = rtems_message_queue_send( queue_id, &housekeeping_packet,
333 status = rtems_message_queue_send( queue_id, &housekeeping_packet,
334 PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
334 PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
335 if (status != RTEMS_SUCCESSFUL) {
335 if (status != RTEMS_SUCCESSFUL) {
336 PRINTF1("in HOUS *** ERR send: %d\n", status)
336 PRINTF1("in HOUS *** ERR send: %d\n", status)
337 }
337 }
338 }
338 }
339 }
339 }
340
340
341 PRINTF("in HOUS *** deleting task\n")
341 PRINTF("in HOUS *** deleting task\n")
342
342
343 status = rtems_task_delete( RTEMS_SELF ); // should not return
343 status = rtems_task_delete( RTEMS_SELF ); // should not return
344
344
345 return;
345 return;
346 }
346 }
347
347
348 rtems_task avgv_task(rtems_task_argument argument)
348 rtems_task avgv_task(rtems_task_argument argument)
349 {
349 {
350 #define MOVING_AVERAGE 16
350 #define MOVING_AVERAGE 16
351 rtems_status_code status;
351 rtems_status_code status;
352 static unsigned int v[MOVING_AVERAGE] = {0};
352 static unsigned int v[MOVING_AVERAGE] = {0};
353 static unsigned int e1[MOVING_AVERAGE] = {0};
353 static unsigned int e1[MOVING_AVERAGE] = {0};
354 static unsigned int e2[MOVING_AVERAGE] = {0};
354 static unsigned int e2[MOVING_AVERAGE] = {0};
355 float average_v;
355 float average_v;
356 float average_e1;
356 float average_e1;
357 float average_e2;
357 float average_e2;
358 unsigned char k;
358 unsigned char k;
359 unsigned char indexOfOldValue;
359 unsigned char indexOfOldValue;
360
360
361 BOOT_PRINTF("in AVGV ***\n");
361 BOOT_PRINTF("in AVGV ***\n");
362
362
363 if (rtems_rate_monotonic_ident( name_avgv_rate_monotonic, &HK_id) != RTEMS_SUCCESSFUL) {
363 if (rtems_rate_monotonic_ident( name_avgv_rate_monotonic, &HK_id) != RTEMS_SUCCESSFUL) {
364 status = rtems_rate_monotonic_create( name_avgv_rate_monotonic, &AVGV_id );
364 status = rtems_rate_monotonic_create( name_avgv_rate_monotonic, &AVGV_id );
365 if( status != RTEMS_SUCCESSFUL ) {
365 if( status != RTEMS_SUCCESSFUL ) {
366 PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status );
366 PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status );
367 }
367 }
368 }
368 }
369
369
370 status = rtems_rate_monotonic_cancel(AVGV_id);
370 status = rtems_rate_monotonic_cancel(AVGV_id);
371 if( status != RTEMS_SUCCESSFUL ) {
371 if( status != RTEMS_SUCCESSFUL ) {
372 PRINTF1( "ERR *** in AVGV *** rtems_rate_monotonic_cancel(AVGV_id) ***code: %d\n", status );
372 PRINTF1( "ERR *** in AVGV *** rtems_rate_monotonic_cancel(AVGV_id) ***code: %d\n", status );
373 }
373 }
374 else {
374 else {
375 DEBUG_PRINTF("OK *** in AVGV *** rtems_rate_monotonic_cancel(AVGV_id)\n");
375 DEBUG_PRINTF("OK *** in AVGV *** rtems_rate_monotonic_cancel(AVGV_id)\n");
376 }
376 }
377
377
378 // initialize values
378 // initialize values
379 indexOfOldValue = MOVING_AVERAGE - 1;
379 indexOfOldValue = MOVING_AVERAGE - 1;
380 average_v = 0.;
380 average_v = 0.;
381 average_e1 = 0.;
381 average_e1 = 0.;
382 average_e2 = 0.;
382 average_e2 = 0.;
383
383
384 k = 0;
384 k = 0;
385
385
386 while(1){ // launch the rate monotonic task
386 while(1){ // launch the rate monotonic task
387 status = rtems_rate_monotonic_period( AVGV_id, AVGV_PERIOD );
387 status = rtems_rate_monotonic_period( AVGV_id, AVGV_PERIOD );
388 if ( status != RTEMS_SUCCESSFUL ) {
388 if ( status != RTEMS_SUCCESSFUL ) {
389 PRINTF1( "in AVGV *** ERR period: %d\n", status);
389 PRINTF1( "in AVGV *** ERR period: %d\n", status);
390 }
390 }
391 else {
391 else {
392 // store new value in buffer
392 // store new value in buffer
393 v[k] = waveform_picker_regs->v;
393 v[k] = waveform_picker_regs->v;
394 e1[k] = waveform_picker_regs->e1;
394 e1[k] = waveform_picker_regs->e1;
395 e2[k] = waveform_picker_regs->e2;
395 e2[k] = waveform_picker_regs->e2;
396 if (k == (MOVING_AVERAGE - 1))
396 if (k == (MOVING_AVERAGE - 1))
397 {
397 {
398 indexOfOldValue = 0;
398 indexOfOldValue = 0;
399 }
399 }
400 else
400 else
401 {
401 {
402 indexOfOldValue = k + 1;
402 indexOfOldValue = k + 1;
403 }
403 }
404 average_v = average_v + v[k] - v[indexOfOldValue];
404 average_v = average_v + v[k] - v[indexOfOldValue];
405 average_e1 = average_e1 + e1[k] - e1[indexOfOldValue];
405 average_e1 = average_e1 + e1[k] - e1[indexOfOldValue];
406 average_e2 = average_e2 + e2[k] - e2[indexOfOldValue];
406 average_e2 = average_e2 + e2[k] - e2[indexOfOldValue];
407 }
407 }
408 if (k == (MOVING_AVERAGE-1))
408 if (k == (MOVING_AVERAGE-1))
409 {
409 {
410 k = 0;
410 k = 0;
411 PRINTF("tick\n");
411 PRINTF("tick\n");
412 }
412 }
413 else
413 else
414 {
414 {
415 k++;
415 k++;
416 }
416 }
417 }
417 }
418
418
419 PRINTF("in AVGV *** deleting task\n")
419 PRINTF("in AVGV *** deleting task\n")
420
420
421 status = rtems_task_delete( RTEMS_SELF ); // should not return
421 status = rtems_task_delete( RTEMS_SELF ); // should not return
422
422
423 return;
423 return;
424 }
424 }
425
425
426 rtems_task dumb_task( rtems_task_argument unused )
426 rtems_task dumb_task( rtems_task_argument unused )
427 {
427 {
428 /** This RTEMS taks is used to print messages without affecting the general behaviour of the software.
428 /** This RTEMS taks is used to print messages without affecting the general behaviour of the software.
429 *
429 *
430 * @param unused is the starting argument of the RTEMS task
430 * @param unused is the starting argument of the RTEMS task
431 *
431 *
432 * The DUMB taks waits for RTEMS events and print messages depending on the incoming events.
432 * The DUMB taks waits for RTEMS events and print messages depending on the incoming events.
433 *
433 *
434 */
434 */
435
435
436 unsigned int i;
436 unsigned int i;
437 unsigned int intEventOut;
437 unsigned int intEventOut;
438 unsigned int coarse_time = 0;
438 unsigned int coarse_time = 0;
439 unsigned int fine_time = 0;
439 unsigned int fine_time = 0;
440 rtems_event_set event_out;
440 rtems_event_set event_out;
441
441
442 event_out = EVENT_SETS_NONE_PENDING;
442 event_out = EVENT_SETS_NONE_PENDING;
443
443
444 BOOT_PRINTF("in DUMB *** \n")
444 BOOT_PRINTF("in DUMB *** \n")
445
445
446 while(1){
446 while(1){
447 rtems_event_receive(RTEMS_EVENT_0 | RTEMS_EVENT_1 | RTEMS_EVENT_2 | RTEMS_EVENT_3
447 rtems_event_receive(RTEMS_EVENT_0 | RTEMS_EVENT_1 | RTEMS_EVENT_2 | RTEMS_EVENT_3
448 | RTEMS_EVENT_4 | RTEMS_EVENT_5 | RTEMS_EVENT_6 | RTEMS_EVENT_7
448 | RTEMS_EVENT_4 | RTEMS_EVENT_5 | RTEMS_EVENT_6 | RTEMS_EVENT_7
449 | RTEMS_EVENT_8 | RTEMS_EVENT_9 | RTEMS_EVENT_12 | RTEMS_EVENT_13
449 | RTEMS_EVENT_8 | RTEMS_EVENT_9 | RTEMS_EVENT_12 | RTEMS_EVENT_13
450 | RTEMS_EVENT_14,
450 | RTEMS_EVENT_14,
451 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT
451 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT
452 intEventOut = (unsigned int) event_out;
452 intEventOut = (unsigned int) event_out;
453 for ( i=0; i<NB_RTEMS_EVENTS; i++)
453 for ( i=0; i<NB_RTEMS_EVENTS; i++)
454 {
454 {
455 if ( ((intEventOut >> i) & 1) != 0)
455 if ( ((intEventOut >> i) & 1) != 0)
456 {
456 {
457 coarse_time = time_management_regs->coarse_time;
457 coarse_time = time_management_regs->coarse_time;
458 fine_time = time_management_regs->fine_time;
458 fine_time = time_management_regs->fine_time;
459 if (i==EVENT_12)
459 if (i==EVENT_12)
460 {
460 {
461 PRINTF1("%s\n", DUMB_MESSAGE_12)
461 PRINTF1("%s\n", DUMB_MESSAGE_12)
462 }
462 }
463 if (i==EVENT_13)
463 if (i==EVENT_13)
464 {
464 {
465 PRINTF1("%s\n", DUMB_MESSAGE_13)
465 PRINTF1("%s\n", DUMB_MESSAGE_13)
466 }
466 }
467 if (i==EVENT_14)
467 if (i==EVENT_14)
468 {
468 {
469 PRINTF1("%s\n", DUMB_MESSAGE_1)
469 PRINTF1("%s\n", DUMB_MESSAGE_1)
470 }
470 }
471 }
471 }
472 }
472 }
473 }
473 }
474 }
474 }
475
475
476 //*****************************
476 //*****************************
477 // init housekeeping parameters
477 // init housekeeping parameters
478
478
479 void init_housekeeping_parameters( void )
479 void init_housekeeping_parameters( void )
480 {
480 {
481 /** This function initialize the housekeeping_packet global variable with default values.
481 /** This function initialize the housekeeping_packet global variable with default values.
482 *
482 *
483 */
483 */
484
484
485 unsigned int i = 0;
485 unsigned int i = 0;
486 unsigned char *parameters;
486 unsigned char *parameters;
487 unsigned char sizeOfHK;
487 unsigned char sizeOfHK;
488
488
489 sizeOfHK = sizeof( Packet_TM_LFR_HK_t );
489 sizeOfHK = sizeof( Packet_TM_LFR_HK_t );
490
490
491 parameters = (unsigned char*) &housekeeping_packet;
491 parameters = (unsigned char*) &housekeeping_packet;
492
492
493 for(i = 0; i< sizeOfHK; i++)
493 for(i = 0; i< sizeOfHK; i++)
494 {
494 {
495 parameters[i] = INIT_CHAR;
495 parameters[i] = INIT_CHAR;
496 }
496 }
497
497
498 housekeeping_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
498 housekeeping_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
499 housekeeping_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
499 housekeeping_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
500 housekeeping_packet.reserved = DEFAULT_RESERVED;
500 housekeeping_packet.reserved = DEFAULT_RESERVED;
501 housekeeping_packet.userApplication = CCSDS_USER_APP;
501 housekeeping_packet.userApplication = CCSDS_USER_APP;
502 housekeeping_packet.packetID[0] = (unsigned char) (APID_TM_HK >> SHIFT_1_BYTE);
502 housekeeping_packet.packetID[0] = (unsigned char) (APID_TM_HK >> SHIFT_1_BYTE);
503 housekeeping_packet.packetID[1] = (unsigned char) (APID_TM_HK);
503 housekeeping_packet.packetID[1] = (unsigned char) (APID_TM_HK);
504 housekeeping_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
504 housekeeping_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
505 housekeeping_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
505 housekeeping_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
506 housekeeping_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> SHIFT_1_BYTE);
506 housekeeping_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> SHIFT_1_BYTE);
507 housekeeping_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK );
507 housekeeping_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK );
508 housekeeping_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
508 housekeeping_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
509 housekeeping_packet.serviceType = TM_TYPE_HK;
509 housekeeping_packet.serviceType = TM_TYPE_HK;
510 housekeeping_packet.serviceSubType = TM_SUBTYPE_HK;
510 housekeeping_packet.serviceSubType = TM_SUBTYPE_HK;
511 housekeeping_packet.destinationID = TM_DESTINATION_ID_GROUND;
511 housekeeping_packet.destinationID = TM_DESTINATION_ID_GROUND;
512 housekeeping_packet.sid = SID_HK;
512 housekeeping_packet.sid = SID_HK;
513
513
514 // init status word
514 // init status word
515 housekeeping_packet.lfr_status_word[0] = DEFAULT_STATUS_WORD_BYTE0;
515 housekeeping_packet.lfr_status_word[0] = DEFAULT_STATUS_WORD_BYTE0;
516 housekeeping_packet.lfr_status_word[1] = DEFAULT_STATUS_WORD_BYTE1;
516 housekeeping_packet.lfr_status_word[1] = DEFAULT_STATUS_WORD_BYTE1;
517 // init software version
517 // init software version
518 housekeeping_packet.lfr_sw_version[0] = SW_VERSION_N1;
518 housekeeping_packet.lfr_sw_version[0] = SW_VERSION_N1;
519 housekeeping_packet.lfr_sw_version[1] = SW_VERSION_N2;
519 housekeeping_packet.lfr_sw_version[1] = SW_VERSION_N2;
520 housekeeping_packet.lfr_sw_version[BYTE_2] = SW_VERSION_N3;
520 housekeeping_packet.lfr_sw_version[BYTE_2] = SW_VERSION_N3;
521 housekeeping_packet.lfr_sw_version[BYTE_3] = SW_VERSION_N4;
521 housekeeping_packet.lfr_sw_version[BYTE_3] = SW_VERSION_N4;
522 // init fpga version
522 // init fpga version
523 parameters = (unsigned char *) (REGS_ADDR_VHDL_VERSION);
523 parameters = (unsigned char *) (REGS_ADDR_VHDL_VERSION);
524 housekeeping_packet.lfr_fpga_version[BYTE_0] = parameters[BYTE_1]; // n1
524 housekeeping_packet.lfr_fpga_version[BYTE_0] = parameters[BYTE_1]; // n1
525 housekeeping_packet.lfr_fpga_version[BYTE_1] = parameters[BYTE_2]; // n2
525 housekeeping_packet.lfr_fpga_version[BYTE_1] = parameters[BYTE_2]; // n2
526 housekeeping_packet.lfr_fpga_version[BYTE_2] = parameters[BYTE_3]; // n3
526 housekeeping_packet.lfr_fpga_version[BYTE_2] = parameters[BYTE_3]; // n3
527
527
528 housekeeping_packet.hk_lfr_q_sd_fifo_size = MSG_QUEUE_COUNT_SEND;
528 housekeeping_packet.hk_lfr_q_sd_fifo_size = MSG_QUEUE_COUNT_SEND;
529 housekeeping_packet.hk_lfr_q_rv_fifo_size = MSG_QUEUE_COUNT_RECV;
529 housekeeping_packet.hk_lfr_q_rv_fifo_size = MSG_QUEUE_COUNT_RECV;
530 housekeeping_packet.hk_lfr_q_p0_fifo_size = MSG_QUEUE_COUNT_PRC0;
530 housekeeping_packet.hk_lfr_q_p0_fifo_size = MSG_QUEUE_COUNT_PRC0;
531 housekeeping_packet.hk_lfr_q_p1_fifo_size = MSG_QUEUE_COUNT_PRC1;
531 housekeeping_packet.hk_lfr_q_p1_fifo_size = MSG_QUEUE_COUNT_PRC1;
532 housekeeping_packet.hk_lfr_q_p2_fifo_size = MSG_QUEUE_COUNT_PRC2;
532 housekeeping_packet.hk_lfr_q_p2_fifo_size = MSG_QUEUE_COUNT_PRC2;
533 }
533 }
534
534
535 void increment_seq_counter( unsigned short *packetSequenceControl )
535 void increment_seq_counter( unsigned short *packetSequenceControl )
536 {
536 {
537 /** This function increment the sequence counter passes in argument.
537 /** This function increment the sequence counter passes in argument.
538 *
538 *
539 * The increment does not affect the grouping flag. In case of an overflow, the counter is reset to 0.
539 * The increment does not affect the grouping flag. In case of an overflow, the counter is reset to 0.
540 *
540 *
541 */
541 */
542
542
543 unsigned short segmentation_grouping_flag;
543 unsigned short segmentation_grouping_flag;
544 unsigned short sequence_cnt;
544 unsigned short sequence_cnt;
545
545
546 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << SHIFT_1_BYTE; // keep bits 7 downto 6
546 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << SHIFT_1_BYTE; // keep bits 7 downto 6
547 sequence_cnt = (*packetSequenceControl) & SEQ_CNT_MASK; // [0011 1111 1111 1111]
547 sequence_cnt = (*packetSequenceControl) & SEQ_CNT_MASK; // [0011 1111 1111 1111]
548
548
549 if ( sequence_cnt < SEQ_CNT_MAX)
549 if ( sequence_cnt < SEQ_CNT_MAX)
550 {
550 {
551 sequence_cnt = sequence_cnt + 1;
551 sequence_cnt = sequence_cnt + 1;
552 }
552 }
553 else
553 else
554 {
554 {
555 sequence_cnt = 0;
555 sequence_cnt = 0;
556 }
556 }
557
557
558 *packetSequenceControl = segmentation_grouping_flag | sequence_cnt ;
558 *packetSequenceControl = segmentation_grouping_flag | sequence_cnt ;
559 }
559 }
560
560
561 void getTime( unsigned char *time)
561 void getTime( unsigned char *time)
562 {
562 {
563 /** This function write the current local time in the time buffer passed in argument.
563 /** This function write the current local time in the time buffer passed in argument.
564 *
564 *
565 */
565 */
566
566
567 time[0] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_3_BYTES);
567 time[0] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_3_BYTES);
568 time[1] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_2_BYTES);
568 time[1] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_2_BYTES);
569 time[2] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_1_BYTE);
569 time[2] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_1_BYTE);
570 time[3] = (unsigned char) (time_management_regs->coarse_time);
570 time[3] = (unsigned char) (time_management_regs->coarse_time);
571 time[4] = (unsigned char) (time_management_regs->fine_time>>SHIFT_1_BYTE);
571 time[4] = (unsigned char) (time_management_regs->fine_time>>SHIFT_1_BYTE);
572 time[5] = (unsigned char) (time_management_regs->fine_time);
572 time[5] = (unsigned char) (time_management_regs->fine_time);
573 }
573 }
574
574
575 unsigned long long int getTimeAsUnsignedLongLongInt( )
575 unsigned long long int getTimeAsUnsignedLongLongInt( )
576 {
576 {
577 /** This function write the current local time in the time buffer passed in argument.
577 /** This function write the current local time in the time buffer passed in argument.
578 *
578 *
579 */
579 */
580 unsigned long long int time;
580 unsigned long long int time;
581
581
582 time = ( (unsigned long long int) (time_management_regs->coarse_time & COARSE_TIME_MASK) << SHIFT_2_BYTES )
582 time = ( (unsigned long long int) (time_management_regs->coarse_time & COARSE_TIME_MASK) << SHIFT_2_BYTES )
583 + time_management_regs->fine_time;
583 + time_management_regs->fine_time;
584
584
585 return time;
585 return time;
586 }
586 }
587
587
588 void send_dumb_hk( void )
588 void send_dumb_hk( void )
589 {
589 {
590 Packet_TM_LFR_HK_t dummy_hk_packet;
590 Packet_TM_LFR_HK_t dummy_hk_packet;
591 unsigned char *parameters;
591 unsigned char *parameters;
592 unsigned int i;
592 unsigned int i;
593 rtems_id queue_id;
593 rtems_id queue_id;
594
594
595 queue_id = RTEMS_ID_NONE;
595 queue_id = RTEMS_ID_NONE;
596
596
597 dummy_hk_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
597 dummy_hk_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
598 dummy_hk_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
598 dummy_hk_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
599 dummy_hk_packet.reserved = DEFAULT_RESERVED;
599 dummy_hk_packet.reserved = DEFAULT_RESERVED;
600 dummy_hk_packet.userApplication = CCSDS_USER_APP;
600 dummy_hk_packet.userApplication = CCSDS_USER_APP;
601 dummy_hk_packet.packetID[0] = (unsigned char) (APID_TM_HK >> SHIFT_1_BYTE);
601 dummy_hk_packet.packetID[0] = (unsigned char) (APID_TM_HK >> SHIFT_1_BYTE);
602 dummy_hk_packet.packetID[1] = (unsigned char) (APID_TM_HK);
602 dummy_hk_packet.packetID[1] = (unsigned char) (APID_TM_HK);
603 dummy_hk_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
603 dummy_hk_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
604 dummy_hk_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
604 dummy_hk_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
605 dummy_hk_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> SHIFT_1_BYTE);
605 dummy_hk_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> SHIFT_1_BYTE);
606 dummy_hk_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK );
606 dummy_hk_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK );
607 dummy_hk_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
607 dummy_hk_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
608 dummy_hk_packet.serviceType = TM_TYPE_HK;
608 dummy_hk_packet.serviceType = TM_TYPE_HK;
609 dummy_hk_packet.serviceSubType = TM_SUBTYPE_HK;
609 dummy_hk_packet.serviceSubType = TM_SUBTYPE_HK;
610 dummy_hk_packet.destinationID = TM_DESTINATION_ID_GROUND;
610 dummy_hk_packet.destinationID = TM_DESTINATION_ID_GROUND;
611 dummy_hk_packet.time[0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
611 dummy_hk_packet.time[0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
612 dummy_hk_packet.time[1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
612 dummy_hk_packet.time[1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
613 dummy_hk_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
613 dummy_hk_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
614 dummy_hk_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
614 dummy_hk_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
615 dummy_hk_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
615 dummy_hk_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
616 dummy_hk_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
616 dummy_hk_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
617 dummy_hk_packet.sid = SID_HK;
617 dummy_hk_packet.sid = SID_HK;
618
618
619 // init status word
619 // init status word
620 dummy_hk_packet.lfr_status_word[0] = INT8_ALL_F;
620 dummy_hk_packet.lfr_status_word[0] = INT8_ALL_F;
621 dummy_hk_packet.lfr_status_word[1] = INT8_ALL_F;
621 dummy_hk_packet.lfr_status_word[1] = INT8_ALL_F;
622 // init software version
622 // init software version
623 dummy_hk_packet.lfr_sw_version[0] = SW_VERSION_N1;
623 dummy_hk_packet.lfr_sw_version[0] = SW_VERSION_N1;
624 dummy_hk_packet.lfr_sw_version[1] = SW_VERSION_N2;
624 dummy_hk_packet.lfr_sw_version[1] = SW_VERSION_N2;
625 dummy_hk_packet.lfr_sw_version[BYTE_2] = SW_VERSION_N3;
625 dummy_hk_packet.lfr_sw_version[BYTE_2] = SW_VERSION_N3;
626 dummy_hk_packet.lfr_sw_version[BYTE_3] = SW_VERSION_N4;
626 dummy_hk_packet.lfr_sw_version[BYTE_3] = SW_VERSION_N4;
627 // init fpga version
627 // init fpga version
628 parameters = (unsigned char *) (REGS_ADDR_WAVEFORM_PICKER + APB_OFFSET_VHDL_REV);
628 parameters = (unsigned char *) (REGS_ADDR_WAVEFORM_PICKER + APB_OFFSET_VHDL_REV);
629 dummy_hk_packet.lfr_fpga_version[BYTE_0] = parameters[BYTE_1]; // n1
629 dummy_hk_packet.lfr_fpga_version[BYTE_0] = parameters[BYTE_1]; // n1
630 dummy_hk_packet.lfr_fpga_version[BYTE_1] = parameters[BYTE_2]; // n2
630 dummy_hk_packet.lfr_fpga_version[BYTE_1] = parameters[BYTE_2]; // n2
631 dummy_hk_packet.lfr_fpga_version[BYTE_2] = parameters[BYTE_3]; // n3
631 dummy_hk_packet.lfr_fpga_version[BYTE_2] = parameters[BYTE_3]; // n3
632
632
633 parameters = (unsigned char *) &dummy_hk_packet.hk_lfr_cpu_load;
633 parameters = (unsigned char *) &dummy_hk_packet.hk_lfr_cpu_load;
634
634
635 for (i=0; i<(BYTE_POS_HK_REACTION_WHEELS_FREQUENCY - BYTE_POS_HK_LFR_CPU_LOAD); i++)
635 for (i=0; i<(BYTE_POS_HK_REACTION_WHEELS_FREQUENCY - BYTE_POS_HK_LFR_CPU_LOAD); i++)
636 {
636 {
637 parameters[i] = INT8_ALL_F;
637 parameters[i] = INT8_ALL_F;
638 }
638 }
639
639
640 get_message_queue_id_send( &queue_id );
640 get_message_queue_id_send( &queue_id );
641
641
642 rtems_message_queue_send( queue_id, &dummy_hk_packet,
642 rtems_message_queue_send( queue_id, &dummy_hk_packet,
643 PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
643 PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
644 }
644 }
645
645
646 void get_temperatures( unsigned char *temperatures )
646 void get_temperatures( unsigned char *temperatures )
647 {
647 {
648 unsigned char* temp_scm_ptr;
648 unsigned char* temp_scm_ptr;
649 unsigned char* temp_pcb_ptr;
649 unsigned char* temp_pcb_ptr;
650 unsigned char* temp_fpga_ptr;
650 unsigned char* temp_fpga_ptr;
651
651
652 // SEL1 SEL0
652 // SEL1 SEL0
653 // 0 0 => PCB
653 // 0 0 => PCB
654 // 0 1 => FPGA
654 // 0 1 => FPGA
655 // 1 0 => SCM
655 // 1 0 => SCM
656
656
657 temp_scm_ptr = (unsigned char *) &time_management_regs->temp_scm;
657 temp_scm_ptr = (unsigned char *) &time_management_regs->temp_scm;
658 temp_pcb_ptr = (unsigned char *) &time_management_regs->temp_pcb;
658 temp_pcb_ptr = (unsigned char *) &time_management_regs->temp_pcb;
659 temp_fpga_ptr = (unsigned char *) &time_management_regs->temp_fpga;
659 temp_fpga_ptr = (unsigned char *) &time_management_regs->temp_fpga;
660
660
661 temperatures[ BYTE_0 ] = temp_scm_ptr[ BYTE_2 ];
661 temperatures[ BYTE_0 ] = temp_scm_ptr[ BYTE_2 ];
662 temperatures[ BYTE_1 ] = temp_scm_ptr[ BYTE_3 ];
662 temperatures[ BYTE_1 ] = temp_scm_ptr[ BYTE_3 ];
663 temperatures[ BYTE_2 ] = temp_pcb_ptr[ BYTE_2 ];
663 temperatures[ BYTE_2 ] = temp_pcb_ptr[ BYTE_2 ];
664 temperatures[ BYTE_3 ] = temp_pcb_ptr[ BYTE_3 ];
664 temperatures[ BYTE_3 ] = temp_pcb_ptr[ BYTE_3 ];
665 temperatures[ BYTE_4 ] = temp_fpga_ptr[ BYTE_2 ];
665 temperatures[ BYTE_4 ] = temp_fpga_ptr[ BYTE_2 ];
666 temperatures[ BYTE_5 ] = temp_fpga_ptr[ BYTE_3 ];
666 temperatures[ BYTE_5 ] = temp_fpga_ptr[ BYTE_3 ];
667 }
667 }
668
668
669 void get_v_e1_e2_f3( unsigned char *spacecraft_potential )
669 void get_v_e1_e2_f3( unsigned char *spacecraft_potential )
670 {
670 {
671 unsigned char* v_ptr;
671 unsigned char* v_ptr;
672 unsigned char* e1_ptr;
672 unsigned char* e1_ptr;
673 unsigned char* e2_ptr;
673 unsigned char* e2_ptr;
674
674
675 v_ptr = (unsigned char *) &waveform_picker_regs->v;
675 v_ptr = (unsigned char *) &waveform_picker_regs->v;
676 e1_ptr = (unsigned char *) &waveform_picker_regs->e1;
676 e1_ptr = (unsigned char *) &waveform_picker_regs->e1;
677 e2_ptr = (unsigned char *) &waveform_picker_regs->e2;
677 e2_ptr = (unsigned char *) &waveform_picker_regs->e2;
678
678
679 spacecraft_potential[ BYTE_0 ] = v_ptr[ BYTE_2 ];
679 spacecraft_potential[ BYTE_0 ] = v_ptr[ BYTE_2 ];
680 spacecraft_potential[ BYTE_1 ] = v_ptr[ BYTE_3 ];
680 spacecraft_potential[ BYTE_1 ] = v_ptr[ BYTE_3 ];
681 spacecraft_potential[ BYTE_2 ] = e1_ptr[ BYTE_2 ];
681 spacecraft_potential[ BYTE_2 ] = e1_ptr[ BYTE_2 ];
682 spacecraft_potential[ BYTE_3 ] = e1_ptr[ BYTE_3 ];
682 spacecraft_potential[ BYTE_3 ] = e1_ptr[ BYTE_3 ];
683 spacecraft_potential[ BYTE_4 ] = e2_ptr[ BYTE_2 ];
683 spacecraft_potential[ BYTE_4 ] = e2_ptr[ BYTE_2 ];
684 spacecraft_potential[ BYTE_5 ] = e2_ptr[ BYTE_3 ];
684 spacecraft_potential[ BYTE_5 ] = e2_ptr[ BYTE_3 ];
685 }
685 }
686
686
687 void get_cpu_load( unsigned char *resource_statistics )
687 void get_cpu_load( unsigned char *resource_statistics )
688 {
688 {
689 unsigned char cpu_load;
689 unsigned char cpu_load;
690
690
691 cpu_load = lfr_rtems_cpu_usage_report();
691 cpu_load = lfr_rtems_cpu_usage_report();
692
692
693 // HK_LFR_CPU_LOAD
693 // HK_LFR_CPU_LOAD
694 resource_statistics[0] = cpu_load;
694 resource_statistics[0] = cpu_load;
695
695
696 // HK_LFR_CPU_LOAD_MAX
696 // HK_LFR_CPU_LOAD_MAX
697 if (cpu_load > resource_statistics[1])
697 if (cpu_load > resource_statistics[1])
698 {
698 {
699 resource_statistics[1] = cpu_load;
699 resource_statistics[1] = cpu_load;
700 }
700 }
701
701
702 // CPU_LOAD_AVE
702 // CPU_LOAD_AVE
703 resource_statistics[BYTE_2] = 0;
703 resource_statistics[BYTE_2] = 0;
704
704
705 #ifndef PRINT_TASK_STATISTICS
705 #ifndef PRINT_TASK_STATISTICS
706 rtems_cpu_usage_reset();
706 rtems_cpu_usage_reset();
707 #endif
707 #endif
708
708
709 }
709 }
710
710
711 void set_hk_lfr_sc_potential_flag( bool state )
711 void set_hk_lfr_sc_potential_flag( bool state )
712 {
712 {
713 if (state == true)
713 if (state == true)
714 {
714 {
715 housekeeping_packet.lfr_status_word[1] =
715 housekeeping_packet.lfr_status_word[1] =
716 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_SC_POTENTIAL_FLAG_BIT; // [0100 0000]
716 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_SC_POTENTIAL_FLAG_BIT; // [0100 0000]
717 }
717 }
718 else
718 else
719 {
719 {
720 housekeeping_packet.lfr_status_word[1] =
720 housekeeping_packet.lfr_status_word[1] =
721 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_SC_POTENTIAL_FLAG_MASK; // [1011 1111]
721 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_SC_POTENTIAL_FLAG_MASK; // [1011 1111]
722 }
722 }
723 }
723 }
724
724
725 void set_sy_lfr_pas_filter_enabled( bool state )
725 void set_sy_lfr_pas_filter_enabled( bool state )
726 {
726 {
727 if (state == true)
727 if (state == true)
728 {
728 {
729 housekeeping_packet.lfr_status_word[1] =
729 housekeeping_packet.lfr_status_word[1] =
730 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_PAS_FILTER_ENABLED_BIT; // [0010 0000]
730 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_PAS_FILTER_ENABLED_BIT; // [0010 0000]
731 }
731 }
732 else
732 else
733 {
733 {
734 housekeeping_packet.lfr_status_word[1] =
734 housekeeping_packet.lfr_status_word[1] =
735 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_PAS_FILTER_ENABLED_MASK; // [1101 1111]
735 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_PAS_FILTER_ENABLED_MASK; // [1101 1111]
736 }
736 }
737 }
737 }
738
738
739 void set_sy_lfr_watchdog_enabled( bool state )
739 void set_sy_lfr_watchdog_enabled( bool state )
740 {
740 {
741 if (state == true)
741 if (state == true)
742 {
742 {
743 housekeeping_packet.lfr_status_word[1] =
743 housekeeping_packet.lfr_status_word[1] =
744 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_WATCHDOG_BIT; // [0001 0000]
744 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_WATCHDOG_BIT; // [0001 0000]
745 }
745 }
746 else
746 else
747 {
747 {
748 housekeeping_packet.lfr_status_word[1] =
748 housekeeping_packet.lfr_status_word[1] =
749 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_WATCHDOG_MASK; // [1110 1111]
749 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_WATCHDOG_MASK; // [1110 1111]
750 }
750 }
751 }
751 }
752
752
753 void set_hk_lfr_calib_enable( bool state )
753 void set_hk_lfr_calib_enable( bool state )
754 {
754 {
755 if (state == true)
755 if (state == true)
756 {
756 {
757 housekeeping_packet.lfr_status_word[1] =
757 housekeeping_packet.lfr_status_word[1] =
758 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_CALIB_BIT; // [0000 1000]
758 housekeeping_packet.lfr_status_word[1] | STATUS_WORD_CALIB_BIT; // [0000 1000]
759 }
759 }
760 else
760 else
761 {
761 {
762 housekeeping_packet.lfr_status_word[1] =
762 housekeeping_packet.lfr_status_word[1] =
763 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_CALIB_MASK; // [1111 0111]
763 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_CALIB_MASK; // [1111 0111]
764 }
764 }
765 }
765 }
766
766
767 void set_hk_lfr_reset_cause( enum lfr_reset_cause_t lfr_reset_cause )
767 void set_hk_lfr_reset_cause( enum lfr_reset_cause_t lfr_reset_cause )
768 {
768 {
769 housekeeping_packet.lfr_status_word[1] =
769 housekeeping_packet.lfr_status_word[1] =
770 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_RESET_CAUSE_MASK; // [1111 1000]
770 housekeeping_packet.lfr_status_word[1] & STATUS_WORD_RESET_CAUSE_MASK; // [1111 1000]
771
771
772 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1]
772 housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1]
773 | (lfr_reset_cause & STATUS_WORD_RESET_CAUSE_BITS ); // [0000 0111]
773 | (lfr_reset_cause & STATUS_WORD_RESET_CAUSE_BITS ); // [0000 0111]
774
774
775 }
775 }
776
776
777 void increment_hk_counter( unsigned char newValue, unsigned char oldValue, unsigned int *counter )
777 void increment_hk_counter( unsigned char newValue, unsigned char oldValue, unsigned int *counter )
778 {
778 {
779 int delta;
779 int delta;
780
780
781 delta = 0;
781 delta = 0;
782
782
783 if (newValue >= oldValue)
783 if (newValue >= oldValue)
784 {
784 {
785 delta = newValue - oldValue;
785 delta = newValue - oldValue;
786 }
786 }
787 else
787 else
788 {
788 {
789 delta = (255 - oldValue) + newValue;
789 delta = (CONST_256 - oldValue) + newValue;
790 }
790 }
791
791
792 *counter = *counter + delta;
792 *counter = *counter + delta;
793 }
793 }
794
794
795 void hk_lfr_le_update( void )
795 void hk_lfr_le_update( void )
796 {
796 {
797 static hk_lfr_le_t old_hk_lfr_le = {0};
797 static hk_lfr_le_t old_hk_lfr_le = {0};
798 hk_lfr_le_t new_hk_lfr_le;
798 hk_lfr_le_t new_hk_lfr_le;
799 unsigned int counter;
799 unsigned int counter;
800
800
801 counter = (((unsigned int) housekeeping_packet.hk_lfr_le_cnt[0]) * 256) + housekeeping_packet.hk_lfr_le_cnt[1];
801 counter = (((unsigned int) housekeeping_packet.hk_lfr_le_cnt[0]) * CONST_256) + housekeeping_packet.hk_lfr_le_cnt[1];
802
802
803 // DPU
803 // DPU
804 new_hk_lfr_le.dpu_spw_parity = housekeeping_packet.hk_lfr_dpu_spw_parity;
804 new_hk_lfr_le.dpu_spw_parity = housekeeping_packet.hk_lfr_dpu_spw_parity;
805 new_hk_lfr_le.dpu_spw_disconnect= housekeeping_packet.hk_lfr_dpu_spw_disconnect;
805 new_hk_lfr_le.dpu_spw_disconnect= housekeeping_packet.hk_lfr_dpu_spw_disconnect;
806 new_hk_lfr_le.dpu_spw_escape = housekeeping_packet.hk_lfr_dpu_spw_escape;
806 new_hk_lfr_le.dpu_spw_escape = housekeeping_packet.hk_lfr_dpu_spw_escape;
807 new_hk_lfr_le.dpu_spw_credit = housekeeping_packet.hk_lfr_dpu_spw_credit;
807 new_hk_lfr_le.dpu_spw_credit = housekeeping_packet.hk_lfr_dpu_spw_credit;
808 new_hk_lfr_le.dpu_spw_write_sync= housekeeping_packet.hk_lfr_dpu_spw_write_sync;
808 new_hk_lfr_le.dpu_spw_write_sync= housekeeping_packet.hk_lfr_dpu_spw_write_sync;
809 // TIMECODE
809 // TIMECODE
810 new_hk_lfr_le.timecode_erroneous= housekeeping_packet.hk_lfr_timecode_erroneous;
810 new_hk_lfr_le.timecode_erroneous= housekeeping_packet.hk_lfr_timecode_erroneous;
811 new_hk_lfr_le.timecode_missing = housekeeping_packet.hk_lfr_timecode_missing;
811 new_hk_lfr_le.timecode_missing = housekeeping_packet.hk_lfr_timecode_missing;
812 new_hk_lfr_le.timecode_invalid = housekeeping_packet.hk_lfr_timecode_invalid;
812 new_hk_lfr_le.timecode_invalid = housekeeping_packet.hk_lfr_timecode_invalid;
813 // TIME
813 // TIME
814 new_hk_lfr_le.time_timecode_it = housekeeping_packet.hk_lfr_time_timecode_it;
814 new_hk_lfr_le.time_timecode_it = housekeeping_packet.hk_lfr_time_timecode_it;
815 new_hk_lfr_le.time_not_synchro = housekeeping_packet.hk_lfr_time_not_synchro;
815 new_hk_lfr_le.time_not_synchro = housekeeping_packet.hk_lfr_time_not_synchro;
816 new_hk_lfr_le.time_timecode_ctr = housekeeping_packet.hk_lfr_time_timecode_ctr;
816 new_hk_lfr_le.time_timecode_ctr = housekeeping_packet.hk_lfr_time_timecode_ctr;
817 //AHB
817 //AHB
818 new_hk_lfr_le.ahb_correctable = housekeeping_packet.hk_lfr_ahb_correctable;
818 new_hk_lfr_le.ahb_correctable = housekeeping_packet.hk_lfr_ahb_correctable;
819 // housekeeping_packet.hk_lfr_dpu_spw_rx_ahb => not handled by the grspw driver
819 // housekeeping_packet.hk_lfr_dpu_spw_rx_ahb => not handled by the grspw driver
820 // housekeeping_packet.hk_lfr_dpu_spw_tx_ahb => not handled by the grspw driver
820 // housekeeping_packet.hk_lfr_dpu_spw_tx_ahb => not handled by the grspw driver
821
821
822 // update the le counter
822 // update the le counter
823 // DPU
823 // DPU
824 increment_hk_counter( new_hk_lfr_le.dpu_spw_parity, old_hk_lfr_le.dpu_spw_parity, &counter );
824 increment_hk_counter( new_hk_lfr_le.dpu_spw_parity, old_hk_lfr_le.dpu_spw_parity, &counter );
825 increment_hk_counter( new_hk_lfr_le.dpu_spw_disconnect,old_hk_lfr_le.dpu_spw_disconnect, &counter );
825 increment_hk_counter( new_hk_lfr_le.dpu_spw_disconnect,old_hk_lfr_le.dpu_spw_disconnect, &counter );
826 increment_hk_counter( new_hk_lfr_le.dpu_spw_escape, old_hk_lfr_le.dpu_spw_escape, &counter );
826 increment_hk_counter( new_hk_lfr_le.dpu_spw_escape, old_hk_lfr_le.dpu_spw_escape, &counter );
827 increment_hk_counter( new_hk_lfr_le.dpu_spw_credit, old_hk_lfr_le.dpu_spw_credit, &counter );
827 increment_hk_counter( new_hk_lfr_le.dpu_spw_credit, old_hk_lfr_le.dpu_spw_credit, &counter );
828 increment_hk_counter( new_hk_lfr_le.dpu_spw_write_sync,old_hk_lfr_le.dpu_spw_write_sync, &counter );
828 increment_hk_counter( new_hk_lfr_le.dpu_spw_write_sync,old_hk_lfr_le.dpu_spw_write_sync, &counter );
829 // TIMECODE
829 // TIMECODE
830 increment_hk_counter( new_hk_lfr_le.timecode_erroneous,old_hk_lfr_le.timecode_erroneous, &counter );
830 increment_hk_counter( new_hk_lfr_le.timecode_erroneous,old_hk_lfr_le.timecode_erroneous, &counter );
831 increment_hk_counter( new_hk_lfr_le.timecode_missing, old_hk_lfr_le.timecode_missing, &counter );
831 increment_hk_counter( new_hk_lfr_le.timecode_missing, old_hk_lfr_le.timecode_missing, &counter );
832 increment_hk_counter( new_hk_lfr_le.timecode_invalid, old_hk_lfr_le.timecode_invalid, &counter );
832 increment_hk_counter( new_hk_lfr_le.timecode_invalid, old_hk_lfr_le.timecode_invalid, &counter );
833 // TIME
833 // TIME
834 increment_hk_counter( new_hk_lfr_le.time_timecode_it, old_hk_lfr_le.time_timecode_it, &counter );
834 increment_hk_counter( new_hk_lfr_le.time_timecode_it, old_hk_lfr_le.time_timecode_it, &counter );
835 increment_hk_counter( new_hk_lfr_le.time_not_synchro, old_hk_lfr_le.time_not_synchro, &counter );
835 increment_hk_counter( new_hk_lfr_le.time_not_synchro, old_hk_lfr_le.time_not_synchro, &counter );
836 increment_hk_counter( new_hk_lfr_le.time_timecode_ctr, old_hk_lfr_le.time_timecode_ctr, &counter );
836 increment_hk_counter( new_hk_lfr_le.time_timecode_ctr, old_hk_lfr_le.time_timecode_ctr, &counter );
837 // AHB
837 // AHB
838 increment_hk_counter( new_hk_lfr_le.ahb_correctable, old_hk_lfr_le.ahb_correctable, &counter );
838 increment_hk_counter( new_hk_lfr_le.ahb_correctable, old_hk_lfr_le.ahb_correctable, &counter );
839
839
840 // DPU
840 // DPU
841 old_hk_lfr_le.dpu_spw_parity = new_hk_lfr_le.dpu_spw_parity;
841 old_hk_lfr_le.dpu_spw_parity = new_hk_lfr_le.dpu_spw_parity;
842 old_hk_lfr_le.dpu_spw_disconnect= new_hk_lfr_le.dpu_spw_disconnect;
842 old_hk_lfr_le.dpu_spw_disconnect= new_hk_lfr_le.dpu_spw_disconnect;
843 old_hk_lfr_le.dpu_spw_escape = new_hk_lfr_le.dpu_spw_escape;
843 old_hk_lfr_le.dpu_spw_escape = new_hk_lfr_le.dpu_spw_escape;
844 old_hk_lfr_le.dpu_spw_credit = new_hk_lfr_le.dpu_spw_credit;
844 old_hk_lfr_le.dpu_spw_credit = new_hk_lfr_le.dpu_spw_credit;
845 old_hk_lfr_le.dpu_spw_write_sync= new_hk_lfr_le.dpu_spw_write_sync;
845 old_hk_lfr_le.dpu_spw_write_sync= new_hk_lfr_le.dpu_spw_write_sync;
846 // TIMECODE
846 // TIMECODE
847 old_hk_lfr_le.timecode_erroneous= new_hk_lfr_le.timecode_erroneous;
847 old_hk_lfr_le.timecode_erroneous= new_hk_lfr_le.timecode_erroneous;
848 old_hk_lfr_le.timecode_missing = new_hk_lfr_le.timecode_missing;
848 old_hk_lfr_le.timecode_missing = new_hk_lfr_le.timecode_missing;
849 old_hk_lfr_le.timecode_invalid = new_hk_lfr_le.timecode_invalid;
849 old_hk_lfr_le.timecode_invalid = new_hk_lfr_le.timecode_invalid;
850 // TIME
850 // TIME
851 old_hk_lfr_le.time_timecode_it = new_hk_lfr_le.time_timecode_it;
851 old_hk_lfr_le.time_timecode_it = new_hk_lfr_le.time_timecode_it;
852 old_hk_lfr_le.time_not_synchro = new_hk_lfr_le.time_not_synchro;
852 old_hk_lfr_le.time_not_synchro = new_hk_lfr_le.time_not_synchro;
853 old_hk_lfr_le.time_timecode_ctr = new_hk_lfr_le.time_timecode_ctr;
853 old_hk_lfr_le.time_timecode_ctr = new_hk_lfr_le.time_timecode_ctr;
854 //AHB
854 //AHB
855 old_hk_lfr_le.ahb_correctable = new_hk_lfr_le.ahb_correctable;
855 old_hk_lfr_le.ahb_correctable = new_hk_lfr_le.ahb_correctable;
856 // housekeeping_packet.hk_lfr_dpu_spw_rx_ahb => not handled by the grspw driver
856 // housekeeping_packet.hk_lfr_dpu_spw_rx_ahb => not handled by the grspw driver
857 // housekeeping_packet.hk_lfr_dpu_spw_tx_ahb => not handled by the grspw driver
857 // housekeeping_packet.hk_lfr_dpu_spw_tx_ahb => not handled by the grspw driver
858
858
859 // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers
859 // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers
860 // LE
860 // LE
861 housekeeping_packet.hk_lfr_le_cnt[0] = (unsigned char) ((counter & BYTE0_MASK) >> SHIFT_1_BYTE);
861 housekeeping_packet.hk_lfr_le_cnt[0] = (unsigned char) ((counter & BYTE0_MASK) >> SHIFT_1_BYTE);
862 housekeeping_packet.hk_lfr_le_cnt[1] = (unsigned char) (counter & BYTE1_MASK);
862 housekeeping_packet.hk_lfr_le_cnt[1] = (unsigned char) (counter & BYTE1_MASK);
863 }
863 }
864
864
865 void hk_lfr_me_update( void )
865 void hk_lfr_me_update( void )
866 {
866 {
867 static hk_lfr_me_t old_hk_lfr_me = {0};
867 static hk_lfr_me_t old_hk_lfr_me = {0};
868 hk_lfr_me_t new_hk_lfr_me;
868 hk_lfr_me_t new_hk_lfr_me;
869 unsigned int counter;
869 unsigned int counter;
870
870
871 counter = (((unsigned int) housekeeping_packet.hk_lfr_me_cnt[0]) * 256) + housekeeping_packet.hk_lfr_me_cnt[1];
871 counter = (((unsigned int) housekeeping_packet.hk_lfr_me_cnt[0]) * CONST_256) + housekeeping_packet.hk_lfr_me_cnt[1];
872
872
873 // get the current values
873 // get the current values
874 new_hk_lfr_me.dpu_spw_early_eop = housekeeping_packet.hk_lfr_dpu_spw_early_eop;
874 new_hk_lfr_me.dpu_spw_early_eop = housekeeping_packet.hk_lfr_dpu_spw_early_eop;
875 new_hk_lfr_me.dpu_spw_invalid_addr = housekeeping_packet.hk_lfr_dpu_spw_invalid_addr;
875 new_hk_lfr_me.dpu_spw_invalid_addr = housekeeping_packet.hk_lfr_dpu_spw_invalid_addr;
876 new_hk_lfr_me.dpu_spw_eep = housekeeping_packet.hk_lfr_dpu_spw_eep;
876 new_hk_lfr_me.dpu_spw_eep = housekeeping_packet.hk_lfr_dpu_spw_eep;
877 new_hk_lfr_me.dpu_spw_rx_too_big = housekeeping_packet.hk_lfr_dpu_spw_rx_too_big;
877 new_hk_lfr_me.dpu_spw_rx_too_big = housekeeping_packet.hk_lfr_dpu_spw_rx_too_big;
878
878
879 // update the me counter
879 // update the me counter
880 increment_hk_counter( new_hk_lfr_me.dpu_spw_early_eop, old_hk_lfr_me.dpu_spw_early_eop, &counter );
880 increment_hk_counter( new_hk_lfr_me.dpu_spw_early_eop, old_hk_lfr_me.dpu_spw_early_eop, &counter );
881 increment_hk_counter( new_hk_lfr_me.dpu_spw_invalid_addr, old_hk_lfr_me.dpu_spw_invalid_addr, &counter );
881 increment_hk_counter( new_hk_lfr_me.dpu_spw_invalid_addr, old_hk_lfr_me.dpu_spw_invalid_addr, &counter );
882 increment_hk_counter( new_hk_lfr_me.dpu_spw_eep, old_hk_lfr_me.dpu_spw_eep, &counter );
882 increment_hk_counter( new_hk_lfr_me.dpu_spw_eep, old_hk_lfr_me.dpu_spw_eep, &counter );
883 increment_hk_counter( new_hk_lfr_me.dpu_spw_rx_too_big, old_hk_lfr_me.dpu_spw_rx_too_big, &counter );
883 increment_hk_counter( new_hk_lfr_me.dpu_spw_rx_too_big, old_hk_lfr_me.dpu_spw_rx_too_big, &counter );
884
884
885 // store the counters for the next time
885 // store the counters for the next time
886 old_hk_lfr_me.dpu_spw_early_eop = new_hk_lfr_me.dpu_spw_early_eop;
886 old_hk_lfr_me.dpu_spw_early_eop = new_hk_lfr_me.dpu_spw_early_eop;
887 old_hk_lfr_me.dpu_spw_invalid_addr = new_hk_lfr_me.dpu_spw_invalid_addr;
887 old_hk_lfr_me.dpu_spw_invalid_addr = new_hk_lfr_me.dpu_spw_invalid_addr;
888 old_hk_lfr_me.dpu_spw_eep = new_hk_lfr_me.dpu_spw_eep;
888 old_hk_lfr_me.dpu_spw_eep = new_hk_lfr_me.dpu_spw_eep;
889 old_hk_lfr_me.dpu_spw_rx_too_big = new_hk_lfr_me.dpu_spw_rx_too_big;
889 old_hk_lfr_me.dpu_spw_rx_too_big = new_hk_lfr_me.dpu_spw_rx_too_big;
890
890
891 // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers
891 // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers
892 // ME
892 // ME
893 housekeeping_packet.hk_lfr_me_cnt[0] = (unsigned char) ((counter & BYTE0_MASK) >> SHIFT_1_BYTE);
893 housekeeping_packet.hk_lfr_me_cnt[0] = (unsigned char) ((counter & BYTE0_MASK) >> SHIFT_1_BYTE);
894 housekeeping_packet.hk_lfr_me_cnt[1] = (unsigned char) (counter & BYTE1_MASK);
894 housekeeping_packet.hk_lfr_me_cnt[1] = (unsigned char) (counter & BYTE1_MASK);
895 }
895 }
896
896
897 void hk_lfr_le_me_he_update()
897 void hk_lfr_le_me_he_update()
898 {
898 {
899
899
900 unsigned int hk_lfr_he_cnt;
900 unsigned int hk_lfr_he_cnt;
901
901
902 hk_lfr_he_cnt = (((unsigned int) housekeeping_packet.hk_lfr_he_cnt[0]) * 256) + housekeeping_packet.hk_lfr_he_cnt[1];
902 hk_lfr_he_cnt = (((unsigned int) housekeeping_packet.hk_lfr_he_cnt[0]) * 256) + housekeeping_packet.hk_lfr_he_cnt[1];
903
903
904 //update the low severity error counter
904 //update the low severity error counter
905 hk_lfr_le_update( );
905 hk_lfr_le_update( );
906
906
907 //update the medium severity error counter
907 //update the medium severity error counter
908 hk_lfr_me_update();
908 hk_lfr_me_update();
909
909
910 //update the high severity error counter
910 //update the high severity error counter
911 hk_lfr_he_cnt = 0;
911 hk_lfr_he_cnt = 0;
912
912
913 // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers
913 // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers
914 // HE
914 // HE
915 housekeeping_packet.hk_lfr_he_cnt[0] = (unsigned char) ((hk_lfr_he_cnt & BYTE0_MASK) >> SHIFT_1_BYTE);
915 housekeeping_packet.hk_lfr_he_cnt[0] = (unsigned char) ((hk_lfr_he_cnt & BYTE0_MASK) >> SHIFT_1_BYTE);
916 housekeeping_packet.hk_lfr_he_cnt[1] = (unsigned char) (hk_lfr_he_cnt & BYTE1_MASK);
916 housekeeping_packet.hk_lfr_he_cnt[1] = (unsigned char) (hk_lfr_he_cnt & BYTE1_MASK);
917
917
918 }
918 }
919
919
920 void set_hk_lfr_time_not_synchro()
920 void set_hk_lfr_time_not_synchro()
921 {
921 {
922 static unsigned char synchroLost = 1;
922 static unsigned char synchroLost = 1;
923 int synchronizationBit;
923 int synchronizationBit;
924
924
925 // get the synchronization bit
925 // get the synchronization bit
926 synchronizationBit =
926 synchronizationBit =
927 (time_management_regs->coarse_time & VAL_LFR_SYNCHRONIZED) >> BIT_SYNCHRONIZATION; // 1000 0000 0000 0000
927 (time_management_regs->coarse_time & VAL_LFR_SYNCHRONIZED) >> BIT_SYNCHRONIZATION; // 1000 0000 0000 0000
928
928
929 switch (synchronizationBit)
929 switch (synchronizationBit)
930 {
930 {
931 case 0:
931 case 0:
932 if (synchroLost == 1)
932 if (synchroLost == 1)
933 {
933 {
934 synchroLost = 0;
934 synchroLost = 0;
935 }
935 }
936 break;
936 break;
937 case 1:
937 case 1:
938 if (synchroLost == 0 )
938 if (synchroLost == 0 )
939 {
939 {
940 synchroLost = 1;
940 synchroLost = 1;
941 increase_unsigned_char_counter(&housekeeping_packet.hk_lfr_time_not_synchro);
941 increase_unsigned_char_counter(&housekeeping_packet.hk_lfr_time_not_synchro);
942 update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_NOT_SYNCHRO );
942 update_hk_lfr_last_er_fields( RID_LE_LFR_TIME, CODE_NOT_SYNCHRO );
943 }
943 }
944 break;
944 break;
945 default:
945 default:
946 PRINTF1("in hk_lfr_time_not_synchro *** unexpected value for synchronizationBit = %d\n", synchronizationBit);
946 PRINTF1("in hk_lfr_time_not_synchro *** unexpected value for synchronizationBit = %d\n", synchronizationBit);
947 break;
947 break;
948 }
948 }
949
949
950 }
950 }
951
951
952 void set_hk_lfr_ahb_correctable() // CRITICITY L
952 void set_hk_lfr_ahb_correctable() // CRITICITY L
953 {
953 {
954 /** This function builds the error counter hk_lfr_ahb_correctable using the statistics provided
954 /** This function builds the error counter hk_lfr_ahb_correctable using the statistics provided
955 * by the Cache Control Register (ASI 2, offset 0) and in the Register Protection Control Register (ASR16) on the
955 * by the Cache Control Register (ASI 2, offset 0) and in the Register Protection Control Register (ASR16) on the
956 * detected errors in the cache, in the integer unit and in the floating point unit.
956 * detected errors in the cache, in the integer unit and in the floating point unit.
957 *
957 *
958 * @param void
958 * @param void
959 *
959 *
960 * @return void
960 * @return void
961 *
961 *
962 * All errors are summed to set the value of the hk_lfr_ahb_correctable counter.
962 * All errors are summed to set the value of the hk_lfr_ahb_correctable counter.
963 *
963 *
964 */
964 */
965
965
966 unsigned int ahb_correctable;
966 unsigned int ahb_correctable;
967 unsigned int instructionErrorCounter;
967 unsigned int instructionErrorCounter;
968 unsigned int dataErrorCounter;
968 unsigned int dataErrorCounter;
969 unsigned int fprfErrorCounter;
969 unsigned int fprfErrorCounter;
970 unsigned int iurfErrorCounter;
970 unsigned int iurfErrorCounter;
971
971
972 instructionErrorCounter = 0;
972 instructionErrorCounter = 0;
973 dataErrorCounter = 0;
973 dataErrorCounter = 0;
974 fprfErrorCounter = 0;
974 fprfErrorCounter = 0;
975 iurfErrorCounter = 0;
975 iurfErrorCounter = 0;
976
976
977 CCR_getInstructionAndDataErrorCounters( &instructionErrorCounter, &dataErrorCounter);
977 CCR_getInstructionAndDataErrorCounters( &instructionErrorCounter, &dataErrorCounter);
978 ASR16_get_FPRF_IURF_ErrorCounters( &fprfErrorCounter, &iurfErrorCounter);
978 ASR16_get_FPRF_IURF_ErrorCounters( &fprfErrorCounter, &iurfErrorCounter);
979
979
980 ahb_correctable = instructionErrorCounter
980 ahb_correctable = instructionErrorCounter
981 + dataErrorCounter
981 + dataErrorCounter
982 + fprfErrorCounter
982 + fprfErrorCounter
983 + iurfErrorCounter
983 + iurfErrorCounter
984 + housekeeping_packet.hk_lfr_ahb_correctable;
984 + housekeeping_packet.hk_lfr_ahb_correctable;
985
985
986 housekeeping_packet.hk_lfr_ahb_correctable = (unsigned char) (ahb_correctable & INT8_ALL_F); // [1111 1111]
986 housekeeping_packet.hk_lfr_ahb_correctable = (unsigned char) (ahb_correctable & INT8_ALL_F); // [1111 1111]
987
987
988 }
988 }
General Comments 0
You need to be logged in to leave comments. Login now