📄 queue.lst
字号:
##############################################################################
# #
# IAR MSP430 C/C++ Compiler V3.41A/W32 22/Apr/2006 00:25:16 #
# Copyright 1996-2006 IAR Systems. All rights reserved. #
# #
# __rt_version = 2 #
# __double_size = 32 #
# __reg_r4 = free #
# __reg_r5 = free #
# __pic = no #
# __core = 64kb #
# Source file = C:\MSP430F169_Eval_Port\FreeRTOSv401\Source\queue.c #
# Command line = C:\MSP430F169_Eval_Port\FreeRTOSv401\Source\queue.c #
# -D ROWLEY_MSP430 -D IAR_MSP430 -lC #
# C:\MSP430F169_Eval_Port\FreeRTOSv401\Debug\List\ -lA #
# C:\MSP430F169_Eval_Port\FreeRTOSv401\Debug\List\ #
# --remarks -o C:\MSP430F169_Eval_Port\FreeRTOSv401\Debu #
# g\Obj\ -s2 --no_cse --no_unroll --no_inline #
# --no_code_motion --no_tbaa --debug -e #
# --migration_preprocessor_extensions --double=32 -I #
# C:\MSP430F169_Eval_Port\FreeRTOSv401\Demo\Common\Inclu #
# de\ -I C:\MSP430F169_Eval_Port\FreeRTOSv401\Source\Inc #
# lude\ -I C:\MSP430F169_Eval_Port\FreeRTOSv401\Demo\MSP #
# 430_IAR\ -I C:\MSP430F169_Eval_Port\FreeRTOSv401\Sourc #
# e\portable\msp430f1611\ -I "C:\Program Files\IAR #
# Systems\Embedded Workbench 4.0\430\INC\" -I #
# "C:\Program Files\IAR Systems\Embedded Workbench #
# 4.0\430\INC\CLIB\" #
# List file = C:\MSP430F169_Eval_Port\FreeRTOSv401\Debug\List\queue. #
# lst #
# Object file = C:\MSP430F169_Eval_Port\FreeRTOSv401\Debug\Obj\queue.r #
# 43 #
# #
# #
##############################################################################
C:\MSP430F169_Eval_Port\FreeRTOSv401\Source\queue.c
1 /*
2 FreeRTOS V4.0.1 - Copyright (C) 2003-2006 Richard Barry.
3
4 This file is part of the FreeRTOS distribution.
5
6 FreeRTOS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 FreeRTOS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with FreeRTOS; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
20 A special exception to the GPL can be applied should you wish to distribute
21 a combined work that includes FreeRTOS, without being obliged to provide
22 the source code for any proprietary components. See the licensing section
23 of http://www.FreeRTOS.org for full details of how and when the exception
24 can be applied.
25
26 ***************************************************************************
27 See http://www.FreeRTOS.org for documentation, latest information, license
28 and contact details. Please ensure to read the configuration and relevant
29 port sections of the online documentation.
30 ***************************************************************************
31 */
32
33 /*
34 Changes from V1.01
35
36 + More use of 8bit data types.
37 + Function name prefixes changed where the data type returned has changed.
38
39 Changed from V2.0.0
40
41 + Added the queue locking mechanism and make more use of the scheduler
42 suspension feature to minimise the time interrupts have to be disabled
43 when accessing a queue.
44
45 Changed from V2.2.0
46
47 + Explicit use of 'signed' qualifier on portCHAR types added.
48
49 Changes from V3.0.0
50
51 + API changes as described on the FreeRTOS.org WEB site.
52
53 Changes from V3.2.3
54
55 + Added the queue functions that can be used from co-routines.
56
57 */
58
59 #include <stdlib.h>
60 #include <string.h>
61 #include "FreeRTOS.h"
62 #include "task.h"
63 #include "croutine.h"
64
65 /*-----------------------------------------------------------
66 * PUBLIC LIST API documented in list.h
67 *----------------------------------------------------------*/
68
69 /* Constants used with the cRxLock and cTxLock structure members. */
70 #define queueUNLOCKED ( ( signed portBASE_TYPE ) -1 )
71
72 /*
73 * Definition of the queue used by the scheduler.
74 * Items are queued by copy, not reference.
75 */
76 typedef struct QueueDefinition
77 {
78 signed portCHAR *pcHead; /*< Points to the beginning of the queue storage area. */
79 signed portCHAR *pcTail; /*< Points to the byte at the end of the queue storage area. Once more byte is allocated than necessary to store the queue items, this is used as a marker. */
80
81 signed portCHAR *pcWriteTo; /*< Points to the free next place in the storage area. */
82 signed portCHAR *pcReadFrom; /*< Points to the last place that a queued item was read from. */
83
84 xList xTasksWaitingToSend; /*< List of tasks that are blocked waiting to post onto this queue. Stored in priority order. */
85 xList xTasksWaitingToReceive; /*< List of tasks that are blocked waiting to read from this queue. Stored in priority order. */
86
87 unsigned portBASE_TYPE uxMessagesWaiting;/*< The number of items currently in the queue. */
88 unsigned portBASE_TYPE uxLength; /*< The length of the queue defined as the number of items it will hold, not the number of bytes. */
89 unsigned portBASE_TYPE uxItemSize; /*< The size of each items that the queue will hold. */
90
91 signed portBASE_TYPE xRxLock; /*< Stores the number of items received from the queue (removed from the queue) while the queue was locked. Set to queueUNLOCKED when the queue is not locked. */
92 signed portBASE_TYPE xTxLock; /*< Stores the number of items transmitted to the queue (added to the queue) while the queue was locked. Set to queueUNLOCKED when the queue is not locked. */
93 } xQUEUE;
94 /*-----------------------------------------------------------*/
95
96 /*
97 * Inside this file xQueueHandle is a pointer to a xQUEUE structure.
98 * To keep the definition private the API header file defines it as a
99 * pointer to void.
100 */
101 typedef xQUEUE * xQueueHandle;
102
103 /*
104 * Prototypes for public functions are included here so we don't have to
105 * include the API header file (as it defines xQueueHandle differently). These
106 * functions are documented in the API header file.
107 */
108 xQueueHandle xQueueCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBASE_TYPE uxItemSize );
109 signed portBASE_TYPE xQueueSend( xQueueHandle xQueue, const void * pvItemToQueue, portTickType xTicksToWait );
110 unsigned portBASE_TYPE uxQueueMessagesWaiting( xQueueHandle pxQueue );
111 void vQueueDelete( xQueueHandle xQueue );
112 signed portBASE_TYPE xQueueSendFromISR( xQueueHandle pxQueue, const void *pvItemToQueue, signed portBASE_TYPE xTaskPreviouslyWoken );
113 signed portBASE_TYPE xQueueReceive( xQueueHandle pxQueue, void *pvBuffer, portTickType xTicksToWait );
114 signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle pxQueue, void *pvBuffer, signed portBASE_TYPE *pxTaskWoken );
115
116 #if configUSE_CO_ROUTINES == 1
117 signed portBASE_TYPE xQueueCRSendFromISR( xQueueHandle pxQueue, const void *pvItemToQueue, signed portBASE_TYPE xCoRoutinePreviouslyWoken );
118 signed portBASE_TYPE xQueueCRReceiveFromISR( xQueueHandle pxQueue, void *pvBuffer, signed portBASE_TYPE *pxTaskWoken );
119 signed portBASE_TYPE xQueueCRSend( xQueueHandle pxQueue, const void *pvItemToQueue, portTickType xTicksToWait );
120 signed portBASE_TYPE xQueueCRReceive( xQueueHandle pxQueue, void *pvBuffer, portTickType xTicksToWait );
121 #endif
122
123 /*
124 * Unlocks a queue locked by a call to prvLockQueue. Locking a queue does not
125 * prevent an ISR from adding or removing items to the queue, but does prevent
126 * an ISR from removing tasks from the queue event lists. If an ISR finds a
127 * queue is locked it will instead increment the appropriate queue lock count
128 * to indicate that a task may require unblocking. When the queue in unlocked
129 * these lock counts are inspected, and the appropriate action taken.
130 */
131 static signed portBASE_TYPE prvUnlockQueue( xQueueHandle pxQueue );
132
133 /*
134 * Uses a critical section to determine if there is any data in a queue.
135 *
136 * @return pdTRUE if the queue contains no items, otherwise pdFALSE.
137 */
138 static signed portBASE_TYPE prvIsQueueEmpty( const xQueueHandle pxQueue );
139
140 /*
141 * Uses a critical section to determine if there is any space in a queue.
142 *
143 * @return pdTRUE if there is no space, otherwise pdFALSE;
144 */
145 static signed portBASE_TYPE prvIsQueueFull( const xQueueHandle pxQueue );
146
147 /*
148 * Macro that copies an item into the queue. This is done by copying the item
149 * byte for byte, not by reference. Updates the queue state to ensure it's
150 * integrity after the copy.
151 */
152 #define prvCopyQueueData( pxQueue, pvItemToQueue ) \
153 { \
154 memcpy( ( void * ) pxQueue->pcWriteTo, pvItemToQueue, ( unsigned ) pxQueue->uxItemSize ); \
155 ++( pxQueue->uxMessagesWaiting ); \
156 pxQueue->pcWriteTo += pxQueue->uxItemSize; \
157 if( pxQueue->pcWriteTo >= pxQueue->pcTail ) \
158 { \
159 pxQueue->pcWriteTo = pxQueue->pcHead; \
160 } \
161 }
162 /*-----------------------------------------------------------*/
163
164 /*
165 * Macro to mark a queue as locked. Locking a queue prevents an ISR from
166 * accessing the queue event lists.
167 */
168 #define prvLockQueue( pxQueue ) \
169 { \
170 taskENTER_CRITICAL(); \
171 ++( pxQueue->xRxLock ); \
172 ++( pxQueue->xTxLock ); \
173 taskEXIT_CRITICAL(); \
174 }
175 /*-----------------------------------------------------------*/
176
177
178 /*-----------------------------------------------------------
179 * PUBLIC QUEUE MANAGEMENT API documented in queue.h
180 *----------------------------------------------------------*/
181
\ In segment CODE, align 2
182 xQueueHandle xQueueCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBASE_TYPE uxItemSize )
\ xQueueCreate:
183 {
\ 000000 0A12 PUSH.W R10
\ 000002 0B12 PUSH.W R11
\ 000004 0812 PUSH.W R8
\ 000006 0912 PUSH.W R9
\ 000008 0612 PUSH.W R6
\ 00000A 0A4C MOV.W R12, R10
\ 00000C 0B4E MOV.W R14, R11
184 xQUEUE *pxNewQueue;
185 size_t xQueueSizeInBytes;
186
187 /* Allocate the new queue structure. */
188 if( uxQueueLength > ( unsigned portBASE_TYPE ) 0 )
\ 00000E 0A93 CMP.W #0x0, R10
\ 000010 4024 JEQ ??xQueueCreate_0
189 {
190 pxNewQueue = ( xQUEUE * ) pvPortMalloc( sizeof( xQUEUE ) );
\ 000012 3C402600 MOV.W #0x26, R12
\ 000016 B012.... CALL #pvPortMalloc
\ 00001A 084C MOV.W R12, R8
191 if( pxNewQueue != NULL )
\ 00001C 0893 CMP.W #0x0, R8
\ 00001E 3924 JEQ ??xQueueCreate_0
192 {
193 /* Create the list of pointers to queue items. The queue is one byte
194 longer than asked for to make wrap checking easier/faster. */
195 xQueueSizeInBytes = ( size_t ) ( uxQueueLength * uxItemSize ) + ( size_t ) 1;
\ 000020 0C4A MOV.W R10, R12
\ 000022 0E4B MOV.W R11, R14
\ 000024 B012.... CALL #?Mul16
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -