初始版本

This commit is contained in:
xiaozhengsheng
2025-08-19 09:49:41 +08:00
parent 10f1ddf1c1
commit 6df0f7d96e
2974 changed files with 1712873 additions and 54 deletions

View File

@@ -0,0 +1,82 @@
/**
* Copyright (c) 2016 - 2020 Nordic Semiconductor ASA and Luxoft Global Operations Gmbh.
*
* 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, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, 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 Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA 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 HAL_ATOMIC_H_INCLUDED
#define HAL_ATOMIC_H_INCLUDED
#include <stdint.h>
/** @file
* This file contains declarations of the Atomic section routines and necessary types.
*
* @defgroup hal_atomic HAL Atomic API
* @ingroup hal_15_4
* @{
* @brief Module to declare HAL Atomic API
* @details The Atomic module implements atomic section interface. This is made by disabling the global interrupts,
* which is a hardware dependent feature. The user may call hal_atomic_start() to open an atomic section
* (disable interrupts) and hal_atomic_end() to exit from the section (restore interrupts). The algorithm
* supports nesting sections.
*/
typedef volatile uint32_t atomic_t;
/**@brief Enters atomic section.
*
* @details Disables global interrupts.
*
* @param[in] p_atomic pointer to buffer to store current value of the status register.
*/
void hal_atomic_start(atomic_t * p_atomic);
/**
* @brief Exits atomic section
*
* @details Restores status register
*
* @param[in] p_atomic pointer to buffer to restore current value of the status register from.
*/
void hal_atomic_end(atomic_t * p_atomic);
/** @} */
#endif // HAL_ATOMIC_H_INCLUDED

View File

@@ -0,0 +1,59 @@
/**
* Copyright (c) 2016 - 2020 Nordic Semiconductor ASA and Luxoft Global Operations Gmbh.
*
* 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, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, 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 Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA 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 HAL_CLOCK_H_INCLUDED
#define HAL_CLOCK_H_INCLUDED
/**
* @defgroup hal_clock HAL Clock API
* @ingroup hal_15_4
* @{
* @brief Module to declare HAL Clock library
*/
/** @brief This function performs initialization and configuration of processor's
* clock module.
*/
void hal_clock_init(void);
/** @} */
#endif /* HAL_CLOCK_H_INCLUDED */

View File

@@ -0,0 +1,113 @@
/**
* Copyright (c) 2016 - 2020 Nordic Semiconductor ASA and Luxoft Global Operations Gmbh.
*
* 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, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, 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 Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA 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 HAL_DEBUG_INTERFACE_H_INCLUDED
#define HAL_DEBUG_INTERFACE_H_INCLUDED
#if defined(NRF52) || defined(NRF52840_XXAA)
#include "nrf_assert.h"
#endif // NRF52
/**
* @defgroup hal_debug_interface HAL Debug Interface
* @ingroup hal_15_4
* @{
* @brief Module to declare HAL debug interface
*/
#ifdef CONFIG_DEBUG
#include <stdint.h>
#define HAL_DEBUG_INTERFACE_INIT() hal_debug_init()
#define HAL_DEBUG_INTERFACE_PUT(c, n) hal_debug_put(c, n)
#define HAL_DEBUG_INTERFACE_PUTC(c) hal_debug_putc(c)
#define HAL_DEBUG_INTERFACE_PUTS(s) hal_debug_puts(s)
/**
* @brief Debug interface initialization
*/
void hal_debug_init(void);
/**
* @brief Sends string to the debug interface
*
* @details send debug data using debug interface
*
* @param[in] p_data debug string.
* @param[in] len string length.
*/
void hal_debug_put(const void * p_data, uint8_t len);
/**
* @brief Sends char symbol to the debug interface
*
* @details send debug data using debug interface
*
* @param[in] data char symbol.
*/
void hal_debug_putc(const char data);
/**
* @brief Sends a null-terminated string to the debug interface
*
* @details send debug data using debug interface
*
* @param[in] p_data null-terminated string.
*/
void hal_debug_puts(const char * p_data);
#else
/* If debug is disabled, these macros are just a stub.*/
#define HAL_DEBUG_INTERFACE_INIT()
#define HAL_DEBUG_INTERFACE_PUT(c, n)
#define HAL_DEBUG_INTERFACE_PUTC(c)
#define HAL_DEBUG_INTERFACE_PUTS(s)
#endif // CONFIG_DEBUG
/** @} */
#endif // HAL_DEBUG_INTERFACE_H_INCLUDED

