嵌入式系统是一个非常广泛的术语。它可能指没有操作系统的微控制器或带有操作系统的“普通”计算机。
一些例子:
- 微控制器读取传感器并通过管道控制水流。
- 树莓派在Linux下运行,控制着嵌入到无人机中的树莓派。
- PC电脑控制激光切割机。
- 主机计算机在射电望远镜系统中。
因此,你的问题没有一个确定的答案。
与在无人机中使用的树莓派不同,uC系统将以完全不同的方式编程。
但是我认为你的问题可能涉及到uC系统。
uC系统的编程通常被称为“裸机”,因为程序员在其应用程序和实际硬件之间没有立即软件(抽象层)。因此,他们直接访问内存、硬件寄存器和其他资源。即使在裸机开发中使用的操作系统(称为RTOS)也与像Linux或Windows这样的常规操作系统完全不同。它们更像是链接到裸金属应用程序的库,只提供任务管理、通信、同步和数据交换机制。
以下是您在评论中提出的一些问题:
- DMA - 直接内存访问 - 允许在没有使用处理器核心的情况下,在内存与外设或内存之间传输数据。一些uC具有非常复杂的DMA和事件系统-例如,定时器溢出可以触发ADC,然后触发DMA传输,将转换后的数据存储到内存中。
- 链接器脚本 - 定义存储在内存中的内容、方式和位置。它们可能非常复杂,并指示包括或排除代码或数据,并如何组织程序存储器。以下是STM32系列uC的链接器脚本示例。
/* Entry Point */
ENTRY(Reset_Handler)
_estack = 0x10004000
/* Generate a link error if heap and stack don't fit into RAM */
_Min_Heap_Size = 0x100; /* required amount of heap */
_Min_Stack_Size = 0x1000; /* required amount of stack */
/* Specify the memory areas */
MEMORY
{
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 64K
CCMRAM (rw) : ORIGIN = 0x10000000, LENGTH = 16K
FLASH (rx) : ORIGIN = 0x8000000 + 32K, LENGTH = 512K - 34K
}
_FLASH_SIZE = LENGTH(FLASH);
/* Define output sections */
SECTIONS
{
/* The startup code goes first into FLASH */
.isr_vector :
{
. = ALIGN(4);
_vectors_start = .;
KEEP(*(.isr_vector)) /* Startup code */
. = ALIGN(4);
_vectors_end = .;
} >FLASH
.sizedata :
{
. = ALIGN(4);
KEEP(*(.sizedata))
KEEP(*(.sizedata*))
. = ALIGN(4);
} >FLASH
.flashdata :
{
. = ALIGN(4);
KEEP(*(.rodata)) /* .rodata sections (constants, strings, etc.) */
KEEP(*(.rodata*)) /* .rodata* sections (constants, strings, etc.) */
. = ALIGN(4);
} >FLASH
/* The program code and other data goes into FLASH */
.text :
{
. = ALIGN(4);
*(.text) /* .text sections (code) */
*(.text*) /* .text* sections (code) */
*(.glue_7) /* glue arm to thumb code */
*(.glue_7t) /* glue thumb to arm code */
*(.eh_frame)
KEEP (*(.init))
KEEP (*(.fini))
. = ALIGN(4);
_etext = .; /* define a global symbols at end of code */
} >FLASH
/* Constant data goes into FLASH */
.rodata :
{
. = ALIGN(4);
*(.rodata) /* .rodata sections (constants, strings, etc.) */
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
. = ALIGN(4);
} >FLASH
.ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH
.ARM : {
__exidx_start = .;
*(.ARM.exidx*)
__exidx_end = .;
} >FLASH
.preinit_array :
{
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array*))
PROVIDE_HIDDEN (__preinit_array_end = .);
} >FLASH
.init_array :
{
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array*))
PROVIDE_HIDDEN (__init_array_end = .);
} >FLASH
.fini_array :
{
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(SORT(.fini_array.*)))
KEEP (*(.fini_array*))
PROVIDE_HIDDEN (__fini_array_end = .);
} >FLASH
/* used by the startup to initialize data */
_sidata = LOADADDR(.data);
_ROMEND = .;
/* Initialized data sections goes into CCMRAM, load LMA copy after code */
.data :
{
. = ALIGN(4);
_sdata = .; /* create a global symbol at data start */
*(.data) /* .data sections */
*(.data*) /* .data sections */
. = ALIGN(4);
_edata = .; /* define a global symbol at data end */
} >CCMRAM AT> FLASH
_ROMSIZE = _ROMEND - ORIGIN(FLASH) + _edata - _sdata;
_siccmram = ORIGIN(CCMRAM);
_sconfig = _ROMSIZE;
_econfig = _sconfig + 2K;
.bss :
{
/* This is used by the startup in order to initialize the .bss secion */
_sbss = .; /* define a global symbol at bss start */
__bss_start__ = _sbss;
*(.bss)
*(.bss*)
*(COMMON)
. = ALIGN(4);
_ebss = .; /* define a global symbol at bss end */
__bss_end__ = _ebss;
} >CCMRAM
/* RAM section
*/
/* Uninitialized data section */
.dummy :
{
. = ALIGN(4);
*(.dummy)
*(.dummy*)
. = ALIGN(4);
} > RAM AT > FLASH
.ram :
{
. = ALIGN(4);
_sram = .; /* create a global symbol at ccmram start */
*(.ram)
*(.ram*)
. = ALIGN(4);
_eram = .; /* create a global symbol at ccmram end */
} >RAM
/* User_heap_stack section, used to check that there is enough RAM left */
._user_heap_stack (NOLOAD):
{
. = ALIGN(8);
PROVIDE ( end = . );
PROVIDE ( _end = . );
. = . + _Min_Heap_Size;
. = . + _Min_Stack_Size;
. = ALIGN(8);
} >CCMRAM
/* Remove information from the standard libraries */
/DISCARD/ :
{
libc.a ( * )
libm.a ( * )
libgcc.a ( * )
}
.ARM.attributes 0 : { *(.ARM.attributes) }
}
MMU - 一些微控制器有内存管理单元,但通常此外设仅保护某些内存区域。由于您没有操作系统,因此也没有文件系统 - 因此不存在类似mmap的内容。
#define SRAM_BASE ((uint32_t)0x20000000)
它只是以人类可读的方式定义了某物的地址。在这种情况下,它可能只是SRAM内存开头的地址。另一个例子:
unsigned char *mem[10240];
is not probably typed as you'd want... Perhaps you meantunsigned char mem[10240];
- Antti Haapala -- Слава Україні