diff --git a/CHANGELOG.md b/CHANGELOG.md index 288952877..71c0dd231 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,24 @@ # Changelog All notable changes to this project are documented in this file. +## [1.4.0] - 2018-11-30 +### Added +- Added the nrfx_is_word_aligned() function for checking whether an address is word-aligned. +- Added HAL for ACL. +- Added functions for disabling and re-enabling interrupts in the SWI driver. +- Added possibility to completely remove interrupt handling from the WDT driver. + +### Changed +- Updated the documentation for the nrfx_uarte_rx() function. It now correctly reflects the actual behavior of the function. + +### Fixed +- Corrected the type of the nrfx_uarte_xfer_evt_t structure field that holds the amount of transferred bytes. +- Corrected the way of disabling interrupts in the NFCT driver when moving the peripheral to the disabled state. +- Fixed a typo in the name of the bmRequest field in the nrfx_usbd_setup_t structure. The new correct name is bRequest. +- Fixed the nrfx_ppi_channel_fork_assign() function. It now accepts also pre-programmed channels. +- Fixed handling of long custom instruction responses in the QSPI driver. +- Fixed a bug affecting the conversion of time to ticks in the TIMER HAL. + ## [1.3.1] - 2018-09-28 ### Fixed - Corrected the type of nrfx_usbd_ep_status_get() return value. diff --git a/doc/config_dox/nrfx_wdt_dox_config.h b/doc/config_dox/nrfx_wdt_dox_config.h index c96b328b0..e2600a211 100644 --- a/doc/config_dox/nrfx_wdt_dox_config.h +++ b/doc/config_dox/nrfx_wdt_dox_config.h @@ -32,6 +32,16 @@ */ #define NRFX_WDT_CONFIG_RELOAD_VALUE +/** @brief Remove WDT IRQ handling from WDT driver + * + * Following options are available: + * - 0 - Include WDT IRQ handling + * - 1 - Remove WDT IRQ handling + * + * @note This is an NRF_CONFIG macro. + */ +#define NRFX_WDT_CONFIG_NO_IRQ + /** @brief Interrupt priority * * Following options are available: diff --git a/doc/drv_supp_matrix.dox b/doc/drv_supp_matrix.dox index 633a12307..7e33d48ff 100644 --- a/doc/drv_supp_matrix.dox +++ b/doc/drv_supp_matrix.dox @@ -6,6 +6,7 @@ This matrix shows which drivers are supported by particular Nordic SoCs. Driver | nRF51 Series | nRF52810 | nRF52832 | nRF52840 | -----------------|--------------|--------------| -------------| -------------| @ref nrf_adc |@tagGreenTick |@tagRedCross |@tagRedCross |@tagRedCross | +@ref nrf_acl |@tagRedCross |@tagRedCross |@tagRedCross |@tagGreenTick | @ref nrf_ccm |@tagGreenTick |@tagGreenTick |@tagGreenTick |@tagGreenTick | @ref nrf_clock |@tagGreenTick |@tagGreenTick |@tagGreenTick |@tagGreenTick | @ref nrf_comp |@tagRedCross |@tagGreenTick |@tagGreenTick |@tagGreenTick | diff --git a/doc/nrf52840.dox b/doc/nrf52840.dox index f9e3a56f6..38f3cffea 100644 --- a/doc/nrf52840.dox +++ b/doc/nrf52840.dox @@ -2,6 +2,8 @@ @page nrf52840_drivers nRF52840 Drivers @{ +@ref nrf_acl + @ref nrf_ccm @ref nrf_clock diff --git a/doc/nrfx.doxyfile b/doc/nrfx.doxyfile index d02eb0f34..93974c86a 100644 --- a/doc/nrfx.doxyfile +++ b/doc/nrfx.doxyfile @@ -33,7 +33,7 @@ PROJECT_NAME = "nrfx" # This could be handy for archiving the generated documentation or # if some version control system is used. -PROJECT_NUMBER = "1.3" +PROJECT_NUMBER = "1.4" ### EDIT THIS ### # Using the PROJECT_BRIEF tag one can provide an optional one line description diff --git a/doc/nrfx_api.dox b/doc/nrfx_api.dox index 4162c681e..6130ec4d7 100644 --- a/doc/nrfx_api.dox +++ b/doc/nrfx_api.dox @@ -4,6 +4,8 @@ @brief List of all drivers available in nrfx. @defgroup nrf_adc ADC +@defgroup nrf_acl ACL + @defgroup nrf_ccm CCM @defgroup nrf_clock CLOCK diff --git a/drivers/include/nrfx_ppi.h b/drivers/include/nrfx_ppi.h index 193148ebf..6db6adc6a 100644 --- a/drivers/include/nrfx_ppi.h +++ b/drivers/include/nrfx_ppi.h @@ -114,7 +114,6 @@ nrfx_err_t nrfx_ppi_channel_assign(nrf_ppi_channel_t channel, uint32_t eep, uint * * @retval NRFX_SUCCESS If the channel was successfully assigned. * @retval NRFX_ERROR_INVALID_STATE If the channel is not allocated for the user. - * @retval NRFX_ERROR_INVALID_PARAM If the channel is not user-configurable. * @retval NRFX_ERROR_NOT_SUPPORTED If function is not supported. */ nrfx_err_t nrfx_ppi_channel_fork_assign(nrf_ppi_channel_t channel, uint32_t fork_tep); diff --git a/drivers/include/nrfx_swi.h b/drivers/include/nrfx_swi.h index 37583e294..539b9f8f9 100644 --- a/drivers/include/nrfx_swi.h +++ b/drivers/include/nrfx_swi.h @@ -78,6 +78,9 @@ typedef void (*nrfx_swi_handler_t)(nrfx_swi_t swi, nrfx_swi_flags_t flags); /** * @brief Function for allocating the first unused SWI instance and setting a handler. * + * If provided handler is not NULL, an allocated SWI has its interrupt enabled by default. + * The interrupt can be disabled by @ref nrfx_swi_int_disable. + * * @param[out] p_swi Points to a place where the allocated SWI instance * number is to be stored. * @param[in] event_handler Event handler function. @@ -93,6 +96,22 @@ nrfx_err_t nrfx_swi_alloc(nrfx_swi_t * p_swi, nrfx_swi_handler_t event_handler, uint32_t irq_priority); +/** + * @brief Function for disabling an allocated SWI interrupt. + * + * Use @ref nrfx_swi_int_enable to re-enable the interrupt. + * + * @param[in] swi SWI instance. + */ +void nrfx_swi_int_disable(nrfx_swi_t swi); + +/** + * @brief Function for enabling an allocated SWI interrupt. + * + * @param[in] swi SWI instance. + */ +void nrfx_swi_int_enable(nrfx_swi_t swi); + /** * @brief Function for freeing a previously allocated SWI. * diff --git a/drivers/include/nrfx_uart.h b/drivers/include/nrfx_uart.h index 53bd7a4fa..855f1cc7e 100644 --- a/drivers/include/nrfx_uart.h +++ b/drivers/include/nrfx_uart.h @@ -250,25 +250,36 @@ void nrfx_uart_tx_abort(nrfx_uart_t const * p_instance); * * If an event handler was provided in the nrfx_uart_init() call, this function * returns immediately and the handler is called when the transfer is done. - * Otherwise, the transfer is performed in blocking mode, i.e. this function + * Otherwise, the transfer is performed in blocking mode, meaning that this function * returns when the transfer is finished. Blocking mode is not using interrupt so * there is no context switching inside the function. + * * The receive buffer pointer is double buffered in non-blocking mode. The secondary * buffer can be set immediately after starting the transfer and will be filled * when the primary buffer is full. The double buffering feature allows * receiving data continuously. * + * If this function is used without a previous call to @ref nrfx_uart_rx_enable, the reception + * will be stopped on error or when the supplied buffer fills up. In both cases, + * RX FIFO gets disabled. This means that, in case of error, the bytes that follow are lost. + * If this nrfx_uart_rx() function is used with the previous call to @ref nrfx_uart_rx_enable, + * the reception is stopped in case of error, but FIFO is still ongoing. The receiver is still + * working, so after handling the error, an immediate repeated call to this nrfx_uart_rx() + * function with fresh data buffer will re-establish reception. To disable the receiver, + * you must call @ref nrfx_uart_rx_disable explicitly. + * * @param[in] p_instance Pointer to the driver instance structure. * @param[in] p_data Pointer to data. * @param[in] length Number of bytes to receive. * - * @retval NRFX_SUCCESS If initialization was successful. - * @retval NRFX_ERROR_BUSY If the driver is already receiving - * (and the secondary buffer has already been set - * in non-blocking mode). + * @retval NRFX_SUCCESS If reception is complete (in case of blocking mode) or it is + * successfully started (in case of non-blocking mode). + * @retval NRFX_ERROR_BUSY If the driver is already receiving + * (and the secondary buffer has already been set + * in non-blocking mode). * @retval NRFX_ERROR_FORBIDDEN If the transfer was aborted from a different context - * (blocking mode only, also see @ref nrfx_uart_rx_disable). - * @retval NRFX_ERROR_INTERNAL If UART peripheral reported an error. + * (blocking mode only, also see @ref nrfx_uart_rx_disable). + * @retval NRFX_ERROR_INTERNAL If UART peripheral reported an error. */ nrfx_err_t nrfx_uart_rx(nrfx_uart_t const * p_instance, uint8_t * p_data, diff --git a/drivers/include/nrfx_uarte.h b/drivers/include/nrfx_uarte.h index 00ba08abc..9554c380e 100644 --- a/drivers/include/nrfx_uarte.h +++ b/drivers/include/nrfx_uarte.h @@ -122,7 +122,7 @@ typedef struct typedef struct { uint8_t * p_data; ///< Pointer to memory used for transfer. - uint8_t bytes; ///< Number of bytes transfered. + size_t bytes; ///< Number of bytes transfered. } nrfx_uarte_xfer_evt_t; /** diff --git a/drivers/include/nrfx_usbd.h b/drivers/include/nrfx_usbd.h index d60b5335b..756d4e9e5 100644 --- a/drivers/include/nrfx_usbd.h +++ b/drivers/include/nrfx_usbd.h @@ -371,7 +371,7 @@ typedef struct typedef struct { uint8_t bmRequestType; //!< byte 0 - uint8_t bmRequest; //!< byte 1 + uint8_t bRequest; //!< byte 1 uint16_t wValue; //!< byte 2, 3 uint16_t wIndex; //!< byte 4, 5 uint16_t wLength; //!< byte 6, 7 diff --git a/drivers/include/nrfx_wdt.h b/drivers/include/nrfx_wdt.h index ff00ff5b7..7124763ce 100644 --- a/drivers/include/nrfx_wdt.h +++ b/drivers/include/nrfx_wdt.h @@ -46,12 +46,23 @@ extern "C" { * @brief Watchdog Timer (WDT) peripheral driver. */ +#if !NRFX_CHECK(NRFX_WDT_CONFIG_NO_IRQ) || defined(__NRFX_DOXYGEN__) +/** + * @brief WDT instance interrupt priority configuration. + */ + #define NRFX_WDT_IRQ_CONFIG .interrupt_priority = NRFX_WDT_CONFIG_IRQ_PRIORITY +#else + #define NRFX_WDT_IRQ_CONFIG +#endif + /**@brief Struct for WDT initialization. */ typedef struct { nrf_wdt_behaviour_t behaviour; /**< WDT behaviour when CPU in sleep/halt mode. */ uint32_t reload_value; /**< WDT reload value in ms. */ +#if !NRFX_CHECK(NRFX_WDT_CONFIG_NO_IRQ) || defined(__NRFX_DOXYGEN__) uint8_t interrupt_priority; /**< WDT interrupt priority */ +#endif } nrfx_wdt_config_t; /**@brief WDT event handler function type. */ @@ -64,14 +75,14 @@ typedef nrf_wdt_rr_register_t nrfx_wdt_channel_id; { \ .behaviour = (nrf_wdt_behaviour_t)NRFX_WDT_CONFIG_BEHAVIOUR, \ .reload_value = NRFX_WDT_CONFIG_RELOAD_VALUE, \ - .interrupt_priority = NRFX_WDT_CONFIG_IRQ_PRIORITY, \ + NRFX_WDT_IRQ_CONFIG \ } /** * @brief This function initializes watchdog. * * @param[in] p_config Pointer to the structure with initial configuration. - * @param[in] wdt_event_handler Event handler provided by the user. - * Must not be NULL. + * @param[in] wdt_event_handler Event handler provided by the user. Ignored when + * @ref NRFX_WDT_CONFIG_NO_IRQ option is enabled. * * @return NRFX_SUCCESS on success, otherwise an error code. */ @@ -134,7 +145,9 @@ __STATIC_INLINE uint32_t nrfx_wdt_ppi_event_addr(nrf_wdt_event_t event) } +#if !NRFX_CHECK(NRFX_WDT_CONFIG_NO_IRQ) void nrfx_wdt_irq_handler(void); +#endif /** @} */ diff --git a/drivers/nrfx_common.h b/drivers/nrfx_common.h index 537f1ef6c..9423ee2fd 100644 --- a/drivers/nrfx_common.h +++ b/drivers/nrfx_common.h @@ -220,6 +220,22 @@ typedef enum */ __STATIC_INLINE bool nrfx_is_in_ram(void const * p_object); + +/** + * @brief Function for checking if an object is aligned to a 32-bit word + * + * Several peripherals (the ones using EasyDMA) require the transfer buffers + * to be aligned to a 32-bit word. This function can be used to check if + * this condition is met. + * + * @param[in] p_object Pointer to an object whose location is to be checked. + * + * @retval true if the pointed object is aligned to a 32-bit word. + * @retval false otherwise. + */ +__STATIC_INLINE bool nrfx_is_word_aligned(void const * p_object); + + /** * @brief Function for getting the interrupt number for a specific peripheral. * @@ -269,6 +285,11 @@ __STATIC_INLINE bool nrfx_is_in_ram(void const * p_object) return ((((uint32_t)p_object) & 0xE0000000u) == 0x20000000u); } +__STATIC_INLINE bool nrfx_is_word_aligned(void const * p_object) +{ + return ((((uint32_t)p_object) & 0x3u) == 0u); +} + __STATIC_INLINE IRQn_Type nrfx_get_irq_number(void const * p_reg) { return (IRQn_Type)NRFX_IRQ_NUMBER_GET(p_reg); diff --git a/drivers/src/nrfx_gpiote.c b/drivers/src/nrfx_gpiote.c index 00ac66db5..4de5d85e2 100644 --- a/drivers/src/nrfx_gpiote.c +++ b/drivers/src/nrfx_gpiote.c @@ -47,6 +47,9 @@ #define SENSE_FIELD_POS (6) #define SENSE_FIELD_MASK (0xC0) +/* Check if every pin can be encoded on provided number of bits. */ +NRFX_STATIC_ASSERT(NUMBER_OF_PINS <= (1 << SENSE_FIELD_POS)); + /** * @brief Macro for converting task-event index to an address of an event register. * diff --git a/drivers/src/nrfx_i2s.c b/drivers/src/nrfx_i2s.c index 76a12ad48..9448fe6e7 100644 --- a/drivers/src/nrfx_i2s.c +++ b/drivers/src/nrfx_i2s.c @@ -208,6 +208,12 @@ nrfx_err_t nrfx_i2s_start(nrfx_i2s_buffers_t const * p_initial_buffers, NRFX_ASSERT(p_initial_buffers != NULL); NRFX_ASSERT(p_initial_buffers->p_rx_buffer != NULL || p_initial_buffers->p_tx_buffer != NULL); + NRFX_ASSERT((p_initial_buffers->p_rx_buffer == NULL) || + (nrfx_is_in_ram(p_initial_buffers->p_rx_buffer) && + nrfx_is_word_aligned(p_initial_buffers->p_rx_buffer))); + NRFX_ASSERT((p_initial_buffers->p_tx_buffer == NULL) || + (nrfx_is_in_ram(p_initial_buffers->p_tx_buffer) && + nrfx_is_word_aligned(p_initial_buffers->p_tx_buffer))); NRFX_ASSERT(buffer_size != 0); (void)(flags); @@ -275,6 +281,12 @@ nrfx_err_t nrfx_i2s_next_buffers_set(nrfx_i2s_buffers_t const * p_buffers) { NRFX_ASSERT(m_cb.state == NRFX_DRV_STATE_POWERED_ON); NRFX_ASSERT(p_buffers); + NRFX_ASSERT((p_buffers->p_rx_buffer == NULL) || + (nrfx_is_in_ram(p_buffers->p_rx_buffer) && + nrfx_is_word_aligned(p_buffers->p_rx_buffer))); + NRFX_ASSERT((p_buffers->p_tx_buffer == NULL) || + (nrfx_is_in_ram(p_buffers->p_tx_buffer) && + nrfx_is_word_aligned(p_buffers->p_tx_buffer))); nrfx_err_t err_code; diff --git a/drivers/src/nrfx_nfct.c b/drivers/src/nrfx_nfct.c index 53ccb5077..b66411320 100644 --- a/drivers/src/nrfx_nfct.c +++ b/drivers/src/nrfx_nfct.c @@ -202,13 +202,6 @@ static void nrfx_nfct_hw_init_setup(void) } #endif // NRF52840_XXAA - //Enable necessary interrupts. - nrf_nfct_int_enable(NRF_NFCT_INT_FIELDDETECTED_MASK | NRF_NFCT_INT_ERROR_MASK | - NRF_NFCT_INT_SELECTED_MASK); -#if !defined(NRF52832_XXAA) && !defined(NRF52832_XXAB) - nrf_nfct_int_enable(NRF_NFCT_INT_FIELDLOST_MASK); -#endif //!defined(NRF52832_XXAA) && !defined(NRF52832_XXAB) - // Use Window Grid frame delay mode. nrf_nfct_frame_delay_mode_set(NRF_NFCT_FRAME_DELAY_MODE_WINDOWGRID); @@ -326,6 +319,7 @@ static void nrfx_nfct_activate_check(void) static inline void nrfx_nfct_reset(void) { uint32_t fdm; + uint32_t int_enabled; uint8_t nfcid1[NRF_NFCT_SENSRES_NFCID1_SIZE_TRIPLE]; nrf_nfct_sensres_nfcid1_size_t nfcid1_size; nrf_nfct_selres_protocol_t protocol; @@ -334,6 +328,7 @@ static inline void nrfx_nfct_reset(void) fdm = nrf_nfct_frame_delay_max_get(); nfcid1_size = nrf_nfct_nfcid1_get(nfcid1); protocol = nrf_nfct_selsres_protocol_get(); + int_enabled = nrf_nfct_int_enable_get(); // Reset the NFCT peripheral. *(volatile uint32_t *)0x40005FFC = 0; @@ -347,6 +342,10 @@ static inline void nrfx_nfct_reset(void) // Restore general HW configuration. nrfx_nfct_hw_init_setup(); + + // Restore interrupts. + nrf_nfct_int_enable(int_enabled); + NRFX_LOG_INFO("Reinitialize"); } @@ -466,6 +465,10 @@ nrfx_err_t nrfx_nfct_init(nrfx_nfct_config_t const * p_config) m_nfct_cb.config = *p_config; nrfx_nfct_hw_init_setup(); + NRFX_IRQ_PENDING_CLEAR(NFCT_IRQn); + NRFX_IRQ_PRIORITY_SET(NFCT_IRQn, NRFX_NFCT_CONFIG_IRQ_PRIORITY); + NRFX_IRQ_ENABLE(NFCT_IRQn); + #ifdef USE_TIMER_WORKAROUND /* Initialize Timer module as the workaround for NFCT HW issues. */ #ifdef NRF52840_XXAA @@ -498,6 +501,9 @@ void nrfx_nfct_uninit(void) { nrfx_nfct_disable(); + NRFX_IRQ_DISABLE(NFCT_IRQn); + NRFX_IRQ_PENDING_CLEAR(NFCT_IRQn); + #ifdef USE_TIMER_WORKAROUND /* Initialize Timer module as the workaround for NFCT HW issues. */ #ifdef NRF52840_XXAA @@ -516,15 +522,18 @@ void nrfx_nfct_enable(void) nrf_nfct_error_status_clear(NRFX_NFCT_ERROR_STATUS_ALL_MASK); nrf_nfct_task_trigger(NRF_NFCT_TASK_SENSE); - NRFX_IRQ_PENDING_CLEAR(NFCT_IRQn); - NRFX_IRQ_PRIORITY_SET(NFCT_IRQn, NRFX_NFCT_CONFIG_IRQ_PRIORITY); - NRFX_IRQ_ENABLE(NFCT_IRQn); + nrf_nfct_int_enable(NRF_NFCT_INT_FIELDDETECTED_MASK | NRF_NFCT_INT_ERROR_MASK | + NRF_NFCT_INT_SELECTED_MASK); +#if !defined(NRF52832_XXAA) && !defined(NRF52832_XXAB) + nrf_nfct_int_enable(NRF_NFCT_INT_FIELDLOST_MASK); +#endif //!defined(NRF52832_XXAA) && !defined(NRF52832_XXAB) NRFX_LOG_INFO("Start"); } void nrfx_nfct_disable(void) { + nrf_nfct_int_disable(NRF_NFCT_DISABLE_ALL_INT); nrf_nfct_task_trigger(NRF_NFCT_TASK_DISABLE); NRFX_LOG_INFO("Stop"); diff --git a/drivers/src/nrfx_ppi.c b/drivers/src/nrfx_ppi.c index 4dbffc985..b3c2d3543 100644 --- a/drivers/src/nrfx_ppi.c +++ b/drivers/src/nrfx_ppi.c @@ -310,11 +310,7 @@ nrfx_err_t nrfx_ppi_channel_fork_assign(nrf_ppi_channel_t channel, uint32_t fork { nrfx_err_t err_code = NRFX_SUCCESS; #ifdef PPI_FEATURE_FORKS_PRESENT - if (!is_programmable_app_channel(channel)) - { - err_code = NRFX_ERROR_INVALID_PARAM; - } - else if (!is_allocated_channel(channel)) + if (!is_allocated_channel(channel)) { err_code = NRFX_ERROR_INVALID_STATE; } diff --git a/drivers/src/nrfx_qspi.c b/drivers/src/nrfx_qspi.c index 8eae4d75b..feb4346b5 100644 --- a/drivers/src/nrfx_qspi.c +++ b/drivers/src/nrfx_qspi.c @@ -256,9 +256,6 @@ void nrfx_qspi_uninit(void) nrf_qspi_task_trigger(NRF_QSPI, NRF_QSPI_TASK_DEACTIVATE); - // Workaround for nRF52840 anomaly 122: Current consumption is too high. - *(volatile uint32_t *)0x40029054ul = 1ul; - nrf_qspi_disable(NRF_QSPI); NRFX_IRQ_DISABLE(QSPI_IRQn); @@ -274,6 +271,8 @@ nrfx_err_t nrfx_qspi_write(void const * p_tx_buffer, { NRFX_ASSERT(m_cb.state != NRFX_DRV_STATE_UNINITIALIZED); NRFX_ASSERT(p_tx_buffer != NULL); + NRFX_ASSERT(nrfx_is_in_ram(p_tx_buffer)); + NRFX_ASSERT(nrfx_is_word_aligned(p_tx_buffer)); if (!nrfx_is_in_ram(p_tx_buffer)) { @@ -291,6 +290,8 @@ nrfx_err_t nrfx_qspi_read(void * p_rx_buffer, { NRFX_ASSERT(m_cb.state != NRFX_DRV_STATE_UNINITIALIZED); NRFX_ASSERT(p_rx_buffer != NULL); + NRFX_ASSERT(nrfx_is_in_ram(p_rx_buffer)); + NRFX_ASSERT(nrfx_is_word_aligned(p_rx_buffer)); if (!nrfx_is_in_ram(p_rx_buffer)) { diff --git a/drivers/src/nrfx_swi.c b/drivers/src/nrfx_swi.c index e59a9c9df..9f75bd751 100644 --- a/drivers/src/nrfx_swi.c +++ b/drivers/src/nrfx_swi.c @@ -158,12 +158,8 @@ static IRQn_Type swi_irq_number_get(nrfx_swi_t swi) return (IRQn_Type)((uint32_t)SWI0_IRQn + (uint32_t)swi); } -static void swi_handler_setup(nrfx_swi_t swi, - nrfx_swi_handler_t event_handler, - uint32_t irq_priority) +static void swi_int_enable(nrfx_swi_t swi) { - m_swi_handlers[swi] = event_handler; - #if NRFX_SWI_EGU_COUNT if (swi < NRFX_SWI_EGU_COUNT) { @@ -171,17 +167,42 @@ static void swi_handler_setup(nrfx_swi_t swi, NRFX_ASSERT(p_egu != NULL); nrf_egu_int_enable(p_egu, NRF_EGU_INT_ALL); - if (event_handler == NULL) + if (m_swi_handlers[swi] == NULL) { return; } } #endif - NRFX_ASSERT(event_handler != NULL); + NRFX_IRQ_ENABLE(swi_irq_number_get(swi)); +} + +static void swi_int_disable(nrfx_swi_t swi) +{ + NRFX_IRQ_DISABLE(swi_irq_number_get(swi)); + +#if NRFX_SWI_EGU_COUNT + if (swi < NRFX_SWI_EGU_COUNT) + { + nrf_egu_int_disable(nrfx_swi_egu_instance_get(swi), NRF_EGU_INT_ALL); + } +#endif +} +static void swi_handler_setup(nrfx_swi_t swi, + nrfx_swi_handler_t event_handler, + uint32_t irq_priority) +{ + m_swi_handlers[swi] = event_handler; NRFX_IRQ_PRIORITY_SET(swi_irq_number_get(swi), irq_priority); - NRFX_IRQ_ENABLE(swi_irq_number_get(swi)); + swi_int_enable(swi); +} + +static void swi_deallocate(nrfx_swi_t swi) +{ + swi_int_disable(swi); + m_swi_handlers[swi] = NULL; + swi_mark_unallocated(swi); } nrfx_err_t nrfx_swi_alloc(nrfx_swi_t * p_swi, @@ -226,16 +247,26 @@ bool nrfx_swi_is_allocated(nrfx_swi_t swi) return swi_is_allocated(swi); } +void nrfx_swi_int_disable(nrfx_swi_t swi) +{ + NRFX_ASSERT(swi_is_allocated(swi)); + swi_int_disable(swi); +} + +void nrfx_swi_int_enable(nrfx_swi_t swi) +{ + NRFX_ASSERT(swi_is_allocated(swi)); + swi_int_enable(swi); +} + void nrfx_swi_free(nrfx_swi_t * p_swi) { NRFX_ASSERT(p_swi != NULL); nrfx_swi_t swi = *p_swi; NRFX_ASSERT(swi_is_allocated(swi)); - NRFX_IRQ_DISABLE(swi_irq_number_get(swi)); - m_swi_handlers[swi] = NULL; + swi_deallocate(swi); - swi_mark_unallocated(swi); *p_swi = NRFX_SWI_UNALLOCATED; } @@ -245,19 +276,9 @@ void nrfx_swi_all_free(void) { if (swi_is_allocated(swi)) { - NRFX_IRQ_DISABLE(swi_irq_number_get(swi)); - m_swi_handlers[swi] = NULL; -#if NRFX_SWI_EGU_COUNT - if (swi < NRFX_SWI_EGU_COUNT) - { - nrf_egu_int_disable(nrfx_swi_egu_instance_get(swi), - NRF_EGU_INT_ALL); - } -#endif + swi_deallocate(swi); } } - - m_swi_allocated_mask = 0; } void nrfx_swi_trigger(nrfx_swi_t swi, uint8_t flag_number) diff --git a/drivers/src/nrfx_usbd.c b/drivers/src/nrfx_usbd.c index 5663e02f7..71a1e6921 100644 --- a/drivers/src/nrfx_usbd.c +++ b/drivers/src/nrfx_usbd.c @@ -2282,7 +2282,7 @@ void nrfx_usbd_setup_get(nrfx_usbd_setup_t * p_setup) { memset(p_setup, 0, sizeof(nrfx_usbd_setup_t)); p_setup->bmRequestType = nrf_usbd_setup_bmrequesttype_get(); - p_setup->bmRequest = nrf_usbd_setup_brequest_get(); + p_setup->bRequest = nrf_usbd_setup_brequest_get(); p_setup->wValue = nrf_usbd_setup_wvalue_get(); p_setup->wIndex = nrf_usbd_setup_windex_get(); p_setup->wLength = nrf_usbd_setup_wlength_get(); diff --git a/drivers/src/nrfx_wdt.c b/drivers/src/nrfx_wdt.c index 4896a9fe6..db7c786ac 100644 --- a/drivers/src/nrfx_wdt.c +++ b/drivers/src/nrfx_wdt.c @@ -37,35 +37,41 @@ #define NRFX_LOG_MODULE WDT #include - -/**@brief WDT event handler. */ -static nrfx_wdt_event_handler_t m_wdt_event_handler; - /**@brief WDT state. */ static nrfx_drv_state_t m_state; /**@brief WDT alloc table. */ -static uint32_t m_alloc_index; +static uint8_t m_alloc_index; + +#if !NRFX_CHECK(NRFX_WDT_CONFIG_NO_IRQ) +/**@brief WDT event handler. */ +static nrfx_wdt_event_handler_t m_wdt_event_handler; /**@brief WDT interrupt handler. */ void nrfx_wdt_irq_handler(void) { - if (nrf_wdt_int_enable_check(NRF_WDT_INT_TIMEOUT_MASK) == true) + if (nrf_wdt_event_check(NRF_WDT_EVENT_TIMEOUT)) { m_wdt_event_handler(); nrf_wdt_event_clear(NRF_WDT_EVENT_TIMEOUT); } } +#endif nrfx_err_t nrfx_wdt_init(nrfx_wdt_config_t const * p_config, nrfx_wdt_event_handler_t wdt_event_handler) { NRFX_ASSERT(p_config); - NRFX_ASSERT(wdt_event_handler != NULL); nrfx_err_t err_code; - m_wdt_event_handler = wdt_event_handler; +#if !NRFX_CHECK(NRFX_WDT_CONFIG_NO_IRQ) + NRFX_ASSERT(wdt_event_handler != NULL); + m_wdt_event_handler = wdt_event_handler; +#else + NRFX_ASSERT(wdt_event_handler == NULL); + (void)wdt_event_handler; +#endif if (m_state == NRFX_DRV_STATE_UNINITIALIZED) { m_state = NRFX_DRV_STATE_INITIALIZED; @@ -83,8 +89,10 @@ nrfx_err_t nrfx_wdt_init(nrfx_wdt_config_t const * p_config, nrf_wdt_reload_value_set((p_config->reload_value * 32768) / 1000); +#if !NRFX_CHECK(NRFX_WDT_CONFIG_NO_IRQ) NRFX_IRQ_PRIORITY_SET(WDT_IRQn, p_config->interrupt_priority); NRFX_IRQ_ENABLE(WDT_IRQn); +#endif err_code = NRFX_SUCCESS; NRFX_LOG_INFO("Function: %s, error code: %s.", __func__, NRFX_LOG_ERROR_STRING_GET(err_code)); @@ -96,7 +104,9 @@ void nrfx_wdt_enable(void) { NRFX_ASSERT(m_alloc_index != 0); NRFX_ASSERT(m_state == NRFX_DRV_STATE_INITIALIZED); +#if !NRFX_CHECK(NRFX_WDT_CONFIG_NO_IRQ) nrf_wdt_int_enable(NRF_WDT_INT_TIMEOUT_MASK); +#endif nrf_wdt_task_trigger(NRF_WDT_TASK_START); m_state = NRFX_DRV_STATE_POWERED_ON; NRFX_LOG_INFO("Enabled."); @@ -106,7 +116,7 @@ void nrfx_wdt_enable(void) void nrfx_wdt_feed(void) { NRFX_ASSERT(m_state == NRFX_DRV_STATE_POWERED_ON); - for (uint32_t i = 0; i < m_alloc_index; i++) + for (uint8_t i = 0; i < m_alloc_index; i++) { nrf_wdt_reload_request_set((nrf_wdt_rr_register_t)(NRF_WDT_RR0 + i)); } diff --git a/hal/nrf_acl.h b/hal/nrf_acl.h new file mode 100644 index 000000000..99043d483 --- /dev/null +++ b/hal/nrf_acl.h @@ -0,0 +1,146 @@ +/* + * Copyright (c) 2018, Nordic Semiconductor ASA + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef NRF_ACL_H__ +#define NRF_ACL_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @defgroup nrf_acl_hal ACL HAL + * @{ + * @ingroup nrf_acl + * @brief Hardware access layer for managing the Access Control List (ACL) peripheral. + */ + +#define NRF_ACL_REGION_SIZE_MAX (512 * 1024UL) + +/** @brief ACL permissions. */ +typedef enum +{ + NRF_ACL_PERM_READ_NO_WRITE = ACL_ACL_PERM_WRITE_Msk, /**< Read allowed, write disallowed. */ + NRF_ACL_PERM_NO_READ_WRITE = ACL_ACL_PERM_READ_Msk, /**< Read disallowed, write allowed. */ + NRF_ACL_PERM_NO_READ_NO_WRITE = ACL_ACL_PERM_READ_Msk | ACL_ACL_PERM_WRITE_Msk /**< Read disallowed, write disallowed. */ +} nrf_acl_perm_t; + +/** + * @brief Function for setting region parameters for given ACL region. + * + * Address must be word and page aligned. Size must be page aligned. + * + * @param[in] p_reg Pointer to the peripheral register structure. + * @param[in] region_id ACL region index. + * @param[in] address Start address. + * @param[in] size Size of region to protect in bytes. + * @param[in] perm Permissions to set for region to protect. + */ +__STATIC_INLINE void nrf_acl_region_set(NRF_ACL_Type * p_reg, + uint32_t region_id, + uint32_t address, + size_t size, + nrf_acl_perm_t perm); + +/** + * @brief Function for getting the configured region address of a specific ACL region. + * + * @param[in] p_reg Pointer to the peripheral register structure. + * @param[in] region_id ACL region index. + * + * @return Configured region address of given ACL region. + */ +__STATIC_INLINE uint32_t nrf_acl_region_address_get(NRF_ACL_Type * p_reg, uint32_t region_id); + +/** + * @brief Function for getting the configured region size of a specific ACL region. + * + * @param[in] p_reg Pointer to the peripheral register structure. + * @param[in] region_id ACL region index. + * + * @return Configured region size of given ACL region. + */ +__STATIC_INLINE size_t nrf_acl_region_size_get(NRF_ACL_Type * p_reg, uint32_t region_id); + +/** + * @brief Function for getting the configured region permissions of a specific ACL region. + * + * @param[in] p_reg Pointer to the peripheral register structure. + * @param[in] region_id ACL region index. + * + * @return Configured region permissions of given ACL region. + */ +__STATIC_INLINE nrf_acl_perm_t nrf_acl_region_perm_get(NRF_ACL_Type * p_reg, uint32_t region_id); + +#ifndef SUPPRESS_INLINE_IMPLEMENTATION + +__STATIC_INLINE void nrf_acl_region_set(NRF_ACL_Type * p_reg, + uint32_t region_id, + uint32_t address, + size_t size, + nrf_acl_perm_t perm) +{ + NRFX_ASSERT(region_id < ACL_REGIONS_COUNT); + NRFX_ASSERT(address % NRF_FICR->CODEPAGESIZE == 0); + NRFX_ASSERT(size <= NRF_ACL_REGION_SIZE_MAX); + NRFX_ASSERT(size != 0); + + p_reg->ACL[region_id].ADDR = address; + p_reg->ACL[region_id].SIZE = size; + p_reg->ACL[region_id].PERM = perm; +} + +__STATIC_INLINE uint32_t nrf_acl_region_address_get(NRF_ACL_Type * p_reg, uint32_t region_id) +{ + return (uint32_t)p_reg->ACL[region_id].ADDR; +} + +__STATIC_INLINE size_t nrf_acl_region_size_get(NRF_ACL_Type * p_reg, uint32_t region_id) +{ + return (size_t)p_reg->ACL[region_id].SIZE; +} + +__STATIC_INLINE nrf_acl_perm_t nrf_acl_region_perm_get(NRF_ACL_Type * p_reg, uint32_t region_id) +{ + return (nrf_acl_perm_t)p_reg->ACL[region_id].PERM; +} + +#endif // SUPPRESS_INLINE_IMPLEMENTATION + +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif // NRF_ACL_H__ diff --git a/hal/nrf_lpcomp.h b/hal/nrf_lpcomp.h index d7347e602..50ee41fe3 100644 --- a/hal/nrf_lpcomp.h +++ b/hal/nrf_lpcomp.h @@ -179,30 +179,7 @@ typedef struct * * @param[in] p_config Configuration. */ -__STATIC_INLINE void nrf_lpcomp_configure(const nrf_lpcomp_config_t * p_config) -{ - NRF_LPCOMP->TASKS_STOP = 1; - NRF_LPCOMP->ENABLE = LPCOMP_ENABLE_ENABLE_Disabled << LPCOMP_ENABLE_ENABLE_Pos; - NRF_LPCOMP->REFSEL = - (p_config->reference << LPCOMP_REFSEL_REFSEL_Pos) & LPCOMP_REFSEL_REFSEL_Msk; - - //If external source is choosen extract analog reference index. - if ((p_config->reference & LPCOMP_REFSEL_REFSEL_ARef)==LPCOMP_REFSEL_REFSEL_ARef) - { - uint32_t extref = p_config->reference >> 16; - NRF_LPCOMP->EXTREFSEL = (extref << LPCOMP_EXTREFSEL_EXTREFSEL_Pos) & LPCOMP_EXTREFSEL_EXTREFSEL_Msk; - } - - NRF_LPCOMP->ANADETECT = - (p_config->detection << LPCOMP_ANADETECT_ANADETECT_Pos) & LPCOMP_ANADETECT_ANADETECT_Msk; -#ifdef LPCOMP_FEATURE_HYST_PRESENT - NRF_LPCOMP->HYST = ((p_config->hyst) << LPCOMP_HYST_HYST_Pos) & LPCOMP_HYST_HYST_Msk; -#endif //LPCOMP_FEATURE_HYST_PRESENT - NRF_LPCOMP->SHORTS = 0; - NRF_LPCOMP->INTENCLR = LPCOMP_INTENCLR_CROSS_Msk | LPCOMP_INTENCLR_UP_Msk | - LPCOMP_INTENCLR_DOWN_Msk | LPCOMP_INTENCLR_READY_Msk; -} - +__STATIC_INLINE void nrf_lpcomp_configure(const nrf_lpcomp_config_t * p_config); /** * @brief Function for selecting the LPCOMP input. @@ -211,16 +188,7 @@ __STATIC_INLINE void nrf_lpcomp_configure(const nrf_lpcomp_config_t * p_config) * * @param[in] input Input to be selected. */ -__STATIC_INLINE void nrf_lpcomp_input_select(nrf_lpcomp_input_t input) -{ - uint32_t lpcomp_enable_state = NRF_LPCOMP->ENABLE; - - NRF_LPCOMP->ENABLE = LPCOMP_ENABLE_ENABLE_Disabled << LPCOMP_ENABLE_ENABLE_Pos; - NRF_LPCOMP->PSEL = - ((uint32_t)input << LPCOMP_PSEL_PSEL_Pos) | (NRF_LPCOMP->PSEL & ~LPCOMP_PSEL_PSEL_Msk); - NRF_LPCOMP->ENABLE = lpcomp_enable_state; -} - +__STATIC_INLINE void nrf_lpcomp_input_select(nrf_lpcomp_input_t input); /** * @brief Function for enabling the Low Power Comparator. @@ -228,15 +196,7 @@ __STATIC_INLINE void nrf_lpcomp_input_select(nrf_lpcomp_input_t input) * This function enables LPCOMP. * */ -__STATIC_INLINE void nrf_lpcomp_enable(void) -{ - NRF_LPCOMP->ENABLE = LPCOMP_ENABLE_ENABLE_Enabled << LPCOMP_ENABLE_ENABLE_Pos; - NRF_LPCOMP->EVENTS_READY = 0; - NRF_LPCOMP->EVENTS_DOWN = 0; - NRF_LPCOMP->EVENTS_UP = 0; - NRF_LPCOMP->EVENTS_CROSS = 0; -} - +__STATIC_INLINE void nrf_lpcomp_enable(void); /** * @brief Function for disabling the Low Power Comparator. @@ -244,22 +204,14 @@ __STATIC_INLINE void nrf_lpcomp_enable(void) * This function disables LPCOMP. * */ -__STATIC_INLINE void nrf_lpcomp_disable(void) -{ - NRF_LPCOMP->ENABLE = LPCOMP_ENABLE_ENABLE_Disabled << LPCOMP_ENABLE_ENABLE_Pos; -} - +__STATIC_INLINE void nrf_lpcomp_disable(void); /** * @brief Function for getting the last LPCOMP compare result. * * @return The last compare result. If 0 then VIN+ < VIN-, if 1 then the opposite. */ -__STATIC_INLINE uint32_t nrf_lpcomp_result_get(void) -{ - return (uint32_t)NRF_LPCOMP->RESULT; -} - +__STATIC_INLINE uint32_t nrf_lpcomp_result_get(void); /** * @brief Function for enabling interrupts from LPCOMP. @@ -269,11 +221,7 @@ __STATIC_INLINE uint32_t nrf_lpcomp_result_get(void) * @sa nrf_lpcomp_int_disable() * @sa nrf_lpcomp_int_enable_check() */ -__STATIC_INLINE void nrf_lpcomp_int_enable(uint32_t lpcomp_int_mask) -{ - NRF_LPCOMP->INTENSET = lpcomp_int_mask; -} - +__STATIC_INLINE void nrf_lpcomp_int_enable(uint32_t lpcomp_int_mask); /** * @brief Function for disabling interrupts from LPCOMP. @@ -283,11 +231,7 @@ __STATIC_INLINE void nrf_lpcomp_int_enable(uint32_t lpcomp_int_mask) * @sa nrf_lpcomp_int_enable() * @sa nrf_lpcomp_int_enable_check() */ -__STATIC_INLINE void nrf_lpcomp_int_disable(uint32_t lpcomp_int_mask) -{ - NRF_LPCOMP->INTENCLR = lpcomp_int_mask; -} - +__STATIC_INLINE void nrf_lpcomp_int_disable(uint32_t lpcomp_int_mask); /** * @brief Function for getting the enabled interrupts of LPCOMP. @@ -299,11 +243,7 @@ __STATIC_INLINE void nrf_lpcomp_int_disable(uint32_t lpcomp_int_mask) * @sa nrf_lpcomp_int_enable() * @sa nrf_lpcomp_int_disable() */ -__STATIC_INLINE bool nrf_lpcomp_int_enable_check(uint32_t lpcomp_int_mask) -{ - return (NRF_LPCOMP->INTENSET & lpcomp_int_mask); // when read this register will return the value of INTEN. -} - +__STATIC_INLINE bool nrf_lpcomp_int_enable_check(uint32_t lpcomp_int_mask); /** * @brief Function for getting the address of a specific LPCOMP task register. @@ -312,11 +252,7 @@ __STATIC_INLINE bool nrf_lpcomp_int_enable_check(uint32_t lpcomp_int_mask) * * @return The address of the specified LPCOMP task. */ -__STATIC_INLINE uint32_t * nrf_lpcomp_task_address_get(nrf_lpcomp_task_t lpcomp_task) -{ - return (uint32_t *)((uint8_t *)NRF_LPCOMP + lpcomp_task); -} - +__STATIC_INLINE uint32_t * nrf_lpcomp_task_address_get(nrf_lpcomp_task_t lpcomp_task); /** * @brief Function for getting the address of a specific LPCOMP event register. @@ -325,11 +261,7 @@ __STATIC_INLINE uint32_t * nrf_lpcomp_task_address_get(nrf_lpcomp_task_t lpcomp_ * * @return The address of the specified LPCOMP event. */ -__STATIC_INLINE uint32_t * nrf_lpcomp_event_address_get(nrf_lpcomp_event_t lpcomp_event) -{ - return (uint32_t *)((uint8_t *)NRF_LPCOMP + lpcomp_event); -} - +__STATIC_INLINE uint32_t * nrf_lpcomp_event_address_get(nrf_lpcomp_event_t lpcomp_event); /** * @brief Function for setting LPCOMP shorts. @@ -337,11 +269,7 @@ __STATIC_INLINE uint32_t * nrf_lpcomp_event_address_get(nrf_lpcomp_event_t lpcom * @param[in] lpcomp_short_mask LPCOMP shorts by mask. * */ -__STATIC_INLINE void nrf_lpcomp_shorts_enable(uint32_t lpcomp_short_mask) -{ - NRF_LPCOMP->SHORTS |= lpcomp_short_mask; -} - +__STATIC_INLINE void nrf_lpcomp_shorts_enable(uint32_t lpcomp_short_mask); /** * @brief Function for clearing LPCOMP shorts by mask. @@ -349,11 +277,7 @@ __STATIC_INLINE void nrf_lpcomp_shorts_enable(uint32_t lpcomp_short_mask) * @param[in] lpcomp_short_mask LPCOMP shorts to be cleared. * */ -__STATIC_INLINE void nrf_lpcomp_shorts_disable(uint32_t lpcomp_short_mask) -{ - NRF_LPCOMP->SHORTS &= ~lpcomp_short_mask; -} - +__STATIC_INLINE void nrf_lpcomp_shorts_disable(uint32_t lpcomp_short_mask); /** * @brief Function for setting a specific LPCOMP task. @@ -361,11 +285,7 @@ __STATIC_INLINE void nrf_lpcomp_shorts_disable(uint32_t lpcomp_short_mask) * @param[in] lpcomp_task LPCOMP task to be set. * */ -__STATIC_INLINE void nrf_lpcomp_task_trigger(nrf_lpcomp_task_t lpcomp_task) -{ - *( (volatile uint32_t *)( (uint8_t *)NRF_LPCOMP + lpcomp_task) ) = 1; -} - +__STATIC_INLINE void nrf_lpcomp_task_trigger(nrf_lpcomp_task_t lpcomp_task); /** * @brief Function for clearing a specific LPCOMP event. @@ -373,6 +293,111 @@ __STATIC_INLINE void nrf_lpcomp_task_trigger(nrf_lpcomp_task_t lpcomp_task) * @param[in] lpcomp_event LPCOMP event to be cleared. * */ +__STATIC_INLINE void nrf_lpcomp_event_clear(nrf_lpcomp_event_t lpcomp_event); + +/** + * @brief Function for getting the state of a specific LPCOMP event. + * + * @retval true If the specified LPCOMP event is active. + * + */ +__STATIC_INLINE bool nrf_lpcomp_event_check(nrf_lpcomp_event_t lpcomp_event); + +#ifndef SUPPRESS_INLINE_IMPLEMENTATION + +__STATIC_INLINE void nrf_lpcomp_configure(const nrf_lpcomp_config_t * p_config) +{ + NRF_LPCOMP->TASKS_STOP = 1; + NRF_LPCOMP->ENABLE = LPCOMP_ENABLE_ENABLE_Disabled << LPCOMP_ENABLE_ENABLE_Pos; + NRF_LPCOMP->REFSEL = + (p_config->reference << LPCOMP_REFSEL_REFSEL_Pos) & LPCOMP_REFSEL_REFSEL_Msk; + + //If external source is choosen extract analog reference index. + if ((p_config->reference & LPCOMP_REFSEL_REFSEL_ARef)==LPCOMP_REFSEL_REFSEL_ARef) + { + uint32_t extref = p_config->reference >> 16; + NRF_LPCOMP->EXTREFSEL = (extref << LPCOMP_EXTREFSEL_EXTREFSEL_Pos) & LPCOMP_EXTREFSEL_EXTREFSEL_Msk; + } + + NRF_LPCOMP->ANADETECT = + (p_config->detection << LPCOMP_ANADETECT_ANADETECT_Pos) & LPCOMP_ANADETECT_ANADETECT_Msk; +#ifdef LPCOMP_FEATURE_HYST_PRESENT + NRF_LPCOMP->HYST = ((p_config->hyst) << LPCOMP_HYST_HYST_Pos) & LPCOMP_HYST_HYST_Msk; +#endif //LPCOMP_FEATURE_HYST_PRESENT + NRF_LPCOMP->SHORTS = 0; + NRF_LPCOMP->INTENCLR = LPCOMP_INTENCLR_CROSS_Msk | LPCOMP_INTENCLR_UP_Msk | + LPCOMP_INTENCLR_DOWN_Msk | LPCOMP_INTENCLR_READY_Msk; +} + +__STATIC_INLINE void nrf_lpcomp_input_select(nrf_lpcomp_input_t input) +{ + uint32_t lpcomp_enable_state = NRF_LPCOMP->ENABLE; + + NRF_LPCOMP->ENABLE = LPCOMP_ENABLE_ENABLE_Disabled << LPCOMP_ENABLE_ENABLE_Pos; + NRF_LPCOMP->PSEL = + ((uint32_t)input << LPCOMP_PSEL_PSEL_Pos) | (NRF_LPCOMP->PSEL & ~LPCOMP_PSEL_PSEL_Msk); + NRF_LPCOMP->ENABLE = lpcomp_enable_state; +} + +__STATIC_INLINE void nrf_lpcomp_enable(void) +{ + NRF_LPCOMP->ENABLE = LPCOMP_ENABLE_ENABLE_Enabled << LPCOMP_ENABLE_ENABLE_Pos; + NRF_LPCOMP->EVENTS_READY = 0; + NRF_LPCOMP->EVENTS_DOWN = 0; + NRF_LPCOMP->EVENTS_UP = 0; + NRF_LPCOMP->EVENTS_CROSS = 0; +} + +__STATIC_INLINE void nrf_lpcomp_disable(void) +{ + NRF_LPCOMP->ENABLE = LPCOMP_ENABLE_ENABLE_Disabled << LPCOMP_ENABLE_ENABLE_Pos; +} + +__STATIC_INLINE uint32_t nrf_lpcomp_result_get(void) +{ + return (uint32_t)NRF_LPCOMP->RESULT; +} + +__STATIC_INLINE void nrf_lpcomp_int_enable(uint32_t lpcomp_int_mask) +{ + NRF_LPCOMP->INTENSET = lpcomp_int_mask; +} + +__STATIC_INLINE void nrf_lpcomp_int_disable(uint32_t lpcomp_int_mask) +{ + NRF_LPCOMP->INTENCLR = lpcomp_int_mask; +} + +__STATIC_INLINE bool nrf_lpcomp_int_enable_check(uint32_t lpcomp_int_mask) +{ + return (NRF_LPCOMP->INTENSET & lpcomp_int_mask); // when read this register will return the value of INTEN. +} + +__STATIC_INLINE uint32_t * nrf_lpcomp_task_address_get(nrf_lpcomp_task_t lpcomp_task) +{ + return (uint32_t *)((uint8_t *)NRF_LPCOMP + lpcomp_task); +} + +__STATIC_INLINE uint32_t * nrf_lpcomp_event_address_get(nrf_lpcomp_event_t lpcomp_event) +{ + return (uint32_t *)((uint8_t *)NRF_LPCOMP + lpcomp_event); +} + +__STATIC_INLINE void nrf_lpcomp_shorts_enable(uint32_t lpcomp_short_mask) +{ + NRF_LPCOMP->SHORTS |= lpcomp_short_mask; +} + +__STATIC_INLINE void nrf_lpcomp_shorts_disable(uint32_t lpcomp_short_mask) +{ + NRF_LPCOMP->SHORTS &= ~lpcomp_short_mask; +} + +__STATIC_INLINE void nrf_lpcomp_task_trigger(nrf_lpcomp_task_t lpcomp_task) +{ + *( (volatile uint32_t *)( (uint8_t *)NRF_LPCOMP + lpcomp_task) ) = 1; +} + __STATIC_INLINE void nrf_lpcomp_event_clear(nrf_lpcomp_event_t lpcomp_event) { *( (volatile uint32_t *)( (uint8_t *)NRF_LPCOMP + lpcomp_event) ) = 0; @@ -382,22 +407,17 @@ __STATIC_INLINE void nrf_lpcomp_event_clear(nrf_lpcomp_event_t lpcomp_event) #endif } - -/** - * @brief Function for getting the state of a specific LPCOMP event. - * - * @retval true If the specified LPCOMP event is active. - * - */ __STATIC_INLINE bool nrf_lpcomp_event_check(nrf_lpcomp_event_t lpcomp_event) { return (bool) (*(volatile uint32_t *)( (uint8_t *)NRF_LPCOMP + lpcomp_event)); } +#endif // SUPPRESS_INLINE_IMPLEMENTATION + /** @} */ #ifdef __cplusplus } #endif -#endif /* NRF_LPCOMP_H_ */ +#endif // NRF_LPCOMP_H_ diff --git a/hal/nrf_nfct.h b/hal/nrf_nfct.h index 57560e16f..e07bc3704 100644 --- a/hal/nrf_nfct.h +++ b/hal/nrf_nfct.h @@ -46,7 +46,8 @@ extern "C" { * @brief Hardware access layer (HAL) for the Near Field Communication Tag (NFCT) peripheral. */ -#define NRF_NFCT_CRC_SIZE 2 /**< CRC size in bytes. */ +#define NRF_NFCT_CRC_SIZE 2 /**< CRC size in bytes. */ +#define NRF_NFCT_DISABLE_ALL_INT 0xFFFFFFFF /**< Value to disable all interrupts. */ /** * @brief NFCT tasks diff --git a/hal/nrf_pdm.h b/hal/nrf_pdm.h index f9a37b9db..5a512cd63 100644 --- a/hal/nrf_pdm.h +++ b/hal/nrf_pdm.h @@ -118,11 +118,7 @@ typedef enum * * @param[in] pdm_task PDM task. */ -__STATIC_INLINE void nrf_pdm_task_trigger(nrf_pdm_task_t pdm_task) -{ - *((volatile uint32_t *)((uint8_t *)NRF_PDM + (uint32_t)pdm_task)) = 0x1UL; -} - +__STATIC_INLINE void nrf_pdm_task_trigger(nrf_pdm_task_t pdm_task); /** * @brief Function for getting the address of a PDM task register. @@ -131,11 +127,7 @@ __STATIC_INLINE void nrf_pdm_task_trigger(nrf_pdm_task_t pdm_task) * * @return Address of the specified PDM task. */ -__STATIC_INLINE uint32_t nrf_pdm_task_address_get(nrf_pdm_task_t pdm_task) -{ - return (uint32_t)((uint8_t *)NRF_PDM + (uint32_t)pdm_task); -} - +__STATIC_INLINE uint32_t nrf_pdm_task_address_get(nrf_pdm_task_t pdm_task); /** * @brief Function for getting the state of a PDM event. @@ -144,26 +136,14 @@ __STATIC_INLINE uint32_t nrf_pdm_task_address_get(nrf_pdm_task_t pdm_task) * * @return State of the specified PDM event. */ -__STATIC_INLINE bool nrf_pdm_event_check(nrf_pdm_event_t pdm_event) -{ - return (bool)*(volatile uint32_t *)((uint8_t *)NRF_PDM + (uint32_t)pdm_event); -} - +__STATIC_INLINE bool nrf_pdm_event_check(nrf_pdm_event_t pdm_event); /** * @brief Function for clearing a PDM event. * * @param[in] pdm_event PDM event. */ -__STATIC_INLINE void nrf_pdm_event_clear(nrf_pdm_event_t pdm_event) -{ - *((volatile uint32_t *)((uint8_t *)NRF_PDM + (uint32_t)pdm_event)) = 0x0UL; -#if __CORTEX_M == 0x04 - volatile uint32_t dummy = *((volatile uint32_t *)((uint8_t *)NRF_PDM + (uint32_t)pdm_event)); - (void)dummy; -#endif -} - +__STATIC_INLINE void nrf_pdm_event_clear(nrf_pdm_event_t pdm_event); /** * @brief Function for getting the address of a PDM event register. @@ -172,22 +152,14 @@ __STATIC_INLINE void nrf_pdm_event_clear(nrf_pdm_event_t pdm_event) * * @return Address of the specified PDM event. */ -__STATIC_INLINE volatile uint32_t * nrf_pdm_event_address_get(nrf_pdm_event_t pdm_event) -{ - return (volatile uint32_t *)((uint8_t *)NRF_PDM + (uint32_t)pdm_event); -} - +__STATIC_INLINE volatile uint32_t * nrf_pdm_event_address_get(nrf_pdm_event_t pdm_event); /** * @brief Function for enabling PDM interrupts. * * @param[in] pdm_int_mask Interrupts to enable. */ -__STATIC_INLINE void nrf_pdm_int_enable(uint32_t pdm_int_mask) -{ - NRF_PDM->INTENSET = pdm_int_mask; -} - +__STATIC_INLINE void nrf_pdm_int_enable(uint32_t pdm_int_mask); /** * @brief Function for retrieving the state of PDM interrupts. @@ -197,42 +169,26 @@ __STATIC_INLINE void nrf_pdm_int_enable(uint32_t pdm_int_mask) * @retval true If all specified interrupts are enabled. * @retval false If at least one of the given interrupts is not enabled. */ -__STATIC_INLINE bool nrf_pdm_int_enable_check(uint32_t pdm_int_mask) -{ - return (bool)(NRF_PDM->INTENSET & pdm_int_mask); -} - +__STATIC_INLINE bool nrf_pdm_int_enable_check(uint32_t pdm_int_mask); /** * @brief Function for disabling interrupts. * * @param pdm_int_mask Interrupts to disable. */ -__STATIC_INLINE void nrf_pdm_int_disable(uint32_t pdm_int_mask) -{ - NRF_PDM->INTENCLR = pdm_int_mask; -} - +__STATIC_INLINE void nrf_pdm_int_disable(uint32_t pdm_int_mask); /** * @brief Function for enabling the PDM peripheral. * * The PDM peripheral must be enabled before use. */ -__STATIC_INLINE void nrf_pdm_enable(void) -{ - NRF_PDM->ENABLE = (PDM_ENABLE_ENABLE_Enabled << PDM_ENABLE_ENABLE_Pos); -} - +__STATIC_INLINE void nrf_pdm_enable(void); /** * @brief Function for disabling the PDM peripheral. */ -__STATIC_INLINE void nrf_pdm_disable(void) -{ - NRF_PDM->ENABLE = (PDM_ENABLE_ENABLE_Disabled << PDM_ENABLE_ENABLE_Pos); -} - +__STATIC_INLINE void nrf_pdm_disable(void); /** * @brief Function for checking if the PDM peripheral is enabled. @@ -240,11 +196,7 @@ __STATIC_INLINE void nrf_pdm_disable(void) * @retval true If the PDM peripheral is enabled. * @retval false If the PDM peripheral is not enabled. */ -__STATIC_INLINE bool nrf_pdm_enable_check(void) -{ - return (NRF_PDM->ENABLE == (PDM_ENABLE_ENABLE_Enabled << PDM_ENABLE_ENABLE_Pos)); -} - +__STATIC_INLINE bool nrf_pdm_enable_check(void); /** * @brief Function for setting the PDM operation mode. @@ -252,12 +204,7 @@ __STATIC_INLINE bool nrf_pdm_enable_check(void) * @param[in] pdm_mode PDM operation mode. * @param[in] pdm_edge PDM sampling mode. */ -__STATIC_INLINE void nrf_pdm_mode_set(nrf_pdm_mode_t pdm_mode, nrf_pdm_edge_t pdm_edge) -{ - NRF_PDM->MODE = ((pdm_mode << PDM_MODE_OPERATION_Pos) & PDM_MODE_OPERATION_Msk) - | ((pdm_edge << PDM_MODE_EDGE_Pos) & PDM_MODE_EDGE_Msk); -} - +__STATIC_INLINE void nrf_pdm_mode_set(nrf_pdm_mode_t pdm_mode, nrf_pdm_edge_t pdm_edge); /** * @brief Function for getting the PDM operation mode. @@ -265,33 +212,19 @@ __STATIC_INLINE void nrf_pdm_mode_set(nrf_pdm_mode_t pdm_mode, nrf_pdm_edge_t pd * @param[out] p_pdm_mode PDM operation mode. * @param[out] p_pdm_edge PDM sampling mode. */ -__STATIC_INLINE void nrf_pdm_mode_get(nrf_pdm_mode_t * p_pdm_mode, nrf_pdm_edge_t * p_pdm_edge) -{ - uint32_t mode = NRF_PDM->MODE; - *p_pdm_mode = (nrf_pdm_mode_t)((mode & PDM_MODE_OPERATION_Msk ) >> PDM_MODE_OPERATION_Pos); - *p_pdm_edge = (nrf_pdm_edge_t)((mode & PDM_MODE_EDGE_Msk ) >> PDM_MODE_EDGE_Pos); -} - +__STATIC_INLINE void nrf_pdm_mode_get(nrf_pdm_mode_t * p_pdm_mode, nrf_pdm_edge_t * p_pdm_edge); /** * @brief Function for setting the PDM clock frequency. * * @param[in] pdm_freq PDM clock frequency. */ -__STATIC_INLINE void nrf_pdm_clock_set(nrf_pdm_freq_t pdm_freq) -{ - NRF_PDM->PDMCLKCTRL = ((pdm_freq << PDM_PDMCLKCTRL_FREQ_Pos) & PDM_PDMCLKCTRL_FREQ_Msk); -} - +__STATIC_INLINE void nrf_pdm_clock_set(nrf_pdm_freq_t pdm_freq); /** * @brief Function for getting the PDM clock frequency. */ -__STATIC_INLINE nrf_pdm_freq_t nrf_pdm_clock_get(void) -{ - return (nrf_pdm_freq_t) ((NRF_PDM->PDMCLKCTRL << PDM_PDMCLKCTRL_FREQ_Pos) & PDM_PDMCLKCTRL_FREQ_Msk); -} - +__STATIC_INLINE nrf_pdm_freq_t nrf_pdm_clock_get(void); /** * @brief Function for setting up the PDM pins. @@ -299,23 +232,12 @@ __STATIC_INLINE nrf_pdm_freq_t nrf_pdm_clock_get(void) * @param[in] psel_clk CLK pin number. * @param[in] psel_din DIN pin number. */ -__STATIC_INLINE void nrf_pdm_psel_connect(uint32_t psel_clk, uint32_t psel_din) -{ - NRF_PDM->PSEL.CLK = psel_clk; - NRF_PDM->PSEL.DIN = psel_din; -} +__STATIC_INLINE void nrf_pdm_psel_connect(uint32_t psel_clk, uint32_t psel_din); /** * @brief Function for disconnecting the PDM pins. */ -__STATIC_INLINE void nrf_pdm_psel_disconnect() -{ - NRF_PDM->PSEL.CLK = ((PDM_PSEL_CLK_CONNECT_Disconnected << PDM_PSEL_CLK_CONNECT_Pos) - & PDM_PSEL_CLK_CONNECT_Msk); - NRF_PDM->PSEL.DIN = ((PDM_PSEL_DIN_CONNECT_Disconnected << PDM_PSEL_DIN_CONNECT_Pos) - & PDM_PSEL_DIN_CONNECT_Msk); -} - +__STATIC_INLINE void nrf_pdm_psel_disconnect(void); /** * @brief Function for setting the PDM gain. @@ -323,12 +245,7 @@ __STATIC_INLINE void nrf_pdm_psel_disconnect() * @param[in] gain_l Left channel gain. * @param[in] gain_r Right channel gain. */ -__STATIC_INLINE void nrf_pdm_gain_set(nrf_pdm_gain_t gain_l, nrf_pdm_gain_t gain_r) -{ - NRF_PDM->GAINL = gain_l; - NRF_PDM->GAINR = gain_r; -} - +__STATIC_INLINE void nrf_pdm_gain_set(nrf_pdm_gain_t gain_l, nrf_pdm_gain_t gain_r); /** * @brief Function for getting the PDM gain. @@ -336,12 +253,7 @@ __STATIC_INLINE void nrf_pdm_gain_set(nrf_pdm_gain_t gain_l, nrf_pdm_gain_t gain * @param[out] p_gain_l Left channel gain. * @param[out] p_gain_r Right channel gain. */ -__STATIC_INLINE void nrf_pdm_gain_get(nrf_pdm_gain_t * p_gain_l, nrf_pdm_gain_t * p_gain_r) -{ - *p_gain_l = NRF_PDM->GAINL; - *p_gain_r = NRF_PDM->GAINR; -} - +__STATIC_INLINE void nrf_pdm_gain_get(nrf_pdm_gain_t * p_gain_l, nrf_pdm_gain_t * p_gain_r); /** * @brief Function for setting the PDM sample buffer. @@ -353,26 +265,140 @@ __STATIC_INLINE void nrf_pdm_gain_get(nrf_pdm_gain_t * p_gain_l, nrf_pdm_gain_t * - For stereo mode: N 32-bit words. * - For mono mode: Ceil(N/2) 32-bit words. */ -__STATIC_INLINE void nrf_pdm_buffer_set(uint32_t * p_buffer, uint32_t num) -{ - NRF_PDM->SAMPLE.PTR = (uint32_t)p_buffer; - NRF_PDM->SAMPLE.MAXCNT = num; -} +__STATIC_INLINE void nrf_pdm_buffer_set(uint32_t * p_buffer, uint32_t num); /** * @brief Function for getting the current PDM sample buffer address. * * @return Pointer to the current sample buffer. */ -__STATIC_INLINE uint32_t * nrf_pdm_buffer_get() +__STATIC_INLINE uint32_t * nrf_pdm_buffer_get(void); + +#ifndef SUPPRESS_INLINE_IMPLEMENTATION +__STATIC_INLINE void nrf_pdm_task_trigger(nrf_pdm_task_t pdm_task) +{ + *((volatile uint32_t *)((uint8_t *)NRF_PDM + (uint32_t)pdm_task)) = 0x1UL; +} + +__STATIC_INLINE uint32_t nrf_pdm_task_address_get(nrf_pdm_task_t pdm_task) +{ + return (uint32_t)((uint8_t *)NRF_PDM + (uint32_t)pdm_task); +} + +__STATIC_INLINE bool nrf_pdm_event_check(nrf_pdm_event_t pdm_event) +{ + return (bool)*(volatile uint32_t *)((uint8_t *)NRF_PDM + (uint32_t)pdm_event); +} + +__STATIC_INLINE void nrf_pdm_event_clear(nrf_pdm_event_t pdm_event) +{ + *((volatile uint32_t *)((uint8_t *)NRF_PDM + (uint32_t)pdm_event)) = 0x0UL; +#if __CORTEX_M == 0x04 + volatile uint32_t dummy = *((volatile uint32_t *)((uint8_t *)NRF_PDM + (uint32_t)pdm_event)); + (void)dummy; +#endif +} + +__STATIC_INLINE volatile uint32_t * nrf_pdm_event_address_get(nrf_pdm_event_t pdm_event) +{ + return (volatile uint32_t *)((uint8_t *)NRF_PDM + (uint32_t)pdm_event); +} + +__STATIC_INLINE void nrf_pdm_int_enable(uint32_t pdm_int_mask) +{ + NRF_PDM->INTENSET = pdm_int_mask; +} + +__STATIC_INLINE bool nrf_pdm_int_enable_check(uint32_t pdm_int_mask) +{ + return (bool)(NRF_PDM->INTENSET & pdm_int_mask); +} + +__STATIC_INLINE void nrf_pdm_int_disable(uint32_t pdm_int_mask) +{ + NRF_PDM->INTENCLR = pdm_int_mask; +} + +__STATIC_INLINE void nrf_pdm_enable(void) +{ + NRF_PDM->ENABLE = (PDM_ENABLE_ENABLE_Enabled << PDM_ENABLE_ENABLE_Pos); +} + +__STATIC_INLINE void nrf_pdm_disable(void) +{ + NRF_PDM->ENABLE = (PDM_ENABLE_ENABLE_Disabled << PDM_ENABLE_ENABLE_Pos); +} + +__STATIC_INLINE bool nrf_pdm_enable_check(void) +{ + return (NRF_PDM->ENABLE == (PDM_ENABLE_ENABLE_Enabled << PDM_ENABLE_ENABLE_Pos)); +} + +__STATIC_INLINE void nrf_pdm_mode_set(nrf_pdm_mode_t pdm_mode, nrf_pdm_edge_t pdm_edge) +{ + NRF_PDM->MODE = ((pdm_mode << PDM_MODE_OPERATION_Pos) & PDM_MODE_OPERATION_Msk) + | ((pdm_edge << PDM_MODE_EDGE_Pos) & PDM_MODE_EDGE_Msk); +} + +__STATIC_INLINE void nrf_pdm_mode_get(nrf_pdm_mode_t * p_pdm_mode, nrf_pdm_edge_t * p_pdm_edge) +{ + uint32_t mode = NRF_PDM->MODE; + *p_pdm_mode = (nrf_pdm_mode_t)((mode & PDM_MODE_OPERATION_Msk ) >> PDM_MODE_OPERATION_Pos); + *p_pdm_edge = (nrf_pdm_edge_t)((mode & PDM_MODE_EDGE_Msk ) >> PDM_MODE_EDGE_Pos); +} + +__STATIC_INLINE void nrf_pdm_clock_set(nrf_pdm_freq_t pdm_freq) +{ + NRF_PDM->PDMCLKCTRL = ((pdm_freq << PDM_PDMCLKCTRL_FREQ_Pos) & PDM_PDMCLKCTRL_FREQ_Msk); +} + +__STATIC_INLINE nrf_pdm_freq_t nrf_pdm_clock_get(void) +{ + return (nrf_pdm_freq_t) ((NRF_PDM->PDMCLKCTRL << PDM_PDMCLKCTRL_FREQ_Pos) & PDM_PDMCLKCTRL_FREQ_Msk); +} + +__STATIC_INLINE void nrf_pdm_psel_connect(uint32_t psel_clk, uint32_t psel_din) +{ + NRF_PDM->PSEL.CLK = psel_clk; + NRF_PDM->PSEL.DIN = psel_din; +} + +__STATIC_INLINE void nrf_pdm_psel_disconnect(void) +{ + NRF_PDM->PSEL.CLK = ((PDM_PSEL_CLK_CONNECT_Disconnected << PDM_PSEL_CLK_CONNECT_Pos) + & PDM_PSEL_CLK_CONNECT_Msk); + NRF_PDM->PSEL.DIN = ((PDM_PSEL_DIN_CONNECT_Disconnected << PDM_PSEL_DIN_CONNECT_Pos) + & PDM_PSEL_DIN_CONNECT_Msk); +} + +__STATIC_INLINE void nrf_pdm_gain_set(nrf_pdm_gain_t gain_l, nrf_pdm_gain_t gain_r) +{ + NRF_PDM->GAINL = gain_l; + NRF_PDM->GAINR = gain_r; +} + +__STATIC_INLINE void nrf_pdm_gain_get(nrf_pdm_gain_t * p_gain_l, nrf_pdm_gain_t * p_gain_r) +{ + *p_gain_l = NRF_PDM->GAINL; + *p_gain_r = NRF_PDM->GAINR; +} + +__STATIC_INLINE void nrf_pdm_buffer_set(uint32_t * p_buffer, uint32_t num) +{ + NRF_PDM->SAMPLE.PTR = (uint32_t)p_buffer; + NRF_PDM->SAMPLE.MAXCNT = num; +} + +__STATIC_INLINE uint32_t * nrf_pdm_buffer_get(void) { return (uint32_t *)NRF_PDM->SAMPLE.PTR; } +#endif // SUPPRESS_INLINE_IMPLEMENTATION /** @} */ #ifdef __cplusplus } #endif -#endif /* NRF_PDM_H_ */ +#endif // NRF_PDM_H_ diff --git a/hal/nrf_qdec.h b/hal/nrf_qdec.h index e87c65d23..d7adde57b 100644 --- a/hal/nrf_qdec.h +++ b/hal/nrf_qdec.h @@ -162,89 +162,53 @@ typedef enum /** * @brief Function for enabling QDEC. */ -__STATIC_INLINE void nrf_qdec_enable(void) -{ - NRF_QDEC->ENABLE = NRF_QDEC_ENABLE; -} - +__STATIC_INLINE void nrf_qdec_enable(void); /** * @brief Function for disabling QDEC. */ -__STATIC_INLINE void nrf_qdec_disable(void) -{ - NRF_QDEC->ENABLE = NRF_QDEC_DISABLE; -} - +__STATIC_INLINE void nrf_qdec_disable(void); /** * @brief Function for returning the enable state of QDEC. * @return State of the register. */ -__STATIC_INLINE uint32_t nrf_qdec_enable_get(void) -{ - return NRF_QDEC->ENABLE; -} - +__STATIC_INLINE uint32_t nrf_qdec_enable_get(void); /** * @brief Function for enabling QDEC interrupts by mask. * @param[in] qdec_int_mask Sources of the interrupts to enable. */ -__STATIC_INLINE void nrf_qdec_int_enable(uint32_t qdec_int_mask) -{ - NRF_QDEC->INTENSET = qdec_int_mask; // writing 0 has no effect -} - +__STATIC_INLINE void nrf_qdec_int_enable(uint32_t qdec_int_mask); /** * @brief Function for disabling QDEC interrupts by mask. * @param[in] qdec_int_mask Sources of the interrupts to disable. * */ -__STATIC_INLINE void nrf_qdec_int_disable(uint32_t qdec_int_mask) -{ - NRF_QDEC->INTENCLR = qdec_int_mask; // writing 0 has no effect -} - +__STATIC_INLINE void nrf_qdec_int_disable(uint32_t qdec_int_mask); /** * @brief Function for getting the enabled interrupts of the QDEC. */ -__STATIC_INLINE uint32_t nrf_qdec_int_enable_check(nrf_qdec_int_mask_t qdec_int_mask) -{ - return NRF_QDEC->INTENSET & qdec_int_mask; // when read this register will return the value of INTEN. -} - +__STATIC_INLINE uint32_t nrf_qdec_int_enable_check(nrf_qdec_int_mask_t qdec_int_mask); /** * @brief Function for enabling the debouncing filter of the QED. */ -__STATIC_INLINE void nrf_qdec_dbfen_enable(void) -{ - NRF_QDEC->DBFEN = NRF_QDEC_DBFEN_ENABLE; -} - +__STATIC_INLINE void nrf_qdec_dbfen_enable(void); /** * @brief Function for disabling the debouncing filter of the QED. */ -__STATIC_INLINE void nrf_qdec_dbfen_disable(void) -{ - NRF_QDEC->DBFEN = NRF_QDEC_DBFEN_DISABLE; -} - +__STATIC_INLINE void nrf_qdec_dbfen_disable(void); /** * @brief Function for getting the state of the QDEC's debouncing filter. * @retval NRF_QDEC_DBFEN_DISABLE If the debouncing filter is disabled. * @retval NRF_QDEC_DBFEN_ENABLE If the debouncing filter is enabled. */ -__STATIC_INLINE uint32_t nrf_qdec_dbfen_get(void) -{ - return NRF_QDEC->DBFEN; -} - +__STATIC_INLINE uint32_t nrf_qdec_dbfen_get(void); /** * @brief Function for assigning QDEC pins. @@ -252,38 +216,204 @@ __STATIC_INLINE uint32_t nrf_qdec_dbfen_get(void) * @param[in] pselb Pin number. * @param[in] pselled Pin number. */ +__STATIC_INLINE void nrf_qdec_pio_assign( uint32_t psela, uint32_t pselb, uint32_t pselled); + +/** + * @brief Function for setting a specific QDEC task. + * @param[in] qdec_task QDEC task to be set. + */ +__STATIC_INLINE void nrf_qdec_task_trigger(nrf_qdec_task_t qdec_task); + +/** + * @brief Function for retrieving the address of a QDEC task register. + * @param[in] qdec_task QDEC task. + */ +__STATIC_INLINE uint32_t * nrf_qdec_task_address_get(nrf_qdec_task_t qdec_task); + +/** + * @brief Function for clearing a specific QDEC event. + * @param[in] qdec_event QDEC event to clear. + */ +__STATIC_INLINE void nrf_qdec_event_clear(nrf_qdec_event_t qdec_event); + +/** + * @brief Function for retrieving the state of a specific QDEC event. + * @return State of the QDEC event. + */ +__STATIC_INLINE uint32_t nrf_qdec_event_check(nrf_qdec_event_t qdec_event); + +/** + * @brief Function for retrieving the address of a specific QDEC event register. + * @param[in] qdec_event QDEC event. + * @return Address of the specified QDEC event. + */ +__STATIC_INLINE uint32_t * nrf_qdec_event_address_get(nrf_qdec_event_t qdec_event); + +/** + * @brief Function for setting QDEC shortcuts. + * @param[in] qdec_short_mask QDEC shortcut by mask. + */ +__STATIC_INLINE void nrf_qdec_shorts_enable(uint32_t qdec_short_mask); + +/** + * @brief Function for clearing shortcuts of the QDEC by mask. + * @param[in] qdec_short_mask QDEC shortcute to be cleared. + */ +__STATIC_INLINE void nrf_qdec_shorts_disable(uint32_t qdec_short_mask); + +/** + * @brief Function for retrieving the value of QDEC's SAMPLEPER register. + * @return Value of the SAMPLEPER register. + */ +__STATIC_INLINE int32_t nrf_qdec_sampleper_reg_get(void); + +/** + * @brief Function for converting the value of QDEC's SAMPLE PERIOD to microseconds. + * @retval sampling period in microseconds. + */ +__STATIC_INLINE uint32_t nrf_qdec_sampleper_to_value(uint32_t sampleper); + +/** + * @brief Function for setting the value of QDEC's SAMPLEPER register. + * @param[in] sample_per Sampling period. + */ +__STATIC_INLINE void nrf_qdec_sampleper_set(nrf_qdec_sampleper_t sample_per); + +/** + * @brief Function for retrieving the value of QDEC's SAMPLE register. + * @return Value of the SAMPLE register. + */ +__STATIC_INLINE int32_t nrf_qdec_sample_get(void); + +/** + * @brief Function for retrieving the value of QDEC's ACC register. + * @return Value of the ACC register. + */ +__STATIC_INLINE int32_t nrf_qdec_acc_get(void); + +/** + * @brief Function for retrieving the value of QDEC's ACCREAD register. + * @return Value of the ACCREAD register. + */ +__STATIC_INLINE int32_t nrf_qdec_accread_get(void); + +/** + * @brief Function for retrieving the value of QDEC's ACCDBL register. + * @return Value of the ACCDBL register. + */ +__STATIC_INLINE uint32_t nrf_qdec_accdbl_get(void); + +/** + * @brief Function for retrieving the value of QDEC's ACCDBLREAD register. + * @return Value of the ACCDBLREAD register. + */ +__STATIC_INLINE uint32_t nrf_qdec_accdblread_get(void); + +/** + * @brief Function for setting how long the LED is switched on before sampling. + * @param[in] time_us Time (in microseconds) how long the LED is switched on before sampling. + */ +__STATIC_INLINE void nrf_qdec_ledpre_set(uint32_t time_us); + +/** + * @brief Function for retrieving how long the LED is switched on before sampling. + * @retval time_us Time (in microseconds) how long the LED is switched on before sampling. + */ +__STATIC_INLINE uint32_t nrf_qdec_ledpre_get(void); + +/** + * @brief Function for setting the report period (in samples). + * @param[in] reportper Number of samples. + */ +__STATIC_INLINE void nrf_qdec_reportper_set(nrf_qdec_reportper_t reportper); + +/** + * @brief Function for retrieving the report period. + * @retval reportper Number of samples as encoded in the register. + */ +__STATIC_INLINE uint32_t nrf_qdec_reportper_reg_get(void); + +/** + * @brief Function for retrieving the value of QDEC's SAMPLEPER register. + * @param [in] reportper Reportper to be converted to amount of samples per report. + */ +__STATIC_INLINE uint32_t nrf_qdec_reportper_to_value(uint32_t reportper); + +/** + * @brief Function for setting the active level for the LED. + * @param[in] pol Active level for the LED. + */ +__STATIC_INLINE void nrf_qdec_ledpol_set(nrf_qdec_ledpol_t pol); + +/** + * @brief Function for retrieving the active level for the LED. + * @return Active level for the LED. + */ +__STATIC_INLINE uint32_t nrf_qdec_ledpol_get(void); + +#ifndef SUPPRESS_INLINE_IMPLEMENTATION +__STATIC_INLINE void nrf_qdec_enable(void) +{ + NRF_QDEC->ENABLE = NRF_QDEC_ENABLE; +} + +__STATIC_INLINE void nrf_qdec_disable(void) +{ + NRF_QDEC->ENABLE = NRF_QDEC_DISABLE; +} + +__STATIC_INLINE uint32_t nrf_qdec_enable_get(void) +{ + return NRF_QDEC->ENABLE; +} + +__STATIC_INLINE void nrf_qdec_int_enable(uint32_t qdec_int_mask) +{ + NRF_QDEC->INTENSET = qdec_int_mask; // writing 0 has no effect +} + +__STATIC_INLINE void nrf_qdec_int_disable(uint32_t qdec_int_mask) +{ + NRF_QDEC->INTENCLR = qdec_int_mask; // writing 0 has no effect +} + +__STATIC_INLINE uint32_t nrf_qdec_int_enable_check(nrf_qdec_int_mask_t qdec_int_mask) +{ + return NRF_QDEC->INTENSET & qdec_int_mask; // when read this register will return the value of INTEN. +} + +__STATIC_INLINE void nrf_qdec_dbfen_enable(void) +{ + NRF_QDEC->DBFEN = NRF_QDEC_DBFEN_ENABLE; +} + +__STATIC_INLINE void nrf_qdec_dbfen_disable(void) +{ + NRF_QDEC->DBFEN = NRF_QDEC_DBFEN_DISABLE; +} + +__STATIC_INLINE uint32_t nrf_qdec_dbfen_get(void) +{ + return NRF_QDEC->DBFEN; +} + __STATIC_INLINE void nrf_qdec_pio_assign( uint32_t psela, uint32_t pselb, uint32_t pselled) { NRF_QDEC->PSELA = psela; NRF_QDEC->PSELB = pselb; NRF_QDEC->PSELLED = pselled; - } -/** - * @brief Function for setting a specific QDEC task. - * @param[in] qdec_task QDEC task to be set. - */ __STATIC_INLINE void nrf_qdec_task_trigger(nrf_qdec_task_t qdec_task) { *( (volatile uint32_t *)( (uint8_t *)NRF_QDEC + qdec_task) ) = 1; } - -/** - * @brief Function for retrieving the address of a QDEC task register. - * @param[in] qdec_task QDEC task. - */ __STATIC_INLINE uint32_t * nrf_qdec_task_address_get(nrf_qdec_task_t qdec_task) { return (uint32_t *)( (uint8_t *)NRF_QDEC + qdec_task); } - -/** - * @brief Function for clearing a specific QDEC event. - * @param[in] qdec_event QDEC event to clear. - */ __STATIC_INLINE void nrf_qdec_event_clear(nrf_qdec_event_t qdec_event) { *( (volatile uint32_t *)( (uint8_t *)NRF_QDEC + qdec_event) ) = 0; @@ -293,201 +423,106 @@ __STATIC_INLINE void nrf_qdec_event_clear(nrf_qdec_event_t qdec_event) #endif } - -/** - * @brief Function for retrieving the state of a specific QDEC event. - * @return State of the QDEC event. - */ __STATIC_INLINE uint32_t nrf_qdec_event_check(nrf_qdec_event_t qdec_event) { return *(volatile uint32_t *)( (uint8_t *)NRF_QDEC + qdec_event); } - -/** - * @brief Function for retrieving the address of a specific QDEC event register. - * @param[in] qdec_event QDEC event. - * @return Address of the specified QDEC event. - */ __STATIC_INLINE uint32_t * nrf_qdec_event_address_get(nrf_qdec_event_t qdec_event) { return (uint32_t *)( (uint8_t *)NRF_QDEC + qdec_event); } - -/** - * @brief Function for setting QDEC shortcuts. - * @param[in] qdec_short_mask QDEC shortcut by mask. - */ __STATIC_INLINE void nrf_qdec_shorts_enable(uint32_t qdec_short_mask) { NRF_QDEC->SHORTS |= qdec_short_mask; } - -/** - * @brief Function for clearing shortcuts of the QDEC by mask. - * @param[in] qdec_short_mask QDEC shortcute to be cleared. - */ __STATIC_INLINE void nrf_qdec_shorts_disable(uint32_t qdec_short_mask) { NRF_QDEC->SHORTS &= ~qdec_short_mask; } - -/** - * @brief Function for retrieving the value of QDEC's SAMPLEPER register. - * @return Value of the SAMPLEPER register. - */ __STATIC_INLINE int32_t nrf_qdec_sampleper_reg_get(void) { return NRF_QDEC->SAMPLEPER; } - -/** - * @brief Function for converting the value of QDEC's SAMPLE PERIOD to microseconds. - * @retval sampling period in microseconds. - */ __STATIC_INLINE uint32_t nrf_qdec_sampleper_to_value(uint32_t sampleper) { return (1 << (7 + sampleper)); } -/** - * @brief Function for setting the value of QDEC's SAMPLEPER register. - * @param[in] sample_per Sampling period. - */ __STATIC_INLINE void nrf_qdec_sampleper_set(nrf_qdec_sampleper_t sample_per) { NRF_QDEC->SAMPLEPER = sample_per; } - -/** - * @brief Function for retrieving the value of QDEC's SAMPLE register. - * @return Value of the SAMPLE register. - */ __STATIC_INLINE int32_t nrf_qdec_sample_get(void) { return NRF_QDEC->SAMPLE; } - -/** - * @brief Function for retrieving the value of QDEC's ACC register. - * @return Value of the ACC register. - */ __STATIC_INLINE int32_t nrf_qdec_acc_get(void) { return NRF_QDEC->ACC; } - -/** - * @brief Function for retrieving the value of QDEC's ACCREAD register. - * @return Value of the ACCREAD register. - */ __STATIC_INLINE int32_t nrf_qdec_accread_get(void) { return NRF_QDEC->ACCREAD; } - -/** - * @brief Function for retrieving the value of QDEC's ACCDBL register. - * @return Value of the ACCDBL register. - */ __STATIC_INLINE uint32_t nrf_qdec_accdbl_get(void) { return NRF_QDEC->ACCDBL; } - -/** - * @brief Function for retrieving the value of QDEC's ACCDBLREAD register. - * @return Value of the ACCDBLREAD register. - */ __STATIC_INLINE uint32_t nrf_qdec_accdblread_get(void) { return NRF_QDEC->ACCDBLREAD; } - -/** - * @brief Function for setting how long the LED is switched on before sampling. - * @param[in] time_us Time (in microseconds) how long the LED is switched on before sampling. - */ __STATIC_INLINE void nrf_qdec_ledpre_set(uint32_t time_us) { NRF_QDEC->LEDPRE = time_us; } - -/** - * @brief Function for retrieving how long the LED is switched on before sampling. - * @retval time_us Time (in microseconds) how long the LED is switched on before sampling. - */ __STATIC_INLINE uint32_t nrf_qdec_ledpre_get(void) { return NRF_QDEC->LEDPRE; } - -/** - * @brief Function for setting the report period (in samples). - * @param[in] reportper Number of samples. - */ __STATIC_INLINE void nrf_qdec_reportper_set(nrf_qdec_reportper_t reportper) { NRF_QDEC->REPORTPER = reportper; } - -/** - * @brief Function for retrieving the report period. - * @retval reportper Number of samples as encoded in the register. - */ __STATIC_INLINE uint32_t nrf_qdec_reportper_reg_get(void) { return NRF_QDEC->REPORTPER; } - -/** - * @brief Function for retrieving the value of QDEC's SAMPLEPER register. - * @param [in] reportper Reportper to be converted to amount of samples per report. - - */ __STATIC_INLINE uint32_t nrf_qdec_reportper_to_value(uint32_t reportper) { return (reportper == NRF_QDEC_REPORTPER_10) ? 10 : reportper * 40; } - -/** - * @brief Function for setting the active level for the LED. - * @param[in] pol Active level for the LED. - */ __STATIC_INLINE void nrf_qdec_ledpol_set(nrf_qdec_ledpol_t pol) { NRF_QDEC->LEDPOL = pol; } - -/** - * @brief Function for retrieving the active level for the LED. - * @return Active level for the LED. - */ __STATIC_INLINE uint32_t nrf_qdec_ledpol_get(void) { return NRF_QDEC->LEDPOL; } +#endif // SUPPRESS_INLINE_IMPLEMENTATION /** @} */ #ifdef __cplusplus } #endif -#endif +#endif // NRF_QDEC_H__ diff --git a/hal/nrf_qspi.h b/hal/nrf_qspi.h index 57b2c0c45..a53c2142a 100644 --- a/hal/nrf_qspi.h +++ b/hal/nrf_qspi.h @@ -554,6 +554,9 @@ __STATIC_INLINE void nrf_qspi_enable(NRF_QSPI_Type * p_reg) __STATIC_INLINE void nrf_qspi_disable(NRF_QSPI_Type * p_reg) { + // Workaround for nRF52840 anomaly 122: Current consumption is too high. + *(volatile uint32_t *)0x40029054ul = 1ul; + p_reg->ENABLE = (QSPI_ENABLE_ENABLE_Disabled << QSPI_ENABLE_ENABLE_Pos); } @@ -705,39 +708,33 @@ __STATIC_INLINE void nrf_qspi_cinstrdata_get(NRF_QSPI_Type const * p_reg, { uint8_t *p_rx_data_8 = (uint8_t *) p_rx_data; - uint32_t reg = p_reg->CINSTRDAT1; + uint32_t reg1 = p_reg->CINSTRDAT1; + uint32_t reg0 = p_reg->CINSTRDAT0; switch (length) { case NRF_QSPI_CINSTR_LEN_9B: - p_rx_data_8[7] = (uint8_t)(reg >> QSPI_CINSTRDAT1_BYTE7_Pos); + p_rx_data_8[7] = (uint8_t)(reg1 >> QSPI_CINSTRDAT1_BYTE7_Pos); /* fall-through */ case NRF_QSPI_CINSTR_LEN_8B: - p_rx_data_8[6] = (uint8_t)(reg >> QSPI_CINSTRDAT1_BYTE6_Pos); + p_rx_data_8[6] = (uint8_t)(reg1 >> QSPI_CINSTRDAT1_BYTE6_Pos); /* fall-through */ case NRF_QSPI_CINSTR_LEN_7B: - p_rx_data_8[5] = (uint8_t)(reg >> QSPI_CINSTRDAT1_BYTE5_Pos); + p_rx_data_8[5] = (uint8_t)(reg1 >> QSPI_CINSTRDAT1_BYTE5_Pos); /* fall-through */ case NRF_QSPI_CINSTR_LEN_6B: - p_rx_data_8[4] = (uint8_t)(reg); + p_rx_data_8[4] = (uint8_t)(reg1); /* fall-through */ - default: - break; - } - - reg = p_reg->CINSTRDAT0; - switch (length) - { case NRF_QSPI_CINSTR_LEN_5B: - p_rx_data_8[3] = (uint8_t)(reg >> QSPI_CINSTRDAT0_BYTE3_Pos); + p_rx_data_8[3] = (uint8_t)(reg0 >> QSPI_CINSTRDAT0_BYTE3_Pos); /* fall-through */ case NRF_QSPI_CINSTR_LEN_4B: - p_rx_data_8[2] = (uint8_t)(reg >> QSPI_CINSTRDAT0_BYTE2_Pos); + p_rx_data_8[2] = (uint8_t)(reg0 >> QSPI_CINSTRDAT0_BYTE2_Pos); /* fall-through */ case NRF_QSPI_CINSTR_LEN_3B: - p_rx_data_8[1] = (uint8_t)(reg >> QSPI_CINSTRDAT0_BYTE1_Pos); + p_rx_data_8[1] = (uint8_t)(reg0 >> QSPI_CINSTRDAT0_BYTE1_Pos); /* fall-through */ case NRF_QSPI_CINSTR_LEN_2B: - p_rx_data_8[0] = (uint8_t)(reg); + p_rx_data_8[0] = (uint8_t)(reg0); /* fall-through */ case NRF_QSPI_CINSTR_LEN_1B: /* Send only opcode. Case to avoid compiler warnings. */ diff --git a/hal/nrf_saadc.h b/hal/nrf_saadc.h index 537141885..3a9efce9e 100644 --- a/hal/nrf_saadc.h +++ b/hal/nrf_saadc.h @@ -280,17 +280,12 @@ typedef struct nrf_saadc_input_t pin_n; } nrf_saadc_channel_config_t; - /** * @brief Function for triggering a specific SAADC task. * * @param[in] saadc_task SAADC task. */ -__STATIC_INLINE void nrf_saadc_task_trigger(nrf_saadc_task_t saadc_task) -{ - *((volatile uint32_t *)((uint8_t *)NRF_SAADC + (uint32_t)saadc_task)) = 0x1UL; -} - +__STATIC_INLINE void nrf_saadc_task_trigger(nrf_saadc_task_t saadc_task); /** * @brief Function for getting the address of a specific SAADC task register. @@ -299,11 +294,7 @@ __STATIC_INLINE void nrf_saadc_task_trigger(nrf_saadc_task_t saadc_task) * * @return Address of the specified SAADC task. */ -__STATIC_INLINE uint32_t nrf_saadc_task_address_get(nrf_saadc_task_t saadc_task) -{ - return (uint32_t)((uint8_t *)NRF_SAADC + (uint32_t)saadc_task); -} - +__STATIC_INLINE uint32_t nrf_saadc_task_address_get(nrf_saadc_task_t saadc_task); /** * @brief Function for getting the state of a specific SAADC event. @@ -312,26 +303,14 @@ __STATIC_INLINE uint32_t nrf_saadc_task_address_get(nrf_saadc_task_t saadc_task) * * @return State of the specified SAADC event. */ -__STATIC_INLINE bool nrf_saadc_event_check(nrf_saadc_event_t saadc_event) -{ - return (bool)*(volatile uint32_t *)((uint8_t *)NRF_SAADC + (uint32_t)saadc_event); -} - +__STATIC_INLINE bool nrf_saadc_event_check(nrf_saadc_event_t saadc_event); /** * @brief Function for clearing the specific SAADC event. * * @param[in] saadc_event SAADC event. */ -__STATIC_INLINE void nrf_saadc_event_clear(nrf_saadc_event_t saadc_event) -{ - *((volatile uint32_t *)((uint8_t *)NRF_SAADC + (uint32_t)saadc_event)) = 0x0UL; -#if __CORTEX_M == 0x04 - volatile uint32_t dummy = *((volatile uint32_t *)((uint8_t *)NRF_SAADC + (uint32_t)saadc_event)); - (void)dummy; -#endif -} - +__STATIC_INLINE void nrf_saadc_event_clear(nrf_saadc_event_t saadc_event); /** * @brief Function for getting the address of a specific SAADC event register. @@ -340,11 +319,7 @@ __STATIC_INLINE void nrf_saadc_event_clear(nrf_saadc_event_t saadc_event) * * @return Address of the specified SAADC event. */ -__STATIC_INLINE uint32_t nrf_saadc_event_address_get(nrf_saadc_event_t saadc_event) -{ - return (uint32_t )((uint8_t *)NRF_SAADC + (uint32_t)saadc_event); -} - +__STATIC_INLINE uint32_t nrf_saadc_event_address_get(nrf_saadc_event_t saadc_event); /** * @brief Function for getting the address of a specific SAADC limit event register. @@ -354,19 +329,7 @@ __STATIC_INLINE uint32_t nrf_saadc_event_address_get(nrf_saadc_event_t saadc_ev * * @return Address of the specified SAADC limit event. */ -__STATIC_INLINE volatile uint32_t * nrf_saadc_event_limit_address_get(uint8_t channel, nrf_saadc_limit_t limit_type) -{ - NRFX_ASSERT(channel < NRF_SAADC_CHANNEL_COUNT); - if (limit_type == NRF_SAADC_LIMIT_HIGH) - { - return &NRF_SAADC->EVENTS_CH[channel].LIMITH; - } - else - { - return &NRF_SAADC->EVENTS_CH[channel].LIMITL; - } -} - +__STATIC_INLINE volatile uint32_t * nrf_saadc_event_limit_address_get(uint8_t channel, nrf_saadc_limit_t limit_type); /** * @brief Function for getting the SAADC channel monitoring limit events. @@ -374,22 +337,7 @@ __STATIC_INLINE volatile uint32_t * nrf_saadc_event_limit_address_get(uint8_t ch * @param[in] channel Channel number. * @param[in] limit_type Low limit or high limit. */ -__STATIC_INLINE nrf_saadc_event_t nrf_saadc_event_limit_get(uint8_t channel, nrf_saadc_limit_t limit_type) -{ - if (limit_type == NRF_SAADC_LIMIT_HIGH) - { - return (nrf_saadc_event_t)( (uint32_t) NRF_SAADC_EVENT_CH0_LIMITH + - (uint32_t) (NRF_SAADC_EVENT_CH1_LIMITH - NRF_SAADC_EVENT_CH0_LIMITH) - * (uint32_t) channel ); - } - else - { - return (nrf_saadc_event_t)( (uint32_t) NRF_SAADC_EVENT_CH0_LIMITL + - (uint32_t) (NRF_SAADC_EVENT_CH1_LIMITL - NRF_SAADC_EVENT_CH0_LIMITL) - * (uint32_t) channel ); - } -} - +__STATIC_INLINE nrf_saadc_event_t nrf_saadc_event_limit_get(uint8_t channel, nrf_saadc_limit_t limit_type); /** * @brief Function for configuring the input pins for a specific SAADC channel. @@ -400,12 +348,7 @@ __STATIC_INLINE nrf_saadc_event_t nrf_saadc_event_limit_get(uint8_t channel, nrf */ __STATIC_INLINE void nrf_saadc_channel_input_set(uint8_t channel, nrf_saadc_input_t pselp, - nrf_saadc_input_t pseln) -{ - NRF_SAADC->CH[channel].PSELN = pseln; - NRF_SAADC->CH[channel].PSELP = pselp; -} - + nrf_saadc_input_t pseln); /** * @brief Function for configuring the positive input pin for a specific SAADC channel. @@ -414,11 +357,7 @@ __STATIC_INLINE void nrf_saadc_channel_input_set(uint8_t channel, * @param[in] pselp Positive input. */ __STATIC_INLINE void nrf_saadc_channel_pos_input_set(uint8_t channel, - nrf_saadc_input_t pselp) -{ - NRF_SAADC->CH[channel].PSELP = pselp; -} - + nrf_saadc_input_t pselp); /** * @brief Function for setting the SAADC channel monitoring limits. @@ -427,24 +366,14 @@ __STATIC_INLINE void nrf_saadc_channel_pos_input_set(uint8_t channel, * @param[in] low Low limit. * @param[in] high High limit. */ -__STATIC_INLINE void nrf_saadc_channel_limits_set(uint8_t channel, int16_t low, int16_t high) -{ - NRF_SAADC->CH[channel].LIMIT = ( - (((uint32_t) low << SAADC_CH_LIMIT_LOW_Pos) & SAADC_CH_LIMIT_LOW_Msk) - | (((uint32_t) high << SAADC_CH_LIMIT_HIGH_Pos) & SAADC_CH_LIMIT_HIGH_Msk)); -} - +__STATIC_INLINE void nrf_saadc_channel_limits_set(uint8_t channel, int16_t low, int16_t high); /** * @brief Function for enabling specified SAADC interrupts. * * @param[in] saadc_int_mask Interrupt(s) to enable. */ -__STATIC_INLINE void nrf_saadc_int_enable(uint32_t saadc_int_mask) -{ - NRF_SAADC->INTENSET = saadc_int_mask; -} - +__STATIC_INLINE void nrf_saadc_int_enable(uint32_t saadc_int_mask); /** * @brief Function for retrieving the state of specified SAADC interrupts. @@ -454,22 +383,14 @@ __STATIC_INLINE void nrf_saadc_int_enable(uint32_t saadc_int_mask) * @retval true If all specified interrupts are enabled. * @retval false If at least one of the given interrupts is not enabled. */ -__STATIC_INLINE bool nrf_saadc_int_enable_check(uint32_t saadc_int_mask) -{ - return (bool)(NRF_SAADC->INTENSET & saadc_int_mask); -} - +__STATIC_INLINE bool nrf_saadc_int_enable_check(uint32_t saadc_int_mask); /** * @brief Function for disabling specified interrupts. * * @param saadc_int_mask Interrupt(s) to disable. */ -__STATIC_INLINE void nrf_saadc_int_disable(uint32_t saadc_int_mask) -{ - NRF_SAADC->INTENCLR = saadc_int_mask; -} - +__STATIC_INLINE void nrf_saadc_int_disable(uint32_t saadc_int_mask); /** * @brief Function for generating masks for SAADC channel limit interrupts. @@ -479,13 +400,7 @@ __STATIC_INLINE void nrf_saadc_int_disable(uint32_t saadc_int_mask) * * @returns Interrupt mask. */ -__STATIC_INLINE uint32_t nrf_saadc_limit_int_get(uint8_t channel, nrf_saadc_limit_t limit_type) -{ - NRFX_ASSERT(channel < NRF_SAADC_CHANNEL_COUNT); - uint32_t mask = (limit_type == NRF_SAADC_LIMIT_LOW) ? NRF_SAADC_INT_CH0LIMITL : NRF_SAADC_INT_CH0LIMITH; - return mask << (channel * 2); -} - +__STATIC_INLINE uint32_t nrf_saadc_limit_int_get(uint8_t channel, nrf_saadc_limit_t limit_type); /** * @brief Function for checking whether the SAADC is busy. @@ -495,33 +410,19 @@ __STATIC_INLINE uint32_t nrf_saadc_limit_int_get(uint8_t channel, nrf_saadc_limi * @retval true If the SAADC is busy. * @retval false If the SAADC is not busy. */ -__STATIC_INLINE bool nrf_saadc_busy_check(void) -{ - //return ((NRF_SAADC->STATUS & SAADC_STATUS_STATUS_Msk) == SAADC_STATUS_STATUS_Msk); - //simplified for performance - return NRF_SAADC->STATUS; -} - +__STATIC_INLINE bool nrf_saadc_busy_check(void); /** * @brief Function for enabling the SAADC. * * The analog-to-digital converter must be enabled before use. */ -__STATIC_INLINE void nrf_saadc_enable(void) -{ - NRF_SAADC->ENABLE = (SAADC_ENABLE_ENABLE_Enabled << SAADC_ENABLE_ENABLE_Pos); -} - +__STATIC_INLINE void nrf_saadc_enable(void); /** * @brief Function for disabling the SAADC. */ -__STATIC_INLINE void nrf_saadc_disable(void) -{ - NRF_SAADC->ENABLE = (SAADC_ENABLE_ENABLE_Disabled << SAADC_ENABLE_ENABLE_Pos); -} - +__STATIC_INLINE void nrf_saadc_disable(void); /** * @brief Function for checking if the SAADC is enabled. @@ -529,12 +430,7 @@ __STATIC_INLINE void nrf_saadc_disable(void) * @retval true If the SAADC is enabled. * @retval false If the SAADC is not enabled. */ -__STATIC_INLINE bool nrf_saadc_enable_check(void) -{ - //simplified for performance - return NRF_SAADC->ENABLE; -} - +__STATIC_INLINE bool nrf_saadc_enable_check(void); /** * @brief Function for initializing the SAADC result buffer. @@ -543,34 +439,21 @@ __STATIC_INLINE bool nrf_saadc_enable_check(void) * @param[in] size Size of the buffer (in 16-bit samples). */ __STATIC_INLINE void nrf_saadc_buffer_init(nrf_saadc_value_t * p_buffer, - uint32_t size) -{ - NRF_SAADC->RESULT.PTR = (uint32_t)p_buffer; - NRF_SAADC->RESULT.MAXCNT = size; -} - + uint32_t size); /** * @brief Function for setting the SAADC result buffer pointer. * * @param[in] p_buffer Pointer to the result buffer. */ -__STATIC_INLINE void nrf_saadc_buffer_pointer_set(nrf_saadc_value_t * p_buffer) -{ - NRF_SAADC->RESULT.PTR = (uint32_t)p_buffer; -} - +__STATIC_INLINE void nrf_saadc_buffer_pointer_set(nrf_saadc_value_t * p_buffer); /** * @brief Function for getting the SAADC result buffer pointer. * * @return Pointer to the result buffer. */ -__STATIC_INLINE nrf_saadc_value_t * nrf_saadc_buffer_pointer_get(void) -{ - return (nrf_saadc_value_t *)NRF_SAADC->RESULT.PTR; -} - +__STATIC_INLINE nrf_saadc_value_t * nrf_saadc_buffer_pointer_get(void); /** * @brief Function for getting the number of samples written to the result @@ -578,42 +461,28 @@ __STATIC_INLINE nrf_saadc_value_t * nrf_saadc_buffer_pointer_get(void) * * @returns Number of 16-bit samples written to the buffer. */ -__STATIC_INLINE uint16_t nrf_saadc_amount_get(void) -{ - return NRF_SAADC->RESULT.AMOUNT; -} - +__STATIC_INLINE uint16_t nrf_saadc_amount_get(void); /** * @brief Function for setting the SAADC sample resolution. * * @param[in] resolution Bit resolution. */ -__STATIC_INLINE void nrf_saadc_resolution_set(nrf_saadc_resolution_t resolution) -{ - NRF_SAADC->RESOLUTION = resolution; -} - +__STATIC_INLINE void nrf_saadc_resolution_set(nrf_saadc_resolution_t resolution); /** * @brief Function for configuring the oversampling feature. * * @param[in] oversample Oversampling mode. */ -__STATIC_INLINE void nrf_saadc_oversample_set(nrf_saadc_oversample_t oversample) -{ - NRF_SAADC->OVERSAMPLE = oversample; -} +__STATIC_INLINE void nrf_saadc_oversample_set(nrf_saadc_oversample_t oversample); /** * @brief Function for getting the oversampling feature configuration. * * @return Oversampling configuration. */ -__STATIC_INLINE nrf_saadc_oversample_t nrf_saadc_oversample_get(void) -{ - return (nrf_saadc_oversample_t)NRF_SAADC->OVERSAMPLE; -} +__STATIC_INLINE nrf_saadc_oversample_t nrf_saadc_oversample_get(void); /** * @brief Function for initializing the SAADC channel. @@ -621,6 +490,181 @@ __STATIC_INLINE nrf_saadc_oversample_t nrf_saadc_oversample_get(void) * @param[in] channel Channel number. * @param[in] config Pointer to the channel configuration structure. */ +__STATIC_INLINE void nrf_saadc_channel_init(uint8_t channel, + nrf_saadc_channel_config_t const * const config); + +/** + * @brief Function for configuring the burst mode for the specified channel. + * + * @param[in] channel Channel number. + * @param[in] burst Burst mode setting. + */ +__STATIC_INLINE void nrf_saadc_burst_set(uint8_t channel, + nrf_saadc_burst_t burst); + +#ifndef SUPPRESS_INLINE_IMPLEMENTATION + +__STATIC_INLINE void nrf_saadc_task_trigger(nrf_saadc_task_t saadc_task) +{ + *((volatile uint32_t *)((uint8_t *)NRF_SAADC + (uint32_t)saadc_task)) = 0x1UL; +} + +__STATIC_INLINE uint32_t nrf_saadc_task_address_get(nrf_saadc_task_t saadc_task) +{ + return (uint32_t)((uint8_t *)NRF_SAADC + (uint32_t)saadc_task); +} + +__STATIC_INLINE bool nrf_saadc_event_check(nrf_saadc_event_t saadc_event) +{ + return (bool)*(volatile uint32_t *)((uint8_t *)NRF_SAADC + (uint32_t)saadc_event); +} + +__STATIC_INLINE void nrf_saadc_event_clear(nrf_saadc_event_t saadc_event) +{ + *((volatile uint32_t *)((uint8_t *)NRF_SAADC + (uint32_t)saadc_event)) = 0x0UL; +#if __CORTEX_M == 0x04 + volatile uint32_t dummy = *((volatile uint32_t *)((uint8_t *)NRF_SAADC + (uint32_t)saadc_event)); + (void)dummy; +#endif +} + +__STATIC_INLINE uint32_t nrf_saadc_event_address_get(nrf_saadc_event_t saadc_event) +{ + return (uint32_t )((uint8_t *)NRF_SAADC + (uint32_t)saadc_event); +} + +__STATIC_INLINE volatile uint32_t * nrf_saadc_event_limit_address_get(uint8_t channel, nrf_saadc_limit_t limit_type) +{ + NRFX_ASSERT(channel < NRF_SAADC_CHANNEL_COUNT); + if (limit_type == NRF_SAADC_LIMIT_HIGH) + { + return &NRF_SAADC->EVENTS_CH[channel].LIMITH; + } + else + { + return &NRF_SAADC->EVENTS_CH[channel].LIMITL; + } +} + +__STATIC_INLINE nrf_saadc_event_t nrf_saadc_event_limit_get(uint8_t channel, nrf_saadc_limit_t limit_type) +{ + if (limit_type == NRF_SAADC_LIMIT_HIGH) + { + return (nrf_saadc_event_t)( (uint32_t) NRF_SAADC_EVENT_CH0_LIMITH + + (uint32_t) (NRF_SAADC_EVENT_CH1_LIMITH - NRF_SAADC_EVENT_CH0_LIMITH) + * (uint32_t) channel ); + } + else + { + return (nrf_saadc_event_t)( (uint32_t) NRF_SAADC_EVENT_CH0_LIMITL + + (uint32_t) (NRF_SAADC_EVENT_CH1_LIMITL - NRF_SAADC_EVENT_CH0_LIMITL) + * (uint32_t) channel ); + } +} + +__STATIC_INLINE void nrf_saadc_channel_input_set(uint8_t channel, + nrf_saadc_input_t pselp, + nrf_saadc_input_t pseln) +{ + NRF_SAADC->CH[channel].PSELN = pseln; + NRF_SAADC->CH[channel].PSELP = pselp; +} + +__STATIC_INLINE void nrf_saadc_channel_pos_input_set(uint8_t channel, + nrf_saadc_input_t pselp) +{ + NRF_SAADC->CH[channel].PSELP = pselp; +} + +__STATIC_INLINE void nrf_saadc_channel_limits_set(uint8_t channel, int16_t low, int16_t high) +{ + NRF_SAADC->CH[channel].LIMIT = ( + (((uint32_t) low << SAADC_CH_LIMIT_LOW_Pos) & SAADC_CH_LIMIT_LOW_Msk) + | (((uint32_t) high << SAADC_CH_LIMIT_HIGH_Pos) & SAADC_CH_LIMIT_HIGH_Msk)); +} + +__STATIC_INLINE void nrf_saadc_int_enable(uint32_t saadc_int_mask) +{ + NRF_SAADC->INTENSET = saadc_int_mask; +} + +__STATIC_INLINE bool nrf_saadc_int_enable_check(uint32_t saadc_int_mask) +{ + return (bool)(NRF_SAADC->INTENSET & saadc_int_mask); +} + +__STATIC_INLINE void nrf_saadc_int_disable(uint32_t saadc_int_mask) +{ + NRF_SAADC->INTENCLR = saadc_int_mask; +} + +__STATIC_INLINE uint32_t nrf_saadc_limit_int_get(uint8_t channel, nrf_saadc_limit_t limit_type) +{ + NRFX_ASSERT(channel < NRF_SAADC_CHANNEL_COUNT); + uint32_t mask = (limit_type == NRF_SAADC_LIMIT_LOW) ? NRF_SAADC_INT_CH0LIMITL : NRF_SAADC_INT_CH0LIMITH; + return mask << (channel * 2); +} + +__STATIC_INLINE bool nrf_saadc_busy_check(void) +{ + //return ((NRF_SAADC->STATUS & SAADC_STATUS_STATUS_Msk) == SAADC_STATUS_STATUS_Msk); + //simplified for performance + return NRF_SAADC->STATUS; +} + +__STATIC_INLINE void nrf_saadc_enable(void) +{ + NRF_SAADC->ENABLE = (SAADC_ENABLE_ENABLE_Enabled << SAADC_ENABLE_ENABLE_Pos); +} + +__STATIC_INLINE void nrf_saadc_disable(void) +{ + NRF_SAADC->ENABLE = (SAADC_ENABLE_ENABLE_Disabled << SAADC_ENABLE_ENABLE_Pos); +} + +__STATIC_INLINE bool nrf_saadc_enable_check(void) +{ + //simplified for performance + return NRF_SAADC->ENABLE; +} + +__STATIC_INLINE void nrf_saadc_buffer_init(nrf_saadc_value_t * p_buffer, + uint32_t size) +{ + NRF_SAADC->RESULT.PTR = (uint32_t)p_buffer; + NRF_SAADC->RESULT.MAXCNT = size; +} + +__STATIC_INLINE void nrf_saadc_buffer_pointer_set(nrf_saadc_value_t * p_buffer) +{ + NRF_SAADC->RESULT.PTR = (uint32_t)p_buffer; +} + +__STATIC_INLINE nrf_saadc_value_t * nrf_saadc_buffer_pointer_get(void) +{ + return (nrf_saadc_value_t *)NRF_SAADC->RESULT.PTR; +} + +__STATIC_INLINE uint16_t nrf_saadc_amount_get(void) +{ + return NRF_SAADC->RESULT.AMOUNT; +} + +__STATIC_INLINE void nrf_saadc_resolution_set(nrf_saadc_resolution_t resolution) +{ + NRF_SAADC->RESOLUTION = resolution; +} + +__STATIC_INLINE void nrf_saadc_oversample_set(nrf_saadc_oversample_t oversample) +{ + NRF_SAADC->OVERSAMPLE = oversample; +} + +__STATIC_INLINE nrf_saadc_oversample_t nrf_saadc_oversample_get(void) +{ + return (nrf_saadc_oversample_t)NRF_SAADC->OVERSAMPLE; +} + __STATIC_INLINE void nrf_saadc_channel_init(uint8_t channel, nrf_saadc_channel_config_t const * const config) { @@ -635,12 +679,6 @@ __STATIC_INLINE void nrf_saadc_channel_init(uint8_t nrf_saadc_channel_input_set(channel, config->pin_p, config->pin_n); } -/** - * @brief Function for configuring the burst mode for the specified channel. - * - * @param[in] channel Channel number. - * @param[in] burst Burst mode setting. - */ __STATIC_INLINE void nrf_saadc_burst_set(uint8_t channel, nrf_saadc_burst_t burst) { @@ -649,10 +687,12 @@ __STATIC_INLINE void nrf_saadc_burst_set(uint8_t channel, (burst << SAADC_CH_CONFIG_BURST_Pos); } +#endif // SUPPRESS_INLINE_IMPLEMENTATION + /** @} */ #ifdef __cplusplus } #endif -#endif /* NRF_SAADC_H_ */ +#endif // NRF_SAADC_H_ diff --git a/hal/nrf_timer.h b/hal/nrf_timer.h index f925acfdd..874d8c04f 100644 --- a/hal/nrf_timer.h +++ b/hal/nrf_timer.h @@ -594,24 +594,26 @@ __STATIC_INLINE nrf_timer_int_mask_t nrf_timer_compare_int_get(uint32_t channel) ((uint32_t)NRF_TIMER_INT_COMPARE0_MASK << channel); } -__STATIC_INLINE uint32_t nrf_timer_us_to_ticks(uint32_t time_us, +__STATIC_INLINE uint32_t nrf_timer_us_to_ticks(uint32_t time_us, nrf_timer_frequency_t frequency) { // The "frequency" parameter here is actually the prescaler value, and the // timer runs at the following frequency: f = 16 MHz / 2^prescaler. uint32_t prescaler = (uint32_t)frequency; - NRFX_ASSERT(time_us <= (UINT32_MAX / 16UL)); - return ((time_us * 16UL) >> prescaler); + uint64_t ticks = ((time_us * 16ULL) >> prescaler); + NRFX_ASSERT(ticks <= UINT32_MAX); + return (uint32_t)ticks; } -__STATIC_INLINE uint32_t nrf_timer_ms_to_ticks(uint32_t time_ms, +__STATIC_INLINE uint32_t nrf_timer_ms_to_ticks(uint32_t time_ms, nrf_timer_frequency_t frequency) { // The "frequency" parameter here is actually the prescaler value, and the // timer runs at the following frequency: f = 16000 kHz / 2^prescaler. uint32_t prescaler = (uint32_t)frequency; - NRFX_ASSERT(time_ms <= (UINT32_MAX / 16000UL)); - return ((time_ms * 16000UL) >> prescaler); + uint64_t ticks = ((time_ms * 16000ULL) >> prescaler); + NRFX_ASSERT(ticks <= UINT32_MAX); + return (uint32_t)ticks; } #endif // SUPPRESS_INLINE_IMPLEMENTATION diff --git a/hal/nrf_wdt.h b/hal/nrf_wdt.h index 81c88bf96..a200a22ff 100644 --- a/hal/nrf_wdt.h +++ b/hal/nrf_wdt.h @@ -115,37 +115,21 @@ typedef enum * * @param behaviour Watchdog behavior when CPU is in SLEEP or HALT mode. */ -__STATIC_INLINE void nrf_wdt_behaviour_set(nrf_wdt_behaviour_t behaviour) -{ - NRF_WDT->CONFIG = behaviour; -} - +__STATIC_INLINE void nrf_wdt_behaviour_set(nrf_wdt_behaviour_t behaviour); /** - * @brief Function for starting the watchdog. + * @brief Function for starting the WDT task. * - * @param[in] task Task. + * @param[in] task Task. */ -__STATIC_INLINE void nrf_wdt_task_trigger(nrf_wdt_task_t task) -{ - *((volatile uint32_t *)((uint8_t *)NRF_WDT + task)) = NRF_WDT_TASK_SET; -} - +__STATIC_INLINE void nrf_wdt_task_trigger(nrf_wdt_task_t task); /** * @brief Function for clearing the WDT event. * * @param[in] event Event. */ -__STATIC_INLINE void nrf_wdt_event_clear(nrf_wdt_event_t event) -{ - *((volatile uint32_t *)((uint8_t *)NRF_WDT + (uint32_t)event)) = NRF_WDT_EVENT_CLEAR; -#if __CORTEX_M == 0x04 - volatile uint32_t dummy = *((volatile uint32_t *)((uint8_t *)NRF_WDT + (uint32_t)event)); - (void)dummy; -#endif -} - +__STATIC_INLINE void nrf_wdt_event_clear(nrf_wdt_event_t event); /** * @brief Function for retrieving the state of the WDT event. @@ -155,22 +139,14 @@ __STATIC_INLINE void nrf_wdt_event_clear(nrf_wdt_event_t event) * @retval true If the event is set. * @retval false If the event is not set. */ -__STATIC_INLINE bool nrf_wdt_event_check(nrf_wdt_event_t event) -{ - return (bool)*((volatile uint32_t *)((uint8_t *)NRF_WDT + event)); -} - +__STATIC_INLINE bool nrf_wdt_event_check(nrf_wdt_event_t event); /** * @brief Function for enabling a specific interrupt. * * @param[in] int_mask Interrupt. */ -__STATIC_INLINE void nrf_wdt_int_enable(uint32_t int_mask) -{ - NRF_WDT->INTENSET = int_mask; -} - +__STATIC_INLINE void nrf_wdt_int_enable(uint32_t int_mask); /** * @brief Function for retrieving the state of given interrupt. @@ -180,33 +156,21 @@ __STATIC_INLINE void nrf_wdt_int_enable(uint32_t int_mask) * @retval true Interrupt is enabled. * @retval false Interrupt is not enabled. */ -__STATIC_INLINE bool nrf_wdt_int_enable_check(uint32_t int_mask) -{ - return (bool)(NRF_WDT->INTENSET & int_mask); -} - +__STATIC_INLINE bool nrf_wdt_int_enable_check(uint32_t int_mask); /** * @brief Function for disabling a specific interrupt. * * @param[in] int_mask Interrupt. */ -__STATIC_INLINE void nrf_wdt_int_disable(uint32_t int_mask) -{ - NRF_WDT->INTENCLR = int_mask; -} - +__STATIC_INLINE void nrf_wdt_int_disable(uint32_t int_mask); /** * @brief Function for returning the address of a specific WDT task register. * * @param[in] task Task. */ -__STATIC_INLINE uint32_t nrf_wdt_task_address_get(nrf_wdt_task_t task) -{ - return ((uint32_t)NRF_WDT + task); -} - +__STATIC_INLINE uint32_t nrf_wdt_task_address_get(nrf_wdt_task_t task); /** * @brief Function for returning the address of a specific WDT event register. @@ -215,11 +179,7 @@ __STATIC_INLINE uint32_t nrf_wdt_task_address_get(nrf_wdt_task_t task) * * @retval address of requested event register */ -__STATIC_INLINE uint32_t nrf_wdt_event_address_get(nrf_wdt_event_t event) -{ - return ((uint32_t)NRF_WDT + event); -} - +__STATIC_INLINE uint32_t nrf_wdt_event_address_get(nrf_wdt_event_t event); /** * @brief Function for retrieving the watchdog status. @@ -227,11 +187,7 @@ __STATIC_INLINE uint32_t nrf_wdt_event_address_get(nrf_wdt_event_t event) * @retval true If the watchdog is started. * @retval false If the watchdog is not started. */ -__STATIC_INLINE bool nrf_wdt_started(void) -{ - return (bool)(NRF_WDT->RUNSTATUS); -} - +__STATIC_INLINE bool nrf_wdt_started(void); /** * @brief Function for retrieving the watchdog reload request status. @@ -241,55 +197,35 @@ __STATIC_INLINE bool nrf_wdt_started(void) * @retval true If a reload request is running. * @retval false If no reload request is running. */ -__STATIC_INLINE bool nrf_wdt_request_status(nrf_wdt_rr_register_t rr_register) -{ - return (bool)(((NRF_WDT->REQSTATUS) >> rr_register) & 0x1UL); -} - +__STATIC_INLINE bool nrf_wdt_request_status(nrf_wdt_rr_register_t rr_register); /** * @brief Function for setting the watchdog reload value. * * @param[in] reload_value Watchdog counter initial value. */ -__STATIC_INLINE void nrf_wdt_reload_value_set(uint32_t reload_value) -{ - NRF_WDT->CRV = reload_value; -} - +__STATIC_INLINE void nrf_wdt_reload_value_set(uint32_t reload_value); /** * @brief Function for retrieving the watchdog reload value. * * @retval Reload value. */ -__STATIC_INLINE uint32_t nrf_wdt_reload_value_get(void) -{ - return (uint32_t)NRF_WDT->CRV; -} - +__STATIC_INLINE uint32_t nrf_wdt_reload_value_get(void); /** * @brief Function for enabling a specific reload request register. * * @param[in] rr_register Reload request register to enable. */ -__STATIC_INLINE void nrf_wdt_reload_request_enable(nrf_wdt_rr_register_t rr_register) -{ - NRF_WDT->RREN |= 0x1UL << rr_register; -} - +__STATIC_INLINE void nrf_wdt_reload_request_enable(nrf_wdt_rr_register_t rr_register); /** * @brief Function for disabling a specific reload request register. * * @param[in] rr_register Reload request register to disable. */ -__STATIC_INLINE void nrf_wdt_reload_request_disable(nrf_wdt_rr_register_t rr_register) -{ - NRF_WDT->RREN &= ~(0x1UL << rr_register); -} - +__STATIC_INLINE void nrf_wdt_reload_request_disable(nrf_wdt_rr_register_t rr_register); /** * @brief Function for retrieving the status of a specific reload request register. @@ -299,26 +235,112 @@ __STATIC_INLINE void nrf_wdt_reload_request_disable(nrf_wdt_rr_register_t rr_reg * @retval true If the reload request register is enabled. * @retval false If the reload request register is not enabled. */ -__STATIC_INLINE bool nrf_wdt_reload_request_is_enabled(nrf_wdt_rr_register_t rr_register) -{ - return (bool)(NRF_WDT->RREN & (0x1UL << rr_register)); -} - +__STATIC_INLINE bool nrf_wdt_reload_request_is_enabled(nrf_wdt_rr_register_t rr_register); /** * @brief Function for setting a specific reload request register. * * @param[in] rr_register Reload request register to set. */ +__STATIC_INLINE void nrf_wdt_reload_request_set(nrf_wdt_rr_register_t rr_register); + +#ifndef SUPPRESS_INLINE_IMPLEMENTATION + +__STATIC_INLINE void nrf_wdt_behaviour_set(nrf_wdt_behaviour_t behaviour) +{ + NRF_WDT->CONFIG = behaviour; +} + +__STATIC_INLINE void nrf_wdt_task_trigger(nrf_wdt_task_t task) +{ + *((volatile uint32_t *)((uint8_t *)NRF_WDT + task)) = NRF_WDT_TASK_SET; +} + +__STATIC_INLINE void nrf_wdt_event_clear(nrf_wdt_event_t event) +{ + *((volatile uint32_t *)((uint8_t *)NRF_WDT + (uint32_t)event)) = NRF_WDT_EVENT_CLEAR; +#if __CORTEX_M == 0x04 + volatile uint32_t dummy = *((volatile uint32_t *)((uint8_t *)NRF_WDT + (uint32_t)event)); + (void)dummy; +#endif +} + +__STATIC_INLINE bool nrf_wdt_event_check(nrf_wdt_event_t event) +{ + return (bool)*((volatile uint32_t *)((uint8_t *)NRF_WDT + event)); +} + +__STATIC_INLINE void nrf_wdt_int_enable(uint32_t int_mask) +{ + NRF_WDT->INTENSET = int_mask; +} + +__STATIC_INLINE bool nrf_wdt_int_enable_check(uint32_t int_mask) +{ + return (bool)(NRF_WDT->INTENSET & int_mask); +} + +__STATIC_INLINE void nrf_wdt_int_disable(uint32_t int_mask) +{ + NRF_WDT->INTENCLR = int_mask; +} + +__STATIC_INLINE uint32_t nrf_wdt_task_address_get(nrf_wdt_task_t task) +{ + return ((uint32_t)NRF_WDT + task); +} + +__STATIC_INLINE uint32_t nrf_wdt_event_address_get(nrf_wdt_event_t event) +{ + return ((uint32_t)NRF_WDT + event); +} + +__STATIC_INLINE bool nrf_wdt_started(void) +{ + return (bool)(NRF_WDT->RUNSTATUS); +} + +__STATIC_INLINE bool nrf_wdt_request_status(nrf_wdt_rr_register_t rr_register) +{ + return (bool)(((NRF_WDT->REQSTATUS) >> rr_register) & 0x1UL); +} + +__STATIC_INLINE void nrf_wdt_reload_value_set(uint32_t reload_value) +{ + NRF_WDT->CRV = reload_value; +} + +__STATIC_INLINE uint32_t nrf_wdt_reload_value_get(void) +{ + return (uint32_t)NRF_WDT->CRV; +} + +__STATIC_INLINE void nrf_wdt_reload_request_enable(nrf_wdt_rr_register_t rr_register) +{ + NRF_WDT->RREN |= 0x1UL << rr_register; +} + +__STATIC_INLINE void nrf_wdt_reload_request_disable(nrf_wdt_rr_register_t rr_register) +{ + NRF_WDT->RREN &= ~(0x1UL << rr_register); +} + +__STATIC_INLINE bool nrf_wdt_reload_request_is_enabled(nrf_wdt_rr_register_t rr_register) +{ + return (bool)(NRF_WDT->RREN & (0x1UL << rr_register)); +} + __STATIC_INLINE void nrf_wdt_reload_request_set(nrf_wdt_rr_register_t rr_register) { NRF_WDT->RR[rr_register] = NRF_WDT_RR_VALUE; } +#endif // SUPPRESS_INLINE_IMPLEMENTATION + /** @} */ #ifdef __cplusplus } #endif -#endif +#endif // NRF_WDT_H__ diff --git a/templates/nRF51/nrfx_config.h b/templates/nRF51/nrfx_config.h index 1d2b6ceed..15304f7c7 100644 --- a/templates/nRF51/nrfx_config.h +++ b/templates/nRF51/nrfx_config.h @@ -1494,6 +1494,15 @@ #define NRFX_WDT_CONFIG_RELOAD_VALUE 2000 #endif +// NRFX_WDT_CONFIG_NO_IRQ - Remove WDT IRQ handling from WDT driver + +// <0=> Include WDT IRQ handling +// <1=> Remove WDT IRQ handling + +#ifndef NRFX_WDT_CONFIG_NO_IRQ +#define NRFX_WDT_CONFIG_NO_IRQ 0 +#endif + // NRFX_WDT_CONFIG_IRQ_PRIORITY - Interrupt priority // <0=> 0 (highest) diff --git a/templates/nRF52810/nrfx_config.h b/templates/nRF52810/nrfx_config.h index 3c0793674..aa0a82425 100644 --- a/templates/nRF52810/nrfx_config.h +++ b/templates/nRF52810/nrfx_config.h @@ -1999,6 +1999,15 @@ #define NRFX_WDT_CONFIG_RELOAD_VALUE 2000 #endif +// NRFX_WDT_CONFIG_NO_IRQ - Remove WDT IRQ handling from WDT driver + +// <0=> Include WDT IRQ handling +// <1=> Remove WDT IRQ handling + +#ifndef NRFX_WDT_CONFIG_NO_IRQ +#define NRFX_WDT_CONFIG_NO_IRQ 0 +#endif + // NRFX_WDT_CONFIG_IRQ_PRIORITY - Interrupt priority // <0=> 0 (highest) diff --git a/templates/nRF52832/nrfx_config.h b/templates/nRF52832/nrfx_config.h index 318b9311c..861b082ec 100644 --- a/templates/nRF52832/nrfx_config.h +++ b/templates/nRF52832/nrfx_config.h @@ -638,14 +638,14 @@ #endif // NRFX_NFCT_CONFIG_IRQ_PRIORITY - Interrupt priority -// <0=> 0 (highest) -// <1=> 1 -// <2=> 2 -// <3=> 3 -// <4=> 4 -// <5=> 5 -// <6=> 6 -// <7=> 7 +// <0=> 0 (highest) +// <1=> 1 +// <2=> 2 +// <3=> 3 +// <4=> 4 +// <5=> 5 +// <6=> 6 +// <7=> 7 #ifndef NRFX_NFCT_CONFIG_IRQ_PRIORITY #define NRFX_NFCT_CONFIG_IRQ_PRIORITY 7 @@ -658,11 +658,11 @@ #endif // NRFX_NFCT_CONFIG_LOG_LEVEL - Default Severity level -// <0=> Off -// <1=> Error -// <2=> Warning -// <3=> Info -// <4=> Debug +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug #ifndef NRFX_NFCT_CONFIG_LOG_LEVEL #define NRFX_NFCT_CONFIG_LOG_LEVEL 3 @@ -670,15 +670,15 @@ // NRFX_NFCT_CONFIG_INFO_COLOR - ANSI escape code prefix. -// <0=> Default -// <1=> Black -// <2=> Red -// <3=> Green -// <4=> Yellow -// <5=> Blue -// <6=> Magenta -// <7=> Cyan -// <8=> White +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White #ifndef NRFX_NFCT_CONFIG_INFO_COLOR #define NRFX_NFCT_CONFIG_INFO_COLOR 0 @@ -686,15 +686,15 @@ // NRFX_NFCT_CONFIG_DEBUG_COLOR - ANSI escape code prefix. -// <0=> Default -// <1=> Black -// <2=> Red -// <3=> Green -// <4=> Yellow -// <5=> Blue -// <6=> Magenta -// <7=> Cyan -// <8=> White +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White #ifndef NRFX_NFCT_CONFIG_DEBUG_COLOR #define NRFX_NFCT_CONFIG_DEBUG_COLOR 0 @@ -2871,6 +2871,15 @@ #define NRFX_WDT_CONFIG_RELOAD_VALUE 2000 #endif +// NRFX_WDT_CONFIG_NO_IRQ - Remove WDT IRQ handling from WDT driver + +// <0=> Include WDT IRQ handling +// <1=> Remove WDT IRQ handling + +#ifndef NRFX_WDT_CONFIG_NO_IRQ +#define NRFX_WDT_CONFIG_NO_IRQ 0 +#endif + // NRFX_WDT_CONFIG_IRQ_PRIORITY - Interrupt priority // <0=> 0 (highest) diff --git a/templates/nRF52840/nrfx_config.h b/templates/nRF52840/nrfx_config.h index 7bd70d82e..2df1926b0 100644 --- a/templates/nRF52840/nrfx_config.h +++ b/templates/nRF52840/nrfx_config.h @@ -638,14 +638,14 @@ #endif // NRFX_NFCT_CONFIG_IRQ_PRIORITY - Interrupt priority -// <0=> 0 (highest) -// <1=> 1 -// <2=> 2 -// <3=> 3 -// <4=> 4 -// <5=> 5 -// <6=> 6 -// <7=> 7 +// <0=> 0 (highest) +// <1=> 1 +// <2=> 2 +// <3=> 3 +// <4=> 4 +// <5=> 5 +// <6=> 6 +// <7=> 7 #ifndef NRFX_NFCT_CONFIG_IRQ_PRIORITY #define NRFX_NFCT_CONFIG_IRQ_PRIORITY 7 @@ -658,11 +658,11 @@ #endif // NRFX_NFCT_CONFIG_LOG_LEVEL - Default Severity level -// <0=> Off -// <1=> Error -// <2=> Warning -// <3=> Info -// <4=> Debug +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug #ifndef NRFX_NFCT_CONFIG_LOG_LEVEL #define NRFX_NFCT_CONFIG_LOG_LEVEL 3 @@ -670,15 +670,15 @@ // NRFX_NFCT_CONFIG_INFO_COLOR - ANSI escape code prefix. -// <0=> Default -// <1=> Black -// <2=> Red -// <3=> Green -// <4=> Yellow -// <5=> Blue -// <6=> Magenta -// <7=> Cyan -// <8=> White +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White #ifndef NRFX_NFCT_CONFIG_INFO_COLOR #define NRFX_NFCT_CONFIG_INFO_COLOR 0 @@ -686,15 +686,15 @@ // NRFX_NFCT_CONFIG_DEBUG_COLOR - ANSI escape code prefix. -// <0=> Default -// <1=> Black -// <2=> Red -// <3=> Green -// <4=> Yellow -// <5=> Blue -// <6=> Magenta -// <7=> Cyan -// <8=> White +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White #ifndef NRFX_NFCT_CONFIG_DEBUG_COLOR #define NRFX_NFCT_CONFIG_DEBUG_COLOR 0 @@ -1871,9 +1871,9 @@ // // NRFX_SPIM3_NRF52840_ANOMALY_198_WORKAROUND_ENABLED - Enables nRF52840 anomaly 198 workaround for SPIM3. - -// See more in the Errata document located at + +// See more in the Errata document located at // https://infocenter.nordicsemi.com/ #ifndef NRFX_SPIM3_NRF52840_ANOMALY_198_WORKAROUND_ENABLED @@ -2950,14 +2950,14 @@ #endif // NRFX_USBD_CONFIG_IRQ_PRIORITY - Interrupt priority -// <0=> 0 (highest) -// <1=> 1 -// <2=> 2 -// <3=> 3 -// <4=> 4 -// <5=> 5 -// <6=> 6 -// <7=> 7 +// <0=> 0 (highest) +// <1=> 1 +// <2=> 2 +// <3=> 3 +// <4=> 4 +// <5=> 5 +// <6=> 6 +// <7=> 7 #ifndef NRFX_USBD_CONFIG_IRQ_PRIORITY #define NRFX_USBD_CONFIG_IRQ_PRIORITY 7 @@ -2976,7 +2976,7 @@ #endif // USBD_CONFIG_ISO_IN_ZLP - Respond to an IN token on ISO IN endpoint with ZLP when no data is ready - + // If set, ISO IN endpoint will respond to an IN token with ZLP when no data is ready to be sent. // Else, there will be no response. @@ -2991,44 +2991,44 @@ #define NRFX_USBD_CONFIG_LOG_ENABLED 0 #endif // NRFX_USBD_CONFIG_LOG_LEVEL - Default Severity level - -// <0=> Off -// <1=> Error -// <2=> Warning -// <3=> Info -// <4=> Debug + +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug #ifndef NRFX_USBD_CONFIG_LOG_LEVEL #define NRFX_USBD_CONFIG_LOG_LEVEL 3 #endif // NRFX_USBD_CONFIG_INFO_COLOR - ANSI escape code prefix. - -// <0=> Default -// <1=> Black -// <2=> Red -// <3=> Green -// <4=> Yellow -// <5=> Blue -// <6=> Magenta -// <7=> Cyan -// <8=> White + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White #ifndef NRFX_USBD_CONFIG_INFO_COLOR #define NRFX_USBD_CONFIG_INFO_COLOR 0 #endif // NRFX_USBD_CONFIG_DEBUG_COLOR - ANSI escape code prefix. - -// <0=> Default -// <1=> Black -// <2=> Red -// <3=> Green -// <4=> Yellow -// <5=> Blue -// <6=> Magenta -// <7=> Cyan -// <8=> White + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White #ifndef NRFX_USBD_CONFIG_DEBUG_COLOR #define NRFX_USBD_CONFIG_DEBUG_COLOR 0 @@ -3061,6 +3061,15 @@ #define NRFX_WDT_CONFIG_RELOAD_VALUE 2000 #endif +// NRFX_WDT_CONFIG_NO_IRQ - Remove WDT IRQ handling from WDT driver + +// <0=> Include WDT IRQ handling +// <1=> Remove WDT IRQ handling + +#ifndef NRFX_WDT_CONFIG_NO_IRQ +#define NRFX_WDT_CONFIG_NO_IRQ 0 +#endif + // NRFX_WDT_CONFIG_IRQ_PRIORITY - Interrupt priority // <0=> 0 (highest)