View File

@@ -0,0 +1,65 @@
/**
* Copyright (c) 2016 - 2020 Nordic Semiconductor ASA and Luxoft Global Operations Gmbh.
*
* 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, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, 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 Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA 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 HAL_DELAY_H_INCLUDED
#define HAL_DELAY_H_INCLUDED
#include <stdint.h>
/** @file
* This file contains declaration of the Hardware Delay routine.
*
* @defgroup hal_delay HAL Delay API
* @ingroup hal_15_4
* @{
* @brief Module to declare HAL Delay API
* @details The Delay module implements the only hal_delay() routine to delay the execution for some microseconds.
*/
/**@brief Function for delaying execution for number of microseconds.
*
* @param[in] number_of_us number of microseconds to delay.
*/
void hal_delay(uint32_t number_of_us);
/** @} */
#endif // HAL_DELAY_H_INCLUDED

View File

@@ -0,0 +1,54 @@
/**
* Copyright (c) 2016 - 2020 Nordic Semiconductor ASA and Luxoft Global Operations Gmbh.
*
* 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, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, 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 Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA 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 HAL_LED_H_INCLUDED
#define HAL_LED_H_INCLUDED
#include <stdint.h>
#define HAL_LED_AMOUNT 4
void hal_led_init(uint32_t led_mask);
void hal_led_on(uint32_t led_mask);
void hal_led_off(uint32_t led_mask);
void hal_led_toggle(uint32_t led_mask);
#endif /* HAL_LED_H_INCLUDED */

View File

@@ -0,0 +1,89 @@
/**
* Copyright (c) 2016 - 2020 Nordic Semiconductor ASA and Luxoft Global Operations Gmbh.
*
* 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, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, 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 Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA 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 HAL_MUTEX_H_INCLUDED
#define HAL_MUTEX_H_INCLUDED
#include "hal_atomic.h"
/** @file
* This is a simple mutex interface to be used in System Memory Manager
* to make it thread aware.
*
* @defgroup hal_mutex HAL Mutex API
* @ingroup hal_15_4
* @{
* @details NRF52 implementation is void and PC implementation is identical to atomic.
*/
#if defined ( __GNUC__ )
#include <signal.h>
typedef volatile sig_atomic_t mutex_t;
#else
#include <stdint.h>
typedef volatile uint32_t mutex_t;
#endif
/**@brief Configures mutex lock before first usage.
*
* @param[inout] p_mutex pointer to mutex variable.
*/
void hal_mutex_init(mutex_t * p_mutex);
/**@brief Atomically sets mutex. If set is failed, enters spin lock loop.
*
* @param[in] p_mutex pointer to mutex variable.
*/
void hal_mutex_lock(mutex_t * p_mutex);
/**
* @brief Atomically clears mutex. Every other thread, spinning at this lock may
* try to lock it afterwards.
*
* @param[in] p_mutex pointer to mutex variable.
*/
void hal_mutex_unlock(mutex_t * p_mutex);
/** @} */
#endif /* HAL_MUTEX_H_INCLUDED */

View File

@@ -0,0 +1,70 @@
/**
* Copyright (c) 2016 - 2020 Nordic Semiconductor ASA and Luxoft Global Operations Gmbh.
*
* 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, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, 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 Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA 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 HAL_RNG_H_INCLUDED
#define HAL_RNG_H_INCLUDED
#include <stdint.h>
/** @file
* This file contains declaration of the random number generator routine.
*
* @defgroup hal_rng HAL Random Number Generator API
* @ingroup hal_15_4
* @{
* @brief Module to declare HAL Random Number Generator API
* @details The Random number generator module implements the only hal_rand_get() routine to get an unsigned 8-bits
* random number generated by hardware.
*/
/**@brief Initialize hardware random generator.
*/
extern void hal_rand_init(void);
/**@brief Generates random number using hardware.
*
* @return An unsigned 8-bits random number.
*/
extern uint8_t hal_rand_get(void);
/** @} */
#endif /* HAL_RNG_H_INCLUDED */

View File

