summaryrefslogtreecommitdiff
path: root/bsp/lpc408x/Libraries/Drivers/source
diff options
context:
space:
mode:
Diffstat (limited to 'bsp/lpc408x/Libraries/Drivers/source')
-rw-r--r--bsp/lpc408x/Libraries/Drivers/source/lpc_adc.c326
-rw-r--r--bsp/lpc408x/Libraries/Drivers/source/lpc_bod.c119
-rw-r--r--bsp/lpc408x/Libraries/Drivers/source/lpc_can.c2197
-rw-r--r--bsp/lpc408x/Libraries/Drivers/source/lpc_clkpwr.c326
-rw-r--r--bsp/lpc408x/Libraries/Drivers/source/lpc_crc.c171
-rw-r--r--bsp/lpc408x/Libraries/Drivers/source/lpc_dac.c196
-rw-r--r--bsp/lpc408x/Libraries/Drivers/source/lpc_eeprom.c267
-rw-r--r--bsp/lpc408x/Libraries/Drivers/source/lpc_emac.c1043
-rw-r--r--bsp/lpc408x/Libraries/Drivers/source/lpc_emc.c1398
-rw-r--r--bsp/lpc408x/Libraries/Drivers/source/lpc_exti.c162
-rw-r--r--bsp/lpc408x/Libraries/Drivers/source/lpc_gpdma.c453
-rw-r--r--bsp/lpc408x/Libraries/Drivers/source/lpc_gpio.c905
-rw-r--r--bsp/lpc408x/Libraries/Drivers/source/lpc_i2c.c1416
-rw-r--r--bsp/lpc408x/Libraries/Drivers/source/lpc_i2s.c589
-rw-r--r--bsp/lpc408x/Libraries/Drivers/source/lpc_iap.c317
-rw-r--r--bsp/lpc408x/Libraries/Drivers/source/lpc_lcd.c856
-rw-r--r--bsp/lpc408x/Libraries/Drivers/source/lpc_mci.c2508
-rw-r--r--bsp/lpc408x/Libraries/Drivers/source/lpc_mcpwm.c573
-rw-r--r--bsp/lpc408x/Libraries/Drivers/source/lpc_nvic.c156
-rw-r--r--bsp/lpc408x/Libraries/Drivers/source/lpc_pinsel.c540
-rw-r--r--bsp/lpc408x/Libraries/Drivers/source/lpc_pwm.c579
-rw-r--r--bsp/lpc408x/Libraries/Drivers/source/lpc_qei.c599
-rw-r--r--bsp/lpc408x/Libraries/Drivers/source/lpc_rtc.c998
-rw-r--r--bsp/lpc408x/Libraries/Drivers/source/lpc_ssp.c644
-rw-r--r--bsp/lpc408x/Libraries/Drivers/source/lpc_systick.c192
-rw-r--r--bsp/lpc408x/Libraries/Drivers/source/lpc_timer.c582
-rw-r--r--bsp/lpc408x/Libraries/Drivers/source/lpc_uart.c1778
-rw-r--r--bsp/lpc408x/Libraries/Drivers/source/lpc_wwdt.c484
-rw-r--r--bsp/lpc408x/Libraries/Drivers/source/makefile91
29 files changed, 0 insertions, 20465 deletions
diff --git a/bsp/lpc408x/Libraries/Drivers/source/lpc_adc.c b/bsp/lpc408x/Libraries/Drivers/source/lpc_adc.c
deleted file mode 100644
index 19a2a2d99f..0000000000
--- a/bsp/lpc408x/Libraries/Drivers/source/lpc_adc.c
+++ /dev/null
@@ -1,326 +0,0 @@
-/**********************************************************************
-* $Id$ lpc_adc.c 2011-06-02
-*//**
-* @file lpc_adc.c
-* @brief Contains all functions support for ADC firmware library on
-* LPC
-* @version 1.0
-* @date 02. June. 2011
-* @author NXP MCU SW Application Team
-*
-* Copyright(C) 2011, NXP Semiconductor
-* All rights reserved.
-*
-***********************************************************************
-* Software that is described herein is for illustrative purposes only
-* which provides customers with programming information regarding the
-* products. This software is supplied "AS IS" without any warranties.
-* NXP Semiconductors assumes no responsibility or liability for the
-* use of the software, conveys no license or title under any patent,
-* copyright, or mask work right to the product. NXP Semiconductors
-* reserves the right to make changes in the software without
-* notification. NXP Semiconductors also make 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'
-* relevant copyright 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.
-**********************************************************************/
-
-/* Peripheral group ----------------------------------------------------------- */
-/** @addtogroup ADC
- * @{
- */
-#ifdef __BUILD_WITH_EXAMPLE__
-#include "lpc_libcfg.h"
-#else
-#include "lpc_libcfg_default.h"
-#endif /* __BUILD_WITH_EXAMPLE__ */
-#ifdef _ADC
-
-/* Includes ------------------------------------------------------------------- */
-#include "lpc_types.h"
-#include "lpc_adc.h"
-#include "lpc_clkpwr.h"
-
-/* Public Functions ----------------------------------------------------------- */
-/** @addtogroup ADC_Public_Functions
- * @{
- */
-
-/*********************************************************************//**
- * @brief Initial for ADC
- * + Set bit PCADC
- * + Set clock for ADC
- * + Set Clock Frequency
- * @param[in] ADCx pointer to LPC_ADC_TypeDef, should be: LPC_ADC
- * @param[in] rate ADC conversion rate, should be <=200KHz
- * @return None
- **********************************************************************/
-void ADC_Init(LPC_ADC_TypeDef *ADCx, uint32_t rate)
-{
- uint32_t ADCPClk, temp, tmp;
-
- // Turn on power and clock
- CLKPWR_ConfigPPWR(CLKPWR_PCONP_PCADC, ENABLE);
-
- ADCx->CR = 0;
-
- //Enable PDN bit
- tmp = ADC_CR_PDN;
-
- // Set clock frequency
- ADCPClk = CLKPWR_GetCLK(CLKPWR_CLKTYPE_PER);
-
- /* The APB clock (PCLK_ADC0) is divided by (CLKDIV+1) to produce the clock for
- * A/D converter, which should be less than or equal to 12.4MHz.
- * A fully conversion requires 31 of these clocks.
- * ADC clock = PCLK_ADC0 / (CLKDIV + 1);
- * ADC rate = ADC clock / 31;
- */
- temp = rate * 31;
- temp = (ADCPClk * 2 + temp)/(2 * temp) - 1; //get the round value by fomular: (2*A + B)/(2*A)
- tmp |= ADC_CR_CLKDIV(temp);
-
- ADCx->CR = tmp;
-}
-
-
-/*********************************************************************//**
-* @brief Close ADC
-* @param[in] ADCx pointer to LPC_ADC_TypeDef, should be: LPC_ADC
-* @return None
-**********************************************************************/
-void ADC_DeInit(LPC_ADC_TypeDef *ADCx)
-{
- if (ADCx->CR & ADC_CR_START_MASK) //need to stop START bits before DeInit
- ADCx->CR &= ~ADC_CR_START_MASK;
- // Clear SEL bits
- ADCx->CR &= ~0xFF;
-
- // Clear PDN bit
- ADCx->CR &= ~ADC_CR_PDN;
- // Turn on power and clock
- CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCADC, DISABLE);
-}
-
-
-/*********************************************************************//**
-* @brief Get Result conversion from A/D data register
-* @param[in] channel number which want to read back the result
-* @return Result of conversion
-*********************************************************************/
-uint32_t ADC_GetData(uint32_t channel)
-{
- uint32_t adc_value;
-
- adc_value = *(uint32_t *)((&LPC_ADC->DR[0]) + channel);
- return ADC_GDR_RESULT(adc_value);
-}
-
-/*********************************************************************//**
-* @brief Set start mode for ADC
-* @param[in] ADCx pointer to LPC_ADC_TypeDef, should be: LPC_ADC
-* @param[in] start_mode Start mode choose one of modes in
-* 'ADC_START_OPT' enumeration type definition, should be:
-* - ADC_START_CONTINUOUS
-* - ADC_START_NOW
-* - ADC_START_ON_EINT0
-* - ADC_START_ON_CAP01
-* - ADC_START_ON_MAT01
-* - ADC_START_ON_MAT03
-* - ADC_START_ON_MAT10
-* - ADC_START_ON_MAT11
-* @return None
-*********************************************************************/
-void ADC_StartCmd(LPC_ADC_TypeDef *ADCx, uint8_t start_mode)
-{
- ADCx->CR &= ~ADC_CR_START_MASK;
- ADCx->CR |=ADC_CR_START_MODE_SEL((uint32_t)start_mode);
-}
-
-
-/*********************************************************************//**
-* @brief ADC Burst mode setting
-* @param[in] ADCx pointer to LPC_ADC_TypeDef, should be: LPC_ADC
-* @param[in] NewState
-* - 1: Set Burst mode
-* - 0: reset Burst mode
-* @return None
-**********************************************************************/
-void ADC_BurstCmd(LPC_ADC_TypeDef *ADCx, FunctionalState NewState)
-{
- ADCx->CR &= ~ADC_CR_BURST;
- if (NewState){
- ADCx->CR |= ADC_CR_BURST;
- }
-}
-
-/*********************************************************************//**
-* @brief Set AD conversion in power mode
-* @param[in] ADCx pointer to LPC_ADC_TypeDef, should be: LPC_ADC
-* @param[in] NewState
-* - 1: AD converter is optional
-* - 0: AD Converter is in power down mode
-* @return None
-**********************************************************************/
-void ADC_PowerdownCmd(LPC_ADC_TypeDef *ADCx, FunctionalState NewState)
-{
- ADCx->CR &= ~ADC_CR_PDN;
- if (NewState){
- ADCx->CR |= ADC_CR_PDN;
- }
-}
-
-/*********************************************************************//**
-* @brief Set Edge start configuration
-* @param[in] ADCx pointer to LPC_ADC_TypeDef, should be: LPC_ADC
-* @param[in] EdgeOption is ADC_START_ON_RISING and ADC_START_ON_FALLING
-* 0:ADC_START_ON_RISING
-* 1:ADC_START_ON_FALLING
-* @return None
-**********************************************************************/
-void ADC_EdgeStartConfig(LPC_ADC_TypeDef *ADCx, uint8_t EdgeOption)
-{
- ADCx->CR &= ~ADC_CR_EDGE;
- if (EdgeOption){
- ADCx->CR |= ADC_CR_EDGE;
- }
-}
-
-/*********************************************************************//**
-* @brief ADC interrupt configuration
-* @param[in] ADCx pointer to LPC_ADC_TypeDef, should be: LPC_ADC
-* @param[in] IntType: type of interrupt, should be:
-* - ADC_ADINTEN0: Interrupt channel 0
-* - ADC_ADINTEN1: Interrupt channel 1
-* ...
-* - ADC_ADINTEN7: Interrupt channel 7
-* - ADC_ADGINTEN: Individual channel/global flag done generate an interrupt
-* @param[in] NewState:
-* - SET : enable ADC interrupt
-* - RESET: disable ADC interrupt
-* @return None
-**********************************************************************/
-void ADC_IntConfig (LPC_ADC_TypeDef *ADCx, ADC_TYPE_INT_OPT IntType, FunctionalState NewState)
-{
- ADCx->INTEN &= ~ADC_INTEN_CH(IntType);
- if (NewState){
- ADCx->INTEN |= ADC_INTEN_CH(IntType);
- }
-}
-
-/*********************************************************************//**
-* @brief Enable/Disable ADC channel number
-* @param[in] ADCx pointer to LPC_ADC_TypeDef, should be: LPC_ADC
-* @param[in] Channel channel number
-* @param[in] NewState Enable or Disable
-*
-* @return None
-**********************************************************************/
-void ADC_ChannelCmd (LPC_ADC_TypeDef *ADCx, uint8_t Channel, FunctionalState NewState)
-{
- if (NewState == ENABLE) {
- ADCx->CR |= ADC_CR_CH_SEL(Channel);
- } else {
- if (ADCx->CR & ADC_CR_START_MASK) //need to stop START bits before disable channel
- ADCx->CR &= ~ADC_CR_START_MASK;
- ADCx->CR &= ~ADC_CR_CH_SEL(Channel);
- }
-}
-
-/*********************************************************************//**
-* @brief Get ADC result
-* @param[in] ADCx pointer to LPC_ADC_TypeDef, should be: LPC_ADC
-* @param[in] channel: channel number, should be 0...7
-* @return Data conversion
-**********************************************************************/
-uint16_t ADC_ChannelGetData(LPC_ADC_TypeDef *ADCx, uint8_t channel)
-{
- uint32_t adc_value;
- adc_value = *(uint32_t *) ((&ADCx->DR[0]) + channel);
- return ADC_DR_RESULT(adc_value);
-}
-
-/*********************************************************************//**
-* @brief Get ADC Chanel status from ADC data register
-* @param[in] ADCx pointer to LPC_ADC_TypeDef, should be: LPC_ADC
-* @param[in] channel: channel number, should be 0..7
-* @param[in] StatusType
-* 0:Burst status
-* 1:Done status
-* @return SET / RESET
-**********************************************************************/
-FlagStatus ADC_ChannelGetStatus(LPC_ADC_TypeDef *ADCx, uint8_t channel, uint32_t StatusType)
-{
- uint32_t temp;
- temp = *(uint32_t *) ((&ADCx->DR[0]) + channel);
- if (StatusType)
- {
- temp &= ADC_DR_DONE_FLAG;
- }
- else
- {
- temp &= ADC_DR_OVERRUN_FLAG;
- }
-
- if (temp)
- {
- return SET;
- }
- else
- {
- return RESET;
- }
-
-}
-
-/*********************************************************************//**
-* @brief Get ADC Data from AD Global register
-* @param[in] ADCx pointer to LPC_ADC_TypeDef, should be: LPC_ADC
-* @return Result of conversion
-**********************************************************************/
-uint32_t ADC_GlobalGetData(LPC_ADC_TypeDef *ADCx)
-{
- return ((uint32_t)(ADCx->GDR));
-}
-
-/*********************************************************************//**
-* @brief Get ADC Chanel status from AD global data register
-* @param[in] ADCx pointer to LPC_ADC_TypeDef, should be: LPC_ADC
-* @param[in] StatusType
-* 0:Burst status
-* 1:Done status
-* @return SET / RESET
-**********************************************************************/
-FlagStatus ADC_GlobalGetStatus(LPC_ADC_TypeDef *ADCx, uint32_t StatusType)
-{
- uint32_t temp;
-
- temp = ADCx->GDR;
- if (StatusType){
- temp &= ADC_DR_DONE_FLAG;
- }else{
- temp &= ADC_DR_OVERRUN_FLAG;
- }
- if (temp){
- return SET;
- }else{
- return RESET;
- }
-}
-
-/**
- * @}
- */
-#endif /*_ADC*/
-
-/**
- * @}
- */
-
-/* --------------------------------- End Of File ------------------------------ */
-
diff --git a/bsp/lpc408x/Libraries/Drivers/source/lpc_bod.c b/bsp/lpc408x/Libraries/Drivers/source/lpc_bod.c
deleted file mode 100644
index 050d12ebdf..0000000000
--- a/bsp/lpc408x/Libraries/Drivers/source/lpc_bod.c
+++ /dev/null
@@ -1,119 +0,0 @@
-/**********************************************************************
-* $Id$ lpc_bod.c 2011-12-09
-*//**
-* @file lpc_bod.c
-* @brief Contain functions related to BOD.
-* @version 1.0
-* @date 09 December. 2011
-* @author NXP MCU SW Application Team
-*
-* Copyright(C) 2011, NXP Semiconductor
-* All rights reserved.
-*
-***********************************************************************
-* Software that is described herein is for illustrative purposes only
-* which provides customers with programming information regarding the
-* products. This software is supplied "AS IS" without any warranties.
-* NXP Semiconductors assumes no responsibility or liability for the
-* use of the software, conveys no license or title under any patent,
-* copyright, or mask work right to the product. NXP Semiconductors
-* reserves the right to make changes in the software without
-* notification. NXP Semiconductors also make 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'
-* relevant copyright 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.
-**********************************************************************/
-/* Peripheral group ----------------------------------------------------------- */
-/** @addtogroup BOD
- * @{
- */
-#ifdef __BUILD_WITH_EXAMPLE__
-#include "lpc_libcfg.h"
-#else
-#include "lpc_libcfg_default.h"
-#endif /* __BUILD_WITH_EXAMPLE__ */
-#ifdef _BOD
-#include "LPC407x_8x_177x_8x.h" /* LPC407x_8x_177x_8x Peripheral Registers */
-#include "lpc_bod.h"
-
-/* Public Functions ----------------------------------------------------------- */
-/** @addtogroup BOD_Public_Functions
- * @{
- */
-/*********************************************************************//**
- * @brief Initialize BOD control register
- * @param[in] pConfig BOD Configuration
- * @return None
- **********************************************************************/
-void BOD_Init( BOD_Config_Type* pConfig )
-{
- /* Turn on/off BOD. */
- if(pConfig->Enabled == DISABLE)
- {
- LPC_SC->PCON |= BOD_PCON_BOGD;
- return;
- }
- LPC_SC->PCON &= ~BOD_PCON_BOGD;
-
- /* Brown-Out Reduced Power Mode */
- if(pConfig->PowerReduced == ENABLE)
- {
- LPC_SC->PCON |= BOD_PCON_BODRPM;
- }
- else
- {
- LPC_SC->PCON &= ~BOD_PCON_BODRPM;
- }
-
- /* Brown-Out Reset */
- if(pConfig->ResetOnVoltageDown == DISABLE)
- {
- LPC_SC->PCON |= BOD_PCON_BORD;
- }
- else
- {
- LPC_SC->PCON &= ~BOD_PCON_BORD;
- }
-
- /* Enable the BOD Interrupt */
- NVIC_EnableIRQ(BOD_IRQn);
-
- return;
-}
-
-
-/*********************************************************************//**
- * @brief Get BOD reset source status
- * @param[in] None
- * @return TRUE/FALSE
- **********************************************************************/
-int32_t BOD_ResetSourceStatus( void )
-{
- if((LPC_SC->RSID & BOD_RSID_POR) == 1)
- return DISABLE;
- return ((LPC_SC->RSID & BOD_RSID_BODR)? ENABLE:DISABLE);
-}
-/*********************************************************************//**
- * @brief Clear BOD reset source bit
- * @param[in] None
- * @return None
- **********************************************************************/
-void BOD_ResetSourceClr( void )
-{
- LPC_SC->RSID |= BOD_RSID_BODR;
-}
-/**
- * @}
- */
-#endif /*_BOD */
-/**
- * @}
- */
-/******************************************************************************
-** End Of File
-******************************************************************************/
diff --git a/bsp/lpc408x/Libraries/Drivers/source/lpc_can.c b/bsp/lpc408x/Libraries/Drivers/source/lpc_can.c
deleted file mode 100644
index 26776179e4..0000000000
--- a/bsp/lpc408x/Libraries/Drivers/source/lpc_can.c
+++ /dev/null
@@ -1,2197 +0,0 @@
-/**********************************************************************
-* $Id$ lpc_can.c 2011-06-02
-*//**
-* @file lpc_can.c
-* @brief Contains all functions support for CAN firmware library on
-* LPC
-* @version 1.0
-* @date 02. June. 2011
-* @author NXP MCU SW Application Team
-*
-* Copyright(C) 2011, NXP Semiconductor
-* All rights reserved.
-*
-***********************************************************************
-* Software that is described herein is for illustrative purposes only
-* which provides customers with programming information regarding the
-* products. This software is supplied "AS IS" without any warranties.
-* NXP Semiconductors assumes no responsibility or liability for the
-* use of the software, conveys no license or title under any patent,
-* copyright, or mask work right to the product. NXP Semiconductors
-* reserves the right to make changes in the software without
-* notification. NXP Semiconductors also make 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'
-* relevant copyright 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.
-**********************************************************************/
-
-/* Peripheral group ----------------------------------------------------------- */
-/** @addtogroup CAN
- * @{
- */
-#ifdef __BUILD_WITH_EXAMPLE__
-#include "lpc_libcfg.h"
-#else
-#include "lpc_libcfg_default.h"
-#endif /* __BUILD_WITH_EXAMPLE__ */
-#ifdef _CAN
-
-/* Includes ------------------------------------------------------------------- */
-#include "lpc_can.h"
-#include "lpc_clkpwr.h"
-
-/* Private Variables ---------------------------------------------------------- */
-/** @defgroup CAN_Private_Variables CAN Private Variables
- * @{
- */
-
-FunctionalState FULLCAN_ENABLE;
-
-
-/* Counts number of filters (CAN message objects) used */
-uint16_t CANAF_FullCAN_cnt = 0;
-uint16_t CANAF_std_cnt = 0;
-uint16_t CANAF_gstd_cnt = 0;
-uint16_t CANAF_ext_cnt = 0;
-uint16_t CANAF_gext_cnt = 0;
-
-/* End of Private Variables ----------------------------------------------------*/
-/**
- * @}
- */
-
-/* Private Variables ---------------------------------------------------------- */
-static LPC_CAN_TypeDef* CAN_GetPointer (uint8_t canId);
-
-
-static void can_SetBaudrate (LPC_CAN_TypeDef *CANx, uint32_t baudrate);
-
-/*********************************************************************//**
- * @brief Setting CAN baud rate (bps)
- * @param[in] canId point to LPC_CAN_TypeDef object, should be:
- * - LPC_CAN1: CAN1 peripheral
- * - LPC_CAN2: CAN2 peripheral
- * @return The pointer to CAN peripheral that's expected to use
- ***********************************************************************/
-static LPC_CAN_TypeDef* CAN_GetPointer (uint8_t canId)
-{
- LPC_CAN_TypeDef* pCan;
-
- switch (canId)
- {
- case CAN_ID_1:
- pCan = LPC_CAN1;
- break;
-
- case CAN_ID_2:
- pCan = LPC_CAN2;
- break;
-
- default:
- pCan = NULL;
- break;
- }
-
- return pCan;
-}
-
-
-/*********************************************************************//**
- * @brief Setting CAN baud rate (bps)
- * @param[in] CANx point to LPC_CAN_TypeDef object, should be:
- * - LPC_CAN1: CAN1 peripheral
- * - LPC_CAN2: CAN2 peripheral
- * @param[in] baudrate: is the baud rate value will be set
- * @return None
- ***********************************************************************/
-static void can_SetBaudrate (LPC_CAN_TypeDef *CANx, uint32_t baudrate)
-{
- uint32_t result = 0;
- uint8_t NT, TSEG1, TSEG2;
- uint32_t CANPclk = 0;
- uint32_t BRP;
-
- CANPclk = CLKPWR_GetCLK(CLKPWR_CLKTYPE_PER);
-
- result = CANPclk / baudrate;
-
- /* Calculate suitable nominal time value
- * NT (nominal time) = (TSEG1 + TSEG2 + 3)
- * NT <= 24
- * TSEG1 >= 2*TSEG2
- */
- for(NT = 24; NT > 0; NT = NT-2)
- {
- if ((result%NT) == 0)
- {
- BRP = result / NT - 1;
-
- NT--;
-
- TSEG2 = (NT/3) - 1;
-
- TSEG1 = NT -(NT/3) - 1;
-
- break;
- }
- }
-
- /* Enter reset mode */
- CANx->MOD = 0x01;
-
- /* Set bit timing
- * Default: SAM = 0x00;
- * SJW = 0x03;
- */
- CANx->BTR = (TSEG2 << 20) | (TSEG1 << 16) | (3 << 14) | BRP;
-
- /* Return to normal operating */
- CANx->MOD = 0;
-}
-/* End of Private Functions ----------------------------------------------------*/
-
-
-/* Public Functions ----------------------------------------------------------- */
-/** @addtogroup CAN_Public_Functions
- * @{
- */
-
-/********************************************************************//**
- * @brief Initialize CAN peripheral with given baudrate
- * @param[in] canId The Id of the expected CAN component
- *
- * @param[in] baudrate: the value of CAN baudrate will be set (bps)
- * @return None
- *********************************************************************/
-void CAN_Init(uint8_t canId, uint32_t baudrate)
-{
- LPC_CAN_TypeDef* pCan = CAN_GetPointer(canId);
-
- uint16_t i;
-
- if(canId == CAN_ID_1)
- {
- /* Turn on power and clock for CAN1 */
- CLKPWR_ConfigPPWR(CLKPWR_PCONP_PCAN1, ENABLE);
- }
- else if(canId == CAN_ID_2)
- {
- /* Turn on power and clock for CAN2 */
- CLKPWR_ConfigPPWR(CLKPWR_PCONP_PCAN2, ENABLE);
- }
- else
- {
- return;
- }
-
- pCan->MOD = 1; // Enter Reset Mode
- pCan->IER = 0; // Disable All CAN Interrupts
- pCan->GSR = 0;
-
- /* Request command to release Rx, Tx buffer and clear data overrun */
- //pCan->CMR = CAN_CMR_AT | CAN_CMR_RRB | CAN_CMR_CDO;
- pCan->CMR = (1 << 1) | (1 << 2) | (1 << 3);
-
- /* Read to clear interrupt pending in interrupt capture register */
- i = pCan->ICR;
- pCan->MOD = 0;// Return Normal operating
-
- //Reset CANAF value
- LPC_CANAF->AFMR = 0x01;
-
- //clear ALUT RAM
- for (i = 0; i < 512; i++)
- {
- LPC_CANAF_RAM->mask[i] = 0x00;
- }
-
- LPC_CANAF->SFF_sa = 0x00;
- LPC_CANAF->SFF_GRP_sa = 0x00;
- LPC_CANAF->EFF_sa = 0x00;
- LPC_CANAF->EFF_GRP_sa = 0x00;
- LPC_CANAF->ENDofTable = 0x00;
-
- LPC_CANAF->AFMR = 0x00;
-
- /* Set baudrate */
- can_SetBaudrate (pCan, baudrate);
-}
-
-/********************************************************************//**
- * @brief CAN deInit
- * @param[in] canId The Id of the expected CAN component
- *
- * @return None
- *********************************************************************/
-void CAN_DeInit(uint8_t canId)
-{
- if(canId == CAN_ID_1)
- {
- /* Turn on power and clock for CAN1 */
- CLKPWR_ConfigPPWR(CLKPWR_PCONP_PCAN1, DISABLE);
- }
- else if(canId == CAN_ID_2)
- {
- /* Turn on power and clock for CAN1 */
- CLKPWR_ConfigPPWR(CLKPWR_PCONP_PCAN2, DISABLE);
- }
-
- return;
-}
-
-/********************************************************************//**
- * @brief Setup Acceptance Filter Look-Up Table
- * @param[in] CANAFx pointer to LPC_CANAF_TypeDef
- * Should be: LPC_CANAF
- * @param[in] AFSection the pointer to AF_SectionDef structure
- * It contain information about 5 sections will be install in AFLUT
- * @return CAN Error could be:
- * - CAN_OBJECTS_FULL_ERROR: No more rx or tx objects available
- * - CAN_AF_ENTRY_ERROR: table error-violation of ascending numerical order
- * - CAN_OK: ID is added into table successfully
- *********************************************************************/
-CAN_ERROR CAN_SetupAFLUT(AF_SectionDef* AFSection)
-{
- uint8_t ctrl1,ctrl2;
- uint8_t dis1, dis2;
- uint16_t SID, ID_temp,i, count = 0;
- uint32_t EID, entry, buf;
- uint16_t lowerSID, upperSID;
- uint32_t lowerEID, upperEID;
-
- LPC_CANAF->AFMR = 0x01;
-
- /***** setup FullCAN Table *****/
- if(AFSection->FullCAN_Sec == NULL)
- {
- FULLCAN_ENABLE = DISABLE;
- }
- else
- {
- FULLCAN_ENABLE = ENABLE;
-
- for(i = 0; i < (AFSection->FC_NumEntry); i++)
- {
- if(count + 1 > 64)
- {
- return CAN_OBJECTS_FULL_ERROR;
- }
-
- ctrl1 = AFSection->FullCAN_Sec->controller;
-
- SID = AFSection->FullCAN_Sec->id_11;
-
- dis1 = AFSection->FullCAN_Sec->disable;
-
- entry = 0x00; //reset entry value
-
- if((CANAF_FullCAN_cnt & 0x00000001)==0)
- {
- if(count != 0x00)
- {
- buf = LPC_CANAF_RAM->mask[count-1];
- ID_temp = (buf & 0xE7FF); //mask controller & identifier bits
- if(ID_temp > ((ctrl1<<13)|SID))
- {
- return CAN_AF_ENTRY_ERROR;
- }
- }
-
- entry = (ctrl1<<29)|(dis1<<28)|(SID<<16)|(1<<27);
-
- LPC_CANAF_RAM->mask[count] &= 0x0000FFFF;
-
- LPC_CANAF_RAM->mask[count] |= entry;
-
- CANAF_FullCAN_cnt++;
- if(CANAF_FullCAN_cnt == AFSection->FC_NumEntry) //this is the lastest FullCAN entry
- count++;
- }
- else
- {
- buf = LPC_CANAF_RAM->mask[count];
- ID_temp = (buf >>16) & 0xE7FF;
- if(ID_temp > ((ctrl1<<13)|SID))
- {
- return CAN_AF_ENTRY_ERROR;
- }
-
- entry = (ctrl1 << 13) | (dis1 << 12) | (SID << 0) | (1 << 11);
-
- LPC_CANAF_RAM->mask[count] &= 0xFFFF0000;
-
- LPC_CANAF_RAM->mask[count]|= entry;
-
- count++;
-
- CANAF_FullCAN_cnt++;
- }
-
- AFSection->FullCAN_Sec = (FullCAN_Entry *)((uint32_t)(AFSection->FullCAN_Sec)+ sizeof(FullCAN_Entry));
- }
- }
-
- /***** Setup Explicit Standard Frame Format Section *****/
- if(AFSection->SFF_Sec != NULL)
- {
- for(i=0;i<(AFSection->SFF_NumEntry);i++)
- {
- if(count + 1 > 512)
- {
- return CAN_OBJECTS_FULL_ERROR;
- }
-
- ctrl1 = AFSection->SFF_Sec->controller;
-
- SID = AFSection->SFF_Sec->id_11;
-
- dis1 = AFSection->SFF_Sec->disable;
-
- entry = 0x00; //reset entry value
-
- if((CANAF_std_cnt & 0x00000001)==0)
- {
- if(CANAF_std_cnt !=0 )
- {
- buf = LPC_CANAF_RAM->mask[count-1];
- ID_temp = (buf & 0xE7FF); //mask controller & identifier bits
- if(ID_temp > ((ctrl1<<13)|SID))
- {
- return CAN_AF_ENTRY_ERROR;
- }
- }
-
- entry = (ctrl1<<29)|(dis1<<28)|(SID<<16);
-
- LPC_CANAF_RAM->mask[count] &= 0x0000FFFF;
-
- LPC_CANAF_RAM->mask[count] |= entry;
-
- CANAF_std_cnt++;
- if(CANAF_std_cnt == AFSection->SFF_NumEntry)//if this is the last SFF entry
- count++;
- }
- else
- {
- buf = LPC_CANAF_RAM->mask[count];
- ID_temp = (buf >>16) & 0xE7FF;
- if(ID_temp > ((ctrl1<<13)|SID))
- {
- return CAN_AF_ENTRY_ERROR;
- }
-
- entry = (ctrl1 << 13) | (dis1 << 12) | (SID << 0);
-
- LPC_CANAF_RAM->mask[count] &= 0xFFFF0000;
-
- LPC_CANAF_RAM->mask[count] |= entry;
-
- count++;
-
- CANAF_std_cnt++;
- }
-
- AFSection->SFF_Sec = (SFF_Entry *)((uint32_t)(AFSection->SFF_Sec)+ sizeof(SFF_Entry));
- }
- }
-
- /***** Setup Group of Standard Frame Format Identifier Section *****/
- if(AFSection->SFF_GPR_Sec != NULL)
- {
- for(i=0;i<(AFSection->SFF_GPR_NumEntry);i++)
- {
- if(count + 1 > 512)
- {
- return CAN_OBJECTS_FULL_ERROR;
- }
-
- ctrl1 = AFSection->SFF_GPR_Sec->controller1;
-
- ctrl2 = AFSection->SFF_GPR_Sec->controller2;
-
- dis1 = AFSection->SFF_GPR_Sec->disable1;
-
- dis2 = AFSection->SFF_GPR_Sec->disable2;
-
- lowerSID = AFSection->SFF_GPR_Sec->lowerID;
-
- upperSID = AFSection->SFF_GPR_Sec->upperID;
-
- entry = 0x00;
-
- if(CANAF_gstd_cnt!=0)
- {
- buf = LPC_CANAF_RAM->mask[count-1];
- ID_temp = buf & 0xE7FF;
- if((ctrl1 != ctrl2)||(lowerSID > upperSID)||(ID_temp > ((ctrl1<<13)|lowerSID)))
- {
- return CAN_AF_ENTRY_ERROR;
- }
- }
- entry = (ctrl1 << 29)|(dis1 << 28)|(lowerSID << 16)| \
- (ctrl2 << 13)|(dis2 << 12)|(upperSID << 0);
- LPC_CANAF_RAM->mask[count] = entry;
-
- CANAF_gstd_cnt++;
-
- count++;
-
- AFSection->SFF_GPR_Sec = (SFF_GPR_Entry *)((uint32_t)(AFSection->SFF_GPR_Sec)+ sizeof(SFF_GPR_Entry));
- }
- }
-
- /***** Setup Explicit Extend Frame Format Identifier Section *****/
- if(AFSection->EFF_Sec != NULL)
- {
- for(i=0;i<(AFSection->EFF_NumEntry);i++)
- {
- if(count + 1 > 512)
- {
- return CAN_OBJECTS_FULL_ERROR;
- }
-
- EID = AFSection->EFF_Sec->ID_29;
-
- ctrl1 = AFSection->EFF_Sec->controller;
-
- entry = 0x00; //reset entry value
-
- entry = (ctrl1 << 29)|(EID << 0);
- if(CANAF_ext_cnt != 0)
- {
- buf = LPC_CANAF_RAM->mask[count-1];
-// EID_temp = buf & 0x0FFFFFFF;
- if(buf > entry)
- {
- return CAN_AF_ENTRY_ERROR;
- }
- }
- LPC_CANAF_RAM->mask[count] = entry;
-
- CANAF_ext_cnt ++;
-
- count++;
-
- AFSection->EFF_Sec = (EFF_Entry *)((uint32_t)(AFSection->EFF_Sec)+ sizeof(EFF_Entry));
- }
- }
-
- /***** Setup Group of Extended Frame Format Identifier Section *****/
- if(AFSection->EFF_GPR_Sec != NULL)
- {
- for(i=0;i<(AFSection->EFF_GPR_NumEntry);i++)
- {
- if(count + 2 > 512)
- {
- return CAN_OBJECTS_FULL_ERROR;
- }
-
- ctrl1 = AFSection->EFF_GPR_Sec->controller1;
-
- ctrl2 = AFSection->EFF_GPR_Sec->controller2;
-
- lowerEID = AFSection->EFF_GPR_Sec->lowerEID;
-
- upperEID = AFSection->EFF_GPR_Sec->upperEID;
-
- entry = 0x00;
-
- if(CANAF_gext_cnt != 0)
- {
- buf = LPC_CANAF_RAM->mask[count-1];
-// EID_temp = buf & 0x0FFFFFFF;
- if((ctrl1 != ctrl2) || (lowerEID > upperEID) || (buf > ((ctrl1 << 29)|(lowerEID << 0))))
- {
- return CAN_AF_ENTRY_ERROR;
- }
- }
-
- entry = (ctrl1 << 29)|(lowerEID << 0);
-
- LPC_CANAF_RAM->mask[count++] = entry;
-
- entry = (ctrl2 << 29)|(upperEID << 0);
-
- LPC_CANAF_RAM->mask[count++] = entry;
-
- CANAF_gext_cnt++;
-
- AFSection->EFF_GPR_Sec = (EFF_GPR_Entry *)((uint32_t)(AFSection->EFF_GPR_Sec)+ sizeof(EFF_GPR_Entry));
- }
- }
-
- //update address values
- LPC_CANAF->SFF_sa = ((CANAF_FullCAN_cnt + 1)>>1)<<2;
-
- LPC_CANAF->SFF_GRP_sa = LPC_CANAF->SFF_sa + (((CANAF_std_cnt+1)>>1)<< 2);
-
- LPC_CANAF->EFF_sa = LPC_CANAF->SFF_GRP_sa + (CANAF_gstd_cnt << 2);
-
- LPC_CANAF->EFF_GRP_sa = LPC_CANAF->EFF_sa + (CANAF_ext_cnt << 2);
-
- LPC_CANAF->ENDofTable = LPC_CANAF->EFF_GRP_sa + (CANAF_gext_cnt << 3);
-
- if(FULLCAN_ENABLE == DISABLE)
- {
- LPC_CANAF->AFMR = 0x00; // Normal mode
- }
- else
- {
- LPC_CANAF->AFMR = 0x04;
- }
-
- return CAN_OK;
-}
-/********************************************************************//**
- * @brief Add Explicit ID into AF Look-Up Table dynamically.
- * @param[in] canId The Id of the expected CAN component
- *
- * @param[in] id: The ID of entry will be added
- * @param[in] format: is the type of ID Frame Format, should be:
- * - STD_ID_FORMAT: 11-bit ID value
- * - EXT_ID_FORMAT: 29-bit ID value
- * @return CAN Error, could be:
- * - CAN_OBJECTS_FULL_ERROR: No more rx or tx objects available
- * - CAN_ID_EXIT_ERROR: ID exited in table
- * - CAN_OK: ID is added into table successfully
- *********************************************************************/
-CAN_ERROR CAN_LoadExplicitEntry(uint8_t canId, uint32_t id, CAN_ID_FORMAT_Type format)
-{
- uint32_t buf0 = 0, buf1 = 0;
- int16_t cnt1 = 0, cnt2 = 0, bound1 = 0, total = 0;
-
- /* Acceptance Filter Memory full - return */
- total =((CANAF_FullCAN_cnt + 1) >> 1) + CANAF_FullCAN_cnt * 3 + ((CANAF_std_cnt + 1) >> 1) \
- + CANAF_gstd_cnt + CANAF_ext_cnt + (CANAF_gext_cnt << 1);
-
- if (total >= 512)
- {
- //don't have enough space
- return CAN_OBJECTS_FULL_ERROR;
- }
-
- /* Setup Acceptance Filter Configuration
- Acceptance Filter Mode Register = Off */
- LPC_CANAF->AFMR = 0x00000001;
-
- /*********** Add Explicit Standard Identifier Frame Format entry *********/
- if(format == STD_ID_FORMAT)
- {
- id &= 0x07FF;
-
- id |= canId << 13;/* Add controller number */
-
- /* Move all remaining sections one place up
- if new entry will increase FullCAN list */
- if ((CANAF_std_cnt & 0x0001) == 0)
- {
- cnt1 = ((CANAF_FullCAN_cnt+1)>>1)+((CANAF_std_cnt+1)>>1);
-
- bound1 = total - cnt1;
-
- buf0 = LPC_CANAF_RAM->mask[cnt1];
-
- while(bound1--)
- {
- cnt1++;
-
- buf1 = LPC_CANAF_RAM->mask[cnt1];
-
- LPC_CANAF_RAM->mask[cnt1] = buf0;
-
- buf0 = buf1;
- }
- }
-
- if (CANAF_std_cnt == 0)
- {
- cnt2 = (CANAF_FullCAN_cnt + 1)>>1;
-
- /* For entering first ID */
- LPC_CANAF_RAM->mask[cnt2] = 0x0000FFFF | (id << 16);
- }
- else if (CANAF_std_cnt == 1)
- {
- cnt2 = (CANAF_FullCAN_cnt + 1) >> 1;
-
- /* For entering second ID */
- if (((LPC_CANAF_RAM->mask[cnt2] >> 16)& 0xE7FF) > id)
- {
- LPC_CANAF_RAM->mask[cnt2] = (LPC_CANAF_RAM->mask[cnt2] >> 16) | (id << 16);
- }
- else
- {
- LPC_CANAF_RAM->mask[cnt2] = (LPC_CANAF_RAM->mask[cnt2] & 0xFFFF0000) | id;
- }
- }
- else
- {
- /* Find where to insert new ID */
- cnt1 = (CANAF_FullCAN_cnt+1)>>1;
-
- cnt2 = CANAF_std_cnt;
-
- bound1 = ((CANAF_FullCAN_cnt+1)>>1)+((CANAF_std_cnt+1)>>1);
-
- while (cnt1 < bound1)
- {
- /* Loop through standard existing IDs */
- if (((LPC_CANAF_RAM->mask[cnt1] >> 16) & 0xE7FF) > id)
- {
- cnt2 = cnt1 * 2;
- break;
- }
-
- if ((LPC_CANAF_RAM->mask[cnt1] & 0x0000E7FF) > id)
- {
- cnt2 = cnt1 * 2 + 1;
- break;
- }
-
- cnt1++;
- }
-
- /* cnt1 = U32 where to insert new ID */
- /* cnt2 = U16 where to insert new ID */
-
- if (cnt1 == bound1)
- {
- /* Adding ID as last entry */
- /* Even number of IDs exists */
- if ((CANAF_std_cnt & 0x0001) == 0)
- {
- LPC_CANAF_RAM->mask[cnt1] = 0x0000FFFF | (id << 16);
- }
- /* Odd number of IDs exists */
- else
- {
- LPC_CANAF_RAM->mask[cnt1] = (LPC_CANAF_RAM->mask[cnt1] & 0xFFFF0000) | id;
- }
- }
- else
- {
- buf0 = LPC_CANAF_RAM->mask[cnt1]; /* Remember current entry */
-
- if ((cnt2 & 0x0001) == 0)
- {
- /* Insert new mask to even address*/
- buf1 = (id << 16) | (buf0 >> 16);
- }
- else
- {
- /* Insert new mask to odd address */
- buf1 = (buf0 & 0xFFFF0000) | id;
- }
-
- LPC_CANAF_RAM->mask[cnt1] = buf1;/* Insert mask */
-
- bound1 = ((CANAF_FullCAN_cnt + 1) >> 1) + ((CANAF_std_cnt+1) >> 1) - 1;
-
- /* Move all remaining standard mask entries one place up */
- while (cnt1 < bound1)
- {
- cnt1++;
-
- buf1 = LPC_CANAF_RAM->mask[cnt1];
-
- LPC_CANAF_RAM->mask[cnt1] = (buf1 >> 16) | (buf0 << 16);
-
- buf0 = buf1;
- }
-
- if ((CANAF_std_cnt & 0x0001) == 0)
- {
- /* Even number of IDs exists */
- LPC_CANAF_RAM->mask[cnt1+1] = (buf0 <<16) |(0x0000FFFF);
- }
- }
- }
-
- CANAF_std_cnt++;
-
- //update address values
- LPC_CANAF->SFF_GRP_sa += 0x04 ;
-
- LPC_CANAF->EFF_sa += 0x04 ;
-
- LPC_CANAF->EFF_GRP_sa += 0x04;
-
- LPC_CANAF->ENDofTable += 0x04;
- }
-
- /*********** Add Explicit Extended Identifier Frame Format entry *********/
- else
- {
- /* Add controller number */
- id |= canId << 29;
-
- cnt1 = ((CANAF_FullCAN_cnt+1) >> 1) + (((CANAF_std_cnt + 1) >> 1) + CANAF_gstd_cnt);
-
- cnt2 = 0;
-
- while (cnt2 < CANAF_ext_cnt)
- {
- /* Loop through extended existing masks*/
- if (LPC_CANAF_RAM->mask[cnt1] > id)
- {
- break;
- }
-
- cnt1++;/* cnt1 = U32 where to insert new mask */
-
- cnt2++;
- }
-
- buf0 = LPC_CANAF_RAM->mask[cnt1]; /* Remember current entry */
-
- LPC_CANAF_RAM->mask[cnt1] = id; /* Insert mask */
-
- CANAF_ext_cnt++;
-
- bound1 = total;
-
- /* Move all remaining extended mask entries one place up*/
- while (cnt2 < bound1)
- {
- cnt1++;
-
- cnt2++;
-
- buf1 = LPC_CANAF_RAM->mask[cnt1];
-
- LPC_CANAF_RAM->mask[cnt1] = buf0;
-
- buf0 = buf1;
- }
-
- /* update address values */
- LPC_CANAF->EFF_GRP_sa += 4;
-
- LPC_CANAF->ENDofTable += 4;
- }
-
- if(CANAF_FullCAN_cnt == 0) //not use FullCAN mode
- {
- LPC_CANAF->AFMR = 0x00;//not use FullCAN mode
- }
- else
- {
- LPC_CANAF->AFMR = 0x04;
- }
-
- return CAN_OK;
-}
-
-/********************************************************************//**
- * @brief Load FullCAN entry into AFLUT
- * @param[in] canId The Id of the expected CAN component
- *
- * @param[in] id: identifier of entry that will be added
- * @return CAN_ERROR, could be:
- * - CAN_OK: loading is successful
- * - CAN_ID_EXIT_ERROR: ID exited in FullCAN Section
- * - CAN_OBJECTS_FULL_ERROR: no more space available
- *********************************************************************/
-CAN_ERROR CAN_LoadFullCANEntry (uint8_t canId, uint16_t id)
-{
- uint32_t buf0 = 0, buf1 = 0, buf2 = 0;
- uint32_t tmp0 = 0, tmp1 = 0, tmp2 = 0;
- int16_t cnt1 = 0, cnt2 = 0, bound1 = 0, total = 0;
-
- /* Acceptance Filter Memory full - return */
- total =((CANAF_FullCAN_cnt + 1) >> 1) + CANAF_FullCAN_cnt*3 + ((CANAF_std_cnt + 1) >> 1) \
- + CANAF_gstd_cnt + CANAF_ext_cnt + (CANAF_gext_cnt << 1);
-
- //don't have enough space for this fullCAN Entry and its Object(3*32 bytes)
- if ((total >= 508) || (CANAF_FullCAN_cnt >= 64))
- {
- return CAN_OBJECTS_FULL_ERROR;
- }
-
- /* Setup Acceptance Filter Configuration
- Acceptance Filter Mode Register = Off */
- LPC_CANAF->AFMR = 0x00000001;
-
- /* Add mask for standard identifiers */
- id &= 0x07FF;
-
- id |= (canId << 13) | (1 << 11);
-
- /* Move all remaining sections one place up
- if new entry will increase FullCAN list */
- if (((CANAF_FullCAN_cnt & 0x0001) == 0)&&(total!=0))
- {
- //then remove remaining section
- cnt1 = (CANAF_FullCAN_cnt >> 1);
-
- bound1 = total;
-
- buf0 = LPC_CANAF_RAM->mask[cnt1];
-
- while (bound1--)
- {
- cnt1++;
-
- buf1 = LPC_CANAF_RAM->mask[cnt1];
-
- LPC_CANAF_RAM->mask[cnt1] = buf0;
-
- buf0 = buf1;
- }
- }
- if (CANAF_FullCAN_cnt == 0)
- {
- /* For entering first ID */
- LPC_CANAF_RAM->mask[0] = 0x0000FFFF | (id << 16);
- }
- else if (CANAF_FullCAN_cnt == 1)
- {
- /* For entering second ID */
- if (((LPC_CANAF_RAM->mask[0] >> 16)& 0xE7FF) > id)
- {
- LPC_CANAF_RAM->mask[0] = (LPC_CANAF_RAM->mask[0] >> 16) | (id << 16);
- }
- else
- {
- LPC_CANAF_RAM->mask[0] = (LPC_CANAF_RAM->mask[0] & 0xFFFF0000) | id;
- }
- }
- else
- {
- /* Find where to insert new ID */
- cnt1 = 0;
-
- cnt2 = CANAF_FullCAN_cnt;
-
- bound1 = (CANAF_FullCAN_cnt - 1) >> 1;
-
- while (cnt1 <= bound1)
- {
- /* Loop through standard existing IDs */
- if (((LPC_CANAF_RAM->mask[cnt1] >> 16) & 0xE7FF) > (id & 0xE7FF))
- {
- cnt2 = cnt1 * 2;
- break;
- }
-
-
- if ((LPC_CANAF_RAM->mask[cnt1] & 0x0000E7FF) > (id & 0xE7FF))
- {
- cnt2 = cnt1 * 2 + 1;
- break;
- }
-
- cnt1++;
- }
- /* cnt1 = U32 where to insert new ID */
- /* cnt2 = U16 where to insert new ID */
-
- if (cnt1 > bound1)
- {
- /* Adding ID as last entry */
- /* Even number of IDs exists */
- if ((CANAF_FullCAN_cnt & 0x0001) == 0)
- {
- LPC_CANAF_RAM->mask[cnt1] = 0x0000FFFF | (id << 16);
- }
- /* Odd number of IDs exists */
- else
- {
- LPC_CANAF_RAM->mask[cnt1] = (LPC_CANAF_RAM->mask[cnt1] & 0xFFFF0000) | id;
- }
- }
- else
- {
- buf0 = LPC_CANAF_RAM->mask[cnt1]; /* Remember current entry */
-
- if ((cnt2 & 0x0001) == 0)
- {
- /* Insert new mask to even address*/
- buf1 = (id << 16) | (buf0 >> 16);
- }
- else
- {
- /* Insert new mask to odd address */
- buf1 = (buf0 & 0xFFFF0000) | id;
- }
-
- LPC_CANAF_RAM->mask[cnt1] = buf1;/* Insert mask */
-
- bound1 = CANAF_FullCAN_cnt >> 1;
-
- /* Move all remaining standard mask entries one place up */
- while (cnt1 < bound1)
- {
- cnt1++;
-
- buf1 = LPC_CANAF_RAM->mask[cnt1];
-
- LPC_CANAF_RAM->mask[cnt1] = (buf1 >> 16) | (buf0 << 16);
-
- buf0 = buf1;
- }
-
- if ((CANAF_FullCAN_cnt & 0x0001) == 0)
- {
- /* Even number of IDs exists */
- LPC_CANAF_RAM->mask[cnt1] = (LPC_CANAF_RAM->mask[cnt1] & 0xFFFF0000)
- | (0x0000FFFF);
- }
- }
- }
-
- //restruct FulCAN Object Section
- bound1 = CANAF_FullCAN_cnt - cnt2;
-
- cnt1 = total - (CANAF_FullCAN_cnt)*3 + cnt2*3 + 1;
-
- buf0 = LPC_CANAF_RAM->mask[cnt1];
-
- buf1 = LPC_CANAF_RAM->mask[cnt1+1];
-
- buf2 = LPC_CANAF_RAM->mask[cnt1+2];
-
- LPC_CANAF_RAM->mask[cnt1]=LPC_CANAF_RAM->mask[cnt1+1]= LPC_CANAF_RAM->mask[cnt1+2]=0x00;
-
- cnt1+=3;
-
- while(bound1--)
- {
- tmp0 = LPC_CANAF_RAM->mask[cnt1];
-
- tmp1 = LPC_CANAF_RAM->mask[cnt1+1];
-
- tmp2 = LPC_CANAF_RAM->mask[cnt1+2];
-
- LPC_CANAF_RAM->mask[cnt1]= buf0;
-
- LPC_CANAF_RAM->mask[cnt1+1]= buf1;
-
- LPC_CANAF_RAM->mask[cnt1+2]= buf2;
-
- buf0 = tmp0;
-
- buf1 = tmp1;
-
- buf2 = tmp2;
-
- cnt1+=3;
- }
-
- CANAF_FullCAN_cnt++;
-
- //update address values
- LPC_CANAF->SFF_sa += 0x04;
-
- LPC_CANAF->SFF_GRP_sa += 0x04 ;
-
- LPC_CANAF->EFF_sa += 0x04 ;
-
- LPC_CANAF->EFF_GRP_sa += 0x04;
-
- LPC_CANAF->ENDofTable += 0x04;
-
- LPC_CANAF->AFMR = 0x04;
-
- return CAN_OK;
-}
-
-/********************************************************************//**
- * @brief Load Group entry into AFLUT
- * @param[in] canId The Id of the expected CAN component
- *
- * @param[in] lowerID, upperID: lower and upper identifier of entry
- * @param[in] format: type of ID format, should be:
- * - STD_ID_FORMAT: Standard ID format (11-bit value)
- * - EXT_ID_FORMAT: Extended ID format (29-bit value)
- * @return CAN_ERROR, could be:
- * - CAN_OK: loading is successful
- * - CAN_CONFLICT_ID_ERROR: Conflict ID occurs
- * - CAN_OBJECTS_FULL_ERROR: no more space available
- *********************************************************************/
-CAN_ERROR CAN_LoadGroupEntry(uint8_t canId, uint32_t lowerID,
- uint32_t upperID, CAN_ID_FORMAT_Type format)
-{
- uint32_t buf0, buf1, entry1, entry2, LID,UID;
- int16_t cnt1, bound1, total;
-
- if(lowerID > upperID)
- return CAN_CONFLICT_ID_ERROR;
-
- total =((CANAF_FullCAN_cnt+1) >> 1)+ CANAF_FullCAN_cnt*3 +((CANAF_std_cnt + 1) >> 1) \
- + CANAF_gstd_cnt + CANAF_ext_cnt + (CANAF_gext_cnt<<1);
-
- /* Setup Acceptance Filter Configuration
- Acceptance Filter Mode Register = Off */
- LPC_CANAF->AFMR = 0x00000001;
-
- /*********Add Group of Standard Identifier Frame Format************/
- if(format == STD_ID_FORMAT)
- {
- if ((total >= 512))
- {
- //don't have enough space
- return CAN_OBJECTS_FULL_ERROR;
- }
-
- lowerID &=0x7FF; //mask ID
-
- upperID &=0x7FF;
-
- entry1 = (canId << 29) | (lowerID << 16) | (canId << 13)|(upperID << 0);
-
- cnt1 = ((CANAF_FullCAN_cnt+1)>>1) + ((CANAF_std_cnt + 1) >> 1);
-
- //if this is the first Group standard ID entry
- if(CANAF_gstd_cnt == 0)
- {
- LPC_CANAF_RAM->mask[cnt1] = entry1;
- }
- else
- {
- //find the position to add new Group entry
- bound1 = ((CANAF_FullCAN_cnt+1)>>1) + ((CANAF_std_cnt + 1) >> 1) + CANAF_gstd_cnt;
-
- while(cnt1 < bound1)
- {
- //compare controller first
- while((LPC_CANAF_RAM->mask[cnt1] >> 29)< (entry1 >> 29))//increase until meet greater or equal controller
- cnt1++;
- buf0 = LPC_CANAF_RAM->mask[cnt1];
- if((LPC_CANAF_RAM->mask[cnt1] >> 29)> (entry1 >> 29)) //meet greater controller
- {
- //add at this position
- LPC_CANAF_RAM->mask[cnt1] = entry1;
- break;
- }
- else //meet equal controller
- {
- LID = (buf0 >> 16)&0x7FF;
- UID = buf0 & 0x7FF;
- if (upperID <= LID)
- {
- //add new entry before this entry
- LPC_CANAF_RAM->mask[cnt1] = entry1;
- break;
- }
- else if (lowerID >= UID)
- {
- //load next entry to compare
- cnt1 ++;
- }
- else
- return CAN_CONFLICT_ID_ERROR;
- }
- }
- if(cnt1 >= bound1)
- {
- //add new entry at the last position in this list
- buf0 = LPC_CANAF_RAM->mask[cnt1];
-
- LPC_CANAF_RAM->mask[cnt1] = entry1;
- }
-
- //remove all remaining entry of this section one place up
- bound1 = total - cnt1;
-
- while(bound1--)
- {
- cnt1++;
-
- buf1 = LPC_CANAF_RAM->mask[cnt1];
-
- LPC_CANAF_RAM->mask[cnt1] = buf0;
-
- buf0 = buf1;
- }
- }
-
- CANAF_gstd_cnt++;
-
- //update address values
- LPC_CANAF->EFF_sa +=0x04 ;
-
- LPC_CANAF->EFF_GRP_sa +=0x04;
-
- LPC_CANAF->ENDofTable +=0x04;
- }
-
-
- /*********Add Group of Extended Identifier Frame Format************/
- else
- {
- if ((total >= 511))
- {
- //don't have enough space
- return CAN_OBJECTS_FULL_ERROR;
- }
-
- lowerID &= 0x1FFFFFFF; //mask ID
-
- upperID &= 0x1FFFFFFF;
-
- entry1 = (canId << 29)|(lowerID << 0);
-
- entry2 = (canId << 29)|(upperID << 0);
-
- cnt1 = ((CANAF_FullCAN_cnt+1)>>1) + ((CANAF_std_cnt + 1) >> 1) + CANAF_gstd_cnt + CANAF_ext_cnt;
-
- //if this is the first Group standard ID entry
- if(CANAF_gext_cnt == 0)
- {
- LPC_CANAF_RAM->mask[cnt1] = entry1;
-
- LPC_CANAF_RAM->mask[cnt1+1] = entry2;
- }
- else
- {
- //find the position to add new Group entry
- bound1 = ((CANAF_FullCAN_cnt+1)>>1) + ((CANAF_std_cnt + 1) >> 1) + CANAF_gstd_cnt \
- + CANAF_ext_cnt + (CANAF_gext_cnt<<1);
-
- while(cnt1 < bound1)
- {
- while((LPC_CANAF_RAM->mask[cnt1] >>29)< canId) //increase until meet greater or equal controller
- cnt1++;
- buf0 = LPC_CANAF_RAM->mask[cnt1];
-
- buf1 = LPC_CANAF_RAM->mask[cnt1+1];
- if((LPC_CANAF_RAM->mask[cnt1] >> 29)> canId) //meet greater controller
- {
- //add at this position
- LPC_CANAF_RAM->mask[cnt1] = entry1;
- LPC_CANAF_RAM->mask[++cnt1] = entry2;
- break;
- }
- else //meet equal controller
- {
- LID = buf0 & 0x1FFFFFFF; //mask ID
- UID = buf1 & 0x1FFFFFFF;
- if (upperID <= LID)
- {
- //add new entry before this entry
- LPC_CANAF_RAM->mask[cnt1] = entry1;
- LPC_CANAF_RAM->mask[++cnt1] = entry2;
- break;
- }
- else if (lowerID >= UID)
- {
- //load next entry to compare
- cnt1 +=2;
- }
- else
- return CAN_CONFLICT_ID_ERROR;
- }
- }
- if(cnt1 >= bound1)
- {
- //add new entry at the last position in this list
- buf0 = LPC_CANAF_RAM->mask[cnt1];
-
- buf1 = LPC_CANAF_RAM->mask[cnt1+1];
-
- LPC_CANAF_RAM->mask[cnt1] = entry1;
-
- LPC_CANAF_RAM->mask[++cnt1] = entry2;
- }
-
- //remove all remaining entry of this section two place up
- bound1 = total - cnt1 + 1;
-
- cnt1++;
-
- while(bound1>0)
- {
- entry1 = LPC_CANAF_RAM->mask[cnt1];
-
- entry2 = LPC_CANAF_RAM->mask[cnt1+1];
-
- LPC_CANAF_RAM->mask[cnt1] = buf0;
-
- LPC_CANAF_RAM->mask[cnt1+1] = buf1;
-
- buf0 = entry1;
-
- buf1 = entry2;
-
- cnt1 +=2;
-
- bound1 -=2;
- }
- }
-
- CANAF_gext_cnt++;
-
- //update address values
- LPC_CANAF->ENDofTable +=0x08;
- }
-
- LPC_CANAF->AFMR = 0x04;
-
- return CAN_OK;
-}
-
-/********************************************************************//**
- * @brief Remove AFLUT entry (FullCAN entry and Explicit Standard entry)
- * @param[in] EntryType: the type of entry that want to remove, should be:
- * - FULLCAN_ENTRY
- * - EXPLICIT_STANDARD_ENTRY
- * - GROUP_STANDARD_ENTRY
- * - EXPLICIT_EXTEND_ENTRY
- * - GROUP_EXTEND_ENTRY
- * @param[in] position: the position of this entry in its section
- * Note: the first position is 0
- * @return CAN_ERROR, could be:
- * - CAN_OK: removing is successful
- * - CAN_ENTRY_NOT_EXIT_ERROR: entry want to remove is not exit
- *********************************************************************/
-CAN_ERROR CAN_RemoveEntry(AFLUT_ENTRY_Type EntryType, uint16_t position)
-{
- uint16_t cnt, bound, total;
- uint32_t buf0, buf1;
-
- /* Setup Acceptance Filter Configuration
- Acceptance Filter Mode Register = Off */
- LPC_CANAF->AFMR = 0x00000001;
-
- total = ((CANAF_FullCAN_cnt + 1) >> 1) + ((CANAF_std_cnt + 1) >> 1) + \
- + CANAF_gstd_cnt + CANAF_ext_cnt + (CANAF_gext_cnt << 1);
-
-
- /************** Remove FullCAN Entry *************/
- if(EntryType == FULLCAN_ENTRY)
- {
- if((CANAF_FullCAN_cnt == 0)||(position >= CANAF_FullCAN_cnt))
- {
- return CAN_ENTRY_NOT_EXIT_ERROR;
- }
- else
- {
- cnt = position >> 1;
-
- buf0 = LPC_CANAF_RAM->mask[cnt];
-
- bound = (CANAF_FullCAN_cnt - position -1)>>1;
-
- if((position & 0x0001) == 0) //event position
- {
- while(bound--)
- {
- //remove all remaining FullCAN entry one place down
- buf1 = LPC_CANAF_RAM->mask[cnt+1];
-
- LPC_CANAF_RAM->mask[cnt] = (buf1 >> 16) | (buf0 << 16);
-
- buf0 = buf1;
-
- cnt++;
- }
- }
- else //odd position
- {
- while(bound--)
- {
- //remove all remaining FullCAN entry one place down
- buf1 = LPC_CANAF_RAM->mask[cnt+1];
-
- LPC_CANAF_RAM->mask[cnt] = (buf0 & 0xFFFF0000)|(buf1 >> 16);
-
- LPC_CANAF_RAM->mask[cnt+1] = LPC_CANAF_RAM->mask[cnt+1] << 16;
-
- buf0 = buf1<<16;
-
- cnt++;
- }
- }
- if((CANAF_FullCAN_cnt & 0x0001) == 0)
- {
- if((position & 0x0001)==0)
- LPC_CANAF_RAM->mask[cnt] = (buf0 << 16) | (0x0000FFFF);
- else
- LPC_CANAF_RAM->mask[cnt] = buf0 | 0x0000FFFF;
- }
- else
- {
- //remove all remaining section one place down
- cnt = (CANAF_FullCAN_cnt + 1)>>1;
-
- bound = total + CANAF_FullCAN_cnt * 3;
-
- while(bound>cnt)
- {
- LPC_CANAF_RAM->mask[cnt-1] = LPC_CANAF_RAM->mask[cnt];
- cnt++;
- }
-
- LPC_CANAF_RAM->mask[cnt-1]=0x00;
-
- //update address values
- LPC_CANAF->SFF_sa -= 0x04;
-
- LPC_CANAF->SFF_GRP_sa -= 0x04 ;
-
- LPC_CANAF->EFF_sa -= 0x04 ;
-
- LPC_CANAF->EFF_GRP_sa -= 0x04;
-
- LPC_CANAF->ENDofTable -= 0x04;
- }
-
- CANAF_FullCAN_cnt--;
-
- //delete its FullCAN Object in the FullCAN Object section
- //remove all remaining FullCAN Object three place down
- cnt = total + position * 3;
-
- bound = (CANAF_FullCAN_cnt - position + 1) * 3;
-
- while(bound)
- {
- LPC_CANAF_RAM->mask[cnt]= LPC_CANAF_RAM->mask[cnt+3];;
-
- LPC_CANAF_RAM->mask[cnt+1]= LPC_CANAF_RAM->mask[cnt+4];
-
- LPC_CANAF_RAM->mask[cnt+2]= LPC_CANAF_RAM->mask[cnt+5];
-
- bound -= 3;
-
- cnt += 3;
- }
- }
- }
-
- /************** Remove Explicit Standard ID Entry *************/
- else if(EntryType == EXPLICIT_STANDARD_ENTRY)
- {
- if((CANAF_std_cnt == 0)||(position >= CANAF_std_cnt))
- {
- return CAN_ENTRY_NOT_EXIT_ERROR;
- }
- else
- {
- cnt = ((CANAF_FullCAN_cnt+1) >> 1) + (position >> 1);
-
- buf0 = LPC_CANAF_RAM->mask[cnt];
-
- bound = (CANAF_std_cnt - position - 1) >> 1;
-
- if((position & 0x0001) == 0) //event position
- {
- while(bound--)
- {
- //remove all remaining FullCAN entry one place down
- buf1 = LPC_CANAF_RAM->mask[cnt + 1];
-
- LPC_CANAF_RAM->mask[cnt] = (buf1 >> 16) | (buf0 << 16);
-
- buf0 = buf1;
-
- cnt++;
- }
- }
- else //odd position
- {
- while(bound--)
- {
- //remove all remaining FullCAN entry one place down
- buf1 = LPC_CANAF_RAM->mask[cnt + 1];
-
- LPC_CANAF_RAM->mask[cnt] = (buf0 & 0xFFFF0000) | (buf1 >> 16);
-
- LPC_CANAF_RAM->mask[cnt + 1] = LPC_CANAF_RAM->mask[cnt + 1] << 16;
-
- buf0 = buf1<<16;
-
- cnt++;
- }
- }
- if((CANAF_std_cnt & 0x0001) == 0)
- {
- if((position & 0x0001)==0)
- LPC_CANAF_RAM->mask[cnt] = (buf0 << 16) | (0x0000FFFF);
- else
- LPC_CANAF_RAM->mask[cnt] = buf0 | 0x0000FFFF;
- }
- else
- {
- //remove all remaining section one place down
- cnt = ((CANAF_FullCAN_cnt + 1)>>1) + ((CANAF_std_cnt + 1) >> 1);
-
- bound = total + CANAF_FullCAN_cnt * 3;
-
- while(bound>cnt)
- {
- LPC_CANAF_RAM->mask[cnt-1] = LPC_CANAF_RAM->mask[cnt];
- cnt++;
- }
-
- LPC_CANAF_RAM->mask[cnt-1]=0x00;
-
- //update address value
- LPC_CANAF->SFF_GRP_sa -= 0x04 ;
-
- LPC_CANAF->EFF_sa -= 0x04 ;
-
- LPC_CANAF->EFF_GRP_sa -= 0x04;
-
- LPC_CANAF->ENDofTable -= 0x04;
- }
-
- CANAF_std_cnt--;
- }
- }
-
- /************** Remove Group of Standard ID Entry *************/
- else if(EntryType == GROUP_STANDARD_ENTRY)
- {
- if((CANAF_gstd_cnt == 0)||(position >= CANAF_gstd_cnt))
- {
- return CAN_ENTRY_NOT_EXIT_ERROR;
- }
- else
- {
- cnt = ((CANAF_FullCAN_cnt + 1) >> 1) + ((CANAF_std_cnt + 1) >> 1)+ position + 1;
-
- bound = total + CANAF_FullCAN_cnt * 3;
-
- while (cnt < bound)
- {
- LPC_CANAF_RAM->mask[cnt - 1] = LPC_CANAF_RAM->mask[cnt];
- cnt++;
- }
- LPC_CANAF_RAM->mask[cnt - 1]=0x00;
- }
-
- CANAF_gstd_cnt--;
-
- //update address value
- LPC_CANAF->EFF_sa -= 0x04;
-
- LPC_CANAF->EFF_GRP_sa -= 0x04;
-
- LPC_CANAF->ENDofTable -= 0x04;
- }
-
- /************** Remove Explicit Extended ID Entry *************/
- else if(EntryType == EXPLICIT_EXTEND_ENTRY)
- {
- if((CANAF_ext_cnt == 0)||(position >= CANAF_ext_cnt))
- {
- return CAN_ENTRY_NOT_EXIT_ERROR;
- }
- else
- {
- cnt = ((CANAF_FullCAN_cnt + 1) >> 1) + ((CANAF_std_cnt + 1) >> 1)+ CANAF_gstd_cnt + position + 1;
-
- bound = total + CANAF_FullCAN_cnt * 3;
-
- while (cnt<bound)
- {
- LPC_CANAF_RAM->mask[cnt - 1] = LPC_CANAF_RAM->mask[cnt];
- cnt++;
- }
- LPC_CANAF_RAM->mask[cnt - 1]=0x00;
- }
-
- CANAF_ext_cnt--;
-
- LPC_CANAF->EFF_GRP_sa -= 0x04;
-
- LPC_CANAF->ENDofTable -= 0x04;
- }
-
- /************** Remove Group of Extended ID Entry *************/
- else
- {
- if((CANAF_gext_cnt == 0)||(position >= CANAF_gext_cnt))
- {
- return CAN_ENTRY_NOT_EXIT_ERROR;
- }
- else
- {
- cnt = total - (CANAF_gext_cnt << 1) + (position << 1);
-
- bound = total + CANAF_FullCAN_cnt * 3;
-
- while (cnt<bound)
- {
- //remove all remaining entry two place up
- LPC_CANAF_RAM->mask[cnt] = LPC_CANAF_RAM->mask[cnt + 2];
-
- LPC_CANAF_RAM->mask[cnt + 1] = LPC_CANAF_RAM->mask[cnt + 3];
-
- cnt += 2;
- }
- }
-
- CANAF_gext_cnt--;
-
- LPC_CANAF->ENDofTable -= 0x08;
- }
-
- LPC_CANAF->AFMR = 0x04;
-
- return CAN_OK;
-}
-
-/********************************************************************//**
- * @brief Send message data
- * @param[in] canId The Id of the expected CAN component
- *
- * @param[in] CAN_Msg point to the CAN_MSG_Type Structure, it contains message
- * information such as: ID, DLC, RTR, ID Format
- * @return Status:
- * - SUCCESS: send message successfully
- * - ERROR: send message unsuccessfully
- *********************************************************************/
-Status CAN_SendMsg (uint8_t canId, CAN_MSG_Type *CAN_Msg)
-{
- LPC_CAN_TypeDef* pCan = CAN_GetPointer(canId);
-
- uint32_t data;
-
- //Check status of Transmit Buffer 1
- if (pCan->SR & (1 << 2))
- {
- /* Transmit Channel 1 is available */
- /* Write frame informations and frame data into its CANxTFI1,
- * CANxTID1, CANxTDA1, CANxTDB1 register */
- pCan->TFI1 &= ~ 0x000F0000;
-
- pCan->TFI1 |= (CAN_Msg->len) << 16;
-
- if(CAN_Msg->type == REMOTE_FRAME)
- {
- pCan->TFI1 |= (1 << 30); //set bit RTR
- }
- else
- {
- pCan->TFI1 &= ~(1 << 30);
- }
-
- if(CAN_Msg->format == EXT_ID_FORMAT)
- {
- pCan->TFI1 |= (((uint32_t)1) << 31); //set bit FF
- }
- else
- {
- pCan->TFI1 &= ~(((uint32_t)1) << 31);
- }
-
- /* Write CAN ID*/
- pCan->TID1 = CAN_Msg->id;
-
- /*Write first 4 data bytes*/
- data = (CAN_Msg->dataA[0]) | (((CAN_Msg->dataA[1]))<< 8) | ((CAN_Msg->dataA[2]) << 16) | ((CAN_Msg->dataA[3]) << 24);
-
- pCan->TDA1 = data;
-
- /*Write second 4 data bytes*/
- data = (CAN_Msg->dataB[0]) | (((CAN_Msg->dataB[1])) << 8)|((CAN_Msg->dataB[2]) << 16)|((CAN_Msg->dataB[3]) << 24);
-
- pCan->TDB1 = data;
-
- /*Write transmission request*/
- pCan->CMR = 0x21;
-
- return SUCCESS;
- }
-
- //check status of Transmit Buffer 2
- else if((pCan->SR) & (1 << 10))
- {
- /* Transmit Channel 2 is available */
- /* Write frame informations and frame data into its CANxTFI2,
- * CANxTID2, CANxTDA2, CANxTDB2 register */
- pCan->TFI2 &= ~0x000F0000;
-
- pCan->TFI2 |= (CAN_Msg->len) << 16;
-
- if(CAN_Msg->type == REMOTE_FRAME)
- {
- pCan->TFI2 |= (1 << 30); //set bit RTR
- }
- else
- {
- pCan->TFI2 &= ~(1 << 30);
- }
-
- if(CAN_Msg->format == EXT_ID_FORMAT)
- {
- pCan->TFI2 |= (((uint32_t)1) << 31); //set bit FF
- }
- else
- {
- pCan->TFI2 &= ~(((uint32_t)1) << 31);
- }
-
- /* Write CAN ID*/
- pCan->TID2 = CAN_Msg->id;
-
- /*Write first 4 data bytes*/
- data = (CAN_Msg->dataA[0]) | (((CAN_Msg->dataA[1])) << 8) | ((CAN_Msg->dataA[2]) << 16)|((CAN_Msg->dataA[3]) << 24);
-
- pCan->TDA2 = data;
-
- /*Write second 4 data bytes*/
- data = (CAN_Msg->dataB[0]) | (((CAN_Msg->dataB[1])) << 8) | ((CAN_Msg->dataB[2]) << 16) | ((CAN_Msg->dataB[3]) << 24);
-
- pCan->TDB2 = data;
-
- /*Write transmission request*/
- pCan->CMR = 0x41;
-
- return SUCCESS;
- }
-
- //check status of Transmit Buffer 3
- else if (pCan->SR & (1<<18))
- {
- /* Transmit Channel 3 is available */
- /* Write frame informations and frame data into its CANxTFI3,
- * CANxTID3, CANxTDA3, CANxTDB3 register */
- pCan->TFI3 &= ~0x000F0000;
-
- pCan->TFI3 |= (CAN_Msg->len) << 16;
-
- if(CAN_Msg->type == REMOTE_FRAME)
- {
- pCan->TFI3 |= (1 << 30); //set bit RTR
- }
- else
- {
- pCan->TFI3 &= ~(1 << 30);
- }
-
- if(CAN_Msg->format == EXT_ID_FORMAT)
- {
- pCan->TFI3 |= (((uint32_t)1) << 31); //set bit FF
- }
- else
- {
- pCan->TFI3 &= ~(((uint32_t)1) << 31);
- }
-
- /* Write CAN ID*/
- pCan->TID3 = CAN_Msg->id;
-
- /*Write first 4 data bytes*/
- data = (CAN_Msg->dataA[0]) | (((CAN_Msg->dataA[1])) << 8) | ((CAN_Msg->dataA[2]) << 16) | ((CAN_Msg->dataA[3]) << 24);
-
- pCan->TDA3 = data;
-
- /*Write second 4 data bytes*/
- data = (CAN_Msg->dataB[0]) | (((CAN_Msg->dataB[1])) << 8) | ((CAN_Msg->dataB[2]) << 16) | ((CAN_Msg->dataB[3]) << 24);
-
- pCan->TDB3 = data;
-
- /*Write transmission request*/
- pCan->CMR = 0x81;
-
- return SUCCESS;
- }
- else
- {
- return ERROR;
- }
-}
-
-/********************************************************************//**
- * @brief Receive message data
- * @param[in] canId The Id of the expected CAN component
- *
- * @param[in] CAN_Msg point to the CAN_MSG_Type Struct, it will contain received
- * message information such as: ID, DLC, RTR, ID Format
- * @return Status:
- * - SUCCESS: receive message successfully
- * - ERROR: receive message unsuccessfully
- *********************************************************************/
-Status CAN_ReceiveMsg (uint8_t canId, CAN_MSG_Type *CAN_Msg)
-{
- LPC_CAN_TypeDef* pCan = CAN_GetPointer(canId);
-
- uint32_t data;
-
- //check status of Receive Buffer
- if((pCan->SR &0x00000001))
- {
- /* Receive message is available */
- /* Read frame informations */
- CAN_Msg->format = (uint8_t)(((pCan->RFS) & 0x80000000) >> 31);
-
- CAN_Msg->type = (uint8_t)(((pCan->RFS) & 0x40000000) >> 30);
-
- CAN_Msg->len = (uint8_t)(((pCan->RFS) & 0x000F0000) >> 16);
-
- /* Read CAN message identifier */
- CAN_Msg->id = pCan->RID;
-
- /* Read the data if received message was DATA FRAME */
- if (CAN_Msg->type == DATA_FRAME)
- {
- /* Read first 4 data bytes */
- data = pCan->RDA;
-
- *((uint8_t *) &CAN_Msg->dataA[0])= data & 0x000000FF;
-
- *((uint8_t *) &CAN_Msg->dataA[1])= (data & 0x0000FF00) >> 8;;
-
- *((uint8_t *) &CAN_Msg->dataA[2])= (data & 0x00FF0000) >> 16;
-
- *((uint8_t *) &CAN_Msg->dataA[3])= (data & 0xFF000000) >> 24;
-
- /* Read second 4 data bytes */
- data = pCan->RDB;
-
- *((uint8_t *) &CAN_Msg->dataB[0])= data & 0x000000FF;
-
- *((uint8_t *) &CAN_Msg->dataB[1])= (data & 0x0000FF00) >> 8;
-
- *((uint8_t *) &CAN_Msg->dataB[2])= (data & 0x00FF0000) >> 16;
-
- *((uint8_t *) &CAN_Msg->dataB[3])= (data & 0xFF000000) >> 24;
-
- /*release receive buffer*/
- pCan->CMR = 0x04;
- }
- else
- {
- /* Received Frame is a Remote Frame, not have data, we just receive
- * message information only */
- pCan->CMR = 0x04; /*release receive buffer*/
-
- return SUCCESS;
- }
- }
- else
- {
- // no receive message available
- return ERROR;
- }
-
- return SUCCESS;
-}
-
-/********************************************************************//**
- * @brief Receive FullCAN Object
- * @param[in] CANAFx: CAN Acceptance Filter register, should be: LPC_CANAF
- * @param[in] CAN_Msg point to the CAN_MSG_Type Struct, it will contain received
- * message information such as: ID, DLC, RTR, ID Format
- * @return CAN_ERROR, could be:
- * - CAN_FULL_OBJ_NOT_RCV: FullCAN Object is not be received
- * - CAN_OK: Received FullCAN Object successful
- *
- *********************************************************************/
-CAN_ERROR FCAN_ReadObj (CAN_MSG_Type *CAN_Msg)
-{
- uint32_t *pSrc, data;
- uint32_t interrut_word, msg_idx, test_bit, head_idx, tail_idx;
-
- interrut_word = 0;
-
- if (LPC_CANAF->FCANIC0 != 0)
- {
- interrut_word = LPC_CANAF->FCANIC0;
-
- head_idx = 0;
-
- tail_idx = 31;
- }
- else if (LPC_CANAF->FCANIC1 != 0)
- {
- interrut_word = LPC_CANAF->FCANIC1;
-
- head_idx = 32;
-
- tail_idx = 63;
- }
-
- if (interrut_word != 0)
- {
- /* Detect for interrupt pending */
- msg_idx = 0;
-
- for (msg_idx = head_idx; msg_idx <= tail_idx; msg_idx++)
- {
- test_bit = interrut_word & 0x1;
-
- interrut_word = interrut_word >> 1;
-
- if (test_bit)
- {
- pSrc = (uint32_t *) (LPC_CANAF->ENDofTable + LPC_CANAF_RAM_BASE + msg_idx * 12);
-
- /* Has been finished updating the content */
- if ((*pSrc & 0x03000000L) == 0x03000000L)
- {
- /*clear semaphore*/
- *pSrc &= 0xFCFFFFFF;
-
- /*Set to DatA*/
- pSrc++;
-
- /* Copy to dest buf */
- data = *pSrc;
-
- *((uint8_t *) &CAN_Msg->dataA[0])= data & 0x000000FF;
-
- *((uint8_t *) &CAN_Msg->dataA[1])= (data & 0x0000FF00) >> 8;
-
- *((uint8_t *) &CAN_Msg->dataA[2])= (data & 0x00FF0000) >> 16;
-
- *((uint8_t *) &CAN_Msg->dataA[3])= (data & 0xFF000000) >> 24;
-
- /*Set to DatB*/
- pSrc++;
-
- /* Copy to dest buf */
- data = *pSrc;
-
- *((uint8_t *) &CAN_Msg->dataB[0])= data & 0x000000FF;
-
- *((uint8_t *) &CAN_Msg->dataB[1])= (data & 0x0000FF00) >> 8;
-
- *((uint8_t *) &CAN_Msg->dataB[2])= (data & 0x00FF0000) >> 16;
-
- *((uint8_t *) &CAN_Msg->dataB[3])= (data & 0xFF000000) >> 24;
-
- /*Back to Dat1*/
- pSrc -= 2;
-
- CAN_Msg->id = *pSrc & 0x7FF;
-
- CAN_Msg->len = (uint8_t) (*pSrc >> 16) & 0x0F;
-
- CAN_Msg->format = 0; //FullCAN Object ID always is 11-bit value
-
- CAN_Msg->type = (uint8_t)(*pSrc >> 30) &0x01;
-
- /*Re-read semaphore*/
- if ((*pSrc & 0x03000000L) == 0)
- {
- return CAN_OK;
- }
- }
- }
- }
- }
-
- return CAN_FULL_OBJ_NOT_RCV;
-}
-
-/********************************************************************//**
- * @brief Get CAN Control Status
- * @param[in] canId The Id of the expected CAN component
- *
- * @param[in] arg: type of CAN status to get from CAN status register
- * Should be:
- * - CANCTRL_GLOBAL_STS: CAN Global Status
- * - CANCTRL_INT_CAP: CAN Interrupt and Capture
- * - CANCTRL_ERR_WRN: CAN Error Warning Limit
- * - CANCTRL_STS: CAN Control Status
- * @return Current Control Status that you want to get value
- *********************************************************************/
-uint32_t CAN_GetCTRLStatus (uint8_t canId, CAN_CTRL_STS_Type arg)
-{
- LPC_CAN_TypeDef* pCan = CAN_GetPointer(canId);
-
- switch (arg)
- {
- case CANCTRL_GLOBAL_STS:
- return pCan->GSR;
-
- case CANCTRL_INT_CAP:
- return pCan->ICR;
-
- case CANCTRL_ERR_WRN:
- return pCan->EWL;
-
- default: // CANCTRL_STS
- return pCan->SR;
- }
-}
-/********************************************************************//**
- * @brief Get CAN Central Status
- * @param[in] CANCRx point to LPC_CANCR_TypeDef, should be: LPC_CANCR
- * @param[in] arg: type of CAN status to get from CAN Central status register
- * Should be:
- * - CANCR_TX_STS: Central CAN Tx Status
- * - CANCR_RX_STS: Central CAN Rx Status
- * - CANCR_MS: Central CAN Miscellaneous Status
- * @return Current Central Status that you want to get value
- *********************************************************************/
-uint32_t CAN_GetCRStatus (CAN_CR_STS_Type arg)
-{
- switch (arg)
- {
- case CANCR_TX_STS:
- return LPC_CANCR->TxSR;
-
- case CANCR_RX_STS:
- return LPC_CANCR->RxSR;
-
- default: // CANCR_MS
- return LPC_CANCR->MSR;
- }
-}
-/********************************************************************//**
- * @brief Enable/Disable CAN Interrupt
- * @param[in] canId The Id of the expected CAN component
- *
- * @param[in] arg: type of CAN interrupt that you want to enable/disable
- * Should be:
- * - CANINT_RIE: CAN Receiver Interrupt Enable
- * - CANINT_TIE1: CAN Transmit Interrupt Enable
- * - CANINT_EIE: CAN Error Warning Interrupt Enable
- * - CANINT_DOIE: CAN Data Overrun Interrupt Enable
- * - CANINT_WUIE: CAN Wake-Up Interrupt Enable
- * - CANINT_EPIE: CAN Error Passive Interrupt Enable
- * - CANINT_ALIE: CAN Arbitration Lost Interrupt Enable
- * - CANINT_BEIE: CAN Bus Error Interrupt Enable
- * - CANINT_IDIE: CAN ID Ready Interrupt Enable
- * - CANINT_TIE2: CAN Transmit Interrupt Enable for Buffer2
- * - CANINT_TIE3: CAN Transmit Interrupt Enable for Buffer3
- * - CANINT_FCE: FullCAN Interrupt Enable
- * @param[in] NewState: New state of this function, should be:
- * - ENABLE
- * - DISABLE
- * @return none
- *********************************************************************/
-void CAN_IRQCmd (uint8_t canId, CAN_INT_EN_Type arg, FunctionalState NewState)
-{
- LPC_CAN_TypeDef* pCan = CAN_GetPointer(canId);
-
- if(NewState == ENABLE)
- {
- if(arg == CANINT_FCE)
- {
- LPC_CANAF->AFMR = 0x01;
-
- LPC_CANAF->FCANIE = 0x01;
-
- LPC_CANAF->AFMR = 0x04;
- }
- else
- pCan->IER |= (1 << arg);
- }
- else
- {
- if(arg == CANINT_FCE)
- {
- LPC_CANAF->AFMR = 0x01;
-
- LPC_CANAF->FCANIE = 0x01;
-
- LPC_CANAF->AFMR = 0x00;
- }
- else
- pCan->IER &= ~(1 << arg);
- }
-}
-
-/********************************************************************//**
- * @brief Setting Acceptance Filter mode
- * @param[in] CANAFx point to LPC_CANAF_TypeDef object, should be: LPC_CANAF
- * @param[in] AFMode: type of AF mode that you want to set, should be:
- * - CAN_NORMAL: Normal mode
- * - CAN_ACC_OFF: Acceptance Filter Off Mode
- * - CAN_ACC_BP: Acceptance Fileter Bypass Mode
- * - CAN_EFCAN: FullCAN Mode Enhancement
- * @return none
- *********************************************************************/
-void CAN_SetAFMode (CAN_AFMODE_Type AFMode)
-{
- switch(AFMode)
- {
- case CAN_NORMAL:
- LPC_CANAF->AFMR = 0x00;
- break;
-
- case CAN_ACC_OFF:
- LPC_CANAF->AFMR = 0x01;
- break;
-
- case CAN_ACC_BP:
- LPC_CANAF->AFMR = 0x02;
- break;
-
- case CAN_EFCAN:
- LPC_CANAF->AFMR = 0x04;
- break;
- }
-}
-
-/********************************************************************//**
- * @brief Enable/Disable CAN Mode
- * @param[in] canId The Id of the expected CAN component
- *
- * @param[in] mode: type of CAN mode that you want to enable/disable, should be:
- * - CAN_OPERATING_MODE: Normal Operating Mode
- * - CAN_RESET_MODE: Reset Mode
- * - CAN_LISTENONLY_MODE: Listen Only Mode
- * - CAN_SELFTEST_MODE: Self Test Mode
- * - CAN_TXPRIORITY_MODE: Transmit Priority Mode
- * - CAN_SLEEP_MODE: Sleep Mode
- * - CAN_RXPOLARITY_MODE: Receive Polarity Mode
- * - CAN_TEST_MODE: Test Mode
- * @param[in] NewState: New State of this function, should be:
- * - ENABLE
- * - DISABLE
- * @return none
- *********************************************************************/
-void CAN_ModeConfig(uint8_t canId, CAN_MODE_Type mode, FunctionalState NewState)
-{
- LPC_CAN_TypeDef* pCan = CAN_GetPointer(canId);
-
- switch(mode)
- {
- case CAN_OPERATING_MODE:
- pCan->MOD = 0x00;
- break;
-
- case CAN_RESET_MODE:
- if(NewState == ENABLE)
- pCan->MOD |= CAN_MOD_RM;
- else
- pCan->MOD &= ~CAN_MOD_RM;
-
- break;
-
- case CAN_LISTENONLY_MODE:
- pCan->MOD |=CAN_MOD_RM;//Enter Reset mode
-
- if(NewState == ENABLE)
- pCan->MOD |= CAN_MOD_LOM;
- else
- pCan->MOD &= ~ CAN_MOD_LOM;
-
- pCan->MOD &= ~ CAN_MOD_RM;//Release Reset mode
-
- break;
-
- case CAN_SELFTEST_MODE:
- pCan->MOD |= CAN_MOD_RM;//Enter Reset mode
-
- if(NewState == ENABLE)
- pCan->MOD |= CAN_MOD_STM;
- else
- pCan->MOD &= ~ CAN_MOD_STM;
-
- pCan->MOD &= ~ CAN_MOD_RM;//Release Reset mode
-
- break;
-
- case CAN_TXPRIORITY_MODE:
- if(NewState == ENABLE)
- pCan->MOD |= CAN_MOD_TPM;
- else
- pCan->MOD &= ~ CAN_MOD_TPM;
-
- break;
-
- case CAN_SLEEP_MODE:
- if(NewState == ENABLE)
- pCan->MOD |= CAN_MOD_SM;
- else
- pCan->MOD &= ~ CAN_MOD_SM;
-
- break;
-
- case CAN_RXPOLARITY_MODE:
- if(NewState == ENABLE)
- pCan->MOD |= CAN_MOD_RPM;
- else
- pCan->MOD &= ~ CAN_MOD_RPM;
-
- break;
-
- case CAN_TEST_MODE:
- if(NewState == ENABLE)
- pCan->MOD |= CAN_MOD_TM;
- else
- pCan->MOD &= ~ CAN_MOD_TM;
-
- break;
- }
-}
-/*********************************************************************//**
- * @brief Set CAN command request
- * @param[in] canId The Id of the expected CAN component
- *
- * @param[in] CMRType command request type, should be:
- * - CAN_CMR_TR: Transmission request
- * - CAN_CMR_AT: Abort Transmission request
- * - CAN_CMR_RRB: Release Receive Buffer request
- * - CAN_CMR_CDO: Clear Data Overrun request
- * - CAN_CMR_SRR: Self Reception request
- * - CAN_CMR_STB1: Select Tx Buffer 1 request
- * - CAN_CMR_STB2: Select Tx Buffer 2 request
- * - CAN_CMR_STB3: Select Tx Buffer 3 request
- * @return CANICR (CAN interrupt and Capture register) value
- **********************************************************************/
-void CAN_SetCommand(uint8_t canId, uint32_t CMRType)
-{
- LPC_CAN_TypeDef* pCan = CAN_GetPointer(canId);
-
- pCan->CMR |= CMRType;
-}
-
-/*********************************************************************//**
- * @brief Get CAN interrupt status
- * @param[in] canId The Id of the expected CAN component
- *
- * @return CANICR (CAN interrupt and Capture register) value
- **********************************************************************/
-uint32_t CAN_IntGetStatus(uint8_t canId)
-{
- LPC_CAN_TypeDef* pCan = CAN_GetPointer(canId);
-
- return pCan->ICR;
-}
-
-/*********************************************************************//**
- * @brief Check if FullCAN interrupt enable or not
- * @param[in] CANAFx point to LPC_CANAF_TypeDef object, should be: LPC_CANAF
- * @return IntStatus, could be:
- * - SET: if FullCAN interrupt is enable
- * - RESET: if FullCAN interrupt is disable
- **********************************************************************/
-IntStatus CAN_FullCANIntGetStatus (void)
-{
- if (LPC_CANAF->FCANIE)
- return SET;
-
- return RESET;
-}
-
-/*********************************************************************//**
- * @brief Get value of FullCAN interrupt and capture register
- * @param[in] CANAFx point to LPC_CANAF_TypeDef object, should be: LPC_CANAF
- * @param[in] type: FullCAN IC type, should be:
- * - FULLCAN_IC0: FullCAN Interrupt Capture 0
- * - FULLCAN_IC1: FullCAN Interrupt Capture 1
- * @return FCANIC0 or FCANIC1 (FullCAN interrupt and Capture register) value
- **********************************************************************/
-uint32_t CAN_FullCANPendGetStatus(FullCAN_IC_Type type)
-{
- if (type == FULLCAN_IC0)
- return LPC_CANAF->FCANIC0;
-
- return LPC_CANAF->FCANIC1;
-}
-/* End of Public Variables ---------------------------------------------------------- */
-/**
- * @}
- */
-#endif /*_CAN*/
-
-/**
- * @}
- */
-
-/* --------------------------------- End Of File ------------------------------ */
diff --git a/bsp/lpc408x/Libraries/Drivers/source/lpc_clkpwr.c b/bsp/lpc408x/Libraries/Drivers/source/lpc_clkpwr.c
deleted file mode 100644
index fc41687637..0000000000
--- a/bsp/lpc408x/Libraries/Drivers/source/lpc_clkpwr.c
+++ /dev/null
@@ -1,326 +0,0 @@
-/**********************************************************************
-* $Id$ lpc_clkpwr.c 2011-06-02
-*//**
-* @file lpc_clkpwr.c
-* @brief Contains all functions support for Clock and Power Control
-* firmware library on LPC
-* @version 1.0
-* @date 02. June. 2011
-* @author NXP MCU SW Application Team
-*
-* Copyright(C) 2011, NXP Semiconductor
-* All rights reserved.
-*
-***********************************************************************
-* Software that is described herein is for illustrative purposes only
-* which provides customers with programming information regarding the
-* products. This software is supplied "AS IS" without any warranties.
-* NXP Semiconductors assumes no responsibility or liability for the
-* use of the software, conveys no license or title under any patent,
-* copyright, or mask work right to the product. NXP Semiconductors
-* reserves the right to make changes in the software without
-* notification. NXP Semiconductors also make 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'
-* relevant copyright 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.
-**********************************************************************/
-
-/* Peripheral group ----------------------------------------------------------- */
-/** @addtogroup CLKPWR
- * @{
- */
-#ifdef __BUILD_WITH_EXAMPLE__
-#include "lpc_libcfg.h"
-#else
-#include "lpc_libcfg_default.h"
-#endif /* __BUILD_WITH_EXAMPLE__ */
-#ifdef _CLKPWR
-
-/* Includes ------------------------------------------------------------------- */
-#include "lpc_clkpwr.h"
-
-uint32_t USBFrequency = 0;
-
-
-/* Public Functions ----------------------------------------------------------- */
-/** @addtogroup CLKPWR_Public_Functions
- * @{
- */
-
-/*********************************************************************//**
- * @brief Set value of each Peripheral Clock Selection
- * @param[in] ClkType clock type that will be divided, should be:
- * - CLKPWR_CLKTYPE_CPU : CPU clock
- * - CLKPWR_CLKTYPE_PER : Peripheral clock
- * - CLKPWR_CLKTYPE_EMC : EMC clock
- * - CLKPWR_CLKTYPE_USB : USB clock
- * @param[in] DivVal Value of divider. This value should be set as follows:
- * - CPU clock: DivVal must be in range: 0..31
- * - Peripheral clock: DivVal must be in range: 0..31
- * - EMC clock: DivVal must be:
- * + 0: The EMC uses the same clock as the CPU
- * + 1: The EMC uses a clock at half the rate of the CPU
- * - USB clock: DivVal must be:
- * + 0: the divider is turned off, no clock will
- * be provided to the USB subsystem
- * + 4: PLL0 output is divided by 4. PLL0 output must be 192MHz
- * + 6: PLL0 output is divided by 6. PLL0 output must be 288MHz
- * @return none
- * Note: Pls assign right DivVal, this function will not check if it is illegal.
- **********************************************************************/
-void CLKPWR_SetCLKDiv (uint8_t ClkType, uint8_t DivVal)
-{
- uint32_t tmp;
- switch(ClkType)
- {
- case CLKPWR_CLKTYPE_CPU:
- tmp = LPC_SC->CCLKSEL & ~(0x1F);
- tmp |= DivVal & 0x1F;
- LPC_SC->CCLKSEL = tmp;
- SystemCoreClockUpdate(); //Update clock
- break;
- case CLKPWR_CLKTYPE_PER:
- tmp = LPC_SC->PCLKSEL & ~(0x1F);
- tmp |= DivVal & 0x1F;
- LPC_SC->PCLKSEL = tmp;
- SystemCoreClockUpdate(); //Update clock
- break;
- case CLKPWR_CLKTYPE_EMC:
- tmp = LPC_SC->EMCCLKSEL & ~(0x01);
- tmp |= DivVal & 0x01;
- LPC_SC->EMCCLKSEL = tmp;
- SystemCoreClockUpdate(); //Update clock
- break;
- case CLKPWR_CLKTYPE_USB:
- tmp = LPC_SC->USBCLKSEL & ~(0x1F);
- tmp |= DivVal & 0x1F;
- LPC_SC->USBCLKSEL |= DivVal & 0x1F;
- SystemCoreClockUpdate(); //Update clock
- break;
- default:
- while(1);//Error Loop;
- }
-}
-
-/*********************************************************************//**
- * @brief Get current clock value
- * @param[in] ClkType clock type that will be divided, should be:
- * - CLKPWR_CLKTYPE_CPU : CPU clock
- * - CLKPWR_CLKTYPE_PER : Peripheral clock
- * - CLKPWR_CLKTYPE_EMC : EMC clock
- * - CLKPWR_CLKTYPE_USB : USB clock
- **********************************************************************/
-uint32_t CLKPWR_GetCLK (uint8_t ClkType)
-{
- switch(ClkType)
- {
- case CLKPWR_CLKTYPE_CPU:
- return SystemCoreClock;
-
- case CLKPWR_CLKTYPE_PER:
- return PeripheralClock;
-
- case CLKPWR_CLKTYPE_EMC:
- return EMCClock;
-
- case CLKPWR_CLKTYPE_USB:
- return USBClock;
-
- default:
- while(1);//error loop
- }
-}
-
-/*********************************************************************//**
- * @brief Configure power supply for each peripheral according to NewState
- * @param[in] PPType Type of peripheral used to enable power,
- * should be one of the following:
- * - CLKPWR_PCONP_PCLCD : LCD
- * - CLKPWR_PCONP_PCTIM0 : Timer 0
- * - CLKPWR_PCONP_PCTIM1 : Timer 1
- * - CLKPWR_PCONP_PCUART0 : UART 0
- * - CLKPWR_PCONP_PCUART1 : UART 1
- * - CLKPWR_PCONP_PCPWM0 : PWM 0
- * - CLKPWR_PCONP_PCPWM1 : PWM 1
- * - CLKPWR_PCONP_PCI2C0 : I2C 0
- * - CLKPWR_PCONP_PCUART4 : UART4
- * - CLKPWR_PCONP_PCLCD : LCD
- * - CLKPWR_PCONP_PCTIM0 : Timer 0
- * - CLKPWR_PCONP_PCRTC : RTC
- * - CLKPWR_PCONP_PCSSP1 : SSP 1
- * - CLKPWR_PCONP_PCEMC : EMC
- * - CLKPWR_PCONP_PCADC : ADC
- * - CLKPWR_PCONP_PCAN1 : CAN 1
- * - CLKPWR_PCONP_PCAN2 : CAN 2
- * - CLKPWR_PCONP_PCGPIO : GPIO
- * - CLKPWR_PCONP_PCMC : MCPWM
- * - CLKPWR_PCONP_PCQEI : QEI
- * - CLKPWR_PCONP_PCI2C1 : I2C 1
- * - CLKPWR_PCONP_PCSSP2 : SSP 2
- * - CLKPWR_PCONP_PCSSP0 : SSP 0
- * - CLKPWR_PCONP_PCTIM2 : Timer 2
- * - CLKPWR_PCONP_PCTIM3 : Timer 3
- * - CLKPWR_PCONP_PCUART2 : UART 2
- * - CLKPWR_PCONP_PCUART3 : UART 3
- * - CLKPWR_PCONP_PCI2C2 : I2C 2
- * - CLKPWR_PCONP_PCI2S : I2S
- * - CLKPWR_PCONP_PCSDC : SDC
- * - CLKPWR_PCONP_PCGPDMA : GPDMA
- * - CLKPWR_PCONP_PCENET : Ethernet
- * - CLKPWR_PCONP_PCUSB : USB
- *
- * @param[in] NewState New state of Peripheral Power, should be:
- * - ENABLE : Enable power for this peripheral
- * - DISABLE : Disable power for this peripheral
- *
- * @return none
- **********************************************************************/
-void CLKPWR_ConfigPPWR (uint32_t PPType, FunctionalState NewState)
-{
- if (NewState == ENABLE)
- {
- LPC_SC->PCONP |= PPType;
- }
- else if (NewState == DISABLE)
- {
- LPC_SC->PCONP &= ~PPType;
- }
-}
-
-#if 0
-// nxp21346
-/*********************************************************************//**
- * @brief Configure hardware reset for each peripheral according to NewState
- * @param[in] PPType Type of peripheral used to enable power,
- * should be one of the following:
- * - CLKPWR_RSTCON0_LCD : LCD
- * - CLKPWR_RSTCON0_TIM0 : Timer 0
- - CLKPWR_RSTCON0_TIM1 : Timer 1
- - CLKPWR_RSTCON0_UART0 : UART 0
- - CLKPWR_RSTCON0_UART1 : UART 1
- - CLKPWR_RSTCON0_PWM0 : PWM 0
- - CLKPWR_RSTCON0_PWM1 : PWM 1
- - CLKPWR_RSTCON0_I2C0 : I2C 0
- - CLKPWR_RSTCON0_UART4 : UART 4
- - CLKPWR_RSTCON0_RTC : RTC
- - CLKPWR_RSTCON0_SSP1 : SSP 1
- - CLKPWR_RSTCON0_EMC : EMC
- - CLKPWR_RSTCON0_ADC : ADC
- - CLKPWR_RSTCON0_CAN1 : CAN 1
- - CLKPWR_RSTCON0_CAN2 : CAN 2
- - CLKPWR_RSTCON0_GPIO : GPIO
- - CLKPWR_RSTCON0_MCPWM : MCPWM
- - CLKPWR_RSTCON0_QEI : QEI
- - CLKPWR_RSTCON0_I2C1 : I2C 1
- - CLKPWR_RSTCON0_SSP2 : SSP 2
- - CLKPWR_RSTCON0_SSP0 : SSP 0
- - CLKPWR_RSTCON0_TIM2 : Timer 2
- - CLKPWR_RSTCON0_TIM3 : Timer 3
- - CLKPWR_RSTCON0_UART2 : UART 2
- - CLKPWR_RSTCON0_UART3 : UART 3
- - CLKPWR_RSTCON0_I2C2 : I2C 2
- - CLKPWR_RSTCON0_I2S : I2S
- - CLKPWR_RSTCON0_SDC : SDC
- - CLKPWR_RSTCON0_GPDMA : GPDMA
- - CLKPWR_RSTCON0_ENET : Ethernet
- - CLKPWR_RSTCON0_USB : USB
- *
- * @param[in] NewState New state of Peripheral Power, should be:
- * - ENABLE : Enable power for this peripheral
- * - DISABLE : Disable power for this peripheral
- *
- * @return none
- **********************************************************************/
-void CLKPWR_ConfigReset(uint8_t PType, FunctionalState NewState)
-{
- if(PType < 32)
- {
- if(NewState == ENABLE)
- LPC_SC->RSTCON0 |=(1<<PType);
- else
- LPC_SC->RSTCON0 &=~(1<<PType);
- }
- else
- {
- if(NewState == ENABLE)
- LPC_SC->RSTCON1 |= (1<<(PType - 31));
- else
- LPC_SC->RSTCON1 &= ~(1<<(PType - 31));
- }
-}
-// nxp21346
-#endif
-
-/*********************************************************************//**
- * @brief Enter Sleep mode with co-operated instruction by the Cortex-M3.
- * @param[in] None
- * @return None
- **********************************************************************/
-void CLKPWR_Sleep(void)
-{
- LPC_SC->PCON = 0x00;
- /* Sleep Mode*/
- __WFI();
-}
-
-
-/*********************************************************************//**
- * @brief Enter Deep Sleep mode with co-operated instruction by the Cortex-M3.
- * @param[in] None
- * @return None
- **********************************************************************/
-void CLKPWR_DeepSleep(void)
-{
- /* Deep-Sleep Mode, set SLEEPDEEP bit */
- SCB->SCR = 0x4;
- LPC_SC->PCON = 0x00;
- /* Deep Sleep Mode*/
- __WFI();
-}
-
-
-/*********************************************************************//**
- * @brief Enter Power Down mode with co-operated instruction by the Cortex-M3.
- * @param[in] None
- * @return None
- **********************************************************************/
-void CLKPWR_PowerDown(void)
-{
- /* Deep-Sleep Mode, set SLEEPDEEP bit */
- SCB->SCR = 0x4;
- LPC_SC->PCON = 0x01;
- /* Power Down Mode*/
- __WFI();
-}
-
-
-/*********************************************************************//**
- * @brief Enter Deep Power Down mode with co-operated instruction by the Cortex-M3.
- * @param[in] None
- * @return None
- **********************************************************************/
-void CLKPWR_DeepPowerDown(void)
-{
- /* Deep-Sleep Mode, set SLEEPDEEP bit */
- SCB->SCR = 0x4;
- LPC_SC->PCON = 0x03;
- /* Deep Power Down Mode*/
- __WFI();
-}
-
-/**
- * @}
- */
-
-#endif /*_CLKPWR*/
-
-/**
- * @}
- */
-
-/* --------------------------------- End Of File ------------------------------ */
diff --git a/bsp/lpc408x/Libraries/Drivers/source/lpc_crc.c b/bsp/lpc408x/Libraries/Drivers/source/lpc_crc.c
deleted file mode 100644
index 8d74c052ea..0000000000
--- a/bsp/lpc408x/Libraries/Drivers/source/lpc_crc.c
+++ /dev/null
@@ -1,171 +0,0 @@
-/**********************************************************************
-* $Id$ lpc_crc.c 2011-06-02
-*//**
-* @file lpc_crc.c
-* @brief Contains all functions support for CRC firmware library on
-* LPC
-* @version 1.0
-* @date 02. June. 2011
-* @author NXP MCU SW Application Team
-*
-* Copyright(C) 2011, NXP Semiconductor
-* All rights reserved.
-*
-***********************************************************************
-* Software that is described herein is for illustrative purposes only
-* which provides customers with programming information regarding the
-* products. This software is supplied "AS IS" without any warranties.
-* NXP Semiconductors assumes no responsibility or liability for the
-* use of the software, conveys no license or title under any patent,
-* copyright, or mask work right to the product. NXP Semiconductors
-* reserves the right to make changes in the software without
-* notification. NXP Semiconductors also make 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'
-* relevant copyright 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.
-**********************************************************************/
-#ifdef __BUILD_WITH_EXAMPLE__
-#include "lpc_libcfg.h"
-#else
-#include "lpc_libcfg_default.h"
-#endif /* __BUILD_WITH_EXAMPLE__ */
-#ifdef _CRC
-
-/* Includes ------------------------------------------------------------------- */
-#include "lpc_crc.h"
-#include "lpc_clkpwr.h"
-
-/* Private Variables ----------------------------------------------------------- */
-volatile CRC_Type crc_cur_type;
-
-/* Public Functions ----------------------------------------------------------- */
-/** @addtogroup CRC_Public_Functions
- * @{
- */
-/*********************************************************************//**
- * @brief Initialize CRC operation
- * @param[in] CRCType CRC standard type, should be:
- * - CRC_POLY_CRCCCITT: CRC-CCITT polynomial
- * - CRC_POLY_CRC16: CRC-16 polynomial
- * - CRC_POLY_CRC32: CRC-32 polynomial
- * @return None
- **********************************************************************/
-void CRC_Init(CRC_Type CRCType)
-{
- if(CRCType == CRC_POLY_CRCCCITT)
- {
- LPC_CRC->MODE = 0x00;
- LPC_CRC->SEED = 0xFFFF;
- crc_cur_type = CRC_POLY_CRCCCITT;
- }
- else if(CRCType == CRC_POLY_CRC16)
- {
- LPC_CRC->MODE = 0x15;
- LPC_CRC->SEED = 0x0000;
- crc_cur_type = CRC_POLY_CRC16;
-
- }
- else if(CRCType == CRC_POLY_CRC32)
- {
- LPC_CRC->MODE = 0x36;
- LPC_CRC->SEED = 0xFFFFFFFF;
- crc_cur_type = CRC_POLY_CRC32;
- }
- else
- {
- //Invalid input parameter
- while(1);//error loop
- }
-}
-/*********************************************************************//**
- * @brief CRC reset
- * @param[in] None
- * @return None
- **********************************************************************/
-void CRC_Reset(void)
-{
- if(crc_cur_type == CRC_POLY_CRCCCITT)
- LPC_CRC->SEED = 0xFFFF;
- else if (crc_cur_type == CRC_POLY_CRC16)
- LPC_CRC->SEED = 0x0000;
- else if (crc_cur_type == CRC_POLY_CRC32)
- LPC_CRC->SEED = 0xFFFFFFFF;
-}
-
-/*********************************************************************//**
- * @brief CRC data checksum calculation
- * @param[in] data input data
- * @return data checksum result
- **********************************************************************/
-uint32_t CRC_CalcDataChecksum(uint32_t data, CRC_WR_SIZE SizeType)
-{
- if(SizeType == CRC_WR_8BIT)
- LPC_CRC->WR_DATA_BYTE.DATA = (uint8_t)data;
- else if(SizeType == CRC_WR_16BIT)
- LPC_CRC->WR_DATA_WORD.DATA = (uint16_t)data;
- else
- LPC_CRC->WR_DATA_DWORD.DATA = data;
- return(LPC_CRC->SUM);
-}
-
-/*********************************************************************//**
- * @brief CRC block data checksum calculation
- * @param[in] blockdata pointer to block input data
- * @param[in] blocksize size of block data
- * @param[in] SizeType size of data width per write, should be:
- - CRC_WR_8BIT : 8-bit write
- - CRC_WR_16BIT: 16-bit write
- - CRC_WR_32BIT: 32-bit write
- * @return block data checksum result
- **********************************************************************/
-uint32_t CRC_CalcBlockChecksum(void *block_data, uint32_t block_size, CRC_WR_SIZE data_size)
-{
- uint8_t *data = (uint8_t*) block_data;
-
- while(block_size !=0) {
-
- switch(data_size) {
-
- case CRC_WR_8BIT:
- {
- uint8_t *tmp = data;
- LPC_CRC->WR_DATA_BYTE.DATA = *tmp;
- data++;
- }
- break;
- case CRC_WR_16BIT:
- {
- uint16_t *tmp = (uint16_t*)data;
- LPC_CRC->WR_DATA_WORD.DATA = *tmp;
- data +=2;
- }
- break;
- default:
- {
- uint32_t *tmp = (uint32_t*)data;
- LPC_CRC->WR_DATA_DWORD.DATA = *tmp;
- data += 4;
- }
- break;
- }
- block_size--;
- }
- return(LPC_CRC->SUM);
-}
-
-/**
- * @}
- */
-#endif /*_CRC*/
-
-/**
- * @}
- */
-
-/* --------------------------------- End Of File ------------------------------ */
-
diff --git a/bsp/lpc408x/Libraries/Drivers/source/lpc_dac.c b/bsp/lpc408x/Libraries/Drivers/source/lpc_dac.c
deleted file mode 100644
index 29e126d085..0000000000
--- a/bsp/lpc408x/Libraries/Drivers/source/lpc_dac.c
+++ /dev/null
@@ -1,196 +0,0 @@
-/**********************************************************************
-* $Id$ lpc_dac.c 2011-06-02
-*//**
-* @file lpc_dac.c
-* @brief Contains all functions support for DAC firmware library on
-* LPC
-* @version 1.0
-* @date 02. June. 2011
-* @author NXP MCU SW Application Team
-*
-* Copyright(C) 2011, NXP Semiconductor
-* All rights reserved.
-*
-***********************************************************************
-* Software that is described herein is for illustrative purposes only
-* which provides customers with programming information regarding the
-* products. This software is supplied "AS IS" without any warranties.
-* NXP Semiconductors assumes no responsibility or liability for the
-* use of the software, conveys no license or title under any patent,
-* copyright, or mask work right to the product. NXP Semiconductors
-* reserves the right to make changes in the software without
-* notification. NXP Semiconductors also make 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'
-* relevant copyright 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.
-**********************************************************************/
-
-/* Peripheral group ----------------------------------------------------------- */
-/** @addtogroup DAC
- * @{
- */
-#ifdef __BUILD_WITH_EXAMPLE__
-#include "lpc_libcfg.h"
-#else
-#include "lpc_libcfg_default.h"
-#endif /* __BUILD_WITH_EXAMPLE__ */
-#ifdef _DAC
-
-/* Includes ------------------------------------------------------------------- */
-#include "lpc_dac.h"
-#include "lpc_clkpwr.h"
-#include "lpc_pinsel.h"
-
-/* Private Functions ---------------------------------------------------------- */
-
-/*********************************************************************//**
- * @brief Get pointer to DAC peripheral
- * @param[in] compId Component ID, normally is zero (0).
- * @param[in] pinnum Pin number value, should be in range from 0..31
- * @return Pointer to DAC peripheral component
- **********************************************************************/
-static LPC_DAC_TypeDef * DAC_GetPointer(uint8_t compId)
-{
- LPC_DAC_TypeDef *pComponent = LPC_DAC;
-
- return pComponent;
-}
-
-
-
-/* Public Functions ----------------------------------------------------------- */
-/** @addtogroup DAC_Public_Functions
- * @{
- */
-
-/*********************************************************************//**
- * @brief Initial ADC configuration
- * - Maximum current is 700 uA
- * - Value to AOUT is 0
- * @param[in] DAC_Id the ID of the DAC component that is using, should be: zero (0)
- * @return None
- ***********************************************************************/
-void DAC_Init(uint8_t DAC_Id)
-{
- /*
- * Init DAC pin connect
- * AOUT on P0.26
- */
- PINSEL_ConfigPin(0, 26, 2);
-
- PINSEL_SetAnalogPinMode(0,26,ENABLE);
-
- //Enable DAC for the pin
- PINSEL_DacEnable(0, 26, ENABLE);
-
- //Set maximum current output as default
- DAC_SetBias(DAC_Id, DAC_MAX_CURRENT_700uA);
-}
-
-/*********************************************************************//**
- * @brief Update value to DAC
- * @param[in] DAC_Id the ID of the DAC component that is using, should be: zero (0)
- * @param[in] dac_value : value 10 bit to be converted to output
- * @return None
- ***********************************************************************/
-void DAC_UpdateValue (uint8_t DAC_Id,uint32_t dac_value)
-{
- uint32_t tmp;
-
- LPC_DAC_TypeDef* pDac = DAC_GetPointer(DAC_Id);
-
- tmp = pDac->CR & DAC_BIAS_EN;
-
- tmp |= DAC_VALUE(dac_value);
-
- // Update value
- pDac->CR = tmp;
-}
-
-/*********************************************************************//**
- * @brief Set Maximum current for DAC
- * @param[in] DAC_Id the ID of the DAC component that is using, should be: zero (0)
- * @param[in] bias : 0 is 700 uA
- * 1 350 uA
- * @return None
- ***********************************************************************/
-void DAC_SetBias (uint8_t DAC_Id, uint32_t bias)
-{
- LPC_DAC_TypeDef* pDac = DAC_GetPointer(DAC_Id);
-
- pDac->CR &=~DAC_BIAS_EN;
-
- if (bias == DAC_MAX_CURRENT_350uA)
- {
- pDac->CR |= DAC_BIAS_EN;
- }
-}
-
-/*********************************************************************//**
- * @brief To enable the DMA operation and control DMA timer
- * @param[in] DAC_Id the ID of the DAC component that is using, should be: zero (0)
- * @param[in] DAC_ConverterConfigStruct pointer to DAC_CONVERTER_CFG_Type
- * - DBLBUF_ENA : enable/disable DACR double buffering feature
- * - CNT_ENA : enable/disable timer out counter
- * - DMA_ENA : enable/disable DMA access
- * @return None
- ***********************************************************************/
-void DAC_ConfigDAConverterControl (uint8_t DAC_Id, DAC_CONVERTER_CFG_Type *DAC_ConverterConfigStruct)
-{
- LPC_DAC_TypeDef* pDac = DAC_GetPointer(DAC_Id);
-
- pDac->CTRL &= ~DAC_DACCTRL_MASK;
-
- if (DAC_ConverterConfigStruct->DBLBUF_ENA)
- pDac->CTRL |= DAC_DBLBUF_ENA;
-
- if (DAC_ConverterConfigStruct->CNT_ENA)
- pDac->CTRL |= DAC_CNT_ENA;
-
- if (DAC_ConverterConfigStruct->DMA_ENA)
- pDac->CTRL |= DAC_DMA_ENA;
-}
-
-/*********************************************************************//**
- * @brief Set reload value for interrupt/DMA counter
- * @param[in] DAC_Id the ID of the DAC component that is using, should be: zero (0)
- * @param[in] time_out time out to reload for interrupt/DMA counter
- * @return None
- ***********************************************************************/
-void DAC_SetDMATimeOut(uint8_t DAC_Id, uint32_t time_out)
-{
- LPC_DAC_TypeDef* pDac = DAC_GetPointer(DAC_Id);
-
- pDac->CNTVAL = DAC_CCNT_VALUE(time_out);
-}
-
-
-/*********************************************************************//**
- * @brief Check the interrupt/DMA counter is occured or not because of the timer counter
- * @param[in] DAC_Id the ID of the DAC component that is using, should be: zero (0)
- * @return None
- ***********************************************************************/
-uint8_t DAC_IsIntRequested(uint8_t DAC_Id)
-{
- LPC_DAC_TypeDef* pDac = DAC_GetPointer(DAC_Id);
-
- //Return the INT_DMA_REQ bit of D/A control register
- return (pDac->CTRL & 0x01);
-}
-
-
-/**
- * @}
- */
-#endif /*_DAC*/
-
-/**
- * @}
- */
-
-/* --------------------------------- End Of File ------------------------------ */
diff --git a/bsp/lpc408x/Libraries/Drivers/source/lpc_eeprom.c b/bsp/lpc408x/Libraries/Drivers/source/lpc_eeprom.c
deleted file mode 100644
index 039a1d4ed3..0000000000
--- a/bsp/lpc408x/Libraries/Drivers/source/lpc_eeprom.c
+++ /dev/null
@@ -1,267 +0,0 @@
-/**********************************************************************
-* $Id$ lpc_eeprom.c 2011-06-02
-*//**
-* @file lpc_eeprom.c
-* @brief Contains all functions support for EEPROM firmware library on
-* LPC
-* @version 1.0
-* @date 02. June. 2011
-* @author NXP MCU SW Application Team
-*
-* Copyright(C) 2011, NXP Semiconductor
-* All rights reserved.
-*
-***********************************************************************
-* Software that is described herein is for illustrative purposes only
-* which provides customers with programming information regarding the
-* products. This software is supplied "AS IS" without any warranties.
-* NXP Semiconductors assumes no responsibility or liability for the
-* use of the software, conveys no license or title under any patent,
-* copyright, or mask work right to the product. NXP Semiconductors
-* reserves the right to make changes in the software without
-* notification. NXP Semiconductors also make 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'
-* relevant copyright 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.
-**********************************************************************/
-
-/* Peripheral group ----------------------------------------------------------- */
-/** @addtogroup EEPROM
- * @{
- */
-#ifdef __BUILD_WITH_EXAMPLE__
-#include "lpc_libcfg.h"
-#else
-#include "lpc_libcfg_default.h"
-#endif /* __BUILD_WITH_EXAMPLE__ */
-#ifdef _EEPROM
-
-/* Includes ------------------------------------------------------------------- */
-#include "lpc_eeprom.h"
-#include "lpc_clkpwr.h"
-
-/* Public Functions ----------------------------------------------------------- */
-
-/*********************************************************************//**
- * @brief Initial EEPROM
- * @param[in] None
- * @return None
- **********************************************************************/
-void EEPROM_Init(void)
-{
- uint32_t val, cclk;
- LPC_EEPROM->PWRDWN = 0x0;
- /* EEPROM is automate turn on after reset */
- /* Setting clock:
- * EEPROM required a 375kHz. This clock is generated by dividing the
- * system bus clock.
- */
- cclk = CLKPWR_GetCLK(CLKPWR_CLKTYPE_CPU);
- val = (cclk/375000)-1;
- LPC_EEPROM->CLKDIV = val;
-
- /* Setting wait state */
- val = ((((cclk / 1000000) * 15) / 1000) + 1);
- val |= (((((cclk / 1000000) * 55) / 1000) + 1) << 8);
- val |= (((((cclk / 1000000) * 35) / 1000) + 1) << 16);
- LPC_EEPROM->WSTATE = val;
-}
-
-/*********************************************************************//**
- * @brief Write data to EEPROM at specific address
- * @param[in] page_offset offset of data in page register(0 - 63)
- * page_address page address (0-62)
- * mode Write mode, should be:
- * - MODE_8_BIT : write 8 bit mode
- * - MODE_16_BIT : write 16 bit mode
- * - MODE_32_BIT : write 32 bit mode
- * data buffer that contain data that will be written to buffer
- * count number written data
- * @return None
- * @note This function actually write data into EEPROM memory and automatically
- * write into next page if current page is overflowed
- **********************************************************************/
-void EEPROM_Write(uint16_t page_offset, uint16_t page_address, void* data, EEPROM_Mode_Type mode, uint32_t count)
-{
- uint32_t i;
- uint8_t *tmp8 = (uint8_t *)data;
- uint16_t *tmp16 = (uint16_t *)data;
- uint32_t *tmp32 = (uint32_t *)data;
-
- LPC_EEPROM->INT_CLR_STATUS = ((1 << EEPROM_ENDOF_RW)|(1 << EEPROM_ENDOF_PROG));
- //check page_offset
- if(mode == MODE_16_BIT){
- if((page_offset & 0x01)!=0) while(1);
- }
- else if(mode == MODE_32_BIT){
- if((page_offset & 0x03)!=0) while(1);
- }
- LPC_EEPROM->ADDR = EEPROM_PAGE_OFFSET(page_offset);
- for(i=0;i<count;i++)
- {
- //update data to page register
- if(mode == MODE_8_BIT){
- LPC_EEPROM->CMD = EEPROM_CMD_8_BIT_WRITE;
- LPC_EEPROM -> WDATA = *tmp8;
- tmp8++;
- page_offset +=1;
- }
- else if(mode == MODE_16_BIT){
- LPC_EEPROM->CMD = EEPROM_CMD_16_BIT_WRITE;
- LPC_EEPROM -> WDATA = *tmp16;
- tmp16++;
- page_offset +=2;
- }
- else{
- LPC_EEPROM->CMD = EEPROM_CMD_32_BIT_WRITE;
- LPC_EEPROM -> WDATA = *tmp32;
- tmp32++;
- page_offset +=4;
- }
- while(!((LPC_EEPROM->INT_STATUS >> EEPROM_ENDOF_RW)&0x01));
- LPC_EEPROM->INT_CLR_STATUS = (1 << EEPROM_ENDOF_RW);
- if((page_offset >= EEPROM_PAGE_SIZE)|(i==count-1)){
- //update to EEPROM memory
- LPC_EEPROM->INT_CLR_STATUS = (0x1 << EEPROM_ENDOF_PROG);
- LPC_EEPROM->ADDR = EEPROM_PAGE_ADRESS(page_address);
- LPC_EEPROM->CMD = EEPROM_CMD_ERASE_PRG_PAGE;
- while(!((LPC_EEPROM->INT_STATUS >> EEPROM_ENDOF_PROG)&0x01));
- LPC_EEPROM->INT_CLR_STATUS = (1 << EEPROM_ENDOF_PROG);
- }
- if(page_offset >= EEPROM_PAGE_SIZE)
- {
- page_offset = 0;
- page_address +=1;
- LPC_EEPROM->ADDR =0;
- if(page_address > EEPROM_PAGE_NUM - 1) page_address = 0;
- }
- }
-}
-
-/*********************************************************************//**
- * @brief Read data to EEPROM at specific address
- * @param[in]
- * data buffer that contain data that will be written to buffer
- * mode Read mode, should be:
- * - MODE_8_BIT : read 8 bit mode
- * - MODE_16_BIT : read 16 bit mode
- * - MODE_32_BIT : read 32 bit mode
- * count number read data (bytes)
- * @return data buffer that contain data that will be read to buffer
- **********************************************************************/
-void EEPROM_Read(uint16_t page_offset, uint16_t page_address, void* data, EEPROM_Mode_Type mode, uint32_t count)
-{
- uint32_t i;
- uint8_t *tmp8 = (uint8_t *)data;
- uint16_t *tmp16 = (uint16_t *)data;
- uint32_t *tmp32 = (uint32_t *)data;
-
- LPC_EEPROM->INT_CLR_STATUS = ((1 << EEPROM_ENDOF_RW)|(1 << EEPROM_ENDOF_PROG));
- LPC_EEPROM->ADDR = EEPROM_PAGE_ADRESS(page_address)|EEPROM_PAGE_OFFSET(page_offset);
- if(mode == MODE_8_BIT)
- LPC_EEPROM->CMD = EEPROM_CMD_8_BIT_READ|EEPROM_CMD_RDPREFETCH;
- else if(mode == MODE_16_BIT){
- LPC_EEPROM->CMD = EEPROM_CMD_16_BIT_READ|EEPROM_CMD_RDPREFETCH;
- //check page_offset
- if((page_offset &0x01)!=0)
- return;
- }
- else{
- LPC_EEPROM->CMD = EEPROM_CMD_32_BIT_READ|EEPROM_CMD_RDPREFETCH;
- //page_offset must be a multiple of 0x04
- if((page_offset & 0x03)!=0)
- return;
- }
-
- //read and store data in buffer
- for(i=0;i<count;i++){
-
- if(mode == MODE_8_BIT){
- *tmp8 = (uint8_t)(LPC_EEPROM -> RDATA);
- tmp8++;
- page_offset +=1;
- }
- else if (mode == MODE_16_BIT)
- {
- *tmp16 = (uint16_t)(LPC_EEPROM -> RDATA);
- tmp16++;
- page_offset +=2;
- }
- else{
- *tmp32 = (uint32_t)(LPC_EEPROM ->RDATA);
- tmp32++;
- page_offset +=4;
- }
- while(!((LPC_EEPROM->INT_STATUS >> EEPROM_ENDOF_RW)&0x01));
- LPC_EEPROM->INT_CLR_STATUS = (1 << EEPROM_ENDOF_RW);
- if((page_offset >= EEPROM_PAGE_SIZE) && (i < count - 1)) {
- page_offset = 0;
- page_address++;
- LPC_EEPROM->ADDR = EEPROM_PAGE_ADRESS(page_address)|EEPROM_PAGE_OFFSET(page_offset);
- if(mode == MODE_8_BIT)
- LPC_EEPROM->CMD = EEPROM_CMD_8_BIT_READ|EEPROM_CMD_RDPREFETCH;
- else if(mode == MODE_16_BIT)
- LPC_EEPROM->CMD = EEPROM_CMD_16_BIT_READ|EEPROM_CMD_RDPREFETCH;
- else
- LPC_EEPROM->CMD = EEPROM_CMD_32_BIT_READ|EEPROM_CMD_RDPREFETCH;
- }
- }
-}
-
-/*********************************************************************//**
- * @brief Erase a page at the specific address
- * @param[in] address EEPROM page address (0-62)
- * @return data buffer that contain data that will be read to buffer
- **********************************************************************/
-void EEPROM_Erase(uint16_t page_address)
-{
- uint32_t i;
- uint32_t count = EEPROM_PAGE_SIZE/4;
-
- LPC_EEPROM->INT_CLR_STATUS = ((1 << EEPROM_ENDOF_RW)|(1 << EEPROM_ENDOF_PROG));
-
- //clear page register
- LPC_EEPROM->ADDR = EEPROM_PAGE_OFFSET(0);
- LPC_EEPROM->CMD = EEPROM_CMD_32_BIT_WRITE;
- for(i=0;i<count;i++)
- {
- LPC_EEPROM->WDATA = 0;
- while(!((LPC_EEPROM->INT_STATUS >> EEPROM_ENDOF_RW)&0x01));
- LPC_EEPROM->INT_CLR_STATUS = (1 << EEPROM_ENDOF_RW);
- }
-
- LPC_EEPROM->INT_CLR_STATUS = (0x1 << EEPROM_ENDOF_PROG);
- LPC_EEPROM->ADDR = EEPROM_PAGE_ADRESS(page_address);
- LPC_EEPROM->CMD = EEPROM_CMD_ERASE_PRG_PAGE;
- while(!((LPC_EEPROM->INT_STATUS >> EEPROM_ENDOF_PROG)&0x01));
- LPC_EEPROM->INT_CLR_STATUS = (1 << EEPROM_ENDOF_PROG);
-}
-
-/*********************************************************************//**
- * @brief Enable/Disable EEPROM power down mdoe
- * @param[in] NewState PowerDown mode state, should be:
- * - ENABLE: Enable power down mode
- * - DISABLE: Disable power down mode
- * @return None
- **********************************************************************/
-void EEPROM_PowerDown(FunctionalState NewState)
-{
- if(NewState == ENABLE)
- LPC_EEPROM->PWRDWN = 0x1;
- else
- LPC_EEPROM->PWRDWN = 0x0;
-}
-
-#endif /*_EEPROM*/
-
-/**
- * @}
- */
-
-/* --------------------------------- End Of File ------------------------------ */
-
diff --git a/bsp/lpc408x/Libraries/Drivers/source/lpc_emac.c b/bsp/lpc408x/Libraries/Drivers/source/lpc_emac.c
deleted file mode 100644
index 750b487b54..0000000000
--- a/bsp/lpc408x/Libraries/Drivers/source/lpc_emac.c
+++ /dev/null
@@ -1,1043 +0,0 @@
-/**********************************************************************
-* $Id$ lpc_emac.c 2011-06-02
-*//**
-* @file lpc_emac.c
-* @brief Contains all functions support for Ethernet MAC firmware
-* library on LPC
-* @version 1.0
-* @date 02. June. 2011
-* @author NXP MCU SW Application Team
-*
-* Copyright(C) 2011, NXP Semiconductor
-* All rights reserved.
-*
-***********************************************************************
-* Software that is described herein is for illustrative purposes only
-* which provides customers with programming information regarding the
-* products. This software is supplied "AS IS" without any warranties.
-* NXP Semiconductors assumes no responsibility or liability for the
-* use of the software, conveys no license or title under any patent,
-* copyright, or mask work right to the product. NXP Semiconductors
-* reserves the right to make changes in the software without
-* notification. NXP Semiconductors also make 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'
-* relevant copyright 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.
-**********************************************************************/
-#ifdef __BUILD_WITH_EXAMPLE__
-#include "lpc_libcfg.h"
-#else
-#include "lpc_libcfg_default.h"
-#endif /* __BUILD_WITH_EXAMPLE__ */
-#ifdef _EMAC
-
-#include "lpc_emac.h"
-#include "lpc_clkpwr.h"
-#include "lpc_pinsel.h"
-
-/* Peripheral group ----------------------------------------------------------- */
-/** @addtogroup EMAC
- * @{
- */
-
-/************************** PRIVATE VARIABLES *************************/
-
-
-/* MII Mgmt Configuration register - Clock divider setting */
-const uint8_t EMAC_clkdiv[] = { 4, 6, 8, 10, 14, 20, 28, 36, 40, 44, 48, 52, 56, 60, 64 };
-
-/* EMAC Config data */
-static EMAC_CFG_Type EMAC_Configs;
-
-
-/* EMAC local DMA Descriptors */
-
-
-#ifdef __IAR_SYSTEMS_ICC__
-/* Global Tx Buffer data */
-#pragma data_alignment=4
-static uint16_t saFrameBuffers[EMAC_MAX_FRAME_NUM][EMAC_MAX_FRAME_SIZE];
-#else
-/* Global Rx Buffer data */
-static uint16_t __attribute__ ((aligned (4))) saFrameBuffers[EMAC_MAX_FRAME_NUM][EMAC_MAX_FRAME_SIZE];
-#endif
-static uint32_t sulCurrFrameSz = 0;
-static uint8_t sbCurrFrameID = 0;
-
-/***************************** PRIVATE FUNCTION *****************************/
-static void EMAC_UpdateRxConsumeIndex(void);
-static void EMAC_UpdateTxProduceIndex(void);
-static uint32_t EMAC_AllocTxBuff(uint16_t nFrameSize, uint8_t bLastFrame);
-static uint32_t EMAC_GetRxFrameSize(void);
-
-
-/*********************************************************************//**
- * @brief
- * @param[in]
- * @return
- **********************************************************************/
-void rx_descr_init (void)
-{
- unsigned int i;
-
- for (i = 0; i < EMAC_NUM_RX_FRAG; i++)
- {
- RX_DESC_PACKET(i) = RX_BUF(i);
- RX_DESC_CTRL(i) = EMAC_RCTRL_INT | (EMAC_ETH_MAX_FLEN-1);
- RX_STAT_INFO(i) = 0;
- RX_STAT_HASHCRC(i) = 0;
- }
-
- /* Set EMAC Receive Descriptor Registers. */
- LPC_EMAC->RxDescriptor = RX_DESC_BASE;
- LPC_EMAC->RxStatus = RX_STAT_BASE;
- LPC_EMAC->RxDescriptorNumber = EMAC_NUM_RX_FRAG-1;
-
- /* Rx Descriptors Point to 0 */
- LPC_EMAC->RxConsumeIndex = 0;
-}
-
-/*********************************************************************//**
- * @brief
- * @param[in]
- * @return
- **********************************************************************/
-void tx_descr_init (void)
-{
- unsigned int i;
-
- for (i = 0; i < EMAC_NUM_TX_FRAG; i++)
- {
- TX_DESC_PACKET(i) = TX_BUF(i);
- TX_DESC_CTRL(i) = 0;
- TX_STAT_INFO(i) = 0;
- }
-
- /* Set EMAC Transmit Descriptor Registers. */
- LPC_EMAC->TxDescriptor = TX_DESC_BASE;
- LPC_EMAC->TxStatus = TX_STAT_BASE;
- LPC_EMAC->TxDescriptorNumber = EMAC_NUM_TX_FRAG-1;
-
- /* Tx Descriptors Point to 0 */
- LPC_EMAC->TxProduceIndex = 0;
-}
-
-/*********************************************************************//**
- * @brief Set Station MAC address for EMAC module
- * @param[in] abStationAddr Pointer to Station address that contains 6-bytes
- * of MAC address.
- * @return None
- **********************************************************************/
-void setEmacAddr(uint8_t abStationAddr[])
-{
- /* Set the Ethernet MAC Address registers */
- LPC_EMAC->SA0 = ((uint32_t)abStationAddr[5] << 8) | (uint32_t)abStationAddr[4];
- LPC_EMAC->SA1 = ((uint32_t)abStationAddr[3] << 8) | (uint32_t)abStationAddr[2];
- LPC_EMAC->SA2 = ((uint32_t)abStationAddr[1] << 8) | (uint32_t)abStationAddr[0];
-}
-
-
-/************************** GLOBAL/PUBLIC FUNCTIONS *************************/
-
-/** @defgroup EMAC_Public_Functions
- * @{
- */
-
-/*********************************************************************//**
- * @brief Write data to PHY
- * @param[in] PhyReg PHY register address
- * @param[in] Value Register Value
- * @return None
- **********************************************************************/
-void EMAC_Write_PHY (uint8_t PhyReg, uint16_t Value)
-{
- unsigned int tout;
-
- LPC_EMAC->MADR = ((EMAC_Configs.bPhyAddr & 0x1F) << 8 )| (PhyReg & 0x1F);
- LPC_EMAC->MWTD = Value;
-
- /* Wait utill operation completed */
- tout = 0;
-
- for (tout = 0; tout < EMAC_MII_WR_TOUT; tout++)
- {
- if ((LPC_EMAC->MIND & EMAC_MIND_BUSY) == 0)
- {
- break;
- }
- }
-}
-
-/*********************************************************************//**
- * @brief Read data from PHY register
- * @param[in] PhyReg PHY register address
- * @return Register value
- **********************************************************************/
-uint16_t EMAC_Read_PHY (uint8_t PhyReg)
-{
- unsigned int tout;
-
- LPC_EMAC->MADR = ((EMAC_Configs.bPhyAddr & 0x1F) << 8 )| (PhyReg & 0x1F);
- LPC_EMAC->MCMD = EMAC_MCMD_READ;
-
- /* Wait until operation completed */
- tout = 0;
- for (tout = 0; tout < EMAC_MII_RD_TOUT; tout++)
- {
- if ((LPC_EMAC->MIND & EMAC_MIND_BUSY) == 0)
- {
- break;
- }
- }
-
- LPC_EMAC->MCMD = 0;
- return (LPC_EMAC->MRDD);
-}
-
-/*********************************************************************//**
- * @brief Set Full/Half Duplex Mode
- * @param[in] full_duplex 0: Half-duplex, 1: Full-duplex
- * @return None
- **********************************************************************/
-void EMAC_SetFullDuplexMode(uint8_t full_duplex)
-{
- if(full_duplex)
- {
- LPC_EMAC->MAC2 |= EMAC_MAC2_FULL_DUP;
- LPC_EMAC->Command |= EMAC_CR_FULL_DUP;
- LPC_EMAC->IPGT = EMAC_IPGT_FULL_DUP;
- }
- else
- {
- LPC_EMAC->IPGT = EMAC_IPGT_HALF_DUP;
- }
-}
-/*********************************************************************//**
- * @brief Set PHY Speed
- * @param[in] mode_100Mbps 0: 10Mbps, 1: 100Mbps
- * @return None
- **********************************************************************/
-void EMAC_SetPHYSpeed(uint8_t mode_100Mbps)
-{
- if(mode_100Mbps)
- {
- LPC_EMAC->SUPP = EMAC_SUPP_SPEED;
- }
- else
- {
- LPC_EMAC->SUPP = 0;
- }
-}
-
-
-/*********************************************************************//**
- * @brief Initializes the EMAC peripheral according to the specified
-* parameters in the EMAC_ConfigStruct.
- * @param[in] EMAC_ConfigStruct Pointer to a EMAC_CFG_Type structure
-* that contains the configuration information for the
-* specified EMAC peripheral.
- * @return None
- *
- * Note: This function will initialize EMAC module according to procedure below:
- * - Remove the soft reset condition from the MAC
- * - Configure the PHY via the MIIM interface of the MAC
- * - Select RMII mode
- * - Configure the transmit and receive DMA engines, including the descriptor arrays
- * - Configure the host registers (MAC1,MAC2 etc.) in the MAC
- * - Enable the receive and transmit data paths
- * In default state after initializing, Rx Done and Tx Done interrupt are enabled,
- * nad all interrupts are also enabled
- * (Ref. from LPC17xx UM)
- **********************************************************************/
-int32_t EMAC_Init(EMAC_CFG_Type *EMAC_ConfigStruct)
-{
- /* Initialize the EMAC Ethernet controller. */
- volatile int32_t tout, tmp;
-
- EMAC_Configs = *EMAC_ConfigStruct;
-
- /* Set up power for Ethernet module */
- CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCENET, ENABLE);
-
- /* Enable P1 Ethernet Pins. */
-
- /* Reset all EMAC internal modules */
- LPC_EMAC->MAC1 = EMAC_MAC1_RES_TX | EMAC_MAC1_RES_MCS_TX | EMAC_MAC1_RES_RX |
- EMAC_MAC1_RES_MCS_RX | EMAC_MAC1_SIM_RES | EMAC_MAC1_SOFT_RES;
-
- LPC_EMAC->Command = EMAC_CR_REG_RES | EMAC_CR_TX_RES | EMAC_CR_RX_RES | EMAC_CR_PASS_RUNT_FRM;
-
- /* A short delay after reset. */
- for (tout = 100; tout; tout--);
-
- /* Initialize MAC control registers. */
- LPC_EMAC->MAC1 = EMAC_MAC1_PASS_ALL;
- LPC_EMAC->MAC2 = EMAC_MAC2_CRC_EN | EMAC_MAC2_PAD_EN;
- LPC_EMAC->MAXF = EMAC_ETH_MAX_FLEN;
- /*
- * Find the clock that close to desired target clock
- */
- tmp = CLKPWR_GetCLK(CLKPWR_CLKTYPE_CPU)/ EMAC_MCFG_MII_MAXCLK;
- for (tout = 0; tout < sizeof (EMAC_clkdiv); tout++)
- {
- if (EMAC_clkdiv[tout] >= tmp)
- break;
- }
-
- if(tout >= sizeof (EMAC_clkdiv))
- return ERROR;
- tout++;
-
- // Set Frame size
- LPC_EMAC->MAXF = EMAC_ConfigStruct->nMaxFrameSize;
-
- // Write to MAC configuration register and reset
- LPC_EMAC->MCFG = EMAC_MCFG_CLK_SEL(tout) | EMAC_MCFG_RES_MII;
-
- // release reset
- LPC_EMAC->MCFG &= ~(EMAC_MCFG_RES_MII);
- LPC_EMAC->CLRT = EMAC_CLRT_DEF;
- LPC_EMAC->IPGR = EMAC_IPGR_P2_DEF;
-
- /* Enable Reduced MII interface. */
- LPC_EMAC->Command = EMAC_CR_RMII | EMAC_CR_PASS_RUNT_FRM;
-
-
- // Initilialize PHY
- if(EMAC_ConfigStruct->pfnPHYInit != NULL)
- {
- if(EMAC_ConfigStruct->pfnPHYInit(&EMAC_ConfigStruct->PhyCfg) != SUCCESS)
- {
- return ERROR;
- }
- }
-
- // Set EMAC address
- setEmacAddr(EMAC_ConfigStruct->pbEMAC_Addr);
-
- /* Initialize Tx and Rx DMA Descriptors */
- rx_descr_init ();
- tx_descr_init ();
-
- // Set Receive Filter register: enable broadcast and multicast
- LPC_EMAC->RxFilterCtrl = EMAC_RFC_MCAST_EN | EMAC_RFC_BCAST_EN | EMAC_RFC_PERFECT_EN;
-
- /* Enable Rx Done and Tx Done interrupt for EMAC */
- EMAC_IntCmd((EMAC_INT_RX_OVERRUN | EMAC_INT_RX_ERR | EMAC_INT_RX_FIN \
- | EMAC_INT_RX_DONE | EMAC_INT_TX_UNDERRUN | EMAC_INT_TX_ERR \
- | EMAC_INT_TX_FIN | EMAC_INT_TX_DONE), ENABLE);
-
- /* Reset all interrupts */
- LPC_EMAC->IntClear = 0xFFFF;
-
- /* Enable receive and transmit mode of MAC Ethernet core */
- EMAC_TxEnable();
- EMAC_RxEnable();
-
- NVIC_EnableIRQ(ENET_IRQn);
-
- return SUCCESS;
-}
-
-
-/*********************************************************************//**
- * @brief De-initializes the EMAC peripheral registers to their
-* default reset values.
- * @param[in] None
- * @return None
- **********************************************************************/
-void EMAC_DeInit(void)
-{
- // Disable all interrupt
- LPC_EMAC->IntEnable = 0x00;
-
- // Clear all pending interrupt
- LPC_EMAC->IntClear = (0xFF) | (EMAC_INT_SOFT_INT | EMAC_INT_WAKEUP);
-
- LPC_EMAC->Command = 0;
-
- /* TurnOff power for Ethernet module */
- CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCENET, DISABLE);
-}
-
-/*********************************************************************//**
- * @brief EMAC TX API modules
- * @param[in] None
- * @return None
- **********************************************************************/
-void EMAC_TxEnable( void )
-{
- LPC_EMAC->Command |= EMAC_CR_TX_EN;
- return;
-}
-
-
-/*********************************************************************//**
- * @brief EMAC RX API modules
- * @param[in] None
- * @return None
- **********************************************************************/
-void EMAC_TxDisable( void )
-{
- LPC_EMAC->Command &= ~EMAC_CR_TX_EN;
- return;
-}
-
-/*********************************************************************//**
- * @brief EMAC RX API modules
- * @param[in] None
- * @return None
- **********************************************************************/
-void EMAC_RxEnable( void )
-{
- LPC_EMAC->Command |= EMAC_CR_RX_EN;
- LPC_EMAC->MAC1 |= EMAC_MAC1_REC_EN;
- return;
-}
-
-/*********************************************************************//**
- * @brief EMAC RX API modules
- * @param[in] None
- * @return None
- **********************************************************************/
-void EMAC_RxDisable( void )
-{
- LPC_EMAC->Command &= ~EMAC_CR_RX_EN;
- LPC_EMAC->MAC1 &= ~EMAC_MAC1_REC_EN;
- return;
-}
-
-/*********************************************************************//**
- * @brief Get the status of given buffer.
- * @param[in] idx Buffer index
- * @return EMAC_BUFF_AVAILABLE/EMAC_BUFF_FULL/EMAC_BUFF_PARTIAL_FULL
- *
- **********************************************************************/
-EMAC_BUFF_STATUS EMAC_GetBufferSts(EMAC_BUFF_IDX idx)
-{
- uint32_t consume_idx, produce_idx;
- uint32_t max_frag_num;
-
- // Get the consume index, produce index and the buffer size
- if(idx == EMAC_TX_BUFF)
- {
- consume_idx = LPC_EMAC->TxConsumeIndex;
- produce_idx = LPC_EMAC->TxProduceIndex;
- max_frag_num = LPC_EMAC->TxDescriptorNumber + 1;
- }
- else
- {
- consume_idx = LPC_EMAC->RxConsumeIndex;
- produce_idx = LPC_EMAC->RxProduceIndex;
- max_frag_num = LPC_EMAC->RxDescriptorNumber + 1;
- }
-
- // empty
- if(consume_idx == produce_idx)
- return EMAC_BUFF_EMPTY;
-
- // Full
- if(consume_idx == 0 &&
- produce_idx == max_frag_num - 1)
- return EMAC_BUFF_FULL;
-
- // Wrap-around
- if(consume_idx == produce_idx + 1)
- return EMAC_BUFF_FULL;
-
- return EMAC_BUFF_PARTIAL_FULL;
-}
-
-/*********************************************************************//**
- * @brief Allocate a descriptor for sending frame and get the coressponding buffer address
- * @param[in] FrameSize The size of frame you want to send
- * @return Address of the TX_DESC_PACKET buffer
- **********************************************************************/
- uint32_t EMAC_AllocTxBuff(uint16_t nFrameSize, uint8_t bLastFrame)
-{
- uint32_t idx;
- uint32_t dp;
- volatile uint32_t i;
-
- idx = LPC_EMAC->TxProduceIndex;
-
- while(EMAC_GetBufferSts(EMAC_TX_BUFF) == EMAC_BUFF_FULL)
- {
- for(i = 0; i < 1000000; i++) ;
- }
-
- dp = TX_DESC_PACKET(idx);
-
- if(bLastFrame)
- TX_DESC_CTRL(idx) = ((nFrameSize-1) & EMAC_TCTRL_SIZE) | (EMAC_TCTRL_INT | EMAC_TCTRL_LAST);
- else
- TX_DESC_CTRL(idx) = ((nFrameSize-1) & EMAC_TCTRL_SIZE) | (EMAC_TCTRL_INT);
-
- return dp;
-}
-
-/*********************************************************************//**
- * @brief Increase the TxProduceIndex (after writting to the Transmit buffer
- * to enable the Transmit buffer) and wrap-around the index if
- * it reaches the maximum Transmit Number
- * @param[in] None
- * @return None
- **********************************************************************/
-void EMAC_UpdateTxProduceIndex(void)
-{
- // Get current Tx produce index
- uint32_t idx = LPC_EMAC->TxProduceIndex;
-
- /* Start frame transmission */
- if (++idx == LPC_EMAC->TxDescriptorNumber + 1) idx = 0;
- LPC_EMAC->TxProduceIndex = idx;
-}
-
-/*********************************************************************//**
- * @brief Get current status value of receive data (due to TxProduceIndex)
- * @param[in] None
- * @return Current value of receive data (due to TxProduceIndex)
- **********************************************************************/
-uint32_t EMAC_GetTxFrameStatus(void)
-{
- uint32_t idx;
-
- idx = LPC_EMAC->TxProduceIndex;
- return (TX_STAT_INFO(idx));
-}
-
-/*********************************************************************//**
- * @brief Write data to Tx packet data buffer at current index due to
- * TxProduceIndex
- * @param[in] pDataStruct store the address and the size of buffer that saves data.
- * @return None
- **********************************************************************/
-void EMAC_WritePacketBuffer(EMAC_PACKETBUF_Type *pDataStruct)
-{
- uint16_t* pDest;
- uint16_t* pSource = (uint16_t*)pDataStruct->pbDataBuf;
- uint32_t size = pDataStruct->ulDataLen;
- int32_t frame_num;
- uint32_t tmp;
- uint32_t max_frame_size = LPC_EMAC->MAXF;
-
- size = (size + 1) & 0xFFFE; // round Size up to next even number
- frame_num = size/max_frame_size;
-
- if(size == 0)
- return;
-
- while(frame_num >= 0)
- {
- tmp = (frame_num > 0)? max_frame_size:size;
-
- if(tmp == 0)
- break;
-
- // Setup descriptors and data
- if(frame_num == 0)
- pDest = (uint16_t*)EMAC_AllocTxBuff(tmp, 1); // last frame
- else
- pDest = (uint16_t*)EMAC_AllocTxBuff(tmp, 0);
-
- // Copy data
- while (tmp > 0)
- {
- *pDest++ = *pSource++;
- tmp -= 2;
- }
- frame_num--;
- size -= tmp;
-
- // Update produce index
- EMAC_UpdateTxProduceIndex();
- }
-}
-
-
-/*********************************************************************//**
- * @brief Get current status value of receive data (due to RxConsumeIndex)
- * @param[in] None
- * @return Current value of receive data (due to RxConsumeIndex)
- **********************************************************************/
-uint32_t EMAC_GetRxFrameStatus(void)
-{
- uint32_t idx;
-
- idx = LPC_EMAC->RxConsumeIndex;
- return (RX_STAT_INFO(idx));
-}
-
-
-/*********************************************************************//**
- * @brief Get size of current Received data in received buffer (due to
- * RxConsumeIndex)
- * @param[in] None
- * @return Size of received data
- **********************************************************************/
-uint32_t EMAC_GetRxFrameSize(void)
-{
- uint32_t idx;
-
- idx = LPC_EMAC->RxConsumeIndex;
-
- return (((RX_STAT_INFO(idx)) & EMAC_RINFO_SIZE)+1);
-}
-
-
-/*********************************************************************//**
- * @brief Get the address of TX_DESC_PACKET buffer so that user can access from application
- * @param[in] None
- * @return Address of the TX_DESC_PACKET buffer
- **********************************************************************/
-
-uint32_t EMAC_GetRxBuffer(void)
-{
- uint32_t idx;
-
- idx = LPC_EMAC->RxConsumeIndex;
-
- return RX_DESC_PACKET(idx);
- }
-
-
-/*********************************************************************//**
- * @brief Increase the RxConsumeIndex (after reading the Receive buffer
- * to release the Receive buffer) and wrap-around the index if
- * it reaches the maximum Receive Number
- * @param[in] None
- * @return None
- **********************************************************************/
-void EMAC_UpdateRxConsumeIndex(void)
-{
- // Get current Rx consume index
- uint32_t idx = LPC_EMAC->RxConsumeIndex;
-
- /* Release frame from EMAC buffer */
- if (++idx == EMAC_NUM_RX_FRAG) idx = 0;
-
- LPC_EMAC->RxConsumeIndex = idx;
-}
-
-/*********************************************************************//**
- * @brief Standard EMAC IRQ Handler. This sub-routine will check
- * these following interrupt and call the call-back function
- * if they're already installed:
- * - Overrun Error interrupt in RX Queue
- * - Receive Error interrupt: AlignmentError, RangeError,
- * LengthError, SymbolError, CRCError or NoDescriptor or Overrun
- * - RX Finished Process Descriptors interrupt (ProduceIndex == ConsumeIndex)
- * - Receive Done interrupt: Read received frame to the internal buffer
- * - Transmit Under-run interrupt
- * - Transmit errors interrupt : LateCollision, ExcessiveCollision
- * and ExcessiveDefer, NoDescriptor or Under-run
- * - TX Finished Process Descriptors interrupt (ProduceIndex == ConsumeIndex)
- * - Transmit Done interrupt
- * - Interrupt triggered by software
- * - Interrupt triggered by a Wakeup event detected by the receive filter
- * @param[in] None
- * @return None
- **********************************************************************/
-void ENET_IRQHandler(void)
-{
- /* EMAC Ethernet Controller Interrupt function. */
- uint32_t int_stat;
- int32_t RxLen;
-
- // Get EMAC interrupt status
- while ((int_stat = (LPC_EMAC->IntStatus & LPC_EMAC->IntEnable)) != 0)
- {
- // Clear interrupt status
- LPC_EMAC->IntClear = int_stat;
-
- if(int_stat & (EMAC_INT_RX_OVERRUN |EMAC_INT_RX_ERR ))
- {
- uint32_t ulFrameSts = EMAC_GetRxFrameStatus();
- uint32_t ulErrCode = 0;
-
- ulErrCode |= (ulFrameSts & EMAC_RINFO_CRC_ERR) ? EMAC_CRC_ERR:0;
- ulErrCode |= (ulFrameSts & EMAC_RINFO_SYM_ERR) ? EMAC_SYMBOL_ERR:0;
- ulErrCode |= (ulFrameSts & EMAC_RINFO_LEN_ERR) ? EMAC_LENGTH_ERR:0;
- ulErrCode |= (ulFrameSts & EMAC_RINFO_ALIGN_ERR) ? EMAC_ALIGN_ERR:0;
- ulErrCode |= (ulFrameSts & EMAC_RINFO_OVERRUN) ? EMAC_OVERRUN_ERR:0;
- ulErrCode |= (ulFrameSts & EMAC_RINFO_NO_DESCR) ? EMAC_RX_NO_DESC_ERR:0;
- ulErrCode |= (ulFrameSts & EMAC_RINFO_FAIL_FILT) ? EMAC_FILTER_FAILED_ERR:0;
-
- if(ulErrCode == 0)
- {
- /* Note:
- * The EMAC doesn't distinguish the frame type and frame length,
- * so, e.g. when the IP(0x8000) or ARP(0x0806) packets are received,
- * it compares the frame type with the max length and gives the
- * "Range" error. In fact, this bit is not an error indication,
- * but simply a statement by the chip regarding the status of
- * the received frame
- */
- int_stat &= ~EMAC_INT_RX_ERR;
- }
- else
- {
- if(EMAC_Configs.pfnErrorReceive != NULL)
- EMAC_Configs.pfnErrorReceive(ulErrCode);
- }
- }
-
- if(int_stat & (EMAC_INT_TX_UNDERRUN|EMAC_INT_TX_ERR ))
- {
- uint32_t ulFrameSts = EMAC_GetTxFrameStatus();
- uint32_t ulErrCode = 0;
-
- ulErrCode |= (ulFrameSts & EMAC_TINFO_EXCESS_DEF) ? EMAC_EXCESSIVE_DEFER_ERR:0;
- ulErrCode |= (ulFrameSts & EMAC_TINFO_EXCESS_COL) ? EMAC_EXCESSIVE_COLLISION_ERR:0;
- ulErrCode |= (ulFrameSts & EMAC_TINFO_LATE_COL) ? EMAC_LATE_COLLISION_ERR:0;
- ulErrCode |= (ulFrameSts & EMAC_TINFO_UNDERRUN) ? EMAC_UNDERRUN_ERR:0;
- ulErrCode |= (ulFrameSts & EMAC_TINFO_NO_DESCR) ? EMAC_TX_NO_DESC_ERR:0;
- if(EMAC_Configs.pfnErrorReceive != NULL)
- EMAC_Configs.pfnErrorReceive(ulErrCode);
- }
-
- if(int_stat & EMAC_INT_RX_DONE)
- {
-
- /* Packet received. */
- if(EMAC_GetBufferSts(EMAC_RX_BUFF) != EMAC_BUFF_EMPTY)
- {
- // Get data size
- RxLen = EMAC_GetRxFrameSize();
- if(RxLen > 0)
- {
- // trip out 4-bytes CRC field, note that length in (-1) style format
- RxLen -= 3;
-
- if((EMAC_GetRxFrameStatus() & EMAC_RINFO_ERR_MASK )== 0)
- {
- uint16_t *pDest = (uint16_t*) &saFrameBuffers[sbCurrFrameID][sulCurrFrameSz];
- uint16_t *pSource = (uint16_t*)EMAC_GetRxBuffer();
- sulCurrFrameSz += RxLen;
-
- if(sulCurrFrameSz >= EMAC_MAX_FRAME_SIZE)
- {
- sulCurrFrameSz = 0;
- if(EMAC_Configs.pfnErrorReceive != NULL)
- EMAC_Configs.pfnErrorReceive(EMAC_LENGTH_ERR);
- }
- else
- {
- // Copy data
- while (RxLen > 0)
- {
- *pDest++ = *pSource++;
- RxLen -= 2;
- }
- if(EMAC_GetRxFrameStatus() & EMAC_RINFO_LAST_FLAG)
- {
-
- if(EMAC_Configs.pfnFrameReceive != NULL)
- {
- EMAC_Configs.pfnFrameReceive((uint16_t*)saFrameBuffers[sbCurrFrameID], sulCurrFrameSz);
- }
- sulCurrFrameSz = 0;
- sbCurrFrameID ++;
- if(sbCurrFrameID >= EMAC_MAX_FRAME_NUM)
- sbCurrFrameID = 0;
- }
- /* Release frame from EMAC buffer */
- EMAC_UpdateRxConsumeIndex();
- }
- }
- }
- }
-
- }
-
- if(int_stat & EMAC_INT_TX_FIN && (EMAC_Configs.pfnTransmitFinish != NULL))
- {
- EMAC_Configs.pfnTransmitFinish();
- }
-
- if(int_stat & EMAC_INT_SOFT_INT && (EMAC_Configs.pfnSoftInt!= NULL))
- {
- EMAC_Configs.pfnSoftInt();
- }
-
- if(int_stat & EMAC_INT_WAKEUP && (EMAC_Configs.pfnWakeup!= NULL))
- {
- EMAC_Configs.pfnWakeup();
- }
-
- }
-}
-
-
-/*********************************************************************//**
- * @brief Enable/Disable hash filter functionality for specified destination
- * MAC address in EMAC module
- * @param[in] dstMAC_addr Pointer to the first MAC destination address, should
- * be 6-bytes length, in order LSB to the MSB
- * @param[in] NewState New State of this command, should be:
- * - ENABLE.
- * - DISABLE.
- * @return None
- *
- * Note:
- * The standard Ethernet cyclic redundancy check (CRC) function is calculated from
- * the 6 byte destination address in the Ethernet frame (this CRC is calculated
- * anyway as part of calculating the CRC of the whole frame), then bits [28:23] out of
- * the 32 bits CRC result are taken to form the hash. The 6 bit hash is used to access
- * the hash table: it is used as an index in the 64 bit HashFilter register that has been
- * programmed with accept values. If the selected accept value is 1, the frame is
- * accepted.
- **********************************************************************/
-void EMAC_SetHashFilter(uint8_t dstMAC_addr[], FunctionalState NewState)
-{
- uint32_t *pReg;
- uint32_t tmp;
- int32_t crc;
-
- // Calculate the CRC from the destination MAC address
- crc = EMAC_CRCCalc(dstMAC_addr, 6);
- // Extract the value from CRC to get index value for hash filter table
- crc = (crc >> 23) & 0x3F;
-
- pReg = (crc > 31) ? ((uint32_t *)&LPC_EMAC->HashFilterH) \
- : ((uint32_t *)&LPC_EMAC->HashFilterL);
- tmp = (crc > 31) ? (crc - 32) : crc;
- if (NewState == ENABLE)
- {
- (*pReg) |= (1UL << tmp);
- }
- else
- {
- (*pReg) &= ~(1UL << tmp);
- }
-
-}
-
-
-/*********************************************************************//**
- * @brief Calculates CRC code for number of bytes in the frame
- * @param[in] frame_no_fcs Pointer to the first byte of the frame
- * @param[in] frame_len length of the frame without the FCS
- * @return the CRC as a 32 bit integer
- **********************************************************************/
-int32_t EMAC_CRCCalc(uint8_t frame_no_fcs[], int32_t frame_len)
-{
- int i; // iterator
- int j; // another iterator
- char byte; // current byte
- int crc; // CRC result
- int q0, q1, q2, q3; // temporary variables
-
- crc = 0xFFFFFFFF;
-
- for (i = 0; i < frame_len; i++)
- {
- byte = *frame_no_fcs++;
- for (j = 0; j < 2; j++)
- {
- if (((crc >> 28) ^ (byte >> 3)) & 0x00000001)
- {
- q3 = 0x04C11DB7;
- }
- else
- {
- q3 = 0x00000000;
- }
-
- if (((crc >> 29) ^ (byte >> 2)) & 0x00000001)
- {
- q2 = 0x09823B6E;
- }
- else
- {
- q2 = 0x00000000;
- }
-
- if (((crc >> 30) ^ (byte >> 1)) & 0x00000001)
- {
- q1 = 0x130476DC;
- }
- else
- {
- q1 = 0x00000000;
- }
-
- if (((crc >> 31) ^ (byte >> 0)) & 0x00000001)
- {
- q0 = 0x2608EDB8;
- }
- else
- {
- q0 = 0x00000000;
- }
-
- crc = (crc << 4) ^ q3 ^ q2 ^ q1 ^ q0;
-
- byte >>= 4;
- }
- }
-
- return crc;
-}
-
-/*********************************************************************//**
- * @brief Enable/Disable Filter mode for each specified type EMAC peripheral
- * @param[in] ulFilterMode Filter mode, should be:
- * - EMAC_RFC_UCAST_EN: all frames of unicast types
- * will be accepted
- * - EMAC_RFC_BCAST_EN: broadcast frame will be
- * accepted
- * - EMAC_RFC_MCAST_EN: all frames of multicast
- * types will be accepted
- * - EMAC_RFC_UCAST_HASH_EN: The imperfect hash
- * filter will be applied to unicast addresses
- * - EMAC_RFC_MCAST_HASH_EN: The imperfect hash
- * filter will be applied to multicast addresses
- * - EMAC_RFC_PERFECT_EN: the destination address
- * will be compared with the 6 byte station address
- * programmed in the station address by the filter
- * - EMAC_RFC_MAGP_WOL_EN: the result of the magic
- * packet filter will generate a WoL interrupt when
- * there is a match
- * - EMAC_RFC_PFILT_WOL_EN: the result of the perfect address
- * matching filter and the imperfect hash filter will
- * generate a WoL interrupt when there is a match
- * @param[in] NewState New State of this command, should be:
- * - ENABLE
- * - DISABLE
- * @return None
- **********************************************************************/
-void EMAC_SetFilterMode(uint32_t ulFilterMode, FunctionalState NewState)
-{
- if (NewState == ENABLE)
- {
- LPC_EMAC->RxFilterCtrl |= ulFilterMode;
-
- if((ulFilterMode & EMAC_RFC_MCAST_HASH_EN) &&
- ((ulFilterMode & EMAC_RFC_MCAST_EN) == 0))
- {
- LPC_EMAC->RxFilterCtrl &= ~EMAC_RFC_MCAST_EN;
- }
- if((ulFilterMode & EMAC_RFC_UCAST_HASH_EN) &&
- ((ulFilterMode & EMAC_RFC_UCAST_EN) == 0))
- {
- LPC_EMAC->RxFilterCtrl &= ~EMAC_RFC_UCAST_EN;
- }
- }
- else
- {
- LPC_EMAC->RxFilterCtrl &= ~ulFilterMode;
- }
-}
-
-/*********************************************************************//**
- * @brief Get status of Wake On LAN Filter for each specified
- * type in EMAC peripheral, clear this status if it is set
- * @param[in] ulFilterMode WoL Filter mode, should be:
- * - EMAC_WOL_UCAST: unicast frames caused WoL
- * - EMAC_WOL_UCAST: broadcast frame caused WoL
- * - EMAC_WOL_MCAST: multicast frame caused WoL
- * - EMAC_WOL_UCAST_HASH: unicast frame that passes the
- * imperfect hash filter caused WoL
- * - EMAC_WOL_MCAST_HASH: multicast frame that passes the
- * imperfect hash filter caused WoL
- * - EMAC_WOL_PERFECT:perfect address matching filter
- * caused WoL
- * - EMAC_WOL_RX_FILTER: the receive filter caused WoL
- * - EMAC_WOL_MAG_PACKET: the magic packet filter caused WoL
- * @return SET/RESET
- **********************************************************************/
-FlagStatus EMAC_GetWoLStatus(uint32_t ulWoLMode)
-{
- if (LPC_EMAC->RxFilterWoLStatus & ulWoLMode)
- {
- LPC_EMAC->RxFilterWoLClear = ulWoLMode;
-
- return SET;
- }
- else
- {
- return RESET;
- }
-}
-
-
-
-
-
-
-/*********************************************************************//**
- * @brief Enable/Disable interrupt for each type in EMAC
- * @param[in] ulIntType Interrupt Type, should be:
- * - EMAC_INT_RX_OVERRUN: Receive Overrun
- * - EMAC_INT_RX_ERR: Receive Error
- * - EMAC_INT_RX_FIN: Receive Descriptor Finish
- * - EMAC_INT_RX_DONE: Receive Done
- * - EMAC_INT_TX_UNDERRUN: Transmit Under-run
- * - EMAC_INT_TX_ERR: Transmit Error
- * - EMAC_INT_TX_FIN: Transmit descriptor finish
- * - EMAC_INT_TX_DONE: Transmit Done
- * - EMAC_INT_SOFT_INT: Software interrupt
- * - EMAC_INT_WAKEUP: Wakeup interrupt
- * @param[in] NewState New State of this function, should be:
- * - ENABLE.
- * - DISABLE.
- * @return None
- **********************************************************************/
-void EMAC_IntCmd(uint32_t ulIntType, FunctionalState NewState)
-{
- if (NewState == ENABLE)
- {
- LPC_EMAC->IntEnable |= ulIntType;
- }
- else
- {
- LPC_EMAC->IntEnable &= ~(ulIntType);
- }
-}
-
-/*********************************************************************//**
- * @brief Check whether if specified interrupt flag is set or not
- * for each interrupt type in EMAC and clear interrupt pending
- * if it is set.
- * @param[in] ulIntType Interrupt Type, should be:
- * - EMAC_INT_RX_OVERRUN: Receive Overrun
- * - EMAC_INT_RX_ERR: Receive Error
- * - EMAC_INT_RX_FIN: Receive Descriptor Finish
- * - EMAC_INT_RX_DONE: Receive Done
- * - EMAC_INT_TX_UNDERRUN: Transmit Under-run
- * - EMAC_INT_TX_ERR: Transmit Error
- * - EMAC_INT_TX_FIN: Transmit descriptor finish
- * - EMAC_INT_TX_DONE: Transmit Done
- * - EMAC_INT_SOFT_INT: Software interrupt
- * - EMAC_INT_WAKEUP: Wakeup interrupt
- * @return New state of specified interrupt (SET or RESET)
- **********************************************************************/
-IntStatus EMAC_IntGetStatus(uint32_t ulIntType)
-{
- if (LPC_EMAC->IntStatus & ulIntType)
- {
- LPC_EMAC->IntClear = ulIntType;
- return SET;
- }
- else
- {
- return RESET;
- }
-}
-
-
-
-/**
- * @}
- */
-
-/**
- * @}
- */
-#endif /*_EMAC*/
diff --git a/bsp/lpc408x/Libraries/Drivers/source/lpc_emc.c b/bsp/lpc408x/Libraries/Drivers/source/lpc_emc.c
deleted file mode 100644
index 0ede2221e7..0000000000
--- a/bsp/lpc408x/Libraries/Drivers/source/lpc_emc.c
+++ /dev/null
@@ -1,1398 +0,0 @@
-/**********************************************************************
-* $Id$ lpc_emc.c 2011-06-02
-*//**
-* @file lpc_emc.c
-* @brief Contains all functions support for EMC firmware library
-* on LPC
-* @version 1.0
-* @date 02. June. 2011
-* @author NXP MCU SW Application Team
-*
-* Copyright(C) 2011, NXP Semiconductor
-* All rights reserved.
-*
-***********************************************************************
-* Software that is described herein is for illustrative purposes only
-* which provides customers with programming information regarding the
-* products. This software is supplied "AS IS" without any warranties.
-* NXP Semiconductors assumes no responsibility or liability for the
-* use of the software, conveys no license or title under any patent,
-* copyright, or mask work right to the product. NXP Semiconductors
-* reserves the right to make changes in the software without
-* notification. NXP Semiconductors also make 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'
-* relevant copyright 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.
-**********************************************************************/
-#ifdef __BUILD_WITH_EXAMPLE__
-#include "lpc_libcfg.h"
-#else
-#include "lpc_libcfg_default.h"
-#endif /* __BUILD_WITH_EXAMPLE__ */
-#ifdef _EMC
-
-#include "lpc_emc.h"
-#include "lpc_clkpwr.h"
-#include "lpc_pinsel.h"
-
-/* Peripheral group ----------------------------------------------------------- */
-/** @addtogroup EMC
- * @{
- */
-
-/** @defgroup EMC_Public_Functions
- * @{
- */
-
-/*********************************************************************
- * @brief Calculate refresh timer (the multiple of 16 CCLKs)
- * @param[in] freq - frequency of EMC Clk
- * @param[in] time - micro second
- * @return None
- **********************************************************************/
-uint32_t EMC_SDRAM_REFRESH(uint32_t time)
-{
- uint32_t emc_freq = CLKPWR_GetCLK(CLKPWR_CLKTYPE_EMC);
- return (((uint64_t)((uint64_t)time * emc_freq)/16000000ull)+1);
-}
-/*********************************************************************
- * @brief Calculate EMC Clock from nano second
- * @param[in] time - nano second
- * @return None
- **********************************************************************/
-uint32_t EMC_NS2CLK(uint32_t time){
- uint32_t emc_freq = CLKPWR_GetCLK(CLKPWR_CLKTYPE_EMC);
- return (((uint64_t)time*emc_freq/1000000000ull));
-}
-
-/*********************************************************************
- * @brief Power on EMC Block
- * @param[in] None
- * @return None
- **********************************************************************/
-EMC_FUNC_CODE EMC_PwrOn(void)
-{
- // If CPU clock is > 80 MHz, then divide it by two to create the EMC clock
- if(CLKPWR_GetCLK(CLKPWR_CLKTYPE_CPU) > 80000000) {
- CLKPWR_SetCLKDiv(CLKPWR_CLKTYPE_EMC, 1); // CPU clock / 2
- } else {
- CLKPWR_SetCLKDiv(CLKPWR_CLKTYPE_EMC, 0); // Same clock as CPU
- }
-
- // Power on
- CLKPWR_ConfigPPWR(CLKPWR_PCONP_PCEMC, ENABLE);
-
- // Enable
- LPC_EMC->Control = EMC_Control_E;
-
- return EMC_FUNC_OK;
-}
-/*********************************************************************//**
- * @brief Initialize external dynamic memory
- * @param[in] pConfig Configuration
- * @return EMC_FUNC_OK/EMC_FUNC_INVALID_PARAM/EMC_FUNC_ERR
- **********************************************************************/
-EMC_FUNC_CODE DynMem_Init(EMC_DYN_MEM_Config_Type* pConfig)
-{
- uint32_t i = 0;
- EMC_FUNC_CODE ret = EMC_FUNC_OK;
-
- /* Pin configuration:
- * P2.16 - /EMC_CAS
- * P2.17 - /EMC_RAS
- * P2.18 - EMC_CLK[0]
- * P2.19 - EMC_CLK[1]
- *
- * P2.20 - EMC_DYCS0
- * P2.21 - EMC_DYCS1
- * P2.22 - EMC_DYCS2
- * P2.23 - EMC_DYCS3
- *
- * P2.24 - EMC_CKE0
- * P2.25 - EMC_CKE1
- * P2.26 - EMC_CKE2
- * P2.27 - EMC_CKE3
- *
- * P2.28 - EMC_DQM0
- * P2.29 - EMC_DQM1
- * P2.30 - EMC_DQM2
- * P2.31 - EMC_DQM3
- *
- * P3.0-P3.31 - EMC_D[0-31]
- * P4.0-P4.23 - EMC_A[0-23]
- * P5.0-P5.1 - EMC_A[24-25]
- *
- * P4.25 - EMC_WE
- */
- PINSEL_ConfigPin(2,16,1);
- PINSEL_ConfigPin(2,17,1);
- PINSEL_ConfigPin(2,18,1);
- PINSEL_ConfigPin(2,19,1);
- PINSEL_ConfigPin(2,20,1);
- PINSEL_ConfigPin(2,21,1);
- PINSEL_ConfigPin(2,22,1);
- PINSEL_ConfigPin(2,23,1);
- PINSEL_ConfigPin(2,24,1);
- PINSEL_ConfigPin(2,25,1);
- PINSEL_ConfigPin(2,26,1);
- PINSEL_ConfigPin(2,27,1);
- PINSEL_ConfigPin(2,28,1);
- PINSEL_ConfigPin(2,29,1);
- PINSEL_ConfigPin(2,30,1);
- PINSEL_ConfigPin(2,31,1);
-
- for(i = 0; i < 32; i++)
- {
- PINSEL_ConfigPin(3,i,1);
- PINSEL_ConfigPin(4,i,1);
- }
- PINSEL_ConfigPin(5,0,1);
- PINSEL_ConfigPin(5,1,1);
-
-
- // Power On
- ret |= EMC_PwrOn();
-
- /*Init SDRAM controller*/
- LPC_SC->EMCDLYCTL |= (8<<0);
- /*Set data read delay*/
- LPC_SC->EMCDLYCTL |=(8<<8);
- LPC_SC->EMCDLYCTL |= (0x08 <<16);
-
- ret |= EMC_ConfigEndianMode(EMC_Config_Little_Endian_Mode);
-
- /* Dynamic memory setting */
- ret |= EMC_DynCtrlSelfRefresh(EMC_DYNAMIC_CTRL_SR_NORMALMODE);
- ret |= EMC_DynCtrlPowerDownMode(EMC_DYNAMIC_CTRL_DP_NORMAL);
- ret |= EMC_DynCtrlClockEnable(EMC_DYNAMIC_CTRL_CE_ALLCLK_HI);
- ret |= EMC_DynCtrlMMC(EMC_DYNAMIC_CTRL_MMC_CLKOUT_ENABLED);
- ret |= EMC_DynCtrlClockControl(EMC_DYNAMIC_CTRL_CE_CLKOUT_CONT);
-
- /* Timing */
- ret |= EMC_SetDynMemoryParameter(EMC_DYN_MEM_REFRESH_TIMER, pConfig->RefreshTime);
- ret |= EMC_SetDynMemoryParameter(EMC_DYN_MEM_READ_CONFIG, pConfig->ReadConfig);
- ret |= EMC_SetDynMemoryParameter(EMC_DYN_MEM_TRP, pConfig->PrechargeCmdPeriod);
- ret |= EMC_SetDynMemoryParameter(EMC_DYN_MEM_TRAS, pConfig->Active2PreChargeTime);
- ret |= EMC_SetDynMemoryParameter(EMC_DYN_MEM_TSREX, pConfig->SeftRefreshExitTime);
- ret |= EMC_SetDynMemoryParameter(EMC_DYN_MEM_TAPR, pConfig->DataOut2ActiveTime);
- ret |= EMC_SetDynMemoryParameter(EMC_DYN_MEM_TDAL, pConfig->DataIn2ActiveTime);
- ret |= EMC_SetDynMemoryParameter(EMC_DYN_MEM_TWR, pConfig->WriteRecoveryTime);
- ret |= EMC_SetDynMemoryParameter(EMC_DYN_MEM_TRC, pConfig->Active2ActivePeriod);
- ret |= EMC_SetDynMemoryParameter(EMC_DYN_MEM_TRFC, pConfig->AutoRefrehPeriod);
- ret |= EMC_SetDynMemoryParameter(EMC_DYN_MEM_TXSR, pConfig->ExitSelfRefreshTime);
- ret |= EMC_SetDynMemoryParameter(EMC_DYN_MEM_TRRD, pConfig->ActiveBankLatency);
- ret |= EMC_SetDynMemoryParameter(EMC_DYN_MEM_TMRD, pConfig->LoadModeReg2Active);
- ret |= EMC_DynMemRAS(pConfig->CSn,pConfig->RASLatency);
- ret |= EMC_DynMemCAS(pConfig->CSn,pConfig->CASLatency);
-
- ret |= EMC_DynMemConfigMD(pConfig->CSn,EMC_DYNAMIC_CFG_MEMDEV_SDRAM);
- ret |= EMC_DynMemConfigAM(pConfig->CSn, pConfig->AddrBusWidth, pConfig->AddrMap, pConfig->DataWidth, pConfig->ChipSize);
-
- return ret;
-}
-
-/*********************************************************************//**
- * @brief Initialize external static memory
- * @param[in] pConfig Configuration
- * @return EMC_FUNC_OK/EMC_FUNC_INVALID_PARAM/EMC_FUNC_ERR
- **********************************************************************/
-EMC_FUNC_CODE StaticMem_Init(EMC_STATIC_MEM_Config_Type* pConfig)
-{
- uint32_t i;
- EMC_FUNC_CODE ret = EMC_FUNC_OK;
- /* Pin configuration:
- * P4.30 - /EMC_CS0
- * P4.31 - /EMC_CS1
- * P2.14 - /EMC_CS2
- * P2.15 - /EMC_CS3
- *
- *
- * P3.0-P3.31 - EMC_D[0-31]
- * P4.0-P4.23 - EMC_A[0-23]
- * P5.0-P5.1 - EMC_A[24-25]
- *
- * P4.24 - /EMC_OE
- * P4.25 - /EMC_WE
- *
-
- */
- PINSEL_ConfigPin(2,14,1);
- PINSEL_ConfigPin(2,15,1);
-
- for(i = 0; i < 32; i++)
- {
- PINSEL_ConfigPin(3,i,1);
- PINSEL_ConfigPin(4,i,1);
- }
- PINSEL_ConfigPin(5,0,1);
- PINSEL_ConfigPin(5,1,1);
-
- // Power On
- ret |= EMC_PwrOn();
-
- // Configuration
- if(pConfig->AddressMirror)
- {
- LPC_EMC->Control |= EMC_Control_M;
- }
-
- ret |= EMC_StaMemConfigMW(pConfig->CSn,pConfig->DataWidth);
-
- if(pConfig->PageMode)
- ret |= EMC_StaMemConfigPM(pConfig->CSn,EMC_CFG_PM_ASYNC_ENABLE);
- else
- ret |= EMC_StaMemConfigPM(pConfig->CSn,EMC_CFG_PM_DISABLE);
-
- if(pConfig->ByteLane)
- ret |= EMC_StaMemConfigPB(pConfig->CSn, EMC_CFG_BYTELAND_READ_BITSLOW);
- else
- ret |= EMC_StaMemConfigPB(pConfig->CSn, EMC_CFG_BYTELAND_READ_BITSHIGH);
-
- if(pConfig->ExtendedWait)
- ret |= EMC_StaMemConfigEW(pConfig->CSn,EMC_CFG_EW_ENABLED);
- else
- ret |= EMC_StaMemConfigEW(pConfig->CSn,EMC_CFG_EW_DISABLED);
-
- // Timing
- ret |= EMC_SetStaMemoryParameter(pConfig->CSn,EMC_STA_MEM_WAITWEN, pConfig->WaitWEn);
- ret |= EMC_SetStaMemoryParameter(pConfig->CSn,EMC_STA_MEM_WAITOEN, pConfig->WaitOEn);
- ret |= EMC_SetStaMemoryParameter(pConfig->CSn,EMC_STA_MEM_WAITRD, pConfig->WaitRd);
- ret |= EMC_SetStaMemoryParameter(pConfig->CSn,EMC_STA_MEM_WAITPAGE, pConfig->WaitPage);
- ret |= EMC_SetStaMemoryParameter(pConfig->CSn,EMC_STA_MEM_WAITWR, pConfig->WaitWr);
- ret |= EMC_SetStaMemoryParameter(pConfig->CSn,EMC_STA_MEM_WAITTURN, pConfig->WaitTurn);
-
-
- return ret;
-}
-
-/*********************************************************************//**
- * @brief EMC initialize (power on block, config EMC pins).
- * @param[in] None
- * @return None
- **********************************************************************/
-EMC_FUNC_CODE EMC_Init(void)
-{
- uint8_t i;
- // If CPU clock is > 80 MHz, then divide it by two to create the EMC clock
- if(CLKPWR_GetCLK(CLKPWR_CLKTYPE_CPU) > 80000000) {
- CLKPWR_SetCLKDiv(CLKPWR_CLKTYPE_EMC, 1); // CPU clock / 2
- } else {
- CLKPWR_SetCLKDiv(CLKPWR_CLKTYPE_EMC, 0); // Same clock as CPU
- }
-
- LPC_SC->PCONP |= 0x00000800;
- LPC_SC->EMCDLYCTL = 0x00001010;
- LPC_EMC->Control = 0x00000001;
- LPC_EMC->Config = 0x00000000;
-
- /* Pin configuration:
- * P2.14 - /EMC_CS2
- * P2.15 - /EMC_CS3
- *
- * P2.16 - /EMC_CAS
- * P2.17 - /EMC_RAS
- * P2.18 - EMC_CLK[0]
- * P2.19 - EMC_CLK[1]
- *
- * P2.20 - EMC_DYCS0
- * P2.21 - EMC_DYCS1
- * P2.22 - EMC_DYCS2
- * P2.23 - EMC_DYCS3
- *
- * P2.24 - EMC_CKE0
- * P2.25 - EMC_CKE1
- * P2.26 - EMC_CKE2
- * P2.27 - EMC_CKE3
- *
- * P2.28 - EMC_DQM0
- * P2.29 - EMC_DQM1
- * P2.30 - EMC_DQM2
- * P2.31 - EMC_DQM3
- *
- * P3.0-P3.31 - EMC_D[0-31]
- * P4.0-P4.23 - EMC_A[0-23]
- * P5.0-P5.1 - EMC_A[24-25]
- *
- * P4.24 - /EMC_OE
- * P4.25 - /EMC_WE
- *
- * P4.30 - /EMC_CS0
- * P4.31 - /EMC_CS1
- */
- PINSEL_ConfigPin(2,14,1);
- PINSEL_ConfigPin(2,15,1);
- PINSEL_ConfigPin(2,16,1);
- PINSEL_ConfigPin(2,17,1);
- PINSEL_ConfigPin(2,18,1);
- PINSEL_ConfigPin(2,19,1);
- PINSEL_ConfigPin(2,20,1);
- PINSEL_ConfigPin(2,21,1);
- PINSEL_ConfigPin(2,22,1);
- PINSEL_ConfigPin(2,23,1);
- PINSEL_ConfigPin(2,24,1);
- PINSEL_ConfigPin(2,25,1);
- PINSEL_ConfigPin(2,26,1);
- PINSEL_ConfigPin(2,27,1);
- PINSEL_ConfigPin(2,28,1);
- PINSEL_ConfigPin(2,29,1);
- PINSEL_ConfigPin(2,30,1);
- PINSEL_ConfigPin(2,31,1);
-
- for(i = 0; i < 32; i++)
- {
- PINSEL_ConfigPin(3,i,1);
- PINSEL_ConfigPin(4,i,1);
- }
- PINSEL_ConfigPin(5,0,1);
- PINSEL_ConfigPin(5,1,1);
-
- return EMC_FUNC_OK;
-}
-
-
-/*********************************************************************//**
- * @brief Configure Little Endian/Big Endian mode for EMC
- *
- * @param[in] endia_mode Endian mode, should be:
- *
- * - EMC_Config_Little_Endian_Mode: Little-endian mode
- *
- * - EMC_Config_Big_Endian_Mode : Big-endian mode
- *
- * @return EMC_FUNC_OK
- **********************************************************************/
-EMC_FUNC_CODE EMC_ConfigEndianMode(uint32_t endian_mode)
-{
- LPC_EMC->Config &= ~(EMC_Config_Endian_Mask);
- LPC_EMC->Config |= (endian_mode&EMC_Config_Endian_Mask);
- return EMC_FUNC_OK;
-}
-
-/****************** Group of Dynamic control functions************************/
-
-/*********************************************************************//**
- * @brief Set the dsvalue for dynamic clock enable bit
- *
- * @param[in] clock_enable clock enable mode, should be:
- *
- * - EMC_DYNAMIC_CTRL_CE_SAVEPWR: Clock enable of idle devices
- * are deasserted to save power
- *
- * - EMC_DYNAMIC_CTRL_CE_ALLCLK_HI: All clock enables are driven
- * HIGH continuously
- *
- * @return EMC_FUNC_CODE
- **********************************************************************/
-EMC_FUNC_CODE EMC_DynCtrlClockEnable(uint32_t clock_enable)
-{
- LPC_EMC->DynamicControl &= ~(EMC_DYNAMIC_CTRL_MEMCLK_EN_BMASK);
- LPC_EMC->DynamicControl |= clock_enable & EMC_DYNAMIC_CTRL_MEMCLK_EN_BMASK;
- return EMC_FUNC_OK;
-}
-
-
-/*********************************************************************//**
- * @brief Set the value for dynamic memory clock control: stops or
- * runs continuously
- *
- * @param[in] clock_control clock control mode, should be:
- *
- * - EMC_DYNAMIC_CTRL_CS_CLKOUT_STOP: CLKOUT stops when all
- * SDRAMs are idle and during self-refresh mode
- *
- * - EMC_DYNAMIC_CTRL_CS_CLKOUT_CONT: CLKOUT runs continuously
- *
- * @return EMC_FUNC_OK
- **********************************************************************/
-EMC_FUNC_CODE EMC_DynCtrlClockControl(int32_t clock_control)
-{
- LPC_EMC->DynamicControl &= ~EMC_DYNAMIC_CTRL_CLKCTRL_BMASK;
- LPC_EMC->DynamicControl |= clock_control & EMC_DYNAMIC_CTRL_CLKCTRL_BMASK;
- return EMC_FUNC_OK;
-}
-
-/*********************************************************************//**
- * @brief Switch the Self-refresh mode between normal and self-refresh mode
- *
- * @param[in] self_refresh_mode self refresh mode, should be:
- *
- * - EMC_DYNAMIC_CTRL_SR_NORMALMODE: Normal mode
- *
- * - EMC_DYNAMIC_CTRL_SR_SELFREFRESH: Enter self-refresh mode
- *
- * @return EMC_FUNC_OK
- **********************************************************************/
-EMC_FUNC_CODE EMC_DynCtrlSelfRefresh(uint32_t self_refresh_mode)
-{
- LPC_EMC->DynamicControl &= ~EMC_DYNAMIC_CTRL_SELFREFRESH_REQ_BMASK;
- LPC_EMC->DynamicControl =self_refresh_mode & EMC_DYNAMIC_CTRL_SELFREFRESH_REQ_BMASK;
- return EMC_FUNC_OK;
-}
-
-/*********************************************************************//**
- * @brief Enable/disable CLKOUT
- *
- * @param[in] MMC_val Memory clock control mode, should be:
- *
- * - EMC_DYNAMIC_CTRL_MMC_CLKOUT_ENABLED: CLKOUT enabled
- *
- * - EMC_DYNAMIC_CTRL_MMC_CLKOUT_DISABLED: CLKOUT disabled
- *
- * @return EMC_FUNC_OK
- **********************************************************************/
-EMC_FUNC_CODE EMC_DynCtrlMMC(uint32_t MMC_val)
-{
- LPC_EMC->DynamicControl &= ~EMC_DYNAMIC_CTRL_MMC_CLKOUTCTRL_BMASK;
- LPC_EMC->DynamicControl |=MMC_val & EMC_DYNAMIC_CTRL_MMC_CLKOUTCTRL_BMASK;
- return EMC_FUNC_OK;
-}
-
-/*********************************************************************//**
- * @brief Issue SDRAM command
- *
- * @param[in] SDRAM_command Command mode, should be:
- *
- * - EMC_DYNAMIC_CTRL_SDRAM_NORMAL: Issue SDRAM NORMAL operation command
- *
- * - EMC_DYNAMIC_CTRL_SDRAM_MODE: Issue SDRAM MODE command
- *
- * - EMC_DYNAMIC_CTRL_SDRAM_PALL: Issue SDRAM PALL (precharge all) command
- *
- * - EMC_DYNAMIC_CTRL_SDRAM_NOP: Issue SRAM NOP (no operation) command
- *
- * @return EMC_FUNC_OK
- **********************************************************************/
-EMC_FUNC_CODE EMC_DynCtrlSDRAMInit(uint32_t SDRAM_command)
-{
- LPC_EMC->DynamicControl &= ~EMC_DYNAMIC_CTRL_SDRAM_INIT_BMASK;
- LPC_EMC->DynamicControl |= SDRAM_command & EMC_DYNAMIC_CTRL_SDRAM_INIT_BMASK;
- return EMC_FUNC_OK;
-}
-
-/*********************************************************************//**
- * @brief Switch between Normal operation and deep sleep power mode
- *
- * @param[in] Power_command Low-power SDRAM deep-sleep mode, should be:
- *
- * - EMC_DYNAMIC_CTRL_DP_NORMAL: Normal operation
- *
- * - EMC_DYNAMIC_CTRL_DP_DEEPSLEEP: Enter deep-sleep mode
- *
- * @return EMC_FUNC_OK
- **********************************************************************/
-EMC_FUNC_CODE EMC_DynCtrlPowerDownMode(uint32_t Power_command)
-{
- LPC_EMC->DynamicControl &= ~EMC_DYNAMIC_CTRL_SDRAM_PWRMODE_BMASK;
- LPC_EMC->DynamicControl |= Power_command & EMC_DYNAMIC_CTRL_SDRAM_PWRMODE_BMASK;
- return EMC_FUNC_OK;
-}
-
-/*********************************************************************//**
- * @brief Set the value of EMC dynamic memory registers
- *
- * @param[in] par EMC register that will set value, should be:
- * - EMC_DYN_MEM_REFRESH_TIMER: Dynamic Refresh register
- * - EMC_DYN_MEM_READ_CONFIG: Dynamic Read Config register
- * - EMC_DYN_MEM_TRP: Dynamic RP register
- * - EMC_DYN_MEM_TRAS: Dynamic RAS register
- * - EMC_DYN_MEM_TSREX: Dynamic SREX register
- * - EMC_DYN_MEM_TAPR: Dynamic APR register
- * - EMC_DYN_MEM_TDAL: Dynamic DAL register
- * - EMC_DYN_MEM_TWR: Dynamic WR register
- * - EMC_DYN_MEM_TRC: Dynamic RC register
- * - EMC_DYN_MEM_TRFC: Dynamic RFC register
- * - EMC_DYN_MEM_TXSR: Dynamic XSR register
- * - EMC_DYN_MEM_TRRD: Dynamic RRD register
- * - EMC_DYN_MEM_TMRD: Dynamic MRD register
- *
- * @return EMC_FUNC_OK/EMC_FUNC_INVALID_PARAM
- **********************************************************************/
-EMC_FUNC_CODE EMC_SetDynMemoryParameter(EMC_DYN_MEM_PAR par, uint32_t val)
-{
- switch ( par)
- {
- case EMC_DYN_MEM_REFRESH_TIMER:
- LPC_EMC->DynamicRefresh = EMC_DynamicRefresh_REFRESH(val);
- break;
-
- case EMC_DYN_MEM_READ_CONFIG:
- LPC_EMC->DynamicReadConfig = EMC_DynamicReadConfig_RD(val);
- break;
-
- case EMC_DYN_MEM_TRP:
- LPC_EMC->DynamicRP = EMC_DynamictRP_tRP(val);
- break;
-
- case EMC_DYN_MEM_TRAS:
- LPC_EMC->DynamicRAS = EMC_DynamictRP_tRAS(val);
- break;
-
- case EMC_DYN_MEM_TSREX:
- LPC_EMC->DynamicSREX = EMC_DynamictRP_tSREX(val);
- break;
-
- case EMC_DYN_MEM_TAPR:
- LPC_EMC->DynamicAPR = EMC_DynamictAPR_tAPR(val);
- break;
-
- case EMC_DYN_MEM_TDAL:
- LPC_EMC->DynamicDAL =EMC_DynamictDAL_tDAL(val);
- break;
-
- case EMC_DYN_MEM_TWR:
- LPC_EMC->DynamicWR = EMC_DynamictWR_tWR(val);
- break;
-
- case EMC_DYN_MEM_TRC:
- LPC_EMC->DynamicRC = EMC_DynamictRC_tRC(val);
- break;
-
- case EMC_DYN_MEM_TRFC:
- LPC_EMC->DynamicRFC = EMC_DynamictRFC_tRFC(val);
- break;
-
- case EMC_DYN_MEM_TXSR:
- LPC_EMC->DynamicXSR = EMC_DynamictXSR_tXSR(val);
- break;
-
- case EMC_DYN_MEM_TRRD:
- LPC_EMC->DynamicRRD = EMC_DynamictRRD_tRRD(val);
- break;
-
- case EMC_DYN_MEM_TMRD:
- LPC_EMC->DynamicMRD = EMC_DynamictMRD_tMRD(val);
- break;
- default:
- return EMC_FUNC_INVALID_PARAM;
- }
- return EMC_FUNC_OK;
-}
-
-/*********************************************************************//**
- * @brief Configure the memory device
- *
- * @param[in] index index number, should be from 0 to 3
- *
- * @param[in] mem_dev Memory device, should be:
- *
- * - EMC_DYNAMIC_CFG_MEMDEV_SDRAM: SDRAM
- *
- * - EMC_DYNAMIC_CFG_MEMDEV_LOWPWR_SDRAM: Low-power SDRAM
- *
- *
- * @return EMC_FUNC_OK/EMC_FUNC_INVALID_PARAM
- **********************************************************************/
-EMC_FUNC_CODE EMC_DynMemConfigMD(uint32_t index , uint32_t mem_dev)
-{
- switch (index)
- {
- case 0:
- LPC_EMC->DynamicConfig0 &= ~EMC_DYNAMIC_CFG_MEMDEV_BMASK;
- LPC_EMC->DynamicConfig0 |= mem_dev & EMC_DYNAMIC_CFG_MEMDEV_BMASK;
- break;
-
- case 1:
- LPC_EMC->DynamicConfig1 &= ~EMC_DYNAMIC_CFG_MEMDEV_BMASK;
- LPC_EMC->DynamicConfig1 |= mem_dev & EMC_DYNAMIC_CFG_MEMDEV_BMASK;
- break;
-
- case 2:
- LPC_EMC->DynamicConfig2 &= ~EMC_DYNAMIC_CFG_MEMDEV_BMASK;
- LPC_EMC->DynamicConfig2 |= mem_dev & EMC_DYNAMIC_CFG_MEMDEV_BMASK;
- break;
-
- case 3:
- LPC_EMC->DynamicConfig3 &= ~EMC_DYNAMIC_CFG_MEMDEV_BMASK;
- LPC_EMC->DynamicConfig3 |= mem_dev & EMC_DYNAMIC_CFG_MEMDEV_BMASK;
- break;
- default:
- return EMC_FUNC_INVALID_PARAM;
- }
- return EMC_FUNC_OK;
-}
-
-/*********************************************************************//**
- * @brief Map the address for the memory device
- *
- * @param[in] index index number, should be from 0 to 3
- *
- * @param[in] add_mapped address where the memory will be mapped
- *
- * @return EMC_FUNC_OK
- **********************************************************************/
-EMC_FUNC_CODE EMC_DynMemConfigAM(uint32_t index ,
- uint8_t addr_bus_width, uint8_t addr_map,
- uint8_t data_bus_width,
- uint16_t chip_size)
-{
- const int chip_max_size = 512; // 512Mb
- uint8_t data_bus_max_size = 0;
- uint32_t add_mapped_p1 = 0x00, add_mapped_p2 = 0x00, add_mapped_p3 = 0x00;
- uint32_t tmp = 16, i = 0, j = 0;
-
- /* Get part 3 of address map */
- switch(addr_bus_width)
- {
- case 16:
- add_mapped_p3 = 0;
- data_bus_max_size = 16;
- break;
- case 32:
- add_mapped_p3 = 1;
- data_bus_max_size = 32;
- break;
- default:
- return EMC_FUNC_INVALID_PARAM;
- }
-
- /* Get part 2 of address map */
- add_mapped_p2 = EMC_DYNAMIC_CFG_ADD_MAP_P2(addr_map);
-
-
- /* Get part 1 of address map */
- if(chip_size == 16)
- {
- if(data_bus_width == 8)
- add_mapped_p1 = 0;
- else if(data_bus_width == 16)
- add_mapped_p1 = 1;
- else
- return EMC_FUNC_INVALID_PARAM;
- }
- else
- {
- while(1)
- {
- i++;
- tmp = 16*(0x01 << (i+1));
- if(tmp == chip_size)
- {
- for(j = 0; (8<<j)<=data_bus_max_size;j++)
- {
- if((8<<j) == data_bus_width)
- break;
- }
- if( (8<<j) > data_bus_max_size)
- return EMC_FUNC_INVALID_PARAM;
-
- add_mapped_p1 = (i<<2) + j;
- break;
- }
- if(tmp >= chip_max_size)
- {
- return EMC_FUNC_INVALID_PARAM;
- }
- }
- }
-
- switch ( index)
- {
- case 0:
- LPC_EMC->DynamicConfig0 &= ~EMC_DYNAMIC_CFG_ADD_MAP_P1_MASK;
- LPC_EMC->DynamicConfig0 |= EMC_DYNAMIC_CFG_ADD_MAP_P1(add_mapped_p1);
- LPC_EMC->DynamicConfig0 &= ~EMC_DYNAMIC_CFG_ADD_MAP_P2_MASK;
- LPC_EMC->DynamicConfig0 |= EMC_DYNAMIC_CFG_ADD_MAP_P2(add_mapped_p2);
- LPC_EMC->DynamicConfig0 &= ~EMC_DYNAMIC_CFG_ADD_MAP_P3_MASK;
- LPC_EMC->DynamicConfig0 |= EMC_DYNAMIC_CFG_ADD_MAP_P3(add_mapped_p3);
- break;
-
- case 1:
- LPC_EMC->DynamicConfig1 &= ~EMC_DYNAMIC_CFG_ADD_MAP_P1_MASK;
- LPC_EMC->DynamicConfig1 |= EMC_DYNAMIC_CFG_ADD_MAP_P1(add_mapped_p1);
- LPC_EMC->DynamicConfig1 &= ~EMC_DYNAMIC_CFG_ADD_MAP_P2_MASK;
- LPC_EMC->DynamicConfig1 |= EMC_DYNAMIC_CFG_ADD_MAP_P2(add_mapped_p2);
- LPC_EMC->DynamicConfig1 &= ~EMC_DYNAMIC_CFG_ADD_MAP_P3_MASK;
- LPC_EMC->DynamicConfig1 |= EMC_DYNAMIC_CFG_ADD_MAP_P3(add_mapped_p3);
-
- break;
-
- case 2:
- LPC_EMC->DynamicConfig2 &= ~EMC_DYNAMIC_CFG_ADD_MAP_P1_MASK;
- LPC_EMC->DynamicConfig2 |= EMC_DYNAMIC_CFG_ADD_MAP_P1(add_mapped_p1);
- LPC_EMC->DynamicConfig2 &= ~EMC_DYNAMIC_CFG_ADD_MAP_P2_MASK;
- LPC_EMC->DynamicConfig2 |= EMC_DYNAMIC_CFG_ADD_MAP_P2( add_mapped_p2);
- LPC_EMC->DynamicConfig2 &= ~EMC_DYNAMIC_CFG_ADD_MAP_P3_MASK;
- LPC_EMC->DynamicConfig2 |= EMC_DYNAMIC_CFG_ADD_MAP_P3(add_mapped_p3);
-
- break;
-
- case 3:
- LPC_EMC->DynamicConfig3 &= ~EMC_DYNAMIC_CFG_ADD_MAP_P1_MASK;
- LPC_EMC->DynamicConfig3 |= EMC_DYNAMIC_CFG_ADD_MAP_P1(add_mapped_p1);
- LPC_EMC->DynamicConfig3 &= ~EMC_DYNAMIC_CFG_ADD_MAP_P2_MASK;
- LPC_EMC->DynamicConfig3 |= EMC_DYNAMIC_CFG_ADD_MAP_P2(add_mapped_p2);
- LPC_EMC->DynamicConfig3 &= ~EMC_DYNAMIC_CFG_ADD_MAP_P3_MASK;
- LPC_EMC->DynamicConfig3 |= EMC_DYNAMIC_CFG_ADD_MAP_P3(add_mapped_p3);
-
- break;
- default:
- return EMC_FUNC_INVALID_PARAM;
- }
- return EMC_FUNC_OK;
-}
-
-/*********************************************************************//**
- * @brief Enable/disable the buffer
- *
- * @param[in] index index number, should be from 0 to 3
- *
- * @param[in] buff_control buffer control mode, should be:
- *
- * - EMC_DYNAMIC_CFG_BUFF_DISABLED: buffer is disabled
- *
- * - EMC_DYNAMIC_CFG_BUFF_ENABLED: buffer is enable
- *
- * @return EMC_FUNC_OK/EMC_FUNC_INVALID_PARAM
- **********************************************************************/
-EMC_FUNC_CODE EMC_DynMemConfigB(uint32_t index , uint32_t buff_control)
-{
- switch ( index)
- {
- case 0:
- LPC_EMC->DynamicConfig0 &= ~EMC_DYNAMIC_CFG_BUFFENABLE_BMASK;
- LPC_EMC->DynamicConfig0 |= buff_control & EMC_DYNAMIC_CFG_BUFFENABLE_BMASK;
- break;
-
- case 1:
- LPC_EMC->DynamicConfig1 &= ~EMC_DYNAMIC_CFG_BUFFENABLE_BMASK;
- LPC_EMC->DynamicConfig1 |= buff_control& EMC_DYNAMIC_CFG_BUFFENABLE_BMASK;
- break;
-
- case 2:
- LPC_EMC->DynamicConfig2 &= ~EMC_DYNAMIC_CFG_BUFFENABLE_BMASK;
- LPC_EMC->DynamicConfig2 |= buff_control& EMC_DYNAMIC_CFG_BUFFENABLE_BMASK;
- break;
-
- case 3:
- LPC_EMC->DynamicConfig3 &= ~EMC_DYNAMIC_CFG_BUFFENABLE_BMASK;
- LPC_EMC->DynamicConfig3|= buff_control& EMC_DYNAMIC_CFG_BUFFENABLE_BMASK;
- break;
- default:
- return EMC_FUNC_INVALID_PARAM;
- }
- return EMC_FUNC_OK;
-}
-
-
-/*********************************************************************//**
- * @brief Configure write permission: protect or not
- *
- * @param[in] index index number, should be from 0 to 3
- *
- * @param[in] permission permission mode, should be:
- *
- * - EMC_DYNAMIC_CFG_WR_UNPROTECTED: will not protect
- *
- * - EMC_DYNAMIC_CFG_WR_PROTECTED: will protect
- *
- * @return EMC_FUNC_OK
- **********************************************************************/
-EMC_FUNC_CODE EMC_DynMemConfigP(uint32_t index , uint32_t permission)
-{
-
- switch ( index)
- {
- case 0:
- LPC_EMC->DynamicConfig0 &= ~ EMC_DYNAMIC_CFG_WRPROTECT_BMASK;
- LPC_EMC->DynamicConfig0 |= permission&EMC_DYNAMIC_CFG_WRPROTECT_BMASK;
- break;
-
- case 1:
- LPC_EMC->DynamicConfig1 &= ~ EMC_DYNAMIC_CFG_WRPROTECT_BMASK;
- LPC_EMC->DynamicConfig1 |= permission&EMC_DYNAMIC_CFG_WRPROTECT_BMASK;
- break;
-
- case 2:
- LPC_EMC->DynamicConfig2 &= ~ EMC_DYNAMIC_CFG_WRPROTECT_BMASK;
- LPC_EMC->DynamicConfig2 |= permission&EMC_DYNAMIC_CFG_WRPROTECT_BMASK;
- break;
-
- case 3:
- LPC_EMC->DynamicConfig3 &= ~ EMC_DYNAMIC_CFG_WRPROTECT_BMASK;
- LPC_EMC->DynamicConfig3 |= permission&EMC_DYNAMIC_CFG_WRPROTECT_BMASK;
- break;
- default:
- return EMC_FUNC_INVALID_PARAM;
- }
- return EMC_FUNC_OK;
-}
-
-/*********************************************************************//**
- * @brief Set value for RAS latency
- *
- * @param[in] index index number, should be from 0 to 3
- *
- * @param[in] ras_val RAS value should be in range: 0..3
- *
- * @return EMC_FUNC_OK
- **********************************************************************/
-EMC_FUNC_CODE EMC_DynMemRAS(uint32_t index , uint32_t ras_val)
-{
- switch ( index)
- {
- case 0:
- LPC_EMC->DynamicRasCas0 &= ~EMC_DYNAMIC_RASCAS_RASCFG_BMASK;
- LPC_EMC->DynamicRasCas0 |=( ras_val << EMC_DYNAMIC_RASCAS_RASCFG_POS)
- &EMC_DYNAMIC_RASCAS_RASCFG_BMASK;
- break;
-
- case 1:
- LPC_EMC->DynamicRasCas1 &= ~EMC_DYNAMIC_RASCAS_RASCFG_BMASK;
- LPC_EMC->DynamicRasCas1 |= ( ras_val << EMC_DYNAMIC_RASCAS_RASCFG_POS)
- &EMC_DYNAMIC_RASCAS_RASCFG_BMASK;
- break;
-
- case 2:
- LPC_EMC->DynamicRasCas2 &= ~EMC_DYNAMIC_RASCAS_RASCFG_BMASK;
- LPC_EMC->DynamicRasCas2 |= ( ras_val << EMC_DYNAMIC_RASCAS_RASCFG_POS)
- &EMC_DYNAMIC_RASCAS_RASCFG_BMASK;
- break;
-
- case 3:
- LPC_EMC->DynamicRasCas3 &= ~EMC_DYNAMIC_RASCAS_RASCFG_BMASK;
- LPC_EMC->DynamicRasCas3 |= ( ras_val << EMC_DYNAMIC_RASCAS_RASCFG_POS)
- &EMC_DYNAMIC_RASCAS_RASCFG_BMASK;
- break;
- default:
- return EMC_FUNC_INVALID_PARAM;
- }
- return EMC_FUNC_OK;
-}
-
-
-/*********************************************************************//**
- * @brief Set value for CAS latency
- *
- * @param[in] index index number, should be from 0 to 3
- *
- * @param[in] ras_val CAS value should be in range: 0..3
- *
- * @return EMC_FUNC_OK/EMC_FUNC_INVALID_PARAM
- **********************************************************************/
-EMC_FUNC_CODE EMC_DynMemCAS(uint32_t index , uint32_t cas_val)
-{
- switch ( index)
- {
- case 0:
- LPC_EMC->DynamicRasCas0 &= ~EMC_DYNAMIC_RASCAS_CASCFG_BMASK;
- LPC_EMC->DynamicRasCas0 |= (cas_val<<EMC_DYNAMIC_RASCAS_CASCFG_POS)
- &EMC_DYNAMIC_RASCAS_CASCFG_BMASK;
- break;
-
- case 1:
- LPC_EMC->DynamicRasCas1 &= ~EMC_DYNAMIC_RASCAS_CASCFG_BMASK;
- LPC_EMC->DynamicRasCas1 |= (cas_val<<EMC_DYNAMIC_RASCAS_CASCFG_POS)
- &EMC_DYNAMIC_RASCAS_CASCFG_BMASK;
- break;
-
- case 2:
- LPC_EMC->DynamicRasCas2 &= ~EMC_DYNAMIC_RASCAS_CASCFG_BMASK;
- LPC_EMC->DynamicRasCas2 |= (cas_val<<EMC_DYNAMIC_RASCAS_CASCFG_POS)
- &EMC_DYNAMIC_RASCAS_CASCFG_BMASK;
- break;
-
- case 3:
- LPC_EMC->DynamicRasCas3 &= ~EMC_DYNAMIC_RASCAS_CASCFG_BMASK;
- LPC_EMC->DynamicRasCas3 |= (cas_val<<EMC_DYNAMIC_RASCAS_CASCFG_POS)
- &EMC_DYNAMIC_RASCAS_CASCFG_BMASK;
- break;
- default:
- return EMC_FUNC_INVALID_PARAM;
- }
- return EMC_FUNC_OK;
-}
-
-/*********************************************************************//**
- * @brief Set extended wait time out for accessing static memory
- *
- * @param[in] Extended_wait_time_out timeout value that will be set
- *
- * @return EMC_FUNC_OK
- **********************************************************************/
-EMC_FUNC_CODE EMC_StaticExtendedWait(uint32_t Extended_wait_time_out)
-{
- LPC_EMC->StaticExtendedWait = EMC_StaticExtendedWait_EXTENDEDWAIT(Extended_wait_time_out);
- return EMC_FUNC_OK;
-}
-
-/*********************************************************************//**
- * @brief Configure the memory width
- *
- * @param[in] index index number, should be from 0 to 3
- *
- * @param[in] mem_width memory width, should be:
- *
- * - EMC_STATIC_CFG_MW_8BITS: 8-bits
- *
- * - EMC_STATIC_CFG_MW_16BITS: 16-bits
- *
- * - EMC_STATIC_CFG_MW_32BITS02: 32-bits
- *
- * @return EMC_FUNC_OK/EMC_FUNC_INVALID_PARAM
- **********************************************************************/
-EMC_FUNC_CODE EMC_StaMemConfigMW(uint32_t index , uint32_t mem_width)
-{
- uint32_t mem_width_flg = 0;
- switch(mem_width)
- {
- case 8:
- mem_width_flg = EMC_STATIC_CFG_MW_8BITS;
- break;
- case 16:
- mem_width_flg = EMC_STATIC_CFG_MW_16BITS;
- break;
- case 32:
- mem_width_flg = EMC_STATIC_CFG_MW_32BITS;
- break;
- default:
- return EMC_FUNC_INVALID_PARAM;
- }
- switch ( index)
- {
- case 0:
- LPC_EMC->StaticConfig0 &= ~ EMC_STATIC_CFG_MEMWIDTH_BMASK;
- LPC_EMC->StaticConfig0 |= mem_width_flg;
- break;
-
- case 1:
- LPC_EMC->StaticConfig1 &= ~ EMC_STATIC_CFG_MEMWIDTH_BMASK;
- LPC_EMC->StaticConfig1 |= mem_width_flg;
- break;
-
- case 2:
- LPC_EMC->StaticConfig2 &= ~ EMC_STATIC_CFG_MEMWIDTH_BMASK;
- LPC_EMC->StaticConfig2 |= mem_width_flg;
- break;
-
- case 3:
- LPC_EMC->StaticConfig3 &= ~ EMC_STATIC_CFG_MEMWIDTH_BMASK;
- LPC_EMC->StaticConfig3 |= mem_width_flg;
- break;
- default:
- return EMC_FUNC_INVALID_PARAM;
- }
- return EMC_FUNC_OK;
-}
-/*********************************************************************//**
- * @brief Configure the page mode
- *
- * @param[in] index index number, should be from 0 to 3
- *
- * @param[in] page_mode page mode, should be:
- *
- * - EMC_CFG_PM_DISABLE: disable
- *
- * - EMC_CFG_PM_ASYNC_ENABLE: asynchronous page mode enable
- *
- * @return EMC_FUNC_OK/EMC_FUNC_INVALID_PARAM
- **********************************************************************/
-EMC_FUNC_CODE EMC_StaMemConfigPM(uint32_t index , uint32_t page_mode)
-{
- switch ( index)
- {
- case 0:
- LPC_EMC->StaticConfig0 &= ~EMC_STATIC_CFG_PAGEMODE_MASK;
- LPC_EMC->StaticConfig0 |= page_mode&EMC_STATIC_CFG_PAGEMODE_MASK;
- break;
-
- case 1:
- LPC_EMC->StaticConfig1 &= ~EMC_STATIC_CFG_PAGEMODE_MASK;
- LPC_EMC->StaticConfig1 |= page_mode&EMC_STATIC_CFG_PAGEMODE_MASK;
- break;
-
- case 2:
- LPC_EMC->StaticConfig2 &= ~EMC_STATIC_CFG_PAGEMODE_MASK;
- LPC_EMC->StaticConfig2 |= page_mode&EMC_STATIC_CFG_PAGEMODE_MASK;
- break;
-
- case 3:
- LPC_EMC->StaticConfig3 &= ~EMC_STATIC_CFG_PAGEMODE_MASK;
- LPC_EMC->StaticConfig3 |= page_mode&EMC_STATIC_CFG_PAGEMODE_MASK;
- break;
- default:
- return EMC_FUNC_INVALID_PARAM;
- }
- return EMC_FUNC_OK;
-}
-
-
-/*********************************************************************//**
- * @brief Configure the chip select polarity
- *
- * @param[in] index index number, should be from 0 to 3
- *
- * @param[in] pagepol_val_mode page mode, should be:
- *
- * - EMC_CFG_BYTELAND_PC_ACTIVE_LO: Active LOW ship select
- *
- * - EMC_CFG_BYTELAND_PC_ACTIVE_HI: Active HIGH chip select
- *
- * @return EMC_FUNC_OK/EMC_FUNC_INVALID_PARAM
- **********************************************************************/
-EMC_FUNC_CODE EMC_StaMemConfigPC(uint32_t index , uint32_t pol_val)
-{
- switch ( index)
- {
- case 0:
- LPC_EMC->StaticConfig0 &= ~EMC_STATIC_CFG_CHIPPOLARITY_MASK;
- LPC_EMC->StaticConfig0 |= pol_val&EMC_STATIC_CFG_CHIPPOLARITY_MASK;
- break;
-
- case 1:
- LPC_EMC->StaticConfig1 &= ~EMC_STATIC_CFG_CHIPPOLARITY_MASK;
- LPC_EMC->StaticConfig1 |= pol_val&EMC_STATIC_CFG_CHIPPOLARITY_MASK;
- break;
-
- case 2:
- LPC_EMC->StaticConfig2 &= ~EMC_STATIC_CFG_CHIPPOLARITY_MASK;
- LPC_EMC->StaticConfig2 |= pol_val&EMC_STATIC_CFG_CHIPPOLARITY_MASK;
- break;
-
- case 3:
- LPC_EMC->StaticConfig3 &= ~EMC_STATIC_CFG_CHIPPOLARITY_MASK;
- LPC_EMC->StaticConfig3 |= pol_val&EMC_STATIC_CFG_CHIPPOLARITY_MASK;
- break;
- default:
- return EMC_FUNC_INVALID_PARAM;
- }
- return EMC_FUNC_OK;
-}
-
-
-/*********************************************************************//**
- * @brief Configure the byte lane state
- *
- * @param[in] index index number, should be from 0 to 3
- *
- * @param[in] pb_val Byte lane state, should be:
- *
- * - EMC_CFG_BYTELAND_READ_BITSHIGH: For reads all bits
- * in BLSn[3:0] are HIGH.
- *
- * - EMC_CFG_BYTELAND_READ_BITSLOW: For reads all bits
- * in BLSn[3:0] are LOW.
- *
- * @return EMC_FUNC_OK/EMC_FUNC_INVALID_PARAM
- **********************************************************************/
-EMC_FUNC_CODE EMC_StaMemConfigPB(uint32_t index , uint32_t pb_val)
-{
- switch ( index)
- {
- case 0:
- LPC_EMC->StaticConfig0 &= ~EMC_STATIC_CFG_BYTELAND_MASK;
- LPC_EMC->StaticConfig0 |= pb_val&EMC_STATIC_CFG_BYTELAND_MASK;
- break;
-
- case 1:
- LPC_EMC->StaticConfig1 &= ~EMC_STATIC_CFG_BYTELAND_MASK;
- LPC_EMC->StaticConfig1 |= pb_val&EMC_STATIC_CFG_BYTELAND_MASK;
- break;
-
- case 2:
- LPC_EMC->StaticConfig2 &= ~EMC_STATIC_CFG_BYTELAND_MASK;
- LPC_EMC->StaticConfig2 |= pb_val&EMC_STATIC_CFG_BYTELAND_MASK;
- break;
-
- case 3:
- LPC_EMC->StaticConfig3 &= ~EMC_STATIC_CFG_BYTELAND_MASK;
- LPC_EMC->StaticConfig3 |= pb_val&EMC_STATIC_CFG_BYTELAND_MASK;
- break;
- default:
- return EMC_FUNC_INVALID_PARAM;
- }
- return EMC_FUNC_OK;
-}
-
-/*********************************************************************//**
- * @brief Configure the extended wait value
- *
- * @param[in] index index number, should be from 0 to 3
- *
- * @param[in] ex_wait Extended wait mode, should be:
- *
- * - EMC_CFG_EW_DISABLED: Extended wait disabled.
- *
- * - EMC_CFG_EW_ENABLED: Extended wait enabled.
- *
- * @return EMC_FUNC_OK/EMC_FUNC_INVALID_PARAM
- **********************************************************************/
-EMC_FUNC_CODE EMC_StaMemConfigEW(uint32_t index , uint32_t ex_wait)
-{
- switch ( index)
- {
- case 0:
- LPC_EMC->StaticConfig0 &= ~EMC_STATIC_CFG_EXTWAIT_MASK;
- LPC_EMC->StaticConfig0 |= ex_wait&EMC_STATIC_CFG_EXTWAIT_MASK;
- break;
-
- case 1:
- LPC_EMC->StaticConfig1 &= ~EMC_STATIC_CFG_EXTWAIT_MASK;
- LPC_EMC->StaticConfig1 |= ex_wait&EMC_STATIC_CFG_EXTWAIT_MASK;
- break;
-
- case 2:
- LPC_EMC->StaticConfig2 &= ~EMC_STATIC_CFG_EXTWAIT_MASK;
- LPC_EMC->StaticConfig2 |= ex_wait&EMC_STATIC_CFG_EXTWAIT_MASK;
- break;
-
- case 3:
- LPC_EMC->StaticConfig3 &= ~EMC_STATIC_CFG_EXTWAIT_MASK;
- LPC_EMC->StaticConfig3 |= ex_wait&EMC_STATIC_CFG_EXTWAIT_MASK;
- break;
- default:
- return EMC_FUNC_INVALID_PARAM;
- }
- return EMC_FUNC_OK;
-}
-
-/*********************************************************************//**
- * @brief Configure the buffer enable value
- *
- * @param[in] index index number, should be from 0 to 3
- *
- * @param[in] buf_val Buffer mode, should be:
- *
- * - EMC_CFG_BUF_DISABLED: Buffer disabled.
- *
- * - EMC_CFG_BUF_ENABLED: Buffer enabled.
- *
- * @return EMC_FUNC_OK/EMC_FUNC_INVALID_PARAM
- **********************************************************************/
-EMC_FUNC_CODE EMC_StaMemConfigB(uint32_t index , uint32_t buf_val)
-{
- switch ( index)
- {
- case 0:
- LPC_EMC->StaticConfig0 &= ~EMC_STATIC_CFG_BUFENABLE_MASK;
- LPC_EMC->StaticConfig0 |= buf_val&EMC_STATIC_CFG_BUFENABLE_MASK;
- break;
-
- case 1:
- LPC_EMC->StaticConfig1 &= ~EMC_STATIC_CFG_BUFENABLE_MASK;
- LPC_EMC->StaticConfig1 |= buf_val&EMC_STATIC_CFG_BUFENABLE_MASK;
- break;
-
- case 2:
- LPC_EMC->StaticConfig2 &= ~EMC_STATIC_CFG_BUFENABLE_MASK;
- LPC_EMC->StaticConfig2 |= buf_val&EMC_STATIC_CFG_BUFENABLE_MASK;
- break;
-
- case 3:
- LPC_EMC->StaticConfig3 &= ~EMC_STATIC_CFG_BUFENABLE_MASK;
- LPC_EMC->StaticConfig3 |= buf_val&EMC_STATIC_CFG_BUFENABLE_MASK;
- break;
- default:
- return EMC_FUNC_INVALID_PARAM;
- }
- return EMC_FUNC_OK;
-}
-
-/*********************************************************************//**
- * @brief Configure the write permission
- *
- * @param[in] index index number, should be from 0 to 3
- *
- * @param[in] per_val Permission mode, should be:
- *
- * - EMC_CFG_WRITEPROTECT_DISABLED: Write not protected.
- *
- * - EMC_CFG_WRITEPROTECT_ENABLED: Write protected.
- *
- * @return EMC_FUNC_OK/EMC_FUNC_INVALID_PARAM
- **********************************************************************/
-EMC_FUNC_CODE EMC_StaMemConfigpP(uint32_t index , uint32_t per_val)
-{
- switch ( index)
- {
- case 0:
- LPC_EMC->StaticConfig0 &= ~EMC_STATIC_CFG_WRIEPROTECT_MASK;
- LPC_EMC->StaticConfig0 |= per_val&EMC_STATIC_CFG_WRIEPROTECT_MASK;
- break;
-
- case 1:
- LPC_EMC->StaticConfig1 &= ~EMC_STATIC_CFG_WRIEPROTECT_MASK;
- LPC_EMC->StaticConfig1 |= per_val&EMC_STATIC_CFG_WRIEPROTECT_MASK;
- break;
-
- case 2:
- LPC_EMC->StaticConfig2 &= ~EMC_STATIC_CFG_WRIEPROTECT_MASK;
- LPC_EMC->StaticConfig2 |= per_val&EMC_STATIC_CFG_WRIEPROTECT_MASK;
- break;
-
- case 3:
- LPC_EMC->StaticConfig3 &= ~EMC_STATIC_CFG_WRIEPROTECT_MASK;
- LPC_EMC->StaticConfig3 |= per_val&EMC_STATIC_CFG_WRIEPROTECT_MASK;
- break;
- default:
- return EMC_FUNC_INVALID_PARAM;
- }
- return EMC_FUNC_OK;
-}
-
-/*********************************************************************//**
- * @brief Set the value of LPC_EMC static memory registers
- *
- * @param[in] index index number, should be from 0 to 3
- *
- * @param[in] EMC_STA_MEM_PAR Static register, should be:
- *
- * - EMC_STA_MEM_WAITWEN: StaticWaitWen0 register
- * - EMC_STA_MEM_WAITOEN: StaticWaitOen0 register
- * - EMC_STA_MEM_WAITRD: StaticWaitRd0 register
- * - EMC_STA_MEM_WAITPAGE: StaticWaitPage0 register
- * - EMC_STA_MEM_WAITWR: StaticWaitWr0 register
- * - EMC_STA_MEM_WAITTURN: StaticWaitTurn0 register
- *
- * @return EMC_FUNC_OK/EMC_FUNC_INVALID_PARAM
- **********************************************************************/
-EMC_FUNC_CODE EMC_SetStaMemoryParameter(uint32_t index ,EMC_STA_MEM_PAR par, uint32_t val)
-{
- switch (index)
- {
- case 0:
- switch ( par)
- {
- case EMC_STA_MEM_WAITWEN:
- LPC_EMC->StaticWaitWen0 = EMC_StaticWaitWen_WAITWEN(val);
- break;
-
- case EMC_STA_MEM_WAITOEN:
- LPC_EMC->StaticWaitOen0 = EMC_StaticWaitOen_WAITOEN(val);
- break;
-
- case EMC_STA_MEM_WAITRD:
- LPC_EMC->StaticWaitRd0 = EMC_StaticWaitRd_WAITRD(val);
- break;
-
- case EMC_STA_MEM_WAITPAGE:
- LPC_EMC->StaticWaitPage0 = EMC_StaticwaitPage_WAITPAGE(val);
- break;
-
- case EMC_STA_MEM_WAITWR:
- LPC_EMC->StaticWaitWr0 = EMC_StaticWaitwr_WAITWR(val);
- break;
-
- case EMC_STA_MEM_WAITTURN:
- LPC_EMC->StaticWaitTurn0 =EMC_StaticWaitTurn_WAITTURN(val);
- break;
- default:
- return EMC_FUNC_INVALID_PARAM;
- }
- break;
-
- case 1:
- switch ( par)
- {
- case EMC_STA_MEM_WAITWEN:
- LPC_EMC->StaticWaitWen1 = EMC_StaticWaitWen_WAITWEN(val);
- break;
-
- case EMC_STA_MEM_WAITOEN:
- LPC_EMC->StaticWaitOen1 = EMC_StaticWaitOen_WAITOEN(val);
- break;
-
- case EMC_STA_MEM_WAITRD:
- LPC_EMC->StaticWaitRd1 = EMC_StaticWaitRd_WAITRD(val);
- break;
-
- case EMC_STA_MEM_WAITPAGE:
- LPC_EMC->StaticWaitPage1 = EMC_StaticwaitPage_WAITPAGE(val);
- break;
-
- case EMC_STA_MEM_WAITWR:
- LPC_EMC->StaticWaitWr1 = EMC_StaticWaitwr_WAITWR(val);
- break;
-
- case EMC_STA_MEM_WAITTURN:
- LPC_EMC->StaticWaitTurn1 =EMC_StaticWaitTurn_WAITTURN(val);
- break;
- default:
- return EMC_FUNC_INVALID_PARAM;
-
- }
- break;
-
- case 2:
- switch ( par)
- {
- case EMC_STA_MEM_WAITWEN:
- LPC_EMC->StaticWaitWen2 = EMC_StaticWaitWen_WAITWEN(val);
- break;
-
- case EMC_STA_MEM_WAITOEN:
- LPC_EMC->StaticWaitOen2 = EMC_StaticWaitOen_WAITOEN(val);
- break;
-
- case EMC_STA_MEM_WAITRD:
- LPC_EMC->StaticWaitRd2 = EMC_StaticWaitRd_WAITRD(val);
- break;
-
- case EMC_STA_MEM_WAITPAGE:
- LPC_EMC->StaticWaitPage2 = EMC_StaticwaitPage_WAITPAGE(val);
- break;
-
- case EMC_STA_MEM_WAITWR:
- LPC_EMC->StaticWaitWr2 = EMC_StaticWaitwr_WAITWR(val);
- break;
-
- case EMC_STA_MEM_WAITTURN:
- LPC_EMC->StaticWaitTurn2 =EMC_StaticWaitTurn_WAITTURN(val);
- break;
- default:
- return EMC_FUNC_INVALID_PARAM;
-
- }
- break;
-
- case 3:
- switch ( par)
- {
- case EMC_STA_MEM_WAITWEN:
- LPC_EMC->StaticWaitWen3 = EMC_StaticWaitWen_WAITWEN(val);
- break;
-
- case EMC_STA_MEM_WAITOEN:
- LPC_EMC->StaticWaitOen3 = EMC_StaticWaitOen_WAITOEN(val);
- break;
-
- case EMC_STA_MEM_WAITRD:
- LPC_EMC->StaticWaitRd3 = EMC_StaticWaitRd_WAITRD(val);
- break;
-
- case EMC_STA_MEM_WAITPAGE:
- LPC_EMC->StaticWaitPage3 = EMC_StaticwaitPage_WAITPAGE(val);
- break;
-
- case EMC_STA_MEM_WAITWR:
- LPC_EMC->StaticWaitWr3 = EMC_StaticWaitwr_WAITWR(val);
- break;
-
- case EMC_STA_MEM_WAITTURN:
- LPC_EMC->StaticWaitTurn3 =EMC_StaticWaitTurn_WAITTURN(val);
- break;
- default:
- return EMC_FUNC_INVALID_PARAM;
- }
- break;
- }
- return EMC_FUNC_OK;
-}
-/**
- * @}
- */
-
- /**
- * @}
- */
-#endif /*_EMC*/
-
-
-
-
-
-
diff --git a/bsp/lpc408x/Libraries/Drivers/source/lpc_exti.c b/bsp/lpc408x/Libraries/Drivers/source/lpc_exti.c
deleted file mode 100644
index 148267ee8b..0000000000
--- a/bsp/lpc408x/Libraries/Drivers/source/lpc_exti.c
+++ /dev/null
@@ -1,162 +0,0 @@
-/**********************************************************************
-* $Id$ lpc_exti.c 2011-06-02
-*//**
-* @file lpc_exti.c
-* @brief Contains all functions support for External Interrupt
-* firmware library on LPC
-* @version 1.0
-* @date 02. June. 2011
-* @author NXP MCU SW Application Team
-*
-* Copyright(C) 2011, NXP Semiconductor
-* All rights reserved.
-*
-***********************************************************************
-* Software that is described herein is for illustrative purposes only
-* which provides customers with programming information regarding the
-* products. This software is supplied "AS IS" without any warranties.
-* NXP Semiconductors assumes no responsibility or liability for the
-* use of the software, conveys no license or title under any patent,
-* copyright, or mask work right to the product. NXP Semiconductors
-* reserves the right to make changes in the software without
-* notification. NXP Semiconductors also make 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'
-* relevant copyright 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.
-**********************************************************************/
-
-/* Peripheral group ----------------------------------------------------------- */
-/** @addtogroup EXTI
- * @{
- */
-#ifdef __BUILD_WITH_EXAMPLE__
-#include "lpc_libcfg.h"
-#else
-#include "lpc_libcfg_default.h"
-#endif /* __BUILD_WITH_EXAMPLE__ */
-#ifdef _EXTI
-
-/* Includes ------------------------------------------------------------------- */
-#include "lpc_exti.h"
-
-/* Public Functions ----------------------------------------------------------- */
-/** @addtogroup EXTI_Public_Functions
- * @{
- */
-
-/*********************************************************************//**
- * @brief Initial for EXT
- * - Set EXTINT, EXTMODE, EXTPOLAR registers to default value
- * @param[in] None
- * @return None
- **********************************************************************/
-void EXTI_Init(void)
-{
- LPC_SC->EXTINT = 0xF;
- LPC_SC->EXTMODE = 0x0;
- LPC_SC->EXTPOLAR = 0x0;
-}
-
-
-/*********************************************************************//**
-* @brief Close EXT
-* @param[in] None
-* @return None
-**********************************************************************/
-void EXTI_DeInit(void)
-{
- ;
-}
-
-/*********************************************************************//**
- * @brief Configuration for EXT
- * - Set EXTINT, EXTMODE, EXTPOLAR register
- * @param[in] EXTICfg Pointer to a EXTI_InitTypeDef structure
- * that contains the configuration information for the
- * specified external interrupt
- * @return None
- **********************************************************************/
-void EXTI_Config(EXTI_InitTypeDef *EXTICfg)
-{
- LPC_SC->EXTINT = 0x0;
- EXTI_SetMode(EXTICfg->EXTI_Line, EXTICfg->EXTI_Mode);
- EXTI_SetPolarity(EXTICfg->EXTI_Line, EXTICfg->EXTI_polarity);
-}
-
-/*********************************************************************//**
-* @brief Set mode for EXTI pin
-* @param[in] EXTILine external interrupt line, should be:
-* - EXTI_EINT0: external interrupt line 0
-* - EXTI_EINT1: external interrupt line 1
-* - EXTI_EINT2: external interrupt line 2
-* - EXTI_EINT3: external interrupt line 3
-* @param[in] mode external mode, should be:
-* - EXTI_MODE_LEVEL_SENSITIVE
-* - EXTI_MODE_EDGE_SENSITIVE
-* @return None
-*********************************************************************/
-void EXTI_SetMode(EXTI_LINE_ENUM EXTILine, EXTI_MODE_ENUM mode)
-{
- if(mode == EXTI_MODE_EDGE_SENSITIVE)
- {
- LPC_SC->EXTMODE |= (1 << EXTILine);
- }
- else if(mode == EXTI_MODE_LEVEL_SENSITIVE)
- {
- LPC_SC->EXTMODE &= ~(1 << EXTILine);
- }
-}
-
-/*********************************************************************//**
-* @brief Set polarity for EXTI pin
-* @param[in] EXTILine external interrupt line, should be:
-* - EXTI_EINT0: external interrupt line 0
-* - EXTI_EINT1: external interrupt line 1
-* - EXTI_EINT2: external interrupt line 2
-* - EXTI_EINT3: external interrupt line 3
-* @param[in] polarity external polarity value, should be:
-* - EXTI_POLARITY_LOW_ACTIVE_OR_FALLING_EDGE
-* - EXTI_POLARITY_LOW_ACTIVE_OR_FALLING_EDGE
-* @return None
-*********************************************************************/
-void EXTI_SetPolarity(EXTI_LINE_ENUM EXTILine, EXTI_POLARITY_ENUM polarity)
-{
- if(polarity == EXTI_POLARITY_HIGH_ACTIVE_OR_RISING_EDGE)
- {
- LPC_SC->EXTPOLAR |= (1 << EXTILine);
- }
- else if(polarity == EXTI_POLARITY_LOW_ACTIVE_OR_FALLING_EDGE)
- {
- LPC_SC->EXTPOLAR &= ~(1 << EXTILine);
- }
-}
-
-/*********************************************************************//**
-* @brief Clear External interrupt flag
-* @param[in] EXTILine external interrupt line, should be:
-* - EXTI_EINT0: external interrupt line 0
-* - EXTI_EINT1: external interrupt line 1
-* - EXTI_EINT2: external interrupt line 2
-* - EXTI_EINT3: external interrupt line 3
-* @return None
-*********************************************************************/
-void EXTI_ClearEXTIFlag(EXTI_LINE_ENUM EXTILine)
-{
- LPC_SC->EXTINT |= (1 << EXTILine);
-}
-
-/**
- * @}
- */
-#endif /*_EXTI*/
-/**
- * @}
- */
-
-/* --------------------------------- End Of File ------------------------------ */
-
diff --git a/bsp/lpc408x/Libraries/Drivers/source/lpc_gpdma.c b/bsp/lpc408x/Libraries/Drivers/source/lpc_gpdma.c
deleted file mode 100644
index 8e8823d3dd..0000000000
--- a/bsp/lpc408x/Libraries/Drivers/source/lpc_gpdma.c
+++ /dev/null
@@ -1,453 +0,0 @@
-/**********************************************************************
-* $Id$ lpc_gpdma.c 2011-06-02
-*//**
-* @file lpc_gpdma.c
-* @brief Contains all functions support for GPDMA firmware library
-* on LPC
-* @version 1.0
-* @date 02. June. 2011
-* @author NXP MCU SW Application Team
-*
-* Copyright(C) 2011, NXP Semiconductor
-* All rights reserved.
-*
-***********************************************************************
-* Software that is described herein is for illustrative purposes only
-* which provides customers with programming information regarding the
-* products. This software is supplied "AS IS" without any warranties.
-* NXP Semiconductors assumes no responsibility or liability for the
-* use of the software, conveys no license or title under any patent,
-* copyright, or mask work right to the product. NXP Semiconductors
-* reserves the right to make changes in the software without
-* notification. NXP Semiconductors also make 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'
-* relevant copyright 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.
-**********************************************************************/
-
-/* Peripheral group ----------------------------------------------------------- */
-/** @addtogroup GPDMA
- * @{
- */
-#ifdef __BUILD_WITH_EXAMPLE__
-#include "lpc_libcfg.h"
-#else
-#include "lpc_libcfg_default.h"
-#endif /* __BUILD_WITH_EXAMPLE__ */
-#ifdef _GPDMA
-
-/* Includes ------------------------------------------------------------------- */
-#include "lpc_gpdma.h"
-#include "lpc_clkpwr.h"
-
-/* Private Variables ---------------------------------------------------------- */
-/** @defgroup GPDMA_Private_Variables GPDMA Private Variables
- * @{
- */
-
-/**
- * @brief Lookup Table of Connection Type matched with
- * Peripheral Data (FIFO) register base address
- */
-volatile const void *GPDMA_LUTPerAddr[] = {
- 0, // Revered
- (&LPC_MCI->FIFO), // SD Card
- (&LPC_SSP0->DR), // SSP0 Tx
- (&LPC_SSP0->DR), // SSP0 Rx
- (&LPC_SSP1->DR), // SSP1 Tx
- (&LPC_SSP1->DR), // SSP1 Rx
- (&LPC_SSP2->DR), // SSP2 Tx
- (&LPC_SSP2->DR), // SSP2 Rx
- (&LPC_ADC->GDR), // ADC
- (&LPC_DAC->CR), // DAC
- (&LPC_UART0->/*RBTHDLR.*/THR), // UART0 Tx
- (&LPC_UART0->/*RBTHDLR.*/RBR), // UART0 Rx
- (&LPC_UART1->/*RBTHDLR.*/THR), // UART1 Tx
- (&LPC_UART1->/*RBTHDLR.*/RBR), // UART1 Rx
- (&LPC_UART2->/*RBTHDLR.*/THR), // UART2 Tx
- (&LPC_UART2->/*RBTHDLR.*/RBR), // UART2 Rx
- (&LPC_TIM0->MR0), // MAT0.0
- (&LPC_TIM0->MR1), // MAT0.1
- (&LPC_TIM1->MR0), // MAT1.0
- (&LPC_TIM1->MR1), // MAT1.1
- (&LPC_TIM2->MR0), // MAT2.0
- (&LPC_TIM2->MR1), // MAT2.1
- (&LPC_I2S->TXFIFO), // I2S Tx
- (&LPC_I2S->RXFIFO), // I2S Rx
- 0, // Reverse
- 0, // Reverse
- (&LPC_UART3->/*RBTHDLR.*/THR), // UART3 Tx
- (&LPC_UART3->/*RBTHDLR.*/RBR), // UART3 Rx
- (&LPC_UART4->/*RBTHDLR.*/THR), // UART4 Tx
- (&LPC_UART4->/*RBTHDLR.*/RBR), // UART4 Rx
- (&LPC_TIM3->MR0), // MAT3.0
- (&LPC_TIM3->MR1), // MAT3.1
-};
-
-/**
- * @brief Lookup Table of GPDMA Channel Number matched with
- * GPDMA channel pointer
- */
-const LPC_GPDMACH_TypeDef *pGPDMACh[8] = {
- LPC_GPDMACH0, // GPDMA Channel 0
- LPC_GPDMACH1, // GPDMA Channel 1
- LPC_GPDMACH2, // GPDMA Channel 2
- LPC_GPDMACH3, // GPDMA Channel 3
- LPC_GPDMACH4, // GPDMA Channel 4
- LPC_GPDMACH5, // GPDMA Channel 5
- LPC_GPDMACH6, // GPDMA Channel 6
- LPC_GPDMACH7, // GPDMA Channel 7
-};
-/**
- * @brief Optimized Peripheral Source and Destination burst size
- */
-const uint8_t GPDMA_LUTPerBurst[] = {
- 0, // Reserved
- GPDMA_BSIZE_8, // SD Card
- GPDMA_BSIZE_4, // SSP0 Tx
- GPDMA_BSIZE_4, // SSP0 Rx
- GPDMA_BSIZE_4, // SSP1 Tx
- GPDMA_BSIZE_4, // SSP1 Rx
- GPDMA_BSIZE_4, // SSP2 Tx
- GPDMA_BSIZE_4, // SSP2 Rx
- GPDMA_BSIZE_1, // ADC
- GPDMA_BSIZE_1, // DAC
- GPDMA_BSIZE_1, // UART0 Tx
- GPDMA_BSIZE_1, // UART0 Rx
- GPDMA_BSIZE_1, // UART1 Tx
- GPDMA_BSIZE_1, // UART1 Rx
- GPDMA_BSIZE_1, // UART2 Tx
- GPDMA_BSIZE_1, // UART2 Rx
- GPDMA_BSIZE_1, // MAT0.0
- GPDMA_BSIZE_1, // MAT0.1
- GPDMA_BSIZE_1, // MAT1.0
- GPDMA_BSIZE_1, // MAT1.1
- GPDMA_BSIZE_1, // MAT2.0
- GPDMA_BSIZE_1, // MAT2.1
- GPDMA_BSIZE_32, // I2S channel 0
- GPDMA_BSIZE_32, // I2S channel 1
- 0, // Reserved
- 0, // Reserved
- GPDMA_BSIZE_1, // UART3 Tx
- GPDMA_BSIZE_1, // UART3 Rx
- GPDMA_BSIZE_1, // UART4 Tx
- GPDMA_BSIZE_1, // UART4 Rx
- GPDMA_BSIZE_1, // MAT3.0
- GPDMA_BSIZE_1, // MAT3.1
-};
-/**
- * @brief Optimized Peripheral Source and Destination transfer width
- */
-const uint8_t GPDMA_LUTPerWid[] = {
- 0, // Reserved
- GPDMA_WIDTH_WORD, // SD Card
- GPDMA_WIDTH_BYTE, // SSP0 Tx
- GPDMA_WIDTH_BYTE, // SSP0 Rx
- GPDMA_WIDTH_BYTE, // SSP1 Tx
- GPDMA_WIDTH_BYTE, // SSP1 Rx
- GPDMA_WIDTH_BYTE, // SSP2 Tx
- GPDMA_WIDTH_BYTE, // SSP2 Rx
- GPDMA_WIDTH_WORD, // ADC
- GPDMA_WIDTH_BYTE, // DAC
- GPDMA_WIDTH_BYTE, // UART0 Tx
- GPDMA_WIDTH_BYTE, // UART0 Rx
- GPDMA_WIDTH_BYTE, // UART1 Tx
- GPDMA_WIDTH_BYTE, // UART1 Rx
- GPDMA_WIDTH_BYTE, // UART2 Tx
- GPDMA_WIDTH_BYTE, // UART2 Rx
- GPDMA_WIDTH_WORD, // MAT0.0
- GPDMA_WIDTH_WORD, // MAT0.1
- GPDMA_WIDTH_WORD, // MAT1.0
- GPDMA_WIDTH_WORD, // MAT1.1
- GPDMA_WIDTH_WORD, // MAT2.0
- GPDMA_WIDTH_WORD, // MAT2.1
- GPDMA_WIDTH_WORD, // I2S channel 0
- GPDMA_WIDTH_WORD, // I2S channel 1
- 0, // Reserved
- 0, // Reserved
- GPDMA_WIDTH_BYTE, // UART3 Tx
- GPDMA_WIDTH_BYTE, // UART3 Rx
- GPDMA_WIDTH_BYTE, // UART4 Tx
- GPDMA_WIDTH_BYTE, // UART4 Rx
- GPDMA_WIDTH_WORD, // MAT3.0
- GPDMA_WIDTH_WORD, // MAT3.1
-};
-
-/**
- * @}
- */
-
-/* Public Functions ----------------------------------------------------------- */
-/** @addtogroup GPDMA_Public_Functions
- * @{
- */
-
-/********************************************************************//**
- * @brief Initialize GPDMA controller
- * @param None
- * @return None
- *********************************************************************/
-void GPDMA_Init(void)
-{
- /* Enable GPDMA clock */
- CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCGPDMA, ENABLE);
-
- // Reset all channel configuration register
- LPC_GPDMACH0->CConfig = 0;
- LPC_GPDMACH1->CConfig = 0;
- LPC_GPDMACH2->CConfig = 0;
- LPC_GPDMACH3->CConfig = 0;
- LPC_GPDMACH4->CConfig = 0;
- LPC_GPDMACH5->CConfig = 0;
- LPC_GPDMACH6->CConfig = 0;
- LPC_GPDMACH7->CConfig = 0;
-
- /* Clear all DMA interrupt and error flag */
- LPC_GPDMA->IntTCClear = 0xFF;
- LPC_GPDMA->IntErrClr = 0xFF;
-}
-
-/********************************************************************//**
- * @brief Setup GPDMA channel peripheral according to the specified
- * parameters in the GPDMAChannelConfig.
- * @param[in] GPDMAChannelConfig Pointer to a GPDMA_CH_CFG_Type
- * structure that contains the configuration
- * information for the specified GPDMA channel peripheral.
- * @return ERROR if selected channel is enabled before
- * or SUCCESS if channel is configured successfully
- *********************************************************************/
-Status GPDMA_Setup(GPDMA_Channel_CFG_Type *GPDMAChannelConfig)
-{
- LPC_GPDMACH_TypeDef *pDMAch;
- uint32_t tmp1, tmp2;
-
- if (LPC_GPDMA->EnbldChns & (GPDMA_DMACEnbldChns_Ch(GPDMAChannelConfig->ChannelNum))) {
- // This channel is enabled, return ERROR, need to release this channel first
- return ERROR;
- }
-
- // Get Channel pointer
- pDMAch = (LPC_GPDMACH_TypeDef *) pGPDMACh[GPDMAChannelConfig->ChannelNum];
-
- // Reset the Interrupt status
- LPC_GPDMA->IntTCClear = GPDMA_DMACIntTCClear_Ch(GPDMAChannelConfig->ChannelNum);
- LPC_GPDMA->IntErrClr = GPDMA_DMACIntErrClr_Ch(GPDMAChannelConfig->ChannelNum);
-
- // Clear DMA configure
- pDMAch->CControl = 0x00;
- pDMAch->CConfig = 0x00;
-
- /* Assign Linker List Item value */
- pDMAch->CLLI = GPDMAChannelConfig->DMALLI;
-
- /* Set value to Channel Control Registers */
- switch (GPDMAChannelConfig->TransferType)
- {
- // Memory to memory
- case GPDMA_TRANSFERTYPE_M2M:
- // Assign physical source and destination address
- pDMAch->CSrcAddr = GPDMAChannelConfig->SrcMemAddr;
- pDMAch->CDestAddr = GPDMAChannelConfig->DstMemAddr;
- pDMAch->CControl
- = GPDMA_DMACCxControl_TransferSize(GPDMAChannelConfig->TransferSize) \
- | GPDMA_DMACCxControl_SBSize(GPDMA_BSIZE_32) \
- | GPDMA_DMACCxControl_DBSize(GPDMA_BSIZE_32) \
- | GPDMA_DMACCxControl_SWidth(GPDMAChannelConfig->TransferWidth) \
- | GPDMA_DMACCxControl_DWidth(GPDMAChannelConfig->TransferWidth) \
- | GPDMA_DMACCxControl_SI \
- | GPDMA_DMACCxControl_DI \
- | GPDMA_DMACCxControl_I;
- break;
- // Memory to peripheral
- case GPDMA_TRANSFERTYPE_M2P:
- case GPDMA_TRANSFERTYPE_M2P_DEST_CTRL:
- // Assign physical source
- pDMAch->CSrcAddr = GPDMAChannelConfig->SrcMemAddr;
- // Assign peripheral destination address
- pDMAch->CDestAddr = (uint32_t)GPDMA_LUTPerAddr[GPDMAChannelConfig->DstConn];
- pDMAch->CControl
- = GPDMA_DMACCxControl_TransferSize((uint32_t)GPDMAChannelConfig->TransferSize) \
- | GPDMA_DMACCxControl_SBSize((uint32_t)GPDMA_LUTPerBurst[GPDMAChannelConfig->DstConn]) \
- | GPDMA_DMACCxControl_DBSize((uint32_t)GPDMA_LUTPerBurst[GPDMAChannelConfig->DstConn]) \
- | GPDMA_DMACCxControl_SWidth((uint32_t)GPDMA_LUTPerWid[GPDMAChannelConfig->DstConn]) \
- | GPDMA_DMACCxControl_DWidth((uint32_t)GPDMA_LUTPerWid[GPDMAChannelConfig->DstConn]) \
- | GPDMA_DMACCxControl_SI \
- | GPDMA_DMACCxControl_I;
- break;
- // Peripheral to memory
- case GPDMA_TRANSFERTYPE_P2M:
- case GPDMA_TRANSFERTYPE_P2M_SRC_CTRL:
- // Assign peripheral source address
- pDMAch->CSrcAddr = (uint32_t)GPDMA_LUTPerAddr[GPDMAChannelConfig->SrcConn];
- // Assign memory destination address
- pDMAch->CDestAddr = GPDMAChannelConfig->DstMemAddr;
- pDMAch->CControl
- = GPDMA_DMACCxControl_TransferSize((uint32_t)GPDMAChannelConfig->TransferSize) \
- | GPDMA_DMACCxControl_SBSize((uint32_t)GPDMA_LUTPerBurst[GPDMAChannelConfig->SrcConn]) \
- | GPDMA_DMACCxControl_DBSize((uint32_t)GPDMA_LUTPerBurst[GPDMAChannelConfig->SrcConn]) \
- | GPDMA_DMACCxControl_SWidth((uint32_t)GPDMA_LUTPerWid[GPDMAChannelConfig->SrcConn]) \
- | GPDMA_DMACCxControl_DWidth((uint32_t)GPDMA_LUTPerWid[GPDMAChannelConfig->SrcConn]) \
- | GPDMA_DMACCxControl_DI \
- | GPDMA_DMACCxControl_I;
- break;
- // Peripheral to peripheral
- case GPDMA_TRANSFERTYPE_P2P:
- // Assign peripheral source address
- pDMAch->CSrcAddr = (uint32_t)GPDMA_LUTPerAddr[GPDMAChannelConfig->SrcConn];
- // Assign peripheral destination address
- pDMAch->CDestAddr = (uint32_t)GPDMA_LUTPerAddr[GPDMAChannelConfig->DstConn];
- pDMAch->CControl = GPDMA_DMACCxControl_TransferSize((uint32_t)GPDMAChannelConfig->TransferSize) \
- | GPDMA_DMACCxControl_SBSize((uint32_t)GPDMA_LUTPerBurst[GPDMAChannelConfig->SrcConn]) \
- | GPDMA_DMACCxControl_DBSize((uint32_t)GPDMA_LUTPerBurst[GPDMAChannelConfig->DstConn]) \
- | GPDMA_DMACCxControl_SWidth((uint32_t)GPDMA_LUTPerWid[GPDMAChannelConfig->SrcConn]) \
- | GPDMA_DMACCxControl_DWidth((uint32_t)GPDMA_LUTPerWid[GPDMAChannelConfig->DstConn]) \
- | GPDMA_DMACCxControl_I;
- break;
- // Do not support any more transfer type, return ERROR
- default:
- return ERROR;
- }
-
- /* Re-Configure DMA Request Select for source peripheral */
- if((GPDMAChannelConfig->SrcConn != 8)&&(GPDMAChannelConfig->SrcConn != 9))
- {
- if (GPDMAChannelConfig->SrcConn > 15)
- {
- LPC_SC->DMAREQSEL |= (1<<(GPDMAChannelConfig->SrcConn - 16));
- } else {
- LPC_SC->DMAREQSEL &= ~(1<<(GPDMAChannelConfig->SrcConn));
- }
- }
-
- /* Re-Configure DMA Request Select for Destination peripheral */
- if((GPDMAChannelConfig->DstConn != 8)&&(GPDMAChannelConfig->DstConn != 9))
- {
- if (GPDMAChannelConfig->DstConn > 15)
- {
- LPC_SC->DMAREQSEL |= (1<<(GPDMAChannelConfig->DstConn - 16));
- } else {
- LPC_SC->DMAREQSEL &= ~(1<<(GPDMAChannelConfig->DstConn));
- }
- }
-
- /* Enable DMA channels, little endian */
- LPC_GPDMA->Config = GPDMA_DMACConfig_E;
- while (!(LPC_GPDMA->Config & GPDMA_DMACConfig_E));
-
- // Calculate absolute value for Connection number
- tmp1 = GPDMAChannelConfig->SrcConn;
- tmp1 = ((tmp1 > 15) ? (tmp1 - 16) : tmp1);
- tmp2 = GPDMAChannelConfig->DstConn;
- tmp2 = ((tmp2 > 15) ? (tmp2 - 16) : tmp2);
-
- // Configure DMA Channel, enable Error Counter and Terminate counter
- pDMAch->CConfig = GPDMA_DMACCxConfig_IE | GPDMA_DMACCxConfig_ITC /*| GPDMA_DMACCxConfig_E*/ \
- | GPDMA_DMACCxConfig_TransferType((uint32_t)GPDMAChannelConfig->TransferType) \
- | GPDMA_DMACCxConfig_SrcPeripheral(tmp1) \
- | GPDMA_DMACCxConfig_DestPeripheral(tmp2);
-
- return SUCCESS;
-}
-
-
-/*********************************************************************//**
- * @brief Enable/Disable DMA channel
- * @param[in] channelNum GPDMA channel, should be in range from 0 to 7
- * @param[in] NewState New State of this command, should be:
- * - ENABLE.
- * - DISABLE.
- * @return None
- **********************************************************************/
-void GPDMA_ChannelCmd(uint8_t channelNum, FunctionalState NewState)
-{
- LPC_GPDMACH_TypeDef *pDMAch;
-
- // Get Channel pointer
- pDMAch = (LPC_GPDMACH_TypeDef *) pGPDMACh[channelNum];
-
- if (NewState == ENABLE) {
- pDMAch->CConfig |= GPDMA_DMACCxConfig_E;
- } else {
- pDMAch->CConfig &= ~GPDMA_DMACCxConfig_E;
- }
-}
-/*********************************************************************//**
- * @brief Check if corresponding channel does have an active interrupt
- * request or not
- * @param[in] type type of status, should be:
- * - GPDMA_STAT_INT: GPDMA Interrupt Status
- * - GPDMA_STAT_INTTC: GPDMA Interrupt Terminal Count Request Status
- * - GPDMA_STAT_INTERR: GPDMA Interrupt Error Status
- * - GPDMA_STAT_RAWINTTC: GPDMA Raw Interrupt Terminal Count Status
- * - GPDMA_STAT_RAWINTERR: GPDMA Raw Error Interrupt Status
- * - GPDMA_STAT_ENABLED_CH:GPDMA Enabled Channel Status
- * @param[in] channel GPDMA channel, should be in range from 0 to 7
- * @return IntStatus status of DMA channel interrupt after masking
- * Should be:
- * - SET: the corresponding channel has no active interrupt request
- * - RESET: the corresponding channel does have an active interrupt request
- **********************************************************************/
-IntStatus GPDMA_IntGetStatus(GPDMA_Status_Type type, uint8_t channel)
-{
- switch (type)
- {
- case GPDMA_STAT_INT: //check status of DMA channel interrupts
- if (LPC_GPDMA->IntStat & (GPDMA_DMACIntStat_Ch(channel)))
- return SET;
- return RESET;
- case GPDMA_STAT_INTTC: // check terminal count interrupt request status for DMA
- if (LPC_GPDMA->IntTCStat & GPDMA_DMACIntTCStat_Ch(channel))
- return SET;
- return RESET;
- case GPDMA_STAT_INTERR: //check interrupt status for DMA channels
- if (LPC_GPDMA->IntErrStat & GPDMA_DMACIntTCClear_Ch(channel))
- return SET;
- return RESET;
- case GPDMA_STAT_RAWINTTC: //check status of the terminal count interrupt for DMA channels
- if (LPC_GPDMA->RawIntErrStat & GPDMA_DMACRawIntTCStat_Ch(channel))
- return SET;
- return RESET;
- case GPDMA_STAT_RAWINTERR: //check status of the error interrupt for DMA channels
- if (LPC_GPDMA->RawIntTCStat & GPDMA_DMACRawIntErrStat_Ch(channel))
- return SET;
- return RESET;
- default: //check enable status for DMA channels
- if (LPC_GPDMA->EnbldChns & GPDMA_DMACEnbldChns_Ch(channel))
- return SET;
- return RESET;
- }
-}
-
-/*********************************************************************//**
- * @brief Clear one or more interrupt requests on DMA channels
- * @param[in] type type of interrupt request, should be:
- * - GPDMA_STATCLR_INTTC: GPDMA Interrupt Terminal Count Request Clear
- * - GPDMA_STATCLR_INTERR: GPDMA Interrupt Error Clear
- * @param[in] channel GPDMA channel, should be in range from 0 to 7
- * @return None
- **********************************************************************/
-void GPDMA_ClearIntPending(GPDMA_StateClear_Type type, uint8_t channel)
-{
- if (type == GPDMA_STATCLR_INTTC) // clears the terminal count interrupt request on DMA channel
- LPC_GPDMA->IntTCClear = GPDMA_DMACIntTCClear_Ch(channel);
- else // clear the error interrupt request
- LPC_GPDMA->IntErrClr = GPDMA_DMACIntErrClr_Ch(channel);
-}
-
-/**
- * @}
- */
-
-#endif /* _GPDMA */
-
-/**
- * @}
- */
-
-/* --------------------------------- End Of File ------------------------------ */
-
diff --git a/bsp/lpc408x/Libraries/Drivers/source/lpc_gpio.c b/bsp/lpc408x/Libraries/Drivers/source/lpc_gpio.c
deleted file mode 100644
index 84440f6977..0000000000
--- a/bsp/lpc408x/Libraries/Drivers/source/lpc_gpio.c
+++ /dev/null
@@ -1,905 +0,0 @@
-/**********************************************************************
-* $Id$ lpc_gpio.c 2011-06-02
-*//**
-* @file lpc_gpio.c
-* @brief Contains all functions support for GPIO firmware library
-* on LPC
-* @version 1.0
-* @date 02. June. 2011
-* @author NXP MCU SW Application Team
-*
-* Copyright(C) 2011, NXP Semiconductor
-* All rights reserved.
-*
-***********************************************************************
-* Software that is described herein is for illustrative purposes only
-* which provides customers with programming information regarding the
-* products. This software is supplied "AS IS" without any warranties.
-* NXP Semiconductors assumes no responsibility or liability for the
-* use of the software, conveys no license or title under any patent,
-* copyright, or mask work right to the product. NXP Semiconductors
-* reserves the right to make changes in the software without
-* notification. NXP Semiconductors also make 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'
-* relevant copyright 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.
-**********************************************************************/
-
-/* Peripheral group ----------------------------------------------------------- */
-/** @addtogroup GPIO
- * @{
- */
-#ifdef __BUILD_WITH_EXAMPLE__
-#include "lpc_libcfg.h"
-#else
-#include "lpc_libcfg_default.h"
-#endif /* __BUILD_WITH_EXAMPLE__ */
-#ifdef _GPIO
-
-/* Includes ------------------------------------------------------------------- */
-#include "lpc_gpio.h"
-#include "lpc_clkpwr.h"
-
-/* definitions ------------------------------------------------------------------- */
-#define GPIO_IS_ENABLED(x) (((x) != 0)? ENABLE:DISABLE)
-
-/* Private Functions ---------------------------------------------------------- */
-
-static LPC_GPIO_TypeDef *GPIO_GetPointer(uint8_t portNum);
-static GPIO_HalfWord_TypeDef *FIO_HalfWordGetPointer(uint8_t portNum);
-static GPIO_Byte_TypeDef *FIO_ByteGetPointer(uint8_t portNum);
-
-/*********************************************************************//**
- * @brief Get pointer to GPIO peripheral due to GPIO port
- * @param[in] portNum Port Number value, should be in range from 0 to 4.
- * @return Pointer to GPIO peripheral
- **********************************************************************/
-static LPC_GPIO_TypeDef *GPIO_GetPointer(uint8_t portNum)
-{
- LPC_GPIO_TypeDef *pGPIO = NULL;
-
- switch (portNum)
- {
- case 0:
- pGPIO = LPC_GPIO0;
- break;
-
- case 1:
- pGPIO = LPC_GPIO1;
- break;
-
- case 2:
- pGPIO = LPC_GPIO2;
- break;
-
- case 3:
- pGPIO = LPC_GPIO3;
- break;
-
- case 4:
- pGPIO = LPC_GPIO4;
- break;
-
- case 5:
- pGPIO = LPC_GPIO5;
- break;
-
- default:
- break;
- }
-
- return pGPIO;
-}
-
-/*********************************************************************//**
- * @brief Get pointer to FIO peripheral in halfword accessible style
- * due to FIO port
- * @param[in] portNum Port Number value, should be in range from 0 to 4.
- * @return Pointer to FIO peripheral
- **********************************************************************/
-static GPIO_HalfWord_TypeDef *FIO_HalfWordGetPointer(uint8_t portNum)
-{
- GPIO_HalfWord_TypeDef *pFIO = NULL;
-
- switch (portNum)
- {
- case 0:
- pFIO = GPIO0_HalfWord;
- break;
-
- case 1:
- pFIO = GPIO1_HalfWord;
- break;
-
- case 2:
- pFIO = GPIO2_HalfWord;
- break;
-
- case 3:
- pFIO = GPIO3_HalfWord;
- break;
-
- case 4:
- pFIO = GPIO4_HalfWord;
- break;
-
- case 5:
- pFIO = GPIO5_HalfWord;
- break;
-
- default:
- break;
- }
-
- return pFIO;
-}
-
-/*********************************************************************//**
- * @brief Get pointer to FIO peripheral in byte accessible style
- * due to FIO port
- * @param[in] portNum Port Number value, should be in range from 0 to 4.
- * @return Pointer to FIO peripheral
- **********************************************************************/
-static GPIO_Byte_TypeDef *FIO_ByteGetPointer(uint8_t portNum)
-{
- GPIO_Byte_TypeDef *pFIO = NULL;
-
- switch (portNum)
- {
- case 0:
- pFIO = GPIO0_Byte;
- break;
-
- case 1:
- pFIO = GPIO1_Byte;
- break;
-
- case 2:
- pFIO = GPIO2_Byte;
- break;
-
- case 3:
- pFIO = GPIO3_Byte;
- break;
-
- case 4:
- pFIO = GPIO4_Byte;
- break;
-
- case 5:
- pFIO = GPIO5_Byte;
- break;
-
- default:
- break;
- }
-
- return pFIO;
-}
-
-/* End of Private Functions --------------------------------------------------- */
-
-
-/* Public Functions ----------------------------------------------------------- */
-/** @addtogroup GPIO_Public_Functions
- * @{
- */
-
-
-/* GPIO ------------------------------------------------------------------------------ */
-
-/*********************************************************************//**
- * @brief Initialize the GPIO component by power on the clock
- * supplied to it.
- * @return None
- *
- * Note:
- **********************************************************************/
-void GPIO_Init(void)
-{
- CLKPWR_ConfigPPWR(CLKPWR_PCONP_PCGPIO, ENABLE);
-
- return;
-}
-
-
-/*********************************************************************//**
- * @brief De-initialize the GPIO component by power off the clock
- * supplied to it.
- * @return None
- *
- * Note:
- **********************************************************************/
-void GPIO_Deinit(void)
-{
- CLKPWR_ConfigPPWR(CLKPWR_PCONP_PCGPIO, DISABLE);
-
- return;
-}
-
-
-/*********************************************************************//**
- * @brief Set Direction for GPIO port.
- * @param[in] portNum Port Number value, should be in range from 0 to 4
- * @param[in] bitValue Value that contains all bits to set direction,
- * in range from 0 to 0xFFFFFFFF.
- * example: value 0x5 to set direction for bit 0 and bit 1.
- * @param[in] dir Direction value, should be:
- * - 0: Input.
- * - 1: Output.
- * @return None
- *
- * Note: All remaining bits that are not activated in bitValue (value '0')
- * will not be effected by this function.
- **********************************************************************/
-void GPIO_SetDir(uint8_t portNum, uint32_t bitValue, uint8_t dir)
-{
- LPC_GPIO_TypeDef *pGPIO = GPIO_GetPointer(portNum);
-
- if (pGPIO != NULL)
- {
- // Enable Output
- if (dir)
- {
- pGPIO->DIR |= bitValue;
- }
- // Enable Input
- else
- {
- pGPIO->DIR &= ~bitValue;
- }
- }
-}
-
-
-/*********************************************************************//**
- * @brief Set Value for bits that have output direction on GPIO port.
- * @param[in] portNum Port number value, should be in range from 0 to 4
- * @param[in] bitValue Value that contains all bits on GPIO to set,
- * in range from 0 to 0xFFFFFFFF.
- * example: value 0x5 to set bit 0 and bit 1.
- * @return None
- *
- * Note:
- * - For all bits that has been set as input direction, this function will
- * not effect.
- * - For all remaining bits that are not activated in bitValue (value '0')
- * will not be effected by this function.
- **********************************************************************/
-void GPIO_SetValue(uint8_t portNum, uint32_t bitValue)
-{
- LPC_GPIO_TypeDef *pGPIO = GPIO_GetPointer(portNum);
-
- if (pGPIO != NULL)
- {
- pGPIO->SET = bitValue;
- }
-}
-
-/*********************************************************************//**
- * @brief Clear Value for bits that have output direction on GPIO port.
- * @param[in] portNum Port number value, should be in range from 0 to 4
- * @param[in] bitValue Value that contains all bits on GPIO to clear,
- * in range from 0 to 0xFFFFFFFF.
- * example: value 0x5 to clear bit 0 and bit 1.
- * @return None
- *
- * Note:
- * - For all bits that has been set as input direction, this function will
- * not effect.
- * - For all remaining bits that are not activated in bitValue (value '0')
- * will not be effected by this function.
- **********************************************************************/
-void GPIO_ClearValue(uint8_t portNum, uint32_t bitValue)
-{
- LPC_GPIO_TypeDef *pGPIO = GPIO_GetPointer(portNum);
-
- if (pGPIO != NULL)
- {
- pGPIO->CLR = bitValue;
- }
-}
-
-/*********************************************************************//**
- * @brief Output to the GPIO pin an expected value
- * @param[in] portNum Port number value, should be in range from 0 to 4
- * @param[in] bitValue Value that contains all bits on GPIO to clear,
- * in range from 0 to 0xFFFFFFFF.
- * example: value 0x5 to clear bit 0 and bit 1.
- * @return None
- *
- * Note:
- * - For all bits that has been set as input direction, this function will
- * not effect.
- * - For all remaining bits that are not activated in bitValue (value '0')
- * will not be effected by this function.
- **********************************************************************/
-void GPIO_OutputValue(uint8_t portNum, uint32_t bitMask, uint8_t value)
-{
- if (value == 0)
- {
- GPIO_ClearValue(portNum, bitMask);
- }
- else
- {
- GPIO_SetValue(portNum, bitMask);
- }
-
-}
-
-
-/*********************************************************************//**
- * @brief Read Current state on port pin that have input direction of GPIO
- * @param[in] portNum Port number to read value, in range from 0 to 4
- * @return Current value of GPIO port.
- *
- * Note: Return value contain state of each port pin (bit) on that GPIO regardless
- * its direction is input or output.
- **********************************************************************/
-uint32_t GPIO_ReadValue(uint8_t portNum)
-{
- LPC_GPIO_TypeDef *pGPIO = GPIO_GetPointer(portNum);
-
- if (pGPIO != NULL)
- {
- return pGPIO->PIN;
- }
-
- return (0);
-}
-
-/*********************************************************************//**
- * @brief Enable GPIO interrupt (just used for P0.0-P0.30, P2.0-P2.13)
- * @param[in] portNum Port number to read value, should be: 0 or 2
- * @param[in] bitValue Value that contains all bits on GPIO to enable,
- * in range from 0 to 0xFFFFFFFF.
- * @param[in] edgeState state of edge, should be:
- * - 0: Rising edge
- * - 1: Falling edge
- * @return None
- **********************************************************************/
-void GPIO_IntCmd(uint8_t portNum, uint32_t bitValue, uint8_t edgeState)
-{
- if((portNum == 0)&&(edgeState == 0))
- LPC_GPIOINT->IO0IntEnR = bitValue;
- else if ((portNum == 2)&&(edgeState == 0))
- LPC_GPIOINT->IO2IntEnR = bitValue;
- else if ((portNum == 0)&&(edgeState == 1))
- LPC_GPIOINT->IO0IntEnF = bitValue;
- else if ((portNum == 2)&&(edgeState == 1))
- LPC_GPIOINT->IO2IntEnF = bitValue;
- else
- //Error
- while(1);
-}
-
-/*********************************************************************//**
- * @brief Get GPIO Interrupt Status (just used for P0.0-P0.30, P2.0-P2.13)
- * @param[in] portNum Port number to read value, should be: 0 or 2
- * @param[in] pinNum Pin number, should be: 0..30(with port 0) and 0..13
- * (with port 2)
- * @param[in] edgeState state of edge, should be:
- * - 0: Rising edge
- * - 1: Falling edge
- * @return Bool could be:
- * - ENABLE: Interrupt has been generated due to a rising
- * edge on P0.0
- * - DISABLE: A rising edge has not been detected on P0.0
- **********************************************************************/
-FunctionalState GPIO_GetIntStatus(uint8_t portNum, uint32_t pinNum, uint8_t edgeState)
-{
- if((portNum == 0) && (edgeState == 0))//Rising Edge
- return GPIO_IS_ENABLED(((LPC_GPIOINT->IO0IntStatR)>>pinNum)& 0x1);
- else if ((portNum == 2) && (edgeState == 0))
- return GPIO_IS_ENABLED(((LPC_GPIOINT->IO2IntStatR)>>pinNum)& 0x1);
- else if ((portNum == 0) && (edgeState == 1))//Falling Edge
- return GPIO_IS_ENABLED(((LPC_GPIOINT->IO0IntStatF)>>pinNum)& 0x1);
- else if ((portNum == 2) && (edgeState == 1))
- return GPIO_IS_ENABLED(((LPC_GPIOINT->IO2IntStatF)>>pinNum)& 0x1);
- else
- //Error
- while(1);
-}
-/*********************************************************************//**
- * @brief Clear GPIO interrupt (just used for P0.0-P0.30, P2.0-P2.13)
- * @param[in] portNum Port number to read value, should be: 0 or 2
- * @param[in] bitValue Value that contains all bits on GPIO to enable,
- * in range from 0 to 0xFFFFFFFF.
- * @return None
- **********************************************************************/
-void GPIO_ClearInt(uint8_t portNum, uint32_t bitValue)
-{
- if(portNum == 0)
- LPC_GPIOINT->IO0IntClr = bitValue;
- else if (portNum == 2)
- LPC_GPIOINT->IO2IntClr = bitValue;
- else
- //Invalid portNum
- while(1);
-}
-
-/* FIO word accessible ----------------------------------------------------------------- */
-/* Stub function for FIO (word-accessible) style */
-
-/**
- * @brief The same with GPIO_SetDir()
- */
-void FIO_SetDir(uint8_t portNum, uint32_t bitValue, uint8_t dir)
-{
- GPIO_SetDir(portNum, bitValue, dir);
-}
-
-/**
- * @brief The same with GPIO_SetValue()
- */
-void FIO_SetValue(uint8_t portNum, uint32_t bitValue)
-{
- GPIO_SetValue(portNum, bitValue);
-}
-
-/**
- * @brief The same with GPIO_ClearValue()
- */
-void FIO_ClearValue(uint8_t portNum, uint32_t bitValue)
-{
- GPIO_ClearValue(portNum, bitValue);
-}
-
-/**
- * @brief The same with GPIO_ReadValue()
- */
-uint32_t FIO_ReadValue(uint8_t portNum)
-{
- return (GPIO_ReadValue(portNum));
-}
-
-/**
- * @brief The same with GPIO_IntCmd()
- */
-void FIO_IntCmd(uint8_t portNum, uint32_t bitValue, uint8_t edgeState)
-{
- GPIO_IntCmd(portNum, bitValue, edgeState);
-}
-
-/**
- * @brief The same with GPIO_GetIntStatus()
- */
-FunctionalState FIO_GetIntStatus(uint8_t portNum, uint32_t pinNum, uint8_t edgeState)
-{
- return (GPIO_GetIntStatus(portNum, pinNum, edgeState));
-}
-
-/**
- * @brief The same with GPIO_ClearInt()
- */
-void FIO_ClearInt(uint8_t portNum, uint32_t bitValue)
-{
- GPIO_ClearInt(portNum, bitValue);
-}
-/*********************************************************************//**
- * @brief Set mask value for bits in FIO port
- * @param[in] portNum Port number, in range from 0 to 4
- * @param[in] bitValue Value that contains all bits in to set,
- * in range from 0 to 0xFFFFFFFF.
- * @param[in] maskValue Mask value contains state value for each bit:
- * - 0: not mask.
- * - 1: mask.
- * @return None
- *
- * Note:
- * - All remaining bits that are not activated in bitValue (value '0')
- * will not be effected by this function.
- * - After executing this function, in mask register, value '0' on each bit
- * enables an access to the corresponding physical pin via a read or write access,
- * while value '1' on bit (masked) that corresponding pin will not be changed
- * with write access and if read, will not be reflected in the updated pin.
- **********************************************************************/
-void FIO_SetMask(uint8_t portNum, uint32_t bitValue, uint8_t maskValue)
-{
- LPC_GPIO_TypeDef *pFIO = GPIO_GetPointer(portNum);
-
- if(pFIO != NULL)
- {
- // Mask
- if (maskValue)
- {
- pFIO->MASK |= bitValue;
- }
- // Un-mask
- else
- {
- pFIO->MASK &= ~bitValue;
- }
- }
-}
-
-
-/* FIO halfword accessible ------------------------------------------------------------- */
-
-/*********************************************************************//**
- * @brief Set direction for FIO port in halfword accessible style
- * @param[in] portNum Port number, in range from 0 to 4
- * @param[in] halfwordNum HalfWord part number, should be 0 (lower) or 1(upper)
- * @param[in] bitValue Value that contains all bits in to set direction,
- * in range from 0 to 0xFFFF.
- * @param[in] dir Direction value, should be:
- * - 0: Input.
- * - 1: Output.
- * @return None
- *
- * Note: All remaining bits that are not activated in bitValue (value '0')
- * will not be effected by this function.
- **********************************************************************/
-void FIO_HalfWordSetDir(uint8_t portNum, uint8_t halfwordNum, uint16_t bitValue, uint8_t dir)
-{
- GPIO_HalfWord_TypeDef *pFIO = FIO_HalfWordGetPointer(portNum);
-
- if(pFIO != NULL)
- {
- // Output direction
- if (dir)
- {
- // Upper
- if(halfwordNum)
- {
- pFIO->FIODIRU |= bitValue;
- }
- // lower
- else
- {
- pFIO->FIODIRL |= bitValue;
- }
- }
- // Input direction
- else
- {
- // Upper
- if(halfwordNum)
- {
- pFIO->FIODIRU &= ~bitValue;
- }
- // lower
- else
- {
- pFIO->FIODIRL &= ~bitValue;
- }
- }
- }
-}
-
-
-/*********************************************************************//**
- * @brief Set mask value for bits in FIO port in halfword accessible style
- * @param[in] portNum Port number, in range from 0 to 4
- * @param[in] halfwordNum HalfWord part number, should be 0 (lower) or 1(upper)
- * @param[in] bitValue Value that contains all bits in to set,
- * in range from 0 to 0xFFFF.
- * @param[in] maskValue Mask value contains state value for each bit:
- * - 0: not mask.
- * - 1: mask.
- * @return None
- *
- * Note:
- * - All remaining bits that are not activated in bitValue (value '0')
- * will not be effected by this function.
- * - After executing this function, in mask register, value '0' on each bit
- * enables an access to the corresponding physical pin via a read or write access,
- * while value '1' on bit (masked) that corresponding pin will not be changed
- * with write access and if read, will not be reflected in the updated pin.
- **********************************************************************/
-void FIO_HalfWordSetMask(uint8_t portNum, uint8_t halfwordNum, uint16_t bitValue, uint8_t maskValue)
-{
- GPIO_HalfWord_TypeDef *pFIO = FIO_HalfWordGetPointer(portNum);
-
- if(pFIO != NULL)
- {
- // Mask
- if (maskValue)
- {
- // Upper
- if(halfwordNum)
- {
- pFIO->FIOMASKU |= bitValue;
- }
- // lower
- else
- {
- pFIO->FIOMASKL |= bitValue;
- }
- }
- // Un-mask
- else
- {
- // Upper
- if(halfwordNum)
- {
- pFIO->FIOMASKU &= ~bitValue;
- }
- // lower
- else
- {
- pFIO->FIOMASKL &= ~bitValue;
- }
- }
- }
-}
-
-
-/*********************************************************************//**
- * @brief Set bits for FIO port in halfword accessible style
- * @param[in] portNum Port number, in range from 0 to 4
- * @param[in] halfwordNum HalfWord part number, should be 0 (lower) or 1(upper)
- * @param[in] bitValue Value that contains all bits in to set,
- * in range from 0 to 0xFFFF.
- * @return None
- *
- * Note:
- * - For all bits that has been set as input direction, this function will
- * not effect.
- * - For all remaining bits that are not activated in bitValue (value '0')
- * will not be effected by this function.
- **********************************************************************/
-void FIO_HalfWordSetValue(uint8_t portNum, uint8_t halfwordNum, uint16_t bitValue)
-{
- GPIO_HalfWord_TypeDef *pFIO = FIO_HalfWordGetPointer(portNum);
-
- if(pFIO != NULL)
- {
- // Upper
- if(halfwordNum)
- {
- pFIO->FIOSETU = bitValue;
- }
- // lower
- else
- {
- pFIO->FIOSETL = bitValue;
- }
- }
-}
-
-
-/*********************************************************************//**
- * @brief Clear bits for FIO port in halfword accessible style
- * @param[in] portNum Port number, in range from 0 to 4
- * @param[in] halfwordNum HalfWord part number, should be 0 (lower) or 1(upper)
- * @param[in] bitValue Value that contains all bits in to clear,
- * in range from 0 to 0xFFFF.
- * @return None
- *
- * Note:
- * - For all bits that has been set as input direction, this function will
- * not effect.
- * - For all remaining bits that are not activated in bitValue (value '0')
- * will not be effected by this function.
- **********************************************************************/
-void FIO_HalfWordClearValue(uint8_t portNum, uint8_t halfwordNum, uint16_t bitValue)
-{
- GPIO_HalfWord_TypeDef *pFIO = FIO_HalfWordGetPointer(portNum);
-
- if(pFIO != NULL)
- {
- // Upper
- if(halfwordNum)
- {
- pFIO->FIOCLRU = bitValue;
- }
- // lower
- else
- {
- pFIO->FIOCLRL = bitValue;
- }
- }
-}
-
-
-/*********************************************************************//**
- * @brief Read Current state on port pin that have input direction of GPIO
- * in halfword accessible style.
- * @param[in] portNum Port number, in range from 0 to 4
- * @param[in] halfwordNum HalfWord part number, should be 0 (lower) or 1(upper)
- * @return Current value of FIO port pin of specified halfword.
- * Note: Return value contain state of each port pin (bit) on that FIO regardless
- * its direction is input or output.
- **********************************************************************/
-uint16_t FIO_HalfWordReadValue(uint8_t portNum, uint8_t halfwordNum)
-{
- GPIO_HalfWord_TypeDef *pFIO = FIO_HalfWordGetPointer(portNum);
-
- if(pFIO != NULL)
- {
- // Upper
- if(halfwordNum)
- {
- return (pFIO->FIOPINU);
- }
- // lower
- else
- {
- return (pFIO->FIOPINL);
- }
- }
-
- return (0);
-}
-
-
-/* FIO Byte accessible ------------------------------------------------------------ */
-
-/*********************************************************************//**
- * @brief Set direction for FIO port in byte accessible style
- * @param[in] portNum Port number, in range from 0 to 4
- * @param[in] byteNum Byte part number, should be in range from 0 to 3
- * @param[in] bitValue Value that contains all bits in to set direction,
- * in range from 0 to 0xFF.
- * @param[in] dir Direction value, should be:
- * - 0: Input.
- * - 1: Output.
- * @return None
- *
- * Note: All remaining bits that are not activated in bitValue (value '0')
- * will not be effected by this function.
- **********************************************************************/
-void FIO_ByteSetDir(uint8_t portNum, uint8_t byteNum, uint8_t bitValue, uint8_t dir)
-{
- GPIO_Byte_TypeDef *pFIO = FIO_ByteGetPointer(portNum);
-
- if(pFIO != NULL)
- {
- // Output direction
- if (dir)
- {
- if (byteNum <= 3)
- {
- pFIO->FIODIR[byteNum] |= bitValue;
- }
- }
- // Input direction
- else
- {
- if (byteNum <= 3)
- {
- pFIO->FIODIR[byteNum] &= ~bitValue;
- }
- }
- }
-}
-
-/*********************************************************************//**
- * @brief Set mask value for bits in FIO port in byte accessible style
- * @param[in] portNum Port number, in range from 0 to 4
- * @param[in] byteNum Byte part number, should be in range from 0 to 3
- * @param[in] bitValue Value that contains all bits in to set mask,
- * in range from 0 to 0xFF.
- * @param[in] maskValue Mask value contains state value for each bit:
- * - 0: not mask.
- * - 1: mask.
- * @return None
- *
- * Note:
- * - All remaining bits that are not activated in bitValue (value '0')
- * will not be effected by this function.
- * - After executing this function, in mask register, value '0' on each bit
- * enables an access to the corresponding physical pin via a read or write access,
- * while value '1' on bit (masked) that corresponding pin will not be changed
- * with write access and if read, will not be reflected in the updated pin.
- **********************************************************************/
-void FIO_ByteSetMask(uint8_t portNum, uint8_t byteNum, uint8_t bitValue, uint8_t maskValue)
-{
- GPIO_Byte_TypeDef *pFIO = FIO_ByteGetPointer(portNum);
-
- if(pFIO != NULL)
- {
- // Mask
- if (maskValue)
- {
- if (byteNum <= 3)
- {
- pFIO->FIOMASK[byteNum] |= bitValue;
- }
- }
- // Un-mask
- else {
- if (byteNum <= 3)
- {
- pFIO->FIOMASK[byteNum] &= ~bitValue;
- }
- }
- }
-}
-
-
-/*********************************************************************//**
- * @brief Set bits for FIO port in byte accessible style
- * @param[in] portNum Port number, in range from 0 to 4
- * @param[in] byteNum Byte part number, should be in range from 0 to 3
- * @param[in] bitValue Value that contains all bits in to set,
- * in range from 0 to 0xFF.
- * @return None
- *
- * Note:
- * - For all bits that has been set as input direction, this function will
- * not effect.
- * - For all remaining bits that are not activated in bitValue (value '0')
- * will not be effected by this function.
- **********************************************************************/
-void FIO_ByteSetValue(uint8_t portNum, uint8_t byteNum, uint8_t bitValue)
-{
- GPIO_Byte_TypeDef *pFIO = FIO_ByteGetPointer(portNum);
-
- if (pFIO != NULL) {
- if (byteNum <= 3)
- {
- pFIO->FIOSET[byteNum] = bitValue;
- }
- }
-}
-
-
-/*********************************************************************//**
- * @brief Clear bits for FIO port in byte accessible style
- * @param[in] portNum Port number, in range from 0 to 4
- * @param[in] byteNum Byte part number, should be in range from 0 to 3
- * @param[in] bitValue Value that contains all bits in to clear,
- * in range from 0 to 0xFF.
- * @return None
- *
- * Note:
- * - For all bits that has been set as input direction, this function will
- * not effect.
- * - For all remaining bits that are not activated in bitValue (value '0')
- * will not be effected by this function.
- **********************************************************************/
-void FIO_ByteClearValue(uint8_t portNum, uint8_t byteNum, uint8_t bitValue)
-{
- GPIO_Byte_TypeDef *pFIO = FIO_ByteGetPointer(portNum);
-
- if (pFIO != NULL)
- {
- if (byteNum <= 3)
- {
- pFIO->FIOCLR[byteNum] = bitValue;
- }
- }
-}
-
-
-/*********************************************************************//**
- * @brief Read Current state on port pin that have input direction of GPIO
- * in byte accessible style.
- * @param[in] portNum Port number, in range from 0 to 4
- * @param[in] byteNum Byte part number, should be in range from 0 to 3
- * @return Current value of FIO port pin of specified byte part.
- * Note: Return value contain state of each port pin (bit) on that FIO regardless
- * its direction is input or output.
- **********************************************************************/
-uint8_t FIO_ByteReadValue(uint8_t portNum, uint8_t byteNum)
-{
- GPIO_Byte_TypeDef *pFIO = FIO_ByteGetPointer(portNum);
-
- if (pFIO != NULL)
- {
- if (byteNum <= 3)
- {
- return (pFIO->FIOPIN[byteNum]);
- }
- }
- return (0);
-}
-
-/**
- * @}
- */
-
-#endif /* _GPIO */
-
-/**
- * @}
- */
-
-/* --------------------------------- End Of File ------------------------------ */
diff --git a/bsp/lpc408x/Libraries/Drivers/source/lpc_i2c.c b/bsp/lpc408x/Libraries/Drivers/source/lpc_i2c.c
deleted file mode 100644
index c466cf655e..0000000000
--- a/bsp/lpc408x/Libraries/Drivers/source/lpc_i2c.c
+++ /dev/null
@@ -1,1416 +0,0 @@
-/**********************************************************************
-* $Id$ lpc_i2c.c 2011-06-02
-*//**
-* @file lpc_i2c.c
-* @brief Contains all functions support for I2C firmware library
-* on LPC
-* @version 1.0
-* @date 02. June. 2011
-* @author NXP MCU SW Application Team
-*
-* Copyright(C) 2011, NXP Semiconductor
-* All rights reserved.
-*
-***********************************************************************
-* Software that is described herein is for illustrative purposes only
-* which provides customers with programming information regarding the
-* products. This software is supplied "AS IS" without any warranties.
-* NXP Semiconductors assumes no responsibility or liability for the
-* use of the software, conveys no license or title under any patent,
-* copyright, or mask work right to the product. NXP Semiconductors
-* reserves the right to make changes in the software without
-* notification. NXP Semiconductors also make 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'
-* relevant copyright 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.
-**********************************************************************/
-
-/* Peripheral group ----------------------------------------------------------- */
-/** @addtogroup I2C
- * @{
- */
-#ifdef __BUILD_WITH_EXAMPLE__
-#include "lpc_libcfg.h"
-#else
-#include "lpc_libcfg_default.h"
-#endif /* __BUILD_WITH_EXAMPLE__ */
-#ifdef _I2C
-
-/* Includes ------------------------------------------------------------------- */
-#include "lpc_i2c.h"
-#include "lpc_clkpwr.h"
-#include "lpc_pinsel.h"
-
-/* Private Types -------------------------------------------------------------- */
-/** @defgroup I2C_Private_Types I2C Private Types
- * @{
- */
-
-/**
- * @brief I2C device configuration structure type
- */
-typedef struct
-{
- uint32_t txrx_setup; /* Transmission setup */
- int32_t dir; /* Current direction phase, 0 - write, 1 - read */
-} I2C_CFG_T;
-
-/**
- * @}
- */
-
-/* Private Variables ---------------------------------------------------------- */
-/**
- * @brief II2C driver data for I2C0, I2C1 and I2C2
- */
-static I2C_CFG_T i2cdat[3];
-
-static uint32_t I2C_MasterComplete[3];
-static uint32_t I2C_SlaveComplete[3];
-
-static uint32_t I2C_MonitorBufferIndex;
-
-/* Private Functions ---------------------------------------------------------- */
-
-/* Get pointer to expected I2C */
-static LPC_I2C_TypeDef* I2C_GetPointer(en_I2C_unitId compId);
-
-/* Generate a start condition on I2C bus (in master mode only) */
-static uint32_t I2C_Start (LPC_I2C_TypeDef *I2Cx, I2C_TRANSFER_OPT_Type Opt);
-
-/* Generate a stop condition on I2C bus (in master mode only) */
-static void I2C_Stop (LPC_I2C_TypeDef *I2Cx, I2C_TRANSFER_OPT_Type Opt);
-
-/* I2C send byte subroutine */
-static uint32_t I2C_SendByte (LPC_I2C_TypeDef *I2Cx, uint8_t databyte);
-
-/* I2C get byte subroutine */
-static uint32_t I2C_GetByte (LPC_I2C_TypeDef *I2Cx, uint8_t *retdat, Bool ack);
-
-/* I2C set clock (hz) */
-static void I2C_SetClock (LPC_I2C_TypeDef *I2Cx, uint32_t target_clock);
-
-/*--------------------------------------------------------------------------------*/
-
-/********************************************************************//**
- * @brief Convert from I2C peripheral to number
- * @param[in] I2Cx: I2C peripheral selected, should be:
- * - LPC_I2C0
- * - LPC_I2C1
- * - LPC_I2C2
- * @return I2C number, could be: 0..2
- *********************************************************************/
-static LPC_I2C_TypeDef* I2C_GetPointer(en_I2C_unitId compId)
-{
- LPC_I2C_TypeDef* pI2C;
-
- switch (compId)
- {
- case I2C_0:
- pI2C = LPC_I2C0;
- break;
-
- case I2C_1:
- pI2C = LPC_I2C1;
- break;
-
- case I2C_2:
- pI2C = LPC_I2C2;
- break;
-
- default:
- pI2C = NULL;
- break;
- }
-
- return pI2C;
-}
-
-
-/********************************************************************//**
- * @brief Generate a start condition on I2C bus (in master mode only)
- * @param[in] I2Cx: I2C peripheral selected, should be:
- * - LPC_I2C0
- * - LPC_I2C1
- * - LPC_I2C2
- * @param[in] Opt a I2C_TRANSFER_OPT_Type type that selected for
- * interrupt or polling mode.
- * @return value of I2C status register after generate a start condition
- *********************************************************************/
-static uint32_t I2C_Start (LPC_I2C_TypeDef *I2Cx, I2C_TRANSFER_OPT_Type Opt)
-{
- // Reset STA, STO, SI
- I2Cx->CONCLR = I2C_I2CONCLR_SIC|I2C_I2CONCLR_STOC|I2C_I2CONCLR_STAC;
-
- // Enter to Master Transmitter mode
- I2Cx->CONSET = I2C_I2CONSET_STA;
-
- if(Opt == I2C_TRANSFER_POLLING)
- {
- // Wait for complete
- while (!(I2Cx->CONSET & I2C_I2CONSET_SI));
- }
-
- return (I2Cx->STAT & I2C_STAT_CODE_BITMASK);
-}
-
-/********************************************************************//**
- * @brief Generate a stop condition on I2C bus (in master mode only)
- * @param[in] I2Cx: I2C peripheral selected, should be:
- * - LPC_I2C0
- * - LPC_I2C1
- * - LPC_I2C2
- * @param[in] Opt a I2C_TRANSFER_OPT_Type type that selected for
- * interrupt or polling mode.
- * @return None
- *********************************************************************/
-static void I2C_Stop (LPC_I2C_TypeDef *I2Cx, I2C_TRANSFER_OPT_Type Opt)
-{
- /* Make sure start bit is not active */
- if (I2Cx->CONSET & I2C_I2CONSET_STA)
- {
- I2Cx->CONCLR = I2C_I2CONCLR_STAC;
- }
-
- I2Cx->CONSET = I2C_I2CONSET_STO;
-
- I2Cx->CONCLR = I2C_I2CONCLR_SIC;
-
- if(Opt == I2C_TRANSFER_POLLING)
- {
- // wait for stop is sent
- while(I2Cx->CONSET & I2C_I2CONSET_STO)
- {
- if(I2Cx->CONSET & I2C_I2CONSET_SI)
- I2Cx->CONCLR = I2C_I2CONCLR_SIC;
- }
- }
-}
-
-/********************************************************************//**
- * @brief Send a byte
- * @param[in] I2Cx: I2C peripheral selected, should be:
- * - LPC_I2C0
- * - LPC_I2C1
- * - LPC_I2C2
- * @param[in] databyte: number of byte
- * @return value of I2C status register after sending
- *********************************************************************/
-static uint32_t I2C_SendByte (LPC_I2C_TypeDef *I2Cx, uint8_t databyte)
-{
- uint32_t CodeStatus = I2Cx->STAT & I2C_STAT_CODE_BITMASK;
-
- if((CodeStatus != I2C_I2STAT_M_TX_START) &&
- (CodeStatus != I2C_I2STAT_M_TX_RESTART) &&
- (CodeStatus != I2C_I2STAT_M_TX_SLAW_ACK) &&
- (CodeStatus != I2C_I2STAT_M_TX_DAT_ACK) )
- {
- return CodeStatus;
- }
-
- I2Cx->DAT = databyte & I2C_I2DAT_BITMASK;
-
- I2Cx->CONSET = I2C_I2CONSET_AA;
-
- I2Cx->CONCLR = I2C_I2CONCLR_SIC;
-
- return (I2Cx->STAT & I2C_STAT_CODE_BITMASK);
-}
-
-/********************************************************************//**
- * @brief Get a byte
- * @param[in] I2Cx: I2C peripheral selected, should be:
- * - LPC_I2C0
- * - LPC_I2C1
- * - LPC_I2C2
- * @param[out] retdat pointer to return data
- * @param[in] ack assert acknowledge or not, should be: TRUE/FALSE
- * @return value of I2C status register after sending
- *********************************************************************/
-static uint32_t I2C_GetByte (LPC_I2C_TypeDef *I2Cx, uint8_t *retdat, Bool ack)
-{
- *retdat = (uint8_t) (I2Cx->DAT & I2C_I2DAT_BITMASK);
-
- if (ack == TRUE)
- {
- I2Cx->CONSET = I2C_I2CONSET_AA;
- }
- else
- {
- I2Cx->CONCLR = I2C_I2CONCLR_AAC;
- }
-
- I2Cx->CONCLR = I2C_I2CONCLR_SIC;
-
- return (I2Cx->STAT & I2C_STAT_CODE_BITMASK);
-}
-
-/*********************************************************************//**
- * @brief Setup clock rate for I2C peripheral
- * @param[in] I2Cx I2C peripheral selected, should be:
- * - LPC_I2C0
- * - LPC_I2C1
- * - LPC_I2C2
- * @param[in] target_clock : clock of SSP (Hz)
- * @return None
- ***********************************************************************/
-static void I2C_SetClock (LPC_I2C_TypeDef *I2Cx, uint32_t target_clock)
-{
- uint32_t temp;
-
- temp = CLKPWR_GetCLK(CLKPWR_CLKTYPE_PER) / target_clock;
-
- /* Set the I2C clock value to register */
- I2Cx->SCLH = (uint32_t)(temp / 2);
-
- I2Cx->SCLL = (uint32_t)(temp - I2Cx->SCLH);
-}
-
-
-/* End of Private Functions --------------------------------------------------- */
-
-
-/* Public Functions ----------------------------------------------------------- */
-/** @addtogroup I2C_Public_Functions
- * @{
- */
-
-/********************************************************************//**
- * @brief Initializes the I2Cx peripheral with specified parameter.
- * @param[in] I2Cx I2C peripheral selected, should be
- * - LPC_I2C0
- * - LPC_I2C1
- * - LPC_I2C2
- * @param[in] clockrate Target clock rate value to initialized I2C
- * peripheral (Hz)
- * @return None
- *********************************************************************/
-void I2C_Init(en_I2C_unitId i2cId, uint32_t clockrate)
-{
- uint32_t clkSetting;
-
- LPC_I2C_TypeDef* I2Cx = I2C_GetPointer(i2cId);
-
- switch (i2cId)
- {
- case I2C_0:
- clkSetting = CLKPWR_PCONP_PCI2C0;
- break;
-
-
- case I2C_1:
- clkSetting = CLKPWR_PCONP_PCI2C1;
- break;
-
- case I2C_2:
- clkSetting = CLKPWR_PCONP_PCI2C2;
- break;
-
- default:
-
- return;
- }
-
- CLKPWR_ConfigPPWR (clkSetting, ENABLE);
-
- /* Set clock rate */
- I2C_SetClock(I2Cx,clockrate);
-
- /* Set I2C operation to default */
- I2Cx->CONCLR = (I2C_I2CONCLR_AAC | I2C_I2CONCLR_STAC | I2C_I2CONCLR_I2ENC);
-}
-
-/*********************************************************************//**
- * @brief De-initializes the I2C peripheral registers to their
- * default reset values.
- * @param[in] I2Cx I2C peripheral selected, should be
- * - LPC_I2C0
- * - LPC_I2C1
- * - LPC_I2C2
- * @return None
- **********************************************************************/
-void I2C_DeInit(en_I2C_unitId i2cId)
-{
- uint32_t clkSetting;
-
- LPC_I2C_TypeDef* I2Cx = I2C_GetPointer(i2cId);
-
- /* Disable I2C control */
- I2Cx->CONCLR = 0xFF;
-
- switch (i2cId)
- {
- case I2C_0:
- clkSetting = CLKPWR_PCONP_PCI2C0;
- break;
-
-
- case I2C_1:
- clkSetting = CLKPWR_PCONP_PCI2C1;
- break;
-
- case I2C_2:
- clkSetting = CLKPWR_PCONP_PCI2C2;
- break;
-
- default:
-
- return;
- }
-
- CLKPWR_ConfigPPWR (clkSetting, DISABLE);
-}
-
-/*********************************************************************//**
- * @brief Enable or disable I2C peripheral's operation
- * @param[in] I2Cx I2C peripheral selected, should be
- * - LPC_I2C0
- * - LPC_I2C1
- * - LPC_I2C2
- * @param[in] NewState New State of I2Cx peripheral's operation
- * @return none
- **********************************************************************/
-void I2C_Cmd(en_I2C_unitId i2cId, en_I2C_Mode Mode, FunctionalState NewState)
-{
- LPC_I2C_TypeDef* I2Cx = I2C_GetPointer(i2cId);
-
- if (NewState == ENABLE)
- {
- if(Mode != I2C_SLAVE_MODE)
- I2Cx->CONSET = I2C_I2CONSET_I2EN;
- else
- I2Cx->CONSET = I2C_I2CONSET_I2EN | I2C_I2CONSET_AA;
- }
- else
- {
- I2Cx->CONCLR = I2C_I2CONCLR_I2ENC;
- }
-}
-
-/*********************************************************************//**
- * @brief Enable/Disable interrupt for I2C peripheral
- * @param[in] I2Cx I2C peripheral selected, should be:
- * - LPC_I2C0
- * - LPC_I2C1
- * - LPC_I2C2
- * @param[in] NewState New State of I2C peripheral interrupt in NVIC core
- * should be:
- * - ENABLE: enable interrupt for this I2C peripheral
- * - DISABLE: disable interrupt for this I2C peripheral
- * @return None
- **********************************************************************/
-void I2C_IntCmd (en_I2C_unitId i2cId, Bool NewState)
-{
- IRQn_Type irq;
-
- switch (i2cId)
- {
- case I2C_0:
- irq = I2C0_IRQn;
- break;
-
- case I2C_1:
- irq = I2C1_IRQn;
- break;
-
- case I2C_2:
- irq = I2C2_IRQn;
- break;
-
- default:
-
- return;
- }
-
- if (NewState)
- {
- NVIC_EnableIRQ(irq);
- }
- else
- {
- NVIC_DisableIRQ(irq);
- }
-
- return;
-}
-/*********************************************************************//**
- * @brief Handle I2C Master states.
- * @param[in] I2Cx I2C peripheral selected, should be:
- * - I2C_0
- * - I2C_1
- * - I2C_2
- * @param[in] CodeStatus I2C state
- * @param[in] TransferCfg Pointer to a I2C_S_SETUP_Type structure that
- * contains specified information about the
- * configuration for master transfer.
- * @param[in] Opt a I2C_TRANSFER_OPT_Type type that selected for
- * interrupt or polling mode.
- * @return It can be
- * - I2C_OK
- * -I2C_BYTE_RECV
- * -I2C_BYTE_SENT
- * -I2C_SEND_END
- * -I2C_RECV_END
- * - I2C_ERR
- * - I2C_NAK_RECV
- **********************************************************************/
-int32_t I2C_MasterHanleStates(en_I2C_unitId i2cId,
- uint32_t CodeStatus,
- I2C_M_SETUP_Type *TransferCfg,
- I2C_TRANSFER_OPT_Type Opt
- )
-{
- LPC_I2C_TypeDef* I2Cx = I2C_GetPointer(i2cId);
- uint8_t *txdat;
- uint8_t *rxdat;
- uint8_t tmp;
- int32_t Ret = I2C_OK;
-
- //get buffer to send/receive
- txdat = (uint8_t *) &TransferCfg->tx_data[TransferCfg->tx_count];
- rxdat = (uint8_t *) &TransferCfg->rx_data[TransferCfg->rx_count];
-
- switch(CodeStatus)
- {
- case I2C_I2STAT_M_TX_START:
- case I2C_I2STAT_M_TX_RESTART:
- //case I2C_I2STAT_M_RX_START:
- //case I2C_I2STAT_M_RX_RESTART
- // Send data first
- if(TransferCfg->tx_count < TransferCfg->tx_length)
- {
- /* Send slave address + WR direction bit = 0 ----------------------------------- */
- I2C_SendByte(I2Cx, (TransferCfg->sl_addr7bit << 1));
- Ret = I2C_BYTE_SENT;
- }
- else if (TransferCfg->rx_count < TransferCfg->rx_length)
- {
- /* Send slave address + RD direction bit = 1 ----------------------------------- */
- I2C_SendByte(I2Cx, ((TransferCfg->sl_addr7bit << 1) | 0x01));
- Ret = I2C_BYTE_SENT;
- }
- // Clear STA bit after the slave address is sent
- I2Cx->CONCLR = I2C_I2CONCLR_STAC;
- break;
- case I2C_I2STAT_M_TX_SLAW_ACK:
- case I2C_I2STAT_M_TX_DAT_ACK:
-
- if(TransferCfg->tx_count < TransferCfg->tx_length)
- {
- I2C_SendByte(I2Cx, *txdat);
-
- txdat++;
-
- TransferCfg->tx_count++;
-
- Ret = I2C_BYTE_SENT;
- }
- else
- {
- if(TransferCfg->rx_count >= TransferCfg->rx_length)
- {
- I2C_Stop(I2Cx, Opt);
- }
- Ret = I2C_SEND_END;
-
-
- }
-
- break;
- case I2C_I2STAT_M_TX_DAT_NACK:
- if(TransferCfg->rx_count >= TransferCfg->rx_length)
- {
- I2C_Stop(I2Cx, Opt);
- }
- Ret = I2C_SEND_END;
- break;
- case I2C_I2STAT_M_RX_ARB_LOST:
- case I2C_I2STAT_S_RX_ARB_LOST_M_GENCALL:
- case I2C_I2STAT_S_TX_ARB_LOST_M_SLA:
- //case I2C_I2STAT_M_TX_ARB_LOST:
- I2C_Stop(I2Cx, Opt);
- Ret = I2C_ERR;
- break;
- case I2C_I2STAT_M_RX_SLAR_ACK:
- if(TransferCfg->rx_length > 1)
- I2Cx->CONSET = I2C_I2CONSET_AA;
- else
- I2Cx->CONCLR = I2C_I2CONCLR_AAC;
- I2Cx->CONCLR = I2C_I2CONCLR_SIC;
-
- Ret = I2C_BYTE_RECV;
- break;
- case I2C_I2STAT_M_RX_DAT_ACK:
- if (TransferCfg->rx_count <TransferCfg->rx_length)
- {
- if ((TransferCfg->rx_length > 1) && (TransferCfg->rx_count < (TransferCfg->rx_length - 2)))
- {
- I2C_GetByte(I2Cx, &tmp, TRUE);
-
- Ret = I2C_BYTE_RECV;
-
- }
- else // the next byte is the last byte, send NACK instead.
- {
- I2C_GetByte(I2Cx, &tmp, FALSE);
- Ret = I2C_BYTE_RECV;
- }
- *rxdat++ = tmp;
-
- TransferCfg->rx_count++;
- }
- else
- {
- I2C_Stop(I2Cx, Opt);
- Ret = I2C_RECV_END;
- }
-
- break;
- case I2C_I2STAT_M_RX_DAT_NACK:
- I2C_GetByte(I2Cx, &tmp, FALSE);
- if (TransferCfg->rx_count < TransferCfg->rx_length)
- {
- *rxdat++ = tmp;
- TransferCfg->rx_count++;
- }
- I2C_Stop(I2Cx, Opt);
- Ret = I2C_RECV_END;
- break;
-
- case I2C_I2STAT_M_RX_SLAR_NACK:
- case I2C_I2STAT_M_TX_SLAW_NACK:
- case I2C_I2STAT_BUS_ERROR:
- // Send STOP condition
- I2C_Stop(I2Cx, Opt);
- Ret = I2C_ERR;
- break;
- /* No status information */
- case I2C_I2STAT_NO_INF:
- if ((TransferCfg->tx_count <TransferCfg->tx_length)||
- (TransferCfg->rx_count <TransferCfg->rx_length))
- {
- I2C_Stop(I2Cx, Opt);
- Ret = I2C_ERR;
- }
- else
- {
- Ret = I2C_RECV_END;
- }
- break;
- default:
- I2Cx->CONCLR = I2C_I2CONCLR_SIC;
- break;
- }
-
- return Ret;
-}
-
-/*********************************************************************//**
- * @brief Handle I2C Slave states.
- * @param[in] I2Cx I2C peripheral selected, should be:
- * - I2C_0
- * - I2C_1
- * - I2C_2
- * @param[in] CodeStatus I2C state
- * @param[in] TransferCfg Pointer to a I2C_S_SETUP_Type structure that
- * contains specified information about the
- * configuration for master transfer.
- * @return It can be
- * - I2C_OK
- * -I2C_BYTE_RECV
- * -I2C_BYTE_SENT
- * -I2C_SEND_END
- * -I2C_RECV_END
- * - I2C_ERR
- * - I2C_NAK_RECV
- **********************************************************************/
-int32_t I2C_SlaveHanleStates(en_I2C_unitId i2cId,
- uint32_t CodeStatus,
- I2C_S_SETUP_Type *TransferCfg)
-{
- LPC_I2C_TypeDef* I2Cx = I2C_GetPointer(i2cId);
- int32_t Ret = I2C_OK;
- uint8_t *txdat;
- uint8_t *rxdat;
-
- //get buffer to send/receive
- txdat = (uint8_t *) &TransferCfg->tx_data[TransferCfg->tx_count];
- rxdat = (uint8_t *) &TransferCfg->rx_data[TransferCfg->rx_count];
-
- switch (CodeStatus)
- {
- /* Reading phase -------------------------------------------------------- */
- /* Own SLA+R has been received, ACK has been returned */
- case I2C_I2STAT_S_RX_SLAW_ACK:
-
- /* General call address has been received, ACK has been returned */
- case I2C_I2STAT_S_RX_GENCALL_ACK:
- I2Cx->CONSET = I2C_I2CONSET_AA;
- I2Cx->CONCLR = I2C_I2CONCLR_SIC;
- break;
- /* Arbitration has been lost in Slave Address + R/W bit as bus Master. General Call has
- been received and ACK has been returned.*/
- case I2C_I2STAT_S_RX_ARB_LOST_M_GENCALL:
- I2Cx->CONSET = I2C_I2CONSET_AA|I2C_I2CONSET_STA;
- I2Cx->CONCLR = I2C_I2CONCLR_SIC;
- break;
- /* Previously addressed with own SLA;
- * DATA byte has been received;
- * ACK has been returned */
- case I2C_I2STAT_S_RX_ARB_LOST_M_SLA:
- case I2C_I2STAT_S_RX_PRE_SLA_DAT_ACK:
-
- /*
- * All data bytes that over-flow the specified receive
- * data length, just ignore them.
- */
- if ((TransferCfg->rx_count < TransferCfg->rx_length) && (TransferCfg->rx_data != NULL))
- {
- *rxdat++ = (uint8_t)I2Cx->DAT;
-
- TransferCfg->rx_count++;
-
- Ret = I2C_BYTE_RECV;
- }
- if(TransferCfg->rx_count == (TransferCfg->rx_length) ) {
- I2Cx->CONCLR = I2C_I2CONCLR_AAC|I2C_I2CONCLR_SIC;
- Ret = I2C_BYTE_RECV;
- }
- else {
- I2Cx->CONSET = I2C_I2CONSET_AA;
- I2Cx->CONCLR = I2C_I2CONCLR_SIC;
- }
-
- break;
- /* DATA has been received, Only the first data byte will be received with ACK. Additional
- data will be received with NOT ACK. */
- case I2C_I2STAT_S_RX_PRE_GENCALL_DAT_ACK:
- if ((TransferCfg->rx_count < TransferCfg->rx_length) && (TransferCfg->rx_data != NULL))
- {
- *rxdat++ = (uint8_t)I2Cx->DAT;
-
- TransferCfg->rx_count++;
-
- Ret = I2C_BYTE_RECV;
- }
- I2Cx->CONCLR = I2C_I2CONCLR_AAC|I2C_I2CONCLR_SIC;
- break;
-
- /* Writing phase -------------------------------------------------------- */
- /* Own SLA+R has been received, ACK has been returned */
- case I2C_I2STAT_S_TX_SLAR_ACK:
-
- /* Data has been transmitted, ACK has been received */
- case I2C_I2STAT_S_TX_DAT_ACK:
- /*
- * All data bytes that over-flow the specified receive
- * data length, just ignore them.
- */
- if ((TransferCfg->tx_count < TransferCfg->tx_length) && (TransferCfg->tx_data != NULL))
- {
- I2Cx->DAT = *txdat++;
-
- TransferCfg->tx_count++;
-
- Ret = I2C_BYTE_SENT;
- }
-
- I2Cx->CONSET = I2C_I2CONSET_AA;
- I2Cx->CONCLR = I2C_I2CONCLR_SIC;
- break;
- /* Arbitration lost in Slave Address and R/W bit as bus Master. Own Slave Address + Read
- has been received, ACK has been returned. */
- case I2C_I2STAT_S_TX_ARB_LOST_M_SLA:
- if ((TransferCfg->tx_count < TransferCfg->tx_length) && (TransferCfg->tx_data != NULL))
- {
- I2Cx->DAT = *txdat++;
-
- TransferCfg->tx_count++;
-
- Ret = I2C_BYTE_SENT;
- }
- I2Cx->CONSET = I2C_I2CONSET_AA|I2C_I2CONSET_STA;
- I2Cx->CONCLR = I2C_I2CONCLR_SIC;
- break;
-
- case I2C_I2STAT_S_TX_LAST_DAT_ACK:
- /* Data has been transmitted, NACK has been received,
- * that means there's no more data to send, exit now */
- /*
- * Note: Don't wait for stop event since in slave transmit mode,
- * since there no proof lets us know when a stop signal has been received
- * on slave side.
- */
- case I2C_I2STAT_S_TX_DAT_NACK:
- I2Cx->CONSET = I2C_I2CONSET_AA;
- I2Cx->CONCLR = I2C_I2CONCLR_SIC;
- Ret = I2C_SEND_END;
- break;
-
- /* Previously addressed with own SLA;
- * DATA byte has been received;
- * NOT ACK has been returned */
- case I2C_I2STAT_S_RX_PRE_SLA_DAT_NACK:
-
- /* DATA has been received, NOT ACK has been returned */
- case I2C_I2STAT_S_RX_PRE_GENCALL_DAT_NACK:
- I2Cx->CONSET = I2C_I2CONSET_AA;
- I2Cx->CONCLR = I2C_I2CONCLR_SIC;
- Ret = I2C_RECV_END;
- break;
-
- /*
- * Note that: Return code only let us know a stop condition mixed
- * with a repeat start condition in the same code value.
- * So we should provide a time-out. In case this is really a stop
- * condition, this will return back after time out condition. Otherwise,
- * next session that is slave receive data will be completed.
- */
-
- /* A Stop or a repeat start condition */
- case I2C_I2STAT_S_RX_STA_STO_SLVREC_SLVTRX:
- I2Cx->CONSET = I2C_I2CONSET_AA;
- I2Cx->CONCLR = I2C_I2CONCLR_SIC;
- Ret = I2C_STA_STO_RECV;
- break;
-
- /* No status information */
- case I2C_I2STAT_NO_INF:
- /* Other status must be captured */
- default:
- I2Cx->CONSET = I2C_I2CONSET_AA;
- I2Cx->CONCLR = I2C_I2CONCLR_SIC;
- break;
-
- }
-
- return Ret;
-}
-/*********************************************************************//**
- * @brief General Master Interrupt handler for I2C peripheral
- * @param[in] I2Cx I2C peripheral selected, should be:
- * - LPC_I2C
- * - LPC_I2C1
- * - LPC_I2C2
- * @return None
- **********************************************************************/
-void I2C_MasterHandler(en_I2C_unitId i2cId)
-{
- LPC_I2C_TypeDef* I2Cx = I2C_GetPointer(i2cId);
- uint8_t returnCode;
- I2C_M_SETUP_Type *txrx_setup;
- int32_t Ret = I2C_OK;
-
- txrx_setup = (I2C_M_SETUP_Type *) i2cdat[i2cId].txrx_setup;
-
- returnCode = (I2Cx->STAT & I2C_STAT_CODE_BITMASK);
-
- // Save current status
- txrx_setup->status = returnCode;
-
- Ret = I2C_MasterHanleStates(i2cId, returnCode, txrx_setup, I2C_TRANSFER_INTERRUPT);
-
- if(I2C_CheckError(Ret))
- {
- if(txrx_setup->retransmissions_count < txrx_setup->retransmissions_max)
- {
- // Retry
- txrx_setup->retransmissions_count ++;
- txrx_setup->tx_count = 0;
- txrx_setup->rx_count = 0;
- // Reset STA, STO, SI
- I2C_Start(I2Cx, I2C_TRANSFER_INTERRUPT);
- return;
- }
- else
- {
- goto s_int_end;
- }
- }
- else if (Ret & I2C_SEND_END)
- {
- // If no need to wait for data from Slave
- if(txrx_setup->rx_count >= (txrx_setup->rx_length))
- {
- goto s_int_end;
- }
- else // Start to wait for data from Slave
- {
- // Reset STA, STO, SI
- I2C_Start(I2Cx, I2C_TRANSFER_INTERRUPT);
- return;
- }
- }
- else if (Ret & I2C_RECV_END)
- {
- goto s_int_end;
- }
- else
- {
- return;
- }
-
-s_int_end:
- // Disable interrupt
- I2C_IntCmd(i2cId, FALSE);
-
- I2Cx->CONCLR = I2C_I2CONCLR_AAC | I2C_I2CONCLR_SIC | I2C_I2CONCLR_STAC;
-
- I2C_MasterComplete[i2cId] = TRUE;
-
-}
-
-
-/*********************************************************************//**
- * @brief General Slave Interrupt handler for I2C peripheral
- * @param[in] I2Cx I2C peripheral selected, should be:
- * - LPC_I2C0
- * - LPC_I2C1
- * - LPC_I2C2
- * @return None
- **********************************************************************/
-void I2C_SlaveHandler (en_I2C_unitId i2cId)
-{
- LPC_I2C_TypeDef* I2Cx = I2C_GetPointer(i2cId);
-
- uint8_t returnCode;
- I2C_S_SETUP_Type *txrx_setup;
- uint32_t timeout;
- int32_t Ret = I2C_OK;
-
- txrx_setup = (I2C_S_SETUP_Type *) i2cdat[i2cId].txrx_setup;
-
-handle_state:
-
- returnCode = (I2Cx->STAT & I2C_STAT_CODE_BITMASK);
- // Save current status
- txrx_setup->status = returnCode;
-
-
- Ret = I2C_SlaveHanleStates(i2cId, returnCode, txrx_setup);
-
- if(I2C_CheckError(Ret))
- {
- goto s_int_end;
- }
- else if (Ret & I2C_STA_STO_RECV)
- {
- if((txrx_setup->tx_count >= (txrx_setup->tx_length)) &&
- (txrx_setup->rx_count >= (txrx_setup->rx_length)))
- {
- goto s_int_end;
- }
- // Temporally lock the interrupt for timeout condition
- I2C_IntCmd(i2cId, FALSE);
- // enable time out
- timeout = I2C_SLAVE_TIME_OUT;
- while(1)
- {
- if (I2Cx->CONSET & I2C_I2CONSET_SI)
- {
- // re-Enable interrupt
- I2C_IntCmd(i2cId, TRUE);
- goto handle_state;
- }
- else
- {
- timeout--;
- if (timeout == 0)
- {
- // timeout occur, it's really a stop condition
- txrx_setup->status |= I2C_SETUP_STATUS_DONE;
- goto s_int_end;
- }
- }
- }
- }
- else if(Ret &I2C_SEND_END)
- {
- goto s_int_end;
- }
- else
- {
- return;
- }
-
-s_int_end:
- // Disable interrupt
- I2C_IntCmd(i2cId, FALSE);
- I2Cx->CONCLR = I2C_I2CONCLR_AAC | I2C_I2CONCLR_SIC | I2C_I2CONCLR_STAC;
-
- I2C_SlaveComplete[i2cId] = TRUE;
-}
-
-/*********************************************************************//**
- * @brief Transmit and Receive data in master mode
- * @param[in] I2Cx I2C peripheral selected, should be:
- * - LPC_I2C0
- * - LPC_I2C1
- * - LPC_I2C2
- * @param[in] TransferCfg Pointer to a I2C_M_SETUP_Type structure that
- * contains specified information about the
- * configuration for master transfer.
- * @param[in] Opt a I2C_TRANSFER_OPT_Type type that selected for
- * interrupt or polling mode.
- * @return SUCCESS or ERROR
- *
- * Note:
- * - In case of using I2C to transmit data only, either transmit length set to 0
- * or transmit data pointer set to NULL.
- * - In case of using I2C to receive data only, either receive length set to 0
- * or receive data pointer set to NULL.
- * - In case of using I2C to transmit followed by receive data, transmit length,
- * transmit data pointer, receive length and receive data pointer should be set
- * corresponding.
- **********************************************************************/
-Status I2C_MasterTransferData(en_I2C_unitId i2cId, I2C_M_SETUP_Type *TransferCfg,
- I2C_TRANSFER_OPT_Type Opt)
-{
- LPC_I2C_TypeDef* I2Cx = I2C_GetPointer(i2cId);
-
- uint32_t CodeStatus;
- int32_t Ret = I2C_OK;
-
- // Reset I2C setup value to default state
- TransferCfg->tx_count = 0;
- TransferCfg->rx_count = 0;
- TransferCfg->status = 0;
-
- if (Opt == I2C_TRANSFER_POLLING)
- {
- /* First Start condition -------------------------------------------------------------- */
- TransferCfg->retransmissions_count = 0;
-retry:
- // Reset I2C setup value to default state
- TransferCfg->tx_count = 0;
- TransferCfg->rx_count = 0;
-
- // Start command
- CodeStatus = I2C_Start(I2Cx, I2C_TRANSFER_POLLING);
-
- while(1) // send data first and then receive data from Slave.
- {
- Ret = I2C_MasterHanleStates(i2cId, CodeStatus, TransferCfg, I2C_TRANSFER_POLLING);
- if(I2C_CheckError(Ret))
- {
- TransferCfg->retransmissions_count++;
- if (TransferCfg->retransmissions_count > TransferCfg->retransmissions_max){
- // save status
- TransferCfg->status = CodeStatus | I2C_SETUP_STATUS_NOACKF;
- goto error;
- } else {
- goto retry;
- }
- }
- else if( (Ret & I2C_BYTE_SENT) ||
- (Ret & I2C_BYTE_RECV))
- {
- // Wait for sending ends/ Wait for next byte
- while (!(I2Cx->CONSET & I2C_I2CONSET_SI));
- }
- else if (Ret & I2C_SEND_END) // already send all data
- {
- // If no need to wait for data from Slave
- if(TransferCfg->rx_count >= (TransferCfg->rx_length))
- {
- break;
- }
- else
- {
- I2C_Start(I2Cx, I2C_TRANSFER_POLLING);
- }
- }
- else if (Ret & I2C_RECV_END) // already receive all data
- {
- break;
- }
- CodeStatus = I2Cx->STAT & I2C_STAT_CODE_BITMASK;
- }
- return SUCCESS;
-error:
- return ERROR;
- }
-
- else if (Opt == I2C_TRANSFER_INTERRUPT)
- {
- // Setup tx_rx data, callback and interrupt handler
- i2cdat[i2cId].txrx_setup = (uint32_t) TransferCfg;
-
- // Set direction phase, write first
- i2cdat[i2cId].dir = 0;
-
- /* First Start condition -------------------------------------------------------------- */
- // Reset STA, STO, SI
- I2C_Start(I2Cx, I2C_TRANSFER_INTERRUPT);
-
- I2C_IntCmd(i2cId, TRUE);
-
- return (SUCCESS);
- }
-
- return ERROR;
-}
-
-/*********************************************************************//**
- * @brief Receive and Transmit data in slave mode
- * @param[in] I2Cx I2C peripheral selected, should be
- * - LPC_I2C0
- * - LPC_I2C1
- * - LPC_I2C2
- * @param[in] TransferCfg Pointer to a I2C_S_SETUP_Type structure that
- * contains specified information about the
- * configuration for master transfer.
- * @param[in] Opt I2C_TRANSFER_OPT_Type type that selected for
- * interrupt or polling mode.
- * @return SUCCESS or ERROR
- *
- * Note:
- * The mode of slave's operation depends on the command sent from master on
- * the I2C bus. If the master send a SLA+W command, this sub-routine will
- * use receive data length and receive data pointer. If the master send a SLA+R
- * command, this sub-routine will use transmit data length and transmit data
- * pointer.
- * If the master issue an repeat start command or a stop command, the slave will
- * enable an time out condition, during time out condition, if there's no activity
- * on I2C bus, the slave will exit, otherwise (i.e. the master send a SLA+R/W),
- * the slave then switch to relevant operation mode. The time out should be used
- * because the return status code can not show difference from stop and repeat
- * start command in slave operation.
- * In case of the expected data length from master is greater than data length
- * that slave can support:
- * - In case of reading operation (from master): slave will return I2C_I2DAT_IDLE_CHAR
- * value.
- * - In case of writing operation (from master): slave will ignore remain data from master.
- **********************************************************************/
-Status I2C_SlaveTransferData(en_I2C_unitId i2cId, I2C_S_SETUP_Type *TransferCfg,
- I2C_TRANSFER_OPT_Type Opt)
-{
- LPC_I2C_TypeDef* I2Cx = I2C_GetPointer(i2cId);
- int32_t Ret = I2C_OK;
-
- uint32_t CodeStatus;
- uint32_t timeout;
- int32_t time_en;
-
- // Reset I2C setup value to default state
- TransferCfg->tx_count = 0;
- TransferCfg->rx_count = 0;
- TransferCfg->status = 0;
-
- // Polling option
- if (Opt == I2C_TRANSFER_POLLING)
- {
- /* Set AA bit to ACK command on I2C bus */
- I2Cx->CONSET = I2C_I2CONSET_AA;
-
- /* Clear SI bit to be ready ... */
- I2Cx->CONCLR = (I2C_I2CONCLR_SIC | I2C_I2CONCLR_STAC|I2C_I2CONCLR_STOC);
-
- time_en = 0;
- timeout = 0;
-
- while (1)
- {
- /* Check SI flag ready */
- if (I2Cx->CONSET & I2C_I2CONSET_SI)
- {
- time_en = 0;
-
- CodeStatus = (I2Cx->STAT & I2C_STAT_CODE_BITMASK);
-
- Ret = I2C_SlaveHanleStates(i2cId, CodeStatus, TransferCfg);
- if(I2C_CheckError(Ret))
- {
- goto s_error;
- }
- else if(Ret & I2C_STA_STO_RECV)
- {
- if((TransferCfg->tx_count >= (TransferCfg->tx_length)) &&
- (TransferCfg->rx_count >= (TransferCfg->rx_length)))
- {
- goto s_end_stage;
- }
- time_en = 1;
- timeout = 0;
- }
- else if (Ret & I2C_SEND_END)
- {
- goto s_end_stage;
- }
- }
- else if (time_en)
- {
- if (timeout++ > I2C_SLAVE_TIME_OUT)
- {
- // it's really a stop condition, goto end stage
- goto s_end_stage;
- }
- }
- }
-
-s_end_stage:
- /* Clear AA bit to disable ACK on I2C bus */
- I2Cx->CONCLR = I2C_I2CONCLR_AAC;
-
- // Check if there's no error during operation
- // Update status
- TransferCfg->status = CodeStatus | I2C_SETUP_STATUS_DONE;
- return SUCCESS;
-
-s_error:
- /* Clear AA bit to disable ACK on I2C bus */
- I2Cx->CONCLR = I2C_I2CONCLR_AAC;
-
- // Update status
- TransferCfg->status = CodeStatus;
- return ERROR;
- }
-
- else if (Opt == I2C_TRANSFER_INTERRUPT)
- {
- // Setup tx_rx data, callback and interrupt handler
- i2cdat[i2cId].txrx_setup = (uint32_t) TransferCfg;
-
- // Set direction phase, read first
- i2cdat[i2cId].dir = 1;
-
- // Enable AA
- I2Cx->CONSET = I2C_I2CONSET_AA;
- I2Cx->CONCLR = I2C_I2CONCLR_SIC | I2C_I2CONCLR_STAC;
- I2C_IntCmd(i2cId, TRUE);
-
- return (SUCCESS);
- }
-
- return ERROR;
-}
-
-/*********************************************************************//**
- * @brief Set Own slave address in I2C peripheral corresponding to
- * parameter specified in OwnSlaveAddrConfigStruct.
- * @param[in] I2Cx I2C peripheral selected, should be
- * - LPC_I2C0
- * - LPC_I2C1
- * - LPC_I2C2
- * @param[in] OwnSlaveAddrConfigStruct Pointer to a I2C_OWNSLAVEADDR_CFG_Type
- * structure that contains the configuration information for the
-* specified I2C slave address.
- * @return None
- **********************************************************************/
-void I2C_SetOwnSlaveAddr(en_I2C_unitId i2cId, I2C_OWNSLAVEADDR_CFG_Type *OwnSlaveAddrConfigStruct)
-{
- LPC_I2C_TypeDef* I2Cx = I2C_GetPointer(i2cId);
-
- uint32_t tmp;
-
- tmp = (((uint32_t)(OwnSlaveAddrConfigStruct->SlaveAddr_7bit << 1)) \
- | ((OwnSlaveAddrConfigStruct->GeneralCallState == ENABLE) ? 0x01 : 0x00))& I2C_I2ADR_BITMASK;
-
- switch (OwnSlaveAddrConfigStruct->SlaveAddrChannel)
- {
- case 0:
- I2Cx->ADR0 = tmp;
-
- I2Cx->MASK0 = I2C_I2MASK_MASK((uint32_t) \
- (OwnSlaveAddrConfigStruct->SlaveAddrMaskValue));
- break;
-
- case 1:
- I2Cx->ADR1 = tmp;
-
- I2Cx->MASK1 = I2C_I2MASK_MASK((uint32_t) \
- (OwnSlaveAddrConfigStruct->SlaveAddrMaskValue));
- break;
-
- case 2:
- I2Cx->ADR2 = tmp;
-
- I2Cx->MASK2 = I2C_I2MASK_MASK((uint32_t) \
- (OwnSlaveAddrConfigStruct->SlaveAddrMaskValue));
- break;
-
- case 3:
- I2Cx->ADR3 = tmp;
-
- I2Cx->MASK3 = I2C_I2MASK_MASK((uint32_t) \
- (OwnSlaveAddrConfigStruct->SlaveAddrMaskValue));
- break;
- }
-}
-
-
-/*********************************************************************//**
- * @brief Configures functionality in I2C monitor mode
- * @param[in] I2Cx I2C peripheral selected, should be
- * - LPC_I2C0
- * - LPC_I2C1
- * - LPC_I2C2
- * @param[in] Monitor configuration. It can include:
- * - I2C_I2MMCTRL_ENA_SCL: I2C module can 'stretch'
- * the clock line (hold it low) until it has had time to
- * respond to an I2C interrupt.
- * - I2C_I2MMCTRL_MATCH_ALL: When the I2C is in monitor mode,
- * an interrupt will be generated on ANY address received.
- * @param[in] NewState New State of this function, should be:
- * - ENABLE: Enable this function.
- * - DISABLE: Disable this function.
- * @return None
- **********************************************************************/
-void I2C_MonitorModeConfig(en_I2C_unitId i2cId, uint32_t MonitorCfgType, FunctionalState NewState)
-{
- LPC_I2C_TypeDef* I2Cx = I2C_GetPointer(i2cId);
-
- if (NewState == ENABLE)
- {
- I2Cx->MMCTRL |= MonitorCfgType;
- }
- else
- {
- I2Cx->MMCTRL &= (~MonitorCfgType) & I2C_I2MMCTRL_BITMASK;
- }
-}
-
-
-/*********************************************************************//**
- * @brief Enable/Disable I2C monitor mode
- * @param[in] I2Cx I2C peripheral selected, should be
- * - LPC_I2C0
- * - LPC_I2C1
- * - LPC_I2C2
- * @param[in] NewState New State of this function, should be:
- * - ENABLE: Enable monitor mode.
- * - DISABLE: Disable monitor mode.
- * @return None
- **********************************************************************/
-void I2C_MonitorModeCmd(en_I2C_unitId i2cId, FunctionalState NewState)
-{
- LPC_I2C_TypeDef* I2Cx = I2C_GetPointer(i2cId);
-
- if (NewState == ENABLE)
- {
- I2Cx->MMCTRL |= I2C_I2MMCTRL_MM_ENA;
- I2Cx->CONSET = I2C_I2CONSET_AA;
- I2Cx->CONCLR = I2C_I2CONCLR_SIC | I2C_I2CONCLR_STAC;
- }
- else
- {
- I2Cx->MMCTRL &= (~I2C_I2MMCTRL_MM_ENA) & I2C_I2MMCTRL_BITMASK;
- I2Cx->CONCLR = I2C_I2CONCLR_SIC | I2C_I2CONCLR_STAC | I2C_I2CONCLR_AAC;
- }
-
- I2C_MonitorBufferIndex = 0;
-}
-
-
-/*********************************************************************//**
- * @brief Get data from I2C data buffer in monitor mode.
- * @param[in] I2Cx I2C peripheral selected, should be
- * - LPC_I2C0
- * - LPC_I2C1
- * - LPC_I2C2
- * @return None
- * Note: In monitor mode, the I2C module may lose the ability to stretch
- * the clock (stall the bus) if the ENA_SCL bit is not set. This means that
- * the processor will have a limited amount of time to read the contents of
- * the data received on the bus. If the processor reads the DAT shift
- * register, as it ordinarily would, it could have only one bit-time to
- * respond to the interrupt before the received data is overwritten by
- * new data.
- **********************************************************************/
-uint8_t I2C_MonitorGetDatabuffer(en_I2C_unitId i2cId)
-{
- LPC_I2C_TypeDef* I2Cx = I2C_GetPointer(i2cId);
-
- return ((uint8_t)(I2Cx->DATA_BUFFER));
-}
-
-/*********************************************************************//**
- * @brief Get data from I2C data buffer in monitor mode.
- * @param[in] I2Cx I2C peripheral selected, should be
- * - LPC_I2C0
- * - LPC_I2C1
- * - LPC_I2C2
- * @return None
- * Note: In monitor mode, the I2C module may lose the ability to stretch
- * the clock (stall the bus) if the ENA_SCL bit is not set. This means that
- * the processor will have a limited amount of time to read the contents of
- * the data received on the bus. If the processor reads the DAT shift
- * register, as it ordinarily would, it could have only one bit-time to
- * respond to the interrupt before the received data is overwritten by
- * new data.
- **********************************************************************/
-BOOL_8 I2C_MonitorHandler(en_I2C_unitId i2cId, uint8_t *buffer, uint32_t size)
-{
- LPC_I2C_TypeDef* I2Cx = I2C_GetPointer(i2cId);
-
- BOOL_8 ret=FALSE;
-
- I2Cx->CONCLR = I2C_I2CONCLR_SIC;
-
- buffer[I2C_MonitorBufferIndex] = (uint8_t)(I2Cx->DATA_BUFFER);
-
- I2C_MonitorBufferIndex++;
-
- if(I2C_MonitorBufferIndex >= size)
- {
- ret = TRUE;
- }
- return ret;
-}
-/*********************************************************************//**
- * @brief Get status of Master Transfer
- * @param[in] I2Cx I2C peripheral selected, should be:
- * - LPC_I2C0
- * - LPC_I2C1
- * - LPC_I2C2
- * @return Master transfer status, could be:
- * - TRUE master transfer completed
- * - FALSE master transfer have not completed yet
- **********************************************************************/
-uint32_t I2C_MasterTransferComplete(en_I2C_unitId i2cId)
-{
- uint32_t retval;
-
- retval = I2C_MasterComplete[i2cId];
-
- I2C_MasterComplete[i2cId] = FALSE;
-
- return retval;
-}
-
-/*********************************************************************//**
- * @brief Get status of Slave Transfer
- * @param[in] I2Cx I2C peripheral selected, should be:
- * - LPC_I2C0
- * - LPC_I2C1
- * - LPC_I2C2
- * @return Complete status, could be: TRUE/FALSE
- **********************************************************************/
-uint32_t I2C_SlaveTransferComplete(en_I2C_unitId i2cId)
-{
- uint32_t retval;
-
- retval = I2C_SlaveComplete[i2cId];
-
- I2C_SlaveComplete[i2cId] = FALSE;
-
- return retval;
-}
-
-#endif /*_I2C*/
-
-/**
- * @}
- */
-
-
-/**
- * @}
- */
-
-/* --------------------------------- End Of File ------------------------------ */
diff --git a/bsp/lpc408x/Libraries/Drivers/source/lpc_i2s.c b/bsp/lpc408x/Libraries/Drivers/source/lpc_i2s.c
deleted file mode 100644
index 88172c7554..0000000000
--- a/bsp/lpc408x/Libraries/Drivers/source/lpc_i2s.c
+++ /dev/null
@@ -1,589 +0,0 @@
-/**********************************************************************
-* $Id$ lpc_i2s.c 2011-06-02
-*//**
-* @file lpc_i2s.c
-* @brief Contains all functions support for I2S firmware library
-* on LPC
-* @version 1.0
-* @date 02. June. 2011
-* @author NXP MCU SW Application Team
-*
-* Copyright(C) 2011, NXP Semiconductor
-* All rights reserved.
-*
-***********************************************************************
-* Software that is described herein is for illustrative purposes only
-* which provides customers with programming information regarding the
-* products. This software is supplied "AS IS" without any warranties.
-* NXP Semiconductors assumes no responsibility or liability for the
-* use of the software, conveys no license or title under any patent,
-* copyright, or mask work right to the product. NXP Semiconductors
-* reserves the right to make changes in the software without
-* notification. NXP Semiconductors also make 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'
-* relevant copyright 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.
-**********************************************************************/
-
-/* Peripheral group ----------------------------------------------------------- */
-/** @addtogroup I2S
- * @{
- */
-#ifdef __BUILD_WITH_EXAMPLE__
-#include "lpc_libcfg.h"
-#else
-#include "lpc_libcfg_default.h"
-#endif /* __BUILD_WITH_EXAMPLE__ */
-#ifdef _I2S
-
-/* Includes ------------------------------------------------------------------- */
-#include "lpc_i2s.h"
-#include "lpc_clkpwr.h"
-
-/* definitions ---------------------------------------------------------- */
-#define I2S_IS_ENABLED(x) ((x)? ENABLE:DISABLE)
-/* Private Functions ---------------------------------------------------------- */
-
-static uint8_t i2s_GetWordWidth(LPC_I2S_TypeDef *I2Sx, uint8_t TRMode);
-static uint8_t i2s_GetChannel(LPC_I2S_TypeDef *I2Sx, uint8_t TRMode);
-
-/********************************************************************//**
- * @brief Get I2S wordwidth value
- * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S
- * @param[in] TRMode is the I2S mode, should be:
- * - I2S_TX_MODE = 0: transmit mode
- * - I2S_RX_MODE = 1: receive mode
- * @return The wordwidth value, should be: 8,16 or 32
- *********************************************************************/
-static uint8_t i2s_GetWordWidth(LPC_I2S_TypeDef *I2Sx, uint8_t TRMode) {
- uint8_t value;
-
- if (TRMode == I2S_TX_MODE) {
- value = (I2Sx->DAO) & 0x03; /* get wordwidth bit */
- } else {
- value = (I2Sx->DAI) & 0x03; /* get wordwidth bit */
- }
- switch (value) {
- case I2S_WORDWIDTH_8:
- return 8;
- case I2S_WORDWIDTH_16:
- return 16;
- default:
- return 32;
- }
-}
-
-/********************************************************************//**
- * @brief Get I2S channel value
- * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S
- * @param[in] TRMode is the I2S mode, should be:
- * - I2S_TX_MODE = 0: transmit mode
- * - I2S_RX_MODE = 1: receive mode
- * @return The channel value, should be: 1(mono) or 2(stereo)
- *********************************************************************/
-static uint8_t i2s_GetChannel(LPC_I2S_TypeDef *I2Sx, uint8_t TRMode) {
- uint8_t value;
-
- if (TRMode == I2S_TX_MODE) {
- value = ((I2Sx->DAO) & 0x04)>>2; /* get bit[2] */
- } else {
- value = ((I2Sx->DAI) & 0x04)>>2; /* get bit[2] */
- }
- if(value == I2S_MONO) return 1;
- return 2;
-}
-
-/* End of Private Functions --------------------------------------------------- */
-
-
-/* Public Functions ----------------------------------------------------------- */
-/** @addtogroup I2S_Public_Functions
- * @{
- */
-
-/********************************************************************//**
- * @brief Initialize I2S
- * - Turn on power and clock
- * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S
- * @return none
- *********************************************************************/
-void I2S_Init(LPC_I2S_TypeDef *I2Sx) {
- // Turn on power and clock
- CLKPWR_ConfigPPWR(CLKPWR_PCONP_PCI2S, ENABLE);
- LPC_I2S->DAI = LPC_I2S->DAO = 0x00;
-}
-
-/********************************************************************//**
- * @brief Configuration I2S, setting:
- * - master/slave mode
- * - wordwidth value
- * - channel mode
- * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S
- * @param[in] TRMode transmit/receive mode, should be:
- * - I2S_TX_MODE = 0: transmit mode
- * - I2S_RX_MODE = 1: receive mode
- * @param[in] ConfigStruct pointer to I2S_CFG_Type structure
- * which will be initialized.
- * @return none
- *********************************************************************/
-void I2S_Config(LPC_I2S_TypeDef *I2Sx, uint8_t TRMode, I2S_CFG_Type* ConfigStruct)
-{
- uint32_t bps, config;
- /* Setup clock */
- bps = (ConfigStruct->wordwidth +1)*8;
-
- /* Calculate audio config */
- config = (bps - 1)<<6 | (ConfigStruct->ws_sel)<<5 | (ConfigStruct->reset)<<4 |
- (ConfigStruct->stop)<<3 | (ConfigStruct->mono)<<2 | (ConfigStruct->wordwidth);
-
- if(TRMode == I2S_RX_MODE){
- LPC_I2S->DAI = config;
- }else{
- LPC_I2S->DAO = config;
- }
-}
-
-/********************************************************************//**
- * @brief DeInitial both I2S transmit or receive
- * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S
- * @return none
- *********************************************************************/
-void I2S_DeInit(LPC_I2S_TypeDef *I2Sx) {
- // Turn off power and clock
- CLKPWR_ConfigPPWR(CLKPWR_PCONP_PCI2S, DISABLE);
-}
-
-/********************************************************************//**
- * @brief Get I2S Buffer Level
- * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S
- * @param[in] TRMode Transmit/receive mode, should be:
- * - I2S_TX_MODE = 0: transmit mode
- * - I2S_RX_MODE = 1: receive mode
- * @return current level of Transmit/Receive Buffer
- *********************************************************************/
-uint8_t I2S_GetLevel(LPC_I2S_TypeDef *I2Sx, uint8_t TRMode)
-{
-
- if(TRMode == I2S_TX_MODE)
- {
- return ((I2Sx->STATE >> 16) & 0xFF);
- }
- else
- {
- return ((I2Sx->STATE >> 8) & 0xFF);
- }
-}
-
-/********************************************************************//**
- * @brief I2S Start: clear all STOP,RESET and MUTE bit, ready to operate
- * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S
- * @return none
- *********************************************************************/
-void I2S_Start(LPC_I2S_TypeDef *I2Sx)
-{
- //Clear STOP,RESET and MUTE bit
- I2Sx->DAO &= ~I2S_DAI_RESET;
- I2Sx->DAI &= ~I2S_DAI_RESET;
- I2Sx->DAO &= ~I2S_DAI_STOP;
- I2Sx->DAI &= ~I2S_DAI_STOP;
- I2Sx->DAO &= ~I2S_DAI_MUTE;
-}
-
-/********************************************************************//**
- * @brief I2S Send data
- * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S
- * @param[in] BufferData pointer to uint32_t is the data will be send
- * @return none
- *********************************************************************/
-void I2S_Send(LPC_I2S_TypeDef *I2Sx, uint32_t BufferData)
-{
- I2Sx->TXFIFO = BufferData;
-}
-
-/********************************************************************//**
- * @brief I2S Receive Data
- * @param[in] I2Sx pointer to LPC_I2S_TypeDef
- * @return received value
- *********************************************************************/
-uint32_t I2S_Receive(LPC_I2S_TypeDef* I2Sx)
-{
- return (I2Sx->RXFIFO);
-}
-
-/********************************************************************//**
- * @brief I2S Pause
- * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S
- * @param[in] TRMode is transmit/receive mode, should be:
- * - I2S_TX_MODE = 0: transmit mode
- * - I2S_RX_MODE = 1: receive mode
- * @return none
- *********************************************************************/
-void I2S_Pause(LPC_I2S_TypeDef *I2Sx, uint8_t TRMode) {
- if (TRMode == I2S_TX_MODE) //Transmit mode
- {
- I2Sx->DAO |= I2S_DAO_STOP;
- } else //Receive mode
- {
- I2Sx->DAI |= I2S_DAI_STOP;
- }
-}
-
-/********************************************************************//**
- * @brief I2S Mute
- * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S
- * @param[in] TRMode is transmit/receive mode, should be:
- * - I2S_TX_MODE = 0: transmit mode
- * - I2S_RX_MODE = 1: receive mode
- * @return none
- *********************************************************************/
-void I2S_Mute(LPC_I2S_TypeDef *I2Sx, uint8_t TRMode) {
- if (TRMode == I2S_TX_MODE) //Transmit mode
- {
- I2Sx->DAO |= I2S_DAO_MUTE;
- } else //Receive mode
- {
- I2Sx->DAI |= I2S_DAI_MUTE;
- }
-}
-
-/********************************************************************//**
- * @brief I2S Stop
- * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S
- * @param[in] TRMode is transmit/receive mode, should be:
- * - I2S_TX_MODE = 0: transmit mode
- * - I2S_RX_MODE = 1: receive mode
- * @return none
- *********************************************************************/
-void I2S_Stop(LPC_I2S_TypeDef *I2Sx, uint8_t TRMode) {
- if (TRMode == I2S_TX_MODE) //Transmit mode
- {
- I2Sx->DAO &= ~I2S_DAO_MUTE;
- I2Sx->DAO |= I2S_DAO_STOP;
- I2Sx->DAO |= I2S_DAO_RESET;
- } else //Receive mode
- {
- I2Sx->DAI |= I2S_DAI_STOP;
- I2Sx->DAI |= I2S_DAI_RESET;
- }
-}
-/********************************************************************//**
- * @brief Set frequency for I2S
- * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S
- * @param[in] Freq is the frequency for I2S will be set. It can range
- * from 16-96 kHz(16, 22.05, 32, 44.1, 48, 96kHz)
- * @param[in] TRMode is transmit/receive mode, should be:
- * - I2S_TX_MODE = 0: transmit mode
- * - I2S_RX_MODE = 1: receive mode
- * @return Status: ERROR or SUCCESS
- *********************************************************************/
-Status I2S_FreqConfig(LPC_I2S_TypeDef *I2Sx, uint32_t Freq, uint8_t TRMode) {
- uint32_t cclk;
- uint8_t channel, wordwidth;
- uint32_t x, y;
- uint64_t divider;
- uint16_t dif;
- uint16_t x_divide, y_divide;
- uint16_t err, ErrorOptimal = 0xFFFF;
-
- uint32_t N;
-
- //get cclk
- cclk = CLKPWR_GetCLK(CLKPWR_CLKTYPE_CPU);
-
- if(TRMode == I2S_TX_MODE)
- {
- channel = i2s_GetChannel(I2Sx,I2S_TX_MODE);
- wordwidth = i2s_GetWordWidth(I2Sx,I2S_TX_MODE);
- }
- else
- {
- channel = i2s_GetChannel(I2Sx,I2S_RX_MODE);
- wordwidth = i2s_GetWordWidth(I2Sx,I2S_RX_MODE);
- }
-
- /* Calculate X and Y divider
- * The MCLK rate for the I2S transmitter is determined by the value
- * in the I2STXRATE/I2SRXRATE register. The required I2STXRATE/I2SRXRATE
- * setting depends on the desired audio sample rate desired, the format
- * (stereo/mono) used, and the data size.
- * The formula is:
- * I2S_MCLK = CCLK * (X/Y) / 2
- * We have:
- * I2S_MCLK = Freq * channel*wordwidth * (I2Sx->TXBITRATE+1);
- * So: (X/Y) = (Freq * channel*wordwidth * (I2Sx->TXBITRATE+1))/CCLK*2
- * We use a loop function to chose the most suitable X,Y value
- */
-
- /* divider is a fixed point number with 16 fractional bits */
- divider = (((uint64_t)Freq *channel*wordwidth * 2)<<16) / cclk;
-
- /* find N that make x/y <= 1 -> divider <= 2^16 */
- for(N=64;N>0;N--){
- if((divider*N) < (1<<16)) break;
- }
-
- if(N == 0) return ERROR;
-
- divider *= N;
-
- for (y = 255; y > 0; y--) {
- x = y * divider;
- if(x & (0xFF000000)) continue;
- dif = x & 0xFFFF;
- if(dif>0x8000) err = 0x10000-dif;
- else err = dif;
- if (err == 0)
- {
- y_divide = y;
- break;
- }
- else if (err < ErrorOptimal)
- {
- ErrorOptimal = err;
- y_divide = y;
- }
- }
- x_divide = ((uint64_t)y_divide * Freq *(channel*wordwidth)* N * 2)/cclk;
- if(x_divide >= 256) x_divide = 0xFF;
- if(x_divide == 0) x_divide = 1;
-
- if (TRMode == I2S_TX_MODE)// Transmitter
- {
- I2Sx->TXBITRATE = N-1;
- I2Sx->TXRATE = y_divide | (x_divide << 8);
- } else //Receiver
- {
- I2Sx->RXBITRATE = N-1;
- I2Sx->TXRATE = y_divide | (x_divide << 8);
- }
- return SUCCESS;
-}
-
-/********************************************************************//**
- * @brief I2S set bitrate
- * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S
- * @param[in] bitrate value will be set
- * bitrate value should be in range: 0 .. 63
- * @param[in] TRMode is transmit/receive mode, should be:
- * - I2S_TX_MODE = 0: transmit mode
- * - I2S_RX_MODE = 1: receive mode
- * @return none
- *********************************************************************/
-void I2S_SetBitRate(LPC_I2S_TypeDef *I2Sx, uint8_t bitrate, uint8_t TRMode)
-{
- if(TRMode == I2S_TX_MODE)
- {
- I2Sx->TXBITRATE = bitrate;
- }
- else
- {
- I2Sx->RXBITRATE = bitrate;
- }
-}
-
-/********************************************************************//**
- * @brief Configuration operating mode for I2S
- * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S
- * @param[in] ModeConfig pointer to I2S_MODEConf_Type will be used to
- * configure
- * @param[in] TRMode is transmit/receive mode, should be:
- * - I2S_TX_MODE = 0: transmit mode
- * - I2S_RX_MODE = 1: receive mode
- * @return none
- *********************************************************************/
-void I2S_ModeConfig(LPC_I2S_TypeDef *I2Sx, I2S_MODEConf_Type* ModeConfig,
- uint8_t TRMode)
-{
- if (TRMode == I2S_TX_MODE) {
- I2Sx->TXMODE &= ~0x0F; //clear bit 3:0 in I2STXMODE register
- if (ModeConfig->clksel == I2S_CLKSEL_MCLK) {
- I2Sx->TXMODE |= 0x02;
- }
- if (ModeConfig->fpin == I2S_4PIN_ENABLE) {
- I2Sx->TXMODE |= (1 << 2);
- }
- if (ModeConfig->mcena == I2S_MCLK_ENABLE) {
- I2Sx->TXMODE |= (1 << 3);
- }
- } else {
- I2Sx->RXMODE &= ~0x0F; //clear bit 3:0 in I2STXMODE register
- if (ModeConfig->clksel == I2S_CLKSEL_MCLK) {
- I2Sx->RXMODE |= 0x02;
- }
- if (ModeConfig->fpin == I2S_4PIN_ENABLE) {
- I2Sx->RXMODE |= (1 << 2);
- }
- if (ModeConfig->mcena == I2S_MCLK_ENABLE) {
- I2Sx->RXMODE |= (1 << 3);
- }
- }
-}
-
-/********************************************************************//**
- * @brief Configure DMA operation for I2S
- * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S
- * @param[in] DMAConfig pointer to I2S_DMAConf_Type will be used to configure
- * @param[in] TRMode is transmit/receive mode, should be:
- * - I2S_TX_MODE = 0: transmit mode
- * - I2S_RX_MODE = 1: receive mode
- * @return none
- *********************************************************************/
-void I2S_DMAConfig(LPC_I2S_TypeDef *I2Sx, I2S_DMAConf_Type* DMAConfig,
- uint8_t TRMode)
-{
- if (TRMode == I2S_RX_MODE) {
- if (DMAConfig->DMAIndex == I2S_DMA_1) {
- LPC_I2S->DMA1 = (DMAConfig->depth) << 8;
- } else {
- LPC_I2S->DMA2 = (DMAConfig->depth) << 8;
- }
- } else {
- if (DMAConfig->DMAIndex == I2S_DMA_1) {
- LPC_I2S->DMA1 = (DMAConfig->depth) << 16;
- } else {
- LPC_I2S->DMA2 = (DMAConfig->depth) << 16;
- }
- }
-}
-
-/********************************************************************//**
- * @brief Enable/Disable DMA operation for I2S
- * @param[in] I2Sx: I2S peripheral selected, should be: LPC_I2S
- * @param[in] DMAIndex chose what DMA is used, should be:
- * - I2S_DMA_1 = 0: DMA1
- * - I2S_DMA_2 = 1: DMA2
- * @param[in] TRMode is transmit/receive mode, should be:
- * - I2S_TX_MODE = 0: transmit mode
- * - I2S_RX_MODE = 1: receive mode
- * @param[in] NewState is new state of DMA operation, should be:
- * - ENABLE
- * - DISABLE
- * @return none
- *********************************************************************/
-void I2S_DMACmd(LPC_I2S_TypeDef *I2Sx, uint8_t DMAIndex, uint8_t TRMode,
- FunctionalState NewState)
-{
- if (TRMode == I2S_RX_MODE) {
- if (DMAIndex == I2S_DMA_1) {
- if (NewState == ENABLE)
- I2Sx->DMA1 |= 0x01;
- else
- I2Sx->DMA1 &= ~0x01;
- } else {
- if (NewState == ENABLE)
- I2Sx->DMA2 |= 0x01;
- else
- I2Sx->DMA2 &= ~0x01;
- }
- } else {
- if (DMAIndex == I2S_DMA_1) {
- if (NewState == ENABLE)
- I2Sx->DMA1 |= 0x02;
- else
- I2Sx->DMA1 &= ~0x02;
- } else {
- if (NewState == ENABLE)
- I2Sx->DMA2 |= 0x02;
- else
- I2Sx->DMA2 &= ~0x02;
- }
- }
-}
-
-/********************************************************************//**
- * @brief Configure IRQ for I2S
- * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S
- * @param[in] TRMode is transmit/receive mode, should be:
- * - I2S_TX_MODE = 0: transmit mode
- * - I2S_RX_MODE = 1: receive mode
- * @param[in] level is the FIFO level that triggers IRQ request
- * @return none
- *********************************************************************/
-void I2S_IRQConfig(LPC_I2S_TypeDef *I2Sx, uint8_t TRMode, uint8_t level) {
- if (TRMode == I2S_RX_MODE) {
- I2Sx->IRQ |= (level << 8);
- } else {
- I2Sx->IRQ |= (level << 16);
- }
-}
-
-/********************************************************************//**
- * @brief Enable/Disable IRQ for I2S
- * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S
- * @param[in] TRMode is transmit/receive mode, should be:
- * - I2S_TX_MODE = 0: transmit mode
- * - I2S_RX_MODE = 1: receive mode
- * @param[in] NewState is new state of DMA operation, should be:
- * - ENABLE
- * - DISABLE
- * @return none
- *********************************************************************/
-void I2S_IRQCmd(LPC_I2S_TypeDef *I2Sx, uint8_t TRMode, FunctionalState NewState) {
-
- if (TRMode == I2S_RX_MODE) {
- if (NewState == ENABLE)
- I2Sx->IRQ |= 0x01;
- else
- I2Sx->IRQ &= ~0x01;
- //Enable DMA
-
- } else {
- if (NewState == ENABLE)
- I2Sx->IRQ |= 0x02;
- else
- I2Sx->IRQ &= ~0x02;
- }
-}
-
-/********************************************************************//**
- * @brief Get I2S interrupt status
- * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S
- * @param[in] TRMode is transmit/receive mode, should be:
- * - I2S_TX_MODE = 0: transmit mode
- * - I2S_RX_MODE = 1: receive mode
- * @return FunctionState should be:
- * - ENABLE: interrupt is enable
- * - DISABLE: interrupt is disable
- *********************************************************************/
-FunctionalState I2S_GetIRQStatus(LPC_I2S_TypeDef *I2Sx,uint8_t TRMode)
-{
-
- if(TRMode == I2S_TX_MODE)
- return I2S_IS_ENABLED((I2Sx->IRQ >> 1)&0x01);
- else
- return I2S_IS_ENABLED((I2Sx->IRQ)&0x01);
-}
-
-/********************************************************************//**
- * @brief Get I2S interrupt depth
- * @param[in] I2Sx I2S peripheral selected, should be: LPC_I2S
- * @param[in] TRMode is transmit/receive mode, should be:
- * - I2S_TX_MODE = 0: transmit mode
- * - I2S_RX_MODE = 1: receive mode
- * @return depth of FIFO level on which to create an irq request
- *********************************************************************/
-uint8_t I2S_GetIRQDepth(LPC_I2S_TypeDef *I2Sx,uint8_t TRMode)
-{
-
- if(TRMode == I2S_TX_MODE)
- return (((I2Sx->IRQ)>>16)&0xFF);
- else
- return (((I2Sx->IRQ)>>8)&0xFF);
-}
-/**
- * @}
- */
-
-#endif /*_I2S*/
-
-/**
- * @}
- */
-
-/* --------------------------------- End Of File ------------------------------ */
-
diff --git a/bsp/lpc408x/Libraries/Drivers/source/lpc_iap.c b/bsp/lpc408x/Libraries/Drivers/source/lpc_iap.c
deleted file mode 100644
index ceccf36570..0000000000
--- a/bsp/lpc408x/Libraries/Drivers/source/lpc_iap.c
+++ /dev/null
@@ -1,317 +0,0 @@
-/**********************************************************************
-* $Id$ lpc_iap.c 2011-11-21
-*//**
-* @file lpc_iap.c
- * @brief Contains all functions support for IAP on LPC
-* @version 1.0
-* @date 21. November. 2011
-* @author NXP MCU SW Application Team
-*
-* Copyright(C) 2011, NXP Semiconductor
-* All rights reserved.
-*
-***********************************************************************
-* Software that is described herein is for illustrative purposes only
-* which provides customers with programming information regarding the
-* products. This software is supplied "AS IS" without any warranties.
-* NXP Semiconductors assumes no responsibility or liability for the
-* use of the software, conveys no license or title under any patent,
-* copyright, or mask work right to the product. NXP Semiconductors
-* reserves the right to make changes in the software without
-* notification. NXP Semiconductors also make 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'
-* relevant copyright 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.
-**********************************************************************/
-#ifdef __BUILD_WITH_EXAMPLE__
-#include "lpc_libcfg.h"
-#else
-#include "lpc_libcfg_default.h"
-#endif /* __BUILD_WITH_EXAMPLE__ */
-#ifdef _IAP
-#include "lpc_iap.h"
-#include "lpc_clkpwr.h"
-
-// IAP Command
-typedef void (*IAP)(uint32_t *cmd,uint32_t *result);
-IAP iap_entry = (IAP) IAP_LOCATION;
-#define IAP_Call iap_entry
-
-/** @addtogroup IAP_Public_Functions LCD Public Function
- * @ingroup IAP
- * @{
- */
-
-
-/*********************************************************************//**
- * @brief Get Sector Number
- *
- * @param[in] adr Sector Address
- *
- * @return Sector Number.
- *
- **********************************************************************/
- uint32_t GetSecNum (uint32_t adr)
-{
- uint32_t n;
-
- n = adr >> 12; // 4kB Sector
- if (n >= 0x10) {
- n = 0x0E + (n >> 3); // 32kB Sector
- }
-
- return (n); // Sector Number
-}
-
-/*********************************************************************//**
- * @brief Prepare sector(s) for write operation
- *
- * @param[in] start_sec The number of start sector
- * @param[in] end_sec The number of end sector
- *
- * @return CMD_SUCCESS/BUSY/INVALID_SECTOR.
- *
- **********************************************************************/
-IAP_STATUS_CODE PrepareSector(uint32_t start_sec, uint32_t end_sec)
-{
- IAP_COMMAND_Type command;
- command.cmd = IAP_PREPARE; // Prepare Sector for Write
- command.param[0] = start_sec; // Start Sector
- command.param[1] = end_sec; // End Sector
- IAP_Call (&command.cmd, &command.status); // Call IAP Command
- return (IAP_STATUS_CODE)command.status;
-}
-
-/*********************************************************************//**
- * @brief Copy RAM to Flash
- *
- * @param[in] dest destination buffer (in Flash memory).
- * @param[in] source source buffer (in RAM).
- * @param[in] size the write size.
- *
- * @return CMD_SUCCESS.
- * SRC_ADDR_ERROR/DST_ADDR_ERROR
- * SRC_ADDR_NOT_MAPPED/DST_ADDR_NOT_MAPPED
- * COUNT_ERROR/SECTOR_NOT_PREPARED_FOR_WRITE_OPERATION
- * BUSY
- *
- **********************************************************************/
-IAP_STATUS_CODE CopyRAM2Flash(uint8_t * dest, uint8_t* source, IAP_WRITE_SIZE size)
-{
- uint32_t sec;
- IAP_STATUS_CODE status;
- IAP_COMMAND_Type command;
-
- // Prepare sectors
- sec = GetSecNum((uint32_t)dest);
- status = PrepareSector(sec, sec);
- if(status != CMD_SUCCESS)
- return status;
-
- // write
- command.cmd = IAP_COPY_RAM2FLASH; // Copy RAM to Flash
- command.param[0] = (uint32_t)dest; // Destination Flash Address
- command.param[1] = (uint32_t)source; // Source RAM Address
- command.param[2] = size; // Number of bytes
- command.param[3] = CLKPWR_GetCLK(CLKPWR_CLKTYPE_CPU) / 1000; // CCLK in kHz
- IAP_Call (&command.cmd, &command.status); // Call IAP Command
-
- return (IAP_STATUS_CODE)command.status; // Finished without Errors
-}
-
-/*********************************************************************//**
- * @brief Erase sector(s)
- *
- * @param[in] start_sec The number of start sector
- * @param[in] end_sec The number of end sector
- *
- * @return CMD_SUCCESS.
- * INVALID_SECTOR
- * SECTOR_NOT_PREPARED_FOR_WRITE_OPERATION
- * BUSY
- *
- **********************************************************************/
-IAP_STATUS_CODE EraseSector(uint32_t start_sec, uint32_t end_sec)
-{
- IAP_COMMAND_Type command;
- IAP_STATUS_CODE status;
-
- // Prepare sectors
- status = PrepareSector(start_sec, end_sec);
- if(status != CMD_SUCCESS)
- return status;
-
- // Erase sectors
- command.cmd = IAP_ERASE; // Prepare Sector for Write
- command.param[0] = start_sec; // Start Sector
- command.param[1] = end_sec; // End Sector
- command.param[2] = CLKPWR_GetCLK(CLKPWR_CLKTYPE_CPU) / 1000; // CCLK in kHz
- IAP_Call (&command.cmd, &command.status); // Call IAP Command
- return (IAP_STATUS_CODE)command.status;
-}
-
-/*********************************************************************//**
- * @brief Blank check sector(s)
- *
- * @param[in] start_sec The number of start sector
- * @param[in] end_sec The number of end sector
- * @param[out] first_nblank_loc The offset of the first non-blank word
- * @param[out] first_nblank_val The value of the first non-blank word
- *
- * @return CMD_SUCCESS.
- * INVALID_SECTOR
- * SECTOR_NOT_BLANK
- * BUSY
- *
- **********************************************************************/
-IAP_STATUS_CODE BlankCheckSector(uint32_t start_sec, uint32_t end_sec,
- uint32_t *first_nblank_loc,
- uint32_t *first_nblank_val)
-{
- IAP_COMMAND_Type command;
-
- command.cmd = IAP_BLANK_CHECK; // Prepare Sector for Write
- command.param[0] = start_sec; // Start Sector
- command.param[1] = end_sec; // End Sector
- IAP_Call (&command.cmd, &command.status); // Call IAP Command
-
- if(command.status == SECTOR_NOT_BLANK)
- {
- // Update out value
- if(first_nblank_loc != NULL)
- *first_nblank_loc = command.result[0];
- if(first_nblank_val != NULL)
- *first_nblank_val = command.result[1];
- }
-
- return (IAP_STATUS_CODE)command.status;
-}
-
-/*********************************************************************//**
- * @brief Read part identification number
- *
- * @param[out] partID Part ID
- *
- * @return CMD_SUCCESS
- *
- **********************************************************************/
-IAP_STATUS_CODE ReadPartID(uint32_t *partID)
-{
- IAP_COMMAND_Type command;
- command.cmd = IAP_READ_PART_ID;
- IAP_Call (&command.cmd, &command.status); // Call IAP Command
-
- if(command.status == CMD_SUCCESS)
- {
- if(partID != NULL)
- *partID = command.result[0];
- }
-
- return (IAP_STATUS_CODE)command.status;
-}
-
-/*********************************************************************//**
- * @brief Read boot code version. The version is interpreted as <major>.<minor>.
- *
- * @param[out] major The major
- * @param[out] minor The minor
- *
- * @return CMD_SUCCESS
- *
- **********************************************************************/
-IAP_STATUS_CODE ReadBootCodeVer(uint8_t *major, uint8_t* minor)
-{
- IAP_COMMAND_Type command;
- command.cmd = IAP_READ_BOOT_VER;
- IAP_Call (&command.cmd, &command.status); // Call IAP Command
-
- if(command.status == CMD_SUCCESS)
- {
- if(major != NULL)
- *major = (command.result[0] >> 8) & 0xFF;
- if(minor != NULL)
- *minor = (command.result[0]) & 0xFF;
- }
-
- return (IAP_STATUS_CODE)command.status;
-}
-
-/*********************************************************************//**
- * @brief Read Device serial number.
- *
- * @param[out] uid Serial number.
- *
- * @return CMD_SUCCESS
- *
- **********************************************************************/
-IAP_STATUS_CODE ReadDeviceSerialNum(uint32_t *uid)
-{
- IAP_COMMAND_Type command;
- command.cmd = IAP_READ_SERIAL_NUMBER;
- IAP_Call (&command.cmd, &command.status); // Call IAP Command
-
- if(command.status == CMD_SUCCESS)
- {
- if(uid != NULL)
- {
- uint32_t i = 0;
- for(i = 0; i < 4; i++)
- uid[i] = command.result[i];
- }
- }
-
- return (IAP_STATUS_CODE)command.status;
-}
-
-/*********************************************************************//**
- * @brief compare the memory contents at two locations.
- *
- * @param[in] addr1 The address of the 1st buffer (in RAM/Flash).
- * @param[in] addr2 The address of the 2nd buffer (in RAM/Flash).
- * @param[in] size Number of bytes to be compared; should be a multiple of 4.
- *
- * @return CMD_SUCCESS
- * COMPARE_ERROR
- * COUNT_ERROR (Byte count is not a multiple of 4)
- * ADDR_ERROR
- * ADDR_NOT_MAPPED
- *
- **********************************************************************/
-IAP_STATUS_CODE Compare(uint8_t *addr1, uint8_t *addr2, uint32_t size)
-{
- IAP_COMMAND_Type command;
- command.cmd = IAP_COMPARE;
- command.param[0] = (uint32_t)addr1;
- command.param[1] = (uint32_t)addr2;
- command.param[2] = size;
- IAP_Call (&command.cmd, &command.status); // Call IAP Command
-
- return (IAP_STATUS_CODE)command.status;
-}
-
-/*********************************************************************//**
- * @brief Re-invoke ISP.
- *
- * @param[in] None.
- *
- * @return None.
- *
- **********************************************************************/
-void InvokeISP(void)
-{
- IAP_COMMAND_Type command;
- command.cmd = IAP_REINVOKE_ISP;
- IAP_Call (&command.cmd, &command.status); // Call IAP Command
-}
-
-/**
- * @}
- */
-
-
-#endif /*_IAP*/
diff --git a/bsp/lpc408x/Libraries/Drivers/source/lpc_lcd.c b/bsp/lpc408x/Libraries/Drivers/source/lpc_lcd.c
deleted file mode 100644
index ea2f6b5cdb..0000000000
--- a/bsp/lpc408x/Libraries/Drivers/source/lpc_lcd.c
+++ /dev/null
@@ -1,856 +0,0 @@
-/**********************************************************************
-* $Id$ lpc_lcd.c 2011-10-14
-*//**
-* @file lpc_lcd.c
-* @brief Contains all functions support for LCD firmware library
-* on LPC
-* @version 1.0
-* @date 14. October. 2011
-* @author NXP MCU SW Application Team
-*
-* Copyright(C) 2011, NXP Semiconductor
-* All rights reserved.
-*
-***********************************************************************
-* Software that is described herein is for illustrative purposes only
-* which provides customers with programming information regarding the
-* products. This software is supplied "AS IS" without any warranties.
-* NXP Semiconductors assumes no responsibility or liability for the
-* use of the software, conveys no license or title under any patent,
-* copyright, or mask work right to the product. NXP Semiconductors
-* reserves the right to make changes in the software without
-* notification. NXP Semiconductors also make 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'
-* relevant copyright 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.
-**********************************************************************/
-#ifdef __BUILD_WITH_EXAMPLE__
-#include "lpc_libcfg.h"
-#else
-#include "lpc_libcfg_default.h"
-#endif /* __BUILD_WITH_EXAMPLE__ */
-#ifdef _LCD
-
-#include "lpc_clkpwr.h"
-#include "lpc_pinsel.h"
-#include "lpc_gpio.h"
-#include "lpc_lcd.h"
-
-uint32_t lcd_hsize = 0, lcd_vsize = 0;
-uint32_t lcd_cursor_base_addr = 0;
-uint32_t lcd_cursor_size = 64;
-LCD_Config_Type lcd_config;
-static uint8_t bits_per_pixel[] = { 1, 2, 4, 8, 16, 32, 16, 16 };
-uint32_t rect[1024];
-
-
-static void LCD_SetHorizontalTiming(LCD_HConfig_Type* pConfig);
-static void LCD_SetVertialTiming(LCD_VConfig_Type* pConfig);
-static void LCD_SetPolarity(LCD_TYPES lcd_type, LCD_POLARITY_Type* pConfig);
-static void LCD_CtrlSetup(LCD_Config_Type* pConfig);
-
-/** @addtogroup LCD_Private_Functions LCD Private Function
- * @ingroup LCD
- * @{
- */
-
-
-/*********************************************************************//**
- * @brief Init LCD. The input clock is CClk
- *
- * @param[in] pConfig Configuration Information
- *
- * @return LCD_FUNC_OK Execute successfully
- * LCD_FUNC_ERR Error occurred.
- *
- **********************************************************************/
-LCD_RET_CODE LCD_Init (LCD_Config_Type* pConfig)
-{
- uint8_t clkdiv;
-
- if(pConfig == NULL)
- return LCD_FUNC_ERR;
-
- if(pConfig->big_endian_byte & !pConfig->big_endian_pixel)
- return LCD_FUNC_ERR;
-
- lcd_config = *pConfig;
-
- // Assign pins
- PINSEL_ConfigPin(0,4,7);
- PINSEL_ConfigPin(0,5,7);
- PINSEL_ConfigPin(0,6,7);
- PINSEL_ConfigPin(0,7,7);
- PINSEL_ConfigPin(0,8,7);
- PINSEL_ConfigPin(0,9,7);
- PINSEL_ConfigPin(1,20,7);
- PINSEL_ConfigPin(1,21,7);
- PINSEL_ConfigPin(1,22,7);
- PINSEL_ConfigPin(1,23,7);
- PINSEL_ConfigPin(1,24,7);
- PINSEL_ConfigPin(1,25,7);
- PINSEL_ConfigPin(1,26,7);
- PINSEL_ConfigPin(1,27,7);
- PINSEL_ConfigPin(1,28,7);
- PINSEL_ConfigPin(1,29,7);
- PINSEL_ConfigPin(2,0,7);
- PINSEL_ConfigPin(2,1,7);
- PINSEL_ConfigPin(2,2,7);
- PINSEL_ConfigPin(2,3,7);
- PINSEL_ConfigPin(2,4,7);
- PINSEL_ConfigPin(2,5,7);
- PINSEL_ConfigPin(2,6,7);
-#ifdef CORE_M4
- PINSEL_ConfigPin(0,10,7);
-#else
- PINSEL_ConfigPin(2,7,7);
-#endif
- PINSEL_ConfigPin(2,8,7);
- PINSEL_ConfigPin(2,9,7);
- PINSEL_ConfigPin(2,11,7);
- PINSEL_ConfigPin(2,12,7);
- PINSEL_ConfigPin(2,13,7);
- PINSEL_ConfigPin(4,28,7);
- PINSEL_ConfigPin(4,29,7);
-
- //Turn on LCD clock
- CLKPWR_ConfigPPWR(CLKPWR_PCONP_PCLCD, ENABLE);
-
- // Set clock
- LPC_LCD->POL &= ~(0x01 << 5);
- if( pConfig->panel_clk > 0) {
- clkdiv = CLKPWR_GetCLK(CLKPWR_CLKTYPE_CPU) / pConfig->panel_clk - 1;
- LPC_SC->LCD_CFG = clkdiv & 0x1F;
- LPC_LCD->POL |=(1<<26);
- }
-
- // init Horizontal Timing
- LCD_SetHorizontalTiming(&pConfig->hConfig);
-
- // Init Vertical Timing
- LCD_SetVertialTiming(&pConfig->vConfig);
-
- // Set Polarity
- LCD_SetPolarity(pConfig->lcd_type, &pConfig->polarity);
-
- if(NULL != pConfig->lcd_palette)
- {
- LCD_SetPalette(pConfig->lcd_palette);
- }
-
- // Set Base address
- LCD_SetBaseAddress(LCD_PANEL_UPPER, pConfig->lcd_panel_upper);
- LCD_SetBaseAddress(LCD_PANEL_LOWER, pConfig->lcd_panel_lower);
-
- // Setup
- LCD_CtrlSetup(pConfig);
-
- return LCD_FUNC_OK;
-
-
-}
-/*********************************************************************//**
- * @brief Horizontal Timing Setting
- *
- * @param[in] pConfig Configuration Information
- *
- * @return None.
- *
- **********************************************************************/
-void LCD_SetHorizontalTiming(LCD_HConfig_Type* pConfig)
-{
- LPC_LCD->TIMH = 0; //reset TIMH before set value
- LPC_LCD->TIMH |= ((pConfig->hbp - 1)& 0xFF)<<24;
- LPC_LCD->TIMH |= ((pConfig->hfp - 1)& 0xFF)<<16;
- LPC_LCD->TIMH |= ((pConfig->hsw - 1)& 0xFF)<<8;
- LPC_LCD->TIMH |= ((pConfig->ppl/16 - 1)& 0x3F)<<2;
- lcd_hsize = pConfig->ppl;
-}
-
-/*********************************************************************//**
- * @brief Vertical Timing Setting
- *
- * @param[in] pConfig Configuration Information
- *
- * @return None.
- *
- **********************************************************************/
-void LCD_SetVertialTiming(LCD_VConfig_Type* pConfig)
-{
- LPC_LCD->TIMV = 0; //reset TIMV value before setting
- LPC_LCD->TIMV |= ((pConfig->vbp)& 0xFF)<<24;
- LPC_LCD->TIMV |= ((pConfig->vfp)& 0xFF)<<16;
- LPC_LCD->TIMV |= ((pConfig->vsw - 1)& 0x3F)<<10;
- LPC_LCD->TIMV |= ((pConfig->lpp - 1)& 0x03FF)<<0;
- lcd_vsize = pConfig->lpp;
-}
-
-/*********************************************************************//**
- * @brief Polarity Setting
- *
- * @param[in] pConfig Configuration Information
- * @param[in] lcd_type It can be:
- * - LCD_STN_MONOCHROME
- * - LCD_STN_COLOR
- * - LCD_TFT
- *
- * @return None.
- *
- **********************************************************************/
-void LCD_SetPolarity(LCD_TYPES lcd_type, LCD_POLARITY_Type* pConfig)
-{
- // LCDFP pin is active LOW and inactive HIGH
- if(pConfig->invert_vsync)
- LPC_LCD->POL |= (1<<11);
- else
- LPC_LCD->POL &= ~(1<<11);
- // LCDLP pin is active LOW and inactive HIGH
- if(pConfig->invert_hsync)
- LPC_LCD->POL |= (1<<12);
- else
- LPC_LCD->POL &= ~(1<<12);
- // data is driven out into the LCD on the falling edge
- if(pConfig->invert_panel_clock)
- LPC_LCD->POL |= (1<<13);
- else
- LPC_LCD->POL &= ~(1<<13);
-
- // active high
- if(pConfig->active_high) {
- LPC_LCD->POL &= ~(1<<14);
- }
- else
- {
- LPC_LCD->POL |= (1<<14);
- }
-
- LPC_LCD->POL &= ~(0x3FF <<16);
- LPC_LCD->POL |= (pConfig->cpl - 1)<<16;
-
- if(lcd_type == LCD_STN_COLOR || lcd_type == LCD_STN_MONOCHROME)
- LPC_LCD->POL |= (pConfig->acb & 0x1F) << 6;
- }
-
-/*********************************************************************//**
- * @brief Set base address of frame buffer
- *
- * @param[in] panel identify which panel is.
- * @param[in] pAddress base address of the inputted panel.
- *
- * @return None.
- *
- **********************************************************************/
-void LCD_SetBaseAddress(LCD_PANEL panel, uint32_t pAddress)
-{
- // Frame Base Address doubleword aligned
- if(panel == LCD_PANEL_UPPER)
- LPC_LCD->UPBASE = pAddress & ~7UL ;
- else
- LPC_LCD->LPBASE = pAddress & ~7UL ;
-}
-
-/*********************************************************************//**
- * @brief LCD Setup.
- *
- * @param[in] pConfig Configuration information.
- *
- * @return None.
- *
- **********************************************************************/
-void LCD_CtrlSetup(LCD_Config_Type* pConfig)
-{
- // disable LCD controller
- LPC_LCD->CTRL = 0;
-
- // bpp
- LPC_LCD->CTRL &= ~(0x07 <<1);
- LPC_LCD->CTRL |=((pConfig->lcd_bpp & 0x07)<<1);
-
- if(pConfig->lcd_type == LCD_TFT) {
- LPC_LCD->CTRL |= (0x01 << 5); // TFT
- }
- else {
- // Color/Mono
- if(pConfig->lcd_type == LCD_STN_COLOR) {
- LPC_LCD->CTRL &= ~ (0x01 << 4); // Color
- }
- else if (pConfig->lcd_type == LCD_STN_MONOCHROME) {
- LPC_LCD->CTRL |= (0x01 << 4); // Mono
- }
-
- // STN/TFT
- LPC_LCD->CTRL &= ~ (0x01 << 5); // STN
-
- // Mono4/8
- if(pConfig->lcd_mono8)
- LPC_LCD->CTRL |= (0x01 << 6);
- else
- LPC_LCD->CTRL &= ~(0x01 << 6);
-
- // Single/dual
- if(pConfig->lcd_dual)
- LPC_LCD->CTRL |= (0x01 << 7);
- else
- LPC_LCD->CTRL &= ~(0x01 << 7);
- }
-
- // notmal output
- if(pConfig->lcd_bgr)
- LPC_LCD->CTRL |= (1<<8); // BGR
- else
- LPC_LCD->CTRL &= ~(1<<8); // RGB
-
- // Byte order
- if(pConfig->big_endian_byte)
- LPC_LCD->CTRL |= (1<<9);
- else
- LPC_LCD->CTRL &= ~(1<<9);
-
- // Pixel order
- if(pConfig->big_endian_pixel)
- LPC_LCD->CTRL |= (1<<10);
- else
- LPC_LCD->CTRL &= ~(1<<10);
-
- // disable power
- LPC_LCD->CTRL &= ~(1<<11);
-}
-
-/*********************************************************************//**
- * @brief Enable/disable LCD Display.
- *
- * @param[in] bEna 0: disable, 1: enable.
- *
- * @return None.
- *
- **********************************************************************/
-void LCD_Enable (Bool bEna)
-{
- volatile uint32_t i;
- if (bEna)
- {
- LPC_LCD->CTRL |= (1<<0);
- for(i = LCD_PWR_ENA_DIS_DLY; i; i--);
- LPC_LCD->CTRL |= (1<<11);
- }
- else
- {
- LPC_LCD->CTRL &= ~(1<<11);
- for(i = LCD_PWR_ENA_DIS_DLY; i; i--);
- LPC_LCD->CTRL &= ~(1<<0);
- }
-}
-
-
-/*********************************************************************//**
- * @brief Set palette.
- *
- * @param[in] bEna 0: disable, 1: enable.
- *
- * @return None.
- *
- **********************************************************************/
-void LCD_SetPalette (const uint8_t* pPallete)
-{
- uint32_t i;
- uint32_t size = (0x01 << bits_per_pixel[lcd_config.lcd_bpp])/2 ;
- uint32_t * pDst = (uint32_t *)LPC_LCD->PAL;
- uint32_t * pInput = (uint32_t*) pPallete;
-
- for (i = 0; i < size; i++)
- {
- *pDst = *pInput;
- pDst++;
- pInput++;
- }
-}
-/*********************************************************************//**
- * @brief Get word offset for the given pixel
- *
- * @param[in] x x position of input pixel
- * @param[in] y y position of input pixel
- *
- * @return Offset
- *
- **********************************************************************/
-uint32_t LCD_GetWordOffset(uint32_t x, uint32_t y)
-{
- uint32_t pixel_num = x + y*lcd_hsize;
-
- return (pixel_num * bits_per_pixel[lcd_config.lcd_bpp])/32;
-}
-/*********************************************************************//**
- * @brief Get bit offset for the given pixel
- *
- * @param[in] x x position of input pixel
- * @param[in] y y position of input pixel
- *
- * @return Offset
- *
- **********************************************************************/
-uint32_t LCD_GetBitOffset(uint32_t x, uint32_t y)
-{
- uint32_t pixel_num;
- uint32_t ofs;
- pixel_num = x + y*lcd_hsize;
-
- ofs = (pixel_num * bits_per_pixel[lcd_config.lcd_bpp])%32;
-
- if(lcd_config.big_endian_pixel & lcd_config.big_endian_byte)
- {
- ofs = 32 - bits_per_pixel[lcd_config.lcd_bpp] - ofs;
- }
- else if (lcd_config.big_endian_pixel & !lcd_config.big_endian_byte)
- {
- if(bits_per_pixel[lcd_config.lcd_bpp] < 8)
- {
- ofs = (ofs/8)*8 + (8 - (ofs%8)-bits_per_pixel[lcd_config.lcd_bpp]);
- }
- }
- return ofs;
-}
-
-
-
-/*********************************************************************//**
- * @brief Copy pixel values from image buffer to frame buffer.
- *
- * @param[in] panel It can be:
- * - LCD_PANEL_UPPER
- * - LCD_PANEL_LOWER
- * @param[in] pPain point to image buffer.
- *
- * @return None.
- *
- **********************************************************************/
-void LCD_SetImage(LCD_PANEL panel, const uint8_t *pPain)
-{
- volatile uint32_t i;
- uint32_t * pWordDst = NULL;
- uint8_t* pByteDst = NULL;
- uint32_t bytes_num;
-
- if(panel == LCD_PANEL_UPPER)
- pWordDst = (uint32_t*) LPC_LCD->UPBASE;
- else
- pWordDst = (uint32_t*) LPC_LCD->LPBASE;
-
- pByteDst = (uint8_t*) pWordDst;
- bytes_num = ((lcd_hsize * lcd_vsize) * bits_per_pixel[lcd_config.lcd_bpp]) /8;
-
- if (NULL == pPain)
- {
- // clear display memory
- for( i = 0; bytes_num > i; i++)
- {
- *pByteDst++ = 0;
- }
- }
- else
- {
- // set display memory
- for(i = 0; bytes_num > i; i++)
- {
- *pByteDst++ = *pPain++;
- }
- }
-
- for(i = LCD_PWR_ENA_DIS_DLY; i; i--);
-}
-/*********************************************************************//**
- * @brief Draw a pixel on the given panel.
- *
- * @param[in] panel It can be:
- * - LCD_PANEL_UPPER
- * - LCD_PANEL_LOWER
- * @param[in] X_Left X position.
- * @param[in] Y_Up Y position.
- * @param[in] color Color which is placed to the given pixel.
- *
- * @return None.
- *
- **********************************************************************/
-void LCD_PutPixel (LCD_PANEL panel, uint32_t X_Left, uint32_t Y_Up, LcdPixel_t color)
-{
- uint32_t k;
- uint32_t * pWordData = NULL;
- uint8_t* pByteData = NULL;
- uint32_t bitOffset;
- uint8_t* pByteSrc = (uint8_t*)&color;
- uint8_t bpp = bits_per_pixel[lcd_config.lcd_bpp];
- uint8_t bytes_per_pixel = bpp/8;
- uint32_t start_bit;
-
- if((X_Left >= lcd_hsize)||(Y_Up >= lcd_vsize))
- return;
-
- if(panel == LCD_PANEL_UPPER)
- pWordData = (uint32_t*) LPC_LCD->UPBASE + LCD_GetWordOffset(X_Left,Y_Up);
- else
- pWordData = (uint32_t*) LPC_LCD->LPBASE + LCD_GetWordOffset(X_Left,Y_Up);
-
- bitOffset = LCD_GetBitOffset(X_Left,Y_Up);
- pByteData = (uint8_t*) pWordData;
- pByteData += bitOffset/8;
-
- start_bit = bitOffset%8;
-
- if(bpp < 8)
- {
- uint8_t bit_pos = start_bit;
- uint8_t bit_ofs = 0;
- for(bit_ofs = 0;bit_ofs <bpp; bit_ofs++,bit_pos++)
- {
- *pByteData &= ~ (0x01 << bit_pos);
- *pByteData |= ((*pByteSrc >> (k+bit_ofs)) & 0x01) << bit_pos;
- }
- }
- else
- {
- for(k = 0; k < bytes_per_pixel; k++)
- {
- *(pByteData+ k) = *pByteSrc++;
- }
- }
-}
-/*********************************************************************//**
- * @brief Place given image to given position.
- *
- * @param[in] panel It can be:
- * - LCD_PANEL_UPPER
- * - LCD_PANEL_LOWER
- * @param[in] X_Left Start X position.
- * @param[in] Y_Up Start Y position.
- * @param[in] pBmp Image information.
- * @param[in] Mask Mask on pixel values.
- *
- * @return None.
- *
- **********************************************************************/
-void LCD_LoadPic (LCD_PANEL panel, uint32_t X_Left, uint32_t Y_Up,
- Bmp_t * pBmp, uint32_t Mask)
-{
- uint32_t i, j, k, inc;
- uint32_t * pWordData = NULL;
- uint8_t* pByteData = NULL;
- uint32_t bitOffset;
- uint8_t* pByteSrc = (uint8_t*) pBmp->pPicStream;
- uint32_t X_LeftHold = X_Left;
- uint8_t bpp = bits_per_pixel[lcd_config.lcd_bpp];
- uint8_t bytes_per_pixel = bpp/8;
- uint8_t pixels_per_byte = 8/bpp;
- uint32_t hsize, vsize;
- uint32_t start_bit;
-
- if(pBmp->BytesPP == 0)
- pBmp->BytesPP = bytes_per_pixel;
-
- hsize = pBmp->H_Size;
- vsize = pBmp->V_Size;
- inc = (pixels_per_byte > 0) ? pixels_per_byte:1;
-
- for(i = 0; i < vsize; i++)
- {
- if(panel == LCD_PANEL_UPPER)
- pWordData = (uint32_t*) LPC_LCD->UPBASE + LCD_GetWordOffset(X_Left,Y_Up);
- else
- pWordData = (uint32_t*) LPC_LCD->LPBASE + LCD_GetWordOffset(X_Left,Y_Up);
-
- bitOffset = LCD_GetBitOffset(X_Left,Y_Up);
- pByteData = (uint8_t*) pWordData;
- pByteData += bitOffset/8;
-
- start_bit = bitOffset%8;
-
- if(pBmp->BytesPP > 0)
- pByteSrc = (uint8_t*) pBmp->pPicStream + i*hsize*pBmp->BytesPP; // storage of each line must be word alignment
- else
- pByteSrc = (uint8_t*) pBmp->pPicStream + (i*hsize*pBmp->BitsPP + 7)/8; // storage of each line must be word alignment
-
- X_LeftHold = X_Left;
-
- for(j = 0; j <= hsize; j+= inc)
- {
- if((X_LeftHold >= lcd_hsize) || (X_LeftHold - X_Left >= hsize))
- break;
- if(bpp < 8)
- {
- uint8_t bit_pos = start_bit;
- uint8_t bit_ofs = 0;
- for(k = 0; k < 8; k+= bpp)
- {
- for(bit_ofs = 0;bit_ofs <bpp; bit_ofs++,bit_pos++)
- {
- *pByteData &= ~ (0x01 << bit_pos);
- *pByteData |= ((*pByteSrc >> (k+bit_ofs)) & 0x01) << bit_pos;
- }
- if(lcd_config.big_endian_byte && lcd_config.big_endian_pixel)
- {
- if(bit_pos >= bpp*2)
- bit_pos -= bpp*2;
- else
- {
- bit_pos = 8-bpp;
- if((((uint32_t)pByteData)%4) == 0)
- pByteData += 7; // change to next word
- else
- pByteData--; // change to previous byte
- }
- }
- else if( !lcd_config.big_endian_byte && lcd_config.big_endian_pixel)
- {
- if(bit_pos >= bpp*2)
- bit_pos -= bpp*2;
- else
- {
- bit_pos = 8-bpp;
- pByteData++; // change to next byte
- }
- }
- else
- {
- if(bit_pos >= 8)
- {
- bit_pos = 0;
- pByteData++; // change to next byte
- }
-
- }
- X_LeftHold++;
- if((X_LeftHold >= lcd_hsize) ||
- (X_LeftHold - X_Left >= hsize))
- break;
- }
- pByteSrc++;
- continue;
- }
- else
- {
- for(k = 0; k < pBmp->BytesPP; k++)
- {
- *(pByteData+ k) = *pByteSrc++ ^ Mask;
- }
- if(lcd_config.big_endian_byte)
- {
- if((uint32_t)pByteData %4 > 0)
- pByteData -= bytes_per_pixel;
- else
- pByteData += 8 - bytes_per_pixel;
- }
- else
- pByteData+= bytes_per_pixel;
- X_LeftHold++;
- }
- }
- if(Y_Up++ >= lcd_vsize)
- {
- break;
- }
- }
-}
-
-/*********************************************************************//**
- * @brief Fill a rectangle.
- *
- * @param[in] panel It can be:
- * - LCD_PANEL_UPPER
- * - LCD_PANEL_LOWER
- * @param[in] startx Start X position.
- * @param[in] endy End X position.
- * @param[in] starty Start Y position.
- * @param[in] endy End Y position.
- *
- * @return None.
- *
- **********************************************************************/
-void LCD_FillRect (LCD_PANEL panel, uint32_t startx,uint32_t endx,
- uint32_t starty, uint32_t endy,
- LcdPixel_t color)
-{
- uint32_t x, xs, xe, ys, ye;
- uint8_t bpp, pixels_per_word;
- uint32_t word_val, mask;
- uint32_t max_vsize = 0;
- Bmp_t bitmap;
- uint32_t hsize, vsize;
-
- bpp = bits_per_pixel[lcd_config.lcd_bpp];
- pixels_per_word = 32/bpp;
-
- mask = 0;
- for( x = 0; x < bpp; x++)
- mask |= 0x01 << x;
-
- color &= mask;
-
- word_val = 0;
- for(x = 0; x < pixels_per_word; x++)
- word_val |= color << (x*bpp);
-
- ys = (starty > endy) ? endy : starty;
- ye = (starty > endy) ? starty : endy;
-
- xs = (startx > endx) ? endx : startx;
- xe = (startx > endx) ? startx : endx;
-
- bitmap.BitsPP = bpp;
- bitmap.BytesPP = bpp/8;
- hsize = xe - xs + 1;
- bitmap.H_Size = hsize;
- vsize = ye - ys + 1;
- bitmap.pPicStream = (uint8_t*)rect;
-
- max_vsize = ((1024 * 32)/(hsize*bpp));
-
- for( x = 0; x < 1024; x++)
- {
- rect[x] = word_val;
- }
-
- while(1)
- {
- if(max_vsize >= vsize)
- {
- bitmap.V_Size = vsize;
- LCD_LoadPic(panel,xs,ys, &bitmap, 0);
- break;
- }
- else {
- bitmap.V_Size = max_vsize;
- vsize -= bitmap.V_Size;
- LCD_LoadPic(panel,xs,ys, &bitmap, 0);
- ys += max_vsize;
- }
- }
-
-
-}
-
-/*********************************************************************//**
- * @brief Configure display of cursor.
- *
- * @param[in] pConfig Configuration information.
- *
- * @return None.
- *
- **********************************************************************/
-void LCD_Cursor_Cfg(LCD_Cursor_Config_Type* pConfig)
-{
- if(pConfig->size32) {
- LPC_LCD->CRSR_CFG &= ~(0x01 << 0);
- lcd_cursor_size = 32;
- }
- else {
- LPC_LCD->CRSR_CFG |= (0x01 << 0);
- lcd_cursor_size = 64;
- }
-
- if(pConfig->framesync)
- LPC_LCD->CRSR_CFG &= ~(0x01 << 1);
- else
- LPC_LCD->CRSR_CFG |= (0x01 << 1);
-
- lcd_cursor_base_addr = pConfig->baseaddress;
-
- LPC_LCD->CRSR_PAL0 = pConfig->palette[0].Red |
- pConfig->palette[0].Green << 8 |
- pConfig->palette[0].Blue << 16;
- LPC_LCD->CRSR_PAL1 = pConfig->palette[1].Red |
- pConfig->palette[1].Green << 8 |
- pConfig->palette[1].Blue << 16;
-
-}
-/*********************************************************************//**
- * @brief Enable/disable cursor display.
- *
- * @param[in] enable 0: disable, 1: enable.
- * @param[in] cursor identify which cursor image is used.
- *
- * @return None.
- *
- **********************************************************************/
-void LCD_Cursor_Enable(int enable, int cursor)
-{
- if(enable) {
- LPC_LCD->CRSR_CTRL |= (1<<0);
- LPC_LCD->CRSR_CTRL |= (cursor<<4);
- }
- else {
- LPC_LCD->CRSR_CTRL &= ~(1<<0);
- }
-}
-
-
-/*********************************************************************//**
- * @brief move the cursor to the inputted position.
- *
- * @param[in] x Position in x-direction.
- * @param[in] y Position in y-direction.
- *
- * @return None.
- *
- **********************************************************************/
-void LCD_Move_Cursor(int x, int y)
-{
- LPC_LCD->CRSR_CLIP = 0;
- LPC_LCD->CRSR_XY = 0;
- if(0 <= x)
- {//no clipping
- LPC_LCD->CRSR_XY |= (x & 0x3FF);
- }
- else
- {//clip x
- LPC_LCD->CRSR_CLIP |= -x;
- }
-
- if(0 <= y)
- {//no clipping
-
- LPC_LCD->CRSR_XY |= (y << 16);
- }
- else
- {//clip y
- LPC_LCD->CRSR_CLIP |= (-y << 8);
- }
-}
-
-/*********************************************************************//**
- * @brief Set the cursor image.
- *
- * @param[in] pCursor point to cursor image.
- * @param[in] cursor cursor image number. It has no meaning when cursor size is 64x64
- * @param[in] cursor cursor size in words.
- *
- * @return None.
- *
- **********************************************************************/
-void LCD_Cursor_SetImage (const uint32_t *pCursor, int cursor, int size)
-{
- uint32_t i ;
- uint32_t * pDst = (uint32_t *)lcd_cursor_base_addr;
-
- if(lcd_cursor_size == 32)
- pDst += cursor*GET_CURSOR_IMG_SIZE(lcd_cursor_size);
-
-
- for(i = 0; i < size ; i++)
- {
- *pDst = *pCursor;
- pDst++;
- pCursor++;
- }
-}
-
-/**
- * @}
- */
-
-#endif /*_LCD*/
-
-
-
diff --git a/bsp/lpc408x/Libraries/Drivers/source/lpc_mci.c b/bsp/lpc408x/Libraries/Drivers/source/lpc_mci.c
deleted file mode 100644
index 813d599be2..0000000000
--- a/bsp/lpc408x/Libraries/Drivers/source/lpc_mci.c
+++ /dev/null
@@ -1,2508 +0,0 @@
-/**********************************************************************
-* $Id$ lpc_mci.c 2011-06-02
-*//**
-* @file lpc_mci.c
-* @brief Contains all functions support for MCI firmware library
-* on LPC
-* @version 2.0
-* @date 29. June. 2011
-* @author NXP MCU SW Application Team
-*
-* Copyright(C) 2011, NXP Semiconductor
-* All rights reserved.
-*
-***********************************************************************
-* Software that is described herein is for illustrative purposes only
-* which provides customers with programming information regarding the
-* products. This software is supplied "AS IS" without any warranties.
-* NXP Semiconductors assumes no responsibility or liability for the
-* use of the software, conveys no license or title under any patent,
-* copyright, or mask work right to the product. NXP Semiconductors
-* reserves the right to make changes in the software without
-* notification. NXP Semiconductors also make 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'
-* relevant copyright 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.
-**********************************************************************/
-#ifdef __BUILD_WITH_EXAMPLE__
-#include "lpc_libcfg.h"
-#else
-#include "lpc_libcfg_default.h"
-#endif /* __BUILD_WITH_EXAMPLE__ */
-#ifdef _MCI
-
-#include "LPC407x_8x_177x_8x.h"
-#include "lpc_types.h"
-#include "lpc_mci.h"
-#include "lpc_gpdma.h"
-#include "lpc_clkpwr.h"
-#include "lpc_pinsel.h"
-
-#define DMA_MCI_SIZE BLOCK_LENGTH
-
-#define MCI_DMA_WRITE_CHANNEL (0)
-#define MCI_DMA_READ_CHANNEL (1)
-
-#define _SHIFT(x) (1 << x)
-#define _XSHIFT(x, y) (x << y)
-
-#define SHIFT_(x) (1 >> x)
-#define XSHIFT_(x, y) (x >> y)
-
-#define MCI_ACMD41_HCS_POS (30)
-
-#define MCI_PWRCTRL_BMASK (0xC3)
-
-#define MCI_PWRCTRL_OPENDRAIN_POS (6)
-#define MCI_PWRCTRL_OPENDRAIN_NUMBIT (1)
-#define MCI_PWRCTRL_OPENDRAIN_BMASK (0x01)
-
-
-volatile uint32_t Mci_Data_Xfer_End = 0;
-
-volatile uint32_t Mci_Data_Xfer_ERR = 0;
-
-volatile uint8_t fifo_plane = 0;
-
-volatile uint32_t CardRCA;
-
-volatile uint8_t CCS;
-
-volatile en_Mci_CardType MCI_CardType;
-
-// Terminal Counter flag, Error Counter flag for Channel 0
-uint32_t dmaWrCh_TermianalCnt, dmaWrCh_ErrorCnt;
-uint32_t dmaRdCh_TermianalCnt, dmaRdCh_ErrorCnt;
-
-
-uint32_t MCI_SettingDma(uint8_t* memBuf, uint32_t ChannelNum, uint32_t DMAMode );
-
-int32_t MCI_ReadFifo(uint32_t * dest);
-int32_t MCI_WriteFifo(uint32_t * src);
-
-void MCI_TXEnable( void );
-void MCI_RXEnable( void );
-void MCI_TXDisable( void );
-void MCI_RXDisable( void );
-
-void MCI_CmdProcess( void );
-void MCI_DataErrorProcess( void );
-void MCI_DataErrorProcess( void );
-void MCI_DATA_END_InterruptService( void );
-void MCI_FIFOInterruptService( void );
-
-int32_t MCI_CheckStatus(uint8_t expect_status);
-
-
-
-volatile uint8_t* dataSrcBlock = (uint8_t *) MCI_DMA_SRC_ADDR;
-volatile uint8_t* dataDestBlock = (uint8_t *) MCI_DMA_DST_ADDR;
-
-volatile uint32_t txBlockCnt=0, rxBlockCnt=0;
-
-/** @addtogroup MCI_Private_Functions MCI Private Function
- * @ingroup MCI
- * @{
- */
-
-#if MCI_DMA_ENABLED
-/*********************************************************************//**
- * @brief Do setting GPDMA for MCI working
- *
- * @param[in] DMAMode set for the Type of DMA Transfer. It may be memory
- * to peripheral (M2P) or peripheral to memory (P2M)
- * in MCI working
- *
- * @param[in] ChannelNum which channel is used for current transfer with
- * DMA compent
- *
- * @param[in] memBuf point to a UINT8 buffer. In 2 cases of DMAMode
- * seperated:
- * - M2P: it is the source address that hold the
- * expected buffer to transfer
- * - P2M: it is the destination address that will store
- * data that retrieved from the peripheral (the Card in slot)
- *
- * @return None
- *
- * @note This is only required if DMA support is enabled
- **********************************************************************/
-uint32_t MCI_SettingDma(uint8_t* memBuf, uint32_t ChannelNum, uint32_t DMAMode )
-{
- GPDMA_Channel_CFG_Type GPDMACfg;
-
- // Transfer size
- GPDMACfg.TransferSize = DMA_MCI_SIZE;
- // Transfer width
- GPDMACfg.TransferWidth = GPDMA_WIDTH_WORD;
- // Transfer type
- GPDMACfg.TransferType = DMAMode;
- // Linker List Item - unused
- GPDMACfg.DMALLI = 0;
-
- /* USB RAM is used for test.
- Please note, Ethernet has its own SRAM, but GPDMA can't access
- that. GPDMA can access USB SRAM and IRAM. Ethernet DMA controller can
- access both IRAM and Ethernet SRAM. */
- GPDMACfg.ChannelNum = ChannelNum;
-
- if ( DMAMode == GPDMA_TRANSFERTYPE_M2P_DEST_CTRL )
- {
- /* Ch0 set for M2P transfer from mempry to MCI FIFO. */
- // Source memory
- GPDMACfg.SrcMemAddr = (uint32_t)memBuf;
- // Destination memory
- GPDMACfg.DstMemAddr = (uint32_t)LPC_MCI->FIFO;
-
- // Source connection
- GPDMACfg.SrcConn = 0;
- // Destination connection
- GPDMACfg.DstConn = GPDMA_CONN_MCI;
-
- }
- else if ( DMAMode == GPDMA_TRANSFERTYPE_P2M_SRC_CTRL )
- {
- /* Ch0 set for P2M transfer from MCI FIFO to memory. */
- // Source memory
- GPDMACfg.SrcMemAddr = (uint32_t)LPC_MCI->FIFO;
- // Destination memory
- GPDMACfg.DstMemAddr = (uint32_t)memBuf;
-
- // Source connection
- GPDMACfg.SrcConn = GPDMA_CONN_MCI;
- // Destination connection
- GPDMACfg.DstConn = 0;
- }
- else
- {
- return ( FALSE );
- }
-
- // Setup channel with given parameter
- GPDMA_Setup(&GPDMACfg);
-
- // Enable GPDMA channel
- GPDMA_ChannelCmd(ChannelNum, ENABLE);
-
- /* Enable GPDMA interrupt */
- NVIC_EnableIRQ(DMA_IRQn);
-
- return (TRUE);
-}
-
-
-/*********************************************************************//**
- * @brief GPDMA interrupt handler sub-routine
- *
- * @param None
- *
- * @return None
- *
- * @note This is only executed if DMA support is enabled
- **********************************************************************/
-void MCI_DMA_IRQHandler (void)
-{
- // check GPDMA interrupt on channel 0
- if (GPDMA_IntGetStatus(GPDMA_STAT_INT, MCI_DMA_WRITE_CHANNEL))
- {
- //check interrupt status on channel 0
- // Check counter terminal status
- if(GPDMA_IntGetStatus(GPDMA_STAT_INTTC, MCI_DMA_WRITE_CHANNEL))
- {
- // Clear terminate counter Interrupt pending
- GPDMA_ClearIntPending (GPDMA_STATCLR_INTTC, MCI_DMA_WRITE_CHANNEL);
-
- dmaWrCh_TermianalCnt++;
- }
- if (GPDMA_IntGetStatus(GPDMA_STAT_INTERR, MCI_DMA_WRITE_CHANNEL))
- {
- // Clear error counter Interrupt pending
- GPDMA_ClearIntPending (GPDMA_STATCLR_INTERR, MCI_DMA_WRITE_CHANNEL);
-
- dmaWrCh_ErrorCnt++;
- }
- }
- else if (GPDMA_IntGetStatus(GPDMA_STAT_INT, MCI_DMA_READ_CHANNEL))
- {
- //check interrupt status on channel 0
- // Check counter terminal status
- if(GPDMA_IntGetStatus(GPDMA_STAT_INTTC, MCI_DMA_READ_CHANNEL))
- {
- // Clear terminate counter Interrupt pending
- GPDMA_ClearIntPending (GPDMA_STATCLR_INTTC, MCI_DMA_READ_CHANNEL);
-
- dmaRdCh_TermianalCnt++;
- }
- if (GPDMA_IntGetStatus(GPDMA_STAT_INTERR, MCI_DMA_READ_CHANNEL))
- {
- // Clear error counter Interrupt pending
- GPDMA_ClearIntPending (GPDMA_STATCLR_INTERR, MCI_DMA_READ_CHANNEL);
-
- dmaRdCh_ErrorCnt++;
- }
- }
-}
-#endif
-
-
-/*********************************************************************//**
- * @brief Read data from FIFO (after a transmission with card) to
- * a destination buffer
- *
- * @param[in] *dest The buffer to store the data that read from card
- *
- * @return MCI_FUNC_OK
- *************************************************************************/
-int32_t MCI_ReadFifo(uint32_t * dest)
-{
- uint8_t i;
- uint8_t start, end;
-
- if(fifo_plane == 0)
- {
- start = 0;
- end = 7;
- }
- else
- {
- start = 8;
- end = 15;
- }
- fifo_plane = (fifo_plane) ? 0:1;
-
- for (i = start; i <= end; i++)
- {
- *dest = LPC_MCI->FIFO[i];
-
- dest++;
- }
-
- return MCI_FUNC_OK;
-}
-
-
-/*********************************************************************//**
- * @brief Write data from a source buffer to FIFO for transmission
- *
- * @param[in] *src The buffer hold the data need to write to card
- *
- * @return MCI_FUNC_OK
- *************************************************************************/
-int32_t MCI_WriteFifo(uint32_t * src)
-{
- uint8_t i;
- uint8_t start, end;
-
- if(fifo_plane == 0)
- {
- start = 0;
- end = 7;
- }
- else
- {
- start = 8;
- end = 15;
- }
- fifo_plane = (fifo_plane) ? 0:1;
-
- for (i = start; i <= end; i++)
- {
- LPC_MCI->FIFO[i] = *src;
-
- src++;
- }
-
- return MCI_FUNC_OK;
-}
-
-
-/*********************************************************************//**
- * @brief Enable Transmit data interrupt
- *
- * @param None
- *
- * @return None
- *************************************************************************/
-void MCI_TXEnable( void )
-{
-#if MCI_DMA_ENABLED
- LPC_MCI->MASK0 |= ((DATA_END_INT_MASK)|(ERR_TX_INT_MASK)); /* Enable TX interrupts only */
-#else
- LPC_MCI->MASK0 |= ((FIFO_TX_INT_MASK)|(DATA_END_INT_MASK)|(ERR_TX_INT_MASK)); /* FIFO TX interrupts only */
-#endif
-
- return;
-}
-
-
-/*********************************************************************//**
- * @brief Disable Transmit data interrupt
- *
- * @param None
- *
- * @return None
- *************************************************************************/
-void MCI_TXDisable( void )
-{
-#if MCI_DMA_ENABLED
- LPC_MCI->MASK0 &= ~((DATA_END_INT_MASK)|(ERR_TX_INT_MASK)); /* Enable TX interrupts only */
-#else
- LPC_MCI->MASK0 &= ~((FIFO_TX_INT_MASK)|(DATA_END_INT_MASK)|(ERR_TX_INT_MASK)); /* FIFO TX interrupts only */
-#endif
-
- return;
-}
-
-
-/*********************************************************************//**
- * @brief Enable Receive data interrupt
- *
- * @param None
- *
- * @return None
- *************************************************************************/
-void MCI_RXEnable( void )
-{
-#if MCI_DMA_ENABLED
- LPC_MCI->MASK0 |= ((DATA_END_INT_MASK)|(ERR_RX_INT_MASK)); /* Enable RX interrupts only */
-#else
- LPC_MCI->MASK0 |= ((FIFO_RX_INT_MASK)|(DATA_END_INT_MASK)|(ERR_RX_INT_MASK)); /* FIFO RX interrupts only */
-#endif
-
- return;
-}
-
-
-/*********************************************************************//**
- * @brief Disable Receive data interrupt
- *
- * @param None
- *
- * @return None
- *************************************************************************/
-void MCI_RXDisable( void )
-{
-#if MCI_DMA_ENABLED
- LPC_MCI->MASK0 &= ~((DATA_END_INT_MASK)|(ERR_RX_INT_MASK)); /* Enable TX interrupts only */
-#else
- LPC_MCI->MASK0 &= ~((FIFO_RX_INT_MASK)|(DATA_END_INT_MASK)|(ERR_RX_INT_MASK)); /* FIFO TX interrupts only */
-#endif
-
- return;
-}
-
-/*********************************************************************//**
- * @brief Check if the card is in the given state.
- *@param expect_status expected status
- * @details Continuously get the card status until the card is ready. if its status matches
- * with the given state, return with success. Else, return MCI_FUNC_ERR_STATE.
- * If the card is still not ready, return MCI_FUNC_NOT_READY.
- *
- * @param None
- *
- * @return MCI_FUNC_OK if all success
- *************************************************************************/
-int32_t MCI_CheckStatus(uint8_t expect_status)
-{
- int32_t respValue, retval = MCI_FUNC_FAILED;
- uint32_t retryCnt = 0xFFFF, i;
- while (retryCnt > 0)
- {
- if (MCI_GetCardStatus(&respValue) != MCI_FUNC_OK)
- {
- break;
- }
- else
- {
- /* The only valid state is TRANS per MMC and SD state diagram.
- RCV state may be seen, but, it happens only when TX_ACTIVE or
- RX_ACTIVE occurs before the WRITE_BLOCK and READ_BLOCK cmds are
- being sent, which is not a valid sequence. */
- if(!(respValue & CARD_STATUS_READY_FOR_DATA ))
- {
- retval = MCI_FUNC_NOT_READY;
- }
- else if(CARDSTATEOF(respValue) != expect_status)
- {
- // If card is in prg state, wait until it changes to trans state
- // when "operation complete"
- if(CARDSTATEOF(respValue) != CARD_STATE_PRG)
- {
- return MCI_FUNC_ERR_STATE;
- }
- }
- else
- {
- return MCI_FUNC_OK;
- }
- }
- retryCnt--;
- for(i = 0; i < 0x20; i++);
-
- }
-
- return retval;
-}
-
-
-/*********************************************************************//**
- * @brief Called by MCI interrupt handler to simplify the command
- * process.
- *
- * @param None
- *
- * @return None
- *
- * @note In card initialization, the commnad interrupts are disabled
- *************************************************************************/
-void MCI_CmdProcess( void )
-{
- uint32_t MCIStatus;
-
- MCIStatus = LPC_MCI->STATUS;
-
- if ( MCIStatus & MCI_CMD_CRC_FAIL )
- {
- LPC_MCI->CLEAR = MCI_CMD_CRC_FAIL;
- }
-
- if ( MCIStatus & MCI_CMD_TIMEOUT )
- {
- LPC_MCI->CLEAR = MCI_CMD_TIMEOUT;
- }
-
- /* Cmd Resp End or Cmd Sent */
- if ( MCIStatus & MCI_CMD_RESP_END )
- {
- LPC_MCI->CLEAR = MCI_CMD_RESP_END;
- }
-
- if ( MCIStatus & MCI_CMD_SENT )
- {
- LPC_MCI->CLEAR = MCI_CMD_SENT;
- }
-
- if ( MCIStatus & MCI_CMD_ACTIVE )
- {
- LPC_MCI->CLEAR = MCI_CMD_ACTIVE;
- }
-
- return;
-}
-
-
-/*********************************************************************//**
- * @brief Called by MCI interrupt handler to manage error on the bus
- *
- * @param None
- *
- * @return None
- *************************************************************************/
-void MCI_DataErrorProcess( void )
-{
- uint32_t MCIStatus;
-
- MCIStatus = LPC_MCI->STATUS;
-
- if ( MCIStatus & MCI_DATA_CRC_FAIL )
- {
- LPC_MCI->CLEAR = MCI_DATA_CRC_FAIL;
- }
-
- if ( MCIStatus & MCI_DATA_TIMEOUT )
- {
- LPC_MCI->CLEAR = MCI_DATA_TIMEOUT;
- }
-
- /* Underrun or overrun */
- if ( MCIStatus & MCI_TX_UNDERRUN )
- {
- LPC_MCI->CLEAR = MCI_TX_UNDERRUN;
- }
-
- if ( MCIStatus & MCI_RX_OVERRUN )
- {
- LPC_MCI->CLEAR = MCI_RX_OVERRUN;
- }
-
- /* Start bit error on data signal */
- if ( MCIStatus & MCI_START_BIT_ERR )
- {
- LPC_MCI->CLEAR = MCI_START_BIT_ERR;
- }
-
- Mci_Data_Xfer_End = 0;
- Mci_Data_Xfer_ERR = MCIStatus;
- return;
-}
-
-
-/*********************************************************************//**
- * @brief Called by MCI interrupt handler. This is the last interrupt
- * manipulates the process of the data-block write and read
- * to/with card
- *
- * @details This service is also used with/without DMA support. It simply
- * clears the flag messages the in-process data-block transfer
- * has been done/ended
- *
- * @param None
- *
- * @return None
- *************************************************************************/
-void MCI_DATA_END_InterruptService( void )
-{
- uint32_t MCIStatus;
-
- MCIStatus = LPC_MCI->STATUS;
- if ( MCIStatus & MCI_DATA_END ) /* Data end, and Data block end */
- {
- LPC_MCI->CLEAR = MCI_DATA_END;
-
- Mci_Data_Xfer_End = 0;
-
- Mci_Data_Xfer_ERR = 0;
-
- MCI_TXDisable();
-
- MCI_RXDisable();
-
- return;
- }
-
- if ( MCIStatus & MCI_DATA_BLK_END )
- {
- LPC_MCI->CLEAR = MCI_DATA_BLK_END;
-
- //MCI_TXDisable();
-
- return;
- }
-
- /* Tx active */
- if ( MCIStatus & MCI_TX_ACTIVE )
- {
-
- }
-
- /* Rx active */
- if ( MCIStatus & MCI_RX_ACTIVE )
- {
-
- }
-
- return;
-}
-
-
-/*********************************************************************//**
- * @brief Called by MCI interrupt handler if requiring to using FIFO
- * for data transferring. It copy data to/from FIFO register
- * from/to a data buffer.
- *
- * @param None
- *
- * @return None
- *
- * @note This function is done without DMA transfer support
- **********************************************************************/
-void MCI_FIFOInterruptService( void )
-{
-#if !MCI_DMA_ENABLED
- uint32_t MCIStatus;
-
- MCIStatus = LPC_MCI->STATUS;
-
- if ( MCIStatus & (FIFO_TX_INT_MASK ) )
- {
- /* empty is multiple of 512 block size */
- if ( MCIStatus & MCI_TX_HALF_EMPTY )
- {
- //There's no data, return
- if(dataSrcBlock == NULL)
- return;
-
- /* write 8 words to fifo */
- MCI_WriteFifo((uint32_t *)&dataSrcBlock[txBlockCnt]);
-
- txBlockCnt += 32;
- }
-
- if (txBlockCnt == BLOCK_LENGTH) /* block complete */
- {
- dataSrcBlock += BLOCK_LENGTH;
-
- txBlockCnt = 0;
-
- /* disable FIFO int until next block write */
- //LPC_MCI->MASK0 &= ~(FIFO_TX_INT_MASK);
-
- /* wait for SD card to complete sending data i.e MCI_DATA_BLK_END interrupt */
- }
- }
- else if ( MCIStatus & (FIFO_RX_INT_MASK) )
- {
- /* if using RX_HALF_FULL remove one ReadFIFO below */
- if ( MCIStatus & MCI_RX_HALF_FULL )
- {
- //There's no store data, return
- if(dataDestBlock == NULL)
- return;
-
- /* read 8 words from fifo */
- MCI_ReadFifo((uint32_t *)&dataDestBlock[rxBlockCnt]);
-
- rxBlockCnt += 32;
- }
-
- /* block complete */
- if (rxBlockCnt == BLOCK_LENGTH)
- {
- dataDestBlock += BLOCK_LENGTH;
-
- rxBlockCnt = 0;
- }
- }
-#endif
-
- return;
-}
-
-/*********************************************************************//**
- * @brief MCI_IRQHandler is to manage the reasons that cause the
- * interrupt.
- *
- * @details It controls the data-block writing and reading by access
- * the FIFO register.
- * It handle the state changes on the MCI bus...
- *
- * @param None
- *
- * @return None
- **********************************************************************/
-void MCI_IRQHandler (void)
-{
- uint32_t MCI_Status;
-
- MCI_Status = LPC_MCI->STATUS;
-
- /* handle MCI_STATUS interrupt */
- if ( MCI_Status & DATA_ERR_INT_MASK )
- {
- MCI_DataErrorProcess();
-
- return;
- }
-
- if ( MCI_Status & DATA_END_INT_MASK )
- {
- MCI_DATA_END_InterruptService();
-
- return;
- }
- else if ( MCI_Status & FIFO_INT_MASK )
- {
- MCI_FIFOInterruptService();
-
- return;
- }
- else if ( MCI_Status & CMD_INT_MASK )
- {
- MCI_CmdProcess();
-
- return;
- }
-}
-
-
-/**
- * @}
- */
-
-
-
-/** @addtogroup MCI_Public_Functions
- * @{
- */
-
-/*********************************************************************//**
- * @brief Set MCI clock rate, during initialization phase < 400K
- * during data phase < 20Mhz
- *
- * @param[in] ClockRate Clock rate to be set (in Hz)
- *
- * @return None
- **********************************************************************/
-void MCI_Set_MCIClock( uint32_t ClockRate )
-{
- volatile uint32_t i;
- uint32_t ClkValue = 0;
- uint32_t pclk;
-
- pclk = CLKPWR_GetCLK(CLKPWR_CLKTYPE_PER);
-
- ClkValue = (pclk + 2*ClockRate - 1) /(2*ClockRate);
- if(ClkValue)
- ClkValue -= 1;
-
- LPC_MCI->CLOCK = (LPC_MCI->CLOCK & ~(0xFF)) | (1 << 8) | ClkValue;
-
- for ( i = 0; i < 0x10; i++ ); /* delay 3MCLK + 2PCLK before next write */
-
- return;
-}
-
-
-/**********************************************************************//**
- * @brief Set the Width to 1-bit Bus or 4-bit Bus
- *
- * @param[in] width buswidth expected to set
- *
- * @return MCI_FUNC_OK in case of success
- *************************************************************************/
-int32_t MCI_SetBusWidth( uint32_t width )
-{
- volatile uint32_t i;
- uint8_t bus_width = BUS_WIDTH_1BIT;
-
- if ( width == SD_1_BIT )
- {
- LPC_MCI->CLOCK &= ~(1 << 11); /* 1 bit bus */
- }
- else if ( width == SD_4_BIT )
- {
- LPC_MCI->CLOCK |= (1 << 11);/* 4 bit bus */
- bus_width = BUS_WIDTH_4BITS;
- }
-
- for ( i = 0; i < 0x10; i++ ); /* delay 3MCLK + 2PCLK */
-
- if ((MCI_CardType == MCI_SDSC_V1_CARD) ||
- (MCI_CardType == MCI_SDSC_V2_CARD) ||
- (MCI_CardType == MCI_SDHC_SDXC_CARD))
- {
- if ( MCI_Acmd_SendBusWidth( bus_width ) != MCI_FUNC_OK )
- {
- return(MCI_FUNC_FAILED);
- }
- }
- return MCI_FUNC_OK;
-}
-
-
-/************************************************************************//**
- * @brief Do initialization the MCI block as set its clock, registers,
- * setup NVIC for interrupts, configure the pins used for MCI
- * function, do initialize the card in slot...
- *
- * @param[in] powerActiveLevel the power level to activate the card in slot
- *
- * @return MCI_FUNC_OK in case of success
- ***************************************************************************/
-int32_t MCI_Init(uint8_t powerActiveLevel )
-{
- volatile uint32_t i;
-
- MCI_CardType = MCI_CARD_UNKNOWN;
-
- // Following block of code added to ensure card VCC drops to zero
- // before card is initialized
-
- // Force all MCI control pins to basic I/O mode
- LPC_IOCON->P1_2 &= ~0x1F; /* SD_CLK @ P1.2 */
- LPC_IOCON->P1_3 &= ~0x1F; /* SD_CMD @ P1.3 */
- LPC_IOCON->P1_5 &= ~0x1F; /* SD_PWR @ P1.5 */
- LPC_IOCON->P1_6 &= ~0x1F; /* SD_DAT_0 @ P1.6 */
- LPC_IOCON->P1_7 &= ~0x1F; /* SD_DAT_1 @ P1.7 */
- LPC_IOCON->P1_11 &= ~0x1F; /* SD_DAT_2 @ P1.11 */
- LPC_IOCON->P1_12 &= 0x1F; /* SD_DAT_3 @ P1.12 */
-
- // Set all MCI pins to outputs
- LPC_GPIO1->DIR |= 0x18EC;
-
- // Force all pins low (except power control pin)
- LPC_GPIO1->CLR = 0x1000;
- LPC_GPIO1->CLR = 0x0800;
- LPC_GPIO1->CLR = 0x0080;
- LPC_GPIO1->CLR = 0x0040;
-
- LPC_GPIO1->SET = 0x0020;
-
- LPC_GPIO1->CLR = 0x0008;
- LPC_GPIO1->CLR = 0x0004;
-
- // Crude delay of 50ms at 120MHz
- for ( i = 0; i < 0x100000; i++ );
-
- LPC_SC->PCONP |= ( 1 << 28 ); /* Enable clock to the MCI block */
-
- if ( LPC_MCI->CLOCK & (1 << 8) )
- {
- LPC_MCI->CLOCK &= ~(1 << 8);
- for ( i = 0; i < 0x10; i++ ); /* delay 3MCLK + 2PCLK */
- }
-
- if ( LPC_MCI->POWER & 0x02 )
- {
- LPC_MCI->POWER = 0x00;
- for ( i = 0; i < 0x10; i++ ); /* delay 3MCLK + 2PCLK */
- }
-
- /* Disable all interrupts for now */
- LPC_MCI->MASK0 = 0;
-
- //SD_CLK
- PINSEL_ConfigPin(1, 2, 2);
-
- //SD_CMD
- PINSEL_ConfigPin(1, 3, 2);
-
- //SD_PWR
- PINSEL_ConfigPin(1, 5, 2);
-
- //SD_DAT_0
- PINSEL_ConfigPin(1, 6, 2);
-
- //SD_DAT_1
- PINSEL_ConfigPin(1, 7, 2);
-
- //SD_DAT_2
- PINSEL_ConfigPin(1, 11, 2);
-
- //SD_DAT_3
- PINSEL_ConfigPin(1, 12, 2);
-
- // SD_PWR is active high (follows the output of the SD Card interface block).
- if(powerActiveLevel == LOW_LVL)
- {
- LPC_SC->SCS &= ~ 0x08;//Becase on EA board SD_PWR is active low
- }
- else
- {
- LPC_SC->SCS |= 0x08;
- }
-
- //Setting for timeout problem
- LPC_MCI->DATATMR = 0x1FFFFFFF;
-
- /*set up clocking default mode, clear any registers as needed */
- LPC_MCI->COMMAND = 0;
- for ( i = 0; i < 0x10; i++ ); /* delay 3MCLK + 2PCLK */
- LPC_MCI->DATACTRL = 0;
- for ( i = 0; i < 0x10; i++ ); /* delay 3MCLK + 2PCLK */
- LPC_MCI->CLEAR = 0x7FF; /* clear all pending interrupts */
-
- LPC_MCI->POWER = 0x02; /* power up */
- for ( i = 0; i < 0x10; i++ ); /* delay 3MCLK + 2PCLK */
-
-
- /* delays for the supply output is stable*/
- for ( i = 0; i < 0x80000; i++ );
-
- /* During identification phase, the clock should be less than
- 400Khz. Once we pass this phase, the normal clock can be set up
- to 25Mhz on SD card and 20Mhz on MMC card. */
- MCI_Set_MCIClock(MCI_SLOW_RATE );
-
- LPC_MCI->POWER |= 0x01; /* bit 1 is set already, from power up to power on */
- for ( i = 0; i < 0x10; i++ ); /* delay 3MCLK + 2PCLK */
-
- NVIC_EnableIRQ(MCI_IRQn);
-
- MCI_CardInit();
-
- /* During the initialization phase, to simplify the process, the CMD related
- interrupts are disabled. The DATA related interrupts are enabled when
- the FIFOs are used and just before WRITE_BLOCK READ_BLOCK cmds are issues, and
- disabled after the data block has been written and read. Please also note,
- before WRITE_BLOCK only TX related data interrupts are enabled, and before
- READ_BLOCK only RX related data interrupts are enabled. */
- return MCI_FUNC_OK;
-}
-
-
-/************************************************************************//**
- * @brief Set output in open drain mode or pushpull mode
- *
- * @param[in] mode the mode going to set
- *
- * @return None
- ***************************************************************************/
-void MCI_SetOutputMode(uint32_t mode)
-{
- uint32_t i = 0;
- if(mode == MCI_OUTPUT_MODE_OPENDRAIN)
- {
- /* Set Open Drain output control for MMC */
- LPC_MCI->POWER |= (1 << MCI_PWRCTRL_OPENDRAIN_POS) & MCI_PWRCTRL_BMASK;
- }
- else
- {
- /* Clear Open Drain output control for SD */
- LPC_MCI->POWER &= (~(1 << MCI_PWRCTRL_OPENDRAIN_POS) & MCI_PWRCTRL_BMASK);
- }
- for ( i = 0; i < 0x10; i++ ); /* delay 3MCLK + 2PCLK */
-}
-
-
-/************************************************************************//**
- * @brief The routine is used to send a CMD to the card
- *
- * @param[in] CmdIndex the command to be sent to cards
- *
- * @param[in] Argument the argument follows the command
- *
- * @param[in] ExpectResp the response type for the command. They may be:
- * - EXPECT_NO_RESP: means no response required
- * - EXPECT_SHORT_RESP: means a response in a word needed
- * - EXPECT_LONG_RESP: means a response in 4 words needed
- *
- * @param[in] AllowTimeout allow timeout the command or not
- *
- * @return None
- ***************************************************************************/
-void MCI_SendCmd(st_Mci_CmdInfo* pCmdIf)
-{
- volatile uint32_t i;
- uint32_t CmdData = 0;
- uint32_t CmdStatus;
-
- uint32_t CmdIndex = pCmdIf->CmdIndex;
- uint32_t Argument = pCmdIf->Argument;
- uint32_t ExpectResp = pCmdIf->ExpectResp;
- uint32_t AllowTimeout = pCmdIf->AllowTimeout;
-
- /* the command engine must be disabled when we modify the argument
- or the peripheral resends */
- while ( (CmdStatus = LPC_MCI->STATUS) & MCI_CMD_ACTIVE ) /* Command in progress. */
- {
- LPC_MCI->COMMAND = 0;
- for ( i = 0; i < 0x10; i++ ); /* delay 3MCLK + 2PCLK */
- LPC_MCI->CLEAR = CmdStatus | MCI_CMD_ACTIVE;
- }
-
-
- /*set the command details, the CmdIndex should 0 through 0x3F only */
- CmdData |= (CmdIndex & 0x3F); /* bit 0 through 5 only */
-
- if ( ExpectResp == EXPECT_NO_RESP ) /* no response */
- {
- CmdData &= ~((1 << 6) | (1 << 7)); /* Clear long response bit as well */
- }
- else if ( ExpectResp == EXPECT_SHORT_RESP ) /* expect short response */
- {
- CmdData |= (1 << 6);
- }
- else if ( ExpectResp == EXPECT_LONG_RESP ) /* expect long response */
- {
- CmdData |= (1 << 6) | (1 << 7);
- }
-
- if ( AllowTimeout == ALLOW_CMD_TIMER ) /* allow timeout or not */
- {
- CmdData &= ~ MCI_DISABLE_CMD_TIMER;
- }
- else
- {
- CmdData |= MCI_DISABLE_CMD_TIMER;
- }
-
- /*send the command*/
- CmdData |= (1 << 10); /* This bit needs to be set last. */
-
- // clear status register
- LPC_MCI->CLEAR = 0x7FF;
-
- LPC_MCI->ARGUMENT = Argument; /* Set the argument first, finally command */
-
- LPC_MCI->COMMAND = CmdData;
-
- for ( i = 0; i < 0x10; i++ ); /* delay 3MCLK + 2PCLK */
-
- // Wait until command is processed
- while(!LPC_MCI->STATUS);
-
- // Wait until command sent
- while(LPC_MCI->STATUS & MCI_CMD_ACTIVE);
-
- return;
-}
-
-
-/************************************************************************//**
- * @brief The routine is to get the reponse from card after commands.
- * This function is always used in pair of MCI_SendCmd() func
- *
- * @param[in] ExpectCmdData specify the command of which the data will be
- * retrieved. This field should be the same with CmdIndex of
- * MCI_SendCmd() function.
- *
- * @param[in] ExpectResp the response type for the command. They may be:
- * - EXPECT_NO_RESP: means no response required
- * - EXPECT_SHORT_RESP: means a response in a word needed
- * - EXPECT_LONG_RESP: means a response in 4 words needed
- *
- * @param[out] CmdResp the buffer stored the data replied from cards
- *
- * @return MCI_FUNC_OK in case of success
- ***************************************************************************/
-int32_t MCI_GetCmdResp(uint32_t ExpectCmdData, uint32_t ExpectResp, uint32_t *CmdResp)
-{
- uint32_t CmdRespStatus = 0;
- uint32_t LastCmdIndex;
- uint32_t i = 0;
-
- if ( ExpectResp == EXPECT_NO_RESP )
- {
- return MCI_FUNC_OK;
- }
-
- while (1)
- {
- // Get the status of the component
- CmdRespStatus = LPC_MCI->STATUS;
-
- if ( CmdRespStatus & (MCI_CMD_TIMEOUT) )
- {
- LPC_MCI->CLEAR = CmdRespStatus | MCI_CMD_TIMEOUT;
-
- LPC_MCI->COMMAND = 0;
- LPC_MCI->ARGUMENT = 0xFFFFFFFF;
-
- for ( i = 0; i < 0x10; i++ ); /* delay 3MCLK + 2PCLK */
-
- return (CmdRespStatus);
- }
-
- if ( CmdRespStatus & MCI_CMD_CRC_FAIL )
- {
- LPC_MCI->CLEAR = CmdRespStatus | MCI_CMD_CRC_FAIL;
- LastCmdIndex = LPC_MCI->COMMAND & 0x003F;
-
- if ( (LastCmdIndex == CMD1_SEND_OP_COND) || (LastCmdIndex == ACMD41_SEND_APP_OP_COND)
- || (LastCmdIndex == CMD12_STOP_TRANSMISSION) )
- {
- LPC_MCI->COMMAND = 0;
- LPC_MCI->ARGUMENT = 0xFFFFFFFF;
- for ( i = 0; i < 0x10; i++ ); /* delay 3MCLK + 2PCLK */
- break; /* ignore CRC error if it's a resp for SEND_OP_COND
- or STOP_TRANSMISSION. */
- }
- else
- {
- return (CmdRespStatus);
- }
- }
- else if (CmdRespStatus & MCI_CMD_RESP_END)
- {
- LPC_MCI->CLEAR = CmdRespStatus | MCI_CMD_RESP_END;
- break; /* cmd response is received, expecting response */
- }
-
- }
-
- if ((LPC_MCI->RESP_CMD & 0x3F) != ExpectCmdData)
- {
- /* If the response is not R1, in the response field, the Expected Cmd data
- won't be the same as the CMD data in SendCmd(). Below four cmds have
- R2 or R3 response. We don't need to check if MCI_RESP_CMD is the same
- as the Expected or not. */
- if ((ExpectCmdData != CMD1_SEND_OP_COND) && (ExpectCmdData != ACMD41_SEND_APP_OP_COND)
- && (ExpectCmdData != CMD2_ALL_SEND_CID) && (ExpectCmdData != CMD9_SEND_CSD))
- {
- CmdRespStatus = INVALID_RESPONSE; /* Reuse error status */
- return (INVALID_RESPONSE);
- }
- }
-
- /* Read MCI_RESP0 register assuming it's not long response. */
- if (CmdResp != NULL)
- {
- if (ExpectResp == EXPECT_SHORT_RESP)
- {
- *(CmdResp + 0) = LPC_MCI->RESP0;
- }
- else if (ExpectResp == EXPECT_LONG_RESP)
- {
- *(CmdResp + 0) = LPC_MCI->RESP0;
- *(CmdResp + 1) = LPC_MCI->RESP1;
- *(CmdResp + 2) = LPC_MCI->RESP2;
- *(CmdResp + 3) = LPC_MCI->RESP3;
- }
- }
-
- return MCI_FUNC_OK;
-}
-
-
-/************************************************************************//**
- * @brief The routine is to send command to cards then get back the
- * reponses (if required).
- *
- * @param[in] CmdIndex the command to be sent to cards
- *
- * @param[in] Argument the argument follows the command
- *
- * @param[in] ExpectResp the response type for the command. They may be:
- * - EXPECT_NO_RESP: means no response required
- * - EXPECT_SHORT_RESP: means a response in a word needed
- * - EXPECT_LONG_RESP: means a response in 4 words needed
- *
- * @param[out] CmdResp the buffer stored the data replied from cards
- *
- * @param[in] AllowTimeout allow timeout the command or not
- *
- * @return MCI_FUNC_OK in case of success
- ***************************************************************************/
-int32_t MCI_CmdResp(st_Mci_CmdInfo* pCmdIf)
-{
- int32_t respStatus;
- uint32_t CmdIndex = pCmdIf->CmdIndex;
- uint32_t ExpectResp = pCmdIf->ExpectResp;
- uint32_t *CmdResp = pCmdIf->CmdResp;
-
-
- MCI_SendCmd(pCmdIf);
-
- if((CmdResp != NULL) || (ExpectResp != EXPECT_NO_RESP))
- {
- respStatus = MCI_GetCmdResp(CmdIndex, ExpectResp, CmdResp);
- }
- else
- {
- respStatus = MCI_FUNC_BAD_PARAMETERS;
- }
-
- return respStatus;
-}
-
-
-/************************************************************************//**
- * @brief To reset the card, the CMD0 is sent and then the card is put
- * in idle state. This is the very first command to be sent to
- * initialize either MMC or SD card.
- *
- * @param None
- *
- * @return Always MCI_FUNC_OK
- ***************************************************************************/
-int32_t MCI_CardReset(void)
-{
- st_Mci_CmdInfo cmdIf;
- /* Because CMD0 command to put the device to idle state does not need response
- since, it's only sending commad */
- cmdIf.CmdIndex = CMD0_GO_IDLE_STATE;
- cmdIf.Argument = 0x00000000;
- cmdIf.ExpectResp = EXPECT_NO_RESP;
- cmdIf.AllowTimeout = 0;
- cmdIf.CmdResp = 0;
- MCI_SendCmd(&cmdIf);
-
- return MCI_FUNC_OK;
-}
-
-
-/************************************************************************//**
- * @brief Send CMD1 (SEND_OP_COND) to card.
- *
- * @param None
- *
- * @return MCI_FUNC_OK if all success
- ****************************************************************************/
-int32_t MCI_Cmd_SendOpCond( void )
-{
- volatile uint32_t i;
- uint32_t retryCount;
- uint32_t respStatus;
- uint32_t respValue[4];
- st_Mci_CmdInfo cmdIf;
- int32_t retval = MCI_FUNC_FAILED;
-
- retryCount = 0x200; /* reset retry counter */
-
- cmdIf.CmdIndex = CMD1_SEND_OP_COND;
- cmdIf.Argument = OCR_INDEX;
- cmdIf.ExpectResp = EXPECT_SHORT_RESP;
- cmdIf.AllowTimeout = ALLOW_CMD_TIMER;
- cmdIf.CmdResp = (uint32_t *)&respValue[0];
- /* continuously sends until the busy bit is cleared */
- while ( retryCount > 0 )
- {
- respStatus = MCI_CmdResp(&cmdIf);
-
- if(respStatus & MCI_CMD_TIMEOUT)
- {
- retval = MCI_FUNC_TIMEOUT;
- }
- else if ((respValue[0] & 0x80000000) == 0)
- {
- //The card has not finished the power up routine
- retval = MCI_FUNC_BUS_NOT_IDLE;
- }
- else
- {
- retval = MCI_FUNC_OK;
- break;
- }
-
- for ( i = 0; i < 0x20; i++ );
-
- retryCount--;
- }
-
- return(retval);
-}
-
-
-/************************************************************************//**
- * @brief Send CMD8 (SEND_IF_COND) for interface condition to card.
- *
- * @param None
- *
- * @return MCI_FUNC_OK if all success
- ****************************************************************************/
-int32_t MCI_Cmd_SendIfCond(void)
-{
- volatile uint32_t i;
- uint32_t retryCount;
- uint32_t CmdArgument;
- uint32_t respStatus;
- uint32_t respValue[4];
-
- int32_t retval = MCI_FUNC_FAILED;
-
- uint8_t voltageSupplied = MCI_CMD8_VOLATAGESUPPLIED_27_36;//in range 2.7-3.6V
- uint8_t checkPattern = 0xAA;
- st_Mci_CmdInfo cmdIf;
-
- CmdArgument = (voltageSupplied << MCI_CMD8_VOLTAGESUPPLIED_POS) | (checkPattern << MCI_CMD8_CHECKPATTERN_POS);
-
- retryCount = 20;
-
- cmdIf.CmdIndex = CMD8_SEND_IF_COND;
- cmdIf.Argument = CmdArgument;
- cmdIf.ExpectResp = EXPECT_SHORT_RESP;
- cmdIf.AllowTimeout = ALLOW_CMD_TIMER;
- cmdIf.CmdResp = (uint32_t *)&respValue[0];
- while ( retryCount > 0 )
- {
- respStatus = MCI_CmdResp(&cmdIf);
-
- if(respStatus & MCI_CMD_TIMEOUT)
- {
- //Consider as no response
- retval = MCI_FUNC_TIMEOUT;
- }
- else if (((respValue[0]>>MCI_CMD8_CHECKPATTERN_POS) & MCI_CMD8_CHECKPATTERN_BMASK) != checkPattern)
- {
- return MCI_FUNC_BAD_PARAMETERS;
- }
- else if (((respValue[0] >> MCI_CMD8_VOLTAGESUPPLIED_POS) & MCI_CMD8_VOLTAGESUPPLIED_BMASK)
- != voltageSupplied)
- {
- return MCI_FUNC_BAD_PARAMETERS;
- }
- else
- {
- return MCI_FUNC_OK;
- }
-
- for ( i = 0; i < 0x20; i++ );
-
- retryCount--;
- }
-
- return retval;
-}
-
-
-/************************************************************************//**
- * @brief Send CMD55 (APP_CMD) to indicate to the card that the next
- * command is an application specific command rather than a
- * standard command. Before an ACMD, call this routine first
- *
- * @param None
- *
- * @return MCI_FUNC_OK if all success
- ****************************************************************************/
-int32_t MCI_Cmd_SendACMD( void )
-{
- volatile uint32_t i;
- uint32_t retryCount;
- uint32_t CmdArgument;
- uint32_t respStatus;
- uint32_t respValue[4];
- st_Mci_CmdInfo cmdIf;
- int32_t retval = MCI_FUNC_FAILED;
-
- if ((MCI_CardType == MCI_SDSC_V1_CARD) ||
- (MCI_CardType == MCI_SDSC_V2_CARD) ||
- (MCI_CardType == MCI_SDHC_SDXC_CARD))
- {
- CmdArgument = CardRCA; /* Use the address from SET_RELATIVE_ADDR cmd */
- }
- else /* if MMC or unknown card type, use 0x0. */
- {
- CmdArgument = 0x00000000;
- }
-
- retryCount = 20;
-
- cmdIf.CmdIndex = CMD55_APP_CMD;
- cmdIf.Argument = CmdArgument;
- cmdIf.ExpectResp = EXPECT_SHORT_RESP;
- cmdIf.AllowTimeout = ALLOW_CMD_TIMER;
- cmdIf.CmdResp = (uint32_t *)&respValue[0];
- while ( retryCount > 0 )
- {
- respStatus = MCI_CmdResp(&cmdIf);
-
- if(respStatus != 0)
- {
- retval = MCI_FUNC_FAILED;
- }
- else if (respValue[0] & CARD_STATUS_ACMD_ENABLE)
- {
- retval = MCI_FUNC_OK;
- break;
- }
- else
- {
- retval = MCI_FUNC_NOT_READY;
- }
-
- for ( i = 0; i < 0x20; i++ );
-
- retryCount--;
- }
-
- return retval;
-}
-
-
-/************************************************************************//**
- * @brief Send ACMD41 (SEND_APP_OP_COND) to Host Capacity Support (HCS)
- * information and asks the accessed card to send its operating
- * condition (OCR).
- *
- * @param[in] hcsVal input the Host Capacity Support
- *
- * @return MCI_FUNC_OK if all success
- *
- * @note If SEND_APP_OP_COND is timeout, the card in the slot is not MMC
- * type, try this combination to see if we can communicate with
- * a SD type.
- ****************************************************************************/
-int32_t MCI_Acmd_SendOpCond(uint8_t hcsVal)
-{
- volatile uint32_t i;
- uint32_t retryCount;
- uint32_t respStatus, argument;
- uint32_t respValue[4];
- st_Mci_CmdInfo cmdIf;
-
- int32_t retval = MCI_FUNC_FAILED;
-
- argument = OCR_INDEX | (hcsVal << MCI_ACMD41_HCS_POS);
-
- /* timeout on SEND_OP_COND command on MMC, now, try SEND_APP_OP_COND
- command to SD */
- retryCount = 0x2000; /* reset retry counter */
-
- cmdIf.CmdIndex = ACMD41_SEND_APP_OP_COND;
- cmdIf.Argument = argument;
- cmdIf.ExpectResp = EXPECT_SHORT_RESP;
- cmdIf.AllowTimeout = ALLOW_CMD_TIMER;
- cmdIf.CmdResp = (uint32_t *)&respValue[0];
-
- /* Clear Open Drain output control for SD */
- MCI_SetOutputMode(MCI_OUTPUT_MODE_PUSHPULL);
-
- /* The host repeatedly issues ACMD41 for at least 1 second or */
- /* until the busy bit are set to 1 */
- while ( retryCount > 0 )
- {
- if ((retval = MCI_Cmd_SendACMD()) == MCI_FUNC_OK)
- {
- respStatus = MCI_CmdResp(&cmdIf);
-
- if(respStatus & MCI_CMD_TIMEOUT)
- {
- retval = MCI_FUNC_TIMEOUT;
- }
- else if (!(respValue[0] & 0x80000000))
- {
- retval = MCI_FUNC_BUS_NOT_IDLE;
- }
- else
- {
- CCS = (respValue[0]&(1<<30)) ? 1:0;
- retval = MCI_FUNC_OK;
- break;
- }
- }
- else /* The command isn't accepted by the card.*/
- {
- return retval;
- }
-
- for ( i = 0; i < 0x20; i++ );
-
- retryCount--;
- }
-
- return retval;
-}
-
-/************************************************************************//**
- * @brief Do initialization for the card in the slot
- *
- * @details Try CMD1 first for MMC, if it's timeout, try CMD55
- * and CMD41 for SD, if both failed, initialization faliure,
- * bailout with unknown card type. Otherwise, return the
- * card type, either MMC or SD. <<<KHOA_110708: checking>>>
- *
- * This is followed Figure 4-2: Card Initialization and
- * Identification Flow (SD mode) in Physical Layer Simplified
- * Specification Version 2.00 document
- *
- * @param None
- *
- * @return MCI_FUNC_OK if success
- ****************************************************************************/
-int32_t MCI_CardInit( void )
-{
- volatile uint32_t i;
- int32_t retval = MCI_FUNC_FAILED;
-
- MCI_CardType = MCI_CARD_UNKNOWN;
-
- if (MCI_CardReset() != MCI_FUNC_OK)
- {
- return MCI_FUNC_FAILED;
- }
-
- /* Clear Open Drain output control for SD */
- MCI_SetOutputMode(MCI_OUTPUT_MODE_PUSHPULL);
-
- for ( i = 0; i < 0x3000; i++ );
-
- retval = MCI_Cmd_SendIfCond();
-
- if(retval == MCI_FUNC_BAD_PARAMETERS)
- {
- //Unknow card is unusable
- return retval;
- }
-
- if(retval == MCI_FUNC_OK) /* Ver2.00 or later*/
- {
- //Check in case of High Capacity Supporting Host
- if ((retval = MCI_Acmd_SendOpCond(1)) == MCI_FUNC_OK)
- {
- MCI_CardType = MCI_SDSC_V2_CARD;//SDSC
-
- if(CCS )
- {
- MCI_CardType = MCI_SDHC_SDXC_CARD;//SDHC or SDXC
- }
-
- return MCI_FUNC_OK; /* Found the card, it's a hD */
- }
- }
-
- if(retval != MCI_FUNC_OK) /* voltage mismatch (ver2.00)or ver1.X SD Card or not SD Card*/
- {
-
- //Check in case of Standard Capacity Supporting Host
- if ((retval = MCI_Acmd_SendOpCond(0)) == MCI_FUNC_OK)
- {
- MCI_CardType = MCI_SDSC_V1_CARD;//Support Standard Capacity only
-
- return MCI_FUNC_OK; /* Found the card, it's a SD */
- }
- }
-
- if(retval != MCI_FUNC_OK)
- {
- /* Set Open Drain output control for MMC */
- MCI_SetOutputMode(MCI_OUTPUT_MODE_OPENDRAIN);
-
- for ( i = 0; i < 0x3000; i++ );
-
- /* Try CMD1 first for MMC, if it's timeout, try CMD55 and CMD41 for SD,
- if both failed, initialization faIlure, bailout. */
- if (MCI_Cmd_SendOpCond() == MCI_FUNC_OK)
- {
- MCI_CardType = MCI_MMC_CARD;
-
- return MCI_FUNC_OK; /* Found the card, it's a MMC */
- }
- }
-
- /* tried both MMC and SD card, give up */
- return MCI_FUNC_OK;
-}
-
-
-/************************************************************************//**
- * @brief Get the type of card that is currently used in the slot
- *
- * @param None
- *
- * @return Card Type: MMC Card or SD card
- ****************************************************************************/
-en_Mci_CardType MCI_GetCardType(void)
-{
- return MCI_CardType;
-}
-
-
-/************************************************************************//**
- * @brief Get the all the Identifier (CID) of the card by sending the
- * CMD2 (ALL_SEND_CID) command. Then parse 4-byte data obtained
- * from the card by the CID meaning.
- *
- * @param[out] cidValue the CID Result after parsing the data from the card
- *
- * @return MCI_FUNC_OK if all success
- ****************************************************************************/
-int32_t MCI_GetCID(st_Mci_CardId* cidValue)
-{
- volatile uint32_t i;
- uint32_t retryCount;
- uint32_t respStatus;
- uint32_t respValue[4];
- st_Mci_CmdInfo cmdIf;
-
- /* This command is normally after CMD1(MMC) or ACMD41(SD). */
- retryCount = 0x200;// 0x20; /* reset retry counter */
-
- cmdIf.CmdIndex = CMD2_ALL_SEND_CID;
- cmdIf.Argument = 0;
- cmdIf.ExpectResp = EXPECT_LONG_RESP;
- cmdIf.AllowTimeout = ALLOW_CMD_TIMER;
- cmdIf.CmdResp = (uint32_t *)&respValue[0];
- while ( retryCount > 0 )
- {
- respStatus = MCI_CmdResp(&cmdIf);
-
- /* bit 0 and bit 2 must be zero, or it's timeout or CRC error */
- //if ((!(respStatus & MCI_CMD_TIMEOUT)) && (!(respStatus & MCI_CMD_CRC_FAIL)))
- if (!(respStatus & MCI_CMD_TIMEOUT))
- {
- // Parsing the data retrieved
- if(cidValue != NULL)
- {
- cidValue->MID = (respValue[0] >> MCI_CID_MANUFACTURER_ID_WPOS) & MCI_CID_MANUFACTURER_ID_WBMASK;
-
- cidValue->OID = (respValue[0] >> MCI_CID_OEMAPPLICATION_ID_WPOS) & MCI_CID_OEMAPPLICATION_ID_WBMASK;
-
- cidValue->PNM_H = (respValue[0] >> MCI_CID_PRODUCTNAME_ID_H_WPOS) & MCI_CID_PRODUCTNAME_ID_H_WBMASK;
-
- cidValue->PNM_L = (respValue[1] >> MCI_CID_PRODUCTNAME_ID_L_WPOS) & MCI_CID_PRODUCTNAME_ID_L_WBMASK;
-
- cidValue->PRV = (respValue[2] >> MCI_CID_PRODUCTREVISION_ID_WPOS) & MCI_CID_PRODUCTREVISION_ID_WBMASK;
-
- cidValue->PSN = (((respValue[2] >> MCI_CID_PRODUCTSERIALNUM_ID_H_WPOS) & MCI_CID_PRODUCTSERIALNUM_ID_H_WBMASK) << 8)
- | ((respValue[3] >> MCI_CID_PRODUCTSERIALNUM_ID_L_WPOS) & MCI_CID_PRODUCTSERIALNUM_ID_L_WBMASK);
-
- cidValue->reserved = (respValue[3] >> MCI_CID_RESERVED_ID_WPOS) & MCI_CID_RESERVED_ID_WBMASK;
-
- cidValue->MDT = (respValue[3] >> MCI_CID_MANUFACTURINGDATE_ID_WPOS) & MCI_CID_MANUFACTURINGDATE_ID_WBMASK;
-
- cidValue->CRC = (respValue[3] >> MCI_CID_CHECKSUM_ID_WPOS) & MCI_CID_CHECKSUM_ID_WBMASK;
-
- cidValue->unused = (respValue[3] >> MCI_CID_UNUSED_ID_WPOS) & MCI_CID_UNUSED_ID_WBMASK;
-
- }
-
- return MCI_FUNC_OK; /* response is back and correct. */
- }
-
-
- for ( i = 0; i < 0x20; i++ );
-
- retryCount--;
- }
-
- return MCI_FUNC_TIMEOUT;
-}
-
-
-/************************************************************************//**
- * @brief Set the address for the card in the slot by sending CMD3
- * (SET_RELATIVE_ADDR) command. To get the address of the card
- * currently in used, needs to call MCI_GetCardAddress()
- *
- * @param None
- *
- * @return MCI_FUNC_OK if all success
- ****************************************************************************/
-int32_t MCI_SetCardAddress( void )
-{
- volatile uint32_t i;
- uint32_t retryCount;
- uint32_t respStatus;
- uint32_t respValue;
- uint32_t CmdArgument;
- st_Mci_CmdInfo cmdIf;
- int32_t retval = MCI_FUNC_FAILED;
-
- /* If it's a SD card, SET_RELATIVE_ADDR is to get the address
- from the card and use this value in RCA, if it's a MMC, set default
- RCA addr. 0x00010000. */
- if ((MCI_CardType == MCI_SDSC_V1_CARD) ||
- (MCI_CardType == MCI_SDSC_V2_CARD) ||
- (MCI_CardType == MCI_SDHC_SDXC_CARD))
- {
- CmdArgument = 0;
- }
- else /* If it's unknown or MMC_CARD, fix the RCA address */
- {
- CmdArgument = 0x00010000;
- }
-
- retryCount = 0x20; /* reset retry counter */
- cmdIf.CmdIndex = CMD3_SET_RELATIVE_ADDR;
- cmdIf.Argument = CmdArgument;
- cmdIf.ExpectResp = EXPECT_SHORT_RESP;
- cmdIf.AllowTimeout = ALLOW_CMD_TIMER;
- cmdIf.CmdResp = &respValue;
- while ( retryCount > 0 )
- {
- /* Send CMD3 command repeatedly until the response is back correctly */
- respStatus = MCI_CmdResp(&cmdIf);
-
- if(respStatus & MCI_CMD_TIMEOUT)
- {
- retval = MCI_FUNC_TIMEOUT;
- }
- else if(!((respValue >> RCA_RES_CARD_STATUS_POS)& CARD_STATUS_READY_FOR_DATA))
- {
- retval = MCI_FUNC_NOT_READY;
- }
- else if((CARDSTATEOF(respValue) != MCI_CARDSTATE_IDENDTIFIED))
- {
- retval = MCI_FUNC_ERR_STATE;
- }
- else
- {
- CardRCA = (respValue >> RCA_RES_NEW_PUBLISHED_RCA_POS) & RCA_RES_NEW_PUBLISHED_RCA_MASK; /* Save the RCA value from SD card */
-
- CardRCA <<= RCA_ARGUMENT_POS;
-
- MCI_SetOutputMode(MCI_OUTPUT_MODE_PUSHPULL);
-
- return (MCI_FUNC_OK); /* response is back and correct. */
- }
-
- for ( i = 0; i < 0x20; i++ );
-
- retryCount--;
- }
-
- return retval;
-}
-
-
-/************************************************************************//**
- * @brief Get the address for the card in the slot
- *
- * @param None
- *
- * @return MCI_FUNC_OK if all success
- *
- * @note This function must be called after MCI_SetCardAddress() executing
- ****************************************************************************/
-uint32_t MCI_GetCardAddress(void)
-{
- return CardRCA;
-}
-
-
-/************************************************************************//**
- * @brief Get the Card-Specific Data of in-slot card by sending CMD9
- * (SEND_CSD) command
- *
- * @param[out] csdVal a buffer stored the value of CSD obtained from the card
- *
- * @return MCI_FUNC_OK if all success
- *
- * @note CMD9 (SEND_CSD) command should be sent only at standby state
- * (STBY) after CMD3
- ****************************************************************************/
-int32_t MCI_GetCSD(uint32_t* csdVal)
-{
- volatile uint32_t i;
- uint32_t retryCount;
- uint32_t respStatus;
- uint32_t respValue[4];
- uint32_t CmdArgument;
- st_Mci_CmdInfo cmdIf;
-
- if ((MCI_CardType == MCI_SDSC_V1_CARD) ||
- (MCI_CardType == MCI_SDSC_V2_CARD) ||
- (MCI_CardType == MCI_SDHC_SDXC_CARD))
- {
- CmdArgument = CardRCA;
- }
- else /* if MMC or unknown card type, use default RCA addr. */
- {
- CmdArgument = 0x00010000;
- }
-
- retryCount = 0x20;
- cmdIf.CmdIndex = CMD9_SEND_CSD;
- cmdIf.Argument = CmdArgument;
- cmdIf.ExpectResp = EXPECT_LONG_RESP;
- cmdIf.AllowTimeout = ALLOW_CMD_TIMER;
- cmdIf.CmdResp = (uint32_t *)&respValue[0];
- while ( retryCount > 0 )
- {
- /* Check current status */
- if(((MCI_CheckStatus(CARD_STATE_STBY) != MCI_FUNC_OK)))
- return MCI_FUNC_ERR_STATE;
-
- respStatus = MCI_CmdResp(&cmdIf);
-
- if ( !respStatus )
- {
- if(csdVal != NULL)
- {
- csdVal[0] = respValue[0];
- csdVal[1] = respValue[1];
- csdVal[2] = respValue[2];
- csdVal[3] = respValue[3];
- }
-
- return (MCI_FUNC_OK);
- }
-
- for ( i = 0; i < 0x20; i++ );
-
- retryCount--;
- }
-
- return (MCI_FUNC_FAILED);
-}
-
-
-/************************************************************************//**
- * @brief Select the card by the specified address. This is done by sending
- * out the CMD7 with the address argument to needed card
- *
- * @param None
- *
- * @return MCI_FUNC_OK if all success
- *
- * @note CMD7 (SELECT_CARD) command should be sent after CMD9 ((SEND_CSD).
- * The state will be inter-changed between STBY to TRANS by this
- * CMD7 command
- ****************************************************************************/
-int32_t MCI_Cmd_SelectCard( void )
-{
- volatile uint32_t i;
- uint32_t retryCount;
- uint32_t respStatus;
- uint32_t respValue[4];
- uint32_t CmdArgument;
- st_Mci_CmdInfo cmdIf;
- int32_t retval = MCI_FUNC_FAILED;
-
- if ((MCI_CardType == MCI_SDSC_V1_CARD) ||
- (MCI_CardType == MCI_SDSC_V2_CARD) ||
- (MCI_CardType == MCI_SDHC_SDXC_CARD))
- {
- CmdArgument = CardRCA;
- }
- else /* if MMC or unknown card type, use default RCA addr. */
- {
- CmdArgument = 0x00010000;
- }
-
- retryCount = 0x20;
- cmdIf.CmdIndex = CMD7_SELECT_CARD;
- cmdIf.Argument = CmdArgument;
- cmdIf.ExpectResp = EXPECT_SHORT_RESP;
- cmdIf.AllowTimeout = ALLOW_CMD_TIMER;
- cmdIf.CmdResp = (uint32_t *)&respValue[0];
- while ( retryCount > 0 )
- {
- /* Check current status */
- if(((MCI_CheckStatus(CARD_STATE_STBY) != MCI_FUNC_OK)) &&
- (MCI_CheckStatus(CARD_STATE_TRAN) != MCI_FUNC_OK) &&
- (MCI_CheckStatus(CARD_STATE_DATA) != MCI_FUNC_OK) &&
- (MCI_CheckStatus(CARD_STATE_PRG) != MCI_FUNC_OK) &&
- (MCI_CheckStatus(CARD_STATE_DIS) != MCI_FUNC_OK))
- return MCI_FUNC_ERR_STATE;
-
- respStatus = MCI_CmdResp(&cmdIf);
-
- if(respStatus)
- {
- retval = MCI_FUNC_FAILED;
- }
- else if (respValue[0] & CARD_STATUS_ERR_MASK)
- {
- return MCI_FUNC_BAD_PARAMETERS;
- }
- else
- {
- if(((MCI_CheckStatus(CARD_STATE_STBY) != MCI_FUNC_OK)) &&
- (MCI_CheckStatus(CARD_STATE_TRAN) != MCI_FUNC_OK) &&
- (MCI_CheckStatus(CARD_STATE_PRG) != MCI_FUNC_OK) &&
- (MCI_CheckStatus(CARD_STATE_DIS) != MCI_FUNC_OK))
- return MCI_FUNC_ERR_STATE;
- return MCI_FUNC_OK;
- }
-
- for ( i = 0; i < 0x20; i++ );
-
- retryCount--;
- }
-
- return retval;
-}
-
-
-/************************************************************************//**
- * @brief Get the status of the card. The return is from the card.
- * By sending CMD13 (SEND_STATUS), the status of the card
- * will be responded from card addressed
- *
- * @param[out] cardStatus the status returned from the card
- *
- * @return MCI_FUNC_OK if all success
- ****************************************************************************/
-int32_t MCI_GetCardStatus(int32_t* cardStatus)
-{
- volatile uint32_t i;
- uint32_t retryCount;
- uint32_t respStatus;
- uint32_t respValue[4];
- uint32_t CmdArgument;
- st_Mci_CmdInfo cmdIf;
- int32_t retval = MCI_FUNC_FAILED;
-
- if(cardStatus == NULL)
- return MCI_FUNC_OK;
-
- if ((MCI_CardType == MCI_SDSC_V1_CARD) ||
- (MCI_CardType == MCI_SDSC_V2_CARD) ||
- (MCI_CardType == MCI_SDHC_SDXC_CARD))
- {
- CmdArgument = CardRCA;
- }
- else /* if MMC or unknown card type, use default RCA addr. */
- {
- CmdArgument = 0x00010000;
- }
-
- retryCount = 0x20;
- cmdIf.CmdIndex = CMD13_SEND_STATUS;
- cmdIf.Argument = CmdArgument;
- cmdIf.ExpectResp = EXPECT_SHORT_RESP;
- cmdIf.AllowTimeout = ALLOW_CMD_TIMER;
- cmdIf.CmdResp = (uint32_t *)&respValue[0];
- while ( retryCount > 0 )
- {
- respStatus = MCI_CmdResp(&cmdIf);
-
- if(respStatus) /* only retry if sending command failed */
- {
- retval = MCI_FUNC_FAILED;
- }
- else
- {
- *cardStatus = respValue[0];
-
- return MCI_FUNC_OK;
- }
-
- retryCount--;
- for ( i = 0; i < 0x10; i++ );
- }
-
- return retval;
-}
-
-/************************************************************************//**
- * @brief Set the length for the blocks in the next action on data
- * manipulation (as read, write, erase). This function is to
- * send CMD16 (SET_BLOCK_LEN) to cards.
- *
- * @param[in] blockLength the value for the length of block will be handled
- *
- * @return MCI_FUNC_OK if all success
- *
- * @note CMD16 command should be sent after the card is selected by CMD7
- * (SELECT_CARD).
- * In the case of SDHC and SDXC Cards, block length set by CMD16 command doen't
- * affect memory read and write commands. Always 512 Bytes fixed block length is
- * used. This command is effective for LOCK_UNLOCK command..
- ****************************************************************************/
-int32_t MCI_SetBlockLen(uint32_t blockLength)
-{
- volatile uint32_t i;
- uint32_t retryCount;
- uint32_t respStatus;
- uint32_t respValue[4];
- st_Mci_CmdInfo cmdIf;
- int32_t retval = MCI_FUNC_FAILED;
-
- retryCount = 0x20;
- cmdIf.CmdIndex = CMD16_SET_BLOCK_LEN;
- cmdIf.Argument = blockLength;
- cmdIf.ExpectResp = EXPECT_SHORT_RESP;
- cmdIf.AllowTimeout = ALLOW_CMD_TIMER;
- cmdIf.CmdResp = (uint32_t *)&respValue[0];
- while ( retryCount > 0 )
- {
- /* Check current status */
- if((MCI_CheckStatus(CARD_STATE_TRAN) != MCI_FUNC_OK) )
- return MCI_FUNC_ERR_STATE;
-
- respStatus = MCI_CmdResp(&cmdIf);
-
- if(respStatus)
- {
- retval = MCI_FUNC_FAILED;
- }
- else if (respValue[0] & CARD_STATUS_ERR_MASK)
- {
- return MCI_FUNC_BAD_PARAMETERS;
- }
- else
- {
- return MCI_CheckStatus(CARD_STATE_TRAN);
- }
-
-
- for ( i = 0; i < 0x20; i++ );
-
- retryCount--;
- }
-
- return retval;
-}
-
-
-/************************************************************************//**
- * @brief Set bus-width (1 bit or 4 bit) to work with the card by command
- * CMD6 (SET_ACMD_BUS_WIDTH).
- *
- * @param[in] buswidth The value represented for bus-width
- * - 0b00: 1-bit bus-width
- * - 0b10: 4-bit bus-width
- *
- * @return MCI_FUNC_OK if all success
- *
- * @note
- * - If SD card is currently in used, it's possible to enable 4-bit
- * bus-width instead of 1-bit to speed up.
- * - This command can only be transferred during TRANS state.
- * - Since, it's a ACMD, CMD55 (APP_CMD) needs to be sent out first
- ****************************************************************************/
-int32_t MCI_Acmd_SendBusWidth( uint32_t buswidth )
-{
- volatile uint32_t i;
- uint32_t retryCount;
- uint32_t respStatus;
- uint32_t respValue[4];
- st_Mci_CmdInfo cmdIf;
- int32_t retval = MCI_FUNC_FAILED;
-
- retryCount = 0x20; /* reset retry counter */
- cmdIf.CmdIndex = ACMD6_SET_BUS_WIDTH;
- cmdIf.Argument = buswidth;
- cmdIf.ExpectResp = EXPECT_SHORT_RESP;
- cmdIf.AllowTimeout = ALLOW_CMD_TIMER;
- cmdIf.CmdResp = (uint32_t *)&respValue[0];
- while ( retryCount > 0 )
- {
- /* The card must be in tran state in order to change the bus width */
- retval = MCI_CheckStatus(CARD_STATE_TRAN);
- if(retval!= MCI_FUNC_OK)
- return retval;
-
- if (MCI_Cmd_SendACMD() == MCI_FUNC_OK)
- {
- respStatus = MCI_CmdResp(&cmdIf);
-
- if(respStatus)
- {
- retval = MCI_FUNC_FAILED;
- }
- else if (respValue[0] & CARD_STATUS_ERR_MASK)
- {
- return MCI_FUNC_BAD_PARAMETERS;
- }
- else
- {
- return MCI_CheckStatus(CARD_STATE_TRAN);
- }
- }
-
- for ( i = 0; i < 0x20; i++ );
-
- retryCount--;
- }
-
- return retval;
-}
-
-
-/************************************************************************//**
- * @brief Get the state of data transfer to see if it is ended or not
- *
- * @param None
- *
- * @return Transfer state (stored by Mci_Data_Xfer_End variable)
- ****************************************************************************/
-uint32_t MCI_GetDataXferEndState(void)
-{
- return Mci_Data_Xfer_End;
-}
-/************************************************************************//**
- * @brief Get the error state of the lastest data transfer
- *
- * @param None
- *
- * @return Error state (stored by Mci_Data_Xfer_ERR variable)
- ****************************************************************************/
-uint32_t MCI_GetXferErrState(void)
-{
- return Mci_Data_Xfer_ERR;
-}
-
-/************************************************************************//**
- * @brief Stop the current transmission on the bus by sending command CMD12
- * (STOP_TRANSMISSION). In this case, the card may be in a unknown
- * state. So that it need a warm reset for normal operation.
- *
- * @param[in] None
- *
- * @return MCI_FUNC_OK if all success
- ****************************************************************************/
-int32_t MCI_Cmd_StopTransmission( void )
-{
- volatile uint32_t i;
- uint32_t retryCount;
- uint32_t respStatus;
- uint32_t respValue[4];
- st_Mci_CmdInfo cmdIf;
- int32_t retval = MCI_FUNC_FAILED;
-
- /* do nothing when the card is in tran state */
- if(MCI_CheckStatus(CARD_STATE_TRAN) == MCI_FUNC_OK)
- {
- return MCI_FUNC_OK;
- }
-
- retryCount = 0x20;
- cmdIf.CmdIndex = CMD12_STOP_TRANSMISSION;
- cmdIf.Argument = 0x00000000;
- cmdIf.ExpectResp = EXPECT_SHORT_RESP;
- cmdIf.AllowTimeout = ALLOW_CMD_TIMER;
- cmdIf.CmdResp = (uint32_t *)&respValue[0];
- while ( retryCount > 0 )
- {
- /* Check current status */
- if((MCI_CheckStatus(CARD_STATE_DATA) != MCI_FUNC_OK) &&
- (MCI_CheckStatus(CARD_STATE_RCV) != MCI_FUNC_OK))
- return MCI_FUNC_ERR_STATE;
-
- respStatus = MCI_CmdResp(&cmdIf);
-
- if(respStatus)
- {
- retval = MCI_FUNC_FAILED;
- }
- else if (respValue[0] & CARD_STATUS_ERR_MASK)
- {
- return MCI_FUNC_BAD_PARAMETERS;
- }
- else
- {
- if((MCI_CheckStatus(CARD_STATE_PRG) != MCI_FUNC_OK) &&
- (MCI_CheckStatus(CARD_STATE_TRAN) != MCI_FUNC_OK))
- return MCI_FUNC_ERR_STATE;
- return MCI_FUNC_OK;
- }
-
- for ( i = 0; i < 0x20; i++ );
-
- retryCount--;
- }
-
- return retval;
-}
-
-
-/************************************************************************//**
- * @brief Write blocks to card by sending command CMD24 (WRITE_BLOCK) or
- * command CMD25 (WRITE_MULTIPLE_BLOCK) followed by the blocks of
- * data to be written.
- *
- * @param[in] blockNum The block number to start writting
- *
- * @param[in] numOfBlock Determine how many blocks will be written (from the
- * starting block)
- *
- * @return MCI_FUNC_OK if all success
- *
- * @note These commands should be sent in TRANS state.
- ****************************************************************************/
-int32_t MCI_Cmd_WriteBlock(uint32_t blockNum, uint32_t numOfBlock)
-{
- volatile uint32_t i;
- uint32_t retryCount;
- uint32_t respStatus;
- uint32_t respValue[4];
- st_Mci_CmdInfo cmdIf;
- uint32_t commandID;
-
- int32_t retval = MCI_FUNC_FAILED;
-
- if (numOfBlock > 1)
- {
- commandID = CMD25_WRITE_MULTIPLE_BLOCK;
- }
- else
- {
- commandID = CMD24_WRITE_BLOCK;
- }
-
- retryCount = 0x20;
- cmdIf.CmdIndex = commandID;
- if (MCI_CardType == MCI_SDHC_SDXC_CARD)
- {
- cmdIf.Argument = blockNum; /* Block Address */
- }
- else
- {
- cmdIf.Argument = blockNum * BLOCK_LENGTH; /* Byte Address */
- }
- cmdIf.ExpectResp = EXPECT_SHORT_RESP;
- cmdIf.AllowTimeout = ALLOW_CMD_TIMER;
- cmdIf.CmdResp = (uint32_t *)&respValue[0];
-
- while ( retryCount > 0 )
- {
- /* Check current status */
- if((MCI_CheckStatus(CARD_STATE_TRAN) != MCI_FUNC_OK))
- return MCI_FUNC_ERR_STATE;
-
- respStatus = MCI_CmdResp(&cmdIf);
-
- if(respStatus)
- {
- retval = MCI_FUNC_FAILED;
- }
- else if (respValue[0] & CARD_STATUS_ERR_MASK)
- {
- return MCI_FUNC_BAD_PARAMETERS;
- }
- else
- {
- if((MCI_CheckStatus(CARD_STATE_RCV) != MCI_FUNC_OK) &&
- (MCI_CheckStatus(CARD_STATE_TRAN) != MCI_FUNC_OK))
- return MCI_FUNC_ERR_STATE;
- return MCI_FUNC_OK;
- }
-
-
- for ( i = 0; i < 0x20; i++ );
-
- retryCount--;
-
- }
-
- return retval; /* Fatal error */
-}
-
-
-
-
-/************************************************************************//**
- * @brief Read blocks to card by sending CMD17 (READ_SINGLE_BLOCK) or
- * CMD18 (READ_MULTIPLE_BLOCK) commands followed by the blocks of
- * data to be read.
- *
- * @param[in] blockNum The block number to start reading
- *
- * @param[in] numOfBlock Determine how many blocks will be read (from the
- * starting block)
- *
- * @return MCI_FUNC_OK if all success
- *
- * @note These commands should be sent in TRANS state.
- ****************************************************************************/
-int32_t MCI_Cmd_ReadBlock(uint32_t blockNum, uint32_t numOfBlock)
-{
- volatile uint32_t i;
- uint32_t retryCount;
- uint32_t respStatus;
- uint32_t respValue[4];
- uint32_t commandID;
- st_Mci_CmdInfo cmdIf;
- int32_t retval = MCI_FUNC_FAILED;
-
- // To Do: Read Multi-Block
- if (numOfBlock > 1)
- commandID = CMD18_READ_MULTIPLE_BLOCK;
- else
- commandID = CMD17_READ_SINGLE_BLOCK;
-
- retryCount = 0x20;
- cmdIf.CmdIndex = commandID;
- if (MCI_CardType == MCI_SDHC_SDXC_CARD)
- {
- cmdIf.Argument = blockNum; /* Block Address */
- }
- else
- {
- cmdIf.Argument = blockNum * BLOCK_LENGTH; /* Byte Address */
- }
- cmdIf.ExpectResp = EXPECT_SHORT_RESP;
- cmdIf.AllowTimeout = ALLOW_CMD_TIMER;
- cmdIf.CmdResp = (uint32_t *)&respValue[0];
- while ( retryCount > 0 )
- {
- /* Check current status */
- if((MCI_CheckStatus(CARD_STATE_TRAN) != MCI_FUNC_OK))
- return MCI_FUNC_ERR_STATE;
-
- respStatus = MCI_CmdResp(&cmdIf);
-
- if(respStatus)
- {
- retval = MCI_FUNC_FAILED;
- }
- else if (respValue[0] & CARD_STATUS_ERR_MASK)
- {
- return MCI_FUNC_BAD_PARAMETERS;
- }
- else
- {
- if((MCI_CheckStatus(CARD_STATE_DATA) != MCI_FUNC_OK) &&
- (MCI_CheckStatus(CARD_STATE_TRAN) != MCI_FUNC_OK))
- return MCI_FUNC_ERR_STATE;
- return MCI_FUNC_OK;
- }
-
-
- for ( i = 0; i < 0x20; i++ );
-
- retryCount--;
-
- }
-
- return retval;
-}
-
-
-/************************************************************************//**
- * @brief Write data at a specific address to starting block with number
- * of blocks will be written from first block
- * @details
- * - At preparation
- * - Set MCI data control register, data length and data timeout
- * - Send CMD24 (WRITE_BLOCK) or CMD25 (WRITE_MULTIPLE_BLOCK)
- * commands to card
- * - Enable interupt for MCI component
- * - At completion
- * - TX_ACTIVE interrupt is occured
- * - Write data to FIFO register continuously until the data block
- * length is reached
- *
- * @param[in] *memblock The pointer to location stored required data to be
- * written to card
- *
- * @param[in] blockNum The block number to start writting
- *
- * @param[in] numOfBlock Determine how many blocks will be written (from the
- * starting block)
- *
- * @return MCI_FUNC_OK if all success
- ****************************************************************************/
-int32_t MCI_WriteBlock(volatile uint8_t* memblock, uint32_t blockNum, uint32_t numOfBlock)
-{
- volatile uint32_t i;
- uint32_t DataCtrl = 0;
-
- if(BLOCK_LENGTH*numOfBlock > DATA_RW_MAX_LEN)
- return MCI_FUNC_BAD_PARAMETERS;
-
- dataSrcBlock = memblock;
-
- LPC_MCI->CLEAR = 0x7FF;
-
- LPC_MCI->DATACTRL = 0;
-
- for ( i = 0; i < 0x10; i++ );
-
- /* Wait the SD Card enters to TRANS state. */
- if (MCI_CheckStatus(CARD_STATE_TRAN) != MCI_FUNC_OK)
- return MCI_FUNC_ERR_STATE;
-
- LPC_MCI->DATATMR = DATA_TIMER_VALUE_W;
-
- LPC_MCI->DATALEN = BLOCK_LENGTH*numOfBlock;
-
- Mci_Data_Xfer_End = 1;
- Mci_Data_Xfer_ERR = 0;
- fifo_plane = 0;
-
- txBlockCnt = 0;
-
- MCI_TXEnable();
-
- if (MCI_Cmd_WriteBlock(blockNum, numOfBlock) != MCI_FUNC_OK)
- {
- return ( MCI_FUNC_FAILED );
- }
-
- //for(blockCnt = 0; blockCnt < numOfBlock; blockCnt++)
- {
-#if MCI_DMA_ENABLED
- MCI_SettingDma((uint8_t*) dataSrcBlock, MCI_DMA_WRITE_CHANNEL, GPDMA_TRANSFERTYPE_M2P_DEST_CTRL);
-
- /* Write, block transfer, DMA, and data length */
- DataCtrl |= MCI_DATACTRL_ENABLE | MCI_DATACTRL_DIR_TO_CARD
- | MCI_DATACTRL_DMA_ENABLE | MCI_DTATCTRL_BLOCKSIZE(DATA_BLOCK_LEN);
-#else
- /* Write, block transfer, and data length */
- DataCtrl |= MCI_DATACTRL_ENABLE | MCI_DATACTRL_DIR_TO_CARD | MCI_DTATCTRL_BLOCKSIZE(DATA_BLOCK_LEN);
-#endif
- }
-
- LPC_MCI->DATACTRL = DataCtrl;
-
- for ( i = 0; i < 0x10; i++ );
-
- return MCI_FUNC_OK;
-}
-
-
-/************************************************************************//**
- * @brief Read data at a specific address to starting block with number
- * of blocks will be read from first block
- *
- * @details
- * - At preparation
- * - Set MCI data control register, data length and data timeout
- * - Send CMD17 (READ_SINGLE_BLOCK) or CMD18 (READ_MULTIPLE_BLOCK)
- * commands to card
- * - Enable interupt for MCI component
- * - At completion
- * - RX_ACTIVE interrupt is occured
- * - Read data from FIFO register continuously until the data block
- * length is reached to retrieve needed data
- *
- * @param[in] *destBlock The pointer to location will captured data read
- * from card
- *
- * @param[in] blockNum The block number to start reading
- *
- * @param[in] numOfBlock Determine how many blocks will be read (from the
- * starting block)
- *
- * @return MCI_FUNC_OK if all success
- ****************************************************************************/
-int32_t MCI_ReadBlock(volatile uint8_t* destBlock, uint32_t blockNum, uint32_t numOfBlock)
-{
- volatile uint32_t i;
- uint32_t DataCtrl = 0;
-
- if(BLOCK_LENGTH*numOfBlock > DATA_RW_MAX_LEN)
- return MCI_FUNC_BAD_PARAMETERS;
-
- dataDestBlock = destBlock;
-
- LPC_MCI->CLEAR = 0x7FF;
-
- LPC_MCI->DATACTRL = 0;
-
- for ( i = 0; i < 0x10; i++ );
-
- /* Wait the SD Card enters to TRANS state. */
- if (MCI_CheckStatus(CARD_STATE_TRAN) != MCI_FUNC_OK)
- return MCI_FUNC_ERR_STATE;
-
- MCI_RXEnable();
-
- LPC_MCI->DATATMR = DATA_TIMER_VALUE_R;
-
- LPC_MCI->DATALEN = BLOCK_LENGTH*numOfBlock;
-
- Mci_Data_Xfer_End = 1;
- Mci_Data_Xfer_ERR = 0;
- rxBlockCnt = 0;
- fifo_plane = 0;
-
-
- // Start data engine on READ before command to avoid overflow of the FIFO.
- {
-#if MCI_DMA_ENABLED
- MCI_SettingDma((uint8_t*) dataDestBlock, MCI_DMA_READ_CHANNEL, GPDMA_TRANSFERTYPE_P2M_SRC_CTRL);
-
- /* Write, block transfer, DMA, and data length */
- DataCtrl |= MCI_DATACTRL_ENABLE | MCI_DATACTRL_DIR_FROM_CARD
- | MCI_DATACTRL_DMA_ENABLE | MCI_DTATCTRL_BLOCKSIZE(DATA_BLOCK_LEN);
-#else
- //Retrieving the result after reading the card is done by the FIFO handling for interrupt
-
- /* Read, enable, block transfer, and data length */
- DataCtrl |= MCI_DATACTRL_ENABLE | MCI_DATACTRL_DIR_FROM_CARD | MCI_DTATCTRL_BLOCKSIZE(DATA_BLOCK_LEN);
-
-#endif
- }
-
- LPC_MCI->DATACTRL = DataCtrl;
-
- for ( i = 0; i < 0x10; i++ );
-
- if ( MCI_Cmd_ReadBlock(blockNum, numOfBlock) != MCI_FUNC_OK )
- {
- return MCI_FUNC_FAILED;
- }
-
- return MCI_FUNC_OK;
-}
-
-
-/************************************************************************//**
- * @brief Turn off the MCI power by disabling the Power Register for MCI
- *
- * @param None
- *
- * @return None
- ****************************************************************************/
-void MCI_PowerOff(void)
-{
- volatile uint32_t i;
-
- LPC_MCI->POWER = 0;
-
- for (i = 0; i < 0x100; i++);
-
- return;
-}
-
-
-/**
- * @}
- */
-
-#endif /*_MCI*/
-
-/*****************************************************************************
-** End Of File
-******************************************************************************/
diff --git a/bsp/lpc408x/Libraries/Drivers/source/lpc_mcpwm.c b/bsp/lpc408x/Libraries/Drivers/source/lpc_mcpwm.c
deleted file mode 100644
index 479ec4d9a4..0000000000
--- a/bsp/lpc408x/Libraries/Drivers/source/lpc_mcpwm.c
+++ /dev/null
@@ -1,573 +0,0 @@
-/**********************************************************************
-* $Id$ lpc_mcpwm.c 2011-06-02
-*//**
-* @file lpc_mcpwm.c
-* @brief Contains all functions support for Motor Control PWM
-* firmware library on LPC
-* @version 1.0
-* @date 02. June. 2011
-* @author NXP MCU SW Application Team
-*
-* Copyright(C) 2011, NXP Semiconductor
-* All rights reserved.
-*
-***********************************************************************
-* Software that is described herein is for illustrative purposes only
-* which provides customers with programming information regarding the
-* products. This software is supplied "AS IS" without any warranties.
-* NXP Semiconductors assumes no responsibility or liability for the
-* use of the software, conveys no license or title under any patent,
-* copyright, or mask work right to the product. NXP Semiconductors
-* reserves the right to make changes in the software without
-* notification. NXP Semiconductors also make 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'
-* relevant copyright 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.
-**********************************************************************/
-
-
-/* Peripheral group ----------------------------------------------------------- */
-/** @addtogroup MCPWM
- * @{
- */
-#ifdef __BUILD_WITH_EXAMPLE__
-#include "lpc_libcfg.h"
-#else
-#include "lpc_libcfg_default.h"
-#endif /* __BUILD_WITH_EXAMPLE__ */
-#ifdef _MCPWM
-
-/* Includes ------------------------------------------------------------------- */
-#include "lpc_mcpwm.h"
-#include "lpc_clkpwr.h"
-
-/* Public Functions ----------------------------------------------------------- */
-/** @addtogroup MCPWM_Public_Functions
- * @{
- */
-
-/*********************************************************************//**
- * @brief Initializes the MCPWM peripheral
- * @param[in] MCPWMx Motor Control PWM peripheral selected,
- * Should be: LPC_MCPWM
- * @return None
- **********************************************************************/
-void MCPWM_Init(LPC_MCPWM_TypeDef *MCPWMx)
-{
- /* Turn On MCPWM PCLK */
- CLKPWR_ConfigPPWR(CLKPWR_PCONP_PCMCPWM, ENABLE);
-
- MCPWMx->CAP_CLR = MCPWM_CAPCLR_CAP(0) | MCPWM_CAPCLR_CAP(1) | MCPWM_CAPCLR_CAP(2);
-
- MCPWMx->INTF_CLR = MCPWM_INT_ILIM(0) | MCPWM_INT_ILIM(1) | MCPWM_INT_ILIM(2) \
- | MCPWM_INT_IMAT(0) | MCPWM_INT_IMAT(1) | MCPWM_INT_IMAT(2) \
- | MCPWM_INT_ICAP(0) | MCPWM_INT_ICAP(1) | MCPWM_INT_ICAP(2);
-
- MCPWMx->INTEN_CLR = MCPWM_INT_ILIM(0) | MCPWM_INT_ILIM(1) | MCPWM_INT_ILIM(2) \
- | MCPWM_INT_IMAT(0) | MCPWM_INT_IMAT(1) | MCPWM_INT_IMAT(2) \
- | MCPWM_INT_ICAP(0) | MCPWM_INT_ICAP(1) | MCPWM_INT_ICAP(2);
-}
-
-
-/*********************************************************************//**
- * @brief Configures each channel in MCPWM peripheral according to the
- * specified parameters in the MCPWM_CHANNEL_CFG_Type.
- * @param[in] MCPWMx Motor Control PWM peripheral selected
- * should be: LPC_MCPWM
- * @param[in] channelNum Channel number, should be: 0..2.
- * @param[in] channelSetup Pointer to a MCPWM_CHANNEL_CFG_Type structure
-* that contains the configuration information for the
-* specified MCPWM channel.
- * @return None
- **********************************************************************/
-void MCPWM_ConfigChannel(LPC_MCPWM_TypeDef *MCPWMx, uint32_t channelNum,
- MCPWM_CHANNEL_CFG_Type * channelSetup)
-{
- if (channelNum < MCPWM_MAX_CHANNEL)
- {
- if (channelNum == MCPWM_CHANNEL_0)
- {
- MCPWMx->TC0 = channelSetup->channelTimercounterValue;
- MCPWMx->LIM0 = channelSetup->channelPeriodValue;
- MCPWMx->MAT0 = channelSetup->channelPulsewidthValue;
- }
- else if (channelNum == MCPWM_CHANNEL_1)
- {
- MCPWMx->TC1 = channelSetup->channelTimercounterValue;
- MCPWMx->LIM1 = channelSetup->channelPeriodValue;
- MCPWMx->MAT1 = channelSetup->channelPulsewidthValue;
- }
- else if (channelNum == MCPWM_CHANNEL_2)
- {
- MCPWMx->TC2 = channelSetup->channelTimercounterValue;
- MCPWMx->LIM2 = channelSetup->channelPeriodValue;
- MCPWMx->MAT2 = channelSetup->channelPulsewidthValue;
- }
- else
- {
- return;
- }
-
- if (channelSetup->channelType == MCPWM_CHANNEL_CENTER_MODE)
- {
- MCPWMx->CON_SET = MCPWM_CON_CENTER(channelNum);
- }
- else
- {
- MCPWMx->CON_CLR = MCPWM_CON_CENTER(channelNum);
- }
-
- if (channelSetup->channelPolarity == MCPWM_CHANNEL_PASSIVE_HI)
- {
- MCPWMx->CON_SET = MCPWM_CON_POLAR(channelNum);
- }
- else
- {
- MCPWMx->CON_CLR = MCPWM_CON_POLAR(channelNum);
- }
-
- if (channelSetup->channelDeadtimeEnable == ENABLE)
- {
- MCPWMx->CON_SET = MCPWM_CON_DTE(channelNum);
-
- MCPWMx->DT &= ~(MCPWM_DT(channelNum, 0x3FF));
-
- MCPWMx->DT |= MCPWM_DT(channelNum, channelSetup->channelDeadtimeValue);
- }
- else
- {
- MCPWMx->CON_CLR = MCPWM_CON_DTE(channelNum);
- }
-
- if (channelSetup->channelUpdateEnable == ENABLE)
- {
- MCPWMx->CON_CLR = MCPWM_CON_DISUP(channelNum);
- }
- else
- {
- MCPWMx->CON_SET = MCPWM_CON_DISUP(channelNum);
- }
- }
-}
-
-
-/*********************************************************************//**
- * @brief Write to MCPWM shadow registers - Update the value for period
- * and pulse width in MCPWM peripheral.
- * @param[in] MCPWMx Motor Control PWM peripheral selected
- * Should be: LPC_MCPWM
- * @param[in] channelNum Channel Number, should be: 0..2.
- * @param[in] channelSetup Pointer to a MCPWM_CHANNEL_CFG_Type structure
-* that contains the configuration information for the
-* specified MCPWM channel.
- * @return None
- **********************************************************************/
-void MCPWM_WriteToShadow(LPC_MCPWM_TypeDef *MCPWMx, uint32_t channelNum,
- MCPWM_CHANNEL_CFG_Type *channelSetup)
-{
- if (channelNum == MCPWM_CHANNEL_0)
- {
- MCPWMx->LIM0 = channelSetup->channelPeriodValue;
- MCPWMx->MAT0 = channelSetup->channelPulsewidthValue;
- }
- else if (channelNum == MCPWM_CHANNEL_1)
- {
- MCPWMx->LIM1 = channelSetup->channelPeriodValue;
- MCPWMx->MAT1 = channelSetup->channelPulsewidthValue;
- }
- else if (channelNum == MCPWM_CHANNEL_2)
- {
- MCPWMx->LIM2 = channelSetup->channelPeriodValue;
- MCPWMx->MAT2 = channelSetup->channelPulsewidthValue;
- }
-}
-
-
-
-/*********************************************************************//**
- * @brief Configures capture function in MCPWM peripheral
- * @param[in] MCPWMx Motor Control PWM peripheral selected
- * Should be: LPC_MCPWM
- * @param[in] channelNum MCI (Motor Control Input pin) number
- * Should be: 0..2
- * @param[in] captureConfig Pointer to a MCPWM_CAPTURE_CFG_Type structure
-* that contains the configuration information for the
-* specified MCPWM capture.
- * @return
- **********************************************************************/
-void MCPWM_ConfigCapture(LPC_MCPWM_TypeDef *MCPWMx, uint32_t channelNum,
- MCPWM_CAPTURE_CFG_Type *captureConfig)
-{
- if (channelNum < MCPWM_MAX_CHANNEL)
- {
-
- if (captureConfig->captureFalling == ENABLE)
- {
- MCPWMx->CAPCON_SET = MCPWM_CAPCON_CAPMCI_FE(captureConfig->captureChannel, channelNum);
- }
- else
- {
- MCPWMx->CAPCON_CLR = MCPWM_CAPCON_CAPMCI_FE(captureConfig->captureChannel, channelNum);
- }
-
- if (captureConfig->captureRising == ENABLE)
- {
- MCPWMx->CAPCON_SET = MCPWM_CAPCON_CAPMCI_RE(captureConfig->captureChannel, channelNum);
- }
- else
- {
- MCPWMx->CAPCON_CLR = MCPWM_CAPCON_CAPMCI_RE(captureConfig->captureChannel, channelNum);
- }
-
- if (captureConfig->timerReset == ENABLE)
- {
- MCPWMx->CAPCON_SET = MCPWM_CAPCON_RT(captureConfig->captureChannel);
- }
- else
- {
- MCPWMx->CAPCON_CLR = MCPWM_CAPCON_RT(captureConfig->captureChannel);
- }
-
- if (captureConfig->hnfEnable == ENABLE)
- {
- MCPWMx->CAPCON_SET = MCPWM_CAPCON_HNFCAP(channelNum);
- }
- else
- {
- MCPWMx->CAPCON_CLR = MCPWM_CAPCON_HNFCAP(channelNum);
- }
- }
-}
-
-
-/*********************************************************************//**
- * @brief Clears current captured value in specified capture channel
- * @param[in] MCPWMx Motor Control PWM peripheral selected
- * Should be: LPC_MCPWM
- * @param[in] captureChannel Capture channel number, should be: 0..2
- * @return None
- **********************************************************************/
-void MCPWM_ClearCapture(LPC_MCPWM_TypeDef *MCPWMx, uint32_t captureChannel)
-{
- MCPWMx->CAP_CLR = MCPWM_CAPCLR_CAP(captureChannel);
-}
-
-/*********************************************************************//**
- * @brief Get current captured value in specified capture channel
- * @param[in] MCPWMx Motor Control PWM peripheral selected,
- * Should be: LPC_MCPWM
- * @param[in] captureChannel Capture channel number, should be: 0..2
- * @return None
- **********************************************************************/
-uint32_t MCPWM_GetCapture(LPC_MCPWM_TypeDef *MCPWMx, uint32_t captureChannel)
-{
- if (captureChannel == MCPWM_CHANNEL_0)
- {
- return (MCPWMx->CAP0);
- }
- else if (captureChannel == MCPWM_CHANNEL_1)
- {
- return (MCPWMx->CAP1);
- }
- else if (captureChannel == MCPWM_CHANNEL_2)
- {
- return (MCPWMx->CAP2);
- }
- return (0);
-}
-
-
-/*********************************************************************//**
- * @brief Configures Count control in MCPWM peripheral
- * @param[in] MCPWMx Motor Control PWM peripheral selected
- * Should be: LPC_MCPWM
- * @param[in] channelNum Channel number, should be: 0..2
- * @param[in] countMode Count mode, should be:
- * - ENABLE: Enables count mode.
- * - DISABLE: Disable count mode, the channel is in timer mode.
- * @param[in] countConfig Pointer to a MCPWM_COUNT_CFG_Type structure
-* that contains the configuration information for the
-* specified MCPWM count control.
- * @return None
- **********************************************************************/
-void MCPWM_CountConfig(LPC_MCPWM_TypeDef *MCPWMx, uint32_t channelNum,
- uint32_t countMode, MCPWM_COUNT_CFG_Type *countConfig)
-{
- if (channelNum < MCPWM_MAX_CHANNEL)
- {
- if (countMode == ENABLE)
- {
- MCPWMx->CNTCON_SET = MCPWM_CNTCON_CNTR(channelNum);
-
- if (countConfig->countFalling == ENABLE)
- {
- MCPWMx->CNTCON_SET = MCPWM_CNTCON_TCMCI_FE(countConfig->counterChannel,channelNum);
- }
- else
- {
- MCPWMx->CNTCON_CLR = MCPWM_CNTCON_TCMCI_FE(countConfig->counterChannel,channelNum);
- }
-
- if (countConfig->countRising == ENABLE)
- {
- MCPWMx->CNTCON_SET = MCPWM_CNTCON_TCMCI_RE(countConfig->counterChannel,channelNum);
- }
- else
- {
- MCPWMx->CNTCON_CLR = MCPWM_CNTCON_TCMCI_RE(countConfig->counterChannel,channelNum);
- }
- }
- else
- {
- MCPWMx->CNTCON_CLR = MCPWM_CNTCON_CNTR(channelNum);
- }
- }
-}
-
-
-/*********************************************************************//**
- * @brief Start MCPWM activity for each MCPWM channel
- * @param[in] MCPWMx Motor Control PWM peripheral selected
- * Should be: LPC_MCPWM
- * @param[in] channel0 State of this command on channel 0:
- * - ENABLE: 'Start' command will effect on channel 0
- * - DISABLE: 'Start' command will not effect on channel 0
- * @param[in] channel1 State of this command on channel 1:
- * - ENABLE: 'Start' command will effect on channel 1
- * - DISABLE: 'Start' command will not effect on channel 1
- * @param[in] channel2 State of this command on channel 2:
- * - ENABLE: 'Start' command will effect on channel 2
- * - DISABLE: 'Start' command will not effect on channel 2
- * @return None
- **********************************************************************/
-void MCPWM_Start(LPC_MCPWM_TypeDef *MCPWMx, uint32_t channel0,
- uint32_t channel1, uint32_t channel2)
-{
- uint32_t regVal = 0;
-
- regVal = (channel0 ? MCPWM_CON_RUN(0) : 0) | (channel1 ? MCPWM_CON_RUN(1) : 0) \
- | (channel2 ? MCPWM_CON_RUN(2) : 0);
-
- MCPWMx->CON_SET = regVal;
-}
-
-
-/*********************************************************************//**
- * @brief Stop MCPWM activity for each MCPWM channel
- * @param[in] MCPWMx Motor Control PWM peripheral selected
- * Should be: LPC_MCPWM
- * @param[in] channel0 State of this command on channel 0:
- * - ENABLE: 'Stop' command will effect on channel 0
- * - DISABLE: 'Stop' command will not effect on channel 0
- * @param[in] channel1 State of this command on channel 1:
- * - ENABLE: 'Stop' command will effect on channel 1
- * - DISABLE: 'Stop' command will not effect on channel 1
- * @param[in] channel2 State of this command on channel 2:
- * - ENABLE: 'Stop' command will effect on channel 2
- * - DISABLE: 'Stop' command will not effect on channel 2
- * @return None
- **********************************************************************/
-void MCPWM_Stop(LPC_MCPWM_TypeDef *MCPWMx, uint32_t channel0,
- uint32_t channel1, uint32_t channel2)
-{
- uint32_t regVal = 0;
-
- regVal = (channel0 ? MCPWM_CON_RUN(0) : 0) | (channel1 ? MCPWM_CON_RUN(1) : 0) \
- | (channel2 ? MCPWM_CON_RUN(2) : 0);
-
- MCPWMx->CON_CLR = regVal;
-}
-
-
-/*********************************************************************//**
- * @brief Enables/Disables 3-phase AC motor mode on MCPWM peripheral
- * @param[in] MCPWMx Motor Control PWM peripheral selected
- * Should be: LPC_MCPWM
- * @param[in] acMode State of this command, should be:
- * - ENABLE.
- * - DISABLE.
- * @return None
- **********************************************************************/
-void MCPWM_ACMode(LPC_MCPWM_TypeDef *MCPWMx, uint32_t acMode)
-{
- if (acMode)
- {
- MCPWMx->CON_SET = MCPWM_CON_ACMODE;
- }
- else
- {
- MCPWMx->CON_CLR = MCPWM_CON_ACMODE;
- }
-}
-
-
-/*********************************************************************//**
- * @brief Enables/Disables 3-phase DC motor mode on MCPWM peripheral
- * @param[in] MCPWMx Motor Control PWM peripheral selected
- * Should be: LPC_MCPWM
- * @param[in] dcMode State of this command, should be:
- * - ENABLE.
- * - DISABLE.
- * @param[in] outputInvered Polarity of the MCOB outputs for all 3 channels,
- * should be:
- * - ENABLE: The MCOB outputs have opposite polarity
- * from the MCOA outputs.
- * - DISABLE: The MCOB outputs have the same basic
- * polarity as the MCOA outputs.
- * @param[in] outputPattern A value contains bits that enables/disables the specified
- * output pins route to the internal MCOA0 signal, should be:
- - MCPWM_PATENT_A0: MCOA0 tracks internal MCOA0
- - MCPWM_PATENT_B0: MCOB0 tracks internal MCOA0
- - MCPWM_PATENT_A1: MCOA1 tracks internal MCOA0
- - MCPWM_PATENT_B1: MCOB1 tracks internal MCOA0
- - MCPWM_PATENT_A2: MCOA2 tracks internal MCOA0
- - MCPWM_PATENT_B2: MCOB2 tracks internal MCOA0
- * @return None
- *
- * Note: all these outputPatent values above can be ORed together for using as input parameter.
- **********************************************************************/
-void MCPWM_DCMode(LPC_MCPWM_TypeDef *MCPWMx, uint32_t dcMode,
- uint32_t outputInvered, uint32_t outputPattern)
-{
- if (dcMode)
- {
- MCPWMx->CON_SET = MCPWM_CON_DCMODE;
- }
- else
- {
- MCPWMx->CON_CLR = MCPWM_CON_DCMODE;
- }
-
- if (outputInvered)
- {
- MCPWMx->CON_SET = MCPWM_CON_INVBDC;
- }
- else
- {
- MCPWMx->CON_CLR = MCPWM_CON_INVBDC;
- }
-
- MCPWMx->CP = outputPattern;
-}
-
-
-/*********************************************************************//**
- * @brief Configures the specified interrupt in MCPWM peripheral
- * @param[in] MCPWMx Motor Control PWM peripheral selected
- * Should be: LPC_MCPWM
- * @param[in] ulIntType Interrupt type, should be:
- * - MCPWM_INTFLAG_LIM0: Limit interrupt for channel (0)
- * - MCPWM_INTFLAG_MAT0: Match interrupt for channel (0)
- * - MCPWM_INTFLAG_CAP0: Capture interrupt for channel (0)
- * - MCPWM_INTFLAG_LIM1: Limit interrupt for channel (1)
- * - MCPWM_INTFLAG_MAT1: Match interrupt for channel (1)
- * - MCPWM_INTFLAG_CAP1: Capture interrupt for channel (1)
- * - MCPWM_INTFLAG_LIM2: Limit interrupt for channel (2)
- * - MCPWM_INTFLAG_MAT2: Match interrupt for channel (2)
- * - MCPWM_INTFLAG_CAP2: Capture interrupt for channel (2)
- * - MCPWM_INTFLAG_ABORT: Fast abort interrupt
- * @param[in] NewState New State of this command, should be:
- * - ENABLE.
- * - DISABLE.
- * @return None
- *
- * Note: all these ulIntType values above can be ORed together for using as input parameter.
- **********************************************************************/
-void MCPWM_IntConfig(LPC_MCPWM_TypeDef *MCPWMx, uint32_t ulIntType, FunctionalState NewState)
-{
- if (NewState)
- {
- MCPWMx->INTEN_SET = ulIntType;
- }
- else
- {
- MCPWMx->INTEN_CLR = ulIntType;
- }
-}
-
-
-/*********************************************************************//**
- * @brief Sets/Forces the specified interrupt for MCPWM peripheral
- * @param[in] MCPWMx Motor Control PWM peripheral selected
- * Should be LPC_MCPWM
- * @param[in] ulIntType Interrupt type, should be:
- * - MCPWM_INTFLAG_LIM0: Limit interrupt for channel (0)
- * - MCPWM_INTFLAG_MAT0: Match interrupt for channel (0)
- * - MCPWM_INTFLAG_CAP0: Capture interrupt for channel (0)
- * - MCPWM_INTFLAG_LIM1: Limit interrupt for channel (1)
- * - MCPWM_INTFLAG_MAT1: Match interrupt for channel (1)
- * - MCPWM_INTFLAG_CAP1: Capture interrupt for channel (1)
- * - MCPWM_INTFLAG_LIM2: Limit interrupt for channel (2)
- * - MCPWM_INTFLAG_MAT2: Match interrupt for channel (2)
- * - MCPWM_INTFLAG_CAP2: Capture interrupt for channel (2)
- * - MCPWM_INTFLAG_ABORT: Fast abort interrupt
- * @return None
- * Note: all these ulIntType values above can be ORed together for using as input parameter.
- **********************************************************************/
-void MCPWM_IntSet(LPC_MCPWM_TypeDef *MCPWMx, uint32_t ulIntType)
-{
- MCPWMx->INTF_SET = ulIntType;
-}
-
-
-/*********************************************************************//**
- * @brief Clear the specified interrupt pending for MCPWM peripheral
- * @param[in] MCPWMx Motor Control PWM peripheral selected,
- * should be: LPC_MCPWM
- * @param[in] ulIntType Interrupt type, should be:
- * - MCPWM_INTFLAG_LIM0: Limit interrupt for channel (0)
- * - MCPWM_INTFLAG_MAT0: Match interrupt for channel (0)
- * - MCPWM_INTFLAG_CAP0: Capture interrupt for channel (0)
- * - MCPWM_INTFLAG_LIM1: Limit interrupt for channel (1)
- * - MCPWM_INTFLAG_MAT1: Match interrupt for channel (1)
- * - MCPWM_INTFLAG_CAP1: Capture interrupt for channel (1)
- * - MCPWM_INTFLAG_LIM2: Limit interrupt for channel (2)
- * - MCPWM_INTFLAG_MAT2: Match interrupt for channel (2)
- * - MCPWM_INTFLAG_CAP2: Capture interrupt for channel (2)
- * - MCPWM_INTFLAG_ABORT: Fast abort interrupt
- * @return None
- * Note: all these ulIntType values above can be ORed together for using as input parameter.
- **********************************************************************/
-void MCPWM_IntClear(LPC_MCPWM_TypeDef *MCPWMx, uint32_t ulIntType)
-{
- MCPWMx->INTF_CLR = ulIntType;
-}
-
-
-/*********************************************************************//**
- * @brief Check whether if the specified interrupt in MCPWM is set or not
- * @param[in] MCPWMx Motor Control PWM peripheral selected,
- * should be: LPC_MCPWM
- * @param[in] ulIntType Interrupt type, should be:
- * - MCPWM_INTFLAG_LIM0: Limit interrupt for channel (0)
- * - MCPWM_INTFLAG_MAT0: Match interrupt for channel (0)
- * - MCPWM_INTFLAG_CAP0: Capture interrupt for channel (0)
- * - MCPWM_INTFLAG_LIM1: Limit interrupt for channel (1)
- * - MCPWM_INTFLAG_MAT1: Match interrupt for channel (1)
- * - MCPWM_INTFLAG_CAP1: Capture interrupt for channel (1)
- * - MCPWM_INTFLAG_LIM2: Limit interrupt for channel (2)
- * - MCPWM_INTFLAG_MAT2: Match interrupt for channel (2)
- * - MCPWM_INTFLAG_CAP2: Capture interrupt for channel (2)
- * - MCPWM_INTFLAG_ABORT: Fast abort interrupt
- * @return None
- **********************************************************************/
-FlagStatus MCPWM_GetIntStatus(LPC_MCPWM_TypeDef *MCPWMx, uint32_t ulIntType)
-{
- return ((MCPWMx->INTF & ulIntType) ? SET : RESET);
-}
-
-/**
- * @}
- */
-
-#endif /*_MCPWM*/
-/**
- * @}
- */
-
-/* --------------------------------- End Of File ------------------------------ */
diff --git a/bsp/lpc408x/Libraries/Drivers/source/lpc_nvic.c b/bsp/lpc408x/Libraries/Drivers/source/lpc_nvic.c
deleted file mode 100644
index 3de1316a82..0000000000
--- a/bsp/lpc408x/Libraries/Drivers/source/lpc_nvic.c
+++ /dev/null
@@ -1,156 +0,0 @@
-/**********************************************************************
-* $Id$ lpc_nvic.c 2011-06-02
-*//**
-* @file lpc_nvic.c
-* @brief Contains all expansion functions support for Nesting
-* Vectored Interrupt Controller (NVIC) firmware library
-* on LPC. The main NVIC functions are defined
-* in core_cm3.h
-* @version 1.0
-* @date 02. June. 2011
-* @author NXP MCU SW Application Team
-*
-* Copyright(C) 2011, NXP Semiconductor
-* All rights reserved.
-*
-***********************************************************************
-* Software that is described herein is for illustrative purposes only
-* which provides customers with programming information regarding the
-* products. This software is supplied "AS IS" without any warranties.
-* NXP Semiconductors assumes no responsibility or liability for the
-* use of the software, conveys no license or title under any patent,
-* copyright, or mask work right to the product. NXP Semiconductors
-* reserves the right to make changes in the software without
-* notification. NXP Semiconductors also make 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'
-* relevant copyright 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.
-**********************************************************************/
-
-/* Peripheral group ----------------------------------------------------------- */
-/** @addtogroup NVIC
- * @{
- */
-#ifdef __BUILD_WITH_EXAMPLE__
-#include "lpc_libcfg.h"
-#else
-#include "lpc_libcfg_default.h"
-#endif /* __BUILD_WITH_EXAMPLE__ */
-#ifdef _NVIC
-
-/* Includes ------------------------------------------------------------------- */
-#include "lpc_nvic.h"
-
-
-/* Private Macros ------------------------------------------------------------- */
-/** @defgroup NVIC_Private_Macros NVIC Private Macros
- * @{
- */
-
-/* Vector table offset bit mask */
-#define NVIC_VTOR_MASK 0x3FFFFF80
-
-/**
- * @}
- */
-
-
-/* Public Functions ----------------------------------------------------------- */
-/** @addtogroup NVIC_Public_Functions
- * @{
- */
-
-
-/*****************************************************************************//**
- * @brief De-initializes the NVIC peripheral registers to their default
- * reset values.
- * @param None
- * @return None
- *
- * These following NVIC peripheral registers will be de-initialized:
- * - Disable Interrupt (32 IRQ interrupt sources that matched with LPC178X)
- * - Clear all Pending Interrupts (32 IRQ interrupt source that matched with LPC178X)
- * - Clear all Interrupt Priorities (32 IRQ interrupt source that matched with LPC178X)
- *******************************************************************************/
-void NVIC_DeInit(void)
-{
- uint8_t tmp;
-
- /* Disable all interrupts */
- NVIC->ICER[0] = 0xFFFFFFFF;
- NVIC->ICER[1] = 0x00000001;
- /* Clear all pending interrupts */
- NVIC->ICPR[0] = 0xFFFFFFFF;
- NVIC->ICPR[1] = 0x00000001;
-
- /* Clear all interrupt priority */
- for (tmp = 0; tmp < 32; tmp++) {
- NVIC->IP[tmp] = 0x00;
- }
-}
-
-/*****************************************************************************//**
- * @brief De-initializes the SCB peripheral registers to their default
- * reset values.
- * @param none
- * @return none
- *
- * These following SCB NVIC peripheral registers will be de-initialized:
- * - Interrupt Control State register
- * - Interrupt Vector Table Offset register
- * - Application Interrupt/Reset Control register
- * - System Control register
- * - Configuration Control register
- * - System Handlers Priority Registers
- * - System Handler Control and State Register
- * - Configurable Fault Status Register
- * - Hard Fault Status Register
- * - Debug Fault Status Register
- *******************************************************************************/
-void NVIC_SCBDeInit(void)
-{
- uint8_t tmp;
-
- SCB->ICSR = 0x0A000000;
- SCB->VTOR = 0x00000000;
- SCB->AIRCR = 0x05FA0000;
- SCB->SCR = 0x00000000;
- SCB->CCR = 0x00000000;
-
- for (tmp = 0; tmp < 32; tmp++) {
- SCB->SHP[tmp] = 0x00;
- }
-
- SCB->SHCSR = 0x00000000;
- SCB->CFSR = 0xFFFFFFFF;
- SCB->HFSR = 0xFFFFFFFF;
- SCB->DFSR = 0xFFFFFFFF;
-}
-
-
-/*****************************************************************************//**
- * @brief Set Vector Table Offset value
- * @param offset Offset value
- * @return None
- *******************************************************************************/
-void NVIC_SetVTOR(uint32_t offset)
-{
-// SCB->VTOR = (offset & NVIC_VTOR_MASK);
- SCB->VTOR = offset;
-}
-
-/**
- * @}
- */
-
-#endif /*_NVIC*/
-/**
- * @}
- */
-
-/* --------------------------------- End Of File ------------------------------ */
diff --git a/bsp/lpc408x/Libraries/Drivers/source/lpc_pinsel.c b/bsp/lpc408x/Libraries/Drivers/source/lpc_pinsel.c
deleted file mode 100644
index 61809f5bd6..0000000000
--- a/bsp/lpc408x/Libraries/Drivers/source/lpc_pinsel.c
+++ /dev/null
@@ -1,540 +0,0 @@
-/**********************************************************************
-* $Id$ lpc_pinsel.c 2011-06-02
-*//**
-* @file lpc_pinsel.c
-* @brief Contains all functions support for Pin-connection block
-* firmware library on LPC
-* @version 1.0
-* @date 02. June. 2011
-* @author NXP MCU SW Application Team
-*
-* Copyright(C) 2011, NXP Semiconductor
-* All rights reserved.
-*
-***********************************************************************
-* Software that is described herein is for illustrative purposes only
-* which provides customers with programming information regarding the
-* products. This software is supplied "AS IS" without any warranties.
-* NXP Semiconductors assumes no responsibility or liability for the
-* use of the software, conveys no license or title under any patent,
-* copyright, or mask work right to the product. NXP Semiconductors
-* reserves the right to make changes in the software without
-* notification. NXP Semiconductors also make 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'
-* relevant copyright 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.
-**********************************************************************/
-
-/* Peripheral group ----------------------------------------------------------- */
-/** @addtogroup PINSEL
- * @{
- */
-#ifdef __BUILD_WITH_EXAMPLE__
-#include "lpc_libcfg.h"
-#else
-#include "lpc_libcfg_default.h"
-#endif /* __BUILD_WITH_EXAMPLE__ */
-#ifdef _PINSEL
-
-/* Includes ------------------------------------------------------------------- */
-#include "lpc_pinsel.h"
-
-/* Private Functions ---------------------------------------------------------- */
-
-/*********************************************************************//**
- * @brief Get pointer to GPIO peripheral due to GPIO port
- * @param[in] portnum Port Number value, should be in range from 0..3.
- * @param[in] pinnum Pin number value, should be in range from 0..31
- * @return Pointer to GPIO peripheral
- **********************************************************************/
-static uint32_t * PIN_GetPointer(uint8_t portnum, uint8_t pinnum)
-{
- uint32_t *pPIN = NULL;
- pPIN = (uint32_t *)(LPC_IOCON_BASE + ((portnum * 32 + pinnum)*sizeof(uint32_t)));
- return pPIN;
-}
-
-/* Public Functions ----------------------------------------------------------- */
-/** @addtogroup PINSEL_Public_Functions
- * @{
- */
-
-/*********************************************************************//**
- * @brief Get type of a pin.
- * @param[in] portnum PORT number, should be in range: 0..3
- * @param[in] pinnum Pin number, should be in range: 0..31
- * @return Port type:
- * - PINSEL_PIN_TYPE_D
- * - PINSEL_PIN_TYPE_A
- * - PINSEL_PIN_TYPE_I
- * - PINSEL_PIN_TYPE_W
- * - PINSEL_PIN_TYPE_U
- * - PINSEL_PIN_TYPE_UNKNOWN: Invalid pin
- **********************************************************************/
-PinSel_PinType PINSEL_GetPinType(uint8_t portnum, uint8_t pinnum)
-{
- PinSel_PinType Ret = PINSEL_PIN_TYPE_UNKNOWN;
- switch(portnum)
- {
- case 0:
- if((pinnum <=6)||
- ((pinnum >= 10)&&(pinnum <=11))||
- ((pinnum >= 14)&&(pinnum <=22)))
- Ret = PINSEL_PIN_TYPE_D;
- else if ((pinnum == 12)||(pinnum==13)||
- ((pinnum >= 23)&&(pinnum <=26)))
- Ret = PINSEL_PIN_TYPE_A;
- else if ((pinnum == 29) || (pinnum==30)|| (pinnum==31))
- Ret = PINSEL_PIN_TYPE_U;
- else if ((pinnum == 27) || (pinnum==28))
- Ret = PINSEL_PIN_TYPE_I;
- else if ((pinnum == 7) || (pinnum==8)|| (pinnum==9))
- Ret = PINSEL_PIN_TYPE_W;
- break;
- case 1:
- if(pinnum <=29)
- Ret = PINSEL_PIN_TYPE_D;
- else if ((pinnum == 30) || (pinnum==31))
- Ret = PINSEL_PIN_TYPE_A;
- break;
- case 2:
- case 3:
- case 4:
- Ret = PINSEL_PIN_TYPE_D;
- break;
- case 5:
- if((pinnum <=1)||
- (pinnum == 4))
- Ret = PINSEL_PIN_TYPE_D;
- else if ((pinnum == 2) || (pinnum==3))
- Ret = PINSEL_PIN_TYPE_I;
- break;
- default:
- break;
- }
-
- return Ret;
-}
-
-/*********************************************************************//**
- * @brief Setup the pin selection function
- * @param[in] portnum PORT number, should be in range: 0..3
- * @param[in] pinnum Pin number, should be in range: 0..31
- * @param[in] funcnum Function number, should be range: 0..7
- * - 0: Select GPIO (Default)
- * - 1: Selects the 1st alternate function
- * - 2: Selects the 2nd alternate function
- * ...
- * - 7: Selects the 7th alternate function
- * @return PINSEL Return Code
- * - PINSEL_RET_INVALID_PIN
- * - PINSEL_RET_OK
- **********************************************************************/
-PINSEL_RET_CODE PINSEL_ConfigPin ( uint8_t portnum, uint8_t pinnum, uint8_t funcnum)
-{
- uint32_t *pPIN = NULL;
- PinSel_PinType type = PINSEL_GetPinType(portnum,pinnum);
-
- if(type == PINSEL_PIN_TYPE_UNKNOWN)
- return PINSEL_RET_INVALID_PIN;
-
- pPIN = PIN_GetPointer(portnum, pinnum);
- *pPIN &= ~IOCON_FUNC_MASK;//Clear function bits
- *pPIN |= funcnum&IOCON_FUNC_MASK;
-
- return PINSEL_RET_OK;
-}
-
-
-/*********************************************************************//**
- * @brief Setup resistor mode for pin of type D,A,W
- * @param[in] portnum PORT number, should be in range: 0..3
- * @param[in] pinnum Pin number, should be in range: 0..31
- * @param[in] modenum: Mode number, should be in range: 0..3
- - PINSEL_BASICMODE_PLAINOUT: Plain output
- - PINSEL_BASICMODE_PULLDOWN: Pull-down enable
- - PINSEL_BASICMODE_PULLUP: Pull-up enable
- - PINSEL_BASICMODE_REPEATER: Repeater mode
- * @return PINSEL Return Code
- * - PINSEL_RET_INVALID_PIN
- * - PINSEL_RET_NOT_SUPPORT
- * - PINSEL_RET_OK
- **********************************************************************/
-PINSEL_RET_CODE PINSEL_SetPinMode ( uint8_t portnum, uint8_t pinnum, PinSel_BasicMode modenum)
-{
- uint32_t *pPIN = NULL;
- PinSel_PinType type = PINSEL_GetPinType(portnum,pinnum);
-
- if(type == PINSEL_PIN_TYPE_UNKNOWN)
- return PINSEL_RET_INVALID_PIN;
- if((type != PINSEL_PIN_TYPE_D )&&
- (type != PINSEL_PIN_TYPE_A )&&
- (type != PINSEL_PIN_TYPE_W))
- return PINSEL_RET_NOT_SUPPORT;
-
- pPIN = PIN_GetPointer(portnum, pinnum);
- *(uint32_t *)pPIN &= ~(IOCON_MODE_MASK);//Clear function bits
- *(uint32_t *)pPIN |= (modenum << IOCON_MODE_POS)&IOCON_MODE_MASK;
-
- return PINSEL_RET_OK;
-}
-
-/*********************************************************************//**
- * @brief Setup hysteresis for pin of type D, W
- * @param[in] portnum Port number, should be in range: 0..3
- * @param[in] pinnum Pin number, should be in range: 0..31
- * @param[in] NewState new state of Hysteresis mode, should be:
- * - ENABLE: Hysteresis enable
- * - DISABLE: Hysteresis disable
- * @return PINSEL Return Code
- * - PINSEL_RET_INVALID_PIN
- * - PINSEL_RET_NOT_SUPPORT
- * - PINSEL_RET_OK
- **********************************************************************/
-PINSEL_RET_CODE PINSEL_SetHysMode(uint8_t portnum, uint8_t pinnum, FunctionalState NewState)
-{
- uint32_t *pPIN = NULL;
- PinSel_PinType type = PINSEL_GetPinType(portnum,pinnum);
-
- if(type == PINSEL_PIN_TYPE_UNKNOWN)
- return PINSEL_RET_INVALID_PIN;
- if((type != PINSEL_PIN_TYPE_D )&&
- (type != PINSEL_PIN_TYPE_W))
- return PINSEL_RET_NOT_SUPPORT;
-
- pPIN = PIN_GetPointer(portnum, pinnum);
- if(NewState == DISABLE)
- {
- *(uint32_t *)pPIN &= ~IOCON_HYS_ENABLE;//Clear hys bits
- }
- else
- *(uint32_t *)pPIN |= IOCON_HYS_ENABLE;
-
- return PINSEL_RET_OK;
-}
-/*********************************************************************//**
- * @brief Setup input polarity for pin of type A,I,D,W
- * @param[in] portnum Port number, should be in range: 0..3
- * @param[in] pinnum Pin number, should be in range: 0..31
- * @param[in] NewState new state of Invert mode, should be:
- * - ENABLE: Input is inverted.
- * - DISABLE: Input isn't inverted.
- * @return PINSEL Return Code
- * - PINSEL_RET_INVALID_PIN
- * - PINSEL_RET_NOT_SUPPORT
- * - PINSEL_RET_OK
- **********************************************************************/
-PINSEL_RET_CODE PINSEL_SetInvertInput(uint8_t portnum, uint8_t pinnum, FunctionalState NewState)
-{
- uint32_t *pPIN = NULL;
- PinSel_PinType type = PINSEL_GetPinType(portnum,pinnum);
-
- if(type == PINSEL_PIN_TYPE_UNKNOWN)
- return PINSEL_RET_INVALID_PIN;
- if(type== PINSEL_PIN_TYPE_U)
- return PINSEL_RET_NOT_SUPPORT;
-
- pPIN = PIN_GetPointer(portnum, pinnum);
- if(NewState == DISABLE)
- {
- *(uint32_t *)pPIN &= ~IOCON_INVERT_INPUT;//Clear hys bits
- }
- else
- *(uint32_t *)pPIN |= IOCON_INVERT_INPUT;
-
- return PINSEL_RET_OK;
-}
-
-/*********************************************************************//**
- * @brief Setup Slew rate for pin of type D,W
- * @param[in] portnum Port number, should be in range: 0..3
- * @param[in] pinnum Pin number, should be in range: 0..31
- * @param[in] NewState new state of Slew rate control, should be:
- * - ENABLE: Output slew rate control is enable
- * - DISABLE: Output slew rate control is disable
- * @return PINSEL Return Code
- * - PINSEL_RET_INVALID_PIN
- * - PINSEL_RET_NOT_SUPPORT
- * - PINSEL_RET_OK
- **********************************************************************/
-PINSEL_RET_CODE PINSEL_SetSlewMode(uint8_t portnum, uint8_t pinnum, FunctionalState NewState)
-{
- uint32_t *pPIN = NULL;
- PinSel_PinType type = PINSEL_GetPinType(portnum,pinnum);
-
- if(type == PINSEL_PIN_TYPE_UNKNOWN)
- return PINSEL_RET_INVALID_PIN;
- if((type!= PINSEL_PIN_TYPE_D) &&
- (type!= PINSEL_PIN_TYPE_W))
- return PINSEL_RET_NOT_SUPPORT;
-
- pPIN = PIN_GetPointer(portnum, pinnum);
- if(NewState == DISABLE)
- {
- *(uint32_t *)pPIN &= ~IOCON_SLEW_ENABLE;//Clear hys bits
- }
- else
- *(uint32_t *)pPIN |= IOCON_SLEW_ENABLE;
-
- return PINSEL_RET_OK;
-}
-
-/*********************************************************************//**
- * @brief Setup I2CMode for only pins that provide special I2C functionality
- * @param[in] portnum Port number, should be in range: 0..3
- * @param[in] pinnum Pin number, should be in range: 0..31
- * @param[in] I2CMode I2C mode, should be:
- * - PINSEL_I2CMODE_FAST_STANDARD: Fast mode and standard I2C mode
- * - PINSEL_I2CMODE_OPENDRAINIO: Open drain I/O
- * - PINSEL_I2CMODE_FASTMODEPLUS: Fast Mode Plus I/O
- * @return PINSEL Return Code
- * - PINSEL_RET_INVALID_PIN
- * - PINSEL_RET_NOT_SUPPORT
- * - PINSEL_RET_OK
- **********************************************************************/
-PINSEL_RET_CODE PINSEL_SetI2CMode(uint8_t portnum, uint8_t pinnum, PinSel_I2cMode I2CMode)
-{
- uint32_t *pPIN = NULL;
- PinSel_PinType type = PINSEL_GetPinType(portnum,pinnum);
-
- if(type == PINSEL_PIN_TYPE_UNKNOWN)
- return PINSEL_RET_INVALID_PIN;
- if(type != PINSEL_PIN_TYPE_I )
- return PINSEL_RET_NOT_SUPPORT;
-
- pPIN = PIN_GetPointer(portnum, pinnum);
-
- switch(I2CMode)
- {
- // Standard/Fast Mode I2C: HS = HIDRIVE = 0
- case PINSEL_I2CMODE_FAST_STANDARD:
- PINSEL_SetI2CFilter(portnum,pinnum,ENABLE);
- *(uint32_t *)pPIN &= ~(IOCON_I2CMODE_FASTPLUS);
- break;
-
- // Non-I2C: HS = 1, HIDRIVE = 0
- case PINSEL_I2CMODE_OPENDRAINIO:
- PINSEL_SetI2CFilter(portnum,pinnum,DISABLE);
- *(uint32_t *)pPIN &= ~(IOCON_I2CMODE_FASTPLUS);
- break;
-
- // Fast Mode Plus I2C: HS = 0, HIDRIVE =1
- case PINSEL_I2CMODE_FASTMODEPLUS:
- PINSEL_SetI2CFilter(portnum,pinnum,ENABLE);
- *(uint32_t *)pPIN |= (IOCON_I2CMODE_FASTPLUS);
- break;
- default:
- return PINSEL_RET_ERR;
- }
-
- return PINSEL_RET_OK;
-}
-
-/*********************************************************************//**
- * @brief Setup Open-drain mode in pin of type D, A, W
- * @param[in] portnum Port number, should be in range: 0..3
- * @param[in] pinnum Pin number, should be in range: 0..31
- * @param[in] NewState new state of Open-drain mode:
- * - DISABLE: Normal pin I/O mode
- * - ENABLE: Open-drain enable
- * @return PINSEL Return Code
- * - PINSEL_RET_INVALID_PIN
- * - PINSEL_RET_NOT_SUPPORT
- * - PINSEL_RET_OK
- **********************************************************************/
-PINSEL_RET_CODE PINSEL_SetOpenDrainMode(uint8_t portnum, uint8_t pinnum, FunctionalState NewState)
-{
- uint32_t *pPIN = NULL;
- PinSel_PinType type = PINSEL_GetPinType(portnum,pinnum);
-
- if(type == PINSEL_PIN_TYPE_UNKNOWN)
- return PINSEL_RET_INVALID_PIN;
- if((type != PINSEL_PIN_TYPE_D ) &&
- (type != PINSEL_PIN_TYPE_A ) &&
- (type != PINSEL_PIN_TYPE_W ))
- return PINSEL_RET_NOT_SUPPORT;
-
- pPIN = PIN_GetPointer(portnum, pinnum);
- if(NewState == DISABLE)
- {
- *(uint32_t *)pPIN &= ~IOCON_OPENDRAIN_MODE;//Clear hys bits
- }
- else
- {
- *(uint32_t *)pPIN |= IOCON_OPENDRAIN_MODE;
- }
- return PINSEL_RET_OK;
-}
-
-/*********************************************************************//**
- * @brief Enable the Analog mode for each pin of Type A(default is as Digital pins)
- * @param[in] portnum PORT number, should be in range: 0..3
- * @param[in] pinnum Pin number, should be in range: 0..31
- * @param[in] enable: the state of the pin that is expected to run
- - ENABLE: Enable the DAC mode of the pin
- - DISABLE: Disable the DAC mode
- * @return PINSEL Return Code
- * - PINSEL_RET_INVALID_PIN
- * - PINSEL_RET_NOT_SUPPORT
- * - PINSEL_RET_OK
- **********************************************************************/
-PINSEL_RET_CODE PINSEL_SetAnalogPinMode (uint8_t portnum, uint8_t pinnum, uint8_t enable)
-{
- uint32_t *pPIN = NULL;
- PinSel_PinType type = PINSEL_GetPinType(portnum,pinnum);
-
- if(type == PINSEL_PIN_TYPE_UNKNOWN)
- return PINSEL_RET_INVALID_PIN;
- if(type != PINSEL_PIN_TYPE_A )
- return PINSEL_RET_NOT_SUPPORT;
-
- pPIN = PIN_GetPointer(portnum, pinnum);
-
- if(enable)
- {
- *(uint32_t *)pPIN &= ~(IOCON_DIGITIAL_MODE);
- }
- else
- {
- *(uint32_t *)pPIN |= IOCON_DIGITIAL_MODE;//Set 7th bit to one
- }
-
- return PINSEL_RET_OK;
-}
-
-
-
-/*********************************************************************//**
- * @brief Choose the DAC mode for pin P0.26
- * @param[in] portnum PORT number, should be in range: 0..3
- * @param[in] pinnum Pin number, should be in range: 0..31
- * @param[in] enable: the state of the pin that is expected to run
- - ENABLE: Enable the DAC mode of the pin
- - DISABLE: Disable the DAC mode
- * @return PINSEL Return Code
- * - PINSEL_RET_INVALID_PIN
- * - PINSEL_RET_NOT_SUPPORT
- * - PINSEL_RET_OK
- **********************************************************************/
-PINSEL_RET_CODE PINSEL_DacEnable (uint8_t portnum, uint8_t pinnum, uint8_t enable)
-{
- uint32_t *pPIN = NULL;
-
- PinSel_PinType type = PINSEL_GetPinType(portnum,pinnum);
-
- if(type == PINSEL_PIN_TYPE_UNKNOWN)
- return PINSEL_RET_INVALID_PIN;
-
- // This setting is only for DAC pin (output pin)
- if(!((portnum == 0) && (pinnum == 26)))
- {
- return PINSEL_RET_NOT_SUPPORT;
- }
-
- pPIN = PIN_GetPointer(portnum, pinnum);
-
- if(enable)
- {
- *(uint32_t *)pPIN |= IOCON_DAC_ENABLE;//Set 16th bit to one
- }
- else
- {
- *(uint32_t *)pPIN &= ~IOCON_DAC_ENABLE;//Set 16th bit to one
-
- }
-
- return PINSEL_RET_OK;
-}
-
-/*********************************************************************//**
- * @brief Control the 10ns glitch filter for pin of type A,W
- * @param[in] portnum PORT number, should be in range: 0..3
- * @param[in] pinnum Pin number, should be in range: 0..31
- * @param[in] enable: the state of the pin that is expected to run
- - ENABLE: The noise pulses below approximately 10ns are filtered out
- - DISABLE: No input filtering is done.
- * @return PINSEL Return Code
- * - PINSEL_RET_INVALID_PIN
- * - PINSEL_RET_NOT_SUPPORT
- * - PINSEL_RET_OK
- **********************************************************************/
-PINSEL_RET_CODE PINSEL_SetFilter (uint8_t portnum, uint8_t pinnum, uint8_t enable)
-{
- uint32_t *pPIN = NULL;
- PinSel_PinType type = PINSEL_GetPinType(portnum,pinnum);
-
- if(type == PINSEL_PIN_TYPE_UNKNOWN)
- return PINSEL_RET_INVALID_PIN;
- if((type != PINSEL_PIN_TYPE_A ) &&
- (type != PINSEL_PIN_TYPE_W ))
- return PINSEL_RET_NOT_SUPPORT;
-
- pPIN = PIN_GetPointer(portnum, pinnum);
-
-
- if(enable)
- {
- *(uint32_t *)pPIN &= ~(IOCON_10ns_FILTER_DISABLE);//Clear 8th bit to 0
- }
- else
- {
- *(uint32_t *)pPIN |= (IOCON_10ns_FILTER_DISABLE);//Set 8th bit to one
- }
-
-
- return PINSEL_RET_OK;
-}
-/*********************************************************************//**
- * @brief Control the 50ns glitch filter for I2C pins (type I)
- * @param[in] portnum PORT number, should be in range: 0..3
- * @param[in] pinnum Pin number, should be in range: 0..31
- * @param[in] enable: the state of the pin that is expected to run
- - ENABLE: The noise pulses below approximately 10ns are filtered out
- - DISABLE: No input filtering is done.
- * @return PINSEL Return Code
- * - PINSEL_RET_INVALID_PIN
- * - PINSEL_RET_NOT_SUPPORT
- * - PINSEL_RET_OK
- **********************************************************************/
-PINSEL_RET_CODE PINSEL_SetI2CFilter (uint8_t portnum, uint8_t pinnum, uint8_t enable)
-{
- uint32_t *pPIN = NULL;
- PinSel_PinType type = PINSEL_GetPinType(portnum,pinnum);
-
- if(type == PINSEL_PIN_TYPE_UNKNOWN)
- return PINSEL_RET_INVALID_PIN;
- if(type != PINSEL_PIN_TYPE_I)
- return PINSEL_RET_NOT_SUPPORT;
-
- pPIN = PIN_GetPointer(portnum, pinnum);
-
-
- if(enable)
- {
- *(uint32_t *)pPIN &= ~(IOCON_HS_MASK);//Clear 8th bit to 0
- }
- else
- {
- *(uint32_t *)pPIN |= (IOCON_I2C_FILTER_DISABLE);//Set 8th bit to one
- }
-
-
- return PINSEL_RET_OK;
-}
-
-
-/**
- * @}
- */
-#endif /*_PINSEL*/
-
-/**
- * @}
- */
-
-/* --------------------------------- End Of File ------------------------------ */
diff --git a/bsp/lpc408x/Libraries/Drivers/source/lpc_pwm.c b/bsp/lpc408x/Libraries/Drivers/source/lpc_pwm.c
deleted file mode 100644
index a9c79c25c4..0000000000
--- a/bsp/lpc408x/Libraries/Drivers/source/lpc_pwm.c
+++ /dev/null
@@ -1,579 +0,0 @@
-/**********************************************************************
-* $Id$ lpc_pwm.c 2011-06-02
-*//**
-* @file lpc_pwm.c
-* @brief Contains all functions support for PWM firmware library
-* on LPC
-* @version 1.0
-* @date 02. June. 2011
-* @author NXP MCU SW Application Team
-*
-* Copyright(C) 2011, NXP Semiconductor
-* All rights reserved.
-*
-***********************************************************************
-* Software that is described herein is for illustrative purposes only
-* which provides customers with programming information regarding the
-* products. This software is supplied "AS IS" without any warranties.
-* NXP Semiconductors assumes no responsibility or liability for the
-* use of the software, conveys no license or title under any patent,
-* copyright, or mask work right to the product. NXP Semiconductors
-* reserves the right to make changes in the software without
-* notification. NXP Semiconductors also make 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'
-* relevant copyright 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.
-**********************************************************************/
-
-/* Peripheral group ----------------------------------------------------------- */
-/** @addtogroup PWM
- * @{
- */
-#ifdef __BUILD_WITH_EXAMPLE__
-#include "lpc_libcfg.h"
-#else
-#include "lpc_libcfg_default.h"
-#endif /* __BUILD_WITH_EXAMPLE__ */
-#ifdef _PWM
-
-/* Includes ------------------------------------------------------------------- */
-#include "lpc_pwm.h"
-#include "lpc_clkpwr.h"
-
-/* Public Functions ----------------------------------------------------------- */
-/** @addtogroup PWM_Public_Functions
- * @{
- */
-
-static LPC_PWM_TypeDef* PWM_GetPointer (uint8_t pwmId);
-
-/*********************************************************************//**
- * @brief Setting CAN baud rate (bps)
- * @param[in] canId point to LPC_CAN_TypeDef object, should be:
- * - LPC_CAN1: CAN1 peripheral
- * - LPC_CAN2: CAN2 peripheral
- * @return The pointer to CAN peripheral that's expected to use
- ***********************************************************************/
-static LPC_PWM_TypeDef* PWM_GetPointer (uint8_t pwmId)
-{
- LPC_PWM_TypeDef* pPwm;
-
- switch (pwmId)
- {
- case PWM_0:
- pPwm = LPC_PWM0;
- break;
-
- case PWM_1:
- pPwm = LPC_PWM1;
- break;
-
- default:
- pPwm = NULL;
- break;
- }
-
- return pPwm;
-}
-
-
-/*********************************************************************//**
- * @brief Check whether specified interrupt flag in PWM is set or not
- * @param[in] pwmId The Id of the expected PWM component
- *
- * @param[in] IntFlag: PWM interrupt flag, should be:
- * - PWM_INTSTAT_MR0: Interrupt flag for PWM match channel 0
- * - PWM_INTSTAT_MR1: Interrupt flag for PWM match channel 1
- * - PWM_INTSTAT_MR2: Interrupt flag for PWM match channel 2
- * - PWM_INTSTAT_MR3: Interrupt flag for PWM match channel 3
- * - PWM_INTSTAT_MR4: Interrupt flag for PWM match channel 4
- * - PWM_INTSTAT_MR5: Interrupt flag for PWM match channel 5
- * - PWM_INTSTAT_MR6: Interrupt flag for PWM match channel 6
- * - PWM_INTSTAT_CAP0: Interrupt flag for capture input 0
- * - PWM_INTSTAT_CAP1: Interrupt flag for capture input 1
- * @return New State of PWM interrupt flag (SET or RESET)
- **********************************************************************/
-IntStatus PWM_GetIntStatus(uint8_t pwmId, uint32_t IntFlag)
-{
- LPC_PWM_TypeDef* pPwm = PWM_GetPointer(pwmId);
-
- return ((pPwm->IR & IntFlag) ? SET : RESET);
-}
-
-
-
-/*********************************************************************//**
- * @brief Clear specified PWM Interrupt pending
- * @param[in] pwmId The Id of the expected PWM component
- *
- * @param[in] IntFlag: PWM interrupt flag, should be:
- * - PWM_INTSTAT_MR0: Interrupt flag for PWM match channel 0
- * - PWM_INTSTAT_MR1: Interrupt flag for PWM match channel 1
- * - PWM_INTSTAT_MR2: Interrupt flag for PWM match channel 2
- * - PWM_INTSTAT_MR3: Interrupt flag for PWM match channel 3
- * - PWM_INTSTAT_MR4: Interrupt flag for PWM match channel 4
- * - PWM_INTSTAT_MR5: Interrupt flag for PWM match channel 5
- * - PWM_INTSTAT_MR6: Interrupt flag for PWM match channel 6
- * - PWM_INTSTAT_CAP0: Interrupt flag for capture input 0
- * - PWM_INTSTAT_CAP1: Interrupt flag for capture input 1
- * @return None
- **********************************************************************/
-void PWM_ClearIntPending(uint8_t pwmId, uint32_t IntFlag)
-{
- LPC_PWM_TypeDef* pPwm = PWM_GetPointer(pwmId);
-
- pPwm->IR = IntFlag;
-}
-
-
-
-/*****************************************************************************//**
-* @brief Fills each PWM_InitStruct member with its default value:
-* - If PWMCounterMode = PWM_MODE_TIMER:
-* + PrescaleOption = PWM_TIMER_PRESCALE_USVAL
-* + PrescaleValue = 1
-* - If PWMCounterMode = PWM_MODE_COUNTER:
-* + CountInputSelect = PWM_COUNTER_PCAP1_0
-* + CounterOption = PWM_COUNTER_RISING
-* @param[in] PWMTimerCounterMode Timer or Counter mode, should be:
-* - PWM_MODE_TIMER: Counter of PWM peripheral is in Timer mode
-* - PWM_MODE_COUNTER: Counter of PWM peripheral is in Counter mode
-* @param[in] PWM_InitStruct Pointer to structure (PWM_TIMERCFG_Type or
-* PWM_COUNTERCFG_Type) which will be initialized.
-* @return None
-* Note: PWM_InitStruct pointer will be assigned to corresponding structure
-* (PWM_TIMERCFG_Type or PWM_COUNTERCFG_Type) due to PWMTimerCounterMode.
-*******************************************************************************/
-void PWM_ConfigStructInit(uint8_t PWMTimerCounterMode, void *PWM_InitStruct)
-{
- PWM_TIMERCFG_Type *pTimeCfg;
- PWM_COUNTERCFG_Type *pCounterCfg;
-
- pTimeCfg = (PWM_TIMERCFG_Type *) PWM_InitStruct;
- pCounterCfg = (PWM_COUNTERCFG_Type *) PWM_InitStruct;
-
- if (PWMTimerCounterMode == PWM_MODE_TIMER )
- {
- pTimeCfg->PrescaleOption = PWM_TIMER_PRESCALE_USVAL;
- pTimeCfg->PrescaleValue = 1;
- }
- else if (PWMTimerCounterMode == PWM_MODE_COUNTER)
- {
- pCounterCfg->CountInputSelect = PWM_COUNTER_PCAP1_0;
- pCounterCfg->CounterOption = PWM_COUNTER_RISING;
- }
-}
-
-
-/*********************************************************************//**
- * @brief Initializes the pPwm peripheral corresponding to the specified
- * parameters in the PWM_ConfigStruct.
- * @param[in] pwmId The Id of the expected PWM component
- *
- *
- * @param[in] PWMTimerCounterMode Timer or Counter mode, should be:
- * - PWM_MODE_TIMER: Counter of PWM peripheral is in Timer mode
- * - PWM_MODE_COUNTER: Counter of PWM peripheral is in Counter mode
- * @param[in] PWM_ConfigStruct Pointer to structure (PWM_TIMERCFG_Type or
- * PWM_COUNTERCFG_Type) which will be initialized.
- * @return None
- * Note: PWM_ConfigStruct pointer will be assigned to corresponding structure
- * (PWM_TIMERCFG_Type or PWM_COUNTERCFG_Type) due to PWMTimerCounterMode.
- **********************************************************************/
-void PWM_Init(uint8_t pwmId, uint32_t PWMTimerCounterMode, void *PWM_ConfigStruct)
-{
- LPC_PWM_TypeDef* pPwm = PWM_GetPointer(pwmId);
-
- PWM_TIMERCFG_Type *pTimeCfg;
- PWM_COUNTERCFG_Type *pCounterCfg;
- uint64_t clkdlycnt;
-
- pTimeCfg = (PWM_TIMERCFG_Type *)PWM_ConfigStruct;
- pCounterCfg = (PWM_COUNTERCFG_Type *)PWM_ConfigStruct;
-
- if(pwmId == PWM_0)
- {
- CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCPWM0, ENABLE);
- }
- else if(pwmId == PWM_1)
- {
- CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCPWM1, ENABLE);
- }
- else
- {
- //Trap the error
- while(1);
- }
-
- // Get peripheral clock of PWM1
- clkdlycnt = CLKPWR_GetCLK(CLKPWR_CLKTYPE_PER);
-
- // Clear all interrupts pending
- pPwm->IR = 0xFF & PWM_IR_BITMASK;
- pPwm->TCR = 0x00;
- pPwm->CTCR = 0x00;
- pPwm->MCR = 0x00;
- pPwm->CCR = 0x00;
- pPwm->PCR = 0x00;
- pPwm->LER = 0x00;
-
- if (PWMTimerCounterMode == PWM_MODE_TIMER)
- {
- /* Absolute prescale value */
- if (pTimeCfg->PrescaleOption == PWM_TIMER_PRESCALE_TICKVAL)
- {
- pPwm->PR = pTimeCfg->PrescaleValue - 1;
- }
- /* uSecond prescale value */
- else
- {
- clkdlycnt = (clkdlycnt * pTimeCfg->PrescaleValue) / 1000000;
- pPwm->PR = ((uint32_t) clkdlycnt) - 1;
- }
-
- }
- else if (PWMTimerCounterMode == PWM_MODE_COUNTER)
- {
-
- pPwm->CTCR |= (PWM_CTCR_MODE((uint32_t)pCounterCfg->CounterOption)) \
- | (PWM_CTCR_SELECT_INPUT((uint32_t)pCounterCfg->CountInputSelect));
- }
-}
-
-/*********************************************************************//**
- * @brief De-initializes the PWM peripheral registers to their
-* default reset values.
- * @param[in] pwmId The Id of the expected PWM component
- *
- * @return None
- **********************************************************************/
-void PWM_DeInit (uint8_t pwmId)
-{
- LPC_PWM_TypeDef* pPwm = PWM_GetPointer(pwmId);
-
- // Disable PWM control (timer, counter and PWM)
- pPwm->TCR = 0x00;
-
- if(pwmId == PWM_0)
- {
- CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCPWM0, DISABLE);
- }
- else if(pwmId == PWM_1)
- {
- CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCPWM1, DISABLE);
- }
-}
-
-
-/*********************************************************************//**
- * @brief Enable/Disable PWM peripheral
- * @param[in] pwmId The Id of the expected PWM component
- *
- * @param[in] NewState New State of this function, should be:
- * - ENABLE: Enable PWM peripheral
- * - DISABLE: Disable PWM peripheral
- * @return None
- **********************************************************************/
-void PWM_Cmd(uint8_t pwmId, FunctionalState NewState)
-{
- LPC_PWM_TypeDef* pPwm = PWM_GetPointer(pwmId);
-
- if (NewState == ENABLE)
- {
- pPwm->TCR |= PWM_TCR_PWM_ENABLE;
- }
- else
- {
- pPwm->TCR &= (~PWM_TCR_PWM_ENABLE) & PWM_TCR_BITMASK;
- }
-}
-
-
-/*********************************************************************//**
- * @brief Enable/Disable Counter in PWM peripheral
- * @param[in] pwmId The Id of the expected PWM component
- *
- * @param[in] NewState New State of this function, should be:
- * - ENABLE: Enable Counter in PWM peripheral
- * - DISABLE: Disable Counter in PWM peripheral
- * @return None
- **********************************************************************/
-void PWM_CounterCmd(uint8_t pwmId, FunctionalState NewState)
-{
- LPC_PWM_TypeDef* pPwm = PWM_GetPointer(pwmId);
-
- if (NewState == ENABLE)
- {
- pPwm->TCR |= PWM_TCR_COUNTER_ENABLE;
- }
- else
- {
- pPwm->TCR &= (~PWM_TCR_COUNTER_ENABLE) & PWM_TCR_BITMASK;
- }
-}
-
-
-/*********************************************************************//**
- * @brief Reset Counter in PWM peripheral
- * @param[in] pwmId The Id of the expected PWM component
- *
- * @return None
- **********************************************************************/
-void PWM_ResetCounter(uint8_t pwmId)
-{
- LPC_PWM_TypeDef* pPwm = PWM_GetPointer(pwmId);
-
- pPwm->TCR |= PWM_TCR_COUNTER_RESET;
-
- pPwm->TCR &= (~PWM_TCR_COUNTER_RESET) & PWM_TCR_BITMASK;
-}
-
-
-/*********************************************************************//**
- * @brief Configures match for PWM peripheral
- * @param[in] pwmId The Id of the expected PWM component
- *
- * @param[in] PWM_MatchConfigStruct Pointer to a PWM_MATCHCFG_Type structure
-* that contains the configuration information for the
-* specified PWM match function.
- * @return None
- **********************************************************************/
-void PWM_ConfigMatch(uint8_t pwmId, PWM_MATCHCFG_Type *PWM_MatchConfigStruct)
-{
- LPC_PWM_TypeDef* pPwm = PWM_GetPointer(pwmId);
-
- //interrupt on MRn
- if (PWM_MatchConfigStruct->IntOnMatch == ENABLE)
- {
- pPwm->MCR |= PWM_MCR_INT_ON_MATCH(PWM_MatchConfigStruct->MatchChannel);
- }
- else
- {
- pPwm->MCR &= (~ PWM_MCR_INT_ON_MATCH(PWM_MatchConfigStruct->MatchChannel)) \
- & PWM_MCR_BITMASK;
- }
-
- //reset on MRn
- if (PWM_MatchConfigStruct->ResetOnMatch == ENABLE)
- {
- pPwm->MCR |= PWM_MCR_RESET_ON_MATCH(PWM_MatchConfigStruct->MatchChannel);
- }
- else
- {
- pPwm->MCR &= (~ PWM_MCR_RESET_ON_MATCH(PWM_MatchConfigStruct->MatchChannel)) \
- & PWM_MCR_BITMASK;
- }
-
- //stop on MRn
- if (PWM_MatchConfigStruct->StopOnMatch == ENABLE)
- {
- pPwm->MCR |= PWM_MCR_STOP_ON_MATCH(PWM_MatchConfigStruct->MatchChannel);
- }
- else
- {
- pPwm->MCR &= (~ PWM_MCR_STOP_ON_MATCH(PWM_MatchConfigStruct->MatchChannel)) \
- & PWM_MCR_BITMASK;
- }
-}
-
-
-/*********************************************************************//**
- * @brief Configures capture input for PWM peripheral
- * @param[in] pwmId The Id of the expected PWM component
- *
- * @param[in] PWM_CaptureConfigStruct Pointer to a PWM_CAPTURECFG_Type structure
- * that contains the configuration information for the
- * specified PWM capture input function.
- * @return None
- **********************************************************************/
-void PWM_ConfigCapture(uint8_t pwmId, PWM_CAPTURECFG_Type *PWM_CaptureConfigStruct)
-{
- LPC_PWM_TypeDef* pPwm = PWM_GetPointer(pwmId);
-
- if (PWM_CaptureConfigStruct->RisingEdge == ENABLE)
- {
- pPwm->CCR |= PWM_CCR_CAP_RISING(PWM_CaptureConfigStruct->CaptureChannel);
- }
- else
- {
- pPwm->CCR &= (~ PWM_CCR_CAP_RISING(PWM_CaptureConfigStruct->CaptureChannel)) \
- & PWM_CCR_BITMASK;
- }
-
- if (PWM_CaptureConfigStruct->FallingEdge == ENABLE)
- {
- pPwm->CCR |= PWM_CCR_CAP_FALLING(PWM_CaptureConfigStruct->CaptureChannel);
- }
- else
- {
- pPwm->CCR &= (~ PWM_CCR_CAP_FALLING(PWM_CaptureConfigStruct->CaptureChannel)) \
- & PWM_CCR_BITMASK;
- }
-
- if (PWM_CaptureConfigStruct->IntOnCaption == ENABLE)
- {
- pPwm->CCR |= PWM_CCR_INT_ON_CAP(PWM_CaptureConfigStruct->CaptureChannel);
- }
- else
- {
- pPwm->CCR &= (~ PWM_CCR_INT_ON_CAP(PWM_CaptureConfigStruct->CaptureChannel)) \
- & PWM_CCR_BITMASK;
- }
-}
-
-
-/*********************************************************************//**
- * @brief Read value of capture register PWM peripheral
- * @param[in] pwmId The Id of the expected PWM component
- *
- * @param[in] CaptureChannel: capture channel number, should be in
- * range 0 to 1
- * @return Value of capture register
- **********************************************************************/
-uint32_t PWM_GetCaptureValue(uint8_t pwmId, uint8_t CaptureChannel)
-{
- LPC_PWM_TypeDef* pPwm = PWM_GetPointer(pwmId);
-
- switch (CaptureChannel)
- {
- case 0:
- return pPwm->CR0;
-
- case 1:
- return pPwm->CR1;
-
- default:
- return (0);
- }
-}
-
-
-/********************************************************************//**
- * @brief Update value for each PWM channel with update type option
- * @param[in] pwmId The Id of the expected PWM component
- *
- * @param[in] MatchChannel Match channel
- * @param[in] MatchValue Match value
- * @param[in] UpdateType Type of Update, should be:
- * - PWM_MATCH_UPDATE_NOW: The update value will be updated for
- * this channel immediately
- * - PWM_MATCH_UPDATE_NEXT_RST: The update value will be updated for
- * this channel on next reset by a PWM Match event.
- * @return None
- *********************************************************************/
-void PWM_MatchUpdate(uint8_t pwmId, uint8_t MatchChannel,
- uint32_t MatchValue, uint8_t UpdateType)
-{
- LPC_PWM_TypeDef* pPwm = PWM_GetPointer(pwmId);
-
- switch (MatchChannel)
- {
- case 0:
- pPwm->MR0 = MatchValue;
- break;
-
- case 1:
- pPwm->MR1 = MatchValue;
- break;
-
- case 2:
- pPwm->MR2 = MatchValue;
- break;
-
- case 3:
- pPwm->MR3 = MatchValue;
- break;
-
- case 4:
- pPwm->MR4 = MatchValue;
- break;
-
- case 5:
- pPwm->MR5 = MatchValue;
- break;
-
- case 6:
- pPwm->MR6 = MatchValue;
- break;
- }
-
- // Write Latch register
- pPwm->LER |= PWM_LER_EN_MATCHn_LATCH(MatchChannel);
-
- // In case of update now
- if (UpdateType == PWM_MATCH_UPDATE_NOW)
- {
- pPwm->TCR |= PWM_TCR_COUNTER_RESET;
- pPwm->TCR &= (~PWM_TCR_COUNTER_RESET) & PWM_TCR_BITMASK;
- }
-}
-
-
-/********************************************************************//**
- * @brief Configure Edge mode for each PWM channel
- * @param[in] pwmId The Id of the expected PWM component
- *
- * @param[in] PWMChannel PWM channel, should be in range from 2 to 6
- * @param[in] ModeOption PWM mode option, should be:
- * - PWM_CHANNEL_SINGLE_EDGE: Single Edge mode
- * - PWM_CHANNEL_DUAL_EDGE: Dual Edge mode
- * @return None
- * Note: PWM Channel 1 can not be selected for mode option
- *********************************************************************/
-void PWM_ChannelConfig(uint8_t pwmId, uint8_t PWMChannel, uint8_t ModeOption)
-{
- LPC_PWM_TypeDef* pPwm = PWM_GetPointer(pwmId);
-
- // Single edge mode
- if (ModeOption == PWM_CHANNEL_SINGLE_EDGE)
- {
- pPwm->PCR &= (~ PWM_PCR_PWMSELn(PWMChannel)) & PWM_PCR_BITMASK;
- }
- // Double edge mode
- else if (PWM_CHANNEL_DUAL_EDGE)
- {
- pPwm->PCR |= PWM_PCR_PWMSELn(PWMChannel);
- }
-}
-
-
-
-/********************************************************************//**
- * @brief Enable/Disable PWM channel output
- * @param[in] pwmId The Id of the expected PWM component
- *
- * @param[in] PWMChannel PWM channel, should be in range from 1 to 6
- * @param[in] NewState New State of this function, should be:
- * - ENABLE: Enable this PWM channel output
- * - DISABLE: Disable this PWM channel output
- * @return None
- *********************************************************************/
-void PWM_ChannelCmd(uint8_t pwmId, uint8_t PWMChannel, FunctionalState NewState)
-{
- LPC_PWM_TypeDef* pPwm = PWM_GetPointer(pwmId);
-
- if (NewState == ENABLE)
- {
- pPwm->PCR |= PWM_PCR_PWMENAn(PWMChannel);
- }
- else
- {
- pPwm->PCR &= (~ PWM_PCR_PWMENAn(PWMChannel)) & PWM_PCR_BITMASK;
- }
-}
-
-/**
- * @}
- */
-
-#endif /*_PWM*/
-/**
- * @}
- */
-
-/* --------------------------------- End Of File ------------------------------ */
diff --git a/bsp/lpc408x/Libraries/Drivers/source/lpc_qei.c b/bsp/lpc408x/Libraries/Drivers/source/lpc_qei.c
deleted file mode 100644
index 8c098a7b69..0000000000
--- a/bsp/lpc408x/Libraries/Drivers/source/lpc_qei.c
+++ /dev/null
@@ -1,599 +0,0 @@
-/**********************************************************************
-* $Id$ lpc_qei.c 2011-06-02
-*//**
-* @file lpc_qei.c
-* @brief Contains all functions support for QEI firmware library
-* on LPC
-* @version 1.0
-* @date 02. June. 2011
-* @author NXP MCU SW Application Team
-*
-* Copyright(C) 2011, NXP Semiconductor
-* All rights reserved.
-*
-***********************************************************************
-* Software that is described herein is for illustrative purposes only
-* which provides customers with programming information regarding the
-* products. This software is supplied "AS IS" without any warranties.
-* NXP Semiconductors assumes no responsibility or liability for the
-* use of the software, conveys no license or title under any patent,
-* copyright, or mask work right to the product. NXP Semiconductors
-* reserves the right to make changes in the software without
-* notification. NXP Semiconductors also make 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'
-* relevant copyright 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.
-**********************************************************************/
-
-/* Peripheral group ----------------------------------------------------------- */
-/** @addtogroup QEI
- * @{
- */
-#ifdef __BUILD_WITH_EXAMPLE__
-#include "lpc_libcfg.h"
-#else
-#include "lpc_libcfg_default.h"
-#endif /* __BUILD_WITH_EXAMPLE__ */
-#ifdef _QEI
-
-/* Includes ------------------------------------------------------------------- */
-#include "lpc_qei.h"
-#include "lpc_clkpwr.h"
-
-/* Private Types -------------------------------------------------------------- */
-/** @defgroup QEI_Private_Types QEI Private Types
- * @{
- */
-
-/**
- * @brief QEI configuration union type definition
- */
-typedef union {
- QEI_CFG_Type bmQEIConfig;
- uint32_t ulQEIConfig;
-} QEI_CFGOPT_Type;
-
-/**
- * @}
- */
-
-LPC_QEI_TypeDef* QEI_GetPointer(uint8_t qeiId);
-
-
-/* Public Functions ----------------------------------------------------------- */
-/** @addtogroup QEI_Public_Functions
- * @{
- */
-
-/*********************************************************************//**
- * @brief Get the point to typedef of QEI component
- * @param[in] qeiId The Id of the expected QEI component
- * It should be 0 (zero) always with LPC
- * @return None
- **********************************************************************/
-LPC_QEI_TypeDef* QEI_GetPointer(uint8_t qeiId)
-{
- LPC_QEI_TypeDef* pQei = NULL;
-
- if(qeiId == 0)
- {
- pQei = LPC_QEI;
- }
-
- return pQei;
-}
-
-
-/*********************************************************************//**
- * @brief Resets value for each type of QEI value, such as velocity,
- * counter, position, etc..
- * @param[in] qeiId The Id of the expected QEI component
- * It should be 0 (zero) always with LPC
- *
- * @param[in] ulResetType QEI Reset Type, should be one of the following:
- * - QEI_RESET_POS: Reset Position Counter
- * - QEI_RESET_POSOnIDX: Reset Position Counter on Index signal
- * - QEI_RESET_VEL: Reset Velocity
- * - QEI_RESET_IDX: Reset Index Counter
- * @return None
- **********************************************************************/
-void QEI_Reset(uint8_t qeiId, uint32_t ulResetType)
-{
- LPC_QEI_TypeDef* pQei = QEI_GetPointer(qeiId);
-
- pQei->CON = ulResetType;
-}
-
-/*********************************************************************//**
- * @brief Initializes the QEI peripheral according to the specified
-* parameters in the QEI_ConfigStruct.
-* @param[in] qeiId The Id of the expected QEI component
-* It should be 0 (zero) always with LPC
-*
-* @param[in] QEI_ConfigStruct Pointer to a QEI_CFG_Type structure
-* that contains the configuration information for the
-* specified QEI peripheral
- * @return None
- **********************************************************************/
-void QEI_Init(uint8_t qeiId, QEI_CFG_Type *QEI_ConfigStruct)
-{
- LPC_QEI_TypeDef* pQei = QEI_GetPointer(qeiId);
-
- /* Set up clock and power for QEI module */
- CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCQEI, ENABLE);
-
- // Reset all remaining value in QEI peripheral
-
- pQei->MAXPOS = 0x00;
- pQei->CMPOS0 = 0x00;
- pQei->CMPOS1 = 0x00;
- pQei->CMPOS2 = 0x00;
- pQei->INXCMP0 = 0x00;
- pQei->VELCOMP = 0x00;
-
- pQei->LOAD = 0x00;
- pQei->CON = QEI_CON_RESP | QEI_CON_RESV | QEI_CON_RESI;
-
- pQei->FILTERPHA = 0x00;
- pQei->FILTERPHB = 0x00;
- pQei->FILTERINX = 0x00;
-
- // Disable all Interrupt
- pQei->IEC = QEI_IECLR_BITMASK;
-
- // Clear all Interrupt pending
- pQei->CLR = QEI_INTCLR_BITMASK;
-
- // Set QEI configuration value corresponding to its setting up value
- pQei->CONF = ((QEI_CFGOPT_Type *)QEI_ConfigStruct)->ulQEIConfig;
-}
-
-
-/*********************************************************************//**
- * @brief De-initializes the QEI peripheral registers to their
- * default reset values.
- * @param[in] qeiId The Id of the expected QEI component
- * It should be 0 (zero) always with LPC
- *
- * @return None
- **********************************************************************/
-void QEI_DeInit(uint8_t qeiId)
-{
- /* Turn off clock and power for QEI module */
- CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCQEI, DISABLE);
-}
-
-
-/*****************************************************************************//**
-* @brief Fills each QIE_InitStruct member with its default value:
-* - DirectionInvert = QEI_DIRINV_NONE
-* - SignalMode = QEI_SIGNALMODE_QUAD
-* - CaptureMode = QEI_CAPMODE_4X
-* - InvertIndex = QEI_INVINX_NONE
-* @param[in] QIE_InitStruct Pointer to a QEI_CFG_Type structure
-* which will be initialized.
-* @return None
-*******************************************************************************/
-void QEI_GetCfgDefault(QEI_CFG_Type *QIE_InitStruct)
-{
- QIE_InitStruct->CaptureMode = QEI_CAPMODE_4X;
- QIE_InitStruct->DirectionInvert = QEI_DIRINV_NONE;
- QIE_InitStruct->InvertIndex = QEI_INVINX_NONE;
- QIE_InitStruct->SignalMode = QEI_SIGNALMODE_QUAD;
-}
-
-
-/*********************************************************************//**
- * @brief Check whether if specified flag status is set or not
- * @param[in] qeiId The Id of the expected QEI component
- * It should be 0 (zero) always with LPC
- *
- * @param[in] ulFlagType Status Flag Type, should be one of the following:
- * - QEI_STATUS_DIR: Direction Status
- * @return New Status of this status flag (SET or RESET)
- **********************************************************************/
-FlagStatus QEI_GetStatus(uint8_t qeiId, uint32_t ulFlagType)
-{
- LPC_QEI_TypeDef* pQei = QEI_GetPointer(qeiId);
-
- return ((pQei->STAT & ulFlagType) ? SET : RESET);
-}
-
-/*********************************************************************//**
- * @brief Get current position value in QEI peripheral
- * @param[in] qeiId The Id of the expected QEI component
- * It should be 0 (zero) always with LPC
- *
- * @return Current position value of QEI peripheral
- **********************************************************************/
-uint32_t QEI_GetPosition(uint8_t qeiId)
-{
- LPC_QEI_TypeDef* pQei = QEI_GetPointer(qeiId);
-
- return (pQei->POS);
-}
-
-/*********************************************************************//**
- * @brief Set max position value for QEI peripheral
- * @param[in] qeiId The Id of the expected QEI component
- * It should be 0 (zero) always with LPC
- *
- * @param[in] ulMaxPos Max position value to set
- * @return None
- **********************************************************************/
-void QEI_SetMaxPosition(uint8_t qeiId, uint32_t ulMaxPos)
-{
- LPC_QEI_TypeDef* pQei = QEI_GetPointer(qeiId);
-
- pQei->MAXPOS = ulMaxPos;
-}
-
-/*********************************************************************//**
- * @brief Set position compare value for QEI peripheral
- * @param[in] qeiId The Id of the expected QEI component
- * It should be 0 (zero) always with LPC
- *
- * @param[in] bPosCompCh Compare Position channel, should be:
- * - QEI_COMPPOS_CH_0: QEI compare position channel 0
- * - QEI_COMPPOS_CH_1: QEI compare position channel 1
- * - QEI_COMPPOS_CH_2: QEI compare position channel 2
- * @param[in] ulPosComp Compare Position value to set
- * @return None
- **********************************************************************/
-void QEI_SetPositionComp(uint8_t qeiId, uint8_t bPosCompCh, uint32_t ulPosComp)
-{
- LPC_QEI_TypeDef* pQei = QEI_GetPointer(qeiId);
- uint32_t *tmp;
-
- tmp = (uint32_t *) (&(pQei->CMPOS0) + bPosCompCh * 4);
- *tmp = ulPosComp;
-}
-
-/*********************************************************************//**
- * @brief Get current index counter of QEI peripheral
- * @param[in] qeiId The Id of the expected QEI component
- * It should be 0 (zero) always with LPC
- *
- * @return Current value of QEI index counter
- **********************************************************************/
-uint32_t QEI_GetIndex(uint8_t qeiId)
-{
- LPC_QEI_TypeDef* pQei = QEI_GetPointer(qeiId);
-
- return (pQei->INXCNT);
-}
-
-/*********************************************************************//**
- * @brief Set value for index compare in QEI peripheral
- * @param[in] qeiId The Id of the expected QEI component
- * It should be 0 (zero) always with LPC
- *
- * @param[in] ulIndexComp Compare Index Value to set
- * @return None
- **********************************************************************/
-void QEI_SetIndexComp(uint8_t qeiId, uint32_t ulIndexComp)
-{
- LPC_QEI_TypeDef* pQei = QEI_GetPointer(qeiId);
-
- pQei->INXCMP0 = ulIndexComp;
-}
-
-/*********************************************************************//**
- * @brief Set timer reload value for QEI peripheral. When the velocity timer is
- * over-flow, the value that set for Timer Reload register will be loaded
- * into the velocity timer for next period. The calculated velocity in RPM
- * therefore will be affect by this value.
- * @param[in] qeiId The Id of the expected QEI component
- * It should be 0 (zero) always with LPC
- *
- * @param[in] QEIReloadStruct QEI reload structure
- * @return None
- **********************************************************************/
-void QEI_SetTimerReload(uint8_t qeiId, QEI_RELOADCFG_Type *QEIReloadStruct)
-{
- LPC_QEI_TypeDef* pQei = QEI_GetPointer(qeiId);
- uint64_t pclk;
-
-
- if (QEIReloadStruct->ReloadOption == QEI_TIMERRELOAD_TICKVAL)
- {
- pQei->LOAD = QEIReloadStruct->ReloadValue - 1;
- }
- else
- {
-#if 1
- pclk = CLKPWR_GetCLK(CLKPWR_CLKTYPE_PER);
-
- pclk = (pclk /(1000000/QEIReloadStruct->ReloadValue)) - 1;
-
- pQei->LOAD = (uint32_t)pclk;
-#else
- ld = CLKPWR_GetCLK(CLKPWR_CLKTYPE_PER);
-
- if (ld/1000000 > 0)
- {
- ld /= 1000000;
- ld *= QEIReloadStruct->ReloadValue;
- ld -= 1;
- }
- else
- {
- ld *= QEIReloadStruct->ReloadValue;
- ld /= 1000000;
- ld -= 1;
- }
-
- pQei->LOAD = ld;
-#endif
- }
-}
-
-/*********************************************************************//**
- * @brief Get current timer counter in QEI peripheral
- * @param[in] qeiId The Id of the expected QEI component
- * It should be 0 (zero) always with LPC
- *
- * @return Current timer counter in QEI peripheral
- **********************************************************************/
-uint32_t QEI_GetTimer(uint8_t qeiId)
-{
- LPC_QEI_TypeDef* pQei = QEI_GetPointer(qeiId);
-
- return (pQei->TIME);
-}
-
-/*********************************************************************//**
- * @brief Get current velocity pulse counter in current time period
- * @param[in] qeiId The Id of the expected QEI component
- * It should be 0 (zero) always with LPC
- *
- * @return Current velocity pulse counter value
- **********************************************************************/
-uint32_t QEI_GetVelocity(uint8_t qeiId)
-{
- LPC_QEI_TypeDef* pQei = QEI_GetPointer(qeiId);
-
- return (pQei->VEL);
-}
-
-/*********************************************************************//**
- * @brief Get the most recently measured velocity of the QEI. When
- * the Velocity timer in QEI is over-flow, the current velocity
- * value will be loaded into Velocity Capture register.
- * @param[in] qeiId The Id of the expected QEI component
- * It should be 0 (zero) always with LPC
- *
- * @return The most recently measured velocity value
- **********************************************************************/
-uint32_t QEI_GetVelocityCap(uint8_t qeiId)
-{
- LPC_QEI_TypeDef* pQei = QEI_GetPointer(qeiId);
-
- return (pQei->CAP);
-}
-
-/*********************************************************************//**
- * @brief Set Velocity Compare value for QEI peripheral
- * @param[in] qeiId The Id of the expected QEI component
- * It should be 0 (zero) always with LPC
- *
- * @param[in] ulVelComp Compare Velocity value to set
- * @return None
- **********************************************************************/
-void QEI_SetVelocityComp(uint8_t qeiId, uint32_t ulVelComp)
-{
- LPC_QEI_TypeDef* pQei = QEI_GetPointer(qeiId);
-
- pQei->VELCOMP = ulVelComp;
-}
-
-/*********************************************************************//**
- * @brief Set value of sampling count for the digital filter in
- * QEI peripheral
- * @param[in] qeiId The Id of the expected QEI component
- * It should be 0 (zero) always with LPC
- *
- * @param[in] ulSamplingPulse Value of sampling count to set
- * @return None
- **********************************************************************/
-void QEI_SetDigiFilter(uint8_t qeiId, st_Qei_FilterCfg FilterVal)
-{
- LPC_QEI_TypeDef* pQei = QEI_GetPointer(qeiId);
-
- pQei->FILTERPHA = FilterVal.PHA_FilterVal;
- pQei->FILTERPHB = FilterVal.PHB_FilterVal;
- pQei->FILTERINX = FilterVal.INX_FilterVal;
-}
-
-/*********************************************************************//**
- * @brief Check whether if specified interrupt flag status in QEI
- * peripheral is set or not
- * @param[in] qeiId The Id of the expected QEI component
- * It should be 0 (zero) always with LPC
- *
- * @param[in] ulIntType Interrupt Flag Status type, should be:
- - QEI_INTFLAG_INX_Int: index pulse was detected interrupt
- - QEI_INTFLAG_TIM_Int: Velocity timer over flow interrupt
- - QEI_INTFLAG_VELC_Int: Capture velocity is less than compare interrupt
- - QEI_INTFLAG_DIR_Int: Change of direction interrupt
- - QEI_INTFLAG_ERR_Int: An encoder phase error interrupt
- - QEI_INTFLAG_ENCLK_Int: An encoder clock pulse was detected interrupt
- - QEI_INTFLAG_POS0_Int: position 0 compare value is equal to the
- current position interrupt
- - QEI_INTFLAG_POS1_Int: position 1 compare value is equal to the
- current position interrupt
- - QEI_INTFLAG_POS2_Int: position 2 compare value is equal to the
- current position interrupt
- - QEI_INTFLAG_REV_Int: Index compare value is equal to the current
- index count interrupt
- - QEI_INTFLAG_POS0REV_Int: Combined position 0 and revolution count interrupt
- - QEI_INTFLAG_POS1REV_Int: Combined position 1 and revolution count interrupt
- - QEI_INTFLAG_POS2REV_Int: Combined position 2 and revolution count interrupt
- * @return New State of specified interrupt flag status (SET or RESET)
- **********************************************************************/
-FlagStatus QEI_GetIntStatus(uint8_t qeiId, uint32_t ulIntType)
-{
- LPC_QEI_TypeDef* pQei = QEI_GetPointer(qeiId);
-
- return((pQei->INTSTAT & ulIntType) ? SET : RESET);
-}
-
-/*********************************************************************//**
- * @brief Enable/Disable specified interrupt in QEI peripheral
- * @param[in] qeiId The Id of the expected QEI component
- * It should be 0 (zero) always with LPC
- *
- * @param[in] ulIntType Interrupt Flag Status type, should be:
- - QEI_INTFLAG_INX_Int: index pulse was detected interrupt
- - QEI_INTFLAG_TIM_Int: Velocity timer over flow interrupt
- - QEI_INTFLAG_VELC_Int: Capture velocity is less than compare interrupt
- - QEI_INTFLAG_DIR_Int: Change of direction interrupt
- - QEI_INTFLAG_ERR_Int: An encoder phase error interrupt
- - QEI_INTFLAG_ENCLK_Int: An encoder clock pulse was detected interrupt
- - QEI_INTFLAG_POS0_Int: position 0 compare value is equal to the
- current position interrupt
- - QEI_INTFLAG_POS1_Int: position 1 compare value is equal to the
- current position interrupt
- - QEI_INTFLAG_POS2_Int: position 2 compare value is equal to the
- current position interrupt
- - QEI_INTFLAG_REV_Int: Index compare value is equal to the current
- index count interrupt
- - QEI_INTFLAG_POS0REV_Int: Combined position 0 and revolution count interrupt
- - QEI_INTFLAG_POS1REV_Int: Combined position 1 and revolution count interrupt
- - QEI_INTFLAG_POS2REV_Int: Combined position 2 and revolution count interrupt
- * @param[in] NewState New function state, should be:
- * - DISABLE
- * - ENABLE
- * @return None
- **********************************************************************/
-void QEI_IntCmd(uint8_t qeiId, uint32_t ulIntType, FunctionalState NewState)
-{
- LPC_QEI_TypeDef* pQei = QEI_GetPointer(qeiId);
-
- if (NewState == ENABLE)
- {
- pQei->IES = ulIntType;
- }
- else
- {
- pQei->IEC = ulIntType;
- }
-}
-
-
-/*********************************************************************//**
- * @brief Sets (forces) specified interrupt in QEI peripheral
- * @param[in] qeiId The Id of the expected QEI component
- * It should be 0 (zero) always with LPC
- *
- * @param[in] ulIntType Interrupt Flag Status type, should be:
- - QEI_INTFLAG_INX_Int: index pulse was detected interrupt
- - QEI_INTFLAG_TIM_Int: Velocity timer over flow interrupt
- - QEI_INTFLAG_VELC_Int: Capture velocity is less than compare interrupt
- - QEI_INTFLAG_DIR_Int: Change of direction interrupt
- - QEI_INTFLAG_ERR_Int: An encoder phase error interrupt
- - QEI_INTFLAG_ENCLK_Int: An encoder clock pulse was detected interrupt
- - QEI_INTFLAG_POS0_Int: position 0 compare value is equal to the
- current position interrupt
- - QEI_INTFLAG_POS1_Int: position 1 compare value is equal to the
- current position interrupt
- - QEI_INTFLAG_POS2_Int: position 2 compare value is equal to the
- current position interrupt
- - QEI_INTFLAG_REV_Int: Index compare value is equal to the current
- index count interrupt
- - QEI_INTFLAG_POS0REV_Int: Combined position 0 and revolution count interrupt
- - QEI_INTFLAG_POS1REV_Int: Combined position 1 and revolution count interrupt
- - QEI_INTFLAG_POS2REV_Int: Combined position 2 and revolution count interrupt
- * @return None
- **********************************************************************/
-void QEI_IntSet(uint8_t qeiId, uint32_t ulIntType)
-{
- LPC_QEI_TypeDef* pQei = QEI_GetPointer(qeiId);
-
- pQei->SET = ulIntType;
-}
-
-/*********************************************************************//**
- * @brief Clear (force) specified interrupt (pending) in QEI peripheral
- * @param[in] qeiId The Id of the expected QEI component
- * It should be 0 (zero) always with LPC
- *
- * @param[in] ulIntType Interrupt Flag Status type, should be:
- - QEI_INTFLAG_INX_Int: index pulse was detected interrupt
- - QEI_INTFLAG_TIM_Int: Velocity timer over flow interrupt
- - QEI_INTFLAG_VELC_Int: Capture velocity is less than compare interrupt
- - QEI_INTFLAG_DIR_Int: Change of direction interrupt
- - QEI_INTFLAG_ERR_Int: An encoder phase error interrupt
- - QEI_INTFLAG_ENCLK_Int: An encoder clock pulse was detected interrupt
- - QEI_INTFLAG_POS0_Int: position 0 compare value is equal to the
- current position interrupt
- - QEI_INTFLAG_POS1_Int: position 1 compare value is equal to the
- current position interrupt
- - QEI_INTFLAG_POS2_Int: position 2 compare value is equal to the
- current position interrupt
- - QEI_INTFLAG_REV_Int: Index compare value is equal to the current
- index count interrupt
- - QEI_INTFLAG_POS0REV_Int: Combined position 0 and revolution count interrupt
- - QEI_INTFLAG_POS1REV_Int: Combined position 1 and revolution count interrupt
- - QEI_INTFLAG_POS2REV_Int: Combined position 2 and revolution count interrupt
- * @return None
- **********************************************************************/
-void QEI_IntClear(uint8_t qeiId, uint32_t ulIntType)
-{
- LPC_QEI_TypeDef* pQei = QEI_GetPointer(qeiId);
-
- pQei->CLR = ulIntType;
-}
-
-
-/*********************************************************************//**
- * @brief Calculates the actual velocity in RPM passed via velocity
- * capture value and Pulse Per Round (of the encoder) value
- * parameter input.
- * @param[in] qeiId The Id of the expected QEI component
- * It should be 0 (zero) always with LPC
- *
- * @param[in] ulVelCapValue Velocity capture input value that can
- * be got from QEI_GetVelocityCap() function
- * @param[in] ulPPR Pulse per round of encoder
- * @return The actual value of velocity in RPM (Round per minute)
- **********************************************************************/
-uint32_t QEI_CalculateRPM(uint8_t qeiId, uint32_t ulVelCapValue, uint32_t ulPPR)
-{
- LPC_QEI_TypeDef* pQei = QEI_GetPointer(qeiId);
-
- uint64_t rpm, clock, Load, edges;
-
- // Get current Clock rate for timer input
- clock = CLKPWR_GetCLK(CLKPWR_CLKTYPE_PER);
-
- // Get Timer load value (velocity capture period)
- Load = (uint64_t)(pQei->LOAD + 1);
-
- // Get Edge
- edges = (uint64_t)((pQei->CONF & QEI_CONF_CAPMODE) ? 4 : 2);
-
- // Calculate RPM
- rpm = ((clock * ulVelCapValue * 60) / (Load * ulPPR * edges));
-
- return (uint32_t)(rpm);
-}
-
-
-/**
- * @}
- */
-
-#endif /*_QEI*/
-
-/**
- * @}
- */
-
-/* --------------------------------- End Of File ------------------------------ */
-
diff --git a/bsp/lpc408x/Libraries/Drivers/source/lpc_rtc.c b/bsp/lpc408x/Libraries/Drivers/source/lpc_rtc.c
deleted file mode 100644
index 9dd34b7228..0000000000
--- a/bsp/lpc408x/Libraries/Drivers/source/lpc_rtc.c
+++ /dev/null
@@ -1,998 +0,0 @@
-/**********************************************************************
-* $Id$ lpc_rtc.c 2011-06-02
-*//**
-* @file lpc_rtc.c
-* @brief Contains all functions support for RTC firmware library
-* on LPC
-* @version 1.0
-* @date 02. June. 2011
-* @author NXP MCU SW Application Team
-*
-* Copyright(C) 2011, NXP Semiconductor
-* All rights reserved.
-*
-***********************************************************************
-* Software that is described herein is for illustrative purposes only
-* which provides customers with programming information regarding the
-* products. This software is supplied "AS IS" without any warranties.
-* NXP Semiconductors assumes no responsibility or liability for the
-* use of the software, conveys no license or title under any patent,
-* copyright, or mask work right to the product. NXP Semiconductors
-* reserves the right to make changes in the software without
-* notification. NXP Semiconductors also make 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'
-* relevant copyright 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.
-**********************************************************************/
-
-/* Peripheral group ----------------------------------------------------------- */
-/** @addtogroup RTC
- * @{
- */
-#ifdef __BUILD_WITH_EXAMPLE__
-#include "lpc_libcfg.h"
-#else
-#include "lpc_libcfg_default.h"
-#endif /* __BUILD_WITH_EXAMPLE__ */
-#ifdef _RTC
-
-/* Includes ------------------------------------------------------------------- */
-#include "lpc_rtc.h"
-#include "lpc_clkpwr.h"
-
-/* Public Functions ----------------------------------------------------------- */
-/** @addtogroup RTC_Public_Functions
- * @{
- */
-
-/********************************************************************//**
- * @brief Initializes the RTC peripheral.
- * @param[in] RTCx RTC peripheral selected, should be LPC_RTC
- * @return None
- *********************************************************************/
-void RTC_Init (LPC_RTC_TypeDef *RTCx)
-{
- /* Set up clock and power for RTC module */
- CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCRTC, ENABLE);
-
- // Clear all register to be default
- RTCx->ILR = 0x00;
- RTCx->CCR = 0x00;
- RTCx->CIIR = 0x00;
- RTCx->AMR = 0xFF;
- RTCx->CALIBRATION = 0x00;
-}
-
-
-/*********************************************************************//**
- * @brief De-initializes the RTC peripheral registers to their
-* default reset values.
- * @param[in] RTCx RTC peripheral selected, should be LPC_RTC
- * @return None
- **********************************************************************/
-void RTC_DeInit(LPC_RTC_TypeDef *RTCx)
-{
- RTCx->CCR = 0x00;
- // Disable power and clock for RTC module
- CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCRTC, DISABLE);
-}
-
-/*********************************************************************//**
- * @brief Reset clock tick counter in RTC peripheral
- * @param[in] RTCx RTC peripheral selected, should be LPC_RTC
- * @return None
- **********************************************************************/
-void RTC_ResetClockTickCounter(LPC_RTC_TypeDef *RTCx)
-{
- RTCx->CCR |= RTC_CCR_CTCRST;
- RTCx->CCR &= (~RTC_CCR_CTCRST) & RTC_CCR_BITMASK;
-}
-
-/*********************************************************************//**
- * @brief Start/Stop RTC peripheral
- * @param[in] RTCx RTC peripheral selected, should be LPC_RTC
- * @param[in] NewState New State of this function, should be:
- * - ENABLE: The time counters are enabled
- * - DISABLE: The time counters are disabled
- * @return None
- **********************************************************************/
-void RTC_Cmd (LPC_RTC_TypeDef *RTCx, FunctionalState NewState)
-{
- if (NewState == ENABLE)
- {
- RTCx->CCR |= RTC_CCR_CLKEN;
- }
- else
- {
- RTCx->CCR &= (~RTC_CCR_CLKEN) & RTC_CCR_BITMASK;
- }
-}
-
-
-/*********************************************************************//**
- * @brief Enable/Disable Counter increment interrupt for each time type
- * in RTC peripheral
- * @param[in] RTCx RTC peripheral selected, should be LPC_RTC
- * @param[in] CntIncrIntType: Counter Increment Interrupt type,
- * an increment of this type value below will generates
- * an interrupt, should be:
- * - RTC_TIMETYPE_SECOND
- * - RTC_TIMETYPE_MINUTE
- * - RTC_TIMETYPE_HOUR
- * - RTC_TIMETYPE_DAYOFWEEK
- * - RTC_TIMETYPE_DAYOFMONTH
- * - RTC_TIMETYPE_DAYOFYEAR
- * - RTC_TIMETYPE_MONTH
- * - RTC_TIMETYPE_YEAR
- * @param[in] NewState New State of this function, should be:
- * - ENABLE: Counter Increment interrupt for this
- * time type are enabled
- * - DISABLE: Counter Increment interrupt for this
- * time type are disabled
- * @return None
- **********************************************************************/
-void RTC_CntIncrIntConfig (LPC_RTC_TypeDef *RTCx, uint32_t CntIncrIntType, \
- FunctionalState NewState)
-{
- if (NewState == ENABLE)
- {
- switch (CntIncrIntType)
- {
- case RTC_TIMETYPE_SECOND:
- RTCx->CIIR |= RTC_CIIR_IMSEC;
- break;
- case RTC_TIMETYPE_MINUTE:
- RTCx->CIIR |= RTC_CIIR_IMMIN;
- break;
- case RTC_TIMETYPE_HOUR:
- RTCx->CIIR |= RTC_CIIR_IMHOUR;
- break;
- case RTC_TIMETYPE_DAYOFWEEK:
- RTCx->CIIR |= RTC_CIIR_IMDOW;
- break;
- case RTC_TIMETYPE_DAYOFMONTH:
- RTCx->CIIR |= RTC_CIIR_IMDOM;
- break;
- case RTC_TIMETYPE_DAYOFYEAR:
- RTCx->CIIR |= RTC_CIIR_IMDOY;
- break;
- case RTC_TIMETYPE_MONTH:
- RTCx->CIIR |= RTC_CIIR_IMMON;
- break;
- case RTC_TIMETYPE_YEAR:
- RTCx->CIIR |= RTC_CIIR_IMYEAR;
- break;
- }
- }
- else
- {
- switch (CntIncrIntType)
- {
- case RTC_TIMETYPE_SECOND:
- RTCx->CIIR &= (~RTC_CIIR_IMSEC) & RTC_CIIR_BITMASK;
- break;
- case RTC_TIMETYPE_MINUTE:
- RTCx->CIIR &= (~RTC_CIIR_IMMIN) & RTC_CIIR_BITMASK;
- break;
- case RTC_TIMETYPE_HOUR:
- RTCx->CIIR &= (~RTC_CIIR_IMHOUR) & RTC_CIIR_BITMASK;
- break;
- case RTC_TIMETYPE_DAYOFWEEK:
- RTCx->CIIR &= (~RTC_CIIR_IMDOW) & RTC_CIIR_BITMASK;
- break;
- case RTC_TIMETYPE_DAYOFMONTH:
- RTCx->CIIR &= (~RTC_CIIR_IMDOM) & RTC_CIIR_BITMASK;
- break;
- case RTC_TIMETYPE_DAYOFYEAR:
- RTCx->CIIR &= (~RTC_CIIR_IMDOY) & RTC_CIIR_BITMASK;
- break;
- case RTC_TIMETYPE_MONTH:
- RTCx->CIIR &= (~RTC_CIIR_IMMON) & RTC_CIIR_BITMASK;
- break;
- case RTC_TIMETYPE_YEAR:
- RTCx->CIIR &= (~RTC_CIIR_IMYEAR) & RTC_CIIR_BITMASK;
- break;
- }
- }
-}
-
-
-/*********************************************************************//**
- * @brief Enable/Disable Alarm interrupt for each time type
- * in RTC peripheral
- * @param[in] RTCx RTC peripheral selected, should be LPC_RTC
- * @param[in] AlarmTimeType: Alarm Time Interrupt type,
- * an matching of this type value below with current time
- * in RTC will generates an interrupt, should be:
- * - RTC_TIMETYPE_SECOND
- * - RTC_TIMETYPE_MINUTE
- * - RTC_TIMETYPE_HOUR
- * - RTC_TIMETYPE_DAYOFWEEK
- * - RTC_TIMETYPE_DAYOFMONTH
- * - RTC_TIMETYPE_DAYOFYEAR
- * - RTC_TIMETYPE_MONTH
- * - RTC_TIMETYPE_YEAR
- * @param[in] NewState New State of this function, should be:
- * - ENABLE: Alarm interrupt for this
- * time type are enabled
- * - DISABLE: Alarm interrupt for this
- * time type are disabled
- * @return None
- **********************************************************************/
-void RTC_AlarmIntConfig (LPC_RTC_TypeDef *RTCx, uint32_t AlarmTimeType, \
- FunctionalState NewState)
-{
- if (NewState == ENABLE)
- {
- switch (AlarmTimeType)
- {
- case RTC_TIMETYPE_SECOND:
- RTCx->AMR &= (~RTC_AMR_AMRSEC) & RTC_AMR_BITMASK;
- break;
- case RTC_TIMETYPE_MINUTE:
- RTCx->AMR &= (~RTC_AMR_AMRMIN) & RTC_AMR_BITMASK;
- break;
- case RTC_TIMETYPE_HOUR:
- RTCx->AMR &= (~RTC_AMR_AMRHOUR) & RTC_AMR_BITMASK;
- break;
- case RTC_TIMETYPE_DAYOFWEEK:
- RTCx->AMR &= (~RTC_AMR_AMRDOW) & RTC_AMR_BITMASK;
- break;
- case RTC_TIMETYPE_DAYOFMONTH:
- RTCx->AMR &= (~RTC_AMR_AMRDOM) & RTC_AMR_BITMASK;
- break;
- case RTC_TIMETYPE_DAYOFYEAR:
- RTCx->AMR &= (~RTC_AMR_AMRDOY) & RTC_AMR_BITMASK;
- break;
- case RTC_TIMETYPE_MONTH:
- RTCx->AMR &= (~RTC_AMR_AMRMON) & RTC_AMR_BITMASK;
- break;
- case RTC_TIMETYPE_YEAR:
- RTCx->AMR &= (~RTC_AMR_AMRYEAR) & RTC_AMR_BITMASK;
- break;
- }
- }
- else
- {
- switch (AlarmTimeType)
- {
- case RTC_TIMETYPE_SECOND:
- RTCx->AMR |= (RTC_AMR_AMRSEC);
- break;
- case RTC_TIMETYPE_MINUTE:
- RTCx->AMR |= (RTC_AMR_AMRMIN);
- break;
- case RTC_TIMETYPE_HOUR:
- RTCx->AMR |= (RTC_AMR_AMRHOUR);
- break;
- case RTC_TIMETYPE_DAYOFWEEK:
- RTCx->AMR |= (RTC_AMR_AMRDOW);
- break;
- case RTC_TIMETYPE_DAYOFMONTH:
- RTCx->AMR |= (RTC_AMR_AMRDOM);
- break;
- case RTC_TIMETYPE_DAYOFYEAR:
- RTCx->AMR |= (RTC_AMR_AMRDOY);
- break;
- case RTC_TIMETYPE_MONTH:
- RTCx->AMR |= (RTC_AMR_AMRMON);
- break;
- case RTC_TIMETYPE_YEAR:
- RTCx->AMR |= (RTC_AMR_AMRYEAR);
- break;
- }
- }
-}
-
-
-/*********************************************************************//**
- * @brief Set current time value for each time type in RTC peripheral
- * @param[in] RTCx RTC peripheral selected, should be LPC_RTC
- * @param[in] Timetype: Time Type, should be:
- * - RTC_TIMETYPE_SECOND
- * - RTC_TIMETYPE_MINUTE
- * - RTC_TIMETYPE_HOUR
- * - RTC_TIMETYPE_DAYOFWEEK
- * - RTC_TIMETYPE_DAYOFMONTH
- * - RTC_TIMETYPE_DAYOFYEAR
- * - RTC_TIMETYPE_MONTH
- * - RTC_TIMETYPE_YEAR
- * @param[in] TimeValue Time value to set
- * @return None
- **********************************************************************/
-void RTC_SetTime (LPC_RTC_TypeDef *RTCx, uint32_t Timetype, uint32_t TimeValue)
-{
- switch ( Timetype)
- {
- case RTC_TIMETYPE_SECOND:
- if(TimeValue <= RTC_SECOND_MAX)
- RTCx->SEC = TimeValue & RTC_SEC_MASK;
- break;
-
- case RTC_TIMETYPE_MINUTE:
- if(TimeValue <= RTC_MINUTE_MAX)
- RTCx->MIN = TimeValue & RTC_MIN_MASK;
- break;
-
- case RTC_TIMETYPE_HOUR:
- if(TimeValue <= RTC_HOUR_MAX)
- RTCx->HOUR = TimeValue & RTC_HOUR_MASK;
- break;
-
- case RTC_TIMETYPE_DAYOFWEEK:
- if(TimeValue <= RTC_DAYOFWEEK_MAX)
- RTCx->DOW = TimeValue & RTC_DOW_MASK;
- break;
-
- case RTC_TIMETYPE_DAYOFMONTH:
- if((TimeValue >= RTC_DAYOFMONTH_MIN)&&(TimeValue <= RTC_DAYOFMONTH_MAX))
- RTCx->DOM = TimeValue & RTC_DOM_MASK;
- break;
-
- case RTC_TIMETYPE_DAYOFYEAR:
- if((TimeValue >= RTC_DAYOFYEAR_MIN)&&(TimeValue <= RTC_DAYOFYEAR_MAX))
- RTCx->DOY = TimeValue & RTC_DOY_MASK;
- break;
-
- case RTC_TIMETYPE_MONTH:
- if((TimeValue >= RTC_MONTH_MIN)&&(TimeValue <= RTC_MONTH_MAX))
- RTCx->MONTH = TimeValue & RTC_MONTH_MASK;
- break;
-
- case RTC_TIMETYPE_YEAR:
- if(TimeValue <= RTC_YEAR_MAX)
- RTCx->YEAR = TimeValue & RTC_YEAR_MASK;
- break;
- }
-}
-
-/*********************************************************************//**
- * @brief Get current time value for each type time type
- * @param[in] RTCx RTC peripheral selected, should be LPC_RTC
- * @param[in] Timetype: Time Type, should be:
- * - RTC_TIMETYPE_SECOND
- * - RTC_TIMETYPE_MINUTE
- * - RTC_TIMETYPE_HOUR
- * - RTC_TIMETYPE_DAYOFWEEK
- * - RTC_TIMETYPE_DAYOFMONTH
- * - RTC_TIMETYPE_DAYOFYEAR
- * - RTC_TIMETYPE_MONTH
- * - RTC_TIMETYPE_YEAR
- * @return Value of time according to specified time type
- **********************************************************************/
-uint32_t RTC_GetTime(LPC_RTC_TypeDef *RTCx, uint32_t Timetype)
-{
- switch (Timetype)
- {
- case RTC_TIMETYPE_SECOND:
- return (RTCx->SEC & RTC_SEC_MASK);
- case RTC_TIMETYPE_MINUTE:
- return (RTCx->MIN & RTC_MIN_MASK);
- case RTC_TIMETYPE_HOUR:
- return (RTCx->HOUR & RTC_HOUR_MASK);
- case RTC_TIMETYPE_DAYOFWEEK:
- return (RTCx->DOW & RTC_DOW_MASK);
- case RTC_TIMETYPE_DAYOFMONTH:
- return (RTCx->DOM & RTC_DOM_MASK);
- case RTC_TIMETYPE_DAYOFYEAR:
- return (RTCx->DOY & RTC_DOY_MASK);
- case RTC_TIMETYPE_MONTH:
- return (RTCx->MONTH & RTC_MONTH_MASK);
- case RTC_TIMETYPE_YEAR:
- return (RTCx->YEAR & RTC_YEAR_MASK);
- default:
- return (0);
- }
-}
-
-
-/*********************************************************************//**
- * @brief Set full of time in RTC peripheral
- * @param[in] RTCx RTC peripheral selected, should be LPC_RTC
- * @param[in] pFullTime Pointer to a RTC_TIME_Type structure that
- * contains time value in full.
- * @return None
- **********************************************************************/
-void RTC_SetFullTime (LPC_RTC_TypeDef *RTCx, RTC_TIME_Type *pFullTime)
-{
- RTCx->DOM = pFullTime->DOM & RTC_DOM_MASK;
- RTCx->DOW = pFullTime->DOW & RTC_DOW_MASK;
- RTCx->DOY = pFullTime->DOY & RTC_DOY_MASK;
- RTCx->HOUR = pFullTime->HOUR & RTC_HOUR_MASK;
- RTCx->MIN = pFullTime->MIN & RTC_MIN_MASK;
- RTCx->SEC = pFullTime->SEC & RTC_SEC_MASK;
- RTCx->MONTH = pFullTime->MONTH & RTC_MONTH_MASK;
- RTCx->YEAR = pFullTime->YEAR & RTC_YEAR_MASK;
-}
-
-
-/*********************************************************************//**
- * @brief Get full of time in RTC peripheral
- * @param[in] RTCx RTC peripheral selected, should be LPC_RTC
- * @param[in] pFullTime Pointer to a RTC_TIME_Type structure that
- * will be stored time in full.
- * @return None
- **********************************************************************/
-void RTC_GetFullTime (LPC_RTC_TypeDef *RTCx, RTC_TIME_Type *pFullTime)
-{
- pFullTime->DOM = RTCx->DOM & RTC_DOM_MASK;
- pFullTime->DOW = RTCx->DOW & RTC_DOW_MASK;
- pFullTime->DOY = RTCx->DOY & RTC_DOY_MASK;
- pFullTime->HOUR = RTCx->HOUR & RTC_HOUR_MASK;
- pFullTime->MIN = RTCx->MIN & RTC_MIN_MASK;
- pFullTime->SEC = RTCx->SEC & RTC_SEC_MASK;
- pFullTime->MONTH = RTCx->MONTH & RTC_MONTH_MASK;
- pFullTime->YEAR = RTCx->YEAR & RTC_YEAR_MASK;
-}
-
-
-/*********************************************************************//**
- * @brief Set alarm time value for each time type
- * @param[in] RTCx RTC peripheral selected, should be LPC_RTC
- * @param[in] Timetype: Time Type, should be:
- * - RTC_TIMETYPE_SECOND
- * - RTC_TIMETYPE_MINUTE
- * - RTC_TIMETYPE_HOUR
- * - RTC_TIMETYPE_DAYOFWEEK
- * - RTC_TIMETYPE_DAYOFMONTH
- * - RTC_TIMETYPE_DAYOFYEAR
- * - RTC_TIMETYPE_MONTH
- * - RTC_TIMETYPE_YEAR
- * @param[in] ALValue Alarm time value to set
- * @return None
- **********************************************************************/
-void RTC_SetAlarmTime (LPC_RTC_TypeDef *RTCx, uint32_t Timetype, uint32_t ALValue)
-{
- switch (Timetype)
- {
- case RTC_TIMETYPE_SECOND:
- if(ALValue <= RTC_SECOND_MAX)
- RTCx->ALSEC = ALValue & RTC_SEC_MASK;
- break;
-
- case RTC_TIMETYPE_MINUTE:
- if(ALValue <= RTC_MINUTE_MAX)
- RTCx->ALMIN = ALValue & RTC_MIN_MASK;
- break;
-
- case RTC_TIMETYPE_HOUR:
- if(ALValue <= RTC_HOUR_MAX)
- RTCx->ALHOUR = ALValue & RTC_HOUR_MASK;
- break;
-
- case RTC_TIMETYPE_DAYOFWEEK:
- if(ALValue <= RTC_DAYOFWEEK_MAX)
- RTCx->ALDOW = ALValue & RTC_DOW_MASK;
- break;
-
- case RTC_TIMETYPE_DAYOFMONTH:
- if((ALValue >= RTC_DAYOFMONTH_MIN)&&(ALValue <= RTC_DAYOFMONTH_MAX))
- RTCx->ALDOM = ALValue & RTC_DOM_MASK;
- break;
-
- case RTC_TIMETYPE_DAYOFYEAR:
- if((ALValue >= RTC_DAYOFYEAR_MIN)&&(ALValue <= RTC_DAYOFYEAR_MAX))
- RTCx->ALDOY = ALValue & RTC_DOY_MASK;
- break;
-
- case RTC_TIMETYPE_MONTH:
- if((ALValue >= RTC_MONTH_MIN)&&(ALValue <= RTC_MONTH_MAX))
- RTCx->ALMON = ALValue & RTC_MONTH_MASK;
- break;
-
- case RTC_TIMETYPE_YEAR:
- if(ALValue <= RTC_YEAR_MAX)
- RTCx->ALYEAR = ALValue & RTC_YEAR_MASK;
- break;
- }
-}
-
-
-
-/*********************************************************************//**
- * @brief Get alarm time value for each time type
- * @param[in] RTCx RTC peripheral selected, should be LPC_RTC
- * @param[in] Timetype: Time Type, should be:
- * - RTC_TIMETYPE_SECOND
- * - RTC_TIMETYPE_MINUTE
- * - RTC_TIMETYPE_HOUR
- * - RTC_TIMETYPE_DAYOFWEEK
- * - RTC_TIMETYPE_DAYOFMONTH
- * - RTC_TIMETYPE_DAYOFYEAR
- * - RTC_TIMETYPE_MONTH
- * - RTC_TIMETYPE_YEAR
- * @return Value of Alarm time according to specified time type
- **********************************************************************/
-uint32_t RTC_GetAlarmTime (LPC_RTC_TypeDef *RTCx, uint32_t Timetype)
-{
- switch (Timetype)
- {
- case RTC_TIMETYPE_SECOND:
- return (RTCx->ALSEC & RTC_SEC_MASK);
- case RTC_TIMETYPE_MINUTE:
- return (RTCx->ALMIN & RTC_MIN_MASK);
- case RTC_TIMETYPE_HOUR:
- return (RTCx->ALHOUR & RTC_HOUR_MASK);
- case RTC_TIMETYPE_DAYOFWEEK:
- return (RTCx->ALDOW & RTC_DOW_MASK);
- case RTC_TIMETYPE_DAYOFMONTH:
- return (RTCx->ALDOM & RTC_DOM_MASK);
- case RTC_TIMETYPE_DAYOFYEAR:
- return (RTCx->ALDOY & RTC_DOY_MASK);
- case RTC_TIMETYPE_MONTH:
- return (RTCx->ALMON & RTC_MONTH_MASK);
- case RTC_TIMETYPE_YEAR:
- return (RTCx->ALYEAR & RTC_YEAR_MASK);
- default:
- return (0);
- }
-}
-
-
-/*********************************************************************//**
- * @brief Set full of alarm time in RTC peripheral
- * @param[in] RTCx RTC peripheral selected, should be LPC_RTC
- * @param[in] pFullTime Pointer to a RTC_TIME_Type structure that
- * contains alarm time value in full.
- * @return None
- **********************************************************************/
-void RTC_SetFullAlarmTime (LPC_RTC_TypeDef *RTCx, RTC_TIME_Type *pFullTime)
-{
- RTCx->ALDOM = pFullTime->DOM & RTC_DOM_MASK;
- RTCx->ALDOW = pFullTime->DOW & RTC_DOW_MASK;
- RTCx->ALDOY = pFullTime->DOY & RTC_DOY_MASK;
- RTCx->ALHOUR = pFullTime->HOUR & RTC_HOUR_MASK;
- RTCx->ALMIN = pFullTime->MIN & RTC_MIN_MASK;
- RTCx->ALSEC = pFullTime->SEC & RTC_SEC_MASK;
- RTCx->ALMON = pFullTime->MONTH & RTC_MONTH_MASK;
- RTCx->ALYEAR = pFullTime->YEAR & RTC_YEAR_MASK;
-}
-
-
-/*********************************************************************//**
- * @brief Get full of alarm time in RTC peripheral
- * @param[in] RTCx RTC peripheral selected, should be LPC_RTC
- * @param[in] pFullTime Pointer to a RTC_TIME_Type structure that
- * will be stored alarm time in full.
- * @return None
- **********************************************************************/
-void RTC_GetFullAlarmTime (LPC_RTC_TypeDef *RTCx, RTC_TIME_Type *pFullTime)
-{
- pFullTime->DOM = RTCx->ALDOM & RTC_DOM_MASK;
- pFullTime->DOW = RTCx->ALDOW & RTC_DOW_MASK;
- pFullTime->DOY = RTCx->ALDOY & RTC_DOY_MASK;
- pFullTime->HOUR = RTCx->ALHOUR & RTC_HOUR_MASK;
- pFullTime->MIN = RTCx->ALMIN & RTC_MIN_MASK;
- pFullTime->SEC = RTCx->ALSEC & RTC_SEC_MASK;
- pFullTime->MONTH = RTCx->ALMON & RTC_MONTH_MASK;
- pFullTime->YEAR = RTCx->ALYEAR & RTC_YEAR_MASK;
-}
-
-
-/*********************************************************************//**
- * @brief Check whether if specified Location interrupt in
- * RTC peripheral is set or not
- * @param[in] RTCx RTC peripheral selected, should be LPC_RTC
- * @param[in] IntType Interrupt location type, should be:
- * - RTC_INT_COUNTER_INCREASE: Counter Increment Interrupt
- * block generated an interrupt.
- * - RTC_INT_ALARM: Alarm generated an
- * interrupt.
- * @return New state of specified Location interrupt in RTC peripheral
- * (SET or RESET)
- **********************************************************************/
-IntStatus RTC_GetIntPending (LPC_RTC_TypeDef *RTCx, uint32_t IntType)
-{
- return ((RTCx->ILR & IntType) ? SET : RESET);
-}
-
-
-/*********************************************************************//**
- * @brief Clear specified Location interrupt pending in
- * RTC peripheral
- * @param[in] RTCx RTC peripheral selected, should be LPC_RTC
- * @param[in] IntType Interrupt location type, should be:
- * - RTC_INT_COUNTER_INCREASE: Clear Counter Increment
- * Interrupt pending.
- * - RTC_INT_ALARM: Clear alarm interrupt pending
- * @return None
- **********************************************************************/
-void RTC_ClearIntPending (LPC_RTC_TypeDef *RTCx, uint32_t IntType)
-{
- RTCx->ILR |= IntType;
-}
-
-/*********************************************************************//**
- * @brief Enable/Disable calibration counter in RTC peripheral
- * @param[in] RTCx RTC peripheral selected, should be LPC_RTC
- * @param[in] NewState New State of this function, should be:
- * - ENABLE: The calibration counter is enabled and counting
- * - DISABLE: The calibration counter is disabled and reset to zero
- * @return None
- **********************************************************************/
-void RTC_CalibCounterCmd(LPC_RTC_TypeDef *RTCx, FunctionalState NewState)
-{
- if (NewState == ENABLE)
- {
- RTCx->CCR &= (~RTC_CCR_CCALEN) & RTC_CCR_BITMASK;
- }
- else
- {
- RTCx->CCR |= RTC_CCR_CCALEN;
- }
-}
-
-
-/*********************************************************************//**
- * @brief Configures Calibration in RTC peripheral
- * @param[in] RTCx RTC peripheral selected, should be LPC_RTC
- * @param[in] CalibValue Calibration value, should be in range from
- * 0 to 131,072
- * @param[in] CalibDir Calibration Direction, should be:
- * - RTC_CALIB_DIR_FORWARD: Forward calibration
- * - RTC_CALIB_DIR_BACKWARD: Backward calibration
- * @return None
- **********************************************************************/
-void RTC_CalibConfig(LPC_RTC_TypeDef *RTCx, uint32_t CalibValue, uint8_t CalibDir)
-{
- RTCx->CALIBRATION = ((CalibValue) & RTC_CALIBRATION_CALVAL_MASK) \
- | ((CalibDir == RTC_CALIB_DIR_BACKWARD) ? RTC_CALIBRATION_LIBDIR : 0);
-}
-
-
-/*********************************************************************//**
- * @brief Write value to General purpose registers
- * @param[in] RTCx RTC peripheral selected, should be LPC_RTC
- * @param[in] Channel General purpose registers Channel number,
- * should be in range from 0 to 4.
- * @param[in] Value Value to write
- * @return None
- * Note: These General purpose registers can be used to store important
- * information when the main power supply is off. The value in these
- * registers is not affected by chip reset.
- **********************************************************************/
-void RTC_WriteGPREG (LPC_RTC_TypeDef *RTCx, uint8_t Channel, uint32_t Value)
-{
- uint32_t *preg;
-
- preg = (uint32_t *)&RTCx->GPREG0;
- preg += Channel;
- *preg = Value;
-}
-
-
-/*********************************************************************//**
- * @brief Read value from General purpose registers
- * @param[in] RTCx RTC peripheral selected, should be LPC_RTC
- * @param[in] Channel General purpose registers Channel number,
- * should be in range from 0 to 4.
- * @return Read Value
- * Note: These General purpose registers can be used to store important
- * information when the main power supply is off. The value in these
- * registers is not affected by chip reset.
- **********************************************************************/
-uint32_t RTC_ReadGPREG (LPC_RTC_TypeDef *RTCx, uint8_t Channel)
-{
- uint32_t *preg;
- uint32_t value;
-
- preg = (uint32_t *)&RTCx->GPREG0;
- preg += Channel;
- value = *preg;
- return (value);
-}
-/*********************************************************************//**
- * @brief Initialize an variable of type RTC_ER_CONFIG_Type.
- * @param[in] pConfig The address of input variable.
- * @return None
- **********************************************************************/
-void RTC_ER_InitConfigStruct(RTC_ER_CONFIG_Type* pConfig)
-{
- uint32_t tmp;
- if(pConfig == NULL)
- return;
-
- for(tmp = 0; tmp < RTC_ER_INPUT_CHANNEL_NUM; tmp++)
- {
- pConfig->InputChannel[tmp].EventOnPosEdge = FALSE;
- pConfig->InputChannel[tmp].GPClear= FALSE;
- pConfig->InputChannel[tmp].IntWake= FALSE;
- }
- pConfig->Clk = 64;
-}
-
-/*********************************************************************//**
- * @brief Initialize Event Monitor/Recorder
- * @param[in] pConfig Configuration
- * @return SUCCESS/ERROR
- * Note: The RTC Module must be intialized before initializing this module.
- **********************************************************************/
-Status RTC_ER_Init(RTC_ER_CONFIG_Type* pConfig)
-{
- if(pConfig == NULL)
- return ERROR;
- if((LPC_RTC->CCR & RTC_CCR_CLKEN) == 0)
- return ERROR;
-
- /* EV0 */
- if(pConfig->InputChannel[0].EventOnPosEdge)
- LPC_RTC->ERCONTROL |= RTC_ERCTRL_EV0_POS_EDGE;
- else
- LPC_RTC->ERCONTROL &= ~RTC_ERCTRL_EV0_POS_EDGE;
-
- if(pConfig->InputChannel[0].IntWake)
- LPC_RTC->ERCONTROL |= RTC_ERCTRL_EV0_INTWAKE_ENABLE;
- else
- LPC_RTC->ERCONTROL &= ~RTC_ERCTRL_EV0_INTWAKE_ENABLE;
-
- if(pConfig->InputChannel[0].GPClear)
- LPC_RTC->ERCONTROL |= RTC_ERCTRL_EV0_GPCLEAR_ENABLE;
- else
- LPC_RTC->ERCONTROL &= ~RTC_ERCTRL_EV0_GPCLEAR_ENABLE;
-
- /* EV1 */
- if(pConfig->InputChannel[1].EventOnPosEdge)
- LPC_RTC->ERCONTROL |= RTC_ERCTRL_EV1_POS_EDGE;
- else
- LPC_RTC->ERCONTROL &= ~RTC_ERCTRL_EV1_POS_EDGE;
-
- if(pConfig->InputChannel[1].IntWake)
- LPC_RTC->ERCONTROL |= RTC_ERCTRL_EV1_INTWAKE_ENABLE;
- else
- LPC_RTC->ERCONTROL &= ~RTC_ERCTRL_EV1_INTWAKE_ENABLE;
-
- if(pConfig->InputChannel[1].GPClear)
- LPC_RTC->ERCONTROL |= RTC_ERCTRL_EV1_GPCLEAR_ENABLE;
- else
- LPC_RTC->ERCONTROL &= ~RTC_ERCTRL_EV1_GPCLEAR_ENABLE;
-
- /* EV2 */
- if(pConfig->InputChannel[2].EventOnPosEdge)
- LPC_RTC->ERCONTROL |= RTC_ERCTRL_EV2_POS_EDGE;
- else
- LPC_RTC->ERCONTROL &= ~RTC_ERCTRL_EV2_POS_EDGE;
-
- if(pConfig->InputChannel[2].IntWake)
- LPC_RTC->ERCONTROL |= RTC_ERCTRL_EV2_INTWAKE_ENABLE;
- else
- LPC_RTC->ERCONTROL &= ~RTC_ERCTRL_EV2_INTWAKE_ENABLE;
-
- if(pConfig->InputChannel[2].GPClear)
- LPC_RTC->ERCONTROL |= RTC_ERCTRL_EV2_GPCLEAR_ENABLE;
- else
- LPC_RTC->ERCONTROL &= ~RTC_ERCTRL_EV2_GPCLEAR_ENABLE;
-
- /* Sample Clock */
- LPC_RTC->ERCONTROL &= ~RTC_ERCTRL_MODE_MASK;
- switch(pConfig->Clk)
- {
- case 0:
- LPC_RTC->ERCONTROL |= RTC_ERCTRL_MODE_CLK_DISABLE;
- break;
- case 16:
- LPC_RTC->ERCONTROL |= RTC_ERCTRL_MODE_16HZ;
- break;
- case 64:
- LPC_RTC->ERCONTROL |= RTC_ERCTRL_MODE_64HZ;
- break;
- case 1000:
- LPC_RTC->ERCONTROL |= RTC_ERCTRL_MODE_1KHZ;
- break;
- default:
- return ERROR;
- }
- return SUCCESS;
-}
-/*********************************************************************//**
- * @brief Enable/Disable a input channel for Event Monitor/Recorder
- * @param[in] channel Channel Number. It should be 0~2
- * @param[in]state ENABLE/DISABLE
- * @return SUCCESS/ERROR
- **********************************************************************/
-Status RTC_ER_Cmd(uint8_t channel, FunctionalState state)
-{
- switch(channel)
- {
- case 0:
- if(state)
- LPC_RTC->ERCONTROL |= RTC_ERCTRL_EV0_INPUT_ENABLE;
- else
- LPC_RTC->ERCONTROL &= ~RTC_ERCTRL_EV0_INPUT_ENABLE;
- break;
- case 1:
- if(state)
- LPC_RTC->ERCONTROL |= RTC_ERCTRL_EV1_INPUT_ENABLE;
- else
- LPC_RTC->ERCONTROL &= ~RTC_ERCTRL_EV1_INPUT_ENABLE;
- break;
- case 2:
- if(state)
- LPC_RTC->ERCONTROL |= RTC_ERCTRL_EV2_INPUT_ENABLE;
- else
- LPC_RTC->ERCONTROL &= ~RTC_ERCTRL_EV2_INPUT_ENABLE;
- break;
- default:
- return ERROR;
- }
- return SUCCESS;
-}
-/*********************************************************************//**
- * @brief Get event count on a given channel.
- * @param[in] channel Channel Number. It should be 0~2
- * @return counter
- **********************************************************************/
-uint8_t RTC_ER_GetEventCount(uint8_t channel)
-{
- uint8_t count = 0;
- switch(channel)
- {
- case 0:
- count = RTC_ER_EV0_COUNTER(LPC_RTC->ERCOUNTERS);
- break;
- case 1:
- count = RTC_ER_EV1_COUNTER(LPC_RTC->ERCOUNTERS);
- break;
- case 2:
- count = RTC_ER_EV2_COUNTER(LPC_RTC->ERCOUNTERS);
- break;
- default:
- break;
- }
- return count;
-}
-/*********************************************************************//**
- * @brief Get Event Monirot/Recorder Status.
- * @param[in] None
- * @return Status. It can includes:
- * RTC_ER_EVENTS_ON_EV0_FLG
- * RTC_ER_EVENTS_ON_EV1_FLG
- * RTC_ER_EVENTS_ON_EV2_FLG
- * RTC_ER_STATUS_GP_CLEARED_FLG
- * RTC_ER_STATUS_WAKEUP_REQ_PENDING
- **********************************************************************/
-uint32_t RTC_ER_GetStatus(void)
-{
- return LPC_RTC->ERSTATUS;
-}
-/*********************************************************************//**
- * @brief Clear Event Monitor/recoder status register.
- * @param[in] status Status Flag. It should be:
- * RTC_ER_EVENTS_ON_EV0_FLG
- * RTC_ER_EVENTS_ON_EV1_FLG
- * RTC_ER_EVENTS_ON_EV2_FLG
- * RTC_ER_STATUS_GP_CLEARED_FLG
- * RTC_ER_STATUS_WAKEUP_REQ_PENDING
- * @return None
- **********************************************************************/
-void RTC_ER_ClearStatus(uint32_t status)
-{
- LPC_RTC->ERSTATUS |= status;
-}
-/*********************************************************************//**
- * @brief Check whether a Wakup request is pending or not.
- * @param[in] None
- * @return TRUE/FALSE
- **********************************************************************/
-Bool RTC_ER_WakupReqPending(void)
-{
- if(LPC_RTC->ERSTATUS & RTC_ER_STATUS_WAKEUP_REQ_PENDING)
- return TRUE;
- else
- return FALSE;
-}
-/*********************************************************************//**
- * @brief Check whether RTC General Purpose registed has been cleared or not.
- * @param[in] None
- * @return TRUE/FALSE
- **********************************************************************/
-Bool RTC_ER_GPCleared(void)
-{
- if(LPC_RTC->ERSTATUS & RTC_ER_STATUS_GP_CLEARED_FLG)
- return TRUE;
- else
- return FALSE;
-}
-/*********************************************************************//**
- * @brief Get the timestamp of the fist event on a given channel.
- * @param[in] channel Channel number (It should be 0~2)
- * @param[in] pTimeStamp point to the buffer
- * @return SUCCESS/ERROR
- **********************************************************************/
-Status RTC_ER_GetFirstTimeStamp(uint8_t channel, RTC_ER_TIMESTAMP_Type* pTimeStamp)
-{
- if(pTimeStamp == NULL)
- return ERROR;
-
- switch(channel)
- {
- case 0:
- if((LPC_RTC->ERSTATUS & (1<<RTC_ER_STATUS_EV0_BIT)) == 0)
- return ERROR;
- pTimeStamp->SEC = RTC_ER_TIMESTAMP_SEC(LPC_RTC->ERFIRSTSTAMP0);
- pTimeStamp->MIN= RTC_ER_TIMESTAMP_MIN(LPC_RTC->ERFIRSTSTAMP0);
- pTimeStamp->HOUR= RTC_ER_TIMESTAMP_HOUR(LPC_RTC->ERFIRSTSTAMP0);
- pTimeStamp->DOY = RTC_ER_TIMESTAMP_DOY(LPC_RTC->ERFIRSTSTAMP0);
- break;
- case 1:
- if((LPC_RTC->ERSTATUS & (1<<RTC_ER_STATUS_EV1_BIT)) == 0)
- return ERROR;
- pTimeStamp->SEC = RTC_ER_TIMESTAMP_SEC(LPC_RTC->ERFIRSTSTAMP1);
- pTimeStamp->MIN= RTC_ER_TIMESTAMP_MIN(LPC_RTC->ERFIRSTSTAMP1);
- pTimeStamp->HOUR= RTC_ER_TIMESTAMP_HOUR(LPC_RTC->ERFIRSTSTAMP1);
- pTimeStamp->DOY = RTC_ER_TIMESTAMP_DOY(LPC_RTC->ERFIRSTSTAMP1);
- break;
- case 2:
- if((LPC_RTC->ERSTATUS & (1<<RTC_ER_STATUS_EV2_BIT)) == 0)
- return ERROR;
- pTimeStamp->SEC = RTC_ER_TIMESTAMP_SEC(LPC_RTC->ERFIRSTSTAMP2);
- pTimeStamp->MIN= RTC_ER_TIMESTAMP_MIN(LPC_RTC->ERFIRSTSTAMP2);
- pTimeStamp->HOUR= RTC_ER_TIMESTAMP_HOUR(LPC_RTC->ERFIRSTSTAMP2);
- pTimeStamp->DOY = RTC_ER_TIMESTAMP_DOY(LPC_RTC->ERFIRSTSTAMP2);
- break;
- default:
- break;
- }
- return SUCCESS;
-
-}
-/*********************************************************************//**
- * @brief Get the timestamp of the last event on a given channel.
- * @param[in] channel Channel number (It should be 0~2)
- * @param[in] pTimeStamp point to the buffer
- * @return SUCCESS/ERROR
- **********************************************************************/
-Status RTC_ER_GetLastTimeStamp(uint8_t channel, RTC_ER_TIMESTAMP_Type* pTimeStamp)
-{
- if(pTimeStamp == NULL)
- return ERROR;
-
- switch(channel)
- {
- case 0:
- if((LPC_RTC->ERSTATUS & (1<<RTC_ER_STATUS_EV0_BIT)) == 0)
- return ERROR;
- pTimeStamp->SEC = RTC_ER_TIMESTAMP_SEC(LPC_RTC->ERLASTSTAMP0);
- pTimeStamp->MIN= RTC_ER_TIMESTAMP_MIN(LPC_RTC->ERLASTSTAMP0);
- pTimeStamp->HOUR= RTC_ER_TIMESTAMP_HOUR(LPC_RTC->ERLASTSTAMP0);
- pTimeStamp->DOY = RTC_ER_TIMESTAMP_DOY(LPC_RTC->ERLASTSTAMP0);
- break;
- case 1:
- if((LPC_RTC->ERSTATUS & (1<<RTC_ER_STATUS_EV1_BIT)) == 0)
- return ERROR;
- pTimeStamp->SEC = RTC_ER_TIMESTAMP_SEC(LPC_RTC->ERLASTSTAMP1);
- pTimeStamp->MIN= RTC_ER_TIMESTAMP_MIN(LPC_RTC->ERLASTSTAMP1);
- pTimeStamp->HOUR= RTC_ER_TIMESTAMP_HOUR(LPC_RTC->ERLASTSTAMP1);
- pTimeStamp->DOY = RTC_ER_TIMESTAMP_DOY(LPC_RTC->ERLASTSTAMP1);
- break;
- case 2:
- if((LPC_RTC->ERSTATUS & (1<<RTC_ER_STATUS_EV2_BIT)) == 0)
- return ERROR;
- pTimeStamp->SEC = RTC_ER_TIMESTAMP_SEC(LPC_RTC->ERLASTSTAMP2);
- pTimeStamp->MIN= RTC_ER_TIMESTAMP_MIN(LPC_RTC->ERLASTSTAMP2);
- pTimeStamp->HOUR= RTC_ER_TIMESTAMP_HOUR(LPC_RTC->ERLASTSTAMP2);
- pTimeStamp->DOY = RTC_ER_TIMESTAMP_DOY(LPC_RTC->ERLASTSTAMP2);
- break;
- default:
- break;
- }
- return SUCCESS;
-
-}
-
-
-/**
- * @}
- */
-
-#endif /*_RTC*/
-/**
- * @}
- */
-
-/* --------------------------------- End Of File ------------------------------ */
-
diff --git a/bsp/lpc408x/Libraries/Drivers/source/lpc_ssp.c b/bsp/lpc408x/Libraries/Drivers/source/lpc_ssp.c
deleted file mode 100644
index f197e5b4e4..0000000000
--- a/bsp/lpc408x/Libraries/Drivers/source/lpc_ssp.c
+++ /dev/null
@@ -1,644 +0,0 @@
-/**********************************************************************
-* $Id$ lpc_ssp.c 2011-06-02
-*//**
-* @file lpc_ssp.c
-* @brief Contains all functions support for SSP firmware library
-* on LPC
-* @version 1.0
-* @date 02. June. 2011
-* @author NXP MCU SW Application Team
-*
-* Copyright(C) 2011, NXP Semiconductor
-* All rights reserved.
-*
-***********************************************************************
-* Software that is described herein is for illustrative purposes only
-* which provides customers with programming information regarding the
-* products. This software is supplied "AS IS" without any warranties.
-* NXP Semiconductors assumes no responsibility or liability for the
-* use of the software, conveys no license or title under any patent,
-* copyright, or mask work right to the product. NXP Semiconductors
-* reserves the right to make changes in the software without
-* notification. NXP Semiconductors also make 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'
-* relevant copyright 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.
-**********************************************************************/
-
-/* Peripheral group ----------------------------------------------------------- */
-/** @addtogroup SSP
- * @{
- */
-#ifdef __BUILD_WITH_EXAMPLE__
-#include "lpc_libcfg.h"
-#else
-#include "lpc_libcfg_default.h"
-#endif /* __BUILD_WITH_EXAMPLE__ */
-#ifdef _SSP
-
-/* Includes ------------------------------------------------------------------- */
-#include "lpc_ssp.h"
-#include "lpc_clkpwr.h"
-
-/* Public Functions ----------------------------------------------------------- */
-/** @addtogroup SSP_Public_Functions
- * @{
- */
-static void setSSPclock (LPC_SSP_TypeDef *SSPx, uint32_t target_clock);
-
-/*********************************************************************//**
- * @brief Setup clock rate for SSP device
- * @param[in] SSPx SSP peripheral definition, should be:
- * - LPC_SSP0: SSP0 peripheral
- * - LPC_SSP1: SSP1 peripheral
- * @param[in] target_clock : clock of SSP (Hz)
- * @return None
- ***********************************************************************/
-static void setSSPclock (LPC_SSP_TypeDef *SSPx, uint32_t target_clock)
-{
- uint32_t prescale, cr0_div, cmp_clk, ssp_clk;
- ssp_clk = CLKPWR_GetCLK (CLKPWR_CLKTYPE_PER);
-
- /* Find closest divider to get at or under the target frequency.
- Use smallest prescale possible and rely on the divider to get
- the closest target frequency */
- cr0_div = 0;
- cmp_clk = 0xFFFFFFFF;
- prescale = 2;
- while (cmp_clk > target_clock)
- {
- cmp_clk = ssp_clk / ((cr0_div + 1) * prescale);
- if (cmp_clk > target_clock)
- {
- cr0_div++;
- if (cr0_div > 0xFF)
- {
- cr0_div = 0;
- prescale += 2;
- }
- }
- }
-
- /* Write computed prescaler and divider back to register */
- SSPx->CR0 &= (~SSP_CR0_SCR(0xFF)) & SSP_CR0_BITMASK;
- SSPx->CR0 |= (SSP_CR0_SCR(cr0_div)) & SSP_CR0_BITMASK;
- SSPx->CPSR = prescale & SSP_CPSR_BITMASK;
-}
-
-/**
- * @}
- */
-
-/* Public Functions ----------------------------------------------------------- */
-/** @addtogroup SSP_Public_Functions
- * @{
- */
-
-/********************************************************************//**
- * @brief Initializes the SSPx peripheral according to the specified
-* parameters in the SSP_ConfigStruct.
- * @param[in] SSPx SSP peripheral selected, should be:
- * - LPC_SSP0: SSP0 peripheral
- * - LPC_SSP1: SSP1 peripheral
- * @param[in] SSP_ConfigStruct Pointer to a SSP_CFG_Type structure
-* that contains the configuration information for the
-* specified SSP peripheral.
- * @return None
- *********************************************************************/
-void SSP_Init(LPC_SSP_TypeDef *SSPx, SSP_CFG_Type *SSP_ConfigStruct)
-{
- uint32_t tmp;
-
- if(SSPx == LPC_SSP0) {
- /* Set up clock and power for SSP0 module */
- CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCSSP0, ENABLE);
- } else if(SSPx == LPC_SSP1) {
- /* Set up clock and power for SSP1 module */
- CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCSSP1, ENABLE);
- } else if(SSPx == LPC_SSP2) {
- /* Set up clock and power for SSP1 module */
- CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCSSP2, ENABLE);
- } else {
- return;
- }
-
- /* Configure SSP, interrupt is disable, LoopBack mode is disable,
- * SSP is disable, Slave output is disable as default
- */
- tmp = ((SSP_ConfigStruct->CPHA) | (SSP_ConfigStruct->CPOL) \
- | (SSP_ConfigStruct->FrameFormat) | (SSP_ConfigStruct->Databit))
- & SSP_CR0_BITMASK;
- // write back to SSP control register
- SSPx->CR0 = tmp;
-
- tmp = SSP_ConfigStruct->Mode & SSP_CR1_BITMASK;
- // Write back to CR1
- SSPx->CR1 = tmp;
-
- // Set clock rate for SSP peripheral
- setSSPclock(SSPx, SSP_ConfigStruct->ClockRate);
-}
-
-/*********************************************************************//**
- * @brief De-initializes the SSPx peripheral registers to their
-* default reset values.
- * @param[in] SSPx SSP peripheral selected, should be:
- * - LPC_SSP0: SSP0 peripheral
- * - LPC_SSP1: SSP1 peripheral
- * @return None
- **********************************************************************/
-void SSP_DeInit(LPC_SSP_TypeDef* SSPx)
-{
- if (SSPx == LPC_SSP0){
- /* Set up clock and power for SSP0 module */
- CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCSSP0, DISABLE);
- } else if (SSPx == LPC_SSP1) {
- /* Set up clock and power for SSP1 module */
- CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCSSP1, DISABLE);
- } else if (SSPx == LPC_SSP2) {
- /* Set up clock and power for SSP1 module */
- CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCSSP2, DISABLE);
- }
-}
-
-/*****************************************************************************//**
-* @brief Get data size bit selected
-* @param[in] SSPx pointer to LPC_SSP_TypeDef structure, should be:
-* - LPC_SSP0: SSP0 peripheral
-* - LPC_SSP1: SSP1 peripheral
-* @return Data size, could be:
-* - SSP_DATABIT_4: 4 bit transfer
-* - SSP_DATABIT_5: 5 bit transfer
-* ...
-* - SSP_DATABIT_16: 16 bit transfer
-*******************************************************************************/
-uint8_t SSP_GetDataSize(LPC_SSP_TypeDef* SSPx)
-{
- return (SSPx->CR0 & (0xF));
-}
-
-/*****************************************************************************//**
-* @brief Fills each SSP_InitStruct member with its default value:
-* - CPHA = SSP_CPHA_FIRST
-* - CPOL = SSP_CPOL_HI
-* - ClockRate = 1000000
-* - Databit = SSP_DATABIT_8
-* - Mode = SSP_MASTER_MODE
-* - FrameFormat = SSP_FRAME_SSP
-* @param[in] SSP_InitStruct Pointer to a SSP_CFG_Type structure
-* which will be initialized.
-* @return None
-*******************************************************************************/
-void SSP_ConfigStructInit(SSP_CFG_Type *SSP_InitStruct)
-{
- SSP_InitStruct->CPHA = SSP_CPHA_FIRST;
- SSP_InitStruct->CPOL = SSP_CPOL_HI;
- SSP_InitStruct->ClockRate = 1000000;
- SSP_InitStruct->Databit = SSP_DATABIT_8;
- SSP_InitStruct->Mode = SSP_MASTER_MODE;
- SSP_InitStruct->FrameFormat = SSP_FRAME_SPI;
-}
-
-
-/*********************************************************************//**
- * @brief Enable or disable SSP peripheral's operation
- * @param[in] SSPx SSP peripheral, should be:
- * - LPC_SSP0: SSP0 peripheral
- * - LPC_SSP1: SSP1 peripheral
- * @param[in] NewState New State of SSPx peripheral's operation
- * @return none
- **********************************************************************/
-void SSP_Cmd(LPC_SSP_TypeDef* SSPx, FunctionalState NewState)
-{
- if (NewState == ENABLE)
- {
- SSPx->CR1 |= SSP_CR1_SSP_EN;
- }
- else
- {
- SSPx->CR1 &= (~SSP_CR1_SSP_EN) & SSP_CR1_BITMASK;
- }
-}
-
-/*********************************************************************//**
- * @brief Enable or disable Loop Back mode function in SSP peripheral
- * @param[in] SSPx SSP peripheral selected, should be:
- * - LPC_SSP0: SSP0 peripheral
- * - LPC_SSP1: SSP1 peripheral
- * @param[in] NewState New State of Loop Back mode, should be:
- * - ENABLE: Enable this function
- * - DISABLE: Disable this function
- * @return None
- **********************************************************************/
-void SSP_LoopBackCmd(LPC_SSP_TypeDef* SSPx, FunctionalState NewState)
-{
- if (NewState == ENABLE)
- {
- SSPx->CR1 |= SSP_CR1_LBM_EN;
- }
- else
- {
- SSPx->CR1 &= (~SSP_CR1_LBM_EN) & SSP_CR1_BITMASK;
- }
-}
-
-/*********************************************************************//**
- * @brief Enable or disable Slave Output function in SSP peripheral
- * @param[in] SSPx SSP peripheral selected, should be:
- * - LPC_SSP0: SSP0 peripheral
- * - LPC_SSP1: SSP1 peripheral
- * @param[in] NewState New State of Slave Output function, should be:
- * - ENABLE: Slave Output in normal operation
- * - DISABLE: Slave Output is disabled. This blocks
- * SSP controller from driving the transmit data
- * line (MISO)
- * Note: This function is available when SSP peripheral in Slave mode
- * @return None
- **********************************************************************/
-void SSP_SlaveOutputCmd(LPC_SSP_TypeDef* SSPx, FunctionalState NewState)
-{
- if (NewState == ENABLE)
- {
- SSPx->CR1 &= (~SSP_CR1_SO_DISABLE) & SSP_CR1_BITMASK;
- }
- else
- {
- SSPx->CR1 |= SSP_CR1_SO_DISABLE;
- }
-}
-
-
-
-/*********************************************************************//**
- * @brief Transmit a single data through SSPx peripheral
- * @param[in] SSPx SSP peripheral selected, should be:
- * - LPC_SSP0: SSP0 peripheral
- * - LPC_SSP1: SSP1 peripheral
- * @param[in] Data Data to transmit (must be 16 or 8-bit long,
- * this depend on SSP data bit number configured)
- * @return none
- **********************************************************************/
-void SSP_SendData(LPC_SSP_TypeDef* SSPx, uint16_t Data)
-{
- SSPx->DR = SSP_DR_BITMASK(Data);
-}
-
-
-
-/*********************************************************************//**
- * @brief Receive a single data from SSPx peripheral
- * @param[in] SSPx SSP peripheral selected, should be
- * - LPC_SSP0: SSP0 peripheral
- * - LPC_SSP1: SSP1 peripheral
- * @return Data received (16-bit long)
- **********************************************************************/
-uint16_t SSP_ReceiveData(LPC_SSP_TypeDef* SSPx)
-{
- return ((uint16_t) (SSP_DR_BITMASK(SSPx->DR)));
-}
-
-/*********************************************************************//**
- * @brief SSP Read write data function
- * @param[in] SSPx Pointer to SSP peripheral, should be
- * - LPC_SSP0: SSP0 peripheral
- * - LPC_SSP1: SSP1 peripheral
- * @param[in] dataCfg Pointer to a SSP_DATA_SETUP_Type structure that
- * contains specified information about transmit
- * data configuration.
- * @param[in] xfType Transfer type, should be:
- * - SSP_TRANSFER_POLLING: Polling mode
- * - SSP_TRANSFER_INTERRUPT: Interrupt mode
- * @return Actual Data length has been transferred in polling mode.
- * In interrupt mode, always return (0)
- * Return (-1) if error.
- * Note: This function can be used in both master and slave mode.
- ***********************************************************************/
-int32_t SSP_ReadWrite (LPC_SSP_TypeDef *SSPx, SSP_DATA_SETUP_Type *dataCfg, \
- SSP_TRANSFER_Type xfType)
-{
- uint8_t *rdata8;
- uint8_t *wdata8;
- uint16_t *rdata16;
- uint16_t *wdata16;
- uint32_t stat;
- uint32_t tmp;
- int32_t dataword;
-
- dataCfg->rx_cnt = 0;
- dataCfg->tx_cnt = 0;
- dataCfg->status = 0;
-
-
- /* Clear all remaining data in RX FIFO */
- while (SSPx->SR & SSP_SR_RNE){
- tmp = (uint32_t) SSP_ReceiveData(SSPx);
- }
-
- // Clear status
- SSPx->ICR = SSP_ICR_BITMASK;
- if(SSP_GetDataSize(SSPx)>SSP_DATABIT_8)
- dataword = 1;
- else dataword = 0;
-
- // Polling mode ----------------------------------------------------------------------
- if (xfType == SSP_TRANSFER_POLLING){
- if (dataword == 0){
- rdata8 = (uint8_t *)dataCfg->rx_data;
- wdata8 = (uint8_t *)dataCfg->tx_data;
- } else {
- rdata16 = (uint16_t *)dataCfg->rx_data;
- wdata16 = (uint16_t *)dataCfg->tx_data;
- }
- while ((dataCfg->tx_cnt < dataCfg->length) || (dataCfg->rx_cnt < dataCfg->length)){
- if ((SSPx->SR & SSP_SR_TNF) && (dataCfg->tx_cnt < dataCfg->length)){
- // Write data to buffer
- if(dataCfg->tx_data == NULL){
- if (dataword == 0){
- SSP_SendData(SSPx, 0xFF);
- dataCfg->tx_cnt++;
- } else {
- SSP_SendData(SSPx, 0xFFFF);
- dataCfg->tx_cnt += 2;
- }
- } else {
- if (dataword == 0){
- SSP_SendData(SSPx, *wdata8);
- wdata8++;
- dataCfg->tx_cnt++;
- } else {
- SSP_SendData(SSPx, *wdata16);
- wdata16++;
- dataCfg->tx_cnt += 2;
- }
- }
- }
-
- // Check overrun error
- if ((stat = SSPx->RIS) & SSP_RIS_ROR){
- // save status and return
- dataCfg->status = stat | SSP_STAT_ERROR;
- return (-1);
- }
-
- // Check for any data available in RX FIFO
- while ((SSPx->SR & SSP_SR_RNE) && (dataCfg->rx_cnt < dataCfg->length)){
- // Read data from SSP data
- tmp = SSP_ReceiveData(SSPx);
-
- // Store data to destination
- if (dataCfg->rx_data != NULL)
- {
- if (dataword == 0){
- *(rdata8) = (uint8_t) tmp;
- rdata8++;
- } else {
- *(rdata16) = (uint16_t) tmp;
- rdata16++;
- }
- }
- // Increase counter
- if (dataword == 0){
- dataCfg->rx_cnt++;
- } else {
- dataCfg->rx_cnt += 2;
- }
- }
- }
-
- // save status
- dataCfg->status = SSP_STAT_DONE;
-
- if (dataCfg->tx_data != NULL){
- return dataCfg->tx_cnt;
- } else if (dataCfg->rx_data != NULL){
- return dataCfg->rx_cnt;
- } else {
- return (0);
- }
- }
-
- // Interrupt mode ----------------------------------------------------------------------
- else if (xfType == SSP_TRANSFER_INTERRUPT){
-
- while ((SSPx->SR & SSP_SR_TNF) && (dataCfg->tx_cnt < dataCfg->length)){
- // Write data to buffer
- if(dataCfg->tx_data == NULL){
- if (dataword == 0){
- SSP_SendData(SSPx, 0xFF);
- dataCfg->tx_cnt++;
- } else {
- SSP_SendData(SSPx, 0xFFFF);
- dataCfg->tx_cnt += 2;
- }
- } else {
- if (dataword == 0){
- SSP_SendData(SSPx, (*(uint8_t *)((uint32_t)dataCfg->tx_data + dataCfg->tx_cnt)));
- dataCfg->tx_cnt++;
- } else {
- SSP_SendData(SSPx, (*(uint16_t *)((uint32_t)dataCfg->tx_data + dataCfg->tx_cnt)));
- dataCfg->tx_cnt += 2;
- }
- }
-
- // Check error
- if ((stat = SSPx->RIS) & SSP_RIS_ROR){
- // save status and return
- dataCfg->status = stat | SSP_STAT_ERROR;
- return (-1);
- }
-
- // Check for any data available in RX FIFO
- while ((SSPx->SR & SSP_SR_RNE) && (dataCfg->rx_cnt < dataCfg->length)){
- // Read data from SSP data
- tmp = SSP_ReceiveData(SSPx);
-
- // Store data to destination
- if (dataCfg->rx_data != NULL)
- {
- if (dataword == 0){
- *(uint8_t *)((uint32_t)dataCfg->rx_data + dataCfg->rx_cnt) = (uint8_t) tmp;
- } else {
- *(uint16_t *)((uint32_t)dataCfg->rx_data + dataCfg->rx_cnt) = (uint16_t) tmp;
- }
- }
- // Increase counter
- if (dataword == 0){
- dataCfg->rx_cnt++;
- } else {
- dataCfg->rx_cnt += 2;
- }
- }
- }
-
- // If there more data to sent or receive
- if ((dataCfg->rx_cnt < dataCfg->length) || (dataCfg->tx_cnt < dataCfg->length)){
- // Enable all interrupt
- SSPx->IMSC = SSP_IMSC_BITMASK;
- } else {
- // Save status
- dataCfg->status = SSP_STAT_DONE;
- }
- return (0);
- }
-
- return (-1);
-}
-
-/*********************************************************************//**
- * @brief Checks whether the specified SSP status flag is set or not
- * @param[in] SSPx SSP peripheral selected, should be:
- * - LPC_SSP0: SSP0 peripheral
- * - LPC_SSP1: SSP1 peripheral
- * @param[in] FlagType Type of flag to check status, should be one
- * of following:
- * - SSP_STAT_TXFIFO_EMPTY: TX FIFO is empty
- * - SSP_STAT_TXFIFO_NOTFULL: TX FIFO is not full
- * - SSP_STAT_RXFIFO_NOTEMPTY: RX FIFO is not empty
- * - SSP_STAT_RXFIFO_FULL: RX FIFO is full
- * - SSP_STAT_BUSY: SSP peripheral is busy
- * @return New State of specified SSP status flag
- **********************************************************************/
-FlagStatus SSP_GetStatus(LPC_SSP_TypeDef* SSPx, uint32_t FlagType)
-{
- return ((SSPx->SR & FlagType) ? SET : RESET);
-}
-
-/*********************************************************************//**
- * @brief Enable or disable specified interrupt type in SSP peripheral
- * @param[in] SSPx SSP peripheral selected, should be:
- * - LPC_SSP0: SSP0 peripheral
- * - LPC_SSP1: SSP1 peripheral
- * @param[in] IntType Interrupt type in SSP peripheral, should be:
- * - SSP_INTCFG_ROR: Receive Overrun interrupt
- * - SSP_INTCFG_RT: Receive Time out interrupt
- * - SSP_INTCFG_RX: RX FIFO is at least half full interrupt
- * - SSP_INTCFG_TX: TX FIFO is at least half empty interrupt
- * @param[in] NewState New State of specified interrupt type, should be:
- * - ENABLE: Enable this interrupt type
- * - DISABLE: Disable this interrupt type
- * @return None
- * Note: We can enable/disable multi-interrupt type by OR multi value
- **********************************************************************/
-void SSP_IntConfig(LPC_SSP_TypeDef *SSPx, uint32_t IntType, FunctionalState NewState)
-{
- if (NewState == ENABLE)
- {
- SSPx->IMSC |= IntType;
- }
- else
- {
- SSPx->IMSC &= (~IntType) & SSP_IMSC_BITMASK;
- }
-}
-
-/*********************************************************************//**
- * @brief Check whether the specified Raw interrupt status flag is
- * set or not
- * @param[in] SSPx SSP peripheral selected, should be:
- * - LPC_SSP0: SSP0 peripheral
- * - LPC_SSP1: SSP1 peripheral
- * @param[in] RawIntType Raw Interrupt Type, should be:
- * - SSP_INTSTAT_RAW_ROR: Receive Overrun interrupt
- * - SSP_INTSTAT_RAW_RT: Receive Time out interrupt
- * - SSP_INTSTAT_RAW_RX: RX FIFO is at least half full interrupt
- * - SSP_INTSTAT_RAW_TX: TX FIFO is at least half empty interrupt
- * @return New State of specified Raw interrupt status flag in SSP peripheral
- * Note: Enabling/Disabling specified interrupt in SSP peripheral does not
- * effect to Raw Interrupt Status flag.
- **********************************************************************/
-IntStatus SSP_GetRawIntStatus(LPC_SSP_TypeDef *SSPx, uint32_t RawIntType)
-{
- return ((SSPx->RIS & RawIntType) ? SET : RESET);
-}
-
-/*********************************************************************//**
- * @brief Get Raw Interrupt Status register
- * @param[in] SSPx SSP peripheral selected, should be:
- * - LPC_SSP0: SSP0 peripheral
- * - LPC_SSP1: SSP1 peripheral
- * @return Raw Interrupt Status (RIS) register value
- **********************************************************************/
-uint32_t SSP_GetRawIntStatusReg(LPC_SSP_TypeDef *SSPx)
-{
- return (SSPx->RIS);
-}
-
-/*********************************************************************//**
- * @brief Check whether the specified interrupt status flag is
- * set or not
- * @param[in] SSPx SSP peripheral selected, should be:
- * - LPC_SSP0: SSP0 peripheral
- * - LPC_SSP1: SSP1 peripheral
- * @param[in] IntType Raw Interrupt Type, should be:
- * - SSP_INTSTAT_ROR: Receive Overrun interrupt
- * - SSP_INTSTAT_RT: Receive Time out interrupt
- * - SSP_INTSTAT_RX: RX FIFO is at least half full interrupt
- * - SSP_INTSTAT_TX: TX FIFO is at least half empty interrupt
- * @return New State of specified interrupt status flag in SSP peripheral
- * Note: Enabling/Disabling specified interrupt in SSP peripheral effects
- * to Interrupt Status flag.
- **********************************************************************/
-IntStatus SSP_GetIntStatus (LPC_SSP_TypeDef *SSPx, uint32_t IntType)
-{
- return ((SSPx->MIS & IntType) ? SET :RESET);
-}
-
-/*********************************************************************//**
- * @brief Clear specified interrupt pending in SSP peripheral
- * @param[in] SSPx SSP peripheral selected, should be:
- * - LPC_SSP0: SSP0 peripheral
- * - LPC_SSP1: SSP1 peripheral
- * @param[in] IntType Interrupt pending to clear, should be:
- * - SSP_INTCLR_ROR: clears the "frame was received when
- * RxFIFO was full" interrupt.
- * - SSP_INTCLR_RT: clears the "Rx FIFO was not empty and
- * has not been read for a timeout period" interrupt.
- * @return None
- **********************************************************************/
-void SSP_ClearIntPending(LPC_SSP_TypeDef *SSPx, uint32_t IntType)
-{
- SSPx->ICR = IntType;
-}
-
-/*********************************************************************//**
- * @brief Enable/Disable DMA function for SSP peripheral
- * @param[in] SSPx SSP peripheral selected, should be:
- * - LPC_SSP0: SSP0 peripheral
- * - LPC_SSP1: SSP1 peripheral
- * @param[in] DMAMode Type of DMA, should be:
- * - SSP_DMA_TX: DMA for the transmit FIFO
- * - SSP_DMA_RX: DMA for the Receive FIFO
- * @param[in] NewState New State of DMA function on SSP peripheral,
- * should be:
- * - ENALBE: Enable this function
- * - DISABLE: Disable this function
- * @return None
- **********************************************************************/
-void SSP_DMACmd(LPC_SSP_TypeDef *SSPx, uint32_t DMAMode, FunctionalState NewState)
-{
- if (NewState == ENABLE)
- {
- SSPx->DMACR |= DMAMode;
- }
- else
- {
- SSPx->DMACR &= (~DMAMode) & SSP_DMA_BITMASK;
- }
-}
-
-/**
- * @}
- */
-
-#endif /*_SSP*/
-/**
- * @}
- */
-
-/* --------------------------------- End Of File ------------------------------ */
-
diff --git a/bsp/lpc408x/Libraries/Drivers/source/lpc_systick.c b/bsp/lpc408x/Libraries/Drivers/source/lpc_systick.c
deleted file mode 100644
index 66ea6d870a..0000000000
--- a/bsp/lpc408x/Libraries/Drivers/source/lpc_systick.c
+++ /dev/null
@@ -1,192 +0,0 @@
-/**********************************************************************
-* $Id$ lpc_systick.c 2011-06-02
-*//**
-* @file lpc_systick.c
-* @brief Contains all functions support for SysTick firmware library
-* on LPC
-* @version 1.0
-* @date 02. June. 2011
-* @author NXP MCU SW Application Team
-*
-* Copyright(C) 2011, NXP Semiconductor
-* All rights reserved.
-*
-***********************************************************************
-* Software that is described herein is for illustrative purposes only
-* which provides customers with programming information regarding the
-* products. This software is supplied "AS IS" without any warranties.
-* NXP Semiconductors assumes no responsibility or liability for the
-* use of the software, conveys no license or title under any patent,
-* copyright, or mask work right to the product. NXP Semiconductors
-* reserves the right to make changes in the software without
-* notification. NXP Semiconductors also make 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'
-* relevant copyright 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.
-**********************************************************************/
-
-/* Peripheral group ----------------------------------------------------------- */
-/** @addtogroup SYSTICK
- * @{
- */
-#ifdef __BUILD_WITH_EXAMPLE__
-#include "lpc_libcfg.h"
-#else
-#include "lpc_libcfg_default.h"
-#endif /* __BUILD_WITH_EXAMPLE__ */
-#ifdef _SYSTICK
-
-/* Includes ------------------------------------------------------------------- */
-#include "lpc_systick.h"
-#include "lpc_clkpwr.h"
-
-
-/* Public Functions ----------------------------------------------------------- */
-/** @addtogroup SYSTICK_Public_Functions
- * @{
- */
-/*********************************************************************//**
- * @brief Initial System Tick with using internal CPU clock source
- * @param[in] time time interval(ms)
- * @return None
- * Note: time interval parameter should be less than:
- * 1/cclk * (2^24) * 1000 (ms)
- * In this case, with cclk = 96Mhz, time interval value < 174ms
- **********************************************************************/
-void SYSTICK_InternalInit(uint32_t time)
-{
- uint32_t cclk;
- float maxtime;
-
- cclk = CLKPWR_GetCLK(CLKPWR_CLKTYPE_CPU);
-
- /* With internal CPU clock frequency for LPC178X is 'SystemCoreClock'
- * And limit 24 bit for RELOAD value
- * So the maximum time can be set:
- * 1/SystemCoreClock * (2^24) * 1000 (ms)
- */
- //check time value is available or not
- maxtime = (1<<24)/(cclk / 1000) ;
-
- if(time > maxtime)
- {
- //Error loop
- while(1);
- }
- else
- {
- //Select CPU clock is System Tick clock source
- SysTick->CTRL |= ST_CTRL_CLKSOURCE;
-
- /* Set RELOAD value
- * RELOAD = (SystemCoreClock/1000) * time - 1
- * with time base is millisecond
- */
- SysTick->LOAD = (cclk/1000)*time - 1;
- }
-}
-
-/*********************************************************************//**
- * @brief Initial System Tick with using external clock source
- * @param[in] freq external clock frequency(Hz)
- * @param[in] time time interval(ms)
- * @return None
- **********************************************************************/
-void SYSTICK_ExternalInit(uint32_t freq, uint32_t time)
-{
- float maxtime;
-
- /* With external clock frequency for LPC178X is 'freq'
- * And limit 24 bit for RELOAD value
- * So the maximum time can be set:
- * 1/freq * (2^24) * 1000 (ms)
- */
- //check time value is available or not
- maxtime = (1<<24)/(freq / 1000) ;
- if (time>maxtime)
- {
- //Error Loop
- while(1);
- }
- else
- {
- //Select external clock is System Tick clock source
- SysTick->CTRL &= ~ ST_CTRL_CLKSOURCE;
-
- /* Set RELOAD value
- * RELOAD = (freq/1000) * time - 1
- * with time base is millisecond
- */
- maxtime = (freq/1000)*time - 1;
- SysTick->LOAD = (freq/1000)*time - 1;
- }
-}
-
-/*********************************************************************//**
- * @brief Enable/disable System Tick counter
- * @param[in] NewState System Tick counter status, should be:
- * - ENABLE
- * - DISABLE
- * @return None
- **********************************************************************/
-void SYSTICK_Cmd(FunctionalState NewState)
-{
- if(NewState == ENABLE)
- //Enable System Tick counter
- SysTick->CTRL |= ST_CTRL_ENABLE;
- else
- //Disable System Tick counter
- SysTick->CTRL &= ~ST_CTRL_ENABLE;
-}
-
-/*********************************************************************//**
- * @brief Enable/disable System Tick interrupt
- * @param[in] NewState System Tick interrupt status, should be:
- * - ENABLE
- * - DISABLE
- * @return None
- **********************************************************************/
-void SYSTICK_IntCmd(FunctionalState NewState)
-{
- if(NewState == ENABLE)
- //Enable System Tick counter
- SysTick->CTRL |= ST_CTRL_TICKINT;
- else
- //Disable System Tick counter
- SysTick->CTRL &= ~ST_CTRL_TICKINT;
-}
-
-/*********************************************************************//**
- * @brief Get current value of System Tick counter
- * @param[in] None
- * @return current value of System Tick counter
- **********************************************************************/
-uint32_t SYSTICK_GetCurrentValue(void)
-{
- return (SysTick->VAL);
-}
-
-/*********************************************************************//**
- * @brief Clear Counter flag
- * @param[in] None
- * @return None
- **********************************************************************/
-void SYSTICK_ClearCounterFlag(void)
-{
- SysTick->CTRL &= ~ST_CTRL_COUNTFLAG;
-}
-/**
- * @}
- */
-#endif /*_SYSTICK*/
-/**
- * @}
- */
-
-/* --------------------------------- End Of File ------------------------------ */
-
diff --git a/bsp/lpc408x/Libraries/Drivers/source/lpc_timer.c b/bsp/lpc408x/Libraries/Drivers/source/lpc_timer.c
deleted file mode 100644
index dee26cc13c..0000000000
--- a/bsp/lpc408x/Libraries/Drivers/source/lpc_timer.c
+++ /dev/null
@@ -1,582 +0,0 @@
-/**********************************************************************
-* $Id$ lpc_timer.c 2011-06-02
-*//**
-* @file lpc_timer.c
-* @brief Contains all functions support for Timer firmware library
-* on LPC
-* @version 1.0
-* @date 02. June. 2011
-* @author NXP MCU SW Application Team
-*
-* Copyright(C) 2011, NXP Semiconductor
-* All rights reserved.
-*
-***********************************************************************
-* Software that is described herein is for illustrative purposes only
-* which provides customers with programming information regarding the
-* products. This software is supplied "AS IS" without any warranties.
-* NXP Semiconductors assumes no responsibility or liability for the
-* use of the software, conveys no license or title under any patent,
-* copyright, or mask work right to the product. NXP Semiconductors
-* reserves the right to make changes in the software without
-* notification. NXP Semiconductors also make 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'
-* relevant copyright 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.
-**********************************************************************/
-
-/* Peripheral group ----------------------------------------------------------- */
-/** @addtogroup TIMER
- * @{
- */
-#ifdef __BUILD_WITH_EXAMPLE__
-#include "lpc_libcfg.h"
-#else
-#include "lpc_libcfg_default.h"
-#endif /* __BUILD_WITH_EXAMPLE__ */
-#ifdef _TIM
-
-/* Includes ------------------------------------------------------------------- */
-#include "lpc_timer.h"
-#include "lpc_clkpwr.h"
-#include "lpc_pinsel.h"
-
-/* Private Functions ---------------------------------------------------------- */
-
-static uint32_t getPClock (uint32_t timernum);
-static uint32_t converUSecToVal (uint32_t timernum, uint32_t usec);
-static int32_t converPtrToTimeNum (LPC_TIM_TypeDef *TIMx);
-
-
-/*********************************************************************//**
- * @brief Get peripheral clock of each timer controller
- * @param[in] timernum Timer number
- * @return Peripheral clock of timer
- **********************************************************************/
-static uint32_t getPClock (uint32_t timernum)
-{
- uint32_t clkdlycnt;
- clkdlycnt = CLKPWR_GetCLK(CLKPWR_CLKTYPE_PER);
- return clkdlycnt;
-}
-
-
-/*********************************************************************//**
- * @brief Convert a time to a timer count value
- * @param[in] timernum Timer number
- * @param[in] usec Time in microseconds
- * @return The number of required clock ticks to give the time delay
- **********************************************************************/
-uint32_t converUSecToVal (uint32_t timernum, uint32_t usec)
-{
- uint64_t clkdlycnt;
-
- // Get Pclock of timer
- clkdlycnt = (uint64_t) getPClock(timernum);
-
- clkdlycnt = (clkdlycnt * usec) / 1000000;
- return (uint32_t) clkdlycnt;
-}
-
-
-/*********************************************************************//**
- * @brief Convert a timer register pointer to a timer number
- * @param[in] TIMx Pointer to LPC_TIM_TypeDef, should be:
- * - LPC_TIM0: TIMER0 peripheral
- * - LPC_TIM1: TIMER1 peripheral
- * - LPC_TIM2: TIMER2 peripheral
- * - LPC_TIM3: TIMER3 peripheral
- * @return The timer number (0 to 3) or -1 if register pointer is bad
- **********************************************************************/
-int32_t converPtrToTimeNum (LPC_TIM_TypeDef *TIMx)
-{
- int32_t tnum = -1;
-
- if (TIMx == LPC_TIM0)
- {
- tnum = 0;
- }
- else if (TIMx == LPC_TIM1)
- {
- tnum = 1;
- }
- else if (TIMx == LPC_TIM2)
- {
- tnum = 2;
- }
- else if (TIMx == LPC_TIM3)
- {
- tnum = 3;
- }
-
- return tnum;
-}
-
-/* End of Private Functions ---------------------------------------------------- */
-
-
-/* Public Functions ----------------------------------------------------------- */
-/** @addtogroup TIM_Public_Functions
- * @{
- */
-
-/*********************************************************************//**
- * @brief Get Interrupt Status
- * @param[in] TIMx Timer selection, should be:
- * - LPC_TIM0: TIMER0 peripheral
- * - LPC_TIM1: TIMER1 peripheral
- * - LPC_TIM2: TIMER2 peripheral
- * - LPC_TIM3: TIMER3 peripheral
- * @param[in] IntFlag Interrupt type, should be:
- * - TIM_MR0_INT: Interrupt for Match channel 0
- * - TIM_MR1_INT: Interrupt for Match channel 1
- * - TIM_MR2_INT: Interrupt for Match channel 2
- * - TIM_MR3_INT: Interrupt for Match channel 3
- * - TIM_CR0_INT: Interrupt for Capture channel 0
- * - TIM_CR1_INT: Interrupt for Capture channel 1
- * @return Flag Status for required interrupt
- * - SET : interrupt
- * - RESET : no interrupt
- **********************************************************************/
-FlagStatus TIM_GetIntStatus(LPC_TIM_TypeDef *TIMx, TIM_INT_TYPE IntFlag)
-{
- uint8_t temp;
- temp = (TIMx->IR)& TIM_IR_CLR(IntFlag);
- if (temp)
- return SET;
-
- return RESET;
-
-}
-/*********************************************************************//**
- * @brief Get Capture Interrupt Status
- * @param[in] TIMx Timer selection, should be:
- * - LPC_TIM0: TIMER0 peripheral
- * - LPC_TIM1: TIMER1 peripheral
- * - LPC_TIM2: TIMER2 peripheral
- * - LPC_TIM3: TIMER3 peripheral
- * @param[in] IntFlag: interrupt type, should be:
- * - TIM_MR0_INT: Interrupt for Match channel 0
- * - TIM_MR1_INT: Interrupt for Match channel 1
- * - TIM_MR2_INT: Interrupt for Match channel 2
- * - TIM_MR3_INT: Interrupt for Match channel 3
- * - TIM_CR0_INT: Interrupt for Capture channel 0
- * - TIM_CR1_INT: Interrupt for Capture channel 1
- * @return FlagStatus
- * - SET : interrupt
- * - RESET : no interrupt
- **********************************************************************/
-FlagStatus TIM_GetIntCaptureStatus(LPC_TIM_TypeDef *TIMx, TIM_INT_TYPE IntFlag)
-{
- uint8_t temp;
- temp = (TIMx->IR) & (1<<(4+IntFlag));
- if(temp)
- return SET;
- return RESET;
-}
-/*********************************************************************//**
- * @brief Clear Interrupt pending
- * @param[in] TIMx Timer selection, should be:
- * - LPC_TIM0: TIMER0 peripheral
- * - LPC_TIM1: TIMER1 peripheral
- * - LPC_TIM2: TIMER2 peripheral
- * - LPC_TIM3: TIMER3 peripheral
- * @param[in] IntFlag: interrupt type, should be:
- * - TIM_MR0_INT: Interrupt for Match channel 0
- * - TIM_MR1_INT: Interrupt for Match channel 1
- * - TIM_MR2_INT: Interrupt for Match channel 2
- * - TIM_MR3_INT: Interrupt for Match channel 3
- * - TIM_CR0_INT: Interrupt for Capture channel 0
- * - TIM_CR1_INT: Interrupt for Capture channel 1
- * @return None
- **********************************************************************/
-void TIM_ClearIntPending(LPC_TIM_TypeDef *TIMx, TIM_INT_TYPE IntFlag)
-{
- TIMx->IR = TIM_IR_CLR(IntFlag);
-}
-
-/*********************************************************************//**
- * @brief Clear Capture Interrupt pending
- * @param[in] TIMx Timer selection, should be
- * - LPC_TIM0: TIMER0 peripheral
- * - LPC_TIM1: TIMER1 peripheral
- * - LPC_TIM2: TIMER2 peripheral
- * - LPC_TIM3: TIMER3 peripheral
- * @param[in] IntFlag interrupt type, should be:
- * - TIM_MR0_INT: Interrupt for Match channel 0
- * - TIM_MR1_INT: Interrupt for Match channel 1
- * - TIM_MR2_INT: Interrupt for Match channel 2
- * - TIM_MR3_INT: Interrupt for Match channel 3
- * - TIM_CR0_INT: Interrupt for Capture channel 0
- * - TIM_CR1_INT: Interrupt for Capture channel 1
- * @return None
- **********************************************************************/
-void TIM_ClearIntCapturePending(LPC_TIM_TypeDef *TIMx, TIM_INT_TYPE IntFlag)
-{
- TIMx->IR = (1<<(4+IntFlag));
-}
-
-/*********************************************************************//**
- * @brief Configuration for Timer at initial time
- * @param[in] TimerCounterMode timer counter mode, should be:
- * - TIM_TIMER_MODE: Timer mode
- * - TIM_COUNTER_RISING_MODE: Counter rising mode
- * - TIM_COUNTER_FALLING_MODE: Counter falling mode
- * - TIM_COUNTER_ANY_MODE:Counter on both edges
- * @param[in] TIM_ConfigStruct pointer to TIM_TIMERCFG_Type or
- * TIM_COUNTERCFG_Type
- * @return None
- **********************************************************************/
-void TIM_ConfigStructInit(TIM_MODE_OPT TimerCounterMode, void *TIM_ConfigStruct)
-{
- if (TimerCounterMode == TIM_TIMER_MODE )
- {
- TIM_TIMERCFG_Type * pTimeCfg = (TIM_TIMERCFG_Type *)TIM_ConfigStruct;
- pTimeCfg->PrescaleOption = TIM_PRESCALE_USVAL;
- pTimeCfg->PrescaleValue = 1;
- }
- else
- {
- TIM_COUNTERCFG_Type * pCounterCfg = (TIM_COUNTERCFG_Type *)TIM_ConfigStruct;
- pCounterCfg->CountInputSelect = TIM_COUNTER_INCAP0;
- }
-}
-
-/*********************************************************************//**
- * @brief Initial Timer/Counter device
- * Set Clock frequency for Timer
- * Set initial configuration for Timer
- * @param[in] TIMx Timer selection, should be:
- * - LPC_TIM0: TIMER0 peripheral
- * - LPC_TIM1: TIMER1 peripheral
- * - LPC_TIM2: TIMER2 peripheral
- * - LPC_TIM3: TIMER3 peripheral
- * @param[in] TimerCounterMode Timer counter mode, should be:
- * - TIM_TIMER_MODE: Timer mode
- * - TIM_COUNTER_RISING_MODE: Counter rising mode
- * - TIM_COUNTER_FALLING_MODE: Counter falling mode
- * - TIM_COUNTER_ANY_MODE:Counter on both edges
- * @param[in] TIM_ConfigStruct pointer to TIM_TIMERCFG_Type
- * that contains the configuration information for the
- * specified Timer peripheral.
- * @return None
- **********************************************************************/
-void TIM_Init(LPC_TIM_TypeDef *TIMx, TIM_MODE_OPT TimerCounterMode, void *TIM_ConfigStruct)
-{
- TIM_TIMERCFG_Type *pTimeCfg;
- TIM_COUNTERCFG_Type *pCounterCfg;
-
- //set power
- if (TIMx== LPC_TIM0)
- {
- CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCTIM0, ENABLE);
- }
- else if (TIMx== LPC_TIM1)
- {
- CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCTIM1, ENABLE);
- }
-
- else if (TIMx== LPC_TIM2)
- {
- CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCTIM2, ENABLE);
- }
- else if (TIMx== LPC_TIM3)
- {
- CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCTIM3, ENABLE);
- }
-
- TIMx->CTCR &= ~TIM_CTCR_MODE_MASK;
- TIMx->CTCR |= TIM_TIMER_MODE;
-
- TIMx->TC =0;
- TIMx->PC =0;
- TIMx->PR =0;
- TIMx->TCR |= (1<<1); //Reset Counter
- TIMx->TCR &= ~(1<<1); //release reset
- if (TimerCounterMode == TIM_TIMER_MODE )
- {
- pTimeCfg = (TIM_TIMERCFG_Type *)TIM_ConfigStruct;
- if (pTimeCfg->PrescaleOption == TIM_PRESCALE_TICKVAL)
- {
- TIMx->PR = pTimeCfg->PrescaleValue -1 ;
- }
- else
- {
- TIMx->PR = converUSecToVal (converPtrToTimeNum(TIMx),pTimeCfg->PrescaleValue)-1;
- }
- }
- else
- {
-
- pCounterCfg = (TIM_COUNTERCFG_Type *)TIM_ConfigStruct;
- TIMx->CTCR &= ~TIM_CTCR_INPUT_MASK;
- if (pCounterCfg->CountInputSelect == TIM_COUNTER_INCAP1)
- TIMx->CCR |= _BIT(2);
- }
-
- // Clear interrupt pending
- TIMx->IR = 0xFFFFFFFF;
-
-}
-
-/*********************************************************************//**
- * @brief Close Timer/Counter device
- * @param[in] TIMx Pointer to timer device, should be:
- * - LPC_TIM0: TIMER0 peripheral
- * - LPC_TIM1: TIMER1 peripheral
- * - LPC_TIM2: TIMER2 peripheral
- * - LPC_TIM3: TIMER3 peripheral
- * @return None
- **********************************************************************/
-void TIM_DeInit (LPC_TIM_TypeDef *TIMx)
-{
- // Disable timer/counter
- TIMx->TCR = 0x00;
-
- // Disable power
- if (TIMx== LPC_TIM0)
- CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCTIM0, DISABLE);
-
- else if (TIMx== LPC_TIM1)
- CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCTIM1, DISABLE);
-
- else if (TIMx== LPC_TIM2)
- CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCTIM2, DISABLE);
-
- else if (TIMx== LPC_TIM3)
- CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCTIM2, DISABLE);
-
-}
-
-/*********************************************************************//**
- * @brief Start/Stop Timer/Counter device
- * @param[in] TIMx Pointer to timer device, should be:
- * - LPC_TIM0: TIMER0 peripheral
- * - LPC_TIM1: TIMER1 peripheral
- * - LPC_TIM2: TIMER2 peripheral
- * - LPC_TIM3: TIMER3 peripheral
- * @param[in] NewState
- * - ENABLE : set timer enable
- * - DISABLE : disable timer
- * @return None
- **********************************************************************/
-void TIM_Cmd(LPC_TIM_TypeDef *TIMx, FunctionalState NewState)
-{
- if (NewState == ENABLE)
- {
- TIMx->TCR |= TIM_ENABLE;
- }
- else
- {
- TIMx->TCR &= ~TIM_ENABLE;
- }
-}
-
-/*********************************************************************//**
- * @brief Reset Timer/Counter device,
- * Make TC and PC are synchronously reset on the next
- * positive edge of PCLK
- * @param[in] TIMx Pointer to timer device, should be:
- * - LPC_TIM0: TIMER0 peripheral
- * - LPC_TIM1: TIMER1 peripheral
- * - LPC_TIM2: TIMER2 peripheral
- * - LPC_TIM3: TIMER3 peripheral
- * @return None
- **********************************************************************/
-void TIM_ResetCounter(LPC_TIM_TypeDef *TIMx)
-{
- TIMx->TCR |= TIM_RESET;
- TIMx->TCR &= ~TIM_RESET;
-}
-
-/*********************************************************************//**
- * @brief Configuration for Match register
- * @param[in] TIMx Pointer to timer device, should be:
- * - LPC_TIM0: TIMER0 peripheral
- * - LPC_TIM1: TIMER1 peripheral
- * - LPC_TIM2: TIMER2 peripheral
- * - LPC_TIM3: TIMER3 peripheral
- * @param[in] TIM_MatchConfigStruct Pointer to TIM_MATCHCFG_Type
- * - MatchChannel : choose channel 0 or 1
- * - IntOnMatch : if SET, interrupt will be generated when MRxx match
- * the value in TC
- * - StopOnMatch : if SET, TC and PC will be stopped whenM Rxx match
- * the value in TC
- * - ResetOnMatch : if SET, Reset on MR0 when MRxx match
- * the value in TC
- * -ExtMatchOutputType: Select output for external match
- * + 0: Do nothing for external output pin if match
- * + 1: Force external output pin to low if match
- * + 2: Force external output pin to high if match
- * + 3: Toggle external output pin if match
- * MatchValue: Set the value to be compared with TC value
- * @return None
- **********************************************************************/
-void TIM_ConfigMatch(LPC_TIM_TypeDef *TIMx, TIM_MATCHCFG_Type *TIM_MatchConfigStruct)
-{
- switch(TIM_MatchConfigStruct->MatchChannel)
- {
- case 0:
- TIMx->MR0 = TIM_MatchConfigStruct->MatchValue;
- break;
- case 1:
- TIMx->MR1 = TIM_MatchConfigStruct->MatchValue;
- break;
- case 2:
- TIMx->MR2 = TIM_MatchConfigStruct->MatchValue;
- break;
- case 3:
- TIMx->MR3 = TIM_MatchConfigStruct->MatchValue;
- break;
- default:
- //Error match value
- //Error loop
- while(1);
- }
- //interrupt on MRn
- TIMx->MCR &= ~ TIM_MCR_CHANNEL_MASKBIT(TIM_MatchConfigStruct->MatchChannel);
-
- if (TIM_MatchConfigStruct->IntOnMatch)
- TIMx->MCR |= TIM_INT_ON_MATCH(TIM_MatchConfigStruct->MatchChannel);
-
- //reset on MRn
- if (TIM_MatchConfigStruct->ResetOnMatch)
- TIMx->MCR |= TIM_RESET_ON_MATCH(TIM_MatchConfigStruct->MatchChannel);
-
- //stop on MRn
- if (TIM_MatchConfigStruct->StopOnMatch)
- TIMx->MCR |= TIM_STOP_ON_MATCH(TIM_MatchConfigStruct->MatchChannel);
-
- // match output type
-
- TIMx->EMR &= ~ TIM_EM_MASK(TIM_MatchConfigStruct->MatchChannel);
- TIMx->EMR |= TIM_EM_SET(TIM_MatchConfigStruct->MatchChannel,TIM_MatchConfigStruct->ExtMatchOutputType);
-}
-/*********************************************************************//**
- * @brief Update Match value
- * @param[in] TIMx Pointer to timer device, should be:
- * - LPC_TIM0: TIMER0 peripheral
- * - LPC_TIM1: TIMER1 peripheral
- * - LPC_TIM2: TIMER2 peripheral
- * - LPC_TIM3: TIMER3 peripheral
- * @param[in] MatchChannel Match channel, should be: 0..3
- * @param[in] MatchValue updated match value
- * @return None
- **********************************************************************/
-void TIM_UpdateMatchValue(LPC_TIM_TypeDef *TIMx,uint8_t MatchChannel, uint32_t MatchValue)
-{
- switch(MatchChannel)
- {
- case 0:
- TIMx->MR0 = MatchValue;
- break;
- case 1:
- TIMx->MR1 = MatchValue;
- break;
- case 2:
- TIMx->MR2 = MatchValue;
- break;
- case 3:
- TIMx->MR3 = MatchValue;
- break;
- default:
- //Error Loop
- while(1);
- }
-}
-
-/*********************************************************************//**
- * @brief Configuration for Capture register
- * @param[in] TIMx Pointer to timer device, should be:
- * - LPC_TIM0: TIMER0 peripheral
- * - LPC_TIM1: TIMER1 peripheral
- * - LPC_TIM2: TIMER2 peripheral
- * - LPC_TIM3: TIMER3 peripheral
- * @param[in] TIM_CaptureConfigStruct Pointer to TIM_CAPTURECFG_Type
- * - CaptureChannel: set the channel to capture data
- * - RisingEdge : if SET, Capture at rising edge
- * - FallingEdge : if SET, Capture at falling edge
- * - IntOnCaption : if SET, Capture generate interrupt
- * @return None
- **********************************************************************/
-void TIM_ConfigCapture(LPC_TIM_TypeDef *TIMx, TIM_CAPTURECFG_Type *TIM_CaptureConfigStruct)
-{
- TIMx->CCR &= ~TIM_CCR_CHANNEL_MASKBIT(TIM_CaptureConfigStruct->CaptureChannel);
-
- if (TIM_CaptureConfigStruct->RisingEdge)
- TIMx->CCR |= TIM_CAP_RISING(TIM_CaptureConfigStruct->CaptureChannel);
-
- if (TIM_CaptureConfigStruct->FallingEdge)
- TIMx->CCR |= TIM_CAP_FALLING(TIM_CaptureConfigStruct->CaptureChannel);
-
- if (TIM_CaptureConfigStruct->IntOnCaption)
- TIMx->CCR |= TIM_INT_ON_CAP(TIM_CaptureConfigStruct->CaptureChannel);
-}
-
-/*********************************************************************//**
- * @brief Read value of capture register in timer/counter device
- * @param[in] TIMx Pointer to timer/counter device, should be:
- * - LPC_TIM0: TIMER0 peripheral
- * - LPC_TIM1: TIMER1 peripheral
- * - LPC_TIM2: TIMER2 peripheral
- * - LPC_TIM3: TIMER3 peripheral
- * @param[in] CaptureChannel: capture channel number, should be:
- * - TIM_COUNTER_INCAP0: CAPn.0 input pin for TIMERn
- * - TIM_COUNTER_INCAP1: CAPn.1 input pin for TIMERn
- * @return Value of capture register
- **********************************************************************/
-uint32_t TIM_GetCaptureValue(LPC_TIM_TypeDef *TIMx, TIM_COUNTER_INPUT_OPT CaptureChannel)
-{
- if(CaptureChannel==0)
- return TIMx->CR0;
- else
- return TIMx->CR1;
-}
-
-/*---------------Advanced TIMER functions -----------------------------------------*/
-/*********************************************************************//**
- * @brief Timer wait (microseconds)
- * @param[in] time number of microseconds waiting
- * @return None
- **********************************************************************/
-void TIM_Waitus(uint32_t time)
-{
- TIM_MATCHCFG_Type MatchConfigStruct;
- LPC_TIM0->IR = 0xFFFFFFFF;
-
- MatchConfigStruct.MatchChannel = 0;
- MatchConfigStruct.IntOnMatch = ENABLE;
- MatchConfigStruct.ResetOnMatch = ENABLE;
- MatchConfigStruct.StopOnMatch = ENABLE;
- MatchConfigStruct.ExtMatchOutputType = 0;
- MatchConfigStruct.MatchValue = time;
-
- TIM_ConfigMatch(LPC_TIM0, &MatchConfigStruct);
- TIM_Cmd(LPC_TIM0,ENABLE);
- //wait until interrupt flag occur
- while(!(LPC_TIM0->IR & 0x01));
- TIM_ResetCounter(LPC_TIM0);
-}
-/*********************************************************************//**
- * @brief Timer wait (milliseconds)
- * @param[in] time number of millisecond waiting
- * @return None
- **********************************************************************/
-void TIM_Waitms(uint32_t time)
-{
- TIM_Waitus(time * 1000);
-}
-/**
- * @}
- */
-#endif /*_TIM*/
-/**
- * @}
- */
-
-/* --------------------------------- End Of File ------------------------------ */
diff --git a/bsp/lpc408x/Libraries/Drivers/source/lpc_uart.c b/bsp/lpc408x/Libraries/Drivers/source/lpc_uart.c
deleted file mode 100644
index bcd9ef51e0..0000000000
--- a/bsp/lpc408x/Libraries/Drivers/source/lpc_uart.c
+++ /dev/null
@@ -1,1778 +0,0 @@
-/**********************************************************************
-* $Id$ lpc_uart.c 2011-06-02
-*//**
-* @file lpc_uart.c
-* @brief Contains all functions support for UART firmware library
-* on LPC
-* @version 1.0
-* @date 02. June. 2011
-* @author NXP MCU SW Application Team
-*
-* Copyright(C) 2011, NXP Semiconductor
-* All rights reserved.
-*
-***********************************************************************
-* Software that is described herein is for illustrative purposes only
-* which provides customers with programming information regarding the
-* products. This software is supplied "AS IS" without any warranties.
-* NXP Semiconductors assumes no responsibility or liability for the
-* use of the software, conveys no license or title under any patent,
-* copyright, or mask work right to the product. NXP Semiconductors
-* reserves the right to make changes in the software without
-* notification. NXP Semiconductors also make 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'
-* relevant copyright 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.
-**********************************************************************/
-
-/* Peripheral group ----------------------------------------------------------- */
-/** @addtogroup UART
- * @{
- */
-#ifdef __BUILD_WITH_EXAMPLE__
-#include "lpc_libcfg.h"
-#else
-#include "lpc_libcfg_default.h"
-#endif /* __BUILD_WITH_EXAMPLE__ */
-#ifdef _UART
-
-/* Includes ------------------------------------------------------------------- */
-#include "lpc_uart.h"
-#include "lpc_clkpwr.h"
-
-/* Private Functions ---------------------------------------------------------- */
-
-static Status uart_set_divisors(UART_ID_Type UartID, uint32_t baudrate);
-static LPC_UART_TypeDef *uart_get_pointer(UART_ID_Type UartID);
-
-
-/*********************************************************************//**
- * @brief Determines best dividers to get a target clock rate
- * @param[in] UARTx Pointer to selected UART peripheral, should be:
- * - UART_0: UART0 peripheral
- * - UART_1: UART1 peripheral
- * - UART_2: UART2 peripheral
- * - UART_3: UART3 peripheral
- * - UART_4: UART4 peripheral
- * @param[in] baudrate Desired UART baud rate.
- * @return Error status, could be:
- * - SUCCESS
- * - ERROR
- **********************************************************************/
-static Status uart_set_divisors(UART_ID_Type UartID, uint32_t baudrate)
-{
- Status errorStatus = ERROR;
-
- uint32_t uClk;
- uint32_t d, m, bestd, bestm, tmp;
- uint64_t best_divisor, divisor;
- uint32_t current_error, best_error;
- uint32_t recalcbaud;
-
- /* get UART block clock */
- uClk = CLKPWR_GetCLK(CLKPWR_CLKTYPE_PER);
-
- /* In the Uart IP block, baud rate is calculated using FDR and DLL-DLM registers
- * The formula is :
- * BaudRate= uClk * (mulFracDiv/(mulFracDiv+dividerAddFracDiv) / (16 * (DLL)
- * It involves floating point calculations. That's the reason the formulae are adjusted with
- * Multiply and divide method.*/
-
- /* The value of mulFracDiv and dividerAddFracDiv should comply to the following expressions:
- * 0 < mulFracDiv <= 15, 0 <= dividerAddFracDiv <= 15 */
- best_error = 0xFFFFFFFF; /* Worst case */
- bestd = 0;
- bestm = 0;
- best_divisor = 0;
-
- for (m = 1 ; m <= 15 ;m++)
- {
- for (d = 0 ; d < m ; d++)
- {
- divisor = ((uint64_t)uClk << 28)*m / (baudrate*(m+d));
- current_error = divisor & 0xFFFFFFFF;
-
- tmp = divisor>>32;
-
- /* Adjust error */
- if(current_error > ((uint32_t)1<<31))
- {
- current_error = -current_error;
- tmp++;
- }
-
- /* Out of range */
- if(tmp < 1 || tmp > 65536)
- continue;
-
- if( current_error < best_error)
- {
- best_error = current_error;
- best_divisor = tmp;
- bestd = d;
- bestm = m;
-
- if(best_error == 0)
- break;
- }
- } /* end of inner for loop */
-
- if (best_error == 0)
- break;
- } /* end of outer for loop */
-
- /* can not find best match */
- if(best_divisor == 0)
- return ERROR;
-
- recalcbaud = (uClk >> 4) * bestm / (best_divisor * (bestm + bestd));
-
- /* reuse best_error to evaluate baud error*/
- if(baudrate > recalcbaud)
- best_error = baudrate - recalcbaud;
- else
- best_error = recalcbaud -baudrate;
-
- best_error = best_error * 100 / baudrate;
-
- if (best_error < UART_ACCEPTED_BAUDRATE_ERROR)
- {
- if (UartID == UART_1)
- {
- LPC_UART1->LCR |= UART_LCR_DLAB_EN;
-
- LPC_UART1->DLM = UART_LOAD_DLM(best_divisor);
-
- LPC_UART1->DLL = UART_LOAD_DLL(best_divisor);
-
- /* Then reset DLAB bit */
- LPC_UART1->LCR &= (~UART_LCR_DLAB_EN) & UART_LCR_BITMASK;
-
- LPC_UART1->FDR = (UART_FDR_MULVAL(bestm)
- | UART_FDR_DIVADDVAL(bestd)) & UART_FDR_BITMASK;
- }
- else if (UartID == UART_4)
- {
- LPC_UART4->LCR |= UART_LCR_DLAB_EN;
-
- LPC_UART4->DLM = UART_LOAD_DLM(best_divisor);
-
- LPC_UART4->DLL = UART_LOAD_DLL(best_divisor);
-
- /* Then reset DLAB bit */
- LPC_UART4->LCR &= (~UART_LCR_DLAB_EN) & UART_LCR_BITMASK;
-
- LPC_UART4->FDR = (UART_FDR_MULVAL(bestm)
- | UART_FDR_DIVADDVAL(bestd)) & UART_FDR_BITMASK;
- }
-
- else
- {
- LPC_UART_TypeDef *UARTx = uart_get_pointer(UartID);
- UARTx->LCR |= UART_LCR_DLAB_EN;
-
- UARTx->DLM = UART_LOAD_DLM(best_divisor);
-
- UARTx->DLL = UART_LOAD_DLL(best_divisor);
-
- /* Then reset DLAB bit */
- UARTx->LCR &= (~UART_LCR_DLAB_EN) & UART_LCR_BITMASK;
-
- UARTx->FDR = (UART_FDR_MULVAL(bestm) \
- | UART_FDR_DIVADDVAL(bestd)) & UART_FDR_BITMASK;
- }
- errorStatus = SUCCESS;
- }
-
- return errorStatus;
-}
-/*********************************************************************//**
- * @brief Get the pointer of a given Uart
- * @param[in] UARTx Pointer to selected UART peripheral, should be:
- * - UART_0: UART0 peripheral
- * - UART_1: UART1 peripheral
- * - UART_2: UART2 peripheral
- * - UART_3: UART3 peripheral
- * - UART_4: UART4 peripheral
- * @return LPC_UART0~LPC_UART4
- **********************************************************************/
-LPC_UART_TypeDef *uart_get_pointer(UART_ID_Type UartID)
-{
- LPC_UART_TypeDef *UARTx = NULL;
- switch(UartID)
- {
- case UART_0:
- UARTx = LPC_UART0;
- break;
- case UART_2:
- UARTx = LPC_UART2;
- break;
- case UART_3:
- UARTx = LPC_UART3;
- break;
- default:
- break;
- }
- return UARTx;
-}
-
-/* End of Private Functions ---------------------------------------------------- */
-
-
-/* Public Functions ----------------------------------------------------------- */
-/** @addtogroup UART_Public_Functions
- * @{
- */
-/* UART Init/DeInit functions -------------------------------------------------*/
-/********************************************************************//**
- * @brief Initializes the UARTx peripheral according to the specified
- * parameters in the UART_ConfigStruct.
- * @param[in] UARTx UART peripheral selected, should be:
- * - UART_0: UART0 peripheral
- * - UART_1: UART1 peripheral
- * - UART_2: UART2 peripheral
- * - UART_3: UART3 peripheral
- * - UART_4: UART4 peripheral
- * @param[in] UART_ConfigStruct Pointer to a UART_CFG_Type structure
-* that contains the configuration information for the
-* specified UART peripheral.
- * @return None
- *********************************************************************/
-void UART_Init(UART_ID_Type UartID, UART_CFG_Type *UART_ConfigStruct)
-{
- uint32_t tmp;
- switch (UartID)
- {
- case UART_0:
- case UART_2:
- case UART_3:
- {
- LPC_UART_TypeDef *UARTx = uart_get_pointer(UartID);
- if(UartID == UART_0)
- /* Set up clock and power for UART module */
- CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCUART0, ENABLE);
- else if(UartID == UART_2)
- /* Set up clock and power for UART module */
- CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCUART2, ENABLE);
- else if(UartID == UART_3)
- /* Set up clock and power for UART module */
- CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCUART3, ENABLE);;
- /* FIFOs are empty */
- UARTx->FCR = ( UART_FCR_FIFO_EN | UART_FCR_RX_RS | UART_FCR_TX_RS);
-
- // Disable FIFO
- UARTx->FCR = 0;
-
- // Dummy reading
- while (UARTx->LSR & UART_LSR_RDR)
- {
- tmp = UARTx->RBR;
- }
-
- UARTx->TER = UART_TER_TXEN;
-
- // Wait for current transmit complete
- while (!(UARTx->LSR & UART_LSR_THRE));
-
- // Disable Tx
- UARTx->TER = 0;
-
- // Disable interrupt
- UARTx->IER = 0;
-
- // Set LCR to default state
- UARTx->LCR = 0;
-
- // Set ACR to default state
- UARTx->ACR = 0;
-
- // Set RS485 control to default state
- UARTx->RS485CTRL = 0;
-
- // Set RS485 delay timer to default state
- UARTx->RS485DLY = 0;
-
- // Set RS485 addr match to default state
- UARTx->ADRMATCH = 0;
-
- // Dummy reading
- tmp = UARTx->LSR;
- }
- break;
- case UART_1:
- {
- /* Set up clock and power for UART module */
- CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCUART1, ENABLE);
-
- /* FIFOs are empty */
- LPC_UART1->FCR = ( UART_FCR_FIFO_EN | UART_FCR_RX_RS | UART_FCR_TX_RS);
-
- // Disable FIFO
- LPC_UART1->FCR = 0;
-
- // Dummy reading
- while (LPC_UART1->LSR & UART_LSR_RDR)
- {
- tmp = LPC_UART1->RBR;
- }
-
- LPC_UART1->TER = UART_TER_TXEN;
-
- // Wait for current transmit complete
- while (!(LPC_UART1->LSR & UART_LSR_THRE));
-
- // Disable Tx
- LPC_UART1->TER = 0;
-
- // Disable interrupt
- LPC_UART1->IER = 0;
-
- // Set LCR to default state
- LPC_UART1->LCR = 0;
-
- // Set ACR to default state
- LPC_UART1->ACR = 0;
-
- // Set RS485 control to default state
- LPC_UART1->RS485CTRL = 0;
-
- // Set RS485 delay timer to default state
- LPC_UART1->RS485DLY = 0;
-
- // Set RS485 addr match to default state
- LPC_UART1->ADRMATCH = 0;
-
- // Dummy reading
- tmp = LPC_UART1->LSR;
-
- // Set Modem Control to default state
- LPC_UART1->MCR = 0;
-
- //Dummy Reading to Clear Status
- tmp = LPC_UART1->MSR;
- }
- break;
- case UART_4:
- {
- /* Set up clock and power for UART module */
- CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCUART4, ENABLE);
-
- /* FIFOs are empty */
- LPC_UART4->FCR = ( UART_FCR_FIFO_EN | UART_FCR_RX_RS | UART_FCR_TX_RS);
-
- // Disable FIFO
- LPC_UART4->FCR = 0;
-
- // Dummy reading
- while (LPC_UART4->LSR & UART_LSR_RDR)
- {
- tmp = LPC_UART4->RBR;
- }
-
- LPC_UART4->TER = UART4_TER_TXEN;
-
- // Wait for current transmit complete
- while (!(LPC_UART4->LSR & UART_LSR_THRE));
-
- // Disable Tx
- LPC_UART4->TER = 0;
-
- // Disable interrupt
- LPC_UART4->IER = 0;
-
- // Set LCR to default state
- LPC_UART4->LCR = 0;
-
- // Set ACR to default state
- LPC_UART4->ACR = 0;
-
- // Set RS485 control to default state
- LPC_UART4->RS485CTRL = 0;
-
- // Set RS485 delay timer to default state
- LPC_UART4->RS485DLY = 0;
-
- // Set RS485 addr match to default state
- LPC_UART4->ADRMATCH = 0;
-
- // Dummy reading
- tmp = LPC_UART4->LSR;
-
- // Set IrDA Mode to default state
- LPC_UART4->ICR = 0;
- }
- break;
- }
-
- // Set Line Control register ----------------------------
-
- uart_set_divisors(UartID, (UART_ConfigStruct->Baud_rate));
-
- if (UartID == UART_1)
- {
- tmp = (LPC_UART1->LCR & (UART_LCR_DLAB_EN | UART_LCR_BREAK_EN)) \
- & UART_LCR_BITMASK;
- }
- else if (UartID == UART_4)
- {
- tmp = (LPC_UART4->LCR & (UART_LCR_DLAB_EN | UART_LCR_BREAK_EN)) \
- & UART_LCR_BITMASK;
- }
- else
- {
- LPC_UART_TypeDef *UARTx = uart_get_pointer(UartID);
- tmp = (UARTx->LCR & (UART_LCR_DLAB_EN | UART_LCR_BREAK_EN)) & UART_LCR_BITMASK;
- }
-
- switch (UART_ConfigStruct->Databits)
- {
- case UART_DATABIT_5:
- tmp |= UART_LCR_WLEN5;
- break;
-
- case UART_DATABIT_6:
- tmp |= UART_LCR_WLEN6;
- break;
-
- case UART_DATABIT_7:
- tmp |= UART_LCR_WLEN7;
- break;
-
- case UART_DATABIT_8:
-
- default:
- tmp |= UART_LCR_WLEN8;
- break;
- }
-
- if (UART_ConfigStruct->Parity == UART_PARITY_NONE)
- {
- // Do nothing...
- }
- else
- {
- tmp |= UART_LCR_PARITY_EN;
- switch (UART_ConfigStruct->Parity)
- {
- case UART_PARITY_ODD:
- tmp |= UART_LCR_PARITY_ODD;
- break;
-
- case UART_PARITY_EVEN:
- tmp |= UART_LCR_PARITY_EVEN;
- break;
-
- case UART_PARITY_SP_1:
- tmp |= UART_LCR_PARITY_F_1;
- break;
-
- case UART_PARITY_SP_0:
- tmp |= UART_LCR_PARITY_F_0;
- break;
-
- default:
- break;
- }
- }
-
- switch (UART_ConfigStruct->Stopbits)
- {
- case UART_STOPBIT_2:
- tmp |= UART_LCR_STOPBIT_SEL;
- break;
-
- case UART_STOPBIT_1:
-
- default:
- // Do no thing
- break;
- }
-
-
- // Write back to LCR, configure FIFO and Disable Tx
- if (UartID == UART_1)
- {
- LPC_UART1->LCR = (uint8_t)(tmp & UART_LCR_BITMASK);
- }
- else if (UartID == UART_4)
- {
- LPC_UART4->LCR = (uint8_t)(tmp & UART_LCR_BITMASK);
- }
- else
- {
- LPC_UART_TypeDef *UARTx = uart_get_pointer(UartID);
- UARTx->LCR = (uint8_t)(tmp & UART_LCR_BITMASK);
- }
-}
-
-/*********************************************************************//**
- * @brief De-initializes the UARTx peripheral registers to their
- * default reset values.
- * @param[in] UartID UART peripheral selected, should be:
- * - UART_0: UART0 peripheral
- * - UART_1: UART1 peripheral
- * - UART_2: UART2 peripheral
- * - UART_3: UART3 peripheral
- * - UART_4: UART4 peripheral
- * @return None
- **********************************************************************/
-void UART_DeInit(UART_ID_Type UartID)
-{
- UART_TxCmd(UartID, DISABLE);
- if (UartID == UART_0)
- {
- /* Set up clock and power for UART module */
- CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCUART0, DISABLE);
- }
-
- else if (UartID == UART_1)
- {
- /* Set up clock and power for UART module */
- CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCUART1, DISABLE);
- }
-
- else if (UartID == UART_2)
- {
- /* Set up clock and power for UART module */
- CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCUART2, DISABLE);
- }
-
- else if (UartID == UART_3)
- {
- /* Set up clock and power for UART module */
- CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCUART3, DISABLE);
- }
- else if (UartID == UART_4)
- {
- /* Set up clock and power for UART module */
- CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCUART4, DISABLE);
- }
-}
-
-/*****************************************************************************//**
-* @brief Fills each UART_InitStruct member with its default value:
-* - 115200 bps
-* - 8-bit data
-* - 1 Stopbit
-* - None Parity
-* @param[in] UART_InitStruct Pointer to a UART_CFG_Type structure
-* which will be initialized.
-* @return None
-*******************************************************************************/
-void UART_ConfigStructInit(UART_CFG_Type *UART_InitStruct)
-{
- UART_InitStruct->Baud_rate = 115200;
-
- UART_InitStruct->Databits = UART_DATABIT_8;
-
- UART_InitStruct->Parity = UART_PARITY_NONE;
-
- UART_InitStruct->Stopbits = UART_STOPBIT_1;
-}
-
-/* UART Send/Recieve functions -------------------------------------------------*/
-/*********************************************************************//**
- * @brief Transmit a single data through UART peripheral
- * @param[in] UARTx UART peripheral selected, should be:
- * - UART_0: UART0 peripheral
- * - UART_1: UART1 peripheral
- * - UART_2: UART2 peripheral
- * - UART_3: UART3 peripheral
- * - UART_4: UART4 peripheral
- * @param[in] Data Data to transmit (must be 8-bit long)
- * @return None
- **********************************************************************/
-void UART_SendByte(UART_ID_Type UartID, uint8_t Data)
-{
- switch (UartID)
- {
- case UART_0:
- LPC_UART0->THR = Data & UART_THR_MASKBIT;
- break;
- case UART_1:
- LPC_UART1->THR = Data & UART_THR_MASKBIT;
- break;
- case UART_2:
- LPC_UART2->THR = Data & UART_THR_MASKBIT;
- break;
- case UART_3:
- LPC_UART3->THR = Data & UART_THR_MASKBIT;
- break;
- case UART_4:
- LPC_UART4->THR = Data & UART_THR_MASKBIT;
- break;
- }
-
-}
-
-
-/*********************************************************************//**
- * @brief Receive a single data from UART peripheral
- * @param[in] UARTx UART peripheral selected, should be:
- * - UART_0: UART0 peripheral
- * - UART_1: UART1 peripheral
- * - UART_2: UART2 peripheral
- * - UART_3: UART3 peripheral
- * - UART_4: UART4 peripheral
- * @return Data received
- **********************************************************************/
-uint8_t UART_ReceiveByte(UART_ID_Type UartID)
-{
- switch (UartID)
- {
- case UART_0:
- return (LPC_UART0->RBR & UART_RBR_MASKBIT);
- case UART_1:
- return (LPC_UART1->RBR & UART_RBR_MASKBIT);
- case UART_2:
- return (LPC_UART2->RBR & UART_RBR_MASKBIT);
- case UART_3:
- return (LPC_UART3->RBR & UART_RBR_MASKBIT);
- case UART_4:
- return (LPC_UART4->RBR & UART_RBR_MASKBIT);
- }
- return 0x00;
-}
-
-/*********************************************************************//**
- * @brief Send a block of data via UART peripheral
- * @param[in] UARTx Selected UART peripheral used to send data, should be:
- * - UART_0: UART0 peripheral
- * - UART_1: UART1 peripheral
- * - UART_2: UART2 peripheral
- * - UART_3: UART3 peripheral
- * - UART_4: UART4 peripheral
- * @param[in] txbuf Pointer to Transmit buffer
- * @param[in] buflen Length of Transmit buffer
- * @param[in] flag Flag used in UART transfer, should be
- * NONE_BLOCKING or BLOCKING
- * @return Number of bytes sent.
- *
- * Note: when using UART in BLOCKING mode, a time-out condition is used
- * via defined symbol UART_BLOCKING_TIMEOUT.
- **********************************************************************/
-uint32_t UART_Send(UART_ID_Type UartID, uint8_t *txbuf,
- uint32_t buflen, TRANSFER_BLOCK_Type flag)
-{
- uint32_t bToSend, bSent, timeOut, fifo_cnt;
- uint8_t *pChar = txbuf;
- __IO uint32_t *LSR = NULL;
-
- switch (UartID)
- {
- case UART_0:
- LSR = (__IO uint32_t *)&LPC_UART0->LSR;
- break;
- case UART_1:
- LSR = (__IO uint32_t *)&LPC_UART1->LSR;
- break;
- case UART_2:
- LSR = (__IO uint32_t *)&LPC_UART2->LSR;
- break;
- case UART_3:
- LSR = (__IO uint32_t *)&LPC_UART3->LSR;
- break;
- case UART_4:
- LSR = (__IO uint32_t *)&LPC_UART4->LSR;
- break;
- }
-
- bToSend = buflen;
-
- // blocking mode
- if (flag == BLOCKING)
- {
- bSent = 0;
- while (bToSend)
- {
- timeOut = UART_BLOCKING_TIMEOUT;
-
- // Wait for THR empty with timeout
- while (!(*LSR & UART_LSR_THRE))
- {
- if (timeOut == 0)
- break;
-
- timeOut--;
- }
-
- // Time out!
- if(timeOut == 0)
- break;
-
- fifo_cnt = UART_TX_FIFO_SIZE;
-
- while (fifo_cnt && bToSend)
- {
- UART_SendByte(UartID, (*pChar++));
-
- fifo_cnt--;
-
- bToSend--;
-
- bSent++;
- }
- }
- }
-
- // None blocking mode
- else
- {
- bSent = 0;
- while (bToSend)
- {
- if (bToSend == 0)
- break;
-
- if (!(*LSR & UART_LSR_THRE))
- {
- break;
- }
-
- fifo_cnt = UART_TX_FIFO_SIZE;
-
- while (fifo_cnt && bToSend)
- {
- UART_SendByte(UartID, (*pChar++));
-
- bToSend--;
-
- fifo_cnt--;
-
- bSent++;
- }
- }
- }
-
- return bSent;
-}
-
-/*********************************************************************//**
- * @brief Receive a block of data via UART peripheral
- * @param[in] UARTx Selected UART peripheral used to send data,
- * should be:
- * - UART_0: UART0 peripheral
- * - UART_1: UART1 peripheral
- * - UART_2: UART2 peripheral
- * - UART_3: UART3 peripheral
- * - UART_4: UART4 peripheral
- * @param[out] rxbuf Pointer to Received buffer
- * @param[in] buflen Length of Received buffer
- * @param[in] flag Flag mode, should be NONE_BLOCKING or BLOCKING
-
- * @return Number of bytes received
- *
- * Note: when using UART in BLOCKING mode, a time-out condition is used
- * via defined symbol UART_BLOCKING_TIMEOUT.
- **********************************************************************/
-uint32_t UART_Receive(UART_ID_Type UartID, uint8_t *rxbuf,
- uint32_t buflen, TRANSFER_BLOCK_Type flag)
-{
- uint32_t bToRecv, bRecv, timeOut;
- uint8_t *pChar = rxbuf;
- __IO uint32_t *LSR = NULL;
-
- switch (UartID)
- {
- case UART_0:
- LSR = (__IO uint32_t *)&LPC_UART0->LSR;
- break;
- case UART_1:
- LSR = (__IO uint32_t *)&LPC_UART1->LSR;
- break;
- case UART_2:
- LSR = (__IO uint32_t *)&LPC_UART2->LSR;
- break;
- case UART_3:
- LSR = (__IO uint32_t *)&LPC_UART3->LSR;
- break;
- case UART_4:
- LSR = (__IO uint32_t *)&LPC_UART4->LSR;
- break;
- }
-
- bToRecv = buflen;
-
- // Blocking mode
- if (flag == BLOCKING)
- {
- bRecv = 0;
- while (bToRecv)
- {
- timeOut = UART_BLOCKING_TIMEOUT;
- while (!(*LSR & UART_LSR_RDR))
- {
- if (timeOut == 0)
- break;
-
- timeOut--;
- }
-
- // Time out!
- if(timeOut == 0)
- break;
-
- // Get data from the buffer
- (*pChar++) = UART_ReceiveByte(UartID);
-
- bToRecv--;
-
- bRecv++;
- }
- }
- // None blocking mode
- else
- {
- bRecv = 0;
- while (bToRecv)
- {
- if (!(*LSR & UART_LSR_RDR))
- {
- break;
- }
- else
- {
- (*pChar++) = UART_ReceiveByte(UartID);
-
- bRecv++;
-
- bToRecv--;
- }
- }
- }
-
- return bRecv;
-}
-
-/*********************************************************************//**
- * @brief Force BREAK character on UART line, output pin UARTx TXD is
- forced to logic 0.
- * @param[in] UARTx UART peripheral selected, should be:
- * - UART_0: UART0 peripheral
- * - UART_1: UART1 peripheral
- * - UART_2: UART2 peripheral
- * - UART_3: UART3 peripheral
- * - UART_4: UART4 peripheral
- * @return None
- **********************************************************************/
-void UART_ForceBreak(UART_ID_Type UartID)
-{
- switch (UartID)
- {
- case UART_0:
- LPC_UART0->LCR |= UART_LCR_BREAK_EN;
- break;
- case UART_1:
- LPC_UART1->LCR |= UART_LCR_BREAK_EN;
- break;
- case UART_2:
- LPC_UART2->LCR |= UART_LCR_BREAK_EN;
- break;
- case UART_3:
- LPC_UART3->LCR |= UART_LCR_BREAK_EN;
- break;
- case UART_4:
- LPC_UART4->LCR |= UART_LCR_BREAK_EN;
- break;
- }
-}
-
-
-/********************************************************************//**
- * @brief Enable or disable specified UART interrupt.
- * @param[in] UARTx UART peripheral selected, should be
- * - UART_0: UART0 peripheral
- * - UART_1: UART1 peripheral
- * - UART_2: UART2 peripheral
- * - UART_3: UART3 peripheral
- * - UART_4: UART4 peripheral
- * @param[in] UARTIntCfg Specifies the interrupt flag,
- * should be one of the following:
- - UART_INTCFG_RBR : RBR Interrupt enable
- - UART_INTCFG_THRE : THR Interrupt enable
- - UART_INTCFG_RLS : RX line status interrupt enable
- - UART1_INTCFG_MS : Modem status interrupt enable (UART1 only)
- - UART1_INTCFG_CTS : CTS1 signal transition interrupt enable (UART1 only)
- - UART_INTCFG_ABEO : Enables the end of auto-baud interrupt
- - UART_INTCFG_ABTO : Enables the auto-baud time-out interrupt
- * @param[in] NewState New state of specified UART interrupt type,
- * should be:
- * - ENALBE: Enable this UART interrupt type.
-* - DISALBE: Disable this UART interrupt type.
- * @return None
- *********************************************************************/
-void UART_IntConfig(UART_ID_Type UartID, UART_INT_Type UARTIntCfg, FunctionalState NewState)
-{
- uint32_t tmp;
- __IO uint32_t *IER = NULL;
- uint32_t IERMask = 0;
-
- switch (UartID)
- {
- case UART_0:
- IER = &LPC_UART0->IER;
- IERMask = UART_IER_BITMASK;
- break;
- case UART_1:
- IER = &LPC_UART1->IER;
- IERMask = UART1_IER_BITMASK;
- break;
- case UART_2:
- IER = &LPC_UART2->IER;
- IERMask = UART_IER_BITMASK;
- break;
- case UART_3:
- IER = &LPC_UART3->IER;
- IERMask = UART_IER_BITMASK;
- break;
- case UART_4:
- IER = &LPC_UART4->IER;
- IERMask = UART_IER_BITMASK;
- break;
- }
-
-
- switch(UARTIntCfg)
- {
- case UART_INTCFG_RBR:
- tmp = UART_IER_RBRINT_EN;
- break;
-
- case UART_INTCFG_THRE:
- tmp = UART_IER_THREINT_EN;
- break;
-
- case UART_INTCFG_RLS:
- tmp = UART_IER_RLSINT_EN;
- break;
-
- case UART_INTCFG_MS:
- tmp = UART1_IER_MSINT_EN;
- break;
-
- case UART_INTCFG_CTS:
- tmp = UART1_IER_CTSINT_EN;
- break;
-
- case UART_INTCFG_ABEO:
- tmp = UART_IER_ABEOINT_EN;
- break;
-
- case UART_INTCFG_ABTO:
- tmp = UART_IER_ABTOINT_EN;
- break;
- }
-
- if (NewState == ENABLE)
- {
- *IER |= tmp& IERMask;
- }
- else
- {
- *IER &= (~tmp) & IERMask;
- }
-}
-
-
-/********************************************************************//**
- * @brief Get current value of Line Status register in UART peripheral.
- * @param[in] UARTx UART peripheral selected, should be:
- * - UART_0: UART0 peripheral
- * - UART_1: UART1 peripheral
- * - UART_2: UART2 peripheral
- * - UART_3: UART3 peripheral
- * - UART_4: UART4 peripheral
- * @return Current value of Line Status register in UART peripheral.
- * Note: The return value of this function must be ANDed with each member in
- * UART_LS_Type enumeration to determine current flag status
- * corresponding to each Line status type. Because some flags in
- * Line Status register will be cleared after reading, the next reading
- * Line Status register could not be correct. So this function used to
- * read Line status register in one time only, then the return value
- * used to check all flags.
- *********************************************************************/
-uint8_t UART_GetLineStatus(UART_ID_Type UartID)
-{
- switch (UartID)
- {
- case UART_0:
- return ((LPC_UART0->LSR) & UART_LSR_BITMASK);
- case UART_1:
- return ((LPC_UART1->LSR) & UART_LSR_BITMASK);
- case UART_2:
- return ((LPC_UART2->LSR) & UART_LSR_BITMASK);
- case UART_3:
- return ((LPC_UART3->LSR) & UART_LSR_BITMASK);
- case UART_4:
- return ((LPC_UART4->LSR) & UART_LSR_BITMASK);
- }
- return 0;
-}
-
-/********************************************************************//**
- * @brief Get Interrupt Identification value
- * @param[in] UARTx UART peripheral selected, should be:
- * - UART_0: UART0 peripheral
- * - UART_1: UART1 peripheral
- * - UART_2: UART2 peripheral
- * - UART_3: UART3 peripheral
- * - UART_4: UART4 peripheral
- * @return Current value of UART UIIR register in UART peripheral.
- *********************************************************************/
-uint32_t UART_GetIntId(UART_ID_Type UartID)
-{
- switch (UartID)
- {
- case UART_0:
- return ((LPC_UART0->IIR) & UART_IIR_BITMASK);
- case UART_1:
- return ((LPC_UART1->IIR) & UART_IIR_BITMASK);
- case UART_2:
- return ((LPC_UART2->IIR) & UART_IIR_BITMASK);
- case UART_3:
- return ((LPC_UART3->IIR) & UART_IIR_BITMASK);
- case UART_4:
- return ((LPC_UART4->IIR) & UART_IIR_BITMASK);
- }
- return 0;
-}
-
-/*********************************************************************//**
- * @brief Check whether if UART is busy or not
- * @param[in] UARTx UART peripheral selected, should be:
- * - UART_0: UART0 peripheral
- * - UART_1: UART1 peripheral
- * - UART_2: UART2 peripheral
- * - UART_3: UART3 peripheral
- * - UART_4: UART4 peripheral
- * @return RESET if UART is not busy, otherwise return SET.
- **********************************************************************/
-FlagStatus UART_CheckBusy(UART_ID_Type UartID)
-{
- uint32_t LSR = 0;
- switch (UartID)
- {
- case UART_0:
- LSR = (LPC_UART0)->LSR & UART_LSR_TEMT;
- break;
- case UART_1:
- LSR = (LPC_UART1)->LSR & UART_LSR_TEMT;
- break;
- case UART_2:
- LSR = (LPC_UART2)->LSR & UART_LSR_TEMT;
- break;
- case UART_3:
- LSR = (LPC_UART3)->LSR & UART_LSR_TEMT;
- break;
- case UART_4:
- LSR = (LPC_UART4)->LSR & UART_LSR_TEMT;
- break;
- }
-
- if (LSR & UART_LSR_TEMT)
- {
- return RESET;
- }
- return SET;
-}
-
-
-/*********************************************************************//**
- * @brief Configure FIFO function on selected UART peripheral
- * @param[in] UARTx UART peripheral selected, should be:
- * - UART_0: UART0 peripheral
- * - UART_1: UART1 peripheral
- * - UART_2: UART2 peripheral
- * - UART_3: UART3 peripheral
- * - UART_4: UART4 peripheral
- * @param[in] FIFOCfg Pointer to a UART_FIFO_CFG_Type Structure that
- * contains specified information about FIFO configuration
- * @return none
- **********************************************************************/
-void UART_FIFOConfig(UART_ID_Type UartID, UART_FIFO_CFG_Type *FIFOCfg)
-{
- uint8_t tmp = 0;
-
- tmp |= UART_FCR_FIFO_EN;
-
- switch (FIFOCfg->FIFO_Level)
- {
- case UART_FIFO_TRGLEV0:
- tmp |= UART_FCR_TRG_LEV0;
- break;
-
- case UART_FIFO_TRGLEV1:
- tmp |= UART_FCR_TRG_LEV1;
- break;
-
- case UART_FIFO_TRGLEV2:
- tmp |= UART_FCR_TRG_LEV2;
- break;
-
- case UART_FIFO_TRGLEV3:
-
- default:
- tmp |= UART_FCR_TRG_LEV3;
- break;
- }
-
- if (FIFOCfg->FIFO_ResetTxBuf == ENABLE)
- {
- tmp |= UART_FCR_TX_RS;
- }
-
- if (FIFOCfg->FIFO_ResetRxBuf == ENABLE)
- {
- tmp |= UART_FCR_RX_RS;
- }
-
- if (FIFOCfg->FIFO_DMAMode == ENABLE)
- {
- tmp |= UART_FCR_DMAMODE_SEL;
- }
-
-
- //write to FIFO control register
- switch (UartID)
- {
- case UART_0:
- LPC_UART0->FCR = tmp & UART_FCR_BITMASK;
- break;
- case UART_1:
- LPC_UART1->FCR = tmp & UART_FCR_BITMASK;
- break;
- case UART_2:
- LPC_UART2->FCR = tmp & UART_FCR_BITMASK;
- break;
- case UART_3:
- LPC_UART3->FCR = tmp & UART_FCR_BITMASK;
- break;
- case UART_4:
- LPC_UART4->FCR = tmp & UART_FCR_BITMASK;
- break;
- }
-}
-
-/*****************************************************************************//**
-* @brief Fills each UART_FIFOInitStruct member with its default value:
-* - FIFO_DMAMode = DISABLE
-* - FIFO_Level = UART_FIFO_TRGLEV0
-* - FIFO_ResetRxBuf = ENABLE
-* - FIFO_ResetTxBuf = ENABLE
-* - FIFO_State = ENABLE
-* @param[in] UART_FIFOInitStruct Pointer to a UART_FIFO_CFG_Type structure
-* which will be initialized.
-* @return None
-*******************************************************************************/
-void UART_FIFOConfigStructInit(UART_FIFO_CFG_Type *UART_FIFOInitStruct)
-{
- UART_FIFOInitStruct->FIFO_DMAMode = DISABLE;
-
- UART_FIFOInitStruct->FIFO_Level = UART_FIFO_TRGLEV0;
-
- UART_FIFOInitStruct->FIFO_ResetRxBuf = ENABLE;
-
- UART_FIFOInitStruct->FIFO_ResetTxBuf = ENABLE;
-}
-
-
-/*********************************************************************//**
- * @brief Start/Stop Auto Baudrate activity
- * @param[in] UARTx UART peripheral selected, should be
- * - UART_0: UART0 peripheral
- * - UART_1: UART1 peripheral
- * - UART_2: UART2 peripheral
- * - UART_3: UART3 peripheral
- * - UART_4: UART4 peripheral
- * @param[in] ABConfigStruct A pointer to UART_AB_CFG_Type structure that
- * contains specified information about UART
- * auto baudrate configuration
- * @param[in] NewState New State of Auto baudrate activity, should be:
- * - ENABLE: Start this activity
- * - DISABLE: Stop this activity
- * Note: Auto-baudrate mode enable bit will be cleared once this mode
- * completed.
- * @return none
- **********************************************************************/
-void UART_ABCmd(UART_ID_Type UartID, UART_AB_CFG_Type *ABConfigStruct,
- FunctionalState NewState)
-{
- uint32_t tmp;
-
- tmp = 0;
- if (NewState == ENABLE)
- {
- if (ABConfigStruct->ABMode == UART_AUTOBAUD_MODE1)
- {
- tmp |= UART_ACR_MODE;
- }
- if (ABConfigStruct->AutoRestart == ENABLE)
- {
- tmp |= UART_ACR_AUTO_RESTART;
- }
- }
-
- if (UartID == UART_1)
- {
- if (NewState == ENABLE)
- {
- // Clear DLL and DLM value
- LPC_UART1->LCR |= UART_LCR_DLAB_EN;
-
- LPC_UART1->DLL = 0;
-
- LPC_UART1->DLM = 0;
-
- LPC_UART1->LCR &= ~UART_LCR_DLAB_EN;
-
- // FDR value must be reset to default value
- LPC_UART1->FDR = 0x10;
-
- LPC_UART1->ACR = UART_ACR_START | tmp;
- }
- else
- {
- LPC_UART1->ACR = 0;
- }
- }
- else if (UartID == UART_4)
- {
- if (NewState == ENABLE)
- {
- // Clear DLL and DLM value
- LPC_UART4->LCR |= UART_LCR_DLAB_EN;
-
- LPC_UART4->DLL = 0;
-
- LPC_UART4->DLM = 0;
-
- LPC_UART4->LCR &= ~UART_LCR_DLAB_EN;
-
- // FDR value must be reset to default value
- LPC_UART4->FDR = 0x10;
-
- LPC_UART4->ACR = UART_ACR_START | tmp;
- }
- else
- {
- LPC_UART4->ACR = 0;
- }
- }
- else
- {
- LPC_UART_TypeDef *UARTx = uart_get_pointer(UartID);
- if (NewState == ENABLE)
- {
- // Clear DLL and DLM value
- UARTx->LCR |= UART_LCR_DLAB_EN;
-
- UARTx->DLL = 0;
-
- UARTx->DLM = 0;
-
- UARTx->LCR &= ~UART_LCR_DLAB_EN;
-
- // FDR value must be reset to default value
- UARTx->FDR = 0x10;
-
- UARTx->ACR = UART_ACR_START | tmp;
- }
- else
- {
- UARTx->ACR = 0;
- }
- }
-}
-
-/*********************************************************************//**
- * @brief Clear Autobaud Interrupt Pending
- * @param[in] UARTx UART peripheral selected, should be
- * - UART_0: UART0 peripheral
- * - UART_1: UART1 peripheral
- * - UART_2: UART2 peripheral
- * - UART_3: UART3 peripheral
- * - UART_4: UART4 peripheral
- * @param[in] ABIntType type of auto-baud interrupt, should be:
- * - UART_AUTOBAUD_INTSTAT_ABEO: End of Auto-baud interrupt
- * - UART_AUTOBAUD_INTSTAT_ABTO: Auto-baud time out interrupt
- * @return none
- **********************************************************************/
-void UART_ABClearIntPending(UART_ID_Type UartID, UART_ABEO_Type ABIntType)
-{
- if (UartID == UART_1)
- {
- LPC_UART1->ACR |= ABIntType;
- }
- else if (UartID == UART_4)
- {
- LPC_UART4->ACR |= ABIntType;
- }
- else
- {
- LPC_UART_TypeDef *UARTx = uart_get_pointer(UartID);
- UARTx->ACR |= ABIntType;
- }
-}
-
-/*********************************************************************//**
- * @brief Enable/Disable transmission on UART TxD pin
- * @param[in] UARTx UART peripheral selected, should be:
- * - UART_0: UART0 peripheral
- * - UART_1: UART1 peripheral
- * - UART_2: UART2 peripheral
- * - UART_3: UART3 peripheral
- * - UART_4: UART4 peripheral
- * @param[in] NewState New State of Tx transmission function, should be:
- * - ENABLE: Enable this function
- - DISABLE: Disable this function
- * @return none
- **********************************************************************/
-void UART_TxCmd(UART_ID_Type UartID, FunctionalState NewState)
-{
- if (NewState == ENABLE)
- {
- if (UartID == UART_1)
- {
- LPC_UART1->TER |= UART_TER_TXEN;
- }
- else if (UartID == UART_4)
- {
- LPC_UART4->TER |= UART4_TER_TXEN;
- }
- else
- {
- LPC_UART_TypeDef *UARTx = uart_get_pointer(UartID);
- UARTx->TER |= UART_TER_TXEN;
- }
- }
- else
- {
- if (UartID == UART_1)
- {
- LPC_UART1->TER &= (~UART_TER_TXEN) & UART_TER_BITMASK;
- }
- else if (UartID == UART_4)
- {
- LPC_UART4->TER &= (~UART4_TER_TXEN) & UART4_TER_BITMASK;
- }
- else
- {
- LPC_UART_TypeDef *UARTx = uart_get_pointer(UartID);
- UARTx->TER &= (~UART_TER_TXEN) & UART_TER_BITMASK;
- }
- }
-}
-
-/* UART IrDA functions ---------------------------------------------------*/
-/*********************************************************************//**
- * @brief Enable or disable inverting serial input function of IrDA
- * on UART peripheral.
- * @param[in] UARTx UART peripheral selected, should be LPC_UART4 (only)
- * @param[in] NewState New state of inverting serial input, should be:
- * - ENABLE: Enable this function.
- * - DISABLE: Disable this function.
- * @return none
- **********************************************************************/
-void UART_IrDAInvtInputCmd(UART_ID_Type UartID, FunctionalState NewState)
-{
- if (UartID != UART_4)
- return;
-
- if (NewState == ENABLE)
- {
- LPC_UART4->ICR |= UART_ICR_IRDAINV;
- }
- else if (NewState == DISABLE)
- {
- LPC_UART4->ICR &= (~UART_ICR_IRDAINV) & UART_ICR_BITMASK;
- }
-
-}
-
-
-/*********************************************************************//**
- * @brief Enable or disable IrDA function on UART peripheral.
- * @param[in] UARTx UART peripheral selected, should be LPC_UART4 (only)
- * @param[in] NewState New state of IrDA function, should be:
- * - ENABLE: Enable this function.
- * - DISABLE: Disable this function.
- * @return none
- **********************************************************************/
-void UART_IrDACmd(UART_ID_Type UartID, FunctionalState NewState)
-{
- if (UartID != UART_4)
- return;
-
- if (NewState == ENABLE)
- {
- LPC_UART4->ICR |= UART_ICR_IRDAEN;
- }
- else
- {
- LPC_UART4->ICR &= (~UART_ICR_IRDAEN) & UART_ICR_BITMASK;
- }
-}
-
-
-/*********************************************************************//**
- * @brief Configure Pulse divider for IrDA function on UART peripheral.
- * @param[in] UARTx UART peripheral selected, should be LPC_UART4 (only)
- * @param[in] PulseDiv Pulse Divider value from Peripheral clock,
- * should be one of the following:
- - UART_IrDA_PULSEDIV2 : Pulse width = 2 * Tpclk
- - UART_IrDA_PULSEDIV4 : Pulse width = 4 * Tpclk
- - UART_IrDA_PULSEDIV8 : Pulse width = 8 * Tpclk
- - UART_IrDA_PULSEDIV16 : Pulse width = 16 * Tpclk
- - UART_IrDA_PULSEDIV32 : Pulse width = 32 * Tpclk
- - UART_IrDA_PULSEDIV64 : Pulse width = 64 * Tpclk
- - UART_IrDA_PULSEDIV128 : Pulse width = 128 * Tpclk
- - UART_IrDA_PULSEDIV256 : Pulse width = 256 * Tpclk
-
- * @return none
- **********************************************************************/
-void UART_IrDAPulseDivConfig(UART_ID_Type UartID, UART_IrDA_PULSE_Type PulseDiv)
-{
- uint32_t tmp, tmp1;
-
- if (UartID != UART_4)
- return;
-
- tmp1 = UART_ICR_PULSEDIV(PulseDiv);
-
- tmp = LPC_UART4->ICR & (~ UART_ICR_PULSEDIV(7));
-
- tmp |= tmp1 | UART_ICR_FIXPULSE_EN;
-
- LPC_UART4->ICR = tmp & UART_ICR_BITMASK;
-}
-
-/* UART1 FullModem function ---------------------------------------------*/
-
-/*********************************************************************//**
- * @brief Force pin DTR/RTS corresponding to given state (Full modem mode)
- * @param[in] UARTx LPC_UART1 (only)
- * @param[in] Pin Pin that NewState will be applied to, should be:
- * - UART1_MODEM_PIN_DTR: DTR pin.
- * - UART1_MODEM_PIN_RTS: RTS pin.
- * @param[in] NewState New State of DTR/RTS pin, should be:
- * - INACTIVE: Force the pin to inactive signal.
- - ACTIVE: Force the pin to active signal.
- * @return none
- **********************************************************************/
-void UART_FullModemForcePinState(UART_ID_Type UartID,
- UART_MODEM_PIN_Type Pin,
- UART1_SignalState NewState)
-{
- uint8_t tmp = 0;
- if (UartID != UART_1)
- return;
- switch (Pin)
- {
- case UART1_MODEM_PIN_DTR:
- tmp = UART1_MCR_DTR_CTRL;
- break;
-
- case UART1_MODEM_PIN_RTS:
- tmp = UART1_MCR_RTS_CTRL;
- break;
-
- default:
- break;
- }
-
- if (NewState == ACTIVE)
- {
- LPC_UART1->MCR |= tmp;
- }
- else
- {
- LPC_UART1->MCR &= (~tmp) & UART1_MCR_BITMASK;
- }
-}
-
-
-/*********************************************************************//**
- * @brief Configure Full Modem mode for UART peripheral
- * @param[in] UARTx LPC_UART1 (only)
- * @param[in] Mode Full Modem mode, should be:
- * - UART1_MODEM_MODE_LOOPBACK: Loop back mode.
- * - UART1_MODEM_MODE_AUTO_RTS: Auto-RTS mode.
- * - UART1_MODEM_MODE_AUTO_CTS: Auto-CTS mode.
- * @param[in] NewState New State of this mode, should be:
- * - ENABLE: Enable this mode.
- - DISABLE: Disable this mode.
- * @return none
- **********************************************************************/
-void UART_FullModemConfigMode(UART_ID_Type UartID, UART_MODEM_MODE_Type Mode,
- FunctionalState NewState)
-{
- uint8_t tmp;
-
- if(UartID != UART_1)
- return;
-
- switch(Mode)
- {
- case UART1_MODEM_MODE_LOOPBACK:
- tmp = UART1_MCR_LOOPB_EN;
- break;
-
- case UART1_MODEM_MODE_AUTO_RTS:
- tmp = UART1_MCR_AUTO_RTS_EN;
- break;
-
- case UART1_MODEM_MODE_AUTO_CTS:
- tmp = UART1_MCR_AUTO_CTS_EN;
- break;
-
- default:
- break;
- }
-
- if (NewState == ENABLE)
- {
- LPC_UART1->MCR |= tmp;
- }
- else
- {
- LPC_UART1->MCR &= (~tmp) & UART1_MCR_BITMASK;
- }
-}
-
-
-/*********************************************************************//**
- * @brief Get current status of modem status register
- * @param[in] UARTx LPC_UART1 (only)
- * @return Current value of modem status register
- * Note: The return value of this function must be ANDed with each member
- * UART_MODEM_STAT_type enumeration to determine current flag status
- * corresponding to each modem flag status. Because some flags in
- * modem status register will be cleared after reading, the next reading
- * modem register could not be correct. So this function used to
- * read modem status register in one time only, then the return value
- * used to check all flags.
- **********************************************************************/
-uint8_t UART_FullModemGetStatus(UART_ID_Type UartID)
-{
- if(UartID != UART_1)
- return 0;
-
- return ((LPC_UART1->MSR) & UART1_MSR_BITMASK);
-}
-
-
-/* UART RS485 functions --------------------------------------------------------------*/
-/*********************************************************************//**
- * @brief Configure UART peripheral in RS485 mode according to the specified
-* parameters in the RS485ConfigStruct.
- * @param[in] UARTx LPC_UART0 ~LPC_UART4
- * @param[in] RS485ConfigStruct Pointer to a UART1_RS485_CTRLCFG_Type structure
-* that contains the configuration information for specified UART
-* in RS485 mode.
- * @return None
- **********************************************************************/
-void UART_RS485Config(UART_ID_Type UartID, UART1_RS485_CTRLCFG_Type *RS485ConfigStruct)
-{
- uint32_t tmp;
- __IO uint32_t *RS485DLY, *ADRMATCH, *RS485CTRL, *LCR;
-
- tmp = 0;
- if (UartID == UART_1)
- {
- RS485DLY = (__IO uint32_t *)&LPC_UART1->RS485DLY;
- ADRMATCH = (__IO uint32_t *)&LPC_UART1->ADRMATCH;
- LCR = (__IO uint32_t *)&LPC_UART1->LCR;
- RS485CTRL = (__IO uint32_t *)&LPC_UART1->RS485CTRL;
- }
- else if (UartID == UART_4)
- {
- RS485DLY = (__IO uint32_t *)&LPC_UART4->RS485DLY;
- ADRMATCH = (__IO uint32_t *)&LPC_UART4->ADRMATCH;
- LCR = (__IO uint32_t *)&LPC_UART4->LCR;
- RS485CTRL = (__IO uint32_t *)&LPC_UART4->RS485CTRL;
- }
- else
- {
- LPC_UART_TypeDef *UARTx = uart_get_pointer(UartID);
- RS485DLY = (__IO uint32_t *)&UARTx->RS485DLY;
- ADRMATCH = (__IO uint32_t *)&UARTx->ADRMATCH;
- LCR = (__IO uint32_t *)&UARTx->LCR;
- RS485CTRL = (__IO uint32_t *)&UARTx->RS485CTRL;
- }
- // If Auto Direction Control is enabled - This function is used in Master mode
- if (RS485ConfigStruct->AutoDirCtrl_State == ENABLE)
- {
- tmp |= UART_RS485CTRL_DCTRL_EN;
-
- // Set polar
- if (RS485ConfigStruct->DirCtrlPol_Level == SET)
- {
- tmp |= UART_RS485CTRL_OINV_1;
- }
-
- // Set pin according to. This condition is only with UART1. The others are used
- // OE pin as default for control the direction of RS485 buffer IC
- if ((RS485ConfigStruct->DirCtrlPin == UART_RS485_DIRCTRL_DTR) &&
- (UartID == UART_1))
- {
- tmp |= UART_RS485CTRL_SEL_DTR;
- }
-
- // Fill delay time
- *RS485DLY = RS485ConfigStruct->DelayValue & UART_RS485DLY_BITMASK;
- }
-
- // MultiDrop mode is enable
- if (RS485ConfigStruct->NormalMultiDropMode_State == ENABLE)
- {
- tmp |= UART_RS485CTRL_NMM_EN;
- }
-
- // Auto Address Detect function
- if (RS485ConfigStruct->AutoAddrDetect_State == ENABLE)
- {
- tmp |= UART_RS485CTRL_AADEN;
-
- // Fill Match Address
- *ADRMATCH = RS485ConfigStruct->MatchAddrValue & UART_RS485ADRMATCH_BITMASK;
- }
-
- // Receiver is disable
- if (RS485ConfigStruct->Rx_State == DISABLE)
- {
- tmp |= UART_RS485CTRL_RX_DIS;
- }
-
- // write back to RS485 control register
- *RS485CTRL = tmp & UART_RS485CTRL_BITMASK;
-
- // Enable Parity function and leave parity in stick '0' parity as default
- *LCR |= (UART_LCR_PARITY_F_0 | UART_LCR_PARITY_EN);
-}
-
-/*********************************************************************//**
- * @brief Enable/Disable receiver in RS485 module in UART1
- * @param[in] UARTx LPC_UART1 (only)
- * @param[in] NewState New State of command, should be:
- * - ENABLE: Enable this function.
- * - DISABLE: Disable this function.
- * @return None
- **********************************************************************/
-void UART_RS485ReceiverCmd(UART_ID_Type UartID, FunctionalState NewState)
-{
- __IO uint32_t *RS485CTRL;
- if (UartID == UART_1)
- {
- RS485CTRL = (__IO uint32_t *)&LPC_UART1->RS485DLY;
- }
- else if (UartID == UART_4)
- {
- RS485CTRL = (__IO uint32_t *)&LPC_UART4->RS485DLY;
- }
- else
- {
- LPC_UART_TypeDef *UARTx = uart_get_pointer(UartID);
- RS485CTRL = (__IO uint32_t *)&UARTx->RS485DLY;
- }
- if (NewState == ENABLE)
- {
- *RS485CTRL &= ~UART_RS485CTRL_RX_DIS;
- }
- else
- {
- *RS485CTRL |= UART_RS485CTRL_RX_DIS;
- }
-}
-
-/*********************************************************************//**
- * @brief Send data on RS485 bus with specified parity stick value (9-bit mode).
- * @param[in] UARTx LPC_UART1 (only)
- * @param[in] pDatFrm Pointer to data frame.
- * @param[in] size Size of data.
- * @param[in] ParityStick Parity Stick value, should be 0 or 1.
- * @return None
- **********************************************************************/
-uint32_t UART_RS485Send(UART_ID_Type UartID, uint8_t *pDatFrm,
- uint32_t size, uint8_t ParityStick)
-{
- uint8_t tmp, save;
- uint32_t cnt;
- __IO uint32_t *LCR, *LSR;
- if (UartID == UART_1)
- {
- LCR = (__IO uint32_t *)&LPC_UART1->LCR;
- LSR = (__IO uint32_t *)&LPC_UART1->LSR;
- }
- else if (UartID == UART_4)
- {
- LCR = (__IO uint32_t *)&LPC_UART4->LCR;
- LSR = (__IO uint32_t *)&LPC_UART4->LSR;
- }
- else
- {
- LPC_UART_TypeDef *UARTx = uart_get_pointer(UartID);
- LCR = (__IO uint32_t *)&UARTx->LCR;
- LSR = (__IO uint32_t *)&UARTx->LSR;
- }
-
- if (ParityStick)
- {
- save = tmp = *LCR & UART_LCR_BITMASK;
-
- tmp &= ~(UART_LCR_PARITY_EVEN);
-
- *LCR = tmp;
-
- cnt = UART_Send(UartID, pDatFrm, size, BLOCKING);
-
- while (!(*LSR & UART_LSR_TEMT));
-
- *LCR = save;
- }
- else
- {
- cnt = UART_Send(UartID, pDatFrm, size, BLOCKING);
-
- while (!(*LSR & UART_LSR_TEMT));
- }
-
- return cnt;
-}
-
-/*********************************************************************//**
- * @brief Send Slave address frames on RS485 bus.
- * @param[in] UARTx LPC_UART1 (only)
- * @param[in] SlvAddr Slave Address.
- * @return None
- **********************************************************************/
-void UART_RS485SendSlvAddr(UART_ID_Type UartID, uint8_t SlvAddr)
-{
- UART_RS485Send(UartID, &SlvAddr, 1, 1);
-}
-
-/*********************************************************************//**
- * @brief Send Data frames on RS485 bus.
- * @param[in] UARTx LPC_UART1 (only)
- * @param[in] pData Pointer to data to be sent.
- * @param[in] size Size of data frame to be sent.
- * @return None
- **********************************************************************/
-uint32_t UART_RS485SendData(UART_ID_Type UartID, uint8_t *pData, uint32_t size)
-{
- return (UART_RS485Send(UartID, pData, size, 0));
-}
-
-/**
- * @}
- */
-#endif /*_UART*/
-/**
- * @}
- */
-/* --------------------------------- End Of File ------------------------------ */
-
diff --git a/bsp/lpc408x/Libraries/Drivers/source/lpc_wwdt.c b/bsp/lpc408x/Libraries/Drivers/source/lpc_wwdt.c
deleted file mode 100644
index b4ca9465fc..0000000000
--- a/bsp/lpc408x/Libraries/Drivers/source/lpc_wwdt.c
+++ /dev/null
@@ -1,484 +0,0 @@
-/**********************************************************************
-* $Id$ lpc_wwdt.c 2011-06-02
-*//**
-* @file lpc_wwdt.c
-* @brief Contains all functions support for Wachtdog Timer
-* firmware library on LPC
-* @version 1.0
-* @date 02. June. 2011
-* @author NXP MCU SW Application Team
-*
-* Copyright(C) 2011, NXP Semiconductor
-* All rights reserved.
-*
-***********************************************************************
-* Software that is described herein is for illustrative purposes only
-* which provides customers with programming information regarding the
-* products. This software is supplied "AS IS" without any warranties.
-* NXP Semiconductors assumes no responsibility or liability for the
-* use of the software, conveys no license or title under any patent,
-* copyright, or mask work right to the product. NXP Semiconductors
-* reserves the right to make changes in the software without
-* notification. NXP Semiconductors also make 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'
-* relevant copyright 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.
-**********************************************************************/
-
-/* Peripheral group ----------------------------------------------------------- */
-/** @addtogroup WWDT
- * @{
- */
-#ifdef __BUILD_WITH_EXAMPLE__
-#include "lpc_libcfg.h"
-#else
-#include "lpc_libcfg_default.h"
-#endif /* __BUILD_WITH_EXAMPLE__ */
-#ifdef _WDT
-
-/* Includes ------------------------------------------------------------------- */
-#include "lpc_wwdt.h"
-#include "lpc_clkpwr.h"
-#include "lpc_pinsel.h"
-
-
- /* Public Functions ----------------------------------------------------------- */
- /** @addtogroup WDT_Public_Functions
- * @{
- */
-
- /********************************************************************//**
- * @brief Set timeout value to Timer Constant register
- * (if enable) to generate a WatchDog event if match
- *
- * @param[in] timeoutVal The value (counter) will write directly to
- * Register w/o pre-calc
- *
- * @return None
- *********************************************************************/
-int8_t WWDT_SetTimeOutRaw(uint32_t timeoutVal)
-{
- int8_t retval = 0;
-
- if(timeoutVal < WWDT_TIMEOUT_MIN)
- {
- timeoutVal = WWDT_TIMEOUT_MIN;
- retval = WWDT_FUNC_BAD_PARAM;
- }
- else if (timeoutVal > WWDT_TIMEOUT_MAX)
- {
- timeoutVal = WWDT_TIMEOUT_MAX;
- retval = WWDT_FUNC_BAD_PARAM;
- }
-
- LPC_WDT->TC = timeoutVal;
-
- return retval;
-}
-
-
-/********************************************************************//**
- * @brief Set WDT timeout (cal by usec) to TC register
- *
- * @param[in] timeout The time (usec) to generate watchdog event if
- * the watchdog counter reach this value
- *
- * @return WWDT_FUNC_OK if success
- *********************************************************************/
-int8_t WWDT_SetTimeOut(uint32_t timeout)
-{
- return WWDT_SetTimeOutRaw(WDT_GET_FROM_USEC(timeout));
-}
-
-
-/*********************************************************************//**
-* @brief Initial for Watchdog function by setting timeout
-*
-* @param[in] TimeOut time out value, should be in range:
-* 2048 .. 134217728
-*
-* @return WWDT_FUNC_OK if success
- **********************************************************************/
-int8_t WWDT_Init(uint32_t TimeOut)
-{
- return WWDT_SetTimeOut(TimeOut);
-}
-
-/*********************************************************************//**
- * @brief Configure the WatchDog by initialization all the timing
- * value for register (Warning value, Window value,...)
- *
- * @param wdtCfg a the st_Wdt_Config type value
- *
- * @return None
- **********************************************************************/
-void WWDT_Configure(st_Wdt_Config wdtCfg)
-{
- WWDT_SetTimeOut(wdtCfg.wdtTmrConst);
-
- if(wdtCfg.wdtEnable)
- {
- LPC_WDT->MOD |= WWDT_WDMOD_WDEN;
- }
- else
- {
- LPC_WDT->MOD &= ~WWDT_WDMOD_WDEN;
- }
-
- if(wdtCfg.wdtReset)
- {
- LPC_WDT->MOD |= WWDT_WDMOD_WDRESET;
- }
- else
- {
- LPC_WDT->MOD &= ~WWDT_WDMOD_WDRESET;
- }
-
- if(wdtCfg.wdtProtect)
- {
- LPC_WDT->MOD |= WWDT_WDMOD_WDPROTECT;
- }
- else
- {
- LPC_WDT->MOD &= ~WWDT_WDMOD_WDPROTECT;
- }
-
- WWDT_SetWarning(wdtCfg.wdtWarningVal);
-
- WWDT_SetWindow(wdtCfg.wdtWindowVal);
-}
-
-/*********************************************************************//**
- * @brief Start WatchDog with specific Timeout
- *
- * @param TimeOut specific Timeout for WatchDog event
- *
- * @return WWDT_FUNC_OK if success
- **********************************************************************/
-int8_t WWDT_Start(uint32_t TimeOut)
-{
- int8_t retval = WWDT_FUNC_OK;
-
- retval = WWDT_SetTimeOut(TimeOut);
-
- WWDT_Cmd(ENABLE);
-
- return retval;
-}
-
-
-/********************************************************************//**
- * @brief Update WDT timeout value and feed
- *
- * @param[in] WarnTime time to generate watchdog warning interrupt(us)
- * should be in range: 2048 .. 134217728
- *
- * @return None
- *********************************************************************/
-void WWDT_SetTimerConstant(uint32_t constVal)
-{
- LPC_WDT->TC = constVal;
-}
-
-
-/*********************************************************************//**
- * @brief Enable/Disable WDT function
- *
- * @param[in] Mode WWDT mode that will be enabled/disabled, should be:
- * - WWDT_PROTECT_MODE : protect mode
- * - WWDT_RESET_MODE : reset mode
- *
- * @param[in] NewState new state of protection function, should be:
- * - ENABLE: The watchdog reload value can be changed at any time
- * - DISABLE: The watchdog reload value can be changed only after
- * the counter is below the value of WDWARNINT and WDWINDOW
- *
- * @return None
- **********************************************************************/
-void WWDT_SetMode(uint8_t mode, FunctionalState NewState)
-{
- if (mode == WWDT_PROTECT_MODE )
- {
- if(NewState == ENABLE)
- LPC_WDT->MOD |= WWDT_WDMOD_WDPROTECT;
- else
- LPC_WDT->MOD &= ~WWDT_WDMOD_WDPROTECT;
- }
- else if(mode == WWDT_RESET_MODE)
- {
- if(NewState == ENABLE)
- LPC_WDT->MOD |= WWDT_WDMOD_WDRESET;
- else
- LPC_WDT->MOD &= ~WWDT_WDMOD_WDRESET;
- }
-}
-
-/*********************************************************************//**
- * @brief Enable/Disable WWDT activity
- *
- * @param[in] NewState To enable/disable the WatchDog
- *
- * @return None
- **********************************************************************/
-void WWDT_Enable(FunctionalState NewState)
-{
- if(NewState == ENABLE)
- {
- LPC_WDT->MOD |= WWDT_WDMOD_WDEN;
- }
- else
- {
- LPC_WDT->MOD &= ~WWDT_WDMOD_WDEN;
- }
-}
-
-/*********************************************************************//**
- * @brief Enable/Disable WWDT activity. In case of Enable, it will
- * do feeding WatchDog for its normal operation.
- *
- * @param[in] NewState To enable/disable the WatchDog
- *
- * @return None
- **********************************************************************/
-void WWDT_Cmd(FunctionalState NewState)
-{
- if(NewState == ENABLE)
- {
- LPC_WDT->MOD |= WWDT_WDMOD_WDEN;
-
- //Load the Feed register to start using WDT
- WWDT_Feed();
- }
- else
- {
- LPC_WDT->MOD &= ~WWDT_WDMOD_WDEN;
- }
-}
-
-/********************************************************************//**
- * @brief Set the warning value to register to generate interrupt
- * (if enable) if the watchdog timer matches this value.
- *
- * @param[in] warnVal The value (counter) will write directly to Warning
- * Register w/o pre-calc
- *
- * @return WWDT_FUNC_OK if success
- *********************************************************************/
-int8_t WWDT_SetWarningRaw(uint32_t warnVal)
-{
- int8_t retval = WWDT_FUNC_OK;
-
- if(warnVal < WWDT_WARNINT_MIN)
- {
- warnVal = WWDT_WARNINT_MIN;
- retval = WWDT_FUNC_BAD_PARAM;
- }
- else if (warnVal > WWDT_WARNINT_MAX)
- {
- warnVal = WWDT_WARNINT_MAX;
- retval = WWDT_FUNC_BAD_PARAM;
- }
-
- LPC_WDT->WARNINT = warnVal;
-
- return retval;
-}
-
-/********************************************************************//**
- * @brief Update WDT warning time (cal by usec) to warning register
- *
- * @param[in] WarnTime The time (usec) to generate watchdog warning
- * interrupt should be in range: 2048 .. 8192
- *
- * @return WWDT_FUNC_OK if success
- *********************************************************************/
-int8_t WWDT_SetWarning(uint32_t WarnTime)
-{
- return WWDT_SetWarningRaw(WDT_GET_FROM_USEC(WarnTime));
-}
-
-
-/********************************************************************//**
- * @brief Update WDT Windows value (by counter) to Window Register
- * of WatchDog
- *
- * @param[in] wndVal The value (counter) will write directly to Window
- * Register w/o pre-calc
- *
- * @return WWDT_FUNC_OK if success
- *********************************************************************/
-int8_t WWDT_SetWindowRaw(uint32_t wndVal)
-{
- int8_t retval = WWDT_FUNC_OK;
-
- if(wndVal < WWDT_WINDOW_MIN)
- {
- wndVal = WWDT_WINDOW_MIN;
- retval = WWDT_FUNC_BAD_PARAM;
- }
- else if (wndVal > WWDT_WINDOW_MAX)
- {
- wndVal = WWDT_WINDOW_MAX;
- retval = WWDT_FUNC_BAD_PARAM;
- }
-
- LPC_WDT->WINDOW = wndVal;
-
- return retval;
-}
-
-
-/********************************************************************//**
- * @brief Update WDT Windows value (by usec) to Window Register
- * of WatchDog
- *
- * @param[in] WindowedTime Expected time (usec) to set watchdog window event
- *
- * @return WWDT_FUNC_OK if success
- *********************************************************************/
-int8_t WWDT_SetWindow(uint32_t WindowedTime)
-{
- return WWDT_SetWindowRaw(WDT_GET_FROM_USEC(WindowedTime));
-}
-
-
-/********************************************************************//**
- * @brief Update WDT timeout value for WatchDog event(s)
- *
- * @param[in] TimeOut Time Out value (usec) to be updated, should be
- * in range: 2048 .. 134217728
- *
- * @return None
- *********************************************************************/
-void WDT_UpdateTimeOut(uint32_t TimeOut)
-{
- /* check WDPROTECT,
- * if it is enable, wait until the counter is below the value of
- * WDWARNINT and WDWINDOW
- */
- if(LPC_WDT->MOD & (1<<4))
- {
- while((LPC_WDT->TV <(LPC_WDT->WARNINT & WWDT_WDWARNINT_MASK))\
- &&(LPC_WDT->TV <(LPC_WDT->WINDOW & WWDT_WDTC_MASK)));
- }
-
- WWDT_SetTimeOut(TimeOut);
-}
-
-
-/********************************************************************//**
- * @brief Read WWDT status flag
- *
- * @param[in] Status kind of status flag that you want to get, should be:
- * - WWDT_WARNINT_FLAG: watchdog interrupt flag
- * - WWDT_TIMEOUT_FLAG: watchdog time-out flag
- *
- * @return Time out flag status of WDT
- *********************************************************************/
-FlagStatus WWDT_GetStatus (uint8_t Status)
-{
- if(Status == WWDT_WARNINT_FLAG)
- {
- return ((FlagStatus)(LPC_WDT->MOD & (1<<3)));
- }
- else if (Status == WWDT_TIMEOUT_FLAG)
- {
- return ((FlagStatus)(LPC_WDT->MOD & (1<<2)));
- }
- return RESET;
-}
-
-/********************************************************************//**
- * @brief Clear WWDT status flag
- *
- * @param[in] Status kind of status flag that you want to get, should be:
- * - WWDT_WARNINT_FLAG: watchdog interrupt flag
- * - WWDT_TIMEOUT_FLAG: watchdog time-out flag
- *
- * @return None
- *********************************************************************/
-void WWDT_ClearStatusFlag (uint8_t flag)
-{
- if(flag == WWDT_WARNINT_FLAG)
- {
- // Write 1 to this bit to clear itself
- LPC_WDT->MOD |= WWDT_WDMOD_WDINT;
- }
- else if(flag == WWDT_TIMEOUT_FLAG)
- {
- // Write 0 to this bit to clear itself
- LPC_WDT->MOD &= ~ WWDT_WDMOD_WDTOF;
- }
-}
-
-/********************************************************************//**
- * @brief Clear WDT Time out flag
- * @param None
- * @return None
- *********************************************************************/
-void WWDT_ClrTimeOutFlag (void)
-{
- LPC_WDT->MOD &= ~ WWDT_WDMOD_WDTOF;
-}
-
-
-/********************************************************************//**
- * @brief Following the standard sequence to Feed the WatchDog Timer
- *
- * @param None
- *
- * @return None
- *********************************************************************/
-void WWDT_FeedStdSeq (void)
-{
- LPC_WDT->FEED = 0xAA;
-
- LPC_WDT->FEED = 0x55;
-}
-
-/********************************************************************//**
- * @brief After set WDTEN, call this function to start Watchdog
- * or reload the Watchdog timer
- *
- * @param None
- *
- * @return None
- *********************************************************************/
-void WWDT_Feed (void)
-{
- // Disable irq interrupt
- __disable_irq();
-
- WWDT_FeedStdSeq();
-
- // Then enable irq interrupt
- __enable_irq();
-}
-
-/********************************************************************//**
- * @brief Get the current value of WDT
- *
- * @param None
- *
- * @return Current value of WDT
- *********************************************************************/
-uint32_t WWDT_GetCurrentCount(void)
-{
- return LPC_WDT->TV;
-}
-
-/**
- * @}
- */
-
-#endif /*_WDT*/
-/**
- * @}
- */
-
-/* --------------------------------- End Of File ------------------------------ */
diff --git a/bsp/lpc408x/Libraries/Drivers/source/makefile b/bsp/lpc408x/Libraries/Drivers/source/makefile
deleted file mode 100644
index 75cb107193..0000000000
--- a/bsp/lpc408x/Libraries/Drivers/source/makefile
+++ /dev/null
@@ -1,91 +0,0 @@
-########################################################################
-# $Id:: makefile 814 2008-06-19 19:57:32Z pdurgesh $
-#
-# Project: Standard compile makefile
-#
-# Description:
-# Makefile
-#
-########################################################################
-# Software that is described herein is for illustrative purposes only
-# which provides customers with programming information regarding the
-# products. This software is supplied "AS IS" without any warranties.
-# NXP Semiconductors assumes no responsibility or liability for the
-# use of the software, conveys no license or title under any patent,
-# copyright, or mask work right to the product. NXP Semiconductors
-# reserves the right to make changes in the software without
-# notification. NXP Semiconductors also make no representation or
-# warranty that such application will be suitable for the specified
-# use without further testing or modification.
-########################################################################
-
-########################################################################
-#
-# Get the project root
-#
-########################################################################
-PROJ_ROOT = $(CURDIR)/../..
-
-########################################################################
-#
-# Pick up the configuration file in make section
-#
-########################################################################
-include ../../makesection/makeconfig
-
-########################################################################
-#
-# Pick up the default build rules
-#
-########################################################################
-
-include $(PROJ_ROOT)/makesection/makerule/LPC/make.LPC.$(TOOL)
-
-########################################################################
-#
-# Pick up the assembler and C source files in the directory
-#
-########################################################################
-include $(PROJ_ROOT)/makesection/makerule/common/make.rules.ftypes
-AFLAGS +=-I../include
-CFLAGS +=-I../include
-
-
-########################################################################
-#
-# Build the library
-#
-########################################################################
-
-$(TARGET_FWLIB_LIB) : .vias $(OBJS) $(FWLIB_LIB_DIR)
- $(ECHO) "creating" $(FWLIB) "Firmware support package library"
- $(AR) $@ $(OBJS)
-
-$(FWLIB_LIB_DIR):
- $(MKDIR) $(FWLIB_LIB_DIR)
-
-# delete all targets this Makefile can make
-lib_clean:
- -@$(RM) $(TARGET_FWLIB_LIB)
-
-# delete all targets this Makefile can make and all built libraries
-# linked in
-lib_realclean:
- -@$(RM) $(FWLIB_LIB_DIR)/*.a
- -@$(RMDIR) $(FWLIB_LIB_DIR)
-
-clean: lib_clean
-realclean: lib_realclean
-
-########################################################################
-#
-# Compile the code base
-#
-########################################################################
-
-include $(PROJ_ROOT)/makesection/makerule/common/make.rules.build
-
-.PHONY: all lib_clean lib_realclean
-
-
-