in OS_TSK, rename run as tsk_run and new as tsk_new.
rt_Mailbox.c@0:5f46ebd8588e, 2012-09-02 (annotated)
- Committer:
- jonathonfletcher
- Date:
- Sun Sep 02 03:24:20 2012 +0000
- Revision:
- 0:5f46ebd8588e
in OS_TSK, rename run as tsk_run and new as tsk_new.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jonathonfletcher | 0:5f46ebd8588e | 1 | /*---------------------------------------------------------------------------- |
jonathonfletcher | 0:5f46ebd8588e | 2 | * RL-ARM - RTX |
jonathonfletcher | 0:5f46ebd8588e | 3 | *---------------------------------------------------------------------------- |
jonathonfletcher | 0:5f46ebd8588e | 4 | * Name: RT_MAILBOX.C |
jonathonfletcher | 0:5f46ebd8588e | 5 | * Purpose: Implements waits and wake-ups for mailbox messages |
jonathonfletcher | 0:5f46ebd8588e | 6 | * Rev.: V4.50 |
jonathonfletcher | 0:5f46ebd8588e | 7 | *---------------------------------------------------------------------------- |
jonathonfletcher | 0:5f46ebd8588e | 8 | * |
jonathonfletcher | 0:5f46ebd8588e | 9 | * Copyright (c) 1999-2009 KEIL, 2009-2012 ARM Germany GmbH |
jonathonfletcher | 0:5f46ebd8588e | 10 | * All rights reserved. |
jonathonfletcher | 0:5f46ebd8588e | 11 | * Redistribution and use in source and binary forms, with or without |
jonathonfletcher | 0:5f46ebd8588e | 12 | * modification, are permitted provided that the following conditions are met: |
jonathonfletcher | 0:5f46ebd8588e | 13 | * - Redistributions of source code must retain the above copyright |
jonathonfletcher | 0:5f46ebd8588e | 14 | * notice, this list of conditions and the following disclaimer. |
jonathonfletcher | 0:5f46ebd8588e | 15 | * - Redistributions in binary form must reproduce the above copyright |
jonathonfletcher | 0:5f46ebd8588e | 16 | * notice, this list of conditions and the following disclaimer in the |
jonathonfletcher | 0:5f46ebd8588e | 17 | * documentation and/or other materials provided with the distribution. |
jonathonfletcher | 0:5f46ebd8588e | 18 | * - Neither the name of ARM nor the names of its contributors may be used |
jonathonfletcher | 0:5f46ebd8588e | 19 | * to endorse or promote products derived from this software without |
jonathonfletcher | 0:5f46ebd8588e | 20 | * specific prior written permission. |
jonathonfletcher | 0:5f46ebd8588e | 21 | * |
jonathonfletcher | 0:5f46ebd8588e | 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
jonathonfletcher | 0:5f46ebd8588e | 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
jonathonfletcher | 0:5f46ebd8588e | 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
jonathonfletcher | 0:5f46ebd8588e | 25 | * ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE |
jonathonfletcher | 0:5f46ebd8588e | 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
jonathonfletcher | 0:5f46ebd8588e | 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
jonathonfletcher | 0:5f46ebd8588e | 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
jonathonfletcher | 0:5f46ebd8588e | 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
jonathonfletcher | 0:5f46ebd8588e | 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
jonathonfletcher | 0:5f46ebd8588e | 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
jonathonfletcher | 0:5f46ebd8588e | 32 | * POSSIBILITY OF SUCH DAMAGE. |
jonathonfletcher | 0:5f46ebd8588e | 33 | *---------------------------------------------------------------------------*/ |
jonathonfletcher | 0:5f46ebd8588e | 34 | |
jonathonfletcher | 0:5f46ebd8588e | 35 | #include "rt_TypeDef.h" |
jonathonfletcher | 0:5f46ebd8588e | 36 | #include "RTX_Config.h" |
jonathonfletcher | 0:5f46ebd8588e | 37 | #include "rt_System.h" |
jonathonfletcher | 0:5f46ebd8588e | 38 | #include "rt_List.h" |
jonathonfletcher | 0:5f46ebd8588e | 39 | #include "rt_Mailbox.h" |
jonathonfletcher | 0:5f46ebd8588e | 40 | #include "rt_MemBox.h" |
jonathonfletcher | 0:5f46ebd8588e | 41 | #include "rt_Task.h" |
jonathonfletcher | 0:5f46ebd8588e | 42 | #include "rt_HAL_CM.h" |
jonathonfletcher | 0:5f46ebd8588e | 43 | |
jonathonfletcher | 0:5f46ebd8588e | 44 | |
jonathonfletcher | 0:5f46ebd8588e | 45 | /*---------------------------------------------------------------------------- |
jonathonfletcher | 0:5f46ebd8588e | 46 | * Functions |
jonathonfletcher | 0:5f46ebd8588e | 47 | *---------------------------------------------------------------------------*/ |
jonathonfletcher | 0:5f46ebd8588e | 48 | |
jonathonfletcher | 0:5f46ebd8588e | 49 | |
jonathonfletcher | 0:5f46ebd8588e | 50 | /*--------------------------- rt_mbx_init -----------------------------------*/ |
jonathonfletcher | 0:5f46ebd8588e | 51 | |
jonathonfletcher | 0:5f46ebd8588e | 52 | void rt_mbx_init (OS_ID mailbox, U16 mbx_size) { |
jonathonfletcher | 0:5f46ebd8588e | 53 | /* Initialize a mailbox */ |
jonathonfletcher | 0:5f46ebd8588e | 54 | P_MCB p_MCB = mailbox; |
jonathonfletcher | 0:5f46ebd8588e | 55 | |
jonathonfletcher | 0:5f46ebd8588e | 56 | p_MCB->cb_type = MCB; |
jonathonfletcher | 0:5f46ebd8588e | 57 | p_MCB->state = 0; |
jonathonfletcher | 0:5f46ebd8588e | 58 | p_MCB->isr_st = 0; |
jonathonfletcher | 0:5f46ebd8588e | 59 | p_MCB->p_lnk = NULL; |
jonathonfletcher | 0:5f46ebd8588e | 60 | p_MCB->first = 0; |
jonathonfletcher | 0:5f46ebd8588e | 61 | p_MCB->last = 0; |
jonathonfletcher | 0:5f46ebd8588e | 62 | p_MCB->count = 0; |
jonathonfletcher | 0:5f46ebd8588e | 63 | p_MCB->size = (mbx_size + sizeof(void *) - sizeof(struct OS_MCB)) / |
jonathonfletcher | 0:5f46ebd8588e | 64 | (U32)sizeof (void *); |
jonathonfletcher | 0:5f46ebd8588e | 65 | } |
jonathonfletcher | 0:5f46ebd8588e | 66 | |
jonathonfletcher | 0:5f46ebd8588e | 67 | |
jonathonfletcher | 0:5f46ebd8588e | 68 | /*--------------------------- rt_mbx_send -----------------------------------*/ |
jonathonfletcher | 0:5f46ebd8588e | 69 | |
jonathonfletcher | 0:5f46ebd8588e | 70 | OS_RESULT rt_mbx_send (OS_ID mailbox, void *p_msg, U16 timeout) { |
jonathonfletcher | 0:5f46ebd8588e | 71 | /* Send message to a mailbox */ |
jonathonfletcher | 0:5f46ebd8588e | 72 | P_MCB p_MCB = mailbox; |
jonathonfletcher | 0:5f46ebd8588e | 73 | P_TCB p_TCB; |
jonathonfletcher | 0:5f46ebd8588e | 74 | |
jonathonfletcher | 0:5f46ebd8588e | 75 | if (p_MCB->state == 1) { |
jonathonfletcher | 0:5f46ebd8588e | 76 | /* A task is waiting for message */ |
jonathonfletcher | 0:5f46ebd8588e | 77 | p_TCB = rt_get_first ((P_XCB)p_MCB); |
jonathonfletcher | 0:5f46ebd8588e | 78 | if (p_MCB->p_lnk == NULL) { |
jonathonfletcher | 0:5f46ebd8588e | 79 | p_MCB->state = 0; |
jonathonfletcher | 0:5f46ebd8588e | 80 | } |
jonathonfletcher | 0:5f46ebd8588e | 81 | rt_ret_val2(p_TCB, 0x10/*osEventMessage*/, (U32)p_msg); |
jonathonfletcher | 0:5f46ebd8588e | 82 | rt_rmv_dly (p_TCB); |
jonathonfletcher | 0:5f46ebd8588e | 83 | rt_dispatch (p_TCB); |
jonathonfletcher | 0:5f46ebd8588e | 84 | } |
jonathonfletcher | 0:5f46ebd8588e | 85 | else { |
jonathonfletcher | 0:5f46ebd8588e | 86 | /* Store message in mailbox queue */ |
jonathonfletcher | 0:5f46ebd8588e | 87 | if (p_MCB->count == p_MCB->size) { |
jonathonfletcher | 0:5f46ebd8588e | 88 | /* No free message entry, wait for one. If message queue is full, */ |
jonathonfletcher | 0:5f46ebd8588e | 89 | /* then no task is waiting for message. The 'p_MCB->p_lnk' list */ |
jonathonfletcher | 0:5f46ebd8588e | 90 | /* pointer can now be reused for send message waits task list. */ |
jonathonfletcher | 0:5f46ebd8588e | 91 | if (timeout == 0) { |
jonathonfletcher | 0:5f46ebd8588e | 92 | return (OS_R_TMO); |
jonathonfletcher | 0:5f46ebd8588e | 93 | } |
jonathonfletcher | 0:5f46ebd8588e | 94 | if (p_MCB->p_lnk != NULL) { |
jonathonfletcher | 0:5f46ebd8588e | 95 | rt_put_prio ((P_XCB)p_MCB, os_tsk.tsk_run); |
jonathonfletcher | 0:5f46ebd8588e | 96 | } |
jonathonfletcher | 0:5f46ebd8588e | 97 | else { |
jonathonfletcher | 0:5f46ebd8588e | 98 | p_MCB->p_lnk = os_tsk.tsk_run; |
jonathonfletcher | 0:5f46ebd8588e | 99 | os_tsk.tsk_run->p_lnk = NULL; |
jonathonfletcher | 0:5f46ebd8588e | 100 | os_tsk.tsk_run->p_rlnk = (P_TCB)p_MCB; |
jonathonfletcher | 0:5f46ebd8588e | 101 | /* Task is waiting to send a message */ |
jonathonfletcher | 0:5f46ebd8588e | 102 | p_MCB->state = 2; |
jonathonfletcher | 0:5f46ebd8588e | 103 | } |
jonathonfletcher | 0:5f46ebd8588e | 104 | os_tsk.tsk_run->msg = p_msg; |
jonathonfletcher | 0:5f46ebd8588e | 105 | rt_block (timeout, WAIT_MBX); |
jonathonfletcher | 0:5f46ebd8588e | 106 | return (OS_R_TMO); |
jonathonfletcher | 0:5f46ebd8588e | 107 | } |
jonathonfletcher | 0:5f46ebd8588e | 108 | /* Yes, there is a free entry in a mailbox. */ |
jonathonfletcher | 0:5f46ebd8588e | 109 | p_MCB->msg[p_MCB->first] = p_msg; |
jonathonfletcher | 0:5f46ebd8588e | 110 | rt_inc (&p_MCB->count); |
jonathonfletcher | 0:5f46ebd8588e | 111 | if (++p_MCB->first == p_MCB->size) { |
jonathonfletcher | 0:5f46ebd8588e | 112 | p_MCB->first = 0; |
jonathonfletcher | 0:5f46ebd8588e | 113 | } |
jonathonfletcher | 0:5f46ebd8588e | 114 | } |
jonathonfletcher | 0:5f46ebd8588e | 115 | return (OS_R_OK); |
jonathonfletcher | 0:5f46ebd8588e | 116 | } |
jonathonfletcher | 0:5f46ebd8588e | 117 | |
jonathonfletcher | 0:5f46ebd8588e | 118 | |
jonathonfletcher | 0:5f46ebd8588e | 119 | /*--------------------------- rt_mbx_wait -----------------------------------*/ |
jonathonfletcher | 0:5f46ebd8588e | 120 | |
jonathonfletcher | 0:5f46ebd8588e | 121 | OS_RESULT rt_mbx_wait (OS_ID mailbox, void **message, U16 timeout) { |
jonathonfletcher | 0:5f46ebd8588e | 122 | /* Receive a message; possibly wait for it */ |
jonathonfletcher | 0:5f46ebd8588e | 123 | P_MCB p_MCB = mailbox; |
jonathonfletcher | 0:5f46ebd8588e | 124 | P_TCB p_TCB; |
jonathonfletcher | 0:5f46ebd8588e | 125 | |
jonathonfletcher | 0:5f46ebd8588e | 126 | /* If a message is available in the fifo buffer */ |
jonathonfletcher | 0:5f46ebd8588e | 127 | /* remove it from the fifo buffer and return. */ |
jonathonfletcher | 0:5f46ebd8588e | 128 | if (p_MCB->count) { |
jonathonfletcher | 0:5f46ebd8588e | 129 | *message = p_MCB->msg[p_MCB->last]; |
jonathonfletcher | 0:5f46ebd8588e | 130 | if (++p_MCB->last == p_MCB->size) { |
jonathonfletcher | 0:5f46ebd8588e | 131 | p_MCB->last = 0; |
jonathonfletcher | 0:5f46ebd8588e | 132 | } |
jonathonfletcher | 0:5f46ebd8588e | 133 | if (p_MCB->state == 2) { |
jonathonfletcher | 0:5f46ebd8588e | 134 | /* A task is waiting to send message */ |
jonathonfletcher | 0:5f46ebd8588e | 135 | p_TCB = rt_get_first ((P_XCB)p_MCB); |
jonathonfletcher | 0:5f46ebd8588e | 136 | if (p_MCB->p_lnk == NULL) { |
jonathonfletcher | 0:5f46ebd8588e | 137 | p_MCB->state = 0; |
jonathonfletcher | 0:5f46ebd8588e | 138 | } |
jonathonfletcher | 0:5f46ebd8588e | 139 | rt_ret_val(p_TCB, 0/*osOK*/); |
jonathonfletcher | 0:5f46ebd8588e | 140 | p_MCB->msg[p_MCB->first] = p_TCB->msg; |
jonathonfletcher | 0:5f46ebd8588e | 141 | if (++p_MCB->first == p_MCB->size) { |
jonathonfletcher | 0:5f46ebd8588e | 142 | p_MCB->first = 0; |
jonathonfletcher | 0:5f46ebd8588e | 143 | } |
jonathonfletcher | 0:5f46ebd8588e | 144 | rt_rmv_dly (p_TCB); |
jonathonfletcher | 0:5f46ebd8588e | 145 | rt_dispatch (p_TCB); |
jonathonfletcher | 0:5f46ebd8588e | 146 | } |
jonathonfletcher | 0:5f46ebd8588e | 147 | else { |
jonathonfletcher | 0:5f46ebd8588e | 148 | rt_dec (&p_MCB->count); |
jonathonfletcher | 0:5f46ebd8588e | 149 | } |
jonathonfletcher | 0:5f46ebd8588e | 150 | return (OS_R_OK); |
jonathonfletcher | 0:5f46ebd8588e | 151 | } |
jonathonfletcher | 0:5f46ebd8588e | 152 | /* No message available: wait for one */ |
jonathonfletcher | 0:5f46ebd8588e | 153 | if (timeout == 0) { |
jonathonfletcher | 0:5f46ebd8588e | 154 | return (OS_R_TMO); |
jonathonfletcher | 0:5f46ebd8588e | 155 | } |
jonathonfletcher | 0:5f46ebd8588e | 156 | if (p_MCB->p_lnk != NULL) { |
jonathonfletcher | 0:5f46ebd8588e | 157 | rt_put_prio ((P_XCB)p_MCB, os_tsk.tsk_run); |
jonathonfletcher | 0:5f46ebd8588e | 158 | } |
jonathonfletcher | 0:5f46ebd8588e | 159 | else { |
jonathonfletcher | 0:5f46ebd8588e | 160 | p_MCB->p_lnk = os_tsk.tsk_run; |
jonathonfletcher | 0:5f46ebd8588e | 161 | os_tsk.tsk_run->p_lnk = NULL; |
jonathonfletcher | 0:5f46ebd8588e | 162 | os_tsk.tsk_run->p_rlnk = (P_TCB)p_MCB; |
jonathonfletcher | 0:5f46ebd8588e | 163 | /* Task is waiting to receive a message */ |
jonathonfletcher | 0:5f46ebd8588e | 164 | p_MCB->state = 1; |
jonathonfletcher | 0:5f46ebd8588e | 165 | } |
jonathonfletcher | 0:5f46ebd8588e | 166 | rt_block(timeout, WAIT_MBX); |
jonathonfletcher | 0:5f46ebd8588e | 167 | return (OS_R_TMO); |
jonathonfletcher | 0:5f46ebd8588e | 168 | } |
jonathonfletcher | 0:5f46ebd8588e | 169 | |
jonathonfletcher | 0:5f46ebd8588e | 170 | |
jonathonfletcher | 0:5f46ebd8588e | 171 | /*--------------------------- rt_mbx_check ----------------------------------*/ |
jonathonfletcher | 0:5f46ebd8588e | 172 | |
jonathonfletcher | 0:5f46ebd8588e | 173 | OS_RESULT rt_mbx_check (OS_ID mailbox) { |
jonathonfletcher | 0:5f46ebd8588e | 174 | /* Check for free space in a mailbox. Returns the number of messages */ |
jonathonfletcher | 0:5f46ebd8588e | 175 | /* that can be stored to a mailbox. It returns 0 when mailbox is full. */ |
jonathonfletcher | 0:5f46ebd8588e | 176 | P_MCB p_MCB = mailbox; |
jonathonfletcher | 0:5f46ebd8588e | 177 | |
jonathonfletcher | 0:5f46ebd8588e | 178 | return (p_MCB->size - p_MCB->count); |
jonathonfletcher | 0:5f46ebd8588e | 179 | } |
jonathonfletcher | 0:5f46ebd8588e | 180 | |
jonathonfletcher | 0:5f46ebd8588e | 181 | |
jonathonfletcher | 0:5f46ebd8588e | 182 | /*--------------------------- isr_mbx_send ----------------------------------*/ |
jonathonfletcher | 0:5f46ebd8588e | 183 | |
jonathonfletcher | 0:5f46ebd8588e | 184 | void isr_mbx_send (OS_ID mailbox, void *p_msg) { |
jonathonfletcher | 0:5f46ebd8588e | 185 | /* Same function as "os_mbx_send", but to be called by ISRs. */ |
jonathonfletcher | 0:5f46ebd8588e | 186 | P_MCB p_MCB = mailbox; |
jonathonfletcher | 0:5f46ebd8588e | 187 | |
jonathonfletcher | 0:5f46ebd8588e | 188 | rt_psq_enq (p_MCB, (U32)p_msg); |
jonathonfletcher | 0:5f46ebd8588e | 189 | rt_psh_req (); |
jonathonfletcher | 0:5f46ebd8588e | 190 | } |
jonathonfletcher | 0:5f46ebd8588e | 191 | |
jonathonfletcher | 0:5f46ebd8588e | 192 | |
jonathonfletcher | 0:5f46ebd8588e | 193 | /*--------------------------- isr_mbx_receive -------------------------------*/ |
jonathonfletcher | 0:5f46ebd8588e | 194 | |
jonathonfletcher | 0:5f46ebd8588e | 195 | OS_RESULT isr_mbx_receive (OS_ID mailbox, void **message) { |
jonathonfletcher | 0:5f46ebd8588e | 196 | /* Receive a message in the interrupt function. The interrupt function */ |
jonathonfletcher | 0:5f46ebd8588e | 197 | /* should not wait for a message since this would block the rtx os. */ |
jonathonfletcher | 0:5f46ebd8588e | 198 | P_MCB p_MCB = mailbox; |
jonathonfletcher | 0:5f46ebd8588e | 199 | |
jonathonfletcher | 0:5f46ebd8588e | 200 | if (p_MCB->count) { |
jonathonfletcher | 0:5f46ebd8588e | 201 | /* A message is available in the fifo buffer. */ |
jonathonfletcher | 0:5f46ebd8588e | 202 | *message = p_MCB->msg[p_MCB->last]; |
jonathonfletcher | 0:5f46ebd8588e | 203 | if (p_MCB->state == 2) { |
jonathonfletcher | 0:5f46ebd8588e | 204 | /* A task is locked waiting to send message */ |
jonathonfletcher | 0:5f46ebd8588e | 205 | rt_psq_enq (p_MCB, 0); |
jonathonfletcher | 0:5f46ebd8588e | 206 | rt_psh_req (); |
jonathonfletcher | 0:5f46ebd8588e | 207 | } |
jonathonfletcher | 0:5f46ebd8588e | 208 | rt_dec (&p_MCB->count); |
jonathonfletcher | 0:5f46ebd8588e | 209 | if (++p_MCB->last == p_MCB->size) { |
jonathonfletcher | 0:5f46ebd8588e | 210 | p_MCB->last = 0; |
jonathonfletcher | 0:5f46ebd8588e | 211 | } |
jonathonfletcher | 0:5f46ebd8588e | 212 | return (OS_R_MBX); |
jonathonfletcher | 0:5f46ebd8588e | 213 | } |
jonathonfletcher | 0:5f46ebd8588e | 214 | return (OS_R_OK); |
jonathonfletcher | 0:5f46ebd8588e | 215 | } |
jonathonfletcher | 0:5f46ebd8588e | 216 | |
jonathonfletcher | 0:5f46ebd8588e | 217 | |
jonathonfletcher | 0:5f46ebd8588e | 218 | /*--------------------------- rt_mbx_psh ------------------------------------*/ |
jonathonfletcher | 0:5f46ebd8588e | 219 | |
jonathonfletcher | 0:5f46ebd8588e | 220 | void rt_mbx_psh (P_MCB p_CB, void *p_msg) { |
jonathonfletcher | 0:5f46ebd8588e | 221 | /* Store the message to the mailbox queue or pass it to task directly. */ |
jonathonfletcher | 0:5f46ebd8588e | 222 | P_TCB p_TCB; |
jonathonfletcher | 0:5f46ebd8588e | 223 | void *mem; |
jonathonfletcher | 0:5f46ebd8588e | 224 | |
jonathonfletcher | 0:5f46ebd8588e | 225 | switch (p_CB->state) { |
jonathonfletcher | 0:5f46ebd8588e | 226 | case 3: |
jonathonfletcher | 0:5f46ebd8588e | 227 | /* Task is waiting to allocate memory, remove it from the waiting list */ |
jonathonfletcher | 0:5f46ebd8588e | 228 | mem = rt_alloc_box(p_msg); |
jonathonfletcher | 0:5f46ebd8588e | 229 | if (mem == NULL) break; |
jonathonfletcher | 0:5f46ebd8588e | 230 | p_TCB = rt_get_first ((P_XCB)p_CB); |
jonathonfletcher | 0:5f46ebd8588e | 231 | if (p_CB->p_lnk == NULL) { |
jonathonfletcher | 0:5f46ebd8588e | 232 | p_CB->state = 0; |
jonathonfletcher | 0:5f46ebd8588e | 233 | } |
jonathonfletcher | 0:5f46ebd8588e | 234 | rt_ret_val(p_TCB, (U32)mem); |
jonathonfletcher | 0:5f46ebd8588e | 235 | p_TCB->state = READY; |
jonathonfletcher | 0:5f46ebd8588e | 236 | rt_rmv_dly (p_TCB); |
jonathonfletcher | 0:5f46ebd8588e | 237 | rt_put_prio (&os_rdy, p_TCB); |
jonathonfletcher | 0:5f46ebd8588e | 238 | break; |
jonathonfletcher | 0:5f46ebd8588e | 239 | case 2: |
jonathonfletcher | 0:5f46ebd8588e | 240 | /* Task is waiting to send a message, remove it from the waiting list */ |
jonathonfletcher | 0:5f46ebd8588e | 241 | p_TCB = rt_get_first ((P_XCB)p_CB); |
jonathonfletcher | 0:5f46ebd8588e | 242 | if (p_CB->p_lnk == NULL) { |
jonathonfletcher | 0:5f46ebd8588e | 243 | p_CB->state = 0; |
jonathonfletcher | 0:5f46ebd8588e | 244 | } |
jonathonfletcher | 0:5f46ebd8588e | 245 | rt_ret_val(p_TCB, 0/*osOK*/); |
jonathonfletcher | 0:5f46ebd8588e | 246 | p_CB->msg[p_CB->first] = p_TCB->msg; |
jonathonfletcher | 0:5f46ebd8588e | 247 | rt_inc (&p_CB->count); |
jonathonfletcher | 0:5f46ebd8588e | 248 | if (++p_CB->first == p_CB->size) { |
jonathonfletcher | 0:5f46ebd8588e | 249 | p_CB->first = 0; |
jonathonfletcher | 0:5f46ebd8588e | 250 | } |
jonathonfletcher | 0:5f46ebd8588e | 251 | p_TCB->state = READY; |
jonathonfletcher | 0:5f46ebd8588e | 252 | rt_rmv_dly (p_TCB); |
jonathonfletcher | 0:5f46ebd8588e | 253 | rt_put_prio (&os_rdy, p_TCB); |
jonathonfletcher | 0:5f46ebd8588e | 254 | break; |
jonathonfletcher | 0:5f46ebd8588e | 255 | case 1: |
jonathonfletcher | 0:5f46ebd8588e | 256 | /* Task is waiting for a message, pass the message to the task directly */ |
jonathonfletcher | 0:5f46ebd8588e | 257 | p_TCB = rt_get_first ((P_XCB)p_CB); |
jonathonfletcher | 0:5f46ebd8588e | 258 | if (p_CB->p_lnk == NULL) { |
jonathonfletcher | 0:5f46ebd8588e | 259 | p_CB->state = 0; |
jonathonfletcher | 0:5f46ebd8588e | 260 | } |
jonathonfletcher | 0:5f46ebd8588e | 261 | rt_ret_val2(p_TCB, 0x10/*osEventMessage*/, (U32)p_msg); |
jonathonfletcher | 0:5f46ebd8588e | 262 | p_TCB->state = READY; |
jonathonfletcher | 0:5f46ebd8588e | 263 | rt_rmv_dly (p_TCB); |
jonathonfletcher | 0:5f46ebd8588e | 264 | rt_put_prio (&os_rdy, p_TCB); |
jonathonfletcher | 0:5f46ebd8588e | 265 | break; |
jonathonfletcher | 0:5f46ebd8588e | 266 | default: |
jonathonfletcher | 0:5f46ebd8588e | 267 | /* No task is waiting for a message, store it to the mailbox queue */ |
jonathonfletcher | 0:5f46ebd8588e | 268 | if (p_CB->count < p_CB->size) { |
jonathonfletcher | 0:5f46ebd8588e | 269 | p_CB->msg[p_CB->first] = p_msg; |
jonathonfletcher | 0:5f46ebd8588e | 270 | rt_inc (&p_CB->count); |
jonathonfletcher | 0:5f46ebd8588e | 271 | if (++p_CB->first == p_CB->size) { |
jonathonfletcher | 0:5f46ebd8588e | 272 | p_CB->first = 0; |
jonathonfletcher | 0:5f46ebd8588e | 273 | } |
jonathonfletcher | 0:5f46ebd8588e | 274 | } |
jonathonfletcher | 0:5f46ebd8588e | 275 | else { |
jonathonfletcher | 0:5f46ebd8588e | 276 | os_error (OS_ERR_MBX_OVF); |
jonathonfletcher | 0:5f46ebd8588e | 277 | } |
jonathonfletcher | 0:5f46ebd8588e | 278 | break; |
jonathonfletcher | 0:5f46ebd8588e | 279 | } |
jonathonfletcher | 0:5f46ebd8588e | 280 | } |
jonathonfletcher | 0:5f46ebd8588e | 281 | |
jonathonfletcher | 0:5f46ebd8588e | 282 | /*---------------------------------------------------------------------------- |
jonathonfletcher | 0:5f46ebd8588e | 283 | * end of file |
jonathonfletcher | 0:5f46ebd8588e | 284 | *---------------------------------------------------------------------------*/ |
jonathonfletcher | 0:5f46ebd8588e | 285 |