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

📄 os_cpu_c.c

📁 uCosII+543+lcd 128*64 汉字显示
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
*********************************************************************************************************
*                                               uC/OS-II
*                                         The Real-Time Kernel
*
*                         (c) Copyright 1992-1999, Jean J. Labrosse, Weston, FL
*                                          All Rights Reserved
*
*
*                                       Fujitsu F2MC-16LX Specific code
*                                             ALL MEMORY MODELS
*
*                                   FFMC-16 Family Softune C Compiler V30L03.
*
* File         : OS_CPU_C.C
* By           : Andrey Mozzhevilov. Yekaterinburg. Russia. andy@svrw.ru, andy_moz@mail.ru
*                                                           www.geocities.com/andy_moz
*                Some ideas by Sergey Pinigin.
*
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*
*                                         REVISION HISTORY
*
*
* Port Version : 1.00
* Date         : 07-December-2001
*
* By          : Andrey Mozzhevilov.
*
* Description : Main version
*
*
*
* Sub Version : 1.01
*
* Updated     : 24-January-2002
* By          : Andrey Mozzhevilov.
*               Thanks Wiktor Widlinski for bug-report
*
* Description : Corrected OSTaskStkInit for Compact, Medium and Large memory models.
*
*
*********************************************************************************************************
*/




#include "includes.h"

/* ------- Memory models ---------      default address size */
                                 /*     data      code       */
#define SMALL     0              /*    16 Bit    16 Bit      */
#define MEDIUM    1              /*    16 Bit    24 Bit      */
#define COMPACT   2              /*    24 Bit    16 Bit      */
#define LARGE     3              /*    24 Bit    24 Bit      */

/* You should use one of the these lines or define MEMMODEL_xxx by option "-D" compiler */
/*#define MEMMODEL_SMALL*/
/*#define MEMMODEL_COMPACT*/
/*#define MEMMODEL_MEDIUM */
#define MEMMODEL_LARGE

#ifndef MEMMODEL_SMALL
  #ifndef MEMMODEL_COMPACT
    #ifndef MEMMODEL_MEDIUM
      #ifndef MEMMODEL_LARGE
        #error MEMMODEL_...... must be specify
      #endif
    #endif
  #endif
#endif

#ifdef MEMMODEL_SMALL
  #define MEMMODEL SMALL
#endif

#ifdef MEMMODEL_COMPACT
  #define MEMMODEL COMPACT
#endif

#ifdef MEMMODEL_MEDIUM
  #define MEMMODEL MEDIUM
#endif

#ifdef MEMMODEL_LARGE
  #define MEMMODEL LARGE
#endif

#if OS_SCAN_FREE_BANK != 0
#define  AVAIL_BANK_MASK ((INT32U)((((INT32U)0xffffffff)<<FIRST_TASK_BANK) & (((INT32U)0xffffffff)>>(31-LAST_TASK_BANK))))
#endif

INT16U Get_DPR_ADB_bank(void); /* Get current value of DPR and ADB registers */
INT16U Get_DTB_PCB_bank(void); /* Get current value of DTB and PCB registers */
INT8U Get_RP(void);            /* Get current register pointer               */

#if MEMMODEL == SMALL || MEMMODEL == COMPACT
#pragma asm
        .SECTION        CODE, CODE, ALIGN=1
_Get_DPR_ADB_bank:
    MOV A, DPR
    SWAP
    MOV A, ADB
    ORW A
    RET

_Get_DTB_PCB_bank:
    MOV A, DTB
    SWAP
    MOV A, PCB
    ORW A
    RET

_Get_RP:
    PUSHW PS
    POPW  A
    SWAP
    ANDW  A,#0x1f
    RET
#pragma endasm
#endif /* MEMMODEL == SMALL || MEMMODEL == COMPACT */

#if MEMMODEL == MEDIUM || MEMMODEL == LARGE
#pragma asm
        .SECTION        CODE, CODE, ALIGN=1
_Get_DPR_ADB_bank:
    MOV A, DPR
    SWAP
    MOV A, ADB
    ORW A
    RETP

_Get_DTB_PCB_bank:
    MOV A, DTB
    SWAP
    MOV A, PCB
    ORW A
    RETP

_Get_RP:
    PUSHW PS
    POPW  A
    SWAP
    ANDW  A,#0x1f
    RETP
#pragma endasm
#endif /* MEMMODEL == MEDIUM || MEMMODEL == LARGE */

/*
*********************************************************************************************************
*                                        INITIALIZE A TASK'S STACK
*
* Description: This function is called by either OSTaskCreate() or OSTaskCreateExt() to initialize the
*              stack frame of the task being created.  This function is highly processor specific.
*
* Arguments  : task          is a pointer to the task code
*
*              pdata         is a pointer to a user supplied data area that will be passed to the task
*                            when the task first executes.
*
*              ptos          is a pointer to the top of stack.  It is assumed that 'ptos' points to
*                            a 'free' entry on the task stack.  If OS_STK_GROWTH is set to 1 then
*                            'ptos' will contain the HIGHEST valid address of the stack.  Similarly, if
*                            OS_STK_GROWTH is set to 0, the 'ptos' will contains the LOWEST valid address
*                            of the stack.
*
*              opt           specifies options that can be used to alter the behavior of OSTaskStkInit().
*                            (see uCOS_II.H for OS_TASK_OPT_???).
*
* Returns    : Always returns the location of the new top-of-stack' once the processor registers have
*              been placed on the stack in the proper order.
*
* Note(s)    : Interrupts are enabled when your task starts executing and ILM = 7.
*
*********************************************************************************************************
*/

#if OS_SCAN_FREE_BANK != 0
static INT32U FreeBankList = 0;
#endif


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

#if OS_SCAN_FREE_BANK != 0
    INT8U  i;
    INT32U BankMask;
#endif

    opt    = opt;                               /* 'opt' is not used, prevent warning      */

    /* Bank 0 is used for that tasks, which came short separate bank of registers */
    rbank = 0;
#if OS_SCAN_FREE_BANK != 0
    /* Here goes searching for of free bank                          */
    /* If free bank will not is found, rbank will remain equal zero. */
    OS_ENTER_CRITICAL();
    if ((FreeBankList & AVAIL_BANK_MASK) ^ AVAIL_BANK_MASK) {
        OS_EXIT_CRITICAL();
        BankMask = (INT32U)(1<<FIRST_TASK_BANK);
        for (i = FIRST_TASK_BANK; i <= LAST_TASK_BANK; i++) {
            OS_ENTER_CRITICAL();
            if ((BankMask & FreeBankList) == 0) {   /* Free bank is found        */
                FreeBankList |= BankMask;           /* Reserve bank of registers */
                OS_EXIT_CRITICAL();
                rbank = i;
                break;
            }
            OS_EXIT_CRITICAL();
            BankMask <<= 1;
        }
    }
    else {
        OS_EXIT_CRITICAL();
    }
#endif

⌨️ 快捷键说明

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