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

VxWorks

开发平台:

C/C++

  1. /* nvRam.c - non-volatile RAM library */
  2. /* Copyright 1984-1996 Wind River Systems, Inc. */
  3. #include "copyright_wrs.h"
  4. /*
  5. modification history
  6. --------------------
  7. 01f,18jun96,wlf  doc: cleanup.
  8. 01e,24may96,wlf  doc: cleanup.
  9. 01d,28jan93,caf  made boot line begin at offset 0 (SPR #1933).
  10. 01c,02sep92,caf  changed nvRamLib.c to nvRam.c. changed NV_BOOT_LINE to
  11.  NV_RAM_ADRS.  tweaked documentation.
  12. 01b,29jun92,caf  changed bbRamLib.c to nvRamLib.c. tweaked documentation.
  13. 01a,26jun92,caf  derived from sysNvRamSet() and sysNvRamGet() in PortKit.
  14. */
  15. /*
  16. DESCRIPTION
  17. This library contains routines to manipulate non-volatile RAM which is
  18. accessed as normal RAM (e.g., battery backed RAM).  Read and write routines
  19. are included.  All non-volatile RAM accesses are byte wide.
  20. The macro NV_RAM_ADRS must be defined to point to the first byte of
  21. non-volatile memory.  The macro NV_RAM_SIZE must be defined to provide parameter
  22. checking for sysNvRamSet() and sysNvRamGet().
  23. */
  24. /******************************************************************************
  25. *
  26. * sysNvRamGet - get the contents of non-volatile RAM
  27. *
  28. * This routine copies the contents of non-volatile memory into a specified
  29. * string.  The string is terminated with an EOS.
  30. *
  31. * RETURNS: OK, or ERROR if access is outside the non-volatile RAM range.
  32. *
  33. * SEE ALSO: sysNvRamSet()
  34. */
  35. STATUS sysNvRamGet
  36.     (
  37.     char *string,    /* where to copy non-volatile RAM    */
  38.     int strLen,      /* maximum number of bytes to copy   */
  39.     int offset       /* byte offset into non-volatile RAM */
  40.     )
  41.     {
  42.     offset += NV_BOOT_OFFSET;   /* boot line begins at <offset> = 0 */
  43.     if ((offset < 0) || (strLen < 0) || ((offset + strLen) > NV_RAM_SIZE))
  44.         return (ERROR);
  45.     bcopyBytes (NV_RAM_ADRS + offset, string, strLen);
  46.     string [strLen] = EOS;
  47.     return (OK);
  48.     }
  49. /*******************************************************************************
  50. *
  51. * sysNvRamSet - write to non-volatile RAM
  52. *
  53. * This routine copies a specified string into non-volatile RAM.
  54. *
  55. * RETURNS: OK, or ERROR if access is outside the non-volatile RAM range.
  56. *
  57. * SEE ALSO: sysNvRamGet()
  58. */
  59. STATUS sysNvRamSet
  60.     (
  61.     char *string,     /* string to be copied into non-volatile RAM */
  62.     int strLen,       /* maximum number of bytes to copy           */
  63.     int offset        /* byte offset into non-volatile RAM         */
  64.     )
  65.     {
  66.     offset += NV_BOOT_OFFSET;   /* boot line begins at <offset> = 0 */
  67.     if ((offset < 0) || (strLen < 0) || ((offset + strLen) > NV_RAM_SIZE))
  68.         return (ERROR);
  69.     bcopyBytes (string, NV_RAM_ADRS + offset, strLen);
  70.     return (OK);
  71.     }