mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2025-08-14 21:17:43 +00:00
Initial firmware commit.
This commit is contained in:
141
firmware/chibios-portapack/os/hal/platforms/LPC43xx_M0/hal_lld.c
Executable file
141
firmware/chibios-portapack/os/hal/platforms/LPC43xx_M0/hal_lld.c
Executable file
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
ChibiOS/RT - Copyright (C) 2006-2013 Giovanni Di Sirio
|
||||
Copyright (C) 2014 Jared Boone, ShareBrained Technology
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file LPC43xx_M0/hal_lld.c
|
||||
* @brief LPC43xx M0 HAL subsystem low level driver source.
|
||||
*
|
||||
* @addtogroup HAL
|
||||
* @{
|
||||
*/
|
||||
|
||||
#include "ch.h"
|
||||
#include "hal.h"
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver local definitions. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver exported variables. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver local variables and types. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/* TODO: Somehow share this value between the M4 and M0 cores. The M0 always
|
||||
* runs at the same speed as the M4 core.
|
||||
*/
|
||||
static halclock_t hal_clock_f = LPC43XX_M0_CLK_PLL1_AT_BOOT;
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver local functions. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver interrupt handlers. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver exported functions. */
|
||||
/*===========================================================================*/
|
||||
|
||||
halclock_t halLPCGetSystemClock(void) {
|
||||
return hal_clock_f;
|
||||
}
|
||||
|
||||
void halLPCSetSystemClock(const halclock_t new_frequency) {
|
||||
hal_clock_f = new_frequency;
|
||||
}
|
||||
|
||||
/* TODO: Expose RIT code, move elsewhere. */
|
||||
static void ritimer_stop(void) {
|
||||
LPC_RITIMER->CTRL =
|
||||
(0 << 0) /* RITINT */
|
||||
| (1 << 1) /* RITENCLR */
|
||||
| (1 << 2) /* RITENBR */
|
||||
| (0 << 3) /* RITEN */
|
||||
;
|
||||
}
|
||||
|
||||
static void ritimer_start(void) {
|
||||
LPC_RITIMER->CTRL =
|
||||
(0 << 0) /* RITINT */
|
||||
| (1 << 1) /* RITENCLR */
|
||||
| (1 << 2) /* RITENBR */
|
||||
| (1 << 3) /* RITEN */
|
||||
;
|
||||
}
|
||||
|
||||
void systick_adjust_period(const uint32_t counts_per_tick) {
|
||||
ritimer_stop();
|
||||
LPC_RITIMER->COMPVAL = counts_per_tick;
|
||||
LPC_RITIMER->COUNTER = 0;
|
||||
ritimer_start();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Low level HAL driver initialization.
|
||||
*
|
||||
* @notapi
|
||||
*/
|
||||
void hal_lld_init(void) {
|
||||
/* Initialize timer 3 to serve as a cycle (PCLK) counter. */
|
||||
LPC_TIMER3->TCR = (1 << 1); /* CRST=1 */
|
||||
LPC_TIMER3->TCR = 0; /* CRST=0 */
|
||||
LPC_TIMER3->TC = 0;
|
||||
LPC_TIMER3->PR = 0;
|
||||
LPC_TIMER3->TCR = (1 << 0); /* CEN=1 */
|
||||
|
||||
/* Initialize repetitive interrupt timer (RIT) to act like SysTick for
|
||||
* operating system process timing.
|
||||
*/
|
||||
LPC_RITIMER->CTRL =
|
||||
(1 << 0) /* RITINT */
|
||||
| (1 << 1) /* RITENCLR */
|
||||
| (1 << 2) /* RITENBR */
|
||||
| (0 << 3) /* RITEN */
|
||||
;
|
||||
LPC_RITIMER->MASK = 0;
|
||||
systick_adjust_period(LPC43XX_M0_CLK_PLL1_AT_BOOT / CH_FREQUENCY - 1);
|
||||
|
||||
nvicEnableVector(RITIMER_OR_WWDT_IRQn, CORTEX_PRIORITY_MASK(CORTEX_PRIORITY_SYSTICK));
|
||||
}
|
||||
|
||||
/* Work-around to use RITimer in place of SysTick, which isn't available on
|
||||
* the LPC43xx M0 core.
|
||||
*/
|
||||
CH_IRQ_HANDLER(RITimer_Or_WWDT_IRQHandler) {
|
||||
/* Same code as in SysTickVector */
|
||||
CH_IRQ_PROLOGUE();
|
||||
|
||||
chSysLockFromIsr();
|
||||
chSysTimerHandlerI();
|
||||
chSysUnlockFromIsr();
|
||||
|
||||
LPC_RITIMER->CTRL =
|
||||
(1 << 0) /* RITINT */
|
||||
| (1 << 1) /* RITENCLR */
|
||||
| (1 << 2) /* RITENBR */
|
||||
| (1 << 3) /* RITEN */
|
||||
;
|
||||
|
||||
CH_IRQ_EPILOGUE();
|
||||
}
|
||||
|
||||
/** @} */
|
157
firmware/chibios-portapack/os/hal/platforms/LPC43xx_M0/hal_lld.h
Executable file
157
firmware/chibios-portapack/os/hal/platforms/LPC43xx_M0/hal_lld.h
Executable file
@@ -0,0 +1,157 @@
|
||||
/*
|
||||
ChibiOS/RT - Copyright (C) 2006-2013 Giovanni Di Sirio
|
||||
Copyright (C) 2014 Jared Boone, ShareBrained Technology
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file LPC43xx_M0/hal_lld.h
|
||||
* @brief HAL subsystem low level driver header template.
|
||||
*
|
||||
* @addtogroup HAL
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef _HAL_LLD_H_
|
||||
#define _HAL_LLD_H_
|
||||
|
||||
#include "lpc43xx_m0.h"
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver constants. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/**
|
||||
* @brief Defines the support for realtime counters in the HAL.
|
||||
*/
|
||||
#define HAL_IMPLEMENTS_COUNTERS TRUE
|
||||
|
||||
/**
|
||||
* @brief Platform name.
|
||||
*/
|
||||
#define PLATFORM_NAME "LPC43xx M0"
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Platform capabilities. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Platform specific friendly IRQ names. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/**
|
||||
* @name IRQ VECTOR names
|
||||
* @{
|
||||
*/
|
||||
#define RTC_IRQHandler Vector40 /**< RTC */
|
||||
#define M4Core_IRQHandler Vector44 /**< Cortex-M4 */
|
||||
#define DMA_IRQHandler Vector48 /**< DMA */
|
||||
#define Ethernet_IRQHandler Vector54 /**< Ethernet */
|
||||
#define SDIO_IRQHandler Vector58 /**< SD/MMC */
|
||||
#define LCD_IRQHandler Vector5C /**< LCD */
|
||||
#define USB0_IRQHandler Vector60 /**< USB0: OTG */
|
||||
#define USB1_IRQHandler Vector64 /**< USB1 */
|
||||
#define SCT_IRQHandler Vector68 /**< SCT combined */
|
||||
#define RITimer_Or_WWDT_IRQHandler Vector6C /**< RI Timer or WWDT */
|
||||
#define Timer0_IRQHandler Vector70 /**< Timer 0 */
|
||||
#define GINT1_IRQHandler Vector74 /**< GPIO global interrupt 1 */
|
||||
#define PIN_INT4_IRQHandler Vector78 /**< GPIO pin interrupt 4 */
|
||||
#define Timer3_IRQHandler Vector7C /**< Timer 3 */
|
||||
#define MCPWM_IRQHandler Vector80 /**< Motor control PWM */
|
||||
#define ADC0_IRQHandler Vector84 /**< ADC0 */
|
||||
#define I2C0_Or_I2C1_IRQHandler Vector88 /**< I2C0 or I2C1 */
|
||||
#define SGPIO_IRQHandler Vector8C /**< SGPIO */
|
||||
#define SPI_Or_DAC_IRQHandler Vector90 /**< SPI or DAC */
|
||||
#define ADC1_IRQHandler Vector94 /**< ADC1 */
|
||||
#define SSP0_Or_SSP1_IRQHandler Vector98 /**< SSP0 or SSP1 */
|
||||
#define EventRouter_IRQHandler Vector9C /**< Event router */
|
||||
#define USART0_IRQHandler VectorA0 /**< USART0 */
|
||||
#define UART1_IRQHandler VectorA4 /**< UART1 */
|
||||
#define USART2_Or_C_CAN1_IRQHandler VectorA8 /**< USART2 or C_CAN1 */
|
||||
#define USART3_IRQHandler VectorAC /**< USART3 */
|
||||
#define I2S0_Or_I2S1_QEI_IRQHandler VectorB0 /**< I2S0 or I2S1 or QEI */
|
||||
#define C_CAN0_IRQHandler VectorB4 /**< C_CAN0 */
|
||||
#define SPIFI_Or_ADCHS_IRQHandler VectorB8 /**< SPIFI or ADCHS */
|
||||
#define M0SUB_IRQHandler VectorBC /**< M0SUB */
|
||||
/** @} */
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver pre-compile time settings. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Derived constants and error checks. */
|
||||
/*===========================================================================*/
|
||||
|
||||
#define LPC43XX_M0_CLK_PLL1_AT_BOOT 96000000
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver data structures and types. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/**
|
||||
* @brief Type representing a system clock frequency.
|
||||
*/
|
||||
typedef uint32_t halclock_t;
|
||||
|
||||
/**
|
||||
* @brief Type of the realtime free counter value.
|
||||
*/
|
||||
typedef uint32_t halrtcnt_t;
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver macros. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/**
|
||||
* @brief Returns the current value of the system free running counter.
|
||||
* @note This service is implemented by returning the content of timer 3's
|
||||
* TC (counter value) register.
|
||||
*
|
||||
* @return The value of the system free running counter of
|
||||
* type halrtcnt_t.
|
||||
*
|
||||
* @notapi
|
||||
*/
|
||||
#define hal_lld_get_counter_value() (LPC_TIMER3->TC)
|
||||
|
||||
/**
|
||||
* @brief Realtime counter frequency.
|
||||
* @note The DWT_CYCCNT register is incremented directly by the system
|
||||
* clock so this function returns STM32_HCLK.
|
||||
*
|
||||
* @return The realtime counter frequency of type halclock_t.
|
||||
*
|
||||
* @notapi
|
||||
*/
|
||||
#define hal_lld_get_counter_frequency() halLPCGetSystemClock()
|
||||
|
||||
/*===========================================================================*/
|
||||
/* External declarations. */
|
||||
/*===========================================================================*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
void hal_lld_init(void);
|
||||
void systick_adjust_period(const uint32_t counts_per_tick);
|
||||
halclock_t halLPCGetSystemClock(void);
|
||||
void halLPCSetSystemClock(const halclock_t new_frequency);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _HAL_LLD_H_ */
|
||||
|
||||
/** @} */
|
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
ChibiOS/RT - Copyright (C) 2014 Jared Boone, ShareBrained Technology
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
/** @addtogroup CMSIS
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup lpc43xx_m0
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __LPC43XX_M0_H
|
||||
#define __LPC43XX_M0_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/** @addtogroup Configuration_section_for_CMSIS
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Configuration of the Cortex-M0 Processor and Core Peripherals
|
||||
*/
|
||||
#define __CM0_REV 0 /*!< Core revision r0p0 */
|
||||
#define __MPU_PRESENT 0 /*!< LPC43XX M0 does not provide MPU */
|
||||
#define __NVIC_PRIO_BITS 2 /*!< LPC43XX M0 uses 2 Bits for the Priority Levels */
|
||||
#define __Vendor_SysTickConfig 0 /*!< Set to 1 if different SysTick Config is used */
|
||||
|
||||
|
||||
/**
|
||||
* @brief LPC43XX M0 Interrupt Number Definition, according to the selected device
|
||||
* in @ref Library_configuration_section
|
||||
*/
|
||||
typedef enum IRQn {
|
||||
/****** Cortex-M0 Processor Exceptions Numbers ****************************************************************/
|
||||
Reset_IRQn = -15, /*!< 1 Reset Vector, invoked on Power up and warm reset */
|
||||
NonMaskableInt_IRQn = -14, /*!< 2 Non Maskable Interrupt */
|
||||
HardFault_IRQn = -13, /*!< 3 Cortex-M0 Hard Fault Interrupt */
|
||||
SVCall_IRQn = -5, /*!< 11 Cortex-M0 SV Call Interrupt */
|
||||
PendSV_IRQn = -2, /*!< 14 Cortex-M0 Pend SV Interrupt */
|
||||
SysTick_IRQn = -1, /*!< 15 Cortex-M0 System Tick Interrupt */
|
||||
|
||||
/****** LPC43xx M0 specific Interrupt Numbers *****************************************************************/
|
||||
RTC_IRQn = 0, /*!< 16 RTC */
|
||||
M4CORE_IRQn = 1, /*!< 17 Cortex-M4; Latched TXEV; for M0APP-M4 communication */
|
||||
DMA_IRQn = 2, /*!< 18 DMA */
|
||||
/* 3: 19 Reserved */
|
||||
/* 4: 20 ORed flash bank A, flash bank B, EEPROM interrupts */
|
||||
ETHERNET_IRQn = 5, /*!< 21 Ethernet */
|
||||
SDIO_IRQn = 6, /*!< 22 SD/MMC */
|
||||
LCD_IRQn = 7, /*!< 23 LCD */
|
||||
USB0_IRQn = 8, /*!< 24 OTG interrupt */
|
||||
USB1_IRQn = 9, /*!< 25 USB1 */
|
||||
SCT_IRQn = 10, /*!< 26 SCT combined interrupt */
|
||||
RITIMER_OR_WWDT_IRQn = 11, /*!< 27 RITIMER or WWDT */
|
||||
TIMER0_IRQn = 12, /*!< 28 TIMER0 */
|
||||
GINT1_IRQn = 13, /*!< 29 GPIO globak interrupt 1 */
|
||||
PIN_INT4_IRQn = 14, /*!< 30 GPIO pin interrupt 4 */
|
||||
TIMER3_IRQn = 15, /*!< 31 TIMER3 */
|
||||
MCPWM_IRQn = 16, /*!< 32 Motor control PWM */
|
||||
ADC0_IRQn = 17, /*!< 33 ADC0 */
|
||||
I2C0_OR_I2C1_IRQn = 18, /*!< 34 I2C0 or I2C1 */
|
||||
SGPIO_IRQn = 19, /*!< 35 SGPIO */
|
||||
SPI_OR_DAC_IRQn = 20, /*!< 36 SPI interrupt ORed with DAC interrupt */
|
||||
ADC1_IRQn = 21, /*!< 37 ADC1 */
|
||||
SSP0_OR_SSP1_IRQn = 22, /*!< 38 SSP0 interrupt ORed with SSP1 interrupt */
|
||||
EVENTROUTER_IRQn = 23, /*!< 39 Event router */
|
||||
USART0_IRQn = 24, /*!< 40 USART0 */
|
||||
UART1_IRQn = 25, /*!< 41 Combined UART interrupt with Modem interrupt */
|
||||
USART2_OR_C_CAN1_IRQn = 26, /*!< 42 USART2 interrupt ORed with C_CAN1 interrupt */
|
||||
USART3_IRQn = 27, /*!< 43 Combined USART interrupt with IrDA interrupt */
|
||||
I2S0_OR_I2S1_QEI_IRQn = 28, /*!< 44 I2S0 OR I2S1 OR QEI interrupt */
|
||||
C_CAN0_IRQn = 29, /*!< 45 C_CAN0 */
|
||||
SPIFI_OR_ADCHS_IRQn = 30, /*!< 46 SPIFI OR ADCHS interrupt */
|
||||
M0SUB_IRQn = 31, /*!< 47 M0SUB core */
|
||||
} IRQn_Type;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#include "core_cm0.h" /* Cortex-M0 processor and core peripherals */
|
||||
#include "lpc43xx.inc"
|
||||
|
||||
#endif /* __LPC43XX_M0_H */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
13
firmware/chibios-portapack/os/hal/platforms/LPC43xx_M0/platform.mk
Executable file
13
firmware/chibios-portapack/os/hal/platforms/LPC43xx_M0/platform.mk
Executable file
@@ -0,0 +1,13 @@
|
||||
# List of all the LPC43xx M0 platform files.
|
||||
PLATFORMSRC = ${CHIBIOS_PORTAPACK}/os/hal/platforms/LPC43xx_M0/hal_lld.c \
|
||||
${CHIBIOS_PORTAPACK}/os/hal/platforms/LPC43xx/gpt_lld.c \
|
||||
${CHIBIOS_PORTAPACK}/os/hal/platforms/LPC43xx/i2c_lld.c \
|
||||
${CHIBIOS_PORTAPACK}/os/hal/platforms/LPC43xx/pal_lld.c \
|
||||
${CHIBIOS_PORTAPACK}/os/hal/platforms/LPC43xx/rtc_lld.c \
|
||||
${CHIBIOS_PORTAPACK}/os/hal/platforms/LPC43xx/sdc_lld.c \
|
||||
${CHIBIOS_PORTAPACK}/os/hal/platforms/LPC43xx/serial_lld.c \
|
||||
${CHIBIOS_PORTAPACK}/os/hal/platforms/LPC43xx/spi_lld.c
|
||||
|
||||
# Required include directories
|
||||
PLATFORMINC = ${CHIBIOS_PORTAPACK}/os/hal/platforms/LPC43xx_M0 \
|
||||
${CHIBIOS_PORTAPACK}/os/hal/platforms/LPC43xx
|
Reference in New Issue
Block a user