src/C/devices.c
uint8_t dev_enable_device(e_device_id  dev_id)
{
    if ( device_tab[dev_id].status == DEV_STATE_ENABLED) {
        /* remapping case, device has been previously mapped and enabled */
        return 0;
    }
    if (device_tab[dev_id].status != DEV_STATE_REGISTERED) {
        KERNLOG(DBG_ERR, "dev_enable_device(): device status is not DEV_REGISTERED\n");
        return 1;
    }

    /* Enable GPIOs if needed */
    dev_enable_gpio(dev_id);

    /* Enable associated IRQs */
    for (uint8_t i = 0; i < MIN(device_tab[dev_id].udev.irq_num, MAX_IRQS); ++i)
    {
        NVIC_EnableIRQ((uint32_t) device_tab[dev_id].udev.irqs[i].irq - 0x10);
        KERNLOG(DBG_INFO, "Enabled IRQ %x, for device %s\n",
            device_tab[dev_id].udev.irqs[i].irq,
            device_tab[dev_id].udev.name);
    }

    /* Enable device itself (RCC, etc.) */
    if (device_tab[dev_id].devinfo != NULL) {
        /* some device may not need an RCC line, like the SoC embedded flash. For
         * these devices, there is no need for clock line activation. In this
         * very case, rcc_enbr and rcc_enb are set to 0 in the json device tree */
        if (device_tab[dev_id].devinfo->rcc_enr != 0) {
            /* write enable bit is needed only in REGISTERED state */
            if (device_tab[dev_id].status == DEV_STATE_REGISTERED) {
                soc_devmap_enable_clock (device_tab[dev_id].devinfo);
            }
        }
        KERNLOG(DBG_INFO, "Enabled device %s\n", device_tab[dev_id].udev.name);
    }

    /* Device is not tagged as enabled */
    device_tab[dev_id].status = DEV_STATE_ENABLED;
    if (device_tab[dev_id].udev.map_mode == DEV_MAP_AUTO) {
        device_tab[dev_id].is_mapped = true;
    }
    return 0;
}
/*
** This function should be called by syscall sys_init(INIT_LOCK).
** This behavior:
** 1) forces user tasks to use this syscall, locking any future sys_init usage
** 2) enable all devices of the task at one single moment, at the end of init
*/
This function should be called by syscall sys_init(INIT_LOCK).
This behavior:
1) forces user tasks to use this syscall, locking any future sys_init usage
2) enable all devices of the task at one single moment, at the end of init
This function should be called by syscall sys_init ( INIT_LOCK ) . This behavior : 1 ) forces user tasks to use this syscall locking any future sys_init usage 2 ) enable all devices of the task at one single moment at the end of init
uint8_t dev_enable_device(e_device_id  dev_id)
{
    if ( device_tab[dev_id].status == DEV_STATE_ENABLED) {
        return 0;
    }
    if (device_tab[dev_id].status != DEV_STATE_REGISTERED) {
        KERNLOG(DBG_ERR, "dev_enable_device(): device status is not DEV_REGISTERED\n");
        return 1;
    }
    dev_enable_gpio(dev_id);
    for (uint8_t i = 0; i < MIN(device_tab[dev_id].udev.irq_num, MAX_IRQS); ++i)
    {
        NVIC_EnableIRQ((uint32_t) device_tab[dev_id].udev.irqs[i].irq - 0x10);
        KERNLOG(DBG_INFO, "Enabled IRQ %x, for device %s\n",
            device_tab[dev_id].udev.irqs[i].irq,
            device_tab[dev_id].udev.name);
    }
    if (device_tab[dev_id].devinfo != NULL) {
        if (device_tab[dev_id].devinfo->rcc_enr != 0) {
            if (device_tab[dev_id].status == DEV_STATE_REGISTERED) {
                soc_devmap_enable_clock (device_tab[dev_id].devinfo);
            }
        }
        KERNLOG(DBG_INFO, "Enabled device %s\n", device_tab[dev_id].udev.name);
    }
    device_tab[dev_id].status = DEV_STATE_ENABLED;
    if (device_tab[dev_id].udev.map_mode == DEV_MAP_AUTO) {
        device_tab[dev_id].is_mapped = true;
    }
    return 0;
}
uint8_t dev_enable_device ( e_device_id dev_id ) { if ( device_tab [ dev_id ] . status == DEV_STATE_ENABLED ) { return 0 ; } if ( device_tab [ dev_id ] . status != DEV_STATE_REGISTERED ) { KERNLOG ( DBG_ERR , " \n " ) ; return 1 ; } dev_enable_gpio ( dev_id ) ; for ( uint8_t i = 0 ; i < MIN ( device_tab [ dev_id ] . udev . irq_num , MAX_IRQS ) ; ++ i ) { NVIC_EnableIRQ ( ( uint32_t ) device_tab [ dev_id ] . udev . irqs [ i ] . irq - 0x10 ) ; KERNLOG ( DBG_INFO , " \n " , device_tab [ dev_id ] . udev . irqs [ i ] . irq , device_tab [ dev_id ] . udev . name ) ; } if ( device_tab [ dev_id ] . devinfo != NULL ) { if ( device_tab [ dev_id ] . devinfo -> rcc_enr != 0 ) { if ( device_tab [ dev_id ] . status == DEV_STATE_REGISTERED ) { soc_devmap_enable_clock ( device_tab [ dev_id ] . devinfo ) ; } } KERNLOG ( DBG_INFO , " \n " , device_tab [ dev_id ] . udev . name ) ; } device_tab [ dev_id ] . status = DEV_STATE_ENABLED ; if ( device_tab [ dev_id ] . udev . map_mode == DEV_MAP_AUTO ) { device_tab [ dev_id ] . is_mapped = true ; } return 0 ; }
This function should be called by syscall sys_init(INIT_LOCK).
This function should be called by syscall sys_init ( INIT_LOCK ) .
/* remapping case, device has been previously mapped and enabled */ /* Enable GPIOs if needed */ /* Enable associated IRQs */ /* Enable device itself (RCC, etc.) */ /* some device may not need an RCC line, like the SoC embedded flash. For
         * these devices, there is no need for clock line activation. In this
         * very case, rcc_enbr and rcc_enb are set to 0 in the json device tree */ /* write enable bit is needed only in REGISTERED state */ /* Device is not tagged as enabled */