index 27c2910b7b07458362c22e33205f9ec798e34467..9a4031910add2e8f1510c4791bab42af566a91ac 100644 (file)
/*
- * Copyright (c) 2011-2013, Texas Instruments Incorporated
+ * Copyright (c) 2011-2014, Texas Instruments Incorporated
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
#include <xdc/runtime/knl/Thread.h>
#include <xdc/runtime/System.h>
-#define MSGBUFFERSIZE 512 // Make global and move to MessageQCopy.h
+#include <ti/sysbios/knl/Task.h>
+
+#define MSGBUFFERSIZE 512 /* Make global and move to RPMessage.h */
#if defined(RCM_ti_ipc)
#include <ti/sdo/utils/List.h>
#include "RcmTypes.h"
#include "RcmServer.h"
-#if USE_MESSAGEQCOPY
+#if USE_RPMESSAGE
#include <ti/srvmgr/rpmsg_omx.h>
#endif
-#define _RCM_KeyResetValue 0x07FF // key reset value
-#define _RCM_KeyMask 0x7FF00000 // key mask in function index
-#define _RCM_KeyShift 20 // key bit position in function index
+#define _RCM_KeyResetValue 0x07FF /* key reset value*/
+#define _RCM_KeyMask 0x7FF00000 /* key mask in function index*/
+#define _RCM_KeyShift 20 /* key bit position in function index*/
-#define RcmServer_MAX_TABLES 9 // max number of function tables
-#define RcmServer_POOL_MAP_LEN 4 // pool map length
+#define RcmServer_MAX_TABLES 9 /* max number of function tables*/
+#define RcmServer_POOL_MAP_LEN 4 /* pool map length*/
#define RcmServer_E_InvalidFxnIdx (-101)
#define RcmServer_E_JobIdNotFound (-102)
#define RcmServer_E_PoolIdNotFound (-103)
-typedef struct { // function table element
+typedef struct { /* function table element*/
String name;
-#if USE_MESSAGEQCOPY
+#if USE_RPMESSAGE
union {
RcmServer_MsgFxn fxn;
RcmServer_MsgCreateFxn createFxn;
} RcmServer_FxnTabElemAry;
typedef struct {
- String name; // pool name
- Int count; // thread count (at create time)
- Thread_Priority priority; // thread priority
+ String name; /* pool name*/
+ Int count; /* thread count (at create time)*/
+ Thread_Priority priority; /* thread priority*/
Int osPriority;
- SizeT stackSize; // thread stack size
- String stackSeg; // thread stack placement
- ISemaphore_Handle sem; // message semaphore (counting)
- List_Struct threadList; // list of worker threads
- List_Struct readyQueue; // queue of messages
+ SizeT stackSize; /* thread stack size*/
+ String stackSeg; /* thread stack placement*/
+ ISemaphore_Handle sem; /* message semaphore (counting)*/
+ List_Struct threadList; /* list of worker threads*/
+ List_Struct readyQueue; /* queue of messages*/
} RcmServer_ThreadPool;
typedef struct RcmServer_Object_tag {
- GateThread_Struct gate; // instance gate
- Ptr run; // run semaphore for the server
-#if USE_MESSAGEQCOPY
- MessageQCopy_Handle serverQue; // inbound message queue
- UInt32 localAddr; // inbound message queue address
- UInt32 replyAddr; // Reply address (same per inst.)
- UInt32 dstProc; // Reply processor.
+ GateThread_Struct gate; /* instance gate*/
+ Ptr run; /* run semaphore for the server*/
+#if USE_RPMESSAGE
+ RPMessage_Handle serverQue; /* inbound message queue */
+ UInt32 localAddr; /* inbound message queue address */
+ UInt32 replyAddr; /* Reply address (same per inst.) */
+ UInt32 dstProc; /* Reply processor. */
#else
- MessageQ_Handle serverQue; // inbound message queue
+ MessageQ_Handle serverQue; /* inbound message queue*/
#endif
- Thread_Handle serverThread; // server thread object
- RcmServer_FxnTabElemAry fxnTabStatic; // static function table
- RcmServer_FxnTabElem * fxnTab[RcmServer_MAX_TABLES]; // base pointers
- UInt16 key; // function index key
- UInt16 jobId; // job id tracker
- Bool shutdown; // server shutdown flag
- Int poolMap0Len;// length of static table
+ Thread_Handle serverThread; /* server thread object*/
+ RcmServer_FxnTabElemAry fxnTabStatic; /* static function table*/
+ RcmServer_FxnTabElem * fxnTab[RcmServer_MAX_TABLES]; /* base pointers*/
+ UInt16 key; /* function index key*/
+ UInt16 jobId; /* job id tracker*/
+ Bool shutdown; /* server shutdown flag*/
+ Int poolMap0Len;/* length of static table*/
RcmServer_ThreadPool * poolMap[RcmServer_POOL_MAP_LEN];
- List_Handle jobList; // list of job stream queues
+ List_Handle jobList; /* list of job stream queues*/
} RcmServer_Object;
typedef struct {
List_Elem elem;
- UInt16 jobId; // current job stream id
- Thread_Handle thread; // server thread object
- Bool terminate; // thread terminate flag
- RcmServer_ThreadPool* pool; // worker pool
- RcmServer_Object * server; // server instance
+ UInt16 jobId; /* current job stream id*/
+ Thread_Handle thread; /* server thread object*/
+ Bool terminate; /* thread terminate flag*/
+ RcmServer_ThreadPool* pool; /* worker pool*/
+ RcmServer_Object * server; /* server instance*/
} RcmServer_WorkerThread;
typedef struct {
List_Elem elem;
- UInt16 jobId; // job stream id
- Bool empty; // true if no messages on server
- List_Struct msgQue; // queue of messages
+ UInt16 jobId; /* job stream id*/
+ Bool empty; /* true if no messages on server*/
+ List_Struct msgQue; /* queue of messages*/
} RcmServer_JobStream;
typedef struct RcmServer_Module_tag {
}
/* register with xdc.runtime to get a diags mask */
-// result = Registry_addModule(&Registry_CURDESC, MODULE_NAME);
+/* result = Registry_addModule(&Registry_CURDESC, MODULE_NAME);*/
result = Registry_addModule(&Registry_CURDESC, ti_grcm_RcmServer_Name);
Assert_isTrue(result == Registry_SUCCESS, (Assert_Id)NULL);
*/
Void RcmServer_exit(Void)
{
-// Registry_Result result;
+/* Registry_Result result;*/
if (--curInit != 0) {
}
/* unregister from xdc.runtime */
-// result = Registry_removeModule(MODULE_NAME);
-// Assert_isTrue(result == Registry_SUCCESS, (Assert_Id)NULL);
+/* result = Registry_removeModule(MODULE_NAME);*/
+/* Assert_isTrue(result == Registry_SUCCESS, (Assert_Id)NULL);*/
}
/* server thread */
params->priority = Thread_Priority_HIGHEST;
params->osPriority = Thread_INVALID_OS_PRIORITY;
- params->stackSize = 0; // use system default
+ params->stackSize = 0; /* use system default*/
params->stackSeg = "";
/* default pool */
params->defaultPool.count = 0;
params->defaultPool.priority = Thread_Priority_NORMAL;
params->defaultPool.osPriority = Thread_INVALID_OS_PRIORITY;
- params->defaultPool.stackSize = 0; // use system default
+ params->defaultPool.stackSize = 0; /* use system default*/
params->defaultPool.stackSeg = "";
/* worker pools */
/* initialize the error block */
Error_init(&eb);
+
+ if (NULL == handle) {
+ Log_error0(FXNN": Invalid pointer");
+ status = RcmServer_E_FAIL;
+ goto leave;
+ }
+
*handle = (RcmServer_Handle)NULL;
/* check for valid params */
status = RcmServer_E_FAIL;
goto leave;
}
- if (NULL == handle) {
- Log_error0(FXNN": Invalid pointer");
- status = RcmServer_E_FAIL;
- goto leave;
- }
if (NULL == name) {
Log_error0(FXNN": name passed is NULL!");
status = RcmServer_E_FAIL;
{
Error_Block eb;
List_Params listP;
-#if USE_MESSAGEQCOPY == 0
+#if USE_RPMESSAGE == 0
MessageQ_Params mqParams;
#endif
Thread_Params threadP;
}
/* create the message queue for inbound messages */
-#if USE_MESSAGEQCOPY
- obj->serverQue = MessageQCopy_create(MessageQCopy_ASSIGN_ANY, NULL, NULL,
+#if USE_RPMESSAGE
+ obj->serverQue = RPMessage_create(RPMessage_ASSIGN_ANY, NULL, NULL,
&obj->localAddr);
#ifdef BIOS_ONLY_TEST
obj->dstProc = MultiProc_self();
List_Handle listH;
List_Handle msgQueH;
RcmClient_Packet *packet;
-#if USE_MESSAGEQCOPY == 0
+#if USE_RPMESSAGE == 0
MessageQ_Msg msgqMsg;
#endif
SemThread_Handle semThreadH;
obj->shutdown = TRUE;
if (obj->serverThread != NULL) {
-#if USE_MESSAGEQCOPY
- MessageQCopy_unblock(obj->serverQue);
+#if USE_RPMESSAGE
+ RPMessage_unblock(obj->serverQue);
#else
MessageQ_unblock(obj->serverQue);
#endif
(IArg)job->jobId, (IArg)packet);
RcmServer_setStatusCode_I(packet, RcmServer_Status_Unprocessed);
-#if USE_MESSAGEQCOPY
+#if USE_RPMESSAGE
packet->hdr.type = OMX_RAW_MSG;
packet->hdr.len = PACKET_DATA_SIZE + packet->message.dataSize;
- rval = MessageQCopy_send(obj->dstProc, obj->replyAddr,
+ rval = RPMessage_send(obj->dstProc, obj->replyAddr,
obj->localAddr, (Ptr)&packet->hdr,
PACKET_HDR_SIZE + packet->message.dataSize);
#else
(IArg)packet->msgId, (IArg)packet);
RcmServer_setStatusCode_I(packet, RcmServer_Status_Unprocessed);
-#if USE_MESSAGEQCOPY
+#if USE_RPMESSAGE
packet->hdr.type = OMX_RAW_MSG;
packet->hdr.len = PACKET_DATA_SIZE + packet->message.dataSize;
- rval = MessageQCopy_send(obj->dstProc, obj->replyAddr,
+ rval = RPMessage_send(obj->dstProc, obj->replyAddr,
obj->localAddr, (Ptr)&packet->hdr,
PACKET_HDR_SIZE + packet->message.dataSize);
#else
}
if (NULL != obj->serverQue) {
-#if USE_MESSAGEQCOPY
- MessageQCopy_delete(&obj->serverQue);
+#if USE_RPMESSAGE
+ RPMessage_delete(&obj->serverQue);
#else
MessageQ_delete(&obj->serverQue);
#endif
if (obj->fxnTab[i] != NULL) {
for (j = 0; j < (1 << (i + 4)); j++) {
if (((obj->fxnTab[i])+j)->addr.fxn == 0) {
- slot = (obj->fxnTab[i]) + j; // found empty slot
+ slot = (obj->fxnTab[i]) + j; /* found empty slot*/
break;
}
}
slot->addr.fxn = addr;
len = _strlen(funcName) + 1;
slot->name = (String)xdc_runtime_Memory_alloc(
- RcmServer_Module_heap(), len, sizeof(Char *), &eb);
+ RcmServer_Module_heap(), len, 0, &eb);
if (Error_check(&eb)) {
Log_error0(FXNN": unable to allocate function name");
_strcpy(slot->name, funcName);
slot->key = RcmServer_getNextKey_P(obj);
- fxnIdx = (slot->key << _RCM_KeyShift) | (i << 12) | j;
+ fxnIdx = ((UInt32)(slot->key) << _RCM_KeyShift) | (i << 12) | j;
}
/* error, no more room to add new symbol */
Int RcmServer_execMsg_I(RcmServer_Object *obj, RcmClient_Message *msg)
{
RcmServer_MsgFxn fxn;
-#if USE_MESSAGEQCOPY
+#if USE_RPMESSAGE
RcmServer_MsgCreateFxn createFxn = NULL;
#endif
Int status;
System_printf("RcmServer_execMsg_I: Calling fxnIdx: %d\n",
(msg->fxnIdx & 0x0000FFFF));
#endif
-#if USE_MESSAGEQCOPY
+ Task_setEnv(Task_self(), (Ptr)RcmServer_getLocalAddress(obj));
+#if USE_RPMESSAGE
if (createFxn) {
msg->result = (*createFxn)(obj, msg->dataSize, msg->data);
}
#else
msg->result = (*fxn)(msg->dataSize, msg->data);
#endif
+ Task_setEnv(Task_self(), NULL);
}
return(status);
if (i == 0) {
fxnIdx = 0x80000000 | j;
} else {
- fxnIdx = (slot->key << _RCM_KeyShift) | (i << 12) | j;
+ fxnIdx = ((UInt32)(slot->key) << _RCM_KeyShift) |
+ (i << 12) | j;
}
break;
}
UInt32 fxnIdx;
RcmServer_MsgFxn fxn;
RcmClient_Message *rcmMsg;
-#if USE_MESSAGEQCOPY
+#if USE_RPMESSAGE
RcmServer_MsgCreateFxn createFxn = NULL;
#endif
-#if USE_MESSAGEQCOPY == 0
+#if USE_RPMESSAGE == 0
MessageQ_Msg msgqMsg;
#endif
UInt16 messageType;
/* decode the message */
rcmMsg = &packet->message;
-#if USE_MESSAGEQCOPY == 0
+#if USE_RPMESSAGE == 0
msgqMsg = &packet->msgqHeader;
#endif
Log_print1(Diags_INFO, FXNN": message desc=0x%x", (IArg)packet->desc);
RcmServer_setStatusCode_I(packet, RcmServer_Status_SUCCESS);
}
-#if USE_MESSAGEQCOPY
+#if USE_RPMESSAGE
#if 0
System_printf("RcmServer_process_P: Sending reply from: %d to: %d\n",
obj->localAddr, obj->replyAddr);
packet->hdr.type = OMX_RAW_MSG;
packet->hdr.len = PACKET_DATA_SIZE + packet->message.dataSize;
- status = MessageQCopy_send(obj->dstProc, obj->replyAddr,
+ status = RPMessage_send(obj->dstProc, obj->replyAddr,
obj->localAddr, (Ptr)&packet->hdr,
PACKET_HDR_SIZE + packet->message.dataSize);
#else
/* if all went well, free the message */
if ((status >= 0) && (rcmMsg->result >= 0)) {
-#if USE_MESSAGEQCOPY == 0
+#if USE_RPMESSAGE == 0
status = MessageQ_free(msgqMsg);
#endif
if (status < 0) {
}
/* send error message back to client */
-#if USE_MESSAGEQCOPY
+#if USE_RPMESSAGE
packet->hdr.type = OMX_RAW_MSG;
packet->hdr.len = PACKET_DATA_SIZE + packet->message.dataSize;
- status = MessageQCopy_send(obj->dstProc, obj->replyAddr,
+ status = RPMessage_send(obj->dstProc, obj->replyAddr,
obj->localAddr, (Ptr)&packet->hdr,
PACKET_HDR_SIZE + packet->message.dataSize);
#else
Error_init(&eb);
}
-#if USE_MESSAGEQCOPY
+#if USE_RPMESSAGE
packet->hdr.type = OMX_RAW_MSG;
packet->hdr.len = PACKET_DATA_SIZE + packet->message.dataSize;
- status = MessageQCopy_send(obj->dstProc, obj->replyAddr,
+ status = RPMessage_send(obj->dstProc, obj->replyAddr,
obj->localAddr, (Ptr)&packet->hdr,
PACKET_HDR_SIZE + packet->message.dataSize);
#else
}
/* invoke the function with a null context */
-#if USE_MESSAGEQCOPY
+#if USE_RPMESSAGE
if (createFxn) {
(*createFxn)(obj, 0, NULL);
}
rcmMsg->result = 0;
}
-#if USE_MESSAGEQCOPY
+#if USE_RPMESSAGE
packet->hdr.type = OMX_RAW_MSG;
packet->hdr.len = PACKET_DATA_SIZE + packet->message.dataSize;
- status = MessageQCopy_send(obj->dstProc, obj->replyAddr,
+ status = RPMessage_send(obj->dstProc, obj->replyAddr,
obj->localAddr, (Ptr)&packet->hdr,
PACKET_HDR_SIZE + packet->message.dataSize);
#else
rcmMsg->result = 0;
}
-#if USE_MESSAGEQCOPY
+#if USE_RPMESSAGE
packet->hdr.type = OMX_RAW_MSG;
packet->hdr.len = PACKET_DATA_SIZE + packet->message.dataSize;
- status = MessageQCopy_send(obj->dstProc, obj->replyAddr,
+ status = RPMessage_send(obj->dstProc, obj->replyAddr,
obj->localAddr, (Ptr)&packet->hdr,
PACKET_HDR_SIZE + packet->message.dataSize);
#else
rcmMsg->result = 0;
}
-#if USE_MESSAGEQCOPY
+#if USE_RPMESSAGE
packet->hdr.type = OMX_RAW_MSG;
packet->hdr.len = PACKET_DATA_SIZE + packet->message.dataSize;
- status = MessageQCopy_send(obj->dstProc, obj->replyAddr,
+ status = RPMessage_send(obj->dstProc, obj->replyAddr,
obj->localAddr, (Ptr)&packet->hdr,
PACKET_HDR_SIZE + packet->message.dataSize);
#else
List_Handle msgQueH;
RcmClient_Packet *packet;
RcmServer_JobStream *job;
-#if USE_MESSAGEQCOPY == 0
+#if USE_RPMESSAGE == 0
MessageQ_Msg msgqMsg;
#endif
Int rval;
RcmServer_setStatusCode_I(packet, RcmServer_Status_Unprocessed);
-#if USE_MESSAGEQCOPY
+#if USE_RPMESSAGE
packet->hdr.type = OMX_RAW_MSG;
packet->hdr.len = PACKET_DATA_SIZE + packet->message.dataSize;
- rval = MessageQCopy_send(obj->dstProc, obj->replyAddr,
+ rval = RPMessage_send(obj->dstProc, obj->replyAddr,
obj->localAddr, (Ptr)&packet->hdr,
PACKET_HDR_SIZE + packet->message.dataSize);
#else
{
Error_Block eb;
RcmClient_Packet *packet;
-#if USE_MESSAGEQCOPY
+#if USE_RPMESSAGE
Char recvBuf[MSGBUFFERSIZE];
UInt16 len;
#else
RcmServer_Object *obj = (RcmServer_Object *)arg;
Int dataSize;
-#if USE_MESSAGEQCOPY
+#if USE_RPMESSAGE
packet = (RcmClient_Packet *)&recvBuf[0];
#endif
/* block until message arrives */
do {
-#if USE_MESSAGEQCOPY
- rval = MessageQCopy_recv(obj->serverQue, (Ptr)&packet->hdr, &len,
- &obj->replyAddr, MessageQCopy_FOREVER);
+#if USE_RPMESSAGE
+ rval = RPMessage_recv(obj->serverQue, (Ptr)&packet->hdr, &len,
+ &obj->replyAddr, RPMessage_FOREVER);
#if 0
System_printf("RcmServer_serverThrFxn_P: Received msg of len %d "
"from: %d\n",
Assert_isTrue((packet->hdr.type == OMX_RAW_MSG) ||
(packet->hdr.type == OMX_DISC_REQ) , NULL);
- if ((rval < 0) && (rval != MessageQCopy_E_UNBLOCKED)) {
+ if ((rval < 0) && (rval != RPMessage_E_UNBLOCKED)) {
#else
rval = MessageQ_get(obj->serverQue, &msgqMsg, MessageQ_FOREVER);
if ((rval < 0) && (rval != MessageQ_E_UNBLOCKED)) {
Log_error1(FXNN": ipc error 0x%x", (IArg)rval);
/* keep running and hope for the best */
}
-#if USE_MESSAGEQCOPY
+#if USE_RPMESSAGE
} while (FALSE);
#else
} while ((msgqMsg == NULL) && !obj->shutdown);
#endif
/* if shutdown, exit this thread */
-#if USE_MESSAGEQCOPY
+#if USE_RPMESSAGE
if (obj->shutdown || packet->hdr.type == OMX_DISC_REQ) {
running = FALSE;
Log_print1(Diags_INFO,
}
#endif
-#if USE_MESSAGEQCOPY == 0
+#if USE_RPMESSAGE == 0
packet = (RcmClient_Packet *)msgqMsg;
#endif
packet->message.result = rval;
/* return the message to the client */
-#if USE_MESSAGEQCOPY
+#if USE_RPMESSAGE
#if 0
System_printf("RcmServer_serverThrFxn_P: "
"Sending response from: %d to: %d\n",
packet->message.dataSize;
dataSize = PACKET_HDR_SIZE + packet->message.dataSize;
}
- rval = MessageQCopy_send(obj->dstProc, obj->replyAddr,
+ rval = RPMessage_send(obj->dstProc, obj->replyAddr,
obj->localAddr, (Ptr)&packet->hdr, dataSize);
#else
rval = MessageQ_put(MessageQ_getReplyQueue(msgqMsg), msgqMsg);
}
packet->message.result = rval;
-#if USE_MESSAGEQCOPY
+#if USE_RPMESSAGE
packet->hdr.type = OMX_RAW_MSG;
packet->hdr.len = PACKET_DATA_SIZE + packet->message.dataSize;
- rval = MessageQCopy_send(
+ rval = RPMessage_send(
(obj->server)->dstProc,
(obj->server)->replyAddr,
(obj->server)->localAddr, (Ptr)&packet->hdr,