@@ -1,2 +1,2 | |||
|
1 | 1 | 3081d1f9bb20b2b64a192585337a292a9804e0c5 LFR_basic-parameters |
|
2 | 721463c11a484e6a3439e16c99f8bd27720b9265 header/lfr_common_headers | |
|
2 | ff85ce82cd9845f180cb578272717bcb76b62cb5 header/lfr_common_headers |
@@ -1,77 +1,78 | |||
|
1 | 1 | #ifndef FSW_MISC_H_INCLUDED |
|
2 | 2 | #define FSW_MISC_H_INCLUDED |
|
3 | 3 | |
|
4 | 4 | #include <rtems.h> |
|
5 | 5 | #include <stdio.h> |
|
6 | 6 | #include <grspw.h> |
|
7 | 7 | #include <grlib_regs.h> |
|
8 | 8 | |
|
9 | 9 | #include "fsw_params.h" |
|
10 | 10 | #include "fsw_spacewire.h" |
|
11 | 11 | #include "lfr_cpu_usage_report.h" |
|
12 | 12 | |
|
13 | 13 | enum lfr_reset_cause_t{ |
|
14 | 14 | UNKNOWN_CAUSE, |
|
15 | 15 | POWER_ON, |
|
16 | 16 | TC_RESET, |
|
17 | 17 | WATCHDOG, |
|
18 | 18 | ERROR_RESET, |
|
19 | 19 | UNEXP_RESET |
|
20 | 20 | }; |
|
21 | 21 | |
|
22 | 22 | extern gptimer_regs_t *gptimer_regs; |
|
23 | 23 | |
|
24 | 24 | #define LFR_RESET_CAUSE_UNKNOWN_CAUSE 0 |
|
25 | 25 | |
|
26 | 26 | rtems_name name_hk_rate_monotonic; // name of the HK rate monotonic |
|
27 | 27 | rtems_id HK_id; // id of the HK rate monotonic period |
|
28 | 28 | |
|
29 | 29 | void timer_configure( unsigned char timer, unsigned int clock_divider, |
|
30 | 30 | unsigned char interrupt_level, rtems_isr (*timer_isr)() ); |
|
31 | 31 | void timer_start( unsigned char timer ); |
|
32 | 32 | void timer_stop( unsigned char timer ); |
|
33 | 33 | void timer_set_clock_divider(unsigned char timer, unsigned int clock_divider); |
|
34 | 34 | |
|
35 | 35 | // WATCHDOG |
|
36 | 36 | rtems_isr watchdog_isr( rtems_vector_number vector ); |
|
37 | 37 | void watchdog_configure(void); |
|
38 | 38 | void watchdog_stop(void); |
|
39 | 39 | void watchdog_start(void); |
|
40 | 40 | |
|
41 | 41 | // SERIAL LINK |
|
42 | 42 | int send_console_outputs_on_apbuart_port( void ); |
|
43 | 43 | int enable_apbuart_transmitter( void ); |
|
44 | 44 | void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value); |
|
45 | 45 | |
|
46 | 46 | // RTEMS TASKS |
|
47 | 47 | rtems_task load_task( rtems_task_argument argument ); |
|
48 | 48 | rtems_task hous_task( rtems_task_argument argument ); |
|
49 | 49 | rtems_task dumb_task( rtems_task_argument unused ); |
|
50 | 50 | |
|
51 | 51 | void init_housekeeping_parameters( void ); |
|
52 | 52 | void increment_seq_counter(unsigned short *packetSequenceControl); |
|
53 | 53 | void getTime( unsigned char *time); |
|
54 | 54 | unsigned long long int getTimeAsUnsignedLongLongInt( ); |
|
55 | 55 | void send_dumb_hk( void ); |
|
56 | 56 | void get_temperatures( unsigned char *temperatures ); |
|
57 | 57 | void get_v_e1_e2_f3( unsigned char *spacecraft_potential ); |
|
58 | 58 | void get_cpu_load( unsigned char *resource_statistics ); |
|
59 | 59 | void set_hk_lfr_sc_potential_flag( bool state ); |
|
60 | 60 | void set_hk_lfr_mag_fields_flag( bool state ); |
|
61 | 61 | void set_hk_lfr_calib_enable( bool state ); |
|
62 | 62 | void set_hk_lfr_reset_cause( enum lfr_reset_cause_t lfr_reset_cause ); |
|
63 | void hk_lfr_le_me_he_update(); | |
|
63 | 64 | |
|
64 | 65 | extern int sched_yield( void ); |
|
65 | 66 | extern void rtems_cpu_usage_reset(); |
|
66 | 67 | extern ring_node *current_ring_node_f3; |
|
67 | 68 | extern ring_node *ring_node_to_send_cwf_f3; |
|
68 | 69 | extern ring_node waveform_ring_f3[]; |
|
69 | 70 | extern unsigned short sequenceCounterHK; |
|
70 | 71 | |
|
71 | 72 | extern unsigned char hk_lfr_q_sd_fifo_size_max; |
|
72 | 73 | extern unsigned char hk_lfr_q_rv_fifo_size_max; |
|
73 | 74 | extern unsigned char hk_lfr_q_p0_fifo_size_max; |
|
74 | 75 | extern unsigned char hk_lfr_q_p1_fifo_size_max; |
|
75 | 76 | extern unsigned char hk_lfr_q_p2_fifo_size_max; |
|
76 | 77 | |
|
77 | 78 | #endif // FSW_MISC_H_INCLUDED |
@@ -1,51 +1,50 | |||
|
1 | 1 | #ifndef FSW_SPACEWIRE_H_INCLUDED |
|
2 | 2 | #define FSW_SPACEWIRE_H_INCLUDED |
|
3 | 3 | |
|
4 | 4 | #include <rtems.h> |
|
5 | 5 | #include <grspw.h> |
|
6 | 6 | |
|
7 | 7 | #include <fcntl.h> // for O_RDWR |
|
8 | 8 | #include <unistd.h> // for the read call |
|
9 | 9 | #include <sys/ioctl.h> // for the ioctl call |
|
10 | 10 | #include <errno.h> |
|
11 | 11 | |
|
12 | 12 | #include "fsw_params.h" |
|
13 | 13 | #include "tc_handler.h" |
|
14 | 14 | #include "fsw_init.h" |
|
15 | 15 | |
|
16 | 16 | extern spw_stats spacewire_stats; |
|
17 | 17 | extern spw_stats spacewire_stats_backup; |
|
18 | 18 | |
|
19 | 19 | // RTEMS TASK |
|
20 | 20 | rtems_task spiq_task( rtems_task_argument argument ); |
|
21 | 21 | rtems_task recv_task( rtems_task_argument unused ); |
|
22 | 22 | rtems_task send_task( rtems_task_argument argument ); |
|
23 | 23 | rtems_task wtdg_task( rtems_task_argument argument ); |
|
24 | 24 | |
|
25 | 25 | int spacewire_open_link( void ); |
|
26 | 26 | int spacewire_start_link( int fd ); |
|
27 | 27 | int spacewire_stop_and_start_link( int fd ); |
|
28 | 28 | int spacewire_configure_link(int fd ); |
|
29 | 29 | int spacewire_reset_link( void ); |
|
30 | 30 | void spacewire_set_NP( unsigned char val, unsigned int regAddr ); // No Port force |
|
31 | 31 | void spacewire_set_RE( unsigned char val, unsigned int regAddr ); // RMAP Enable |
|
32 | 32 | void spacewire_compute_stats_offsets( void ); |
|
33 | 33 | void spacewire_update_statistics( void ); |
|
34 | 34 | |
|
35 | 35 | void init_header_cwf( Header_TM_LFR_SCIENCE_CWF_t *header ); |
|
36 | 36 | void init_header_swf( Header_TM_LFR_SCIENCE_SWF_t *header ); |
|
37 | 37 | void init_header_asm( Header_TM_LFR_SCIENCE_ASM_t *header ); |
|
38 | 38 | int spw_send_waveform_CWF( ring_node *ring_node_to_send, Header_TM_LFR_SCIENCE_CWF_t *header ); |
|
39 | 39 | int spw_send_waveform_SWF( ring_node *ring_node_to_send, Header_TM_LFR_SCIENCE_SWF_t *header ); |
|
40 | 40 | int spw_send_waveform_CWF3_light( ring_node *ring_node_to_send, Header_TM_LFR_SCIENCE_CWF_t *header ); |
|
41 | 41 | void spw_send_asm_f0( ring_node *ring_node_to_send, Header_TM_LFR_SCIENCE_ASM_t *header ); |
|
42 | 42 | void spw_send_asm_f1( ring_node *ring_node_to_send, Header_TM_LFR_SCIENCE_ASM_t *header ); |
|
43 | 43 | void spw_send_asm_f2( ring_node *ring_node_to_send, Header_TM_LFR_SCIENCE_ASM_t *header ); |
|
44 | 44 | void spw_send_k_dump( ring_node *ring_node_to_send ); |
|
45 | 45 | |
|
46 | 46 | void timecode_irq_handler( void *pDev, void *regs, int minor, unsigned int tc ); |
|
47 | rtems_timer_service_routine user_routine( rtems_id timer_id, void *user_data ); | |
|
48 | 47 | |
|
49 | 48 | void (*grspw_timecode_callback) ( void *pDev, void *regs, int minor, unsigned int tc ); |
|
50 | 49 | |
|
51 | 50 | #endif // FSW_SPACEWIRE_H_INCLUDED |
@@ -1,77 +1,80 | |||
|
1 | 1 | #ifndef TC_HANDLER_H_INCLUDED |
|
2 | 2 | #define TC_HANDLER_H_INCLUDED |
|
3 | 3 | |
|
4 | 4 | #include <rtems.h> |
|
5 | 5 | #include <leon.h> |
|
6 | 6 | |
|
7 | 7 | #include "tc_load_dump_parameters.h" |
|
8 | 8 | #include "tc_acceptance.h" |
|
9 | 9 | #include "tm_lfr_tc_exe.h" |
|
10 | 10 | #include "wf_handler.h" |
|
11 | 11 | #include "fsw_processing.h" |
|
12 | 12 | |
|
13 | 13 | #include "lfr_cpu_usage_report.h" |
|
14 | 14 | |
|
15 | extern unsigned int lastValidTransitionDate; | |
|
16 | ||
|
15 | 17 | //**** |
|
16 | 18 | // ISR |
|
17 | 19 | rtems_isr commutation_isr1( rtems_vector_number vector ); |
|
18 | 20 | rtems_isr commutation_isr2( rtems_vector_number vector ); |
|
19 | 21 | |
|
20 | 22 | //*********** |
|
21 | 23 | // RTEMS TASK |
|
22 | 24 | rtems_task actn_task( rtems_task_argument unused ); |
|
23 | 25 | |
|
24 | 26 | //*********** |
|
25 | 27 | // TC ACTIONS |
|
26 | 28 | int action_reset( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time ); |
|
27 | 29 | int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id); |
|
28 | 30 | int action_update_info( ccsdsTelecommandPacket_t *TC, rtems_id queue_id ); |
|
29 | 31 | int action_enable_calibration( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time ); |
|
30 | 32 | int action_disable_calibration( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time ); |
|
31 | 33 | int action_update_time( ccsdsTelecommandPacket_t *TC); |
|
32 | 34 | |
|
33 | 35 | // mode transition |
|
34 | 36 | int check_mode_value( unsigned char requestedMode ); |
|
35 | 37 | int check_mode_transition( unsigned char requestedMode ); |
|
38 | void update_last_valid_transition_date( unsigned int transitionCoarseTime ); | |
|
36 | 39 | int check_transition_date( unsigned int transitionCoarseTime ); |
|
37 | 40 | int stop_spectral_matrices( void ); |
|
38 | 41 | int stop_current_mode( void ); |
|
39 | 42 | int enter_mode_standby( void ); |
|
40 | 43 | int enter_mode_normal( unsigned int transitionCoarseTime ); |
|
41 | 44 | int enter_mode_burst( unsigned int transitionCoarseTime ); |
|
42 | 45 | int enter_mode_sbm1( unsigned int transitionCoarseTime ); |
|
43 | 46 | int enter_mode_sbm2( unsigned int transitionCoarseTime ); |
|
44 | 47 | int restart_science_tasks( unsigned char lfrRequestedMode ); |
|
45 | 48 | int restart_asm_tasks(unsigned char lfrRequestedMode ); |
|
46 | 49 | int suspend_science_tasks(void); |
|
47 | 50 | int suspend_asm_tasks( void ); |
|
48 | 51 | void launch_waveform_picker( unsigned char mode , unsigned int transitionCoarseTime ); |
|
49 | 52 | void launch_spectral_matrix( void ); |
|
50 | 53 | void set_sm_irq_onNewMatrix( unsigned char value ); |
|
51 | 54 | void set_sm_irq_onError( unsigned char value ); |
|
52 | 55 | |
|
53 | 56 | // other functions |
|
54 | 57 | void updateLFRCurrentMode(); |
|
55 | 58 | void set_lfr_soft_reset( unsigned char value ); |
|
56 | 59 | void reset_lfr( void ); |
|
57 | 60 | // CALIBRATION |
|
58 | 61 | void setCalibrationPrescaler( unsigned int prescaler ); |
|
59 | 62 | void setCalibrationDivisor( unsigned int divisionFactor ); |
|
60 | 63 | void setCalibrationData( void ); |
|
61 | 64 | void setCalibrationReload( bool state); |
|
62 | 65 | void setCalibrationEnable( bool state ); |
|
63 | 66 | void setCalibrationInterleaved( bool state ); |
|
64 | 67 | void setCalibration( bool state ); |
|
65 | 68 | void configureCalibration( bool interleaved ); |
|
66 | 69 | // |
|
67 | 70 | void update_last_TC_exe( ccsdsTelecommandPacket_t *TC , unsigned char *time ); |
|
68 | 71 | void update_last_TC_rej(ccsdsTelecommandPacket_t *TC , unsigned char *time ); |
|
69 | 72 | void close_action( ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id ); |
|
70 | 73 | |
|
71 | 74 | extern rtems_status_code get_message_queue_id_send( rtems_id *queue_id ); |
|
72 | 75 | extern rtems_status_code get_message_queue_id_recv( rtems_id *queue_id ); |
|
73 | 76 | |
|
74 | 77 | #endif // TC_HANDLER_H_INCLUDED |
|
75 | 78 | |
|
76 | 79 | |
|
77 | 80 |
@@ -1,79 +1,80 | |||
|
1 | 1 | /** Global variables of the LFR flight software. |
|
2 | 2 | * |
|
3 | 3 | * @file |
|
4 | 4 | * @author P. LEROY |
|
5 | 5 | * |
|
6 | 6 | * Among global variables, there are: |
|
7 | 7 | * - RTEMS names and id. |
|
8 | 8 | * - APB configuration registers. |
|
9 | 9 | * - waveforms global buffers, used by the waveform picker hardware module to store data. |
|
10 | 10 | * - spectral matrices buffesr, used by the hardware module to store data. |
|
11 | 11 | * - variable related to LFR modes parameters. |
|
12 | 12 | * - the global HK packet buffer. |
|
13 | 13 | * - the global dump parameter buffer. |
|
14 | 14 | * |
|
15 | 15 | */ |
|
16 | 16 | |
|
17 | 17 | #include <rtems.h> |
|
18 | 18 | #include <grspw.h> |
|
19 | 19 | |
|
20 | 20 | #include "ccsds_types.h" |
|
21 | 21 | #include "grlib_regs.h" |
|
22 | 22 | #include "fsw_params.h" |
|
23 | 23 | #include "fsw_params_wf_handler.h" |
|
24 | 24 | |
|
25 | 25 | // RTEMS GLOBAL VARIABLES |
|
26 | 26 | rtems_name misc_name[5]; |
|
27 | 27 | rtems_name Task_name[20]; /* array of task names */ |
|
28 | 28 | rtems_id Task_id[20]; /* array of task ids */ |
|
29 | 29 | int fdSPW = 0; |
|
30 | 30 | int fdUART = 0; |
|
31 | 31 | unsigned char lfrCurrentMode; |
|
32 | 32 | unsigned char pa_bia_status_info; |
|
33 | 33 | |
|
34 | 34 | // WAVEFORMS GLOBAL VARIABLES // 2048 * 3 * 4 + 2 * 4 = 24576 + 8 bytes = 24584 |
|
35 | 35 | // 97 * 256 = 24832 => delta = 248 bytes = 62 words |
|
36 | 36 | // WAVEFORMS GLOBAL VARIABLES // 2688 * 3 * 4 + 2 * 4 = 32256 + 8 bytes = 32264 |
|
37 | 37 | // 127 * 256 = 32512 => delta = 248 bytes = 62 words |
|
38 | 38 | // F0 F1 F2 F3 |
|
39 | 39 | volatile int wf_buffer_f0[ NB_RING_NODES_F0 * WFRM_BUFFER ] __attribute__((aligned(0x100))); |
|
40 | 40 | volatile int wf_buffer_f1[ NB_RING_NODES_F1 * WFRM_BUFFER ] __attribute__((aligned(0x100))); |
|
41 | 41 | volatile int wf_buffer_f2[ NB_RING_NODES_F2 * WFRM_BUFFER ] __attribute__((aligned(0x100))); |
|
42 | 42 | volatile int wf_buffer_f3[ NB_RING_NODES_F3 * WFRM_BUFFER ] __attribute__((aligned(0x100))); |
|
43 | 43 | |
|
44 | 44 | //*********************************** |
|
45 | 45 | // SPECTRAL MATRICES GLOBAL VARIABLES |
|
46 | 46 | |
|
47 | 47 | // alignment constraints for the spectral matrices buffers => the first data after the time (8 bytes) shall be aligned on 0x00 |
|
48 | 48 | volatile int sm_f0[ NB_RING_NODES_SM_F0 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100))); |
|
49 | 49 | volatile int sm_f1[ NB_RING_NODES_SM_F1 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100))); |
|
50 | 50 | volatile int sm_f2[ NB_RING_NODES_SM_F2 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100))); |
|
51 | 51 | |
|
52 | 52 | // APB CONFIGURATION REGISTERS |
|
53 | 53 | time_management_regs_t *time_management_regs = (time_management_regs_t*) REGS_ADDR_TIME_MANAGEMENT; |
|
54 | 54 | gptimer_regs_t *gptimer_regs = (gptimer_regs_t *) REGS_ADDR_GPTIMER; |
|
55 | 55 | waveform_picker_regs_0_1_18_t *waveform_picker_regs = (waveform_picker_regs_0_1_18_t*) REGS_ADDR_WAVEFORM_PICKER; |
|
56 | 56 | spectral_matrix_regs_t *spectral_matrix_regs = (spectral_matrix_regs_t*) REGS_ADDR_SPECTRAL_MATRIX; |
|
57 | 57 | |
|
58 | 58 | // MODE PARAMETERS |
|
59 | 59 | Packet_TM_LFR_PARAMETER_DUMP_t parameter_dump_packet; |
|
60 | 60 | struct param_local_str param_local; |
|
61 | unsigned int lastValidTransitionDate; | |
|
61 | 62 | |
|
62 | 63 | // HK PACKETS |
|
63 | 64 | Packet_TM_LFR_HK_t housekeeping_packet; |
|
64 | 65 | // message queues occupancy |
|
65 | 66 | unsigned char hk_lfr_q_sd_fifo_size_max; |
|
66 | 67 | unsigned char hk_lfr_q_rv_fifo_size_max; |
|
67 | 68 | unsigned char hk_lfr_q_p0_fifo_size_max; |
|
68 | 69 | unsigned char hk_lfr_q_p1_fifo_size_max; |
|
69 | 70 | unsigned char hk_lfr_q_p2_fifo_size_max; |
|
70 | 71 | // sequence counters are incremented by APID (PID + CAT) and destination ID |
|
71 | 72 | unsigned short sequenceCounters_SCIENCE_NORMAL_BURST; |
|
72 | 73 | unsigned short sequenceCounters_SCIENCE_SBM1_SBM2; |
|
73 | 74 | unsigned short sequenceCounters_TC_EXE[SEQ_CNT_NB_DEST_ID]; |
|
74 | 75 | unsigned short sequenceCounters_TM_DUMP[SEQ_CNT_NB_DEST_ID]; |
|
75 | 76 | unsigned short sequenceCounterHK; |
|
76 | 77 | spw_stats spacewire_stats; |
|
77 | 78 | spw_stats spacewire_stats_backup; |
|
78 | 79 | |
|
79 | 80 |
@@ -1,864 +1,865 | |||
|
1 | 1 | /** This is the RTEMS initialization module. |
|
2 | 2 | * |
|
3 | 3 | * @file |
|
4 | 4 | * @author P. LEROY |
|
5 | 5 | * |
|
6 | 6 | * This module contains two very different information: |
|
7 | 7 | * - specific instructions to configure the compilation of the RTEMS executive |
|
8 | 8 | * - functions related to the fligth softwre initialization, especially the INIT RTEMS task |
|
9 | 9 | * |
|
10 | 10 | */ |
|
11 | 11 | |
|
12 | 12 | //************************* |
|
13 | 13 | // GPL reminder to be added |
|
14 | 14 | //************************* |
|
15 | 15 | |
|
16 | 16 | #include <rtems.h> |
|
17 | 17 | |
|
18 | 18 | /* configuration information */ |
|
19 | 19 | |
|
20 | 20 | #define CONFIGURE_INIT |
|
21 | 21 | |
|
22 | 22 | #include <bsp.h> /* for device driver prototypes */ |
|
23 | 23 | |
|
24 | 24 | /* configuration information */ |
|
25 | 25 | |
|
26 | 26 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
|
27 | 27 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
|
28 | 28 | |
|
29 | 29 | #define CONFIGURE_MAXIMUM_TASKS 20 |
|
30 | 30 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
|
31 | 31 | #define CONFIGURE_EXTRA_TASK_STACKS (3 * RTEMS_MINIMUM_STACK_SIZE) |
|
32 | 32 | #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 32 |
|
33 | 33 | #define CONFIGURE_INIT_TASK_PRIORITY 1 // instead of 100 |
|
34 | 34 | #define CONFIGURE_INIT_TASK_MODE (RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT) |
|
35 | 35 | #define CONFIGURE_INIT_TASK_ATTRIBUTES (RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT) |
|
36 | 36 | #define CONFIGURE_MAXIMUM_DRIVERS 16 |
|
37 | 37 | #define CONFIGURE_MAXIMUM_PERIODS 5 |
|
38 | 38 | #define CONFIGURE_MAXIMUM_TIMERS 5 // STAT (1s), send SWF (0.3s), send CWF3 (1s) |
|
39 | 39 | #define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 5 |
|
40 | 40 | #ifdef PRINT_STACK_REPORT |
|
41 | 41 | #define CONFIGURE_STACK_CHECKER_ENABLED |
|
42 | 42 | #endif |
|
43 | 43 | |
|
44 | 44 | #include <rtems/confdefs.h> |
|
45 | 45 | |
|
46 | 46 | /* If --drvmgr was enabled during the configuration of the RTEMS kernel */ |
|
47 | 47 | #ifdef RTEMS_DRVMGR_STARTUP |
|
48 | 48 | #ifdef LEON3 |
|
49 | 49 | /* Add Timer and UART Driver */ |
|
50 | 50 | #ifdef CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
|
51 | 51 | #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GPTIMER |
|
52 | 52 | #endif |
|
53 | 53 | #ifdef CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
|
54 | 54 | #define CONFIGURE_DRIVER_AMBAPP_GAISLER_APBUART |
|
55 | 55 | #endif |
|
56 | 56 | #endif |
|
57 | 57 | #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GRSPW /* GRSPW Driver */ |
|
58 | 58 | #include <drvmgr/drvmgr_confdefs.h> |
|
59 | 59 | #endif |
|
60 | 60 | |
|
61 | 61 | #include "fsw_init.h" |
|
62 | 62 | #include "fsw_config.c" |
|
63 | 63 | #include "GscMemoryLPP.hpp" |
|
64 | 64 | |
|
65 | 65 | void initCache() |
|
66 | 66 | { |
|
67 | 67 | unsigned int cacheControlRegister; |
|
68 | 68 | |
|
69 | 69 | cacheControlRegister = getCacheControlRegister(); |
|
70 | 70 | PRINTF1("(0) cacheControlRegister = %x\n", cacheControlRegister) |
|
71 | 71 | |
|
72 | 72 | resetCacheControlRegister(); |
|
73 | 73 | |
|
74 | 74 | enableInstructionCache(); |
|
75 | 75 | enableDataCache(); |
|
76 | 76 | enableInstructionBurstFetch(); |
|
77 | 77 | |
|
78 | 78 | cacheControlRegister = getCacheControlRegister(); |
|
79 | 79 | PRINTF1("(1) cacheControlRegister = %x\n", cacheControlRegister) |
|
80 | 80 | } |
|
81 | 81 | |
|
82 | 82 | rtems_task Init( rtems_task_argument ignored ) |
|
83 | 83 | { |
|
84 | 84 | /** This is the RTEMS INIT taks, it is the first task launched by the system. |
|
85 | 85 | * |
|
86 | 86 | * @param unused is the starting argument of the RTEMS task |
|
87 | 87 | * |
|
88 | 88 | * The INIT task create and run all other RTEMS tasks. |
|
89 | 89 | * |
|
90 | 90 | */ |
|
91 | 91 | |
|
92 | 92 | //*********** |
|
93 | 93 | // INIT CACHE |
|
94 | 94 | |
|
95 | 95 | unsigned char *vhdlVersion; |
|
96 | 96 | |
|
97 | 97 | reset_lfr(); |
|
98 | 98 | |
|
99 | 99 | reset_local_time(); |
|
100 | 100 | |
|
101 | 101 | rtems_cpu_usage_reset(); |
|
102 | 102 | |
|
103 | 103 | rtems_status_code status; |
|
104 | 104 | rtems_status_code status_spw; |
|
105 | 105 | rtems_isr_entry old_isr_handler; |
|
106 | 106 | |
|
107 | 107 | // UART settings |
|
108 | 108 | send_console_outputs_on_apbuart_port(); |
|
109 | 109 | set_apbuart_scaler_reload_register(REGS_ADDR_APBUART, APBUART_SCALER_RELOAD_VALUE); |
|
110 | 110 | enable_apbuart_transmitter(); |
|
111 | 111 | |
|
112 | 112 | DEBUG_PRINTF("\n\n\n\n\nIn INIT *** Now the console is on port COM1\n") |
|
113 | 113 | |
|
114 | 114 | |
|
115 | 115 | PRINTF("\n\n\n\n\n") |
|
116 | 116 | |
|
117 | 117 | initCache(); |
|
118 | 118 | |
|
119 | 119 | PRINTF("*************************\n") |
|
120 | 120 | PRINTF("** LFR Flight Software **\n") |
|
121 | 121 | PRINTF1("** %d.", SW_VERSION_N1) |
|
122 | 122 | PRINTF1("%d." , SW_VERSION_N2) |
|
123 | 123 | PRINTF1("%d." , SW_VERSION_N3) |
|
124 | 124 | PRINTF1("%d **\n", SW_VERSION_N4) |
|
125 | 125 | |
|
126 | 126 | vhdlVersion = (unsigned char *) (REGS_ADDR_VHDL_VERSION); |
|
127 | 127 | PRINTF("** VHDL **\n") |
|
128 | 128 | PRINTF1("** %d.", vhdlVersion[1]) |
|
129 | 129 | PRINTF1("%d." , vhdlVersion[2]) |
|
130 | 130 | PRINTF1("%d **\n", vhdlVersion[3]) |
|
131 | 131 | PRINTF("*************************\n") |
|
132 | 132 | PRINTF("\n\n") |
|
133 | 133 | |
|
134 | 134 | init_parameter_dump(); |
|
135 | 135 | init_kcoefficients_dump(); |
|
136 | 136 | init_local_mode_parameters(); |
|
137 | 137 | init_housekeeping_parameters(); |
|
138 | 138 | init_k_coefficients_prc0(); |
|
139 | 139 | init_k_coefficients_prc1(); |
|
140 | 140 | init_k_coefficients_prc2(); |
|
141 | 141 | pa_bia_status_info = 0x00; |
|
142 | update_last_valid_transition_date( DEFAULT_LAST_VALID_TRANSITION_DATE ); | |
|
142 | 143 | |
|
143 | 144 | // waveform picker initialization |
|
144 | 145 | WFP_init_rings(); LEON_Clear_interrupt( IRQ_SPARC_GPTIMER_WATCHDOG ); // initialize the waveform rings |
|
145 | 146 | WFP_reset_current_ring_nodes(); |
|
146 | 147 | reset_waveform_picker_regs(); |
|
147 | 148 | |
|
148 | 149 | // spectral matrices initialization |
|
149 | 150 | SM_init_rings(); // initialize spectral matrices rings |
|
150 | 151 | SM_reset_current_ring_nodes(); |
|
151 | 152 | reset_spectral_matrix_regs(); |
|
152 | 153 | |
|
153 | 154 | // configure calibration |
|
154 | 155 | configureCalibration( false ); // true means interleaved mode, false is for normal mode |
|
155 | 156 | |
|
156 | 157 | updateLFRCurrentMode(); |
|
157 | 158 | |
|
158 | 159 | BOOT_PRINTF1("in INIT *** lfrCurrentMode is %d\n", lfrCurrentMode) |
|
159 | 160 | |
|
160 | 161 | create_names(); // create all names |
|
161 | 162 | |
|
162 | 163 | status = create_message_queues(); // create message queues |
|
163 | 164 | if (status != RTEMS_SUCCESSFUL) |
|
164 | 165 | { |
|
165 | 166 | PRINTF1("in INIT *** ERR in create_message_queues, code %d", status) |
|
166 | 167 | } |
|
167 | 168 | |
|
168 | 169 | status = create_all_tasks(); // create all tasks |
|
169 | 170 | if (status != RTEMS_SUCCESSFUL) |
|
170 | 171 | { |
|
171 | 172 | PRINTF1("in INIT *** ERR in create_all_tasks, code %d\n", status) |
|
172 | 173 | } |
|
173 | 174 | |
|
174 | 175 | // ************************** |
|
175 | 176 | // <SPACEWIRE INITIALIZATION> |
|
176 | 177 | grspw_timecode_callback = &timecode_irq_handler; |
|
177 | 178 | |
|
178 | 179 | status_spw = spacewire_open_link(); // (1) open the link |
|
179 | 180 | if ( status_spw != RTEMS_SUCCESSFUL ) |
|
180 | 181 | { |
|
181 | 182 | PRINTF1("in INIT *** ERR spacewire_open_link code %d\n", status_spw ) |
|
182 | 183 | } |
|
183 | 184 | |
|
184 | 185 | if ( status_spw == RTEMS_SUCCESSFUL ) // (2) configure the link |
|
185 | 186 | { |
|
186 | 187 | status_spw = spacewire_configure_link( fdSPW ); |
|
187 | 188 | if ( status_spw != RTEMS_SUCCESSFUL ) |
|
188 | 189 | { |
|
189 | 190 | PRINTF1("in INIT *** ERR spacewire_configure_link code %d\n", status_spw ) |
|
190 | 191 | } |
|
191 | 192 | } |
|
192 | 193 | |
|
193 | 194 | if ( status_spw == RTEMS_SUCCESSFUL) // (3) start the link |
|
194 | 195 | { |
|
195 | 196 | status_spw = spacewire_start_link( fdSPW ); |
|
196 | 197 | if ( status_spw != RTEMS_SUCCESSFUL ) |
|
197 | 198 | { |
|
198 | 199 | PRINTF1("in INIT *** ERR spacewire_start_link code %d\n", status_spw ) |
|
199 | 200 | } |
|
200 | 201 | } |
|
201 | 202 | // </SPACEWIRE INITIALIZATION> |
|
202 | 203 | // *************************** |
|
203 | 204 | |
|
204 | 205 | status = start_all_tasks(); // start all tasks |
|
205 | 206 | if (status != RTEMS_SUCCESSFUL) |
|
206 | 207 | { |
|
207 | 208 | PRINTF1("in INIT *** ERR in start_all_tasks, code %d", status) |
|
208 | 209 | } |
|
209 | 210 | |
|
210 | 211 | // start RECV and SEND *AFTER* SpaceWire Initialization, due to the timeout of the start call during the initialization |
|
211 | 212 | status = start_recv_send_tasks(); |
|
212 | 213 | if ( status != RTEMS_SUCCESSFUL ) |
|
213 | 214 | { |
|
214 | 215 | PRINTF1("in INIT *** ERR start_recv_send_tasks code %d\n", status ) |
|
215 | 216 | } |
|
216 | 217 | |
|
217 | 218 | // suspend science tasks, they will be restarted later depending on the mode |
|
218 | 219 | status = suspend_science_tasks(); // suspend science tasks (not done in stop_current_mode if current mode = STANDBY) |
|
219 | 220 | if (status != RTEMS_SUCCESSFUL) |
|
220 | 221 | { |
|
221 | 222 | PRINTF1("in INIT *** in suspend_science_tasks *** ERR code: %d\n", status) |
|
222 | 223 | } |
|
223 | 224 | |
|
224 | 225 | // configure IRQ handling for the waveform picker unit |
|
225 | 226 | status = rtems_interrupt_catch( waveforms_isr, |
|
226 | 227 | IRQ_SPARC_WAVEFORM_PICKER, |
|
227 | 228 | &old_isr_handler) ; |
|
228 | 229 | // configure IRQ handling for the spectral matrices unit |
|
229 | 230 | status = rtems_interrupt_catch( spectral_matrices_isr, |
|
230 | 231 | IRQ_SPARC_SPECTRAL_MATRIX, |
|
231 | 232 | &old_isr_handler) ; |
|
232 | 233 | |
|
233 | 234 | // if the spacewire link is not up then send an event to the SPIQ task for link recovery |
|
234 | 235 | if ( status_spw != RTEMS_SUCCESSFUL ) |
|
235 | 236 | { |
|
236 | 237 | status = rtems_event_send( Task_id[TASKID_SPIQ], SPW_LINKERR_EVENT ); |
|
237 | 238 | if ( status != RTEMS_SUCCESSFUL ) { |
|
238 | 239 | PRINTF1("in INIT *** ERR rtems_event_send to SPIQ code %d\n", status ) |
|
239 | 240 | } |
|
240 | 241 | } |
|
241 | 242 | |
|
242 | 243 | BOOT_PRINTF("delete INIT\n") |
|
243 | 244 | |
|
244 | 245 | set_hk_lfr_sc_potential_flag( true ); |
|
245 | 246 | |
|
246 | 247 | status = rtems_task_delete(RTEMS_SELF); |
|
247 | 248 | |
|
248 | 249 | } |
|
249 | 250 | |
|
250 | 251 | void init_local_mode_parameters( void ) |
|
251 | 252 | { |
|
252 | 253 | /** This function initialize the param_local global variable with default values. |
|
253 | 254 | * |
|
254 | 255 | */ |
|
255 | 256 | |
|
256 | 257 | unsigned int i; |
|
257 | 258 | |
|
258 | 259 | // LOCAL PARAMETERS |
|
259 | 260 | |
|
260 | 261 | BOOT_PRINTF1("local_sbm1_nb_cwf_max %d \n", param_local.local_sbm1_nb_cwf_max) |
|
261 | 262 | BOOT_PRINTF1("local_sbm2_nb_cwf_max %d \n", param_local.local_sbm2_nb_cwf_max) |
|
262 | 263 | BOOT_PRINTF1("nb_interrupt_f0_MAX = %d\n", param_local.local_nb_interrupt_f0_MAX) |
|
263 | 264 | |
|
264 | 265 | // init sequence counters |
|
265 | 266 | |
|
266 | 267 | for(i = 0; i<SEQ_CNT_NB_DEST_ID; i++) |
|
267 | 268 | { |
|
268 | 269 | sequenceCounters_TC_EXE[i] = 0x00; |
|
269 | 270 | sequenceCounters_TM_DUMP[i] = 0x00; |
|
270 | 271 | } |
|
271 | 272 | sequenceCounters_SCIENCE_NORMAL_BURST = 0x00; |
|
272 | 273 | sequenceCounters_SCIENCE_SBM1_SBM2 = 0x00; |
|
273 | 274 | sequenceCounterHK = TM_PACKET_SEQ_CTRL_STANDALONE << 8; |
|
274 | 275 | } |
|
275 | 276 | |
|
276 | 277 | void reset_local_time( void ) |
|
277 | 278 | { |
|
278 | 279 | time_management_regs->ctrl = time_management_regs->ctrl | 0x02; // [0010] software reset, coarse time = 0x80000000 |
|
279 | 280 | } |
|
280 | 281 | |
|
281 | 282 | void create_names( void ) // create all names for tasks and queues |
|
282 | 283 | { |
|
283 | 284 | /** This function creates all RTEMS names used in the software for tasks and queues. |
|
284 | 285 | * |
|
285 | 286 | * @return RTEMS directive status codes: |
|
286 | 287 | * - RTEMS_SUCCESSFUL - successful completion |
|
287 | 288 | * |
|
288 | 289 | */ |
|
289 | 290 | |
|
290 | 291 | // task names |
|
291 | 292 | Task_name[TASKID_RECV] = rtems_build_name( 'R', 'E', 'C', 'V' ); |
|
292 | 293 | Task_name[TASKID_ACTN] = rtems_build_name( 'A', 'C', 'T', 'N' ); |
|
293 | 294 | Task_name[TASKID_SPIQ] = rtems_build_name( 'S', 'P', 'I', 'Q' ); |
|
294 | 295 | Task_name[TASKID_LOAD] = rtems_build_name( 'L', 'O', 'A', 'D' ); |
|
295 | 296 | Task_name[TASKID_AVF0] = rtems_build_name( 'A', 'V', 'F', '0' ); |
|
296 | 297 | Task_name[TASKID_SWBD] = rtems_build_name( 'S', 'W', 'B', 'D' ); |
|
297 | 298 | Task_name[TASKID_WFRM] = rtems_build_name( 'W', 'F', 'R', 'M' ); |
|
298 | 299 | Task_name[TASKID_DUMB] = rtems_build_name( 'D', 'U', 'M', 'B' ); |
|
299 | 300 | Task_name[TASKID_HOUS] = rtems_build_name( 'H', 'O', 'U', 'S' ); |
|
300 | 301 | Task_name[TASKID_PRC0] = rtems_build_name( 'P', 'R', 'C', '0' ); |
|
301 | 302 | Task_name[TASKID_CWF3] = rtems_build_name( 'C', 'W', 'F', '3' ); |
|
302 | 303 | Task_name[TASKID_CWF2] = rtems_build_name( 'C', 'W', 'F', '2' ); |
|
303 | 304 | Task_name[TASKID_CWF1] = rtems_build_name( 'C', 'W', 'F', '1' ); |
|
304 | 305 | Task_name[TASKID_SEND] = rtems_build_name( 'S', 'E', 'N', 'D' ); |
|
305 | 306 | Task_name[TASKID_WTDG] = rtems_build_name( 'W', 'T', 'D', 'G' ); |
|
306 | 307 | Task_name[TASKID_AVF1] = rtems_build_name( 'A', 'V', 'F', '1' ); |
|
307 | 308 | Task_name[TASKID_PRC1] = rtems_build_name( 'P', 'R', 'C', '1' ); |
|
308 | 309 | Task_name[TASKID_AVF2] = rtems_build_name( 'A', 'V', 'F', '2' ); |
|
309 | 310 | Task_name[TASKID_PRC2] = rtems_build_name( 'P', 'R', 'C', '2' ); |
|
310 | 311 | |
|
311 | 312 | // rate monotonic period names |
|
312 | 313 | name_hk_rate_monotonic = rtems_build_name( 'H', 'O', 'U', 'S' ); |
|
313 | 314 | |
|
314 | 315 | misc_name[QUEUE_RECV] = rtems_build_name( 'Q', '_', 'R', 'V' ); |
|
315 | 316 | misc_name[QUEUE_SEND] = rtems_build_name( 'Q', '_', 'S', 'D' ); |
|
316 | 317 | misc_name[QUEUE_PRC0] = rtems_build_name( 'Q', '_', 'P', '0' ); |
|
317 | 318 | misc_name[QUEUE_PRC1] = rtems_build_name( 'Q', '_', 'P', '1' ); |
|
318 | 319 | misc_name[QUEUE_PRC2] = rtems_build_name( 'Q', '_', 'P', '2' ); |
|
319 | 320 | } |
|
320 | 321 | |
|
321 | 322 | int create_all_tasks( void ) // create all tasks which run in the software |
|
322 | 323 | { |
|
323 | 324 | /** This function creates all RTEMS tasks used in the software. |
|
324 | 325 | * |
|
325 | 326 | * @return RTEMS directive status codes: |
|
326 | 327 | * - RTEMS_SUCCESSFUL - task created successfully |
|
327 | 328 | * - RTEMS_INVALID_ADDRESS - id is NULL |
|
328 | 329 | * - RTEMS_INVALID_NAME - invalid task name |
|
329 | 330 | * - RTEMS_INVALID_PRIORITY - invalid task priority |
|
330 | 331 | * - RTEMS_MP_NOT_CONFIGURED - multiprocessing not configured |
|
331 | 332 | * - RTEMS_TOO_MANY - too many tasks created |
|
332 | 333 | * - RTEMS_UNSATISFIED - not enough memory for stack/FP context |
|
333 | 334 | * - RTEMS_TOO_MANY - too many global objects |
|
334 | 335 | * |
|
335 | 336 | */ |
|
336 | 337 | |
|
337 | 338 | rtems_status_code status; |
|
338 | 339 | |
|
339 | 340 | //********** |
|
340 | 341 | // SPACEWIRE |
|
341 | 342 | // RECV |
|
342 | 343 | status = rtems_task_create( |
|
343 | 344 | Task_name[TASKID_RECV], TASK_PRIORITY_RECV, RTEMS_MINIMUM_STACK_SIZE, |
|
344 | 345 | RTEMS_DEFAULT_MODES, |
|
345 | 346 | RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_RECV] |
|
346 | 347 | ); |
|
347 | 348 | if (status == RTEMS_SUCCESSFUL) // SEND |
|
348 | 349 | { |
|
349 | 350 | status = rtems_task_create( |
|
350 | 351 | Task_name[TASKID_SEND], TASK_PRIORITY_SEND, RTEMS_MINIMUM_STACK_SIZE * 2, |
|
351 | 352 | RTEMS_DEFAULT_MODES, |
|
352 | 353 | RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_SEND] |
|
353 | 354 | ); |
|
354 | 355 | } |
|
355 | 356 | if (status == RTEMS_SUCCESSFUL) // WTDG |
|
356 | 357 | { |
|
357 | 358 | status = rtems_task_create( |
|
358 | 359 | Task_name[TASKID_WTDG], TASK_PRIORITY_WTDG, RTEMS_MINIMUM_STACK_SIZE, |
|
359 | 360 | RTEMS_DEFAULT_MODES, |
|
360 | 361 | RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_WTDG] |
|
361 | 362 | ); |
|
362 | 363 | } |
|
363 | 364 | if (status == RTEMS_SUCCESSFUL) // ACTN |
|
364 | 365 | { |
|
365 | 366 | status = rtems_task_create( |
|
366 | 367 | Task_name[TASKID_ACTN], TASK_PRIORITY_ACTN, RTEMS_MINIMUM_STACK_SIZE, |
|
367 | 368 | RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT, |
|
368 | 369 | RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_ACTN] |
|
369 | 370 | ); |
|
370 | 371 | } |
|
371 | 372 | if (status == RTEMS_SUCCESSFUL) // SPIQ |
|
372 | 373 | { |
|
373 | 374 | status = rtems_task_create( |
|
374 | 375 | Task_name[TASKID_SPIQ], TASK_PRIORITY_SPIQ, RTEMS_MINIMUM_STACK_SIZE, |
|
375 | 376 | RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT, |
|
376 | 377 | RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_SPIQ] |
|
377 | 378 | ); |
|
378 | 379 | } |
|
379 | 380 | |
|
380 | 381 | //****************** |
|
381 | 382 | // SPECTRAL MATRICES |
|
382 | 383 | if (status == RTEMS_SUCCESSFUL) // AVF0 |
|
383 | 384 | { |
|
384 | 385 | status = rtems_task_create( |
|
385 | 386 | Task_name[TASKID_AVF0], TASK_PRIORITY_AVF0, RTEMS_MINIMUM_STACK_SIZE, |
|
386 | 387 | RTEMS_DEFAULT_MODES, |
|
387 | 388 | RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF0] |
|
388 | 389 | ); |
|
389 | 390 | } |
|
390 | 391 | if (status == RTEMS_SUCCESSFUL) // PRC0 |
|
391 | 392 | { |
|
392 | 393 | status = rtems_task_create( |
|
393 | 394 | Task_name[TASKID_PRC0], TASK_PRIORITY_PRC0, RTEMS_MINIMUM_STACK_SIZE * 2, |
|
394 | 395 | RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT, |
|
395 | 396 | RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC0] |
|
396 | 397 | ); |
|
397 | 398 | } |
|
398 | 399 | if (status == RTEMS_SUCCESSFUL) // AVF1 |
|
399 | 400 | { |
|
400 | 401 | status = rtems_task_create( |
|
401 | 402 | Task_name[TASKID_AVF1], TASK_PRIORITY_AVF1, RTEMS_MINIMUM_STACK_SIZE, |
|
402 | 403 | RTEMS_DEFAULT_MODES, |
|
403 | 404 | RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF1] |
|
404 | 405 | ); |
|
405 | 406 | } |
|
406 | 407 | if (status == RTEMS_SUCCESSFUL) // PRC1 |
|
407 | 408 | { |
|
408 | 409 | status = rtems_task_create( |
|
409 | 410 | Task_name[TASKID_PRC1], TASK_PRIORITY_PRC1, RTEMS_MINIMUM_STACK_SIZE * 2, |
|
410 | 411 | RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT, |
|
411 | 412 | RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC1] |
|
412 | 413 | ); |
|
413 | 414 | } |
|
414 | 415 | if (status == RTEMS_SUCCESSFUL) // AVF2 |
|
415 | 416 | { |
|
416 | 417 | status = rtems_task_create( |
|
417 | 418 | Task_name[TASKID_AVF2], TASK_PRIORITY_AVF2, RTEMS_MINIMUM_STACK_SIZE, |
|
418 | 419 | RTEMS_DEFAULT_MODES, |
|
419 | 420 | RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVF2] |
|
420 | 421 | ); |
|
421 | 422 | } |
|
422 | 423 | if (status == RTEMS_SUCCESSFUL) // PRC2 |
|
423 | 424 | { |
|
424 | 425 | status = rtems_task_create( |
|
425 | 426 | Task_name[TASKID_PRC2], TASK_PRIORITY_PRC2, RTEMS_MINIMUM_STACK_SIZE * 2, |
|
426 | 427 | RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT, |
|
427 | 428 | RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_PRC2] |
|
428 | 429 | ); |
|
429 | 430 | } |
|
430 | 431 | |
|
431 | 432 | //**************** |
|
432 | 433 | // WAVEFORM PICKER |
|
433 | 434 | if (status == RTEMS_SUCCESSFUL) // WFRM |
|
434 | 435 | { |
|
435 | 436 | status = rtems_task_create( |
|
436 | 437 | Task_name[TASKID_WFRM], TASK_PRIORITY_WFRM, RTEMS_MINIMUM_STACK_SIZE, |
|
437 | 438 | RTEMS_DEFAULT_MODES, |
|
438 | 439 | RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_WFRM] |
|
439 | 440 | ); |
|
440 | 441 | } |
|
441 | 442 | if (status == RTEMS_SUCCESSFUL) // CWF3 |
|
442 | 443 | { |
|
443 | 444 | status = rtems_task_create( |
|
444 | 445 | Task_name[TASKID_CWF3], TASK_PRIORITY_CWF3, RTEMS_MINIMUM_STACK_SIZE, |
|
445 | 446 | RTEMS_DEFAULT_MODES, |
|
446 | 447 | RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF3] |
|
447 | 448 | ); |
|
448 | 449 | } |
|
449 | 450 | if (status == RTEMS_SUCCESSFUL) // CWF2 |
|
450 | 451 | { |
|
451 | 452 | status = rtems_task_create( |
|
452 | 453 | Task_name[TASKID_CWF2], TASK_PRIORITY_CWF2, RTEMS_MINIMUM_STACK_SIZE, |
|
453 | 454 | RTEMS_DEFAULT_MODES, |
|
454 | 455 | RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF2] |
|
455 | 456 | ); |
|
456 | 457 | } |
|
457 | 458 | if (status == RTEMS_SUCCESSFUL) // CWF1 |
|
458 | 459 | { |
|
459 | 460 | status = rtems_task_create( |
|
460 | 461 | Task_name[TASKID_CWF1], TASK_PRIORITY_CWF1, RTEMS_MINIMUM_STACK_SIZE, |
|
461 | 462 | RTEMS_DEFAULT_MODES, |
|
462 | 463 | RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CWF1] |
|
463 | 464 | ); |
|
464 | 465 | } |
|
465 | 466 | if (status == RTEMS_SUCCESSFUL) // SWBD |
|
466 | 467 | { |
|
467 | 468 | status = rtems_task_create( |
|
468 | 469 | Task_name[TASKID_SWBD], TASK_PRIORITY_SWBD, RTEMS_MINIMUM_STACK_SIZE, |
|
469 | 470 | RTEMS_DEFAULT_MODES, |
|
470 | 471 | RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_SWBD] |
|
471 | 472 | ); |
|
472 | 473 | } |
|
473 | 474 | |
|
474 | 475 | //***** |
|
475 | 476 | // MISC |
|
476 | 477 | if (status == RTEMS_SUCCESSFUL) // LOAD |
|
477 | 478 | { |
|
478 | 479 | status = rtems_task_create( |
|
479 | 480 | Task_name[TASKID_LOAD], TASK_PRIORITY_LOAD, RTEMS_MINIMUM_STACK_SIZE, |
|
480 | 481 | RTEMS_DEFAULT_MODES, |
|
481 | 482 | RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_LOAD] |
|
482 | 483 | ); |
|
483 | 484 | } |
|
484 | 485 | if (status == RTEMS_SUCCESSFUL) // DUMB |
|
485 | 486 | { |
|
486 | 487 | status = rtems_task_create( |
|
487 | 488 | Task_name[TASKID_DUMB], TASK_PRIORITY_DUMB, RTEMS_MINIMUM_STACK_SIZE, |
|
488 | 489 | RTEMS_DEFAULT_MODES, |
|
489 | 490 | RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_DUMB] |
|
490 | 491 | ); |
|
491 | 492 | } |
|
492 | 493 | if (status == RTEMS_SUCCESSFUL) // HOUS |
|
493 | 494 | { |
|
494 | 495 | status = rtems_task_create( |
|
495 | 496 | Task_name[TASKID_HOUS], TASK_PRIORITY_HOUS, RTEMS_MINIMUM_STACK_SIZE, |
|
496 | 497 | RTEMS_DEFAULT_MODES, |
|
497 | 498 | RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_HOUS] |
|
498 | 499 | ); |
|
499 | 500 | } |
|
500 | 501 | |
|
501 | 502 | return status; |
|
502 | 503 | } |
|
503 | 504 | |
|
504 | 505 | int start_recv_send_tasks( void ) |
|
505 | 506 | { |
|
506 | 507 | rtems_status_code status; |
|
507 | 508 | |
|
508 | 509 | status = rtems_task_start( Task_id[TASKID_RECV], recv_task, 1 ); |
|
509 | 510 | if (status!=RTEMS_SUCCESSFUL) { |
|
510 | 511 | BOOT_PRINTF("in INIT *** Error starting TASK_RECV\n") |
|
511 | 512 | } |
|
512 | 513 | |
|
513 | 514 | if (status == RTEMS_SUCCESSFUL) // SEND |
|
514 | 515 | { |
|
515 | 516 | status = rtems_task_start( Task_id[TASKID_SEND], send_task, 1 ); |
|
516 | 517 | if (status!=RTEMS_SUCCESSFUL) { |
|
517 | 518 | BOOT_PRINTF("in INIT *** Error starting TASK_SEND\n") |
|
518 | 519 | } |
|
519 | 520 | } |
|
520 | 521 | |
|
521 | 522 | return status; |
|
522 | 523 | } |
|
523 | 524 | |
|
524 | 525 | int start_all_tasks( void ) // start all tasks except SEND RECV and HOUS |
|
525 | 526 | { |
|
526 | 527 | /** This function starts all RTEMS tasks used in the software. |
|
527 | 528 | * |
|
528 | 529 | * @return RTEMS directive status codes: |
|
529 | 530 | * - RTEMS_SUCCESSFUL - ask started successfully |
|
530 | 531 | * - RTEMS_INVALID_ADDRESS - invalid task entry point |
|
531 | 532 | * - RTEMS_INVALID_ID - invalid task id |
|
532 | 533 | * - RTEMS_INCORRECT_STATE - task not in the dormant state |
|
533 | 534 | * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot start remote task |
|
534 | 535 | * |
|
535 | 536 | */ |
|
536 | 537 | // starts all the tasks fot eh flight software |
|
537 | 538 | |
|
538 | 539 | rtems_status_code status; |
|
539 | 540 | |
|
540 | 541 | //********** |
|
541 | 542 | // SPACEWIRE |
|
542 | 543 | status = rtems_task_start( Task_id[TASKID_SPIQ], spiq_task, 1 ); |
|
543 | 544 | if (status!=RTEMS_SUCCESSFUL) { |
|
544 | 545 | BOOT_PRINTF("in INIT *** Error starting TASK_SPIQ\n") |
|
545 | 546 | } |
|
546 | 547 | |
|
547 | 548 | if (status == RTEMS_SUCCESSFUL) // WTDG |
|
548 | 549 | { |
|
549 | 550 | status = rtems_task_start( Task_id[TASKID_WTDG], wtdg_task, 1 ); |
|
550 | 551 | if (status!=RTEMS_SUCCESSFUL) { |
|
551 | 552 | BOOT_PRINTF("in INIT *** Error starting TASK_WTDG\n") |
|
552 | 553 | } |
|
553 | 554 | } |
|
554 | 555 | |
|
555 | 556 | if (status == RTEMS_SUCCESSFUL) // ACTN |
|
556 | 557 | { |
|
557 | 558 | status = rtems_task_start( Task_id[TASKID_ACTN], actn_task, 1 ); |
|
558 | 559 | if (status!=RTEMS_SUCCESSFUL) { |
|
559 | 560 | BOOT_PRINTF("in INIT *** Error starting TASK_ACTN\n") |
|
560 | 561 | } |
|
561 | 562 | } |
|
562 | 563 | |
|
563 | 564 | //****************** |
|
564 | 565 | // SPECTRAL MATRICES |
|
565 | 566 | if (status == RTEMS_SUCCESSFUL) // AVF0 |
|
566 | 567 | { |
|
567 | 568 | status = rtems_task_start( Task_id[TASKID_AVF0], avf0_task, LFR_MODE_STANDBY ); |
|
568 | 569 | if (status!=RTEMS_SUCCESSFUL) { |
|
569 | 570 | BOOT_PRINTF("in INIT *** Error starting TASK_AVF0\n") |
|
570 | 571 | } |
|
571 | 572 | } |
|
572 | 573 | if (status == RTEMS_SUCCESSFUL) // PRC0 |
|
573 | 574 | { |
|
574 | 575 | status = rtems_task_start( Task_id[TASKID_PRC0], prc0_task, LFR_MODE_STANDBY ); |
|
575 | 576 | if (status!=RTEMS_SUCCESSFUL) { |
|
576 | 577 | BOOT_PRINTF("in INIT *** Error starting TASK_PRC0\n") |
|
577 | 578 | } |
|
578 | 579 | } |
|
579 | 580 | if (status == RTEMS_SUCCESSFUL) // AVF1 |
|
580 | 581 | { |
|
581 | 582 | status = rtems_task_start( Task_id[TASKID_AVF1], avf1_task, LFR_MODE_STANDBY ); |
|
582 | 583 | if (status!=RTEMS_SUCCESSFUL) { |
|
583 | 584 | BOOT_PRINTF("in INIT *** Error starting TASK_AVF1\n") |
|
584 | 585 | } |
|
585 | 586 | } |
|
586 | 587 | if (status == RTEMS_SUCCESSFUL) // PRC1 |
|
587 | 588 | { |
|
588 | 589 | status = rtems_task_start( Task_id[TASKID_PRC1], prc1_task, LFR_MODE_STANDBY ); |
|
589 | 590 | if (status!=RTEMS_SUCCESSFUL) { |
|
590 | 591 | BOOT_PRINTF("in INIT *** Error starting TASK_PRC1\n") |
|
591 | 592 | } |
|
592 | 593 | } |
|
593 | 594 | if (status == RTEMS_SUCCESSFUL) // AVF2 |
|
594 | 595 | { |
|
595 | 596 | status = rtems_task_start( Task_id[TASKID_AVF2], avf2_task, 1 ); |
|
596 | 597 | if (status!=RTEMS_SUCCESSFUL) { |
|
597 | 598 | BOOT_PRINTF("in INIT *** Error starting TASK_AVF2\n") |
|
598 | 599 | } |
|
599 | 600 | } |
|
600 | 601 | if (status == RTEMS_SUCCESSFUL) // PRC2 |
|
601 | 602 | { |
|
602 | 603 | status = rtems_task_start( Task_id[TASKID_PRC2], prc2_task, 1 ); |
|
603 | 604 | if (status!=RTEMS_SUCCESSFUL) { |
|
604 | 605 | BOOT_PRINTF("in INIT *** Error starting TASK_PRC2\n") |
|
605 | 606 | } |
|
606 | 607 | } |
|
607 | 608 | |
|
608 | 609 | //**************** |
|
609 | 610 | // WAVEFORM PICKER |
|
610 | 611 | if (status == RTEMS_SUCCESSFUL) // WFRM |
|
611 | 612 | { |
|
612 | 613 | status = rtems_task_start( Task_id[TASKID_WFRM], wfrm_task, 1 ); |
|
613 | 614 | if (status!=RTEMS_SUCCESSFUL) { |
|
614 | 615 | BOOT_PRINTF("in INIT *** Error starting TASK_WFRM\n") |
|
615 | 616 | } |
|
616 | 617 | } |
|
617 | 618 | if (status == RTEMS_SUCCESSFUL) // CWF3 |
|
618 | 619 | { |
|
619 | 620 | status = rtems_task_start( Task_id[TASKID_CWF3], cwf3_task, 1 ); |
|
620 | 621 | if (status!=RTEMS_SUCCESSFUL) { |
|
621 | 622 | BOOT_PRINTF("in INIT *** Error starting TASK_CWF3\n") |
|
622 | 623 | } |
|
623 | 624 | } |
|
624 | 625 | if (status == RTEMS_SUCCESSFUL) // CWF2 |
|
625 | 626 | { |
|
626 | 627 | status = rtems_task_start( Task_id[TASKID_CWF2], cwf2_task, 1 ); |
|
627 | 628 | if (status!=RTEMS_SUCCESSFUL) { |
|
628 | 629 | BOOT_PRINTF("in INIT *** Error starting TASK_CWF2\n") |
|
629 | 630 | } |
|
630 | 631 | } |
|
631 | 632 | if (status == RTEMS_SUCCESSFUL) // CWF1 |
|
632 | 633 | { |
|
633 | 634 | status = rtems_task_start( Task_id[TASKID_CWF1], cwf1_task, 1 ); |
|
634 | 635 | if (status!=RTEMS_SUCCESSFUL) { |
|
635 | 636 | BOOT_PRINTF("in INIT *** Error starting TASK_CWF1\n") |
|
636 | 637 | } |
|
637 | 638 | } |
|
638 | 639 | if (status == RTEMS_SUCCESSFUL) // SWBD |
|
639 | 640 | { |
|
640 | 641 | status = rtems_task_start( Task_id[TASKID_SWBD], swbd_task, 1 ); |
|
641 | 642 | if (status!=RTEMS_SUCCESSFUL) { |
|
642 | 643 | BOOT_PRINTF("in INIT *** Error starting TASK_SWBD\n") |
|
643 | 644 | } |
|
644 | 645 | } |
|
645 | 646 | |
|
646 | 647 | //***** |
|
647 | 648 | // MISC |
|
648 | 649 | if (status == RTEMS_SUCCESSFUL) // HOUS |
|
649 | 650 | { |
|
650 | 651 | status = rtems_task_start( Task_id[TASKID_HOUS], hous_task, 1 ); |
|
651 | 652 | if (status!=RTEMS_SUCCESSFUL) { |
|
652 | 653 | BOOT_PRINTF("in INIT *** Error starting TASK_HOUS\n") |
|
653 | 654 | } |
|
654 | 655 | } |
|
655 | 656 | if (status == RTEMS_SUCCESSFUL) // DUMB |
|
656 | 657 | { |
|
657 | 658 | status = rtems_task_start( Task_id[TASKID_DUMB], dumb_task, 1 ); |
|
658 | 659 | if (status!=RTEMS_SUCCESSFUL) { |
|
659 | 660 | BOOT_PRINTF("in INIT *** Error starting TASK_DUMB\n") |
|
660 | 661 | } |
|
661 | 662 | } |
|
662 | 663 | if (status == RTEMS_SUCCESSFUL) // LOAD |
|
663 | 664 | { |
|
664 | 665 | status = rtems_task_start( Task_id[TASKID_LOAD], load_task, 1 ); |
|
665 | 666 | if (status!=RTEMS_SUCCESSFUL) { |
|
666 | 667 | BOOT_PRINTF("in INIT *** Error starting TASK_LOAD\n") |
|
667 | 668 | } |
|
668 | 669 | } |
|
669 | 670 | |
|
670 | 671 | return status; |
|
671 | 672 | } |
|
672 | 673 | |
|
673 | 674 | rtems_status_code create_message_queues( void ) // create the two message queues used in the software |
|
674 | 675 | { |
|
675 | 676 | rtems_status_code status_recv; |
|
676 | 677 | rtems_status_code status_send; |
|
677 | 678 | rtems_status_code status_q_p0; |
|
678 | 679 | rtems_status_code status_q_p1; |
|
679 | 680 | rtems_status_code status_q_p2; |
|
680 | 681 | rtems_status_code ret; |
|
681 | 682 | rtems_id queue_id; |
|
682 | 683 | |
|
683 | 684 | //**************************************** |
|
684 | 685 | // create the queue for handling valid TCs |
|
685 | 686 | status_recv = rtems_message_queue_create( misc_name[QUEUE_RECV], |
|
686 | 687 | MSG_QUEUE_COUNT_RECV, CCSDS_TC_PKT_MAX_SIZE, |
|
687 | 688 | RTEMS_FIFO | RTEMS_LOCAL, &queue_id ); |
|
688 | 689 | if ( status_recv != RTEMS_SUCCESSFUL ) { |
|
689 | 690 | PRINTF1("in create_message_queues *** ERR creating QUEU queue, %d\n", status_recv) |
|
690 | 691 | } |
|
691 | 692 | |
|
692 | 693 | //************************************************ |
|
693 | 694 | // create the queue for handling TM packet sending |
|
694 | 695 | status_send = rtems_message_queue_create( misc_name[QUEUE_SEND], |
|
695 | 696 | MSG_QUEUE_COUNT_SEND, MSG_QUEUE_SIZE_SEND, |
|
696 | 697 | RTEMS_FIFO | RTEMS_LOCAL, &queue_id ); |
|
697 | 698 | if ( status_send != RTEMS_SUCCESSFUL ) { |
|
698 | 699 | PRINTF1("in create_message_queues *** ERR creating PKTS queue, %d\n", status_send) |
|
699 | 700 | } |
|
700 | 701 | |
|
701 | 702 | //***************************************************************************** |
|
702 | 703 | // create the queue for handling averaged spectral matrices for processing @ f0 |
|
703 | 704 | status_q_p0 = rtems_message_queue_create( misc_name[QUEUE_PRC0], |
|
704 | 705 | MSG_QUEUE_COUNT_PRC0, MSG_QUEUE_SIZE_PRC0, |
|
705 | 706 | RTEMS_FIFO | RTEMS_LOCAL, &queue_id ); |
|
706 | 707 | if ( status_q_p0 != RTEMS_SUCCESSFUL ) { |
|
707 | 708 | PRINTF1("in create_message_queues *** ERR creating Q_P0 queue, %d\n", status_q_p0) |
|
708 | 709 | } |
|
709 | 710 | |
|
710 | 711 | //***************************************************************************** |
|
711 | 712 | // create the queue for handling averaged spectral matrices for processing @ f1 |
|
712 | 713 | status_q_p1 = rtems_message_queue_create( misc_name[QUEUE_PRC1], |
|
713 | 714 | MSG_QUEUE_COUNT_PRC1, MSG_QUEUE_SIZE_PRC1, |
|
714 | 715 | RTEMS_FIFO | RTEMS_LOCAL, &queue_id ); |
|
715 | 716 | if ( status_q_p1 != RTEMS_SUCCESSFUL ) { |
|
716 | 717 | PRINTF1("in create_message_queues *** ERR creating Q_P1 queue, %d\n", status_q_p1) |
|
717 | 718 | } |
|
718 | 719 | |
|
719 | 720 | //***************************************************************************** |
|
720 | 721 | // create the queue for handling averaged spectral matrices for processing @ f2 |
|
721 | 722 | status_q_p2 = rtems_message_queue_create( misc_name[QUEUE_PRC2], |
|
722 | 723 | MSG_QUEUE_COUNT_PRC2, MSG_QUEUE_SIZE_PRC2, |
|
723 | 724 | RTEMS_FIFO | RTEMS_LOCAL, &queue_id ); |
|
724 | 725 | if ( status_q_p2 != RTEMS_SUCCESSFUL ) { |
|
725 | 726 | PRINTF1("in create_message_queues *** ERR creating Q_P2 queue, %d\n", status_q_p2) |
|
726 | 727 | } |
|
727 | 728 | |
|
728 | 729 | if ( status_recv != RTEMS_SUCCESSFUL ) |
|
729 | 730 | { |
|
730 | 731 | ret = status_recv; |
|
731 | 732 | } |
|
732 | 733 | else if( status_send != RTEMS_SUCCESSFUL ) |
|
733 | 734 | { |
|
734 | 735 | ret = status_send; |
|
735 | 736 | } |
|
736 | 737 | else if( status_q_p0 != RTEMS_SUCCESSFUL ) |
|
737 | 738 | { |
|
738 | 739 | ret = status_q_p0; |
|
739 | 740 | } |
|
740 | 741 | else if( status_q_p1 != RTEMS_SUCCESSFUL ) |
|
741 | 742 | { |
|
742 | 743 | ret = status_q_p1; |
|
743 | 744 | } |
|
744 | 745 | else |
|
745 | 746 | { |
|
746 | 747 | ret = status_q_p2; |
|
747 | 748 | } |
|
748 | 749 | |
|
749 | 750 | return ret; |
|
750 | 751 | } |
|
751 | 752 | |
|
752 | 753 | rtems_status_code get_message_queue_id_send( rtems_id *queue_id ) |
|
753 | 754 | { |
|
754 | 755 | rtems_status_code status; |
|
755 | 756 | rtems_name queue_name; |
|
756 | 757 | |
|
757 | 758 | queue_name = rtems_build_name( 'Q', '_', 'S', 'D' ); |
|
758 | 759 | |
|
759 | 760 | status = rtems_message_queue_ident( queue_name, 0, queue_id ); |
|
760 | 761 | |
|
761 | 762 | return status; |
|
762 | 763 | } |
|
763 | 764 | |
|
764 | 765 | rtems_status_code get_message_queue_id_recv( rtems_id *queue_id ) |
|
765 | 766 | { |
|
766 | 767 | rtems_status_code status; |
|
767 | 768 | rtems_name queue_name; |
|
768 | 769 | |
|
769 | 770 | queue_name = rtems_build_name( 'Q', '_', 'R', 'V' ); |
|
770 | 771 | |
|
771 | 772 | status = rtems_message_queue_ident( queue_name, 0, queue_id ); |
|
772 | 773 | |
|
773 | 774 | return status; |
|
774 | 775 | } |
|
775 | 776 | |
|
776 | 777 | rtems_status_code get_message_queue_id_prc0( rtems_id *queue_id ) |
|
777 | 778 | { |
|
778 | 779 | rtems_status_code status; |
|
779 | 780 | rtems_name queue_name; |
|
780 | 781 | |
|
781 | 782 | queue_name = rtems_build_name( 'Q', '_', 'P', '0' ); |
|
782 | 783 | |
|
783 | 784 | status = rtems_message_queue_ident( queue_name, 0, queue_id ); |
|
784 | 785 | |
|
785 | 786 | return status; |
|
786 | 787 | } |
|
787 | 788 | |
|
788 | 789 | rtems_status_code get_message_queue_id_prc1( rtems_id *queue_id ) |
|
789 | 790 | { |
|
790 | 791 | rtems_status_code status; |
|
791 | 792 | rtems_name queue_name; |
|
792 | 793 | |
|
793 | 794 | queue_name = rtems_build_name( 'Q', '_', 'P', '1' ); |
|
794 | 795 | |
|
795 | 796 | status = rtems_message_queue_ident( queue_name, 0, queue_id ); |
|
796 | 797 | |
|
797 | 798 | return status; |
|
798 | 799 | } |
|
799 | 800 | |
|
800 | 801 | rtems_status_code get_message_queue_id_prc2( rtems_id *queue_id ) |
|
801 | 802 | { |
|
802 | 803 | rtems_status_code status; |
|
803 | 804 | rtems_name queue_name; |
|
804 | 805 | |
|
805 | 806 | queue_name = rtems_build_name( 'Q', '_', 'P', '2' ); |
|
806 | 807 | |
|
807 | 808 | status = rtems_message_queue_ident( queue_name, 0, queue_id ); |
|
808 | 809 | |
|
809 | 810 | return status; |
|
810 | 811 | } |
|
811 | 812 | |
|
812 | 813 | void update_queue_max_count( rtems_id queue_id, unsigned char*fifo_size_max ) |
|
813 | 814 | { |
|
814 | 815 | u_int32_t count; |
|
815 | 816 | rtems_status_code status; |
|
816 | 817 | |
|
817 | 818 | status = rtems_message_queue_get_number_pending( queue_id, &count ); |
|
818 | 819 | |
|
819 | 820 | count = count + 1; |
|
820 | 821 | |
|
821 | 822 | if (status != RTEMS_SUCCESSFUL) |
|
822 | 823 | { |
|
823 | 824 | PRINTF1("in update_queue_max_count *** ERR = %d\n", status) |
|
824 | 825 | } |
|
825 | 826 | else |
|
826 | 827 | { |
|
827 | 828 | if (count > *fifo_size_max) |
|
828 | 829 | { |
|
829 | 830 | *fifo_size_max = count; |
|
830 | 831 | } |
|
831 | 832 | } |
|
832 | 833 | } |
|
833 | 834 | |
|
834 | 835 | void init_ring(ring_node ring[], unsigned char nbNodes, volatile int buffer[], unsigned int bufferSize ) |
|
835 | 836 | { |
|
836 | 837 | unsigned char i; |
|
837 | 838 | |
|
838 | 839 | //*************** |
|
839 | 840 | // BUFFER ADDRESS |
|
840 | 841 | for(i=0; i<nbNodes; i++) |
|
841 | 842 | { |
|
842 | 843 | ring[i].coarseTime = 0xffffffff; |
|
843 | 844 | ring[i].fineTime = 0xffffffff; |
|
844 | 845 | ring[i].sid = 0x00; |
|
845 | 846 | ring[i].status = 0x00; |
|
846 | 847 | ring[i].buffer_address = (int) &buffer[ i * bufferSize ]; |
|
847 | 848 | } |
|
848 | 849 | |
|
849 | 850 | //***** |
|
850 | 851 | // NEXT |
|
851 | 852 | ring[ nbNodes - 1 ].next = (ring_node*) &ring[ 0 ]; |
|
852 | 853 | for(i=0; i<nbNodes-1; i++) |
|
853 | 854 | { |
|
854 | 855 | ring[i].next = (ring_node*) &ring[ i + 1 ]; |
|
855 | 856 | } |
|
856 | 857 | |
|
857 | 858 | //********* |
|
858 | 859 | // PREVIOUS |
|
859 | 860 | ring[ 0 ].previous = (ring_node*) &ring[ nbNodes - 1 ]; |
|
860 | 861 | for(i=1; i<nbNodes; i++) |
|
861 | 862 | { |
|
862 | 863 | ring[i].previous = (ring_node*) &ring[ i - 1 ]; |
|
863 | 864 | } |
|
864 | 865 | } |
@@ -1,652 +1,698 | |||
|
1 | 1 | /** General usage functions and RTEMS tasks. |
|
2 | 2 | * |
|
3 | 3 | * @file |
|
4 | 4 | * @author P. LEROY |
|
5 | 5 | * |
|
6 | 6 | */ |
|
7 | 7 | |
|
8 | 8 | #include "fsw_misc.h" |
|
9 | 9 | |
|
10 | 10 | void timer_configure(unsigned char timer, unsigned int clock_divider, |
|
11 | 11 | unsigned char interrupt_level, rtems_isr (*timer_isr)() ) |
|
12 | 12 | { |
|
13 | 13 | /** This function configures a GPTIMER timer instantiated in the VHDL design. |
|
14 | 14 | * |
|
15 | 15 | * @param gptimer_regs points to the APB registers of the GPTIMER IP core. |
|
16 | 16 | * @param timer is the number of the timer in the IP core (several timers can be instantiated). |
|
17 | 17 | * @param clock_divider is the divider of the 1 MHz clock that will be configured. |
|
18 | 18 | * @param interrupt_level is the interrupt level that the timer drives. |
|
19 | 19 | * @param timer_isr is the interrupt subroutine that will be attached to the IRQ driven by the timer. |
|
20 | 20 | * |
|
21 | 21 | * Interrupt levels are described in the SPARC documentation sparcv8.pdf p.76 |
|
22 | 22 | * |
|
23 | 23 | */ |
|
24 | 24 | |
|
25 | 25 | rtems_status_code status; |
|
26 | 26 | rtems_isr_entry old_isr_handler; |
|
27 | 27 | |
|
28 | 28 | gptimer_regs->timer[timer].ctrl = 0x00; // reset the control register |
|
29 | 29 | |
|
30 | 30 | status = rtems_interrupt_catch( timer_isr, interrupt_level, &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels |
|
31 | 31 | if (status!=RTEMS_SUCCESSFUL) |
|
32 | 32 | { |
|
33 | 33 | PRINTF("in configure_timer *** ERR rtems_interrupt_catch\n") |
|
34 | 34 | } |
|
35 | 35 | |
|
36 | 36 | timer_set_clock_divider( timer, clock_divider); |
|
37 | 37 | } |
|
38 | 38 | |
|
39 | 39 | void timer_start(unsigned char timer) |
|
40 | 40 | { |
|
41 | 41 | /** This function starts a GPTIMER timer. |
|
42 | 42 | * |
|
43 | 43 | * @param gptimer_regs points to the APB registers of the GPTIMER IP core. |
|
44 | 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 | 48 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000010; // clear pending IRQ if any |
|
49 | 49 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000004; // LD load value from the reload register |
|
50 | 50 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000001; // EN enable the timer |
|
51 | 51 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000002; // RS restart |
|
52 | 52 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000008; // IE interrupt enable |
|
53 | 53 | } |
|
54 | 54 | |
|
55 | 55 | void timer_stop(unsigned char timer) |
|
56 | 56 | { |
|
57 | 57 | /** This function stops a GPTIMER timer. |
|
58 | 58 | * |
|
59 | 59 | * @param gptimer_regs points to the APB registers of the GPTIMER IP core. |
|
60 | 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 | 64 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & 0xfffffffe; // EN enable the timer |
|
65 | 65 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & 0xffffffef; // IE interrupt enable |
|
66 | 66 | gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000010; // clear pending IRQ if any |
|
67 | 67 | } |
|
68 | 68 | |
|
69 | 69 | void timer_set_clock_divider(unsigned char timer, unsigned int clock_divider) |
|
70 | 70 | { |
|
71 | 71 | /** This function sets the clock divider of a GPTIMER timer. |
|
72 | 72 | * |
|
73 | 73 | * @param gptimer_regs points to the APB registers of the GPTIMER IP core. |
|
74 | 74 | * @param timer is the number of the timer in the IP core (several timers can be instantiated). |
|
75 | 75 | * @param clock_divider is the divider of the 1 MHz clock that will be configured. |
|
76 | 76 | * |
|
77 | 77 | */ |
|
78 | 78 | |
|
79 | 79 | gptimer_regs->timer[timer].reload = clock_divider; // base clock frequency is 1 MHz |
|
80 | 80 | } |
|
81 | 81 | |
|
82 | 82 | // WATCHDOG |
|
83 | 83 | |
|
84 | 84 | rtems_isr watchdog_isr( rtems_vector_number vector ) |
|
85 | 85 | { |
|
86 | 86 | rtems_status_code status_code; |
|
87 | 87 | |
|
88 | 88 | status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_12 ); |
|
89 | 89 | } |
|
90 | 90 | |
|
91 | 91 | void watchdog_configure(void) |
|
92 | 92 | { |
|
93 | 93 | /** This function configure the watchdog. |
|
94 | 94 | * |
|
95 | 95 | * @param gptimer_regs points to the APB registers of the GPTIMER IP core. |
|
96 | 96 | * @param timer is the number of the timer in the IP core (several timers can be instantiated). |
|
97 | 97 | * |
|
98 | 98 | * The watchdog is a timer provided by the GPTIMER IP core of the GRLIB. |
|
99 | 99 | * |
|
100 | 100 | */ |
|
101 | 101 | |
|
102 | 102 | LEON_Mask_interrupt( IRQ_GPTIMER_WATCHDOG ); // mask gptimer/watchdog interrupt during configuration |
|
103 | 103 | |
|
104 | 104 | timer_configure( TIMER_WATCHDOG, CLKDIV_WATCHDOG, IRQ_SPARC_GPTIMER_WATCHDOG, watchdog_isr ); |
|
105 | 105 | |
|
106 | 106 | LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG ); // clear gptimer/watchdog interrupt |
|
107 | 107 | } |
|
108 | 108 | |
|
109 | 109 | void watchdog_stop(void) |
|
110 | 110 | { |
|
111 | 111 | LEON_Mask_interrupt( IRQ_GPTIMER_WATCHDOG ); // mask gptimer/watchdog interrupt line |
|
112 | 112 | timer_stop( TIMER_WATCHDOG ); |
|
113 | 113 | LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG ); // clear gptimer/watchdog interrupt |
|
114 | 114 | } |
|
115 | 115 | |
|
116 | 116 | void watchdog_reload(void) |
|
117 | 117 | { |
|
118 | 118 | /** This function reloads the watchdog timer counter with the timer reload value. |
|
119 | 119 | * |
|
120 | 120 | * |
|
121 | 121 | */ |
|
122 | 122 | |
|
123 | 123 | gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | 0x00000004; // LD load value from the reload register |
|
124 | 124 | } |
|
125 | 125 | |
|
126 | 126 | void watchdog_start(void) |
|
127 | 127 | { |
|
128 | 128 | /** This function starts the watchdog timer. |
|
129 | 129 | * |
|
130 | 130 | * @param gptimer_regs points to the APB registers of the GPTIMER IP core. |
|
131 | 131 | * @param timer is the number of the timer in the IP core (several timers can be instantiated). |
|
132 | 132 | * |
|
133 | 133 | */ |
|
134 | 134 | |
|
135 | 135 | LEON_Clear_interrupt( IRQ_GPTIMER_WATCHDOG ); |
|
136 | 136 | |
|
137 | 137 | gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | 0x00000010; // clear pending IRQ if any |
|
138 | 138 | gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | 0x00000004; // LD load value from the reload register |
|
139 | 139 | gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | 0x00000001; // EN enable the timer |
|
140 | 140 | gptimer_regs->timer[TIMER_WATCHDOG].ctrl = gptimer_regs->timer[TIMER_WATCHDOG].ctrl | 0x00000008; // IE interrupt enable |
|
141 | 141 | |
|
142 | 142 | LEON_Unmask_interrupt( IRQ_GPTIMER_WATCHDOG ); |
|
143 | 143 | |
|
144 | 144 | } |
|
145 | 145 | |
|
146 | 146 | int send_console_outputs_on_apbuart_port( void ) // Send the console outputs on the apbuart port |
|
147 | 147 | { |
|
148 | 148 | struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART; |
|
149 | 149 | |
|
150 | 150 | apbuart_regs->ctrl = APBUART_CTRL_REG_MASK_TE; |
|
151 | 151 | |
|
152 | 152 | return 0; |
|
153 | 153 | } |
|
154 | 154 | |
|
155 | 155 | int enable_apbuart_transmitter( void ) // set the bit 1, TE Transmitter Enable to 1 in the APBUART control register |
|
156 | 156 | { |
|
157 | 157 | struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART; |
|
158 | 158 | |
|
159 | 159 | apbuart_regs->ctrl = apbuart_regs->ctrl | APBUART_CTRL_REG_MASK_TE; |
|
160 | 160 | |
|
161 | 161 | return 0; |
|
162 | 162 | } |
|
163 | 163 | |
|
164 | 164 | void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value) |
|
165 | 165 | { |
|
166 | 166 | /** This function sets the scaler reload register of the apbuart module |
|
167 | 167 | * |
|
168 | 168 | * @param regs is the address of the apbuart registers in memory |
|
169 | 169 | * @param value is the value that will be stored in the scaler register |
|
170 | 170 | * |
|
171 | 171 | * The value shall be set by the software to get data on the serial interface. |
|
172 | 172 | * |
|
173 | 173 | */ |
|
174 | 174 | |
|
175 | 175 | struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) regs; |
|
176 | 176 | |
|
177 | 177 | apbuart_regs->scaler = value; |
|
178 | 178 | BOOT_PRINTF1("OK *** apbuart port scaler reload register set to 0x%x\n", value) |
|
179 | 179 | } |
|
180 | 180 | |
|
181 | 181 | //************ |
|
182 | 182 | // RTEMS TASKS |
|
183 | 183 | |
|
184 | 184 | rtems_task load_task(rtems_task_argument argument) |
|
185 | 185 | { |
|
186 | 186 | BOOT_PRINTF("in LOAD *** \n") |
|
187 | 187 | |
|
188 | 188 | rtems_status_code status; |
|
189 | 189 | unsigned int i; |
|
190 | 190 | unsigned int j; |
|
191 | 191 | rtems_name name_watchdog_rate_monotonic; // name of the watchdog rate monotonic |
|
192 | 192 | rtems_id watchdog_period_id; // id of the watchdog rate monotonic period |
|
193 | 193 | |
|
194 | 194 | name_watchdog_rate_monotonic = rtems_build_name( 'L', 'O', 'A', 'D' ); |
|
195 | 195 | |
|
196 | 196 | status = rtems_rate_monotonic_create( name_watchdog_rate_monotonic, &watchdog_period_id ); |
|
197 | 197 | if( status != RTEMS_SUCCESSFUL ) { |
|
198 | 198 | PRINTF1( "in LOAD *** rtems_rate_monotonic_create failed with status of %d\n", status ) |
|
199 | 199 | } |
|
200 | 200 | |
|
201 | 201 | i = 0; |
|
202 | 202 | j = 0; |
|
203 | 203 | |
|
204 | 204 | watchdog_configure(); |
|
205 | 205 | |
|
206 | 206 | watchdog_start(); |
|
207 | 207 | |
|
208 | 208 | while(1){ |
|
209 | 209 | status = rtems_rate_monotonic_period( watchdog_period_id, WATCHDOG_PERIOD ); |
|
210 | 210 | watchdog_reload(); |
|
211 | 211 | i = i + 1; |
|
212 | 212 | if ( i == 10 ) |
|
213 | 213 | { |
|
214 | 214 | i = 0; |
|
215 | 215 | j = j + 1; |
|
216 | 216 | PRINTF1("%d\n", j) |
|
217 | 217 | } |
|
218 | 218 | if (j == 3 ) |
|
219 | 219 | { |
|
220 | 220 | status = rtems_task_delete(RTEMS_SELF); |
|
221 | 221 | } |
|
222 | 222 | } |
|
223 | 223 | } |
|
224 | 224 | |
|
225 | 225 | rtems_task hous_task(rtems_task_argument argument) |
|
226 | 226 | { |
|
227 | 227 | rtems_status_code status; |
|
228 | 228 | rtems_status_code spare_status; |
|
229 | 229 | rtems_id queue_id; |
|
230 | 230 | rtems_rate_monotonic_period_status period_status; |
|
231 | 231 | |
|
232 | 232 | status = get_message_queue_id_send( &queue_id ); |
|
233 | 233 | if (status != RTEMS_SUCCESSFUL) |
|
234 | 234 | { |
|
235 | 235 | PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status) |
|
236 | 236 | } |
|
237 | 237 | |
|
238 | 238 | BOOT_PRINTF("in HOUS ***\n") |
|
239 | 239 | |
|
240 | 240 | if (rtems_rate_monotonic_ident( name_hk_rate_monotonic, &HK_id) != RTEMS_SUCCESSFUL) { |
|
241 | 241 | status = rtems_rate_monotonic_create( name_hk_rate_monotonic, &HK_id ); |
|
242 | 242 | if( status != RTEMS_SUCCESSFUL ) { |
|
243 | 243 | PRINTF1( "rtems_rate_monotonic_create failed with status of %d\n", status ) |
|
244 | 244 | } |
|
245 | 245 | } |
|
246 | 246 | |
|
247 | 247 | status = rtems_rate_monotonic_cancel(HK_id); |
|
248 | 248 | if( status != RTEMS_SUCCESSFUL ) { |
|
249 | 249 | PRINTF1( "ERR *** in HOUS *** rtems_rate_monotonic_cancel(HK_id) ***code: %d\n", status ) |
|
250 | 250 | } |
|
251 | 251 | else { |
|
252 | 252 | DEBUG_PRINTF("OK *** in HOUS *** rtems_rate_monotonic_cancel(HK_id)\n") |
|
253 | 253 | } |
|
254 | 254 | |
|
255 | 255 | // startup phase |
|
256 | 256 | status = rtems_rate_monotonic_period( HK_id, SY_LFR_TIME_SYN_TIMEOUT_in_ticks ); |
|
257 | 257 | status = rtems_rate_monotonic_get_status( HK_id, &period_status ); |
|
258 | 258 | DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state) |
|
259 | 259 | while(period_status.state != RATE_MONOTONIC_EXPIRED ) // after SY_LFR_TIME_SYN_TIMEOUT ms, starts HK anyway |
|
260 | 260 | { |
|
261 | 261 | if ((time_management_regs->coarse_time & 0x80000000) == 0x00000000) // check time synchronization |
|
262 | 262 | { |
|
263 | 263 | break; // break if LFR is synchronized |
|
264 | 264 | } |
|
265 | 265 | else |
|
266 | 266 | { |
|
267 | 267 | status = rtems_rate_monotonic_get_status( HK_id, &period_status ); |
|
268 | 268 | // sched_yield(); |
|
269 | 269 | status = rtems_task_wake_after( 10 ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 100 ms = 10 * 10 ms |
|
270 | 270 | } |
|
271 | 271 | } |
|
272 | 272 | status = rtems_rate_monotonic_cancel(HK_id); |
|
273 | 273 | DEBUG_PRINTF1("startup HK, HK_id status = %d\n", period_status.state) |
|
274 | 274 | |
|
275 | 275 | set_hk_lfr_reset_cause( POWER_ON ); |
|
276 | 276 | |
|
277 | 277 | while(1){ // launch the rate monotonic task |
|
278 | 278 | status = rtems_rate_monotonic_period( HK_id, HK_PERIOD ); |
|
279 | 279 | if ( status != RTEMS_SUCCESSFUL ) { |
|
280 | 280 | PRINTF1( "in HOUS *** ERR period: %d\n", status); |
|
281 | 281 | spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_6 ); |
|
282 | 282 | } |
|
283 | 283 | else { |
|
284 | 284 | housekeeping_packet.packetSequenceControl[0] = (unsigned char) (sequenceCounterHK >> 8); |
|
285 | 285 | housekeeping_packet.packetSequenceControl[1] = (unsigned char) (sequenceCounterHK ); |
|
286 | 286 | increment_seq_counter( &sequenceCounterHK ); |
|
287 | 287 | |
|
288 | 288 | housekeeping_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24); |
|
289 | 289 | housekeeping_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16); |
|
290 | 290 | housekeeping_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8); |
|
291 | 291 | housekeeping_packet.time[3] = (unsigned char) (time_management_regs->coarse_time); |
|
292 | 292 | housekeeping_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8); |
|
293 | 293 | housekeeping_packet.time[5] = (unsigned char) (time_management_regs->fine_time); |
|
294 | 294 | |
|
295 | 295 | spacewire_update_statistics(); |
|
296 | 296 | |
|
297 | hk_lfr_le_me_he_update(); | |
|
298 | ||
|
297 | 299 | housekeeping_packet.hk_lfr_q_sd_fifo_size_max = hk_lfr_q_sd_fifo_size_max; |
|
298 | 300 | housekeeping_packet.hk_lfr_q_rv_fifo_size_max = hk_lfr_q_rv_fifo_size_max; |
|
299 | 301 | housekeeping_packet.hk_lfr_q_p0_fifo_size_max = hk_lfr_q_p0_fifo_size_max; |
|
300 | 302 | housekeeping_packet.hk_lfr_q_p1_fifo_size_max = hk_lfr_q_p1_fifo_size_max; |
|
301 | 303 | housekeeping_packet.hk_lfr_q_p2_fifo_size_max = hk_lfr_q_p2_fifo_size_max; |
|
302 | 304 | |
|
303 | 305 | housekeeping_packet.sy_lfr_common_parameters_spare = parameter_dump_packet.sy_lfr_common_parameters_spare; |
|
304 | 306 | housekeeping_packet.sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; |
|
305 | 307 | get_temperatures( housekeeping_packet.hk_lfr_temp_scm ); |
|
306 | 308 | get_v_e1_e2_f3( housekeeping_packet.hk_lfr_sc_v_f3 ); |
|
307 | 309 | get_cpu_load( (unsigned char *) &housekeeping_packet.hk_lfr_cpu_load ); |
|
308 | 310 | |
|
309 | 311 | // SEND PACKET |
|
310 | 312 | status = rtems_message_queue_send( queue_id, &housekeeping_packet, |
|
311 | 313 | PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES); |
|
312 | 314 | if (status != RTEMS_SUCCESSFUL) { |
|
313 | 315 | PRINTF1("in HOUS *** ERR send: %d\n", status) |
|
314 | 316 | } |
|
315 | 317 | } |
|
316 | 318 | } |
|
317 | 319 | |
|
318 | 320 | PRINTF("in HOUS *** deleting task\n") |
|
319 | 321 | |
|
320 | 322 | status = rtems_task_delete( RTEMS_SELF ); // should not return |
|
321 | 323 | |
|
322 | 324 | return; |
|
323 | 325 | } |
|
324 | 326 | |
|
325 | 327 | rtems_task dumb_task( rtems_task_argument unused ) |
|
326 | 328 | { |
|
327 | 329 | /** This RTEMS taks is used to print messages without affecting the general behaviour of the software. |
|
328 | 330 | * |
|
329 | 331 | * @param unused is the starting argument of the RTEMS task |
|
330 | 332 | * |
|
331 | 333 | * The DUMB taks waits for RTEMS events and print messages depending on the incoming events. |
|
332 | 334 | * |
|
333 | 335 | */ |
|
334 | 336 | |
|
335 | 337 | unsigned int i; |
|
336 | 338 | unsigned int intEventOut; |
|
337 | 339 | unsigned int coarse_time = 0; |
|
338 | 340 | unsigned int fine_time = 0; |
|
339 | 341 | rtems_event_set event_out; |
|
340 | 342 | |
|
341 | 343 | char *DumbMessages[13] = {"in DUMB *** default", // RTEMS_EVENT_0 |
|
342 | 344 | "in DUMB *** timecode_irq_handler", // RTEMS_EVENT_1 |
|
343 | 345 | "in DUMB *** f3 buffer changed", // RTEMS_EVENT_2 |
|
344 | 346 | "in DUMB *** in SMIQ *** Error sending event to AVF0", // RTEMS_EVENT_3 |
|
345 | 347 | "in DUMB *** spectral_matrices_isr *** Error sending event to SMIQ", // RTEMS_EVENT_4 |
|
346 | 348 | "in DUMB *** waveforms_simulator_isr", // RTEMS_EVENT_5 |
|
347 | 349 | "VHDL SM *** two buffers f0 ready", // RTEMS_EVENT_6 |
|
348 | 350 | "ready for dump", // RTEMS_EVENT_7 |
|
349 | 351 | "VHDL ERR *** spectral matrix", // RTEMS_EVENT_8 |
|
350 | 352 | "tick", // RTEMS_EVENT_9 |
|
351 | 353 | "VHDL ERR *** waveform picker", // RTEMS_EVENT_10 |
|
352 | 354 | "VHDL ERR *** unexpected ready matrix values", // RTEMS_EVENT_11 |
|
353 | 355 | "WATCHDOG timer" // RTEMS_EVENT_12 |
|
354 | 356 | }; |
|
355 | 357 | |
|
356 | 358 | BOOT_PRINTF("in DUMB *** \n") |
|
357 | 359 | |
|
358 | 360 | while(1){ |
|
359 | 361 | rtems_event_receive(RTEMS_EVENT_0 | RTEMS_EVENT_1 | RTEMS_EVENT_2 | RTEMS_EVENT_3 |
|
360 | 362 | | RTEMS_EVENT_4 | RTEMS_EVENT_5 | RTEMS_EVENT_6 | RTEMS_EVENT_7 |
|
361 | 363 | | RTEMS_EVENT_8 | RTEMS_EVENT_9 | RTEMS_EVENT_12, |
|
362 | 364 | RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT |
|
363 | 365 | intEventOut = (unsigned int) event_out; |
|
364 | 366 | for ( i=0; i<32; i++) |
|
365 | 367 | { |
|
366 | 368 | if ( ((intEventOut >> i) & 0x0001) != 0) |
|
367 | 369 | { |
|
368 | 370 | coarse_time = time_management_regs->coarse_time; |
|
369 | 371 | fine_time = time_management_regs->fine_time; |
|
370 | 372 | if (i==12) |
|
371 | 373 | { |
|
372 | 374 | PRINTF1("%s\n", DumbMessages[12]) |
|
373 | 375 | } |
|
374 | 376 | } |
|
375 | 377 | } |
|
376 | 378 | } |
|
377 | 379 | } |
|
378 | 380 | |
|
379 | 381 | //***************************** |
|
380 | 382 | // init housekeeping parameters |
|
381 | 383 | |
|
382 | 384 | void init_housekeeping_parameters( void ) |
|
383 | 385 | { |
|
384 | 386 | /** This function initialize the housekeeping_packet global variable with default values. |
|
385 | 387 | * |
|
386 | 388 | */ |
|
387 | 389 | |
|
388 | 390 | unsigned int i = 0; |
|
389 | 391 | unsigned char *parameters; |
|
390 | 392 | unsigned char sizeOfHK; |
|
391 | 393 | |
|
392 | 394 | sizeOfHK = sizeof( Packet_TM_LFR_HK_t ); |
|
393 | 395 | |
|
394 | 396 | parameters = (unsigned char*) &housekeeping_packet; |
|
395 | 397 | |
|
396 | 398 | for(i = 0; i< sizeOfHK; i++) |
|
397 | 399 | { |
|
398 | 400 | parameters[i] = 0x00; |
|
399 | 401 | } |
|
400 | 402 | |
|
401 | 403 | housekeeping_packet.targetLogicalAddress = CCSDS_DESTINATION_ID; |
|
402 | 404 | housekeeping_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID; |
|
403 | 405 | housekeeping_packet.reserved = DEFAULT_RESERVED; |
|
404 | 406 | housekeeping_packet.userApplication = CCSDS_USER_APP; |
|
405 | 407 | housekeeping_packet.packetID[0] = (unsigned char) (APID_TM_HK >> 8); |
|
406 | 408 | housekeeping_packet.packetID[1] = (unsigned char) (APID_TM_HK); |
|
407 | 409 | housekeeping_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE; |
|
408 | 410 | housekeeping_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT; |
|
409 | 411 | housekeeping_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> 8); |
|
410 | 412 | housekeeping_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK ); |
|
411 | 413 | housekeeping_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; |
|
412 | 414 | housekeeping_packet.serviceType = TM_TYPE_HK; |
|
413 | 415 | housekeeping_packet.serviceSubType = TM_SUBTYPE_HK; |
|
414 | 416 | housekeeping_packet.destinationID = TM_DESTINATION_ID_GROUND; |
|
415 | 417 | housekeeping_packet.sid = SID_HK; |
|
416 | 418 | |
|
417 | 419 | // init status word |
|
418 | 420 | housekeeping_packet.lfr_status_word[0] = DEFAULT_STATUS_WORD_BYTE0; |
|
419 | 421 | housekeeping_packet.lfr_status_word[1] = DEFAULT_STATUS_WORD_BYTE1; |
|
420 | 422 | // init software version |
|
421 | 423 | housekeeping_packet.lfr_sw_version[0] = SW_VERSION_N1; |
|
422 | 424 | housekeeping_packet.lfr_sw_version[1] = SW_VERSION_N2; |
|
423 | 425 | housekeeping_packet.lfr_sw_version[2] = SW_VERSION_N3; |
|
424 | 426 | housekeeping_packet.lfr_sw_version[3] = SW_VERSION_N4; |
|
425 | 427 | // init fpga version |
|
426 | 428 | parameters = (unsigned char *) (REGS_ADDR_VHDL_VERSION); |
|
427 | 429 | housekeeping_packet.lfr_fpga_version[0] = parameters[1]; // n1 |
|
428 | 430 | housekeeping_packet.lfr_fpga_version[1] = parameters[2]; // n2 |
|
429 | 431 | housekeeping_packet.lfr_fpga_version[2] = parameters[3]; // n3 |
|
430 | 432 | |
|
431 | 433 | housekeeping_packet.hk_lfr_q_sd_fifo_size = MSG_QUEUE_COUNT_SEND; |
|
432 | 434 | housekeeping_packet.hk_lfr_q_rv_fifo_size = MSG_QUEUE_COUNT_RECV; |
|
433 | 435 | housekeeping_packet.hk_lfr_q_p0_fifo_size = MSG_QUEUE_COUNT_PRC0; |
|
434 | 436 | housekeeping_packet.hk_lfr_q_p1_fifo_size = MSG_QUEUE_COUNT_PRC1; |
|
435 | 437 | housekeeping_packet.hk_lfr_q_p2_fifo_size = MSG_QUEUE_COUNT_PRC2; |
|
436 | 438 | } |
|
437 | 439 | |
|
438 | 440 | void increment_seq_counter( unsigned short *packetSequenceControl ) |
|
439 | 441 | { |
|
440 | 442 | /** This function increment the sequence counter passes in argument. |
|
441 | 443 | * |
|
442 | 444 | * The increment does not affect the grouping flag. In case of an overflow, the counter is reset to 0. |
|
443 | 445 | * |
|
444 | 446 | */ |
|
445 | 447 | |
|
446 | 448 | unsigned short segmentation_grouping_flag; |
|
447 | 449 | unsigned short sequence_cnt; |
|
448 | 450 | |
|
449 | 451 | segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << 8; // keep bits 7 downto 6 |
|
450 | 452 | sequence_cnt = (*packetSequenceControl) & 0x3fff; // [0011 1111 1111 1111] |
|
451 | 453 | |
|
452 | 454 | if ( sequence_cnt < SEQ_CNT_MAX) |
|
453 | 455 | { |
|
454 | 456 | sequence_cnt = sequence_cnt + 1; |
|
455 | 457 | } |
|
456 | 458 | else |
|
457 | 459 | { |
|
458 | 460 | sequence_cnt = 0; |
|
459 | 461 | } |
|
460 | 462 | |
|
461 | 463 | *packetSequenceControl = segmentation_grouping_flag | sequence_cnt ; |
|
462 | 464 | } |
|
463 | 465 | |
|
464 | 466 | void getTime( unsigned char *time) |
|
465 | 467 | { |
|
466 | 468 | /** This function write the current local time in the time buffer passed in argument. |
|
467 | 469 | * |
|
468 | 470 | */ |
|
469 | 471 | |
|
470 | 472 | time[0] = (unsigned char) (time_management_regs->coarse_time>>24); |
|
471 | 473 | time[1] = (unsigned char) (time_management_regs->coarse_time>>16); |
|
472 | 474 | time[2] = (unsigned char) (time_management_regs->coarse_time>>8); |
|
473 | 475 | time[3] = (unsigned char) (time_management_regs->coarse_time); |
|
474 | 476 | time[4] = (unsigned char) (time_management_regs->fine_time>>8); |
|
475 | 477 | time[5] = (unsigned char) (time_management_regs->fine_time); |
|
476 | 478 | } |
|
477 | 479 | |
|
478 | 480 | unsigned long long int getTimeAsUnsignedLongLongInt( ) |
|
479 | 481 | { |
|
480 | 482 | /** This function write the current local time in the time buffer passed in argument. |
|
481 | 483 | * |
|
482 | 484 | */ |
|
483 | 485 | unsigned long long int time; |
|
484 | 486 | |
|
485 | 487 | time = ( (unsigned long long int) (time_management_regs->coarse_time & 0x7fffffff) << 16 ) |
|
486 | 488 | + time_management_regs->fine_time; |
|
487 | 489 | |
|
488 | 490 | return time; |
|
489 | 491 | } |
|
490 | 492 | |
|
491 | 493 | void send_dumb_hk( void ) |
|
492 | 494 | { |
|
493 | 495 | Packet_TM_LFR_HK_t dummy_hk_packet; |
|
494 | 496 | unsigned char *parameters; |
|
495 | 497 | unsigned int i; |
|
496 | 498 | rtems_id queue_id; |
|
497 | 499 | |
|
498 | 500 | dummy_hk_packet.targetLogicalAddress = CCSDS_DESTINATION_ID; |
|
499 | 501 | dummy_hk_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID; |
|
500 | 502 | dummy_hk_packet.reserved = DEFAULT_RESERVED; |
|
501 | 503 | dummy_hk_packet.userApplication = CCSDS_USER_APP; |
|
502 | 504 | dummy_hk_packet.packetID[0] = (unsigned char) (APID_TM_HK >> 8); |
|
503 | 505 | dummy_hk_packet.packetID[1] = (unsigned char) (APID_TM_HK); |
|
504 | 506 | dummy_hk_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE; |
|
505 | 507 | dummy_hk_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT; |
|
506 | 508 | dummy_hk_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> 8); |
|
507 | 509 | dummy_hk_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK ); |
|
508 | 510 | dummy_hk_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; |
|
509 | 511 | dummy_hk_packet.serviceType = TM_TYPE_HK; |
|
510 | 512 | dummy_hk_packet.serviceSubType = TM_SUBTYPE_HK; |
|
511 | 513 | dummy_hk_packet.destinationID = TM_DESTINATION_ID_GROUND; |
|
512 | 514 | dummy_hk_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24); |
|
513 | 515 | dummy_hk_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16); |
|
514 | 516 | dummy_hk_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8); |
|
515 | 517 | dummy_hk_packet.time[3] = (unsigned char) (time_management_regs->coarse_time); |
|
516 | 518 | dummy_hk_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8); |
|
517 | 519 | dummy_hk_packet.time[5] = (unsigned char) (time_management_regs->fine_time); |
|
518 | 520 | dummy_hk_packet.sid = SID_HK; |
|
519 | 521 | |
|
520 | 522 | // init status word |
|
521 | 523 | dummy_hk_packet.lfr_status_word[0] = 0xff; |
|
522 | 524 | dummy_hk_packet.lfr_status_word[1] = 0xff; |
|
523 | 525 | // init software version |
|
524 | 526 | dummy_hk_packet.lfr_sw_version[0] = SW_VERSION_N1; |
|
525 | 527 | dummy_hk_packet.lfr_sw_version[1] = SW_VERSION_N2; |
|
526 | 528 | dummy_hk_packet.lfr_sw_version[2] = SW_VERSION_N3; |
|
527 | 529 | dummy_hk_packet.lfr_sw_version[3] = SW_VERSION_N4; |
|
528 | 530 | // init fpga version |
|
529 | 531 | parameters = (unsigned char *) (REGS_ADDR_WAVEFORM_PICKER + 0xb0); |
|
530 | 532 | dummy_hk_packet.lfr_fpga_version[0] = parameters[1]; // n1 |
|
531 | 533 | dummy_hk_packet.lfr_fpga_version[1] = parameters[2]; // n2 |
|
532 | 534 | dummy_hk_packet.lfr_fpga_version[2] = parameters[3]; // n3 |
|
533 | 535 | |
|
534 | 536 | parameters = (unsigned char *) &dummy_hk_packet.hk_lfr_cpu_load; |
|
535 | 537 | |
|
536 | 538 | for (i=0; i<100; i++) |
|
537 | 539 | { |
|
538 | 540 | parameters[i] = 0xff; |
|
539 | 541 | } |
|
540 | 542 | |
|
541 | 543 | get_message_queue_id_send( &queue_id ); |
|
542 | 544 | |
|
543 | 545 | rtems_message_queue_send( queue_id, &dummy_hk_packet, |
|
544 | 546 | PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES); |
|
545 | 547 | } |
|
546 | 548 | |
|
547 | 549 | void get_temperatures( unsigned char *temperatures ) |
|
548 | 550 | { |
|
549 | 551 | unsigned char* temp_scm_ptr; |
|
550 | 552 | unsigned char* temp_pcb_ptr; |
|
551 | 553 | unsigned char* temp_fpga_ptr; |
|
552 | 554 | |
|
553 | 555 | // SEL1 SEL0 |
|
554 | 556 | // 0 0 => PCB |
|
555 | 557 | // 0 1 => FPGA |
|
556 | 558 | // 1 0 => SCM |
|
557 | 559 | |
|
558 | 560 | temp_scm_ptr = (unsigned char *) &time_management_regs->temp_scm; |
|
559 | 561 | temp_pcb_ptr = (unsigned char *) &time_management_regs->temp_pcb; |
|
560 | 562 | temp_fpga_ptr = (unsigned char *) &time_management_regs->temp_fpga; |
|
561 | 563 | |
|
562 | 564 | temperatures[0] = temp_scm_ptr[2]; |
|
563 | 565 | temperatures[1] = temp_scm_ptr[3]; |
|
564 | 566 | temperatures[2] = temp_pcb_ptr[2]; |
|
565 | 567 | temperatures[3] = temp_pcb_ptr[3]; |
|
566 | 568 | temperatures[4] = temp_fpga_ptr[2]; |
|
567 | 569 | temperatures[5] = temp_fpga_ptr[3]; |
|
568 | 570 | } |
|
569 | 571 | |
|
570 | 572 | void get_v_e1_e2_f3( unsigned char *spacecraft_potential ) |
|
571 | 573 | { |
|
572 | 574 | unsigned char* v_ptr; |
|
573 | 575 | unsigned char* e1_ptr; |
|
574 | 576 | unsigned char* e2_ptr; |
|
575 | 577 | |
|
576 | 578 | v_ptr = (unsigned char *) &waveform_picker_regs->v; |
|
577 | 579 | e1_ptr = (unsigned char *) &waveform_picker_regs->e1; |
|
578 | 580 | e2_ptr = (unsigned char *) &waveform_picker_regs->e2; |
|
579 | 581 | |
|
580 | 582 | spacecraft_potential[0] = v_ptr[2]; |
|
581 | 583 | spacecraft_potential[1] = v_ptr[3]; |
|
582 | 584 | spacecraft_potential[2] = e1_ptr[2]; |
|
583 | 585 | spacecraft_potential[3] = e1_ptr[3]; |
|
584 | 586 | spacecraft_potential[4] = e2_ptr[2]; |
|
585 | 587 | spacecraft_potential[5] = e2_ptr[3]; |
|
586 | 588 | } |
|
587 | 589 | |
|
588 | 590 | void get_cpu_load( unsigned char *resource_statistics ) |
|
589 | 591 | { |
|
590 | 592 | unsigned char cpu_load; |
|
591 | 593 | |
|
592 | 594 | cpu_load = lfr_rtems_cpu_usage_report(); |
|
593 | 595 | |
|
594 | 596 | // HK_LFR_CPU_LOAD |
|
595 | 597 | resource_statistics[0] = cpu_load; |
|
596 | 598 | |
|
597 | 599 | // HK_LFR_CPU_LOAD_MAX |
|
598 | 600 | if (cpu_load > resource_statistics[1]) |
|
599 | 601 | { |
|
600 | 602 | resource_statistics[1] = cpu_load; |
|
601 | 603 | } |
|
602 | 604 | |
|
603 | 605 | // CPU_LOAD_AVE |
|
604 | 606 | resource_statistics[2] = 0; |
|
605 | 607 | |
|
606 | 608 | #ifndef PRINT_TASK_STATISTICS |
|
607 | 609 | rtems_cpu_usage_reset(); |
|
608 | 610 | #endif |
|
609 | 611 | |
|
610 | 612 | } |
|
611 | 613 | |
|
612 | 614 | void set_hk_lfr_sc_potential_flag( bool state ) |
|
613 | 615 | { |
|
614 | 616 | if (state == true) |
|
615 | 617 | { |
|
616 | 618 | housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] | 0x40; // [0100 0000] |
|
617 | 619 | } |
|
618 | 620 | else |
|
619 | 621 | { |
|
620 | 622 | housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] & 0xbf; // [1011 1111] |
|
621 | 623 | } |
|
622 | 624 | } |
|
623 | 625 | |
|
624 | 626 | void set_hk_lfr_mag_fields_flag( bool state ) |
|
625 | 627 | { |
|
626 | 628 | if (state == true) |
|
627 | 629 | { |
|
628 | 630 | housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] | 0x20; // [0010 0000] |
|
629 | 631 | } |
|
630 | 632 | else |
|
631 | 633 | { |
|
632 | 634 | housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] & 0xd7; // [1101 1111] |
|
633 | 635 | } |
|
634 | 636 | } |
|
635 | 637 | |
|
636 | 638 | void set_hk_lfr_calib_enable( bool state ) |
|
637 | 639 | { |
|
638 | 640 | if (state == true) |
|
639 | 641 | { |
|
640 | 642 | housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] | 0x08; // [0000 1000] |
|
641 | 643 | } |
|
642 | 644 | else |
|
643 | 645 | { |
|
644 | 646 | housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] & 0xf7; // [1111 0111] |
|
645 | 647 | } |
|
646 | 648 | } |
|
647 | 649 | |
|
648 | 650 | void set_hk_lfr_reset_cause( enum lfr_reset_cause_t lfr_reset_cause ) |
|
649 | 651 | { |
|
650 | 652 | housekeeping_packet.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1] |
|
651 | 653 | | (lfr_reset_cause & 0x07 ); // [0000 0111] |
|
652 | 654 | } |
|
655 | ||
|
656 | void hk_lfr_le_me_he_update() | |
|
657 | { | |
|
658 | unsigned int hk_lfr_le_cnt; | |
|
659 | unsigned int hk_lfr_me_cnt; | |
|
660 | unsigned int hk_lfr_he_cnt; | |
|
661 | ||
|
662 | hk_lfr_le_cnt = 0; | |
|
663 | hk_lfr_me_cnt = 0; | |
|
664 | hk_lfr_he_cnt = 0; | |
|
665 | ||
|
666 | //update the low severity error counter | |
|
667 | hk_lfr_le_cnt = | |
|
668 | housekeeping_packet.hk_lfr_dpu_spw_parity | |
|
669 | + housekeeping_packet.hk_lfr_dpu_spw_disconnect | |
|
670 | + housekeeping_packet.hk_lfr_dpu_spw_escape | |
|
671 | + housekeeping_packet.hk_lfr_dpu_spw_credit | |
|
672 | + housekeeping_packet.hk_lfr_dpu_spw_write_sync | |
|
673 | + housekeeping_packet.hk_lfr_dpu_spw_rx_ahb | |
|
674 | + housekeeping_packet.hk_lfr_dpu_spw_tx_ahb | |
|
675 | + housekeeping_packet.hk_lfr_time_timecode_ctr; | |
|
676 | ||
|
677 | //update the medium severity error counter | |
|
678 | hk_lfr_me_cnt = | |
|
679 | housekeeping_packet.hk_lfr_dpu_spw_early_eop | |
|
680 | + housekeeping_packet.hk_lfr_dpu_spw_invalid_addr | |
|
681 | + housekeeping_packet.hk_lfr_dpu_spw_eep | |
|
682 | + housekeeping_packet.hk_lfr_dpu_spw_rx_too_big; | |
|
683 | ||
|
684 | //update the high severity error counter | |
|
685 | hk_lfr_he_cnt = 0; | |
|
686 | ||
|
687 | // update housekeeping packet counters, convert unsigned int numbers in 2 bytes numbers | |
|
688 | // LE | |
|
689 | housekeeping_packet.hk_lfr_le_cnt[0] = (unsigned char) ((hk_lfr_le_cnt & 0xff00) >> 8); | |
|
690 | housekeeping_packet.hk_lfr_le_cnt[1] = (unsigned char) (hk_lfr_le_cnt & 0x00ff); | |
|
691 | // ME | |
|
692 | housekeeping_packet.hk_lfr_me_cnt[0] = (unsigned char) ((hk_lfr_me_cnt & 0xff00) >> 8); | |
|
693 | housekeeping_packet.hk_lfr_me_cnt[1] = (unsigned char) (hk_lfr_me_cnt & 0x00ff); | |
|
694 | // HE | |
|
695 | housekeeping_packet.hk_lfr_he_cnt[0] = (unsigned char) ((hk_lfr_he_cnt & 0xff00) >> 8); | |
|
696 | housekeeping_packet.hk_lfr_he_cnt[1] = (unsigned char) (hk_lfr_he_cnt & 0x00ff); | |
|
697 | ||
|
698 | } |
@@ -1,1308 +1,1295 | |||
|
1 | 1 | /** Functions related to the SpaceWire interface. |
|
2 | 2 | * |
|
3 | 3 | * @file |
|
4 | 4 | * @author P. LEROY |
|
5 | 5 | * |
|
6 | 6 | * A group of functions to handle SpaceWire transmissions: |
|
7 | 7 | * - configuration of the SpaceWire link |
|
8 | 8 | * - SpaceWire related interruption requests processing |
|
9 | 9 | * - transmission of TeleMetry packets by a dedicated RTEMS task |
|
10 | 10 | * - reception of TeleCommands by a dedicated RTEMS task |
|
11 | 11 | * |
|
12 | 12 | */ |
|
13 | 13 | |
|
14 | 14 | #include "fsw_spacewire.h" |
|
15 | 15 | |
|
16 | 16 | rtems_name semq_name; |
|
17 | 17 | rtems_id semq_id; |
|
18 | 18 | |
|
19 | 19 | //***************** |
|
20 | 20 | // waveform headers |
|
21 | 21 | Header_TM_LFR_SCIENCE_CWF_t headerCWF; |
|
22 | 22 | Header_TM_LFR_SCIENCE_SWF_t headerSWF; |
|
23 | 23 | Header_TM_LFR_SCIENCE_ASM_t headerASM; |
|
24 | 24 | |
|
25 | 25 | //*********** |
|
26 | 26 | // RTEMS TASK |
|
27 | 27 | rtems_task spiq_task(rtems_task_argument unused) |
|
28 | 28 | { |
|
29 | 29 | /** This RTEMS task is awaken by an rtems_event sent by the interruption subroutine of the SpaceWire driver. |
|
30 | 30 | * |
|
31 | 31 | * @param unused is the starting argument of the RTEMS task |
|
32 | 32 | * |
|
33 | 33 | */ |
|
34 | 34 | |
|
35 | 35 | rtems_event_set event_out; |
|
36 | 36 | rtems_status_code status; |
|
37 | 37 | int linkStatus; |
|
38 | 38 | |
|
39 | 39 | BOOT_PRINTF("in SPIQ *** \n") |
|
40 | 40 | |
|
41 | 41 | while(true){ |
|
42 | 42 | rtems_event_receive(SPW_LINKERR_EVENT, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an SPW_LINKERR_EVENT |
|
43 | 43 | PRINTF("in SPIQ *** got SPW_LINKERR_EVENT\n") |
|
44 | 44 | |
|
45 | 45 | // [0] SUSPEND RECV AND SEND TASKS |
|
46 | 46 | status = rtems_task_suspend( Task_id[ TASKID_RECV ] ); |
|
47 | 47 | if ( status != RTEMS_SUCCESSFUL ) { |
|
48 | 48 | PRINTF("in SPIQ *** ERR suspending RECV Task\n") |
|
49 | 49 | } |
|
50 | 50 | status = rtems_task_suspend( Task_id[ TASKID_SEND ] ); |
|
51 | 51 | if ( status != RTEMS_SUCCESSFUL ) { |
|
52 | 52 | PRINTF("in SPIQ *** ERR suspending SEND Task\n") |
|
53 | 53 | } |
|
54 | 54 | |
|
55 | 55 | // [1] CHECK THE LINK |
|
56 | 56 | status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (1) |
|
57 | 57 | if ( linkStatus != 5) { |
|
58 | 58 | PRINTF1("in SPIQ *** linkStatus %d, wait...\n", linkStatus) |
|
59 | 59 | status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms |
|
60 | 60 | } |
|
61 | 61 | |
|
62 | 62 | // [2] RECHECK THE LINK AFTER SY_LFR_DPU_CONNECT_TIMEOUT |
|
63 | 63 | status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (2) |
|
64 | 64 | if ( linkStatus != 5 ) // [2.a] not in run state, reset the link |
|
65 | 65 | { |
|
66 | 66 | spacewire_compute_stats_offsets(); |
|
67 | 67 | status = spacewire_reset_link( ); |
|
68 | 68 | } |
|
69 | 69 | else // [2.b] in run state, start the link |
|
70 | 70 | { |
|
71 | 71 | status = spacewire_stop_and_start_link( fdSPW ); // start the link |
|
72 | 72 | if ( status != RTEMS_SUCCESSFUL) |
|
73 | 73 | { |
|
74 | 74 | PRINTF1("in SPIQ *** ERR spacewire_stop_and_start_link %d\n", status) |
|
75 | 75 | } |
|
76 | 76 | } |
|
77 | 77 | |
|
78 | 78 | // [3] COMPLETE RECOVERY ACTION AFTER SY_LFR_DPU_CONNECT_ATTEMPTS |
|
79 | 79 | if ( status == RTEMS_SUCCESSFUL ) // [3.a] the link is in run state and has been started successfully |
|
80 | 80 | { |
|
81 | 81 | status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 ); |
|
82 | 82 | if ( status != RTEMS_SUCCESSFUL ) { |
|
83 | 83 | PRINTF("in SPIQ *** ERR resuming SEND Task\n") |
|
84 | 84 | } |
|
85 | 85 | status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 ); |
|
86 | 86 | if ( status != RTEMS_SUCCESSFUL ) { |
|
87 | 87 | PRINTF("in SPIQ *** ERR resuming RECV Task\n") |
|
88 | 88 | } |
|
89 | 89 | } |
|
90 | 90 | else // [3.b] the link is not in run state, go in STANDBY mode |
|
91 | 91 | { |
|
92 | 92 | status = enter_mode_standby(); |
|
93 | 93 | if ( status != RTEMS_SUCCESSFUL ) { |
|
94 | 94 | PRINTF1("in SPIQ *** ERR enter_standby_mode *** code %d\n", status) |
|
95 | 95 | } |
|
96 | 96 | // wake the WTDG task up to wait for the link recovery |
|
97 | 97 | status = rtems_event_send ( Task_id[TASKID_WTDG], RTEMS_EVENT_0 ); |
|
98 | 98 | status = rtems_task_suspend( RTEMS_SELF ); |
|
99 | 99 | } |
|
100 | 100 | } |
|
101 | 101 | } |
|
102 | 102 | |
|
103 | 103 | rtems_task recv_task( rtems_task_argument unused ) |
|
104 | 104 | { |
|
105 | 105 | /** This RTEMS task is dedicated to the reception of incoming TeleCommands. |
|
106 | 106 | * |
|
107 | 107 | * @param unused is the starting argument of the RTEMS task |
|
108 | 108 | * |
|
109 | 109 | * The RECV task blocks on a call to the read system call, waiting for incoming SpaceWire data. When unblocked: |
|
110 | 110 | * 1. It reads the incoming data. |
|
111 | 111 | * 2. Launches the acceptance procedure. |
|
112 | 112 | * 3. If the Telecommand is valid, sends it to a dedicated RTEMS message queue. |
|
113 | 113 | * |
|
114 | 114 | */ |
|
115 | 115 | |
|
116 | 116 | int len; |
|
117 | 117 | ccsdsTelecommandPacket_t currentTC; |
|
118 | 118 | unsigned char computed_CRC[ 2 ]; |
|
119 | 119 | unsigned char currentTC_LEN_RCV[ 2 ]; |
|
120 | 120 | unsigned char destinationID; |
|
121 | 121 | unsigned int estimatedPacketLength; |
|
122 | 122 | unsigned int parserCode; |
|
123 | 123 | rtems_status_code status; |
|
124 | 124 | rtems_id queue_recv_id; |
|
125 | 125 | rtems_id queue_send_id; |
|
126 | 126 | |
|
127 | 127 | initLookUpTableForCRC(); // the table is used to compute Cyclic Redundancy Codes |
|
128 | 128 | |
|
129 | 129 | status = get_message_queue_id_recv( &queue_recv_id ); |
|
130 | 130 | if (status != RTEMS_SUCCESSFUL) |
|
131 | 131 | { |
|
132 | 132 | PRINTF1("in RECV *** ERR get_message_queue_id_recv %d\n", status) |
|
133 | 133 | } |
|
134 | 134 | |
|
135 | 135 | status = get_message_queue_id_send( &queue_send_id ); |
|
136 | 136 | if (status != RTEMS_SUCCESSFUL) |
|
137 | 137 | { |
|
138 | 138 | PRINTF1("in RECV *** ERR get_message_queue_id_send %d\n", status) |
|
139 | 139 | } |
|
140 | 140 | |
|
141 | 141 | BOOT_PRINTF("in RECV *** \n") |
|
142 | 142 | |
|
143 | 143 | while(1) |
|
144 | 144 | { |
|
145 | 145 | len = read( fdSPW, (char*) ¤tTC, CCSDS_TC_PKT_MAX_SIZE ); // the call to read is blocking |
|
146 | 146 | if (len == -1){ // error during the read call |
|
147 | 147 | PRINTF1("in RECV *** last read call returned -1, ERRNO %d\n", errno) |
|
148 | 148 | } |
|
149 | 149 | else { |
|
150 | 150 | if ( (len+1) < CCSDS_TC_PKT_MIN_SIZE ) { |
|
151 | 151 | PRINTF("in RECV *** packet lenght too short\n") |
|
152 | 152 | } |
|
153 | 153 | else { |
|
154 | 154 | estimatedPacketLength = (unsigned int) (len - CCSDS_TC_TM_PACKET_OFFSET - 3); // => -3 is for Prot ID, Reserved and User App bytes |
|
155 | 155 | currentTC_LEN_RCV[ 0 ] = (unsigned char) (estimatedPacketLength >> 8); |
|
156 | 156 | currentTC_LEN_RCV[ 1 ] = (unsigned char) (estimatedPacketLength ); |
|
157 | 157 | // CHECK THE TC |
|
158 | 158 | parserCode = tc_parser( ¤tTC, estimatedPacketLength, computed_CRC ) ; |
|
159 | 159 | if ( (parserCode == ILLEGAL_APID) || (parserCode == WRONG_LEN_PKT) |
|
160 | 160 | || (parserCode == INCOR_CHECKSUM) || (parserCode == ILL_TYPE) |
|
161 | 161 | || (parserCode == ILL_SUBTYPE) || (parserCode == WRONG_APP_DATA) |
|
162 | 162 | || (parserCode == WRONG_SRC_ID) ) |
|
163 | 163 | { // send TM_LFR_TC_EXE_CORRUPTED |
|
164 | 164 | PRINTF1("TC corrupted received, with code: %d\n", parserCode) |
|
165 | 165 | if ( !( (currentTC.serviceType==TC_TYPE_TIME) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_TIME) ) |
|
166 | 166 | && |
|
167 | 167 | !( (currentTC.serviceType==TC_TYPE_GEN) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_INFO)) |
|
168 | 168 | ) |
|
169 | 169 | { |
|
170 | 170 | if ( parserCode == WRONG_SRC_ID ) |
|
171 | 171 | { |
|
172 | 172 | destinationID = SID_TC_GROUND; |
|
173 | 173 | } |
|
174 | 174 | else |
|
175 | 175 | { |
|
176 | 176 | destinationID = currentTC.sourceID; |
|
177 | 177 | } |
|
178 | 178 | send_tm_lfr_tc_exe_corrupted( ¤tTC, queue_send_id, |
|
179 | 179 | computed_CRC, currentTC_LEN_RCV, |
|
180 | 180 | destinationID ); |
|
181 | 181 | } |
|
182 | 182 | } |
|
183 | 183 | else |
|
184 | 184 | { // send valid TC to the action launcher |
|
185 | 185 | status = rtems_message_queue_send( queue_recv_id, ¤tTC, |
|
186 | 186 | estimatedPacketLength + CCSDS_TC_TM_PACKET_OFFSET + 3); |
|
187 | 187 | } |
|
188 | 188 | } |
|
189 | 189 | } |
|
190 | 190 | |
|
191 | 191 | update_queue_max_count( queue_recv_id, &hk_lfr_q_rv_fifo_size_max ); |
|
192 | 192 | |
|
193 | 193 | } |
|
194 | 194 | } |
|
195 | 195 | |
|
196 | 196 | rtems_task send_task( rtems_task_argument argument) |
|
197 | 197 | { |
|
198 | 198 | /** This RTEMS task is dedicated to the transmission of TeleMetry packets. |
|
199 | 199 | * |
|
200 | 200 | * @param unused is the starting argument of the RTEMS task |
|
201 | 201 | * |
|
202 | 202 | * The SEND task waits for a message to become available in the dedicated RTEMS queue. When a message arrives: |
|
203 | 203 | * - if the first byte is equal to CCSDS_DESTINATION_ID, the message is sent as is using the write system call. |
|
204 | 204 | * - if the first byte is not equal to CCSDS_DESTINATION_ID, the message is handled as a spw_ioctl_pkt_send. After |
|
205 | 205 | * analyzis, the packet is sent either using the write system call or using the ioctl call SPACEWIRE_IOCTRL_SEND, depending on the |
|
206 | 206 | * data it contains. |
|
207 | 207 | * |
|
208 | 208 | */ |
|
209 | 209 | |
|
210 | 210 | rtems_status_code status; // RTEMS status code |
|
211 | 211 | char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer |
|
212 | 212 | ring_node *incomingRingNodePtr; |
|
213 | 213 | int ring_node_address; |
|
214 | 214 | char *charPtr; |
|
215 | 215 | spw_ioctl_pkt_send *spw_ioctl_send; |
|
216 | 216 | size_t size; // size of the incoming TC packet |
|
217 | 217 | rtems_id queue_send_id; |
|
218 | 218 | unsigned int sid; |
|
219 | 219 | unsigned char sidAsUnsignedChar; |
|
220 | 220 | unsigned char type; |
|
221 | 221 | |
|
222 | 222 | incomingRingNodePtr = NULL; |
|
223 | 223 | ring_node_address = 0; |
|
224 | 224 | charPtr = (char *) &ring_node_address; |
|
225 | 225 | sid = 0; |
|
226 | 226 | sidAsUnsignedChar = 0; |
|
227 | 227 | |
|
228 | 228 | init_header_cwf( &headerCWF ); |
|
229 | 229 | init_header_swf( &headerSWF ); |
|
230 | 230 | init_header_asm( &headerASM ); |
|
231 | 231 | |
|
232 | 232 | status = get_message_queue_id_send( &queue_send_id ); |
|
233 | 233 | if (status != RTEMS_SUCCESSFUL) |
|
234 | 234 | { |
|
235 | 235 | PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status) |
|
236 | 236 | } |
|
237 | 237 | |
|
238 | 238 | BOOT_PRINTF("in SEND *** \n") |
|
239 | 239 | |
|
240 | 240 | while(1) |
|
241 | 241 | { |
|
242 | 242 | status = rtems_message_queue_receive( queue_send_id, incomingData, &size, |
|
243 | 243 | RTEMS_WAIT, RTEMS_NO_TIMEOUT ); |
|
244 | 244 | |
|
245 | 245 | if (status!=RTEMS_SUCCESSFUL) |
|
246 | 246 | { |
|
247 | 247 | PRINTF1("in SEND *** (1) ERR = %d\n", status) |
|
248 | 248 | } |
|
249 | 249 | else |
|
250 | 250 | { |
|
251 | 251 | if ( size == sizeof(ring_node*) ) |
|
252 | 252 | { |
|
253 | 253 | charPtr[0] = incomingData[0]; |
|
254 | 254 | charPtr[1] = incomingData[1]; |
|
255 | 255 | charPtr[2] = incomingData[2]; |
|
256 | 256 | charPtr[3] = incomingData[3]; |
|
257 | 257 | incomingRingNodePtr = (ring_node*) ring_node_address; |
|
258 | 258 | sid = incomingRingNodePtr->sid; |
|
259 | 259 | if ( (sid==SID_NORM_CWF_LONG_F3) |
|
260 | 260 | || (sid==SID_BURST_CWF_F2 ) |
|
261 | 261 | || (sid==SID_SBM1_CWF_F1 ) |
|
262 | 262 | || (sid==SID_SBM2_CWF_F2 )) |
|
263 | 263 | { |
|
264 | 264 | spw_send_waveform_CWF( incomingRingNodePtr, &headerCWF ); |
|
265 | 265 | } |
|
266 | 266 | else if ( (sid==SID_NORM_SWF_F0) || (sid== SID_NORM_SWF_F1) || (sid==SID_NORM_SWF_F2) ) |
|
267 | 267 | { |
|
268 | 268 | spw_send_waveform_SWF( incomingRingNodePtr, &headerSWF ); |
|
269 | 269 | } |
|
270 | 270 | else if ( (sid==SID_NORM_CWF_F3) ) |
|
271 | 271 | { |
|
272 | 272 | spw_send_waveform_CWF3_light( incomingRingNodePtr, &headerCWF ); |
|
273 | 273 | } |
|
274 | 274 | else if (sid==SID_NORM_ASM_F0) |
|
275 | 275 | { |
|
276 | 276 | spw_send_asm_f0( incomingRingNodePtr, &headerASM ); |
|
277 | 277 | } |
|
278 | 278 | else if (sid==SID_NORM_ASM_F1) |
|
279 | 279 | { |
|
280 | 280 | spw_send_asm_f1( incomingRingNodePtr, &headerASM ); |
|
281 | 281 | } |
|
282 | 282 | else if (sid==SID_NORM_ASM_F2) |
|
283 | 283 | { |
|
284 | 284 | spw_send_asm_f2( incomingRingNodePtr, &headerASM ); |
|
285 | 285 | } |
|
286 | 286 | else if ( sid==TM_CODE_K_DUMP ) |
|
287 | 287 | { |
|
288 | 288 | spw_send_k_dump( incomingRingNodePtr ); |
|
289 | 289 | } |
|
290 | 290 | else |
|
291 | 291 | { |
|
292 | 292 | PRINTF1("unexpected sid = %d\n", sid); |
|
293 | 293 | } |
|
294 | 294 | } |
|
295 | 295 | else if ( incomingData[0] == CCSDS_DESTINATION_ID ) // the incoming message is a ccsds packet |
|
296 | 296 | { |
|
297 | 297 | sidAsUnsignedChar = (unsigned char) incomingData[ PACKET_POS_PA_LFR_SID_PKT ]; |
|
298 | 298 | sid = sidAsUnsignedChar; |
|
299 | 299 | type = (unsigned char) incomingData[ PACKET_POS_SERVICE_TYPE ]; |
|
300 | 300 | if (type == TM_TYPE_LFR_SCIENCE) // this is a BP packet, all other types are handled differently |
|
301 | 301 | // SET THE SEQUENCE_CNT PARAMETER IN CASE OF BP0 OR BP1 PACKETS |
|
302 | 302 | { |
|
303 | 303 | increment_seq_counter_source_id( (unsigned char*) &incomingData[ PACKET_POS_SEQUENCE_CNT ], sid ); |
|
304 | 304 | } |
|
305 | 305 | |
|
306 | 306 | status = write( fdSPW, incomingData, size ); |
|
307 | 307 | if (status == -1){ |
|
308 | 308 | PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size) |
|
309 | 309 | } |
|
310 | 310 | } |
|
311 | 311 | else // the incoming message is a spw_ioctl_pkt_send structure |
|
312 | 312 | { |
|
313 | 313 | spw_ioctl_send = (spw_ioctl_pkt_send*) incomingData; |
|
314 | 314 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, spw_ioctl_send ); |
|
315 | 315 | if (status == -1){ |
|
316 | 316 | PRINTF2("in SEND *** (2.b) ERRNO = %d, RTEMS = %d\n", errno, status) |
|
317 | 317 | } |
|
318 | 318 | } |
|
319 | 319 | } |
|
320 | 320 | |
|
321 | 321 | update_queue_max_count( queue_send_id, &hk_lfr_q_sd_fifo_size_max ); |
|
322 | 322 | |
|
323 | 323 | } |
|
324 | 324 | } |
|
325 | 325 | |
|
326 | 326 | rtems_task wtdg_task( rtems_task_argument argument ) |
|
327 | 327 | { |
|
328 | 328 | rtems_event_set event_out; |
|
329 | 329 | rtems_status_code status; |
|
330 | 330 | int linkStatus; |
|
331 | 331 | |
|
332 | 332 | BOOT_PRINTF("in WTDG ***\n") |
|
333 | 333 | |
|
334 | 334 | while(1) |
|
335 | 335 | { |
|
336 | 336 | // wait for an RTEMS_EVENT |
|
337 | 337 | rtems_event_receive( RTEMS_EVENT_0, |
|
338 | 338 | RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); |
|
339 | 339 | PRINTF("in WTDG *** wait for the link\n") |
|
340 | 340 | status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status |
|
341 | 341 | while( linkStatus != 5) // wait for the link |
|
342 | 342 | { |
|
343 | 343 | status = rtems_task_wake_after( 10 ); // monitor the link each 100ms |
|
344 | 344 | status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status |
|
345 | 345 | } |
|
346 | 346 | |
|
347 | 347 | status = spacewire_stop_and_start_link( fdSPW ); |
|
348 | 348 | |
|
349 | 349 | if (status != RTEMS_SUCCESSFUL) |
|
350 | 350 | { |
|
351 | 351 | PRINTF1("in WTDG *** ERR link not started %d\n", status) |
|
352 | 352 | } |
|
353 | 353 | else |
|
354 | 354 | { |
|
355 | 355 | PRINTF("in WTDG *** OK link started\n") |
|
356 | 356 | } |
|
357 | 357 | |
|
358 | 358 | // restart the SPIQ task |
|
359 | 359 | status = rtems_task_restart( Task_id[TASKID_SPIQ], 1 ); |
|
360 | 360 | if ( status != RTEMS_SUCCESSFUL ) { |
|
361 | 361 | PRINTF("in SPIQ *** ERR restarting SPIQ Task\n") |
|
362 | 362 | } |
|
363 | 363 | |
|
364 | 364 | // restart RECV and SEND |
|
365 | 365 | status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 ); |
|
366 | 366 | if ( status != RTEMS_SUCCESSFUL ) { |
|
367 | 367 | PRINTF("in SPIQ *** ERR restarting SEND Task\n") |
|
368 | 368 | } |
|
369 | 369 | status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 ); |
|
370 | 370 | if ( status != RTEMS_SUCCESSFUL ) { |
|
371 | 371 | PRINTF("in SPIQ *** ERR restarting RECV Task\n") |
|
372 | 372 | } |
|
373 | 373 | } |
|
374 | 374 | } |
|
375 | 375 | |
|
376 | 376 | //**************** |
|
377 | 377 | // OTHER FUNCTIONS |
|
378 | 378 | int spacewire_open_link( void ) // by default, the driver resets the core: [SPW_CTRL_WRITE(pDev, SPW_CTRL_RESET);] |
|
379 | 379 | { |
|
380 | 380 | /** This function opens the SpaceWire link. |
|
381 | 381 | * |
|
382 | 382 | * @return a valid file descriptor in case of success, -1 in case of a failure |
|
383 | 383 | * |
|
384 | 384 | */ |
|
385 | 385 | rtems_status_code status; |
|
386 | 386 | |
|
387 | 387 | fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call resets the hardware |
|
388 | 388 | if ( fdSPW < 0 ) { |
|
389 | 389 | PRINTF1("ERR *** in configure_spw_link *** error opening "GRSPW_DEVICE_NAME" with ERR %d\n", errno) |
|
390 | 390 | } |
|
391 | 391 | else |
|
392 | 392 | { |
|
393 | 393 | status = RTEMS_SUCCESSFUL; |
|
394 | 394 | } |
|
395 | 395 | |
|
396 | 396 | return status; |
|
397 | 397 | } |
|
398 | 398 | |
|
399 | 399 | int spacewire_start_link( int fd ) |
|
400 | 400 | { |
|
401 | 401 | rtems_status_code status; |
|
402 | 402 | |
|
403 | 403 | status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started |
|
404 | 404 | // -1 default hardcoded driver timeout |
|
405 | 405 | |
|
406 | 406 | return status; |
|
407 | 407 | } |
|
408 | 408 | |
|
409 | 409 | int spacewire_stop_and_start_link( int fd ) |
|
410 | 410 | { |
|
411 | 411 | rtems_status_code status; |
|
412 | 412 | |
|
413 | 413 | status = ioctl( fd, SPACEWIRE_IOCTRL_STOP); // start fails if link pDev->running != 0 |
|
414 | 414 | status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started |
|
415 | 415 | // -1 default hardcoded driver timeout |
|
416 | 416 | |
|
417 | 417 | return status; |
|
418 | 418 | } |
|
419 | 419 | |
|
420 | 420 | int spacewire_configure_link( int fd ) |
|
421 | 421 | { |
|
422 | 422 | /** This function configures the SpaceWire link. |
|
423 | 423 | * |
|
424 | 424 | * @return GR-RTEMS-DRIVER directive status codes: |
|
425 | 425 | * - 22 EINVAL - Null pointer or an out of range value was given as the argument. |
|
426 | 426 | * - 16 EBUSY - Only used for SEND. Returned when no descriptors are avialble in non-blocking mode. |
|
427 | 427 | * - 88 ENOSYS - Returned for SET_DESTKEY if RMAP command handler is not available or if a non-implemented call is used. |
|
428 | 428 | * - 116 ETIMEDOUT - REturned for SET_PACKET_SIZE and START if the link could not be brought up. |
|
429 | 429 | * - 12 ENOMEM - Returned for SET_PACKETSIZE if it was unable to allocate the new buffers. |
|
430 | 430 | * - 5 EIO - Error when writing to grswp hardware registers. |
|
431 | 431 | * - 2 ENOENT - No such file or directory |
|
432 | 432 | */ |
|
433 | 433 | |
|
434 | 434 | rtems_status_code status; |
|
435 | 435 | |
|
436 | 436 | spacewire_set_NP(1, REGS_ADDR_GRSPW); // [N]o [P]ort force |
|
437 | 437 | spacewire_set_RE(1, REGS_ADDR_GRSPW); // [R]MAP [E]nable, the dedicated call seems to break the no port force configuration |
|
438 | 438 | |
|
439 | 439 | status = ioctl(fd, SPACEWIRE_IOCTRL_SET_RXBLOCK, 1); // sets the blocking mode for reception |
|
440 | 440 | if (status!=RTEMS_SUCCESSFUL) { |
|
441 | 441 | PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_RXBLOCK\n") |
|
442 | 442 | } |
|
443 | 443 | // |
|
444 | 444 | status = ioctl(fd, SPACEWIRE_IOCTRL_SET_EVENT_ID, Task_id[TASKID_SPIQ]); // sets the task ID to which an event is sent when a |
|
445 | 445 | if (status!=RTEMS_SUCCESSFUL) { |
|
446 | 446 | PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_EVENT_ID\n") // link-error interrupt occurs |
|
447 | 447 | } |
|
448 | 448 | // |
|
449 | 449 | status = ioctl(fd, SPACEWIRE_IOCTRL_SET_DISABLE_ERR, 0); // automatic link-disabling due to link-error interrupts |
|
450 | 450 | if (status!=RTEMS_SUCCESSFUL) { |
|
451 | 451 | PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_DISABLE_ERR\n") |
|
452 | 452 | } |
|
453 | 453 | // |
|
454 | 454 | status = ioctl(fd, SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ, 1); // sets the link-error interrupt bit |
|
455 | 455 | if (status!=RTEMS_SUCCESSFUL) { |
|
456 | 456 | PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n") |
|
457 | 457 | } |
|
458 | 458 | // |
|
459 | 459 | status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK, 1); // transmission blocks |
|
460 | 460 | if (status!=RTEMS_SUCCESSFUL) { |
|
461 | 461 | PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK\n") |
|
462 | 462 | } |
|
463 | 463 | // |
|
464 | 464 | status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL, 1); // transmission blocks when no transmission descriptor is available |
|
465 | 465 | if (status!=RTEMS_SUCCESSFUL) { |
|
466 | 466 | PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL\n") |
|
467 | 467 | } |
|
468 | 468 | // |
|
469 | 469 | status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TCODE_CTRL, 0x0909); // [Time Rx : Time Tx : Link error : Tick-out IRQ] |
|
470 | 470 | if (status!=RTEMS_SUCCESSFUL) { |
|
471 | 471 | PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TCODE_CTRL,\n") |
|
472 | 472 | } |
|
473 | 473 | |
|
474 | 474 | return status; |
|
475 | 475 | } |
|
476 | 476 | |
|
477 | 477 | int spacewire_reset_link( void ) |
|
478 | 478 | { |
|
479 | 479 | /** This function is executed by the SPIQ rtems_task wehn it has been awaken by an interruption raised by the SpaceWire driver. |
|
480 | 480 | * |
|
481 | 481 | * @return RTEMS directive status code: |
|
482 | 482 | * - RTEMS_UNSATISFIED is returned is the link is not in the running state after 10 s. |
|
483 | 483 | * - RTEMS_SUCCESSFUL is returned if the link is up before the timeout. |
|
484 | 484 | * |
|
485 | 485 | */ |
|
486 | 486 | |
|
487 | 487 | rtems_status_code status_spw; |
|
488 | 488 | rtems_status_code status; |
|
489 | 489 | int i; |
|
490 | 490 | |
|
491 | 491 | for ( i=0; i<SY_LFR_DPU_CONNECT_ATTEMPT; i++ ) |
|
492 | 492 | { |
|
493 | 493 | PRINTF1("in spacewire_reset_link *** link recovery, try %d\n", i); |
|
494 | 494 | |
|
495 | 495 | // CLOSING THE DRIVER AT THIS POINT WILL MAKE THE SEND TASK BLOCK THE SYSTEM |
|
496 | 496 | |
|
497 | 497 | status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms |
|
498 | 498 | |
|
499 | 499 | status_spw = spacewire_stop_and_start_link( fdSPW ); |
|
500 | 500 | if ( status_spw != RTEMS_SUCCESSFUL ) |
|
501 | 501 | { |
|
502 | 502 | PRINTF1("in spacewire_reset_link *** ERR spacewire_start_link code %d\n", status_spw) |
|
503 | 503 | } |
|
504 | 504 | |
|
505 | 505 | if ( status_spw == RTEMS_SUCCESSFUL) |
|
506 | 506 | { |
|
507 | 507 | break; |
|
508 | 508 | } |
|
509 | 509 | } |
|
510 | 510 | |
|
511 | 511 | return status_spw; |
|
512 | 512 | } |
|
513 | 513 | |
|
514 | 514 | void spacewire_set_NP( unsigned char val, unsigned int regAddr ) // [N]o [P]ort force |
|
515 | 515 | { |
|
516 | 516 | /** This function sets the [N]o [P]ort force bit of the GRSPW control register. |
|
517 | 517 | * |
|
518 | 518 | * @param val is the value, 0 or 1, used to set the value of the NP bit. |
|
519 | 519 | * @param regAddr is the address of the GRSPW control register. |
|
520 | 520 | * |
|
521 | 521 | * NP is the bit 20 of the GRSPW control register. |
|
522 | 522 | * |
|
523 | 523 | */ |
|
524 | 524 | |
|
525 | 525 | unsigned int *spwptr = (unsigned int*) regAddr; |
|
526 | 526 | |
|
527 | 527 | if (val == 1) { |
|
528 | 528 | *spwptr = *spwptr | 0x00100000; // [NP] set the No port force bit |
|
529 | 529 | } |
|
530 | 530 | if (val== 0) { |
|
531 | 531 | *spwptr = *spwptr & 0xffdfffff; |
|
532 | 532 | } |
|
533 | 533 | } |
|
534 | 534 | |
|
535 | 535 | void spacewire_set_RE( unsigned char val, unsigned int regAddr ) // [R]MAP [E]nable |
|
536 | 536 | { |
|
537 | 537 | /** This function sets the [R]MAP [E]nable bit of the GRSPW control register. |
|
538 | 538 | * |
|
539 | 539 | * @param val is the value, 0 or 1, used to set the value of the RE bit. |
|
540 | 540 | * @param regAddr is the address of the GRSPW control register. |
|
541 | 541 | * |
|
542 | 542 | * RE is the bit 16 of the GRSPW control register. |
|
543 | 543 | * |
|
544 | 544 | */ |
|
545 | 545 | |
|
546 | 546 | unsigned int *spwptr = (unsigned int*) regAddr; |
|
547 | 547 | |
|
548 | 548 | if (val == 1) |
|
549 | 549 | { |
|
550 | 550 | *spwptr = *spwptr | 0x00010000; // [RE] set the RMAP Enable bit |
|
551 | 551 | } |
|
552 | 552 | if (val== 0) |
|
553 | 553 | { |
|
554 | 554 | *spwptr = *spwptr & 0xfffdffff; |
|
555 | 555 | } |
|
556 | 556 | } |
|
557 | 557 | |
|
558 | 558 | void spacewire_compute_stats_offsets( void ) |
|
559 | 559 | { |
|
560 | 560 | /** This function computes the SpaceWire statistics offsets in case of a SpaceWire related interruption raising. |
|
561 | 561 | * |
|
562 | 562 | * The offsets keep a record of the statistics in case of a reset of the statistics. They are added to the current statistics |
|
563 | 563 | * to keep the counters consistent even after a reset of the SpaceWire driver (the counter are set to zero by the driver when it |
|
564 | 564 | * during the open systel call). |
|
565 | 565 | * |
|
566 | 566 | */ |
|
567 | 567 | |
|
568 | 568 | spw_stats spacewire_stats_grspw; |
|
569 | 569 | rtems_status_code status; |
|
570 | 570 | |
|
571 | 571 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &spacewire_stats_grspw ); |
|
572 | 572 | |
|
573 | 573 | spacewire_stats_backup.packets_received = spacewire_stats_grspw.packets_received |
|
574 | 574 | + spacewire_stats.packets_received; |
|
575 | 575 | spacewire_stats_backup.packets_sent = spacewire_stats_grspw.packets_sent |
|
576 | 576 | + spacewire_stats.packets_sent; |
|
577 | 577 | spacewire_stats_backup.parity_err = spacewire_stats_grspw.parity_err |
|
578 | 578 | + spacewire_stats.parity_err; |
|
579 | 579 | spacewire_stats_backup.disconnect_err = spacewire_stats_grspw.disconnect_err |
|
580 | 580 | + spacewire_stats.disconnect_err; |
|
581 | 581 | spacewire_stats_backup.escape_err = spacewire_stats_grspw.escape_err |
|
582 | 582 | + spacewire_stats.escape_err; |
|
583 | 583 | spacewire_stats_backup.credit_err = spacewire_stats_grspw.credit_err |
|
584 | 584 | + spacewire_stats.credit_err; |
|
585 | 585 | spacewire_stats_backup.write_sync_err = spacewire_stats_grspw.write_sync_err |
|
586 | 586 | + spacewire_stats.write_sync_err; |
|
587 | 587 | spacewire_stats_backup.rx_rmap_header_crc_err = spacewire_stats_grspw.rx_rmap_header_crc_err |
|
588 | 588 | + spacewire_stats.rx_rmap_header_crc_err; |
|
589 | 589 | spacewire_stats_backup.rx_rmap_data_crc_err = spacewire_stats_grspw.rx_rmap_data_crc_err |
|
590 | 590 | + spacewire_stats.rx_rmap_data_crc_err; |
|
591 | 591 | spacewire_stats_backup.early_ep = spacewire_stats_grspw.early_ep |
|
592 | 592 | + spacewire_stats.early_ep; |
|
593 | 593 | spacewire_stats_backup.invalid_address = spacewire_stats_grspw.invalid_address |
|
594 | 594 | + spacewire_stats.invalid_address; |
|
595 | 595 | spacewire_stats_backup.rx_eep_err = spacewire_stats_grspw.rx_eep_err |
|
596 | 596 | + spacewire_stats.rx_eep_err; |
|
597 | 597 | spacewire_stats_backup.rx_truncated = spacewire_stats_grspw.rx_truncated |
|
598 | 598 | + spacewire_stats.rx_truncated; |
|
599 | 599 | } |
|
600 | 600 | |
|
601 | 601 | void spacewire_update_statistics( void ) |
|
602 | 602 | { |
|
603 | 603 | rtems_status_code status; |
|
604 | 604 | spw_stats spacewire_stats_grspw; |
|
605 | 605 | |
|
606 | 606 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_GET_STATISTICS, &spacewire_stats_grspw ); |
|
607 | 607 | |
|
608 | 608 | spacewire_stats.packets_received = spacewire_stats_backup.packets_received |
|
609 | 609 | + spacewire_stats_grspw.packets_received; |
|
610 | 610 | spacewire_stats.packets_sent = spacewire_stats_backup.packets_sent |
|
611 | 611 | + spacewire_stats_grspw.packets_sent; |
|
612 | 612 | spacewire_stats.parity_err = spacewire_stats_backup.parity_err |
|
613 | 613 | + spacewire_stats_grspw.parity_err; |
|
614 | 614 | spacewire_stats.disconnect_err = spacewire_stats_backup.disconnect_err |
|
615 | 615 | + spacewire_stats_grspw.disconnect_err; |
|
616 | 616 | spacewire_stats.escape_err = spacewire_stats_backup.escape_err |
|
617 | 617 | + spacewire_stats_grspw.escape_err; |
|
618 | 618 | spacewire_stats.credit_err = spacewire_stats_backup.credit_err |
|
619 | 619 | + spacewire_stats_grspw.credit_err; |
|
620 | 620 | spacewire_stats.write_sync_err = spacewire_stats_backup.write_sync_err |
|
621 | 621 | + spacewire_stats_grspw.write_sync_err; |
|
622 | 622 | spacewire_stats.rx_rmap_header_crc_err = spacewire_stats_backup.rx_rmap_header_crc_err |
|
623 | 623 | + spacewire_stats_grspw.rx_rmap_header_crc_err; |
|
624 | 624 | spacewire_stats.rx_rmap_data_crc_err = spacewire_stats_backup.rx_rmap_data_crc_err |
|
625 | 625 | + spacewire_stats_grspw.rx_rmap_data_crc_err; |
|
626 | 626 | spacewire_stats.early_ep = spacewire_stats_backup.early_ep |
|
627 | 627 | + spacewire_stats_grspw.early_ep; |
|
628 | 628 | spacewire_stats.invalid_address = spacewire_stats_backup.invalid_address |
|
629 | 629 | + spacewire_stats_grspw.invalid_address; |
|
630 | 630 | spacewire_stats.rx_eep_err = spacewire_stats_backup.rx_eep_err |
|
631 | 631 | + spacewire_stats_grspw.rx_eep_err; |
|
632 | 632 | spacewire_stats.rx_truncated = spacewire_stats_backup.rx_truncated |
|
633 | 633 | + spacewire_stats_grspw.rx_truncated; |
|
634 | 634 | //spacewire_stats.tx_link_err; |
|
635 | 635 | |
|
636 | 636 | //**************************** |
|
637 | 637 | // DPU_SPACEWIRE_IF_STATISTICS |
|
638 | 638 | housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[0] = (unsigned char) (spacewire_stats.packets_received >> 8); |
|
639 | 639 | housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[1] = (unsigned char) (spacewire_stats.packets_received); |
|
640 | 640 | housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[0] = (unsigned char) (spacewire_stats.packets_sent >> 8); |
|
641 | 641 | housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[1] = (unsigned char) (spacewire_stats.packets_sent); |
|
642 | 642 | //housekeeping_packet.hk_lfr_dpu_spw_tick_out_cnt; |
|
643 | 643 | //housekeeping_packet.hk_lfr_dpu_spw_last_timc; |
|
644 | 644 | |
|
645 | 645 | //****************************************** |
|
646 | 646 | // ERROR COUNTERS / SPACEWIRE / LOW SEVERITY |
|
647 | 647 | housekeeping_packet.hk_lfr_dpu_spw_parity = (unsigned char) spacewire_stats.parity_err; |
|
648 | 648 | housekeeping_packet.hk_lfr_dpu_spw_disconnect = (unsigned char) spacewire_stats.disconnect_err; |
|
649 | 649 | housekeeping_packet.hk_lfr_dpu_spw_escape = (unsigned char) spacewire_stats.escape_err; |
|
650 | 650 | housekeeping_packet.hk_lfr_dpu_spw_credit = (unsigned char) spacewire_stats.credit_err; |
|
651 | 651 | housekeeping_packet.hk_lfr_dpu_spw_write_sync = (unsigned char) spacewire_stats.write_sync_err; |
|
652 | 652 | |
|
653 | 653 | //********************************************* |
|
654 | 654 | // ERROR COUNTERS / SPACEWIRE / MEDIUM SEVERITY |
|
655 | 655 | housekeeping_packet.hk_lfr_dpu_spw_early_eop = (unsigned char) spacewire_stats.early_ep; |
|
656 | 656 | housekeeping_packet.hk_lfr_dpu_spw_invalid_addr = (unsigned char) spacewire_stats.invalid_address; |
|
657 | 657 | housekeeping_packet.hk_lfr_dpu_spw_eep = (unsigned char) spacewire_stats.rx_eep_err; |
|
658 | 658 | housekeeping_packet.hk_lfr_dpu_spw_rx_too_big = (unsigned char) spacewire_stats.rx_truncated; |
|
659 | 659 | } |
|
660 | 660 | |
|
661 | 661 | void timecode_irq_handler( void *pDev, void *regs, int minor, unsigned int tc ) |
|
662 | 662 | { |
|
663 | 663 | // a valid timecode has been received, write it in the HK report |
|
664 | 664 | unsigned int *grspwPtr; |
|
665 | 665 | unsigned char timecodeCtr; |
|
666 | 666 | unsigned char updateTimeCtr; |
|
667 | 667 | |
|
668 | 668 | grspwPtr = (unsigned int *) (REGS_ADDR_GRSPW + APB_OFFSET_GRSPW_TIME_REGISTER); |
|
669 | 669 | |
|
670 | 670 | housekeeping_packet.hk_lfr_dpu_spw_last_timc = (unsigned char) (grspwPtr[0] & 0xff); // [1111 1111] |
|
671 | 671 | timecodeCtr = (unsigned char) (grspwPtr[0] & 0x3f); // [0011 1111] |
|
672 | 672 | updateTimeCtr = time_management_regs->coarse_time_load & 0x3f; // [0011 1111] |
|
673 | 673 | |
|
674 | 674 | // update the number of valid timecodes that have been received |
|
675 | 675 | if (housekeeping_packet.hk_lfr_dpu_spw_tick_out_cnt == 255) |
|
676 | 676 | { |
|
677 | 677 | housekeeping_packet.hk_lfr_dpu_spw_tick_out_cnt = 0; |
|
678 | 678 | } |
|
679 | 679 | else |
|
680 | 680 | { |
|
681 | 681 | housekeeping_packet.hk_lfr_dpu_spw_tick_out_cnt = housekeeping_packet.hk_lfr_dpu_spw_tick_out_cnt + 1; |
|
682 | 682 | } |
|
683 | 683 | |
|
684 | 684 | // check the value of the timecode with respect to the last TC_LFR_UPDATE_TIME => SSS-CP-FS-370 |
|
685 | 685 | if (timecodeCtr != updateTimeCtr) |
|
686 | 686 | { |
|
687 | 687 | if (housekeeping_packet.hk_lfr_time_timecode_ctr == 255) |
|
688 | 688 | { |
|
689 | 689 | housekeeping_packet.hk_lfr_time_timecode_ctr = 0; |
|
690 | 690 | } |
|
691 | 691 | else |
|
692 | 692 | { |
|
693 | 693 | housekeeping_packet.hk_lfr_time_timecode_ctr = housekeeping_packet.hk_lfr_time_timecode_ctr + 1; |
|
694 | 694 | } |
|
695 | 695 | } |
|
696 | 696 | } |
|
697 | 697 | |
|
698 | rtems_timer_service_routine user_routine( rtems_id timer_id, void *user_data ) | |
|
699 | { | |
|
700 | int linkStatus; | |
|
701 | rtems_status_code status; | |
|
702 | ||
|
703 | status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status | |
|
704 | ||
|
705 | if ( linkStatus == 5) { | |
|
706 | PRINTF("in spacewire_reset_link *** link is running\n") | |
|
707 | status = RTEMS_SUCCESSFUL; | |
|
708 | } | |
|
709 | } | |
|
710 | ||
|
711 | 698 | void init_header_cwf( Header_TM_LFR_SCIENCE_CWF_t *header ) |
|
712 | 699 | { |
|
713 | 700 | header->targetLogicalAddress = CCSDS_DESTINATION_ID; |
|
714 | 701 | header->protocolIdentifier = CCSDS_PROTOCOLE_ID; |
|
715 | 702 | header->reserved = DEFAULT_RESERVED; |
|
716 | 703 | header->userApplication = CCSDS_USER_APP; |
|
717 | 704 | header->packetSequenceControl[0]= TM_PACKET_SEQ_CTRL_STANDALONE; |
|
718 | 705 | header->packetSequenceControl[1]= TM_PACKET_SEQ_CNT_DEFAULT; |
|
719 | 706 | header->packetLength[0] = 0x00; |
|
720 | 707 | header->packetLength[1] = 0x00; |
|
721 | 708 | // DATA FIELD HEADER |
|
722 | 709 | header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; |
|
723 | 710 | header->serviceType = TM_TYPE_LFR_SCIENCE; // service type |
|
724 | 711 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; // service subtype |
|
725 | 712 | header->destinationID = TM_DESTINATION_ID_GROUND; |
|
726 | 713 | header->time[0] = 0x00; |
|
727 | 714 | header->time[0] = 0x00; |
|
728 | 715 | header->time[0] = 0x00; |
|
729 | 716 | header->time[0] = 0x00; |
|
730 | 717 | header->time[0] = 0x00; |
|
731 | 718 | header->time[0] = 0x00; |
|
732 | 719 | // AUXILIARY DATA HEADER |
|
733 | 720 | header->sid = 0x00; |
|
734 | 721 | header->hkBIA = DEFAULT_HKBIA; |
|
735 | 722 | header->blkNr[0] = 0x00; |
|
736 | 723 | header->blkNr[1] = 0x00; |
|
737 | 724 | } |
|
738 | 725 | |
|
739 | 726 | void init_header_swf( Header_TM_LFR_SCIENCE_SWF_t *header ) |
|
740 | 727 | { |
|
741 | 728 | header->targetLogicalAddress = CCSDS_DESTINATION_ID; |
|
742 | 729 | header->protocolIdentifier = CCSDS_PROTOCOLE_ID; |
|
743 | 730 | header->reserved = DEFAULT_RESERVED; |
|
744 | 731 | header->userApplication = CCSDS_USER_APP; |
|
745 | 732 | header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8); |
|
746 | 733 | header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST); |
|
747 | 734 | header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE; |
|
748 | 735 | header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT; |
|
749 | 736 | header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> 8); |
|
750 | 737 | header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 ); |
|
751 | 738 | // DATA FIELD HEADER |
|
752 | 739 | header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; |
|
753 | 740 | header->serviceType = TM_TYPE_LFR_SCIENCE; // service type |
|
754 | 741 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; // service subtype |
|
755 | 742 | header->destinationID = TM_DESTINATION_ID_GROUND; |
|
756 | 743 | header->time[0] = 0x00; |
|
757 | 744 | header->time[0] = 0x00; |
|
758 | 745 | header->time[0] = 0x00; |
|
759 | 746 | header->time[0] = 0x00; |
|
760 | 747 | header->time[0] = 0x00; |
|
761 | 748 | header->time[0] = 0x00; |
|
762 | 749 | // AUXILIARY DATA HEADER |
|
763 | 750 | header->sid = 0x00; |
|
764 | 751 | header->hkBIA = DEFAULT_HKBIA; |
|
765 | 752 | header->pktCnt = DEFAULT_PKTCNT; // PKT_CNT |
|
766 | 753 | header->pktNr = 0x00; |
|
767 | 754 | header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> 8); |
|
768 | 755 | header->blkNr[1] = (unsigned char) (BLK_NR_CWF ); |
|
769 | 756 | } |
|
770 | 757 | |
|
771 | 758 | void init_header_asm( Header_TM_LFR_SCIENCE_ASM_t *header ) |
|
772 | 759 | { |
|
773 | 760 | header->targetLogicalAddress = CCSDS_DESTINATION_ID; |
|
774 | 761 | header->protocolIdentifier = CCSDS_PROTOCOLE_ID; |
|
775 | 762 | header->reserved = DEFAULT_RESERVED; |
|
776 | 763 | header->userApplication = CCSDS_USER_APP; |
|
777 | 764 | header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8); |
|
778 | 765 | header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST); |
|
779 | 766 | header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE; |
|
780 | 767 | header->packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT; |
|
781 | 768 | header->packetLength[0] = 0x00; |
|
782 | 769 | header->packetLength[1] = 0x00; |
|
783 | 770 | // DATA FIELD HEADER |
|
784 | 771 | header->spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; |
|
785 | 772 | header->serviceType = TM_TYPE_LFR_SCIENCE; // service type |
|
786 | 773 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; // service subtype |
|
787 | 774 | header->destinationID = TM_DESTINATION_ID_GROUND; |
|
788 | 775 | header->time[0] = 0x00; |
|
789 | 776 | header->time[0] = 0x00; |
|
790 | 777 | header->time[0] = 0x00; |
|
791 | 778 | header->time[0] = 0x00; |
|
792 | 779 | header->time[0] = 0x00; |
|
793 | 780 | header->time[0] = 0x00; |
|
794 | 781 | // AUXILIARY DATA HEADER |
|
795 | 782 | header->sid = 0x00; |
|
796 | 783 | header->biaStatusInfo = 0x00; |
|
797 | 784 | header->pa_lfr_pkt_cnt_asm = 0x00; |
|
798 | 785 | header->pa_lfr_pkt_nr_asm = 0x00; |
|
799 | 786 | header->pa_lfr_asm_blk_nr[0] = 0x00; |
|
800 | 787 | header->pa_lfr_asm_blk_nr[1] = 0x00; |
|
801 | 788 | } |
|
802 | 789 | |
|
803 | 790 | int spw_send_waveform_CWF( ring_node *ring_node_to_send, |
|
804 | 791 | Header_TM_LFR_SCIENCE_CWF_t *header ) |
|
805 | 792 | { |
|
806 | 793 | /** This function sends CWF CCSDS packets (F2, F1 or F0). |
|
807 | 794 | * |
|
808 | 795 | * @param waveform points to the buffer containing the data that will be send. |
|
809 | 796 | * @param sid is the source identifier of the data that will be sent. |
|
810 | 797 | * @param headerCWF points to a table of headers that have been prepared for the data transmission. |
|
811 | 798 | * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures |
|
812 | 799 | * contain information to setup the transmission of the data packets. |
|
813 | 800 | * |
|
814 | 801 | * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks. |
|
815 | 802 | * |
|
816 | 803 | */ |
|
817 | 804 | |
|
818 | 805 | unsigned int i; |
|
819 | 806 | int ret; |
|
820 | 807 | unsigned int coarseTime; |
|
821 | 808 | unsigned int fineTime; |
|
822 | 809 | rtems_status_code status; |
|
823 | 810 | spw_ioctl_pkt_send spw_ioctl_send_CWF; |
|
824 | 811 | int *dataPtr; |
|
825 | 812 | unsigned char sid; |
|
826 | 813 | |
|
827 | 814 | spw_ioctl_send_CWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_CWF; |
|
828 | 815 | spw_ioctl_send_CWF.options = 0; |
|
829 | 816 | |
|
830 | 817 | ret = LFR_DEFAULT; |
|
831 | 818 | sid = (unsigned char) ring_node_to_send->sid; |
|
832 | 819 | |
|
833 | 820 | coarseTime = ring_node_to_send->coarseTime; |
|
834 | 821 | fineTime = ring_node_to_send->fineTime; |
|
835 | 822 | dataPtr = (int*) ring_node_to_send->buffer_address; |
|
836 | 823 | |
|
837 | 824 | header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> 8); |
|
838 | 825 | header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 ); |
|
839 | 826 | header->hkBIA = pa_bia_status_info; |
|
840 | 827 | header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; |
|
841 | 828 | header->blkNr[0] = (unsigned char) (BLK_NR_CWF >> 8); |
|
842 | 829 | header->blkNr[1] = (unsigned char) (BLK_NR_CWF ); |
|
843 | 830 | |
|
844 | 831 | for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF; i++) // send waveform |
|
845 | 832 | { |
|
846 | 833 | spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF * NB_WORDS_SWF_BLK) ]; |
|
847 | 834 | spw_ioctl_send_CWF.hdr = (char*) header; |
|
848 | 835 | // BUILD THE DATA |
|
849 | 836 | spw_ioctl_send_CWF.dlen = BLK_NR_CWF * NB_BYTES_SWF_BLK; |
|
850 | 837 | |
|
851 | 838 | // SET PACKET SEQUENCE CONTROL |
|
852 | 839 | increment_seq_counter_source_id( header->packetSequenceControl, sid ); |
|
853 | 840 | |
|
854 | 841 | // SET SID |
|
855 | 842 | header->sid = sid; |
|
856 | 843 | |
|
857 | 844 | // SET PACKET TIME |
|
858 | 845 | compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime); |
|
859 | 846 | // |
|
860 | 847 | header->time[0] = header->acquisitionTime[0]; |
|
861 | 848 | header->time[1] = header->acquisitionTime[1]; |
|
862 | 849 | header->time[2] = header->acquisitionTime[2]; |
|
863 | 850 | header->time[3] = header->acquisitionTime[3]; |
|
864 | 851 | header->time[4] = header->acquisitionTime[4]; |
|
865 | 852 | header->time[5] = header->acquisitionTime[5]; |
|
866 | 853 | |
|
867 | 854 | // SET PACKET ID |
|
868 | 855 | if ( (sid == SID_SBM1_CWF_F1) || (sid == SID_SBM2_CWF_F2) ) |
|
869 | 856 | { |
|
870 | 857 | header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2 >> 8); |
|
871 | 858 | header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2); |
|
872 | 859 | } |
|
873 | 860 | else |
|
874 | 861 | { |
|
875 | 862 | header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8); |
|
876 | 863 | header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST); |
|
877 | 864 | } |
|
878 | 865 | |
|
879 | 866 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF ); |
|
880 | 867 | if (status != RTEMS_SUCCESSFUL) { |
|
881 | 868 | ret = LFR_DEFAULT; |
|
882 | 869 | } |
|
883 | 870 | } |
|
884 | 871 | |
|
885 | 872 | return ret; |
|
886 | 873 | } |
|
887 | 874 | |
|
888 | 875 | int spw_send_waveform_SWF( ring_node *ring_node_to_send, |
|
889 | 876 | Header_TM_LFR_SCIENCE_SWF_t *header ) |
|
890 | 877 | { |
|
891 | 878 | /** This function sends SWF CCSDS packets (F2, F1 or F0). |
|
892 | 879 | * |
|
893 | 880 | * @param waveform points to the buffer containing the data that will be send. |
|
894 | 881 | * @param sid is the source identifier of the data that will be sent. |
|
895 | 882 | * @param headerSWF points to a table of headers that have been prepared for the data transmission. |
|
896 | 883 | * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures |
|
897 | 884 | * contain information to setup the transmission of the data packets. |
|
898 | 885 | * |
|
899 | 886 | * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks. |
|
900 | 887 | * |
|
901 | 888 | */ |
|
902 | 889 | |
|
903 | 890 | unsigned int i; |
|
904 | 891 | int ret; |
|
905 | 892 | unsigned int coarseTime; |
|
906 | 893 | unsigned int fineTime; |
|
907 | 894 | rtems_status_code status; |
|
908 | 895 | spw_ioctl_pkt_send spw_ioctl_send_SWF; |
|
909 | 896 | int *dataPtr; |
|
910 | 897 | unsigned char sid; |
|
911 | 898 | |
|
912 | 899 | spw_ioctl_send_SWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_SWF; |
|
913 | 900 | spw_ioctl_send_SWF.options = 0; |
|
914 | 901 | |
|
915 | 902 | ret = LFR_DEFAULT; |
|
916 | 903 | |
|
917 | 904 | coarseTime = ring_node_to_send->coarseTime; |
|
918 | 905 | fineTime = ring_node_to_send->fineTime; |
|
919 | 906 | dataPtr = (int*) ring_node_to_send->buffer_address; |
|
920 | 907 | sid = ring_node_to_send->sid; |
|
921 | 908 | |
|
922 | 909 | header->hkBIA = pa_bia_status_info; |
|
923 | 910 | header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; |
|
924 | 911 | |
|
925 | 912 | for (i=0; i<7; i++) // send waveform |
|
926 | 913 | { |
|
927 | 914 | spw_ioctl_send_SWF.data = (char*) &dataPtr[ (i * BLK_NR_304 * NB_WORDS_SWF_BLK) ]; |
|
928 | 915 | spw_ioctl_send_SWF.hdr = (char*) header; |
|
929 | 916 | |
|
930 | 917 | // SET PACKET SEQUENCE CONTROL |
|
931 | 918 | increment_seq_counter_source_id( header->packetSequenceControl, sid ); |
|
932 | 919 | |
|
933 | 920 | // SET PACKET LENGTH AND BLKNR |
|
934 | 921 | if (i == 6) |
|
935 | 922 | { |
|
936 | 923 | spw_ioctl_send_SWF.dlen = BLK_NR_224 * NB_BYTES_SWF_BLK; |
|
937 | 924 | header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_224 >> 8); |
|
938 | 925 | header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_224 ); |
|
939 | 926 | header->blkNr[0] = (unsigned char) (BLK_NR_224 >> 8); |
|
940 | 927 | header->blkNr[1] = (unsigned char) (BLK_NR_224 ); |
|
941 | 928 | } |
|
942 | 929 | else |
|
943 | 930 | { |
|
944 | 931 | spw_ioctl_send_SWF.dlen = BLK_NR_304 * NB_BYTES_SWF_BLK; |
|
945 | 932 | header->packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_304 >> 8); |
|
946 | 933 | header->packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_304 ); |
|
947 | 934 | header->blkNr[0] = (unsigned char) (BLK_NR_304 >> 8); |
|
948 | 935 | header->blkNr[1] = (unsigned char) (BLK_NR_304 ); |
|
949 | 936 | } |
|
950 | 937 | |
|
951 | 938 | // SET PACKET TIME |
|
952 | 939 | compute_acquisition_time( coarseTime, fineTime, sid, i, header->acquisitionTime ); |
|
953 | 940 | // |
|
954 | 941 | header->time[0] = header->acquisitionTime[0]; |
|
955 | 942 | header->time[1] = header->acquisitionTime[1]; |
|
956 | 943 | header->time[2] = header->acquisitionTime[2]; |
|
957 | 944 | header->time[3] = header->acquisitionTime[3]; |
|
958 | 945 | header->time[4] = header->acquisitionTime[4]; |
|
959 | 946 | header->time[5] = header->acquisitionTime[5]; |
|
960 | 947 | |
|
961 | 948 | // SET SID |
|
962 | 949 | header->sid = sid; |
|
963 | 950 | |
|
964 | 951 | // SET PKTNR |
|
965 | 952 | header->pktNr = i+1; // PKT_NR |
|
966 | 953 | |
|
967 | 954 | // SEND PACKET |
|
968 | 955 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_SWF ); |
|
969 | 956 | if (status != RTEMS_SUCCESSFUL) { |
|
970 | 957 | ret = LFR_DEFAULT; |
|
971 | 958 | } |
|
972 | 959 | } |
|
973 | 960 | |
|
974 | 961 | return ret; |
|
975 | 962 | } |
|
976 | 963 | |
|
977 | 964 | int spw_send_waveform_CWF3_light( ring_node *ring_node_to_send, |
|
978 | 965 | Header_TM_LFR_SCIENCE_CWF_t *header ) |
|
979 | 966 | { |
|
980 | 967 | /** This function sends CWF_F3 CCSDS packets without the b1, b2 and b3 data. |
|
981 | 968 | * |
|
982 | 969 | * @param waveform points to the buffer containing the data that will be send. |
|
983 | 970 | * @param headerCWF points to a table of headers that have been prepared for the data transmission. |
|
984 | 971 | * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures |
|
985 | 972 | * contain information to setup the transmission of the data packets. |
|
986 | 973 | * |
|
987 | 974 | * By default, CWF_F3 packet are send without the b1, b2 and b3 data. This function rebuilds a data buffer |
|
988 | 975 | * from the incoming data and sends it in 7 packets, 6 containing 340 blocks and 1 one containing 8 blocks. |
|
989 | 976 | * |
|
990 | 977 | */ |
|
991 | 978 | |
|
992 | 979 | unsigned int i; |
|
993 | 980 | int ret; |
|
994 | 981 | unsigned int coarseTime; |
|
995 | 982 | unsigned int fineTime; |
|
996 | 983 | rtems_status_code status; |
|
997 | 984 | spw_ioctl_pkt_send spw_ioctl_send_CWF; |
|
998 | 985 | char *dataPtr; |
|
999 | 986 | unsigned char sid; |
|
1000 | 987 | |
|
1001 | 988 | spw_ioctl_send_CWF.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_CWF; |
|
1002 | 989 | spw_ioctl_send_CWF.options = 0; |
|
1003 | 990 | |
|
1004 | 991 | ret = LFR_DEFAULT; |
|
1005 | 992 | sid = ring_node_to_send->sid; |
|
1006 | 993 | |
|
1007 | 994 | coarseTime = ring_node_to_send->coarseTime; |
|
1008 | 995 | fineTime = ring_node_to_send->fineTime; |
|
1009 | 996 | dataPtr = (char*) ring_node_to_send->buffer_address; |
|
1010 | 997 | |
|
1011 | 998 | header->packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_672 >> 8); |
|
1012 | 999 | header->packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_672 ); |
|
1013 | 1000 | header->hkBIA = pa_bia_status_info; |
|
1014 | 1001 | header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; |
|
1015 | 1002 | header->blkNr[0] = (unsigned char) (BLK_NR_CWF_SHORT_F3 >> 8); |
|
1016 | 1003 | header->blkNr[1] = (unsigned char) (BLK_NR_CWF_SHORT_F3 ); |
|
1017 | 1004 | |
|
1018 | 1005 | //********************* |
|
1019 | 1006 | // SEND CWF3_light DATA |
|
1020 | 1007 | for (i=0; i<NB_PACKETS_PER_GROUP_OF_CWF_LIGHT; i++) // send waveform |
|
1021 | 1008 | { |
|
1022 | 1009 | spw_ioctl_send_CWF.data = (char*) &dataPtr[ (i * BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK) ]; |
|
1023 | 1010 | spw_ioctl_send_CWF.hdr = (char*) header; |
|
1024 | 1011 | // BUILD THE DATA |
|
1025 | 1012 | spw_ioctl_send_CWF.dlen = BLK_NR_CWF_SHORT_F3 * NB_BYTES_CWF3_LIGHT_BLK; |
|
1026 | 1013 | |
|
1027 | 1014 | // SET PACKET SEQUENCE COUNTER |
|
1028 | 1015 | increment_seq_counter_source_id( header->packetSequenceControl, sid ); |
|
1029 | 1016 | |
|
1030 | 1017 | // SET SID |
|
1031 | 1018 | header->sid = sid; |
|
1032 | 1019 | |
|
1033 | 1020 | // SET PACKET TIME |
|
1034 | 1021 | compute_acquisition_time( coarseTime, fineTime, SID_NORM_CWF_F3, i, header->acquisitionTime ); |
|
1035 | 1022 | // |
|
1036 | 1023 | header->time[0] = header->acquisitionTime[0]; |
|
1037 | 1024 | header->time[1] = header->acquisitionTime[1]; |
|
1038 | 1025 | header->time[2] = header->acquisitionTime[2]; |
|
1039 | 1026 | header->time[3] = header->acquisitionTime[3]; |
|
1040 | 1027 | header->time[4] = header->acquisitionTime[4]; |
|
1041 | 1028 | header->time[5] = header->acquisitionTime[5]; |
|
1042 | 1029 | |
|
1043 | 1030 | // SET PACKET ID |
|
1044 | 1031 | header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8); |
|
1045 | 1032 | header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST); |
|
1046 | 1033 | |
|
1047 | 1034 | // SEND PACKET |
|
1048 | 1035 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_CWF ); |
|
1049 | 1036 | if (status != RTEMS_SUCCESSFUL) { |
|
1050 | 1037 | ret = LFR_DEFAULT; |
|
1051 | 1038 | } |
|
1052 | 1039 | } |
|
1053 | 1040 | |
|
1054 | 1041 | return ret; |
|
1055 | 1042 | } |
|
1056 | 1043 | |
|
1057 | 1044 | void spw_send_asm_f0( ring_node *ring_node_to_send, |
|
1058 | 1045 | Header_TM_LFR_SCIENCE_ASM_t *header ) |
|
1059 | 1046 | { |
|
1060 | 1047 | unsigned int i; |
|
1061 | 1048 | unsigned int length = 0; |
|
1062 | 1049 | rtems_status_code status; |
|
1063 | 1050 | unsigned int sid; |
|
1064 | 1051 | float *spectral_matrix; |
|
1065 | 1052 | int coarseTime; |
|
1066 | 1053 | int fineTime; |
|
1067 | 1054 | spw_ioctl_pkt_send spw_ioctl_send_ASM; |
|
1068 | 1055 | |
|
1069 | 1056 | sid = ring_node_to_send->sid; |
|
1070 | 1057 | spectral_matrix = (float*) ring_node_to_send->buffer_address; |
|
1071 | 1058 | coarseTime = ring_node_to_send->coarseTime; |
|
1072 | 1059 | fineTime = ring_node_to_send->fineTime; |
|
1073 | 1060 | |
|
1074 | 1061 | header->biaStatusInfo = pa_bia_status_info; |
|
1075 | 1062 | header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; |
|
1076 | 1063 | |
|
1077 | 1064 | for (i=0; i<3; i++) |
|
1078 | 1065 | { |
|
1079 | 1066 | if ((i==0) || (i==1)) |
|
1080 | 1067 | { |
|
1081 | 1068 | spw_ioctl_send_ASM.dlen = DLEN_ASM_F0_PKT_1; |
|
1082 | 1069 | spw_ioctl_send_ASM.data = (char *) &spectral_matrix[ |
|
1083 | 1070 | ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0_1) ) * NB_VALUES_PER_SM ) |
|
1084 | 1071 | ]; |
|
1085 | 1072 | length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0_1; |
|
1086 | 1073 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; |
|
1087 | 1074 | header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0_1) >> 8 ); // BLK_NR MSB |
|
1088 | 1075 | header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0_1); // BLK_NR LSB |
|
1089 | 1076 | } |
|
1090 | 1077 | else |
|
1091 | 1078 | { |
|
1092 | 1079 | spw_ioctl_send_ASM.dlen = DLEN_ASM_F0_PKT_2; |
|
1093 | 1080 | spw_ioctl_send_ASM.data = (char*) &spectral_matrix[ |
|
1094 | 1081 | ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0_1) ) * NB_VALUES_PER_SM ) |
|
1095 | 1082 | ]; |
|
1096 | 1083 | length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0_2; |
|
1097 | 1084 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; |
|
1098 | 1085 | header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0_2) >> 8 ); // BLK_NR MSB |
|
1099 | 1086 | header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0_2); // BLK_NR LSB |
|
1100 | 1087 | } |
|
1101 | 1088 | |
|
1102 | 1089 | spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM; |
|
1103 | 1090 | spw_ioctl_send_ASM.hdr = (char *) header; |
|
1104 | 1091 | spw_ioctl_send_ASM.options = 0; |
|
1105 | 1092 | |
|
1106 | 1093 | // (2) BUILD THE HEADER |
|
1107 | 1094 | increment_seq_counter_source_id( header->packetSequenceControl, sid ); |
|
1108 | 1095 | header->packetLength[0] = (unsigned char) (length>>8); |
|
1109 | 1096 | header->packetLength[1] = (unsigned char) (length); |
|
1110 | 1097 | header->sid = (unsigned char) sid; // SID |
|
1111 | 1098 | header->pa_lfr_pkt_cnt_asm = 3; |
|
1112 | 1099 | header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1); |
|
1113 | 1100 | |
|
1114 | 1101 | // (3) SET PACKET TIME |
|
1115 | 1102 | header->time[0] = (unsigned char) (coarseTime>>24); |
|
1116 | 1103 | header->time[1] = (unsigned char) (coarseTime>>16); |
|
1117 | 1104 | header->time[2] = (unsigned char) (coarseTime>>8); |
|
1118 | 1105 | header->time[3] = (unsigned char) (coarseTime); |
|
1119 | 1106 | header->time[4] = (unsigned char) (fineTime>>8); |
|
1120 | 1107 | header->time[5] = (unsigned char) (fineTime); |
|
1121 | 1108 | // |
|
1122 | 1109 | header->acquisitionTime[0] = header->time[0]; |
|
1123 | 1110 | header->acquisitionTime[1] = header->time[1]; |
|
1124 | 1111 | header->acquisitionTime[2] = header->time[2]; |
|
1125 | 1112 | header->acquisitionTime[3] = header->time[3]; |
|
1126 | 1113 | header->acquisitionTime[4] = header->time[4]; |
|
1127 | 1114 | header->acquisitionTime[5] = header->time[5]; |
|
1128 | 1115 | |
|
1129 | 1116 | // (4) SEND PACKET |
|
1130 | 1117 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM ); |
|
1131 | 1118 | if (status != RTEMS_SUCCESSFUL) { |
|
1132 | 1119 | PRINTF1("in ASM_send *** ERR %d\n", (int) status) |
|
1133 | 1120 | } |
|
1134 | 1121 | } |
|
1135 | 1122 | } |
|
1136 | 1123 | |
|
1137 | 1124 | void spw_send_asm_f1( ring_node *ring_node_to_send, |
|
1138 | 1125 | Header_TM_LFR_SCIENCE_ASM_t *header ) |
|
1139 | 1126 | { |
|
1140 | 1127 | unsigned int i; |
|
1141 | 1128 | unsigned int length = 0; |
|
1142 | 1129 | rtems_status_code status; |
|
1143 | 1130 | unsigned int sid; |
|
1144 | 1131 | float *spectral_matrix; |
|
1145 | 1132 | int coarseTime; |
|
1146 | 1133 | int fineTime; |
|
1147 | 1134 | spw_ioctl_pkt_send spw_ioctl_send_ASM; |
|
1148 | 1135 | |
|
1149 | 1136 | sid = ring_node_to_send->sid; |
|
1150 | 1137 | spectral_matrix = (float*) ring_node_to_send->buffer_address; |
|
1151 | 1138 | coarseTime = ring_node_to_send->coarseTime; |
|
1152 | 1139 | fineTime = ring_node_to_send->fineTime; |
|
1153 | 1140 | |
|
1154 | 1141 | header->biaStatusInfo = pa_bia_status_info; |
|
1155 | 1142 | header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; |
|
1156 | 1143 | |
|
1157 | 1144 | for (i=0; i<3; i++) |
|
1158 | 1145 | { |
|
1159 | 1146 | if ((i==0) || (i==1)) |
|
1160 | 1147 | { |
|
1161 | 1148 | spw_ioctl_send_ASM.dlen = DLEN_ASM_F1_PKT_1; |
|
1162 | 1149 | spw_ioctl_send_ASM.data = (char *) &spectral_matrix[ |
|
1163 | 1150 | ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1_1) ) * NB_VALUES_PER_SM ) |
|
1164 | 1151 | ]; |
|
1165 | 1152 | length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1_1; |
|
1166 | 1153 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; |
|
1167 | 1154 | header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1_1) >> 8 ); // BLK_NR MSB |
|
1168 | 1155 | header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1_1); // BLK_NR LSB |
|
1169 | 1156 | } |
|
1170 | 1157 | else |
|
1171 | 1158 | { |
|
1172 | 1159 | spw_ioctl_send_ASM.dlen = DLEN_ASM_F1_PKT_2; |
|
1173 | 1160 | spw_ioctl_send_ASM.data = (char*) &spectral_matrix[ |
|
1174 | 1161 | ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1_1) ) * NB_VALUES_PER_SM ) |
|
1175 | 1162 | ]; |
|
1176 | 1163 | length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1_2; |
|
1177 | 1164 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_6; |
|
1178 | 1165 | header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1_2) >> 8 ); // BLK_NR MSB |
|
1179 | 1166 | header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1_2); // BLK_NR LSB |
|
1180 | 1167 | } |
|
1181 | 1168 | |
|
1182 | 1169 | spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM; |
|
1183 | 1170 | spw_ioctl_send_ASM.hdr = (char *) header; |
|
1184 | 1171 | spw_ioctl_send_ASM.options = 0; |
|
1185 | 1172 | |
|
1186 | 1173 | // (2) BUILD THE HEADER |
|
1187 | 1174 | increment_seq_counter_source_id( header->packetSequenceControl, sid ); |
|
1188 | 1175 | header->packetLength[0] = (unsigned char) (length>>8); |
|
1189 | 1176 | header->packetLength[1] = (unsigned char) (length); |
|
1190 | 1177 | header->sid = (unsigned char) sid; // SID |
|
1191 | 1178 | header->pa_lfr_pkt_cnt_asm = 3; |
|
1192 | 1179 | header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1); |
|
1193 | 1180 | |
|
1194 | 1181 | // (3) SET PACKET TIME |
|
1195 | 1182 | header->time[0] = (unsigned char) (coarseTime>>24); |
|
1196 | 1183 | header->time[1] = (unsigned char) (coarseTime>>16); |
|
1197 | 1184 | header->time[2] = (unsigned char) (coarseTime>>8); |
|
1198 | 1185 | header->time[3] = (unsigned char) (coarseTime); |
|
1199 | 1186 | header->time[4] = (unsigned char) (fineTime>>8); |
|
1200 | 1187 | header->time[5] = (unsigned char) (fineTime); |
|
1201 | 1188 | // |
|
1202 | 1189 | header->acquisitionTime[0] = header->time[0]; |
|
1203 | 1190 | header->acquisitionTime[1] = header->time[1]; |
|
1204 | 1191 | header->acquisitionTime[2] = header->time[2]; |
|
1205 | 1192 | header->acquisitionTime[3] = header->time[3]; |
|
1206 | 1193 | header->acquisitionTime[4] = header->time[4]; |
|
1207 | 1194 | header->acquisitionTime[5] = header->time[5]; |
|
1208 | 1195 | |
|
1209 | 1196 | // (4) SEND PACKET |
|
1210 | 1197 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM ); |
|
1211 | 1198 | if (status != RTEMS_SUCCESSFUL) { |
|
1212 | 1199 | PRINTF1("in ASM_send *** ERR %d\n", (int) status) |
|
1213 | 1200 | } |
|
1214 | 1201 | } |
|
1215 | 1202 | } |
|
1216 | 1203 | |
|
1217 | 1204 | void spw_send_asm_f2( ring_node *ring_node_to_send, |
|
1218 | 1205 | Header_TM_LFR_SCIENCE_ASM_t *header ) |
|
1219 | 1206 | { |
|
1220 | 1207 | unsigned int i; |
|
1221 | 1208 | unsigned int length = 0; |
|
1222 | 1209 | rtems_status_code status; |
|
1223 | 1210 | unsigned int sid; |
|
1224 | 1211 | float *spectral_matrix; |
|
1225 | 1212 | int coarseTime; |
|
1226 | 1213 | int fineTime; |
|
1227 | 1214 | spw_ioctl_pkt_send spw_ioctl_send_ASM; |
|
1228 | 1215 | |
|
1229 | 1216 | sid = ring_node_to_send->sid; |
|
1230 | 1217 | spectral_matrix = (float*) ring_node_to_send->buffer_address; |
|
1231 | 1218 | coarseTime = ring_node_to_send->coarseTime; |
|
1232 | 1219 | fineTime = ring_node_to_send->fineTime; |
|
1233 | 1220 | |
|
1234 | 1221 | header->biaStatusInfo = pa_bia_status_info; |
|
1235 | 1222 | header->sy_lfr_common_parameters = parameter_dump_packet.sy_lfr_common_parameters; |
|
1236 | 1223 | |
|
1237 | 1224 | for (i=0; i<3; i++) |
|
1238 | 1225 | { |
|
1239 | 1226 | |
|
1240 | 1227 | spw_ioctl_send_ASM.dlen = DLEN_ASM_F2_PKT; |
|
1241 | 1228 | spw_ioctl_send_ASM.data = (char *) &spectral_matrix[ |
|
1242 | 1229 | ( (ASM_F2_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F2) ) * NB_VALUES_PER_SM ) |
|
1243 | 1230 | ]; |
|
1244 | 1231 | length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F2; |
|
1245 | 1232 | header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE_3; |
|
1246 | 1233 | header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F2) >> 8 ); // BLK_NR MSB |
|
1247 | 1234 | header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F2); // BLK_NR LSB |
|
1248 | 1235 | |
|
1249 | 1236 | spw_ioctl_send_ASM.hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM; |
|
1250 | 1237 | spw_ioctl_send_ASM.hdr = (char *) header; |
|
1251 | 1238 | spw_ioctl_send_ASM.options = 0; |
|
1252 | 1239 | |
|
1253 | 1240 | // (2) BUILD THE HEADER |
|
1254 | 1241 | increment_seq_counter_source_id( header->packetSequenceControl, sid ); |
|
1255 | 1242 | header->packetLength[0] = (unsigned char) (length>>8); |
|
1256 | 1243 | header->packetLength[1] = (unsigned char) (length); |
|
1257 | 1244 | header->sid = (unsigned char) sid; // SID |
|
1258 | 1245 | header->pa_lfr_pkt_cnt_asm = 3; |
|
1259 | 1246 | header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1); |
|
1260 | 1247 | |
|
1261 | 1248 | // (3) SET PACKET TIME |
|
1262 | 1249 | header->time[0] = (unsigned char) (coarseTime>>24); |
|
1263 | 1250 | header->time[1] = (unsigned char) (coarseTime>>16); |
|
1264 | 1251 | header->time[2] = (unsigned char) (coarseTime>>8); |
|
1265 | 1252 | header->time[3] = (unsigned char) (coarseTime); |
|
1266 | 1253 | header->time[4] = (unsigned char) (fineTime>>8); |
|
1267 | 1254 | header->time[5] = (unsigned char) (fineTime); |
|
1268 | 1255 | // |
|
1269 | 1256 | header->acquisitionTime[0] = header->time[0]; |
|
1270 | 1257 | header->acquisitionTime[1] = header->time[1]; |
|
1271 | 1258 | header->acquisitionTime[2] = header->time[2]; |
|
1272 | 1259 | header->acquisitionTime[3] = header->time[3]; |
|
1273 | 1260 | header->acquisitionTime[4] = header->time[4]; |
|
1274 | 1261 | header->acquisitionTime[5] = header->time[5]; |
|
1275 | 1262 | |
|
1276 | 1263 | // (4) SEND PACKET |
|
1277 | 1264 | status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, &spw_ioctl_send_ASM ); |
|
1278 | 1265 | if (status != RTEMS_SUCCESSFUL) { |
|
1279 | 1266 | PRINTF1("in ASM_send *** ERR %d\n", (int) status) |
|
1280 | 1267 | } |
|
1281 | 1268 | } |
|
1282 | 1269 | } |
|
1283 | 1270 | |
|
1284 | 1271 | void spw_send_k_dump( ring_node *ring_node_to_send ) |
|
1285 | 1272 | { |
|
1286 | 1273 | rtems_status_code status; |
|
1287 | 1274 | Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *kcoefficients_dump; |
|
1288 | 1275 | unsigned int packetLength; |
|
1289 | 1276 | unsigned int size; |
|
1290 | 1277 | |
|
1291 | 1278 | PRINTF("spw_send_k_dump\n") |
|
1292 | 1279 | |
|
1293 | 1280 | kcoefficients_dump = (Packet_TM_LFR_KCOEFFICIENTS_DUMP_t *) ring_node_to_send->buffer_address; |
|
1294 | 1281 | |
|
1295 | 1282 | packetLength = kcoefficients_dump->packetLength[0] * 256 + kcoefficients_dump->packetLength[1]; |
|
1296 | 1283 | |
|
1297 | 1284 | size = packetLength + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES; |
|
1298 | 1285 | |
|
1299 | 1286 | PRINTF2("packetLength %d, size %d\n", packetLength, size ) |
|
1300 | 1287 | |
|
1301 | 1288 | status = write( fdSPW, (char *) ring_node_to_send->buffer_address, size ); |
|
1302 | 1289 | |
|
1303 | 1290 | if (status == -1){ |
|
1304 | 1291 | PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size) |
|
1305 | 1292 | } |
|
1306 | 1293 | |
|
1307 | 1294 | ring_node_to_send->status = 0x00; |
|
1308 | 1295 | } |
@@ -1,1519 +1,1604 | |||
|
1 | 1 | /** Functions and tasks related to TeleCommand handling. |
|
2 | 2 | * |
|
3 | 3 | * @file |
|
4 | 4 | * @author P. LEROY |
|
5 | 5 | * |
|
6 | 6 | * A group of functions to handle TeleCommands:\n |
|
7 | 7 | * action launching\n |
|
8 | 8 | * TC parsing\n |
|
9 | 9 | * ... |
|
10 | 10 | * |
|
11 | 11 | */ |
|
12 | 12 | |
|
13 | 13 | #include "tc_handler.h" |
|
14 | 14 | #include "math.h" |
|
15 | 15 | |
|
16 | 16 | //*********** |
|
17 | 17 | // RTEMS TASK |
|
18 | 18 | |
|
19 | 19 | rtems_task actn_task( rtems_task_argument unused ) |
|
20 | 20 | { |
|
21 | 21 | /** This RTEMS task is responsible for launching actions upton the reception of valid TeleCommands. |
|
22 | 22 | * |
|
23 | 23 | * @param unused is the starting argument of the RTEMS task |
|
24 | 24 | * |
|
25 | 25 | * The ACTN task waits for data coming from an RTEMS msesage queue. When data arrives, it launches specific actions depending |
|
26 | 26 | * on the incoming TeleCommand. |
|
27 | 27 | * |
|
28 | 28 | */ |
|
29 | 29 | |
|
30 | 30 | int result; |
|
31 | 31 | rtems_status_code status; // RTEMS status code |
|
32 | 32 | ccsdsTelecommandPacket_t TC; // TC sent to the ACTN task |
|
33 | 33 | size_t size; // size of the incoming TC packet |
|
34 | 34 | unsigned char subtype; // subtype of the current TC packet |
|
35 | 35 | unsigned char time[6]; |
|
36 | 36 | rtems_id queue_rcv_id; |
|
37 | 37 | rtems_id queue_snd_id; |
|
38 | 38 | |
|
39 | 39 | status = get_message_queue_id_recv( &queue_rcv_id ); |
|
40 | 40 | if (status != RTEMS_SUCCESSFUL) |
|
41 | 41 | { |
|
42 | 42 | PRINTF1("in ACTN *** ERR get_message_queue_id_recv %d\n", status) |
|
43 | 43 | } |
|
44 | 44 | |
|
45 | 45 | status = get_message_queue_id_send( &queue_snd_id ); |
|
46 | 46 | if (status != RTEMS_SUCCESSFUL) |
|
47 | 47 | { |
|
48 | 48 | PRINTF1("in ACTN *** ERR get_message_queue_id_send %d\n", status) |
|
49 | 49 | } |
|
50 | 50 | |
|
51 | 51 | result = LFR_SUCCESSFUL; |
|
52 | 52 | subtype = 0; // subtype of the current TC packet |
|
53 | 53 | |
|
54 | 54 | BOOT_PRINTF("in ACTN *** \n") |
|
55 | 55 | |
|
56 | 56 | while(1) |
|
57 | 57 | { |
|
58 | 58 | status = rtems_message_queue_receive( queue_rcv_id, (char*) &TC, &size, |
|
59 | 59 | RTEMS_WAIT, RTEMS_NO_TIMEOUT); |
|
60 | 60 | getTime( time ); // set time to the current time |
|
61 | 61 | if (status!=RTEMS_SUCCESSFUL) |
|
62 | 62 | { |
|
63 | 63 | PRINTF1("ERR *** in task ACTN *** error receiving a message, code %d \n", status) |
|
64 | 64 | } |
|
65 | 65 | else |
|
66 | 66 | { |
|
67 | 67 | subtype = TC.serviceSubType; |
|
68 | 68 | switch(subtype) |
|
69 | 69 | { |
|
70 | 70 | case TC_SUBTYPE_RESET: |
|
71 | 71 | result = action_reset( &TC, queue_snd_id, time ); |
|
72 | 72 | close_action( &TC, result, queue_snd_id ); |
|
73 | 73 | break; |
|
74 | 74 | case TC_SUBTYPE_LOAD_COMM: |
|
75 | 75 | result = action_load_common_par( &TC ); |
|
76 | 76 | close_action( &TC, result, queue_snd_id ); |
|
77 | 77 | break; |
|
78 | 78 | case TC_SUBTYPE_LOAD_NORM: |
|
79 | 79 | result = action_load_normal_par( &TC, queue_snd_id, time ); |
|
80 | 80 | close_action( &TC, result, queue_snd_id ); |
|
81 | 81 | break; |
|
82 | 82 | case TC_SUBTYPE_LOAD_BURST: |
|
83 | 83 | result = action_load_burst_par( &TC, queue_snd_id, time ); |
|
84 | 84 | close_action( &TC, result, queue_snd_id ); |
|
85 | 85 | break; |
|
86 | 86 | case TC_SUBTYPE_LOAD_SBM1: |
|
87 | 87 | result = action_load_sbm1_par( &TC, queue_snd_id, time ); |
|
88 | 88 | close_action( &TC, result, queue_snd_id ); |
|
89 | 89 | break; |
|
90 | 90 | case TC_SUBTYPE_LOAD_SBM2: |
|
91 | 91 | result = action_load_sbm2_par( &TC, queue_snd_id, time ); |
|
92 | 92 | close_action( &TC, result, queue_snd_id ); |
|
93 | 93 | break; |
|
94 | 94 | case TC_SUBTYPE_DUMP: |
|
95 | 95 | result = action_dump_par( &TC, queue_snd_id ); |
|
96 | 96 | close_action( &TC, result, queue_snd_id ); |
|
97 | 97 | break; |
|
98 | 98 | case TC_SUBTYPE_ENTER: |
|
99 | 99 | result = action_enter_mode( &TC, queue_snd_id ); |
|
100 | 100 | close_action( &TC, result, queue_snd_id ); |
|
101 | 101 | break; |
|
102 | 102 | case TC_SUBTYPE_UPDT_INFO: |
|
103 | 103 | result = action_update_info( &TC, queue_snd_id ); |
|
104 | 104 | close_action( &TC, result, queue_snd_id ); |
|
105 | 105 | break; |
|
106 | 106 | case TC_SUBTYPE_EN_CAL: |
|
107 | 107 | result = action_enable_calibration( &TC, queue_snd_id, time ); |
|
108 | 108 | close_action( &TC, result, queue_snd_id ); |
|
109 | 109 | break; |
|
110 | 110 | case TC_SUBTYPE_DIS_CAL: |
|
111 | 111 | result = action_disable_calibration( &TC, queue_snd_id, time ); |
|
112 | 112 | close_action( &TC, result, queue_snd_id ); |
|
113 | 113 | break; |
|
114 | 114 | case TC_SUBTYPE_LOAD_K: |
|
115 | 115 | result = action_load_kcoefficients( &TC, queue_snd_id, time ); |
|
116 | 116 | close_action( &TC, result, queue_snd_id ); |
|
117 | 117 | break; |
|
118 | 118 | case TC_SUBTYPE_DUMP_K: |
|
119 | 119 | result = action_dump_kcoefficients( &TC, queue_snd_id, time ); |
|
120 | 120 | close_action( &TC, result, queue_snd_id ); |
|
121 | 121 | break; |
|
122 | 122 | case TC_SUBTYPE_LOAD_FBINS: |
|
123 | 123 | result = action_load_fbins_mask( &TC, queue_snd_id, time ); |
|
124 | 124 | close_action( &TC, result, queue_snd_id ); |
|
125 | 125 | break; |
|
126 | 126 | case TC_SUBTYPE_UPDT_TIME: |
|
127 | 127 | result = action_update_time( &TC ); |
|
128 | 128 | close_action( &TC, result, queue_snd_id ); |
|
129 | 129 | break; |
|
130 | 130 | default: |
|
131 | 131 | break; |
|
132 | 132 | } |
|
133 | 133 | } |
|
134 | 134 | } |
|
135 | 135 | } |
|
136 | 136 | |
|
137 | 137 | //*********** |
|
138 | 138 | // TC ACTIONS |
|
139 | 139 | |
|
140 | 140 | int action_reset(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) |
|
141 | 141 | { |
|
142 | 142 | /** This function executes specific actions when a TC_LFR_RESET TeleCommand has been received. |
|
143 | 143 | * |
|
144 | 144 | * @param TC points to the TeleCommand packet that is being processed |
|
145 | 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 | 149 | PRINTF("this is the end!!!\n") |
|
150 | 150 | exit(0); |
|
151 | 151 | send_tm_lfr_tc_exe_not_implemented( TC, queue_id, time ); |
|
152 | 152 | return LFR_DEFAULT; |
|
153 | 153 | } |
|
154 | 154 | |
|
155 | 155 | int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id ) |
|
156 | 156 | { |
|
157 | 157 | /** This function executes specific actions when a TC_LFR_ENTER_MODE TeleCommand has been received. |
|
158 | 158 | * |
|
159 | 159 | * @param TC points to the TeleCommand packet that is being processed |
|
160 | 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 | 164 | rtems_status_code status; |
|
165 | 165 | unsigned char requestedMode; |
|
166 | 166 | unsigned int *transitionCoarseTime_ptr; |
|
167 | 167 | unsigned int transitionCoarseTime; |
|
168 | 168 | unsigned char * bytePosPtr; |
|
169 | 169 | |
|
170 | 170 | bytePosPtr = (unsigned char *) &TC->packetID; |
|
171 | 171 | |
|
172 | 172 | requestedMode = bytePosPtr[ BYTE_POS_CP_MODE_LFR_SET ]; |
|
173 | 173 | transitionCoarseTime_ptr = (unsigned int *) ( &bytePosPtr[ BYTE_POS_CP_LFR_ENTER_MODE_TIME ] ); |
|
174 | 174 | transitionCoarseTime = (*transitionCoarseTime_ptr) & 0x7fffffff; |
|
175 | 175 | |
|
176 | 176 | status = check_mode_value( requestedMode ); |
|
177 | 177 | |
|
178 | 178 | if ( status != LFR_SUCCESSFUL ) // the mode value is inconsistent |
|
179 | 179 | { |
|
180 | 180 | send_tm_lfr_tc_exe_inconsistent( TC, queue_id, BYTE_POS_CP_MODE_LFR_SET, requestedMode ); |
|
181 | 181 | } |
|
182 | ||
|
182 | 183 | else // the mode value is valid, check the transition |
|
183 | 184 | { |
|
184 | 185 | status = check_mode_transition(requestedMode); |
|
185 | 186 | if (status != LFR_SUCCESSFUL) |
|
186 | 187 | { |
|
187 | 188 | PRINTF("ERR *** in action_enter_mode *** check_mode_transition\n") |
|
188 | 189 | send_tm_lfr_tc_exe_not_executable( TC, queue_id ); |
|
189 | 190 | } |
|
190 | 191 | } |
|
191 | 192 | |
|
192 | 193 | if ( status == LFR_SUCCESSFUL ) // the transition is valid, check the date |
|
193 | 194 | { |
|
194 | 195 | status = check_transition_date( transitionCoarseTime ); |
|
195 | 196 | if (status != LFR_SUCCESSFUL) |
|
196 | 197 | { |
|
197 | 198 | PRINTF("ERR *** in action_enter_mode *** check_transition_date\n") |
|
198 | 199 | send_tm_lfr_tc_exe_inconsistent( TC, queue_id, |
|
199 | 200 | BYTE_POS_CP_LFR_ENTER_MODE_TIME, |
|
200 | 201 | bytePosPtr[ BYTE_POS_CP_LFR_ENTER_MODE_TIME + 3 ] ); |
|
201 | 202 | } |
|
202 | 203 | } |
|
203 | 204 | |
|
204 | 205 | if ( status == LFR_SUCCESSFUL ) // the date is valid, enter the mode |
|
205 | 206 | { |
|
206 | 207 | PRINTF1("OK *** in action_enter_mode *** enter mode %d\n", requestedMode); |
|
207 | 208 | |
|
209 | ||
|
210 | ||
|
208 | 211 | switch(requestedMode) |
|
209 | 212 | { |
|
210 | 213 | case LFR_MODE_STANDBY: |
|
211 | 214 | status = enter_mode_standby(); |
|
212 | 215 | break; |
|
213 | 216 | case LFR_MODE_NORMAL: |
|
214 | 217 | status = enter_mode_normal( transitionCoarseTime ); |
|
215 | 218 | break; |
|
216 | 219 | case LFR_MODE_BURST: |
|
217 | 220 | status = enter_mode_burst( transitionCoarseTime ); |
|
218 | 221 | break; |
|
219 | 222 | case LFR_MODE_SBM1: |
|
220 | 223 | status = enter_mode_sbm1( transitionCoarseTime ); |
|
221 | 224 | break; |
|
222 | 225 | case LFR_MODE_SBM2: |
|
223 | 226 | status = enter_mode_sbm2( transitionCoarseTime ); |
|
224 | 227 | break; |
|
225 | 228 | default: |
|
226 | 229 | break; |
|
227 | 230 | } |
|
228 | 231 | } |
|
229 | 232 | |
|
230 | 233 | return status; |
|
231 | 234 | } |
|
232 | 235 | |
|
233 | 236 | int action_update_info(ccsdsTelecommandPacket_t *TC, rtems_id queue_id) |
|
234 | 237 | { |
|
235 | 238 | /** This function executes specific actions when a TC_LFR_UPDATE_INFO TeleCommand has been received. |
|
236 | 239 | * |
|
237 | 240 | * @param TC points to the TeleCommand packet that is being processed |
|
238 | 241 | * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver |
|
239 | 242 | * |
|
240 | 243 | * @return LFR directive status code: |
|
241 | 244 | * - LFR_DEFAULT |
|
242 | 245 | * - LFR_SUCCESSFUL |
|
243 | 246 | * |
|
244 | 247 | */ |
|
245 | 248 | |
|
246 | 249 | unsigned int val; |
|
247 | 250 | int result; |
|
248 | 251 | unsigned int status; |
|
249 | 252 | unsigned char mode; |
|
250 | 253 | unsigned char * bytePosPtr; |
|
251 | 254 | |
|
252 | 255 | bytePosPtr = (unsigned char *) &TC->packetID; |
|
253 | 256 | |
|
254 | 257 | // check LFR mode |
|
255 | 258 | mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET5 ] & 0x1e) >> 1; |
|
256 | 259 | status = check_update_info_hk_lfr_mode( mode ); |
|
257 | 260 | if (status == LFR_SUCCESSFUL) // check TDS mode |
|
258 | 261 | { |
|
259 | 262 | mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & 0xf0) >> 4; |
|
260 | 263 | status = check_update_info_hk_tds_mode( mode ); |
|
261 | 264 | } |
|
262 | 265 | if (status == LFR_SUCCESSFUL) // check THR mode |
|
263 | 266 | { |
|
264 | 267 | mode = (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 ] & 0x0f); |
|
265 | 268 | status = check_update_info_hk_thr_mode( mode ); |
|
266 | 269 | } |
|
267 | 270 | if (status == LFR_SUCCESSFUL) // if the parameter check is successful |
|
268 | 271 | { |
|
269 | 272 | val = housekeeping_packet.hk_lfr_update_info_tc_cnt[0] * 256 |
|
270 | 273 | + housekeeping_packet.hk_lfr_update_info_tc_cnt[1]; |
|
271 | 274 | val++; |
|
272 | 275 | housekeeping_packet.hk_lfr_update_info_tc_cnt[0] = (unsigned char) (val >> 8); |
|
273 | 276 | housekeeping_packet.hk_lfr_update_info_tc_cnt[1] = (unsigned char) (val); |
|
274 | 277 | } |
|
275 | 278 | |
|
276 | 279 | // pa_bia_status_info |
|
277 | 280 | // => pa_bia_mode_mux_set 3 bits |
|
278 | 281 | // => pa_bia_mode_hv_enabled 1 bit |
|
279 | 282 | // => pa_bia_mode_bias1_enabled 1 bit |
|
280 | 283 | // => pa_bia_mode_bias2_enabled 1 bit |
|
281 | 284 | // => pa_bia_mode_bias3_enabled 1 bit |
|
282 | 285 | // => pa_bia_on_off (cp_dpu_bias_on_off) |
|
283 | 286 | pa_bia_status_info = bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET2 ] & 0xfe; // [1111 1110] |
|
284 | 287 | pa_bia_status_info = pa_bia_status_info |
|
285 | 288 | | (bytePosPtr[ BYTE_POS_UPDATE_INFO_PARAMETERS_SET1 ] & 0x1); |
|
286 | 289 | |
|
287 | 290 | result = status; |
|
288 | 291 | |
|
289 | 292 | return result; |
|
290 | 293 | } |
|
291 | 294 | |
|
292 | 295 | int action_enable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) |
|
293 | 296 | { |
|
294 | 297 | /** This function executes specific actions when a TC_LFR_ENABLE_CALIBRATION TeleCommand has been received. |
|
295 | 298 | * |
|
296 | 299 | * @param TC points to the TeleCommand packet that is being processed |
|
297 | 300 | * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver |
|
298 | 301 | * |
|
299 | 302 | */ |
|
300 | 303 | |
|
301 | 304 | int result; |
|
302 | 305 | |
|
303 | 306 | result = LFR_DEFAULT; |
|
304 | 307 | |
|
305 | 308 | setCalibration( true ); |
|
306 | 309 | |
|
307 | 310 | result = LFR_SUCCESSFUL; |
|
308 | 311 | |
|
309 | 312 | return result; |
|
310 | 313 | } |
|
311 | 314 | |
|
312 | 315 | int action_disable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) |
|
313 | 316 | { |
|
314 | 317 | /** This function executes specific actions when a TC_LFR_DISABLE_CALIBRATION TeleCommand has been received. |
|
315 | 318 | * |
|
316 | 319 | * @param TC points to the TeleCommand packet that is being processed |
|
317 | 320 | * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver |
|
318 | 321 | * |
|
319 | 322 | */ |
|
320 | 323 | |
|
321 | 324 | int result; |
|
322 | 325 | |
|
323 | 326 | result = LFR_DEFAULT; |
|
324 | 327 | |
|
325 | 328 | setCalibration( false ); |
|
326 | 329 | |
|
327 | 330 | result = LFR_SUCCESSFUL; |
|
328 | 331 | |
|
329 | 332 | return result; |
|
330 | 333 | } |
|
331 | 334 | |
|
332 | 335 | int action_update_time(ccsdsTelecommandPacket_t *TC) |
|
333 | 336 | { |
|
334 | 337 | /** This function executes specific actions when a TC_LFR_UPDATE_TIME TeleCommand has been received. |
|
335 | 338 | * |
|
336 | 339 | * @param TC points to the TeleCommand packet that is being processed |
|
337 | 340 | * @param queue_id is the id of the queue which handles TM transmission by the SpaceWire driver |
|
338 | 341 | * |
|
339 | 342 | * @return LFR_SUCCESSFUL |
|
340 | 343 | * |
|
341 | 344 | */ |
|
342 | 345 | |
|
343 | 346 | unsigned int val; |
|
344 | 347 | |
|
345 | 348 | time_management_regs->coarse_time_load = (TC->dataAndCRC[0] << 24) |
|
346 | 349 | + (TC->dataAndCRC[1] << 16) |
|
347 | 350 | + (TC->dataAndCRC[2] << 8) |
|
348 | 351 | + TC->dataAndCRC[3]; |
|
349 | 352 | |
|
350 | 353 | val = housekeeping_packet.hk_lfr_update_time_tc_cnt[0] * 256 |
|
351 | 354 | + housekeeping_packet.hk_lfr_update_time_tc_cnt[1]; |
|
352 | 355 | val++; |
|
353 | 356 | housekeeping_packet.hk_lfr_update_time_tc_cnt[0] = (unsigned char) (val >> 8); |
|
354 | 357 | housekeeping_packet.hk_lfr_update_time_tc_cnt[1] = (unsigned char) (val); |
|
355 | 358 | |
|
356 | 359 | return LFR_SUCCESSFUL; |
|
357 | 360 | } |
|
358 | 361 | |
|
359 | 362 | //******************* |
|
360 | 363 | // ENTERING THE MODES |
|
361 | 364 | int check_mode_value( unsigned char requestedMode ) |
|
362 | 365 | { |
|
363 | 366 | int status; |
|
364 | 367 | |
|
365 | 368 | if ( (requestedMode != LFR_MODE_STANDBY) |
|
366 | 369 | && (requestedMode != LFR_MODE_NORMAL) && (requestedMode != LFR_MODE_BURST) |
|
367 | 370 | && (requestedMode != LFR_MODE_SBM1) && (requestedMode != LFR_MODE_SBM2) ) |
|
368 | 371 | { |
|
369 | 372 | status = LFR_DEFAULT; |
|
370 | 373 | } |
|
371 | 374 | else |
|
372 | 375 | { |
|
373 | 376 | status = LFR_SUCCESSFUL; |
|
374 | 377 | } |
|
375 | 378 | |
|
376 | 379 | return status; |
|
377 | 380 | } |
|
378 | 381 | |
|
379 | 382 | int check_mode_transition( unsigned char requestedMode ) |
|
380 | 383 | { |
|
381 | 384 | /** This function checks the validity of the transition requested by the TC_LFR_ENTER_MODE. |
|
382 | 385 | * |
|
383 | 386 | * @param requestedMode is the mode requested by the TC_LFR_ENTER_MODE |
|
384 | 387 | * |
|
385 | 388 | * @return LFR directive status codes: |
|
386 | 389 | * - LFR_SUCCESSFUL - the transition is authorized |
|
387 | 390 | * - LFR_DEFAULT - the transition is not authorized |
|
388 | 391 | * |
|
389 | 392 | */ |
|
390 | 393 | |
|
391 | 394 | int status; |
|
392 | 395 | |
|
393 | 396 | switch (requestedMode) |
|
394 | 397 | { |
|
395 | 398 | case LFR_MODE_STANDBY: |
|
396 | 399 | if ( lfrCurrentMode == LFR_MODE_STANDBY ) { |
|
397 | 400 | status = LFR_DEFAULT; |
|
398 | 401 | } |
|
399 | 402 | else |
|
400 | 403 | { |
|
401 | 404 | status = LFR_SUCCESSFUL; |
|
402 | 405 | } |
|
403 | 406 | break; |
|
404 | 407 | case LFR_MODE_NORMAL: |
|
405 | 408 | if ( lfrCurrentMode == LFR_MODE_NORMAL ) { |
|
406 | 409 | status = LFR_DEFAULT; |
|
407 | 410 | } |
|
408 | 411 | else { |
|
409 | 412 | status = LFR_SUCCESSFUL; |
|
410 | 413 | } |
|
411 | 414 | break; |
|
412 | 415 | case LFR_MODE_BURST: |
|
413 | 416 | if ( lfrCurrentMode == LFR_MODE_BURST ) { |
|
414 | 417 | status = LFR_DEFAULT; |
|
415 | 418 | } |
|
416 | 419 | else { |
|
417 | 420 | status = LFR_SUCCESSFUL; |
|
418 | 421 | } |
|
419 | 422 | break; |
|
420 | 423 | case LFR_MODE_SBM1: |
|
421 | 424 | if ( lfrCurrentMode == LFR_MODE_SBM1 ) { |
|
422 | 425 | status = LFR_DEFAULT; |
|
423 | 426 | } |
|
424 | 427 | else { |
|
425 | 428 | status = LFR_SUCCESSFUL; |
|
426 | 429 | } |
|
427 | 430 | break; |
|
428 | 431 | case LFR_MODE_SBM2: |
|
429 | 432 | if ( lfrCurrentMode == LFR_MODE_SBM2 ) { |
|
430 | 433 | status = LFR_DEFAULT; |
|
431 | 434 | } |
|
432 | 435 | else { |
|
433 | 436 | status = LFR_SUCCESSFUL; |
|
434 | 437 | } |
|
435 | 438 | break; |
|
436 | 439 | default: |
|
437 | 440 | status = LFR_DEFAULT; |
|
438 | 441 | break; |
|
439 | 442 | } |
|
440 | 443 | |
|
441 | 444 | return status; |
|
442 | 445 | } |
|
443 | 446 | |
|
447 | void update_last_valid_transition_date(unsigned int transitionCoarseTime) | |
|
448 | { | |
|
449 | lastValidTransitionDate = transitionCoarseTime; | |
|
450 | } | |
|
451 | ||
|
444 | 452 | int check_transition_date( unsigned int transitionCoarseTime ) |
|
445 | 453 | { |
|
446 | 454 | int status; |
|
447 | 455 | unsigned int localCoarseTime; |
|
448 | 456 | unsigned int deltaCoarseTime; |
|
449 | 457 | |
|
450 | 458 | status = LFR_SUCCESSFUL; |
|
451 | 459 | |
|
452 | 460 | if (transitionCoarseTime == 0) // transition time = 0 means an instant transition |
|
453 | 461 | { |
|
454 | 462 | status = LFR_SUCCESSFUL; |
|
455 | 463 | } |
|
456 | 464 | else |
|
457 | 465 | { |
|
458 | 466 | localCoarseTime = time_management_regs->coarse_time & 0x7fffffff; |
|
459 | 467 | |
|
460 | 468 | PRINTF2("localTime = %x, transitionTime = %x\n", localCoarseTime, transitionCoarseTime) |
|
461 | 469 | |
|
462 | 470 | if ( transitionCoarseTime <= localCoarseTime ) // SSS-CP-EQS-322 |
|
463 | 471 | { |
|
464 | 472 | status = LFR_DEFAULT; |
|
465 | 473 | PRINTF("ERR *** in check_transition_date *** transitionCoarseTime <= localCoarseTime\n") |
|
466 | 474 | } |
|
467 | 475 | |
|
468 | 476 | if (status == LFR_SUCCESSFUL) |
|
469 | 477 | { |
|
470 | 478 | deltaCoarseTime = transitionCoarseTime - localCoarseTime; |
|
471 | 479 | if ( deltaCoarseTime > 3 ) // SSS-CP-EQS-323 |
|
472 | 480 | { |
|
473 | 481 | status = LFR_DEFAULT; |
|
474 | 482 | PRINTF1("ERR *** in check_transition_date *** deltaCoarseTime = %x\n", deltaCoarseTime) |
|
475 | 483 | } |
|
476 | 484 | } |
|
477 | 485 | } |
|
478 | 486 | |
|
479 | 487 | return status; |
|
480 | 488 | } |
|
481 | 489 | |
|
482 | 490 | int restart_asm_activities( unsigned char lfrRequestedMode ) |
|
483 | 491 | { |
|
484 | 492 | rtems_status_code status; |
|
485 | 493 | |
|
486 | 494 | status = stop_spectral_matrices(); |
|
487 | 495 | |
|
488 | 496 | status = restart_asm_tasks( lfrRequestedMode ); |
|
489 | 497 | |
|
490 | 498 | launch_spectral_matrix(); |
|
491 | 499 | |
|
492 | 500 | return status; |
|
493 | 501 | } |
|
494 | 502 | |
|
495 | 503 | int stop_spectral_matrices( void ) |
|
496 | 504 | { |
|
497 | 505 | /** This function stops and restarts the current mode average spectral matrices activities. |
|
498 | 506 | * |
|
499 | 507 | * @return RTEMS directive status codes: |
|
500 | 508 | * - RTEMS_SUCCESSFUL - task restarted successfully |
|
501 | 509 | * - RTEMS_INVALID_ID - task id invalid |
|
502 | 510 | * - RTEMS_ALREADY_SUSPENDED - task already suspended |
|
503 | 511 | * |
|
504 | 512 | */ |
|
505 | 513 | |
|
506 | 514 | rtems_status_code status; |
|
507 | 515 | |
|
508 | 516 | status = RTEMS_SUCCESSFUL; |
|
509 | 517 | |
|
510 | 518 | // (1) mask interruptions |
|
511 | 519 | LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt |
|
512 | 520 | |
|
513 | 521 | // (2) reset spectral matrices registers |
|
514 | 522 | set_sm_irq_onNewMatrix( 0 ); // stop the spectral matrices |
|
515 | 523 | reset_sm_status(); |
|
516 | 524 | |
|
517 | 525 | // (3) clear interruptions |
|
518 | 526 | LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt |
|
519 | 527 | |
|
520 | 528 | // suspend several tasks |
|
521 | 529 | if (lfrCurrentMode != LFR_MODE_STANDBY) { |
|
522 | 530 | status = suspend_asm_tasks(); |
|
523 | 531 | } |
|
524 | 532 | |
|
525 | 533 | if (status != RTEMS_SUCCESSFUL) |
|
526 | 534 | { |
|
527 | 535 | PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status) |
|
528 | 536 | } |
|
529 | 537 | |
|
530 | 538 | return status; |
|
531 | 539 | } |
|
532 | 540 | |
|
533 | 541 | int stop_current_mode( void ) |
|
534 | 542 | { |
|
535 | 543 | /** This function stops the current mode by masking interrupt lines and suspending science tasks. |
|
536 | 544 | * |
|
537 | 545 | * @return RTEMS directive status codes: |
|
538 | 546 | * - RTEMS_SUCCESSFUL - task restarted successfully |
|
539 | 547 | * - RTEMS_INVALID_ID - task id invalid |
|
540 | 548 | * - RTEMS_ALREADY_SUSPENDED - task already suspended |
|
541 | 549 | * |
|
542 | 550 | */ |
|
543 | 551 | |
|
544 | 552 | rtems_status_code status; |
|
545 | 553 | |
|
546 | 554 | status = RTEMS_SUCCESSFUL; |
|
547 | 555 | |
|
548 | 556 | // (1) mask interruptions |
|
549 | 557 | LEON_Mask_interrupt( IRQ_WAVEFORM_PICKER ); // mask waveform picker interrupt |
|
550 | 558 | LEON_Mask_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt |
|
551 | 559 | |
|
552 | 560 | // (2) reset waveform picker registers |
|
553 | 561 | reset_wfp_burst_enable(); // reset burst and enable bits |
|
554 | 562 | reset_wfp_status(); // reset all the status bits |
|
555 | 563 | |
|
556 | 564 | // (3) reset spectral matrices registers |
|
557 | 565 | set_sm_irq_onNewMatrix( 0 ); // stop the spectral matrices |
|
558 | 566 | reset_sm_status(); |
|
559 | 567 | |
|
560 | 568 | // reset lfr VHDL module |
|
561 | 569 | reset_lfr(); |
|
562 | 570 | |
|
563 | 571 | reset_extractSWF(); // reset the extractSWF flag to false |
|
564 | 572 | |
|
565 | 573 | // (4) clear interruptions |
|
566 | 574 | LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER ); // clear waveform picker interrupt |
|
567 | 575 | LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); // clear spectral matrix interrupt |
|
568 | 576 | |
|
569 | 577 | // suspend several tasks |
|
570 | 578 | if (lfrCurrentMode != LFR_MODE_STANDBY) { |
|
571 | 579 | status = suspend_science_tasks(); |
|
572 | 580 | } |
|
573 | 581 | |
|
574 | 582 | if (status != RTEMS_SUCCESSFUL) |
|
575 | 583 | { |
|
576 | 584 | PRINTF1("in stop_current_mode *** in suspend_science_tasks *** ERR code: %d\n", status) |
|
577 | 585 | } |
|
578 | 586 | |
|
579 | 587 | return status; |
|
580 | 588 | } |
|
581 | 589 | |
|
582 | 590 | int enter_mode_standby() |
|
583 | 591 | { |
|
592 | /** This function is used to put LFR in the STANDBY mode. | |
|
593 | * | |
|
594 | * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE | |
|
595 | * | |
|
596 | * @return RTEMS directive status codes: | |
|
597 | * - RTEMS_SUCCESSFUL - task restarted successfully | |
|
598 | * - RTEMS_INVALID_ID - task id invalid | |
|
599 | * - RTEMS_INCORRECT_STATE - task never started | |
|
600 | * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task | |
|
601 | * | |
|
602 | * The STANDBY mode does not depends on a specific transition date, the effect of the TC_LFR_ENTER_MODE | |
|
603 | * is immediate. | |
|
604 | * | |
|
605 | */ | |
|
606 | ||
|
584 | 607 | int status; |
|
585 | 608 | |
|
586 | 609 | status = stop_current_mode(); // STOP THE CURRENT MODE |
|
587 | 610 | |
|
588 | 611 | #ifdef PRINT_TASK_STATISTICS |
|
589 | 612 | rtems_cpu_usage_report(); |
|
590 | 613 | #endif |
|
591 | 614 | |
|
592 | 615 | #ifdef PRINT_STACK_REPORT |
|
593 | 616 | PRINTF("stack report selected\n") |
|
594 | 617 | rtems_stack_checker_report_usage(); |
|
595 | 618 | #endif |
|
596 | 619 | |
|
597 | 620 | return status; |
|
598 | 621 | } |
|
599 | 622 | |
|
600 | 623 | int enter_mode_normal( unsigned int transitionCoarseTime ) |
|
601 | 624 | { |
|
625 | /** This function is used to start the NORMAL mode. | |
|
626 | * | |
|
627 | * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE | |
|
628 | * | |
|
629 | * @return RTEMS directive status codes: | |
|
630 | * - RTEMS_SUCCESSFUL - task restarted successfully | |
|
631 | * - RTEMS_INVALID_ID - task id invalid | |
|
632 | * - RTEMS_INCORRECT_STATE - task never started | |
|
633 | * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task | |
|
634 | * | |
|
635 | * The way the NORMAL mode is started depends on the LFR current mode. If LFR is in SBM1 or SBM2, | |
|
636 | * the snapshots are not restarted, only ASM, BP and CWF data generation are affected. | |
|
637 | * | |
|
638 | */ | |
|
639 | ||
|
602 | 640 | int status; |
|
603 | 641 | |
|
604 | 642 | #ifdef PRINT_TASK_STATISTICS |
|
605 | 643 | rtems_cpu_usage_reset(); |
|
606 | 644 | #endif |
|
607 | 645 | |
|
608 | 646 | status = RTEMS_UNSATISFIED; |
|
609 | 647 | |
|
610 | 648 | switch( lfrCurrentMode ) |
|
611 | 649 | { |
|
612 | 650 | case LFR_MODE_STANDBY: |
|
613 | 651 | status = restart_science_tasks( LFR_MODE_NORMAL ); // restart science tasks |
|
614 | 652 | if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules |
|
615 | 653 | { |
|
616 | 654 | launch_spectral_matrix( ); |
|
617 | 655 | launch_waveform_picker( LFR_MODE_NORMAL, transitionCoarseTime ); |
|
618 | 656 | } |
|
619 | 657 | break; |
|
620 | 658 | case LFR_MODE_BURST: |
|
621 | 659 | status = stop_current_mode(); // stop the current mode |
|
622 | 660 | status = restart_science_tasks( LFR_MODE_NORMAL ); // restart the science tasks |
|
623 | 661 | if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules |
|
624 | 662 | { |
|
625 | 663 | launch_spectral_matrix( ); |
|
626 | 664 | launch_waveform_picker( LFR_MODE_NORMAL, transitionCoarseTime ); |
|
627 | 665 | } |
|
628 | 666 | break; |
|
629 | 667 | case LFR_MODE_SBM1: |
|
630 | restart_asm_activities( LFR_MODE_NORMAL ); | |
|
631 | status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action | |
|
668 | restart_asm_activities( LFR_MODE_NORMAL ); // this is necessary to restart ASM tasks to update the parameters | |
|
669 | status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action | |
|
632 | 670 | break; |
|
633 | 671 | case LFR_MODE_SBM2: |
|
634 | restart_asm_activities( LFR_MODE_NORMAL ); | |
|
635 | status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action | |
|
672 | restart_asm_activities( LFR_MODE_NORMAL ); // this is necessary to restart ASM tasks to update the parameters | |
|
673 | status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action | |
|
636 | 674 | break; |
|
637 | 675 | default: |
|
638 | 676 | break; |
|
639 | 677 | } |
|
640 | 678 | |
|
641 | 679 | if (status != RTEMS_SUCCESSFUL) |
|
642 | 680 | { |
|
643 | 681 | PRINTF1("ERR *** in enter_mode_normal *** status = %d\n", status) |
|
644 | 682 | status = RTEMS_UNSATISFIED; |
|
645 | 683 | } |
|
646 | 684 | |
|
647 | 685 | return status; |
|
648 | 686 | } |
|
649 | 687 | |
|
650 | 688 | int enter_mode_burst( unsigned int transitionCoarseTime ) |
|
651 | 689 | { |
|
690 | /** This function is used to start the BURST mode. | |
|
691 | * | |
|
692 | * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE | |
|
693 | * | |
|
694 | * @return RTEMS directive status codes: | |
|
695 | * - RTEMS_SUCCESSFUL - task restarted successfully | |
|
696 | * - RTEMS_INVALID_ID - task id invalid | |
|
697 | * - RTEMS_INCORRECT_STATE - task never started | |
|
698 | * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task | |
|
699 | * | |
|
700 | * The way the BURST mode is started does not depend on the LFR current mode. | |
|
701 | * | |
|
702 | */ | |
|
703 | ||
|
704 | ||
|
652 | 705 | int status; |
|
653 | 706 | |
|
654 | 707 | #ifdef PRINT_TASK_STATISTICS |
|
655 | 708 | rtems_cpu_usage_reset(); |
|
656 | 709 | #endif |
|
657 | 710 | |
|
658 | 711 | status = stop_current_mode(); // stop the current mode |
|
659 | 712 | status = restart_science_tasks( LFR_MODE_BURST ); // restart the science tasks |
|
660 | 713 | if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules |
|
661 | 714 | { |
|
662 | 715 | launch_spectral_matrix( ); |
|
663 | 716 | launch_waveform_picker( LFR_MODE_BURST, transitionCoarseTime ); |
|
664 | 717 | } |
|
665 | 718 | |
|
666 | 719 | if (status != RTEMS_SUCCESSFUL) |
|
667 | 720 | { |
|
668 | 721 | PRINTF1("ERR *** in enter_mode_burst *** status = %d\n", status) |
|
669 | 722 | status = RTEMS_UNSATISFIED; |
|
670 | 723 | } |
|
671 | 724 | |
|
672 | 725 | return status; |
|
673 | 726 | } |
|
674 | 727 | |
|
675 | 728 | int enter_mode_sbm1( unsigned int transitionCoarseTime ) |
|
676 | 729 | { |
|
730 | /** This function is used to start the SBM1 mode. | |
|
731 | * | |
|
732 | * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE | |
|
733 | * | |
|
734 | * @return RTEMS directive status codes: | |
|
735 | * - RTEMS_SUCCESSFUL - task restarted successfully | |
|
736 | * - RTEMS_INVALID_ID - task id invalid | |
|
737 | * - RTEMS_INCORRECT_STATE - task never started | |
|
738 | * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task | |
|
739 | * | |
|
740 | * The way the SBM1 mode is started depends on the LFR current mode. If LFR is in NORMAL or SBM2, | |
|
741 | * the snapshots are not restarted, only ASM, BP and CWF data generation are affected. In other | |
|
742 | * cases, the acquisition is completely restarted. | |
|
743 | * | |
|
744 | */ | |
|
745 | ||
|
677 | 746 | int status; |
|
678 | 747 | |
|
679 | 748 | #ifdef PRINT_TASK_STATISTICS |
|
680 | 749 | rtems_cpu_usage_reset(); |
|
681 | 750 | #endif |
|
682 | 751 | |
|
683 | 752 | status = RTEMS_UNSATISFIED; |
|
684 | 753 | |
|
685 | 754 | switch( lfrCurrentMode ) |
|
686 | 755 | { |
|
687 | 756 | case LFR_MODE_STANDBY: |
|
688 | 757 | status = restart_science_tasks( LFR_MODE_SBM1 ); // restart science tasks |
|
689 | 758 | if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules |
|
690 | 759 | { |
|
691 | 760 | launch_spectral_matrix( ); |
|
692 | 761 | launch_waveform_picker( LFR_MODE_SBM1, transitionCoarseTime ); |
|
693 | 762 | } |
|
694 | 763 | break; |
|
695 | 764 | case LFR_MODE_NORMAL: // lfrCurrentMode will be updated after the execution of close_action |
|
696 | 765 | restart_asm_activities( LFR_MODE_SBM1 ); |
|
697 | 766 | status = LFR_SUCCESSFUL; |
|
698 | 767 | break; |
|
699 | 768 | case LFR_MODE_BURST: |
|
700 | 769 | status = stop_current_mode(); // stop the current mode |
|
701 | 770 | status = restart_science_tasks( LFR_MODE_SBM1 ); // restart the science tasks |
|
702 | 771 | if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules |
|
703 | 772 | { |
|
704 | 773 | launch_spectral_matrix( ); |
|
705 | 774 | launch_waveform_picker( LFR_MODE_SBM1, transitionCoarseTime ); |
|
706 | 775 | } |
|
707 | 776 | break; |
|
708 | 777 | case LFR_MODE_SBM2: |
|
709 | 778 | restart_asm_activities( LFR_MODE_SBM1 ); |
|
710 | 779 | status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action |
|
711 | 780 | break; |
|
712 | 781 | default: |
|
713 | 782 | break; |
|
714 | 783 | } |
|
715 | 784 | |
|
716 | 785 | if (status != RTEMS_SUCCESSFUL) |
|
717 | 786 | { |
|
718 | 787 | PRINTF1("ERR *** in enter_mode_sbm1 *** status = %d\n", status) |
|
719 | 788 | status = RTEMS_UNSATISFIED; |
|
720 | 789 | } |
|
721 | 790 | |
|
722 | 791 | return status; |
|
723 | 792 | } |
|
724 | 793 | |
|
725 | 794 | int enter_mode_sbm2( unsigned int transitionCoarseTime ) |
|
726 | 795 | { |
|
796 | /** This function is used to start the SBM2 mode. | |
|
797 | * | |
|
798 | * @param transitionCoarseTime is the requested transition time contained in the TC_LFR_ENTER_MODE | |
|
799 | * | |
|
800 | * @return RTEMS directive status codes: | |
|
801 | * - RTEMS_SUCCESSFUL - task restarted successfully | |
|
802 | * - RTEMS_INVALID_ID - task id invalid | |
|
803 | * - RTEMS_INCORRECT_STATE - task never started | |
|
804 | * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task | |
|
805 | * | |
|
806 | * The way the SBM2 mode is started depends on the LFR current mode. If LFR is in NORMAL or SBM1, | |
|
807 | * the snapshots are not restarted, only ASM, BP and CWF data generation are affected. In other | |
|
808 | * cases, the acquisition is completely restarted. | |
|
809 | * | |
|
810 | */ | |
|
811 | ||
|
727 | 812 | int status; |
|
728 | 813 | |
|
729 | 814 | #ifdef PRINT_TASK_STATISTICS |
|
730 | 815 | rtems_cpu_usage_reset(); |
|
731 | 816 | #endif |
|
732 | 817 | |
|
733 | 818 | status = RTEMS_UNSATISFIED; |
|
734 | 819 | |
|
735 | 820 | switch( lfrCurrentMode ) |
|
736 | 821 | { |
|
737 | 822 | case LFR_MODE_STANDBY: |
|
738 | 823 | status = restart_science_tasks( LFR_MODE_SBM2 ); // restart science tasks |
|
739 | 824 | if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules |
|
740 | 825 | { |
|
741 | 826 | launch_spectral_matrix( ); |
|
742 | 827 | launch_waveform_picker( LFR_MODE_SBM2, transitionCoarseTime ); |
|
743 | 828 | } |
|
744 | 829 | break; |
|
745 | 830 | case LFR_MODE_NORMAL: |
|
746 | 831 | restart_asm_activities( LFR_MODE_SBM2 ); |
|
747 | 832 | status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action |
|
748 | 833 | break; |
|
749 | 834 | case LFR_MODE_BURST: |
|
750 | 835 | status = stop_current_mode(); // stop the current mode |
|
751 | 836 | status = restart_science_tasks( LFR_MODE_SBM2 ); // restart the science tasks |
|
752 | 837 | if (status == RTEMS_SUCCESSFUL) // relaunch spectral_matrix and waveform_picker modules |
|
753 | 838 | { |
|
754 | 839 | launch_spectral_matrix( ); |
|
755 | 840 | launch_waveform_picker( LFR_MODE_SBM2, transitionCoarseTime ); |
|
756 | 841 | } |
|
757 | 842 | break; |
|
758 | 843 | case LFR_MODE_SBM1: |
|
759 | 844 | restart_asm_activities( LFR_MODE_SBM2 ); |
|
760 | 845 | status = LFR_SUCCESSFUL; // lfrCurrentMode will be updated after the execution of close_action |
|
761 | 846 | break; |
|
762 | 847 | default: |
|
763 | 848 | break; |
|
764 | 849 | } |
|
765 | 850 | |
|
766 | 851 | if (status != RTEMS_SUCCESSFUL) |
|
767 | 852 | { |
|
768 | 853 | PRINTF1("ERR *** in enter_mode_sbm2 *** status = %d\n", status) |
|
769 | 854 | status = RTEMS_UNSATISFIED; |
|
770 | 855 | } |
|
771 | 856 | |
|
772 | 857 | return status; |
|
773 | 858 | } |
|
774 | 859 | |
|
775 | 860 | int restart_science_tasks( unsigned char lfrRequestedMode ) |
|
776 | 861 | { |
|
777 | 862 | /** This function is used to restart all science tasks. |
|
778 | 863 | * |
|
779 | 864 | * @return RTEMS directive status codes: |
|
780 | 865 | * - RTEMS_SUCCESSFUL - task restarted successfully |
|
781 | 866 | * - RTEMS_INVALID_ID - task id invalid |
|
782 | 867 | * - RTEMS_INCORRECT_STATE - task never started |
|
783 | 868 | * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task |
|
784 | 869 | * |
|
785 | 870 | * Science tasks are AVF0, PRC0, WFRM, CWF3, CW2, CWF1 |
|
786 | 871 | * |
|
787 | 872 | */ |
|
788 | 873 | |
|
789 | 874 | rtems_status_code status[10]; |
|
790 | 875 | rtems_status_code ret; |
|
791 | 876 | |
|
792 | 877 | ret = RTEMS_SUCCESSFUL; |
|
793 | 878 | |
|
794 | 879 | status[0] = rtems_task_restart( Task_id[TASKID_AVF0], lfrRequestedMode ); |
|
795 | 880 | if (status[0] != RTEMS_SUCCESSFUL) |
|
796 | 881 | { |
|
797 | 882 | PRINTF1("in restart_science_task *** AVF0 ERR %d\n", status[0]) |
|
798 | 883 | } |
|
799 | 884 | |
|
800 | 885 | status[1] = rtems_task_restart( Task_id[TASKID_PRC0], lfrRequestedMode ); |
|
801 | 886 | if (status[1] != RTEMS_SUCCESSFUL) |
|
802 | 887 | { |
|
803 | 888 | PRINTF1("in restart_science_task *** PRC0 ERR %d\n", status[1]) |
|
804 | 889 | } |
|
805 | 890 | |
|
806 | 891 | status[2] = rtems_task_restart( Task_id[TASKID_WFRM],1 ); |
|
807 | 892 | if (status[2] != RTEMS_SUCCESSFUL) |
|
808 | 893 | { |
|
809 | 894 | PRINTF1("in restart_science_task *** WFRM ERR %d\n", status[2]) |
|
810 | 895 | } |
|
811 | 896 | |
|
812 | 897 | status[3] = rtems_task_restart( Task_id[TASKID_CWF3],1 ); |
|
813 | 898 | if (status[3] != RTEMS_SUCCESSFUL) |
|
814 | 899 | { |
|
815 | 900 | PRINTF1("in restart_science_task *** CWF3 ERR %d\n", status[3]) |
|
816 | 901 | } |
|
817 | 902 | |
|
818 | 903 | status[4] = rtems_task_restart( Task_id[TASKID_CWF2],1 ); |
|
819 | 904 | if (status[4] != RTEMS_SUCCESSFUL) |
|
820 | 905 | { |
|
821 | 906 | PRINTF1("in restart_science_task *** CWF2 ERR %d\n", status[4]) |
|
822 | 907 | } |
|
823 | 908 | |
|
824 | 909 | status[5] = rtems_task_restart( Task_id[TASKID_CWF1],1 ); |
|
825 | 910 | if (status[5] != RTEMS_SUCCESSFUL) |
|
826 | 911 | { |
|
827 | 912 | PRINTF1("in restart_science_task *** CWF1 ERR %d\n", status[5]) |
|
828 | 913 | } |
|
829 | 914 | |
|
830 | 915 | status[6] = rtems_task_restart( Task_id[TASKID_AVF1], lfrRequestedMode ); |
|
831 | 916 | if (status[6] != RTEMS_SUCCESSFUL) |
|
832 | 917 | { |
|
833 | 918 | PRINTF1("in restart_science_task *** AVF1 ERR %d\n", status[6]) |
|
834 | 919 | } |
|
835 | 920 | |
|
836 | 921 | status[7] = rtems_task_restart( Task_id[TASKID_PRC1],lfrRequestedMode ); |
|
837 | 922 | if (status[7] != RTEMS_SUCCESSFUL) |
|
838 | 923 | { |
|
839 | 924 | PRINTF1("in restart_science_task *** PRC1 ERR %d\n", status[7]) |
|
840 | 925 | } |
|
841 | 926 | |
|
842 | 927 | status[8] = rtems_task_restart( Task_id[TASKID_AVF2], 1 ); |
|
843 | 928 | if (status[8] != RTEMS_SUCCESSFUL) |
|
844 | 929 | { |
|
845 | 930 | PRINTF1("in restart_science_task *** AVF2 ERR %d\n", status[8]) |
|
846 | 931 | } |
|
847 | 932 | |
|
848 | 933 | status[9] = rtems_task_restart( Task_id[TASKID_PRC2], 1 ); |
|
849 | 934 | if (status[9] != RTEMS_SUCCESSFUL) |
|
850 | 935 | { |
|
851 | 936 | PRINTF1("in restart_science_task *** PRC2 ERR %d\n", status[9]) |
|
852 | 937 | } |
|
853 | 938 | |
|
854 | 939 | if ( (status[0] != RTEMS_SUCCESSFUL) || (status[1] != RTEMS_SUCCESSFUL) || |
|
855 | 940 | (status[2] != RTEMS_SUCCESSFUL) || (status[3] != RTEMS_SUCCESSFUL) || |
|
856 | 941 | (status[4] != RTEMS_SUCCESSFUL) || (status[5] != RTEMS_SUCCESSFUL) || |
|
857 | 942 | (status[6] != RTEMS_SUCCESSFUL) || (status[7] != RTEMS_SUCCESSFUL) || |
|
858 | 943 | (status[8] != RTEMS_SUCCESSFUL) || (status[9] != RTEMS_SUCCESSFUL) ) |
|
859 | 944 | { |
|
860 | 945 | ret = RTEMS_UNSATISFIED; |
|
861 | 946 | } |
|
862 | 947 | |
|
863 | 948 | return ret; |
|
864 | 949 | } |
|
865 | 950 | |
|
866 | 951 | int restart_asm_tasks( unsigned char lfrRequestedMode ) |
|
867 | 952 | { |
|
868 | 953 | /** This function is used to restart average spectral matrices tasks. |
|
869 | 954 | * |
|
870 | 955 | * @return RTEMS directive status codes: |
|
871 | 956 | * - RTEMS_SUCCESSFUL - task restarted successfully |
|
872 | 957 | * - RTEMS_INVALID_ID - task id invalid |
|
873 | 958 | * - RTEMS_INCORRECT_STATE - task never started |
|
874 | 959 | * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot restart remote task |
|
875 | 960 | * |
|
876 | 961 | * ASM tasks are AVF0, PRC0, AVF1, PRC1, AVF2 and PRC2 |
|
877 | 962 | * |
|
878 | 963 | */ |
|
879 | 964 | |
|
880 | 965 | rtems_status_code status[6]; |
|
881 | 966 | rtems_status_code ret; |
|
882 | 967 | |
|
883 | 968 | ret = RTEMS_SUCCESSFUL; |
|
884 | 969 | |
|
885 | 970 | status[0] = rtems_task_restart( Task_id[TASKID_AVF0], lfrRequestedMode ); |
|
886 | 971 | if (status[0] != RTEMS_SUCCESSFUL) |
|
887 | 972 | { |
|
888 | 973 | PRINTF1("in restart_science_task *** AVF0 ERR %d\n", status[0]) |
|
889 | 974 | } |
|
890 | 975 | |
|
891 | 976 | status[1] = rtems_task_restart( Task_id[TASKID_PRC0], lfrRequestedMode ); |
|
892 | 977 | if (status[1] != RTEMS_SUCCESSFUL) |
|
893 | 978 | { |
|
894 | 979 | PRINTF1("in restart_science_task *** PRC0 ERR %d\n", status[1]) |
|
895 | 980 | } |
|
896 | 981 | |
|
897 | 982 | status[2] = rtems_task_restart( Task_id[TASKID_AVF1], lfrRequestedMode ); |
|
898 | 983 | if (status[2] != RTEMS_SUCCESSFUL) |
|
899 | 984 | { |
|
900 | 985 | PRINTF1("in restart_science_task *** AVF1 ERR %d\n", status[2]) |
|
901 | 986 | } |
|
902 | 987 | |
|
903 | 988 | status[3] = rtems_task_restart( Task_id[TASKID_PRC1],lfrRequestedMode ); |
|
904 | 989 | if (status[3] != RTEMS_SUCCESSFUL) |
|
905 | 990 | { |
|
906 | 991 | PRINTF1("in restart_science_task *** PRC1 ERR %d\n", status[3]) |
|
907 | 992 | } |
|
908 | 993 | |
|
909 | 994 | status[4] = rtems_task_restart( Task_id[TASKID_AVF2], 1 ); |
|
910 | 995 | if (status[4] != RTEMS_SUCCESSFUL) |
|
911 | 996 | { |
|
912 | 997 | PRINTF1("in restart_science_task *** AVF2 ERR %d\n", status[4]) |
|
913 | 998 | } |
|
914 | 999 | |
|
915 | 1000 | status[5] = rtems_task_restart( Task_id[TASKID_PRC2], 1 ); |
|
916 | 1001 | if (status[5] != RTEMS_SUCCESSFUL) |
|
917 | 1002 | { |
|
918 | 1003 | PRINTF1("in restart_science_task *** PRC2 ERR %d\n", status[5]) |
|
919 | 1004 | } |
|
920 | 1005 | |
|
921 | 1006 | if ( (status[0] != RTEMS_SUCCESSFUL) || (status[1] != RTEMS_SUCCESSFUL) || |
|
922 | 1007 | (status[2] != RTEMS_SUCCESSFUL) || (status[3] != RTEMS_SUCCESSFUL) || |
|
923 | 1008 | (status[4] != RTEMS_SUCCESSFUL) || (status[5] != RTEMS_SUCCESSFUL) ) |
|
924 | 1009 | { |
|
925 | 1010 | ret = RTEMS_UNSATISFIED; |
|
926 | 1011 | } |
|
927 | 1012 | |
|
928 | 1013 | return ret; |
|
929 | 1014 | } |
|
930 | 1015 | |
|
931 | 1016 | int suspend_science_tasks( void ) |
|
932 | 1017 | { |
|
933 | 1018 | /** This function suspends the science tasks. |
|
934 | 1019 | * |
|
935 | 1020 | * @return RTEMS directive status codes: |
|
936 | 1021 | * - RTEMS_SUCCESSFUL - task restarted successfully |
|
937 | 1022 | * - RTEMS_INVALID_ID - task id invalid |
|
938 | 1023 | * - RTEMS_ALREADY_SUSPENDED - task already suspended |
|
939 | 1024 | * |
|
940 | 1025 | */ |
|
941 | 1026 | |
|
942 | 1027 | rtems_status_code status; |
|
943 | 1028 | |
|
944 | 1029 | PRINTF("in suspend_science_tasks\n") |
|
945 | 1030 | |
|
946 | 1031 | status = rtems_task_suspend( Task_id[TASKID_AVF0] ); // suspend AVF0 |
|
947 | 1032 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
948 | 1033 | { |
|
949 | 1034 | PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status) |
|
950 | 1035 | } |
|
951 | 1036 | else |
|
952 | 1037 | { |
|
953 | 1038 | status = RTEMS_SUCCESSFUL; |
|
954 | 1039 | } |
|
955 | 1040 | if (status == RTEMS_SUCCESSFUL) // suspend PRC0 |
|
956 | 1041 | { |
|
957 | 1042 | status = rtems_task_suspend( Task_id[TASKID_PRC0] ); |
|
958 | 1043 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
959 | 1044 | { |
|
960 | 1045 | PRINTF1("in suspend_science_task *** PRC0 ERR %d\n", status) |
|
961 | 1046 | } |
|
962 | 1047 | else |
|
963 | 1048 | { |
|
964 | 1049 | status = RTEMS_SUCCESSFUL; |
|
965 | 1050 | } |
|
966 | 1051 | } |
|
967 | 1052 | if (status == RTEMS_SUCCESSFUL) // suspend AVF1 |
|
968 | 1053 | { |
|
969 | 1054 | status = rtems_task_suspend( Task_id[TASKID_AVF1] ); |
|
970 | 1055 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
971 | 1056 | { |
|
972 | 1057 | PRINTF1("in suspend_science_task *** AVF1 ERR %d\n", status) |
|
973 | 1058 | } |
|
974 | 1059 | else |
|
975 | 1060 | { |
|
976 | 1061 | status = RTEMS_SUCCESSFUL; |
|
977 | 1062 | } |
|
978 | 1063 | } |
|
979 | 1064 | if (status == RTEMS_SUCCESSFUL) // suspend PRC1 |
|
980 | 1065 | { |
|
981 | 1066 | status = rtems_task_suspend( Task_id[TASKID_PRC1] ); |
|
982 | 1067 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
983 | 1068 | { |
|
984 | 1069 | PRINTF1("in suspend_science_task *** PRC1 ERR %d\n", status) |
|
985 | 1070 | } |
|
986 | 1071 | else |
|
987 | 1072 | { |
|
988 | 1073 | status = RTEMS_SUCCESSFUL; |
|
989 | 1074 | } |
|
990 | 1075 | } |
|
991 | 1076 | if (status == RTEMS_SUCCESSFUL) // suspend AVF2 |
|
992 | 1077 | { |
|
993 | 1078 | status = rtems_task_suspend( Task_id[TASKID_AVF2] ); |
|
994 | 1079 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
995 | 1080 | { |
|
996 | 1081 | PRINTF1("in suspend_science_task *** AVF2 ERR %d\n", status) |
|
997 | 1082 | } |
|
998 | 1083 | else |
|
999 | 1084 | { |
|
1000 | 1085 | status = RTEMS_SUCCESSFUL; |
|
1001 | 1086 | } |
|
1002 | 1087 | } |
|
1003 | 1088 | if (status == RTEMS_SUCCESSFUL) // suspend PRC2 |
|
1004 | 1089 | { |
|
1005 | 1090 | status = rtems_task_suspend( Task_id[TASKID_PRC2] ); |
|
1006 | 1091 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1007 | 1092 | { |
|
1008 | 1093 | PRINTF1("in suspend_science_task *** PRC2 ERR %d\n", status) |
|
1009 | 1094 | } |
|
1010 | 1095 | else |
|
1011 | 1096 | { |
|
1012 | 1097 | status = RTEMS_SUCCESSFUL; |
|
1013 | 1098 | } |
|
1014 | 1099 | } |
|
1015 | 1100 | if (status == RTEMS_SUCCESSFUL) // suspend WFRM |
|
1016 | 1101 | { |
|
1017 | 1102 | status = rtems_task_suspend( Task_id[TASKID_WFRM] ); |
|
1018 | 1103 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1019 | 1104 | { |
|
1020 | 1105 | PRINTF1("in suspend_science_task *** WFRM ERR %d\n", status) |
|
1021 | 1106 | } |
|
1022 | 1107 | else |
|
1023 | 1108 | { |
|
1024 | 1109 | status = RTEMS_SUCCESSFUL; |
|
1025 | 1110 | } |
|
1026 | 1111 | } |
|
1027 | 1112 | if (status == RTEMS_SUCCESSFUL) // suspend CWF3 |
|
1028 | 1113 | { |
|
1029 | 1114 | status = rtems_task_suspend( Task_id[TASKID_CWF3] ); |
|
1030 | 1115 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1031 | 1116 | { |
|
1032 | 1117 | PRINTF1("in suspend_science_task *** CWF3 ERR %d\n", status) |
|
1033 | 1118 | } |
|
1034 | 1119 | else |
|
1035 | 1120 | { |
|
1036 | 1121 | status = RTEMS_SUCCESSFUL; |
|
1037 | 1122 | } |
|
1038 | 1123 | } |
|
1039 | 1124 | if (status == RTEMS_SUCCESSFUL) // suspend CWF2 |
|
1040 | 1125 | { |
|
1041 | 1126 | status = rtems_task_suspend( Task_id[TASKID_CWF2] ); |
|
1042 | 1127 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1043 | 1128 | { |
|
1044 | 1129 | PRINTF1("in suspend_science_task *** CWF2 ERR %d\n", status) |
|
1045 | 1130 | } |
|
1046 | 1131 | else |
|
1047 | 1132 | { |
|
1048 | 1133 | status = RTEMS_SUCCESSFUL; |
|
1049 | 1134 | } |
|
1050 | 1135 | } |
|
1051 | 1136 | if (status == RTEMS_SUCCESSFUL) // suspend CWF1 |
|
1052 | 1137 | { |
|
1053 | 1138 | status = rtems_task_suspend( Task_id[TASKID_CWF1] ); |
|
1054 | 1139 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1055 | 1140 | { |
|
1056 | 1141 | PRINTF1("in suspend_science_task *** CWF1 ERR %d\n", status) |
|
1057 | 1142 | } |
|
1058 | 1143 | else |
|
1059 | 1144 | { |
|
1060 | 1145 | status = RTEMS_SUCCESSFUL; |
|
1061 | 1146 | } |
|
1062 | 1147 | } |
|
1063 | 1148 | |
|
1064 | 1149 | return status; |
|
1065 | 1150 | } |
|
1066 | 1151 | |
|
1067 | 1152 | int suspend_asm_tasks( void ) |
|
1068 | 1153 | { |
|
1069 | 1154 | /** This function suspends the science tasks. |
|
1070 | 1155 | * |
|
1071 | 1156 | * @return RTEMS directive status codes: |
|
1072 | 1157 | * - RTEMS_SUCCESSFUL - task restarted successfully |
|
1073 | 1158 | * - RTEMS_INVALID_ID - task id invalid |
|
1074 | 1159 | * - RTEMS_ALREADY_SUSPENDED - task already suspended |
|
1075 | 1160 | * |
|
1076 | 1161 | */ |
|
1077 | 1162 | |
|
1078 | 1163 | rtems_status_code status; |
|
1079 | 1164 | |
|
1080 | 1165 | PRINTF("in suspend_science_tasks\n") |
|
1081 | 1166 | |
|
1082 | 1167 | status = rtems_task_suspend( Task_id[TASKID_AVF0] ); // suspend AVF0 |
|
1083 | 1168 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1084 | 1169 | { |
|
1085 | 1170 | PRINTF1("in suspend_science_task *** AVF0 ERR %d\n", status) |
|
1086 | 1171 | } |
|
1087 | 1172 | else |
|
1088 | 1173 | { |
|
1089 | 1174 | status = RTEMS_SUCCESSFUL; |
|
1090 | 1175 | } |
|
1091 | 1176 | |
|
1092 | 1177 | if (status == RTEMS_SUCCESSFUL) // suspend PRC0 |
|
1093 | 1178 | { |
|
1094 | 1179 | status = rtems_task_suspend( Task_id[TASKID_PRC0] ); |
|
1095 | 1180 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1096 | 1181 | { |
|
1097 | 1182 | PRINTF1("in suspend_science_task *** PRC0 ERR %d\n", status) |
|
1098 | 1183 | } |
|
1099 | 1184 | else |
|
1100 | 1185 | { |
|
1101 | 1186 | status = RTEMS_SUCCESSFUL; |
|
1102 | 1187 | } |
|
1103 | 1188 | } |
|
1104 | 1189 | |
|
1105 | 1190 | if (status == RTEMS_SUCCESSFUL) // suspend AVF1 |
|
1106 | 1191 | { |
|
1107 | 1192 | status = rtems_task_suspend( Task_id[TASKID_AVF1] ); |
|
1108 | 1193 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1109 | 1194 | { |
|
1110 | 1195 | PRINTF1("in suspend_science_task *** AVF1 ERR %d\n", status) |
|
1111 | 1196 | } |
|
1112 | 1197 | else |
|
1113 | 1198 | { |
|
1114 | 1199 | status = RTEMS_SUCCESSFUL; |
|
1115 | 1200 | } |
|
1116 | 1201 | } |
|
1117 | 1202 | |
|
1118 | 1203 | if (status == RTEMS_SUCCESSFUL) // suspend PRC1 |
|
1119 | 1204 | { |
|
1120 | 1205 | status = rtems_task_suspend( Task_id[TASKID_PRC1] ); |
|
1121 | 1206 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1122 | 1207 | { |
|
1123 | 1208 | PRINTF1("in suspend_science_task *** PRC1 ERR %d\n", status) |
|
1124 | 1209 | } |
|
1125 | 1210 | else |
|
1126 | 1211 | { |
|
1127 | 1212 | status = RTEMS_SUCCESSFUL; |
|
1128 | 1213 | } |
|
1129 | 1214 | } |
|
1130 | 1215 | |
|
1131 | 1216 | if (status == RTEMS_SUCCESSFUL) // suspend AVF2 |
|
1132 | 1217 | { |
|
1133 | 1218 | status = rtems_task_suspend( Task_id[TASKID_AVF2] ); |
|
1134 | 1219 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1135 | 1220 | { |
|
1136 | 1221 | PRINTF1("in suspend_science_task *** AVF2 ERR %d\n", status) |
|
1137 | 1222 | } |
|
1138 | 1223 | else |
|
1139 | 1224 | { |
|
1140 | 1225 | status = RTEMS_SUCCESSFUL; |
|
1141 | 1226 | } |
|
1142 | 1227 | } |
|
1143 | 1228 | |
|
1144 | 1229 | if (status == RTEMS_SUCCESSFUL) // suspend PRC2 |
|
1145 | 1230 | { |
|
1146 | 1231 | status = rtems_task_suspend( Task_id[TASKID_PRC2] ); |
|
1147 | 1232 | if ((status != RTEMS_SUCCESSFUL) && (status != RTEMS_ALREADY_SUSPENDED)) |
|
1148 | 1233 | { |
|
1149 | 1234 | PRINTF1("in suspend_science_task *** PRC2 ERR %d\n", status) |
|
1150 | 1235 | } |
|
1151 | 1236 | else |
|
1152 | 1237 | { |
|
1153 | 1238 | status = RTEMS_SUCCESSFUL; |
|
1154 | 1239 | } |
|
1155 | 1240 | } |
|
1156 | 1241 | |
|
1157 | 1242 | return status; |
|
1158 | 1243 | } |
|
1159 | 1244 | |
|
1160 | 1245 | void launch_waveform_picker( unsigned char mode, unsigned int transitionCoarseTime ) |
|
1161 | 1246 | { |
|
1162 | 1247 | WFP_reset_current_ring_nodes(); |
|
1163 | 1248 | |
|
1164 | 1249 | reset_waveform_picker_regs(); |
|
1165 | 1250 | |
|
1166 | 1251 | set_wfp_burst_enable_register( mode ); |
|
1167 | 1252 | |
|
1168 | 1253 | LEON_Clear_interrupt( IRQ_WAVEFORM_PICKER ); |
|
1169 | 1254 | LEON_Unmask_interrupt( IRQ_WAVEFORM_PICKER ); |
|
1170 | 1255 | |
|
1171 | 1256 | if (transitionCoarseTime == 0) |
|
1172 | 1257 | { |
|
1173 | 1258 | waveform_picker_regs->start_date = time_management_regs->coarse_time; |
|
1174 | 1259 | } |
|
1175 | 1260 | else |
|
1176 | 1261 | { |
|
1177 | 1262 | waveform_picker_regs->start_date = transitionCoarseTime; |
|
1178 | 1263 | } |
|
1179 | 1264 | |
|
1180 | 1265 | } |
|
1181 | 1266 | |
|
1182 | 1267 | void launch_spectral_matrix( void ) |
|
1183 | 1268 | { |
|
1184 | 1269 | SM_reset_current_ring_nodes(); |
|
1185 | 1270 | |
|
1186 | 1271 | reset_spectral_matrix_regs(); |
|
1187 | 1272 | |
|
1188 | 1273 | reset_nb_sm(); |
|
1189 | 1274 | |
|
1190 | 1275 | set_sm_irq_onNewMatrix( 1 ); |
|
1191 | 1276 | |
|
1192 | 1277 | LEON_Clear_interrupt( IRQ_SPECTRAL_MATRIX ); |
|
1193 | 1278 | LEON_Unmask_interrupt( IRQ_SPECTRAL_MATRIX ); |
|
1194 | 1279 | |
|
1195 | 1280 | } |
|
1196 | 1281 | |
|
1197 | 1282 | void set_sm_irq_onNewMatrix( unsigned char value ) |
|
1198 | 1283 | { |
|
1199 | 1284 | if (value == 1) |
|
1200 | 1285 | { |
|
1201 | 1286 | spectral_matrix_regs->config = spectral_matrix_regs->config | 0x01; |
|
1202 | 1287 | } |
|
1203 | 1288 | else |
|
1204 | 1289 | { |
|
1205 | 1290 | spectral_matrix_regs->config = spectral_matrix_regs->config & 0xfffffffe; // 1110 |
|
1206 | 1291 | } |
|
1207 | 1292 | } |
|
1208 | 1293 | |
|
1209 | 1294 | void set_sm_irq_onError( unsigned char value ) |
|
1210 | 1295 | { |
|
1211 | 1296 | if (value == 1) |
|
1212 | 1297 | { |
|
1213 | 1298 | spectral_matrix_regs->config = spectral_matrix_regs->config | 0x02; |
|
1214 | 1299 | } |
|
1215 | 1300 | else |
|
1216 | 1301 | { |
|
1217 | 1302 | spectral_matrix_regs->config = spectral_matrix_regs->config & 0xfffffffd; // 1101 |
|
1218 | 1303 | } |
|
1219 | 1304 | } |
|
1220 | 1305 | |
|
1221 | 1306 | //***************************** |
|
1222 | 1307 | // CONFIGURE CALIBRATION SIGNAL |
|
1223 | 1308 | void setCalibrationPrescaler( unsigned int prescaler ) |
|
1224 | 1309 | { |
|
1225 | 1310 | // prescaling of the master clock (25 MHz) |
|
1226 | 1311 | // master clock is divided by 2^prescaler |
|
1227 | 1312 | time_management_regs->calPrescaler = prescaler; |
|
1228 | 1313 | } |
|
1229 | 1314 | |
|
1230 | 1315 | void setCalibrationDivisor( unsigned int divisionFactor ) |
|
1231 | 1316 | { |
|
1232 | 1317 | // division of the prescaled clock by the division factor |
|
1233 | 1318 | time_management_regs->calDivisor = divisionFactor; |
|
1234 | 1319 | } |
|
1235 | 1320 | |
|
1236 | 1321 | void setCalibrationData( void ){ |
|
1237 | 1322 | unsigned int k; |
|
1238 | 1323 | unsigned short data; |
|
1239 | 1324 | float val; |
|
1240 | 1325 | float f0; |
|
1241 | 1326 | float f1; |
|
1242 | 1327 | float fs; |
|
1243 | 1328 | float Ts; |
|
1244 | 1329 | float scaleFactor; |
|
1245 | 1330 | |
|
1246 | 1331 | f0 = 625; |
|
1247 | 1332 | f1 = 10000; |
|
1248 | 1333 | fs = 160256.410; |
|
1249 | 1334 | Ts = 1. / fs; |
|
1250 | 1335 | scaleFactor = 0.250 / 0.000654; // 191, 500 mVpp, 2 sinus waves => 500 mVpp each, amplitude = 250 mV |
|
1251 | 1336 | |
|
1252 | 1337 | time_management_regs->calDataPtr = 0x00; |
|
1253 | 1338 | |
|
1254 | 1339 | // build the signal for the SCM calibration |
|
1255 | 1340 | for (k=0; k<256; k++) |
|
1256 | 1341 | { |
|
1257 | 1342 | val = sin( 2 * pi * f0 * k * Ts ) |
|
1258 | 1343 | + sin( 2 * pi * f1 * k * Ts ); |
|
1259 | 1344 | data = (unsigned short) ((val * scaleFactor) + 2048); |
|
1260 | 1345 | time_management_regs->calData = data & 0xfff; |
|
1261 | 1346 | } |
|
1262 | 1347 | } |
|
1263 | 1348 | |
|
1264 | 1349 | void setCalibrationDataInterleaved( void ){ |
|
1265 | 1350 | unsigned int k; |
|
1266 | 1351 | float val; |
|
1267 | 1352 | float f0; |
|
1268 | 1353 | float f1; |
|
1269 | 1354 | float fs; |
|
1270 | 1355 | float Ts; |
|
1271 | 1356 | unsigned short data[384]; |
|
1272 | 1357 | unsigned char *dataPtr; |
|
1273 | 1358 | |
|
1274 | 1359 | f0 = 625; |
|
1275 | 1360 | f1 = 10000; |
|
1276 | 1361 | fs = 240384.615; |
|
1277 | 1362 | Ts = 1. / fs; |
|
1278 | 1363 | |
|
1279 | 1364 | time_management_regs->calDataPtr = 0x00; |
|
1280 | 1365 | |
|
1281 | 1366 | // build the signal for the SCM calibration |
|
1282 | 1367 | for (k=0; k<384; k++) |
|
1283 | 1368 | { |
|
1284 | 1369 | val = sin( 2 * pi * f0 * k * Ts ) |
|
1285 | 1370 | + sin( 2 * pi * f1 * k * Ts ); |
|
1286 | 1371 | data[k] = (unsigned short) (val * 512 + 2048); |
|
1287 | 1372 | } |
|
1288 | 1373 | |
|
1289 | 1374 | // write the signal in interleaved mode |
|
1290 | 1375 | for (k=0; k<128; k++) |
|
1291 | 1376 | { |
|
1292 | 1377 | dataPtr = (unsigned char*) &data[k*3 + 2]; |
|
1293 | 1378 | time_management_regs->calData = (data[k*3] & 0xfff) |
|
1294 | 1379 | + ( (dataPtr[0] & 0x3f) << 12); |
|
1295 | 1380 | time_management_regs->calData = (data[k*3 + 1] & 0xfff) |
|
1296 | 1381 | + ( (dataPtr[1] & 0x3f) << 12); |
|
1297 | 1382 | } |
|
1298 | 1383 | } |
|
1299 | 1384 | |
|
1300 | 1385 | void setCalibrationReload( bool state) |
|
1301 | 1386 | { |
|
1302 | 1387 | if (state == true) |
|
1303 | 1388 | { |
|
1304 | 1389 | time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | 0x00000010; // [0001 0000] |
|
1305 | 1390 | } |
|
1306 | 1391 | else |
|
1307 | 1392 | { |
|
1308 | 1393 | time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & 0xffffffef; // [1110 1111] |
|
1309 | 1394 | } |
|
1310 | 1395 | } |
|
1311 | 1396 | |
|
1312 | 1397 | void setCalibrationEnable( bool state ) |
|
1313 | 1398 | { |
|
1314 | 1399 | // this bit drives the multiplexer |
|
1315 | 1400 | if (state == true) |
|
1316 | 1401 | { |
|
1317 | 1402 | time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | 0x00000040; // [0100 0000] |
|
1318 | 1403 | } |
|
1319 | 1404 | else |
|
1320 | 1405 | { |
|
1321 | 1406 | time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & 0xffffffbf; // [1011 1111] |
|
1322 | 1407 | } |
|
1323 | 1408 | } |
|
1324 | 1409 | |
|
1325 | 1410 | void setCalibrationInterleaved( bool state ) |
|
1326 | 1411 | { |
|
1327 | 1412 | // this bit drives the multiplexer |
|
1328 | 1413 | if (state == true) |
|
1329 | 1414 | { |
|
1330 | 1415 | time_management_regs->calDACCtrl = time_management_regs->calDACCtrl | 0x00000020; // [0010 0000] |
|
1331 | 1416 | } |
|
1332 | 1417 | else |
|
1333 | 1418 | { |
|
1334 | 1419 | time_management_regs->calDACCtrl = time_management_regs->calDACCtrl & 0xffffffdf; // [1101 1111] |
|
1335 | 1420 | } |
|
1336 | 1421 | } |
|
1337 | 1422 | |
|
1338 | 1423 | void setCalibration( bool state ) |
|
1339 | 1424 | { |
|
1340 | 1425 | if (state == true) |
|
1341 | 1426 | { |
|
1342 | 1427 | setCalibrationEnable( true ); |
|
1343 | 1428 | setCalibrationReload( false ); |
|
1344 | 1429 | set_hk_lfr_calib_enable( true ); |
|
1345 | 1430 | } |
|
1346 | 1431 | else |
|
1347 | 1432 | { |
|
1348 | 1433 | setCalibrationEnable( false ); |
|
1349 | 1434 | setCalibrationReload( true ); |
|
1350 | 1435 | set_hk_lfr_calib_enable( false ); |
|
1351 | 1436 | } |
|
1352 | 1437 | } |
|
1353 | 1438 | |
|
1354 | 1439 | void configureCalibration( bool interleaved ) |
|
1355 | 1440 | { |
|
1356 | 1441 | setCalibration( false ); |
|
1357 | 1442 | if ( interleaved == true ) |
|
1358 | 1443 | { |
|
1359 | 1444 | setCalibrationInterleaved( true ); |
|
1360 | 1445 | setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000 |
|
1361 | 1446 | setCalibrationDivisor( 26 ); // => 240 384 |
|
1362 | 1447 | setCalibrationDataInterleaved(); |
|
1363 | 1448 | } |
|
1364 | 1449 | else |
|
1365 | 1450 | { |
|
1366 | 1451 | setCalibrationPrescaler( 0 ); // 25 MHz => 25 000 000 |
|
1367 | 1452 | setCalibrationDivisor( 38 ); // => 160 256 (39 - 1) |
|
1368 | 1453 | setCalibrationData(); |
|
1369 | 1454 | } |
|
1370 | 1455 | } |
|
1371 | 1456 | |
|
1372 | 1457 | //**************** |
|
1373 | 1458 | // CLOSING ACTIONS |
|
1374 | 1459 | void update_last_TC_exe( ccsdsTelecommandPacket_t *TC, unsigned char * time ) |
|
1375 | 1460 | { |
|
1376 | 1461 | /** This function is used to update the HK packets statistics after a successful TC execution. |
|
1377 | 1462 | * |
|
1378 | 1463 | * @param TC points to the TC being processed |
|
1379 | 1464 | * @param time is the time used to date the TC execution |
|
1380 | 1465 | * |
|
1381 | 1466 | */ |
|
1382 | 1467 | |
|
1383 | 1468 | unsigned int val; |
|
1384 | 1469 | |
|
1385 | 1470 | housekeeping_packet.hk_lfr_last_exe_tc_id[0] = TC->packetID[0]; |
|
1386 | 1471 | housekeeping_packet.hk_lfr_last_exe_tc_id[1] = TC->packetID[1]; |
|
1387 | 1472 | housekeeping_packet.hk_lfr_last_exe_tc_type[0] = 0x00; |
|
1388 | 1473 | housekeeping_packet.hk_lfr_last_exe_tc_type[1] = TC->serviceType; |
|
1389 | 1474 | housekeeping_packet.hk_lfr_last_exe_tc_subtype[0] = 0x00; |
|
1390 | 1475 | housekeeping_packet.hk_lfr_last_exe_tc_subtype[1] = TC->serviceSubType; |
|
1391 | 1476 | housekeeping_packet.hk_lfr_last_exe_tc_time[0] = time[0]; |
|
1392 | 1477 | housekeeping_packet.hk_lfr_last_exe_tc_time[1] = time[1]; |
|
1393 | 1478 | housekeeping_packet.hk_lfr_last_exe_tc_time[2] = time[2]; |
|
1394 | 1479 | housekeeping_packet.hk_lfr_last_exe_tc_time[3] = time[3]; |
|
1395 | 1480 | housekeeping_packet.hk_lfr_last_exe_tc_time[4] = time[4]; |
|
1396 | 1481 | housekeeping_packet.hk_lfr_last_exe_tc_time[5] = time[5]; |
|
1397 | 1482 | |
|
1398 | 1483 | val = housekeeping_packet.hk_lfr_exe_tc_cnt[0] * 256 + housekeeping_packet.hk_lfr_exe_tc_cnt[1]; |
|
1399 | 1484 | val++; |
|
1400 | 1485 | housekeeping_packet.hk_lfr_exe_tc_cnt[0] = (unsigned char) (val >> 8); |
|
1401 | 1486 | housekeeping_packet.hk_lfr_exe_tc_cnt[1] = (unsigned char) (val); |
|
1402 | 1487 | } |
|
1403 | 1488 | |
|
1404 | 1489 | void update_last_TC_rej(ccsdsTelecommandPacket_t *TC, unsigned char * time ) |
|
1405 | 1490 | { |
|
1406 | 1491 | /** This function is used to update the HK packets statistics after a TC rejection. |
|
1407 | 1492 | * |
|
1408 | 1493 | * @param TC points to the TC being processed |
|
1409 | 1494 | * @param time is the time used to date the TC rejection |
|
1410 | 1495 | * |
|
1411 | 1496 | */ |
|
1412 | 1497 | |
|
1413 | 1498 | unsigned int val; |
|
1414 | 1499 | |
|
1415 | 1500 | housekeeping_packet.hk_lfr_last_rej_tc_id[0] = TC->packetID[0]; |
|
1416 | 1501 | housekeeping_packet.hk_lfr_last_rej_tc_id[1] = TC->packetID[1]; |
|
1417 | 1502 | housekeeping_packet.hk_lfr_last_rej_tc_type[0] = 0x00; |
|
1418 | 1503 | housekeeping_packet.hk_lfr_last_rej_tc_type[1] = TC->serviceType; |
|
1419 | 1504 | housekeeping_packet.hk_lfr_last_rej_tc_subtype[0] = 0x00; |
|
1420 | 1505 | housekeeping_packet.hk_lfr_last_rej_tc_subtype[1] = TC->serviceSubType; |
|
1421 | 1506 | housekeeping_packet.hk_lfr_last_rej_tc_time[0] = time[0]; |
|
1422 | 1507 | housekeeping_packet.hk_lfr_last_rej_tc_time[1] = time[1]; |
|
1423 | 1508 | housekeeping_packet.hk_lfr_last_rej_tc_time[2] = time[2]; |
|
1424 | 1509 | housekeeping_packet.hk_lfr_last_rej_tc_time[3] = time[3]; |
|
1425 | 1510 | housekeeping_packet.hk_lfr_last_rej_tc_time[4] = time[4]; |
|
1426 | 1511 | housekeeping_packet.hk_lfr_last_rej_tc_time[5] = time[5]; |
|
1427 | 1512 | |
|
1428 | 1513 | val = housekeeping_packet.hk_lfr_rej_tc_cnt[0] * 256 + housekeeping_packet.hk_lfr_rej_tc_cnt[1]; |
|
1429 | 1514 | val++; |
|
1430 | 1515 | housekeeping_packet.hk_lfr_rej_tc_cnt[0] = (unsigned char) (val >> 8); |
|
1431 | 1516 | housekeeping_packet.hk_lfr_rej_tc_cnt[1] = (unsigned char) (val); |
|
1432 | 1517 | } |
|
1433 | 1518 | |
|
1434 | 1519 | void close_action(ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id ) |
|
1435 | 1520 | { |
|
1436 | 1521 | /** This function is the last step of the TC execution workflow. |
|
1437 | 1522 | * |
|
1438 | 1523 | * @param TC points to the TC being processed |
|
1439 | 1524 | * @param result is the result of the TC execution (LFR_SUCCESSFUL / LFR_DEFAULT) |
|
1440 | 1525 | * @param queue_id is the id of the RTEMS message queue used to send TM packets |
|
1441 | 1526 | * @param time is the time used to date the TC execution |
|
1442 | 1527 | * |
|
1443 | 1528 | */ |
|
1444 | 1529 | |
|
1445 | 1530 | unsigned char requestedMode; |
|
1446 | 1531 | |
|
1447 | 1532 | if (result == LFR_SUCCESSFUL) |
|
1448 | 1533 | { |
|
1449 | 1534 | if ( !( (TC->serviceType==TC_TYPE_TIME) & (TC->serviceSubType==TC_SUBTYPE_UPDT_TIME) ) |
|
1450 | 1535 | & |
|
1451 | 1536 | !( (TC->serviceType==TC_TYPE_GEN) & (TC->serviceSubType==TC_SUBTYPE_UPDT_INFO)) |
|
1452 | 1537 | ) |
|
1453 | 1538 | { |
|
1454 | 1539 | send_tm_lfr_tc_exe_success( TC, queue_id ); |
|
1455 | 1540 | } |
|
1456 | 1541 | if ( (TC->serviceType == TC_TYPE_GEN) & (TC->serviceSubType == TC_SUBTYPE_ENTER) ) |
|
1457 | 1542 | { |
|
1458 | 1543 | //********************************** |
|
1459 | 1544 | // UPDATE THE LFRMODE LOCAL VARIABLE |
|
1460 | 1545 | requestedMode = TC->dataAndCRC[1]; |
|
1461 | 1546 | housekeeping_packet.lfr_status_word[0] = (unsigned char) ((requestedMode << 4) + 0x0d); |
|
1462 | 1547 | updateLFRCurrentMode(); |
|
1463 | 1548 | } |
|
1464 | 1549 | } |
|
1465 | 1550 | else if (result == LFR_EXE_ERROR) |
|
1466 | 1551 | { |
|
1467 | 1552 | send_tm_lfr_tc_exe_error( TC, queue_id ); |
|
1468 | 1553 | } |
|
1469 | 1554 | } |
|
1470 | 1555 | |
|
1471 | 1556 | //*************************** |
|
1472 | 1557 | // Interrupt Service Routines |
|
1473 | 1558 | rtems_isr commutation_isr1( rtems_vector_number vector ) |
|
1474 | 1559 | { |
|
1475 | 1560 | if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) { |
|
1476 | 1561 | PRINTF("In commutation_isr1 *** Error sending event to DUMB\n") |
|
1477 | 1562 | } |
|
1478 | 1563 | } |
|
1479 | 1564 | |
|
1480 | 1565 | rtems_isr commutation_isr2( rtems_vector_number vector ) |
|
1481 | 1566 | { |
|
1482 | 1567 | if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) { |
|
1483 | 1568 | PRINTF("In commutation_isr2 *** Error sending event to DUMB\n") |
|
1484 | 1569 | } |
|
1485 | 1570 | } |
|
1486 | 1571 | |
|
1487 | 1572 | //**************** |
|
1488 | 1573 | // OTHER FUNCTIONS |
|
1489 | 1574 | void updateLFRCurrentMode() |
|
1490 | 1575 | { |
|
1491 | 1576 | /** This function updates the value of the global variable lfrCurrentMode. |
|
1492 | 1577 | * |
|
1493 | 1578 | * lfrCurrentMode is a parameter used by several functions to know in which mode LFR is running. |
|
1494 | 1579 | * |
|
1495 | 1580 | */ |
|
1496 | 1581 | // update the local value of lfrCurrentMode with the value contained in the housekeeping_packet structure |
|
1497 | 1582 | lfrCurrentMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4; |
|
1498 | 1583 | } |
|
1499 | 1584 | |
|
1500 | 1585 | void set_lfr_soft_reset( unsigned char value ) |
|
1501 | 1586 | { |
|
1502 | 1587 | if (value == 1) |
|
1503 | 1588 | { |
|
1504 | 1589 | time_management_regs->ctrl = time_management_regs->ctrl | 0x00000004; // [0100] |
|
1505 | 1590 | } |
|
1506 | 1591 | else |
|
1507 | 1592 | { |
|
1508 | 1593 | time_management_regs->ctrl = time_management_regs->ctrl & 0xfffffffb; // [1011] |
|
1509 | 1594 | } |
|
1510 | 1595 | } |
|
1511 | 1596 | |
|
1512 | 1597 | void reset_lfr( void ) |
|
1513 | 1598 | { |
|
1514 | 1599 | set_lfr_soft_reset( 1 ); |
|
1515 | 1600 | |
|
1516 | 1601 | set_lfr_soft_reset( 0 ); |
|
1517 | 1602 | |
|
1518 | 1603 | set_hk_lfr_sc_potential_flag( true ); |
|
1519 | 1604 | } |
General Comments 0
You need to be logged in to leave comments.
Login now