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

📄 general_definitions.c

📁 嵌入式操作系统EOS(Embedded OperatingSystem)是一种用途广泛的系统软件
💻 C
字号:
/*
** Copyright (C) 2006 Tamir Michael
**  
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
** 
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
** 
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software 
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

#include <stdio.h>
#include <XC167.h>
#include <stdarg.h>

#include "general_definitions.h"
#include "rtos_services.h"

// user defined callback in case of system failure
extern callback_ptr     g_system_failure_hook ;
// the inirial values for these constants were best suited for a 32 bit machine, actually.
static const int32s s_A = 1366, s_C = 150889, s_M = 714025 ;
static 		 int32s	s_R = 0 ;

// system failure
void software_error(const char* a_fmt, ...)
{
	char 	l_buffer[0x80] ;
	va_list l_arg_ptr ;

	PSW_IEN = 0 ; // freeze the system in the condition that let to its failure. could be valuable for analysis.

	va_start(l_arg_ptr, a_fmt) ;
	vsprintf(l_buffer, a_fmt, l_arg_ptr) ;
	va_end(l_arg_ptr) ;

	printf("SOFTWARE ERROR:%s\n", l_buffer) ;

	// the following commands will cause the system to freeze in the state when things went wrong.
	// if the software error was reported in interrupt context, the interrupt will remain active (due to the infinite
	// loop) and the system will hang after reporting the error. for errors that are reported from task context, the
	// scheduler/interrupts is stopped as well (so that the preemptive scheduler cannot select another task).
    // in simulator mode, this also allows to look at the call stack.

	if (g_system_failure_hook)
	{
		g_system_failure_hook(0) ;
	}

	while(1) ; // hang here
}

void software_warning(const char* a_fmt, ...)
{
	char 	l_buffer[0x80] ;
	va_list l_arg_ptr ;
	
	va_start(l_arg_ptr, a_fmt) ;
	vsprintf(l_buffer, a_fmt, l_arg_ptr) ;
	va_end(l_arg_ptr) ;

	printf("SOFTWARE WARNING:%s\n", l_buffer) ;
}

int32s g_generate_random_id()
{
	// R(n) = ( (A * R(n-1) + C) mod M)
	s_R = (s_A * s_R + s_C) % s_M ;

	return s_R ;
}

⌨️ 快捷键说明

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