mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-09-01 11:53:53 -04:00
Add FreeRTOS-Plus directory.
This commit is contained in:
parent
7bd5f21ad5
commit
f508a5f653
6798 changed files with 134949 additions and 19 deletions
72
FreeRTOS/Demo/CORTEX_EFMG890F128_IAR/bsp/chip.h
Normal file
72
FreeRTOS/Demo/CORTEX_EFMG890F128_IAR/bsp/chip.h
Normal file
|
@ -0,0 +1,72 @@
|
|||
/**************************************************************************//**
|
||||
* @file
|
||||
* @brief Chip initialization, SW workarounds for chip errata issues
|
||||
* @author Energy Micro AS
|
||||
* @version 1.1.1
|
||||
******************************************************************************
|
||||
* @section License
|
||||
* <b>(C) Copyright 2009 Energy Micro AS, http://www.energymicro.com</b>
|
||||
******************************************************************************
|
||||
*
|
||||
* This source code is the property of Energy Micro AS. The source and compiled
|
||||
* code may only be used on Energy Micro "EFM32" microcontrollers.
|
||||
*
|
||||
* This copyright notice may not be removed from the source code nor changed.
|
||||
*
|
||||
* DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Energy Micro AS has no
|
||||
* obligation to support this Software. Energy Micro AS is providing the
|
||||
* Software "AS IS", with no express or implied warranties of any kind,
|
||||
* including, but not limited to, any implied warranties of merchantability
|
||||
* or fitness for any particular purpose or warranties against infringement
|
||||
* of any proprietary rights of a third party.
|
||||
*
|
||||
* Energy Micro AS will not be liable for any consequential, incidental, or
|
||||
* special damages, or any other relief, or for any claim by any third party,
|
||||
* arising from your use of this Software.
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef __CHIP_H
|
||||
#define __CHIP_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/**************************************************************************//**
|
||||
* @brief Chip errata workarounds
|
||||
*****************************************************************************/
|
||||
static inline void CHIP_init(void)
|
||||
{
|
||||
uint32_t rev;
|
||||
volatile uint32_t *reg;
|
||||
|
||||
rev = *(volatile uint32_t *)(0x0FE081FC);
|
||||
/* Engineering Sample calibration setup */
|
||||
if ((rev >> 24) == 0)
|
||||
{
|
||||
reg = (volatile uint32_t *) 0x400CA00C;
|
||||
*reg &= ~(0x70UL);
|
||||
/* DREG */
|
||||
reg = (volatile uint32_t *) 0x400C6020;
|
||||
*reg &= ~(0xE0000000UL);
|
||||
*reg |= ~(7 << 25);
|
||||
}
|
||||
if ((rev >> 24) <= 1)
|
||||
{
|
||||
/* DREG */
|
||||
reg = (volatile uint32_t *) 0x400C6020;
|
||||
*reg &= ~(0x00001F80UL);
|
||||
/* Update CMU reset values */
|
||||
reg = (volatile uint32_t *) 0x400C8040;
|
||||
*reg = 0;
|
||||
reg = (volatile uint32_t *) 0x400C8044;
|
||||
*reg = 0;
|
||||
reg = (volatile uint32_t *) 0x400C8058;
|
||||
*reg = 0;
|
||||
reg = (volatile uint32_t *) 0x400C8060;
|
||||
*reg = 0;
|
||||
reg = (volatile uint32_t *) 0x400C8078;
|
||||
*reg = 0;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
62
FreeRTOS/Demo/CORTEX_EFMG890F128_IAR/bsp/dvk.c
Normal file
62
FreeRTOS/Demo/CORTEX_EFMG890F128_IAR/bsp/dvk.c
Normal file
|
@ -0,0 +1,62 @@
|
|||
/**************************************************************************//**
|
||||
* @file
|
||||
* @brief DVK board support package, initialization
|
||||
* @author Energy Micro AS
|
||||
* @version 1.0.1
|
||||
******************************************************************************
|
||||
* @section License
|
||||
* <b>(C) Copyright 2009 Energy Micro AS, http://www.energymicro.com</b>
|
||||
******************************************************************************
|
||||
*
|
||||
* This source code is the property of Energy Micro AS. The source and compiled
|
||||
* code may only be used on Energy Micro "EFM32" microcontrollers.
|
||||
*
|
||||
* This copyright notice may not be removed from the source code nor changed.
|
||||
*
|
||||
* DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Energy Micro AS has no
|
||||
* obligation to support this Software. Energy Micro AS is providing the
|
||||
* Software "AS IS", with no express or implied warranties of any kind,
|
||||
* including, but not limited to, any implied warranties of merchantability
|
||||
* or fitness for any particular purpose or warranties against infringement
|
||||
* of any proprietary rights of a third party.
|
||||
*
|
||||
* Energy Micro AS will not be liable for any consequential, incidental, or
|
||||
* special damages, or any other relief, or for any claim by any third party,
|
||||
* arising from your use of this Software.
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#include "efm32.h"
|
||||
#include "dvk.h"
|
||||
|
||||
/**************************************************************************//**
|
||||
* @brief Initializes DVK, configures board control access
|
||||
*****************************************************************************/
|
||||
void DVK_init(void)
|
||||
{
|
||||
#ifdef DVK_EBI_CONTROL
|
||||
DVK_EBI_init();
|
||||
#endif
|
||||
#ifdef DVK_SPI_CONTROL
|
||||
DVK_SPI_init();
|
||||
#endif
|
||||
/* Inform AEM application that we are in Energy Mode 0 by default */
|
||||
DVK_setEnergyMode(0);
|
||||
}
|
||||
|
||||
/**************************************************************************//**
|
||||
* @brief Disables DVK, free up resources
|
||||
*****************************************************************************/
|
||||
void DVK_disable(void)
|
||||
{
|
||||
#ifdef DVK_EBI_CONTROL
|
||||
/* Handover bus control */
|
||||
DVK_disableBus();
|
||||
/* Disable EBI interface */
|
||||
DVK_EBI_disable();
|
||||
#endif
|
||||
|
||||
#ifdef DVK_SPI_CONTROL
|
||||
DVK_SPI_disable();
|
||||
#endif
|
||||
}
|
122
FreeRTOS/Demo/CORTEX_EFMG890F128_IAR/bsp/dvk.h
Normal file
122
FreeRTOS/Demo/CORTEX_EFMG890F128_IAR/bsp/dvk.h
Normal file
|
@ -0,0 +1,122 @@
|
|||
/**************************************************************************//**
|
||||
* @file
|
||||
* @brief DVK Board Support, master header file
|
||||
* @author Energy Micro AS
|
||||
* @version 1.0.1
|
||||
******************************************************************************
|
||||
* @section License
|
||||
* <b>(C) Copyright 2009 Energy Micro AS, http://www.energymicro.com</b>
|
||||
******************************************************************************
|
||||
*
|
||||
* This source code is the property of Energy Micro AS. The source and compiled
|
||||
* code may only be used on Energy Micro "EFM32" microcontrollers.
|
||||
*
|
||||
* This copyright notice may not be removed from the source code nor changed.
|
||||
*
|
||||
* DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Energy Micro AS has no
|
||||
* obligation to support this Software. Energy Micro AS is providing the
|
||||
* Software "AS IS", with no express or implied warranties of any kind,
|
||||
* including, but not limited to, any implied warranties of merchantability
|
||||
* or fitness for any particular purpose or warranties against infringement
|
||||
* of any proprietary rights of a third party.
|
||||
*
|
||||
* Energy Micro AS will not be liable for any consequential, incidental, or
|
||||
* special damages, or any other relief, or for any claim by any third party,
|
||||
* arising from your use of this Software.
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef __DVK_H
|
||||
#define __DVK_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "dvk_boardcontrol.h"
|
||||
#include "dvk_bcregisters.h"
|
||||
|
||||
/* IF not user overrides default, try to decide DVK access interface based on
|
||||
* part number */
|
||||
#ifndef DVK_SPI_CONTROL
|
||||
#ifndef DVK_EBI_CONTROL
|
||||
|
||||
#if defined(EFM32G200F16)
|
||||
#define DVK_SPI_CONTROL
|
||||
#elif defined(EFM32G200F32)
|
||||
#define DVK_SPI_CONTROL
|
||||
#elif defined(EFM32G200F64)
|
||||
#define DVK_SPI_CONTROL
|
||||
#elif defined(EFM32G210F128)
|
||||
#define DVK_SPI_CONTROL
|
||||
#elif defined(EFM32G230F128)
|
||||
#define DVK_SPI_CONTROL
|
||||
#elif defined(EFM32G230F32)
|
||||
#define DVK_SPI_CONTROL
|
||||
#elif defined(EFM32G230F64)
|
||||
#define DVK_SPI_CONTROL
|
||||
#elif defined(EFM32G280F128)
|
||||
#define DVK_EBI_CONTROL
|
||||
#elif defined(EFM32G280F32)
|
||||
#define DVK_EBI_CONTROL
|
||||
#elif defined(EFM32G280F64)
|
||||
#define DVK_EBI_CONTROL
|
||||
#elif defined(EFM32G290F128)
|
||||
#define DVK_EBI_CONTROL
|
||||
#elif defined(EFM32G290F32)
|
||||
#define DVK_EBI_CONTROL
|
||||
#elif defined(EFM32G290F64)
|
||||
#define DVK_EBI_CONTROL
|
||||
#elif defined(EFM32G840F128)
|
||||
#define DVK_SPI_CONTROL
|
||||
#elif defined(EFM32G840F32)
|
||||
#define DVK_SPI_CONTROL
|
||||
#elif defined(EFM32G840F64)
|
||||
#define DVK_SPI_CONTROL
|
||||
#elif defined(EFM32G880F128)
|
||||
#define DVK_SPI_CONTROL
|
||||
#elif defined(EFM32G880F32)
|
||||
#define DVK_SPI_CONTROL
|
||||
#elif defined(EFM32G880F64)
|
||||
#define DVK_SPI_CONTROL
|
||||
#elif defined(EFM32G890F128)
|
||||
#define DVK_SPI_CONTROL
|
||||
#elif defined(EFM32G890F32)
|
||||
#define DVK_SPI_CONTROL
|
||||
#elif defined(EFM32G890F64)
|
||||
#define DVK_SPI_CONTROL
|
||||
#else
|
||||
#define DVK_SPI_CONTROL
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* EBI access */
|
||||
void DVK_EBI_init(void);
|
||||
void DVK_EBI_disable(void);
|
||||
|
||||
void DVK_EBI_writeRegister(volatile uint16_t *addr, uint16_t data);
|
||||
uint16_t DVK_EBI_readRegister(volatile uint16_t *addr);
|
||||
|
||||
/* SPI access */
|
||||
void DVK_SPI_init(void);
|
||||
void DVK_SPI_disable(void);
|
||||
|
||||
void DVK_SPI_writeRegister(volatile uint16_t *addr, uint16_t data);
|
||||
uint16_t DVK_SPI_readRegister(volatile uint16_t *addr);
|
||||
|
||||
|
||||
/* Accodring to configuration, use either SPI or EBI */
|
||||
#ifdef DVK_EBI_CONTROL
|
||||
#define DVK_writeRegister(A, B) DVK_EBI_writeRegister(A, B)
|
||||
#define DVK_readRegister(A) DVK_EBI_readRegister(A)
|
||||
#endif
|
||||
|
||||
#ifdef DVK_SPI_CONTROL
|
||||
#define DVK_writeRegister(A, B) DVK_SPI_writeRegister(A, B)
|
||||
#define DVK_readRegister(A) DVK_SPI_readRegister(A)
|
||||
#endif
|
||||
|
||||
/* General initialization routines */
|
||||
void DVK_init(void);
|
||||
void DVK_disable(void);
|
||||
|
||||
#endif
|
103
FreeRTOS/Demo/CORTEX_EFMG890F128_IAR/bsp/dvk_bcregisters.h
Normal file
103
FreeRTOS/Demo/CORTEX_EFMG890F128_IAR/bsp/dvk_bcregisters.h
Normal file
|
@ -0,0 +1,103 @@
|
|||
/**************************************************************************//**
|
||||
* @file
|
||||
* @brief Board Control register definitions
|
||||
* @author Energy Micro AS
|
||||
* @version 1.0.1
|
||||
******************************************************************************
|
||||
* @section License
|
||||
* <b>(C) Copyright 2009 Energy Micro AS, http://www.energymicro.com</b>
|
||||
******************************************************************************
|
||||
*
|
||||
* This source code is the property of Energy Micro AS. The source and compiled
|
||||
* code may only be used on Energy Micro "EFM32" microcontrollers.
|
||||
*
|
||||
* This copyright notice may not be removed from the source code nor changed.
|
||||
*
|
||||
* DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Energy Micro AS has no
|
||||
* obligation to support this Software. Energy Micro AS is providing the
|
||||
* Software "AS IS", with no express or implied warranties of any kind,
|
||||
* including, but not limited to, any implied warranties of merchantability
|
||||
* or fitness for any particular purpose or warranties against infringement
|
||||
* of any proprietary rights of a third party.
|
||||
*
|
||||
* Energy Micro AS will not be liable for any consequential, incidental, or
|
||||
* special damages, or any other relief, or for any claim by any third party,
|
||||
* arising from your use of this Software.
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef __DVK_BCREGISTERS_H
|
||||
#define __DVK_BCREGISTERS_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/**************************************************************************//**
|
||||
* Defines FPGA register bank for Energy Micro Development Kit (DVK) board,
|
||||
* i.e. board control registers
|
||||
*****************************************************************************/
|
||||
#define BC_REGISTER_BASE 0x8c000000
|
||||
|
||||
#define BC_CFG ((volatile uint16_t *)(BC_REGISTER_BASE + sizeof(uint16_t) * 0x00))
|
||||
#define BC_EM ((volatile uint16_t *)(BC_REGISTER_BASE + sizeof(uint16_t) * 0x01))
|
||||
#define BC_MAGIC ((volatile uint16_t *)(BC_REGISTER_BASE + sizeof(uint16_t) * 0x02))
|
||||
#define BC_LED ((volatile uint16_t *)(BC_REGISTER_BASE + sizeof(uint16_t) * 0x03))
|
||||
#define BC_PUSHBUTTON ((volatile uint16_t *)(BC_REGISTER_BASE + sizeof(uint16_t) * 0x04))
|
||||
#define BC_DIPSWITCH ((volatile uint16_t *)(BC_REGISTER_BASE + sizeof(uint16_t) * 0x05))
|
||||
#define BC_JOYSTICK ((volatile uint16_t *)(BC_REGISTER_BASE + sizeof(uint16_t) * 0x06))
|
||||
#define BC_AEM ((volatile uint16_t *)(BC_REGISTER_BASE + sizeof(uint16_t) * 0x07))
|
||||
#define BC_DISPLAY_CTRL ((volatile uint16_t *)(BC_REGISTER_BASE + sizeof(uint16_t) * 0x08))
|
||||
#define BC_EBI_CFG ((volatile uint16_t *)(BC_REGISTER_BASE + sizeof(uint16_t) * 0x09))
|
||||
#define BC_BUS_CFG ((volatile uint16_t *)(BC_REGISTER_BASE + sizeof(uint16_t) * 0x0a))
|
||||
#define BC_PERCTRL ((volatile uint16_t *)(BC_REGISTER_BASE + sizeof(uint16_t) * 0x0c))
|
||||
#define BC_AEMSTATE ((volatile uint16_t *)(BC_REGISTER_BASE + sizeof(uint16_t) * 0x0d))
|
||||
#define BC_SPI_CFG ((volatile uint16_t *)(BC_REGISTER_BASE + sizeof(uint16_t) * 0x0e))
|
||||
#define BC_RESET ((volatile uint16_t *)(BC_REGISTER_BASE + sizeof(uint16_t) * 0x0f))
|
||||
#define BC_ADC_START ((volatile uint16_t *)(BC_REGISTER_BASE + sizeof(uint16_t) * 0x10))
|
||||
#define BC_ADC_STATUS ((volatile uint16_t *)(BC_REGISTER_BASE + sizeof(uint16_t) * 0x11))
|
||||
#define BC_ADC_DATA ((volatile uint16_t *)(BC_REGISTER_BASE + sizeof(uint16_t) * 0x12))
|
||||
#define BC_HW_VERSION ((volatile uint16_t *)(BC_REGISTER_BASE + sizeof(uint16_t) * 0x14))
|
||||
#define BC_FW_BUILDNO ((volatile uint16_t *)(BC_REGISTER_BASE + sizeof(uint16_t) * 0x15))
|
||||
#define BC_FW_VERSION ((volatile uint16_t *)(BC_REGISTER_BASE + sizeof(uint16_t) * 0x16))
|
||||
#define BC_SCRATCH_COMMON ((volatile uint16_t *)(BC_REGISTER_BASE + sizeof(uint16_t) * 0x17))
|
||||
#define BC_SCRATCH_EFM0 ((volatile uint16_t *)(BC_REGISTER_BASE + sizeof(uint16_t) * 0x18))
|
||||
#define BC_SCRATCH_EFM1 ((volatile uint16_t *)(BC_REGISTER_BASE + sizeof(uint16_t) * 0x19))
|
||||
#define BC_SCRATCH_EFM2 ((volatile uint16_t *)(BC_REGISTER_BASE + sizeof(uint16_t) * 0x1A))
|
||||
#define BC_SCRATCH_EFM3 ((volatile uint16_t *)(BC_REGISTER_BASE + sizeof(uint16_t) * 0x1B))
|
||||
#define BC_SCRATCH_BC0 ((volatile uint16_t *)(BC_REGISTER_BASE + sizeof(uint16_t) * 0x1C))
|
||||
#define BC_SCRATCH_BC1 ((volatile uint16_t *)(BC_REGISTER_BASE + sizeof(uint16_t) * 0x1D))
|
||||
#define BC_SCRATCH_BC2 ((volatile uint16_t *)(BC_REGISTER_BASE + sizeof(uint16_t) * 0x1E))
|
||||
#define BC_SCRATCH_BC3 ((volatile uint16_t *)(BC_REGISTER_BASE + sizeof(uint16_t) * 0x1f))
|
||||
#define BC_INTFLAG ((volatile uint16_t *)(BC_REGISTER_BASE + sizeof(uint16_t) * 0x20))
|
||||
#define BC_INTEN ((volatile uint16_t *)(BC_REGISTER_BASE + sizeof(uint16_t) * 0x21))
|
||||
|
||||
/**************************************************************************//**
|
||||
* Defines bit fields for board control registers
|
||||
*****************************************************************************/
|
||||
#define BC_PERCTRL_ACCEL (1 << 0)
|
||||
#define BC_PERCTRL_AMBIENT (1 << 1)
|
||||
#define BC_PERCTRL_POTMETER (1 << 2)
|
||||
#define BC_PERCTRL_RS232A (1 << 3)
|
||||
#define BC_PERCTRL_RS232B (1 << 4)
|
||||
#define BC_PERCTRL_SPI (1 << 5)
|
||||
#define BC_PERCTRL_I2C (1 << 6)
|
||||
#define BC_PERCTRL_IRDA (1 << 7)
|
||||
#define BC_PERCTRL_ANALOG_SE (1 << 8)
|
||||
#define BC_PERCTRL_ANALOG_DIFF (1 << 9)
|
||||
#define BC_PERCTRL_AUDIO_OUT (1 << 10)
|
||||
#define BC_PERCTRL_AUDIO_IN (1 << 11)
|
||||
#define BC_PERCTRL_ACCEL_GSEL (1 << 12)
|
||||
#define BC_PERCTRL_ACCEL_SELFTEST (1 << 13)
|
||||
#define BC_PERCTRL_RS232_SHUTDOWN (1 << 14)
|
||||
#define BC_PERCTRL_IRDA_SHUTDOWN (1 << 15)
|
||||
|
||||
#define BC_INTEN_PB (1 << 0)
|
||||
#define BC_INTEN_DIP (1 << 1)
|
||||
#define BC_INTEN_JOYSTICK (1 << 2)
|
||||
#define BC_INTEN_AEM (1 << 3)
|
||||
|
||||
#define BC_CFG_SPI (0)
|
||||
#define BC_CFG_EBI (1)
|
||||
|
||||
#define BC_MAGIC_VALUE (0xef32)
|
||||
|
||||
#endif
|
235
FreeRTOS/Demo/CORTEX_EFMG890F128_IAR/bsp/dvk_boardcontrol.c
Normal file
235
FreeRTOS/Demo/CORTEX_EFMG890F128_IAR/bsp/dvk_boardcontrol.c
Normal file
|
@ -0,0 +1,235 @@
|
|||
/**************************************************************************//**
|
||||
* @file
|
||||
* @brief DVK Peripheral Board Control API implementation
|
||||
* @author Energy Micro AS
|
||||
* @version 1.0.1
|
||||
******************************************************************************
|
||||
* @section License
|
||||
* <b>(C) Copyright 2009 Energy Micro AS, http://www.energymicro.com</b>
|
||||
******************************************************************************
|
||||
*
|
||||
* This source code is the property of Energy Micro AS. The source and compiled
|
||||
* code may only be used on Energy Micro "EFM32" microcontrollers.
|
||||
*
|
||||
* This copyright notice may not be removed from the source code nor changed.
|
||||
*
|
||||
* DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Energy Micro AS has no
|
||||
* obligation to support this Software. Energy Micro AS is providing the
|
||||
* Software "AS IS", with no express or implied warranties of any kind,
|
||||
* including, but not limited to, any implied warranties of merchantability
|
||||
* or fitness for any particular purpose or warranties against infringement
|
||||
* of any proprietary rights of a third party.
|
||||
*
|
||||
* Energy Micro AS will not be liable for any consequential, incidental, or
|
||||
* special damages, or any other relief, or for any claim by any third party,
|
||||
* arising from your use of this Software.
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#include "efm32.h"
|
||||
#include "dvk.h"
|
||||
#include "dvk_boardcontrol.h"
|
||||
#include "dvk_bcregisters.h"
|
||||
|
||||
/**************************************************************************//**
|
||||
* @brief Enable EFM32 access to periheral on DVK board
|
||||
* @param peri Peripheral to enable
|
||||
*****************************************************************************/
|
||||
void DVK_enablePeripheral(DVKPeripheral peri)
|
||||
{
|
||||
uint16_t bit;
|
||||
uint16_t tmp;
|
||||
|
||||
/* Calculate which bit to set */
|
||||
bit = (uint16_t) peri;
|
||||
|
||||
/* Read peripheral control register */
|
||||
tmp = DVK_readRegister(BC_PERCTRL);
|
||||
|
||||
/* Enable peripheral */
|
||||
tmp |= bit;
|
||||
|
||||
/* Special case for RS232, if enabled disable shutdown */
|
||||
if ((peri == DVK_RS232A) || (peri == DVK_RS232B))
|
||||
{
|
||||
/* clear shutdown bit */
|
||||
tmp &= ~(BC_PERCTRL_RS232_SHUTDOWN);
|
||||
}
|
||||
|
||||
/* Special case for IRDA if enabled disable shutdown */
|
||||
if (peri == DVK_IRDA)
|
||||
{
|
||||
/* clear shutdown bit */
|
||||
tmp &= ~(BC_PERCTRL_IRDA_SHUTDOWN);
|
||||
}
|
||||
|
||||
DVK_writeRegister(BC_PERCTRL, tmp);
|
||||
}
|
||||
|
||||
/**************************************************************************//**
|
||||
* @brief Disable EFM32 access to peripheral on DVK board
|
||||
* @param peri Peripheral to disable
|
||||
*****************************************************************************/
|
||||
void DVK_disablePeripheral(DVKPeripheral peri)
|
||||
{
|
||||
uint16_t bit;
|
||||
uint16_t tmp;
|
||||
|
||||
/* Calculate which bit to set */
|
||||
bit = (uint16_t) peri;
|
||||
|
||||
/* Read peripheral control register */
|
||||
tmp = DVK_readRegister(BC_PERCTRL);
|
||||
|
||||
/* Disable peripheral */
|
||||
tmp &= ~(bit);
|
||||
|
||||
/* Special case for RS232, if enabled disable shutdown */
|
||||
if ((peri == DVK_RS232A) || (peri == DVK_RS232B))
|
||||
{
|
||||
/* Set shutdown bit */
|
||||
tmp |= (BC_PERCTRL_RS232_SHUTDOWN);
|
||||
}
|
||||
|
||||
/* Special case for IRDA */
|
||||
if (peri == DVK_IRDA)
|
||||
{
|
||||
/* Set shutdown bit */
|
||||
tmp |= (BC_PERCTRL_IRDA_SHUTDOWN);
|
||||
}
|
||||
|
||||
|
||||
DVK_writeRegister(BC_PERCTRL, tmp);
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************//**
|
||||
* @brief Enable BUS access
|
||||
*****************************************************************************/
|
||||
void DVK_enableBus(void)
|
||||
{
|
||||
/* Enable bus access */
|
||||
DVK_writeRegister(BC_BUS_CFG, 1);
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************//**
|
||||
* @brief Disable BUS access
|
||||
*****************************************************************************/
|
||||
void DVK_disableBus(void)
|
||||
{
|
||||
DVK_writeRegister(BC_BUS_CFG, 0);
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************//**
|
||||
* @brief Inform AEM about current energy mode
|
||||
* @param energyMode What energy mode we are going to use next
|
||||
*****************************************************************************/
|
||||
void DVK_setEnergyMode(uint16_t energyMode)
|
||||
{
|
||||
DVK_writeRegister(BC_EM, energyMode);
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************//**
|
||||
* @brief Get status of bush buttons
|
||||
* @return Status of push buttons
|
||||
*****************************************************************************/
|
||||
uint16_t DVK_getPushButtons(void)
|
||||
{
|
||||
uint16_t tmp;
|
||||
|
||||
tmp = (~(DVK_readRegister(BC_PUSHBUTTON))) & 0x000f;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
/**************************************************************************//**
|
||||
* @brief Get joystick button status
|
||||
* @return Joystick controller status
|
||||
*****************************************************************************/
|
||||
uint16_t DVK_getJoystick(void)
|
||||
{
|
||||
uint16_t tmp;
|
||||
|
||||
tmp = (~(DVK_readRegister(BC_JOYSTICK))) & 0x001f;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
/**************************************************************************//**
|
||||
* @brief Get dipswitch status
|
||||
* The DIP switches are free for user programmable purposes
|
||||
* @return Joystick controller status
|
||||
*****************************************************************************/
|
||||
uint16_t DVK_getDipSwitch(void)
|
||||
{
|
||||
uint16_t tmp;
|
||||
|
||||
tmp = (~(DVK_readRegister(BC_DIPSWITCH))) & 0x00ff;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
/**************************************************************************//**
|
||||
* @brief Sets user leds
|
||||
* @param leds 16-bits which enables or disables the board "User leds"
|
||||
*****************************************************************************/
|
||||
void DVK_setLEDs(uint16_t leds)
|
||||
{
|
||||
DVK_writeRegister(BC_LED, leds);
|
||||
}
|
||||
|
||||
/**************************************************************************//**
|
||||
* @brief Get status of user LEDs
|
||||
* @return Status of 16 user leds, bit 1 = on, bit 0 = off
|
||||
*****************************************************************************/
|
||||
uint16_t DVK_getLEDs(void)
|
||||
{
|
||||
return DVK_readRegister(BC_LED);
|
||||
}
|
||||
|
||||
/**************************************************************************//**
|
||||
* @brief Enable "Control" buttons/joystick/dip switch interrupts
|
||||
* @param flags Board control interrupt flags, BC_INTEN_<something>
|
||||
*****************************************************************************/
|
||||
void DVK_enableInterrupt(uint16_t flags)
|
||||
{
|
||||
uint16_t tmp;
|
||||
|
||||
/* Add flags to interrupt enable register */
|
||||
tmp = DVK_readRegister(BC_INTEN);
|
||||
tmp |= flags;
|
||||
DVK_writeRegister(BC_INTEN, tmp);
|
||||
}
|
||||
|
||||
/**************************************************************************//**
|
||||
* @brief Disable "Control" buttons/joystick/dip switch interrupts
|
||||
* @param flags Board control interrupt flags, BC_INTEN_<something>
|
||||
*****************************************************************************/
|
||||
void DVK_disableInterrupt(uint16_t flags)
|
||||
{
|
||||
uint16_t tmp;
|
||||
|
||||
/* Clear flags from interrupt enable register */
|
||||
tmp = DVK_readRegister(BC_INTEN);
|
||||
flags = ~(flags);
|
||||
tmp &= flags;
|
||||
DVK_writeRegister(BC_INTEN, tmp);
|
||||
}
|
||||
|
||||
/**************************************************************************//**
|
||||
* @brief Clear interrupts
|
||||
* @param flags Board control interrupt flags, BC_INTEN_<something>
|
||||
*****************************************************************************/
|
||||
void DVK_clearInterruptFlags(uint16_t flags)
|
||||
{
|
||||
DVK_writeRegister(BC_INTFLAG, flags);
|
||||
}
|
||||
|
||||
/**************************************************************************//**
|
||||
* @brief Read interrupt flags
|
||||
* @return Returns currently triggered interrupts
|
||||
*****************************************************************************/
|
||||
uint16_t DVK_getInterruptFlags(void)
|
||||
{
|
||||
return DVK_readRegister(BC_INTFLAG);
|
||||
}
|
81
FreeRTOS/Demo/CORTEX_EFMG890F128_IAR/bsp/dvk_boardcontrol.h
Normal file
81
FreeRTOS/Demo/CORTEX_EFMG890F128_IAR/bsp/dvk_boardcontrol.h
Normal file
|
@ -0,0 +1,81 @@
|
|||
/**************************************************************************//**
|
||||
* @file
|
||||
* @brief DVK Peripheral Board Control, prototypes and definitions
|
||||
* @author Energy Micro AS
|
||||
* @version 1.0.1
|
||||
******************************************************************************
|
||||
* @section License
|
||||
* <b>(C) Copyright 2009 Energy Micro AS, http://www.energymicro.com</b>
|
||||
******************************************************************************
|
||||
*
|
||||
* This source code is the property of Energy Micro AS. The source and compiled
|
||||
* code may only be used on Energy Micro "EFM32" microcontrollers.
|
||||
*
|
||||
* This copyright notice may not be removed from the source code nor changed.
|
||||
*
|
||||
* DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Energy Micro AS has no
|
||||
* obligation to support this Software. Energy Micro AS is providing the
|
||||
* Software "AS IS", with no express or implied warranties of any kind,
|
||||
* including, but not limited to, any implied warranties of merchantability
|
||||
* or fitness for any particular purpose or warranties against infringement
|
||||
* of any proprietary rights of a third party.
|
||||
*
|
||||
* Energy Micro AS will not be liable for any consequential, incidental, or
|
||||
* special damages, or any other relief, or for any claim by any third party,
|
||||
* arising from your use of this Software.
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef __DVK_BOARDCONTROL_H
|
||||
#define __DVK_BOARDCONTROL_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "dvk_bcregisters.h"
|
||||
|
||||
/** Periperhal access switches */
|
||||
typedef enum
|
||||
{
|
||||
DVK_ACCEL = BC_PERCTRL_ACCEL,
|
||||
DVK_AMBIENT = BC_PERCTRL_AMBIENT,
|
||||
DVK_POTMETER = BC_PERCTRL_POTMETER,
|
||||
DVK_RS232A = BC_PERCTRL_RS232A,
|
||||
DVK_RS232B = BC_PERCTRL_RS232B,
|
||||
DVK_SPI = BC_PERCTRL_SPI,
|
||||
DVK_I2C = BC_PERCTRL_I2C,
|
||||
DVK_IRDA = BC_PERCTRL_IRDA,
|
||||
DVK_ANALOG_SE = BC_PERCTRL_ANALOG_SE,
|
||||
DVK_ANALOG_DIFF = BC_PERCTRL_ANALOG_DIFF,
|
||||
DVK_AUDIO_OUT = BC_PERCTRL_AUDIO_OUT,
|
||||
DVK_AUDIO_IN = BC_PERCTRL_AUDIO_IN,
|
||||
DVK_ACCEL_GSEL = BC_PERCTRL_ACCEL_GSEL,
|
||||
DVK_ACCEL_SELFTEST = BC_PERCTRL_ACCEL_SELFTEST,
|
||||
DVK_RS232_SHUTDOWN = BC_PERCTRL_RS232_SHUTDOWN,
|
||||
DVK_IRDA_SHUTDOWN = BC_PERCTRL_IRDA_SHUTDOWN,
|
||||
} DVKPeripheral;
|
||||
|
||||
/* Peripheral Control */
|
||||
void DVK_enablePeripheral(DVKPeripheral peri);
|
||||
void DVK_disablePeripheral(DVKPeripheral peri);
|
||||
void DVK_enableBus(void);
|
||||
void DVK_disableBus(void);
|
||||
|
||||
/* Read board controllers */
|
||||
uint16_t DVK_getPushButtons(void);
|
||||
uint16_t DVK_getJoystick(void);
|
||||
uint16_t DVK_getDipSwitch(void);
|
||||
|
||||
/* Report AEM status */
|
||||
void DVK_setEnergyMode(uint16_t energyMode);
|
||||
|
||||
/* User LEDs */
|
||||
void DVK_setLEDs(uint16_t leds);
|
||||
uint16_t DVK_getLEDs(void);
|
||||
|
||||
/* Interrupt callback */
|
||||
void DVK_enableInterrupt(uint16_t flags);
|
||||
void DVK_disableInterrupt(uint16_t flags);
|
||||
|
||||
uint16_t DVK_getInterruptFlags(void);
|
||||
void DVK_clearInterruptFlags(uint16_t flags);
|
||||
|
||||
#endif
|
248
FreeRTOS/Demo/CORTEX_EFMG890F128_IAR/bsp/dvk_ebi.c
Normal file
248
FreeRTOS/Demo/CORTEX_EFMG890F128_IAR/bsp/dvk_ebi.c
Normal file
|
@ -0,0 +1,248 @@
|
|||
/**************************************************************************//**
|
||||
* @file
|
||||
* @brief EBI implementation of Board Control interface
|
||||
* This implementation works for devices w/o LCD display on the
|
||||
* MCU module, specifically the EFM32_G2xx_DK development board
|
||||
* @author Energy Micro AS
|
||||
* @version 1.0.1
|
||||
******************************************************************************
|
||||
* @section License
|
||||
* <b>(C) Copyright 2009 Energy Micro AS, http://www.energymicro.com</b>
|
||||
******************************************************************************
|
||||
*
|
||||
* This source code is the property of Energy Micro AS. The source and compiled
|
||||
* code may only be used on Energy Micro "EFM32" microcontrollers.
|
||||
*
|
||||
* This copyright notice may not be removed from the source code nor changed.
|
||||
*
|
||||
* DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Energy Micro AS has no
|
||||
* obligation to support this Software. Energy Micro AS is providing the
|
||||
* Software "AS IS", with no express or implied warranties of any kind,
|
||||
* including, but not limited to, any implied warranties of merchantability
|
||||
* or fitness for any particular purpose or warranties against infringement
|
||||
* of any proprietary rights of a third party.
|
||||
*
|
||||
* Energy Micro AS will not be liable for any consequential, incidental, or
|
||||
* special damages, or any other relief, or for any claim by any third party,
|
||||
* arising from your use of this Software.
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#include "efm32.h"
|
||||
#include "dvk.h"
|
||||
#include "dvk_bcregisters.h"
|
||||
|
||||
/**************************************************************************//**
|
||||
* @brief Configure EBI (external bus interface) for Board Control register
|
||||
* access
|
||||
*****************************************************************************/
|
||||
void DVK_EBI_configure(void)
|
||||
{
|
||||
GPIO_TypeDef *gpio = GPIO;
|
||||
EBI_TypeDef *ebi = EBI;
|
||||
CMU_TypeDef *cmu = CMU;
|
||||
|
||||
/* Run time check if we have EBI on-chip capability on this device */
|
||||
switch ((DEVINFO->PART & _DEVINFO_PART_DEVICE_NUMBER_MASK) >>
|
||||
_DEVINFO_PART_DEVICE_NUMBER_SHIFT)
|
||||
{
|
||||
/* Only device types EFM32G 280/290/880 and 890 have EBI capability */
|
||||
case 280:
|
||||
case 290:
|
||||
case 880:
|
||||
case 890:
|
||||
break;
|
||||
default:
|
||||
/* This device do not have EBI capability - use SPI to interface DVK */
|
||||
/* With high probability your project has been configured for an */
|
||||
/* incorrect part number. */
|
||||
while (1) ;
|
||||
}
|
||||
|
||||
/* Enable clocks */
|
||||
cmu->HFCORECLKEN0 |= CMU_HFCORECLKEN0_EBI;
|
||||
cmu->HFPERCLKEN0 |= CMU_HFPERCLKEN0_GPIO;
|
||||
|
||||
/* Configure bus connect PC bit 12 active low */
|
||||
gpio->P[2].MODEH |=
|
||||
GPIO_P_MODEH_MODE12_PUSHPULL;
|
||||
|
||||
gpio->P[2].DOUT &= ~(1UL << 12);
|
||||
|
||||
/* Configure GPIO pins as push pull */
|
||||
/* EBI AD9..15 */
|
||||
gpio->P[0].MODEL |=
|
||||
(GPIO_P_MODEL_MODE0_PUSHPULL |
|
||||
GPIO_P_MODEL_MODE1_PUSHPULL |
|
||||
GPIO_P_MODEL_MODE2_PUSHPULL |
|
||||
GPIO_P_MODEL_MODE3_PUSHPULL |
|
||||
GPIO_P_MODEL_MODE4_PUSHPULL |
|
||||
GPIO_P_MODEL_MODE5_PUSHPULL |
|
||||
GPIO_P_MODEL_MODE6_PUSHPULL);
|
||||
/* EBI AD8 */
|
||||
gpio->P[0].MODEH |=
|
||||
GPIO_P_MODEH_MODE15_PUSHPULL;
|
||||
/* EBI CS0-CS3 */
|
||||
gpio->P[3].MODEH |=
|
||||
(GPIO_P_MODEH_MODE9_PUSHPULL |
|
||||
GPIO_P_MODEH_MODE10_PUSHPULL |
|
||||
GPIO_P_MODEH_MODE11_PUSHPULL |
|
||||
GPIO_P_MODEH_MODE12_PUSHPULL);
|
||||
/* EBI AD0..7 */
|
||||
gpio->P[4].MODEH |=
|
||||
(GPIO_P_MODEH_MODE8_PUSHPULL |
|
||||
GPIO_P_MODEH_MODE9_PUSHPULL |
|
||||
GPIO_P_MODEH_MODE10_PUSHPULL |
|
||||
GPIO_P_MODEH_MODE11_PUSHPULL |
|
||||
GPIO_P_MODEH_MODE12_PUSHPULL |
|
||||
GPIO_P_MODEH_MODE13_PUSHPULL |
|
||||
GPIO_P_MODEH_MODE14_PUSHPULL |
|
||||
GPIO_P_MODEH_MODE15_PUSHPULL);
|
||||
/* EBI ARDY/ALEN/Wen/Ren */
|
||||
gpio->P[5].MODEL |=
|
||||
(GPIO_P_MODEL_MODE2_PUSHPULL |
|
||||
GPIO_P_MODEL_MODE3_PUSHPULL |
|
||||
GPIO_P_MODEL_MODE4_PUSHPULL |
|
||||
GPIO_P_MODEL_MODE5_PUSHPULL);
|
||||
|
||||
/* Configure EBI controller */
|
||||
/* 16 bit address, 16 bit data mode */
|
||||
/* Enable bank 0 address map 0x80000000, FPGA Flash */
|
||||
/* Enable bank 1 address map 0x84000000, FPGA SRAM */
|
||||
/* Enable bank 2 address map 0x88000000, FPGA TFT Display (SSD2119) */
|
||||
/* Enable bank 3 address map 0x8c000000, FPGA Board Control Registers */
|
||||
ebi->CTRL =
|
||||
EBI_CTRL_MODE_D16A16ALE |
|
||||
EBI_CTRL_BANK0EN |
|
||||
EBI_CTRL_BANK1EN |
|
||||
EBI_CTRL_BANK2EN |
|
||||
EBI_CTRL_BANK3EN;
|
||||
|
||||
/* Setup and hold time */
|
||||
ebi->ADDRTIMING = 3 << _EBI_ADDRTIMING_ADDRHOLD_SHIFT | 3 << _EBI_ADDRTIMING_ADDRSET_SHIFT;
|
||||
|
||||
/* Default values for all write timing registers, read timing conservative */
|
||||
ebi->RDTIMING = 7 << _EBI_RDTIMING_RDSTRB_SHIFT | 3 << _EBI_RDTIMING_RDHOLD_SHIFT | 3 << _EBI_RDTIMING_RDSETUP_SHIFT;
|
||||
ebi->WRTIMING = 7 << _EBI_WRTIMING_WRSTRB_SHIFT | 3 << _EBI_WRTIMING_WRHOLD_SHIFT | 3 << _EBI_WRTIMING_WRSETUP_SHIFT;
|
||||
ebi->POLARITY = _EBI_POLARITY_RESETVALUE;
|
||||
|
||||
/* Toggle on all chip selects for all banks */
|
||||
ebi->ROUTE =
|
||||
EBI_ROUTE_CS0PEN |
|
||||
EBI_ROUTE_CS1PEN |
|
||||
EBI_ROUTE_CS2PEN |
|
||||
EBI_ROUTE_CS3PEN |
|
||||
EBI_ROUTE_ALEPEN |
|
||||
EBI_ROUTE_EBIPEN;
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************//**
|
||||
* @brief Initialize EBI
|
||||
* access
|
||||
*****************************************************************************/
|
||||
void DVK_EBI_init(void)
|
||||
{
|
||||
uint16_t ebiMagic;
|
||||
int ctr;
|
||||
volatile int i;
|
||||
|
||||
/* Configure EBI */
|
||||
DVK_EBI_configure();
|
||||
/* Verify that EBI access is working, if not kit is in SPI mode and needs to
|
||||
* be configured for EBI access */
|
||||
ebiMagic = DVK_EBI_readRegister(BC_MAGIC);
|
||||
if (ebiMagic != BC_MAGIC_VALUE)
|
||||
{
|
||||
/* Disable EBI */
|
||||
DVK_EBI_disable();
|
||||
/* Enable SPI interface */
|
||||
DVK_SPI_init();
|
||||
/* Set EBI mode - after this SPI access will no longer be available */
|
||||
DVK_SPI_writeRegister(BC_CFG, BC_CFG_EBI);
|
||||
/* Disable SPI */
|
||||
DVK_SPI_disable();
|
||||
/* Now setup EBI again */
|
||||
DVK_EBI_configure();
|
||||
/* Wait until ready */
|
||||
ctr = 0;
|
||||
do {
|
||||
/* Check if FPGA responds */
|
||||
ebiMagic = DVK_EBI_readRegister(BC_MAGIC);
|
||||
ctr++;
|
||||
DVK_EBI_writeRegister(BC_LED, ctr);
|
||||
} while (ebiMagic != BC_MAGIC_VALUE);
|
||||
}
|
||||
}
|
||||
|
||||
/**************************************************************************//**
|
||||
* @brief Disable EBI interface, free all GPIO pins
|
||||
*****************************************************************************/
|
||||
void DVK_EBI_disable(void)
|
||||
{
|
||||
GPIO_TypeDef *gpio = GPIO;
|
||||
EBI_TypeDef *ebi = EBI;
|
||||
CMU_TypeDef *cmu = CMU;
|
||||
|
||||
/* Toggle off all chip selects for all banks */
|
||||
ebi->ROUTE = _EBI_ROUTE_RESETVALUE;
|
||||
|
||||
/* Disable EBI controller */
|
||||
ebi->CTRL = _EBI_CTRL_RESETVALUE;
|
||||
|
||||
/* Disable EBI clock */
|
||||
cmu->HFCORECLKEN0 &= ~(CMU_HFCORECLKEN0_EBI);
|
||||
|
||||
/* Disable EBI _BC_BUS_CONNECT */
|
||||
gpio->P[2].MODEH &= ~(_GPIO_P_MODEH_MODE12_MASK);
|
||||
|
||||
/* Configure GPIO pins as disabled */
|
||||
gpio->P[0].MODEL &= ~(
|
||||
_GPIO_P_MODEL_MODE0_MASK |
|
||||
_GPIO_P_MODEL_MODE1_MASK |
|
||||
_GPIO_P_MODEL_MODE2_MASK |
|
||||
_GPIO_P_MODEL_MODE3_MASK |
|
||||
_GPIO_P_MODEL_MODE4_MASK |
|
||||
_GPIO_P_MODEL_MODE5_MASK |
|
||||
_GPIO_P_MODEL_MODE6_MASK);
|
||||
gpio->P[0].MODEH &= ~(_GPIO_P_MODEH_MODE15_MASK);
|
||||
gpio->P[3].MODEH &= ~(
|
||||
_GPIO_P_MODEH_MODE9_MASK|
|
||||
_GPIO_P_MODEH_MODE10_MASK|
|
||||
_GPIO_P_MODEH_MODE11_MASK|
|
||||
_GPIO_P_MODEH_MODE12_MASK
|
||||
);
|
||||
gpio->P[4].MODEH &= ~(
|
||||
_GPIO_P_MODEH_MODE8_MASK |
|
||||
_GPIO_P_MODEH_MODE9_MASK |
|
||||
_GPIO_P_MODEH_MODE10_MASK |
|
||||
_GPIO_P_MODEH_MODE11_MASK |
|
||||
_GPIO_P_MODEH_MODE12_MASK |
|
||||
_GPIO_P_MODEH_MODE13_MASK |
|
||||
_GPIO_P_MODEH_MODE14_MASK |
|
||||
_GPIO_P_MODEH_MODE15_MASK);
|
||||
gpio->P[5].MODEL &= ~(
|
||||
_GPIO_P_MODEL_MODE2_MASK |
|
||||
_GPIO_P_MODEL_MODE3_MASK |
|
||||
_GPIO_P_MODEL_MODE4_MASK |
|
||||
_GPIO_P_MODEL_MODE5_MASK);
|
||||
}
|
||||
|
||||
/**************************************************************************//**
|
||||
* @brief Write data into 16-bit board control register
|
||||
* @param addr Address to board control register
|
||||
* @param data Data to write into register
|
||||
*****************************************************************************/
|
||||
void DVK_EBI_writeRegister(volatile uint16_t *addr, uint16_t data)
|
||||
{
|
||||
*addr = data;
|
||||
}
|
||||
|
||||
/**************************************************************************//**
|
||||
* @brief Write data into 16-bit board control register
|
||||
* @param addr Register to read from
|
||||
*****************************************************************************/
|
||||
uint16_t DVK_EBI_readRegister(volatile uint16_t *addr)
|
||||
{
|
||||
return *addr;
|
||||
}
|
229
FreeRTOS/Demo/CORTEX_EFMG890F128_IAR/bsp/dvk_spi.c
Normal file
229
FreeRTOS/Demo/CORTEX_EFMG890F128_IAR/bsp/dvk_spi.c
Normal file
|
@ -0,0 +1,229 @@
|
|||
/**************************************************************************//**
|
||||
* @file
|
||||
* @brief SPI implementation of Board Control interface
|
||||
* This implementation use the USART2 SPI interface to control board
|
||||
* control registers. It works
|
||||
* @author Energy Micro AS
|
||||
* @version 1.0.1
|
||||
******************************************************************************
|
||||
* @section License
|
||||
* <b>(C) Copyright 2009 Energy Micro AS, http://www.energymicro.com</b>
|
||||
******************************************************************************
|
||||
*
|
||||
* This source code is the property of Energy Micro AS. The source and compiled
|
||||
* code may only be used on Energy Micro "EFM32" microcontrollers.
|
||||
*
|
||||
* This copyright notice may not be removed from the source code nor changed.
|
||||
*
|
||||
* DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Energy Micro AS has no
|
||||
* obligation to support this Software. Energy Micro AS is providing the
|
||||
* Software "AS IS", with no express or implied warranties of any kind,
|
||||
* including, but not limited to, any implied warranties of merchantability
|
||||
* or fitness for any particular purpose or warranties against infringement
|
||||
* of any proprietary rights of a third party.
|
||||
*
|
||||
* Energy Micro AS will not be liable for any consequential, incidental, or
|
||||
* special damages, or any other relief, or for any claim by any third party,
|
||||
* arising from your use of this Software.
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#include "efm32.h"
|
||||
#include "dvk.h"
|
||||
#include "dvk_bcregisters.h"
|
||||
|
||||
#define clear_bit(reg, bit) (reg &= ~(1 << bit))
|
||||
|
||||
static volatile uint16_t *lastAddr = 0;
|
||||
|
||||
/**************************************************************************//**
|
||||
* @brief Initializes USART2 SPI interface for access to FPGA registers
|
||||
* for board control
|
||||
*****************************************************************************/
|
||||
static void spiInit(void)
|
||||
{
|
||||
USART_TypeDef *usart = USART2;
|
||||
GPIO_TypeDef *gpio = GPIO;
|
||||
uint32_t clk, spidiv;
|
||||
const uint32_t baudrate = 7000000;
|
||||
const uint32_t div = (2 * baudrate / 256);
|
||||
|
||||
/* Configure SPI bus connect pins */
|
||||
gpio->P[2].MODEH &= ~(_GPIO_P_MODEH_MODE13_MASK);
|
||||
gpio->P[2].MODEH |= (GPIO_P_MODEH_MODE13_PUSHPULL);
|
||||
gpio->P[2].DOUT &= ~(1UL << 13);
|
||||
|
||||
/* Configure SPI pins */
|
||||
gpio->P[2].MODEL &= ~(_GPIO_P_MODEL_MODE2_MASK |
|
||||
_GPIO_P_MODEL_MODE3_MASK |
|
||||
_GPIO_P_MODEL_MODE4_MASK |
|
||||
_GPIO_P_MODEL_MODE5_MASK);
|
||||
gpio->P[2].MODEL |= (GPIO_P_MODEL_MODE2_PUSHPULL |
|
||||
GPIO_P_MODEL_MODE3_PUSHPULL |
|
||||
GPIO_P_MODEL_MODE4_PUSHPULL |
|
||||
GPIO_P_MODEL_MODE5_PUSHPULL);
|
||||
gpio->P[2].DOUT |= (1UL << 5);
|
||||
|
||||
/* Configure USART2 as SPI master with manual CS */
|
||||
/* Get peripheral clock - ensure updated SystemCoreClock */
|
||||
SystemCoreClockUpdate();
|
||||
clk = (SystemCoreClock >> ((CMU->HFPERCLKDIV & _CMU_HFPERCLKDIV_HFPERCLKDIV_MASK) >>
|
||||
_CMU_HFPERCLKDIV_HFPERCLKDIV_SHIFT));
|
||||
/* Drive spi at max 7Mhz or half clockrate if core freq < 14Mhz */
|
||||
if (clk < 14000000)
|
||||
{
|
||||
spidiv = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
spidiv = (clk) / (div) - 256;
|
||||
}
|
||||
|
||||
/* Never allow higher frequency than specified, round up 1/4 div */
|
||||
if (spidiv & 0x3f) spidiv += 0x40;
|
||||
|
||||
usart->CLKDIV = spidiv;
|
||||
usart->CTRL = USART_CTRL_SYNC;
|
||||
usart->CMD = USART_CMD_CLEARRX | USART_CMD_CLEARTX;
|
||||
usart->ROUTE = USART_ROUTE_TXPEN | USART_ROUTE_RXPEN | USART_ROUTE_CLKPEN;
|
||||
usart->CMD = USART_CMD_MASTEREN | USART_CMD_TXEN | USART_CMD_RXEN;
|
||||
}
|
||||
|
||||
/**************************************************************************//**
|
||||
* @brief Disables GPIO pins and USART2 from FPGA register access
|
||||
*****************************************************************************/
|
||||
static void spiDisable(void)
|
||||
{
|
||||
USART_TypeDef *usart = USART2;
|
||||
GPIO_TypeDef *gpio = GPIO;
|
||||
|
||||
/* Disable USART2 */
|
||||
usart->CTRL = _USART_CTRL_RESETVALUE;
|
||||
usart->ROUTE = _USART_ROUTE_RESETVALUE;
|
||||
usart->CMD = USART_CMD_MASTERDIS | USART_CMD_TXDIS | USART_CMD_RXDIS;
|
||||
|
||||
/* Disable SPI pins */
|
||||
gpio->P[2].MODEH &= ~(_GPIO_P_MODEH_MODE13_MASK);
|
||||
gpio->P[2].MODEL &= ~(_GPIO_P_MODEL_MODE2_MASK |
|
||||
_GPIO_P_MODEL_MODE3_MASK |
|
||||
_GPIO_P_MODEL_MODE4_MASK |
|
||||
_GPIO_P_MODEL_MODE5_MASK);
|
||||
}
|
||||
|
||||
/**************************************************************************//**
|
||||
* @brief Performs USART2 SPI Transfer
|
||||
*****************************************************************************/
|
||||
static uint16_t spiAccess(uint8_t spiadr, uint8_t rw, uint16_t spidata)
|
||||
{
|
||||
USART_TypeDef *usart = USART2;
|
||||
GPIO_TypeDef *gpio = GPIO;
|
||||
uint16_t tmp;
|
||||
|
||||
clear_bit(gpio->P[2].DOUT, 5);
|
||||
|
||||
/* SPI address */
|
||||
usart->TXDATA = (spiadr & 0x3) | rw << 3;
|
||||
while (!(usart->STATUS & USART_STATUS_TXC)) ;
|
||||
tmp = (usart->RXDATA) << 0;
|
||||
|
||||
/* SPI data LSB */
|
||||
usart->TXDATA = spidata & 0xFF;
|
||||
while (!(usart->STATUS & USART_STATUS_TXC)) ;
|
||||
tmp = (usart->RXDATA);
|
||||
|
||||
/* SPI data MSB */
|
||||
usart->TXDATA = spidata >> 8;
|
||||
while (!(usart->STATUS & USART_STATUS_TXC)) ;
|
||||
tmp |= (usart->RXDATA) << 8;
|
||||
|
||||
gpio->P[2].DOUT |= (1 << 5);
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
/**************************************************************************//**
|
||||
* @brief Performs USART2 SPI write to FPGA register
|
||||
* @param spiadr Address of register
|
||||
* @param spidata Data to write
|
||||
*****************************************************************************/
|
||||
static void spiWrite(uint8_t spiadr, uint16_t spidata)
|
||||
{
|
||||
spiAccess(spiadr, 0, spidata);
|
||||
}
|
||||
|
||||
/**************************************************************************//**
|
||||
* @brief Performs USART2 SPI read from FPGA register
|
||||
* @param spiadr Address of register
|
||||
* @param spidata Dummy data
|
||||
*****************************************************************************/
|
||||
static uint16_t spiRead(uint8_t spiadr, uint16_t spidata)
|
||||
{
|
||||
return spiAccess(spiadr, 1, spidata);
|
||||
}
|
||||
|
||||
/**************************************************************************//**
|
||||
* @brief Initializes DVK register access
|
||||
*****************************************************************************/
|
||||
void DVK_SPI_init(void)
|
||||
{
|
||||
uint16_t spiMagic;
|
||||
|
||||
spiInit();
|
||||
/* Read "board control Magic" register to verify SPI is up and running */
|
||||
/* if not FPGA is configured to be in EBI mode */
|
||||
|
||||
spiMagic = DVK_SPI_readRegister(BC_MAGIC);
|
||||
if (spiMagic != BC_MAGIC_VALUE)
|
||||
{
|
||||
/* Development Kit is configured to use EBI mode, restart of kit required */
|
||||
/* to use USART2-SPI for configuration */
|
||||
spiDisable();
|
||||
while (1) ;
|
||||
}
|
||||
}
|
||||
|
||||
/**************************************************************************//**
|
||||
* @brief Disable and free up resources used by SPI board control access
|
||||
*****************************************************************************/
|
||||
void DVK_SPI_disable(void)
|
||||
{
|
||||
spiDisable();
|
||||
}
|
||||
|
||||
/**************************************************************************//**
|
||||
* @brief Perform read from DVK board control register
|
||||
* @param addr Address of register to read from
|
||||
*****************************************************************************/
|
||||
uint16_t DVK_SPI_readRegister(volatile uint16_t *addr)
|
||||
{
|
||||
uint16_t data;
|
||||
|
||||
if (addr != lastAddr)
|
||||
{
|
||||
spiWrite(0x00, 0xFFFF & ((uint32_t) addr)); /*LSBs of address*/
|
||||
spiWrite(0x01, 0xFF & ((uint32_t) addr >> 16)); /*MSBs of address*/
|
||||
spiWrite(0x02, (0x0C000000 & (uint32_t) addr) >> 26); /*Chip select*/
|
||||
}
|
||||
/* Read twice */
|
||||
data = spiRead(0x03, 0);
|
||||
data = spiRead(0x03, 0);
|
||||
lastAddr = addr;
|
||||
return data;
|
||||
}
|
||||
|
||||
/**************************************************************************//**
|
||||
* @brief Perform write to DVK board control register
|
||||
* @param addr Address of register to write to
|
||||
* @param data 16-bit to write into register
|
||||
*****************************************************************************/
|
||||
void DVK_SPI_writeRegister(volatile uint16_t *addr, uint16_t data)
|
||||
{
|
||||
if (addr != lastAddr)
|
||||
{
|
||||
spiWrite(0x00, 0xFFFF & ((uint32_t) addr)); /*LSBs of address*/
|
||||
spiWrite(0x01, 0xFF & ((uint32_t) addr >> 16)); /*MSBs of address*/
|
||||
spiWrite(0x02, (0x0C000000 & (uint32_t) addr) >> 26); /*Chip select*/
|
||||
}
|
||||
spiWrite(0x03, data); /*Data*/
|
||||
lastAddr = addr;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue