示例#1
0
文件: dma.c 项目: bwbromley/clockTest
uint32_t dmanum_to_phys(int dmanum) {
	int array_size = sizeof(dma_offset) / sizeof(dma_offset[0]);
	if (dmanum >= array_size) {
		return 0;
	}
	return dma_offset[dmanum] + board_info_peripheral_base_addr();
}
/**
 * Map all devices into userspace memory.
 *
 * @param    ws2811  ws2811 instance pointer.
 *
 * @returns  0 on success, -1 otherwise.
 */
static int map_registers(ws2811_t *ws2811)
{
    ws2811_device_t *device = ws2811->device;
    uint32_t dma_addr = dmanum_to_phys(ws2811->dmanum);
    uint32_t base = board_info_peripheral_base_addr();

    if (!dma_addr)
    {
        return -1;
    }

    device->dma = mapmem(dma_addr, sizeof(dma_t));
    if (!device->dma)
    {
        return -1;
    }

    device->pwm = mapmem(PWM_OFFSET + base, sizeof(pwm_t));
    if (!device->pwm)
    {
        return -1;
    }

    device->gpio = mapmem(GPIO_OFFSET + base, sizeof(gpio_t));
    if (!device->gpio)
    {
        return -1;
    }

    device->cm_pwm = mapmem(CM_PWM_OFFSET + base, sizeof(cm_pwm_t));
    if (!device->cm_pwm)
    {
        return -1;
    }

    return 0;
}