A library implementing IEEE 802.15.4 PHY functionality for the MCR20A transceiver. The PHY sublayer provides two services: the PHY data service and the PHY management service interfacing to the PHY sublayer management entity (PLME) service access point (SAP) (known as PLME-SAP). The PHY data service enables the transmission and reception of PHY protocol data units (PSDUs) over the media (radio).

Fork of fsl_phy_mcr20a by Freescale

The Freescale PHY Layer deals with the physical burst which is to be sent and/or received. It performs modulation and demodulation, transmitter and receiver switching, fragmentation, scrambling, interleaving, and error correction coding. The communication to the upper protocol layers is carried out through the Layer 1 Interface.

The PHY Layer is capable of executing the following sequences:

  • I (Idle)
  • R (Receive Sequence conditionally followed by a TxAck)
  • T (Transmit Sequence)
  • C (Standalone CCA)
  • CCCA (Continuous CCA)
  • TR (Transmit/Receive Sequence - transmit unconditionally followed by either an R or RxAck)

In addition to these sequences the PHY Layer also integrates a packet processor which determines whether the packet is MAC-compliant, and if it is, whether it is addressed to the end device. Another feature of the packet processor is Source Address Matching which can be viewed as an extension of packet filtering; however its function is very specific to its intended application (data-polling and indirect queue management by a PAN Coordinator).

Documentation

MCR20A PHY Reference Manual

