Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
OS_CPU_C.C
Package: OS_CPU_C.rar [view]
Upload User: qqy_2008
Upload Date: 2020-04-21
Package Size: 4k
Code Size: 19k
Category:
OS Develop
Development Platform:
Visual C++
- /*---------------------------------------------------------------------------
- //
- // FILE : $Workfile: Os_cpu_c.c $
- //
- // ORIGINATOR : Martin Rodier
- // CREATION DATE : March, 7 2002
- // REVISION : 1.10
- // PURPOSE : This uC/OS-II port is intended for Infineon Technologies and ST10R167
- // C16x Extended Architecture Micro Controller Targets (C167CR-LM)
- // PART OF : uC/OS-II version 2.00
- // COMPILE WITH : KEIL C166/ST10 V4.20 Ansi C Compiler
- //
- //---------------------------------------------------------------------------
- // uC/OS-II
- // The Real-Time Kernel
- // Infineon C16x/C167CR
- // Extended Architecture Specific Code
- // HLARGE MEMORY MODEL
- //---------------------------------------------------------------------------
- //
- // Revision history:
- //
- // $Log: /.../UCOS-II/C167/Os_cpu_c.c $
- *
- * 5 3/07/02 3:49p Mrodier
- * Revised Version of the port that include a copy of the interrupting
- * task PSW to fix the problem of the multiplication when the interrupted
- * task had a multiplication in progress and the interrupting task do not
- * return to it.
- *
- * Addition into OSTaskBuildStk of the PSW at position -2E of the task
- * stack to let the interrupting task memorize the state of PSW into the
- * task stack.
- *
- * 4 6/13/01 10:42a Mrodier
- * Revised to final version as relased in uCOSII port
- //
- //-------------------------------------------------------------------------
- */
- #define OS_CPU_GLOBALS
- #include "includes.h"
- #include <intrins.h>
- #pragma SRC
- /*
- *********************************************************************************************************
- * INITIALISE A TASK'S STACK
- *
- * Description: This function is called by either OSTaskCreate() or OSTaskCreateExt() to initialise 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().
- *
- * TASK STACK AREA (High Memory)
- * +14 TASK DATA PARAMETER SEGMENT pointer of task
- * +12 TASK DATA PARAMETER OFFSET pointer of task
- * +10 SEGMENT of task code address
- * +0E OFFSET of task code address
- * +0C SP of System stack of task
- * +0A USER STACK OFFSET POINTER (R0) of task
- * +08 USER STACK PAGE POINTER (DPP2) of task
- * +06 PSW of task
- * +04 OFFSET of task return address (IP)
- * +02 SEGMENT of task return address (CSP)
- * 0 (Low Memory)
- *
- * 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. You can change this by setting the
- * PSW to 0x0800 instead. In this case, interrupts would be disabled upon task startup. The
- * application code would be responsible for enabling interrupts at the beginning of the task
- * code. You will need to modify OSTaskIdle() and OSTaskStat() so that they enable
- * interrupts. Failure to do this will make your system crash!
- *
- *********************************************************************************************************
- */
- OS_STK *OSTaskStkInit (void (*task)(void *pd), void *pdata, OS_STK *ptos, INT16U opt)
- {
- INT16U *stk;
- INT32U usr;
- INT16U page;
- INT16U offset;
- INT16U data_seg;
- INT16U data_sof;
- opt = opt; /* 'opt' is not used, prevent warning */
- data_seg = (INT16U)((INT32U)pdata >> 16);
- data_sof = ((INT16U) pdata & 0xFFFF);
- stk = (INT16U *)ptos; /* Load stack pointer */
- *stk-- = data_seg; /* TASK DATA PARAMETER SEGMENT pointer of task */
- *stk-- = data_sof; /* TASK DATA PARAMETER OFFSET pointer of task */
- *stk-- = (INT16U)((INT32U)task >> 16); /* Task segment start address */
- *stk-- = ((INT16U)task & 0xFFFF); /* Task offset start address */
- *stk-- = (INT16U)0xFC00; /* Task SP of System stack of task */
- usr = (INT32U)stk; /* Keep a copy of STACK OFFSET POINTER location */
- offset = (INT16U)((((usr) & 0x3FFF) - 0x0A) | 0x4000); /* First adress of stack offset pointer of the task */
- *stk-- = offset; /* Task user stack offset R0 */
- page = (INT16U)(usr >> 0x000E); /* Task user stack page DPP2 */
- *stk-- = page; /* Task user stack page DPP2 */
- *stk-- = (INT16U)0x0800; /* Task PSW = Interrupt enabled */
- *stk-- = ((INT16U)task & 0xFFFF); /* Task offset return address */
- *stk-- = (INT16U)((INT32U)task >> 16); /* Task segment return address */
- OSTaskBuildStk(page, offset, data_seg, data_sof);
- return ((OS_STK *)stk);
- }
- /*$PAGE*/
- #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)
- {}
- /*
- *********************************************************************************************************
- *
- *Description :Those function is added by donghegang
- *
- *Notes :There are not those function at the version before 200.
- *
- *********************************************************************************************************
- */
- void OSInitHookBegin(void)
- {}
- void OSInitHookEnd(void)
- {}
- void OSTaskIdleHook(void)
- {}
- void OSTCBInitHook(OS_TCB *ptcb)
- {
- ptcb=ptcb;
- }
- #endif
- /*
- *********************************************************************************************************
- * BUILD A TASK'S STACK AREA
- *
- * Description: This function is called by OSTaskStkInit to initialise the
- * stack frame of the task being created.
- *
- * Arguments : page is a pointer to the current task user stack page.
- *
- * offset is a pointer to the current task user stack offset.
- *
- * datapag is a pointer to a user supplied data area page when the task first executes.
- *
- * datapof is a pointer to a user supplied data area offset when the task first executes.
- *
- * TASK STACK AREA (High Memory)
- * 0
- * -02 R[1 ..15] General Purpose registers of task
- * -20 CP Context pointer of task
- * -22 DPP3 Data page pointer 3 of task
- * -24 DPP2 Data page pointer 1 of task
- * -26 DPP0 Data page pointer 0 of task
- * -28 MDC Multiply/Divide Control of task
- * -2A MDH Multiply/Divide High register of task
- * -2C MDL Multiply/Divide Low register of task (Low Memory)
- * -2E PSW OF the interrupting task to preserve the MULIP flag
- *
- * Returns : None
- *********************************************************************************************************
- */
- void OSTaskBuildStk (INT16U page, INT16U offset, INT16U datapag, INT16U datapof)
- {
- page=page; // The compiler assign page to R8
- offset=offset; // The compiler assign offset to R9
- datapag=datapag; // The compiler assign datapag to R10
- datapof=datapof; // The compiler assign datapof to R11
- #pragma asm
- ; SAVE USED REGISTERS
- PUSH R1
- PUSH R2
- PUSH R3
- PUSH R4
- PUSH R10
- PUSH R11
- PUSH R12
- ; LOAD INITIAL TASK STACK.
- MOV R4,R9 ; Get pointer to Task Stack
- MOV R2,R10 ; Page pointer to passed parameter
- MOV R3,R11 ; Offset pointer to passed parameter
- ; ADJUST THE TASK USER OFFSET POINTER
- EXTP R8,#1
- MOV R1,[R4+#0x0A] ; Get initial user offset pointer
- SUB R1,#0x2E ; adjust user offset pointer to save task registers
- EXTP R8,#1
- MOV [R4+#0x0A],R1 ; Save true user offset pointer
- ; INITIALISE REGISTER VALUES
- MOV R9 ,#0x1111 ; R1 initialised to 1111
- MOV R10,#0x2222 ; R2 initialised to 2222
- MOV R11,#0x3333 ; R3 initialised to 3333
- MOV R12,#0x4444 ; R4 initialised to 4444
- EXTP R8,#4
- MOV [-R4],R9
- MOV [-R4],R10
- MOV [-R4],R11
- MOV [-R4],R12
- MOV R9, #0x5555 ; R5 initialised to 5555
- MOV R10,#0x6666 ; R6 initialised to 6666
- MOV R11,#0x7777 ; R7 initialised to 7777
- MOV R12,R3 ; R8 initialised to point @ POF of pdata
- EXTP R8,#4
- MOV [-R4],R9
- MOV [-R4],R10
- MOV [-R4],R11
- MOV [-R4],R12
- MOV R9 ,R2 ; R9 initialised to point @ PAG of pdata
- MOV R10,#0xAAAA ; R10 initialised to AAAA
- MOV R11,#0xBBBB ; R11 initialised to BBBB
- MOV R12,#0xCCCC ; R12 initialised to CCCC
- EXTP R8,#4
- MOV [-R4],R9
- MOV [-R4],R10
- MOV [-R4],R11
- MOV [-R4],R12
- MOV R9 ,#0xDDDD ; R13 initialised to DDDD
- MOV R10,#0xEEEE ; R14 initialised to EEEE
- MOV R11,#0xFFFF ; R15 initialised to FFFF
- MOV R12,CP ; Get the Context Pointer (CP)
- EXTP R8,#4
- MOV [-R4],R9
- MOV [-R4],R10
- MOV [-R4],R11
- MOV [-R4],R12
- MOV R9 ,DPP3 ; Get Data Page Pointer 3 (DPP3)
- MOV R10,DPP2 ; Get Data Page Pointer 2 (DPP2)
- MOV R11,DPP0 ; Get Data Page Pointer 0 (DPP0)
- EXTP R8,#3
- MOV [-R4],R9 ; Put it on the user stack
- MOV [-R4],R10 ; Put it on the user stack
- MOV [-R4],R11 ; Put it on the user stack
- MOV R9,#0x00 ; R10 initialised to 0
- EXTP R8,#4
- MOV [-R4],R9 ; Set Multiply/Divide Control (MDC)
- MOV [-R4],R9 ; Set Multiply/Divide High (MDH)
- MOV [-R4],R9 ; Set Multiply/Divide Low (MDL)
- MOV [-R4],R9 ; Set Temporary PSW (Cleared)
- ; RESTORE USED REGISTERS
- POP R12
- POP R11
- POP R10
- POP R4
- POP R3
- POP R2
- POP R1
- #pragma endasm
- }
- /*$PAGE*/
- /*
- *********************************************************************************************************
- * INITIALIZE SYSTEM TICK
- *
- * Description: This function is called to initialize and configure the system interrupt tick.
- *
- * Arguments : none
- *********************************************************************************************************
- */
- void OSTickISRInit (void)
- {
- /// -----------------------------------------------------------------------
- /// Configuration of Timer Block Prescaler 1:
- /// -----------------------------------------------------------------------
- /// - prescaler for timer block 1 is 8
- /// -----------------------------------------------------------------------
- /// Configuration of the GPT1 Core Timer 3:
- /// -----------------------------------------------------------------------
- /// - timer 3 works in timer mode
- /// - external up/down control is disabled
- /// - prescaler factor is 8
- /// - up/down control bit is reset
- /// - alternate output function T3OUT (P3.3) is disabled
- /// - timer 3 output toggle latch (T3OTL) is set to 0
- /// - timer 3 run bit is reset
- GPT12E_T3CON = 0x0000; // load timer 3 control register
- GPT12E_T3 = 0x0000; // load timer 3 register
- /// -----------------------------------------------------------------------
- /// Configuration of the GPT1 Auxiliary Timer 2:
- /// -----------------------------------------------------------------------
- /// - timer 2 works in timer mode
- /// - external up/down control is disabled
- /// - prescaler factor is 16
- /// - up/down control bit is reset
- GPT12E_T2CON = 0x0001; // load timer 2 control register
- GPT12E_T2 = 0x0000; // load timer 2 register
- /// -----------------------------------------------------------------------
- /// Configuration of the GPT1 Auxiliary Timer 4:
- /// -----------------------------------------------------------------------
- /// - timer 4 works in timer mode
- /// - external up/down control is disabled
- /// - prescaler factor is 8
- /// - up/down control bit is reset
- /// - timer 4 run bit is reset
- GPT12E_T4CON = 0x0000; // load timer 4 control register
- GPT12E_T4 = 0x0000; // load timer 4 register
- /// -----------------------------------------------------------------------
- /// Configuration of the used GPT1 Port Pins:
- /// -----------------------------------------------------------------------
- /// -----------------------------------------------------------------------
- /// Configuration of the used GPT1 Interrupts:
- /// -----------------------------------------------------------------------
- /// timer 2 service request node configuration:
- /// - timer 2 interrupt priority level (ILVL) = 13
- /// - timer 2 interrupt group level (GLVL) = 1
- /// - timer 2 group priority extension (GPX) = 0
- GPT12E_T2IC = 0x0075;
- // USER CODE BEGIN (GPT1_Function,3)
- // USER CODE END
- GPT12E_T2CON_T2R = 1; // set timer 2 run bit
- } // End of function GPT1_vInit