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