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