@@ -0,0 +1,100 @@
/**
* Copyright (c) 2016 - 2020 Nordic Semiconductor ASA and Luxoft Global Operations Gmbh.
*
* 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, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, 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 Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA 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 HAL_SLEEP_H_INCLUDED
#define HAL_SLEEP_H_INCLUDED
#include <stdint.h>
/** @file
* This file contains declaration of the HAL sleep interface.
*
* @defgroup hal_sleep HAL Sleep API
* @ingroup hal_15_4
* @{
* @brief Module to declare HAL Sleep API
* @details The Sleep module implements the only hal_sleep() routine to put the hardware to the sleep mode for some
* milliseconds. The user can use convenient macros DAYS_TO_MS(), HOURS_TO_MS(), MINS_TO_MS(), and SEC_TO_MS()
* to convert different time periods into milliseconds. Please note that this module requires a call to
* hal_sleep_init() which is in turn called by sys_init() before using any module routines. This module is
* only used to implement the System Sleep interface. The hal_sleep() routine is not assumed to be used by
* the user explicitly.
*/
/**@brief Converts days to milliseconds */
#define DAYS_TO_MS(d) ((d) * 3600L * 24L * 1000L )
/**@brief Converts hours to milliseconds */
#define HOURS_TO_MS(h) ((h) * 3600L * 1000L )
/**@brief Converts minutes to milliseconds */
#define MINS_TO_MS(m) ((m) * 60L * 1000L )
/**@brief Converts seconds to milliseconds */
#define SEC_TO_MS(s) ((s) * 1000L )
/**@brief Information, provided by the HAL, in order to explain the reason,
* which caused the system to wake up.
*/
typedef enum
{
UNKNOWN_INTERRUPT, /**< HAL can't define a wake up reason */
RTC_CC_INTERRUPT /**< RTC interrupt was the awakening reason */
} hal_wakeup_reason_t;
/**@brief Puts hardware into the sleep mode for some milliseconds.
*
* @param[in] sleep_time_ms Time to sleep in ms
*
* @retval wakeup_reason Specifies reason of awakening
*/
hal_wakeup_reason_t hal_sleep(uint32_t sleep_time_ms);
/**@brief Initialization of the sleep module
*
*/
void hal_sleep_init(void);
/** @} */
#endif /* HAL_SLEEP_H_INCLUDED */

View File

@@ -0,0 +1,124 @@
/**
* Copyright (c) 2016 - 2020 Nordic Semiconductor ASA and Luxoft Global Operations Gmbh.
*
* 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, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, 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 Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA 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 HAL_TASK_H_INCLUDED
#define HAL_TASK_H_INCLUDED
#include <stdint.h>
#include "hal_atomic.h"
#include "sys_utils.h"
#include "sys_task_scheduler.h"
/**
* @defgroup hal_task HAL Tasks
* @ingroup hal_15_4
* @{
* @brief Module to declare HAL tasks library
*/
/**@brief Identifiers for registered HAL handlers.
*
* @details enumeration with identifiers of registered HAL handlers.
* HAL handlers will be called from the HAL task.
*/
typedef enum
{
HAL_TIMER_TASK_ID,
HAL_UART_TASK_ID,
HAL_TIMER_CRITICAL_MANUAL_TASK,
HAL_TASKS_AMOUNT,
} hal_task_id_t;
/**@brief Prototype of a HAL task handler.
*
* @details Handler which will be called from HAL task.
*/
typedef void (* hal_task_handler_t)(void);
void hal_task_handler(void);
void hal_timer_task_handler(void);
void hal_uart_task_handler(void);
void hal_timer_critical_manual_handler(void);
/**@brief Pending HAL tasks.
*
* @details Variable which includes markers of pending HAL tasks.
*/
extern volatile uint_fast16_t g_hal_tasks;
/**@brief Notify task scheduler to add a HAL task for execution.
*
* @details The function sets a marker for the HAL task for execution.
*
* @param[in] hal_task_id HAL task identifier (see \ref hal_task_id_t enumeration).
*/
static inline void hal_task_post(hal_task_id_t hal_task_id)
{
atomic_t atomic = 0;
hal_atomic_start(&atomic);
g_hal_tasks |= BIT(hal_task_id);
hal_atomic_end(&atomic);
sys_task_post(HAL_TASK_ID);
}
/**@brief Removes a task from pending list in HAL task scheduler.
*
* @details The function removes a marker from the HAL execution list.
*
* @param[in] hal_task_id HAL task identifier (see \ref hal_task_id_t enumeration).
*/
static inline void hal_task_unpost(hal_task_id_t hal_task_id)
{
atomic_t atomic = 0;
hal_atomic_start(&atomic);
g_hal_tasks &= ~BIT(hal_task_id);
hal_atomic_end(&atomic);
}
/** @} */
#endif // HAL_TASK_H_INCLUDED

