mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-03-25 10:39:32 +08:00
[bsp] add new bsp for lpc824
This commit is contained in:
34
bsp/lpc824/Libraries/SConscript
Normal file
34
bsp/lpc824/Libraries/SConscript
Normal file
@@ -0,0 +1,34 @@
|
||||
# RT-Thread building script for component
|
||||
|
||||
Import('rtconfig')
|
||||
Import('RTT_ROOT')
|
||||
from building import *
|
||||
|
||||
cwd = GetCurrentDir()
|
||||
|
||||
src = Glob('peri_driver/*/*.c')
|
||||
src += Glob('common/board/*.c')
|
||||
src += Glob('common/chip/*.c')
|
||||
|
||||
# add for startup script
|
||||
if rtconfig.CROSS_TOOL == 'gcc':
|
||||
print "not gcc startup file"
|
||||
exit(0)
|
||||
elif rtconfig.CROSS_TOOL == 'keil':
|
||||
src += [cwd + '/common/startup/keil_startup_lpc82x.s']
|
||||
elif rtconfig.CROSS_TOOL == 'iar':
|
||||
src += [cwd + '/common/startup/iar_startup_lpc82x.s']
|
||||
|
||||
CPPPATH = [ cwd + '/peri_driver', cwd + '/common/board',
|
||||
cwd + '/common/chip', cwd + '/common/CMSIS']
|
||||
|
||||
if GetDepend(['RT_USING_BSP_CMSIS']):
|
||||
CPPPATH += [cwd + '/common/CMSIS/']
|
||||
elif GetDepend(['RT_USING_RTT_CMSIS']):
|
||||
CPPPATH += [RTT_ROOT + '/components/CMSIS/Include']
|
||||
|
||||
CPPDEFINES = ['CORE_M0PLUS']
|
||||
|
||||
group = DefineGroup('Libraries', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES=CPPDEFINES)
|
||||
|
||||
Return('group')
|
||||
734
bsp/lpc824/Libraries/common/CMSIS/cmsis_armcc.h
Normal file
734
bsp/lpc824/Libraries/common/CMSIS/cmsis_armcc.h
Normal file
File diff suppressed because it is too large
Load Diff
1800
bsp/lpc824/Libraries/common/CMSIS/cmsis_armcc_V6.h
Normal file
1800
bsp/lpc824/Libraries/common/CMSIS/cmsis_armcc_V6.h
Normal file
File diff suppressed because it is too large
Load Diff
914
bsp/lpc824/Libraries/common/CMSIS/core_cm0plus.h
Normal file
914
bsp/lpc824/Libraries/common/CMSIS/core_cm0plus.h
Normal file
File diff suppressed because it is too large
Load Diff
87
bsp/lpc824/Libraries/common/CMSIS/core_cmFunc.h
Normal file
87
bsp/lpc824/Libraries/common/CMSIS/core_cmFunc.h
Normal file
@@ -0,0 +1,87 @@
|
||||
/**************************************************************************//**
|
||||
* @file core_cmFunc.h
|
||||
* @brief CMSIS Cortex-M Core Function Access Header File
|
||||
* @version V4.30
|
||||
* @date 20. October 2015
|
||||
******************************************************************************/
|
||||
/* Copyright (c) 2009 - 2015 ARM LIMITED
|
||||
|
||||
All rights reserved.
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
- Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
- Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
- Neither the name of ARM nor the names of its contributors may be used
|
||||
to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
*
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#if defined ( __ICCARM__ )
|
||||
#pragma system_include /* treat file as system include file for MISRA check */
|
||||
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
|
||||
#pragma clang system_header /* treat file as system include file */
|
||||
#endif
|
||||
|
||||
#ifndef __CORE_CMFUNC_H
|
||||
#define __CORE_CMFUNC_H
|
||||
|
||||
|
||||
/* ########################### Core Function Access ########################### */
|
||||
/** \ingroup CMSIS_Core_FunctionInterface
|
||||
\defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions
|
||||
@{
|
||||
*/
|
||||
|
||||
/*------------------ RealView Compiler -----------------*/
|
||||
#if defined ( __CC_ARM )
|
||||
#include "cmsis_armcc.h"
|
||||
|
||||
/*------------------ ARM Compiler V6 -------------------*/
|
||||
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
|
||||
#include "cmsis_armcc_V6.h"
|
||||
|
||||
/*------------------ GNU Compiler ----------------------*/
|
||||
#elif defined ( __GNUC__ )
|
||||
#include "cmsis_gcc.h"
|
||||
|
||||
/*------------------ ICC Compiler ----------------------*/
|
||||
#elif defined ( __ICCARM__ )
|
||||
#include <cmsis_iar.h>
|
||||
|
||||
/*------------------ TI CCS Compiler -------------------*/
|
||||
#elif defined ( __TMS470__ )
|
||||
#include <cmsis_ccs.h>
|
||||
|
||||
/*------------------ 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.
|
||||
*/
|
||||
|
||||
/*------------------ COSMIC Compiler -------------------*/
|
||||
#elif defined ( __CSMC__ )
|
||||
#include <cmsis_csm.h>
|
||||
|
||||
#endif
|
||||
|
||||
/*@} end of CMSIS_Core_RegAccFunctions */
|
||||
|
||||
#endif /* __CORE_CMFUNC_H */
|
||||
87
bsp/lpc824/Libraries/common/CMSIS/core_cmInstr.h
Normal file
87
bsp/lpc824/Libraries/common/CMSIS/core_cmInstr.h
Normal file
@@ -0,0 +1,87 @@
|
||||
/**************************************************************************//**
|
||||
* @file core_cmInstr.h
|
||||
* @brief CMSIS Cortex-M Core Instruction Access Header File
|
||||
* @version V4.30
|
||||
* @date 20. October 2015
|
||||
******************************************************************************/
|
||||
/* Copyright (c) 2009 - 2015 ARM LIMITED
|
||||
|
||||
All rights reserved.
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
- Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
- Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
- Neither the name of ARM nor the names of its contributors may be used
|
||||
to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
*
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#if defined ( __ICCARM__ )
|
||||
#pragma system_include /* treat file as system include file for MISRA check */
|
||||
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
|
||||
#pragma clang system_header /* treat file as system include file */
|
||||
#endif
|
||||
|
||||
#ifndef __CORE_CMINSTR_H
|
||||
#define __CORE_CMINSTR_H
|
||||
|
||||
|
||||
/* ########################## Core Instruction Access ######################### */
|
||||
/** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface
|
||||
Access to dedicated instructions
|
||||
@{
|
||||
*/
|
||||
|
||||
/*------------------ RealView Compiler -----------------*/
|
||||
#if defined ( __CC_ARM )
|
||||
#include "cmsis_armcc.h"
|
||||
|
||||
/*------------------ ARM Compiler V6 -------------------*/
|
||||
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
|
||||
#include "cmsis_armcc_V6.h"
|
||||
|
||||
/*------------------ GNU Compiler ----------------------*/
|
||||
#elif defined ( __GNUC__ )
|
||||
#include "cmsis_gcc.h"
|
||||
|
||||
/*------------------ ICC Compiler ----------------------*/
|
||||
#elif defined ( __ICCARM__ )
|
||||
#include <cmsis_iar.h>
|
||||
|
||||
/*------------------ TI CCS Compiler -------------------*/
|
||||
#elif defined ( __TMS470__ )
|
||||
#include <cmsis_ccs.h>
|
||||
|
||||
/*------------------ 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.
|
||||
*/
|
||||
|
||||
/*------------------ COSMIC Compiler -------------------*/
|
||||
#elif defined ( __CSMC__ )
|
||||
#include <cmsis_csm.h>
|
||||
|
||||
#endif
|
||||
|
||||
/*@}*/ /* end of group CMSIS_Core_InstructionInterface */
|
||||
|
||||
#endif /* __CORE_CMINSTR_H */
|
||||
211
bsp/lpc824/Libraries/common/board/board_api.h
Normal file
211
bsp/lpc824/Libraries/common/board/board_api.h
Normal file
@@ -0,0 +1,211 @@
|
||||
/*
|
||||
* @brief Common board API functions
|
||||
*
|
||||
* @note
|
||||
* Copyright(C) NXP Semiconductors, 2013
|
||||
* All rights reserved.
|
||||
*
|
||||
* @par
|
||||
* Software that is described herein is for illustrative purposes only
|
||||
* which provides customers with programming information regarding the
|
||||
* LPC products. This software is supplied "AS IS" without any warranties of
|
||||
* any kind, and NXP Semiconductors and its licensor disclaim any and
|
||||
* all warranties, express or implied, including all implied warranties of
|
||||
* merchantability, fitness for a particular purpose and non-infringement of
|
||||
* intellectual property rights. NXP Semiconductors assumes no responsibility
|
||||
* or liability for the use of the software, conveys no license or rights under any
|
||||
* patent, copyright, mask work right, or any other intellectual property rights in
|
||||
* or to any products. NXP Semiconductors reserves the right to make changes
|
||||
* in the software without notification. NXP Semiconductors also makes no
|
||||
* representation or warranty that such application will be suitable for the
|
||||
* specified use without further testing or modification.
|
||||
*
|
||||
* @par
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation is hereby granted, under NXP Semiconductors' and its
|
||||
* licensor's relevant copyrights in the software, without fee, provided that it
|
||||
* is used in conjunction with NXP Semiconductors microcontrollers. This
|
||||
* copyright, permission, and disclaimer notice must appear in all copies of
|
||||
* this code.
|
||||
*/
|
||||
|
||||
#ifndef __BOARD_API_H_
|
||||
#define __BOARD_API_H_
|
||||
|
||||
#include "lpc_types.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @defgroup BOARD_COMMON_API BOARD: Common board functions
|
||||
* @ingroup BOARD_Common
|
||||
* This file contains common board definitions that are shared across
|
||||
* boards and devices. All of these functions do not need to be
|
||||
* implemented for a specific board, but if they are implemented, they
|
||||
* should use this API standard.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Setup and initialize hardware prior to call to main()
|
||||
* @return None
|
||||
* @note Board_SystemInit() is called prior to the application and sets up system
|
||||
* clocking, memory, and any resources needed prior to the application
|
||||
* starting.
|
||||
*/
|
||||
void Board_SystemInit(void);
|
||||
|
||||
/**
|
||||
* @brief Setup pin multiplexer per board schematics
|
||||
* @return None
|
||||
* @note Board_SetupMuxing() should be called from SystemInit() prior to application
|
||||
* main() is called. So that the PINs are set in proper state.
|
||||
*/
|
||||
void Board_SetupMuxing(void);
|
||||
|
||||
/**
|
||||
* @brief Setup system clocking
|
||||
* @return None
|
||||
* @note This sets up board clocking.
|
||||
*/
|
||||
void Board_SetupClocking(void);
|
||||
|
||||
/**
|
||||
* @brief Setup external system memory
|
||||
* @return None
|
||||
* @note This function is typically called after pin mux setup and clock setup and
|
||||
* sets up any external memory needed by the system (DRAM, SRAM, etc.). Not all
|
||||
* boards need this function.
|
||||
*/
|
||||
void Board_SetupExtMemory(void);
|
||||
|
||||
/**
|
||||
* @brief Set up and initialize all required blocks and functions related to the board hardware.
|
||||
* @return None
|
||||
*/
|
||||
void Board_Init(void);
|
||||
|
||||
/**
|
||||
* @brief Initializes board UART for output, required for printf redirection
|
||||
* @return None
|
||||
*/
|
||||
void Board_Debug_Init(void);
|
||||
|
||||
/**
|
||||
* @brief Sends a single character on the UART, required for printf redirection
|
||||
* @param ch : character to send
|
||||
* @return None
|
||||
*/
|
||||
void Board_UARTPutChar(char ch);
|
||||
|
||||
/**
|
||||
* @brief Sends a single character on the UART, automatic process '\n' -> '\r\n'
|
||||
* @param ch : character to send
|
||||
* @return None
|
||||
*/
|
||||
void Board_UARTPutTextChar(char ch);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Classic implementation of itoa -- integer to ASCII
|
||||
* @param value : value to convert
|
||||
* @param result : result string
|
||||
* @param base : output radix
|
||||
* @return result string or NULL
|
||||
*/
|
||||
char *Board_itoa(int value, char *result, int base);
|
||||
|
||||
/**
|
||||
* @brief Get a single character from the UART, required for scanf input
|
||||
* @return EOF if not character was received, or character value
|
||||
*/
|
||||
int Board_UARTGetChar(void);
|
||||
|
||||
/**
|
||||
* @brief Prints a string to the UART
|
||||
* @param str : Terminated string to output
|
||||
* @return None
|
||||
*/
|
||||
void Board_UARTPutSTR(const char *str);
|
||||
|
||||
/**
|
||||
* @brief Get if a key is down
|
||||
* @param keyIndex : The index of the key to detect
|
||||
* @return 1 = key is down , 0 = key is up
|
||||
*/
|
||||
uint32_t Board_Key_GetKeyDown(uint32_t keyIndex);
|
||||
|
||||
/**
|
||||
* @brief Sets the state of a board LED to on or off
|
||||
* @param LEDNumber : LED number to set state for
|
||||
* @param State : true for on, false for off
|
||||
* @return None
|
||||
*/
|
||||
void Board_LED_Set(uint8_t LEDNumber, bool State);
|
||||
|
||||
/**
|
||||
* @brief Returns the current state of a board LED
|
||||
* @param LEDNumber : LED number to set state for
|
||||
* @return true if the LED is on, otherwise false
|
||||
*/
|
||||
bool Board_LED_Test(uint8_t LEDNumber);
|
||||
|
||||
/**
|
||||
* @brief Toggles the current state of a board LED
|
||||
* @param LEDNumber : LED number to change state for
|
||||
* @return None
|
||||
*/
|
||||
void Board_LED_Toggle(uint8_t LEDNumber);
|
||||
|
||||
/**
|
||||
* @brief Turn on Board LCD Backlight
|
||||
* @param Intensity : Backlight intensity (0 = off, >=1 = on)
|
||||
* @return None
|
||||
* @note On boards where a GPIO is used to control backlight on/off state, a '0' or '1'
|
||||
* value will turn off or on the backlight. On some boards, a non-0 value will
|
||||
* control backlight intensity via a PWN. For PWM systems, the intensity value
|
||||
* is a percentage value between 0 and 100%.
|
||||
*/
|
||||
void Board_SetLCDBacklight(uint8_t Intensity);
|
||||
|
||||
/**
|
||||
* @brief Function prototype for a MS delay function. Board layers or example code may
|
||||
* define this function as needed.
|
||||
*/
|
||||
typedef void (*p_msDelay_func_t)(uint32_t);
|
||||
|
||||
/* The DEBUG* functions are selected based on system configuration.
|
||||
Code that uses the DEBUG* functions will have their I/O routed to
|
||||
the UART, semihosting, or nowhere. */
|
||||
#if defined(DEBUG_ENABLE)
|
||||
#if defined(DEBUG_SEMIHOSTING)
|
||||
#define DEBUGINIT()
|
||||
#define DEBUGOUT(...) printf(__VA_ARGS__)
|
||||
#define DEBUGSTR(str) printf(str)
|
||||
#define DEBUGIN() (int) EOF
|
||||
|
||||
#else
|
||||
#define DEBUGINIT() Board_Debug_Init()
|
||||
#define DEBUGOUT(...) printf(__VA_ARGS__)
|
||||
#define DEBUGSTR(str) Board_UARTPutSTR(str)
|
||||
#define DEBUGIN() Board_UARTGetChar()
|
||||
#endif /* defined(DEBUG_SEMIHOSTING) */
|
||||
|
||||
#else
|
||||
#define DEBUGINIT()
|
||||
#define DEBUGOUT(...)
|
||||
#define DEBUGSTR(str)
|
||||
#define DEBUGIN() (int) EOF
|
||||
#endif /* defined(DEBUG_ENABLE) */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __BOARD_API_H_ */
|
||||
284
bsp/lpc824/Libraries/common/board/board_lpc.c
Normal file
284
bsp/lpc824/Libraries/common/board/board_lpc.c
Normal file
@@ -0,0 +1,284 @@
|
||||
|
||||
/*
|
||||
* @brief NXP LPCXpresso LPC824 board file
|
||||
*
|
||||
* @note
|
||||
* Copyright(C) NXP Semiconductors, 2013
|
||||
* All rights reserved.
|
||||
*
|
||||
* @par
|
||||
* Software that is described herein is for illustrative purposes only
|
||||
* which provides customers with programming information regarding the
|
||||
* LPC products. This software is supplied "AS IS" without any warranties of
|
||||
* any kind, and NXP Semiconductors and its licensor disclaim any and
|
||||
* all warranties, express or implied, including all implied warranties of
|
||||
* merchantability, fitness for a particular purpose and non-infringement of
|
||||
* intellectual property rights. NXP Semiconductors assumes no responsibility
|
||||
* or liability for the use of the software, conveys no license or rights under any
|
||||
* patent, copyright, mask work right, or any other intellectual property rights in
|
||||
* or to any products. NXP Semiconductors reserves the right to make changes
|
||||
* in the software without notification. NXP Semiconductors also makes no
|
||||
* representation or warranty that such application will be suitable for the
|
||||
* specified use without further testing or modification.
|
||||
*
|
||||
* @par
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation is hereby granted, under NXP Semiconductors' and its
|
||||
* licensor's relevant copyrights in the software, without fee, provided that it
|
||||
* is used in conjunction with NXP Semiconductors microcontrollers. This
|
||||
* copyright, permission, and disclaimer notice must appear in all copies of
|
||||
* this code.
|
||||
*/
|
||||
|
||||
// Must define _BOARD_C_ before ANY include
|
||||
#define _BOARD_C_
|
||||
|
||||
#include "board_lpc.h"
|
||||
#include "string.h"
|
||||
#include <stdint.h>
|
||||
/*****************************************************************************
|
||||
* Private types/enumerations/variables
|
||||
****************************************************************************/
|
||||
|
||||
#define BOARD_LED_CNT 8
|
||||
|
||||
/*****************************************************************************
|
||||
* Public types/enumerations/variables
|
||||
****************************************************************************/
|
||||
|
||||
/* System oscillator rate and clock rate on the CLKIN pin */
|
||||
const uint32_t OscRateIn = MAIN_OSC_XTAL_FREQ_HZ;
|
||||
const uint32_t ExtRateIn = EXT_CLOCK_IN_FREQ_HZ;
|
||||
|
||||
/*****************************************************************************
|
||||
* Private functions
|
||||
****************************************************************************/
|
||||
static void Board_Key_Init(void)
|
||||
{
|
||||
int i;
|
||||
LPC_IOCON_T *pIOCON = LPC_IOCON;
|
||||
for (i = 0; i < BOARD_KEY_CNT; i++) {
|
||||
Chip_GPIO_PinSetDIR(LPC_GPIO_PORT, 0, cs_keyBits[i], 0);
|
||||
pIOCON->PIO0[cs_keyIoConNdce[i]] = 0x80; // weak pUp
|
||||
}
|
||||
}
|
||||
|
||||
/* Initialize the LEDs on the NXP LPC824 LPCXpresso Board */
|
||||
static void Board_LED_Init(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < BOARD_LED_CNT; i++) {
|
||||
Chip_GPIO_PinSetDIR(LPC_GPIO_PORT, 0, ledBits[i], 1);
|
||||
Chip_GPIO_PinSetState(LPC_GPIO_PORT, 0, ledBits[i], true);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t Board_Key_GetKeyDown(uint32_t keyNdx)
|
||||
{
|
||||
LPC_GPIO_T *pGP = LPC_GPIO_PORT;
|
||||
return pGP->W[0][cs_keyBits[keyNdx]] == 0 ? 1 : 0;
|
||||
}
|
||||
|
||||
/* Board Debug UART Initialisation function */
|
||||
STATIC void Board_UART_Init(void)
|
||||
{
|
||||
/* Enable the clock to the Switch Matrix */
|
||||
Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SWM);
|
||||
|
||||
/* Connect the TXD_O and RXD_I signals to port pins(P0.4, P0.0) */
|
||||
//Chip_SWM_DisableFixedPin(SWM_FIXED_XTALIN);
|
||||
//Chip_SWM_DisableFixedPin(SWM_FIXED_XTALOUT);
|
||||
|
||||
Chip_SWM_DisableFixedPin(SWM_FIXED_ACMP_I1);
|
||||
Chip_SWM_DisableFixedPin(SWM_FIXED_ADC11);
|
||||
|
||||
/* Enable UART Divider clock, divided by 1 */
|
||||
Chip_Clock_SetUARTClockDiv(1);
|
||||
|
||||
/* Divided by 1 */
|
||||
if (DEBUG_UART == LPC_USART0) {
|
||||
|
||||
Chip_SWM_MovablePinAssign(SWM_U0_TXD_O, 4);
|
||||
Chip_SWM_MovablePinAssign(SWM_U0_RXD_I, 0);
|
||||
} else if (DEBUG_UART == LPC_USART1) {
|
||||
Chip_SWM_MovablePinAssign(SWM_U1_TXD_O, 4);
|
||||
Chip_SWM_MovablePinAssign(SWM_U1_RXD_I, 0);
|
||||
} else {
|
||||
Chip_SWM_MovablePinAssign(SWM_U2_TXD_O, 4);
|
||||
Chip_SWM_MovablePinAssign(SWM_U2_RXD_I, 0);
|
||||
}
|
||||
|
||||
/* Disable the clock to the Switch Matrix to save power */
|
||||
Chip_Clock_DisablePeriphClock(SYSCTL_CLOCK_SWM);
|
||||
}
|
||||
|
||||
/* Initializes pin muxing for SPI1 interface - note that SystemInit() may
|
||||
already setup your pin muxing at system startup */
|
||||
static void Init_SPI_PinMux(void)
|
||||
{
|
||||
|
||||
Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SWM);
|
||||
Chip_SWM_MovablePinAssign(SWM_SPI1_SSEL0_IO, 15);
|
||||
Chip_SWM_MovablePinAssign(SWM_SPI1_SCK_IO, 24);
|
||||
Chip_SWM_MovablePinAssign(SWM_SPI1_MISO_IO, 25);
|
||||
Chip_SWM_MovablePinAssign(SWM_SPI1_MOSI_IO, 26);
|
||||
Chip_Clock_DisablePeriphClock(SYSCTL_CLOCK_SWM);
|
||||
|
||||
}
|
||||
|
||||
/* Initializes pin muxing for I2C interface */
|
||||
static void Init_I2C_PinMux(void)
|
||||
{
|
||||
/* Enable the clock to the Switch Matrix */
|
||||
Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SWM);
|
||||
Chip_SWM_EnableFixedPin(SWM_FIXED_I2C0_SDA);
|
||||
Chip_SWM_EnableFixedPin(SWM_FIXED_I2C0_SCL);
|
||||
|
||||
/* Enable Fast Mode Plus for I2C pins */
|
||||
Chip_IOCON_PinSetI2CMode(LPC_IOCON, IOCON_PIO10, PIN_I2CMODE_FASTPLUS);
|
||||
Chip_IOCON_PinSetI2CMode(LPC_IOCON, IOCON_PIO11, PIN_I2CMODE_FASTPLUS);
|
||||
|
||||
/* Disable the clock to the Switch Matrix to save power */
|
||||
Chip_Clock_DisablePeriphClock(SYSCTL_CLOCK_SWM);
|
||||
}
|
||||
/*****************************************************************************
|
||||
* Public functions
|
||||
****************************************************************************/
|
||||
|
||||
/* Set the LED to the state of "On" */
|
||||
void Board_LED_Set(uint8_t LEDNumber, bool On)
|
||||
{
|
||||
if (LEDNumber < BOARD_LED_CNT) {
|
||||
Chip_GPIO_PinSetState(LPC_GPIO_PORT, 0, ledBits[LEDNumber], (bool) !On);
|
||||
}
|
||||
}
|
||||
|
||||
/* Return the state of LEDNumber */
|
||||
bool Board_LED_Test(uint8_t LEDNumber)
|
||||
{
|
||||
bool state = false;
|
||||
|
||||
if (LEDNumber < BOARD_LED_CNT) {
|
||||
state = (bool) !Chip_GPIO_PinGetState(LPC_GPIO_PORT, 0, ledBits[LEDNumber]);
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
/* Toggles the current state of a board LED */
|
||||
void Board_LED_Toggle(uint8_t LEDNumber)
|
||||
{
|
||||
if (LEDNumber < BOARD_LED_CNT) {
|
||||
Chip_GPIO_PinToggleState(LPC_GPIO_PORT, 0, ledBits[LEDNumber]);
|
||||
}
|
||||
}
|
||||
|
||||
/* Classic implementation of itoa -- integer to ASCII */
|
||||
char *Board_itoa(int value, char *result, int base)
|
||||
{
|
||||
char* ptr = result, *ptr1 = result, tmp_char;
|
||||
int tmp_value;
|
||||
|
||||
if (base < 2 || base > 36) { *result = '\0'; return result; }
|
||||
do {
|
||||
tmp_value = value;
|
||||
value /= base;
|
||||
*ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz" [35 + (tmp_value - value * base)];
|
||||
} while ( value );
|
||||
|
||||
if (tmp_value < 0) *ptr++ = '-';
|
||||
*ptr-- = '\0';
|
||||
while (ptr1 < ptr) {
|
||||
tmp_char = *ptr;
|
||||
*ptr--= *ptr1;
|
||||
*ptr1++ = tmp_char;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Sends a character on the UART */
|
||||
void Board_UARTPutChar(char ch)
|
||||
{
|
||||
#if defined(DEBUG_UART)
|
||||
Chip_UART_SendBlocking(DEBUG_UART, &ch, 1);
|
||||
#endif
|
||||
}
|
||||
|
||||
void Board_UARTPutTextChar(char ch)
|
||||
{
|
||||
#if defined(DEBUG_UART)
|
||||
static char prevChar = 0;
|
||||
if (ch == '\n' && prevChar != '\r')
|
||||
{
|
||||
prevChar = '\r';
|
||||
Chip_UART_SendBlocking(DEBUG_UART, &prevChar, 1);
|
||||
Chip_UART_SendBlocking(DEBUG_UART, &ch, 1);
|
||||
} else {
|
||||
Chip_UART_SendBlocking(DEBUG_UART, &ch, 1);
|
||||
prevChar = ch;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/* Gets a character from the UART, returns EOF if no character is ready */
|
||||
int Board_UARTGetChar(void)
|
||||
{
|
||||
#if defined(DEBUG_UART)
|
||||
uint8_t data;
|
||||
|
||||
if (Chip_UART_ReadBlocking(DEBUG_UART, &data, 1) == 1) {
|
||||
Board_UARTPutChar(data); // echo back the char
|
||||
return (int) data;
|
||||
}
|
||||
#endif
|
||||
return EOF;
|
||||
}
|
||||
|
||||
/* Outputs a string on the debug UART */
|
||||
void Board_UARTPutSTR(const char *str)
|
||||
{
|
||||
#if defined(DEBUG_UART)
|
||||
while (*str != '\0') {
|
||||
Board_UARTPutTextChar(*str++);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Initialize debug output via UART for board */
|
||||
void Board_Debug_Init(void)
|
||||
{
|
||||
#if defined(DEBUG_UART)
|
||||
Board_UART_Init();
|
||||
Chip_UART_Init(DEBUG_UART);
|
||||
Chip_UART_ConfigData(DEBUG_UART, UART_CFG_DATALEN_8 | UART_CFG_PARITY_NONE | UART_CFG_STOPLEN_1);
|
||||
Chip_Clock_SetUSARTNBaseClockRate((115200 * 6 * 16), true);
|
||||
Chip_UART_SetBaud(DEBUG_UART, 115200);
|
||||
Chip_UART_Enable(DEBUG_UART);
|
||||
Chip_UART_TXEnable(DEBUG_UART);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Set up and initialize all required blocks and functions related to the
|
||||
board hardware */
|
||||
void Board_Init(void)
|
||||
{
|
||||
LPC_SWM_T *pSWM = LPC_SWM;
|
||||
/* Sets up DEBUG UART */
|
||||
#if defined(DEBUG_ENABLE)
|
||||
DEBUGINIT();
|
||||
//pSWM->PINENABLE0 |= ~(1UL<<SWM_FIXED_SWCLK | 1UL<<SWM_FIXED_SWDIO | 1UL<<SWM_FIXED_RST);
|
||||
#ifdef USE_IRC_AS_ROOT_CLOCK
|
||||
pSWM->PINENABLE0 |= 1UL<<SWM_FIXED_XTALIN | 1UL<<SWM_FIXED_XTALOUT;
|
||||
#endif
|
||||
#endif
|
||||
/* Initialize GPIO */
|
||||
Chip_GPIO_Init(LPC_GPIO_PORT);
|
||||
|
||||
/* Initialize the LEDs */
|
||||
Board_LED_Init();
|
||||
//Board_Key_Init();
|
||||
Init_SPI_PinMux();
|
||||
Init_I2C_PinMux();
|
||||
}
|
||||
117
bsp/lpc824/Libraries/common/board/board_lpc.h
Normal file
117
bsp/lpc824/Libraries/common/board/board_lpc.h
Normal file
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* @brief NXP LPCXpresso LPC824 board file
|
||||
*
|
||||
* @note
|
||||
* Copyright(C) NXP Semiconductors, 2012
|
||||
* All rights reserved.
|
||||
*
|
||||
* @par
|
||||
* Software that is described herein is for illustrative purposes only
|
||||
* which provides customers with programming information regarding the
|
||||
* LPC products. This software is supplied "AS IS" without any warranties of
|
||||
* any kind, and NXP Semiconductors and its licensor disclaim any and
|
||||
* all warranties, express or implied, including all implied warranties of
|
||||
* merchantability, fitness for a particular purpose and non-infringement of
|
||||
* intellectual property rights. NXP Semiconductors assumes no responsibility
|
||||
* or liability for the use of the software, conveys no license or rights under any
|
||||
* patent, copyright, mask work right, or any other intellectual property rights in
|
||||
* or to any products. NXP Semiconductors reserves the right to make changes
|
||||
* in the software without notification. NXP Semiconductors also makes no
|
||||
* representation or warranty that such application will be suitable for the
|
||||
* specified use without further testing or modification.
|
||||
*
|
||||
* @par
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation is hereby granted, under NXP Semiconductors' and its
|
||||
* licensor's relevant copyrights in the software, without fee, provided that it
|
||||
* is used in conjunction with NXP Semiconductors microcontrollers. This
|
||||
* copyright, permission, and disclaimer notice must appear in all copies of
|
||||
* this code.
|
||||
*/
|
||||
|
||||
#ifndef __BOARD_H_
|
||||
#define __BOARD_H_
|
||||
|
||||
#include "chip.h"
|
||||
/* board_api.h is included at the bottom of this file after DEBUG setup */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @defgroup BOARD_NXP_LPCXPRESSO_824 NXP LPC824 LPCXpresso board support software API functions
|
||||
* @ingroup LPCOPEN_8XX_BOARD_LPCXPRESSO_824
|
||||
* The board support software API functions provide some simple abstracted
|
||||
* functions used across multiple LPCOpen board examples. See @ref BOARD_COMMON_API
|
||||
* for the functions defined by this board support layer.<br>
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup LPCOPEN_8XX_BOARD_LPCXPRESSO_824_OPTIONS BOARD: LPC824 LPCXpresso board build options
|
||||
* This board has options that configure its operation at build-time.<br>
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** Define the frequency in Hz, of the main oscillator (from Xtal)
|
||||
* Note that it only takes effect if main oscillator is selected as clock source
|
||||
*/
|
||||
#define MAIN_OSC_XTAL_FREQ_HZ 12000000
|
||||
/** Define the frequency in Hz, of the external clock input.
|
||||
* Note that it only takes effect if external clock is selected as clock source
|
||||
*/
|
||||
#define EXT_CLOCK_IN_FREQ_HZ 0
|
||||
|
||||
//#define USE_IRC_AS_ROOT_CLOCK /*注释掉使用外部晶体 打开定义则是使用内部IRC*/
|
||||
|
||||
#define BOARD_LED_CNT 8
|
||||
#define BOARD_KEY_CNT 3
|
||||
|
||||
typedef enum _enum_boardKeys
|
||||
{
|
||||
BOARD_KEY_0 = 0,
|
||||
BOARD_KEY_1 = 1,
|
||||
BOARD_KEY_2 = 2,
|
||||
}enum_boardKeys;
|
||||
|
||||
// define LED bits (bit <--> pin on port 0) only if in board.c file
|
||||
#ifdef _BOARD_C_
|
||||
static const uint8_t ledBits[BOARD_LED_CNT] = {7, 13, 16, 17, 19, 27, 28, 18};
|
||||
static const uint8_t cs_keyBits[BOARD_KEY_CNT] = {12, 4 , 1};
|
||||
static const uint8_t cs_keyIoConNdce[BOARD_KEY_CNT] = {IOCON_PIO12, IOCON_PIO4, IOCON_PIO1};
|
||||
#endif
|
||||
|
||||
/** Define DEBUG_ENABLE to enable IO via the DEBUGSTR, DEBUGOUT, and
|
||||
DEBUGIN macros. If not defined, DEBUG* functions will be optimized
|
||||
out of the code at build time.
|
||||
*/
|
||||
#define DEBUG_ENABLE
|
||||
|
||||
/** Define DEBUG_SEMIHOSTING along with DEBUG_ENABLE to enable IO support
|
||||
via semihosting. You may need to use a C library that supports
|
||||
semihosting with this option.
|
||||
*/
|
||||
//#define DEBUG_SEMIHOSTING
|
||||
|
||||
/** Board UART used for debug output and input using the DEBUG* macros. This
|
||||
is also the port used for Board_UARTPutChar, Board_UARTGetChar, and
|
||||
Board_UARTPutSTR functions. Although you can setup multiple UARTs here,
|
||||
the board code only supoprts UART0 in the Board_UART_Init() fucntion,
|
||||
so be sure to change it there too if not using UART0.
|
||||
*/
|
||||
#define DEBUG_UART LPC_USART1
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Board name */
|
||||
#define BOARD_NXP_LPCXPRESSO_824
|
||||
|
||||
|
||||
#include "board_api.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __BOARD_H_ */
|
||||
230
bsp/lpc824/Libraries/common/chip/chip.h
Normal file
230
bsp/lpc824/Libraries/common/chip/chip.h
Normal file
@@ -0,0 +1,230 @@
|
||||
/*
|
||||
* @brief LPC8xx basic chip inclusion file
|
||||
*
|
||||
* @note
|
||||
* Copyright(C) NXP Semiconductors, 2013
|
||||
* All rights reserved.
|
||||
*
|
||||
* @par
|
||||
* Software that is described herein is for illustrative purposes only
|
||||
* which provides customers with programming information regarding the
|
||||
* LPC products. This software is supplied "AS IS" without any warranties of
|
||||
* any kind, and NXP Semiconductors and its licensor disclaim any and
|
||||
* all warranties, express or implied, including all implied warranties of
|
||||
* merchantability, fitness for a particular purpose and non-infringement of
|
||||
* intellectual property rights. NXP Semiconductors assumes no responsibility
|
||||
* or liability for the use of the software, conveys no license or rights under any
|
||||
* patent, copyright, mask work right, or any other intellectual property rights in
|
||||
* or to any products. NXP Semiconductors reserves the right to make changes
|
||||
* in the software without notification. NXP Semiconductors also makes no
|
||||
* representation or warranty that such application will be suitable for the
|
||||
* specified use without further testing or modification.
|
||||
*
|
||||
* @par
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation is hereby granted, under NXP Semiconductors' and its
|
||||
* licensor's relevant copyrights in the software, without fee, provided that it
|
||||
* is used in conjunction with NXP Semiconductors microcontrollers. This
|
||||
* copyright, permission, and disclaimer notice must appear in all copies of
|
||||
* this code.
|
||||
*/
|
||||
|
||||
#ifndef __CHIP_H_
|
||||
#define __CHIP_H_
|
||||
|
||||
#include "lpc_types.h"
|
||||
#include "cmsis.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef CORE_M0PLUS
|
||||
#error CORE_M0PLUS is not defined for the LPC8xx architecture
|
||||
#error CORE_M0PLUS should be defined as part of your compiler define list
|
||||
#endif
|
||||
|
||||
#ifndef CHIP_LPC8XX
|
||||
#error The LPC8XX Chip include path is used for this build, but
|
||||
#error CHIP_LPC8XX is not defined!
|
||||
#endif
|
||||
|
||||
/** @defgroup PERIPH_8XX_BASE CHIP: LPC8xx Peripheral addresses and register set declarations
|
||||
* @ingroup CHIP_8XX_Drivers
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Base addresses */
|
||||
#define LPC_FLASH_BASE (0x00000000UL)
|
||||
#define LPC_RAM_BASE (0x10000000UL)
|
||||
#define LPC_ROM_BASE (0x1FFF0000UL)
|
||||
#define LPC_APB0_BASE (0x40000000UL)
|
||||
#define LPC_AHB_BASE (0x50000000UL)
|
||||
|
||||
/* APB0 peripherals */
|
||||
#define LPC_WWDT_BASE (0x40000000UL)
|
||||
#define LPC_MRT_BASE (0x40004000UL)
|
||||
#define LPC_WKT_BASE (0x40008000UL)
|
||||
#define LPC_SWM_BASE (0x4000C000UL)
|
||||
#define LPC_ADC_BASE (0x4001C000UL) /* Available only on LPC82x */
|
||||
#define LPC_PMU_BASE (0x40020000UL)
|
||||
#define LPC_CMP_BASE (0x40024000UL)
|
||||
#define LPC_DMATIRGMUX_BASE (0x40028000UL) /* Available only on LPC82x */
|
||||
#define LPC_INMUX_BASE (0x4002C000UL) /* Available only on LPC82x */
|
||||
|
||||
#define LPC_FMC_BASE (0x40040000UL)
|
||||
#define LPC_IOCON_BASE (0x40044000UL)
|
||||
#define LPC_SYSCTL_BASE (0x40048000UL)
|
||||
#define LPC_I2C0_BASE (0x40050000UL)
|
||||
#define LPC_I2C1_BASE (0x40054000UL) /* Available only on LPC82x */
|
||||
#define LPC_SPI0_BASE (0x40058000UL)
|
||||
#define LPC_SPI1_BASE (0x4005C000UL)
|
||||
#define LPC_USART0_BASE (0x40064000UL)
|
||||
#define LPC_USART1_BASE (0x40068000UL)
|
||||
#define LPC_USART2_BASE (0x4006C000UL)
|
||||
#define LPC_I2C2_BASE (0x40070000UL) /* Available only on LPC82x */
|
||||
#define LPC_I2C3_BASE (0x40074000UL) /* Available only on LPC82x */
|
||||
|
||||
/* AHB peripherals */
|
||||
#define LPC_CRC_BASE (0x50000000UL)
|
||||
#define LPC_SCT_BASE (0x50004000UL)
|
||||
#define LPC_DMA_BASE (0x50008000UL) /* Available only on LPC82x */
|
||||
|
||||
#define LPC_GPIO_PORT_BASE (0xA0000000UL)
|
||||
#define LPC_PIN_INT_BASE (0xA0004000UL)
|
||||
|
||||
#define LPC_WWDT ((LPC_WWDT_T *) LPC_WWDT_BASE)
|
||||
#define LPC_SPI0 ((LPC_SPI_T *) LPC_SPI0_BASE)
|
||||
#define LPC_SPI1 ((LPC_SPI_T *) LPC_SPI1_BASE)
|
||||
#define LPC_USART0 ((LPC_USART_T *) LPC_USART0_BASE)
|
||||
#define LPC_USART1 ((LPC_USART_T *) LPC_USART1_BASE)
|
||||
#define LPC_USART2 ((LPC_USART_T *) LPC_USART2_BASE)
|
||||
#define LPC_WKT ((LPC_WKT_T *) LPC_WKT_BASE)
|
||||
#define LPC_PMU ((LPC_PMU_T *) LPC_PMU_BASE)
|
||||
#define LPC_CRC ((LPC_CRC_T *) LPC_CRC_BASE)
|
||||
#define LPC_SCT ((LPC_SCT_T *) LPC_SCT_BASE)
|
||||
#define LPC_GPIO_PORT ((LPC_GPIO_T *) LPC_GPIO_PORT_BASE)
|
||||
#define LPC_PININT ((LPC_PININT_T *) LPC_PIN_INT_BASE)
|
||||
#define LPC_IOCON ((LPC_IOCON_T *) LPC_IOCON_BASE)
|
||||
#define LPC_SWM ((LPC_SWM_T *) LPC_SWM_BASE)
|
||||
#define LPC_SYSCTL ((LPC_SYSCTL_T *) LPC_SYSCTL_BASE)
|
||||
#define LPC_CMP ((LPC_CMP_T *) LPC_CMP_BASE)
|
||||
#define LPC_FMC ((LPC_FMC_T *) LPC_FMC_BASE)
|
||||
#define LPC_MRT ((LPC_MRT_T *) LPC_MRT_BASE)
|
||||
#define LPC_I2C0 ((LPC_I2C_T *) LPC_I2C0_BASE)
|
||||
|
||||
#ifdef CHIP_LPC82X
|
||||
/* Peripherals available only on LPC82x */
|
||||
#define LPC_ADC ((LPC_ADC_T *) LPC_ADC_BASE)
|
||||
#define LPC_I2C1 ((LPC_I2C_T *) LPC_I2C1_BASE)
|
||||
#define LPC_I2C2 ((LPC_I2C_T *) LPC_I2C2_BASE)
|
||||
#define LPC_I2C3 ((LPC_I2C_T *) LPC_I2C3_BASE)
|
||||
#define LPC_DMA ((LPC_DMA_T *) LPC_DMA_BASE)
|
||||
#define LPC_DMATRIGMUX ((LPC_DMATRIGMUX_T *) LPC_DMATIRGMUX_BASE)
|
||||
#define LPC_INMUX ((LPC_INMUX_T *) LPC_INMUX_BASE)
|
||||
#endif
|
||||
|
||||
/* Base address Alias list */
|
||||
#define LPC_I2C_BASE LPC_I2C0_BASE
|
||||
#define LPC_I2C LPC_I2C0
|
||||
#define LPC_SYSCON LPC_SYSCTL
|
||||
|
||||
/* IRQ Handler alias list */
|
||||
#ifdef CHIP_LPC82X
|
||||
#define I2C_IRQHandler I2C0_IRQHandler
|
||||
#define PININT0_IRQHandler PIN_INT0_IRQHandler
|
||||
#define PININT1_IRQHandler PIN_INT1_IRQHandler
|
||||
#define PININT2_IRQHandler PIN_INT2_IRQHandler
|
||||
#define PININT3_IRQHandler PIN_INT3_IRQHandler
|
||||
#define PININT4_IRQHandler PIN_INT4_IRQHandler
|
||||
#define PININT5_IRQHandler PIN_INT5_IRQHandler
|
||||
#define PININT6_IRQHandler PIN_INT6_IRQHandler
|
||||
#define PININT7_IRQHandler PIN_INT7_IRQHandler
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @ingroup CHIP_8XX_DRIVER_OPTIONS
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief System oscillator rate
|
||||
* This value is defined externally to the chip layer and contains
|
||||
* the value in Hz for the external oscillator for the board. If using the
|
||||
* internal oscillator, this rate can be 0.
|
||||
*/
|
||||
extern const uint32_t OscRateIn;
|
||||
|
||||
/**
|
||||
* @brief Clock rate on the CLKIN pin
|
||||
* This value is defined externally to the chip layer and contains
|
||||
* the value in Hz for the CLKIN pin for the board. If this pin isn't used,
|
||||
* this rate can be 0.
|
||||
*/
|
||||
extern const uint32_t ExtRateIn;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Include order is important! */
|
||||
#include "syscon_8xx.h"
|
||||
#include "clock_8xx.h"
|
||||
#include "fmc_8xx.h"
|
||||
#include "ioswm_8xx.h"
|
||||
|
||||
#ifndef _CHIP_COMMON_
|
||||
#include "../../peri_driver/peri_driver.h"
|
||||
#endif
|
||||
|
||||
/** @defgroup SUPPORT_8XX_FUNC CHIP: LPC8xx support functions
|
||||
* @ingroup CHIP_8XX_Drivers
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Current system clock rate, mainly used for sysTick
|
||||
*/
|
||||
extern uint32_t SystemCoreClock;
|
||||
|
||||
/**
|
||||
* @brief Update system core clock rate, should be called if the
|
||||
* system has a clock rate change
|
||||
* @return None
|
||||
*/
|
||||
void SystemCoreClockUpdate(void);
|
||||
|
||||
/**
|
||||
* @brief Set up and initialize hardware prior to call to main()
|
||||
* @return None
|
||||
* @note Chip_SystemInit() is called prior to the application and sets up
|
||||
* system clocking prior to the application starting.
|
||||
*/
|
||||
void Chip_SystemInit(void);
|
||||
|
||||
/**
|
||||
* @brief Clock and PLL initialization based on the external oscillator
|
||||
* @return None
|
||||
* @note This function assumes an external crystal oscillator
|
||||
* frequency of 12MHz.
|
||||
*/
|
||||
void Chip_SetupXtalClocking(void);
|
||||
|
||||
/**
|
||||
* @brief Clock and PLL initialization based on the internal oscillator
|
||||
* @return None
|
||||
*/
|
||||
void Chip_SetupIrcClocking(void);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __CHIP_H_ */
|
||||
468
bsp/lpc824/Libraries/common/chip/clock_8xx.c
Normal file
468
bsp/lpc824/Libraries/common/chip/clock_8xx.c
Normal file
@@ -0,0 +1,468 @@
|
||||
/*
|
||||
* @brief LPC8xx clock driver
|
||||
*
|
||||
* @note
|
||||
* Copyright(C) NXP Semiconductors, 2012
|
||||
* All rights reserved.
|
||||
*
|
||||
* @par
|
||||
* Software that is described herein is for illustrative purposes only
|
||||
* which provides customers with programming information regarding the
|
||||
* LPC products. This software is supplied "AS IS" without any warranties of
|
||||
* any kind, and NXP Semiconductors and its licenser disclaim any and
|
||||
* all warranties, express or implied, including all implied warranties of
|
||||
* merchantability, fitness for a particular purpose and non-infringement of
|
||||
* intellectual property rights. NXP Semiconductors assumes no responsibility
|
||||
* or liability for the use of the software, conveys no license or rights under any
|
||||
* patent, copyright, mask work right, or any other intellectual property rights in
|
||||
* or to any products. NXP Semiconductors reserves the right to make changes
|
||||
* in the software without notification. NXP Semiconductors also makes no
|
||||
* representation or warranty that such application will be suitable for the
|
||||
* specified use without further testing or modification.
|
||||
*
|
||||
* @par
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation is hereby granted, under NXP Semiconductors' and its
|
||||
* licensor's relevant copyrights in the software, without fee, provided that it
|
||||
* is used in conjunction with NXP Semiconductors microcontrollers. This
|
||||
* copyright, permission, and disclaimer notice must appear in all copies of
|
||||
* this code.
|
||||
*/
|
||||
#define _CHIP_COMMON_
|
||||
#include "chip.h"
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* Private types/enumerations/variables
|
||||
****************************************************************************/
|
||||
|
||||
/* Inprecise clock rates for the watchdog oscillator */
|
||||
static const uint32_t wdtOSCRate[WDTLFO_OSC_4_60 + 1] = {
|
||||
0, /* WDT_OSC_ILLEGAL */
|
||||
600000, /* WDT_OSC_0_60 */
|
||||
1050000, /* WDT_OSC_1_05 */
|
||||
1400000, /* WDT_OSC_1_40 */
|
||||
1750000, /* WDT_OSC_1_75 */
|
||||
2100000, /* WDT_OSC_2_10 */
|
||||
2400000, /* WDT_OSC_2_40 */
|
||||
2700000, /* WDT_OSC_2_70 */
|
||||
3000000, /* WDT_OSC_3_00 */
|
||||
3250000, /* WDT_OSC_3_25 */
|
||||
3500000, /* WDT_OSC_3_50 */
|
||||
3750000, /* WDT_OSC_3_75 */
|
||||
4000000, /* WDT_OSC_4_00 */
|
||||
4200000, /* WDT_OSC_4_20 */
|
||||
4400000, /* WDT_OSC_4_40 */
|
||||
4600000 /* WDT_OSC_4_60 */
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
uint16_t freq_main; // main clock frequency in MHz
|
||||
uint16_t freq_sys; // system (CPU) clock frequency in MHz
|
||||
uint16_t freq_fcco; // FCCO clock frequency in MHz
|
||||
uint16_t msel; // MSEL (pre-decremented)
|
||||
uint16_t psel; // PSEL (pre-decremented)
|
||||
uint16_t divider; // SYSAHBCLKDIV
|
||||
} LPC_8XX_PLL_T;
|
||||
|
||||
/*
|
||||
* This table contains all useful PLL configurations
|
||||
* for "integer" MHZ (e.g. 1MHz, 2MHz, etc.) frequencies.
|
||||
*
|
||||
* This table has two inputs:
|
||||
* - freq_main: This is the main frequency.
|
||||
* - freq_sys: This is the system (CPU) frequency.
|
||||
* These are used to select which table entry to use.
|
||||
*
|
||||
* There are many ways to get some frequencies. For example,
|
||||
* there are eight ways to make the CPU run at 12MHZ. If the peripheral bus
|
||||
* needs to run very fast, it's possible to set the main clock
|
||||
* up to 96MHz. If low power is a requirement, it's possible to set the main
|
||||
* clock to 12MHz.
|
||||
*
|
||||
* All the rest of the table entries are outputs.
|
||||
* - freq_fcco is simply an FYI value. It is not used for programming.
|
||||
* - MSEL / PSEL / divider are used to program the PLL.
|
||||
*/
|
||||
static const LPC_8XX_PLL_T config_tab[] = {
|
||||
{ 12, 12, 192, 0, 3, 1 }, // 12.0000MHz
|
||||
{ 12, 6, 192, 0, 3, 2 }, // 6.0000MHz
|
||||
{ 12, 4, 192, 0, 3, 3 }, // 4.0000MHz
|
||||
{ 12, 3, 192, 0, 3, 4 }, // 3.0000MHz
|
||||
{ 12, 2, 192, 0, 3, 6 }, // 2.0000MHz
|
||||
{ 12, 1, 192, 0, 3, 12 }, // 1.0000MHz
|
||||
{ 24, 24, 192, 1, 2, 1 }, // 24.0000MHz
|
||||
{ 24, 12, 192, 1, 2, 2 }, // 12.0000MHz
|
||||
{ 24, 8, 192, 1, 2, 3 }, // 8.0000MHz
|
||||
{ 24, 6, 192, 1, 2, 4 }, // 6.0000MHz
|
||||
{ 24, 4, 192, 1, 2, 6 }, // 4.0000MHz
|
||||
{ 24, 3, 192, 1, 2, 8 }, // 3.0000MHz
|
||||
{ 24, 2, 192, 1, 2, 12 }, // 2.0000MHz
|
||||
{ 24, 1, 192, 1, 2, 24 }, // 1.0000MHz
|
||||
{ 36, 18, 288, 2, 2, 2 }, // 18.0000MHz
|
||||
{ 36, 12, 288, 2, 2, 3 }, // 12.0000MHz
|
||||
{ 36, 9, 288, 2, 2, 4 }, // 9.0000MHz
|
||||
{ 36, 6, 288, 2, 2, 6 }, // 6.0000MHz
|
||||
{ 36, 4, 288, 2, 2, 9 }, // 4.0000MHz
|
||||
{ 36, 3, 288, 2, 2, 12 }, // 3.0000MHz
|
||||
{ 36, 2, 288, 2, 2, 18 }, // 2.0000MHz
|
||||
{ 36, 1, 288, 2, 2, 36 }, // 1.0000MHz
|
||||
{ 48, 24, 192, 3, 1, 2 }, // 24.0000MHz
|
||||
{ 48, 16, 192, 3, 1, 3 }, // 16.0000MHz
|
||||
{ 48, 12, 192, 3, 1, 4 }, // 12.0000MHz
|
||||
{ 48, 8, 192, 3, 1, 6 }, // 8.0000MHz
|
||||
{ 48, 6, 192, 3, 1, 8 }, // 6.0000MHz
|
||||
{ 48, 4, 192, 3, 1, 12 }, // 4.0000MHz
|
||||
{ 48, 3, 192, 3, 1, 16 }, // 3.0000MHz
|
||||
{ 48, 2, 192, 3, 1, 24 }, // 2.0000MHz
|
||||
{ 48, 1, 192, 3, 1, 48 }, // 1.0000MHz
|
||||
{ 60, 30, 240, 4, 1, 2 }, // 30.0000MHz
|
||||
{ 60, 20, 240, 4, 1, 3 }, // 20.0000MHz
|
||||
{ 60, 15, 240, 4, 1, 4 }, // 15.0000MHz
|
||||
{ 60, 12, 240, 4, 1, 5 }, // 12.0000MHz
|
||||
{ 60, 10, 240, 4, 1, 6 }, // 10.0000MHz
|
||||
{ 60, 6, 240, 4, 1, 10 }, // 6.0000MHz
|
||||
{ 60, 5, 240, 4, 1, 12 }, // 5.0000MHz
|
||||
{ 60, 4, 240, 4, 1, 15 }, // 4.0000MHz
|
||||
{ 60, 3, 240, 4, 1, 20 }, // 3.0000MHz
|
||||
{ 60, 2, 240, 4, 1, 30 }, // 2.0000MHz
|
||||
{ 60, 1, 240, 4, 1, 60 }, // 1.0000MHz
|
||||
{ 72, 24, 288, 5, 1, 3 }, // 24.0000MHz
|
||||
{ 72, 18, 288, 5, 1, 4 }, // 18.0000MHz
|
||||
{ 72, 12, 288, 5, 1, 6 }, // 12.0000MHz
|
||||
{ 72, 9, 288, 5, 1, 8 }, // 9.0000MHz
|
||||
{ 72, 8, 288, 5, 1, 9 }, // 8.0000MHz
|
||||
{ 72, 6, 288, 5, 1, 12 }, // 6.0000MHz
|
||||
{ 72, 4, 288, 5, 1, 18 }, // 4.0000MHz
|
||||
{ 72, 3, 288, 5, 1, 24 }, // 3.0000MHz
|
||||
{ 72, 2, 288, 5, 1, 36 }, // 2.0000MHz
|
||||
{ 72, 1, 288, 5, 1, 72 }, // 1.0000MHz
|
||||
{ 84, 28, 168, 6, 0, 3 }, // 28.0000MHz
|
||||
{ 84, 21, 168, 6, 0, 4 }, // 21.0000MHz
|
||||
{ 84, 14, 168, 6, 0, 6 }, // 14.0000MHz
|
||||
{ 84, 12, 168, 6, 0, 7 }, // 12.0000MHz
|
||||
{ 84, 7, 168, 6, 0, 12 }, // 7.0000MHz
|
||||
{ 84, 6, 168, 6, 0, 14 }, // 6.0000MHz
|
||||
{ 84, 4, 168, 6, 0, 21 }, // 4.0000MHz
|
||||
{ 84, 3, 168, 6, 0, 28 }, // 3.0000MHz
|
||||
{ 84, 2, 168, 6, 0, 42 }, // 2.0000MHz
|
||||
{ 84, 1, 168, 6, 0, 84 }, // 1.0000MHz
|
||||
{ 96, 24, 192, 7, 0, 4 }, // 24.0000MHz
|
||||
{ 96, 16, 192, 7, 0, 6 }, // 16.0000MHz
|
||||
{ 96, 12, 192, 7, 0, 8 }, // 12.0000MHz
|
||||
{ 96, 8, 192, 7, 0, 12 }, // 8.0000MHz
|
||||
{ 96, 6, 192, 7, 0, 16 }, // 6.0000MHz
|
||||
{ 96, 4, 192, 7, 0, 24 }, // 4.0000MHz
|
||||
{ 96, 3, 192, 7, 0, 32 }, // 3.0000MHz
|
||||
{ 96, 2, 192, 7, 0, 48 }, // 2.0000MHz
|
||||
{ 96, 1, 192, 7, 0, 96 }, // 1.0000MHz
|
||||
};
|
||||
static const uint16_t config_tab_ct = sizeof(config_tab) / sizeof(LPC_8XX_PLL_T);
|
||||
static uint16_t config_tab_idx = 0;
|
||||
/*****************************************************************************
|
||||
* Public types/enumerations/variables
|
||||
****************************************************************************/
|
||||
/* System Clock Frequency (Core Clock) */
|
||||
uint32_t SystemCoreClock;
|
||||
|
||||
/*****************************************************************************
|
||||
* Private functions
|
||||
****************************************************************************/
|
||||
|
||||
static void pll_config(const LPC_8XX_PLL_T* pll_cfg)
|
||||
{
|
||||
Chip_SYSCTL_PowerUp(SYSCTL_SLPWAKE_IRC_PD); /* turn on the IRC by clearing the power down bit */
|
||||
Chip_Clock_SetSystemPLLSource(SYSCTL_PLLCLKSRC_IRC); /* select PLL input to be IRC */
|
||||
Chip_Clock_SetMainClockSource(SYSCTL_MAINCLKSRC_IRC);
|
||||
Chip_FMC_SetFLASHAccess(FLASHTIM_30MHZ_CPU); /* setup FLASH access to 2 clocks (up to 30MHz) */
|
||||
Chip_SYSCTL_PowerDown(SYSCTL_SLPWAKE_SYSPLL_PD); /* power down PLL to change the PLL divider ratio */
|
||||
Chip_Clock_SetupSystemPLL(pll_cfg->msel, pll_cfg->psel); /* configure the PLL */
|
||||
Chip_SYSCTL_PowerUp(SYSCTL_SLPWAKE_SYSPLL_PD); /* turn on the PLL by clearing the power down bit */
|
||||
while (!Chip_Clock_IsSystemPLLLocked()) {} /* wait for PLL to lock */
|
||||
Chip_Clock_SetSysClockDiv(pll_cfg->divider); /* load the divider */
|
||||
Chip_Clock_SetMainClockSource(SYSCTL_MAINCLKSRC_PLLOUT); /* enable the new Frequency */
|
||||
}
|
||||
|
||||
/* Compute a WDT or LFO rate */
|
||||
static uint32_t Chip_Clock_GetWDTLFORate(uint32_t reg)
|
||||
{
|
||||
uint32_t div;
|
||||
CHIP_WDTLFO_OSC_T clk;
|
||||
|
||||
/* Get WDT oscillator settings */
|
||||
clk = (CHIP_WDTLFO_OSC_T) ((reg >> 5) & 0xF);
|
||||
div = reg & 0x1F;
|
||||
|
||||
/* Compute clock rate and divided by divde value */
|
||||
return wdtOSCRate[clk] / ((div + 1) << 1);
|
||||
}
|
||||
|
||||
/* Compute PLL frequency */
|
||||
static uint32_t Chip_Clock_GetPLLFreq(uint32_t PLLReg, uint32_t inputRate)
|
||||
{
|
||||
uint32_t m_val = ((PLLReg & 0x1F) + 1);
|
||||
|
||||
return (inputRate * m_val);
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
* Public functions
|
||||
****************************************************************************/
|
||||
|
||||
bool Chip_IRC_SetFreq(uint32_t main, uint32_t sys)
|
||||
{
|
||||
uint16_t freq_m = main/1000000; /* main frequency in MHz */
|
||||
uint16_t freq_s = sys/1000000; /* system frequency in MHz */
|
||||
bool found = false; /* frequencies found */
|
||||
uint32_t i = 0;
|
||||
|
||||
if (freq_s > 30) /* if system frequency is higher than 30MHz... */
|
||||
return false; /* ...don't attempt to set it */
|
||||
if (freq_m > 96) /* if main frequency is higher than 96MHz... */
|
||||
return false; /* ...don't attempt to set it */
|
||||
|
||||
for (i=0; i<config_tab_ct; i++) { /* loop through table */
|
||||
if ((freq_m == config_tab[i].freq_main) && (freq_s == config_tab[i].freq_sys)) { /* attempt to find a match */
|
||||
config_tab_idx = i; /* save the data for later */
|
||||
found = true; /* set state to found */
|
||||
break; /* go config the PLL */
|
||||
}
|
||||
}
|
||||
if (found == true) { /* if a match has been found */
|
||||
pll_config(&config_tab[config_tab_idx]); /* configure the PLL */
|
||||
}
|
||||
|
||||
return found; /* return operation status */
|
||||
}
|
||||
|
||||
// Open this API only if ROM headers are included
|
||||
#ifdef LPC_PWRD_API
|
||||
void Chip_IRC_SetFreq_ROM(uint32_t sys)
|
||||
{
|
||||
uint32_t cmd[4], resp[2];
|
||||
|
||||
Chip_SYSCTL_PowerUp(SYSCTL_SLPWAKE_IRC_PD); /* Turn on the IRC by clearing the power down bit */
|
||||
Chip_Clock_SetSystemPLLSource(SYSCTL_PLLCLKSRC_IRC); /* Select PLL input to be IRC */
|
||||
Chip_FMC_SetFLASHAccess(FLASHTIM_30MHZ_CPU); /* Setup FLASH access to 2 clocks (up to 30MHz) */
|
||||
|
||||
cmd[0] = Chip_Clock_GetIntOscRate() / 1000; /* in KHz */
|
||||
cmd[1] = sys / 1000; /* system clock rate in kHz */
|
||||
cmd[2] = CPU_FREQ_EQU;
|
||||
cmd[3] = sys / 10000; /* Timeout. See UM10601, section 23.4.1.3 for details */
|
||||
LPC_PWRD_API->set_pll(cmd, resp); /* Attempt to set the PLL */
|
||||
|
||||
while (resp[0] != PLL_CMD_SUCCESS) {} /* Dead loop on fail */
|
||||
}
|
||||
#else
|
||||
|
||||
#endif
|
||||
|
||||
/* Update system core clock rate, should be called if the system has
|
||||
a clock rate change */
|
||||
void SystemCoreClockUpdate(void)
|
||||
{
|
||||
/* CPU core speed */
|
||||
SystemCoreClock = Chip_Clock_GetSystemClockRate();
|
||||
}
|
||||
/* Set System PLL clock source */
|
||||
void Chip_Clock_SetSystemPLLSource(CHIP_SYSCTL_PLLCLKSRC_T src)
|
||||
{
|
||||
LPC_SYSCTL->SYSPLLCLKSEL = (uint32_t) src;
|
||||
|
||||
/* sequnce a 0 followed by 1 to update PLL source selection */
|
||||
LPC_SYSCTL->SYSPLLCLKUEN = 0;
|
||||
LPC_SYSCTL->SYSPLLCLKUEN = 1;
|
||||
}
|
||||
|
||||
/* Bypass System Oscillator and set oscillator frequency range */
|
||||
void Chip_Clock_SetPLLBypass(bool bypass, bool highfr)
|
||||
{
|
||||
uint32_t ctrl = 0;
|
||||
|
||||
if (bypass) {
|
||||
ctrl |= (1 << 0);
|
||||
}
|
||||
if (highfr) {
|
||||
ctrl |= (1 << 1);
|
||||
}
|
||||
|
||||
LPC_SYSCTL->SYSOSCCTRL = ctrl;
|
||||
}
|
||||
|
||||
/* Set main system clock source */
|
||||
void Chip_Clock_SetMainClockSource(CHIP_SYSCTL_MAINCLKSRC_T src)
|
||||
{
|
||||
LPC_SYSCTL->MAINCLKSEL = (uint32_t) src;
|
||||
|
||||
/* sequnce a 0 followed by 1 to update MAINCLK source selection */
|
||||
LPC_SYSCTL->MAINCLKUEN = 0;
|
||||
LPC_SYSCTL->MAINCLKUEN = 1;
|
||||
}
|
||||
|
||||
/* Set CLKOUT clock source and divider */
|
||||
void Chip_Clock_SetCLKOUTSource(CHIP_SYSCTL_CLKOUTSRC_T src, uint32_t div)
|
||||
{
|
||||
LPC_SYSCTL->CLKOUTSEL = (uint32_t) src;
|
||||
|
||||
/* sequnce a 0 followed by 1 to update CLKOUT source selection */
|
||||
LPC_SYSCTL->CLKOUTUEN = 0;
|
||||
LPC_SYSCTL->CLKOUTUEN = 1;
|
||||
LPC_SYSCTL->CLKOUTDIV = div;
|
||||
}
|
||||
|
||||
/* Return estimated watchdog oscillator rate */
|
||||
uint32_t Chip_Clock_GetWDTOSCRate(void)
|
||||
{
|
||||
return Chip_Clock_GetWDTLFORate(LPC_SYSCTL->WDTOSCCTRL & ~SYSCTL_WDTOSCCTRL_RESERVED);
|
||||
}
|
||||
|
||||
/* Return System PLL input clock rate */
|
||||
uint32_t Chip_Clock_GetSystemPLLInClockRate(void)
|
||||
{
|
||||
uint32_t clkRate;
|
||||
|
||||
switch ((CHIP_SYSCTL_PLLCLKSRC_T) (LPC_SYSCTL->SYSPLLCLKSEL & 0x3)) {
|
||||
case SYSCTL_PLLCLKSRC_IRC:
|
||||
clkRate = Chip_Clock_GetIntOscRate();
|
||||
break;
|
||||
|
||||
case SYSCTL_PLLCLKSRC_SYSOSC:
|
||||
clkRate = Chip_Clock_GetMainOscRate();
|
||||
break;
|
||||
|
||||
case SYSCTL_PLLCLKSRC_EXT_CLKIN:
|
||||
clkRate = Chip_Clock_GetExtClockInRate();
|
||||
break;
|
||||
|
||||
default:
|
||||
clkRate = 0;
|
||||
}
|
||||
|
||||
return clkRate;
|
||||
}
|
||||
|
||||
/* Return System PLL output clock rate */
|
||||
uint32_t Chip_Clock_GetSystemPLLOutClockRate(void)
|
||||
{
|
||||
return Chip_Clock_GetPLLFreq((LPC_SYSCTL->SYSPLLCTRL & ~SYSCTL_SYSPLLCTRL_RESERVED),
|
||||
Chip_Clock_GetSystemPLLInClockRate());
|
||||
}
|
||||
|
||||
/* Return main clock rate */
|
||||
uint32_t Chip_Clock_GetMainClockRate(void)
|
||||
{
|
||||
uint32_t clkRate = 0;
|
||||
|
||||
switch ((CHIP_SYSCTL_MAINCLKSRC_T) (LPC_SYSCTL->MAINCLKSEL & 0x3)) {
|
||||
case SYSCTL_MAINCLKSRC_IRC:
|
||||
clkRate = Chip_Clock_GetIntOscRate();
|
||||
break;
|
||||
|
||||
case SYSCTL_MAINCLKSRC_PLLIN:
|
||||
clkRate = Chip_Clock_GetSystemPLLInClockRate();
|
||||
break;
|
||||
|
||||
case SYSCTL_MAINCLKSRC_WDTOSC:
|
||||
clkRate = Chip_Clock_GetWDTOSCRate();
|
||||
break;
|
||||
|
||||
case SYSCTL_MAINCLKSRC_PLLOUT:
|
||||
clkRate = Chip_Clock_GetSystemPLLOutClockRate();
|
||||
break;
|
||||
}
|
||||
|
||||
return clkRate;
|
||||
}
|
||||
|
||||
/* Return system clock rate */
|
||||
uint32_t Chip_Clock_GetSystemClockRate(void)
|
||||
{
|
||||
/* No point in checking for divide by 0 */
|
||||
return Chip_Clock_GetMainClockRate() / (LPC_SYSCTL->SYSAHBCLKDIV & ~SYSCTL_SYSAHBCLKDIV_RESERVED);
|
||||
}
|
||||
|
||||
/* Get USART 0/1/2 UART base rate */
|
||||
uint32_t Chip_Clock_GetUSARTNBaseClockRate(void)
|
||||
{
|
||||
uint64_t inclk;
|
||||
uint32_t div;
|
||||
|
||||
div = (uint32_t) Chip_Clock_GetUARTClockDiv();
|
||||
if (div == 0) {
|
||||
/* Divider is 0 so UART clock is disabled */
|
||||
inclk = 0;
|
||||
}
|
||||
else {
|
||||
uint32_t mult, divf;
|
||||
|
||||
/* Input clock into FRG block is the divided main system clock */
|
||||
inclk = (uint64_t) (Chip_Clock_GetMainClockRate() / div);
|
||||
|
||||
divf = Chip_SYSCTL_GetUSARTFRGDivider();
|
||||
if (divf == 0xFF) {
|
||||
/* Fractional part is enabled, get multiplier */
|
||||
mult = (uint32_t) Chip_SYSCTL_GetUSARTFRGMultiplier();
|
||||
|
||||
/* Get fractional error */
|
||||
inclk = (inclk * 256) / (uint64_t) (256 + mult);
|
||||
}
|
||||
}
|
||||
|
||||
return (uint32_t) inclk;
|
||||
}
|
||||
|
||||
/* Set USART 0/1/2 UART base rate */
|
||||
uint32_t Chip_Clock_SetUSARTNBaseClockRate(uint32_t rate, bool fEnable)
|
||||
{
|
||||
uint32_t div, inclk;
|
||||
|
||||
/* Input clock into FRG block is the main system clock */
|
||||
inclk = Chip_Clock_GetMainClockRate();
|
||||
|
||||
/* Get integer divider for coarse rate */
|
||||
div = inclk / rate;
|
||||
if (div == 0) {
|
||||
div = 1;
|
||||
}
|
||||
|
||||
/* Approximated rate with only integer divider */
|
||||
Chip_Clock_SetUARTClockDiv((uint8_t) div);
|
||||
|
||||
if (fEnable) {
|
||||
uint32_t uart_fra_multiplier;
|
||||
|
||||
/* Reset FRG */
|
||||
Chip_SYSCTL_PeriphReset(RESET_UARTFBRG);
|
||||
|
||||
/* Enable fractional divider */
|
||||
Chip_SYSCTL_SetUSARTFRGDivider(0xFF);
|
||||
|
||||
/* Compute the fractional divisor (the lower byte is the
|
||||
fractional portion) */
|
||||
uart_fra_multiplier = ((inclk / div) * 256) / rate;
|
||||
|
||||
/* ...just the fractional portion (the lower byte) */
|
||||
Chip_SYSCTL_SetUSARTFRGMultiplier((uint8_t) uart_fra_multiplier);
|
||||
}
|
||||
else {
|
||||
/* Disable fractional generator and use integer divider only */
|
||||
Chip_SYSCTL_SetUSARTFRGDivider(0);
|
||||
}
|
||||
|
||||
return Chip_Clock_GetUSARTNBaseClockRate();
|
||||
}
|
||||
|
||||
/* Get the IOCONCLKDIV clock rate */
|
||||
uint32_t Chip_Clock_GetIOCONCLKDIVClockRate(CHIP_PIN_CLKDIV_T reg)
|
||||
{
|
||||
uint32_t div = LPC_SYSCTL->IOCONCLKDIV[reg] & ~SYSCTL_IOCONCLKDIV_RESERVED;
|
||||
uint32_t main_clk = Chip_Clock_GetMainClockRate();
|
||||
|
||||
return (div == 0) ? 0 : (main_clk / div);
|
||||
}
|
||||
|
||||
void Chip_Clock_SetIOCONCLKDIV(CHIP_PIN_CLKDIV_T reg, uint8_t div)
|
||||
{
|
||||
int t_reg = IOCONCLK_MAX-reg;
|
||||
LPC_SYSCTL->IOCONCLKDIV[t_reg] = div;
|
||||
}
|
||||
453
bsp/lpc824/Libraries/common/chip/clock_8xx.h
Normal file
453
bsp/lpc824/Libraries/common/chip/clock_8xx.h
Normal file
@@ -0,0 +1,453 @@
|
||||
/*
|
||||
* @brief LPC8xx clock driver
|
||||
*
|
||||
* @note
|
||||
* Copyright(C) NXP Semiconductors, 2012
|
||||
* All rights reserved.
|
||||
*
|
||||
* @par
|
||||
* Software that is described herein is for illustrative purposes only
|
||||
* which provides customers with programming information regarding the
|
||||
* LPC products. This software is supplied "AS IS" without any warranties of
|
||||
* any kind, and NXP Semiconductors and its licenser disclaim any and
|
||||
* all warranties, express or implied, including all implied warranties of
|
||||
* merchantability, fitness for a particular purpose and non-infringement of
|
||||
* intellectual property rights. NXP Semiconductors assumes no responsibility
|
||||
* or liability for the use of the software, conveys no license or rights under any
|
||||
* patent, copyright, mask work right, or any other intellectual property rights in
|
||||
* or to any products. NXP Semiconductors reserves the right to make changes
|
||||
* in the software without notification. NXP Semiconductors also makes no
|
||||
* representation or warranty that such application will be suitable for the
|
||||
* specified use without further testing or modification.
|
||||
*
|
||||
* @par
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation is hereby granted, under NXP Semiconductors' and its
|
||||
* licensor's relevant copyrights in the software, without fee, provided that it
|
||||
* is used in conjunction with NXP Semiconductors microcontrollers. This
|
||||
* copyright, permission, and disclaimer notice must appear in all copies of
|
||||
* this code.
|
||||
*/
|
||||
|
||||
#ifndef __CLOCK_8XX_H_
|
||||
#define __CLOCK_8XX_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @defgroup CLOCK_8XX CHIP: LPC8xx Clock Driver
|
||||
* @ingroup CHIP_8XX_Drivers
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Internal oscillator frequency */
|
||||
#define SYSCTL_IRC_FREQ (12000000)
|
||||
#ifndef MAX_CLOCK_FREQ
|
||||
#define MAX_CLOCK_FREQ (30000000)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Clock sources for system and USB PLLs
|
||||
*/
|
||||
typedef enum CHIP_SYSCTL_PLLCLKSRC {
|
||||
SYSCTL_PLLCLKSRC_IRC = 0, /*!< Internal oscillator */
|
||||
SYSCTL_PLLCLKSRC_SYSOSC, /*!< Crystal (system) oscillator */
|
||||
SYSCTL_PLLCLKSRC_RESERVED,
|
||||
SYSCTL_PLLCLKSRC_EXT_CLKIN, /*!< External clock input */
|
||||
} CHIP_SYSCTL_PLLCLKSRC_T;
|
||||
|
||||
/**
|
||||
* Watchdog oscillator analog output frequency selection
|
||||
* values enum (plus or minus 40%)
|
||||
*/
|
||||
typedef enum CHIP_WDTLFO_OSC {
|
||||
WDTLFO_OSC_ILLEGAL,
|
||||
WDTLFO_OSC_0_60, /*!< 0.6 MHz watchdog/LFO rate */
|
||||
WDTLFO_OSC_1_05, /*!< 1.05 MHz watchdog/LFO rate */
|
||||
WDTLFO_OSC_1_40, /*!< 1.4 MHz watchdog/LFO rate */
|
||||
WDTLFO_OSC_1_75, /*!< 1.75 MHz watchdog/LFO rate */
|
||||
WDTLFO_OSC_2_10, /*!< 2.1 MHz watchdog/LFO rate */
|
||||
WDTLFO_OSC_2_40, /*!< 2.4 MHz watchdog/LFO rate */
|
||||
WDTLFO_OSC_2_70, /*!< 2.7 MHz watchdog/LFO rate */
|
||||
WDTLFO_OSC_3_00, /*!< 3.0 MHz watchdog/LFO rate */
|
||||
WDTLFO_OSC_3_25, /*!< 3.25 MHz watchdog/LFO rate */
|
||||
WDTLFO_OSC_3_50, /*!< 3.5 MHz watchdog/LFO rate */
|
||||
WDTLFO_OSC_3_75, /*!< 3.75 MHz watchdog/LFO rate */
|
||||
WDTLFO_OSC_4_00, /*!< 4.0 MHz watchdog/LFO rate */
|
||||
WDTLFO_OSC_4_20, /*!< 4.2 MHz watchdog/LFO rate */
|
||||
WDTLFO_OSC_4_40, /*!< 4.4 MHz watchdog/LFO rate */
|
||||
WDTLFO_OSC_4_60 /*!< 4.6 MHz watchdog/LFO rate */
|
||||
} CHIP_WDTLFO_OSC_T;
|
||||
|
||||
/**
|
||||
* Clock sources for main system clock
|
||||
*/
|
||||
typedef enum CHIP_SYSCTL_MAINCLKSRC {
|
||||
SYSCTL_MAINCLKSRC_IRC = 0, /*!< Internal oscillator */
|
||||
SYSCTL_MAINCLKSRC_PLLIN, /*!< System PLL input */
|
||||
SYSCTL_MAINCLKSRC_WDTOSC, /*!< Watchdog oscillator rate */
|
||||
SYSCTL_MAINCLKSRC_PLLOUT, /*!< System PLL output */
|
||||
} CHIP_SYSCTL_MAINCLKSRC_T;
|
||||
|
||||
/**
|
||||
* System and peripheral clocks enum
|
||||
*/
|
||||
typedef enum CHIP_SYSCTL_CLOCK {
|
||||
SYSCTL_CLOCK_SYS = 0, /*!< System clock */
|
||||
SYSCTL_CLOCK_ROM, /*!< ROM clock */
|
||||
SYSCTL_CLOCK_RAM, /*!< RAM clock */
|
||||
SYSCTL_CLOCK_FLASHREG, /*!< FLASH register interface clock */
|
||||
SYSCTL_CLOCK_FLASH, /*!< FLASH array access clock */
|
||||
SYSCTL_CLOCK_I2C0, /*!< I2C0 clock */
|
||||
SYSCTL_CLOCK_GPIO, /*!< GPIO clock */
|
||||
SYSCTL_CLOCK_SWM, /*!< Switch matrix clock */
|
||||
SYSCTL_CLOCK_SCT, /*!< State configurable timer clock */
|
||||
SYSCTL_CLOCK_WKT, /*!< Self wake-up timer clock */
|
||||
SYSCTL_CLOCK_MRT, /*!< Multi-rate timer clock */
|
||||
SYSCTL_CLOCK_SPI0, /*!< SPI0 clock */
|
||||
SYSCTL_CLOCK_SPI1, /*!< SPI01 clock */
|
||||
SYSCTL_CLOCK_CRC, /*!< CRC clock */
|
||||
SYSCTL_CLOCK_UART0, /*!< UART0 clock */
|
||||
SYSCTL_CLOCK_UART1, /*!< UART1 clock */
|
||||
SYSCTL_CLOCK_UART2, /*!< UART2 clock */
|
||||
SYSCTL_CLOCK_WWDT, /*!< Watchdog clock */
|
||||
SYSCTL_CLOCK_IOCON, /*!< IOCON clock */
|
||||
SYSCTL_CLOCK_ACOMP, /*!< Analog comparator clock */
|
||||
|
||||
/* LPC82x Specific Clocks */
|
||||
SYSCTL_CLOCK_I2C1 = 21, /*!< I2C1 Clock */
|
||||
SYSCTL_CLOCK_I2C2, /*!< I2C2 Clock */
|
||||
SYSCTL_CLOCK_I2C3, /*!< I2C3 Clock */
|
||||
SYSCTL_CLOCK_ADC, /*!< 12-Bit ADC Clock */
|
||||
SYSCTL_CLOCK_MTB = 26, /*!< Macro Trace Buffer [USED FOR DEBUGGING] */
|
||||
SYSCTL_CLOCK_DMA = 29, /*!< DMA Clock */
|
||||
} CHIP_SYSCTL_CLOCK_T;
|
||||
|
||||
/* Clock name alias */
|
||||
#define SYSCTL_CLOCK_I2C SYSCTL_CLOCK_I2C0
|
||||
#define SYSCTL_CLOCK_ACMP SYSCTL_CLOCK_ACOMP
|
||||
|
||||
/**
|
||||
* Clock sources for CLKOUT
|
||||
*/
|
||||
typedef enum CHIP_SYSCTL_CLKOUTSRC {
|
||||
SYSCTL_CLKOUTSRC_IRC = 0, /*!< Internal oscillator for CLKOUT */
|
||||
SYSCTL_CLKOUTSRC_SYSOSC, /*!< System oscillator for CLKOUT */
|
||||
SYSCTL_CLKOUTSRC_WDTOSC, /*!< Watchdog oscillator for CLKOUT */
|
||||
SYSCTL_CLKOUTSRC_MAINSYSCLK, /*!< Main system clock for CLKOUT */
|
||||
} CHIP_SYSCTL_CLKOUTSRC_T;
|
||||
|
||||
/**
|
||||
* @brief Set System PLL divider values
|
||||
* @param msel : PLL feedback divider value
|
||||
* @param psel : PLL post divider value
|
||||
* @return Nothing
|
||||
* @note See the user manual for how to setup the PLL
|
||||
*/
|
||||
STATIC INLINE void Chip_Clock_SetupSystemPLL(uint8_t msel, uint8_t psel)
|
||||
{
|
||||
LPC_SYSCTL->SYSPLLCTRL = (msel & 0x1F) | ((psel & 0x3) << 5);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Read System PLL status
|
||||
* @return true if the PLL is locked, false if not locked
|
||||
*/
|
||||
STATIC INLINE bool Chip_Clock_IsSystemPLLLocked(void)
|
||||
{
|
||||
return (bool) ((LPC_SYSCTL->SYSPLLSTAT & 1) != 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Setup Watchdog oscillator rate and divider
|
||||
* @param wdtclk : Selected watchdog clock rate
|
||||
* @param div : Watchdog divider value, even value between 2 and 64
|
||||
* @return Nothing
|
||||
* @note Watchdog rate = selected rate divided by divider rate
|
||||
*/
|
||||
STATIC INLINE void Chip_Clock_SetWDTOSC(CHIP_WDTLFO_OSC_T wdtclk, uint8_t div)
|
||||
{
|
||||
LPC_SYSCTL->WDTOSCCTRL = (((uint32_t) wdtclk) << 5) | ((div >> 1) - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the main clock source
|
||||
* @return Main clock source
|
||||
*/
|
||||
STATIC INLINE CHIP_SYSCTL_MAINCLKSRC_T Chip_Clock_GetMainClockSource(void)
|
||||
{
|
||||
return (CHIP_SYSCTL_MAINCLKSRC_T) (LPC_SYSCTL->MAINCLKSEL & ~SYSCTL_MAINCLKSEL_RESERVED);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set system clock divider
|
||||
* @param div : divider for system clock
|
||||
* @return Nothing
|
||||
* @note Use 0 to disable, or a divider value of 1 to 255. The system clock
|
||||
* rate is the main system clock divided by this value.
|
||||
*/
|
||||
STATIC INLINE void Chip_Clock_SetSysClockDiv(uint32_t div)
|
||||
{
|
||||
LPC_SYSCTL->SYSAHBCLKDIV = div;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable system or peripheral clock
|
||||
* @param clk : Clock to enable
|
||||
* @return Nothing
|
||||
*/
|
||||
STATIC INLINE void Chip_Clock_EnablePeriphClock(CHIP_SYSCTL_CLOCK_T clk)
|
||||
{
|
||||
LPC_SYSCTL->SYSAHBCLKCTRL = (1 << clk) | (LPC_SYSCTL->SYSAHBCLKCTRL & ~SYSCTL_SYSAHBCLKCTRL_RESERVED);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disable system or peripheral clock
|
||||
* @param clk : Clock to disable
|
||||
* @return Nothing
|
||||
*/
|
||||
STATIC INLINE void Chip_Clock_DisablePeriphClock(CHIP_SYSCTL_CLOCK_T clk)
|
||||
{
|
||||
LPC_SYSCTL->SYSAHBCLKCTRL &= ~((1 << clk) | SYSCTL_SYSAHBCLKCTRL_RESERVED);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set UART divider clock
|
||||
* @param div : divider for UART clock
|
||||
* @return Nothing
|
||||
* @note Use 0 to disable, or a divider value of 1 to 255. The UART clock
|
||||
* rate is the main system clock divided by this value.
|
||||
*/
|
||||
STATIC INLINE void Chip_Clock_SetUARTClockDiv(uint32_t div)
|
||||
{
|
||||
LPC_SYSCTL->UARTCLKDIV = div;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return UART divider
|
||||
* @return divider for UART clock
|
||||
* @note A value of 0 means the clock is disabled.
|
||||
*/
|
||||
STATIC INLINE uint32_t Chip_Clock_GetUARTClockDiv(void)
|
||||
{
|
||||
return LPC_SYSCTL->UARTCLKDIV & ~SYSCTL_UARTCLKDIV_RESERVED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set The USART Fractional Generator Divider
|
||||
* @param div : Fractional Generator Divider value, should be 0xFF
|
||||
* @return Nothing
|
||||
*/
|
||||
STATIC INLINE void Chip_SYSCTL_SetUSARTFRGDivider(uint8_t div)
|
||||
{
|
||||
LPC_SYSCTL->UARTFRGDIV = (uint32_t) div;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get The USART Fractional Generator Divider
|
||||
* @return Value of USART Fractional Generator Divider
|
||||
*/
|
||||
STATIC INLINE uint32_t Chip_SYSCTL_GetUSARTFRGDivider(void)
|
||||
{
|
||||
return LPC_SYSCTL->UARTFRGDIV & ~SYSCTL_UARTFRGDIV_RESERVED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set The USART Fractional Generator Multiplier
|
||||
* @param mult : An 8-bit value (0-255) U_PCLK = UARTCLKDIV/(1 + MULT/256)
|
||||
* @return Nothing
|
||||
*/
|
||||
STATIC INLINE void Chip_SYSCTL_SetUSARTFRGMultiplier(uint8_t mult)
|
||||
{
|
||||
LPC_SYSCTL->UARTFRGMULT = (uint32_t) mult;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get The USART Fractional Generator Multiplier
|
||||
* @return Value of USART Fractional Generator Multiplier
|
||||
*/
|
||||
STATIC INLINE uint32_t Chip_SYSCTL_GetUSARTFRGMultiplier(void)
|
||||
{
|
||||
return LPC_SYSCTL->UARTFRGMULT & ~SYSCTL_UARTFRGMULT_RESERVED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set USART 0/1/2 UART base rate (up to main clock rate)
|
||||
* @param rate : Desired rate for fractional divider/multipler output
|
||||
* @param fEnable : true to use fractional clocking, false for integer clocking
|
||||
* @return Actual rate generated
|
||||
* @note USARTs 0 - 2 use the same base clock for their baud rate
|
||||
* basis. This function is used to generate that clock, while the
|
||||
* UART driver's SetBaud functions will attempt to get the closest
|
||||
* baud rate from this base clock without altering it. This needs
|
||||
* to be setup prior to individual UART setup.<br>
|
||||
* UARTs need a base clock 16x faster than the baud rate, so if you
|
||||
* need a 115.2Kbps baud rate, you will need a clock rate of at
|
||||
* least (115.2K * 16). The UART base clock is generated from the
|
||||
* main system clock, so fractional clocking may be the only
|
||||
* possible choice when using a low main system clock frequency.
|
||||
* Do not alter the FRGCLKDIV register after this call.
|
||||
*/
|
||||
uint32_t Chip_Clock_SetUSARTNBaseClockRate(uint32_t rate, bool fEnable);
|
||||
|
||||
/**
|
||||
* @brief Get USART 0/1/2 UART base rate
|
||||
* @return USART 0/1/2 UART base rate
|
||||
*/
|
||||
uint32_t Chip_Clock_GetUSARTNBaseClockRate(void);
|
||||
|
||||
/**
|
||||
* @brief Returns the main oscillator clock rate
|
||||
* @return main oscillator clock rate
|
||||
*/
|
||||
STATIC INLINE uint32_t Chip_Clock_GetMainOscRate(void)
|
||||
{
|
||||
return OscRateIn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the internal oscillator (IRC) clock rate
|
||||
* @return internal oscillator (IRC) clock rate
|
||||
*/
|
||||
STATIC INLINE uint32_t Chip_Clock_GetIntOscRate(void)
|
||||
{
|
||||
return SYSCTL_IRC_FREQ;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the external clock input rate
|
||||
* @return External clock input rate
|
||||
*/
|
||||
STATIC INLINE uint32_t Chip_Clock_GetExtClockInRate(void)
|
||||
{
|
||||
return ExtRateIn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set System PLL clock source
|
||||
* @param src : Clock source for system PLL
|
||||
* @return Nothing
|
||||
* @note This function will also toggle the clock source update register
|
||||
* to update the clock source
|
||||
*/
|
||||
void Chip_Clock_SetSystemPLLSource(CHIP_SYSCTL_PLLCLKSRC_T src);
|
||||
|
||||
/**
|
||||
* @brief Bypass System Oscillator and set oscillator frequency range
|
||||
* @param bypass : Flag to bypass oscillator
|
||||
* @param highfr : Flag to set oscillator range from 15-25 MHz
|
||||
* @return Nothing
|
||||
* @note Sets the PLL input to bypass the oscillator. This would be
|
||||
* used if an external clock that is not an oscillator is attached
|
||||
* to the XTALIN pin.
|
||||
*/
|
||||
void Chip_Clock_SetPLLBypass(bool bypass, bool highfr);
|
||||
|
||||
/**
|
||||
* @brief Set main system clock source
|
||||
* @param src : Clock source for main system
|
||||
* @return Nothing
|
||||
* @note This function will also toggle the clock source update register
|
||||
* to update the clock source
|
||||
*/
|
||||
void Chip_Clock_SetMainClockSource(CHIP_SYSCTL_MAINCLKSRC_T src);
|
||||
|
||||
/**
|
||||
* @brief Set CLKOUT clock source and divider
|
||||
* @param src : Clock source for CLKOUT
|
||||
* @param div : divider for CLKOUT clock
|
||||
* @return Nothing
|
||||
* @note Use 0 to disable, or a divider value of 1 to 255. The CLKOUT clock
|
||||
* rate is the clock source divided by the divider. This function will
|
||||
* also toggle the clock source update register to update the clock
|
||||
* source.
|
||||
*/
|
||||
void Chip_Clock_SetCLKOUTSource(CHIP_SYSCTL_CLKOUTSRC_T src, uint32_t div);
|
||||
|
||||
/**
|
||||
* @brief Return estimated watchdog oscillator rate
|
||||
* @return Estimated watchdog oscillator rate
|
||||
* @note This rate is accurate to plus or minus 40%.
|
||||
*/
|
||||
uint32_t Chip_Clock_GetWDTOSCRate(void);
|
||||
|
||||
/**
|
||||
* @brief Return System PLL input clock rate
|
||||
* @return System PLL input clock rate
|
||||
*/
|
||||
uint32_t Chip_Clock_GetSystemPLLInClockRate(void);
|
||||
|
||||
/**
|
||||
* @brief Return System PLL output clock rate
|
||||
* @return System PLL output clock rate
|
||||
*/
|
||||
uint32_t Chip_Clock_GetSystemPLLOutClockRate(void);
|
||||
|
||||
/**
|
||||
* @brief Return main clock rate
|
||||
* @return main clock rate
|
||||
*/
|
||||
uint32_t Chip_Clock_GetMainClockRate(void);
|
||||
|
||||
/**
|
||||
* @brief Return system clock rate
|
||||
* @return system clock rate
|
||||
*/
|
||||
uint32_t Chip_Clock_GetSystemClockRate(void);
|
||||
|
||||
/**
|
||||
* @brief Get IOCONCLKDIV clock rate
|
||||
* @param reg : Divider register to get
|
||||
* @return The clock rate going to the IOCON glitch filter
|
||||
* @note Use 0 to disable, or a divider value of 1 to 255.
|
||||
*/
|
||||
uint32_t Chip_Clock_GetIOCONCLKDIVClockRate(CHIP_PIN_CLKDIV_T reg);
|
||||
|
||||
/**
|
||||
* @brief Set IOCONCLKDIV divider
|
||||
* @param reg : divider register to set
|
||||
* @param div : divider value for IOCONCLKDIV[reg] clock
|
||||
* @return Nothing
|
||||
* @note Use 0 to disable, or a divider value of 1 to 255.
|
||||
*/
|
||||
void Chip_Clock_SetIOCONCLKDIV(CHIP_PIN_CLKDIV_T reg, uint8_t div);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup IRC_8XX CHIP: LPC8xx IRC Configuration
|
||||
* @ingroup CHIP_8XX_Drivers
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief set main / system clock using IRC and PLL
|
||||
* @param main: main clock frequency (in MHz)
|
||||
* @param sys : system clock frequency (in MHz)
|
||||
* @return bool: Success = true / fail = false
|
||||
* @note This is a table based function. The table uses both the
|
||||
* main frequency and the system frequency to set the PLL.
|
||||
* All useful main / system clock combinations are in the table.
|
||||
* See irc_8xx.c for details.
|
||||
*/
|
||||
bool Chip_IRC_SetFreq(uint32_t main, uint32_t sys);
|
||||
|
||||
/**
|
||||
* @brief Set main / system clock using IRC and PLL
|
||||
* @param sys : system clock frequency (in MHz)
|
||||
* @return Nothing
|
||||
* @note This function uses the ROM set_pll() function.
|
||||
*/
|
||||
void Chip_IRC_SetFreq_ROM(uint32_t sys);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __CLOCK_8XX_H_ */
|
||||
160
bsp/lpc824/Libraries/common/chip/cmsis.h
Normal file
160
bsp/lpc824/Libraries/common/chip/cmsis.h
Normal file
@@ -0,0 +1,160 @@
|
||||
/*
|
||||
* @brief Basic CMSIS include file
|
||||
*
|
||||
* @note
|
||||
* Copyright(C) NXP Semiconductors, 2013
|
||||
* All rights reserved.
|
||||
*
|
||||
* @par
|
||||
* Software that is described herein is for illustrative purposes only
|
||||
* which provides customers with programming information regarding the
|
||||
* LPC products. This software is supplied "AS IS" without any warranties of
|
||||
* any kind, and NXP Semiconductors and its licensor disclaim any and
|
||||
* all warranties, express or implied, including all implied warranties of
|
||||
* merchantability, fitness for a particular purpose and non-infringement of
|
||||
* intellectual property rights. NXP Semiconductors assumes no responsibility
|
||||
* or liability for the use of the software, conveys no license or rights under any
|
||||
* patent, copyright, mask work right, or any other intellectual property rights in
|
||||
* or to any products. NXP Semiconductors reserves the right to make changes
|
||||
* in the software without notification. NXP Semiconductors also makes no
|
||||
* representation or warranty that such application will be suitable for the
|
||||
* specified use without further testing or modification.
|
||||
*
|
||||
* @par
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation is hereby granted, under NXP Semiconductors' and its
|
||||
* licensor's relevant copyrights in the software, without fee, provided that it
|
||||
* is used in conjunction with NXP Semiconductors microcontrollers. This
|
||||
* copyright, permission, and disclaimer notice must appear in all copies of
|
||||
* this code.
|
||||
*/
|
||||
|
||||
#ifndef __CMSIS_H_
|
||||
#define __CMSIS_H_
|
||||
|
||||
#include "lpc_types.h"
|
||||
|
||||
// >>> system config
|
||||
#define CHIP_LPC8XX
|
||||
#define CHIP_LPC82X
|
||||
// <<<
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @defgroup CMSIS_8XX_ALL CHIP: LPC8xx CMSIS include file
|
||||
* @ingroup CHIP_8XX_Drivers
|
||||
* @{
|
||||
*/
|
||||
|
||||
#if defined(__ARMCC_VERSION)
|
||||
// Kill warning "#pragma push with no matching #pragma pop"
|
||||
#pragma diag_suppress 2525
|
||||
#pragma push
|
||||
#pragma anon_unions
|
||||
#elif defined(__CWCC__)
|
||||
#pragma push
|
||||
#pragma cpp_extensions on
|
||||
#elif defined(__GNUC__)
|
||||
/* anonymous unions are enabled by default */
|
||||
#elif defined(__IAR_SYSTEMS_ICC__)
|
||||
// #pragma push // FIXME not usable for IAR
|
||||
#pragma language=extended
|
||||
#else
|
||||
#error Not supported compiler type
|
||||
#endif
|
||||
|
||||
#if !defined(CORE_M0PLUS)
|
||||
#error Please #define CORE_M0PLUS
|
||||
#endif
|
||||
|
||||
/** @defgroup CMSIS_8XX CHIP: LPC8xx Cortex CMSIS definitions
|
||||
* @ingroup CMSIS_8XX_ALL
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Configuration of the Cortex-M0+ Processor and Core Peripherals */
|
||||
#define __CM0PLUS_REV 0x0001 /*!< Cortex-M0+ Core Revision */
|
||||
#define __MPU_PRESENT 0 /*!< MPU present or not */
|
||||
#define __VTOR_PRESENT 1 /*!< VTOR is present in this implementation */
|
||||
#define __NVIC_PRIO_BITS 2 /*!< Number of Bits used for Priority Levels */
|
||||
#define __Vendor_SysTickConfig 0 /*!< Set to 1 if different SysTick Config is used */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup CMSIS_8XX_IRQ CHIP: LPC8xx peripheral interrupt numbers
|
||||
* @ingroup CMSIS_8XX_ALL
|
||||
* @{
|
||||
*/
|
||||
|
||||
typedef enum {
|
||||
/****** Cortex-M0 Processor Exceptions Numbers ***************************************************/
|
||||
Reset_IRQn = -15, /*!< 1 Reset Vector, invoked on Power up and warm reset */
|
||||
NonMaskableInt_IRQn = -14, /*!< 2 Non Maskable Interrupt */
|
||||
HardFault_IRQn = -13, /*!< 3 Cortex-M0 Hard Fault Interrupt */
|
||||
SVCall_IRQn = -5, /*!< 11 Cortex-M0 SV Call Interrupt */
|
||||
PendSV_IRQn = -2, /*!< 14 Cortex-M0 Pend SV Interrupt */
|
||||
SysTick_IRQn = -1, /*!< 15 Cortex-M0 System Tick Interrupt */
|
||||
|
||||
/****** LPC8xx Specific Interrupt Numbers ********************************************************/
|
||||
SPI0_IRQn = 0, /*!< SPI0 */
|
||||
SPI1_IRQn = 1, /*!< SPI1 */
|
||||
Reserved0_IRQn = 2, /*!< Reserved Interrupt */
|
||||
UART0_IRQn = 3, /*!< USART0 */
|
||||
UART1_IRQn = 4, /*!< USART1 */
|
||||
UART2_IRQn = 5, /*!< USART2 */
|
||||
Reserved1_IRQn = 6, /*!< Reserved Interrupt */
|
||||
I2C1_IRQn = 7, /*!< I2C1 */
|
||||
I2C0_IRQn = 8, /*!< I2C0 */
|
||||
I2C_IRQn = 8, /*!< Alias for I2C0 */
|
||||
SCT_IRQn = 9, /*!< SCT */
|
||||
MRT_IRQn = 10, /*!< MRT */
|
||||
CMP_IRQn = 11, /*!< CMP */
|
||||
WDT_IRQn = 12, /*!< WDT */
|
||||
BOD_IRQn = 13, /*!< BOD */
|
||||
FLASH_IRQn = 14, /*!< Flash interrupt */
|
||||
WKT_IRQn = 15, /*!< WKT Interrupt */
|
||||
ADC_SEQA_IRQn = 16, /*!< ADC sequence A completion */
|
||||
ADC_SEQB_IRQn = 17, /*!< ADC sequence B completion */
|
||||
ADC_THCMP_IRQn = 18, /*!< ADC threshold compare */
|
||||
ADC_OVR_IRQn = 19, /*!< ADC overrun */
|
||||
DMA_IRQn = 20, /*!< Reserved Interrupt */
|
||||
I2C2_IRQn = 21, /*!< Reserved Interrupt */
|
||||
I2C3_IRQn = 22, /*!< Reserved Interrupt */
|
||||
Reserved2_IRQn = 23, /*!< Reserved Interrupt */
|
||||
PININT0_IRQn = 24, /*!< External Interrupt 0 */
|
||||
PIN_INT0_IRQn = 24, /*!< External Interrupt 0 (alias) */
|
||||
PININT1_IRQn = 25, /*!< External Interrupt 1 */
|
||||
PIN_INT1_IRQn = 25, /*!< External Interrupt 1 (alias) */
|
||||
PININT2_IRQn = 26, /*!< External Interrupt 2 */
|
||||
PIN_INT2_IRQn = 26, /*!< External Interrupt 2 (alias) */
|
||||
PININT3_IRQn = 27, /*!< External Interrupt 3 */
|
||||
PIN_INT3_IRQn = 27, /*!< External Interrupt 3 (alias) */
|
||||
PININT4_IRQn = 28, /*!< External Interrupt 4 */
|
||||
PIN_INT4_IRQn = 28, /*!< External Interrupt 4 (alias) */
|
||||
PININT5_IRQn = 29, /*!< External Interrupt 5 */
|
||||
PIN_INT5_IRQn = 29, /*!< External Interrupt 5 (alias) */
|
||||
PININT6_IRQn = 30, /*!< External Interrupt 6 */
|
||||
PIN_INT6_IRQn = 30, /*!< External Interrupt 6 (alias) */
|
||||
PININT7_IRQn = 31, /*!< External Interrupt 7 */
|
||||
PIN_INT7_IRQn = 31, /*!< External Interrupt 7 (alias) */
|
||||
} IRQn_Type;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include "core_cm0plus.h" /*!< Cortex-M0+ processor and core peripherals */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __CMSIS_H_ */
|
||||
100
bsp/lpc824/Libraries/common/chip/error_8xx.h
Normal file
100
bsp/lpc824/Libraries/common/chip/error_8xx.h
Normal file
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* @brief Error code returned by LPC8xx Boot ROM drivers/library functions
|
||||
*
|
||||
* @note
|
||||
* Copyright(C) NXP Semiconductors, 2012
|
||||
* All rights reserved.
|
||||
*
|
||||
* @par
|
||||
* Software that is described herein is for illustrative purposes only
|
||||
* which provides customers with programming information regarding the
|
||||
* LPC products. This software is supplied "AS IS" without any warranties of
|
||||
* any kind, and NXP Semiconductors and its licensor disclaim any and
|
||||
* all warranties, express or implied, including all implied warranties of
|
||||
* merchantability, fitness for a particular purpose and non-infringement of
|
||||
* intellectual property rights. NXP Semiconductors assumes no responsibility
|
||||
* or liability for the use of the software, conveys no license or rights under any
|
||||
* patent, copyright, mask work right, or any other intellectual property rights in
|
||||
* or to any products. NXP Semiconductors reserves the right to make changes
|
||||
* in the software without notification. NXP Semiconductors also makes no
|
||||
* representation or warranty that such application will be suitable for the
|
||||
* specified use without further testing or modification.
|
||||
*
|
||||
* @par
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation is hereby granted, under NXP Semiconductors' and its
|
||||
* licensor's relevant copyrights in the software, without fee, provided that it
|
||||
* is used in conjunction with NXP Semiconductors microcontrollers. This
|
||||
* copyright, permission, and disclaimer notice must appear in all copies of
|
||||
* this code.
|
||||
*/
|
||||
|
||||
#ifndef __ERROR_8XX_H__
|
||||
#define __ERROR_8XX_H__
|
||||
|
||||
/** @defgroup ROMAPI_ERRORCODES_8XX CHIP: LPC8xx ROM API error codes
|
||||
* @ingroup ROMAPI_8XX
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** Error code returned by Boot ROM drivers/library functions
|
||||
*
|
||||
* Error codes are a 32-bit value with :
|
||||
* - The 16 MSB contains the peripheral code number
|
||||
* - The 16 LSB contains an error code number associated to that peripheral
|
||||
*
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
/**\b 0x00000000*/ LPC_OK = 0, /**< enum value returned on Successful completion */
|
||||
/**\b 0x00000001*/ LPC_ERROR, /**< enum value returned on general error (I2C) */
|
||||
|
||||
/* ISP related errors */
|
||||
ERR_ISP_BASE = 0x00000000,
|
||||
/**\b 0x00000001*/ ERR_ISP_INVALID_COMMAND = ERR_ISP_BASE + 1,
|
||||
/**\b 0x00000002*/ ERR_ISP_SRC_ADDR_ERROR, /*!< Source address not on word boundary */
|
||||
/**\b 0x00000003*/ ERR_ISP_DST_ADDR_ERROR, /*!< Destination address not on word or 256 byte boundary */
|
||||
/**\b 0x00000004*/ ERR_ISP_SRC_ADDR_NOT_MAPPED,
|
||||
/**\b 0x00000005*/ ERR_ISP_DST_ADDR_NOT_MAPPED,
|
||||
/**\b 0x00000006*/ ERR_ISP_COUNT_ERROR, /*!< Byte count is not multiple of 4 or is not a permitted value */
|
||||
/**\b 0x00000007*/ ERR_ISP_INVALID_SECTOR,
|
||||
/**\b 0x00000008*/ ERR_ISP_SECTOR_NOT_BLANK,
|
||||
/**\b 0x00000009*/ ERR_ISP_SECTOR_NOT_PREPARED_FOR_WRITE_OPERATION,
|
||||
/**\b 0x0000000A*/ ERR_ISP_COMPARE_ERROR,
|
||||
/**\b 0x0000000B*/ ERR_ISP_BUSY, /*!< Flash programming hardware interface is busy */
|
||||
/**\b 0x0000000C*/ ERR_ISP_PARAM_ERROR, /*!< Insufficient number of parameters */
|
||||
/**\b 0x0000000D*/ ERR_ISP_ADDR_ERROR, /*!< Address not on word boundary */
|
||||
/**\b 0x0000000E*/ ERR_ISP_ADDR_NOT_MAPPED,
|
||||
/**\b 0x0000000F*/ ERR_ISP_CMD_LOCKED, /*!< Command is locked */
|
||||
/**\b 0x00000010*/ ERR_ISP_INVALID_CODE, /*!< Unlock code is invalid */
|
||||
/**\b 0x00000011*/ ERR_ISP_INVALID_BAUD_RATE,
|
||||
/**\b 0x00000012*/ ERR_ISP_INVALID_STOP_BIT,
|
||||
/**\b 0x00000013*/ ERR_ISP_CODE_READ_PROTECTION_ENABLED,
|
||||
|
||||
/* I2C related errors */
|
||||
ERR_I2C_BASE = 0x00060000,
|
||||
/**\b 0x00060001*/ ERR_I2C_NAK = ERR_I2C_BASE + 1, /*!< NAK */
|
||||
/**\b 0x00060002*/ ERR_I2C_BUFFER_OVERFLOW, /*!< Buffer overflow */
|
||||
/**\b 0x00060003*/ ERR_I2C_BYTE_COUNT_ERR, /*!< Byte count error */
|
||||
/**\b 0x00060004*/ ERR_I2C_LOSS_OF_ARBRITRATION, /*!< Loss of arbitration */
|
||||
/**\b 0x00060005*/ ERR_I2C_SLAVE_NOT_ADDRESSED, /*!< Slave not addressed */
|
||||
/**\b 0x00060006*/ ERR_I2C_LOSS_OF_ARBRITRATION_NAK_BIT, /*!< Loss arbritation NAK */
|
||||
/**\b 0x00060007*/ ERR_I2C_GENERAL_FAILURE, /*!< General failure */
|
||||
/**\b 0x00060008*/ ERR_I2C_REGS_SET_TO_DEFAULT, /*!< Set to default */
|
||||
/**\b 0x00060009*/ ERR_I2C_TIMEOUT, /*!< I2C Timeout */
|
||||
|
||||
/* UART related errors */
|
||||
/**\b 0x00080001*/ ERR_NO_ERROR = LPC_OK, /*!< Receive is busy */
|
||||
ERR_UART_BASE = 0x00080000,
|
||||
/**\b 0x00080001*/ ERR_UART_RXD_BUSY = ERR_UART_BASE + 1, /*!< Receive is busy */
|
||||
/**\b 0x00080002*/ ERR_UART_TXD_BUSY, /*!< Transmit is busy */
|
||||
/**\b 0x00080003*/ ERR_UART_OVERRUN_FRAME_PARITY_NOISE, /*!< Overrun, Frame, Parity , Receive Noise error */
|
||||
/**\b 0x00080004*/ ERR_UART_UNDERRUN, /*!< Underrun */
|
||||
/**\b 0x00080005*/ ERR_UART_PARAM, /*!< Parameter error */
|
||||
} ErrorCode_t;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* __ERROR_8XX_H__ */
|
||||
146
bsp/lpc824/Libraries/common/chip/fmc_8xx.h
Normal file
146
bsp/lpc824/Libraries/common/chip/fmc_8xx.h
Normal file
@@ -0,0 +1,146 @@
|
||||
/*
|
||||
* @brief LPC8xx FLASH Memory Controller (FMC) driver
|
||||
*
|
||||
* @note
|
||||
* Copyright(C) NXP Semiconductors, 2013
|
||||
* All rights reserved.
|
||||
*
|
||||
* @par
|
||||
* Software that is described herein is for illustrative purposes only
|
||||
* which provides customers with programming information regarding the
|
||||
* LPC products. This software is supplied "AS IS" without any warranties of
|
||||
* any kind, and NXP Semiconductors and its licensor disclaim any and
|
||||
* all warranties, express or implied, including all implied warranties of
|
||||
* merchantability, fitness for a particular purpose and non-infringement of
|
||||
* intellectual property rights. NXP Semiconductors assumes no responsibility
|
||||
* or liability for the use of the software, conveys no license or rights under any
|
||||
* patent, copyright, mask work right, or any other intellectual property rights in
|
||||
* or to any products. NXP Semiconductors reserves the right to make changes
|
||||
* in the software without notification. NXP Semiconductors also makes no
|
||||
* representation or warranty that such application will be suitable for the
|
||||
* specified use without further testing or modification.
|
||||
*
|
||||
* @par
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation is hereby granted, under NXP Semiconductors' and its
|
||||
* licensor's relevant copyrights in the software, without fee, provided that it
|
||||
* is used in conjunction with NXP Semiconductors microcontrollers. This
|
||||
* copyright, permission, and disclaimer notice must appear in all copies of
|
||||
* this code.
|
||||
*/
|
||||
|
||||
#ifndef __FMC_8XX_H_
|
||||
#define __FMC_8XX_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @defgroup FMC_8XX CHIP: LPC8xx FLASH Memory Controller driver
|
||||
* @ingroup CHIP_8XX_Drivers
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief FLASH Memory Controller Unit register block structure
|
||||
*/
|
||||
typedef struct {
|
||||
__I uint32_t RESERVED1[4];
|
||||
__IO uint32_t FLASHCFG; /*!< Flash Configuration register */
|
||||
__I uint32_t RESERVED2[3];
|
||||
__IO uint32_t FMSSTART; /*!< Signature start address register */
|
||||
__IO uint32_t FMSSTOP; /*!< Signature stop address register */
|
||||
__I uint32_t RESERVED3;
|
||||
__I uint32_t FMSW[1]; /*!< Signature word regsiter */
|
||||
} LPC_FMC_T;
|
||||
|
||||
/* Reserved bits masks for registers */
|
||||
#define FMC_FLASHCFG_RESERVED (~3)
|
||||
#define FMC_FMSSTART_RESERVED 0xfffe0000
|
||||
#define FMC_FMSSTOP_RESERVED 0x7ffe0000
|
||||
|
||||
/**
|
||||
* @brief FLASH Access time definitions
|
||||
*/
|
||||
typedef enum {
|
||||
FLASHTIM_20MHZ_CPU = 0, /*!< Flash accesses use 1 CPU clocks. Use for up to 20 MHz CPU clock*/
|
||||
FLASHTIM_30MHZ_CPU = 1, /*!< Flash accesses use 2 CPU clocks. Use for up to 30 MHz CPU clock*/
|
||||
} FMC_FLASHTIM_T;
|
||||
|
||||
/**
|
||||
* @brief Set FLASH memory access time in clocks
|
||||
* @param clks : Clock cycles for FLASH access
|
||||
* @return Nothing
|
||||
* @note For CPU speed up to 20MHz, use a value of 0. For up to 30MHz, use
|
||||
* a value of 1
|
||||
*/
|
||||
STATIC INLINE void Chip_FMC_SetFLASHAccess(FMC_FLASHTIM_T clks)
|
||||
{
|
||||
uint32_t tmp = LPC_FMC->FLASHCFG & (~((0x3)|FMC_FLASHCFG_RESERVED));
|
||||
|
||||
/* Don't alter upper bits */
|
||||
LPC_FMC->FLASHCFG = tmp | clks;
|
||||
}
|
||||
|
||||
/* Flash signature start and busy status bit */
|
||||
#define FMC_FLASHSIG_BUSY (1UL << 31)
|
||||
|
||||
/**
|
||||
* @brief Start computation of a signature for a FLASH memory range
|
||||
* @param start : Starting FLASH address for computation, must be aligned on 16 byte boundary
|
||||
* @param stop : Ending FLASH address for computation, must be aligned on 16 byte boundary
|
||||
* @return Nothing
|
||||
* @note Only bits 20..4 are used for the FLASH signature computation.
|
||||
* Use the Chip_FMC_IsSignatureBusy() function to determine when the
|
||||
* signature computation operation is complete and the
|
||||
* Chip_FMC_GetSignature() function to get the computed signature.
|
||||
*/
|
||||
STATIC INLINE void Chip_FMC_ComputeSignature(uint32_t start, uint32_t stop)
|
||||
{
|
||||
LPC_FMC->FMSSTART = (start >> 4);
|
||||
LPC_FMC->FMSSTOP = (stop >> 4) | FMC_FLASHSIG_BUSY;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Start computation of a signature for a FLASH memory address and block count
|
||||
* @param start : Starting FLASH address for computation, must be aligned on 16 byte boundary
|
||||
* @param blocks : Number of 16 byte blocks used for computation
|
||||
* @return Nothing
|
||||
* @note Only bits 20..4 are used for the FLASH signature computation.
|
||||
* Use the Chip_FMC_IsSignatureBusy() function to determine when the
|
||||
* signature computation operation is complete and the
|
||||
* Chip_FMC_GetSignature() function to get the computed signature.
|
||||
*/
|
||||
STATIC INLINE void Chip_FMC_ComputeSignatureBlocks(uint32_t start, uint32_t blocks)
|
||||
{
|
||||
Chip_FMC_ComputeSignature(start, (start + (blocks * 16)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check for signature geenration completion
|
||||
* @return true if the signature computation is running, false if finished
|
||||
*/
|
||||
STATIC INLINE bool Chip_FMC_IsSignatureBusy(void)
|
||||
{
|
||||
return (bool) ((LPC_FMC->FMSSTOP & FMC_FLASHSIG_BUSY) != 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the generated FLASH signature value
|
||||
* @param index : Signature index, must be 0
|
||||
* @return the generated FLASH signature value
|
||||
*/
|
||||
STATIC INLINE uint32_t Chip_FMC_GetSignature(int index)
|
||||
{
|
||||
return LPC_FMC->FMSW[index];
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __FMC_8XX_H_ */
|
||||
152
bsp/lpc824/Libraries/common/chip/ioswm_8xx.c
Normal file
152
bsp/lpc824/Libraries/common/chip/ioswm_8xx.c
Normal file
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
* @brief LPC8xx IOCON driver
|
||||
*
|
||||
* @note
|
||||
* Copyright(C) NXP Semiconductors, 2012
|
||||
* All rights reserved.
|
||||
*
|
||||
* @par
|
||||
* Software that is described herein is for illustrative purposes only
|
||||
* which provides customers with programming information regarding the
|
||||
* LPC products. This software is supplied "AS IS" without any warranties of
|
||||
* any kind, and NXP Semiconductors and its licenser disclaim any and
|
||||
* all warranties, express or implied, including all implied warranties of
|
||||
* merchantability, fitness for a particular purpose and non-infringement of
|
||||
* intellectual property rights. NXP Semiconductors assumes no responsibility
|
||||
* or liability for the use of the software, conveys no license or rights under any
|
||||
* patent, copyright, mask work right, or any other intellectual property rights in
|
||||
* or to any products. NXP Semiconductors reserves the right to make changes
|
||||
* in the software without notification. NXP Semiconductors also makes no
|
||||
* representation or warranty that such application will be suitable for the
|
||||
* specified use without further testing or modification.
|
||||
*
|
||||
* @par
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation is hereby granted, under NXP Semiconductors' and its
|
||||
* licensor's relevant copyrights in the software, without fee, provided that it
|
||||
* is used in conjunction with NXP Semiconductors microcontrollers. This
|
||||
* copyright, permission, and disclaimer notice must appear in all copies of
|
||||
* this code.
|
||||
*/
|
||||
#define _CHIP_COMMON_
|
||||
#include "chip.h"
|
||||
|
||||
/*****************************************************************************
|
||||
* Private types/enumerations/variables
|
||||
****************************************************************************/
|
||||
|
||||
#define PINASSIGN_IDX(movable) (((movable) >> 4))
|
||||
#define PINSHIFT(movable) (((movable) & 0xF) << 3)
|
||||
|
||||
/*****************************************************************************
|
||||
* Public types/enumerations/variables
|
||||
****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* Private functions
|
||||
****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* Public functions
|
||||
****************************************************************************/
|
||||
|
||||
/* Set the pin mode (pull-up/pull-down). */
|
||||
void Chip_IOCON_PinSetMode(LPC_IOCON_T *pIOCON, CHIP_PINx_T pin, CHIP_PIN_MODE_T mode)
|
||||
{
|
||||
uint32_t reg;
|
||||
|
||||
reg = pIOCON->PIO0[pin] & ~(PIN_MODE_MASK);
|
||||
pIOCON->PIO0[pin] = reg | (mode << PIN_MODE_BITNUM);
|
||||
}
|
||||
|
||||
/* Enables/disables the pin hysteresis. */
|
||||
void Chip_IOCON_PinSetHysteresis(LPC_IOCON_T *pIOCON, CHIP_PINx_T pin, bool enable)
|
||||
{
|
||||
if (enable == true) {
|
||||
Chip_IOCON_PinEnableHysteresis(pIOCON, pin);
|
||||
}
|
||||
else {
|
||||
Chip_IOCON_PinDisableHysteresis(pIOCON, pin);
|
||||
}
|
||||
}
|
||||
|
||||
/*Inverts (or not) the input seen by a pin. */
|
||||
void Chip_IOCON_PinSetInputInverted(LPC_IOCON_T *pIOCON, CHIP_PINx_T pin, bool invert)
|
||||
{
|
||||
if (invert == true) {
|
||||
Chip_IOCON_PinEnableInputInverted(pIOCON, pin);
|
||||
}
|
||||
else {
|
||||
Chip_IOCON_PinDisableInputInverted(pIOCON, pin);
|
||||
}
|
||||
}
|
||||
|
||||
/* Enables/disables Open-Drain mode for a pin. */
|
||||
void Chip_IOCON_PinSetOpenDrainMode(LPC_IOCON_T *pIOCON, CHIP_PINx_T pin, bool open_drain)
|
||||
{
|
||||
if (open_drain == true) {
|
||||
Chip_IOCON_PinEnableOpenDrainMode(pIOCON, pin);
|
||||
}
|
||||
else {
|
||||
Chip_IOCON_PinDisableOpenDrainMode(pIOCON, pin);
|
||||
}
|
||||
}
|
||||
|
||||
/* Enable/configure digital filter sample mode for a pin. */
|
||||
void Chip_IOCON_PinSetSampleMode(LPC_IOCON_T *pIOCON, CHIP_PINx_T pin, CHIP_PIN_SMODE_T smode)
|
||||
{
|
||||
uint32_t reg;
|
||||
|
||||
reg = pIOCON->PIO0[pin] & ~(PIN_SMODE_MASK);
|
||||
pIOCON->PIO0[pin] = reg | (smode << PIN_SMODE_BITNUM);
|
||||
}
|
||||
|
||||
/* Set the peripheral clock divisor for a pin. */
|
||||
void Chip_IOCON_PinSetClockDivisor(LPC_IOCON_T *pIOCON, CHIP_PINx_T pin, CHIP_PIN_CLKDIV_T clkdiv)
|
||||
{
|
||||
uint32_t reg;
|
||||
|
||||
reg = pIOCON->PIO0[pin] & ~(PIN_CLKDIV_MASK);
|
||||
pIOCON->PIO0[pin] = reg | (clkdiv << PIN_CLKDIV_BITNUM);
|
||||
}
|
||||
|
||||
/* Set the I2C mode for a pin. */
|
||||
void Chip_IOCON_PinSetI2CMode(LPC_IOCON_T *pIOCON, CHIP_PINx_T pin, CHIP_PIN_I2CMODE_T mode)
|
||||
{
|
||||
uint32_t reg;
|
||||
|
||||
/* I2C mode bits only for I2C pins */
|
||||
reg = pIOCON->PIO0[pin] & ~(PIN_I2CMODE_MASK);
|
||||
pIOCON->PIO0[pin] = reg | (mode << PIN_I2CMODE_BITNUM);
|
||||
}
|
||||
|
||||
/* Set all I/O Control pin muxing */
|
||||
void Chip_IOCON_SetPinMuxing(LPC_IOCON_T *pIOCON, const PINMUX_GRP_T* pinArray, uint32_t arrayLength)
|
||||
{
|
||||
uint32_t ix;
|
||||
|
||||
for (ix = 0; ix < arrayLength; ix++ ) {
|
||||
Chip_IOCON_PinMuxSet(pIOCON, pinArray[ix].pin, pinArray[ix].modefunc);
|
||||
}
|
||||
}
|
||||
|
||||
/* assign a movable pin function to a physical pin */
|
||||
void Chip_SWM_MovablePinAssign(CHIP_SWM_PIN_MOVABLE_T movable, uint8_t pin)
|
||||
{
|
||||
uint32_t temp;
|
||||
int pinshift = PINSHIFT(movable), regIndex = PINASSIGN_IDX(movable);
|
||||
|
||||
temp = LPC_SWM->PINASSIGN[regIndex] & (~(0xFF << pinshift));
|
||||
LPC_SWM->PINASSIGN[regIndex] = temp | (pin << pinshift);
|
||||
}
|
||||
|
||||
/* true enables, false disables a Switch Matrix fixed-pin Function */
|
||||
void Chip_SWM_FixedPinEnable(CHIP_SWM_PIN_FIXED_T pin, bool enable)
|
||||
{
|
||||
if (enable) {
|
||||
Chip_SWM_EnableFixedPin(pin);
|
||||
}
|
||||
else {
|
||||
Chip_SWM_DisableFixedPin(pin);
|
||||
}
|
||||
}
|
||||
601
bsp/lpc824/Libraries/common/chip/ioswm_8xx.h
Normal file
601
bsp/lpc824/Libraries/common/chip/ioswm_8xx.h
Normal file
File diff suppressed because it is too large
Load Diff
216
bsp/lpc824/Libraries/common/chip/lpc_types.h
Normal file
216
bsp/lpc824/Libraries/common/chip/lpc_types.h
Normal file
@@ -0,0 +1,216 @@
|
||||
/*
|
||||
* @brief Common types used in LPC functions
|
||||
*
|
||||
* @note
|
||||
* Copyright(C) NXP Semiconductors, 2012
|
||||
* All rights reserved.
|
||||
*
|
||||
* @par
|
||||
* Software that is described herein is for illustrative purposes only
|
||||
* which provides customers with programming information regarding the
|
||||
* LPC products. This software is supplied "AS IS" without any warranties of
|
||||
* any kind, and NXP Semiconductors and its licensor disclaim any and
|
||||
* all warranties, express or implied, including all implied warranties of
|
||||
* merchantability, fitness for a particular purpose and non-infringement of
|
||||
* intellectual property rights. NXP Semiconductors assumes no responsibility
|
||||
* or liability for the use of the software, conveys no license or rights under any
|
||||
* patent, copyright, mask work right, or any other intellectual property rights in
|
||||
* or to any products. NXP Semiconductors reserves the right to make changes
|
||||
* in the software without notification. NXP Semiconductors also makes no
|
||||
* representation or warranty that such application will be suitable for the
|
||||
* specified use without further testing or modification.
|
||||
*
|
||||
* @par
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation is hereby granted, under NXP Semiconductors' and its
|
||||
* licensor's relevant copyrights in the software, without fee, provided that it
|
||||
* is used in conjunction with NXP Semiconductors microcontrollers. This
|
||||
* copyright, permission, and disclaimer notice must appear in all copies of
|
||||
* this code.
|
||||
*/
|
||||
|
||||
#ifndef __LPC_TYPES_H_
|
||||
#define __LPC_TYPES_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
/** @defgroup LPC_Types CHIP: LPC Common Types
|
||||
* @ingroup CHIP_Common
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup LPC_Types_Public_Types LPC Public Types
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Boolean Type definition
|
||||
*/
|
||||
typedef enum {FALSE = 0, TRUE = !FALSE} Bool;
|
||||
|
||||
/**
|
||||
* @brief Boolean Type definition
|
||||
*/
|
||||
#if !defined(__cplusplus)
|
||||
// typedef enum {false = 0, true = !false} bool;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Flag Status and Interrupt Flag Status type definition
|
||||
*/
|
||||
typedef enum {RESET = 0, SET = !RESET} FlagStatus, IntStatus, SetState;
|
||||
#define PARAM_SETSTATE(State) ((State == RESET) || (State == SET))
|
||||
|
||||
/**
|
||||
* @brief Functional State Definition
|
||||
*/
|
||||
typedef enum {DISABLE = 0, ENABLE = !DISABLE} FunctionalState;
|
||||
#define PARAM_FUNCTIONALSTATE(State) ((State == DISABLE) || (State == ENABLE))
|
||||
|
||||
/**
|
||||
* @ Status type definition
|
||||
*/
|
||||
typedef enum {ERROR = 0, SUCCESS = !ERROR} Status;
|
||||
|
||||
/**
|
||||
* Read/Write transfer type mode (Block or non-block)
|
||||
*/
|
||||
typedef enum {
|
||||
NONE_BLOCKING = 0, /**< None Blocking type */
|
||||
BLOCKING, /**< Blocking type */
|
||||
} TRANSFER_BLOCK_T;
|
||||
|
||||
/** Pointer to Function returning Void (any number of parameters) */
|
||||
typedef void (*PFV)();
|
||||
|
||||
/** Pointer to Function returning int32_t (any number of parameters) */
|
||||
typedef int32_t (*PFI)();
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup LPC_Types_Public_Macros LPC Public Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* _BIT(n) sets the bit at position "n"
|
||||
* _BIT(n) is intended to be used in "OR" and "AND" expressions:
|
||||
* e.g., "(_BIT(3) | _BIT(7))".
|
||||
*/
|
||||
#undef _BIT
|
||||
/* Set bit macro */
|
||||
#define _BIT(n) (1 << (n))
|
||||
|
||||
/* _SBF(f,v) sets the bit field starting at position "f" to value "v".
|
||||
* _SBF(f,v) is intended to be used in "OR" and "AND" expressions:
|
||||
* e.g., "((_SBF(5,7) | _SBF(12,0xF)) & 0xFFFF)"
|
||||
*/
|
||||
#undef _SBF
|
||||
/* Set bit field macro */
|
||||
#define _SBF(f, v) ((v) << (f))
|
||||
|
||||
/* _BITMASK constructs a symbol with 'field_width' least significant
|
||||
* bits set.
|
||||
* e.g., _BITMASK(5) constructs '0x1F', _BITMASK(16) == 0xFFFF
|
||||
* The symbol is intended to be used to limit the bit field width
|
||||
* thusly:
|
||||
* <a_register> = (any_expression) & _BITMASK(x), where 0 < x <= 32.
|
||||
* If "any_expression" results in a value that is larger than can be
|
||||
* contained in 'x' bits, the bits above 'x - 1' are masked off. When
|
||||
* used with the _SBF example above, the example would be written:
|
||||
* a_reg = ((_SBF(5,7) | _SBF(12,0xF)) & _BITMASK(16))
|
||||
* This ensures that the value written to a_reg is no wider than
|
||||
* 16 bits, and makes the code easier to read and understand.
|
||||
*/
|
||||
#undef _BITMASK
|
||||
/* Bitmask creation macro */
|
||||
#define _BITMASK(field_width) ( _BIT(field_width) - 1)
|
||||
|
||||
/* NULL pointer */
|
||||
#ifndef NULL
|
||||
#define NULL ((void *) 0)
|
||||
#endif
|
||||
|
||||
/* Number of elements in an array */
|
||||
#define NELEMENTS(array) (sizeof(array) / sizeof(array[0]))
|
||||
|
||||
/* Static data/function define */
|
||||
#define STATIC static
|
||||
/* External data/function define */
|
||||
#define EXTERN extern
|
||||
|
||||
#if !defined(MAX)
|
||||
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
|
||||
#endif
|
||||
#if !defined(MIN)
|
||||
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/* Old Type Definition compatibility */
|
||||
/** @addtogroup LPC_Types_Public_Types
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** LPC type for character type */
|
||||
typedef char CHAR;
|
||||
|
||||
/** LPC type for 8 bit unsigned value */
|
||||
typedef uint8_t UNS_8;
|
||||
|
||||
/** LPC type for 8 bit signed value */
|
||||
typedef int8_t INT_8;
|
||||
|
||||
/** LPC type for 16 bit unsigned value */
|
||||
typedef uint16_t UNS_16;
|
||||
|
||||
/** LPC type for 16 bit signed value */
|
||||
typedef int16_t INT_16;
|
||||
|
||||
/** LPC type for 32 bit unsigned value */
|
||||
typedef uint32_t UNS_32;
|
||||
|
||||
/** LPC type for 32 bit signed value */
|
||||
typedef int32_t INT_32;
|
||||
|
||||
/** LPC type for 64 bit signed value */
|
||||
typedef int64_t INT_64;
|
||||
|
||||
/** LPC type for 64 bit unsigned value */
|
||||
typedef uint64_t UNS_64;
|
||||
|
||||
#ifdef __CODE_RED
|
||||
#define BOOL_32 bool
|
||||
#define BOOL_16 bool
|
||||
#define BOOL_8 bool
|
||||
#else
|
||||
/** 32 bit boolean type */
|
||||
typedef bool BOOL_32;
|
||||
|
||||
/** 16 bit boolean type */
|
||||
typedef bool BOOL_16;
|
||||
|
||||
/** 8 bit boolean type */
|
||||
typedef bool BOOL_8;
|
||||
#endif
|
||||
|
||||
#ifdef __CC_ARM
|
||||
#define INLINE __inline
|
||||
#else
|
||||
#define INLINE inline
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* __LPC_TYPES_H_ */
|
||||
107
bsp/lpc824/Libraries/common/chip/syscon_8xx.c
Normal file
107
bsp/lpc824/Libraries/common/chip/syscon_8xx.c
Normal file
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* @brief LPC8xx System & Control driver
|
||||
*
|
||||
* @note
|
||||
* Copyright(C) NXP Semiconductors, 2012
|
||||
* All rights reserved.
|
||||
*
|
||||
* @par
|
||||
* Software that is described herein is for illustrative purposes only
|
||||
* which provides customers with programming information regarding the
|
||||
* LPC products. This software is supplied "AS IS" without any warranties of
|
||||
* any kind, and NXP Semiconductors and its licenser disclaim any and
|
||||
* all warranties, express or implied, including all implied warranties of
|
||||
* merchantability, fitness for a particular purpose and non-infringement of
|
||||
* intellectual property rights. NXP Semiconductors assumes no responsibility
|
||||
* or liability for the use of the software, conveys no license or rights under any
|
||||
* patent, copyright, mask work right, or any other intellectual property rights in
|
||||
* or to any products. NXP Semiconductors reserves the right to make changes
|
||||
* in the software without notification. NXP Semiconductors also makes no
|
||||
* representation or warranty that such application will be suitable for the
|
||||
* specified use without further testing or modification.
|
||||
*
|
||||
* @par
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation is hereby granted, under NXP Semiconductors' and its
|
||||
* licensor's relevant copyrights in the software, without fee, provided that it
|
||||
* is used in conjunction with NXP Semiconductors microcontrollers. This
|
||||
* copyright, permission, and disclaimer notice must appear in all copies of
|
||||
* this code.
|
||||
*/
|
||||
#define _CHIP_COMMON_
|
||||
#include "chip.h"
|
||||
|
||||
/*****************************************************************************
|
||||
* Private types/enumerations/variables
|
||||
****************************************************************************/
|
||||
|
||||
/* PDSLEEPCFG register mask */
|
||||
#define PDSLEEPWRMASK (0x0000FFB7)
|
||||
#define PDSLEEPDATMASK (0x00000048)
|
||||
|
||||
#if defined(CHIP_LPC82X)
|
||||
/* PDWAKECFG and PDRUNCFG register masks */
|
||||
#define PDWAKEUPWRMASK (0x00006D00)
|
||||
#define PDWAKEUPDATMASK (0x000080FF)
|
||||
|
||||
#else
|
||||
/* PDWAKECFG and PDRUNCFG register masks */
|
||||
#define PDWAKEUPWRMASK (0x00006D10)
|
||||
#define PDWAKEUPDATMASK (0x000080EF)
|
||||
#endif
|
||||
|
||||
/*****************************************************************************
|
||||
* Public types/enumerations/variables
|
||||
****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* Private functions
|
||||
****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* Public functions
|
||||
****************************************************************************/
|
||||
|
||||
/* Setup deep sleep behaviour for power down */
|
||||
void Chip_SYSCTL_SetDeepSleepPD(uint32_t sleepmask)
|
||||
{
|
||||
/* Update new value */
|
||||
LPC_SYSCTL->PDSLEEPCFG = PDSLEEPWRMASK | (sleepmask & PDSLEEPDATMASK);
|
||||
}
|
||||
|
||||
/* Setup wakeup behaviour from deep sleep */
|
||||
void Chip_SYSCTL_SetWakeup(uint32_t wakeupmask)
|
||||
{
|
||||
/* Update new value */
|
||||
LPC_SYSCTL->PDAWAKECFG = PDWAKEUPWRMASK | (wakeupmask & PDWAKEUPDATMASK);
|
||||
}
|
||||
|
||||
/* Power down one or more blocks or peripherals */
|
||||
void Chip_SYSCTL_PowerDown(uint32_t powerdownmask)
|
||||
{
|
||||
uint32_t pdrun;
|
||||
|
||||
/* Get current power states */
|
||||
pdrun = LPC_SYSCTL->PDRUNCFG & PDWAKEUPDATMASK;
|
||||
|
||||
/* Disable peripheral states by setting high */
|
||||
pdrun |= (powerdownmask & PDWAKEUPDATMASK);
|
||||
|
||||
/* Update power states with required register bits */
|
||||
LPC_SYSCTL->PDRUNCFG = (PDWAKEUPWRMASK | pdrun);
|
||||
}
|
||||
|
||||
/* Power up one or more blocks or peripherals */
|
||||
void Chip_SYSCTL_PowerUp(uint32_t powerupmask)
|
||||
{
|
||||
uint32_t pdrun;
|
||||
|
||||
/* Get current power states */
|
||||
pdrun = LPC_SYSCTL->PDRUNCFG & PDWAKEUPDATMASK;
|
||||
|
||||
/* Enable peripheral states by setting low */
|
||||
pdrun &= ~(powerupmask & PDWAKEUPDATMASK);
|
||||
|
||||
/* Update power states with required register bits */
|
||||
LPC_SYSCTL->PDRUNCFG = (PDWAKEUPWRMASK | pdrun);
|
||||
}
|
||||
573
bsp/lpc824/Libraries/common/chip/syscon_8xx.h
Normal file
573
bsp/lpc824/Libraries/common/chip/syscon_8xx.h
Normal file
File diff suppressed because it is too large
Load Diff
115
bsp/lpc824/Libraries/common/chip/sysinit_8xx.c
Normal file
115
bsp/lpc824/Libraries/common/chip/sysinit_8xx.c
Normal file
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* @brief LPC8xx Chip specific SystemInit
|
||||
*
|
||||
* @note
|
||||
* Copyright(C) NXP Semiconductors, 2013
|
||||
* All rights reserved.
|
||||
*
|
||||
* @par
|
||||
* Software that is described herein is for illustrative purposes only
|
||||
* which provides customers with programming information regarding the
|
||||
* LPC products. This software is supplied "AS IS" without any warranties of
|
||||
* any kind, and NXP Semiconductors and its licensor disclaim any and
|
||||
* all warranties, express or implied, including all implied warranties of
|
||||
* merchantability, fitness for a particular purpose and non-infringement of
|
||||
* intellectual property rights. NXP Semiconductors assumes no responsibility
|
||||
* or liability for the use of the software, conveys no license or rights under any
|
||||
* patent, copyright, mask work right, or any other intellectual property rights in
|
||||
* or to any products. NXP Semiconductors reserves the right to make changes
|
||||
* in the software without notification. NXP Semiconductors also makes no
|
||||
* representation or warranty that such application will be suitable for the
|
||||
* specified use without further testing or modification.
|
||||
*
|
||||
* @par
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation is hereby granted, under NXP Semiconductors' and its
|
||||
* licensor's relevant copyrights in the software, without fee, provided that it
|
||||
* is used in conjunction with NXP Semiconductors microcontrollers. This
|
||||
* copyright, permission, and disclaimer notice must appear in all copies of
|
||||
* this code.
|
||||
*/
|
||||
#define _CHIP_COMMON_
|
||||
#include "board_lpc.h"
|
||||
|
||||
/*****************************************************************************
|
||||
* Private types/enumerations/variables
|
||||
****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* Public types/enumerations/variables
|
||||
****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* Private functions
|
||||
****************************************************************************/
|
||||
#define CONFIG_MAIN_FREQ 60000000
|
||||
#define CONFIG_SYS_FREQ MAX_CLOCK_FREQ
|
||||
|
||||
/*****************************************************************************
|
||||
* Public functions
|
||||
****************************************************************************/
|
||||
|
||||
/* Setup system clocking */
|
||||
void Chip_SetupXtalClocking(void)
|
||||
{
|
||||
/* EXT oscillator < 15MHz */
|
||||
Chip_Clock_SetPLLBypass(false, false);
|
||||
|
||||
/* Turn on the SYSOSC by clearing the power down bit */
|
||||
Chip_SYSCTL_PowerUp(SYSCTL_SLPWAKE_SYSOSC_PD);
|
||||
|
||||
/* Select the PLL input to the external oscillator */
|
||||
Chip_Clock_SetSystemPLLSource(SYSCTL_PLLCLKSRC_SYSOSC);
|
||||
|
||||
/* Setup FLASH access to 2 clocks (up to 30MHz) */
|
||||
Chip_FMC_SetFLASHAccess(FLASHTIM_30MHZ_CPU);
|
||||
|
||||
/* Power down PLL to change the PLL divider ratio */
|
||||
Chip_SYSCTL_PowerDown(SYSCTL_SLPWAKE_SYSPLL_PD);
|
||||
|
||||
/* Configure the PLL M and P dividers */
|
||||
/* Setup PLL for main oscillator rate ((FCLKIN = 12MHz) * 5)/2 = 30MHz */
|
||||
Chip_Clock_SetupSystemPLL(4, 1);
|
||||
|
||||
/* Turn on the PLL by clearing the power down bit */
|
||||
Chip_SYSCTL_PowerUp(SYSCTL_SLPWAKE_SYSPLL_PD);
|
||||
|
||||
/* Enable the clock to the Switch Matrix */
|
||||
Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SWM);
|
||||
|
||||
/* Wait for PLL to lock */
|
||||
while (!Chip_Clock_IsSystemPLLLocked()) {}
|
||||
|
||||
Chip_Clock_SetSysClockDiv(2);
|
||||
|
||||
/* Set main clock source to the system PLL. This will drive 24MHz
|
||||
for the main clock and 24MHz for the system clock */
|
||||
Chip_Clock_SetMainClockSource(SYSCTL_MAINCLKSRC_PLLOUT);
|
||||
}
|
||||
|
||||
/* Set up and initialize hardware prior to call to main */
|
||||
void Chip_SetupIrcClocking(void)
|
||||
{
|
||||
Chip_IRC_SetFreq(CONFIG_MAIN_FREQ, CONFIG_SYS_FREQ);
|
||||
}
|
||||
|
||||
/* Set up and initialize hardware prior to call to main */
|
||||
/* 在main()函数之前调用此函数做基本的初始化工作 */
|
||||
void SystemInit(void)
|
||||
{
|
||||
Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_IOCON);
|
||||
#ifdef USE_IRC_AS_ROOT_CLOCK
|
||||
/* Use 12MHz IRC as clock source */
|
||||
Chip_SetupIrcClocking();
|
||||
#else
|
||||
/* Use Xtal or external clock_in as clock source*/
|
||||
Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SWM);
|
||||
Chip_SWM_EnableFixedPin(SWM_FIXED_XTALIN);
|
||||
Chip_SWM_EnableFixedPin(SWM_FIXED_XTALOUT);
|
||||
// Chip_Clock_DisablePeriphClock(SYSCTL_CLOCK_SWM);
|
||||
Chip_IOCON_PinSetMode(LPC_IOCON, IOCON_PIO8, PIN_MODE_INACTIVE);
|
||||
Chip_IOCON_PinSetMode(LPC_IOCON, IOCON_PIO9, PIN_MODE_INACTIVE);
|
||||
|
||||
Chip_SetupXtalClocking();
|
||||
#endif
|
||||
}
|
||||
188
bsp/lpc824/Libraries/common/startup/iar_startup_lpc82x.s
Normal file
188
bsp/lpc824/Libraries/common/startup/iar_startup_lpc82x.s
Normal file
@@ -0,0 +1,188 @@
|
||||
/**************************************************
|
||||
*
|
||||
* Part one of the system initialization code, contains low-level
|
||||
* initialization, plain thumb variant.
|
||||
*
|
||||
* Copyright 2009 IAR Systems. All rights reserved.
|
||||
*
|
||||
* $Revision: 33183 $
|
||||
*
|
||||
**************************************************/
|
||||
|
||||
;
|
||||
; The modules in this file are included in the libraries, and may be replaced
|
||||
; by any user-defined modules that define the PUBLIC symbol _program_start or
|
||||
; a user defined start symbol.
|
||||
; To override the cstartup defined in the library, simply add your modified
|
||||
; version to the workbench project.
|
||||
;
|
||||
; The vector table is normally located at address 0.
|
||||
; When debugging in RAM, it can be located in RAM, aligned to at least 2^6.
|
||||
; The name "__vector_table" has special meaning for C-SPY:
|
||||
; it is where the SP start value is found, and the NVIC vector
|
||||
; table register (VTOR) is initialized to this address if != 0.
|
||||
;
|
||||
; Cortex-M version
|
||||
;
|
||||
|
||||
MODULE ?cstartup
|
||||
|
||||
;; Forward declaration of sections.
|
||||
SECTION CSTACK:DATA:NOROOT(3)
|
||||
|
||||
SECTION .intvec:CODE:NOROOT(2)
|
||||
|
||||
EXTERN __iar_program_start
|
||||
EXTERN SystemInit
|
||||
EXTERN IRC_Only_SystemInit
|
||||
|
||||
PUBLIC __vector_table
|
||||
PUBLIC __vector_table_0x1c
|
||||
DATA
|
||||
__vector_table
|
||||
DCD sfe(CSTACK) ; Top of Stack
|
||||
DCD Reset_Handler ; Reset Handler
|
||||
DCD NMI_Handler ; NMI Handler
|
||||
DCD HardFault_Handler ; Hard Fault Handler
|
||||
__vector_table_0x1c
|
||||
DCD 0 ; Reserved
|
||||
DCD 0 ; Reserved
|
||||
DCD 0 ; Reserved
|
||||
DCD 0 ; Reserved
|
||||
DCD 0 ; Reserved
|
||||
DCD 0 ; Reserved
|
||||
DCD 0 ; Reserved
|
||||
DCD SVC_Handler ; SVCall Handler
|
||||
DCD 0 ; Reserved
|
||||
DCD 0 ; Reserved
|
||||
DCD PendSV_Handler ; PendSV Handler
|
||||
DCD SysTick_Handler ; SysTick Handler
|
||||
|
||||
|
||||
; External Interrupts
|
||||
DCD SPI0_IRQHandler ; SPI0 controller
|
||||
DCD SPI1_IRQHandler ; SPI1 controller
|
||||
DCD 0 ; Reserved
|
||||
DCD UART0_IRQHandler ; UART0
|
||||
DCD UART1_IRQHandler ; UART1
|
||||
DCD UART2_IRQHandler ; UART2
|
||||
DCD 0 ; Reserved
|
||||
DCD I2C1_IRQHandler ; I2C1
|
||||
DCD I2C0_IRQHandler ; I2C0 controller
|
||||
DCD SCT_IRQHandler ; Smart Counter Timer
|
||||
DCD MRT_IRQHandler ; Multi-Rate Timer
|
||||
DCD CMP_IRQHandler ; Comparator
|
||||
DCD WDT_IRQHandler ; PIO1 (0:11)
|
||||
DCD BOD_IRQHandler ; Brown Out Detect
|
||||
DCD FLASH_IRQHandler ; Flash interrupt
|
||||
DCD WKT_IRQHandler ; Wakeup timer
|
||||
DCD ADC_SEQA_IRQHandler ; ADC sequence A completeion
|
||||
DCD ADC_SEQB_IRQHandler ; ADC sequence B completeion
|
||||
DCD ADC_THCMP_IRQHandler ; ADC threshold compare
|
||||
DCD ADC_OVR_IRQHandler ; ADC overrun
|
||||
DCD DMA_IRQHandler ; DMA
|
||||
DCD I2C2_IRQHandler ; I2C2
|
||||
DCD I2C3_IRQHandler ; I2C3
|
||||
DCD 0 ; Reserved
|
||||
DCD PININT0_IRQHandler ; PIO INT0
|
||||
DCD PININT1_IRQHandler ; PIO INT1
|
||||
DCD PININT2_IRQHandler ; PIO INT2
|
||||
DCD PININT3_IRQHandler ; PIO INT3
|
||||
DCD PININT4_IRQHandler ; PIO INT4
|
||||
DCD PININT5_IRQHandler ; PIO INT5
|
||||
DCD PININT6_IRQHandler ; PIO INT6
|
||||
DCD PININT7_IRQHandler ; PIO INT7
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;;
|
||||
;; Default interrupt handlers.
|
||||
;;
|
||||
THUMB
|
||||
|
||||
PUBWEAK Reset_Handler
|
||||
SECTION .text:CODE:REORDER:NOROOT(2)
|
||||
Reset_Handler
|
||||
LDR R0, =SystemInit
|
||||
BLX R0
|
||||
LDR R0, =__iar_program_start
|
||||
BX R0
|
||||
|
||||
|
||||
|
||||
SECTION .text:CODE:REORDER:NOROOT(1)
|
||||
|
||||
PUBWEAK NMI_Handler
|
||||
PUBWEAK HardFault_Handler
|
||||
PUBWEAK SVC_Handler
|
||||
PUBWEAK DebugMon_Handler
|
||||
PUBWEAK PendSV_Handler
|
||||
PUBWEAK SysTick_Handler
|
||||
PUBWEAK SPI0_IRQHandler
|
||||
PUBWEAK SPI1_IRQHandler
|
||||
PUBWEAK UART0_IRQHandler
|
||||
PUBWEAK UART1_IRQHandler
|
||||
PUBWEAK UART2_IRQHandler
|
||||
PUBWEAK I2C1_IRQHandler
|
||||
PUBWEAK I2C0_IRQHandler
|
||||
PUBWEAK SCT_IRQHandler
|
||||
PUBWEAK MRT_IRQHandler
|
||||
PUBWEAK CMP_IRQHandler
|
||||
PUBWEAK WDT_IRQHandler
|
||||
PUBWEAK BOD_IRQHandler
|
||||
PUBWEAK FLASH_IRQHandler
|
||||
PUBWEAK WKT_IRQHandler
|
||||
PUBWEAK ADC_SEQA_IRQHandler
|
||||
PUBWEAK ADC_SEQB_IRQHandler
|
||||
PUBWEAK ADC_THCMP_IRQHandler
|
||||
PUBWEAK ADC_OVR_IRQHandler
|
||||
PUBWEAK DMA_IRQHandler
|
||||
PUBWEAK I2C2_IRQHandler
|
||||
PUBWEAK I2C3_IRQHandler
|
||||
PUBWEAK PININT0_IRQHandler
|
||||
PUBWEAK PININT1_IRQHandler
|
||||
PUBWEAK PININT2_IRQHandler
|
||||
PUBWEAK PININT3_IRQHandler
|
||||
PUBWEAK PININT4_IRQHandler
|
||||
PUBWEAK PININT5_IRQHandler
|
||||
PUBWEAK PININT6_IRQHandler
|
||||
PUBWEAK PININT7_IRQHandler
|
||||
|
||||
NMI_Handler:
|
||||
HardFault_Handler:
|
||||
SVC_Handler:
|
||||
DebugMon_Handler:
|
||||
PendSV_Handler:
|
||||
SysTick_Handler:
|
||||
SPI0_IRQHandler:
|
||||
SPI1_IRQHandler:
|
||||
UART0_IRQHandler:
|
||||
UART1_IRQHandler:
|
||||
UART2_IRQHandler:
|
||||
I2C1_IRQHandler:
|
||||
I2C0_IRQHandler:
|
||||
SCT_IRQHandler:
|
||||
MRT_IRQHandler:
|
||||
CMP_IRQHandler:
|
||||
WDT_IRQHandler:
|
||||
BOD_IRQHandler:
|
||||
FLASH_IRQHandler:
|
||||
WKT_IRQHandler:
|
||||
ADC_SEQA_IRQHandler:
|
||||
ADC_SEQB_IRQHandler:
|
||||
ADC_THCMP_IRQHandler:
|
||||
ADC_OVR_IRQHandler:
|
||||
DMA_IRQHandler:
|
||||
I2C2_IRQHandler:
|
||||
I2C3_IRQHandler:
|
||||
PININT0_IRQHandler:
|
||||
PININT1_IRQHandler:
|
||||
PININT2_IRQHandler:
|
||||
PININT3_IRQHandler:
|
||||
PININT4_IRQHandler:
|
||||
PININT5_IRQHandler:
|
||||
PININT6_IRQHandler:
|
||||
PININT7_IRQHandler:
|
||||
Default_Handler:
|
||||
B Default_Handler
|
||||
|
||||
END
|
||||
260
bsp/lpc824/Libraries/common/startup/keil_startup_lpc82x.s
Normal file
260
bsp/lpc824/Libraries/common/startup/keil_startup_lpc82x.s
Normal file
@@ -0,0 +1,260 @@
|
||||
;/*****************************************************************************
|
||||
; * @file: startup_LPC8xx.s
|
||||
; * @purpose: CMSIS Cortex-M0+ Core Device Startup File
|
||||
; * for the NXP LPC8xx Device Series
|
||||
; * @version: V1.0
|
||||
; * @date: 16. Aug. 2012
|
||||
; *------- <<< Use Configuration Wizard in Context Menu >>> ------------------
|
||||
; *
|
||||
; * Copyright (C) 2012 ARM Limited. All rights reserved.
|
||||
; * ARM Limited (ARM) is supplying this software for use with Cortex-M0+
|
||||
; * processor based microcontrollers. This file can be freely distributed
|
||||
; * within development tools that are supporting such ARM based processors.
|
||||
; *
|
||||
; * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
|
||||
; * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
|
||||
; * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
|
||||
; * ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
|
||||
; * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
|
||||
; *
|
||||
; *****************************************************************************/
|
||||
|
||||
|
||||
; <h> Stack Configuration
|
||||
; <o> Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>
|
||||
; </h>
|
||||
|
||||
Stack_Size EQU 0x00000180
|
||||
|
||||
AREA STACK, NOINIT, READWRITE, ALIGN=3
|
||||
Stack_Mem SPACE Stack_Size
|
||||
__initial_sp
|
||||
|
||||
|
||||
; <h> Heap Configuration
|
||||
; <o> Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
|
||||
; </h>
|
||||
|
||||
Heap_Size EQU 0x00000000
|
||||
|
||||
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
|
||||
|
||||
__Vectors DCD __initial_sp ; Top of Stack
|
||||
DCD Reset_Handler ; Reset Handler
|
||||
DCD NMI_Handler ; NMI Handler
|
||||
DCD HardFault_Handler ; Hard Fault Handler
|
||||
DCD 0 ; Reserved
|
||||
DCD 0 ; Reserved
|
||||
DCD 0 ; Reserved
|
||||
DCD 0 ; Reserved
|
||||
DCD 0 ; Reserved
|
||||
DCD 0 ; Reserved
|
||||
DCD 0 ; Reserved
|
||||
DCD SVC_Handler ; SVCall Handler
|
||||
DCD 0 ; Reserved
|
||||
DCD 0 ; Reserved
|
||||
DCD PendSV_Handler ; PendSV Handler
|
||||
DCD SysTick_Handler ; SysTick Handler
|
||||
|
||||
; External Interrupts
|
||||
DCD SPI0_IRQHandler ; SPI0 controller
|
||||
DCD SPI1_IRQHandler ; SPI1 controller
|
||||
DCD 0 ; Reserved
|
||||
DCD UART0_IRQHandler ; UART0
|
||||
DCD UART1_IRQHandler ; UART1
|
||||
DCD UART2_IRQHandler ; UART2
|
||||
DCD 0 ; Reserved
|
||||
DCD I2C1_IRQHandler ; I2C1 controller
|
||||
DCD I2C0_IRQHandler ; I2C0 controller
|
||||
DCD SCT_IRQHandler ; Smart Counter Timer
|
||||
DCD MRT_IRQHandler ; Multi-Rate Timer
|
||||
DCD CMP_IRQHandler ; Comparator
|
||||
DCD WDT_IRQHandler ; PIO1 (0:11)
|
||||
DCD BOD_IRQHandler ; Brown Out Detect
|
||||
DCD FLASH_IRQHandler ; Non-Volatile Memory Controller
|
||||
DCD WKT_IRQHandler ; Wakeup timer
|
||||
DCD ADC_SEQA_IRQHandler ; ADC Sequence A Completion [Only on LPC82X]
|
||||
DCD ADC_SEQB_IRQHanlder ; ADC Sequence B Completion [Only on LPC82X]
|
||||
DCD ADC_THCMP_IRQHandler ; ADC Threshold compare [Only on LPC82X]
|
||||
DCD ADC_OVR_IRQHandler ; ADC Overrun [Only on LPC82X]
|
||||
DCD DMA_IRQHandler ; DMA Controller [Only on LPC82X]
|
||||
DCD I2C2_IRQHandler ; I2C2 Controller [Only on LPC82X]
|
||||
DCD I2C3_IRQHandler ; I2C3 Controller [Only on LPC82X]
|
||||
DCD 0 ; Reserved
|
||||
DCD PIN_INT0_IRQHandler ; PIO INT0
|
||||
DCD PIN_INT1_IRQHandler ; PIO INT1
|
||||
DCD PIN_INT2_IRQHandler ; PIO INT2
|
||||
DCD PIN_INT3_IRQHandler ; PIO INT3
|
||||
DCD PIN_INT4_IRQHandler ; PIO INT4
|
||||
DCD PIN_INT5_IRQHandler ; PIO INT5
|
||||
DCD PIN_INT6_IRQHandler ; PIO INT6
|
||||
DCD PIN_INT7_IRQHandler ; PIO INT7
|
||||
|
||||
;// <h> Code Read Protection level (CRP)
|
||||
;// <o> CRP_Level:
|
||||
;// <0xFFFFFFFF=> Disabled
|
||||
;// <0x4E697370=> NO_ISP
|
||||
;// <0x12345678=> CRP1
|
||||
;// <0x87654321=> CRP2
|
||||
;// <0x43218765=> CRP3 (Are you sure?)
|
||||
;// </h>
|
||||
CRP_Level EQU 0xFFFFFFFF
|
||||
|
||||
IF :LNOT::DEF:NO_CRP
|
||||
AREA |.ARM.__at_0x02FC|, CODE, READONLY
|
||||
CRP_Key DCD 0xFFFFFFFF
|
||||
ENDIF
|
||||
|
||||
|
||||
AREA |.text|, CODE, READONLY
|
||||
|
||||
|
||||
; Reset Handler
|
||||
|
||||
Reset_Handler PROC
|
||||
EXPORT Reset_Handler [WEAK]
|
||||
IMPORT SystemInit
|
||||
IMPORT __main
|
||||
LDR R0, = SystemInit
|
||||
BLX R0
|
||||
LDR R0, =__main
|
||||
BX R0
|
||||
ENDP
|
||||
|
||||
|
||||
; Dummy Exception Handlers (infinite loops which can be modified)
|
||||
; now, under COMMON lpc8xx_nmi.c and lpc8xx_nmi.h, a real NMI handler is created if NMI is enabled
|
||||
; for particular peripheral.
|
||||
;NMI_Handler PROC
|
||||
; EXPORT NMI_Handler [WEAK]
|
||||
; B .
|
||||
; ENDP
|
||||
HardFault_Handler\
|
||||
PROC
|
||||
EXPORT HardFault_Handler [WEAK]
|
||||
B .
|
||||
ENDP
|
||||
SVC_Handler PROC
|
||||
EXPORT SVC_Handler [WEAK]
|
||||
B .
|
||||
ENDP
|
||||
PendSV_Handler PROC
|
||||
EXPORT PendSV_Handler [WEAK]
|
||||
B .
|
||||
ENDP
|
||||
SysTick_Handler PROC
|
||||
EXPORT SysTick_Handler [WEAK]
|
||||
B .
|
||||
ENDP
|
||||
|
||||
Default_Handler PROC
|
||||
|
||||
EXPORT NMI_Handler [WEAK]
|
||||
EXPORT SPI0_IRQHandler [WEAK]
|
||||
EXPORT SPI1_IRQHandler [WEAK]
|
||||
EXPORT UART0_IRQHandler [WEAK]
|
||||
EXPORT UART1_IRQHandler [WEAK]
|
||||
EXPORT UART2_IRQHandler [WEAK]
|
||||
EXPORT I2C0_IRQHandler [WEAK]
|
||||
EXPORT SCT_IRQHandler [WEAK]
|
||||
EXPORT MRT_IRQHandler [WEAK]
|
||||
EXPORT CMP_IRQHandler [WEAK]
|
||||
EXPORT WDT_IRQHandler [WEAK]
|
||||
EXPORT BOD_IRQHandler [WEAK]
|
||||
EXPORT FLASH_IRQHandler [WEAK]
|
||||
EXPORT WKT_IRQHandler [WEAK]
|
||||
EXPORT PIN_INT0_IRQHandler [WEAK]
|
||||
EXPORT PIN_INT1_IRQHandler [WEAK]
|
||||
EXPORT PIN_INT2_IRQHandler [WEAK]
|
||||
EXPORT PIN_INT3_IRQHandler [WEAK]
|
||||
EXPORT PIN_INT4_IRQHandler [WEAK]
|
||||
EXPORT PIN_INT5_IRQHandler [WEAK]
|
||||
EXPORT PIN_INT6_IRQHandler [WEAK]
|
||||
EXPORT PIN_INT7_IRQHandler [WEAK]
|
||||
EXPORT ADC_SEQA_IRQHandler [WEAK]
|
||||
EXPORT ADC_SEQB_IRQHanlder [WEAK]
|
||||
EXPORT ADC_THCMP_IRQHandler [WEAK]
|
||||
EXPORT ADC_OVR_IRQHandler [WEAK]
|
||||
EXPORT DMA_IRQHandler [WEAK]
|
||||
EXPORT I2C1_IRQHandler [WEAK]
|
||||
EXPORT I2C2_IRQHandler [WEAK]
|
||||
EXPORT I2C3_IRQHandler [WEAK]
|
||||
|
||||
NMI_Handler
|
||||
SPI0_IRQHandler
|
||||
SPI1_IRQHandler
|
||||
UART0_IRQHandler
|
||||
UART1_IRQHandler
|
||||
UART2_IRQHandler
|
||||
I2C0_IRQHandler
|
||||
SCT_IRQHandler
|
||||
MRT_IRQHandler
|
||||
CMP_IRQHandler
|
||||
WDT_IRQHandler
|
||||
BOD_IRQHandler
|
||||
FLASH_IRQHandler
|
||||
WKT_IRQHandler
|
||||
PIN_INT0_IRQHandler
|
||||
PIN_INT1_IRQHandler
|
||||
PIN_INT2_IRQHandler
|
||||
PIN_INT3_IRQHandler
|
||||
PIN_INT4_IRQHandler
|
||||
PIN_INT5_IRQHandler
|
||||
PIN_INT6_IRQHandler
|
||||
PIN_INT7_IRQHandler
|
||||
ADC_SEQA_IRQHandler
|
||||
ADC_SEQB_IRQHanlder
|
||||
ADC_THCMP_IRQHandler
|
||||
ADC_OVR_IRQHandler
|
||||
DMA_IRQHandler
|
||||
I2C1_IRQHandler
|
||||
I2C2_IRQHandler
|
||||
I2C3_IRQHandler
|
||||
|
||||
B .
|
||||
|
||||
ENDP
|
||||
|
||||
|
||||
ALIGN
|
||||
|
||||
|
||||
; User Initial Stack & Heap
|
||||
|
||||
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
|
||||
|
||||
LDR R0, = Heap_Mem
|
||||
LDR R1, =(Stack_Mem + Stack_Size)
|
||||
LDR R2, = (Heap_Mem + Heap_Size)
|
||||
LDR R3, = Stack_Mem
|
||||
BX LR
|
||||
|
||||
ALIGN
|
||||
|
||||
ENDIF
|
||||
|
||||
|
||||
END
|
||||
130
bsp/lpc824/Libraries/peri_driver/acmp/acmp_8xx.c
Normal file
130
bsp/lpc824/Libraries/peri_driver/acmp/acmp_8xx.c
Normal file
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* @brief LPC8xx Analog comparator driver
|
||||
*
|
||||
* Copyright(C) NXP Semiconductors, 2012
|
||||
* All rights reserved.
|
||||
*
|
||||
* Software that is described herein is for illustrative purposes only
|
||||
* which provides customers with programming information regarding the
|
||||
* LPC products. This software is supplied "AS IS" without any warranties of
|
||||
* any kind, and NXP Semiconductors and its licensor disclaim any and
|
||||
* all warranties, express or implied, including all implied warranties of
|
||||
* merchantability, fitness for a particular purpose and non-infringement of
|
||||
* intellectual property rights. NXP Semiconductors assumes no responsibility
|
||||
* or liability for the use of the software, conveys no license or rights under any
|
||||
* patent, copyright, mask work right, or any other intellectual property rights in
|
||||
* or to any products. NXP Semiconductors reserves the right to make changes
|
||||
* in the software without notification. NXP Semiconductors also makes no
|
||||
* representation or warranty that such application will be suitable for the
|
||||
* specified use without further testing or modification.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation is hereby granted, under NXP Semiconductors' and its
|
||||
* licensor's relevant copyrights in the software, without fee, provided that it
|
||||
* is used in conjunction with NXP Semiconductors microcontrollers. This
|
||||
* copyright, permission, and disclaimer notice must appear in all copies of
|
||||
* this code.
|
||||
*/
|
||||
|
||||
#include "chip.h"
|
||||
|
||||
/*****************************************************************************
|
||||
* Private types/enumerations/variables
|
||||
****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* Public types/enumerations/variables
|
||||
****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* Private functions
|
||||
****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* Public functions
|
||||
****************************************************************************/
|
||||
|
||||
/* Initializes the ACMP */
|
||||
void Chip_ACMP_Init(LPC_CMP_T *pACMP)
|
||||
{
|
||||
Chip_SYSCTL_PowerUp(SYSCTL_SLPWAKE_ACMP_PD);
|
||||
Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_ACOMP);
|
||||
}
|
||||
|
||||
/* De-initializes the ACMP */
|
||||
void Chip_ACMP_Deinit(LPC_CMP_T *pACMP)
|
||||
{
|
||||
Chip_Clock_DisablePeriphClock(SYSCTL_CLOCK_ACOMP);
|
||||
Chip_SYSCTL_PowerDown(SYSCTL_SLPWAKE_ACMP_PD);
|
||||
}
|
||||
|
||||
/* Clears the ACMP interrupt (EDGECLR bit) */
|
||||
void Chip_ACMP_EdgeClear(LPC_CMP_T *pACMP)
|
||||
{
|
||||
uint32_t reg = pACMP->CTRL & ~ACMP_CTRL_RESERVED;
|
||||
|
||||
/* Toggle EDGECLR bit high and then low */
|
||||
pACMP->CTRL = reg | ACMP_EDGECLR_BIT;
|
||||
pACMP->CTRL = reg & ~ACMP_EDGECLR_BIT;
|
||||
}
|
||||
|
||||
/* Sets up ACMP edge selection */
|
||||
void Chip_ACMP_SetEdgeSelection(LPC_CMP_T *pACMP, ACMP_EDGESEL_T edgeSel)
|
||||
{
|
||||
uint32_t reg = pACMP->CTRL & ~(ACMP_EDGESEL_MASK | ACMP_CTRL_RESERVED);
|
||||
|
||||
/* Select edge for COMPEDGE */
|
||||
pACMP->CTRL = reg | (uint32_t) edgeSel;
|
||||
}
|
||||
|
||||
/* Selects positive voltage input */
|
||||
void Chip_ACMP_SetPosVoltRef(LPC_CMP_T *pACMP, ACMP_POS_INPUT_T Posinput)
|
||||
{
|
||||
uint32_t reg = pACMP->CTRL & ~(ACMP_COMPVPSEL_MASK | ACMP_CTRL_RESERVED);
|
||||
|
||||
/* Select positive input */
|
||||
pACMP->CTRL = reg | (uint32_t) Posinput;
|
||||
}
|
||||
|
||||
/* Selects negative voltage input */
|
||||
void Chip_ACMP_SetNegVoltRef(LPC_CMP_T *pACMP, ACMP_NEG_INPUT_T Neginput)
|
||||
{
|
||||
uint32_t reg = pACMP->CTRL & ~(ACMP_COMPVMSEL_MASK | ACMP_CTRL_RESERVED);
|
||||
|
||||
/* Select negative input */
|
||||
pACMP->CTRL = reg | (uint32_t) Neginput;
|
||||
}
|
||||
|
||||
/* Selects hysteresis level */
|
||||
void Chip_ACMP_SetHysteresis(LPC_CMP_T *pACMP, ACMP_HYS_T hys)
|
||||
{
|
||||
uint32_t reg = pACMP->CTRL & ~(ACMP_HYSTERESIS_MASK | ACMP_CTRL_RESERVED);
|
||||
|
||||
/* Select negative input */
|
||||
pACMP->CTRL = reg | (uint32_t) hys;
|
||||
}
|
||||
|
||||
/* Helper function for setting up ACMP control */
|
||||
void Chip_ACMP_SetupAMCPRefs(LPC_CMP_T *pACMP, ACMP_EDGESEL_T edgeSel,
|
||||
ACMP_POS_INPUT_T Posinput, ACMP_NEG_INPUT_T Neginput,
|
||||
ACMP_HYS_T hys)
|
||||
{
|
||||
uint32_t reg = pACMP->CTRL & ~(ACMP_HYSTERESIS_MASK | ACMP_CTRL_RESERVED |
|
||||
ACMP_COMPVMSEL_MASK | ACMP_COMPVPSEL_MASK | ACMP_EDGESEL_MASK);
|
||||
|
||||
/* Select negative input */
|
||||
pACMP->CTRL = reg | (uint32_t) edgeSel | (uint32_t) Posinput |
|
||||
(uint32_t) Neginput | (uint32_t) hys;
|
||||
}
|
||||
|
||||
/* Sets up voltage ladder */
|
||||
void Chip_ACMP_SetupVoltLadder(LPC_CMP_T *pACMP, uint32_t ladsel, bool ladrefVDDCMP)
|
||||
{
|
||||
uint32_t reg = pACMP->LAD & ~(ACMP_LADSEL_MASK | ACMP_LADREF_MASK | ACMP_LAD_RESERVED);
|
||||
|
||||
/* Setup voltage ladder and ladder reference */
|
||||
if (ladrefVDDCMP) {
|
||||
reg |= ACMP_LADREF_MASK;
|
||||
}
|
||||
pACMP->LAD = reg | (ladsel << 1);
|
||||
}
|
||||
253
bsp/lpc824/Libraries/peri_driver/acmp/acmp_8xx.h
Normal file
253
bsp/lpc824/Libraries/peri_driver/acmp/acmp_8xx.h
Normal file
@@ -0,0 +1,253 @@
|
||||
/*
|
||||
* @brief LPC8xx Analog comparator driver
|
||||
*
|
||||
* @note
|
||||
* Copyright(C) NXP Semiconductors, 2012
|
||||
* All rights reserved.
|
||||
*
|
||||
* @par
|
||||
* Software that is described herein is for illustrative purposes only
|
||||
* which provides customers with programming information regarding the
|
||||
* LPC products. This software is supplied "AS IS" without any warranties of
|
||||
* any kind, and NXP Semiconductors and its licenser disclaim any and
|
||||
* all warranties, express or implied, including all implied warranties of
|
||||
* merchantability, fitness for a particular purpose and non-infringement of
|
||||
* intellectual property rights. NXP Semiconductors assumes no responsibility
|
||||
* or liability for the use of the software, conveys no license or rights under any
|
||||
* patent, copyright, mask work right, or any other intellectual property rights in
|
||||
* or to any products. NXP Semiconductors reserves the right to make changes
|
||||
* in the software without notification. NXP Semiconductors also makes no
|
||||
* representation or warranty that such application will be suitable for the
|
||||
* specified use without further testing or modification.
|
||||
*
|
||||
* @par
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation is hereby granted, under NXP Semiconductors' and its
|
||||
* licensor's relevant copyrights in the software, without fee, provided that it
|
||||
* is used in conjunction with NXP Semiconductors microcontrollers. This
|
||||
* copyright, permission, and disclaimer notice must appear in all copies of
|
||||
* this code.
|
||||
*/
|
||||
|
||||
#ifndef __ACMP_8XX_H_
|
||||
#define __ACMP_8XX_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @defgroup ACMP_8XX CHIP: LPC8xx Analog Comparator driver
|
||||
* @ingroup CHIP_8XX_Drivers
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Analog Comparator register block structure
|
||||
*/
|
||||
typedef struct { /*!< ACMP Structure */
|
||||
__IO uint32_t CTRL; /*!< Comparator control register */
|
||||
__IO uint32_t LAD; /*!< Voltage ladder register */
|
||||
} LPC_CMP_T;
|
||||
|
||||
/* Reserved bits masks for registers */
|
||||
#define ACMP_CTRL_RESERVED (7|(1<<5)|(1<<7)|(0x3f<<14)|(1<<22)|(1<<24)|(0x1fu<<27))
|
||||
#define ACMP_LAD_RESERVED (~0x7f)
|
||||
|
||||
#define ACMP_COMPSA_BIT (1 << 6) /* Comparator output control bit */
|
||||
#define ACMP_COMPSTAT_BIT (1 << 21) /* Comparator status, reflects the state of the comparator output */
|
||||
#define ACMP_COMPEDGE_BIT (1 << 23) /* Comparator edge-detect status */
|
||||
#define ACMP_LADENAB_BIT (1 << 0) /* Voltage ladder enable bit */
|
||||
|
||||
/* EDGECLR interrupt clear bit, write 1, then 0 */
|
||||
#define ACMP_EDGECLR_BIT (1 << 20)
|
||||
#define ACMP_EDGESEL_MASK (0x3 << 3)
|
||||
#define ACMP_COMPVPSEL_MASK (0x7 << 8)
|
||||
#define ACMP_COMPVMSEL_MASK (0x7 << 11)
|
||||
#define ACMP_HYSTERESIS_MASK (0x3 << 25)
|
||||
#define ACMP_LADSEL_MASK (0x1F << 1)
|
||||
#define ACMP_LADREF_MASK (0x1 << 6)
|
||||
|
||||
/** Edge selection for comparator */
|
||||
typedef enum {
|
||||
ACMP_EDGESEL_FALLING = (0 << 3), /* Set the COMPEDGE bit on falling edge */
|
||||
ACMP_EDGESEL_RISING = (1 << 3), /* Set the COMPEDGE bit on rising edge */
|
||||
ACMP_EDGESEL_BOTH = (2 << 3) /* Set the COMPEDGE bit on falling and rising edges */
|
||||
} ACMP_EDGESEL_T;
|
||||
|
||||
/** Hysteresis selection for comparator */
|
||||
typedef enum {
|
||||
ACMP_HYS_NONE = (0 << 25), /* No hysteresis (the output will switch as the voltages cross) */
|
||||
ACMP_HYS_5MV = (1 << 25), /* 5mV hysteresis */
|
||||
ACMP_HYS_10MV = (2 << 25), /* 10mV hysteresis */
|
||||
ACMP_HYS_20MV = (3 << 25) /* 20mV hysteresis */
|
||||
} ACMP_HYS_T;
|
||||
|
||||
/**
|
||||
* Analog Comparator positive input values
|
||||
*/
|
||||
typedef enum CHIP_ACMP_POS_INPUT {
|
||||
ACMP_POSIN_VLO = (0 << 8), /*!< Voltage ladder output */
|
||||
ACMP_POSIN_ACMP_I1 = (1 << 8), /*!< ACMP_I1 pin */
|
||||
ACMP_POSIN_ACMP_I2 = (2 << 8), /*!< ACMP_I2 pin */
|
||||
ACMP_POSIN_ACMP_I3 = (3 << 8), /*!< ACMP_I3 pin */
|
||||
ACMP_POSIN_ACMP_I4 = (4 << 8), /*!< ACMP_I4 pin */
|
||||
#if defined(CHIP_LPC82X)
|
||||
ACMP_POSIN_INT_REF = (5 << 8), /*!< Internal reference voltage */
|
||||
ACMP_POSIN_ADC_0 = (6 << 8), /*!< ADC_0 Input */
|
||||
#else
|
||||
ACMP_POSIN_INT_REF = (6 << 8), /*!< Internal reference voltage */
|
||||
#endif
|
||||
} ACMP_POS_INPUT_T;
|
||||
|
||||
/**
|
||||
* Analog Comparator negative input values
|
||||
*/
|
||||
typedef enum CHIP_ACMP_NEG_INPUT {
|
||||
ACMP_NEGIN_VLO = (0 << 11), /*!< Voltage ladder output */
|
||||
ACMP_NEGIN_ACMP_I1 = (1 << 11), /*!< ACMP_I1 pin */
|
||||
ACMP_NEGIN_ACMP_I2 = (2 << 11), /*!< ACMP_I2 pin */
|
||||
ACMP_NEGIN_ACMP_I3 = (3 << 11), /*!< ACMP_I3 pin */
|
||||
ACMP_NEGIN_ACMP_I4 = (4 << 11), /*!< ACMP_I4 pin */
|
||||
#if defined(CHIP_LPC82X)
|
||||
ACMP_NEGIN_INT_REF = (5 << 11), /*!< Internal reference voltage */
|
||||
ACMP_NEGIN_ADC_0 = (6 << 11), /*!< ADC_0 Input */
|
||||
#else
|
||||
ACMP_NEGIN_INT_REF = (6 << 11) /*!< Internal reference voltage */
|
||||
#endif
|
||||
} ACMP_NEG_INPUT_T;
|
||||
|
||||
/**
|
||||
* @brief Initializes the ACMP
|
||||
* @param pACMP : Pointer to Analog Comparator block
|
||||
* @return Nothing
|
||||
*/
|
||||
void Chip_ACMP_Init(LPC_CMP_T *pACMP);
|
||||
|
||||
/**
|
||||
* @brief Deinitializes the ACMP
|
||||
* @param pACMP : Pointer to Analog Comparator block
|
||||
* @return Nothing
|
||||
*/
|
||||
void Chip_ACMP_Deinit(LPC_CMP_T *pACMP);
|
||||
|
||||
/**
|
||||
* @brief Returns the current comparator status
|
||||
* @param pACMP : Pointer to Analog Comparator block
|
||||
* @return Status is an Or'ed value of ACMP_COMPSTAT_BIT or ACMP_COMPEDGE_BIT
|
||||
*/
|
||||
STATIC INLINE uint32_t Chip_ACMP_GetCompStatus(LPC_CMP_T *pACMP)
|
||||
{
|
||||
return pACMP->CTRL & (ACMP_COMPSTAT_BIT | ACMP_COMPEDGE_BIT);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Clears the ACMP interrupt (EDGECLR bit)
|
||||
* @param pACMP : Pointer to Analog Comparator block
|
||||
* @return Nothing
|
||||
*/
|
||||
void Chip_ACMP_EdgeClear(LPC_CMP_T *pACMP);
|
||||
|
||||
/**
|
||||
* @brief Sets up ACMP edge selection
|
||||
* @param pACMP : Pointer to Analog Comparator block
|
||||
* @param edgeSel : Edge selection value
|
||||
* @return Nothing
|
||||
*/
|
||||
void Chip_ACMP_SetEdgeSelection(LPC_CMP_T *pACMP, ACMP_EDGESEL_T edgeSel);
|
||||
|
||||
/**
|
||||
* @brief Synchronizes Comparator output to bus clock
|
||||
* @param pACMP : Pointer to Analog Comparator block
|
||||
* @return Nothing
|
||||
*/
|
||||
STATIC INLINE void Chip_ACMP_EnableSyncCompOut(LPC_CMP_T *pACMP)
|
||||
{
|
||||
pACMP->CTRL = ACMP_COMPSA_BIT | (pACMP->CTRL & ~ACMP_CTRL_RESERVED);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets comparator output to be used directly (no sync)
|
||||
* @param pACMP : Pointer to Analog Comparator block
|
||||
* @return Nothing
|
||||
*/
|
||||
STATIC INLINE void Chip_ACMP_DisableSyncCompOut(LPC_CMP_T *pACMP)
|
||||
{
|
||||
pACMP->CTRL &= ~(ACMP_COMPSA_BIT | ACMP_CTRL_RESERVED);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Selects positive voltage input
|
||||
* @param pACMP : Pointer to Analog Comparator block
|
||||
* @param Posinput : one of the positive input voltage sources
|
||||
* @return Nothing
|
||||
*/
|
||||
void Chip_ACMP_SetPosVoltRef(LPC_CMP_T *pACMP, ACMP_POS_INPUT_T Posinput);
|
||||
|
||||
/**
|
||||
* @brief Selects negative voltage input
|
||||
* @param pACMP : Pointer to Analog Comparator block
|
||||
* @param Neginput : one of the negative input voltage sources
|
||||
* @return Nothing
|
||||
*/
|
||||
void Chip_ACMP_SetNegVoltRef(LPC_CMP_T *pACMP, ACMP_NEG_INPUT_T Neginput);
|
||||
|
||||
/**
|
||||
* @brief Selects hysteresis level
|
||||
* @param pACMP : Pointer to Analog Comparator block
|
||||
* @param hys : Selected Hysteresis level
|
||||
* @return Nothing
|
||||
*/
|
||||
void Chip_ACMP_SetHysteresis(LPC_CMP_T *pACMP, ACMP_HYS_T hys);
|
||||
|
||||
/**
|
||||
* @brief Helper function for setting up ACMP control
|
||||
* @param pACMP : Pointer to Analog Comparator block
|
||||
* @param edgeSel : Edge selection value
|
||||
* @param Posinput : one of the positive input voltage sources
|
||||
* @param Neginput : one of the negative input voltage sources
|
||||
* @param hys : Selected Hysteresis level
|
||||
* @return Nothing
|
||||
*/
|
||||
void Chip_ACMP_SetupAMCPRefs(LPC_CMP_T *pACMP, ACMP_EDGESEL_T edgeSel,
|
||||
ACMP_POS_INPUT_T Posinput, ACMP_NEG_INPUT_T Neginput,
|
||||
ACMP_HYS_T hys);
|
||||
|
||||
/**
|
||||
* @brief Sets up voltage ladder
|
||||
* @param pACMP : Pointer to Analog Comparator block
|
||||
* @param ladsel : Voltage ladder value (0 .. 31)
|
||||
* @param ladrefVDDCMP : Selects the reference voltage Vref for the voltage ladder
|
||||
* : false for VDD, true for VDDCMP pin
|
||||
* @return Nothing
|
||||
*/
|
||||
void Chip_ACMP_SetupVoltLadder(LPC_CMP_T *pACMP, uint32_t ladsel, bool ladrefVDDCMP);
|
||||
|
||||
/**
|
||||
* @brief Enables voltage ladder
|
||||
* @param pACMP : Pointer to Analog Comparator block
|
||||
* @return Nothing
|
||||
*/
|
||||
STATIC INLINE void Chip_ACMP_EnableVoltLadder(LPC_CMP_T *pACMP)
|
||||
{
|
||||
pACMP->LAD = ACMP_LADENAB_BIT | (pACMP->LAD & ~ACMP_LAD_RESERVED);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disables voltage ladder
|
||||
* @param pACMP : Pointer to Analog Comparator block
|
||||
* @return Nothing
|
||||
*/
|
||||
STATIC INLINE void Chip_ACMP_DisableVoltLadder(LPC_CMP_T *pACMP)
|
||||
{
|
||||
pACMP->LAD &= ~(ACMP_LADENAB_BIT | ACMP_LAD_RESERVED);
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __ACMP_8XX_H_ */
|
||||
91
bsp/lpc824/Libraries/peri_driver/adc/adc_8xx.c
Normal file
91
bsp/lpc824/Libraries/peri_driver/adc/adc_8xx.c
Normal file
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* @brief LPC82x ADC driver
|
||||
*
|
||||
* @note
|
||||
* Copyright(C) NXP Semiconductors, 2014
|
||||
* All rights reserved.
|
||||
*
|
||||
* @par
|
||||
* Software that is described herein is for illustrative purposes only
|
||||
* which provides customers with programming information regarding the
|
||||
* LPC products. This software is supplied "AS IS" without any warranties of
|
||||
* any kind, and NXP Semiconductors and its licensor disclaim any and
|
||||
* all warranties, express or implied, including all implied warranties of
|
||||
* merchantability, fitness for a particular purpose and non-infringement of
|
||||
* intellectual property rights. NXP Semiconductors assumes no responsibility
|
||||
* or liability for the use of the software, conveys no license or rights under any
|
||||
* patent, copyright, mask work right, or any other intellectual property rights in
|
||||
* or to any products. NXP Semiconductors reserves the right to make changes
|
||||
* in the software without notification. NXP Semiconductors also makes no
|
||||
* representation or warranty that such application will be suitable for the
|
||||
* specified use without further testing or modification.
|
||||
*
|
||||
* @par
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation is hereby granted, under NXP Semiconductors' and its
|
||||
* licensor's relevant copyrights in the software, without fee, provided that it
|
||||
* is used in conjunction with NXP Semiconductors microcontrollers. This
|
||||
* copyright, permission, and disclaimer notice must appear in all copies of
|
||||
* this code.
|
||||
*/
|
||||
|
||||
#include "chip.h"
|
||||
#include "adc_8xx.h"
|
||||
/*****************************************************************************
|
||||
* Private types/enumerations/variables
|
||||
****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* Public types/enumerations/variables
|
||||
****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* Private functions
|
||||
****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* Public functions
|
||||
****************************************************************************/
|
||||
|
||||
/* Initialize the ADC peripheral */
|
||||
void Chip_ADC_Init(LPC_ADC_T *pADC, uint32_t flags)
|
||||
{
|
||||
/* Power up ADC and enable ADC base clock */
|
||||
Chip_SYSCTL_PowerUp(SYSCTL_SLPWAKE_ADC_PD);
|
||||
Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_ADC);
|
||||
|
||||
/* Disable ADC interrupts */
|
||||
pADC->INTEN = 0;
|
||||
|
||||
/* Set ADC control options */
|
||||
pADC->CTRL = flags;
|
||||
}
|
||||
|
||||
/* Shutdown ADC */
|
||||
void Chip_ADC_DeInit(LPC_ADC_T *pADC)
|
||||
{
|
||||
pADC->INTEN = 0;
|
||||
pADC->CTRL = 0;
|
||||
|
||||
/* Stop ADC clock and then power down ADC */
|
||||
Chip_Clock_DisablePeriphClock(SYSCTL_CLOCK_ADC);
|
||||
Chip_SYSCTL_PowerDown(SYSCTL_SLPWAKE_ADC_PD);
|
||||
}
|
||||
|
||||
/* Start ADC calibration */
|
||||
void Chip_ADC_StartCalibration(LPC_ADC_T *pADC)
|
||||
{
|
||||
/* Set calibration mode */
|
||||
pADC->CTRL |= ADC_CR_CALMODEBIT;
|
||||
|
||||
/* Clear ASYNC bit */
|
||||
pADC->CTRL &= ~ADC_CR_ASYNMODE;
|
||||
|
||||
/* Setup ADC for about 500KHz (per UM) */
|
||||
Chip_ADC_SetClockRate(pADC, 500000);
|
||||
|
||||
/* Clearn low power bit */
|
||||
pADC->CTRL &= ~ADC_CR_LPWRMODEBIT;
|
||||
|
||||
/* Calibration is only complete when ADC_CR_CALMODEBIT bit has cleared */
|
||||
}
|
||||
586
bsp/lpc824/Libraries/peri_driver/adc/adc_8xx.h
Normal file
586
bsp/lpc824/Libraries/peri_driver/adc/adc_8xx.h
Normal file
File diff suppressed because it is too large
Load Diff
117
bsp/lpc824/Libraries/peri_driver/crc/crc_8xx.c
Normal file
117
bsp/lpc824/Libraries/peri_driver/crc/crc_8xx.c
Normal file
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* @brief LPC8xx Cyclic Redundancy Check (CRC) Engine driver
|
||||
*
|
||||
* @note
|
||||
* Copyright(C) NXP Semiconductors, 2012
|
||||
* All rights reserved.
|
||||
*
|
||||
* @par
|
||||
* Software that is described herein is for illustrative purposes only
|
||||
* which provides customers with programming information regarding the
|
||||
* LPC products. This software is supplied "AS IS" without any warranties of
|
||||
* any kind, and NXP Semiconductors and its licenser disclaim any and
|
||||
* all warranties, express or implied, including all implied warranties of
|
||||
* merchantability, fitness for a particular purpose and non-infringement of
|
||||
* intellectual property rights. NXP Semiconductors assumes no responsibility
|
||||
* or liability for the use of the software, conveys no license or rights under any
|
||||
* patent, copyright, mask work right, or any other intellectual property rights in
|
||||
* or to any products. NXP Semiconductors reserves the right to make changes
|
||||
* in the software without notification. NXP Semiconductors also makes no
|
||||
* representation or warranty that such application will be suitable for the
|
||||
* specified use without further testing or modification.
|
||||
*
|
||||
* @par
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation is hereby granted, under NXP Semiconductors' and its
|
||||
* licensor's relevant copyrights in the software, without fee, provided that it
|
||||
* is used in conjunction with NXP Semiconductors microcontrollers. This
|
||||
* copyright, permission, and disclaimer notice must appear in all copies of
|
||||
* this code.
|
||||
*/
|
||||
#include "chip.h"
|
||||
|
||||
/*****************************************************************************
|
||||
* Private types/enumerations/variables
|
||||
****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* Public types/enumerations/variables
|
||||
****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* Private functions
|
||||
****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* Public functions
|
||||
****************************************************************************/
|
||||
|
||||
/* Initialize CRC engine */
|
||||
void Chip_CRC_Init(void)
|
||||
{
|
||||
Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_CRC);
|
||||
}
|
||||
|
||||
/* De-initialize CRC engine */
|
||||
void Chip_CRC_Deinit(void)
|
||||
{
|
||||
Chip_Clock_DisablePeriphClock(SYSCTL_CLOCK_CRC);
|
||||
}
|
||||
|
||||
/* Sets up the CRC engine with defaults based on the polynomial to be used */
|
||||
void Chip_CRC_UseDefaultConfig(CRC_POLY_T poly)
|
||||
{
|
||||
switch (poly) {
|
||||
case CRC_POLY_CRC16:
|
||||
Chip_CRC_UseCRC16();
|
||||
break;
|
||||
|
||||
case CRC_POLY_CRC32:
|
||||
Chip_CRC_UseCRC32();
|
||||
break;
|
||||
|
||||
case CRC_POLY_CCITT:
|
||||
default:
|
||||
Chip_CRC_UseCCITT();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* configure CRC engine and compute CCITT checksum from 8-bit data */
|
||||
uint32_t Chip_CRC_CRC8(const uint8_t *data, uint32_t bytes)
|
||||
{
|
||||
Chip_CRC_UseCCITT();
|
||||
while (bytes > 0) {
|
||||
Chip_CRC_Write8(*data);
|
||||
data++;
|
||||
bytes--;
|
||||
}
|
||||
|
||||
return Chip_CRC_Sum();
|
||||
}
|
||||
|
||||
/* Convenience function for computing a standard CRC16 checksum from 16-bit data block */
|
||||
uint32_t Chip_CRC_CRC16(const uint16_t *data, uint32_t hwords)
|
||||
{
|
||||
Chip_CRC_UseCRC16();
|
||||
while (hwords > 0) {
|
||||
Chip_CRC_Write16(*data);
|
||||
data++;
|
||||
hwords--;
|
||||
}
|
||||
|
||||
return Chip_CRC_Sum();
|
||||
}
|
||||
|
||||
/* Convenience function for computing a standard CRC32 checksum from 32-bit data block */
|
||||
uint32_t Chip_CRC_CRC32(const uint32_t *data, uint32_t words)
|
||||
{
|
||||
Chip_CRC_UseCRC32();
|
||||
while (words > 0) {
|
||||
Chip_CRC_Write32(*data);
|
||||
data++;
|
||||
words--;
|
||||
}
|
||||
|
||||
return Chip_CRC_Sum();
|
||||
}
|
||||
262
bsp/lpc824/Libraries/peri_driver/crc/crc_8xx.h
Normal file
262
bsp/lpc824/Libraries/peri_driver/crc/crc_8xx.h
Normal file
@@ -0,0 +1,262 @@
|
||||
/*
|
||||
* @brief LPC8xx Cyclic Redundancy Check (CRC) Engine driver
|
||||
*
|
||||
* @note
|
||||
* Copyright(C) NXP Semiconductors, 2012
|
||||
* All rights reserved.
|
||||
*
|
||||
* @par
|
||||
* Software that is described herein is for illustrative purposes only
|
||||
* which provides customers with programming information regarding the
|
||||
* LPC products. This software is supplied "AS IS" without any warranties of
|
||||
* any kind, and NXP Semiconductors and its licenser disclaim any and
|
||||
* all warranties, express or implied, including all implied warranties of
|
||||
* merchantability, fitness for a particular purpose and non-infringement of
|
||||
* intellectual property rights. NXP Semiconductors assumes no responsibility
|
||||
* or liability for the use of the software, conveys no license or rights under any
|
||||
* patent, copyright, mask work right, or any other intellectual property rights in
|
||||
* or to any products. NXP Semiconductors reserves the right to make changes
|
||||
* in the software without notification. NXP Semiconductors also makes no
|
||||
* representation or warranty that such application will be suitable for the
|
||||
* specified use without further testing or modification.
|
||||
*
|
||||
* @par
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation is hereby granted, under NXP Semiconductors' and its
|
||||
* licensor's relevant copyrights in the software, without fee, provided that it
|
||||
* is used in conjunction with NXP Semiconductors microcontrollers. This
|
||||
* copyright, permission, and disclaimer notice must appear in all copies of
|
||||
* this code.
|
||||
*/
|
||||
|
||||
#ifndef __CRC_8XX_H_
|
||||
#define __CRC_8XX_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @defgroup CRC_8XX CHIP: LPC8xx Cyclic Redundancy Check Engine driver
|
||||
* @ingroup CHIP_8XX_Drivers
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief CRC register block structure
|
||||
*/
|
||||
typedef struct { /*!< CRC Structure */
|
||||
__IO uint32_t MODE; /*!< CRC Mode Register */
|
||||
__IO uint32_t SEED; /*!< CRC SEED Register */
|
||||
union {
|
||||
__I uint32_t SUM; /*!< CRC Checksum Register. */
|
||||
__O uint32_t WRDATA32; /*!< CRC Data Register: write size 32-bit*/
|
||||
__O uint16_t WRDATA16; /*!< CRC Data Register: write size 16-bit*/
|
||||
__O uint8_t WRDATA8; /*!< CRC Data Register: write size 8-bit*/
|
||||
};
|
||||
|
||||
} LPC_CRC_T;
|
||||
|
||||
/*
|
||||
* @brief CRC MODE register description
|
||||
*/
|
||||
#define CRC_MODE_POLY_BITMASK ((0x03)) /** CRC polynomial Bit mask */
|
||||
#define CRC_MODE_POLY_CCITT (0x00) /** Select CRC-CCITT polynomial */
|
||||
#define CRC_MODE_POLY_CRC16 (0x01) /** Select CRC-16 polynomial */
|
||||
#define CRC_MODE_POLY_CRC32 (0x02) /** Select CRC-32 polynomial */
|
||||
#define CRC_MODE_WRDATA_BITMASK (0x03 << 2) /** CRC WR_Data Config Bit mask */
|
||||
#define CRC_MODE_WRDATA_BIT_RVS (1 << 2) /** Select Bit order reverse for WR_DATA (per byte) */
|
||||
#define CRC_MODE_WRDATA_CMPL (1 << 3) /** Select One's complement for WR_DATA */
|
||||
#define CRC_MODE_SUM_BITMASK (0x03 << 4) /** CRC Sum Config Bit mask */
|
||||
#define CRC_MODE_SUM_BIT_RVS (1 << 4) /** Select Bit order reverse for CRC_SUM */
|
||||
#define CRC_MODE_SUM_CMPL (1 << 5) /** Select One's complement for CRC_SUM */
|
||||
|
||||
#define MODE_CFG_CCITT (0x00) /** Pre-defined mode word for default CCITT setup */
|
||||
#define MODE_CFG_CRC16 (0x15) /** Pre-defined mode word for default CRC16 setup */
|
||||
#define MODE_CFG_CRC32 (0x36) /** Pre-defined mode word for default CRC32 setup */
|
||||
|
||||
#define CRC_SEED_CCITT (0x0000FFFF)/** Initial seed value for CCITT mode */
|
||||
#define CRC_SEED_CRC16 (0x00000000)/** Initial seed value for CRC16 mode */
|
||||
#define CRC_SEED_CRC32 (0xFFFFFFFF)/** Initial seed value for CRC32 mode */
|
||||
|
||||
/**
|
||||
* @brief CRC polynomial
|
||||
*/
|
||||
typedef enum IP_CRC_001_POLY {
|
||||
CRC_POLY_CCITT = CRC_MODE_POLY_CCITT, /**< CRC-CCIT polynomial */
|
||||
CRC_POLY_CRC16 = CRC_MODE_POLY_CRC16, /**< CRC-16 polynomial */
|
||||
CRC_POLY_CRC32 = CRC_MODE_POLY_CRC32, /**< CRC-32 polynomial */
|
||||
CRC_POLY_LAST,
|
||||
} CRC_POLY_T;
|
||||
|
||||
/**
|
||||
* @brief Initializes the CRC Engine
|
||||
* @return Nothing
|
||||
*/
|
||||
void Chip_CRC_Init(void);
|
||||
|
||||
/**
|
||||
* @brief Deinitializes the CRC Engine
|
||||
* @return Nothing
|
||||
*/
|
||||
void Chip_CRC_Deinit(void);
|
||||
|
||||
/**
|
||||
* @brief Set the polynomial used for the CRC calculation
|
||||
* @param poly : The enumerated polynomial to be used
|
||||
* @param flags : An Or'ed value of flags that setup the mode
|
||||
* @return Nothing
|
||||
* @note Flags for setting up the mode word include CRC_MODE_WRDATA_BIT_RVS,
|
||||
* CRC_MODE_WRDATA_CMPL, CRC_MODE_SUM_BIT_RVS, and CRC_MODE_SUM_CMPL.
|
||||
*/
|
||||
STATIC INLINE void Chip_CRC_SetPoly(CRC_POLY_T poly, uint32_t flags)
|
||||
{
|
||||
LPC_CRC->MODE = (uint32_t) poly | flags;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets up the CRC engine for CRC16 mode
|
||||
* @return Nothing
|
||||
*/
|
||||
STATIC INLINE void Chip_CRC_UseCRC16(void)
|
||||
{
|
||||
LPC_CRC->MODE = MODE_CFG_CRC16;
|
||||
LPC_CRC->SEED = CRC_SEED_CRC16;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets up the CRC engine for CRC32 mode
|
||||
* @return Nothing
|
||||
*/
|
||||
STATIC INLINE void Chip_CRC_UseCRC32(void)
|
||||
{
|
||||
LPC_CRC->MODE = MODE_CFG_CRC32;
|
||||
LPC_CRC->SEED = CRC_SEED_CRC32;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets up the CRC engine for CCITT mode
|
||||
* @return Nothing
|
||||
*/
|
||||
STATIC INLINE void Chip_CRC_UseCCITT(void)
|
||||
{
|
||||
LPC_CRC->MODE = MODE_CFG_CCITT;
|
||||
LPC_CRC->SEED = CRC_SEED_CCITT;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Engage the CRC engine with defaults based on the polynomial to be used
|
||||
* @param poly : The enumerated polynomial to be used
|
||||
* @return Nothing
|
||||
*/
|
||||
void Chip_CRC_UseDefaultConfig(CRC_POLY_T poly);
|
||||
|
||||
/**
|
||||
* @brief Set the CRC Mode bits
|
||||
* @param mode : Mode value
|
||||
* @return Nothing
|
||||
*/
|
||||
STATIC INLINE void Chip_CRC_SetMode(uint32_t mode)
|
||||
{
|
||||
LPC_CRC->MODE = mode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the CRC Mode bits
|
||||
* @return The current value of the CRC Mode bits
|
||||
*/
|
||||
STATIC INLINE uint32_t Chip_CRC_GetMode(void)
|
||||
{
|
||||
return LPC_CRC->MODE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the seed bits used by the CRC_SUM register
|
||||
* @param seed : Seed value
|
||||
* @return Nothing
|
||||
*/
|
||||
STATIC INLINE void Chip_CRC_SetSeed(uint32_t seed)
|
||||
{
|
||||
LPC_CRC->SEED = seed;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the CRC seed value
|
||||
* @return Seed value
|
||||
*/
|
||||
STATIC INLINE uint32_t Chip_CRC_GetSeed(void)
|
||||
{
|
||||
return LPC_CRC->SEED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Convenience function for writing 8-bit data to the CRC engine
|
||||
* @param data : 8-bit data to write
|
||||
* @return Nothing
|
||||
*/
|
||||
STATIC INLINE void Chip_CRC_Write8(uint8_t data)
|
||||
{
|
||||
LPC_CRC->WRDATA8 = data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Convenience function for writing 16-bit data to the CRC engine
|
||||
* @param data : 16-bit data to write
|
||||
* @return Nothing
|
||||
*/
|
||||
STATIC INLINE void Chip_CRC_Write16(uint16_t data)
|
||||
{
|
||||
LPC_CRC->WRDATA16 = data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Convenience function for writing 32-bit data to the CRC engine
|
||||
* @param data : 32-bit data to write
|
||||
* @return Nothing
|
||||
*/
|
||||
STATIC INLINE void Chip_CRC_Write32(uint32_t data)
|
||||
{
|
||||
LPC_CRC->WRDATA32 = data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Gets the CRC Sum based on the Mode and Seed as previously configured
|
||||
* @return CRC Checksum value
|
||||
*/
|
||||
STATIC INLINE uint32_t Chip_CRC_Sum(void)
|
||||
{
|
||||
return LPC_CRC->SUM;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Convenience function for computing a standard CCITT checksum from an 8-bit data block
|
||||
* @param data : Pointer to the block of 8-bit data
|
||||
* @param bytes : The number of bytes pointed to by data
|
||||
* @return Check sum value
|
||||
*/
|
||||
uint32_t Chip_CRC_CRC8(const uint8_t *data, uint32_t bytes);
|
||||
|
||||
/**
|
||||
* @brief Convenience function for computing a standard CRC16 checksum from 16-bit data block
|
||||
* @param data : Pointer to the block of 16-bit data
|
||||
* @param hwords : The number of 16 byte entries pointed to by data
|
||||
* @return Check sum value
|
||||
*/
|
||||
uint32_t Chip_CRC_CRC16(const uint16_t *data, uint32_t hwords);
|
||||
|
||||
/**
|
||||
* @brief Convenience function for computing a standard CRC32 checksum from 32-bit data block
|
||||
* @param data : Pointer to the block of 32-bit data
|
||||
* @param words : The number of 32-bit entries pointed to by data
|
||||
* @return Check sum value
|
||||
*/
|
||||
uint32_t Chip_CRC_CRC32(const uint32_t *data, uint32_t words);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __CRC_8XX_H_ */
|
||||
149
bsp/lpc824/Libraries/peri_driver/dma/dma_8xx.c
Normal file
149
bsp/lpc824/Libraries/peri_driver/dma/dma_8xx.c
Normal file
@@ -0,0 +1,149 @@
|
||||
/*
|
||||
* @brief LPC82x DMA chip driver
|
||||
*
|
||||
* @note
|
||||
* Copyright(C) NXP Semiconductors, 2013
|
||||
* All rights reserved.
|
||||
*
|
||||
* @par
|
||||
* Software that is described herein is for illustrative purposes only
|
||||
* which provides customers with programming information regarding the
|
||||
* LPC products. This software is supplied "AS IS" without any warranties of
|
||||
* any kind, and NXP Semiconductors and its licensor disclaim any and
|
||||
* all warranties, express or implied, including all implied warranties of
|
||||
* merchantability, fitness for a particular purpose and non-infringement of
|
||||
* intellectual property rights. NXP Semiconductors assumes no responsibility
|
||||
* or liability for the use of the software, conveys no license or rights under any
|
||||
* patent, copyright, mask work right, or any other intellectual property rights in
|
||||
* or to any products. NXP Semiconductors reserves the right to make changes
|
||||
* in the software without notification. NXP Semiconductors also makes no
|
||||
* representation or warranty that such application will be suitable for the
|
||||
* specified use without further testing or modification.
|
||||
*
|
||||
* @par
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation is hereby granted, under NXP Semiconductors' and its
|
||||
* licensor's relevant copyrights in the software, without fee, provided that it
|
||||
* is used in conjunction with NXP Semiconductors microcontrollers. This
|
||||
* copyright, permission, and disclaimer notice must appear in all copies of
|
||||
* this code.
|
||||
*/
|
||||
|
||||
#include "chip.h"
|
||||
|
||||
/*****************************************************************************
|
||||
* Private types/enumerations/variables
|
||||
****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* Public types/enumerations/variables
|
||||
****************************************************************************/
|
||||
|
||||
/* DMA SRAM table - this can be optionally used with the Chip_DMA_SetSRAMBase()
|
||||
function if a DMA SRAM table is needed. This table is correctly aligned for
|
||||
the DMA controller. */
|
||||
#ifdef __ICCARM__
|
||||
#define ASTR(str) #str
|
||||
#define ALIGN(x) _Pragma(ASTR(data_alignment=##x))
|
||||
#else
|
||||
#define ALIGN(x) __attribute__((aligned(x)))
|
||||
#endif
|
||||
|
||||
/* Alignment of 512 bytes */
|
||||
#define DMA_ALIGN ALIGN(512)
|
||||
DMA_ALIGN DMA_CHDESC_T Chip_DMA_Table[MAX_DMA_CHANNEL];
|
||||
|
||||
/*****************************************************************************
|
||||
* Private functions
|
||||
****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* Public functions
|
||||
****************************************************************************/
|
||||
|
||||
void ChipEz_DMA_Init(uint32_t isEnableIRQ)
|
||||
{
|
||||
Chip_DMA_Init(LPC_DMA);
|
||||
Chip_DMA_Enable(LPC_DMA);
|
||||
Chip_DMA_SetSRAMBase(LPC_DMA, DMA_ADDR(Chip_DMA_Table));
|
||||
if (isEnableIRQ)
|
||||
NVIC_EnableIRQ(DMA_IRQn);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize DMA parameters specific to a channel
|
||||
*
|
||||
* @param channel
|
||||
* @param src_address
|
||||
* @param dst_address
|
||||
* @param xfr_width
|
||||
* @param length_bytes
|
||||
*/
|
||||
void ChipEz_DMA_InitChannel( DMA_CHID_T channel, uint32_t src_address, uint32_t src_increment,
|
||||
uint32_t dst_address, uint32_t dst_increment, uint32_t xfr_width, uint32_t length_bytes, uint32_t priority)
|
||||
{
|
||||
Chip_DMA_EnableChannel(LPC_DMA, channel);
|
||||
Chip_DMA_EnableIntChannel(LPC_DMA, channel);
|
||||
|
||||
Chip_DMA_SetupChannelConfig(LPC_DMA, channel, DMA_CFG_PERIPHREQEN |
|
||||
DMA_CFG_CHPRIORITY(priority));
|
||||
|
||||
if (src_increment != DMA_XFERCFG_SRCINC_0) {
|
||||
Chip_DMA_Table[channel].source = DMA_ADDR((src_address + length_bytes)
|
||||
- (1UL << xfr_width));
|
||||
} else {
|
||||
Chip_DMA_Table[channel].source = DMA_ADDR(src_address);
|
||||
}
|
||||
|
||||
if (dst_increment != DMA_XFERCFG_DSTINC_0) {
|
||||
Chip_DMA_Table[channel].dest = DMA_ADDR((dst_address + length_bytes)
|
||||
- (1UL << xfr_width));
|
||||
} else {
|
||||
Chip_DMA_Table[channel].dest = DMA_ADDR(dst_address);
|
||||
}
|
||||
Chip_DMA_Table[channel].next = DMA_ADDR(0);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the DMA transfer
|
||||
*
|
||||
* @param channel
|
||||
* @param src_increment
|
||||
* @param dst_increment
|
||||
* @param xfr_width
|
||||
* @param length_bytes
|
||||
*/
|
||||
void ChipEz_DMA_StartTransfer(DMA_CHID_T channel, uint32_t src_increment, uint32_t dst_increment, uint32_t xfr_width, uint32_t length_bytes)
|
||||
{
|
||||
uint32_t xfer_count;
|
||||
|
||||
/* Calculate transfer_count ( length in terms of transfers) */
|
||||
xfer_count = (xfr_width == DMA_XFERCFG_WIDTH_8) ? length_bytes :
|
||||
(xfr_width == DMA_XFERCFG_WIDTH_16) ? (length_bytes >> 1) :
|
||||
(length_bytes >> 2);
|
||||
|
||||
Chip_DMA_SetupChannelTransfer(LPC_DMA, channel,
|
||||
(DMA_XFERCFG_CFGVALID | DMA_XFERCFG_SETINTA | DMA_XFERCFG_SWTRIG |
|
||||
xfr_width | src_increment | dst_increment |
|
||||
DMA_XFERCFG_XFERCOUNT(xfer_count)));
|
||||
}
|
||||
|
||||
bool ChipEzr_DMA_Transfer( DMA_CHID_T channel, uint32_t src_address, uint32_t src_increment,
|
||||
uint32_t dst_address, uint32_t dst_increment, uint32_t xfr_width, uint32_t length_bytes, uint32_t priority)
|
||||
{
|
||||
if ((Chip_DMA_GetBusyChannels(LPC_DMA) & (1 << channel)) != 0)
|
||||
return FALSE;
|
||||
ChipEz_DMA_InitChannel(channel, src_address, src_increment, dst_address, dst_increment, xfr_width, length_bytes, priority);
|
||||
ChipEz_DMA_StartTransfer(channel, src_increment, dst_increment, xfr_width, length_bytes);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void ChipEz_DMA_AbortChannel(DMA_CHID_T ch) {
|
||||
Chip_DMA_DisableChannel(LPC_DMA, ch);
|
||||
while ((Chip_DMA_GetBusyChannels(LPC_DMA) & (1 << ch)) != 0) {}
|
||||
Chip_DMA_AbortChannel(LPC_DMA, ch);
|
||||
Chip_DMA_ClearErrorIntChannel(LPC_DMA, ch);
|
||||
}
|
||||
|
||||
810
bsp/lpc824/Libraries/peri_driver/dma/dma_8xx.h
Normal file
810
bsp/lpc824/Libraries/peri_driver/dma/dma_8xx.h
Normal file
File diff suppressed because it is too large
Load Diff
61
bsp/lpc824/Libraries/peri_driver/gpio/gpio_8xx.c
Normal file
61
bsp/lpc824/Libraries/peri_driver/gpio/gpio_8xx.c
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* @brief LPC8xx GPIO driver
|
||||
*
|
||||
* @note
|
||||
* Copyright(C) NXP Semiconductors, 2012
|
||||
* All rights reserved.
|
||||
*
|
||||
* @par
|
||||
* Software that is described herein is for illustrative purposes only
|
||||
* which provides customers with programming information regarding the
|
||||
* LPC products. This software is supplied "AS IS" without any warranties of
|
||||
* any kind, and NXP Semiconductors and its licensor disclaim any and
|
||||
* all warranties, express or implied, including all implied warranties of
|
||||
* merchantability, fitness for a particular purpose and non-infringement of
|
||||
* intellectual property rights. NXP Semiconductors assumes no responsibility
|
||||
* or liability for the use of the software, conveys no license or rights under any
|
||||
* patent, copyright, mask work right, or any other intellectual property rights in
|
||||
* or to any products. NXP Semiconductors reserves the right to make changes
|
||||
* in the software without notification. NXP Semiconductors also makes no
|
||||
* representation or warranty that such application will be suitable for the
|
||||
* specified use without further testing or modification.
|
||||
*
|
||||
* @par
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation is hereby granted, under NXP Semiconductors' and its
|
||||
* licensor's relevant copyrights in the software, without fee, provided that it
|
||||
* is used in conjunction with NXP Semiconductors microcontrollers. This
|
||||
* copyright, permission, and disclaimer notice must appear in all copies of
|
||||
* this code.
|
||||
*/
|
||||
|
||||
#include "chip.h"
|
||||
#include "gpio_8xx.h"
|
||||
/*****************************************************************************
|
||||
* Private types/enumerations/variables
|
||||
****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* Public types/enumerations/variables
|
||||
****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* Private functions
|
||||
****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* Public functions
|
||||
****************************************************************************/
|
||||
|
||||
///* GPIO initilisation function */
|
||||
//void Chip_GPIO_Init(LPC_GPIO_T *pGPIO)
|
||||
//{
|
||||
// Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_GPIO);
|
||||
//}
|
||||
|
||||
///* GPIO deinitialisation function */
|
||||
//void Chip_GPIO_DeInit(LPC_GPIO_T *pGPIO)
|
||||
//{
|
||||
// Chip_Clock_DisablePeriphClock(SYSCTL_CLOCK_GPIO);
|
||||
//}
|
||||
|
||||
357
bsp/lpc824/Libraries/peri_driver/gpio/gpio_8xx.h
Normal file
357
bsp/lpc824/Libraries/peri_driver/gpio/gpio_8xx.h
Normal file
@@ -0,0 +1,357 @@
|
||||
/*
|
||||
* @brief LPC8xx GPIO driver
|
||||
*
|
||||
* @note
|
||||
* Copyright(C) NXP Semiconductors, 2012
|
||||
* All rights reserved.
|
||||
*
|
||||
* @par
|
||||
* Software that is described herein is for illustrative purposes only
|
||||
* which provides customers with programming information regarding the
|
||||
* LPC products. This software is supplied "AS IS" without any warranties of
|
||||
* any kind, and NXP Semiconductors and its licensor disclaim any and
|
||||
* all warranties, express or implied, including all implied warranties of
|
||||
* merchantability, fitness for a particular purpose and non-infringement of
|
||||
* intellectual property rights. NXP Semiconductors assumes no responsibility
|
||||
* or liability for the use of the software, conveys no license or rights under any
|
||||
* patent, copyright, mask work right, or any other intellectual property rights in
|
||||
* or to any products. NXP Semiconductors reserves the right to make changes
|
||||
* in the software without notification. NXP Semiconductors also makes no
|
||||
* representation or warranty that such application will be suitable for the
|
||||
* specified use without further testing or modification.
|
||||
*
|
||||
* @par
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation is hereby granted, under NXP Semiconductors' and its
|
||||
* licensor's relevant copyrights in the software, without fee, provided that it
|
||||
* is used in conjunction with NXP Semiconductors microcontrollers. This
|
||||
* copyright, permission, and disclaimer notice must appear in all copies of
|
||||
* this code.
|
||||
*/
|
||||
|
||||
#ifndef __GPIO_8XX_H_
|
||||
#define __GPIO_8XX_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @defgroup GPIO_8XX CHIP: LPC8xx GPIO driver
|
||||
* @ingroup CHIP_8XX_Drivers
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief GPIO port register block structure
|
||||
*/
|
||||
typedef struct { /*!< GPIO_PORT Structure */
|
||||
__IO uint8_t B[128][32]; /*!< Offset 0x0000: Byte pin registers ports 0 to n; pins PIOn_0 to PIOn_31 */
|
||||
__IO uint32_t W[32][32]; /*!< Offset 0x1000: Word pin registers port 0 to n */
|
||||
__IO uint32_t DIR[32]; /*!< Offset 0x2000: Direction registers port n */
|
||||
__IO uint32_t MASK[32]; /*!< Offset 0x2080: Mask register port n */
|
||||
__IO uint32_t PIN[32]; /*!< Offset 0x2100: Portpin register port n */
|
||||
__IO uint32_t MPIN[32]; /*!< Offset 0x2180: Masked port register port n */
|
||||
__IO uint32_t SET[32]; /*!< Offset 0x2200: Write: Set register for port n Read: output bits for port n */
|
||||
__O uint32_t CLR[32]; /*!< Offset 0x2280: Clear port n */
|
||||
__O uint32_t NOT[32]; /*!< Offset 0x2300: Toggle port n */
|
||||
__O uint32_t DIRSET[32]; /*!< Offset 0x2380: Set Direction */
|
||||
__O uint32_t DIRCLR[32]; /*!< Offset 0x2400: Clear Direction */
|
||||
__O uint32_t DIRNOT[32]; /*!< Offset 0x2480: Toggle Dirction */
|
||||
} LPC_GPIO_T;
|
||||
|
||||
/**
|
||||
* @brief Initialize GPIO block
|
||||
* @param pGPIO : The base of GPIO peripheral on the chip
|
||||
* @return Nothing
|
||||
*/
|
||||
STATIC INLINE void Chip_GPIO_Init(LPC_GPIO_T *pGPIO)
|
||||
{
|
||||
LPC_SYSCTL->SYSAHBCLKCTRL = (1 << SYSCTL_CLOCK_GPIO) | (LPC_SYSCTL->SYSAHBCLKCTRL & ~SYSCTL_SYSAHBCLKCTRL_RESERVED);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief De-Initialize GPIO block
|
||||
* @param pGPIO : The base of GPIO peripheral on the chip
|
||||
* @return Nothing
|
||||
*/
|
||||
STATIC INLINE void Chip_GPIO_DeInit(LPC_GPIO_T *pGPIO)
|
||||
{
|
||||
LPC_SYSCTL->SYSAHBCLKCTRL &= ~((1 << SYSCTL_CLOCK_GPIO) | SYSCTL_SYSAHBCLKCTRL_RESERVED);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set GPIO direction for a single GPIO pin
|
||||
* @param pGPIO : The base of GPIO peripheral on the chip
|
||||
* @param port : GPIO port to set (supports port 0 only)
|
||||
* @param pin : GPIO pin to set direction on as output
|
||||
* @param isOutput: If new direction is output
|
||||
* @return Nothing
|
||||
*/
|
||||
STATIC INLINE void Chip_GPIO_PinSetDIR(LPC_GPIO_T *pGPIO, uint8_t port, uint8_t pin, bool isOutput)
|
||||
{
|
||||
|
||||
#ifdef CHIP_LPC82X
|
||||
if (isOutput)
|
||||
pGPIO->DIRSET[port] = 1UL << pin;
|
||||
else
|
||||
pGPIO->DIRCLR[port] = 1UL << pin;
|
||||
#else
|
||||
if (isOutput)
|
||||
pGPIO->DIR[port] |= 1UL << pin;
|
||||
else
|
||||
pGPIO->DIR[port] &= ~(1UL << pin);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get GPIO direction for a single GPIO pin
|
||||
* @param pGPIO : The base of GPIO peripheral on the chip
|
||||
* @param port : GPIO port to read (supports port 0 only)
|
||||
* @param pin : GPIO pin to get direction for
|
||||
* @return true if the GPIO is an output, false if input
|
||||
*/
|
||||
STATIC INLINE bool Chip_GPIO_PinGetDIR(LPC_GPIO_T *pGPIO, uint8_t port, uint8_t pin)
|
||||
{
|
||||
return (bool) (((pGPIO->DIR[port]) >> pin) & 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Toggle GPIO direction for a single GPIO pin
|
||||
* @param pGPIO : The base of GPIO peripheral on the chip
|
||||
* @param port : GPIO port to set (supports port 0 only)
|
||||
* @param pin : GPIO pin to toggle direction
|
||||
* @return Nothing
|
||||
*/
|
||||
STATIC INLINE void Chip_GPIO_PinToggleDIR(LPC_GPIO_T *pGPIO, uint8_t port, uint8_t pin)
|
||||
{
|
||||
#ifdef CHIP_LPC82X
|
||||
pGPIO->DIRNOT[port] = 1UL << pin;
|
||||
#else
|
||||
pGPIO->DIR[port] ^= 1UL << pin;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set a GPIO pin state via the GPIO byte register
|
||||
* @param pGPIO : The base of GPIO peripheral on the chip
|
||||
* @param port : GPIO port to set (supports port 0 only)
|
||||
* @param pin : GPIO pin to set
|
||||
* @param setting : true for high, false for low
|
||||
* @return Nothing
|
||||
* @note This function replaces Chip_GPIO_WritePortBit()
|
||||
*/
|
||||
STATIC INLINE void Chip_GPIO_PinSetState(LPC_GPIO_T *pGPIO, uint8_t port, uint8_t pin, bool setting)
|
||||
{
|
||||
pGPIO->B[port][pin] = setting;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Get a GPIO pin state via the GPIO byte register
|
||||
* @param pGPIO : The base of GPIO peripheral on the chip
|
||||
* @param port : GPIO port to read (supports port 0 only)
|
||||
* @param pin : GPIO pin to get state for
|
||||
* @return true if the GPIO is high, false if low
|
||||
* @note This function replaces Chip_GPIO_ReadPortBit()
|
||||
*/
|
||||
STATIC INLINE bool Chip_GPIO_PinGetState(LPC_GPIO_T *pGPIO, uint8_t port, uint8_t pin)
|
||||
{
|
||||
return (bool) pGPIO->B[port][pin];
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get a GPIO pin state via the GPIO byte register
|
||||
* @param pGPIO : The base of GPIO peripheral on the chip
|
||||
* @param port : GPIO port to read (supports port 0 only)
|
||||
* @param pin : GPIO pin to get state for
|
||||
* @return true if the GPIO is high, false if low
|
||||
* @note This function replaces Chip_GPIO_ReadPortBit()
|
||||
*/
|
||||
STATIC INLINE void Chip_GPIO_PinToggleState(LPC_GPIO_T *pGPIO, uint8_t port, uint8_t pin)
|
||||
{
|
||||
pGPIO->NOT[port] = 1UL << pin;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set GPIO direction for a all selected GPIO pins
|
||||
* @param pGPIO : The base of GPIO peripheral on the chip
|
||||
* @param port : port Number (supports port 0 only)
|
||||
* @param pinMask : GPIO pin mask to set direction on as output (bits 0..b for pins 0..n)
|
||||
* @param isOutput: If new direction is output
|
||||
* @return Nothing
|
||||
* @note Sets multiple GPIO pins to the output direction, each bit's position that is
|
||||
* high sets the corresponding pin number for that bit to an output.
|
||||
*/
|
||||
STATIC INLINE void Chip_GPIO_PortSetDIR(LPC_GPIO_T *pGPIO, uint8_t port, uint8_t pinMask, bool isOutput)
|
||||
{
|
||||
#ifdef CHIP_LPC82X
|
||||
if (isOutput)
|
||||
pGPIO->DIRSET[port] = pinMask;
|
||||
else
|
||||
pGPIO->DIRCLR[port] = pinMask;
|
||||
#else
|
||||
if (isOutput)
|
||||
pGPIO->DIR[port] |= pinMask;
|
||||
else
|
||||
pGPIO->DIR[port] &= ~pinMask;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get GPIO direction for a all GPIO pins
|
||||
* @param pGPIO : The base of GPIO peripheral on the chip
|
||||
* @param port : port Number (supports port 0 only)
|
||||
* @return a bitfield containing the input and output states for each pin
|
||||
* @note For pins 0..n, a high state in a bit corresponds to an output state for the
|
||||
* same pin, while a low state corresponds to an input state.
|
||||
*/
|
||||
STATIC INLINE uint32_t Chip_GPIO_PortGetDIR(LPC_GPIO_T *pGPIO, uint8_t port)
|
||||
{
|
||||
return pGPIO->DIR[port];
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Toggle GPIO direction for a all selected GPIO pins
|
||||
* @param pGPIO : The base of GPIO peripheral on the chip
|
||||
* @param port : port Number (supports port 0 only)
|
||||
* @param pinMask : GPIO pin mask Toggle direction (bits 0..n for pins 0..n)
|
||||
* @return Nothing
|
||||
* @note Toggles multiple GPIO pin's direction, each bit's position that is
|
||||
* high toggles direction of the corresponding pin number.
|
||||
*/
|
||||
STATIC INLINE void Chip_GPIO_PortToggleDIR(LPC_GPIO_T *pGPIO, uint8_t port, uint8_t pinMask)
|
||||
{
|
||||
#ifdef CHIP_LPC82X
|
||||
pGPIO->DIRNOT[port] = pinMask;
|
||||
#else
|
||||
pGPIO->DIR[port] ^= pinMask;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set all GPIO raw pin states (regardless of masking)
|
||||
* @param pGPIO : The base of GPIO peripheral on the chip
|
||||
* @param port : port Number (supports port 0 only)
|
||||
* @param value : Value to set all GPIO pin states (0..n) to
|
||||
* @return Nothing
|
||||
*/
|
||||
STATIC INLINE void Chip_GPIO_PortSetState(LPC_GPIO_T *pGPIO, uint8_t port, uint32_t value)
|
||||
{
|
||||
pGPIO->PIN[port] = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get all GPIO raw pin states (regardless of masking)
|
||||
* @param pGPIO : The base of GPIO peripheral on the chip
|
||||
* @param port : port Number (supports port 0 only)
|
||||
* @return Current (raw) state of all GPIO pins
|
||||
*/
|
||||
STATIC INLINE uint32_t Chip_GPIO_PortGetState(LPC_GPIO_T *pGPIO, uint8_t port)
|
||||
{
|
||||
return pGPIO->PIN[port];
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Toggle selected GPIO output pins to the opposite state
|
||||
* @param pGPIO : The base of GPIO peripheral on the chip
|
||||
* @param port : port Number (supports port 0 only)
|
||||
* @param pins : pins (0..n) to toggle
|
||||
* @return None
|
||||
* @note Any bit set as a '0' will not have it's state changed. This only
|
||||
* applies to ports configured as an output.
|
||||
*/
|
||||
STATIC INLINE void Chip_GPIO_PortToggleState(LPC_GPIO_T *pGPIO, uint8_t port, uint32_t pins)
|
||||
{
|
||||
pGPIO->NOT[port] = pins;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set selected GPIO output pins to the high state
|
||||
* @param pGPIO : The base of GPIO peripheral on the chip
|
||||
* @param port : port Number (supports port 0 only)
|
||||
* @param pins : pins (0..n) to set high
|
||||
* @return None
|
||||
* @note Any bit set as a '0' will not have it's state changed. This only
|
||||
* applies to ports configured as an output.
|
||||
*/
|
||||
STATIC INLINE void Chip_GPIO_PortSetOutHigh(LPC_GPIO_T *pGPIO, uint8_t port, uint32_t bmPins)
|
||||
{
|
||||
pGPIO->SET[port] = bmPins;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set selected GPIO output pins to the low state
|
||||
* @param pGPIO : The base of GPIO peripheral on the chip
|
||||
* @param port : port Number (supports port 0 only)
|
||||
* @param pins : pins (0..n) to set low
|
||||
* @return None
|
||||
* @note Any bit set as a '0' will not have it's state changed. This only
|
||||
* applies to ports configured as an output.
|
||||
*/
|
||||
STATIC INLINE void Chip_GPIO_PortSetOutLow(LPC_GPIO_T *pGPIO, uint8_t port, uint32_t pins)
|
||||
{
|
||||
pGPIO->CLR[port] = pins;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set GPIO port mask value for GPIO masked read and write
|
||||
* @param pGPIO : The base of GPIO peripheral on the chip
|
||||
* @param port : port Number (supports port 0 only)
|
||||
* @param mask : Mask value for read and write (only low bits are enabled)
|
||||
* @return Nothing
|
||||
* @note Controls which bits are set or unset when using the masked
|
||||
* GPIO read and write functions. A low state indicates the pin is settable
|
||||
* and readable via the masked write and read functions.
|
||||
*/
|
||||
STATIC INLINE void Chip_GPIO_PortSetMask(LPC_GPIO_T *pGPIO, uint8_t port, uint32_t mask)
|
||||
{
|
||||
pGPIO->MASK[port] = mask;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get GPIO port mask value used for GPIO masked read and write
|
||||
* @param pGPIO : The base of GPIO peripheral on the chip
|
||||
* @param port : port Number (supports port 0 only)
|
||||
* @return Returns value set with the Chip_GPIO_PortSetMask() function.
|
||||
* @note A high bit in the return value indicates that that GPIO pin for the
|
||||
* port cannot be set using the masked write function.
|
||||
*/
|
||||
STATIC INLINE uint32_t Chip_GPIO_PortGetMask(LPC_GPIO_T *pGPIO, uint8_t port)
|
||||
{
|
||||
return pGPIO->MASK[port];
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set all GPIO pin states, but mask via the MASKP0 register
|
||||
* @param pGPIO : The base of GPIO peripheral on the chip
|
||||
* @param port : port Number (supports port 0 only)
|
||||
* @param value : Value to set all GPIO pin states (0..n) to
|
||||
* @return Nothing
|
||||
*/
|
||||
STATIC INLINE void Chip_GPIO_PortSetMaskedState(LPC_GPIO_T *pGPIO, uint8_t port, uint32_t value)
|
||||
{
|
||||
pGPIO->MPIN[port] = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get all GPIO pin statesm but mask via the MASKP0 register
|
||||
* @param pGPIO : The base of GPIO peripheral on the chip
|
||||
* @param port : port Number (supports port 0 only)
|
||||
* @return Current (masked) state of all GPIO pins
|
||||
*/
|
||||
STATIC INLINE uint32_t Chip_GPIO_PortGetMaskedState(LPC_GPIO_T *pGPIO, uint8_t port)
|
||||
{
|
||||
return pGPIO->MPIN[port];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __GPIO_8XX_H_ */
|
||||
307
bsp/lpc824/Libraries/peri_driver/i2c/i2c_8xx.c
Normal file
307
bsp/lpc824/Libraries/peri_driver/i2c/i2c_8xx.c
Normal file
@@ -0,0 +1,307 @@
|
||||
/*
|
||||
* @brief LPC15xx I2C Common driver
|
||||
*
|
||||
* @note
|
||||
* Copyright(C) NXP Semiconductors, 2014
|
||||
* All rights reserved.
|
||||
*
|
||||
* @par
|
||||
* Software that is described herein is for illustrative purposes only
|
||||
* which provides customers with programming information regarding the
|
||||
* LPC products. This software is supplied "AS IS" without any warranties of
|
||||
* any kind, and NXP Semiconductors and its licensor disclaim any and
|
||||
* all warranties, express or implied, including all implied warranties of
|
||||
* merchantability, fitness for a particular purpose and non-infringement of
|
||||
* intellectual property rights. NXP Semiconductors assumes no responsibility
|
||||
* or liability for the use of the software, conveys no license or rights under any
|
||||
* patent, copyright, mask work right, or any other intellectual property rights in
|
||||
* or to any products. NXP Semiconductors reserves the right to make changes
|
||||
* in the software without notification. NXP Semiconductors also makes no
|
||||
* representation or warranty that such application will be suitable for the
|
||||
* specified use without further testing or modification.
|
||||
*
|
||||
* @par
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation is hereby granted, under NXP Semiconductors' and its
|
||||
* licensor's relevant copyrights in the software, without fee, provided that it
|
||||
* is used in conjunction with NXP Semiconductors microcontrollers. This
|
||||
* copyright, permission, and disclaimer notice must appear in all copies of
|
||||
* this code.
|
||||
*/
|
||||
|
||||
#include "chip.h"
|
||||
|
||||
/*****************************************************************************
|
||||
* Private types/enumerations/variables
|
||||
****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* Public types/enumerations/variables
|
||||
****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* Private functions
|
||||
****************************************************************************/
|
||||
|
||||
/* Get the RESET ID corresponding to the given I2C base */
|
||||
static CHIP_SYSCTL_PERIPH_RESET_T I2C_GetResetID(LPC_I2C_T *pI2C)
|
||||
{
|
||||
uint32_t base = (uint32_t) pI2C;
|
||||
switch (base) {
|
||||
case LPC_I2C1_BASE:
|
||||
return RESET_I2C1;
|
||||
case LPC_I2C2_BASE:
|
||||
return RESET_I2C2;
|
||||
case LPC_I2C3_BASE:
|
||||
return RESET_I2C3;
|
||||
default:
|
||||
return RESET_I2C0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Get the CLOCK ID corresponding to the given I2C base */
|
||||
static CHIP_SYSCTL_CLOCK_T I2C_GetClockID(LPC_I2C_T *pI2C)
|
||||
{
|
||||
uint32_t base = (uint32_t) pI2C;
|
||||
switch (base) {
|
||||
case LPC_I2C1_BASE:
|
||||
return SYSCTL_CLOCK_I2C1;
|
||||
case LPC_I2C2_BASE:
|
||||
return SYSCTL_CLOCK_I2C2;
|
||||
case LPC_I2C3_BASE:
|
||||
return SYSCTL_CLOCK_I2C3;
|
||||
default:
|
||||
return SYSCTL_CLOCK_I2C0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets HIGH and LOW duty cycle registers
|
||||
* @param pI2C : Pointer to selected I2C peripheral
|
||||
* @param sclH : Number of I2C_PCLK cycles for the SCL HIGH time value between (2 - 9).
|
||||
* @param sclL : Number of I2C_PCLK cycles for the SCL LOW time value between (2 - 9).
|
||||
* @return Nothing
|
||||
* @note The I2C clock divider should be set to the appropriate value before calling this function
|
||||
* The I2C baud is determined by the following formula: <br>
|
||||
* I2C_bitFrequency = (I2C_PCLK)/(I2C_CLKDIV * (sclH + sclL)) <br>
|
||||
* where I2C_PCLK is the frequency of the System clock and I2C_CLKDIV is I2C clock divider
|
||||
*/
|
||||
static void Chip_I2CM_SetDutyCycle(LPC_I2C_T *pI2C, uint16_t sclH, uint16_t sclL)
|
||||
{
|
||||
/* Limit to usable range of timing values */
|
||||
if (sclH < 2) {
|
||||
sclH = 2;
|
||||
}
|
||||
else if (sclH > 9) {
|
||||
sclH = 9;
|
||||
}
|
||||
if (sclL < 2) {
|
||||
sclL = 2;
|
||||
}
|
||||
else if (sclL > 9) {
|
||||
sclL = 9;
|
||||
}
|
||||
|
||||
pI2C->MSTTIME = (((sclH - 2) & 0x07) << 4) | ((sclL - 2) & 0x07);
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
* Public functions
|
||||
****************************************************************************/
|
||||
|
||||
/* Initializes the LPC_I2C peripheral */
|
||||
void Chip_I2C_Init(LPC_I2C_T *pI2C)
|
||||
{
|
||||
/* Enable I2C clock */
|
||||
Chip_Clock_EnablePeriphClock(I2C_GetClockID(pI2C));
|
||||
|
||||
/* Peripheral reset control to I2C */
|
||||
Chip_SYSCTL_PeriphReset(I2C_GetResetID(pI2C));
|
||||
}
|
||||
|
||||
/* Shuts down the I2C controller block */
|
||||
void Chip_I2C_DeInit(LPC_I2C_T *pI2C)
|
||||
{
|
||||
/* Disable I2C clock */
|
||||
Chip_Clock_DisablePeriphClock(I2C_GetClockID(pI2C));
|
||||
}
|
||||
|
||||
/* Set up bus speed for LPC_I2C interface */
|
||||
void Chip_I2CM_SetBusSpeed(LPC_I2C_T *pI2C, uint32_t busSpeed)
|
||||
{
|
||||
uint32_t scl = Chip_Clock_GetSystemClockRate() / (Chip_I2C_GetClockDiv(pI2C) * busSpeed);
|
||||
Chip_I2CM_SetDutyCycle(pI2C, (scl >> 1), (scl - (scl >> 1)));
|
||||
}
|
||||
|
||||
/* Master transfer state change handler handler */
|
||||
uint32_t Chip_I2CM_XferHandler(LPC_I2C_T *pI2C, I2CM_XFER_T *xfer)
|
||||
{
|
||||
uint32_t status = Chip_I2CM_GetStatus(pI2C);
|
||||
/* Master Lost Arbitration */
|
||||
if (status & I2C_STAT_MSTRARBLOSS) {
|
||||
/* Set transfer status as Arbitration Lost */
|
||||
xfer->status = I2CM_STATUS_ARBLOST;
|
||||
/* Clear Status Flags */
|
||||
Chip_I2CM_ClearStatus(pI2C, I2C_STAT_MSTRARBLOSS);
|
||||
}
|
||||
/* Master Start Stop Error */
|
||||
else if (status & I2C_STAT_MSTSTSTPERR) {
|
||||
/* Set transfer status as Bus Error */
|
||||
xfer->status = I2CM_STATUS_BUS_ERROR;
|
||||
/* Clear Status Flags */
|
||||
Chip_I2CM_ClearStatus(pI2C, I2C_STAT_MSTSTSTPERR);
|
||||
}
|
||||
/* Master is Pending */
|
||||
else if (status & I2C_STAT_MSTPENDING) {
|
||||
/* Branch based on Master State Code */
|
||||
switch (Chip_I2CM_GetMasterState(pI2C)) {
|
||||
/* Master idle */
|
||||
case I2C_STAT_MSTCODE_IDLE:
|
||||
/* Do Nothing */
|
||||
break;
|
||||
|
||||
/* Receive data is available */
|
||||
case I2C_STAT_MSTCODE_RXREADY:
|
||||
/* Read Data */
|
||||
*xfer->rxBuff++ = pI2C->MSTDAT;
|
||||
xfer->rxSz--;
|
||||
if (xfer->rxSz) {
|
||||
/* Set Continue if there is more data to read */
|
||||
Chip_I2CM_MasterContinue(pI2C);
|
||||
}
|
||||
else {
|
||||
/* Set transfer status as OK */
|
||||
xfer->status = I2CM_STATUS_OK;
|
||||
/* No data to read send Stop */
|
||||
Chip_I2CM_SendStop(pI2C);
|
||||
}
|
||||
break;
|
||||
|
||||
/* Master Transmit available */
|
||||
case I2C_STAT_MSTCODE_TXREADY:
|
||||
if (xfer->txSz) {
|
||||
/* If Tx data available transmit data and continue */
|
||||
pI2C->MSTDAT = *xfer->txBuff++;
|
||||
xfer->txSz--;
|
||||
Chip_I2CM_MasterContinue(pI2C);
|
||||
}
|
||||
else {
|
||||
/* If receive queued after transmit then initiate master receive transfer*/
|
||||
if (xfer->rxSz) {
|
||||
/* Write Address and RW bit to data register */
|
||||
Chip_I2CM_WriteByte(pI2C, (xfer->slaveAddr << 1) | 0x1);
|
||||
/* Enter to Master Transmitter mode */
|
||||
Chip_I2CM_SendStart(pI2C);
|
||||
}
|
||||
else {
|
||||
/* If no receive queued then set transfer status as OK */
|
||||
xfer->status = I2CM_STATUS_OK;
|
||||
/* Send Stop */
|
||||
Chip_I2CM_SendStop(pI2C);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case I2C_STAT_MSTCODE_NACKADR:
|
||||
/* Set transfer status as NACK on address */
|
||||
xfer->status = I2CM_STATUS_NAK_ADR;
|
||||
Chip_I2CM_SendStop(pI2C);
|
||||
break;
|
||||
|
||||
case I2C_STAT_MSTCODE_NACKDAT:
|
||||
/* Set transfer status as NACK on data */
|
||||
xfer->status = I2CM_STATUS_NAK_DAT;
|
||||
Chip_I2CM_SendStop(pI2C);
|
||||
break;
|
||||
|
||||
default:
|
||||
/* Default case should not occur*/
|
||||
xfer->status = I2CM_STATUS_ERROR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* Default case should not occur */
|
||||
xfer->status = I2CM_STATUS_ERROR;
|
||||
}
|
||||
return xfer->status != I2CM_STATUS_BUSY;
|
||||
}
|
||||
|
||||
/* Transmit and Receive data in master mode */
|
||||
void Chip_I2CM_Xfer(LPC_I2C_T *pI2C, I2CM_XFER_T *xfer)
|
||||
{
|
||||
/* set the transfer status as busy */
|
||||
xfer->status = I2CM_STATUS_BUSY;
|
||||
/* Clear controller state. */
|
||||
Chip_I2CM_ClearStatus(pI2C, I2C_STAT_MSTRARBLOSS | I2C_STAT_MSTSTSTPERR);
|
||||
/* Write Address and RW bit to data register */
|
||||
Chip_I2CM_WriteByte(pI2C, (xfer->slaveAddr << 1) | (xfer->txSz == 0));
|
||||
/* Enter to Master Transmitter mode */
|
||||
Chip_I2CM_SendStart(pI2C);
|
||||
}
|
||||
|
||||
/* Transmit and Receive data in master mode */
|
||||
uint32_t Chip_I2CM_XferBlocking(LPC_I2C_T *pI2C, I2CM_XFER_T *xfer)
|
||||
{
|
||||
uint32_t ret = 0;
|
||||
/* start transfer */
|
||||
Chip_I2CM_Xfer(pI2C, xfer);
|
||||
|
||||
while (ret == 0) {
|
||||
/* wait for status change interrupt */
|
||||
while (!Chip_I2CM_IsMasterPending(pI2C)) {}
|
||||
/* call state change handler */
|
||||
ret = Chip_I2CM_XferHandler(pI2C, xfer);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Slave transfer state change handler */
|
||||
uint32_t Chip_I2CS_XferHandler(LPC_I2C_T *pI2C, const I2CS_XFER_T *xfers)
|
||||
{
|
||||
uint32_t done = 0;
|
||||
|
||||
uint8_t data;
|
||||
uint32_t state;
|
||||
|
||||
/* transfer complete? */
|
||||
if ((Chip_I2C_GetPendingInt(pI2C) & I2C_INTENSET_SLVDESEL) != 0) {
|
||||
Chip_I2CS_ClearStatus(pI2C, I2C_STAT_SLVDESEL);
|
||||
xfers->slaveDone();
|
||||
}
|
||||
else {
|
||||
/* Determine the current I2C slave state */
|
||||
state = Chip_I2CS_GetSlaveState(pI2C);
|
||||
|
||||
switch (state) {
|
||||
case I2C_STAT_SLVCODE_ADDR: /* Slave address received */
|
||||
/* Get slave address that needs servicing */
|
||||
data = Chip_I2CS_GetSlaveAddr(pI2C, Chip_I2CS_GetSlaveMatchIndex(pI2C));
|
||||
|
||||
/* Call address callback */
|
||||
xfers->slaveStart(data);
|
||||
break;
|
||||
|
||||
case I2C_STAT_SLVCODE_RX: /* Data byte received */
|
||||
/* Get received data */
|
||||
data = Chip_I2CS_ReadByte(pI2C);
|
||||
done = xfers->slaveRecv(data);
|
||||
break;
|
||||
|
||||
case I2C_STAT_SLVCODE_TX: /* Get byte that needs to be sent */
|
||||
/* Get data to send */
|
||||
done = xfers->slaveSend(&data);
|
||||
Chip_I2CS_WriteByte(pI2C, data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (done == 0) {
|
||||
Chip_I2CS_SlaveContinue(pI2C);
|
||||
}
|
||||
else {
|
||||
Chip_I2CS_SlaveNACK(pI2C);
|
||||
}
|
||||
|
||||
return done;
|
||||
}
|
||||
890
bsp/lpc824/Libraries/peri_driver/i2c/i2c_8xx.h
Normal file
890
bsp/lpc824/Libraries/peri_driver/i2c/i2c_8xx.h
Normal file
File diff suppressed because it is too large
Load Diff
179
bsp/lpc824/Libraries/peri_driver/iap/iap.c
Normal file
179
bsp/lpc824/Libraries/peri_driver/iap/iap.c
Normal file
@@ -0,0 +1,179 @@
|
||||
/*
|
||||
* @brief Common FLASH support functions
|
||||
*
|
||||
* @note
|
||||
* Copyright(C) NXP Semiconductors, 2013
|
||||
* All rights reserved.
|
||||
*
|
||||
* @par
|
||||
* Software that is described herein is for illustrative purposes only
|
||||
* which provides customers with programming information regarding the
|
||||
* LPC products. This software is supplied "AS IS" without any warranties of
|
||||
* any kind, and NXP Semiconductors and its licensor disclaim any and
|
||||
* all warranties, express or implied, including all implied warranties of
|
||||
* merchantability, fitness for a particular purpose and non-infringement of
|
||||
* intellectual property rights. NXP Semiconductors assumes no responsibility
|
||||
* or liability for the use of the software, conveys no license or rights under any
|
||||
* patent, copyright, mask work right, or any other intellectual property rights in
|
||||
* or to any products. NXP Semiconductors reserves the right to make changes
|
||||
* in the software without notification. NXP Semiconductors also makes no
|
||||
* representation or warranty that such application will be suitable for the
|
||||
* specified use without further testing or modification.
|
||||
*
|
||||
* @par
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation is hereby granted, under NXP Semiconductors' and its
|
||||
* licensor's relevant copyrights in the software, without fee, provided that it
|
||||
* is used in conjunction with NXP Semiconductors microcontrollers. This
|
||||
* copyright, permission, and disclaimer notice must appear in all copies of
|
||||
* this code.
|
||||
*/
|
||||
|
||||
#include "chip.h"
|
||||
|
||||
/*****************************************************************************
|
||||
* Private types/enumerations/variables
|
||||
****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* Public types/enumerations/variables
|
||||
****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* Private functions
|
||||
****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* Public functions
|
||||
****************************************************************************/
|
||||
|
||||
/* Prepare sector for write operation */
|
||||
uint8_t Chip_IAP_PreSectorForReadWrite(uint32_t strSector, uint32_t endSector)
|
||||
{
|
||||
uint32_t command[5], result[5];
|
||||
|
||||
command[0] = IAP_PREWRRITE_CMD;
|
||||
command[1] = strSector;
|
||||
command[2] = endSector;
|
||||
iap_entry(command, result);
|
||||
|
||||
return result[0];
|
||||
}
|
||||
|
||||
/* Copy RAM to flash */
|
||||
uint8_t Chip_IAP_CopyRamToFlash(uint32_t dstAdd, uint32_t *srcAdd, uint32_t byteswrt)
|
||||
{
|
||||
uint32_t command[5], result[5];
|
||||
|
||||
command[0] = IAP_WRISECTOR_CMD;
|
||||
command[1] = dstAdd;
|
||||
command[2] = (uint32_t) srcAdd;
|
||||
command[3] = byteswrt;
|
||||
command[4] = SystemCoreClock / 1000;
|
||||
iap_entry(command, result);
|
||||
|
||||
return result[0];
|
||||
}
|
||||
|
||||
/* Erase sector */
|
||||
uint8_t Chip_IAP_EraseSector(uint32_t strSector, uint32_t endSector)
|
||||
{
|
||||
uint32_t command[5], result[5];
|
||||
|
||||
command[0] = IAP_ERSSECTOR_CMD;
|
||||
command[1] = strSector;
|
||||
command[2] = endSector;
|
||||
command[3] = SystemCoreClock / 1000;
|
||||
iap_entry(command, result);
|
||||
|
||||
return result[0];
|
||||
}
|
||||
|
||||
/* Blank check sector */
|
||||
uint8_t Chip_IAP_BlankCheckSector(uint32_t strSector, uint32_t endSector)
|
||||
{
|
||||
uint32_t command[5], result[5];
|
||||
|
||||
command[0] = IAP_BLANK_CHECK_SECTOR_CMD;
|
||||
command[1] = strSector;
|
||||
command[2] = endSector;
|
||||
iap_entry(command, result);
|
||||
|
||||
return result[0];
|
||||
}
|
||||
|
||||
/* Read part identification number */
|
||||
uint32_t Chip_IAP_ReadPID(void)
|
||||
{
|
||||
uint32_t command[5], result[5];
|
||||
|
||||
command[0] = IAP_REPID_CMD;
|
||||
iap_entry(command, result);
|
||||
|
||||
return result[1];
|
||||
}
|
||||
|
||||
/* Read boot code version number */
|
||||
uint32_t Chip_IAP_ReadBootCode(void)
|
||||
{
|
||||
uint32_t command[5], result[5];
|
||||
|
||||
command[0] = IAP_READ_BOOT_CODE_CMD;
|
||||
iap_entry(command, result);
|
||||
|
||||
return result[1] & 0xffff;
|
||||
}
|
||||
|
||||
/* IAP compare */
|
||||
uint8_t Chip_IAP_Compare(uint32_t dstAdd, uint32_t srcAdd, uint32_t bytescmp)
|
||||
{
|
||||
uint32_t command[5], result[5];
|
||||
|
||||
command[0] = IAP_COMPARE_CMD;
|
||||
command[1] = dstAdd;
|
||||
command[2] = srcAdd;
|
||||
command[3] = bytescmp;
|
||||
iap_entry(command, result);
|
||||
|
||||
return result[0];
|
||||
}
|
||||
|
||||
/* Reinvoke ISP */
|
||||
uint8_t Chip_IAP_ReinvokeISP(void)
|
||||
{
|
||||
uint32_t command[5], result[5];
|
||||
|
||||
command[0] = IAP_REINVOKE_ISP_CMD;
|
||||
iap_entry(command, result);
|
||||
|
||||
return result[0];
|
||||
}
|
||||
|
||||
/* Read the unique ID */
|
||||
uint32_t Chip_IAP_ReadUID(uint32_t* uid)
|
||||
{
|
||||
uint32_t command[5], result[5];
|
||||
uint32_t i;
|
||||
|
||||
command[0] = IAP_READ_UID_CMD;
|
||||
iap_entry(command, result);
|
||||
|
||||
for (i=0; i<4; i++)
|
||||
*(uid+i) = result[i+1];
|
||||
|
||||
return result[0];
|
||||
}
|
||||
|
||||
/* Erase page */
|
||||
uint8_t Chip_IAP_ErasePage(uint32_t strPage, uint32_t endPage)
|
||||
{
|
||||
uint32_t command[5], result[5];
|
||||
|
||||
command[0] = IAP_ERASE_PAGE_CMD;
|
||||
command[1] = strPage;
|
||||
command[2] = endPage;
|
||||
command[3] = SystemCoreClock / 1000;
|
||||
iap_entry(command, result);
|
||||
|
||||
return result[0];
|
||||
}
|
||||
184
bsp/lpc824/Libraries/peri_driver/iap/iap.h
Normal file
184
bsp/lpc824/Libraries/peri_driver/iap/iap.h
Normal file
@@ -0,0 +1,184 @@
|
||||
/*
|
||||
* @brief Common IAP support functions
|
||||
*
|
||||
* @note
|
||||
* Copyright(C) NXP Semiconductors, 2013
|
||||
* All rights reserved.
|
||||
*
|
||||
* @par
|
||||
* Software that is described herein is for illustrative purposes only
|
||||
* which provides customers with programming information regarding the
|
||||
* LPC products. This software is supplied "AS IS" without any warranties of
|
||||
* any kind, and NXP Semiconductors and its licenser disclaim any and
|
||||
* all warranties, express or implied, including all implied warranties of
|
||||
* merchantability, fitness for a particular purpose and non-infringement of
|
||||
* intellectual property rights. NXP Semiconductors assumes no responsibility
|
||||
* or liability for the use of the software, conveys no license or rights under any
|
||||
* patent, copyright, mask work right, or any other intellectual property rights in
|
||||
* or to any products. NXP Semiconductors reserves the right to make changes
|
||||
* in the software without notification. NXP Semiconductors also makes no
|
||||
* representation or warranty that such application will be suitable for the
|
||||
* specified use without further testing or modification.
|
||||
*
|
||||
* @par
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation is hereby granted, under NXP Semiconductors' and its
|
||||
* licensor's relevant copyrights in the software, without fee, provided that it
|
||||
* is used in conjunction with NXP Semiconductors microcontrollers. This
|
||||
* copyright, permission, and disclaimer notice must appear in all copies of
|
||||
* this code.
|
||||
*/
|
||||
|
||||
#ifndef __IAP_H_
|
||||
#define __IAP_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @defgroup COMMON_IAP CHIP: Common Chip ISP/IAP commands and return codes
|
||||
* @ingroup CHIP_Common
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* IAP command definitions */
|
||||
#define IAP_PREWRRITE_CMD 50 /*!< Prepare sector for write operation command */
|
||||
#define IAP_WRISECTOR_CMD 51 /*!< Write Sector command */
|
||||
#define IAP_ERSSECTOR_CMD 52 /*!< Erase Sector command */
|
||||
#define IAP_BLANK_CHECK_SECTOR_CMD 53 /*!< Blank check sector */
|
||||
#define IAP_REPID_CMD 54 /*!< Read PartID command */
|
||||
#define IAP_READ_BOOT_CODE_CMD 55 /*!< Read Boot code version */
|
||||
#define IAP_COMPARE_CMD 56 /*!< Compare two RAM address locations */
|
||||
#define IAP_REINVOKE_ISP_CMD 57 /*!< Reinvoke ISP */
|
||||
#define IAP_READ_UID_CMD 58 /*!< Read UID */
|
||||
#define IAP_ERASE_PAGE_CMD 59 /*!< Erase page */
|
||||
#define IAP_EEPROM_WRITE 61 /*!< EEPROM Write command */
|
||||
#define IAP_EEPROM_READ 62 /*!< EEPROM READ command */
|
||||
|
||||
/* IAP response definitions */
|
||||
#define IAP_CMD_SUCCESS 0 /*!< Command is executed successfully */
|
||||
#define IAP_INVALID_COMMAND 1 /*!< Invalid command */
|
||||
#define IAP_SRC_ADDR_ERROR 2 /*!< Source address is not on word boundary */
|
||||
#define IAP_DST_ADDR_ERROR 3 /*!< Destination address is not on a correct boundary */
|
||||
#define IAP_SRC_ADDR_NOT_MAPPED 4 /*!< Source address is not mapped in the memory map */
|
||||
#define IAP_DST_ADDR_NOT_MAPPED 5 /*!< Destination address is not mapped in the memory map */
|
||||
#define IAP_COUNT_ERROR 6 /*!< Byte count is not multiple of 4 or is not a permitted value */
|
||||
#define IAP_INVALID_SECTOR 7 /*!< Sector number is invalid or end sector number is greater than start sector number */
|
||||
#define IAP_SECTOR_NOT_BLANK 8 /*!< Sector is not blank */
|
||||
#define IAP_SECTOR_NOT_PREPARED 9 /*!< Command to prepare sector for write operation was not executed */
|
||||
#define IAP_COMPARE_ERROR 10 /*!< Source and destination data not equal */
|
||||
#define IAP_BUSY 11 /*!< Flash programming hardware interface is busy */
|
||||
#define IAP_PARAM_ERROR 12 /*!< nsufficient number of parameters or invalid parameter */
|
||||
#define IAP_ADDR_ERROR 13 /*!< Address is not on word boundary */
|
||||
#define IAP_ADDR_NOT_MAPPED 14 /*!< Address is not mapped in the memory map */
|
||||
#define IAP_CMD_LOCKED 15 /*!< Command is locked */
|
||||
#define IAP_INVALID_CODE 16 /*!< Unlock code is invalid */
|
||||
#define IAP_INVALID_BAUD_RATE 17 /*!< Invalid baud rate setting */
|
||||
#define IAP_INVALID_STOP_BIT 18 /*!< Invalid stop bit setting */
|
||||
#define IAP_CRP_ENABLED 19 /*!< Code read protection enabled */
|
||||
|
||||
/* IAP_ENTRY API function type */
|
||||
typedef void (*IAP_ENTRY_T)(unsigned int[], unsigned int[]);
|
||||
|
||||
/**
|
||||
* @brief Prepare sector for write operation
|
||||
* @param strSector : Start sector number
|
||||
* @param endSector : End sector number
|
||||
* @return Status code to indicate the command is executed successfully or not
|
||||
* @note This command must be executed before executing "Copy RAM to flash"
|
||||
* or "Erase Sector" command.
|
||||
* The end sector must be greater than or equal to start sector number
|
||||
*/
|
||||
uint8_t Chip_IAP_PreSectorForReadWrite(uint32_t strSector, uint32_t endSector);
|
||||
|
||||
/**
|
||||
* @brief Copy RAM to flash
|
||||
* @param dstAdd : Destination FLASH address where data bytes are to be written
|
||||
* @param srcAdd : Source RAM address where data bytes are to be read
|
||||
* @param byteswrt : Number of bytes to be written
|
||||
* @return Status code to indicate the command is executed successfully or not
|
||||
* @note The addresses should be a 256 byte boundary and the number of bytes
|
||||
* should be 256 | 512 | 1024 | 4096
|
||||
*/
|
||||
uint8_t Chip_IAP_CopyRamToFlash(uint32_t dstAdd, uint32_t *srcAdd, uint32_t byteswrt);
|
||||
|
||||
/**
|
||||
* @brief Erase sector
|
||||
* @param strSector : Start sector number
|
||||
* @param endSector : End sector number
|
||||
* @return Status code to indicate the command is executed successfully or not
|
||||
* @note The end sector must be greater than or equal to start sector number
|
||||
*/
|
||||
uint8_t Chip_IAP_EraseSector(uint32_t strSector, uint32_t endSector);
|
||||
|
||||
/**
|
||||
* @brief Blank check a sector or multiples sector of on-chip flash memory
|
||||
* @param strSector : Start sector number
|
||||
* @param endSector : End sector number
|
||||
* @return Offset of the first non blank word location if the status code is SECTOR_NOT_BLANK
|
||||
* @note The end sector must be greater than or equal to start sector number
|
||||
*/
|
||||
// FIXME - There are two return value (result[0] & result[1]
|
||||
// Result0:Offset of the first non blank word location if the Status Code is
|
||||
// SECTOR_NOT_BLANK.
|
||||
// Result1:Contents of non blank word location.
|
||||
uint8_t Chip_IAP_BlankCheckSector(uint32_t strSector, uint32_t endSector);
|
||||
|
||||
/**
|
||||
* @brief Read part identification number
|
||||
* @return Part identification number
|
||||
*/
|
||||
uint32_t Chip_IAP_ReadPID(void);
|
||||
|
||||
/**
|
||||
* @brief Read boot code version number
|
||||
* @return Boot code version number
|
||||
*/
|
||||
uint32_t Chip_IAP_ReadBootCode(void);
|
||||
|
||||
/**
|
||||
* @brief Compare the memory contents at two locations
|
||||
* @param dstAdd : Destination of the RAM address of data bytes to be compared
|
||||
* @param srcAdd : Source of the RAM address of data bytes to be compared
|
||||
* @param bytescmp : Number of bytes to be compared
|
||||
* @return Offset of the first mismatch of the status code is COMPARE_ERROR
|
||||
* @note The addresses should be a word boundary and number of bytes should be
|
||||
* a multiply of 4
|
||||
*/
|
||||
uint8_t Chip_IAP_Compare(uint32_t dstAdd, uint32_t srcAdd, uint32_t bytescmp);
|
||||
|
||||
/**
|
||||
* @brief IAP reinvoke ISP to invoke the bootloader in ISP mode
|
||||
* @return none
|
||||
*/
|
||||
uint8_t Chip_IAP_ReinvokeISP(void);
|
||||
|
||||
/**
|
||||
* @brief Read the unique ID
|
||||
* @return Status code to indicate the command is executed successfully or not
|
||||
*/
|
||||
uint32_t Chip_IAP_ReadUID(uint32_t* uid);
|
||||
|
||||
/**
|
||||
* @brief Erase a page or multiple papers of on-chip flash memory
|
||||
* @param strPage : Start page number
|
||||
* @param endPage : End page number
|
||||
* @return Status code to indicate the command is executed successfully or not
|
||||
* @note The page number must be greater than or equal to start page number
|
||||
*/
|
||||
// FIXME - There are four return value
|
||||
// Result0:The first 32-bit word (at the lowest address)
|
||||
// Result1:The second 32-bit word.
|
||||
// Result2:The third 32-bit word.
|
||||
// Result3:The fourth 32-bit word.
|
||||
uint8_t Chip_IAP_ErasePage(uint32_t strPage, uint32_t endPage);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __IAP_H_ */
|
||||
156
bsp/lpc824/Libraries/peri_driver/inmux/inmux_8xx.h
Normal file
156
bsp/lpc824/Libraries/peri_driver/inmux/inmux_8xx.h
Normal file
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
* @brief LPC8xx INPUT MUX chip driver
|
||||
*
|
||||
* @note
|
||||
* Copyright(C) NXP Semiconductors, 2013
|
||||
* All rights reserved.
|
||||
*
|
||||
* @par
|
||||
* Software that is described herein is for illustrative purposes only
|
||||
* which provides customers with programming information regarding the
|
||||
* LPC products. This software is supplied "AS IS" without any warranties of
|
||||
* any kind, and NXP Semiconductors and its licensor disclaim any and
|
||||
* all warranties, express or implied, including all implied warranties of
|
||||
* merchantability, fitness for a particular purpose and non-infringement of
|
||||
* intellectual property rights. NXP Semiconductors assumes no responsibility
|
||||
* or liability for the use of the software, conveys no license or rights under any
|
||||
* patent, copyright, mask work right, or any other intellectual property rights in
|
||||
* or to any products. NXP Semiconductors reserves the right to make changes
|
||||
* in the software without notification. NXP Semiconductors also makes no
|
||||
* representation or warranty that such application will be suitable for the
|
||||
* specified use without further testing or modification.
|
||||
*
|
||||
* @par
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation is hereby granted, under NXP Semiconductors' and its
|
||||
* licensor's relevant copyrights in the software, without fee, provided that it
|
||||
* is used in conjunction with NXP Semiconductors microcontrollers. This
|
||||
* copyright, permission, and disclaimer notice must appear in all copies of
|
||||
* this code.
|
||||
*/
|
||||
|
||||
#ifndef __INMUX_8XX_H_
|
||||
#define __INMUX_8XX_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @defgroup INMUX_8XX CHIP: LPC8xx INPUT Mux Controller driver
|
||||
* @ingroup CHIP_8XX_Drivers
|
||||
* @{
|
||||
*/
|
||||
typedef struct {
|
||||
__IO uint32_t DMA_INMUX_INMUX[2]; /*!< DMA Trigger Input 20 & 21 PINMUX 0-1 */
|
||||
__O uint32_t RESERVED[6]; /*!< Reserved; Should not be used */
|
||||
__IO uint32_t SCT0_INMUX[4]; /*!< Input mux register for SCT0; INPUT0-3 */
|
||||
} LPC_INMUX_T;
|
||||
|
||||
/**
|
||||
* @brief DMA INPUT MUX Index see Chip_INMUX_SetDMAOTrig()
|
||||
*/
|
||||
typedef enum {
|
||||
DMA_INMUX_0, /*!< MUX for DMA input trigger 20 */
|
||||
DMA_INMUX_1, /*!< MUX for DMA input trigger 21 */
|
||||
}DMA_INMUX_T;
|
||||
|
||||
/**
|
||||
* @brief SCT Input Mux Index; See Chip_INMUX_SetSCTInMux()
|
||||
*/
|
||||
typedef enum {
|
||||
SCT_INMUX_0, /*!< Input mux for SCT0; INPUT 0 */
|
||||
SCT_INMUX_1, /*!< Input mux for SCT0; INPUT 1 */
|
||||
SCT_INMUX_2, /*!< Input mux for SCT0; INPUT 2 */
|
||||
SCT_INMUX_3, /*!< Input mux for SCT0; INPUT 3 */
|
||||
} SCT_INMUX_T;
|
||||
|
||||
/**
|
||||
* @brief SCT INPUT triggers
|
||||
*/
|
||||
typedef enum {
|
||||
SCT_INP_IN0, /*!< SCT0_IN0 selected by Pin Matrix */ /* FIXME: UM hints about changes */
|
||||
SCT_INP_IN1, /*!< SCT0_IN1 selected by Pin Matrix */
|
||||
SCT_INP_IN2, /*!< SCT0_IN2 selected by Pin Matrix */
|
||||
SCT_INP_IN3, /*!< SCT0_IN3 selected by Pin Matrix */
|
||||
SCT_INP_ADC_THCMP_IRQ, /*!< ADC Threshold compare IRQ */
|
||||
SCT_INP_ACMP_O, /*!< Analog comparator output */
|
||||
SCT_INP_ARM_TXEV, /*!< ARM TX Event */
|
||||
SCT_INP_DEBUG_HALTED, /*!< Debug halted event */
|
||||
} SCT_INP_T;
|
||||
|
||||
/**
|
||||
* @brief Select a trigger source for a DMA channel
|
||||
* @param pINMUX : The base of INPUT MUX register block
|
||||
* @param imux : Index of DMA input mux
|
||||
* @param ch : DMA channel ID
|
||||
* @return Nothing
|
||||
*/
|
||||
STATIC INLINE void Chip_INMUX_SetDMAOTrig(LPC_INMUX_T *pINMUX, DMA_INMUX_T imux, DMA_CHID_T ch)
|
||||
{
|
||||
pINMUX->DMA_INMUX_INMUX[imux] = ch;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Select a trigger source SCT module
|
||||
* @param pINMUX : The base of INPUT MUX register block
|
||||
* @param isct : Index of SCT input mux
|
||||
* @param trig : SCT Input function that will cause the trigger
|
||||
* @return Nothing
|
||||
*/
|
||||
STATIC INLINE void Chip_INMUX_SetSCTInMux(LPC_INMUX_T *pINMUX, SCT_INMUX_T isct, SCT_INP_T trig)
|
||||
{
|
||||
pINMUX->SCT0_INMUX[isct] = trig;
|
||||
}
|
||||
|
||||
/** @defgroup DMATRIGMUX_8XX CHIP: LPC8xx DMA trigger selection driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief DMA trigger pin muxing structure
|
||||
*/
|
||||
typedef struct { /*!< DMA trigger pin muxing register structure */
|
||||
__IO uint32_t DMA_ITRIG_INMUX[MAX_DMA_CHANNEL]; /*!< Trigger input select register for DMA channels */
|
||||
} LPC_DMATRIGMUX_T;
|
||||
|
||||
/* DMA triggers that can mapped to DMA channels */
|
||||
typedef enum {
|
||||
DMATRIG_ADC_SEQA_IRQ = 0, /*!< ADC0 sequencer A interrupt as trigger */
|
||||
DMATRIG_ADC_SEQB_IRQ, /*!< ADC0 sequencer B interrupt as trigger */
|
||||
DMATRIG_SCT0_DMA0, /*!< SCT 0, DMA 0 as trigger */
|
||||
DMATRIG_SCT0_DMA1, /*!< SCT 1, DMA 1 as trigger */
|
||||
DMATRIG_ACMP_O, /*!< Analog comparator output */
|
||||
DMATRIG_PINT0, /*!< Pin interrupt 0 as trigger */
|
||||
DMATRIG_PINT1, /*!< Pin interrupt 1 as trigger */
|
||||
DMATRIG_DMA_INMUX0, /*!< DMA Trigger MUX0 */
|
||||
DMATRIG_DMA_INMUX1, /*!< DMA Trigger MUX1 */
|
||||
} DMA_TRIGSRC_T;
|
||||
|
||||
/**
|
||||
* @brief Select a trigger source for a DMA channel
|
||||
* @param pDMATRIG : The base of DMA trigger setup block on the chip
|
||||
* @param ch : DMA channel ID
|
||||
* @param trig : Trigger source for the DMA channel
|
||||
* @return Nothing
|
||||
* @note A DMA trigger source only needs to be setup when the DMA is setup
|
||||
* for hardware trigger mode (when Chip_DMA_SetupChannelConfig() is
|
||||
* called with DMA_CFG_HWTRIGEN as OR'ed option).
|
||||
*/
|
||||
STATIC INLINE void Chip_DMATRIGMUX_SetInputTrig(LPC_DMATRIGMUX_T *pDMATRIG, DMA_CHID_T ch, DMA_TRIGSRC_T trig)
|
||||
{
|
||||
pDMATRIG->DMA_ITRIG_INMUX[ch] = (uint32_t) trig;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __INMUX_8XX_H_ */
|
||||
343
bsp/lpc824/Libraries/peri_driver/mrt/mrt_8xx.h
Normal file
343
bsp/lpc824/Libraries/peri_driver/mrt/mrt_8xx.h
Normal file
@@ -0,0 +1,343 @@
|
||||
/*
|
||||
* @brief LPC8xx Multi-Rate Timer (MRT) registers and driver functions
|
||||
*
|
||||
* @note
|
||||
* Copyright(C) NXP Semiconductors, 2012
|
||||
* All rights reserved.
|
||||
*
|
||||
* @par
|
||||
* Software that is described herein is for illustrative purposes only
|
||||
* which provides customers with programming information regarding the
|
||||
* LPC products. This software is supplied "AS IS" without any warranties of
|
||||
* any kind, and NXP Semiconductors and its licensor disclaim any and
|
||||
* all warranties, express or implied, including all implied warranties of
|
||||
* merchantability, fitness for a particular purpose and non-infringement of
|
||||
* intellectual property rights. NXP Semiconductors assumes no responsibility
|
||||
* or liability for the use of the software, conveys no license or rights under any
|
||||
* patent, copyright, mask work right, or any other intellectual property rights in
|
||||
* or to any products. NXP Semiconductors reserves the right to make changes
|
||||
* in the software without notification. NXP Semiconductors also makes no
|
||||
* representation or warranty that such application will be suitable for the
|
||||
* specified use without further testing or modification.
|
||||
*
|
||||
* @par
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation is hereby granted, under NXP Semiconductors' and its
|
||||
* licensor's relevant copyrights in the software, without fee, provided that it
|
||||
* is used in conjunction with NXP Semiconductors microcontrollers. This
|
||||
* copyright, permission, and disclaimer notice must appear in all copies of
|
||||
* this code.
|
||||
*/
|
||||
|
||||
#ifndef __MRT_8XX_H_
|
||||
#define __MRT_8XX_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @defgroup MRT_8XX CHIP: LPC8xx Multi-Rate Timer driver
|
||||
* @ingroup CHIP_8XX_Drivers
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief LPC8xx MRT chip configuration
|
||||
*/
|
||||
#define MRT_CHANNELS_NUM (4)
|
||||
#define MRT_NO_IDLE_CHANNEL (0x40)
|
||||
|
||||
/**
|
||||
* @brief MRT register block structure
|
||||
*/
|
||||
typedef struct {
|
||||
__IO uint32_t INTVAL; /*!< Timer interval register */
|
||||
__O uint32_t TIMER; /*!< Timer register */
|
||||
__IO uint32_t CTRL; /*!< Timer control register */
|
||||
__IO uint32_t STAT; /*!< Timer status register */
|
||||
} LPC_MRT_CH_T;
|
||||
|
||||
/**
|
||||
* @brief MRT register block structure
|
||||
*/
|
||||
typedef struct {
|
||||
LPC_MRT_CH_T CHANNEL[MRT_CHANNELS_NUM];
|
||||
uint32_t unused[45];
|
||||
__O uint32_t IDLE_CH;
|
||||
__IO uint32_t IRQ_FLAG;
|
||||
} LPC_MRT_T;
|
||||
|
||||
/* Reserved bits masks for registers */
|
||||
#define MRT_CTRL_RESERVED (~7)
|
||||
#define MRT_STAT_RESERVED (~3)
|
||||
|
||||
/**
|
||||
* @brief MRT Interrupt Modes enum
|
||||
*/
|
||||
typedef enum MRT_MODE {
|
||||
MRT_MODE_REPEAT = (0 << 1), /*!< MRT Repeat interrupt mode */
|
||||
MRT_MODE_ONESHOT = (1 << 1) /*!< MRT One-shot interrupt mode */
|
||||
} MRT_MODE_T;
|
||||
|
||||
/**
|
||||
* @brief MRT register bit fields & masks
|
||||
*/
|
||||
/* MRT Time interval register bit fields */
|
||||
#define MRT_INTVAL_IVALUE (0x7FFFFFFFUL) /* Maximum interval load value and mask */
|
||||
#define MRT_INTVAL_LOAD (0x80000000UL) /* Force immediate load of timer interval register bit */
|
||||
|
||||
/* MRT Control register bit fields & masks */
|
||||
#define MRT_CTRL_INTEN_MASK (0x01)
|
||||
#define MRT_CTRL_MODE_MASK (0x06)
|
||||
|
||||
/* MRT Status register bit fields & masks */
|
||||
#define MRT_STAT_INTFLAG (0x01)
|
||||
#define MRT_STAT_RUNNING (0x02)
|
||||
|
||||
/* Pointer to individual MR register blocks */
|
||||
#define LPC_MRT_CH0 ((LPC_MRT_CH_T *) &LPC_MRT->CHANNEL[0])
|
||||
#define LPC_MRT_CH1 ((LPC_MRT_CH_T *) &LPC_MRT->CHANNEL[1])
|
||||
#define LPC_MRT_CH2 ((LPC_MRT_CH_T *) &LPC_MRT->CHANNEL[2])
|
||||
#define LPC_MRT_CH3 ((LPC_MRT_CH_T *) &LPC_MRT->CHANNEL[3])
|
||||
#define LPC_MRT_CH(ch) ((LPC_MRT_CH_T *) &LPC_MRT->CHANNEL[(ch)])
|
||||
|
||||
/* Global interrupt flag register interrupt mask/clear values */
|
||||
#define MRT0_INTFLAG (1)
|
||||
#define MRT1_INTFLAG (2)
|
||||
#define MRT2_INTFLAG (4)
|
||||
#define MRT3_INTFLAG (8)
|
||||
#define MRTn_INTFLAG(ch) (1 << (ch))
|
||||
|
||||
/**
|
||||
* @brief Initializes the MRT
|
||||
* @return Nothing
|
||||
*/
|
||||
STATIC INLINE void Chip_MRT_Init(void)
|
||||
{
|
||||
/* Enable the clock to the register interface */
|
||||
Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_MRT);
|
||||
|
||||
/* Reset MRT */
|
||||
Chip_SYSCTL_PeriphReset(RESET_MRT);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief De-initializes the MRT Channel
|
||||
* @return Nothing
|
||||
*/
|
||||
STATIC INLINE void Chip_MRT_DeInit(void)
|
||||
{
|
||||
/* Disable the clock to the MRT */
|
||||
Chip_Clock_DisablePeriphClock(SYSCTL_CLOCK_MRT);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns a pointer to the register block for a MRT channel
|
||||
* @param ch : MRT channel tog et register block for (0..3)
|
||||
* @return Pointer to the MRT register block for the channel
|
||||
*/
|
||||
STATIC INLINE LPC_MRT_CH_T *Chip_MRT_GetRegPtr(uint8_t ch)
|
||||
{
|
||||
return LPC_MRT_CH(ch);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the timer time interval value
|
||||
* @param pMRT : Pointer to selected MRT Channel
|
||||
* @return Timer time interval value (IVALUE)
|
||||
*/
|
||||
STATIC INLINE uint32_t Chip_MRT_GetInterval(LPC_MRT_CH_T *pMRT)
|
||||
{
|
||||
return pMRT->INTVAL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets the timer time interval value
|
||||
* @param pMRT : Pointer to selected MRT Channel
|
||||
* @param interval : The interval timeout (31-bits)
|
||||
* @return Nothing
|
||||
* @note Setting bit 31 in timer time interval register causes the time interval value
|
||||
* to load immediately, otherwise the time interval value will be loaded in
|
||||
* next timer cycle.<br>
|
||||
* Example: Chip_MRT_SetInterval(pMRT, 0x500 | MRT_INTVAL_LOAD); // Will load timer interval immediately<br>
|
||||
* Example: Chip_MRT_SetInterval(pMRT, 0x500); // Will load timer interval after internal expires
|
||||
*/
|
||||
STATIC INLINE void Chip_MRT_SetInterval(LPC_MRT_CH_T *pMRT, uint32_t interval)
|
||||
{
|
||||
pMRT->INTVAL = interval;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the current timer value
|
||||
* @param pMRT : Pointer to selected MRT Channel
|
||||
* @return The current timer value
|
||||
*/
|
||||
STATIC INLINE uint32_t Chip_MRT_GetTimer(LPC_MRT_CH_T *pMRT)
|
||||
{
|
||||
return pMRT->TIMER;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns true if the timer is enabled
|
||||
* @param pMRT : Pointer to selected MRT Channel
|
||||
* @return True if enabled, Flase if not enabled
|
||||
*/
|
||||
STATIC INLINE bool Chip_MRT_GetEnabled(LPC_MRT_CH_T *pMRT)
|
||||
{
|
||||
return (bool) ((pMRT->CTRL & MRT_CTRL_INTEN_MASK) != 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enables the timer
|
||||
* @param pMRT : Pointer to selected MRT Channel
|
||||
* @return Nothing
|
||||
*/
|
||||
STATIC INLINE void Chip_MRT_SetEnabled(LPC_MRT_CH_T *pMRT)
|
||||
{
|
||||
pMRT->CTRL = MRT_CTRL_INTEN_MASK | (pMRT->CTRL & ~MRT_CTRL_RESERVED);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disables the timer
|
||||
* @param pMRT : Pointer to selected MRT Channel
|
||||
* @return Nothing
|
||||
*/
|
||||
STATIC INLINE void Chip_MRT_SetDisabled(LPC_MRT_CH_T *pMRT)
|
||||
{
|
||||
pMRT->CTRL &= ~(MRT_CTRL_INTEN_MASK | MRT_CTRL_RESERVED);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the timer mode (repeat or one-shot)
|
||||
* @param pMRT : Pointer to selected MRT Channel
|
||||
* @return The current timer mode
|
||||
*/
|
||||
STATIC INLINE MRT_MODE_T Chip_MRT_GetMode(LPC_MRT_CH_T *pMRT)
|
||||
{
|
||||
return (MRT_MODE_T) (pMRT->CTRL & MRT_CTRL_MODE_MASK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets the timer mode (repeat or one-shot)
|
||||
* @param pMRT : Pointer to selected MRT Channel
|
||||
* @param mode : Timer mode
|
||||
* @return Nothing
|
||||
*/
|
||||
STATIC INLINE void Chip_MRT_SetMode(LPC_MRT_CH_T *pMRT, MRT_MODE_T mode)
|
||||
{
|
||||
uint32_t reg;
|
||||
|
||||
reg = pMRT->CTRL & ~(MRT_CTRL_MODE_MASK | MRT_CTRL_RESERVED);
|
||||
pMRT->CTRL = reg | (uint32_t) mode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check if the timer is configured in repeat mode
|
||||
* @param pMRT : Pointer to selected MRT Channel
|
||||
* @return True if in repeat mode, False if in one-shot mode
|
||||
*/
|
||||
STATIC INLINE bool Chip_MRT_IsRepeatMode(LPC_MRT_CH_T *pMRT)
|
||||
{
|
||||
return ((pMRT->CTRL & MRT_CTRL_MODE_MASK) != 0) ? false : true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check if the timer is configured in one-shot mode
|
||||
* @param pMRT : Pointer to selected MRT Channel
|
||||
* @return True if in one-shot mode, False if in repeat mode
|
||||
*/
|
||||
STATIC INLINE bool Chip_MRT_IsOneShotMode(LPC_MRT_CH_T *pMRT)
|
||||
{
|
||||
return ((pMRT->CTRL & MRT_CTRL_MODE_MASK) != 0) ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check if the timer has an interrupt pending
|
||||
* @param pMRT : Pointer to selected MRT Channel
|
||||
* @return True if interrupt is pending, False if no interrupt is pending
|
||||
*/
|
||||
STATIC INLINE bool Chip_MRT_IntPending(LPC_MRT_CH_T *pMRT)
|
||||
{
|
||||
return (bool) ((pMRT->STAT & MRT_STAT_INTFLAG) != 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Clears the pending interrupt (if any)
|
||||
* @param pMRT : Pointer to selected MRT Channel
|
||||
* @return Nothing
|
||||
*/
|
||||
STATIC INLINE void Chip_MRT_IntClear(LPC_MRT_CH_T *pMRT)
|
||||
{
|
||||
pMRT->STAT = MRT_STAT_INTFLAG | (pMRT->STAT & ~MRT_STAT_RESERVED);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check if the timer is running
|
||||
* @param pMRT : Pointer to selected MRT Channel
|
||||
* @return True if running, False if stopped
|
||||
*/
|
||||
STATIC INLINE bool Chip_MRT_Running(LPC_MRT_CH_T *pMRT)
|
||||
{
|
||||
return (bool) ((pMRT->STAT & MRT_STAT_RUNNING) != 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the IDLE channel value
|
||||
* @return IDLE channel value (unshifted in bits 7..4)
|
||||
*/
|
||||
STATIC INLINE uint8_t Chip_MRT_GetIdleChannel(void)
|
||||
{
|
||||
return (uint8_t) (LPC_MRT->IDLE_CH);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the IDLE channel value
|
||||
* @return IDLE channel value (shifted in bits 3..0)
|
||||
*/
|
||||
STATIC INLINE uint8_t Chip_MRT_GetIdleChannelShifted(void)
|
||||
{
|
||||
return (uint8_t) (Chip_MRT_GetIdleChannel() >> 4);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the interrupt pending status for all MRT channels
|
||||
* @return IRQ pending channel bitfield(bit 0 = MRT0, bit 1 = MRT1, etc.)
|
||||
*/
|
||||
STATIC INLINE uint32_t Chip_MRT_GetIntPending(void)
|
||||
{
|
||||
return LPC_MRT->IRQ_FLAG;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the interrupt pending status for a singel MRT channel
|
||||
* @param ch : Channel to check pending interrupt status for
|
||||
* @return IRQ pending channel number
|
||||
*/
|
||||
STATIC INLINE bool Chip_MRT_GetIntPendingByChannel(uint8_t ch)
|
||||
{
|
||||
return (bool) (((LPC_MRT->IRQ_FLAG >> ch) & 1) != 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Clears the interrupt pending status for one or more MRT channels
|
||||
* @param mask : Channels to clear (bit 0 = MRT0, bit 1 = MRT1, etc.)
|
||||
* @return Nothing
|
||||
* @note Use this function to clear multiple interrupt pending states in
|
||||
* a single call via the IRQ_FLAG register. Performs the same function for
|
||||
* all MRT channels in a single call as the Chip_MRT_IntClear() does for a
|
||||
* single channel.
|
||||
*/
|
||||
STATIC INLINE void Chip_MRT_ClearIntPending(uint32_t mask)
|
||||
{
|
||||
LPC_MRT->IRQ_FLAG = mask;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __MRT_8XX_H_ */
|
||||
111
bsp/lpc824/Libraries/peri_driver/mrt/stopwatch.c
Normal file
111
bsp/lpc824/Libraries/peri_driver/mrt/stopwatch.c
Normal file
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* @brief LPC8xx specific stopwatch implementation
|
||||
*
|
||||
* @note
|
||||
* Copyright(C) NXP Semiconductors, 2013
|
||||
* All rights reserved.
|
||||
*
|
||||
* @par
|
||||
* Software that is described herein is for illustrative purposes only
|
||||
* which provides customers with programming information regarding the
|
||||
* LPC products. This software is supplied "AS IS" without any warranties of
|
||||
* any kind, and NXP Semiconductors and its licensor disclaim any and
|
||||
* all warranties, express or implied, including all implied warranties of
|
||||
* merchantability, fitness for a particular purpose and non-infringement of
|
||||
* intellectual property rights. NXP Semiconductors assumes no responsibility
|
||||
* or liability for the use of the software, conveys no license or rights under any
|
||||
* patent, copyright, mask work right, or any other intellectual property rights in
|
||||
* or to any products. NXP Semiconductors reserves the right to make changes
|
||||
* in the software without notification. NXP Semiconductors also makes no
|
||||
* representation or warranty that such application will be suitable for the
|
||||
* specified use without further testing or modification.
|
||||
*
|
||||
* @par
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation is hereby granted, under NXP Semiconductors' and its
|
||||
* licensor's relevant copyrights in the software, without fee, provided that it
|
||||
* is used in conjunction with NXP Semiconductors microcontrollers. This
|
||||
* copyright, permission, and disclaimer notice must appear in all copies of
|
||||
* this code.
|
||||
*/
|
||||
|
||||
#include "chip.h"
|
||||
#include "stopwatch.h"
|
||||
|
||||
/*****************************************************************************
|
||||
* Private types/enumerations/variables
|
||||
****************************************************************************/
|
||||
|
||||
/* Precompute these to optimize runtime */
|
||||
static uint32_t ticksPerSecond;
|
||||
static uint32_t ticksPerMs;
|
||||
static uint32_t ticksPerUs;
|
||||
|
||||
/*****************************************************************************
|
||||
* Public types/enumerations/variables
|
||||
****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* Private functions
|
||||
****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* Public functions
|
||||
****************************************************************************/
|
||||
|
||||
/* Initialize stopwatch */
|
||||
void StopWatch_Init(void)
|
||||
{
|
||||
Chip_MRT_Init();
|
||||
Chip_MRT_SetMode(LPC_MRT_CH1, MRT_MODE_REPEAT);
|
||||
Chip_MRT_SetInterval(LPC_MRT_CH1, 0x7ffffff | MRT_INTVAL_LOAD);
|
||||
Chip_MRT_GetEnabled(LPC_MRT_CH1);
|
||||
|
||||
/* Pre-compute tick rate. */
|
||||
ticksPerSecond = Chip_Clock_GetSystemClockRate();
|
||||
ticksPerMs = ticksPerSecond / 1000;
|
||||
ticksPerUs = ticksPerSecond / 1000000;
|
||||
}
|
||||
/* reset stopwatch */
|
||||
void StopWatch_Reset(void)
|
||||
{
|
||||
Chip_MRT_SetInterval(LPC_MRT_CH1, 0x7ffffff | MRT_INTVAL_LOAD);
|
||||
}
|
||||
|
||||
|
||||
/* Start a stopwatch */
|
||||
uint32_t StopWatch_Start(void)
|
||||
{
|
||||
/* Return the current timer count. */
|
||||
return 0x7ffffff - Chip_MRT_GetTimer(LPC_MRT_CH1);
|
||||
}
|
||||
|
||||
/* Returns number of ticks per second of the stopwatch timer */
|
||||
uint32_t StopWatch_TicksPerSecond(void)
|
||||
{
|
||||
return ticksPerSecond;
|
||||
}
|
||||
|
||||
/* Converts from stopwatch ticks to mS. */
|
||||
uint32_t StopWatch_TicksToMs(uint32_t ticks)
|
||||
{
|
||||
return ticks / ticksPerMs;
|
||||
}
|
||||
|
||||
/* Converts from stopwatch ticks to uS. */
|
||||
uint32_t StopWatch_TicksToUs(uint32_t ticks)
|
||||
{
|
||||
return ticks / ticksPerUs;
|
||||
}
|
||||
|
||||
/* Converts from mS to stopwatch ticks. */
|
||||
uint32_t StopWatch_MsToTicks(uint32_t mS)
|
||||
{
|
||||
return mS * ticksPerMs;
|
||||
}
|
||||
|
||||
/* Converts from uS to stopwatch ticks. */
|
||||
uint32_t StopWatch_UsToTicks(uint32_t uS)
|
||||
{
|
||||
return uS * ticksPerUs;
|
||||
}
|
||||
143
bsp/lpc824/Libraries/peri_driver/mrt/stopwatch.h
Normal file
143
bsp/lpc824/Libraries/peri_driver/mrt/stopwatch.h
Normal file
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
* @brief Common stopwatch support
|
||||
*
|
||||
* @note
|
||||
* Copyright(C) NXP Semiconductors, 2013
|
||||
* All rights reserved.
|
||||
*
|
||||
* @par
|
||||
* Software that is described herein is for illustrative purposes only
|
||||
* which provides customers with programming information regarding the
|
||||
* LPC products. This software is supplied "AS IS" without any warranties of
|
||||
* any kind, and NXP Semiconductors and its licensor disclaim any and
|
||||
* all warranties, express or implied, including all implied warranties of
|
||||
* merchantability, fitness for a particular purpose and non-infringement of
|
||||
* intellectual property rights. NXP Semiconductors assumes no responsibility
|
||||
* or liability for the use of the software, conveys no license or rights under any
|
||||
* patent, copyright, mask work right, or any other intellectual property rights in
|
||||
* or to any products. NXP Semiconductors reserves the right to make changes
|
||||
* in the software without notification. NXP Semiconductors also makes no
|
||||
* representation or warranty that such application will be suitable for the
|
||||
* specified use without further testing or modification.
|
||||
*
|
||||
* @par
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation is hereby granted, under NXP Semiconductors' and its
|
||||
* licensor's relevant copyrights in the software, without fee, provided that it
|
||||
* is used in conjunction with NXP Semiconductors microcontrollers. This
|
||||
* copyright, permission, and disclaimer notice must appear in all copies of
|
||||
* this code.
|
||||
*/
|
||||
|
||||
#ifndef __STOPWATCH_H_
|
||||
#define __STOPWATCH_H_
|
||||
|
||||
#include "cmsis.h"
|
||||
|
||||
/** @defgroup Stop_Watch CHIP: Stopwatch primitives.
|
||||
* @ingroup CHIP_Common
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Initialize stopwatch
|
||||
* @return Nothing
|
||||
*/
|
||||
void StopWatch_Init(void);
|
||||
|
||||
/**
|
||||
* @brief reset stopwatch
|
||||
* @return Nothing
|
||||
*/
|
||||
void StopWatch_Reset(void);
|
||||
|
||||
/**
|
||||
* @brief Start a stopwatch
|
||||
* @return Current cycle count
|
||||
*/
|
||||
uint32_t StopWatch_Start(void);
|
||||
|
||||
/**
|
||||
* @brief Returns number of ticks elapsed since stopwatch was started
|
||||
* @param startTime : Time returned by StopWatch_Start().
|
||||
* @return Number of ticks elapsed since stopwatch was started
|
||||
*/
|
||||
STATIC INLINE uint32_t StopWatch_Elapsed(uint32_t startTime)
|
||||
{
|
||||
return StopWatch_Start() - startTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns number of ticks per second of the stopwatch timer
|
||||
* @return Number of ticks per second of the stopwatch timer
|
||||
*/
|
||||
uint32_t StopWatch_TicksPerSecond(void);
|
||||
|
||||
/**
|
||||
* @brief Converts from stopwatch ticks to mS.
|
||||
* @param ticks : Duration in ticks to convert to mS.
|
||||
* @return Number of mS in given number of ticks
|
||||
*/
|
||||
uint32_t StopWatch_TicksToMs(uint32_t ticks);
|
||||
|
||||
/**
|
||||
* @brief Converts from stopwatch ticks to uS.
|
||||
* @param ticks : Duration in ticks to convert to uS.
|
||||
* @return Number of uS in given number of ticks
|
||||
*/
|
||||
uint32_t StopWatch_TicksToUs(uint32_t ticks);
|
||||
|
||||
/**
|
||||
* @brief Converts from mS to stopwatch ticks.
|
||||
* @param mS : Duration in mS to convert to ticks.
|
||||
* @return Number of ticks in given number of mS
|
||||
*/
|
||||
uint32_t StopWatch_MsToTicks(uint32_t mS);
|
||||
|
||||
/**
|
||||
* @brief Converts from uS to stopwatch ticks.
|
||||
* @param uS : Duration in uS to convert to ticks.
|
||||
* @return Number of ticks in given number of uS
|
||||
*/
|
||||
uint32_t StopWatch_UsToTicks(uint32_t uS);
|
||||
|
||||
/**
|
||||
* @brief Delays the given number of ticks using stopwatch primitives
|
||||
* @param ticks : Number of ticks to delay
|
||||
* @return Nothing
|
||||
*/
|
||||
STATIC INLINE void StopWatch_DelayTicks(uint32_t ticks)
|
||||
{
|
||||
uint32_t startTime = StopWatch_Start();
|
||||
while (StopWatch_Elapsed(startTime) < ticks) {}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Delays the given number of mS using stopwatch primitives
|
||||
* @param mS : Number of mS to delay
|
||||
* @return Nothing
|
||||
*/
|
||||
STATIC INLINE void StopWatch_DelayMs(uint32_t mS)
|
||||
{
|
||||
uint32_t ticks = StopWatch_MsToTicks(mS);
|
||||
uint32_t startTime = StopWatch_Start();
|
||||
while (StopWatch_Elapsed(startTime) < ticks) {}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Delays the given number of uS using stopwatch primitives
|
||||
* @param uS : Number of uS to delay
|
||||
* @return Nothing
|
||||
*/
|
||||
STATIC INLINE void StopWatch_DelayUs(uint32_t uS)
|
||||
{
|
||||
uint32_t ticks = StopWatch_UsToTicks(uS);
|
||||
uint32_t startTime = StopWatch_Start();
|
||||
while (StopWatch_Elapsed(startTime) < ticks) {}
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* __STOPWATCH_H_ */
|
||||
39
bsp/lpc824/Libraries/peri_driver/peri_driver.h
Normal file
39
bsp/lpc824/Libraries/peri_driver/peri_driver.h
Normal file
@@ -0,0 +1,39 @@
|
||||
#ifndef _PERI_DRIVER_H_
|
||||
#define _PERI_DRIVER_H_
|
||||
|
||||
#include "chip.h"
|
||||
#include "rom/romapi_8xx.h"
|
||||
#include "acmp/acmp_8xx.h"
|
||||
|
||||
#if defined(CHIP_LPC82X)
|
||||
#include "adc/adc_8xx.h"
|
||||
#endif
|
||||
|
||||
#include "crc/crc_8xx.h"
|
||||
|
||||
#if defined(CHIP_LPC82X)
|
||||
#include "dma/dma_8xx.h"
|
||||
#endif
|
||||
|
||||
#include "gpio/gpio_8xx.h"
|
||||
#include "i2c/i2c_8xx.h"
|
||||
#include "iap/iap.h"
|
||||
#include "crc/crc_8xx.h"
|
||||
|
||||
#if defined(CHIP_LPC82X)
|
||||
#include "inmux/inmux_8xx.h"
|
||||
#endif
|
||||
|
||||
#include "mrt/mrt_8xx.h"
|
||||
#include "mrt/stopwatch.h"
|
||||
#include "pinint/pinint_8xx.h"
|
||||
#include "pmu/pmu_8xx.h"
|
||||
|
||||
#include "sctimer/sct_8xx.h"
|
||||
#include "sctimer/sct_pwm_8xx.h"
|
||||
#include "spi/spi_8xx.h"
|
||||
#include "uart/uart_8xx.h"
|
||||
#include "wkt/wkt_8xx.h"
|
||||
#include "wwdt/wwdt_8xx.h"
|
||||
#include "iap/iap.h"
|
||||
#endif
|
||||
81
bsp/lpc824/Libraries/peri_driver/pinint/pinint_8xx.c
Normal file
81
bsp/lpc824/Libraries/peri_driver/pinint/pinint_8xx.c
Normal file
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* @brief LPC8xx Pin Interrupt and Pattern Match driver
|
||||
*
|
||||
* @note
|
||||
* Copyright(C) NXP Semiconductors, 2012
|
||||
* All rights reserved.
|
||||
*
|
||||
* @par
|
||||
* Software that is described herein is for illustrative purposes only
|
||||
* which provides customers with programming information regarding the
|
||||
* LPC products. This software is supplied "AS IS" without any warranties of
|
||||
* any kind, and NXP Semiconductors and its licenser disclaim any and
|
||||
* all warranties, express or implied, including all implied warranties of
|
||||
* merchantability, fitness for a particular purpose and non-infringement of
|
||||
* intellectual property rights. NXP Semiconductors assumes no responsibility
|
||||
* or liability for the use of the software, conveys no license or rights under any
|
||||
* patent, copyright, mask work right, or any other intellectual property rights in
|
||||
* or to any products. NXP Semiconductors reserves the right to make changes
|
||||
* in the software without notification. NXP Semiconductors also makes no
|
||||
* representation or warranty that such application will be suitable for the
|
||||
* specified use without further testing or modification.
|
||||
*
|
||||
* @par
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation is hereby granted, under NXP Semiconductors' and its
|
||||
* licensor's relevant copyrights in the software, without fee, provided that it
|
||||
* is used in conjunction with NXP Semiconductors microcontrollers. This
|
||||
* copyright, permission, and disclaimer notice must appear in all copies of
|
||||
* this code.
|
||||
*/
|
||||
|
||||
#include "chip.h"
|
||||
|
||||
/*****************************************************************************
|
||||
* Private types/enumerations/variables
|
||||
****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* Public types/enumerations/variables
|
||||
****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* Private functions
|
||||
****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* Public functions
|
||||
****************************************************************************/
|
||||
|
||||
/* Set source for pattern match engine */
|
||||
void Chip_PININT_SetPatternMatchSrc(LPC_PININT_T *pPININT, uint8_t chan, Chip_PININT_BITSLICE_T slice)
|
||||
{
|
||||
uint32_t pmsrc_reg;
|
||||
|
||||
/* Source source for pattern matching */
|
||||
pmsrc_reg = pPININT->PMSRC & ~((PININT_SRC_BITSOURCE_MASK << (PININT_SRC_BITSOURCE_START + (slice * 3)))
|
||||
| PININT_PMSRC_RESERVED);
|
||||
pPININT->PMSRC = pmsrc_reg | (chan << (PININT_SRC_BITSOURCE_START + (slice * 3)));
|
||||
}
|
||||
|
||||
/* Configure Pattern match engine */
|
||||
void Chip_PININT_SetPatternMatchConfig(LPC_PININT_T *pPININT, Chip_PININT_BITSLICE_T slice,
|
||||
Chip_PININT_BITSLICE_CFG_T slice_cfg, bool end_point)
|
||||
{
|
||||
uint32_t pmcfg_reg;
|
||||
|
||||
/* Configure bit slice configuration */
|
||||
pmcfg_reg = pPININT->PMCFG & ~((PININT_SRC_BITCFG_MASK << (PININT_SRC_BITCFG_START + (slice * 3)))
|
||||
| PININT_PMCFG_RESERVED);
|
||||
pPININT->PMCFG = pmcfg_reg | (slice_cfg << (PININT_SRC_BITCFG_START + (slice * 3)));
|
||||
|
||||
/* If end point is true, enable the bits */
|
||||
if (end_point == true)
|
||||
{
|
||||
/* By default slice 7 is final component */
|
||||
if (slice != PININTBITSLICE7)
|
||||
{
|
||||
pPININT->PMCFG = (0x1 << slice) | (pPININT->PMCFG & ~PININT_PMCFG_RESERVED);
|
||||
}
|
||||
}
|
||||
}
|
||||
389
bsp/lpc824/Libraries/peri_driver/pinint/pinint_8xx.h
Normal file
389
bsp/lpc824/Libraries/peri_driver/pinint/pinint_8xx.h
Normal file
@@ -0,0 +1,389 @@
|
||||
/*
|
||||
* @brief LPC8xx Pin Interrupt and Pattern Match Registers and driver
|
||||
*
|
||||
* @note
|
||||
* Copyright(C) NXP Semiconductors, 2012
|
||||
* All rights reserved.
|
||||
*
|
||||
* @par
|
||||
* Software that is described herein is for illustrative purposes only
|
||||
* which provides customers with programming information regarding the
|
||||
* LPC products. This software is supplied "AS IS" without any warranties of
|
||||
* any kind, and NXP Semiconductors and its licensor disclaim any and
|
||||
* all warranties, express or implied, including all implied warranties of
|
||||
* merchantability, fitness for a particular purpose and non-infringement of
|
||||
* intellectual property rights. NXP Semiconductors assumes no responsibility
|
||||
* or liability for the use of the software, conveys no license or rights under any
|
||||
* patent, copyright, mask work right, or any other intellectual property rights in
|
||||
* or to any products. NXP Semiconductors reserves the right to make changes
|
||||
* in the software without notification. NXP Semiconductors also makes no
|
||||
* representation or warranty that such application will be suitable for the
|
||||
* specified use without further testing or modification.
|
||||
*
|
||||
* @par
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation is hereby granted, under NXP Semiconductors' and its
|
||||
* licensor's relevant copyrights in the software, without fee, provided that it
|
||||
* is used in conjunction with NXP Semiconductors microcontrollers. This
|
||||
* copyright, permission, and disclaimer notice must appear in all copies of
|
||||
* this code.
|
||||
*/
|
||||
|
||||
#ifndef __PININT_8XX_H_
|
||||
#define __PININT_8XX_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @defgroup PININT_8XX CHIP: LPC8xx Pin Interrupt and Pattern Match driver
|
||||
* @ingroup CHIP_8XX_Drivers
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief LPC8xx Pin Interrupt and Pattern Match register block structure
|
||||
*/
|
||||
typedef struct { /*!< (@ 0xA0004000) PIN_INT Structure */
|
||||
__IO uint32_t ISEL; /*!< (@ 0xA0004000) Pin Interrupt Mode register */
|
||||
__IO uint32_t IENR; /*!< (@ 0xA0004004) Pin Interrupt Enable (Rising) register */
|
||||
__IO uint32_t SIENR; /*!< (@ 0xA0004008) Set Pin Interrupt Enable (Rising) register */
|
||||
__IO uint32_t CIENR; /*!< (@ 0xA000400C) Clear Pin Interrupt Enable (Rising) register */
|
||||
__IO uint32_t IENF; /*!< (@ 0xA0004010) Pin Interrupt Enable Falling Edge / Active Level register */
|
||||
__IO uint32_t SIENF; /*!< (@ 0xA0004014) Set Pin Interrupt Enable Falling Edge / Active Level register */
|
||||
__IO uint32_t CIENF; /*!< (@ 0xA0004018) Clear Pin Interrupt Enable Falling Edge / Active Level address */
|
||||
__IO uint32_t RISE; /*!< (@ 0xA000401C) Pin Interrupt Rising Edge register */
|
||||
__IO uint32_t FALL; /*!< (@ 0xA0004020) Pin Interrupt Falling Edge register */
|
||||
__IO uint32_t IST; /*!< (@ 0xA0004024) Pin Interrupt Status register */
|
||||
__IO uint32_t PMCTRL; /*!< (@ 0xA0004028) GPIO pattern match interrupt control register */
|
||||
__IO uint32_t PMSRC; /*!< (@ 0xA000402C) GPIO pattern match interrupt bit-slice source register */
|
||||
__IO uint32_t PMCFG; /*!< (@ 0xA0004030) GPIO pattern match interrupt bit slice configuration register */
|
||||
} LPC_PININT_T;
|
||||
|
||||
/* Reserved bits masks for registers */
|
||||
#define PININT_ISEL_RESERVED (~0xff)
|
||||
#define PININT_IENR_RESERVED (~0xff)
|
||||
#define PININT_SIENR_RESERVED (~0xff)
|
||||
#define PININT_CIENR_RESERVED (~0xff)
|
||||
#define PININT_IENF_RESERVED (~0xff)
|
||||
#define PININT_SIENF_RESERVED (~0xff)
|
||||
#define PININT_CIENF_RESERVED (~0xff)
|
||||
#define PININT_RISE_RESERVED (~0xff)
|
||||
#define PININT_FALL_RESERVED (~0xff)
|
||||
#define PININT_IST_RESERVED (~0xff)
|
||||
#define PININT_PMCTRL_RESERVED (~0xff000003)
|
||||
#define PININT_PMSRC_RESERVED 0xff
|
||||
#define PININT_PMCFG_RESERVED (1<<7)
|
||||
|
||||
/**
|
||||
* LPC8xx Pin Interrupt and Pattern match engine register
|
||||
* bit fields and macros
|
||||
*/
|
||||
/* PININT interrupt control register */
|
||||
#define PININT_PMCTRL_PMATCH_SEL (1 << 0)
|
||||
#define PININT_PMCTRL_RXEV_ENA (1 << 1)
|
||||
|
||||
/* PININT Bit slice source register bits */
|
||||
#define PININT_SRC_BITSOURCE_START 8
|
||||
#define PININT_SRC_BITSOURCE_MASK 7
|
||||
|
||||
/* PININT Bit slice configuration register bits */
|
||||
#define PININT_SRC_BITCFG_START 8
|
||||
#define PININT_SRC_BITCFG_MASK 7
|
||||
|
||||
/**
|
||||
* LPC8xx Pin Interrupt channel values
|
||||
*/
|
||||
#define PININTCH0 (1 << 0)
|
||||
#define PININTCH1 (1 << 1)
|
||||
#define PININTCH2 (1 << 2)
|
||||
#define PININTCH3 (1 << 3)
|
||||
#define PININTCH4 (1 << 4)
|
||||
#define PININTCH5 (1 << 5)
|
||||
#define PININTCH6 (1 << 6)
|
||||
#define PININTCH7 (1 << 7)
|
||||
#define PININTCH(ch) (1 << (ch))
|
||||
|
||||
/**
|
||||
* LPC8xx Pin Matching Interrupt bit slice enum values
|
||||
*/
|
||||
typedef enum Chip_PININT_BITSLICE {
|
||||
PININTBITSLICE0 = 0, /*!< PININT Bit slice 0 */
|
||||
PININTBITSLICE1 = 1, /*!< PININT Bit slice 1 */
|
||||
PININTBITSLICE2 = 2, /*!< PININT Bit slice 2 */
|
||||
PININTBITSLICE3 = 3, /*!< PININT Bit slice 3 */
|
||||
PININTBITSLICE4 = 4, /*!< PININT Bit slice 4 */
|
||||
PININTBITSLICE5 = 5, /*!< PININT Bit slice 5 */
|
||||
PININTBITSLICE6 = 6, /*!< PININT Bit slice 6 */
|
||||
PININTBITSLICE7 = 7 /*!< PININT Bit slice 7 */
|
||||
} Chip_PININT_BITSLICE_T;
|
||||
|
||||
/**
|
||||
* LPC8xx Pin Matching Interrupt bit slice configuration enum values
|
||||
*/
|
||||
typedef enum Chip_PININT_BITSLICE_CFG {
|
||||
PININT_PATTERNCONST1 = 0x0, /*!< Contributes to product term match */
|
||||
PININT_PATTERNRISING = 0x1, /*!< Rising edge */
|
||||
PININT_PATTERNFALLING = 0x2, /*!< Falling edge */
|
||||
PININT_PATTERNRISINGRFALLING = 0x3, /*!< Rising or Falling edge */
|
||||
PININT_PATTERNHIGH = 0x4, /*!< High level */
|
||||
PININT_PATTERNLOW = 0x5, /*!< Low level */
|
||||
PININT_PATTERCONST0 = 0x6, /*!< Never contributes for match */
|
||||
PININT_PATTEREVENT = 0x7 /*!< Match occurs on event */
|
||||
} Chip_PININT_BITSLICE_CFG_T;
|
||||
|
||||
/**
|
||||
* @brief Initialize Pin interrupt block
|
||||
* @param pPININT : The base address of Pin interrupt block
|
||||
* @return Nothing
|
||||
* @note This function should be used after the Chip_GPIO_Init() function.
|
||||
*/
|
||||
STATIC INLINE void Chip_PININT_Init(LPC_PININT_T *pPININT) {}
|
||||
|
||||
/**
|
||||
* @brief De-Initialize Pin interrupt block
|
||||
* @param pPININT : The base address of Pin interrupt block
|
||||
* @return Nothing
|
||||
*/
|
||||
STATIC INLINE void Chip_PININT_DeInit(LPC_PININT_T *pPININT) {}
|
||||
|
||||
/**
|
||||
* @brief Configure the pins as edge sensitive in Pin interrupt block
|
||||
* @param pPININT : The base address of Pin interrupt block
|
||||
* @param pins : Pins (ORed value of PININTCH*)
|
||||
* @return Nothing
|
||||
*/
|
||||
STATIC INLINE void Chip_PININT_SetPinModeEdge(LPC_PININT_T *pPININT, uint32_t pins)
|
||||
{
|
||||
pPININT->ISEL &= ~(pins | PININT_ISEL_RESERVED);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configure the pins as level sensitive in Pin interrupt block
|
||||
* @param pPININT : The base address of Pin interrupt block
|
||||
* @param pins : Pins (ORed value of PININTCH*)
|
||||
* @return Nothing
|
||||
*/
|
||||
STATIC INLINE void Chip_PININT_SetPinModeLevel(LPC_PININT_T *pPININT, uint32_t pins)
|
||||
{
|
||||
pPININT->ISEL = pins | (pPININT->ISEL & ~PININT_ISEL_RESERVED);
|
||||
pPININT->SIENR = pins;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return current PININT rising edge or high level interrupt enable state
|
||||
* @param pPININT : The base address of Pin interrupt block
|
||||
* @return A bifield containing the high edge/level interrupt enables for each
|
||||
* interrupt. Bit 0 = PININT0, 1 = PININT1, etc.
|
||||
* For each bit, a 0 means the high edge/level interrupt is disabled, while a 1
|
||||
* means it's enabled.
|
||||
*/
|
||||
STATIC INLINE uint32_t Chip_PININT_GetHighEnabled(LPC_PININT_T *pPININT)
|
||||
{
|
||||
return pPININT->IENR & ~PININT_IENR_RESERVED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable high edge/level PININT interrupts for pins
|
||||
* @param pPININT : The base address of Pin interrupt block
|
||||
* @param pins : Pins to enable (ORed value of PININTCH*)
|
||||
* @return Nothing
|
||||
*/
|
||||
STATIC INLINE void Chip_PININT_EnableIntHigh(LPC_PININT_T *pPININT, uint32_t pins)
|
||||
{
|
||||
pPININT->SIENR = pins;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Select high/low level for level sensitive PININT interrupts
|
||||
* @param pPININT : The base address of Pin interrupt block
|
||||
* @param pins : Pins to enable (ORed value of PININTCH*)
|
||||
* @return Nothing
|
||||
*/
|
||||
STATIC INLINE void Chip_PININT_SelectLevel(LPC_PININT_T *pPININT, uint32_t pins, bool isHigh)
|
||||
{
|
||||
if (isHigh)
|
||||
pPININT->SIENF = pins;
|
||||
else
|
||||
pPININT->CIENF = pins;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Disable high edge/level PININT interrupts for pins
|
||||
* @param pPININT : The base address of Pin interrupt block
|
||||
* @param pins : Pins to disable (ORed value of PININTCH*)
|
||||
* @return Nothing
|
||||
*/
|
||||
STATIC INLINE void Chip_PININT_DisableIntHigh(LPC_PININT_T *pPININT, uint32_t pins)
|
||||
{
|
||||
pPININT->CIENR = pins;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return current PININT falling edge or low level interrupt enable state
|
||||
* @param pPININT : The base address of Pin interrupt block
|
||||
* @return A bifield containing the low edge/level interrupt enables for each
|
||||
* interrupt. Bit 0 = PININT0, 1 = PININT1, etc.
|
||||
* For each bit, a 0 means the low edge/level interrupt is disabled, while a 1
|
||||
* means it's enabled.
|
||||
*/
|
||||
STATIC INLINE uint32_t Chip_PININT_GetLowEnabled(LPC_PININT_T *pPININT)
|
||||
{
|
||||
return pPININT->IENF & ~PININT_IENF_RESERVED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable low edge/level PININT interrupts for pins
|
||||
* @param pPININT : The base address of Pin interrupt block
|
||||
* @param pins : Pins to enable (ORed value of PININTCH*)
|
||||
* @return Nothing
|
||||
*/
|
||||
STATIC INLINE void Chip_PININT_EnableIntLow(LPC_PININT_T *pPININT, uint32_t pins)
|
||||
{
|
||||
pPININT->SIENF = pins;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disable low edge/level PININT interrupts for pins
|
||||
* @param pPININT : The base address of Pin interrupt block
|
||||
* @param pins : Pins to disable (ORed value of PININTCH*)
|
||||
* @return Nothing
|
||||
*/
|
||||
STATIC INLINE void Chip_PININT_DisableIntLow(LPC_PININT_T *pPININT, uint32_t pins)
|
||||
{
|
||||
pPININT->CIENF = pins;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return pin states that have a detected latched high edge (RISE) state
|
||||
* @param pPININT : The base address of Pin interrupt block
|
||||
* @return PININT states (bit n = high) with a latched rise state detected
|
||||
*/
|
||||
STATIC INLINE uint32_t Chip_PININT_GetRiseStates(LPC_PININT_T *pPININT)
|
||||
{
|
||||
return pPININT->RISE & ~PININT_RISE_RESERVED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Clears pin states that had a latched high edge (RISE) state
|
||||
* @param pPININT : The base address of Pin interrupt block
|
||||
* @param pins : Pins with latched states to clear
|
||||
* @return Nothing
|
||||
*/
|
||||
STATIC INLINE void Chip_PININT_ClearRiseStates(LPC_PININT_T *pPININT, uint32_t pins)
|
||||
{
|
||||
pPININT->RISE = pins;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return pin states that have a detected latched falling edge (FALL) state
|
||||
* @param pPININT : The base address of Pin interrupt block
|
||||
* @return PININT states (bit n = high) with a latched rise state detected
|
||||
*/
|
||||
STATIC INLINE uint32_t Chip_PININT_GetFallStates(LPC_PININT_T *pPININT)
|
||||
{
|
||||
return pPININT->FALL & ~PININT_FALL_RESERVED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Clears pin states that had a latched falling edge (FALL) state
|
||||
* @param pPININT : The base address of Pin interrupt block
|
||||
* @param pins : Pins with latched states to clear
|
||||
* @return Nothing
|
||||
*/
|
||||
STATIC INLINE void Chip_PININT_ClearFallStates(LPC_PININT_T *pPININT, uint32_t pins)
|
||||
{
|
||||
pPININT->FALL = pins;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get interrupt status from Pin interrupt block
|
||||
* @param pPININT : The base address of Pin interrupt block
|
||||
* @return Interrupt status (bit n for PININTn = high means interrupt ie pending)
|
||||
*/
|
||||
STATIC INLINE uint32_t Chip_PININT_GetIntStatus(LPC_PININT_T *pPININT)
|
||||
{
|
||||
return pPININT->IST& ~PININT_IST_RESERVED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Clear interrupt status in Pin interrupt block
|
||||
* @param pPININT : The base address of Pin interrupt block
|
||||
* @param pins : Pin interrupts to clear (ORed value of PININTCH*)
|
||||
* @return Nothing
|
||||
*/
|
||||
STATIC INLINE void Chip_PININT_ClearIntStatus(LPC_PININT_T *pPININT, uint32_t pins)
|
||||
{
|
||||
pPININT->IST = pins;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set source for pattern match in Pin interrupt block
|
||||
* @param pPININT : The base address of Pin interrupt block
|
||||
* @param chan : PININT channel number (From 0 to 7)
|
||||
* @param slice : PININT slice number
|
||||
* @return Nothing
|
||||
*/
|
||||
void Chip_PININT_SetPatternMatchSrc(LPC_PININT_T *pPININT, uint8_t chan, Chip_PININT_BITSLICE_T slice);
|
||||
|
||||
/**
|
||||
* @brief Configure the pattern matcch in Pin interrupt block
|
||||
* @param pPININT : The base address of Pin interrupt block
|
||||
* @param slice : PININT slice number
|
||||
* @param slice_cfg : PININT slice configuration value (enum Chip_PININT_BITSLICE_CFG_T)
|
||||
* @param end_point : If true, current slice is final component
|
||||
* @return Nothing
|
||||
*/
|
||||
void Chip_PININT_SetPatternMatchConfig(LPC_PININT_T *pPININT, Chip_PININT_BITSLICE_T slice,
|
||||
Chip_PININT_BITSLICE_CFG_T slice_cfg, bool end_point);
|
||||
|
||||
/**
|
||||
* @brief Enable pattern match interrupts in Pin interrupt block
|
||||
* @param pPININT : The base address of Pin interrupt block
|
||||
* @return Nothing
|
||||
*/
|
||||
STATIC INLINE void Chip_PININT_EnablePatternMatch(LPC_PININT_T *pPININT)
|
||||
{
|
||||
pPININT->PMCTRL = PININT_PMCTRL_PMATCH_SEL | (pPININT->PMCTRL & ~PININT_PMCTRL_RESERVED);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disable pattern match interrupts in Pin interrupt block
|
||||
* @param pPININT : The base address of Pin interrupt block
|
||||
* @return Nothing
|
||||
*/
|
||||
STATIC INLINE void Chip_PININT_DisablePatternMatch(LPC_PININT_T *pPININT)
|
||||
{
|
||||
pPININT->PMCTRL &= ~(PININT_PMCTRL_PMATCH_SEL | PININT_PMCTRL_RESERVED);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable RXEV output in Pin interrupt block
|
||||
* @param pPININT : The base address of Pin interrupt block
|
||||
* @return Nothing
|
||||
*/
|
||||
STATIC INLINE void Chip_PININT_EnablePatternMatchRxEv(LPC_PININT_T *pPININT)
|
||||
{
|
||||
pPININT->PMCTRL = PININT_PMCTRL_RXEV_ENA | (pPININT->PMCTRL & ~PININT_PMCTRL_RESERVED);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disable RXEV output in Pin interrupt block
|
||||
* @param pPININT : The base address of Pin interrupt block
|
||||
* @return Nothing
|
||||
*/
|
||||
STATIC INLINE void Chip_PININT_DisablePatternMatchRxEv(LPC_PININT_T *pPININT)
|
||||
{
|
||||
pPININT->PMCTRL &= ~(PININT_PMCTRL_RXEV_ENA | PININT_PMCTRL_RESERVED);
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __PININT_8XX_H_ */
|
||||
109
bsp/lpc824/Libraries/peri_driver/pmu/pmu_8xx.c
Normal file
109
bsp/lpc824/Libraries/peri_driver/pmu/pmu_8xx.c
Normal file
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* @brief LPC8xx PMU chip driver
|
||||
*
|
||||
* @note
|
||||
* Copyright(C) NXP Semiconductors, 2012
|
||||
* All rights reserved.
|
||||
*
|
||||
* @par
|
||||
* Software that is described herein is for illustrative purposes only
|
||||
* which provides customers with programming information regarding the
|
||||
* LPC products. This software is supplied "AS IS" without any warranties of
|
||||
* any kind, and NXP Semiconductors and its licensor disclaim any and
|
||||
* all warranties, express or implied, including all implied warranties of
|
||||
* merchantability, fitness for a particular purpose and non-infringement of
|
||||
* intellectual property rights. NXP Semiconductors assumes no responsibility
|
||||
* or liability for the use of the software, conveys no license or rights under any
|
||||
* patent, copyright, mask work right, or any other intellectual property rights in
|
||||
* or to any products. NXP Semiconductors reserves the right to make changes
|
||||
* in the software without notification. NXP Semiconductors also makes no
|
||||
* representation or warranty that such application will be suitable for the
|
||||
* specified use without further testing or modification.
|
||||
*
|
||||
* @par
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation is hereby granted, under NXP Semiconductors' and its
|
||||
* licensor's relevant copyrights in the software, without fee, provided that it
|
||||
* is used in conjunction with NXP Semiconductors microcontrollers. This
|
||||
* copyright, permission, and disclaimer notice must appear in all copies of
|
||||
* this code.
|
||||
*/
|
||||
|
||||
#include "chip.h"
|
||||
|
||||
/*****************************************************************************
|
||||
* Private types/enumerations/variables
|
||||
****************************************************************************/
|
||||
|
||||
/* Reserved bits mask for SCR register */
|
||||
#define SCB_SCR_RESERVED (~(SCB_SCR_SLEEPONEXIT_Msk|SCB_SCR_SLEEPDEEP_Msk|SCB_SCR_SEVONPEND_Msk))
|
||||
|
||||
/*****************************************************************************
|
||||
* Public types/enumerations/variables
|
||||
****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* Private functions
|
||||
****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* Public functions
|
||||
****************************************************************************/
|
||||
|
||||
/* Enter MCU Sleep mode */
|
||||
void Chip_PMU_SleepState(LPC_PMU_T *pPMU)
|
||||
{
|
||||
SCB->SCR = ~(1UL << SCB_SCR_SLEEPDEEP_Pos) & (SCB->SCR & ~SCB_SCR_RESERVED);
|
||||
pPMU->PCON = PMU_PCON_PM_SLEEP;
|
||||
|
||||
/* Enter sleep mode */
|
||||
__WFI();
|
||||
}
|
||||
|
||||
/* Enter MCU Deep Sleep mode */
|
||||
void Chip_PMU_DeepSleepState(LPC_PMU_T *pPMU)
|
||||
{
|
||||
SCB->SCR = (1UL << SCB_SCR_SLEEPDEEP_Pos) | (SCB->SCR & ~SCB_SCR_RESERVED);
|
||||
pPMU->PCON = PMU_PCON_PM_DEEPSLEEP;
|
||||
|
||||
/* Enter sleep mode */
|
||||
__WFI();
|
||||
}
|
||||
|
||||
/* Enter MCU Power down mode */
|
||||
void Chip_PMU_PowerDownState(LPC_PMU_T *pPMU)
|
||||
{
|
||||
SCB->SCR = (1UL << SCB_SCR_SLEEPDEEP_Pos) | (SCB->SCR & ~SCB_SCR_RESERVED);
|
||||
pPMU->PCON = PMU_PCON_PM_POWERDOWN;
|
||||
|
||||
/* Enter sleep mode */
|
||||
__WFI();
|
||||
}
|
||||
|
||||
/* Enter MCU Deep Power down mode */
|
||||
void Chip_PMU_DeepPowerDownState(LPC_PMU_T *pPMU)
|
||||
{
|
||||
SCB->SCR = (1UL << SCB_SCR_SLEEPDEEP_Pos) | (SCB->SCR & ~SCB_SCR_RESERVED);
|
||||
pPMU->PCON = PMU_PCON_PM_DEEPPOWERDOWN;
|
||||
|
||||
/* Enter sleep mode */
|
||||
__WFI();
|
||||
}
|
||||
|
||||
/* Put some of the peripheral in sleep mode */
|
||||
void Chip_PMU_Sleep(LPC_PMU_T *pPMU, CHIP_PMU_MCUPOWER_T SleepMode)
|
||||
{
|
||||
if (SleepMode == PMU_MCU_DEEP_SLEEP) {
|
||||
Chip_PMU_DeepSleepState(pPMU);
|
||||
}
|
||||
else if (SleepMode == PMU_MCU_POWER_DOWN) {
|
||||
Chip_PMU_PowerDownState(pPMU);
|
||||
}
|
||||
else if (SleepMode == PMU_MCU_DEEP_PWRDOWN) {
|
||||
Chip_PMU_DeepPowerDownState(pPMU);
|
||||
}
|
||||
else {
|
||||
/* PMU_MCU_SLEEP */
|
||||
Chip_PMU_SleepState(pPMU);
|
||||
}
|
||||
}
|
||||
237
bsp/lpc824/Libraries/peri_driver/pmu/pmu_8xx.h
Normal file
237
bsp/lpc824/Libraries/peri_driver/pmu/pmu_8xx.h
Normal file
@@ -0,0 +1,237 @@
|
||||
/*
|
||||
* @brief LPC8xx PMU chip driver
|
||||
*
|
||||
* @note
|
||||
* Copyright(C) NXP Semiconductors, 2012
|
||||
* All rights reserved.
|
||||
*
|
||||
* @par
|
||||
* Software that is described herein is for illustrative purposes only
|
||||
* which provides customers with programming information regarding the
|
||||
* LPC products. This software is supplied "AS IS" without any warranties of
|
||||
* any kind, and NXP Semiconductors and its licensor disclaim any and
|
||||
* all warranties, express or implied, including all implied warranties of
|
||||
* merchantability, fitness for a particular purpose and non-infringement of
|
||||
* intellectual property rights. NXP Semiconductors assumes no responsibility
|
||||
* or liability for the use of the software, conveys no license or rights under any
|
||||
* patent, copyright, mask work right, or any other intellectual property rights in
|
||||
* or to any products. NXP Semiconductors reserves the right to make changes
|
||||
* in the software without notification. NXP Semiconductors also makes no
|
||||
* representation or warranty that such application will be suitable for the
|
||||
* specified use without further testing or modification.
|
||||
*
|
||||
* @par
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation is hereby granted, under NXP Semiconductors' and its
|
||||
* licensor's relevant copyrights in the software, without fee, provided that it
|
||||
* is used in conjunction with NXP Semiconductors microcontrollers. This
|
||||
* copyright, permission, and disclaimer notice must appear in all copies of
|
||||
* this code.
|
||||
*/
|
||||
|
||||
#ifndef __PMU_8XX_H_
|
||||
#define __PMU_8XX_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @defgroup PMU_8XX CHIP: LPC8xx PMU driver
|
||||
* @ingroup CHIP_8XX_Drivers
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief LPC8xx Power Management Unit register block structure
|
||||
*/
|
||||
typedef struct {
|
||||
__IO uint32_t PCON; /*!< Offset: 0x000 Power control Register (R/W) */
|
||||
__IO uint32_t GPREG[4]; /*!< Offset: 0x004 General purpose Registers 0..3 (R/W) */
|
||||
__IO uint32_t DPDCTRL; /*!< Offset: 0x014 Deep power-down control register (R/W) */
|
||||
} LPC_PMU_T;
|
||||
|
||||
/* Reserved bits masks for registers */
|
||||
#define PMU_PCON_RESERVED ((0xf<<4)|(0x6<<8)|0xfffff000)
|
||||
#define PMU_DPDCTRL_RESERVED (~0xf)
|
||||
|
||||
/**
|
||||
* @brief LPC8xx low power mode type definitions
|
||||
*/
|
||||
typedef enum CHIP_PMU_MCUPOWER {
|
||||
PMU_MCU_SLEEP = 0, /*!< Sleep mode */
|
||||
PMU_MCU_DEEP_SLEEP, /*!< Deep Sleep mode */
|
||||
PMU_MCU_POWER_DOWN, /*!< Power down mode */
|
||||
PMU_MCU_DEEP_PWRDOWN /*!< Deep power down mode */
|
||||
} CHIP_PMU_MCUPOWER_T;
|
||||
|
||||
/**
|
||||
* PMU PCON register bit fields & masks
|
||||
*/
|
||||
#define PMU_PCON_PM_SLEEP (0x0) /*!< ARM WFI enter sleep mode */
|
||||
#define PMU_PCON_PM_DEEPSLEEP (0x1) /*!< ARM WFI enter Deep-sleep mode */
|
||||
#define PMU_PCON_PM_POWERDOWN (0x2) /*!< ARM WFI enter Power-down mode */
|
||||
#define PMU_PCON_PM_DEEPPOWERDOWN (0x3) /*!< ARM WFI enter Deep Power-down mode */
|
||||
#define PMU_PCON_NODPD (1 << 3) /*!< Disable deep power-down mode */
|
||||
#define PMU_PCON_SLEEPFLAG (1 << 8) /*!< Sleep mode flag */
|
||||
#define PMU_PCON_DPDFLAG (1 << 11) /*!< Deep power-down flag */
|
||||
|
||||
/**
|
||||
* PMU DPDCTRL register bit fields & masks
|
||||
*/
|
||||
#define PMU_DPDCTRL_WAKEUPPHYS (1 << 0) /** Enable wake-up pin hysteresis */
|
||||
#define PMU_DPDCTRL_WAKEPAD (1 << 1) /** Disable the Wake-up */
|
||||
#define PMU_DPDCTRL_LPOSCEN (1 << 2) /** Enable the low-power oscillator (10 khz self wk) */
|
||||
#define PMU_DPDCTRL_LPOSCDPDEN (1 << 3) /** Enable the low-power oscillator in deep power-down*/
|
||||
|
||||
/**
|
||||
* @brief Write a value to a GPREG register
|
||||
* @param pPMU : Pointer to PMU register block
|
||||
* @param regIndex : Register index to write to, must be 0..3
|
||||
* @param value : Value to write
|
||||
* @return None
|
||||
*/
|
||||
STATIC INLINE void Chip_PMU_WriteGPREG(LPC_PMU_T *pPMU, uint8_t regIndex, uint32_t value)
|
||||
{
|
||||
pPMU->GPREG[regIndex] = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Read a value to a GPREG register
|
||||
* @param pPMU : Pointer to PMU register block
|
||||
* @param regIndex : Register index to read from, must be 0..3
|
||||
* @return Value read from the GPREG register
|
||||
*/
|
||||
STATIC INLINE uint32_t Chip_PMU_ReadGPREG(LPC_PMU_T *pPMU, uint8_t regIndex)
|
||||
{
|
||||
return pPMU->GPREG[regIndex];
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enter MCU Sleep mode
|
||||
* @param pPMU : Pointer to PMU register block
|
||||
* @return None
|
||||
* @note The sleep mode affects the ARM Cortex-M0+ core only. Peripherals
|
||||
* and memories are active.
|
||||
*/
|
||||
void Chip_PMU_SleepState(LPC_PMU_T *pPMU);
|
||||
|
||||
/**
|
||||
* @brief Enter MCU Deep Sleep mode
|
||||
* @param pPMU : Pointer to PMU register block
|
||||
* @return None
|
||||
* @note In Deep-sleep mode, the peripherals receive no internal clocks.
|
||||
* The flash is in stand-by mode. The SRAM memory and all peripheral registers
|
||||
* as well as the processor maintain their internal states. The WWDT, WKT,
|
||||
* and BOD can remain active to wake up the system on an interrupt.
|
||||
*/
|
||||
void Chip_PMU_DeepSleepState(LPC_PMU_T *pPMU);
|
||||
|
||||
/**
|
||||
* @brief Enter MCU Power down mode
|
||||
* @param pPMU : Pointer to PMU register block
|
||||
* @return None
|
||||
* @note In Power-down mode, the peripherals receive no internal clocks.
|
||||
* The internal SRAM memory and all peripheral registers as well as the
|
||||
* processor maintain their internal states. The flash memory is powered
|
||||
* down. The WWDT, WKT, and BOD can remain active to wake up the system
|
||||
* on an interrupt.
|
||||
*/
|
||||
void Chip_PMU_PowerDownState(LPC_PMU_T *pPMU);
|
||||
|
||||
/**
|
||||
* @brief Enter MCU Deep Power down mode
|
||||
* @param pPMU : Pointer to PMU register block
|
||||
* @return None
|
||||
* @note For maximal power savings, the entire system is shut down
|
||||
* except for the general purpose registers in the PMU and the self
|
||||
* wake-up timer. Only the general purpose registers in the PMU maintain
|
||||
* their internal states. The part can wake up on a pulse on the WAKEUP
|
||||
* pin or when the self wake-up timer times out. On wake-up, the part
|
||||
* reboots.
|
||||
*/
|
||||
void Chip_PMU_DeepPowerDownState(LPC_PMU_T *pPMU);
|
||||
|
||||
/**
|
||||
* @brief Place the MCU in a low power state
|
||||
* @param pPMU : Pointer to PMU register block
|
||||
* @param SleepMode : Sleep mode
|
||||
* @return None
|
||||
*/
|
||||
void Chip_PMU_Sleep(LPC_PMU_T *pPMU, CHIP_PMU_MCUPOWER_T SleepMode);
|
||||
|
||||
/**
|
||||
* @brief Disables deep power-down mode
|
||||
* @param pPMU : Pointer to PMU register block
|
||||
* @return None
|
||||
* @note Calling this functions prevents entry to Deep power-down
|
||||
* mode. Once set, this can only be cleared by power-on reset.
|
||||
*/
|
||||
STATIC INLINE void Chip_PMU_DisableDeepPowerDown(LPC_PMU_T *pPMU)
|
||||
{
|
||||
pPMU->PCON = PMU_PCON_NODPD | (pPMU->PCON & ~PMU_PCON_RESERVED);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns sleep/power-down flags
|
||||
* @param pPMU : Pointer to PMU register block
|
||||
* @return Or'ed values of PMU_PCON_SLEEPFLAG and PMU_PCON_DPDFLAG
|
||||
* @note These indicate that the PMU is setup for entry into a low
|
||||
* power state on the next WFI() instruction.
|
||||
*/
|
||||
STATIC INLINE uint32_t Chip_PMU_GetSleepFlags(LPC_PMU_T *pPMU)
|
||||
{
|
||||
return (pPMU->PCON & (PMU_PCON_SLEEPFLAG | PMU_PCON_DPDFLAG));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Clears sleep/power-down flags
|
||||
* @param pPMU : Pointer to PMU register block
|
||||
* @param flags : Or'ed value of PMU_PCON_SLEEPFLAG and PMU_PCON_DPDFLAG
|
||||
* @return Nothing
|
||||
* @note Use this function to clear a low power state prior to calling
|
||||
* WFI().
|
||||
*/
|
||||
STATIC INLINE void Chip_PMU_ClearSleepFlags(LPC_PMU_T *pPMU, uint32_t flags)
|
||||
{
|
||||
pPMU->PCON |= (flags & (~PMU_PCON_RESERVED));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets deep power-down functions
|
||||
* @param pPMU : Pointer to PMU register block
|
||||
* @param flags : Or'ed value of PMU_DPDCTRL_* values
|
||||
* @return Nothing
|
||||
* @note Some of these functions may need to be set prior to going
|
||||
* into a low power mode. Note that some calls to this function enable
|
||||
* functions while others disable it based on the PMU_DPDCTRL_*
|
||||
* definitions.
|
||||
*/
|
||||
STATIC INLINE void Chip_PMU_SetPowerDownControl(LPC_PMU_T *pPMU, uint32_t flags)
|
||||
{
|
||||
pPMU->DPDCTRL = flags | (pPMU->DPDCTRL & ~PMU_DPDCTRL_RESERVED);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Cleats deep power-down functions
|
||||
* @param pPMU : Pointer to PMU register block
|
||||
* @param flags : Or'ed value of PMU_DPDCTRL_* values
|
||||
* @return Nothing
|
||||
* @note Some of these functions may need to be cleared prior to going
|
||||
* into a low power mode. Note that some calls to this function enable
|
||||
* functions while others disable it based on the PMU_DPDCTRL_*
|
||||
* definitions.
|
||||
*/
|
||||
STATIC INLINE void Chip_PMU_ClearPowerDownControl(LPC_PMU_T *pPMU, uint32_t flags)
|
||||
{
|
||||
pPMU->DPDCTRL &= ~(flags | PMU_DPDCTRL_RESERVED);
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __PMU_8XX_H_ */
|
||||
125
bsp/lpc824/Libraries/peri_driver/rom/rom_i2c_8xx.h
Normal file
125
bsp/lpc824/Libraries/peri_driver/rom/rom_i2c_8xx.h
Normal file
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* @brief LPC8xx I2C ROM API declarations and functions
|
||||
*
|
||||
* @note
|
||||
* Copyright(C) NXP Semiconductors, 2012
|
||||
* All rights reserved.
|
||||
*
|
||||
* @par
|
||||
* Software that is described herein is for illustrative purposes only
|
||||
* which provides customers with programming information regarding the
|
||||
* LPC products. This software is supplied "AS IS" without any warranties of
|
||||
* any kind, and NXP Semiconductors and its licensor disclaim any and
|
||||
* all warranties, express or implied, including all implied warranties of
|
||||
* merchantability, fitness for a particular purpose and non-infringement of
|
||||
* intellectual property rights. NXP Semiconductors assumes no responsibility
|
||||
* or liability for the use of the software, conveys no license or rights under any
|
||||
* patent, copyright, mask work right, or any other intellectual property rights in
|
||||
* or to any products. NXP Semiconductors reserves the right to make changes
|
||||
* in the software without notification. NXP Semiconductors also makes no
|
||||
* representation or warranty that such application will be suitable for the
|
||||
* specified use without further testing or modification.
|
||||
*
|
||||
* @par
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation is hereby granted, under NXP Semiconductors' and its
|
||||
* licensor's relevant copyrights in the software, without fee, provided that it
|
||||
* is used in conjunction with NXP Semiconductors microcontrollers. This
|
||||
* copyright, permission, and disclaimer notice must appear in all copies of
|
||||
* this code.
|
||||
*/
|
||||
|
||||
#ifndef __ROM_I2C_8XX_H_
|
||||
#define __ROM_I2C_8XX_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @defgroup CHIP_I2CROM_8XX CHIP: LPC8xx I2C ROM API declarations and functions
|
||||
* @ingroup CHIP_8XX_Drivers
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief LPC8xx I2C ROM driver handle structure
|
||||
*/
|
||||
typedef void *I2C_HANDLE_T;
|
||||
|
||||
/**
|
||||
* @brief LPC8xx I2C ROM driver callback function
|
||||
*/
|
||||
typedef void (*I2C_CALLBK_T)(uint32_t err_code, uint32_t n);
|
||||
|
||||
/**
|
||||
* LPC8xx I2C ROM driver parameter structure
|
||||
*/
|
||||
typedef struct I2C_PARAM {
|
||||
uint32_t num_bytes_send; /*!< No. of bytes to send */
|
||||
uint32_t num_bytes_rec; /*!< No. of bytes to receive */
|
||||
uint8_t *buffer_ptr_send; /*!< Pointer to send buffer */
|
||||
uint8_t *buffer_ptr_rec; /*!< Pointer to receive buffer */
|
||||
I2C_CALLBK_T func_pt; /*!< Callback function */
|
||||
uint8_t stop_flag; /*!< Stop flag */
|
||||
uint8_t dummy[3];
|
||||
} I2C_PARAM_T;
|
||||
|
||||
/**
|
||||
* LPC8xx I2C ROM driver result structure
|
||||
*/
|
||||
typedef struct I2C_RESULT {
|
||||
uint32_t n_bytes_sent; /*!< No. of bytes sent */
|
||||
uint32_t n_bytes_recd; /*!< No. of bytes received */
|
||||
} I2C_RESULT_T;
|
||||
|
||||
/**
|
||||
* LPC8xx I2C ROM driver modes enum
|
||||
*/
|
||||
typedef enum CHIP_I2C_MODE {
|
||||
IDLE, /*!< IDLE state */
|
||||
MASTER_SEND, /*!< Master send state */
|
||||
MASTER_RECEIVE, /*!< Master Receive state */
|
||||
SLAVE_SEND, /*!< Slave send state */
|
||||
SLAVE_RECEIVE /*!< Slave receive state */
|
||||
} CHIP_I2C_MODE_T;
|
||||
|
||||
/**
|
||||
* LPC8xx I2C ROM driver APIs structure
|
||||
*/
|
||||
typedef struct I2CD_API {
|
||||
/*!< Interrupt Support Routine */
|
||||
void (*i2c_isr_handler)(I2C_HANDLE_T *handle);
|
||||
|
||||
/*!< MASTER functions */
|
||||
ErrorCode_t (*i2c_master_transmit_poll)(I2C_HANDLE_T *handle, I2C_PARAM_T *param, I2C_RESULT_T *result);
|
||||
ErrorCode_t (*i2c_master_receive_poll)(I2C_HANDLE_T *handle, I2C_PARAM_T *param, I2C_RESULT_T *result);
|
||||
ErrorCode_t (*i2c_master_tx_rx_poll)(I2C_HANDLE_T *handle, I2C_PARAM_T *param, I2C_RESULT_T *result);
|
||||
ErrorCode_t (*i2c_master_transmit_intr)(I2C_HANDLE_T *handle, I2C_PARAM_T *param, I2C_RESULT_T *result);
|
||||
ErrorCode_t (*i2c_master_receive_intr)(I2C_HANDLE_T *handle, I2C_PARAM_T *param, I2C_RESULT_T *result);
|
||||
ErrorCode_t (*i2c_master_tx_rx_intr)(I2C_HANDLE_T *handle, I2C_PARAM_T *param, I2C_RESULT_T *result);
|
||||
|
||||
/*!< SLAVE functions */
|
||||
ErrorCode_t (*i2c_slave_receive_poll)(I2C_HANDLE_T *handle, I2C_PARAM_T *param, I2C_RESULT_T *result);
|
||||
ErrorCode_t (*i2c_slave_transmit_poll)(I2C_HANDLE_T *handle, I2C_PARAM_T *param, I2C_RESULT_T *result);
|
||||
ErrorCode_t (*i2c_slave_receive_intr)(I2C_HANDLE_T *handle, I2C_PARAM_T *param, I2C_RESULT_T *result);
|
||||
ErrorCode_t (*i2c_slave_transmit_intr)(I2C_HANDLE_T *handle, I2C_PARAM_T *param, I2C_RESULT_T *result);
|
||||
ErrorCode_t (*i2c_set_slave_addr)(I2C_HANDLE_T *handle, uint32_t slave_addr_0_3, uint32_t slave_mask_0_3);
|
||||
|
||||
/*!< OTHER support functions */
|
||||
uint32_t (*i2c_get_mem_size)(void);
|
||||
I2C_HANDLE_T * (*i2c_setup)( uint32_t i2c_base_addr, uint32_t * start_of_ram);
|
||||
ErrorCode_t (*i2c_set_bitrate)(I2C_HANDLE_T *handle, uint32_t p_clk_in_hz, uint32_t bitrate_in_bps);
|
||||
uint32_t (*i2c_get_firmware_version)(void);
|
||||
CHIP_I2C_MODE_T (*i2c_get_status)(I2C_HANDLE_T *handle);
|
||||
ErrorCode_t (*i2c_set_timeout)(I2C_HANDLE_T *handle, uint32_t timeout);
|
||||
} I2CD_API_T;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __ROM_I2C_8XX_H_ */
|
||||
92
bsp/lpc824/Libraries/peri_driver/rom/rom_pwr_8xx.h
Normal file
92
bsp/lpc824/Libraries/peri_driver/rom/rom_pwr_8xx.h
Normal file
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* @brief LPC8xx Power ROM API declarations and functions
|
||||
*
|
||||
* @note
|
||||
* Copyright(C) NXP Semiconductors, 2012
|
||||
* All rights reserved.
|
||||
*
|
||||
* @par
|
||||
* Software that is described herein is for illustrative purposes only
|
||||
* which provides customers with programming information regarding the
|
||||
* LPC products. This software is supplied "AS IS" without any warranties of
|
||||
* any kind, and NXP Semiconductors and its licensor disclaim any and
|
||||
* all warranties, express or implied, including all implied warranties of
|
||||
* merchantability, fitness for a particular purpose and non-infringement of
|
||||
* intellectual property rights. NXP Semiconductors assumes no responsibility
|
||||
* or liability for the use of the software, conveys no license or rights under any
|
||||
* patent, copyright, mask work right, or any other intellectual property rights in
|
||||
* or to any products. NXP Semiconductors reserves the right to make changes
|
||||
* in the software without notification. NXP Semiconductors also makes no
|
||||
* representation or warranty that such application will be suitable for the
|
||||
* specified use without further testing or modification.
|
||||
*
|
||||
* @par
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation is hereby granted, under NXP Semiconductors' and its
|
||||
* licensor's relevant copyrights in the software, without fee, provided that it
|
||||
* is used in conjunction with NXP Semiconductors microcontrollers. This
|
||||
* copyright, permission, and disclaimer notice must appear in all copies of
|
||||
* this code.
|
||||
*/
|
||||
|
||||
#ifndef __ROM_PWR_8XX_H_
|
||||
#define __ROM_PWR_8XX_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @defgroup PWRD_8XX CHIP: LPC8xx Power ROM API declarations and functions
|
||||
* @ingroup CHIP_8XX_Drivers
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief LPC8xx Power ROM APIs - set_pll mode options
|
||||
*/
|
||||
#define CPU_FREQ_EQU 0
|
||||
#define CPU_FREQ_LTE 1
|
||||
#define CPU_FREQ_GTE 2
|
||||
#define CPU_FREQ_APPROX 3
|
||||
|
||||
/**
|
||||
* @brief LPC8xx Power ROM APIs - set_pll response0 options
|
||||
*/
|
||||
#define PLL_CMD_SUCCESS 0
|
||||
#define PLL_INVALID_FREQ 1
|
||||
#define PLL_INVALID_MODE 2
|
||||
#define PLL_FREQ_NOT_FOUND 3
|
||||
#define PLL_NOT_LOCKED 4
|
||||
|
||||
/**
|
||||
* @brief LPC8xx Power ROM APIs - set_power mode options
|
||||
*/
|
||||
#define PWR_DEFAULT 0
|
||||
#define PWR_CPU_PERFORMANCE 1
|
||||
#define PWR_EFFICIENCY 2
|
||||
#define PWR_LOW_CURRENT 3
|
||||
|
||||
/**
|
||||
* @brief LPC8xx Power ROM APIs - set_power response0 options
|
||||
*/
|
||||
#define PWR_CMD_SUCCESS 0
|
||||
#define PWR_INVALID_FREQ 1
|
||||
#define PWR_INVALID_MODE 2
|
||||
|
||||
/**
|
||||
* @brief LPC8XX Power ROM API structure
|
||||
*/
|
||||
typedef struct PWRD_API {
|
||||
void (*set_pll)(uint32_t cmd[], uint32_t resp[]); /*!< Set PLL function */
|
||||
void (*set_power)(uint32_t cmd[], uint32_t resp[]); /*!< Set power function */
|
||||
} PWRD_API_T;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __ROM_PWR_8XX_H_ */
|
||||
180
bsp/lpc824/Libraries/peri_driver/rom/rom_uart_8xx.h
Normal file
180
bsp/lpc824/Libraries/peri_driver/rom/rom_uart_8xx.h
Normal file
@@ -0,0 +1,180 @@
|
||||
/*
|
||||
* @brief LPC8xx UART ROM API declarations and functions
|
||||
*
|
||||
* @note
|
||||
* Copyright(C) NXP Semiconductors, 2012
|
||||
* All rights reserved.
|
||||
*
|
||||
* @par
|
||||
* Software that is described herein is for illustrative purposes only
|
||||
* which provides customers with programming information regarding the
|
||||
* LPC products. This software is supplied "AS IS" without any warranties of
|
||||
* any kind, and NXP Semiconductors and its licensor disclaim any and
|
||||
* all warranties, express or implied, including all implied warranties of
|
||||
* merchantability, fitness for a particular purpose and non-infringement of
|
||||
* intellectual property rights. NXP Semiconductors assumes no responsibility
|
||||
* or liability for the use of the software, conveys no license or rights under any
|
||||
* patent, copyright, mask work right, or any other intellectual property rights in
|
||||
* or to any products. NXP Semiconductors reserves the right to make changes
|
||||
* in the software without notification. NXP Semiconductors also makes no
|
||||
* representation or warranty that such application will be suitable for the
|
||||
* specified use without further testing or modification.
|
||||
*
|
||||
* @par
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation is hereby granted, under NXP Semiconductors' and its
|
||||
* licensor's relevant copyrights in the software, without fee, provided that it
|
||||
* is used in conjunction with NXP Semiconductors microcontrollers. This
|
||||
* copyright, permission, and disclaimer notice must appear in all copies of
|
||||
* this code.
|
||||
*/
|
||||
|
||||
#ifndef __ROM_UART_8XX_H_
|
||||
#define __ROM_UART_8XX_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @defgroup UARTROM_8XX CHIP: LPC8xx UART ROM API declarations and functions
|
||||
* @ingroup CHIP_8XX_Drivers
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief UART ROM driver - UART errors in UART configuration used in uart_init function
|
||||
*/
|
||||
#define OVERRUN_ERR_EN (1 << 0) /*!< Bit 0: Enable overrun error */
|
||||
#define UNDERRUN_ERR_EN (1 << 1) /*!< Bit 1: Enable underrun error */
|
||||
#define FRAME_ERR_EN (1 << 2) /*!< Bit 2: enable frame error */
|
||||
#define PARITY_ERR_EN (1 << 3) /*!< Bit 3: enable parity error */
|
||||
#define RXNOISE_ERR_EN (1 << 4) /*!< Bit 4: enable receive noise error */
|
||||
|
||||
/**
|
||||
* Macros for UART errors
|
||||
*/
|
||||
/*!< Enable all the UART errors */
|
||||
#define ALL_ERR_EN (OVERRUN_ERR_EN | UNDERRUN_ERR_EN | FRAME_ERR_EN | PARITY_ERR_EN | \
|
||||
RXNOISE_ERR_EN)
|
||||
/*!< Disable all the errors */
|
||||
#define NO_ERR_EN (0)
|
||||
|
||||
/**
|
||||
* Transfer mode values in UART parameter structure.
|
||||
* Used in uart_get_line & uart_put_line function
|
||||
*/
|
||||
/*!< 0x00: uart_get_line: stop transfer when the buffer is full */
|
||||
/*!< 0x00: uart_put_line: stop transfer when the buffer is empty */
|
||||
#define TX_MODE_BUF_EMPTY (0x00)
|
||||
#define RX_MODE_BUF_FULL (0x00)
|
||||
/*!< 0x01: uart_get_line: stop transfer when CRLF are received */
|
||||
/*!< 0x01: uart_put_line: transfer stopped after reaching \0 and CRLF is sent out after that */
|
||||
#define TX_MODE_SZERO_SEND_CRLF (0x01)
|
||||
#define RX_MODE_CRLF_RECVD (0x01)
|
||||
/*!< 0x02: uart_get_line: stop transfer when LF are received */
|
||||
/*!< 0x02: uart_put_line: transfer stopped after reaching \0. And LF is sent out after that */
|
||||
#define TX_MODE_SZERO_SEND_LF (0x02)
|
||||
#define RX_MODE_LF_RECVD (0x02)
|
||||
/*!< 0x03: uart_get_line: RESERVED */
|
||||
/*!< 0x03: uart_put_line: transfer stopped after reaching \0 */
|
||||
#define TX_MODE_SZERO (0x03)
|
||||
|
||||
/**
|
||||
* @brief UART ROM driver modes
|
||||
*/
|
||||
#define DRIVER_MODE_POLLING (0x00) /*!< Polling mode */
|
||||
#define DRIVER_MODE_INTERRUPT (0x01) /*!< Interrupt mode */
|
||||
#define DRIVER_MODE_DMA (0x02) /*!< DMA mode */
|
||||
|
||||
/**
|
||||
* @brief UART ROM driver UART handle
|
||||
*/
|
||||
typedef void UART_HANDLE_T;
|
||||
|
||||
/**
|
||||
* @brief UART ROM driver UART callback function
|
||||
*/
|
||||
typedef void (*UART_CALLBK_T)(uint32_t err_code, uint32_t n);
|
||||
|
||||
/**
|
||||
* @brief UART ROM driver UART DMA callback function
|
||||
*/
|
||||
typedef void (*UART_DMA_REQ_T)(uint32_t src_adr, uint32_t dst_adr, uint32_t size);
|
||||
|
||||
/**
|
||||
* @brief UART ROM driver configutaion structure
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t sys_clk_in_hz; /*!< main clock in Hz */
|
||||
uint32_t baudrate_in_hz; /*!< Baud rate in Hz */
|
||||
uint8_t config; /*!< Configuration value */
|
||||
/*!< bit1:0 Data Length: 00: 7 bits length, 01: 8 bits length, others: reserved */
|
||||
/*!< bit3:2 Parity: 00: No Parity, 01: reserved, 10: Even, 11: Odd */
|
||||
/*!< bit4: Stop Bit(s): 0: 1 Stop bit, 1: 2 Stop bits */
|
||||
uint8_t sync_mod; /*!< Sync mode settings */
|
||||
/*!< bit0: Mode: 0: Asynchronous mode, 1: Synchronous mode */
|
||||
/*!< bit1: 0: Un_RXD is sampled on the falling edge of SCLK */
|
||||
/*!< 1: Un_RXD is sampled on the rising edge of SCLK */
|
||||
/*!< bit2: 0: Start and stop bits are transmitted as in asynchronous mode) */
|
||||
/*!< 1: Start and stop bits are not transmitted) */
|
||||
/*!< bit3: 0: The UART is a slave in Synchronous mode */
|
||||
/*!< 1: The UART is a master in Synchronous mode */
|
||||
uint16_t error_en; /*!< Errors to be enabled */
|
||||
/*!< bit0: Overrun Errors Enabled */
|
||||
/*!< bit1: Underrun Errors Enabled */
|
||||
/*!< bit2: FrameErr Errors Enabled */
|
||||
/*!< bit3: ParityErr Errors Enabled */
|
||||
/*!< bit4: RxNoise Errors Enabled */
|
||||
} UART_CONFIG_T;
|
||||
|
||||
/**
|
||||
* @brief UART ROM driver parameter structure
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t *buffer; /*!< Pointer to data buffer */
|
||||
uint32_t size; /*!< Size of the buffer */
|
||||
uint16_t transfer_mode; /*!< Transfer mode settings */
|
||||
/*!< 0x00: uart_get_line: stop transfer when the buffer is full */
|
||||
/*!< 0x00: uart_put_line: stop transfer when the buffer is empty */
|
||||
/*!< 0x01: uart_get_line: stop transfer when CRLF are received */
|
||||
/*!< 0x01: uart_put_line: transfer stopped after reaching \0 and CRLF is sent out after that */
|
||||
/*!< 0x02: uart_get_line: stop transfer when LF are received */
|
||||
/*!< 0x02: uart_put_line: transfer stopped after reaching \0 and LF is sent out after that */
|
||||
/*!< 0x03: uart_get_line: RESERVED */
|
||||
/*!< 0x03: uart_put_line: transfer stopped after reaching \0 */
|
||||
uint16_t driver_mode; /*!< Driver mode */
|
||||
/*!< 0x00: Polling mode, function blocked until transfer completes */
|
||||
/*!< 0x01: Interrupt mode, function immediately returns, callback invoked when transfer completes */
|
||||
/*!< 0x02: DMA mode, in case DMA block is available, DMA req function is called for UART DMA channel setup, then callback function indicate that transfer completes */
|
||||
UART_CALLBK_T callback_func_pt; /*!< callback function pointer */
|
||||
UART_DMA_REQ_T dma_req_func_pt; /*!< UART DMA channel setup function pointer, not applicable on LPC8xx */
|
||||
} UART_PARAM_T;
|
||||
|
||||
/**
|
||||
* @brief UART ROM driver APIs structure
|
||||
*/
|
||||
typedef struct UARTD_API {
|
||||
/*!< UART Configuration functions */
|
||||
uint32_t (*uart_get_mem_size)(void); /*!< Get the memory size needed by one Min UART instance */
|
||||
UART_HANDLE_T * (*uart_setup)(uint32_t base_addr, uint8_t * ram); /*!< Setup Min UART instance with provided memory and return the handle to this instance */
|
||||
uint32_t (*uart_init)(UART_HANDLE_T *handle, UART_CONFIG_T *set); /*!< Setup baud rate and operation mode for uart, then enable uart */
|
||||
|
||||
/*!< UART polling functions block until completed */
|
||||
uint8_t (*uart_get_char)(UART_HANDLE_T *handle); /*!< Receive one Char from uart. This functions is only returned after Char is received. In case Echo is enabled, the received data is sent out immediately */
|
||||
void (*uart_put_char)(UART_HANDLE_T *handle, uint8_t data); /*!< Send one Char through uart. This function is only returned after data is sent */
|
||||
uint32_t (*uart_get_line)(UART_HANDLE_T *handle, UART_PARAM_T *param); /*!< Receive multiple bytes from UART */
|
||||
uint32_t (*uart_put_line)(UART_HANDLE_T *handle, UART_PARAM_T *param); /*!< Send string (end with \0) or raw data through UART */
|
||||
|
||||
/*!< UART interrupt functions return immediately and callback when completed */
|
||||
void (*uart_isr)(UART_HANDLE_T *handle); /*!< UART interrupt service routine. To use this routine, the corresponding USART interrupt must be enabled. This function is invoked by the user ISR */
|
||||
} UARTD_API_T;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __ROM_UART_8XX_H_ */
|
||||
96
bsp/lpc824/Libraries/peri_driver/rom/romapi_8xx.h
Normal file
96
bsp/lpc824/Libraries/peri_driver/rom/romapi_8xx.h
Normal file
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* @brief LPC8xx ROM API declarations and functions
|
||||
*
|
||||
* @note
|
||||
* Copyright(C) NXP Semiconductors, 2012
|
||||
* All rights reserved.
|
||||
*
|
||||
* @par
|
||||
* Software that is described herein is for illustrative purposes only
|
||||
* which provides customers with programming information regarding the
|
||||
* LPC products. This software is supplied "AS IS" without any warranties of
|
||||
* any kind, and NXP Semiconductors and its licensor disclaim any and
|
||||
* all warranties, express or implied, including all implied warranties of
|
||||
* merchantability, fitness for a particular purpose and non-infringement of
|
||||
* intellectual property rights. NXP Semiconductors assumes no responsibility
|
||||
* or liability for the use of the software, conveys no license or rights under any
|
||||
* patent, copyright, mask work right, or any other intellectual property rights in
|
||||
* or to any products. NXP Semiconductors reserves the right to make changes
|
||||
* in the software without notification. NXP Semiconductors also makes no
|
||||
* representation or warranty that such application will be suitable for the
|
||||
* specified use without further testing or modification.
|
||||
*
|
||||
* @par
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation is hereby granted, under NXP Semiconductors' and its
|
||||
* licensor's relevant copyrights in the software, without fee, provided that it
|
||||
* is used in conjunction with NXP Semiconductors microcontrollers. This
|
||||
* copyright, permission, and disclaimer notice must appear in all copies of
|
||||
* this code.
|
||||
*/
|
||||
|
||||
#ifndef __ROMAPI_8XX_H_
|
||||
#define __ROMAPI_8XX_H_
|
||||
|
||||
#include "../iap/iap.h"
|
||||
#include "../../common/chip/error_8xx.h"
|
||||
#include "rom_i2c_8xx.h"
|
||||
#include "rom_pwr_8xx.h"
|
||||
#include "rom_uart_8xx.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @defgroup ROMAPI_8XX CHIP: LPC8xx ROM API declarations and functions
|
||||
* @ingroup CHIP_8XX_Drivers
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief LPC8XX High level ROM API structure
|
||||
*/
|
||||
typedef struct ROM_API {
|
||||
const uint32_t unused[3];
|
||||
const PWRD_API_T *pPWRD; /*!< Power profiles API function table */
|
||||
const uint32_t p_dev1;
|
||||
const I2CD_API_T *pI2CD; /*!< I2C driver routines functions table */
|
||||
const uint32_t p_dev3;
|
||||
const uint32_t p_dev4;
|
||||
const uint32_t p_dev5;
|
||||
const UARTD_API_T *pUARTD; /*!< UART driver routines function table */
|
||||
} LPC_ROM_API_T;
|
||||
|
||||
/* Pointer to ROM API function address */
|
||||
#define LPC_ROM_API_BASE_LOC 0x1FFF1FF8UL
|
||||
#define LPC_ROM_API (*(LPC_ROM_API_T * *) LPC_ROM_API_BASE_LOC)
|
||||
|
||||
/* Pointer to @ref PWRD_API_T functions in ROM */
|
||||
#define LPC_PWRD_API ((LPC_ROM_API)->pPWRD)
|
||||
|
||||
/* Pointer to @ref I2CD_API_T functions in ROM */
|
||||
#define LPC_I2CD_API ((LPC_ROM_API)->pI2CD)
|
||||
|
||||
/* Pointer to @ref UARTD_API_T functions in ROM */
|
||||
#define LPC_UARTD_API ((LPC_ROM_API)->pUARTD)
|
||||
|
||||
/* Pointer to ROM IAP entry functions */
|
||||
#define IAP_ENTRY_LOCATION 0X1FFF1FF1UL
|
||||
|
||||
/**
|
||||
* @brief LPC8XX IAP_ENTRY API function type
|
||||
*/
|
||||
static INLINE void iap_entry(unsigned int cmd_param[], unsigned int status_result[])
|
||||
{
|
||||
((IAP_ENTRY_T) IAP_ENTRY_LOCATION)(cmd_param, status_result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __ROMAPI_8XX_H_ */
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user