meh

Fork of mbed by mbed official

Committer:
bogdanm
Date:
Fri Sep 12 16:41:52 2014 +0100
Revision:
89:552587b429a1
Release 89 of the mbed library

Main changes:

- low power optimizations for Nordic targets
- code structure changes for Freescale K64F targets
- bug fixes in various backends

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bogdanm 89:552587b429a1 1 /* Copyright (c) 2013 Nordic Semiconductor. All Rights Reserved.
bogdanm 89:552587b429a1 2 *
bogdanm 89:552587b429a1 3 * The information contained herein is property of Nordic Semiconductor ASA.
bogdanm 89:552587b429a1 4 * Terms and conditions of usage are described in detail in NORDIC
bogdanm 89:552587b429a1 5 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
bogdanm 89:552587b429a1 6 *
bogdanm 89:552587b429a1 7 * Licensees are granted free, non-transferable use of the information. NO
bogdanm 89:552587b429a1 8 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
bogdanm 89:552587b429a1 9 * the file.
bogdanm 89:552587b429a1 10 *
bogdanm 89:552587b429a1 11 */
bogdanm 89:552587b429a1 12
bogdanm 89:552587b429a1 13 /**@file
bogdanm 89:552587b429a1 14 *
bogdanm 89:552587b429a1 15 * @defgroup app_fifo FIFO implementation
bogdanm 89:552587b429a1 16 * @{
bogdanm 89:552587b429a1 17 * @ingroup app_common
bogdanm 89:552587b429a1 18 *
bogdanm 89:552587b429a1 19 * @brief FIFO implementation.
bogdanm 89:552587b429a1 20 */
bogdanm 89:552587b429a1 21
bogdanm 89:552587b429a1 22 #ifndef APP_FIFO_H__
bogdanm 89:552587b429a1 23 #define APP_FIFO_H__
bogdanm 89:552587b429a1 24
bogdanm 89:552587b429a1 25 #include <stdint.h>
bogdanm 89:552587b429a1 26 #include <stdlib.h>
bogdanm 89:552587b429a1 27 #include "nrf_error.h"
bogdanm 89:552587b429a1 28
bogdanm 89:552587b429a1 29 /**@brief A FIFO instance structure. Keeps track of which bytes to read and write next.
bogdanm 89:552587b429a1 30 * Also it keeps the information about which memory is allocated for the buffer
bogdanm 89:552587b429a1 31 * and its size. This needs to be initialized by app_fifo_init() before use.
bogdanm 89:552587b429a1 32 */
bogdanm 89:552587b429a1 33 typedef struct
bogdanm 89:552587b429a1 34 {
bogdanm 89:552587b429a1 35 uint8_t * p_buf; /**< Pointer to FIFO buffer memory. */
bogdanm 89:552587b429a1 36 uint16_t buf_size_mask; /**< Read/write index mask. Also used for size checking. */
bogdanm 89:552587b429a1 37 volatile uint32_t read_pos; /**< Next read position in the FIFO buffer. */
bogdanm 89:552587b429a1 38 volatile uint32_t write_pos; /**< Next write position in the FIFO buffer. */
bogdanm 89:552587b429a1 39 } app_fifo_t;
bogdanm 89:552587b429a1 40
bogdanm 89:552587b429a1 41 /**@brief Function for initializing the FIFO.
bogdanm 89:552587b429a1 42 *
bogdanm 89:552587b429a1 43 * @param[out] p_fifo FIFO object.
bogdanm 89:552587b429a1 44 * @param[in] p_buf FIFO buffer for storing data. The buffer size has to be a power of two.
bogdanm 89:552587b429a1 45 * @param[in] buf_size Size of the FIFO buffer provided, has to be a power of 2.
bogdanm 89:552587b429a1 46 *
bogdanm 89:552587b429a1 47 * @retval NRF_SUCCESS If initialization was successful.
bogdanm 89:552587b429a1 48 * @retval NRF_ERROR_NULL If a NULL pointer is provided as buffer.
bogdanm 89:552587b429a1 49 * @retval NRF_ERROR_INVALID_LENGTH If size of buffer provided is not a power of two.
bogdanm 89:552587b429a1 50 */
bogdanm 89:552587b429a1 51 uint32_t app_fifo_init(app_fifo_t * p_fifo, uint8_t * p_buf, uint16_t buf_size);
bogdanm 89:552587b429a1 52
bogdanm 89:552587b429a1 53 /**@brief Function for adding an element to the FIFO.
bogdanm 89:552587b429a1 54 *
bogdanm 89:552587b429a1 55 * @param[in] p_fifo Pointer to the FIFO.
bogdanm 89:552587b429a1 56 * @param[in] byte Data byte to add to the FIFO.
bogdanm 89:552587b429a1 57 *
bogdanm 89:552587b429a1 58 * @retval NRF_SUCCESS If an element has been successfully added to the FIFO.
bogdanm 89:552587b429a1 59 * @retval NRF_ERROR_NO_MEM If the FIFO is full.
bogdanm 89:552587b429a1 60 */
bogdanm 89:552587b429a1 61 uint32_t app_fifo_put(app_fifo_t * p_fifo, uint8_t byte);
bogdanm 89:552587b429a1 62
bogdanm 89:552587b429a1 63 /**@brief Function for getting the next element from the FIFO.
bogdanm 89:552587b429a1 64 *
bogdanm 89:552587b429a1 65 * @param[in] p_fifo Pointer to the FIFO.
bogdanm 89:552587b429a1 66 * @param[out] p_byte Byte fetched from the FIFO.
bogdanm 89:552587b429a1 67 *
bogdanm 89:552587b429a1 68 * @retval NRF_SUCCESS If an element was returned.
bogdanm 89:552587b429a1 69 * @retval NRF_ERROR_NOT_FOUND If there is no more elements in the queue.
bogdanm 89:552587b429a1 70 */
bogdanm 89:552587b429a1 71 uint32_t app_fifo_get(app_fifo_t * p_fifo, uint8_t * p_byte);
bogdanm 89:552587b429a1 72
bogdanm 89:552587b429a1 73 /**@brief Function for flushing the FIFO.
bogdanm 89:552587b429a1 74 *
bogdanm 89:552587b429a1 75 * @param[in] p_fifo Pointer to the FIFO.
bogdanm 89:552587b429a1 76 *
bogdanm 89:552587b429a1 77 * @retval NRF_SUCCESS If the FIFO flushed successfully.
bogdanm 89:552587b429a1 78 */
bogdanm 89:552587b429a1 79 uint32_t app_fifo_flush(app_fifo_t * p_fifo);
bogdanm 89:552587b429a1 80
bogdanm 89:552587b429a1 81 #endif // APP_FIFO_H__
bogdanm 89:552587b429a1 82
bogdanm 89:552587b429a1 83 /** @} */