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