c/c++语言开发共享英特尔Galileo裸机UART

我想在Intel Galileo板上编写一个“hello world” 裸机应用程序。 当然,使用UEFI打印文本(到UART-1)效果很好,但我想“手动”访问UART,而无需UEFI的任何帮助。

在QEMU,我的代码效果很好:

.h文件

#define COM1_PORT (0x03F8) #define UART_PORT (COM1_PORT) enum uart_port_offs_t { // DLAB RW THR = 0, // 0 W Transmitter Holding Buffer RBR = 0, // 0 R Receiver Buffer DLL = 0, // 1 RW Divisor Latch Low Byte IER = 1, // 0 RW Interrupt Enable Register DLH = 1, // 1 RW Divisor Latch High Byte IIR = 2, // - R Interrupt Identification Register FCR = 2, // - RW FIFO Control Register LCR = 3, // - RW Line Control Register MCR = 4, // - RW Modem Control Register LSR = 5, // - R Line Status Register MSR = 6, // - R Modem Status Register SR = 7, // - RW Scratch Register }; 

.c文件

 void uart_init(void) { outb(UART_PORT + IER, 0x00); // Disable all interrupts outb(UART_PORT + LCR, LCR_DLAB); outb(UART_PORT + DLL, BAUD_LL); // Set divisor (lo byte) outb(UART_PORT + DLH, BAUD_HL); // (hi byte) outb(UART_PORT + LCR, LCR_WORD_BITS_8 | LCR_PAR_NONE | LCR_STOP_BITS_1); outb(UART_PORT + FCR, FCR_ENABLE | FCR_CLR_RECV | FCR_CLR_SEND | FCR_TRIGGER_16); outb(UART_PORT + MCR, MCR_DSR | MCR_RTS | MCR_AUX2); } ssize_t uart_write(const char *buf, size_t len) { size_t written = 0; while (written < len) { while (!is_output_empty()) { asm volatile ("pause"); } outb(UART_PORT + THR, buf[written]); ++written; } return written; } 

主要

 SystemTable->ConOut->OutputString(SystemTable->ConOut, L"Exiting EFI boot services ...rn"); SystemTable->BootServices->ExitBootServices(ImageHandle, map_key); uart_init(); while (1) { const char s[] = "UARTrn"; uart_write(s, sizeof (s) - 1); } 

这些规格对我没什么帮助。 我猜英特尔Galileo板上的UART不使用/模拟普通/传统COM端口3F8h,2F8h,3E8h或2E8h。

谁能告诉我我做错了什么,甚至发布了一个最小的裸机世界示例?

    我假设您的目标是英特尔Galileo开发板上的“类似音频”连接器的串行端口。

    以下是一些应该有用的资源

    有关此UART的注意事项

    由于第18章(约67页的有用信息)有很多内容需要阅读,所以我不打算重新输入所有内容,请阅读数据表并相应配置寄存器。

    一般说明

    需要了解更多c/c++开发分享英特尔Galileo裸机UART,也可以关注C/ C++技术分享栏目—计算机技术网(www.ctvol.com)!

      以上就是c/c++开发分享英特尔Galileo裸机UART相关内容,想了解更多C/C++开发(异常处理)及C/C++游戏开发关注计算机技术网(www.ctvol.com)!)。

      本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

      ctvol管理联系方式QQ:251552304

      本文章地址:https://www.ctvol.com/c-cdevelopment/979391.html

      (0)
      上一篇 2021年12月12日
      下一篇 2021年12月12日

      精彩推荐