View File

@@ -0,0 +1,80 @@
/**
* Copyright (c) 2016 - 2020 Nordic Semiconductor ASA and Luxoft Global Operations Gmbh.
*
* 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, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, 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 Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA 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 HAL_TIMER_H_INCLUDED
#define HAL_TIMER_H_INCLUDED
#include "hal_delay.h"
#include <stdint.h>
/**
* @defgroup hal_timer HAL Timer
* @ingroup hal_15_4
* @{
* @brief Module to declare HAL timer interface
*/
/**@brief Initializes hardware timer.
*/
void hal_timer_init(void);
/**@brief Starts hardware timer.
*
* @param[in] interval timer interval in microseconds for timer start.
*/
void hal_timer_start(uint64_t interval);
/**@brief Stops hardware timer.
*/
void hal_timer_stop(void);
/**@brief Reads microseconds passed since the device start.
*
* @return time in microseconds since the device was launched.
*/
uint64_t hal_time_get(void);
/** @} */
#endif /* HAL_TIMER_H_INCLUDED */

View File

@@ -0,0 +1,82 @@
/**
* Copyright (c) 2016 - 2020 Nordic Semiconductor ASA and Luxoft Global Operations Gmbh.
*
* 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, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, 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 Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA 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 HAL_TIMER_CRITICAL_H_INCLUDED
#define HAL_TIMER_CRITICAL_H_INCLUDED
#include <stdint.h>
#include <stdbool.h>
/**
* @defgroup hal_timer_critical HAL Hardware Critical Timer
* @ingroup hal_15_4
* @{
* @brief Module to declare HAL hardware critical timer interface
*/
/**@brief Prototype for critical timer handler.
*/
typedef void (* hal_timer_critical_handler_t)(void);
/**@brief Starts hardware critical timer.
*
* @param[in] interval_us timer interval for timer start.
* @param[in] handler critical timer event handler.
*/
void hal_timer_critical_start(uint32_t interval_us, hal_timer_critical_handler_t handler);
/**@brief Stops hardware critical timer.
*/
void hal_timer_critical_stop(void);
/**@brief Check if critical timer is currently used.
*
* @retval timer_state true - timer is running now
* false - timer in stop mode
*/
bool is_critical_timer_started(void);
/** @} */
#endif /* HAL_TIMER_CRITICAL_H_INCLUDED */

View File

@@ -0,0 +1,103 @@
/**
* Copyright (c) 2016 - 2020 Nordic Semiconductor ASA and Luxoft Global Operations Gmbh.
*
* 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, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, 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 Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA 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 HAL_TRACE_INTERFACE_H_INCLUDED
#define HAL_TRACE_INTERFACE_H_INCLUDED
/**
* @defgroup hal_trace_interface HAL Trace Interface
* @ingroup hal_15_4
* @{
* @brief Module to declare HAL Trace Interface
*/
#ifdef CONFIG_TRACE
#include "hal_uart.h"
#define HAL_TRACE_INTERFACE_REUSE(p_uart_desc) hal_trace_reuse(p_uart_desc)
#define HAL_TRACE_INTERFACE_INIT() hal_trace_init()
#define HAL_TRACE_INTERFACE_PUTS(s) hal_trace_puts(s)
#define HAL_TRACE_INTERFACE_FINALIZE() hal_trace_finalize()
/**
* @brief Trace interface initialization
*/
void hal_trace_init(void);
/**
* @brief Initializes trace interface, using already initialized UART.
*
* @param[in] p_uart_desc UART descriptor, which has been already initialized.
*/
void hal_trace_reuse(hal_uart_descriptor_t * p_uart_desc);
/**
* @brief Sends a null-terminated string to the debug interface
*
* @details send debug data using debug interface
*
* @param[in] p_data null-terminated string.
*/
void hal_trace_puts(const char * p_data);
/**
* @brief Finalizes buffered trace data output to UART,
* before commencing non-buffered assertion output
*/
void hal_trace_finalize(void);
#else
/* If debug is disabled, these macros are just a stub.*/
#define HAL_TRACE_INTERFACE_REUSE(p_uart_desc)
#define HAL_TRACE_INTERFACE_INIT()
#define HAL_TRACE_INTERFACE_PUTS(s)
#define HAL_TRACE_INTERFACE_FINALIZE()
#endif // CONFIG_DEBUG
/** @} */
#endif // HAL_TRACE_INTERFACE_H_INCLUDED

