CySpc.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*******************************************************************************
  2. * File Name: CySpc.c
  3. * Version 4.0
  4. *
  5. * Description:
  6. * Provides definitions for the System Performance Component API.
  7. * The SPC functions are not meant to be called directly by the user
  8. * application.
  9. *
  10. ********************************************************************************
  11. * Copyright 2008-2013, Cypress Semiconductor Corporation. All rights reserved.
  12. * You may use this file only in accordance with the license, terms, conditions,
  13. * disclaimers, and limitations in the end user license agreement accompanying
  14. * the software package with which this file was provided.
  15. *******************************************************************************/
  16. #if !defined(CY_BOOT_CYSPC_H)
  17. #define CY_BOOT_CYSPC_H
  18. #include "cytypes.h"
  19. #include "CyLib.h"
  20. #include "cydevice_trm.h"
  21. /***************************************
  22. * Global Variables
  23. ***************************************/
  24. extern uint8 SpcLockState;
  25. /***************************************
  26. * Function Prototypes
  27. ***************************************/
  28. void CySpcStart(void);
  29. void CySpcStop(void);
  30. uint8 CySpcReadData(uint8 buffer[], uint8 size);
  31. cystatus CySpcLoadMultiByte(uint8 array, uint16 address, const uint8 buffer[], uint8 size)\
  32. ;
  33. cystatus CySpcLoadRow(uint8 array, const uint8 buffer[], uint16 size);
  34. cystatus CySpcWriteRow(uint8 array, uint16 address, uint8 tempPolarity, uint8 tempMagnitude)\
  35. ;
  36. cystatus CySpcEraseSector(uint8 array, uint8 sectorNumber);
  37. cystatus CySpcGetTemp(uint8 numSamples);
  38. cystatus CySpcLock(void);
  39. void CySpcUnlock(void);
  40. /***************************************
  41. * API Constants
  42. ***************************************/
  43. #define CY_SPC_LOCKED (0x01u)
  44. #define CY_SPC_UNLOCKED (0x00u)
  45. /*******************************************************************************
  46. * The Array ID indicates the unique ID of the SONOS array being accessed:
  47. * - 0x00-0x3E : Flash Arrays
  48. * - 0x3F : Selects all Flash arrays simultaneously
  49. * - 0x40-0x7F : Embedded EEPROM Arrays
  50. *******************************************************************************/
  51. #define CY_SPC_FIRST_FLASH_ARRAYID (0x00u)
  52. #define CY_SPC_LAST_FLASH_ARRAYID (0x3Fu)
  53. #define CY_SPC_FIRST_EE_ARRAYID (0x40u)
  54. #define CY_SPC_LAST_EE_ARRAYID (0x7Fu)
  55. #define CY_SPC_STATUS_DATA_READY_MASK (0x01u)
  56. #define CY_SPC_STATUS_IDLE_MASK (0x02u)
  57. #define CY_SPC_STATUS_CODE_MASK (0xFCu)
  58. #define CY_SPC_STATUS_CODE_SHIFT (0x02u)
  59. /* Status codes for the SPC. */
  60. #define CY_SPC_STATUS_SUCCESS (0x00u) /* Operation Successful */
  61. #define CY_SPC_STATUS_INVALID_ARRAY_ID (0x01u) /* Invalid Array ID for given command */
  62. #define CY_SPC_STATUS_INVALID_2BYTEKEY (0x02u) /* Invalid 2-byte key */
  63. #define CY_SPC_STATUS_ARRAY_ASLEEP (0x03u) /* Addressed Array is Asleep */
  64. #define CY_SPC_STATUS_EXTERN_ACCESS (0x04u) /* External Access Failure (SPC is not in external access mode) */
  65. #define CY_SPC_STATUS_INVALID_NUMBER (0x05u) /* Invalid 'N' Value for given command */
  66. #define CY_SPC_STATUS_TEST_MODE (0x06u) /* Test Mode Failure (SPC is not in test mode) */
  67. #define CY_SPC_STATUS_ALG_CSUM (0x07u) /* Smart Write Algorithm Checksum Failure */
  68. #define CY_SPC_STATUS_PARAM_CSUM (0x08u) /* Smart Write Parameter Checksum Failure */
  69. #define CY_SPC_STATUS_PROTECTION (0x09u) /* Protection Check Failure */
  70. #define CY_SPC_STATUS_ADDRESS_PARAM (0x0Au) /* Invalid Address parameter for the given command */
  71. #define CY_SPC_STATUS_COMMAND_CODE (0x0Bu) /* Invalid Command Code */
  72. #define CY_SPC_STATUS_ROW_ID (0x0Cu) /* Invalid Row ID parameter for given command */
  73. #define CY_SPC_STATUS_TADC_INPUT (0x0Du) /* Invalid input value for Get Temp & Get ADC commands */
  74. #define CY_SPC_STATUS_BUSY (0xFFu) /* SPC is busy */
  75. #if(CY_PSOC5)
  76. /* Wait-state pipeline */
  77. #define CY_SPC_CPU_WAITPIPE_BYPASS ((uint32)0x01u)
  78. #endif /* (CY_PSOC5) */
  79. /***************************************
  80. * Registers
  81. ***************************************/
  82. /* SPC CPU Data Register */
  83. #define CY_SPC_CPU_DATA_REG (* (reg8 *) CYREG_SPC_CPU_DATA )
  84. #define CY_SPC_CPU_DATA_PTR ( (reg8 *) CYREG_SPC_CPU_DATA )
  85. /* SPC Status Register */
  86. #define CY_SPC_STATUS_REG (* (reg8 *) CYREG_SPC_SR )
  87. #define CY_SPC_STATUS_PTR ( (reg8 *) CYREG_SPC_SR )
  88. /* Active Power Mode Configuration Register 0 */
  89. #define CY_SPC_PM_ACT_REG (* (reg8 *) CYREG_PM_ACT_CFG0 )
  90. #define CY_SPC_PM_ACT_PTR ( (reg8 *) CYREG_PM_ACT_CFG0 )
  91. /* Standby Power Mode Configuration Register 0 */
  92. #define CY_SPC_PM_STBY_REG (* (reg8 *) CYREG_PM_STBY_CFG0 )
  93. #define CY_SPC_PM_STBY_PTR ( (reg8 *) CYREG_PM_STBY_CFG0 )
  94. #if(CY_PSOC5)
  95. /* Wait State Pipeline */
  96. #define CY_SPC_CPU_WAITPIPE_REG (* (reg32 *) CYREG_PANTHER_WAITPIPE )
  97. #define CY_SPC_CPU_WAITPIPE_PTR ( (reg32 *) CYREG_PANTHER_WAITPIPE )
  98. #endif /* (CY_PSOC5) */
  99. /***************************************
  100. * Macros
  101. ***************************************/
  102. #define CY_SPC_IDLE (0u != (CY_SPC_STATUS_REG & CY_SPC_STATUS_IDLE_MASK))
  103. #define CY_SPC_BUSY (0u == (CY_SPC_STATUS_REG & CY_SPC_STATUS_IDLE_MASK))
  104. #define CY_SPC_DATA_READY (0u != (CY_SPC_STATUS_REG & CY_SPC_STATUS_DATA_READY_MASK))
  105. /* SPC must be in idle state in order to obtain correct status */
  106. #define CY_SPC_READ_STATUS (CY_SPC_IDLE ? \
  107. ((uint8)(CY_SPC_STATUS_REG >> CY_SPC_STATUS_CODE_SHIFT)) : \
  108. ((uint8) CY_SPC_STATUS_BUSY))
  109. /*******************************************************************************
  110. * Following code are OBSOLETE and must not be used starting from cy_boot 3.0
  111. *******************************************************************************/
  112. #define FIRST_FLASH_ARRAYID (CY_SPC_FIRST_FLASH_ARRAYID)
  113. #define LAST_FLASH_ARRAYID (CY_SPC_LAST_FLASH_ARRAYID)
  114. #define FIRST_EE_ARRAYID (CY_SPC_FIRST_EE_ARRAYID)
  115. #define LAST_EE_ARRAYID (CY_SPC_LAST_EE_ARRAYID)
  116. #define SIZEOF_ECC_ROW (CYDEV_ECC_ROW_SIZE)
  117. #define SIZEOF_FLASH_ROW (CYDEV_FLS_ROW_SIZE)
  118. #define SIZEOF_EEPROM_ROW (CYDEV_EEPROM_ROW_SIZE)
  119. #endif /* (CY_BOOT_CYSPC_H) */
  120. /* [] END OF FILE */