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

📄 os_cpu_c.c

📁 ucosii的实用程序
💻 C
字号:
// os_cpu_c.c 
//
// Port of uC/OS-II (C) to the Intel 80x86 (32-bit flat protected mode)
// By Jean L. Gareau (jean.gareau@exposecorp.com)
//
// Copyright (C) 1997-1999, Jean L. Gareau. All rights reserved. 
// This file or its content can not be used for commercial applications 
// without the prior written permission of the author.
//
// (c)2000 Anton Civit (civit@icaro.fie.us.es) Port to Borland's C++ V5.2 and
// On Time Systems RTTarget32 V2.0
//
// Description:
//	This file contains the C routines of the port (see Ix86pm_a.asm for the
//      assembly language routines). 
//
// Development Environment:
//      This file has been developed with Borlands C++ V5.2  
 //	it can be compiled using the following command:
//
//     BCC32 -n UserProg.c ucos_ii.c os_cpu_a.asm rtt32.lib
//
// or  BCC32 -n UserProg.c ucos_ii.c os_cpu_a.asm rtt32.lib pc386.c
//if auxiliary PC functions are used.
//
//  The macro _DEBUG can be enabled to dump the stack of unexpected interrupts, 
//	as in: #define _DEBUG. Note that Ix86p_a.asm must also be assembled with
//	_DEBUG defined as well.
//
// Versions:
//	1.00 14-Dec-97	Initial release.
//	2.00 28-Feb-99	Upgrade from uC/OS to uC/OS-II
//      2.00B 29-Feb-2000 Port to Borland飐 C++ V5.2 and RTTarget32 


#include "os_cpu.h"
#include "os_cfg.h"
#include "ucos_ii.h"

#ifdef _DEBUG
#include <stdlib.h>						// for itoa()
#endif

// Intel 8259 ports
#define I8259_A0	0x020				// 8259 #1, port #1
#define I8259_A1	0x021				// 8259 #1, port #2
#define I8259_B0	0x0a0				// 8259 #2, port #1
#define I8259_B1	0x0a1				// 8259 #2, port #2

// Prototypes
static void TaskBucket();

#ifdef _DEBUG
extern void OnScreen(int x, int y, char * pszText, int nColor);
#endif

///////////////////////////////////////////////////////////////////////////////
// uCOS-II Functions

// OSCpuInit()
// Performs CPU-dependent intiailization.

void OSCpuInit()
{
	int	IntNo;

        // Init A20 and PIC is done by RTTarget32.
        // Install a default handler for all supported interrupts: Done by RtTarget
	//	a) 0x00-0x1F: Intel-reserved
        //         0x20 Reserved
        //         0x21 RTTarget DOS Emulation
        //         0x22-0x30 Reserved
        //         0x31 RTTarget DPMI Emulation     
        //      b) 0x40-0x4F: IRQ (relocated)
        //         0x50-0x5F: See RTTarget documentation.     
        //      c) 0x70-0x7F: Available for uCOS and application.


#ifdef _DEBUG
	// Install a dump stack handler for int 13 (General Protection Fault).
        RTSetIntVector(13, DumpStackHandler);
#endif
        RTDisableIRQ(0);
        RTSetIntVector(0x40, OSTickISR);                  // Install the tick handler 
        RTSetIntVector(uCOS, OSCtxSw);                    // Install uCOS-II's context switch handler
        RTEnableIRQ(0);
}

// OSTaskStkInit()
// This is a uCOS-II function. Only the stack setup part needs some modifications.

void * OSTaskStkInit(void (*task)(void *pd), void *pdata, void *ptos, INT16U opt)
{
	OS_STK*	stk;

	stk = (OS_STK *) ptos;			// Load stack pointer

	*--stk = (INT32U) pdata;			// Simulate a function call (to pass the parameter)
	*--stk = (INT32U) TaskBucket;	// Return address in case the task exits.

	*--stk = 0x00000202;			// Eflags (interrupt flag enabled)
	*--stk = CS_SELECTOR;			// CS
	*--stk = (INT32U) task;			// Entry point

	*--stk = 0;						// EAX
	*--stk = 0;						// ECX
	*--stk = 0;						// EDX
	*--stk = 0;						// EBX
	*--stk = 0;						// ESP (unused)
	*--stk = 0;						// EBP
	*--stk = 0;						// ESI
	*--stk = 0;						// EDI

    return stk;
}

// TaskBucket()
// This is the function that is executed if a task inadvertedly
// returns from its main function. This is specified in OSTaskStkInit(),
// when a task's stack is being intialized.

void TaskBucket()
{
	while (1)
		;
}

/*$PAGE*/
//Original Labrosse version from now
#if OS_CPU_HOOKS_EN
/*
*********************************************************************************************************
*                                          TASK CREATION HOOK
*
* Description: This function is called when a task is created.
*
* Arguments  : ptcb   is a pointer to the task control block of the task being created.
*
* Note(s)    : 1) Interrupts are disabled during this call.
*********************************************************************************************************
*/
void OSTaskCreateHook (OS_TCB *ptcb)
{
    ptcb = ptcb;                       /* Prevent compiler warning                                     */
}


/*
*********************************************************************************************************
*                                           TASK DELETION HOOK
*
* Description: This function is called when a task is deleted.
*
* Arguments  : ptcb   is a pointer to the task control block of the task being deleted.
*
* Note(s)    : 1) Interrupts are disabled during this call.
*********************************************************************************************************
*/
void OSTaskDelHook (OS_TCB *ptcb)
{
    ptcb = ptcb;                       /* Prevent compiler warning                                     */
}

/*
*********************************************************************************************************
*                                           TASK SWITCH HOOK
*
* Description: This function is called when a task switch is performed.  This allows you to perform other
*              operations during a context switch.
*
* Arguments  : none
*
* Note(s)    : 1) Interrupts are disabled during this call.
*              2) It is assumed that the global pointer 'OSTCBHighRdy' points to the TCB of the task that
*                 will be 'switched in' (i.e. the highest priority task) and, 'OSTCBCur' points to the 
*                 task being switched out (i.e. the preempted task).
*********************************************************************************************************
*/
void OSTaskSwHook (void)
{
}

/*
*********************************************************************************************************
*                                           STATISTIC TASK HOOK
*
* Description: This function is called every second by uC/OS-II's statistics task.  This allows your 
*              application to add functionality to the statistics task.
*
* Arguments  : none
*********************************************************************************************************
*/
void OSTaskStatHook (void)
{
}

/*
*********************************************************************************************************
*                                               TICK HOOK
*
* Description: This function is called every tick.
*
* Arguments  : none
*
* Note(s)    : 1) Interrupts may or may not be ENABLED during this call.
*********************************************************************************************************
*/
void OSTimeTickHook (void)
{
}
#endif

⌨️ 快捷键说明

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