View File

@@ -0,0 +1,284 @@
/**
* Copyright (c) 2016 - 2020 Nordic Semiconductor ASA and Luxoft Global Operations Gmbh.
*
* 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, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, 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 Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA 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 HAL_UART_H_INCLUDED
#define HAL_UART_H_INCLUDED
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
/** @file
* This file contains declarations of the routines, types and macros to implement the UART protocol.
*
* @defgroup hal_uart HAL UART protocol
* @ingroup hal_15_4
* @{
* @brief Module to declare HAL UART protocol
* @details The UART module implements the standard UART driver API. This includes open/close via hal_uart_open(),
* hal_uart_close(), read/write via hal_uart_read(), hal_uart_write() routines, and hal_uart_puts() for
* sending a null-terminated string in a non-blocking way. The user also can get some info about the available
* bytes for read/write via hal_uart_read_buffer_size_get() and hal_uart_write_buffer_size_get(). This implies
* that the user may register read/write buffers to use for buffered input/output and handler routines that
* will be called upon read/written characters. Also the most popular settings of the UART driver are supported:
* different baudrates, parity checks, flow control, character size, and stop bits.
*/
/** @brief Maximum size in bytes of input and output buffers. */
#define MAX_QUEUE_LENGTH 0xffffu
/** @brief Maximum size in bytes of data can be stored in hardware unit output buffer. */
#define MAX_TX_CHUNK_SIZE UCHAR_MAX
/** @brief UART baudrate. */
typedef enum
{
HAL_UART_BAUDRATE_38400, /**< 38400 bits per second.*/
HAL_UART_BAUDRATE_115200, /**< 115200 bits per second.*/
HAL_UART_BAUDRATE_230400 /**< 230400 bits per second.*/
} hal_uart_baudrate_t;
/** @brief UART parity check. */
typedef enum
{
HAL_UART_PARITY_NONE, /**< Do not check parity.*/
HAL_UART_PARITY_EVEN /**< Check even parity.*/
} hal_uart_parity_t;
/** @brief UART flow control. */
typedef enum
{
HAL_UART_FLOW_CONTROL_DISABLED, /**< Flow control is disabled.*/
HAL_UART_FLOW_CONTROL_ENABLED, /**< Flow control is enabled.*/
} hal_uart_flow_control_t;
/** @brief UART character size settings. */
typedef enum
{
HAL_UART_FIVE_BITS_CHAR = 5, /**< 5 bits character.*/
HAL_UART_SIX_BITS_CHAR, /**< 6 bits character.*/
HAL_UART_SEVEN_BITS_CHAR, /**< 7 bits character.*/
HAL_UART_EIGHT_BITS_CHAR, /**< 8 bits character.*/
} hal_uart_char_size_t;
/** @brief UART stop bits settings. */
typedef enum
{
HAL_UART_ONE_STOP_BIT, /**< 1 stop bit.*/
HAL_UART_ONEHALF_STOP_BITS, /**< 1.5 stop bits.*/
HAL_UART_TWO_STOP_BITS, /**< 2 stop bits.*/
} hal_uart_stop_bits_t;
/** @brief Represents error source for the UART driver. There might be other values,
* representing clearer elaborating of error statuses, if this module is used
* with Windows or Linux.
*/
typedef enum
{
HAL_UART_ERROR_NONE = 0, /**< Success.*/
HAL_UART_ERROR_TX_OVERFLOW = 252, /**< This error happens when amount of elements in
the transmitter ring buffer exceeds its size.
All the data above limit is not placed into
buffer.*/
HAL_UART_ERROR_RX_OVERFLOW = 253, /**< This error happens when amount of elements in
the receiver ring buffer exceeds its size.
All the unread data is overwritten with new
received data.*/
HAL_UART_ERROR_RX_UNDERFLOW = 254, /**< This error happens when the user-side software
tries to read more elements than it is available
in the receive buffer.
The user-side buffer will be filled with all available
characters and then the error handler is started.*/
HAL_UART_ERROR_HW_ERROR = 255, /**< There is some unrecoverable error in hardware.*/
} hal_uart_error_t;
/**
* @brief User-side handler of UART read and write events.
*
* @param[in] channel event channel number.
* @param[in] char_count number of characters successfully sent before entering
* the callback function.
*/
typedef void (*hal_uart_handler_t)(uint32_t channel, size_t char_count);
/**
* @brief User-side handler for UART error events.
*
* @param[in] channel event channel number.
* @param[in] error_id call reason.
*/
typedef void (*hal_uart_error_handler_t)(uint32_t channel, hal_uart_error_t error_id);
/** @brief HAL UART configuration structure.
*/
typedef struct
{
uint32_t module; /**< UART module number. By now zero
is the only option.*/
uint32_t tx_pin; /**< Number of pin used as TX.*/
uint32_t rx_pin; /**< Number of pin used as RX.*/
uint32_t cts_pin; /**< Number of pin used as CTS.*/
uint32_t rts_pin; /**< Number of pin used as RTS.*/
hal_uart_baudrate_t baudrate; /**< Baudrate selector.*/
hal_uart_parity_t parity; /**< Parity selector.*/
hal_uart_flow_control_t flow_control; /**< Flow control selector.*/
hal_uart_char_size_t char_size; /**< Size of char in bits.*/
hal_uart_stop_bits_t stop_bits; /**< Stop bits number.*/
} hal_uart_config_t;
/**
* @brief This structure defines the UART module operation.
*
* If \a write_buffer_ptr is defined as NULL, then sending data will work
* in blocking way, that is call for \a hal_uart_write will be completed
* only after sending of the last byte passed as input parameter.
*
* If \a read_buffer_ptr is defined as NULL, then driver will drop every
* received byte.
*/
typedef struct
{
hal_uart_config_t uart_config; /**< UART settings struct.*/
hal_uart_handler_t write_handler; /**< Callback function for write operation.*/
void * write_buffer_ptr; /**< User-side buffer for write operation.*/
size_t write_buffer_size; /**< Size of write operation buffer.*/
hal_uart_handler_t read_handler; /**< Callback function for read operation.*/
void * read_buffer_ptr; /**< User-side buffer for read operation.*/
size_t read_buffer_size; /**< Size of read operation buffer.*/
hal_uart_error_handler_t error_handler; /**< Callback function in case of something
goes wrong.*/
} hal_uart_descriptor_t;
/**
* @brief Configures UART interface using input parameter.
*
* @param[in] config pointer to a config struct.
* @param[in] descriptor pointer to a descriptor struct.
*
* @return Return status of operation.
*/
hal_uart_error_t hal_uart_open(const hal_uart_config_t * config,
const hal_uart_descriptor_t * descriptor);
/**
* @brief Sends data in a non-blocking way.
*
* @param[in] descriptor pointer to the UART module operation structure.
* @param[in] data pointer to the user-side buffer of output data.
* @param[in] length number of bytes to transmit.
*
* If descriptor has a non-null \a write_buffer_ptr then this function will use it
* as a temporary buffer and will copy input \a data to it before starting
* transmit. If descriptor has the NULL \a write_buffer_ptr, then the user-side code
* is responsible to retain \a data until \a write_handler is called.
*/
void hal_uart_write(const hal_uart_descriptor_t * descriptor,
const uint8_t * data,
const size_t length);
/**
* @brief Sends a null-terminated C-string in a non-blocking way.
*
* @param[in] descriptor pointer to the UART module operation structure.
* @param[in] s null-terminated string to send.
*/
void hal_uart_puts(const hal_uart_descriptor_t * descriptor, const char * s);
/**
* @brief Receives data in a non-blocking way.
*
* @param[in] descriptor pointer to the UART module operation structure.
* @param[out] data pointer to the user-side buffer used to receive data.
* @param[in] length number of bytes to receive.
*
* If descriptor has a non-null \a read_buffer_ptr, then this function is used to
* copy input characters from it to \a data.
* If \a read_buffer_ptr is NULL, then this function ignores all inputs.
*/
void hal_uart_read(const hal_uart_descriptor_t * descriptor,
uint8_t * data,
const size_t length);
/**
* @brief Returns number of bytes available to read from the income buffer of the
* driver.
*
* @param[in] descriptor pointer to driver structure.
*
* @return Number of bytes available to read.
*/
size_t hal_uart_read_buffer_size_get(const hal_uart_descriptor_t * descriptor);
/**
* @brief Returns number of bytes available to write to the outgoing buffer of the
* driver.
*
* @param[in] descriptor pointer to driver structure.
*
* @return Number of bytes available to write.
*/
size_t hal_uart_write_buffer_size_get(const hal_uart_descriptor_t * descriptor);
/**
* @brief This function deallocates resources previously allocated by hal_uart_open.
*
* @param[in] descriptor pointer to driver structure.
*
* @return Return status of operation.
*/
hal_uart_error_t hal_uart_close(const hal_uart_descriptor_t * descriptor);
#if defined(CONFIG_TRACE) && defined(CONFIG_DEBUG)
/**
* @brief Finalizes remaining trace data output to UART.
*
* @details This debugging feature is needed to finalize buffered trace output
* to UART before commencing non-buffered assertion output.
*/
void hal_uart_trace_finalize(void);
#endif
/** @} */
#endif /* HAL_UART_H_INCLUDED */

