OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [exec/] [score/] [src/] [coremsgseize.c] - Blame information for rev 587

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 unneback
/*
2
 *  CORE Message Queue Handler
3
 *
4
 *  DESCRIPTION:
5
 *
6
 *  This package is the implementation of the CORE Message Queue Handler.
7
 *  This core object provides task synchronization and communication functions
8
 *  via messages passed to queue objects.
9
 *
10
 *  COPYRIGHT (c) 1989-1999.
11
 *  On-Line Applications Research Corporation (OAR).
12
 *
13
 *  The license and distribution terms for this file may be
14
 *  found in the file LICENSE in this distribution or at
15
 *  http://www.OARcorp.com/rtems/license.html.
16
 *
17
 *  $Id: coremsgseize.c,v 1.2 2001-09-27 11:59:34 chris Exp $
18
 */
19
 
20
#include <rtems/system.h>
21
#include <rtems/score/chain.h>
22
#include <rtems/score/isr.h>
23
#include <rtems/score/object.h>
24
#include <rtems/score/coremsg.h>
25
#include <rtems/score/states.h>
26
#include <rtems/score/thread.h>
27
#include <rtems/score/wkspace.h>
28
#if defined(RTEMS_MULTIPROCESSING)
29
#include <rtems/score/mpci.h>
30
#endif
31
 
32
/*PAGE
33
 *
34
 *  _CORE_message_queue_Seize
35
 *
36
 *  This kernel routine dequeues a message, copies the message buffer to
37
 *  a given destination buffer, and frees the message buffer to the
38
 *  inactive message pool.  The thread will be blocked if wait is TRUE,
39
 *  otherwise an error will be given to the thread if no messages are available.
40
 *
41
 *  Input parameters:
42
 *    the_message_queue - pointer to message queue
43
 *    id                - id of object we are waitig on
44
 *    buffer            - pointer to message buffer to be filled
45
 *    size              - pointer to the size of buffer to be filled
46
 *    wait              - TRUE if wait is allowed, FALSE otherwise
47
 *    timeout           - time to wait for a message
48
 *
49
 *  Output parameters:  NONE
50
 *
51
 *  NOTE: Dependent on BUFFER_LENGTH
52
 *
53
 *  INTERRUPT LATENCY:
54
 *    available
55
 *    wait
56
 */
57
 
58
void _CORE_message_queue_Seize(
59
  CORE_message_queue_Control      *the_message_queue,
60
  Objects_Id                       id,
61
  void                            *buffer,
62
  unsigned32                      *size,
63
  boolean                          wait,
64
  Watchdog_Interval                timeout
65
)
66
{
67
  ISR_Level                          level;
68
  CORE_message_queue_Buffer_control *the_message;
69
  Thread_Control                    *executing;
70
  Thread_Control                    *the_thread;
71
 
72
  executing = _Thread_Executing;
73
  executing->Wait.return_code = CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL;
74
  _ISR_Disable( level );
75
  if ( the_message_queue->number_of_pending_messages != 0 ) {
76
    the_message_queue->number_of_pending_messages -= 1;
77
 
78
    the_message = _CORE_message_queue_Get_pending_message( the_message_queue );
79
    _ISR_Enable( level );
80
 
81
    *size = the_message->Contents.size;
82
    _Thread_Executing->Wait.count = the_message->priority;
83
    _CORE_message_queue_Copy_buffer(the_message->Contents.buffer,buffer,*size);
84
 
85
    /*
86
     *  There could be a thread waiting to send a message.  If there
87
     *  is not, then we can go ahead and free the buffer.
88
     *
89
     *  NOTE: If we note that the queue was not full before this receive,
90
     *  then we can avoid this dequeue.
91
     */
92
 
93
    the_thread = _Thread_queue_Dequeue( &the_message_queue->Wait_queue );
94
    if ( !the_thread ) {
95
      _CORE_message_queue_Free_message_buffer( the_message_queue, the_message );
96
      return;
97
    }
98
 
99
    /*
100
     *  There was a thread waiting to send a message.  This code
101
     *  puts the messages in the message queue on behalf of the
102
     *  waiting task.
103
     */
104
 
105
    the_message->priority  = the_thread->Wait.count;
106
    the_message->Contents.size = (unsigned32)the_thread->Wait.return_argument_1;
107
    _CORE_message_queue_Copy_buffer(
108
      the_thread->Wait.return_argument,
109
      the_message->Contents.buffer,
110
      the_message->Contents.size
111
    );
112
 
113
    _CORE_message_queue_Insert_message(
114
       the_message_queue,
115
       the_message,
116
       the_message->priority
117
    );
118
    return;
119
  }
120
 
121
  if ( !wait ) {
122
    _ISR_Enable( level );
123
    executing->Wait.return_code = CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED_NOWAIT;
124
    return;
125
  }
126
 
127
  _Thread_queue_Enter_critical_section( &the_message_queue->Wait_queue );
128
  executing->Wait.queue              = &the_message_queue->Wait_queue;
129
  executing->Wait.id                 = id;
130
  executing->Wait.return_argument    = (void *)buffer;
131
  executing->Wait.return_argument_1  = (void *)size;
132
  /* Wait.count will be filled in with the message priority */
133
  _ISR_Enable( level );
134
 
135
  _Thread_queue_Enqueue( &the_message_queue->Wait_queue, timeout );
136
}
137
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.