00001
00021
00022
00023
00024
00025 #include <stddef.h>
00026 #include "co_int.h"
00027 #include "co_bool.h"
00028 #include "dbg_assert.h"
00029
00030 #include "rwnx_config.h"
00031
00032 #include "ke_config.h"
00033 #include "ke_queue.h"
00034 #include "ke_msg.h"
00035 #include "ke_task.h"
00036 #include "ke_mem.h"
00037 #include "dbg.h"
00038
00039 #include "macif.h"
00040
00041 #include "ke_event.h"
00042 #include "ke_env.h"
00043
00044
00073 void *ke_msg_alloc(ke_msg_id_t const id,
00074 ke_task_id_t const dest_id,
00075 ke_task_id_t const src_id,
00076 uint16_t const param_len)
00077 {
00078 struct ke_msg *msg = (struct ke_msg*) ke_malloc(sizeof(struct ke_msg) +
00079 param_len - sizeof (uint32_t));
00080 void *param_ptr = NULL;
00081
00082 ASSERT_ERR(msg != NULL);
00083 msg->hdr.next = NULL;
00084 msg->id = id;
00085 msg->dest_id = dest_id;
00086 msg->src_id = src_id;
00087 msg->param_len = param_len;
00088
00089 param_ptr = ke_msg2param(msg);
00090
00091 memset(param_ptr, 0, param_len);
00092
00093 return param_ptr;
00094 }
00095
00096
00113 void ke_msg_send(void const *param_ptr)
00114 {
00115 struct ke_msg * msg = ke_param2msg(param_ptr);
00116 int type = KE_TYPE_GET(msg->dest_id);
00117
00118 if (ke_task_local(type))
00119 {
00120
00121
00122
00123 ke_queue_push(&ke_env.queue_sent, &msg->hdr);
00124
00125
00126 ke_evt_set(KE_EVT_KE_MESSAGE_BIT);
00127 }
00128 else
00129 {
00130 dbg(D_INF D_KE "Dispatching msg:%x from tsk:%x to tsk:%x\n",
00131 msg->id, msg->src_id, msg->dest_id);
00132 TRACE_KERNEL(MSG_API, "Dispatching %kM from %kT to %kT",
00133 msg->id, msg->src_id, msg->dest_id);
00134
00135
00136 macif_kmsg_fwd(msg);
00137 }
00138 }
00139
00152 void ke_msg_send_basic(ke_msg_id_t const id,
00153 ke_task_id_t const dest_id,
00154 ke_task_id_t const src_id)
00155 {
00156 void *no_param = ke_msg_alloc(id, dest_id, src_id, 0);
00157 ke_msg_send(no_param);
00158 }
00159
00172 void ke_msg_forward(void const *param_ptr,
00173 ke_task_id_t const dest_id,
00174 ke_task_id_t const src_id)
00175
00176 {
00177 struct ke_msg * msg = ke_param2msg(param_ptr);
00178
00179
00180 msg->dest_id = dest_id;
00181 msg->src_id = src_id;
00182
00183
00184 ke_msg_send(param_ptr);
00185
00186 }
00187
00201 void ke_msg_forward_and_change_id(void const *param_ptr,
00202 ke_msg_id_t const msg_id,
00203 ke_task_id_t const dest_id,
00204 ke_task_id_t const src_id)
00205 {
00206 struct ke_msg * msg = ke_param2msg(param_ptr);
00207
00208
00209 msg->id = msg_id;
00210 msg->dest_id = dest_id;
00211 msg->src_id = src_id;
00212
00213
00214 ke_msg_send(param_ptr);
00215
00216 }
00217
00225 void ke_msg_free(struct ke_msg const *msg)
00226 {
00227
00228 ke_free( (void*) msg);
00229 }
00230