original files of m241

This commit is contained in:
neelimap
2026-07-30 11:19:44 +05:30
parent 170c2b3f3a
commit afc7070c1f
12254 changed files with 7655111 additions and 0 deletions
+442
View File
@@ -0,0 +1,442 @@
/* mipc.h - Library for multi-OS IPC */
/********************************************************************
The following file is dual licensed and is available under either
the GPL version 2 or a Wind River commercial license.
*********************************************************************
Copyright (c) 2008-2011 Wind River Systems, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2 as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*********************************************************************
Copyright (c) 2008-2011 Wind River Systems, Inc.
The right to copy, distribute, modify, or otherwise make use
of this software may be licensed pursuant to the terms
of an applicable Wind River license agreement.
*********************************************************************/
/*
modification history
--------------------
02m,07jan11,jlk Update license header and update version to 2.2
02l,24sep10,jlk Add support for setting and getting debug mode
02k,03jun10,als Ensure address argument to mipc_bind() is not altered
02j,02jun10,als Remove code for deprecated MIPC 1.0 APIs
02i,02mar10,als Add support for 64-bit memory addressing
02h,29oct09,als Fix minor API issues (WIND00186193)
02g,15sep09,als Adjust MIPC_SD_BITS to account for smaller socket structure
02f,09sep09,als Correct minor statistics collection issues
02e,19aug09,h_x Fix for WIND00176194
02d,19aug09,als Correct port number usage definitions
02c,11aug09,ebh Add in suggested port number for applications to start using
02b,07aug09,als Make socket descriptors simple positive integers
02a,04aug09,als Convert shared memory offsets to use MIPC_OFFSET type
01z,29jul09,als Add support for per-bus statistics collection
01y,28jul09,als Add/revise APIs to reflect feedback from HLD review
01x,03jul09,als Remove socket option default symbols
01w,30jun09,als Make express callback arg types consistent with rx callback
01v,26jun09,h_w Rename express data messaging send routine 'mipc_send_express'
to 'mipc_sendexpress64'
01u,17jun09,ebh Add MIPC_SD_BITS definition
01t,13jun09,ebh Add mipc_zallocbuf for fast buffer allocations
01s,09jun09,als Rework system configuration/initialization as per HLD and CI
01r,03jun09,ebh Add support for a callback on a listening socket for incoming
connect request
01q,25may09,ebh Remove the MIPC_BROADCAST macro that is obsolete
01p,13may09,ebh Turn on CHECK_ARGS and KEEP_STATS
01o,01may09,ebh Update the getuserhandle and setuserhandle macros
01n,29apr09,ebh Remove unused macro MIPC_SO_USER_DATA
01m,28apr09,ebh Modify the API for mipc_setuserhandle() and
mipc_getuserhandle()
01l,24apr09,ebh Restore MIPC_BROADCAST temporarily
01k,21apr09,ebh Add in macros for ANY parameter specification for mipc_bind
01j,20apr09,ebh Add mipc_getbusmaxnodes API
01i,25mar09,ebh Add in define for MIPC_BUFFER_STARVATION_PREVENTION
01h,20mar09,ebh Fix Default TIMEOUTS to include WAIT_FOREVER values
01g,11mar09,ebh Add in a macro for wait forever on a receive
01f,15dec08,apa Added MIPC 2.0 changes.
01e,27nov08,ebh Turn off default API parameter checks MIPC_CHECK_ARGS
01d,24nov08,ebh Add in versioning macros
01c,15sep08,apa Changes and fixes following code review.
01b,11aug08,apa Changes to sync up with latest MIPC HLD.
01a,11jun08,apa Initial version.
*/
#ifndef __INCmipch
#define __INCmipch
#include "multios_adapt.h"
#include "mipc_os_adapt.h"
#ifdef __cplusplus
extern "C" {
#endif
/*---------------------------------------------------------------------------
* Version Macros
*---------------------------------------------------------------------------
*/
#define MIPC_VERSION_MAJOR 2 /* major version of MIPC */
#define MIPC_VERSION_MINOR 2 /* minor version of MIPC */
/*---------------------------------------------------------------------------
* API - Constants and Types
*---------------------------------------------------------------------------
*/
/* Socket option level */
#define MIPC_SOL 0
/* Socket options [used with mipc_getsockopt() and mipc_setsockopt()] */
#define MIPC_SO_TXBUFS 0
#define MIPC_SO_MTU 1
#define MIPC_SO_RX_CALLBACK 2
#define MIPC_SO_NODEJOIN_CALLBACK 3
#define MIPC_SO_NODELEFT_CALLBACK 4
#define MIPC_SO_TXBUFAVAIL_CALLBACK 5
#define MIPC_SO_NBIO 6
/* for MIPC_SO_TXBUFAVAIL_THRESHOLD 7 now unsupported */
#define MIPC_SO_CONN_TIMEOUT 8
#define MIPC_SO_SEND_TIMEOUT 9
#define MIPC_SO_CONNECTED_CALLBACK 10
#define MIPC_SO_CONNECTREFUSED_CALLBACK 11
#define MIPC_SO_DISCONNECTED_CALLBACK 12
#define MIPC_SO_RECEIVE_TIMEOUT 13
#define MIPC_SO_RXBUFS 14
/* for MIPC_SO_SHUTDOWN_TIMEOUT 15 now unsupported */
#define MIPC_SO_EXPRESS_CALLBACK 16
/* for MIPC_SO_EVENTQUEUE_SIZE 17 now unsupported */
#define MIPC_SO_RXQUEUED_CALLBACK 18
#define MIPC_SO_CONNECTREQUEST_CALLBACK 19
/* Socket and timing option */
#define MIPC_TIMEOUT_FOREVER (-1)
/* Return values of MIPC_RX_CALLBACK */
#define MIPC_RX_RELEASEBUF 0
#define MIPC_RX_QUEUEBUF 1
#define MIPC_RX_KEEPBUF 2
/* Addressing values for mipc_bind calls */
#define MIPC_BUS_ANY ((uint16_t)(~0))
#define MIPC_NODE_ANY ((uint16_t)(~0))
#define MIPC_PORT_ANY ((uint16_t)(~0))
/* MIPC port number allocations */
#define MIPC_SYS_PORT_BASE 0 /* lowest reserved port number */
#define MIPC_OPEN_PORT_BASE 3 /* lowest unreseved port number */
/* MIPC socket address structure */
struct mipc_sockaddr
{
unsigned short family; /* family number (MIPC_AF) */
unsigned short busNum; /* bus number */
unsigned short nodeNum; /* node number */
unsigned short portNum; /* port number */
};
/* MIPC statistics structure (one per active bus) */
struct mipc_stats {
uint32_t bufs_sent; /* # buffers sent */
uint32_t bufs_rcvd; /* # buffers received */
uint32_t bytes_sent; /* # buffer bytes sent */
uint32_t bytes_rcvd; /* # buffer bytes received */
uint32_t bufs_allocated; /* # buffers allocated */
uint32_t bufs_freed; /* # buffers freed */
uint32_t buf_cong_wait; /* buffer congestion (blocking) */
uint32_t buf_cong_no_wait; /* buffer congestion (non-blocking) */
uint32_t buf_avail_sent; /* buffer available events sent */
uint32_t buf_avail_rcvd; /* buffer available events received */
uint32_t express_msgs_sent; /* express messages sent */
uint32_t express_msgs_rcvd; /* express messages received */
uint32_t buffer_not_avail; /* couldn't get buffer from packet pool */
uint32_t event_not_avail; /* couldn't get event from event pool */
uint32_t interrupts_sent; /* # interrupts sent */
uint32_t interrupts_rcvd; /* # interrupts received */
uint32_t interrupts_deferred; /* # invocations of deferred work thead */
uint32_t sockets_bound; /* # sockets bound to bus */
uint32_t sockets_closed; /* # sockets closed after binding to bus */
uint32_t socket_rx_queue_err; /* # socket rx queue errors (full q) */
};
/* Node-independent memory offset [opaque type; definition subject to change] */
typedef uint32_t MIPC_OFFSET;
/* Zero-copy buffer handle [opaque type; definition subject to change] */
typedef void *MIPC_ZBUFFER;
/* Called when an incoming buffer has been received */
typedef int (*MIPC_RX_CALLBACK) (int sd,
const unsigned char *buff,
size_t nbytes,
unsigned short srcNodeNum,
unsigned short srcPortNum,
MIPC_ZBUFFER zbuf);
/* Called when an incoming buffer has been queued */
typedef int (*MIPC_RXQUEUED_CALLBACK) (int sd);
/* Called when a node has joined the bus */
typedef void (*MIPC_NODEJOIN_CALLBACK) (int sd, unsigned short nodeNum);
/* Called when a node has left the bus */
typedef void (*MIPC_NODELEFT_CALLBACK) (int sd, unsigned short nodeNum);
/* Called when there are transmission buffers available */
typedef void (*MIPC_TXBUFAVAIL_CALLBACK) (int sd);
/* Called when a connection is established on a socket */
typedef void (*MIPC_CONNECTED_CALLBACK) (int sd);
/* Called when a connection is refused on a socket */
typedef void (*MIPC_CONNECTREFUSED_CALLBACK) (int sd);
/* Called when a socket become disconnected */
typedef void (*MIPC_DISCONNECTED_CALLBACK) (int sd);
/* Called when a connect request is received on a listening socket */
typedef void (*MIPC_CONNECTREQUEST_CALLBACK) (int sd);
/* Called when 64-bit express data is received */
typedef void (*MIPC_EXPRESS_CALLBACK) (int sd, unsigned short srcNode,
unsigned short srcPort, uint64_t data);
/*---------------------------------------------------------------------------
* API - Functions
*---------------------------------------------------------------------------
*/
/* Accept a connection on a MIPC socket */
int mipc_accept(int sd, struct mipc_sockaddr *addr, socklen_t *addrlen);
/* Convert a local pointer address to a node-independent offset */
static MULTIOS_INLINE MIPC_OFFSET mipc_addr2offset(void *address);
/* Bind an address to a MIPC socket */
int mipc_bind(int sd, const struct mipc_sockaddr *myaddr, socklen_t addrlen);
/* Clear MIPC statistics for a bus */
int mipc_clearstatsbybus(int busnum);
/* Close a MIPC socket */
int mipc_close(int sd);
/* Request a connection to a MIPC socket */
int mipc_connect(int sd, const struct mipc_sockaddr *servaddr,
socklen_t addrlen);
/* Get bitfield of the buses this node can utilize */
int mipc_getactivebusesl(unsigned char *buses, size_t buseslen);
/* Get bitfield of the active nodes on a bus */
int mipc_getactivenodes(int bus, unsigned long long *nodes);
/* Get bitfield of the active nodes on a bus */
int mipc_getactivenodesl(int bus, unsigned char *nodes, size_t nodeslen);
/* Get the number of a bus given its name */
int mipc_getbusbyname(const char *name, int *busnum);
/* Get the number of nodes present on a bus */
int mipc_getbusmaxnodes(int busnum);
/* Get the name of a bus given its number */
int mipc_getnamebybus(int busnum, char *name, size_t namelen);
/* Get the node number of this node on a bus */
int mipc_getnodebybus(int busnum);
/* Get the address of the peer MIPC socket */
int mipc_getpeername(int sd, struct mipc_sockaddr *addr, socklen_t *addrlen);
/* Get the address of a MIPC socket */
int mipc_getsockname(int sd, struct mipc_sockaddr *addr, socklen_t *addrlen);
/* Get the value of an option associated with a MIPC socket */
int mipc_getsockopt(int sd, int level, int optname, void *optval,
socklen_t *optlen);
/* Get MIPC statistics for a bus */
int mipc_getstatsbybus(int busnum, struct mipc_stats *buf);
/* Enable a MIPC socket to listen for connection requests */
int mipc_listen(int sd, int backlog);
/* Convert a node-independent offset to a local pointer address */
static MULTIOS_INLINE void *mipc_offset2addr(MIPC_OFFSET offset);
/* Process bus events (for polled buses) */
int mipc_processbus(int busId);
/* Receive a message from a MIPC socket */
ssize_t mipc_recv(int sd, void *buf, size_t buflen, int flags);
/* Receive a message from a MIPC socket */
ssize_t mipc_recvfrom(int sd, void *buf, size_t buflen, int flags,
struct mipc_sockaddr *from, socklen_t *fromlen);
/* Send a message to a MIPC socket */
ssize_t mipc_send(int sd, const void *buf, size_t buflen, int flags);
/* Send a message to a MIPC socket */
ssize_t mipc_sendto(int sd, const void *buf, size_t buflen, int flags,
const struct mipc_sockaddr *to, socklen_t tolen);
/* Send 64-bit data (fast datapath) */
int mipc_sendexpress64(int sd, const struct mipc_sockaddr *to,
uint64_t data);
/* Set the value of an option associated to a MIPC socket */
int mipc_setsockopt(int sd, int level, int optname,
const void *optval, socklen_t optlen);
/* Shutdown a MIPC connection */
int mipc_shutdown(int sd, int how);
/* Creates a MIPC socket */
int mipc_socket(int family, int type, int protocol);
/* Allocate a zero-copy buffer */
int mipc_zalloc(int sd, size_t nbytes, uint8_t **buf, MIPC_ZBUFFER *zbuf,
int flags);
/* Allocate a zero-copy buffer of MTU size */
int mipc_zallocbuf(int sd, uint8_t **buf, MIPC_ZBUFFER *zbuf, int flags);
/* Free a zero-copy buffer */
int mipc_zfree(int sd, MIPC_ZBUFFER zbuf);
/* Receive a zero-copy message from a MIPC socket */
ssize_t mipc_zrecv(int sd, void **buf, MIPC_ZBUFFER *zbuf, int flags);
/* Receive a zero-copy message from a MIPC socket */
ssize_t mipc_zrecvfrom(int sd, void **buf, MIPC_ZBUFFER *zbuf, int flags,
struct mipc_sockaddr *from, socklen_t *fromlen);
/* Send a zero-copy message to a MIPC socket */
ssize_t mipc_zsend(int sd, MIPC_ZBUFFER zbuf, size_t buflen, int flags);
/* Send a zero-copy message to a MIPC socket */
ssize_t mipc_zsendto(int sd, MIPC_ZBUFFER zbuf, size_t buflen, int flags,
const struct mipc_sockaddr *to, socklen_t tolen);
/* Get the user handle of a socket */
static MULTIOS_INLINE int mipc_getuserhandle(int sd, unsigned long *userhandle);
/* Set the user handle of a socket */
static MULTIOS_INLINE int mipc_setuserhandle(int sd, unsigned long userhandle);
/*---------------------------------------------------------------------------
* Implementation of inlined APIs -- NOT FOR USE BY MIPC APPLICATIONS!
*---------------------------------------------------------------------------
*/
/* Functions to get/set the debug mode */
int mipc_getdebugmode(void);
void mipc_setdebugmode(int value);
#define MIPC_SD_MODE 1
/* 0 = sd is socket array index; 1 = sd is socket array byte offset */
extern char *mipcSmStartAddr;
extern unsigned long *mipcUserHandles;
extern unsigned int mipcMaxSockets;
static MULTIOS_INLINE unsigned int mipc_sd2index(int sd)
{
#if (MIPC_SD_MODE == 0)
return (unsigned int)sd;
#else
return (unsigned int)sd >> MIPC_SD_BITS;
#endif
}
static MULTIOS_INLINE int mipc_index2sd(unsigned int index)
{
#if (MIPC_SD_MODE == 0)
return (int)index;
#else
return (int)(index << MIPC_SD_BITS);
#endif
}
static MULTIOS_INLINE unsigned int mipc_sd2offset(int sd)
{
#if (MIPC_SD_MODE == 0)
return (unsigned int)sd << MIPC_SD_BITS;
#else
return (unsigned int)sd;
#endif
}
static MULTIOS_INLINE int mipc_offset2sd(unsigned int offset)
{
#if (MIPC_SD_MODE == 0)
return (int)(offset >> MIPC_SD_BITS);
#else
return (int)offset;
#endif
}
static MULTIOS_INLINE int mipc_sd_legal(int sd)
{
#if (MIPC_SD_MODE == 0)
return (sd >= 0) && ((unsigned int)sd < mipcMaxSockets);
#else
return (sd >= 0) && (mipc_sd2index(sd) < mipcMaxSockets) &&
!(sd & ((1 << MIPC_SD_BITS) - 1));
#endif
}
static MULTIOS_INLINE MIPC_OFFSET mipc_addr2offset(void *address)
{
return (MIPC_OFFSET)((char *)address - mipcSmStartAddr);
}
static MULTIOS_INLINE void *mipc_offset2addr(MIPC_OFFSET offset)
{
return (void *)(mipcSmStartAddr + offset);
}
static MULTIOS_INLINE int mipc_getuserhandle(int sd, unsigned long *userhandle)
{
#ifdef MIPC_CHECK_ARGS
if (!mipc_sd_legal(sd))
return -MIPC_EBADF;
#endif
*userhandle = mipcUserHandles[mipc_sd2index(sd)];
return MIPC_OK;
}
static MULTIOS_INLINE int mipc_setuserhandle(int sd, unsigned long userhandle)
{
#ifdef MIPC_CHECK_ARGS
if (!mipc_sd_legal(sd))
return -MIPC_EBADF;
#endif
mipcUserHandles[mipc_sd2index(sd)] = userhandle;
return MIPC_OK;
}
#ifdef __cplusplus
}
#endif
#endif /* __INCmipch */
@@ -0,0 +1,145 @@
/* mipc_os_adapt.h - MIPC OS adaptation header file for VxWorks */
/*
* Copyright (c) 2008-2010 Wind River Systems, Inc.
*
* The right to copy, distribute, modify or otherwise make use
* of this software may be licensed only pursuant to the terms
* of an applicable Wind River license agreement.
*/
/*
modification history
--------------------
01w,08sep10,h_w Add definition of MIPC_MSG_TRUNC
01v,26aug10,jlk Make sure #ifdef __cplusplus starts after #includes
01u,02jun10,als Remove code for deprecated MIPC 1.0 APIs
01t,04mar10,als Add support for 64-bit memory addressing
01s,10feb10,h_w Update after code inspection
01r,10jan10,h_w Add AF_MIPC support
01q,29oct09,als Fix minor API issues (WIND00186193)
01p,18aug09,jlk WIND00177194 - Remove deferred semaphore code.
01o,28jul09,als Add/revise APIs to reflect feedback from HLD review
01n,26jun09,h_w Add MIPC_64bit data type definition
01m,22jun09,ebh Add -MIPC_EFAULT to the error codes
01l,17jun09,als Enhance error path code during initialization
01k,03jun09,als Rework system configuration/initialization as per HLD and CI
01j,28may09,als Revise configuration based on MIPC 2.0 HLD feedback
01i,22apr09,ebh Add in MIPC_EPROTONOSUPPORT
01h,27mar09,ebh Add in MIPC_ENOENT error code
01g,11mar09,ebh Add in MIPC_EPIPE as an error code
01f,12jan09,ebh Update for MIPC 2.0
01e,16oct08,apa Removed definitions conflicting with TIPC.
01d,18sep08,apa Changes and fixes following code review.
01c,19aug08,apa Added MIPC_MSG_USER
01b,30mar08,bwa added description.
01a,07feb08,bwa written.
*/
/*
DESCRIPTION
MIPC OS adaptation. The definitions in this file allow MIPC to run on any
OS without major changes to the MIPC code, other than adjustments in this
file and the Multios adaptation file.
*/
#ifndef __INCmipc_os_adapth
#define __INCmipc_os_adapth
#include <vxWorks.h>
#include <tickLib.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <../usr/h/multios_ipc/mipc.h>
#ifdef __cplusplus
extern "C" {
#endif
#define inline __inline__
#define __stringify_1(x) #x
#define __stringify(x) __stringify_1(x)
/* MIPC socket family support */
#define MIPC_AF AF_MIPC
/* Support MIPC socket types */
#define MIPC_SOCK_STREAM 1
#define MIPC_SOCK_DGRAM 2
#define MIPC_SOCK_RDM 4
#define MIPC_SOCK_SEQPACKET 5
/* log2 of MIPC socket structure size (rounded up to an integer value) */
#ifndef _WRS_CONFIG_LP64
#define MIPC_SD_BITS 9
#else
#define MIPC_SD_BITS 10
#endif /* _WRS_CONFIG_LP64 */
/* MIPC error codes */
#define MIPC_OK 0
#define MIPC_ENOENT ENOENT /* no such file or directory */
#define MIPC_EBADF EBADF /* bad socket number */
#define MIPC_EAGAIN EAGAIN /* try again */
#define MIPC_ENOMEM ENOMEM /* out of memory */
#define MIPC_EFAULT EFAULT /* bad address */
#define MIPC_EINVAL EINVAL /* invalid argument */
#define MIPC_ENFILE ENFILE /* socket table overflow */
#define MIPC_EWOULDBLOCK EWOULDBLOCK /* operation would block */
#define MIPC_ENOMSG ENOMSG /* no message of desired type */
#define MIPC_EMSGSIZE EMSGSIZE /* message too long */
#define MIPC_EPIPE EPIPE /* broken pipe */
#define MIPC_EPROTOTYPE EPROTOTYPE /* protocol wrong type for socket */
#define MIPC_EAFNOSUPPORT EAFNOSUPPORT /* addr family not supported */
#define MIPC_EOPNOTSUPP EOPNOTSUPP /* operation not supported */
#define MIPC_EADDRINUSE EADDRINUSE /* address already in use */
#define MIPC_EADDRNOTAVAIL EADDRNOTAVAIL /* cannot assign requested address */
#define MIPC_ENETUNREACH ENETUNREACH /* network is unreachable */
#define MIPC_ECONNABORTED ECONNABORTED /* software caused connection abort */
#define MIPC_ECONNRESET ECONNRESET /* connection reset by peer */
#define MIPC_ENOBUFS ENOBUFS /* no buffer space available */
#define MIPC_EISCONN EISCONN /* socket is already connected */
#define MIPC_ENOTCONN ENOTCONN /* socket is not connected */
#define MIPC_ESHUTDOWN ESHUTDOWN /* cannot send after socket shutdown */
#define MIPC_ETIMEDOUT ETIMEDOUT /* operation timed out */
#define MIPC_ECONNREFUSED ECONNREFUSED /* connection refused */
#define MIPC_EALREADY EALREADY /* operation already in progress */
#define MIPC_EINPROGRESS EINPROGRESS /* operation now in progress */
#define MIPC_EINTR EINTR /* interrupted */
#define MIPC_ENOPROTOOPT ENOPROTOOPT /* protocol option not available */
#define MIPC_EDESTADDRREQ EDESTADDRREQ /* destination address required */
#define MIPC_ENODEV ENODEV /* no such device */
#define MIPC_EOVERFLOW EOVERFLOW /* value too large for data type */
/* To be used with mipc_shutdown() */
#define MIPC_SHUT_RDWR SHUT_RDWR
/* To be used with the receive functions */
#define MIPC_MSG_DONTWAIT MSG_DONTWAIT
#define MIPC_MSG_WAITALL MSG_WAITALL
#define MIPC_MSG_PEEK MSG_PEEK
#define MIPC_MSG_USER MSG_COMPAT
#define MIPC_MSG_TRUNC MSG_TRUNC
/* MIPC output definitions */
#define MIPC_CONS_HDR "MIPC: "
#define MIPC_INFO MIPC_CONS_HDR "<info> "
#define MIPC_ALERT MIPC_CONS_HDR "<alert> "
#define MIPC_PRINT printf
/* Prototypes associated with ISR handler */
typedef void (*MIPC_ISR_FUNC) (void *arg);
extern int mipc_sm_isr_set(uint16_t intId, MIPC_ISR_FUNC func, void *arg);
#ifdef __cplusplus
}
#endif
#endif /* __INCmipc_os_adapth */
@@ -0,0 +1,211 @@
/* mipc_sm_adapt.h - MIPC-SM OS adaptation layer API */
/********************************************************************
The following file is dual licensed and is available under either
the GPL version 2 or a Wind River commercial license.
*********************************************************************
Copyright (c) 2008-2011 Wind River Systems, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2 as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*********************************************************************
Copyright (c) 2008-2011 Wind River Systems, Inc.
The right to copy, distribute, modify, or otherwise make use
of this software may be licensed pursuant to the terms
of an applicable Wind River license agreement.
*********************************************************************/
/*
modification history
--------------------
02b,07jan11,jlk Update license header
02a,04jan11,ste validate MIPC settings, check timer as MACRO
01z,26oct10,ste Add functions to allocate various structures
01y,26aug10,jlk Make sure #ifdef __cplusplus starts after #includes
01x,01apr10,als Initial changes in support of 64-bit memory addressing
01w,17sep09,als Obsolete MIPC_DEBUG symbol
01v,09sep09,als Correct minor statistics collection issues
01u,25aug09,bwa Add mipc_sm_adapt_get_node_id() prototype.
01t,25aug09,jlk WIND00178668 - MIPC flow control changes.
01s,12aug09,als Fix MIPC_STATS_ADD to avoid risk of mismatching else clauses
01r,07aug09,als Make socket descriptors simple positive integers
01q,05aug09,ebh Testing
01p,04aug09,als Convert shared memory offsets to use MIPC_OFFSET type
01o,02aug09,als Add support for selective stats collection
01n,29jul09,als Add support for per-bus statistics collection
01m,27jul09,als Event queue rework
01l,24jul09,jlk Event Q re-work.
01k,22jul09,als Allow adaptation code to handle fatal errors detected by
common code
01j,02jul09,als Renamed from mipc_sm_init.h
01i,16jun09,als Enhance error path code during initialization
01h,02jun09,als Rework system configuration/initialization as per HLD and CI
01g,28may09,als Revise configuration based on MIPC 2.0 HLD feedback
01f,25may09,ebh Code Inspection Modifications
01e,13may09,ebh Add in max sockets macro
01d,18mar09,ebh Add information storage in local memory about node on buses
01c,25feb09,ebh Remove POLL macro as it is no longer supported
01b,19feb09,ebh Collapse 3 packet pools into a single pool per bus
01a,15dec08,apa Initial version.
*/
#ifndef __INC_mipc_sm_adapt_h
#define __INC_mipc_sm_adapt_h
#include <multios_ipc/mipc.h>
#ifdef __cplusplus
extern "C" {
#endif
/* MIPC compile options */
#undef MIPC_CHECK_ARGS
#define MIPC_STATS_MODE 0
/* 0 = no statistics; 1 = stats in local memory */
/* (in future, may support: 2 = stats in shared memory) */
#define MIPC_STATS_FIELDS (0x000FFFFF)
/* bitfield indicating which statistics fields are to be recorded */
/* (only meaningful if MIPC_STATS_MODE > 0) */
/* MIPC shared memory size */
typedef MIPC_OFFSET MIPC_MEMSIZE;
/* MIPC configuration settings specified for this node */
struct mipc_sm_config
{
char *busList; /* ptr to bus info */
uint32_t nodeBuffers; /* default # of buffers per bus */
uint32_t nodeMtu; /* default buffer size per bus */
uint32_t nodeMaxNodes; /* default max # nodes per bus */
uint32_t nodeMaxPorts; /* default num ports per bus */
int32_t nodeEvents; /* default # of events per bus */
int32_t nodeQos; /* default quality of service */
int32_t nodeSockets; /* number of sockets on node */
uint32_t nodeInitMode; /* SM initialization mode used by node */
uint32_t nodeHeartbeatPeriod; /* heartbeat period (ms) */
void *systemPoolBaseAddr; /* location of the SM region */
MIPC_MEMSIZE systemPoolSize; /* size of the SM region */
uint32_t nodeIntId; /* interrupt num of this node */
};
/* MIPC atomic statistics - must match struct mipc_stats & MIPC_STATS_FIELDS */
#define MIPC_STATS_BUFS_SENT 0
#define MIPC_STATS_BUFS_RCVD 1
#define MIPC_STATS_BYTES_SENT 2
#define MIPC_STATS_BYTES_RCVD 3
#define MIPC_STATS_BUFS_ALLOCATED 4
#define MIPC_STATS_BUFS_FREED 5
#define MIPC_STATS_BUF_CONG_WAIT 6
#define MIPC_STATS_BUF_CONG_NO_WAIT 7
#define MIPC_STATS_BUF_AVAIL_SENT 8
#define MIPC_STATS_BUF_AVAIL_RCVD 9
#define MIPC_STATS_EXPRESS_MSGS_SENT 10
#define MIPC_STATS_EXPRESS_MSGS_RCVD 11
#define MIPC_STATS_BUFFER_NOT_AVAIL 12
#define MIPC_STATS_EVENT_NOT_AVAIL 13
#define MIPC_STATS_INTERRUPTS_SENT 14
#define MIPC_STATS_INTERRUPTS_RCVD 15
#define MIPC_STATS_INTERRUPTS_DEFERRED 16
#define MIPC_STATS_SOCKETS_BOUND 17
#define MIPC_STATS_SOCKETS_CLOSED 18
#define MIPC_STATS_SOCKET_RX_QUEUE_ERR 19
#define MIPC_NUM_STATS (sizeof(struct mipc_stats) / sizeof(uint32_t))
/* MIPC routines that OS adaptation code must call */
int mipc_sm_init(struct mipc_sm_config *config);
void mipc_sm_api_process_rx_events(uint16_t busId);
#if (MIPC_STATS_MODE > 0)
#define MIPC_STATS_ADD(stats, statId, value) \
do { if (MIPC_STATS_FIELDS & (1 << statId)) \
MULTIOS_ATOMIC_ADD(stats + statId, value); } while (0)
#else
#define MIPC_STATS_ADD(busId, statId, value) \
do { } while (0)
#endif
struct mipc_sm_sys_config;
struct mipc_sm_node_config;
struct mipc_sm_bus_config;
/* OS adaptation routines that MIPC calls */
int mipc_sm_adapt_get_cpu_id(void);
int mipc_sm_adapt_get_node_id(void);
int mipc_sm_adapt_config_init(uint32_t maxBuses);
int mipc_sm_adapt_config_bus(uint16_t busId, uint16_t nodeId, int qos,
uint16_t intId, MULTIOS_ATOMIC *stats);
int mipc_sm_adapt_config_done(uint32_t maxBuses);
void mipc_sm_adapt_config_abort(void);
int mipc_sm_adapt_notify_node(uint16_t busId, uint16_t nodeId, uint16_t intId);
void mipc_sm_adapt_fatal_error(char *reason);
int mipc_sm_adapt_validate_settings(uint16_t num_buses,
struct mipc_sm_sys_config *sys,
struct mipc_sm_node_config *nodes,
struct mipc_sm_bus_config *buses);
/* Functions use to allocate/free different type of data */
unsigned long *mipc_alloc_sock_user_handle(uint32_t number);
void mipc_free_sock_user_handle(unsigned long *ptr);
struct mipc_sm_socket *mipc_alloc_socket(uint32_t number);
void mipc_free_socket(struct mipc_sm_socket *ptr);
struct mipc_sm_rx_buffer *mipc_alloc_rx_buffer(int sd, uint32_t number);
void mipc_free_rx_buffer(int sd, struct mipc_sm_rx_buffer* ptr);
struct mipc_sm_conn_request *mipc_alloc_conn_request(int sd, uint32_t number);
void mipc_free_conn_request(int sd, struct mipc_sm_conn_request *ptr);
struct mipc_sm_local_port_info *mipc_alloc_local_port_info(int busId, uint32_t number);
void mipc_free_local_port_info(struct mipc_sm_local_port_info *ptr);
struct mipc_sm_local_peer_info *mipc_alloc_local_peer_info(int busId, uint32_t number);
void mipc_free_local_peer_info(struct mipc_sm_local_peer_info *ptr);
struct mipc_sm_local_bus_info *mipc_alloc_local_bus_info(uint32_t number);
void mipc_free_local_bus_info(struct mipc_sm_local_bus_info *ptr);
struct mipc_sm_bus_config *mipc_alloc_bus_config(uint32_t number);
void mipc_free_bus_config(struct mipc_sm_bus_config *ptr);
struct mipc_sm_node_config *mipc_alloc_node_config(uint32_t number);
void mipc_free_node_config(struct mipc_sm_node_config* ptr);
struct mipc_sm_sys_config *mipc_alloc_sys_config(void);
void mipc_free_sys_config(struct mipc_sm_sys_config *ptr);
static MULTIOS_INLINE void mipc_sm_adapt_check_timer(MULTIOS_TIMER_ID timer)
{
MIPC_SM_ADAPT_CHECK_TIMER(timer);
}
#ifdef __cplusplus
}
#endif
#endif /* __INC_mipc_sm_adapt_h */
@@ -0,0 +1,210 @@
/* mipcnetIpc.h - private Multi-OS IPC API for MND net driver */
/********************************************************************
The following file is dual licensed and is available under either
the GPL version 2 or a Wind River commercial license.
*********************************************************************
Copyright (c) 2008-2011 Wind River Systems, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2 as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*********************************************************************
Copyright (c) 2008-2011 Wind River Systems, Inc.
The right to copy, distribute, modify, or otherwise make use
of this software may be licensed pursuant to the terms
of an applicable Wind River license agreement.
*********************************************************************/
/*
modification history
--------------------
01i,07jan11,jlk Update license header
01h,17dec10,h_w Add the API mipcnetUnitTxBufAvail and other type defines
01g,23jun10,h_w upgrade to MND 2.1
01f,29apr10,h_w fix WIND00162940, add an api mipcnetBusCtrlTxActive to
active bus control tx task mipcnetBusCtrlTxTask
01e,10mar10,wy1 fix WIND00188999, add api mipcnetUnitPktDiscard for buffer
free
01d,25sep09,spw Add tx, rx buffer configuration to mipcnetUnitConfig
01c,20sep09,spw Add mipcnetBusRxCallback
01b,02jul09,spw linux compatibility
01a,13nov08,mak written
*/
#ifndef __INCmipcnetIpch
#define __INCmipcnetIpch
#include <multios_ipc/mipc.h>
#include <multios_ipc/multios_adapt.h>
#ifdef __cplusplus
extern "C" {
#endif
#define MND_IF_NAME "mnd"
#define MND_IF_NAME_MAX_LEN 64
#define MIPCNET_BUS_MAX 4 /* mipcnet busses per OS, max value is 1024 */
#define MIPCNET_NODE_MAX 1024 /* mipcnet nodes per bus, max value is 1024 */
#define MIPCNET_UNIT_MAX 256 /* mipcnet i/f units supported, max value 256 */
#define MIPCNET_INT_RX 1
#define MIPCNET_INT_TX_AVAIL 2
/* typedefs */
typedef void (*INTFUNCPTR) (void *, unsigned char);
struct mipcnetUnitConfig {
void *pBus; /* the bus handle from mipcnetBusCreate() */
int unit; /* the mipcnet unit number on this node */
int segment; /* the mipcnet eth segment number */
int dataPort; /* the data port used for this segment */
int mtu; /* the size of the MND frame payload */
int txBufs; /* transmit buffers on the data socket */
int rxBufs; /* receive buffers on the data socket */
char busName[MIPC_BUS_NAME_MAX_LEN];/* the MIPC bus on which the MND unit resides */
};
void *mipcnetBusCreate
(
char *busName,
int txBufs,
int rxBufs,
int ctrlPort
);
void * mipcnetUnitCreate
(
struct mipcnetUnitConfig * config
);
void mipcnetUnitDelete
(
void * pUnit
);
void mipcnetUnitStart
(
void * pUnit
);
void mipcnetUnitIntEnable
(
void * pUnit
);
void mipcnetUnitIntDisable
(
void * pUnit
);
void mipcnetUnitPhysAddrGet
(
void * pUnit,
unsigned char * enetAddr
);
int mipcnetUnitPhysAddrIsValid
(
void * pUnit,
unsigned char * enetAddr
);
MIPC_ZBUFFER mipcnetUnitPktAlloc
(
void * pUnit,
char ** ppBuffer
);
int mipcnetUnitPktSend
(
void * pUnit,
void * pPkt,
unsigned char * pBuffer,
size_t bufSize
);
void mipcnetUnitIntConnect
(
void * pUnit,
INTFUNCPTR intRtn,
void * intArg
);
void mipcnetUnitIntDisconnect
(
void * pUnit
);
int mipcnetUnitMtuGet
(
void * pUnit,
int * pMtu
);
int mipcnetUnitTxBufAvail
(
void * pUnit
);
int mipcnetUnitPktZReceive
(
void * pUnit,
void ** buffer,
MIPC_ZBUFFER * zbuf
);
int mipcnetUnitPktZFree
(
void * pUnit,
MIPC_ZBUFFER zbuf
);
void mipcnetUnitSendNodeJoinMsgAll
(
void *pUnit
);
void mipcnetUnitSendSegDetachMsgAll
(
void *pUnit
);
void mipcnetUnitPollEnable
(
void *pUnit
);
void mipcnetUnitPollDisable
(
void *pUnit
);
int mipcnetUnitParser
(
char * start,
char * end,
struct mipcnetUnitConfig* cfg
);
#ifdef __cplusplus
}
#endif
#endif /* __INCmipcnetIpch */
@@ -0,0 +1,70 @@
/* mnd_adapt.h - MIPC network device OS adaptation layer API */
/********************************************************************
The following file is dual licensed and is available under either
the GPL version 2 or a Wind River commercial license.
*********************************************************************
Copyright (c) 2009-2011 Wind River Systems, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2 as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*********************************************************************
Copyright (c) 2009-2011 Wind River Systems, Inc.
The right to copy, distribute, modify, or otherwise make use
of this software may be licensed pursuant to the terms
of an applicable Wind River license agreement.
*********************************************************************/
/*
modification history
--------------------
01d,07jan11,jlk Update license header
01c,26aug10,jlk Make sure #ifdef __cplusplus starts after #includes
01b,24jun10,h_w Upgrade to MND 2.1
01a,03jul09,spw Written.
*/
#ifndef __INC_mnd_adapt_h
#define __INC_mnd_adapt_h
#ifdef _WRS_KERNEL
#include <vxWorks.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif
#ifdef _WRS_KERNEL
typedef TASK_ID MULTIOS_PROC_ID;
#else
typedef int MULTIOS_PROC_ID;
#endif
/* OS adaptation routines that MND calls */
int mnd_proc_create(const char *name, int (*entry)(void *data), void *arg,
MULTIOS_PROC_ID *ppid);
int mnd_proc_delete(MULTIOS_PROC_ID pid);
#ifdef __cplusplus
}
#endif
#endif /* __INC_mnd_adapt_h */
+241
View File
@@ -0,0 +1,241 @@
/* msd.h - MIPC Serial Device Header File */
/********************************************************************
The following file is dual licensed and is available under either
the GPL version 2 or a Wind River commercial license.
*********************************************************************
Copyright (c) 2008-2009,2011 Wind River Systems, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2 as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*********************************************************************
Copyright (c) 2008-2009,2011 Wind River Systems, Inc.
The right to copy, distribute, modify, or otherwise make use
of this software may be licensed pursuant to the terms
of an applicable Wind River license agreement.
*********************************************************************/
/*
modification history
--------------------
01l,07jan11,jlk Update license header
01k,18nov09,als Revise MSD single threading to work with Linux (WIND00190478)
01j,05nov09,ebh Add socket locks to single thread access to MIPC
01i,23jun09,jlk Code inspection changes
01h,02mar09,jlk Linux work
01g,23apr09,ebh Add in MIPC_AF family type
01f,25aug08,jlk Updated as per code review.
01e,08aug08,jlk Updated as per HLD review.
01d,07jul08,jlk TTY adaptation
01c,26jun08,jlk Conversion from mpipe to mio
01b,07may08,jlk Bug fixes.
01a,11apr08,jlk Written.
*/
#ifndef __INCmsdh
#define __INCmsdh
/* This header file is shared with VxWorks */
#ifdef _WRS_KERNEL
#define __KERNEL__
#endif
#ifdef __KERNEL__
/* Includes */
/*
* These are needed for kernel (VxWorks or Linux) apps and the MSD kernel code
* itself
*/
#include <multios_ipc/mipc.h>
#include <multios_ipc/multios_adapt.h>
#endif /* __KERNEL__ */
#ifdef __cplusplus
extern "C" {
#endif
/* Shared between kernel and user */
#ifdef MIPC_BUS_NAME_MAX_LEN
#define MSD_BUS_NAME_LEN MIPC_BUS_NAME_MAX_LEN
#else
#define MSD_BUS_NAME_LEN 20
#endif
/* typedefs */
struct msd_endpoint_set {
unsigned short node;
unsigned char instance;
char bus_name[MSD_BUS_NAME_LEN];
};
struct msd_endpoint_get {
unsigned short node;
unsigned char instance;
unsigned char up;
char bus_name[MSD_BUS_NAME_LEN];
};
/* ioctls */
#if (defined (_WRS_KERNEL) || defined (_VX_CPU))
/*
* The VxWorks way.
* _WRS_KERNEL for VxWorks kernel apps. _VX_CPU for VxWorks RTP apps
*/
#define MSD_SET_ENDPOINT ((int)0x80000001)
#define MSD_GET_ENDPOINT ((int)0x80000002)
#else
/* The Linux way */
#include <linux/ioctl.h>
#define MSD_SET_ENDPOINT _IOW('$', 1, struct msd_endpoint_set)
#define MSD_GET_ENDPOINT _IOR('$', 1, struct msd_endpoint_get)
#endif
#ifdef __KERNEL__
#ifndef MSD_DEBUG_LEVEL
#define MSD_DEBUG_LEVEL 0
#endif
/* Debug macros */
#define MSD_DBG1(x)
#define MSD_DBG2(x)
#define MSD_DBG3(x)
#define MSD_DBG4(x)
#define MSD_DBG5(x)
#define MSD_DBG6(x)
#define MSD_DBG7(x)
#define MSD_DBG8(x)
#if MSD_DEBUG_LEVEL > 0
#undef MSD_DBG1
#define MSD_DBG1(x) x
#endif
#if MSD_DEBUG_LEVEL > 1
#undef MSD_DBG2
#define MSD_DBG2(x) x
#endif
#if MSD_DEBUG_LEVEL > 2
#undef MSD_DBG3
#define MSD_DBG3(x) x
#endif
#if MSD_DEBUG_LEVEL > 3
#undef MSD_DBG4
#define MSD_DBG4(x) x
#endif
#if MSD_DEBUG_LEVEL > 4
#undef MSD_DBG5
#define MSD_DBG5(x) x
#endif
#if MSD_DEBUG_LEVEL > 5
#undef MSD_DBG6
#define MSD_DBG6(x) x
#endif
#if MSD_DEBUG_LEVEL > 6
#undef MSD_DBG7
#define MSD_DBG7(x) x
#endif
#if MSD_DEBUG_LEVEL > 7
#undef MSD_DBG8
#define MSD_DBG8(x) x
#endif
#else
/* Non-kernel code */
#ifdef MSD_DEBUG_LEVEL
#undef MSD_DEBUG_LEVEL
#endif
#endif /* __KERNEL__ */
/* defines */
/* Defines the MSD product version */
#define MSD_MAJOR_VERSION MIPC_VERSION_MAJOR
#define MSD_MINOR_VERSION MIPC_MINOR_VERSION
/* Defines the MSD protocol version */
#define MSD_PROTO_MAJOR_VER 0x01
#define MSD_PROTO_MINOR_VER 0x00
#define MSD_BASE_NAME "msd"
#define MSD_PORT_NUM 1
/* This can't be more than 254 */
#define MSD_MAX_DEVS 128
#define MSD_DOMAIN MIPC_AF
#define MSD_PROTOCOL 0
#ifdef __KERNEL__
/* Command op codes */
#define MSD_OP_NOP 0
#define MSD_OP_SEND 1
/* private macros */
#define MSD_FREE_DEV(m) ((m)->in_use = 0)
#define MSD_HDR_DATA_SZ 4
struct msd_hdr {
uint8_t op; /* op code */
uint8_t dev_id; /* identifier */
uint8_t ver_maj; /* major version number */
uint8_t ver_min; /* minor version number */
char data[MSD_HDR_DATA_SZ]; /* payload. */
};
struct msd_addr {
struct mipc_sockaddr mipc_addr;
uint8_t instance;
};
struct msd_device {
int mipc_socket;
struct msd_addr local_addr;
struct msd_addr remote_addr;
int in_use;
int up;
int bound;
int tx_start;
int mtu;
int tx_bufs;
void *os_data;
char bus_name[MSD_BUS_NAME_LEN];
};
struct msd_socket_lock {
int in_use; /* this lock entry is active (or not) */
MULTIOS_SEM sem; /* the lock */
};
typedef void (*msd_handle_rx_data_func)(struct msd_device *, struct msd_hdr *, int);
typedef void (*msd_tx_start_func)(struct msd_device *);
void msd_close_socket (struct msd_device *);
int msd_connect_endpoint (struct msd_device *, struct msd_endpoint_set *);
struct msd_device * msd_find_free_dev (uint8_t *);
void msd_send (struct msd_device *, struct msd_hdr *, MIPC_ZBUFFER, int,
uint8_t);
struct msd_device * msd_init (msd_handle_rx_data_func, msd_tx_start_func);
#endif /* __KERNEL__ */
#ifdef __cplusplus
}
#endif
#endif /* __INCmsdh */
+45
View File
@@ -0,0 +1,45 @@
/* msdLib.h - VxWorks centric MSD header file */
/*
* Copyright (c) 2008 Wind River Systems, Inc.
*
* The right to copy, distribute, modify or otherwise make use
* of this software may be licensed only pursuant to the terms
* of an applicable Wind River license agreement.
*/
/*
modification history
--------------------
01c,18oct08,jlk WIND00136113 - Configure multiple MSDs
01b,08aug08,jlk Updated as per HLD review.
01a,17jul08,jlk written.
*/
/*
DESCRIPTION
Definitions for the VxWorks version of the MSD component.
*/
#ifndef _MSD_LIB_H_
#define _MSD_LIB_H_
#include <sioLib.h>
#include <multios_ipc/msd.h>
#ifdef __cplusplus
extern "C" {
#endif
extern STATUS usrMsdInit(int, int, int, int, int, int, char *);
extern SIO_CHAN * msdCreate(void);
extern STATUS msdDestroy(SIO_CHAN *);
extern STATUS msdLibInit(int, int, int, int);
#ifdef __cplusplus
}
#endif
#endif /* _MSD_LIB_H_ */
@@ -0,0 +1,308 @@
/* multios_adapt.h - MULTIOS adaptation header file for VxWorks */
/*
* Copyright (c) 2008-2011 Wind River Systems, Inc.
*
* The right to copy, distribute, modify or otherwise make use
* of this software may be licensed only pursuant to the terms
* of an applicable Wind River license agreement.
*/
/*
modification history
--------------------
02g,29dec11,swg Add the macro MULTIOS_CURR_TIME(). (WIND00261229)
02f,05dec11,zhw Modify the bcopy calling to match its prototype (WIND00304594)
02e,18feb11,ebh Update with changes from VBE project
02d,05jan11,wyl Ensure timer delay is a minimum of 1 tick (WIND00246398)
02c,04jan11,ste Add MIPC_SM_ADAPT_CHECK_TIMER
02b,26aug10,jlk Make sure #ifdef __cplusplus starts after #includes
02a,02jul10,h_w Add MULTIOS_SEM_TERM definition
01z,22apr10,als Terminate semaphores when socket is closed (WIND00201777)
01y,02mar10,als Add support for 64-bit memory addressing
01x,30sep09,als Specify return type for timer start API
01w,15sep09,bwa add and use multios task delay
01v,07aug09,ebh Code inspection updates
01u,05aug09,als Introduce MULTIOS_ADDR type
01t,30jun09,als Hide unused spinlock APIs
01s,23jun09,als Fix issues with handling of timers
01r,19jun09,ebh Change MULTIOS_COPY_FROM/TO_USR to return success or fail
01q,03jun09,als Rework system configuration/initialization as per HLD and CI
01p,26may09,ebh Code Inspection Modifications
01o,12may09,ebh Allow WAIT_FOREVER to work with SEM_DOWN_WITH_TIMEOUT
01n,05may09,h_W Remove including vxAtomicLib.h
01m,28apr09,ebh Remove unused macros
01l,22apr09,ebh Add prototype for semaphores
01k,21apr09,ebh Add in MULTIOS_TIMER_ARG type
01j,19mar09,ebh Use VxWorks AMP Atomic operators instead of arch specific
ones
01i,13mar09,ebh Update MULTIOS_SEM_DOWN_WITH_TIMEOUT and add general comments
01h,15dec08,apa MIPC 2.0 changes
01g,26sep08,ebh changes as per code review
01f,02sep08,apa Rename the byte order conversion macros.
01e,20jun08,jlk Added MULTIOS_SEM_CINIT macro.
01e,05may08,apa Adding counting semaphores.
01d,02may08,jlk added copy to/from usr macros
01c,30mar08,bwa added description.
01b,24mar08,bwa added SEMAPHORE, fixed MUTEX_UP()
01a,22feb08,bwa written, forked from dshm/adapt/types.h:01k.
*/
/*
DESCRIPTION
VxWorks adaptation main header file. Contains VxWorks definitions of multiple
types of OS-specific objects, such as semaphores, mutexes and spinlocks and
APIs such as 'round up' and ntoh.
The definitions in this file are to allow users to operate on, and port to,
different OSs. Some items are for inter-OS compatibility while others are
strictly for portability of code.
*/
#ifndef __INC_multios_adapt_h
#define __INC_multios_adapt_h
#include <vxWorks.h>
#include <assert.h>
#include <errnoLib.h>
#include <ffsLib.h>
#include <intLib.h>
#include <logLib.h>
#include <semLib.h>
#include <spinLockLib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sysLib.h>
#include <taskLib.h>
#include <tickLib.h>
#include <wdLib.h>
#ifdef __cplusplus
extern "C" {
#endif
/* miscellaneous adaptation */
#define MULTIOS_INLINE __inline__
#define MULTIOS_ROUND_UP(ptr, align) ROUND_UP(ptr, align)
#define MULTIOS_STRUCT_MEMBER_OFFSET(s,m) OFFSET(s, m)
/* assertion */
#define MULTIOS_ASSERT assert
/* console output */
#define MULTIOS_PRINT printf
#define MULTIOS_IPRINT logMsg /* interrupt-safe printout */
/* memory manipulation */
#define MULTIOS_CACHE_ALIGN _CACHE_ALIGN_SIZE
#define MULTIOS_MEM_BARRIER() VX_MEM_BARRIER_RW()
#define MULTIOS_KALLOC(size) malloc(size)
#define MULTIOS_KFREE(ptr) free(ptr)
#define MULTIOS_MSB(value) (ffsMsb((UINT32)value) - 1)
#define MULTIOS_LSB(value) (ffsLsb((UINT32)value) - 1)
/* Copy to user space - return number of uncopied bytes, 0 on success */
static MULTIOS_INLINE int MULTIOS_COPY_TO_USR(void *dst, const void *src,
unsigned long sz)
{
bcopy ((const char *)src, (char *)dst, (size_t)sz);
return 0;
}
/* Copy from user space - return number of uncopied bytes, 0 on success */
static MULTIOS_INLINE int MULTIOS_COPY_FROM_USR(void *dst, const void *src,
unsigned long sz)
{
bcopy ((const char *)src, (char *)dst, (size_t)sz);
return 0;
}
/* multi-OS atomic operators */
typedef uint32_t MULTIOS_ATOMIC_VAL;
typedef atomic32_t MULTIOS_ATOMIC;
/*
* The following routines are simple wrappers that utilize the standard VxWorks
* kernel 32-bit atomic operators. They are only needed because the multi-os
* operators deal with unsigned values, rather than signed values.
*/
static MULTIOS_INLINE MULTIOS_ATOMIC_VAL MULTIOS_ATOMIC_GET(MULTIOS_ATOMIC *a)
{
return (MULTIOS_ATOMIC_VAL)atomic32Get(a);
}
static MULTIOS_INLINE MULTIOS_ATOMIC_VAL MULTIOS_ATOMIC_SET(MULTIOS_ATOMIC *a,
MULTIOS_ATOMIC_VAL v)
{
return (MULTIOS_ATOMIC_VAL)atomic32Set(a, (atomic32Val_t)v);
}
static MULTIOS_INLINE MULTIOS_ATOMIC_VAL MULTIOS_ATOMIC_ADD(MULTIOS_ATOMIC *a,
MULTIOS_ATOMIC_VAL v)
{
return (MULTIOS_ATOMIC_VAL)atomic32Add(a, (atomic32Val_t)v);
}
static MULTIOS_INLINE MULTIOS_ATOMIC_VAL MULTIOS_ATOMIC_SUB(MULTIOS_ATOMIC *a,
MULTIOS_ATOMIC_VAL v)
{
return (MULTIOS_ATOMIC_VAL)atomic32Sub(a, (atomic32Val_t)v);
}
static MULTIOS_INLINE MULTIOS_ATOMIC_VAL MULTIOS_ATOMIC_INC(MULTIOS_ATOMIC *a)
{
return (MULTIOS_ATOMIC_VAL)atomic32Inc(a);
}
static MULTIOS_INLINE MULTIOS_ATOMIC_VAL MULTIOS_ATOMIC_DEC(MULTIOS_ATOMIC *a)
{
return (MULTIOS_ATOMIC_VAL)atomic32Dec(a);
}
static MULTIOS_INLINE MULTIOS_ATOMIC_VAL MULTIOS_ATOMIC_AND(MULTIOS_ATOMIC *a,
MULTIOS_ATOMIC_VAL v)
{
return (MULTIOS_ATOMIC_VAL)atomic32And(a, (atomic32Val_t)v);
}
static MULTIOS_INLINE MULTIOS_ATOMIC_VAL MULTIOS_ATOMIC_OR(MULTIOS_ATOMIC *a,
MULTIOS_ATOMIC_VAL v)
{
return (MULTIOS_ATOMIC_VAL)atomic32Or(a, (atomic32Val_t)v);
}
static MULTIOS_INLINE int MULTIOS_ATOMIC_CAS(MULTIOS_ATOMIC *a,
MULTIOS_ATOMIC_VAL o,
MULTIOS_ATOMIC_VAL n)
{
return (int)atomic32Cas(a, (atomic32Val_t)o, (atomic32Val_t)n);
}
/* timers */
#define MULTIOS_WAIT_FOREVER WAIT_FOREVER
#define MULTIOS_TIMER_ID WDOG_ID
#define MULTIOS_TIMER_INVALID NULL
#define MULTIOS_TIMER_ARG _Vx_usr_arg_t
typedef void (*MULTIOS_TIMER_FUNC) (MULTIOS_TIMER_ARG);
static MULTIOS_INLINE MULTIOS_TIMER_ID MULTIOS_TIMER_CREATE(void)
{
return wdCreate();
}
static MULTIOS_INLINE void MULTIOS_TIMER_START(MULTIOS_TIMER_ID timer, int ms,
MULTIOS_TIMER_FUNC func,
MULTIOS_TIMER_ARG arg)
{
int tick = ((ms) * sysClkRateGet() + 999) / 1000;
(void)wdStart(timer, tick, (WD_RTN)func, arg);
}
#define MIPC_SM_ADAPT_CHECK_TIMER(timer) do {} while(0)
/* spinlocks (currently unused) */
#if 0
#define MULTIOS_SPIN_LOCK_T spinlockIsr_t
#define MULTIOS_SPIN_LOCK_INIT(lock) SPIN_LOCK_ISR_INIT((lock), 0)
#define MULTIOS_SPIN_LOCK(lock) SPIN_LOCK_ISR_TAKE(lock)
#define MULTIOS_SPIN_UNLOCK(lock) SPIN_LOCK_ISR_GIVE(lock)
#endif
/* task delay */
/*
* MULTIOS_TASK_DELAY() - delay a task by X ms
*/
static MULTIOS_INLINE void MULTIOS_TASK_DELAY(int delay_in_ms)
{
taskDelay((((delay_in_ms * sysClkRateGet()) + 999) / 1000) + 1);
}
/* semaphores */
#define MULTIOS_SEM SEMAPHORE
#define MULTIOS_SEM_ID SEM_ID
#define MULTIOS_SEM_INIT(sem) (void)semBInit(sem, SEM_Q_FIFO, SEM_EMPTY)
#define MULTIOS_SEM_INIT_FULL(sem) (void)semBInit(sem, SEM_Q_FIFO, SEM_FULL)
#define MULTIOS_SEM_TERM(sem) (void)semTerminate(sem)
#define MULTIOS_SEM_CREATE() semBCreate(SEM_Q_FIFO, SEM_EMPTY)
#define MULTIOS_SEM_CREATE_FULL() semBCreate(SEM_Q_FIFO, SEM_FULL)
#define MULTIOS_SEM_DELETE(sem) semDelete(sem)
extern int multios_down_timeout(MULTIOS_SEM_ID sem, int timeout);
/*
* MULTIOS_SEM_DOWN(sem) - get a multi-OS semaphore
* Parameters: semaphore to wait on
* Returns: 0 if successful; -EINVAL if any error occurred
*/
static __inline__ int MULTIOS_SEM_DOWN(MULTIOS_SEM_ID sem)
{
return semTake(sem, MULTIOS_WAIT_FOREVER) ? -EINVAL : 0;
}
/*
* MULTIOS_SEM_DOWN_WITH_TIMEOUT - get a multi-OS semaphore within a time limit
* Parameters: semaphore to wait on; timeout in ms (or MULTIOS_WAIT_FOREVER)
* Returns: time remaining if semaphore is taken
* (is >= 0 if timeout >= 0; is 0 if timeout == MULTIOS_WAIT_FOREVER);
* -ETIMEDOUT if time limit expired without getting semaphore;
* -EINVAL if any other error occurred
*/
static __inline__ int MULTIOS_SEM_DOWN_WITH_TIMEOUT(MULTIOS_SEM_ID sem, int timeout)
{
return multios_down_timeout(sem, timeout);
}
#define MULTIOS_SEM_UP(sem) semGive(sem)
#define MULTIOS_SEM_FLUSH(sem) semFlush(sem)
/* linked lists */
#define MULTIOS_LIST DL_LIST /* list type */
#define MULTIOS_LIST_NODE DL_NODE /* element-in-the-list type */
#define MULTIOS_LIST_INIT(list) dllInit (list)
#define MULTIOS_LIST_ADD(list, elem) dllAdd (list, elem)
#define MULTIOS_LIST_GET(list) dllGet (list)
/* byte-order macros (currently only support same endianness on all nodes) */
#define MULTIOS_ntoh16(x) (x)
#define MULTIOS_ntoh32(x) (x)
#define MULTIOS_ntoh64(x) (x)
#define MULTIOS_hton16(x) (x)
#define MULTIOS_hton32(x) (x)
#define MULTIOS_hton64(x) (x)
/* current time, in millisecond */
#define MULTIOS_CURR_TIME() (unsigned int)(tickGet() * 1000 / sysClkRateGet())
#ifdef __cplusplus
}
#endif
#endif /* __INC_multios_adapt_h */