The system libraries provide APIs that can be called in the user application to handle the timing, logical checking or register.
The functions and other declarations used in this driver are in cy_syslib.h. You can include cy_pdl.h (ModusToolbox only) to get access to all functions and declarations in the PDL.
The SysLib driver contains a set of different system functions. These functions can be called in the application routine. Major features of the system library:
Assertion Usage
Use the CY_ASSERT() macro to check expressions that must be true as long as the program is running correctly. It is a convenient way to insert sanity checks. The CY_ASSERT() macro is defined in the cy_syslib.h file which is part of the PDL library. The behavior of the macro is as follows: if the expression passed to the macro is false, output an error message that includes the file name and line number, and then halts the CPU.
In case of fault, the CY_ASSERT() macro calls the Cy_SysLib_AssertFailed() function. This is a weakly linked function. The default implementation stores the file name and line number of the ASSERT into global variables, cy_assertFileName and cy_assertLine . It then calls the Cy_SysLib_Halt() function.
The PDL source code uses this assert mechanism extensively. It is recommended that you enable asserts when debugging firmware.
Assertion Classes and Levels
The PDL defines three assert classes, which correspond to different kinds of parameters. There is a corresponding assert "level" for each class.
| Class Macro | Level Macro | Type of check |
|---|---|---|
| CY_ASSERT_CLASS_1 | CY_ASSERT_L1 | A parameter that could change between different PSoC devices (e.g. the number of clock paths) |
| CY_ASSERT_CLASS_2 | CY_ASSERT_L2 | A parameter that has fixed limits such as a counter period |
| CY_ASSERT_CLASS_3 | CY_ASSERT_L3 | A parameter that is an enum constant |
Firmware defines which ASSERT class is enabled by defining CY_ASSERT_LEVEL. This is a compiler command line argument, similar to how the DEBUG / NDEBUG macro is passed.
Enabling any class also enables any lower-numbered class. CY_ASSERT_CLASS_3 is the default level, and it enables asserts for all three classes. The following example shows the command-line option to enable all the assert levels:
After CY_ASSERT_LEVEL is defined, firmware can use one of the three level macros to make an assertion. For example, if the parameter can vary between devices, firmware uses the L1 macro.
If the parameter has bounds, firmware uses L2.
If the parameter is an enum, firmware uses L3.
Each check uses the appropriate level macro for the kind of parameter being checked. If a particular assert class/level is not enabled, then the assert does nothing.
Refer to the technical reference manual (TRM).
| MISRA Rule | Rule Class (Required/Advisory) | Rule Description | Description of Deviation(s) |
|---|---|---|---|
| 1.2 | R | No reliance shall be placed on undefined or unspecified behaviour. | This specific behavior is explicitly covered in rule 20.1. |
| 2.1 | R | This function contains a mixture of in-line assembler statements and C statements. | This si required by design of the Cy_SysLib_Halt function. |
| 18.4 | R | Unions shall not be used. | The unions are used for CFSR, HFSR and SHCSR Fault Status Registers content access as a word in code and as a structure during debug. |
| 19.13 | A | The # and ## operators should not be used. | The ## preprocessor operator is used in macros to form the field mask. |
| 20.1 | R | Reserved identifiers, macros and functions in the standard library, shall not be defined, redefined or undefined. | The driver defines the macros with leading underscores (_CLR_SET_FLD/_BOOL2FLD/_FLD2BOOL) and therefore generates this MISRA violation. |
| Version | Changes | Reason for Change |
|---|---|---|
| 2.40.1 | Correct the CY_RAMFUNC_BEGIN macro for the IAR compiler. | Removed the IAR compiler warning. |
| 2.40 | Added new macros CY_SYSLIB_DIV_ROUND and CY_SYSLIB_DIV_ROUNDUP to easy perform integer division with rounding. | Improve PDL code base. |
| 2.30 | Updated implementation of the Cy_SysLib_AsmInfiniteLoop() function to be compatible with ARMC6. | Provided support for the ARM Compiler 6. |
| Minor documentation edits. | Documentation update and clarification. | |
| Added new macros CY_RAMFUNC_BEGIN and CY_RAMFUNC_END for convenient placement function in RAM for all supported compilers. | Improve user experience. | |
| 2.20 | Updated implementation of the Cy_SysLib_AssertFailed() function to be available in Release and Debug modes. | Provided support for the PDL static library in Release mode. |
| Minor documentation edits. | Documentation update and clarification. | |
| 2.10 | Flattened the organization of the driver source code into the single source directory and the single include directory. | Driver library directory-structure simplification. |
| Added the following macros: CY_REG32_CLR_SET, _CLR_SET_FLD16U, CY_REG16_CLR_SET, _CLR_SET_FLD8U, CY_REG8_CLR_SET | Register access simplification. | |
| Removed the Cy_SysLib_GetNumHfclkResetCause API function. | This feature is not supported by SRSS_ver1. | |
| Added register access layer. Use register access macros instead of direct register access using dereferenced pointers. | Makes register access device-independent, so that the PDL does not need to be recompiled for each supported part number. | |
| 2.0.1 | Minor documentation edits | Documentation update and clarification |
| 2.0 | Added Cy_SysLib_ResetBackupDomain() API implementation. Added CY_NOINLINE attribute implementation. Added DIE_YEAR field to 64-bit unique ID return value of Cy_SysLib_GetUniqueId() API. Added storing of SCB->HFSR, SCB->SHCSR registers and SCB->MMFAR, SCB->BFAR addresses to Fault Handler debug structure. Optimized Cy_SysLib_SetWaitStates() API implementation. | Improvements made based on usability feedback. |
| Added Assertion Classes and Levels. | For error checking, parameter validation and status returns in the PDL API. | |
| Applied CY_NOINIT attribute to cy_assertFileName, cy_assertLine, and cy_faultFrame global variables. | To store debug information into a non-zero init area for future analysis. | |
| Removed CY_WEAK attribute implementation. | CMSIS __WEAK attribute should be used instead. | |
| 1.0 | Initial version |
API Reference | |
| Macros | |
| Functions | |
| Data Structures | |
| Enumerated Types | |