mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-09-21 02:06:14 +08:00
Add bsp apollo2
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,348 @@
|
||||
//*****************************************************************************
|
||||
//
|
||||
// am_hal_adc.h
|
||||
//! @file
|
||||
//!
|
||||
//! @brief Functions for interfacing with the Analog to Digital Converter
|
||||
//!
|
||||
//! @addtogroup adc2 Analog-to-Digital Converter (ADC)
|
||||
//! @ingroup apollo2hal
|
||||
//! @{
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Copyright (c) 2017, Ambiq Micro
|
||||
// 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.
|
||||
//
|
||||
// This is part of revision 1.2.9 of the AmbiqSuite Development Package.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#ifndef AM_HAL_ADC_H
|
||||
#define AM_HAL_ADC_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @name Clock Selection
|
||||
//! @brief These macros may be used to set the ADC module's clock source.
|
||||
//! @{
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define AM_HAL_ADC_CLOCK_OFF AM_REG_ADC_CFG_CLKSEL_OFF
|
||||
#define AM_HAL_ADC_CLOCK_HFRC AM_REG_ADC_CFG_CLKSEL_HFRC
|
||||
#define AM_HAL_ADC_CLOCK_DIV2 AM_REG_ADC_CFG_CLKSEL_HFRC_DIV2
|
||||
//! @}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @name Trigger Settings
|
||||
//! @brief ADC trigger setting macros.
|
||||
//!
|
||||
//! These macros alter the ADC's trigger source and trigger polarity. Note that
|
||||
//! the external trigger setting needs to be ORed with a POS or NEG option to
|
||||
//! define the desired trigger polarity.
|
||||
//! @{
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define AM_HAL_ADC_TRIGGER_SOFT AM_REG_ADC_CFG_TRIGSEL_SWT
|
||||
#define AM_HAL_ADC_TRIGGER_VCOMP AM_REG_ADC_CFG_TRIGSEL_VCOMP
|
||||
#define AM_HAL_ADC_TRIGGER_EXT0 AM_REG_ADC_CFG_TRIGSEL_EXT0
|
||||
#define AM_HAL_ADC_TRIGGER_EXT1 AM_REG_ADC_CFG_TRIGSEL_EXT1
|
||||
#define AM_HAL_ADC_TRIGGER_EXT2 AM_REG_ADC_CFG_TRIGSEL_EXT2
|
||||
#define AM_HAL_ADC_TRIGGER_EXT3 AM_REG_ADC_CFG_TRIGSEL_EXT3
|
||||
#define AM_HAL_ADC_TRIGGER_FALL AM_REG_ADC_CFG_TRIGPOL_FALLING_EDGE
|
||||
#define AM_HAL_ADC_TRIGGER_RISE AM_REG_ADC_CFG_TRIGPOL_RISING_EDGE
|
||||
//! @}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @name Reference Settings
|
||||
//! @brief ADC reference voltage setting macros.
|
||||
//!
|
||||
//! These macros control the ADC reference voltage source.
|
||||
//! @{
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define AM_HAL_ADC_REF_EXT_2P0 AM_REG_ADC_CFG_REFSEL_EXT2P0
|
||||
#define AM_HAL_ADC_REF_EXT_1P5 AM_REG_ADC_CFG_REFSEL_EXT1P5
|
||||
#define AM_HAL_ADC_REF_INT_2P0 AM_REG_ADC_CFG_REFSEL_INT2P0
|
||||
#define AM_HAL_ADC_REF_INT_1P5 AM_REG_ADC_CFG_REFSEL_INT1P5
|
||||
//! @}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @name Clock Mode
|
||||
//! @brief ADC clock mode settings
|
||||
//!
|
||||
//! These macros determine whether the ADC shuts down its clock between
|
||||
//! samples. Shutting down the clock will reduce power consumption, but
|
||||
//! increase latency. This setting is only valid for LPMODE 0. For other modes,
|
||||
//! it will be ignored.
|
||||
//!
|
||||
//! @{
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define AM_HAL_ADC_CK_LOW_POWER AM_REG_ADC_CFG_CKMODE_LPCKMODE
|
||||
#define AM_HAL_ADC_CK_LOW_LATENCY AM_REG_ADC_CFG_CKMODE_LLCKMODE
|
||||
//! @}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @name Low Power Mode
|
||||
//! @brief ADC power conservation settings.
|
||||
//!
|
||||
//! These macros select the power state to enter between active scans. Each low
|
||||
//! power mode has its own set of timing constraints. Please see the datasheet
|
||||
//! for additional timing information on each power mode.
|
||||
//! @{
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define AM_HAL_ADC_LPMODE_0 AM_REG_ADC_CFG_LPMODE_MODE0
|
||||
#define AM_HAL_ADC_LPMODE_1 AM_REG_ADC_CFG_LPMODE_MODE1
|
||||
//! @}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @name Repeat Mode
|
||||
//! @brief Enable repeating scan mode.
|
||||
//!
|
||||
//! Use this macro to enable repeating scans using timer 3.
|
||||
//!
|
||||
//! @{
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define AM_HAL_ADC_REPEAT AM_REG_ADC_CFG_RPTEN(1)
|
||||
#define AM_HAL_ADC_NO_REPEAT AM_REG_ADC_CFG_RPTEN(0)
|
||||
//! @}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @name Slot configuration
|
||||
//! @brief Slot configuration macros
|
||||
//!
|
||||
//! These macros may be used to configure an individual ADC slot.
|
||||
//! @{
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
// Set number of samples to average.
|
||||
#define AM_HAL_ADC_SLOT_AVG_1 AM_REG_ADC_SL0CFG_ADSEL0(0)
|
||||
#define AM_HAL_ADC_SLOT_AVG_2 AM_REG_ADC_SL0CFG_ADSEL0(1)
|
||||
#define AM_HAL_ADC_SLOT_AVG_4 AM_REG_ADC_SL0CFG_ADSEL0(2)
|
||||
#define AM_HAL_ADC_SLOT_AVG_8 AM_REG_ADC_SL0CFG_ADSEL0(3)
|
||||
#define AM_HAL_ADC_SLOT_AVG_16 AM_REG_ADC_SL0CFG_ADSEL0(4)
|
||||
#define AM_HAL_ADC_SLOT_AVG_32 AM_REG_ADC_SL0CFG_ADSEL0(5)
|
||||
#define AM_HAL_ADC_SLOT_AVG_64 AM_REG_ADC_SL0CFG_ADSEL0(6)
|
||||
#define AM_HAL_ADC_SLOT_AVG_128 AM_REG_ADC_SL0CFG_ADSEL0(7)
|
||||
|
||||
// Set slot precision mode.
|
||||
#define AM_HAL_ADC_SLOT_14BIT AM_REG_ADC_SL0CFG_PRMODE0_P14B
|
||||
#define AM_HAL_ADC_SLOT_12BIT AM_REG_ADC_SL0CFG_PRMODE0_P14B
|
||||
#define AM_HAL_ADC_SLOT_10BIT AM_REG_ADC_SL0CFG_PRMODE0_P14B
|
||||
#define AM_HAL_ADC_SLOT_8BIT AM_REG_ADC_SL0CFG_PRMODE0_P14B
|
||||
|
||||
// Select a channel by number.
|
||||
#define AM_HAL_ADC_SLOT_CHANNEL(n) AM_REG_ADC_SL0CFG_CHSEL0(n)
|
||||
|
||||
// Single-ended channels
|
||||
#define AM_HAL_ADC_SLOT_CHSEL_SE0 AM_REG_ADC_SL0CFG_CHSEL0_SE0
|
||||
#define AM_HAL_ADC_SLOT_CHSEL_SE1 AM_REG_ADC_SL0CFG_CHSEL0_SE1
|
||||
#define AM_HAL_ADC_SLOT_CHSEL_SE2 AM_REG_ADC_SL0CFG_CHSEL0_SE2
|
||||
#define AM_HAL_ADC_SLOT_CHSEL_SE3 AM_REG_ADC_SL0CFG_CHSEL0_SE3
|
||||
#define AM_HAL_ADC_SLOT_CHSEL_SE4 AM_REG_ADC_SL0CFG_CHSEL0_SE4
|
||||
#define AM_HAL_ADC_SLOT_CHSEL_SE5 AM_REG_ADC_SL0CFG_CHSEL0_SE5
|
||||
#define AM_HAL_ADC_SLOT_CHSEL_SE6 AM_REG_ADC_SL0CFG_CHSEL0_SE6
|
||||
#define AM_HAL_ADC_SLOT_CHSEL_SE7 AM_REG_ADC_SL0CFG_CHSEL0_SE7
|
||||
#define AM_HAL_ADC_SLOT_CHSEL_SE8 AM_REG_ADC_SL0CFG_CHSEL0_SE8
|
||||
#define AM_HAL_ADC_SLOT_CHSEL_SE9 AM_REG_ADC_SL0CFG_CHSEL0_SE9
|
||||
|
||||
// Differential channels.
|
||||
#define AM_HAL_ADC_SLOT_CHSEL_DF0 AM_REG_ADC_SL0CFG_CHSEL0_DF0
|
||||
#define AM_HAL_ADC_SLOT_CHSEL_DF1 AM_REG_ADC_SL0CFG_CHSEL0_DF1
|
||||
|
||||
// Miscellaneous other signals.
|
||||
#define AM_HAL_ADC_SLOT_CHSEL_TEMP AM_REG_ADC_SL0CFG_CHSEL0_TEMP
|
||||
#define AM_HAL_ADC_SLOT_CHSEL_VSS AM_REG_ADC_SL0CFG_CHSEL0_VSS
|
||||
#define AM_HAL_ADC_SLOT_CHSEL_VBATT AM_REG_ADC_SL0CFG_CHSEL0_BATT
|
||||
|
||||
// Window enable.
|
||||
#define AM_HAL_ADC_SLOT_WINDOW_EN AM_REG_ADC_SL0CFG_WCEN0(1)
|
||||
|
||||
// Enable the slot.
|
||||
#define AM_HAL_ADC_SLOT_ENABLE AM_REG_ADC_SL0CFG_SLEN0(1)
|
||||
//! @}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @name Interrupt Status Bits
|
||||
//! @brief Interrupt Status Bits for enable/disble use
|
||||
//!
|
||||
//! These macros may be used to enable an individual ADC interrupt cause.
|
||||
//! @{
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define AM_HAL_ADC_INT_WCINC AM_REG_ADC_INTEN_WCINC(1)
|
||||
#define AM_HAL_ADC_INT_WCEXC AM_REG_ADC_INTEN_WCEXC(1)
|
||||
#define AM_HAL_ADC_INT_FIFOOVR2 AM_REG_ADC_INTEN_FIFOOVR2(1)
|
||||
#define AM_HAL_ADC_INT_FIFOOVR1 AM_REG_ADC_INTEN_FIFOOVR1(1)
|
||||
#define AM_HAL_ADC_INT_SCNCMP AM_REG_ADC_INTEN_SCNCMP(1)
|
||||
#define AM_HAL_ADC_INT_CNVCMP AM_REG_ADC_INTEN_CNVCMP(1)
|
||||
//! @}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @name Temperature Trim Value Locations
|
||||
//! @brief Temperature calibration cofficients are stored in readable space.
|
||||
//!
|
||||
//! These macros are used to access the temperature trim values in readable
|
||||
//! space.
|
||||
//! @{
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define AM_HAL_ADC_CALIB_TEMP_ADDR (0x50023010)
|
||||
#define AM_HAL_ADC_CALIB_AMBIENT_ADDR (0x50023014)
|
||||
#define AM_HAL_ADC_CALIB_ADC_OFFSET_ADDR (0x50023018)
|
||||
|
||||
//
|
||||
// Default coefficients (used when trims not provided):
|
||||
// TEMP_DEFAULT = Temperature in deg K (e.g. 299.5 - 273.15 = 26.35)
|
||||
// AMBIENT_DEFAULT = Voltage measurement at default temperature.
|
||||
// OFFSET_DEFAULT = Default ADC offset at 1v.
|
||||
//
|
||||
#define AM_HAL_ADC_CALIB_TEMP_DEFAULT (299.5F)
|
||||
#define AM_HAL_ADC_CALIB_AMBIENT_DEFAULT (1.02809F)
|
||||
#define AM_HAL_ADC_CALIB_ADC_OFFSET_DEFAULT (-0.004281F)
|
||||
//! @}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Configuration structure for the ADC.
|
||||
//
|
||||
//*****************************************************************************
|
||||
typedef struct
|
||||
{
|
||||
//! Select the ADC Clock source using one of the clock source macros.
|
||||
uint32_t ui32Clock;
|
||||
|
||||
//! Select the ADC trigger source using a trigger source macro.
|
||||
uint32_t ui32TriggerConfig;
|
||||
|
||||
//! Use a macro to select the ADC reference voltage.
|
||||
uint32_t ui32Reference;
|
||||
|
||||
//! Use a macro to decide whether to disable clocks between samples.
|
||||
uint32_t ui32ClockMode;
|
||||
|
||||
//! Use a macro to select the ADC power mode.
|
||||
uint32_t ui32PowerMode;
|
||||
|
||||
//! Select whether the ADC will re-trigger based on a signal from timer 3.
|
||||
uint32_t ui32Repeat;
|
||||
}
|
||||
am_hal_adc_config_t;
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief ADC Fifo Read macros
|
||||
//!
|
||||
//! These are helper macros for interpreting FIFO data. Each ADC FIFO entry
|
||||
//! contains information about the slot number and the FIFO depth alongside the
|
||||
//! current sample. These macros perform the correct masking and shifting to
|
||||
//! read those values.
|
||||
//!
|
||||
//! The SAMPLE and FULL_SAMPLE options refer to the fractional part of averaged
|
||||
//! samples. If you are not using hardware averaging or don't need the
|
||||
//! fractional part of the ADC sample, you should just use
|
||||
//! AM_HAL_ADC_FIFO_SAMPLE.
|
||||
//!
|
||||
//! If you do need the fractional part, use AM_HAL_ADC_FIFO_FULL_SAMPLE. This
|
||||
//! macro will keep six bits of precision past the decimal point. Depending on
|
||||
//! the number of averaged samples, anywhere between 1 and 6 of these bits will
|
||||
//! be valid. Please consult the datasheet to find out how many bits of data
|
||||
//! are valid for your chosen averaging settings.
|
||||
//!
|
||||
//! @{
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define AM_HAL_ADC_FIFO_SAMPLE(value) \
|
||||
((((value) & AM_REG_ADC_FIFO_DATA_M) >> AM_REG_ADC_FIFO_DATA_S) >> 6)
|
||||
|
||||
#define AM_HAL_ADC_FIFO_FULL_SAMPLE(value) \
|
||||
(((value) & AM_REG_ADC_FIFO_DATA_M) >> AM_REG_ADC_FIFO_DATA_S )
|
||||
|
||||
#define AM_HAL_ADC_FIFO_SLOT(value) \
|
||||
(((value) & AM_REG_ADC_FIFO_SLOTNUM_M) >> AM_REG_ADC_FIFO_SLOTNUM_S)
|
||||
|
||||
#define AM_HAL_ADC_FIFO_COUNT(value) \
|
||||
(((value) & AM_REG_ADC_FIFO_COUNT_M) >> AM_REG_ADC_FIFO_COUNT_S)
|
||||
//! @}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// External function definitions
|
||||
//
|
||||
//*****************************************************************************
|
||||
extern void am_hal_adc_config(am_hal_adc_config_t *psConfig);
|
||||
extern void am_hal_adc_window_set(uint32_t ui32Upper, uint32_t ui32Lower);
|
||||
extern void am_hal_adc_slot_config(uint32_t ui32SlotNumber,
|
||||
uint32_t ui32SlotConfig);
|
||||
|
||||
extern uint32_t am_hal_adc_fifo_peek(void);
|
||||
extern uint32_t am_hal_adc_fifo_pop(void);
|
||||
|
||||
extern void am_hal_adc_trigger(void);
|
||||
extern void am_hal_adc_enable(void);
|
||||
extern void am_hal_adc_disable(void);
|
||||
extern void am_hal_adc_int_enable(uint32_t ui32Interrupt);
|
||||
extern uint32_t am_hal_adc_int_enable_get(void);
|
||||
extern void am_hal_adc_int_disable(uint32_t ui32Interrupt);
|
||||
extern void am_hal_adc_int_clear(uint32_t ui32Interrupt);
|
||||
extern void am_hal_adc_int_set(uint32_t ui32Interrupt);
|
||||
extern uint32_t am_hal_adc_int_status_get(bool bEnabledOnly);
|
||||
extern float am_hal_adc_volts_to_celsius(float fVoltage);
|
||||
extern void am_hal_adc_temp_trims_get(float * pfTemp, float * pfVoltage, float * pfOffsetV);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // AM_HAL_ADC_H
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// End Doxygen group.
|
||||
//! @}
|
||||
//
|
||||
//*****************************************************************************
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,211 @@
|
||||
//*****************************************************************************
|
||||
//
|
||||
// am_hal_cachectrl.h
|
||||
//! @file
|
||||
//!
|
||||
//! @brief Functions for accessing and configuring the CACHE controller.
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Copyright (c) 2017, Ambiq Micro
|
||||
// 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.
|
||||
//
|
||||
// This is part of revision 1.2.9 of the AmbiqSuite Development Package.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#ifndef AM_HAL_CACHECTRL_H
|
||||
#define AM_HAL_CACHECTRL_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Cache configuration structure
|
||||
//
|
||||
//*****************************************************************************
|
||||
typedef struct
|
||||
{
|
||||
//
|
||||
//! Set to 1 to enable the cache.
|
||||
//
|
||||
uint8_t ui32EnableCache;
|
||||
|
||||
//
|
||||
//! Set to 1 to enable the LRU cache replacement policy.
|
||||
//! Set to 0 to enable the LRR (least recently used) replacement policy.
|
||||
//! LEE minimizes writes to the TAG SRAM.
|
||||
//
|
||||
uint8_t ui32LRU;
|
||||
|
||||
//
|
||||
//! Set to 3 to enable non-cachable region 1 and non-cachable region 0.
|
||||
//! Set to 2 to enable non-cachable region 1.
|
||||
//! Set to 1 to enable non-cachable region 0.
|
||||
//! Set to 0 to make all regions cacheable.
|
||||
//
|
||||
uint8_t ui32EnableNCregions;
|
||||
|
||||
//
|
||||
//! Set to:
|
||||
//! AM_HAL_CACHECTRL_CACHECFG_CONFIG_DIRECT_256 for direct-mapped,
|
||||
//! 128-bit linesize, 256 entries (2 SRAMs active)
|
||||
//! AM_HAL_CACHECTRL_CACHECFG_CONFIG_2WAY_256 for two-way set associative,
|
||||
//! 128-bit linesize, 256 entries (4 SRAMs active)
|
||||
//! AM_HAL_CACHECTRL_CACHECFG_CONFIG_2WAY_512 for two-way set associative,
|
||||
//! 128-bit linesize, 512 entries (8 SRAMs active)
|
||||
//
|
||||
uint8_t ui32Config;
|
||||
|
||||
//
|
||||
//! Set to 1 to enable serial cache mode.
|
||||
//
|
||||
uint8_t ui32SerialCacheMode;
|
||||
|
||||
//
|
||||
//! Set to 3 to enable flash data caching and flash instruction caching.
|
||||
//! Set to 2 to enable flash data caching.
|
||||
//! Set to 1 to enable flash instruction caching.
|
||||
//! Set to 0 to disable flash data caching and flash instruction caching.
|
||||
//
|
||||
uint8_t ui32FlashCachingEnables;
|
||||
|
||||
//
|
||||
//! Set to 1 to enable clock gating of cache RAMs.
|
||||
//
|
||||
uint8_t ui32EnableCacheClockGating;
|
||||
|
||||
//
|
||||
//! Set to 1 to enable light sleep of cache RAMs.
|
||||
//
|
||||
uint8_t ui32EnableLightSleep;
|
||||
|
||||
//
|
||||
//! Set Data RAM delay value (0x0 - 0xF).
|
||||
//
|
||||
uint8_t ui32Dly;
|
||||
|
||||
//
|
||||
//! Set SM Data RAM delay value (0x0 - 0xF).
|
||||
//
|
||||
uint8_t ui32SMDly;
|
||||
|
||||
//
|
||||
//! Set to 1 to enable clock gating of the entire data array.
|
||||
//
|
||||
uint8_t ui32EnableDataClockGating;
|
||||
|
||||
//
|
||||
//! Set to 1 to enable cache monitor statistics.
|
||||
//
|
||||
uint8_t ui32EnableCacheMonitoring;
|
||||
}
|
||||
am_hal_cachectrl_config_t;
|
||||
|
||||
extern const am_hal_cachectrl_config_t am_hal_cachectrl_defaults;
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @name Cache enables
|
||||
//! @brief Configuration selection for the various cache enables.
|
||||
//!
|
||||
//! These macros may be used in conjunction with the
|
||||
//! am_hal_cachectrl_cache_enable() function to enable various cache features.
|
||||
//!
|
||||
//! @{
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define AM_HAL_CACHECTRL_CACHECFG_ENABLE AM_REG_CACHECTRL_CACHECFG_ENABLE_M
|
||||
#define AM_HAL_CACHECTRL_CACHECFG_LRU_ENABLE AM_REG_CACHECTRL_CACHECFG_LRU_M
|
||||
#define AM_HAL_CACHECTRL_CACHECFG_NC0_ENABLE AM_REG_CACHECTRL_CACHECFG_ENABLE_NC0_M
|
||||
#define AM_HAL_CACHECTRL_CACHECFG_NC1_ENABLE AM_REG_CACHECTRL_CACHECFG_ENABLE_NC1_M
|
||||
#define AM_HAL_CACHECTRL_CACHECFG_SERIAL_ENABLE AM_REG_CACHECTRL_CACHECFG_SERIAL_M
|
||||
#define AM_HAL_CACHECTRL_CACHECFG_ICACHE_ENABLE AM_REG_CACHECTRL_CACHECFG_ICACHE_ENABLE_M
|
||||
#define AM_HAL_CACHECTRL_CACHECFG_DCACHE_ENABLE AM_REG_CACHECTRL_CACHECFG_DCACHE_ENABLE_M
|
||||
#define AM_HAL_CACHECTRL_CACHECFG_CACHE_CLKGATE_ENABLE AM_REG_CACHECTRL_CACHECFG_CACHE_CLKGATE_M
|
||||
#define AM_HAL_CACHECTRL_CACHECFG_LS_ENABLE AM_REG_CACHECTRL_CACHECFG_CACHE_LS_M
|
||||
#define AM_HAL_CACHECTRL_CACHECFG_DATA_CLKGATE_ENABLE AM_REG_CACHECTRL_CACHECFG_DATA_CLKGATE_M
|
||||
#define AM_HAL_CACHECTRL_CACHECFG_MONITOR_ENABLE AM_REG_CACHECTRL_CACHECFG_ENABLE_MONITOR_M
|
||||
//! @}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @name Cache Config
|
||||
//! @brief Configuration selection for the cache.
|
||||
//!
|
||||
//! These macros may be used in conjunction with the
|
||||
//! am_hal_cachectrl_cache_config() function to select the cache type.
|
||||
//!
|
||||
//! @{
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define AM_HAL_CACHECTRL_CACHECFG_CONFIG_DIRECT_256 AM_REG_CACHECTRL_CACHECFG_CONFIG_W1_128B_256E
|
||||
#define AM_HAL_CACHECTRL_CACHECFG_CONFIG_2WAY_256 AM_REG_CACHECTRL_CACHECFG_CONFIG_W2_128B_256E
|
||||
#define AM_HAL_CACHECTRL_CACHECFG_CONFIG_2WAY_512 AM_REG_CACHECTRL_CACHECFG_CONFIG_W2_128B_512E
|
||||
//! @}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Default cache settings
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define AM_HAL_CACHECTRL_DEFAULTS \
|
||||
(AM_HAL_CACHECTRL_CACHECFG_ICACHE_ENABLE | \
|
||||
AM_HAL_CACHECTRL_CACHECFG_DCACHE_ENABLE | \
|
||||
AM_HAL_CACHECTRL_CACHECFG_CACHE_CLKGATE_ENABLE | \
|
||||
AM_HAL_CACHECTRL_CACHECFG_DATA_CLKGATE_ENABLE | \
|
||||
AM_HAL_CACHECTRL_CACHECFG_CONFIG_2WAY_512)
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// External function definitions
|
||||
//
|
||||
//*****************************************************************************
|
||||
extern void am_hal_cachectrl_enable(const am_hal_cachectrl_config_t *psConfig);
|
||||
extern void am_hal_cachectrl_disable(void);
|
||||
extern void am_hal_cachectrl_config_default(void);
|
||||
extern void am_hal_cachectrl_config(am_hal_cachectrl_config_t *psConfig);
|
||||
extern uint32_t am_hal_cachectrl_cache_enables(uint32_t u32EnableMask,
|
||||
uint32_t u32DisableMask);
|
||||
extern void am_hal_cachectrl_cache_config(uint32_t ui32CacheConfig);
|
||||
extern void am_hal_cachectrl_invalidate_flash_cache(void);
|
||||
extern void am_hal_cachectrl_reset_statistics(void);
|
||||
extern uint32_t am_hal_cachectrl_sleep_mode_status(void);
|
||||
extern uint32_t am_hal_cachectrl_sleep_mode_enable(uint32_t ui32EnableMask,
|
||||
uint32_t ui32DisableMask);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // AM_HAL_CACHECTRL_H
|
||||
@@ -0,0 +1,491 @@
|
||||
//*****************************************************************************
|
||||
//
|
||||
// am_hal_clkgen.c
|
||||
//! @file
|
||||
//!
|
||||
//! @brief Functions for interfacing with the CLKGEN.
|
||||
//!
|
||||
//! @addtogroup clkgen2 Clock Generator (CLKGEN)
|
||||
//! @ingroup apollo2hal
|
||||
//! @{
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Copyright (c) 2017, Ambiq Micro
|
||||
// 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.
|
||||
//
|
||||
// This is part of revision 1.2.9 of the AmbiqSuite Development Package.
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "am_mcu_apollo.h"
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// CLKGEN HFADJ register
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define AM_REG_CLKGEN_HFADJ_HFXTADJ_DEFAULT 0x5B8
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Select the clock divisor for the main system clock.
|
||||
//!
|
||||
//! @param ui32ClockSetting - The divisor value for the system clock.
|
||||
//!
|
||||
//! This function can be used to select the frequency of the main system clock.
|
||||
//! The \e ui32ClockSetting parameter should be set to one of the following
|
||||
//! values:
|
||||
//!
|
||||
//! AM_HAL_CLKGEN_SYSCLK_MAX
|
||||
//! AM_HAL_CLKGEN_SYSCLK_48MHZ
|
||||
//!
|
||||
//! @return None.
|
||||
//
|
||||
//*****************************************************************************
|
||||
void
|
||||
am_hal_clkgen_sysclk_select(uint32_t ui32ClockSetting)
|
||||
{
|
||||
am_hal_debug_assert_msg(ui32ClockSetting == AM_HAL_CLKGEN_SYSCLK_48MHZ,
|
||||
"am_hal_clkgen_sysclk_select(): invalid clock setting.");
|
||||
|
||||
//
|
||||
// Unlock the clock control register.
|
||||
//
|
||||
AM_REG(CLKGEN, CLKKEY) = AM_REG_CLKGEN_CLKKEY_KEYVAL;
|
||||
|
||||
//
|
||||
// Set the HFRC divisor to the user-selected value.
|
||||
//
|
||||
AM_REG(CLKGEN, CCTRL) = ui32ClockSetting;
|
||||
|
||||
//
|
||||
// Lock the clock configuration registers.
|
||||
//
|
||||
AM_REG(CLKGEN, CLKKEY) = 0;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Get the current system clock frequency.
|
||||
//!
|
||||
//! This function can be used to determine the frequency of the main system
|
||||
//! clock. The return value is the system clock frequency measured in hertz.
|
||||
//!
|
||||
//! @return System clock frequency in Hz
|
||||
//
|
||||
//*****************************************************************************
|
||||
uint32_t
|
||||
am_hal_clkgen_sysclk_get(void)
|
||||
{
|
||||
uint32_t ui32ClockSetting;
|
||||
|
||||
//
|
||||
// Read the value of the clock divider.
|
||||
//
|
||||
ui32ClockSetting = AM_REG(CLKGEN, CCTRL) & AM_REG_CLKGEN_CCTRL_CORESEL_M;
|
||||
|
||||
switch ( ui32ClockSetting )
|
||||
{
|
||||
case AM_REG_CLKGEN_CCTRL_CORESEL_HFRC:
|
||||
return 48000000;
|
||||
case AM_REG_CLKGEN_CCTRL_CORESEL_HFRC_DIV2:
|
||||
return 24000000;
|
||||
default:
|
||||
return 0xFFFFFFFF;
|
||||
}
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Enable selected CLKGEN Interrupts.
|
||||
//!
|
||||
//! Use this function to enable the interrupts.
|
||||
//!
|
||||
//! @param ui32Interrupt - Use the macro bit fields provided in am_hal_clkgen.h
|
||||
//!
|
||||
//! @return None
|
||||
//
|
||||
//*****************************************************************************
|
||||
void
|
||||
am_hal_clkgen_int_enable(uint32_t ui32Interrupt)
|
||||
{
|
||||
//
|
||||
// Enable the interrupts.
|
||||
//
|
||||
AM_REG(CLKGEN, INTEN) |= ui32Interrupt;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Return enabled CLKGEN Interrupts.
|
||||
//!
|
||||
//! Use this function to get all enabled CLKGEN interrupts.
|
||||
//!
|
||||
//! @return enabled CLKGEN interrupts.
|
||||
//
|
||||
//*****************************************************************************
|
||||
uint32_t
|
||||
am_hal_clkgen_int_enable_get(void)
|
||||
{
|
||||
//
|
||||
// Return the enabled interrupts.
|
||||
//
|
||||
return AM_REG(CLKGEN, INTEN);
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Disable selected CLKGEN Interrupts.
|
||||
//!
|
||||
//! Use this function to disable the CLKGEN interrupts.
|
||||
//!
|
||||
//! @param ui32Interrupt - Use the macro bit fields provided in am_hal_clkgen.h
|
||||
//!
|
||||
//! @return None
|
||||
//
|
||||
//*****************************************************************************
|
||||
void
|
||||
am_hal_clkgen_int_disable(uint32_t ui32Interrupt)
|
||||
{
|
||||
//
|
||||
// Disable the interrupts.
|
||||
//
|
||||
AM_REG(CLKGEN, INTEN) &= ~ui32Interrupt;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Sets the interrupt status.
|
||||
//!
|
||||
//! @param ui32IntFlags interrupts to be enabled.
|
||||
//!
|
||||
//! This function sets the interrupts.
|
||||
//!
|
||||
//! Valid values for ui32IntFlags are:
|
||||
//!
|
||||
//! AM_HAL_CLKGEN_INT_RTC_ALARM
|
||||
//! AM_HAL_CLKGEN_INT_XT_FAIL
|
||||
//! AM_HAL_CLKGEN_INT_AUTOCAL_COMPLETE
|
||||
//! AM_HAL_CLKGEN_INT AUTOCAL_FAIL
|
||||
//!
|
||||
//! @return None.
|
||||
//
|
||||
//*****************************************************************************
|
||||
void
|
||||
am_hal_clkgen_int_set(uint32_t ui32Interrupt)
|
||||
{
|
||||
//
|
||||
// Set the interrupt status.
|
||||
//
|
||||
AM_REG(CLKGEN, INTSET) = ui32Interrupt;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Gets the interrupt configuration.
|
||||
//!
|
||||
//! @param bEnabledOnly - return the status of only the enabled interrupts.
|
||||
//!
|
||||
//! This function gets the currently configured interrupts.
|
||||
//!
|
||||
//! @return the configured interrupts.
|
||||
//!
|
||||
//! Possible values for the return are:
|
||||
//!
|
||||
//! AM_HAL_CLKGEN_INT_RTC_ALARM
|
||||
//! AM_HAL_CLKGEN_INT_XT_FAIL
|
||||
//! AM_HAL_CLKGEN_INT_AUTOCAL_COMPLETE
|
||||
//! AM_HAL_CLKGEN_INT AUTOCAL_FAIL
|
||||
//
|
||||
//*****************************************************************************
|
||||
uint32_t
|
||||
am_hal_clkgen_int_status_get(bool bEnabledOnly)
|
||||
{
|
||||
//
|
||||
// Return the status.
|
||||
//
|
||||
if ( bEnabledOnly )
|
||||
{
|
||||
uint32_t u32RetVal = AM_REG(CLKGEN, INTSTAT);
|
||||
u32RetVal &= AM_REG(CLKGEN, INTEN);
|
||||
return u32RetVal;
|
||||
}
|
||||
else
|
||||
{
|
||||
return AM_REG(CLKGEN, INTSTAT);
|
||||
}
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Clears the interrupts.
|
||||
//!
|
||||
//! @param ui32IntFlags interrupts to be cleared.
|
||||
//!
|
||||
//! This function clears the interrupts.
|
||||
//!
|
||||
//! Valid values for ui32IntFlags are:
|
||||
//!
|
||||
//! AM_HAL_CLKGEN_INT_RTC_ALARM
|
||||
//! AM_HAL_CLKGEN_INT_XT_FAIL
|
||||
//! AM_HAL_CLKGEN_INT_AUTOCAL_COMPLETE
|
||||
//! AM_HAL_CLKGEN_INT AUTOCAL_FAIL
|
||||
//!
|
||||
//! @return None.
|
||||
//
|
||||
//*****************************************************************************
|
||||
void
|
||||
am_hal_clkgen_int_clear(uint32_t ui32Interrupt)
|
||||
{
|
||||
//
|
||||
// Clear the interrupts.
|
||||
//
|
||||
AM_REG(CLKGEN, INTCLR) = ui32Interrupt;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Starts the desired oscillator(s) (OSC).
|
||||
//!
|
||||
//! @param ui32OscFlags oscillator(s) to start.
|
||||
//!
|
||||
//! This function starts the desired oscillator(s) (OSC).
|
||||
//!
|
||||
//! Valid values for ui32OscFlags are:
|
||||
//!
|
||||
//! AM_HAL_CLKGEN_OSC_LFRC
|
||||
//! AM_HAL_CLKGEN_OSC_XT
|
||||
//!
|
||||
//! @return 0 None.
|
||||
//
|
||||
//*****************************************************************************
|
||||
void
|
||||
am_hal_clkgen_osc_start(uint32_t ui32OscFlags)
|
||||
{
|
||||
//
|
||||
// Start the oscillator(s).
|
||||
//
|
||||
AM_REG(CLKGEN, OCTRL) &= ~ui32OscFlags;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Stops the desired oscillator(s) (OSC).
|
||||
//!
|
||||
//! @param ui32OscFlags oscillator(s) to stop.
|
||||
//!
|
||||
//! This function stops the desired oscillator(s) (OSC).
|
||||
//!
|
||||
//! Valid values for ui32OscFlags are:
|
||||
//!
|
||||
//! AM_HAL_CLKGEN_OSC_LFRC
|
||||
//! AM_HAL_CLKGEN_OSC_XT
|
||||
//!
|
||||
//! @return None.
|
||||
//
|
||||
//*****************************************************************************
|
||||
void
|
||||
am_hal_clkgen_osc_stop(uint32_t ui32OscFlags)
|
||||
{
|
||||
//
|
||||
// Stop the oscillator(s).
|
||||
//
|
||||
AM_REG(CLKGEN, OCTRL) |= ui32OscFlags;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Enables the clock out signal.
|
||||
//!
|
||||
//! @param ui32Signal desired location for the clock out signal.
|
||||
//!
|
||||
//! This function enables the clock out signal. See am_hal_clkgen.h for
|
||||
//! available signals.
|
||||
//!
|
||||
//! e.g. AM_HAL_CLKGEN_CLKOUT_CKSEL_HFRC
|
||||
//! AM_HAL_CLKGEN_CLKOUT_CKSEL_HFRC_DIV4
|
||||
//! AM_HAL_CLKGEN_CLKOUT_CKSEL_LFRC
|
||||
//!
|
||||
//! @return None.
|
||||
//
|
||||
//*****************************************************************************
|
||||
void
|
||||
am_hal_clkgen_clkout_enable(uint32_t ui32Signal)
|
||||
{
|
||||
//
|
||||
// Enable the clock out on desired signal.
|
||||
//
|
||||
AM_REG(CLKGEN, CLKOUT) = AM_REG_CLKGEN_CLKOUT_CKEN_M | ui32Signal;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Disables the clock out signal.
|
||||
//!
|
||||
//! This function disables the clock out signal.
|
||||
//!
|
||||
//! @return None.
|
||||
//
|
||||
//*****************************************************************************
|
||||
void
|
||||
am_hal_clkgen_clkout_disable(void)
|
||||
{
|
||||
//
|
||||
// Disable the clock out.
|
||||
//
|
||||
AM_REG(CLKGEN, CLKOUT) = 0;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Enable UART system clock.
|
||||
//!
|
||||
//! This function enables or disables the UART system clock.
|
||||
//!
|
||||
//! @param ui32Module is 0 or 1 for Apollo2.
|
||||
//! @param ui32UartEn is one of the following.
|
||||
//! AM_HAL_CLKGEN_UARTEN_DIS
|
||||
//! AM_HAL_CLKGEN_UARTEN_EN
|
||||
//! AM_HAL_CLKGEN_UARTEN_REDUCE_FREQ
|
||||
//! AM_HAL_CLKGEN_UARTEN_EN_POWER_SAV
|
||||
//!
|
||||
//! @return None.
|
||||
//
|
||||
//*****************************************************************************
|
||||
void
|
||||
am_hal_clkgen_uarten_set(uint32_t ui32Module, uint32_t ui32UartEn)
|
||||
{
|
||||
uint32_t ui32Mask;
|
||||
|
||||
if ( (ui32Module >= AM_REG_UART_NUM_MODULES) ||
|
||||
(ui32UartEn > AM_HAL_CLKGEN_UARTEN_EN_POWER_SAV) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ui32UartEn <<= (ui32Module * AM_HAL_CLKGEN_UARTEN_UARTENn_S(ui32Module));
|
||||
ui32Mask = ~(AM_HAL_CLKGEN_UARTEN_UARTENn_M(ui32Module));
|
||||
|
||||
//
|
||||
// Begin critical section.
|
||||
//
|
||||
AM_CRITICAL_BEGIN_ASM
|
||||
|
||||
//
|
||||
// Set the UART clock
|
||||
//
|
||||
AM_REG(CLKGEN, UARTEN) &= ui32Mask;
|
||||
AM_REG(CLKGEN, UARTEN) |= ui32UartEn;
|
||||
|
||||
//
|
||||
// Begin critical section.
|
||||
//
|
||||
AM_CRITICAL_END_ASM
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Enables HFRC auto-adjustment at the specified interval.
|
||||
//!
|
||||
//! @param ui32Warmup - How long to give the HFRC to stabilize during each
|
||||
//! calibration attempt.
|
||||
//! @param ui32Frequency - How often the auto-adjustment should happen.
|
||||
//!
|
||||
//! This function enables HFRC auto-adjustment from an external crystal
|
||||
//! oscillator even when the crystal is not normally being used.
|
||||
//!
|
||||
//! ui32Warmup should be one of the following values:
|
||||
//!
|
||||
//! AM_REG_CLKGEN_HFADJ_HFWARMUP_1SEC
|
||||
//! AM_REG_CLKGEN_HFADJ_HFWARMUP_2SEC
|
||||
//!
|
||||
//! ui32Frequency should be one of the following values:
|
||||
//!
|
||||
//! AM_REG_CLKGEN_HFADJ_HFADJCK_4SEC
|
||||
//! AM_REG_CLKGEN_HFADJ_HFADJCK_16SEC
|
||||
//! AM_REG_CLKGEN_HFADJ_HFADJCK_32SEC
|
||||
//! AM_REG_CLKGEN_HFADJ_HFADJCK_64SEC
|
||||
//! AM_REG_CLKGEN_HFADJ_HFADJCK_128SEC
|
||||
//! AM_REG_CLKGEN_HFADJ_HFADJCK_256SEC
|
||||
//! AM_REG_CLKGEN_HFADJ_HFADJCK_512SEC
|
||||
//! AM_REG_CLKGEN_HFADJ_HFADJCK_1024SEC
|
||||
//!
|
||||
//! @return None.
|
||||
//
|
||||
//*****************************************************************************
|
||||
void
|
||||
am_hal_clkgen_hfrc_adjust_enable(uint32_t ui32Warmup, uint32_t ui32Frequency)
|
||||
{
|
||||
//
|
||||
// Set the HFRC Auto-adjust register for the user's chosen settings. Assume
|
||||
// that the HFRC should be calibrated to 48 MHz and that the crystal is
|
||||
// running at 32.768 kHz.
|
||||
//
|
||||
AM_REG(CLKGEN, HFADJ) =
|
||||
AM_REG_CLKGEN_HFADJ_HFADJ_GAIN_Gain_of_1_in_2 |
|
||||
ui32Warmup |
|
||||
AM_REG_CLKGEN_HFADJ_HFXTADJ(AM_REG_CLKGEN_HFADJ_HFXTADJ_DEFAULT) |
|
||||
ui32Frequency |
|
||||
AM_REG_CLKGEN_HFADJ_HFADJEN_EN;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Disables HFRC auto-adjustment.
|
||||
//!
|
||||
//! This function disables HFRC auto-adjustment.
|
||||
//!
|
||||
//! @return None.
|
||||
//
|
||||
//*****************************************************************************
|
||||
void
|
||||
am_hal_clkgen_hfrc_adjust_disable(void)
|
||||
{
|
||||
//
|
||||
// Disable the clock out.
|
||||
//
|
||||
AM_REG(CLKGEN, HFADJ) =
|
||||
AM_REG_CLKGEN_HFADJ_HFADJ_GAIN_Gain_of_1_in_2 |
|
||||
AM_REG_CLKGEN_HFADJ_HFWARMUP_1SEC |
|
||||
AM_REG_CLKGEN_HFADJ_HFXTADJ(AM_REG_CLKGEN_HFADJ_HFXTADJ_DEFAULT) |
|
||||
AM_REG_CLKGEN_HFADJ_HFADJCK_4SEC |
|
||||
AM_REG_CLKGEN_HFADJ_HFADJEN_DIS;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// End Doxygen group.
|
||||
//! @}
|
||||
//
|
||||
//*****************************************************************************
|
||||
@@ -0,0 +1,206 @@
|
||||
//*****************************************************************************
|
||||
//
|
||||
// am_hal_clkgen.h
|
||||
//! @file
|
||||
//!
|
||||
//! @brief Functions for accessing and configuring the CLKGEN.
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Copyright (c) 2017, Ambiq Micro
|
||||
// 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.
|
||||
//
|
||||
// This is part of revision 1.2.9 of the AmbiqSuite Development Package.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#ifndef AM_HAL_CLKGEN_H
|
||||
#define AM_HAL_CLKGEN_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @name System Clock max frequency
|
||||
//! @brief Defines the maximum clock frequency for this device.
|
||||
//!
|
||||
//! These macros provide a definition of the maximum clock frequency.
|
||||
//!
|
||||
//! @{
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define AM_HAL_CLKGEN_FREQ_MAX_HZ 48000000
|
||||
#define AM_HAL_CLKGEN_FREQ_MAX_MHZ (AM_HAL_CLKGEN_FREQ_MAX_HZ / 1000000)
|
||||
//! @}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @name System Clock Selection
|
||||
//! @brief Divisor selection for the main system clock.
|
||||
//!
|
||||
//! These macros may be used along with the am_hal_clkgen_sysctl_select()
|
||||
//! function to select the frequency of the main system clock.
|
||||
//!
|
||||
//! @{
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define AM_HAL_CLKGEN_SYSCLK_MAX AM_REG_CLKGEN_CCTRL_CORESEL_HFRC
|
||||
#define AM_HAL_CLKGEN_SYSCLK_48MHZ AM_REG_CLKGEN_CCTRL_CORESEL_HFRC
|
||||
//! @}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @name Interrupt Status Bits
|
||||
//! @brief Interrupt Status Bits for enable/disble use
|
||||
//!
|
||||
//! These macros may be used to set and clear interrupt bits.
|
||||
//! @{
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define AM_HAL_CLKGEN_INT_ALM AM_REG_CLKGEN_INTEN_ALM_M
|
||||
#define AM_HAL_CLKGEN_INT_OF AM_REG_CLKGEN_INTEN_OF_M
|
||||
#define AM_HAL_CLKGEN_INT_ACC AM_REG_CLKGEN_INTEN_ACC_M
|
||||
#define AM_HAL_CLKGEN_INT_ACF AM_REG_CLKGEN_INTEN_ACF_M
|
||||
//! @}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @name OSC Start and Stop
|
||||
//! @brief OSC Start and Stop defines.
|
||||
//!
|
||||
//! OSC Start and Stop defines to be used with \e am_hal_clkgen_osc_x().
|
||||
//! @{
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define AM_HAL_CLKGEN_OSC_LFRC AM_REG_CLKGEN_OCTRL_STOPRC_M
|
||||
#define AM_HAL_CLKGEN_OSC_XT AM_REG_CLKGEN_OCTRL_STOPXT_M
|
||||
//! @}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// OSC Start, Stop, Select defines
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define AM_HAL_CLKGEN_CLKOUT_CKSEL_LFRC AM_REG_CLKGEN_CLKOUT_CKSEL_LFRC
|
||||
#define AM_HAL_CLKGEN_CLKOUT_CKSEL_XT_DIV2 AM_REG_CLKGEN_CLKOUT_CKSEL_XT_DIV2
|
||||
#define AM_HAL_CLKGEN_CLKOUT_CKSEL_XT_DIV4 AM_REG_CLKGEN_CLKOUT_CKSEL_XT_DIV4
|
||||
#define AM_HAL_CLKGEN_CLKOUT_CKSEL_XT_DIV8 AM_REG_CLKGEN_CLKOUT_CKSEL_XT_DIV8
|
||||
#define AM_HAL_CLKGEN_CLKOUT_CKSEL_XT_DIV16 AM_REG_CLKGEN_CLKOUT_CKSEL_XT_DIV16
|
||||
#define AM_HAL_CLKGEN_CLKOUT_CKSEL_XT_DIV32 AM_REG_CLKGEN_CLKOUT_CKSEL_XT_DIV32
|
||||
#define AM_HAL_CLKGEN_CLKOUT_CKSEL_RTC_100Hz AM_REG_CLKGEN_CLKOUT_CKSEL_RTC_100Hz
|
||||
#define AM_HAL_CLKGEN_CLKOUT_CKSEL_XT_DIV2M AM_REG_CLKGEN_CLKOUT_CKSEL_XT_DIV2M
|
||||
#define AM_HAL_CLKGEN_CLKOUT_CKSEL_XT AM_REG_CLKGEN_CLKOUT_CKSEL_XT
|
||||
#define AM_HAL_CLKGEN_CLKOUT_CKSEL_CG_100Hz AM_REG_CLKGEN_CLKOUT_CKSEL_CG_100Hz
|
||||
#define AM_HAL_CLKGEN_CLKOUT_CKSEL_HFRC AM_REG_CLKGEN_CLKOUT_CKSEL_HFRC
|
||||
#define AM_HAL_CLKGEN_CLKOUT_CKSEL_HFRC_DIV4 AM_REG_CLKGEN_CLKOUT_CKSEL_HFRC_DIV4
|
||||
#define AM_HAL_CLKGEN_CLKOUT_CKSEL_HFRC_DIV8 AM_REG_CLKGEN_CLKOUT_CKSEL_HFRC_DIV8
|
||||
#define AM_HAL_CLKGEN_CLKOUT_CKSEL_HFRC_DIV32 AM_REG_CLKGEN_CLKOUT_CKSEL_HFRC_DIV32
|
||||
#define AM_HAL_CLKGEN_CLKOUT_CKSEL_HFRC_DIV64 AM_REG_CLKGEN_CLKOUT_CKSEL_HFRC_DIV64
|
||||
#define AM_HAL_CLKGEN_CLKOUT_CKSEL_HFRC_DIV128 AM_REG_CLKGEN_CLKOUT_CKSEL_HFRC_DIV128
|
||||
#define AM_HAL_CLKGEN_CLKOUT_CKSEL_HFRC_DIV256 AM_REG_CLKGEN_CLKOUT_CKSEL_HFRC_DIV256
|
||||
#define AM_HAL_CLKGEN_CLKOUT_CKSEL_CORE_CLK AM_REG_CLKGEN_CLKOUT_CKSEL_CORE_CLK
|
||||
#define AM_HAL_CLKGEN_CLKOUT_CKSEL_FLASH_CLK AM_REG_CLKGEN_CLKOUT_CKSEL_FLASH_CLK
|
||||
#define AM_HAL_CLKGEN_CLKOUT_CKSEL_LFRC_DIV2 AM_REG_CLKGEN_CLKOUT_CKSEL_LFRC_DIV2
|
||||
#define AM_HAL_CLKGEN_CLKOUT_CKSEL_LFRC_DIV32 AM_REG_CLKGEN_CLKOUT_CKSEL_LFRC_DIV32
|
||||
#define AM_HAL_CLKGEN_CLKOUT_CKSEL_LFRC_DIV512 AM_REG_CLKGEN_CLKOUT_CKSEL_LFRC_DIV512
|
||||
#define AM_HAL_CLKGEN_CLKOUT_CKSEL_LFRC_DIV32K AM_REG_CLKGEN_CLKOUT_CKSEL_LFRC_DIV32K
|
||||
#define AM_HAL_CLKGEN_CLKOUT_CKSEL_XT_DIV256 AM_REG_CLKGEN_CLKOUT_CKSEL_XT_DIV256
|
||||
#define AM_HAL_CLKGEN_CLKOUT_CKSEL_XT_DIV8K AM_REG_CLKGEN_CLKOUT_CKSEL_XT_DIV8K
|
||||
#define AM_HAL_CLKGEN_CLKOUT_CKSEL_XT_DIV64K AM_REG_CLKGEN_CLKOUT_CKSEL_XT_DIV64K
|
||||
#define AM_HAL_CLKGEN_CLKOUT_CKSEL_ULFRC_DIV16 AM_REG_CLKGEN_CLKOUT_CKSEL_ULFRC_DIV16
|
||||
#define AM_HAL_CLKGEN_CLKOUT_CKSEL_ULFRC_DIV128 AM_REG_CLKGEN_CLKOUT_CKSEL_ULFRC_DIV128
|
||||
#define AM_HAL_CLKGEN_CLKOUT_CKSEL_ULFRC_1Hz AM_REG_CLKGEN_CLKOUT_CKSEL_ULFRC_1Hz
|
||||
#define AM_HAL_CLKGEN_CLKOUT_CKSEL_ULFRC_DIV4K AM_REG_CLKGEN_CLKOUT_CKSEL_ULFRC_DIV4K
|
||||
#define AM_HAL_CLKGEN_CLKOUT_CKSEL_ULFRC_DIV1M AM_REG_CLKGEN_CLKOUT_CKSEL_ULFRC_DIV1M
|
||||
#define AM_HAL_CLKGEN_CLKOUT_CKSEL_HFRC_DIV64K AM_REG_CLKGEN_CLKOUT_CKSEL_HFRC_DIV64K
|
||||
#define AM_HAL_CLKGEN_CLKOUT_CKSEL_HFRC_DIV16M AM_REG_CLKGEN_CLKOUT_CKSEL_HFRC_DIV16M
|
||||
#define AM_HAL_CLKGEN_CLKOUT_CKSEL_LFRC_DIV2M AM_REG_CLKGEN_CLKOUT_CKSEL_LFRC_DIV2M
|
||||
#define AM_HAL_CLKGEN_CLKOUT_CKSEL_HFRCNE AM_REG_CLKGEN_CLKOUT_CKSEL_HFRCNE
|
||||
#define AM_HAL_CLKGEN_CLKOUT_CKSEL_HFRCNE_DIV8 AM_REG_CLKGEN_CLKOUT_CKSEL_HFRCNE_DIV8
|
||||
#define AM_HAL_CLKGEN_CLKOUT_CKSEL_CORE_CLKNE AM_REG_CLKGEN_CLKOUT_CKSEL_CORE_CLKNE
|
||||
#define AM_HAL_CLKGEN_CLKOUT_CKSEL_XTNE AM_REG_CLKGEN_CLKOUT_CKSEL_XTNE
|
||||
#define AM_HAL_CLKGEN_CLKOUT_CKSEL_XTNE_DIV16 AM_REG_CLKGEN_CLKOUT_CKSEL_XTNE_DIV16
|
||||
#define AM_HAL_CLKGEN_CLKOUT_CKSEL_LFRCNE_DIV32 AM_REG_CLKGEN_CLKOUT_CKSEL_LFRCNE_DIV32
|
||||
#define AM_HAL_CLKGEN_CLKOUT_CKSEL_FCLKNE AM_REG_CLKGEN_CLKOUT_CKSEL_FCLKNE
|
||||
#define AM_HAL_CLKGEN_CLKOUT_CKSEL_LFRCNE AM_REG_CLKGEN_CLKOUT_CKSEL_LFRCNE
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// UARTEN
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define AM_HAL_CLKGEN_UARTEN_DIS AM_REG_CLKGEN_UARTEN_UART0EN_DIS
|
||||
#define AM_HAL_CLKGEN_UARTEN_EN AM_REG_CLKGEN_UARTEN_UART0EN_EN
|
||||
#define AM_HAL_CLKGEN_UARTEN_REDUCE_FREQ AM_REG_CLKGEN_UARTEN_UART0EN_REDUCE_FREQ
|
||||
#define AM_HAL_CLKGEN_UARTEN_EN_POWER_SAV AM_REG_CLKGEN_UARTEN_UART0EN_EN_POWER_SAV
|
||||
|
||||
#define AM_HAL_CLKGEN_UARTEN_UARTENn_S(module) \
|
||||
((module) * \
|
||||
(AM_REG_CLKGEN_UARTEN_UART1EN_S - AM_REG_CLKGEN_UARTEN_UART0EN_S))
|
||||
|
||||
#define AM_HAL_CLKGEN_UARTEN_UARTENn_M(module) \
|
||||
(AM_REG_CLKGEN_UARTEN_UART0EN_M << AM_HAL_CLKGEN_UARTEN_UARTENn_S(module))
|
||||
|
||||
//
|
||||
// UARTEN: entype is one of DIS, EN, REDUCE_FREQ, EN_POWER_SAV.
|
||||
//
|
||||
#define AM_HAL_CLKGEN_UARTEN_UARTENn(module, entype) \
|
||||
(AM_REG_CLKGEN_UARTEN_UART0EN_##entype << \
|
||||
AM_HAL_CLKGEN_UARTEN_UARTENn_S(module))
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// External function definitions
|
||||
//
|
||||
//*****************************************************************************
|
||||
extern void am_hal_clkgen_sysclk_select(uint32_t ui32ClockSetting);
|
||||
extern uint32_t am_hal_clkgen_sysclk_get(void);
|
||||
extern void am_hal_clkgen_osc_start(uint32_t ui32OscFlags);
|
||||
extern void am_hal_clkgen_osc_stop(uint32_t ui32OscFlags);
|
||||
extern void am_hal_clkgen_clkout_enable(uint32_t ui32Signal);
|
||||
extern void am_hal_clkgen_clkout_disable(void);
|
||||
extern void am_hal_clkgen_uarten_set(uint32_t ui32Module, uint32_t ui32UartEn);
|
||||
extern void am_hal_clkgen_int_enable(uint32_t ui32Interrupt);
|
||||
extern uint32_t am_hal_clkgen_int_enable_get(void);
|
||||
extern void am_hal_clkgen_int_disable(uint32_t ui32Interrupt);
|
||||
extern void am_hal_clkgen_int_clear(uint32_t ui32Interrupt);
|
||||
extern void am_hal_clkgen_int_set(uint32_t ui32Interrupt);
|
||||
extern uint32_t am_hal_clkgen_int_status_get(bool bEnabledOnly);
|
||||
extern void am_hal_clkgen_hfrc_adjust_enable(uint32_t ui32Warmup, uint32_t ui32Frequency);
|
||||
extern void am_hal_clkgen_hfrc_adjust_disable(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // AM_HAL_CLKGEN_H
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,278 @@
|
||||
//*****************************************************************************
|
||||
//
|
||||
// am_hal_ctimer.h
|
||||
//! @file
|
||||
//!
|
||||
//! @brief Functions for accessing and configuring the CTIMER.
|
||||
//!
|
||||
//! @addtogroup ctimer2 Counter/Timer (CTIMER)
|
||||
//! @ingroup apollo2hal
|
||||
//! @{
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Copyright (c) 2017, Ambiq Micro
|
||||
// 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.
|
||||
//
|
||||
// This is part of revision 1.2.9 of the AmbiqSuite Development Package.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#ifndef AM_HAL_CTIMER_H
|
||||
#define AM_HAL_CTIMER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! Number of timers
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define AM_HAL_CTIMER_TIMERS_NUM 4
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! Timer offset value
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define AM_HAL_CTIMER_TIMER_OFFSET (AM_REG_CTIMER_TMR1_O - AM_REG_CTIMER_TMR0_O)
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @name Interrupt Status Bits
|
||||
//! @brief Interrupt Status Bits for enable/disble use
|
||||
//!
|
||||
//! These macros may be used to set and clear interrupt bits
|
||||
//! @{
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define AM_HAL_CTIMER_INT_TIMERA0C0 AM_REG_CTIMER_INTEN_CTMRA0C0INT_M
|
||||
#define AM_HAL_CTIMER_INT_TIMERA0C1 AM_REG_CTIMER_INTEN_CTMRA0C1INT_M
|
||||
#define AM_HAL_CTIMER_INT_TIMERA1C0 AM_REG_CTIMER_INTEN_CTMRA1C0INT_M
|
||||
#define AM_HAL_CTIMER_INT_TIMERA1C1 AM_REG_CTIMER_INTEN_CTMRA1C1INT_M
|
||||
#define AM_HAL_CTIMER_INT_TIMERA2C0 AM_REG_CTIMER_INTEN_CTMRA2C0INT_M
|
||||
#define AM_HAL_CTIMER_INT_TIMERA2C1 AM_REG_CTIMER_INTEN_CTMRA2C1INT_M
|
||||
#define AM_HAL_CTIMER_INT_TIMERA3C0 AM_REG_CTIMER_INTEN_CTMRA3C0INT_M
|
||||
#define AM_HAL_CTIMER_INT_TIMERA3C1 AM_REG_CTIMER_INTEN_CTMRA3C1INT_M
|
||||
|
||||
#define AM_HAL_CTIMER_INT_TIMERB0C0 AM_REG_CTIMER_INTEN_CTMRB0C0INT_M
|
||||
#define AM_HAL_CTIMER_INT_TIMERB0C1 AM_REG_CTIMER_INTEN_CTMRB0C1INT_M
|
||||
#define AM_HAL_CTIMER_INT_TIMERB1C0 AM_REG_CTIMER_INTEN_CTMRB1C0INT_M
|
||||
#define AM_HAL_CTIMER_INT_TIMERB1C1 AM_REG_CTIMER_INTEN_CTMRB1C1INT_M
|
||||
#define AM_HAL_CTIMER_INT_TIMERB2C0 AM_REG_CTIMER_INTEN_CTMRB2C0INT_M
|
||||
#define AM_HAL_CTIMER_INT_TIMERB2C1 AM_REG_CTIMER_INTEN_CTMRB2C1INT_M
|
||||
#define AM_HAL_CTIMER_INT_TIMERB3C0 AM_REG_CTIMER_INTEN_CTMRB3C0INT_M
|
||||
#define AM_HAL_CTIMER_INT_TIMERB3C1 AM_REG_CTIMER_INTEN_CTMRB3C1INT_M
|
||||
|
||||
//
|
||||
// Deprecated, use the newer macros above.
|
||||
//
|
||||
#define AM_HAL_CTIMER_INT_TIMERA0 AM_HAL_CTIMER_INT_TIMERA0C0
|
||||
#define AM_HAL_CTIMER_INT_TIMERB0 AM_HAL_CTIMER_INT_TIMERB0C0
|
||||
#define AM_HAL_CTIMER_INT_TIMERA1 AM_HAL_CTIMER_INT_TIMERA1C0
|
||||
#define AM_HAL_CTIMER_INT_TIMERB1 AM_HAL_CTIMER_INT_TIMERB1C0
|
||||
#define AM_HAL_CTIMER_INT_TIMERA2 AM_HAL_CTIMER_INT_TIMERA2C0
|
||||
#define AM_HAL_CTIMER_INT_TIMERB2 AM_HAL_CTIMER_INT_TIMERB2C0
|
||||
#define AM_HAL_CTIMER_INT_TIMERA3 AM_HAL_CTIMER_INT_TIMERA3C0
|
||||
#define AM_HAL_CTIMER_INT_TIMERB3 AM_HAL_CTIMER_INT_TIMERB3C0
|
||||
//! @}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @name Configuration options
|
||||
//! @brief Configuration options for \e am_hal_ctimer_config_t
|
||||
//!
|
||||
//! These options are to be used with the \e am_hal_ctimer_config_t structure
|
||||
//! used by \e am_hal_ctimer_config
|
||||
//! @{
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define AM_HAL_CTIMER_CLK_PIN AM_REG_CTIMER_CTRL0_TMRA0CLK(0x0)
|
||||
#define AM_HAL_CTIMER_HFRC_12MHZ AM_REG_CTIMER_CTRL0_TMRA0CLK(0x1)
|
||||
#define AM_HAL_CTIMER_HFRC_3MHZ AM_REG_CTIMER_CTRL0_TMRA0CLK(0x2)
|
||||
#define AM_HAL_CTIMER_HFRC_187_5KHZ AM_REG_CTIMER_CTRL0_TMRA0CLK(0x3)
|
||||
#define AM_HAL_CTIMER_HFRC_47KHZ AM_REG_CTIMER_CTRL0_TMRA0CLK(0x4)
|
||||
#define AM_HAL_CTIMER_HFRC_12KHZ AM_REG_CTIMER_CTRL0_TMRA0CLK(0x5)
|
||||
#define AM_HAL_CTIMER_XT_32_768KHZ AM_REG_CTIMER_CTRL0_TMRA0CLK(0x6)
|
||||
#define AM_HAL_CTIMER_XT_16_384KHZ AM_REG_CTIMER_CTRL0_TMRA0CLK(0x7)
|
||||
#define AM_HAL_CTIMER_XT_2_048KHZ AM_REG_CTIMER_CTRL0_TMRA0CLK(0x8)
|
||||
#define AM_HAL_CTIMER_XT_256HZ AM_REG_CTIMER_CTRL0_TMRA0CLK(0x9)
|
||||
#define AM_HAL_CTIMER_LFRC_512HZ AM_REG_CTIMER_CTRL0_TMRA0CLK(0xA)
|
||||
#define AM_HAL_CTIMER_LFRC_32HZ AM_REG_CTIMER_CTRL0_TMRA0CLK(0xB)
|
||||
#define AM_HAL_CTIMER_LFRC_1HZ AM_REG_CTIMER_CTRL0_TMRA0CLK(0xC)
|
||||
#define AM_HAL_CTIMER_LFRC_1_16HZ AM_REG_CTIMER_CTRL0_TMRA0CLK(0xD)
|
||||
#define AM_HAL_CTIMER_RTC_100HZ AM_REG_CTIMER_CTRL0_TMRA0CLK(0xE)
|
||||
#define AM_HAL_CTIMER_HCLK AM_REG_CTIMER_CTRL0_TMRA0CLK(0xF)
|
||||
#define AM_HAL_CTIMER_BUCK AM_REG_CTIMER_CTRL0_TMRA0CLK(0x10)
|
||||
//! @}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Timer function macros.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define AM_HAL_CTIMER_FN_ONCE AM_REG_CTIMER_CTRL0_TMRA0FN(0)
|
||||
#define AM_HAL_CTIMER_FN_REPEAT AM_REG_CTIMER_CTRL0_TMRA0FN(1)
|
||||
#define AM_HAL_CTIMER_FN_PWM_ONCE AM_REG_CTIMER_CTRL0_TMRA0FN(2)
|
||||
#define AM_HAL_CTIMER_FN_PWM_REPEAT AM_REG_CTIMER_CTRL0_TMRA0FN(3)
|
||||
#define AM_HAL_CTIMER_FN_CONTINUOUS AM_REG_CTIMER_CTRL0_TMRA0FN(4)
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Half-timer options.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define AM_HAL_CTIMER_INT_ENABLE AM_REG_CTIMER_CTRL0_TMRA0IE0_M
|
||||
#define AM_HAL_CTIMER_PIN_ENABLE AM_REG_CTIMER_CTRL0_TMRA0PE_M
|
||||
#define AM_HAL_CTIMER_PIN_INVERT AM_REG_CTIMER_CTRL0_TMRA0POL_M
|
||||
#define AM_HAL_CTIMER_CLEAR AM_REG_CTIMER_CTRL0_TMRA0CLR_M
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Additional timer options.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define AM_HAL_CTIMER_LINK AM_REG_CTIMER_CTRL0_CTLINK0_M
|
||||
#define AM_HAL_CTIMER_ADC_TRIG AM_REG_CTIMER_CTRL3_ADCEN_M
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Timer selection macros.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define AM_HAL_CTIMER_TIMERA 0x0000FFFF
|
||||
#define AM_HAL_CTIMER_TIMERB 0xFFFF0000
|
||||
#define AM_HAL_CTIMER_BOTH 0xFFFFFFFF
|
||||
//! @}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Timer configuration structure
|
||||
//
|
||||
//*****************************************************************************
|
||||
typedef struct
|
||||
{
|
||||
//
|
||||
//! Set to 1 to operate this timer as a 32-bit timer instead of two 16-bit
|
||||
//! timers.
|
||||
//
|
||||
uint32_t ui32Link;
|
||||
|
||||
//
|
||||
//! Configuration options for TIMERA
|
||||
//
|
||||
uint32_t ui32TimerAConfig;
|
||||
|
||||
//
|
||||
//! Configuration options for TIMERB
|
||||
//
|
||||
uint32_t ui32TimerBConfig;
|
||||
|
||||
}
|
||||
am_hal_ctimer_config_t;
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Function pointer type for CTimer interrupt handlers.
|
||||
//
|
||||
//*****************************************************************************
|
||||
typedef void (*am_hal_ctimer_handler_t)(void);
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// External function definitions
|
||||
//
|
||||
//*****************************************************************************
|
||||
extern void am_hal_ctimer_config(uint32_t ui32TimerNumber,
|
||||
am_hal_ctimer_config_t *psConfig);
|
||||
|
||||
extern void am_hal_ctimer_config_single(uint32_t ui32TimerNumber,
|
||||
uint32_t ui32TimerSegment,
|
||||
uint32_t ui32ConfigVal);
|
||||
|
||||
extern void am_hal_ctimer_start(uint32_t ui32TimerNumber,
|
||||
uint32_t ui32TimerSegment);
|
||||
|
||||
extern void am_hal_ctimer_stop(uint32_t ui32TimerNumber,
|
||||
uint32_t ui32TimerSegment);
|
||||
|
||||
extern void am_hal_ctimer_clear(uint32_t ui32TimerNumber,
|
||||
uint32_t ui32TimerSegment);
|
||||
|
||||
extern uint32_t am_hal_ctimer_read(uint32_t ui32TimerNumber,
|
||||
uint32_t ui32TimerSegment);
|
||||
|
||||
extern void am_hal_ctimer_pin_enable(uint32_t ui32TimerNumber,
|
||||
uint32_t ui32TimerSegment);
|
||||
|
||||
extern void am_hal_ctimer_pin_disable(uint32_t ui32TimerNumber,
|
||||
uint32_t ui32TimerSegment);
|
||||
|
||||
extern void am_hal_ctimer_pin_invert(uint32_t ui32TimerNumber,
|
||||
uint32_t ui32TimerSegment,
|
||||
bool bInvertOutput);
|
||||
|
||||
extern void am_hal_ctimer_compare_set(uint32_t ui32TimerNumber,
|
||||
uint32_t ui32TimerSegment,
|
||||
uint32_t ui32CompareReg,
|
||||
uint32_t ui32Value);
|
||||
|
||||
extern void am_hal_ctimer_period_set(uint32_t ui32TimerNumber,
|
||||
uint32_t ui32TimerSegment,
|
||||
uint32_t ui32Period,
|
||||
uint32_t ui32OnTime);
|
||||
|
||||
extern void am_hal_ctimer_adc_trigger_enable(void);
|
||||
extern void am_hal_ctimer_adc_trigger_disable(void);
|
||||
extern void am_hal_ctimer_int_enable(uint32_t ui32Interrupt);
|
||||
extern uint32_t am_hal_ctimer_int_enable_get(void);
|
||||
extern void am_hal_ctimer_int_disable(uint32_t ui32Interrupt);
|
||||
extern void am_hal_ctimer_int_set(uint32_t ui32Interrupt);
|
||||
extern void am_hal_ctimer_int_clear(uint32_t ui32Interrupt);
|
||||
extern uint32_t am_hal_ctimer_int_status_get(bool bEnabledOnly);
|
||||
extern void am_hal_ctimer_int_register(uint32_t ui32Interrupt,
|
||||
am_hal_ctimer_handler_t pfnHandler);
|
||||
extern void am_hal_ctimer_int_service(uint32_t ui32Status);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // AM_HAL_CTIMER_H
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// End Doxygen group.
|
||||
//! @}
|
||||
//
|
||||
//*****************************************************************************
|
||||
@@ -0,0 +1,81 @@
|
||||
//*****************************************************************************
|
||||
//
|
||||
// am_hal_debug.c
|
||||
//! @file
|
||||
//!
|
||||
//! @brief Useful functions for debugging.
|
||||
//!
|
||||
//! These functions and macros were created to assist with debugging. They are
|
||||
//! intended to be as unintrusive as possible and designed to be removed from
|
||||
//! the compilation of a project when they are no longer needed.
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Copyright (c) 2017, Ambiq Micro
|
||||
// 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.
|
||||
//
|
||||
// This is part of revision 1.2.9 of the AmbiqSuite Development Package.
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "am_mcu_apollo.h"
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Default implementation of a failed ASSERT statement.
|
||||
//!
|
||||
//! @param pcFile is the name of the source file where the error occurred.
|
||||
//! @param ui32Line is the line number where the error occurred.
|
||||
//! @param pcMessage is an optional message describing the failure.
|
||||
//!
|
||||
//! This function is called by am_hal_debug_assert() macro when the supplied
|
||||
//! condition is not true. The implementation here simply halts the application
|
||||
//! for further analysis. Individual applications may define their own
|
||||
//! implementations of am_hal_debug_error() to provide more detailed feedback
|
||||
//! about the failed am_hal_debug_assert() statement.
|
||||
//!
|
||||
//! @return
|
||||
//
|
||||
//*****************************************************************************
|
||||
#if defined (__IAR_SYSTEMS_ICC__)
|
||||
__weak void
|
||||
#else
|
||||
void __attribute__((weak))
|
||||
#endif
|
||||
am_hal_debug_error(const char *pcFile, uint32_t ui32Line, const char *pcMessage)
|
||||
{
|
||||
//
|
||||
// Halt for analysis.
|
||||
//
|
||||
while(1);
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
//*****************************************************************************
|
||||
//
|
||||
// am_hal_debug.h
|
||||
//! @file
|
||||
//!
|
||||
//! @brief Useful macros for debugging.
|
||||
//!
|
||||
//! These functions and macros were created to assist with debugging. They are
|
||||
//! intended to be as unintrusive as possible and designed to be removed from
|
||||
//! the compilation of a project when they are no longer needed.
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Copyright (c) 2017, Ambiq Micro
|
||||
// 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.
|
||||
//
|
||||
// This is part of revision 1.2.9 of the AmbiqSuite Development Package.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#ifndef AM_HAL_DEBUG_H
|
||||
#define AM_HAL_DEBUG_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Debug assert macros.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#ifndef AM_HAL_DEBUG_NO_ASSERT
|
||||
|
||||
#define am_hal_debug_assert_msg(bCondition, pcMessage) \
|
||||
if ( !(bCondition)) am_hal_debug_error(__FILE__, __LINE__, pcMessage)
|
||||
|
||||
#define am_hal_debug_assert(bCondition) \
|
||||
if ( !(bCondition)) am_hal_debug_error(__FILE__, __LINE__, 0)
|
||||
|
||||
#else
|
||||
|
||||
#define am_hal_debug_assert_msg(bCondition, pcMessage)
|
||||
#define am_hal_debug_assert(bCondition)
|
||||
|
||||
#endif // AM_DEBUG_ASSERT
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// External function prototypes.
|
||||
//
|
||||
//*****************************************************************************
|
||||
extern void am_hal_debug_error(const char *pcFile, uint32_t ui32Line,
|
||||
const char *pcMessage);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // AM_HAL_DEBUG_H
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,297 @@
|
||||
//*****************************************************************************
|
||||
//
|
||||
// am_hal_flash.h
|
||||
//! @file
|
||||
//!
|
||||
//! @brief Functions for performing Flash operations.
|
||||
//!
|
||||
//! @addtogroup flash2 Flash
|
||||
//! @ingroup apollo2hal
|
||||
//! @{
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Copyright (c) 2017, Ambiq Micro
|
||||
// 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.
|
||||
//
|
||||
// This is part of revision 1.2.9 of the AmbiqSuite Development Package.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#ifndef AM_HAL_FLASH_H
|
||||
#define AM_HAL_FLASH_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Flash Program keys.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define AM_HAL_FLASH_PROGRAM_KEY 0x12344321
|
||||
#define AM_HAL_FLASH_RECOVERY_KEY 0xA35C9B6D
|
||||
#define AM_HAL_FLASH_INFO_KEY 0x12344321
|
||||
#define AM_HAL_FLASH_OTP_KEY (AM_HAL_FLASH_INFO_KEY)
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Some helpful flash values and macros.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define AM_HAL_FLASH_ADDR 0x00000000
|
||||
#define AM_HAL_FLASH_PAGE_SIZE ( 8 * 1024 )
|
||||
#define AM_HAL_FLASH_INFO_SIZE AM_HAL_FLASH_PAGE_SIZE
|
||||
#define AM_HAL_FLASH_INSTANCE_SIZE ( 512 * 1024 )
|
||||
#define AM_HAL_FLASH_INSTANCE_PAGES ( AM_HAL_FLASH_INSTANCE_SIZE / AM_HAL_FLASH_PAGE_SIZE )
|
||||
#define AM_HAL_FLASH_TOTAL_SIZE ( AM_HAL_FLASH_INSTANCE_SIZE * 2 )
|
||||
#define AM_HAL_FLASH_LARGEST_VALID_ADDR ( AM_HAL_FLASH_ADDR + AM_HAL_FLASH_TOTAL_SIZE - 1 )
|
||||
|
||||
//
|
||||
// Convert an absolute flash address to a instance
|
||||
//
|
||||
#define AM_HAL_FLASH_ADDR2INST(addr) ( ( addr >> 19 ) & 1 )
|
||||
|
||||
//
|
||||
// Convert an absolute flash address to a page number relative to the instance
|
||||
//
|
||||
#define AM_HAL_FLASH_ADDR2PAGE(addr) ( ( addr >> 13 ) & 0x3F )
|
||||
|
||||
//
|
||||
// Convert an absolute flash address to an absolute page number
|
||||
//
|
||||
#define AM_HAL_FLASH_ADDR2ABSPAGE(addr) ( addr >> 13 )
|
||||
|
||||
//
|
||||
// Given a number of microseconds, convert to a value representing the number of
|
||||
// cycles that will give that delay. This macro is basically taking into account
|
||||
// some of the call overhead.
|
||||
// e.g. To provide a 2us delay:
|
||||
// am_hal_flash_delay( FLASH_CYCLES_US(2) );
|
||||
//
|
||||
#define FLASH_CYCLES_US(n) ((n * (AM_HAL_CLKGEN_FREQ_MAX_MHZ / 3)) - 4)
|
||||
|
||||
//
|
||||
// Backward compatibility
|
||||
//
|
||||
#define am_hal_flash_program_otp am_hal_flash_program_info
|
||||
#define am_hal_flash_program_otp_sram am_hal_flash_program_info_sram
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Structure of function pointers to helper functions for invoking various
|
||||
// flash operations. The functions we are pointing to here are in the Apollo 2
|
||||
// integrated BOOTROM.
|
||||
//
|
||||
//*****************************************************************************
|
||||
typedef struct am_hal_flash_helper_struct
|
||||
{
|
||||
//
|
||||
// The basics.
|
||||
//
|
||||
int (*flash_mass_erase)(uint32_t, uint32_t);
|
||||
int (*flash_page_erase)(uint32_t, uint32_t, uint32_t);
|
||||
int (*flash_program_main)(uint32_t, uint32_t *,
|
||||
uint32_t*, uint32_t);
|
||||
int (*flash_program_info)(uint32_t, uint32_t,
|
||||
uint32_t*, uint32_t, uint32_t);
|
||||
|
||||
//
|
||||
// Non-blocking variants, but be careful these are not interrupt safe so
|
||||
// mask interrupts while these very long operations proceed.
|
||||
//
|
||||
int (*flash_mass_erase_nb)(uint32_t, uint32_t);
|
||||
int (*flash_page_erase_nb)(uint32_t, uint32_t, uint32_t);
|
||||
bool (*flash_nb_operation_complete)(void);
|
||||
|
||||
//
|
||||
// Essentially these are recovery options.
|
||||
//
|
||||
int (*flash_erase_info)(uint32_t, uint32_t);
|
||||
int (*flash_erase_main_plus_info)(uint32_t, uint32_t);
|
||||
int (*flash_erase_main_plus_info_both_instances)(uint32_t);
|
||||
void (*flash_recovery)(uint32_t);
|
||||
|
||||
//
|
||||
// Useful utilities.
|
||||
//
|
||||
uint32_t (*flash_util_read_word)(uint32_t*);
|
||||
void (*flash_util_write_word)(uint32_t*, uint32_t);
|
||||
void (*delay_cycles)(uint32_t);
|
||||
|
||||
//
|
||||
// The following functions pointers will generally never be called from
|
||||
// user programs. They are here primarily to document these entry points
|
||||
// which are usable from a debugger or debugger script.
|
||||
//
|
||||
void (*flash_program_main_sram)(void);
|
||||
void (*flash_program_info_sram)(void);
|
||||
void (*flash_erase_main_pages_sram)(void);
|
||||
void (*flash_mass_erase_sram)(void);
|
||||
void (*flash_erase_info_sram)(void);
|
||||
void (*flash_erase_main_plus_info_sram)(void);
|
||||
} g_am_hal_flash_t;
|
||||
extern g_am_hal_flash_t g_am_hal_flash;
|
||||
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Define some FLASH INFO SPACE values and macros.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define AM_HAL_FLASH_INFO_ADDR 0x50020000
|
||||
#define AM_HAL_FLASH_INFO_SECURITY_O 0x10
|
||||
#define AM_HAL_FLASH_INFO_WRITPROT_O 0x20
|
||||
#define AM_HAL_FLASH_INFO_COPYPROT_O 0x30
|
||||
|
||||
#define AM_HAL_FLASH_INFO_SECURITY_ADDR (AM_HAL_FLASH_INFO_ADDR + AM_HAL_FLASH_INFO_SECURITY_O)
|
||||
#define AM_HAL_FLASH_INFO_WRITPROT_ADDR (AM_HAL_FLASH_INFO_ADDR + AM_HAL_FLASH_INFO_WRITPROT_O)
|
||||
#define AM_HAL_FLASH_INFO_COPYPROT_ADDR (AM_HAL_FLASH_INFO_ADDR + AM_HAL_FLASH_INFO_COPYPROT_O)
|
||||
|
||||
//
|
||||
// Define the customer info signature data (at AM_HAL_FLASH_INFO_ADDR).
|
||||
// These bits must exist in the customer info space in order for many of the
|
||||
// security and protection functions to work.
|
||||
//
|
||||
#define AM_HAL_FLASH_INFO_SIGNATURE0 0x48EAAD88
|
||||
#define AM_HAL_FLASH_INFO_SIGNATURE1 0xC9705737
|
||||
#define AM_HAL_FLASH_INFO_SIGNATURE2 0x0A6B8458
|
||||
#define AM_HAL_FLASH_INFO_SIGNATURE3 0xE41A9D74
|
||||
|
||||
//
|
||||
// Define the customer security bits (at AM_HAL_FLASH_INFO_SECURITY_ADDR)
|
||||
//
|
||||
#define AM_HAL_FLASH_INFO_SECURITY_DEBUGGERPROT_S 0
|
||||
#define AM_HAL_FLASH_INFO_SECURITY_SWOCTRL_S 1
|
||||
#define AM_HAL_FLASH_INFO_SECURITY_SRAMWIPE_S 2
|
||||
#define AM_HAL_FLASH_INFO_SECURITY_FLASHWIPE_S 3
|
||||
#define AM_HAL_FLASH_INFO_SECURITY_ENINFOPRGM_S 4
|
||||
#define AM_HAL_FLASH_INFO_SECURITY_ENINFOERASE_S 8
|
||||
#define AM_HAL_FLASH_INFO_SECURITY_BOOTLOADERSPIN_S 9
|
||||
|
||||
#define AM_HAL_FLASH_INFO_SECURITY_DEBUGGERPROT_M ((uint32_t)(0x1 << AM_HAL_FLASH_INFO_SECURITY_DEBUGGERPROT_S))
|
||||
#define AM_HAL_FLASH_INFO_SECURITY_SWOCTRL_M ((uint32_t)(0x1 << AM_HAL_FLASH_INFO_SECURITY_SWOCTRL_S))
|
||||
#define AM_HAL_FLASH_INFO_SECURITY_SRAMWIPE_M ((uint32_t)(0x1 << AM_HAL_FLASH_INFO_SECURITY_SRAMWIPE_S))
|
||||
#define AM_HAL_FLASH_INFO_SECURITY_FLASHWIPE_M ((uint32_t)(0x1 << AM_HAL_FLASH_INFO_SECURITY_FLASHWIPE_S))
|
||||
#define AM_HAL_FLASH_INFO_SECURITY_ENINFOPRGM_M ((uint32_t)(0xF << AM_HAL_FLASH_INFO_SECURITY_ENINFOPRGM_S))
|
||||
#define AM_HAL_FLASH_INFO_SECURITY_ENINFOERASE_M ((uint32_t)(0x1 << AM_HAL_FLASH_INFO_SECURITY_ENINFOERASE_S))
|
||||
#define AM_HAL_FLASH_INFO_SECURITY_BOOTLOADERSPIN_M ((uint32_t)(0x1 << AM_HAL_FLASH_INFO_SECURITY_BOOTLOADERSPIN_S))
|
||||
#define AM_HAL_FLASH_INFO_SECURITY_DEEPSLEEP_M ((uint32_t)(0x1 << AM_HAL_FLASH_INFO_SECURITY_BOOTLOADERSPIN_S))
|
||||
#define AM_HAL_FLASH_INFO_SECURITY_DEEPSLEEP ((uint32_t)(0x0 << AM_HAL_FLASH_INFO_SECURITY_BOOTLOADERSPIN_S))
|
||||
|
||||
//
|
||||
// Protection chunk macros
|
||||
// AM_HAL_FLASH_INFO_CHUNK2ADDR: Convert a chunk number to an address
|
||||
// AM_HAL_FLASH_INFO_CHUNK2INST: Convert a chunk number to an instance number
|
||||
// AM_HAL_FLASH_INFO_ADDR2CHUNK: Convert an address to a chunk number
|
||||
//
|
||||
#define AM_HAL_FLASH_INFO_CHUNKSIZE (16*1024)
|
||||
|
||||
#define AM_HAL_FLASH_INFO_CHUNK2ADDR(n) (AM_HAL_FLASH_ADDR + (n << 14))
|
||||
#define AM_HAL_FLASH_INFO_CHUNK2INST(n) ((n >> 5) & 1
|
||||
#define AM_HAL_FLASH_INFO_ADDR2CHUNK(n) ((n) >> 14)
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Function prototypes for the helper functions
|
||||
//
|
||||
//*****************************************************************************
|
||||
extern int am_hal_flash_mass_erase(uint32_t ui32Value, uint32_t ui32FlashInst);
|
||||
extern int am_hal_flash_page_erase(uint32_t ui32Value, uint32_t ui32FlashInst,
|
||||
uint32_t ui32PageNum);
|
||||
extern int am_hal_flash_program_main(uint32_t value, uint32_t *pSrc,
|
||||
uint32_t *pDst, uint32_t NumberOfWords);
|
||||
extern int am_hal_flash_program_info(uint32_t ui32Value, uint32_t ui32InfoInst,
|
||||
uint32_t *pui32Src, uint32_t ui32Offset,
|
||||
uint32_t ui32NumWords);
|
||||
|
||||
//
|
||||
// Recovery type functions for Customer INFO space.
|
||||
//
|
||||
extern int am_hal_flash_erase_info(uint32_t ui32ProgramKey,
|
||||
uint32_t ui32Instance);
|
||||
extern int am_hal_flash_erase_main_plus_info(uint32_t ui32ProgramKey,
|
||||
uint32_t ui32Instance);
|
||||
extern int am_hal_flash_erase_main_plus_info_both_instances(
|
||||
uint32_t ui32ProgramKey);
|
||||
extern void am_hal_flash_recovery(uint32_t ui32RecoveryKey);
|
||||
|
||||
//
|
||||
// BOOTROM resident reader, writer and delay utility functions.
|
||||
//
|
||||
extern uint32_t am_hal_flash_load_ui32(uint32_t ui32Address);
|
||||
extern void am_hal_flash_store_ui32(uint32_t ui32Address, uint32_t ui32Data);
|
||||
extern void am_hal_flash_delay(uint32_t ui32Iterations);
|
||||
|
||||
//
|
||||
// These functions update security/protection bits in the customer INFO blOCK.
|
||||
//
|
||||
extern bool am_hal_flash_customer_info_signature_check(void);
|
||||
extern bool am_hal_flash_info_signature_set(void);
|
||||
extern int32_t am_hal_flash_info_erase_disable(void);
|
||||
extern bool am_hal_flash_info_erase_disable_check(void);
|
||||
extern int32_t am_hal_flash_info_program_disable(uint32_t ui32Mask);
|
||||
extern uint32_t am_hal_flash_info_program_disable_get(void);
|
||||
extern int32_t am_hal_flash_wipe_flash_enable(void);
|
||||
extern bool am_hal_flash_wipe_flash_enable_check(void);
|
||||
extern int32_t am_hal_flash_wipe_sram_enable(void);
|
||||
extern bool am_hal_flash_wipe_sram_enable_check(void);
|
||||
extern int32_t am_hal_flash_swo_disable(void);
|
||||
extern bool am_hal_flash_swo_disable_check(void);
|
||||
extern int32_t am_hal_flash_debugger_disable(void);
|
||||
extern bool am_hal_flash_debugger_disable_check(void);
|
||||
|
||||
extern int32_t am_hal_flash_copy_protect_set(uint32_t *pui32StartAddress,
|
||||
uint32_t *pui32StopAddress);
|
||||
extern bool am_hal_flash_copy_protect_check(uint32_t *pui32StartAddress,
|
||||
uint32_t *pui32StopAddress);
|
||||
extern int32_t am_hal_flash_write_protect_set(uint32_t *pui32StartAddress,
|
||||
uint32_t *pui32StopAddress);
|
||||
extern bool am_hal_flash_write_protect_check(uint32_t *pui32StartAddress,
|
||||
uint32_t *pui32StopAddress);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // AM_HAL_FLASH_H
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// End Doxygen group.
|
||||
//! @}
|
||||
//
|
||||
//*****************************************************************************
|
||||
@@ -0,0 +1,59 @@
|
||||
//*****************************************************************************
|
||||
//
|
||||
// am_hal_global.c
|
||||
//! @file
|
||||
//!
|
||||
//! @brief Locate global variables here.
|
||||
//!
|
||||
//! This module contains global variables that are used throughout the HAL.
|
||||
//!
|
||||
//! One use in particular is that it uses a global HAL flags variable that
|
||||
//! contains flags used in various parts of the HAL.
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Copyright (c) 2017, Ambiq Micro
|
||||
// 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.
|
||||
//
|
||||
// This is part of revision 1.2.9 of the AmbiqSuite Development Package.
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "am_mcu_apollo.h"
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Global Variables
|
||||
//
|
||||
//*****************************************************************************
|
||||
uint32_t volatile g_ui32HALflags = 0x00000000;
|
||||
@@ -0,0 +1,114 @@
|
||||
//*****************************************************************************
|
||||
//
|
||||
// am_hal_global.h
|
||||
//! @file
|
||||
//!
|
||||
//! @brief Locate all HAL global variables here.
|
||||
//!
|
||||
//! This module contains global variables that are used throughout the HAL,
|
||||
//! but not necessarily those designated as const (which typically end up in
|
||||
//! flash). Consolidating globals here will make it easier to manage them.
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Copyright (c) 2017, Ambiq Micro
|
||||
// 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.
|
||||
//
|
||||
// This is part of revision 1.2.9 of the AmbiqSuite Development Package.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#ifndef AM_HAL_GLOBAL_H
|
||||
#define AM_HAL_GLOBAL_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Macro definitions
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
//******************************************************************************
|
||||
//
|
||||
// Macros used to access the bit fields in the flags variable.
|
||||
//
|
||||
//******************************************************************************
|
||||
#define AM_HAL_FLAGS_BFR(flagnm) \
|
||||
((g_ui32HALflags & AM_HAL_FLAGS_##flagnm##_M) >> AM_HAL_FLAGS_##flagnm##_S)
|
||||
|
||||
#define AM_HAL_FLAGS_BFW(flagnm, value) \
|
||||
g_ui32HALflags = ((g_ui32HALflags & (~(AM_HAL_FLAGS_##flagnm##_M))) | \
|
||||
((value << AM_HAL_FLAGS_##flagnm##_S) & (AM_HAL_FLAGS_##flagnm##_M)) )
|
||||
|
||||
//******************************************************************************
|
||||
//
|
||||
// ITMSKIPENABLEDISABLE - Set when the ITM is not to be disabled. This is
|
||||
// typically needed by Keil debug.ini.
|
||||
//
|
||||
//******************************************************************************
|
||||
#define AM_HAL_FLAGS_ITMSKIPENABLEDISABLE_S 0
|
||||
#define AM_HAL_FLAGS_ITMSKIPENABLEDISABLE_M (1 << AM_HAL_FLAGS_ITMSKIPENABLEDISABLE_S)
|
||||
#define AM_HAL_FLAGS_ITMSKIPENABLEDISABLE(n) (((n) << AM_HAL_FLAGS_ITMSKIPENABLEDISABLE_S) & AM_HAL_FLAGS_ITMSKIPENABLEDISABLE_M)
|
||||
|
||||
//******************************************************************************
|
||||
//
|
||||
// ITMBKPT - Breakpoint at the end of itm_enable(), which is needed by
|
||||
// Keil debug.ini.
|
||||
//
|
||||
//******************************************************************************
|
||||
#define AM_HAL_FLAGS_ITMBKPT_S 1
|
||||
#define AM_HAL_FLAGS_ITMBKPT_M (1 << AM_HAL_FLAGS_ITMBKPT_S)
|
||||
#define AM_HAL_FLAGS_ITMBKPT(n) (((n) << AM_HAL_FLAGS_ITMBKPT_S) & AM_HAL_FLAGS_ITMBKPT_M)
|
||||
|
||||
//******************************************************************************
|
||||
//
|
||||
// Next available flag or bit field.
|
||||
//
|
||||
//******************************************************************************
|
||||
#define AM_HAL_FLAGS_NEXTBITFIELD_S 2
|
||||
#define AM_HAL_FLAGS_NEXTBITFIELD_M (1 << AM_HAL_FLAGS_NEXTBITFIELD_S)
|
||||
#define AM_HAL_FLAGS_NEXTBITFIELD(n) (((n) << AM_HAL_FLAGS_NEXTBITFIELD_S) & AM_HAL_FLAGS_NEXTBITFIELD_M)
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Global Variables extern declarations.
|
||||
//
|
||||
//*****************************************************************************
|
||||
extern volatile uint32_t g_ui32HALflags;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // AM_HAL_GLOBAL_H
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,100 @@
|
||||
//*****************************************************************************
|
||||
//
|
||||
// am_hal_i2c_bit_bang.h
|
||||
//! @file
|
||||
//!
|
||||
//! @brief I2C bit bang module.
|
||||
//!
|
||||
//! These functions implement the I2C bit bang utility
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Copyright (c) 2017, Ambiq Micro
|
||||
// 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.
|
||||
//
|
||||
// This is part of revision 1.2.9 of the AmbiqSuite Development Package.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#ifndef AM_HAL_I2C_BIT_BANG_H
|
||||
#define AM_HAL_I2C_BIT_BANG_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Enumerated return constants
|
||||
//
|
||||
//*****************************************************************************
|
||||
typedef enum
|
||||
{
|
||||
AM_HAL_I2C_BIT_BANG_SUCCESS = 0,
|
||||
AM_HAL_I2C_BIT_BANG_ADDRESS_NAKED,
|
||||
AM_HAL_I2C_BIT_BANG_DATA_NAKED,
|
||||
AM_HAL_I2C_BIT_BANG_CLOCK_TIMEOUT,
|
||||
AM_HAL_I2C_BIT_BANG_DATA_TIMEOUT,
|
||||
}am_hal_i2c_bit_bang_enum_t;
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// External function definitions
|
||||
//
|
||||
//*****************************************************************************
|
||||
extern am_hal_i2c_bit_bang_enum_t am_hal_i2c_bit_bang_init(uint32_t sck_gpio_number,
|
||||
uint32_t sda_gpio_number);
|
||||
|
||||
extern am_hal_i2c_bit_bang_enum_t am_hal_i2c_bit_bang_send(uint8_t address,
|
||||
uint32_t number_of_bytes,
|
||||
uint8_t *pData,
|
||||
uint8_t ui8Offset,
|
||||
bool bUseOffset,
|
||||
bool bNoStop);
|
||||
|
||||
extern am_hal_i2c_bit_bang_enum_t am_hal_i2c_bit_bang_receive(uint8_t address,
|
||||
uint32_t number_of_bytes,
|
||||
uint8_t *pData,
|
||||
uint8_t ui8Offset,
|
||||
bool bUseOffset,
|
||||
bool bNoStop);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif //AM_HAL_I2C_BIT_BANG_H
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// End Doxygen group.
|
||||
//! @}
|
||||
//
|
||||
//*****************************************************************************
|
||||
@@ -0,0 +1,407 @@
|
||||
//*****************************************************************************
|
||||
//
|
||||
// am_hal_interrupt.c
|
||||
//! @file
|
||||
//!
|
||||
//! @brief Helper functions supporting interrupts and NVIC operation.
|
||||
//!
|
||||
//! These functions may be used for NVIC-level interrupt configuration.
|
||||
//!
|
||||
//! @addtogroup interrupt2 Interrupt (ARM NVIC support functions)
|
||||
//! @ingroup apollo2hal
|
||||
//! @{
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Copyright (c) 2017, Ambiq Micro
|
||||
// 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.
|
||||
//
|
||||
// This is part of revision 1.2.9 of the AmbiqSuite Development Package.
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "am_mcu_apollo.h"
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Enable an interrupt.
|
||||
//!
|
||||
//! @param ui32Interrupt The ISR number of the interrupt to be enabled.
|
||||
//!
|
||||
//! This function enables an interrupt signal to the NVIC based on the provided
|
||||
//! ISR number.
|
||||
//!
|
||||
//! @return None
|
||||
//
|
||||
//*****************************************************************************
|
||||
void
|
||||
am_hal_interrupt_enable(uint32_t ui32Interrupt)
|
||||
{
|
||||
//
|
||||
// Check to see what type of interrupt this is.
|
||||
//
|
||||
if ( ui32Interrupt > 15 )
|
||||
{
|
||||
//
|
||||
// If this ISR number corresponds to a "normal" peripheral interrupt,
|
||||
// enable it using the NVIC register.
|
||||
//
|
||||
AM_REG(NVIC, ISER0) = 0x1 << ((ui32Interrupt - 16) & 0x1F);
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// If this is an ARM internal interrupt number, route it to the
|
||||
// appropriate enable register.
|
||||
//
|
||||
switch(ui32Interrupt)
|
||||
{
|
||||
case AM_HAL_INTERRUPT_BUSFAULT:
|
||||
AM_BFW(SYSCTRL, SHCSR, BUSFAULTENA, 1);
|
||||
break;
|
||||
|
||||
case AM_HAL_INTERRUPT_USAGEFAULT:
|
||||
AM_BFW(SYSCTRL, SHCSR, USAGEFAULTENA, 1);
|
||||
break;
|
||||
|
||||
case AM_HAL_INTERRUPT_MPUFAULT:
|
||||
AM_BFW(SYSCTRL, SHCSR, MEMFAULTENA, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Disable an interrupt.
|
||||
//!
|
||||
//! @param ui32Interrupt The ISR number of the interrupt to be disabled.
|
||||
//!
|
||||
//! This function disables an interrupt signal to the NVIC based on the
|
||||
//! provided ISR number.
|
||||
//!
|
||||
//! @return None
|
||||
//
|
||||
//*****************************************************************************
|
||||
void
|
||||
am_hal_interrupt_disable(uint32_t ui32Interrupt)
|
||||
{
|
||||
//
|
||||
// Check to see what type of interrupt this is.
|
||||
//
|
||||
if ( ui32Interrupt > 15 )
|
||||
{
|
||||
//
|
||||
// If this ISR number corresponds to a "normal" peripheral interrupt,
|
||||
// disable it using the NVIC register.
|
||||
//
|
||||
AM_REG(NVIC, ICER0) = 0x1 << ((ui32Interrupt - 16) & 0x1F);
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// If this is an ARM internal interrupt number, route it to the
|
||||
// appropriate enable register.
|
||||
//
|
||||
switch(ui32Interrupt)
|
||||
{
|
||||
case AM_HAL_INTERRUPT_BUSFAULT:
|
||||
AM_BFW(SYSCTRL, SHCSR, BUSFAULTENA, 0);
|
||||
break;
|
||||
|
||||
case AM_HAL_INTERRUPT_USAGEFAULT:
|
||||
AM_BFW(SYSCTRL, SHCSR, USAGEFAULTENA, 0);
|
||||
break;
|
||||
|
||||
case AM_HAL_INTERRUPT_MPUFAULT:
|
||||
AM_BFW(SYSCTRL, SHCSR, MEMFAULTENA, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Set the priority of an interrupt vector.
|
||||
//!
|
||||
//! @param ui32Interrupt is the ISR number of the interrupt to change.
|
||||
//! @param ui32Priority is the new ISR priority value.
|
||||
//!
|
||||
//! This function changes the priority value in the NVIC for the given
|
||||
//! interrupt vector number.
|
||||
//!
|
||||
//! @return None
|
||||
//
|
||||
//*****************************************************************************
|
||||
void
|
||||
am_hal_interrupt_priority_set(uint32_t ui32Interrupt, uint32_t ui32Priority)
|
||||
{
|
||||
volatile uint32_t *pui32PriorityReg;
|
||||
volatile uint32_t ui32OldPriority;
|
||||
uint32_t ui32Shift;
|
||||
|
||||
//
|
||||
// Find the correct priority register.
|
||||
//
|
||||
pui32PriorityReg = (volatile uint32_t *) AM_REG_NVIC_IPR0_O;
|
||||
pui32PriorityReg += ((ui32Interrupt - 16) >> 2);
|
||||
|
||||
//
|
||||
// Find the correct shift value.
|
||||
//
|
||||
ui32Shift = (((ui32Interrupt - 16) & 0x3) * 8);
|
||||
|
||||
//
|
||||
// Mask out the old priority.
|
||||
//
|
||||
ui32OldPriority = *pui32PriorityReg;
|
||||
ui32OldPriority &= ~(0xFF << ui32Shift);
|
||||
|
||||
//
|
||||
// OR in the new priority.
|
||||
//
|
||||
*pui32PriorityReg |= (ui32Priority << ui32Shift);
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Set a pending interrupt bit in the NVIC (Software Interrupt)
|
||||
//!
|
||||
//! @param ui32Interrupt is the ISR number of the interrupt to change.
|
||||
//!
|
||||
//! This function sets the specified bit in the Interrupt Set Pending (ISPR0)
|
||||
//! register. For future MCUs there may be more than one ISPR.
|
||||
//!
|
||||
//! @return None
|
||||
//
|
||||
//*****************************************************************************
|
||||
void am_hal_interrupt_pend_set(uint32_t ui32Interrupt)
|
||||
{
|
||||
//
|
||||
// Check to see if the specified interrupt is valid for this MCU
|
||||
//
|
||||
if ( ui32Interrupt > 47 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Check to see what type of interrupt this is.
|
||||
//
|
||||
if ( ui32Interrupt > 15 )
|
||||
{
|
||||
//
|
||||
// If this ISR number corresponds to a "normal" peripheral interrupt,
|
||||
// disable it using the NVIC register.
|
||||
//
|
||||
AM_REG(NVIC, ISPR0) = 0x1 << ((ui32Interrupt - 16) & 0x1F);
|
||||
}
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Clear a pending interrupt bit in the NVIC without servicing it
|
||||
//!
|
||||
//! @param ui32Interrupt is the ISR number of the interrupt to change.
|
||||
//!
|
||||
//! This function clears the specified bit in the Interrupt Clear Pending
|
||||
//! (ICPR0) register. For future MCUs there may be more than one ICPR. This
|
||||
//! function is useful immediately following a WFI before interrupts are
|
||||
//! re-enabled.
|
||||
//!
|
||||
//! @return None
|
||||
//
|
||||
//*****************************************************************************
|
||||
void am_hal_interrupt_pend_clear(uint32_t ui32Interrupt)
|
||||
{
|
||||
//
|
||||
// Check to see if the specified interrupt is valid for this MCU
|
||||
//
|
||||
if ( ui32Interrupt > 47 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Check to see what type of interrupt this is.
|
||||
//
|
||||
if ( ui32Interrupt > 15 )
|
||||
{
|
||||
//
|
||||
// If this ISR number corresponds to a "normal" peripheral interrupt,
|
||||
// disable it using the NVIC register.
|
||||
//
|
||||
AM_REG(NVIC, ICPR0) = 0x1 << ((ui32Interrupt - 16) & 0x1F);
|
||||
}
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Globally enable interrupt service routines
|
||||
//!
|
||||
//! This function allows interrupt signals from the NVIC to trigger ISR entry
|
||||
//! in the CPU. This function must be called if interrupts are to be serviced
|
||||
//! in software.
|
||||
//!
|
||||
//! @return 1 if interrupts were previously disabled, 0 otherwise.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#if defined(__GNUC_STDC_INLINE__)
|
||||
uint32_t __attribute__((naked))
|
||||
am_hal_interrupt_master_enable(void)
|
||||
{
|
||||
__asm(" mrs r0, PRIMASK");
|
||||
__asm(" cpsie i");
|
||||
__asm(" bx lr");
|
||||
}
|
||||
#elif defined(__ARMCC_VERSION)
|
||||
__asm uint32_t
|
||||
am_hal_interrupt_master_enable(void)
|
||||
{
|
||||
mrs r0, PRIMASK
|
||||
cpsie i
|
||||
bx lr
|
||||
}
|
||||
#elif defined(__IAR_SYSTEMS_ICC__)
|
||||
#pragma diag_suppress = Pe940 // Suppress IAR compiler warning about missing
|
||||
// return statement on a non-void function
|
||||
__stackless uint32_t
|
||||
am_hal_interrupt_master_enable(void)
|
||||
{
|
||||
__asm(" mrs r0, PRIMASK");
|
||||
__asm(" cpsie i");
|
||||
__asm(" bx lr");
|
||||
}
|
||||
#pragma diag_default = Pe940 // Restore IAR compiler warning
|
||||
#endif
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Globally disable interrupt service routines
|
||||
//!
|
||||
//! This function prevents interrupt signals from the NVIC from triggering ISR
|
||||
//! entry in the CPU. This will effectively stop incoming interrupt sources
|
||||
//! from triggering their corresponding ISRs.
|
||||
//!
|
||||
//! @note Any external interrupt signal that occurs while the master interrupt
|
||||
//! disable is active will still reach the "pending" state in the NVIC, but it
|
||||
//! will not be allowed to reach the "active" state or trigger the
|
||||
//! corresponding ISR. Instead, these interrupts are essentially "queued" until
|
||||
//! the next time the master interrupt enable instruction is executed. At that
|
||||
//! time, the interrupt handlers will be executed in order of decreasing
|
||||
//! priority.
|
||||
//!
|
||||
//! @return 1 if interrupts were previously disabled, 0 otherwise.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#if defined(__GNUC_STDC_INLINE__)
|
||||
uint32_t __attribute__((naked))
|
||||
am_hal_interrupt_master_disable(void)
|
||||
{
|
||||
__asm(" mrs r0, PRIMASK");
|
||||
__asm(" cpsid i");
|
||||
__asm(" bx lr");
|
||||
}
|
||||
#elif defined(__ARMCC_VERSION)
|
||||
__asm uint32_t
|
||||
am_hal_interrupt_master_disable(void)
|
||||
{
|
||||
mrs r0, PRIMASK
|
||||
cpsid i
|
||||
bx lr
|
||||
}
|
||||
#elif defined(__IAR_SYSTEMS_ICC__)
|
||||
#pragma diag_suppress = Pe940 // Suppress IAR compiler warning about missing
|
||||
// return statement on a non-void function
|
||||
__stackless uint32_t
|
||||
am_hal_interrupt_master_disable(void)
|
||||
{
|
||||
__asm(" mrs r0, PRIMASK");
|
||||
__asm(" cpsid i");
|
||||
__asm(" bx lr");
|
||||
}
|
||||
#pragma diag_default = Pe940 // Restore IAR compiler warning
|
||||
#endif
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Sets the master interrupt state based on the input.
|
||||
//!
|
||||
//! @param ui32InterruptState - Desired PRIMASK value.
|
||||
//!
|
||||
//! This function directly writes the PRIMASK register in the ARM core. A value
|
||||
//! of 1 will disable interrupts, while a value of zero will enable them.
|
||||
//!
|
||||
//! This function may be used along with am_hal_interrupt_master_disable() to
|
||||
//! implement a nesting critical section. To do this, call
|
||||
//! am_hal_interrupt_master_disable() to start the critical section, and save
|
||||
//! its return value. To complete the critical section, call
|
||||
//! am_hal_interrupt_master_set() using the saved return value as \e
|
||||
//! ui32InterruptState. This will safely restore PRIMASK to the value it
|
||||
//! contained just before the start of the critical section.
|
||||
//!
|
||||
//! @return None.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#if defined(__GNUC_STDC_INLINE__)
|
||||
void __attribute__((naked))
|
||||
am_hal_interrupt_master_set(uint32_t ui32InterruptState)
|
||||
{
|
||||
__asm(" msr PRIMASK, r0");
|
||||
__asm(" bx lr");
|
||||
}
|
||||
#elif defined(__ARMCC_VERSION)
|
||||
__asm void
|
||||
am_hal_interrupt_master_set(uint32_t ui32InterruptState)
|
||||
{
|
||||
msr PRIMASK, r0
|
||||
bx lr
|
||||
}
|
||||
#elif defined(__IAR_SYSTEMS_ICC__)
|
||||
#pragma diag_suppress = Pe940 // Suppress IAR compiler warning about missing
|
||||
// return statement on a non-void function
|
||||
__stackless void
|
||||
am_hal_interrupt_master_set(uint32_t ui32InterruptState)
|
||||
{
|
||||
__asm(" msr PRIMASK, r0");
|
||||
__asm(" bx lr");
|
||||
}
|
||||
#pragma diag_default = Pe940 // Restore IAR compiler warning
|
||||
#endif
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// End Doxygen group.
|
||||
//! @}
|
||||
//
|
||||
//*****************************************************************************
|
||||
@@ -0,0 +1,159 @@
|
||||
//*****************************************************************************
|
||||
//
|
||||
// am_hal_interrupt.h
|
||||
//! @file
|
||||
//!
|
||||
//! @brief Helper functions supporting interrupts and NVIC operation.
|
||||
//!
|
||||
//! These functions may be used for NVIC-level interrupt configuration.
|
||||
//!
|
||||
//! @addtogroup interrupt2 Interrupt (ARM NVIC support functions)
|
||||
//! @ingroup apollo2hal
|
||||
//! @{
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Copyright (c) 2017, Ambiq Micro
|
||||
// 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.
|
||||
//
|
||||
// This is part of revision 1.2.9 of the AmbiqSuite Development Package.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#ifndef AM_HAL_INTERRUPT_H
|
||||
#define AM_HAL_INTERRUPT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @name ISR number macros.
|
||||
//! @brief ISR macros.
|
||||
//!
|
||||
//! These macros are used for all ui32Interrupt arguments in this module.
|
||||
//! @{
|
||||
//
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Hardware interrupts
|
||||
//
|
||||
#define AM_HAL_INTERRUPT_RESET 1
|
||||
#define AM_HAL_INTERRUPT_NMI 2
|
||||
#define AM_HAL_INTERRUPT_HARDFAULT 3
|
||||
#define AM_HAL_INTERRUPT_MPUFAULT 4
|
||||
#define AM_HAL_INTERRUPT_BUSFAULT 5
|
||||
#define AM_HAL_INTERRUPT_USAGEFAULT 6
|
||||
|
||||
#define AM_HAL_INTERRUPT_SVCALL 11
|
||||
#define AM_HAL_INTERRUPT_DEBUGMON 12
|
||||
#define AM_HAL_INTERRUPT_PENDSV 14
|
||||
#define AM_HAL_INTERRUPT_SYSTICK 15
|
||||
|
||||
//
|
||||
// Begin IRQs
|
||||
//
|
||||
#define AM_HAL_INTERRUPT_BROWNOUT 16
|
||||
#define AM_HAL_INTERRUPT_WATCHDOG 17
|
||||
#define AM_HAL_INTERRUPT_CLKGEN 18
|
||||
#define AM_HAL_INTERRUPT_VCOMP 19
|
||||
#define AM_HAL_INTERRUPT_IOSLAVE 20
|
||||
#define AM_HAL_INTERRUPT_IOSACC 21
|
||||
#define AM_HAL_INTERRUPT_IOMASTER0 22
|
||||
#define AM_HAL_INTERRUPT_IOMASTER1 23
|
||||
#define AM_HAL_INTERRUPT_IOMASTER2 24
|
||||
#define AM_HAL_INTERRUPT_IOMASTER3 25
|
||||
#define AM_HAL_INTERRUPT_IOMASTER4 26
|
||||
#define AM_HAL_INTERRUPT_IOMASTER5 27
|
||||
#define AM_HAL_INTERRUPT_GPIO 28
|
||||
#define AM_HAL_INTERRUPT_CTIMER 29
|
||||
#define AM_HAL_INTERRUPT_UART0 30
|
||||
#define AM_HAL_INTERRUPT_UART1 31
|
||||
#define AM_HAL_INTERRUPT_UART (AM_HAL_INTERRUPT_UART0)
|
||||
#define AM_HAL_INTERRUPT_ADC 32
|
||||
#define AM_HAL_INTERRUPT_PDM 33
|
||||
#define AM_HAL_INTERRUPT_STIMER 34
|
||||
#define AM_HAL_INTERRUPT_STIMER_CMPR0 35
|
||||
#define AM_HAL_INTERRUPT_STIMER_CMPR1 36
|
||||
#define AM_HAL_INTERRUPT_STIMER_CMPR2 37
|
||||
#define AM_HAL_INTERRUPT_STIMER_CMPR3 38
|
||||
#define AM_HAL_INTERRUPT_STIMER_CMPR4 39
|
||||
#define AM_HAL_INTERRUPT_STIMER_CMPR5 40
|
||||
#define AM_HAL_INTERRUPT_STIMER_CMPR6 41
|
||||
#define AM_HAL_INTERRUPT_STIMER_CMPR7 42
|
||||
#define AM_HAL_INTERRUPT_FLASH 43
|
||||
|
||||
#define AM_HAL_INTERRUPT_SOFTWARE0 44
|
||||
#define AM_HAL_INTERRUPT_SOFTWARE1 45
|
||||
#define AM_HAL_INTERRUPT_SOFTWARE2 46
|
||||
#define AM_HAL_INTERRUPT_SOFTWARE3 47
|
||||
//! @}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Interrupt priority
|
||||
//!
|
||||
//! This macro is made to be used with the \e am_hal_interrupt_priority_set()
|
||||
//! function. It converts a priority number to the format used by the ARM
|
||||
//! standard priority register, where only the top 3 bits are used.
|
||||
//!
|
||||
//! For example, AM_HAL_INTERRUPT_PRIORITY(1) yields a value of 0x20.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define AM_HAL_INTERRUPT_PRIORITY(n) (((uint32_t)(n) & 0x7) << 5)
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// External function definitions
|
||||
//
|
||||
//*****************************************************************************
|
||||
extern void am_hal_interrupt_enable(uint32_t ui32Interrupt);
|
||||
extern void am_hal_interrupt_disable(uint32_t ui32Interrupt);
|
||||
extern void am_hal_interrupt_pend_set(uint32_t ui32Interrupt);
|
||||
extern void am_hal_interrupt_pend_clear(uint32_t ui32Interrupt);
|
||||
extern void am_hal_interrupt_priority_set(uint32_t ui32Interrupt,
|
||||
uint32_t ui32Priority);
|
||||
extern uint32_t am_hal_interrupt_master_disable(void);
|
||||
extern uint32_t am_hal_interrupt_master_enable(void);
|
||||
extern void am_hal_interrupt_master_set(uint32_t ui32InterruptState);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // AM_HAL_INTERRUPT_H
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// End Doxygen group.
|
||||
//! @}
|
||||
//
|
||||
//*****************************************************************************
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,362 @@
|
||||
//*****************************************************************************
|
||||
//
|
||||
// am_hal_ios.h
|
||||
//! @file
|
||||
//!
|
||||
//! @brief Functions for interfacing with the IO Slave module
|
||||
//!
|
||||
//! @addtogroup ios2 IO Slave (SPI/I2C)
|
||||
//! @ingroup apollo2hal
|
||||
//! @{
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Copyright (c) 2017, Ambiq Micro
|
||||
// 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.
|
||||
//
|
||||
// This is part of revision 1.2.9 of the AmbiqSuite Development Package.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#ifndef AM_HAL_IOS_H
|
||||
#define AM_HAL_IOS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @name Interface Configuration
|
||||
//! @brief Macro definitions for configuring the physical interface of the IO
|
||||
//! Slave
|
||||
//!
|
||||
//! These macros may be used with the am_hal_ios_config_t structure to set the
|
||||
//! physical parameters of the SPI/I2C slave module.
|
||||
//!
|
||||
//! @{
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define AM_HAL_IOS_USE_SPI AM_REG_IOSLAVE_CFG_IFCSEL_SPI
|
||||
#define AM_HAL_IOS_SPIMODE_0 AM_REG_IOSLAVE_CFG_SPOL_SPI_MODES_0_3
|
||||
#define AM_HAL_IOS_SPIMODE_1 AM_REG_IOSLAVE_CFG_SPOL_SPI_MODES_1_2
|
||||
#define AM_HAL_IOS_SPIMODE_2 AM_REG_IOSLAVE_CFG_SPOL_SPI_MODES_1_2
|
||||
#define AM_HAL_IOS_SPIMODE_3 AM_REG_IOSLAVE_CFG_SPOL_SPI_MODES_0_3
|
||||
|
||||
#define AM_HAL_IOS_USE_I2C AM_REG_IOSLAVE_CFG_IFCSEL_I2C
|
||||
#define AM_HAL_IOS_I2C_ADDRESS(n) AM_REG_IOSLAVE_CFG_I2CADDR(n)
|
||||
|
||||
#define AM_HAL_IOS_LSB_FIRST AM_REG_IOSLAVE_CFG_LSB(1)
|
||||
//! @}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @name Register Access Interrupts
|
||||
//! @brief Macro definitions for register access interrupts.
|
||||
//!
|
||||
//! These macros may be used with any of the
|
||||
//!
|
||||
//! @{
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define AM_HAL_IOS_ACCESS_INT_00 AM_REG_IOSLAVE_REGACCINTEN_REGACC((uint32_t)1 << 31)
|
||||
#define AM_HAL_IOS_ACCESS_INT_01 AM_REG_IOSLAVE_REGACCINTEN_REGACC((uint32_t)1 << 30)
|
||||
#define AM_HAL_IOS_ACCESS_INT_02 AM_REG_IOSLAVE_REGACCINTEN_REGACC((uint32_t)1 << 29)
|
||||
#define AM_HAL_IOS_ACCESS_INT_03 AM_REG_IOSLAVE_REGACCINTEN_REGACC((uint32_t)1 << 28)
|
||||
#define AM_HAL_IOS_ACCESS_INT_04 AM_REG_IOSLAVE_REGACCINTEN_REGACC((uint32_t)1 << 27)
|
||||
#define AM_HAL_IOS_ACCESS_INT_05 AM_REG_IOSLAVE_REGACCINTEN_REGACC((uint32_t)1 << 26)
|
||||
#define AM_HAL_IOS_ACCESS_INT_06 AM_REG_IOSLAVE_REGACCINTEN_REGACC((uint32_t)1 << 25)
|
||||
#define AM_HAL_IOS_ACCESS_INT_07 AM_REG_IOSLAVE_REGACCINTEN_REGACC((uint32_t)1 << 24)
|
||||
#define AM_HAL_IOS_ACCESS_INT_08 AM_REG_IOSLAVE_REGACCINTEN_REGACC((uint32_t)1 << 23)
|
||||
#define AM_HAL_IOS_ACCESS_INT_09 AM_REG_IOSLAVE_REGACCINTEN_REGACC((uint32_t)1 << 22)
|
||||
#define AM_HAL_IOS_ACCESS_INT_0A AM_REG_IOSLAVE_REGACCINTEN_REGACC((uint32_t)1 << 21)
|
||||
#define AM_HAL_IOS_ACCESS_INT_0B AM_REG_IOSLAVE_REGACCINTEN_REGACC((uint32_t)1 << 20)
|
||||
#define AM_HAL_IOS_ACCESS_INT_0C AM_REG_IOSLAVE_REGACCINTEN_REGACC((uint32_t)1 << 19)
|
||||
#define AM_HAL_IOS_ACCESS_INT_0D AM_REG_IOSLAVE_REGACCINTEN_REGACC((uint32_t)1 << 18)
|
||||
#define AM_HAL_IOS_ACCESS_INT_0E AM_REG_IOSLAVE_REGACCINTEN_REGACC((uint32_t)1 << 17)
|
||||
#define AM_HAL_IOS_ACCESS_INT_0F AM_REG_IOSLAVE_REGACCINTEN_REGACC((uint32_t)1 << 16)
|
||||
#define AM_HAL_IOS_ACCESS_INT_13 AM_REG_IOSLAVE_REGACCINTEN_REGACC((uint32_t)1 << 15)
|
||||
#define AM_HAL_IOS_ACCESS_INT_17 AM_REG_IOSLAVE_REGACCINTEN_REGACC((uint32_t)1 << 14)
|
||||
#define AM_HAL_IOS_ACCESS_INT_1B AM_REG_IOSLAVE_REGACCINTEN_REGACC((uint32_t)1 << 13)
|
||||
#define AM_HAL_IOS_ACCESS_INT_1F AM_REG_IOSLAVE_REGACCINTEN_REGACC((uint32_t)1 << 12)
|
||||
#define AM_HAL_IOS_ACCESS_INT_23 AM_REG_IOSLAVE_REGACCINTEN_REGACC((uint32_t)1 << 11)
|
||||
#define AM_HAL_IOS_ACCESS_INT_27 AM_REG_IOSLAVE_REGACCINTEN_REGACC((uint32_t)1 << 10)
|
||||
#define AM_HAL_IOS_ACCESS_INT_2B AM_REG_IOSLAVE_REGACCINTEN_REGACC((uint32_t)1 << 9)
|
||||
#define AM_HAL_IOS_ACCESS_INT_2F AM_REG_IOSLAVE_REGACCINTEN_REGACC((uint32_t)1 << 8)
|
||||
#define AM_HAL_IOS_ACCESS_INT_33 AM_REG_IOSLAVE_REGACCINTEN_REGACC((uint32_t)1 << 7)
|
||||
#define AM_HAL_IOS_ACCESS_INT_37 AM_REG_IOSLAVE_REGACCINTEN_REGACC((uint32_t)1 << 6)
|
||||
#define AM_HAL_IOS_ACCESS_INT_3B AM_REG_IOSLAVE_REGACCINTEN_REGACC((uint32_t)1 << 5)
|
||||
#define AM_HAL_IOS_ACCESS_INT_3F AM_REG_IOSLAVE_REGACCINTEN_REGACC((uint32_t)1 << 4)
|
||||
#define AM_HAL_IOS_ACCESS_INT_43 AM_REG_IOSLAVE_REGACCINTEN_REGACC((uint32_t)1 << 3)
|
||||
#define AM_HAL_IOS_ACCESS_INT_47 AM_REG_IOSLAVE_REGACCINTEN_REGACC((uint32_t)1 << 2)
|
||||
#define AM_HAL_IOS_ACCESS_INT_4B AM_REG_IOSLAVE_REGACCINTEN_REGACC((uint32_t)1 << 1)
|
||||
#define AM_HAL_IOS_ACCESS_INT_4F AM_REG_IOSLAVE_REGACCINTEN_REGACC((uint32_t)1 << 0)
|
||||
#define AM_HAL_IOS_ACCESS_INT_ALL 0xFFFFFFFF
|
||||
//! @}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @name I/O Slave Interrupts
|
||||
//! @brief Macro definitions for I/O slave (IOS) interrupts.
|
||||
//!
|
||||
//! These macros may be used with any of the
|
||||
//!
|
||||
//! @{
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define AM_HAL_IOS_INT_FSIZE AM_REG_IOSLAVE_INTEN_FSIZE_M
|
||||
#define AM_HAL_IOS_INT_FOVFL AM_REG_IOSLAVE_INTEN_FOVFL_M
|
||||
#define AM_HAL_IOS_INT_FUNDFL AM_REG_IOSLAVE_INTEN_FUNDFL_M
|
||||
#define AM_HAL_IOS_INT_FRDERR AM_REG_IOSLAVE_INTEN_FRDERR_M
|
||||
#define AM_HAL_IOS_INT_GENAD AM_REG_IOSLAVE_INTEN_GENAD_M
|
||||
#define AM_HAL_IOS_INT_IOINTW AM_REG_IOSLAVE_INTEN_IOINTW_M
|
||||
#define AM_HAL_IOS_INT_XCMPWR AM_REG_IOSLAVE_INTEN_XCMPWR_M
|
||||
#define AM_HAL_IOS_INT_XCMPWF AM_REG_IOSLAVE_INTEN_XCMPWF_M
|
||||
#define AM_HAL_IOS_INT_XCMPRR AM_REG_IOSLAVE_INTEN_XCMPRR_M
|
||||
#define AM_HAL_IOS_INT_XCMPRF AM_REG_IOSLAVE_INTEN_XCMPRF_M
|
||||
#define AM_HAL_IOS_INT_ALL 0xFFFFFFFF
|
||||
//! @}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @name I/O Slave Interrupts triggers
|
||||
//! @brief Macro definitions for I/O slave (IOS) interrupts.
|
||||
//!
|
||||
//! These macros may be used with am_hal_ios_int_set and am_hal_ios_int_clear
|
||||
//!
|
||||
//! @{
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define AM_HAL_IOS_IOINTCTL_INT0 (0x01)
|
||||
#define AM_HAL_IOS_IOINTCTL_INT1 (0x02)
|
||||
#define AM_HAL_IOS_IOINTCTL_INT2 (0x04)
|
||||
#define AM_HAL_IOS_IOINTCTL_INT3 (0x08)
|
||||
#define AM_HAL_IOS_IOINTCTL_INT4 (0x10)
|
||||
#define AM_HAL_IOS_IOINTCTL_INT5 (0x20)
|
||||
//! @}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// External variable definitions
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief LRAM pointer
|
||||
//!
|
||||
//! Pointer to the base of the IO Slave LRAM.
|
||||
//
|
||||
//*****************************************************************************
|
||||
extern volatile uint8_t * const am_hal_ios_pui8LRAM;
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Configuration structure for the IO slave module.
|
||||
//!
|
||||
//! This structure may be used along with the am_hal_ios_config() function to
|
||||
//! select key parameters of the IO Slave module. See the descriptions of each
|
||||
//! parameter within this structure for more information on what they control.
|
||||
//
|
||||
//*****************************************************************************
|
||||
typedef struct
|
||||
{
|
||||
//
|
||||
//! Interface Selection
|
||||
//!
|
||||
//! This word selects the physical behavior of the IO Slave port. For SPI
|
||||
//! mode, this word should be the logical OR of one or more of the
|
||||
//! following:
|
||||
//!
|
||||
//! AM_HAL_IOS_USE_SPI
|
||||
//! AM_HAL_IOS_SPIMODE_0
|
||||
//! AM_HAL_IOS_SPIMODE_1
|
||||
//! AM_HAL_IOS_SPIMODE_2
|
||||
//! AM_HAL_IOS_SPIMODE_3
|
||||
//!
|
||||
//! For I2C mode, use the logical OR of one or more of these values instead
|
||||
//! (where n is the 7 or 10-bit I2C address to use):
|
||||
//!
|
||||
//! AM_HAL_IOS_USE_I2C
|
||||
//! AM_HAL_IOS_I2C_ADDRESS(n)
|
||||
//!
|
||||
//! Also, in any mode, you may OR in this value to reverse the order of
|
||||
//! incoming data bits.
|
||||
//!
|
||||
//! AM_HAL_IOS_LSB_FIRST
|
||||
//
|
||||
uint32_t ui32InterfaceSelect;
|
||||
|
||||
//
|
||||
//! Read-Only section
|
||||
//!
|
||||
//! The IO Slave LRAM is split into three main sections. The first section
|
||||
//! is a "Direct Write" section, which may be accessed for reads or write
|
||||
//! either directly through the Apollo CPU, or over the SPI/I2C bus. The
|
||||
//! "Direct Write" section always begins at LRAM offset 0x0. At the end of
|
||||
//! the normal "Direct Write" space, there is a "Read Only" space, which is
|
||||
//! read/write accessible to the Apollo CPU, but read-only over the I2C/SPI
|
||||
//! Bus. This word selects the base address of this "Read Only" space.
|
||||
//!
|
||||
//! This value may be set to any multiple of 8 between 0x0 and 0x78,
|
||||
//! inclusive. For the configuration to be valid, \e ui32ROBase must also
|
||||
//! be less than or equal to \e ui32FIFOBase
|
||||
//!
|
||||
//! @note The address given here is in units of BYTES. Since the location
|
||||
//! of the "Read Only" space may only be set in 8-byte increments, this
|
||||
//! value must be a multiple of 8.
|
||||
//!
|
||||
//! For the avoidance of doubt this means 0x80 is 128 bytes. These functions
|
||||
//! will shift right by 8 internally.
|
||||
//
|
||||
uint32_t ui32ROBase;
|
||||
|
||||
//
|
||||
//! FIFO section
|
||||
//!
|
||||
//! After the "Direct Access" and "Read Only" sections is a section of LRAM
|
||||
//! allocated to a FIFO. This section is accessible by the Apollo CPU
|
||||
//! through the FIFO control registers, and accessible on the SPI/I2C bus
|
||||
//! through the 0x7F address. This word selects the base address of the
|
||||
//! FIFO space. The FIFO will extend from the address specified here to the
|
||||
//! address specified in \e ui32RAMBase.
|
||||
//!
|
||||
//! This value may be set to any multiple of 8 between 0x0 and 0x78,
|
||||
//! inclusive. For the configuration to be valid, \e ui32FIFOBase must also
|
||||
//! be greater than or equal to \e ui32ROBase.
|
||||
//!
|
||||
//! @note The address given here is in units of BYTES. Since the location
|
||||
//! of the "FIFO" space may only be set in 8-byte increments, this value
|
||||
//! must be a multiple of 8.
|
||||
//!
|
||||
//! For the avoidance of doubt this means 0x80 is 128 bytes. These functions
|
||||
//! will shift right by 8 internally.
|
||||
//
|
||||
uint32_t ui32FIFOBase;
|
||||
|
||||
//
|
||||
//! RAM section
|
||||
//!
|
||||
//! At the end of the IOS LRAM, the user may allocate a "RAM" space that
|
||||
//! can only be accessed by the Apollo CPU. This space will not interact
|
||||
//! with the SPI/I2C bus at all, and may be used as general-purpose memory.
|
||||
//! Unlike normal SRAM, this section of LRAM will retain its state through
|
||||
//! Deep Sleep, so it may be used as a data retention space for
|
||||
//! ultra-low-power applications.
|
||||
//!
|
||||
//! This value may be set to any multiple of 8 between 0x0 and 0x100,
|
||||
//! inclusive. For the configuration to be valid, \e ui32RAMBase must also
|
||||
//! be greater than or equal to \e ui32FIFOBase.
|
||||
//!
|
||||
//! @note The address given here is in units of BYTES. Since the location
|
||||
//! of the "FIFO" space may only be set in 8-byte increments, this value
|
||||
//! must be a multiple of 8.
|
||||
//!
|
||||
//! For the avoidance of doubt this means 0x80 is 128 bytes. These functions
|
||||
//! will shift right by 8 internally.
|
||||
//
|
||||
uint32_t ui32RAMBase;
|
||||
|
||||
//
|
||||
//! FIFO threshold
|
||||
//!
|
||||
//! The IO Slave module will trigger an interrupt when the number of
|
||||
//! entries in the FIFO drops below this number of bytes.
|
||||
//
|
||||
uint32_t ui32FIFOThreshold;
|
||||
|
||||
//
|
||||
// Pointer to an SRAM
|
||||
//
|
||||
uint8_t *pui8SRAMBuffer;
|
||||
}
|
||||
am_hal_ios_config_t;
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// External function definitions
|
||||
//
|
||||
//*****************************************************************************
|
||||
extern void am_hal_ios_enable(uint32_t ui32Module);
|
||||
extern void am_hal_ios_disable(uint32_t ui32Module);
|
||||
|
||||
// these interrupts drive the HOST side IOS interrupt pins
|
||||
extern void am_hal_ios_host_int_set(uint32_t ui32Interrupt);
|
||||
extern void am_hal_ios_host_int_clear(uint32_t ui32Interrupt);
|
||||
extern uint32_t am_hal_ios_host_int_get(void);
|
||||
extern uint32_t am_hal_ios_host_int_enable_get(void);
|
||||
|
||||
extern void am_hal_ios_lram_write(uint32_t ui32Offset, uint8_t ui8Value);
|
||||
extern uint8_t am_hal_ios_lram_read(uint32_t ui32Offset);
|
||||
|
||||
// the following interrupts go back to the NVIC
|
||||
extern void am_hal_ios_config(am_hal_ios_config_t *psConfig);
|
||||
extern void am_hal_ios_access_int_enable(uint32_t ui32Interrupt);
|
||||
extern uint32_t am_hal_ios_access_int_enable_get(void);
|
||||
extern void am_hal_ios_access_int_disable(uint32_t ui32Interrupt);
|
||||
extern void am_hal_ios_access_int_clear(uint32_t ui32Interrupt);
|
||||
extern void am_hal_ios_access_int_set(uint32_t ui32Interrupt);
|
||||
extern uint32_t am_hal_ios_access_int_status_get(bool bEnabledOnly);
|
||||
extern void am_hal_ios_int_enable(uint32_t ui32Interrupt);
|
||||
extern uint32_t am_hal_ios_int_enable_get(void);
|
||||
extern void am_hal_ios_int_disable(uint32_t ui32Interrupt);
|
||||
extern void am_hal_ios_int_clear(uint32_t ui32Interrupt);
|
||||
extern void am_hal_ios_int_set(uint32_t ui32Interrupt);
|
||||
extern uint32_t am_hal_ios_int_status_get(bool bEnabledOnly);
|
||||
|
||||
extern void am_hal_ios_fifo_buffer_init(uint8_t *pui8Buffer, uint32_t ui32NumBytes);
|
||||
extern uint32_t am_hal_ios_fifo_space_left(void);
|
||||
extern uint32_t am_hal_ios_fifo_space_used(void);
|
||||
extern void am_hal_ios_fifo_service(uint32_t ui32Status);
|
||||
// Returns the number of bytes actually written
|
||||
extern uint32_t am_hal_ios_fifo_write(uint8_t *pui8Data, uint32_t ui32NumBytes);
|
||||
extern void am_hal_ios_fifo_write_simple(uint8_t *pui8Data,
|
||||
uint32_t ui32NumBytes);
|
||||
extern void am_hal_ios_fifo_ptr_set(uint32_t ui32Offset);
|
||||
extern void am_hal_ios_update_fifoctr(void);
|
||||
|
||||
extern void am_hal_ios_read_poll_complete(void);
|
||||
extern void am_hal_ios_pwrctrl_enable(void);
|
||||
extern void am_hal_ios_pwrctrl_disable(void);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // AM_HAL_IOS_H
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// End Doxygen group.
|
||||
//! @}
|
||||
//
|
||||
//*****************************************************************************
|
||||
@@ -0,0 +1,453 @@
|
||||
//*****************************************************************************
|
||||
//
|
||||
// am_hal_itm.c
|
||||
//! @file
|
||||
//!
|
||||
//! @brief Functions for operating the instrumentation trace macrocell
|
||||
//!
|
||||
//! @addtogroup itm2 Instrumentation Trace Macrocell (ITM)
|
||||
//! @ingroup apollo2hal
|
||||
//! @{
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Copyright (c) 2017, Ambiq Micro
|
||||
// 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.
|
||||
//
|
||||
// This is part of revision 1.2.9 of the AmbiqSuite Development Package.
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "am_mcu_apollo.h"
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Global Variables
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Delays for a desired amount of microseconds.
|
||||
//!
|
||||
//! @note - This function is based on the similar function in am_util_delay.c,
|
||||
//! please see that module for implementation details. It was necessary to
|
||||
//! duplicate it here to avoid having to update every example to include the
|
||||
//! am_util_delay.c module in its build.
|
||||
//!
|
||||
//! @returns None
|
||||
//
|
||||
//*****************************************************************************
|
||||
void
|
||||
am_hal_itm_delay_us(uint32_t ui32MicroSeconds)
|
||||
{
|
||||
uint32_t ui32Iterations = ui32MicroSeconds *
|
||||
(am_hal_clkgen_sysclk_get() / 3000000);
|
||||
|
||||
//
|
||||
// Call the BOOTROM cycle delay function
|
||||
//
|
||||
am_hal_flash_delay(ui32Iterations);
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Enables the ITM
|
||||
//!
|
||||
//! This function enables the ARM ITM by setting the TRCENA bit in the DEMCR
|
||||
//! register.
|
||||
//!
|
||||
//! @return None.
|
||||
//
|
||||
//*****************************************************************************
|
||||
void
|
||||
am_hal_itm_enable(void)
|
||||
{
|
||||
if (g_ui32HALflags & AM_HAL_FLAGS_ITMSKIPENABLEDISABLE_M)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// To be able to access ITM registers, set the Trace Enable bit
|
||||
// in the Debug Exception and Monitor Control Register (DEMCR).
|
||||
//
|
||||
AM_REG(SYSCTRL, DEMCR) |= AM_REG_SYSCTRL_DEMCR_TRCENA(1);
|
||||
while ( !(AM_REG(SYSCTRL, DEMCR) & AM_REG_SYSCTRL_DEMCR_TRCENA(1)) );
|
||||
|
||||
//
|
||||
// Write the key to the ITM Lock Access register to unlock the ITM_TCR.
|
||||
//
|
||||
AM_REGVAL(AM_REG_ITM_LOCKAREG_O) = AM_REG_ITM_LOCKAREG_KEYVAL;
|
||||
|
||||
//
|
||||
// Set the enable bits in the ITM trace enable register, and the ITM
|
||||
// control registers to enable trace data output.
|
||||
//
|
||||
AM_REGVAL(AM_REG_ITM_TPR_O) = 0x0000000f;
|
||||
AM_REGVAL(AM_REG_ITM_TER_O) = 0xffffffff;
|
||||
|
||||
//
|
||||
// Write to the ITM control and status register (don't enable yet).
|
||||
//
|
||||
AM_REGVAL(AM_REG_ITM_TCR_O) =
|
||||
AM_WRITE_SM(AM_REG_ITM_TCR_ATB_ID, 0x15) |
|
||||
AM_WRITE_SM(AM_REG_ITM_TCR_TS_FREQ, 1) |
|
||||
AM_WRITE_SM(AM_REG_ITM_TCR_TS_PRESCALE, 1) |
|
||||
AM_WRITE_SM(AM_REG_ITM_TCR_SWV_ENABLE, 1) |
|
||||
AM_WRITE_SM(AM_REG_ITM_TCR_DWT_ENABLE, 0) |
|
||||
AM_WRITE_SM(AM_REG_ITM_TCR_SYNC_ENABLE, 0) |
|
||||
AM_WRITE_SM(AM_REG_ITM_TCR_TS_ENABLE, 0) |
|
||||
AM_WRITE_SM(AM_REG_ITM_TCR_ITM_ENABLE, 1);
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Disables the ITM
|
||||
//!
|
||||
//! This function completely disables the ARM ITM by resetting the TRCENA bit
|
||||
//! in the DEMCR register.
|
||||
//!
|
||||
//! @return None.
|
||||
//
|
||||
//*****************************************************************************
|
||||
void
|
||||
am_hal_itm_disable(void)
|
||||
{
|
||||
|
||||
if (g_ui32HALflags & AM_HAL_FLAGS_ITMSKIPENABLEDISABLE_M)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Make sure the ITM_TCR is unlocked.
|
||||
//
|
||||
AM_REGVAL(AM_REG_ITM_LOCKAREG_O) = AM_REG_ITM_LOCKAREG_KEYVAL;
|
||||
|
||||
//
|
||||
// Make sure the ITM/TPIU is not busy.
|
||||
//
|
||||
while ( AM_REG(ITM, TCR) & AM_REG_ITM_TCR_BUSY(1) );
|
||||
|
||||
//
|
||||
// Disable the ITM.
|
||||
//
|
||||
for (int ix = 0; ix < 100; ix++)
|
||||
{
|
||||
AM_REG(ITM, TCR) &= ~AM_REG_ITM_TCR_ITM_ENABLE(1);
|
||||
while ( AM_REG(ITM, TCR) & (AM_REG_ITM_TCR_ITM_ENABLE(1) | AM_REG_ITM_TCR_BUSY(1)) );
|
||||
}
|
||||
|
||||
//
|
||||
// Reset the TRCENA bit in the DEMCR register, which should disable the ITM
|
||||
// for operation.
|
||||
//
|
||||
AM_REG(SYSCTRL, DEMCR) &= ~AM_REG_SYSCTRL_DEMCR_TRCENA(1);
|
||||
|
||||
//
|
||||
// Disable the TPIU clock source in MCU control.
|
||||
//
|
||||
AM_REG(MCUCTRL, TPIUCTRL) = AM_REG_MCUCTRL_TPIUCTRL_CLKSEL_0MHz |
|
||||
AM_REG_MCUCTRL_TPIUCTRL_ENABLE_DIS;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Checks if itm is busy and provides a delay to flush the fifo
|
||||
//!
|
||||
//! This function disables the ARM ITM by resetting the TRCENA bit in the DEMCR
|
||||
//! register.
|
||||
//!
|
||||
//! @return None.
|
||||
//
|
||||
//*****************************************************************************
|
||||
void
|
||||
am_hal_itm_not_busy(void)
|
||||
{
|
||||
//
|
||||
// Make sure the ITM/TPIU is not busy.
|
||||
//
|
||||
while (AM_REG(ITM, TCR) & AM_REG_ITM_TCR_BUSY(1));
|
||||
|
||||
//
|
||||
// wait for 50us for the data to flush out
|
||||
//
|
||||
am_hal_itm_delay_us(50);
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Enables tracing on a given set of ITM ports
|
||||
//!
|
||||
//! @param ui8portNum - Set ports to be enabled
|
||||
//!
|
||||
//! Enables tracing on the ports referred to by \e ui8portNum by writing the
|
||||
//! associated bit in the Trace Privilege Register in the ITM. The value for
|
||||
//! ui8portNum should be the logical OR one or more of the following values:
|
||||
//!
|
||||
//! \e ITM_PRIVMASK_0_7 - enable ports 0 through 7
|
||||
//! \e ITM_PRIVMASK_8_15 - enable ports 8 through 15
|
||||
//! \e ITM_PRIVMASK_16_23 - enable ports 16 through 23
|
||||
//! \e ITM_PRIVMASK_24_31 - enable ports 24 through 31
|
||||
//!
|
||||
//! @return None.
|
||||
//
|
||||
//*****************************************************************************
|
||||
void
|
||||
am_hal_itm_trace_port_enable(uint8_t ui8portNum)
|
||||
{
|
||||
AM_REGVAL(AM_REG_ITM_TPR_O) |= (0x00000001 << (ui8portNum>>3));
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Disable tracing on the given ITM stimulus port.
|
||||
//!
|
||||
//! @param ui8portNum
|
||||
//!
|
||||
//! Disables tracing on the ports referred to by \e ui8portNum by writing the
|
||||
//! associated bit in the Trace Privilege Register in the ITM. The value for
|
||||
//! ui8portNum should be the logical OR one or more of the following values:
|
||||
//!
|
||||
//! \e ITM_PRIVMASK_0_7 - disable ports 0 through 7
|
||||
//! \e ITM_PRIVMASK_8_15 - disable ports 8 through 15
|
||||
//! \e ITM_PRIVMASK_16_23 - disable ports 16 through 23
|
||||
//! \e ITM_PRIVMASK_24_31 - disable ports 24 through 31
|
||||
//!
|
||||
//! @return None.
|
||||
//
|
||||
//*****************************************************************************
|
||||
void
|
||||
am_hal_itm_trace_port_disable(uint8_t ui8portNum)
|
||||
{
|
||||
AM_REGVAL(AM_REG_ITM_TPR_O) &= ~(0x00000001 << (ui8portNum >> 3));
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Poll the given ITM stimulus register until not busy.
|
||||
//!
|
||||
//! @param ui32StimReg - stimulus register
|
||||
//!
|
||||
//! @return true if not busy, false if busy (timed out or other error).
|
||||
//
|
||||
//*****************************************************************************
|
||||
bool
|
||||
am_hal_itm_stimulus_not_busy(uint32_t ui32StimReg)
|
||||
{
|
||||
uint32_t ui32StimAddr = (AM_REG_ITM_STIM0_O + (4 * ui32StimReg));
|
||||
|
||||
//
|
||||
// Busy waiting until it is available, non-zero means ready.
|
||||
//
|
||||
while (!AM_REGVAL(ui32StimAddr));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Writes a 32-bit value to the given ITM stimulus register.
|
||||
//!
|
||||
//! @param ui32StimReg - stimulus register
|
||||
//! @param ui32Value - value to be written.
|
||||
//!
|
||||
//! Write a word to the desired stimulus register.
|
||||
//!
|
||||
//! @return None.
|
||||
//
|
||||
//*****************************************************************************
|
||||
void
|
||||
am_hal_itm_stimulus_reg_word_write(uint32_t ui32StimReg, uint32_t ui32Value)
|
||||
{
|
||||
uint32_t ui32StimAddr;
|
||||
|
||||
ui32StimAddr = (AM_REG_ITM_STIM0_O + (4 * ui32StimReg));
|
||||
|
||||
//
|
||||
// Busy waiting until it is available, non-zero means ready
|
||||
//
|
||||
while (!AM_REGVAL(ui32StimAddr));
|
||||
|
||||
//
|
||||
// Write the register.
|
||||
//
|
||||
AM_REGVAL(ui32StimAddr) = ui32Value;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Writes a short to the given ITM stimulus register.
|
||||
//!
|
||||
//! @param ui32StimReg - stimulus register
|
||||
//! @param ui16Value - short to be written.
|
||||
//!
|
||||
//! Write a short to the desired stimulus register.
|
||||
//!
|
||||
//! @return None.
|
||||
//
|
||||
//*****************************************************************************
|
||||
void
|
||||
am_hal_itm_stimulus_reg_short_write(uint32_t ui32StimReg, uint16_t ui16Value)
|
||||
{
|
||||
uint32_t ui32StimAddr;
|
||||
|
||||
ui32StimAddr = (AM_REG_ITM_STIM0_O + (4 * ui32StimReg));
|
||||
|
||||
//
|
||||
// Busy waiting until it is available non-zero means ready
|
||||
//
|
||||
while (!AM_REGVAL(ui32StimAddr));
|
||||
|
||||
//
|
||||
// Write the register.
|
||||
//
|
||||
*((volatile uint16_t *) ui32StimAddr) = ui16Value;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Writes a byte to the given ITM stimulus register.
|
||||
//!
|
||||
//! @param ui32StimReg - stimulus register
|
||||
//! @param ui8Value - byte to be written.
|
||||
//!
|
||||
//! Write a byte to the desired stimulus register.
|
||||
//!
|
||||
//! @return None.
|
||||
//
|
||||
//*****************************************************************************
|
||||
void
|
||||
am_hal_itm_stimulus_reg_byte_write(uint32_t ui32StimReg, uint8_t ui8Value)
|
||||
{
|
||||
uint32_t ui32StimAddr;
|
||||
|
||||
ui32StimAddr = (AM_REG_ITM_STIM0_O + (4 * ui32StimReg));
|
||||
|
||||
//
|
||||
// Busy waiting until it is available (non-zero means ready)
|
||||
//
|
||||
while (!AM_REGVAL(ui32StimAddr));
|
||||
|
||||
//
|
||||
// Write the register.
|
||||
//
|
||||
*((volatile uint8_t *) ui32StimAddr) = ui8Value;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Sends a Sync Packet.
|
||||
//!
|
||||
//! Sends a sync packet. This can be useful for external software should it
|
||||
//! become out of sync with the ITM stream.
|
||||
//!
|
||||
//! @return None.
|
||||
//
|
||||
//*****************************************************************************
|
||||
void
|
||||
am_hal_itm_sync_send(void)
|
||||
{
|
||||
//
|
||||
// Write the register.
|
||||
//
|
||||
am_hal_itm_stimulus_reg_word_write(AM_HAL_ITM_SYNC_REG,
|
||||
AM_HAL_ITM_SYNC_VAL);
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Poll the print stimulus registers until not busy.
|
||||
//!
|
||||
//! @return true if not busy, false if busy (timed out or other error).
|
||||
//
|
||||
//*****************************************************************************
|
||||
bool
|
||||
am_hal_itm_print_not_busy(void)
|
||||
{
|
||||
//
|
||||
// Poll stimulus register allocated for printing.
|
||||
//
|
||||
am_hal_itm_stimulus_not_busy(0);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Prints a char string out of the ITM.
|
||||
//!
|
||||
//! @param pcString pointer to the character sting
|
||||
//!
|
||||
//! This function prints a sting out of the ITM.
|
||||
//!
|
||||
//! @return None.
|
||||
//
|
||||
//*****************************************************************************
|
||||
void
|
||||
am_hal_itm_print(char *pcString)
|
||||
{
|
||||
uint32_t ui32Length = 0;
|
||||
|
||||
//
|
||||
// Determine the length of the string.
|
||||
//
|
||||
while (*(pcString + ui32Length))
|
||||
{
|
||||
ui32Length++;
|
||||
}
|
||||
|
||||
//
|
||||
// If there is no longer a word left, empty out the remaining characters.
|
||||
//
|
||||
while (ui32Length)
|
||||
{
|
||||
//
|
||||
// Print string out the ITM.
|
||||
//
|
||||
am_hal_itm_stimulus_reg_byte_write(0, (uint8_t)*pcString++);
|
||||
|
||||
//
|
||||
// Subtract from length.
|
||||
//
|
||||
ui32Length--;
|
||||
}
|
||||
}
|
||||
//*****************************************************************************
|
||||
//
|
||||
// End Doxygen group.
|
||||
//! @}
|
||||
//
|
||||
//*****************************************************************************
|
||||
@@ -0,0 +1,107 @@
|
||||
//*****************************************************************************
|
||||
//
|
||||
// am_hal_itm.h
|
||||
//! @file
|
||||
//!
|
||||
//! @brief Functions for accessing and configuring the ARM ITM.
|
||||
//!
|
||||
//! @addtogroup itm2 Instrumentation Trace Macrocell (ITM)
|
||||
//! @ingroup apollo2hal
|
||||
//! @{
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Copyright (c) 2017, Ambiq Micro
|
||||
// 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.
|
||||
//
|
||||
// This is part of revision 1.2.9 of the AmbiqSuite Development Package.
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
#ifndef AM_HAL_ITM_H
|
||||
#define AM_HAL_ITM_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Sync Packet Defines
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define AM_HAL_ITM_SYNC_REG 23
|
||||
#define AM_HAL_ITM_SYNC_VAL 0xF8F8F8F8
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// PrintF Setup
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define AM_HAL_ITM_PRINT_NUM_BYTES 1
|
||||
#define AM_HAL_ITM_PRINT_NUM_REGS 1
|
||||
extern uint32_t am_hal_itm_print_registers[AM_HAL_ITM_PRINT_NUM_REGS];
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// External function definitions
|
||||
//
|
||||
//*****************************************************************************
|
||||
extern void am_hal_itm_delay_us(uint32_t ui32MicroSeconds);
|
||||
extern void am_hal_itm_enable(void);
|
||||
extern void am_hal_itm_disable(void);
|
||||
extern void am_hal_itm_not_busy(void);
|
||||
extern void am_hal_itm_sync_send(void);
|
||||
extern void am_hal_itm_trace_port_enable(uint8_t ui8portNum);
|
||||
extern void am_hal_itm_trace_port_disable(uint8_t ui8portNum);
|
||||
extern bool am_hal_itm_stimulus_not_busy(uint32_t ui32StimReg);
|
||||
extern void am_hal_itm_stimulus_reg_word_write(uint32_t ui32StimReg,
|
||||
uint32_t ui32Value);
|
||||
extern void am_hal_itm_stimulus_reg_short_write(uint32_t ui32StimReg,
|
||||
uint16_t ui16Value);
|
||||
extern void am_hal_itm_stimulus_reg_byte_write(uint32_t ui32StimReg,
|
||||
uint8_t ui8Value);
|
||||
extern bool am_hal_itm_print_not_busy(void);
|
||||
extern void am_hal_itm_print(char *pcString);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // AM_HAL_ITM_H
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// End Doxygen group.
|
||||
//! @}
|
||||
//
|
||||
//*****************************************************************************
|
||||
@@ -0,0 +1,292 @@
|
||||
//*****************************************************************************
|
||||
//
|
||||
// am_hal_mcuctrl.c
|
||||
//! @file
|
||||
//!
|
||||
//! @brief Functions for interfacing with the MCUCTRL.
|
||||
//!
|
||||
//! @addtogroup mcuctrl2 MCU Control (MCUCTRL)
|
||||
//! @ingroup apollo2hal
|
||||
//! @{
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Copyright (c) 2017, Ambiq Micro
|
||||
// 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.
|
||||
//
|
||||
// This is part of revision 1.2.9 of the AmbiqSuite Development Package.
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "am_mcu_apollo.h"
|
||||
|
||||
#define LDO_TRIM_REG_ADDR (0x50023004)
|
||||
#define BUCK_TRIM_REG_ADDR (0x50023000)
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Global Variables.
|
||||
//
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Define the flash sizes from CHIP_INFO.
|
||||
//
|
||||
const uint32_t g_am_hal_mcuctrl_flash_size[16] =
|
||||
{
|
||||
16 * 1024, /* 0x0 0x00004000 16 KB */
|
||||
32 * 1024, /* 0x1 0x00008000 32 KB */
|
||||
64 * 1024, /* 0x2 0x00010000 64 KB */
|
||||
128 * 1024, /* 0x3 0x00020000 128 KB */
|
||||
256 * 1024, /* 0x4 0x00040000 256 KB */
|
||||
512 * 1024, /* 0x5 0x00080000 512 KB */
|
||||
1 * 1024 * 1024, /* 0x6 0x00100000 1 MB */
|
||||
2 * 1024 * 1024, /* 0x7 0x00200000 2 MB */
|
||||
4 * 1024 * 1024, /* 0x8 0x00400000 4 MB */
|
||||
8 * 1024 * 1024, /* 0x9 0x00800000 8 MB */
|
||||
16 * 1024 * 1024, /* 0xA 0x01000000 16 MB */
|
||||
32 * 1024 * 1024, /* 0xB 0x02000000 32 MB */
|
||||
64 * 1024 * 1024, /* 0xC 0x04000000 64 MB */
|
||||
128 * 1024 * 1024, /* 0xD 0x08000000 128 MB */
|
||||
256 * 1024 * 1024, /* 0xE 0x10000000 256 MB */
|
||||
512 * 1024 * 1024 /* 0xF 0x20000000 512 MB */
|
||||
};
|
||||
|
||||
//
|
||||
// Define the SRAM sizes from CHIP_INFO.
|
||||
// For Apollo2, the SRAM sizes are defined exactly the same as the flash sizes.
|
||||
//
|
||||
#define g_am_hal_mcuctrl_sram_size g_am_hal_mcuctrl_flash_size
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Gets all relevant device information.
|
||||
//!
|
||||
//! @param psDevice is a pointer to a structure that will be used to store all
|
||||
//! device info.
|
||||
//!
|
||||
//! This function gets the device part number, chip IDs, and revision and
|
||||
//! stores them in the passed structure.
|
||||
//!
|
||||
//! @return None
|
||||
//
|
||||
//*****************************************************************************
|
||||
void
|
||||
am_hal_mcuctrl_device_info_get(am_hal_mcuctrl_device_t *psDevice)
|
||||
{
|
||||
//
|
||||
// Read the Part Number.
|
||||
//
|
||||
psDevice->ui32ChipPN = AM_REG(MCUCTRL, CHIP_INFO);
|
||||
|
||||
//
|
||||
// Read the Chip ID0.
|
||||
//
|
||||
psDevice->ui32ChipID0 = AM_REG(MCUCTRL, CHIPID0);
|
||||
|
||||
//
|
||||
// Read the Chip ID1.
|
||||
//
|
||||
psDevice->ui32ChipID1 = AM_REG(MCUCTRL, CHIPID1);
|
||||
|
||||
//
|
||||
// Read the Chip Revision.
|
||||
//
|
||||
psDevice->ui32ChipRev = AM_REG(MCUCTRL, CHIPREV);
|
||||
|
||||
//
|
||||
// Read the Part Number.
|
||||
//
|
||||
psDevice->ui32ChipPN = AM_REG(MCUCTRL, CHIP_INFO);
|
||||
|
||||
//
|
||||
// Read the Chip ID0.
|
||||
//
|
||||
psDevice->ui32ChipID0 = AM_REG(MCUCTRL, CHIPID0);
|
||||
|
||||
//
|
||||
// Read the Chip ID1.
|
||||
//
|
||||
psDevice->ui32ChipID1 = AM_REG(MCUCTRL, CHIPID1);
|
||||
|
||||
//
|
||||
// Read the Chip Revision.
|
||||
//
|
||||
psDevice->ui32ChipRev = AM_REG(MCUCTRL, CHIPREV);
|
||||
|
||||
//
|
||||
// Read the Chip VENDOR ID.
|
||||
//
|
||||
psDevice->ui32VendorID = AM_REG(MCUCTRL, VENDORID);
|
||||
|
||||
//
|
||||
// Qualified from Part Number.
|
||||
//
|
||||
psDevice->ui32Qualified =
|
||||
(psDevice->ui32ChipPN & AM_HAL_MCUCTRL_CHIP_INFO_QUAL_M) >>
|
||||
AM_HAL_MCUCTRL_CHIP_INFO_QUAL_S;
|
||||
|
||||
//
|
||||
// Flash size from Part Number.
|
||||
//
|
||||
psDevice->ui32FlashSize =
|
||||
g_am_hal_mcuctrl_flash_size[
|
||||
(psDevice->ui32ChipPN & AM_HAL_MCUCTRL_CHIP_INFO_FLASH_SIZE_M) >>
|
||||
AM_HAL_MCUCTRL_CHIP_INFO_FLASH_SIZE_S];
|
||||
|
||||
//
|
||||
// SRAM size from Part Number.
|
||||
//
|
||||
psDevice->ui32SRAMSize =
|
||||
g_am_hal_mcuctrl_flash_size[
|
||||
(psDevice->ui32ChipPN & AM_HAL_MCUCTRL_CHIP_INFO_SRAM_SIZE_M) >>
|
||||
AM_HAL_MCUCTRL_CHIP_INFO_SRAM_SIZE_S];
|
||||
|
||||
//
|
||||
// Now, let's look at the JEDEC info.
|
||||
// The full partnumber is 12 bits total, but is scattered across 2 registers.
|
||||
// Bits [11:8] are 0xE.
|
||||
// Bits [7:4] are 0xE for Apollo, 0xD for Apollo2.
|
||||
// Bits [3:0] are defined differently for Apollo and Apollo2.
|
||||
// For Apollo, the low nibble is 0x0.
|
||||
// For Apollo2, the low nibble indicates flash and SRAM size.
|
||||
//
|
||||
psDevice->ui32JedecPN = (AM_BFR(JEDEC, PID0, PNL8) << 0);
|
||||
psDevice->ui32JedecPN |= (AM_BFR(JEDEC, PID1, PNH4) << 8);
|
||||
|
||||
//
|
||||
// JEPID is the JEP-106 Manufacturer ID Code, which is assigned to Ambiq as
|
||||
// 0x1B, with parity bit is 0x9B. It is 8 bits located across 2 registers.
|
||||
//
|
||||
psDevice->ui32JedecJEPID = (AM_BFR(JEDEC, PID1, JEPIDL) << 0);
|
||||
psDevice->ui32JedecJEPID |= (AM_BFR(JEDEC, PID2, JEPIDH) << 4);
|
||||
|
||||
//
|
||||
// CHIPREV is 8 bits located across 2 registers.
|
||||
//
|
||||
psDevice->ui32JedecCHIPREV = (AM_BFR(JEDEC, PID2, CHIPREVH4) << 4);
|
||||
psDevice->ui32JedecCHIPREV |= (AM_BFR(JEDEC, PID3, CHIPREVL4) << 0);
|
||||
|
||||
//
|
||||
// Let's get the Coresight ID (32-bits across 4 registers)
|
||||
// For Apollo and Apollo2, it's expected to be 0xB105100D.
|
||||
//
|
||||
psDevice->ui32JedecCID = (AM_BFR(JEDEC, CID3, CID) << 24);
|
||||
psDevice->ui32JedecCID |= (AM_BFR(JEDEC, CID2, CID) << 16);
|
||||
psDevice->ui32JedecCID |= (AM_BFR(JEDEC, CID1, CID) << 8);
|
||||
psDevice->ui32JedecCID |= (AM_BFR(JEDEC, CID0, CID) << 0);
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Enables the fault capture registers.
|
||||
//!
|
||||
//! This function enables the DCODEFAULTADDR and ICODEFAULTADDR registers.
|
||||
//!
|
||||
//! @return None
|
||||
//
|
||||
//*****************************************************************************
|
||||
void
|
||||
am_hal_mcuctrl_fault_capture_enable(void)
|
||||
{
|
||||
//
|
||||
// Enable the Fault Capture registers.
|
||||
//
|
||||
AM_BFW(MCUCTRL, FAULTCAPTUREEN, ENABLE, 1);
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Disables the fault capture registers.
|
||||
//!
|
||||
//! This function disables the DCODEFAULTADDR and ICODEFAULTADDR registers.
|
||||
//!
|
||||
//! @return None
|
||||
//
|
||||
//*****************************************************************************
|
||||
void
|
||||
am_hal_mcuctrl_fault_capture_disable(void)
|
||||
{
|
||||
//
|
||||
// Disable the Fault Capture registers.
|
||||
//
|
||||
AM_BFW(MCUCTRL, FAULTCAPTUREEN, ENABLE, 0);
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Gets the fault status and capture registers.
|
||||
//!
|
||||
//! @param psFault is a pointer to a structure that will be used to store all
|
||||
//! fault info.
|
||||
//!
|
||||
//! This function gets the status of the ICODE, DCODE, and SYS bus faults and
|
||||
//! the addresses associated with the fault.
|
||||
//!
|
||||
//! @return None
|
||||
//
|
||||
//*****************************************************************************
|
||||
void
|
||||
am_hal_mcuctrl_fault_status(am_hal_mcuctrl_fault_t *psFault)
|
||||
{
|
||||
uint32_t ui32FaultStat;
|
||||
|
||||
//
|
||||
// Read the Fault Status Register.
|
||||
//
|
||||
ui32FaultStat = AM_REG(MCUCTRL, FAULTSTATUS);
|
||||
psFault->bICODE = (ui32FaultStat & AM_REG_MCUCTRL_FAULTSTATUS_ICODE_M);
|
||||
psFault->bDCODE = (ui32FaultStat & AM_REG_MCUCTRL_FAULTSTATUS_DCODE_M);
|
||||
psFault->bSYS = (ui32FaultStat & AM_REG_MCUCTRL_FAULTSTATUS_SYS_M);
|
||||
|
||||
//
|
||||
// Read the DCODE fault capture address register.
|
||||
//
|
||||
psFault->ui32DCODE = AM_REG(MCUCTRL, DCODEFAULTADDR);
|
||||
|
||||
//
|
||||
// Read the ICODE fault capture address register.
|
||||
//
|
||||
psFault->ui32ICODE |= AM_REG(MCUCTRL, ICODEFAULTADDR);
|
||||
|
||||
//
|
||||
// Read the ICODE fault capture address register.
|
||||
//
|
||||
psFault->ui32SYS |= AM_REG(MCUCTRL, SYSFAULTADDR);
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// End Doxygen group.
|
||||
//! @}
|
||||
//
|
||||
//*****************************************************************************
|
||||
@@ -0,0 +1,212 @@
|
||||
//*****************************************************************************
|
||||
//
|
||||
// am_hal_mcuctrl.h
|
||||
//! @file
|
||||
//!
|
||||
//! @brief Functions for accessing and configuring the MCUCTRL.
|
||||
//!
|
||||
//! @addtogroup mcuctrl2 MCU Control (MCUCTRL)
|
||||
//! @ingroup apollo2hal
|
||||
//! @{
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Copyright (c) 2017, Ambiq Micro
|
||||
// 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.
|
||||
//
|
||||
// This is part of revision 1.2.9 of the AmbiqSuite Development Package.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#ifndef AM_HAL_MCUCTRL_H
|
||||
#define AM_HAL_MCUCTRL_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
//
|
||||
// Deprecate the am_hal_mcuctrl_bucks_enable() and disable() functions.
|
||||
// This functionality is now handled in pwrctrl.
|
||||
//
|
||||
#define am_hal_mcuctrl_bucks_enable am_hal_pwrctrl_bucks_enable
|
||||
#define am_hal_mcuctrl_bucks_disable am_hal_pwrctrl_bucks_disable
|
||||
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Define CHIP_INFO fields, which for Apollo2 are not defined in the register
|
||||
// definitions.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define AM_HAL_MCUCTRL_CHIP_INFO_CLASS_M 0xFF000000
|
||||
#define AM_HAL_MCUCTRL_CHIP_INFO_CLASS_S 24
|
||||
#define AM_HAL_MCUCTRL_CHIP_INFO_FLASH_SIZE_M 0x00F00000
|
||||
#define AM_HAL_MCUCTRL_CHIP_INFO_FLASH_SIZE_S 20
|
||||
#define AM_HAL_MCUCTRL_CHIP_INFO_SRAM_SIZE_M 0x000F0000
|
||||
#define AM_HAL_MCUCTRL_CHIP_INFO_SRAM_SIZE_S 16
|
||||
#define AM_HAL_MCUCTRL_CHIP_INFO_REV_M 0x0000FF00
|
||||
#define AM_HAL_MCUCTRL_CHIP_INFO_REV_S 8
|
||||
#define AM_HAL_MCUCTRL_CHIP_INFO_PKG_M 0x000000C0
|
||||
#define AM_HAL_MCUCTRL_CHIP_INFO_PKG_S 6
|
||||
#define AM_HAL_MCUCTRL_CHIP_INFO_PINS_M 0x00000038
|
||||
#define AM_HAL_MCUCTRL_CHIP_INFO_PINS_S 3
|
||||
#define AM_HAL_MCUCTRL_CHIP_INFO_TEMP_M 0x00000006
|
||||
#define AM_HAL_MCUCTRL_CHIP_INFO_TEMP_S 1
|
||||
#define AM_HAL_MCUCTRL_CHIP_INFO_QUAL_M 0x00000001
|
||||
#define AM_HAL_MCUCTRL_CHIP_INFO_QUAL_S 0
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Apollo Number Decode.
|
||||
//
|
||||
//*****************************************************************************
|
||||
extern const uint32_t g_am_hal_mcuctrl_flash_size[];
|
||||
extern const uint32_t g_am_hal_mcuctrl_sram_size[];
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! MCUCTRL device structure
|
||||
//
|
||||
//*****************************************************************************
|
||||
typedef struct
|
||||
{
|
||||
//
|
||||
//! Device part number. (BCD format)
|
||||
//
|
||||
uint32_t ui32ChipPN;
|
||||
|
||||
//
|
||||
//! Unique Chip ID 0.
|
||||
//
|
||||
uint32_t ui32ChipID0;
|
||||
|
||||
//
|
||||
//! Unique Chip ID 1.
|
||||
//
|
||||
uint32_t ui32ChipID1;
|
||||
|
||||
//
|
||||
//! Chip Revision.
|
||||
//
|
||||
uint32_t ui32ChipRev;
|
||||
|
||||
//
|
||||
//! Vendor ID.
|
||||
//
|
||||
uint32_t ui32VendorID;
|
||||
|
||||
//
|
||||
//! Qualified chip.
|
||||
//
|
||||
uint32_t ui32Qualified;
|
||||
|
||||
//
|
||||
//! Flash Size.
|
||||
//
|
||||
uint32_t ui32FlashSize;
|
||||
|
||||
//
|
||||
//! SRAM Size.
|
||||
//
|
||||
uint32_t ui32SRAMSize;
|
||||
|
||||
//
|
||||
// JEDEC chip info
|
||||
//
|
||||
uint32_t ui32JedecPN;
|
||||
uint32_t ui32JedecJEPID;
|
||||
uint32_t ui32JedecCHIPREV;
|
||||
uint32_t ui32JedecCID;
|
||||
}
|
||||
am_hal_mcuctrl_device_t;
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! MCUCTRL fault structure
|
||||
//
|
||||
//*****************************************************************************
|
||||
typedef struct
|
||||
{
|
||||
//
|
||||
//! ICODE bus fault occurred.
|
||||
//
|
||||
bool bICODE;
|
||||
|
||||
//
|
||||
//! ICODE bus fault address.
|
||||
//
|
||||
uint32_t ui32ICODE;
|
||||
|
||||
//
|
||||
//! DCODE bus fault occurred.
|
||||
//
|
||||
bool bDCODE;
|
||||
|
||||
//
|
||||
//! DCODE bus fault address.
|
||||
//
|
||||
uint32_t ui32DCODE;
|
||||
|
||||
//
|
||||
//! SYS bus fault occurred.
|
||||
//
|
||||
bool bSYS;
|
||||
|
||||
//
|
||||
//! SYS bus fault address.
|
||||
//
|
||||
uint32_t ui32SYS;
|
||||
}
|
||||
am_hal_mcuctrl_fault_t;
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// External function definitions
|
||||
//
|
||||
//*****************************************************************************
|
||||
extern void am_hal_mcuctrl_device_info_get(am_hal_mcuctrl_device_t *psDevice);
|
||||
extern void am_hal_mcuctrl_fault_capture_enable(void);
|
||||
extern void am_hal_mcuctrl_fault_capture_disable(void);
|
||||
extern void am_hal_mcuctrl_fault_status(am_hal_mcuctrl_fault_t *psFault);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // AM_HAL_MCUCTRL_H
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// End Doxygen group.
|
||||
//! @}
|
||||
//
|
||||
//*****************************************************************************
|
||||
@@ -0,0 +1,173 @@
|
||||
//*****************************************************************************
|
||||
//
|
||||
// am_hal_otp.c
|
||||
//! @file
|
||||
//!
|
||||
//! @brief Functions for handling the OTP interface.
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Copyright (c) 2017, Ambiq Micro
|
||||
// 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.
|
||||
//
|
||||
// This is part of revision 1.2.9 of the AmbiqSuite Development Package.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#include "am_mcu_apollo.h"
|
||||
#include "am_hal_flash.h"
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! THIS FUNCTION IS DEPRECATED!
|
||||
//! Use the respective HAL flash function instead.
|
||||
//!
|
||||
// @brief Check if debugger is currently locked out.
|
||||
//
|
||||
// @param None.
|
||||
//
|
||||
// Determine if the debugger is already locked out.
|
||||
//
|
||||
// @return non-zero if debugger is currently locked out.
|
||||
// Specifically:
|
||||
// 0 = debugger is not locked out.
|
||||
// 1 = debugger is locked out.
|
||||
//
|
||||
//*****************************************************************************
|
||||
int
|
||||
am_hal_otp_is_debugger_lockedout(void)
|
||||
{
|
||||
return am_hal_flash_debugger_disable_check();
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! THIS FUNCTION IS DEPRECATED!
|
||||
//! Use the respective HAL flash function instead.
|
||||
//!
|
||||
// @brief Lock out debugger access.
|
||||
//
|
||||
// @param None.
|
||||
//
|
||||
// This function locks out access by a debugger.
|
||||
//
|
||||
// @return 0 if lockout was successful or if lockout was already enabled.
|
||||
//
|
||||
//*****************************************************************************
|
||||
int
|
||||
am_hal_otp_debugger_lockout(void)
|
||||
{
|
||||
return am_hal_flash_debugger_disable();
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! THIS FUNCTION IS DEPRECATED!
|
||||
//! Use the respective HAL flash function instead.
|
||||
//!
|
||||
// @brief Lock out SRAM access.
|
||||
//
|
||||
// @param None.
|
||||
//
|
||||
// This function locks out access by a debugger to SRAM.
|
||||
//
|
||||
// @return 0 if lockout was successful or if lockout was already enabled.
|
||||
// Low byte=0xff, byte 1 contains current value of lockout.
|
||||
// Else, return value from HAL programming function.
|
||||
//
|
||||
//*****************************************************************************
|
||||
int
|
||||
am_hal_otp_sram_lockout(void)
|
||||
{
|
||||
return am_hal_flash_wipe_sram_enable();
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! THIS FUNCTION IS DEPRECATED!
|
||||
//! Use the respective HAL flash function instead.
|
||||
//!
|
||||
// @brief Set copy (read) protection.
|
||||
//
|
||||
// @param @u32BegAddr The beginning address to be copy protected.
|
||||
// @u32EndAddr The ending address to be copy protected.
|
||||
//
|
||||
// @note For Apollo, the u32BegAddr parameter should be on a 16KB boundary, and
|
||||
// the u32EndAddr parameter should be on a (16KB-1) boundary. Otherwise
|
||||
// both parameters will be truncated/expanded to do so.
|
||||
// For example, if u32BegAddr=0x1000 and u32EndAddr=0xC200, the actual
|
||||
// range that protected is: 0x0 - 0xFFFF.
|
||||
//
|
||||
// This function enables copy protection on a given flash address range.
|
||||
//
|
||||
// @return 0 if copy protection was successfully enabled.
|
||||
//
|
||||
//*****************************************************************************
|
||||
int
|
||||
am_hal_otp_set_copy_protection(uint32_t u32BegAddr, uint32_t u32EndAddr)
|
||||
{
|
||||
return am_hal_flash_copy_protect_set((uint32_t*)u32BegAddr,
|
||||
(uint32_t*)u32EndAddr);
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! THIS FUNCTION IS DEPRECATED!
|
||||
//! Use the respective HAL flash function instead.
|
||||
//!
|
||||
// @brief Set write protection.
|
||||
//
|
||||
// @param @u32BegAddr The beginning address to be write protected.
|
||||
// @u32EndAddr The ending address to be write protected.
|
||||
//
|
||||
// @note For Apollo, the u32BegAddr parameter should be on a 16KB boundary, and
|
||||
// the u32EndAddr parameter should be on a (16KB-1) boundary. Otherwise
|
||||
// both parameters will be truncated/expanded to do so.
|
||||
// For example, if u32BegAddr=0x1000 and u32EndAddr=0xC200, the actual
|
||||
// range that protected is: 0x0 - 0xFFFF.
|
||||
//
|
||||
// This function enables write protection on a given flash address range.
|
||||
//
|
||||
// @return 0 if write protection was successfully enabled.
|
||||
//
|
||||
//*****************************************************************************
|
||||
int
|
||||
am_hal_otp_set_write_protection(uint32_t u32BegAddr, uint32_t u32EndAddr)
|
||||
{
|
||||
return am_hal_flash_write_protect_set((uint32_t*)u32BegAddr,
|
||||
(uint32_t*)u32EndAddr);
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// End Doxygen group.
|
||||
//! @}
|
||||
//
|
||||
//*****************************************************************************
|
||||
@@ -0,0 +1,108 @@
|
||||
//*****************************************************************************
|
||||
//
|
||||
// am_hal_otp.h
|
||||
//! @file
|
||||
//!
|
||||
//! @brief Functions for handling the OTP interface.
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Copyright (c) 2017, Ambiq Micro
|
||||
// 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.
|
||||
//
|
||||
// This is part of revision 1.2.9 of the AmbiqSuite Development Package.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#ifndef AM_HAL_OTP_H
|
||||
#define AM_HAL_OTP_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Define some OTP values and macros.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define AM_HAL_OTP_SIG0 0x00
|
||||
#define AM_HAL_OTP_SIG1 0x04
|
||||
#define AM_HAL_OTP_SIG2 0x08
|
||||
#define AM_HAL_OTP_SIG3 0x0C
|
||||
|
||||
#define AM_HAL_OTP_DBGR_O 0x10
|
||||
#define AM_HAL_OTP_WRITPROT0_O 0x20
|
||||
#define AM_HAL_OTP_WRITPROT1_O 0x24
|
||||
#define AM_HAL_OTP_COPYPROT0_O 0x30
|
||||
#define AM_HAL_OTP_COPYPROT1_O 0x34
|
||||
|
||||
#define AM_HAL_OTP_ADDR 0x50020000
|
||||
#define AM_HAL_OTP_DBGRPROT_ADDR (AM_HAL_OTP_ADDR + AM_HAL_OTP_DBGR_O)
|
||||
#define AM_HAL_OTP_WRITPROT_ADDR (AM_HAL_OTP_ADDR + AM_HAL_OTP_WRITPROT0_O)
|
||||
#define AM_HAL_OTP_COPYPROT_ADDR (AM_HAL_OTP_ADDR + AM_HAL_OTP_COPYPROT0_O)
|
||||
|
||||
#define AM_HAL_OTP_CHUNKSIZE (16*1024)
|
||||
|
||||
//
|
||||
// Debugger port lockout macros.
|
||||
//
|
||||
#define AM_OTP_DBGR_LOCKOUT_S (0)
|
||||
#define AM_OTP_DBGR_LOCKOUT_M (0x1 << AM_OTP_DBGR_LOCKOUT_S)
|
||||
#define AM_OTP_STRM_LOCKOUT_S (1)
|
||||
#define AM_OTP_STRM_LOCKOUT_M (0x1 << AM_OTP_STRM_LOCKOUT_S)
|
||||
#define AM_OTP_SRAM_LOCKOUT_S (2)
|
||||
#define AM_OTP_SRAM_LOCKOUT_M (0x1 << AM_OTP_SRAM_LOCKOUT_S)
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Function prototypes
|
||||
//
|
||||
//*****************************************************************************
|
||||
extern int am_hal_otp_is_debugger_lockedout(void);
|
||||
extern int am_hal_otp_debugger_lockout(void);
|
||||
extern int am_hal_otp_sram_lockout(void);
|
||||
extern int am_hal_otp_set_copy_protection(uint32_t u32BegAddr, uint32_t u32EndAddr);
|
||||
extern int am_hal_otp_set_write_protection(uint32_t u32BegAddr, uint32_t u32EndAddr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // AM_HAL_OTP_H
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// End Doxygen group.
|
||||
//! @}
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
@@ -0,0 +1,158 @@
|
||||
//*****************************************************************************
|
||||
//
|
||||
// am_hal_pdm.c
|
||||
//! @file
|
||||
//!
|
||||
//! @brief Functions for interfacing with Pulse Density Modulation (PDM).
|
||||
//!
|
||||
//! @addtogroup pdm2 DMEMS Microphon3 (PDM)
|
||||
//! @ingroup apollo2hal
|
||||
//! @{
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Copyright (c) 2017, Ambiq Micro
|
||||
// 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.
|
||||
//
|
||||
// This is part of revision 1.2.9 of the AmbiqSuite Development Package.
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "am_mcu_apollo.h"
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Configure the PDM module.
|
||||
//!
|
||||
//! This function reads the an \e am_hal_pdm_config_t structure and uses it to
|
||||
//! set up the PDM module.
|
||||
//!
|
||||
//! Please see the information on the am_hal_pdm_config_t configuration
|
||||
//! structure, found in am_hal_pdm.h, for more information on the parameters
|
||||
//! that may be set by this function.
|
||||
//!
|
||||
//! @return None.
|
||||
//
|
||||
//*****************************************************************************
|
||||
void
|
||||
am_hal_pdm_config(am_hal_pdm_config_t *psConfig)
|
||||
{
|
||||
//
|
||||
// setup the PDM PCFG register
|
||||
//
|
||||
AM_REG(PDM, PCFG) = psConfig->ui32PDMConfigReg;
|
||||
|
||||
//
|
||||
// setup the PDM VCFG register
|
||||
//
|
||||
AM_REG(PDM, VCFG) = psConfig->ui32VoiceConfigReg;
|
||||
|
||||
//
|
||||
// setup the PDM FIFO Threshold register
|
||||
//
|
||||
AM_REG(PDM, FTHR) = psConfig->ui32FIFOThreshold;
|
||||
|
||||
//
|
||||
// Flush the FIFO for good measure.
|
||||
//
|
||||
am_hal_pdm_fifo_flush();
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Enable the PDM module.
|
||||
//!
|
||||
//! This function enables the PDM module in the mode previously defined by
|
||||
//! am_hal_pdm_config().
|
||||
//!
|
||||
//! @return None.
|
||||
//
|
||||
//*****************************************************************************
|
||||
void
|
||||
am_hal_pdm_enable(void)
|
||||
{
|
||||
AM_REG(PDM, PCFG) |= AM_REG_PDM_PCFG_PDMCORE_EN;
|
||||
AM_REG(PDM, VCFG) |= ( AM_REG_PDM_VCFG_IOCLKEN_EN |
|
||||
AM_REG_PDM_VCFG_PDMCLK_EN |
|
||||
AM_REG_PDM_VCFG_RSTB_NORM );
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Disable the PDM module.
|
||||
//!
|
||||
//! This function disables the PDM module.
|
||||
//!
|
||||
//! @return None.
|
||||
//
|
||||
//*****************************************************************************
|
||||
void
|
||||
am_hal_pdm_disable(void)
|
||||
{
|
||||
AM_REG(PDM, PCFG) &= ~ AM_REG_PDM_PCFG_PDMCORE_EN;
|
||||
AM_REG(PDM, VCFG) &= ~ ( AM_REG_PDM_VCFG_IOCLKEN_EN |
|
||||
AM_REG_PDM_VCFG_PDMCLK_EN |
|
||||
AM_REG_PDM_VCFG_RSTB_NORM );
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Return the PDM Interrupt status.
|
||||
//!
|
||||
//! @param bEnabledOnly - return only the enabled interrupts.
|
||||
//!
|
||||
//! Use this function to get the PDM interrupt status.
|
||||
//!
|
||||
//! @return intrrupt status
|
||||
//
|
||||
//*****************************************************************************
|
||||
uint32_t
|
||||
am_hal_pdm_int_status_get(bool bEnabledOnly)
|
||||
{
|
||||
if ( bEnabledOnly )
|
||||
{
|
||||
uint32_t u32RetVal = AM_REG(PDM, INTSTAT);
|
||||
return u32RetVal & AM_REG(PDM, INTEN);
|
||||
}
|
||||
else
|
||||
{
|
||||
return AM_REG(PDM, INTSTAT);
|
||||
}
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// End the doxygen group
|
||||
//! @}
|
||||
//
|
||||
//*****************************************************************************
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,342 @@
|
||||
//*****************************************************************************
|
||||
//
|
||||
// am_hal_pwrctrl.h
|
||||
//! @file
|
||||
//!
|
||||
//! @brief Functions for enabling and disabling power domains.
|
||||
//!
|
||||
//! @addtogroup pwrctrl2 Power Control
|
||||
//! @ingroup apollo2hal
|
||||
//! @{
|
||||
|
||||
//*****************************************************************************
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Copyright (c) 2017, Ambiq Micro
|
||||
// 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.
|
||||
//
|
||||
// This is part of revision 1.2.9 of the AmbiqSuite Development Package.
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
#ifndef AM_HAL_PWRCTRL_H
|
||||
#define AM_HAL_PWRCTRL_H
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Peripheral enable bits for am_hal_pwrctrl_periph_enable/disable()
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define AM_HAL_PWRCTRL_ADC AM_REG_PWRCTRL_DEVICEEN_ADC_EN
|
||||
#define AM_HAL_PWRCTRL_IOM0 AM_REG_PWRCTRL_DEVICEEN_IO_MASTER0_EN
|
||||
#define AM_HAL_PWRCTRL_IOM1 AM_REG_PWRCTRL_DEVICEEN_IO_MASTER1_EN
|
||||
#define AM_HAL_PWRCTRL_IOM2 AM_REG_PWRCTRL_DEVICEEN_IO_MASTER2_EN
|
||||
#define AM_HAL_PWRCTRL_IOM3 AM_REG_PWRCTRL_DEVICEEN_IO_MASTER3_EN
|
||||
#define AM_HAL_PWRCTRL_IOM4 AM_REG_PWRCTRL_DEVICEEN_IO_MASTER4_EN
|
||||
#define AM_HAL_PWRCTRL_IOM5 AM_REG_PWRCTRL_DEVICEEN_IO_MASTER5_EN
|
||||
#define AM_HAL_PWRCTRL_IOS AM_REG_PWRCTRL_DEVICEEN_IO_SLAVE_EN
|
||||
#define AM_HAL_PWRCTRL_PDM AM_REG_PWRCTRL_DEVICEEN_PDM_EN
|
||||
#define AM_HAL_PWRCTRL_UART0 AM_REG_PWRCTRL_DEVICEEN_UART0_EN
|
||||
#define AM_HAL_PWRCTRL_UART1 AM_REG_PWRCTRL_DEVICEEN_UART1_EN
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Macro to set the appropriate IOM peripheral when using
|
||||
// am_hal_pwrctrl_periph_enable()/disable().
|
||||
// For Apollo2, the module argument must resolve to be a value from 0-5.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define AM_HAL_PWRCTRL_IOM(module) \
|
||||
(AM_REG_PWRCTRL_DEVICEEN_IO_MASTER0_EN << module)
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Macro to set the appropriate UART peripheral when using
|
||||
// am_hal_pwrctrl_periph_enable()/disable().
|
||||
// For Apollo2, the module argument must resolve to be a value from 0-1.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define AM_HAL_PWRCTRL_UART(module) \
|
||||
(AM_REG_PWRCTRL_DEVICEEN_UART0_EN << module)
|
||||
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Memory enable values for am_hal_pwrctrl_memory_enable()
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define AM_HAL_PWRCTRL_MEMEN_SRAM8K AM_REG_PWRCTRL_MEMEN_SRAMEN_SRAM8K
|
||||
#define AM_HAL_PWRCTRL_MEMEN_SRAM16K AM_REG_PWRCTRL_MEMEN_SRAMEN_SRAM16K
|
||||
#define AM_HAL_PWRCTRL_MEMEN_SRAM24K (AM_REG_PWRCTRL_MEMEN_SRAMEN_SRAM16K | \
|
||||
AM_REG_PWRCTRL_MEMEN_SRAMEN_GROUP0_SRAM2)
|
||||
#define AM_HAL_PWRCTRL_MEMEN_SRAM32K AM_REG_PWRCTRL_MEMEN_SRAMEN_SRAM32K
|
||||
#define AM_HAL_PWRCTRL_MEMEN_SRAM64K AM_REG_PWRCTRL_MEMEN_SRAMEN_SRAM64K
|
||||
#define AM_HAL_PWRCTRL_MEMEN_SRAM96K \
|
||||
(AM_REG_PWRCTRL_MEMEN_SRAMEN_SRAM64K | \
|
||||
AM_REG_PWRCTRL_MEMEN_SRAMEN_GROUP2)
|
||||
#define AM_HAL_PWRCTRL_MEMEN_SRAM128K AM_REG_PWRCTRL_MEMEN_SRAMEN_SRAM128K
|
||||
#define AM_HAL_PWRCTRL_MEMEN_SRAM160K \
|
||||
(AM_REG_PWRCTRL_MEMEN_SRAMEN_SRAM128K | \
|
||||
AM_REG_PWRCTRL_MEMEN_SRAMEN_GROUP4)
|
||||
#define AM_HAL_PWRCTRL_MEMEN_SRAM192K \
|
||||
(AM_REG_PWRCTRL_MEMEN_SRAMEN_SRAM128K | \
|
||||
AM_REG_PWRCTRL_MEMEN_SRAMEN_GROUP4 | \
|
||||
AM_REG_PWRCTRL_MEMEN_SRAMEN_GROUP5)
|
||||
#define AM_HAL_PWRCTRL_MEMEN_SRAM224K \
|
||||
(AM_REG_PWRCTRL_MEMEN_SRAMEN_SRAM128K | \
|
||||
AM_REG_PWRCTRL_MEMEN_SRAMEN_GROUP4 | \
|
||||
AM_REG_PWRCTRL_MEMEN_SRAMEN_GROUP5 | \
|
||||
AM_REG_PWRCTRL_MEMEN_SRAMEN_GROUP6)
|
||||
#define AM_HAL_PWRCTRL_MEMEN_SRAM256K AM_REG_PWRCTRL_MEMEN_SRAMEN_SRAM256K
|
||||
|
||||
#define AM_HAL_PWRCTRL_MEMEN_FLASH512K AM_REG_PWRCTRL_MEMEN_FLASH0_EN
|
||||
#define AM_HAL_PWRCTRL_MEMEN_FLASH1M \
|
||||
(AM_REG_PWRCTRL_MEMEN_FLASH0_EN | \
|
||||
AM_REG_PWRCTRL_MEMEN_FLASH1_EN)
|
||||
#define AM_HAL_PWRCTRL_MEMEN_CACHE \
|
||||
(AM_REG_PWRCTRL_MEMEN_CACHEB0_EN | \
|
||||
AM_REG_PWRCTRL_MEMEN_CACHEB2_EN)
|
||||
#define AM_HAL_PWRCTRL_MEMEN_CACHE_DIS \
|
||||
~(AM_REG_PWRCTRL_MEMEN_CACHEB0_EN | \
|
||||
AM_REG_PWRCTRL_MEMEN_CACHEB2_EN)
|
||||
|
||||
//
|
||||
// Power up all available memory devices (this is the default power up state)
|
||||
//
|
||||
#define AM_HAL_PWRCTRL_MEMEN_ALL \
|
||||
(AM_REG_PWRCTRL_MEMEN_SRAMEN_ALL | \
|
||||
AM_REG_PWRCTRL_MEMEN_FLASH0_EN | \
|
||||
AM_REG_PWRCTRL_MEMEN_FLASH1_EN | \
|
||||
AM_REG_PWRCTRL_MEMEN_CACHEB0_EN | \
|
||||
AM_REG_PWRCTRL_MEMEN_CACHEB2_EN)
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Peripheral power enable and disable delays
|
||||
// The delay counts are based on an internal clock that runs at half of
|
||||
// HFRC. Therefore, we need to double the delay cycles.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define AM_HAL_PWRCTRL_DEVICEEN_DELAYCYCLES (22 * 2)
|
||||
#define AM_HAL_PWRCTRL_DEVICEDIS_DELAYCYCLES (22 * 2)
|
||||
|
||||
//
|
||||
// Use the following only when enabling after sleep (not during initialization).
|
||||
//
|
||||
#define AM_HAL_PWRCTRL_BUCKEN_DELAYCYCLES (0 * 2)
|
||||
#define AM_HAL_PWRCTRL_BUCKDIS_DELAYCYCLES (15 * 2)
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Peripheral PWRONSTATUS groupings.
|
||||
//
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Group DEVICEEN bits (per PWRONSTATUS groupings).
|
||||
//
|
||||
#define AM_HAL_PWRCTRL_DEVICEEN_IOM_0_2 \
|
||||
(AM_REG_PWRCTRL_DEVICEEN_IO_MASTER0_EN | \
|
||||
AM_REG_PWRCTRL_DEVICEEN_IO_MASTER1_EN | \
|
||||
AM_REG_PWRCTRL_DEVICEEN_IO_MASTER2_EN )
|
||||
|
||||
#define AM_HAL_PWRCTRL_DEVICEEN_IOM_3_5 \
|
||||
(AM_REG_PWRCTRL_DEVICEEN_IO_MASTER3_EN | \
|
||||
AM_REG_PWRCTRL_DEVICEEN_IO_MASTER4_EN | \
|
||||
AM_REG_PWRCTRL_DEVICEEN_IO_MASTER5_EN )
|
||||
|
||||
#define AM_HAL_PWRCTRL_DEVICEEN_IOS_UARTS \
|
||||
(AM_REG_PWRCTRL_DEVICEEN_UART0_EN | \
|
||||
AM_REG_PWRCTRL_DEVICEEN_UART1_EN | \
|
||||
AM_REG_PWRCTRL_DEVICEEN_IO_SLAVE_EN )
|
||||
|
||||
#define AM_HAL_PWRCTRL_DEVICEEN_ADC AM_REG_PWRCTRL_DEVICEEN_ADC_EN
|
||||
#define AM_HAL_PWRCTRL_DEVICEEN_PDM AM_REG_PWRCTRL_DEVICEEN_PDM_EN
|
||||
|
||||
//
|
||||
// Map PWRONSTATUS bits to peripheral groupings.
|
||||
//
|
||||
#define AM_HAL_PWRCTRL_PWRONSTATUS_IOS_UARTS AM_REG_PWRCTRL_PWRONSTATUS_PDA_M
|
||||
#define AM_HAL_PWRCTRL_PWRONSTATUS_IOM_3_5 AM_REG_PWRCTRL_PWRONSTATUS_PDC_M
|
||||
#define AM_HAL_PWRCTRL_PWRONSTATUS_IOM_0_2 AM_REG_PWRCTRL_PWRONSTATUS_PDB_M
|
||||
#define AM_HAL_PWRCTRL_PWRONSTATUS_ADC AM_REG_PWRCTRL_PWRONSTATUS_PDADC_M
|
||||
#define AM_HAL_PWRCTRL_PWRONSTATUS_PDM AM_REG_PWRCTRL_PWRONSTATUS_PD_PDM_M
|
||||
|
||||
#define POLL_PWRSTATUS(ui32Peripheral) \
|
||||
if ( 1 ) \
|
||||
{ \
|
||||
uint32_t ui32PwrOnStat; \
|
||||
if ( ui32Peripheral & AM_HAL_PWRCTRL_DEVICEEN_IOM_0_2 ) \
|
||||
{ \
|
||||
ui32PwrOnStat = AM_HAL_PWRCTRL_PWRONSTATUS_IOM_0_2; \
|
||||
} \
|
||||
else if ( ui32Peripheral & AM_HAL_PWRCTRL_DEVICEEN_IOM_3_5 ) \
|
||||
{ \
|
||||
ui32PwrOnStat = AM_HAL_PWRCTRL_PWRONSTATUS_IOM_3_5; \
|
||||
} \
|
||||
else if ( ui32Peripheral & AM_HAL_PWRCTRL_DEVICEEN_IOS_UARTS ) \
|
||||
{ \
|
||||
ui32PwrOnStat = AM_HAL_PWRCTRL_PWRONSTATUS_IOS_UARTS; \
|
||||
} \
|
||||
else if ( ui32Peripheral & AM_HAL_PWRCTRL_DEVICEEN_ADC ) \
|
||||
{ \
|
||||
ui32PwrOnStat = AM_HAL_PWRCTRL_PWRONSTATUS_ADC; \
|
||||
} \
|
||||
else if ( ui32Peripheral & AM_HAL_PWRCTRL_DEVICEEN_PDM ) \
|
||||
{ \
|
||||
ui32PwrOnStat = AM_HAL_PWRCTRL_PWRONSTATUS_PDM; \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
ui32PwrOnStat = 0xFFFFFFFF; \
|
||||
} \
|
||||
\
|
||||
/* */ \
|
||||
/* Wait for the power control setting to take effect. */ \
|
||||
/* */ \
|
||||
while ( !(AM_REG(PWRCTRL, PWRONSTATUS) & ui32PwrOnStat) ); \
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Memory PWRONSTATUS enable values for am_hal_pwrctrl_memory_enable()
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define AM_HAL_PWRCTRL_PWRONSTATUS_SRAM_8K \
|
||||
AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP0_SRAM0_M
|
||||
|
||||
#define AM_HAL_PWRCTRL_PWRONSTATUS_SRAM_16K \
|
||||
(AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP0_SRAM1_M | \
|
||||
AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP0_SRAM0_M)
|
||||
|
||||
#define AM_HAL_PWRCTRL_PWRONSTATUS_SRAM_24K \
|
||||
(AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP0_SRAM2_M | \
|
||||
AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP0_SRAM1_M | \
|
||||
AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP0_SRAM0_M)
|
||||
|
||||
#define AM_HAL_PWRCTRL_PWRONSTATUS_SRAM_32K \
|
||||
(AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP0_SRAM3_M | \
|
||||
AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP0_SRAM2_M | \
|
||||
AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP0_SRAM1_M | \
|
||||
AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP0_SRAM0_M)
|
||||
|
||||
#define AM_HAL_PWRCTRL_PWRONSTATUS_SRAM_64K \
|
||||
(AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP1_SRAM_M | \
|
||||
AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP0_SRAM3_M | \
|
||||
AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP0_SRAM2_M | \
|
||||
AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP0_SRAM1_M | \
|
||||
AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP0_SRAM0_M)
|
||||
|
||||
#define AM_HAL_PWRCTRL_PWRONSTATUS_SRAM_96K \
|
||||
(AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP2_SRAM_M | \
|
||||
AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP1_SRAM_M | \
|
||||
AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP0_SRAM3_M | \
|
||||
AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP0_SRAM2_M | \
|
||||
AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP0_SRAM1_M | \
|
||||
AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP0_SRAM0_M)
|
||||
|
||||
#define AM_HAL_PWRCTRL_PWRONSTATUS_SRAM_128K \
|
||||
(AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP3_SRAM_M | \
|
||||
AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP2_SRAM_M | \
|
||||
AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP1_SRAM_M | \
|
||||
AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP0_SRAM3_M | \
|
||||
AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP0_SRAM2_M | \
|
||||
AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP0_SRAM1_M | \
|
||||
AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP0_SRAM0_M)
|
||||
|
||||
#define AM_HAL_PWRCTRL_PWRONSTATUS_SRAM_160K \
|
||||
(AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP4_SRAM_M | \
|
||||
AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP3_SRAM_M | \
|
||||
AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP2_SRAM_M | \
|
||||
AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP1_SRAM_M | \
|
||||
AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP0_SRAM3_M | \
|
||||
AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP0_SRAM2_M | \
|
||||
AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP0_SRAM1_M | \
|
||||
AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP0_SRAM0_M)
|
||||
|
||||
#define AM_HAL_PWRCTRL_PWRONSTATUS_SRAM_192K \
|
||||
(AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP5_SRAM_M | \
|
||||
AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP4_SRAM_M | \
|
||||
AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP3_SRAM_M | \
|
||||
AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP2_SRAM_M | \
|
||||
AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP1_SRAM_M | \
|
||||
AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP0_SRAM3_M | \
|
||||
AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP0_SRAM2_M | \
|
||||
AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP0_SRAM1_M | \
|
||||
AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP0_SRAM0_M)
|
||||
|
||||
#define AM_HAL_PWRCTRL_PWRONSTATUS_SRAM_224K \
|
||||
(AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP6_SRAM_M | \
|
||||
AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP5_SRAM_M | \
|
||||
AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP4_SRAM_M | \
|
||||
AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP3_SRAM_M | \
|
||||
AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP2_SRAM_M | \
|
||||
AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP1_SRAM_M | \
|
||||
AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP0_SRAM3_M | \
|
||||
AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP0_SRAM2_M | \
|
||||
AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP0_SRAM1_M | \
|
||||
AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP0_SRAM0_M)
|
||||
|
||||
#define AM_HAL_PWRCTRL_PWRONSTATUS_SRAM_256K \
|
||||
(AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP7_SRAM_M | \
|
||||
AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP6_SRAM_M | \
|
||||
AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP5_SRAM_M | \
|
||||
AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP4_SRAM_M | \
|
||||
AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP3_SRAM_M | \
|
||||
AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP2_SRAM_M | \
|
||||
AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP1_SRAM_M | \
|
||||
AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP0_SRAM3_M | \
|
||||
AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP0_SRAM2_M | \
|
||||
AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP0_SRAM1_M | \
|
||||
AM_REG_PWRCTRL_PWRONSTATUS_PD_GRP0_SRAM0_M)
|
||||
|
||||
#define AM_HAL_PWRCTRL_PWRONSTATUS_SRAM_ALL \
|
||||
AM_HAL_PWRCTRL_PWRONSTATUS_SRAM_256K
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Function prototypes
|
||||
//
|
||||
//*****************************************************************************
|
||||
extern void am_hal_pwrctrl_periph_enable(uint32_t ui32Peripheral);
|
||||
extern void am_hal_pwrctrl_periph_disable(uint32_t ui32Peripheral);
|
||||
extern bool am_hal_pwrctrl_memory_enable(uint32_t ui32MemEn);
|
||||
extern void am_hal_pwrctrl_bucks_init(void);
|
||||
extern void am_hal_pwrctrl_bucks_enable(void);
|
||||
extern void am_hal_pwrctrl_bucks_disable(void);
|
||||
extern void am_hal_pwrctrl_low_power_init(void);
|
||||
|
||||
#endif // AM_HAL_PWRCTRL_H
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// End Doxygen group.
|
||||
//! @}
|
||||
//
|
||||
//*****************************************************************************
|
||||
@@ -0,0 +1,286 @@
|
||||
//*****************************************************************************
|
||||
//
|
||||
// am_hal_queue.c
|
||||
//! @file
|
||||
//!
|
||||
//! @brief Functions for implementing a queue system.
|
||||
//!
|
||||
//! @addtogroup Miscellaneous2 Software Features (MISC)
|
||||
//! @ingroup apollo2hal
|
||||
//! @{
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Copyright (c) 2017, Ambiq Micro
|
||||
// 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.
|
||||
//
|
||||
// This is part of revision 1.2.9 of the AmbiqSuite Development Package.
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "am_mcu_apollo.h"
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Initializes a queue.
|
||||
//!
|
||||
//! @param psQueue - Pointer to a queue structure.
|
||||
//! @param pvData - Pointer to a memory location to be used for data storage.
|
||||
//! @param ui32ItemSize - Number of bytes per item in the queue.
|
||||
//! @param ui32ArraySize - Number of bytes in the data array.
|
||||
//!
|
||||
//! This function initializes the members of a queue structure and attaches it
|
||||
//! to an array of memory that it can use for storage. This function should be
|
||||
//! called before the queue is used.
|
||||
//!
|
||||
//! In this example, we are creating a queue that can hold 1024 32-bit
|
||||
//! integers. The integers themselves will be stored in the array named
|
||||
//! pui32WorkingSpace, while information about the queue itself will be stored
|
||||
//! in sDataQueue.
|
||||
//!
|
||||
//! @note The caller should not modify any of the members of am_hal_queue_t
|
||||
//! structures. The queue API will handle these members in a thread-safe way.
|
||||
//!
|
||||
//! @note The queue will remember what size data is in it. Other queue API
|
||||
//! functions will perform transfers in units of "items" where one "item" is
|
||||
//! the number of bytes you specify in the \e ui32ItemSize argument upon
|
||||
//! initialization.
|
||||
//!
|
||||
//! Example usage:
|
||||
//!
|
||||
//! @code
|
||||
//!
|
||||
//! //
|
||||
//! // Declare a queue structure and an array of bytes we can use to store
|
||||
//! // data.
|
||||
//! //
|
||||
//! am_hal_queue_t sDataQueue;
|
||||
//! uint32_t pui32WorkingSpace[1024];
|
||||
//!
|
||||
//! //
|
||||
//! // Attach the queue structure to the working memory.
|
||||
//! //
|
||||
//! am_hal_queue_init(&sDataQueue, pui8WorkingSpace, sizeof(uint32_t)
|
||||
//! sizeof(pui32WorkingSpace));
|
||||
//!
|
||||
//! @endcode
|
||||
//!
|
||||
//! The am_hal_queue_from_array macro is a convenient shorthand for this
|
||||
//! operation. The code below does the same thing as the code above.
|
||||
//!
|
||||
//! @code
|
||||
//!
|
||||
//! //
|
||||
//! // Declare a queue structure and an array of bytes we can use to store
|
||||
//! // data.
|
||||
//! //
|
||||
//! am_hal_queue_t sDataQueue;
|
||||
//! uint32_t pui32WorkingSpace[1024];
|
||||
//!
|
||||
//! //
|
||||
//! // Attach the queue structure to the working memory.
|
||||
//! //
|
||||
//! am_hal_queue_from_array(&sDataQueue, pui8WorkingSpace);
|
||||
//!
|
||||
//! @endcode
|
||||
//
|
||||
//*****************************************************************************
|
||||
void
|
||||
am_hal_queue_init(am_hal_queue_t *psQueue, void *pvData, uint32_t ui32ItemSize,
|
||||
uint32_t ui32ArraySize)
|
||||
{
|
||||
psQueue->ui32WriteIndex = 0;
|
||||
psQueue->ui32ReadIndex = 0;
|
||||
psQueue->ui32Length = 0;
|
||||
psQueue->ui32Capacity = ui32ArraySize;
|
||||
psQueue->ui32ItemSize = ui32ItemSize;
|
||||
psQueue->pui8Data = (uint8_t *) pvData;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Adds an item to the Queue
|
||||
//!
|
||||
//! @param psQueue - Pointer to a queue structure.
|
||||
//! @param pvSource - Pointer to the data to be added.
|
||||
//! @param ui32NumItems - Number of items to be added.
|
||||
//!
|
||||
//! This function will copy the data pointed to by pvSource into the queue. The
|
||||
//! \e ui32NumItems term specifies the number of items to be copied from \e
|
||||
//! pvSource. The size of an "item" depends on how the queue was initialized.
|
||||
//! Please see am_hal_queue_init() for more information on this.
|
||||
//!
|
||||
//! @return true if the add operation was successful, or false if the queue
|
||||
//! didn't have enough space.
|
||||
//
|
||||
//*****************************************************************************
|
||||
bool
|
||||
am_hal_queue_item_add(am_hal_queue_t *psQueue, const void *pvSource, uint32_t ui32NumItems)
|
||||
{
|
||||
uint32_t i;
|
||||
uint8_t *pui8Source;
|
||||
uint32_t ui32Bytes = ui32NumItems * psQueue->ui32ItemSize;
|
||||
bool bSuccess = false;
|
||||
uint32_t ui32Primask;
|
||||
|
||||
pui8Source = (uint8_t *) pvSource;
|
||||
|
||||
ui32Primask = am_hal_interrupt_master_disable();
|
||||
|
||||
//
|
||||
// Check to make sure that the buffer isn't already full
|
||||
//
|
||||
if ( am_hal_queue_space_left(psQueue) >= ui32Bytes )
|
||||
{
|
||||
//
|
||||
// Loop over the bytes in the source array.
|
||||
//
|
||||
for ( i = 0; i < ui32Bytes; i++ )
|
||||
{
|
||||
//
|
||||
// Write the value to the buffer.
|
||||
//
|
||||
psQueue->pui8Data[psQueue->ui32WriteIndex] = pui8Source[i];
|
||||
|
||||
//
|
||||
// Advance the write index, making sure to wrap if necessary.
|
||||
//
|
||||
psQueue->ui32WriteIndex = ((psQueue->ui32WriteIndex + 1) %
|
||||
psQueue->ui32Capacity);
|
||||
}
|
||||
|
||||
//
|
||||
// Update the length value appropriately.
|
||||
//
|
||||
psQueue->ui32Length += ui32Bytes;
|
||||
|
||||
//
|
||||
// Report a success.
|
||||
//
|
||||
bSuccess = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// The buffer can't fit the amount of data requested. Return a
|
||||
// failure.
|
||||
//
|
||||
bSuccess = false;
|
||||
}
|
||||
|
||||
am_hal_interrupt_master_set(ui32Primask);
|
||||
|
||||
return bSuccess;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Removes an item from the Queue
|
||||
//!
|
||||
//! @param psQueue - Pointer to a queue structure.
|
||||
//! @param pvDest - Pointer to the data to be added.
|
||||
//! @param ui32NumItems - Number of items to be added.
|
||||
//!
|
||||
//! This function will copy the data from the queue into the memory pointed to
|
||||
//! by pvDest. The \e ui32NumItems term specifies the number of items to be
|
||||
//! copied from the queue. The size of an "item" depends on how the queue was
|
||||
//! initialized. Please see am_hal_queue_init() for more information on this.
|
||||
//!
|
||||
//! @return true if we were able to pull the requested number of items from the
|
||||
//! queue, or false if the queue didn't have that many items to pull.
|
||||
//
|
||||
//*****************************************************************************
|
||||
bool
|
||||
am_hal_queue_item_get(am_hal_queue_t *psQueue, void *pvDest, uint32_t ui32NumItems)
|
||||
{
|
||||
uint32_t i;
|
||||
uint8_t *pui8Dest;
|
||||
uint32_t ui32Bytes = ui32NumItems * psQueue->ui32ItemSize;
|
||||
bool bSuccess = false;
|
||||
uint32_t ui32Primask;
|
||||
|
||||
pui8Dest = (uint8_t *) pvDest;
|
||||
|
||||
ui32Primask = am_hal_interrupt_master_disable();
|
||||
|
||||
//
|
||||
// Check to make sure that the buffer isn't empty
|
||||
//
|
||||
if ( am_hal_queue_data_left(psQueue) >= ui32Bytes )
|
||||
{
|
||||
//
|
||||
// Loop over the bytes in the destination array.
|
||||
//
|
||||
for ( i = 0; i < ui32Bytes; i++ )
|
||||
{
|
||||
//
|
||||
// Grab the next value from the buffer.
|
||||
//
|
||||
pui8Dest[i] = psQueue->pui8Data[psQueue->ui32ReadIndex];
|
||||
|
||||
//
|
||||
// Advance the read index, wrapping if needed.
|
||||
//
|
||||
psQueue->ui32ReadIndex = ((psQueue->ui32ReadIndex + 1) %
|
||||
psQueue->ui32Capacity);
|
||||
}
|
||||
|
||||
//
|
||||
// Adjust the length value to reflect the change.
|
||||
//
|
||||
psQueue->ui32Length -= ui32Bytes;
|
||||
|
||||
//
|
||||
// Report a success.
|
||||
//
|
||||
bSuccess = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// If the buffer didn't have enough data, just return false.
|
||||
//
|
||||
bSuccess = false;
|
||||
}
|
||||
|
||||
am_hal_interrupt_master_set(ui32Primask);
|
||||
|
||||
return bSuccess;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// End Doxygen group.
|
||||
//! @}
|
||||
//
|
||||
//*****************************************************************************
|
||||
@@ -0,0 +1,123 @@
|
||||
//*****************************************************************************
|
||||
//
|
||||
// am_hal_queue.h
|
||||
//! @file
|
||||
//!
|
||||
//! @brief Functions for implementing a queue system.
|
||||
//!
|
||||
//! @addtogroup Miscellaneous2 Software Features (MISC)
|
||||
//! @ingroup apollo2hal
|
||||
//! @{
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Copyright (c) 2017, Ambiq Micro
|
||||
// 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.
|
||||
//
|
||||
// This is part of revision 1.2.9 of the AmbiqSuite Development Package.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#ifndef AM_HAL_QUEUE_H
|
||||
#define AM_HAL_QUEUE_H
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief A data structure that will operate as a queue.
|
||||
//!
|
||||
//! This data structure holds information necessary for operating a thread-safe
|
||||
//! queue. When declaring a structure of type am_hal_queue_t, you will also need
|
||||
//! to provide some working memory for the queue to use. For more information on
|
||||
//! setting up and using the am_hal_queue_t structure, please see the
|
||||
//! documentation for am_hal_queue_init().
|
||||
//
|
||||
//*****************************************************************************
|
||||
typedef struct
|
||||
{
|
||||
uint32_t ui32WriteIndex;
|
||||
uint32_t ui32ReadIndex;
|
||||
uint32_t ui32Length;
|
||||
uint32_t ui32Capacity;
|
||||
uint32_t ui32ItemSize;
|
||||
uint8_t *pui8Data;
|
||||
}
|
||||
am_hal_queue_t;
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Function-like macros.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define am_hal_queue_empty(psQueue) \
|
||||
((psQueue)->ui32Length == 0)
|
||||
|
||||
#define am_hal_queue_full(psQueue) \
|
||||
((psQueue)->ui32Length == (psQueue)->ui32Capacity)
|
||||
|
||||
#define am_hal_queue_space_left(psQueue) \
|
||||
((psQueue)->ui32Capacity - (psQueue)->ui32Length)
|
||||
|
||||
#define am_hal_queue_data_left(psQueue) \
|
||||
((psQueue)->ui32Length)
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Use this to make sure you get the size parameters right.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define am_hal_queue_from_array(queue, array) \
|
||||
am_hal_queue_init((queue), (array), sizeof((array)[0]), sizeof(array))
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// External function definitions.
|
||||
//
|
||||
//*****************************************************************************
|
||||
extern void am_hal_queue_init(am_hal_queue_t *psQueue, void *pvData, uint32_t ui32ItemSize, uint32_t ui32ArraySize);
|
||||
extern bool am_hal_queue_item_add(am_hal_queue_t *psQueue, const void *pvSource, uint32_t ui32NumItems);
|
||||
extern bool am_hal_queue_item_get(am_hal_queue_t *psQueue, void *pvDest, uint32_t ui32NumItems);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // AM_HAL_QUEUE_H
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// End Doxygen group.
|
||||
//! @}
|
||||
//
|
||||
//*****************************************************************************
|
||||
@@ -0,0 +1,160 @@
|
||||
//*****************************************************************************
|
||||
//
|
||||
// am_hal_reset.c
|
||||
//! @file
|
||||
//!
|
||||
//! @brief Hardware abstraction layer for the Reset Generator module.
|
||||
//!
|
||||
//! @addtogroup rstgen2 Reset Generator (RSTGEN)
|
||||
//! @ingroup apollo2hal
|
||||
//! @{
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Copyright (c) 2017, Ambiq Micro
|
||||
// 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.
|
||||
//
|
||||
// This is part of revision 1.2.9 of the AmbiqSuite Development Package.
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
#include "am_mcu_apollo.h"
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Configure the Reset Generator.
|
||||
//!
|
||||
//! @param ui32Config - Or together the supplied macros to enable
|
||||
//! configurations to obtain the desired reset generator settings.
|
||||
//!
|
||||
//! This function will set the reset generator's configuration register based on
|
||||
//! the user's desired settings listed in the supplied arugment.
|
||||
//!
|
||||
//! @return None.
|
||||
//
|
||||
//*****************************************************************************
|
||||
void
|
||||
am_hal_reset_init(uint32_t ui32Config)
|
||||
{
|
||||
//
|
||||
// Write the configuration to the reset generator
|
||||
//
|
||||
AM_REG(RSTGEN, CFG) = ui32Config;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Issue a POR (Apollo's last stage interrupt).
|
||||
//!
|
||||
//! This function will issue a POR reset.
|
||||
//! The Apollo chip has numerous stages of reset. POR is the last and is also
|
||||
//! the reset invoked by the chip's reset pin, the watchdog timer, the AIRCR
|
||||
//! reset, and the SWD debugger requested interrupt.
|
||||
//!
|
||||
//! The Debug Access Port in the M4 is not cleared by this reset.
|
||||
//!
|
||||
//! @return None.
|
||||
//
|
||||
//*****************************************************************************
|
||||
void am_hal_reset_por(void)
|
||||
{
|
||||
//
|
||||
// Write the POR key to the software POR register.
|
||||
//
|
||||
AM_REG(RSTGEN, SWPOR) =
|
||||
AM_REG_RSTGEN_SWPOR_SWPORKEY(AM_REG_RSTGEN_SWPOR_SWPORKEY_KEYVALUE);
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Issue a POI (Apollo's second stage interrupt).
|
||||
//!
|
||||
//! This function will issue a POI reset.
|
||||
//! The Apollo chip has numerous stages of reset. POI is the second stage.
|
||||
//! A few modules are reset by POI that are not reset by POR, notably POI
|
||||
//! causes the shadow registers to be reloaded from the OTP. A full power
|
||||
//! cycle or POI should be used after writing new flash, debug or SRAM
|
||||
//! protection bits into the OTP for these protections to take effect.
|
||||
//!
|
||||
//! The Debug Access Port in the M4 is not cleared by this reset.
|
||||
//!
|
||||
//! @return None.
|
||||
//
|
||||
//*****************************************************************************
|
||||
void am_hal_reset_poi(void)
|
||||
{
|
||||
//
|
||||
// Write the POI key to the software POI register.
|
||||
//
|
||||
AM_REG(RSTGEN, SWPOI) =
|
||||
AM_REG_RSTGEN_SWPOI_SWPOIKEY(AM_REG_RSTGEN_SWPOI_SWPOIKEY_KEYVALUE);
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Retrieve the status bits from the reset generator.
|
||||
//!
|
||||
//! This function will get the status bits from the reset generator.
|
||||
//! These bits are sticky and show the accumulation of reset types that the
|
||||
//! Apollo chip has experienced since power on. One should clear these out
|
||||
//! after reading them.
|
||||
//!
|
||||
//! @return None.
|
||||
//
|
||||
//*****************************************************************************
|
||||
uint32_t am_hal_reset_status_get(void)
|
||||
{
|
||||
//
|
||||
// Retrieve the reset generator status bits
|
||||
//
|
||||
return AM_REG(RSTGEN, STAT);
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Clear ALL of the status bits in the reset generator.
|
||||
//!
|
||||
//! This function will clear all status bits in the reset generator status.
|
||||
//!
|
||||
//! @return None.
|
||||
//
|
||||
//*****************************************************************************
|
||||
void am_hal_reset_status_clear(void)
|
||||
{
|
||||
AM_REG(RSTGEN, CLRSTAT) = AM_REG_RSTGEN_CLRSTAT_CLRSTAT(1);
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// End Doxygen group.
|
||||
//! @}
|
||||
//
|
||||
//*****************************************************************************
|
||||
@@ -0,0 +1,119 @@
|
||||
//*****************************************************************************
|
||||
//
|
||||
// am_hal_reset.h
|
||||
//! @file
|
||||
//!
|
||||
//! @brief Hardware abstraction layer for the Reset Generator module.
|
||||
//!
|
||||
//! @addtogroup wdt2 Watchdog Timer (RSTGEN)
|
||||
//! @ingroup apollo2hal
|
||||
//! @{
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Copyright (c) 2017, Ambiq Micro
|
||||
// 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.
|
||||
//
|
||||
// This is part of revision 1.2.9 of the AmbiqSuite Development Package.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#ifndef AM_HAL_RSTGEN_H
|
||||
#define AM_HAL_RSTGEN_H
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @name Reset Generator Configuration
|
||||
//! @brief These macros may be used to set the reset generator's configuration.
|
||||
//! @{
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define AM_HAL_RESET_CFG_WDT_RESET_ENABLE (AM_REG_RSTGEN_CFG_WDREN(1))
|
||||
// Brown out high (2.1v) reset enable.
|
||||
#define AM_HAL_RESET_CFG_BOD_HIGH_RESET_ENABLE (AM_REG_RSTGEN_CFG_BODHREN(1))
|
||||
//! @}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @name Reset Generator Status Bit Masks
|
||||
//! @brief These macros may be used to determine which type(s) of resets have
|
||||
//! been seen.
|
||||
//! @{
|
||||
//
|
||||
//*****************************************************************************
|
||||
// Reset was initiated by a Watchdog Timer Reset.
|
||||
#define AM_HAL_RESET_STAT_WDT (AM_REG_RSTGEN_STAT_WDRSTAT_M)
|
||||
|
||||
// Reset was a initiated by Debugger Reset.
|
||||
#define AM_HAL_RESET_STAT_DEBUG (AM_REG_RSTGEN_STAT_DBGRSTAT_M)
|
||||
|
||||
// Reset was a initiated by Software POI Reset.
|
||||
#define AM_HAL_RESET_STAT_POI (AM_REG_RSTGEN_STAT_POIRSTAT_M)
|
||||
|
||||
// Reset was a initiated by Software POR or AIRCR Reset.
|
||||
#define AM_HAL_RESET_STAT_SOFTWARE (AM_REG_RSTGEN_STAT_SWRSTAT_M)
|
||||
|
||||
// Reset was initiated by a Brown-Out Reset.
|
||||
#define AM_HAL_RESET_STAT_BOD (AM_REG_RSTGEN_STAT_BORSTAT_M)
|
||||
|
||||
// Reset was initiated by a Power Cycle
|
||||
#define AM_HAL_RESET_STAT_POWER_CYCLE (AM_REG_RSTGEN_STAT_PORSTAT_M)
|
||||
|
||||
// Reset was initiated by an External Reset.
|
||||
#define AM_HAL_RESET_STAT_EXTERNAL (AM_REG_RSTGEN_STAT_EXRSTAT_M)
|
||||
//! @}
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
//*****************************************************************************
|
||||
//
|
||||
// External function definitions
|
||||
//
|
||||
//*****************************************************************************
|
||||
extern void am_hal_reset_init(uint32_t ui32Config);
|
||||
extern void am_hal_reset_por(void);
|
||||
extern void am_hal_reset_poi(void);
|
||||
extern uint32_t am_hal_reset_status_get(void);
|
||||
extern void am_hal_reset_status_clear(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // AM_HAL_RSTGEN_H
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// End Doxygen group.
|
||||
//! @}
|
||||
//
|
||||
//*****************************************************************************
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,185 @@
|
||||
//*****************************************************************************
|
||||
//
|
||||
// am_hal_rtc.h
|
||||
//! @file
|
||||
//!
|
||||
//! @brief Functions for interfacing and accessing the Real-Time Clock (RTC).
|
||||
//!
|
||||
//! @addtogroup rtc2 Real-Time Clock (RTC)
|
||||
//! @ingroup apollo2hal
|
||||
//! @{
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Copyright (c) 2017, Ambiq Micro
|
||||
// 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.
|
||||
//
|
||||
// This is part of revision 1.2.9 of the AmbiqSuite Development Package.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#ifndef AM_HAL_RTC_H
|
||||
#define AM_HAL_RTC_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @name OSC Start and Stop
|
||||
//! @brief OSC Start and Stop defines.
|
||||
//!
|
||||
//! OSC Start and Stop defines to be used with \e am_hal_clkgen_osc_x().
|
||||
//! @{
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define AM_HAL_RTC_OSC_LFRC 0x1
|
||||
#define AM_HAL_RTC_OSC_XT 0x0
|
||||
//! @}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @name RTC Interrupts
|
||||
//! @brief Macro definitions for RTC interrupt status bits.
|
||||
//!
|
||||
//! These macros correspond to the bits in the RTC interrupt status register.
|
||||
//! They may be used with any of the \e am_hal_rtc_int_x() functions.
|
||||
//!
|
||||
//! @{
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define AM_HAL_RTC_INT_ALM AM_REG_RTC_INTEN_ALM_M
|
||||
#define AM_HAL_RTC_INT_OF AM_REG_RTC_INTEN_OF_M
|
||||
#define AM_HAL_RTC_INT_ACC AM_REG_RTC_INTEN_ACC_M
|
||||
#define AM_HAL_RTC_INT_ACF AM_REG_RTC_INTEN_ACF_M
|
||||
//! @}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @name RTC Alarm Repeat Interval.
|
||||
//! @brief Macro definitions for the RTC alarm repeat interval.
|
||||
//!
|
||||
//! These macros correspond to the RPT bits in the RTCCTL register.
|
||||
//! They may be used with the \e am_hal_rtc_alarm_interval_set() function.
|
||||
//!
|
||||
//! Note: AM_HAL_RTC_ALM_RPT_10TH and AM_HAL_RTC_ALM_RPT_100TH do not
|
||||
//! correspond to the RPT bits but are used in conjunction with setting the
|
||||
//! ALM100 bits in the ALMLOW register.
|
||||
//!
|
||||
//! @{
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define AM_HAL_RTC_ALM_RPT_DIS 0x0
|
||||
#define AM_HAL_RTC_ALM_RPT_YR 0x1
|
||||
#define AM_HAL_RTC_ALM_RPT_MTH 0x2
|
||||
#define AM_HAL_RTC_ALM_RPT_WK 0x3
|
||||
#define AM_HAL_RTC_ALM_RPT_DAY 0x4
|
||||
#define AM_HAL_RTC_ALM_RPT_HR 0x5
|
||||
#define AM_HAL_RTC_ALM_RPT_MIN 0x6
|
||||
#define AM_HAL_RTC_ALM_RPT_SEC 0x7
|
||||
#define AM_HAL_RTC_ALM_RPT_10TH 0x8
|
||||
#define AM_HAL_RTC_ALM_RPT_100TH 0x9
|
||||
//! @}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @name RTC Alarm 100 Interval.
|
||||
//! @brief Macro definitions for the RTC alarm ms intervals.
|
||||
//!
|
||||
//! These macros are used inside the #am_hal_rtc_alarm_interval_set function
|
||||
//! when 10ms and 100ms repeated alarm intervals are desired.
|
||||
//!
|
||||
//! @{
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define AM_HAL_RTC_ALM100_DEFAULT 0x00
|
||||
#define AM_HAL_RTC_ALM100_10TH 0xF0
|
||||
#define AM_HAL_RTC_ALM100_100TH 0xFF
|
||||
//! @}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief The basic time structure used by the HAL for RTC interaction.
|
||||
//!
|
||||
//! All values are positive whole numbers. The HAL routines convert back and
|
||||
//! forth to BCD.
|
||||
//
|
||||
//*****************************************************************************
|
||||
typedef struct am_hal_rtc_time_struct
|
||||
{
|
||||
uint32_t ui32ReadError;
|
||||
uint32_t ui32CenturyEnable;
|
||||
uint32_t ui32Weekday;
|
||||
uint32_t ui32Century;
|
||||
uint32_t ui32Year;
|
||||
uint32_t ui32Month;
|
||||
uint32_t ui32DayOfMonth;
|
||||
uint32_t ui32Hour;
|
||||
uint32_t ui32Minute;
|
||||
uint32_t ui32Second;
|
||||
uint32_t ui32Hundredths;
|
||||
}am_hal_rtc_time_t;
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// External function definitions
|
||||
//
|
||||
//*****************************************************************************
|
||||
extern void am_hal_rtc_osc_select(uint32_t ui32OSC);
|
||||
extern void am_hal_rtc_osc_enable(void);
|
||||
extern void am_hal_rtc_osc_disable(void);
|
||||
extern void am_hal_rtc_time_12hour(bool b12Hour);
|
||||
extern void am_hal_rtc_time_set(am_hal_rtc_time_t *pTime);
|
||||
extern uint32_t am_hal_rtc_time_get(am_hal_rtc_time_t *pTime);
|
||||
extern void am_hal_rtc_alarm_interval_set(uint32_t ui32RepeatInterval);
|
||||
extern void am_hal_rtc_alarm_set(am_hal_rtc_time_t *pTime,
|
||||
uint32_t ui32RepeatInterval);
|
||||
extern void am_hal_rtc_alarm_get(am_hal_rtc_time_t *pTime);
|
||||
extern void am_hal_rtc_int_enable(uint32_t ui32Interrupt);
|
||||
extern uint32_t am_hal_rtc_int_enable_get(void);
|
||||
extern void am_hal_rtc_int_disable(uint32_t ui32Interrupt);
|
||||
extern void am_hal_rtc_int_clear(uint32_t ui32Interrupt);
|
||||
extern void am_hal_rtc_int_set(uint32_t ui32Interrupt);
|
||||
extern uint32_t am_hal_rtc_int_status_get(bool bEnabledOnly);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // AM_HAL_RTC_H
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// End Doxygen group.
|
||||
//! @}
|
||||
//
|
||||
//*****************************************************************************
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,242 @@
|
||||
//*****************************************************************************
|
||||
//
|
||||
// am_hal_stimer.h
|
||||
//! @file
|
||||
//!
|
||||
//! @brief Functions for accessing and configuring the STIMER.
|
||||
//!
|
||||
//! @addtogroup stimer2 Counter/Timer (STIMER)
|
||||
//! @ingroup apollo2hal
|
||||
//! @{
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Copyright (c) 2017, Ambiq Micro
|
||||
// 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.
|
||||
//
|
||||
// This is part of revision 1.2.9 of the AmbiqSuite Development Package.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#ifndef AM_HAL_STIMER_H
|
||||
#define AM_HAL_STIMER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
//
|
||||
// Compute address of a given COMPARE or CAPTURE register.
|
||||
// Note - For Apollo2, the parameter n should be 0 (as only 1 stimer module
|
||||
// exists) and the parameter r should be 0-7 (compare) or 0-3 (capture).
|
||||
//
|
||||
#define AM_REG_STIMER_COMPARE(n, r) (AM_REG_CTIMERn(n) + \
|
||||
AM_REG_CTIMER_SCMPR0_O + (r * 4))
|
||||
|
||||
#define AM_REG_STIMER_CAPTURE(n, r) (AM_REG_CTIMERn(n) + \
|
||||
AM_REG_CTIMER_SCAPT0_O + (r * 4))
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @name Interrupt Status Bits
|
||||
//! @brief Interrupt Status Bits for enable/disble use
|
||||
//!
|
||||
//! These macros may be used to set and clear interrupt bits
|
||||
//! @{
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define AM_HAL_STIMER_INT_COMPAREA AM_REG_CTIMER_STMINTSTAT_COMPAREA_M
|
||||
#define AM_HAL_STIMER_INT_COMPAREB AM_REG_CTIMER_STMINTSTAT_COMPAREB_M
|
||||
#define AM_HAL_STIMER_INT_COMPAREC AM_REG_CTIMER_STMINTSTAT_COMPAREC_M
|
||||
#define AM_HAL_STIMER_INT_COMPARED AM_REG_CTIMER_STMINTSTAT_COMPARED_M
|
||||
#define AM_HAL_STIMER_INT_COMPAREE AM_REG_CTIMER_STMINTSTAT_COMPAREE_M
|
||||
#define AM_HAL_STIMER_INT_COMPAREF AM_REG_CTIMER_STMINTSTAT_COMPAREF_M
|
||||
#define AM_HAL_STIMER_INT_COMPAREG AM_REG_CTIMER_STMINTSTAT_COMPAREG_M
|
||||
#define AM_HAL_STIMER_INT_COMPAREH AM_REG_CTIMER_STMINTSTAT_COMPAREH_M
|
||||
|
||||
#define AM_HAL_STIMER_INT_OVERFLOW AM_REG_CTIMER_STMINTSTAT_OVERFLOW_M
|
||||
|
||||
#define AM_HAL_STIMER_INT_CAPTUREA AM_REG_CTIMER_STMINTSTAT_CAPTUREA_M
|
||||
#define AM_HAL_STIMER_INT_CAPTUREB AM_REG_CTIMER_STMINTSTAT_CAPTUREB_M
|
||||
#define AM_HAL_STIMER_INT_CAPTUREC AM_REG_CTIMER_STMINTSTAT_CAPTUREC_M
|
||||
#define AM_HAL_STIMER_INT_CAPTURED AM_REG_CTIMER_STMINTSTAT_CAPTURED_M
|
||||
|
||||
//! @}
|
||||
|
||||
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @name STimer Configuration Bits
|
||||
//! @brief Interrupt Status Bits for enable/disble use
|
||||
//!
|
||||
//! These macros may be used to set and clear interrupt bits
|
||||
//! @{
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define AM_HAL_STIMER_CFG_THAW \
|
||||
AM_REG_CTIMER_STCFG_FREEZE_THAW
|
||||
#define AM_HAL_STIMER_CFG_FREEZE \
|
||||
AM_REG_CTIMER_STCFG_FREEZE_FREEZE
|
||||
#define AM_HAL_STIMER_CFG_RUN \
|
||||
AM_REG_CTIMER_STCFG_CLEAR_RUN
|
||||
#define AM_HAL_STIMER_CFG_CLEAR \
|
||||
AM_REG_CTIMER_STCFG_CLEAR_CLEAR
|
||||
#define AM_HAL_STIMER_CFG_COMPARE_A_ENABLE \
|
||||
AM_REG_CTIMER_STCFG_COMPARE_A_EN_ENABLE
|
||||
#define AM_HAL_STIMER_CFG_COMPARE_B_ENABLE \
|
||||
AM_REG_CTIMER_STCFG_COMPARE_B_EN_ENABLE
|
||||
#define AM_HAL_STIMER_CFG_COMPARE_C_ENABLE \
|
||||
AM_REG_CTIMER_STCFG_COMPARE_C_EN_ENABLE
|
||||
#define AM_HAL_STIMER_CFG_COMPARE_D_ENABLE \
|
||||
AM_REG_CTIMER_STCFG_COMPARE_D_EN_ENABLE
|
||||
#define AM_HAL_STIMER_CFG_COMPARE_E_ENABLE \
|
||||
AM_REG_CTIMER_STCFG_COMPARE_E_EN_ENABLE
|
||||
#define AM_HAL_STIMER_CFG_COMPARE_F_ENABLE \
|
||||
AM_REG_CTIMER_STCFG_COMPARE_F_EN_ENABLE
|
||||
#define AM_HAL_STIMER_CFG_COMPARE_G_ENABLE \
|
||||
AM_REG_CTIMER_STCFG_COMPARE_G_EN_ENABLE
|
||||
#define AM_HAL_STIMER_CFG_COMPARE_H_ENABLE \
|
||||
AM_REG_CTIMER_STCFG_COMPARE_H_EN_ENABLE
|
||||
|
||||
//! @}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @name Clock Configuration options
|
||||
//! @brief STimer Configuration register options.
|
||||
//!
|
||||
//! These options are to be used with the am_hal_stimer_config() function.
|
||||
//! @{
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define AM_HAL_STIMER_NO_CLK \
|
||||
AM_REG_CTIMER_STCFG_CLKSEL(AM_REG_CTIMER_STCFG_CLKSEL_NOCLK)
|
||||
#define AM_HAL_STIMER_HFRC_3MHZ \
|
||||
AM_REG_CTIMER_STCFG_CLKSEL(AM_REG_CTIMER_STCFG_CLKSEL_HFRC_DIV16)
|
||||
#define AM_HAL_STIMER_HFRC_187_5KHZ \
|
||||
AM_REG_CTIMER_STCFG_CLKSEL(AM_REG_CTIMER_STCFG_CLKSEL_HFRC_DIV256)
|
||||
#define AM_HAL_STIMER_XTAL_32KHZ \
|
||||
AM_REG_CTIMER_STCFG_CLKSEL(AM_REG_CTIMER_STCFG_CLKSEL_XTAL_DIV1)
|
||||
#define AM_HAL_STIMER_XTAL_16KHZ \
|
||||
AM_REG_CTIMER_STCFG_CLKSEL(AM_REG_CTIMER_STCFG_CLKSEL_XTAL_DIV2)
|
||||
#define AM_HAL_STIMER_XTAL_1KHZ \
|
||||
AM_REG_CTIMER_STCFG_CLKSEL(AM_REG_CTIMER_STCFG_CLKSEL_XTAL_DIV32)
|
||||
#define AM_HAL_STIMER_LFRC_1KHZ \
|
||||
AM_REG_CTIMER_STCFG_CLKSEL(AM_REG_CTIMER_STCFG_CLKSEL_LFRC_DIV1)
|
||||
#define AM_HAL_STIMER_HFRC_CTIMER0A \
|
||||
AM_REG_CTIMER_STCFG_CLKSEL(AM_REG_CTIMER_STCFG_CLKSEL_CTIMER0A)
|
||||
#define AM_HAL_STIMER_HFRC_CTIMER0B \
|
||||
AM_REG_CTIMER_STCFG_CLKSEL(AM_REG_CTIMER_STCFG_CLKSEL_CTIMER0B)
|
||||
//! @}
|
||||
|
||||
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @name Capture Control Register options.
|
||||
//! @brief Configuration options for capture control register.
|
||||
//!
|
||||
//! These options are to be used with the am_hal_stimer_capture_control_set
|
||||
//! function.
|
||||
//! @{
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define AM_HAL_STIMER_CAPTURE_A_ENABLE \
|
||||
AM_REG_CTIMER_CAPTURE_CONTROL_CAPTURE_A_ENABLE
|
||||
#define AM_HAL_STIMER_CAPTURE_B_ENABLE \
|
||||
AM_REG_CTIMER_CAPTURE_CONTROL_CAPTURE_B_ENABLE
|
||||
#define AM_HAL_STIMER_CAPTURE_C_ENABLE \
|
||||
AM_REG_CTIMER_CAPTURE_CONTROL_CAPTURE_C_ENABLE
|
||||
#define AM_HAL_STIMER_CAPTURE_D_ENABLE \
|
||||
AM_REG_CTIMER_CAPTURE_CONTROL_CAPTURE_D_ENABLE
|
||||
|
||||
//! @}
|
||||
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Stimer configuration structure
|
||||
//
|
||||
//*****************************************************************************
|
||||
typedef struct
|
||||
{
|
||||
//
|
||||
//! Configuration options for the STIMER
|
||||
//
|
||||
uint32_t ui32STimerConfig;
|
||||
}
|
||||
am_hal_stimer_config_t;
|
||||
|
||||
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// External function definitions
|
||||
//
|
||||
//*****************************************************************************
|
||||
extern uint32_t am_hal_stimer_config(uint32_t ui32STimerConfig);
|
||||
extern uint32_t am_hal_stimer_counter_get(void);
|
||||
extern void am_hal_stimer_counter_clear(void);
|
||||
extern void am_hal_stimer_compare_delta_set(uint32_t ui32CmprInstance,
|
||||
uint32_t ui32Delta);
|
||||
extern uint32_t am_hal_stimer_compare_get(uint32_t ui32CmprInstance);
|
||||
extern void am_hal_stimer_capture_start(uint32_t ui32CaptureNum,
|
||||
uint32_t ui32GPIONumber,
|
||||
bool bPolarity);
|
||||
extern void am_hal_stimer_capture_stop(uint32_t ui32CaptureNum);
|
||||
extern uint32_t am_hal_stimer_capture_get(uint32_t ui32CaptureNum);
|
||||
extern void am_hal_stimer_int_enable(uint32_t ui32Interrupt);
|
||||
extern uint32_t am_hal_stimer_int_enable_get(void);
|
||||
extern void am_hal_stimer_int_disable(uint32_t ui32Interrupt);
|
||||
extern void am_hal_stimer_int_set(uint32_t ui32Interrupt);
|
||||
extern void am_hal_stimer_int_clear(uint32_t ui32Interrupt);
|
||||
extern uint32_t am_hal_stimer_int_status_get(bool bEnabledOnly);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // AM_HAL_STIMER_H
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// End Doxygen group.
|
||||
//! @}
|
||||
//
|
||||
//*****************************************************************************
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,119 @@
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! am_hal_sysctrl.h
|
||||
//! @file
|
||||
//!
|
||||
//! @brief Functions for interfacing with the M4F system control registers
|
||||
//!
|
||||
//! @addtogroup sysctrl2 System Control (SYSCTRL)
|
||||
//! @ingroup apollo2hal
|
||||
//! @{
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Copyright (c) 2017, Ambiq Micro
|
||||
// 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.
|
||||
//
|
||||
// This is part of revision 1.2.9 of the AmbiqSuite Development Package.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#ifndef AM_HAL_SYSCTRL_H
|
||||
#define AM_HAL_SYSCTRL_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Definitions for sleep mode parameter
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define AM_HAL_SYSCTRL_SLEEP_DEEP true
|
||||
#define AM_HAL_SYSCTRL_SLEEP_NORMAL false
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Parameters for am_hal_sysctrl_buck_ctimer_isr_init()
|
||||
//
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Define the maximum valid timer number
|
||||
//
|
||||
#define BUCK_TIMER_MAX (AM_HAL_CTIMER_TIMERS_NUM - 1)
|
||||
|
||||
//
|
||||
// Define the valid timer numbers
|
||||
//
|
||||
#define AM_HAL_SYSCTRL_BUCK_CTIMER_TIMER0 0
|
||||
#define AM_HAL_SYSCTRL_BUCK_CTIMER_TIMER1 1
|
||||
#define AM_HAL_SYSCTRL_BUCK_CTIMER_TIMER2 2
|
||||
#define AM_HAL_SYSCTRL_BUCK_CTIMER_TIMER3 3
|
||||
|
||||
//
|
||||
// The following is an invalid timer number. If used, it is the caller telling
|
||||
// the HAL to use the "Hard Option", which applies a constant value to the zero
|
||||
// cross. The applied value is more noise immune, if less energy efficent.
|
||||
//
|
||||
#define AM_HAL_SYSCTRL_BUCK_CTIMER_ZX_CONSTANT 0x01000000 // No timer, apply a constant value
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// External function definitions
|
||||
//
|
||||
//*****************************************************************************
|
||||
extern void am_hal_sysctrl_sleep(bool bSleepDeep);
|
||||
extern void am_hal_sysctrl_fpu_enable(void);
|
||||
extern void am_hal_sysctrl_fpu_disable(void);
|
||||
extern void am_hal_sysctrl_fpu_stacking_enable(bool bLazy);
|
||||
extern void am_hal_sysctrl_fpu_stacking_disable(void);
|
||||
extern void am_hal_sysctrl_aircr_reset(void);
|
||||
|
||||
//
|
||||
// Apollo2 zero-cross buck/ctimer related functions
|
||||
//
|
||||
extern uint32_t am_hal_sysctrl_buck_ctimer_isr_init(uint32_t ui32BuckTimerNumber);
|
||||
extern bool am_hal_sysctrl_buck_update_complete(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // AM_HAL_SYSCTRL_H
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// End Doxygen group.
|
||||
//! @}
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
@@ -0,0 +1,453 @@
|
||||
//*****************************************************************************
|
||||
//
|
||||
// am_hal_systick.c
|
||||
//! @file
|
||||
//!
|
||||
//! @brief Functions for interfacing with the SYSTICK
|
||||
//!
|
||||
//! @addtogroup systick2 System Timer (SYSTICK)
|
||||
//! @ingroup apollo2hal
|
||||
//! @{
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Copyright (c) 2017, Ambiq Micro
|
||||
// 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.
|
||||
//
|
||||
// This is part of revision 1.2.9 of the AmbiqSuite Development Package.
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "am_mcu_apollo.h"
|
||||
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Macro definitions
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define SYSTICK_MAX_TICKS ((1 << 24)-1)
|
||||
#define MAX_U32 (0xffffffff)
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Start the SYSTICK.
|
||||
//!
|
||||
//! This function starts the systick timer.
|
||||
//!
|
||||
//! @note This timer does not run in deep-sleep mode as it runs from the core
|
||||
//! clock, which is gated in deep-sleep. If a timer is needed in deep-sleep use
|
||||
//! one of the ctimers instead. Also to note is this timer will consume higher
|
||||
//! power than the ctimers.
|
||||
//!
|
||||
//! @return None.
|
||||
//
|
||||
//*****************************************************************************
|
||||
void
|
||||
am_hal_systick_start(void)
|
||||
{
|
||||
//
|
||||
// Start the systick timer.
|
||||
//
|
||||
AM_REG(SYSTICK, SYSTCSR) |= AM_REG_SYSTICK_SYSTCSR_ENABLE_M;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Stop the SYSTICK.
|
||||
//!
|
||||
//! This function stops the systick timer.
|
||||
//!
|
||||
//! @note This timer does not run in deep-sleep mode as it runs from the core
|
||||
//! clock, which is gated in deep-sleep. If a timer is needed in deep-sleep use
|
||||
//! one of the ctimers instead. Also to note is this timer will consume higher
|
||||
//! power than the ctimers.
|
||||
//!
|
||||
//! @return None.
|
||||
//
|
||||
//*****************************************************************************
|
||||
void
|
||||
am_hal_systick_stop(void)
|
||||
{
|
||||
//
|
||||
// Stop the systick timer.
|
||||
//
|
||||
AM_REG(SYSTICK, SYSTCSR) &= ~AM_REG_SYSTICK_SYSTCSR_ENABLE_M;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Enable the interrupt in the SYSTICK.
|
||||
//!
|
||||
//! This function enables the interupt in the systick timer.
|
||||
//!
|
||||
//! @return None.
|
||||
//
|
||||
//*****************************************************************************
|
||||
void
|
||||
am_hal_systick_int_enable(void)
|
||||
{
|
||||
//
|
||||
// Enable the systick timer interrupt.
|
||||
//
|
||||
AM_REG(SYSTICK, SYSTCSR) |= AM_REG_SYSTICK_SYSTCSR_TICKINT_M;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Disable the interrupt in the SYSTICK.
|
||||
//!
|
||||
//! This function disables the interupt in the systick timer.
|
||||
//!
|
||||
//! @return None.
|
||||
//
|
||||
//*****************************************************************************
|
||||
void
|
||||
am_hal_systick_int_disable(void)
|
||||
{
|
||||
//
|
||||
// Disable the systick timer interrupt.
|
||||
//
|
||||
AM_REG(SYSTICK, SYSTCSR) &= ~AM_REG_SYSTICK_SYSTCSR_TICKINT_M;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Reads the interrupt status.
|
||||
//!
|
||||
//! This function reads the interrupt status in the systick timer.
|
||||
//!
|
||||
//! @return the interrupt status.
|
||||
//
|
||||
//*****************************************************************************
|
||||
uint32_t
|
||||
am_hal_systick_int_status_get(void)
|
||||
{
|
||||
//
|
||||
// Return the systick timer interrupt status.
|
||||
//
|
||||
return AM_REG(SYSTICK, SYSTCSR) & AM_REG_SYSTICK_SYSTCSR_COUNTFLAG_M;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Reset the interrupt in the SYSTICK.
|
||||
//!
|
||||
//! This function resets the systick timer by clearing out the configuration
|
||||
//! register.
|
||||
//!
|
||||
//! @return None.
|
||||
//
|
||||
//*****************************************************************************
|
||||
void
|
||||
am_hal_systick_reset(void)
|
||||
{
|
||||
//
|
||||
// Reset the systick timer interrupt.
|
||||
//
|
||||
AM_REG(SYSTICK, SYSTCSR) = 0x0;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Load the value into the SYSTICK.
|
||||
//!
|
||||
//! @param ui32LoadVal the desired load value for the systick. Maximum value is
|
||||
//! 0x00FF.FFFF.
|
||||
//!
|
||||
//! This function loads the desired value into the systick timer.
|
||||
//!
|
||||
//! @return None.
|
||||
//
|
||||
//*****************************************************************************
|
||||
void
|
||||
am_hal_systick_load(uint32_t ui32LoadVal)
|
||||
{
|
||||
//
|
||||
// Write the reload register.
|
||||
//
|
||||
AM_REG(SYSTICK, SYSTRVR) = ui32LoadVal;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Get the current count value in the SYSTICK.
|
||||
//!
|
||||
//! This function gets the current count value in the systick timer.
|
||||
//!
|
||||
//! @return Current count value.
|
||||
//
|
||||
//*****************************************************************************
|
||||
uint32_t
|
||||
am_hal_systick_count(void)
|
||||
{
|
||||
//
|
||||
// Return the current systick timer count value.
|
||||
//
|
||||
return AM_REG(SYSTICK, SYSTCVR);
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Wait the specified number of ticks.
|
||||
//!
|
||||
//! This function delays for the given number of SysTick ticks.
|
||||
//!
|
||||
//! @note If the SysTick timer is being used elsewhere, it will be corrupted
|
||||
//! by calling this function.
|
||||
//!
|
||||
//! @return 0 if successful.
|
||||
//
|
||||
//*****************************************************************************
|
||||
uint32_t
|
||||
am_hal_systick_wait_ticks(uint32_t u32Ticks)
|
||||
{
|
||||
|
||||
if ( u32Ticks == 0 )
|
||||
{
|
||||
u32Ticks++; // Make sure we get the COUNTFLAG
|
||||
}
|
||||
|
||||
//
|
||||
// The proper SysTick initialization sequence is: (p 4-36 of the M4 UG).
|
||||
// 1. Program reload value
|
||||
// 2. Clear current value
|
||||
// 3. Program CSR
|
||||
//
|
||||
// Set the reload value to the required number of ticks.
|
||||
//
|
||||
AM_REG(SYSTICK, SYSTRVR) = u32Ticks;
|
||||
|
||||
//
|
||||
// Clear the current count.
|
||||
//
|
||||
AM_REG(SYSTICK, SYSTCVR) = 0x0;
|
||||
|
||||
//
|
||||
// Set to use the processor clock, but don't cause an exception (we'll poll).
|
||||
//
|
||||
AM_REG(SYSTICK, SYSTCSR) = AM_REG_SYSTICK_SYSTCSR_ENABLE_M;
|
||||
|
||||
//
|
||||
// Poll till done
|
||||
//
|
||||
while ( !(AM_REG(SYSTICK, SYSTCSR) & AM_REG_SYSTICK_SYSTCSR_COUNTFLAG_M) );
|
||||
|
||||
//
|
||||
// And disable systick before exiting.
|
||||
//
|
||||
AM_REG(SYSTICK, SYSTCSR) = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Delay the specified number of microseconds.
|
||||
//!
|
||||
//! This function will use the SysTick timer to delay until the specified
|
||||
//! number of microseconds have elapsed. It uses the processor clocks and
|
||||
//! takes into account the current CORESEL setting.
|
||||
//!
|
||||
//! @note If the SysTick timer is being used elsewhere, it will be corrupted
|
||||
//! by calling this function.
|
||||
//!
|
||||
//! @return Total number of SysTick ticks delayed.
|
||||
//
|
||||
//*****************************************************************************
|
||||
uint32_t
|
||||
am_hal_systick_delay_us(uint32_t u32NumUs)
|
||||
{
|
||||
uint32_t u32ClkFreq, u32nLoops, u32Ticks, uRet;
|
||||
uint32_t u32CoreSel = AM_BFR(CLKGEN, CCTRL, CORESEL);
|
||||
|
||||
u32nLoops = 1;
|
||||
switch (u32CoreSel)
|
||||
{
|
||||
//
|
||||
// We need to compute the required number of ticks. To do so and to
|
||||
// minimize divide operations, we'll use the following equation:
|
||||
// u32Ticks = (u32NumUs * HFCR_EXACT)/1000000
|
||||
// = (u32NumUs * (HFCR_EXACT * 1024)/1000000) / 1024
|
||||
// The values for the variable u32ClkFreq are computed as follows:
|
||||
// u32ClkFreq = (24390200 * 1024) / ((clksel+1)*1000000);
|
||||
// (and we'll do the remaining divide by 1024, using a shift, later).
|
||||
//
|
||||
case 0:
|
||||
u32ClkFreq = 24975;
|
||||
if ( u32NumUs > ((SYSTICK_MAX_TICKS / 24975)*1024) )
|
||||
{
|
||||
u32nLoops = (u32NumUs / ((SYSTICK_MAX_TICKS / 24975)*1024)) + 1;
|
||||
u32NumUs /= u32nLoops;
|
||||
}
|
||||
if ( u32NumUs > (MAX_U32 / 24975) )
|
||||
{
|
||||
u32Ticks = (u32NumUs >> 10) * u32ClkFreq;
|
||||
}
|
||||
else
|
||||
{
|
||||
u32Ticks = (u32NumUs * u32ClkFreq) >> 10;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
u32ClkFreq = 12487;
|
||||
if ( u32NumUs > ((SYSTICK_MAX_TICKS / 12487)*1024) )
|
||||
{
|
||||
u32nLoops = (u32NumUs / ((SYSTICK_MAX_TICKS / 12487)*1024)) + 1;
|
||||
u32NumUs /= u32nLoops;
|
||||
}
|
||||
if ( u32NumUs > (MAX_U32 / 12487) )
|
||||
{
|
||||
u32Ticks = (u32NumUs >> 10) * u32ClkFreq;
|
||||
}
|
||||
else
|
||||
{
|
||||
u32Ticks = (u32NumUs * u32ClkFreq) >> 10;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
u32ClkFreq = 8325;
|
||||
if ( u32NumUs > ((SYSTICK_MAX_TICKS / 8325)*1024) )
|
||||
{
|
||||
u32nLoops = (u32NumUs / ((SYSTICK_MAX_TICKS / 8325)*1024)) + 1;
|
||||
u32NumUs /= u32nLoops;
|
||||
}
|
||||
if ( u32NumUs > (MAX_U32 / 8325) )
|
||||
{
|
||||
u32Ticks = (u32NumUs >> 10) * u32ClkFreq;
|
||||
}
|
||||
else
|
||||
{
|
||||
u32Ticks = (u32NumUs * u32ClkFreq) >> 10;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
u32ClkFreq = 6243;
|
||||
if ( u32NumUs > ((SYSTICK_MAX_TICKS / 6243)*1024) )
|
||||
{
|
||||
u32nLoops = (u32NumUs / ((SYSTICK_MAX_TICKS / 6243)*1024)) + 1;
|
||||
u32NumUs /= u32nLoops;
|
||||
}
|
||||
if ( u32NumUs > (MAX_U32 / 6243) )
|
||||
{
|
||||
u32Ticks = (u32NumUs >> 10) * u32ClkFreq;
|
||||
}
|
||||
else
|
||||
{
|
||||
u32Ticks = (u32NumUs * u32ClkFreq) >> 10;
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
u32ClkFreq = 4995;
|
||||
if ( u32NumUs > ((SYSTICK_MAX_TICKS / 4995)*1024) )
|
||||
{
|
||||
u32nLoops = (u32NumUs / ((SYSTICK_MAX_TICKS / 4995)*1024)) + 1;
|
||||
u32NumUs /= u32nLoops;
|
||||
}
|
||||
if ( u32NumUs > (MAX_U32 / 4995) )
|
||||
{
|
||||
u32Ticks = (u32NumUs >> 10) * u32ClkFreq;
|
||||
}
|
||||
else
|
||||
{
|
||||
u32Ticks = (u32NumUs * u32ClkFreq) >> 10;
|
||||
}
|
||||
break;
|
||||
case 5:
|
||||
u32ClkFreq = 4162;
|
||||
if ( u32NumUs > ((SYSTICK_MAX_TICKS / 4162)*1024) )
|
||||
{
|
||||
u32nLoops = (u32NumUs / ((SYSTICK_MAX_TICKS / 4162)*1024)) + 1;
|
||||
u32NumUs /= u32nLoops;
|
||||
}
|
||||
if ( u32NumUs > (MAX_U32 / 4162) )
|
||||
{
|
||||
u32Ticks = (u32NumUs >> 10) * u32ClkFreq;
|
||||
}
|
||||
else
|
||||
{
|
||||
u32Ticks = (u32NumUs * u32ClkFreq) >> 10;
|
||||
}
|
||||
break;
|
||||
case 6:
|
||||
u32ClkFreq = 3567;
|
||||
if ( u32NumUs > ((SYSTICK_MAX_TICKS / 3567)*1024) )
|
||||
{
|
||||
u32nLoops = (u32NumUs / ((SYSTICK_MAX_TICKS / 3567)*1024)) + 1;
|
||||
u32NumUs /= u32nLoops;
|
||||
}
|
||||
if ( u32NumUs > (MAX_U32 / 3567) )
|
||||
{
|
||||
u32Ticks = (u32NumUs >> 10) * u32ClkFreq;
|
||||
}
|
||||
else
|
||||
{
|
||||
u32Ticks = (u32NumUs * u32ClkFreq) >> 10;
|
||||
}
|
||||
break;
|
||||
case 7:
|
||||
u32ClkFreq = 3121;
|
||||
if ( u32NumUs > ((SYSTICK_MAX_TICKS / 3121)*1024) )
|
||||
{
|
||||
u32nLoops = (u32NumUs / ((SYSTICK_MAX_TICKS / 3121)*1024)) + 1;
|
||||
u32NumUs /= u32nLoops;
|
||||
}
|
||||
if ( u32NumUs > (MAX_U32 / 3121) )
|
||||
{
|
||||
u32Ticks = (u32NumUs >> 10) * u32ClkFreq;
|
||||
}
|
||||
else
|
||||
{
|
||||
u32Ticks = (u32NumUs * u32ClkFreq) >> 10;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
u32Ticks = 1;
|
||||
break;
|
||||
} // switch()
|
||||
|
||||
uRet = u32Ticks * u32nLoops;
|
||||
while ( u32nLoops-- )
|
||||
{
|
||||
am_hal_systick_wait_ticks(u32Ticks);
|
||||
}
|
||||
|
||||
return uRet;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// End Doxygen group.
|
||||
//! @}
|
||||
//
|
||||
//*****************************************************************************
|
||||
@@ -0,0 +1,83 @@
|
||||
//*****************************************************************************
|
||||
//
|
||||
// am_hal_systick.h
|
||||
//! @file
|
||||
//!
|
||||
//! @brief Functions for accessing and configuring the SYSTICK.
|
||||
//!
|
||||
//! @addtogroup systick2 System Timer (SYSTICK)
|
||||
//! @ingroup apollo2hal
|
||||
//! @{
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Copyright (c) 2017, Ambiq Micro
|
||||
// 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.
|
||||
//
|
||||
// This is part of revision 1.2.9 of the AmbiqSuite Development Package.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#ifndef AM_HAL_SYSTICK_H
|
||||
#define AM_HAL_SYSTICK_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// External function definitions
|
||||
//
|
||||
//*****************************************************************************
|
||||
extern void am_hal_systick_start(void);
|
||||
extern void am_hal_systick_stop(void);
|
||||
extern void am_hal_systick_int_enable(void);
|
||||
extern void am_hal_systick_int_disable(void);
|
||||
extern uint32_t am_hal_systick_int_status_get(void);
|
||||
extern void am_hal_systick_reset(void);
|
||||
extern void am_hal_systick_load(uint32_t ui32LoadVal);
|
||||
extern uint32_t am_hal_systick_count(void);
|
||||
extern uint32_t am_hal_systick_wait_ticks(uint32_t u32Ticks);
|
||||
extern uint32_t am_hal_systick_delay_us(uint32_t u32NumUs);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // AM_HAL_SYSTICK_H
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// End Doxygen group.
|
||||
//! @}
|
||||
//
|
||||
//*****************************************************************************
|
||||
@@ -0,0 +1,381 @@
|
||||
//*****************************************************************************
|
||||
//
|
||||
// am_hal_tpiu.c
|
||||
//! @file
|
||||
//!
|
||||
//! @brief Support functions for the ARM TPIU module
|
||||
//!
|
||||
//! Provides support functions for configuring the ARM TPIU module
|
||||
//!
|
||||
//! @addtogroup tpiu2 Trace Port Interface Unit (TPIU)
|
||||
//! @ingroup apollo2hal
|
||||
//! @{
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Copyright (c) 2017, Ambiq Micro
|
||||
// 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.
|
||||
//
|
||||
// This is part of revision 1.2.9 of the AmbiqSuite Development Package.
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "am_mcu_apollo.h"
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Enable the clock to the TPIU module.
|
||||
//!
|
||||
//! This function enables the clock to the TPIU module.
|
||||
//!
|
||||
//! @return None.
|
||||
//
|
||||
//*****************************************************************************
|
||||
void
|
||||
am_hal_tpiu_clock_enable(void)
|
||||
{
|
||||
//
|
||||
// Enable the TPIU clock
|
||||
//
|
||||
AM_REG(MCUCTRL, TPIUCTRL) |= AM_REG_MCUCTRL_TPIUCTRL_ENABLE_M;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Disable the clock to the TPIU module.
|
||||
//!
|
||||
//! This function disables the clock to the TPIU module.
|
||||
//!
|
||||
//! @return None.
|
||||
//
|
||||
//*****************************************************************************
|
||||
void
|
||||
am_hal_tpiu_clock_disable(void)
|
||||
{
|
||||
//
|
||||
// Disable the TPIU clock
|
||||
//
|
||||
AM_REG(MCUCTRL, TPIUCTRL) &= ~AM_REG_MCUCTRL_TPIUCTRL_ENABLE_M;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Set the output port width of the TPIU
|
||||
//!
|
||||
//! @param ui32PortWidth - The desired port width (in bits)
|
||||
//!
|
||||
//! This function uses the TPIU_CSPSR register to set the desired output port
|
||||
//! width of the TPIU.
|
||||
//!
|
||||
//! @return None.
|
||||
//
|
||||
//*****************************************************************************
|
||||
void
|
||||
am_hal_tpiu_port_width_set(uint32_t ui32PortWidth)
|
||||
{
|
||||
AM_REG(TPIU, CSPSR) = 1 << (ui32PortWidth - 1);
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Read the supported_output port width of the TPIU
|
||||
//!
|
||||
//! This function uses the \e TPIU_SSPSR register to set the supported output
|
||||
//! port widths of the TPIU.
|
||||
//!
|
||||
//! @return Current width of the TPIU output port
|
||||
//
|
||||
//*****************************************************************************
|
||||
uint32_t
|
||||
am_hal_tpiu_supported_port_width_get(void)
|
||||
{
|
||||
uint32_t i, ui32WidthValue;
|
||||
|
||||
//
|
||||
// Read the supported width register.
|
||||
//
|
||||
ui32WidthValue = AM_REG(TPIU, SSPSR);
|
||||
|
||||
//
|
||||
// The register value is encoded in a one-hot format, so the position of
|
||||
// the single set bit determines the actual width of the port.
|
||||
//
|
||||
for (i = 1; i < 32; i++)
|
||||
{
|
||||
//
|
||||
// Check each bit for a '1'. When we find it, our current loop index
|
||||
// will be equal to the port width.
|
||||
//
|
||||
if (ui32WidthValue == (0x1 << (i - 1)))
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// We should never get here, but if we do, just return the smallest
|
||||
// possible value for a supported trace port width.
|
||||
//
|
||||
return 1;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Read the output port width of the TPIU
|
||||
//!
|
||||
//! This function uses the \e TPIU_CSPSR register to set the desired output
|
||||
//! port width of the TPIU.
|
||||
//!
|
||||
//! @return Current width of the TPIU output port
|
||||
//
|
||||
//*****************************************************************************
|
||||
uint32_t
|
||||
am_hal_tpiu_port_width_get(void)
|
||||
{
|
||||
uint32_t ui32Temp;
|
||||
uint32_t ui32Width;
|
||||
|
||||
ui32Width = 1;
|
||||
ui32Temp = AM_REG(TPIU, CSPSR);
|
||||
|
||||
while ( !(ui32Temp & 1) )
|
||||
{
|
||||
ui32Temp = ui32Temp >> 1;
|
||||
ui32Width++;
|
||||
|
||||
if (ui32Width > 32)
|
||||
{
|
||||
ui32Width = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Current width of the TPIU output port.
|
||||
//
|
||||
return ui32Width;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Configure the TPIU based on the values in the configuration struct.
|
||||
//!
|
||||
//! @param psConfig - pointer to an am_hal_tpiu_config_t structure containing
|
||||
//! the desired configuration information.
|
||||
//!
|
||||
//! This function reads the provided configuration structure, and sets the
|
||||
//! relevant TPIU registers to achieve the desired configuration.
|
||||
//!
|
||||
//! @return None.
|
||||
//
|
||||
//*****************************************************************************
|
||||
void
|
||||
am_hal_tpiu_configure(am_hal_tpiu_config_t *psConfig)
|
||||
{
|
||||
//
|
||||
// Set the clock freq in the MCUCTRL register.
|
||||
//
|
||||
AM_REG(MCUCTRL, TPIUCTRL) |= psConfig->ui32TraceClkIn;
|
||||
|
||||
//
|
||||
// Set the desired protocol.
|
||||
//
|
||||
AM_REG(TPIU, SPPR) = psConfig->ui32PinProtocol;
|
||||
|
||||
//
|
||||
// Set the parallel port width. This may be redundant if the user has
|
||||
// selected a serial protocol, but we'll set it anyway.
|
||||
//
|
||||
AM_REG(TPIU, CSPSR) = (1 << (psConfig->ui32ParallelPortSize - 1));
|
||||
|
||||
//
|
||||
// Set the clock prescaler.
|
||||
//
|
||||
AM_REG(TPIU, ACPR) = psConfig->ui32ClockPrescaler;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Enables the TPIU
|
||||
//!
|
||||
//! This function enables the ARM TPIU by setting the TPIU registers and then
|
||||
//! enabling the TPIU clock source in MCU control register.
|
||||
//!
|
||||
//! @param psConfig - structure for configuration.
|
||||
//! If ui32SetItmBaud, the other structure members are used to set the
|
||||
//! TPIU configuration.
|
||||
//! But for simplicity, ui32SetItmBaud can be set to one of the
|
||||
//! following, in which case all other structure members are ignored.
|
||||
//! In this case, the given BAUD rate is based on a div-by-8 HFRC clock.
|
||||
//! AM_HAL_TPIU_BAUD_57600
|
||||
//! AM_HAL_TPIU_BAUD_115200
|
||||
//! AM_HAL_TPIU_BAUD_230400
|
||||
//! AM_HAL_TPIU_BAUD_460800
|
||||
//! AM_HAL_TPIU_BAUD_500000
|
||||
//! AM_HAL_TPIU_BAUD_1M
|
||||
//!
|
||||
//! @return None.
|
||||
//
|
||||
//*****************************************************************************
|
||||
void
|
||||
am_hal_tpiu_enable(am_hal_tpiu_config_t *psConfig)
|
||||
{
|
||||
uint32_t ui32HFRC, ui32SWOscaler, ui32ITMbitrate;
|
||||
|
||||
ui32ITMbitrate = psConfig->ui32SetItmBaud;
|
||||
|
||||
//
|
||||
// TPIU formatter & flush control register.
|
||||
//
|
||||
AM_REG(TPIU, FFCR) = 0;
|
||||
|
||||
if ( ui32ITMbitrate )
|
||||
{
|
||||
//
|
||||
// Set the Current Parallel Port Size (note - only 1 bit can be set).
|
||||
//
|
||||
AM_REG(TPIU, CSPSR) = AM_REG_TPIU_CSPSR_CWIDTH_1BIT;
|
||||
|
||||
//
|
||||
// Use some default assumptions to set the ITM frequency.
|
||||
//
|
||||
if ( (ui32ITMbitrate < AM_HAL_TPIU_BAUD_57600 ) ||
|
||||
(ui32ITMbitrate > AM_HAL_TPIU_BAUD_2M ) )
|
||||
{
|
||||
ui32ITMbitrate = AM_HAL_TPIU_BAUD_DEFAULT;
|
||||
}
|
||||
|
||||
//
|
||||
// Get the current HFRC frequency.
|
||||
//
|
||||
ui32HFRC = am_hal_clkgen_sysclk_get();
|
||||
|
||||
//
|
||||
// Compute the SWO scaler value.
|
||||
//
|
||||
if ( ui32HFRC != 0xFFFFFFFF )
|
||||
{
|
||||
ui32SWOscaler = ((ui32HFRC / 8) / ui32ITMbitrate) - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
ui32SWOscaler = ( (AM_HAL_CLKGEN_FREQ_MAX_HZ / 8) /
|
||||
AM_HAL_TPIU_BAUD_DEFAULT ) - 1;
|
||||
}
|
||||
|
||||
//
|
||||
// Set the scaler value.
|
||||
//
|
||||
AM_REG(TPIU, ACPR) = AM_REG_TPIU_ACPR_SWOSCALER(ui32SWOscaler);
|
||||
|
||||
//
|
||||
// Set for UART mode
|
||||
//
|
||||
AM_REG(TPIU, SPPR) = AM_REG_TPIU_SPPR_TXMODE_UART;
|
||||
|
||||
//
|
||||
// Make sure we are not in test mode (important for proper deep sleep
|
||||
// operation).
|
||||
//
|
||||
AM_REG(TPIU, ITCTRL) = AM_REG_TPIU_ITCTRL_MODE_NORMAL;
|
||||
|
||||
//
|
||||
// Enable the TPIU clock source in MCU control.
|
||||
// Set TPIU clock for HFRC/8 (6 or 3 MHz) operation.
|
||||
//
|
||||
AM_REGn(MCUCTRL, 0, TPIUCTRL) =
|
||||
AM_REG_MCUCTRL_TPIUCTRL_CLKSEL_HFRC_DIV_8 |
|
||||
AM_REG_MCUCTRL_TPIUCTRL_ENABLE_EN;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// Set the configuration according to the structure values.
|
||||
//
|
||||
|
||||
//
|
||||
// Set the Asynchronous Clock Prescaler Register.
|
||||
//
|
||||
AM_REG(TPIU, ACPR) = psConfig->ui32ClockPrescaler;
|
||||
|
||||
//
|
||||
// Set the Selected Pin Protocol Register.
|
||||
// e.g. AM_REG_TPIU_SPPR_TXMODE_UART
|
||||
//
|
||||
AM_REG(TPIU, SPPR) = psConfig->ui32PinProtocol;
|
||||
|
||||
//
|
||||
// Set the Current Parallel Port Size (note - only 1 bit can be set).
|
||||
// This may be redundant if the user has selected a serial protocol,
|
||||
// but we'll set it anyway.
|
||||
//
|
||||
AM_REG(TPIU, CSPSR) = (1 << (psConfig->ui32ParallelPortSize - 1));
|
||||
|
||||
//
|
||||
// Set the clock freq in the MCUCTRL register.
|
||||
//
|
||||
AM_REG(MCUCTRL, TPIUCTRL) |= psConfig->ui32TraceClkIn;
|
||||
}
|
||||
|
||||
//
|
||||
// Wait for 50us for the data to flush out.
|
||||
//
|
||||
am_hal_itm_delay_us(50);
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Disables the TPIU
|
||||
//!
|
||||
//! This function disables the ARM TPIU by disabling the TPIU clock source
|
||||
//! in MCU control register.
|
||||
//!
|
||||
//! @return None.
|
||||
//
|
||||
//*****************************************************************************
|
||||
void
|
||||
am_hal_tpiu_disable(void)
|
||||
{
|
||||
//
|
||||
// Disable the TPIU clock source in MCU control.
|
||||
//
|
||||
AM_REG(MCUCTRL, TPIUCTRL) = AM_REG_MCUCTRL_TPIUCTRL_CLKSEL_0MHz |
|
||||
AM_REG_MCUCTRL_TPIUCTRL_ENABLE_DIS;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// End Doxygen group.
|
||||
//! @}
|
||||
//
|
||||
//*****************************************************************************
|
||||
@@ -0,0 +1,193 @@
|
||||
//*****************************************************************************
|
||||
//
|
||||
// am_hal_tpiu.h
|
||||
//! @file
|
||||
//!
|
||||
//! @brief Definitions and structures for working with the TPIU.
|
||||
//!
|
||||
//! @addtogroup tpiu2 Trace Port Interface Unit (TPIU)
|
||||
//! @ingroup apollo2hal
|
||||
//! @{
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Copyright (c) 2017, Ambiq Micro
|
||||
// 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.
|
||||
//
|
||||
// This is part of revision 1.2.9 of the AmbiqSuite Development Package.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#ifndef AM_HAL_TPIU_H
|
||||
#define AM_HAL_TPIU_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// TPIU bit rate defines.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define AM_HAL_TPIU_BAUD_57600 (115200 / 2)
|
||||
#define AM_HAL_TPIU_BAUD_115200 (115200 * 1)
|
||||
#define AM_HAL_TPIU_BAUD_230400 (115200 * 2)
|
||||
#define AM_HAL_TPIU_BAUD_460800 (115200 * 4)
|
||||
#define AM_HAL_TPIU_BAUD_500000 (1000000 / 2)
|
||||
#define AM_HAL_TPIU_BAUD_1M (1000000 * 1)
|
||||
#define AM_HAL_TPIU_BAUD_2M (1000000 * 2)
|
||||
#define AM_HAL_TPIU_BAUD_DEFAULT (AM_HAL_TPIU_BAUD_1M)
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// TPIU register defines.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define AM_HAL_TPIU_SSPSR 0xE0040000 //! Supported Parallel Port Sizes
|
||||
#define AM_HAL_TPIU_CSPSR 0xE0040004 //! Current Parallel Port Size
|
||||
#define AM_HAL_TPIU_ACPR 0xE0040010 //! Asynchronous Clock Prescaler
|
||||
#define AM_HAL_TPIU_SPPR 0xE00400F0 //! Selected Pin Protocol
|
||||
#define AM_HAL_TPIU_TYPE 0xE0040FC8 //! TPIU Type
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// TPIU ACPR defines.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define AM_HAL_TPIU_ACPR_SWOSCALER_M 0x0000FFFF //! SWO baud rate prescalar
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// TPIU_SPPR TXMODE defines.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define AM_HAL_TPIU_SPPR_PARALLEL 0x00000000
|
||||
#define AM_HAL_TPIU_SPPR_MANCHESTER 0x00000001
|
||||
#define AM_HAL_TPIU_SPPR_NRZ 0x00000002
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// TPIU Type defines
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define AM_HAL_TPIU_TYPE_NRZVALID 0x00000800
|
||||
#define AM_HAL_TPIU_TYPE_MANCVALID 0x00000400
|
||||
#define AM_HAL_TPIU_TYPE_PTINVALID 0x00000200
|
||||
#define AM_HAL_TPIU_TYPE_FIFOSZ_M 0x000001C0
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// TPIU Clock defines
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define AM_HAL_TPIU_TRACECLKIN_6MHZ AM_REG_MCUCTRL_TPIUCTRL_TPIUCLKSEL(0)
|
||||
#define AM_HAL_TPIU_TRACECLKIN_3MHZ AM_REG_MCUCTRL_TPIUCTRL_TPIUCLKSEL(1)
|
||||
#define AM_HAL_TPIU_TRACECLKIN_1_5MHZ AM_REG_MCUCTRL_TPIUCTRL_TPIUCLKSEL(2)
|
||||
#define AM_HAL_TPIU_TRACECLKIN_750KHZ AM_REG_MCUCTRL_TPIUCTRL_TPIUCLKSEL(3)
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief Structure used for configuring the TPIU
|
||||
//
|
||||
//*****************************************************************************
|
||||
typedef struct
|
||||
{
|
||||
//
|
||||
// If ui32SetItmBaud is non-zero, the ITM frequency is set to the given
|
||||
// frequency, and is based on a divide-by-8 HFRC TPIU clock.
|
||||
// If zero, other structure members are used to set the TPIU configuration.
|
||||
//
|
||||
uint32_t ui32SetItmBaud;
|
||||
|
||||
//
|
||||
//! MCU Control TRACECLKIN clock freq.
|
||||
//!
|
||||
//! Valid values for ui32TraceClkIn are:
|
||||
//!
|
||||
//! AM_HAL_TPIU_TRACECLKIN_6MHZ
|
||||
//! AM_HAL_TPIU_TRACECLKIN_3MHZ
|
||||
//! AM_HAL_TPIU_TRACECLKIN_1_5MHZ
|
||||
//! AM_HAL_TPIU_TRACECLKIN_750KHZ
|
||||
//
|
||||
uint32_t ui32TraceClkIn;
|
||||
|
||||
//
|
||||
//! Protocol to use for the TPIU
|
||||
//!
|
||||
//! Valid values for ui32PinProtocol are:
|
||||
//!
|
||||
//! AM_HAL_TPIU_SPPR_PARALLEL
|
||||
//! AM_HAL_TPIU_SPPR_MANCHESTER
|
||||
//! AM_HAL_TPIU_SPPR_NRZ
|
||||
//
|
||||
uint32_t ui32PinProtocol;
|
||||
|
||||
//
|
||||
//! Desired width of the TPIU parallel port
|
||||
//
|
||||
uint32_t ui32ParallelPortSize;
|
||||
|
||||
//
|
||||
//! Desired Clock prescaler value
|
||||
//
|
||||
uint32_t ui32ClockPrescaler;
|
||||
}
|
||||
am_hal_tpiu_config_t;
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// External function definitions
|
||||
//
|
||||
//*****************************************************************************
|
||||
extern void am_hal_tpiu_clock_enable(void);
|
||||
extern void am_hal_tpiu_clock_disable(void);
|
||||
extern void am_hal_tpiu_port_width_set(uint32_t ui32PortWidth);
|
||||
extern uint32_t am_hal_tpiu_supported_port_width_get(void);
|
||||
extern uint32_t am_hal_tpiu_port_width_get(void);
|
||||
extern void am_hal_tpiu_configure(am_hal_tpiu_config_t *psConfig);
|
||||
extern void am_hal_tpiu_enable(am_hal_tpiu_config_t *psConfig);
|
||||
extern void am_hal_tpiu_disable(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // AM_HAL_TPIU_H
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// End Doxygen group.
|
||||
//! @}
|
||||
//
|
||||
//*****************************************************************************
|
||||
@@ -0,0 +1,205 @@
|
||||
//*****************************************************************************
|
||||
//
|
||||
// am_hal_ttp.c
|
||||
//! @file
|
||||
//!
|
||||
//! @brief Functions for handling the "two time program" interface.
|
||||
//!
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Copyright (c) 2017, Ambiq Micro
|
||||
// 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.
|
||||
//
|
||||
// This is part of revision 1.2.9 of the AmbiqSuite Development Package.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#include "am_mcu_apollo.h"
|
||||
#include "am_hal_ttp.h"
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Local constants
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define TTP_ADDR 0x50020000
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Local prototypes
|
||||
//
|
||||
//*****************************************************************************
|
||||
#if !defined(__GNUC__)
|
||||
void __breakpoint(int val);
|
||||
#endif
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// A function to verify that the TTP was saved and/or restored properly.
|
||||
//
|
||||
//*****************************************************************************
|
||||
int
|
||||
verifyTTPSaved(uint32_t *pSaveArray, int iNumWords)
|
||||
{
|
||||
int ix, iErrCnt = 0;
|
||||
uint32_t *pDataSpace = (uint32_t*)TTP_ADDR;
|
||||
|
||||
for (ix = 0; ix<iNumWords; ix++)
|
||||
{
|
||||
if ( *pSaveArray != am_hal_flash_load_ui32((uint32_t)pDataSpace) )
|
||||
{
|
||||
iErrCnt++;
|
||||
}
|
||||
pSaveArray++;
|
||||
pDataSpace++;
|
||||
}
|
||||
|
||||
//
|
||||
// Hopefully returning 0.
|
||||
//
|
||||
return iErrCnt;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! @brief TTP unlock.
|
||||
//!
|
||||
//! @param ui32Keyval - The key value to unlock the interface.
|
||||
//! @param pui8_1024Bytes - A pointer to a 1024 bytes array, used for
|
||||
//! temporary data storage.
|
||||
//! WARNING This area must be 32-bit aligned and at
|
||||
//! least 1024 bytes long.
|
||||
//!
|
||||
//! This function is used to unlock the TTP ability.
|
||||
//!
|
||||
//! @return None.
|
||||
//
|
||||
//*****************************************************************************
|
||||
int
|
||||
am_hal_ttp_unlock(uint32_t ui32Keyval, uint8_t *pui8_1024Bytes)
|
||||
{
|
||||
int iErrCnt = 0;
|
||||
int ix, iRet;
|
||||
int iNumWords = 1024 / 4;
|
||||
uint32_t *pSaveArray, *pDataSpace;
|
||||
int (*pTTPClear)(uint32_t, uint32_t) = (int (*)(uint32_t, uint32_t))0x080002EF;
|
||||
int (*pTTPSet)(uint32_t, uint32_t, uint32_t*, uint32_t, uint32_t) =
|
||||
(int (*)(uint32_t, uint32_t, uint32_t*, uint32_t, uint32_t))0x080006FF;
|
||||
|
||||
//
|
||||
// Save off the data.
|
||||
//
|
||||
pSaveArray = (uint32_t*)pui8_1024Bytes;
|
||||
pDataSpace = (uint32_t*)TTP_ADDR;
|
||||
for (ix = 0; ix < iNumWords; ix++)
|
||||
{
|
||||
*pSaveArray = am_hal_flash_load_ui32((uint32_t)pDataSpace);
|
||||
pSaveArray++;
|
||||
pDataSpace++;
|
||||
}
|
||||
|
||||
//
|
||||
// Before proceeding, make sure that we captured the data correctly.
|
||||
//
|
||||
iErrCnt += verifyTTPSaved((uint32_t*)pui8_1024Bytes, iNumWords);
|
||||
if ( iErrCnt )
|
||||
{
|
||||
return 0x10000001;
|
||||
}
|
||||
|
||||
//
|
||||
// Erase the TTP area.
|
||||
//
|
||||
iRet = (*pTTPClear)(0, ui32Keyval);
|
||||
if ( iRet != 0 )
|
||||
{
|
||||
iErrCnt++;
|
||||
return 0x10000002;
|
||||
}
|
||||
|
||||
//
|
||||
// The point of no return! The TTP space is successfully erased.
|
||||
// Let's make sure.
|
||||
//
|
||||
pDataSpace = (uint32_t*)TTP_ADDR;
|
||||
for (ix = 0; ix < iNumWords; ix++)
|
||||
{
|
||||
if ( am_hal_flash_load_ui32((uint32_t)pDataSpace) != 0xffffffff )
|
||||
{
|
||||
iErrCnt++;
|
||||
}
|
||||
pDataSpace++;
|
||||
}
|
||||
|
||||
if ( iErrCnt )
|
||||
{
|
||||
return 0x10000003;
|
||||
}
|
||||
|
||||
//
|
||||
// Restore the TTP block from the saved data.
|
||||
//
|
||||
iRet = (*pTTPSet)(ui32Keyval, 0, (uint32_t*)pui8_1024Bytes, 0, iNumWords);
|
||||
if ( iRet != 0 )
|
||||
{
|
||||
iErrCnt++;
|
||||
return 0x10000004;
|
||||
}
|
||||
|
||||
//
|
||||
// Now, check the restored INFO data.
|
||||
//
|
||||
iRet = verifyTTPSaved((uint32_t*)pui8_1024Bytes, iNumWords);
|
||||
if ( iRet )
|
||||
{
|
||||
iErrCnt++;
|
||||
return 0x10000005;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// All good. The device was successfully recovered.
|
||||
//
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Return with error count (hopefully 0).
|
||||
//
|
||||
return iErrCnt;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// End Doxygen group.
|
||||
//! @}
|
||||
//
|
||||
//*****************************************************************************
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user