本帖最后由 干簧管 于 2023-12-3 17:00 编辑
学习Ai-M61-32S的外设demo代码时发现每个例程前都有 bflb_device_get_by_name 来获得外设句柄
- gpio = bflb_device_get_by_name("gpio");
- i2c0 = bflb_device_get_by_name("i2c0");
- dma0_ch0 = bflb_device_get_by_name("dma0_ch0");
复制代码 于是感觉这个和 linux 中的of函数获取dts的属性有点类似,那么就来找找这个函数的具体实现吧
- >>>>drivers\lhal\config\bl602\device_table.c
- struct bflb_device_s *bflb_device_get_by_name(const char *name)
- {
- for (uint8_t i = 0; i < sizeof(bl616_device_table) / sizeof(bl616_device_table[0]); i++) {
- if (strcmp(bl616_device_table[i].name, name) == 0) {
- return &bl616_device_table[i];
- }
- }
- return NULL;
- }
复制代码 如上,函数中通过name查找 bflb_device_s 类型结构体 bl616_device_table 中的name字段,如果一致则返回其地址,然后这个bl616_device_table 就定义在这个文件上面,如下:含有name、reg_base 、irq_num 等字段,其中 reg_base 刚好和我们的硬件打交道,即外设物理地址
- struct bflb_device_s bl616_device_table[] = {
- { .name = "adc",
- .reg_base = AON_BASE,
- .irq_num = BL616_IRQ_GPADC_DMA,
- .idx = 0,
- .sub_idx = 0,
- .dev_type = BFLB_DEVICE_TYPE_ADC,
- .user_data = NULL },
- { .name = "dac",
- .reg_base = GLB_BASE,
- .irq_num = 0xff,
- .idx = 0,
- .sub_idx = 0,
- .dev_type = BFLB_DEVICE_TYPE_DAC,
- .user_data = NULL },
- { .name = "ef_ctrl",
- .reg_base = EF_CTRL_BASE,
- .irq_num = 0xff,
- .idx = 0,
- .sub_idx = 0,
- .dev_type = BFLB_DEVICE_TYPE_EF_CTRL,
- .user_data = NULL },
- { .name = "gpio",
- .reg_base = GLB_BASE,
- .irq_num = BL616_IRQ_GPIO_INT0,
- .idx = 0,
- .sub_idx = 0,
- .dev_type = BFLB_DEVICE_TYPE_GPIO,
- .user_data = NULL },
- { .name = "uart0",
- .reg_base = UART0_BASE,
- .irq_num = BL616_IRQ_UART0,
- .idx = 0,
- .dev_type = BFLB_DEVICE_TYPE_UART,
- .user_data = NULL },
- { .name = "uart1",
- .reg_base = UART1_BASE,
- .irq_num = BL616_IRQ_UART1,
- .idx = 1,
- .dev_type = BFLB_DEVICE_TYPE_UART,
- .user_data = NULL },
- { .name = "spi0",
- .reg_base = SPI_BASE,
- .irq_num = BL616_IRQ_SPI0,
- .idx = 0,
- .dev_type = BFLB_DEVICE_TYPE_SPI,
- .user_data = NULL },
- { .name = "pwm_v2_0",
- .reg_base = PWM_BASE,
- .irq_num = BL616_IRQ_PWM,
- .idx = 0,
- .sub_idx = 0,
- .dev_type = BFLB_DEVICE_TYPE_PWM,
- .user_data = NULL },
- { .name = "dma0_ch0",
- .reg_base = DMA_BASE + 1 * DMA_CHANNEL_OFFSET,
- .irq_num = BL616_IRQ_DMA0_ALL,
- .idx = 0,
- .sub_idx = 0,
- .dev_type = BFLB_DEVICE_TYPE_DMA,
- .user_data = NULL },
- { .name = "dma0_ch1",
- .reg_base = DMA_BASE + 2 * DMA_CHANNEL_OFFSET,
- .irq_num = BL616_IRQ_DMA0_ALL,
- .idx = 0,
- .sub_idx = 1,
- .dev_type = BFLB_DEVICE_TYPE_DMA,
- .user_data = NULL },
- { .name = "dma0_ch2",
- .reg_base = DMA_BASE + 3 * DMA_CHANNEL_OFFSET,
- .irq_num = BL616_IRQ_DMA0_ALL,
- .idx = 0,
- .sub_idx = 2,
- .dev_type = BFLB_DEVICE_TYPE_DMA,
- .user_data = NULL },
- { .name = "dma0_ch3",
- .reg_base = DMA_BASE + 4 * DMA_CHANNEL_OFFSET,
- .irq_num = BL616_IRQ_DMA0_ALL,
- .idx = 0,
- .sub_idx = 3,
- .dev_type = BFLB_DEVICE_TYPE_DMA,
- .user_data = NULL },
- { .name = "dma0_ch4",
- .reg_base = DMA_BASE + 5 * DMA_CHANNEL_OFFSET,
- .irq_num = BL616_IRQ_DMA0_ALL,
- .idx = 0,
- .sub_idx = 4,
- .dev_type = BFLB_DEVICE_TYPE_DMA,
- .user_data = NULL },
- { .name = "dma0_ch5",
- .reg_base = DMA_BASE + 6 * DMA_CHANNEL_OFFSET,
- .irq_num = BL616_IRQ_DMA0_ALL,
- .idx = 0,
- .sub_idx = 5,
- .dev_type = BFLB_DEVICE_TYPE_DMA,
- .user_data = NULL },
- { .name = "dma0_ch6",
- .reg_base = DMA_BASE + 7 * DMA_CHANNEL_OFFSET,
- .irq_num = BL616_IRQ_DMA0_ALL,
- .idx = 0,
- .sub_idx = 6,
- .dev_type = BFLB_DEVICE_TYPE_DMA,
- .user_data = NULL },
- { .name = "dma0_ch7",
- .reg_base = DMA_BASE + 8 * DMA_CHANNEL_OFFSET,
- .irq_num = BL616_IRQ_DMA0_ALL,
- .idx = 0,
- .sub_idx = 7,
- .dev_type = BFLB_DEVICE_TYPE_DMA,
- .user_data = NULL },
- { .name = "i2c0",
- .reg_base = I2C0_BASE,
- .irq_num = BL616_IRQ_I2C0,
- .idx = 0,
- .sub_idx = 0,
- .dev_type = BFLB_DEVICE_TYPE_I2C,
- .user_data = NULL },
- { .name = "i2c1",
- .reg_base = I2C1_BASE,
- .irq_num = BL616_IRQ_I2C1,
- .idx = 1,
- .sub_idx = 0,
- .dev_type = BFLB_DEVICE_TYPE_I2C,
- .user_data = NULL },
- { .name = "i2s0",
- .reg_base = I2S_BASE,
- .irq_num = BL616_IRQ_I2S,
- .idx = 0,
- .sub_idx = 0,
- .dev_type = BFLB_DEVICE_TYPE_I2S,
- .user_data = NULL },
- { .name = "timer0",
- .reg_base = TIMER_BASE,
- .irq_num = BL616_IRQ_TIMER0,
- .idx = 0,
- .sub_idx = 0,
- .dev_type = BFLB_DEVICE_TYPE_TIMER,
- .user_data = NULL },
- { .name = "timer1",
- .reg_base = TIMER_BASE,
- .irq_num = BL616_IRQ_TIMER1,
- .idx = 1,
- .sub_idx = 0,
- .dev_type = BFLB_DEVICE_TYPE_TIMER,
- .user_data = NULL },
- { .name = "rtc",
- .reg_base = HBN_BASE,
- .irq_num = BL616_IRQ_HBN_OUT0,
- .idx = 0,
- .sub_idx = 0,
- .dev_type = BFLB_DEVICE_TYPE_RTC,
- .user_data = NULL },
- { .name = "aes",
- .reg_base = SEC_ENG_BASE,
- .irq_num = 0xff,
- .idx = 0,
- .sub_idx = 0,
- .dev_type = BFLB_DEVICE_TYPE_AES,
- .user_data = NULL },
- { .name = "sha",
- .reg_base = SEC_ENG_BASE,
- .irq_num = 0xff,
- .idx = 0,
- .sub_idx = 0,
- .dev_type = BFLB_DEVICE_TYPE_SHA,
- .user_data = NULL },
- { .name = "trng",
- .reg_base = SEC_ENG_BASE,
- .irq_num = 0xff,
- .idx = 0,
- .sub_idx = 0,
- .dev_type = BFLB_DEVICE_TYPE_TRNG,
- .user_data = NULL },
- { .name = "pka",
- .reg_base = SEC_ENG_BASE,
- .irq_num = 0xff,
- .idx = 0,
- .sub_idx = 0,
- .dev_type = BFLB_DEVICE_TYPE_PKA,
- .user_data = NULL },
- { .name = "emac0",
- .reg_base = EMAC_BASE,
- .irq_num = BL616_IRQ_EMAC,
- .idx = 0,
- .sub_idx = 0,
- .dev_type = BFLB_DEVICE_TYPE_ETH,
- .user_data = NULL },
- { .name = "watchdog",
- .reg_base = TIMER_BASE,
- .irq_num = BL616_IRQ_WDG,
- .idx = 0,
- .sub_idx = 0,
- .dev_type = BFLB_DEVICE_TYPE_TIMER,
- .user_data = NULL },
- { .name = "cks",
- .reg_base = CKS_BASE,
- .irq_num = 0,
- .idx = 0,
- .sub_idx = 0,
- .dev_type = BFLB_DEVICE_TYPE_CKS,
- .user_data = NULL },
- { .name = "mjpeg",
- .reg_base = MJPEG_BASE,
- .irq_num = BL616_IRQ_MJPEG,
- .idx = 0,
- .sub_idx = 0,
- .dev_type = BFLB_DEVICE_TYPE_MJPEG,
- .user_data = NULL },
- { .name = "irrx",
- .reg_base = IR_BASE,
- .irq_num = BL616_IRQ_IRRX,
- .idx = 0,
- .sub_idx = 0,
- .dev_type = BFLB_DEVICE_TYPE_IR,
- .user_data = NULL },
- { .name = "cam0",
- .reg_base = DVP2AXI0_BASE,
- .irq_num = BL616_IRQ_DVP2BUS_INT0,
- .idx = 0,
- .sub_idx = 0,
- .dev_type = BFLB_DEVICE_TYPE_CAMERA,
- .user_data = NULL },
- { .name = "cam1",
- .reg_base = DVP2AXI1_BASE,
- .irq_num = BL616_IRQ_DVP2BUS_INT1,
- .idx = 0,
- .sub_idx = 0,
- .dev_type = BFLB_DEVICE_TYPE_CAMERA,
- .user_data = NULL },
- { .name = "auadc",
- .reg_base = AUADC_BASE,
- .irq_num = BL616_IRQ_AUADC,
- .idx = 0,
- .sub_idx = 0,
- .dev_type = BFLB_DEVICE_TYPE_AUDIOADC,
- .user_data = NULL },
- { .name = "audac",
- .reg_base = AUDAC_BASE,
- .irq_num = BL616_IRQ_AUDAC,
- .idx = 0,
- .sub_idx = 0,
- .dev_type = BFLB_DEVICE_TYPE_AUDIODAC,
- .user_data = NULL },
- { .name = "sdio2",
- .reg_base = SDU_BASE,
- .irq_num = BL616_IRQ_SDIO,
- .idx = 0,
- .sub_idx = 0,
- .dev_type = BFLB_DEVICE_TYPE_SDIO2,
- .user_data = NULL },
- { .name = "dbi",
- .reg_base = DBI_BASE,
- .irq_num = BL616_IRQ_DBI,
- .idx = 0,
- .sub_idx = 0,
- .dev_type = BFLB_DEVICE_TYPE_DBI,
- .user_data = NULL },
- { .name = "plfm_dma_ch0",
- .reg_base = PLFM_DMA_BASE,
- .irq_num = 0,
- .idx = 0,
- .sub_idx = 0,
- .dev_type = BFLB_DEVICE_TYPE_PLFMDMA,
- .user_data = NULL },
- { .name = "plfm_dma_ch1",
- .reg_base = PLFM_DMA_BASE,
- .irq_num = 0,
- .idx = 1,
- .sub_idx = 0,
- .dev_type = BFLB_DEVICE_TYPE_PLFMDMA,
- .user_data = NULL },
- { .name = "plfm_dma_ch2",
- .reg_base = PLFM_DMA_BASE,
- .irq_num = 0,
- .idx = 2,
- .sub_idx = 0,
- .dev_type = BFLB_DEVICE_TYPE_PLFMDMA,
- .user_data = NULL },
- { .name = "plfm_dma_ch3",
- .reg_base = PLFM_DMA_BASE,
- .irq_num = 0,
- .idx = 3,
- .sub_idx = 0,
- .dev_type = BFLB_DEVICE_TYPE_PLFMDMA,
- .user_data = NULL },
- { .name = "plfm_dma_ch4",
- .reg_base = PLFM_DMA_BASE,
- .irq_num = 0,
- .idx = 4,
- .sub_idx = 0,
- .dev_type = BFLB_DEVICE_TYPE_PLFMDMA,
- .user_data = NULL },
- };
复制代码 如下,reg_base 字段的宏定义在 XXX_memorymap.h 文件中进行了定义
- >>>>drivers\lhal\config\bl616\bl616_memorymap.h
- #define MCU_MISC_BASE ((uint32_t)0x20009000)
- #define L1C_BASE ((uint32_t)0x20009000)
- #define UART0_BASE ((uint32_t)0x2000a000)
- #define UART1_BASE ((uint32_t)0x2000a100)
- #define SPI_BASE ((uint32_t)0x2000a200)
- #define I2C0_BASE ((uint32_t)0x2000a300)
- #define PWM_BASE ((uint32_t)0x2000a400)
- #define TIMER_BASE ((uint32_t)0x2000a500)
复制代码 然后也可以通过id字段匹配。
最后请问下坛友,关于介绍芯片这些寄存器的spec文档哪里有下载呀?谢谢!
|