📄 wdbserial.c
字号:
/* wdbserial.c - Remote Procedure Call (RPC) backend library *//* Copyright 1995-1998 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------01i,25jan99,elg Add Flow Control on Serial Backend (SPR 22159)01h,15jun98,c_c Changed the init_2 routine to initialize to be in sync with the doc.01g,11feb98,c_c Removed the -Bd flag.01f,04feb98,c_c Removed log routines.01e,21jan98,c_c Implemented backend V2 APIs. Get rid of EXT_FUNC refs.01d,28jun96,c_s just include <fcntl.h>; this is more portable.01c,15jan96,elp added external function variable + modified wdbserialInit to take care of new variable01b,11jun95,p_m added errno = WTX_ERR_SVR_INVALID_DEVICE when an invalid device is given.01a,31may95,tpr written, inspired from wdbrpc.c version 02l.*//*DESCRIPTIONThis file is a target server backend using the RPC mechanism to dialog witha WDB target agent. This backend is the default backend attached when the userstart the target server without specifying a backend. It's also attached whenthe target server is started with the option -a followed by "wdbrpc".The communication protocol used is UDP/IP. To increase the reliability of thisprotocol a simple mechanism of timeout and re-sending is implemented. When aservice is called a timer (implemented in the RPC client mechanism) isalso started. If the timeout arrived before the service has replied then therequest is re-sent. The number of time a same request can be re-sent is limited.When this limit is reached and the service call fails one more in timeout thelink is declared as broken. The default timeout value is handled by WDB_TIMEOUTbut this value can be changed by the user. He must start the target server withthe option -Bt followed by a number. This number is the timeout value to use(in second). The user can also modify the maxinum number of time that a samerequest can be re-sent. In this case the option -Br must be used. The default value of this option is handled by WDB_MAX_RESEND.The TCP/IP was not used because it requests timer. This feature is not alwaysavailable on all target boards. Moreover the implementation of this protocolrequer more memory space as the UDP protocol. As the WDB target agent mustbe the smallest possible the UDP protocol is the obligatory choise.This backend file handles all functions that a target serveur backend request.The diagram below gives the function link. The wdbRpcClntCall () isthe root function. It allows to call any WDB service and performs the linkreliability control as describe before. This function is called by 7 functions:5 are backend functions and 2 are internal to this backend. This 2 functions(wdbRpcCallRStatus() and wdbRpcCallStatus()) are used by the otherbackend functions that don't call wdbRpcClntCall() directly. They allow tocall a WDB service but this service must return either a RESULT_STATUS (forwdbRpcCallRStatus()) or a STATUS (for wdbRpcCallStatus()). *//* includes */#include <stdio.h>#include <netdb.h>#include <arpa/inet.h>#include <rpc/rpc.h>#include <sys/time.h>#include <sys/types.h>#include <sys/socket.h>#include <fcntl.h>#include "tgtlib.h"#include "tgtsvr.h"#include "tssvcmgt.h"#include "host.h"#include "wdb.h"#include "wdbP.h"#include "bkendlib.h"#include "bkendlog.h"#include "wpwrutil.h"#include "flagutil.h"#ifdef WIN32#include "win32Serial.h"#endif /* WIN32 *//* locals */#ifndef WIN32LOCAL char * pTtyDevName = "/dev/ttya"; /* serial device -a- */#elseLOCAL char * pTtyDevName = "com2"; /* serial device -a- */#endifLOCAL int baudRate = 9600; /* Serial line speed */LOCAL BOOL hardFlowControl = FALSE; /* Serial Flow Control */LOCAL int timeout = BKEND_TIMEOUT;/* timeout value */LOCAL int recallNum = BKEND_RESEND; /* how much calls allowed */static FLAG_DESC wdbserialFlags [] = { { "-bps", "-b", (PARSE_RTN) flagInt, &baudRate, "-b[ps] bit/s\t\tHost tty device speed. (default 9600)." }, { "-device", "-d", (PARSE_RTN) flagName, &pTtyDevName,#ifndef WIN32 "-d[evice] device\tHost tty device to use. (default /dev/ttya)."#else "-d[evice] device\tHost tty device to use. (default com2)."#endif }, { "-Btimeout","-Bt", (PARSE_RTN) flagInt, &timeout, "-Bt[imeout] value\tWDB Serial Backend request timeout (default 1 sec)." }, { "-Bresend", "-Br", (PARSE_RTN) flagInt, &recallNum, "-Br[esend] number\tWDB Serial Backend request re-send number (default 3)." }, { "-hfc", NULL, (PARSE_RTN) flagBool, &hardFlowControl, "-hfc\t\t\tInclude hardware flow control." }, {NULL, NULL, NULL, NULL, NULL} /* End Of Record delimiter */ }; /* forward declarations */extern STATUS rpcCoreInit (CLIENT *, u_int, u_int, TGT_OPS *);extern CLIENT * clnttty_create (char *, int, BOOL, u_long, u_long, struct timeval);/********************************************************************************* wdbserialFlagsGet - Get the supported flags for this backend** This function is called by the target server when it wants to get the flags* which are supported by the currently attached backend. The following options* can be set trough command line parameters.** <timeout> is the time out duration to use for the communication with the* WDB target agent. This input argument is set when the target server is* started with the option -Bt. Otherwise set to zero.** <recallNum> is the maximun number of time that a request is re-sent before* to admit the communication link is broken. Set when the target server is* started with the option -Br, otherwise reset to zero.** <pTtyDevName> is the name of the device to use to deal with the target. It* can be set with the -d(evice) parameter (defaults to /dev/ttya for UNIX or* COM1 for WIN32).** <baudRate> is the speed of the used serial line. It can be set with the* -b(ps) parameter (defaults to 9600).** * Here we return our supported flags.**/DLL_EXPORT FLAG_DESC * wdbserialFlagsGet (void) { return (FLAG_DESC *) wdbserialFlags; }/********************************************************************************* wdbserialInitialize - initialize the backend interface.** This function is called by the target server when it wants to attach this* backend. Four input arguments are accepted:** <tgtName> is a pointer to a string that handles either the name or the* internet address (in dotted-decimal * format) of the target board. ** <pTgtOps> is a pointer to TGT_OPS structure (defines in tgtlib.h file).* This structure handles function pointers used by the target server to call* a backend function. The backend attachment is performed by filling this* structure with the backend function address. ** <pBkInfo> is a structure to fill for the target server to know if the backend* exports a selectable file descriptor, a select-like function, or nothing for* the asynchronous event notification. * Remember that the target server now dedicates a thread to the event* notification.** This function initializes the backend. It creates the backend client, resets* the udp datagram sequence number and fills the TGT_OPS structure with* the information describing the backend and returns a pointer to this * structure.** CAVEAT: its name is built from the file name concatenated with the string* "Initialize". This is compulsory.* * RETURNS: TRUE if the backend is properly initialized, otherwise FALSE.*/DLL_EXPORT STATUS wdbserialInitialize ( char * tgtName, /* target name to connect to (unused) */ TGT_OPS * pTgtOps, /* backend function */ BKEND_INFO * pBkInfo /* Backend info and select method */ ) { CLIENT * pClnt; /* target client */ struct timeval tv; /* connection timeout */ u_int resendCnt; /* connection re-send counter */ /* set the connection timeout to the current value */ tv.tv_sec = timeout; tv.tv_usec = 0; /* * set the resendCnt counter with the maximun of time the client creation * will be re-tried. */ resendCnt = recallNum; do { /* create the backend client and connect the target deamon */ pClnt = clnttty_create (pTtyDevName, baudRate, hardFlowControl, WDBPROG, WDBVERS, tv); } while((pClnt == NULL) && (--resendCnt > 0)); /* * check the client creation : If the creation failed, log a message with * the RPC error and return ERROR to stop the target server initialization. */ if(pClnt == NULL) { /* * XXX p_m: We set errno to WTX_ERR_SVR_INVALID_DEVICE here since * an invalid serial device is the main cause of failure, but it's * not the only one. Should be fixed someday. */ errno = WTX_ERR_SVR_INVALID_DEVICE; wpwrLogErr ("%s\n", clnt_spcreateerror("wdbserial backend client create")); return (ERROR); } /* initialize the rpc core */ rpcCoreInit (pClnt, timeout, recallNum, pTgtOps); /* describe the link used between the backend and the target */ pTgtOps->tgtLink.name = "WDB Agent across serial line"; pTgtOps->tgtLink.type = TGT_LINK_SERIAL_RPC; pTgtOps->tgtLink.speed = baudRate; pBkInfo->tgtBkVersion = BKEND_VERSION_2; /* Backend version 2 */ #ifdef WIN32 /* we'll provide our polling method ( on NT ) */ pBkInfo->INFO.POLLING_METHOD.bkEndPollingMethod = POLL_BKROUTINE_MODE; pBkInfo->INFO.POLLING_METHOD.BKEND_NOTIF_METHOD.bkEndSelectRtn = win32SerialSelect;#else /* on UNIX we give the tty file desc */ pBkInfo->INFO.POLLING_METHOD.bkEndPollingMethod = POLL_SELECT_MODE; pBkInfo->INFO.POLLING_METHOD.BKEND_NOTIF_METHOD.pollingFd = pTgtOps->tgtEventFd;#endif /* WIN32 */ return (OK); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -