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

📄 133.htm

📁 pcb设计资料初学者难得的入门资料包含工厂制作过程
💻 HTM
📖 第 1 页 / 共 5 页
字号:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>CTerm非常精华下载</title>
</head>
<body bgcolor="#FFFFFF">
<table border="0" width="100%" cellspacing="0" cellpadding="0" height="577">
<tr><td width="32%" rowspan="3" height="123"><img src="DDl_back.jpg" width="300" height="129" alt="DDl_back.jpg"></td><td width="30%" background="DDl_back2.jpg" height="35"><p align="center"><a href="http://202.112.58.200"><font face="黑体"><big><big>Tsinghua</big></big></font></a></td></tr>
<tr>
<td width="68%" background="DDl_back2.jpg" height="44"><big><big><font face="黑体"><p align="center">         嵌入式系统                            (BM: turbolinux jacobw)          </font></big></big></td></tr>
<tr>
<td width="68%" height="44" bgcolor="#000000"><font face="黑体"><big><big><p   align="center"></big></big><a href="http://cterm.163.net"><img src="banner.gif" width="400" height="60" alt="banner.gif"border="0"></a></font></td>
</tr>
<tr><td width="100%" colspan="2" height="100" align="center" valign="top"><br><p align="center">[<a href="嵌入式系统.htm">回到开始</a>][<a href="62.htm">上一层</a>][<a href="134.htm">下一篇</a>]
<hr><p align="left"><small>寄信人: sunno (民工★节网失败ing) <br>

标  题: 【源代码】ucos (c code)                camera (转寄) (转载) <br>

发信站: BBS 水木清华站 (Sat Apr 15 14:13:54 2000) <br>

来  源: 166.111.7.200 <br>

(本文转载自circuit精华区) <br>

  <br>

【 原文由 mot 所发表 】 <br>

/* <br>

********************************************************************************************************** <br>

*                                                 uC/OS <br>

*                                          The Real-Time Kernel <br>

*                                                 KERNEL <br>

* <br>

*                        (c) Copyright 1992-1995, Jean J. Labrosse, Plantation, FL <br>

*                                           All Rights Reserved <br>

* <br>

*                                                  V1.08 <br>

* <br>

* File : UCOS.C <br>

* By   : Jean J. Labrosse <br>

********************************************************************************************************** <br>

*/ <br>

  <br>

  <br>

#define  OS_GLOBALS <br>

#include "INCLUDES.H" <br>

  <br>

/* <br>

********************************************************************************************************** <br>

*                                              CONSTANTS <br>

********************************************************************************************************** <br>

*/ <br>

  <br>

#define  OS_LO_PRIO          63        /* IDLE task priority <br>

  <br>

                                       /* TASK STATUS <br>

#define  OS_STAT_RDY       0x00        /* Ready to run <br>

#define  OS_STAT_SEM       0x01        /* Pending on semaphore <br>

#define  OS_STAT_MBOX      0x02        /* Pending on mailbox <br>

#define  OS_STAT_Q         0x04        /* Pending on queue <br>

#define  OS_STAT_SUSPEND   0x08        /* Task is suspended <br>

/*$PAGE*/ <br>

/* <br>

********************************************************************************************************** <br>

*                              MAPPING TABLE TO MAP BIT POSITION TO BIT MASK <br>

* <br>

* <br>

* Note: Index into table is desired bit position, 0..7 <br>

*       Indexed value corresponds to bit mask <br>

********************************************************************************************************** <br>

*/ <br>

  <br>

UBYTE const OSMapTbl[]   = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80}; <br>

  <br>

/* <br>

********************************************************************************************************** <br>

*                                       PRIORITY RESOLUTION TABLE <br>

* <br>

* Note: Index into table is bit pattern to resolve highest priority <br>

*       Indexed value corresponds to highest priority bit position (i.e. 0..7) <br>

********************************************************************************************************** <br>

*/ <br>

  <br>

UBYTE const OSUnMapTbl[] = { <br>

    0, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, <br>

    4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, <br>

    5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, <br>

    4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, <br>

    6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, <br>



    4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, <br>

    5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, <br>

    4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, <br>

    7, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, <br>

    4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, <br>

    5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, <br>

    4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, <br>

    6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, <br>

    4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, <br>

    5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, <br>

    4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0 <br>

}; <br>

/*$PAGE*/ <br>

/* <br>

********************************************************************************************************** <br>

*                                            LOCAL VARIABLES <br>

********************************************************************************************************** <br>

*/ <br>

  <br>

static  OS_TCB     *OSTCBList;                 /* Pointer to doubly linked list of TCBs                */ <br>

static  UBYTE       OSRdyGrp;                  /* Ready list group <br>

static  UBYTE       OSRdyTbl[8];               /* Table of tasks which are readyy to run                */ <br>



static  UBYTE       OSLockNesting;             /* Multitasking lock nesting leveel                      */ <br>

static  OS_TCB     *OSTCBFreeList;             /* Pointer to list of free TCBs                         */ <br>

static  OS_EVENT   *OSEventFreeList;           /* Pointer to list of free EVENT control blocks         */ <br>

static  OS_Q       *OSQFreeList;               /* Pointer to list of free QUEUE control blocks         */ <br>

static  ULONG       OSTime;                    /* Current value of system time ((in ticks)              */ <br>

static  UBYTE       OSIntExitY;                /* Variable used by 'OSIntExit' tto prevent using locals */ <br>

static  OS_STK_TYPE OSTaskIdleStk[OS_IDLE_TASK_STK_SIZE];  /* Idle task stack <br>

static  OS_TCB      OSTCBTbl[OS_MAX_TASKS+1];              /* Table of TCBs <br>

static  OS_EVENT    OSEventTbl[OS_MAX_EVENTS];             /* Table of EVENT conntrol blocks            */ <br>

static  OS_Q        OSQTbl[OS_MAX_QS];                     /* Table of QUEUE conntrol blocks            */ <br>

  <br>

  <br>

/* <br>

********************************************************************************************************** <br>

*                                       LOCAL FUNCTION PROTOTYPES <br>

********************************************************************************************************** <br>

*/ <br>

  <br>

static  void OS_FAR OSTaskIdle(void *data); <br>

static  void        OSDummy(void); <br>

/*$PAGE*/ <br>

/* <br>

/* <br>

********************************************************************************************************** <br>

*                                         uC/OS INITIALIZATION <br>

********************************************************************************************************** <br>

*/ <br>

  <br>

void OSInit(void) <br>

{ <br>

    UBYTE i; <br>

  <br>

  <br>

    OSTime        = 0L; <br>

    OSTCBHighRdy  = (OS_TCB *)0; <br>

    OSTCBCur      = (OS_TCB *)0; <br>

    OSTCBList     = (OS_TCB *)0; <br>

    OSIntNesting  = 0; <br>

    OSLockNesting = 0; <br>

    OSRunning     = FALSE;                                 /* Indicate that multtitasking not started   */ <br>

    OSIdleCtr     = 0L; <br>

    OSCtxSwCtr    = 0; <br>

    OSRdyGrp      = 0;                                     /* Clear the ready liist                     */ <br>

    for (i = 0; i < 8; i++) { <br>

        OSRdyTbl[i] = 0; <br>



    } <br>

    for (i = 0; i < 64; i++) {                             /* Clear the priorityy table                 */ <br>

        OSTCBPrioTbl[i] = (OS_TCB *)0; <br>

    } <br>

    for (i = 0; i < OS_MAX_TASKS; i++) {                   /* Init. list of freee TCBs                  */ <br>

        OSTCBTbl[i].OSTCBNext = &OSTCBTbl[i+1]; <br>

    } <br>

    OSTCBTbl[OS_MAX_TASKS].OSTCBNext = (OS_TCB *)0;        /* Last OS_TCB is forr OSTaskIdle()          */ <br>

    OSTCBFreeList                    = &OSTCBTbl[0]; <br>

    for (i = 0; i < (OS_MAX_EVENTS - 1); i++) {            /* Init. list of freee EVENT control blocks  */ <br>

        OSEventTbl[i].OSEventPtr = &OSEventTbl[i+1]; <br>

    } <br>

    OSEventTbl[OS_MAX_EVENTS - 1].OSEventPtr = (OS_EVENT *)0; <br>

    OSEventFreeList                          = &OSEventTbl[0]; <br>

    for (i = 0; i < (OS_MAX_QS - 1); i++) {                /* Init. list of freee QUEUE control blocks  */ <br>

        OSQTbl[i].OSQPtr = &OSQTbl[i+1]; <br>

    } <br>

    OSQTbl[OS_MAX_QS - 1].OSQPtr = (OS_Q *)0; <br>

    OSQFreeList                  = &OSQTbl[0]; <br>

    OSTaskCreate(OSTaskIdle, (void *)0, (void *)&OSTaskIdleStk[OS_IDLE_TASK_STK__TOP], OS_LO_PRIO); <br>

} <br>

  <br>

  <br>

/* <br>

********************************************************************************************************** <br>

*                                              IDLE TASK <br>

********************************************************************************************************** <br>

*/ <br>

  <br>

static void OS_FAR OSTaskIdle(void *data) <br>

{ <br>

    data = data; <br>

    while (1) { <br>

        OS_ENTER_CRITICAL(); <br>

        OSIdleCtr++; <br>

        OS_EXIT_CRITICAL(); <br>

    } <br>

} <br>

/*$PAGE*/ <br>

/* <br>

********************************************************************************************************** <br>

*                                          START MULTITASKING <br>

********************************************************************************************************** <br>

*/ <br>

  <br>

  <br>

void OSStart(void) <br>

{ <br>

    UBYTE y; <br>

    UBYTE x; <br>

    UBYTE prio; <br>

  <br>

  <br>

    y             = OSUnMapTbl[OSRdyGrp];        /* Find highest priority's taskk priority number       */ <br>

    x             = OSUnMapTbl[OSRdyTbl[y]]; <br>

    prio          = (y << 3) + x; <br>

    OSTCBHighRdy  = OSTCBPrioTbl[prio];          /* Point to highest priority taask ready to run        */ <br>

    OSTCBCur      = OSTCBHighRdy; <br>

    OSRunning     = TRUE; <br>

    OSStartHighRdy();                            /* Execute target specific codee to start task         */ <br>

} <br>

  <br>

  <br>

/* <br>

********************************************************************************************************** <br>

*                                            uC/OS SCHEDULER <br>

********************************************************************************************************** <br>

*/ <br>

*/ <br>

  <br>

void OSSched(void) <br>

{ <br>

    UBYTE y; <br>

  <br>

  <br>

    OS_ENTER_CRITICAL(); <br>

    if ((OSLockNesting | OSIntNesting) == 0) {   /* Task scheduling must be enabbled and not ISR level  */ <br>

        y             = OSUnMapTbl[OSRdyGrp];    /* Get pointer to highest priorrity task ready to run  */ <br>

        OSTCBHighRdy  = OSTCBPrioTbl[(y << 3) + OSUnMapTbl[OSRdyTbl[y]]]; <br>

        if (OSTCBHighRdy != OSTCBCur) {          /* Make sure this is not the cuurrent task running     */ <br>

            OSCtxSwCtr++;                        /* Increment context switch couunter                   */ <br>

            OS_TASK_SW();                        /* Perform a context switch <br>

        } <br>

    } <br>

    OS_EXIT_CRITICAL(); <br>

} <br>

/*$PAGE*/ <br>

/* <br>

********************************************************************************************************** <br>

*                                          PREVENT SCHEDULING <br>

********************************************************************************************************** <br>



*/ <br>

  <br>

void OSSchedLock(void) <br>

{ <br>

    if (OSRunning == TRUE) {                     /* Make sure multitasking is ruunning                  */ <br>

        OS_ENTER_CRITICAL(); <br>

        OSLockNesting++;                         /* Increment lock nesting levell                       */ <br>

        OS_EXIT_CRITICAL(); <br>

    } <br>

} <br>

⌨️ 快捷键说明

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