feat: 集成RT-Thread Nano系统,添加LCD DMA驱动,完善任务框架
This commit is contained in:
+91
-50
@@ -7,8 +7,14 @@
|
||||
#include "flash_manager.h"
|
||||
#include "lcd.h"
|
||||
#include "touch.h"
|
||||
#include "monitor_task.h"
|
||||
#include "work_task.h"
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <rthw.h>
|
||||
#include <rtthread.h>
|
||||
|
||||
extern "C" void rt_hw_board_init(void);
|
||||
|
||||
__attribute__((section(".sdram"))) uint8_t sdram_big_buffer[1024 * 1024];
|
||||
|
||||
@@ -20,49 +26,67 @@ Led led3(GpioPort::A, 0x20);
|
||||
static void led_pattern(uint8_t p)
|
||||
{
|
||||
led0.off();
|
||||
led1.off();
|
||||
led2.off();
|
||||
led3.off();
|
||||
if (p & 0x01) led0.on();
|
||||
led1.off();
|
||||
if (p & 0x02) led1.on();
|
||||
led2.off();
|
||||
if (p & 0x04) led2.on();
|
||||
led3.off();
|
||||
if (p & 0x08) led3.on();
|
||||
}
|
||||
|
||||
USART uart0(UartPort::_0, 9600);
|
||||
static void led_task_entry(void *parameter)
|
||||
{
|
||||
(void)parameter;
|
||||
uint32_t tick = 0;
|
||||
uint8_t step = 0;
|
||||
uint8_t led_map[4] = {1, 2, 4, 8};
|
||||
uint32_t job_id = 0;
|
||||
|
||||
int main(void)
|
||||
led0.on();
|
||||
led1.off();
|
||||
led2.off();
|
||||
led3.off();
|
||||
|
||||
while (1)
|
||||
{
|
||||
rt_thread_mdelay(250);
|
||||
tick++;
|
||||
|
||||
step = (step + 1) & 3;
|
||||
led_pattern(led_map[step]);
|
||||
|
||||
if (tick % 8 == 0)
|
||||
{
|
||||
printf("\r[%08lu] *** system alive @ %lu ticks ",
|
||||
(unsigned long)(tick / 4),
|
||||
(unsigned long)rt_tick_get());
|
||||
}
|
||||
|
||||
if (tick % 120 == 0)
|
||||
{
|
||||
job_id++;
|
||||
printf("\r\n[MAIN] Dispatching job #%lu to worker...\r\n", (unsigned long)job_id);
|
||||
work_task_send(job_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" int main(void)
|
||||
{
|
||||
led0.init();
|
||||
led1.init();
|
||||
led2.init();
|
||||
led3.init();
|
||||
led_pattern(0x01);
|
||||
|
||||
USART::setDefault(&uart0);
|
||||
led_pattern(0x03);
|
||||
|
||||
printf("\r\n===== LSPi Board Boot =====\r\n");
|
||||
|
||||
uint32_t cs = RCU_CFG0 & RCU_CFG0_SCS;
|
||||
printf("Clock source: ");
|
||||
if (cs == RCU_SCSS_IRC16M)
|
||||
printf("IRC16M (16MHz)\r\n");
|
||||
else if (cs == RCU_SCSS_HXTAL)
|
||||
printf("HXTAL (25MHz)\r\n");
|
||||
else if (cs == RCU_SCSS_PLLP)
|
||||
printf("PLL (168MHz)\r\n");
|
||||
else
|
||||
printf("UNKNOWN\r\n");
|
||||
printf("SystemCoreClock: %lu Hz\r\n", SystemCoreClock);
|
||||
|
||||
led_pattern(0x05);
|
||||
|
||||
HardwareInit::init();
|
||||
led_pattern(0x07);
|
||||
|
||||
uart0.reinit(9600);
|
||||
uart_0.reinit(9600);
|
||||
USART::setDefault(&uart_0);
|
||||
|
||||
cs = RCU_CFG0 & RCU_CFG0_SCS;
|
||||
uint32_t cs = RCU_CFG0 & RCU_CFG0_SCS;
|
||||
printf("System clock switched to: ");
|
||||
if (cs == RCU_SCSS_PLLP)
|
||||
printf("PLL (168MHz)\r\n");
|
||||
@@ -78,9 +102,12 @@ int main(void)
|
||||
led_pattern(0x0B);
|
||||
{
|
||||
RetCode ret = SdramManager::instance().init();
|
||||
if (ret != RET_OK) {
|
||||
if (ret != RET_OK)
|
||||
{
|
||||
printf(" SDRAM init failed: %d\r\n", ret);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
printf(" SDRAM init OK\r\n");
|
||||
}
|
||||
}
|
||||
@@ -89,9 +116,12 @@ int main(void)
|
||||
led_pattern(0x0D);
|
||||
{
|
||||
RetCode ret = FlashManager::instance().init();
|
||||
if (ret != RET_OK) {
|
||||
if (ret != RET_OK)
|
||||
{
|
||||
printf(" Flash init failed: %d\r\n", ret);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
printf(" Flash init OK (%lu KB total, %lu KB/sector)\r\n",
|
||||
FlashManager::instance().total_size() / 1024,
|
||||
FlashManager::instance().sector_size() / 1024);
|
||||
@@ -101,9 +131,12 @@ int main(void)
|
||||
printf("Initializing LCD...\r\n");
|
||||
{
|
||||
RetCode ret = Lcd::instance().init();
|
||||
if (ret != RET_OK) {
|
||||
if (ret != RET_OK)
|
||||
{
|
||||
printf(" LCD init failed: %d\r\n", ret);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
printf(" LCD init OK (%s)\r\n", Lcd::instance().idString());
|
||||
}
|
||||
}
|
||||
@@ -111,9 +144,12 @@ int main(void)
|
||||
printf("Initializing Touch...\r\n");
|
||||
{
|
||||
RetCode ret = GT1151::instance().init();
|
||||
if (ret != RET_OK) {
|
||||
if (ret != RET_OK)
|
||||
{
|
||||
printf(" Touch init failed: %d\r\n", ret);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
printf(" Touch init OK\r\n");
|
||||
}
|
||||
}
|
||||
@@ -123,23 +159,28 @@ int main(void)
|
||||
printf("CPU: 168MHz, SDRAM: 32MB, Flash: 1MB\r\n\r\n");
|
||||
|
||||
Lcd::instance().clear(Lcd::BLACK);
|
||||
Lcd::instance().setForeground(Lcd::CYAN);
|
||||
Lcd::instance().showString(10, 10, 460, 24, 16, 0, (uint8_t *)"LSPi System Ready");
|
||||
Lcd::instance().setForeground(Lcd::GRAY);
|
||||
Lcd::instance().showString(10, 30, 460, 20, 16, 0, (uint8_t *)"168MHz | 32MB SDRAM | 1MB Flash");
|
||||
|
||||
uint32_t tick = 0;
|
||||
while (1)
|
||||
printf("Initializing RT-Thread...\r\n");
|
||||
rt_hw_board_init();
|
||||
rt_system_timer_init();
|
||||
rt_system_scheduler_init();
|
||||
|
||||
monitor_task_init();
|
||||
work_task_init();
|
||||
|
||||
rt_thread_t led_thread = rt_thread_create("led",
|
||||
led_task_entry,
|
||||
RT_NULL,
|
||||
512,
|
||||
RT_THREAD_PRIORITY_MAX - 4,
|
||||
10);
|
||||
if (led_thread != RT_NULL)
|
||||
{
|
||||
led0.toggle();
|
||||
delay_1ms(500);
|
||||
|
||||
tick++;
|
||||
if (tick % 10 == 0) {
|
||||
printf(".");
|
||||
}
|
||||
if (tick % 120 == 0) {
|
||||
printf(" [%lu s]\r\n", tick / 2);
|
||||
}
|
||||
rt_thread_startup(led_thread);
|
||||
}
|
||||
|
||||
printf("Starting RT-Thread scheduler...\r\n");
|
||||
rt_system_scheduler_start();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user