arm: small refactor in main

This commit is contained in:
Paul Mathieu 2022-06-19 09:43:36 +02:00
parent 15488550c0
commit e1eaa0ec0a
2 changed files with 11 additions and 7 deletions

View File

@ -3,6 +3,8 @@ MEMORY
ICTM (rwx) : ORIGIN = 0x00000800, LENGTH = 14336 ICTM (rwx) : ORIGIN = 0x00000800, LENGTH = 14336
} }
_vector_table = 0x0;
SECTIONS SECTIONS
{ {
.text : .text :

View File

@ -8,6 +8,8 @@
#include "uart.h" #include "uart.h"
#include "uart_async.h" #include "uart_async.h"
extern volatile uint32_t _vector_table[];
namespace { namespace {
using async::AwaitableType; using async::AwaitableType;
@ -24,20 +26,17 @@ void Timer0Isr() {
void SetupUart() { void SetupUart() {
InitUarts(); InitUarts();
auto* vector_table = reinterpret_cast<uint32_t*>(0x0); _vector_table[16 + Uart0_IRQn] = reinterpret_cast<uint32_t>(Uart0Isr);
vector_table[16 + HardFault_IRQn] =
reinterpret_cast<uint32_t>(crash::HardFaultHandler);
vector_table[16 + Uart0_IRQn] = reinterpret_cast<uint32_t>(Uart0Isr);
vector_table[16 + Timer0_IRQn] = reinterpret_cast<uint32_t>(Timer0Isr);
NVIC_SetPriority(Uart0_IRQn, 3); NVIC_SetPriority(Uart0_IRQn, 3);
NVIC_EnableIRQ(Uart0_IRQn); NVIC_EnableIRQ(Uart0_IRQn);
} }
void SetupTimer() { void SetupTimer() {
NVIC_EnableIRQ(Timer0_IRQn);
timer0->SetupAsWdt(100000 * 4000); timer0->SetupAsWdt(100000 * 4000);
timer0->EnableT1(); timer0->EnableT1();
_vector_table[16 + Timer0_IRQn] = reinterpret_cast<uint32_t>(Timer0Isr);
NVIC_EnableIRQ(Timer0_IRQn);
} }
async::task<> echo() { async::task<> echo() {
@ -49,6 +48,9 @@ async::task<> echo() {
} // namespace } // namespace
int main() { int main() {
_vector_table[16 + HardFault_IRQn] =
reinterpret_cast<uint32_t>(crash::HardFaultHandler);
SetupUart(); SetupUart();
SetupTimer(); SetupTimer();