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

📄 osslib.c

📁 T2.0 USB driver.rar T2.0 USB driver.rar
💻 C
📖 第 1 页 / 共 2 页
字号:
/* ossLib.c - O/S-independent services for vxWorks *//* Copyright 2000 Wind River Systems, Inc. *//*Modification history--------------------01c,01aug01,rcb  fixed manpage generation in comments01b,07mar00,rcb  Cast handles as necessary to reflect change in handle		 definition from UINT32 to pVOID.01a,07jun99,rcb  First.*//*DESCRIPTIONImplements functions defined by ossLib.h.  See ossLib.h fora complete description of these functions.*//* includes */#include "vxWorks.h"#include "stdio.h"#include "stdlib.h"#include "string.h"#include "errnoLib.h"		/* errno */#include "sysLib.h"		/* sysClkRateGet(), etc. */#include "taskLib.h"		/* taskSpawn(), etc. */#include "semLib.h"		/* semCreate(), etc. */#include "objLib.h"		/* S_objLib_OBJ_xxxx errors */#include "tickLib.h"		/* tickGet(), etc. */#include "usb/usbPlatform.h"#include "usb/ossLib.h" 	/* Our API *//* Defines *//* #define  FILL_MEMORY */	    /* for debugging *//* Definitions related to the creation of new threads. */#define DEFAULT_OPTIONS     0	    /* task options */#define DEFAULT_STACK	    0x4000  /* Default stack size *//*  * TIMEOUT() calculates the number of ticks for a timeout from a blockFlag * parameter to one of the ossLib functions. */#define TIMEOUT(bf) (((bf) == OSS_BLOCK) ? \    WAIT_FOREVER : ((bf) + msecsPerTick - 1) / msecsPerTick)/* typedefs *//* locals */LOCAL int msecsPerTick = 55;	    /* milliseconds per system tick */				    /* value updated by ossInitialize() *//* Functions *//***************************************************************************** translateError - translates vxWorks error to S_ossLib_xxxx** Translates certain vxWorks errno values to an appropriate S_ossLib_xxxx.* This function should only be invoked when the caller has already* ascertained that a vxWorks function has returned an error.** RETURNS: S_ossLib_xxxx** ERRNO:*  S_ossLib_BAD_HANDLE*  S_ossLib_TIMEOUT*  S_ossLib_GENERAL_FAULT*/LOCAL int translateError (void)    {    switch (errno)	{	case S_objLib_OBJ_ID_ERROR:	return S_ossLib_BAD_HANDLE;	case S_objLib_OBJ_TIMEOUT:	return S_ossLib_TIMEOUT;	default:			return S_ossLib_GENERAL_FAULT;	}    }/***************************************************************************** translatePriority - translates OSS_PRIORITY_xxx to vxWorks priority** RETURNS: vxWorks task priority*/LOCAL int translatePriority    (    UINT16 priority    )    {    int curPriority;    switch (priority)	{	case OSS_PRIORITY_LOW:	case OSS_PRIORITY_TYPICAL:	case OSS_PRIORITY_HIGH:	case OSS_PRIORITY_INTERRUPT:	    return priority;	case OSS_PRIORITY_INHERIT:	default:	    taskPriorityGet (0, &curPriority);	    return curPriority;	}    }/***************************************************************************** threadHead - vxWorks taskSpawn() compatible thread entry point** ossThreadCreate() uses this intermediary function to spawn threads.  The* vxWorks taskSpawn() function passes 10 int parameters to the task entry* point.  By convention, ossThreadCreate passes the function's real entry* point in <arg1> and the thread's <param> in <arg2>..*/LOCAL int threadHead    (    int arg1,			    /* <func> in this parameter */    int arg2,			    /* <param> in this parameter */    int arg3,    int arg4,    int arg5,    int arg6,    int arg7,    int arg8,    int arg9,    int arg10    )        {    THREAD_PROTOTYPE func = (THREAD_PROTOTYPE) arg1;    pVOID param = (pVOID) arg2;    (*func) (param);    return 0;    }/***************************************************************************** ossStatus - Returns OK or ERROR and sets errno based on status** If <status> & 0xffff is not equal to zero, then sets errno to the* indicated <status> and returns ERROR.  Otherwise, does not set errno* and returns OK.** RETURNS: OK or ERROR*/STATUS ossStatus     (    int status    )    {    if ((status & 0xffff) != 0)	{	errnoSet (status);	return ERROR;	}        return OK;    }/***************************************************************************** ossInitialize - Initializes ossLib** This function should be called once at initialization in order* to initialize the ossLib.  Calls to this function may be* nested.  This permits multiple, indpendent libraries to use this library* without need to coordinate the use of ossInitialize() and ossShutdown()* across the libraries.** RETURNS: OK or ERROR*/STATUS ossInitialize (void)    {    /* Get the system clock rate...used by ossThreadSleep */    msecsPerTick = 1000 / sysClkRateGet();        return OK;    }/***************************************************************************** ossShutdown - Shuts down ossLib** This function should be called once at system shutdown if an only if* the corresponding call to ossInitialize() was successful.** RETURNS: OK or ERROR*/STATUS ossShutdown (void)    {    return OK;    }/***************************************************************************** ossThreadCreate - Spawns a new thread** The ossThreadCreate() function creates a new thread which begins execution * with the specified <func>.  The <param> argument will be passed to <func>.  * The ossThreadCreate() function creates the new thread with a stack of a * default size and with no security restrictions - that is, there are no * restrictions on the use of the returned <pThreadHandle> by other threads.  * The newly created thread will execute in the same address space as the * calling thread.  <priority> specifies the thread's desired priority - in* systems which implement thread priorities, as OSS_PRIORITY_xxxx.  ** RETURNS: OK or ERROR** ERRNO:*  S_ossLib_BAD_PARAMETER*  S_ossLib_GENERAL_FAULT*/STATUS ossThreadCreate     (    THREAD_PROTOTYPE func,	    /* function to spawn as new thread */    pVOID param,		    /* Parameter to be passed to new thread */    UINT16 priority,		    /* OSS_PRIORITY_xxxx */    pCHAR name, 		    /* thread name or NULL */    pTHREAD_HANDLE pThreadHandle    /* Handle of newly spawned thread */    )    {    /* validate params */    if (pThreadHandle == NULL)	return ossStatus (S_ossLib_BAD_PARAMETER);    /* Use vxWorks to spawn a new thread (task in vxWorks parlance). */    if ((*pThreadHandle = (THREAD_HANDLE) taskSpawn (name, 	translatePriority (priority), DEFAULT_OPTIONS, DEFAULT_STACK, 	threadHead, (int) func, (int) param, 0, 0, 0, 0, 0, 0, 0, 0)) == 	(THREAD_HANDLE) ERROR)	return ossStatus (S_ossLib_GENERAL_FAULT);    return OK;    }/***************************************************************************** ossThreadDestroy - Attempts to destroy a thread** This function attempts to destroy the thread specified by <threadHandle>.** NOTE: Generally, this function should be called only after the given* thread has terminated normally.  Destroying a running thread may result* in a failure to release resources allocated by the thread.** RETURNS: OK or ERROR** ERRNO:*  S_ossLib_GENERAL_FAULT*/STATUS ossThreadDestroy     (    THREAD_HANDLE threadHandle	    /* handle of thread to be destroyed */    )    {    if (taskDelete ((int) threadHandle) == ERROR)	return ossStatus (S_ossLib_GENERAL_FAULT);    return OK;    }    /***************************************************************************** ossThreadSleep - Voluntarily relinquishes the CPU** Threads may call ossThreadSleeph() to voluntarily release the CPU to* another thread/process.  If the <msec> argument is 0, then the thread will* be reschuled for execution as soon as possible.  If the <msec> argument is* greater than 0, then the current thread will sleep for at least the number* of milliseconds specified.** RETURNS: OK or ERROR*/STATUS ossThreadSleep    (    UINT32 msec 		    /* Number of msec to sleep */    )    {    /* Delay for a number of ticks at least as long as the number of    milliseconds requested by the caller. */    taskDelay ((msec == 0) ? 0 : ((msec + msecsPerTick - 1) / msecsPerTick) + 1);    return OK;    }/***************************************************************************** ossSemCreate - Creates a new semaphore** This function creates a new semaphore and returns the handle of that* semaphore in <pSemHandle>.  The semaphore's initial count is set to* <curCount> and has a maximum count as specified by <maxCount>.** RETURNS: OK or ERROR* * ERRNO:*  S_ossLib_BAD_PARAMETER*  S_ossLib_GENERAL_FAULT*/STATUS ossSemCreate     (

⌨️ 快捷键说明

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