⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 《OSEK/VDX汽车电子嵌入式软件编程技术》中光盘的资料
💻 C
字号:
/************************************************
*
*	$Copyright    2001 Joseph J. Lemieux  ALL RIGHTS RESERVED. $
*
*	$Filename: C:\OSEKBook\src\CH13\src\main.c $
*
*	Description:	Main application routines.
*				This module provides the main()
*				entry point that starts the OS 
*				and allows application mode
*				switching.
*
************************************************/
#ifndef MAINC
#define MAINC

#include "typedefs.h"
#include "os.h"
#include "main.h"
#include "init.h"
#include "mpc555.h"

/***
*
* Static Variable used for selected mode.
*
***/
static AppModeType SelectedMode = SINGLE_PLAYER;

/***
*
* Static Variable used for Last Error.
*
***/
static StatusType LastError = E_OK;

/************************************************
*
*   Function:     main
*
*   Inputs:       argc - application specific value
*                        passed by startup code.
*
*   Outputs:      none
*
*   Returns:      void
*
*   Description:  Application specific startup code.
*                 Initializes the application and then
*                 start the operating system.
*
************************************************/

void main(long argc)
{
base_add = 0x00800000;
/*****
*
*   Initialize the 16 and 32 bit registers. The lists
*   are defined in init.cfg.
*
*****/
   InitReg16(InitHardwareRegs16);
   InitReg32(InitHardwareRegs32);

/*****
*
*   Initialize the application based upon a reset. It is
*   up to the individual functions to take action based upon
*   a reset.
*
*****/
   InitSystem(INIT_RESET);
   SelectedMode = SINGLE_PLAYER;
/*****
*
*   WindRiver OSEKWorks specific initialization
*
*****/
   Init_ExtISRs(dummy_isr);  /* Initialize External Interrupts */
/*****
*
*   Start the operating system within an infinite loop. Since
*   the OSEK/VDX operating system can be started and stopped,
*   this routine restarts the OS after shutdown.
*
*****/
   while(1)
   {
      StartOS(SelectedMode);
   }
}

/************************************************
*
*   Function:     ChangeMode
*
*   Inputs:       mode - mode that is being requested.
*
*   Outputs:      none
*
*   Returns:      If mode cannot be switched, returns
*                 ERROR_INVALID_MODE.
*
*   Description:  If the mode is valid, shuts down the OS
*                 and never returns. Otherwise, returns an
*                 error.
*
************************************************/
ApplicationErrorType ChangeMode(AppModeType mode)
{
ApplicationErrorType error=ERROR_NONE;   /* Default to No Error */
/*****
*
*   Check for a valid mode and switch if valid.
*
*****/
	
   if(mode != GetActiveApplicationMode())
   {
      if((mode == SINGLE_PLAYER))
      {
         SelectedMode = SINGLE_PLAYER;
         ActivateTask(CloseOS);
      }
      if((mode == HEAD_TO_HEAD))
      {
         SelectedMode = HEAD_TO_HEAD;
         ActivateTask(CloseOS);
      }
      if((mode == TEST))
      {
         error = ERROR_INVALID_MODE;
      }
/*****
*
* If not valid, return an error.
*
*****/
      error = ERROR_INVALID_MODE;
   }

   return error;
}

/************************************************
*
*   Function:     GetRequestedMode
*
*   Inputs:       void
*
*   Outputs:      none
*
*   Returns:      Selected Application Mode
*
*   Description:  Returns the selected application mode.
*
************************************************/
AppModeType GetRequestedMode(void)
{
   return SelectedMode;
}
/************************************************
*
*   Function:     StartupHook
*
*   Inputs:       none
*
*   Outputs:      none
*
*   Returns:      void
*
*   Description:  Calls InitSystem to initialize the system
*                 based upon an OS startup.
*
************************************************/
void StartupHook(void)
{
   InitSystem(INIT_STARTUP);
   InitCOM();
}

/************************************************
*
*   Function:     ShutdownHook
*
*   Inputs:       StatusType - type of error that occurred.
*
*   Outputs:      Sets static variable LastError to error.
*
*   Returns:      void
*
*   Description:  Calls InitSystem to initialize the system
*                 based upon an OS shutdown after logging error.
*
************************************************/
void ShutdownHook(StatusType error)
{
   if(error!=E_OK)
   {
      LastError = error;
   }
   CloseCOM();
   InitSystem(INIT_SHUTDOWN);
}

/************************************************
*
*   Task:         background
*
*   Description:  Dummy task that is required to get
*                 the system started.
*
************************************************/
TASK(background)
{
   while(1){
   }
}

#endif /* MAINC */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -