Пример #1
0
/* Use to add simulated memory range */
void UTF_AddSimulatedMemory ( int argc, char *argv[])
{
    uint32 data1;
    uint32 data2;
    data1 = 0x1337d00d;
    data2 = 0x3475BEEF;

    UTF_add_sim_address (0x01234000, 16, "MEMORY_BANK" );
    CFE_PSP_MemRangeSet(0, CFE_PSP_MEM_RAM, 0x01234000,
                     16,  CFE_PSP_MEM_SIZE_BYTE,  CFE_PSP_MEM_ATTR_READ);

    UTF_write_sim_address(0x01234000, 4, &data1);
    UTF_write_sim_address(0x01234004, 4, &data2);
    UTF_write_sim_address(0x01234008, 4, &data1);
    UTF_write_sim_address(0x0123400C, 4, &data2);
}
Пример #2
0
int32 CFE_TBL_GetAddress_FunctionHook ( void **TblPtr,
                          CFE_TBL_Handle_t TblHandle )
/* To be used before control is turned over to input command file. */
/* Used in concert with CFE_TBL_Register_FunctionHook to set up test cases. */
/* Count 1: invalid table */
/* Count 2: valid table and unexpected return code */
/* Count 3: valid table with enabled field == TRUE */
/* Count 4: valid table and nominal return code */
{
   static uint32 Count = 0;
   Count++;
   static MD_DwellTableLoad_t DwellTbl;
   static int16 Num1 = 5;
   int32 RetVal;
      
   UTF_put_text("CALL #%d to GetAddress_FunctionHook\n", Count);
          
   CFE_PSP_MemSet(&DwellTbl, 0, sizeof(MD_DwellTableLoad_t));


    /********************************/
    /* Set up Memory                */
    /********************************/
    
    /* Calling CFE_PSP_MemRangeSet makes calls to CFE_PSP_MemValidateRange for this */
    /* range return true. */
    RetVal = CFE_PSP_MemRangeSet(1, CFE_PSP_MEM_RAM, (uint32)&Num1,
                     0x00000002,  CFE_PSP_MEM_SIZE_BYTE,  CFE_PSP_MEM_ATTR_READ);
    if (RetVal != OS_SUCCESS)
    {
       UTF_put_text ("Error return %d from CFE_PSP_MemRangeSet\n", RetVal);
    }
    

/* Recover invalid table w/invalid value for enable flag */
/* for dwell tables #1 and #4                            */
   if (Count == 1)
/* Use for first dwell table */
   {
      /* Set TblPtr to point to an invalid table */
      DwellTbl.Enabled = 17;  /* invalid value */
      DwellTbl.Entry[0].Length = 2;
      DwellTbl.Entry[0].Delay = 1;
      DwellTbl.Entry[0].DwellAddress.Offset = (uint32)&Num1;
      strcpy (DwellTbl.Entry[0].DwellAddress.SymName, "");
      DwellTbl.Entry[1].Length = 0;
      DwellTbl.Entry[1].Delay = 0;
      DwellTbl.Entry[1].DwellAddress.Offset = 0;
   /*   strcpy (DwellTbl.Entry[1].DwellAddress.SymName, ""); */
      DwellTbl.Entry[1].DwellAddress.SymName[0]='\0';

      /* */
      *TblPtr = (void *)&DwellTbl;
      return (CFE_TBL_INFO_UPDATED);
   }

   else if  (Count == 3)
   {
      DwellTbl.Enabled = 1;  
      DwellTbl.Entry[0].Length = 2;
      DwellTbl.Entry[0].Delay = 1;
      DwellTbl.Entry[0].DwellAddress.Offset = (uint32)&Num1;
      strcpy (DwellTbl.Entry[0].DwellAddress.SymName, "");
      DwellTbl.Entry[1].Length = 0;
      DwellTbl.Entry[1].Delay = 0;
      DwellTbl.Entry[1].DwellAddress.Offset = 0;
   /*   strcpy (DwellTbl.Entry[1].DwellAddress.SymName, ""); */
      DwellTbl.Entry[1].DwellAddress.SymName[0]='\0';

      /* */
      *TblPtr = (void *)&DwellTbl;
      return (CFE_TBL_INFO_UPDATED);
   }
   else if (Count == 2)
   {

      *TblPtr = (void *)0;
      return (CFE_TBL_ERR_NO_ACCESS);
   }
/* Recover valid tables */
   else 
   /* this will cover 4th call on initialization, as well as any */
   /* for any updates. */
   {

      /* Set TblPtr to point to a valid table */
      DwellTbl.Enabled = MD_DWELL_STREAM_DISABLED;
      DwellTbl.Entry[0].Length = 2;
      DwellTbl.Entry[0].Delay = 1;
      DwellTbl.Entry[0].DwellAddress.Offset = (uint32)&Num1;
      strcpy (DwellTbl.Entry[0].DwellAddress.SymName, "");
      DwellTbl.Entry[1].Length = 0;
      DwellTbl.Entry[1].Delay = 0;
      DwellTbl.Entry[1].DwellAddress.Offset = 0;
      strcpy (DwellTbl.Entry[1].DwellAddress.SymName, "");

      /* */
      *TblPtr = (void *)&DwellTbl;
      return (CFE_TBL_INFO_UPDATED);
   }
}
Пример #3
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);
}
Пример #4
0
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int main(void)
{
   char AppName[10];
   UTF_SymbolTable_t    UTF_Symbol;

   strcpy(AppName, "MM");
   
   /*
   ** Set up to read in script
   */
   UTF_add_input_file(MM_CMD_PIPE, "mm_utf_cmds.in");
   MM_AppData.CmdPipe = MM_CMD_PIPE;  /* Hook for application code */
   
   /*
   ** Set up output file and HK packet handler           
   */
   UTF_set_output_filename("mm_utf_test.out");
   UTF_set_packet_handler(MM_HK_TLM_MID, (utf_packet_handler)PrintHKPacket);
    
   /* 
   ** Set up simulated memory for loads and dumps 
   */
   UTF_add_sim_address(SIM_RAM_MEM_ADDR, SIM_RAM_MEM_SIZE, 
                                         "MM_RAM_ADDRESS_SPACE");

   UTF_add_sim_address(SIM_EEPROM_MEM_ADDR, SIM_EEPROM_MEM_SIZE, 
                                            "MM_EEPROM_ADDRESS_SPACE");
   
   /*
   ** Add these ranges to the OSAL memory table so the CFE_PSP_MemValidateRange 
   ** routine won't barf on them. We set these ranges much bigger than we're
   ** going to need so we can test bounds checking in MM and not 
   ** CFE_PSP_MemValidateRange.
   */
   CFE_PSP_MemRangeSet(0, CFE_PSP_MEM_RAM, SIM_RAM_MEM_ADDR, (MM_MAX_LOAD_FILE_DATA_RAM * 2), 
                                          CFE_PSP_MEM_SIZE_BYTE, CFE_PSP_MEM_ATTR_READWRITE);

   CFE_PSP_MemRangeSet(1, CFE_PSP_MEM_EEPROM, SIM_EEPROM_MEM_ADDR, (MM_MAX_LOAD_FILE_DATA_EEPROM * 10), 
                                                   CFE_PSP_MEM_SIZE_BYTE, CFE_PSP_MEM_ATTR_READWRITE);

   /*
   ** Setup the UTF symbol table structures
   */
   UTF_InitSymbolTable();
   
   strcpy(UTF_Symbol.symbolName, "GoodSymName");
   UTF_Symbol.symbolAddr = SIM_RAM_MEM_ADDR;
   
   UTF_SetSymbolTableEntry(UTF_Symbol);
   
   /*
   ** Initialize time data structures
   */
   UTF_init_sim_time(0.0);
   UTF_OSAPI_set_function_hook(OS_GETLOCALTIME_HOOK, TimeHook);

   /*
   ** Initialize the PSP EEPROM Write Ena/Dis return status
   */
   
   UTF_PSP_Set_Api_Return_Code(CFE_PSP_EEPROMWRITEENA_PROC, CFE_PSP_SUCCESS);
   UTF_PSP_Set_Api_Return_Code(CFE_PSP_EEPROMWRITEDIS_PROC, CFE_PSP_SUCCESS);

   /*
   ** Register app MM with executive services.                         
   */
   UTF_ES_InitAppRecords();
   UTF_ES_AddAppRecord("MM",0);  
   CFE_ES_RegisterApp();
   CFE_EVS_Register(NULL, 0, CFE_EVS_BINARY_FILTER);
   
   /*
   ** Initialize table services data structures, though we
   ** don't use any tables for these tests
   */
   CFE_ES_CDS_EarlyInit();
   CFE_TBL_EarlyInit();

   /*
   ** Add an entry to the volume table
   */
   UTF_add_volume("/", "ram", FS_BASED, FALSE, FALSE, TRUE, "RAM", "/ram", 0);

   /*
   ** Add this hook so we can force a software bus read error
   ** in our command input file that will make the application exit
   */
   UTF_add_special_command("SET_SB_RETURN_CODE", UTF_SCRIPT_SB_Set_Api_Return_Code);
   UTF_add_special_command("SET_PSP_RETURN_CODE", UTF_SCRIPT_PSP_Set_Api_Return_Code);

   /*
   ** Initialize the CRC value for our test data set
   */
   MM_TestDataSetCRC = CFE_ES_CalculateCRC(MM_TestDataSet, sizeof(MM_TestDataSet),
                                                           0, CFE_ES_DEFAULT_CRC);
   /*
   ** This is a function stub in cfs_utils.c that does nothing, but
   ** by calling it here we can increase our coverage statistics, so
   ** why not?
   */
   CFS_LibInit();
   
   /*
   ** Call test functions that invoke MM code directly 
   */
   printf("***UTF MM DRIVER TESTS START***\n\n");
   UTF_put_text("\n");
   UTF_put_text("***UTF MM DRIVER TESTS START***");
   UTF_put_text("\n\n");

   Test_Pokes();
   Test_Peeks();
   Test_LoadWID();
   Test_DumpInEvent();
   Test_LoadFromFile();
   Test_DumpToFile();
   Test_Fill();
   Test_SymLookup();
   Test_SymTblDump();
   
   printf("***UTF MM DRIVER TESTS END***\n\n");
   UTF_put_text("\n");
   UTF_put_text("***UTF MM DRIVER TESTS END***");
   UTF_put_text("\n\n");
   
   /* 
   ** Call Application Main procedure that will test command 
   ** processing through the software bus command pipe via
   ** the mm_utf_cmds.in command script
   */
   printf("***UTF MM CMD PIPE TESTS START***\n\n");
   UTF_put_text("\n");
   UTF_put_text("***UTF MM CMD PIPE TESTS START***");
   UTF_put_text("\n\n");
   
   MM_AppMain();
    
   printf("***UTF MM CMD PIPE TESTS END***\n\n");
   UTF_put_text("\n");
   UTF_put_text("***UTF MM CMD PIPE TESTS END***");
   UTF_put_text("\n\n");

   /*
   ** These tests force some CFE api error returns
   ** during MM initialization. This increases
   ** the gcov coverage metrics for the app startup
   ** code.
   */
   printf("***UTF MM APP INIT TESTS START***\n\n");
   UTF_put_text("\n");
   UTF_put_text("***UTF MM APP INIT TESTS START***");
   UTF_put_text("\n\n");
 
   UTF_put_text("\n");
   UTF_put_text("Test App Init Error conditions \n");
   UTF_put_text("-------------------------------\n");
   
   /*
   ** Set trigger so CFE_EVS_Register returns something
   ** other than CFE_SUCCESS (0). Then call app main, this
   ** should make the app init fail.
   */
   UTF_CFE_EVS_Set_Api_Return_Code(CFE_EVS_REGISTER_PROC, 0xc2000003L);
   MM_AppMain();

   /* Go back to "normal" behavior */
   UTF_CFE_EVS_Use_Default_Api_Return_Code(CFE_EVS_REGISTER_PROC);
   
   /*
   ** Set trigger so CFE_SB_CreatePipe returns an error code
   */
   UTF_CFE_SB_Set_Api_Return_Code(CFE_SB_CREATEPIPE_PROC, 0xca000004L);
   MM_AppMain(); 
   UTF_CFE_SB_Use_Default_Api_Return_Code(CFE_SB_CREATEPIPE_PROC); 
   
   /*
   ** Set trigger so CFE_SB_Subscribe returns an error code
   */
   UTF_CFE_SB_Set_Api_Return_Code(CFE_SB_SUBSCRIBE_PROC, 0xca000009L);
   MM_AppMain();
   UTF_CFE_SB_Use_Default_Api_Return_Code(CFE_SB_SUBSCRIBE_PROC); 

   /*
   ** Hook our own custom function to CFE_SB_Subscribe so we can
   ** trigger an error return on the SECOND call in MM_AppInit
   */
   UTF_SB_set_function_hook(CFE_SB_SUBSCRIBE_HOOK, (void *)&CFE_SB_SubscribeHook);
   MM_AppMain();
   
   printf("***UTF MM APP INIT TESTS END***\n\n");
   UTF_put_text("\n");
   UTF_put_text("***UTF MM APP INIT TESTS END***");
   UTF_put_text("\n\n");
   
   return 0;
   
} /* end main */