\r
#include <string.h>\r
\r
-static const uint16_t FIRMWARE_VERSION = 0x0440;\r
+static const uint16_t FIRMWARE_VERSION = 0x0441;\r
\r
// 1 flash row\r
static const uint8_t DEFAULT_CONFIG[256] =\r
0x00,0x01, // Write delay time, in 100ms units\r
0x00, // Default gap size\r
0x10, // auto-generation of default eod (end of data)\r
-0x00,0x00,0x00 // buffer-size at early warning\r
+0x00,0x00,0x00, // buffer-size at early warning\r
0x00, // No data compression\r
0x00 // reserved\r
};\r
break;\r
\r
case CONFIG_MO:\r
- TODO\r
+ mediumType = 0x03; // Optical reversible or erasable medium\r
+ deviceSpecificParam =\r
+ (blockDev.state & DISK_WP) ? 0x80 : 0;\r
+ density = 0x00; // Default\r
break;\r
\r
};\r
-/*******************************************************************************
-* File Name: Bootloadable_1.c
-* Version 1.30
-*
-* Description:
-* Provides an API for the Bootloadable application. The API includes a
-* single function for starting the bootloader.
-*
-********************************************************************************
-* Copyright 2008-2014, Cypress Semiconductor Corporation. All rights reserved.
-* You may use this file only in accordance with the license, terms, conditions,
-* disclaimers, and limitations in the end user license agreement accompanying
-* the software package with which this file was provided.
-*******************************************************************************/
-
-#include "Bootloadable_1.h"
-
-
-/*******************************************************************************
-* Function Name: Bootloadable_1_Load
-********************************************************************************
-* Summary:
-* Begins the bootloading algorithm downloading a new ACD image from the host.
-*
-* Parameters:
-* None
-*
-* Returns:
-* This method will never return. It will load a new application and reset
-* the device.
-*
-*******************************************************************************/
-void Bootloadable_1_Load(void)
-{
- /* Schedule Bootloader to start after reset */
- Bootloadable_1_SET_RUN_TYPE(Bootloadable_1_START_BTLDR);
-
- CySoftwareReset();
-}
-
-
-/*******************************************************************************
-* The following code is OBSOLETE and must not be used.
-*******************************************************************************/
-void Bootloadable_1_SetFlashByte(uint32 address, uint8 runType)
-{
- uint32 flsAddr = address - CYDEV_FLASH_BASE;
- uint8 rowData[CYDEV_FLS_ROW_SIZE];
-
- #if !(CY_PSOC4)
- uint8 arrayId = ( uint8 )(flsAddr / CYDEV_FLS_SECTOR_SIZE);
- #endif /* !(CY_PSOC4) */
-
- #if (CY_PSOC4)
- uint16 rowNum = ( uint16 )(flsAddr / CYDEV_FLS_ROW_SIZE);
- #else
- uint16 rowNum = ( uint16 )((flsAddr % CYDEV_FLS_SECTOR_SIZE) / CYDEV_FLS_ROW_SIZE);
- #endif /* (CY_PSOC4) */
-
- uint32 baseAddr = address - (address % CYDEV_FLS_ROW_SIZE);
- uint16 idx;
-
-
- for (idx = 0u; idx < CYDEV_FLS_ROW_SIZE; idx++)
- {
- rowData[idx] = Bootloadable_1_GET_CODE_DATA(baseAddr + idx);
- }
- rowData[address % CYDEV_FLS_ROW_SIZE] = runType;
-
- #if(CY_PSOC4)
- (void) CySysFlashWriteRow((uint32) rowNum, rowData);
- #else
- (void) CyWriteRowData(arrayId, rowNum, rowData);
- #endif /* (CY_PSOC4) */
-
- #if(CY_PSOC5)
- /***************************************************************************
- * When writing Flash, data in the instruction cache can become stale.
- * Therefore, the cache data does not correlate to the data just written to
- * Flash. A call to CyFlushCache() is required to invalidate the data in the
- * cache and force fresh information to be loaded from Flash.
- ***************************************************************************/
- CyFlushCache();
- #endif /* (CY_PSOC5) */
-}
-
-
-/* [] END OF FILE */
+/*******************************************************************************\r
+* File Name: Bootloadable_1.c\r
+* Version 1.30\r
+*\r
+* Description:\r
+* Provides an API for the Bootloadable application. The API includes a\r
+* single function for starting the bootloader.\r
+*\r
+********************************************************************************\r
+* Copyright 2008-2014, Cypress Semiconductor Corporation. All rights reserved.\r
+* You may use this file only in accordance with the license, terms, conditions,\r
+* disclaimers, and limitations in the end user license agreement accompanying\r
+* the software package with which this file was provided.\r
+*******************************************************************************/\r
+\r
+#include "Bootloadable_1.h"\r
+\r
+\r
+/*******************************************************************************\r
+* Function Name: Bootloadable_1_Load\r
+********************************************************************************\r
+* Summary:\r
+* Begins the bootloading algorithm downloading a new ACD image from the host.\r
+*\r
+* Parameters:\r
+* None\r
+*\r
+* Returns:\r
+* This method will never return. It will load a new application and reset\r
+* the device.\r
+*\r
+*******************************************************************************/\r
+void Bootloadable_1_Load(void) \r
+{\r
+ /* Schedule Bootloader to start after reset */\r
+ Bootloadable_1_SET_RUN_TYPE(Bootloadable_1_START_BTLDR);\r
+\r
+ CySoftwareReset();\r
+}\r
+\r
+\r
+/*******************************************************************************\r
+* The following code is OBSOLETE and must not be used.\r
+*******************************************************************************/\r
+void Bootloadable_1_SetFlashByte(uint32 address, uint8 runType) \r
+{\r
+ uint32 flsAddr = address - CYDEV_FLASH_BASE;\r
+ uint8 rowData[CYDEV_FLS_ROW_SIZE];\r
+\r
+ #if !(CY_PSOC4)\r
+ uint8 arrayId = ( uint8 )(flsAddr / CYDEV_FLS_SECTOR_SIZE);\r
+ #endif /* !(CY_PSOC4) */\r
+\r
+ #if (CY_PSOC4)\r
+ uint16 rowNum = ( uint16 )(flsAddr / CYDEV_FLS_ROW_SIZE);\r
+ #else\r
+ uint16 rowNum = ( uint16 )((flsAddr % CYDEV_FLS_SECTOR_SIZE) / CYDEV_FLS_ROW_SIZE);\r
+ #endif /* (CY_PSOC4) */\r
+\r
+ uint32 baseAddr = address - (address % CYDEV_FLS_ROW_SIZE);\r
+ uint16 idx;\r
+\r
+\r
+ for (idx = 0u; idx < CYDEV_FLS_ROW_SIZE; idx++)\r
+ {\r
+ rowData[idx] = Bootloadable_1_GET_CODE_DATA(baseAddr + idx);\r
+ }\r
+ rowData[address % CYDEV_FLS_ROW_SIZE] = runType;\r
+\r
+ #if(CY_PSOC4)\r
+ (void) CySysFlashWriteRow((uint32) rowNum, rowData);\r
+ #else\r
+ (void) CyWriteRowData(arrayId, rowNum, rowData);\r
+ #endif /* (CY_PSOC4) */\r
+\r
+ #if(CY_PSOC5)\r
+ /***************************************************************************\r
+ * When writing Flash, data in the instruction cache can become stale.\r
+ * Therefore, the cache data does not correlate to the data just written to\r
+ * Flash. A call to CyFlushCache() is required to invalidate the data in the\r
+ * cache and force fresh information to be loaded from Flash.\r
+ ***************************************************************************/\r
+ CyFlushCache();\r
+ #endif /* (CY_PSOC5) */\r
+}\r
+\r
+\r
+/* [] END OF FILE */\r
-/*******************************************************************************
-* File Name: Bootloadable_1.h
-* Version 1.30
-*
-* Description:
-* Provides an API for the Bootloadable application. The API includes a
-* single function for starting bootloader.
-*
-********************************************************************************
-* Copyright 2008-2014, Cypress Semiconductor Corporation. All rights reserved.
-* You may use this file only in accordance with the license, terms, conditions,
-* disclaimers, and limitations in the end user license agreement accompanying
-* the software package with which this file was provided.
-********************************************************************************/
-
-
-#ifndef CY_BOOTLOADABLE_Bootloadable_1_H
-#define CY_BOOTLOADABLE_Bootloadable_1_H
-
-#include "cydevice_trm.h"
-#include "CyFlash.h"
-
-
-/* Check to see if required defines such as CY_PSOC5LP are available */
-/* They are defined starting with cy_boot v3.0 */
-#if !defined (CY_PSOC5LP)
- #error Component Bootloadable_v1_30 requires cy_boot v3.0 or later
-#endif /* !defined (CY_PSOC5LP) */
-
-
-#ifndef CYDEV_FLASH_BASE
- #define CYDEV_FLASH_BASE CYDEV_FLS_BASE
- #define CYDEV_FLASH_SIZE CYDEV_FLS_SIZE
-#endif /* CYDEV_FLASH_BASE */
-
-#if(CY_PSOC3)
- #define Bootloadable_1_GET_CODE_DATA(idx) (*((uint8 CYCODE *) (idx)))
-#else
- #define Bootloadable_1_GET_CODE_DATA(idx) (*((uint8 *)(CYDEV_FLASH_BASE + (idx))))
-#endif /* (CY_PSOC3) */
-
-
-/*******************************************************************************
-* This variable is used by Bootloader/Bootloadable components to schedule what
-* application will be started after software reset.
-*******************************************************************************/
-#if (CY_PSOC4)
- #if defined(__ARMCC_VERSION)
- __attribute__ ((section(".bootloaderruntype"), zero_init))
- #elif defined (__GNUC__)
- __attribute__ ((section(".bootloaderruntype")))
- #elif defined (__ICCARM__)
- #pragma location=".bootloaderruntype"
- #endif /* defined(__ARMCC_VERSION) */
- extern volatile uint32 cyBtldrRunType;
-#endif /* (CY_PSOC4) */
-
-
-/*******************************************************************************
-* Get the reason of the device reset
-*******************************************************************************/
-#if(CY_PSOC4)
- #define Bootloadable_1_RES_CAUSE_RESET_SOFT (0x10u)
- #define Bootloadable_1_GET_RUN_TYPE \
- (((CY_GET_REG32(CYREG_RES_CAUSE) & Bootloadable_1_RES_CAUSE_RESET_SOFT) > 0u) \
- ? (cyBtldrRunType) \
- : 0u)
-#else
- #define Bootloadable_1_GET_RUN_TYPE (CY_GET_REG8(CYREG_RESET_SR0) & \
- (Bootloadable_1_START_BTLDR | Bootloadable_1_START_APP))
-#endif /* (CY_PSOC4) */
-
-
-/*******************************************************************************
-* Schedule Bootloader/Bootloadable to be run after software reset
-*******************************************************************************/
-#if(CY_PSOC4)
- #define Bootloadable_1_SET_RUN_TYPE(x) (cyBtldrRunType = (x))
-#else
- #define Bootloadable_1_SET_RUN_TYPE(x) CY_SET_REG8(CYREG_RESET_SR0, (x))
-#endif /* (CY_PSOC4) */
-
-
-
-/***************************************
-* Function Prototypes
-***************************************/
-extern void Bootloadable_1_Load(void) ;
-
-
-/*******************************************************************************
-* The following code is OBSOLETE and must not be used starting from version 1.10
-*******************************************************************************/
-#define CYBTDLR_SET_RUN_TYPE(x) Bootloadable_1_SET_RUN_TYPE(x)
-
-
-/*******************************************************************************
-* The following code is OBSOLETE and must not be used starting from version 1.20
-*******************************************************************************/
-#define Bootloadable_1_START_APP (0x80u)
-#define Bootloadable_1_START_BTLDR (0x40u)
-#define Bootloadable_1_META_DATA_SIZE (64u)
-#define Bootloadable_1_META_APP_CHECKSUM_OFFSET (0u)
-
-#if(CY_PSOC3)
-
- #define Bootloadable_1_APP_ADDRESS uint16
- #define Bootloadable_1_GET_CODE_WORD(idx) (*((uint32 CYCODE *) (idx)))
-
- /* Offset by 2 from 32 bit start because only need 16 bits */
- #define Bootloadable_1_META_APP_ADDR_OFFSET (3u)
- #define Bootloadable_1_META_APP_BL_LAST_ROW_OFFSET (7u)
- #define Bootloadable_1_META_APP_BYTE_LEN_OFFSET (11u)
- #define Bootloadable_1_META_APP_RUN_TYPE_OFFSET (15u)
-
-#else
-
- #define Bootloadable_1_APP_ADDRESS uint32
- #define Bootloadable_1_GET_CODE_WORD(idx) (*((uint32 *)(CYDEV_FLASH_BASE + (idx))))
-
- #define Bootloadable_1_META_APP_ADDR_OFFSET (1u)
- #define Bootloadable_1_META_APP_BL_LAST_ROW_OFFSET (5u)
- #define Bootloadable_1_META_APP_BYTE_LEN_OFFSET (9u)
- #define Bootloadable_1_META_APP_RUN_TYPE_OFFSET (13u)
-
-#endif /* (CY_PSOC3) */
-
-#define Bootloadable_1_META_APP_ACTIVE_OFFSET (16u)
-#define Bootloadable_1_META_APP_VERIFIED_OFFSET (17u)
-
-#define Bootloadable_1_META_APP_BL_BUILD_VER_OFFSET (18u)
-#define Bootloadable_1_META_APP_ID_OFFSET (20u)
-#define Bootloadable_1_META_APP_VER_OFFSET (22u)
-#define Bootloadable_1_META_APP_CUST_ID_OFFSET (24u)
-
-#define Bootloadable_1_SetFlashRunType(runType) \
- Bootloadable_1_SetFlashByte(Bootloadable_1_MD_APP_RUN_ADDR(0), (runType))
-
-
-/*******************************************************************************
-* The following code is OBSOLETE and must not be used.
-*
-* If the obsoleted macro definitions intended for use in the application use the
-* following scheme, redefine your own versions of these definitions:
-* #ifdef <OBSOLETED_DEFINE>
-* #undef <OBSOLETED_DEFINE>
-* #define <OBSOLETED_DEFINE> (<New Value>)
-* #endif
-*
-* Note: Redefine obsoleted macro definitions with caution. They might still be
-* used in the application and their modification might lead to unexpected
-* consequences.
-*******************************************************************************/
-void Bootloadable_1_SetFlashByte(uint32 address, uint8 runType) ;
-#if(CY_PSOC4)
- #define Bootloadable_1_SOFTWARE_RESET CySoftwareReset()
-#else
- #define Bootloadable_1_SOFTWARE_RESET CySoftwareReset()
-#endif /* (CY_PSOC4) */
-
-#if(CY_PSOC4)
- extern uint8 appRunType;
-#endif /* (CY_PSOC4) */
-
-
-#endif /* CY_BOOTLOADABLE_Bootloadable_1_H */
-
-
-/* [] END OF FILE */
+/*******************************************************************************\r
+* File Name: Bootloadable_1.h\r
+* Version 1.30\r
+*\r
+* Description:\r
+* Provides an API for the Bootloadable application. The API includes a\r
+* single function for starting bootloader.\r
+*\r
+********************************************************************************\r
+* Copyright 2008-2014, Cypress Semiconductor Corporation. All rights reserved.\r
+* You may use this file only in accordance with the license, terms, conditions,\r
+* disclaimers, and limitations in the end user license agreement accompanying\r
+* the software package with which this file was provided.\r
+********************************************************************************/\r
+\r
+\r
+#ifndef CY_BOOTLOADABLE_Bootloadable_1_H\r
+#define CY_BOOTLOADABLE_Bootloadable_1_H\r
+\r
+#include "cydevice_trm.h"\r
+#include "CyFlash.h"\r
+\r
+\r
+/* Check to see if required defines such as CY_PSOC5LP are available */\r
+/* They are defined starting with cy_boot v3.0 */\r
+#if !defined (CY_PSOC5LP)\r
+ #error Component Bootloadable_v1_30 requires cy_boot v3.0 or later\r
+#endif /* !defined (CY_PSOC5LP) */\r
+\r
+\r
+#ifndef CYDEV_FLASH_BASE\r
+ #define CYDEV_FLASH_BASE CYDEV_FLS_BASE\r
+ #define CYDEV_FLASH_SIZE CYDEV_FLS_SIZE\r
+#endif /* CYDEV_FLASH_BASE */\r
+\r
+#if(CY_PSOC3)\r
+ #define Bootloadable_1_GET_CODE_DATA(idx) (*((uint8 CYCODE *) (idx)))\r
+#else\r
+ #define Bootloadable_1_GET_CODE_DATA(idx) (*((uint8 *)(CYDEV_FLASH_BASE + (idx))))\r
+#endif /* (CY_PSOC3) */\r
+\r
+\r
+/*******************************************************************************\r
+* This variable is used by Bootloader/Bootloadable components to schedule what\r
+* application will be started after software reset.\r
+*******************************************************************************/\r
+#if (CY_PSOC4)\r
+ #if defined(__ARMCC_VERSION)\r
+ __attribute__ ((section(".bootloaderruntype"), zero_init))\r
+ #elif defined (__GNUC__)\r
+ __attribute__ ((section(".bootloaderruntype")))\r
+ #elif defined (__ICCARM__)\r
+ #pragma location=".bootloaderruntype"\r
+ #endif /* defined(__ARMCC_VERSION) */\r
+ extern volatile uint32 cyBtldrRunType;\r
+#endif /* (CY_PSOC4) */\r
+\r
+\r
+/*******************************************************************************\r
+* Get the reason of the device reset\r
+*******************************************************************************/\r
+#if(CY_PSOC4)\r
+ #define Bootloadable_1_RES_CAUSE_RESET_SOFT (0x10u)\r
+ #define Bootloadable_1_GET_RUN_TYPE \\r
+ (((CY_GET_REG32(CYREG_RES_CAUSE) & Bootloadable_1_RES_CAUSE_RESET_SOFT) > 0u) \\r
+ ? (cyBtldrRunType) \\r
+ : 0u)\r
+#else\r
+ #define Bootloadable_1_GET_RUN_TYPE (CY_GET_REG8(CYREG_RESET_SR0) & \\r
+ (Bootloadable_1_START_BTLDR | Bootloadable_1_START_APP))\r
+#endif /* (CY_PSOC4) */\r
+\r
+\r
+/*******************************************************************************\r
+* Schedule Bootloader/Bootloadable to be run after software reset\r
+*******************************************************************************/\r
+#if(CY_PSOC4)\r
+ #define Bootloadable_1_SET_RUN_TYPE(x) (cyBtldrRunType = (x))\r
+#else\r
+ #define Bootloadable_1_SET_RUN_TYPE(x) CY_SET_REG8(CYREG_RESET_SR0, (x))\r
+#endif /* (CY_PSOC4) */\r
+\r
+\r
+\r
+/***************************************\r
+* Function Prototypes\r
+***************************************/\r
+extern void Bootloadable_1_Load(void) ;\r
+\r
+\r
+/*******************************************************************************\r
+* The following code is OBSOLETE and must not be used starting from version 1.10\r
+*******************************************************************************/\r
+#define CYBTDLR_SET_RUN_TYPE(x) Bootloadable_1_SET_RUN_TYPE(x)\r
+\r
+\r
+/*******************************************************************************\r
+* The following code is OBSOLETE and must not be used starting from version 1.20\r
+*******************************************************************************/\r
+#define Bootloadable_1_START_APP (0x80u)\r
+#define Bootloadable_1_START_BTLDR (0x40u)\r
+#define Bootloadable_1_META_DATA_SIZE (64u)\r
+#define Bootloadable_1_META_APP_CHECKSUM_OFFSET (0u)\r
+\r
+#if(CY_PSOC3)\r
+\r
+ #define Bootloadable_1_APP_ADDRESS uint16\r
+ #define Bootloadable_1_GET_CODE_WORD(idx) (*((uint32 CYCODE *) (idx)))\r
+\r
+ /* Offset by 2 from 32 bit start because only need 16 bits */\r
+ #define Bootloadable_1_META_APP_ADDR_OFFSET (3u)\r
+ #define Bootloadable_1_META_APP_BL_LAST_ROW_OFFSET (7u)\r
+ #define Bootloadable_1_META_APP_BYTE_LEN_OFFSET (11u)\r
+ #define Bootloadable_1_META_APP_RUN_TYPE_OFFSET (15u)\r
+\r
+#else\r
+\r
+ #define Bootloadable_1_APP_ADDRESS uint32\r
+ #define Bootloadable_1_GET_CODE_WORD(idx) (*((uint32 *)(CYDEV_FLASH_BASE + (idx))))\r
+\r
+ #define Bootloadable_1_META_APP_ADDR_OFFSET (1u)\r
+ #define Bootloadable_1_META_APP_BL_LAST_ROW_OFFSET (5u)\r
+ #define Bootloadable_1_META_APP_BYTE_LEN_OFFSET (9u)\r
+ #define Bootloadable_1_META_APP_RUN_TYPE_OFFSET (13u)\r
+\r
+#endif /* (CY_PSOC3) */\r
+\r
+#define Bootloadable_1_META_APP_ACTIVE_OFFSET (16u)\r
+#define Bootloadable_1_META_APP_VERIFIED_OFFSET (17u)\r
+\r
+#define Bootloadable_1_META_APP_BL_BUILD_VER_OFFSET (18u)\r
+#define Bootloadable_1_META_APP_ID_OFFSET (20u)\r
+#define Bootloadable_1_META_APP_VER_OFFSET (22u)\r
+#define Bootloadable_1_META_APP_CUST_ID_OFFSET (24u)\r
+\r
+#define Bootloadable_1_SetFlashRunType(runType) \\r
+ Bootloadable_1_SetFlashByte(Bootloadable_1_MD_APP_RUN_ADDR(0), (runType))\r
+\r
+\r
+/*******************************************************************************\r
+* The following code is OBSOLETE and must not be used.\r
+*\r
+* If the obsoleted macro definitions intended for use in the application use the\r
+* following scheme, redefine your own versions of these definitions:\r
+* #ifdef <OBSOLETED_DEFINE>\r
+* #undef <OBSOLETED_DEFINE>\r
+* #define <OBSOLETED_DEFINE> (<New Value>)\r
+* #endif\r
+*\r
+* Note: Redefine obsoleted macro definitions with caution. They might still be\r
+* used in the application and their modification might lead to unexpected\r
+* consequences.\r
+*******************************************************************************/\r
+void Bootloadable_1_SetFlashByte(uint32 address, uint8 runType) ;\r
+#if(CY_PSOC4)\r
+ #define Bootloadable_1_SOFTWARE_RESET CySoftwareReset()\r
+#else\r
+ #define Bootloadable_1_SOFTWARE_RESET CySoftwareReset()\r
+#endif /* (CY_PSOC4) */\r
+\r
+#if(CY_PSOC4)\r
+ extern uint8 appRunType;\r
+#endif /* (CY_PSOC4) */\r
+\r
+\r
+#endif /* CY_BOOTLOADABLE_Bootloadable_1_H */\r
+\r
+\r
+/* [] END OF FILE */\r
-/*******************************************************************************
-* File Name: CFG_EEPROM.c
-* Version 3.0
-*
-* Description:
-* Provides the source code to the API for the EEPROM component.
-*
-********************************************************************************
-* Copyright 2008-2015, Cypress Semiconductor Corporation. All rights reserved.
-* You may use this file only in accordance with the license, terms, conditions,
-* disclaimers, and limitations in the end user license agreement accompanying
-* the software package with which this file was provided.
-*******************************************************************************/
-
-#include "CFG_EEPROM.h"
-
-
-/*******************************************************************************
-* Function Name: CFG_EEPROM_Enable
-********************************************************************************
-*
-* Summary:
-* Enable the EEPROM block. Also reads the temperature and stores it for
-* future writes.
-*
-* Parameters:
-* None
-*
-* Return:
-* None
-*
-*******************************************************************************/
-void CFG_EEPROM_Enable(void)
-{
- /* Read temperature value */
- (void)CySetTemp();
-
- /* Start EEPROM block */
- CyEEPROM_Start();
-}
-
-
-/*******************************************************************************
-* Function Name: CFG_EEPROM_Start
-********************************************************************************
-*
-* Summary:
-* Starts EEPROM.
-*
-* Parameters:
-* None
-*
-* Return:
-* None
-*
-*******************************************************************************/
-void CFG_EEPROM_Start(void)
-{
- CFG_EEPROM_Enable();
-}
-
-
-/*******************************************************************************
-* Function Name: CFG_EEPROM_Stop
-********************************************************************************
-*
-* Summary:
-* Stops and powers down EEPROM.
-*
-* Parameters:
-* None
-*
-* Return:
-* None
-*
-*******************************************************************************/
-void CFG_EEPROM_Stop (void)
-{
- /* Stop and power down EEPROM block */
- CyEEPROM_Stop();
-}
-
-
-/*******************************************************************************
-* Function Name: CFG_EEPROM_WriteByte
-********************************************************************************
-*
-* Summary:
-* Writes a byte of data to the EEPROM. This function blocks until
-* the function is complete. For a reliable write procedure to occur you should
-* call CFG_EEPROM_UpdateTemperature() function if the temperature of the
-* silicon has been changed for more than 10C since the component was started.
-*
-* Parameters:
-* dataByte: The byte of data to write to the EEPROM
-* address: The address of data to be written. The maximum address is dependent
-* on the EEPROM size.
-*
-* Return:
-* CYRET_SUCCESS, if the operation was successful.
-* CYRET_BAD_PARAM, if the parameter sectorNumber is out of range.
-* CYRET_LOCKED, if the SPC is being used.
-* CYRET_UNKNOWN, if there was an SPC error.
-*
-*******************************************************************************/
-cystatus CFG_EEPROM_WriteByte(uint8 dataByte, uint16 address)
-{
- cystatus status;
- uint16 rowNumber;
- uint16 byteNumber;
-
- CySpcStart();
-
- if (address < CY_EEPROM_SIZE)
- {
- rowNumber = address/(uint16)CY_EEPROM_SIZEOF_ROW;
- byteNumber = address - (rowNumber * ((uint16)CY_EEPROM_SIZEOF_ROW));
- if(CYRET_SUCCESS == CySpcLock())
- {
- status = CySpcLoadMultiByte(CY_SPC_FIRST_EE_ARRAYID, byteNumber, &dataByte, \
- CFG_EEPROM_SPC_BYTE_WRITE_SIZE);
- if (CYRET_STARTED == status)
- {
- /* Plan for failure */
- status = CYRET_UNKNOWN;
-
- while(CY_SPC_BUSY)
- {
- /* Wait until SPC becomes idle */
- }
-
- if(CY_SPC_STATUS_SUCCESS == CY_SPC_READ_STATUS)
- {
- status = CYRET_SUCCESS;
- }
- /* Command to erase and program the row. */
- if(CYRET_SUCCESS == status)
- {
- if(CySpcWriteRow(CY_SPC_FIRST_EE_ARRAYID, (uint16)rowNumber, dieTemperature[0u],
- dieTemperature[1u]) == CYRET_STARTED)
- {
- /* Plan for failure */
- status = CYRET_UNKNOWN;
-
- while(CY_SPC_BUSY)
- {
- /* Wait until SPC becomes idle */
- }
-
- /* SPC is idle now */
- if(CY_SPC_STATUS_SUCCESS == CY_SPC_READ_STATUS)
- {
- status = CYRET_SUCCESS;
- }
- }
- else
- {
- status = CYRET_UNKNOWN;
- }
- }
- else
- {
- status = CYRET_UNKNOWN;
- }
- }
- else
- {
- if (CYRET_BAD_PARAM != status)
- {
- status = CYRET_UNKNOWN;
- }
- }
- CySpcUnlock();
- }
- else
- {
- status = CYRET_LOCKED;
- }
- }
- else
- {
- status = CYRET_BAD_PARAM;
- }
-
-
- return (status);
-}
-
-
-/*******************************************************************************
-* Function Name: CFG_EEPROM_ReadByte
-********************************************************************************
-*
-* Summary:
-* Reads and returns a byte of data from the on-chip EEPROM memory. Although
-* the data is present in the CPU memory space, this function provides an
-* intuitive user interface, addressing the EEPROM memory as a separate block with
-* the first EERPOM byte address equal to 0x0000.
-*
-* Parameters:
-* address: The address of data to be read. The maximum address is limited by the
-* size of the EEPROM array on a specific device.
-*
-* Return:
-* Data located at an address.
-*
-*******************************************************************************/
-uint8 CFG_EEPROM_ReadByte(uint16 address)
-{
- uint8 retByte;
- uint8 interruptState;
-
- interruptState = CyEnterCriticalSection();
-
- /* Request access to EEPROM for reading.
- This is needed to reserve PHUB for read operation from EEPROM */
- CyEEPROM_ReadReserve();
-
- retByte = *((reg8 *) (CYDEV_EE_BASE + address));
-
- /* Release EEPROM array */
- CyEEPROM_ReadRelease();
-
- CyExitCriticalSection(interruptState);
-
- return (retByte);
-}
-
-
-/*******************************************************************************
-* Function Name: CFG_EEPROM_UpdateTemperature
-********************************************************************************
-*
-* Summary:
-* Updates and stores the temperature value. This function should be called
-* before EEPROM writes if the temperature may have been changed by more than
-* 10 degrees Celsius.
-*
-* Parameters:
-* None
-*
-* Return:
-* Status of operation, 0 if operation complete, non-zero value if error
-* was detected.
-*
-*******************************************************************************/
-uint8 CFG_EEPROM_UpdateTemperature(void)
-{
- return ((uint8)CySetTemp());
-}
-
-
-/*******************************************************************************
-* Function Name: CFG_EEPROM_EraseSector
-********************************************************************************
-*
-* Summary:
-* Erase an EEPROM sector (64 rows). This function blocks until the erase
-* operation is complete. Using this API helps to erase the EEPROM sector at
-* a time. This is faster than using individual writes but affects a cycle
-* recourse of the whole EEPROM row.
-*
-* Parameters:
-* sectorNumber: The sector number to erase.
-*
-* Return:
-* CYRET_SUCCESS, if the operation was successful.
-* CYRET_BAD_PARAM, if the parameter sectorNumber is out of range.
-* CYRET_LOCKED, if the SPC is being used.
-* CYRET_UNKNOWN, if there was an SPC error.
-*
-*******************************************************************************/
-cystatus CFG_EEPROM_EraseSector(uint8 sectorNumber)
-{
- cystatus status;
-
- CySpcStart();
-
- if(sectorNumber < (uint8) CFG_EEPROM_SECTORS_NUMBER)
- {
- /* See if we can get SPC. */
- if(CySpcLock() == CYRET_SUCCESS)
- {
- if(CySpcEraseSector(CY_SPC_FIRST_EE_ARRAYID, sectorNumber) == CYRET_STARTED)
- {
- /* Plan for failure */
- status = CYRET_UNKNOWN;
-
- while(CY_SPC_BUSY)
- {
- /* Wait until SPC becomes idle */
- }
-
- /* SPC is idle now */
- if(CY_SPC_STATUS_SUCCESS == CY_SPC_READ_STATUS)
- {
- status = CYRET_SUCCESS;
- }
- }
- else
- {
- status = CYRET_UNKNOWN;
- }
-
- /* Unlock SPC so that someone else can use it. */
- CySpcUnlock();
- }
- else
- {
- status = CYRET_LOCKED;
- }
- }
- else
- {
- status = CYRET_BAD_PARAM;
- }
-
- return(status);
-}
-
-
-/*******************************************************************************
-* Function Name: CFG_EEPROM_Write
-********************************************************************************
-*
-* Summary:
-* Writes a row (16 bytes) of data to the EEPROM. This function blocks until
-* the write operation is complete. Compared to functions that write one byte,
-* this function allows writing a whole row (16 bytes) at a time. For
-* a reliable write procedure to occur you should call the
-* CFG_EEPROM_UpdateTemperature() function if the temperature of the
-* silicon has changed for more than 10C since component was started.
-*
-* Parameters:
-* rowData: The address of the data to write to the EEPROM.
-* rowNumber: The row number to write.
-*
-* Return:
-* CYRET_SUCCESS, if the operation was successful.
-* CYRET_BAD_PARAM, if the parameter rowNumber is out of range.
-* CYRET_LOCKED, if the SPC is being used.
-* CYRET_UNKNOWN, if there was an SPC error.
-*
-*******************************************************************************/
-cystatus CFG_EEPROM_Write(const uint8 * rowData, uint8 rowNumber)
-{
- cystatus status;
-
- CySpcStart();
-
- if(rowNumber < (uint8) CY_EEPROM_NUMBER_ROWS)
- {
- /* See if we can get SPC. */
- if(CySpcLock() == CYRET_SUCCESS)
- {
- /* Plan for failure */
- status = CYRET_UNKNOWN;
-
- /* Command to load a row of data */
- if(CySpcLoadRow(CY_SPC_FIRST_EE_ARRAYID, rowData, CYDEV_EEPROM_ROW_SIZE) == CYRET_STARTED)
- {
- while(CY_SPC_BUSY)
- {
- /* Wait until SPC becomes idle */
- }
-
- /* SPC is idle now */
- if(CY_SPC_STATUS_SUCCESS == CY_SPC_READ_STATUS)
- {
- status = CYRET_SUCCESS;
- }
-
- /* Command to erase and program the row. */
- if(status == CYRET_SUCCESS)
- {
- if(CySpcWriteRow(CY_SPC_FIRST_EE_ARRAYID, (uint16)rowNumber, dieTemperature[0u],
- dieTemperature[1u]) == CYRET_STARTED)
- {
- /* Plan for failure */
- status = CYRET_UNKNOWN;
-
- while(CY_SPC_BUSY)
- {
- /* Wait until SPC becomes idle */
- }
-
- /* SPC is idle now */
- if(CY_SPC_STATUS_SUCCESS == CY_SPC_READ_STATUS)
- {
- status = CYRET_SUCCESS;
- }
- }
- else
- {
- status = CYRET_UNKNOWN;
- }
- }
- else
- {
- status = CYRET_UNKNOWN;
- }
- }
-
- /* Unlock SPC so that someone else can use it. */
- CySpcUnlock();
- }
- else
- {
- status = CYRET_LOCKED;
- }
- }
- else
- {
- status = CYRET_BAD_PARAM;
- }
-
- return(status);
-}
-
-
-/*******************************************************************************
-* Function Name: CFG_EEPROM_StartWrite
-********************************************************************************
-*
-* Summary:
-* Starts a write of a row (16 bytes) of data to the EEPROM.
-* This function does not block. The function returns once the SPC has begun
-* writing the data. This function must be used in combination with
-* CFG_EEPROM_Query(). CFG_EEPROM_Query() must be called
-* until it returns a status other than CYRET_STARTED. That indicates that the
-* write has completed. Until CFG_EEPROM_Query() detects that
-* the write is complete, the SPC is marked as locked to prevent another
-* SPC operation from being performed. For a reliable write procedure to occur
-* you should call CFG_EEPROM_UpdateTemperature() API if the temperature
-* of the silicon has changed for more than 10C since component was started.
-*
-* Parameters:
-* rowData: The address of the data to write to the EEPROM.
-* rowNumber: The row number to write.
-*
-* Return:
-* CYRET_STARTED, if the SPC command to write was successfully started.
-* CYRET_BAD_PARAM, if the parameter rowNumber is out of range.
-* CYRET_LOCKED, if the SPC is being used.
-* CYRET_UNKNOWN, if there was an SPC error.
-*
-* Side effects:
-* After calling this API, the device should not be powered down, reset or switched
-* to low power modes until EEPROM operation is complete.
-* Ignoring this recommendation may lead to data corruption or silicon
-* unexpected behavior.
-*
-*******************************************************************************/
-cystatus CFG_EEPROM_StartWrite(const uint8 * rowData, uint8 rowNumber) \
-
-{
- cystatus status;
-
- CySpcStart();
-
- if(rowNumber < (uint8) CY_EEPROM_NUMBER_ROWS)
- {
- /* See if we can get SPC. */
- if(CySpcLock() == CYRET_SUCCESS)
- {
- /* Plan for failure */
- status = CYRET_UNKNOWN;
-
- /* Command to load a row of data */
- if(CySpcLoadRow(CY_SPC_FIRST_EE_ARRAYID, rowData, CYDEV_EEPROM_ROW_SIZE) == CYRET_STARTED)
- {
- while(CY_SPC_BUSY)
- {
- /* Wait until SPC becomes idle */
- }
-
- /* SPC is idle now */
- if(CY_SPC_STATUS_SUCCESS == CY_SPC_READ_STATUS)
- {
- status = CYRET_SUCCESS;
- }
-
- /* Command to erase and program the row. */
- if(status == CYRET_SUCCESS)
- {
- if(CySpcWriteRow(CY_SPC_FIRST_EE_ARRAYID, (uint16)rowNumber, dieTemperature[0u],
- dieTemperature[1u]) == CYRET_STARTED)
- {
- status = CYRET_STARTED;
- }
- else
- {
- status = CYRET_UNKNOWN;
- }
- }
- else
- {
- status = CYRET_UNKNOWN;
- }
- }
- }
- else
- {
- status = CYRET_LOCKED;
- }
- }
- else
- {
- status = CYRET_BAD_PARAM;
- }
-
- return(status);
-}
-
-
-/*******************************************************************************
-* Function Name: CFG_EEPROM_StartErase
-********************************************************************************
-*
-* Summary:
-* Starts the EEPROM sector erase. This function does not block.
-* The function returns once the SPC has begun writing the data. This function
-* must be used in combination with CFG_EEPROM_Query().
-* CFG_EEPROM_Query() must be called until it returns a status
-* other than CYRET_STARTED. That indicates the erase has been completed.
-* Until CFG_EEPROM_Query() detects that the erase is
-* complete, the SPC is marked as locked to prevent another SPC operation
-* from being performed.
-*
-* Parameters:
-* sectorNumber: The sector number to erase.
-*
-* Return:
-* CYRET_STARTED, if the SPC command to erase was successfully started.
-* CYRET_BAD_PARAM, if the parameter sectorNumber is out of range.
-* CYRET_LOCKED, if the SPC is being used.
-* CYRET_UNKNOWN, if there was an SPC error.
-*
-* Side effects:
-* After calling this API, the device should not be powered down, reset or switched
-* to low power modes until EEPROM operation is complete.
-* Ignoring this recommendation may lead to data corruption or silicon
-* unexpected behavior.
-*
-*******************************************************************************/
-cystatus CFG_EEPROM_StartErase(uint8 sectorNumber)
-{
- cystatus status;
-
- CySpcStart();
-
- if(sectorNumber < (uint8) CY_EEPROM_NUMBER_ARRAYS)
- {
- /* See if we can get SPC. */
- if(CySpcLock() == CYRET_SUCCESS)
- {
- /* Plan for failure */
- status = CYRET_UNKNOWN;
-
- /* Command to load a row of data */
- if(CySpcEraseSector(CY_SPC_FIRST_EE_ARRAYID, sectorNumber) == CYRET_STARTED)
- {
- status = CYRET_SUCCESS;
- }
- }
- else
- {
- status = CYRET_LOCKED;
- }
- }
- else
- {
- status = CYRET_BAD_PARAM;
- }
-
- return(status);
-}
-
-
-/*******************************************************************************
-* Function Name: CFG_EEPROM_Query
-********************************************************************************
-*
-* Summary:
-* Checks the status of an earlier call to CFG_EEPROM_StartWrite() or
-* CFG_EEPROM_StartErase().
-* This function must be called until it returns a value other than
-* CYRET_STARTED. Once that occurs, the write or erase has been completed and
-* the SPC is unlocked.
-*
-* Parameters:
-* None
-*
-* Return:
-* CYRET_STARTED, if the SPC command is still processing.
-* CYRET_SUCCESS, if the operation was completed successfully.
-* CYRET_UNKNOWN, if there was an SPC error.
-*
-*******************************************************************************/
-cystatus CFG_EEPROM_Query(void)
-{
- cystatus status;
-
- CySpcStart();
-
- /* Check if SPC is idle */
- if(CY_SPC_IDLE)
- {
- /* SPC is idle now */
- if(CY_SPC_STATUS_SUCCESS == CY_SPC_READ_STATUS)
- {
- status = CYRET_SUCCESS;
- }
- else
- {
- status = CYRET_UNKNOWN;
- }
-
- /* Unlock SPC so that someone else can use it. */
- CySpcUnlock();
- }
- else
- {
- status = CYRET_STARTED;
- }
-
- return(status);
-}
-
-
-/*******************************************************************************
-* Function Name: CFG_EEPROM_ByteWritePos
-********************************************************************************
-*
-* Summary:
-* Writes a byte of data to the EEPROM. This is a blocking call. It will not
-* return until the write operation succeeds or fails.
-*
-* Parameters:
-* dataByte: The byte of data to write to the EEPROM.
-* rowNumber: The EEPROM row number to program.
-* byteNumber: The byte number within the row to program.
-*
-* Return:
-* CYRET_SUCCESS, if the operation was successful.
-* CYRET_BAD_PARAM, if the parameter rowNumber or byteNumber is out of range.
-* CYRET_LOCKED, if the SPC is being used.
-* CYRET_UNKNOWN, if there was an SPC error.
-*
-*******************************************************************************/
-cystatus CFG_EEPROM_ByteWritePos(uint8 dataByte, uint8 rowNumber, uint8 byteNumber) \
-
-{
- cystatus status;
-
- /* Start SPC */
- CySpcStart();
-
- if((rowNumber < (uint8) CY_EEPROM_NUMBER_ROWS) && (byteNumber < (uint8) SIZEOF_EEPROM_ROW))
- {
- /* See if we can get SPC. */
- if(CySpcLock() == CYRET_SUCCESS)
- {
- /* Plan for failure */
- status = CYRET_UNKNOWN;
-
- /* Command to load byte of data */
- if(CySpcLoadMultiByte(CY_SPC_FIRST_EE_ARRAYID, (uint16)byteNumber, &dataByte,\
- CFG_EEPROM_SPC_BYTE_WRITE_SIZE) == CYRET_STARTED)
- {
- while(CY_SPC_BUSY)
- {
- /* Wait until SPC becomes idle */
- }
-
- /* SPC is idle now */
- if(CY_SPC_STATUS_SUCCESS == CY_SPC_READ_STATUS)
- {
- status = CYRET_SUCCESS;
- }
-
- /* Command to erase and program the row. */
- if(status == CYRET_SUCCESS)
- {
- if(CySpcWriteRow(CY_SPC_FIRST_EE_ARRAYID, (uint16)rowNumber, dieTemperature[0u],
- dieTemperature[1u]) == CYRET_STARTED)
- {
- /* Plan for failure */
- status = CYRET_UNKNOWN;
-
- while(CY_SPC_BUSY)
- {
- /* Wait until SPC becomes idle */
- }
-
- /* SPC is idle now */
- if(CY_SPC_STATUS_SUCCESS == CY_SPC_READ_STATUS)
- {
- status = CYRET_SUCCESS;
- }
- }
- else
- {
- status = CYRET_UNKNOWN;
- }
- }
- else
- {
- status = CYRET_UNKNOWN;
- }
- }
-
- /* Unlock SPC so that someone else can use it. */
- CySpcUnlock();
- }
- else
- {
- status = CYRET_LOCKED;
- }
- }
- else
- {
- status = CYRET_BAD_PARAM;
- }
-
- return(status);
-}
-
-
-/* [] END OF FILE */
+/*******************************************************************************\r
+* File Name: CFG_EEPROM.c\r
+* Version 3.0\r
+*\r
+* Description:\r
+* Provides the source code to the API for the EEPROM component.\r
+*\r
+********************************************************************************\r
+* Copyright 2008-2015, Cypress Semiconductor Corporation. All rights reserved.\r
+* You may use this file only in accordance with the license, terms, conditions,\r
+* disclaimers, and limitations in the end user license agreement accompanying\r
+* the software package with which this file was provided.\r
+*******************************************************************************/\r
+\r
+#include "CFG_EEPROM.h"\r
+\r
+\r
+/*******************************************************************************\r
+* Function Name: CFG_EEPROM_Enable\r
+********************************************************************************\r
+*\r
+* Summary:\r
+* Enable the EEPROM block. Also reads the temperature and stores it for\r
+* future writes.\r
+*\r
+* Parameters:\r
+* None\r
+*\r
+* Return:\r
+* None\r
+*\r
+*******************************************************************************/\r
+void CFG_EEPROM_Enable(void) \r
+{\r
+ /* Read temperature value */\r
+ (void)CySetTemp();\r
+\r
+ /* Start EEPROM block */\r
+ CyEEPROM_Start();\r
+}\r
+\r
+\r
+/*******************************************************************************\r
+* Function Name: CFG_EEPROM_Start\r
+********************************************************************************\r
+*\r
+* Summary:\r
+* Starts EEPROM.\r
+*\r
+* Parameters:\r
+* None\r
+*\r
+* Return:\r
+* None\r
+*\r
+*******************************************************************************/\r
+void CFG_EEPROM_Start(void) \r
+{\r
+ CFG_EEPROM_Enable();\r
+}\r
+\r
+\r
+/*******************************************************************************\r
+* Function Name: CFG_EEPROM_Stop\r
+********************************************************************************\r
+*\r
+* Summary:\r
+* Stops and powers down EEPROM.\r
+*\r
+* Parameters:\r
+* None\r
+*\r
+* Return:\r
+* None\r
+*\r
+*******************************************************************************/\r
+void CFG_EEPROM_Stop (void) \r
+{\r
+ /* Stop and power down EEPROM block */\r
+ CyEEPROM_Stop();\r
+}\r
+\r
+\r
+/*******************************************************************************\r
+* Function Name: CFG_EEPROM_WriteByte\r
+********************************************************************************\r
+*\r
+* Summary:\r
+* Writes a byte of data to the EEPROM. This function blocks until\r
+* the function is complete. For a reliable write procedure to occur you should\r
+* call CFG_EEPROM_UpdateTemperature() function if the temperature of the\r
+* silicon has been changed for more than 10C since the component was started.\r
+*\r
+* Parameters:\r
+* dataByte: The byte of data to write to the EEPROM\r
+* address: The address of data to be written. The maximum address is dependent\r
+* on the EEPROM size.\r
+*\r
+* Return:\r
+* CYRET_SUCCESS, if the operation was successful.\r
+* CYRET_BAD_PARAM, if the parameter sectorNumber is out of range.\r
+* CYRET_LOCKED, if the SPC is being used.\r
+* CYRET_UNKNOWN, if there was an SPC error.\r
+*\r
+*******************************************************************************/\r
+cystatus CFG_EEPROM_WriteByte(uint8 dataByte, uint16 address) \r
+{\r
+ cystatus status;\r
+ uint16 rowNumber;\r
+ uint16 byteNumber;\r
+ \r
+ CySpcStart();\r
+\r
+ if (address < CY_EEPROM_SIZE)\r
+ {\r
+ rowNumber = address/(uint16)CY_EEPROM_SIZEOF_ROW;\r
+ byteNumber = address - (rowNumber * ((uint16)CY_EEPROM_SIZEOF_ROW));\r
+ if(CYRET_SUCCESS == CySpcLock())\r
+ {\r
+ status = CySpcLoadMultiByte(CY_SPC_FIRST_EE_ARRAYID, byteNumber, &dataByte, \\r
+ CFG_EEPROM_SPC_BYTE_WRITE_SIZE);\r
+ if (CYRET_STARTED == status)\r
+ {\r
+ /* Plan for failure */\r
+ status = CYRET_UNKNOWN;\r
+\r
+ while(CY_SPC_BUSY)\r
+ {\r
+ /* Wait until SPC becomes idle */\r
+ }\r
+\r
+ if(CY_SPC_STATUS_SUCCESS == CY_SPC_READ_STATUS)\r
+ {\r
+ status = CYRET_SUCCESS;\r
+ }\r
+ /* Command to erase and program the row. */\r
+ if(CYRET_SUCCESS == status)\r
+ {\r
+ if(CySpcWriteRow(CY_SPC_FIRST_EE_ARRAYID, (uint16)rowNumber, dieTemperature[0u],\r
+ dieTemperature[1u]) == CYRET_STARTED)\r
+ {\r
+ /* Plan for failure */\r
+ status = CYRET_UNKNOWN;\r
+\r
+ while(CY_SPC_BUSY)\r
+ {\r
+ /* Wait until SPC becomes idle */\r
+ }\r
+\r
+ /* SPC is idle now */\r
+ if(CY_SPC_STATUS_SUCCESS == CY_SPC_READ_STATUS)\r
+ {\r
+ status = CYRET_SUCCESS;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ status = CYRET_UNKNOWN;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ status = CYRET_UNKNOWN;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ if (CYRET_BAD_PARAM != status)\r
+ {\r
+ status = CYRET_UNKNOWN;\r
+ }\r
+ }\r
+ CySpcUnlock();\r
+ }\r
+ else\r
+ {\r
+ status = CYRET_LOCKED;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ status = CYRET_BAD_PARAM;\r
+ }\r
+\r
+\r
+ return (status);\r
+}\r
+\r
+\r
+/*******************************************************************************\r
+* Function Name: CFG_EEPROM_ReadByte\r
+********************************************************************************\r
+*\r
+* Summary:\r
+* Reads and returns a byte of data from the on-chip EEPROM memory. Although\r
+* the data is present in the CPU memory space, this function provides an\r
+* intuitive user interface, addressing the EEPROM memory as a separate block with\r
+* the first EERPOM byte address equal to 0x0000.\r
+*\r
+* Parameters:\r
+* address: The address of data to be read. The maximum address is limited by the\r
+* size of the EEPROM array on a specific device.\r
+*\r
+* Return:\r
+* Data located at an address.\r
+*\r
+*******************************************************************************/\r
+uint8 CFG_EEPROM_ReadByte(uint16 address) \r
+{\r
+ uint8 retByte;\r
+ uint8 interruptState;\r
+\r
+ interruptState = CyEnterCriticalSection();\r
+\r
+ /* Request access to EEPROM for reading.\r
+ This is needed to reserve PHUB for read operation from EEPROM */\r
+ CyEEPROM_ReadReserve();\r
+ \r
+ retByte = *((reg8 *) (CYDEV_EE_BASE + address));\r
+\r
+ /* Release EEPROM array */\r
+ CyEEPROM_ReadRelease();\r
+ \r
+ CyExitCriticalSection(interruptState);\r
+\r
+ return (retByte);\r
+}\r
+\r
+\r
+/*******************************************************************************\r
+* Function Name: CFG_EEPROM_UpdateTemperature\r
+********************************************************************************\r
+*\r
+* Summary:\r
+* Updates and stores the temperature value. This function should be called\r
+* before EEPROM writes if the temperature may have been changed by more than\r
+* 10 degrees Celsius.\r
+*\r
+* Parameters:\r
+* None\r
+*\r
+* Return:\r
+* Status of operation, 0 if operation complete, non-zero value if error\r
+* was detected.\r
+*\r
+*******************************************************************************/\r
+uint8 CFG_EEPROM_UpdateTemperature(void) \r
+{\r
+ return ((uint8)CySetTemp());\r
+}\r
+\r
+\r
+/*******************************************************************************\r
+* Function Name: CFG_EEPROM_EraseSector\r
+********************************************************************************\r
+*\r
+* Summary:\r
+* Erase an EEPROM sector (64 rows). This function blocks until the erase\r
+* operation is complete. Using this API helps to erase the EEPROM sector at\r
+* a time. This is faster than using individual writes but affects a cycle\r
+* recourse of the whole EEPROM row.\r
+*\r
+* Parameters:\r
+* sectorNumber: The sector number to erase.\r
+*\r
+* Return:\r
+* CYRET_SUCCESS, if the operation was successful.\r
+* CYRET_BAD_PARAM, if the parameter sectorNumber is out of range.\r
+* CYRET_LOCKED, if the SPC is being used.\r
+* CYRET_UNKNOWN, if there was an SPC error.\r
+*\r
+*******************************************************************************/\r
+cystatus CFG_EEPROM_EraseSector(uint8 sectorNumber) \r
+{\r
+ cystatus status;\r
+ \r
+ CySpcStart();\r
+\r
+ if(sectorNumber < (uint8) CFG_EEPROM_SECTORS_NUMBER)\r
+ {\r
+ /* See if we can get SPC. */\r
+ if(CySpcLock() == CYRET_SUCCESS)\r
+ {\r
+ if(CySpcEraseSector(CY_SPC_FIRST_EE_ARRAYID, sectorNumber) == CYRET_STARTED)\r
+ {\r
+ /* Plan for failure */\r
+ status = CYRET_UNKNOWN;\r
+\r
+ while(CY_SPC_BUSY)\r
+ {\r
+ /* Wait until SPC becomes idle */\r
+ }\r
+\r
+ /* SPC is idle now */\r
+ if(CY_SPC_STATUS_SUCCESS == CY_SPC_READ_STATUS)\r
+ {\r
+ status = CYRET_SUCCESS;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ status = CYRET_UNKNOWN;\r
+ }\r
+\r
+ /* Unlock SPC so that someone else can use it. */\r
+ CySpcUnlock();\r
+ }\r
+ else\r
+ {\r
+ status = CYRET_LOCKED;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ status = CYRET_BAD_PARAM;\r
+ }\r
+\r
+ return(status);\r
+}\r
+\r
+\r
+/*******************************************************************************\r
+* Function Name: CFG_EEPROM_Write\r
+********************************************************************************\r
+*\r
+* Summary:\r
+* Writes a row (16 bytes) of data to the EEPROM. This function blocks until\r
+* the write operation is complete. Compared to functions that write one byte,\r
+* this function allows writing a whole row (16 bytes) at a time. For\r
+* a reliable write procedure to occur you should call the\r
+* CFG_EEPROM_UpdateTemperature() function if the temperature of the\r
+* silicon has changed for more than 10C since component was started.\r
+*\r
+* Parameters:\r
+* rowData: The address of the data to write to the EEPROM.\r
+* rowNumber: The row number to write.\r
+*\r
+* Return:\r
+* CYRET_SUCCESS, if the operation was successful.\r
+* CYRET_BAD_PARAM, if the parameter rowNumber is out of range.\r
+* CYRET_LOCKED, if the SPC is being used.\r
+* CYRET_UNKNOWN, if there was an SPC error.\r
+*\r
+*******************************************************************************/\r
+cystatus CFG_EEPROM_Write(const uint8 * rowData, uint8 rowNumber) \r
+{\r
+ cystatus status;\r
+ \r
+ CySpcStart();\r
+\r
+ if(rowNumber < (uint8) CY_EEPROM_NUMBER_ROWS)\r
+ {\r
+ /* See if we can get SPC. */\r
+ if(CySpcLock() == CYRET_SUCCESS)\r
+ {\r
+ /* Plan for failure */\r
+ status = CYRET_UNKNOWN;\r
+\r
+ /* Command to load a row of data */\r
+ if(CySpcLoadRow(CY_SPC_FIRST_EE_ARRAYID, rowData, CYDEV_EEPROM_ROW_SIZE) == CYRET_STARTED)\r
+ {\r
+ while(CY_SPC_BUSY)\r
+ {\r
+ /* Wait until SPC becomes idle */\r
+ }\r
+\r
+ /* SPC is idle now */\r
+ if(CY_SPC_STATUS_SUCCESS == CY_SPC_READ_STATUS)\r
+ {\r
+ status = CYRET_SUCCESS;\r
+ }\r
+\r
+ /* Command to erase and program the row. */\r
+ if(status == CYRET_SUCCESS)\r
+ {\r
+ if(CySpcWriteRow(CY_SPC_FIRST_EE_ARRAYID, (uint16)rowNumber, dieTemperature[0u],\r
+ dieTemperature[1u]) == CYRET_STARTED)\r
+ {\r
+ /* Plan for failure */\r
+ status = CYRET_UNKNOWN;\r
+\r
+ while(CY_SPC_BUSY)\r
+ {\r
+ /* Wait until SPC becomes idle */\r
+ }\r
+\r
+ /* SPC is idle now */\r
+ if(CY_SPC_STATUS_SUCCESS == CY_SPC_READ_STATUS)\r
+ {\r
+ status = CYRET_SUCCESS;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ status = CYRET_UNKNOWN;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ status = CYRET_UNKNOWN;\r
+ }\r
+ }\r
+\r
+ /* Unlock SPC so that someone else can use it. */\r
+ CySpcUnlock();\r
+ }\r
+ else\r
+ {\r
+ status = CYRET_LOCKED;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ status = CYRET_BAD_PARAM;\r
+ }\r
+\r
+ return(status);\r
+}\r
+\r
+\r
+/*******************************************************************************\r
+* Function Name: CFG_EEPROM_StartWrite\r
+********************************************************************************\r
+*\r
+* Summary:\r
+* Starts a write of a row (16 bytes) of data to the EEPROM.\r
+* This function does not block. The function returns once the SPC has begun\r
+* writing the data. This function must be used in combination with\r
+* CFG_EEPROM_Query(). CFG_EEPROM_Query() must be called\r
+* until it returns a status other than CYRET_STARTED. That indicates that the\r
+* write has completed. Until CFG_EEPROM_Query() detects that\r
+* the write is complete, the SPC is marked as locked to prevent another\r
+* SPC operation from being performed. For a reliable write procedure to occur\r
+* you should call CFG_EEPROM_UpdateTemperature() API if the temperature\r
+* of the silicon has changed for more than 10C since component was started.\r
+*\r
+* Parameters:\r
+* rowData: The address of the data to write to the EEPROM.\r
+* rowNumber: The row number to write.\r
+*\r
+* Return:\r
+* CYRET_STARTED, if the SPC command to write was successfully started.\r
+* CYRET_BAD_PARAM, if the parameter rowNumber is out of range.\r
+* CYRET_LOCKED, if the SPC is being used.\r
+* CYRET_UNKNOWN, if there was an SPC error.\r
+*\r
+* Side effects:\r
+* After calling this API, the device should not be powered down, reset or switched\r
+* to low power modes until EEPROM operation is complete. \r
+* Ignoring this recommendation may lead to data corruption or silicon\r
+* unexpected behavior.\r
+*\r
+*******************************************************************************/\r
+cystatus CFG_EEPROM_StartWrite(const uint8 * rowData, uint8 rowNumber) \\r
+\r
+{\r
+ cystatus status;\r
+ \r
+ CySpcStart();\r
+\r
+ if(rowNumber < (uint8) CY_EEPROM_NUMBER_ROWS)\r
+ {\r
+ /* See if we can get SPC. */\r
+ if(CySpcLock() == CYRET_SUCCESS)\r
+ {\r
+ /* Plan for failure */\r
+ status = CYRET_UNKNOWN;\r
+\r
+ /* Command to load a row of data */\r
+ if(CySpcLoadRow(CY_SPC_FIRST_EE_ARRAYID, rowData, CYDEV_EEPROM_ROW_SIZE) == CYRET_STARTED)\r
+ {\r
+ while(CY_SPC_BUSY)\r
+ {\r
+ /* Wait until SPC becomes idle */\r
+ }\r
+\r
+ /* SPC is idle now */\r
+ if(CY_SPC_STATUS_SUCCESS == CY_SPC_READ_STATUS)\r
+ {\r
+ status = CYRET_SUCCESS;\r
+ }\r
+\r
+ /* Command to erase and program the row. */\r
+ if(status == CYRET_SUCCESS)\r
+ {\r
+ if(CySpcWriteRow(CY_SPC_FIRST_EE_ARRAYID, (uint16)rowNumber, dieTemperature[0u],\r
+ dieTemperature[1u]) == CYRET_STARTED)\r
+ {\r
+ status = CYRET_STARTED;\r
+ }\r
+ else\r
+ {\r
+ status = CYRET_UNKNOWN;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ status = CYRET_UNKNOWN;\r
+ }\r
+ }\r
+ }\r
+ else\r
+ {\r
+ status = CYRET_LOCKED;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ status = CYRET_BAD_PARAM;\r
+ }\r
+\r
+ return(status);\r
+}\r
+\r
+\r
+/*******************************************************************************\r
+* Function Name: CFG_EEPROM_StartErase\r
+********************************************************************************\r
+*\r
+* Summary:\r
+* Starts the EEPROM sector erase. This function does not block.\r
+* The function returns once the SPC has begun writing the data. This function\r
+* must be used in combination with CFG_EEPROM_Query().\r
+* CFG_EEPROM_Query() must be called until it returns a status\r
+* other than CYRET_STARTED. That indicates the erase has been completed.\r
+* Until CFG_EEPROM_Query() detects that the erase is\r
+* complete, the SPC is marked as locked to prevent another SPC operation\r
+* from being performed.\r
+*\r
+* Parameters:\r
+* sectorNumber: The sector number to erase.\r
+*\r
+* Return:\r
+* CYRET_STARTED, if the SPC command to erase was successfully started.\r
+* CYRET_BAD_PARAM, if the parameter sectorNumber is out of range.\r
+* CYRET_LOCKED, if the SPC is being used.\r
+* CYRET_UNKNOWN, if there was an SPC error.\r
+*\r
+* Side effects:\r
+* After calling this API, the device should not be powered down, reset or switched\r
+* to low power modes until EEPROM operation is complete.\r
+* Ignoring this recommendation may lead to data corruption or silicon\r
+* unexpected behavior.\r
+*\r
+*******************************************************************************/\r
+cystatus CFG_EEPROM_StartErase(uint8 sectorNumber) \r
+{\r
+ cystatus status;\r
+ \r
+ CySpcStart();\r
+\r
+ if(sectorNumber < (uint8) CY_EEPROM_NUMBER_ARRAYS)\r
+ {\r
+ /* See if we can get SPC. */\r
+ if(CySpcLock() == CYRET_SUCCESS)\r
+ {\r
+ /* Plan for failure */\r
+ status = CYRET_UNKNOWN;\r
+\r
+ /* Command to load a row of data */\r
+ if(CySpcEraseSector(CY_SPC_FIRST_EE_ARRAYID, sectorNumber) == CYRET_STARTED)\r
+ {\r
+ status = CYRET_SUCCESS;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ status = CYRET_LOCKED;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ status = CYRET_BAD_PARAM;\r
+ }\r
+\r
+ return(status);\r
+}\r
+\r
+\r
+/*******************************************************************************\r
+* Function Name: CFG_EEPROM_Query\r
+********************************************************************************\r
+*\r
+* Summary:\r
+* Checks the status of an earlier call to CFG_EEPROM_StartWrite() or\r
+* CFG_EEPROM_StartErase().\r
+* This function must be called until it returns a value other than\r
+* CYRET_STARTED. Once that occurs, the write or erase has been completed and\r
+* the SPC is unlocked.\r
+*\r
+* Parameters:\r
+* None\r
+*\r
+* Return:\r
+* CYRET_STARTED, if the SPC command is still processing.\r
+* CYRET_SUCCESS, if the operation was completed successfully.\r
+* CYRET_UNKNOWN, if there was an SPC error.\r
+*\r
+*******************************************************************************/\r
+cystatus CFG_EEPROM_Query(void) \r
+{\r
+ cystatus status;\r
+ \r
+ CySpcStart();\r
+\r
+ /* Check if SPC is idle */\r
+ if(CY_SPC_IDLE)\r
+ {\r
+ /* SPC is idle now */\r
+ if(CY_SPC_STATUS_SUCCESS == CY_SPC_READ_STATUS)\r
+ {\r
+ status = CYRET_SUCCESS;\r
+ }\r
+ else\r
+ {\r
+ status = CYRET_UNKNOWN;\r
+ }\r
+\r
+ /* Unlock SPC so that someone else can use it. */\r
+ CySpcUnlock();\r
+ }\r
+ else\r
+ {\r
+ status = CYRET_STARTED;\r
+ }\r
+\r
+ return(status);\r
+}\r
+\r
+\r
+/*******************************************************************************\r
+* Function Name: CFG_EEPROM_ByteWritePos\r
+********************************************************************************\r
+*\r
+* Summary:\r
+* Writes a byte of data to the EEPROM. This is a blocking call. It will not\r
+* return until the write operation succeeds or fails.\r
+*\r
+* Parameters:\r
+* dataByte: The byte of data to write to the EEPROM.\r
+* rowNumber: The EEPROM row number to program.\r
+* byteNumber: The byte number within the row to program.\r
+*\r
+* Return:\r
+* CYRET_SUCCESS, if the operation was successful.\r
+* CYRET_BAD_PARAM, if the parameter rowNumber or byteNumber is out of range.\r
+* CYRET_LOCKED, if the SPC is being used.\r
+* CYRET_UNKNOWN, if there was an SPC error.\r
+*\r
+*******************************************************************************/\r
+cystatus CFG_EEPROM_ByteWritePos(uint8 dataByte, uint8 rowNumber, uint8 byteNumber) \\r
+\r
+{\r
+ cystatus status;\r
+\r
+ /* Start SPC */\r
+ CySpcStart();\r
+\r
+ if((rowNumber < (uint8) CY_EEPROM_NUMBER_ROWS) && (byteNumber < (uint8) SIZEOF_EEPROM_ROW))\r
+ {\r
+ /* See if we can get SPC. */\r
+ if(CySpcLock() == CYRET_SUCCESS)\r
+ {\r
+ /* Plan for failure */\r
+ status = CYRET_UNKNOWN;\r
+\r
+ /* Command to load byte of data */\r
+ if(CySpcLoadMultiByte(CY_SPC_FIRST_EE_ARRAYID, (uint16)byteNumber, &dataByte,\\r
+ CFG_EEPROM_SPC_BYTE_WRITE_SIZE) == CYRET_STARTED)\r
+ {\r
+ while(CY_SPC_BUSY)\r
+ {\r
+ /* Wait until SPC becomes idle */\r
+ }\r
+\r
+ /* SPC is idle now */\r
+ if(CY_SPC_STATUS_SUCCESS == CY_SPC_READ_STATUS)\r
+ {\r
+ status = CYRET_SUCCESS;\r
+ }\r
+\r
+ /* Command to erase and program the row. */\r
+ if(status == CYRET_SUCCESS)\r
+ {\r
+ if(CySpcWriteRow(CY_SPC_FIRST_EE_ARRAYID, (uint16)rowNumber, dieTemperature[0u],\r
+ dieTemperature[1u]) == CYRET_STARTED)\r
+ {\r
+ /* Plan for failure */\r
+ status = CYRET_UNKNOWN;\r
+\r
+ while(CY_SPC_BUSY)\r
+ {\r
+ /* Wait until SPC becomes idle */\r
+ }\r
+\r
+ /* SPC is idle now */\r
+ if(CY_SPC_STATUS_SUCCESS == CY_SPC_READ_STATUS)\r
+ {\r
+ status = CYRET_SUCCESS;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ status = CYRET_UNKNOWN;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ status = CYRET_UNKNOWN;\r
+ }\r
+ }\r
+\r
+ /* Unlock SPC so that someone else can use it. */\r
+ CySpcUnlock();\r
+ }\r
+ else\r
+ {\r
+ status = CYRET_LOCKED;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ status = CYRET_BAD_PARAM;\r
+ }\r
+\r
+ return(status);\r
+}\r
+\r
+\r
+/* [] END OF FILE */\r
-/*******************************************************************************
-* File Name: CFG_EEPROM.h
-* Version 3.0
-*
-* Description:
-* Provides the function definitions for the EEPROM APIs.
-*
-********************************************************************************
-* Copyright 2008-2015, Cypress Semiconductor Corporation. All rights reserved.
-* You may use this file only in accordance with the license, terms, conditions,
-* disclaimers, and limitations in the end user license agreement accompanying
-* the software package with which this file was provided.
-*******************************************************************************/
-
-#if !defined(CY_EEPROM_CFG_EEPROM_H)
-#define CY_EEPROM_CFG_EEPROM_H
-
-#include "cydevice_trm.h"
-#include "CyFlash.h"
-
-#if !defined(CY_PSOC5LP)
- #error Component EEPROM_v3_0 requires cy_boot v3.0 or later
-#endif /* (CY_PSOC5LP) */
-
-
-/***************************************
-* Function Prototypes
-***************************************/
-
-void CFG_EEPROM_Enable(void) ;
-void CFG_EEPROM_Start(void) ;
-void CFG_EEPROM_Stop (void) ;
-cystatus CFG_EEPROM_WriteByte(uint8 dataByte, uint16 address) \
- ;
-uint8 CFG_EEPROM_ReadByte(uint16 address) ;
-uint8 CFG_EEPROM_UpdateTemperature(void) ;
-cystatus CFG_EEPROM_EraseSector(uint8 sectorNumber) ;
-cystatus CFG_EEPROM_Write(const uint8 * rowData, uint8 rowNumber) ;
-cystatus CFG_EEPROM_StartWrite(const uint8 * rowData, uint8 rowNumber) \
- ;
-cystatus CFG_EEPROM_StartErase(uint8 sectorNumber) ;
-cystatus CFG_EEPROM_Query(void) ;
-cystatus CFG_EEPROM_ByteWritePos(uint8 dataByte, uint8 rowNumber, uint8 byteNumber) \
- ;
-
-
-/****************************************
-* API Constants
-****************************************/
-
-#define CFG_EEPROM_EEPROM_SIZE CYDEV_EE_SIZE
-#define CFG_EEPROM_SPC_BYTE_WRITE_SIZE (0x01u)
-
-#define CFG_EEPROM_SECTORS_NUMBER (CYDEV_EE_SIZE / CYDEV_EEPROM_SECTOR_SIZE)
-
-#define CFG_EEPROM_AHB_REQ_SHIFT (0x00u)
-#define CFG_EEPROM_AHB_REQ ((uint8)(0x01u << CFG_EEPROM_AHB_REQ_SHIFT))
-#define CFG_EEPROM_AHB_ACK_SHIFT (0x01u)
-#define CFG_EEPROM_AHB_ACK_MASK ((uint8)(0x01u << CFG_EEPROM_AHB_ACK_SHIFT))
-
-
-/***************************************
-* Registers
-***************************************/
-#define CFG_EEPROM_SPC_EE_SCR_REG (*(reg8 *) CYREG_SPC_EE_SCR)
-#define CFG_EEPROM_SPC_EE_SCR_PTR ( (reg8 *) CYREG_SPC_EE_SCR)
-
-
-
-/***************************************
-* The following code is DEPRECATED and
-* should not be used in new projects.
-***************************************/
-#define CFG_EEPROM_ByteWrite CFG_EEPROM_ByteWritePos
-#define CFG_EEPROM_QueryWrite CFG_EEPROM_Query
-
-#endif /* CY_EEPROM_CFG_EEPROM_H */
-
-/* [] END OF FILE */
+/*******************************************************************************\r
+* File Name: CFG_EEPROM.h\r
+* Version 3.0\r
+*\r
+* Description:\r
+* Provides the function definitions for the EEPROM APIs.\r
+*\r
+********************************************************************************\r
+* Copyright 2008-2015, Cypress Semiconductor Corporation. All rights reserved.\r
+* You may use this file only in accordance with the license, terms, conditions,\r
+* disclaimers, and limitations in the end user license agreement accompanying\r
+* the software package with which this file was provided.\r
+*******************************************************************************/\r
+\r
+#if !defined(CY_EEPROM_CFG_EEPROM_H)\r
+#define CY_EEPROM_CFG_EEPROM_H\r
+\r
+#include "cydevice_trm.h"\r
+#include "CyFlash.h"\r
+\r
+#if !defined(CY_PSOC5LP)\r
+ #error Component EEPROM_v3_0 requires cy_boot v3.0 or later\r
+#endif /* (CY_PSOC5LP) */\r
+\r
+\r
+/***************************************\r
+* Function Prototypes\r
+***************************************/\r
+\r
+void CFG_EEPROM_Enable(void) ;\r
+void CFG_EEPROM_Start(void) ;\r
+void CFG_EEPROM_Stop (void) ;\r
+cystatus CFG_EEPROM_WriteByte(uint8 dataByte, uint16 address) \\r
+ ;\r
+uint8 CFG_EEPROM_ReadByte(uint16 address) ;\r
+uint8 CFG_EEPROM_UpdateTemperature(void) ;\r
+cystatus CFG_EEPROM_EraseSector(uint8 sectorNumber) ;\r
+cystatus CFG_EEPROM_Write(const uint8 * rowData, uint8 rowNumber) ;\r
+cystatus CFG_EEPROM_StartWrite(const uint8 * rowData, uint8 rowNumber) \\r
+ ;\r
+cystatus CFG_EEPROM_StartErase(uint8 sectorNumber) ;\r
+cystatus CFG_EEPROM_Query(void) ;\r
+cystatus CFG_EEPROM_ByteWritePos(uint8 dataByte, uint8 rowNumber, uint8 byteNumber) \\r
+ ;\r
+\r
+\r
+/****************************************\r
+* API Constants\r
+****************************************/\r
+\r
+#define CFG_EEPROM_EEPROM_SIZE CYDEV_EE_SIZE\r
+#define CFG_EEPROM_SPC_BYTE_WRITE_SIZE (0x01u)\r
+\r
+#define CFG_EEPROM_SECTORS_NUMBER (CYDEV_EE_SIZE / CYDEV_EEPROM_SECTOR_SIZE)\r
+\r
+#define CFG_EEPROM_AHB_REQ_SHIFT (0x00u)\r
+#define CFG_EEPROM_AHB_REQ ((uint8)(0x01u << CFG_EEPROM_AHB_REQ_SHIFT))\r
+#define CFG_EEPROM_AHB_ACK_SHIFT (0x01u)\r
+#define CFG_EEPROM_AHB_ACK_MASK ((uint8)(0x01u << CFG_EEPROM_AHB_ACK_SHIFT))\r
+\r
+\r
+/***************************************\r
+* Registers\r
+***************************************/\r
+#define CFG_EEPROM_SPC_EE_SCR_REG (*(reg8 *) CYREG_SPC_EE_SCR)\r
+#define CFG_EEPROM_SPC_EE_SCR_PTR ( (reg8 *) CYREG_SPC_EE_SCR)\r
+\r
+\r
+\r
+/***************************************\r
+* The following code is DEPRECATED and\r
+* should not be used in new projects.\r
+***************************************/\r
+#define CFG_EEPROM_ByteWrite CFG_EEPROM_ByteWritePos\r
+#define CFG_EEPROM_QueryWrite CFG_EEPROM_Query\r
+\r
+#endif /* CY_EEPROM_CFG_EEPROM_H */\r
+\r
+/* [] END OF FILE */\r
-/*###ICF### Section handled by ICF editor, don't touch! ****/
-/*-Editor annotation file-*/
-/* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml" */
-/*-Specials-*/
-define symbol __ICFEDIT_intvec_start__ = 0x00000000;
-/*-Memory Regions-*/
-define symbol __ICFEDIT_region_ROM_start__ = 0x0;
-define symbol __ICFEDIT_region_ROM_end__ = 131072 - 1;
-define symbol __ICFEDIT_region_RAM_start__ = 0x20000000 - (32768 / 2);
-define symbol __ICFEDIT_region_RAM_end__ = 0x20000000 + (32768 / 2) - 1;
-/*-Sizes-*/
-define symbol __ICFEDIT_size_cstack__ = 0x1000;
-define symbol __ICFEDIT_size_heap__ = 0x0400;
-/**** End of ICF editor section. ###ICF###*/
-
-
-/******** Definitions ********/
-define symbol CY_APPL_LOADABLE = 1;
-define symbol CY_APPL_LOADER = 0;
-define symbol CY_APPL_NUM = 1;
-define symbol CY_APPL_MAX = 1;
-define symbol CY_METADATA_SIZE = 64;
-define symbol CY_EE_IN_BTLDR = 0x00;
-define symbol CY_EE_SIZE = 2048;
-include "cybootloader.icf";
-if (!CY_APPL_LOADABLE) {
- define symbol CYDEV_BTLDR_SIZE = 0;
-}
-
-define symbol CY_FLASH_SIZE = 131072;
-define symbol CY_APPL_ORIGIN = 0;
-define symbol CY_FLASH_ROW_SIZE = 256;
-define symbol CY_ECC_ROW_SIZE = 32;
-
-define memory mem with size = 4G;
-define region ROM_region = mem:[from __ICFEDIT_region_ROM_start__ to __ICFEDIT_region_ROM_end__];
-define region RAM_region = mem:[from __ICFEDIT_region_RAM_start__ to __ICFEDIT_region_RAM_end__];
-
-define block CSTACK with alignment = 8, size = __ICFEDIT_size_cstack__ { };
-define block HEAP with alignment = 8, size = __ICFEDIT_size_heap__ { };
-define block HSTACK {block HEAP, last block CSTACK};
-
-if (CY_APPL_LOADABLE)
-{
-define block LOADER { readonly section .cybootloader };
-}
-define block APPL with fixed order {readonly section .romvectors, readonly};
-
-/* The address of Flash row next after Bootloader image */
-define symbol CY_BTLDR_END = CYDEV_BTLDR_SIZE +
- ((CYDEV_BTLDR_SIZE % CY_FLASH_ROW_SIZE) ?
- (CY_FLASH_ROW_SIZE - (CYDEV_BTLDR_SIZE % CY_FLASH_ROW_SIZE)) : 0);
-
-/* The start address of Standard/Loader/Loadable#1 image */
-define symbol CY_APPL1_START = CY_APPL_ORIGIN ? CY_APPL_ORIGIN : CY_BTLDR_END;
-
-/* The number of metadata records located at the end of Flash */
-define symbol CY_METADATA_CNT = (CY_APPL_NUM == 2) ? 2 : ((CY_APPL_LOADER || CY_APPL_LOADABLE) ? 1 : 0);
-
-/* The application area size measured in rows */
-define symbol CY_APPL_ROW_CNT = ((CY_FLASH_SIZE - CY_APPL1_START) / CY_FLASH_ROW_SIZE) - CY_METADATA_CNT;
-
-/* The start address of Loadable#2 image if any */
-define symbol CY_APPL2_START = CY_APPL1_START + (CY_APPL_ROW_CNT / 2 + CY_APPL_ROW_CNT % 2) * CY_FLASH_ROW_SIZE;
-
-/* The current image (Standard/Loader/Loadable) start address */
-define symbol CY_APPL_START = (CY_APPL_NUM == 1) ? CY_APPL1_START : CY_APPL2_START;
-
-/* The ECC data placement address */
-define exported symbol CY_ECC_OFFSET = (CY_APPL_START / CY_FLASH_ROW_SIZE) * CY_ECC_ROW_SIZE;
-
-/* The EEPROM offset and size that can be used by current application (Standard/Loader/Loadable) */
-define symbol CY_EE_OFFSET = (CY_APPL_LOADABLE && !CY_EE_IN_BTLDR) ? ((CY_EE_SIZE / CY_APPL_MAX) * (CY_APPL_NUM - 1)) : 0;
-define symbol CY_EE_IN_USE = (CY_APPL_LOADABLE && !CY_EE_IN_BTLDR) ? (CY_EE_SIZE / CY_APPL_MAX) : CY_EE_SIZE;
-
-/* Define EEPROM region */
-define region EEPROM_region = mem:[from (0x90200000 + CY_EE_OFFSET) size CY_EE_IN_USE];
-
-/* Define APPL region that will limit application size */
-define region APPL_region = mem:[from CY_APPL_START size CY_APPL_ROW_CNT * CY_FLASH_ROW_SIZE];
-
-
-/****** Initializations ******/
-initialize by copy { readwrite };
-do not initialize { section .noinit };
-do not initialize { readwrite section .ramvectors };
-
-/******** Placements *********/
-if (CY_APPL_LOADABLE)
-{
-".cybootloader" : place at start of ROM_region {block LOADER};
-}
-
-"APPL" : place at start of APPL_region {block APPL};
-
-"RAMVEC" : place at start of RAM_region { readwrite section .ramvectors };
-"readwrite" : place in RAM_region { readwrite };
-"HSTACK" : place at end of RAM_region { block HSTACK};
-
-keep { section .cybootloader,
- section .cyloadermeta,
- section .cyloadablemeta,
- section .cyconfigecc,
- section .cycustnvl,
- section .cywolatch,
- section .cyeeprom,
- section .cyflashprotect,
- section .cymeta };
-
-".cyloadermeta" : place at address mem : (CY_APPL_LOADER ? (CY_FLASH_SIZE - CY_METADATA_SIZE) : 0xF0000000) { readonly section .cyloadermeta };
-if (CY_APPL_LOADABLE)
-{
-".cyloadablemeta" : place at address mem : (CY_FLASH_SIZE - CY_FLASH_ROW_SIZE * (CY_APPL_NUM - 1) - CY_METADATA_SIZE) { readonly section .cyloadablemeta };
-}
-".cyconfigecc" : place at address mem : (0x80000000 + CY_ECC_OFFSET) { readonly section .cyconfigecc };
-".cycustnvl" : place at address mem : 0x90000000 { readonly section .cycustnvl };
-".cywolatch" : place at address mem : 0x90100000 { readonly section .cywolatch };
-".cyeeprom" : place in EEPROM_region { readonly section .cyeeprom };
-".cyflashprotect" : place at address mem : 0x90400000 { readonly section .cyflashprotect };
-".cymeta" : place at address mem : 0x90500000 { readonly section .cymeta };
-
-
-/* EOF */
+/*###ICF### Section handled by ICF editor, don't touch! ****/\r
+/*-Editor annotation file-*/\r
+/* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml" */\r
+/*-Specials-*/\r
+define symbol __ICFEDIT_intvec_start__ = 0x00000000;\r
+/*-Memory Regions-*/\r
+define symbol __ICFEDIT_region_ROM_start__ = 0x0;\r
+define symbol __ICFEDIT_region_ROM_end__ = 131072 - 1;\r
+define symbol __ICFEDIT_region_RAM_start__ = 0x20000000 - (32768 / 2);\r
+define symbol __ICFEDIT_region_RAM_end__ = 0x20000000 + (32768 / 2) - 1;\r
+/*-Sizes-*/\r
+define symbol __ICFEDIT_size_cstack__ = 0x1000;\r
+define symbol __ICFEDIT_size_heap__ = 0x0400;\r
+/**** End of ICF editor section. ###ICF###*/\r
+\r
+\r
+/******** Definitions ********/\r
+define symbol CY_APPL_LOADABLE = 1;\r
+define symbol CY_APPL_LOADER = 0;\r
+define symbol CY_APPL_NUM = 1;\r
+define symbol CY_APPL_MAX = 1;\r
+define symbol CY_METADATA_SIZE = 64;\r
+define symbol CY_EE_IN_BTLDR = 0x00;\r
+define symbol CY_EE_SIZE = 2048;\r
+include "cybootloader.icf";\r
+if (!CY_APPL_LOADABLE) {\r
+ define symbol CYDEV_BTLDR_SIZE = 0;\r
+}\r
+\r
+define symbol CY_FLASH_SIZE = 131072;\r
+define symbol CY_APPL_ORIGIN = 0; \r
+define symbol CY_FLASH_ROW_SIZE = 256;\r
+define symbol CY_ECC_ROW_SIZE = 32;\r
+\r
+define memory mem with size = 4G;\r
+define region ROM_region = mem:[from __ICFEDIT_region_ROM_start__ to __ICFEDIT_region_ROM_end__];\r
+define region RAM_region = mem:[from __ICFEDIT_region_RAM_start__ to __ICFEDIT_region_RAM_end__];\r
+\r
+define block CSTACK with alignment = 8, size = __ICFEDIT_size_cstack__ { };\r
+define block HEAP with alignment = 8, size = __ICFEDIT_size_heap__ { };\r
+define block HSTACK {block HEAP, last block CSTACK};\r
+\r
+if (CY_APPL_LOADABLE)\r
+{\r
+define block LOADER { readonly section .cybootloader };\r
+}\r
+define block APPL with fixed order {readonly section .romvectors, readonly};\r
+\r
+/* The address of Flash row next after Bootloader image */\r
+define symbol CY_BTLDR_END = CYDEV_BTLDR_SIZE +\r
+ ((CYDEV_BTLDR_SIZE % CY_FLASH_ROW_SIZE) ?\r
+ (CY_FLASH_ROW_SIZE - (CYDEV_BTLDR_SIZE % CY_FLASH_ROW_SIZE)) : 0);\r
+\r
+/* The start address of Standard/Loader/Loadable#1 image */\r
+define symbol CY_APPL1_START = CY_APPL_ORIGIN ? CY_APPL_ORIGIN : CY_BTLDR_END;\r
+\r
+/* The number of metadata records located at the end of Flash */\r
+define symbol CY_METADATA_CNT = (CY_APPL_NUM == 2) ? 2 : ((CY_APPL_LOADER || CY_APPL_LOADABLE) ? 1 : 0);\r
+\r
+/* The application area size measured in rows */\r
+define symbol CY_APPL_ROW_CNT = ((CY_FLASH_SIZE - CY_APPL1_START) / CY_FLASH_ROW_SIZE) - CY_METADATA_CNT;\r
+\r
+/* The start address of Loadable#2 image if any */\r
+define symbol CY_APPL2_START = CY_APPL1_START + (CY_APPL_ROW_CNT / 2 + CY_APPL_ROW_CNT % 2) * CY_FLASH_ROW_SIZE;\r
+\r
+/* The current image (Standard/Loader/Loadable) start address */\r
+define symbol CY_APPL_START = (CY_APPL_NUM == 1) ? CY_APPL1_START : CY_APPL2_START;\r
+\r
+/* The ECC data placement address */\r
+define exported symbol CY_ECC_OFFSET = (CY_APPL_START / CY_FLASH_ROW_SIZE) * CY_ECC_ROW_SIZE;\r
+\r
+/* The EEPROM offset and size that can be used by current application (Standard/Loader/Loadable) */\r
+define symbol CY_EE_OFFSET = (CY_APPL_LOADABLE && !CY_EE_IN_BTLDR) ? ((CY_EE_SIZE / CY_APPL_MAX) * (CY_APPL_NUM - 1)) : 0;\r
+define symbol CY_EE_IN_USE = (CY_APPL_LOADABLE && !CY_EE_IN_BTLDR) ? (CY_EE_SIZE / CY_APPL_MAX) : CY_EE_SIZE;\r
+\r
+/* Define EEPROM region */\r
+define region EEPROM_region = mem:[from (0x90200000 + CY_EE_OFFSET) size CY_EE_IN_USE];\r
+\r
+/* Define APPL region that will limit application size */\r
+define region APPL_region = mem:[from CY_APPL_START size CY_APPL_ROW_CNT * CY_FLASH_ROW_SIZE];\r
+\r
+\r
+/****** Initializations ******/\r
+initialize by copy { readwrite };\r
+do not initialize { section .noinit };\r
+do not initialize { readwrite section .ramvectors };\r
+\r
+/******** Placements *********/\r
+if (CY_APPL_LOADABLE)\r
+{\r
+".cybootloader" : place at start of ROM_region {block LOADER};\r
+}\r
+\r
+"APPL" : place at start of APPL_region {block APPL};\r
+\r
+"RAMVEC" : place at start of RAM_region { readwrite section .ramvectors };\r
+"readwrite" : place in RAM_region { readwrite };\r
+"HSTACK" : place at end of RAM_region { block HSTACK};\r
+\r
+keep { section .cybootloader, \r
+ section .cyloadermeta, \r
+ section .cyloadablemeta,\r
+ section .cyconfigecc, \r
+ section .cycustnvl, \r
+ section .cywolatch,\r
+ section .cyeeprom, \r
+ section .cyflashprotect,\r
+ section .cymeta };\r
+\r
+".cyloadermeta" : place at address mem : (CY_APPL_LOADER ? (CY_FLASH_SIZE - CY_METADATA_SIZE) : 0xF0000000) { readonly section .cyloadermeta };\r
+if (CY_APPL_LOADABLE)\r
+{\r
+".cyloadablemeta" : place at address mem : (CY_FLASH_SIZE - CY_FLASH_ROW_SIZE * (CY_APPL_NUM - 1) - CY_METADATA_SIZE) { readonly section .cyloadablemeta };\r
+}\r
+".cyconfigecc" : place at address mem : (0x80000000 + CY_ECC_OFFSET) { readonly section .cyconfigecc };\r
+".cycustnvl" : place at address mem : 0x90000000 { readonly section .cycustnvl };\r
+".cywolatch" : place at address mem : 0x90100000 { readonly section .cywolatch };\r
+".cyeeprom" : place in EEPROM_region { readonly section .cyeeprom };\r
+".cyflashprotect" : place at address mem : 0x90400000 { readonly section .cyflashprotect };\r
+".cymeta" : place at address mem : 0x90500000 { readonly section .cymeta };\r
+\r
+\r
+/* EOF */\r
-#! armcc -E
-; The first line specifies a preprocessor command that the linker invokes
-; to pass a scatter file through a C preprocessor.
-
-;********************************************************************************
-;* File Name: Cm3RealView.scat
-;* Version 4.20
-;*
-;* Description:
-;* This Linker Descriptor file describes the memory layout of the PSoC5
-;* device. The memory layout of the final binary and hex images as well as
-;* the placement in PSoC5 memory is described.
-;*
-;*
-;* Note:
-;*
-;* romvectors: Cypress default Interrupt service routine vector table.
-;*
-;* This is the ISR vector table at bootup. Used only for the reset vector.
-;*
-;*
-;* ramvectors: Cypress ram interrupt service routine vector table.
-;*
-;* This is the ISR vector table used by the application.
-;*
-;*
-;********************************************************************************
-;* Copyright 2008-2014, Cypress Semiconductor Corporation. All rights reserved.
-;* You may use this file only in accordance with the license, terms, conditions,
-;* disclaimers, and limitations in the end user license agreement accompanying
-;* the software package with which this file was provided.
-;********************************************************************************/
-#include "cyfitter.h"
-
-#define CY_FLASH_SIZE 131072
-#define CY_APPL_ORIGIN 0
-#define CY_FLASH_ROW_SIZE 256
-#define CY_ECC_ROW_SIZE 32
-#define CY_EE_SIZE 2048
-#define CY_METADATA_SIZE 64
-
-
-; Define application base address
-#if (CYDEV_PROJ_TYPE == CYDEV_PROJ_TYPE_LOADABLE)
- #define CY_APPL_NUM 1
- #define CY_APPL_MAX 1
- #define CY_EE_IN_BTLDR 0
-
- #if CY_APPL_ORIGIN
- #define APPL1_START CY_APPL_ORIGIN
- #else
- #define APPL1_START AlignExpr(ImageLimit(CYBOOTLOADER), CY_FLASH_ROW_SIZE)
- #endif
-
- #define APPL_START (APPL1_START + AlignExpr(((CY_FLASH_SIZE - APPL1_START - 2 * CY_FLASH_ROW_SIZE) / 2 ) * (CY_APPL_NUM - 1), CY_FLASH_ROW_SIZE))
- #define ECC_OFFSET ((APPL_START / CY_FLASH_ROW_SIZE) * CY_ECC_ROW_SIZE)
- #define EE_OFFSET (CY_EE_IN_BTLDR ? 0 : (CY_EE_SIZE / CY_APPL_MAX) * (CY_APPL_NUM - 1))
- #define EE_SIZE (CY_EE_IN_BTLDR ? CY_EE_SIZE : (CY_EE_SIZE / CY_APPL_MAX))
-
-#else
-
- #define APPL_START 0
- #define ECC_OFFSET 0
- #define EE_OFFSET 0
- #define EE_SIZE CY_EE_SIZE
-
-#endif
-
-
-; Place Bootloader at the beginning of Flash
-#if (CYDEV_PROJ_TYPE == CYDEV_PROJ_TYPE_LOADABLE)
-
- CYBOOTLOADER 0
- {
- .cybootloader +0
- {
- * (.cybootloader)
- }
- }
-
- #if CY_APPL_ORIGIN
- ScatterAssert(APPL_START > LoadLimit(CYBOOTLOADER))
- #endif
-
-#endif
-
-
-APPLICATION APPL_START (CY_FLASH_SIZE - APPL_START)
-{
- VECTORS +0
- {
- * (.romvectors)
- }
-
- CODE +0
- {
- * (+RO)
- }
-
- ISRVECTORS (0x20000000 - (32768 / 2)) UNINIT
- {
- * (.ramvectors)
- }
-
- NOINIT_DATA +0 UNINIT
- {
- * (.noinit)
- }
-
- DATA +0
- {
- .ANY (+RW, +ZI)
- }
-
- ARM_LIB_HEAP (0x20000000 + (32768 / 2) - 0x0400 - 0x1000) EMPTY 0x0400
- {
- }
-
- ARM_LIB_STACK (0x20000000 + (32768 / 2)) EMPTY -0x1000
- {
- }
-}
-
-
-#if (CYDEV_PROJ_TYPE == CYDEV_PROJ_TYPE_BOOTLOADER || CYDEV_PROJ_TYPE == CYDEV_PROJ_TYPE_MULTIAPPBOOTLOADER)
-
- CYLOADERMETA (CY_FLASH_SIZE - CY_METADATA_SIZE)
- {
- .cyloadermeta +0 { * (.cyloadermeta) }
- }
-
-#else
-
- #if (CYDEV_PROJ_TYPE == CYDEV_PROJ_TYPE_LOADABLE)
-
- CYLOADABLEMETA (CY_FLASH_SIZE - CY_FLASH_ROW_SIZE * (CY_APPL_NUM - 1) - CY_METADATA_SIZE)
- {
- .cyloadablemeta +0 { * (.cyloadablemeta) }
- }
-
- #endif
-
-#endif
-
-#if (CYDEV_ECC_ENABLE == 0)
-
- CYCONFIGECC (0x80000000 + ECC_OFFSET)
- {
- .cyconfigecc +0 { * (.cyconfigecc) }
- }
-
-#endif
-
-CYCUSTNVL 0x90000000
-{
- .cycustnvl +0 { * (.cycustnvl) }
-}
-
-CYWOLATCH 0x90100000
-{
- .cywolatch +0 { * (.cywolatch) }
-}
-
-#if defined(CYDEV_ALLOCATE_EEPROM)
-
- CYEEPROM 0x90200000 + EE_OFFSET (EE_SIZE)
- {
- .cyeeprom +0 { * (.cyeeprom) }
- }
-
-#endif
-
-CYFLASHPROTECT 0x90400000
-{
- .cyflashprotect +0 { * (.cyflashprotect) }
-}
-
-CYMETA 0x90500000
-{
- .cymeta +0 { * (.cymeta) }
-}
-
-#if (CYDEV_PROJ_TYPE == CYDEV_PROJ_TYPE_LOADABLE)
-
- CYLOADERMETA +0
- {
- .cyloadermeta +0 { * (.cyloadermeta) }
- }
-
-#endif
+#! armcc -E\r
+; The first line specifies a preprocessor command that the linker invokes \r
+; to pass a scatter file through a C preprocessor.\r
+\r
+;********************************************************************************\r
+;* File Name: Cm3RealView.scat\r
+;* Version 4.20\r
+;*\r
+;* Description:\r
+;* This Linker Descriptor file describes the memory layout of the PSoC5\r
+;* device. The memory layout of the final binary and hex images as well as\r
+;* the placement in PSoC5 memory is described.\r
+;*\r
+;*\r
+;* Note:\r
+;*\r
+;* romvectors: Cypress default Interrupt service routine vector table.\r
+;*\r
+;* This is the ISR vector table at bootup. Used only for the reset vector.\r
+;*\r
+;*\r
+;* ramvectors: Cypress ram interrupt service routine vector table.\r
+;*\r
+;* This is the ISR vector table used by the application.\r
+;*\r
+;*\r
+;********************************************************************************\r
+;* Copyright 2008-2014, Cypress Semiconductor Corporation. All rights reserved.\r
+;* You may use this file only in accordance with the license, terms, conditions,\r
+;* disclaimers, and limitations in the end user license agreement accompanying\r
+;* the software package with which this file was provided.\r
+;********************************************************************************/\r
+#include "cyfitter.h"\r
+\r
+#define CY_FLASH_SIZE 131072\r
+#define CY_APPL_ORIGIN 0\r
+#define CY_FLASH_ROW_SIZE 256\r
+#define CY_ECC_ROW_SIZE 32\r
+#define CY_EE_SIZE 2048\r
+#define CY_METADATA_SIZE 64\r
+\r
+\r
+; Define application base address\r
+#if (CYDEV_PROJ_TYPE == CYDEV_PROJ_TYPE_LOADABLE)\r
+ #define CY_APPL_NUM 1\r
+ #define CY_APPL_MAX 1\r
+ #define CY_EE_IN_BTLDR 0\r
+\r
+ #if CY_APPL_ORIGIN\r
+ #define APPL1_START CY_APPL_ORIGIN\r
+ #else\r
+ #define APPL1_START AlignExpr(ImageLimit(CYBOOTLOADER), CY_FLASH_ROW_SIZE)\r
+ #endif\r
+\r
+ #define APPL_START (APPL1_START + AlignExpr(((CY_FLASH_SIZE - APPL1_START - 2 * CY_FLASH_ROW_SIZE) / 2 ) * (CY_APPL_NUM - 1), CY_FLASH_ROW_SIZE))\r
+ #define ECC_OFFSET ((APPL_START / CY_FLASH_ROW_SIZE) * CY_ECC_ROW_SIZE)\r
+ #define EE_OFFSET (CY_EE_IN_BTLDR ? 0 : (CY_EE_SIZE / CY_APPL_MAX) * (CY_APPL_NUM - 1))\r
+ #define EE_SIZE (CY_EE_IN_BTLDR ? CY_EE_SIZE : (CY_EE_SIZE / CY_APPL_MAX))\r
+\r
+#else\r
+\r
+ #define APPL_START 0\r
+ #define ECC_OFFSET 0\r
+ #define EE_OFFSET 0\r
+ #define EE_SIZE CY_EE_SIZE\r
+\r
+#endif\r
+\r
+\r
+; Place Bootloader at the beginning of Flash\r
+#if (CYDEV_PROJ_TYPE == CYDEV_PROJ_TYPE_LOADABLE)\r
+\r
+ CYBOOTLOADER 0\r
+ {\r
+ .cybootloader +0\r
+ {\r
+ * (.cybootloader)\r
+ }\r
+ }\r
+\r
+ #if CY_APPL_ORIGIN\r
+ ScatterAssert(APPL_START > LoadLimit(CYBOOTLOADER))\r
+ #endif\r
+\r
+#endif\r
+\r
+\r
+APPLICATION APPL_START (CY_FLASH_SIZE - APPL_START)\r
+{\r
+ VECTORS +0\r
+ {\r
+ * (.romvectors)\r
+ }\r
+\r
+ CODE +0\r
+ {\r
+ * (+RO)\r
+ }\r
+\r
+ ISRVECTORS (0x20000000 - (32768 / 2)) UNINIT\r
+ {\r
+ * (.ramvectors)\r
+ }\r
+\r
+ NOINIT_DATA +0 UNINIT\r
+ {\r
+ * (.noinit)\r
+ }\r
+\r
+ DATA +0\r
+ {\r
+ .ANY (+RW, +ZI)\r
+ }\r
+\r
+ ARM_LIB_HEAP (0x20000000 + (32768 / 2) - 0x0400 - 0x1000) EMPTY 0x0400\r
+ {\r
+ }\r
+\r
+ ARM_LIB_STACK (0x20000000 + (32768 / 2)) EMPTY -0x1000\r
+ {\r
+ }\r
+}\r
+\r
+\r
+#if (CYDEV_PROJ_TYPE == CYDEV_PROJ_TYPE_BOOTLOADER || CYDEV_PROJ_TYPE == CYDEV_PROJ_TYPE_MULTIAPPBOOTLOADER)\r
+\r
+ CYLOADERMETA (CY_FLASH_SIZE - CY_METADATA_SIZE)\r
+ {\r
+ .cyloadermeta +0 { * (.cyloadermeta) }\r
+ }\r
+\r
+#else\r
+\r
+ #if (CYDEV_PROJ_TYPE == CYDEV_PROJ_TYPE_LOADABLE)\r
+\r
+ CYLOADABLEMETA (CY_FLASH_SIZE - CY_FLASH_ROW_SIZE * (CY_APPL_NUM - 1) - CY_METADATA_SIZE)\r
+ {\r
+ .cyloadablemeta +0 { * (.cyloadablemeta) }\r
+ }\r
+ \r
+ #endif\r
+\r
+#endif\r
+\r
+#if (CYDEV_ECC_ENABLE == 0)\r
+\r
+ CYCONFIGECC (0x80000000 + ECC_OFFSET)\r
+ {\r
+ .cyconfigecc +0 { * (.cyconfigecc) }\r
+ }\r
+\r
+#endif\r
+\r
+CYCUSTNVL 0x90000000\r
+{\r
+ .cycustnvl +0 { * (.cycustnvl) }\r
+}\r
+\r
+CYWOLATCH 0x90100000\r
+{\r
+ .cywolatch +0 { * (.cywolatch) }\r
+}\r
+\r
+#if defined(CYDEV_ALLOCATE_EEPROM)\r
+\r
+ CYEEPROM 0x90200000 + EE_OFFSET (EE_SIZE)\r
+ {\r
+ .cyeeprom +0 { * (.cyeeprom) }\r
+ }\r
+\r
+#endif\r
+\r
+CYFLASHPROTECT 0x90400000\r
+{\r
+ .cyflashprotect +0 { * (.cyflashprotect) }\r
+}\r
+\r
+CYMETA 0x90500000\r
+{\r
+ .cymeta +0 { * (.cymeta) }\r
+}\r
+\r
+#if (CYDEV_PROJ_TYPE == CYDEV_PROJ_TYPE_LOADABLE)\r
+\r
+ CYLOADERMETA +0\r
+ {\r
+ .cyloadermeta +0 { * (.cyloadermeta) }\r
+ }\r
+\r
+#endif\r
-/*******************************************************************************
-* File Name: Cm3Start.c
-* Version 4.20
-*
-* Description:
-* Startup code for the ARM CM3.
-*
-********************************************************************************
-* Copyright 2008-2014, Cypress Semiconductor Corporation. All rights reserved.
-* You may use this file only in accordance with the license, terms, conditions,
-* disclaimers, and limitations in the end user license agreement accompanying
-* the software package with which this file was provided.
-*******************************************************************************/
-
-#include <limits.h>
-#include "cydevice_trm.h"
-#include "cytypes.h"
-#include "cyfitter_cfg.h"
-#include "CyLib.h"
-#include "CyDmac.h"
-#include "cyfitter.h"
-
-#define CY_NUM_INTERRUPTS (32u)
-#define CY_NUM_VECTORS (CYINT_IRQ_BASE + CY_NUM_INTERRUPTS)
-#define CY_NUM_ROM_VECTORS (4u)
-#define CY_NVIC_APINT_PTR ((reg32 *) CYREG_NVIC_APPLN_INTR)
-#define CY_NVIC_CFG_CTRL_PTR ((reg32 *) CYREG_NVIC_CFG_CONTROL)
-#define CY_NVIC_APINT_PRIGROUP_3_5 (0x00000400u) /* Priority group 3.5 split */
-#define CY_NVIC_APINT_VECTKEY (0x05FA0000u) /* This key is required in order to write the NVIC_APINT register */
-#define CY_NVIC_CFG_STACKALIGN (0x00000200u) /* This specifies that the exception stack must be 8 byte aligned */
-
-
-/* Extern functions */
-extern void CyBtldr_CheckLaunch(void);
-
-/* Function prototypes */
-void initialize_psoc(void);
-CY_ISR(IntDefaultHandler);
-void Reset(void);
-CY_ISR(IntDefaultHandler);
-
-#if defined(__ARMCC_VERSION)
- #define INITIAL_STACK_POINTER ((cyisraddress)(uint32)&Image$$ARM_LIB_STACK$$ZI$$Limit)
-#elif defined (__GNUC__)
- #define INITIAL_STACK_POINTER (&__cy_stack)
-#elif defined (__ICCARM__)
- #pragma language=extended
- #pragma segment="CSTACK"
- #define INITIAL_STACK_POINTER { .__ptr = __sfe( "CSTACK" ) }
-
- extern void __iar_program_start( void );
- extern void __iar_data_init3 (void);
-#endif /* (__ARMCC_VERSION) */
-
-#if defined(__GNUC__)
- #include <errno.h>
- extern int errno;
- extern int end;
-#endif /* defined(__GNUC__) */
-
-/* Global variables */
-#if !defined (__ICCARM__)
- CY_NOINIT static uint32 cySysNoInitDataValid;
-#endif /* !defined (__ICCARM__) */
-
-
-/*******************************************************************************
-* Default Ram Interrupt Vector table storage area. Must be 256-byte aligned.
-*******************************************************************************/
-#if defined (__ICCARM__)
- #pragma location=".ramvectors"
- #pragma data_alignment=256
-#else
- CY_SECTION(".ramvectors")
- CY_ALIGN(256)
-#endif /* defined (__ICCARM__) */
-cyisraddress CyRamVectors[CY_NUM_VECTORS];
-
-
-/*******************************************************************************
-* Function Name: IntDefaultHandler
-********************************************************************************
-*
-* Summary:
-* This function is called for all interrupts, other than a reset that gets
-* called before the system is setup.
-*
-* Parameters:
-* None
-*
-* Return:
-* None
-*
-* Theory:
-* Any value other than zero is acceptable.
-*
-*******************************************************************************/
-CY_ISR(IntDefaultHandler)
-{
-
- while(1)
- {
- /***********************************************************************
- * We must not get here. If we do, a serious problem occurs, so go
- * into an infinite loop.
- ***********************************************************************/
- }
-}
-
-
-#if defined(__ARMCC_VERSION)
-
-/* Local function for device reset. */
-extern void Reset(void);
-
-/* Application entry point. */
-extern void $Super$$main(void);
-
-/* Linker-generated Stack Base addresses, Two Region and One Region */
-extern uint32 Image$$ARM_LIB_STACK$$ZI$$Limit;
-
-/* RealView C Library initialization. */
-extern int __main(void);
-
-
-/*******************************************************************************
-* Function Name: Reset
-********************************************************************************
-*
-* Summary:
-* This function handles the reset interrupt for the RVDS/MDK toolchains.
-* This is the first bit of code that is executed at startup.
-*
-* Parameters:
-* None
-*
-* Return:
-* None
-*
-*******************************************************************************/
-void Reset(void)
-{
- #if(CYDEV_PROJ_TYPE != CYDEV_PROJ_TYPE_LOADABLE)
-
- /* For PSoC 5LP, debugging is enabled by default */
- #if(CYDEV_DEBUGGING_ENABLE == 0)
- *(reg32 *)(CYDEV_DEBUG_ENABLE_REGISTER) |= CYDEV_DEBUG_ENABLE_MASK;
- #endif /* (CYDEV_DEBUGGING_ENABLE) */
-
- /* Reset Status Register has Read-to-clear SW access mode.
- * Preserve current RESET_SR0 state to make it available for next reading.
- */
- *(reg32 *)(CYREG_PHUB_CFGMEM23_CFG1) = *(reg32 *)(CYREG_RESET_SR0);
-
- #endif /* (CYDEV_PROJ_TYPE != CYDEV_PROJ_TYPE_LOADABLE) */
-
- #if(CYDEV_BOOTLOADER_ENABLE)
- CyBtldr_CheckLaunch();
- #endif /* (CYDEV_BOOTLOADER_ENABLE) */
-
- __main();
-}
-
-
-/*******************************************************************************
-* Function Name: $Sub$$main
-********************************************************************************
-*
-* Summary:
-* This function is called immediately before the users main
-*
-* Parameters:
-* None
-*
-* Return:
-* None
-*
-*******************************************************************************/
-void $Sub$$main(void)
-{
- initialize_psoc();
-
- /* Call original main */
- $Super$$main();
-
- while (1)
- {
- /* If main returns, it is undefined what we should do. */
- }
-}
-
-#elif defined(__GNUC__)
-
-void Start_c(void);
-
-/* Stack Base address */
-extern void __cy_stack(void);
-
-/* Application entry point. */
-extern int main(void);
-
-/* Static objects constructors initializer */
-extern void __libc_init_array(void);
-
-typedef unsigned char __cy_byte_align8 __attribute ((aligned (8)));
-
-struct __cy_region
-{
- __cy_byte_align8 *init; /* Initial contents of this region. */
- __cy_byte_align8 *data; /* Start address of region. */
- size_t init_size; /* Size of initial data. */
- size_t zero_size; /* Additional size to be zeroed. */
-};
-
-extern const struct __cy_region __cy_regions[];
-extern const char __cy_region_num __attribute__((weak));
-#define __cy_region_num ((size_t)&__cy_region_num)
-
-
-/*******************************************************************************
-* System Calls of the Red Hat newlib C Library
-*******************************************************************************/
-
-
-/*******************************************************************************
-* Function Name: _exit
-********************************************************************************
-*
-* Summary:
-* Exit a program without cleaning up files. If your system doesn't provide
-* this, it is best to avoid linking with subroutines that require it (exit,
-* system).
-*
-* Parameters:
-* status: Status caused program exit.
-*
-* Return:
-* None
-*
-*******************************************************************************/
-__attribute__((weak))
-void _exit(int status)
-{
- /* Cause divide by 0 exception */
- int x = status / (int) INT_MAX;
- x = 4 / x;
-
- while(1)
- {
-
- }
-}
-
-
-/*******************************************************************************
-* Function Name: _sbrk
-********************************************************************************
-*
-* Summary:
-* Increase program data space. As malloc and related functions depend on this,
-* it is useful to have a working implementation. The following suffices for a
-* standalone system; it exploits the symbol end automatically defined by the
-* GNU linker.
-*
-* Parameters:
-* nbytes: The number of bytes requested (if the parameter value is positive)
-* from the heap or returned back to the heap (if the parameter value is
-* negative).
-*
-* Return:
-* None
-*
-*******************************************************************************/
-__attribute__((weak))
-void * _sbrk (int nbytes)
-{
- extern int end; /* Symbol defined by linker map. Start of free memory (as symbol). */
- void * returnValue;
-
- /* The statically held previous end of the heap, with its initialization. */
- static void *heapPointer = (void *) &end; /* Previous end */
-
- if (((heapPointer + nbytes) - (void *) &end) <= CYDEV_HEAP_SIZE)
- {
- returnValue = heapPointer;
- heapPointer += nbytes;
- }
- else
- {
- errno = ENOMEM;
- returnValue = (void *) -1;
- }
-
- return (returnValue);
-}
-
-
-/*******************************************************************************
-* Function Name: Reset
-********************************************************************************
-*
-* Summary:
-* This function handles the reset interrupt for the GCC toolchain. This is the
-* first bit of code that is executed at startup.
-*
-* Parameters:
-* None
-*
-* Return:
-* None
-*
-*******************************************************************************/
-void Reset(void)
-{
- #if(CYDEV_PROJ_TYPE != CYDEV_PROJ_TYPE_LOADABLE)
-
- /* For PSoC 5LP, debugging is enabled by default */
- #if(CYDEV_DEBUGGING_ENABLE == 0)
- *(reg32 *)(CYDEV_DEBUG_ENABLE_REGISTER) |= CYDEV_DEBUG_ENABLE_MASK;
- #endif /* (CYDEV_DEBUGGING_ENABLE) */
-
- /* Reset Status Register has Read-to-clear SW access mode.
- * Preserve current RESET_SR0 state to make it available for next reading.
- */
- *(reg32 *)(CYREG_PHUB_CFGMEM23_CFG1) = *(reg32 *)(CYREG_RESET_SR0);
-
- #endif /* (CYDEV_PROJ_TYPE != CYDEV_PROJ_TYPE_LOADABLE) */
-
- #if(CYDEV_BOOTLOADER_ENABLE)
- CyBtldr_CheckLaunch();
- #endif /* (CYDEV_BOOTLOADER_ENABLE) */
-
- Start_c();
-}
-
-
-/*******************************************************************************
-* Function Name: Start_c
-********************************************************************************
-*
-* Summary:
-* This function handles initializing the .data and .bss sections in
-* preparation for running the standard C code. Once initialization is complete
-* it will call main(). This function will never return.
-*
-* Parameters:
-* None
-*
-* Return:
-* None
-*
-*******************************************************************************/
-void Start_c(void) __attribute__ ((noreturn));
-void Start_c(void)
-{
- unsigned regions = __cy_region_num;
- const struct __cy_region *rptr = __cy_regions;
-
- /* Initialize memory */
- for (regions = __cy_region_num; regions != 0u; regions--)
- {
- uint32 *src = (uint32 *)rptr->init;
- uint32 *dst = (uint32 *)rptr->data;
- unsigned limit = rptr->init_size;
- unsigned count;
-
- for (count = 0u; count != limit; count += sizeof (uint32))
- {
- *dst = *src;
- dst++;
- src++;
- }
- limit = rptr->zero_size;
- for (count = 0u; count != limit; count += sizeof (uint32))
- {
- *dst = 0u;
- dst++;
- }
-
- rptr++;
- }
-
- /* Invoke static objects constructors */
- __libc_init_array();
- (void) main();
-
- while (1)
- {
- /* If main returns, make sure we don't return. */
- }
-}
-
-
-#elif defined (__ICCARM__)
-
-/*******************************************************************************
-* Function Name: __low_level_init
-********************************************************************************
-*
-* Summary:
-* This function performs early initializations for the IAR Embedded
-* Workbench IDE. It is executed in the context of a reset interrupt handler
-* before the data sections are initialized.
-*
-* Parameters:
-* None
-*
-* Return:
-* The value that determines whether or not data sections should be initialized
-* by the system startup code:
-* 0 - skip data sections initialization;
-* 1 - initialize data sections;
-*
-*******************************************************************************/
-int __low_level_init(void)
-{
- #if(CYDEV_PROJ_TYPE != CYDEV_PROJ_TYPE_LOADABLE)
-
- /* For PSoC 5LP, debugging is enabled by default */
- #if(CYDEV_DEBUGGING_ENABLE == 0)
- *(reg32 *)(CYDEV_DEBUG_ENABLE_REGISTER) |= CYDEV_DEBUG_ENABLE_MASK;
- #endif /* (CYDEV_DEBUGGING_ENABLE) */
-
- /* Reset Status Register has Read-to-clear SW access mode.
- * Preserve current RESET_SR0 state to make it available for next reading.
- */
- *(reg32 *)(CYREG_PHUB_CFGMEM23_CFG1) = *(reg32 *)(CYREG_RESET_SR0);
-
- #endif /* (CYDEV_PROJ_TYPE != CYDEV_PROJ_TYPE_LOADABLE) */
-
- #if (CYDEV_BOOTLOADER_ENABLE)
- CyBtldr_CheckLaunch();
- #endif /* CYDEV_BOOTLOADER_ENABLE */
-
- /* Initialize data sections */
- __iar_data_init3();
-
- initialize_psoc();
-
- return 0;
-}
-
-#endif /* __GNUC__ */
-
-
-/*******************************************************************************
-*
-* Default Rom Interrupt Vector table.
-*
-*******************************************************************************/
-#if defined(__ARMCC_VERSION)
- /* Suppress diagnostic message 1296-D: extended constant initialiser used */
- #pragma diag_suppress 1296
-#endif /* defined(__ARMCC_VERSION) */
-
-#if defined (__ICCARM__)
- #pragma location=".romvectors"
- const intvec_elem __vector_table[CY_NUM_ROM_VECTORS] =
-#else
- CY_SECTION(".romvectors")
- const cyisraddress RomVectors[CY_NUM_ROM_VECTORS] =
-#endif /* defined (__ICCARM__) */
-{
- INITIAL_STACK_POINTER, /* Initial stack pointer 0 */
- #if defined (__ICCARM__) /* Reset handler 1 */
- __iar_program_start,
- #else
- (cyisraddress)&Reset,
- #endif /* defined (__ICCARM__) */
- &IntDefaultHandler, /* NMI handler 2 */
- &IntDefaultHandler, /* Hard fault handler 3 */
-};
-
-#if defined(__ARMCC_VERSION)
- #pragma diag_default 1296
-#endif /* defined(__ARMCC_VERSION) */
-
-
-/*******************************************************************************
-* Function Name: initialize_psoc
-********************************************************************************
-*
-* Summary:
-* This function used to initialize the PSoC chip before calling main.
-*
-* Parameters:
-* None
-*
-* Return:
-* None
-*
-*******************************************************************************/
-#if (defined(__GNUC__) && !defined(__ARMCC_VERSION))
-__attribute__ ((constructor(101)))
-#endif
-void initialize_psoc(void)
-{
- uint32 i;
-
- /* Set Priority group 5. */
-
- /* Writes to NVIC_APINT register require the VECTKEY in the upper half */
- *CY_NVIC_APINT_PTR = CY_NVIC_APINT_VECTKEY | CY_NVIC_APINT_PRIGROUP_3_5;
- *CY_NVIC_CFG_CTRL_PTR |= CY_NVIC_CFG_STACKALIGN;
-
- /* Set Ram interrupt vectors to default functions. */
- for (i = 0u; i < CY_NUM_VECTORS; i++)
- {
- #if defined (__ICCARM__)
- CyRamVectors[i] = (i < CY_NUM_ROM_VECTORS) ? __vector_table[i].__fun : &IntDefaultHandler;
- #else
- CyRamVectors[i] = (i < CY_NUM_ROM_VECTORS) ? RomVectors[i] : &IntDefaultHandler;
- #endif /* defined (__ICCARM__) */
- }
-
- /* Was stored in CFGMEM to avoid being cleared while SRAM gets cleared */
- CyResetStatus = CY_GET_REG8(CYREG_PHUB_CFGMEM23_CFG1);
-
- /* Point NVIC at RAM vector table. */
- *CYINT_VECT_TABLE = CyRamVectors;
-
- /* Initialize the configuration registers. */
- cyfitter_cfg();
-
- #if(0u != DMA_CHANNELS_USED__MASK0)
-
- /* Setup DMA - only necessary if design contains DMA component. */
- CyDmacConfigure();
-
- #endif /* (0u != DMA_CHANNELS_USED__MASK0) */
-
- #if !defined (__ICCARM__)
- /* Actually, no need to clean this variable, just to make compiler happy. */
- cySysNoInitDataValid = 0u;
- #endif /* !defined (__ICCARM__) */
-}
-
-
-/* [] END OF FILE */
+/*******************************************************************************\r
+* File Name: Cm3Start.c\r
+* Version 4.20\r
+*\r
+* Description:\r
+* Startup code for the ARM CM3.\r
+*\r
+********************************************************************************\r
+* Copyright 2008-2014, Cypress Semiconductor Corporation. All rights reserved.\r
+* You may use this file only in accordance with the license, terms, conditions,\r
+* disclaimers, and limitations in the end user license agreement accompanying\r
+* the software package with which this file was provided.\r
+*******************************************************************************/\r
+\r
+#include <limits.h>\r
+#include "cydevice_trm.h"\r
+#include "cytypes.h"\r
+#include "cyfitter_cfg.h"\r
+#include "CyLib.h"\r
+#include "CyDmac.h"\r
+#include "cyfitter.h"\r
+\r
+#define CY_NUM_INTERRUPTS (32u)\r
+#define CY_NUM_VECTORS (CYINT_IRQ_BASE + CY_NUM_INTERRUPTS)\r
+#define CY_NUM_ROM_VECTORS (4u)\r
+#define CY_NVIC_APINT_PTR ((reg32 *) CYREG_NVIC_APPLN_INTR)\r
+#define CY_NVIC_CFG_CTRL_PTR ((reg32 *) CYREG_NVIC_CFG_CONTROL)\r
+#define CY_NVIC_APINT_PRIGROUP_3_5 (0x00000400u) /* Priority group 3.5 split */\r
+#define CY_NVIC_APINT_VECTKEY (0x05FA0000u) /* This key is required in order to write the NVIC_APINT register */\r
+#define CY_NVIC_CFG_STACKALIGN (0x00000200u) /* This specifies that the exception stack must be 8 byte aligned */\r
+\r
+\r
+/* Extern functions */\r
+extern void CyBtldr_CheckLaunch(void);\r
+\r
+/* Function prototypes */\r
+void initialize_psoc(void);\r
+CY_ISR(IntDefaultHandler);\r
+void Reset(void);\r
+CY_ISR(IntDefaultHandler);\r
+\r
+#if defined(__ARMCC_VERSION)\r
+ #define INITIAL_STACK_POINTER ((cyisraddress)(uint32)&Image$$ARM_LIB_STACK$$ZI$$Limit)\r
+#elif defined (__GNUC__)\r
+ #define INITIAL_STACK_POINTER (&__cy_stack)\r
+#elif defined (__ICCARM__)\r
+ #pragma language=extended\r
+ #pragma segment="CSTACK"\r
+ #define INITIAL_STACK_POINTER { .__ptr = __sfe( "CSTACK" ) }\r
+\r
+ extern void __iar_program_start( void );\r
+ extern void __iar_data_init3 (void);\r
+#endif /* (__ARMCC_VERSION) */\r
+\r
+#if defined(__GNUC__)\r
+ #include <errno.h>\r
+ extern int errno;\r
+ extern int end;\r
+#endif /* defined(__GNUC__) */\r
+\r
+/* Global variables */\r
+#if !defined (__ICCARM__)\r
+ CY_NOINIT static uint32 cySysNoInitDataValid;\r
+#endif /* !defined (__ICCARM__) */\r
+\r
+\r
+/*******************************************************************************\r
+* Default Ram Interrupt Vector table storage area. Must be 256-byte aligned.\r
+*******************************************************************************/\r
+#if defined (__ICCARM__)\r
+ #pragma location=".ramvectors"\r
+ #pragma data_alignment=256\r
+#else\r
+ CY_SECTION(".ramvectors")\r
+ CY_ALIGN(256)\r
+#endif /* defined (__ICCARM__) */\r
+cyisraddress CyRamVectors[CY_NUM_VECTORS];\r
+\r
+\r
+/*******************************************************************************\r
+* Function Name: IntDefaultHandler\r
+********************************************************************************\r
+*\r
+* Summary:\r
+* This function is called for all interrupts, other than a reset that gets\r
+* called before the system is setup.\r
+*\r
+* Parameters:\r
+* None\r
+*\r
+* Return:\r
+* None\r
+*\r
+* Theory:\r
+* Any value other than zero is acceptable.\r
+*\r
+*******************************************************************************/\r
+CY_ISR(IntDefaultHandler)\r
+{\r
+\r
+ while(1)\r
+ {\r
+ /***********************************************************************\r
+ * We must not get here. If we do, a serious problem occurs, so go\r
+ * into an infinite loop.\r
+ ***********************************************************************/\r
+ }\r
+}\r
+\r
+\r
+#if defined(__ARMCC_VERSION)\r
+\r
+/* Local function for device reset. */\r
+extern void Reset(void);\r
+\r
+/* Application entry point. */\r
+extern void $Super$$main(void);\r
+\r
+/* Linker-generated Stack Base addresses, Two Region and One Region */\r
+extern uint32 Image$$ARM_LIB_STACK$$ZI$$Limit;\r
+\r
+/* RealView C Library initialization. */\r
+extern int __main(void);\r
+\r
+\r
+/*******************************************************************************\r
+* Function Name: Reset\r
+********************************************************************************\r
+*\r
+* Summary:\r
+* This function handles the reset interrupt for the RVDS/MDK toolchains.\r
+* This is the first bit of code that is executed at startup.\r
+*\r
+* Parameters:\r
+* None\r
+*\r
+* Return:\r
+* None\r
+*\r
+*******************************************************************************/\r
+void Reset(void)\r
+{\r
+ #if(CYDEV_PROJ_TYPE != CYDEV_PROJ_TYPE_LOADABLE)\r
+\r
+ /* For PSoC 5LP, debugging is enabled by default */\r
+ #if(CYDEV_DEBUGGING_ENABLE == 0)\r
+ *(reg32 *)(CYDEV_DEBUG_ENABLE_REGISTER) |= CYDEV_DEBUG_ENABLE_MASK;\r
+ #endif /* (CYDEV_DEBUGGING_ENABLE) */\r
+\r
+ /* Reset Status Register has Read-to-clear SW access mode.\r
+ * Preserve current RESET_SR0 state to make it available for next reading.\r
+ */\r
+ *(reg32 *)(CYREG_PHUB_CFGMEM23_CFG1) = *(reg32 *)(CYREG_RESET_SR0);\r
+\r
+ #endif /* (CYDEV_PROJ_TYPE != CYDEV_PROJ_TYPE_LOADABLE) */\r
+\r
+ #if(CYDEV_BOOTLOADER_ENABLE)\r
+ CyBtldr_CheckLaunch();\r
+ #endif /* (CYDEV_BOOTLOADER_ENABLE) */\r
+\r
+ __main();\r
+}\r
+\r
+\r
+/*******************************************************************************\r
+* Function Name: $Sub$$main\r
+********************************************************************************\r
+*\r
+* Summary:\r
+* This function is called immediately before the users main\r
+*\r
+* Parameters:\r
+* None\r
+*\r
+* Return:\r
+* None\r
+*\r
+*******************************************************************************/\r
+void $Sub$$main(void)\r
+{\r
+ initialize_psoc();\r
+\r
+ /* Call original main */\r
+ $Super$$main();\r
+\r
+ while (1)\r
+ {\r
+ /* If main returns, it is undefined what we should do. */\r
+ }\r
+}\r
+\r
+#elif defined(__GNUC__)\r
+\r
+void Start_c(void);\r
+\r
+/* Stack Base address */\r
+extern void __cy_stack(void);\r
+\r
+/* Application entry point. */\r
+extern int main(void);\r
+\r
+/* Static objects constructors initializer */\r
+extern void __libc_init_array(void);\r
+\r
+typedef unsigned char __cy_byte_align8 __attribute ((aligned (8)));\r
+\r
+struct __cy_region\r
+{\r
+ __cy_byte_align8 *init; /* Initial contents of this region. */\r
+ __cy_byte_align8 *data; /* Start address of region. */\r
+ size_t init_size; /* Size of initial data. */\r
+ size_t zero_size; /* Additional size to be zeroed. */\r
+};\r
+\r
+extern const struct __cy_region __cy_regions[];\r
+extern const char __cy_region_num __attribute__((weak));\r
+#define __cy_region_num ((size_t)&__cy_region_num)\r
+\r
+\r
+/*******************************************************************************\r
+* System Calls of the Red Hat newlib C Library\r
+*******************************************************************************/\r
+\r
+\r
+/*******************************************************************************\r
+* Function Name: _exit\r
+********************************************************************************\r
+*\r
+* Summary:\r
+* Exit a program without cleaning up files. If your system doesn't provide\r
+* this, it is best to avoid linking with subroutines that require it (exit,\r
+* system).\r
+*\r
+* Parameters:\r
+* status: Status caused program exit.\r
+*\r
+* Return:\r
+* None\r
+*\r
+*******************************************************************************/\r
+__attribute__((weak))\r
+void _exit(int status)\r
+{\r
+ /* Cause divide by 0 exception */\r
+ int x = status / (int) INT_MAX;\r
+ x = 4 / x;\r
+\r
+ while(1)\r
+ {\r
+\r
+ }\r
+}\r
+\r
+\r
+/*******************************************************************************\r
+* Function Name: _sbrk\r
+********************************************************************************\r
+*\r
+* Summary:\r
+* Increase program data space. As malloc and related functions depend on this,\r
+* it is useful to have a working implementation. The following suffices for a\r
+* standalone system; it exploits the symbol end automatically defined by the\r
+* GNU linker.\r
+*\r
+* Parameters:\r
+* nbytes: The number of bytes requested (if the parameter value is positive)\r
+* from the heap or returned back to the heap (if the parameter value is\r
+* negative).\r
+*\r
+* Return:\r
+* None\r
+*\r
+*******************************************************************************/\r
+__attribute__((weak))\r
+void * _sbrk (int nbytes)\r
+{\r
+ extern int end; /* Symbol defined by linker map. Start of free memory (as symbol). */\r
+ void * returnValue;\r
+\r
+ /* The statically held previous end of the heap, with its initialization. */\r
+ static void *heapPointer = (void *) &end; /* Previous end */\r
+\r
+ if (((heapPointer + nbytes) - (void *) &end) <= CYDEV_HEAP_SIZE)\r
+ {\r
+ returnValue = heapPointer;\r
+ heapPointer += nbytes;\r
+ }\r
+ else\r
+ {\r
+ errno = ENOMEM;\r
+ returnValue = (void *) -1;\r
+ }\r
+\r
+ return (returnValue);\r
+}\r
+\r
+\r
+/*******************************************************************************\r
+* Function Name: Reset\r
+********************************************************************************\r
+*\r
+* Summary:\r
+* This function handles the reset interrupt for the GCC toolchain. This is the\r
+* first bit of code that is executed at startup.\r
+*\r
+* Parameters:\r
+* None\r
+*\r
+* Return:\r
+* None\r
+*\r
+*******************************************************************************/\r
+void Reset(void)\r
+{\r
+ #if(CYDEV_PROJ_TYPE != CYDEV_PROJ_TYPE_LOADABLE)\r
+\r
+ /* For PSoC 5LP, debugging is enabled by default */\r
+ #if(CYDEV_DEBUGGING_ENABLE == 0)\r
+ *(reg32 *)(CYDEV_DEBUG_ENABLE_REGISTER) |= CYDEV_DEBUG_ENABLE_MASK;\r
+ #endif /* (CYDEV_DEBUGGING_ENABLE) */\r
+\r
+ /* Reset Status Register has Read-to-clear SW access mode.\r
+ * Preserve current RESET_SR0 state to make it available for next reading.\r
+ */\r
+ *(reg32 *)(CYREG_PHUB_CFGMEM23_CFG1) = *(reg32 *)(CYREG_RESET_SR0);\r
+\r
+ #endif /* (CYDEV_PROJ_TYPE != CYDEV_PROJ_TYPE_LOADABLE) */\r
+\r
+ #if(CYDEV_BOOTLOADER_ENABLE)\r
+ CyBtldr_CheckLaunch();\r
+ #endif /* (CYDEV_BOOTLOADER_ENABLE) */\r
+\r
+ Start_c();\r
+}\r
+\r
+\r
+/*******************************************************************************\r
+* Function Name: Start_c\r
+********************************************************************************\r
+*\r
+* Summary:\r
+* This function handles initializing the .data and .bss sections in\r
+* preparation for running the standard C code. Once initialization is complete\r
+* it will call main(). This function will never return.\r
+*\r
+* Parameters:\r
+* None\r
+*\r
+* Return:\r
+* None\r
+*\r
+*******************************************************************************/\r
+void Start_c(void) __attribute__ ((noreturn));\r
+void Start_c(void)\r
+{\r
+ unsigned regions = __cy_region_num;\r
+ const struct __cy_region *rptr = __cy_regions;\r
+\r
+ /* Initialize memory */\r
+ for (regions = __cy_region_num; regions != 0u; regions--)\r
+ {\r
+ uint32 *src = (uint32 *)rptr->init;\r
+ uint32 *dst = (uint32 *)rptr->data;\r
+ unsigned limit = rptr->init_size;\r
+ unsigned count;\r
+\r
+ for (count = 0u; count != limit; count += sizeof (uint32))\r
+ {\r
+ *dst = *src;\r
+ dst++;\r
+ src++;\r
+ }\r
+ limit = rptr->zero_size;\r
+ for (count = 0u; count != limit; count += sizeof (uint32))\r
+ {\r
+ *dst = 0u;\r
+ dst++;\r
+ }\r
+\r
+ rptr++;\r
+ }\r
+\r
+ /* Invoke static objects constructors */\r
+ __libc_init_array();\r
+ (void) main();\r
+\r
+ while (1)\r
+ {\r
+ /* If main returns, make sure we don't return. */\r
+ }\r
+}\r
+\r
+\r
+#elif defined (__ICCARM__)\r
+\r
+/*******************************************************************************\r
+* Function Name: __low_level_init\r
+********************************************************************************\r
+*\r
+* Summary:\r
+* This function performs early initializations for the IAR Embedded\r
+* Workbench IDE. It is executed in the context of a reset interrupt handler\r
+* before the data sections are initialized.\r
+*\r
+* Parameters:\r
+* None\r
+*\r
+* Return:\r
+* The value that determines whether or not data sections should be initialized\r
+* by the system startup code:\r
+* 0 - skip data sections initialization;\r
+* 1 - initialize data sections;\r
+*\r
+*******************************************************************************/\r
+int __low_level_init(void)\r
+{\r
+ #if(CYDEV_PROJ_TYPE != CYDEV_PROJ_TYPE_LOADABLE)\r
+\r
+ /* For PSoC 5LP, debugging is enabled by default */\r
+ #if(CYDEV_DEBUGGING_ENABLE == 0)\r
+ *(reg32 *)(CYDEV_DEBUG_ENABLE_REGISTER) |= CYDEV_DEBUG_ENABLE_MASK;\r
+ #endif /* (CYDEV_DEBUGGING_ENABLE) */\r
+\r
+ /* Reset Status Register has Read-to-clear SW access mode.\r
+ * Preserve current RESET_SR0 state to make it available for next reading.\r
+ */\r
+ *(reg32 *)(CYREG_PHUB_CFGMEM23_CFG1) = *(reg32 *)(CYREG_RESET_SR0);\r
+\r
+ #endif /* (CYDEV_PROJ_TYPE != CYDEV_PROJ_TYPE_LOADABLE) */\r
+\r
+ #if (CYDEV_BOOTLOADER_ENABLE)\r
+ CyBtldr_CheckLaunch();\r
+ #endif /* CYDEV_BOOTLOADER_ENABLE */\r
+\r
+ /* Initialize data sections */\r
+ __iar_data_init3();\r
+\r
+ initialize_psoc();\r
+\r
+ return 0;\r
+}\r
+\r
+#endif /* __GNUC__ */\r
+\r
+\r
+/*******************************************************************************\r
+*\r
+* Default Rom Interrupt Vector table.\r
+*\r
+*******************************************************************************/\r
+#if defined(__ARMCC_VERSION)\r
+ /* Suppress diagnostic message 1296-D: extended constant initialiser used */\r
+ #pragma diag_suppress 1296\r
+#endif /* defined(__ARMCC_VERSION) */\r
+\r
+#if defined (__ICCARM__)\r
+ #pragma location=".romvectors"\r
+ const intvec_elem __vector_table[CY_NUM_ROM_VECTORS] =\r
+#else\r
+ CY_SECTION(".romvectors")\r
+ const cyisraddress RomVectors[CY_NUM_ROM_VECTORS] =\r
+#endif /* defined (__ICCARM__) */\r
+{\r
+ INITIAL_STACK_POINTER, /* Initial stack pointer 0 */\r
+ #if defined (__ICCARM__) /* Reset handler 1 */\r
+ __iar_program_start,\r
+ #else\r
+ (cyisraddress)&Reset,\r
+ #endif /* defined (__ICCARM__) */\r
+ &IntDefaultHandler, /* NMI handler 2 */\r
+ &IntDefaultHandler, /* Hard fault handler 3 */\r
+};\r
+\r
+#if defined(__ARMCC_VERSION)\r
+ #pragma diag_default 1296\r
+#endif /* defined(__ARMCC_VERSION) */\r
+\r
+\r
+/*******************************************************************************\r
+* Function Name: initialize_psoc\r
+********************************************************************************\r
+*\r
+* Summary:\r
+* This function used to initialize the PSoC chip before calling main.\r
+*\r
+* Parameters:\r
+* None\r
+*\r
+* Return:\r
+* None\r
+*\r
+*******************************************************************************/\r
+#if (defined(__GNUC__) && !defined(__ARMCC_VERSION))\r
+__attribute__ ((constructor(101)))\r
+#endif\r
+void initialize_psoc(void)\r
+{\r
+ uint32 i;\r
+\r
+ /* Set Priority group 5. */\r
+\r
+ /* Writes to NVIC_APINT register require the VECTKEY in the upper half */\r
+ *CY_NVIC_APINT_PTR = CY_NVIC_APINT_VECTKEY | CY_NVIC_APINT_PRIGROUP_3_5;\r
+ *CY_NVIC_CFG_CTRL_PTR |= CY_NVIC_CFG_STACKALIGN;\r
+\r
+ /* Set Ram interrupt vectors to default functions. */\r
+ for (i = 0u; i < CY_NUM_VECTORS; i++)\r
+ {\r
+ #if defined (__ICCARM__)\r
+ CyRamVectors[i] = (i < CY_NUM_ROM_VECTORS) ? __vector_table[i].__fun : &IntDefaultHandler;\r
+ #else\r
+ CyRamVectors[i] = (i < CY_NUM_ROM_VECTORS) ? RomVectors[i] : &IntDefaultHandler;\r
+ #endif /* defined (__ICCARM__) */\r
+ }\r
+\r
+ /* Was stored in CFGMEM to avoid being cleared while SRAM gets cleared */\r
+ CyResetStatus = CY_GET_REG8(CYREG_PHUB_CFGMEM23_CFG1);\r
+\r
+ /* Point NVIC at RAM vector table. */\r
+ *CYINT_VECT_TABLE = CyRamVectors;\r
+\r
+ /* Initialize the configuration registers. */\r
+ cyfitter_cfg();\r
+\r
+ #if(0u != DMA_CHANNELS_USED__MASK0)\r
+\r
+ /* Setup DMA - only necessary if design contains DMA component. */\r
+ CyDmacConfigure();\r
+\r
+ #endif /* (0u != DMA_CHANNELS_USED__MASK0) */\r
+\r
+ #if !defined (__ICCARM__)\r
+ /* Actually, no need to clean this variable, just to make compiler happy. */\r
+ cySysNoInitDataValid = 0u;\r
+ #endif /* !defined (__ICCARM__) */\r
+}\r
+\r
+\r
+/* [] END OF FILE */\r
-/*******************************************************************************
-* File Name: CyBootAsmGnu.s
-* Version 4.20
-*
-* Description:
-* Assembly routines for GNU as.
-*
-********************************************************************************
-* Copyright 2010-2014, Cypress Semiconductor Corporation. All rights reserved.
-* You may use this file only in accordance with the license, terms, conditions,
-* disclaimers, and limitations in the end user license agreement accompanying
-* the software package with which this file was provided.
-*******************************************************************************/
-
-.include "cyfittergnu.inc"
-
-.syntax unified
-.text
-.thumb
-
-
-/*******************************************************************************
-* Function Name: CyDelayCycles
-********************************************************************************
-*
-* Summary:
-* Delays for the specified number of cycles.
-*
-* Parameters:
-* uint32 cycles: number of cycles to delay.
-*
-* Return:
-* None
-*
-*******************************************************************************/
-/* void CyDelayCycles(uint32 cycles) */
-.align 3 /* Align to 8 byte boundary (2^n) */
-.global CyDelayCycles
-.func CyDelayCycles, CyDelayCycles
-.type CyDelayCycles, %function
-.thumb_func
-CyDelayCycles: /* cycles bytes */
-/* If ICache is enabled */
-.ifeq CYDEV_INSTRUCT_CACHE_ENABLED - 1
-
- ADDS r0, r0, #2 /* 1 2 Round to nearest multiple of 4 */
- LSRS r0, r0, #2 /* 1 2 Divide by 4 and set flags */
- BEQ CyDelayCycles_done /* 2 2 Skip if 0 */
- NOP /* 1 2 Loop alignment padding */
-
-CyDelayCycles_loop:
- SUBS r0, r0, #1 /* 1 2 */
- MOV r0, r0 /* 1 2 Pad loop to power of two cycles */
- BNE CyDelayCycles_loop /* 2 2 */
-
-CyDelayCycles_done:
- BX lr /* 3 2 */
-
-.else
-
- CMP r0, #20 /* 1 2 If delay is short - jump to cycle */
- BLS CyDelayCycles_short /* 1 2 */
- PUSH {r1} /* 2 2 PUSH r1 to stack */
- MOVS r1, #1 /* 1 2 */
-
- SUBS r0, r0, #20 /* 1 2 Subtract overhead */
- LDR r1,=CYREG_CACHE_CC_CTL/* 2 2 Load flash wait cycles value */
- LDRB r1, [r1, #0] /* 2 2 */
- ANDS r1, #0xC0 /* 1 2 */
-
- LSRS r1, r1, #6 /* 1 2 */
- PUSH {r2} /* 1 2 PUSH r2 to stack */
- LDR r2, =cy_flash_cycles /* 2 2 */
- LDRB r1, [r2, r1] /* 2 2 */
-
- POP {r2} /* 2 2 POP r2 from stack */
- NOP /* 1 2 Alignment padding */
- NOP /* 1 2 Alignment padding */
- NOP /* 1 2 Alignment padding */
-
-CyDelayCycles_loop:
- SBCS r0, r0, r1 /* 1 2 */
- BPL CyDelayCycles_loop /* 3 2 */
- NOP /* 1 2 Loop alignment padding */
- NOP /* 1 2 Loop alignment padding */
-
- POP {r1} /* 2 2 POP r1 from stack */
-CyDelayCycles_done:
- BX lr /* 3 2 */
- NOP /* 1 2 Alignment padding */
- NOP /* 1 2 Alignment padding */
-
-CyDelayCycles_short:
- SBCS r0, r0, #4 /* 1 2 */
- BPL CyDelayCycles_short /* 3 2 */
- BX lr /* 3 2 */
-
-cy_flash_cycles:
-.byte 0x0B
-.byte 0x05
-.byte 0x07
-.byte 0x09
-.endif
-
-.endfunc
-
-
-/*******************************************************************************
-* Function Name: CyEnterCriticalSection
-********************************************************************************
-*
-* Summary:
-* CyEnterCriticalSection disables interrupts and returns a value indicating
-* whether interrupts were previously enabled (the actual value depends on
-* whether the device is PSoC 3 or PSoC 5).
-*
-* Note Implementation of CyEnterCriticalSection manipulates the IRQ enable bit
-* with interrupts still enabled. The test and set of the interrupt bits is not
-* atomic; this is true for both PSoC 3 and PSoC 5. Therefore, to avoid
-* corrupting processor state, it must be the policy that all interrupt routines
-* restore the interrupt enable bits as they were found on entry.
-*
-* Parameters:
-* None
-*
-* Return:
-* uint8
-* Returns 0 if interrupts were previously enabled or 1 if interrupts
-* were previously disabled.
-*
-*******************************************************************************/
-/* uint8 CyEnterCriticalSection(void) */
-.global CyEnterCriticalSection
-.func CyEnterCriticalSection, CyEnterCriticalSection
-.type CyEnterCriticalSection, %function
-.thumb_func
-CyEnterCriticalSection:
- MRS r0, PRIMASK /* Save and return interrupt state */
- CPSID I /* Disable interrupts */
- BX lr
-.endfunc
-
-
-/*******************************************************************************
-* Function Name: CyExitCriticalSection
-********************************************************************************
-*
-* Summary:
-* CyExitCriticalSection re-enables interrupts if they were enabled before
-* CyEnterCriticalSection was called. The argument should be the value returned
-* from CyEnterCriticalSection.
-*
-* Parameters:
-* uint8 savedIntrStatus:
-* Saved interrupt status returned by the CyEnterCriticalSection function.
-*
-* Return:
-* None
-*
-*******************************************************************************/
-/* void CyExitCriticalSection(uint8 savedIntrStatus) */
-.global CyExitCriticalSection
-.func CyExitCriticalSection, CyExitCriticalSection
-.type CyExitCriticalSection, %function
-.thumb_func
-CyExitCriticalSection:
- MSR PRIMASK, r0 /* Restore interrupt state */
- BX lr
-.endfunc
-
-.end
-
-
-/* [] END OF FILE */
+/*******************************************************************************\r
+* File Name: CyBootAsmGnu.s\r
+* Version 4.20\r
+*\r
+* Description:\r
+* Assembly routines for GNU as.\r
+*\r
+********************************************************************************\r
+* Copyright 2010-2014, Cypress Semiconductor Corporation. All rights reserved.\r
+* You may use this file only in accordance with the license, terms, conditions,\r
+* disclaimers, and limitations in the end user license agreement accompanying\r
+* the software package with which this file was provided.\r
+*******************************************************************************/\r
+\r
+.include "cyfittergnu.inc"\r
+\r
+.syntax unified\r
+.text\r
+.thumb\r
+\r
+\r
+/*******************************************************************************\r
+* Function Name: CyDelayCycles\r
+********************************************************************************\r
+*\r
+* Summary:\r
+* Delays for the specified number of cycles.\r
+*\r
+* Parameters:\r
+* uint32 cycles: number of cycles to delay.\r
+*\r
+* Return:\r
+* None\r
+*\r
+*******************************************************************************/\r
+/* void CyDelayCycles(uint32 cycles) */\r
+.align 3 /* Align to 8 byte boundary (2^n) */\r
+.global CyDelayCycles\r
+.func CyDelayCycles, CyDelayCycles\r
+.type CyDelayCycles, %function\r
+.thumb_func\r
+CyDelayCycles: /* cycles bytes */\r
+/* If ICache is enabled */\r
+.ifeq CYDEV_INSTRUCT_CACHE_ENABLED - 1\r
+\r
+ ADDS r0, r0, #2 /* 1 2 Round to nearest multiple of 4 */\r
+ LSRS r0, r0, #2 /* 1 2 Divide by 4 and set flags */\r
+ BEQ CyDelayCycles_done /* 2 2 Skip if 0 */\r
+ NOP /* 1 2 Loop alignment padding */\r
+\r
+CyDelayCycles_loop:\r
+ SUBS r0, r0, #1 /* 1 2 */\r
+ MOV r0, r0 /* 1 2 Pad loop to power of two cycles */\r
+ BNE CyDelayCycles_loop /* 2 2 */\r
+\r
+CyDelayCycles_done:\r
+ BX lr /* 3 2 */\r
+\r
+.else\r
+\r
+ CMP r0, #20 /* 1 2 If delay is short - jump to cycle */\r
+ BLS CyDelayCycles_short /* 1 2 */\r
+ PUSH {r1} /* 2 2 PUSH r1 to stack */\r
+ MOVS r1, #1 /* 1 2 */\r
+\r
+ SUBS r0, r0, #20 /* 1 2 Subtract overhead */\r
+ LDR r1,=CYREG_CACHE_CC_CTL/* 2 2 Load flash wait cycles value */\r
+ LDRB r1, [r1, #0] /* 2 2 */\r
+ ANDS r1, #0xC0 /* 1 2 */\r
+\r
+ LSRS r1, r1, #6 /* 1 2 */\r
+ PUSH {r2} /* 1 2 PUSH r2 to stack */\r
+ LDR r2, =cy_flash_cycles /* 2 2 */\r
+ LDRB r1, [r2, r1] /* 2 2 */\r
+\r
+ POP {r2} /* 2 2 POP r2 from stack */\r
+ NOP /* 1 2 Alignment padding */\r
+ NOP /* 1 2 Alignment padding */\r
+ NOP /* 1 2 Alignment padding */\r
+\r
+CyDelayCycles_loop:\r
+ SBCS r0, r0, r1 /* 1 2 */\r
+ BPL CyDelayCycles_loop /* 3 2 */\r
+ NOP /* 1 2 Loop alignment padding */\r
+ NOP /* 1 2 Loop alignment padding */\r
+\r
+ POP {r1} /* 2 2 POP r1 from stack */\r
+CyDelayCycles_done:\r
+ BX lr /* 3 2 */\r
+ NOP /* 1 2 Alignment padding */\r
+ NOP /* 1 2 Alignment padding */\r
+\r
+CyDelayCycles_short:\r
+ SBCS r0, r0, #4 /* 1 2 */\r
+ BPL CyDelayCycles_short /* 3 2 */\r
+ BX lr /* 3 2 */\r
+\r
+cy_flash_cycles:\r
+.byte 0x0B\r
+.byte 0x05\r
+.byte 0x07\r
+.byte 0x09\r
+.endif\r
+\r
+.endfunc\r
+\r
+\r
+/*******************************************************************************\r
+* Function Name: CyEnterCriticalSection\r
+********************************************************************************\r
+*\r
+* Summary:\r
+* CyEnterCriticalSection disables interrupts and returns a value indicating\r
+* whether interrupts were previously enabled (the actual value depends on\r
+* whether the device is PSoC 3 or PSoC 5).\r
+*\r
+* Note Implementation of CyEnterCriticalSection manipulates the IRQ enable bit\r
+* with interrupts still enabled. The test and set of the interrupt bits is not\r
+* atomic; this is true for both PSoC 3 and PSoC 5. Therefore, to avoid\r
+* corrupting processor state, it must be the policy that all interrupt routines\r
+* restore the interrupt enable bits as they were found on entry.\r
+*\r
+* Parameters:\r
+* None\r
+*\r
+* Return:\r
+* uint8\r
+* Returns 0 if interrupts were previously enabled or 1 if interrupts\r
+* were previously disabled.\r
+*\r
+*******************************************************************************/\r
+/* uint8 CyEnterCriticalSection(void) */\r
+.global CyEnterCriticalSection\r
+.func CyEnterCriticalSection, CyEnterCriticalSection\r
+.type CyEnterCriticalSection, %function\r
+.thumb_func\r
+CyEnterCriticalSection:\r
+ MRS r0, PRIMASK /* Save and return interrupt state */\r
+ CPSID I /* Disable interrupts */\r
+ BX lr\r
+.endfunc\r
+\r
+\r
+/*******************************************************************************\r
+* Function Name: CyExitCriticalSection\r
+********************************************************************************\r
+*\r
+* Summary:\r
+* CyExitCriticalSection re-enables interrupts if they were enabled before\r
+* CyEnterCriticalSection was called. The argument should be the value returned\r
+* from CyEnterCriticalSection.\r
+*\r
+* Parameters:\r
+* uint8 savedIntrStatus:\r
+* Saved interrupt status returned by the CyEnterCriticalSection function.\r
+*\r
+* Return:\r
+* None\r
+*\r
+*******************************************************************************/\r
+/* void CyExitCriticalSection(uint8 savedIntrStatus) */\r
+.global CyExitCriticalSection\r
+.func CyExitCriticalSection, CyExitCriticalSection\r
+.type CyExitCriticalSection, %function\r
+.thumb_func\r
+CyExitCriticalSection:\r
+ MSR PRIMASK, r0 /* Restore interrupt state */\r
+ BX lr\r
+.endfunc\r
+\r
+.end\r
+\r
+\r
+/* [] END OF FILE */\r
-;-------------------------------------------------------------------------------
-; FILENAME: CyBootAsmIar.s
-; Version 4.20
-;
-; DESCRIPTION:
-; Assembly routines for IAR Embedded Workbench IDE.
-;
-;-------------------------------------------------------------------------------
-; Copyright 2013-2014, Cypress Semiconductor Corporation. All rights reserved.
-; You may use this file only in accordance with the license, terms, conditions,
-; disclaimers, and limitations in the end user license agreement accompanying
-; the software package with which this file was provided.
-;-------------------------------------------------------------------------------
-
- SECTION .text:CODE:ROOT(4)
- PUBLIC CyDelayCycles
- PUBLIC CyEnterCriticalSection
- PUBLIC CyExitCriticalSection
- INCLUDE cyfitteriar.inc
- THUMB
-
-
-;-------------------------------------------------------------------------------
-; Function Name: CyEnterCriticalSection
-;-------------------------------------------------------------------------------
-;
-; Summary:
-; CyEnterCriticalSection disables interrupts and returns a value indicating
-; whether interrupts were previously enabled.
-;
-; Note Implementation of CyEnterCriticalSection manipulates the IRQ enable bit
-; with interrupts still enabled. The test and set of the interrupt bits is not
-; atomic. Therefore, to avoid a corrupting processor state, it must be the policy
-; that all interrupt routines restore the interrupt enable bits as they were
-; found on entry.
-;
-; Parameters:
-; None
-;
-; Return:
-; uint8
-; Returns 0 if interrupts were previously enabled or 1 if interrupts
-; were previously disabled.
-;
-;-------------------------------------------------------------------------------
-; uint8 CyEnterCriticalSection(void)
-
-CyEnterCriticalSection:
- MRS r0, PRIMASK ; Save and return interrupt state
- CPSID I ; Disable interrupts
- BX lr
-
-
-;-------------------------------------------------------------------------------
-; Function Name: CyExitCriticalSection
-;-------------------------------------------------------------------------------
-;
-; Summary:
-; CyExitCriticalSection re-enables interrupts if they were enabled before
-; CyEnterCriticalSection was called. The argument should be the value returned
-; from CyEnterCriticalSection.
-;
-; Parameters:
-; uint8 savedIntrStatus:
-; Saved interrupt status returned by the CyEnterCriticalSection function.
-;
-; Return:
-; None
-;
-;-------------------------------------------------------------------------------
-; void CyExitCriticalSection(uint8 savedIntrStatus)
-
-CyExitCriticalSection:
- MSR PRIMASK, r0 ; Restore interrupt state
- BX lr
-
-
-;-------------------------------------------------------------------------------
-; Function Name: CyDelayCycles
-;-------------------------------------------------------------------------------
-;
-; Summary:
-; Delays for the specified number of cycles.
-;
-; Parameters:
-; uint32 cycles: number of cycles to delay.
-;
-; Return:
-; None
-;
-;-------------------------------------------------------------------------------
-; void CyDelayCycles(uint32 cycles)
-
-CyDelayCycles:
- IF CYDEV_INSTRUCT_CACHE_ENABLED == 1
- ; cycles bytes
- ADDS r0, r0, #2 ; 1 2 Round to nearest multiple of 4
- LSRS r0, r0, #2 ; 1 2 Divide by 4 and set flags
- BEQ CyDelayCycles_done ; 2 2 Skip if 0
- NOP ; 1 2 Loop alignment padding
-CyDelayCycles_loop:
- SUBS r0, r0, #1 ; 1 2
- MOV r0, r0 ; 1 2 Pad loop to power of two cycles
- BNE CyDelayCycles_loop ; 2 2
-CyDelayCycles_done:
- BX lr ; 3 2
-
- ELSE
-
- CMP r0, #20 ; 1 2 If delay is short - jump to cycle
- BLS CyDelayCycles_short ; 1 2
- PUSH {r1} ; 2 2 PUSH r1 to stack
- MOVS r1, #1 ; 1 2
-
- SUBS r0, r0, #20 ; 1 2 Subtract overhead
- LDR r1,=CYREG_CACHE_CC_CTL; 2 2 Load flash wait cycles value
- LDRB r1, [r1, #0] ; 2 2
- ANDS r1, r1, #0xC0 ; 1 2
-
- LSRS r1, r1, #6 ; 1 2
- PUSH {r2} ; 1 2 PUSH r2 to stack
- LDR r2, =cy_flash_cycles ; 2 2
- LDRB r1, [r2, r1] ; 2 2
-
- POP {r2} ; 2 2 POP r2 from stack
- NOP ; 1 2 Alignment padding
- NOP ; 1 2 Alignment padding
- NOP ; 1 2 Alignment padding
-
-CyDelayCycles_loop:
- SBCS r0, r0, r1 ; 1 2
- BPL CyDelayCycles_loop ; 3 2
- NOP ; 1 2 Loop alignment padding
- NOP ; 1 2 Loop alignment padding
-
- POP {r1} ; 2 2 POP r1 from stack
-CyDelayCycles_done:
- BX lr ; 3 2
- NOP ; 1 2 Alignment padding
- NOP ; 1 2 Alignment padding
-CyDelayCycles_short:
- SBCS r0, r0, #4 ; 1 2
- BPL CyDelayCycles_short ; 3 2
- BX lr ; 3 2
- NOP ; 1 2 Loop alignment padding
-
- DATA
-cy_flash_cycles:
-byte_1 DCB 0x0B
-byte_2 DCB 0x05
-byte_3 DCB 0x07
-byte_4 DCB 0x09
-
- ENDIF
-
- END
+;-------------------------------------------------------------------------------\r
+; FILENAME: CyBootAsmIar.s\r
+; Version 4.20\r
+;\r
+; DESCRIPTION:\r
+; Assembly routines for IAR Embedded Workbench IDE.\r
+;\r
+;-------------------------------------------------------------------------------\r
+; Copyright 2013-2014, Cypress Semiconductor Corporation. All rights reserved.\r
+; You may use this file only in accordance with the license, terms, conditions,\r
+; disclaimers, and limitations in the end user license agreement accompanying\r
+; the software package with which this file was provided.\r
+;-------------------------------------------------------------------------------\r
+\r
+ SECTION .text:CODE:ROOT(4)\r
+ PUBLIC CyDelayCycles\r
+ PUBLIC CyEnterCriticalSection\r
+ PUBLIC CyExitCriticalSection\r
+ INCLUDE cyfitteriar.inc\r
+ THUMB\r
+\r
+\r
+;-------------------------------------------------------------------------------\r
+; Function Name: CyEnterCriticalSection\r
+;-------------------------------------------------------------------------------\r
+;\r
+; Summary:\r
+; CyEnterCriticalSection disables interrupts and returns a value indicating\r
+; whether interrupts were previously enabled.\r
+;\r
+; Note Implementation of CyEnterCriticalSection manipulates the IRQ enable bit\r
+; with interrupts still enabled. The test and set of the interrupt bits is not\r
+; atomic. Therefore, to avoid a corrupting processor state, it must be the policy \r
+; that all interrupt routines restore the interrupt enable bits as they were \r
+; found on entry.\r
+;\r
+; Parameters:\r
+; None\r
+;\r
+; Return:\r
+; uint8\r
+; Returns 0 if interrupts were previously enabled or 1 if interrupts\r
+; were previously disabled.\r
+;\r
+;-------------------------------------------------------------------------------\r
+; uint8 CyEnterCriticalSection(void)\r
+\r
+CyEnterCriticalSection:\r
+ MRS r0, PRIMASK ; Save and return interrupt state\r
+ CPSID I ; Disable interrupts\r
+ BX lr\r
+\r
+\r
+;-------------------------------------------------------------------------------\r
+; Function Name: CyExitCriticalSection\r
+;-------------------------------------------------------------------------------\r
+;\r
+; Summary:\r
+; CyExitCriticalSection re-enables interrupts if they were enabled before\r
+; CyEnterCriticalSection was called. The argument should be the value returned\r
+; from CyEnterCriticalSection.\r
+;\r
+; Parameters:\r
+; uint8 savedIntrStatus:\r
+; Saved interrupt status returned by the CyEnterCriticalSection function.\r
+;\r
+; Return:\r
+; None\r
+;\r
+;-------------------------------------------------------------------------------\r
+; void CyExitCriticalSection(uint8 savedIntrStatus)\r
+\r
+CyExitCriticalSection:\r
+ MSR PRIMASK, r0 ; Restore interrupt state\r
+ BX lr\r
+\r
+\r
+;-------------------------------------------------------------------------------\r
+; Function Name: CyDelayCycles\r
+;-------------------------------------------------------------------------------\r
+;\r
+; Summary:\r
+; Delays for the specified number of cycles.\r
+;\r
+; Parameters:\r
+; uint32 cycles: number of cycles to delay.\r
+;\r
+; Return:\r
+; None\r
+;\r
+;-------------------------------------------------------------------------------\r
+; void CyDelayCycles(uint32 cycles)\r
+\r
+CyDelayCycles: \r
+ IF CYDEV_INSTRUCT_CACHE_ENABLED == 1\r
+ ; cycles bytes\r
+ ADDS r0, r0, #2 ; 1 2 Round to nearest multiple of 4\r
+ LSRS r0, r0, #2 ; 1 2 Divide by 4 and set flags\r
+ BEQ CyDelayCycles_done ; 2 2 Skip if 0\r
+ NOP ; 1 2 Loop alignment padding\r
+CyDelayCycles_loop:\r
+ SUBS r0, r0, #1 ; 1 2\r
+ MOV r0, r0 ; 1 2 Pad loop to power of two cycles\r
+ BNE CyDelayCycles_loop ; 2 2\r
+CyDelayCycles_done:\r
+ BX lr ; 3 2\r
+ \r
+ ELSE\r
+ \r
+ CMP r0, #20 ; 1 2 If delay is short - jump to cycle\r
+ BLS CyDelayCycles_short ; 1 2\r
+ PUSH {r1} ; 2 2 PUSH r1 to stack\r
+ MOVS r1, #1 ; 1 2\r
+\r
+ SUBS r0, r0, #20 ; 1 2 Subtract overhead\r
+ LDR r1,=CYREG_CACHE_CC_CTL; 2 2 Load flash wait cycles value\r
+ LDRB r1, [r1, #0] ; 2 2\r
+ ANDS r1, r1, #0xC0 ; 1 2\r
+\r
+ LSRS r1, r1, #6 ; 1 2\r
+ PUSH {r2} ; 1 2 PUSH r2 to stack\r
+ LDR r2, =cy_flash_cycles ; 2 2\r
+ LDRB r1, [r2, r1] ; 2 2\r
+\r
+ POP {r2} ; 2 2 POP r2 from stack\r
+ NOP ; 1 2 Alignment padding\r
+ NOP ; 1 2 Alignment padding\r
+ NOP ; 1 2 Alignment padding\r
+\r
+CyDelayCycles_loop:\r
+ SBCS r0, r0, r1 ; 1 2\r
+ BPL CyDelayCycles_loop ; 3 2\r
+ NOP ; 1 2 Loop alignment padding\r
+ NOP ; 1 2 Loop alignment padding\r
+\r
+ POP {r1} ; 2 2 POP r1 from stack\r
+CyDelayCycles_done:\r
+ BX lr ; 3 2\r
+ NOP ; 1 2 Alignment padding\r
+ NOP ; 1 2 Alignment padding\r
+CyDelayCycles_short:\r
+ SBCS r0, r0, #4 ; 1 2\r
+ BPL CyDelayCycles_short ; 3 2\r
+ BX lr ; 3 2\r
+ NOP ; 1 2 Loop alignment padding\r
+\r
+ DATA\r
+cy_flash_cycles:\r
+byte_1 DCB 0x0B\r
+byte_2 DCB 0x05\r
+byte_3 DCB 0x07\r
+byte_4 DCB 0x09\r
+\r
+ ENDIF\r
+\r
+ END\r
-;-------------------------------------------------------------------------------
-; FILENAME: CyBootAsmRv.s
-; Version 4.20
-;
-; DESCRIPTION:
-; Assembly routines for RealView.
-;
-;-------------------------------------------------------------------------------
-; Copyright 2010-2014, Cypress Semiconductor Corporation. All rights reserved.
-; You may use this file only in accordance with the license, terms, conditions,
-; disclaimers, and limitations in the end user license agreement accompanying
-; the software package with which this file was provided.
-;-------------------------------------------------------------------------------
-
- AREA |.text|,CODE,ALIGN=3
- THUMB
- EXTERN Reset
-
- GET cyfitterrv.inc
-
-;-------------------------------------------------------------------------------
-; Function Name: CyDelayCycles
-;-------------------------------------------------------------------------------
-;
-; Summary:
-; Delays for the specified number of cycles.
-;
-; Parameters:
-; uint32 cycles: number of cycles to delay.
-;
-; Return:
-; None
-;
-;-------------------------------------------------------------------------------
-; void CyDelayCycles(uint32 cycles)
- ALIGN 8
-CyDelayCycles FUNCTION
- EXPORT CyDelayCycles
- IF CYDEV_INSTRUCT_CACHE_ENABLED == 1
- ; cycles bytes
- ADDS r0, r0, #2 ; 1 2 Round to nearest multiple of 4
- LSRS r0, r0, #2 ; 1 2 Divide by 4 and set flags
- BEQ CyDelayCycles_done ; 2 2 Skip if 0
- NOP ; 1 2 Loop alignment padding
-CyDelayCycles_loop
- SUBS r0, r0, #1 ; 1 2
- MOV r0, r0 ; 1 2 Pad loop to power of two cycles
- BNE CyDelayCycles_loop ; 2 2
- NOP ; 1 2 Loop alignment padding
-CyDelayCycles_done
- BX lr ; 3 2
-
- ELSE
-
- CMP r0, #20 ; 1 2 If delay is short - jump to cycle
- BLS CyDelayCycles_short ; 1 2
- PUSH {r1} ; 2 2 PUSH r1 to stack
- MOVS r1, #1 ; 1 2
-
- SUBS r0, r0, #20 ; 1 2 Subtract overhead
- LDR r1,=CYREG_CACHE_CC_CTL; 2 2 Load flash wait cycles value
- LDRB r1, [r1, #0] ; 2 2
- ANDS r1, #0xC0 ; 1 2
-
- LSRS r1, r1, #6 ; 1 2
- PUSH {r2} ; 1 2 PUSH r2 to stack
- LDR r2, =cy_flash_cycles ; 2 2
- LDRB r1, [r2, r1] ; 2 2
-
- POP {r2} ; 2 2 POP r2 from stack
- NOP ; 1 2 Alignment padding
- NOP ; 1 2 Alignment padding
- NOP ; 1 2 Alignment padding
-
-CyDelayCycles_loop
- SBCS r0, r0, r1 ; 1 2
- BPL CyDelayCycles_loop ; 3 2
- NOP ; 1 2 Loop alignment padding
- NOP ; 1 2 Loop alignment padding
-
- POP {r1} ; 2 2 POP r1 from stack
-CyDelayCycles_done
- BX lr ; 3 2
- NOP ; 1 2 Alignment padding
- NOP ; 1 2 Alignment padding
-
-CyDelayCycles_short
- SBCS r0, r0, #4 ; 1 2
- BPL CyDelayCycles_short ; 3 2
- BX lr ; 3 2
-
-cy_flash_cycles
-byte_1 DCB 0x0B
-byte_2 DCB 0x05
-byte_3 DCB 0x07
-byte_4 DCB 0x09
-
- ENDIF
- ENDFUNC
-
-
-;-------------------------------------------------------------------------------
-; Function Name: CyEnterCriticalSection
-;-------------------------------------------------------------------------------
-;
-; Summary:
-; CyEnterCriticalSection disables interrupts and returns a value indicating
-; whether interrupts were previously enabled (the actual value depends on
-; whether the device is PSoC 3 or PSoC 5).
-;
-; Note Implementation of CyEnterCriticalSection manipulates the IRQ enable bit
-; with interrupts still enabled. The test and set of the interrupt bits is not
-; atomic; this is true for both PSoC 3 and PSoC 5. Therefore, to avoid a
-; corrupting processor state, it must be the policy that all interrupt routines
-; restore the interrupt enable bits as they were found on entry.
-;
-; Parameters:
-; None
-;
-; Return:
-; uint8
-; Returns 0 if interrupts were previously enabled or 1 if interrupts
-; were previously disabled.
-;
-;-------------------------------------------------------------------------------
-; uint8 CyEnterCriticalSection(void)
-CyEnterCriticalSection FUNCTION
- EXPORT CyEnterCriticalSection
- MRS r0, PRIMASK ; Save and return interrupt state
- CPSID I ; Disable interrupts
- BX lr
- ENDFUNC
-
-
-;-------------------------------------------------------------------------------
-; Function Name: CyExitCriticalSection
-;-------------------------------------------------------------------------------
-;
-; Summary:
-; CyExitCriticalSection re-enables interrupts if they were enabled before
-; CyEnterCriticalSection was called. The argument should be the value returned
-; from CyEnterCriticalSection.
-;
-; Parameters:
-; uint8 savedIntrStatus:
-; Saved interrupt status returned by the CyEnterCriticalSection function.
-;
-; Return:
-; None
-;
-;-------------------------------------------------------------------------------
-; void CyExitCriticalSection(uint8 savedIntrStatus)
-CyExitCriticalSection FUNCTION
- EXPORT CyExitCriticalSection
- MSR PRIMASK, r0 ; Restore interrupt state
- BX lr
- ENDFUNC
-
- END
-
-; [] END OF FILE
+;-------------------------------------------------------------------------------\r
+; FILENAME: CyBootAsmRv.s\r
+; Version 4.20\r
+;\r
+; DESCRIPTION:\r
+; Assembly routines for RealView.\r
+;\r
+;-------------------------------------------------------------------------------\r
+; Copyright 2010-2014, Cypress Semiconductor Corporation. All rights reserved.\r
+; You may use this file only in accordance with the license, terms, conditions,\r
+; disclaimers, and limitations in the end user license agreement accompanying\r
+; the software package with which this file was provided.\r
+;-------------------------------------------------------------------------------\r
+\r
+ AREA |.text|,CODE,ALIGN=3\r
+ THUMB\r
+ EXTERN Reset\r
+\r
+ GET cyfitterrv.inc\r
+\r
+;-------------------------------------------------------------------------------\r
+; Function Name: CyDelayCycles\r
+;-------------------------------------------------------------------------------\r
+;\r
+; Summary:\r
+; Delays for the specified number of cycles.\r
+;\r
+; Parameters:\r
+; uint32 cycles: number of cycles to delay.\r
+;\r
+; Return:\r
+; None\r
+;\r
+;-------------------------------------------------------------------------------\r
+; void CyDelayCycles(uint32 cycles)\r
+ ALIGN 8\r
+CyDelayCycles FUNCTION\r
+ EXPORT CyDelayCycles\r
+ IF CYDEV_INSTRUCT_CACHE_ENABLED == 1\r
+ ; cycles bytes\r
+ ADDS r0, r0, #2 ; 1 2 Round to nearest multiple of 4\r
+ LSRS r0, r0, #2 ; 1 2 Divide by 4 and set flags\r
+ BEQ CyDelayCycles_done ; 2 2 Skip if 0\r
+ NOP ; 1 2 Loop alignment padding\r
+CyDelayCycles_loop\r
+ SUBS r0, r0, #1 ; 1 2\r
+ MOV r0, r0 ; 1 2 Pad loop to power of two cycles\r
+ BNE CyDelayCycles_loop ; 2 2\r
+ NOP ; 1 2 Loop alignment padding\r
+CyDelayCycles_done\r
+ BX lr ; 3 2\r
+\r
+ ELSE\r
+\r
+ CMP r0, #20 ; 1 2 If delay is short - jump to cycle\r
+ BLS CyDelayCycles_short ; 1 2\r
+ PUSH {r1} ; 2 2 PUSH r1 to stack\r
+ MOVS r1, #1 ; 1 2\r
+\r
+ SUBS r0, r0, #20 ; 1 2 Subtract overhead\r
+ LDR r1,=CYREG_CACHE_CC_CTL; 2 2 Load flash wait cycles value\r
+ LDRB r1, [r1, #0] ; 2 2\r
+ ANDS r1, #0xC0 ; 1 2\r
+\r
+ LSRS r1, r1, #6 ; 1 2\r
+ PUSH {r2} ; 1 2 PUSH r2 to stack\r
+ LDR r2, =cy_flash_cycles ; 2 2\r
+ LDRB r1, [r2, r1] ; 2 2\r
+\r
+ POP {r2} ; 2 2 POP r2 from stack\r
+ NOP ; 1 2 Alignment padding\r
+ NOP ; 1 2 Alignment padding\r
+ NOP ; 1 2 Alignment padding\r
+\r
+CyDelayCycles_loop\r
+ SBCS r0, r0, r1 ; 1 2\r
+ BPL CyDelayCycles_loop ; 3 2\r
+ NOP ; 1 2 Loop alignment padding\r
+ NOP ; 1 2 Loop alignment padding\r
+\r
+ POP {r1} ; 2 2 POP r1 from stack\r
+CyDelayCycles_done\r
+ BX lr ; 3 2\r
+ NOP ; 1 2 Alignment padding\r
+ NOP ; 1 2 Alignment padding\r
+\r
+CyDelayCycles_short\r
+ SBCS r0, r0, #4 ; 1 2\r
+ BPL CyDelayCycles_short ; 3 2\r
+ BX lr ; 3 2\r
+\r
+cy_flash_cycles\r
+byte_1 DCB 0x0B\r
+byte_2 DCB 0x05\r
+byte_3 DCB 0x07\r
+byte_4 DCB 0x09\r
+\r
+ ENDIF\r
+ ENDFUNC\r
+\r
+\r
+;-------------------------------------------------------------------------------\r
+; Function Name: CyEnterCriticalSection\r
+;-------------------------------------------------------------------------------\r
+;\r
+; Summary:\r
+; CyEnterCriticalSection disables interrupts and returns a value indicating\r
+; whether interrupts were previously enabled (the actual value depends on\r
+; whether the device is PSoC 3 or PSoC 5).\r
+;\r
+; Note Implementation of CyEnterCriticalSection manipulates the IRQ enable bit\r
+; with interrupts still enabled. The test and set of the interrupt bits is not\r
+; atomic; this is true for both PSoC 3 and PSoC 5. Therefore, to avoid a\r
+; corrupting processor state, it must be the policy that all interrupt routines\r
+; restore the interrupt enable bits as they were found on entry.\r
+;\r
+; Parameters:\r
+; None\r
+;\r
+; Return:\r
+; uint8\r
+; Returns 0 if interrupts were previously enabled or 1 if interrupts\r
+; were previously disabled.\r
+;\r
+;-------------------------------------------------------------------------------\r
+; uint8 CyEnterCriticalSection(void)\r
+CyEnterCriticalSection FUNCTION\r
+ EXPORT CyEnterCriticalSection\r
+ MRS r0, PRIMASK ; Save and return interrupt state\r
+ CPSID I ; Disable interrupts\r
+ BX lr\r
+ ENDFUNC\r
+\r
+\r
+;-------------------------------------------------------------------------------\r
+; Function Name: CyExitCriticalSection\r
+;-------------------------------------------------------------------------------\r
+;\r
+; Summary:\r
+; CyExitCriticalSection re-enables interrupts if they were enabled before\r
+; CyEnterCriticalSection was called. The argument should be the value returned\r
+; from CyEnterCriticalSection.\r
+;\r
+; Parameters:\r
+; uint8 savedIntrStatus:\r
+; Saved interrupt status returned by the CyEnterCriticalSection function.\r
+;\r
+; Return:\r
+; None\r
+;\r
+;-------------------------------------------------------------------------------\r
+; void CyExitCriticalSection(uint8 savedIntrStatus)\r
+CyExitCriticalSection FUNCTION\r
+ EXPORT CyExitCriticalSection\r
+ MSR PRIMASK, r0 ; Restore interrupt state\r
+ BX lr\r
+ ENDFUNC\r
+\r
+ END\r
+\r
+; [] END OF FILE\r
-/*******************************************************************************
-* File Name: CyDmac.c
-* Version 4.20
-*
-* Description:
-* Provides an API for the DMAC component. The API includes functions for the
-* DMA controller, DMA channels and Transfer Descriptors.
-*
-* This API is the library version not the auto generated code that gets
-* generated when the user places a DMA component on the schematic.
-*
-* The auto generated code would use the APi's in this module.
-*
-* Note:
-* This code is endian agnostic.
-*
-* The Transfer Descriptor memory can be used as regular memory if the TD's are
-* not being used.
-*
-* This code uses the first byte of each TD to manage the free list of TD's.
-* The user can overwrite this once the TD is allocated.
-*
-********************************************************************************
-* Copyright 2008-2014, Cypress Semiconductor Corporation. All rights reserved.
-* You may use this file only in accordance with the license, terms, conditions,
-* disclaimers, and limitations in the end user license agreement accompanying
-* the software package with which this file was provided.
-*******************************************************************************/
-
-#include "CyDmac.h"
-
-
-/*******************************************************************************
-* The following variables are initialized from CyDmacConfigure() function that
-* is executed from initialize_psoc() at the early initialization stage.
-* In case of IAR EW IDE, initialize_psoc() is executed before the data sections
-* are initialized. To avoid zeroing, these variables should be initialized
-* properly during segments initialization as well.
-*******************************************************************************/
-static uint8 CyDmaTdCurrentNumber = CY_DMA_NUMBEROF_TDS; /* Current Number of free elements on list */
-static uint8 CyDmaTdFreeIndex = (uint8)(CY_DMA_NUMBEROF_TDS - 1u); /* Index of first available TD */
-static uint32 CyDmaChannels = DMA_CHANNELS_USED__MASK0; /* Bit map of DMA channel ownership */
-
-
-/*******************************************************************************
-* Function Name: CyDmacConfigure
-********************************************************************************
-*
-* Summary:
-* Creates a linked list of all the TDs to be allocated. This function is called
-* by the startup code; you do not normally need to call it. You can call this
-* function if all of the DMA channels are inactive.
-*
-* Parameters:
-* None
-*
-* Return:
-* None
-*
-*******************************************************************************/
-void CyDmacConfigure(void)
-{
- uint8 dmaIndex;
-
- /* Set TD list variables. */
- CyDmaTdFreeIndex = (uint8)(CY_DMA_NUMBEROF_TDS - 1u);
- CyDmaTdCurrentNumber = CY_DMA_NUMBEROF_TDS;
-
- /* Make TD free list. */
- for(dmaIndex = (uint8)(CY_DMA_NUMBEROF_TDS - 1u); dmaIndex != 0u; dmaIndex--)
- {
- CY_DMA_TDMEM_STRUCT_PTR[dmaIndex].TD0[0u] = (uint8)(dmaIndex - 1u);
- }
-
- /* Make last one point to zero. */
- CY_DMA_TDMEM_STRUCT_PTR[dmaIndex].TD0[0u] = 0u;
-}
-
-
-/*******************************************************************************
-* Function Name: CyDmacError
-********************************************************************************
-*
-* Summary:
-* Returns errors of the last failed DMA transaction.
-*
-* Parameters:
-* None
-*
-* Return:
-* Errors of the last failed DMA transaction.
-*
-* DMAC_PERIPH_ERR:
-* Set to 1 when a peripheral responds to a bus transaction with an error
-* response.
-*
-* DMAC_UNPOP_ACC:
-* Set to 1 when an access is attempted to an invalid address.
-*
-* DMAC_BUS_TIMEOUT:
-* Set to 1 when a bus timeout occurs. Cleared by writing a 1. Timeout values
-* are determined by the BUS_TIMEOUT field in the PHUBCFG register.
-*
-* Theory:
-* Once an error occurs the error bits are sticky and are only cleared by
-* writing 1 to the error register.
-*
-*******************************************************************************/
-uint8 CyDmacError(void)
-{
- return((uint8)(((uint32) 0x0Fu) & *CY_DMA_ERR_PTR));
-}
-
-
-/*******************************************************************************
-* Function Name: CyDmacClearError
-********************************************************************************
-*
-* Summary:
-* Clears the error bits in the error register of the DMAC.
-*
-* Parameters:
-* error:
-* Clears the error bits in the DMAC error register.
-*
-* DMAC_PERIPH_ERR:
-* Set to 1 when a peripheral responds to a bus transaction with an error
-* response.
-*
-* DMAC_UNPOP_ACC:
-* Set to 1 when an access is attempted to an invalid address.
-*
-* DMAC_BUS_TIMEOUT:
-* Set to 1 when a bus timeout occurs. Cleared by writing 1. Timeout values
-* are determined by the BUS_TIMEOUT field in the PHUBCFG register.
-*
-* Return:
-* None
-*
-* Theory:
-* Once an error occurs the error bits are sticky and are only cleared by
-* writing 1 to the error register.
-*
-*******************************************************************************/
-void CyDmacClearError(uint8 error)
-{
- *CY_DMA_ERR_PTR = (((uint32)0x0Fu) & ((uint32)error));
-}
-
-
-/*******************************************************************************
-* Function Name: CyDmacErrorAddress
-********************************************************************************
-*
-* Summary:
-* When DMAC_BUS_TIMEOUT, DMAC_UNPOP_ACC, and DMAC_PERIPH_ERR occur the
-* address of the error is written to the error address register and can be read
-* with this function.
-*
-* If there are multiple errors, only the address of the first is saved.
-*
-* Parameters:
-* None
-*
-* Return:
-* The address that caused the error.
-*
-*******************************************************************************/
-uint32 CyDmacErrorAddress(void)
-{
- return(CY_GET_REG32(CY_DMA_ERR_ADR_PTR));
-}
-
-
-/*******************************************************************************
-* Function Name: CyDmaChAlloc
-********************************************************************************
-*
-* Summary:
-* Allocates a channel from the DMAC to be used in all functions that require a
-* channel handle.
-*
-* Parameters:
-* None
-*
-* Return:
-* The allocated channel number. Zero is a valid channel number.
-* DMA_INVALID_CHANNEL is returned if there are no channels available.
-*
-*******************************************************************************/
-uint8 CyDmaChAlloc(void)
-{
- uint8 interruptState;
- uint8 dmaIndex;
- uint32 channel = 1u;
-
-
- /* Enter critical section! */
- interruptState = CyEnterCriticalSection();
-
- /* Look for free channel. */
- for(dmaIndex = 0u; dmaIndex < CY_DMA_NUMBEROF_CHANNELS; dmaIndex++)
- {
- if(0uL == (CyDmaChannels & channel))
- {
- /* Mark channel as used. */
- CyDmaChannels |= channel;
- break;
- }
-
- channel <<= 1u;
- }
-
- if(dmaIndex >= CY_DMA_NUMBEROF_CHANNELS)
- {
- dmaIndex = CY_DMA_INVALID_CHANNEL;
- }
-
- /* Exit critical section! */
- CyExitCriticalSection(interruptState);
-
- return(dmaIndex);
-}
-
-
-/*******************************************************************************
-* Function Name: CyDmaChFree
-********************************************************************************
-*
-* Summary:
-* Frees a channel allocated by DmaChAlloc().
-*
-* Parameters:
-* uint8 chHandle:
-* The handle previously returned by CyDmaChAlloc() or DMA_DmaInitalize().
-*
-* Return:
-* CYRET_SUCCESS if successful.
-* CYRET_BAD_PARAM if chHandle is invalid.
-*
-*******************************************************************************/
-cystatus CyDmaChFree(uint8 chHandle)
-{
- cystatus status = CYRET_BAD_PARAM;
- uint8 interruptState;
-
- if(chHandle < CY_DMA_NUMBEROF_CHANNELS)
- {
- /* Enter critical section */
- interruptState = CyEnterCriticalSection();
-
- /* Clear bit mask that keeps track of ownership. */
- CyDmaChannels &= ~(((uint32) 1u) << chHandle);
-
- /* Exit critical section */
- CyExitCriticalSection(interruptState);
- status = CYRET_SUCCESS;
- }
-
- return(status);
-}
-
-
-/*******************************************************************************
-* Function Name: CyDmaChEnable
-********************************************************************************
-*
-* Summary:
-* Enables the DMA channel. A software or hardware request still must happen
-* before the channel is executed.
-*
-* Parameters:
-* uint8 chHandle:
-* A handle previously returned by CyDmaChAlloc() or DMA_DmaInitalize().
-*
-* uint8 preserveTds:
-* Preserves the original TD state when the TD has completed. This parameter
-* applies to all TDs in the channel.
-*
-* 0 - When TD is completed, the DMAC leaves the TD configuration values in
-* their current state, and does not restore them to their original state.
-*
-* 1 - When TD is completed, the DMAC restores the original configuration
-* values of the TD.
-*
-* When preserveTds is set, the TD slot that equals the channel number becomes
-* RESERVED and that becomes where the working registers exist. So, for example,
-* if you are using CH06 and preserveTds is set, you are not allowed to use TD
-* slot 6. That is reclaimed by the DMA engine for its private use.
-*
-* Note Do not chain back to a completed TD if the preserveTds for the channel
-* is set to 0. When a TD has completed preserveTds for the channel set to 0,
-* the transfer count will be at 0. If a TD with a transfer count of 0 is
-* started, the TD will transfer an indefinite amount of data.
-*
-* Take extra precautions when using the hardware request (DRQ) option when the
-* preserveTds is set to 0, as you might be requesting the wrong data.
-*
-* Return:
-* CYRET_SUCCESS if successful.
-* CYRET_BAD_PARAM if chHandle is invalid.
-*
-*******************************************************************************/
-cystatus CyDmaChEnable(uint8 chHandle, uint8 preserveTds)
-{
- cystatus status = CYRET_BAD_PARAM;
-
- if(chHandle < CY_DMA_NUMBEROF_CHANNELS)
- {
- if (0u != preserveTds)
- {
- /* Store intermediate TD states separately in CHn_SEP_TD0/1 to
- * preserve original TD chain
- */
- CY_DMA_CH_STRUCT_PTR[chHandle].basic_cfg[0u] |= CY_DMA_CH_BASIC_CFG_WORK_SEP;
- }
- else
- {
- /* Store intermediate and final TD states on top of original TD chain */
- CY_DMA_CH_STRUCT_PTR[chHandle].basic_cfg[0u] &= (uint8)(~CY_DMA_CH_BASIC_CFG_WORK_SEP);
- }
-
- /* Enable channel */
- CY_DMA_CH_STRUCT_PTR[chHandle].basic_cfg[0u] |= CY_DMA_CH_BASIC_CFG_EN;
-
- status = CYRET_SUCCESS;
- }
-
- return(status);
-}
-
-
-/*******************************************************************************
-* Function Name: CyDmaChDisable
-********************************************************************************
-*
-* Summary:
-* Disables the DMA channel. Once this function is called, CyDmaChStatus() may
-* be called to determine when the channel is disabled and which TDs were being
-* executed.
-*
-* If it is currently executing it will allow the current burst to finish
-* naturally.
-*
-* Parameters:
-* uint8 chHandle:
-* A handle previously returned by CyDmaChAlloc() or DMA_DmaInitalize().
-*
-* Return:
-* CYRET_SUCCESS if successful.
-* CYRET_BAD_PARAM if chHandle is invalid.
-*
-*******************************************************************************/
-cystatus CyDmaChDisable(uint8 chHandle)
-{
- cystatus status = CYRET_BAD_PARAM;
-
- if(chHandle < CY_DMA_NUMBEROF_CHANNELS)
- {
- /***********************************************************************
- * Should not change configuration information of a DMA channel when it
- * is active (or vulnerable to becoming active).
- ***********************************************************************/
-
- /* Disable channel */
- CY_DMA_CH_STRUCT_PTR[chHandle].basic_cfg[0] &= ((uint8) (~CY_DMA_CH_BASIC_CFG_EN));
-
- /* Store intermediate and final TD states on top of original TD chain */
- CY_DMA_CH_STRUCT_PTR[chHandle].basic_cfg[0] &= ((uint8) (~CY_DMA_CH_BASIC_CFG_WORK_SEP));
- status = CYRET_SUCCESS;
- }
-
- return(status);
-}
-
-
-/*******************************************************************************
-* Function Name: CyDmaClearPendingDrq
-********************************************************************************
-*
-* Summary:
-* Clears pending the DMA data request.
-*
-* Parameters:
-* uint8 chHandle:
-* Handle to the dma channel.
-*
-* Return:
-* CYRET_SUCCESS if successful.
-* CYRET_BAD_PARAM if chHandle is invalid.
-*
-*******************************************************************************/
-cystatus CyDmaClearPendingDrq(uint8 chHandle)
-{
- cystatus status = CYRET_BAD_PARAM;
-
- if(chHandle < CY_DMA_NUMBEROF_CHANNELS)
- {
- CY_DMA_CH_STRUCT_PTR[chHandle].action[0] |= CY_DMA_CPU_TERM_CHAIN;
- CY_DMA_CH_STRUCT_PTR[chHandle].basic_cfg[0] |= 0x01u;
- status = CYRET_SUCCESS;
- }
-
- return(status);
-}
-
-
-/*******************************************************************************
-* Function Name: CyDmaChPriority
-********************************************************************************
-*
-* Summary:
-* Sets the priority of a DMA channel. You can use this function when you want
-* to change the priority at run time. If the priority remains the same for a
-* DMA channel, then you can configure the priority in the .cydwr file.
-*
-* Parameters:
-* uint8 chHandle:
-* A handle previously returned by CyDmaChAlloc() or DMA_DmaInitalize().
-*
-* uint8 priority:
-* Priority to set the channel to, 0 - 7.
-*
-* Return:
-* CYRET_SUCCESS if successful.
-* CYRET_BAD_PARAM if chHandle is invalid.
-*
-*******************************************************************************/
-cystatus CyDmaChPriority(uint8 chHandle, uint8 priority)
-{
- uint8 value;
- cystatus status = CYRET_BAD_PARAM;
-
- if(chHandle < CY_DMA_NUMBEROF_CHANNELS)
- {
- value = CY_DMA_CH_STRUCT_PTR[chHandle].basic_cfg[0u] & ((uint8)(~(0x0Eu)));
-
- CY_DMA_CH_STRUCT_PTR[chHandle].basic_cfg[0u] = value | ((uint8) ((priority & 0x7u) << 0x01u));
-
- status = CYRET_SUCCESS;
- }
-
- return(status);
-}
-
-
-/*******************************************************************************
-* Function Name: CyDmaChSetExtendedAddress
-********************************************************************************
-*
-* Summary:
-* Sets the high 16 bits of the source and destination addresses for the DMA
-* channel (valid for all TDs in the chain).
-*
-* Parameters:
-* uint8 chHandle:
-* A handle previously returned by CyDmaChAlloc() or DMA_DmaInitalize().
-*
-* uint16 source:
-* Upper 16 bit address of the DMA transfer source.
-*
-* uint16 destination:
-* Upper 16 bit address of the DMA transfer destination.
-*
-* Return:
-* CYRET_SUCCESS if successful.
-* CYRET_BAD_PARAM if chHandle is invalid.
-*
-*******************************************************************************/
-cystatus CyDmaChSetExtendedAddress(uint8 chHandle, uint16 source, uint16 destination) \
-
-{
- cystatus status = CYRET_BAD_PARAM;
- reg16 *convert;
-
- #if(CY_PSOC5)
-
- /* 0x1FFF8000-0x1FFFFFFF needs to use alias at 0x20008000-0x2000FFFF */
- if(source == 0x1FFFu)
- {
- source = 0x2000u;
- }
-
- if(destination == 0x1FFFu)
- {
- destination = 0x2000u;
- }
-
- #endif /* (CY_PSOC5) */
-
-
- if(chHandle < CY_DMA_NUMBEROF_CHANNELS)
- {
- /* Set source address */
- convert = (reg16 *) &CY_DMA_CFGMEM_STRUCT_PTR[chHandle].CFG1[0];
- CY_SET_REG16(convert, source);
-
- /* Set destination address */
- convert = (reg16 *) &CY_DMA_CFGMEM_STRUCT_PTR[chHandle].CFG1[2u];
- CY_SET_REG16(convert, destination);
- status = CYRET_SUCCESS;
- }
-
- return(status);
-}
-
-
-/*******************************************************************************
-* Function Name: CyDmaChSetInitialTd
-********************************************************************************
-*
-* Summary:
-* Sets the initial TD to be executed for the channel when the CyDmaChEnable()
-* function is called.
-*
-* Parameters:
-* uint8 chHandle:
-* A handle previously returned by CyDmaChAlloc() or DMA_DmaInitialize().
-*
-* uint8 startTd:
-* Set the TD index as the first TD associated with the channel. Zero is
-* a valid TD index.
-*
-* Return:
-* CYRET_SUCCESS if successful.
-* CYRET_BAD_PARAM if chHandle is invalid.
-*
-*******************************************************************************/
-cystatus CyDmaChSetInitialTd(uint8 chHandle, uint8 startTd)
-{
- cystatus status = CYRET_BAD_PARAM;
-
- if(chHandle < CY_DMA_NUMBEROF_CHANNELS)
- {
- CY_DMA_CH_STRUCT_PTR[chHandle].basic_status[1u] = startTd;
- status = CYRET_SUCCESS;
- }
-
- return(status);
-}
-
-
-/*******************************************************************************
-* Function Name: CyDmaChSetRequest
-********************************************************************************
-*
-* Summary:
-* Allows the caller to terminate a chain of TDs, terminate one TD, or create a
-* direct request to start the DMA channel.
-*
-* Parameters:
-* uint8 chHandle:
-* A handle previously returned by CyDmaChAlloc() or DMA_DmaInitalize().
-*
-* uint8 request:
-* One of the following constants. Each of the constants is a three-bit value.
-*
-* CPU_REQ - Create a direct request to start the DMA channel
-* CPU_TERM_TD - Terminate one TD
-* CPU_TERM_CHAIN - Terminate a chain of TDs
-*
-* Return:
-* CYRET_SUCCESS if successful.
-* CYRET_BAD_PARAM if chHandle is invalid.
-*
-*******************************************************************************/
-cystatus CyDmaChSetRequest(uint8 chHandle, uint8 request)
-{
- cystatus status = CYRET_BAD_PARAM;
-
- if(chHandle < CY_DMA_NUMBEROF_CHANNELS)
- {
- CY_DMA_CH_STRUCT_PTR[chHandle].action[0u] |= (request & (CPU_REQ | CPU_TERM_TD | CPU_TERM_CHAIN));
- status = CYRET_SUCCESS;
- }
-
- return(status);
-}
-
-
-/*******************************************************************************
-* Function Name: CyDmaChGetRequest
-********************************************************************************
-*
-* Summary:
-* This function allows the caller of CyDmaChSetRequest() to determine if the
-* request was completed.
-*
-* Parameters:
-* uint8 chHandle:
-* A handle previously returned by CyDmaChAlloc() or DMA_DmaInitalize().
-*
-* Return:
-* Returns a three-bit field, corresponding to the three bits of the request,
-* which describes the state of the previously posted request. If the value is
-* zero, the request was completed. CY_DMA_INVALID_CHANNEL if the handle is
-* invalid.
-*
-*******************************************************************************/
-cystatus CyDmaChGetRequest(uint8 chHandle)
-{
- cystatus status = CY_DMA_INVALID_CHANNEL;
-
- if(chHandle < CY_DMA_NUMBEROF_CHANNELS)
- {
- status = (cystatus) ((uint32)CY_DMA_CH_STRUCT_PTR[chHandle].action[0u] &
- (uint32)(CY_DMA_CPU_REQ | CY_DMA_CPU_TERM_TD | CY_DMA_CPU_TERM_CHAIN));
- }
-
- return(status);
-}
-
-
-/*******************************************************************************
-* Function Name: CyDmaChStatus
-********************************************************************************
-*
-* Summary:
-* Determines the status of the DMA channel.
-*
-* Parameters:
-* uint8 chHandle:
-* A handle previously returned by CyDmaChAlloc() or DMA_DmaInitalize().
-*
-* uint8 * currentTd:
-* The address to store the index of the current TD. Can be NULL if the value
-* is not needed.
-*
-* uint8 * state:
-* The address to store the state of the channel. Can be NULL if the value is
-* not needed.
-*
-* STATUS_TD_ACTIVE
-* 0: Channel is not currently being serviced by DMAC
-* 1: Channel is currently being serviced by DMAC
-*
-* STATUS_CHAIN_ACTIVE
-* 0: TD chain is inactive; either no DMA requests have triggered a new chain
-* or the previous chain has completed.
-* 1: TD chain has been triggered by a DMA request
-*
-* Return:
-* CYRET_SUCCESS if successful.
-* CYRET_BAD_PARAM if chHandle is invalid.
-*
-* Theory:
-* The caller can check on the activity of the Current TD and the Chain.
-*
-*******************************************************************************/
-cystatus CyDmaChStatus(uint8 chHandle, uint8 * currentTd, uint8 * state)
-{
- cystatus status = CYRET_BAD_PARAM;
-
- if(chHandle < CY_DMA_NUMBEROF_CHANNELS)
- {
- if(NULL != currentTd)
- {
- *currentTd = CY_DMA_CH_STRUCT_PTR[chHandle].basic_status[1] & 0x7Fu;
- }
-
- if(NULL != state)
- {
- *state= CY_DMA_CH_STRUCT_PTR[chHandle].basic_status[0];
- }
-
- status = CYRET_SUCCESS;
- }
-
- return (status);
-}
-
-
-/*******************************************************************************
-* Function Name: CyDmaChSetConfiguration
-********************************************************************************
-*
-* Summary:
-* Sets configuration information of the channel.
-*
-* Parameters:
-* uint8 chHandle:
-* A handle previously returned by CyDmaChAlloc() or DMA_DmaInitialize().
-*
-* uint8 burstCount:
-* Specifies the size of bursts (1 to 127) the data transfer should be divided
-* into. If this value is zero then the whole transfer is done in one burst.
-*
-* uint8 requestPerBurst:
-* The whole of the data can be split into multiple bursts, if this is
-* required to complete the transaction:
-* 0: All subsequent bursts after the first burst will be automatically
-* requested and carried out
-* 1: All subsequent bursts after the first burst must also be individually
-* requested.
-*
-* uint8 tdDone0:
-* Selects one of the TERMOUT0 interrupt lines to signal completion. The line
-* connected to the nrq terminal will determine the TERMOUT0_SEL definition and
-* should be used as supplied by cyfitter.h
-*
-* uint8 tdDone1:
-* Selects one of the TERMOUT1 interrupt lines to signal completion. The line
-* connected to the nrq terminal will determine the TERMOUT1_SEL definition and
-* should be used as supplied by cyfitter.h
-*
-* uint8 tdStop:
-* Selects one of the TERMIN interrupt lines to signal to the DMAC that the TD
-* should terminate. The signal connected to the trq terminal will determine
-* which TERMIN (termination request) is used.
-*
-* Return:
-* CYRET_SUCCESS if successful.
-* CYRET_BAD_PARAM if chHandle is invalid.
-*
-*******************************************************************************/
-cystatus CyDmaChSetConfiguration(uint8 chHandle, uint8 burstCount, uint8 requestPerBurst,
- uint8 tdDone0, uint8 tdDone1, uint8 tdStop)
-{
- cystatus status = CYRET_BAD_PARAM;
-
- if(chHandle < CY_DMA_NUMBEROF_CHANNELS)
- {
- CY_DMA_CFGMEM_STRUCT_PTR[chHandle].CFG0[0] = (burstCount & 0x7Fu) | ((uint8)((requestPerBurst & 0x1u) << 7u));
- CY_DMA_CFGMEM_STRUCT_PTR[chHandle].CFG0[1] = ((uint8)((tdDone1 & 0xFu) << 4u)) | (tdDone0 & 0xFu);
- CY_DMA_CFGMEM_STRUCT_PTR[chHandle].CFG0[2] = 0x0Fu & tdStop;
- CY_DMA_CFGMEM_STRUCT_PTR[chHandle].CFG0[3] = 0u; /* burstcount_remain. */
-
- status = CYRET_SUCCESS;
- }
-
- return (status);
-}
-
-
-/*******************************************************************************
-* Function Name: CyDmaTdAllocate
-********************************************************************************
-*
-* Summary:
-* Allocates a TD for use with an allocated DMA channel.
-*
-* Parameters:
-* None
-*
-* Return:
-* Zero-based index of the TD to be used by the caller. Since there are 128 TDs
-* minus the reserved TDs (0 to 23), the value returned would range from 24 to
-* 127 not 24 to 128. DMA_INVALID_TD is returned if there are no free TDs
-* available.
-*
-*******************************************************************************/
-uint8 CyDmaTdAllocate(void)
-{
- uint8 interruptState;
- uint8 element = CY_DMA_INVALID_TD;
-
- /* Enter critical section! */
- interruptState = CyEnterCriticalSection();
-
- if(CyDmaTdCurrentNumber > NUMBEROF_CHANNELS)
- {
- /* Get pointer to Next available. */
- element = CyDmaTdFreeIndex;
-
- /* Decrement the count. */
- CyDmaTdCurrentNumber--;
-
- /* Update next available pointer. */
- CyDmaTdFreeIndex = CY_DMA_TDMEM_STRUCT_PTR[element].TD0[0];
- }
-
- /* Exit critical section! */
- CyExitCriticalSection(interruptState);
-
- return(element);
-}
-
-
-/*******************************************************************************
-* Function Name: CyDmaTdFree
-********************************************************************************
-*
-* Summary:
-* Returns a TD to the free list.
-*
-* Parameters:
-* uint8 tdHandle:
-* The TD handle returned by the CyDmaTdAllocate().
-*
-* Return:
-* None
-*
-*******************************************************************************/
-void CyDmaTdFree(uint8 tdHandle)
-{
- if(tdHandle < CY_DMA_NUMBEROF_TDS)
- {
- /* Enter critical section! */
- uint8 interruptState = CyEnterCriticalSection();
-
- /* Get pointer to Next available. */
- CY_DMA_TDMEM_STRUCT_PTR[tdHandle].TD0[0u] = CyDmaTdFreeIndex;
-
- /* Set new Next Available. */
- CyDmaTdFreeIndex = tdHandle;
-
- /* Keep track of how many left. */
- CyDmaTdCurrentNumber++;
-
- /* Exit critical section! */
- CyExitCriticalSection(interruptState);
- }
-}
-
-
-/*******************************************************************************
-* Function Name: CyDmaTdFreeCount
-********************************************************************************
-*
-* Summary:
-* Returns the number of free TDs available to be allocated.
-*
-* Parameters:
-* None
-*
-* Return:
-* The number of free TDs.
-*
-*******************************************************************************/
-uint8 CyDmaTdFreeCount(void)
-{
- return(CyDmaTdCurrentNumber - CY_DMA_NUMBEROF_CHANNELS);
-}
-
-
-/*******************************************************************************
-* Function Name: CyDmaTdSetConfiguration
-********************************************************************************
-*
-* Summary:
-* Configures the TD.
-*
-* Parameters:
-* uint8 tdHandle:
-* A handle previously returned by CyDmaTdAlloc().
-*
-* uint16 transferCount:
-* The size of the data transfer (in bytes) for this TD. A size of zero will
-* cause the transfer to continue indefinitely. This parameter is limited to
-* 4095 bytes; the TD is not initialized at all when a higher value is passed.
-*
-* uint8 nextTd:
-* Zero based index of the next Transfer Descriptor in the TD chain. Zero is a
-* valid pointer to the next TD; DMA_END_CHAIN_TD is the end of the chain.
-* DMA_DISABLE_TD indicates an end to the chain and the DMA is disabled. No
-* further TDs are fetched. DMA_DISABLE_TD is only supported on PSoC3 and
-* PSoC 5LP silicons.
-*
-* uint8 configuration:
-* Stores the Bit field of configuration bits.
-*
-* CY_DMA_TD_SWAP_EN - Perform endian swap
-*
-* CY_DMA_TD_SWAP_SIZE4 - Swap size = 4 bytes
-*
-* CY_DMA_TD_AUTO_EXEC_NEXT - The next TD in the chain will trigger
-* automatically when the current TD completes.
-*
-* CY_DMA_TD_TERMIN_EN - Terminate this TD if a positive edge on the trq
-* input line occurs. The positive edge must occur
-* during a burst. That is the only time the DMAC
-* will listen for it.
-*
-* DMA__TD_TERMOUT_EN - When this TD completes, the TERMOUT signal will
-* generate a pulse. Note that this option is
-* instance specific with the instance name followed
-* by two underscores. In this example, the instance
-* name is DMA.
-*
-* CY_DMA_TD_INC_DST_ADR - Increment DST_ADR according to the size of each
-* data transaction in the burst.
-*
-* CY_DMA_TD_INC_SRC_ADR - Increment SRC_ADR according to the size of each
-* data transaction in the burst.
-*
-* Return:
-* CYRET_SUCCESS if successful.
-* CYRET_BAD_PARAM if tdHandle or transferCount is invalid.
-*
-*******************************************************************************/
-cystatus CyDmaTdSetConfiguration(uint8 tdHandle, uint16 transferCount, uint8 nextTd, uint8 configuration) \
-
-{
- cystatus status = CYRET_BAD_PARAM;
-
- if((tdHandle < CY_DMA_NUMBEROF_TDS) && (0u == (0xF000u & transferCount)))
- {
- /* Set 12 bits transfer count. */
- reg16 *convert = (reg16 *) &CY_DMA_TDMEM_STRUCT_PTR[tdHandle].TD0[0u];
- CY_SET_REG16(convert, transferCount);
-
- /* Set Next TD pointer. */
- CY_DMA_TDMEM_STRUCT_PTR[tdHandle].TD0[2u] = nextTd;
-
- /* Configure the TD */
- CY_DMA_TDMEM_STRUCT_PTR[tdHandle].TD0[3u] = configuration;
-
- status = CYRET_SUCCESS;
- }
-
- return(status);
-}
-
-
-/*******************************************************************************
-* Function Name: CyDmaTdGetConfiguration
-********************************************************************************
-*
-* Summary:
-* Retrieves the configuration of the TD. If a NULL pointer is passed as a
-* parameter, that parameter is skipped. You may request only the values you are
-* interested in.
-*
-* Parameters:
-* uint8 tdHandle:
-* A handle previously returned by CyDmaTdAlloc().
-*
-* uint16 * transferCount:
-* The address to store the size of the data transfer (in bytes) for this TD.
-* A size of zero could indicate that the TD has completed its transfer, or
-* that the TD is doing an indefinite transfer.
-*
-* uint8 * nextTd:
-* The address to store the index of the next TD in the TD chain.
-*
-* uint8 * configuration:
-* The address to store the Bit field of configuration bits.
-* See CyDmaTdSetConfiguration() function description.
-*
-* Return:
-* CYRET_SUCCESS if successful.
-* CYRET_BAD_PARAM if tdHandle is invalid.
-*
-* Side Effects:
-* If TD has a transfer count of N and is executed, the transfer count becomes
-* 0. If it is reexecuted, the Transfer count of zero will be interpreted as a
-* request for indefinite transfer. Be careful when requesting TD with a
-* transfer count of zero.
-*
-*******************************************************************************/
-cystatus CyDmaTdGetConfiguration(uint8 tdHandle, uint16 * transferCount, uint8 * nextTd, uint8 * configuration) \
-
-{
- cystatus status = CYRET_BAD_PARAM;
-
- if(tdHandle < CY_DMA_NUMBEROF_TDS)
- {
- /* If we have pointer */
- if(NULL != transferCount)
- {
- /* Get 12 bits of transfer count */
- reg16 *convert = (reg16 *) &CY_DMA_TDMEM_STRUCT_PTR[tdHandle].TD0[0];
- *transferCount = 0x0FFFu & CY_GET_REG16(convert);
- }
-
- /* If we have pointer */
- if(NULL != nextTd)
- {
- /* Get Next TD pointer */
- *nextTd = CY_DMA_TDMEM_STRUCT_PTR[tdHandle].TD0[2u];
- }
-
- /* If we have pointer */
- if(NULL != configuration)
- {
- /* Get configuration TD */
- *configuration = CY_DMA_TDMEM_STRUCT_PTR[tdHandle].TD0[3u];
- }
-
- status = CYRET_SUCCESS;
- }
-
- return(status);
-}
-
-
-/*******************************************************************************
-* Function Name: CyDmaTdSetAddress
-********************************************************************************
-*
-* Summary:
-* Sets the lower 16 bits of the source and destination addresses for this TD
-* only.
-*
-* Parameters:
-* uint8 tdHandle:
-* A handle previously returned by CyDmaTdAlloc().
-*
-* uint16 source:
-* The lower 16 address bits of the source of the data transfer.
-*
-* uint16 destination:
-* The lower 16 address bits of the destination of the data transfer.
-*
-* Return:
-* CYRET_SUCCESS if successful.
-* CYRET_BAD_PARAM if tdHandle is invalid.
-*
-*******************************************************************************/
-cystatus CyDmaTdSetAddress(uint8 tdHandle, uint16 source, uint16 destination)
-{
- cystatus status = CYRET_BAD_PARAM;
- reg16 *convert;
-
- if(tdHandle < CY_DMA_NUMBEROF_TDS)
- {
- /* Set source address */
- convert = (reg16 *) &CY_DMA_TDMEM_STRUCT_PTR[tdHandle].TD1[0u];
- CY_SET_REG16(convert, source);
-
- /* Set destination address */
- convert = (reg16 *) &CY_DMA_TDMEM_STRUCT_PTR[tdHandle].TD1[2u];
- CY_SET_REG16(convert, destination);
-
- status = CYRET_SUCCESS;
- }
-
- return(status);
-}
-
-
-/*******************************************************************************
-* Function Name: CyDmaTdGetAddress
-********************************************************************************
-*
-* Summary:
-* Retrieves the lower 16 bits of the source and/or destination addresses for
-* this TD only. If NULL is passed for a pointer parameter, that value is
-* skipped. You may request only the values of interest.
-*
-* Parameters:
-* uint8 tdHandle:
-* A handle previously returned by CyDmaTdAlloc().
-*
-* uint16 * source:
-* The address to store the lower 16 address bits of the source of the data
-* transfer.
-*
-* uint16 * destination:
-* The address to store the lower 16 address bits of the destination of the
-* data transfer.
-*
-* Return:
-* CYRET_SUCCESS if successful.
-* CYRET_BAD_PARAM if tdHandle is invalid.
-*
-*******************************************************************************/
-cystatus CyDmaTdGetAddress(uint8 tdHandle, uint16 * source, uint16 * destination)
-{
- cystatus status = CYRET_BAD_PARAM;
- reg16 *convert;
-
- if(tdHandle < CY_DMA_NUMBEROF_TDS)
- {
- /* If we have a pointer. */
- if(NULL != source)
- {
- /* Get source address */
- convert = (reg16 *) &CY_DMA_TDMEM_STRUCT_PTR[tdHandle].TD1[0u];
- *source = CY_GET_REG16(convert);
- }
-
- /* If we have a pointer. */
- if(NULL != destination)
- {
- /* Get Destination address. */
- convert = (reg16 *) &CY_DMA_TDMEM_STRUCT_PTR[tdHandle].TD1[2u];
- *destination = CY_GET_REG16(convert);
- }
-
- status = CYRET_SUCCESS;
- }
-
- return(status);
-}
-
-
-/*******************************************************************************
-* Function Name: CyDmaChRoundRobin
-********************************************************************************
-*
-* Summary:
-* Either enables or disables the Round-Robin scheduling enforcement algorithm.
-* Within a priority level a Round-Robin fairness algorithm is enforced.
-*
-* Parameters:
-* uint8 chHandle:
-* A handle previously returned by CyDmaChAlloc() or Dma_DmaInitialize().
-*
-* uint8 enableRR:
-* 0: Disable Round-Robin fairness algorithm
-* 1: Enable Round-Robin fairness algorithm
-*
-* Return:
-* CYRET_SUCCESS if successful.
-* CYRET_BAD_PARAM if chHandle is invalid.
-*
-*******************************************************************************/
-cystatus CyDmaChRoundRobin(uint8 chHandle, uint8 enableRR)
-{
- cystatus status = CYRET_BAD_PARAM;
-
- if(chHandle < CY_DMA_NUMBEROF_CHANNELS)
- {
- if (0u != enableRR)
- {
- CY_DMA_CH_STRUCT_PTR[chHandle].basic_cfg[0u] |= (uint8)CY_DMA_ROUND_ROBIN_ENABLE;
- }
- else
- {
- CY_DMA_CH_STRUCT_PTR[chHandle].basic_cfg[0u] &= (uint8)(~CY_DMA_ROUND_ROBIN_ENABLE);
- }
-
- status = CYRET_SUCCESS;
- }
-
- return(status);
-}
-
-
-/* [] END OF FILE */
+/*******************************************************************************\r
+* File Name: CyDmac.c\r
+* Version 4.20\r
+*\r
+* Description:\r
+* Provides an API for the DMAC component. The API includes functions for the\r
+* DMA controller, DMA channels and Transfer Descriptors.\r
+*\r
+* This API is the library version not the auto generated code that gets\r
+* generated when the user places a DMA component on the schematic.\r
+*\r
+* The auto generated code would use the APi's in this module.\r
+*\r
+* Note:\r
+* This code is endian agnostic.\r
+*\r
+* The Transfer Descriptor memory can be used as regular memory if the TD's are\r
+* not being used.\r
+*\r
+* This code uses the first byte of each TD to manage the free list of TD's.\r
+* The user can overwrite this once the TD is allocated.\r
+*\r
+********************************************************************************\r
+* Copyright 2008-2014, Cypress Semiconductor Corporation. All rights reserved.\r
+* You may use this file only in accordance with the license, terms, conditions,\r
+* disclaimers, and limitations in the end user license agreement accompanying\r
+* the software package with which this file was provided.\r
+*******************************************************************************/\r
+\r
+#include "CyDmac.h"\r
+\r
+\r
+/*******************************************************************************\r
+* The following variables are initialized from CyDmacConfigure() function that\r
+* is executed from initialize_psoc() at the early initialization stage.\r
+* In case of IAR EW IDE, initialize_psoc() is executed before the data sections\r
+* are initialized. To avoid zeroing, these variables should be initialized\r
+* properly during segments initialization as well.\r
+*******************************************************************************/\r
+static uint8 CyDmaTdCurrentNumber = CY_DMA_NUMBEROF_TDS; /* Current Number of free elements on list */\r
+static uint8 CyDmaTdFreeIndex = (uint8)(CY_DMA_NUMBEROF_TDS - 1u); /* Index of first available TD */\r
+static uint32 CyDmaChannels = DMA_CHANNELS_USED__MASK0; /* Bit map of DMA channel ownership */\r
+\r
+\r
+/*******************************************************************************\r
+* Function Name: CyDmacConfigure\r
+********************************************************************************\r
+*\r
+* Summary:\r
+* Creates a linked list of all the TDs to be allocated. This function is called\r
+* by the startup code; you do not normally need to call it. You can call this\r
+* function if all of the DMA channels are inactive.\r
+*\r
+* Parameters:\r
+* None\r
+*\r
+* Return:\r
+* None\r
+*\r
+*******************************************************************************/\r
+void CyDmacConfigure(void) \r
+{\r
+ uint8 dmaIndex;\r
+\r
+ /* Set TD list variables. */\r
+ CyDmaTdFreeIndex = (uint8)(CY_DMA_NUMBEROF_TDS - 1u);\r
+ CyDmaTdCurrentNumber = CY_DMA_NUMBEROF_TDS;\r
+\r
+ /* Make TD free list. */\r
+ for(dmaIndex = (uint8)(CY_DMA_NUMBEROF_TDS - 1u); dmaIndex != 0u; dmaIndex--)\r
+ {\r
+ CY_DMA_TDMEM_STRUCT_PTR[dmaIndex].TD0[0u] = (uint8)(dmaIndex - 1u);\r
+ }\r
+\r
+ /* Make last one point to zero. */\r
+ CY_DMA_TDMEM_STRUCT_PTR[dmaIndex].TD0[0u] = 0u;\r
+}\r
+\r
+\r
+/*******************************************************************************\r
+* Function Name: CyDmacError\r
+********************************************************************************\r
+*\r
+* Summary:\r
+* Returns errors of the last failed DMA transaction.\r
+*\r
+* Parameters:\r
+* None\r
+*\r
+* Return:\r
+* Errors of the last failed DMA transaction.\r
+*\r
+* DMAC_PERIPH_ERR:\r
+* Set to 1 when a peripheral responds to a bus transaction with an error\r
+* response.\r
+*\r
+* DMAC_UNPOP_ACC:\r
+* Set to 1 when an access is attempted to an invalid address.\r
+*\r
+* DMAC_BUS_TIMEOUT:\r
+* Set to 1 when a bus timeout occurs. Cleared by writing a 1. Timeout values\r
+* are determined by the BUS_TIMEOUT field in the PHUBCFG register.\r
+*\r
+* Theory:\r
+* Once an error occurs the error bits are sticky and are only cleared by \r
+* writing 1 to the error register.\r
+*\r
+*******************************************************************************/\r
+uint8 CyDmacError(void) \r
+{\r
+ return((uint8)(((uint32) 0x0Fu) & *CY_DMA_ERR_PTR));\r
+}\r
+\r
+\r
+/*******************************************************************************\r
+* Function Name: CyDmacClearError\r
+********************************************************************************\r
+*\r
+* Summary:\r
+* Clears the error bits in the error register of the DMAC.\r
+*\r
+* Parameters:\r
+* error:\r
+* Clears the error bits in the DMAC error register.\r
+*\r
+* DMAC_PERIPH_ERR:\r
+* Set to 1 when a peripheral responds to a bus transaction with an error\r
+* response.\r
+*\r
+* DMAC_UNPOP_ACC:\r
+* Set to 1 when an access is attempted to an invalid address.\r
+*\r
+* DMAC_BUS_TIMEOUT:\r
+* Set to 1 when a bus timeout occurs. Cleared by writing 1. Timeout values\r
+* are determined by the BUS_TIMEOUT field in the PHUBCFG register.\r
+*\r
+* Return:\r
+* None\r
+*\r
+* Theory:\r
+* Once an error occurs the error bits are sticky and are only cleared by \r
+* writing 1 to the error register.\r
+*\r
+*******************************************************************************/\r
+void CyDmacClearError(uint8 error) \r
+{\r
+ *CY_DMA_ERR_PTR = (((uint32)0x0Fu) & ((uint32)error));\r
+}\r
+\r
+\r
+/*******************************************************************************\r
+* Function Name: CyDmacErrorAddress\r
+********************************************************************************\r
+*\r
+* Summary:\r
+* When DMAC_BUS_TIMEOUT, DMAC_UNPOP_ACC, and DMAC_PERIPH_ERR occur the\r
+* address of the error is written to the error address register and can be read\r
+* with this function.\r
+*\r
+* If there are multiple errors, only the address of the first is saved.\r
+*\r
+* Parameters:\r
+* None\r
+*\r
+* Return:\r
+* The address that caused the error.\r
+*\r
+*******************************************************************************/\r
+uint32 CyDmacErrorAddress(void) \r
+{\r
+ return(CY_GET_REG32(CY_DMA_ERR_ADR_PTR));\r
+}\r
+\r
+\r
+/*******************************************************************************\r
+* Function Name: CyDmaChAlloc\r
+********************************************************************************\r
+*\r
+* Summary:\r
+* Allocates a channel from the DMAC to be used in all functions that require a\r
+* channel handle.\r
+*\r
+* Parameters:\r
+* None\r
+*\r
+* Return:\r
+* The allocated channel number. Zero is a valid channel number.\r
+* DMA_INVALID_CHANNEL is returned if there are no channels available.\r
+*\r
+*******************************************************************************/\r
+uint8 CyDmaChAlloc(void) \r
+{\r
+ uint8 interruptState;\r
+ uint8 dmaIndex;\r
+ uint32 channel = 1u;\r
+\r
+\r
+ /* Enter critical section! */\r
+ interruptState = CyEnterCriticalSection();\r
+\r
+ /* Look for free channel. */\r
+ for(dmaIndex = 0u; dmaIndex < CY_DMA_NUMBEROF_CHANNELS; dmaIndex++)\r
+ {\r
+ if(0uL == (CyDmaChannels & channel))\r
+ {\r
+ /* Mark channel as used. */\r
+ CyDmaChannels |= channel;\r
+ break;\r
+ }\r
+\r
+ channel <<= 1u;\r
+ }\r
+\r
+ if(dmaIndex >= CY_DMA_NUMBEROF_CHANNELS)\r
+ {\r
+ dmaIndex = CY_DMA_INVALID_CHANNEL;\r
+ }\r
+\r
+ /* Exit critical section! */\r
+ CyExitCriticalSection(interruptState);\r
+\r
+ return(dmaIndex);\r
+}\r
+\r
+\r
+/*******************************************************************************\r
+* Function Name: CyDmaChFree\r
+********************************************************************************\r
+*\r
+* Summary:\r
+* Frees a channel allocated by DmaChAlloc().\r
+*\r
+* Parameters:\r
+* uint8 chHandle:\r
+* The handle previously returned by CyDmaChAlloc() or DMA_DmaInitalize().\r
+*\r
+* Return:\r
+* CYRET_SUCCESS if successful.\r
+* CYRET_BAD_PARAM if chHandle is invalid.\r
+*\r
+*******************************************************************************/\r
+cystatus CyDmaChFree(uint8 chHandle) \r
+{\r
+ cystatus status = CYRET_BAD_PARAM;\r
+ uint8 interruptState;\r
+\r
+ if(chHandle < CY_DMA_NUMBEROF_CHANNELS)\r
+ {\r
+ /* Enter critical section */\r
+ interruptState = CyEnterCriticalSection();\r
+\r
+ /* Clear bit mask that keeps track of ownership. */\r
+ CyDmaChannels &= ~(((uint32) 1u) << chHandle);\r
+\r
+ /* Exit critical section */\r
+ CyExitCriticalSection(interruptState);\r
+ status = CYRET_SUCCESS;\r
+ }\r
+\r
+ return(status);\r
+}\r
+\r
+\r
+/*******************************************************************************\r
+* Function Name: CyDmaChEnable\r
+********************************************************************************\r
+*\r
+* Summary:\r
+* Enables the DMA channel. A software or hardware request still must happen\r
+* before the channel is executed.\r
+*\r
+* Parameters:\r
+* uint8 chHandle:\r
+* A handle previously returned by CyDmaChAlloc() or DMA_DmaInitalize().\r
+*\r
+* uint8 preserveTds:\r
+* Preserves the original TD state when the TD has completed. This parameter\r
+* applies to all TDs in the channel.\r
+*\r
+* 0 - When TD is completed, the DMAC leaves the TD configuration values in\r
+* their current state, and does not restore them to their original state.\r
+*\r
+* 1 - When TD is completed, the DMAC restores the original configuration\r
+* values of the TD.\r
+*\r
+* When preserveTds is set, the TD slot that equals the channel number becomes\r
+* RESERVED and that becomes where the working registers exist. So, for example,\r
+* if you are using CH06 and preserveTds is set, you are not allowed to use TD\r
+* slot 6. That is reclaimed by the DMA engine for its private use.\r
+*\r
+* Note Do not chain back to a completed TD if the preserveTds for the channel\r
+* is set to 0. When a TD has completed preserveTds for the channel set to 0,\r
+* the transfer count will be at 0. If a TD with a transfer count of 0 is\r
+* started, the TD will transfer an indefinite amount of data.\r
+*\r
+* Take extra precautions when using the hardware request (DRQ) option when the\r
+* preserveTds is set to 0, as you might be requesting the wrong data.\r
+*\r
+* Return:\r
+* CYRET_SUCCESS if successful.\r
+* CYRET_BAD_PARAM if chHandle is invalid.\r
+*\r
+*******************************************************************************/\r
+cystatus CyDmaChEnable(uint8 chHandle, uint8 preserveTds) \r
+{\r
+ cystatus status = CYRET_BAD_PARAM;\r
+\r
+ if(chHandle < CY_DMA_NUMBEROF_CHANNELS)\r
+ {\r
+ if (0u != preserveTds)\r
+ {\r
+ /* Store intermediate TD states separately in CHn_SEP_TD0/1 to\r
+ * preserve original TD chain\r
+ */\r
+ CY_DMA_CH_STRUCT_PTR[chHandle].basic_cfg[0u] |= CY_DMA_CH_BASIC_CFG_WORK_SEP;\r
+ }\r
+ else\r
+ {\r
+ /* Store intermediate and final TD states on top of original TD chain */\r
+ CY_DMA_CH_STRUCT_PTR[chHandle].basic_cfg[0u] &= (uint8)(~CY_DMA_CH_BASIC_CFG_WORK_SEP);\r
+ }\r
+\r
+ /* Enable channel */\r
+ CY_DMA_CH_STRUCT_PTR[chHandle].basic_cfg[0u] |= CY_DMA_CH_BASIC_CFG_EN;\r
+\r
+ status = CYRET_SUCCESS;\r
+ }\r
+\r
+ return(status);\r
+}\r
+\r
+\r
+/*******************************************************************************\r
+* Function Name: CyDmaChDisable\r
+********************************************************************************\r
+*\r
+* Summary:\r
+* Disables the DMA channel. Once this function is called, CyDmaChStatus() may\r
+* be called to determine when the channel is disabled and which TDs were being\r
+* executed.\r
+*\r
+* If it is currently executing it will allow the current burst to finish\r
+* naturally.\r
+*\r
+* Parameters:\r
+* uint8 chHandle:\r
+* A handle previously returned by CyDmaChAlloc() or DMA_DmaInitalize().\r
+*\r
+* Return:\r
+* CYRET_SUCCESS if successful.\r
+* CYRET_BAD_PARAM if chHandle is invalid.\r
+*\r
+*******************************************************************************/\r
+cystatus CyDmaChDisable(uint8 chHandle) \r
+{\r
+ cystatus status = CYRET_BAD_PARAM;\r
+\r
+ if(chHandle < CY_DMA_NUMBEROF_CHANNELS)\r
+ {\r
+ /***********************************************************************\r
+ * Should not change configuration information of a DMA channel when it\r
+ * is active (or vulnerable to becoming active).\r
+ ***********************************************************************/\r
+\r
+ /* Disable channel */\r
+ CY_DMA_CH_STRUCT_PTR[chHandle].basic_cfg[0] &= ((uint8) (~CY_DMA_CH_BASIC_CFG_EN));\r
+\r
+ /* Store intermediate and final TD states on top of original TD chain */\r
+ CY_DMA_CH_STRUCT_PTR[chHandle].basic_cfg[0] &= ((uint8) (~CY_DMA_CH_BASIC_CFG_WORK_SEP));\r
+ status = CYRET_SUCCESS;\r
+ }\r
+\r
+ return(status);\r
+}\r
+\r
+\r
+/*******************************************************************************\r
+* Function Name: CyDmaClearPendingDrq\r
+********************************************************************************\r
+*\r
+* Summary:\r
+* Clears pending the DMA data request.\r
+*\r
+* Parameters:\r
+* uint8 chHandle:\r
+* Handle to the dma channel.\r
+*\r
+* Return:\r
+* CYRET_SUCCESS if successful.\r
+* CYRET_BAD_PARAM if chHandle is invalid.\r
+*\r
+*******************************************************************************/\r
+cystatus CyDmaClearPendingDrq(uint8 chHandle) \r
+{\r
+ cystatus status = CYRET_BAD_PARAM;\r
+\r
+ if(chHandle < CY_DMA_NUMBEROF_CHANNELS)\r
+ {\r
+ CY_DMA_CH_STRUCT_PTR[chHandle].action[0] |= CY_DMA_CPU_TERM_CHAIN;\r
+ CY_DMA_CH_STRUCT_PTR[chHandle].basic_cfg[0] |= 0x01u;\r
+ status = CYRET_SUCCESS;\r
+ }\r
+\r
+ return(status);\r
+}\r
+\r
+\r
+/*******************************************************************************\r
+* Function Name: CyDmaChPriority\r
+********************************************************************************\r
+*\r
+* Summary:\r
+* Sets the priority of a DMA channel. You can use this function when you want\r
+* to change the priority at run time. If the priority remains the same for a\r
+* DMA channel, then you can configure the priority in the .cydwr file.\r
+*\r
+* Parameters:\r
+* uint8 chHandle:\r
+* A handle previously returned by CyDmaChAlloc() or DMA_DmaInitalize().\r
+*\r
+* uint8 priority:\r
+* Priority to set the channel to, 0 - 7.\r
+*\r
+* Return:\r
+* CYRET_SUCCESS if successful.\r
+* CYRET_BAD_PARAM if chHandle is invalid.\r
+*\r
+*******************************************************************************/\r
+cystatus CyDmaChPriority(uint8 chHandle, uint8 priority) \r
+{\r
+ uint8 value;\r
+ cystatus status = CYRET_BAD_PARAM;\r
+\r
+ if(chHandle < CY_DMA_NUMBEROF_CHANNELS)\r
+ {\r
+ value = CY_DMA_CH_STRUCT_PTR[chHandle].basic_cfg[0u] & ((uint8)(~(0x0Eu)));\r
+\r
+ CY_DMA_CH_STRUCT_PTR[chHandle].basic_cfg[0u] = value | ((uint8) ((priority & 0x7u) << 0x01u));\r
+\r
+ status = CYRET_SUCCESS;\r
+ }\r
+\r
+ return(status);\r
+}\r
+\r
+\r
+/*******************************************************************************\r
+* Function Name: CyDmaChSetExtendedAddress\r
+********************************************************************************\r
+*\r
+* Summary:\r
+* Sets the high 16 bits of the source and destination addresses for the DMA\r
+* channel (valid for all TDs in the chain).\r
+*\r
+* Parameters:\r
+* uint8 chHandle:\r
+* A handle previously returned by CyDmaChAlloc() or DMA_DmaInitalize().\r
+*\r
+* uint16 source:\r
+* Upper 16 bit address of the DMA transfer source.\r
+*\r
+* uint16 destination:\r
+* Upper 16 bit address of the DMA transfer destination.\r
+*\r
+* Return:\r
+* CYRET_SUCCESS if successful.\r
+* CYRET_BAD_PARAM if chHandle is invalid.\r
+*\r
+*******************************************************************************/\r
+cystatus CyDmaChSetExtendedAddress(uint8 chHandle, uint16 source, uint16 destination) \\r
+ \r
+{\r
+ cystatus status = CYRET_BAD_PARAM;\r
+ reg16 *convert;\r
+\r
+ #if(CY_PSOC5)\r
+\r
+ /* 0x1FFF8000-0x1FFFFFFF needs to use alias at 0x20008000-0x2000FFFF */\r
+ if(source == 0x1FFFu)\r
+ {\r
+ source = 0x2000u;\r
+ }\r
+\r
+ if(destination == 0x1FFFu)\r
+ {\r
+ destination = 0x2000u;\r
+ }\r
+\r
+ #endif /* (CY_PSOC5) */\r
+\r
+\r
+ if(chHandle < CY_DMA_NUMBEROF_CHANNELS)\r
+ {\r
+ /* Set source address */\r
+ convert = (reg16 *) &CY_DMA_CFGMEM_STRUCT_PTR[chHandle].CFG1[0];\r
+ CY_SET_REG16(convert, source);\r
+\r
+ /* Set destination address */\r
+ convert = (reg16 *) &CY_DMA_CFGMEM_STRUCT_PTR[chHandle].CFG1[2u];\r
+ CY_SET_REG16(convert, destination);\r
+ status = CYRET_SUCCESS;\r
+ }\r
+\r
+ return(status);\r
+}\r
+\r
+\r
+/*******************************************************************************\r
+* Function Name: CyDmaChSetInitialTd\r
+********************************************************************************\r
+*\r
+* Summary:\r
+* Sets the initial TD to be executed for the channel when the CyDmaChEnable()\r
+* function is called.\r
+*\r
+* Parameters:\r
+* uint8 chHandle:\r
+* A handle previously returned by CyDmaChAlloc() or DMA_DmaInitialize().\r
+*\r
+* uint8 startTd:\r
+* Set the TD index as the first TD associated with the channel. Zero is\r
+* a valid TD index.\r
+*\r
+* Return:\r
+* CYRET_SUCCESS if successful.\r
+* CYRET_BAD_PARAM if chHandle is invalid.\r
+*\r
+*******************************************************************************/\r
+cystatus CyDmaChSetInitialTd(uint8 chHandle, uint8 startTd) \r
+{\r
+ cystatus status = CYRET_BAD_PARAM;\r
+\r
+ if(chHandle < CY_DMA_NUMBEROF_CHANNELS)\r
+ {\r
+ CY_DMA_CH_STRUCT_PTR[chHandle].basic_status[1u] = startTd;\r
+ status = CYRET_SUCCESS;\r
+ }\r
+\r
+ return(status);\r
+}\r
+\r
+\r
+/*******************************************************************************\r
+* Function Name: CyDmaChSetRequest\r
+********************************************************************************\r
+*\r
+* Summary:\r
+* Allows the caller to terminate a chain of TDs, terminate one TD, or create a\r
+* direct request to start the DMA channel.\r
+*\r
+* Parameters:\r
+* uint8 chHandle:\r
+* A handle previously returned by CyDmaChAlloc() or DMA_DmaInitalize().\r
+*\r
+* uint8 request:\r
+* One of the following constants. Each of the constants is a three-bit value.\r
+*\r
+* CPU_REQ - Create a direct request to start the DMA channel\r
+* CPU_TERM_TD - Terminate one TD\r
+* CPU_TERM_CHAIN - Terminate a chain of TDs\r
+*\r
+* Return:\r
+* CYRET_SUCCESS if successful.\r
+* CYRET_BAD_PARAM if chHandle is invalid.\r
+*\r
+*******************************************************************************/\r
+cystatus CyDmaChSetRequest(uint8 chHandle, uint8 request) \r
+{\r
+ cystatus status = CYRET_BAD_PARAM;\r
+\r
+ if(chHandle < CY_DMA_NUMBEROF_CHANNELS)\r
+ {\r
+ CY_DMA_CH_STRUCT_PTR[chHandle].action[0u] |= (request & (CPU_REQ | CPU_TERM_TD | CPU_TERM_CHAIN));\r
+ status = CYRET_SUCCESS;\r
+ }\r
+\r
+ return(status);\r
+}\r
+\r
+\r
+/*******************************************************************************\r
+* Function Name: CyDmaChGetRequest\r
+********************************************************************************\r
+*\r
+* Summary:\r
+* This function allows the caller of CyDmaChSetRequest() to determine if the\r
+* request was completed.\r
+*\r
+* Parameters:\r
+* uint8 chHandle:\r
+* A handle previously returned by CyDmaChAlloc() or DMA_DmaInitalize().\r
+*\r
+* Return:\r
+* Returns a three-bit field, corresponding to the three bits of the request,\r
+* which describes the state of the previously posted request. If the value is\r
+* zero, the request was completed. CY_DMA_INVALID_CHANNEL if the handle is\r
+* invalid.\r
+*\r
+*******************************************************************************/\r
+cystatus CyDmaChGetRequest(uint8 chHandle) \r
+{\r
+ cystatus status = CY_DMA_INVALID_CHANNEL;\r
+\r
+ if(chHandle < CY_DMA_NUMBEROF_CHANNELS)\r
+ {\r
+ status = (cystatus) ((uint32)CY_DMA_CH_STRUCT_PTR[chHandle].action[0u] &\r
+ (uint32)(CY_DMA_CPU_REQ | CY_DMA_CPU_TERM_TD | CY_DMA_CPU_TERM_CHAIN));\r
+ }\r
+\r
+ return(status);\r
+}\r
+\r
+\r
+/*******************************************************************************\r
+* Function Name: CyDmaChStatus\r
+********************************************************************************\r
+*\r
+* Summary:\r
+* Determines the status of the DMA channel.\r
+*\r
+* Parameters:\r
+* uint8 chHandle:\r
+* A handle previously returned by CyDmaChAlloc() or DMA_DmaInitalize().\r
+*\r
+* uint8 * currentTd:\r
+* The address to store the index of the current TD. Can be NULL if the value\r
+* is not needed.\r
+*\r
+* uint8 * state:\r
+* The address to store the state of the channel. Can be NULL if the value is\r
+* not needed.\r
+*\r
+* STATUS_TD_ACTIVE\r
+* 0: Channel is not currently being serviced by DMAC\r
+* 1: Channel is currently being serviced by DMAC\r
+*\r
+* STATUS_CHAIN_ACTIVE\r
+* 0: TD chain is inactive; either no DMA requests have triggered a new chain\r
+* or the previous chain has completed.\r
+* 1: TD chain has been triggered by a DMA request\r
+*\r
+* Return:\r
+* CYRET_SUCCESS if successful.\r
+* CYRET_BAD_PARAM if chHandle is invalid.\r
+*\r
+* Theory:\r
+* The caller can check on the activity of the Current TD and the Chain.\r
+*\r
+*******************************************************************************/\r
+cystatus CyDmaChStatus(uint8 chHandle, uint8 * currentTd, uint8 * state) \r
+{\r
+ cystatus status = CYRET_BAD_PARAM;\r
+\r
+ if(chHandle < CY_DMA_NUMBEROF_CHANNELS)\r
+ {\r
+ if(NULL != currentTd)\r
+ {\r
+ *currentTd = CY_DMA_CH_STRUCT_PTR[chHandle].basic_status[1] & 0x7Fu;\r
+ }\r
+\r
+ if(NULL != state)\r
+ {\r
+ *state= CY_DMA_CH_STRUCT_PTR[chHandle].basic_status[0];\r
+ }\r
+\r
+ status = CYRET_SUCCESS;\r
+ }\r
+\r
+ return (status);\r
+}\r
+\r
+\r
+/*******************************************************************************\r
+* Function Name: CyDmaChSetConfiguration\r
+********************************************************************************\r
+*\r
+* Summary:\r
+* Sets configuration information of the channel.\r
+*\r
+* Parameters:\r
+* uint8 chHandle:\r
+* A handle previously returned by CyDmaChAlloc() or DMA_DmaInitialize().\r
+*\r
+* uint8 burstCount:\r
+* Specifies the size of bursts (1 to 127) the data transfer should be divided\r
+* into. If this value is zero then the whole transfer is done in one burst.\r
+*\r
+* uint8 requestPerBurst:\r
+* The whole of the data can be split into multiple bursts, if this is\r
+* required to complete the transaction:\r
+* 0: All subsequent bursts after the first burst will be automatically\r
+* requested and carried out\r
+* 1: All subsequent bursts after the first burst must also be individually\r
+* requested.\r
+*\r
+* uint8 tdDone0:\r
+* Selects one of the TERMOUT0 interrupt lines to signal completion. The line\r
+* connected to the nrq terminal will determine the TERMOUT0_SEL definition and\r
+* should be used as supplied by cyfitter.h\r
+*\r
+* uint8 tdDone1:\r
+* Selects one of the TERMOUT1 interrupt lines to signal completion. The line\r
+* connected to the nrq terminal will determine the TERMOUT1_SEL definition and\r
+* should be used as supplied by cyfitter.h\r
+*\r
+* uint8 tdStop:\r
+* Selects one of the TERMIN interrupt lines to signal to the DMAC that the TD\r
+* should terminate. The signal connected to the trq terminal will determine\r
+* which TERMIN (termination request) is used.\r
+*\r
+* Return:\r
+* CYRET_SUCCESS if successful.\r
+* CYRET_BAD_PARAM if chHandle is invalid.\r
+*\r
+*******************************************************************************/\r
+cystatus CyDmaChSetConfiguration(uint8 chHandle, uint8 burstCount, uint8 requestPerBurst,\r
+ uint8 tdDone0, uint8 tdDone1, uint8 tdStop) \r
+{\r
+ cystatus status = CYRET_BAD_PARAM;\r
+\r
+ if(chHandle < CY_DMA_NUMBEROF_CHANNELS)\r
+ {\r
+ CY_DMA_CFGMEM_STRUCT_PTR[chHandle].CFG0[0] = (burstCount & 0x7Fu) | ((uint8)((requestPerBurst & 0x1u) << 7u));\r
+ CY_DMA_CFGMEM_STRUCT_PTR[chHandle].CFG0[1] = ((uint8)((tdDone1 & 0xFu) << 4u)) | (tdDone0 & 0xFu);\r
+ CY_DMA_CFGMEM_STRUCT_PTR[chHandle].CFG0[2] = 0x0Fu & tdStop;\r
+ CY_DMA_CFGMEM_STRUCT_PTR[chHandle].CFG0[3] = 0u; /* burstcount_remain. */\r
+\r
+ status = CYRET_SUCCESS;\r
+ }\r
+\r
+ return (status);\r
+}\r
+\r
+\r
+/*******************************************************************************\r
+* Function Name: CyDmaTdAllocate\r
+********************************************************************************\r
+*\r
+* Summary:\r
+* Allocates a TD for use with an allocated DMA channel.\r
+*\r
+* Parameters:\r
+* None\r
+*\r
+* Return:\r
+* Zero-based index of the TD to be used by the caller. Since there are 128 TDs\r
+* minus the reserved TDs (0 to 23), the value returned would range from 24 to\r
+* 127 not 24 to 128. DMA_INVALID_TD is returned if there are no free TDs\r
+* available.\r
+*\r
+*******************************************************************************/\r
+uint8 CyDmaTdAllocate(void) \r
+{\r
+ uint8 interruptState;\r
+ uint8 element = CY_DMA_INVALID_TD;\r
+\r
+ /* Enter critical section! */\r
+ interruptState = CyEnterCriticalSection();\r
+\r
+ if(CyDmaTdCurrentNumber > NUMBEROF_CHANNELS)\r
+ {\r
+ /* Get pointer to Next available. */\r
+ element = CyDmaTdFreeIndex;\r
+\r
+ /* Decrement the count. */\r
+ CyDmaTdCurrentNumber--;\r
+\r
+ /* Update next available pointer. */\r
+ CyDmaTdFreeIndex = CY_DMA_TDMEM_STRUCT_PTR[element].TD0[0];\r
+ }\r
+\r
+ /* Exit critical section! */\r
+ CyExitCriticalSection(interruptState);\r
+\r
+ return(element);\r
+}\r
+\r
+\r
+/*******************************************************************************\r
+* Function Name: CyDmaTdFree\r
+********************************************************************************\r
+*\r
+* Summary:\r
+* Returns a TD to the free list.\r
+*\r
+* Parameters:\r
+* uint8 tdHandle:\r
+* The TD handle returned by the CyDmaTdAllocate().\r
+*\r
+* Return:\r
+* None\r
+*\r
+*******************************************************************************/\r
+void CyDmaTdFree(uint8 tdHandle) \r
+{\r
+ if(tdHandle < CY_DMA_NUMBEROF_TDS)\r
+ {\r
+ /* Enter critical section! */\r
+ uint8 interruptState = CyEnterCriticalSection();\r
+\r
+ /* Get pointer to Next available. */\r
+ CY_DMA_TDMEM_STRUCT_PTR[tdHandle].TD0[0u] = CyDmaTdFreeIndex;\r
+\r
+ /* Set new Next Available. */\r
+ CyDmaTdFreeIndex = tdHandle;\r
+\r
+ /* Keep track of how many left. */\r
+ CyDmaTdCurrentNumber++;\r
+\r
+ /* Exit critical section! */\r
+ CyExitCriticalSection(interruptState);\r
+ }\r
+}\r
+\r
+\r
+/*******************************************************************************\r
+* Function Name: CyDmaTdFreeCount\r
+********************************************************************************\r
+*\r
+* Summary:\r
+* Returns the number of free TDs available to be allocated.\r
+*\r
+* Parameters:\r
+* None\r
+*\r
+* Return:\r
+* The number of free TDs.\r
+*\r
+*******************************************************************************/\r
+uint8 CyDmaTdFreeCount(void) \r
+{\r
+ return(CyDmaTdCurrentNumber - CY_DMA_NUMBEROF_CHANNELS);\r
+}\r
+\r
+\r
+/*******************************************************************************\r
+* Function Name: CyDmaTdSetConfiguration\r
+********************************************************************************\r
+*\r
+* Summary:\r
+* Configures the TD.\r
+*\r
+* Parameters:\r
+* uint8 tdHandle:\r
+* A handle previously returned by CyDmaTdAlloc().\r
+*\r
+* uint16 transferCount:\r
+* The size of the data transfer (in bytes) for this TD. A size of zero will\r
+* cause the transfer to continue indefinitely. This parameter is limited to\r
+* 4095 bytes; the TD is not initialized at all when a higher value is passed.\r
+*\r
+* uint8 nextTd:\r
+* Zero based index of the next Transfer Descriptor in the TD chain. Zero is a\r
+* valid pointer to the next TD; DMA_END_CHAIN_TD is the end of the chain.\r
+* DMA_DISABLE_TD indicates an end to the chain and the DMA is disabled. No\r
+* further TDs are fetched. DMA_DISABLE_TD is only supported on PSoC3 and\r
+* PSoC 5LP silicons.\r
+*\r
+* uint8 configuration:\r
+* Stores the Bit field of configuration bits.\r
+*\r
+* CY_DMA_TD_SWAP_EN - Perform endian swap\r
+*\r
+* CY_DMA_TD_SWAP_SIZE4 - Swap size = 4 bytes\r
+*\r
+* CY_DMA_TD_AUTO_EXEC_NEXT - The next TD in the chain will trigger\r
+* automatically when the current TD completes.\r
+*\r
+* CY_DMA_TD_TERMIN_EN - Terminate this TD if a positive edge on the trq\r
+* input line occurs. The positive edge must occur\r
+* during a burst. That is the only time the DMAC\r
+* will listen for it.\r
+*\r
+* DMA__TD_TERMOUT_EN - When this TD completes, the TERMOUT signal will\r
+* generate a pulse. Note that this option is\r
+* instance specific with the instance name followed\r
+* by two underscores. In this example, the instance\r
+* name is DMA.\r
+*\r
+* CY_DMA_TD_INC_DST_ADR - Increment DST_ADR according to the size of each\r
+* data transaction in the burst.\r
+*\r
+* CY_DMA_TD_INC_SRC_ADR - Increment SRC_ADR according to the size of each\r
+* data transaction in the burst.\r
+*\r
+* Return:\r
+* CYRET_SUCCESS if successful.\r
+* CYRET_BAD_PARAM if tdHandle or transferCount is invalid.\r
+*\r
+*******************************************************************************/\r
+cystatus CyDmaTdSetConfiguration(uint8 tdHandle, uint16 transferCount, uint8 nextTd, uint8 configuration) \\r
+ \r
+{\r
+ cystatus status = CYRET_BAD_PARAM;\r
+\r
+ if((tdHandle < CY_DMA_NUMBEROF_TDS) && (0u == (0xF000u & transferCount)))\r
+ {\r
+ /* Set 12 bits transfer count. */\r
+ reg16 *convert = (reg16 *) &CY_DMA_TDMEM_STRUCT_PTR[tdHandle].TD0[0u];\r
+ CY_SET_REG16(convert, transferCount);\r
+\r
+ /* Set Next TD pointer. */\r
+ CY_DMA_TDMEM_STRUCT_PTR[tdHandle].TD0[2u] = nextTd;\r
+\r
+ /* Configure the TD */\r
+ CY_DMA_TDMEM_STRUCT_PTR[tdHandle].TD0[3u] = configuration;\r
+\r
+ status = CYRET_SUCCESS;\r
+ }\r
+\r
+ return(status);\r
+}\r
+\r
+\r
+/*******************************************************************************\r
+* Function Name: CyDmaTdGetConfiguration\r
+********************************************************************************\r
+*\r
+* Summary:\r
+* Retrieves the configuration of the TD. If a NULL pointer is passed as a\r
+* parameter, that parameter is skipped. You may request only the values you are\r
+* interested in.\r
+*\r
+* Parameters:\r
+* uint8 tdHandle:\r
+* A handle previously returned by CyDmaTdAlloc().\r
+*\r
+* uint16 * transferCount:\r
+* The address to store the size of the data transfer (in bytes) for this TD.\r
+* A size of zero could indicate that the TD has completed its transfer, or\r
+* that the TD is doing an indefinite transfer.\r
+*\r
+* uint8 * nextTd:\r
+* The address to store the index of the next TD in the TD chain.\r
+*\r
+* uint8 * configuration:\r
+* The address to store the Bit field of configuration bits.\r
+* See CyDmaTdSetConfiguration() function description.\r
+*\r
+* Return:\r
+* CYRET_SUCCESS if successful.\r
+* CYRET_BAD_PARAM if tdHandle is invalid.\r
+*\r
+* Side Effects:\r
+* If TD has a transfer count of N and is executed, the transfer count becomes\r
+* 0. If it is reexecuted, the Transfer count of zero will be interpreted as a\r
+* request for indefinite transfer. Be careful when requesting TD with a\r
+* transfer count of zero.\r
+*\r
+*******************************************************************************/\r
+cystatus CyDmaTdGetConfiguration(uint8 tdHandle, uint16 * transferCount, uint8 * nextTd, uint8 * configuration) \\r
+ \r
+{\r
+ cystatus status = CYRET_BAD_PARAM;\r
+\r
+ if(tdHandle < CY_DMA_NUMBEROF_TDS)\r
+ {\r
+ /* If we have pointer */\r
+ if(NULL != transferCount)\r
+ {\r
+ /* Get 12 bits of transfer count */\r
+ reg16 *convert = (reg16 *) &CY_DMA_TDMEM_STRUCT_PTR[tdHandle].TD0[0];\r
+ *transferCount = 0x0FFFu & CY_GET_REG16(convert);\r
+ }\r
+\r
+ /* If we have pointer */\r
+ if(NULL != nextTd)\r
+ {\r
+ /* Get Next TD pointer */\r
+ *nextTd = CY_DMA_TDMEM_STRUCT_PTR[tdHandle].TD0[2u];\r
+ }\r
+\r
+ /* If we have pointer */\r
+ if(NULL != configuration)\r
+ {\r
+ /* Get configuration TD */\r
+ *configuration = CY_DMA_TDMEM_STRUCT_PTR[tdHandle].TD0[3u];\r
+ }\r
+\r
+ status = CYRET_SUCCESS;\r
+ }\r
+\r
+ return(status);\r
+}\r
+\r
+\r
+/*******************************************************************************\r
+* Function Name: CyDmaTdSetAddress\r
+********************************************************************************\r
+*\r
+* Summary:\r
+* Sets the lower 16 bits of the source and destination addresses for this TD\r
+* only.\r
+*\r
+* Parameters:\r
+* uint8 tdHandle:\r
+* A handle previously returned by CyDmaTdAlloc().\r
+*\r
+* uint16 source:\r
+* The lower 16 address bits of the source of the data transfer.\r
+*\r
+* uint16 destination:\r
+* The lower 16 address bits of the destination of the data transfer.\r
+*\r
+* Return:\r
+* CYRET_SUCCESS if successful.\r
+* CYRET_BAD_PARAM if tdHandle is invalid.\r
+*\r
+*******************************************************************************/\r
+cystatus CyDmaTdSetAddress(uint8 tdHandle, uint16 source, uint16 destination) \r
+{\r
+ cystatus status = CYRET_BAD_PARAM;\r
+ reg16 *convert;\r
+\r
+ if(tdHandle < CY_DMA_NUMBEROF_TDS)\r
+ {\r
+ /* Set source address */\r
+ convert = (reg16 *) &CY_DMA_TDMEM_STRUCT_PTR[tdHandle].TD1[0u];\r
+ CY_SET_REG16(convert, source);\r
+\r
+ /* Set destination address */\r
+ convert = (reg16 *) &CY_DMA_TDMEM_STRUCT_PTR[tdHandle].TD1[2u];\r
+ CY_SET_REG16(convert, destination);\r
+\r
+ status = CYRET_SUCCESS;\r
+ }\r
+\r
+ return(status);\r
+}\r
+\r
+\r
+/*******************************************************************************\r
+* Function Name: CyDmaTdGetAddress\r
+********************************************************************************\r
+*\r
+* Summary:\r
+* Retrieves the lower 16 bits of the source and/or destination addresses for\r
+* this TD only. If NULL is passed for a pointer parameter, that value is\r
+* skipped. You may request only the values of interest.\r
+*\r
+* Parameters:\r
+* uint8 tdHandle:\r
+* A handle previously returned by CyDmaTdAlloc().\r
+*\r
+* uint16 * source:\r
+* The address to store the lower 16 address bits of the source of the data\r
+* transfer.\r
+*\r
+* uint16 * destination:\r
+* The address to store the lower 16 address bits of the destination of the\r
+* data transfer.\r
+*\r
+* Return:\r
+* CYRET_SUCCESS if successful.\r
+* CYRET_BAD_PARAM if tdHandle is invalid.\r
+*\r
+*******************************************************************************/\r
+cystatus CyDmaTdGetAddress(uint8 tdHandle, uint16 * source, uint16 * destination) \r
+{\r
+ cystatus status = CYRET_BAD_PARAM;\r
+ reg16 *convert;\r
+\r
+ if(tdHandle < CY_DMA_NUMBEROF_TDS)\r
+ {\r
+ /* If we have a pointer. */\r
+ if(NULL != source)\r
+ {\r
+ /* Get source address */\r
+ convert = (reg16 *) &CY_DMA_TDMEM_STRUCT_PTR[tdHandle].TD1[0u];\r
+ *source = CY_GET_REG16(convert);\r
+ }\r
+\r
+ /* If we have a pointer. */\r
+ if(NULL != destination)\r
+ {\r
+ /* Get Destination address. */\r
+ convert = (reg16 *) &CY_DMA_TDMEM_STRUCT_PTR[tdHandle].TD1[2u];\r
+ *destination = CY_GET_REG16(convert);\r
+ }\r
+\r
+ status = CYRET_SUCCESS;\r
+ }\r
+\r
+ return(status);\r
+}\r
+\r
+\r
+/*******************************************************************************\r
+* Function Name: CyDmaChRoundRobin\r
+********************************************************************************\r
+*\r
+* Summary:\r
+* Either enables or disables the Round-Robin scheduling enforcement algorithm.\r
+* Within a priority level a Round-Robin fairness algorithm is enforced.\r
+*\r
+* Parameters:\r
+* uint8 chHandle:\r
+* A handle previously returned by CyDmaChAlloc() or Dma_DmaInitialize().\r
+*\r
+* uint8 enableRR:\r
+* 0: Disable Round-Robin fairness algorithm\r
+* 1: Enable Round-Robin fairness algorithm\r
+*\r
+* Return:\r
+* CYRET_SUCCESS if successful.\r
+* CYRET_BAD_PARAM if chHandle is invalid.\r
+*\r
+*******************************************************************************/\r
+cystatus CyDmaChRoundRobin(uint8 chHandle, uint8 enableRR) \r
+{\r
+ cystatus status = CYRET_BAD_PARAM;\r
+\r
+ if(chHandle < CY_DMA_NUMBEROF_CHANNELS)\r
+ {\r
+ if (0u != enableRR)\r
+ {\r
+ CY_DMA_CH_STRUCT_PTR[chHandle].basic_cfg[0u] |= (uint8)CY_DMA_ROUND_ROBIN_ENABLE;\r
+ }\r
+ else\r
+ {\r
+ CY_DMA_CH_STRUCT_PTR[chHandle].basic_cfg[0u] &= (uint8)(~CY_DMA_ROUND_ROBIN_ENABLE);\r
+ }\r
+\r
+ status = CYRET_SUCCESS;\r
+ }\r
+\r
+ return(status);\r
+}\r
+\r
+\r
+/* [] END OF FILE */\r
-/*******************************************************************************
-* File Name: CyDmac.h
-* Version 4.20
-*
-* Description:
-* Provides the function definitions for the DMA Controller.
-*
-* Note:
-* Documentation of the API's in this file is located in the
-* System Reference Guide provided with PSoC Creator.
-*
-********************************************************************************
-* Copyright 2008-2014, Cypress Semiconductor Corporation. All rights reserved.
-* You may use this file only in accordance with the license, terms, conditions,
-* disclaimers, and limitations in the end user license agreement accompanying
-* the software package with which this file was provided.
-*******************************************************************************/
-
-#if !defined(CY_BOOT_CYDMAC_H)
-#define CY_BOOT_CYDMAC_H
-
-
-#include "cytypes.h"
-#include "cyfitter.h"
-#include "cydevice_trm.h"
-#include "CyLib.h"
-
-
-/***************************************
-* Function Prototypes
-***************************************/
-
-/* DMA Controller functions. */
-void CyDmacConfigure(void) ;
-uint8 CyDmacError(void) ;
-void CyDmacClearError(uint8 error) ;
-uint32 CyDmacErrorAddress(void) ;
-
-/* Channel specific functions. */
-uint8 CyDmaChAlloc(void) ;
-cystatus CyDmaChFree(uint8 chHandle) ;
-cystatus CyDmaChEnable(uint8 chHandle, uint8 preserveTds) ;
-cystatus CyDmaChDisable(uint8 chHandle) ;
-cystatus CyDmaClearPendingDrq(uint8 chHandle) ;
-cystatus CyDmaChPriority(uint8 chHandle, uint8 priority) ;
-cystatus CyDmaChSetExtendedAddress(uint8 chHandle, uint16 source, uint16 destination)\
-;
-cystatus CyDmaChSetInitialTd(uint8 chHandle, uint8 startTd) ;
-cystatus CyDmaChSetRequest(uint8 chHandle, uint8 request) ;
-cystatus CyDmaChGetRequest(uint8 chHandle) ;
-cystatus CyDmaChStatus(uint8 chHandle, uint8 * currentTd, uint8 * state) ;
-cystatus CyDmaChSetConfiguration(uint8 chHandle, uint8 burstCount, uint8 requestPerBurst, uint8 tdDone0,
- uint8 tdDone1, uint8 tdStop) ;
-cystatus CyDmaChRoundRobin(uint8 chHandle, uint8 enableRR) ;
-
-/* Transfer Descriptor functions. */
-uint8 CyDmaTdAllocate(void) ;
-void CyDmaTdFree(uint8 tdHandle) ;
-uint8 CyDmaTdFreeCount(void) ;
-cystatus CyDmaTdSetConfiguration(uint8 tdHandle, uint16 transferCount, uint8 nextTd, uint8 configuration)\
-;
-cystatus CyDmaTdGetConfiguration(uint8 tdHandle, uint16 * transferCount, uint8 * nextTd, uint8 * configuration)\
-;
-cystatus CyDmaTdSetAddress(uint8 tdHandle, uint16 source, uint16 destination) ;
-cystatus CyDmaTdGetAddress(uint8 tdHandle, uint16 * source, uint16 * destination) ;
-
-
-/***************************************
-* Data Struct Definitions
-***************************************/
-
-typedef struct dmac_ch_struct
-{
- volatile uint8 basic_cfg[4];
- volatile uint8 action[4];
- volatile uint8 basic_status[4];
- volatile uint8 reserved[4];
-
-} dmac_ch;
-
-
-typedef struct dmac_cfgmem_struct
-{
- volatile uint8 CFG0[4];
- volatile uint8 CFG1[4];
-
-} dmac_cfgmem;
-
-
-typedef struct dmac_tdmem_struct
-{
- volatile uint8 TD0[4];
- volatile uint8 TD1[4];
-
-} dmac_tdmem;
-
-
-typedef struct dmac_tdmem2_struct
-{
- volatile uint16 xfercnt;
- volatile uint8 next_td_ptr;
- volatile uint8 flags;
- volatile uint16 src_adr;
- volatile uint16 dst_adr;
-} dmac_tdmem2;
-
-
-/***************************************
-* API Constants
-***************************************/
-
-#define CY_DMA_INVALID_CHANNEL 0xFFu /* Invalid Channel ID */
-#define CY_DMA_INVALID_TD 0xFFu /* Invalid TD */
-#define CY_DMA_END_CHAIN_TD 0xFFu /* End of chain TD */
-#define CY_DMA_DISABLE_TD 0xFEu
-
-#define CY_DMA_TD_SIZE 0x08u
-
-/* "u" was removed as workaround for Keil compiler bug */
-#define CY_DMA_TD_SWAP_EN 0x80
-#define CY_DMA_TD_SWAP_SIZE4 0x40
-#define CY_DMA_TD_AUTO_EXEC_NEXT 0x20
-#define CY_DMA_TD_TERMIN_EN 0x10
-#define CY_DMA_TD_TERMOUT1_EN 0x08
-#define CY_DMA_TD_TERMOUT0_EN 0x04
-#define CY_DMA_TD_INC_DST_ADR 0x02
-#define CY_DMA_TD_INC_SRC_ADR 0x01
-
-#define CY_DMA_NUMBEROF_TDS 128u
-#define CY_DMA_NUMBEROF_CHANNELS ((uint8)(CYDEV_DMA_CHANNELS_AVAILABLE))
-
-/* Action register bits */
-#define CY_DMA_CPU_REQ ((uint8)(1u << 0u))
-#define CY_DMA_CPU_TERM_TD ((uint8)(1u << 1u))
-#define CY_DMA_CPU_TERM_CHAIN ((uint8)(1u << 2u))
-
-/* Basic Status register bits */
-#define CY_DMA_STATUS_CHAIN_ACTIVE ((uint8)(1u << 0u))
-#define CY_DMA_STATUS_TD_ACTIVE ((uint8)(1u << 1u))
-
-/* DMA controller register error bits */
-#define CY_DMA_BUS_TIMEOUT (1u << 1u)
-#define CY_DMA_UNPOP_ACC (1u << 2u)
-#define CY_DMA_PERIPH_ERR (1u << 3u)
-
-/* Round robin bits */
-#define CY_DMA_ROUND_ROBIN_ENABLE ((uint8)(1u << 4u))
-
-
-/*******************************************************************************
-* CyDmaChEnable() / CyDmaChDisable() API constants
-*******************************************************************************/
-#define CY_DMA_CH_BASIC_CFG_EN (0x01u)
-#define CY_DMA_CH_BASIC_CFG_WORK_SEP (0x20u)
-
-
-/***************************************
-* Registers
-***************************************/
-
-#define CY_DMA_CFG_REG (*(reg32 *) CYREG_PHUB_CFG)
-#define CY_DMA_CFG_PTR ( (reg32 *) CYREG_PHUB_CFG)
-
-#define CY_DMA_ERR_REG (*(reg32 *) CYREG_PHUB_ERR)
-#define CY_DMA_ERR_PTR ( (reg32 *) CYREG_PHUB_ERR)
-
-#define CY_DMA_ERR_ADR_REG (*(reg32 *) CYREG_PHUB_ERR_ADR)
-#define CY_DMA_ERR_ADR_PTR ( (reg32 *) CYREG_PHUB_ERR_ADR)
-
-#define CY_DMA_CH_STRUCT_REG (*(dmac_ch CYXDATA *) CYDEV_PHUB_CH0_BASE)
-#define CY_DMA_CH_STRUCT_PTR ( (dmac_ch CYXDATA *) CYDEV_PHUB_CH0_BASE)
-
-#define CY_DMA_CFGMEM_STRUCT_REG (*(dmac_cfgmem CYXDATA *) CYDEV_PHUB_CFGMEM0_BASE)
-#define CY_DMA_CFGMEM_STRUCT_PTR ( (dmac_cfgmem CYXDATA *) CYDEV_PHUB_CFGMEM0_BASE)
-
-#define CY_DMA_TDMEM_STRUCT_REG (*(dmac_tdmem CYXDATA *) CYDEV_PHUB_TDMEM0_BASE)
-#define CY_DMA_TDMEM_STRUCT_PTR ( (dmac_tdmem CYXDATA *) CYDEV_PHUB_TDMEM0_BASE)
-
-
-/*******************************************************************************
-* The following code is OBSOLETE and must not be used.
-*
-* If the obsoleted macro definitions intended for use in the application use the
-* following scheme, redefine your own versions of these definitions:
-* #ifdef <OBSOLETED_DEFINE>
-* #undef <OBSOLETED_DEFINE>
-* #define <OBSOLETED_DEFINE> (<New Value>)