View File

@@ -0,0 +1,105 @@
/**
* Copyright (c) 2016 - 2020 Nordic Semiconductor ASA and Luxoft Global Operations Gmbh.
*
* 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, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, 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 Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA 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 HAL_UART_TASK_SCHEDULER_H_INCLUDED
#define HAL_UART_TASK_SCHEDULER_H_INCLUDED
#include <stdint.h>
#include "hal_atomic.h"
#include "hal_task_scheduler.h"
#include "sys_utils.h"
/**
* @defgroup hal_uart_task_scheduler HAL UART Task Scheduler
* @ingroup hal_15_4
* @{
* @brief Module to declare HAL UART Task Scheduler interface
*/
/**@brief Identifiers for registered UART event handlers.
*
* @details enumeration with identifiers of registered UART event handlers.
* UART handlers will be called from the HAL_UART task. */
typedef enum
{
HAL_UART_RX_TASK_ID,
HAL_UART_TX_TASK_ID,
HAL_UART_ERROR_TASK_ID,
HAL_UART_TASKS_AMOUNT,
} hal_uart_task_id_t;
/**@brief Prototype of a UART task handler.
*
* @details Handler which will be called from HAL_UART task. */
typedef void (* hal_uart_task_handler_t)(uint32_t channel);
void hal_uart_rx_handler(uint32_t channel);
void hal_uart_tx_handler(uint32_t channel);
void hal_uart_error_handler(uint32_t channel);
/**@brief UART channels.
*
* @details Array which includes event id for every channel it happened. */
extern volatile uint16_t g_hal_uart_modules_tasks[CONFIG_HAL_UART_CHANNELS];
/**@brief Notifies HAL task scheduler to add an UART task for execution.
*
* @details The function sets a marker for the UART event task for execution.
* And sets this marker for a channel where event happened.
*
* @param[in] channel event channel.
* @param[in] hal_uart_task_id HAL task identificator. */
static inline void hal_uart_task_post(uint32_t channel,
uint8_t hal_uart_task_id)
{
atomic_t atomic = 0;
hal_atomic_start(&atomic);
g_hal_uart_modules_tasks[channel] |= BIT(hal_uart_task_id);
hal_atomic_end(&atomic);
hal_task_post(HAL_UART_TASK_ID);
}
/** @} */
#endif /* HAL_UART_TASK_SCHEDULER_H_INCLUDED */

