PageRenderTime 38ms CodeModel.GetById 21ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

/src/compiler/ucos-vs2008/UCOS_SIM/src/ucosii-port/win32/os_cpu.h

http://ftk.googlecode.com/
C++ Header | 113 lines | 45 code | 16 blank | 52 comment | 0 complexity | 71c3bc65c2c75f6ab38c6be3636efa16 MD5 | raw file
  1/*
  2*********************************************************************************************************
  3*                                               uC/OS-II
  4*                                        The Real-Time Kernel
  5*
  6*                                        Win32 Specific code
  7*
  8* This is free software; you can redistribute it and/or
  9* modify it under the terms of the GNU General Public License
 10*
 11* File : OS_CPU.H
 12* By   : Vladimir Antonenko
 13*
 14* Rules of use of the given emulation uCOS in Win32:
 15*
 16*   1. All Win32-threads which interact with uCOS-tasks should initialize
 17*      critical section by call OS_INIT_CRITICAL() (if defined USE_CRITICAL_SECTION
 18*      in os_cpu_c.c). They can be considered as handlers of interrupts.
 19*   2. Function printf() and it similar should be made in critical section as
 20*      the console is shared resource and can cause deadlock of tasks ( see osprintf()
 21*      in the end of file ).
 22*   3. It is necessary very closely use shared resources of Windows - they can cause
 23*      blocking of tasks.
 24*
 25* The given emulation starts each uCOS-task in separate thread. At any moment of time
 26* only 0 or one from these threads can be active. (remaining in SUSPEND state, not considering
 27* two service threads (have priorities 10 and 15). Each thread in SUSPEND state
 28* must have SUSPEND counter = 1).
 29*
 30*********************************************************************************************************
 31*/
 32
 33#ifndef _OS_CPU_H
 34#define _OS_CPU_H
 35
 36#include <stdio.h>
 37#include <windows.h>
 38
 39/*
 40*********************************************************************************************************
 41*                                              Defines
 42*********************************************************************************************************
 43*/
 44#ifndef _WIN32_WINNT
 45#define _WIN32_WINNT          0x0400 
 46#endif
 47
 48#define  OS_CPU_EXT           extern
 49#define  OS_TASK_SW()         SetEvent(OSCtxSwW32Event)
 50#define  OS_STK_GROWTH        1                             /* Stack grows from HIGH to LOW memory on 80x86  */
 51
 52/*
 53*********************************************************************************************************
 54*                                              GLOBALS
 55*********************************************************************************************************
 56*/
 57
 58OS_CPU_EXT  CRITICAL_SECTION  OSCriticalSection;
 59OS_CPU_EXT  HANDLE            OSCtxSwW32Event;
 60
 61/*
 62*********************************************************************************************************
 63*                                              Prototypes
 64*********************************************************************************************************
 65*/
 66
 67void     OS_SLEEP();                             /* Recommend to insert call of this function in Idle task                     */
 68void     OS_STOP();
 69int      OS_Printf( char* str, ... );            /* analog of printf, but use critical sections                                */
 70
 71void     OS_INIT_CRITICAL();
 72void     OS_ENTER_CRITICAL();
 73void     OS_EXIT_CRITICAL();
 74
 75void     OSStartHighRdy();
 76void     OSIntCtxSw();
 77
 78/*
 79*********************************************************************************************************
 80*                                              DATA TYPES
 81*                                         (Compiler Specific)
 82*********************************************************************************************************
 83*/
 84
 85typedef unsigned char  BOOLEAN;
 86typedef unsigned char  INT8U;                    /* Unsigned  8 bit quantity                           */
 87typedef signed   char  INT8S;                    /* Signed    8 bit quantity                           */
 88typedef unsigned short INT16U;                   /* Unsigned 16 bit quantity                           */
 89typedef signed   short INT16S;                   /* Signed   16 bit quantity                           */
 90typedef unsigned long  INT32U;                   /* Unsigned 32 bit quantity                           */
 91typedef signed   long  INT32S;                   /* Signed   32 bit quantity                           */
 92typedef float          FP32;                     /* Single precision floating point                    */
 93typedef double         FP64;                     /* Double precision floating point                    */
 94
 95typedef unsigned short OS_STK;                   /* Each stack entry is 16-bit wide                    */
 96
 97#define BYTE           INT8S                     /* Define data types for backward compatibility ...   */
 98#define UBYTE          INT8U                     /* ... to uC/OS V1.xx.  Not actually needed for ...   */
 99#define WORD           INT16S                    /* ... uC/OS-II.                                      */
100#define UWORD          INT16U
101#define LONG           INT32S
102#define ULONG          INT32U
103
104typedef struct {
105    void    *pData;
106    INT16U  Opt;
107    void    (*Task)(void*);
108    HANDLE  Handle;
109    INT32U  Id;
110    INT32   Exit;
111} OS_EMU_STK;
112
113#endif                                           /*_OS_CPU_H                                                                   */