feat: interrupt request

This commit is contained in:
liuyihui 2023-04-17 22:45:13 +08:00
parent 0b75add2d1
commit 3e1079ec1b
4 changed files with 95 additions and 25 deletions

View File

@ -12,7 +12,6 @@
#define CPU_INT_FAST_CLK_HZ 4000000u // Value of the fast internal oscillator clock frequency in Hz
#define UART_MSG UART1
#define UART_WIFI UART2
#define PI 3.1415926
#define BIT(x) (1UL << (x))

View File

@ -37,9 +37,12 @@ static inline void uart_init(UART_Type *UART, unsigned long baud) {
// UARTx_BLH is the low 8 bits of SBR (band rate)
UART->BDL = sbr & UART_BDL_SBR_MASK;
// Enable receiver and transmitter
UART->C2 |= UART_C2_TE_MASK // Transmitter enable
| UART_C2_RE_MASK // Receiver enable
| UART_C2_RIE_MASK; // Receiver interrupt enable
UART->C2 |= UART_C2_TE_MASK // Transmitter enable
| UART_C2_RE_MASK; // Receiver enable
}
static inline void uart_rie_enable(UART_Type *UART) {
UART->C2 |= UART_C2_RIE_MASK; // Receiver interrupt enable
}
static inline int uart_read_ready(UART_Type *UART) {

2
main.c
View File

@ -1,4 +1,3 @@
#include "ESP8266.h"
#include "derivative.h"
#include "systick.h"
#include "uart.h"
@ -9,6 +8,7 @@ int main(void) {
// Initialize
systick_init(CORCLK / 1000); // Period of systick timer : 1ms
uart_init(UART_MSG, 9600); // Initialize UART1 with PC
uart_rie_enable(UART_MSG); // Enable UART1 receive interrupt
uart_printf(UART_MSG, "System Clock: %lu\r\n", CORCLK);
uart_printf(UART_MSG, "Bus Clock: %lu\r\n", BUSCLK);

View File

@ -171,10 +171,7 @@ __attribute__((naked, noreturn)) void _reset(void) {
}
// Interrupt service routine (ISR)
extern void _estack(void); // Defined in link.ld
extern void SysTick_Handler(void); // Defined in main.c
void Default_Handler() { __asm("bkpt"); }
extern void _estack(void); // Defined in link.ld
/*
Set tab (the vector table) in the section ".vectors"
@ -183,23 +180,94 @@ void Default_Handler() { __asm("bkpt"); }
the first one is the initial stack pointer
the second one is the initial program counter
*/
void Default_Handler() { __asm("bkpt"); }
void NMI_Handler() __attribute__((weak, alias("Default_Handler")));
void HardFault_Handler() __attribute__((weak, alias("Default_Handler")));
void SVC_Handler() __attribute__((weak, alias("Default_Handler")));
void PendSV_Handler() __attribute__((weak, alias("Default_Handler")));
void SysTick_Handler() __attribute__((weak, alias("Default_Handler")));
void DMA0_IRQHandler() __attribute__((weak, alias("Default_Handler")));
void DMA1_IRQHandler() __attribute__((weak, alias("Default_Handler")));
void DMA2_IRQHandler() __attribute__((weak, alias("Default_Handler")));
void DMA3_IRQHandler() __attribute__((weak, alias("Default_Handler")));
void MCM_IRQHandler() __attribute__((weak, alias("Default_Handler")));
void FTFL_IRQHandler() __attribute__((weak, alias("Default_Handler")));
void PMC_IRQHandler() __attribute__((weak, alias("Default_Handler")));
void LLWU_IRQHandler() __attribute__((weak, alias("Default_Handler")));
void I2C0_IRQHandler() __attribute__((weak, alias("Default_Handler")));
void I2C1_IRQHandler() __attribute__((weak, alias("Default_Handler")));
void SPI0_IRQHandler() __attribute__((weak, alias("Default_Handler")));
void SPI1_IRQHandler() __attribute__((weak, alias("Default_Handler")));
void UART0_IRQHandler() __attribute__((weak, alias("Default_Handler")));
void UART1_IRQHandler() __attribute__((weak, alias("Default_Handler")));
void UART2_IRQHandler() __attribute__((weak, alias("Default_Handler")));
void ADC0_IRQHandler() __attribute__((weak, alias("Default_Handler")));
void CMP0_IRQHandler() __attribute__((weak, alias("Default_Handler")));
void TPM0_IRQHandler() __attribute__((weak, alias("Default_Handler")));
void TPM1_IRQHandler() __attribute__((weak, alias("Default_Handler")));
void TPM2_IRQHandler() __attribute__((weak, alias("Default_Handler")));
void RTC_Alarm_IRQHandler() __attribute__((weak, alias("Default_Handler")));
void RTC_Seconds_IRQHandler() __attribute__((weak, alias("Default_Handler")));
void PIT_IRQHandler() __attribute__((weak, alias("Default_Handler")));
void USBOTG_IRQHandler() __attribute__((weak, alias("Default_Handler")));
void DAC0_IRQHandler() __attribute__((weak, alias("Default_Handler")));
void TSI0_IRQHandler() __attribute__((weak, alias("Default_Handler")));
void MCG_IRQHandler() __attribute__((weak, alias("Default_Handler")));
void LPTMR0_IRQHandler() __attribute__((weak, alias("Default_Handler")));
void PORTA_IRQHandler() __attribute__((weak, alias("Default_Handler")));
void PORTD_IRQHandler() __attribute__((weak, alias("Default_Handler")));
__attribute__((section(".vectors"))) void (*tab[16 + 32])(void) = {
_estack, // Initial stack pointer
_reset, // Reset handler
Default_Handler, // NMI handler
Default_Handler, // Hard Fault handler
0, // Reserved
0, // Reserved
0, // Reserved
0, // Reserved
0, // Reserved
0, // Reserved
0, // Reserved
Default_Handler, // SVC handler
0, // Reserved
0, // Reserved
Default_Handler, // PendSV handler
SysTick_Handler // SysTick handler
_estack, // Initial stack pointer
_reset, // Reset handler
NMI_Handler, // NMI handler
HardFault_Handler, // Hard Fault handler
0, // Reserved
0, // Reserved
0, // Reserved
0, // Reserved
0, // Reserved
0, // Reserved
0, // Reserved
SVC_Handler, // SVC handler
0, // Reserved
0, // Reserved
PendSV_Handler, // PendSV handler
SysTick_Handler, // SysTick handler
DMA0_IRQHandler, // DMA channel 0 transfer complete and error
DMA1_IRQHandler, // DMA channel 1 transfer complete and error
DMA2_IRQHandler, // DMA channel 2 transfer complete and error
DMA3_IRQHandler, // DMA channel 3 transfer complete and error
MCM_IRQHandler, // Normal interrupt
FTFL_IRQHandler, // command complete and read collision
PMC_IRQHandler, // Low-voltage detect, low-voltage warning
LLWU_IRQHandler, // Low Leakage Wakeup
I2C0_IRQHandler, // I2C0 interrupt
I2C1_IRQHandler, // I2C1 interrupt
SPI0_IRQHandler, // SPI0 interrupt
SPI1_IRQHandler, // SPI1 interrupt
UART0_IRQHandler, // UART0 status and error
UART1_IRQHandler, // UART1 status and error
UART2_IRQHandler, // UART2 status and error
ADC0_IRQHandler, // ADC0 interrupt
CMP0_IRQHandler, // CMP0 interrupt
TPM0_IRQHandler, // TPM0 fault, overflow and channels interrupt
TPM1_IRQHandler, // TPM1 fault, overflow and channels interrupt
TPM2_IRQHandler, // TPM2 fault, overflow and channels interrupt
RTC_Alarm_IRQHandler, // RTC alarm interrupt
RTC_Seconds_IRQHandler, // RTC seconds interrupt
PIT_IRQHandler, // PIT timer all channels interrupt
Default_Handler, // Reserved
USBOTG_IRQHandler, // USB OTG interrupt
DAC0_IRQHandler, // DAC0 interrupt
TSI0_IRQHandler, // TSI0 interrupt
MCG_IRQHandler, // MCG interrupt
LPTMR0_IRQHandler, // LPTimer interrupt
Default_Handler, // Reserved
PORTA_IRQHandler, // Port A interrupt
PORTD_IRQHandler, // Port D interrupt
};
__attribute__((section(".cfmconfig"))) uint32_t(cfm[4]) = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFE};