Example #1
0
/******************************************************************************
**  Function:  main()
**
**  Purpose:
**    BSP Application entry point.
**
**  Arguments:
**    (none)
**
**  Return:
**    (none)
*/
int main(int argc, char *argv[])
{
   uint32             reset_type;
   uint32             reset_subtype;
   struct             sigaction sa;
   struct             itimerval timer;
   int                opt = 0;
   int                longIndex = 0;
   sigset_t           mask;
   pthread_t          thread_id;
   struct sched_param thread_params;
   int                ret;

#ifdef CFE_PSP_EEPROM_SUPPORT
   int32  Status;
   uint32 eeprom_address;
   uint32 eeprom_size;
#endif
   
   /*
   ** Initialize the CommandData struct 
   */
   memset(&(CommandData), 0, sizeof(CFE_PSP_CommandData_t));
      
   /* 
   ** Process the arguments with getopt_long(), then 
   ** start the cFE
   */
   opt = getopt_long( argc, argv, optString, longOpts, &longIndex );
   while( opt != -1 ) 
   {
      switch( opt ) 
      {
         case 'R':
            strncpy(CommandData.ResetType, optarg, CFE_PSP_RESET_NAME_LENGTH);
            if ((strncmp(CommandData.ResetType, "PO", CFE_PSP_RESET_NAME_LENGTH ) != 0 ) &&
                (strncmp(CommandData.ResetType, "PR", CFE_PSP_RESET_NAME_LENGTH ) != 0 ))
            {
               printf("\nERROR: Invalid Reset Type: %s\n\n",CommandData.ResetType);
               CommandData.GotResetType = 0;
               CFE_PSP_DisplayUsage(argv[0]);
               break;
            }
            printf("CFE_PSP: Reset Type: %s\n",(char *)optarg);
            CommandData.GotResetType = 1;
            break;
				
         case 'S':
            CommandData.SubType = strtol(optarg, NULL, 0 );
            if ( CommandData.SubType < 1 || CommandData.SubType > 5 )
            {
               printf("\nERROR: Invalid Reset SubType: %s\n\n",optarg);
               CommandData.SubType = 0;
               CommandData.GotSubType = 0;
               CFE_PSP_DisplayUsage(argv[0]);
               break;
            }
            printf("CFE_PSP: Reset SubType: %d\n",(int)CommandData.SubType);
            CommandData.GotSubType = 1;
            break;

         case 'N':
            strncpy(CommandData.CpuName, optarg, CFE_PSP_CPU_NAME_LENGTH );
            printf("CFE_PSP: CPU Name: %s\n",CommandData.CpuName);
            CommandData.GotCpuName = 1;
            break;

         case 'C':
            CommandData.CpuId = strtol(optarg, NULL, 0 );
            printf("CFE_PSP: CPU ID: %d\n",(int)CommandData.CpuId);
            CommandData.GotCpuId = 1;
            break;

         case 'I':
            CommandData.SpacecraftId = strtol(optarg, NULL, 0 );
            printf("CFE_PSP: Spacecraft ID: %d\n",(int)CommandData.SpacecraftId);
            CommandData.GotSpacecraftId = 1;
            break;

         case 'h':
            CFE_PSP_DisplayUsage(argv[0]);
            break;
	
         default:
            CFE_PSP_DisplayUsage(argv[0]);
            break;
       }
		
       opt = getopt_long( argc, argv, optString, longOpts, &longIndex );
   } /* end while */
   
   /*
   ** Set the defaults for values that were not given for the 
   ** optional arguments, and check for arguments that are required.
   */
   CFE_PSP_ProcessArgumentDefaults(&CommandData);

   /*
   ** Set the reset type
   */
   if (strncmp("PR", CommandData.ResetType, 2 ) == 0 )
   {
     reset_type = CFE_ES_PROCESSOR_RESET;
      OS_printf("CFE_PSP: Starting the cFE with a PROCESSOR reset.\n");
   }
   else
   {
      reset_type = CFE_ES_POWERON_RESET;
      OS_printf("CFE_PSP: Starting the cFE with a POWER ON reset.\n");
   }

   /*
   ** Assign the Spacecraft ID, CPU ID, and CPU Name
   */
   CFE_PSP_SpacecraftId = CommandData.SpacecraftId;
   CFE_PSP_CpuId = CommandData.CpuId;
   strncpy(CFE_PSP_CpuName, CommandData.CpuName, CFE_PSP_CPU_NAME_LENGTH);

   /*
   ** Set the reset subtype
   */
   reset_subtype = CommandData.SubType;

   /*
   ** Install sigint_handler as the signal handler for SIGINT.
   */
   signal(SIGINT, CFE_PSP_SigintHandler);

   /*
   ** Init timer counter
   */
   TimerCounter = 0;

   /*
   ** Install timer_handler as the signal handler for SIGVTALRM.
   */
   memset (&sa, 0, sizeof (sa));
   sa.sa_handler = &CFE_PSP_TimerHandler;
   sigaction (SIGALRM, &sa, NULL);

   /*
   ** Configure the timer to expire after 250ms
   */
   timer.it_value.tv_sec  = 0;
   timer.it_value.tv_usec = 250000;

   /*
   **  and every 500ms after that.
   */
   timer.it_interval.tv_sec  = 0;
   timer.it_interval.tv_usec = 250000;

   /*
   ** Initialize the OS API data structures
   */
   OS_API_Init();
     
   sleep(1);

   /*
   ** Initialize the reserved memory 
   */
   CFE_PSP_InitProcessorReservedMemory(reset_type);


   /*
   ** Start the timer
   */
   setitimer (ITIMER_REAL, &timer, NULL);


#ifdef CFE_PSP_EEPROM_SUPPORT
   /*
   ** Create the simulated EEPROM segment by mapping a memory segment to a file. 
   ** Since the file will be saved, the "EEPROM" contents will be preserved.
   ** Set up 512Kbytes of EEPROM
   */
   eeprom_size = 0x80000;
   Status = CFE_PSP_SetupEEPROM(eeprom_size, &eeprom_address);
   
   if ( Status == 0 )
   {
      uint32 Dword;
      /*
      ** Install the 2nd memory range as the mapped file ( EEPROM )
      */  
      Status = CFE_PSP_MemRangeSet (1, CFE_PSP_MEM_EEPROM, eeprom_address, 
                                    eeprom_size, CFE_PSP_MEM_SIZE_DWORD, 0 ); 
      OS_printf("CFE_PSP: EEPROM Range (2) created: Start Address = %08X, Size = %08X\n", eeprom_address, eeprom_size);  
      
   }
   else
   {
      OS_printf("CFE_PSP: Cannot create EEPROM Range from Memory Mapped file.\n");
   }
#endif

   /*
   ** Disable Signals to parent thread and therefore all
   ** child threads create will block all signals
   ** Note: Timers will not work in the application unless
   **       threads are spawned in OS_Application_Startup.
   */
   sigfillset(&mask);
   sigdelset(&mask, SIGINT); /* Needed to kill program */
   sigprocmask(SIG_SETMASK, &mask, NULL);


   /*
   ** Raise the priority of the main thread so ES Main completes  
   */
   thread_id = pthread_self(); 
   thread_params.sched_priority = sched_get_priority_max(SCHED_FIFO);
   ret = pthread_setschedparam(thread_id, SCHED_FIFO, &thread_params);
   if ( ret != 0 )
   {
      OS_printf("Unable to set main thread priority to max\n");
   }

   /*
   ** Call cFE entry point.
   */
   CFE_ES_Main(reset_type, reset_subtype, 1, (uint8 *)CFE_ES_NONVOL_STARTUP_FILE); 

   /*
   ** Re-enable Signals to current thread so that
   ** any signals will interrupt in this threads context
   ** ... this is needed for timers
   */
   sigprocmask(SIG_UNBLOCK, &mask, NULL);

   /*
   ** Lower the thread priority to before entering the sleep loop
   */
   thread_params.sched_priority = sched_get_priority_min(SCHED_FIFO);
   ret = pthread_setschedparam(thread_id, SCHED_FIFO, &thread_params);
   if ( ret != 0 )
   {
      OS_printf("Unable to set main thread priority to minimum\n");
   }

   /*
   ** Let the main thread sleep 
   */     
   for ( ;; )
   {
      /* 
      ** Even though this sleep call is for 1 second,
      ** the sigalarm timer for the 1hz will keep waking
      ** it up. Keep that in mind when setting the timer down
      ** to something very small.
      */
      sleep(1);
   }
                 
   return(0);
}
Example #2
0
void CFE_PSP_Main(  int ModeId, char *StartupFilePath )
{
   uint32            reset_type;
   uint32            reset_subtype;
   rtems_status_code RtemsStatus;
   rtems_name        RtemsTimerName;
   
   /*
   ** Initialize the OS API
   */
   OS_API_Init();

   /* 
   ** Create an interval timer for the 1hz
   */
   RtemsTimerName = rtems_build_name('1',' ','H','Z');
   RtemsStatus = rtems_timer_create(RtemsTimerName, &RtemsTimerId);
   if ( RtemsStatus != RTEMS_SUCCESSFUL )
   {
      printf("CFE_PSP: Error: Cannot create RTEMS 1hz interval timer\n");
   }
   
   /*
   ** Allocate memory for the cFE memory. Note that this is malloced on
   ** the COTS board, but will be a static location in the ETU. 
   */
   printf("Sizeof BSP reserved memory = %d bytes\n",sizeof(CFE_PSP_ReservedMemory_t));

   CFE_PSP_ReservedMemoryPtr = malloc(sizeof(CFE_PSP_ReservedMemory_t));

   if ( CFE_PSP_ReservedMemoryPtr == NULL )
   {
      printf("CFE_PSP: Error: Cannot malloc BSP reserved memory!\n");
   }
   else
   {
      printf("CFE_PSP: Allocated %d bytes for PSP reserved memory at: 0x%08X\n",
              sizeof(CFE_PSP_ReservedMemory_t), (int)CFE_PSP_ReservedMemoryPtr);
   }
   /*
   ** Determine Reset type by reading the hardware reset register.
   */
   reset_type = CFE_ES_POWERON_RESET;
   reset_subtype = CFE_ES_POWER_CYCLE;

   /*
   ** Initialize the reserved memory 
   */
   CFE_PSP_InitProcessorReservedMemory(reset_type);

   /*
   ** Call cFE entry point. This will return when cFE startup
   ** is complete.
   */
   CFE_ES_Main(reset_type,reset_subtype, 1, (uint8 *)StartupFilePath); 

   /*
   ** Setup the timer to fire at 1hz 
   */  
   
   /* CLOCK TICK */ 
   RtemsStatus = rtems_timer_fire_after(RtemsTimerId, 100, CFE_PSP_1hzTimer, NULL );
   if ( RtemsStatus != RTEMS_SUCCESSFUL )
   {
      printf("CFE_PSP: Error: Cannot setup interval timer to fire at 1hz\n");
   }
      
   /*
   ** Return to the shell/monitor
   */
   return; 
   
}
Example #3
0
/******************************************************************************
**  Function:  CFE_PSP_Start()
**
**  Purpose:
**    Initialize the PSP and start cFE
**
**  Arguments:
**    ModeId          - Used to indicate which bank of non-volatile memory
**                      was used to boot.  If the bank used to boot this time
**                      is different from the previous boot, then we re-initialize
**                      reserved memory.
**    StartupFilePath - path to cFE startup file to use 
**
**  Return:
**    (none)
*/
void CFE_PSP_Start( int ModeId, char *StartupFilePath )
{
   uint32 reset_type = 0;
   uint32 reset_subtype = 0;
   uint32 status = 0;
   

   /*
    ** Initialize the hardware timer for the local time source
    ** On VxWorks, the default config sets the sysClk to 200 Hz (default 60Hz)
    ** OS_API_Init() calls OS_TimerAPIInit() which gets the
    ** clock resolution of the realtime clock, which is based on the sysClk
    ** and determines the clock accuracy which is used by the scheduler
    ** timers later.  sysClk needs to be at least 200Hz for a 100Hz minor
    ** frame rate.
    */
   CFE_PSP_InitLocalTime();

   /*
   ** Initialize the OS API data structures
   */
   status = OS_API_Init();
   if(status != OS_SUCCESS)
   {
     printf("CFE_PSP_Start() - OS_API_Init() fail, RC = 0x%x\n", status);
   }
 
   /*
   ** Setup the pointer to the reserved area in vxWorks.
   ** This must be done before any of the reset variables are used.
   */
   CFE_PSP_ReservedMemoryPtr = (CFE_PSP_ReservedMemory_t *) sysMemTop();

   printf("CFE_PSP_Main: Reserved Memory Address %08X\n", (uint32)CFE_PSP_ReservedMemoryPtr);

   /* PSP System Initialization */
   CFE_PSP_SysInit(&reset_type, &reset_subtype, CFE_PSP_ReservedMemoryPtr->bsp_reset_type);

   /*
   ** Initialize the watchdog, it's left disabled
   */
   CFE_PSP_WatchdogInit();
   
   /*
   ** Initialize the reserved memory 
   */
   CFE_PSP_InitProcessorReservedMemory(reset_type);
   
    /*
     * Adjust system task priorities so that tasks such as the shell are
     * at a lower priority that the CFS apps
     */
    SetSysTasksPrio();

   /*
   ** Call cFE entry point. This will return when cFE startup
   ** is complete.
   */
   CFE_ES_Main(reset_type, reset_subtype, ModeId, StartupFilePath);

   /*
    * Initializing the 1Hz timer connects the cFE 1Hz ISR for providing the
    * CFS 1Hz time sync, sync the scheduler's 1Hz major frame start to the
    * 1Hz timer.  This call can only occur after CFE_ES_Main() because the
    * 1Hz ISR uses a semaphore that is created when timer services are
    * initialized.
    */
   CFE_PSP_Init1HzTimer();
   CFE_TIME_SetState(CFE_TIME_VALID);
   
   /*
   ** Enable the watchdog
   */
/* CFE_PSP_WatchdogEnable(); really should be enabled in HS */

    printf("CFE_PSP_Start done, exiting.\n");
               
   return;
   
}  /* End CFE_PSP_Main */