The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.
Dependents: hello SerialTestv11 SerialTestv12 Sierpinski ... more
mbed 2
This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.
TARGET_SDT51822B/TOOLCHAIN_IAR/nrf_spis.h@172:65be27845400, 2019-02-20 (annotated)
- Committer:
- AnnaBridge
- Date:
- Wed Feb 20 20:53:29 2019 +0000
- Revision:
- 172:65be27845400
- Parent:
- 171:3a7713b1edbc
mbed library release version 165
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Kojto | 148:fd96258d940d | 1 | /* |
Kojto | 148:fd96258d940d | 2 | * Copyright (c) 2015 Nordic Semiconductor ASA |
Kojto | 148:fd96258d940d | 3 | * All rights reserved. |
Kojto | 148:fd96258d940d | 4 | * |
Kojto | 148:fd96258d940d | 5 | * Redistribution and use in source and binary forms, with or without modification, |
Kojto | 148:fd96258d940d | 6 | * are permitted provided that the following conditions are met: |
Kojto | 148:fd96258d940d | 7 | * |
Kojto | 148:fd96258d940d | 8 | * 1. Redistributions of source code must retain the above copyright notice, this list |
Kojto | 148:fd96258d940d | 9 | * of conditions and the following disclaimer. |
Kojto | 148:fd96258d940d | 10 | * |
Kojto | 148:fd96258d940d | 11 | * 2. Redistributions in binary form, except as embedded into a Nordic Semiconductor ASA |
Kojto | 148:fd96258d940d | 12 | * integrated circuit in a product or a software update for such product, must reproduce |
Kojto | 148:fd96258d940d | 13 | * the above copyright notice, this list of conditions and the following disclaimer in |
Kojto | 148:fd96258d940d | 14 | * the documentation and/or other materials provided with the distribution. |
Kojto | 148:fd96258d940d | 15 | * |
Kojto | 148:fd96258d940d | 16 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of its contributors may be |
Kojto | 148:fd96258d940d | 17 | * used to endorse or promote products derived from this software without specific prior |
Kojto | 148:fd96258d940d | 18 | * written permission. |
Kojto | 148:fd96258d940d | 19 | * |
Kojto | 148:fd96258d940d | 20 | * 4. This software, with or without modification, must only be used with a |
Kojto | 148:fd96258d940d | 21 | * Nordic Semiconductor ASA integrated circuit. |
Kojto | 148:fd96258d940d | 22 | * |
Kojto | 148:fd96258d940d | 23 | * 5. Any software provided in binary or object form under this license must not be reverse |
Kojto | 148:fd96258d940d | 24 | * engineered, decompiled, modified and/or disassembled. |
Kojto | 148:fd96258d940d | 25 | * |
Kojto | 148:fd96258d940d | 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
Kojto | 148:fd96258d940d | 27 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
Kojto | 148:fd96258d940d | 28 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
Kojto | 148:fd96258d940d | 29 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
Kojto | 148:fd96258d940d | 30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
Kojto | 148:fd96258d940d | 31 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
Kojto | 148:fd96258d940d | 32 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
Kojto | 148:fd96258d940d | 33 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
Kojto | 148:fd96258d940d | 34 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
Kojto | 148:fd96258d940d | 35 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Kojto | 148:fd96258d940d | 36 | * |
Kojto | 148:fd96258d940d | 37 | */ |
Kojto | 148:fd96258d940d | 38 | |
Kojto | 148:fd96258d940d | 39 | |
Kojto | 148:fd96258d940d | 40 | /** |
Kojto | 148:fd96258d940d | 41 | * @defgroup nrf_spis_hal SPIS HAL |
Kojto | 148:fd96258d940d | 42 | * @{ |
Kojto | 148:fd96258d940d | 43 | * @ingroup nrf_spis |
Kojto | 148:fd96258d940d | 44 | * |
Kojto | 148:fd96258d940d | 45 | * @brief Hardware access layer for accessing the SPIS peripheral. |
Kojto | 148:fd96258d940d | 46 | */ |
Kojto | 148:fd96258d940d | 47 | |
Kojto | 148:fd96258d940d | 48 | #ifndef NRF_SPIS_H__ |
Kojto | 148:fd96258d940d | 49 | #define NRF_SPIS_H__ |
Kojto | 148:fd96258d940d | 50 | |
Kojto | 148:fd96258d940d | 51 | #include <stddef.h> |
Kojto | 148:fd96258d940d | 52 | #include <stdbool.h> |
Kojto | 148:fd96258d940d | 53 | #include <stdint.h> |
Kojto | 148:fd96258d940d | 54 | |
Kojto | 148:fd96258d940d | 55 | #include "nrf.h" |
Kojto | 148:fd96258d940d | 56 | |
Kojto | 148:fd96258d940d | 57 | |
Kojto | 148:fd96258d940d | 58 | /** |
Kojto | 148:fd96258d940d | 59 | * @brief This value can be used as a parameter for the @ref nrf_spis_pins_set |
Kojto | 148:fd96258d940d | 60 | * function to specify that a given SPI signal (SCK, MOSI, or MISO) |
Kojto | 148:fd96258d940d | 61 | * shall not be connected to a physical pin. |
Kojto | 148:fd96258d940d | 62 | */ |
Kojto | 148:fd96258d940d | 63 | #define NRF_SPIS_PIN_NOT_CONNECTED 0xFFFFFFFF |
Kojto | 148:fd96258d940d | 64 | |
Kojto | 148:fd96258d940d | 65 | |
Kojto | 148:fd96258d940d | 66 | /** |
Kojto | 148:fd96258d940d | 67 | * @brief SPIS tasks. |
Kojto | 148:fd96258d940d | 68 | */ |
Kojto | 148:fd96258d940d | 69 | typedef enum |
Kojto | 148:fd96258d940d | 70 | { |
Kojto | 148:fd96258d940d | 71 | /*lint -save -e30*/ |
Kojto | 148:fd96258d940d | 72 | NRF_SPIS_TASK_ACQUIRE = offsetof(NRF_SPIS_Type, TASKS_ACQUIRE), ///< Acquire SPI semaphore. |
Kojto | 148:fd96258d940d | 73 | NRF_SPIS_TASK_RELEASE = offsetof(NRF_SPIS_Type, TASKS_RELEASE), ///< Release SPI semaphore, enabling the SPI slave to acquire it. |
Kojto | 148:fd96258d940d | 74 | /*lint -restore*/ |
Kojto | 148:fd96258d940d | 75 | } nrf_spis_task_t; |
Kojto | 148:fd96258d940d | 76 | |
Kojto | 148:fd96258d940d | 77 | /** |
Kojto | 148:fd96258d940d | 78 | * @brief SPIS events. |
Kojto | 148:fd96258d940d | 79 | */ |
Kojto | 148:fd96258d940d | 80 | typedef enum |
Kojto | 148:fd96258d940d | 81 | { |
Kojto | 148:fd96258d940d | 82 | /*lint -save -e30*/ |
Kojto | 148:fd96258d940d | 83 | NRF_SPIS_EVENT_END = offsetof(NRF_SPIS_Type, EVENTS_END), ///< Granted transaction completed. |
Kojto | 148:fd96258d940d | 84 | NRF_SPIS_EVENT_ACQUIRED = offsetof(NRF_SPIS_Type, EVENTS_ACQUIRED) ///< Semaphore acquired. |
Kojto | 148:fd96258d940d | 85 | /*lint -restore*/ |
Kojto | 148:fd96258d940d | 86 | } nrf_spis_event_t; |
Kojto | 148:fd96258d940d | 87 | |
Kojto | 148:fd96258d940d | 88 | /** |
Kojto | 148:fd96258d940d | 89 | * @brief SPIS shortcuts. |
Kojto | 148:fd96258d940d | 90 | */ |
Kojto | 148:fd96258d940d | 91 | typedef enum |
Kojto | 148:fd96258d940d | 92 | { |
Kojto | 148:fd96258d940d | 93 | NRF_SPIS_SHORT_END_ACQUIRE = SPIS_SHORTS_END_ACQUIRE_Msk ///< Shortcut between END event and ACQUIRE task. |
Kojto | 148:fd96258d940d | 94 | } nrf_spis_short_mask_t; |
Kojto | 148:fd96258d940d | 95 | |
Kojto | 148:fd96258d940d | 96 | /** |
Kojto | 148:fd96258d940d | 97 | * @brief SPIS interrupts. |
Kojto | 148:fd96258d940d | 98 | */ |
Kojto | 148:fd96258d940d | 99 | typedef enum |
Kojto | 148:fd96258d940d | 100 | { |
Kojto | 148:fd96258d940d | 101 | NRF_SPIS_INT_END_MASK = SPIS_INTENSET_END_Msk, ///< Interrupt on END event. |
Kojto | 148:fd96258d940d | 102 | NRF_SPIS_INT_ACQUIRED_MASK = SPIS_INTENSET_ACQUIRED_Msk ///< Interrupt on ACQUIRED event. |
Kojto | 148:fd96258d940d | 103 | } nrf_spis_int_mask_t; |
Kojto | 148:fd96258d940d | 104 | |
Kojto | 148:fd96258d940d | 105 | /** |
Kojto | 148:fd96258d940d | 106 | * @brief SPI modes. |
Kojto | 148:fd96258d940d | 107 | */ |
Kojto | 148:fd96258d940d | 108 | typedef enum |
Kojto | 148:fd96258d940d | 109 | { |
Kojto | 148:fd96258d940d | 110 | NRF_SPIS_MODE_0, ///< SCK active high, sample on leading edge of clock. |
Kojto | 148:fd96258d940d | 111 | NRF_SPIS_MODE_1, ///< SCK active high, sample on trailing edge of clock. |
Kojto | 148:fd96258d940d | 112 | NRF_SPIS_MODE_2, ///< SCK active low, sample on leading edge of clock. |
Kojto | 148:fd96258d940d | 113 | NRF_SPIS_MODE_3 ///< SCK active low, sample on trailing edge of clock. |
Kojto | 148:fd96258d940d | 114 | } nrf_spis_mode_t; |
Kojto | 148:fd96258d940d | 115 | |
Kojto | 148:fd96258d940d | 116 | /** |
Kojto | 148:fd96258d940d | 117 | * @brief SPI bit orders. |
Kojto | 148:fd96258d940d | 118 | */ |
Kojto | 148:fd96258d940d | 119 | typedef enum |
Kojto | 148:fd96258d940d | 120 | { |
Kojto | 148:fd96258d940d | 121 | NRF_SPIS_BIT_ORDER_MSB_FIRST = SPIS_CONFIG_ORDER_MsbFirst, ///< Most significant bit shifted out first. |
Kojto | 148:fd96258d940d | 122 | NRF_SPIS_BIT_ORDER_LSB_FIRST = SPIS_CONFIG_ORDER_LsbFirst ///< Least significant bit shifted out first. |
Kojto | 148:fd96258d940d | 123 | } nrf_spis_bit_order_t; |
Kojto | 148:fd96258d940d | 124 | |
Kojto | 148:fd96258d940d | 125 | /** |
Kojto | 148:fd96258d940d | 126 | * @brief SPI semaphore status. |
Kojto | 148:fd96258d940d | 127 | */ |
Kojto | 148:fd96258d940d | 128 | typedef enum |
Kojto | 148:fd96258d940d | 129 | { |
Kojto | 148:fd96258d940d | 130 | NRF_SPIS_SEMSTAT_FREE = 0, ///< Semaphore is free. |
Kojto | 148:fd96258d940d | 131 | NRF_SPIS_SEMSTAT_CPU = 1, ///< Semaphore is assigned to the CPU. |
Kojto | 148:fd96258d940d | 132 | NRF_SPIS_SEMSTAT_SPIS = 2, ///< Semaphore is assigned to the SPI slave. |
Kojto | 148:fd96258d940d | 133 | NRF_SPIS_SEMSTAT_CPUPENDING = 3 ///< Semaphore is assigned to the SPI, but a handover to the CPU is pending. |
Kojto | 148:fd96258d940d | 134 | } nrf_spis_semstat_t; |
Kojto | 148:fd96258d940d | 135 | |
Kojto | 148:fd96258d940d | 136 | /** |
Kojto | 148:fd96258d940d | 137 | * @brief SPIS status. |
Kojto | 148:fd96258d940d | 138 | */ |
Kojto | 148:fd96258d940d | 139 | typedef enum |
Kojto | 148:fd96258d940d | 140 | { |
Kojto | 148:fd96258d940d | 141 | NRF_SPIS_STATUS_OVERREAD = SPIS_STATUS_OVERREAD_Msk, ///< TX buffer over-read detected and prevented. |
Kojto | 148:fd96258d940d | 142 | NRF_SPIS_STATUS_OVERFLOW = SPIS_STATUS_OVERFLOW_Msk ///< RX buffer overflow detected and prevented. |
Kojto | 148:fd96258d940d | 143 | } nrf_spis_status_mask_t; |
Kojto | 148:fd96258d940d | 144 | |
Kojto | 148:fd96258d940d | 145 | /** |
Kojto | 148:fd96258d940d | 146 | * @brief Function for activating a specific SPIS task. |
Kojto | 148:fd96258d940d | 147 | * |
Kojto | 148:fd96258d940d | 148 | * @param[in] p_spis SPIS instance. |
Kojto | 148:fd96258d940d | 149 | * @param[in] spis_task Task to activate. |
Kojto | 148:fd96258d940d | 150 | */ |
Kojto | 148:fd96258d940d | 151 | __STATIC_INLINE void nrf_spis_task_trigger(NRF_SPIS_Type * p_spis, |
Kojto | 148:fd96258d940d | 152 | nrf_spis_task_t spis_task); |
Kojto | 148:fd96258d940d | 153 | |
Kojto | 148:fd96258d940d | 154 | /** |
Kojto | 148:fd96258d940d | 155 | * @brief Function for getting the address of a specific SPIS task register. |
Kojto | 148:fd96258d940d | 156 | * |
Kojto | 148:fd96258d940d | 157 | * @param[in] p_spis SPIS instance. |
Kojto | 148:fd96258d940d | 158 | * @param[in] spis_task Requested task. |
Kojto | 148:fd96258d940d | 159 | * |
Kojto | 148:fd96258d940d | 160 | * @return Address of the specified task register. |
Kojto | 148:fd96258d940d | 161 | */ |
Kojto | 148:fd96258d940d | 162 | __STATIC_INLINE uint32_t nrf_spis_task_address_get(NRF_SPIS_Type const * p_spis, |
Kojto | 148:fd96258d940d | 163 | nrf_spis_task_t spis_task); |
Kojto | 148:fd96258d940d | 164 | |
Kojto | 148:fd96258d940d | 165 | /** |
Kojto | 148:fd96258d940d | 166 | * @brief Function for clearing a specific SPIS event. |
Kojto | 148:fd96258d940d | 167 | * |
Kojto | 148:fd96258d940d | 168 | * @param[in] p_spis SPIS instance. |
Kojto | 148:fd96258d940d | 169 | * @param[in] spis_event Event to clear. |
Kojto | 148:fd96258d940d | 170 | */ |
Kojto | 148:fd96258d940d | 171 | __STATIC_INLINE void nrf_spis_event_clear(NRF_SPIS_Type * p_spis, |
Kojto | 148:fd96258d940d | 172 | nrf_spis_event_t spis_event); |
Kojto | 148:fd96258d940d | 173 | |
Kojto | 148:fd96258d940d | 174 | /** |
Kojto | 148:fd96258d940d | 175 | * @brief Function for checking the state of a specific SPIS event. |
Kojto | 148:fd96258d940d | 176 | * |
Kojto | 148:fd96258d940d | 177 | * @param[in] p_spis SPIS instance. |
Kojto | 148:fd96258d940d | 178 | * @param[in] spis_event Event to check. |
Kojto | 148:fd96258d940d | 179 | * |
Kojto | 148:fd96258d940d | 180 | * @retval true If the event is set. |
Kojto | 148:fd96258d940d | 181 | * @retval false If the event is not set. |
Kojto | 148:fd96258d940d | 182 | */ |
Kojto | 148:fd96258d940d | 183 | __STATIC_INLINE bool nrf_spis_event_check(NRF_SPIS_Type const * p_spis, |
Kojto | 148:fd96258d940d | 184 | nrf_spis_event_t spis_event); |
Kojto | 148:fd96258d940d | 185 | |
Kojto | 148:fd96258d940d | 186 | /** |
Kojto | 148:fd96258d940d | 187 | * @brief Function for getting the address of a specific SPIS event register. |
Kojto | 148:fd96258d940d | 188 | * |
Kojto | 148:fd96258d940d | 189 | * @param[in] p_spis SPIS instance. |
Kojto | 148:fd96258d940d | 190 | * @param[in] spis_event Requested event. |
Kojto | 148:fd96258d940d | 191 | * |
Kojto | 148:fd96258d940d | 192 | * @return Address of the specified event register. |
Kojto | 148:fd96258d940d | 193 | */ |
Kojto | 148:fd96258d940d | 194 | __STATIC_INLINE uint32_t nrf_spis_event_address_get(NRF_SPIS_Type const * p_spis, |
Kojto | 148:fd96258d940d | 195 | nrf_spis_event_t spis_event); |
Kojto | 148:fd96258d940d | 196 | |
Kojto | 148:fd96258d940d | 197 | /** |
Kojto | 148:fd96258d940d | 198 | * @brief Function for enabling specified shortcuts. |
Kojto | 148:fd96258d940d | 199 | * |
Kojto | 148:fd96258d940d | 200 | * @param[in] p_spis SPIS instance. |
Kojto | 148:fd96258d940d | 201 | * @param[in] spis_shorts_mask Shortcuts to enable. |
Kojto | 148:fd96258d940d | 202 | */ |
Kojto | 148:fd96258d940d | 203 | __STATIC_INLINE void nrf_spis_shorts_enable(NRF_SPIS_Type * p_spis, |
Kojto | 148:fd96258d940d | 204 | uint32_t spis_shorts_mask); |
Kojto | 148:fd96258d940d | 205 | |
Kojto | 148:fd96258d940d | 206 | /** |
Kojto | 148:fd96258d940d | 207 | * @brief Function for disabling specified shortcuts. |
Kojto | 148:fd96258d940d | 208 | * |
Kojto | 148:fd96258d940d | 209 | * @param[in] p_spis SPIS instance. |
Kojto | 148:fd96258d940d | 210 | * @param[in] spis_shorts_mask Shortcuts to disable. |
Kojto | 148:fd96258d940d | 211 | */ |
Kojto | 148:fd96258d940d | 212 | __STATIC_INLINE void nrf_spis_shorts_disable(NRF_SPIS_Type * p_spis, |
Kojto | 148:fd96258d940d | 213 | uint32_t spis_shorts_mask); |
Kojto | 148:fd96258d940d | 214 | |
Kojto | 148:fd96258d940d | 215 | /** |
Kojto | 148:fd96258d940d | 216 | * @brief Function for enabling specified interrupts. |
Kojto | 148:fd96258d940d | 217 | * |
Kojto | 148:fd96258d940d | 218 | * @param[in] p_spis SPIS instance. |
Kojto | 148:fd96258d940d | 219 | * @param[in] spis_int_mask Interrupts to enable. |
Kojto | 148:fd96258d940d | 220 | */ |
Kojto | 148:fd96258d940d | 221 | __STATIC_INLINE void nrf_spis_int_enable(NRF_SPIS_Type * p_spis, |
Kojto | 148:fd96258d940d | 222 | uint32_t spis_int_mask); |
Kojto | 148:fd96258d940d | 223 | |
Kojto | 148:fd96258d940d | 224 | /** |
Kojto | 148:fd96258d940d | 225 | * @brief Function for disabling specified interrupts. |
Kojto | 148:fd96258d940d | 226 | * |
Kojto | 148:fd96258d940d | 227 | * @param[in] p_spis SPIS instance. |
Kojto | 148:fd96258d940d | 228 | * @param[in] spis_int_mask Interrupts to disable. |
Kojto | 148:fd96258d940d | 229 | */ |
Kojto | 148:fd96258d940d | 230 | __STATIC_INLINE void nrf_spis_int_disable(NRF_SPIS_Type * p_spis, |
Kojto | 148:fd96258d940d | 231 | uint32_t spis_int_mask); |
Kojto | 148:fd96258d940d | 232 | |
Kojto | 148:fd96258d940d | 233 | /** |
Kojto | 148:fd96258d940d | 234 | * @brief Function for retrieving the state of a given interrupt. |
Kojto | 148:fd96258d940d | 235 | * |
Kojto | 148:fd96258d940d | 236 | * @param[in] p_spis SPIS instance. |
Kojto | 148:fd96258d940d | 237 | * @param[in] spis_int Interrupt to check. |
Kojto | 148:fd96258d940d | 238 | * |
Kojto | 148:fd96258d940d | 239 | * @retval true If the interrupt is enabled. |
Kojto | 148:fd96258d940d | 240 | * @retval false If the interrupt is not enabled. |
Kojto | 148:fd96258d940d | 241 | */ |
Kojto | 148:fd96258d940d | 242 | __STATIC_INLINE bool nrf_spis_int_enable_check(NRF_SPIS_Type const * p_spis, |
Kojto | 148:fd96258d940d | 243 | nrf_spis_int_mask_t spis_int); |
Kojto | 148:fd96258d940d | 244 | |
Kojto | 148:fd96258d940d | 245 | /** |
Kojto | 148:fd96258d940d | 246 | * @brief Function for enabling the SPIS peripheral. |
Kojto | 148:fd96258d940d | 247 | * |
Kojto | 148:fd96258d940d | 248 | * @param[in] p_spis SPIS instance. |
Kojto | 148:fd96258d940d | 249 | */ |
Kojto | 148:fd96258d940d | 250 | __STATIC_INLINE void nrf_spis_enable(NRF_SPIS_Type * p_spis); |
Kojto | 148:fd96258d940d | 251 | |
Kojto | 148:fd96258d940d | 252 | /** |
Kojto | 148:fd96258d940d | 253 | * @brief Function for disabling the SPIS peripheral. |
Kojto | 148:fd96258d940d | 254 | * |
Kojto | 148:fd96258d940d | 255 | * @param[in] p_spis SPIS instance. |
Kojto | 148:fd96258d940d | 256 | */ |
Kojto | 148:fd96258d940d | 257 | __STATIC_INLINE void nrf_spis_disable(NRF_SPIS_Type * p_spis); |
Kojto | 148:fd96258d940d | 258 | |
Kojto | 148:fd96258d940d | 259 | /** |
Kojto | 148:fd96258d940d | 260 | * @brief Function for retrieving the SPIS semaphore status. |
Kojto | 148:fd96258d940d | 261 | * |
Kojto | 148:fd96258d940d | 262 | * @param[in] p_spis SPIS instance. |
Kojto | 148:fd96258d940d | 263 | * |
Kojto | 148:fd96258d940d | 264 | * @returns Current semaphore status. |
Kojto | 148:fd96258d940d | 265 | */ |
Kojto | 148:fd96258d940d | 266 | __STATIC_INLINE nrf_spis_semstat_t nrf_spis_semaphore_status_get(NRF_SPIS_Type * p_spis); |
Kojto | 148:fd96258d940d | 267 | |
Kojto | 148:fd96258d940d | 268 | /** |
Kojto | 148:fd96258d940d | 269 | * @brief Function for retrieving the SPIS status. |
Kojto | 148:fd96258d940d | 270 | * |
Kojto | 148:fd96258d940d | 271 | * @param[in] p_spis SPIS instance. |
Kojto | 148:fd96258d940d | 272 | * |
Kojto | 148:fd96258d940d | 273 | * @returns Current SPIS status. |
Kojto | 148:fd96258d940d | 274 | */ |
Kojto | 148:fd96258d940d | 275 | __STATIC_INLINE nrf_spis_status_mask_t nrf_spis_status_get(NRF_SPIS_Type * p_spis); |
Kojto | 148:fd96258d940d | 276 | |
Kojto | 148:fd96258d940d | 277 | /** |
Kojto | 148:fd96258d940d | 278 | * @brief Function for configuring SPIS pins. |
Kojto | 148:fd96258d940d | 279 | * |
Kojto | 148:fd96258d940d | 280 | * If a given signal is not needed, pass the @ref NRF_SPIS_PIN_NOT_CONNECTED |
Kojto | 148:fd96258d940d | 281 | * value instead of its pin number. |
Kojto | 148:fd96258d940d | 282 | * |
Kojto | 148:fd96258d940d | 283 | * @param[in] p_spis SPIS instance. |
Kojto | 148:fd96258d940d | 284 | * @param[in] sck_pin SCK pin number. |
Kojto | 148:fd96258d940d | 285 | * @param[in] mosi_pin MOSI pin number. |
Kojto | 148:fd96258d940d | 286 | * @param[in] miso_pin MISO pin number. |
Kojto | 148:fd96258d940d | 287 | * @param[in] csn_pin CSN pin number. |
Kojto | 148:fd96258d940d | 288 | */ |
Kojto | 148:fd96258d940d | 289 | __STATIC_INLINE void nrf_spis_pins_set(NRF_SPIS_Type * p_spis, |
Kojto | 148:fd96258d940d | 290 | uint32_t sck_pin, |
Kojto | 148:fd96258d940d | 291 | uint32_t mosi_pin, |
Kojto | 148:fd96258d940d | 292 | uint32_t miso_pin, |
Kojto | 148:fd96258d940d | 293 | uint32_t csn_pin); |
Kojto | 148:fd96258d940d | 294 | |
Kojto | 148:fd96258d940d | 295 | /** |
Kojto | 148:fd96258d940d | 296 | * @brief Function for setting the transmit buffer. |
Kojto | 148:fd96258d940d | 297 | * |
Kojto | 148:fd96258d940d | 298 | * @param[in] p_spis SPIS instance. |
Kojto | 148:fd96258d940d | 299 | * @param[in] p_buffer Pointer to the buffer that contains the data to send. |
Kojto | 148:fd96258d940d | 300 | * @param[in] length Maximum number of data bytes to transmit. |
Kojto | 148:fd96258d940d | 301 | */ |
Kojto | 148:fd96258d940d | 302 | __STATIC_INLINE void nrf_spis_tx_buffer_set(NRF_SPIS_Type * p_spis, |
Kojto | 148:fd96258d940d | 303 | uint8_t const * p_buffer, |
Kojto | 148:fd96258d940d | 304 | uint8_t length); |
Kojto | 148:fd96258d940d | 305 | |
Kojto | 148:fd96258d940d | 306 | /** |
Kojto | 148:fd96258d940d | 307 | * @brief Function for setting the receive buffer. |
Kojto | 148:fd96258d940d | 308 | * |
Kojto | 148:fd96258d940d | 309 | * @param[in] p_spis SPIS instance. |
Kojto | 148:fd96258d940d | 310 | * @param[in] p_buffer Pointer to the buffer for received data. |
Kojto | 148:fd96258d940d | 311 | * @param[in] length Maximum number of data bytes to receive. |
Kojto | 148:fd96258d940d | 312 | */ |
Kojto | 148:fd96258d940d | 313 | __STATIC_INLINE void nrf_spis_rx_buffer_set(NRF_SPIS_Type * p_spis, |
Kojto | 148:fd96258d940d | 314 | uint8_t * p_buffer, |
Kojto | 148:fd96258d940d | 315 | uint8_t length); |
Kojto | 148:fd96258d940d | 316 | |
Kojto | 148:fd96258d940d | 317 | /** |
Kojto | 148:fd96258d940d | 318 | * @brief Function for getting the number of bytes transmitted |
Kojto | 148:fd96258d940d | 319 | * in the last granted transaction. |
Kojto | 148:fd96258d940d | 320 | * |
Kojto | 148:fd96258d940d | 321 | * @param[in] p_spis SPIS instance. |
Kojto | 148:fd96258d940d | 322 | * |
Kojto | 148:fd96258d940d | 323 | * @returns Number of bytes transmitted. |
Kojto | 148:fd96258d940d | 324 | */ |
Kojto | 148:fd96258d940d | 325 | __STATIC_INLINE uint8_t nrf_spis_tx_amount_get(NRF_SPIS_Type const * p_spis); |
Kojto | 148:fd96258d940d | 326 | |
Kojto | 148:fd96258d940d | 327 | /** |
Kojto | 148:fd96258d940d | 328 | * @brief Function for getting the number of bytes received |
Kojto | 148:fd96258d940d | 329 | * in the last granted transaction. |
Kojto | 148:fd96258d940d | 330 | * |
Kojto | 148:fd96258d940d | 331 | * @param[in] p_spis SPIS instance. |
Kojto | 148:fd96258d940d | 332 | * |
Kojto | 148:fd96258d940d | 333 | * @returns Number of bytes received. |
Kojto | 148:fd96258d940d | 334 | */ |
Kojto | 148:fd96258d940d | 335 | __STATIC_INLINE uint8_t nrf_spis_rx_amount_get(NRF_SPIS_Type const * p_spis); |
Kojto | 148:fd96258d940d | 336 | |
Kojto | 148:fd96258d940d | 337 | /** |
Kojto | 148:fd96258d940d | 338 | * @brief Function for setting the SPI configuration. |
Kojto | 148:fd96258d940d | 339 | * |
Kojto | 148:fd96258d940d | 340 | * @param[in] p_spis SPIS instance. |
Kojto | 148:fd96258d940d | 341 | * @param[in] spi_mode SPI mode. |
Kojto | 148:fd96258d940d | 342 | * @param[in] spi_bit_order SPI bit order. |
Kojto | 148:fd96258d940d | 343 | */ |
Kojto | 148:fd96258d940d | 344 | __STATIC_INLINE void nrf_spis_configure(NRF_SPIS_Type * p_spis, |
Kojto | 148:fd96258d940d | 345 | nrf_spis_mode_t spi_mode, |
Kojto | 148:fd96258d940d | 346 | nrf_spis_bit_order_t spi_bit_order); |
Kojto | 148:fd96258d940d | 347 | |
Kojto | 148:fd96258d940d | 348 | /** |
Kojto | 148:fd96258d940d | 349 | * @brief Function for setting the default character. |
Kojto | 148:fd96258d940d | 350 | * |
Kojto | 148:fd96258d940d | 351 | * @param[in] p_spis SPIS instance. |
Kojto | 148:fd96258d940d | 352 | * @param[in] def Default character that is clocked out in case of |
Kojto | 148:fd96258d940d | 353 | * an overflow of the RXD buffer. |
Kojto | 148:fd96258d940d | 354 | */ |
Kojto | 148:fd96258d940d | 355 | __STATIC_INLINE void nrf_spis_def_set(NRF_SPIS_Type * p_spis, |
Kojto | 148:fd96258d940d | 356 | uint8_t def); |
Kojto | 148:fd96258d940d | 357 | |
Kojto | 148:fd96258d940d | 358 | /** |
Kojto | 148:fd96258d940d | 359 | * @brief Function for setting the over-read character. |
Kojto | 148:fd96258d940d | 360 | * |
Kojto | 148:fd96258d940d | 361 | * @param[in] p_spis SPIS instance. |
Kojto | 148:fd96258d940d | 362 | * @param[in] orc Over-read character that is clocked out in case of |
Kojto | 148:fd96258d940d | 363 | * an over-read of the TXD buffer. |
Kojto | 148:fd96258d940d | 364 | */ |
Kojto | 148:fd96258d940d | 365 | __STATIC_INLINE void nrf_spis_orc_set(NRF_SPIS_Type * p_spis, |
Kojto | 148:fd96258d940d | 366 | uint8_t orc); |
Kojto | 148:fd96258d940d | 367 | |
Kojto | 148:fd96258d940d | 368 | |
Kojto | 148:fd96258d940d | 369 | #ifndef SUPPRESS_INLINE_IMPLEMENTATION |
Kojto | 148:fd96258d940d | 370 | |
Kojto | 148:fd96258d940d | 371 | __STATIC_INLINE void nrf_spis_task_trigger(NRF_SPIS_Type * p_spis, |
Kojto | 148:fd96258d940d | 372 | nrf_spis_task_t spis_task) |
Kojto | 148:fd96258d940d | 373 | { |
Kojto | 148:fd96258d940d | 374 | *((volatile uint32_t *)((uint8_t *)p_spis + (uint32_t)spis_task)) = 0x1UL; |
Kojto | 148:fd96258d940d | 375 | } |
Kojto | 148:fd96258d940d | 376 | |
Kojto | 148:fd96258d940d | 377 | __STATIC_INLINE uint32_t nrf_spis_task_address_get(NRF_SPIS_Type const * p_spis, |
Kojto | 148:fd96258d940d | 378 | nrf_spis_task_t spis_task) |
Kojto | 148:fd96258d940d | 379 | { |
Kojto | 148:fd96258d940d | 380 | return (uint32_t)p_spis + (uint32_t)spis_task; |
Kojto | 148:fd96258d940d | 381 | } |
Kojto | 148:fd96258d940d | 382 | |
Kojto | 148:fd96258d940d | 383 | __STATIC_INLINE void nrf_spis_event_clear(NRF_SPIS_Type * p_spis, |
Kojto | 148:fd96258d940d | 384 | nrf_spis_event_t spis_event) |
Kojto | 148:fd96258d940d | 385 | { |
Kojto | 148:fd96258d940d | 386 | *((volatile uint32_t *)((uint8_t *)p_spis + (uint32_t)spis_event)) = 0x0UL; |
Kojto | 148:fd96258d940d | 387 | } |
Kojto | 148:fd96258d940d | 388 | |
Kojto | 148:fd96258d940d | 389 | __STATIC_INLINE bool nrf_spis_event_check(NRF_SPIS_Type const * p_spis, |
Kojto | 148:fd96258d940d | 390 | nrf_spis_event_t spis_event) |
Kojto | 148:fd96258d940d | 391 | { |
Kojto | 148:fd96258d940d | 392 | return (bool)*(volatile uint32_t *)((uint8_t *)p_spis + (uint32_t)spis_event); |
Kojto | 148:fd96258d940d | 393 | } |
Kojto | 148:fd96258d940d | 394 | |
Kojto | 148:fd96258d940d | 395 | __STATIC_INLINE uint32_t nrf_spis_event_address_get(NRF_SPIS_Type const * p_spis, |
Kojto | 148:fd96258d940d | 396 | nrf_spis_event_t spis_event) |
Kojto | 148:fd96258d940d | 397 | { |
Kojto | 148:fd96258d940d | 398 | return (uint32_t)p_spis + (uint32_t)spis_event; |
Kojto | 148:fd96258d940d | 399 | } |
Kojto | 148:fd96258d940d | 400 | |
Kojto | 148:fd96258d940d | 401 | __STATIC_INLINE void nrf_spis_shorts_enable(NRF_SPIS_Type * p_spis, |
Kojto | 148:fd96258d940d | 402 | uint32_t spis_shorts_mask) |
Kojto | 148:fd96258d940d | 403 | { |
Kojto | 148:fd96258d940d | 404 | p_spis->SHORTS |= spis_shorts_mask; |
Kojto | 148:fd96258d940d | 405 | } |
Kojto | 148:fd96258d940d | 406 | |
Kojto | 148:fd96258d940d | 407 | __STATIC_INLINE void nrf_spis_shorts_disable(NRF_SPIS_Type * p_spis, |
Kojto | 148:fd96258d940d | 408 | uint32_t spis_shorts_mask) |
Kojto | 148:fd96258d940d | 409 | { |
Kojto | 148:fd96258d940d | 410 | p_spis->SHORTS &= ~(spis_shorts_mask); |
Kojto | 148:fd96258d940d | 411 | } |
Kojto | 148:fd96258d940d | 412 | |
Kojto | 148:fd96258d940d | 413 | __STATIC_INLINE void nrf_spis_int_enable(NRF_SPIS_Type * p_spis, |
Kojto | 148:fd96258d940d | 414 | uint32_t spis_int_mask) |
Kojto | 148:fd96258d940d | 415 | { |
Kojto | 148:fd96258d940d | 416 | p_spis->INTENSET = spis_int_mask; |
Kojto | 148:fd96258d940d | 417 | } |
Kojto | 148:fd96258d940d | 418 | |
Kojto | 148:fd96258d940d | 419 | __STATIC_INLINE void nrf_spis_int_disable(NRF_SPIS_Type * p_spis, |
Kojto | 148:fd96258d940d | 420 | uint32_t spis_int_mask) |
Kojto | 148:fd96258d940d | 421 | { |
Kojto | 148:fd96258d940d | 422 | p_spis->INTENCLR = spis_int_mask; |
Kojto | 148:fd96258d940d | 423 | } |
Kojto | 148:fd96258d940d | 424 | |
Kojto | 148:fd96258d940d | 425 | __STATIC_INLINE bool nrf_spis_int_enable_check(NRF_SPIS_Type const * p_spis, |
Kojto | 148:fd96258d940d | 426 | nrf_spis_int_mask_t spis_int) |
Kojto | 148:fd96258d940d | 427 | { |
Kojto | 148:fd96258d940d | 428 | return (bool)(p_spis->INTENSET & spis_int); |
Kojto | 148:fd96258d940d | 429 | } |
Kojto | 148:fd96258d940d | 430 | |
Kojto | 148:fd96258d940d | 431 | __STATIC_INLINE void nrf_spis_enable(NRF_SPIS_Type * p_spis) |
Kojto | 148:fd96258d940d | 432 | { |
Kojto | 148:fd96258d940d | 433 | p_spis->ENABLE = (SPIS_ENABLE_ENABLE_Enabled << SPIS_ENABLE_ENABLE_Pos); |
Kojto | 148:fd96258d940d | 434 | } |
Kojto | 148:fd96258d940d | 435 | |
Kojto | 148:fd96258d940d | 436 | __STATIC_INLINE void nrf_spis_disable(NRF_SPIS_Type * p_spis) |
Kojto | 148:fd96258d940d | 437 | { |
Kojto | 148:fd96258d940d | 438 | p_spis->ENABLE = (SPIS_ENABLE_ENABLE_Disabled << SPIS_ENABLE_ENABLE_Pos); |
Kojto | 148:fd96258d940d | 439 | } |
Kojto | 148:fd96258d940d | 440 | |
Kojto | 148:fd96258d940d | 441 | __STATIC_INLINE nrf_spis_semstat_t nrf_spis_semaphore_status_get(NRF_SPIS_Type * p_spis) |
Kojto | 148:fd96258d940d | 442 | { |
Kojto | 148:fd96258d940d | 443 | return (nrf_spis_semstat_t) ((p_spis->SEMSTAT & SPIS_SEMSTAT_SEMSTAT_Msk) |
Kojto | 148:fd96258d940d | 444 | >> SPIS_SEMSTAT_SEMSTAT_Pos); |
Kojto | 148:fd96258d940d | 445 | } |
Kojto | 148:fd96258d940d | 446 | |
Kojto | 148:fd96258d940d | 447 | __STATIC_INLINE nrf_spis_status_mask_t nrf_spis_status_get(NRF_SPIS_Type * p_spis) |
Kojto | 148:fd96258d940d | 448 | { |
Kojto | 148:fd96258d940d | 449 | return (nrf_spis_status_mask_t) p_spis->STATUS; |
Kojto | 148:fd96258d940d | 450 | } |
Kojto | 148:fd96258d940d | 451 | |
Kojto | 148:fd96258d940d | 452 | __STATIC_INLINE void nrf_spis_pins_set(NRF_SPIS_Type * p_spis, |
Kojto | 148:fd96258d940d | 453 | uint32_t sck_pin, |
Kojto | 148:fd96258d940d | 454 | uint32_t mosi_pin, |
Kojto | 148:fd96258d940d | 455 | uint32_t miso_pin, |
Kojto | 148:fd96258d940d | 456 | uint32_t csn_pin) |
Kojto | 148:fd96258d940d | 457 | { |
Kojto | 148:fd96258d940d | 458 | p_spis->PSELSCK = sck_pin; |
Kojto | 148:fd96258d940d | 459 | p_spis->PSELMOSI = mosi_pin; |
Kojto | 148:fd96258d940d | 460 | p_spis->PSELMISO = miso_pin; |
Kojto | 148:fd96258d940d | 461 | p_spis->PSELCSN = csn_pin; |
Kojto | 148:fd96258d940d | 462 | } |
Kojto | 148:fd96258d940d | 463 | |
Kojto | 148:fd96258d940d | 464 | __STATIC_INLINE void nrf_spis_tx_buffer_set(NRF_SPIS_Type * p_spis, |
Kojto | 148:fd96258d940d | 465 | uint8_t const * p_buffer, |
Kojto | 148:fd96258d940d | 466 | uint8_t length) |
Kojto | 148:fd96258d940d | 467 | { |
Kojto | 148:fd96258d940d | 468 | p_spis->TXDPTR = (uint32_t)p_buffer; |
Kojto | 148:fd96258d940d | 469 | p_spis->MAXTX = length; |
Kojto | 148:fd96258d940d | 470 | } |
Kojto | 148:fd96258d940d | 471 | |
Kojto | 148:fd96258d940d | 472 | __STATIC_INLINE void nrf_spis_rx_buffer_set(NRF_SPIS_Type * p_spis, |
Kojto | 148:fd96258d940d | 473 | uint8_t * p_buffer, |
Kojto | 148:fd96258d940d | 474 | uint8_t length) |
Kojto | 148:fd96258d940d | 475 | { |
Kojto | 148:fd96258d940d | 476 | p_spis->RXDPTR = (uint32_t)p_buffer; |
Kojto | 148:fd96258d940d | 477 | p_spis->MAXRX = length; |
Kojto | 148:fd96258d940d | 478 | } |
Kojto | 148:fd96258d940d | 479 | |
Kojto | 148:fd96258d940d | 480 | __STATIC_INLINE uint8_t nrf_spis_tx_amount_get(NRF_SPIS_Type const * p_spis) |
Kojto | 148:fd96258d940d | 481 | { |
Kojto | 148:fd96258d940d | 482 | return (uint8_t) p_spis->AMOUNTRX; |
Kojto | 148:fd96258d940d | 483 | } |
Kojto | 148:fd96258d940d | 484 | |
Kojto | 148:fd96258d940d | 485 | __STATIC_INLINE uint8_t nrf_spis_rx_amount_get(NRF_SPIS_Type const * p_spis) |
Kojto | 148:fd96258d940d | 486 | { |
Kojto | 148:fd96258d940d | 487 | return (uint8_t) p_spis->AMOUNTTX; |
Kojto | 148:fd96258d940d | 488 | } |
Kojto | 148:fd96258d940d | 489 | |
Kojto | 148:fd96258d940d | 490 | __STATIC_INLINE void nrf_spis_configure(NRF_SPIS_Type * p_spis, |
Kojto | 148:fd96258d940d | 491 | nrf_spis_mode_t spi_mode, |
Kojto | 148:fd96258d940d | 492 | nrf_spis_bit_order_t spi_bit_order) |
Kojto | 148:fd96258d940d | 493 | { |
Kojto | 148:fd96258d940d | 494 | uint32_t config = (spi_bit_order == NRF_SPIS_BIT_ORDER_MSB_FIRST ? |
Kojto | 148:fd96258d940d | 495 | SPIS_CONFIG_ORDER_MsbFirst : SPIS_CONFIG_ORDER_LsbFirst); |
Kojto | 148:fd96258d940d | 496 | |
Kojto | 148:fd96258d940d | 497 | switch (spi_mode) |
Kojto | 148:fd96258d940d | 498 | { |
Kojto | 148:fd96258d940d | 499 | default: |
Kojto | 148:fd96258d940d | 500 | case NRF_SPIS_MODE_0: |
Kojto | 148:fd96258d940d | 501 | config |= (SPIS_CONFIG_CPOL_ActiveHigh << SPIS_CONFIG_CPOL_Pos) | |
Kojto | 148:fd96258d940d | 502 | (SPIS_CONFIG_CPHA_Leading << SPIS_CONFIG_CPHA_Pos); |
Kojto | 148:fd96258d940d | 503 | break; |
Kojto | 148:fd96258d940d | 504 | |
Kojto | 148:fd96258d940d | 505 | case NRF_SPIS_MODE_1: |
Kojto | 148:fd96258d940d | 506 | config |= (SPIS_CONFIG_CPOL_ActiveHigh << SPIS_CONFIG_CPOL_Pos) | |
Kojto | 148:fd96258d940d | 507 | (SPIS_CONFIG_CPHA_Trailing << SPIS_CONFIG_CPHA_Pos); |
Kojto | 148:fd96258d940d | 508 | break; |
Kojto | 148:fd96258d940d | 509 | |
Kojto | 148:fd96258d940d | 510 | case NRF_SPIS_MODE_2: |
Kojto | 148:fd96258d940d | 511 | config |= (SPIS_CONFIG_CPOL_ActiveLow << SPIS_CONFIG_CPOL_Pos) | |
Kojto | 148:fd96258d940d | 512 | (SPIS_CONFIG_CPHA_Leading << SPIS_CONFIG_CPHA_Pos); |
Kojto | 148:fd96258d940d | 513 | break; |
Kojto | 148:fd96258d940d | 514 | |
Kojto | 148:fd96258d940d | 515 | case NRF_SPIS_MODE_3: |
Kojto | 148:fd96258d940d | 516 | config |= (SPIS_CONFIG_CPOL_ActiveLow << SPIS_CONFIG_CPOL_Pos) | |
Kojto | 148:fd96258d940d | 517 | (SPIS_CONFIG_CPHA_Trailing << SPIS_CONFIG_CPHA_Pos); |
Kojto | 148:fd96258d940d | 518 | break; |
Kojto | 148:fd96258d940d | 519 | } |
Kojto | 148:fd96258d940d | 520 | p_spis->CONFIG = config; |
Kojto | 148:fd96258d940d | 521 | } |
Kojto | 148:fd96258d940d | 522 | |
Kojto | 148:fd96258d940d | 523 | __STATIC_INLINE void nrf_spis_orc_set(NRF_SPIS_Type * p_spis, |
Kojto | 148:fd96258d940d | 524 | uint8_t orc) |
Kojto | 148:fd96258d940d | 525 | { |
Kojto | 148:fd96258d940d | 526 | p_spis->ORC = orc; |
Kojto | 148:fd96258d940d | 527 | } |
Kojto | 148:fd96258d940d | 528 | |
Kojto | 148:fd96258d940d | 529 | __STATIC_INLINE void nrf_spis_def_set(NRF_SPIS_Type * p_spis, |
Kojto | 148:fd96258d940d | 530 | uint8_t def) |
Kojto | 148:fd96258d940d | 531 | { |
Kojto | 148:fd96258d940d | 532 | p_spis->DEF = def; |
Kojto | 148:fd96258d940d | 533 | } |
Kojto | 148:fd96258d940d | 534 | |
Kojto | 148:fd96258d940d | 535 | #endif // SUPPRESS_INLINE_IMPLEMENTATION |
Kojto | 148:fd96258d940d | 536 | |
Kojto | 148:fd96258d940d | 537 | #endif // NRF_SPIS_H__ |
Kojto | 148:fd96258d940d | 538 | |
Kojto | 148:fd96258d940d | 539 | /** @} */ |