📄 tmdlhdmitx_iw.c
字号:
/* * Copyright (C) 2007 NXP N.V., All Rights Reserved. * This source code and any compilation or derivative thereof is the proprietary * information of NXP N.V. and is confidential in nature. Under no circumstances * is this software to be exposed to or placed under an Open Source License of * any type without the expressed written permission of NXP N.V. * * \file tmdlHdmiTx_IW.c * * \version $Revision: 1 $ * * \date $Date: 07/08/07 16:00 $ * * \brief devlib driver component API for the TDA998x HDMI Transmitters * * \section refs Reference Documents * TDA998x Driver - FRS.doc, * TDA998x Driver - tmdlHdmiTx - SCS.doc * * \section info Change Information * * \verbatim $History: tmdlHdmiTx_IW.c $ * * ***************** Version 1 ***************** * User: J. Lamotte Date: 07/08/07 Time: 16:00 * Updated in $/Source/tmdlHdmiTx/inc * initial version * \endverbatim **//*============================================================================*//* INCLUDE FILES *//*============================================================================*/#define HS800#define _WIN32_WINNT 0x0500#define DWORD void *#define HANDLE void *#define WINAPI #define LPTHREAD_START_ROUTINE U32#define LPVOID void *#include "tmNxTypes.h"#include "tmNxCompId.h"#include "tmdlHdmiTx_Types.h"#include "tmdlHdmiTx_cfg.h"#include "tmdlHdmiTx_IW.h"#include <sections.h>#ifdef __cplusplusextern "C" {#endif/*============================================================================*//* DEFINES *//*============================================================================*//* maximum number of tasks that can be handled by the wrapper */#define MAX_TASKS 5/* maximum number of message queues that can be handled by the wrapper */#define MAX_QUEUES 5/*============================================================================*//* MACRO *//*============================================================================*//* macro for quick error handling */#define RETIF(cond, rslt) if ((cond)){return (rslt);}/*============================================================================*//* TYPE DEFINITIONS *//*============================================================================*//* structure describing each task handled by the wrapper */typedef struct{ Bool created; Bool started; UInt8 priority; UInt16 stackSize; DWORD threadID; HANDLE threadHandle; LPTHREAD_START_ROUTINE associatedThread; tmdlHdmiTxIWFuncPtr_t associatedTask;} iwTcb_t;/* structure describing each message queue handled by the wrapper */typedef struct{ Bool created; HANDLE accessSemaphore; HANDLE countSemaphore; UInt16 queueFullness; UInt16 queueSize; UInt16 writePointer; UInt16 readPointer; UInt8 *queue;} iwQueue_t;void maketasks(iwTcb_t *tasklist);/*============================================================================*//* FUNCTION PROTOTYPES *//*============================================================================*/void ThreadProc0(void){ /* dummy reference to avoid compilation warning C4100 */ iwTcb_t *taskTableR; maketasks(taskTableR); /* call the registered task */ taskTableR[0].associatedTask(); /* if we reach this point, the task is terminated, so update its status */ taskTableR[0].started = False; return;}/******************************************************************************/void ThreadProc1(void){ /* dummy reference to avoid compilation warning C4100 */ iwTcb_t *taskTableR; maketasks(taskTableR); /* call the registered task */ taskTableR[1].associatedTask(); /* if we reach this point, the task is terminated, so update its status */ taskTableR[1].started = False; return;}/******************************************************************************/void ThreadProc2(void){ /* dummy reference to avoid compilation warning C4100 */ iwTcb_t *taskTableR; maketasks(taskTableR); /* call the registered task */ taskTableR[2].associatedTask(); /* if we reach this point, the task is terminated, so update its status */ taskTableR[2].started = False; return;}/******************************************************************************/void ThreadProc3(void){ /* dummy reference to avoid compilation warning C4100 */ iwTcb_t *taskTableR; maketasks(taskTableR); /* call the registered task */ taskTableR[3].associatedTask(); /* if we reach this point, the task is terminated, so update its status */ taskTableR[3].started = False; return;}void ThreadProc4(void){ /* dummy reference to avoid compilation warning C4100 */ iwTcb_t *taskTableR; maketasks(taskTableR); /* call the registered task */ taskTableR[4].associatedTask(); /* if we reach this point, the task is terminated, so update its status */ taskTableR[4].started = False; return;}/*============================================================================*//* VARIABLES *//*============================================================================*//* table storing all tasks descriptions */iwTcb_t taskTable[MAX_TASKS] ={ {False, False, 0, 0, 0, 0, 0, ThreadProc1}, {False, False, 0, 0, 0, 0, 0, ThreadProc1}, {False, False, 0, 0, 0, 0, 0, ThreadProc2}, {False, False, 0, 0, 0, 0, 0, ThreadProc3}, {False, False, 0, 0, 0, 0, 0, ThreadProc4}};/* table storing all message queues descriptions */iwQueue_t queueTable[MAX_QUEUES] ={ {False, 0, 0, 0, 0, 0, 0, Null}, {False, 0, 0, 0, 0, 0, 0, Null}, {False, 0, 0, 0, 0, 0, 0, Null}, {False, 0, 0, 0, 0, 0, 0, Null}, {False, 0, 0, 0, 0, 0, 0, Null}};void maketasks(iwTcb_t *tasklist){ tasklist=taskTable;}/*============================================================================*//* FUNCTION *//*============================================================================*//****************************************************************************** \brief This function creates a task and allocates all the necessary resources. Note that creating a task do not start it automatically, an explicit call to tmdlHdmiTxIWTaskStart must be made. \param pFunc Pointer to the function that will be executed in the task context. \param Priority Priority of the task. The minimum priority is 0, the maximum is 255. \param StackSize Size of the stack to allocate for this task. \param pHandle Pointer to the handle buffer. \return The call result: - TM_OK: the call was successful - TMDL_ERR_DLHDMITX_NO_RESOURCES: the resource is not available - TMDL_ERR_DLHDMITX_INCONSISTENT_PARAMS: an input parameter is inconsistent******************************************************************************/tmErrorCode_t tmdlHdmiTxIWTaskCreate( tmdlHdmiTxIWFuncPtr_t pFunc, UInt8 priority, UInt16 stackSize, tmdlHdmiTxIWTaskHandle_t *pHandle){ UInt32 i; /* check that input pointer is not NULL */ RETIF(pFunc == Null, TMDL_ERR_DLHDMITX_INCONSISTENT_PARAMS) /* check that input pointer is not NULL */ RETIF(pHandle == Null, TMDL_ERR_DLHDMITX_INCONSISTENT_PARAMS) /* search for available task slot */ for(i = 0; i < MAX_TASKS; i++) { if (taskTable[i].created == False) break; } RETIF(i >= MAX_TASKS, TMDL_ERR_DLHDMITX_NO_RESOURCES) /* store task parameters into the dedicated structure */ taskTable[i].priority = priority; taskTable[i].stackSize = stackSize; taskTable[i].associatedTask = pFunc; taskTable[i].created = True; *pHandle = (tmdlHdmiTxIWTaskHandle_t)i; return(TM_OK);}/****************************************************************************** \brief This function destroys an existing task and frees resources used by it. \param Handle Handle of the task to be destroyed, as returned by tmdlHdmiTxIWTaskCreate. \return The call result: - TM_OK: the call was successful - TMDL_ERR_DLHDMITX_RESOURCE_NOT_OWNED: the caller does not own the resource - TMDL_ERR_DLHDMITX_BAD_HANDLE: the handle number is wrong******************************************************************************/tmErrorCode_t tmdlHdmiTxIWTaskDestroy( tmdlHdmiTxIWTaskHandle_t handle){ /* check if handle number is in range */ RETIF((handle < 0) || (handle >= MAX_TASKS), TMDL_ERR_DLHDMITX_BAD_HANDLE) /* check if handle corresponding to task is created */ RETIF(taskTable[handle].created == False, TMDL_ERR_DLHDMITX_RESOURCE_NOT_OWNED) if (taskTable[handle].started == True) { task_kill(taskTable[handle].threadHandle, 0, 0); taskTable[handle].started = False; } taskTable[handle].created = False; return(TM_OK);}/****************************************************************************** \brief This function start an existing task. \param Handle Handle of the task to be started. \return The call result: - TM_OK: the call was successful - TMDL_ERR_DLHDMITX_ALREADY_STARTED: the function is already started - TMDL_ERR_DLHDMITX_NOT_STARTED: the function is not started - TMDL_ERR_DLHDMITX_BAD_HANDLE: the handle number is wrong******************************************************************************/tmErrorCode_t tmdlHdmiTxIWTaskStart( tmdlHdmiTxIWTaskHandle_t index){ HANDLE threadHandle; iwTcb_t *taskTableR; int handle=index; maketasks(taskTableR); /* check if handle number is in range */ RETIF((handle < 0) || (handle >= MAX_TASKS), TMDL_ERR_DLHDMITX_BAD_HANDLE) /* check if task is already started */ RETIF(taskTableR[handle].started == True, TMDL_ERR_DLHDMITX_ALREADY_STARTED) /* start thread associated to the task */#ifndef HS800 threadHandle = CreateThread(NULL, (SIZE_T)taskTableR[handle].stackSize, taskTableR[handle].associatedThread, NULL, 0, &(taskTableR[handle].threadID)); /* check return code for errors */ RETIF(!threadHandle, TMDL_ERR_DLHDMITX_NOT_STARTED) /* set the priority task */ SetThreadPriority(threadHandle,(int)taskTableR[handle].priority);#else switch(handle){ case 0: threadHandle = task_create ((void (*)(void*))ThreadProc0, 0, (size_t)taskTableR[handle].stackSize, (int)taskTableR[handle].priority, (const char *)"HDMI", 0 ); RETIF(!threadHandle, TMDL_ERR_DLHDMITX_NOT_STARTED) break; case 1: threadHandle = task_create ((void (*)(void*))ThreadProc1, 0, (size_t)taskTableR[handle].stackSize, (int)taskTableR[handle].priority, (const char *)"HDMI", 0 ); RETIF(!threadHandle, TMDL_ERR_DLHDMITX_NOT_STARTED) break; case 2: threadHandle = task_create ((void (*)(void*))ThreadProc2, 0, (size_t)taskTableR[handle].stackSize, (int)taskTableR[handle].priority, (const char *)"HDMI", 0 ); RETIF(!threadHandle, TMDL_ERR_DLHDMITX_NOT_STARTED) break; case 3: threadHandle = task_create ((void (*)(void*))ThreadProc3, 0,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -