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