summaryrefslogtreecommitdiffstats
path: root/c/src/exec/itron/src/tsnd_mbf.c
blob: 0ed3b4f90ec79f01628d9c661dcc777b65154199 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
 *  ITRON Message Buffer Manager
 *
 *  COPYRIGHT (c) 1989-1999.
 *  On-Line Applications Research Corporation (OAR).
 *
 *  The license and distribution terms for this file may be
 *  found in the file LICENSE in this distribution or at
 *  http://www.OARcorp.com/rtems/license.html.
 *
 *  $Id$
 */

#include <itron.h>

#include <rtems/itron/msgbuffer.h>
#include <rtems/itron/task.h>

#include <assert.h>  /* only for blocking */

/*
 *  tsnd_mbf - Send Message to MessageBuffer with Timeout
 */

ER tsnd_mbf(
  ID  mbfid,
  VP  msg,
  INT msgsz,
  TMO tmout
)
{
  ITRON_Message_buffer_Control  *the_message_buffer;
  Objects_Locations              location;
  Watchdog_Interval              interval;
  boolean                        wait;

  if (msgsz <= 0 || !msg)
    return E_PAR;

  interval = 0;
  if ( tmout == TMO_POL ) {
    wait = FALSE;
  } else {
    wait = TRUE;
    if ( tmout != TMO_FEVR )
      interval = TOD_MILLISECONDS_TO_TICKS(tmout);
  }

  if ( wait && _ITRON_Is_in_non_task_state() )
    return E_CTX;

  the_message_buffer = _ITRON_Message_buffer_Get(mbfid, &location);
  switch (location) {
    case OBJECTS_REMOTE:
    case OBJECTS_ERROR:           /* Multiprocessing not supported */
      return _ITRON_Message_buffer_Clarify_get_id_error(mbfid);

    case OBJECTS_LOCAL:
      /* XXX Submit needs to take into account blocking */
      _CORE_message_queue_Submit(
        &the_message_buffer->message_queue,
        msg,
        msgsz,
        the_message_buffer->Object.id,
        NULL,
        CORE_MESSAGE_QUEUE_SEND_REQUEST,
        wait,      /* sender may block */
        interval   /* timeout interval */
      );
      _Thread_Enable_dispatch();
      return _ITRON_Message_buffer_Translate_core_message_buffer_return_code(
          _Thread_Executing->Wait.return_code
      );
    }

    /*
     *  If multiprocessing were supported, this is where we would announce
     *  the existence of the semaphore to the rest of the system.
     */

#if defined(RTEMS_MULTIPROCESSING)
#endif

    return E_OK;
}