index 626658be6c264193433dca3d5f7398fa0fa70ac0..8284b07475c0020dee2500f68e8367be65e45e92 100644 (file)
/*
- * Copyright (c) 2012, Texas Instruments Incorporated
+ * Copyright (c) 2012-2015 Texas Instruments Incorporated - http://www.ti.com
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
*/
/* Standard headers */
-#include <Std.h>
+#include <ti/ipc/Std.h>
/* Socket Headers */
#include <sys/types.h>
/* For PRINTVERBOSE* */
#include <_lad.h>
-static Bool verbose = FALSE;
+/* For MultiProc id to remoteproc index map */
+#include <_MultiProc.h>
+
+/* Traces in this file are controlled via _SocketFxns_verbose
+ *
+ * Caution! This file is used by both LAD and TransportRpmsg. The
+ * PRINTVERBOSE macros use printf(), which sends its output to
+ * STDOUT (fd = 0). However, LAD closes STDOUT and by unfortunate
+ * chance, the file descriptor zero (fd = 0) is reused for the outbound
+ * pipe to the first client. This means all trace messages go into
+ * the pipe and corrupt the data on the client side.
+
+ * If you want to enable this trace for LAD, in addition to setting
+ * _SocketFxns_versbose to TRUE below, you must also comment out the
+ * three calls to close() in linux/src/daemon/lad.c:
+ *
+ * close(STDIN_FILENO);
+ * close(STDOUT_FILENO);
+ * close(STDERR_FILENO);
+ *
+ * If you only want to enable trace in the client (i.e. calls from
+ * TransportRpmsg), then simply set the environment variable IPC_DEBUG
+ * (to either 2 or 3) before you run your program.
+ *
+ * IPC_DEBUG=3 ./app_host
+ */
+Bool _SocketFxns_verbose = FALSE;
+#define verbose _SocketFxns_verbose
int ConnectSocket(int sock, UInt16 procId, int dst)
{
int err;
struct sockaddr_rpmsg srcAddr, dstAddr;
socklen_t len;
+ UInt16 clusterId;
+
+ /* map procId to clusterId (rprocList[] indexed by clusterId) */
+ clusterId = procId - _MultiProc_cfg.baseIdOfCluster;
/* connect to remote service */
memset(&dstAddr, 0, sizeof(dstAddr));
dstAddr.family = AF_RPMSG;
- /* rpmsg "vproc_id" is one less than the MultiProc ID: */
- dstAddr.vproc_id = procId - 1;
+ /* convert MultiProc 'clusterId' to remoteproc index */
+ dstAddr.vproc_id = _MultiProc_cfg.rprocList[clusterId];
dstAddr.addr = dst;
len = sizeof(struct sockaddr_rpmsg);
err = connect(sock, (struct sockaddr *)&dstAddr, len);
if (err < 0) {
- printf("connect failed: %s (%d)\n", strerror(errno), errno);
- return (-1);
+ /* don't hard-printf since this is no longer fatal */
+ PRINTVERBOSE2("connect failed: %s (%d)\n", strerror(errno), errno);
+ return (-1);
}
/* let's see what local address we got */
err = getsockname(sock, (struct sockaddr *)&srcAddr, &len);
if (err < 0) {
- printf("getpeername failed: %s (%d)\n", strerror(errno), errno);
- return (-1);
+ fprintf(stderr, "getpeername failed: %s (%d)\n",
+ strerror(errno), errno);
+ return (-1);
}
PRINTVERBOSE3("Connected over sock: %d\n\tdst vproc_id: %d, dst addr: %d\n",
return(0);
}
-int SocketBindAddr(int fd, UInt16 rprocId, UInt32 localAddr)
+int SocketBindAddr(int fd, UInt16 procId, UInt32 localAddr)
{
int err;
socklen_t len;
struct sockaddr_rpmsg srcAddr;
+ UInt16 clusterId;
+
+ /* map procId to clusterId (rprocList[] indexed by clusterId) */
+ clusterId = procId - _MultiProc_cfg.baseIdOfCluster;
/* Now bind to the source address. */
memset(&srcAddr, 0, sizeof(srcAddr));
srcAddr.family = AF_RPMSG;
- /* We bind the remote proc ID, but local address! */
- srcAddr.vproc_id = (rprocId - 1);
+ /* We bind the remote clusterId, but local address! */
+ srcAddr.vproc_id = _MultiProc_cfg.rprocList[clusterId];
srcAddr.addr = localAddr;
len = sizeof(struct sockaddr_rpmsg);
/* let's see what local address we got */
err = getsockname(fd, (struct sockaddr *)&srcAddr, &len);
if (err < 0) {
- printf("getsockname failed: %s (%d)\n", strerror(errno), errno);
+ fprintf(stderr, "getsockname failed: %s (%d)\n",
+ strerror(errno), errno);
}
else {
PRINTVERBOSE2("\tsrc vproc_id: %d, src addr: %d\n",