##// END OF EJS Templates
Bug 803 Tr_BoucleSortie...
paul -
r319:9f779b655c52 R3_plus draft
parent child
Show More
@@ -1,993 +1,997
1 /** General usage functions and RTEMS tasks.
1 /** General usage functions and RTEMS tasks.
2 *
2 *
3 * @file
3 * @file
4 * @author P. LEROY
4 * @author P. LEROY
5 *
5 *
6 */
6 */
7
7
8 #include "fsw_misc.h"
8 #include "fsw_misc.h"
9
9
10 void timer_configure(unsigned char timer, unsigned int clock_divider,
10 void timer_configure(unsigned char timer, unsigned int clock_divider,
11 unsigned char interrupt_level, rtems_isr (*timer_isr)() )
11 unsigned char interrupt_level, rtems_isr (*timer_isr)() )
12 {
12 {
13 /** This function configures a GPTIMER timer instantiated in the VHDL design.
13 /** This function configures a GPTIMER timer instantiated in the VHDL design.
14 *
14 *
15 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
15 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
16 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
16 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
17 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
17 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
18 * @param interrupt_level is the interrupt level that the timer drives.
18 * @param interrupt_level is the interrupt level that the timer drives.
19 * @param timer_isr is the interrupt subroutine that will be attached to the IRQ driven by the timer.
19 * @param timer_isr is the interrupt subroutine that will be attached to the IRQ driven by the timer.
20 *
20 *
21 * Interrupt levels are described in the SPARC documentation sparcv8.pdf p.76
21 * Interrupt levels are described in the SPARC documentation sparcv8.pdf p.76
22 *
22 *
23 */
23 */
24
24
25 rtems_status_code status;
25 rtems_status_code status;
26 rtems_isr_entry old_isr_handler;
26 rtems_isr_entry old_isr_handler;
27
27
28 gptimer_regs->timer[timer].ctrl = INIT_CHAR; // reset the control register
28 gptimer_regs->timer[timer].ctrl = INIT_CHAR; // reset the control register
29
29
30 status = rtems_interrupt_catch( timer_isr, interrupt_level, &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels
30 status = rtems_interrupt_catch( timer_isr, interrupt_level, &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels
31 if (status!=RTEMS_SUCCESSFUL)
31 if (status!=RTEMS_SUCCESSFUL)
32 {
32 {
33 PRINTF("in configure_timer *** ERR rtems_interrupt_catch\n")
33 PRINTF("in configure_timer *** ERR rtems_interrupt_catch\n")
34 }
34 }
35
35
36 timer_set_clock_divider( timer, clock_divider);
36 timer_set_clock_divider( timer, clock_divider);
37 }
37 }
38
38
39 void timer_start(unsigned char timer)
39 void timer_start(unsigned char timer)
40 {
40 {
41 /** This function starts a GPTIMER timer.
41 /** This function starts a GPTIMER timer.
42 *
42 *
43 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
43 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
44 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
44 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
45 *
45 *
46 */
46 */
47
47
48 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_CLEAR_IRQ;
48 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_CLEAR_IRQ;
49 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_LD;
49 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_LD;
50 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_EN;
50 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_EN;
51 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_RS;
51 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_RS;
52 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_IE;
52 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_IE;
53 }
53 }
54
54
55 void timer_stop(unsigned char timer)
55 void timer_stop(unsigned char timer)
56 {
56 {
57 /** This function stops a GPTIMER timer.
57 /** This function stops a GPTIMER timer.
58 *
58 *
59 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
59 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
60 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
60 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
61 *
61 *
62 */
62 */
63
63
64 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & GPTIMER_EN_MASK;
64 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & GPTIMER_EN_MASK;
65 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & GPTIMER_IE_MASK;
65 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & GPTIMER_IE_MASK;
66 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_CLEAR_IRQ;
66 gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | GPTIMER_CLEAR_IRQ;
67 }
67 }
68
68
69 void timer_set_clock_divider(unsigned char timer, unsigned int clock_divider)
69 void timer_set_clock_divider(unsigned char timer, unsigned int clock_divider)
70 {
70 {
71 /** This function sets the clock divider of a GPTIMER timer.
71 /** This function sets the clock divider of a GPTIMER timer.
72 *
72 *
73 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
73 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
74 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
74 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
75 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
75 * @param clock_divider is the divider of the 1 MHz clock that will be configured.
76 *
76 *
77 */
77 */
78
78
79 gptimer_regs->timer[timer].reload = clock_divider; // base clock frequency is 1 MHz
79 gptimer_regs->timer[timer].reload = clock_divider; // base clock frequency is 1 MHz
80 }
80 }
81
81
82 // WATCHDOG
82 // WATCHDOG
83
83
84 rtems_isr watchdog_isr( rtems_vector_number vector )
84 rtems_isr watchdog_isr( rtems_vector_number vector )
85 {
85 {
86 rtems_status_code status_code;
86 rtems_status_code status_code;
87
87
88 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_12 );
88 status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_12 );
89
89
90 PRINTF("watchdog_isr *** this is the end, exit(0)\n");
90 PRINTF("watchdog_isr *** this is the end, exit(0)\n");
91
91
92 exit(0);
92 exit(0);
93 }
93 }
94
94
95 void watchdog_configure(void)
95 void watchdog_configure(void)
96 {
96 {
97 /** This function configure the watchdog.
97 /** This function configure the watchdog.
98 *
98 *
99 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
99 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
100 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
100 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
101 *
101 *
102 * The watchdog is a timer provided by the GPTIMER IP core of the GRLIB.
102 * The watchdog is a timer provided by the GPTIMER IP core of the GRLIB.
103 *
103 *
104 */
104 */
105
105
106 LEON_Mask_interrupt( IRQ_GPTIMER_WATCHDOG ); // mask gptimer/watchdog interrupt during configuration
106 LEON_Mask_interrupt( IRQ_GPTIMER_WATCHDOG ); // mask gptimer/watchdog interrupt during configuration
107
107
108 timer_configure( TIMER_WATCHDOG, CLKDIV_WATCHDOG, IRQ_SPARC_GPTIMER_WATCHDOG, watchdog_isr );
108 timer_configure( TIMER_WATCHDOG, CLKDIV_WATCHDOG, IRQ_SPARC_GPTIMER_WATCHDOG, watchdog_isr );
109
109
110 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG ); // clear gptimer/watchdog interrupt
110 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG ); // clear gptimer/watchdog interrupt
111 }
111 }
112
112
113 void watchdog_stop(void)
113 void watchdog_stop(void)
114 {
114 {
115 LEON_Mask_interrupt( IRQ_GPTIMER_WATCHDOG ); // mask gptimer/watchdog interrupt line
115 LEON_Mask_interrupt( IRQ_GPTIMER_WATCHDOG ); // mask gptimer/watchdog interrupt line
116 timer_stop( TIMER_WATCHDOG );
116 timer_stop( TIMER_WATCHDOG );
117 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG ); // clear gptimer/watchdog interrupt
117 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG ); // clear gptimer/watchdog interrupt
118 }
118 }
119
119
120 void watchdog_reload(void)
120 void watchdog_reload(void)
121 {
121 {
122 /** This function reloads the watchdog timer counter with the timer reload value.
122 /** This function reloads the watchdog timer counter with the timer reload value.
123 *
123 *
124 * @param void
124 * @param void
125 *
125 *
126 * @return void
126 * @return void
127 *
127 *
128 */
128 */
129
129
130 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_LD;
130 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_LD;
131 }
131 }
132
132
133 void watchdog_start(void)
133 void watchdog_start(void)
134 {
134 {
135 /** This function starts the watchdog timer.
135 /** This function starts the watchdog timer.
136 *
136 *
137 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
137 * @param gptimer_regs points to the APB registers of the GPTIMER IP core.
138 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
138 * @param timer is the number of the timer in the IP core (several timers can be instantiated).
139 *
139 *
140 */
140 */
141
141
142 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG );
142 LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG );
143
143
144 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_CLEAR_IRQ;
144 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_CLEAR_IRQ;
145 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_LD;
145 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_LD;
146 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_EN;
146 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_EN;
147 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_IE;
147 gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | GPTIMER_IE;
148
148
149 LEON_Unmask_interrupt( IRQ_GPTIMER_WATCHDOG );
149 LEON_Unmask_interrupt( IRQ_GPTIMER_WATCHDOG );
150
150
151 }
151 }
152
152
153 int enable_apbuart_transmitter( void ) // set the bit 1, TE Transmitter Enable to 1 in the APBUART control register
153 int enable_apbuart_transmitter( void ) // set the bit 1, TE Transmitter Enable to 1 in the APBUART control register
154 {
154 {
155 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART;
155 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART;
156
156
157 apbuart_regs->ctrl = APBUART_CTRL_REG_MASK_TE;
157 apbuart_regs->ctrl = APBUART_CTRL_REG_MASK_TE;
158
158
159 return 0;
159 return 0;
160 }
160 }
161
161
162 void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value)
162 void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value)
163 {
163 {
164 /** This function sets the scaler reload register of the apbuart module
164 /** This function sets the scaler reload register of the apbuart module
165 *
165 *
166 * @param regs is the address of the apbuart registers in memory
166 * @param regs is the address of the apbuart registers in memory
167 * @param value is the value that will be stored in the scaler register
167 * @param value is the value that will be stored in the scaler register
168 *
168 *
169 * The value shall be set by the software to get data on the serial interface.
169 * The value shall be set by the software to get data on the serial interface.
170 *
170 *
171 */
171 */
172
172
173 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) regs;
173 struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) regs;
174
174
175 apbuart_regs->scaler = value;
175 apbuart_regs->scaler = value;
176
176
177 BOOT_PRINTF1("OK *** apbuart port scaler reload register set to 0x%x\n", value)
177 BOOT_PRINTF1("OK *** apbuart port scaler reload register set to 0x%x\n", value)
178 }
178 }
179
179
180 //************
180 //************
181 // RTEMS TASKS
181 // RTEMS TASKS
182
182
183 rtems_task load_task(rtems_task_argument argument)
183 rtems_task load_task(rtems_task_argument argument)
184 {
184 {
185 BOOT_PRINTF("in LOAD *** \n")
185 BOOT_PRINTF("in LOAD *** \n")
186
186
187 rtems_status_code status;
187 rtems_status_code status;
188 unsigned int i;
188 unsigned int i;
189 unsigned int j;
189 unsigned int j;
190 rtems_name name_watchdog_rate_monotonic; // name of the watchdog rate monotonic
190 rtems_name name_watchdog_rate_monotonic; // name of the watchdog rate monotonic
191 rtems_id watchdog_period_id; // id of the watchdog rate monotonic period
191 rtems_id watchdog_period_id; // id of the watchdog rate monotonic period
192
192
193 name_watchdog_rate_monotonic = rtems_build_name( 'L', 'O', 'A', 'D' );
193 name_watchdog_rate_monotonic = rtems_build_name( 'L', 'O', 'A', 'D' );
194
194
195 status = rtems_rate_monotonic_create( name_watchdog_rate_monotonic, &watchdog_period_id );
195 status = rtems_rate_monotonic_create( name_watchdog_rate_monotonic, &watchdog_period_id );
196 if( status != RTEMS_SUCCESSFUL ) {
196 if( status != RTEMS_SUCCESSFUL ) {
197 PRINTF1( "in LOAD *** rtems_rate_monotonic_create failed with status of %d\n", status )
197 PRINTF1( "in LOAD *** rtems_rate_monotonic_create failed with status of %d\n", status )
198 }
198 }
199
199
200 i = 0;
200 i = 0;
201 j = 0;
201 j = 0;
202
202
203 watchdog_configure();
203 watchdog_configure();
204
204
205 watchdog_start();
205 watchdog_start();
206
206
207 set_sy_lfr_watchdog_enabled( true );
207 set_sy_lfr_watchdog_enabled( true );
208
208
209 while(1){
209 while(1){
210 status = rtems_rate_monotonic_period( watchdog_period_id, WATCHDOG_PERIOD );
210 status = rtems_rate_monotonic_period( watchdog_period_id, WATCHDOG_PERIOD );
211 watchdog_reload();
211 watchdog_reload();
212 i = i + 1;
212 i = i + 1;
213 if ( i == WATCHDOG_LOOP_PRINTF )
213 if ( i == WATCHDOG_LOOP_PRINTF )
214 {
214 {
215 i = 0;
215 i = 0;
216 j = j + 1;
216 j = j + 1;
217 PRINTF1("%d\n", j)
217 PRINTF1("%d\n", j)
218 }
218 }
219 #ifdef DEBUG_WATCHDOG
219 #ifdef DEBUG_WATCHDOG
220 if (j == WATCHDOG_LOOP_DEBUG )
220 if (j == WATCHDOG_LOOP_DEBUG )
221 {
221 {
222 status = rtems_task_delete(RTEMS_SELF);
222 status = rtems_task_delete(RTEMS_SELF);
223 }
223 }
224 #endif
224 #endif
225 }
225 }
226 }
226 }
227
227
228 rtems_task hous_task(rtems_task_argument argument)
228 rtems_task hous_task(rtems_task_argument argument)
229 {
229 {
230 rtems_status_code status;
230 rtems_status_code status;
231 rtems_status_code spare_status;
231 rtems_status_code spare_status;
232 rtems_id queue_id;
232 rtems_id queue_id;
233 rtems_rate_monotonic_period_status period_status;
233 rtems_rate_monotonic_period_status period_status;
234 bool isSynchronized;
235
236 isSynchronized = false;
234
237
235 status = get_message_queue_id_send( &queue_id );
238 status = get_message_queue_id_send( &queue_id );
236 if (status != RTEMS_SUCCESSFUL)
239 if (status != RTEMS_SUCCESSFUL)
237 {
240 {
238 PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status)
241 PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status)
239 }
242 }
240
243
241 BOOT_PRINTF("in HOUS ***\n");
244 BOOT_PRINTF("in HOUS ***\n");
242
245
243 if (rtems_rate_monotonic_ident( name_hk_rate_monotonic, &HK_id) != RTEMS_SUCCESSFUL) {
246 if (rtems_rate_monotonic_ident( name_hk_rate_monotonic, &HK_id) != RTEMS_SUCCESSFUL) {
244 status = rtems_rate_monotonic_create( name_hk_rate_monotonic, &HK_id );
247 status = rtems_rate_monotonic_create( name_hk_rate_monotonic, &HK_id );
245 if( status != RTEMS_SUCCESSFUL ) {
248 if( status != RTEMS_SUCCESSFUL ) {
246 PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status );
249 PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status );
247 }
250 }
248 }
251 }
249
252
250 status = rtems_rate_monotonic_cancel(HK_id);
253 status = rtems_rate_monotonic_cancel(HK_id);
251 if( status != RTEMS_SUCCESSFUL ) {
254 if( status != RTEMS_SUCCESSFUL ) {
252 PRINTF1( "ERR *** in HOUS *** rtems_rate_monotonic_cancel(HK_id) ***code: %d\n", status );
255 PRINTF1( "ERR *** in HOUS *** rtems_rate_monotonic_cancel(HK_id) ***code: %d\n", status );
253 }
256 }
254 else {
257 else {
255 DEBUG_PRINTF("OK *** in HOUS *** rtems_rate_monotonic_cancel(HK_id)\n");
258 DEBUG_PRINTF("OK *** in HOUS *** rtems_rate_monotonic_cancel(HK_id)\n");
256 }
259 }
257
260
258 // startup phase
261 // startup phase
259 status = rtems_rate_monotonic_period( HK_id, SY_LFR_TIME_SYN_TIMEOUT_in_ticks );
262 status = rtems_rate_monotonic_period( HK_id, SY_LFR_TIME_SYN_TIMEOUT_in_ticks );
260 status = rtems_rate_monotonic_get_status( HK_id, &period_status );
263 status = rtems_rate_monotonic_get_status( HK_id, &period_status );
261 DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state)
264 DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state)
262 while(period_status.state != RATE_MONOTONIC_EXPIRED ) // after SY_LFR_TIME_SYN_TIMEOUT ms, starts HK anyway
265 while( (period_status.state != RATE_MONOTONIC_EXPIRED)
266 && (isSynchronized == false) ) // after SY_LFR_TIME_SYN_TIMEOUT ms, starts HK anyway
263 {
267 {
264 if ((time_management_regs->coarse_time & VAL_LFR_SYNCHRONIZED) == INT32_ALL_0) // check time synchronization
268 if ((time_management_regs->coarse_time & VAL_LFR_SYNCHRONIZED) == INT32_ALL_0) // check time synchronization
265 {
269 {
266 break; // break if LFR is synchronized
270 isSynchronized = true;
267 }
271 }
268 else
272 else
269 {
273 {
270 status = rtems_rate_monotonic_get_status( HK_id, &period_status );
274 status = rtems_rate_monotonic_get_status( HK_id, &period_status );
271
275
272 status = rtems_task_wake_after( HK_SYNC_WAIT ); // wait HK_SYNCH_WAIT 100 ms = 10 * 10 ms
276 status = rtems_task_wake_after( HK_SYNC_WAIT ); // wait HK_SYNCH_WAIT 100 ms = 10 * 10 ms
273 }
277 }
274 }
278 }
275 status = rtems_rate_monotonic_cancel(HK_id);
279 status = rtems_rate_monotonic_cancel(HK_id);
276 DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state)
280 DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state)
277
281
278 set_hk_lfr_reset_cause( POWER_ON );
282 set_hk_lfr_reset_cause( POWER_ON );
279
283
280 while(1){ // launch the rate monotonic task
284 while(1){ // launch the rate monotonic task
281 status = rtems_rate_monotonic_period( HK_id, HK_PERIOD );
285 status = rtems_rate_monotonic_period( HK_id, HK_PERIOD );
282 if ( status != RTEMS_SUCCESSFUL ) {
286 if ( status != RTEMS_SUCCESSFUL ) {
283 PRINTF1( "in HOUS *** ERR period: %d\n", status);
287 PRINTF1( "in HOUS *** ERR period: %d\n", status);
284 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_6 );
288 spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_6 );
285 }
289 }
286 else {
290 else {
287 housekeeping_packet.packetSequenceControl[BYTE_0] = (unsigned char) (sequenceCounterHK >> SHIFT_1_BYTE);
291 housekeeping_packet.packetSequenceControl[BYTE_0] = (unsigned char) (sequenceCounterHK >> SHIFT_1_BYTE);
288 housekeeping_packet.packetSequenceControl[BYTE_1] = (unsigned char) (sequenceCounterHK );
292 housekeeping_packet.packetSequenceControl[BYTE_1] = (unsigned char) (sequenceCounterHK );
289 increment_seq_counter( &sequenceCounterHK );
293 increment_seq_counter( &sequenceCounterHK );
290
294
291 housekeeping_packet.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
295 housekeeping_packet.time[BYTE_0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES);
292 housekeeping_packet.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
296 housekeeping_packet.time[BYTE_1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES);
293 housekeeping_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
297 housekeeping_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE);
294 housekeeping_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
298 housekeeping_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time);
295 housekeeping_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
299 housekeeping_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE);
296 housekeeping_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
300 housekeeping_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time);
297
301
298 spacewire_update_hk_lfr_link_state( &housekeeping_packet.lfr_status_word[0] );
302 spacewire_update_hk_lfr_link_state( &housekeeping_packet.lfr_status_word[0] );
299
303
300 spacewire_read_statistics();
304 spacewire_read_statistics();
301
305
302 update_hk_with_grspw_stats();
306 update_hk_with_grspw_stats();
303
307
304 set_hk_lfr_time_not_synchro();
308 set_hk_lfr_time_not_synchro();
305
309
306 housekeeping_packet.hk_lfr_q_sd_fifo_size_max = hk_lfr_q_sd_fifo_size_max;
310 housekeeping_packet.hk_lfr_q_sd_fifo_size_max = hk_lfr_q_sd_fifo_size_max;
307 housekeeping_packet.hk_lfr_q_rv_fifo_size_max = hk_lfr_q_rv_fifo_size_max;
311 housekeeping_packet.hk_lfr_q_rv_fifo_size_max = hk_lfr_q_rv_fifo_size_max;
308 housekeeping_packet.hk_lfr_q_p0_fifo_size_max = hk_lfr_q_p0_fifo_size_max;
312 housekeeping_packet.hk_lfr_q_p0_fifo_size_max = hk_lfr_q_p0_fifo_size_max;
309 housekeeping_packet.hk_lfr_q_p1_fifo_size_max = hk_lfr_q_p1_fifo_size_max;
313 housekeeping_packet.hk_lfr_q_p1_fifo_size_max = hk_lfr_q_p1_fifo_size_max;
310 housekeeping_packet.hk_lfr_q_p2_fifo_size_max = hk_lfr_q_p2_fifo_size_max;
314 housekeeping_packet.hk_lfr_q_p2_fifo_size_max = hk_lfr_q_p2_fifo_size_max;
311
315
312 housekeeping_packet.sy_lfr_common_parameters_spare = parameter_dump_packet.sy_lfr_common_parameters_spare;
316 housekeeping_packet.sy_lfr_common_parameters_spare = parameter_dump_packet.sy_lfr_common_parameters_spare;
313 housekeeping_packet.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
317 housekeeping_packet.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters;
314 get_temperatures( housekeeping_packet.hk_lfr_temp_scm );
318 get_temperatures( housekeeping_packet.hk_lfr_temp_scm );
315 get_v_e1_e2_f3( housekeeping_packet.hk_lfr_sc_v_f3 );
319 get_v_e1_e2_f3( housekeeping_packet.hk_lfr_sc_v_f3 );
316 get_cpu_load( (unsigned char *) &housekeeping_packet.hk_lfr_cpu_load );
320 get_cpu_load( (unsigned char *) &housekeeping_packet.hk_lfr_cpu_load );
317
321
318 hk_lfr_le_me_he_update();
322 hk_lfr_le_me_he_update();
319
323
320 housekeeping_packet.hk_lfr_sc_rw_f_flags = cp_rpw_sc_rw_f_flags;
324 housekeeping_packet.hk_lfr_sc_rw_f_flags = cp_rpw_sc_rw_f_flags;
321
325
322 // SEND PACKET
326 // SEND PACKET
323 status = rtems_message_queue_send( queue_id, &housekeeping_packet,
327 status = rtems_message_queue_send( queue_id, &housekeeping_packet,
324 PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
328 PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES);
325 if (status != RTEMS_SUCCESSFUL) {
329 if (status != RTEMS_SUCCESSFUL) {
326 PRINTF1("in HOUS *** ERR send: %d\n", status)
330 PRINTF1("in HOUS *** ERR send: %d\n", status)
327 }
331 }
328 }
332 }
329 }
333 }
330
334
331 PRINTF("in HOUS *** deleting task\n")
335 PRINTF("in HOUS *** deleting task\n")
332
336
333 status = rtems_task_delete( RTEMS_SELF ); // should not return
337 status = rtems_task_delete( RTEMS_SELF ); // should not return
334
338
335 return;
339 return;
336 }
340 }
337
341
338 rtems_task avgv_task(rtems_task_argument argument)
342 rtems_task avgv_task(rtems_task_argument argument)
339 {
343 {
340 #define MOVING_AVERAGE 16
344 #define MOVING_AVERAGE 16
341 rtems_status_code status;
345 rtems_status_code status;
342 unsigned int v[MOVING_AVERAGE];
346 unsigned int v[MOVING_AVERAGE];
343 unsigned int e1[MOVING_AVERAGE];
347 unsigned int e1[MOVING_AVERAGE];
344 unsigned int e2[MOVING_AVERAGE];
348 unsigned int e2[MOVING_AVERAGE];
345 float average_v;
349 float average_v;
346 float average_e1;
350 float average_e1;
347 float average_e2;
351 float average_e2;
348 unsigned char k;
352 unsigned char k;
349 unsigned char indexOfOldValue;
353 unsigned char indexOfOldValue;
350
354
351 BOOT_PRINTF("in AVGV ***\n");
355 BOOT_PRINTF("in AVGV ***\n");
352
356
353 if (rtems_rate_monotonic_ident( name_avgv_rate_monotonic, &HK_id) != RTEMS_SUCCESSFUL) {
357 if (rtems_rate_monotonic_ident( name_avgv_rate_monotonic, &HK_id) != RTEMS_SUCCESSFUL) {
354 status = rtems_rate_monotonic_create( name_avgv_rate_monotonic, &AVGV_id );
358 status = rtems_rate_monotonic_create( name_avgv_rate_monotonic, &AVGV_id );
355 if( status != RTEMS_SUCCESSFUL ) {
359 if( status != RTEMS_SUCCESSFUL ) {
356 PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status );
360 PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status );
357 }
361 }
358 }
362 }
359
363
360 status = rtems_rate_monotonic_cancel(AVGV_id);
364 status = rtems_rate_monotonic_cancel(AVGV_id);
361 if( status != RTEMS_SUCCESSFUL ) {
365 if( status != RTEMS_SUCCESSFUL ) {
362 PRINTF1( "ERR *** in AVGV *** rtems_rate_monotonic_cancel(AVGV_id) ***code: %d\n", status );
366 PRINTF1( "ERR *** in AVGV *** rtems_rate_monotonic_cancel(AVGV_id) ***code: %d\n", status );
363 }
367 }
364 else {
368 else {
365 DEBUG_PRINTF("OK *** in AVGV *** rtems_rate_monotonic_cancel(AVGV_id)\n");
369 DEBUG_PRINTF("OK *** in AVGV *** rtems_rate_monotonic_cancel(AVGV_id)\n");
366 }
370 }
367
371
368 // initialize values
372 // initialize values
369 k = 0;
373 k = 0;
370 indexOfOldValue = MOVING_AVERAGE - 1;
374 indexOfOldValue = MOVING_AVERAGE - 1;
371 for (k = 0; k < MOVING_AVERAGE; k++)
375 for (k = 0; k < MOVING_AVERAGE; k++)
372 {
376 {
373 v[k] = 0;
377 v[k] = 0;
374 e1[k] = 0;
378 e1[k] = 0;
375 e2[k] = 0;
379 e2[k] = 0;
376 average_v = 0.;
380 average_v = 0.;
377 average_e1 = 0.;
381 average_e1 = 0.;
378 average_e2 = 0.;
382 average_e2 = 0.;
379 }
383 }
380
384
381 k = 0;
385 k = 0;
382
386
383 while(1){ // launch the rate monotonic task
387 while(1){ // launch the rate monotonic task
384 status = rtems_rate_monotonic_period( AVGV_id, AVGV_PERIOD );
388 status = rtems_rate_monotonic_period( AVGV_id, AVGV_PERIOD );
385 if ( status != RTEMS_SUCCESSFUL ) {
389 if ( status != RTEMS_SUCCESSFUL ) {
386 PRINTF1( "in AVGV *** ERR period: %d\n", status);
390 PRINTF1( "in AVGV *** ERR period: %d\n", status);
387 }
391 }
388 else {
392 else {
389 // store new value in buffer
393 // store new value in buffer
390 v[k] = waveform_picker_regs->v;
394 v[k] = waveform_picker_regs->v;
391 e1[k] = waveform_picker_regs->e1;
395 e1[k] = waveform_picker_regs->e1;
392 e2[k] = waveform_picker_regs->e2;
396 e2[k] = waveform_picker_regs->e2;
393 if (k == (MOVING_AVERAGE - 1))
397 if (k == (MOVING_AVERAGE - 1))
394 {
398 {
395 indexOfOldValue = 0;
399 indexOfOldValue = 0;
396 }
400 }
397 else
401 else
398 {
402 {
399 indexOfOldValue = k + 1;
403 indexOfOldValue = k + 1;
400 }
404 }
401 average_v = average_v + v[k] - v[indexOfOldValue];
405 average_v = average_v + v[k] - v[indexOfOldValue];
402 average_e1 = average_e1 + e1[k] - e1[indexOfOldValue];
406 average_e1 = average_e1 + e1[k] - e1[indexOfOldValue];
403 average_e2 = average_e2 + e2[k] - e2[indexOfOldValue];
407 average_e2 = average_e2 + e2[k] - e2[indexOfOldValue];
404 }
408 }
405 if (k == (MOVING_AVERAGE-1))
409 if (k == (MOVING_AVERAGE-1))
406 {
410 {
407 k = 0;
411 k = 0;
408 printf("tick\n");
412 printf("tick\n");
409 }
413 }
410 else
414 else
411 {
415 {
412 k++;
416 k++;
413 }
417 }
414 }
418 }
415
419
416 PRINTF("in AVGV *** deleting task\n")
420 PRINTF("in AVGV *** deleting task\n")
417
421
418 status = rtems_task_delete( RTEMS_SELF ); // should not return
422 status = rtems_task_delete( RTEMS_SELF ); // should not return
419
423
420 return;
424 return;
421 }
425 }
422
426
423 rtems_task dumb_task( rtems_task_argument unused )
427 rtems_task dumb_task( rtems_task_argument unused )
424 {
428 {
425 /** This RTEMS taks is used to print messages without affecting the general behaviour of the software.
429 /** This RTEMS taks is used to print messages without affecting the general behaviour of the software.
426 *
430 *
427 * @param unused is the starting argument of the RTEMS task
431 * @param unused is the starting argument of the RTEMS task
428 *
432 *
429 * The DUMB taks waits for RTEMS events and print messages depending on the incoming events.
433 * The DUMB taks waits for RTEMS events and print messages depending on the incoming events.
430 *
434 *
431 */
435 */
432
436
433 unsigned int i;
437 unsigned int i;
434 unsigned int intEventOut;
438 unsigned int intEventOut;
435 unsigned int coarse_time = 0;
439 unsigned int coarse_time = 0;
436 unsigned int fine_time = 0;
440 unsigned int fine_time = 0;
437 rtems_event_set event_out;
441 rtems_event_set event_out;
438
442
439 char *DumbMessages[DUMB_MESSAGE_NB] = {DUMB_MESSAGE_0, // RTEMS_EVENT_0
443 char *DumbMessages[DUMB_MESSAGE_NB] = {DUMB_MESSAGE_0, // RTEMS_EVENT_0
440 DUMB_MESSAGE_1, // RTEMS_EVENT_1
444 DUMB_MESSAGE_1, // RTEMS_EVENT_1
441 DUMB_MESSAGE_2, // RTEMS_EVENT_2
445 DUMB_MESSAGE_2, // RTEMS_EVENT_2
442 DUMB_MESSAGE_3, // RTEMS_EVENT_3
446 DUMB_MESSAGE_3, // RTEMS_EVENT_3
443 DUMB_MESSAGE_4, // RTEMS_EVENT_4
447 DUMB_MESSAGE_4, // RTEMS_EVENT_4
444 DUMB_MESSAGE_5, // RTEMS_EVENT_5
448 DUMB_MESSAGE_5, // RTEMS_EVENT_5
445 DUMB_MESSAGE_6, // RTEMS_EVENT_6
449 DUMB_MESSAGE_6, // RTEMS_EVENT_6
446 DUMB_MESSAGE_7, // RTEMS_EVENT_7
450 DUMB_MESSAGE_7, // RTEMS_EVENT_7
447 DUMB_MESSAGE_8, // RTEMS_EVENT_8
451 DUMB_MESSAGE_8, // RTEMS_EVENT_8
448 DUMB_MESSAGE_9, // RTEMS_EVENT_9
452 DUMB_MESSAGE_9, // RTEMS_EVENT_9
449 DUMB_MESSAGE_10, // RTEMS_EVENT_10
453 DUMB_MESSAGE_10, // RTEMS_EVENT_10
450 DUMB_MESSAGE_11, // RTEMS_EVENT_11
454 DUMB_MESSAGE_11, // RTEMS_EVENT_11
451 DUMB_MESSAGE_12, // RTEMS_EVENT_12
455 DUMB_MESSAGE_12, // RTEMS_EVENT_12
452 DUMB_MESSAGE_13, // RTEMS_EVENT_13
456 DUMB_MESSAGE_13, // RTEMS_EVENT_13
453 DUMB_MESSAGE_14 // RTEMS_EVENT_14
457 DUMB_MESSAGE_14 // RTEMS_EVENT_14
454 };
458 };
455
459
456 BOOT_PRINTF("in DUMB *** \n")
460 BOOT_PRINTF("in DUMB *** \n")
457
461
458 while(1){
462 while(1){
459 rtems_event_receive(RTEMS_EVENT_0 | RTEMS_EVENT_1 | RTEMS_EVENT_2 | RTEMS_EVENT_3
463 rtems_event_receive(RTEMS_EVENT_0 | RTEMS_EVENT_1 | RTEMS_EVENT_2 | RTEMS_EVENT_3
460 | RTEMS_EVENT_4 | RTEMS_EVENT_5 | RTEMS_EVENT_6 | RTEMS_EVENT_7
464 | RTEMS_EVENT_4 | RTEMS_EVENT_5 | RTEMS_EVENT_6 | RTEMS_EVENT_7
461 | RTEMS_EVENT_8 | RTEMS_EVENT_9 | RTEMS_EVENT_12 | RTEMS_EVENT_13
465 | RTEMS_EVENT_8 | RTEMS_EVENT_9 | RTEMS_EVENT_12 | RTEMS_EVENT_13
462 | RTEMS_EVENT_14,
466 | RTEMS_EVENT_14,
463 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT
467 RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT
464 intEventOut = (unsigned int) event_out;
468 intEventOut = (unsigned int) event_out;
465 for ( i=0; i<NB_RTEMS_EVENTS; i++)
469 for ( i=0; i<NB_RTEMS_EVENTS; i++)
466 {
470 {
467 if ( ((intEventOut >> i) & 1) != 0)
471 if ( ((intEventOut >> i) & 1) != 0)
468 {
472 {
469 coarse_time = time_management_regs->coarse_time;
473 coarse_time = time_management_regs->coarse_time;
470 fine_time = time_management_regs->fine_time;
474 fine_time = time_management_regs->fine_time;
471 if (i==EVENT_12)
475 if (i==EVENT_12)
472 {
476 {
473 PRINTF1("%s\n", DUMB_MESSAGE_12)
477 PRINTF1("%s\n", DUMB_MESSAGE_12)
474 }
478 }
475 if (i==EVENT_13)
479 if (i==EVENT_13)
476 {
480 {
477 PRINTF1("%s\n", DUMB_MESSAGE_13)
481 PRINTF1("%s\n", DUMB_MESSAGE_13)
478 }
482 }
479 if (i==EVENT_14)
483 if (i==EVENT_14)
480 {
484 {
481 PRINTF1("%s\n", DUMB_MESSAGE_1)
485 PRINTF1("%s\n", DUMB_MESSAGE_1)
482 }
486 }
483 }
487 }
484 }
488 }
485 }
489 }
486 }
490 }
487
491
488 //*****************************
492 //*****************************
489 // init housekeeping parameters
493 // init housekeeping parameters
490
494
491 void init_housekeeping_parameters( void )
495 void init_housekeeping_parameters( void )
492 {
496 {
493 /** This function initialize the housekeeping_packet global variable with default values.
497 /** This function initialize the housekeeping_packet global variable with default values.
494 *
498 *
495 */
499 */
496
500
497 unsigned int i = 0;
501 unsigned int i = 0;
498 unsigned char *parameters;
502 unsigned char *parameters;
499 unsigned char sizeOfHK;
503 unsigned char sizeOfHK;
500
504
501 sizeOfHK = sizeof( Packet_TM_LFR_HK_t );
505 sizeOfHK = sizeof( Packet_TM_LFR_HK_t );
502
506
503 parameters = (unsigned char*) &housekeeping_packet;
507 parameters = (unsigned char*) &housekeeping_packet;
504
508
505 for(i = 0; i< sizeOfHK; i++)
509 for(i = 0; i< sizeOfHK; i++)
506 {
510 {
507 parameters[i] = INIT_CHAR;
511 parameters[i] = INIT_CHAR;
508 }
512 }
509
513
510 housekeeping_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
514 housekeeping_packet.targetLogicalAddress = CCSDS_DESTINATION_ID;
511 housekeeping_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
515 housekeeping_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID;
512 housekeeping_packet.reserved = DEFAULT_RESERVED;
516 housekeeping_packet.reserved = DEFAULT_RESERVED;
513 housekeeping_packet.userApplication = CCSDS_USER_APP;
517 housekeeping_packet.userApplication = CCSDS_USER_APP;
514 housekeeping_packet.packetID[0] = (unsigned char) (APID_TM_HK >> SHIFT_1_BYTE);
518 housekeeping_packet.packetID[0] = (unsigned char) (APID_TM_HK >> SHIFT_1_BYTE);
515 housekeeping_packet.packetID[1] = (unsigned char) (APID_TM_HK);
519 housekeeping_packet.packetID[1] = (unsigned char) (APID_TM_HK);
516 housekeeping_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
520 housekeeping_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE;
517 housekeeping_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
521 housekeeping_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT;
518 housekeeping_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> SHIFT_1_BYTE);
522 housekeeping_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> SHIFT_1_BYTE);
519 housekeeping_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK );
523 housekeeping_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK );
520 housekeeping_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
524 housekeeping_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2;
521 housekeeping_packet.serviceType = TM_TYPE_HK;
525 housekeeping_packet.serviceType = TM_TYPE_HK;
522 housekeeping_packet.serviceSubType = TM_SUBTYPE_HK;
526 housekeeping_packet.serviceSubType = TM_SUBTYPE_HK;
523 housekeeping_packet.destinationID = TM_DESTINATION_ID_GROUND;
527 housekeeping_packet.destinationID = TM_DESTINATION_ID_GROUND;
524 housekeeping_packet.sid = SID_HK;
528 housekeeping_packet.sid = SID_HK;
525
529
526 // init status word
530 // init status word
527 housekeeping_packet.lfr_status_word[0] = DEFAULT_STATUS_WORD_BYTE0;
531 housekeeping_packet.lfr_status_word[0] = DEFAULT_STATUS_WORD_BYTE0;
528 housekeeping_packet.lfr_status_word[1] = DEFAULT_STATUS_WORD_BYTE1;
532 housekeeping_packet.lfr_status_word[1] = DEFAULT_STATUS_WORD_BYTE1;
529 // init software version
533 // init software version
530 housekeeping_packet.lfr_sw_version[0] = SW_VERSION_N1;
534 housekeeping_packet.lfr_sw_version[0] = SW_VERSION_N1;
531 housekeeping_packet.lfr_sw_version[1] = SW_VERSION_N2;
535 housekeeping_packet.lfr_sw_version[1] = SW_VERSION_N2;
532 housekeeping_packet.lfr_sw_version[BYTE_2] = SW_VERSION_N3;
536 housekeeping_packet.lfr_sw_version[BYTE_2] = SW_VERSION_N3;
533 housekeeping_packet.lfr_sw_version[BYTE_3] = SW_VERSION_N4;
537 housekeeping_packet.lfr_sw_version[BYTE_3] = SW_VERSION_N4;
534 // init fpga version
538 // init fpga version
535 parameters = (unsigned char *) (REGS_ADDR_VHDL_VERSION);
539 parameters = (unsigned char *) (REGS_ADDR_VHDL_VERSION);
536 housekeeping_packet.lfr_fpga_version[BYTE_0] = parameters[BYTE_1]; // n1
540 housekeeping_packet.lfr_fpga_version[BYTE_0] = parameters[BYTE_1]; // n1
537 housekeeping_packet.lfr_fpga_version[BYTE_1] = parameters[BYTE_2]; // n2
541 housekeeping_packet.lfr_fpga_version[BYTE_1] = parameters[BYTE_2]; // n2
538 housekeeping_packet.lfr_fpga_version[BYTE_2] = parameters[BYTE_3]; // n3
542 housekeeping_packet.lfr_fpga_version[BYTE_2] = parameters[BYTE_3]; // n3
539
543
540 housekeeping_packet.hk_lfr_q_sd_fifo_size = MSG_QUEUE_COUNT_SEND;
544 housekeeping_packet.hk_lfr_q_sd_fifo_size = MSG_QUEUE_COUNT_SEND;
541 housekeeping_packet.hk_lfr_q_rv_fifo_size = MSG_QUEUE_COUNT_RECV;
545 housekeeping_packet.hk_lfr_q_rv_fifo_size = MSG_QUEUE_COUNT_RECV;
542 housekeeping_packet.hk_lfr_q_p0_fifo_size = MSG_QUEUE_COUNT_PRC0;
546 housekeeping_packet.hk_lfr_q_p0_fifo_size = MSG_QUEUE_COUNT_PRC0;
543 housekeeping_packet.hk_lfr_q_p1_fifo_size = MSG_QUEUE_COUNT_PRC1;
547 housekeeping_packet.hk_lfr_q_p1_fifo_size = MSG_QUEUE_COUNT_PRC1;
544 housekeeping_packet.hk_lfr_q_p2_fifo_size = MSG_QUEUE_COUNT_PRC2;
548 housekeeping_packet.hk_lfr_q_p2_fifo_size = MSG_QUEUE_COUNT_PRC2;
545 }
549 }
546
550
547 void increment_seq_counter( unsigned short *packetSequenceControl )
551 void increment_seq_counter( unsigned short *packetSequenceControl )
548 {
552 {
549 /** This function increment the sequence counter passes in argument.
553 /** This function increment the sequence counter passes in argument.
550 *
554 *
551 * The increment does not affect the grouping flag. In case of an overflow, the counter is reset to 0.
555 * The increment does not affect the grouping flag. In case of an overflow, the counter is reset to 0.
552 *
556 *
553 */
557 */
554
558
555 unsigned short segmentation_grouping_flag;
559 unsigned short segmentation_grouping_flag;
556 unsigned short sequence_cnt;
560 unsigned short sequence_cnt;
557
561
558 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << SHIFT_1_BYTE; // keep bits 7 downto 6
562 segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << SHIFT_1_BYTE; // keep bits 7 downto 6
559 sequence_cnt = (*packetSequenceControl) & SEQ_CNT_MASK; // [0011 1111 1111 1111]
563 sequence_cnt = (*packetSequenceControl) & SEQ_CNT_MASK; // [0011 1111 1111 1111]
560
564
561 if ( sequence_cnt < SEQ_CNT_MAX)
565 if ( sequence_cnt < SEQ_CNT_MAX)
562 {
566 {
563 sequence_cnt = sequence_cnt + 1;
567 sequence_cnt = sequence_cnt + 1;
564 }
568 }
565 else
569 else
566 {
570 {
567 sequence_cnt = 0;
571 sequence_cnt = 0;
568 }
572 }
569
573
570 *packetSequenceControl = segmentation_grouping_flag | sequence_cnt ;
574 *packetSequenceControl = segmentation_grouping_flag | sequence_cnt ;
571 }
575 }
572
576
573 void getTime( unsigned char *time)
577 void getTime( unsigned char *time)
574 {
578 {
575 /** This function write the current local time in the time buffer passed in argument.
579 /** This function write the current local time in the time buffer passed in argument.
576 *
580 *
577 */
581 */
578
582
579 time[0] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_3_BYTES);
583 time[0] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_3_BYTES);
580 time[1] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_2_BYTES);
584 time[1] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_2_BYTES);
581 time[2] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_1_BYTE);
585 time[2] = (unsigned char) (time_management_regs->coarse_time>>SHIFT_1_BYTE);
582 time[3] = (unsigned char) (time_management_regs->coarse_time);
586 time[3] = (unsigned char) (time_management_regs->coarse_time);
583 time[4] = (unsigned char) (time_management_regs->fine_time>>SHIFT_1_BYTE);
587 time[4] = (unsigned char) (time_management_regs->fine_time>>SHIFT_1_BYTE);
584 time[5] = (unsigned char) (time_management_regs->fine_time);
588 time[5] = (unsigned char) (time_management_regs->fine_time);
585 }
589 }
586
590
587 unsigned long long int getTimeAsUnsignedLongLongInt( )
591 unsigned long long int getTimeAsUnsignedLongLongInt( )
588 {
592 {
589 /** This function write the current local time in the time buffer passed in argument.
593 /** This function write the current local time in the time buffer passed in argument.
590 *
594 *
591 */
595 */
592 unsigned long long int time;
596 unsigned long long int time;
593
597
594 time = ( (unsigned long long int) (time_management_regs->coarse_time & COARSE_TIME_MASK) << SHIFT_2_BYTES )
598