当前位置:   article > 正文

ZigBee学习笔记_osal_nv_init()

osal_nv_init

新年过完了,又可以继续学习了,进度好慢那感觉,今天看哈osal_nv_init()函数,代码很简单如下,

  1. void osal_nv_init( void *p )
  2. {
  3. (void)p; // Suppress Lint warning.
  4. (void)initNV(); // Always returns TRUE after pages have been erased.
  5. }

明明没有用到参数,还给传递进来一个参数,不晓得在搞什么,其中重点函数式initNVIDIA()函数,

  1. static uint8 initNV( void )
  2. {
  3. osalNvPgHdr_t pgHdr;
  4. uint8 oldPg = OSAL_NV_PAGE_NULL;
  5. uint8 newPg = OSAL_NV_PAGE_NULL;
  6. uint8 findDups = FALSE;
  7. uint8 pg;
  8. pgRes = OSAL_NV_PAGE_NULL;
  9. for ( pg = OSAL_NV_PAGE_BEG; pg <= OSAL_NV_PAGE_END; pg++ )
  10. {
  11. HalFlashRead(pg, OSAL_NV_PAGE_HDR_OFFSET, (uint8 *)(&pgHdr), OSAL_NV_HDR_SIZE);
  12. if ( pgHdr.active == OSAL_NV_ERASED_ID )
  13. {
  14. if ( pgRes == OSAL_NV_PAGE_NULL )
  15. {
  16. pgRes = pg;
  17. }
  18. else
  19. {
  20. setPageUse( pg, TRUE );
  21. }
  22. }
  23. else // Page is active.
  24. {
  25. // If the page is not yet in use, it is the tgt of items from an xfer.
  26. if ( pgHdr.inUse == OSAL_NV_ERASED_ID )
  27. {
  28. newPg = pg;
  29. }
  30. // An Xfer from this page was in progress.
  31. else if ( pgHdr.xfer != OSAL_NV_ERASED_ID )
  32. {
  33. oldPg = pg;
  34. }
  35. }
  36. // Calculate page offset and lost bytes - any "old" item triggers an N^2 re-scan from start.
  37. if ( initPage( pg, OSAL_NV_ITEM_NULL, findDups ) != OSAL_NV_ITEM_NULL )
  38. {
  39. findDups = TRUE;
  40. pg = OSAL_NV_PAGE_BEG-1;
  41. continue;
  42. }
  43. } // for ( pg = OSAL_NV_PAGE_BEG; pg <= OSAL_NV_PAGE_END; pg++ )
  44. /* First the old page is erased, and then the new page is put into use.
  45. * So if a transfer was in progress, the new page will always not yet be
  46. * marked as in use, since that is the last step to ending a transfer.
  47. */
  48. if ( newPg != OSAL_NV_PAGE_NULL )
  49. {
  50. /* If there is already a fallow page reserved, keep it and put the newPg in use.
  51. * An unfinished compaction will finish to the new reserve page and the old page
  52. * will be erased and reserved.
  53. */
  54. if ( pgRes != OSAL_NV_PAGE_NULL )
  55. {
  56. setPageUse( newPg, TRUE );
  57. }
  58. /* If setting old page to 'xfer' failed or board reset before it was effected, there is no way
  59. * to know which page was the 'old page' - so just reset all NV pages to start clean.
  60. */
  61. else if ( oldPg != OSAL_N
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/数据可视化灵魂/article/detail/60611
推荐阅读
  

闽ICP备14008679号