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

VxWorks

开发平台:

C/C++

  1. /* m48t18NvRam.c - non-volatile RAM library for m48t18 */
  2. /* Copyright 1984-1996 Wind River Systems, Inc. */
  3. #include "copyright_wrs.h"
  4. /*
  5. modification history
  6. --------------------
  7. 01b,25jan95,vin  made it generic for both I/O mapped as well as memory mapped.
  8. 01a,24jan95,kvk  created from 01d of nvRam.c.
  9. */
  10. /*
  11. DESCRIPTION
  12. This library contains routines to manipulate non-volatile RAM which is
  13. accessed as normal RAM (e.g. battery backed RAM).  Read and write routines
  14. are included.  All non-volatile RAM accesses are byte wide.
  15. The macro NV_RAM_ADRS must be defined to point to the first byte of
  16. non-volatile memory.  The macro NV_RAM_SIZE must be defined to provide parameter
  17. checking for sysNvRamSet() and sysNvRamGet().
  18. */
  19. /* local defines */
  20. #define NV_RAM_ADRS_MASK 0x0000FFFF
  21. /* forward declarations */
  22. #ifdef NV_RAM_IO_MAPPED
  23. static void m4818Read (char * string, int strLen, USHORT addr);
  24. static void m4818Write (char * string, int strLen, USHORT addr);
  25. #endif /* NV_RAM_IO_MAPPED */
  26. /******************************************************************************
  27. *
  28. * sysNvRamGet - get the contents of non-volatile RAM
  29. *
  30. * This routine copies the contents of non-volatile memory into a specified
  31. * string.  The string will be terminated with an EOS.
  32. *
  33. * RETURNS: OK, or ERROR if access is outside the non-volatile RAM range.
  34. *
  35. * SEE ALSO: sysNvRamSet()
  36. */
  37. STATUS sysNvRamGet
  38.     (
  39.     char *string,    /* where to copy non-volatile RAM    */
  40.     int strLen,      /* maximum number of bytes to copy   */
  41.     int offset       /* byte offset into non-volatile RAM */
  42.     )
  43.     {
  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. #ifdef NV_RAM_IO_MAPPED /* nvram is io mapped */
  48.     m4818Read (string, strLen,  (USHORT)((ULONG)(NV_RAM_ADRS + offset) & 
  49.  NV_RAM_ADRS_MASK));
  50. #else /* nvram is memory mapped */
  51.     
  52.     bcopyBytes (NV_RAM_ADRS + offset, string, strLen);
  53. #endif /* NV_RAM_IO_MAPPED */
  54.     string [strLen] = EOS;
  55.     return (OK);
  56.     }
  57. /*******************************************************************************
  58. *
  59. * sysNvRamSet - write to non-volatile RAM
  60. *
  61. * This routine copies a specified string into non-volatile RAM.
  62. *
  63. * RETURNS: OK, or ERROR if access is outside the non-volatile RAM range.
  64. *
  65. * SEE ALSO: sysNvRamGet()
  66. */
  67. STATUS sysNvRamSet
  68.     (
  69.     char *string,     /* string to be copied into non-volatile RAM */
  70.     int strLen,       /* maximum number of bytes to copy           */
  71.     int offset        /* byte offset into non-volatile RAM         */
  72.     )
  73.     {
  74.     offset += NV_BOOT_OFFSET;   /* boot line begins at <offset> = 0 */
  75.     if ((offset < 0) || (strLen < 0) || ((offset + strLen) > NV_RAM_SIZE))
  76.         return (ERROR);
  77. #ifdef NV_RAM_IO_MAPPED /* nvram is iomapped */
  78.     m4818Write (string, strLen, (USHORT)((ULONG)(NV_RAM_ADRS + offset) & 
  79.  NV_RAM_ADRS_MASK));
  80. #else /* nvram is memory mapped */
  81.     bcopyBytes (string, NV_RAM_ADRS + offset, strLen);
  82. #endif /* NV_RAM_IO_MAPPED */
  83.     return (OK);
  84.     }
  85. #ifdef NV_RAM_IO_MAPPED
  86. /*******************************************************************************
  87. *
  88. * m4818Read - read from I/O mapped non-volatile RAM
  89. *
  90. * This routine copies non-volatile RAM to a specified string.
  91. *
  92. * RETURNS: N/A
  93. *
  94. * NOMANUAL
  95. */
  96. static void m4818Read
  97.     (
  98.     char * string, /* string to copy to non-volatile RAM    */
  99.     int  strLen, /* maximum number of bytes to copy   */
  100.     USHORT  offset /* byte offset into non-volatile RAM */
  101.     )
  102.     {
  103.     int  ix;
  104.     for(ix = 0; ix < strLen; offset++, ix++)
  105. {
  106. sysOutByte (NV_RAM_LSB_REG, LSB(offset));
  107. sysOutByte (NV_RAM_MSB_REG, MSB(offset));
  108. *string++ = (char)sysInByte (NV_RAM_DAT_REG);
  109. }
  110.     }
  111. /*******************************************************************************
  112. *
  113. * m4818Write - Write to I/O mapped non-volatile RAM
  114. *
  115. * This routine copies a specified string to non-volatile RAM.
  116. *
  117. * RETURNS: N/A
  118. *
  119. * NOMANUAL
  120. */
  121. static void m4818Write
  122.     (
  123.     char * string, /* string to copy to non-volatile RAM    */
  124.     int  strLen, /* maximum number of bytes to copy   */
  125.     USHORT  offset /* byte offset into non-volatile RAM */
  126.     )
  127.     {
  128.     int  ix;
  129.     for(ix = 0; ix < strLen;  string++, offset++, ix++)
  130. {
  131. sysOutByte (NV_RAM_LSB_REG, LSB(offset));
  132. sysOutByte (NV_RAM_MSB_REG, MSB(offset));
  133. sysOutByte (NV_RAM_DAT_REG, *string);
  134. }
  135.     }
  136. #endif /* NV_RAM_IO_MAPPED */