nvRamToFlash.c
上传用户:luoyougen
上传日期:2008-05-12
资源大小:23136k
文件大小:3k
源码类别:

VxWorks

开发平台:

C/C++

  1. /* nvRamToFlash.c - non-volatile RAM to FLASH memory routine mapping */
  2. /* Copyright 1994-1997 Wind River Systems, Inc. */
  3. #include "copyright_wrs.h"
  4. /*
  5. modification history
  6. --------------------
  7. 01d,04feb97,wlf  doc: more cleanup.
  8. 01c,14nov96,wlf  doc: cleanup.
  9. 01b,31jan96,dzb  added NV_BOOT_OFFSET and NV_RAM_SIZE checking.  Added EOS.
  10. 01a,08jan94,dzb  created.
  11. */
  12. /*
  13. DESCRIPTION
  14. This library contains non-volatile RAM manipulation routines for targets
  15. lacking non-volatile RAM, but that do have FLASH memory.  Read and write
  16. wrappers are provided for the FLASH memory routines sysFlashGet() and
  17. sysFlashSet().
  18. */
  19. /* includes */
  20. #include "drv/mem/memDev.h"
  21. #include "drv/mem/flashDev.h"
  22. /******************************************************************************
  23. *
  24. * sysNvRamGet - get the contents of non-volatile RAM
  25. *
  26. * This routine calls sysFlashGet() to copy the contents of flash memory
  27. * into a specified string.  The string is terminated with an EOS.
  28. *
  29. * NOTE: This routine uses flash memory, since there is no NVRAM on the IBM 
  30. * 403 EVB.
  31. *
  32. * RETURNS: The return value of sysFlashGet().
  33. *
  34. * SEE ALSO: sysNvRamSet(), sysFlashGet()
  35. */
  36. STATUS sysNvRamGet
  37.     (
  38.     char *string,    /* where to copy non-volatile RAM    */
  39.     int strLen,      /* maximum number of bytes to copy   */
  40.     int offset       /* byte offset into non-volatile RAM */
  41.     )
  42.     {
  43.     STATUS retVal;
  44.     offset += NV_BOOT_OFFSET;   /* boot line begins at <offset> = 0 */
  45.     if ((offset < 0) || (strLen < 0) || ((offset + strLen) > NV_RAM_SIZE))
  46.         return (ERROR);
  47.     retVal = sysFlashGet (string, strLen, (offset + NV_BOOT_SEGMENT));
  48.     string [strLen] = EOS;
  49.     return (retVal);
  50.     }
  51. /*******************************************************************************
  52. *
  53. * sysNvRamSet - write to non-volatile RAM
  54. *
  55. * This routine calls sysFlashSet() to copy a specified string into
  56. * flash memory.
  57. *
  58. * NOTE: This routine uses flash memory, since there is no NVRAM on the IBM 
  59. * 403 EVB.
  60. *
  61. * RETURNS: The return value of sysFlashSet().
  62. *
  63. * SEE ALSO: sysNvRamGet(), sysFlashSet()
  64. */
  65. STATUS sysNvRamSet
  66.     (
  67.     char *string,     /* string to be copied into non-volatile RAM */
  68.     int strLen,       /* maximum number of bytes to copy           */
  69.     int offset        /* byte offset into non-volatile RAM         */
  70.     )
  71.     {
  72.     offset += NV_BOOT_OFFSET;   /* boot line begins at <offset> = 0 */
  73.     if ((offset < 0) || (strLen < 0) || ((offset + strLen) > NV_RAM_SIZE))
  74.         return (ERROR);
  75.     return (sysFlashSet (string, strLen, NV_BOOT_SEGMENT, offset));
  76.     }