📄 trucos.c
字号:
/*
* Copyright Notice:
* Copyright Elmic Systems Japan 1997, 1998
* Copyright Treck Incorporated 1997, 1998
* No portions or the complete contents of this file may be copied or
* distributed in any form (including but not limited to printed or electronic
* forms) without the expressed written consent of Treck Incorporated OR
* Elmic Systems. Copyright laws and International Treaties protect the
* contents of this file. Unauthorized use is prohibited. All rights
* reserved.
*
* Description: Kernel Hooks for uC/OS
* NOTE: This File is intended to be modified by the user
* In order to add a new operating system
* Filename: trucos.c
* Author: Paul
* Date Created: 11/10/97
*
* Modification History
* Date:
* Author:
* Version:
* Description:
*
*/
#include <includes.h> /* uC/OS include */
#include <trsocket.h>
#define TM_KERN_OKAY 0
#define TM_KERN_ERROR -1
static char tlUcosErrorFunction[80];
static char tlUcosErrorType[80];
static char tlUcosWarnFunction[80];
static char tlUcosWarnType[80];
void tfKernelInitialize()
{
}
/*
* Report an Error
*/
void tfKernelError(char TM_FAR *functionName, char TM_FAR *errorMessage)
{
char TM_FAR *ptr;
ptr=tlUcosErrorFunction;
while(*functionName)
*ptr++ = *functionName++;
ptr=tlUcosErrorType;
while(*errorMessage)
*ptr++ = *errorMessage++;
/* printf("%s --- %s\n",functionName, errorMessage); */
tm_thread_stop;
}
void tfKernelWarning(char TM_FAR *functionName, char TM_FAR *warnMessage)
{
char TM_FAR *ptr;
ptr=tlUcosWarnFunction;
while(*functionName)
*ptr++ = *functionName++;
ptr=tlUcosWarnType;
while(*warnMessage)
*ptr++ = *warnMessage++;
}
/*
* Allocate a memory block of size from the kernel
*/
/*
* Since uC/OS does not provide a heap, we call the simple heap
* routine provided in the Treck libraries.
*/
void TM_FAR *tfKernelMalloc(unsigned size)
{
return(tfSheapMalloc(size));
}
/*
* Since uC/OS does not provide a heap, we call the simple heap
* routine provided in the Treck libraries.
*/
void tfKernelFree(void TM_FAR *memoryBlockPtr)
{
tfSheapFree(memoryBlockPtr);
}
#ifndef TM_SDS68K_ASM_CRITICAL
/*
* Stop all other calls into Treck by
* a kernel context switch
*/
void tfKernelSetCritical()
{
OS_ENTER_CRITICAL();
}
/*
* Resume normal operation (from tfKernelSetCritical)
*/
void tfKernelReleaseCritical()
{
OS_EXIT_CRITICAL();
}
#endif /* TM_SDS68K_ASM_CRITICAL */
/*
* Create a counting semaphore
*/
int tfKernelCreateCountSem(ttUserGenericUnionPtr countingSemaphore)
{
OS_EVENT TM_FAR *semaphorePtr;
int retCode;
retCode=TM_KERN_OKAY;
/* Initialize the semaphore to zero */
semaphorePtr = OSSemCreate(0);
if (semaphorePtr != (OS_EVENT TM_FAR *)0)
{
countingSemaphore->genVoidParmPtr = (void TM_FAR *)semaphorePtr;
}
else
{
tfKernelError("tfKernelCreateCountSem","Unable to Create uC/OS Semaphore");
tm_thread_stop;
}
return retCode;
}
/*
* Wait on a counting semaphore
*/
int tfKernelPendCountSem(ttUserGenericUnionPtr countingSemaphore)
{
UBYTE kernelError;
int retCode;
retCode=TM_KERN_OKAY;
OSSemPend((OS_EVENT TM_FAR *)countingSemaphore->genVoidParmPtr, 0, &kernelError);
if (kernelError != OS_NO_ERR)
{
tfKernelError("tfKernelPendCountSem","Unable to Pend on uC/OS Semaphore");
tm_thread_stop;
}
return(retCode);
}
/*
* Resume waiting tasks on a counting semaphore
*/
int tfKernelPostCountSem(ttUserGenericUnionPtr countingSemaphore)
{
UBYTE kernelError;
int retCode;
retCode=TM_KERN_OKAY;
kernelError = OSSemPost((OS_EVENT TM_FAR *)countingSemaphore->genVoidParmPtr);
if (kernelError != OS_NO_ERR)
{
tfKernelError("tfKernelPendCountSem","Unable to Post on uC/OS Semaphore");
tm_thread_stop;
}
return(retCode);
}
/*
* Delete a counting semaphore
*/
int tfKernelDeleteCountSem(ttUserGenericUnionPtr countingSemaphore)
{
/* No uC/OS facility to delete a semaphore */
return(TM_KERN_OKAY);
}
/*
* Install an ISR Handler
*/
void tfKernelInstallIsrHandler(ttUserIsrHandlerPtr funcPtr, unsigned long offSet)
{
OSInstallISR((void TM_FAR *)funcPtr, offSet);
return;
}
/*
* Create an event structure for pend/post from an ISR
*/
void tfKernelCreateEvent(ttUserGenericUnionPtr eventPtr)
{
OS_EVENT TM_FAR *semaphorePtr;
/* Initialize the semaphore to zero */
semaphorePtr = OSSemCreate(0);
if (semaphorePtr != (OS_EVENT TM_FAR *)0)
{
eventPtr->genVoidParmPtr = (void TM_FAR *)semaphorePtr;
}
else
{
tfKernelError("tfKernelCreateIsrEvent","Unable to Create uC/OS Semaphore");
tm_thread_stop;
}
}
/*
* Wait on an Event from an ISR
*/
void tfKernelPendEvent(ttUserGenericUnionPtr eventPtr)
{
UBYTE kernelError;
OSSemPend((OS_EVENT TM_FAR *)eventPtr->genVoidParmPtr, 0, &kernelError);
if (kernelError != OS_NO_ERR)
{
tfKernelError("tfKernelPendIsrEvent","Unable to Pend on uC/OS Semaphore");
tm_thread_stop;
}
}
/*
* Resume waiting tasks that ware waiting on this event
*/
void tfKernelIsrPostEvent(ttUserGenericUnionPtr eventPtr)
{
UBYTE kernelError;
kernelError = OSSemPost((OS_EVENT TM_FAR *)eventPtr->genVoidParmPtr);
if (kernelError != OS_NO_ERR)
{
tfKernelError("tfKernelPostIsrEvent","Unable to Post on uC/OS Semaphore");
tm_thread_stop;
}
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -