hw_flash_data.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #include "board.h"
  2. #include "global.h"
  3. /**
  4. * 读取硬件参数保存部分,要求数据指针地址是4字节对齐
  5. *
  6. * @author lxz (2019/5/30/周四)
  7. *
  8. * @param data
  9. *
  10. * @return int
  11. */
  12. int hw_flash_data_read(uint32_t pos, void * data,uint32_t length)
  13. {
  14. st_flash_read(pos,(uint32_t *)data,length / 4);
  15. //hw_24cxx_read(pos,data,length);
  16. return length;
  17. }
  18. /**
  19. * 写入硬件参数部分,要求数据指针地址是4字节对齐
  20. *
  21. * @author lxz (2019/5/30/周四)
  22. *
  23. * @param data
  24. *
  25. * @return int
  26. */
  27. int hw_flash_data_write(uint32_t pos, void * data,uint32_t length)
  28. {
  29. //开始编写参数
  30. st_flash_write(pos, (uint32_t *)data, length / 4);
  31. //hw_24cxx_write(pos,data,length);
  32. return length;
  33. }
  34. /**
  35. *
  36. *
  37. * @author lxz
  38. *
  39. * @param pos
  40. */
  41. void hw_flash_data_erase(uint32_t pos)
  42. {
  43. st_flash_unlock();
  44. st_flash_erase_secotr(st_flash_addr_to_sector_no(pos));
  45. st_flash_lock();
  46. }
  47. /**
  48. * 检查指定的空间是否能写入
  49. *
  50. * @author lxz (2019/5/31/周五)
  51. *
  52. * @param pos 必须保证32字节对齐的地址
  53. * @param length
  54. *
  55. * @return int
  56. */
  57. int hw_flash_data_check_empty(uint32_t pos,uint32_t length)
  58. {
  59. length = (length + 3) / 4;
  60. while (length > 0)
  61. {
  62. if (st_flash_read_word(pos) != 0xFFFFFFFF)
  63. {
  64. break;
  65. }
  66. length--;
  67. pos+= 4;
  68. }
  69. return length;
  70. }
  71. void ManualSaveData(void)
  72. {
  73. hw_flash_data_erase(MANUAL_SAVE_ADDRESS);
  74. hw_flash_data_write(MANUAL_SAVE_ADDRESS,&user_datas[POWEROFF_SAVE_BLOCK_SIZE / 2],MANUAL_SAVE_BLOCK_SIZE);
  75. }
  76. void ManualReadData(void)
  77. {
  78. hw_flash_data_read(MANUAL_SAVE_ADDRESS, &user_datas[POWEROFF_SAVE_BLOCK_SIZE / 2],MANUAL_SAVE_BLOCK_SIZE);
  79. }