#include "sr_osal.h"
#include "fal.h"

#include <string.h>

static os_list_node_t fal_device_list = OS_LIST_INIT(fal_device_list);

int fal_flash_register(fal_flash_t *flash)
{
    if (flash == SR_NULL)  return SR_INVALID;
  
    SR_OsEnterCritical();

    os_list_add_tail(&fal_device_list, &flash->list);

    SR_OsExitCritical();

    return 0;
}

int fal_flash_unregister(fal_flash_t *flash)
{
    //暂不需要
    return -1;
}

fal_flash_t *fal_flash_find(const char *name)
{
    fal_flash_t *flash;

    SR_OsEnterCritical();

    os_list_for_each_entry(flash, &fal_device_list, fal_flash_t, list)
    {
        if (!strcmp(name, flash->name))
        {
            SR_OsExitCritical();
            return (fal_flash_t *)flash;
        }
    }

     SR_OsExitCritical();

    return SR_NULL;
}
