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

📄 debug.c

📁 《OSEK/VDX汽车电子嵌入式软件编程技术》中光盘的资料
💻 C
字号:
/************************************************
*
*	$Copyright    2001 Joseph J. Lemieux  ALL RIGHTS RESERVED. $
*
*	$Filename: C:\OSEKBook\src\CH07\src\debug.c $
*
*	Description:  Module that contains routines to aid in
*                  the debugging of an application.
*
************************************************/
#ifndef DEBUGC
#define DEBUGC

/************************************************
*
*	Include files
*
************************************************/

#include "typedefs.h"
#include "os.h"
#include "debug.h"

/************************************************
*
*	Local macros
*
************************************************/

/************************************************
*
*	Local type definitions
*
************************************************/
/***
*
* Type of structure that holds the error information
*
***/

typedef struct ERROR_LOG_TYPEtag {
   StatusType error;
   TaskType task;
   }ERROR_LOG_TYPE;

/************************************************
*
*	Local Function Prototypes
*
************************************************/
UINT64 GetRealTimeClock(void);

/************************************************
*
*	Local Variables
*
************************************************/
/***
*
* Define error log and a pointer to the next
* entry in the log to be updated.
*
***/
ERROR_LOG_TYPE errorLog[10] = {
   {E_OK,(TaskType)0},
   {E_OK,(TaskType)0},
   {E_OK,(TaskType)0},
   {E_OK,(TaskType)0},
   {E_OK,(TaskType)0},
   {E_OK,(TaskType)0},
   {E_OK,(TaskType)0},
   {E_OK,(TaskType)0},
   {E_OK,(TaskType)0},
   {E_OK,(TaskType)0}
   };
ERROR_LOG_TYPE *nextErrorLog = errorLog;

UINT64 enterTime=0,exitTime=0,timeInBackground=0,timeOutOfBackground=0;

/************************************************
*
*	Local Constants
*
************************************************/

/************************************************
*
*	Functions
*
************************************************/
/************************************************
*
*   Function:     ErrorHook
*
*   Inputs:       StatusType - type of error that occurred.
*
*   Outputs:      Updates the Error Log.
*
*   Returns:      void
*
*   Description:  Adds the error to the log and updates
*                 the pointer.
*
************************************************/
void ErrorHook(StatusType error)
{
/***
*
* Store error and update pointer
*
***/
   nextErrorLog->error = error;
   GetTaskID(&nextErrorLog->task);
   ++nextErrorLog;
/***
*
* Limit pointer to buffer
*
***/
   if(nextErrorLog > &errorLog[9])
   {
      nextErrorLog = errorLog;
   }
}

/************************************************
*
*   Function:     PreTaskHook
*
*   Inputs:       none
*
*   Outputs:      none
*
*   Returns:      void
*
*   Description:  Hook routine that is called just 
*                 before a task obtains the CPU.
*
************************************************/
void PreTaskHook(void)
{
	TaskType enteringTask;
	GetTaskID(&enteringTask);
	if(enteringTask == background){
		enterTime = GetRealTimeClock();
      if(exitTime != 0){
      timeOutOfBackground += enterTime-exitTime;
      }
   }
}

/************************************************
*
*   Function:     PostTaskHook
*
*   Inputs:       none
*
*   Outputs:      none
*
*   Returns:      void
*
*   Description:  Hook routine that is called just 
*                 before a task obtains the CPU.
*
************************************************/
void PostTaskHook(void)
{
	TaskType exitingTask;
	GetTaskID(&exitingTask);
	if(exitingTask == (TaskType)background){
		exitTime = GetRealTimeClock();
      timeInBackground += exitTime-enterTime;
   }
}

/************************************************
*
*   Function:     GetRealTimeClock
*
*   Inputs:       none
*
*   Outputs:      none
*
*   Returns:      64 bit value of the clock.
*
*   Description:  Obtains the real time clock of the MPC555
*
************************************************/
UINT64 GetRealTimeClock(void)
{
   asm(" mftbu r3");
   asm(" mftb r4");
	return;
}

#endif /* DEBUGC */

⌨️ 快捷键说明

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