aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/init.c12
-rw-r--r--src/isr.s5
-rw-r--r--src/main.c (renamed from src/blinky.c)59
3 files changed, 52 insertions, 24 deletions
diff --git a/src/init.c b/src/init.c
index 30e2c6d..5753a13 100644
--- a/src/init.c
+++ b/src/init.c
@@ -5,7 +5,7 @@
void on_reset(void);
-void __attribute__((weak, interrupt, __section__(".isr_vector")))
+void __attribute__((weak, interrupt, __section__(".isr_vector.routines")))
default_irq_handler(void)
{
return;
@@ -13,7 +13,7 @@ default_irq_handler(void)
#define WEAK_IRQ(irq) \
void __attribute__(( \
- weak, alias("default_irq_handler"), __section__(".isr_vector"))) \
+ weak, alias("default_irq_handler"), __section__(".isr_vector.routines"))) \
irq(void)
WEAK_IRQ(irq_on_reset);
@@ -60,7 +60,9 @@ extern uint32_t BSS_STOP;
static inline void set_mtvec(void* vector_table)
{
- asm volatile("csrw mtvec, %0" : : "r"(vector_table));
+ uint32_t mtvec = (uint32_t) vector_table;
+ mtvec |= 1; // Set interrupt table mode to "VECTORED"
+ asm volatile("csrw mtvec, %0" : : "r"(mtvec));
}
/*
@@ -99,7 +101,7 @@ extern void main(void);
/* Start function. Responsible for initializing the system and jumping to the
* main function. */
-static void start(void)
+static __attribute((__section__(".sinit.1"))) void start(void)
{
/* Initialize the data segments. */
init_data_segments();
@@ -113,7 +115,7 @@ static void start(void)
* The reset callback.This has to be a naked function because the stack pointer
* may not be initialized!!.
*/
-__attribute((naked, __section__(".isr_routines.on_reset"))) void on_reset(void)
+__attribute((naked, __section__(".sinit"))) void _begin(void)
{
// Set up the stack pointer to point to the end of SRAM.
asm volatile(
diff --git a/src/isr.s b/src/isr.s
index 065450d..04d66d1 100644
--- a/src/isr.s
+++ b/src/isr.s
@@ -1,8 +1,3 @@
-
-.section .sinit
-_start:
-j on_reset /* first instruction. Should jump directly to on_reset */
-
.section .isr_vector
.global isr_vector
isr_vector:
diff --git a/src/blinky.c b/src/main.c
index 355b479..3066123 100644
--- a/src/blinky.c
+++ b/src/main.c
@@ -1,11 +1,20 @@
#include <stdint.h>
-#include "isr_vector.h"
#include "ch573/gpio.h"
+#include "ch573/uart.h"
+#include "ch573/pwr.h"
+
+#include "isr_vector.h"
#define GPIO_PORT_A ch573_gpio__gpio_port_a
#define GPIO_PORT CH573_GPIO__GPIO_PORT_T_INTF
+#define UART1 ch573_uart__uart1
+#define UART CH573_UART__UART_T_INTF
+
+#define PWR1 ch573_pwr__pwr_mgmt
+#define PWR CH573_PWR__PWR_MGMT_T_INTF
+
/*
* Function which delays for a bit.
*/
@@ -57,29 +66,51 @@ extern uint32_t DATA_VALUES_IN_FLASH;
extern uint32_t DATA_SEGMENT_START;
extern uint32_t DATA_SEGMENT_STOP;
+#define gpio_usart1_tx_pin 9
+#define gpio_usart1_rx_pin 8
+
+const char* hello_world = "Hello, World!\r\n";
+
+#define BAUD_RATE 115200
+
/* Main routine. This is called on_reset once everything else has been set up.
*/
void main(void)
{
- GPIO_PORT.dir.set(GPIO_PORT_A, DIR_OUT, 8);
- GPIO_PORT.pd_drv.set(GPIO_PORT_A, PD_DRV_OPEN_DRAIN, 8);
+ GPIO_PORT.dir.set(GPIO_PORT_A, DIR_OUT, gpio_usart1_tx_pin);
+ GPIO_PORT.pd_drv.set(GPIO_PORT_A, 0, gpio_usart1_tx_pin);
+
+ UART.div.set(UART1, 1);
+ UART.fcr.set(UART1, 0x07);
+ UART.ier.txd_en.set(UART1, ON);
+ UART.lcr.word_sz.set(UART1, WORD_SZ_8_BITS);
+
+ uint32_t dl = (10 * 6400000 / 8 / BAUD_RATE + 5) / 10;
+ UART.dl.set(UART1, dl);
+
+ // PWR.slp_clk_off_0.uart1.set(PWR1, CLK_SOURCE_ENABLED);
+
+ const char* ptr = hello_world;
- for (;;) {
- if (deadbeef == 0xdeadbeef) {
- GPIO_PORT.out.set(GPIO_PORT_A, ON, 8);
+ while (1) {
+ if (*ptr == 0) {
+ ptr = hello_world;
}
- delay();
- delay();
- delay();
- GPIO_PORT.out.set(GPIO_PORT_A, OFF, 8);
- delay();
+
+ while (!UART.lsr.thr_empty.get(UART1));
+ UART.thr.set(UART1, *(ptr++));
}
}
-IRQ(systick) {
+IRQ(systick)
+{
collatz(5);
}
-IRQ(exc) {}
+IRQ(exc)
+{
+}
-IRQ(nmi) {}
+IRQ(nmi)
+{
+}