📄 hpcfsfunc.c
字号:
/* hpcFsFunc.c - RPC functions for HPCFS *//* Copyright 1996-1998 Wind River Systems, Inc.; Copyright 2000 Intel Corp. *//*modification history--------------------01a,29Jun00,jdg written*//*DESCRIPTIONThis library provides the RPC functions used by HPCFS. A semaphore ensures thatthe reply is for the calling function.*/#include "hpcIf.h"#include "hpcFsFunc.h"#include "hpcFsRpc.h"#include "errnoLib.h"#include "objLib.h"static SEM_ID rpcAccess;static HPC_IRP rpcIrp;static int HpcChanNum;static int HpcTimeout;int sysClkRateGet(void);/* HPC Timeout in seconds */#define HPC_TIMEOUT 3000inthpcFuncInit(int channel_num){ rpcAccess = semBCreate(SEM_Q_FIFO, SEM_FULL); if (!rpcAccess) return ERROR; hpcInitIrp(&rpcIrp); HpcChanNum = channel_num; HpcTimeout = HPC_TIMEOUT * sysClkRateGet(); return OK;}inthpcFuncRWTimeout(int channelNum, HPC_OP op, char *buf, int bufsize, int *bytesUsed, int timeout){ /* Assume that app has already taken rpcAccess */ HPC_ERROR_CODE result; result = hpcReadwrite(channelNum, op, (unsigned char*) buf, bufsize, (unsigned int*) bytesUsed, &rpcIrp); if (result != HPC_PENDING) return (int) result; if (OK != semTake(rpcIrp.done, timeout)) { hpcCancelio(channelNum, op); if (errno == S_objLib_OBJ_TIMEOUT) { return -1; } else { return errno; } } result = hpcGetIrpStatus(&rpcIrp, (unsigned int*) bytesUsed, FALSE); return result;}inthpcfsFuncOpen(int pmode, int pperm, char *name, int *channel){ HPC_ERROR_CODE result; int iResult; char buf[RPC_BUFF_SIZE], *pbuf = buf; unsigned int bytesUsed; pbuf = hpcRpcWrInt(pbuf, HPCFS_FUNC_OPEN); pbuf = hpcRpcWrInt(pbuf, pmode); pbuf = hpcRpcWrInt(pbuf, pperm); pbuf = hpcRpcWrCStr(pbuf, name); semTake(rpcAccess, WAIT_FOREVER); result = hpcFuncRWTimeout(HpcChanNum, HPC_WRITE, (unsigned char*)buf, pbuf - buf, &bytesUsed, HpcTimeout); if (result != HPC_OK) { semGive(rpcAccess); return (int) result; } result = hpcFuncRWTimeout(HpcChanNum, HPC_READ, buf, sizeof(buf), &bytesUsed, HpcTimeout); semGive(rpcAccess); if (result != HPC_OK) { return (int) result; } pbuf = buf; pbuf = hpcRpcRdInt(pbuf, &iResult); if (iResult != 0) return iResult; pbuf = hpcRpcRdInt(pbuf, channel); return OK;}inthpcfsFuncDel(char *name){ HPC_ERROR_CODE result; int iResult; char buf[RPC_BUFF_SIZE], *pbuf = buf; unsigned int bytesUsed; pbuf = hpcRpcWrInt(pbuf, HPCFS_FUNC_DEL); pbuf = hpcRpcWrCStr(pbuf, name); semTake(rpcAccess, WAIT_FOREVER); result = hpcFuncRWTimeout(HpcChanNum, HPC_WRITE, (unsigned char*)buf, pbuf - buf, &bytesUsed, HpcTimeout); if (result != HPC_OK) { semGive(rpcAccess); return (int) result; } result = hpcFuncRWTimeout(HpcChanNum, HPC_READ, buf, sizeof(buf), &bytesUsed, HpcTimeout); semGive(rpcAccess); if (result != HPC_OK) { return (int) result; } pbuf = buf; pbuf = hpcRpcRdInt(pbuf, &iResult); if (iResult != 0) return iResult; return OK;}inthpcfsFuncClose(int channel){ HPC_ERROR_CODE result; int iResult; char buf[RPC_BUFF_SIZE], *pbuf = buf; unsigned int bytesUsed; pbuf = hpcRpcWrInt(pbuf, HPCFS_FUNC_CLOSE | channel); semTake(rpcAccess, WAIT_FOREVER); result = hpcFuncRWTimeout(HpcChanNum, HPC_WRITE, (unsigned char*)buf, pbuf - buf, &bytesUsed, HpcTimeout); if (result != HPC_OK) { semGive(rpcAccess); return (int) result; } result = hpcFuncRWTimeout(HpcChanNum, HPC_READ, buf, sizeof(buf), &bytesUsed, HpcTimeout); semGive(rpcAccess); if (result != HPC_OK) { return (int) result; } pbuf = buf; pbuf = hpcRpcRdInt(pbuf, &iResult); if (iResult != 0) return iResult; return OK;}inthpcfsFuncRead(int channel, char *userBuf, int maxBytes, int *actuallyRead){ HPC_ERROR_CODE result; int iResult, iSize; char buf[RPC_BUFF_SIZE], *pbuf = buf; unsigned int bytesUsed; pbuf = hpcRpcWrInt(pbuf, HPCFS_FUNC_READ | channel); pbuf = hpcRpcWrInt(pbuf, maxBytes); semTake(rpcAccess, WAIT_FOREVER); result = hpcFuncRWTimeout(HpcChanNum, HPC_WRITE, (unsigned char*)buf, pbuf - buf, &bytesUsed, HpcTimeout); if (result != HPC_OK) { semGive(rpcAccess); return (int) result; } result = hpcFuncRWTimeout(HpcChanNum, HPC_READ, buf, sizeof(buf), &bytesUsed, HpcTimeout); if (result != HPC_OK) { semGive(rpcAccess); return (int) result; } pbuf = buf; pbuf = hpcRpcRdInt(pbuf, &iResult); pbuf = hpcRpcRdInt(pbuf, &iSize); if (iResult != 0) { semGive(rpcAccess); return iResult; } if (iSize != 0) { result = hpcFuncRWTimeout(HpcChanNum, HPC_READ, userBuf, maxBytes, actuallyRead, HpcTimeout); } else { *actuallyRead = 0; } semGive(rpcAccess); if (result != HPC_OK) { return (int) result; } return OK;}inthpcfsFuncWrite(int channel, char *userBuf, int maxBytes, int *actuallyWritten){ HPC_ERROR_CODE result; int iResult; char buf[RPC_BUFF_SIZE], *pbuf = buf; unsigned int bytesUsed; pbuf = hpcRpcWrInt(pbuf, HPCFS_FUNC_WRITE | channel); pbuf = hpcRpcWrInt(pbuf, maxBytes); semTake(rpcAccess, WAIT_FOREVER); result = hpcFuncRWTimeout(HpcChanNum, HPC_WRITE, (unsigned char*)buf, pbuf - buf, &bytesUsed, HpcTimeout); if (result != HPC_OK) { semGive(rpcAccess); return (int) result; } result = hpcFuncRWTimeout(HpcChanNum, HPC_WRITE, (unsigned char*)userBuf, maxBytes, &bytesUsed, HpcTimeout); if (result != HPC_OK) { semGive(rpcAccess); return (int) result; } result = hpcFuncRWTimeout(HpcChanNum, HPC_READ, buf, sizeof(buf), &bytesUsed, HpcTimeout); semGive(rpcAccess); if (result != HPC_OK) { return (int) result; } pbuf = buf; pbuf = hpcRpcRdInt(pbuf, &iResult); if (iResult != 0) { return iResult; } pbuf = hpcRpcRdInt(pbuf, actuallyWritten); return OK;}inthpcfsFuncIoctl(int channel, int request, int arg, int *resultArg){ HPC_ERROR_CODE result; int iResult; char buf[RPC_BUFF_SIZE], *pbuf = buf; unsigned int bytesUsed; pbuf = hpcRpcWrInt(pbuf, HPCFS_FUNC_IOCTL | channel); pbuf = hpcRpcWrInt(pbuf, request); pbuf = hpcRpcWrInt(pbuf, arg); semTake(rpcAccess, WAIT_FOREVER); result = hpcFuncRWTimeout(HpcChanNum, HPC_WRITE, (unsigned char*)buf, pbuf - buf, &bytesUsed, HpcTimeout); if (result != HPC_OK) { semGive(rpcAccess); return (int) result; } result = hpcFuncRWTimeout(HpcChanNum, HPC_READ, buf, sizeof(buf), &bytesUsed, HpcTimeout); semGive(rpcAccess); if (result != HPC_OK) { return (int) result; } pbuf = buf; pbuf = hpcRpcRdInt(pbuf, &iResult); if (iResult != 0) return iResult; return OK;}/*HPCFS_CHANNEL_DESC* hpcfsChannel[MAX_CHANNELS];int hpcfsFuncWrite(int channel, char *buf, int maxBytes, int *errno){ static char hdr[8], *h; HPCFS_CHANNEL_DESC *desc = hpcfsChannel[channel]; h = hpcRpcWrInt(hdr, HPC_FS_FUNC_WRITE | MAKE_CHANNEL(channel)); h = hpcRpcWrDataHdr(h, maxBytes) hpcfsTxSend(hdr, h-hdr, buf, maxBytes); semTake(desc->rpcSem); *errno = desc->errno; return (desc->numBytes);}void hpcfsRtnWrite(int channel, char *buf){ HPCFS_CHANNEL_DESC *desc; if ((channel < 0) || (channel >= MAX_CHANNELS)) return; desc = hpcfsChannel[channel]; if (desc == NULL) return; hpcRpcRdInt(buf, &desc->errno); hpcRpcRdInt(buf, &desc->numBytes); semGive(desc->rpcSem);}int hpcfsFuncRead(int channel, char *buf, int maxBytes, int *errno){ static char buf[8], *b; HPCFS_CHANNEL_DESC *desc = hpcfsChannel[channel]; b = hpcRpcWrInt(buf, HPC_FS_FUNC_READ | MAKE_CHANNEL(channel)); hpcRpcWrInt(b, maxBytes); desc->buf = buf; hpcfsTxSend(buf, 4, buf, maxBytes); semTake(desc->rpcSem); *errno = desc->errno; return (desc->numBytes);}void hpcfsRtnRead(int channel, char *buf){ HPCFS_CHANNEL_DESC *desc; if ((channel < 0) || (channel >= MAX_CHANNELS)) return; desc = hpcfsChannel[channel]; if (desc == NULL) return; hpcRpcRdInt(buf, &desc->errno); hpcRpcRdData( hpcRpcRdInt(buf, &desc->numBytes); semGive(desc->rpcSem);}*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -