?? rmlocalremote.c
字號(hào):
/***************************************** Copyright (c) 2001-2003 Sigma Designs, Inc. All Rights Reserved Proprietary and Confidential *****************************************/#ifndef ALLOW_OS_CODE#define ALLOW_OS_CODE 1#endif //ALLOW_OS_CODE#include <stdlib.h>#include <fcntl.h>#include <termios.h>#include <unistd.h>#include <time.h>typedef struct { RMint32 fd;}remoteHandleType;#ifndef EM86XX_REMOTEstatic RMstatus RMPseudoFileSetRaw(RMint32 fd){ struct termios newtermios; if (tcgetattr(fd,&newtermios)<0) { printf("RMPseudoFileSetRaw : failed tcgetattr\n"); return RM_ERROR; } // all the basic magic for raw mode cfmakeraw(&newtermios); // input speed setting if (cfsetispeed(&newtermios,B1200)<0) { printf("RMPseudoFileSetRaw : failed cfsetispeed\n"); return RM_ERROR; } // receive byte per byte newtermios.c_cc[VMIN] = 1; newtermios.c_cc[VTIME] = 0; /* You tell me why TCSAFLUSH. */ if(tcsetattr(fd, TCSAFLUSH, &newtermios) < 0) { printf("RMPseudoFileSetRaw : failed newtermios\n"); return RM_ERROR; } return RM_OK;}#endifstatic RMstatus RMlocalRemoteOpen(const RMascii *device, remoteHandleType **handle){ int flags = O_RDONLY; *handle=(remoteHandleType *)MALLOC(sizeof(remoteHandleType)); (*handle)->fd=open(device, flags); if ((*handle)->fd <= 0) { printf("RMlocalRemoteOpen : Cannot open device %s \n", device); free(*handle); return RM_ERROR; }#ifndef EM86XX_REMOTE if (RMPseudoFileSetRaw((*handle)->fd)!=RM_OK) { printf("Cannot exec RMPseudoFileSetRaw\n"); free(*handle); return RM_ERROR; }#endif return RM_OK;}static RMint32 RMFlushCallback (void *fileHandle){#ifndef EM86XX_REMOTE return tcflush(((remoteHandleType*)fileHandle)->fd,TCIOFLUSH);#else return 0;#endif}static void RMlocalRemoteClose(remoteHandleType **handle){ close((*handle)->fd); RFREE(*handle); *handle = NULL;}static RMint32 PseudoFileReadWithTimeout(void *fileHandle,void *buf,RMuint32 count,RMint64 timeoutMicroSeconds){RMbool b; fd_set rfds; RMuint32 *key; RMuint16 hi,lo; struct timeval tv, *tva; ssize_t res = 0; FD_ZERO(&rfds); FD_SET(((remoteHandleType*)fileHandle)->fd,&rfds); if (timeoutMicroSeconds==-1) tva=NULL; else { tv.tv_sec=timeoutMicroSeconds/1000000ULL; tv.tv_usec=timeoutMicroSeconds%1000000ULL; tva=&tv; }RMDBGPRINT((DISABLE, "> select %d\n", FD_ISSET(((remoteHandleType*)fileHandle)->fd, &rfds))); b = select(((remoteHandleType*)fileHandle)->fd+1, &rfds, NULL, NULL, tva) > 0;RMDBGPRINT((DISABLE, "> select OK\n")); if (b) { res = read(((remoteHandleType*)fileHandle)->fd,buf,count); key = (RMuint32*) buf; hi = (*key & 0xFFFF0000) >>16; lo = (*key & 0x0000FFFF); printf("DBG: key %x%x\n",hi,lo); return(res > 0 ? res : 0); } else return 0;}RMbool PseudoFileAvailable(void *fileHandle){ fd_set rfds; struct timeval tv, *tva; FD_ZERO(&rfds); FD_SET(((remoteHandleType*)fileHandle)->fd,&rfds); tv.tv_sec=0; tv.tv_usec=1000; tva=&tv; return (select(((remoteHandleType*)fileHandle)->fd+1, &rfds, NULL, NULL, tva) > 0);}static void RMSleepCallback(RMuint64 microsec){ struct timespec usleep_req = { 0 }; usleep_req.tv_sec = microsec / 1000000; usleep_req.tv_nsec = (microsec % 1000000) * 1000; nanosleep(&usleep_req, 0);}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -