Matrix653 内存块

更新时间:
2023-11-16
下载文档

Matrix653 内存块

本节将介绍 Matrix653 内存块的使用。Matrix653 支持 ARINC653 P2-4 规范中的 Memory Block 服务。分区应用可以使用此服务实现分区间的共享内存;也可以实现在分区中访问外设寄存器,从而在分区中实现外设驱动。分区应用中使用此服务,需要 BSP 预先注册相应的内存块。只有 BSP 注册过的内存块,才能被分区应用使用。 本节详细定义在 mx_memory_block.h 头文件中。

内存块相关 API

下表展示了内存块相关的 API:

API描述
mx_memory_block_register注册内存块

mx_memory_block_register()

  • 描述 注册内存块

  • 函数原型

RETURN_CODE_TYPE mx_memory_block_register (
        /*in */ MEMORY_BLOCK_NAME_TYPE      name,
        /*in */ MX_PHYS_ADDR_TYPE           phys_addr,
        /*in */ MX_PHYS_SIZE_TYPE           size);
  • 参数
输入/输出参数描述
[in]name内存块名称
[in]phys_addr内存块物理地址
[in]size内存块大小
  • 返回值 Matrix653 内核错误码

  • 注意事项

  • 示例

BSP 代码:

#define MX_CONFIG_BSP_MEM_BLOCK_BASE     (0x20000000)
#define MX_CONFIG_BSP_MEM_BLOCK_SIZE     (64 * MX_KB)

/*
 * _mx_hook_memory_block_init() is an OS hook function,
 * it's called by kernel after the memory block unit initialization.
 */
void _mx_hook_memory_block_init(void)
{
    mx_memory_block_register("test_mem_blcok", MX_CONFIG_BSP_MEM_BLOCK_BASE, MX_CONFIG_BSP_MEM_BLOCK_SIZE);
}
  • 分区使用示例

分区配置:

<Partition>
	<PartitionDefinition ... />
	<PartitionPeriodicity ... />
	<PartitionLimits ... />
	<MemoryRegions>
		...
	</MemoryRegions>
	<PartitionPorts>
		...
	</PartitionPorts>
	<MemoryBlocks>
		<MemoryBlock Name="test_mem_blcok" AccessRights="READ_WRITE" CacheSetting="Cache_Off"/>
	</MemoryBlocks>
</Partition>

分区代码:

int main(void)
{
    RETURN_CODE_TYPE          return_code;
    MEMORY_BLOCK_NAME_TYPE    memory_block_name = "test_mem_blcok";
    MEMORY_BLOCK_STATUS_TYPE  memory_block_status;

    GET_MEMORY_BLOCK_STATUS(memory_block_name, &memory_block_status, &return_code);
    if (return_code != NO_ERROR) {
        printf("GET_MEMORY_BLOCK_STATUS failed!\n");
        while (MX_TRUE) {
        }
    }
    printf("MEMORY_BLOCK_ADDR: 0x%x\n", (unsigned int)memory_block_status.MEMORY_BLOCK_ADDR);
    printf("MEMORY_BLOCK_SIZE: %d\n", memory_block_status.MEMORY_BLOCK_SIZE);
}
文档内容是否对您有所帮助?
有帮助
没帮助