fal.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Copyright (c) 2006-2018, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2018-05-17 armink the first version
  9. */
  10. #include <fal.h>
  11. #include <rtdevice.h>
  12. #define DBG_TAG "FAL"
  13. #ifdef FAL_USING_DEBUG
  14. #define DBG_LVL DBG_LOG
  15. #else
  16. #define DBG_LVL DBG_WARNING
  17. #endif
  18. #include <rtdbg.h>
  19. static rt_uint8_t init_ok = 0;
  20. /**
  21. * FAL (Flash Abstraction Layer) initialization.
  22. * It will initialize all flash device and all flash partition.
  23. *
  24. * @return >= 0: partitions total number
  25. */
  26. int fal_init(void)
  27. {
  28. extern int fal_flash_init(void);
  29. extern int fal_partition_init(void);
  30. int result;
  31. /* initialize all flash device on FAL flash table */
  32. result = fal_flash_init();
  33. if (result < 0) {
  34. goto __exit;
  35. }
  36. /* initialize all flash partition on FAL partition table */
  37. result = fal_partition_init();
  38. __exit:
  39. if ((result > 0) && (!init_ok))
  40. {
  41. init_ok = 1;
  42. LOG_I("RT-Thread Flash Abstraction Layer initialize success.");
  43. }
  44. else if(result <= 0)
  45. {
  46. init_ok = 0;
  47. LOG_E("RT-Thread Flash Abstraction Layer initialize failed.");
  48. }
  49. return result;
  50. }
  51. /**
  52. * Check if the FAL is initialized successfully
  53. *
  54. * @return 0: not init or init failed; 1: init success
  55. */
  56. int fal_init_check(void)
  57. {
  58. return init_ok;
  59. }