0
|
1 /****************************************************************************/
|
|
2 /* */
|
|
3 /* Name rvf_msg.c */
|
|
4 /* */
|
|
5 /* Function this file contains rvf message handling functions */
|
|
6 /* */
|
|
7 /* Version 0.1 */
|
|
8 /* */
|
|
9 /* Date Modification */
|
|
10 /* ------------------------------------ */
|
|
11 /* 18-March-2002 */
|
|
12 /* */
|
|
13 /* (C) Copyright 2002 by Texas Instruments Incorporated, All Rights Reserved*/
|
|
14 /****************************************************************************/
|
|
15
|
|
16 #include "rvf/rvf_api.h"
|
|
17 #include "rvf/rvf_i.h"
|
|
18 #include "rvm/rvm_use_id_list.h"
|
|
19 #include "rvm/rvm_api.h" // RVM_TMS_MSG & RVM_MSG_OFFSET
|
|
20
|
|
21 // PRIVATE
|
|
22 static const UINT8 BOUNDBUFVAL=20;
|
|
23 T_RVF_RET _send_msg (T_RVF_G_ADDR_ID addr_id, void *msg, UINT8 mbox, UINT8 bindbuf);
|
|
24
|
|
25 /*******************************************************************************
|
|
26 **
|
|
27 ** Function rvf_get_msg_buf
|
|
28 **
|
|
29 ** Description Request for a message buffer.
|
|
30 ** Automatically update the message id of the buffer
|
|
31 **
|
|
32 **
|
|
33 ** Returns T_RVF_MB_STATUS: RVF_GREEN if everything is ok,
|
|
34 ** RVF_YELLOW if watermark limit has been reached,
|
|
35 ** RVF_RED if max size has been reached (does not return a buffer)
|
|
36 **
|
|
37 *******************************************************************************/
|
|
38 T_RVF_MB_STATUS rvf_get_msg_buf(T_RVF_MB_ID mb_id,
|
|
39 UINT32 message_size,
|
|
40 T_RVF_MSG_ID msg_id,
|
|
41 T_RVF_MSG ** pp_msg)
|
|
42 {
|
|
43
|
|
44 T_RVF_MB_STATUS mb_status;
|
|
45
|
|
46
|
|
47 mb_status = rvf_get_buf(mb_id,message_size,(T_RVF_BUFFER**) pp_msg);
|
|
48
|
|
49 if (mb_status != RVF_RED)
|
|
50 {
|
|
51 (*pp_msg)->msg_id = msg_id;
|
|
52 }
|
|
53
|
|
54 return mb_status;
|
|
55 }
|
|
56
|
|
57
|
|
58
|
|
59 /*******************************************************************************
|
|
60 **
|
|
61 ** Function rvf_fre_msg
|
|
62 **
|
|
63 ** Description Deallocate a message buffer
|
|
64 **
|
|
65 **
|
|
66 ** Returns T_RVF_RET: T_RVF_OK if succesful,...
|
|
67 **
|
|
68 *******************************************************************************/
|
|
69 T_RVF_RET rvf_free_msg(T_RVF_MSG *p_msg)
|
|
70 {
|
|
71 return rvf_free_buf( (T_RVF_BUFFER *) p_msg);
|
|
72 }
|
|
73
|
|
74 T_RVF_RET rvf_free_timer_msg(T_RVF_MSG *p_msg)
|
|
75 {
|
|
76 return rvf_free_buf( (T_RVF_BUFFER *) p_msg);
|
|
77 }
|
|
78
|
|
79
|
|
80 /*******************************************************************************
|
|
81 **
|
|
82 ** Function rvf_send_msg
|
|
83 **
|
|
84 ** Description Called by applications to send a buffer to a SWE.
|
|
85 **
|
|
86 ** Returns RVF_OK if successful, else an error code.
|
|
87 **
|
|
88 ** Comments Priority is defined the inverse of NU. for legacy reasons
|
|
89 *******************************************************************************/
|
|
90 T_RVF_RET rvf_send_msg (T_RVF_G_ADDR_ID addr_id, void *msg) {
|
|
91 return _send_msg ( addr_id, msg, 0, FALSE);
|
|
92 }
|
|
93
|
|
94 T_RVF_RET rvf_send_priority_msg (T_RVF_G_ADDR_ID addr_id, void *msg) {
|
|
95 return _send_msg ( addr_id, msg, 1, TRUE);
|
|
96 }
|
|
97
|
|
98 T_RVF_RET _send_msg (T_RVF_G_ADDR_ID addr_id, void *msg, UINT8 mbox, UINT8 bindbuf) {
|
|
99 T_RVF_INTERNAL_BUF *p_hdr;
|
|
100 T_RVF_INTERNAL_BUF* cur=NULL;
|
|
101 UINT8 i=0;
|
|
102 T_RVF_G_ADDR_ID tid=RVF_INVALID_ADDR_ID;
|
|
103
|
|
104 /* If task non-existant or not started, drop buffer */
|
|
105 if ((addr_id >= MAX_RVF_G_ADDR_ID)) {
|
|
106 rvf_send_trace( "RVF: rvf_send_msg(): invalid taskid", 35, NULL_PARAM, RV_TRACE_LEVEL_ERROR, RVM_USE_ID );
|
|
107 rvf_free_buf (msg);
|
|
108 return RVF_INVALID_PARAMETER;
|
|
109 }
|
|
110 if((tid=resolveHostAddrId(addr_id))==RVF_INVALID_ADDR_ID) {
|
|
111 rvf_free_buf (msg);
|
|
112 return RVF_INTERNAL_ERR;
|
|
113 }
|
|
114 if(!pRtAddrIdTable[tid]) {
|
|
115 rvf_free_buf (msg);
|
|
116 return RVF_INTERNAL_ERR;
|
|
117 }
|
|
118
|
|
119 // Reject all msg or only continuous tm msg if bound buf limit
|
|
120 if(bindbuf) {
|
|
121 for(i=0, cur=pRtAddrIdTable[tid]->OSTaskQFirst[mbox];
|
|
122 cur && cur->p_next; cur=cur->p_next, i++) ;
|
|
123 if(((T_RV_HDR*)msg)->msg_id==RVM_TMS_MSG) {
|
|
124 if(i>=BOUNDBUFVAL && ((T_RVF_TMS_MSG*)msg)->cont) {
|
|
125 rvf_free_buf(msg);
|
|
126 return RVF_MEMORY_ERR;
|
|
127 }
|
|
128 } else {
|
|
129 if(i>=BOUNDBUFVAL) {
|
|
130 rvf_free_buf(msg);
|
|
131 return RVF_MEMORY_ERR;
|
|
132 }
|
|
133 }
|
|
134 }
|
|
135
|
|
136 #if RVF_ENABLE_BUF_CORRUPTION_CHECK
|
|
137 /* check for buffer corruption */
|
|
138 if (_rvf_chk_buf_damage(msg) == TRUE)
|
|
139 { rvf_send_trace( "RVF: rvf_send_msg(): buffer corrupted", 37, NULL_PARAM, RV_TRACE_LEVEL_ERROR, RVM_USE_ID );
|
|
140 }
|
|
141 #endif
|
|
142
|
|
143 /* update the addr_id field of the message */
|
|
144 ((T_RV_HDR *)msg)->dest_addr_id = addr_id;
|
|
145 p_hdr = USER2MEM(msg);
|
|
146
|
|
147 #if RVF_ENABLE_BUF_LINKAGE_CHECK
|
|
148 /* check if the buffer has been already enqueued */
|
|
149 if ( RVF_BUF_IS_LINKED( p_hdr) )
|
|
150 {
|
|
151 rvf_send_trace( "RVF: rvf_send_msg(): buffer already enqueued", 44, NULL_PARAM, RV_TRACE_LEVEL_ERROR, RVM_USE_ID );
|
|
152 return RVF_MEMORY_ERR;
|
|
153 }
|
|
154 #endif
|
|
155
|
|
156 rvf_disable(8); /* enter critical section */
|
|
157
|
|
158 /* chained the buffer in the mailbox list */
|
|
159 /*if (OSTaskQFirst[task_id][mbox]) {
|
|
160 OSTaskQLast[task_id][mbox]->p_next = p_hdr;
|
|
161 } else {
|
|
162 OSTaskQFirst[task_id][mbox] = p_hdr;
|
|
163 }
|
|
164 OSTaskQLast[task_id][mbox] = p_hdr;
|
|
165 p_hdr->p_next = NULL;*/
|
|
166
|
|
167 if (pRtAddrIdTable[tid]->OSTaskQFirst[mbox]) {
|
|
168 pRtAddrIdTable[tid]->OSTaskQLast[mbox]->p_next = p_hdr;
|
|
169 } else {
|
|
170 pRtAddrIdTable[tid]->OSTaskQFirst[mbox] = p_hdr;
|
|
171 }
|
|
172 pRtAddrIdTable[tid]->OSTaskQLast[mbox] = p_hdr;
|
|
173
|
|
174 p_hdr->p_next = NULL;
|
|
175
|
|
176 #if RVF_ENABLE_BUF_LINKAGE_CHECK
|
|
177 RVF_SET_BUF_LINKED(p_hdr); /* change buffer status */
|
|
178 #endif
|
|
179
|
|
180 rvf_enable();
|
|
181
|
|
182 /* send a rvf event */
|
|
183 rvf_send_event(tid, (UINT16) (EVENT_MASK(mbox)) );
|
|
184
|
|
185 return RVF_OK;
|
|
186 }
|
|
187
|
|
188 // Poss. Deprecate ! [Only used by: rvf.Buffer::_rvf_send_msg_to_mbox() ]
|
|
189 // May conflict with "msg::rvf_send_priority_msg()"
|
|
190 T_RVF_RET rvf_adapt_send_msg (T_RVF_G_ADDR_ID addr_id, void *msg, UINT8 mbox) {
|
|
191 return _send_msg ( addr_id, msg, mbox, FALSE);
|
|
192 }
|
|
193
|
|
194
|