//************************* // GPL reminder to be added //************************* #include /* configuration information */ #define CONFIGURE_INIT #include /* for device driver prototypes */ /* configuration information */ #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER #define CONFIGURE_MAXIMUM_TASKS 15 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE #define CONFIGURE_EXTRA_TASK_STACKS (3 * RTEMS_MINIMUM_STACK_SIZE) #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 32 #define CONFIGURE_INIT_TASK_PRIORITY 100 #define CONFIGURE_MAXIMUM_DRIVERS 16 #define CONFIGURE_MAXIMUM_PERIODS 5 #define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 1 #include /* If --drvmgr was enabled during the configuration of the RTEMS kernel */ #ifdef RTEMS_DRVMGR_STARTUP #ifdef LEON3 /* Add Timer and UART Driver */ #ifdef CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GPTIMER #endif #ifdef CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER #define CONFIGURE_DRIVER_AMBAPP_GAISLER_APBUART #endif #endif #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GRSPW /* GRSPW Driver */ #include #endif #include #include char *lstates[6] = {"Error-reset", "Error-wait", "Ready", "Started", "Connecting", "Run" }; rtems_task Init( rtems_task_argument ignored ) { rtems_status_code status; rtems_isr_entry old_isr_handler; PRINTF("\n\n\n\n\n") PRINTF("***************************\n") PRINTF("** START Flight Software **\n") PRINTF("***************************\n") PRINTF("\n\n") //send_console_outputs_on_apbuart_port(); set_apbuart_scaler_reload_register(REGS_ADDR_APBUART, APBUART_SCALER_RELOAD_VALUE); initLookUpTableForCRC(); // in tc_handler.h init_default_mode_parameters(); init_housekeeping_parameters(); create_message_queue(); create_names(); // create all names create_all_tasks(); // create all tasks start_all_tasks(); // start all tasks stop_current_mode(); // go in STANDBY mode grspw_timecode_callback = &timecode_irq_handler; spacewire_configure_link(); //**************************** // Spectral Matrices simulator configure_timer((gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_SM_SIMULATOR, CLKDIV_SM_SIMULATOR, IRQ_SPARC_SM, spectral_matrices_isr ); //********** // WAVEFORMS // simulator #ifdef GSA configure_timer((gptimer_regs_t*) REGS_ADDR_GPTIMER, TIMER_WF_SIMULATOR, CLKDIV_WF_SIMULATOR, IRQ_SPARC_WF, waveforms_simulator_isr ); #else // configure the registers of the waveform picker reset_wfp_regs(); // configure the waveform picker interrupt service routine status = rtems_interrupt_catch( waveforms_isr, IRQ_SPARC_WAVEFORM_PICKER, &old_isr_handler) ; LEON_Mask_interrupt( IRQ_WAVEFORM_PICKER ); #endif //********** //***************************************** // irq handling of the time management unit status = rtems_interrupt_catch( commutation_isr1, IRQ_SPARC_TIME1, &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels if (status==RTEMS_SUCCESSFUL) { PRINTF("OK *** commutation_isr1 *** rtems_interrupt_catch successfullly configured\n") } status = rtems_interrupt_catch( commutation_isr2, IRQ_SPARC_TIME2, &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels if (status==RTEMS_SUCCESSFUL) { PRINTF("OK *** commutation_isr2 *** rtems_interrupt_catch successfullly configured\n") } LEON_Unmask_interrupt( IRQ_TIME1 ); LEON_Unmask_interrupt( IRQ_TIME2 ); #ifdef GSA //if (rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) { // printf("in INIT *** Error sending event to WFRM\n"); //} #endif status = rtems_task_delete(RTEMS_SELF); } rtems_task spiq_task(rtems_task_argument unused) { rtems_event_set event_out; rtems_status_code status; unsigned char lfrMode; while(true){ PRINTF("in SPIQ *** Waiting for SPW_LINKERR_EVENT\n") rtems_event_receive(SPW_LINKERR_EVENT, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an SPW_LINKERR_EVENT lfrMode = (housekeeping_packet.lfr_status_word[0] & 0xf0) >> 4; // get the current mode status = spacewire_wait_for_link(); if (status != RTEMS_SUCCESSFUL) { //**************** // STOP THE SYSTEM spacewire_compute_stats_offsets(); stop_current_mode(); if (rtems_task_suspend(Task_id[TASKID_RECV])!=RTEMS_SUCCESSFUL) { // suspend RECV task PRINTF("in SPIQ *** Error suspending RECV Task\n") } if (rtems_task_suspend(Task_id[TASKID_HOUS])!=RTEMS_SUCCESSFUL) { // suspend HOUS task PRINTF("in SPIQ *** Error suspending HOUS Task\n") } //*************************** // RESTART THE SPACEWIRE LINK spacewire_configure_link(); //******************* // RESTART THE SYSTEM //ioctl(fdSPW, SPACEWIRE_IOCTRL_CLR_STATISTICS); // clear statistics status = rtems_task_restart( Task_id[TASKID_HOUS], 1 ); if (status != RTEMS_SUCCESSFUL) { PRINTF1("in SPIQ *** Error restarting HOUS Task *** code %d\n", status) } if (rtems_task_restart(Task_id[TASKID_RECV], 1) != RTEMS_SUCCESSFUL) { // restart RECV task PRINTF("in SPIQ *** Error restarting RECV Task\n") } //enter_mode(lfrMode, NULL); // enter the mode that was running before the SpaceWire interruption } } } void init_default_mode_parameters(void) { // COMMON PARAMETERS param_common.sy_lfr_common0 = 0x00; param_common.sy_lfr_common1 = 0x10; // default value 0 0 0 1 0 0 0 0 // NORMAL MODE param_norm.sy_lfr_n_swf_l = DEFAULT_SY_LFR_N_SWF_L; // nb sample param_norm.sy_lfr_n_swf_p = DEFAULT_SY_LFR_N_SWF_P; // sec param_norm.sy_lfr_n_asm_p = DEFAULT_SY_LFR_N_ASM_P; // sec param_norm.sy_lfr_n_bp_p0 = DEFAULT_SY_LFR_N_BP_P0; // sec param_norm.sy_lfr_n_bp_p1 = DEFAULT_SY_LFR_N_BP_P1; // sec // BURST MODE param_burst.sy_lfr_b_bp_p0 = DEFAULT_SY_LFR_B_BP_P0; // sec param_burst.sy_lfr_b_bp_p1 = DEFAULT_SY_LFR_B_BP_P1; // sec // SBM1 MODE param_sbm1.sy_lfr_s1_bp_p0 = DEFAULT_SY_LFR_S1_BP_P0; // sec param_sbm1.sy_lfr_s1_bp_p1 = DEFAULT_SY_LFR_B_BP_P1; // sec // SBM2 MODE param_sbm2.sy_lfr_s2_bp_p0 = DEFAULT_SY_LFR_S2_BP_P0; // sec param_sbm2.sy_lfr_s2_bp_p1 = DEFAULT_SY_LFR_S2_BP_P1; // sec // LOCAL PARAMETERS // (2 snapshots of 2048 points per seconds) * (period of the NORM snashots) param_local.local_sbm1_nb_cwf_max = 2 * param_norm.sy_lfr_n_swf_p; // (period of the NORM snashots) / (8 seconds per snapshot at f2 = 256 Hz) param_local.local_sbm2_nb_cwf_max = param_norm.sy_lfr_n_swf_p / 8; PRINTF1("local_sbm1_nb_cwf_max %d \n", param_local.local_sbm1_nb_cwf_max) PRINTF1("local_sbm2_nb_cwf_max %d \n", param_local.local_sbm2_nb_cwf_max) param_local.local_sbm1_nb_cwf_sent = 0; param_local.local_sbm2_nb_cwf_sent = 0; } void init_housekeeping_parameters(void) { unsigned int i = 0; unsigned int j = 0; unsigned int k = 0; char *parameters; parameters = (char*) &housekeeping_packet.lfr_status_word; for(i = 0; i< SIZE_HK_PARAMETERS; i++) { parameters[i] = 0x00; } // init status word housekeeping_packet.lfr_status_word[0] = 0x00; housekeeping_packet.lfr_status_word[1] = 0x00; // init software version housekeeping_packet.lfr_sw_version[0] = SW_VERSION_N1; housekeeping_packet.lfr_sw_version[1] = SW_VERSION_N2; housekeeping_packet.lfr_sw_version[2] = SW_VERSION_N3; housekeeping_packet.lfr_sw_version[3] = SW_VERSION_N4; // init sequence counters for (i = 0; i