[352c9b2] | 1 | /* |
---|
[3c49a508] | 2 | * ITRON Message Buffer Manager |
---|
| 3 | * |
---|
[352c9b2] | 4 | * The license and distribution terms for this file may be |
---|
| 5 | * found in the file LICENSE in this distribution or at |
---|
| 6 | * http://www.OARcorp.com/rtems/license.html. |
---|
| 7 | * |
---|
| 8 | * $Id$ |
---|
| 9 | */ |
---|
| 10 | |
---|
| 11 | #include <itron.h> |
---|
| 12 | |
---|
| 13 | #include <rtems/itron/msgbuffer.h> |
---|
| 14 | #include <rtems/itron/task.h> |
---|
| 15 | |
---|
| 16 | ER _ITRON_Message_buffer_Translate_core_message_buffer_return_code( |
---|
[3c49a508] | 17 | CORE_message_queue_Status status |
---|
| 18 | ) |
---|
[352c9b2] | 19 | { |
---|
[3c49a508] | 20 | switch (status) { |
---|
[352c9b2] | 21 | case CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL: |
---|
[3c49a508] | 22 | return E_OK; |
---|
[352c9b2] | 23 | case CORE_MESSAGE_QUEUE_STATUS_TOO_MANY: |
---|
[3c49a508] | 24 | return E_TMOUT; |
---|
[352c9b2] | 25 | case CORE_MESSAGE_QUEUE_STATUS_INVALID_SIZE: |
---|
[3c49a508] | 26 | return E_PAR; |
---|
[352c9b2] | 27 | case CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED_NOWAIT: |
---|
[3c49a508] | 28 | return E_TMOUT; |
---|
[352c9b2] | 29 | case CORE_MESSAGE_QUEUE_STATUS_TIMEOUT: |
---|
[3c49a508] | 30 | return E_TMOUT; |
---|
[352c9b2] | 31 | default: |
---|
[3c49a508] | 32 | return E_ID; |
---|
| 33 | } |
---|
[352c9b2] | 34 | } |
---|
| 35 | |
---|
| 36 | /* |
---|
| 37 | * _ITRON_Message_buffer_Manager_initialization |
---|
| 38 | * |
---|
| 39 | * This routine initializes all message buffer manager related data |
---|
| 40 | * structures. |
---|
| 41 | * |
---|
| 42 | * Input parameters: |
---|
| 43 | * maximum_message_buffers - maximum configured message buffers |
---|
| 44 | * |
---|
| 45 | * Output parameters: NONE |
---|
| 46 | */ |
---|
| 47 | |
---|
| 48 | void _ITRON_Message_buffer_Manager_initialization( |
---|
[3c49a508] | 49 | unsigned32 maximum_message_buffers |
---|
| 50 | ) |
---|
[352c9b2] | 51 | { |
---|
[3c49a508] | 52 | _Objects_Initialize_information( |
---|
| 53 | &_ITRON_Message_buffer_Information, /* object information table */ |
---|
| 54 | OBJECTS_ITRON_MESSAGE_BUFFERS, /* object class */ |
---|
| 55 | FALSE, /* TRUE if this is a |
---|
| 56 | global object class */ |
---|
| 57 | maximum_message_buffers, /* maximum objects of this class */ |
---|
| 58 | sizeof( ITRON_Message_buffer_Control ), /* size of this |
---|
| 59 | object's control |
---|
| 60 | block */ |
---|
| 61 | FALSE, /* TRUE if names for this |
---|
| 62 | object are strings */ |
---|
| 63 | RTEMS_MAXIMUM_NAME_LENGTH, /* maximum length of each |
---|
| 64 | object's name */ |
---|
| 65 | FALSE /* TRUE if this class is threads */ |
---|
| 66 | ); |
---|
| 67 | |
---|
| 68 | /* |
---|
| 69 | * Register the MP Process Packet routine. |
---|
| 70 | * |
---|
| 71 | * NOTE: No MP Support YET in RTEMS ITRON implementation. |
---|
| 72 | */ |
---|
[352c9b2] | 73 | } |
---|
| 74 | |
---|
| 75 | /* |
---|
| 76 | * cre_mbf - Create MessageBuffer |
---|
| 77 | */ |
---|
| 78 | |
---|
| 79 | ER cre_mbf( |
---|
[3c49a508] | 80 | ID mbfid, |
---|
| 81 | T_CMBF *pk_cmbf |
---|
| 82 | ) |
---|
[352c9b2] | 83 | { |
---|
[3c49a508] | 84 | CORE_message_queue_Attributes the_message_queue_attributes; |
---|
| 85 | ITRON_Message_buffer_Control *the_message_buffer; |
---|
[352c9b2] | 86 | |
---|
[3c49a508] | 87 | /* |
---|
| 88 | * Bad pointer to the attributes structure |
---|
| 89 | */ |
---|
[352c9b2] | 90 | |
---|
[3c49a508] | 91 | if ( !pk_cmbf ) |
---|
| 92 | return E_PAR; |
---|
[352c9b2] | 93 | |
---|
[3c49a508] | 94 | /* |
---|
| 95 | * Bits were set that were note defined. |
---|
| 96 | */ |
---|
[352c9b2] | 97 | |
---|
[3c49a508] | 98 | if (pk_cmbf->mbfatr & ~(TA_TPRI)) |
---|
| 99 | return E_RSATR; |
---|
[352c9b2] | 100 | |
---|
[3c49a508] | 101 | if (pk_cmbf->bufsz < 0 || pk_cmbf->maxmsz < 0) |
---|
| 102 | return E_PAR; |
---|
[352c9b2] | 103 | |
---|
[3c49a508] | 104 | if (pk_cmbf->bufsz < pk_cmbf->maxmsz) |
---|
| 105 | return E_PAR; |
---|
[352c9b2] | 106 | |
---|
[3c49a508] | 107 | _Thread_Disable_dispatch(); /* prevents deletion */ |
---|
[352c9b2] | 108 | |
---|
[3c49a508] | 109 | the_message_buffer = _ITRON_Message_buffer_Allocate(mbfid); |
---|
| 110 | if ( !the_message_buffer ) { |
---|
| 111 | _Thread_Enable_dispatch(); |
---|
| 112 | return _ITRON_Message_buffer_Clarify_allocation_id_error(mbfid); |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | if ( pk_cmbf->mbfatr & TA_TPRI ) |
---|
| 116 | the_message_queue_attributes.discipline = |
---|
| 117 | CORE_MESSAGE_QUEUE_DISCIPLINES_PRIORITY; |
---|
| 118 | else |
---|
| 119 | the_message_queue_attributes.discipline = |
---|
| 120 | CORE_MESSAGE_QUEUE_DISCIPLINES_FIFO; |
---|
| 121 | |
---|
| 122 | _CORE_message_queue_Initialize( |
---|
| 123 | &the_message_buffer->message_queue, |
---|
| 124 | OBJECTS_ITRON_MESSAGE_BUFFERS, |
---|
| 125 | &the_message_queue_attributes, |
---|
| 126 | pk_cmbf->bufsz / pk_cmbf->maxmsz, |
---|
| 127 | pk_cmbf->maxmsz, |
---|
| 128 | NULL /* Multiprocessing not supported */ |
---|
| 129 | ); |
---|
| 130 | |
---|
| 131 | _ITRON_Objects_Open( &_ITRON_Message_buffer_Information, |
---|
| 132 | &the_message_buffer->Object ); |
---|
[352c9b2] | 133 | |
---|
[3c49a508] | 134 | /* |
---|
| 135 | * If multiprocessing were supported, this is where we would announce |
---|
| 136 | * the existence of the semaphore to the rest of the system. |
---|
| 137 | */ |
---|
[352c9b2] | 138 | |
---|
| 139 | #if defined(RTEMS_MULTIPROCESSING) |
---|
| 140 | #endif |
---|
| 141 | |
---|
[3c49a508] | 142 | _Thread_Enable_dispatch(); |
---|
[352c9b2] | 143 | |
---|
[3c49a508] | 144 | return E_OK; |
---|
[352c9b2] | 145 | } |
---|
| 146 | |
---|
| 147 | /* |
---|
| 148 | * del_mbf - Delete MessageBuffer |
---|
| 149 | */ |
---|
| 150 | |
---|
| 151 | ER del_mbf( |
---|
[3c49a508] | 152 | ID mbfid |
---|
| 153 | ) |
---|
[352c9b2] | 154 | { |
---|
[3c49a508] | 155 | ITRON_Message_buffer_Control *the_message_buffer; |
---|
| 156 | Objects_Locations location; |
---|
[352c9b2] | 157 | |
---|
[3c49a508] | 158 | the_message_buffer = _ITRON_Message_buffer_Get(mbfid, &location); |
---|
| 159 | switch (location) { |
---|
[352c9b2] | 160 | case OBJECTS_REMOTE: |
---|
| 161 | case OBJECTS_ERROR: /* Multiprocessing not supported */ |
---|
[3c49a508] | 162 | return _ITRON_Message_buffer_Clarify_get_id_error(mbfid); |
---|
[352c9b2] | 163 | |
---|
| 164 | case OBJECTS_LOCAL: |
---|
[3c49a508] | 165 | _CORE_message_queue_Flush(&the_message_buffer->message_queue); |
---|
| 166 | _ITRON_Objects_Close( &_ITRON_Message_buffer_Information, |
---|
| 167 | &the_message_buffer->Object); |
---|
| 168 | _ITRON_Message_buffer_Free(the_message_buffer); |
---|
| 169 | |
---|
| 170 | /* |
---|
| 171 | * If multiprocessing were supported, this is where we would announce |
---|
| 172 | * the existence of the semaphore to the rest of the system. |
---|
| 173 | */ |
---|
[352c9b2] | 174 | |
---|
| 175 | #if defined(RTEMS_MULTIPROCESSING) |
---|
| 176 | #endif |
---|
[3c49a508] | 177 | _Thread_Enable_dispatch(); |
---|
| 178 | return E_OK; |
---|
| 179 | } |
---|
| 180 | |
---|
| 181 | return E_OK; |
---|
[352c9b2] | 182 | } |
---|
| 183 | |
---|
| 184 | /* |
---|
| 185 | * snd_mbf - Send Message to MessageBuffer |
---|
| 186 | */ |
---|
| 187 | |
---|
| 188 | ER snd_mbf( |
---|
[3c49a508] | 189 | ID mbfid, |
---|
| 190 | VP msg, |
---|
| 191 | INT msgsz |
---|
| 192 | ) |
---|
[352c9b2] | 193 | { |
---|
| 194 | return E_OK; |
---|
| 195 | } |
---|
| 196 | |
---|
| 197 | /* |
---|
| 198 | * psnd_mbf - Poll and Send Message to MessageBuffer |
---|
| 199 | */ |
---|
| 200 | |
---|
| 201 | ER psnd_mbf( |
---|
[3c49a508] | 202 | ID mbfid, |
---|
| 203 | VP msg, |
---|
| 204 | INT msgsz |
---|
| 205 | ) |
---|
[352c9b2] | 206 | { |
---|
[3c49a508] | 207 | ITRON_Message_buffer_Control *the_message_buffer; |
---|
| 208 | Objects_Locations location; |
---|
| 209 | CORE_message_queue_Status status; |
---|
[352c9b2] | 210 | |
---|
[3c49a508] | 211 | if (msgsz <= 0 || !msg) |
---|
| 212 | return E_PAR; |
---|
[352c9b2] | 213 | |
---|
[3c49a508] | 214 | the_message_buffer = _ITRON_Message_buffer_Get(mbfid, &location); |
---|
| 215 | switch (location) { |
---|
[352c9b2] | 216 | case OBJECTS_REMOTE: |
---|
| 217 | case OBJECTS_ERROR: /* Multiprocessing not supported */ |
---|
[3c49a508] | 218 | return _ITRON_Message_buffer_Clarify_get_id_error(mbfid); |
---|
[352c9b2] | 219 | |
---|
| 220 | case OBJECTS_LOCAL: |
---|
[3c49a508] | 221 | status = _CORE_message_queue_Submit( |
---|
| 222 | &the_message_buffer->message_queue, |
---|
| 223 | msg, |
---|
| 224 | msgsz, |
---|
| 225 | the_message_buffer->Object.id, |
---|
| 226 | NULL, |
---|
| 227 | CORE_MESSAGE_QUEUE_SEND_REQUEST |
---|
| 228 | ); |
---|
| 229 | _Thread_Enable_dispatch(); |
---|
| 230 | return |
---|
| 231 | _ITRON_Message_buffer_Translate_core_message_buffer_return_code(status); |
---|
[352c9b2] | 232 | } |
---|
| 233 | |
---|
| 234 | /* |
---|
| 235 | * If multiprocessing were supported, this is where we would announce |
---|
| 236 | * the existence of the semaphore to the rest of the system. |
---|
| 237 | */ |
---|
| 238 | |
---|
| 239 | #if defined(RTEMS_MULTIPROCESSING) |
---|
| 240 | #endif |
---|
| 241 | |
---|
| 242 | return E_OK; |
---|
| 243 | } |
---|
| 244 | |
---|
| 245 | /* |
---|
| 246 | * tsnd_mbf - Send Message to MessageBuffer with Timeout |
---|
| 247 | */ |
---|
| 248 | |
---|
| 249 | ER tsnd_mbf( |
---|
[3c49a508] | 250 | ID mbfid, |
---|
| 251 | VP msg, |
---|
| 252 | INT msgsz, |
---|
| 253 | TMO tmout |
---|
| 254 | ) |
---|
[352c9b2] | 255 | { |
---|
[3c49a508] | 256 | return E_OK; |
---|
[352c9b2] | 257 | } |
---|
| 258 | |
---|
| 259 | /* |
---|
| 260 | * rcv_mbf - Receive Message from MessageBuffer |
---|
| 261 | */ |
---|
| 262 | |
---|
| 263 | ER rcv_mbf( |
---|
[3c49a508] | 264 | VP msg, |
---|
| 265 | INT *p_msgsz, |
---|
| 266 | ID mbfid |
---|
| 267 | ) |
---|
[352c9b2] | 268 | { |
---|
[3c49a508] | 269 | return trcv_mbf(msg, p_msgsz, mbfid, TMO_FEVR); |
---|
[352c9b2] | 270 | } |
---|
| 271 | |
---|
| 272 | /* |
---|
| 273 | * prcv_mbf - Poll and Receive Message from MessageBuffer |
---|
| 274 | */ |
---|
| 275 | |
---|
| 276 | ER prcv_mbf( |
---|
[3c49a508] | 277 | VP msg, |
---|
| 278 | INT *p_msgsz, |
---|
| 279 | ID mbfid |
---|
| 280 | ) |
---|
[352c9b2] | 281 | { |
---|
[3c49a508] | 282 | return trcv_mbf(msg, p_msgsz, mbfid, TMO_POL); |
---|
[352c9b2] | 283 | } |
---|
| 284 | |
---|
| 285 | /* |
---|
| 286 | * trcv_mbf - Receive Message from MessageBuffer with Timeout |
---|
| 287 | */ |
---|
| 288 | |
---|
| 289 | ER trcv_mbf( |
---|
[3c49a508] | 290 | VP msg, |
---|
| 291 | INT *p_msgsz, |
---|
| 292 | ID mbfid, |
---|
| 293 | TMO tmout |
---|
| 294 | ) |
---|
[352c9b2] | 295 | { |
---|
[3c49a508] | 296 | ITRON_Message_buffer_Control *the_message_buffer; |
---|
| 297 | Objects_Locations location; |
---|
| 298 | CORE_message_queue_Status status; |
---|
| 299 | boolean wait; |
---|
| 300 | Watchdog_Interval interval; |
---|
| 301 | |
---|
| 302 | interval = 0; |
---|
| 303 | if (tmout == TMO_POL) { |
---|
| 304 | wait = FALSE; |
---|
| 305 | } else { |
---|
| 306 | wait = TRUE; |
---|
| 307 | if (tmout != TMO_FEVR) |
---|
| 308 | interval = TOD_MILLISECONDS_TO_TICKS(tmout); |
---|
| 309 | } |
---|
| 310 | |
---|
| 311 | if (wait && _ITRON_Is_in_non_task_state() ) |
---|
| 312 | return E_CTX; |
---|
| 313 | |
---|
| 314 | if (!p_msgsz || !msg || tmout <= -2) |
---|
| 315 | return E_PAR; |
---|
[352c9b2] | 316 | |
---|
[3c49a508] | 317 | the_message_buffer = _ITRON_Message_buffer_Get(mbfid, &location); |
---|
| 318 | switch (location) { |
---|
[352c9b2] | 319 | case OBJECTS_REMOTE: |
---|
| 320 | case OBJECTS_ERROR: /* Multiprocessing not supported */ |
---|
[3c49a508] | 321 | return _ITRON_Message_buffer_Clarify_get_id_error(mbfid); |
---|
[352c9b2] | 322 | |
---|
| 323 | case OBJECTS_LOCAL: |
---|
[3c49a508] | 324 | _CORE_message_queue_Seize( |
---|
| 325 | &the_message_buffer->message_queue, |
---|
| 326 | the_message_buffer->Object.id, |
---|
| 327 | msg, |
---|
| 328 | p_msgsz, |
---|
| 329 | wait, |
---|
| 330 | interval |
---|
| 331 | ); |
---|
| 332 | _Thread_Enable_dispatch(); |
---|
| 333 | status = (CORE_message_queue_Status)_Thread_Executing->Wait.return_code; |
---|
| 334 | return |
---|
| 335 | _ITRON_Message_buffer_Translate_core_message_buffer_return_code(status); |
---|
[352c9b2] | 336 | } |
---|
| 337 | |
---|
| 338 | /* |
---|
| 339 | * If multiprocessing were supported, this is where we would announce |
---|
| 340 | * the existence of the semaphore to the rest of the system. |
---|
| 341 | */ |
---|
| 342 | |
---|
| 343 | #if defined(RTEMS_MULTIPROCESSING) |
---|
| 344 | #endif |
---|
| 345 | return E_OK; |
---|
| 346 | } |
---|
| 347 | |
---|
| 348 | /* |
---|
| 349 | * ref_mbf - Reference MessageBuffer Status |
---|
| 350 | */ |
---|
| 351 | |
---|
| 352 | ER ref_mbf( |
---|
[3c49a508] | 353 | T_RMBF *pk_rmbf, |
---|
| 354 | ID mbfid |
---|
| 355 | ) |
---|
[352c9b2] | 356 | { |
---|
[3c49a508] | 357 | ITRON_Message_buffer_Control *the_message_buffer; |
---|
| 358 | Objects_Locations location; |
---|
| 359 | CORE_message_queue_Control *the_core_msgq; |
---|
[352c9b2] | 360 | |
---|
[3c49a508] | 361 | if ( !pk_rmbf ) |
---|
| 362 | return E_PAR; /* XXX check this error code */ |
---|
| 363 | |
---|
| 364 | the_message_buffer = _ITRON_Message_buffer_Get( mbfid, &location ); |
---|
| 365 | switch ( location ) { |
---|
| 366 | case OBJECTS_REMOTE: /* Multiprocessing not supported */ |
---|
| 367 | case OBJECTS_ERROR: |
---|
| 368 | return _ITRON_Message_buffer_Clarify_get_id_error( mbfid ); |
---|
[352c9b2] | 369 | |
---|
[3c49a508] | 370 | case OBJECTS_LOCAL: |
---|
| 371 | the_core_msgq = &the_message_buffer->message_queue; |
---|
| 372 | |
---|
| 373 | /* |
---|
| 374 | * Fill in the size of message to be sent |
---|
| 375 | */ |
---|
| 376 | |
---|
| 377 | if (the_core_msgq->number_of_pending_messages == 0) { |
---|
| 378 | pk_rmbf->msgsz = 0; |
---|
| 379 | } else { |
---|
| 380 | pk_rmbf->msgsz = ((CORE_message_queue_Buffer_control *) |
---|
| 381 | the_core_msgq->Pending_messages.first)->Contents.size; |
---|
| 382 | } |
---|
[352c9b2] | 383 | |
---|
[3c49a508] | 384 | /* |
---|
| 385 | * Fill in the size of free buffer |
---|
| 386 | */ |
---|
| 387 | |
---|
| 388 | pk_rmbf->frbufsz = |
---|
| 389 | (the_core_msgq->maximum_pending_messages - |
---|
| 390 | the_core_msgq->number_of_pending_messages) * |
---|
| 391 | the_core_msgq->maximum_message_size; |
---|
| 392 | |
---|
| 393 | |
---|
| 394 | /* |
---|
| 395 | * Fill in whether or not there is a waiting task |
---|
| 396 | */ |
---|
| 397 | |
---|
| 398 | if ( !_Thread_queue_First(&the_core_msgq->Wait_queue ) ) |
---|
| 399 | pk_rmbf->wtsk = FALSE; |
---|
| 400 | else |
---|
| 401 | pk_rmbf->wtsk = TRUE; |
---|
| 402 | |
---|
| 403 | pk_rmbf->stsk = FALSE; |
---|
| 404 | _Thread_Enable_dispatch(); |
---|
[352c9b2] | 405 | return E_OK; |
---|
[3c49a508] | 406 | } |
---|
| 407 | return E_OK; |
---|
[352c9b2] | 408 | } |
---|