📄 queue.lst
字号:
##############################################################################
# #
# IAR ARM ANSI C/C++ Compiler V4.30A/W32 KICKSTART 14/Dec/2005 14:41:47 #
# Copyright 1999-2005 IAR Systems. All rights reserved. #
# #
# Cpu mode = interwork #
# Endian = little #
# Stack alignment = 4 #
# Source file = D:\board\FreeRTOSV3.2.3\FreeRTOS\Source\queue.c #
# Command line = D:\board\FreeRTOSV3.2.3\FreeRTOS\Source\queue.c -D #
# _NDEBUG -D STR71X_IAR -lC #
# D:\board\FreeRTOSV3.2.3\FreeRTOS\Demo\ARM7_STR71x_IA #
# R\binary\List\ --diag_suppress pe191,pa082 -o #
# D:\board\FreeRTOSV3.2.3\FreeRTOS\Demo\ARM7_STR71x_IA #
# R\binary\Obj\ -s9 --no_clustering --cpu_mode thumb #
# --endian little --cpu ARM7TDMI --stack_align 4 #
# --interwork -e --require_prototypes --fpu None #
# --dlib_config "C:\Program Files\IAR #
# Systems\Embedded Workbench 4.0 #
# Kickstart\arm\LIB\dl4tptinl8n.h" -I #
# D:\board\FreeRTOSV3.2.3\FreeRTOS\Demo\ARM7_STR71x_IA #
# R\ -I D:\board\FreeRTOSV3.2.3\FreeRTOS\Demo\ARM7_STR #
# 71x_IAR\library\include\ -I #
# D:\board\FreeRTOSV3.2.3\FreeRTOS\Demo\ARM7_STR71x_IA #
# R\..\common\include\ -I D:\board\FreeRTOSV3.2.3\Free #
# RTOS\Demo\ARM7_STR71x_IAR\..\..\source\include\ -I #
# "C:\Program Files\IAR Systems\Embedded Workbench #
# 4.0 Kickstart\arm\INC\" #
# List file = D:\board\FreeRTOSV3.2.3\FreeRTOS\Demo\ARM7_STR71x_IA #
# R\binary\List\queue.lst #
# Object file = D:\board\FreeRTOSV3.2.3\FreeRTOS\Demo\ARM7_STR71x_IA #
# R\binary\Obj\queue.r79 #
# #
# #
##############################################################################
D:\board\FreeRTOSV3.2.3\FreeRTOS\Source\queue.c
1 /*
2 FreeRTOS V3.2.3 - Copyright (C) 2003-2005 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 */
54
55 #include <stdlib.h>
56 #include <string.h>
57 #include "FreeRTOS.h"
58 #include "task.h"
59 #include "list.h"
60
61 /*-----------------------------------------------------------
62 * PUBLIC LIST API documented in list.h
63 *----------------------------------------------------------*/
64
65 /* Constants used with the cRxLock and cTxLock structure members. */
66 #define queueUNLOCKED ( ( signed portBASE_TYPE ) -1 )
67
68 /*
69 * Definition of the queue used by the scheduler.
70 * Items are queued by copy, not reference.
71 */
72 typedef struct QueueDefinition
73 {
74 signed portCHAR *pcHead; /*< Points to the beginning of the queue storage area. */
75 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. */
76
77 signed portCHAR *pcWriteTo; /*< Points to the free next place in the storage area. */
78 signed portCHAR *pcReadFrom; /*< Points to the last place that a queued item was read from. */
79
80 xList xTasksWaitingToSend; /*< List of tasks that are blocked waiting to post onto this queue. Stored in priority order. */
81 xList xTasksWaitingToReceive; /*< List of tasks that are blocked waiting to read from this queue. Stored in priority order. */
82
83 unsigned portBASE_TYPE uxMessagesWaiting;/*< The number of items currently in the queue. */
84 unsigned portBASE_TYPE uxLength; /*< The length of the queue defined as the number of items it will hold, not the number of bytes. */
85 unsigned portBASE_TYPE uxItemSize; /*< The size of each items that the queue will hold. */
86
87 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. */
88 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. */
89 } xQUEUE;
90 /*-----------------------------------------------------------*/
91
92 /*
93 * Inside this file xQueueHandle is a pointer to a xQUEUE structure.
94 * To keep the definition private the API header file defines it as a
95 * pointer to void.
96 */
97 typedef xQUEUE * xQueueHandle;
98
99 /*
100 * Prototypes for public functions are included here so we don't have to
101 * include the API header file (as it defines xQueueHandle differently). These
102 * functions are documented in the API header file.
103 */
104 xQueueHandle xQueueCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBASE_TYPE uxItemSize );
105 signed portBASE_TYPE xQueueSend( xQueueHandle xQueue, const void * pvItemToQueue, portTickType xTicksToWait );
106 unsigned portBASE_TYPE uxQueueMessagesWaiting( xQueueHandle pxQueue );
107 void vQueueDelete( xQueueHandle xQueue );
108 signed portBASE_TYPE xQueueSendFromISR( xQueueHandle pxQueue, const void *pvItemToQueue, signed portBASE_TYPE xTaskPreviouslyWoken );
109 signed portBASE_TYPE xQueueReceive( xQueueHandle pxQueue, void *pcBuffer, portTickType xTicksToWait );
110 signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle pxQueue, void *pcBuffer, signed portBASE_TYPE *pxTaskWoken );
111
112 /*
113 * Unlocks a queue locked by a call to prvLockQueue. Locking a queue does not
114 * prevent an ISR from adding or removing items to the queue, but does prevent
115 * an ISR from removing tasks from the queue event lists. If an ISR finds a
116 * queue is locked it will instead increment the appropriate queue lock count
117 * to indicate that a task may require unblocking. When the queue in unlocked
118 * these lock counts are inspected, and the appropriate action taken.
119 */
120 static signed portBASE_TYPE prvUnlockQueue( xQueueHandle pxQueue );
121
122 /*
123 * Uses a critical section to determine if there is any data in a queue.
124 *
125 * @return pdTRUE if the queue contains no items, otherwise pdFALSE.
126 */
127 static signed portBASE_TYPE prvIsQueueEmpty( const xQueueHandle pxQueue );
128
129 /*
130 * Uses a critical section to determine if there is any space in a queue.
131 *
132 * @return pdTRUE if there is no space, otherwise pdFALSE;
133 */
134 static signed portBASE_TYPE prvIsQueueFull( const xQueueHandle pxQueue );
135
136 /*
137 * Macro that copies an item into the queue. This is done by copying the item
138 * byte for byte, not by reference. Updates the queue state to ensure it's
139 * integrity after the copy.
140 */
141 #define prvCopyQueueData( pxQueue, pvItemToQueue ) \
142 { \
143 memcpy( ( void * ) pxQueue->pcWriteTo, pvItemToQueue, ( unsigned ) pxQueue->uxItemSize ); \
144 ++( pxQueue->uxMessagesWaiting ); \
145 pxQueue->pcWriteTo += pxQueue->uxItemSize; \
146 if( pxQueue->pcWriteTo >= pxQueue->pcTail ) \
147 { \
148 pxQueue->pcWriteTo = pxQueue->pcHead; \
149 } \
150 }
151 /*-----------------------------------------------------------*/
152
153 /*
154 * Macro to mark a queue as locked. Locking a queue prevents an ISR from
155 * accessing the queue event lists.
156 */
157 #define prvLockQueue( pxQueue ) \
158 { \
159 taskENTER_CRITICAL(); \
160 ++( pxQueue->xRxLock ); \
161 ++( pxQueue->xTxLock ); \
162 taskEXIT_CRITICAL(); \
163 }
164 /*-----------------------------------------------------------*/
165
166
167 /*-----------------------------------------------------------
168 * PUBLIC QUEUE MANAGEMENT API documented in queue.h
169 *----------------------------------------------------------*/
170
\ In segment CODE, align 4, keep-with-next
171 xQueueHandle xQueueCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBASE_TYPE uxItemSize )
172 {
\ xQueueCreate:
\ 00000000 F0B5 PUSH {R4-R7,LR}
\ 00000002 041C MOV R4,R0
\ 00000004 0D1C MOV R5,R1
173 xQUEUE *pxNewQueue;
174 size_t xQueueSizeInBytes;
175
176 /* Allocate the new queue structure. */
177 if( uxQueueLength > ( unsigned portBASE_TYPE ) 0 )
\ 00000006 0028 CMP R0,#+0
\ 00000008 2AD0 BEQ ??xQueueCreate_0
178 {
179 pxNewQueue = ( xQUEUE * ) pvPortMalloc( sizeof( xQUEUE ) );
\ 0000000A 6420 MOV R0,#+0x64
\ 0000000C ........ _BLF pvPortMalloc,pvPortMalloc??rT
\ 00000010 061C MOV R6,R0
180 if( pxNewQueue != NULL )
\ 00000012 25D0 BEQ ??xQueueCreate_0
181 {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -