Initial commit of firmware
This commit is contained in:
78
Libs/platform/service/udelay/inc/sl_udelay.h
Normal file
78
Libs/platform/service/udelay/inc/sl_udelay.h
Normal file
@@ -0,0 +1,78 @@
|
||||
/***************************************************************************//**
|
||||
* @file
|
||||
* @brief Microsecond delay.
|
||||
*******************************************************************************
|
||||
* # License
|
||||
* <b>Copyright 2020 Silicon Laboratories Inc. www.silabs.com</b>
|
||||
*******************************************************************************
|
||||
*
|
||||
* SPDX-License-Identifier: Zlib
|
||||
*
|
||||
* The licensor of this software is Silicon Laboratories Inc.
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef UDELAY_H
|
||||
#define UDELAY_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/***************************************************************************//**
|
||||
* @addtogroup udelay Microsecond Delay
|
||||
* @brief Microsecond delay function
|
||||
* @{
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* Delay a number of microseconds
|
||||
*
|
||||
* @details
|
||||
* This function will use a busy loop to delay code execution by a certain
|
||||
* number of microseconds before returning to the caller. This function will
|
||||
* not return to the caller earlier than the time given as the input parameter.
|
||||
* This function will not use any hardware timing peripherals, it is using
|
||||
* the core clock frequency to calculate the delay.
|
||||
*
|
||||
* Note that there will always be some overhead associated with calling this
|
||||
* function in addition to the internal delay loop. This overhead is relatively
|
||||
* small when the delay is large (>= 100us).
|
||||
*
|
||||
* The accuracy of this delay loop will be affected by interrupts and context
|
||||
* switching. If accuracy is needed, a hardware timer should be used
|
||||
* to handle delays.
|
||||
*
|
||||
* @param[in] us
|
||||
* This is the number of microseconds to delay execution. This function will
|
||||
* return after this amount of time has elapsed. Minimum value is 0 us and
|
||||
* maximum value is 100 000 us (100 ms). It is however recommended to use
|
||||
* the sleeptimer api for delays of more than 1 ms as it is using a hardware
|
||||
* counter and will result in better accuracy.
|
||||
*/
|
||||
void sl_udelay_wait(unsigned us);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/** @} (end addtogroup udelay) */
|
||||
|
||||
#endif
|
||||
69
Libs/platform/service/udelay/src/sl_udelay.c
Normal file
69
Libs/platform/service/udelay/src/sl_udelay.c
Normal file
@@ -0,0 +1,69 @@
|
||||
/***************************************************************************//**
|
||||
* @file
|
||||
* @brief Microsecond delay.
|
||||
*******************************************************************************
|
||||
* # License
|
||||
* <b>Copyright 2020 Silicon Laboratories Inc. www.silabs.com</b>
|
||||
*******************************************************************************
|
||||
*
|
||||
* SPDX-License-Identifier: Zlib
|
||||
*
|
||||
* The licensor of this software is Silicon Laboratories Inc.
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*
|
||||
******************************************************************************/
|
||||
#include "sl_udelay.h"
|
||||
#include "em_device.h"
|
||||
#include "sl_assert.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
/* The Cortex-M33 has a faster execution of the hw loop
|
||||
* with the same arm instructions. */
|
||||
#if defined(__CORTEX_M) && (__CORTEX_M == 33U)
|
||||
#define HW_LOOP_CYCLE 3
|
||||
#else
|
||||
#define HW_LOOP_CYCLE 4
|
||||
#endif
|
||||
|
||||
void sli_delay_loop(unsigned n);
|
||||
|
||||
void sl_udelay_wait(unsigned us)
|
||||
{
|
||||
uint32_t freq_khz;
|
||||
uint32_t ns_period;
|
||||
uint32_t cycles;
|
||||
uint32_t loops;
|
||||
|
||||
freq_khz = SystemCoreClockGet() / 1000U;
|
||||
if (freq_khz == 0) {
|
||||
EFM_ASSERT(false);
|
||||
return;
|
||||
}
|
||||
|
||||
ns_period = 1000000U / freq_khz;
|
||||
if (ns_period == 0) {
|
||||
EFM_ASSERT(false);
|
||||
return;
|
||||
}
|
||||
|
||||
cycles = us * 1000U / ns_period;
|
||||
loops = cycles / HW_LOOP_CYCLE;
|
||||
if (loops > 0U) {
|
||||
sli_delay_loop(loops);
|
||||
}
|
||||
}
|
||||
60
Libs/platform/service/udelay/src/sl_udelay_armv6m_gcc.S
Normal file
60
Libs/platform/service/udelay/src/sl_udelay_armv6m_gcc.S
Normal file
@@ -0,0 +1,60 @@
|
||||
/***************************************************************************//**
|
||||
* @file
|
||||
* @brief Microsecond delay.
|
||||
*******************************************************************************
|
||||
* # License
|
||||
* <b>Copyright 2020 Silicon Laboratories Inc. www.silabs.com</b>
|
||||
*******************************************************************************
|
||||
*
|
||||
* SPDX-License-Identifier: Zlib
|
||||
*
|
||||
* The licensor of this software is Silicon Laboratories Inc.
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
.text
|
||||
.align 4
|
||||
.syntax unified
|
||||
.thumb_func
|
||||
.global sli_delay_loop
|
||||
|
||||
/*
|
||||
* @brief
|
||||
* Hardware delay loop
|
||||
*
|
||||
* @detail
|
||||
* This is the hardware specific delay loop. It is designed specifically to
|
||||
* execute in 4 or 3 cycles for each iteration depending on the architecture.
|
||||
* Using this information the caller can use the core clock frequency to
|
||||
* calculate the number of loops required in order to delay a specific time
|
||||
* period.
|
||||
*
|
||||
* @param[in] n (r0)
|
||||
* n is the number of loops to execute. Each loop will execute in 4 cycles.
|
||||
* Note that we assume that r0 > 0, so this invariant should be checked by
|
||||
* the caller.
|
||||
*/
|
||||
sli_delay_loop:
|
||||
subs r0, r0, #1
|
||||
beq done
|
||||
b.n sli_delay_loop
|
||||
done:
|
||||
bx lr
|
||||
|
||||
.end
|
||||
Reference in New Issue
Block a user