View File

@@ -0,0 +1,90 @@
/**
* Copyright (c) 2016 - 2020 Nordic Semiconductor ASA and Luxoft Global Operations Gmbh.
*
* 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, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, 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 Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA 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 HAL_EXCEPTIONS_H_INCLUDED
#define HAL_EXCEPTIONS_H_INCLUDED
#include <stdint.h>
/**
* @defgroup hal_15_4_nrf52 Chip-specific library interface
* @ingroup hal_15_4
*
* @defgroup hal_nrf52_exceptions HAL exceptions
* @ingroup hal_15_4_nrf52
* @{
*/
/** @brief Size of stack dump in 4-byte words.*/
#define HAL_EXCEPTIONS_DUMP_SIZE 16
/** @brief Defines where to put a '\n' in stack dump.
*
* This value defines power of 2 items in one row.
* E.g. 3 gives 2 ^ 3 = 8 items in a row.*/
#define HAL_EXCEPTIONS_ITEMS_IN_LINE 3
/** @brief This structure holds values of fault status registers.*/
typedef struct
{
uint32_t CFSR; /*!< Configurable Fault Status Register.*/
uint32_t HFSR; /*!< HardFault Status Register.*/
uint32_t DFSR; /*!< Debug Fault Status Register.*/
uint32_t AFSR; /*!< Auxiliary Fault Status Register.*/
} hal_exceptions_status_registers_t;
/** @brief This structure is put into dump monitor port and holds values of said
* registers when exception has happen.*/
typedef struct
{
uint32_t R0; /**< Register R0 (Argument 1 / word result).*/
uint32_t R1; /**< Register R1 (Argument 2 / double-word result).*/
uint32_t R2; /**< Register R2 (Argument 3).*/
uint32_t R3; /**< Register R3 (Argument 4).*/
uint32_t R12; /**< Register R12 (Scratch register (corruptible)).*/
uint32_t LR; /**< Link register (R14).*/
uint32_t PC; /**< Program counter (R15).*/
uint32_t PSR; /**< Combined processor status register.*/
uint32_t* FP; /**< Value of register, which may be used as Frame Pointer.*/
} hal_exceptions_dump_t;
/** @} */
#endif // HAL_EXCEPTIONS_H_INCLUDED

View File

@@ -0,0 +1,107 @@
/**
* Copyright (c) 2016 - 2020 Nordic Semiconductor ASA and Luxoft Global Operations Gmbh.
*
* 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, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, 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 Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA 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 HAL_NRF52_RTC_H_INCLUDED
#define HAL_NRF52_RTC_H_INCLUDED
#include "nordic_common.h"
#include "nrf_drv_config.h"
#include "nrf_drv_common.h"
#include "nrf_drv_rtc.h"
#include "nrf_rtc.h"
/**
* @defgroup hal_nrf52_rtc HAL RTC
* @ingroup hal_15_4_nrf52
* @{
*/
// RTC counter bitlenght
#define LAGEST_PRESCALER_VALUE 4096
// RTC counter bitlenght
#define RTC_CNT_BITLENGHT 24
// Longest sleep time, ms
#define LONGEST_SLEEP_TIME ((( 1UL << RTC_CNT_BITLENGHT ) \
/(RTC_INPUT_FREQ/LAGEST_PRESCALER_VALUE)) * 1000UL )
// Shortest sleep time, ms
#define SHORTEST_SLEEP_TIME 1
/**@brief Function for initialize low frequency clock
*/
void rtc_lfclk_start(void);
/** @brief Function initialization and configuration of RTC driver instance.
*
* @param[in] sleep_time_ms after this time compare event will be triggered
*/
void rtc_start(uint32_t sleep_time_ms);
/** @brief Stop RTC
*/
void rtc_stop(void);
/** @brief Get RTC counter
*
* @retval uint32_t Contents of RTC counter register.
*/
uint32_t rtc_cnt_get(void);
/** @brief Get time elapsed since cnt_ticks
*
* @param[in] cnt_ticks Number of rtc-ticks
*
* @retval uint32_t Time since cnt_ticks, ms
*/
uint64_t get_rtc_time_since(uint32_t cnt_ticks);
/** @brief Check if rtc compare interrupt was triggered after calling
* rtc_start function
*
* @retval bool true - compare interrupt was triggered
* false - it wasn't
*/
bool is_rtc_comp_irq_triggerd(void);
/** @} */
#endif /* HAL_NRF52_RTC_H_INCLUDED */

View File

@@ -0,0 +1,75 @@
/**
* Copyright (c) 2016 - 2020 Nordic Semiconductor ASA and Luxoft Global Operations Gmbh.
*
* 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, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, 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 Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA 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 HAL_NRF52_TIMER_INCLUDED
#define HAL_NRF52_TIMER_INCLUDED
/**
* @defgroup hal_nrf52_timer HAL timer - additional features
* @ingroup hal_15_4_nrf52
* @{
*/
/**@brief Pause hardware timer.
*/
void hal_timer_pause(void);
/**@brief Resume hardware timer.
*/
void hal_timer_resume(void);
/**@brief Set a new system time
*
* @param[in] time_us time to set.
*/
void hal_time_adjust(uint64_t time_us);
/**@brief Uninit hardwware timer
*/
void hal_timer_uninit(void);
/** @} */
#endif /* HAL_NRF52_TIMER_INCLUDED */