first console project

This commit is contained in:
supperthomas
2021-02-11 04:51:35 +08:00
parent 0fe8fccfbd
commit abcac46fcf
76 changed files with 21199 additions and 13707 deletions
@@ -0,0 +1,24 @@
/*
* Auto generated Run-Time-Environment Component Configuration File
* *** Do not modify ! ***
*
* Project: 'Hello_World'
* Target: 'Debug'
*/
#ifndef RTE_COMPONENTS_H
#define RTE_COMPONENTS_H
/*
* Define the Device Header File:
*/
#define CMSIS_device_header "max32660.h"
#define BOARD EvKit_V1 /* Target Board */
#define RTE_USING_FINSH
#define TARGET 32660 /* Target Device Part Number */
#define TARGET_REV 0x4131 /* Target Device Revision Number */
#endif /* RTE_COMPONENTS_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
+283
View File
@@ -0,0 +1,283 @@
/**************************************************************************//**
* @file cmsis_compiler.h
* @brief CMSIS compiler generic header file
* @version V5.1.0
* @date 09. October 2018
******************************************************************************/
/*
* Copyright (c) 2009-2018 Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __CMSIS_COMPILER_H
#define __CMSIS_COMPILER_H
#include <stdint.h>
/*
* Arm Compiler 4/5
*/
#if defined ( __CC_ARM )
#include "cmsis_armcc.h"
/*
* Arm Compiler 6.6 LTM (armclang)
*/
#elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) && (__ARMCC_VERSION < 6100100)
#include "cmsis_armclang_ltm.h"
/*
* Arm Compiler above 6.10.1 (armclang)
*/
#elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6100100)
#include "cmsis_armclang.h"
/*
* GNU Compiler
*/
#elif defined ( __GNUC__ )
#include "cmsis_gcc.h"
/*
* IAR Compiler
*/
#elif defined ( __ICCARM__ )
#include <cmsis_iccarm.h>
/*
* TI Arm Compiler
*/
#elif defined ( __TI_ARM__ )
#include <cmsis_ccs.h>
#ifndef __ASM
#define __ASM __asm
#endif
#ifndef __INLINE
#define __INLINE inline
#endif
#ifndef __STATIC_INLINE
#define __STATIC_INLINE static inline
#endif
#ifndef __STATIC_FORCEINLINE
#define __STATIC_FORCEINLINE __STATIC_INLINE
#endif
#ifndef __NO_RETURN
#define __NO_RETURN __attribute__((noreturn))
#endif
#ifndef __USED
#define __USED __attribute__((used))
#endif
#ifndef __WEAK
#define __WEAK __attribute__((weak))
#endif
#ifndef __PACKED
#define __PACKED __attribute__((packed))
#endif
#ifndef __PACKED_STRUCT
#define __PACKED_STRUCT struct __attribute__((packed))
#endif
#ifndef __PACKED_UNION
#define __PACKED_UNION union __attribute__((packed))
#endif
#ifndef __UNALIGNED_UINT32 /* deprecated */
struct __attribute__((packed)) T_UINT32 { uint32_t v; };
#define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
#endif
#ifndef __UNALIGNED_UINT16_WRITE
__PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
#define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void*)(addr))->v) = (val))
#endif
#ifndef __UNALIGNED_UINT16_READ
__PACKED_STRUCT T_UINT16_READ { uint16_t v; };
#define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
#endif
#ifndef __UNALIGNED_UINT32_WRITE
__PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
#define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
#endif
#ifndef __UNALIGNED_UINT32_READ
__PACKED_STRUCT T_UINT32_READ { uint32_t v; };
#define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
#endif
#ifndef __ALIGNED
#define __ALIGNED(x) __attribute__((aligned(x)))
#endif
#ifndef __RESTRICT
#define __RESTRICT __restrict
#endif
#ifndef __COMPILER_BARRIER
#warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored.
#define __COMPILER_BARRIER() (void)0
#endif
/*
* TASKING Compiler
*/
#elif defined ( __TASKING__ )
/*
* The CMSIS functions have been implemented as intrinsics in the compiler.
* Please use "carm -?i" to get an up to date list of all intrinsics,
* Including the CMSIS ones.
*/
#ifndef __ASM
#define __ASM __asm
#endif
#ifndef __INLINE
#define __INLINE inline
#endif
#ifndef __STATIC_INLINE
#define __STATIC_INLINE static inline
#endif
#ifndef __STATIC_FORCEINLINE
#define __STATIC_FORCEINLINE __STATIC_INLINE
#endif
#ifndef __NO_RETURN
#define __NO_RETURN __attribute__((noreturn))
#endif
#ifndef __USED
#define __USED __attribute__((used))
#endif
#ifndef __WEAK
#define __WEAK __attribute__((weak))
#endif
#ifndef __PACKED
#define __PACKED __packed__
#endif
#ifndef __PACKED_STRUCT
#define __PACKED_STRUCT struct __packed__
#endif
#ifndef __PACKED_UNION
#define __PACKED_UNION union __packed__
#endif
#ifndef __UNALIGNED_UINT32 /* deprecated */
struct __packed__ T_UINT32 { uint32_t v; };
#define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
#endif
#ifndef __UNALIGNED_UINT16_WRITE
__PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
#define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
#endif
#ifndef __UNALIGNED_UINT16_READ
__PACKED_STRUCT T_UINT16_READ { uint16_t v; };
#define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
#endif
#ifndef __UNALIGNED_UINT32_WRITE
__PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
#define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
#endif
#ifndef __UNALIGNED_UINT32_READ
__PACKED_STRUCT T_UINT32_READ { uint32_t v; };
#define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
#endif
#ifndef __ALIGNED
#define __ALIGNED(x) __align(x)
#endif
#ifndef __RESTRICT
#warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
#define __RESTRICT
#endif
#ifndef __COMPILER_BARRIER
#warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored.
#define __COMPILER_BARRIER() (void)0
#endif
/*
* COSMIC Compiler
*/
#elif defined ( __CSMC__ )
#include <cmsis_csm.h>
#ifndef __ASM
#define __ASM _asm
#endif
#ifndef __INLINE
#define __INLINE inline
#endif
#ifndef __STATIC_INLINE
#define __STATIC_INLINE static inline
#endif
#ifndef __STATIC_FORCEINLINE
#define __STATIC_FORCEINLINE __STATIC_INLINE
#endif
#ifndef __NO_RETURN
// NO RETURN is automatically detected hence no warning here
#define __NO_RETURN
#endif
#ifndef __USED
#warning No compiler specific solution for __USED. __USED is ignored.
#define __USED
#endif
#ifndef __WEAK
#define __WEAK __weak
#endif
#ifndef __PACKED
#define __PACKED @packed
#endif
#ifndef __PACKED_STRUCT
#define __PACKED_STRUCT @packed struct
#endif
#ifndef __PACKED_UNION
#define __PACKED_UNION @packed union
#endif
#ifndef __UNALIGNED_UINT32 /* deprecated */
@packed struct T_UINT32 { uint32_t v; };
#define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
#endif
#ifndef __UNALIGNED_UINT16_WRITE
__PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
#define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
#endif
#ifndef __UNALIGNED_UINT16_READ
__PACKED_STRUCT T_UINT16_READ { uint16_t v; };
#define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
#endif
#ifndef __UNALIGNED_UINT32_WRITE
__PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
#define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
#endif
#ifndef __UNALIGNED_UINT32_READ
__PACKED_STRUCT T_UINT32_READ { uint32_t v; };
#define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
#endif
#ifndef __ALIGNED
#warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored.
#define __ALIGNED(x)
#endif
#ifndef __RESTRICT
#warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
#define __RESTRICT
#endif
#ifndef __COMPILER_BARRIER
#warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored.
#define __COMPILER_BARRIER() (void)0
#endif
#else
#error Unknown compiler.
#endif
#endif /* __CMSIS_COMPILER_H */
+39
View File
@@ -0,0 +1,39 @@
/**************************************************************************//**
* @file cmsis_version.h
* @brief CMSIS Core(M) Version definitions
* @version V5.0.4
* @date 23. July 2019
******************************************************************************/
/*
* Copyright (c) 2009-2019 ARM Limited. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if defined ( __ICCARM__ )
#pragma system_include /* treat file as system include file for MISRA check */
#elif defined (__clang__)
#pragma clang system_header /* treat file as system include file */
#endif
#ifndef __CMSIS_VERSION_H
#define __CMSIS_VERSION_H
/* CMSIS Version definitions */
#define __CM_CMSIS_VERSION_MAIN ( 5U) /*!< [31:16] CMSIS Core(M) main version */
#define __CM_CMSIS_VERSION_SUB ( 4U) /*!< [15:0] CMSIS Core(M) sub version */
#define __CM_CMSIS_VERSION ((__CM_CMSIS_VERSION_MAIN << 16U) | \
__CM_CMSIS_VERSION_SUB ) /*!< CMSIS Core(M) version number */
#endif
File diff suppressed because it is too large Load Diff
+403
View File
@@ -0,0 +1,403 @@
/**
* @file max32660.h
* @brief Device-specific perhiperal header file
*/
/*******************************************************************************
* Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Maxim Integrated
* Products, Inc. shall not be used except as stated in the Maxim Integrated
* Products, Inc. Branding Policy.
*
* The mere transfer of this software does not imply any licenses
* of trade secrets, proprietary technology, copyrights, patents,
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*
* $Date: 2018-12-18 15:37:22 -0600 (Tue, 18 Dec 2018) $
* $Revision: 40072 $
*
******************************************************************************/
#ifndef _MAX32660_REGS_H_
#define _MAX32660_REGS_H_
#ifndef TARGET_NUM
#define TARGET_NUM 32660
#endif
#include <stdint.h>
#ifndef FALSE
#define FALSE (0)
#endif
#ifndef TRUE
#define TRUE (1)
#endif
#if !defined (__GNUC__)
#define CMSIS_VECTAB_VIRTUAL
#define CMSIS_VECTAB_VIRTUAL_HEADER_FILE "nvic_table.h"
#endif /* !__GNUC__ */
/* COMPILER SPECIFIC DEFINES (IAR, ARMCC and GNUC) */
#if defined ( __GNUC__ ) /* GCC */
#define __weak __attribute__((weak))
#elif defined ( __CC_ARM) /* Keil */
#define inline __inline
#pragma anon_unions
#endif
typedef enum {
NonMaskableInt_IRQn = -14,
HardFault_IRQn = -13,
MemoryManagement_IRQn = -12,
BusFault_IRQn = -11,
UsageFault_IRQn = -10,
SVCall_IRQn = -5,
DebugMonitor_IRQn = -4,
PendSV_IRQn = -2,
SysTick_IRQn = -1,
/* Device-specific interrupt sources (external to ARM core) */
/* table entry number */
/* |||| */
/* |||| table offset address */
/* vvvv vvvvvv */
PF_IRQn = 0, /* 0x10 0x0040 16: Power Fail */
WDT0_IRQn, /* 0x11 0x0044 17: Watchdog 0 */
RSV00_IRQn, /* 0x12 0x0048 18: RSV00 */
RTC_IRQn, /* 0x13 0x004C 19: RTC */
RSV1_IRQn, /* 0x14 0x0050 20: RSV1 */
TMR0_IRQn, /* 0x15 0x0054 21: Timer 0 */
TMR1_IRQn, /* 0x16 0x0058 22: Timer 1 */
TMR2_IRQn, /* 0x17 0x005C 23: Timer 2 */
RSV02_IRQn, /* 0x18 0x0060 24: RSV02 */
RSV03_IRQn, /* 0x19 0x0064 25: RSV03 */
RSV04_IRQn, /* 0x1A 0x0068 26: RSV04 */
RSV05_IRQn, /* 0x1B 0x006C 27: RSV05 */
RSV06_IRQn, /* 0x1C 0x0070 28: RSV06 */
I2C0_IRQn, /* 0x1D 0x0074 29: I2C0 */
UART0_IRQn, /* 0x1E 0x0078 30: UART 0 */
UART1_IRQn, /* 0x1F 0x007C 31: UART 1 */
SPI17Y_IRQn, /* 0x20 0x0080 32: SPI17Y */
SPIMSS_IRQn, /* 0x21 0x0084 33: SPIMSS */
RSV07_IRQn, /* 0x22 0x0088 34: RSV07 */
RSV08_IRQn, /* 0x23 0x008C 35: RSV08 */
RSV09_IRQn, /* 0x24 0x0090 36: RSV09 */
RSV10_IRQn, /* 0x25 0x0094 37: RSV10 */
RSV11_IRQn, /* 0x26 0x0098 38: RSV11 */
FLC_IRQn, /* 0x27 0x009C 39: FLC */
GPIO0_IRQn, /* 0x28 0x00A0 40: GPIO0 */
RSV12_IRQn, /* 0x29 0x00A4 41: RSV12 */
RSV13_IRQn, /* 0x2A 0x00A8 42: RSV13 */
RSV14_IRQn, /* 0x2B 0x00AC 43: RSV14 */
DMA0_IRQn, /* 0x2C 0x00B0 44: DMA0 */
DMA1_IRQn, /* 0x2D 0x00B4 45: DMA1 */
DMA2_IRQn, /* 0x2E 0x00B8 46: DMA2 */
DMA3_IRQn, /* 0x2F 0x00BC 47: DMA3 */
RSV15_IRQn, /* 0x30 0x00C0 48: RSV15 */
RSV16_IRQn, /* 0x31 0x00C4 49: RSV16 */
RSV17_IRQn, /* 0x32 0x00C8 50: RSV17 */
RSV18_IRQn, /* 0x33 0x00CC 51: RSV18 */
I2C1_IRQn, /* 0x34 0x00D0 52: I2C1 */
RSV19_IRQn, /* 0x35 0x00D4 53: RSV19 */
RSV20_IRQn, /* 0x36 0x00D8 54: RSV20 */
RSV21_IRQn, /* 0x37 0x00DC 55: RSV21 */
RSV22_IRQn, /* 0x38 0x00E0 56: RSV22 */
RSV23_IRQn, /* 0x39 0x00E4 57: RSV23 */
RSV24_IRQn, /* 0x3A 0x00E8 58: RSV24 */
RSV25_IRQn, /* 0x3B 0x00EC 59: RSV25 */
RSV26_IRQn, /* 0x3C 0x00F0 60: RSV26 */
RSV27_IRQn, /* 0x3D 0x00F4 61: RSV27 */
RSV28_IRQn, /* 0x3E 0x00F8 62: RSV28 */
RSV29_IRQn, /* 0x3F 0x00FC 63: RSV29 */
RSV30_IRQn, /* 0x40 0x0100 64: RSV30 */
RSV31_IRQn, /* 0x41 0x0104 65: RSV31 */
RSV32_IRQn, /* 0x42 0x0108 66: RSV32 */
RSV33_IRQn, /* 0x43 0x010C 67: RSV33 */
RSV34_IRQn, /* 0x44 0x0110 68: RSV34 */
RSV35_IRQn, /* 0x45 0x0114 69: RSV35 */
GPIOWAKE_IRQn, /* 0x46 0x0118 70: GPIO Wakeup */
MXC_IRQ_EXT_COUNT,
} IRQn_Type;
#define MXC_IRQ_COUNT (MXC_IRQ_EXT_COUNT + 16)
/* ================================================================================ */
/* ================ Processor and Core Peripheral Section ================ */
/* ================================================================================ */
/* ---------------------- Configuration of the Cortex-M Processor and Core Peripherals ---------------------- */
#define __CM4_REV 0x0100 /*!< Cortex-M4 Core Revision */
#define __MPU_PRESENT 1 /*!< MPU present or not */
#define __NVIC_PRIO_BITS 3 /*!< Number of Bits used for Priority Levels */
#define __Vendor_SysTickConfig 0 /*!< Set to 1 if different SysTick Config is used */
#define __FPU_PRESENT 1 /*!< FPU present or not */
#include <core_cm4.h> /*!< Cortex-M4 processor and core peripherals */
#include "system_max32660.h" /*!< System Header */
/* ================================================================================ */
/* ================== Device Specific Memory Section ================== */
/* ================================================================================ */
#define MXC_FLASH_MEM_BASE 0x00000000UL
#define MXC_FLASH_PAGE_SIZE 0x00002000UL
#define MXC_FLASH_MEM_SIZE 0x00040000UL
#define MXC_INFO_MEM_BASE 0x00040000UL
#define MXC_INFO_MEM_SIZE 0x00001000UL
#define MXC_SRAM_MEM_BASE 0x20000000UL
#define MXC_SRAM_MEM_SIZE 0x00018000UL
/* ================================================================================ */
/* ================ Device Specific Peripheral Section ================ */
/* ================================================================================ */
/*
Base addresses and configuration settings for all MAX32660 peripheral modules.
*/
/******************************************************************************/
/* Global control */
#define MXC_BASE_GCR ((uint32_t)0x40000000UL)
#define MXC_GCR ((mxc_gcr_regs_t*)MXC_BASE_GCR)
/******************************************************************************/
/* Non-battery backed SI Registers */
#define MXC_BASE_SIR ((uint32_t)0x40000400UL)
#define MXC_SIR ((mxc_sir_regs_t*)MXC_BASE_SIR)
/******************************************************************************/
/* Watchdog */
#define MXC_BASE_WDT0 ((uint32_t)0x40003000UL)
#define MXC_WDT0 ((mxc_wdt_regs_t*)MXC_BASE_WDT0)
/******************************************************************************/
/* Real Time Clock */
#define MXC_BASE_RTC ((uint32_t)0x40006000UL)
#define MXC_RTC ((mxc_rtc_regs_t*)MXC_BASE_RTC)
/******************************************************************************/
/* Power Sequencer */
#define MXC_BASE_PWRSEQ ((uint32_t)0x40006800UL)
#define MXC_PWRSEQ ((mxc_pwrseq_regs_t*)MXC_BASE_PWRSEQ)
/******************************************************************************/
/* GPIO */
#define MXC_CFG_GPIO_INSTANCES (1)
#define MXC_CFG_GPIO_PINS_PORT (14)
#define MXC_BASE_GPIO0 ((uint32_t)0x40008000UL)
#define MXC_GPIO0 ((mxc_gpio_regs_t*)MXC_BASE_GPIO0)
#define MXC_GPIO_GET_IDX(p) ((p) == MXC_GPIO0 ? 0 :-1)
#define MXC_GPIO_GET_GPIO(i) ((i) == 0 ? MXC_GPIO0 : 0)
#define MXC_GPIO_GET_IRQ(i) ((i) == 0 ? GPIO0_IRQn : 0)
/******************************************************************************/
/* Timer */
#define MXC_CFG_TMR_INSTANCES (3)
#define MXC_BASE_TMR0 ((uint32_t)0x40010000UL)
#define MXC_TMR0 ((mxc_tmr_regs_t*)MXC_BASE_TMR0)
#define MXC_BASE_TMR1 ((uint32_t)0x40011000UL)
#define MXC_TMR1 ((mxc_tmr_regs_t*)MXC_BASE_TMR1)
#define MXC_BASE_TMR2 ((uint32_t)0x40012000UL)
#define MXC_TMR2 ((mxc_tmr_regs_t*)MXC_BASE_TMR2)
#define MXC_TMR_GET_IRQ(i) (IRQn_Type)((i) == 0 ? TMR0_IRQn : \
(i) == 1 ? TMR1_IRQn : \
(i) == 2 ? TMR2_IRQn : 0)
#define MXC_TMR_GET_BASE(i) ((i) == 0 ? MXC_BASE_TMR0 : \
(i) == 1 ? MXC_BASE_TMR1 : \
(i) == 2 ? MXC_BASE_TMR2 : 0)
#define MXC_TMR_GET_TMR(i) ((i) == 0 ? MXC_TMR0 : \
(i) == 1 ? MXC_TMR1 : \
(i) == 2 ? MXC_TMR2 : 0)
#define MXC_TMR_GET_IDX(p) ((p) == MXC_TMR0 ? 0 : \
(p) == MXC_TMR1 ? 1 : \
(p) == MXC_TMR2 ? 2 : -1)
/******************************************************************************/
/* SPIMSS */
#define MXC_SPIMSS_INSTANCES (1)
#define MXC_SPIMSS_FIFO_DEPTH (8)
#define MXC_BASE_SPIMSS ((uint32_t)0x40019000UL)
#define MXC_SPIMSS ((mxc_spimss_regs_t*)MXC_BASE_SPIMSS)
#define MXC_SPIMSS_GET_IDX(p) ((p) == MXC_SPIMSS ? 0 : -1)
#define MXC_SPIMSS_GET_SPI(i) ((i) == 0 ? MXC_SPIMSS : 0)
/******************************************************************************/
/* I2C */
#define MXC_I2C_INSTANCES (2)
#define MXC_I2C_FIFO_DEPTH (8)
#define MXC_BASE_I2C0 ((uint32_t)0x4001D000UL)
#define MXC_I2C0 ((mxc_i2c_regs_t*)MXC_BASE_I2C0)
#define MXC_BASE_I2C1 ((uint32_t)0x4001E000UL)
#define MXC_I2C1 ((mxc_i2c_regs_t*)MXC_BASE_I2C1)
#define MXC_I2C_GET_IRQ(i) (IRQn_Type)((i) == 0 ? I2C0_IRQn : \
(i) == 1 ? I2C1_IRQn : 0)
#define MXC_I2C_GET_BASE(i) ((i) == 0 ? MXC_BASE_I2C0 : \
(i) == 1 ? MXC_BASE_I2C1 : 0)
#define MXC_I2C_GET_I2C(i) ((i) == 0 ? MXC_I2C0 : \
(i) == 1 ? MXC_I2C1 : 0)
#define MXC_I2C_GET_IDX(p) ((p) == MXC_I2C0 ? 0 : \
(p) == MXC_I2C1 ? 1 : -1)
/******************************************************************************/
/* DMA */
#define MXC_DMA_CHANNELS (4)
#define MXC_BASE_DMA ((uint32_t)0x40028000UL)
#define MXC_DMA ((mxc_dma_regs_t*)MXC_BASE_DMA)
/******************************************************************************/
/* FLC */
#define MXC_BASE_FLC ((uint32_t)0x40029000UL)
#define MXC_FLC ((mxc_flc_regs_t*)MXC_BASE_FLC)
/******************************************************************************/
/* Instruction Cache */
#define MXC_BASE_ICC ((uint32_t)0x4002A000UL)
#define MXC_ICC ((mxc_icc_regs_t*)MXC_BASE_ICC)
/******************************************************************************/
/* UART / Serial Port Interface */
#define MXC_UART_INSTANCES (2)
#define MXC_UART_FIFO_DEPTH (8)
#define MXC_BASE_UART0 ((uint32_t)0x40042000UL)
#define MXC_UART0 ((mxc_uart_regs_t*)MXC_BASE_UART0)
#define MXC_BASE_UART1 ((uint32_t)0x40043000UL)
#define MXC_UART1 ((mxc_uart_regs_t*)MXC_BASE_UART1)
#define MXC_UART_GET_IRQ(i) (IRQn_Type)((i) == 0 ? UART0_IRQn : \
(i) == 1 ? UART1_IRQn : 0)
#define MXC_UART_GET_BASE(i) ((i) == 0 ? MXC_BASE_UART0 : \
(i) == 1 ? MXC_BASE_UART1 : 0)
#define MXC_UART_GET_UART(i) ((i) == 0 ? MXC_UART0 : \
(i) == 1 ? MXC_UART1 : 0)
#define MXC_UART_GET_IDX(p) ((p) == MXC_UART0 ? 0 : \
(p) == MXC_UART1 ? 1 : -1)
/******************************************************************************/
/* SPI */
#define MXC_SPI17Y_INSTANCES (4)
#define MXC_SPI17Y_SS_INSTANCES (1)
#define MXC_SPI17Y_FIFO_DEPTH (32)
#define MXC_BASE_SPI17Y ((uint32_t)0x40046000UL)
#define MXC_SPI17Y ((mxc_spi17y_regs_t*)MXC_BASE_SPI17Y)
#define MXC_SPI17Y_GET_IDX(p) ((p) == MXC_SPI17Y ? 0 : -1)
#define MXC_SPI17Y_GET_BASE(i) ((i) == 0 ? MXC_BASE_SPI17Y : 0)
#define MXC_SPI17Y_GET_SPI17Y(i) ((i) == 0 ? MXC_SPI17Y : 0)
/******************************************************************************/
/* Bit Shifting */
#define MXC_F_BIT_0 (1 << 0)
#define MXC_F_BIT_1 (1 << 1)
#define MXC_F_BIT_2 (1 << 2)
#define MXC_F_BIT_3 (1 << 3)
#define MXC_F_BIT_4 (1 << 4)
#define MXC_F_BIT_5 (1 << 5)
#define MXC_F_BIT_6 (1 << 6)
#define MXC_F_BIT_7 (1 << 7)
#define MXC_F_BIT_8 (1 << 8)
#define MXC_F_BIT_9 (1 << 9)
#define MXC_F_BIT_10 (1 << 10)
#define MXC_F_BIT_11 (1 << 11)
#define MXC_F_BIT_12 (1 << 12)
#define MXC_F_BIT_13 (1 << 13)
#define MXC_F_BIT_14 (1 << 14)
#define MXC_F_BIT_15 (1 << 15)
#define MXC_F_BIT_16 (1 << 16)
#define MXC_F_BIT_17 (1 << 17)
#define MXC_F_BIT_18 (1 << 18)
#define MXC_F_BIT_19 (1 << 19)
#define MXC_F_BIT_20 (1 << 20)
#define MXC_F_BIT_21 (1 << 21)
#define MXC_F_BIT_22 (1 << 22)
#define MXC_F_BIT_23 (1 << 23)
#define MXC_F_BIT_24 (1 << 24)
#define MXC_F_BIT_25 (1 << 25)
#define MXC_F_BIT_26 (1 << 26)
#define MXC_F_BIT_27 (1 << 27)
#define MXC_F_BIT_28 (1 << 28)
#define MXC_F_BIT_29 (1 << 29)
#define MXC_F_BIT_30 (1 << 30)
#define MXC_F_BIT_31 (1 << 31)
/******************************************************************************/
/* Bit Banding */
#define BITBAND(reg, bit) ((0xf0000000 & (uint32_t)(reg)) + 0x2000000 + \
(((uint32_t)(reg) & 0x0fffffff) << 5) + ((bit) << 2))
#define MXC_CLRBIT(reg, bit) (*(volatile uint32_t *)BITBAND(reg, bit) = 0)
#define MXC_SETBIT(reg, bit) (*(volatile uint32_t *)BITBAND(reg, bit) = 1)
#define MXC_GETBIT(reg, bit) (*(volatile uint32_t *)BITBAND(reg, bit))
#define MXC_SETFIELD(reg, mask, value) (reg = (reg & ~mask) | (value & mask))
/******************************************************************************/
/* SCB CPACR */
/* Note: Added by Maxim Integrated, as these are missing from CMSIS/Core/Include/core_cm4.h */
#define SCB_CPACR_CP10_Pos 20 /*!< SCB CPACR: Coprocessor 10 Position */
#define SCB_CPACR_CP10_Msk (0x3UL << SCB_CPACR_CP10_Pos) /*!< SCB CPACR: Coprocessor 10 Mask */
#define SCB_CPACR_CP11_Pos 22 /*!< SCB CPACR: Coprocessor 11 Position */
#define SCB_CPACR_CP11_Msk (0x3UL << SCB_CPACR_CP11_Pos) /*!< SCB CPACR: Coprocessor 11 Mask */
#endif /* _MAX32660_REGS_H_ */
+275
View File
@@ -0,0 +1,275 @@
/******************************************************************************
* @file mpu_armv7.h
* @brief CMSIS MPU API for Armv7-M MPU
* @version V5.1.1
* @date 10. February 2020
******************************************************************************/
/*
* Copyright (c) 2017-2020 Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if defined ( __ICCARM__ )
#pragma system_include /* treat file as system include file for MISRA check */
#elif defined (__clang__)
#pragma clang system_header /* treat file as system include file */
#endif
#ifndef ARM_MPU_ARMV7_H
#define ARM_MPU_ARMV7_H
#define ARM_MPU_REGION_SIZE_32B ((uint8_t)0x04U) ///!< MPU Region Size 32 Bytes
#define ARM_MPU_REGION_SIZE_64B ((uint8_t)0x05U) ///!< MPU Region Size 64 Bytes
#define ARM_MPU_REGION_SIZE_128B ((uint8_t)0x06U) ///!< MPU Region Size 128 Bytes
#define ARM_MPU_REGION_SIZE_256B ((uint8_t)0x07U) ///!< MPU Region Size 256 Bytes
#define ARM_MPU_REGION_SIZE_512B ((uint8_t)0x08U) ///!< MPU Region Size 512 Bytes
#define ARM_MPU_REGION_SIZE_1KB ((uint8_t)0x09U) ///!< MPU Region Size 1 KByte
#define ARM_MPU_REGION_SIZE_2KB ((uint8_t)0x0AU) ///!< MPU Region Size 2 KBytes
#define ARM_MPU_REGION_SIZE_4KB ((uint8_t)0x0BU) ///!< MPU Region Size 4 KBytes
#define ARM_MPU_REGION_SIZE_8KB ((uint8_t)0x0CU) ///!< MPU Region Size 8 KBytes
#define ARM_MPU_REGION_SIZE_16KB ((uint8_t)0x0DU) ///!< MPU Region Size 16 KBytes
#define ARM_MPU_REGION_SIZE_32KB ((uint8_t)0x0EU) ///!< MPU Region Size 32 KBytes
#define ARM_MPU_REGION_SIZE_64KB ((uint8_t)0x0FU) ///!< MPU Region Size 64 KBytes
#define ARM_MPU_REGION_SIZE_128KB ((uint8_t)0x10U) ///!< MPU Region Size 128 KBytes
#define ARM_MPU_REGION_SIZE_256KB ((uint8_t)0x11U) ///!< MPU Region Size 256 KBytes
#define ARM_MPU_REGION_SIZE_512KB ((uint8_t)0x12U) ///!< MPU Region Size 512 KBytes
#define ARM_MPU_REGION_SIZE_1MB ((uint8_t)0x13U) ///!< MPU Region Size 1 MByte
#define ARM_MPU_REGION_SIZE_2MB ((uint8_t)0x14U) ///!< MPU Region Size 2 MBytes
#define ARM_MPU_REGION_SIZE_4MB ((uint8_t)0x15U) ///!< MPU Region Size 4 MBytes
#define ARM_MPU_REGION_SIZE_8MB ((uint8_t)0x16U) ///!< MPU Region Size 8 MBytes
#define ARM_MPU_REGION_SIZE_16MB ((uint8_t)0x17U) ///!< MPU Region Size 16 MBytes
#define ARM_MPU_REGION_SIZE_32MB ((uint8_t)0x18U) ///!< MPU Region Size 32 MBytes
#define ARM_MPU_REGION_SIZE_64MB ((uint8_t)0x19U) ///!< MPU Region Size 64 MBytes
#define ARM_MPU_REGION_SIZE_128MB ((uint8_t)0x1AU) ///!< MPU Region Size 128 MBytes
#define ARM_MPU_REGION_SIZE_256MB ((uint8_t)0x1BU) ///!< MPU Region Size 256 MBytes
#define ARM_MPU_REGION_SIZE_512MB ((uint8_t)0x1CU) ///!< MPU Region Size 512 MBytes
#define ARM_MPU_REGION_SIZE_1GB ((uint8_t)0x1DU) ///!< MPU Region Size 1 GByte
#define ARM_MPU_REGION_SIZE_2GB ((uint8_t)0x1EU) ///!< MPU Region Size 2 GBytes
#define ARM_MPU_REGION_SIZE_4GB ((uint8_t)0x1FU) ///!< MPU Region Size 4 GBytes
#define ARM_MPU_AP_NONE 0U ///!< MPU Access Permission no access
#define ARM_MPU_AP_PRIV 1U ///!< MPU Access Permission privileged access only
#define ARM_MPU_AP_URO 2U ///!< MPU Access Permission unprivileged access read-only
#define ARM_MPU_AP_FULL 3U ///!< MPU Access Permission full access
#define ARM_MPU_AP_PRO 5U ///!< MPU Access Permission privileged access read-only
#define ARM_MPU_AP_RO 6U ///!< MPU Access Permission read-only access
/** MPU Region Base Address Register Value
*
* \param Region The region to be configured, number 0 to 15.
* \param BaseAddress The base address for the region.
*/
#define ARM_MPU_RBAR(Region, BaseAddress) \
(((BaseAddress) & MPU_RBAR_ADDR_Msk) | \
((Region) & MPU_RBAR_REGION_Msk) | \
(MPU_RBAR_VALID_Msk))
/**
* MPU Memory Access Attributes
*
* \param TypeExtField Type extension field, allows you to configure memory access type, for example strongly ordered, peripheral.
* \param IsShareable Region is shareable between multiple bus masters.
* \param IsCacheable Region is cacheable, i.e. its value may be kept in cache.
* \param IsBufferable Region is bufferable, i.e. using write-back caching. Cacheable but non-bufferable regions use write-through policy.
*/
#define ARM_MPU_ACCESS_(TypeExtField, IsShareable, IsCacheable, IsBufferable) \
((((TypeExtField) << MPU_RASR_TEX_Pos) & MPU_RASR_TEX_Msk) | \
(((IsShareable) << MPU_RASR_S_Pos) & MPU_RASR_S_Msk) | \
(((IsCacheable) << MPU_RASR_C_Pos) & MPU_RASR_C_Msk) | \
(((IsBufferable) << MPU_RASR_B_Pos) & MPU_RASR_B_Msk))
/**
* MPU Region Attribute and Size Register Value
*
* \param DisableExec Instruction access disable bit, 1= disable instruction fetches.
* \param AccessPermission Data access permissions, allows you to configure read/write access for User and Privileged mode.
* \param AccessAttributes Memory access attribution, see \ref ARM_MPU_ACCESS_.
* \param SubRegionDisable Sub-region disable field.
* \param Size Region size of the region to be configured, for example 4K, 8K.
*/
#define ARM_MPU_RASR_EX(DisableExec, AccessPermission, AccessAttributes, SubRegionDisable, Size) \
((((DisableExec) << MPU_RASR_XN_Pos) & MPU_RASR_XN_Msk) | \
(((AccessPermission) << MPU_RASR_AP_Pos) & MPU_RASR_AP_Msk) | \
(((AccessAttributes) & (MPU_RASR_TEX_Msk | MPU_RASR_S_Msk | MPU_RASR_C_Msk | MPU_RASR_B_Msk))) | \
(((SubRegionDisable) << MPU_RASR_SRD_Pos) & MPU_RASR_SRD_Msk) | \
(((Size) << MPU_RASR_SIZE_Pos) & MPU_RASR_SIZE_Msk) | \
(((MPU_RASR_ENABLE_Msk))))
/**
* MPU Region Attribute and Size Register Value
*
* \param DisableExec Instruction access disable bit, 1= disable instruction fetches.
* \param AccessPermission Data access permissions, allows you to configure read/write access for User and Privileged mode.
* \param TypeExtField Type extension field, allows you to configure memory access type, for example strongly ordered, peripheral.
* \param IsShareable Region is shareable between multiple bus masters.
* \param IsCacheable Region is cacheable, i.e. its value may be kept in cache.
* \param IsBufferable Region is bufferable, i.e. using write-back caching. Cacheable but non-bufferable regions use write-through policy.
* \param SubRegionDisable Sub-region disable field.
* \param Size Region size of the region to be configured, for example 4K, 8K.
*/
#define ARM_MPU_RASR(DisableExec, AccessPermission, TypeExtField, IsShareable, IsCacheable, IsBufferable, SubRegionDisable, Size) \
ARM_MPU_RASR_EX(DisableExec, AccessPermission, ARM_MPU_ACCESS_(TypeExtField, IsShareable, IsCacheable, IsBufferable), SubRegionDisable, Size)
/**
* MPU Memory Access Attribute for strongly ordered memory.
* - TEX: 000b
* - Shareable
* - Non-cacheable
* - Non-bufferable
*/
#define ARM_MPU_ACCESS_ORDERED ARM_MPU_ACCESS_(0U, 1U, 0U, 0U)
/**
* MPU Memory Access Attribute for device memory.
* - TEX: 000b (if shareable) or 010b (if non-shareable)
* - Shareable or non-shareable
* - Non-cacheable
* - Bufferable (if shareable) or non-bufferable (if non-shareable)
*
* \param IsShareable Configures the device memory as shareable or non-shareable.
*/
#define ARM_MPU_ACCESS_DEVICE(IsShareable) ((IsShareable) ? ARM_MPU_ACCESS_(0U, 1U, 0U, 1U) : ARM_MPU_ACCESS_(2U, 0U, 0U, 0U))
/**
* MPU Memory Access Attribute for normal memory.
* - TEX: 1BBb (reflecting outer cacheability rules)
* - Shareable or non-shareable
* - Cacheable or non-cacheable (reflecting inner cacheability rules)
* - Bufferable or non-bufferable (reflecting inner cacheability rules)
*
* \param OuterCp Configures the outer cache policy.
* \param InnerCp Configures the inner cache policy.
* \param IsShareable Configures the memory as shareable or non-shareable.
*/
#define ARM_MPU_ACCESS_NORMAL(OuterCp, InnerCp, IsShareable) ARM_MPU_ACCESS_((4U | (OuterCp)), IsShareable, ((InnerCp) >> 1U), ((InnerCp) & 1U))
/**
* MPU Memory Access Attribute non-cacheable policy.
*/
#define ARM_MPU_CACHEP_NOCACHE 0U
/**
* MPU Memory Access Attribute write-back, write and read allocate policy.
*/
#define ARM_MPU_CACHEP_WB_WRA 1U
/**
* MPU Memory Access Attribute write-through, no write allocate policy.
*/
#define ARM_MPU_CACHEP_WT_NWA 2U
/**
* MPU Memory Access Attribute write-back, no write allocate policy.
*/
#define ARM_MPU_CACHEP_WB_NWA 3U
/**
* Struct for a single MPU Region
*/
typedef struct {
uint32_t RBAR; //!< The region base address register value (RBAR)
uint32_t RASR; //!< The region attribute and size register value (RASR) \ref MPU_RASR
} ARM_MPU_Region_t;
/** Enable the MPU.
* \param MPU_Control Default access permissions for unconfigured regions.
*/
__STATIC_INLINE void ARM_MPU_Enable(uint32_t MPU_Control)
{
__DMB();
MPU->CTRL = MPU_Control | MPU_CTRL_ENABLE_Msk;
#ifdef SCB_SHCSR_MEMFAULTENA_Msk
SCB->SHCSR |= SCB_SHCSR_MEMFAULTENA_Msk;
#endif
__DSB();
__ISB();
}
/** Disable the MPU.
*/
__STATIC_INLINE void ARM_MPU_Disable(void)
{
__DMB();
#ifdef SCB_SHCSR_MEMFAULTENA_Msk
SCB->SHCSR &= ~SCB_SHCSR_MEMFAULTENA_Msk;
#endif
MPU->CTRL &= ~MPU_CTRL_ENABLE_Msk;
__DSB();
__ISB();
}
/** Clear and disable the given MPU region.
* \param rnr Region number to be cleared.
*/
__STATIC_INLINE void ARM_MPU_ClrRegion(uint32_t rnr)
{
MPU->RNR = rnr;
MPU->RASR = 0U;
}
/** Configure an MPU region.
* \param rbar Value for RBAR register.
* \param rsar Value for RSAR register.
*/
__STATIC_INLINE void ARM_MPU_SetRegion(uint32_t rbar, uint32_t rasr)
{
MPU->RBAR = rbar;
MPU->RASR = rasr;
}
/** Configure the given MPU region.
* \param rnr Region number to be configured.
* \param rbar Value for RBAR register.
* \param rsar Value for RSAR register.
*/
__STATIC_INLINE void ARM_MPU_SetRegionEx(uint32_t rnr, uint32_t rbar, uint32_t rasr)
{
MPU->RNR = rnr;
MPU->RBAR = rbar;
MPU->RASR = rasr;
}
/** Memcopy with strictly ordered memory access, e.g. for register targets.
* \param dst Destination data is copied to.
* \param src Source data is copied from.
* \param len Amount of data words to be copied.
*/
__STATIC_INLINE void ARM_MPU_OrderedMemcpy(volatile uint32_t* dst, const uint32_t* __RESTRICT src, uint32_t len)
{
uint32_t i;
for (i = 0U; i < len; ++i)
{
dst[i] = src[i];
}
}
/** Load the given number of MPU regions from a table.
* \param table Pointer to the MPU configuration table.
* \param cnt Amount of regions to be configured.
*/
__STATIC_INLINE void ARM_MPU_Load(ARM_MPU_Region_t const* table, uint32_t cnt)
{
const uint32_t rowWordSize = sizeof(ARM_MPU_Region_t)/4U;
while (cnt > MPU_TYPE_RALIASES) {
ARM_MPU_OrderedMemcpy(&(MPU->RBAR), &(table->RBAR), MPU_TYPE_RALIASES*rowWordSize);
table += MPU_TYPE_RALIASES;
cnt -= MPU_TYPE_RALIASES;
}
ARM_MPU_OrderedMemcpy(&(MPU->RBAR), &(table->RBAR), cnt*rowWordSize);
}
#endif
+53
View File
@@ -0,0 +1,53 @@
/**
* @file mxc_config.h
* @brief Top-level include file for device configuration.
*/
/*******************************************************************************
* Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Maxim Integrated
* Products, Inc. shall not be used except as stated in the Maxim Integrated
* Products, Inc. Branding Policy.
*
* The mere transfer of this software does not imply any licenses
* of trade secrets, proprietary technology, copyrights, patents,
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*
* $Date: 2018-08-09 18:45:02 -0500 (Thu, 09 Aug 2018) $
* $Revision: 36818 $
*
******************************************************************************/
#ifndef _MXC_CONFIG_H
#define _MXC_CONFIG_H
#if !defined __GNUC__
#include "RTE_Components.h"
#endif /* not __GNUC__ */
#include "mxc_device.h"
#include "mxc_errors.h"
#include "mxc_pins.h"
#endif /* _CONFIG_H */
@@ -0,0 +1,373 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
;
; Permission is hereby granted, free of charge, to any person obtaining a
; copy of this software and associated documentation files (the "Software"),
; to deal in the Software without restriction, including without limitation
; the rights to use, copy, modify, merge, publish, distribute, sublicense,
; and/or sell copies of the Software, and to permit persons to whom the
; Software is furnished to do so, subject to the following conditions:
;
; The above copyright notice and this permission notice shall be included
; in all copies or substantial portions of the Software.
;
; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
; OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
; IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
; OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
; ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
; OTHER DEALINGS IN THE SOFTWARE.
;
; Except as contained in this notice, the name of Maxim Integrated
; Products, Inc. shall not be used except as stated in the Maxim Integrated
; Products, Inc. Branding Policy.
;
; The mere transfer of this software does not imply any licenses
; of trade secrets, proprietary technology, copyrights, patents,
; trademarks, maskwork rights, or any other form of intellectual
; property whatsoever. Maxim Integrated Products, Inc. retains all
; ownership rights.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; To map FreeRTOS function names to their CMSIS equivalents add following lines to FreeRTOSConfig.h
; #define vPortSVCHandler SVC_Handler
; #define xPortPendSVHandler PendSV_Handler
; #define xPortSysTickHandler SysTick_Handler
; *------- <<< Use Configuration Wizard in Context Menu to Modify Stack Size and Heap Size. >>> ----
; <h> Stack Configuration
; <o> Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>
Stack_Size EQU 0x00001000
AREA STACK, NOINIT, READWRITE, ALIGN=3
Stack_Mem SPACE Stack_Size
__initial_sp ; Name used with Keil Configuration Wizard and Keil MicroLib
; <h> Heap Configuration
; <o> Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>
Heap_Size EQU 0x00000C00
AREA HEAP, NOINIT, READWRITE, ALIGN=3
__heap_base
Heap_Mem SPACE Heap_Size
__heap_limit
PRESERVE8
THUMB
; Vector Table Mapped to Address 0 at Reset
AREA RESET, DATA, READONLY
EXPORT __Vectors
EXPORT __Vectors_End
EXPORT __Vectors_Size
EXPORT __isr_vector
IMPORT SysTick_Handler
__isr_vector DCD __initial_sp ; Top of Stack
DCD Reset_Handler ; Reset Handler
DCD NMI_Handler ; NMI Handler
DCD HardFault_Handler ; Hard Fault Handler
DCD MemManage_Handler ; MPU Fault Handler
DCD BusFault_Handler ; Bus Fault Handler
DCD UsageFault_Handler ; Usage Fault Handler
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD SVC_Handler ; SVCall Handler
DCD DebugMon_Handler ; Debug Monitor Handler
DCD 0 ; Reserved
DCD PendSV_Handler ; PendSV Handler
DCD SysTick_Handler ; SysTick Handler
; Device-specific Interrupts
DCD PF_IRQHandler ; 0x10 0x0040 16: Power Fail
DCD WDT0_IRQHandler ; 0x11 0x0044 17: Watchdog 0
DCD RSV00_IRQHandler ; 0x12 0x0048 18: RSV00
DCD RTC_IRQHandler ; 0x13 0x004C 19: RTC
DCD RSV01_IRQHandler ; 0x14 0x0050 20: RSV1
DCD TMR0_IRQHandler ; 0x15 0x0054 21: Timer 0
DCD TMR1_IRQHandler ; 0x16 0x0058 22: Timer 1
DCD TMR2_IRQHandler ; 0x17 0x005C 23: Timer 2
DCD RSV02_IRQHandler ; 0x18 0x0060 24: RSV02
DCD RSV03_IRQHandler ; 0x19 0x0064 25: RSV03
DCD RSV04_IRQHandler ; 0x1A 0x0068 26: RSV04
DCD RSV05_IRQHandler ; 0x1B 0x006C 27: RSV05
DCD RSV06_IRQHandler ; 0x1C 0x0070 28: RSV06
DCD I2C0_IRQHandler ; 0x1D 0x0074 29: I2C0
DCD UART0_IRQHandler ; 0x1E 0x0078 30: UART 0
DCD UART1_IRQHandler ; 0x1F 0x007C 31: UART 1
DCD SPI0_IRQHandler ; 0x20 0x0080 32: SPIY17
DCD SPI1_IRQHandler ; 0x21 0x0084 33: SPIMSS
DCD RSV07_IRQHandler ; 0x22 0x0088 34: RSV07
DCD RSV08_IRQHandler ; 0x23 0x008C 35: RSV08
DCD RSV09_IRQHandler ; 0x24 0x0090 36: RSV09
DCD RSV10_IRQHandler ; 0x25 0x0094 37: RSV10
DCD RSV11_IRQHandler ; 0x26 0x0098 38: RSV11
DCD FLC_IRQHandler ; 0x27 0x009C 39: FLC
DCD GPIO0_IRQHandler ; 0x28 0x00A0 40: GPIO0
DCD RSV12_IRQHandler ; 0x29 0x00A4 41: RSV12
DCD RSV13_IRQHandler ; 0x2A 0x00A8 42: RSV13
DCD RSV14_IRQHandler ; 0x2B 0x00AC 43: RSV14
DCD DMA0_IRQHandler ; 0x2C 0x00B0 44: DMA0
DCD DMA1_IRQHandler ; 0x2D 0x00B4 45: DMA1
DCD DMA2_IRQHandler ; 0x2E 0x00B8 46: DMA2
DCD DMA3_IRQHandler ; 0x2F 0x00BC 47: DMA3
DCD RSV15_IRQHandler ; 0x30 0x00C0 48: RSV15
DCD RSV16_IRQHandler ; 0x31 0x00C4 49: RSV16
DCD RSV17_IRQHandler ; 0x32 0x00C8 50: RSV17
DCD RSV18_IRQHandler ; 0x33 0x00CC 51: RSV18
DCD I2C1_IRQHandler ; 0x34 0x00D0 52: I2C1
DCD RSV19_IRQHandler ; 0x35 0x00D4 53: RSV19
DCD RSV20_IRQHandler ; 0x36 0x00D8 54: RSV20
DCD RSV21_IRQHandler ; 0x37 0x00DC 55: RSV21
DCD RSV22_IRQHandler ; 0x38 0x00E0 56: RSV22
DCD RSV23_IRQHandler ; 0x39 0x00E4 57: RSV23
DCD RSV24_IRQHandler ; 0x3A 0x00E8 58: RSV24
DCD RSV25_IRQHandler ; 0x3B 0x00EC 59: RSV25
DCD RSV26_IRQHandler ; 0x3C 0x00F0 60: RSV26
DCD RSV27_IRQHandler ; 0x3D 0x00F4 61: RSV27
DCD RSV28_IRQHandler ; 0x3E 0x00F8 62: RSV28
DCD RSV29_IRQHandler ; 0x3F 0x00FC 63: RSV29
DCD RSV30_IRQHandler ; 0x40 0x0100 64: RSV30
DCD RSV31_IRQHandler ; 0x41 0x0104 65: RSV31
DCD RSV32_IRQHandler ; 0x42 0x0108 66: RSV32
DCD RSV33_IRQHandler ; 0x43 0x010C 67: RSV33
DCD RSV34_IRQHandler ; 0x44 0x0110 68: RSV34
DCD RSV35_IRQHandler ; 0x45 0x0114 69: RSV35
DCD GPIOWAKE_IRQHandler ; 0x46 0x0118 70: GPIO Wakeup
__isr_vector_end
__isr_vector_size EQU __isr_vector_end - __isr_vector
__Vectors EQU __isr_vector
__Vectors_End EQU __isr_vector_end
__Vectors_Size EQU __isr_vector_size
AREA |.text|, CODE, READONLY
Reset_Handler PROC
EXPORT Reset_Handler [WEAK]
IMPORT PreInit
;IMPORT SystemInit
IMPORT __main
LDR R0, =PreInit ; Call to PreInit (prior to RAM initialization)
BLX R0
LDR R0, =__main ; SystemInit() is called from post scatter memory initialization in function $Sub$$__main_after_scatterload - system_max32660.c
BX R0
__SPIN
WFI
BL __SPIN
ENDP
; Dummy Exception Handlers (infinite loops which can be modified)
NMI_Handler\
PROC
EXPORT NMI_Handler [WEAK]
B .
ENDP
HardFault_Handler\
PROC
EXPORT HardFault_Handler [WEAK]
B .
ENDP
MemManage_Handler\
PROC
EXPORT MemManage_Handler [WEAK]
B .
ENDP
BusFault_Handler\
PROC
EXPORT BusFault_Handler [WEAK]
B .
ENDP
UsageFault_Handler\
PROC
EXPORT UsageFault_Handler [WEAK]
B .
ENDP
SVC_Handler\
PROC
EXPORT SVC_Handler [WEAK]
B .
ENDP
DebugMon_Handler\
PROC
EXPORT DebugMon_Handler [WEAK]
B .
ENDP
PendSV_Handler\
PROC
EXPORT PendSV_Handler [WEAK]
B .
ENDP
Default_Handler\
PROC
; MAX32660 Device-specific Interrupts
EXPORT PF_IRQHandler [WEAK] ; 0x10 0x0040 16: Power Fail
EXPORT WDT0_IRQHandler [WEAK] ; 0x11 0x0044 17: Watchdog 0
EXPORT RSV00_IRQHandler [WEAK] ; 0x12 0x0048 18: RSV00
EXPORT RTC_IRQHandler [WEAK] ; 0x13 0x004C 19: RTC
EXPORT RSV01_IRQHandler [WEAK] ; 0x14 0x0050 20: RSV01
EXPORT TMR0_IRQHandler [WEAK] ; 0x15 0x0054 21: Timer 0
EXPORT TMR1_IRQHandler [WEAK] ; 0x16 0x0058 22: Timer 1
EXPORT TMR2_IRQHandler [WEAK] ; 0x17 0x005C 23: Timer 2
EXPORT RSV02_IRQHandler [WEAK] ; 0x18 0x0060 24: RSV02
EXPORT RSV03_IRQHandler [WEAK] ; 0x19 0x0064 25: RSV03
EXPORT RSV04_IRQHandler [WEAK] ; 0x1A 0x0068 26: RSV04
EXPORT RSV05_IRQHandler [WEAK] ; 0x1B 0x006C 27: RSV05
EXPORT RSV06_IRQHandler [WEAK] ; 0x1C 0x0070 28: RSV06
EXPORT I2C0_IRQHandler [WEAK] ; 0x1D 0x0074 29: I2C0
EXPORT UART0_IRQHandler [WEAK] ; 0x1E 0x0078 30: UART 0
EXPORT UART1_IRQHandler [WEAK] ; 0x1F 0x007C 31: UART 1
EXPORT SPI0_IRQHandler [WEAK] ; 0x20 0x0080 32: SPIY17
EXPORT SPI1_IRQHandler [WEAK] ; 0x21 0x0084 33: SPIMSS
EXPORT RSV07_IRQHandler [WEAK] ; 0x22 0x0088 34: RSV07
EXPORT RSV08_IRQHandler [WEAK] ; 0x23 0x008C 35: RSV08
EXPORT RSV09_IRQHandler [WEAK] ; 0x24 0x0090 36: RSV09
EXPORT RSV10_IRQHandler [WEAK] ; 0x25 0x0094 37: RSV10
EXPORT RSV11_IRQHandler [WEAK] ; 0x26 0x0098 38: RSV11
EXPORT FLC_IRQHandler [WEAK] ; 0x27 0x009C 39: FLC
EXPORT GPIO0_IRQHandler [WEAK] ; 0x28 0x00A0 40: GPIO0
EXPORT RSV12_IRQHandler [WEAK] ; 0x29 0x00A4 41: RSV12
EXPORT RSV13_IRQHandler [WEAK] ; 0x2A 0x00A8 42: RSV13
EXPORT RSV14_IRQHandler [WEAK] ; 0x2B 0x00AC 43: RSV14
EXPORT DMA0_IRQHandler [WEAK] ; 0x2C 0x00B0 44: DMA0
EXPORT DMA1_IRQHandler [WEAK] ; 0x2D 0x00B4 45: DMA1
EXPORT DMA2_IRQHandler [WEAK] ; 0x2E 0x00B8 46: DMA2
EXPORT DMA3_IRQHandler [WEAK] ; 0x2F 0x00BC 47: DMA3
EXPORT RSV15_IRQHandler [WEAK] ; 0x30 0x00C0 48: RSV15
EXPORT RSV16_IRQHandler [WEAK] ; 0x31 0x00C4 49: RSV16
EXPORT RSV17_IRQHandler [WEAK] ; 0x32 0x00C8 50: RSV17
EXPORT RSV18_IRQHandler [WEAK] ; 0x33 0x00CC 51: RSV18
EXPORT I2C1_IRQHandler [WEAK] ; 0x34 0x00D0 52: I2C1
EXPORT RSV19_IRQHandler [WEAK] ; 0x35 0x00D4 53: RSV19
EXPORT RSV20_IRQHandler [WEAK] ; 0x36 0x00D8 54: RSV20
EXPORT RSV21_IRQHandler [WEAK] ; 0x37 0x00DC 55: RSV21
EXPORT RSV22_IRQHandler [WEAK] ; 0x38 0x00E0 56: RSV22
EXPORT RSV23_IRQHandler [WEAK] ; 0x39 0x00E4 57: RSV23
EXPORT RSV24_IRQHandler [WEAK] ; 0x3A 0x00E8 58: RSV24
EXPORT RSV25_IRQHandler [WEAK] ; 0x3B 0x00EC 59: RSV25
EXPORT RSV26_IRQHandler [WEAK] ; 0x3C 0x00F0 60: RSV26
EXPORT RSV27_IRQHandler [WEAK] ; 0x3D 0x00F4 61: RSV27
EXPORT RSV28_IRQHandler [WEAK] ; 0x3E 0x00F8 62: RSV28
EXPORT RSV29_IRQHandler [WEAK] ; 0x3F 0x00FC 63: RSV29
EXPORT RSV30_IRQHandler [WEAK] ; 0x40 0x0100 64: RSV30
EXPORT RSV31_IRQHandler [WEAK] ; 0x41 0x0104 65: RSV31
EXPORT RSV32_IRQHandler [WEAK] ; 0x42 0x0108 66: RSV32
EXPORT RSV33_IRQHandler [WEAK] ; 0x43 0x010C 67: RSV33
EXPORT RSV34_IRQHandler [WEAK] ; 0x44 0x0110 68: RSV34
EXPORT RSV35_IRQHandler [WEAK] ; 0x45 0x0114 69: RSV35
EXPORT GPIOWAKE_IRQHandler [WEAK] ; 0x46 0x0118 70: GPIO Wakeup
;*******************************************************************************
; Default handler implementations
;*******************************************************************************
PF_IRQHandler ; 0x10 0x0040 16: Power Fail
WDT0_IRQHandler ; 0x11 0x0044 17: Watchdog 0
RSV00_IRQHandler ; 0x12 0x0048 18: RSV00
RTC_IRQHandler ; 0x13 0x004C 19: RTC
RSV01_IRQHandler ; 0x14 0x0050 20: RSV01
TMR0_IRQHandler ; 0x15 0x0054 21: Timer 0
TMR1_IRQHandler ; 0x16 0x0058 22: Timer 1
TMR2_IRQHandler ; 0x17 0x005C 23: Timer 2
RSV02_IRQHandler ; 0x18 0x0060 24: RSV02
RSV03_IRQHandler ; 0x19 0x0064 25: RSV03
RSV04_IRQHandler ; 0x1A 0x0068 26: RSV04
RSV05_IRQHandler ; 0x1B 0x006C 27: RSV05
RSV06_IRQHandler ; 0x1C 0x0070 28: RSV06
I2C0_IRQHandler ; 0x1D 0x0074 29: I2C0
UART0_IRQHandler ; 0x1E 0x0078 30: UART 0
UART1_IRQHandler ; 0x1F 0x007C 31: UART 1
SPI0_IRQHandler ; 0x20 0x0080 32: SPI0
SPI1_IRQHandler ; 0x21 0x0084 33: SPI1
RSV07_IRQHandler ; 0x22 0x0088 34: RSV07
RSV08_IRQHandler ; 0x23 0x008C 35: RSV08
RSV09_IRQHandler ; 0x24 0x0090 36: RSV09
RSV10_IRQHandler ; 0x25 0x0094 37: RSV10
RSV11_IRQHandler ; 0x26 0x0098 38: RSV11
FLC_IRQHandler ; 0x27 0x009C 39: FLC
GPIO0_IRQHandler ; 0x28 0x00A0 40: GPIO0
RSV12_IRQHandler ; 0x29 0x00A4 41: RSV12
RSV13_IRQHandler ; 0x2A 0x00A8 42: RSV13
RSV14_IRQHandler ; 0x2B 0x00AC 43: RSV14
DMA0_IRQHandler ; 0x2C 0x00B0 44: DMA0
DMA1_IRQHandler ; 0x2D 0x00B4 45: DMA1
DMA2_IRQHandler ; 0x2E 0x00B8 46: DMA2
DMA3_IRQHandler ; 0x2F 0x00BC 47: DMA3
RSV15_IRQHandler ; 0x30 0x00C0 48: RSV15
RSV16_IRQHandler ; 0x31 0x00C4 49: RSV16
RSV17_IRQHandler ; 0x32 0x00C8 50: RSV17
RSV18_IRQHandler ; 0x33 0x00CC 51: RSV18
I2C1_IRQHandler ; 0x34 0x00D0 52: I2C1
RSV19_IRQHandler ; 0x35 0x00D4 53: RSV19
RSV20_IRQHandler ; 0x36 0x00D8 54: RSV20
RSV21_IRQHandler ; 0x37 0x00DC 55: RSV21
RSV22_IRQHandler ; 0x38 0x00E0 56: RSV22
RSV23_IRQHandler ; 0x39 0x00E4 57: RSV23
RSV24_IRQHandler ; 0x3A 0x00E8 58: RSV24
RSV25_IRQHandler ; 0x3B 0x00EC 59: RSV25
RSV26_IRQHandler ; 0x3C 0x00F0 60: RSV26
RSV27_IRQHandler ; 0x3D 0x00F4 61: RSV27
RSV28_IRQHandler ; 0x3E 0x00F8 62: RSV28
RSV29_IRQHandler ; 0x3F 0x00FC 63: RSV29
RSV30_IRQHandler ; 0x40 0x0100 64: RSV30
RSV31_IRQHandler ; 0x41 0x0104 65: RSV31
RSV32_IRQHandler ; 0x42 0x0108 66: RSV32
RSV33_IRQHandler ; 0x43 0x010C 67: RSV33
RSV34_IRQHandler ; 0x44 0x0110 68: RSV34
RSV35_IRQHandler ; 0x45 0x0114 69: RSV35
GPIOWAKE_IRQHandler ; 0x46 0x0118 70: GPIO Wakeup
B .
ENDP
ALIGN
;*******************************************************************************
; User Stack and Heap initialization
;*******************************************************************************
IF :DEF:__MICROLIB
EXPORT __initial_sp
EXPORT __heap_base
EXPORT __heap_limit
ELSE
IMPORT __use_two_region_memory
EXPORT __user_initial_stackheap
__user_initial_stackheap\
PROC
LDR R0, = Heap_Mem
LDR R1, = (Stack_Mem + Stack_Size)
LDR R2, = (Heap_Mem + Heap_Size)
LDR R3, = Stack_Mem
BX LR
ENDP
ALIGN
ENDIF
END
;;;;;;;;;;;;;;;;;;;;;;;;;
;; End of file.
;;;;;;;;;;;;;;;;;;;;;;;;;
+167
View File
@@ -0,0 +1,167 @@
/**
* @file system_max32660.c
* @brief System-level initialization implementation file
*/
/*******************************************************************************
* Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Maxim Integrated
* Products, Inc. shall not be used except as stated in the Maxim Integrated
* Products, Inc. Branding Policy.
*
* The mere transfer of this software does not imply any licenses
* of trade secrets, proprietary technology, copyrights, patents,
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*
* $Date: 2018-12-18 15:37:22 -0600 (Tue, 18 Dec 2018) $
* $Revision: 40072 $
*
******************************************************************************/
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "max32660.h"
#include "gcr_regs.h"
#include "pwrseq_regs.h"
#include "tmr_regs.h"
#include "wdt_regs.h"
#include "mxc_sys.h"
extern void (* const __isr_vector[])(void);
uint32_t SystemCoreClock = HIRC96_FREQ;
__weak void SystemCoreClockUpdate(void)
{
uint32_t base_freq, div, clk_src,ovr;
// Get the clock source and frequency
clk_src = (MXC_GCR->clkcn & MXC_F_GCR_CLKCN_CLKSEL);
if (clk_src == MXC_S_GCR_CLKCN_CLKSEL_HFXIN) {
base_freq = HFX_FREQ;
} else {
if (clk_src == MXC_S_GCR_CLKCN_CLKSEL_NANORING) {
base_freq = NANORING_FREQ;
} else {
ovr = (MXC_PWRSEQ->lp_ctrl & MXC_F_PWRSEQ_LP_CTRL_OVR);
if (ovr == MXC_S_PWRSEQ_LP_CTRL_OVR_0_9V) {
base_freq = HIRC96_FREQ/4;
} else {
if (ovr == MXC_S_PWRSEQ_LP_CTRL_OVR_1_0V) {
base_freq = HIRC96_FREQ/2;
} else {
base_freq = HIRC96_FREQ;
}
}
}
}
// Get the clock divider
div = (MXC_GCR->clkcn & MXC_F_GCR_CLKCN_PSC) >> MXC_F_GCR_CLKCN_PSC_POS;
SystemCoreClock = base_freq >> div;
}
/* This function is called before C runtime initialization and can be
* implemented by the application for early initializations. If a value other
* than '0' is returned, the C runtime initialization will be skipped.
*
* You may over-ride this function in your program by defining a custom
* PreInit(), but care should be taken to reproduce the initilization steps
* or a non-functional system may result.
*/
__weak int PreInit(void)
{
/* Do nothing */
return 0;
}
/* This function can be implemented by the application to initialize the board */
__weak int Board_Init(void)
{
/* Do nothing */
return 0;
}
/* This function is called just before control is transferred to main().
*
* You may over-ride this function in your program by defining a custom
* SystemInit(), but care should be taken to reproduce the initialization
* steps or a non-functional system may result.
*/
__weak void SystemInit(void)
{
/* Configure the interrupt controller to use the application vector table in */
/* the application space */
/* IAR & Keil must set vector table after all memory initialization. */
SCB->VTOR = (unsigned long)__isr_vector;
MXC_WDT0->ctrl &= ~MXC_F_WDT_CTRL_WDT_EN; /* Turn off watchdog. Application can re-enable as needed. */
/* Enable FPU on Cortex-M4, which occupies coprocessor slots 10 & 11 */
/* Grant full access, per "Table B3-24 CPACR bit assignments". */
/* DDI0403D "ARMv7-M Architecture Reference Manual" */
SCB->CPACR |= SCB_CPACR_CP10_Msk | SCB_CPACR_CP11_Msk;
__DSB();
__ISB();
/* Switch system clock to HIRC */
SYS_Clock_Select(SYS_CLOCK_HIRC, MXC_TMR0);
/* Disable clocks to peripherals by default to reduce power */
SYS_ClockDisable(SYS_PERIPH_CLOCK_DMA);
SYS_ClockDisable(SYS_PERIPH_CLOCK_SPI17Y);
SYS_ClockDisable(SYS_PERIPH_CLOCK_SPIMSS);
SYS_ClockDisable(SYS_PERIPH_CLOCK_UART0);
SYS_ClockDisable(SYS_PERIPH_CLOCK_UART1);
SYS_ClockDisable(SYS_PERIPH_CLOCK_I2C0);
SYS_ClockDisable(SYS_PERIPH_CLOCK_T0);
SYS_ClockDisable(SYS_PERIPH_CLOCK_T1);
SYS_ClockDisable(SYS_PERIPH_CLOCK_T2);
SYS_ClockDisable(SYS_PERIPH_CLOCK_I2C1);
Board_Init();
}
#if defined ( __CC_ARM )
/* Global variable initialization does not occur until post scatterload in Keil tools.*/
/* External function called after our post scatterload function implementation. */
extern void $Super$$__main_after_scatterload(void);
/**
* @brief Initialization function for SystemCoreClock and Board_Init.
* @details $Sub$$__main_after_scatterload is called during system startup in the Keil
* toolset. Global variable and static variable space must be set up by the compiler
* prior to using these memory spaces. Setting up the SystemCoreClock and Board_Init
* require global memory for variable storage and are called from this function in
* the Keil tool chain.
*/
void $Sub$$__main_after_scatterload(void)
{
SystemInit();
$Super$$__main_after_scatterload();
}
#endif /* __CC_ARM */
@@ -0,0 +1,93 @@
/**
* @file system_max32660.h
* @brief System-specific header file
*/
/*******************************************************************************
* Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Maxim Integrated
* Products, Inc. shall not be used except as stated in the Maxim Integrated
* Products, Inc. Branding Policy.
*
* The mere transfer of this software does not imply any licenses
* of trade secrets, proprietary technology, copyrights, patents,
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*
* $Date: 2018-12-18 15:37:22 -0600 (Tue, 18 Dec 2018) $
* $Revision: 40072 $
*
******************************************************************************/
#ifndef _SYSTEM_MAX32660_H_
#define _SYSTEM_MAX32660_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
/*----------------------------------------------------------------------------
Define clocks
*----------------------------------------------------------------------------*/
#ifndef HFX_FREQ
#define HFX_FREQ 32768
#endif
#ifndef NANORING_FREQ
#define NANORING_FREQ 8000
#endif
#ifndef HIRC96_FREQ
#define HIRC96_FREQ 96000000
#endif
extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */
#ifndef PeripheralClock
#define PeripheralClock (SystemCoreClock /2) /*!< Peripheral Clock Frequency */
#endif
/*
* Initialize the system
*
* @brief Setup the microcontroller system.
* Initialize the System and update the SystemCoreClock variable.
*/
void SystemInit(void);
/*
* Update SystemCoreClock variable
*
* @brief Updates the SystemCoreClock with current core Clock
* retrieved from cpu registers.
*/
void SystemCoreClockUpdate(void);
#ifdef __cplusplus
}
#endif
#endif /* _SYSTEM_MAX32660_H_ */
@@ -0,0 +1,317 @@
/**
* @file
* @brief Direct Memory Access (DMA) driver function prototypes and data types.
*/
/* ****************************************************************************
* Copyright (C) 2017 Maxim Integrated Products, Inc., All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Maxim Integrated
* Products, Inc. shall not be used except as stated in the Maxim Integrated
* Products, Inc. Branding Policy.
*
* The mere transfer of this software does not imply any licenses
* of trade secrets, proprietary technology, copyrights, patents,
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*
* $Date: 2019-07-01 11:06:19 -0500 (Mon, 01 Jul 2019) $
* $Revision: 44383 $
*
*************************************************************************** */
#ifndef _DMA_H_
#define _DMA_H_
/* **** Includes **** */
#include "mxc_config.h"
#include "dma_regs.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @defgroup dma Direct Memory Access (DMA)
* @ingroup periphlibs
* @{
*/
/* **** Definitions **** */
/**
* Enumeration for the DMA Channel's priority level.
*/
typedef enum {
DMA_PRIO_HIGH = MXC_S_DMA_CFG_PRI_HIGH, /**< High Priority */
DMA_PRIO_MEDHIGH = MXC_S_DMA_CFG_PRI_MEDHIGH, /**< Medium High Priority */
DMA_PRIO_MEDLOW = MXC_S_DMA_CFG_PRI_MEDLOW, /**< Medium Low Priority */
DMA_PRIO_LOW = MXC_S_DMA_CFG_PRI_LOW, /**< Low Priority */
} dma_priority_t;
/** @brief DMA request select */
typedef enum {
DMA_REQSEL_MEMTOMEM = MXC_S_DMA_CFG_REQSEL_MEMTOMEM, /**< Memory to Memory DMA Request Selection */
DMA_REQSEL_SPI0RX = MXC_S_DMA_CFG_REQSEL_SPI0RX, /**< SPI0 Receive DMA Request Selection */
DMA_REQSEL_SPI1RX = MXC_S_DMA_CFG_REQSEL_SPI1RX, /**< SPI1 Receive DMA Request Selection */
DMA_REQSEL_UART0RX = MXC_S_DMA_CFG_REQSEL_UART0RX, /**< UART0 Receive DMA Request Selection */
DMA_REQSEL_UART1RX = MXC_S_DMA_CFG_REQSEL_UART1RX, /**< UART1 Receive DMA Request Selection */
DMA_REQSEL_I2C0RX = MXC_S_DMA_CFG_REQSEL_I2C0RX, /**< I2C0 Receive DMA Request Selection */
DMA_REQSEL_I2C1RX = MXC_S_DMA_CFG_REQSEL_I2C1RX, /**< I2C1 Receive DMA Request Selection */
DMA_REQSEL_SPI0TX = MXC_S_DMA_CFG_REQSEL_SPI0TX, /**< SPI0 Transmit DMA Request Selection */
DMA_REQSEL_SPI1TX = MXC_S_DMA_CFG_REQSEL_SPI1TX, /**< SPI1 Transmit DMA Request Selection */
DMA_REQSEL_UART0TX = MXC_S_DMA_CFG_REQSEL_UART0TX, /**< UART0 Transmit DMA Request Selection */
DMA_REQSEL_UART1TX = MXC_S_DMA_CFG_REQSEL_UART1TX, /**< UART1 Transmit DMA Request Selection */
DMA_REQSEL_I2C0TX = MXC_S_DMA_CFG_REQSEL_I2C0TX, /**< I2C0 Transmit DMA Request Selection */
DMA_REQSEL_I2C1TX = MXC_S_DMA_CFG_REQSEL_I2C1TX, /**< I2C1 Transmit DMA Request Selection */
} dma_reqsel_t;
/** @brief Enumeration for the DMA prescaler */
typedef enum {
DMA_PRESCALE_DISABLE = MXC_S_DMA_CFG_PSSEL_DIS, /**< Prescaler disabled */
DMA_PRESCALE_DIV256 = MXC_S_DMA_CFG_PSSEL_DIV256, /**< Divide by 256 */
DMA_PRESCALE_DIV64K = MXC_S_DMA_CFG_PSSEL_DIV64K, /**< Divide by 65,536 */
DMA_PRESCALE_DIV16M = MXC_S_DMA_CFG_PSSEL_DIV16M, /**< Divide by 16,777,216 */
} dma_prescale_t;
/** @brief Enumeration for the DMA timeout value */
typedef enum {
DMA_TIMEOUT_4_CLK = MXC_S_DMA_CFG_TOSEL_TO4, /**< DMA timeout of 4 clocks */
DMA_TIMEOUT_8_CLK = MXC_S_DMA_CFG_TOSEL_TO8, /**< DMA timeout of 8 clocks */
DMA_TIMEOUT_16_CLK = MXC_S_DMA_CFG_TOSEL_TO16, /**< DMA timeout of 16 clocks */
DMA_TIMEOUT_32_CLK = MXC_S_DMA_CFG_TOSEL_TO32, /**< DMA timeout of 32 clocks */
DMA_TIMEOUT_64_CLK = MXC_S_DMA_CFG_TOSEL_TO64, /**< DMA timeout of 64 clocks */
DMA_TIMEOUT_128_CLK = MXC_S_DMA_CFG_TOSEL_TO128, /**< DMA timeout of 128 clocks */
DMA_TIMEOUT_256_CLK = MXC_S_DMA_CFG_TOSEL_TO256, /**< DMA timeout of 256 clocks */
DMA_TIMEOUT_512_CLK = MXC_S_DMA_CFG_TOSEL_TO512, /**< DMA timeout of 512 clocks */
} dma_timeout_t;
/** @brief DMA transfer data width */
typedef enum {
/* Using the '_V_' define instead of the '_S_' since these same values will be used to
specify the DSTWD also. The API functions will shift the value the correct amount
prior to writing the cfg register. */
DMA_WIDTH_BYTE = MXC_V_DMA_CFG_SRCWD_BYTE, /**< DMA transfer in bytes */
DMA_WIDTH_HALFWORD = MXC_V_DMA_CFG_SRCWD_HALFWORD, /**< DMA transfer in 16-bit half-words */
DMA_WIDTH_WORD = MXC_V_DMA_CFG_SRCWD_WORD, /**< DMA transfer in 32-bit words */
} dma_width_t;
/** @brief Convenience defines for options */
#define DMA_FALSE 0 /**< Define for passing 0 to DMA functions */
#define DMA_TRUE 1 /**< Define for passing 1 to DMA functions */
/* **** Function Prototypes **** */
/**
* @brief Initialize DMA resources
* @details This initialization is required before using the DMA driver functions.
* @return #E_NO_ERROR if successful
*/
int DMA_Init(void);
/**
* @brief Request DMA channel
* @details Returns a handle to the first free DMA channel, which can be used via API calls
* or direct access to channel registers using the DMA_GetCHRegs(int ch) function.
* @return Non-negative channel handle (inclusive of zero).
* @return #E_NONE_AVAIL All channels in use.
* @return #E_BAD_STATE DMA is not initialized, call DMA_Init() first.
* @return #E_BUSY DMA is currently busy (locked), try again later.
*/
int DMA_AcquireChannel(void);
/**
* @brief Release DMA channel
* @details Stops any DMA operation on the channel and returns it to the pool of free channels.
*
* @param ch channel handle to release
*
* @return #E_BAD_PARAM if an unused or invalid channel handle, #E_NO_ERROR otherwise
*/
int DMA_ReleaseChannel(int ch);
/**
* @brief Configure the DMA channel
* @details Configures the channel, which was previously requested by DMA_Getchannel()
*
* @param ch The channel to configure
* @param prio The channel's priority
* @param reqsel Select the DMA request line
* @param reqwait_en The enable delay before request
* @param tosel The transfer timer timeout select
* @param pssel The transfer timer prescale select
* @param srcwd The size of the read transactions
* @param srcinc_en Enable auto-increment source pointer
* @param dstwd The size of write transactions
* @param dstinc_en Enable auto-increment destination pointer
* @param burst_size The number of bytes transferred in one transaction
* @param chdis_inten The channel disable interrupt enable
* @param ctz_inten The count-to-zero interrupt enable
*
* @return #E_BAD_PARAM if an unused or invalid channel handle
* @return #E_NO_ERROR otherwise
*/
int DMA_ConfigChannel(int ch,
dma_priority_t prio,
dma_reqsel_t reqsel, unsigned int reqwait_en,
dma_timeout_t tosel, dma_prescale_t pssel,
dma_width_t srcwd, unsigned int srcinc_en,
dma_width_t dstwd, unsigned int dstinc_en,
unsigned int burst_size, unsigned int chdis_inten,
unsigned int ctz_inten);
/**
* @brief Set channel source, destination, and count for transfer
* @param ch channel handle
* @param src_addr source address (*)
* @param dst_addr destination address (*)
* @param count number of bytes to transfer
* @details This function is used to set the source and destination addresses and the number
* of bytes to transfer using the channel, @p ch.
* @note Unless the channel request select is #DMA_REQSEL_MEMTOMEM,
* either src_addr or dst_addr will be ignored by the DMA engine.
* In these cases, the address is a don't-care. See the User's
* Guide for more information.
* @return #E_BAD_PARAM if an unused or invalid channel handle
* @return #E_NO_ERROR otherwise
*/
int DMA_SetSrcDstCnt(int ch,
void *src_addr,
void *dst_addr,
unsigned int count);
/**
* @brief Set channel reload values
* @param ch channel handle
* @param src_addr_reload source address
* @param dst_addr_reload destination address
* @param count_reload number of bytes to transfer
* @details This function will set the values which will be loaded after the
* channel count register reaches zero. After enabling, call with
* count_reload set to zero to disable reload.
* @return #E_BAD_PARAM if an unused or invalid channel handle
* @return #E_NO_ERROR otherwise
*/
int DMA_SetReload(int ch,
void *src_addr_reload,
void *dst_addr_reload,
unsigned int count_reload);
/**
* @brief Set channel interrupt callback
* @param ch channel handle
* @param callback Pointer to a function to call when the channel
* interrupt flag is set and interrupts are enabled or
* when DMA is shutdown by the driver.
* @details Configures the channel interrupt callback. The @p callback
* function is called for two conditions:
* -# When the channel's interrupt flag is set and DMA interrupts
* are enabled.
* -# If the driver calls the DMA_Shutdown() function. The
* callback function prototype is:
* @code
* void callback_fn(int ch, int reason);
* @endcode
* @p ch indicates the channel that generated the callback, @p
* reason is either #E_NO_ERROR for a DMA interrupt or #E_SHUTDOWN
* if the DMA is being shutdown.
*
* @return #E_BAD_PARAM if an unused or invalid channel handle
* @return #E_NO_ERROR otherwise
*/
int DMA_SetCallback(int ch, void (*callback)(int, int));
/**
* @brief Enable channel interrupt
* @param ch channel handle
* @return #E_BAD_PARAM if an unused or invalid channel handle
* @return #E_NO_ERROR otherwise
*/
int DMA_EnableInterrupt(int ch);
/**
* @brief Disable channel interrupt
* @param ch channel handle
* @return #E_BAD_PARAM if an unused or invalid channel handle
* @return #E_NO_ERROR otherwise
*/
int DMA_DisableInterrupt(int ch);
/**
* @brief Read channel interrupt flags
* @param ch channel handle
* @param fl flags to get
* @return #E_BAD_PARAM if an unused or invalid channel handle
* @return #E_NO_ERROR otherwise
*/
int DMA_GetFlags(int ch, unsigned int *fl);
/**
* @brief Clear channel interrupt flags
* @param ch channel handle
* @return #E_BAD_PARAM if an unused or invalid channel handle
* @return #E_NO_ERROR otherwise
*/
int DMA_ClearFlags(int ch);
/**
* @brief Start transfer
* @param ch channel handle
* @details Start the DMA channel transfer, assumes that DMA_SetSrcDstCnt() has been called beforehand.
* @return #E_BAD_PARAM if an unused or invalid channel handle
* @return #E_NO_ERROR otherwise
*/
int DMA_Start(int ch);
/**
* @brief Stop DMA transfer, irrespective of status (complete or in-progress)
* @param ch channel handle
* @return #E_BAD_PARAM if an unused or invalid channel handle
* @return #E_NO_ERROR otherwise
*/
int DMA_Stop(int ch);
/**
* @brief Get a pointer to the DMA channel registers
* @param ch channel handle
* @details If direct access to DMA channel registers is required, this
* function can be used on a channel handle returned by DMA_AcquireChannel().
* @return NULL if an unused or invalid channel handle, or a valid pointer otherwise
*/
mxc_dma_ch_regs_t *DMA_GetCHRegs(int ch);
/**
* @brief Interrupt handler function
* @param ch channel handle
* @details Call this function as the ISR for each DMA channel under driver control.
* Interrupt flags for channel ch will be automatically cleared before return.
* @return NULL if an unused or invalid channel handle, or a valid pointer otherwise
*/
void DMA_Handler(int ch);
/**@} end of group dma */
#ifdef __cplusplus
}
#endif
#endif /* _DMA_H_ */
@@ -0,0 +1,200 @@
/**
* @file
* @brief Flash Controler driver.
* @details This driver can be used to operate on the embedded flash memory.
*/
/* ****************************************************************************
* Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Maxim Integrated
* Products, Inc. shall not be used except as stated in the Maxim Integrated
* Products, Inc. Branding Policy.
*
* The mere transfer of this software does not imply any licenses
* of trade secrets, proprietary technology, copyrights, patents,
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*
* $Date: 2019-06-05 16:53:29 -0500 (Wed, 05 Jun 2019) $
* $Revision: 43696 $
*
*************************************************************************** */
#ifndef _FLC_H_
#define _FLC_H_
/* **** Includes **** */
#include "flc_regs.h"
#include "mxc_sys.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @defgroup flc Flash Controller
* @ingroup periphlibs
* @{
*/
/***** Definitions *****/
/// Bit mask that can be used to find the starting address of a page in flash
#define MXC_FLASH_PAGE_MASK ~(MXC_FLASH_PAGE_SIZE - 1)
/// Calculate the address of a page in flash from the page number
#define MXC_FLASH_PAGE_ADDR(page) (MXC_FLASH_MEM_BASE + ((unsigned long)page * MXC_FLASH_PAGE_SIZE))
/***** Function Prototypes *****/
/**
* @brief Initializes the flash controller for erase/write operations
* @param sys_cfg Reserved for future use. Use NULL as this parameter's value.
* @return #E_NO_ERROR if successful, @ref MXC_Error_Codes "error" if unsuccessful.
*/
int FLC_Init(const sys_cfg_flc_t *sys_cfg);
/**
* @brief Checks if Flash controller is busy.
* @details Reading or executing from flash is not possible if flash is busy
* with an erase or write operation.
* @return If non-zero, flash operation is in progress
*/
int FLC_Busy(void);
/**
* @brief Erases the entire flash array.
* @return #E_NO_ERROR if successful, @ref MXC_Error_Codes "error" if unsuccessful.
*/
int FLC_MassErase(void);
/**
* @brief Erases the page of flash at the specified address.
* @param address Any address within the page to erase.
* @return #E_NO_ERROR if successful, @ref MXC_Error_Codes "error" if unsuccessful.
*/
int FLC_PageErase(uint32_t address);
/**
* @brief Page erase from start to end address.
* @note All data within the selected pages will be erased.
* @param start Any address within the first page to erase.
* @param end Any address within the last page to erase.
* @return #E_NO_ERROR if successful, @ref MXC_Error_Codes "error" if unsuccessful.
*/
int FLC_Erase(uint32_t start, uint32_t end);
/**
* @brief Erase from start to end address. Restoring any flash page contents outside the given range.
* @param start Starting address to erase, inclusive.
* @param end Ending address to erase, exclusive.
* @param buffer Data buffer to restore data in beginning and ending pages.
* @param length Length of given buffer.
*
* @note Buffer should be appropriate size to store all of the data remaining in the
* first and last pages. length should be greater than or equal to
* (start % MXC_FLASH_PAGE_SIZE) and ((MXC_FLASH_PAGE_SIZE - (end % MXC_FLASH_PAGE_SIZE)) % MXC_FLASH_PAGE_SIZE).
*
* @return #E_NO_ERROR if successful, @ref MXC_Error_Codes "error" if unsuccessful.
*/
int FLC_BufferErase(uint32_t start, uint32_t end, uint8_t *buffer, unsigned length);
/**
* @brief Writes the specified 32-bit value to flash.
* @param address 32-bit aligned address in flash to write.
* @param data value to be written to flash.
* @return #E_NO_ERROR if successful, @ref MXC_Error_Codes "error" if
* unsuccessful.
*/
int FLC_Write32(uint32_t address, uint32_t data);
/**
* @brief Writes the specified 128-bits of data to flash.
* @param address 128-bit aligned address in flash to write.
* @param data pointer to data to be written to flash.
* @return #E_NO_ERROR if successful, @ref MXC_Error_Codes "error" if
* unsuccessful.
*/
int FLC_Write128(uint32_t address, uint32_t *data);
/**
* @brief Writes data to flash.
* @param address Address in flash to start writing from.
* @param length Number of bytes to be written.
* @param buffer Pointer to data to be written to flash.
* @return #E_NO_ERROR if successful, @ref MXC_Error_Codes "error" if
* unsuccessful.
*/
int FLC_Write(uint32_t address, uint32_t length, uint8_t *buffer);
/**
* @brief Enable flash interrupts
* @param mask Interrupts to enable
* @return #E_NO_ERROR if successful, @ref MXC_Error_Codes "error" if
* unsuccessful.
*/
int FLC_EnableInt(uint32_t mask);
/**
* @brief Disable flash interrupts
* @param mask Interrupts to disable
* @return #E_NO_ERROR if successful, @ref MXC_Error_Codes "error" if
* unsuccessful.
*/
int FLC_DisableInt(uint32_t mask);
/**
* @brief Retrieve flash interrupt flags
* @return Mask of active flags.
*/
int FLC_GetFlags(void);
/**
* @brief Clear flash interrupt flags
* @note Provide the bit position to clear, even if the flag is write-0-to-clear
* @param mask Mask of flags to clear
* @return #E_NO_ERROR if successful, @ref MXC_Error_Codes "error" if
* unsuccessful.
*/
int FLC_ClearFlags(uint32_t mask);
/**
* @brief Unlock info block
*
* @return #E_NO_ERROR If function is successful.
*/
int FLC_UnlockInfoBlock(void);
/**
* @brief Lock info block
*
* @return #E_NO_ERROR If function is successful.
*/
int FLC_LockInfoBlock(void);
/**@} end of group flc */
#ifdef __cplusplus
}
#endif
#endif /* _FLC_H_ */
@@ -0,0 +1,295 @@
/**
* @file gpio.h
* @brief General-Purpose Input/Output (GPIO) function prototypes and data types.
*/
/* ****************************************************************************
* Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Maxim Integrated
* Products, Inc. shall not be used except as stated in the Maxim Integrated
* Products, Inc. Branding Policy.
*
* The mere transfer of this software does not imply any licenses
* of trade secrets, proprietary technology, copyrights, patents,
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*
* $Date: 2018-12-18 15:37:22 -0600 (Tue, 18 Dec 2018) $
* $Revision: 40072 $
*
*************************************************************************** */
/* Define to prevent redundant inclusion */
#ifndef _GPIO_H_
#define _GPIO_H_
/* **** Includes **** */
#include "gpio_regs.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @defgroup gpio General-Purpose Input/Output (GPIO)
* @ingroup periphlibs
* @{
*/
/* **** Definitions **** */
/**
* @defgroup gpio_port_pin Port and Pin Definitions
* @ingroup gpio
* @{
* @defgroup gpio_port Port Definitions
* @ingroup gpio_port_pin
* @{
*/
#define PORT_0 ((uint32_t)(0UL)) /**< Port 0 Define*/
#define PORT_1 ((uint32_t)(1UL)) /**< Port 1 Define*/
#define PORT_2 ((uint32_t)(2UL)) /**< Port 2 Define*/
#define PORT_3 ((uint32_t)(3UL)) /**< Port 3 Define*/
#define PORT_4 ((uint32_t)(4UL)) /**< Port 4 Define*/
/**@} end of gpio_port group*/
/**
* @defgroup gpio_pin Pin Definitions
* @ingroup gpio_port_pin
* @{
*/
#define PIN_0 ((uint32_t)(1UL << 0)) /**< Pin 0 Define */
#define PIN_1 ((uint32_t)(1UL << 1)) /**< Pin 1 Define */
#define PIN_2 ((uint32_t)(1UL << 2)) /**< Pin 2 Define */
#define PIN_3 ((uint32_t)(1UL << 3)) /**< Pin 3 Define */
#define PIN_4 ((uint32_t)(1UL << 4)) /**< Pin 4 Define */
#define PIN_5 ((uint32_t)(1UL << 5)) /**< Pin 5 Define */
#define PIN_6 ((uint32_t)(1UL << 6)) /**< Pin 6 Define */
#define PIN_7 ((uint32_t)(1UL << 7)) /**< Pin 7 Define */
#define PIN_8 ((uint32_t)(1UL << 8)) /**< Pin 8 Define */
#define PIN_9 ((uint32_t)(1UL << 9)) /**< Pin 9 Define */
#define PIN_10 ((uint32_t)(1UL << 10)) /**< Pin 10 Define */
#define PIN_11 ((uint32_t)(1UL << 11)) /**< Pin 11 Define */
#define PIN_12 ((uint32_t)(1UL << 12)) /**< Pin 12 Define */
#define PIN_13 ((uint32_t)(1UL << 13)) /**< Pin 13 Define */
#define PIN_14 ((uint32_t)(1UL << 14)) /**< Pin 14 Define */
#define PIN_15 ((uint32_t)(1UL << 15)) /**< Pin 15 Define */
#define PIN_16 ((uint32_t)(1UL << 16)) /**< Pin 16 Define */
#define PIN_17 ((uint32_t)(1UL << 17)) /**< Pin 17 Define */
#define PIN_18 ((uint32_t)(1UL << 18)) /**< Pin 18 Define */
#define PIN_19 ((uint32_t)(1UL << 19)) /**< Pin 19 Define */
#define PIN_20 ((uint32_t)(1UL << 20)) /**< Pin 20 Define */
#define PIN_21 ((uint32_t)(1UL << 21)) /**< Pin 21 Define */
#define PIN_22 ((uint32_t)(1UL << 22)) /**< Pin 22 Define */
#define PIN_23 ((uint32_t)(1UL << 23)) /**< Pin 23 Define */
#define PIN_24 ((uint32_t)(1UL << 24)) /**< Pin 24 Define */
#define PIN_25 ((uint32_t)(1UL << 25)) /**< Pin 25 Define */
#define PIN_26 ((uint32_t)(1UL << 26)) /**< Pin 26 Define */
#define PIN_27 ((uint32_t)(1UL << 27)) /**< Pin 27 Define */
#define PIN_28 ((uint32_t)(1UL << 28)) /**< Pin 28 Define */
#define PIN_29 ((uint32_t)(1UL << 29)) /**< Pin 29 Define */
#define PIN_30 ((uint32_t)(1UL << 30)) /**< Pin 30 Define */
#define PIN_31 ((uint32_t)(1UL << 31)) /**< Pin 31 Define */
/**@} end of gpio_pin group */
/**@} end of gpio_port_pin group */
/**
* Enumeration type for the GPIO Function Type
*/
typedef enum {
GPIO_FUNC_IN, /**< GPIO Input */
GPIO_FUNC_OUT, /**< GPIO Output */
GPIO_FUNC_ALT1, /**< Alternate Function Selection */
GPIO_FUNC_ALT2, /**< Alternate Function Selection */
GPIO_FUNC_ALT3, /**< Alternate Function Selection */
GPIO_FUNC_ALT4, /**< Alternate Function Selection */
} gpio_func_t;
/**
* Enumeration type for the type of GPIO pad on a given pin.
*/
typedef enum {
GPIO_PAD_NONE, /**< No pull-up or pull-down */
GPIO_PAD_PULL_UP, /**< Set pad to weak pull-up */
GPIO_PAD_PULL_DOWN, /**< Set pad to weak pull-down */
} gpio_pad_t;
/**
* Structure type for configuring a GPIO port.
*/
typedef struct {
uint32_t port; /**< Index of GPIO port */
uint32_t mask; /**< Pin mask (multiple pins may be set) */
gpio_func_t func; /**< Function type */
gpio_pad_t pad; /**< Pad type */
} gpio_cfg_t;
/**
* Enumeration type for the interrupt modes.
*/
typedef enum {
GPIO_INT_LEVEL = 0, /**< Interrupt is level sensitive */
GPIO_INT_EDGE = 1 /**< Interrupt is edge sensitive */
} gpio_int_mode_t;
/**
* Enumeration type for the interrupt polarity.
*/
typedef enum {
GPIO_INT_FALLING = 0, /**< Interrupt triggers on falling edge */
GPIO_INT_HIGH = GPIO_INT_FALLING, /**< Interrupt triggers when level is high */
GPIO_INT_RISING, /**< Interrupt triggers on rising edge */
GPIO_INT_LOW = GPIO_INT_RISING, /**< Interrupt triggers when level is low */
GPIO_INT_BOTH /**< Interrupt triggers on either edge */
} gpio_int_pol_t;
/* **** Function Prototypes **** */
/**
* @brief Initialize GPIO.
* @return #E_NO_ERROR if everything is successful.
*/
int GPIO_Init(void);
/**
* @brief Configure GPIO pin(s).
* @param cfg Pointer to configuration structure describing the pin.
* @return #E_NO_ERROR if everything is successful.
*/
int GPIO_Config(const gpio_cfg_t *cfg);
/**
* @brief Gets the pin(s) input state.
* @param cfg Pointer to configuration structure describing the pin.
* @return The requested pin state.
*/
uint32_t GPIO_InGet(const gpio_cfg_t *cfg);
/**
* @brief Sets the pin(s) to a high level output.
* @param cfg Pointer to configuration structure describing the pin.
*
*/
void GPIO_OutSet(const gpio_cfg_t *cfg);
/**
* @brief Clears the pin(s) to a low level output.
* @param cfg Pointer to configuration structure describing the pin.
*
*/
void GPIO_OutClr(const gpio_cfg_t *cfg);
/**
* @brief Gets the pin(s) output state.
* @param cfg Pointer to configuration structure describing the pin.
*
* @return The state of the requested pin.
*
*/
uint32_t GPIO_OutGet(const gpio_cfg_t *cfg);
/**
* @brief Write the pin(s) to a desired output level.
* @param cfg Pointer to configuration structure describing the pin.
* @param val Desired output level of the pin(s). This will be masked
* with the configuration mask.
*/
void GPIO_OutPut(const gpio_cfg_t *cfg, uint32_t val);
/**
* @brief Toggles the the pin(s) output level.
* @param cfg Pointer to configuration structure describing the pin.
*
*/
void GPIO_OutToggle(const gpio_cfg_t *cfg);
/**
* @brief Configure GPIO interrupt(s)
* @param cfg Pointer to configuration structure describing the pin.
* @param mode Requested interrupt mode.
* @param pol Requested interrupt polarity.
* @return #E_NO_ERROR if everything is successful.
*/
int GPIO_IntConfig(const gpio_cfg_t *cfg, gpio_int_mode_t mode, gpio_int_pol_t pol);
/**
* @brief Enables the specified GPIO interrupt
* @param cfg Pointer to configuration structure describing the pin.
*
*/
void GPIO_IntEnable(const gpio_cfg_t *cfg);
/**
* @brief Disables the specified GPIO interrupt.
* @param cfg Pointer to configuration structure describing the pin.
*/
void GPIO_IntDisable(const gpio_cfg_t *cfg);
/**
* @brief Gets the interrupt(s) status on a GPIO pin.
* @param cfg Pointer to configuration structure describing the pin
* for which the status is being requested.
* @return The requested interrupt status.
*/
uint32_t GPIO_IntStatus(const gpio_cfg_t *cfg);
/**
* @brief Clears the interrupt(s) status on a GPIO pin.
* @param cfg Pointer to configuration structure describing the pin
* to clear the interrupt state of.
*/
void GPIO_IntClr(const gpio_cfg_t *cfg);
/**
* @brief Type alias for a GPIO callback function with prototype:
* @code
void callback_fn(void *cbdata);
* @endcode
* @param cbdata A void pointer to the data type as registered when
* GPIO_RegisterCallback() was called.
*/
typedef void (*gpio_callback_fn)(void *cbdata);
/**
* @brief Registers a callback for the interrupt on a given port and pin.
* @param cfg Pointer to configuration structure describing the pin
* @param callback A pointer to a function of type \c #gpio_callback_fn.
* @param cbdata The parameter to be passed to the callback function, #gpio_callback_fn, when an interrupt occurs.
*
*/
void GPIO_RegisterCallback(const gpio_cfg_t *cfg, gpio_callback_fn callback, void *cbdata);
/**
* @brief GPIO IRQ Handler. @note If a callback is registered for a given
* interrupt, the callback function will be called.
*
* @param port number of the port that generated the interrupt service routine.
*
*/
void GPIO_Handler(unsigned int port);
/**@} end of group gpio */
#ifdef __cplusplus
}
#endif
#endif /* _GPIO_H_ */
@@ -0,0 +1,250 @@
/**
* @file i2c.h
* @brief Inter-integrated circuit (I2C) communications interface driver.
*/
/* ****************************************************************************
* Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Maxim Integrated
* Products, Inc. shall not be used except as stated in the Maxim Integrated
* Products, Inc. Branding Policy.
*
* The mere transfer of this software does not imply any licenses
* of trade secrets, proprietary technology, copyrights, patents,
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*
* $Date: 2019-06-28 09:42:42 -0500 (Fri, 28 Jun 2019) $
* $Revision: 44330 $
*
*************************************************************************** */
#ifndef _I2C_H_
#define _I2C_H_
#include <stdint.h>
#include "i2c_regs.h"
#include "mxc_sys.h"
/**
* @defgroup i2c I2C
* @ingroup periphlibs
* @{
*/
/***** Definitions *****/
/// @brief I2C Speed Modes
typedef enum {
I2C_STD_MODE = 100000, //!< 100KHz Bus Speed
I2C_FAST_MODE = 400000, //!< 400KHz Bus Speed
I2C_FASTPLUS_MODE = 1000000, //!< 1MHz Bus Speed
I2C_HS_MODE = 3400000 //!< 3.4MHz Bus Speed
} i2c_speed_t;
//State for Master
typedef enum {
I2C_STATE_READING = 0,
I2C_STATE_WRITING = 1
} i2c_state_t;
// @brief Enable/Disable TXFIFO Autoflush mode
typedef enum {
I2C_AUTOFLUSH_ENABLE = 0,
I2C_AUTOFLUSH_DISABLE = 1
} i2c_autoflush_disable_t;
// @brief I2C Transaction request.
typedef struct i2c_req i2c_req_t;
struct i2c_req {
uint8_t addr; /**< @parblock I2C 7-bit Address left aligned, bit 7 to bit 1.
* Only supports 7-bit addressing. LSb of the given address
* will be used as the read/write bit, the @p addr <b>will
* not be shifted</b>. Used for <em>both master</em> and
* @em slave transactions. @endparblock
*/
const uint8_t *tx_data; ///< Data for mater write/slave read.
uint8_t *rx_data; ///< Data for master read/slave write.
unsigned tx_len; ///< Length of tx data.
unsigned rx_len; ///< Length of rx.
unsigned tx_num; ///< Number of tx bytes sent.
unsigned rx_num; ///< Number of rx bytes sent.
i2c_state_t state; ///< Read or Write.
/**
* @details 0 to send a stop bit at the end of the transaction,
otherwise send a restart. Only used in master trasnactions.
*/
int restart; /**< @parblock Restart or stop bit indicator.
* @arg 0 to send a stop bit at the end of the transaction
* @arg Non-zero to send a restart at end of the transaction
* @note Only used for Master transactions.
* @endparblock
*/
i2c_autoflush_disable_t sw_autoflush_disable; ///< Enable/Disable autoflush.
/**
* @brief Callback for asynchronous request.
* @param i2c_req_t* Pointer to the transaction request.
* @param int Error code.
*/
void (*callback)(i2c_req_t*, int);
};
/***** Function Prototypes *****/
/**
* @brief Initialize and enable I2C.
* @param i2c Pointer to I2C peripheral registers.
* @param i2cspeed desired speed (I2C mode)
* @param sys_cfg System configuration object
* @returns \c #E_NO_ERROR if everything is successful,
* @ref MXC_Error_Codes if an error occurred.
*/
int I2C_Init(mxc_i2c_regs_t * i2c, i2c_speed_t i2cspeed, const sys_cfg_i2c_t* sys_cfg);
/**
* @brief Shutdown I2C module.
* @param i2c Pointer to the I2C registers.
* @returns #E_NO_ERROR I2C shutdown successfully, @ref MXC_Error_Codes "error" if
* unsuccessful.
*/
int I2C_Shutdown(mxc_i2c_regs_t *i2c);
/**
* @brief Master write data. Will block until transaction is complete.
* @param i2c Pointer to I2C regs.
* @param addr @parblock I2C 7-bit Address left aligned, bit 7 to bit 1.
* Only supports 7-bit addressing. LSb of the given address
* will be used as the read/write bit, the \p addr <b>will
* not be shifted</b>. Used for <em>both master</em> and
* @em slave transactions. @endparblock
* @param data Data to be written.
* @param len Number of bytes to Write.
* @param restart 0 to send a stop bit at the end of the transaction,
otherwise send a restart.
* @returns Bytes transacted if everything is successful,
* @ref MXC_Error_Codes if an error occurred.
*/
int I2C_MasterWrite(mxc_i2c_regs_t *i2c, uint8_t addr, const uint8_t* data, int len, int restart);
/**
* @brief Master read data. Will block until transaction is complete.
* @param i2c Pointer to I2C regs.
* @param addr @parblock I2C 7-bit Address left aligned, bit 7 to bit 1.
* Only supports 7-bit addressing. LSb of the given address
* will be used as the read/write bit, the @p addr <b>will
* not be shifted</b>. Used for <em>both master</em> and
* @em slave transactions. @endparblock
* @param data Data to be written.
* @param len Number of bytes to Write.
* @param restart 0 to send a stop bit at the end of the transaction,
otherwise send a restart.
* @returns Bytes transacted if everything is successful, @ref MXC_Error_Codes if an error occurred.
*/
int I2C_MasterRead(mxc_i2c_regs_t *i2c, uint8_t addr, uint8_t* data, int len, int restart);
/**
* @brief Slave read data. Will block until transaction is complete.
* @param i2c Pointer to I2C regs.
* @param addr @parblock I2C 7-bit Address left aligned, bit 7 to bit 1.
* Only supports 7-bit addressing. LSb of the given address
* will be used as the read/write bit, the @p addr <b>will
* not be shifted</b>. Used for <em>both master</em> and
* @em slave transactions. @endparblock
* @param read_data Buffer that the master will read from.
* @param read_len Number of bytes the master can read.
* @param write_data Buffer that the master will write to.
* @param write_len Number of bytes the master can write.
* @param tx_num Number of bytes transmitted by the slave.
* @param rx_num Number of bytes received by the slave.
* @param sw_autoflush_disable TX Autoflush enabled by default.Set this bit to disable autoflush manually.
* @returns #E_NO_ERROR if everything is successful, @ref MXC_Error_Codes if an error occurred.
*/
int I2C_Slave(mxc_i2c_regs_t *i2c, uint8_t addr, const uint8_t* read_data,
int read_len, uint8_t* write_data, int write_len, int* tx_num,
int* rx_num, i2c_autoflush_disable_t sw_autoflush_disable);
/**
* @brief Master Read and Write Asynchronous.
* @param i2c Pointer to I2C regs.
* @param req Request for an I2C transaction.
* @returns #E_NO_ERROR if everything is successful, @ref MXC_Error_Codes if an error occurred.
*/
int I2C_MasterAsync(mxc_i2c_regs_t *i2c, i2c_req_t *req);
/**
* @brief Slave Read and Write Asynchronous.
* @param i2c Pointer to I2C regs.
* @param req Request for an I2C transaction.
* @returns #E_NO_ERROR if everything is successful, @ref MXC_Error_Codes if an error occurred.
*/
int I2C_SlaveAsync(mxc_i2c_regs_t *i2c, i2c_req_t *req);
/**
* @brief I2C interrupt handler.
* @details This function should be called by the application from the interrupt
* handler if I2C interrupts are enabled. Alternately, this function
* can be periodically called by the application if I2C interrupts are
* disabled.
* @param i2c Base address of the I2C module.
*/
void I2C_Handler(mxc_i2c_regs_t *i2c);
/**
* @brief Drain all of the data in the RXFIFO.
* @param i2c Pointer to I2C regs.
*/
void I2C_DrainRX(mxc_i2c_regs_t *i2c);
/**
* @brief Drain all of the data in the TXFIFO.
* @param i2c Pointer to I2C regs.
*/
void I2C_DrainTX(mxc_i2c_regs_t *i2c);
/**
* @brief Abort Async request based on the request you want to abort.
* @param req Pointer to I2C Transaction.
*/
int I2C_AbortAsync(i2c_req_t *req);
/**
* @brief Enable and Set Timeout
*
* @param i2c pointer to I2C regs
* @param[in] us micro seconds to delay
*
* @return E_NO_ERROR or E_BAD_PARAM if delay is to long.
*/
int I2C_SetTimeout(mxc_i2c_regs_t *i2c, int us);
/**
* @brief clear and disable timeout
*
* @param i2c pointer to I2C regs
*/
void I2C_ClearTimeout(mxc_i2c_regs_t *i2c);
/**@} end of group i2c */
#endif /* _I2C_H_ */
@@ -0,0 +1,179 @@
/**
* @file i2s.h
* @brief I2S (Inter-Integrated Sound) driver function prototypes and data types.
*/
/* ****************************************************************************
* Copyright (C) 2017 Maxim Integrated Products, Inc., All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Maxim Integrated
* Products, Inc. shall not be used except as stated in the Maxim Integrated
* Products, Inc. Branding Policy.
*
* The mere transfer of this software does not imply any licenses
* of trade secrets, proprietary technology, copyrights, patents,
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*
* $Date: 2018-12-18 15:37:22 -0600 (Tue, 18 Dec 2018) $
* $Revision: 40072 $
*
*************************************************************************** */
#ifndef _I2S_H_
#define _I2S_H_
/* **** Includes **** */
#include "mxc_config.h"
#include "dma.h"
#include "spimss_regs.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @defgroup i2s Inter-Integrated Sound (I2S)
* @ingroup spi
* @{
*/
/* **** Definitions **** */
/** @brief I2S audio directions */
typedef enum {
AUDIO_OUT = 1,
AUDIO_IN = 2,
} i2s_direction_t;
/** @brief I2S Configuration Struct */
typedef struct {
uint8_t left_justify;
uint8_t mono_audio;
i2s_direction_t audio_direction;
unsigned int sample_rate;
unsigned int start_immediately;
void *dma_src_addr;
void *dma_dst_addr;
unsigned int dma_cnt;
unsigned int dma_reload_en;
} i2s_cfg_t;
/* **** Function Prototypes **** */
/**
* @brief Initialize I2S resources
* @param cfg I2S Configuration Struct
* @param dma_ctz_cb Optional function to be called when the DMA completes
a transfer. Set to NULL if unused.
* @param sys_cfg_i2s System configuration object
* @details This initialization is required before using the I2S driver functions.
* @return \c #E_NO_ERROR if successful
*/
int I2S_Init(const i2s_cfg_t *cfg, void (*dma_ctz_cb)(int, int), const sys_cfg_i2s_t* sys_cfg_i2s);
/**
* @brief Release I2S
* @details De-configures the I2S protocol and stops DMA request
* @return \c #E_BAD_PARAM if DMA cannot be stopped, #E_NO_ERROR otherwise
*/
int I2S_Shutdown(void);
/**
* @brief Mute I2S Output
* @details Sets I2S data to zero, continues sending clock and accessing DMA
* @return \c #E_NO_ERROR
*/
int I2S_Mute(void);
/**
* @brief Unmute I2S Output
* @details Restores I2S data
* @return \c #E_NO_ERROR
*/
int I2S_Unmute(void);
/**
* @brief Pause I2S Output
* @details Similar to mute, but stops FIFO and DMA access, clocks continue
* @return \c #E_NO_ERROR
*/
int I2S_Pause(void);
/**
* @brief Unpause I2S Output
* @details Similar to mute, but restarts FIFO and DMA access
* @return \c #E_NO_ERROR
*/
int I2S_Unpause(void);
/**
* @brief Stops I2S Output
* @details Similar to pause, but also halts clock
* @return \c #E_NO_ERROR
*/
int I2S_Stop(void);
/**
* @brief Starts I2S Output
* @details Starts I2S Output, automatically called by configure if requested
* @return \c #E_NO_ERROR
*/
int I2S_Start(void);
/**
* @brief Clears DMA Interrupt Flags
* @details Clears the DMA Interrupt flags, should be called at the end of a dma_ctz_cb
* @return \c #E_NO_ERROR
*/
int I2S_DMA_ClearFlags(void);
/**
* @brief Set DMA Addr (Source or Dest) and bytes to transfer
* @param src_addr The address to read data from (Audio Out)
* @param dst_addr The address to write data to (Audio In)
* @param count The length of the transfer in bytes
* @details Sets the address to read/write data in memory and the length of
* the transfer. The unused addr parameter is ignored.
* @return \c #E_NO_ERROR
*/
int I2S_DMA_SetAddrCnt(void *src_addr, void *dst_addr, unsigned int count);
/**
* @brief Sets the DMA reload address and count
* @param src_addr The address to read data from (Audio Out)
* @param dst_addr The address to write data to (Audio In)
* @param count The length of the transfer in bytes
* @details If DMA reload is enabled, when the DMA has transfered $count bytes
* (a CTZ event occurs) the src, dst, and count registers will be
* set to these. The DMA reload flag clears after a reload occurs.
* @return \c #E_NO_ERROR
*/
int I2S_DMA_SetReload(void *src_addr, void *dst_addr, unsigned int count);
/**@} end of group i2s */
#ifdef __cplusplus
}
#endif
#endif /* _I2S_H_ */
@@ -0,0 +1,97 @@
/**
* @file icc.h
* @brief Instruction Controller Cache(ICC) function prototypes and data types.
*/
/* ****************************************************************************
* Copyright (C) 2017 Maxim Integrated Products, Inc., All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Maxim Integrated
* Products, Inc. shall not be used except as stated in the Maxim Integrated
* Products, Inc. Branding Policy.
*
* The mere transfer of this software does not imply any licenses
* of trade secrets, proprietary technology, copyrights, patents,
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*
* $Date: 2018-12-18 15:37:22 -0600 (Tue, 18 Dec 2018) $
* $Revision: 40072 $
*
*************************************************************************** */
/* Define to prevent redundant inclusion */
#ifndef _ICC_H_
#define _ICC_H_
/* **** Includes **** */
#include <stdint.h>
#include "icc_regs.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @defgroup icc Internal Cache Controller (ICC)
* @ingroup periphlibs
* @{
*/
/**
* @brief Enumeration type for the Cache ID Register
*/
typedef enum {
ICC_CACHE_ID_RELNUM, // Identifies the RTL release version
ICC_CACHE_ID_PARTNUM, // Specifies the value of C_ID Port Number
ICC_CACHE_ID_CCHID // Specifies the value of Cache ID
} icc_cache_id_t;
/**
* @brief Reads the data from the Cache Id Register.
* @param cid Enumeration type for Cache Id Register.
* @retval Returns the contents of Cache Id Register.
*/
int ICC_ID(icc_cache_id_t cid);
/**
* @brief Enable the instruction cache controller.
*/
void ICC_Enable(void);
/**
* @brief Disable the instruction cache controller.
*/
void ICC_Disable(void);
/**
* @brief Flush the instruction cache controller.
*/
void ICC_Flush(void);
/**@} end of group icc */
#ifdef __cplusplus
}
#endif
#endif /* _ICC_H_ */
@@ -0,0 +1,341 @@
/**
* @file lp.h
* @brief Low power function prototypes and data types.
*/
/* ****************************************************************************
* Copyright (C) 2017 Maxim Integrated Products, Inc., All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Maxim Integrated
* Products, Inc. shall not be used except as stated in the Maxim Integrated
* Products, Inc. Branding Policy.
*
* The mere transfer of this software does not imply any licenses
* of trade secrets, proprietary technology, copyrights, patents,
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*
* $Date: 2018-09-26 08:48:30 -0500 (Wed, 26 Sep 2018) $
* $Revision: 38105 $
*
*************************************************************************** */
// Define to prevent redundant inclusion
#ifndef _LP_H_
#define _LP_H_
/***** Includes *****/
#include "gpio.h"
#include "pwrseq_regs.h"
#ifdef __cplusplus
extern "C" {
#endif
/** @brief System reset0 enumeration. Used in SYS_PeriphReset0 function */
typedef enum {
LP_OVR_0_9 = MXC_S_PWRSEQ_LP_CTRL_OVR_0_9V, /**< Reset DMA */
LP_OVR_1_0 = MXC_S_PWRSEQ_LP_CTRL_OVR_1_0V, /**< Reset DMA */
LP_OVR_1_1 = MXC_S_PWRSEQ_LP_CTRL_OVR_1_1V, /**< Reset DMA */
} lp_ovr_t;
/**
* @brief Clears the low power wakeup flags
*/
void LP_ClearWakeStatus(void);
/**
* @brief Enables power to RAM addresses 0x20010000-0x20017FFF.
*/
void LP_EnableSRAM3(void);
/**
* @brief Enables power to RAM addresses 0x20008000-0x2000FFFF.
*/
void LP_EnableSRAM2(void);
/**
* @brief Enables power to RAM addresses 0x20004000-0x20007FFF.
*/
void LP_EnableSRAM1(void);
/**
* @brief Enables power to RAM addresses 0x20000000-0x20003FFF.
*/
void LP_EnableSRAM0(void);
/**
* @brief Disables power to RAM addresses 0x20010000-0x20017FFF. The contents of the RAM are destroyed.
*/
void LP_DisableSRAM3(void);
/**
* @brief Disables power to RAM addresses 0x20008000-0x2000FFFF. The contents of the RAM are destroyed.
*/
void LP_DisableSRAM2(void);
/**
* @brief Disables power to RAM addresses 0x20004000-0x20007FFF. The contents of the RAM are destroyed.
*/
void LP_DisableSRAM1(void);
/**
* @brief Disables power to RAM addresses 0x20000000-0x20003FFF. The contents of the RAM are destroyed.
*/
void LP_DisableSRAM0(void);
/**
* @brief Places the instruction cache in light sleep mode. Data will be unavailable for read/write operations but will be retained.
*/
void LP_EnableICacheLightSleep(void);
/**
* @brief Places addresses 0x20010000 to 0x20017FFF of the RAM in light sleep mode. Data will be unavailable for read/write operations but will be retained.
*/
void LP_EnableSysRAM3LightSleep(void);
/**
* @brief Places addresses 0x20008000 to 0x2000FFFF of the RAM in light sleep mode. Data will be unavailable for read/write operations but will be retained.
*/
void LP_EnableSysRAM2LightSleep(void);
/**
* @brief Places addresses 0x20004000 to 0x20007FFF of the RAM in light sleep mode. Data will be unavailable for read/write operations but will be retained.
*/
void LP_EnableSysRAM1LightSleep(void);
/**
* @brief Places addresses 0x20000000 to 0x20003FFF of the RAM in light sleep mode. Data will be unavailable for read/write operations but will be retained.
*/
void LP_EnableSysRAM0LightSleep(void);
/**
* @brief Places the instruction cache in active mode.
*/
void LP_DisableICacheLightSleep(void);
/**
* @brief Places addresses 0x20010000 to 0x20017FFF of the RAM in active mode.
*/
void LP_DisableSysRAM3LightSleep(void);
/**
* @brief Places addresses 0x20008000 to 0x2000FFFF of the RAM in active mode.
*/
void LP_DisableSysRAM2LightSleep(void);
/**
* @brief Places addresses 0x20004000 to 0x20007FFF of the RAM in active mode.
*/
void LP_DisableSysRAM1LightSleep(void);
/**
* @brief Places addresses 0x20000000 to 0x20003FFF of the RAM in active mode.
*/
void LP_DisableSysRAM0LightSleep(void);
/**
* @brief Enables the selected GPIO port and its selected pins to wake up the device from any low power mode.
* Call this function multiple times to enable pins on multiple ports. This function does not configure
* the GPIO pins nor does it setup their interrupt functionality.
* @param wu_pins The port and pins to configure as wakeup sources. Only the gpio and mask fields of the
* structure are used. The func and pad fields are ignored.
*/
void LP_EnableGPIOWakeup(const gpio_cfg_t *wu_pins);
/**
* @brief Disables the selected GPIO port and its selected pins as a wake up source.
* Call this function multiple times to disable pins on multiple ports.
* @param wu_pins The port and pins to disable as wakeup sources. Only the gpio and mask fields of the
* structure are used. The func and pad fields are ignored.
*/
void LP_DisableGPIOWakeup(const gpio_cfg_t *wu_pins);
/**
* @brief Enables the RTC alarm to wake up the device from any low power mode.
*/
void LP_EnableRTCAlarmWakeup(void);
/**
* @brief Disables the RTC alarm from waking up the device.
*/
void LP_DisableRTCAlarmWakeup(void);
/**
* @brief Places the device into SLEEP mode. This function returns once any interrupt occurs.
* @note LP_ClearWakeStatus should be called before this function, to avoid immediately waking up again
*/
void LP_EnterSleepMode(void);
/**
* @brief Places the device into DEEPSLEEP mode. This function returns once an RTC or external interrupt occur.
* @note LP_ClearWakeStatus should be called before this function, to avoid immediately waking up again
*/
void LP_EnterDeepSleepMode(void);
/**
* @brief Places the device into BACKUP mode. CPU state is not maintained in this mode, so this function never returns.
* Instead, the device will restart once an RTC or external interrupt occur.
* @note LP_ClearWakeStatus should be called before this function, to avoid immediately waking up again
*/
void LP_EnterBackupMode(void);
/**
* @brief Places the device into Shutdown mode. CPU state is not maintained in this mode, so this function never returns.
* Instead, the device will restart once an RTC, USB wakeup, or external interrupt occur.
*/
void LP_EnterShutDownMode(void);
/**
* @brief Set operating voltage and change the clock to match the new voltage.
* @param system reset configuration struct
*/
void LP_SetOperatingVoltage(lp_ovr_t ovr);
/**
* @brief Enables Data Retention to RAM addresses 0x20000000-0x20003FFF.
*/
void LP_EnableSRamRet0(void);
/**
* @brief Disables Data Retention to RAM addresses 0x20000000-0x20003FFF.
*/
void LP_DisableSRamRet0(void);
/**
* @brief Enables Data Retention to RAM addresses 0x20004000-0x20007FFF.
*/
void LP_EnableSRamRet1(void);
/**
* @brief Disables Data Retention to RAM addresses 0x20004000-0x20007FFF.
*/
void LP_DisableSRamRet1(void);
/**
* @brief Enables Data Retention to RAM addresses 0x20008000-0x2000FFFF.
*/
void LP_EnableSRamRet2(void);
/**
* @brief Disables Data Retention to RAM addresses 0x20008000-0x2000FFFF.
*/
void LP_DisableSRamRet2(void);
/**
* @brief Enables Data Retention to RAM addresses 0x20010000-0x20017FFF.
*/
void LP_EnableSRamRet3(void);
/**
* @brief Disables Data Retention to RAM addresses 0x20010000-0x20017FFF.
*/
void LP_DisableSRamRet3(void);
/**
* @brief Enables Bypassing the hardware detection of an external supply on V CORE enables a faster wakeup time.
*/
void LP_EnableBlockDetect(void);
/**
* @brief Disables Bypassing the hardware detection of an external supply on V CORE enables a faster wakeup time
*/
void LP_DisableBlockDetect(void);
/**
* @brief RAM Retention Regulator Enable for BACKUP Mode
*/
void LP_EnableRamRetReg(void);
/**
* @brief RAM Retention Regulator Disabels for BACKUP Mode
*/
void LP_DisableRamRetReg(void);
/**
* @brief Enables Fast wake up from deepsleep
*/
void LP_EnableFastWk(void);
/**
* @brief Disables Fast wake up from deepsleep
*/
void LP_DisableFastWk(void);
/**
* @brief Turns on band gap during deepsleep and backup mode.
*/
void LP_EnableBandGap(void);
/**
* @brief Turns off band gap during deepsleep and backup mode.
*/
void LP_DisableBandGap(void);
/**
* @brief Enables signal for power on reset when the device is int DEEPSLEEP or BACKUP mode
*/
void LP_EnableVCorePORSignal(void);
/**
* @brief Disables signal for power on reset when the device is int DEEPSLEEP or BACKUP mode
*/
void LP_DisableVCorePORSignal(void);
/**
* @brief Enables signal for power on reset when the device is int DEEPSLEEP or BACKUP mode
*/
void LP_EnableLDO(void);
/**
* @brief Disables signal for power on reset when the device is int DEEPSLEEP or BACKUP mode
*/
void LP_DisableLDO(void);
/**
* @brief Enables V CORE Supply Voltage Monitor
*/
void LP_EnableVCoreSVM(void);
/**
* @brief Disables V CORE Supply Voltage Monitor
*/
void LP_DisableVCoreSVM(void);
/**
* @brief Enables VDDIO Power-On-Reset Monitor
*/
void LP_EnableVDDIOPorMonitor(void);
/**
* @brief Disables VDDIO Power-On-Reset Monitor
*/
void LP_DisableVDDIOPorMonitor(void);
#ifdef __cplusplus
}
#endif
#endif /* _LP_H_ */
@@ -0,0 +1,113 @@
/**
* @file
* @brief Assertion checks for debugging.
*/
/* ****************************************************************************
* Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Maxim Integrated
* Products, Inc. shall not be used except as stated in the Maxim Integrated
* Products, Inc. Branding Policy.
*
* The mere transfer of this software does not imply any licenses
* of trade secrets, proprietary technology, copyrights, patents,
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*
*
* $Date: 2018-08-09 18:45:02 -0500 (Thu, 09 Aug 2018) $
* $Revision: 36818 $
*
*************************************************************************** */
/* Define to prevent redundant inclusion */
#ifndef _MXC_ASSERT_H_
#define _MXC_ASSERT_H_
/* **** Includes **** */
#ifdef __cplusplus
extern "C" {
#endif
/**
* @ingroup syscfg
* @defgroup mxc_assertions Assertion Checks for Debugging
* @brief Assertion checks for debugging.
* @{
*/
/* **** Definitions **** */
/**
* @note To use debug assertions, the symbol @c MXC_ASSERT_ENABLE must be
* defined.
*/
///@cond
#ifdef MXC_ASSERT_ENABLE
/**
* Macro that checks the expression for true and generates an assertion.
* @note To use debug assertions, the symbol @c MXC_ASSERT_ENABLE must be
* defined.
*/
#define MXC_ASSERT(expr) \
if (!(expr)) \
{ \
mxc_assert(#expr, __FILE__, __LINE__); \
}
/**
* Macro that generates an assertion with the message "FAIL".
* @note To use debug assertions, the symbol @c MXC_ASSERT_ENABLE must be
* defined.
*/
#define MXC_ASSERT_FAIL() mxc_assert("FAIL", __FILE__, __LINE__);
#else
#define MXC_ASSERT(expr)
#define MXC_ASSERT_FAIL()
#endif
///@endcond
/* **** Globals **** */
/* **** Function Prototypes **** */
/**
* @brief Assert an error when the given expression fails during debugging.
* @param expr String with the expression that failed the assertion.
* @param file File containing the failed assertion.
* @param line Line number for the failed assertion.
* @note This is defined as a weak function and can be overridden at the
* application layer to print the debugging information.
* @code
* printf("%s, file: %s, line %d\n", expr, file, line);
* @endcode
* @note To use debug assertions, the symbol @c MXC_ASSERT_ENABLE must be
* defined.
*/
void mxc_assert(const char *expr, const char *file, int line);
/**@} end of group MXC_Assertions*/
#ifdef __cplusplus
}
#endif
#endif /* _MXC_ASSERT_H_ */
@@ -0,0 +1,53 @@
/**
* @file mxc_config.h
* @brief Top-level include file for device configuration.
*/
/*******************************************************************************
* Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Maxim Integrated
* Products, Inc. shall not be used except as stated in the Maxim Integrated
* Products, Inc. Branding Policy.
*
* The mere transfer of this software does not imply any licenses
* of trade secrets, proprietary technology, copyrights, patents,
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*
* $Date: 2018-08-09 18:45:02 -0500 (Thu, 09 Aug 2018) $
* $Revision: 36818 $
*
******************************************************************************/
#ifndef _MXC_CONFIG_H
#define _MXC_CONFIG_H
#if !defined __GNUC__
#include "RTE_Components.h"
#endif /* not __GNUC__ */
#include "mxc_device.h"
#include "mxc_errors.h"
#include "mxc_pins.h"
#endif /* _CONFIG_H */
@@ -0,0 +1,124 @@
/**
* @file
* @brief Asynchronous delay routines based on the SysTick Timer.
*/
/* ****************************************************************************
* Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Maxim Integrated
* Products, Inc. shall not be used except as stated in the Maxim Integrated
* Products, Inc. Branding Policy.
*
* The mere transfer of this software does not imply any licenses
* of trade secrets, proprietary technology, copyrights, patents,
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*
* $Date: 2018-11-05 09:52:05 -0600 (Mon, 05 Nov 2018) $
* $Revision: 38934 $
*
*************************************************************************** */
/* Define to prevent redundant inclusion */
#ifndef _DELAY_H_
#define _DELAY_H_
/**
* @defgroup MXC_delay Delay Utility Functions
* @ingroup devicelibs
* @brief Asynchronous delay routines based on the SysTick Timer
* @{
*/
/***** Definitions *****/
/**
* Macro used to specify a microsecond timing parameter in seconds.
* \code
* x = SEC(3) // 3 seconds -> x = 3,000,000
* \endcode
*/
#define MXC_DELAY_SEC(s) (((unsigned long)s) * 1000000UL)
/**
* Macro used to specify a microsecond timing parameter in milliseconds.
* \code
* x = MSEC(3) // 3ms -> x = 3,000
* \endcode
*/
#define MXC_DELAY_MSEC(ms) (ms * 1000UL)
/**
* Macro used to specify a microsecond timing parameter.
* \code
* x = USEC(3) // 3us -> x = 3
* \endcode
*/
#define MXC_DELAY_USEC(us) (us)
/***** Function Prototypes *****/
/**
* @brief Blocks and delays for the specified number of microseconds.
* @details Uses the SysTick to create the requested delay. If the SysTick is
* running, the current settings will be used. If the SysTick is not
* running, it will be started.
* @param us microseconds to delay
* @return #E_NO_ERROR if no errors, @ref MXC_Error_Codes "error" if unsuccessful.
*/
int mxc_delay(unsigned long us);
/**
* @brief Starts a non-blocking delay for the specified number of
* microseconds.
* @details Uses the SysTick to time the requested delay. If the SysTick is
* running, the current settings will be used. If the SysTick is not
* running, it will be started.
* @note mxc_delay_handler() must be called from the SysTick interrupt service
* routine or at a rate greater than the SysTick overflow rate.
* @param us microseconds to delay
* @return #E_NO_ERROR if no errors, #E_BUSY if currently servicing another
* delay request.
*/
int mxc_delay_start(unsigned long us);
/**
* @brief Returns the status of a non-blocking delay request
* @pre Start the asynchronous delay by calling mxc_delay_start().
* @return #E_BUSY until the requested delay time has expired.
*/
int mxc_delay_check(void);
/**
* @brief Stops an asynchronous delay previously started.
* @pre Start the asynchronous delay by calling mxc_delay_start().
*/
void mxc_delay_stop(void);
/**
* @brief Processes the delay interrupt.
* @details This function must be called from the SysTick IRQ or polled at a
* rate greater than the SysTick overflow rate.
*/
void mxc_delay_handler(void);
/**@} end of group MXC_delay */
#endif /* _DELAY_H_ */
@@ -0,0 +1,94 @@
/**
* @file
* @brief List of common error return codes for Maxim Integrated libraries.
*/
/* ****************************************************************************
* Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Maxim Integrated
* Products, Inc. shall not be used except as stated in the Maxim Integrated
* Products, Inc. Branding Policy.
*
* The mere transfer of this software does not imply any licenses
* of trade secrets, proprietary technology, copyrights, patents,
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*
* $Date: 2018-08-09 18:45:02 -0500 (Thu, 09 Aug 2018) $
* $Revision: 36818 $
*
*************************************************************************** */
/* Define to prevent redundant inclusion */
#ifndef _MXC_ERRORS_H_
#define _MXC_ERRORS_H_
/**
* @ingroup syscfg
* @defgroup MXC_Error_Codes Error Codes
* @brief A list of common error codes used by the API.
* @note A Negative Error Convention is used to avoid conflict with
* positive, Non-Error, returns.
* @{
*/
/** No Error */
#define E_NO_ERROR 0
/** No Error, success */
#define E_SUCCESS 0
/** Pointer is NULL */
#define E_NULL_PTR -1
/** No such device */
#define E_NO_DEVICE -2
/** Parameter not acceptable */
#define E_BAD_PARAM -3
/** Value not valid or allowed */
#define E_INVALID -4
/** Module not initialized */
#define E_UNINITIALIZED -5
/** Busy now, try again later */
#define E_BUSY -6
/** Operation not allowed in current state */
#define E_BAD_STATE -7
/** Generic error */
#define E_UNKNOWN -8
/** General communications error */
#define E_COMM_ERR -9
/** Operation timed out */
#define E_TIME_OUT -10
/** Expected response did not occur */
#define E_NO_RESPONSE -11
/** Operations resulted in unexpected overflow */
#define E_OVERFLOW -12
/** Operations resulted in unexpected underflow */
#define E_UNDERFLOW -13
/** Data or resource not available at this time */
#define E_NONE_AVAIL -14
/** Event was shutdown */
#define E_SHUTDOWN -15
/** Event was aborted */
#define E_ABORT -16
/** The requested operation is not supported */
#define E_NOT_SUPPORTED -17
/**@} end of MXC_Error_Codes group */
#endif /* _MXC_ERRORS_H_ */
@@ -0,0 +1,94 @@
/**
* @file
* @brief Exclusive access lock utility functions.
*/
/* ****************************************************************************
* Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Maxim Integrated
* Products, Inc. shall not be used except as stated in the Maxim Integrated
* Products, Inc. Branding Policy.
*
* The mere transfer of this software does not imply any licenses
* of trade secrets, proprietary technology, copyrights, patents,
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*
* $Date: 2018-08-09 18:45:02 -0500 (Thu, 09 Aug 2018) $
* $Revision: 36818 $
*
*************************************************************************** */
/* Define to prevent redundant inclusion */
#ifndef _MXC_LOCK_H_
#define _MXC_LOCK_H_
/* **** Includes **** */
#include "mxc_config.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @ingroup syscfg
* @defgroup mxc_lock_utilities Exclusive Access Locks
* @brief Lock functions to obtain and release a variable for exclusive
* access. These functions are marked interrupt safe if they are
* interrupt safe.
* @{
*/
/* **** Definitions **** */
/* **** Globals **** */
/* **** Function Prototypes **** */
/**
* @brief Attempts to acquire the lock.
* @details This in an interrupt safe function that can be used as a mutex.
* The lock variable must remain in scope until the lock is
* released. Will not block if another thread has already acquired
* the lock.
* @param lock Pointer to variable that is used for the lock.
* @param value Value to be place in the lock. Can not be 0.
*
* @return #E_NO_ERROR if everything successful, #E_BUSY if lock is taken.
*/
int mxc_get_lock(uint32_t *lock, uint32_t value);
/**
* @brief Free the given lock.
* @param[in,out] lock Pointer to the variable used for the lock. When the lock
* is free, the value pointed to by @p lock is set to zero.
*/
void mxc_free_lock(uint32_t *lock);
/**@} end of group mxc_lock_utilities */
#ifdef __cplusplus
}
#endif
#endif /* _MXC_LOCK_H_ */
@@ -0,0 +1,91 @@
/**
* @file mxc_pins.h
* @brief This file contains constant pin configurations for the peripherals.
*/
/* *****************************************************************************
* Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Maxim Integrated
* Products, Inc. shall not be used except as stated in the Maxim Integrated
* Products, Inc. Branding Policy.
*
* The mere transfer of this software does not imply any licenses
* of trade secrets, proprietary technology, copyrights, patents,
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*
* $Date: 2018-08-09 18:45:02 -0500 (Thu, 09 Aug 2018) $
* $Revision: 36818 $
*
**************************************************************************** */
/* Define to prevent redundant inclusion */
#ifndef _MXC_PINS_H_
#define _MXC_PINS_H_
/* **** Includes **** */
#include "gpio.h"
#ifdef __cplusplus
extern "C" {
#endif
/* **** Global Variables **** */
// Predefined GPIO Configurations
/***** @brief TIMER pins *****/
extern const gpio_cfg_t gpio_cfg_tmr0;
/***** @brief UART pins *****/
extern const gpio_cfg_t gpio_cfg_uart0rtscts;
extern const gpio_cfg_t gpio_cfg_uart0a;
extern const gpio_cfg_t gpio_cfg_uart1rtscts;
extern const gpio_cfg_t gpio_cfg_uart1a;
extern const gpio_cfg_t gpio_cfg_uart1b;
extern const gpio_cfg_t gpio_cfg_uart1c;
extern const gpio_cfg_t gpio_cfg_uart2;
/***** @brief I2C pins *****/
extern const gpio_cfg_t gpio_cfg_i2c0;
extern const gpio_cfg_t gpio_cfg_i2c1;
/***** @brief SPI/I2S pins *****/
extern const gpio_cfg_t gpio_cfg_spi17y; // SPI0A
extern const gpio_cfg_t gpio_cfg_spimss1a; // SPI1A
extern const gpio_cfg_t gpio_cfg_spimss1b; // SPI1B
extern const gpio_cfg_t gpio_cfg_i2s1a; // same port as SPI1A
extern const gpio_cfg_t gpio_cfg_i2s1b; // same port as SPI1B
/***** @brief SWD pins *****/
extern const gpio_cfg_t gpio_cfg_swd;
/***** @brief RTC pins *****/
extern const gpio_cfg_t gpio_cfg_rtc;
#ifdef __cplusplus
}
#endif
#endif /* _MXC_PINS_H_ */
@@ -0,0 +1,450 @@
/**
* @file
* @brief System level header file.
*/
/*******************************************************************************
* Copyright (C) 2015 Maxim Integrated Products, Inc., All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Maxim Integrated
* Products, Inc. shall not be used except as stated in the Maxim Integrated
* Products, Inc. Branding Policy.
*
* The mere transfer of this software does not imply any licenses
* of trade secrets, proprietary technology, copyrights, patents,
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*
* $Date: 2019-04-15 09:35:40 -0500 (Mon, 15 Apr 2019) $
* $Revision: 42499 $
*
******************************************************************************/
#ifndef _MXC_SYS_H_
#define _MXC_SYS_H_
#include "mxc_config.h"
#include "uart_regs.h"
#include "i2c_regs.h"
#include "gcr_regs.h"
#include "tmr_regs.h"
#include "icc_regs.h"
#include "spi17y_regs.h"
#include "spimss_regs.h"
#include "gpio.h"
#include "flc_regs.h"
#include "dma.h"
#include "wdt_regs.h"
#ifdef __cplusplus
extern "C" {
#endif
#if defined ( __CC_ARM ) /* Suppressing the warning: "enum value is out of range of int" for Keil */
#pragma push
#pragma diag_suppress 66
#endif /* __CC_ARM */
/** @brief System reset0 enumeration. Used in SYS_PeriphReset0 function */
typedef enum {
SYS_RESET0_DMA = MXC_F_GCR_RSTR0_DMA, /**< Reset DMA */
SYS_RESET0_WDT = MXC_F_GCR_RSTR0_WDT, /**< Reset WDT */
SYS_RESET0_GPIO0 = MXC_F_GCR_RSTR0_GPIO0, /**< Reset GPIO0 */
SYS_RESET0_TIMER0 = MXC_F_GCR_RSTR0_TIMER0, /**< Reset TIMER0 */
SYS_RESET0_TIMER1 = MXC_F_GCR_RSTR0_TIMER1, /**< Reset TIMER1 */
SYS_RESET0_TIMER2 = MXC_F_GCR_RSTR0_TIMER2, /**< Reset TIMER2 */
SYS_RESET0_UART0 = MXC_F_GCR_RSTR0_UART0, /**< Reset UART0 */
SYS_RESET0_UART1 = MXC_F_GCR_RSTR0_UART1, /**< Reset UART1 */
SYS_RESET0_SPI0 = MXC_F_GCR_RSTR0_SPI0, /**< Reset SPI0 */
SYS_RESET0_SPI1 = MXC_F_GCR_RSTR0_SPI1, /**< Reset SPI1 */
SYS_RESET0_I2C0 = MXC_F_GCR_RSTR0_I2C0, /**< Reset I2C0 */
SYS_RESET0_RTC = MXC_F_GCR_RSTR0_RTC, /**< Reset RTC */
SYS_RESET0_SRST = MXC_F_GCR_RSTR0_SRST, /**< Soft reset */
SYS_RESET0_PRST = MXC_F_GCR_RSTR0_PRST, /**< Peripheral reset */
SYS_RESET0_SYSTEM = MXC_F_GCR_RSTR0_SYSTEM, /**< System reset */
} sys_reset0_t;
/** @brief System reset1 enumeration. Used in SYS_PeriphReset1 function */
typedef enum {
SYS_RESET1_I2C1 = MXC_F_GCR_RSTR1_I2C1, /**< Reset I2C1 */
} sys_reset1_t;
/** @brief System clock disable enumeration. Used in SYS_ClockDisable and SYS_ClockEnable functions */
typedef enum {
SYS_PERIPH_CLOCK_GPIO0 = MXC_F_GCR_PERCKCN0_GPIO0D, /**< Disable MXC_F_GCR_PERCKCN0_GPIO0D clock */
SYS_PERIPH_CLOCK_DMA = MXC_F_GCR_PERCKCN0_DMAD, /**< Disable MXC_F_GCR_PERCKCN0_DMAD clock */
SYS_PERIPH_CLOCK_SPI17Y = MXC_F_GCR_PERCKCN0_SPI0D, /**< Disable MXC_F_GCR_PERCKCN0_SPI0D clock */
SYS_PERIPH_CLOCK_SPIMSS = MXC_F_GCR_PERCKCN0_SPI1D, /**< Disable MXC_F_GCR_PERCKCN0_SPI1D clock */
SYS_PERIPH_CLOCK_UART0 = MXC_F_GCR_PERCKCN0_UART0D, /**< Disable MXC_F_GCR_PERCKCN0_UART0D clock */
SYS_PERIPH_CLOCK_UART1 = MXC_F_GCR_PERCKCN0_UART1D, /**< Disable MXC_F_GCR_PERCKCN0_UART1D clock */
SYS_PERIPH_CLOCK_I2C0 = MXC_F_GCR_PERCKCN0_I2C0D, /**< Disable MXC_F_GCR_PERCKCN0_I2C0D clock */
SYS_PERIPH_CLOCK_T0 = MXC_F_GCR_PERCKCN0_T0D, /**< Disable MXC_F_GCR_PERCKCN0_T0D clock */
SYS_PERIPH_CLOCK_T1 = MXC_F_GCR_PERCKCN0_T1D, /**< Disable MXC_F_GCR_PERCKCN0_T1D clock */
SYS_PERIPH_CLOCK_T2 = MXC_F_GCR_PERCKCN0_T2D, /**< Disable MXC_F_GCR_PERCKCN0_T2D clock */
SYS_PERIPH_CLOCK_I2C1 = MXC_F_GCR_PERCKCN0_I2C1D, /**< Disable MXC_F_GCR_PERCKCN0_I2C1D clock */
} sys_periph_clock_t;
/** @brief Clock source */
typedef enum {
SYS_CLOCK_NANORING = MXC_V_GCR_CLKCN_CLKSEL_NANORING, /**< 8KHz nanoring on MAX32660 */
SYS_CLOCK_HFXIN = MXC_V_GCR_CLKCN_CLKSEL_HFXIN, /**< 32KHz on MAX32660 */
SYS_CLOCK_HFXIN_DIGITAL = 0x9, /**< External Clock Input*/
SYS_CLOCK_HIRC = MXC_V_GCR_CLKCN_CLKSEL_HIRC, /**< High Frequency Internal Oscillator */
} sys_system_clock_t;
typedef void* sys_cfg_t;
typedef sys_cfg_t sys_cfg_i2c_t;
typedef sys_cfg_t sys_cfg_flc_t;
typedef sys_cfg_t sys_cfg_wdt_t;
/** @brief Map control */
typedef enum {
MAP_A,
MAP_B,
MAP_C,
} sys_map_t;
/** @brief UART Flow control */
typedef enum {
UART_FLOW_DISABLE,
UART_FLOW_ENABLE,
} sys_uart_flow_t;
/** @brief UART system configuration object */
typedef struct {
sys_map_t map;
sys_uart_flow_t flow_flag;
} sys_cfg_uart_t;
/** @brief SPI17Y system configuration object */
typedef struct {
sys_map_t map;
} sys_cfg_spi17y_t;
/** @brief SPIMSS system configuration object */
typedef struct {
sys_map_t map;
} sys_cfg_spimss_t;
/** @brief I2S system configuration object */
typedef struct {
sys_map_t map;
dma_reqsel_t dma_reqsel_tx;
dma_reqsel_t dma_reqsel_rx;
} sys_cfg_i2s_t;
/** @brief TIMER system configuration object */
typedef struct {
int out_en;
} sys_cfg_tmr_t;
/** @brief Real Time Clock system configuration object */
typedef struct {
mxc_tmr_regs_t* tmr;
} sys_cfg_rtc_t;
/** @brief Pulse Train System Configuration Object */
typedef gpio_cfg_t sys_cfg_pt_t;
#if defined ( __CC_ARM ) /* Restore the warning: "enum is out of int range" for Keil */
#pragma pop
#endif /* __CC_ARM */
/***** Function Prototypes *****/
/**
* @brief Selects the system clock and enables it once ready
* @param clock Enumeration for desired clock.
* @param tmr Optional tmr pointer for timeout. NULL if undesired.
*
* @returns #E_NO_ERROR is clock is succesfully selected
*/
int SYS_Clock_Select(sys_system_clock_t clock, mxc_tmr_regs_t* tmr);
/**
* @brief Enables the selected peripheral clock.
* @param clock Enumeration for desired clock.
*/
void SYS_ClockEnable(sys_periph_clock_t clock);
/**
* @brief Disables the selected peripheral clock.
* @param clock Enumeration for desired clock.
*/
void SYS_ClockDisable(sys_periph_clock_t clock);
/**
* @brief Enables the external 32k oscillator.
* @param sys_cfg system configuration object
*
* @returns #E_NO_ERROR is successful, appropriate error otherwise
*/
int SYS_ClockEnable_X32K(sys_cfg_rtc_t *sys_cfg);
/**
* @brief Disables the external 32k oscillator.
*
* @returns #E_NO_ERROR is successful, appropriate error otherwise
*/
int SYS_ClockDisable_X32K(void);
/**
* @brief System level initialization for UART module.
* @param uart Pointer to UART module registers
* @param sys_cfg System configuration object
*
* @returns #E_NO_ERROR if successful, appropriate error otherwise
*/
int SYS_UART_Init(mxc_uart_regs_t *uart, const sys_cfg_uart_t* sys_cfg);
/**
* @brief System level shutdown for UART module
* @param uart Pointer to UART module registers
*
* @return #E_NO_ERROR if successful, appropriate error otherwise
*/
int SYS_UART_Shutdown(mxc_uart_regs_t *uart);
/**
* @brief System level initialization for I2C module.
* @param i2c Pointer to I2C module registers
* @param sys_cfg System configuration object
*
* @returns #E_NO_ERROR if successful, appropriate error otherwise
*/
int SYS_I2C_Init(mxc_i2c_regs_t *i2c, const sys_cfg_i2c_t* sys_cfg);
/**
* @brief System level Shutdown for I2C module.
* @param i2c Pointer to I2C module registers
*
* @returns #E_NO_ERROR if successful, appropriate error otherwise
*/
int SYS_I2C_Shutdown(mxc_i2c_regs_t *i2c);
/**
* @brief Init DMA system settings
*
* @returns #E_NO_ERROR if successful, appropriate error otherwise
*/
int SYS_DMA_Init(void);
/**
* @brief Shutdown DMA system specific settings
*
* @returns #E_NO_ERROR if successful, appropriate error otherwise
*/
int SYS_DMA_Shutdown(void);
/**
* @brief Get the frequency of the I2C module source clock
* @param spim Unused, pointer to I2C module registers
*
* @returns frequency in Hz
*/
unsigned SYS_I2C_GetFreq(mxc_i2c_regs_t *i2c);
/**
* @brief Get the frequency of the Timer module source clock.
* @params tmr Unused, pointer to timer module registers
*
* @returns frequency in Hz
*/
unsigned SYS_TMR_GetFreq(mxc_tmr_regs_t *tmr);
/**
* @brief Reset the peripherals and/or CPU in the rstr0 register.
* @param Enumeration for what to reset. Can reset multiple items at once.
*/
void SYS_Reset0(sys_reset0_t reset);
/**
* @brief Reset the peripherals and/or CPU in the rstr1 register.
* @param Enumeration for what to reset. Can reset multiple items at once.
*/
void SYS_Reset1(sys_reset1_t reset);
/**
* @brief Clear Cache and Line buffer.
*/
void SYS_Flash_Operation(void);
/**
* @brief Init TMR system settings
* @param tmr Pointer to timer module registers
* @param sys_cfg System configuration object
*
* @returns #E_NO_ERROR if successful, appropriate error otherwise
*/
int SYS_TMR_Init(mxc_tmr_regs_t *tmr, const sys_cfg_tmr_t* sys_cfg);
/**
* @brief Init flash system settings
* @param sys_cfg System configuration object
*
* @returns #E_NO_ERROR if successful, appropriate error otherwise
*/
int SYS_FLC_Init(const sys_cfg_flc_t* sys_cfg);
/**
* @brief Shutdown flash system specific settings
*
* @returns #E_NO_ERROR if successful, appropriate error otherwise
*/
int SYS_FLC_Shutdown(void);
/**
* @brief System level initialization for SPI17Y module.
* @param spi pointer to spi module registers
* @param sys_cfg System configuration object
*
* @returns E_NO_ERROR if successful, appropriate error otherwise
*/
int SYS_SPI17Y_Init( mxc_spi17y_regs_t *spi, const sys_cfg_spi17y_t* sys_cfg);
/**
* @brief System level shutdown for SPI17Y module
* @param pointer to spi module registers
*
* @returns E_NO_ERROR if successful, appropriate error otherwise
*/
int SYS_SPI17Y_Shutdown(mxc_spi17y_regs_t *spi);
/**
* @brief System level initialization for SPIMSS module.
* @param spi pointer to spi module registers
* @param sys_cfg System configuration object
*
* @returns E_NO_ERROR if successful, appropriate error otherwise
*/
int SYS_SPIMSS_Init(mxc_spimss_regs_t *spi, const sys_cfg_spimss_t* sys_cfg);
/**
* @brief System level shutdown for SPIMSS module
* @param pointer to spi module registers
*
* @returns E_NO_ERROR if everything is successful
*/
int SYS_SPIMSS_Shutdown(mxc_spimss_regs_t *spi);
/**
* @brief Shutdown Timer system specific settings
* @param tmr pointer to timer module registers
*
* @returns #E_NO_ERROR if successful, appropriate error otherwise
*/
int SYS_TMR_Shutdown(mxc_tmr_regs_t *tmr);
/**
* @brief System level initialization for I2S Module
* @param sys_cfg System configuration object
*
* @returns #E_NO_ERROR if successful, appropriate error otherwise
*/
int SYS_I2S_Init(const sys_cfg_i2s_t* sys_cfg);
/**
* @brief System level shutdown of I2S module
*
* @returns #E_NO_ERROR if everything is successful
*/
int SYS_I2S_Shutdown(void);
/**
* @brief Get the frequency of the I2S module source clock
* @param spimss Pointer to I2S module registers
*
* @returns frequency in Hz
*/
int SYS_I2S_GetFreq(mxc_spimss_regs_t *spimss);
/**
* @brief Init system settings for RTC square wave output.
* @param sys_cfg System configuration object
*
* @returns #E_NO_ERROR if successful, appropriate error otherwise
*/
int SYS_RTC_SqwavInit(const sys_cfg_rtc_t* sys_cfg);
/**
* @brief System Tick Configuration Helper
*
* The function enables selection of the external clock source for
* the System Tick Timer. It initializes the System Timer and its
* interrupt, and starts the System Tick Timer. Counter is in free
* running mode to generate periodic interrupts.
*
* @param ticks Number of ticks between two interrupts.
* @param clk_src Selects between default SystemClock or External Clock.
* - 0 Use external clock source
* @param tmr Optional tmr pointer for timeout. NULL if undesired.
* - 1 SystemClock
*
* @return #E_NO_ERROR Function succeeded, of #E_INVALID if an invalid value is requested
*/
int SYS_SysTick_Config(uint32_t ticks, int clk_src, mxc_tmr_regs_t* tmr);
/**
* @brief Disable System Tick timer
*/
void SYS_SysTick_Disable(void);
/**
* @brief Delay a requested number of SysTick Timer Ticks.
* @param ticks Number of System Ticks to delay.
* @note This delay function is based on the clock used for the SysTick
* timer if the SysTick timer is enabled. If the SysTick timer is
* not enabled, the current SysTick registers are saved and the
* timer will use the SystemClock as the source for the delay. The
* delay is measured in clock ticks and is not based on the SysTick
* interval.
*
* @return #E_NO_ERROR if everything is successful
*/
int SYS_SysTick_Delay(uint32_t ticks);
/**
* @brief Get the frequency of the SysTick Timer
*
* @return frequency in Hz
*/
uint32_t SYS_SysTick_GetFreq(void);
/**
* @brief Delay a requested number of microseconds.
* @param us Number of microseconds to delay.
* @note Calls SYS_SysTick_Delay().
*/
void SYS_SysTick_DelayUs(uint32_t us);
/**
* @brief Init WDT system settings
* @param wdt watchdog registers
* @param sys_cfg System configuration object
*/
int SYS_WDT_Init(mxc_wdt_regs_t* wdt, const sys_cfg_wdt_t* sys_cfg);
#ifdef __cplusplus
}
#endif
#endif /* _MXC_SYS_H_*/
@@ -0,0 +1,89 @@
/**
* @file nvic_table.h
* @brief Interrupt vector table manipulation functions.
*/
/*******************************************************************************
* Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Maxim Integrated
* Products, Inc. shall not be used except as stated in the Maxim Integrated
* Products, Inc. Branding Policy.
*
* The mere transfer of this software does not imply any licenses
* of trade secrets, proprietary technology, copyrights, patents,
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*
* $Date: 2020-04-20 15:48:35 -0500 (Mon, 20 Apr 2020) $
* $Revision: 53144 $
*
******************************************************************************/
#ifndef _NVIC_TABLE_H
#define _NVIC_TABLE_H
#include "mxc_config.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @ingroup syscfg
* @defgroup nvic NVIC Table
* @brief functions handling the nvic table.
* @{
*/
/**
* @brief Set an IRQ hander callback function. If the IRQ table is in
* flash, this will copy it to RAM and set NVIC to RAM based table.
*
* @param irqn ARM external IRQ number
* @param irq_callback Function to be called at IRQ context
*
*/
void NVIC_SetVector(IRQn_Type irqn, void (*irq_callback)(void));
/**
* @brief Copy NVIC vector table to RAM and set NVIC to RAM based table.
*
*/
void NVIC_SetRAM(void);
/**
* @brief Get Interrupt Vector
* @details Reads an interrupt vector from interrupt vector table. The
* interrupt number can be positive to specify a device specific
* interrupt, or negative to specify a processor exception.
* @param[in] IRQn Interrupt number.
* @return Address of interrupt handler function
*/
uint32_t NVIC_GetVector(IRQn_Type IRQn);
/**@} end of group nvic */
#ifdef __cplusplus
}
#endif
#endif /* _NVIC_TABLE_H */
@@ -0,0 +1,242 @@
/**
* @file
* @brief Real Time Clock (RTC) functions and prototypes.
*/
/* ****************************************************************************
* Copyright (C) 2017 Maxim Integrated Products, Inc., All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Maxim Integrated
* Products, Inc. shall not be used except as stated in the Maxim Integrated
* Products, Inc. Branding Policy.
*
* The mere transfer of this software does not imply any licenses
* of trade secrets, proprietary technology, copyrights, patents,
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*
*
* $Date: 2019-10-07 11:05:30 -0500 (Mon, 07 Oct 2019) $
* $Revision: 47429 $
*************************************************************************** */
/* Define to prevent redundant inclusion */
#ifndef _RTC_H_
#define _RTC_H_
/* **** Includes **** */
#include <stdint.h>
#include "mxc_config.h"
#include "rtc_regs.h"
#include "mxc_sys.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @defgroup rtc RTC
* @ingroup periphlibs
* @{
*/
/* **** Definitions **** */
typedef enum {
SQUARE_WAVE_DISABLED, /**< Sq. wave output disabled */
SQUARE_WAVE_ENABLED, /**< Sq. wave output enabled */
} rtc_sqwave_en_t;
typedef enum {
F_1HZ = MXC_S_RTC_CTRL_FT_FREQ1HZ, /**< 1Hz (Compensated) */
F_512HZ = MXC_S_RTC_CTRL_FT_FREQ512HZ, /**< 512Hz (Compensated) */
F_4KHZ = MXC_S_RTC_CTRL_FT_FREQ4KHZ, /**< 4Khz */
F_32KHZ = 32, /**< 32Khz */
} rtc_freq_sel_t;
typedef enum {
NOISE_IMMUNE_MODE = MXC_S_RTC_CTRL_X32KMD_NOISEIMMUNEMODE,
QUIET_MODE = MXC_S_RTC_CTRL_X32KMD_QUIETMODE,
QUIET_STOP_WARMUP_MODE = MXC_S_RTC_CTRL_X32KMD_QUIETINSTOPWITHWARMUP,
QUIET_STOP_NOWARMUP_MODE = MXC_S_RTC_CTRL_X32KMD_QUIETINSTOPNOWARMUP,
} rtc_osc_mode_t;
/**
*@brief Enables Time-of-Day's Alarm Interrupt
*@param rtc pointer to the rtc register structure
*@return #E_SUCCESS=pass
*@return #E_BAD_STATE=fail
*@return #E_BUSY=Fail
*/
int RTC_EnableTimeofdayInterrupt(mxc_rtc_regs_t *rtc);
/**
*@brief Disable Time-of-Day's Alarm Interrupt
*@param rtc pointer to the rtc register structure
*@return #E_SUCCESS=pass
*@return #E_BAD_STATE=fail
*@return #E_BUSY=Fail
*/
int RTC_DisableTimeofdayInterrupt(mxc_rtc_regs_t *rtc);
/**
*@brief Enables Sub-Second's Alarm Interrupt
*@param rtc pointer to the rtc register structure
*@return #E_SUCCESS=pass
*@return #E_BAD_STATE=fail
*@return #E_BUSY=Fail
*/
int RTC_EnableSubsecondInterrupt(mxc_rtc_regs_t *rtc);
/**
*@brief Disable Sub-Second's Alarm Interrupt
*@param rtc pointer to the rtc register structure
*@return #E_SUCCESS=pass
*@return #E_BAD_STATE=fail
*@return #E_BUSY=Fail
*/
int RTC_DisableSubsecondInterrupt(mxc_rtc_regs_t *rtc);
/**
*@brief Set Time-of-Day alarm value and enable Interrupt
*@param rtc pointer to the rtc register structure
*@param ras 20-bit value 0-0xFFFFF
*@return #E_SUCCESS=pass
*@return #E_BAD_STATE=fail
*@return #E_BUSY=Fail
*/
int RTC_SetTimeofdayAlarm(mxc_rtc_regs_t *rtc, uint32_t ras);
/**
*@brief Set Sub-Second alarm value and enable interrupt,
*@brief this is to be called after the init_rtc() function
*@param rtc pointer to the rtc register structure
*@param rssa 32-bit value 0-0xFFFFFFFF
*@return #E_SUCCESS=pass
*@return #E_BAD_STATE=fail
*@return #E_BUSY=Fail
*/
int RTC_SetSubsecondAlarm(mxc_rtc_regs_t *rtc, uint32_t rssa);
/**
*@brief Enable/Start the Real Time Clock
*@param rtc pointer to the rtc register structure
*@return #E_SUCCESS=Pass
*@return #E_BUSY=Fail
*/
int RTC_EnableRTCE(mxc_rtc_regs_t *rtc);
/**
*@brief Disable/Stop the Real Time Clock
*@param rtc pointer to the rtc register structure
*@return #E_SUCCESS=Pass
*@return #E_BUSY=Fail
*/
int RTC_DisableRTCE(mxc_rtc_regs_t *rtc);
/**
* @brief Initialize the sec and ssec registers and enable RTC
* @param rtc pointer to the rtc register structure
* @param sec set the RTC Sec counter (32-bit)
* @param ssec set the RTC Sub-second counter (8-bit)
* @param sys_cfg The system configuration
* @return #E_SUCCESS=pass
* @return #E_BAD_STATE=fail
*/
int RTC_Init(mxc_rtc_regs_t *rtc, uint32_t sec, uint8_t ssec, sys_cfg_rtc_t *sys_cfg);
/**
* @brief Allow generation of Square Wave on the SQW pin
* @param rtc pointer to the rtc register structure
* @param sqe Enable/Disable square wave output
* @param ft Frequency output selection
* @param x32kmd 32KHz Oscillator mode
* @param sys_cfg The system configuration
* @return #E_SUCCESS=Pass
* @return #E_BUSY=Fail
*/
int RTC_SquareWave(mxc_rtc_regs_t *rtc, rtc_sqwave_en_t sqe, rtc_freq_sel_t ft,
rtc_osc_mode_t x32kmd, const sys_cfg_rtc_t* sys_cfg);
/**
*@brief Set Trim register value
*@param rtc pointer to the rtc register structure
*@param trm set the RTC Trim (8-bit, +/- 127)
*@return #E_SUCCESS=Pass
*@return #E_BUSY=Fail
*/
int RTC_Trim(mxc_rtc_regs_t *rtc, int8_t trm);
/**
*@brief Check if BUSY bit is 0.
*@return #E_SUCCESS=Pass
*@return #E_BUSY=Fail
*/
int RTC_CheckBusy(void);
/**
*@brief Gets Interrupt flags.
*@return Interrupts flags that have not been cleared
*/
int RTC_GetFlags(void);
/**
*@brief Clear Interrupt flag.
*@param flags the flags that need to be cleared
*/
int RTC_ClearFlags(int flags);
/**
*@brief Get SubSecond
*@return Returns subsecond value
*/
int RTC_GetSubSecond(void);
/**
* @brief Get Second
* @return returns Second value
*/
int RTC_GetSecond(void);
/**
* @brief Read seconds, then subseconds, and finally seconds. If RTC ready flag ever gets cleared during this sequence,
the RTC is in the middle of updating the counts and the user should come back later and try again. If the first
read of the seconds register doesn't match the next read, then a subsecond overflow condition has happened and
another attempt to read the counts should be made.
* @param sec variable that will be changed to hold second value
* @param subsec variable that will be changed to hold Subsecond value
* @return #E_NO_ERROR=Pass
* @return #E_BUSY=Fail
*/
int RTC_GetTime(uint32_t* sec, uint32_t* subsec);
/**
*@brief Check if RTC is already running
*/
int RTC_IsEnabled(void);
#ifdef __cplusplus
}
#endif
/**@} end of group rtc */
#endif /* _RTC_H_ */
@@ -0,0 +1,259 @@
/**
* @file spi.h
* @brief Serial Peripheral Interface (SPIMSS) function prototypes and data types.
*/
/* ****************************************************************************
* Copyright (C) 2017 Maxim Integrated Products, Inc., All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Maxim Integrated
* Products, Inc. shall not be used except as stated in the Maxim Integrated
* Products, Inc. Branding Policy.
*
* The mere transfer of this software does not imply any licenses
* of trade secrets, proprietary technology, copyrights, patents,
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*
* $Date: 2018-11-07 14:48:15 -0600 (Wed, 07 Nov 2018) $
* $Revision: 39010 $
*
*************************************************************************** */
/* Define to prevent redundant inclusion */
#ifndef _SPI_H_
#define _SPI_H_
/* **** Includes **** */
#include "spi17y_regs.h"
#include "spimss_regs.h"
#include "spimss.h"
#include "spi17y.h"
#include "mxc_sys.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @defgroup spi SPI
* @ingroup periphlibs
* @{
*/
/* **** Definitions **** */
/**
* @brief Enums assigning numbers to SPI
*/
typedef enum {
SPI0A, // SPI17Y (0A)
SPI1A, // SPIMSS (1A)
SPI1B, // SPIMSS (1B)
}spi_type;
/**
* @brief Renaming the SPI address names
*/
#define MXC_SPI0 MXC_SPI17Y // SPI0A
#define MXC_SPI1 MXC_SPIMSS // SPI1A & SPI1B
/**
* @brief Renaming Interrupt SPI Interrupt sources
*/
#define SPI0_IRQn SPI17Y_IRQn // SPI0A
#define SPI1_IRQn SPIMSS_IRQn // SPI1A & SPI1B
/**
* @brief Renaming SPI Width
*/
#define SPI0_WIDTH_1 SPI17Y_WIDTH_1 /**< 1 Data Line. */
#define SPI0_WIDTH_2 SPI17Y_WIDTH_2 /**< 2 Data Lines (x2). */
#define SPI0_WIDTH_4 SPI17Y_WIDTH_4 /**< 4 Data Lines (x4). */
/**
* @brief Renaming SPI Polarity
*/
#define SPI_POL_LOW SPI17Y_POL_LOW /**< Slave Select polarity Low. */
#define SPI_POL_HIGH SPI17Y_POL_HIGH /**< Slave Select polarity High. */
/**
* @brief Structure type representing a SPI Master Transaction request.
*/
typedef struct spi_req spi_req_t;
/**
* @brief Callback function type used in asynchronous SPI Master communication requests.
* @details The function declaration for the SPI Master callback is:
* @code
* void callback(spi_req_t * req, int error_code);
* @endcode
* | | |
* | -----: | :----------------------------------------- |
* | \p req | Pointer to a #spi_req object representing the active SPI Master active transaction. |
* | \p error_code | An error code if the active transaction had a failure or #E_NO_ERROR if successful. |
* @note Callback will execute in interrupt context
* @addtogroup spi_async
*/
typedef void (*spi_callback_fn)(void * req, int error_code);
/**
* @brief Structure definition for an SPI Master Transaction request.
* @note When using this structure for an asynchronous operation, the
* structure must remain allocated until the callback is completed.
* @addtogroup spi_async
*/
struct spi_req {
uint8_t ssel; /**< Slave select line to use. (Master only) */
uint8_t deass; /**< Non-zero to de-assert slave select after transaction. (Master only)*/
spi17y_sspol_t ssel_pol; /**< Slave select line polarity. */
const void *tx_data; /**< Pointer to a buffer to transmit data from. NULL if undesired. */
void *rx_data; /**< Pointer to a buffer to store data received. NULL if undesired.*/
spi17y_width_t width; /**< Number of data lines to use, see #spi17y_width_t. */
unsigned len; /**< Number of transfer units to send from the \p tx_data buffer. */
unsigned bits; /**< Number of bits in transfer unit (e.g. 8 for byte, 16 for short) */
unsigned rx_num; /**< Number of bytes actually read into the \p rx_data buffer. */
unsigned tx_num; /**< Number of bytes actually sent from the \p tx_data buffer */
spi_callback_fn callback; /**< Callback function if desired, NULL otherwise */
};
/* **** Function Prototypes **** */
/**
* @brief Initialize the spi.
* @param spi_name spi module to initialize.
* @param mode SPI mode for clock phase and polarity.
* @param freq Desired clock frequency.
*
* @return #E_NO_ERROR if successful, @ref
* MXC_Error_Codes "error" if unsuccessful.
*/
int SPI_Init(spi_type spi_name, unsigned mode, unsigned freq);
/**
* @brief Asynchronously read/write SPI Master data
*
* @param spi_name SPI instance being used
* @param req Pointer to spi request
*
* @return #E_NO_ERROR if successful, @ref
* MXC_Error_Codes "error" if unsuccessful.
*/
int SPI_MasterTransAsync(spi_type spi_name, spi_req_t *req);
/**
* @brief Execute a master transaction.
* @param spi_name SPI instance being used
* @param req Pointer to spi request
*
* @return #E_NO_ERROR if successful, @ref
* MXC_Error_Codes "error" if unsuccessful.
*/
int SPI_MasterTrans(spi_type spi_name, spi_req_t *req);
/**
* @brief Asynchronously read/write SPI Slave data
* @param spi_name SPI instance being used
* @param req Pointer to spi request
*
* @return #E_NO_ERROR if successful, @ref
* MXC_Error_Codes "error" if unsuccessful.
*/
int SPI_SlaveTransAsync(spi_type spi_name, spi_req_t *req);
/**
* @brief Execute a slave transaction.
* @param spi_name SPI instance being used
* @param req Pointer to spi request
*
* @return #E_NO_ERROR if successful, @ref
* MXC_Error_Codes "error" if unsuccessful.
*/
int SPI_SlaveTrans(spi_type spi_name, spi_req_t *req);
/**
* @brief Shutdown SPI module.
* @param spi_name SPI instance being used
*
* @return #E_NO_ERROR if successful, appropriate error otherwise
*/
int SPI_Shutdown(spi_type spi_name);
/**
* @brief Aborts an Asynchronous request
* @param spi_name SPI instance being used
* @param req Pointer to spi request
*
* @return #E_NO_ERROR if successful, @ref
* MXC_Error_Codes "error" if unsuccessful.
*/
int SPI_AbortAsync(spi_type spi_name, spi_req_t *req);
/**
* @brief Execute SPI transaction based on interrupt handler
* @param spi_name SPI instance being used
*
* @return #E_NO_ERROR if successful,
* @return #E_BAD_PARAM otherwise
*/
int SPI_Handler(spi_type spi_name);
/**
* @brief Enable SPI
* @param spi_name Pointer to spi module.
*
* @return #E_NO_ERROR if successful, appropriate error otherwise
*/
int SPI_Enable(spi_type spi_name);
/**
* @brief Disable SPI
* @param spi_name Pointer to spi module.
*
* @return #E_NO_ERROR if successful, appropriate error otherwise
*/
int SPI_Disable(spi_type spi_name);
/**
* @brief Clear the TX and RX FIFO
* @param spi_name Pointer to spi module.
*
* @return #E_NO_ERROR if successful, appropriate error otherwise
*/
int SPI_Clear_fifo(spi_type spi_name);
//-------------------------------------------------------------------------------------------
/**@} end of group spi */
#ifdef __cplusplus
}
#endif
#endif /* _SPI_H_ */
@@ -0,0 +1,242 @@
/**
* @file spi17y.h
* @brief Serial Peripheral Interface (SPI17Y) function prototypes and data types.
*/
/* ****************************************************************************
* Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Maxim Integrated
* Products, Inc. shall not be used except as stated in the Maxim Integrated
* Products, Inc. Branding Policy.
*
* The mere transfer of this software does not imply any licenses
* of trade secrets, proprietary technology, copyrights, patents,
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*
* $Date: 2018-12-18 15:37:22 -0600 (Tue, 18 Dec 2018) $
* $Revision: 40072 $
*
*************************************************************************** */
/* Define to prevent redundant inclusion */
#ifndef _SPI17Y_H_
#define _SPI17Y_H_
/* **** Includes **** */
#include "mxc_config.h"
#include "spi17y_regs.h"
#include "mxc_sys.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @defgroup spi17y SPI17Y
* @ingroup spi
* @{
*/
/* **** Definitions **** */
/**
* Enumeration type for setting the number data lines to use for communication.
*/
typedef enum {
SPI17Y_WIDTH_1 = 0, /**< 1 Data Line. */
SPI17Y_WIDTH_2 = 1, /**< 2 Data Lines (x2). */
SPI17Y_WIDTH_4 = 2 /**< 4 Data Lines (x4). */
} spi17y_width_t;
/**
* Enumeration type for setting the polarity of ss lines.
*/
typedef enum {
SPI17Y_POL_LOW = 0, /**< Polarity Low. */
SPI17Y_POL_HIGH = 1 /**< Polarity High. */
} spi17y_sspol_t;
/**
* Structure type representing a SPI17Y Master Transaction request.
*/
typedef struct spi17y_req spi17y_req_t;
/**
* @brief Callback function type used in asynchronous SPI Master communication requests.
* @details The function declaration for the SPI Master callback is:
* @code
* void callback(spi17y_req_t * req, int error_code);
* @endcode
* | | |
* | -----: | :----------------------------------------- |
* | \p req | Pointer to a #spi_req object representing the active SPI Master active transaction. |
* | \p error_code | An error code if the active transaction had a failure or #E_NO_ERROR if successful. |
* @note Callback will execute in interrupt context
* @addtogroup spi_async
*/
typedef void (*spi17y_callback_fn)(spi17y_req_t * req, int error_code);
/**
* @brief Structure definition for an SPI Master Transaction request.
* @note When using this structure for an asynchronous operation, the
* structure must remain allocated until the callback is completed.
* @addtogroup spi_async
*/
struct spi17y_req {
uint8_t ssel; /**< Slave select line to use. (Master only, ignored in slave mode) */
uint8_t deass; /**< Non-zero to de-assert slave select after transaction. (Master only, ignored in slave mode)*/
spi17y_sspol_t ssel_pol; /**< Slave select line polarity. */
const void *tx_data; /**< Pointer to a buffer to transmit data from. NULL if undesired. */
void *rx_data; /**< Pointer to a buffer to store data received. NULL if undesired.*/
spi17y_width_t width; /**< Number of data lines to use, see #spi17y_width_t. */
unsigned len; /**< Number of transfer units to send from the \p tx_data buffer. */
unsigned bits; /**< Number of bits in transfer unit (e.g. 8 for byte, 16 for short) */
unsigned rx_num; /**< Number of bytes actually read into the \p rx_data buffer. */
unsigned tx_num; /**< Number of bytes actually sent from the \p tx_data buffer */
spi17y_callback_fn callback; /**< Callback function if desired, NULL otherwise */
};
/* **** Function Prototypes **** */
/**
* @brief Initialize the spi.
* @param spi Pointer to spi module to initialize.
* @param mode SPI mode for clock phase and polarity.
* @param freq Desired clock frequency.
* @param sys_cfg System configuration object
*
* @return #E_NO_ERROR if successful, @ref
* MXC_Error_Codes "error" if unsuccessful.
*/
int SPI17Y_Init(mxc_spi17y_regs_t *spi, unsigned int mode, unsigned int freq, const sys_cfg_spi17y_t* sys_cfg);
/**
* @brief Shutdown SPI module.
* @param spi Pointer to SPI regs.
*
* @return #E_NO_ERROR if successful, @ref
* MXC_Error_Codes "error" if unsuccessful.
*/
int SPI17Y_Shutdown(mxc_spi17y_regs_t *spi);
/**
* @brief Processing function for asynchronous SPI operations.
* This function must be called either from the SPI interrupt
* handler or periodically.
*
* @param spi Pointer to spi module.
*/
void SPI17Y_Handler(mxc_spi17y_regs_t *spi);
/**
* @brief Execute a master transaction.
* This function will block until the transaction is complete.
* @param spi Pointer to spi module.
* @param req Pointer to spi request
*
* @return #E_NO_ERROR if successful, @ref
* MXC_Error_Codes "error" if unsuccessful.
*/
int SPI17Y_MasterTrans(mxc_spi17y_regs_t *spi, spi17y_req_t *req);
/**
* @brief Execute a slave transaction.
* This function will block until the transaction is complete.
* @param spi Pointer to spi module.
* @param req Pointer to spi request
*
* @return #E_NO_ERROR if successful, @ref
* MXC_Error_Codes "error" if unsuccessful.
*/
int SPI17Y_SlaveTrans(mxc_spi17y_regs_t *spi, spi17y_req_t *req);
/**
* @brief Asynchronously read/write SPI Master data
*
* @param spi Pointer to spi module
* @param req Pointer to spi request
*
* @return #E_NO_ERROR if successful, @ref
* MXC_Error_Codes "error" if unsuccessful.
*/
int SPI17Y_MasterTransAsync(mxc_spi17y_regs_t *spi, spi17y_req_t *req);
/**
* @brief Asynchronously read/write SPI Slave data
*
* @param spi Pointer to spi module
* @param req Pointer to spi request
*
* @return #E_NO_ERROR if successful, @ref
* MXC_Error_Codes "error" if unsuccessful.
*/
int SPI17Y_SlaveTransAsync(mxc_spi17y_regs_t *spi, spi17y_req_t *req);
/**
* @brief Aborts an Asynchronous request
*
* @param req Pointer to spi request
* @return #E_NO_ERROR if successful, @ref
* MXC_Error_Codes "error" if unsuccessful.
*/
int SPI17Y_AbortAsync(spi17y_req_t *req);
/**
* @brief Enable SPI
* @param spi Pointer to spi module.
*
* @return #E_NO_ERROR if successful, @ref
* MXC_Error_Codes "error" if unsuccessful.
*/
void SPI17Y_Enable(mxc_spi17y_regs_t* spi);
/**
* @brief Disable SPI. Any pending asynchronous transactions will not
* complete and their callbacks will not be executed.
* @param spi Pointer to spi module.
*
* @return #E_NO_ERROR if successful, @ref
* MXC_Error_Codes "error" if unsuccessful.
*/
void SPI17Y_Disable(mxc_spi17y_regs_t* spi);
/**
* @brief Clear the TX and RX FIFO
* @param spi Pointer to spi module.
*
* @return #E_NO_ERROR if successful, @ref
* MXC_Error_Codes "error" if unsuccessful.
*/
void SPI17Y_Clear_fifo(mxc_spi17y_regs_t* spi);
/**@} end of group spi17y */
#ifdef __cplusplus
}
#endif
#endif /* _SPI17Y_H_ */
@@ -0,0 +1,197 @@
/**
* @file spimss.h
* @brief Serial Peripheral Interface (SPIMSS) function prototypes and data types.
*/
/* ****************************************************************************
* Copyright (C) 2017 Maxim Integrated Products, Inc., All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Maxim Integrated
* Products, Inc. shall not be used except as stated in the Maxim Integrated
* Products, Inc. Branding Policy.
*
* The mere transfer of this software does not imply any licenses
* of trade secrets, proprietary technology, copyrights, patents,
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*
* $Date: 2018-12-18 15:37:22 -0600 (Tue, 18 Dec 2018) $
* $Revision: 40072 $
*
*************************************************************************** */
/* Define to prevent redundant inclusion */
#ifndef _SPIMSS_H_
#define _SPIMSS_H_
/* **** Includes **** */
#include "mxc_config.h"
#include "mxc_sys.h"
#include "spimss_regs.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @defgroup spimss SPIMSS
* @ingroup spi
* @{
*/
/* **** Definitions **** */
/**
* @brief Enumeration type for setting the number data lines to use for communication.
*/
typedef enum { // ONLY FOR COMPATIBILITY FOR CONSOLIDATION WITH SPY17, NOT USED OR NEEDED
DUMMY_1, /**< NOT USED */
DUMMY_2, /**< NOT USED */
DUMMY_3, /**< NOT USED */
} spimss_width_t;
/**
* @brief Structure type representing a SPI Master Transaction request.
*/
typedef struct spimss_req spimss_req_t;
/**
* @brief Callback function type used in asynchronous SPI Master communication requests.
* @details The function declaration for the SPI Master callback is:
* @code
* void callback(spi_req_t * req, int error_code);
* @endcode
* | | |
* | -----: | :----------------------------------------- |
* | \p req | Pointer to a #spi_req object representing the active SPI Master active transaction. |
* | \p error_code | An error code if the active transaction had a failure or #E_NO_ERROR if successful. |
* @note Callback will execute in interrupt context
* @addtogroup spi_async
*/
typedef void (*spimss_callback_fn)(spimss_req_t * req, int error_code);
/**
* @brief Structure definition for an SPI Master Transaction request.
* @note When using this structure for an asynchronous operation, the
* structure must remain allocated until the callback is completed.
* @addtogroup spi_async
*/
struct spimss_req {
uint8_t ssel; /**< Not Used*/
uint8_t deass; /**< Not Used*/
const void *tx_data; /**< Pointer to a buffer to transmit data from. NULL if undesired. */
void *rx_data; /**< Pointer to a buffer to store data received. NULL if undesired.*/
spimss_width_t width; /**< Not Used */
unsigned len; /**< Number of transfer units to send from the \p tx_data buffer. */
unsigned bits; /**< Number of bits in transfer unit (e.g. 8 for byte, 16 for short) */
unsigned rx_num; /**< Number of bytes actually read into the \p rx_data buffer. */
unsigned tx_num; /**< Number of bytes actually sent from the \p tx_data buffer */
spimss_callback_fn callback; /**< Callback function if desired, NULL otherwise */
};
/* **** Function Prototypes **** */
/**
* @brief Initialize the spi.
* @param spi Pointer to spi module to initialize.
* @param mode SPI mode for clock phase and polarity.
* @param freq Desired clock frequency.
* @param sys_cfg System configuration object
*
* @return \c #E_NO_ERROR if successful, appropriate error otherwise
*/
int SPIMSS_Init(mxc_spimss_regs_t *spi, unsigned mode, unsigned freq, const sys_cfg_spimss_t* sys_cfg);
/**
* @brief Shutdown SPI module.
* @param spi Pointer to SPI regs.
*
* @return \c #E_NO_ERROR if successful, appropriate error otherwise
*/
int SPIMSS_Shutdown(mxc_spimss_regs_t *spi);
/**
* @brief Execute a master transaction.
* @param spi Pointer to spi module.
* @param req Pointer to spi request
*
* @return \c #E_NO_ERROR if successful, @ref
* MXC_Error_Codes "error" if unsuccessful.
*/
int SPIMSS_MasterTrans(mxc_spimss_regs_t *spi, spimss_req_t *req);
/**
* @brief Execute SPI transaction based on interrupt handler
* @param spi The spi
*
*/
void SPIMSS_Handler(mxc_spimss_regs_t *spi);
/**
* @brief Execute a slave transaction.
* @param spi Pointer to spi module.
* @param req Pointer to spi request
*
* @return \c #E_NO_ERROR if successful, @ref
* MXC_Error_Codes "error" if unsuccessful.
*/
int SPIMSS_SlaveTrans(mxc_spimss_regs_t *spi, spimss_req_t *req);
/**
* @brief Asynchronously read/write SPI Master data
*
* @param spi Pointer to spi module
* @param req Pointer to spi request
*
* @return \c #E_NO_ERROR if successful, @ref
* MXC_Error_Codes "error" if unsuccessful.
*/
int SPIMSS_MasterTransAsync(mxc_spimss_regs_t *spi, spimss_req_t *req);
/**
* @brief Asynchronously read/write SPI Slave data
*
* @param spi Pointer to spi module
* @param req Pointer to spi request
*
* @return \c #E_NO_ERROR if successful, @ref
* MXC_Error_Codes "error" if unsuccessful.
*/
int SPIMSS_SlaveTransAsync(mxc_spimss_regs_t *spi, spimss_req_t *req);
/**
* @brief Aborts an Asynchronous request
*
* @param req Pointer to spi request
* @return \c #E_NO_ERROR if successful, @ref
* MXC_Error_Codes "error" if unsuccessful.
*/
int SPIMSS_AbortAsync(spimss_req_t *req);
/**@} end of group spimss */
#ifdef __cplusplus
}
#endif
#endif /* _SPIMSS_H_ */
@@ -0,0 +1,265 @@
/**
* @file tmr.h
* @brief Timer (TMR) function prototypes and data types.
*/
/* ****************************************************************************
* Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Maxim Integrated
* Products, Inc. shall not be used except as stated in the Maxim Integrated
* Products, Inc. Branding Policy.
*
* The mere transfer of this software does not imply any licenses
* of trade secrets, proprietary technology, copyrights, patents,
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*
* $Date: 2019-09-11 14:32:22 -0500 (Wed, 11 Sep 2019) $
* $Revision: 46047 $
*
*************************************************************************** */
/* Define to prevent redundant inclusion */
#ifndef _TMR_H_
#define _TMR_H_
/* **** Includes **** */
#include "mxc_config.h"
#include "tmr_regs.h"
#include "mxc_sys.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @defgroup tmr Timer (TMR)
* @ingroup periphlibs
* @{
*/
/**
* @brief Timer prescaler values
*/
typedef enum {
TMR_PRES_1 = MXC_S_TMR_CN_PRES_DIV1, /// Divide input clock by 1
TMR_PRES_2 = MXC_S_TMR_CN_PRES_DIV2, /// Divide input clock by 2
TMR_PRES_4 = MXC_S_TMR_CN_PRES_DIV4, /// Divide input clock by 4
TMR_PRES_8 = MXC_S_TMR_CN_PRES_DIV8, /// Divide input clock by 8
TMR_PRES_16 = MXC_S_TMR_CN_PRES_DIV16, /// Divide input clock by 16
TMR_PRES_32 = MXC_S_TMR_CN_PRES_DIV32, /// Divide input clock by 32
TMR_PRES_64 = MXC_S_TMR_CN_PRES_DIV64, /// Divide input clock by 64
TMR_PRES_128 = MXC_S_TMR_CN_PRES_DIV128, /// Divide input clock by 128
TMR_PRES_256 = MXC_F_TMR_CN_PRES3 | MXC_S_TMR_CN_PRES_DIV1, /// Divide input clock by 256
TMR_PRES_512 = MXC_F_TMR_CN_PRES3 | MXC_S_TMR_CN_PRES_DIV2, /// Divide input clock by 512
TMR_PRES_1024 = MXC_F_TMR_CN_PRES3 | MXC_S_TMR_CN_PRES_DIV4, /// Divide input clock by 1024
TMR_PRES_2048 = MXC_F_TMR_CN_PRES3 | MXC_S_TMR_CN_PRES_DIV8, /// Divide input clock by 2048
TMR_PRES_4096 = MXC_F_TMR_CN_PRES3 | MXC_S_TMR_CN_PRES_DIV16 /// Divide input clock by 4096
} tmr_pres_t;
/**
* @brief Timer modes
*/
typedef enum {
TMR_MODE_ONESHOT = MXC_V_TMR_CN_TMODE_ONESHOT, /// Timer Mode ONESHOT
TMR_MODE_CONTINUOUS = MXC_V_TMR_CN_TMODE_CONTINUOUS, /// Timer Mode CONTINUOUS
TMR_MODE_COUNTER = MXC_V_TMR_CN_TMODE_COUNTER, /// Timer Mode COUNTER
TMR_MODE_PWM = MXC_V_TMR_CN_TMODE_PWM, /// Timer Mode PWM
TMR_MODE_CAPTURE = MXC_V_TMR_CN_TMODE_CAPTURE, /// Timer Mode CAPTURE
TMR_MODE_COMPARE = MXC_V_TMR_CN_TMODE_COMPARE, /// Timer Mode COMPARE
TMR_MODE_GATED = MXC_V_TMR_CN_TMODE_GATED, /// Timer Mode GATED
TMR_MODE_CAPTURE_COMPARE = MXC_V_TMR_CN_TMODE_CAPTURECOMPARE /// Timer Mode CAPTURECOMPARE
} tmr_mode_t;
/**
* @brief Timer units of time enumeration
*/
typedef enum {
TMR_UNIT_NANOSEC = 0, /**< Nanosecond Unit Indicator. */
TMR_UNIT_MICROSEC, /**< Microsecond Unit Indicator. */
TMR_UNIT_MILLISEC, /**< Millisecond Unit Indicator. */
TMR_UNIT_SEC, /**< Second Unit Indicator. */
} tmr_unit_t;
/**
* @brief Timer Configuration
*/
typedef struct {
tmr_mode_t mode; /// Desired timer mode
uint32_t cmp_cnt; /// Compare register value in timer ticks
unsigned pol; /// Polarity (0 or 1)
} tmr_cfg_t;
/**
* @brief Timer PWM Configuration
*/
typedef struct {
unsigned pol; /// PWM polarity (0 or 1)
uint32_t per_cnt; /// PWM period in timer ticks
uint32_t duty_cnt; /// PWM duty in timer ticks
} tmr_pwm_cfg_t;
/* **** Definitions **** */
/* **** Function Prototypes **** */
/**
* @brief Initialize timer module clock.
* @param tmr Pointer to timer module to initialize.
* @param pres Prescaler value.
* @param sys_cfg System configuration object
* @return #E_NO_ERROR if successful, error code otherwise.
*/
int TMR_Init(mxc_tmr_regs_t *tmr, tmr_pres_t pres, const sys_cfg_tmr_t* sys_cfg);
/**
* @brief Shutdown timer module clock.
* @param tmr Pointer to timer module to initialize.
* @return #E_NO_ERROR if successful, error code otherwise.
*/
int TMR_Shutdown(mxc_tmr_regs_t *tmr);
/**
* @brief Enable the timer.
* @param tmr Pointer to timer module to initialize.
*/
void TMR_Enable(mxc_tmr_regs_t* tmr);
/**
* @brief Disable the timer.
* @param tmr Pointer to timer module to initialize.
*/
void TMR_Disable(mxc_tmr_regs_t* tmr);
/**
* @brief Configure the timer.
* @param tmr Pointer to timer module to initialize.
* @param cfg Pointer to timer configuration struct.
* @return #E_NO_ERROR if successful.
*/
int TMR_Config(mxc_tmr_regs_t *tmr, const tmr_cfg_t *cfg);
/**
* @brief Configure the timer for PWM operation.
* @param tmr Pointer to timer module to initialize.
* @param cfg Pointer to timer PWM configuration struct.
* @note Can cause a glitch if the Timer is currently running.
* @return #E_BAD_PARAM if duty_cnt > per_cnt.
*/
int TMR_PWMConfig(mxc_tmr_regs_t *tmr, const tmr_pwm_cfg_t *cfg);
/**
* @brief Set the timer duty cycle.
* @param tmr Pointer to timer module to initialize
* @param duty New duty cycle count
* @note Will block until safe to change the duty count.
* @return #E_BAD_PARAM if duty_cnt > per_cnt.
*/
int TMR_PWMSetDuty(mxc_tmr_regs_t *tmr, uint32_t duty);
/**
* @brief Set the timer period.
* @param tmr Pointer to timer module to initialize.
* @param per New period count.
* @note Will block until safe to change the period count.
* @return #E_BAD_PARAM if duty_cnt > per_cnt.
*/
int TMR_PWMSetPeriod(mxc_tmr_regs_t* tmr, uint32_t per);
/**
* @brief Get the timer compare count.
* @param tmr Pointer to timer module to initialize.
* @return Returns the current compare count.
*/
uint32_t TMR_GetCompare(mxc_tmr_regs_t* tmr);
/**
* @brief Get the timer capture count.
* @param tmr Pointer to timer module to initialize.
* @return Returns the most recent capture count.
*/
uint32_t TMR_GetCapture(mxc_tmr_regs_t* tmr);
/**
* @brief Get the timer count.
* @param tmr Pointer to timer module to initialize.
* @return Returns the current count.
*/
uint32_t TMR_GetCount(mxc_tmr_regs_t* tmr);
/**
* @brief Clear the timer interrupt.
* @param tmr Pointer to timer module to initialize.
*/
void TMR_IntClear(mxc_tmr_regs_t* tmr);
/**
* @brief Get the timer interrupt status.
* @param tmr Pointer to timer module to initialize.
* @return Returns the interrupt status. 1 if interrupt has occurred.
*/
uint32_t TMR_IntStatus(mxc_tmr_regs_t* tmr);
/**
* @brief Set the timer compare count.
* @param tmr Pointer to timer module to initialize.
* @param cmp_cnt New compare count.
* @note This function does not protect against output glitches in PWM mode.
* Use TMR_PWMSetPeriod when in PWM mode.
*/
void TMR_SetCompare(mxc_tmr_regs_t *tmr, uint32_t cmp_cnt);
/**
* @brief Set the timer count.
* @param tmr Pointer to timer module to initialize.
* @param cnt New count.
*/
void TMR_SetCount(mxc_tmr_regs_t *tmr, uint32_t cnt);
/**
* @brief Convert real time to timer ticks.
* @param tmr Pointer to timer module to initialize.
* @param time Number of units of time.
* @param units Which units of time you want to convert.
* @param ticks Pointer to store the number of ticks calculated.
* @return #E_NO_ERROR if successful, error code otherwise.
*/
int TMR_GetTicks(mxc_tmr_regs_t *tmr, uint32_t time, tmr_unit_t units, uint32_t *ticks);
/**
* @brief Convert timer ticks to real time.
* @param tmr Pointer to timer module to initialize.
* @param ticks Number of ticks.
* @param time Pointer to store number of units of time.
* @param units Pointer to store the units that time represents.
* @return #E_NO_ERROR if successful, error code otherwise.
*/
int TMR_GetTime(mxc_tmr_regs_t *tmr, uint32_t ticks, uint32_t *time, tmr_unit_t *units);
/**@} end of group tmr */
#ifdef __cplusplus
}
#endif
#endif /* _TMR_H_ */
@@ -0,0 +1,146 @@
/**
* @file tmr_utils.h
* @brief Timer utility function declarations
*/
/* *****************************************************************************
* Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Maxim Integrated
* Products, Inc. shall not be used except as stated in the Maxim Integrated
* Products, Inc. Branding Policy.
*
* The mere transfer of this software does not imply any licenses
* of trade secrets, proprietary technology, copyrights, patents,
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*
* $Date: 2018-10-17 14:16:30 -0500 (Wed, 17 Oct 2018) $
* $Revision: 38560 $
*
**************************************************************************** */
/* Define to prevent redundant inclusion */
#ifndef _TMR_UTILS_H
#define _TMR_UTILS_H
/***** Includes *****/
#include "mxc_config.h"
#include "tmr_regs.h"
#include "mxc_sys.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @ingroup tmr
* @defgroup tmr_utils Timer Utility Functions
* @{
*/
/* **** Definitions **** */
/** @def Macro to convert the parameter \p s from seconds to micro-seconds. */
#define SEC(s) (((unsigned long)s) * 1000000UL)
/** @def Macro to convert the parameter \p ms from milli-seconds to micro-seconds. */
#define MSEC(ms) (ms * 1000UL)
/** @def Macro to convert the parameter \p us to micro-seconds. */
#define USEC(us) (us)
/* **** Globals **** */
/* **** Function Prototypes **** */
/**
* @brief Delays for the specified number of microseconds.
* @param tmr Which Timer instance to use
* @param us Number of microseconds to delay.
* @param sys_cfg System configuration object, identical to TMR_Init()
*/
void TMR_Delay(mxc_tmr_regs_t *tmr, unsigned long us, const sys_cfg_tmr_t *sys_cfg);
/**
* @brief Start the timeout time for the specified number of microseconds.
* @param tmr Which Timer instance to use
* @param us Number of microseconds in the timeout.
* @param sys_cfg System configuration object, identical to TMR_Init()
*/
void TMR_TO_Start(mxc_tmr_regs_t *tmr, unsigned long us, const sys_cfg_tmr_t *sys_cfg);
/**
* @brief Check if the timeout has occurred.
* @param tmr Which Timer instance to use
* @return #E_NO_ERROR if the timeout has not occurred, #E_TIME_OUT if it has.
*/
int TMR_TO_Check(mxc_tmr_regs_t *tmr);
/**
* @brief Stops the timer for the timeout.
* @param tmr Which Timer instance to use
*/
void TMR_TO_Stop(mxc_tmr_regs_t *tmr);
/**
* @brief Clears the timeout flag.
* @param tmr Which Timer instance to use
*/
void TMR_TO_Clear(mxc_tmr_regs_t *tmr);
/**
* @brief Get the number of microseconds elapsed since TMR_TO_Start().
* @param tmr Which Timer instance to use
* @return Number of microseconds since TMR_TO_Start().
*/
unsigned int TMR_TO_Elapsed(mxc_tmr_regs_t *tmr);
/**
* @brief Get the number of microseconds remaining in the timeout.
* @param tmr Which Timer instance to use
* @return Number of microseconds until timeout.
*/
unsigned int TMR_TO_Remaining(mxc_tmr_regs_t *tmr);
/**
* @brief Start the stopwatch.
* @note This function does not handle overflows
* @param tmr Which Timer to use
* @param sys_cfg System configuration object, identical to TMR_Init()
*/
void TMR_SW_Start(mxc_tmr_regs_t *tmr, const sys_cfg_tmr_t *sys_cfg);
/**
* @brief Stop the stopwatch and return the number of microseconds that
* have elapsed.
* @note This function does not handle overflows
* @param tmr Which Timer instance to use
* @return Number of microseconds since TMR_SW_Start().
*/
unsigned int TMR_SW_Stop(mxc_tmr_regs_t *tmr);
/**@} end of defgroup tmr_utils*/
#ifdef __cplusplus
}
#endif
#endif /* _TMR_UTILS_H */
@@ -0,0 +1,364 @@
/**
* @file
* @brief This files defines the driver API including definitions, data types
* and function prototypes.
*/
/* ****************************************************************************
* Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Maxim Integrated
* Products, Inc. shall not be used except as stated in the Maxim Integrated
* Products, Inc. Branding Policy.
*
* The mere transfer of this software does not imply any licenses
* of trade secrets, proprietary technology, copyrights, patents,
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*
* $Date: 2019-10-07 11:05:30 -0500 (Mon, 07 Oct 2019) $
* $Revision: 47429 $
*
*************************************************************************** */
#ifndef _UART_H_
#define _UART_H_
/***** Includes *****/
#include <stdint.h>
#include "uart_regs.h"
#include "mxc_sys.h"
/***** Definitions *****/
/**
* @brief Alternate clock rate. (7.3728MHz) */
#define UART_ALTERNATE_CLOCK_HZ 7372800
/**
* @defgroup uart UART
* @ingroup periphlibs
* @{
*/
/**
* @brief Parity settings type */
typedef enum {
UART_PARITY_DISABLE = 0, /**< Parity disabled */
UART_PARITY_EVEN_0 = (MXC_F_UART_CTRL_PARITY_EN |
MXC_S_UART_CTRL_PARITY_EVEN |
MXC_F_UART_CTRL_PARMD), /**< Use for even parity 0 */
UART_PARITY_EVEN_1 = (MXC_F_UART_CTRL_PARITY_EN |
MXC_S_UART_CTRL_PARITY_EVEN), /**< Use for even parity 1 */
UART_PARITY_EVEN = UART_PARITY_EVEN_1, /**< Conventional even parity */
UART_PARITY_ODD_0 = (MXC_F_UART_CTRL_PARITY_EN |
MXC_S_UART_CTRL_PARITY_ODD |
MXC_F_UART_CTRL_PARMD), /**< Use for odd parity 0 */
UART_PARITY_ODD_1 = (MXC_F_UART_CTRL_PARITY_EN |
MXC_S_UART_CTRL_PARITY_ODD), /**< Use for odd parity 1 */
UART_PARITY_ODD = UART_PARITY_ODD_1, /**< Conventional odd parity */
UART_PARITY_MARK_0 = (MXC_F_UART_CTRL_PARITY_EN |
MXC_S_UART_CTRL_PARITY_MARK |
MXC_F_UART_CTRL_PARMD), /**< Use for mark parity 0 */
UART_PARITY_MARK_1 = (MXC_F_UART_CTRL_PARITY_EN |
MXC_S_UART_CTRL_PARITY_MARK), /**< Use for mark parity 1 */
UART_PARITY_MARK = UART_PARITY_MARK_1, /**< Conventional mark parity */
UART_PARITY_SPACE_0 = (MXC_F_UART_CTRL_PARITY_EN |
MXC_S_UART_CTRL_PARITY_SPACE |
MXC_F_UART_CTRL_PARMD), /**< Use for space parity 0 */
UART_PARITY_SPACE_1 = (MXC_F_UART_CTRL_PARITY_EN |
MXC_S_UART_CTRL_PARITY_SPACE), /**< Use for space parity 1 */
UART_PARITY_SPACE = UART_PARITY_SPACE_1, /**< Conventional space parity */
} uart_parity_t;
/**
* @brief Message size settings */
typedef enum {
UART_DATA_SIZE_5_BITS = MXC_S_UART_CTRL_CHAR_SIZE_5, /**< Data Size 5 Bits */
UART_DATA_SIZE_6_BITS = MXC_S_UART_CTRL_CHAR_SIZE_6, /**< Data Size 6 Bits */
UART_DATA_SIZE_7_BITS = MXC_S_UART_CTRL_CHAR_SIZE_7, /**< Data Size 7 Bits */
UART_DATA_SIZE_8_BITS = MXC_S_UART_CTRL_CHAR_SIZE_8, /**< Data Size 8 Bits */
} uart_size_t;
/**
* @brief Stop bit settings */
typedef enum {
UART_STOP_1 = 0, /**< UART Stop 1 clock cycle */
UART_STOP_1P5 = MXC_F_UART_CTRL_STOPBITS, /**< UART Stop 1.5 clock cycle */
UART_STOP_2 = MXC_F_UART_CTRL_STOPBITS, /**< UART Stop 2 clock cycle */
} uart_stop_t;
/**
* @brief Flow control */
typedef enum {
UART_FLOW_CTRL_DIS = 0, /**< RTS/CTS flow is disabled */
UART_FLOW_CTRL_EN = MXC_F_UART_CTRL_FLOW_CTRL, /**< RTS/CTS flow is enabled */
} uart_flow_ctrl_t;
/**
* @brief Flow control Polarity */
typedef enum {
UART_FLOW_POL_DIS = 0, /**< RTS/CTS asserted is low */
UART_FLOW_POL_EN = MXC_F_UART_CTRL_FLOW_POL, /**< RTS/CTS asserted is high */
} uart_flow_pol_t;
#if (TARGET != 32660)
/**
* @brief Clock Source Select */
typedef enum {
UART_CLKSEL_SYSTEM = 0, /**< Peripheral clock will be used as the bit rate clock */
UART_CLKSEL_ALTERNATE = MXC_F_UART_CTRL_CLKSEL, /**< Use the device's alternate UART bit rate clock. */
} uart_clksel_t;
#endif
/**
* @brief UART configuration type. */
typedef struct {
uart_parity_t parity; /** Configure parity checking */
uart_size_t size; /** Configure character size */
uart_stop_t stop; /** Configure the number of stop bits to use */
uart_flow_ctrl_t flow; /** Configure hardware flow control */
uart_flow_pol_t pol; /** Configure hardware flow control */
uint32_t baud; /** Configure baud rate */
#if (TARGET != 32660)
uart_clksel_t clksel; /** Configure hardware clock source */
#endif
} uart_cfg_t;
/**
* @brief Non-blocking UART transaction request. */
typedef struct uart_req uart_req_t;
struct uart_req {
uint8_t *data; /** Data buffer for characters */
int len; /** Length of characters in data to send or receive */
int num; /** Number of characters actually sent or received */
/**
* @brief Callback for asynchronous request.
*
* @param uart_req_t* Pointer to the transaction request.
* @param int Error code.
*
*/
void(*callback)(uart_req_t*, int);
};
/***** Functions Prototypes *****/
/**
* @brief Initialize and enable UART module.
* @param uart Pointer to the UART registers.
* @param cfg Pointer to UART configuration.
* @param sys_cfg Pointer to system configuration object
* @returns #E_NO_ERROR UART initialized successfully, @ref MXC_Error_Codes "error" if
* unsuccessful.
*/
int UART_Init(mxc_uart_regs_t *uart, const uart_cfg_t *cfg, const sys_cfg_uart_t* sys_cfg);
/**
* @brief Shutdown UART module.
* @param uart Pointer to the UART registers.
* @returns #E_NO_ERROR UART shutdown successfully, @ref MXC_Error_Codes "error" if
* unsuccessful.
*/
int UART_Shutdown(mxc_uart_regs_t *uart);
/**
* @brief UART interrupt handler.
* @details This function should be called by the application from the
* interrupt handler if UART interrupts are enabled. Alternately,
* this function can be periodically called by the application if
* UART interrupts are disabled. It is only necessary to call this
* when using asynchronous functions.
*
* @param uart Pointer to the UART registers.
*/
void UART_Handler(mxc_uart_regs_t *uart);
/**
* @brief Read UART data, <em>blocking</em> until transaction is complete.
*
* @param uart Pointer to the UART registers.
* @param data Pointer to buffer to save the data read.
* @param len Number of bytes to read.
* @param num Pointer to store the number of bytes actually read, pass NULL if not needed.
*
* @return Number of bytes read, @ref MXC_Error_Codes "error" if unsuccessful.
*/
int UART_Read(mxc_uart_regs_t *uart, uint8_t *data, int len, int *num);
/**
* @brief Write UART data. This function blocks until the write transaction
* is complete.
* @param uart Pointer to the UART registers.
* @param data Pointer to buffer for write data.
* @param len Number of bytes to write.
* @note This function will return once data has been put into FIFO, not necessarily
* transmitted.
* @return Number of bytes written if successful, @ref MXC_Error_Codes "error" if unsuccessful.
*/
int UART_Write(mxc_uart_regs_t *uart, const uint8_t *data, int len);
/**
* @brief Asynchronously read UART data.
*
* @param uart Pointer to the UART registers.
* @param req Pointer to request for a UART transaction, see #uart_req.
* @note Request struct must remain allocated until callback function specified in 'req' is called.
*
* @return #E_NO_ERROR Asynchronous read successfully started, @ref MXC_Error_Codes "error" if unsuccessful.
*/
int UART_ReadAsync(mxc_uart_regs_t *uart, uart_req_t *req);
/**
* @brief Asynchronously write/transmit UART data.
*
* @param uart Pointer to the UART registers.
* @param req Request for a UART transaction, see #uart_req.
* @note Request struct must remain allocated until callback function specified in 'req' is called.
*
* @return #E_NO_ERROR Asynchronous write successfully started, @ref
* MXC_Error_Codes "error" if unsuccessful.
*/
int UART_WriteAsync(mxc_uart_regs_t *uart, uart_req_t *req);
/**
* @brief Read a single byte from the UART.
* @note This function will block until a character is available.
*
* @param uart Pointer to the UART registers.
* @return The byte read.
*/
uint8_t UART_ReadByte(mxc_uart_regs_t *uart);
/**
* @brief Write one byte at a time to the UART.
* @note This function will block until the character has been placed in the transmit FIFO.
* It may return before the character is actually transmitted.
*
* @param uart Pointer to the UART registers.
* @param data The byte to write.
*/
void UART_WriteByte(mxc_uart_regs_t *uart, uint8_t data);
/**
* @brief Check to see if the UART is busy.
*
* @param uart Pointer to the UART registers.
*
* @return #E_NO_ERROR if the UART is idle, #E_BUSY if the UART is in use.
*/
int UART_Busy(mxc_uart_regs_t *uart);
/**
* @brief Prepare the UART for entry into a Low-Power mode (DEEPSLEEP/BACKUP).
* @details Checks for any ongoing transactions. Disables interrupts if the
* UART is idle.
*
* @param uart Pointer to the UART registers.
* @return #E_NO_ERROR UART is ready to enter Low-Power modes (DEEPSLEEP/BACKUP).
* @return #E_BUSY UART is active and busy and not ready to enter a
* Low-Power mode (DEEPSLEEP/BACKUP).
*
*/
int UART_PrepForSleep(mxc_uart_regs_t *uart);
/**
* @brief Abort asynchronous request.
*
* @param req Pointer to the request to abort. See #uart_req.
*
* @return #E_NO_ERROR if the asynchronous request aborted successfully started, @ref
* MXC_Error_Codes "error" if unsuccessful.
*/
int UART_AbortAsync(uart_req_t *req);
/**
* @brief Returns the number of bytes still pending transmission in the UART TX FIFO.
*
* @param uart Pointer to the UART registers.
*
* @return Number of unused bytes in the TX FIFO.
*/
unsigned UART_NumWriteAvail(mxc_uart_regs_t *uart);
/**
* @brief Returns the number of bytes available to be read from the RX FIFO.
*
* @param uart Pointer to the UART registers.
*
* @return The number of bytes available to read in the RX FIFO.
*/
unsigned UART_NumReadAvail(mxc_uart_regs_t *uart);
/**
* @brief Clears the specified interrupt flags.
*
* @param uart Pointer to the UART registers.
* @param mask Mask of the UART interrupts to clear, see
* @ref UART_INT_FL Register.
*/
void UART_ClearFlags(mxc_uart_regs_t *uart, uint32_t mask);
/**
* @brief Get the UART interrupt flags.
*
* @param uart Pointer to the UART registers.
*
* @return Mask of active flags.
*/
unsigned UART_GetFlags(mxc_uart_regs_t *uart);
/**
* @brief Enables the UART.
* @note This function does not change the existing UART configuration.
*
* @param uart Pointer to the UART registers.
*/
void UART_Enable(mxc_uart_regs_t *uart);
/**
* @brief Disables the UART.
* @note This function does not change the existing UART configuration.
*
* @param uart Pointer to the UART registers.
*/
void UART_Disable(mxc_uart_regs_t *uart);
/**
* @brief Drains/empties and data in the RX FIFO, discarding any bytes not yet consumed.
*
* @param uart Pointer to the UART registers.
*/
void UART_DrainRX(mxc_uart_regs_t *uart);
/**
* @brief Drains/empties any data in the TX FIFO, discarding any bytes not yet transmitted.
*
* @param uart Pointer to the UART registers.
*/
void UART_DrainTX(mxc_uart_regs_t *uart);
/**@} end of group uart */
#endif /* _UART_H_ */
@@ -0,0 +1,166 @@
/**
* @file wdt.h
* @brief Watchdog timer (WDT) function prototypes and data types.
*/
/* ****************************************************************************
* Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Maxim Integrated
* Products, Inc. shall not be used except as stated in the Maxim Integrated
* Products, Inc. Branding Policy.
*
* The mere transfer of this software does not imply any licenses
* of trade secrets, proprietary technology, copyrights, patents,
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*
* $Date: 2020-04-20 15:06:58 -0500 (Mon, 20 Apr 2020) $
* $Revision: 53142 $
*
*************************************************************************** */
/* Define to prevent redundant inclusion */
#ifndef _WDT_H_
#define _WDT_H_
/* **** Includes **** */
#include <stdint.h>
#include "mxc_config.h"
#include "mxc_sys.h"
#include "wdt_regs.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @defgroup wdt Watchdog Timer (WDT)
* @ingroup periphlibs
* @{
*/
/* **** Definitions **** */
/** @brief Watchdog period enumeration.
Used to configure the period of the watchdog interrupt */
typedef enum {
WDT_PERIOD_2_31 = MXC_S_WDT_CTRL_INT_PERIOD_WDT2POW31, /**< Period 2^31 */
WDT_PERIOD_2_30 = MXC_S_WDT_CTRL_INT_PERIOD_WDT2POW30, /**< Period 2^30 */
WDT_PERIOD_2_29 = MXC_S_WDT_CTRL_INT_PERIOD_WDT2POW29, /**< Period 2^29 */
WDT_PERIOD_2_28 = MXC_S_WDT_CTRL_INT_PERIOD_WDT2POW28, /**< Period 2^28 */
WDT_PERIOD_2_27 = MXC_S_WDT_CTRL_INT_PERIOD_WDT2POW27, /**< Period 2^27 */
WDT_PERIOD_2_26 = MXC_S_WDT_CTRL_INT_PERIOD_WDT2POW26, /**< Period 2^26 */
WDT_PERIOD_2_25 = MXC_S_WDT_CTRL_INT_PERIOD_WDT2POW25, /**< Period 2^25 */
WDT_PERIOD_2_24 = MXC_S_WDT_CTRL_INT_PERIOD_WDT2POW24, /**< Period 2^24 */
WDT_PERIOD_2_23 = MXC_S_WDT_CTRL_INT_PERIOD_WDT2POW23, /**< Period 2^23 */
WDT_PERIOD_2_22 = MXC_S_WDT_CTRL_INT_PERIOD_WDT2POW22, /**< Period 2^22 */
WDT_PERIOD_2_21 = MXC_S_WDT_CTRL_INT_PERIOD_WDT2POW21, /**< Period 2^21 */
WDT_PERIOD_2_20 = MXC_S_WDT_CTRL_INT_PERIOD_WDT2POW20, /**< Period 2^20 */
WDT_PERIOD_2_19 = MXC_S_WDT_CTRL_INT_PERIOD_WDT2POW19, /**< Period 2^19 */
WDT_PERIOD_2_18 = MXC_S_WDT_CTRL_INT_PERIOD_WDT2POW18, /**< Period 2^18 */
WDT_PERIOD_2_17 = MXC_S_WDT_CTRL_INT_PERIOD_WDT2POW17, /**< Period 2^17 */
WDT_PERIOD_2_16 = MXC_S_WDT_CTRL_INT_PERIOD_WDT2POW16, /**< Period 2^16 */
} wdt_period_t;
/* **** Function Prototypes **** */
/**
* @brief Initialize the Watchdog Timer
* @param wdt Pointer to the watchdog registers
* @param sys_cfg The system configuration object
*/
int WDT_Init(mxc_wdt_regs_t* wdt, sys_cfg_wdt_t sys_cfg);
/**
* @brief Set the period of the watchdog interrupt.
* @param wdt Pointer to watchdog registers.
* @param period Enumeration of the desired watchdog period.
*/
void WDT_SetIntPeriod(mxc_wdt_regs_t* wdt, wdt_period_t period);
/**
* @brief Set the period of the watchdog reset.
* @param wdt Pointer to watchdog registers.
* @param period Enumeration of the desired watchdog period.
*/
void WDT_SetResetPeriod(mxc_wdt_regs_t* wdt, wdt_period_t period);
/**
* @brief Enable the watchdog timer.
* @param wdt Pointer to watchdog registers.
* @param enable 1 to enable the timer, 0 to disable.
*/
void WDT_Enable(mxc_wdt_regs_t* wdt, int enable);
/**
* @brief Enable the watchdog interrupt.
* @param wdt Pointer to watchdog registers.
* @param enable 1 to enable the interrupt, 0 to disable.
*/
void WDT_EnableInt(mxc_wdt_regs_t* wdt, int enable);
/**
* @brief Enable the watchdog reset.
* @param wdt Pointer to watchdog registers.
* @param enable 1 to enable the reset, 0 to disable.
*/
void WDT_EnableReset(mxc_wdt_regs_t* wdt, int enable);
/**
* @brief Reset the watchdog timer.
* @param wdt Pointer to watchdog registers.
*/
void WDT_ResetTimer(mxc_wdt_regs_t* wdt);
/**
* @brief Get the status of the reset flag.
* @param wdt Pointer to watchdog registers.
* @returns 1 if the previous reset was caused by the watchdog, 0 otherwise.
*/
int WDT_GetResetFlag(mxc_wdt_regs_t* wdt);
/**
* @brief Clears the reset flag.
* @param wdt Pointer to watchdog registers.
*/
void WDT_ClearResetFlag(mxc_wdt_regs_t* wdt);
/**
* @brief Get the status of the interrupt flag.
* @param wdt Pointer to watchdog registers.
* @returns 1 if the interrupt is pending, 0 otherwise.
*/
int WDT_GetIntFlag(mxc_wdt_regs_t* wdt);
/**
* @brief Clears the interrupt flag.
* @param wdt Pointer to watchdog registers.
*/
void WDT_ClearIntFlag(mxc_wdt_regs_t* wdt);
/**@} end of group wdt */
#ifdef __cplusplus
}
#endif
#endif /* _WDT_H_ */
@@ -0,0 +1,374 @@
/* *****************************************************************************
* Copyright (C) 2017 Maxim Integrated Products, Inc., All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Maxim Integrated
* Products, Inc. shall not be used except as stated in the Maxim Integrated
* Products, Inc. Branding Policy.
*
* The mere transfer of this software does not imply any licenses
* of trade secrets, proprietary technology, copyrights, patents,
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*
* $Date: 2019-07-01 11:06:19 -0500 (Mon, 01 Jul 2019) $
* $Revision: 44383 $
*
**************************************************************************** */
#include <stddef.h>
#include <stdint.h>
#include "mxc_config.h"
#include "mxc_assert.h"
#include "mxc_lock.h"
#include "mxc_sys.h"
#include "dma.h"
/*
* Structure type
*/
typedef struct {
unsigned int valid; /* Flag to invalidate this resource */
unsigned int instance; /* Hardware instance of this DMA controller */
unsigned int id; /* Channel ID, which matches the index into the underlying hardware */
mxc_dma_ch_regs_t *regs; /* Pointer to the registers for this channel */
void (*cb)(int, int); /* Pointer to a callback function type */
} dma_channel_t;
#define CHECK_HANDLE(x) ((x >= 0) && (x < MXC_DMA_CHANNELS) && (dma_resource[x].valid))
/* DMA driver must be initialized once before use, and may not be initialized again without shutdown, as it is a shared resource */
static unsigned int dma_initialized = 0;
static dma_channel_t dma_resource[MXC_DMA_CHANNELS];
static uint32_t dma_lock;
/* Initialize DMA to known state */
int DMA_Init(void)
{
int i;
if (dma_initialized) {
return E_BAD_STATE;
}
/* Initialize any system-level DMA settings */
SYS_DMA_Init();
/* Initialize mutex */
mxc_free_lock(&dma_lock);
if (mxc_get_lock(&dma_lock, 1) != E_NO_ERROR) {
return E_BUSY;
}
/* Ensure all channels are disabled at start, clear flags, init handles */
MXC_DMA->cn = 0;
for (i = 0; i < MXC_DMA_CHANNELS; i++) {
dma_resource[i].valid = 0;
dma_resource[i].instance = 0;
dma_resource[i].id = i;
dma_resource[i].regs = (mxc_dma_ch_regs_t *)&MXC_DMA->ch[i];
dma_resource[i].regs->cfg = 0;
dma_resource[i].regs->st = dma_resource[i].regs->st;
dma_resource[i].cb = NULL;
}
dma_initialized++;
mxc_free_lock(&dma_lock);
return E_NO_ERROR;
}
/* Shut down DMA in an orderly manner, informing clients that their requests did not complete */
int DMA_Shutdown(void)
{
int i;
if (!dma_initialized) {
/* Never initialized, so shutdown is not appropriate */
return E_BUSY;
}
if (mxc_get_lock(&dma_lock, 1) != E_NO_ERROR) {
return E_BUSY;
}
/* Prevent any new resource allocation by this API */
dma_initialized = 0;
/* Disable interrupts, preventing future callbacks */
MXC_DMA->cn = 0;
/* For each channel:
* - invalidate the handles held by clients
* - stop any transfer in progress
*/
for (i = 0; i < MXC_DMA_CHANNELS; i++) {
dma_resource[i].regs->cfg = 0;
if (dma_resource[i].valid) {
dma_resource[i].valid = 0;
if (dma_resource[i].cb != NULL) {
dma_resource[i].cb(i, E_SHUTDOWN);
}
}
}
/* Disable any system-level DMA settings */
SYS_DMA_Shutdown();
mxc_free_lock(&dma_lock);
return E_NO_ERROR;
}
/* Request DMA channel */
/* Once "owned", this channel may be used directly via the DMA_GetCHRegs(ch) pointer, or */
/* configured via the API functions */
int DMA_AcquireChannel(void)
{
int i, channel;
/* Check for initialization */
if (!dma_initialized) {
return E_BAD_STATE;
}
/* If DMA is locked return busy */
if (mxc_get_lock(&dma_lock, 1) != E_NO_ERROR) {
return E_BUSY;
}
/* Default is no channel available */
channel = E_NONE_AVAIL;
if (dma_initialized) {
for (i = 0; i < MXC_DMA_CHANNELS; i++) {
if (!dma_resource[i].valid) {
/* Found one */
channel = i;
dma_resource[i].valid = 1;
dma_resource[i].regs->cfg = 0;
dma_resource[i].regs->cnt_rld = 0; /* Used by DMA_Start() to conditionally set RLDEN */
break;
}
}
}
mxc_free_lock(&dma_lock);
return channel;
}
/* Release DMA channel */
/* Callbacks will not be called */
int DMA_ReleaseChannel(int ch)
{
if (CHECK_HANDLE(ch)) {
if (mxc_get_lock(&dma_lock, 1) != E_NO_ERROR) {
return E_BUSY;
}
dma_resource[ch].valid = 0;
dma_resource[ch].regs->cfg = 0;
dma_resource[ch].regs->st = dma_resource[ch].regs->st;
mxc_free_lock(&dma_lock);
} else {
return E_BAD_PARAM;
}
return E_NO_ERROR;
}
/* Channel configuration */
int DMA_ConfigChannel(int ch,
dma_priority_t prio,
dma_reqsel_t reqsel, unsigned int reqwait_en,
dma_timeout_t tosel, dma_prescale_t pssel,
dma_width_t srcwd, unsigned int srcinc_en,
dma_width_t dstwd, unsigned int dstinc_en,
unsigned int burst_size, unsigned int chdis_inten,
unsigned int ctz_inten)
{
if (CHECK_HANDLE(ch) && (burst_size > 0)) {
/* Designed to be safe, not speedy. Should not be called often */
dma_resource[ch].regs->cfg =
((reqwait_en ? MXC_F_DMA_CFG_REQWAIT : 0) |
(srcinc_en ? MXC_F_DMA_CFG_SRCINC : 0) |
(dstinc_en ? MXC_F_DMA_CFG_DSTINC : 0) |
(chdis_inten ? MXC_F_DMA_CFG_CHDIEN : 0) |
(ctz_inten ? MXC_F_DMA_CFG_CTZIEN : 0) |
prio |reqsel | tosel | pssel |
(srcwd << MXC_F_DMA_CFG_SRCWD_POS) |
(dstwd << MXC_F_DMA_CFG_DSTWD_POS) |
(((burst_size - 1) << MXC_F_DMA_CFG_BRST_POS) & MXC_F_DMA_CFG_BRST));
} else {
return E_BAD_PARAM;
}
return E_NO_ERROR;
}
/*
* DMA request selects for peripherals will override either src_addr or dst_addr.
* In these cases, the overridden address is a don't care and may be 0.
*/
int DMA_SetSrcDstCnt(int ch,
void *src_addr,
void *dst_addr,
unsigned int count)
{
if (CHECK_HANDLE(ch)) {
dma_resource[ch].regs->src = (unsigned int)src_addr;
dma_resource[ch].regs->dst = (unsigned int)dst_addr;
dma_resource[ch].regs->cnt = count;
} else {
return E_BAD_PARAM;
}
return E_NO_ERROR;
}
/* Must set en_reload == 1 to have any effect */
int DMA_SetReload(int ch,
void *src_addr_reload,
void *dst_addr_reload,
unsigned int count_reload)
{
if (CHECK_HANDLE(ch)) {
dma_resource[ch].regs->src_rld = (unsigned int)src_addr_reload;
dma_resource[ch].regs->dst_rld = (unsigned int)dst_addr_reload;
if (dma_resource[ch].regs->cfg & MXC_F_DMA_CFG_CHEN) {
/* If channel is already running, set RLDEN to enable next reload */
dma_resource[ch].regs->cnt_rld = MXC_F_DMA_CNT_RLD_RLDEN | count_reload;
} else {
/* Otherwise, this is the initial setup, so DMA_Start() will handle setting that bit */
dma_resource[ch].regs->cnt_rld = count_reload;
}
} else {
return E_BAD_PARAM;
}
return E_NO_ERROR;
}
int DMA_SetCallback(int ch, void (*callback)(int, int))
{
if (CHECK_HANDLE(ch)) {
/* Callback for interrupt handler, no checking is done, as NULL is valid for (none) */
dma_resource[ch].cb = callback;
} else {
return E_BAD_PARAM;
}
return E_NO_ERROR;
}
/* Interrupt enable/disable */
int DMA_EnableInterrupt(int ch)
{
if (CHECK_HANDLE(ch)) {
MXC_DMA->cn |= (1 << ch);
} else {
return E_BAD_PARAM;
}
return E_NO_ERROR;
}
int DMA_DisableInterrupt(int ch)
{
if (CHECK_HANDLE(ch)) {
MXC_DMA->cn &= ~(1 << ch);
} else {
return E_BAD_PARAM;
}
return E_NO_ERROR;
}
/* Channel interrupt flags */
int DMA_GetFlags(int ch, unsigned int *fl)
{
if (CHECK_HANDLE(ch) && fl) {
*fl = dma_resource[ch].regs->st;
} else {
return E_BAD_PARAM;
}
return E_NO_ERROR;
}
int DMA_ClearFlags(int ch)
{
if (CHECK_HANDLE(ch)) {
dma_resource[ch].regs->st = dma_resource[ch].regs->st;
} else {
return E_BAD_PARAM;
}
return E_NO_ERROR;
}
/* Start channel */
int DMA_Start(int ch)
{
if (CHECK_HANDLE(ch)) {
DMA_ClearFlags(ch);
if (dma_resource[ch].regs->cnt_rld) {
dma_resource[ch].regs->cfg |= (MXC_F_DMA_CFG_CHEN | MXC_F_DMA_CFG_RLDEN);
} else {
dma_resource[ch].regs->cfg |= MXC_F_DMA_CFG_CHEN;
}
} else {
return E_BAD_PARAM;
}
return E_NO_ERROR;
}
/* Stop channel */
int DMA_Stop(int ch)
{
if (CHECK_HANDLE(ch)) {
dma_resource[ch].regs->cfg &= ~MXC_F_DMA_CFG_CHEN;
} else {
return E_BAD_PARAM;
}
return E_NO_ERROR;
}
/* Get pointer to registers, for advanced users */
mxc_dma_ch_regs_t *DMA_GetCHRegs(int ch)
{
if (CHECK_HANDLE(ch)) {
return dma_resource[ch].regs;
} else {
return NULL;
}
}
/* */
void DMA_Handler(int ch)
{
/* Do callback, if enabled */
if (dma_resource[ch].cb != NULL) {
dma_resource[ch].cb(ch, E_NO_ERROR);
}
DMA_ClearFlags(ch);
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,312 @@
/* *****************************************************************************
* Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Maxim Integrated
* Products, Inc. shall not be used except as stated in the Maxim Integrated
* Products, Inc. Branding Policy.
*
* The mere transfer of this software does not imply any licenses
* of trade secrets, proprietary technology, copyrights, patents,
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*
* $Date: 2018-12-18 15:37:22 -0600 (Tue, 18 Dec 2018) $
* $Revision: 40072 $
*
**************************************************************************** */
/* **** Includes **** */
#include "mxc_config.h"
#include "mxc_assert.h"
#include "gpio.h"
#include <stddef.h>
/* **** Definitions **** */
/* **** Globals **** */
static void (*callback[MXC_CFG_GPIO_INSTANCES][MXC_CFG_GPIO_PINS_PORT])(void *);
static void *cbparam[MXC_CFG_GPIO_INSTANCES][MXC_CFG_GPIO_PINS_PORT];
/* **** Functions **** */
int GPIO_Init(void)
{
int i;
int j;
// Initialize call back arrays
for(i = 0; i < MXC_CFG_GPIO_INSTANCES; i++) {
for(j = 0; j < MXC_CFG_GPIO_PINS_PORT; j++) {
callback[i][j] = NULL;
}
}
return E_NO_ERROR;
}
/* ************************************************************************** */
/*
* GPIO_EN2 | GPIO_EN1 | GPIO_EN | Function
* --------------|---------------------|---------------------|----------------------
* 0 | 0 | 0 | Alternative 1
* 0 | 1 | 0 | Alternative 2
* 1 | 0 | 0 | Alternative 3
* 1 | 1 | 0 | Alternative 4
* 0 | 0 | 1 | GPIO (default)
*/
int GPIO_Config(const gpio_cfg_t *cfg)
{
mxc_gpio_regs_t *gpio = MXC_GPIO_GET_GPIO(cfg->port);
// Set the GPIO type
switch (cfg->func) {
case GPIO_FUNC_IN:
gpio->out_en_clr = cfg->mask;
gpio->en_set = cfg->mask;
gpio->en1_clr = cfg->mask;
gpio->en2_clr = cfg->mask;
break;
case GPIO_FUNC_OUT:
gpio->out_en_set = cfg->mask;
gpio->en_set = cfg->mask;
gpio->en1_clr = cfg->mask;
gpio->en2_clr = cfg->mask;
break;
case GPIO_FUNC_ALT1:
gpio->en_clr = cfg->mask;
gpio->en1_clr = cfg->mask;
gpio->en2_clr = cfg->mask;
break;
case GPIO_FUNC_ALT2:
gpio->en_clr = cfg->mask;
gpio->en1_set = cfg->mask;
gpio->en2_clr = cfg->mask;
break;
case GPIO_FUNC_ALT3:
#if TARGET==32660
gpio->en_set = cfg->mask;
gpio->en1_set = cfg->mask;
#else
gpio->en_clr = cfg->mask;
gpio->en1_clr = cfg->mask;
gpio->en2_set = cfg->mask;
#endif
break;
case GPIO_FUNC_ALT4:
gpio->en_clr = cfg->mask;
gpio->en1_set = cfg->mask;
gpio->en2_set = cfg->mask;
break;
default:
return E_BAD_PARAM;
}
// Configure the pad
switch (cfg->pad) {
case GPIO_PAD_NONE:
gpio->pad_cfg1 &= ~cfg->mask;
gpio->pad_cfg2 &= ~cfg->mask;
#if TARGET==32660
gpio->ps &= ~cfg->mask;
#endif
break;
case GPIO_PAD_PULL_UP:
gpio->pad_cfg1 |= cfg->mask;
gpio->pad_cfg2 &= ~cfg->mask;
#if TARGET==32660
gpio->ps |= cfg->mask;
#endif
break;
case GPIO_PAD_PULL_DOWN:
gpio->pad_cfg1 &= ~cfg->mask;
gpio->pad_cfg2 |= cfg->mask;
#if TARGET==32660
gpio->ps &= ~cfg->mask;
#endif
break;
default:
return E_BAD_PARAM;
}
return E_NO_ERROR;
}
/* ************************************************************************** */
uint32_t GPIO_InGet(const gpio_cfg_t *cfg)
{
mxc_gpio_regs_t *gpio = MXC_GPIO_GET_GPIO(cfg->port);
return (gpio->in & cfg->mask);
}
/* ************************************************************************** */
void GPIO_OutSet(const gpio_cfg_t *cfg)
{
mxc_gpio_regs_t *gpio = MXC_GPIO_GET_GPIO(cfg->port);
gpio->out_set = cfg->mask;
}
/* ************************************************************************** */
void GPIO_OutClr(const gpio_cfg_t *cfg)
{
mxc_gpio_regs_t *gpio = MXC_GPIO_GET_GPIO(cfg->port);
gpio->out_clr = cfg->mask;
}
/* ************************************************************************** */
uint32_t GPIO_OutGet(const gpio_cfg_t *cfg)
{
mxc_gpio_regs_t *gpio = MXC_GPIO_GET_GPIO(cfg->port);
return (gpio->out & cfg->mask);
}
/* ************************************************************************** */
void GPIO_OutPut(const gpio_cfg_t *cfg, uint32_t val)
{
mxc_gpio_regs_t *gpio = MXC_GPIO_GET_GPIO(cfg->port);
gpio->out = (gpio->out & ~cfg->mask) | (val & cfg->mask);
}
/* ************************************************************************** */
void GPIO_OutToggle(const gpio_cfg_t *cfg)
{
mxc_gpio_regs_t *gpio = MXC_GPIO_GET_GPIO(cfg->port);
gpio->out ^= cfg->mask;
}
/* ************************************************************************** */
int GPIO_IntConfig(const gpio_cfg_t *cfg, gpio_int_mode_t mode, gpio_int_pol_t pol)
{
mxc_gpio_regs_t *gpio = MXC_GPIO_GET_GPIO(cfg->port);
switch (mode) {
case GPIO_INT_LEVEL:
gpio->int_mod &= ~cfg->mask;
break;
case GPIO_INT_EDGE:
gpio->int_mod |= cfg->mask;
break;
default:
return E_BAD_PARAM;
}
switch (pol) {
case GPIO_INT_FALLING: /* GPIO_INT_HIGH */
gpio->int_pol &= ~cfg->mask;
gpio->int_dual_edge &= ~cfg->mask;
break;
case GPIO_INT_RISING: /* GPIO_INT_LOW */
gpio->int_pol |= cfg->mask;
gpio->int_dual_edge &= ~cfg->mask;
break;
case GPIO_INT_BOTH:
gpio->int_dual_edge |= cfg->mask;
break;
default:
return E_BAD_PARAM;
}
return E_NO_ERROR;
}
/* ************************************************************************** */
void GPIO_IntEnable(const gpio_cfg_t *cfg)
{
mxc_gpio_regs_t *gpio = MXC_GPIO_GET_GPIO(cfg->port);
gpio->int_en_set = cfg->mask;
}
/* ************************************************************************** */
void GPIO_IntDisable(const gpio_cfg_t *cfg)
{
mxc_gpio_regs_t *gpio = MXC_GPIO_GET_GPIO(cfg->port);
gpio->int_en_clr = cfg->mask;
}
/* ************************************************************************** */
uint32_t GPIO_IntStatus(const gpio_cfg_t *cfg)
{
mxc_gpio_regs_t *gpio = MXC_GPIO_GET_GPIO(cfg->port);
return (gpio->int_stat & cfg->mask);
}
/* ************************************************************************** */
void GPIO_IntClr(const gpio_cfg_t *cfg)
{
mxc_gpio_regs_t *gpio = MXC_GPIO_GET_GPIO(cfg->port);
gpio->int_clr = cfg->mask;
}
/* ************************************************************************** */
void GPIO_RegisterCallback(const gpio_cfg_t *cfg, gpio_callback_fn func, void *cbdata)
{
uint32_t mask;
unsigned int pin;
mask = cfg->mask;
pin = 0;
while (mask) {
if (mask & 1) {
callback[cfg->port][pin] = func;
cbparam[cfg->port][pin] = cbdata;
}
pin++;
mask >>= 1;
}
}
/* ************************************************************************** */
void GPIO_Handler(unsigned int port)
{
uint32_t stat;
unsigned int pin;
MXC_ASSERT(port < MXC_CFG_GPIO_INSTANCES);
mxc_gpio_regs_t *gpio = MXC_GPIO_GET_GPIO(port);
stat = gpio->int_stat;
gpio->int_clr = stat;
pin = 0;
while (stat) {
if (stat & 1) {
if(callback[port][pin]) {
callback[port][pin](cbparam[port][pin]);
}
}
pin++;
stat >>= 1;
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,216 @@
/**
* @file i2s.c
* @brief Inter-Integrated Sound (I2S) driver implementation.
*/
/* ****************************************************************************
* Copyright (C) 2017 Maxim Integrated Products, Inc., All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Maxim Integrated
* Products, Inc. shall not be used except as stated in the Maxim Integrated
* Products, Inc. Branding Policy.
*
* The mere transfer of this software does not imply any licenses
* of trade secrets, proprietary technology, copyrights, patents,
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*
* $Date: 2018-12-18 15:37:22 -0600 (Tue, 18 Dec 2018) $
* $Revision: 40072 $
*
*************************************************************************** */
#include <stddef.h>
#include <stdint.h>
#include "mxc_config.h"
#include "mxc_assert.h"
#include "mxc_lock.h"
#include "mxc_sys.h"
#include "dma.h"
#include "i2s.h"
#define I2S_CHANNELS 2
#define I2S_WIDTH 16
int dma_channel = -1;
int I2S_Init(const i2s_cfg_t *cfg, void (*dma_ctz_cb)(int, int), const sys_cfg_i2s_t* sys_cfg_i2s)
{
unsigned int i2s_clk, baud;
uint16_t clocks;
uint8_t ctz_en;
int err;
SYS_I2S_Init(sys_cfg_i2s);
/* Setup SPI_MSS as master, mode 0, 16 bit transfers as I2S Requires */
MXC_SPIMSS->ctrl = MXC_F_SPIMSS_CTRL_MMEN;
MXC_SPIMSS->mod = MXC_V_SPIMSS_MOD_NUMBITS_BITS16 | MXC_F_SPIMSS_MOD_SSIO;
MXC_SPIMSS->dma = MXC_S_SPIMSS_DMA_TX_FIFO_LEVEL_ENTRIES8;
/* Setup I2S register from i2s_cfg_t */
MXC_SPIMSS->i2s_ctrl = cfg->left_justify << MXC_F_SPIMSS_I2S_CTRL_I2S_LJ_POS |
cfg->mono_audio << MXC_F_SPIMSS_I2S_CTRL_I2S_MONO_POS;
/* Determine divisor for baud rate generator */
baud = cfg->sample_rate*I2S_CHANNELS*I2S_WIDTH;
i2s_clk = SYS_I2S_GetFreq(MXC_SPIMSS);
if (i2s_clk/4 < baud) {
return E_BAD_PARAM;
}
clocks = i2s_clk / (2*baud);
MXC_SPIMSS->brg = clocks;
/* Prepare SPIMSS DMA register for DMA setup */
if (dma_ctz_cb == NULL) {
ctz_en = 0;
} else {
ctz_en = 1;
}
/* Initialize DMA */
if (cfg->audio_direction % 2) {
MXC_SPIMSS->dma |= MXC_F_SPIMSS_DMA_TX_DMA_EN | MXC_F_SPIMSS_DMA_TX_FIFO_CLEAR;
if ((err = DMA_Init()) != E_NO_ERROR) {
if (err != E_BAD_STATE) {
return err;
}
}
if ((err = DMA_AcquireChannel()) < 0) {
return err;
}
dma_channel = err;
DMA_ConfigChannel(dma_channel, DMA_PRIO_MEDHIGH,
sys_cfg_i2s->dma_reqsel_tx, 1, DMA_TIMEOUT_512_CLK,
DMA_PRESCALE_DIV64K, DMA_WIDTH_HALFWORD, 1,
DMA_WIDTH_HALFWORD, 0, 16, 0, ctz_en);
if (ctz_en) {
DMA_SetCallback(dma_channel, dma_ctz_cb);
DMA_EnableInterrupt(dma_channel);
}
}
if (cfg->audio_direction / 2) {
MXC_SPIMSS->dma = MXC_F_SPIMSS_DMA_RX_DMA_EN | MXC_F_SPIMSS_DMA_RX_FIFO_CLEAR;
if ((err = DMA_Init()) != E_NO_ERROR) {
if (err != E_BAD_STATE) { //DMA already initialized
return err;
}
}
if ((err = DMA_AcquireChannel()) < 0) {
return err;
}
dma_channel = err;
DMA_ConfigChannel(dma_channel, DMA_PRIO_MEDHIGH,
sys_cfg_i2s->dma_reqsel_rx, 1, DMA_TIMEOUT_512_CLK,
DMA_PRESCALE_DIV64K, DMA_WIDTH_HALFWORD, 0,
DMA_WIDTH_HALFWORD, 1, 8, 0, ctz_en);
if (ctz_en) {
DMA_SetCallback(dma_channel, dma_ctz_cb);
DMA_EnableInterrupt(dma_channel);
}
}
I2S_DMA_SetAddrCnt(cfg->dma_src_addr, cfg->dma_dst_addr, cfg->dma_cnt);
if (cfg->dma_reload_en) {
I2S_DMA_SetReload(cfg->dma_src_addr, cfg->dma_dst_addr, cfg->dma_cnt);
}
if (cfg->start_immediately) {
return I2S_Start();
}
return E_NO_ERROR;
}
int I2S_Shutdown(void)
{
MXC_SPIMSS->ctrl = 0;
MXC_SPIMSS->i2s_ctrl = 0;
MXC_SPIMSS->brg = 0;
MXC_SPIMSS->mod = 0;
MXC_SPIMSS->dma = 0;
SYS_I2S_Shutdown();
return DMA_ReleaseChannel(dma_channel);
}
int I2S_Mute(void)
{
MXC_SPIMSS->i2s_ctrl |= MXC_F_SPIMSS_I2S_CTRL_I2S_MUTE;
return E_NO_ERROR;
}
int I2S_Unmute(void)
{
MXC_SPIMSS->i2s_ctrl &= ~MXC_F_SPIMSS_I2S_CTRL_I2S_MUTE;
return E_NO_ERROR;
}
int I2S_Pause(void)
{
MXC_SPIMSS->i2s_ctrl |= MXC_F_SPIMSS_I2S_CTRL_I2S_PAUSE;
return E_NO_ERROR;
}
int I2S_Unpause(void)
{
MXC_SPIMSS->i2s_ctrl &= ~MXC_F_SPIMSS_I2S_CTRL_I2S_PAUSE;
return E_NO_ERROR;
}
int I2S_Stop(void)
{
MXC_SPIMSS->ctrl &= ~MXC_F_SPIMSS_CTRL_SPIEN;
MXC_SPIMSS->i2s_ctrl &= ~MXC_F_SPIMSS_I2S_CTRL_I2S_EN;
return DMA_Stop(dma_channel);
}
int I2S_Start(void)
{
MXC_SPIMSS->ctrl |= MXC_F_SPIMSS_CTRL_SPIEN;
MXC_SPIMSS->i2s_ctrl |= MXC_F_SPIMSS_I2S_CTRL_I2S_EN;
return DMA_Start(dma_channel);
}
int I2S_DMA_ClearFlags(void)
{
return DMA_ClearFlags(dma_channel);
}
int I2S_DMA_SetAddrCnt(void *src_addr, void *dst_addr, unsigned int count)
{
return DMA_SetSrcDstCnt(dma_channel, src_addr, dst_addr, count);
}
int I2S_DMA_SetReload(void *src_addr, void *dst_addr, unsigned int count)
{
return DMA_SetReload(dma_channel, src_addr, dst_addr, count);
}
@@ -0,0 +1,84 @@
/* *****************************************************************************
* Copyright (C) 2017 Maxim Integrated Products, Inc., All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Maxim Integrated
* Products, Inc. shall not be used except as stated in the Maxim Integrated
* Products, Inc. Branding Policy.
*
* The mere transfer of this software does not imply any licenses
* of trade secrets, proprietary technology, copyrights, patents,
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*
* $Date: 2018-12-18 15:37:22 -0600 (Tue, 18 Dec 2018) $
* $Revision: 40072 $
*
**************************************************************************** */
/* **** Includes **** */
#include <stdint.h>
#include <stdio.h>
#include "mxc_config.h"
#include "mxc_errors.h"
#include "icc_regs.h"
#include "icc.h"
static int ICC_Ready(void)
{
return (MXC_ICC->cache_ctrl & MXC_F_ICC_CACHE_CTRL_CACHE_RDY);
}
int ICC_ID(icc_cache_id_t cid)
{
switch (cid) {
case ICC_CACHE_ID_RELNUM:
return ((MXC_ICC->cache_id & MXC_F_ICC_CACHE_ID_RELNUM) >> MXC_F_ICC_CACHE_ID_RELNUM_POS);
case ICC_CACHE_ID_PARTNUM:
return ((MXC_ICC->cache_id & MXC_F_ICC_CACHE_ID_PARTNUM) >> MXC_F_ICC_CACHE_ID_PARTNUM_POS);
case ICC_CACHE_ID_CCHID:
return ((MXC_ICC->cache_id & MXC_F_ICC_CACHE_ID_CCHID) >> MXC_F_ICC_CACHE_ID_CCHID_POS);
default:
return E_BAD_PARAM;
}
}
void ICC_Enable(void)
{
// Invalidate cache and wait until ready
MXC_ICC->invalidate = 1;
while (!(ICC_Ready()));
// Enable Cache
MXC_ICC->cache_ctrl |= MXC_F_ICC_CACHE_CTRL_CACHE_EN;
}
void ICC_Disable(void)
{
// Disable Cache
MXC_ICC->cache_ctrl &= ~MXC_F_ICC_CACHE_CTRL_CACHE_EN;
}
void ICC_Flush(void)
{
ICC_Disable();
ICC_Enable();
}
@@ -0,0 +1,371 @@
/**
* @file lp.c
* @brief Low power functions
*/
/* ****************************************************************************
* Copyright (C) 2017 Maxim Integrated Products, Inc., All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Maxim Integrated
* Products, Inc. shall not be used except as stated in the Maxim Integrated
* Products, Inc. Branding Policy.
*
* The mere transfer of this software does not imply any licenses
* of trade secrets, proprietary technology, copyrights, patents,
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*
* $Date: 2019-10-07 11:05:30 -0500 (Mon, 07 Oct 2019) $
* $Revision: 47429 $
*
*************************************************************************** */
/***** Includes *****/
#include "lp.h"
#include "pwrseq_regs.h"
#include "mxc_errors.h"
#include "gcr_regs.h"
#include "mxc_config.h"
#include "mxc_sys.h"
#include "flc.h"
#include "tmr_utils.h"
/***** Functions *****/
void LP_ClearWakeStatus(void)
{
MXC_PWRSEQ->lp_wakefl = 0xFFFFFFFF;
/* These flags are slow to clear, so block until they do */
while(MXC_PWRSEQ->lp_wakefl & (MXC_PWRSEQ->lpwk_en));
}
void LP_EnableSRAM3(void)
{
MXC_PWRSEQ->lpmemsd &= ~MXC_F_PWRSEQ_LPMEMSD_SRAM3_OFF;
}
void LP_DisableSRAM3(void)
{
MXC_PWRSEQ->lpmemsd |= MXC_F_PWRSEQ_LPMEMSD_SRAM3_OFF;
}
void LP_EnableSRAM2(void)
{
MXC_PWRSEQ->lpmemsd &= ~MXC_F_PWRSEQ_LPMEMSD_SRAM2_OFF;
}
void LP_DisableSRAM2(void)
{
MXC_PWRSEQ->lpmemsd |= MXC_F_PWRSEQ_LPMEMSD_SRAM2_OFF;
}
void LP_EnableSRAM1(void)
{
MXC_PWRSEQ->lpmemsd &= ~MXC_F_PWRSEQ_LPMEMSD_SRAM1_OFF;
}
void LP_DisableSRAM1(void)
{
MXC_PWRSEQ->lpmemsd |= MXC_F_PWRSEQ_LPMEMSD_SRAM1_OFF;
}
void LP_EnableSRAM0(void)
{
MXC_PWRSEQ->lpmemsd &= ~MXC_F_PWRSEQ_LPMEMSD_SRAM0_OFF;
}
void LP_DisableSRAM0(void)
{
MXC_PWRSEQ->lpmemsd |= MXC_F_PWRSEQ_LPMEMSD_SRAM0_OFF;
}
void LP_EnableICacheLightSleep(void)
{
MXC_GCR->memckcn |= (MXC_F_GCR_MEMCKCN_ICACHELS);
}
void LP_DisableICacheLightSleep(void)
{
MXC_GCR->memckcn &= ~(MXC_F_GCR_MEMCKCN_ICACHELS);
}
void LP_EnableSysRAM3LightSleep(void)
{
MXC_GCR->memckcn |= (MXC_F_GCR_MEMCKCN_SYSRAM3LS);
}
void LP_DisableSysRAM3LightSleep(void)
{
MXC_GCR->memckcn &= ~(MXC_F_GCR_MEMCKCN_SYSRAM3LS);
}
void LP_EnableSysRAM2LightSleep(void)
{
MXC_GCR->memckcn |= (MXC_F_GCR_MEMCKCN_SYSRAM2LS);
}
void LP_DisableSysRAM2LightSleep(void)
{
MXC_GCR->memckcn &= ~(MXC_F_GCR_MEMCKCN_SYSRAM2LS);
}
void LP_EnableSysRAM1LightSleep(void)
{
MXC_GCR->memckcn |= (MXC_F_GCR_MEMCKCN_SYSRAM1LS);
}
void LP_DisableSysRAM1LightSleep(void)
{
MXC_GCR->memckcn &= ~(MXC_F_GCR_MEMCKCN_SYSRAM1LS);
}
void LP_EnableSysRAM0LightSleep(void)
{
MXC_GCR->memckcn |= (MXC_F_GCR_MEMCKCN_SYSRAM0LS);
}
void LP_DisableSysRAM0LightSleep(void)
{
MXC_GCR->memckcn &= ~(MXC_F_GCR_MEMCKCN_SYSRAM0LS);
}
void LP_EnableRTCAlarmWakeup(void)
{
MXC_GCR->pm |= MXC_F_GCR_PM_RTCWKEN;
}
void LP_DisableRTCAlarmWakeup(void)
{
MXC_GCR->pm &= ~MXC_F_GCR_PM_RTCWKEN;
}
void LP_EnableGPIOWakeup(const gpio_cfg_t *wu_pins)
{
MXC_GCR->pm |= MXC_F_GCR_PM_GPIOWKEN;
switch(wu_pins->port)
{
case 0: MXC_PWRSEQ->lpwk_en |= wu_pins->mask; break;
}
}
void LP_DisableGPIOWakeup(const gpio_cfg_t *wu_pins)
{
switch(wu_pins->port)
{
case 0: MXC_PWRSEQ->lpwk_en &= ~wu_pins->mask; break;
}
if(MXC_PWRSEQ->lpwk_en == 0)
{
MXC_GCR->pm &= ~MXC_F_GCR_PM_GPIOWKEN;
}
}
void LP_EnterSleepMode(void)
{
// Clear SLEEPDEEP bit
SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk;
// Go into Sleep mode and wait for an interrupt to wake the processor
__WFI();
}
void LP_EnterDeepSleepMode(void)
{
// Set SLEEPDEEP bit
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
// Auto-powerdown 96 MHz oscillator when in deep sleep
MXC_GCR->pm |= MXC_F_GCR_PM_HIRCPD;
// Go into Deepsleep mode and wait for an interrupt to wake the processor
__WFI();
}
void LP_EnterBackupMode(void)
{
MXC_GCR->pm &= ~MXC_F_GCR_PM_MODE;
MXC_GCR->pm |= MXC_S_GCR_PM_MODE_BACKUP;
while(1);
}
void LP_EnterShutdownMode(void)
{
MXC_GCR->pm &= ~MXC_F_GCR_PM_MODE;
MXC_GCR->pm |= MXC_S_GCR_PM_MODE_SHUTDOWN;
while(1);
}
void LP_SetOperatingVoltage(lp_ovr_t ovr)
{
uint32_t div;
//Set flash wait state for any clock so its not to low after clock changes.
MXC_GCR->memckcn = (MXC_GCR->memckcn & ~(MXC_F_GCR_MEMCKCN_FWS)) | (0x5UL << MXC_F_GCR_MEMCKCN_FWS_POS);
//set the OVR bits
MXC_PWRSEQ->lp_ctrl &= ~(MXC_F_PWRSEQ_LP_CTRL_OVR);
MXC_PWRSEQ->lp_ctrl |= ovr;
//Set LVE bit
if(ovr == LP_OVR_0_9){
MXC_FLC->cn |= MXC_F_FLC_CN_LVE;
}
else{
MXC_FLC->cn &= ~(MXC_F_FLC_CN_LVE);
}
// Update SystemCoreClock variable
SystemCoreClockUpdate();
// Get the clock divider
div = (MXC_GCR->clkcn & MXC_F_GCR_CLKCN_PSC) >> MXC_F_GCR_CLKCN_PSC_POS;
//Set Flash Wait States
if(ovr == LP_OVR_0_9){
if(div == 0){
MXC_GCR->memckcn = (MXC_GCR->memckcn & ~(MXC_F_GCR_MEMCKCN_FWS)) | (0x2UL << MXC_F_GCR_MEMCKCN_FWS_POS);
} else{
MXC_GCR->memckcn = (MXC_GCR->memckcn & ~(MXC_F_GCR_MEMCKCN_FWS)) | (0x1UL << MXC_F_GCR_MEMCKCN_FWS_POS);
}
} else if( ovr == LP_OVR_1_0){
if(div == 0){
MXC_GCR->memckcn = (MXC_GCR->memckcn & ~(MXC_F_GCR_MEMCKCN_FWS)) | (0x2UL << MXC_F_GCR_MEMCKCN_FWS_POS);
} else{
MXC_GCR->memckcn = (MXC_GCR->memckcn & ~(MXC_F_GCR_MEMCKCN_FWS)) | (0x1UL << MXC_F_GCR_MEMCKCN_FWS_POS);
}
} else {
if(div == 0){
MXC_GCR->memckcn = (MXC_GCR->memckcn & ~(MXC_F_GCR_MEMCKCN_FWS)) | (0x4UL << MXC_F_GCR_MEMCKCN_FWS_POS);
} else if(div == 1){
MXC_GCR->memckcn = (MXC_GCR->memckcn & ~(MXC_F_GCR_MEMCKCN_FWS)) | (0x2UL << MXC_F_GCR_MEMCKCN_FWS_POS);
} else{
MXC_GCR->memckcn = (MXC_GCR->memckcn & ~(MXC_F_GCR_MEMCKCN_FWS)) | (0x1UL << MXC_F_GCR_MEMCKCN_FWS_POS);
}
}
}
void LP_EnableSRamRet0(void){
MXC_PWRSEQ->lp_ctrl |= MXC_F_PWRSEQ_LP_CTRL_RAMRET_SEL0;
}
void LP_DisableSRamRet0(void){
MXC_PWRSEQ->lp_ctrl &= ~MXC_F_PWRSEQ_LP_CTRL_RAMRET_SEL0;
}
void LP_EnableSRamRet1(void){
MXC_PWRSEQ->lp_ctrl |= MXC_F_PWRSEQ_LP_CTRL_RAMRET_SEL1;
}
void LP_DisableSRamRet1(void){
MXC_PWRSEQ->lp_ctrl &= ~MXC_F_PWRSEQ_LP_CTRL_RAMRET_SEL1;
}
void LP_EnableSRamRet2(void){
MXC_PWRSEQ->lp_ctrl |= MXC_F_PWRSEQ_LP_CTRL_RAMRET_SEL2;
}
void LP_DisableSRamRet2(void){
MXC_PWRSEQ->lp_ctrl &= ~MXC_F_PWRSEQ_LP_CTRL_RAMRET_SEL2;
}
void LP_EnableSRamRet3(void){
MXC_PWRSEQ->lp_ctrl |= MXC_F_PWRSEQ_LP_CTRL_RAMRET_SEL3;
}
void LP_DisableSRamRet3(void){
MXC_PWRSEQ->lp_ctrl &= ~MXC_F_PWRSEQ_LP_CTRL_RAMRET_SEL3;
}
void LP_EnableBlockDetect(void){
MXC_PWRSEQ->lp_ctrl &= ~MXC_F_PWRSEQ_LP_CTRL_VCORE_DET_BYPASS;
}
void LP_DisableBlockDetect(void){
MXC_PWRSEQ->lp_ctrl |= MXC_F_PWRSEQ_LP_CTRL_VCORE_DET_BYPASS;
}
void LP_EnableRamRetReg(void){
MXC_PWRSEQ->lp_ctrl |= MXC_F_PWRSEQ_LP_CTRL_RETREG_EN;
}
void LP_DisableRamRetReg(void){
MXC_PWRSEQ->lp_ctrl &= ~MXC_F_PWRSEQ_LP_CTRL_RETREG_EN;
}
void LP_EnableFastWk(void){
MXC_PWRSEQ->lp_ctrl |= MXC_F_PWRSEQ_LP_CTRL_FAST_WK_EN;
}
void LP_DisableFastWk(void){
MXC_PWRSEQ->lp_ctrl &= ~MXC_F_PWRSEQ_LP_CTRL_FAST_WK_EN;
}
void LP_EnableBandGap(void){
MXC_PWRSEQ->lp_ctrl &= ~MXC_F_PWRSEQ_LP_CTRL_BG_OFF;
}
void LP_DisableBandGap(void){
MXC_PWRSEQ->lp_ctrl |= MXC_F_PWRSEQ_LP_CTRL_BG_OFF;
}
void LP_EnableVCorePORSignal(void){
MXC_PWRSEQ->lp_ctrl &= ~MXC_F_PWRSEQ_LP_CTRL_VCORE_POR_DIS;
}
void LP_DisableVCorePORSignal(void){
MXC_PWRSEQ->lp_ctrl |= MXC_F_PWRSEQ_LP_CTRL_VCORE_POR_DIS;
}
void LP_EnableLDO(void){
MXC_PWRSEQ->lp_ctrl &= ~MXC_F_PWRSEQ_LP_CTRL_LDO_DIS;
}
void LP_DisableLDO(void){
MXC_PWRSEQ->lp_ctrl |= MXC_F_PWRSEQ_LP_CTRL_LDO_DIS;
}
void LP_EnableVCoreSVM(void){
MXC_PWRSEQ->lp_ctrl &= ~MXC_F_PWRSEQ_LP_CTRL_VCORE_SVM_DIS;
}
void LP_DisableVCoreSVM(void){
MXC_PWRSEQ->lp_ctrl |= MXC_F_PWRSEQ_LP_CTRL_VCORE_SVM_DIS;
}
void LP_EnableVDDIOPorMonitoF(void){
MXC_PWRSEQ->lp_ctrl &= ~MXC_F_PWRSEQ_LP_CTRL_VDDIO_POR_DIS;
}
void LP_DisableVDDIOPorMonitor(void){
MXC_PWRSEQ->lp_ctrl |= MXC_F_PWRSEQ_LP_CTRL_VDDIO_POR_DIS;
}
@@ -0,0 +1,50 @@
/* *****************************************************************************
* Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Maxim Integrated
* Products, Inc. shall not be used except as stated in the Maxim Integrated
* Products, Inc. Branding Policy.
*
* The mere transfer of this software does not imply any licenses
* of trade secrets, proprietary technology, copyrights, patents,
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*
* $Date: 2018-08-09 18:45:02 -0500 (Thu, 09 Aug 2018) $
* $Revision: 36818 $
*
*************************************************************************** */
/* **** Includes **** */
#include "mxc_config.h"
/* **** Definitions **** */
/* **** Globals *****/
/* **** Functions **** */
/* ************************************************************************** */
__weak void mxc_assert(const char *expr, const char *file, int line)
{
while (1) {}
}
@@ -0,0 +1,179 @@
/* *****************************************************************************
* Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Maxim Integrated
* Products, Inc. shall not be used except as stated in the Maxim Integrated
* Products, Inc. Branding Policy.
*
* The mere transfer of this software does not imply any licenses
* of trade secrets, proprietary technology, copyrights, patents,
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*
* $Id: mxc_delay.c 36202 2018-07-16 21:06:02Z michael.bayern $
*
*************************************************************************** */
/* **** Includes **** */
#include <stdint.h>
#include "mxc_config.h"
#include "mxc_delay.h"
/* **** File Scope Variables **** */
static uint32_t ctrl_save;
static volatile uint64_t compare_value = 0;
static volatile uint64_t curr_value;
static volatile uint32_t reload;
static void mxc_delay_init(unsigned long us);
extern void SysTick_Handler(void);
/* ************************************************************************** */
__weak void SysTick_Handler(void)
{
mxc_delay_handler();
}
/* ************************************************************************** */
void mxc_delay_handler(void)
{
// Check and clear overflow flag
if (SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk) {
// Is a delay in progress?
if(compare_value != 0) {
curr_value += reload;
if(curr_value >= compare_value) {
mxc_delay_stop();
}
}
}
}
/* ************************************************************************** */
static void mxc_delay_init(unsigned long us)
{
uint32_t starttick, ticks;
// Record the current tick value and clear the overflow flag
starttick = SysTick->VAL;
// Save the state of control register (and clear the overflow flag)
ctrl_save = SysTick->CTRL & ~SysTick_CTRL_COUNTFLAG_Msk;
// If the SysTick is not running, configure and start it
if (!(SysTick->CTRL & SysTick_CTRL_ENABLE_Msk)) {
SysTick->LOAD = SysTick_LOAD_RELOAD_Msk;
SysTick->VAL = SysTick_VAL_CURRENT_Msk;
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk;
starttick = SysTick_VAL_CURRENT_Msk;
reload = SysTick_LOAD_RELOAD_Msk + 1;
} else {
reload = SysTick->LOAD + 1; // get the current reload value
}
// Calculate the total number of ticks to delay
ticks = (uint32_t)(((uint64_t)us * (uint64_t)SystemCoreClock) / 1000000);
compare_value = ticks + (reload - starttick);
curr_value = 0;
if (!(SysTick->CTRL & SysTick_CTRL_ENABLE_Msk)) {
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
}
}
/* ************************************************************************** */
int mxc_delay_start(unsigned long us)
{
// Check if timeout currently ongoing
if (compare_value != 0) {
return E_BUSY;
}
// Check if there is nothing to do
if (us == 0) {
return E_NO_ERROR;
}
// Calculate the necessary delay and start the timer
mxc_delay_init(us);
// Enable SysTick interrupt if necessary
if (compare_value != 0) {
SysTick->CTRL |= SysTick_CTRL_TICKINT_Msk;
}
return E_NO_ERROR;
}
/* ************************************************************************** */
int mxc_delay_check(void)
{
// Check if timeout currently ongoing
if (compare_value == 0) {
return E_NO_ERROR;
}
if((curr_value + (reload - SysTick->VAL)) >= compare_value) {
mxc_delay_stop();
return E_NO_ERROR;
}
return E_BUSY;
}
/* ************************************************************************** */
void mxc_delay_stop(void)
{
SysTick->CTRL = ctrl_save;
compare_value = 0;
}
/* ************************************************************************** */
int mxc_delay(unsigned long us)
{
// Check if timeout currently ongoing
if (compare_value != 0) {
return E_BUSY;
}
// Check if there is nothing to do
if (us == 0) {
return E_NO_ERROR;
}
// Calculate the necessary delay and start the timer
mxc_delay_init(us);
// Wait until the total number of ticks exceeds the compare value.
while ((curr_value + (reload - SysTick->VAL)) < compare_value) {
// If SysTick interrupts are enabled, COUNTFLAG will never be set here and
// curr_value will be incremented in the ISR. If SysTick interrupts are
// disabled, curr_value is incremented here.
if (SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk) {
curr_value += reload;
}
}
mxc_delay_stop();
return E_NO_ERROR;
}
@@ -0,0 +1,85 @@
/* ****************************************************************************
* Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Maxim Integrated
* Products, Inc. shall not be used except as stated in the Maxim Integrated
* Products, Inc. Branding Policy.
*
* The mere transfer of this software does not imply any licenses
* of trade secrets, proprietary technology, copyrights, patents,
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*
* $Date: 2018-12-18 15:37:22 -0600 (Tue, 18 Dec 2018) $
* $Revision: 40072 $
*
*************************************************************************** */
/* Define to prevent redundant inclusion */
#ifndef _MXC_LOCK_H_
#define _MXC_LOCK_H_
/* **** Includes **** */
#include "mxc_config.h"
#include "mxc_lock.h"
#ifdef __cplusplus
extern "C" {
#endif
#if defined ( __ICCARM__ )
#define MXC_LOCK_CAST unsigned int volatile *
#else
#define MXC_LOCK_CAST volatile unsigned long *
#endif
/* ************************************************************************** */
int mxc_get_lock(uint32_t *lock, uint32_t value)
{
do {
// Return if the lock is taken by a different thread
if(__LDREXW((MXC_LOCK_CAST)lock) != 0) {
return E_BUSY;
}
// Attempt to take the lock
} while(__STREXW(value, (MXC_LOCK_CAST)lock) != 0);
// Do not start any other memory access until memory barrier is complete
__DMB();
return E_NO_ERROR;
}
/* ************************************************************************** */
void mxc_free_lock(uint32_t *lock)
{
// Ensure memory operations complete before releasing lock
__DMB();
*lock = 0;
}
#ifdef __cplusplus
}
#endif
#endif /* _MXC_LOCK_H_ */
@@ -0,0 +1,79 @@
/**
* @file mxc_pins.c
* @brief This file contains constant pin configurations for the peripherals.
*/
/* *****************************************************************************
* Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Maxim Integrated
* Products, Inc. shall not be used except as stated in the Maxim Integrated
* Products, Inc. Branding Policy.
*
* The mere transfer of this software does not imply any licenses
* of trade secrets, proprietary technology, copyrights, patents,
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*
* $Date: 2018-12-18 15:37:22 -0600 (Tue, 18 Dec 2018) $
* $Revision: 40072 $
*
**************************************************************************** */
/* **** Includes **** */
#include "gpio.h"
#include "mxc_config.h"
/**
* @ingroup MXC_pins
* @{
*/
/* **** TIMER pins **** */
const gpio_cfg_t gpio_cfg_tmr0 = { PORT_0, PIN_3, GPIO_FUNC_ALT3, GPIO_PAD_NONE };
/* **** UART pins **** */
const gpio_cfg_t gpio_cfg_uart0rtscts = { PORT_0, (PIN_6 | PIN_7), GPIO_FUNC_ALT2, GPIO_PAD_NONE };
const gpio_cfg_t gpio_cfg_uart0a = { PORT_0, (PIN_4 | PIN_5), GPIO_FUNC_ALT2, GPIO_PAD_NONE };
const gpio_cfg_t gpio_cfg_uart1rtscts = { PORT_0, (PIN_12 | PIN_13), GPIO_FUNC_ALT2, GPIO_PAD_NONE };
const gpio_cfg_t gpio_cfg_uart1a = { PORT_0, (PIN_10 | PIN_11), GPIO_FUNC_ALT2, GPIO_PAD_NONE };
const gpio_cfg_t gpio_cfg_uart1b = { PORT_0, (PIN_0 | PIN_1), GPIO_FUNC_ALT3, GPIO_PAD_NONE };
const gpio_cfg_t gpio_cfg_uart1c = { PORT_0, (PIN_6 | PIN_7), GPIO_FUNC_ALT3, GPIO_PAD_NONE };
/* **** I2C pins **** */
const gpio_cfg_t gpio_cfg_i2c0 = { PORT_0, (PIN_8 | PIN_9), GPIO_FUNC_ALT1, GPIO_PAD_PULL_UP };
const gpio_cfg_t gpio_cfg_i2c1 = { PORT_0, (PIN_2 | PIN_3), GPIO_FUNC_ALT1, GPIO_PAD_PULL_UP };
/* **** SPI/I2S pins **** */
const gpio_cfg_t gpio_cfg_spi17y = { PORT_0, (PIN_4 | PIN_5 | PIN_6 | PIN_7), GPIO_FUNC_ALT1, GPIO_PAD_NONE }; // SPI0A
const gpio_cfg_t gpio_cfg_spimss1a = { PORT_0, (PIN_10 | PIN_11 | PIN_12 | PIN_13) , GPIO_FUNC_ALT1, GPIO_PAD_NONE }; // SPI1A
const gpio_cfg_t gpio_cfg_spimss1b = { PORT_0, (PIN_0 | PIN_1 | PIN_2 | PIN_3 ) , GPIO_FUNC_ALT2, GPIO_PAD_NONE }; // SPI1B
const gpio_cfg_t gpio_cfg_i2s1a = { PORT_0, (PIN_10 | PIN_11 | PIN_12 | PIN_13) , GPIO_FUNC_ALT1, GPIO_PAD_NONE }; // same port as SPI1A
const gpio_cfg_t gpio_cfg_i2s1b = { PORT_0, (PIN_0 | PIN_1 | PIN_2 | PIN_3 ) , GPIO_FUNC_ALT2, GPIO_PAD_NONE }; // same port as SPI1B
/* **** SWD pins **** */
const gpio_cfg_t gpio_cfg_swd = { PORT_0, (PIN_0 | PIN_1 | PIN_2 | PIN_3 ) , GPIO_FUNC_ALT1, GPIO_PAD_NONE };
/* **** RTC pins **** */
const gpio_cfg_t gpio_cfg_rtc = { PORT_0, PIN_2, GPIO_FUNC_ALT3, GPIO_PAD_NONE };
/**@} end of ingroup MXC_pins*/
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,84 @@
/* *****************************************************************************
* Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Maxim Integrated
* Products, Inc. shall not be used except as stated in the Maxim Integrated
* Products, Inc. Branding Policy.
*
* The mere transfer of this software does not imply any licenses
* of trade secrets, proprietary technology, copyrights, patents,
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*
* $Date: 2019-06-05 16:53:29 -0500 (Wed, 05 Jun 2019) $
* $Revision: 43696 $
*
**************************************************************************** */
#include "mxc_config.h"
#include <string.h>
#include "nvic_table.h"
#if !defined (NVIC_USER_IRQ_OFFSET)
#define NVIC_USER_IRQ_OFFSET 16 /**! Offset for device specific IRQs */
#endif
/* RAM vector_table needs to be aligned with the size of the vector table */
#if defined ( __ICCARM__ )
#pragma data_alignment = 512
#else
__attribute__((aligned(512)))
#endif
static void (*ramVectorTable[MXC_IRQ_COUNT])(void);
void NVIC_SetRAM(void)
{
#if defined (__ICCARM__)
extern void (* const __isr_vector[])(void);
#else
/* should be defined in starup_<device>.S */
extern uint32_t __isr_vector[97];
#endif
memcpy(&ramVectorTable, &__isr_vector, sizeof(ramVectorTable));
SCB->VTOR = (uint32_t)&ramVectorTable;
}
void NVIC_SetVector(IRQn_Type irqn, void(*irq_handler)(void))
{
int index = irqn + 16; /* offset for externals */
/* If not copied, do copy */
if (SCB->VTOR != (uint32_t)&ramVectorTable) {
NVIC_SetRAM();
}
ramVectorTable[index] = irq_handler;
NVIC_EnableIRQ(irqn);
}
uint32_t NVIC_GetVector(IRQn_Type irqn)
{
uint32_t *vectors = (uint32_t *)SCB->VTOR;
return vectors[(int32_t)irqn + NVIC_USER_IRQ_OFFSET];
}
@@ -0,0 +1,419 @@
/* ****************************************************************************
* Copyright (C) 2017 Maxim Integrated Products, Inc., All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Maxim Integrated
* Products, Inc. shall not be used except as stated in the Maxim Integrated
* Products, Inc. Branding Policy.
*
* The mere transfer of this software does not imply any licenses
* of trade secrets, proprietary technology, copyrights, patents,
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*
*
**************************************************************************** */
#include "mxc_config.h"
#include "rtc_regs.h"
#include "rtc.h"
#include "mxc_sys.h"
#include "mxc_delay.h"
#include "gpio_regs.h"
#include "mxc_errors.h"
#if TARGET == 32650
#include "pwrseq_regs.h"
#endif
#define RTC_CTRL_RESET_DEFAULT (0x0000UL)
#define RTC_IS_BUSY (MXC_RTC->ctrl & MXC_F_RTC_CTRL_BUSY)
#define RTC_IS_ENABLED (MXC_RTC->ctrl & MXC_F_RTC_CTRL_RTCE)
#define BUSY_TIMEOUT 1000 // Timeout counts for the Busy bit
// *****************************************************************************
int RTC_EnableTimeofdayInterrupt(mxc_rtc_regs_t *rtc)
{
if (RTC_CheckBusy()) {
return E_BUSY;
}
rtc->ctrl |= MXC_F_RTC_CTRL_ADE; // Enable Time-of-day Interrupt
return E_SUCCESS;
}
// *****************************************************************************
int RTC_DisableTimeofdayInterrupt(mxc_rtc_regs_t *rtc)
{
if (RTC_CheckBusy()) {
return E_BUSY;
}
rtc->ctrl &= ~MXC_F_RTC_CTRL_ADE; // Disable Time-of-day Interrupt
if (RTC_CheckBusy()) {
return E_BUSY;
}
return E_SUCCESS;
}
// *****************************************************************************
int RTC_EnableSubsecondInterrupt(mxc_rtc_regs_t *rtc)
{
if (RTC_CheckBusy()) {
return E_BUSY;
}
rtc->ctrl |= MXC_F_RTC_CTRL_ASE; // Enable Sub-Second Interrupt
return E_SUCCESS;
}
// *****************************************************************************
int RTC_DisableSubsecondInterrupt(mxc_rtc_regs_t *rtc)
{
if (RTC_CheckBusy()) {
return E_BUSY;
}
rtc->ctrl &= ~MXC_F_RTC_CTRL_ASE; // Alarm Sub-Second Interrupt disabled
if (RTC_CheckBusy()) {
return E_BUSY;
}
return E_SUCCESS;
}
// *****************************************************************************
int RTC_SetTimeofdayAlarm(mxc_rtc_regs_t *rtc, uint32_t ras)
{
// ras can only be written if BUSY = 0 & (RTCE = 0 or ADE = 0);
if(RTC_DisableTimeofdayInterrupt(rtc) == E_BUSY) {
return E_BUSY;
}
if (RTC_CheckBusy()) {
return E_BUSY;
}
rtc->ras = (ras << MXC_F_RTC_RAS_RAS_POS) & MXC_F_RTC_RAS_RAS;
if(RTC_EnableTimeofdayInterrupt(rtc) == E_BUSY) {
return E_BUSY;
}
return E_SUCCESS;
}
// *****************************************************************************
int RTC_SetSubsecondAlarm(mxc_rtc_regs_t *rtc, uint32_t rssa)
{
// ras can only be written if BUSY = 0 & (RTCE = 0 or ASE = 0);
if(RTC_DisableSubsecondInterrupt(rtc) == E_BUSY) {
return E_BUSY;
}
if (RTC_CheckBusy()) {
return E_BUSY;
}
rtc->rssa = (rssa << MXC_F_RTC_RSSA_RSSA_POS) & MXC_F_RTC_RSSA_RSSA;
if(RTC_EnableSubsecondInterrupt(rtc) == E_BUSY) {
return E_BUSY;
}
return E_SUCCESS;
}
// *****************************************************************************
int RTC_EnableRTCE(mxc_rtc_regs_t *rtc)
{
if (RTC_CheckBusy()) {
return E_BUSY;
}
rtc->ctrl |= MXC_F_RTC_CTRL_WE; // Allow writing to registers
if (RTC_CheckBusy()) {
return E_BUSY;
}
// Can only write if WE=1 and BUSY=0
rtc->ctrl |= MXC_F_RTC_CTRL_RTCE; // setting RTCE = 1
if (RTC_CheckBusy()) {
return E_BUSY;
}
rtc->ctrl &= ~MXC_F_RTC_CTRL_WE; // Prevent Writing...
return E_SUCCESS;
}
// *****************************************************************************
int RTC_DisableRTCE(mxc_rtc_regs_t *rtc)
{
if (RTC_CheckBusy()) {
return E_BUSY;
}
rtc->ctrl |= MXC_F_RTC_CTRL_WE; // Allow writing to registers
if (RTC_CheckBusy()) {
return E_BUSY;
}
// Can only write if WE=1 and BUSY=0
rtc->ctrl &= ~MXC_F_RTC_CTRL_RTCE; // setting RTCE = 0
if (RTC_CheckBusy()) {
return E_BUSY;
}
rtc->ctrl &= ~MXC_F_RTC_CTRL_WE; // Prevent Writing...
return E_SUCCESS;
}
// *****************************************************************************
int RTC_Init(mxc_rtc_regs_t *rtc, uint32_t sec, uint8_t ssec, sys_cfg_rtc_t *sys_cfg)
{
#if((TARGET == 32650) || (TARGET == 32660))
SYS_ClockEnable_X32K(sys_cfg);
#else
SYS_RTCClockEnable(sys_cfg);
#endif
if (RTC_CheckBusy()) {
return E_BUSY;
}
rtc->ctrl = MXC_F_RTC_CTRL_WE; // Allow Writes
if (RTC_CheckBusy()) {
return E_BUSY;
}
rtc->ctrl = RTC_CTRL_RESET_DEFAULT; // Start with a Clean Register
if (RTC_CheckBusy()) {
return E_BUSY;
}
rtc->ctrl |= MXC_F_RTC_CTRL_WE; // Set Write Enable, allow writing to reg.
if (RTC_CheckBusy()) {
return E_BUSY;
}
rtc->ssec = ssec;
if (RTC_CheckBusy()) {
return E_BUSY;
}
rtc->sec = sec;
if (RTC_CheckBusy()) {
return E_BUSY;
}
rtc->ctrl &= ~MXC_F_RTC_CTRL_WE; // Prevent Writing...
return E_SUCCESS;
}
// *****************************************************************************
int RTC_SquareWave(mxc_rtc_regs_t *rtc, rtc_sqwave_en_t sqe, rtc_freq_sel_t ft,
rtc_osc_mode_t x32kmd, const sys_cfg_rtc_t* sys_cfg)
{
SYS_RTC_SqwavInit(sys_cfg); // Set the Output pins for the squarewave.
if (RTC_CheckBusy()) {
return E_BUSY;
}
rtc->ctrl |= MXC_F_RTC_CTRL_WE; // Allow writing to registers
if (RTC_CheckBusy()) {
return E_BUSY;
}
if (sqe == SQUARE_WAVE_ENABLED) {
if (ft == F_32KHZ){ // if 32KHz output is selected...
rtc->oscctrl |= MXC_F_RTC_OSCCTRL_OUT32K; // Enable 32KHz wave
if (RTC_CheckBusy()) {
return E_BUSY;
}
rtc->ctrl |= MXC_F_RTC_CTRL_SQE; // Enable output on the pin
} else { // if 1Hz, 512Hz, 4KHz output is selected
rtc->oscctrl &= ~MXC_F_RTC_OSCCTRL_OUT32K; // Must make sure that the 32KHz is disabled
if (RTC_CheckBusy()) {
return E_BUSY;
}
rtc->ctrl &= ~(MXC_F_RTC_CTRL_FT | MXC_F_RTC_CTRL_X32KMD);
if (RTC_CheckBusy()) {
return E_BUSY;
}
rtc->ctrl |= (MXC_F_RTC_CTRL_SQE | ft | x32kmd); // Enable Sq. wave,
}
if (RTC_CheckBusy()) {
return E_BUSY;
}
rtc->ctrl |= MXC_F_RTC_CTRL_RTCE; // Enable Real Time Clock
} else { // Turn off the square wave output on the pin
rtc->oscctrl &= ~MXC_F_RTC_OSCCTRL_OUT32K; // Must make sure that the 32KHz is disabled
if (RTC_CheckBusy()) {
return E_BUSY;
}
rtc->ctrl &= ~MXC_F_RTC_CTRL_SQE; // No sq. wave output
}
if (RTC_CheckBusy()) {
return E_BUSY;
}
rtc->ctrl &= ~MXC_F_RTC_CTRL_WE; // Disable Writing to register
return E_SUCCESS;
}
// *****************************************************************************
int RTC_Trim(mxc_rtc_regs_t *rtc, int8_t trim)
{
if (RTC_CheckBusy()) {
return E_BUSY;
}
rtc->ctrl |= MXC_F_RTC_CTRL_WE;
if (RTC_CheckBusy()) {
return E_BUSY;
}
MXC_SETFIELD(rtc->trim, MXC_F_RTC_TRIM_TRIM, trim << MXC_F_RTC_TRIM_TRIM_POS);
if (RTC_CheckBusy()) {
return E_BUSY;
}
rtc->ctrl &= ~MXC_F_RTC_CTRL_WE; // Disable Writing to register
return E_SUCCESS;
}
// *****************************************************************************
int RTC_CheckBusy(void)
{
// Time-out transfer if it takes > BUSY_TIMEOUT microseconds
mxc_delay_start(MXC_DELAY_USEC(BUSY_TIMEOUT));
while (RTC_IS_BUSY) {
if (mxc_delay_check() != E_BUSY){
return E_BUSY;
}
}
mxc_delay_stop();
return E_SUCCESS;
}
// *****************************************************************************
int RTC_GetFlags(void)
{
return MXC_RTC->ctrl & (MXC_F_RTC_CTRL_ALDF | MXC_F_RTC_CTRL_ALSF | MXC_F_RTC_CTRL_RDY);
}
// *****************************************************************************
int RTC_ClearFlags(int flags)
{
if (RTC_CheckBusy()) {
return E_BUSY;
}
MXC_RTC->ctrl &= ~(flags & (MXC_F_RTC_CTRL_ALDF | MXC_F_RTC_CTRL_ALSF | MXC_F_RTC_CTRL_RDY));
return E_SUCCESS;
}
// *****************************************************************************
int RTC_GetSubSecond(void)
{
#if TARGET == 32650
int ssec;
if(ChipRevision > 0xA1){
ssec = ((MXC_PWRSEQ->lpcn >> 12)& 0xF00) | (MXC_RTC->ssec & 0xFF);
}else{
ssec = MXC_RTC->ssec;
}
return ssec;
#else
return MXC_RTC->ssec;
#endif
}
// *****************************************************************************
int RTC_GetSecond(void)
{
return MXC_RTC->sec;
}
// *****************************************************************************
int RTC_GetTime(uint32_t* sec, uint32_t* subsec)
{
uint32_t temp_sec;
do {
// Check if an update is about to happen.
if(!(MXC_RTC->ctrl & MXC_F_RTC_CTRL_RDY)) {
return E_BUSY;
}
// Read the seconds count.
temp_sec = RTC_GetSecond();
// Check if an update is about to happen.
if(!(MXC_RTC->ctrl & MXC_F_RTC_CTRL_RDY)) {
return E_BUSY;
}
// Read the sub-seconds count.
*subsec = RTC_GetSubSecond();
// Check if an update is about to happen.
if(!(MXC_RTC->ctrl & MXC_F_RTC_CTRL_RDY)) {
return E_BUSY;
}
// Read the seconds count.
*sec = RTC_GetSecond();
// Repeat until a steady state is reached.
} while (temp_sec != *sec);
return E_NO_ERROR;
}
// *****************************************************************************
int RTC_IsEnabled(void)
{
return RTC_IS_ENABLED;
}

Some files were not shown because too many files have changed in this diff Show More