cyutils.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*******************************************************************************
  2. * FILENAME: cyutils.c
  3. * Version 4.0
  4. *
  5. * Description:
  6. * CyUtils provides function to handle 24-bit value writes.
  7. *
  8. ********************************************************************************
  9. * Copyright 2008-2013, Cypress Semiconductor Corporation. All rights reserved.
  10. * You may use this file only in accordance with the license, terms, conditions,
  11. * disclaimers, and limitations in the end user license agreement accompanying
  12. * the software package with which this file was provided.
  13. *******************************************************************************/
  14. #include "cytypes.h"
  15. #if (!CY_PSOC3)
  16. /***************************************************************************
  17. * Function Name: CySetReg24
  18. ****************************************************************************
  19. *
  20. * Summary:
  21. * Writes the 24-bit value to the specified register.
  22. *
  23. * Parameters:
  24. * addr : adress where data must be written
  25. * value: data that must be written
  26. *
  27. * Return:
  28. * None
  29. *
  30. * Reentrant:
  31. * No
  32. *
  33. ***************************************************************************/
  34. void CySetReg24(uint32 volatile * addr, uint32 value)
  35. {
  36. uint8 volatile *tmpAddr;
  37. tmpAddr = (uint8 volatile *) addr;
  38. tmpAddr[0u] = (uint8) value;
  39. tmpAddr[1u] = (uint8) (value >> 8u);
  40. tmpAddr[2u] = (uint8) (value >> 16u);
  41. }
  42. #if(CY_PSOC4)
  43. /***************************************************************************
  44. * Function Name: CyGetReg24
  45. ****************************************************************************
  46. *
  47. * Summary:
  48. * Reads the 24-bit value from the specified register.
  49. *
  50. * Parameters:
  51. * addr : adress where data must be read
  52. *
  53. * Return:
  54. * None
  55. *
  56. * Reentrant:
  57. * No
  58. *
  59. ***************************************************************************/
  60. uint32 CyGetReg24(uint32 const volatile * addr)
  61. {
  62. uint8 const volatile *tmpAddr;
  63. uint32 value;
  64. tmpAddr = (uint8 const volatile *) addr;
  65. value = (uint32) tmpAddr[0u];
  66. value |= ((uint32) tmpAddr[1u] << 8u );
  67. value |= ((uint32) tmpAddr[2u] << 16u);
  68. return(value);
  69. }
  70. #endif /*(CY_PSOC4)*/
  71. #endif /* (!CY_PSOC3) */
  72. /* [] END OF FILE */