@@ -1,54 +1,57 | |||||
1 | #ifndef FSW_MISC_H_INCLUDED |
|
1 | #ifndef FSW_MISC_H_INCLUDED | |
2 | #define FSW_MISC_H_INCLUDED |
|
2 | #define FSW_MISC_H_INCLUDED | |
3 |
|
3 | |||
4 | #include <rtems.h> |
|
4 | #include <rtems.h> | |
5 | #include <stdio.h> |
|
5 | #include <stdio.h> | |
6 | #include <grspw.h> |
|
6 | #include <grspw.h> | |
7 | #include <grlib_regs.h> |
|
7 | #include <grlib_regs.h> | |
8 |
|
8 | |||
9 | #include "fsw_params.h" |
|
9 | #include "fsw_params.h" | |
10 | #include "fsw_spacewire.h" |
|
10 | #include "fsw_spacewire.h" | |
11 | #include "lfr_cpu_usage_report.h" |
|
11 | #include "lfr_cpu_usage_report.h" | |
12 |
|
12 | |||
13 | rtems_name name_hk_rate_monotonic; // name of the HK rate monotonic |
|
13 | rtems_name name_hk_rate_monotonic; // name of the HK rate monotonic | |
14 | rtems_id HK_id; // id of the HK rate monotonic period |
|
14 | rtems_id HK_id; // id of the HK rate monotonic period | |
15 |
|
15 | |||
16 | void configure_timer(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider, |
|
16 | void configure_timer(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider, | |
17 | unsigned char interrupt_level, rtems_isr (*timer_isr)() ); |
|
17 | unsigned char interrupt_level, rtems_isr (*timer_isr)() ); | |
18 | void timer_start( gptimer_regs_t *gptimer_regs, unsigned char timer ); |
|
18 | void timer_start( gptimer_regs_t *gptimer_regs, unsigned char timer ); | |
19 | void timer_stop( gptimer_regs_t *gptimer_regs, unsigned char timer ); |
|
19 | void timer_stop( gptimer_regs_t *gptimer_regs, unsigned char timer ); | |
20 | void timer_set_clock_divider(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider); |
|
20 | void timer_set_clock_divider(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider); | |
21 |
|
21 | |||
22 | // SERIAL LINK |
|
22 | // SERIAL LINK | |
23 | int send_console_outputs_on_apbuart_port( void ); |
|
23 | int send_console_outputs_on_apbuart_port( void ); | |
24 | int enable_apbuart_transmitter( void ); |
|
24 | int enable_apbuart_transmitter( void ); | |
25 | void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value); |
|
25 | void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value); | |
26 |
|
26 | |||
27 | // RTEMS TASKS |
|
27 | // RTEMS TASKS | |
28 | rtems_task stat_task( rtems_task_argument argument ); |
|
28 | rtems_task stat_task( rtems_task_argument argument ); | |
29 | rtems_task hous_task( rtems_task_argument argument ); |
|
29 | rtems_task hous_task( rtems_task_argument argument ); | |
30 | rtems_task dumb_task( rtems_task_argument unused ); |
|
30 | rtems_task dumb_task( rtems_task_argument unused ); | |
31 |
|
31 | |||
32 | void init_housekeeping_parameters( void ); |
|
32 | void init_housekeeping_parameters( void ); | |
33 | void increment_seq_counter(unsigned short *packetSequenceControl); |
|
33 | void increment_seq_counter(unsigned short *packetSequenceControl); | |
34 | void getTime( unsigned char *time); |
|
34 | void getTime( unsigned char *time); | |
35 | unsigned long long int getTimeAsUnsignedLongLongInt( ); |
|
35 | unsigned long long int getTimeAsUnsignedLongLongInt( ); | |
36 | void send_dumb_hk( void ); |
|
36 | void send_dumb_hk( void ); | |
37 | void get_temperatures( unsigned char *temperatures ); |
|
37 | void get_temperatures( unsigned char *temperatures ); | |
38 | void get_v_e1_e2_f3( unsigned char *spacecraft_potential ); |
|
38 | void get_v_e1_e2_f3( unsigned char *spacecraft_potential ); | |
39 | void get_cpu_load( unsigned char *resource_statistics ); |
|
39 | void get_cpu_load( unsigned char *resource_statistics ); | |
|
40 | void set_hk_lfr_sc_potential_flag( bool state ); | |||
|
41 | void set_hk_lfr_calib_enable( bool state ); | |||
|
42 | ||||
40 |
|
43 | |||
41 | extern int sched_yield( void ); |
|
44 | extern int sched_yield( void ); | |
42 | extern void rtems_cpu_usage_reset(); |
|
45 | extern void rtems_cpu_usage_reset(); | |
43 | extern ring_node *current_ring_node_f3; |
|
46 | extern ring_node *current_ring_node_f3; | |
44 | extern ring_node *ring_node_to_send_cwf_f3; |
|
47 | extern ring_node *ring_node_to_send_cwf_f3; | |
45 | extern ring_node waveform_ring_f3[]; |
|
48 | extern ring_node waveform_ring_f3[]; | |
46 | extern unsigned short sequenceCounterHK; |
|
49 | extern unsigned short sequenceCounterHK; | |
47 |
|
50 | |||
48 | extern unsigned char hk_lfr_q_sd_fifo_size_max; |
|
51 | extern unsigned char hk_lfr_q_sd_fifo_size_max; | |
49 | extern unsigned char hk_lfr_q_rv_fifo_size_max; |
|
52 | extern unsigned char hk_lfr_q_rv_fifo_size_max; | |
50 | extern unsigned char hk_lfr_q_p0_fifo_size_max; |
|
53 | extern unsigned char hk_lfr_q_p0_fifo_size_max; | |
51 | extern unsigned char hk_lfr_q_p1_fifo_size_max; |
|
54 | extern unsigned char hk_lfr_q_p1_fifo_size_max; | |
52 | extern unsigned char hk_lfr_q_p2_fifo_size_max; |
|
55 | extern unsigned char hk_lfr_q_p2_fifo_size_max; | |
53 |
|
56 | |||
54 | #endif // FSW_MISC_H_INCLUDED |
|
57 | #endif // FSW_MISC_H_INCLUDED |
@@ -1,72 +1,71 | |||||
1 | #ifndef TC_HANDLER_H_INCLUDED |
|
1 | #ifndef TC_HANDLER_H_INCLUDED | |
2 | #define TC_HANDLER_H_INCLUDED |
|
2 | #define TC_HANDLER_H_INCLUDED | |
3 |
|
3 | |||
4 | #include <rtems.h> |
|
4 | #include <rtems.h> | |
5 | #include <leon.h> |
|
5 | #include <leon.h> | |
6 |
|
6 | |||
7 | #include "tc_load_dump_parameters.h" |
|
7 | #include "tc_load_dump_parameters.h" | |
8 | #include "tc_acceptance.h" |
|
8 | #include "tc_acceptance.h" | |
9 | #include "tm_lfr_tc_exe.h" |
|
9 | #include "tm_lfr_tc_exe.h" | |
10 | #include "wf_handler.h" |
|
10 | #include "wf_handler.h" | |
11 | #include "fsw_processing.h" |
|
11 | #include "fsw_processing.h" | |
12 |
|
12 | |||
13 | #include "lfr_cpu_usage_report.h" |
|
13 | #include "lfr_cpu_usage_report.h" | |
14 |
|
14 | |||
15 | //**** |
|
15 | //**** | |
16 | // ISR |
|
16 | // ISR | |
17 | rtems_isr commutation_isr1( rtems_vector_number vector ); |
|
17 | rtems_isr commutation_isr1( rtems_vector_number vector ); | |
18 | rtems_isr commutation_isr2( rtems_vector_number vector ); |
|
18 | rtems_isr commutation_isr2( rtems_vector_number vector ); | |
19 |
|
19 | |||
20 | //*********** |
|
20 | //*********** | |
21 | // RTEMS TASK |
|
21 | // RTEMS TASK | |
22 | rtems_task actn_task( rtems_task_argument unused ); |
|
22 | rtems_task actn_task( rtems_task_argument unused ); | |
23 |
|
23 | |||
24 | //*********** |
|
24 | //*********** | |
25 | // TC ACTIONS |
|
25 | // TC ACTIONS | |
26 | int action_reset( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time ); |
|
26 | int action_reset( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time ); | |
27 | int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id); |
|
27 | int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id); | |
28 | int action_update_info( ccsdsTelecommandPacket_t *TC, rtems_id queue_id ); |
|
28 | int action_update_info( ccsdsTelecommandPacket_t *TC, rtems_id queue_id ); | |
29 | int action_enable_calibration( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time ); |
|
29 | int action_enable_calibration( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time ); | |
30 | int action_disable_calibration( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time ); |
|
30 | int action_disable_calibration( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time ); | |
31 | int action_update_time( ccsdsTelecommandPacket_t *TC); |
|
31 | int action_update_time( ccsdsTelecommandPacket_t *TC); | |
32 |
|
32 | |||
33 | // mode transition |
|
33 | // mode transition | |
34 | int check_mode_value( unsigned char requestedMode ); |
|
34 | int check_mode_value( unsigned char requestedMode ); | |
35 | int check_mode_transition( unsigned char requestedMode ); |
|
35 | int check_mode_transition( unsigned char requestedMode ); | |
36 | int check_transition_date( unsigned int transitionCoarseTime ); |
|
36 | int check_transition_date( unsigned int transitionCoarseTime ); | |
37 | int stop_current_mode( void ); |
|
37 | int stop_current_mode( void ); | |
38 | int enter_mode( unsigned char mode , unsigned int transitionCoarseTime ); |
|
38 | int enter_mode( unsigned char mode , unsigned int transitionCoarseTime ); | |
39 | int restart_science_tasks( unsigned char lfrRequestedMode ); |
|
39 | int restart_science_tasks( unsigned char lfrRequestedMode ); | |
40 | int suspend_science_tasks(); |
|
40 | int suspend_science_tasks(); | |
41 | void launch_waveform_picker( unsigned char mode , unsigned int transitionCoarseTime ); |
|
41 | void launch_waveform_picker( unsigned char mode , unsigned int transitionCoarseTime ); | |
42 | void launch_spectral_matrix( void ); |
|
42 | void launch_spectral_matrix( void ); | |
43 | void launch_spectral_matrix_simu( void ); |
|
43 | void launch_spectral_matrix_simu( void ); | |
44 | void set_sm_irq_onNewMatrix( unsigned char value ); |
|
44 | void set_sm_irq_onNewMatrix( unsigned char value ); | |
45 | void set_sm_irq_onError( unsigned char value ); |
|
45 | void set_sm_irq_onError( unsigned char value ); | |
46 |
|
46 | |||
47 | // other functions |
|
47 | // other functions | |
48 | void updateLFRCurrentMode(); |
|
48 | void updateLFRCurrentMode(); | |
49 | void set_lfr_soft_reset( unsigned char value ); |
|
49 | void set_lfr_soft_reset( unsigned char value ); | |
50 | void reset_lfr( void ); |
|
50 | void reset_lfr( void ); | |
51 | // CALIBRATION |
|
51 | // CALIBRATION | |
52 | void setCalibrationPrescaler( unsigned int prescaler ); |
|
52 | void setCalibrationPrescaler( unsigned int prescaler ); | |
53 | void setCalibrationDivisor( unsigned int divisionFactor ); |
|
53 | void setCalibrationDivisor( unsigned int divisionFactor ); | |
54 | void setCalibrationData( void ); |
|
54 | void setCalibrationData( void ); | |
55 | void setCalibrationReload( bool state); |
|
55 | void setCalibrationReload( bool state); | |
56 | void setCalibrationEnable( bool state ); |
|
56 | void setCalibrationEnable( bool state ); | |
57 | void setCalibrationInterleaved( bool state ); |
|
57 | void setCalibrationInterleaved( bool state ); | |
58 | void setCalibration( bool state ); |
|
58 | void setCalibration( bool state ); | |
59 | void set_hk_lfr_calib_enable( bool state ); |
|
|||
60 | void configureCalibration( bool interleaved ); |
|
59 | void configureCalibration( bool interleaved ); | |
61 | // |
|
60 | // | |
62 | void update_last_TC_exe( ccsdsTelecommandPacket_t *TC , unsigned char *time ); |
|
61 | void update_last_TC_exe( ccsdsTelecommandPacket_t *TC , unsigned char *time ); | |
63 | void update_last_TC_rej(ccsdsTelecommandPacket_t *TC , unsigned char *time ); |
|
62 | void update_last_TC_rej(ccsdsTelecommandPacket_t *TC , unsigned char *time ); | |
64 | void close_action( ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id ); |
|
63 | void close_action( ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id ); | |
65 |
|
64 | |||
66 | extern rtems_status_code get_message_queue_id_send( rtems_id *queue_id ); |
|
65 | extern rtems_status_code get_message_queue_id_send( rtems_id *queue_id ); | |
67 | extern rtems_status_code get_message_queue_id_recv( rtems_id *queue_id ); |
|
66 | extern rtems_status_code get_message_queue_id_recv( rtems_id *queue_id ); | |
68 |
|
67 | |||
69 | #endif // TC_HANDLER_H_INCLUDED |
|
68 | #endif // TC_HANDLER_H_INCLUDED | |
70 |
|
69 | |||
71 |
|
70 | |||
72 |
|
71 |
@@ -1,530 +1,551 | |||||
1 | /** General usage functions and RTEMS tasks. |
|
1 | /** General usage functions and RTEMS tasks. | |
2 | * |
|
2 | * | |
3 | * @file |
|
3 | * @file | |
4 | * @author P. LEROY |
|
4 | * @author P. LEROY | |
5 | * |
|
5 | * | |
6 | */ |
|
6 | */ | |
7 |
|
7 | |||
8 | #include "fsw_misc.h" |
|
8 | #include "fsw_misc.h" | |
9 |
|
9 | |||
10 | void configure_timer(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider, |
|
10 | void configure_timer(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider, | |
11 | unsigned char interrupt_level, rtems_isr (*timer_isr)() ) |
|
11 | unsigned char interrupt_level, rtems_isr (*timer_isr)() ) | |
12 | { |
|
12 | { | |
13 | /** This function configures a GPTIMER timer instantiated in the VHDL design. |
|
13 | /** This function configures a GPTIMER timer instantiated in the VHDL design. | |
14 | * |
|
14 | * | |
15 | * @param gptimer_regs points to the APB registers of the GPTIMER IP core. |
|
15 | * @param gptimer_regs points to the APB registers of the GPTIMER IP core. | |
16 | * @param timer is the number of the timer in the IP core (several timers can be instantiated). |
|
16 | * @param timer is the number of the timer in the IP core (several timers can be instantiated). | |
17 | * @param clock_divider is the divider of the 1 MHz clock that will be configured. |
|
17 | * @param clock_divider is the divider of the 1 MHz clock that will be configured. | |
18 | * @param interrupt_level is the interrupt level that the timer drives. |
|
18 | * @param interrupt_level is the interrupt level that the timer drives. | |
19 | * @param timer_isr is the interrupt subroutine that will be attached to the IRQ driven by the timer. |
|
19 | * @param timer_isr is the interrupt subroutine that will be attached to the IRQ driven by the timer. | |
20 | * |
|
20 | * | |
21 | * Interrupt levels are described in the SPARC documentation sparcv8.pdf p.76 |
|
21 | * Interrupt levels are described in the SPARC documentation sparcv8.pdf p.76 | |
22 | * |
|
22 | * | |
23 | */ |
|
23 | */ | |
24 |
|
24 | |||
25 | rtems_status_code status; |
|
25 | rtems_status_code status; | |
26 | rtems_isr_entry old_isr_handler; |
|
26 | rtems_isr_entry old_isr_handler; | |
27 |
|
27 | |||
28 | gptimer_regs->timer[timer].ctrl = 0x00; // reset the control register |
|
28 | gptimer_regs->timer[timer].ctrl = 0x00; // reset the control register | |
29 |
|
29 | |||
30 | status = rtems_interrupt_catch( timer_isr, interrupt_level, &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels |
|
30 | status = rtems_interrupt_catch( timer_isr, interrupt_level, &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels | |
31 | if (status!=RTEMS_SUCCESSFUL) |
|
31 | if (status!=RTEMS_SUCCESSFUL) | |
32 | { |
|
32 | { | |
33 | PRINTF("in configure_timer *** ERR rtems_interrupt_catch\n") |
|
33 | PRINTF("in configure_timer *** ERR rtems_interrupt_catch\n") | |
34 | } |
|
34 | } | |
35 |
|
35 | |||
36 | timer_set_clock_divider( gptimer_regs, timer, clock_divider); |
|
36 | timer_set_clock_divider( gptimer_regs, timer, clock_divider); | |
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | void timer_start(gptimer_regs_t *gptimer_regs, unsigned char timer) |
|
39 | void timer_start(gptimer_regs_t *gptimer_regs, unsigned char timer) | |
40 | { |
|
40 | { | |
41 | /** This function starts a GPTIMER timer. |
|
41 | /** This function starts a GPTIMER timer. | |
42 | * |
|
42 | * | |
43 | * @param gptimer_regs points to the APB registers of the GPTIMER IP core. |
|
43 | * @param gptimer_regs points to the APB registers of the GPTIMER IP core. | |
44 | * @param timer is the number of the timer in the IP core (several timers can be instantiated). |
|
44 | * @param timer is the number of the timer in the IP core (several timers can be instantiated). | |
45 | * |
|
45 | * | |
46 | */ |
|
46 | */ | |
47 |
|
47 | |||
48 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000010; // clear pending IRQ if any |
|
48 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000010; // clear pending IRQ if any | |
49 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000004; // LD load value from the reload register |
|
49 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000004; // LD load value from the reload register | |
50 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000001; // EN enable the timer |
|
50 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000001; // EN enable the timer | |
51 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000002; // RS restart |
|
51 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000002; // RS restart | |
52 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000008; // IE interrupt enable |
|
52 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000008; // IE interrupt enable | |
53 | } |
|
53 | } | |
54 |
|
54 | |||
55 | void timer_stop(gptimer_regs_t *gptimer_regs, unsigned char timer) |
|
55 | void timer_stop(gptimer_regs_t *gptimer_regs, unsigned char timer) | |
56 | { |
|
56 | { | |
57 | /** This function stops a GPTIMER timer. |
|
57 | /** This function stops a GPTIMER timer. | |
58 | * |
|
58 | * | |
59 | * @param gptimer_regs points to the APB registers of the GPTIMER IP core. |
|
59 | * @param gptimer_regs points to the APB registers of the GPTIMER IP core. | |
60 | * @param timer is the number of the timer in the IP core (several timers can be instantiated). |
|
60 | * @param timer is the number of the timer in the IP core (several timers can be instantiated). | |
61 | * |
|
61 | * | |
62 | */ |
|
62 | */ | |
63 |
|
63 | |||
64 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & 0xfffffffe; // EN enable the timer |
|
64 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & 0xfffffffe; // EN enable the timer | |
65 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & 0xffffffef; // IE interrupt enable |
|
65 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & 0xffffffef; // IE interrupt enable | |
66 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000010; // clear pending IRQ if any |
|
66 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000010; // clear pending IRQ if any | |
67 | } |
|
67 | } | |
68 |
|
68 | |||
69 | void timer_set_clock_divider(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider) |
|
69 | void timer_set_clock_divider(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider) | |
70 | { |
|
70 | { | |
71 | /** This function sets the clock divider of a GPTIMER timer. |
|
71 | /** This function sets the clock divider of a GPTIMER timer. | |
72 | * |
|
72 | * | |
73 | * @param gptimer_regs points to the APB registers of the GPTIMER IP core. |
|
73 | * @param gptimer_regs points to the APB registers of the GPTIMER IP core. | |
74 | * @param timer is the number of the timer in the IP core (several timers can be instantiated). |
|
74 | * @param timer is the number of the timer in the IP core (several timers can be instantiated). | |
75 | * @param clock_divider is the divider of the 1 MHz clock that will be configured. |
|
75 | * @param clock_divider is the divider of the 1 MHz clock that will be configured. | |
76 | * |
|
76 | * | |
77 | */ |
|
77 | */ | |
78 |
|
78 | |||
79 | gptimer_regs->timer[timer].reload = clock_divider; // base clock frequency is 1 MHz |
|
79 | gptimer_regs->timer[timer].reload = clock_divider; // base clock frequency is 1 MHz | |
80 | } |
|
80 | } | |
81 |
|
81 | |||
82 | int send_console_outputs_on_apbuart_port( void ) // Send the console outputs on the apbuart port |
|
82 | int send_console_outputs_on_apbuart_port( void ) // Send the console outputs on the apbuart port | |
83 | { |
|
83 | { | |
84 | struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART; |
|
84 | struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART; | |
85 |
|
85 | |||
86 | apbuart_regs->ctrl = APBUART_CTRL_REG_MASK_TE; |
|
86 | apbuart_regs->ctrl = APBUART_CTRL_REG_MASK_TE; | |
87 |
|
87 | |||
88 | return 0; |
|
88 | return 0; | |
89 | } |
|
89 | } | |
90 |
|
90 | |||
91 | int enable_apbuart_transmitter( void ) // set the bit 1, TE Transmitter Enable to 1 in the APBUART control register |
|
91 | int enable_apbuart_transmitter( void ) // set the bit 1, TE Transmitter Enable to 1 in the APBUART control register | |
92 | { |
|
92 | { | |
93 | struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART; |
|
93 | struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART; | |
94 |
|
94 | |||
95 | apbuart_regs->ctrl = apbuart_regs->ctrl | APBUART_CTRL_REG_MASK_TE; |
|
95 | apbuart_regs->ctrl = apbuart_regs->ctrl | APBUART_CTRL_REG_MASK_TE; | |
96 |
|
96 | |||
97 | return 0; |
|
97 | return 0; | |
98 | } |
|
98 | } | |
99 |
|
99 | |||
100 | void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value) |
|
100 | void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value) | |
101 | { |
|
101 | { | |
102 | /** This function sets the scaler reload register of the apbuart module |
|
102 | /** This function sets the scaler reload register of the apbuart module | |
103 | * |
|
103 | * | |
104 | * @param regs is the address of the apbuart registers in memory |
|
104 | * @param regs is the address of the apbuart registers in memory | |
105 | * @param value is the value that will be stored in the scaler register |
|
105 | * @param value is the value that will be stored in the scaler register | |
106 | * |
|
106 | * | |
107 | * The value shall be set by the software to get data on the serial interface. |
|
107 | * The value shall be set by the software to get data on the serial interface. | |
108 | * |
|
108 | * | |
109 | */ |
|
109 | */ | |
110 |
|
110 | |||
111 | struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) regs; |
|
111 | struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) regs; | |
112 |
|
112 | |||
113 | apbuart_regs->scaler = value; |
|
113 | apbuart_regs->scaler = value; | |
114 | BOOT_PRINTF1("OK *** apbuart port scaler reload register set to 0x%x\n", value) |
|
114 | BOOT_PRINTF1("OK *** apbuart port scaler reload register set to 0x%x\n", value) | |
115 | } |
|
115 | } | |
116 |
|
116 | |||
117 | //************ |
|
117 | //************ | |
118 | // RTEMS TASKS |
|
118 | // RTEMS TASKS | |
119 |
|
119 | |||
120 | rtems_task stat_task(rtems_task_argument argument) |
|
120 | rtems_task stat_task(rtems_task_argument argument) | |
121 | { |
|
121 | { | |
122 | int i; |
|
122 | int i; | |
123 | int j; |
|
123 | int j; | |
124 | i = 0; |
|
124 | i = 0; | |
125 | j = 0; |
|
125 | j = 0; | |
126 | BOOT_PRINTF("in STAT *** \n") |
|
126 | BOOT_PRINTF("in STAT *** \n") | |
127 | while(1){ |
|
127 | while(1){ | |
128 | rtems_task_wake_after(1000); |
|
128 | rtems_task_wake_after(1000); | |
129 | PRINTF1("%d\n", j) |
|
129 | PRINTF1("%d\n", j) | |
130 | if (i == CPU_USAGE_REPORT_PERIOD) { |
|
130 | if (i == CPU_USAGE_REPORT_PERIOD) { | |
131 | // #ifdef PRINT_TASK_STATISTICS |
|
131 | // #ifdef PRINT_TASK_STATISTICS | |
132 | // rtems_cpu_usage_report(); |
|
132 | // rtems_cpu_usage_report(); | |
133 | // rtems_cpu_usage_reset(); |
|
133 | // rtems_cpu_usage_reset(); | |
134 | // #endif |
|
134 | // #endif | |
135 | i = 0; |
|
135 | i = 0; | |
136 | } |
|
136 | } | |
137 | else i++; |
|
137 | else i++; | |
138 | j++; |
|
138 | j++; | |
139 | } |
|
139 | } | |
140 | } |
|
140 | } | |
141 |
|
141 | |||
142 | rtems_task hous_task(rtems_task_argument argument) |
|
142 | rtems_task hous_task(rtems_task_argument argument) | |
143 | { |
|
143 | { | |
144 | rtems_status_code status; |
|
144 | rtems_status_code status; | |
145 | rtems_status_code spare_status; |
|
145 | rtems_status_code spare_status; | |
146 | rtems_id queue_id; |
|
146 | rtems_id queue_id; | |
147 | rtems_rate_monotonic_period_status period_status; |
|
147 | rtems_rate_monotonic_period_status period_status; | |
148 |
|
148 | |||
149 | status = get_message_queue_id_send( &queue_id ); |
|
149 | status = get_message_queue_id_send( &queue_id ); | |
150 | if (status != RTEMS_SUCCESSFUL) |
|
150 | if (status != RTEMS_SUCCESSFUL) | |
151 | { |
|
151 | { | |
152 | PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status) |
|
152 | PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status) | |
153 | } |
|
153 | } | |
154 |
|
154 | |||
155 | BOOT_PRINTF("in HOUS ***\n") |
|
155 | BOOT_PRINTF("in HOUS ***\n") | |
156 |
|
156 | |||
157 | if (rtems_rate_monotonic_ident( name_hk_rate_monotonic, &HK_id) != RTEMS_SUCCESSFUL) { |
|
157 | if (rtems_rate_monotonic_ident( name_hk_rate_monotonic, &HK_id) != RTEMS_SUCCESSFUL) { | |
158 | status = rtems_rate_monotonic_create( name_hk_rate_monotonic, &HK_id ); |
|
158 | status = rtems_rate_monotonic_create( name_hk_rate_monotonic, &HK_id ); | |
159 | if( status != RTEMS_SUCCESSFUL ) { |
|
159 | if( status != RTEMS_SUCCESSFUL ) { | |
160 | PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status ) |
|
160 | PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status ) | |
161 | } |
|
161 | } | |
162 | } |
|
162 | } | |
163 |
|
163 | |||
164 | status = rtems_rate_monotonic_cancel(HK_id); |
|
164 | status = rtems_rate_monotonic_cancel(HK_id); | |
165 | if( status != RTEMS_SUCCESSFUL ) { |
|
165 | if( status != RTEMS_SUCCESSFUL ) { | |
166 | PRINTF1( "ERR *** in HOUS *** rtems_rate_monotonic_cancel(HK_id) ***code: %d\n", status ) |
|
166 | PRINTF1( "ERR *** in HOUS *** rtems_rate_monotonic_cancel(HK_id) ***code: %d\n", status ) | |
167 | } |
|
167 | } | |
168 | else { |
|
168 | else { | |
169 | DEBUG_PRINTF("OK *** in HOUS *** rtems_rate_monotonic_cancel(HK_id)\n") |
|
169 | DEBUG_PRINTF("OK *** in HOUS *** rtems_rate_monotonic_cancel(HK_id)\n") | |
170 | } |
|
170 | } | |
171 |
|
171 | |||
172 | // startup phase |
|
172 | // startup phase | |
173 | status = rtems_rate_monotonic_period( HK_id, SY_LFR_TIME_SYN_TIMEOUT_in_ticks ); |
|
173 | status = rtems_rate_monotonic_period( HK_id, SY_LFR_TIME_SYN_TIMEOUT_in_ticks ); | |
174 | status = rtems_rate_monotonic_get_status( HK_id, &period_status ); |
|
174 | status = rtems_rate_monotonic_get_status( HK_id, &period_status ); | |
175 | DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state) |
|
175 | DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state) | |
176 | while(period_status.state != RATE_MONOTONIC_EXPIRED ) // after SY_LFR_TIME_SYN_TIMEOUT ms, starts HK anyway |
|
176 | while(period_status.state != RATE_MONOTONIC_EXPIRED ) // after SY_LFR_TIME_SYN_TIMEOUT ms, starts HK anyway | |
177 | { |
|
177 | { | |
178 | if ((time_management_regs->coarse_time & 0x80000000) == 0x00000000) // check time synchronization |
|
178 | if ((time_management_regs->coarse_time & 0x80000000) == 0x00000000) // check time synchronization | |
179 | { |
|
179 | { | |
180 | break; // break if LFR is synchronized |
|
180 | break; // break if LFR is synchronized | |
181 | } |
|
181 | } | |
182 | else |
|
182 | else | |
183 | { |
|
183 | { | |
184 | status = rtems_rate_monotonic_get_status( HK_id, &period_status ); |
|
184 | status = rtems_rate_monotonic_get_status( HK_id, &period_status ); | |
185 | // sched_yield(); |
|
185 | // sched_yield(); | |
186 | status = rtems_task_wake_after( 10 ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 100 ms = 10 * 10 ms |
|
186 | status = rtems_task_wake_after( 10 ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 100 ms = 10 * 10 ms | |
187 | } |
|
187 | } | |
188 | } |
|
188 | } | |
189 | status = rtems_rate_monotonic_cancel(HK_id); |
|
189 | status = rtems_rate_monotonic_cancel(HK_id); | |
190 | DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state) |
|
190 | DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state) | |
191 |
|
191 | |||
192 | while(1){ // launch the rate monotonic task |
|
192 | while(1){ // launch the rate monotonic task | |
193 | status = rtems_rate_monotonic_period( HK_id, HK_PERIOD ); |
|
193 | status = rtems_rate_monotonic_period( HK_id, HK_PERIOD ); | |
194 | if ( status != RTEMS_SUCCESSFUL ) { |
|
194 | if ( status != RTEMS_SUCCESSFUL ) { | |
195 | PRINTF1( "in HOUS *** ERR period: %d\n", status); |
|
195 | PRINTF1( "in HOUS *** ERR period: %d\n", status); | |
196 | spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_6 ); |
|
196 | spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_6 ); | |
197 | } |
|
197 | } | |
198 | else { |
|
198 | else { | |
199 | housekeeping_packet.packetSequenceControl[0] = (unsigned char) (sequenceCounterHK >> 8); |
|
199 | housekeeping_packet.packetSequenceControl[0] = (unsigned char) (sequenceCounterHK >> 8); | |
200 | housekeeping_packet.packetSequenceControl[1] = (unsigned char) (sequenceCounterHK ); |
|
200 | housekeeping_packet.packetSequenceControl[1] = (unsigned char) (sequenceCounterHK ); | |
201 | increment_seq_counter( &sequenceCounterHK ); |
|
201 | increment_seq_counter( &sequenceCounterHK ); | |
202 |
|
202 | |||
203 | housekeeping_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24); |
|
203 | housekeeping_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24); | |
204 | housekeeping_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16); |
|
204 | housekeeping_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16); | |
205 | housekeeping_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8); |
|
205 | housekeeping_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8); | |
206 | housekeeping_packet.time[3] = (unsigned char) (time_management_regs->coarse_time); |
|
206 | housekeeping_packet.time[3] = (unsigned char) (time_management_regs->coarse_time); | |
207 | housekeeping_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8); |
|
207 | housekeeping_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8); | |
208 | housekeeping_packet.time[5] = (unsigned char) (time_management_regs->fine_time); |
|
208 | housekeeping_packet.time[5] = (unsigned char) (time_management_regs->fine_time); | |
209 |
|
209 | |||
210 | spacewire_update_statistics(); |
|
210 | spacewire_update_statistics(); | |
211 |
|
211 | |||
212 | housekeeping_packet.hk_lfr_q_sd_fifo_size_max = hk_lfr_q_sd_fifo_size_max; |
|
212 | housekeeping_packet.hk_lfr_q_sd_fifo_size_max = hk_lfr_q_sd_fifo_size_max; | |
213 | housekeeping_packet.hk_lfr_q_rv_fifo_size_max = hk_lfr_q_rv_fifo_size_max; |
|
213 | housekeeping_packet.hk_lfr_q_rv_fifo_size_max = hk_lfr_q_rv_fifo_size_max; | |
214 | housekeeping_packet.hk_lfr_q_p0_fifo_size_max = hk_lfr_q_p0_fifo_size_max; |
|
214 | housekeeping_packet.hk_lfr_q_p0_fifo_size_max = hk_lfr_q_p0_fifo_size_max; | |
215 | housekeeping_packet.hk_lfr_q_p1_fifo_size_max = hk_lfr_q_p1_fifo_size_max; |
|
215 | housekeeping_packet.hk_lfr_q_p1_fifo_size_max = hk_lfr_q_p1_fifo_size_max; | |
216 | housekeeping_packet.hk_lfr_q_p2_fifo_size_max = hk_lfr_q_p2_fifo_size_max; |
|
216 | housekeeping_packet.hk_lfr_q_p2_fifo_size_max = hk_lfr_q_p2_fifo_size_max; | |
217 |
|
217 | |||
218 | housekeeping_packet.sy_lfr_common_parameters_spare = parameter_dump_packet.sy_lfr_common_parameters_spare; |
|
218 | housekeeping_packet.sy_lfr_common_parameters_spare = parameter_dump_packet.sy_lfr_common_parameters_spare; | |
219 | housekeeping_packet.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; |
|
219 | housekeeping_packet.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; | |
220 | get_temperatures( housekeeping_packet.hk_lfr_temp_scm ); |
|
220 | get_temperatures( housekeeping_packet.hk_lfr_temp_scm ); | |
221 | get_v_e1_e2_f3( housekeeping_packet.hk_lfr_sc_v_f3 ); |
|
221 | get_v_e1_e2_f3( housekeeping_packet.hk_lfr_sc_v_f3 ); | |
222 | get_cpu_load( (unsigned char *) &housekeeping_packet.hk_lfr_cpu_load ); |
|
222 | get_cpu_load( (unsigned char *) &housekeeping_packet.hk_lfr_cpu_load ); | |
223 |
|
223 | |||
224 | // SEND PACKET |
|
224 | // SEND PACKET | |
225 | status = rtems_message_queue_send( queue_id, &housekeeping_packet, |
|
225 | status = rtems_message_queue_send( queue_id, &housekeeping_packet, | |
226 | PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES); |
|
226 | PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES); | |
227 | if (status != RTEMS_SUCCESSFUL) { |
|
227 | if (status != RTEMS_SUCCESSFUL) { | |
228 | PRINTF1("in HOUS *** ERR send: %d\n", status) |
|
228 | PRINTF1("in HOUS *** ERR send: %d\n", status) | |
229 | } |
|
229 | } | |
230 | } |
|
230 | } | |
231 | } |
|
231 | } | |
232 |
|
232 | |||
233 | PRINTF("in HOUS *** deleting task\n") |
|
233 | PRINTF("in HOUS *** deleting task\n") | |
234 |
|
234 | |||
235 | status = rtems_task_delete( RTEMS_SELF ); // should not return |
|
235 | status = rtems_task_delete( RTEMS_SELF ); // should not return | |
236 | printf( "rtems_task_delete returned with status of %d.\n", status ); |
|
236 | printf( "rtems_task_delete returned with status of %d.\n", status ); | |
237 | return; |
|
237 | return; | |
238 | } |
|
238 | } | |
239 |
|
239 | |||
240 | rtems_task dumb_task( rtems_task_argument unused ) |
|
240 | rtems_task dumb_task( rtems_task_argument unused ) | |
241 | { |
|
241 | { | |
242 | /** This RTEMS taks is used to print messages without affecting the general behaviour of the software. |
|
242 | /** This RTEMS taks is used to print messages without affecting the general behaviour of the software. | |
243 | * |
|
243 | * | |
244 | * @param unused is the starting argument of the RTEMS task |
|
244 | * @param unused is the starting argument of the RTEMS task | |
245 | * |
|
245 | * | |
246 | * The DUMB taks waits for RTEMS events and print messages depending on the incoming events. |
|
246 | * The DUMB taks waits for RTEMS events and print messages depending on the incoming events. | |
247 | * |
|
247 | * | |
248 | */ |
|
248 | */ | |
249 |
|
249 | |||
250 | unsigned int i; |
|
250 | unsigned int i; | |
251 | unsigned int intEventOut; |
|
251 | unsigned int intEventOut; | |
252 | unsigned int coarse_time = 0; |
|
252 | unsigned int coarse_time = 0; | |
253 | unsigned int fine_time = 0; |
|
253 | unsigned int fine_time = 0; | |
254 | rtems_event_set event_out; |
|
254 | rtems_event_set event_out; | |
255 |
|
255 | |||
256 | char *DumbMessages[12] = {"in DUMB *** default", // RTEMS_EVENT_0 |
|
256 | char *DumbMessages[12] = {"in DUMB *** default", // RTEMS_EVENT_0 | |
257 | "in DUMB *** timecode_irq_handler", // RTEMS_EVENT_1 |
|
257 | "in DUMB *** timecode_irq_handler", // RTEMS_EVENT_1 | |
258 | "in DUMB *** f3 buffer changed", // RTEMS_EVENT_2 |
|
258 | "in DUMB *** f3 buffer changed", // RTEMS_EVENT_2 | |
259 | "in DUMB *** in SMIQ *** Error sending event to AVF0", // RTEMS_EVENT_3 |
|
259 | "in DUMB *** in SMIQ *** Error sending event to AVF0", // RTEMS_EVENT_3 | |
260 | "in DUMB *** spectral_matrices_isr *** Error sending event to SMIQ", // RTEMS_EVENT_4 |
|
260 | "in DUMB *** spectral_matrices_isr *** Error sending event to SMIQ", // RTEMS_EVENT_4 | |
261 | "in DUMB *** waveforms_simulator_isr", // RTEMS_EVENT_5 |
|
261 | "in DUMB *** waveforms_simulator_isr", // RTEMS_EVENT_5 | |
262 | "VHDL SM *** two buffers f0 ready", // RTEMS_EVENT_6 |
|
262 | "VHDL SM *** two buffers f0 ready", // RTEMS_EVENT_6 | |
263 | "ready for dump", // RTEMS_EVENT_7 |
|
263 | "ready for dump", // RTEMS_EVENT_7 | |
264 | "VHDL ERR *** spectral matrix", // RTEMS_EVENT_8 |
|
264 | "VHDL ERR *** spectral matrix", // RTEMS_EVENT_8 | |
265 | "tick", // RTEMS_EVENT_9 |
|
265 | "tick", // RTEMS_EVENT_9 | |
266 | "VHDL ERR *** waveform picker", // RTEMS_EVENT_10 |
|
266 | "VHDL ERR *** waveform picker", // RTEMS_EVENT_10 | |
267 | "VHDL ERR *** unexpected ready matrix values" // RTEMS_EVENT_11 |
|
267 | "VHDL ERR *** unexpected ready matrix values" // RTEMS_EVENT_11 | |
268 | }; |
|
268 | }; | |
269 |
|
269 | |||
270 | BOOT_PRINTF("in DUMB *** \n") |
|
270 | BOOT_PRINTF("in DUMB *** \n") | |
271 |
|
271 | |||
272 | while(1){ |
|
272 | while(1){ | |
273 | rtems_event_receive(RTEMS_EVENT_0 | RTEMS_EVENT_1 | RTEMS_EVENT_2 | RTEMS_EVENT_3 |
|
273 | rtems_event_receive(RTEMS_EVENT_0 | RTEMS_EVENT_1 | RTEMS_EVENT_2 | RTEMS_EVENT_3 | |
274 | | RTEMS_EVENT_4 | RTEMS_EVENT_5 | RTEMS_EVENT_6 | RTEMS_EVENT_7 |
|
274 | | RTEMS_EVENT_4 | RTEMS_EVENT_5 | RTEMS_EVENT_6 | RTEMS_EVENT_7 | |
275 | | RTEMS_EVENT_8 | RTEMS_EVENT_9, |
|
275 | | RTEMS_EVENT_8 | RTEMS_EVENT_9, | |
276 | RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT |
|
276 | RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT | |
277 | intEventOut = (unsigned int) event_out; |
|
277 | intEventOut = (unsigned int) event_out; | |
278 | for ( i=0; i<32; i++) |
|
278 | for ( i=0; i<32; i++) | |
279 | { |
|
279 | { | |
280 | if ( ((intEventOut >> i) & 0x0001) != 0) |
|
280 | if ( ((intEventOut >> i) & 0x0001) != 0) | |
281 | { |
|
281 | { | |
282 | coarse_time = time_management_regs->coarse_time; |
|
282 | coarse_time = time_management_regs->coarse_time; | |
283 | fine_time = time_management_regs->fine_time; |
|
283 | fine_time = time_management_regs->fine_time; | |
284 | printf("in DUMB *** coarse: %x, fine: %x, %s\n", coarse_time, fine_time, DumbMessages[i]); |
|
284 | printf("in DUMB *** coarse: %x, fine: %x, %s\n", coarse_time, fine_time, DumbMessages[i]); | |
285 | if (i==8) |
|
285 | if (i==8) | |
286 | { |
|
286 | { | |
287 | } |
|
287 | } | |
288 | if (i==10) |
|
288 | if (i==10) | |
289 | { |
|
289 | { | |
290 | } |
|
290 | } | |
291 | } |
|
291 | } | |
292 | } |
|
292 | } | |
293 | } |
|
293 | } | |
294 | } |
|
294 | } | |
295 |
|
295 | |||
296 | //***************************** |
|
296 | //***************************** | |
297 | // init housekeeping parameters |
|
297 | // init housekeeping parameters | |
298 |
|
298 | |||
299 | void init_housekeeping_parameters( void ) |
|
299 | void init_housekeeping_parameters( void ) | |
300 | { |
|
300 | { | |
301 | /** This function initialize the housekeeping_packet global variable with default values. |
|
301 | /** This function initialize the housekeeping_packet global variable with default values. | |
302 | * |
|
302 | * | |
303 | */ |
|
303 | */ | |
304 |
|
304 | |||
305 | unsigned int i = 0; |
|
305 | unsigned int i = 0; | |
306 | unsigned char *parameters; |
|
306 | unsigned char *parameters; | |
307 | unsigned char sizeOfHK; |
|
307 | unsigned char sizeOfHK; | |
308 |
|
308 | |||
309 | sizeOfHK = sizeof( Packet_TM_LFR_HK_t ); |
|
309 | sizeOfHK = sizeof( Packet_TM_LFR_HK_t ); | |
310 |
|
310 | |||
311 | parameters = (unsigned char*) &housekeeping_packet; |
|
311 | parameters = (unsigned char*) &housekeeping_packet; | |
312 |
|
312 | |||
313 | for(i = 0; i< sizeOfHK; i++) |
|
313 | for(i = 0; i< sizeOfHK; i++) | |
314 | { |
|
314 | { | |
315 | parameters[i] = 0x00; |
|
315 | parameters[i] = 0x00; | |
316 | } |
|
316 | } | |
317 |
|
317 | |||
318 | housekeeping_packet.targetLogicalAddress = CCSDS_DESTINATION_ID; |
|
318 | housekeeping_packet.targetLogicalAddress = CCSDS_DESTINATION_ID; | |
319 | housekeeping_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID; |
|
319 | housekeeping_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID; | |
320 | housekeeping_packet.reserved = DEFAULT_RESERVED; |
|
320 | housekeeping_packet.reserved = DEFAULT_RESERVED; | |
321 | housekeeping_packet.userApplication = CCSDS_USER_APP; |
|
321 | housekeeping_packet.userApplication = CCSDS_USER_APP; | |
322 | housekeeping_packet.packetID[0] = (unsigned char) (APID_TM_HK >> 8); |
|
322 | housekeeping_packet.packetID[0] = (unsigned char) (APID_TM_HK >> 8); | |
323 | housekeeping_packet.packetID[1] = (unsigned char) (APID_TM_HK); |
|
323 | housekeeping_packet.packetID[1] = (unsigned char) (APID_TM_HK); | |
324 | housekeeping_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE; |
|
324 | housekeeping_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE; | |
325 | housekeeping_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT; |
|
325 | housekeeping_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT; | |
326 | housekeeping_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> 8); |
|
326 | housekeeping_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> 8); | |
327 | housekeeping_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK ); |
|
327 | housekeeping_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK ); | |
328 | housekeeping_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; |
|
328 | housekeeping_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; | |
329 | housekeeping_packet.serviceType = TM_TYPE_HK; |
|
329 | housekeeping_packet.serviceType = TM_TYPE_HK; | |
330 | housekeeping_packet.serviceSubType = TM_SUBTYPE_HK; |
|
330 | housekeeping_packet.serviceSubType = TM_SUBTYPE_HK; | |
331 | housekeeping_packet.destinationID = TM_DESTINATION_ID_GROUND; |
|
331 | housekeeping_packet.destinationID = TM_DESTINATION_ID_GROUND; | |
332 | housekeeping_packet.sid = SID_HK; |
|
332 | housekeeping_packet.sid = SID_HK; | |
333 |
|
333 | |||
334 | // init status word |
|
334 | // init status word | |
335 | housekeeping_packet.lfr_status_word[0] = DEFAULT_STATUS_WORD_BYTE0; |
|
335 | housekeeping_packet.lfr_status_word[0] = DEFAULT_STATUS_WORD_BYTE0; | |
336 | housekeeping_packet.lfr_status_word[1] = DEFAULT_STATUS_WORD_BYTE1; |
|
336 | housekeeping_packet.lfr_status_word[1] = DEFAULT_STATUS_WORD_BYTE1; | |
337 | // init software version |
|
337 | // init software version | |
338 | housekeeping_packet.lfr_sw_version[0] = SW_VERSION_N1; |
|
338 | housekeeping_packet.lfr_sw_version[0] = SW_VERSION_N1; | |
339 | housekeeping_packet.lfr_sw_version[1] = SW_VERSION_N2; |
|
339 | housekeeping_packet.lfr_sw_version[1] = SW_VERSION_N2; | |
340 | housekeeping_packet.lfr_sw_version[2] = SW_VERSION_N3; |
|
340 | housekeeping_packet.lfr_sw_version[2] = SW_VERSION_N3; | |
341 | housekeeping_packet.lfr_sw_version[3] = SW_VERSION_N4; |
|
341 | housekeeping_packet.lfr_sw_version[3] = SW_VERSION_N4; | |
342 | // init fpga version |
|
342 | // init fpga version | |
343 | parameters = (unsigned char *) (REGS_ADDR_VHDL_VERSION); |
|
343 | parameters = (unsigned char *) (REGS_ADDR_VHDL_VERSION); | |
344 | housekeeping_packet.lfr_fpga_version[0] = parameters[1]; // n1 |
|
344 | housekeeping_packet.lfr_fpga_version[0] = parameters[1]; // n1 | |
345 | housekeeping_packet.lfr_fpga_version[1] = parameters[2]; // n2 |
|
345 | housekeeping_packet.lfr_fpga_version[1] = parameters[2]; // n2 | |
346 | housekeeping_packet.lfr_fpga_version[2] = parameters[3]; // n3 |
|
346 | housekeeping_packet.lfr_fpga_version[2] = parameters[3]; // n3 | |
347 |
|
347 | |||
348 | housekeeping_packet.hk_lfr_q_sd_fifo_size = MSG_QUEUE_COUNT_SEND; |
|
348 | housekeeping_packet.hk_lfr_q_sd_fifo_size = MSG_QUEUE_COUNT_SEND; | |
349 | housekeeping_packet.hk_lfr_q_rv_fifo_size = MSG_QUEUE_COUNT_RECV; |
|
349 | housekeeping_packet.hk_lfr_q_rv_fifo_size = MSG_QUEUE_COUNT_RECV; | |
350 | housekeeping_packet.hk_lfr_q_p0_fifo_size = MSG_QUEUE_COUNT_PRC0; |
|
350 | housekeeping_packet.hk_lfr_q_p0_fifo_size = MSG_QUEUE_COUNT_PRC0; | |
351 | housekeeping_packet.hk_lfr_q_p1_fifo_size = MSG_QUEUE_COUNT_PRC1; |
|
351 | housekeeping_packet.hk_lfr_q_p1_fifo_size = MSG_QUEUE_COUNT_PRC1; | |
352 | housekeeping_packet.hk_lfr_q_p2_fifo_size = MSG_QUEUE_COUNT_PRC2; |
|
352 | housekeeping_packet.hk_lfr_q_p2_fifo_size = MSG_QUEUE_COUNT_PRC2; | |
353 | } |
|
353 | } | |
354 |
|
354 | |||
355 | void increment_seq_counter( unsigned short *packetSequenceControl ) |
|
355 | void increment_seq_counter( unsigned short *packetSequenceControl ) | |
356 | { |
|
356 | { | |
357 | /** This function increment the sequence counter passes in argument. |
|
357 | /** This function increment the sequence counter passes in argument. | |
358 | * |
|
358 | * | |
359 | * The increment does not affect the grouping flag. In case of an overflow, the counter is reset to 0. |
|
359 | * The increment does not affect the grouping flag. In case of an overflow, the counter is reset to 0. | |
360 | * |
|
360 | * | |
361 | */ |
|
361 | */ | |
362 |
|
362 | |||
363 | unsigned short segmentation_grouping_flag; |
|
363 | unsigned short segmentation_grouping_flag; | |
364 | unsigned short sequence_cnt; |
|
364 | unsigned short sequence_cnt; | |
365 |
|
365 | |||
366 | segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << 8; // keep bits 7 downto 6 |
|
366 | segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << 8; // keep bits 7 downto 6 | |
367 | sequence_cnt = (*packetSequenceControl) & 0x3fff; // [0011 1111 1111 1111] |
|
367 | sequence_cnt = (*packetSequenceControl) & 0x3fff; // [0011 1111 1111 1111] | |
368 |
|
368 | |||
369 | if ( sequence_cnt < SEQ_CNT_MAX) |
|
369 | if ( sequence_cnt < SEQ_CNT_MAX) | |
370 | { |
|
370 | { | |
371 | sequence_cnt = sequence_cnt + 1; |
|
371 | sequence_cnt = sequence_cnt + 1; | |
372 | } |
|
372 | } | |
373 | else |
|
373 | else | |
374 | { |
|
374 | { | |
375 | sequence_cnt = 0; |
|
375 | sequence_cnt = 0; | |
376 | } |
|
376 | } | |
377 |
|
377 | |||
378 | *packetSequenceControl = segmentation_grouping_flag | sequence_cnt ; |
|
378 | *packetSequenceControl = segmentation_grouping_flag | sequence_cnt ; | |
379 | } |
|
379 | } | |
380 |
|
380 | |||
381 | void getTime( unsigned char *time) |
|
381 | void getTime( unsigned char *time) | |
382 | { |
|
382 | { | |
383 | /** This function write the current local time in the time buffer passed in argument. |
|
383 | /** This function write the current local time in the time buffer passed in argument. | |
384 | * |
|
384 | * | |
385 | */ |
|
385 | */ | |
386 |
|
386 | |||
387 | time[0] = (unsigned char) (time_management_regs->coarse_time>>24); |
|
387 | time[0] = (unsigned char) (time_management_regs->coarse_time>>24); | |
388 | time[1] = (unsigned char) (time_management_regs->coarse_time>>16); |
|
388 | time[1] = (unsigned char) (time_management_regs->coarse_time>>16); | |
389 | time[2] = (unsigned char) (time_management_regs->coarse_time>>8); |
|
389 | time[2] = (unsigned char) (time_management_regs->coarse_time>>8); | |
390 | time[3] = (unsigned char) (time_management_regs->coarse_time); |
|
390 | time[3] = (unsigned char) (time_management_regs->coarse_time); | |
391 | time[4] = (unsigned char) (time_management_regs->fine_time>>8); |
|
391 | time[4] = (unsigned char) (time_management_regs->fine_time>>8); | |
392 | time[5] = (unsigned char) (time_management_regs->fine_time); |
|
392 | time[5] = (unsigned char) (time_management_regs->fine_time); | |
393 | } |
|
393 | } | |
394 |
|
394 | |||
395 | unsigned long long int getTimeAsUnsignedLongLongInt( ) |
|
395 | unsigned long long int getTimeAsUnsignedLongLongInt( ) | |
396 | { |
|
396 | { | |
397 | /** This function write the current local time in the time buffer passed in argument. |
|
397 | /** This function write the current local time in the time buffer passed in argument. | |
398 | * |
|
398 | * | |
399 | */ |
|
399 | */ | |
400 | unsigned long long int time; |
|
400 | unsigned long long int time; | |
401 |
|
401 | |||
402 | time = ( (unsigned long long int) (time_management_regs->coarse_time & 0x7fffffff) << 16 ) |
|
402 | time = ( (unsigned long long int) (time_management_regs->coarse_time & 0x7fffffff) << 16 ) | |
403 | + time_management_regs->fine_time; |
|
403 | + time_management_regs->fine_time; | |
404 |
|
404 | |||
405 | return time; |
|
405 | return time; | |
406 | } |
|
406 | } | |
407 |
|
407 | |||
408 | void send_dumb_hk( void ) |
|
408 | void send_dumb_hk( void ) | |
409 | { |
|
409 | { | |
410 | Packet_TM_LFR_HK_t dummy_hk_packet; |
|
410 | Packet_TM_LFR_HK_t dummy_hk_packet; | |
411 | unsigned char *parameters; |
|
411 | unsigned char *parameters; | |
412 | unsigned int i; |
|
412 | unsigned int i; | |
413 | rtems_id queue_id; |
|
413 | rtems_id queue_id; | |
414 |
|
414 | |||
415 | dummy_hk_packet.targetLogicalAddress = CCSDS_DESTINATION_ID; |
|
415 | dummy_hk_packet.targetLogicalAddress = CCSDS_DESTINATION_ID; | |
416 | dummy_hk_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID; |
|
416 | dummy_hk_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID; | |
417 | dummy_hk_packet.reserved = DEFAULT_RESERVED; |
|
417 | dummy_hk_packet.reserved = DEFAULT_RESERVED; | |
418 | dummy_hk_packet.userApplication = CCSDS_USER_APP; |
|
418 | dummy_hk_packet.userApplication = CCSDS_USER_APP; | |
419 | dummy_hk_packet.packetID[0] = (unsigned char) (APID_TM_HK >> 8); |
|
419 | dummy_hk_packet.packetID[0] = (unsigned char) (APID_TM_HK >> 8); | |
420 | dummy_hk_packet.packetID[1] = (unsigned char) (APID_TM_HK); |
|
420 | dummy_hk_packet.packetID[1] = (unsigned char) (APID_TM_HK); | |
421 | dummy_hk_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE; |
|
421 | dummy_hk_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE; | |
422 | dummy_hk_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT; |
|
422 | dummy_hk_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT; | |
423 | dummy_hk_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> 8); |
|
423 | dummy_hk_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> 8); | |
424 | dummy_hk_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK ); |
|
424 | dummy_hk_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK ); | |
425 | dummy_hk_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; |
|
425 | dummy_hk_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; | |
426 | dummy_hk_packet.serviceType = TM_TYPE_HK; |
|
426 | dummy_hk_packet.serviceType = TM_TYPE_HK; | |
427 | dummy_hk_packet.serviceSubType = TM_SUBTYPE_HK; |
|
427 | dummy_hk_packet.serviceSubType = TM_SUBTYPE_HK; | |
428 | dummy_hk_packet.destinationID = TM_DESTINATION_ID_GROUND; |
|
428 | dummy_hk_packet.destinationID = TM_DESTINATION_ID_GROUND; | |
429 | dummy_hk_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24); |
|
429 | dummy_hk_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24); | |
430 | dummy_hk_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16); |
|
430 | dummy_hk_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16); | |
431 | dummy_hk_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8); |
|
431 | dummy_hk_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8); | |
432 | dummy_hk_packet.time[3] = (unsigned char) (time_management_regs->coarse_time); |
|
432 | dummy_hk_packet.time[3] = (unsigned char) (time_management_regs->coarse_time); | |
433 | dummy_hk_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8); |
|
433 | dummy_hk_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8); | |
434 | dummy_hk_packet.time[5] = (unsigned char) (time_management_regs->fine_time); |
|
434 | dummy_hk_packet.time[5] = (unsigned char) (time_management_regs->fine_time); | |
435 | dummy_hk_packet.sid = SID_HK; |
|
435 | dummy_hk_packet.sid = SID_HK; | |
436 |
|
436 | |||
437 | // init status word |
|
437 | // init status word | |
438 | dummy_hk_packet.lfr_status_word[0] = 0xff; |
|
438 | dummy_hk_packet.lfr_status_word[0] = 0xff; | |
439 | dummy_hk_packet.lfr_status_word[1] = 0xff; |
|
439 | dummy_hk_packet.lfr_status_word[1] = 0xff; | |
440 | // init software version |
|
440 | // init software version | |
441 | dummy_hk_packet.lfr_sw_version[0] = SW_VERSION_N1; |
|
441 | dummy_hk_packet.lfr_sw_version[0] = SW_VERSION_N1; | |
442 | dummy_hk_packet.lfr_sw_version[1] = SW_VERSION_N2; |
|
442 | dummy_hk_packet.lfr_sw_version[1] = SW_VERSION_N2; | |
443 | dummy_hk_packet.lfr_sw_version[2] = SW_VERSION_N3; |
|
443 | dummy_hk_packet.lfr_sw_version[2] = SW_VERSION_N3; | |
444 | dummy_hk_packet.lfr_sw_version[3] = SW_VERSION_N4; |
|
444 | dummy_hk_packet.lfr_sw_version[3] = SW_VERSION_N4; | |
445 | // init fpga version |
|
445 | // init fpga version | |
446 | parameters = (unsigned char *) (REGS_ADDR_WAVEFORM_PICKER + 0xb0); |
|
446 | parameters = (unsigned char *) (REGS_ADDR_WAVEFORM_PICKER + 0xb0); | |
447 | dummy_hk_packet.lfr_fpga_version[0] = parameters[1]; // n1 |
|
447 | dummy_hk_packet.lfr_fpga_version[0] = parameters[1]; // n1 | |
448 | dummy_hk_packet.lfr_fpga_version[1] = parameters[2]; // n2 |
|
448 | dummy_hk_packet.lfr_fpga_version[1] = parameters[2]; // n2 | |
449 | dummy_hk_packet.lfr_fpga_version[2] = parameters[3]; // n3 |
|
449 | dummy_hk_packet.lfr_fpga_version[2] = parameters[3]; // n3 | |
450 |
|
450 | |||
451 | parameters = (unsigned char *) &dummy_hk_packet.hk_lfr_cpu_load; |
|
451 | parameters = (unsigned char *) &dummy_hk_packet.hk_lfr_cpu_load; | |
452 |
|
452 | |||
453 | for (i=0; i<100; i++) |
|
453 | for (i=0; i<100; i++) | |
454 | { |
|
454 | { | |
455 | parameters[i] = 0xff; |
|
455 | parameters[i] = 0xff; | |
456 | } |
|
456 | } | |
457 |
|
457 | |||
458 | get_message_queue_id_send( &queue_id ); |
|
458 | get_message_queue_id_send( &queue_id ); | |
459 |
|
459 | |||
460 | rtems_message_queue_send( queue_id, &dummy_hk_packet, |
|
460 | rtems_message_queue_send( queue_id, &dummy_hk_packet, | |
461 | PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES); |
|
461 | PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES); | |
462 | } |
|
462 | } | |
463 |
|
463 | |||
464 | void get_temperatures( unsigned char *temperatures ) |
|
464 | void get_temperatures( unsigned char *temperatures ) | |
465 | { |
|
465 | { | |
466 | unsigned char* temp_scm_ptr; |
|
466 | unsigned char* temp_scm_ptr; | |
467 | unsigned char* temp_pcb_ptr; |
|
467 | unsigned char* temp_pcb_ptr; | |
468 | unsigned char* temp_fpga_ptr; |
|
468 | unsigned char* temp_fpga_ptr; | |
469 |
|
469 | |||
470 | // SEL1 SEL0 |
|
470 | // SEL1 SEL0 | |
471 | // 0 0 => PCB |
|
471 | // 0 0 => PCB | |
472 | // 0 1 => FPGA |
|
472 | // 0 1 => FPGA | |
473 | // 1 0 => SCM |
|
473 | // 1 0 => SCM | |
474 |
|
474 | |||
475 | temp_scm_ptr = (unsigned char *) &time_management_regs->temp_scm; |
|
475 | temp_scm_ptr = (unsigned char *) &time_management_regs->temp_scm; | |
476 | temp_pcb_ptr = (unsigned char *) &time_management_regs->temp_pcb; |
|
476 | temp_pcb_ptr = (unsigned char *) &time_management_regs->temp_pcb; | |
477 | temp_fpga_ptr = (unsigned char *) &time_management_regs->temp_fpga; |
|
477 | temp_fpga_ptr = (unsigned char *) &time_management_regs->temp_fpga; | |
478 |
|
478 | |||
479 | temperatures[0] = temp_scm_ptr[2]; |
|
479 | temperatures[0] = temp_scm_ptr[2]; | |
480 | temperatures[1] = temp_scm_ptr[3]; |
|
480 | temperatures[1] = temp_scm_ptr[3]; | |
481 | temperatures[2] = temp_pcb_ptr[2]; |
|
481 | temperatures[2] = temp_pcb_ptr[2]; | |
482 | temperatures[3] = temp_pcb_ptr[3]; |
|
482 | temperatures[3] = temp_pcb_ptr[3]; | |
483 | temperatures[4] = temp_fpga_ptr[2]; |
|
483 | temperatures[4] = temp_fpga_ptr[2]; | |
484 | temperatures[5] = temp_fpga_ptr[3]; |
|
484 | temperatures[5] = temp_fpga_ptr[3]; | |
485 | } |
|
485 | } | |
486 |
|
486 | |||
487 | void get_v_e1_e2_f3( unsigned char *spacecraft_potential ) |
|
487 | void get_v_e1_e2_f3( unsigned char *spacecraft_potential ) | |
488 | { |
|
488 | { | |
489 | unsigned char* v_ptr; |
|
489 | unsigned char* v_ptr; | |
490 | unsigned char* e1_ptr; |
|
490 | unsigned char* e1_ptr; | |
491 | unsigned char* e2_ptr; |
|
491 | unsigned char* e2_ptr; | |
492 |
|
492 | |||
493 | v_ptr = (unsigned char *) &waveform_picker_regs->v; |
|
493 | v_ptr = (unsigned char *) &waveform_picker_regs->v; | |
494 | e1_ptr = (unsigned char *) &waveform_picker_regs->e1; |
|
494 | e1_ptr = (unsigned char *) &waveform_picker_regs->e1; | |
495 | e2_ptr = (unsigned char *) &waveform_picker_regs->e2; |
|
495 | e2_ptr = (unsigned char *) &waveform_picker_regs->e2; | |
496 |
|
496 | |||
497 | spacecraft_potential[0] = v_ptr[2]; |
|
497 | spacecraft_potential[0] = v_ptr[2]; | |
498 | spacecraft_potential[1] = v_ptr[3]; |
|
498 | spacecraft_potential[1] = v_ptr[3]; | |
499 | spacecraft_potential[2] = e1_ptr[2]; |
|
499 | spacecraft_potential[2] = e1_ptr[2]; | |
500 | spacecraft_potential[3] = e1_ptr[3]; |
|
500 | spacecraft_potential[3] = e1_ptr[3]; | |
501 | spacecraft_potential[4] = e2_ptr[2]; |
|
501 | spacecraft_potential[4] = e2_ptr[2]; | |
502 | spacecraft_potential[5] = e2_ptr[3]; |
|
502 | spacecraft_potential[5] = e2_ptr[3]; | |
503 | } |
|
503 | } | |
504 |
|
504 | |||
505 | void get_cpu_load( unsigned char *resource_statistics ) |
|
505 | void get_cpu_load( unsigned char *resource_statistics ) | |
506 | { |
|
506 | { | |
507 | unsigned char cpu_load; |
|
507 | unsigned char cpu_load; | |
508 |
|
508 | |||
509 | cpu_load = lfr_rtems_cpu_usage_report(); |
|
509 | cpu_load = lfr_rtems_cpu_usage_report(); | |
510 |
|
510 | |||
511 | // HK_LFR_CPU_LOAD |
|
511 | // HK_LFR_CPU_LOAD | |
512 | resource_statistics[0] = cpu_load; |
|
512 | resource_statistics[0] = cpu_load; | |
513 |
|
513 | |||
514 | // HK_LFR_CPU_LOAD_MAX |
|
514 | // HK_LFR_CPU_LOAD_MAX | |
515 | if (cpu_load > resource_statistics[1]) |
|
515 | if (cpu_load > resource_statistics[1]) | |
516 | { |
|
516 | { | |
517 | resource_statistics[1] = cpu_load; |
|
517 | resource_statistics[1] = cpu_load; | |
518 | } |
|
518 | } | |
519 |
|
519 | |||
520 | // CPU_LOAD_AVE |
|
520 | // CPU_LOAD_AVE | |
521 | resource_statistics[2] = 0; |
|
521 | resource_statistics[2] = 0; | |
522 |
|
522 | |||
523 | #ifndef PRINT_TASK_STATISTICS |
|
523 | #ifndef PRINT_TASK_STATISTICS | |
524 | rtems_cpu_usage_reset(); |
|
524 | rtems_cpu_usage_reset(); | |
525 | #endif |
|
525 | #endif | |
526 |
|
526 | |||
527 | } |
|
527 | } | |
528 |
|
528 | |||
|
529 | void set_hk_lfr_sc_potential_flag( bool state ) | |||
|
530 | { | |||
|
531 | if (state == true) | |||
|
532 | { | |||
|
533 | housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] | 0x40; // [0100 0000] | |||
|
534 | } | |||
|
535 | else | |||
|
536 | { | |||
|
537 | housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] & 0xbf; // [1011 1111] | |||
|
538 | } | |||
|
539 | } | |||
529 |
|
540 | |||
530 |
|
541 | void set_hk_lfr_calib_enable( bool state ) | ||
|
542 | { | |||
|
543 | if (state == true) | |||
|
544 | { | |||
|
545 | housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] | 0x08; // [0000 1000] | |||
|
546 | } | |||
|
547 | else | |||
|
548 | { | |||
|
549 | housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] & 0xf7; // [1111 0111] | |||
|
550 | } | |||
|
551 | } |
@@ -1,1174 +1,1164 | |||||
1 | /** Functions and tasks related to TeleCommand handling. |
|
1 | /** Functions and tasks related to TeleCommand handling. | |
2 | * |
|
2 | * | |
3 | * @file |
|
3 | * @file | |
4 | * @author P. LEROY |
|
4 | * @author P. LEROY | |
5 | * |
|
5 | * | |
6 | * A group of functions to handle TeleCommands:\n |
|
6 | * A group of functions to handle TeleCommands:\n | |
7 | * action launching\n |
|
7 | * action launching\n | |
8 | * TC parsing\n |
|
8 | * TC parsing\n | |
9 | * ... |
|
9 | * ... | |
10 | * |
|
10 | * | |
11 | */ |
|
11 | */ | |
12 |
|
12 | |||
13 | #include "tc_handler.h" |
|
13 | #include "tc_handler.h" | |
14 | #include "math.h" |
|
14 | #include "math.h" | |
15 |
|
15 | |||
16 | //*********** |
|
16 | //*********** | |
17 | // RTEMS TASK |
|
17 | // RTEMS TASK | |
18 |
|
18 | |||
19 | rtems_task actn_task( rtems_task_argument unused ) |
|
19 | rtems_task actn_task( rtems_task_argument unused ) | |
20 | { |
|
20 | { | |
21 | /** This RTEMS task is responsible for launching actions upton the reception of valid TeleCommands. |
|
21 | /** This RTEMS task is responsible for launching actions upton the reception of valid TeleCommands. | |
22 | * |
|
22 | * | |
23 | * @param unused is the starting argument of the RTEMS task |
|
23 | * @param unused is the starting argument of the RTEMS task | |
24 | * |
|
24 | * | |
25 | * The ACTN task waits for data coming from an RTEMS msesage queue. When data arrives, it launches specific actions depending |
|
25 | * The ACTN task waits for data coming from an RTEMS msesage queue. When data arrives, it launches specific actions depending | |
26 | * on the incoming TeleCommand. |
|
26 | * on the incoming TeleCommand. | |
27 | * |
|
27 | * | |
28 | */ |
|
28 | */ | |
29 |
|
29 | |||
30 | int result; |
|
30 | int result; | |
31 | rtems_status_code status; // RTEMS status code |
|
31 | rtems_status_code status; // RTEMS status code | |
32 | ccsdsTelecommandPacket_t TC; // TC sent to the ACTN task |
|
32 | ccsdsTelecommandPacket_t TC; // TC sent to the ACTN task | |
33 | size_t size; // size of the incoming TC packet |
|
33 | size_t size; // size of the incoming TC packet | |
34 | unsigned char subtype; // subtype of the current TC packet |
|
34 | unsigned char subtype; // subtype of the current TC packet | |
35 | unsigned char time[6]; |
|
35 | unsigned char time[6]; | |
36 | rtems_id queue_rcv_id; |
|
36 | rtems_id queue_rcv_id; | |
37 | rtems_id queue_snd_id; |
|
37 | rtems_id queue_snd_id; | |
38 |
|
38 | |||
39 | status = get_message_queue_id_recv( &queue_rcv_id ); |
|
39 | status = get_message_queue_id_recv( &queue_rcv_id ); | |
40 | if (status != RTEMS_SUCCESSFUL) |
|
40 | if (status != RTEMS_SUCCESSFUL) | |
41 | { |
|
41 | { | |
42 | PRINTF1("in ACTN *** ERR get_message_queue_id_recv %d\n", status) |
|
42 | PRINTF1("in ACTN *** ERR get_message_queue_id_recv %d\n", status) | |
43 | } |
|
43 | } | |
44 |
|
44 | |||
45 | status = get_message_queue_id_send( &queue_snd_id ); |
|
45 | status = get_message_queue_id_send( &queue_snd_id ); | |
46 | if (status != RTEMS_SUCCESSFUL) |
|
46 | if (status != RTEMS_SUCCESSFUL) | |
47 | { |
|
47 | { | |
48 | PRINTF1("in ACTN *** ERR get_message_queue_id_send %d\n", status) |
|
48 | PRINTF1("in ACTN *** ERR get_message_queue_id_send %d\n", status) | |
49 | } |
|
49 | } | |
50 |
|
50 | |||
51 | result = LFR_SUCCESSFUL; |
|
51 | result = LFR_SUCCESSFUL; | |
52 | subtype = 0; // subtype of the current TC packet |
|
52 | subtype = 0; // subtype of the current TC packet | |
53 |
|
53 | |||
54 | BOOT_PRINTF("in ACTN *** \n") |
|
54 | BOOT_PRINTF("in ACTN *** \n") | |
55 |
|
55 | |||
56 | while(1) |
|
56 | while(1) | |
57 | { |
|
57 | { | |
58 | status = rtems_message_queue_receive( queue_rcv_id, (char*) &TC, &size, |
|
58 | status = rtems_message_queue_receive( queue_rcv_id, (char*) &TC, &size, | |
59 | RTEMS_WAIT, RTEMS_NO_TIMEOUT); |
|
59 | RTEMS_WAIT, RTEMS_NO_TIMEOUT); | |
60 | getTime( time ); // set time to the current time |
|
60 | getTime( time ); // set time to the current time | |
61 | if (status!=RTEMS_SUCCESSFUL) |
|
61 | if (status!=RTEMS_SUCCESSFUL) | |
62 | { |
|
62 | { | |
63 | PRINTF1("ERR *** in task ACTN *** error receiving a message, code %d \n", status) |
|
63 | PRINTF1("ERR *** in task ACTN *** error receiving a message, code %d \n", status) | |
64 | } |
|
64 | } | |
65 | else |
|
65 | else | |
66 | { |
|
66 | { | |
67 | subtype = TC.serviceSubType; |
|
67 | subtype = TC.serviceSubType; | |
68 | switch(subtype) |
|
68 | switch(subtype) | |
69 | { |
|
69 | { | |
70 | case TC_SUBTYPE_RESET: |
|
70 | case TC_SUBTYPE_RESET: | |
71 | result = action_reset( &TC, queue_snd_id, time ); |
|
71 | result = action_reset( &TC, queue_snd_id, time ); | |
72 | close_action( &TC, result, queue_snd_id ); |
|
72 | close_action( &TC, result, queue_snd_id ); | |
73 | break; |
|
73 | break; | |
74 | case TC_SUBTYPE_LOAD_COMM: |
|
74 | case TC_SUBTYPE_LOAD_COMM: | |
75 | result = action_load_common_par( &TC ); |
|
75 | result = action_load_common_par( &TC ); | |
76 | close_action( &TC, result, queue_snd_id ); |
|
76 | close_action( &TC, result, queue_snd_id ); | |
77 | break; |
|
77 | break; | |
78 | case TC_SUBTYPE_LOAD_NORM: |
|
78 | case TC_SUBTYPE_LOAD_NORM: | |
79 | result = action_load_normal_par( &TC, queue_snd_id, time ); |
|
79 | result = action_load_normal_par( &TC, queue_snd_id, time ); | |
80 | close_action( &TC, result, queue_snd_id ); |
|
80 | close_action( &TC, result, queue_snd_id ); | |
81 | break; |
|
81 | break; | |
82 | case TC_SUBTYPE_LOAD_BURST: |
|
82 | case TC_SUBTYPE_LOAD_BURST: | |
83 | result = action_load_burst_par( &TC, queue_snd_id, time ); |
|
83 | result = action_load_burst_par( &TC, queue_snd_id, time ); | |
84 | close_action( &TC, result, queue_snd_id ); |
|
84 | close_action( &TC, result, queue_snd_id ); | |
85 | break; |
|
85 | break; | |
86 | case TC_SUBTYPE_LOAD_SBM1: |
|
86 | case TC_SUBTYPE_LOAD_SBM1: | |
87 | result = action_load_sbm1_par( &TC, queue_snd_id, time ); |
|
87 | result = action_load_sbm1_par( &TC, queue_snd_id, time ); | |
88 | close_action( &TC, result, queue_snd_id ); |
|
88 | close_action( &TC, result, queue_snd_id ); | |
89 | break; |
|
89 | break; | |
90 | case TC_SUBTYPE_LOAD_SBM2: |
|
90 | case TC_SUBTYPE_LOAD_SBM2: | |
91 | result = action_load_sbm2_par( &TC, queue_snd_id, time ); |
|
91 | result = action_load_sbm2_par( &TC, queue_snd_id, time ); | |
92 | close_action( &TC, result, queue_snd_id ); |
|
92 | close_action( &TC, result, queue_snd_id ); | |
93 | break; |
|
93 | break; | |
94 | case TC_SUBTYPE_DUMP: |
|
94 | case TC_SUBTYPE_DUMP: | |
95 | result = action_dump_par( queue_snd_id ); |
|
95 | result = action_dump_par( queue_snd_id ); | |
96 | close_action( &TC, result, queue_snd_id ); |
|
96 | close_action( &TC, result, queue_snd_id ); | |
97 | break; |
|
97 | break; | |
98 | case TC_SUBTYPE_ENTER: |
|
98 | case TC_SUBTYPE_ENTER: | |
99 | result = action_enter_mode( &TC, queue_snd_id ); |
|
99 | result = action_enter_mode( &TC, queue_snd_id ); | |
100 | close_action( &TC, result, queue_snd_id ); |
|
100 | close_action( &TC, result, queue_snd_id ); | |
101 | break; |
|
101 | break; | |
102 | case TC_SUBTYPE_UPDT_INFO: |
|
102 | case TC_SUBTYPE_UPDT_INFO: | |
103 | result = action_update_info( &TC, queue_snd_id ); |
|
103 | result = action_update_info( &TC, queue_snd_id ); | |
104 | close_action( &TC, result, queue_snd_id ); |
|
104 | close_action( &TC, result, queue_snd_id ); | |
105 | break; |
|
105 | break; | |
106 | case TC_SUBTYPE_EN_CAL: |
|
106 | case TC_SUBTYPE_EN_CAL: | |
107 | result = action_enable_calibration( &TC, queue_snd_id, time ); |
|
107 | result = action_enable_calibration( &TC, queue_snd_id, time ); | |
108 | close_action( &TC, result, queue_snd_id ); |
|
108 | close_action( &TC, result, queue_snd_id ); | |
109 | break; |
|
109 | break; | |
110 | case TC_SUBTYPE_DIS_CAL: |
|
110 | case TC_SUBTYPE_DIS_CAL: | |
111 | result = action_disable_calibration( &TC, queue_snd_id, time ); |
|
111 | result = action_disable_calibration( &TC, queue_snd_id, time ); | |
112 | close_action( &TC, result, queue_snd_id ); |
|
112 | close_action( &TC, result, queue_snd_id ); | |
113 | break; |
|
113 | break; | |
114 | case TC_SUBTYPE_LOAD_K: |
|
114 | case TC_SUBTYPE_LOAD_K: | |
115 | result = action_load_kcoefficients( &TC, queue_snd_id, time ); |
|
115 | result = action_load_kcoefficients( &TC, queue_snd_id, time ); | |
116 | close_action( &TC, result, queue_snd_id ); |
|
116 | close_action( &TC, result, queue_snd_id ); | |
117 | break; |
|
117 | break; | |
118 | case TC_SUBTYPE_DUMP_K: |
|
118 | case TC_SUBTYPE_DUMP_K: | |
119 | result = action_dump_kcoefficients( &TC, queue_snd_id, time ); |
|
119 | result = action_dump_kcoefficients( &TC, queue_snd_id, time ); | |
120 | close_action( &TC, result, queue_snd_id ); |
|
120 | close_action( &TC, result, queue_snd_id ); | |
121 | break; |
|
121 | break; | |
122 | case TC_SUBTYPE_LOAD_FBINS: |
|
122 | case TC_SUBTYPE_LOAD_FBINS: | |
123 | result = action_load_fbins_mask( &TC, queue_snd_id, time ); |
|
123 | result = action_load_fbins_mask( &TC, queue_snd_id, time ); | |
124 | close_action( &TC, result, queue_snd_id ); |
|
124 | close_action( &TC, result, queue_snd_id ); | |
125 | break; |
|
125 | break; | |
126 | case TC_SUBTYPE_UPDT_TIME: |
|
126 | case TC_SUBTYPE_UPDT_TIME: | |
127 | result = action_update_time( &TC ); |
|
127 | result = action_update_time( &TC ); | |
128 | close_action( &TC, result, queue_snd_id ); |
|
128 | close_action( &TC, result, queue_snd_id ); | |
129 | break; |
|
129 | break; | |
130 | default: |
|
130 | default: | |
131 | break; |
|
131 | break; | |
132 | } |
|
132 | } | |
133 | } |
|
133 | } | |
134 | } |
|
134 | } | |
135 | } |
|
135 | } | |
136 |
|
136 | |||
137 | //*********** |
|
137 | //*********** | |
138 | // TC ACTIONS |
|
138 | // TC ACTIONS | |
139 |
|
139 | |||
140 | int action_reset(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) |
|
140 | int action_reset(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) | |
141 | { |
|
141 | { | |
142 | /** This function executes specific actions when a TC_LFR_RESET TeleCommand has been received. |
|
142 | /** This function executes specific actions when a TC_LFR_RESET TeleCommand has been received. | |
143 | * |
|
143 | * | |
144 | * @param TC points to the TeleCommand packet that is being processed |
|
144 | * @param TC points to the TeleCommand packet that is being processed | |
145 | * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver |
|
145 | * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver | |
146 | * |
|
146 | * | |
147 | */ |
|
147 | */ | |
148 |
|
148 | |||
149 | printf("this is the end!!!\n"); |
|
149 | printf("this is the end!!!\n"); | |
150 | exit(0); |
|
150 | exit(0); | |
151 | send_tm_lfr_tc_exe_not_implemented( TC, queue_id, time ); |
|
151 | send_tm_lfr_tc_exe_not_implemented( TC, queue_id, time ); | |
152 | return LFR_DEFAULT; |
|
152 | return LFR_DEFAULT; | |
153 | } |
|
153 | } | |
154 |
|
154 | |||
155 | int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id ) |
|
155 | int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id ) | |
156 | { |
|
156 | { | |
157 | /** This function executes specific actions when a TC_LFR_ENTER_MODE TeleCommand has been received. |
|
157 | /** This function executes specific actions when a TC_LFR_ENTER_MODE TeleCommand has been received. | |
158 | * |
|
158 | * | |
159 | * @param TC points to the TeleCommand packet that is being processed |
|
159 | * @param TC points to the TeleCommand packet that is being processed | |
160 | * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver |
|
160 | * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver | |
161 | * |
|
161 | * | |
162 | */ |
|
162 | */ | |
163 |
|
163 | |||
164 | rtems_status_code status; |
|
164 | rtems_status_code status; | |
165 | unsigned char requestedMode; |
|
165 | unsigned char requestedMode; | |
166 | unsigned int *transitionCoarseTime_ptr; |
|
166 | unsigned int *transitionCoarseTime_ptr; | |
167 | unsigned int transitionCoarseTime; |
|
167 | unsigned int transitionCoarseTime; | |
168 | unsigned char * bytePosPtr; |
|
168 | unsigned char * bytePosPtr; | |
169 |
|
169 | |||
170 | bytePosPtr = (unsigned char *) &TC->packetID; |
|
170 | bytePosPtr = (unsigned char *) &TC->packetID; | |
171 |
|
171 | |||
172 | requestedMode = bytePosPtr[ BYTE_POS_CP_MODE_LFR_SET ]; |
|
172 | requestedMode = bytePosPtr[ BYTE_POS_CP_MODE_LFR_SET ]; | |
173 | transitionCoarseTime_ptr = (unsigned int *) ( &bytePosPtr[ BYTE_POS_CP_LFR_ENTER_MODE_TIME ] ); |
|
173 | transitionCoarseTime_ptr = (unsigned int *) ( &bytePosPtr[ BYTE_POS_CP_LFR_ENTER_MODE_TIME ] ); | |
174 | transitionCoarseTime = (*transitionCoarseTime_ptr) & 0x7fffffff; |
|
174 | transitionCoarseTime = (*transitionCoarseTime_ptr) & 0x7fffffff; | |
175 |
|
175 | |||
176 | status = check_mode_value( requestedMode ); |
|
176 | status = check_mode_value( requestedMode ); | |
177 |
|
177 | |||
178 | if ( status != LFR_SUCCESSFUL ) // the mode value is inconsistent |
|
178 | if ( status != LFR_SUCCESSFUL ) // the mode value is inconsistent | |
179 | { |
|
179 | { | |
180 | send_tm_lfr_tc_exe_inconsistent( TC, queue_id, BYTE_POS_CP_MODE_LFR_SET, requestedMode ); |
|
180 | send_tm_lfr_tc_exe_inconsistent( TC, queue_id, BYTE_POS_CP_MODE_LFR_SET, requestedMode ); | |
181 | } |
|
181 | } | |
182 | else // the mode value is consistent, check the transition |
|
182 | else // the mode value is consistent, check the transition | |
183 | { |
|
183 | { | |
184 | status = check_mode_transition(requestedMode); |
|
184 | status = check_mode_transition(requestedMode); | |
185 | if (status != LFR_SUCCESSFUL) |
|
185 | if (status != LFR_SUCCESSFUL) | |
186 | { |
|
186 | { | |
187 | PRINTF("ERR *** in action_enter_mode *** check_mode_transition\n") |
|
187 | PRINTF("ERR *** in action_enter_mode *** check_mode_transition\n") | |
188 | send_tm_lfr_tc_exe_not_executable( TC, queue_id ); |
|
188 | send_tm_lfr_tc_exe_not_executable( TC, queue_id ); | |
189 | } |
|
189 | } | |
190 | } |
|
190 | } | |
191 |
|
191 | |||
192 | if ( status == LFR_SUCCESSFUL ) // the transition is valid, enter the mode |
|
192 | if ( status == LFR_SUCCESSFUL ) // the transition is valid, enter the mode | |
193 | { |
|
193 | { | |
194 | status = check_transition_date( transitionCoarseTime ); |
|
194 | status = check_transition_date( transitionCoarseTime ); | |
195 | if (status != LFR_SUCCESSFUL) |
|
195 | if (status != LFR_SUCCESSFUL) | |
196 | { |
|
196 | { | |
197 | PRINTF("ERR *** in action_enter_mode *** check_transition_date\n") |
|
197 | PRINTF("ERR *** in action_enter_mode *** check_transition_date\n") | |
198 | send_tm_lfr_tc_exe_inconsistent( TC, queue_id, |
|
198 | send_tm_lfr_tc_exe_inconsistent( TC, queue_id, | |
199 | BYTE_POS_CP_LFR_ENTER_MODE_TIME, |
|
199 | BYTE_POS_CP_LFR_ENTER_MODE_TIME, | |
200 | bytePosPtr[ BYTE_POS_CP_LFR_ENTER_MODE_TIME + 3 ] ); |
|
200 | bytePosPtr[ BYTE_POS_CP_LFR_ENTER_MODE_TIME + 3 ] ); | |
201 | } |
|
201 | } | |
202 | } |
|
202 | } | |
203 |
|
203 | |||
204 | if ( status == LFR_SUCCESSFUL ) // the date is valid, enter the mode |
|
204 | if ( status == LFR_SUCCESSFUL ) // the date is valid, enter the mode | |
205 | { |
|
205 | { | |
206 | PRINTF1("OK *** in action_enter_mode *** enter mode %d\n", requestedMode); |
|
206 | PRINTF1("OK *** in action_enter_mode *** enter mode %d\n", requestedMode); | |
207 | status = enter_mode( requestedMode, transitionCoarseTime ); |
|
207 | status = enter_mode( requestedMode, transitionCoarseTime ); | |
208 | } |
|
208 | } | |
209 |
|
209 | |||
210 | return status; |
|
210 | return status; | |
211 | } |
|
211 | } | |
212 |
|
212 | |||
213 | int action_update_info(ccsdsTelecommandPacket_t *TC, rtems_id queue_id) |
|
213 | int action_update_info(ccsdsTelecommandPacket_t *TC, rtems_id queue_id) | |
214 | { |
|
214 | { | |
215 | /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received. |
|
215 | /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received. | |
216 | * |
|
216 | * | |
217 | * @param TC points to the TeleCommand packet that is being processed |
|
217 | * @param TC points to the TeleCommand packet that is being processed | |
218 | * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver |
|
218 | * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver | |
219 | * |
|
219 | * | |
220 | * @return LFR directive status code: |
|
220 | * @return LFR directive status code: | |
221 | * - LFR_DEFAULT |
|
221 | * - LFR_DEFAULT | |
222 | * - LFR_SUCCESSFUL |
|
222 | * - LFR_SUCCESSFUL | |
223 | * |
|
223 | * | |
224 | */ |
|
224 | */ | |
225 |
|
225 | |||
226 | unsigned int val; |
|
226 | unsigned int val; | |
227 | int result; |
|
227 | int result; | |
228 | unsigned int status; |
|
228 | unsigned int status; | |
229 | unsigned char mode; |
|
229 | unsigned char mode; | |
230 | unsigned char * bytePosPtr; |
|
230 | unsigned char * bytePosPtr; | |
231 |
|
231 | |||
232 | bytePosPtr = (unsigned char *) &TC->packetID; |
|
232 | bytePosPtr = (unsigned char *) &TC->packetID; | |
233 |
|
233 | |||
234 | // check LFR mode |
|
234 | // check LFR mode | |
235 | mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET5 ] & 0x1e) >> 1; |
|
235 | mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET5 ] & 0x1e) >> 1; | |
236 | status = check_update_info_hk_lfr_mode( mode ); |
|
236 | status = check_update_info_hk_lfr_mode( mode ); | |
237 | if (status == LFR_SUCCESSFUL) // check TDS mode |
|
237 | if (status == LFR_SUCCESSFUL) // check TDS mode | |
238 | { |
|
238 | { | |
239 | mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & 0xf0) >> 4; |
|
239 | mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & 0xf0) >> 4; | |
240 | status = check_update_info_hk_tds_mode( mode ); |
|
240 | status = check_update_info_hk_tds_mode( mode ); | |
241 | } |
|
241 | } | |
242 | if (status == LFR_SUCCESSFUL) // check THR mode |
|
242 | if (status == LFR_SUCCESSFUL) // check THR mode | |
243 | { |
|
243 | { | |
244 | mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & 0x0f); |
|
244 | mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & 0x0f); | |
245 | status = check_update_info_hk_thr_mode( mode ); |
|
245 | status = check_update_info_hk_thr_mode( mode ); | |
246 | } |
|
246 | } | |
247 | if (status == LFR_SUCCESSFUL) // if the parameter check is successful |
|
247 | if (status == LFR_SUCCESSFUL) // if the parameter check is successful | |
248 | { |
|
248 | { | |
249 | val = housekeeping_packet.hk_lfr_update_info_tc_cnt[0] * 256 |
|
249 | val = housekeeping_packet.hk_lfr_update_info_tc_cnt[0] * 256 | |
250 | + housekeeping_packet.hk_lfr_update_info_tc_cnt[1]; |
|
250 | + housekeeping_packet.hk_lfr_update_info_tc_cnt[1]; | |
251 | val++; |
|
251 | val++; | |
252 | housekeeping_packet.hk_lfr_update_info_tc_cnt[0] = (unsigned char) (val >> 8); |
|
252 | housekeeping_packet.hk_lfr_update_info_tc_cnt[0] = (unsigned char) (val >> 8); | |
253 | housekeeping_packet.hk_lfr_update_info_tc_cnt[1] = (unsigned char) (val); |
|
253 | housekeeping_packet.hk_lfr_update_info_tc_cnt[1] = (unsigned char) (val); | |
254 | } |
|
254 | } | |
255 |
|
255 | |||
256 | result = status; |
|
256 | result = status; | |
257 |
|
257 | |||
258 | return result; |
|
258 | return result; | |
259 | } |
|
259 | } | |
260 |
|
260 | |||
261 | int action_enable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) |
|
261 | int action_enable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) | |
262 | { |
|
262 | { | |
263 | /** This function executes specific actions when a TC_LFR_ENABLE_CALIBRATION TeleCommand has been received. |
|
263 | /** This function executes specific actions when a TC_LFR_ENABLE_CALIBRATION TeleCommand has been received. | |
264 | * |
|
264 | * | |
265 | * @param TC points to the TeleCommand packet that is being processed |
|
265 | * @param TC points to the TeleCommand packet that is being processed | |
266 | * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver |
|
266 | * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver | |
267 | * |
|
267 | * | |
268 | */ |
|
268 | */ | |
269 |
|
269 | |||
270 | int result; |
|
270 | int result; | |
271 |
|
271 | |||
272 | result = LFR_DEFAULT; |
|
272 | result = LFR_DEFAULT; | |
273 |
|
273 | |||
274 | setCalibration( true ); |
|
274 | setCalibration( true ); | |
275 |
|
275 | |||
276 | result = LFR_SUCCESSFUL; |
|
276 | result = LFR_SUCCESSFUL; | |
277 |
|
277 | |||
278 | return result; |
|
278 | return result; | |
279 | } |
|
279 | } | |
280 |
|
280 | |||
281 | int action_disable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) |
|
281 | int action_disable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) | |
282 | { |
|
282 | { | |
283 | /** This function executes specific actions when a TC_LFR_DISABLE_CALIBRATION TeleCommand has been received. |
|
283 | /** This function executes specific actions when a TC_LFR_DISABLE_CALIBRATION TeleCommand has been received. | |
284 | * |
|
284 | * | |
285 | * @param TC points to the TeleCommand packet that is being processed |
|
285 | * @param TC points to the TeleCommand packet that is being processed | |
286 | * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver |
|
286 | * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver | |
287 | * |
|
287 | * | |
288 | */ |
|
288 | */ | |
289 |
|
289 | |||
290 | int result; |
|
290 | int result; | |
291 |
|
291 | |||
292 | result = LFR_DEFAULT; |
|
292 | result = LFR_DEFAULT; | |
293 |
|
293 | |||
294 | setCalibration( false ); |
|
294 | setCalibration( false ); | |
295 |
|
295 | |||
296 | result = LFR_SUCCESSFUL; |
|
296 | result = LFR_SUCCESSFUL; | |
297 |
|
297 | |||
298 | return result; |
|
298 | return result; | |
299 | } |
|
299 | } | |
300 |
|
300 | |||
301 | int action_update_time(ccsdsTelecommandPacket_t *TC) |
|
301 | int action_update_time(ccsdsTelecommandPacket_t *TC) | |
302 | { |
|
302 | { | |
303 | /** This function executes specific actions when a TC_LFR_UPDATE_TIME TeleCommand has been received. |
|
303 | /** This function executes specific actions when a TC_LFR_UPDATE_TIME TeleCommand has been received. | |
304 | * |
|
304 | * | |
305 | * @param TC points to the TeleCommand packet that is being processed |
|
305 | * @param TC points to the TeleCommand packet that is being processed | |
306 | * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver |
|
306 | * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver | |
307 | * |
|
307 | * | |
308 | * @return LFR_SUCCESSFUL |
|
308 | * @return LFR_SUCCESSFUL | |
309 | * |
|
309 | * | |
310 | */ |
|
310 | */ | |
311 |
|
311 | |||
312 | unsigned int val; |
|
312 | unsigned int val; | |
313 |
|
313 | |||
314 | time_management_regs->coarse_time_load = (TC->dataAndCRC[0] << 24) |
|
314 | time_management_regs->coarse_time_load = (TC->dataAndCRC[0] << 24) | |
315 | + (TC->dataAndCRC[1] << 16) |
|
315 | + (TC->dataAndCRC[1] << 16) | |
316 | + (TC->dataAndCRC[2] << 8) |
|
316 | + (TC->dataAndCRC[2] << 8) | |
317 | + TC->dataAndCRC[3]; |
|
317 | + TC->dataAndCRC[3]; | |
318 |
|
318 | |||
319 | val = housekeeping_packet.hk_lfr_update_time_tc_cnt[0] * 256 |
|
319 | val = housekeeping_packet.hk_lfr_update_time_tc_cnt[0] * 256 | |
320 | + housekeeping_packet.hk_lfr_update_time_tc_cnt[1]; |
|
320 | + housekeeping_packet.hk_lfr_update_time_tc_cnt[1]; | |
321 | val++; |
|
321 | val++; | |
322 | housekeeping_packet.hk_lfr_update_time_tc_cnt[0] = (unsigned char) (val >> 8); |
|
322 | housekeeping_packet.hk_lfr_update_time_tc_cnt[0] = (unsigned char) (val >> 8); | |
323 | housekeeping_packet.hk_lfr_update_time_tc_cnt[1] = (unsigned char) (val); |
|
323 | housekeeping_packet.hk_lfr_update_time_tc_cnt[1] = (unsigned char) (val); | |
324 |
|
324 | |||
325 | return LFR_SUCCESSFUL; |
|
325 | return LFR_SUCCESSFUL; | |
326 | } |
|
326 | } | |
327 |
|
327 | |||
328 | //******************* |
|
328 | //******************* | |
329 | // ENTERING THE MODES |
|
329 | // ENTERING THE MODES | |
330 | int check_mode_value( unsigned char requestedMode ) |
|
330 | int check_mode_value( unsigned char requestedMode ) | |
331 | { |
|
331 | { | |
332 | int status; |
|
332 | int status; | |
333 |
|
333 | |||
334 | if ( (requestedMode != LFR_MODE_STANDBY) |
|
334 | if ( (requestedMode != LFR_MODE_STANDBY) | |
335 | && (requestedMode != LFR_MODE_NORMAL) && (requestedMode != LFR_MODE_BURST) |
|
335 | && (requestedMode != LFR_MODE_NORMAL) && (requestedMode != LFR_MODE_BURST) | |
336 | && (requestedMode != LFR_MODE_SBM1) && (requestedMode != LFR_MODE_SBM2) ) |
|
336 | && (requestedMode != LFR_MODE_SBM1) && (requestedMode != LFR_MODE_SBM2) ) | |
337 | { |
|
337 | { | |
338 | status = LFR_DEFAULT; |
|
338 | status = LFR_DEFAULT; | |
339 | } |
|
339 | } | |
340 | else |
|
340 | else | |
341 | { |
|
341 | { | |
342 | status = LFR_SUCCESSFUL; |
|
342 | status = LFR_SUCCESSFUL; | |
343 | } |
|
343 | } | |
344 |
|
344 | |||
345 | return status; |
|
345 | return status; | |
346 | } |
|
346 | } | |
347 |
|
347 | |||
348 | int check_mode_transition( unsigned char requestedMode ) |
|
348 | int check_mode_transition( unsigned char requestedMode ) | |
349 | { |
|
349 | { | |
350 | /** This function checks the validity of the transition requested by the TC_LFR_ENTER_MODE. |
|
350 | /** This function checks the validity of the transition requested by the TC_LFR_ENTER_MODE. | |
351 | * |
|
351 | * | |
352 | * @param requestedMode is the mode requested by the TC_LFR_ENTER_MODE |
|
352 | * @param requestedMode is the mode requested by the TC_LFR_ENTER_MODE | |
353 | * |
|
353 | * | |
354 | * @return LFR directive status codes: |
|
354 | * @return LFR directive status codes: | |
355 | * - LFR_SUCCESSFUL - the transition is authorized |
|
355 | * - LFR_SUCCESSFUL - the transition is authorized | |
356 | * - LFR_DEFAULT - the transition is not authorized |
|
356 | * - LFR_DEFAULT - the transition is not authorized | |
357 | * |
|
357 | * | |
358 | */ |
|
358 | */ | |
359 |
|
359 | |||
360 | int status; |
|
360 | int status; | |
361 |
|
361 | |||
362 | switch (requestedMode) |
|
362 | switch (requestedMode) | |
363 | { |
|
363 | { | |
364 | case LFR_MODE_STANDBY: |
|
364 | case LFR_MODE_STANDBY: | |
365 | if ( lfrCurrentMode == LFR_MODE_STANDBY ) { |
|
365 | if ( lfrCurrentMode == LFR_MODE_STANDBY ) { | |
366 | status = LFR_DEFAULT; |
|
366 | status = LFR_DEFAULT; | |
367 | } |
|
367 | } | |
368 | else |
|
368 | else | |
369 | { |
|
369 | { | |
370 | status = LFR_SUCCESSFUL; |
|
370 | status = LFR_SUCCESSFUL; | |
371 | } |
|
371 | } | |
372 | break; |
|
372 | break; | |
373 | case LFR_MODE_NORMAL: |
|
373 | case LFR_MODE_NORMAL: | |
374 | if ( lfrCurrentMode == LFR_MODE_NORMAL ) { |
|
374 | if ( lfrCurrentMode == LFR_MODE_NORMAL ) { | |
375 | status = LFR_DEFAULT; |
|
375 | status = LFR_DEFAULT; | |
376 | } |
|
376 | } | |
377 | else { |
|
377 | else { | |
378 | status = LFR_SUCCESSFUL; |
|
378 | status = LFR_SUCCESSFUL; | |
379 | } |
|
379 | } | |
380 | break; |
|
380 | break; | |
381 | case LFR_MODE_BURST: |
|
381 | case LFR_MODE_BURST: | |
382 | if ( lfrCurrentMode == LFR_MODE_BURST ) { |
|
382 | if ( lfrCurrentMode == LFR_MODE_BURST ) { | |
383 | status = LFR_DEFAULT; |
|
383 | status = LFR_DEFAULT; | |
384 | } |
|
384 | } | |
385 | else { |
|
385 | else { | |
386 | status = LFR_SUCCESSFUL; |
|
386 | status = LFR_SUCCESSFUL; | |
387 | } |
|
387 | } | |
388 | break; |
|
388 | break; | |
389 | case LFR_MODE_SBM1: |
|
389 | case LFR_MODE_SBM1: | |
390 | if ( lfrCurrentMode == LFR_MODE_SBM1 ) { |
|
390 | if ( lfrCurrentMode == LFR_MODE_SBM1 ) { | |
391 | status = LFR_DEFAULT; |
|
391 | status = LFR_DEFAULT; | |
392 | } |
|
392 | } | |
393 | else { |
|
393 | else { | |
394 | status = LFR_SUCCESSFUL; |
|
394 | status = LFR_SUCCESSFUL; | |
395 | } |
|
395 | } | |
396 | break; |
|
396 | break; | |
397 | case LFR_MODE_SBM2: |
|
397 | case LFR_MODE_SBM2: | |
398 | if ( lfrCurrentMode == LFR_MODE_SBM2 ) { |
|
398 | if ( lfrCurrentMode == LFR_MODE_SBM2 ) { | |
399 | status = LFR_DEFAULT; |
|
399 | status = LFR_DEFAULT; | |
400 | } |
|
400 | } | |
401 | else { |
|
401 | else { | |
402 | status = LFR_SUCCESSFUL; |
|
402 | status = LFR_SUCCESSFUL; | |
403 | } |
|
403 | } | |
404 | break; |
|
404 | break; | |
405 | default: |
|
405 | default: | |
406 | status = LFR_DEFAULT; |
|
406 | status = LFR_DEFAULT; | |
407 | break; |
|
407 | break; | |
408 | } |
|
408 | } | |
409 |
|
409 | |||
410 | return status; |
|
410 | return status; | |
411 | } |
|
411 | } | |
412 |
|
412 | |||
413 | int check_transition_date( unsigned int transitionCoarseTime ) |
|
413 | int check_transition_date( unsigned int transitionCoarseTime ) | |
414 | { |
|
414 | { | |
415 | int status; |
|
415 | int status; | |
416 | unsigned int localCoarseTime; |
|
416 | unsigned int localCoarseTime; | |
417 | unsigned int deltaCoarseTime; |
|
417 | unsigned int deltaCoarseTime; | |
418 |
|
418 | |||
419 | status = LFR_SUCCESSFUL; |
|
419 | status = LFR_SUCCESSFUL; | |
420 |
|
420 | |||
421 | if (transitionCoarseTime == 0) // transition time = 0 means an instant transition |
|
421 | if (transitionCoarseTime == 0) // transition time = 0 means an instant transition | |
422 | { |
|
422 | { | |
423 | status = LFR_SUCCESSFUL; |
|
423 | status = LFR_SUCCESSFUL; | |
424 | } |
|
424 | } | |
425 | else |
|
425 | else | |
426 | { |
|
426 | { | |
427 | localCoarseTime = time_management_regs->coarse_time & 0x7fffffff; |
|
427 | localCoarseTime = time_management_regs->coarse_time & 0x7fffffff; | |
428 |
|
428 | |||
429 | PRINTF2("localTime = %x, transitionTime = %x\n", localCoarseTime, transitionCoarseTime) |
|
429 | PRINTF2("localTime = %x, transitionTime = %x\n", localCoarseTime, transitionCoarseTime) | |
430 |
|
430 | |||
431 | if ( transitionCoarseTime <= localCoarseTime ) // SSS-CP-EQS-322 |
|
431 | if ( transitionCoarseTime <= localCoarseTime ) // SSS-CP-EQS-322 | |
432 | { |
|
432 | { | |
433 | status = LFR_DEFAULT; |
|
433 | status = LFR_DEFAULT; | |
434 | PRINTF("ERR *** in check_transition_date *** transitionCoarseTime <= localCoarseTime\n") |
|
434 | PRINTF("ERR *** in check_transition_date *** transitionCoarseTime <= localCoarseTime\n") | |
435 | } |
|
435 | } | |
436 |
|
436 | |||
437 | if (status == LFR_SUCCESSFUL) |
|
437 | if (status == LFR_SUCCESSFUL) | |
438 | { |
|
438 | { | |
439 | deltaCoarseTime = transitionCoarseTime - localCoarseTime; |
|
439 | deltaCoarseTime = transitionCoarseTime - localCoarseTime; | |
440 | if ( deltaCoarseTime > 3 ) // SSS-CP-EQS-323 |
|
440 | if ( deltaCoarseTime > 3 ) // SSS-CP-EQS-323 | |
441 | { |
|
441 | { | |
442 | status = LFR_DEFAULT; |
|
442 | status = LFR_DEFAULT; | |
443 | PRINTF1("ERR *** in check_transition_date *** deltaCoarseTime = %x\n", deltaCoarseTime) |
|
443 | PRINTF1("ERR *** in check_transition_date *** deltaCoarseTime = %x\n", deltaCoarseTime) | |
444 | } |
|
444 | } | |
445 | } |
|
445 | } | |
446 | } |
|
446 | } | |
447 |
|
447 | |||
448 | return status; |
|
448 | return status; | |
449 | } |
|
449 | } | |
450 |
|
450 | |||
451 | int stop_current_mode( void ) |
|
451 | int stop_current_mode( void ) | |
452 | { |
|
452 | { | |
453 | /** This function stops the current mode by masking interrupt lines and suspending science tasks. |
|
453 | /** This function stops the current mode by masking interrupt lines and suspending science tasks. | |
454 | * |
|
454 | * | |
455 | * @return RTEMS directive status codes: |
|
455 | * @return RTEMS directive status codes: | |
456 | * - RTEMS_SUCCESSFUL - task restarted successfully |
|
456 | * - RTEMS_SUCCESSFUL - task restarted successfully | |
457 | * - RTEMS_INVALID_ID - task id invalid |
|
457 | * - RTEMS_INVALID_ID - task id invalid | |
458 | * - RTEMS_ALREADY_SUSPENDED - task already suspended |
|
458 | * - RTEMS_ALREADY_SUSPENDED - task already suspended | |
459 | * |
|
459 | * | |
460 | */ |
|
460 | */ | |
461 |
|
461 | |||
462 | rtems_status_code status; |
|
462 | rtems_status_code status; | |
463 |
|
463 | |||
464 | status = RTEMS_SUCCESSFUL; |
|
464 | status = RTEMS_SUCCESSFUL; | |
465 |
|
465 | |||
466 | // (1) mask interruptions |
|
466 | // (1) mask interruptions | |
467 | LEON_Mask_interrupt( IRQ_WAVEFORM_PICKER ); // mask waveform picker interrupt |
|
467 | LEON_Mask_interrupt( IRQ_WAVEFORM_PICKER ); // mask waveform picker interrupt | |
468 | LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt |
|
468 | LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt | |
469 |
|
469 | |||
470 | // (2) reset waveform picker registers |
|
470 | // (2) reset waveform picker registers | |
471 | reset_wfp_burst_enable(); // reset burst and enable bits |
|
471 | reset_wfp_burst_enable(); // reset burst and enable bits | |
472 | reset_wfp_status(); // reset all the status bits |
|
472 | reset_wfp_status(); // reset all the status bits | |
473 |
|
473 | |||
474 | // (3) reset spectral matrices registers |
|
474 | // (3) reset spectral matrices registers | |
475 | set_sm_irq_onNewMatrix( 0 ); // stop the spectral matrices |
|
475 | set_sm_irq_onNewMatrix( 0 ); // stop the spectral matrices | |
476 | reset_sm_status(); |
|
476 | reset_sm_status(); | |
477 |
|
477 | |||
478 | // reset lfr VHDL module |
|
478 | // reset lfr VHDL module | |
479 | reset_lfr(); |
|
479 | reset_lfr(); | |
480 |
|
480 | |||
481 | reset_extractSWF(); // reset the extractSWF flag to false |
|
481 | reset_extractSWF(); // reset the extractSWF flag to false | |
482 |
|
482 | |||
483 | // (4) clear interruptions |
|
483 | // (4) clear interruptions | |
484 | LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER ); // clear waveform picker interrupt |
|
484 | LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER ); // clear waveform picker interrupt | |
485 | LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt |
|
485 | LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt | |
486 |
|
486 | |||
487 | // <Spectral Matrices simulator> |
|
487 | // <Spectral Matrices simulator> | |
488 | LEON_Mask_interrupt( IRQ_SM_SIMULATOR ); // mask spectral matrix interrupt simulator |
|
488 | LEON_Mask_interrupt( IRQ_SM_SIMULATOR ); // mask spectral matrix interrupt simulator | |
489 | timer_stop( (gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_SM_SIMULATOR ); |
|
489 | timer_stop( (gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_SM_SIMULATOR ); | |
490 | LEON_Clear_interrupt( IRQ_SM_SIMULATOR ); // clear spectral matrix interrupt simulator |
|
490 | LEON_Clear_interrupt( IRQ_SM_SIMULATOR ); // clear spectral matrix interrupt simulator | |
491 | // </Spectral Matrices simulator> |
|
491 | // </Spectral Matrices simulator> | |
492 |
|
492 | |||
493 | // suspend several tasks |
|
493 | // suspend several tasks | |
494 | if (lfrCurrentMode != LFR_MODE_STANDBY) { |
|
494 | if (lfrCurrentMode != LFR_MODE_STANDBY) { | |
495 | status = suspend_science_tasks(); |
|
495 | status = suspend_science_tasks(); | |
496 | } |
|
496 | } | |
497 |
|
497 | |||
498 | if (status != RTEMS_SUCCESSFUL) |
|
498 | if (status != RTEMS_SUCCESSFUL) | |
499 | { |
|
499 | { | |
500 | PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status) |
|
500 | PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status) | |
501 | } |
|
501 | } | |
502 |
|
502 | |||
503 | return status; |
|
503 | return status; | |
504 | } |
|
504 | } | |
505 |
|
505 | |||
506 | int enter_mode( unsigned char mode, unsigned int transitionCoarseTime ) |
|
506 | int enter_mode( unsigned char mode, unsigned int transitionCoarseTime ) | |
507 | { |
|
507 | { | |
508 | /** This function is launched after a mode transition validation. |
|
508 | /** This function is launched after a mode transition validation. | |
509 | * |
|
509 | * | |
510 | * @param mode is the mode in which LFR will be put. |
|
510 | * @param mode is the mode in which LFR will be put. | |
511 | * |
|
511 | * | |
512 | * @return RTEMS directive status codes: |
|
512 | * @return RTEMS directive status codes: | |
513 | * - RTEMS_SUCCESSFUL - the mode has been entered successfully |
|
513 | * - RTEMS_SUCCESSFUL - the mode has been entered successfully | |
514 | * - RTEMS_NOT_SATISFIED - the mode has not been entered successfully |
|
514 | * - RTEMS_NOT_SATISFIED - the mode has not been entered successfully | |
515 | * |
|
515 | * | |
516 | */ |
|
516 | */ | |
517 |
|
517 | |||
518 | rtems_status_code status; |
|
518 | rtems_status_code status; | |
519 |
|
519 | |||
520 | //********************** |
|
520 | //********************** | |
521 | // STOP THE CURRENT MODE |
|
521 | // STOP THE CURRENT MODE | |
522 | status = stop_current_mode(); |
|
522 | status = stop_current_mode(); | |
523 | if (status != RTEMS_SUCCESSFUL) |
|
523 | if (status != RTEMS_SUCCESSFUL) | |
524 | { |
|
524 | { | |
525 | PRINTF1("ERR *** in enter_mode *** stop_current_mode with mode = %d\n", mode) |
|
525 | PRINTF1("ERR *** in enter_mode *** stop_current_mode with mode = %d\n", mode) | |
526 | } |
|
526 | } | |
527 |
|
527 | |||
528 | //************************* |
|
528 | //************************* | |
529 | // ENTER THE REQUESTED MODE |
|
529 | // ENTER THE REQUESTED MODE | |
530 | if ( (mode == LFR_MODE_NORMAL) || (mode == LFR_MODE_BURST) |
|
530 | if ( (mode == LFR_MODE_NORMAL) || (mode == LFR_MODE_BURST) | |
531 | || (mode == LFR_MODE_SBM1) || (mode == LFR_MODE_SBM2) ) |
|
531 | || (mode == LFR_MODE_SBM1) || (mode == LFR_MODE_SBM2) ) | |
532 | { |
|
532 | { | |
533 | #ifdef PRINT_TASK_STATISTICS |
|
533 | #ifdef PRINT_TASK_STATISTICS | |
534 | rtems_cpu_usage_reset(); |
|
534 | rtems_cpu_usage_reset(); | |
535 | #endif |
|
535 | #endif | |
536 | status = restart_science_tasks( mode ); |
|
536 | status = restart_science_tasks( mode ); | |
537 | launch_spectral_matrix( ); |
|
537 | launch_spectral_matrix( ); | |
538 | launch_waveform_picker( mode, transitionCoarseTime ); |
|
538 | launch_waveform_picker( mode, transitionCoarseTime ); | |
539 | // launch_spectral_matrix_simu( ); |
|
539 | // launch_spectral_matrix_simu( ); | |
540 | } |
|
540 | } | |
541 | else if ( mode == LFR_MODE_STANDBY ) |
|
541 | else if ( mode == LFR_MODE_STANDBY ) | |
542 | { |
|
542 | { | |
543 | #ifdef PRINT_TASK_STATISTICS |
|
543 | #ifdef PRINT_TASK_STATISTICS | |
544 | rtems_cpu_usage_report(); |
|
544 | rtems_cpu_usage_report(); | |
545 | #endif |
|
545 | #endif | |
546 |
|
546 | |||
547 | #ifdef PRINT_STACK_REPORT |
|
547 | #ifdef PRINT_STACK_REPORT | |
548 | PRINTF("stack report selected\n") |
|
548 | PRINTF("stack report selected\n") | |
549 | rtems_stack_checker_report_usage(); |
|
549 | rtems_stack_checker_report_usage(); | |
550 | #endif |
|
550 | #endif | |
551 | } |
|
551 | } | |
552 | else |
|
552 | else | |
553 | { |
|
553 | { | |
554 | status = RTEMS_UNSATISFIED; |
|
554 | status = RTEMS_UNSATISFIED; | |
555 | } |
|
555 | } | |
556 |
|
556 | |||
557 | if (status != RTEMS_SUCCESSFUL) |
|
557 | if (status != RTEMS_SUCCESSFUL) | |
558 | { |
|
558 | { | |
559 | PRINTF1("ERR *** in enter_mode *** status = %d\n", status) |
|
559 | PRINTF1("ERR *** in enter_mode *** status = %d\n", status) | |
560 | status = RTEMS_UNSATISFIED; |
|
560 | status = RTEMS_UNSATISFIED; | |
561 | } |
|
561 | } | |
562 |
|
562 | |||
563 | return status; |
|
563 | return status; | |
564 | } |
|
564 | } | |
565 |
|
565 | |||
566 | int restart_science_tasks(unsigned char lfrRequestedMode ) |
|
566 | int restart_science_tasks(unsigned char lfrRequestedMode ) | |
567 | { |
|
567 | { | |
568 | /** This function is used to restart all science tasks. |
|
568 | /** This function is used to restart all science tasks. | |
569 | * |
|
569 | * | |
570 | * @return RTEMS directive status codes: |
|
570 | * @return RTEMS directive status codes: | |
571 | * - RTEMS_SUCCESSFUL - task restarted successfully |
|
571 | * - RTEMS_SUCCESSFUL - task restarted successfully | |
572 | * - RTEMS_INVALID_ID - task id invalid |
|
572 | * - RTEMS_INVALID_ID - task id invalid | |
573 | * - RTEMS_INCORRECT_STATE - task never started |
|
573 | * - RTEMS_INCORRECT_STATE - task never started | |
574 | * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task |
|
574 | * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task | |
575 | * |
|
575 | * | |
576 | * Science tasks are AVF0, PRC0, WFRM, CWF3, CW2, CWF1 |
|
576 | * Science tasks are AVF0, PRC0, WFRM, CWF3, CW2, CWF1 | |
577 | * |
|
577 | * | |
578 | */ |
|
578 | */ | |
579 |
|
579 | |||
580 | rtems_status_code status[10]; |
|
580 | rtems_status_code status[10]; | |
581 | rtems_status_code ret; |
|
581 | rtems_status_code ret; | |
582 |
|
582 | |||
583 | ret = RTEMS_SUCCESSFUL; |
|
583 | ret = RTEMS_SUCCESSFUL; | |
584 |
|
584 | |||
585 | status[0] = rtems_task_restart( Task_id[TASKID_AVF0], lfrRequestedMode ); |
|
585 | status[0] = rtems_task_restart( Task_id[TASKID_AVF0], lfrRequestedMode ); | |
586 | if (status[0] != RTEMS_SUCCESSFUL) |
|
586 | if (status[0] != RTEMS_SUCCESSFUL) | |
587 | { |
|
587 | { | |
588 | PRINTF1("in restart_science_task *** AVF0 ERR %d\n", status[0]) |
|
588 | PRINTF1("in restart_science_task *** AVF0 ERR %d\n", status[0]) | |
589 | } |
|
589 | } | |
590 |
|
590 | |||
591 | status[1] = rtems_task_restart( Task_id[TASKID_PRC0], lfrRequestedMode ); |
|
591 | status[1] = rtems_task_restart( Task_id[TASKID_PRC0], lfrRequestedMode ); | |
592 | if (status[1] != RTEMS_SUCCESSFUL) |
|
592 | if (status[1] != RTEMS_SUCCESSFUL) | |
593 | { |
|
593 | { | |
594 | PRINTF1("in restart_science_task *** PRC0 ERR %d\n", status[1]) |
|
594 | PRINTF1("in restart_science_task *** PRC0 ERR %d\n", status[1]) | |
595 | } |
|
595 | } | |
596 |
|
596 | |||
597 | status[2] = rtems_task_restart( Task_id[TASKID_WFRM],1 ); |
|
597 | status[2] = rtems_task_restart( Task_id[TASKID_WFRM],1 ); | |
598 | if (status[2] != RTEMS_SUCCESSFUL) |
|
598 | if (status[2] != RTEMS_SUCCESSFUL) | |
599 | { |
|
599 | { | |
600 | PRINTF1("in restart_science_task *** WFRM ERR %d\n", status[2]) |
|
600 | PRINTF1("in restart_science_task *** WFRM ERR %d\n", status[2]) | |
601 | } |
|
601 | } | |
602 |
|
602 | |||
603 | status[3] = rtems_task_restart( Task_id[TASKID_CWF3],1 ); |
|
603 | status[3] = rtems_task_restart( Task_id[TASKID_CWF3],1 ); | |
604 | if (status[3] != RTEMS_SUCCESSFUL) |
|
604 | if (status[3] != RTEMS_SUCCESSFUL) | |
605 | { |
|
605 | { | |
606 | PRINTF1("in restart_science_task *** CWF3 ERR %d\n", status[3]) |
|
606 | PRINTF1("in restart_science_task *** CWF3 ERR %d\n", status[3]) | |
607 | } |
|
607 | } | |
608 |
|
608 | |||
609 | status[4] = rtems_task_restart( Task_id[TASKID_CWF2],1 ); |
|
609 | status[4] = rtems_task_restart( Task_id[TASKID_CWF2],1 ); | |
610 | if (status[4] != RTEMS_SUCCESSFUL) |
|
610 | if (status[4] != RTEMS_SUCCESSFUL) | |
611 | { |
|
611 | { | |
612 | PRINTF1("in restart_science_task *** CWF2 ERR %d\n", status[4]) |
|
612 | PRINTF1("in restart_science_task *** CWF2 ERR %d\n", status[4]) | |
613 | } |
|
613 | } | |
614 |
|
614 | |||
615 | status[5] = rtems_task_restart( Task_id[TASKID_CWF1],1 ); |
|
615 | status[5] = rtems_task_restart( Task_id[TASKID_CWF1],1 ); | |
616 | if (status[5] != RTEMS_SUCCESSFUL) |
|
616 | if (status[5] != RTEMS_SUCCESSFUL) | |
617 | { |
|
617 | { | |
618 | PRINTF1("in restart_science_task *** CWF1 ERR %d\n", status[5]) |
|
618 | PRINTF1("in restart_science_task *** CWF1 ERR %d\n", status[5]) | |
619 | } |
|
619 | } | |
620 |
|
620 | |||
621 | status[6] = rtems_task_restart( Task_id[TASKID_AVF1], lfrRequestedMode ); |
|
621 | status[6] = rtems_task_restart( Task_id[TASKID_AVF1], lfrRequestedMode ); | |
622 | if (status[6] != RTEMS_SUCCESSFUL) |
|
622 | if (status[6] != RTEMS_SUCCESSFUL) | |
623 | { |
|
623 | { | |
624 | PRINTF1("in restart_science_task *** AVF1 ERR %d\n", status[6]) |
|
624 | PRINTF1("in restart_science_task *** AVF1 ERR %d\n", status[6]) | |
625 | } |
|
625 | } | |
626 |
|
626 | |||
627 | status[7] = rtems_task_restart( Task_id[TASKID_PRC1],lfrRequestedMode ); |
|
627 | status[7] = rtems_task_restart( Task_id[TASKID_PRC1],lfrRequestedMode ); | |
628 | if (status[7] != RTEMS_SUCCESSFUL) |
|
628 | if (status[7] != RTEMS_SUCCESSFUL) | |
629 | { |
|
629 | { | |
630 | PRINTF1("in restart_science_task *** PRC1 ERR %d\n", status[7]) |
|
630 | PRINTF1("in restart_science_task *** PRC1 ERR %d\n", status[7]) | |
631 | } |
|
631 | } | |
632 |
|
632 | |||
633 | status[8] = rtems_task_restart( Task_id[TASKID_AVF2], 1 ); |
|
633 | status[8] = rtems_task_restart( Task_id[TASKID_AVF2], 1 ); | |
634 | if (status[8] != RTEMS_SUCCESSFUL) |
|
634 | if (status[8] != RTEMS_SUCCESSFUL) | |
635 | { |
|
635 | { | |
636 | PRINTF1("in restart_science_task *** AVF2 ERR %d\n", status[8]) |
|
636 | PRINTF1("in restart_science_task *** AVF2 ERR %d\n", status[8]) | |
637 | } |
|
637 | } | |
638 |
|
638 | |||
639 | status[9] = rtems_task_restart( Task_id[TASKID_PRC2], 1 ); |
|
639 | status[9] = rtems_task_restart( Task_id[TASKID_PRC2], 1 ); | |
640 | if (status[9] != RTEMS_SUCCESSFUL) |
|
640 | if (status[9] != RTEMS_SUCCESSFUL) | |
641 | { |
|
641 | { | |
642 | PRINTF1("in restart_science_task *** PRC2 ERR %d\n", status[9]) |
|
642 | PRINTF1("in restart_science_task *** PRC2 ERR %d\n", status[9]) | |
643 | } |
|
643 | } | |
644 |
|
644 | |||
645 | if ( (status[0] != RTEMS_SUCCESSFUL) || (status[1] != RTEMS_SUCCESSFUL) || |
|
645 | if ( (status[0] != RTEMS_SUCCESSFUL) || (status[1] != RTEMS_SUCCESSFUL) || | |
646 | (status[2] != RTEMS_SUCCESSFUL) || (status[3] != RTEMS_SUCCESSFUL) || |
|
646 | (status[2] != RTEMS_SUCCESSFUL) || (status[3] != RTEMS_SUCCESSFUL) || | |
647 | (status[4] != RTEMS_SUCCESSFUL) || (status[5] != RTEMS_SUCCESSFUL) || |
|
647 | (status[4] != RTEMS_SUCCESSFUL) || (status[5] != RTEMS_SUCCESSFUL) || | |
648 | (status[6] != RTEMS_SUCCESSFUL) || (status[7] != RTEMS_SUCCESSFUL) || |
|
648 | (status[6] != RTEMS_SUCCESSFUL) || (status[7] != RTEMS_SUCCESSFUL) || | |
649 | (status[8] != RTEMS_SUCCESSFUL) || (status[9] != RTEMS_SUCCESSFUL) ) |
|
649 | (status[8] != RTEMS_SUCCESSFUL) || (status[9] != RTEMS_SUCCESSFUL) ) | |
650 | { |
|
650 | { | |
651 | ret = RTEMS_UNSATISFIED; |
|
651 | ret = RTEMS_UNSATISFIED; | |
652 | } |
|
652 | } | |
653 |
|
653 | |||
654 | return ret; |
|
654 | return ret; | |
655 | } |
|
655 | } | |
656 |
|
656 | |||
657 | int suspend_science_tasks() |
|
657 | int suspend_science_tasks() | |
658 | { |
|
658 | { | |
659 | /** This function suspends the science tasks. |
|
659 | /** This function suspends the science tasks. | |
660 | * |
|
660 | * | |
661 | * @return RTEMS directive status codes: |
|
661 | * @return RTEMS directive status codes: | |
662 | * - RTEMS_SUCCESSFUL - task restarted successfully |
|
662 | * - RTEMS_SUCCESSFUL - task restarted successfully | |
663 | * - RTEMS_INVALID_ID - task id invalid |
|
663 | * - RTEMS_INVALID_ID - task id invalid | |
664 | * - RTEMS_ALREADY_SUSPENDED - task already suspended |
|
664 | * - RTEMS_ALREADY_SUSPENDED - task already suspended | |
665 | * |
|
665 | * | |
666 | */ |
|
666 | */ | |
667 |
|
667 | |||
668 | rtems_status_code status; |
|
668 | rtems_status_code status; | |
669 |
|
669 | |||
670 | printf("in suspend_science_tasks\n"); |
|
670 | printf("in suspend_science_tasks\n"); | |
671 |
|
671 | |||
672 | status = rtems_task_suspend( Task_id[TASKID_AVF0] ); // suspend AVF0 |
|
672 | status = rtems_task_suspend( Task_id[TASKID_AVF0] ); // suspend AVF0 | |
673 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
673 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | |
674 | { |
|
674 | { | |
675 | PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status) |
|
675 | PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status) | |
676 | } |
|
676 | } | |
677 | else |
|
677 | else | |
678 | { |
|
678 | { | |
679 | status = RTEMS_SUCCESSFUL; |
|
679 | status = RTEMS_SUCCESSFUL; | |
680 | } |
|
680 | } | |
681 | if (status == RTEMS_SUCCESSFUL) // suspend PRC0 |
|
681 | if (status == RTEMS_SUCCESSFUL) // suspend PRC0 | |
682 | { |
|
682 | { | |
683 | status = rtems_task_suspend( Task_id[TASKID_PRC0] ); |
|
683 | status = rtems_task_suspend( Task_id[TASKID_PRC0] ); | |
684 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
684 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | |
685 | { |
|
685 | { | |
686 | PRINTF1("in suspend_science_task *** PRC0 ERR %d\n", status) |
|
686 | PRINTF1("in suspend_science_task *** PRC0 ERR %d\n", status) | |
687 | } |
|
687 | } | |
688 | else |
|
688 | else | |
689 | { |
|
689 | { | |
690 | status = RTEMS_SUCCESSFUL; |
|
690 | status = RTEMS_SUCCESSFUL; | |
691 | } |
|
691 | } | |
692 | } |
|
692 | } | |
693 | if (status == RTEMS_SUCCESSFUL) // suspend AVF1 |
|
693 | if (status == RTEMS_SUCCESSFUL) // suspend AVF1 | |
694 | { |
|
694 | { | |
695 | status = rtems_task_suspend( Task_id[TASKID_AVF1] ); |
|
695 | status = rtems_task_suspend( Task_id[TASKID_AVF1] ); | |
696 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
696 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | |
697 | { |
|
697 | { | |
698 | PRINTF1("in suspend_science_task *** AVF1 ERR %d\n", status) |
|
698 | PRINTF1("in suspend_science_task *** AVF1 ERR %d\n", status) | |
699 | } |
|
699 | } | |
700 | else |
|
700 | else | |
701 | { |
|
701 | { | |
702 | status = RTEMS_SUCCESSFUL; |
|
702 | status = RTEMS_SUCCESSFUL; | |
703 | } |
|
703 | } | |
704 | } |
|
704 | } | |
705 | if (status == RTEMS_SUCCESSFUL) // suspend PRC1 |
|
705 | if (status == RTEMS_SUCCESSFUL) // suspend PRC1 | |
706 | { |
|
706 | { | |
707 | status = rtems_task_suspend( Task_id[TASKID_PRC1] ); |
|
707 | status = rtems_task_suspend( Task_id[TASKID_PRC1] ); | |
708 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
708 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | |
709 | { |
|
709 | { | |
710 | PRINTF1("in suspend_science_task *** PRC1 ERR %d\n", status) |
|
710 | PRINTF1("in suspend_science_task *** PRC1 ERR %d\n", status) | |
711 | } |
|
711 | } | |
712 | else |
|
712 | else | |
713 | { |
|
713 | { | |
714 | status = RTEMS_SUCCESSFUL; |
|
714 | status = RTEMS_SUCCESSFUL; | |
715 | } |
|
715 | } | |
716 | } |
|
716 | } | |
717 | if (status == RTEMS_SUCCESSFUL) // suspend AVF2 |
|
717 | if (status == RTEMS_SUCCESSFUL) // suspend AVF2 | |
718 | { |
|
718 | { | |
719 | status = rtems_task_suspend( Task_id[TASKID_AVF2] ); |
|
719 | status = rtems_task_suspend( Task_id[TASKID_AVF2] ); | |
720 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
720 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | |
721 | { |
|
721 | { | |
722 | PRINTF1("in suspend_science_task *** AVF2 ERR %d\n", status) |
|
722 | PRINTF1("in suspend_science_task *** AVF2 ERR %d\n", status) | |
723 | } |
|
723 | } | |
724 | else |
|
724 | else | |
725 | { |
|
725 | { | |
726 | status = RTEMS_SUCCESSFUL; |
|
726 | status = RTEMS_SUCCESSFUL; | |
727 | } |
|
727 | } | |
728 | } |
|
728 | } | |
729 | if (status == RTEMS_SUCCESSFUL) // suspend PRC2 |
|
729 | if (status == RTEMS_SUCCESSFUL) // suspend PRC2 | |
730 | { |
|
730 | { | |
731 | status = rtems_task_suspend( Task_id[TASKID_PRC2] ); |
|
731 | status = rtems_task_suspend( Task_id[TASKID_PRC2] ); | |
732 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
732 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | |
733 | { |
|
733 | { | |
734 | PRINTF1("in suspend_science_task *** PRC2 ERR %d\n", status) |
|
734 | PRINTF1("in suspend_science_task *** PRC2 ERR %d\n", status) | |
735 | } |
|
735 | } | |
736 | else |
|
736 | else | |
737 | { |
|
737 | { | |
738 | status = RTEMS_SUCCESSFUL; |
|
738 | status = RTEMS_SUCCESSFUL; | |
739 | } |
|
739 | } | |
740 | } |
|
740 | } | |
741 | if (status == RTEMS_SUCCESSFUL) // suspend WFRM |
|
741 | if (status == RTEMS_SUCCESSFUL) // suspend WFRM | |
742 | { |
|
742 | { | |
743 | status = rtems_task_suspend( Task_id[TASKID_WFRM] ); |
|
743 | status = rtems_task_suspend( Task_id[TASKID_WFRM] ); | |
744 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
744 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | |
745 | { |
|
745 | { | |
746 | PRINTF1("in suspend_science_task *** WFRM ERR %d\n", status) |
|
746 | PRINTF1("in suspend_science_task *** WFRM ERR %d\n", status) | |
747 | } |
|
747 | } | |
748 | else |
|
748 | else | |
749 | { |
|
749 | { | |
750 | status = RTEMS_SUCCESSFUL; |
|
750 | status = RTEMS_SUCCESSFUL; | |
751 | } |
|
751 | } | |
752 | } |
|
752 | } | |
753 | if (status == RTEMS_SUCCESSFUL) // suspend CWF3 |
|
753 | if (status == RTEMS_SUCCESSFUL) // suspend CWF3 | |
754 | { |
|
754 | { | |
755 | status = rtems_task_suspend( Task_id[TASKID_CWF3] ); |
|
755 | status = rtems_task_suspend( Task_id[TASKID_CWF3] ); | |
756 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
756 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | |
757 | { |
|
757 | { | |
758 | PRINTF1("in suspend_science_task *** CWF3 ERR %d\n", status) |
|
758 | PRINTF1("in suspend_science_task *** CWF3 ERR %d\n", status) | |
759 | } |
|
759 | } | |
760 | else |
|
760 | else | |
761 | { |
|
761 | { | |
762 | status = RTEMS_SUCCESSFUL; |
|
762 | status = RTEMS_SUCCESSFUL; | |
763 | } |
|
763 | } | |
764 | } |
|
764 | } | |
765 | if (status == RTEMS_SUCCESSFUL) // suspend CWF2 |
|
765 | if (status == RTEMS_SUCCESSFUL) // suspend CWF2 | |
766 | { |
|
766 | { | |
767 | status = rtems_task_suspend( Task_id[TASKID_CWF2] ); |
|
767 | status = rtems_task_suspend( Task_id[TASKID_CWF2] ); | |
768 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
768 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | |
769 | { |
|
769 | { | |
770 | PRINTF1("in suspend_science_task *** CWF2 ERR %d\n", status) |
|
770 | PRINTF1("in suspend_science_task *** CWF2 ERR %d\n", status) | |
771 | } |
|
771 | } | |
772 | else |
|
772 | else | |
773 | { |
|
773 | { | |
774 | status = RTEMS_SUCCESSFUL; |
|
774 | status = RTEMS_SUCCESSFUL; | |
775 | } |
|
775 | } | |
776 | } |
|
776 | } | |
777 | if (status == RTEMS_SUCCESSFUL) // suspend CWF1 |
|
777 | if (status == RTEMS_SUCCESSFUL) // suspend CWF1 | |
778 | { |
|
778 | { | |
779 | status = rtems_task_suspend( Task_id[TASKID_CWF1] ); |
|
779 | status = rtems_task_suspend( Task_id[TASKID_CWF1] ); | |
780 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
780 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) | |
781 | { |
|
781 | { | |
782 | PRINTF1("in suspend_science_task *** CWF1 ERR %d\n", status) |
|
782 | PRINTF1("in suspend_science_task *** CWF1 ERR %d\n", status) | |
783 | } |
|
783 | } | |
784 | else |
|
784 | else | |
785 | { |
|
785 | { | |
786 | status = RTEMS_SUCCESSFUL; |
|
786 | status = RTEMS_SUCCESSFUL; | |
787 | } |
|
787 | } | |
788 | } |
|
788 | } | |
789 |
|
789 | |||
790 | return status; |
|
790 | return status; | |
791 | } |
|
791 | } | |
792 |
|
792 | |||
793 | void launch_waveform_picker( unsigned char mode, unsigned int transitionCoarseTime ) |
|
793 | void launch_waveform_picker( unsigned char mode, unsigned int transitionCoarseTime ) | |
794 | { |
|
794 | { | |
795 | WFP_reset_current_ring_nodes(); |
|
795 | WFP_reset_current_ring_nodes(); | |
796 |
|
796 | |||
797 | reset_waveform_picker_regs(); |
|
797 | reset_waveform_picker_regs(); | |
798 |
|
798 | |||
799 | set_wfp_burst_enable_register( mode ); |
|
799 | set_wfp_burst_enable_register( mode ); | |
800 |
|
800 | |||
801 | LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER ); |
|
801 | LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER ); | |
802 | LEON_Unmask_interrupt( IRQ_WAVEFORM_PICKER ); |
|
802 | LEON_Unmask_interrupt( IRQ_WAVEFORM_PICKER ); | |
803 |
|
803 | |||
804 | if (transitionCoarseTime == 0) |
|
804 | if (transitionCoarseTime == 0) | |
805 | { |
|
805 | { | |
806 | waveform_picker_regs->start_date = time_management_regs->coarse_time; |
|
806 | waveform_picker_regs->start_date = time_management_regs->coarse_time; | |
807 | } |
|
807 | } | |
808 | else |
|
808 | else | |
809 | { |
|
809 | { | |
810 | waveform_picker_regs->start_date = transitionCoarseTime; |
|
810 | waveform_picker_regs->start_date = transitionCoarseTime; | |
811 | } |
|
811 | } | |
812 |
|
812 | |||
813 | } |
|
813 | } | |
814 |
|
814 | |||
815 | void launch_spectral_matrix( void ) |
|
815 | void launch_spectral_matrix( void ) | |
816 | { |
|
816 | { | |
817 | SM_reset_current_ring_nodes(); |
|
817 | SM_reset_current_ring_nodes(); | |
818 |
|
818 | |||
819 | reset_spectral_matrix_regs(); |
|
819 | reset_spectral_matrix_regs(); | |
820 |
|
820 | |||
821 | reset_nb_sm(); |
|
821 | reset_nb_sm(); | |
822 |
|
822 | |||
823 | set_sm_irq_onNewMatrix( 1 ); |
|
823 | set_sm_irq_onNewMatrix( 1 ); | |
824 |
|
824 | |||
825 | LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); |
|
825 | LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); | |
826 | LEON_Unmask_interrupt( IRQ_SPECTRAL_MATRIX ); |
|
826 | LEON_Unmask_interrupt( IRQ_SPECTRAL_MATRIX ); | |
827 |
|
827 | |||
828 | } |
|
828 | } | |
829 |
|
829 | |||
830 | void launch_spectral_matrix_simu( void ) |
|
830 | void launch_spectral_matrix_simu( void ) | |
831 | { |
|
831 | { | |
832 | SM_reset_current_ring_nodes(); |
|
832 | SM_reset_current_ring_nodes(); | |
833 | reset_spectral_matrix_regs(); |
|
833 | reset_spectral_matrix_regs(); | |
834 | reset_nb_sm(); |
|
834 | reset_nb_sm(); | |
835 |
|
835 | |||
836 | // Spectral Matrices simulator |
|
836 | // Spectral Matrices simulator | |
837 | timer_start( (gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_SM_SIMULATOR ); |
|
837 | timer_start( (gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_SM_SIMULATOR ); | |
838 | LEON_Clear_interrupt( IRQ_SM_SIMULATOR ); |
|
838 | LEON_Clear_interrupt( IRQ_SM_SIMULATOR ); | |
839 | LEON_Unmask_interrupt( IRQ_SM_SIMULATOR ); |
|
839 | LEON_Unmask_interrupt( IRQ_SM_SIMULATOR ); | |
840 | } |
|
840 | } | |
841 |
|
841 | |||
842 | void set_sm_irq_onNewMatrix( unsigned char value ) |
|
842 | void set_sm_irq_onNewMatrix( unsigned char value ) | |
843 | { |
|
843 | { | |
844 | if (value == 1) |
|
844 | if (value == 1) | |
845 | { |
|
845 | { | |
846 | spectral_matrix_regs->config = spectral_matrix_regs->config | 0x01; |
|
846 | spectral_matrix_regs->config = spectral_matrix_regs->config | 0x01; | |
847 | } |
|
847 | } | |
848 | else |
|
848 | else | |
849 | { |
|
849 | { | |
850 | spectral_matrix_regs->config = spectral_matrix_regs->config & 0xfffffffe; // 1110 |
|
850 | spectral_matrix_regs->config = spectral_matrix_regs->config & 0xfffffffe; // 1110 | |
851 | } |
|
851 | } | |
852 | } |
|
852 | } | |
853 |
|
853 | |||
854 | void set_sm_irq_onError( unsigned char value ) |
|
854 | void set_sm_irq_onError( unsigned char value ) | |
855 | { |
|
855 | { | |
856 | if (value == 1) |
|
856 | if (value == 1) | |
857 | { |
|
857 | { | |
858 | spectral_matrix_regs->config = spectral_matrix_regs->config | 0x02; |
|
858 | spectral_matrix_regs->config = spectral_matrix_regs->config | 0x02; | |
859 | } |
|
859 | } | |
860 | else |
|
860 | else | |
861 | { |
|
861 | { | |
862 | spectral_matrix_regs->config = spectral_matrix_regs->config & 0xfffffffd; // 1101 |
|
862 | spectral_matrix_regs->config = spectral_matrix_regs->config & 0xfffffffd; // 1101 | |
863 | } |
|
863 | } | |
864 | } |
|
864 | } | |
865 |
|
865 | |||
866 | //***************************** |
|
866 | //***************************** | |
867 | // CONFIGURE CALIBRATION SIGNAL |
|
867 | // CONFIGURE CALIBRATION SIGNAL | |
868 | void setCalibrationPrescaler( unsigned int prescaler ) |
|
868 | void setCalibrationPrescaler( unsigned int prescaler ) | |
869 | { |
|
869 | { | |
870 | // prescaling of the master clock (25 MHz) |
|
870 | // prescaling of the master clock (25 MHz) | |
871 | // master clock is divided by 2^prescaler |
|
871 | // master clock is divided by 2^prescaler | |
872 | time_management_regs->calPrescaler = prescaler; |
|
872 | time_management_regs->calPrescaler = prescaler; | |
873 | } |
|
873 | } | |
874 |
|
874 | |||
875 | void setCalibrationDivisor( unsigned int divisionFactor ) |
|
875 | void setCalibrationDivisor( unsigned int divisionFactor ) | |
876 | { |
|
876 | { | |
877 | // division of the prescaled clock by the division factor |
|
877 | // division of the prescaled clock by the division factor | |
878 | time_management_regs->calDivisor = divisionFactor; |
|
878 | time_management_regs->calDivisor = divisionFactor; | |
879 | } |
|
879 | } | |
880 |
|
880 | |||
881 | void setCalibrationData( void ){ |
|
881 | void setCalibrationData( void ){ | |
882 | unsigned int k; |
|
882 | unsigned int k; | |
883 | unsigned short data; |
|
883 | unsigned short data; | |
884 | float val; |
|
884 | float val; | |
885 | float f0; |
|
885 | float f0; | |
886 | float f1; |
|
886 | float f1; | |
887 | float fs; |
|
887 | float fs; | |
888 | float Ts; |
|
888 | float Ts; | |
889 | float scaleFactor; |
|
889 | float scaleFactor; | |
890 |
|
890 | |||
891 | f0 = 625; |
|
891 | f0 = 625; | |
892 | f1 = 10000; |
|
892 | f1 = 10000; | |
893 | fs = 160256.410; |
|
893 | fs = 160256.410; | |
894 | Ts = 1. / fs; |
|
894 | Ts = 1. / fs; | |
895 | scaleFactor = 0.125 / 0.000654; // 191, 500 mVpp, 2 sinus waves => 250 mVpp each, amplitude = 125 mV |
|
895 | scaleFactor = 0.125 / 0.000654; // 191, 500 mVpp, 2 sinus waves => 250 mVpp each, amplitude = 125 mV | |
896 |
|
896 | |||
897 | time_management_regs->calDataPtr = 0x00; |
|
897 | time_management_regs->calDataPtr = 0x00; | |
898 |
|
898 | |||
899 | // build the signal for the SCM calibration |
|
899 | // build the signal for the SCM calibration | |
900 | for (k=0; k<256; k++) |
|
900 | for (k=0; k<256; k++) | |
901 | { |
|
901 | { | |
902 | val = sin( 2 * pi * f0 * k * Ts ) |
|
902 | val = sin( 2 * pi * f0 * k * Ts ) | |
903 | + sin( 2 * pi * f1 * k * Ts ); |
|
903 | + sin( 2 * pi * f1 * k * Ts ); | |
904 | data = (unsigned short) ((val * scaleFactor) + 2048); |
|
904 | data = (unsigned short) ((val * scaleFactor) + 2048); | |
905 | time_management_regs->calData = data & 0xfff; |
|
905 | time_management_regs->calData = data & 0xfff; | |
906 | } |
|
906 | } | |
907 | } |
|
907 | } | |
908 |
|
908 | |||
909 | void setCalibrationDataInterleaved( void ){ |
|
909 | void setCalibrationDataInterleaved( void ){ | |
910 | unsigned int k; |
|
910 | unsigned int k; | |
911 | float val; |
|
911 | float val; | |
912 | float f0; |
|
912 | float f0; | |
913 | float f1; |
|
913 | float f1; | |
914 | float fs; |
|
914 | float fs; | |
915 | float Ts; |
|
915 | float Ts; | |
916 | unsigned short data[384]; |
|
916 | unsigned short data[384]; | |
917 | unsigned char *dataPtr; |
|
917 | unsigned char *dataPtr; | |
918 |
|
918 | |||
919 | f0 = 625; |
|
919 | f0 = 625; | |
920 | f1 = 10000; |
|
920 | f1 = 10000; | |
921 | fs = 240384.615; |
|
921 | fs = 240384.615; | |
922 | Ts = 1. / fs; |
|
922 | Ts = 1. / fs; | |
923 |
|
923 | |||
924 | time_management_regs->calDataPtr = 0x00; |
|
924 | time_management_regs->calDataPtr = 0x00; | |
925 |
|
925 | |||
926 | // build the signal for the SCM calibration |
|
926 | // build the signal for the SCM calibration | |
927 | for (k=0; k<384; k++) |
|
927 | for (k=0; k<384; k++) | |
928 | { |
|
928 | { | |
929 | val = sin( 2 * pi * f0 * k * Ts ) |
|
929 | val = sin( 2 * pi * f0 * k * Ts ) | |
930 | + sin( 2 * pi * f1 * k * Ts ); |
|
930 | + sin( 2 * pi * f1 * k * Ts ); | |
931 | data[k] = (unsigned short) (val * 512 + 2048); |
|
931 | data[k] = (unsigned short) (val * 512 + 2048); | |
932 | } |
|
932 | } | |
933 |
|
933 | |||
934 | // write the signal in interleaved mode |
|
934 | // write the signal in interleaved mode | |
935 | for (k=0; k<128; k++) |
|
935 | for (k=0; k<128; k++) | |
936 | { |
|
936 | { | |
937 | dataPtr = (unsigned char*) &data[k*3 + 2]; |
|
937 | dataPtr = (unsigned char*) &data[k*3 + 2]; | |
938 | time_management_regs->calData = (data[k*3] & 0xfff) |
|
938 | time_management_regs->calData = (data[k*3] & 0xfff) | |
939 | + ( (dataPtr[0] & 0x3f) << 12); |
|
939 | + ( (dataPtr[0] & 0x3f) << 12); | |
940 | time_management_regs->calData = (data[k*3 + 1] & 0xfff) |
|
940 | time_management_regs->calData = (data[k*3 + 1] & 0xfff) | |
941 | + ( (dataPtr[1] & 0x3f) << 12); |
|
941 | + ( (dataPtr[1] & 0x3f) << 12); | |
942 | } |
|
942 | } | |
943 | } |
|
943 | } | |
944 |
|
944 | |||
945 | void setCalibrationReload( bool state) |
|
945 | void setCalibrationReload( bool state) | |
946 | { |
|
946 | { | |
947 | if (state == true) |
|
947 | if (state == true) | |
948 | { |
|
948 | { | |
949 | time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | 0x00000010; // [0001 0000] |
|
949 | time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | 0x00000010; // [0001 0000] | |
950 | } |
|
950 | } | |
951 | else |
|
951 | else | |
952 | { |
|
952 | { | |
953 | time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & 0xffffffef; // [1110 1111] |
|
953 | time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & 0xffffffef; // [1110 1111] | |
954 | } |
|
954 | } | |
955 | } |
|
955 | } | |
956 |
|
956 | |||
957 | void setCalibrationEnable( bool state ) |
|
957 | void setCalibrationEnable( bool state ) | |
958 | { |
|
958 | { | |
959 | // this bit drives the multiplexer |
|
959 | // this bit drives the multiplexer | |
960 | if (state == true) |
|
960 | if (state == true) | |
961 | { |
|
961 | { | |
962 | time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | 0x00000040; // [0100 0000] |
|
962 | time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | 0x00000040; // [0100 0000] | |
963 | } |
|
963 | } | |
964 | else |
|
964 | else | |
965 | { |
|
965 | { | |
966 | time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & 0xffffffbf; // [1011 1111] |
|
966 | time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & 0xffffffbf; // [1011 1111] | |
967 | } |
|
967 | } | |
968 | } |
|
968 | } | |
969 |
|
969 | |||
970 | void setCalibrationInterleaved( bool state ) |
|
970 | void setCalibrationInterleaved( bool state ) | |
971 | { |
|
971 | { | |
972 | // this bit drives the multiplexer |
|
972 | // this bit drives the multiplexer | |
973 | if (state == true) |
|
973 | if (state == true) | |
974 | { |
|
974 | { | |
975 | time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | 0x00000020; // [0010 0000] |
|
975 | time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | 0x00000020; // [0010 0000] | |
976 | } |
|
976 | } | |
977 | else |
|
977 | else | |
978 | { |
|
978 | { | |
979 | time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & 0xffffffdf; // [1101 1111] |
|
979 | time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & 0xffffffdf; // [1101 1111] | |
980 | } |
|
980 | } | |
981 | } |
|
981 | } | |
982 |
|
982 | |||
983 | void setCalibration( bool state ) |
|
983 | void setCalibration( bool state ) | |
984 | { |
|
984 | { | |
985 | if (state == true) |
|
985 | if (state == true) | |
986 | { |
|
986 | { | |
987 | setCalibrationEnable( true ); |
|
987 | setCalibrationEnable( true ); | |
988 | setCalibrationReload( false ); |
|
988 | setCalibrationReload( false ); | |
989 | set_hk_lfr_calib_enable( true ); |
|
989 | set_hk_lfr_calib_enable( true ); | |
990 | } |
|
990 | } | |
991 | else |
|
991 | else | |
992 | { |
|
992 | { | |
993 | setCalibrationEnable( false ); |
|
993 | setCalibrationEnable( false ); | |
994 | setCalibrationReload( true ); |
|
994 | setCalibrationReload( true ); | |
995 | set_hk_lfr_calib_enable( false ); |
|
995 | set_hk_lfr_calib_enable( false ); | |
996 | } |
|
996 | } | |
997 | } |
|
997 | } | |
998 |
|
998 | |||
999 | void set_hk_lfr_calib_enable( bool state ) |
|
|||
1000 | { |
|
|||
1001 | if (state == true) |
|
|||
1002 | { |
|
|||
1003 | housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] | 0x08; // [0000 1000] |
|
|||
1004 | } |
|
|||
1005 | else |
|
|||
1006 | { |
|
|||
1007 | housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] & 0xf7; // [1111 0111] |
|
|||
1008 | } |
|
|||
1009 | } |
|
|||
1010 |
|
||||
1011 | void configureCalibration( bool interleaved ) |
|
999 | void configureCalibration( bool interleaved ) | |
1012 | { |
|
1000 | { | |
1013 | setCalibration( false ); |
|
1001 | setCalibration( false ); | |
1014 | if ( interleaved == true ) |
|
1002 | if ( interleaved == true ) | |
1015 | { |
|
1003 | { | |
1016 | setCalibrationInterleaved( true ); |
|
1004 | setCalibrationInterleaved( true ); | |
1017 | setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000 |
|
1005 | setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000 | |
1018 | setCalibrationDivisor( 26 ); // => 240 384 |
|
1006 | setCalibrationDivisor( 26 ); // => 240 384 | |
1019 | setCalibrationDataInterleaved(); |
|
1007 | setCalibrationDataInterleaved(); | |
1020 | } |
|
1008 | } | |
1021 | else |
|
1009 | else | |
1022 | { |
|
1010 | { | |
1023 | setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000 |
|
1011 | setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000 | |
1024 | setCalibrationDivisor( 38 ); // => 160 256 (39 - 1) |
|
1012 | setCalibrationDivisor( 38 ); // => 160 256 (39 - 1) | |
1025 | setCalibrationData(); |
|
1013 | setCalibrationData(); | |
1026 | } |
|
1014 | } | |
1027 | } |
|
1015 | } | |
1028 |
|
1016 | |||
1029 | //**************** |
|
1017 | //**************** | |
1030 | // CLOSING ACTIONS |
|
1018 | // CLOSING ACTIONS | |
1031 | void update_last_TC_exe( ccsdsTelecommandPacket_t *TC, unsigned char * time ) |
|
1019 | void update_last_TC_exe( ccsdsTelecommandPacket_t *TC, unsigned char * time ) | |
1032 | { |
|
1020 | { | |
1033 | /** This function is used to update the HK packets statistics after a successful TC execution. |
|
1021 | /** This function is used to update the HK packets statistics after a successful TC execution. | |
1034 | * |
|
1022 | * | |
1035 | * @param TC points to the TC being processed |
|
1023 | * @param TC points to the TC being processed | |
1036 | * @param time is the time used to date the TC execution |
|
1024 | * @param time is the time used to date the TC execution | |
1037 | * |
|
1025 | * | |
1038 | */ |
|
1026 | */ | |
1039 |
|
1027 | |||
1040 | unsigned int val; |
|
1028 | unsigned int val; | |
1041 |
|
1029 | |||
1042 | housekeeping_packet.hk_lfr_last_exe_tc_id[0] = TC->packetID[0]; |
|
1030 | housekeeping_packet.hk_lfr_last_exe_tc_id[0] = TC->packetID[0]; | |
1043 | housekeeping_packet.hk_lfr_last_exe_tc_id[1] = TC->packetID[1]; |
|
1031 | housekeeping_packet.hk_lfr_last_exe_tc_id[1] = TC->packetID[1]; | |
1044 | housekeeping_packet.hk_lfr_last_exe_tc_type[0] = 0x00; |
|
1032 | housekeeping_packet.hk_lfr_last_exe_tc_type[0] = 0x00; | |
1045 | housekeeping_packet.hk_lfr_last_exe_tc_type[1] = TC->serviceType; |
|
1033 | housekeeping_packet.hk_lfr_last_exe_tc_type[1] = TC->serviceType; | |
1046 | housekeeping_packet.hk_lfr_last_exe_tc_subtype[0] = 0x00; |
|
1034 | housekeeping_packet.hk_lfr_last_exe_tc_subtype[0] = 0x00; | |
1047 | housekeeping_packet.hk_lfr_last_exe_tc_subtype[1] = TC->serviceSubType; |
|
1035 | housekeeping_packet.hk_lfr_last_exe_tc_subtype[1] = TC->serviceSubType; | |
1048 | housekeeping_packet.hk_lfr_last_exe_tc_time[0] = time[0]; |
|
1036 | housekeeping_packet.hk_lfr_last_exe_tc_time[0] = time[0]; | |
1049 | housekeeping_packet.hk_lfr_last_exe_tc_time[1] = time[1]; |
|
1037 | housekeeping_packet.hk_lfr_last_exe_tc_time[1] = time[1]; | |
1050 | housekeeping_packet.hk_lfr_last_exe_tc_time[2] = time[2]; |
|
1038 | housekeeping_packet.hk_lfr_last_exe_tc_time[2] = time[2]; | |
1051 | housekeeping_packet.hk_lfr_last_exe_tc_time[3] = time[3]; |
|
1039 | housekeeping_packet.hk_lfr_last_exe_tc_time[3] = time[3]; | |
1052 | housekeeping_packet.hk_lfr_last_exe_tc_time[4] = time[4]; |
|
1040 | housekeeping_packet.hk_lfr_last_exe_tc_time[4] = time[4]; | |
1053 | housekeeping_packet.hk_lfr_last_exe_tc_time[5] = time[5]; |
|
1041 | housekeeping_packet.hk_lfr_last_exe_tc_time[5] = time[5]; | |
1054 |
|
1042 | |||
1055 | val = housekeeping_packet.hk_lfr_exe_tc_cnt[0] * 256 + housekeeping_packet.hk_lfr_exe_tc_cnt[1]; |
|
1043 | val = housekeeping_packet.hk_lfr_exe_tc_cnt[0] * 256 + housekeeping_packet.hk_lfr_exe_tc_cnt[1]; | |
1056 | val++; |
|
1044 | val++; | |
1057 | housekeeping_packet.hk_lfr_exe_tc_cnt[0] = (unsigned char) (val >> 8); |
|
1045 | housekeeping_packet.hk_lfr_exe_tc_cnt[0] = (unsigned char) (val >> 8); | |
1058 | housekeeping_packet.hk_lfr_exe_tc_cnt[1] = (unsigned char) (val); |
|
1046 | housekeeping_packet.hk_lfr_exe_tc_cnt[1] = (unsigned char) (val); | |
1059 | } |
|
1047 | } | |
1060 |
|
1048 | |||
1061 | void update_last_TC_rej(ccsdsTelecommandPacket_t *TC, unsigned char * time ) |
|
1049 | void update_last_TC_rej(ccsdsTelecommandPacket_t *TC, unsigned char * time ) | |
1062 | { |
|
1050 | { | |
1063 | /** This function is used to update the HK packets statistics after a TC rejection. |
|
1051 | /** This function is used to update the HK packets statistics after a TC rejection. | |
1064 | * |
|
1052 | * | |
1065 | * @param TC points to the TC being processed |
|
1053 | * @param TC points to the TC being processed | |
1066 | * @param time is the time used to date the TC rejection |
|
1054 | * @param time is the time used to date the TC rejection | |
1067 | * |
|
1055 | * | |
1068 | */ |
|
1056 | */ | |
1069 |
|
1057 | |||
1070 | unsigned int val; |
|
1058 | unsigned int val; | |
1071 |
|
1059 | |||
1072 | housekeeping_packet.hk_lfr_last_rej_tc_id[0] = TC->packetID[0]; |
|
1060 | housekeeping_packet.hk_lfr_last_rej_tc_id[0] = TC->packetID[0]; | |
1073 | housekeeping_packet.hk_lfr_last_rej_tc_id[1] = TC->packetID[1]; |
|
1061 | housekeeping_packet.hk_lfr_last_rej_tc_id[1] = TC->packetID[1]; | |
1074 | housekeeping_packet.hk_lfr_last_rej_tc_type[0] = 0x00; |
|
1062 | housekeeping_packet.hk_lfr_last_rej_tc_type[0] = 0x00; | |
1075 | housekeeping_packet.hk_lfr_last_rej_tc_type[1] = TC->serviceType; |
|
1063 | housekeeping_packet.hk_lfr_last_rej_tc_type[1] = TC->serviceType; | |
1076 | housekeeping_packet.hk_lfr_last_rej_tc_subtype[0] = 0x00; |
|
1064 | housekeeping_packet.hk_lfr_last_rej_tc_subtype[0] = 0x00; | |
1077 | housekeeping_packet.hk_lfr_last_rej_tc_subtype[1] = TC->serviceSubType; |
|
1065 | housekeeping_packet.hk_lfr_last_rej_tc_subtype[1] = TC->serviceSubType; | |
1078 | housekeeping_packet.hk_lfr_last_rej_tc_time[0] = time[0]; |
|
1066 | housekeeping_packet.hk_lfr_last_rej_tc_time[0] = time[0]; | |
1079 | housekeeping_packet.hk_lfr_last_rej_tc_time[1] = time[1]; |
|
1067 | housekeeping_packet.hk_lfr_last_rej_tc_time[1] = time[1]; | |
1080 | housekeeping_packet.hk_lfr_last_rej_tc_time[2] = time[2]; |
|
1068 | housekeeping_packet.hk_lfr_last_rej_tc_time[2] = time[2]; | |
1081 | housekeeping_packet.hk_lfr_last_rej_tc_time[3] = time[3]; |
|
1069 | housekeeping_packet.hk_lfr_last_rej_tc_time[3] = time[3]; | |
1082 | housekeeping_packet.hk_lfr_last_rej_tc_time[4] = time[4]; |
|
1070 | housekeeping_packet.hk_lfr_last_rej_tc_time[4] = time[4]; | |
1083 | housekeeping_packet.hk_lfr_last_rej_tc_time[5] = time[5]; |
|
1071 | housekeeping_packet.hk_lfr_last_rej_tc_time[5] = time[5]; | |
1084 |
|
1072 | |||
1085 | val = housekeeping_packet.hk_lfr_rej_tc_cnt[0] * 256 + housekeeping_packet.hk_lfr_rej_tc_cnt[1]; |
|
1073 | val = housekeeping_packet.hk_lfr_rej_tc_cnt[0] * 256 + housekeeping_packet.hk_lfr_rej_tc_cnt[1]; | |
1086 | val++; |
|
1074 | val++; | |
1087 | housekeeping_packet.hk_lfr_rej_tc_cnt[0] = (unsigned char) (val >> 8); |
|
1075 | housekeeping_packet.hk_lfr_rej_tc_cnt[0] = (unsigned char) (val >> 8); | |
1088 | housekeeping_packet.hk_lfr_rej_tc_cnt[1] = (unsigned char) (val); |
|
1076 | housekeeping_packet.hk_lfr_rej_tc_cnt[1] = (unsigned char) (val); | |
1089 | } |
|
1077 | } | |
1090 |
|
1078 | |||
1091 | void close_action(ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id ) |
|
1079 | void close_action(ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id ) | |
1092 | { |
|
1080 | { | |
1093 | /** This function is the last step of the TC execution workflow. |
|
1081 | /** This function is the last step of the TC execution workflow. | |
1094 | * |
|
1082 | * | |
1095 | * @param TC points to the TC being processed |
|
1083 | * @param TC points to the TC being processed | |
1096 | * @param result is the result of the TC execution (LFR_SUCCESSFUL / LFR_DEFAULT) |
|
1084 | * @param result is the result of the TC execution (LFR_SUCCESSFUL / LFR_DEFAULT) | |
1097 | * @param queue_id is the id of the RTEMS message queue used to send TM packets |
|
1085 | * @param queue_id is the id of the RTEMS message queue used to send TM packets | |
1098 | * @param time is the time used to date the TC execution |
|
1086 | * @param time is the time used to date the TC execution | |
1099 | * |
|
1087 | * | |
1100 | */ |
|
1088 | */ | |
1101 |
|
1089 | |||
1102 | unsigned char requestedMode; |
|
1090 | unsigned char requestedMode; | |
1103 |
|
1091 | |||
1104 | if (result == LFR_SUCCESSFUL) |
|
1092 | if (result == LFR_SUCCESSFUL) | |
1105 | { |
|
1093 | { | |
1106 | if ( !( (TC->serviceType==TC_TYPE_TIME) & (TC->serviceSubType==TC_SUBTYPE_UPDT_TIME) ) |
|
1094 | if ( !( (TC->serviceType==TC_TYPE_TIME) & (TC->serviceSubType==TC_SUBTYPE_UPDT_TIME) ) | |
1107 | & |
|
1095 | & | |
1108 | !( (TC->serviceType==TC_TYPE_GEN) & (TC->serviceSubType==TC_SUBTYPE_UPDT_INFO)) |
|
1096 | !( (TC->serviceType==TC_TYPE_GEN) & (TC->serviceSubType==TC_SUBTYPE_UPDT_INFO)) | |
1109 | ) |
|
1097 | ) | |
1110 | { |
|
1098 | { | |
1111 | send_tm_lfr_tc_exe_success( TC, queue_id ); |
|
1099 | send_tm_lfr_tc_exe_success( TC, queue_id ); | |
1112 | } |
|
1100 | } | |
1113 | if ( (TC->serviceType == TC_TYPE_GEN) & (TC->serviceSubType == TC_SUBTYPE_ENTER) ) |
|
1101 | if ( (TC->serviceType == TC_TYPE_GEN) & (TC->serviceSubType == TC_SUBTYPE_ENTER) ) | |
1114 | { |
|
1102 | { | |
1115 | //********************************** |
|
1103 | //********************************** | |
1116 | // UPDATE THE LFRMODE LOCAL VARIABLE |
|
1104 | // UPDATE THE LFRMODE LOCAL VARIABLE | |
1117 | requestedMode = TC->dataAndCRC[1]; |
|
1105 | requestedMode = TC->dataAndCRC[1]; | |
1118 | housekeeping_packet.lfr_status_word[0] = (unsigned char) ((requestedMode << 4) + 0x0d); |
|
1106 | housekeeping_packet.lfr_status_word[0] = (unsigned char) ((requestedMode << 4) + 0x0d); | |
1119 | updateLFRCurrentMode(); |
|
1107 | updateLFRCurrentMode(); | |
1120 | } |
|
1108 | } | |
1121 | } |
|
1109 | } | |
1122 | else if (result == LFR_EXE_ERROR) |
|
1110 | else if (result == LFR_EXE_ERROR) | |
1123 | { |
|
1111 | { | |
1124 | send_tm_lfr_tc_exe_error( TC, queue_id ); |
|
1112 | send_tm_lfr_tc_exe_error( TC, queue_id ); | |
1125 | } |
|
1113 | } | |
1126 | } |
|
1114 | } | |
1127 |
|
1115 | |||
1128 | //*************************** |
|
1116 | //*************************** | |
1129 | // Interrupt Service Routines |
|
1117 | // Interrupt Service Routines | |
1130 | rtems_isr commutation_isr1( rtems_vector_number vector ) |
|
1118 | rtems_isr commutation_isr1( rtems_vector_number vector ) | |
1131 | { |
|
1119 | { | |
1132 | if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) { |
|
1120 | if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) { | |
1133 | printf("In commutation_isr1 *** Error sending event to DUMB\n"); |
|
1121 | printf("In commutation_isr1 *** Error sending event to DUMB\n"); | |
1134 | } |
|
1122 | } | |
1135 | } |
|
1123 | } | |
1136 |
|
1124 | |||
1137 | rtems_isr commutation_isr2( rtems_vector_number vector ) |
|
1125 | rtems_isr commutation_isr2( rtems_vector_number vector ) | |
1138 | { |
|
1126 | { | |
1139 | if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) { |
|
1127 | if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) { | |
1140 | printf("In commutation_isr2 *** Error sending event to DUMB\n"); |
|
1128 | printf("In commutation_isr2 *** Error sending event to DUMB\n"); | |
1141 | } |
|
1129 | } | |
1142 | } |
|
1130 | } | |
1143 |
|
1131 | |||
1144 | //**************** |
|
1132 | //**************** | |
1145 | // OTHER FUNCTIONS |
|
1133 | // OTHER FUNCTIONS | |
1146 | void updateLFRCurrentMode() |
|
1134 | void updateLFRCurrentMode() | |
1147 | { |
|
1135 | { | |
1148 | /** This function updates the value of the global variable lfrCurrentMode. |
|
1136 | /** This function updates the value of the global variable lfrCurrentMode. | |
1149 | * |
|
1137 | * | |
1150 | * lfrCurrentMode is a parameter used by several functions to know in which mode LFR is running. |
|
1138 | * lfrCurrentMode is a parameter used by several functions to know in which mode LFR is running. | |
1151 | * |
|
1139 | * | |
1152 | */ |
|
1140 | */ | |
1153 | // update the local value of lfrCurrentMode with the value contained in the housekeeping_packet structure |
|
1141 | // update the local value of lfrCurrentMode with the value contained in the housekeeping_packet structure | |
1154 | lfrCurrentMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4; |
|
1142 | lfrCurrentMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4; | |
1155 | } |
|
1143 | } | |
1156 |
|
1144 | |||
1157 | void set_lfr_soft_reset( unsigned char value ) |
|
1145 | void set_lfr_soft_reset( unsigned char value ) | |
1158 | { |
|
1146 | { | |
1159 | if (value == 1) |
|
1147 | if (value == 1) | |
1160 | { |
|
1148 | { | |
1161 | time_management_regs->ctrl = time_management_regs->ctrl | 0x00000004; // [0100] |
|
1149 | time_management_regs->ctrl = time_management_regs->ctrl | 0x00000004; // [0100] | |
1162 | } |
|
1150 | } | |
1163 | else |
|
1151 | else | |
1164 | { |
|
1152 | { | |
1165 | time_management_regs->ctrl = time_management_regs->ctrl & 0xfffffffb; // [1011] |
|
1153 | time_management_regs->ctrl = time_management_regs->ctrl & 0xfffffffb; // [1011] | |
1166 | } |
|
1154 | } | |
1167 | } |
|
1155 | } | |
1168 |
|
1156 | |||
1169 | void reset_lfr( void ) |
|
1157 | void reset_lfr( void ) | |
1170 | { |
|
1158 | { | |
1171 | set_lfr_soft_reset( 1 ); |
|
1159 | set_lfr_soft_reset( 1 ); | |
1172 |
|
1160 | |||
1173 | set_lfr_soft_reset( 0 ); |
|
1161 | set_lfr_soft_reset( 0 ); | |
|
1162 | ||||
|
1163 | set_hk_lfr_sc_potential_flag( true ); | |||
1174 | } |
|
1164 | } |
General Comments 0
You need to be logged in to leave comments.
Login now