Committer:
andreikovacs
Date:
Tue Aug 18 12:41:42 2015 +0000
Revision:
0:764779eedf2d
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
andreikovacs 0:764779eedf2d 1 /*!
andreikovacs 0:764779eedf2d 2 * Copyright (c) 2015, Freescale Semiconductor, Inc.
andreikovacs 0:764779eedf2d 3 * All rights reserved.
andreikovacs 0:764779eedf2d 4 *
andreikovacs 0:764779eedf2d 5 * \file GenericList.c
andreikovacs 0:764779eedf2d 6 * This is the source file for the linked lists part of the Utils package.
andreikovacs 0:764779eedf2d 7 *
andreikovacs 0:764779eedf2d 8 * Redistribution and use in source and binary forms, with or without modification,
andreikovacs 0:764779eedf2d 9 * are permitted provided that the following conditions are met:
andreikovacs 0:764779eedf2d 10 *
andreikovacs 0:764779eedf2d 11 * o Redistributions of source code must retain the above copyright notice, this list
andreikovacs 0:764779eedf2d 12 * of conditions and the following disclaimer.
andreikovacs 0:764779eedf2d 13 *
andreikovacs 0:764779eedf2d 14 * o Redistributions in binary form must reproduce the above copyright notice, this
andreikovacs 0:764779eedf2d 15 * list of conditions and the following disclaimer in the documentation and/or
andreikovacs 0:764779eedf2d 16 * other materials provided with the distribution.
andreikovacs 0:764779eedf2d 17 *
andreikovacs 0:764779eedf2d 18 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
andreikovacs 0:764779eedf2d 19 * contributors may be used to endorse or promote products derived from this
andreikovacs 0:764779eedf2d 20 * software without specific prior written permission.
andreikovacs 0:764779eedf2d 21 *
andreikovacs 0:764779eedf2d 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
andreikovacs 0:764779eedf2d 23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
andreikovacs 0:764779eedf2d 24 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
andreikovacs 0:764779eedf2d 25 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
andreikovacs 0:764779eedf2d 26 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
andreikovacs 0:764779eedf2d 27 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
andreikovacs 0:764779eedf2d 28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
andreikovacs 0:764779eedf2d 29 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
andreikovacs 0:764779eedf2d 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
andreikovacs 0:764779eedf2d 31 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
andreikovacs 0:764779eedf2d 32 */
andreikovacs 0:764779eedf2d 33
andreikovacs 0:764779eedf2d 34 /*! *********************************************************************************
andreikovacs 0:764779eedf2d 35 *************************************************************************************
andreikovacs 0:764779eedf2d 36 * Include
andreikovacs 0:764779eedf2d 37 *************************************************************************************
andreikovacs 0:764779eedf2d 38 ********************************************************************************** */
andreikovacs 0:764779eedf2d 39 #include "GenericList.h"
andreikovacs 0:764779eedf2d 40 #include "mbedAbstraction.h"
andreikovacs 0:764779eedf2d 41
andreikovacs 0:764779eedf2d 42
andreikovacs 0:764779eedf2d 43
andreikovacs 0:764779eedf2d 44 /*! *********************************************************************************
andreikovacs 0:764779eedf2d 45 *************************************************************************************
andreikovacs 0:764779eedf2d 46 * Public functions
andreikovacs 0:764779eedf2d 47 *************************************************************************************
andreikovacs 0:764779eedf2d 48 ********************************************************************************** */
andreikovacs 0:764779eedf2d 49 /*! *********************************************************************************
andreikovacs 0:764779eedf2d 50 * \brief Initialises the list descriptor.
andreikovacs 0:764779eedf2d 51 *
andreikovacs 0:764779eedf2d 52 * \param[in] list - List handle to init.
andreikovacs 0:764779eedf2d 53 * max - Maximum number of elements in list. 0 for unlimited.
andreikovacs 0:764779eedf2d 54 *
andreikovacs 0:764779eedf2d 55 * \return void.
andreikovacs 0:764779eedf2d 56 *
andreikovacs 0:764779eedf2d 57 * \pre
andreikovacs 0:764779eedf2d 58 *
andreikovacs 0:764779eedf2d 59 * \post
andreikovacs 0:764779eedf2d 60 *
andreikovacs 0:764779eedf2d 61 * \remarks
andreikovacs 0:764779eedf2d 62 *
andreikovacs 0:764779eedf2d 63 ********************************************************************************** */
andreikovacs 0:764779eedf2d 64
andreikovacs 0:764779eedf2d 65 void ListInit(listHandle_t list, uint32_t max)
andreikovacs 0:764779eedf2d 66 {
andreikovacs 0:764779eedf2d 67 list->head = NULL;
andreikovacs 0:764779eedf2d 68 list->tail = NULL;
andreikovacs 0:764779eedf2d 69 list->max = max;
andreikovacs 0:764779eedf2d 70 list->size = 0;
andreikovacs 0:764779eedf2d 71 }
andreikovacs 0:764779eedf2d 72
andreikovacs 0:764779eedf2d 73 /*! *********************************************************************************
andreikovacs 0:764779eedf2d 74 * \brief Gets the list that contains the given element.
andreikovacs 0:764779eedf2d 75 *
andreikovacs 0:764779eedf2d 76 * \param[in] element - Handle of the element.
andreikovacs 0:764779eedf2d 77 *
andreikovacs 0:764779eedf2d 78 * \return NULL if element is orphan.
andreikovacs 0:764779eedf2d 79 * Handle of the list the element is inserted into.
andreikovacs 0:764779eedf2d 80 *
andreikovacs 0:764779eedf2d 81 * \pre
andreikovacs 0:764779eedf2d 82 *
andreikovacs 0:764779eedf2d 83 * \post
andreikovacs 0:764779eedf2d 84 *
andreikovacs 0:764779eedf2d 85 * \remarks
andreikovacs 0:764779eedf2d 86 *
andreikovacs 0:764779eedf2d 87 ********************************************************************************** */
andreikovacs 0:764779eedf2d 88 listHandle_t ListGetList(listElementHandle_t elementHandle)
andreikovacs 0:764779eedf2d 89 {
andreikovacs 0:764779eedf2d 90 return elementHandle->list;
andreikovacs 0:764779eedf2d 91 }
andreikovacs 0:764779eedf2d 92
andreikovacs 0:764779eedf2d 93 /*! *********************************************************************************
andreikovacs 0:764779eedf2d 94 * \brief Links element to the tail of the list.
andreikovacs 0:764779eedf2d 95 *
andreikovacs 0:764779eedf2d 96 * \param[in] list - ID of list to insert into.
andreikovacs 0:764779eedf2d 97 * element - element to add
andreikovacs 0:764779eedf2d 98 *
andreikovacs 0:764779eedf2d 99 * \return gListFull_c if list is full.
andreikovacs 0:764779eedf2d 100 * gListOk_c if insertion was successful.
andreikovacs 0:764779eedf2d 101 *
andreikovacs 0:764779eedf2d 102 * \pre
andreikovacs 0:764779eedf2d 103 *
andreikovacs 0:764779eedf2d 104 * \post
andreikovacs 0:764779eedf2d 105 *
andreikovacs 0:764779eedf2d 106 * \remarks
andreikovacs 0:764779eedf2d 107 *
andreikovacs 0:764779eedf2d 108 ********************************************************************************** */
andreikovacs 0:764779eedf2d 109 listStatus_t ListAddTail(listHandle_t list, listElementHandle_t element)
andreikovacs 0:764779eedf2d 110 {
andreikovacs 0:764779eedf2d 111 OSA_EnterCritical(kCriticalDisableInt);
andreikovacs 0:764779eedf2d 112
andreikovacs 0:764779eedf2d 113 if( (list->max != 0) && (list->max == list->size) )
andreikovacs 0:764779eedf2d 114 {
andreikovacs 0:764779eedf2d 115 OSA_ExitCritical(kCriticalDisableInt);
andreikovacs 0:764779eedf2d 116 return gListFull_c;
andreikovacs 0:764779eedf2d 117 }
andreikovacs 0:764779eedf2d 118
andreikovacs 0:764779eedf2d 119 if(list->size == 0)
andreikovacs 0:764779eedf2d 120 {
andreikovacs 0:764779eedf2d 121 list->head = element;
andreikovacs 0:764779eedf2d 122 }
andreikovacs 0:764779eedf2d 123 else
andreikovacs 0:764779eedf2d 124 {
andreikovacs 0:764779eedf2d 125 list->tail->next = element;
andreikovacs 0:764779eedf2d 126 }
andreikovacs 0:764779eedf2d 127 element->prev = list->tail;
andreikovacs 0:764779eedf2d 128 element->next = NULL;
andreikovacs 0:764779eedf2d 129 element->list = list;
andreikovacs 0:764779eedf2d 130 list->tail = element;
andreikovacs 0:764779eedf2d 131 list->size++;
andreikovacs 0:764779eedf2d 132
andreikovacs 0:764779eedf2d 133 OSA_ExitCritical(kCriticalDisableInt);
andreikovacs 0:764779eedf2d 134 return gListOk_c;
andreikovacs 0:764779eedf2d 135 }
andreikovacs 0:764779eedf2d 136
andreikovacs 0:764779eedf2d 137 /*! *********************************************************************************
andreikovacs 0:764779eedf2d 138 * \brief Links element to the head of the list.
andreikovacs 0:764779eedf2d 139 *
andreikovacs 0:764779eedf2d 140 * \param[in] list - ID of list to insert into.
andreikovacs 0:764779eedf2d 141 * element - element to add
andreikovacs 0:764779eedf2d 142 *
andreikovacs 0:764779eedf2d 143 * \return gListFull_c if list is full.
andreikovacs 0:764779eedf2d 144 * gListOk_c if insertion was successful.
andreikovacs 0:764779eedf2d 145 *
andreikovacs 0:764779eedf2d 146 * \pre
andreikovacs 0:764779eedf2d 147 *
andreikovacs 0:764779eedf2d 148 * \post
andreikovacs 0:764779eedf2d 149 *
andreikovacs 0:764779eedf2d 150 * \remarks
andreikovacs 0:764779eedf2d 151 *
andreikovacs 0:764779eedf2d 152 ********************************************************************************** */
andreikovacs 0:764779eedf2d 153 listStatus_t ListAddHead(listHandle_t list, listElementHandle_t element)
andreikovacs 0:764779eedf2d 154 {
andreikovacs 0:764779eedf2d 155 OSA_EnterCritical(kCriticalDisableInt);
andreikovacs 0:764779eedf2d 156
andreikovacs 0:764779eedf2d 157 if( (list->max != 0) && (list->max == list->size) )
andreikovacs 0:764779eedf2d 158 {
andreikovacs 0:764779eedf2d 159 OSA_ExitCritical(kCriticalDisableInt);
andreikovacs 0:764779eedf2d 160 return gListFull_c;
andreikovacs 0:764779eedf2d 161 }
andreikovacs 0:764779eedf2d 162
andreikovacs 0:764779eedf2d 163 if(list->size == 0)
andreikovacs 0:764779eedf2d 164 {
andreikovacs 0:764779eedf2d 165 list->tail = element;
andreikovacs 0:764779eedf2d 166 }
andreikovacs 0:764779eedf2d 167 else
andreikovacs 0:764779eedf2d 168 {
andreikovacs 0:764779eedf2d 169 list->head->prev = element;
andreikovacs 0:764779eedf2d 170 }
andreikovacs 0:764779eedf2d 171 element->next = list->head;
andreikovacs 0:764779eedf2d 172 element->prev = NULL;
andreikovacs 0:764779eedf2d 173 element->list = list;
andreikovacs 0:764779eedf2d 174 list->head = element;
andreikovacs 0:764779eedf2d 175 list->size++;
andreikovacs 0:764779eedf2d 176
andreikovacs 0:764779eedf2d 177 OSA_ExitCritical(kCriticalDisableInt);
andreikovacs 0:764779eedf2d 178 return gListOk_c;
andreikovacs 0:764779eedf2d 179 }
andreikovacs 0:764779eedf2d 180
andreikovacs 0:764779eedf2d 181 /*! *********************************************************************************
andreikovacs 0:764779eedf2d 182 * \brief Unlinks element from the head of the list.
andreikovacs 0:764779eedf2d 183 *
andreikovacs 0:764779eedf2d 184 * \param[in] list - ID of list to remove from.
andreikovacs 0:764779eedf2d 185 *
andreikovacs 0:764779eedf2d 186 * \return NULL if list is empty.
andreikovacs 0:764779eedf2d 187 * ID of removed element(pointer) if removal was successful.
andreikovacs 0:764779eedf2d 188 *
andreikovacs 0:764779eedf2d 189 * \pre
andreikovacs 0:764779eedf2d 190 *
andreikovacs 0:764779eedf2d 191 * \post
andreikovacs 0:764779eedf2d 192 *
andreikovacs 0:764779eedf2d 193 * \remarks
andreikovacs 0:764779eedf2d 194 *
andreikovacs 0:764779eedf2d 195 ********************************************************************************** */
andreikovacs 0:764779eedf2d 196 listElementHandle_t ListRemoveHead(listHandle_t list)
andreikovacs 0:764779eedf2d 197 {
andreikovacs 0:764779eedf2d 198 listElementHandle_t element;
andreikovacs 0:764779eedf2d 199
andreikovacs 0:764779eedf2d 200 OSA_EnterCritical(kCriticalDisableInt);
andreikovacs 0:764779eedf2d 201
andreikovacs 0:764779eedf2d 202 if(NULL == list || list->size == 0)
andreikovacs 0:764779eedf2d 203 {
andreikovacs 0:764779eedf2d 204 OSA_ExitCritical(kCriticalDisableInt);
andreikovacs 0:764779eedf2d 205 return NULL; /*List is empty*/
andreikovacs 0:764779eedf2d 206 }
andreikovacs 0:764779eedf2d 207
andreikovacs 0:764779eedf2d 208 element = list->head;
andreikovacs 0:764779eedf2d 209 list->size--;
andreikovacs 0:764779eedf2d 210 if(list->size == 0)
andreikovacs 0:764779eedf2d 211 {
andreikovacs 0:764779eedf2d 212 list->tail = NULL;
andreikovacs 0:764779eedf2d 213 }
andreikovacs 0:764779eedf2d 214 else
andreikovacs 0:764779eedf2d 215 {
andreikovacs 0:764779eedf2d 216 element->next->prev = NULL;
andreikovacs 0:764779eedf2d 217 }
andreikovacs 0:764779eedf2d 218 list->head = element->next; /*Is NULL if element is head*/
andreikovacs 0:764779eedf2d 219 element->list = NULL;
andreikovacs 0:764779eedf2d 220
andreikovacs 0:764779eedf2d 221 OSA_ExitCritical(kCriticalDisableInt);
andreikovacs 0:764779eedf2d 222 return element;
andreikovacs 0:764779eedf2d 223 }
andreikovacs 0:764779eedf2d 224
andreikovacs 0:764779eedf2d 225 /*! *********************************************************************************
andreikovacs 0:764779eedf2d 226 * \brief Gets head element ID.
andreikovacs 0:764779eedf2d 227 *
andreikovacs 0:764779eedf2d 228 * \param[in] list - ID of list.
andreikovacs 0:764779eedf2d 229 *
andreikovacs 0:764779eedf2d 230 * \return NULL if list is empty.
andreikovacs 0:764779eedf2d 231 * ID of head element if list is not empty.
andreikovacs 0:764779eedf2d 232 *
andreikovacs 0:764779eedf2d 233 * \pre
andreikovacs 0:764779eedf2d 234 *
andreikovacs 0:764779eedf2d 235 * \post
andreikovacs 0:764779eedf2d 236 *
andreikovacs 0:764779eedf2d 237 * \remarks
andreikovacs 0:764779eedf2d 238 *
andreikovacs 0:764779eedf2d 239 ********************************************************************************** */
andreikovacs 0:764779eedf2d 240 listElementHandle_t ListGetHead(listHandle_t list)
andreikovacs 0:764779eedf2d 241 {
andreikovacs 0:764779eedf2d 242 return list->head;
andreikovacs 0:764779eedf2d 243 }
andreikovacs 0:764779eedf2d 244
andreikovacs 0:764779eedf2d 245 /*! *********************************************************************************
andreikovacs 0:764779eedf2d 246 * \brief Gets next element ID.
andreikovacs 0:764779eedf2d 247 *
andreikovacs 0:764779eedf2d 248 * \param[in] element - ID of the element.
andreikovacs 0:764779eedf2d 249 *
andreikovacs 0:764779eedf2d 250 * \return NULL if element is tail.
andreikovacs 0:764779eedf2d 251 * ID of next element if exists.
andreikovacs 0:764779eedf2d 252 *
andreikovacs 0:764779eedf2d 253 * \pre
andreikovacs 0:764779eedf2d 254 *
andreikovacs 0:764779eedf2d 255 * \post
andreikovacs 0:764779eedf2d 256 *
andreikovacs 0:764779eedf2d 257 * \remarks
andreikovacs 0:764779eedf2d 258 *
andreikovacs 0:764779eedf2d 259 ********************************************************************************** */
andreikovacs 0:764779eedf2d 260 listElementHandle_t ListGetNext(listElementHandle_t element)
andreikovacs 0:764779eedf2d 261 {
andreikovacs 0:764779eedf2d 262 return element->next;
andreikovacs 0:764779eedf2d 263 }
andreikovacs 0:764779eedf2d 264
andreikovacs 0:764779eedf2d 265 /*! *********************************************************************************
andreikovacs 0:764779eedf2d 266 * \brief Gets previous element ID.
andreikovacs 0:764779eedf2d 267 *
andreikovacs 0:764779eedf2d 268 * \param[in] element - ID of the element.
andreikovacs 0:764779eedf2d 269 *
andreikovacs 0:764779eedf2d 270 * \return NULL if element is head.
andreikovacs 0:764779eedf2d 271 * ID of previous element if exists.
andreikovacs 0:764779eedf2d 272 *
andreikovacs 0:764779eedf2d 273 * \pre
andreikovacs 0:764779eedf2d 274 *
andreikovacs 0:764779eedf2d 275 * \post
andreikovacs 0:764779eedf2d 276 *
andreikovacs 0:764779eedf2d 277 * \remarks
andreikovacs 0:764779eedf2d 278 *
andreikovacs 0:764779eedf2d 279 ********************************************************************************** */
andreikovacs 0:764779eedf2d 280 listElementHandle_t ListGetPrev(listElementHandle_t element)
andreikovacs 0:764779eedf2d 281 {
andreikovacs 0:764779eedf2d 282 return element->prev;
andreikovacs 0:764779eedf2d 283 }
andreikovacs 0:764779eedf2d 284
andreikovacs 0:764779eedf2d 285 /*! *********************************************************************************
andreikovacs 0:764779eedf2d 286 * \brief Unlinks an element from its list.
andreikovacs 0:764779eedf2d 287 *
andreikovacs 0:764779eedf2d 288 * \param[in] element - ID of the element to remove.
andreikovacs 0:764779eedf2d 289 *
andreikovacs 0:764779eedf2d 290 * \return gOrphanElement_c if element is not part of any list.
andreikovacs 0:764779eedf2d 291 * gListOk_c if removal was successful.
andreikovacs 0:764779eedf2d 292 *
andreikovacs 0:764779eedf2d 293 * \pre
andreikovacs 0:764779eedf2d 294 *
andreikovacs 0:764779eedf2d 295 * \post
andreikovacs 0:764779eedf2d 296 *
andreikovacs 0:764779eedf2d 297 * \remarks
andreikovacs 0:764779eedf2d 298 *
andreikovacs 0:764779eedf2d 299 ********************************************************************************** */
andreikovacs 0:764779eedf2d 300 listStatus_t ListRemoveElement(listElementHandle_t element)
andreikovacs 0:764779eedf2d 301 {
andreikovacs 0:764779eedf2d 302 if(element->list == NULL)
andreikovacs 0:764779eedf2d 303 {
andreikovacs 0:764779eedf2d 304 return gOrphanElement_c; /*Element was previusly removed or never added*/
andreikovacs 0:764779eedf2d 305 }
andreikovacs 0:764779eedf2d 306
andreikovacs 0:764779eedf2d 307 OSA_EnterCritical(kCriticalDisableInt);
andreikovacs 0:764779eedf2d 308
andreikovacs 0:764779eedf2d 309 if(element->prev == NULL) /*Element is head or solo*/
andreikovacs 0:764779eedf2d 310 {
andreikovacs 0:764779eedf2d 311 element->list->head = element->next; /*is null if solo*/
andreikovacs 0:764779eedf2d 312 }
andreikovacs 0:764779eedf2d 313 if(element->next == NULL) /*Element is tail or solo*/
andreikovacs 0:764779eedf2d 314 {
andreikovacs 0:764779eedf2d 315 element->list->tail = element->prev; /*is null if solo*/
andreikovacs 0:764779eedf2d 316 }
andreikovacs 0:764779eedf2d 317 if(element->prev != NULL) /*Element is not head*/
andreikovacs 0:764779eedf2d 318 {
andreikovacs 0:764779eedf2d 319 element->prev->next = element->next;
andreikovacs 0:764779eedf2d 320 }
andreikovacs 0:764779eedf2d 321 if(element->next != NULL) /*Element is not tail*/
andreikovacs 0:764779eedf2d 322 {
andreikovacs 0:764779eedf2d 323 element->next->prev = element->prev;
andreikovacs 0:764779eedf2d 324 }
andreikovacs 0:764779eedf2d 325 element->list->size--;
andreikovacs 0:764779eedf2d 326 element->list = NULL;
andreikovacs 0:764779eedf2d 327
andreikovacs 0:764779eedf2d 328 OSA_ExitCritical(kCriticalDisableInt);
andreikovacs 0:764779eedf2d 329 return gListOk_c;
andreikovacs 0:764779eedf2d 330 }
andreikovacs 0:764779eedf2d 331
andreikovacs 0:764779eedf2d 332 /*! *********************************************************************************
andreikovacs 0:764779eedf2d 333 * \brief Links an element in the previous position relative to a given member
andreikovacs 0:764779eedf2d 334 * of a list.
andreikovacs 0:764779eedf2d 335 *
andreikovacs 0:764779eedf2d 336 * \param[in] element - ID of a member of a list.
andreikovacs 0:764779eedf2d 337 * newElement - new element to insert before the given member.
andreikovacs 0:764779eedf2d 338 *
andreikovacs 0:764779eedf2d 339 * \return gOrphanElement_c if element is not part of any list.
andreikovacs 0:764779eedf2d 340 * gListFull_c if list is full.
andreikovacs 0:764779eedf2d 341 * gListOk_c if insertion was successful.
andreikovacs 0:764779eedf2d 342 *
andreikovacs 0:764779eedf2d 343 * \pre
andreikovacs 0:764779eedf2d 344 *
andreikovacs 0:764779eedf2d 345 * \post
andreikovacs 0:764779eedf2d 346 *
andreikovacs 0:764779eedf2d 347 * \remarks
andreikovacs 0:764779eedf2d 348 *
andreikovacs 0:764779eedf2d 349 ********************************************************************************** */
andreikovacs 0:764779eedf2d 350 listStatus_t ListAddPrevElement(listElementHandle_t element, listElementHandle_t newElement)
andreikovacs 0:764779eedf2d 351 {
andreikovacs 0:764779eedf2d 352 if(element->list == NULL)
andreikovacs 0:764779eedf2d 353 {
andreikovacs 0:764779eedf2d 354 return gOrphanElement_c; /*Element was previusly removed or never added*/
andreikovacs 0:764779eedf2d 355 }
andreikovacs 0:764779eedf2d 356 OSA_EnterCritical(kCriticalDisableInt);
andreikovacs 0:764779eedf2d 357
andreikovacs 0:764779eedf2d 358 if( (element->list->max != 0) && (element->list->max == element->list->size) )
andreikovacs 0:764779eedf2d 359 {
andreikovacs 0:764779eedf2d 360 OSA_ExitCritical(kCriticalDisableInt);
andreikovacs 0:764779eedf2d 361 return gListFull_c;
andreikovacs 0:764779eedf2d 362 }
andreikovacs 0:764779eedf2d 363
andreikovacs 0:764779eedf2d 364 if(element->prev == NULL) /*Element is list head*/
andreikovacs 0:764779eedf2d 365 {
andreikovacs 0:764779eedf2d 366 element->list->head = newElement;
andreikovacs 0:764779eedf2d 367 }
andreikovacs 0:764779eedf2d 368 else
andreikovacs 0:764779eedf2d 369 {
andreikovacs 0:764779eedf2d 370 element->prev->next = newElement;
andreikovacs 0:764779eedf2d 371 }
andreikovacs 0:764779eedf2d 372 newElement->list = element->list;
andreikovacs 0:764779eedf2d 373 element->list->size++;
andreikovacs 0:764779eedf2d 374 newElement->next = element;
andreikovacs 0:764779eedf2d 375 newElement->prev = element->prev;
andreikovacs 0:764779eedf2d 376 element->prev = newElement;
andreikovacs 0:764779eedf2d 377
andreikovacs 0:764779eedf2d 378 OSA_ExitCritical(kCriticalDisableInt);
andreikovacs 0:764779eedf2d 379 return gListOk_c;
andreikovacs 0:764779eedf2d 380 }
andreikovacs 0:764779eedf2d 381
andreikovacs 0:764779eedf2d 382 /*! *********************************************************************************
andreikovacs 0:764779eedf2d 383 * \brief Gets the current size of a list.
andreikovacs 0:764779eedf2d 384 *
andreikovacs 0:764779eedf2d 385 * \param[in] list - ID of the list.
andreikovacs 0:764779eedf2d 386 *
andreikovacs 0:764779eedf2d 387 * \return Current size of the list.
andreikovacs 0:764779eedf2d 388 *
andreikovacs 0:764779eedf2d 389 * \pre
andreikovacs 0:764779eedf2d 390 *
andreikovacs 0:764779eedf2d 391 * \post
andreikovacs 0:764779eedf2d 392 *
andreikovacs 0:764779eedf2d 393 * \remarks
andreikovacs 0:764779eedf2d 394 *
andreikovacs 0:764779eedf2d 395 ********************************************************************************** */
andreikovacs 0:764779eedf2d 396 uint32_t ListGetSize(listHandle_t list)
andreikovacs 0:764779eedf2d 397 {
andreikovacs 0:764779eedf2d 398 return list->size;
andreikovacs 0:764779eedf2d 399 }
andreikovacs 0:764779eedf2d 400
andreikovacs 0:764779eedf2d 401 /*! *********************************************************************************
andreikovacs 0:764779eedf2d 402 * \brief Gets the number of free places in the list.
andreikovacs 0:764779eedf2d 403 *
andreikovacs 0:764779eedf2d 404 * \param[in] list - ID of the list.
andreikovacs 0:764779eedf2d 405 *
andreikovacs 0:764779eedf2d 406 * \return Available size of the list.
andreikovacs 0:764779eedf2d 407 *
andreikovacs 0:764779eedf2d 408 * \pre
andreikovacs 0:764779eedf2d 409 *
andreikovacs 0:764779eedf2d 410 * \post
andreikovacs 0:764779eedf2d 411 *
andreikovacs 0:764779eedf2d 412 * \remarks
andreikovacs 0:764779eedf2d 413 *
andreikovacs 0:764779eedf2d 414 ********************************************************************************** */
andreikovacs 0:764779eedf2d 415 uint32_t ListGetAvailable(listHandle_t list)
andreikovacs 0:764779eedf2d 416 {
andreikovacs 0:764779eedf2d 417 return (list->max - list->size);
andreikovacs 0:764779eedf2d 418 }
andreikovacs 0:764779eedf2d 419
andreikovacs 0:764779eedf2d 420 /*! *********************************************************************************
andreikovacs 0:764779eedf2d 421 * \brief Creates, tests and deletes a list. Any error that occurs will trap the
andreikovacs 0:764779eedf2d 422 * CPU in a while(1) loop.
andreikovacs 0:764779eedf2d 423 *
andreikovacs 0:764779eedf2d 424 * \param[in] void.
andreikovacs 0:764779eedf2d 425 *
andreikovacs 0:764779eedf2d 426 * \return gListOk_c.
andreikovacs 0:764779eedf2d 427 *
andreikovacs 0:764779eedf2d 428 * \pre
andreikovacs 0:764779eedf2d 429 *
andreikovacs 0:764779eedf2d 430 * \post
andreikovacs 0:764779eedf2d 431 *
andreikovacs 0:764779eedf2d 432 * \remarks
andreikovacs 0:764779eedf2d 433 *
andreikovacs 0:764779eedf2d 434 ********************************************************************************** */
andreikovacs 0:764779eedf2d 435 // To be removed or rewritten to remove MemManager dependency.
andreikovacs 0:764779eedf2d 436 #if 0
andreikovacs 0:764779eedf2d 437 listStatus_t ListTest()
andreikovacs 0:764779eedf2d 438 {
andreikovacs 0:764779eedf2d 439 listHandle_t list;
andreikovacs 0:764779eedf2d 440 listElementHandle_t element, newElement;
andreikovacs 0:764779eedf2d 441 uint32_t i,freeBlocks;
andreikovacs 0:764779eedf2d 442 const uint32_t max = 10;
andreikovacs 0:764779eedf2d 443
andreikovacs 0:764779eedf2d 444 freeBlocks = MEM_GetAvailableFwkBlocks(0);
andreikovacs 0:764779eedf2d 445 /*create list*/
andreikovacs 0:764779eedf2d 446 list = ListCreate(max);
andreikovacs 0:764779eedf2d 447 LIST_ASSERT(list != NULL);
andreikovacs 0:764779eedf2d 448
andreikovacs 0:764779eedf2d 449 /*add elements*/
andreikovacs 0:764779eedf2d 450 for(i=0; i<max; i++)
andreikovacs 0:764779eedf2d 451 {
andreikovacs 0:764779eedf2d 452 element = (listElementHandle_t)MEM_BufferFwkAlloc(sizeof(listElement_t));
andreikovacs 0:764779eedf2d 453 LIST_ASSERT(element != NULL);
andreikovacs 0:764779eedf2d 454 LIST_ASSERT(ListAddHead(list, element) == gListOk_c);
andreikovacs 0:764779eedf2d 455 LIST_ASSERT(list->head == element)
andreikovacs 0:764779eedf2d 456 ListRemoveHead(list);
andreikovacs 0:764779eedf2d 457 LIST_ASSERT(ListAddTail(list, element) == gListOk_c);
andreikovacs 0:764779eedf2d 458 LIST_ASSERT(list->tail == element);
andreikovacs 0:764779eedf2d 459 if(ListGetSize(list) == 1)
andreikovacs 0:764779eedf2d 460 {
andreikovacs 0:764779eedf2d 461 LIST_ASSERT(list->head == element);
andreikovacs 0:764779eedf2d 462 }
andreikovacs 0:764779eedf2d 463 else
andreikovacs 0:764779eedf2d 464 {
andreikovacs 0:764779eedf2d 465 LIST_ASSERT(list->head != element);
andreikovacs 0:764779eedf2d 466 }
andreikovacs 0:764779eedf2d 467 }
andreikovacs 0:764779eedf2d 468 LIST_ASSERT(ListGetSize(list) == max);
andreikovacs 0:764779eedf2d 469
andreikovacs 0:764779eedf2d 470 /*add one more element*/
andreikovacs 0:764779eedf2d 471 element = (listElementHandle_t)MEM_BufferFwkAlloc(sizeof(listElement_t));
andreikovacs 0:764779eedf2d 472 LIST_ASSERT(element != NULL);
andreikovacs 0:764779eedf2d 473 LIST_ASSERT(ListAddTail(list, element) == gListFull_c);
andreikovacs 0:764779eedf2d 474 list->max = 0;
andreikovacs 0:764779eedf2d 475 LIST_ASSERT(ListAddTail(list, element) == gListOk_c);
andreikovacs 0:764779eedf2d 476 LIST_ASSERT(ListGetSize(list) == max+1);
andreikovacs 0:764779eedf2d 477 /*remove the extra element*/
andreikovacs 0:764779eedf2d 478 element = ListRemoveHead(list);
andreikovacs 0:764779eedf2d 479 LIST_ASSERT(element != NULL);
andreikovacs 0:764779eedf2d 480 LIST_ASSERT(ListGetSize(list) == max);
andreikovacs 0:764779eedf2d 481 LIST_ASSERT(MEM_BufferFree(element) == MEM_SUCCESS_c);
andreikovacs 0:764779eedf2d 482 list->max = max;
andreikovacs 0:764779eedf2d 483
andreikovacs 0:764779eedf2d 484 /*parse elements*/
andreikovacs 0:764779eedf2d 485 element = ListGetHead(list);
andreikovacs 0:764779eedf2d 486 LIST_ASSERT(element != NULL);
andreikovacs 0:764779eedf2d 487 for(i=0; i<(max-1); i++)
andreikovacs 0:764779eedf2d 488 {
andreikovacs 0:764779eedf2d 489 element = ListGetNext(element);
andreikovacs 0:764779eedf2d 490 LIST_ASSERT(element != NULL);
andreikovacs 0:764779eedf2d 491 }
andreikovacs 0:764779eedf2d 492 LIST_ASSERT(element == list->tail);
andreikovacs 0:764779eedf2d 493 LIST_ASSERT(ListGetNext(element) == NULL);
andreikovacs 0:764779eedf2d 494
andreikovacs 0:764779eedf2d 495 /*Reverse parse elements*/
andreikovacs 0:764779eedf2d 496 for(i=0; i<(max-1); i++)
andreikovacs 0:764779eedf2d 497 {
andreikovacs 0:764779eedf2d 498 element = ListGetPrev(element);
andreikovacs 0:764779eedf2d 499 LIST_ASSERT(element != NULL);
andreikovacs 0:764779eedf2d 500 }
andreikovacs 0:764779eedf2d 501 LIST_ASSERT(element == list->head);
andreikovacs 0:764779eedf2d 502 LIST_ASSERT(ListGetPrev(element) == NULL);
andreikovacs 0:764779eedf2d 503
andreikovacs 0:764779eedf2d 504 /*Add prev*/
andreikovacs 0:764779eedf2d 505 element = ListGetHead(list);
andreikovacs 0:764779eedf2d 506 LIST_ASSERT(element != NULL);
andreikovacs 0:764779eedf2d 507 newElement = (listElementHandle_t)MEM_BufferFwkAlloc(sizeof(listElement_t));
andreikovacs 0:764779eedf2d 508 LIST_ASSERT(newElement != NULL);
andreikovacs 0:764779eedf2d 509 LIST_ASSERT(ListAddPrevElement(element, newElement) == gListFull_c);
andreikovacs 0:764779eedf2d 510 LIST_ASSERT(ListGetHead(list) == element);
andreikovacs 0:764779eedf2d 511 list->max = 0;
andreikovacs 0:764779eedf2d 512 LIST_ASSERT(ListAddPrevElement(element, newElement) == gListOk_c);
andreikovacs 0:764779eedf2d 513 LIST_ASSERT(ListGetHead(list) == newElement);
andreikovacs 0:764779eedf2d 514 newElement = (listElementHandle_t)MEM_BufferFwkAlloc(sizeof(listElement_t));
andreikovacs 0:764779eedf2d 515 LIST_ASSERT(newElement != NULL);
andreikovacs 0:764779eedf2d 516 element = list->head->next->next;
andreikovacs 0:764779eedf2d 517 LIST_ASSERT(ListAddPrevElement(element, newElement) == gListOk_c);
andreikovacs 0:764779eedf2d 518 LIST_ASSERT(list->head->next->next == newElement);
andreikovacs 0:764779eedf2d 519 newElement = (listElementHandle_t)MEM_BufferFwkAlloc(sizeof(listElement_t));
andreikovacs 0:764779eedf2d 520 LIST_ASSERT(newElement != NULL);
andreikovacs 0:764779eedf2d 521 element = list->tail;
andreikovacs 0:764779eedf2d 522 LIST_ASSERT(ListAddPrevElement(element, newElement) == gListOk_c);
andreikovacs 0:764779eedf2d 523 LIST_ASSERT(list->tail->prev == newElement);
andreikovacs 0:764779eedf2d 524 newElement = (listElementHandle_t)MEM_BufferFwkAlloc(sizeof(listElement_t));
andreikovacs 0:764779eedf2d 525 LIST_ASSERT(newElement != NULL);
andreikovacs 0:764779eedf2d 526 element = (listElementHandle_t)MEM_BufferFwkAlloc(sizeof(listElement_t));
andreikovacs 0:764779eedf2d 527 LIST_ASSERT(element != NULL);
andreikovacs 0:764779eedf2d 528 element->list = NULL;
andreikovacs 0:764779eedf2d 529 LIST_ASSERT(ListAddPrevElement(element, newElement) == gOrphanElement_c);
andreikovacs 0:764779eedf2d 530 MEM_BufferFree(newElement);
andreikovacs 0:764779eedf2d 531 MEM_BufferFree(element);
andreikovacs 0:764779eedf2d 532 LIST_ASSERT(ListGetSize(list) == max+3);
andreikovacs 0:764779eedf2d 533
andreikovacs 0:764779eedf2d 534 /*Remove element*/
andreikovacs 0:764779eedf2d 535 element = ListGetHead(list);
andreikovacs 0:764779eedf2d 536 LIST_ASSERT(element == list->head);
andreikovacs 0:764779eedf2d 537 LIST_ASSERT(ListRemoveElement(element) == gListOk_c);
andreikovacs 0:764779eedf2d 538 LIST_ASSERT(list->head != element);
andreikovacs 0:764779eedf2d 539 LIST_ASSERT(ListRemoveElement(element) == gOrphanElement_c);
andreikovacs 0:764779eedf2d 540 MEM_BufferFree(element);
andreikovacs 0:764779eedf2d 541 element = ListGetHead(list)->next->next;
andreikovacs 0:764779eedf2d 542 LIST_ASSERT(ListRemoveElement(element) == gListOk_c);
andreikovacs 0:764779eedf2d 543 MEM_BufferFree(element);
andreikovacs 0:764779eedf2d 544 element = list->tail;
andreikovacs 0:764779eedf2d 545 LIST_ASSERT(ListRemoveElement(element) == gListOk_c);
andreikovacs 0:764779eedf2d 546 LIST_ASSERT(list->tail != element);
andreikovacs 0:764779eedf2d 547 MEM_BufferFree(element);
andreikovacs 0:764779eedf2d 548 LIST_ASSERT(ListGetSize(list) == max);
andreikovacs 0:764779eedf2d 549 list->max = max;
andreikovacs 0:764779eedf2d 550
andreikovacs 0:764779eedf2d 551 for(i=0; i<(max-1); i++)
andreikovacs 0:764779eedf2d 552 {
andreikovacs 0:764779eedf2d 553 element = ListRemoveHead(list);
andreikovacs 0:764779eedf2d 554 LIST_ASSERT(element != NULL);
andreikovacs 0:764779eedf2d 555 MEM_BufferFree(element);
andreikovacs 0:764779eedf2d 556 }
andreikovacs 0:764779eedf2d 557 element = ListGetHead(list);
andreikovacs 0:764779eedf2d 558 LIST_ASSERT(element != NULL);
andreikovacs 0:764779eedf2d 559 LIST_ASSERT(ListRemoveElement(element) == gListOk_c);
andreikovacs 0:764779eedf2d 560 LIST_ASSERT(list->head == NULL);
andreikovacs 0:764779eedf2d 561 LIST_ASSERT(list->tail == NULL);
andreikovacs 0:764779eedf2d 562 LIST_ASSERT(element->list == NULL);
andreikovacs 0:764779eedf2d 563 MEM_BufferFree(element);
andreikovacs 0:764779eedf2d 564
andreikovacs 0:764779eedf2d 565 /*List is empty here.*/
andreikovacs 0:764779eedf2d 566 LIST_ASSERT(ListGetSize(list) == 0);
andreikovacs 0:764779eedf2d 567 element = ListRemoveHead(list);
andreikovacs 0:764779eedf2d 568 LIST_ASSERT(element == NULL);
andreikovacs 0:764779eedf2d 569 element = ListGetHead(list);
andreikovacs 0:764779eedf2d 570 LIST_ASSERT(element == NULL);
andreikovacs 0:764779eedf2d 571
andreikovacs 0:764779eedf2d 572 MEM_BufferFree(list);
andreikovacs 0:764779eedf2d 573 /*Did we produce a memory leak?*/
andreikovacs 0:764779eedf2d 574 LIST_ASSERT(freeBlocks == MEM_GetAvailableFwkBlocks(0));
andreikovacs 0:764779eedf2d 575
andreikovacs 0:764779eedf2d 576 return gListOk_c;
andreikovacs 0:764779eedf2d 577 }
andreikovacs 0:764779eedf2d 578 #else
andreikovacs 0:764779eedf2d 579 listStatus_t ListTest()
andreikovacs 0:764779eedf2d 580 {
andreikovacs 0:764779eedf2d 581 return gListOk_c;
andreikovacs 0:764779eedf2d 582 }
andreikovacs 0:764779eedf2d 583 #endif