1 /*********************************************************************************************************//**
2  * @file    ht32_cm3_misc.h
3  * @version $Rev:: 3143         $
4  * @date    $Date:: 2024-07-04 #$
5  * @brief   All the function prototypes for the miscellaneous firmware library.
6  *************************************************************************************************************
7  * @attention
8  *
9  * Firmware Disclaimer Information
10  *
11  * 1. The customer hereby acknowledges and agrees that the program technical documentation, including the
12  *    code, which is supplied by Holtek Semiconductor Inc., (hereinafter referred to as "HOLTEK") is the
13  *    proprietary and confidential intellectual property of HOLTEK, and is protected by copyright law and
14  *    other intellectual property laws.
15  *
16  * 2. The customer hereby acknowledges and agrees that the program technical documentation, including the
17  *    code, is confidential information belonging to HOLTEK, and must not be disclosed to any third parties
18  *    other than HOLTEK and the customer.
19  *
20  * 3. The program technical documentation, including the code, is provided "as is" and for customer reference
21  *    only. After delivery by HOLTEK, the customer shall use the program technical documentation, including
22  *    the code, at their own risk. HOLTEK disclaims any expressed, implied or statutory warranties, including
23  *    the warranties of merchantability, satisfactory quality and fitness for a particular purpose.
24  *
25  * <h2><center>Copyright (C) Holtek Semiconductor Inc. All rights reserved</center></h2>
26  ************************************************************************************************************/
27 
28 /* Define to prevent recursive inclusion -------------------------------------------------------------------*/
29 #ifndef __HT32_CM3_MISC_H
30 #define __HT32_CM3_MISC_H
31 
32 #ifdef __cplusplus
33  extern "C" {
34 #endif
35 
36 /* Includes ------------------------------------------------------------------------------------------------*/
37 #include "ht32.h"
38 
39 /** @addtogroup HT32_Peripheral_Driver
40   * @{
41   */
42 
43 /** @addtogroup MISC
44   * @{
45   */
46 
47 
48 /* Exported constants --------------------------------------------------------------------------------------*/
49 /** @defgroup MISC_Exported_Constants MISC exported constants
50   * @{
51   */
52 
53 /* Vector Table Base                                                                                        */
54 #define NVIC_VECTTABLE_RAM                          ((u32)0x20000000)
55 #define NVIC_VECTTABLE_FLASH                        ((u32)0x00000000)
56 
57 #define IS_NVIC_VECTTABLE(VECTTABLE)                ((VECTTABLE == NVIC_VECTTABLE_RAM) || \
58                                                      (VECTTABLE == NVIC_VECTTABLE_FLASH))
59 
60 #define IS_NVIC_OFFSET(OFFSET)                      (OFFSET < 0x0001FFFF)
61 
62 /* System Low Power                                                                                         */
63 #define NVIC_LOWPOWER_SEVONPEND                     ((u8)0x10)
64 #define NVIC_LOWPOWER_SLEEPDEEP                     ((u8)0x04)
65 #define NVIC_LOWPOWER_SLEEPONEXIT                   ((u8)0x02)
66 
67 #define IS_NVIC_LOWPOWER(LOWPOWER)                  ((LOWPOWER == NVIC_LOWPOWER_SEVONPEND) || \
68                                                      (LOWPOWER == NVIC_LOWPOWER_SLEEPDEEP) || \
69                                                      (LOWPOWER == NVIC_LOWPOWER_SLEEPONEXIT))
70 
71 /* System Handler                                                                                           */
72 #define SYSTEMHANDLER_NMI                           ((u32)0x80000000)
73 #define SYSTEMHANDLER_PSV                           ((u32)0x10000000)
74 #define SYSTEMHANDLER_SYSTICK                       ((u32)0x04000000)
75 #define SYSTEMHANDLER_ALL                           ((u32)0x94000000)
76 
77 #define IS_NVIC_SYSTEMHANDLER(HANDLER)              ((HANDLER == SYSTEMHANDLER_NMI)     || \
78                                                      (HANDLER == SYSTEMHANDLER_PSV)     || \
79                                                      (HANDLER == SYSTEMHANDLER_SYSTICK) ||\
80                                                      (HANDLER == SYSTEMHANDLER_ALL))
81 
82 /* SysTick clock source                                                                                     */
83 #define SYSTICK_SRC_STCLK                           ((u32)0xFFFFFFFB)
84 #define SYSTICK_SRC_FCLK                            ((u32)0x00000004)
85 
86 #define IS_SYSTICK_CLOCK_SOURCE(SOURCE)             ((SOURCE == SYSTICK_SRC_STCLK) || \
87                                                      (SOURCE == SYSTICK_SRC_FCLK) )
88 
89 /* SysTick counter state                                                                                    */
90 #define SYSTICK_COUNTER_DISABLE                     ((u32)0xFFFFFFFE)
91 #define SYSTICK_COUNTER_ENABLE                      ((u32)0x00000001)
92 #define SYSTICK_COUNTER_CLEAR                       ((u32)0x00000000)
93 
94 #define IS_SYSTICK_COUNTER(COUNTER)                 ((COUNTER == SYSTICK_COUNTER_DISABLE) || \
95                                                      (COUNTER == SYSTICK_COUNTER_ENABLE)  || \
96                                                      (COUNTER == SYSTICK_COUNTER_CLEAR))
97 
98 #define IS_SYSTICK_RELOAD(RELOAD)                   ((RELOAD  > 0) && (RELOAD <= 0xFFFFFF))
99 /**
100   * @}
101   */
102 
103 /* Exported functions --------------------------------------------------------------------------------------*/
104 /** @defgroup MISC_Exported_Functions MISC exported functions
105   * @{
106   */
107 void NVIC_SetVectorTable(u32 NVIC_VectTable, u32 NVIC_Offset);
108 void NVIC_LowPowerConfig(u8 NVIC_LowPowerMode, ControlStatus NewState);
109 void NVIC_CoreReset(void);
110 void NVIC_SetPendingSystemHandler(u32 SystemHandler);
111 void SYSTICK_ClockSourceConfig(u32 SysTick_ClockSource);
112 void SYSTICK_CounterCmd(u32 SysTick_Counter);
113 void SYSTICK_IntConfig(ControlStatus NewState);
114 void SYSTICK_SetReloadValue(u32 SysTick_Reload);
115 #if (HTCFG_STACK_USAGE_ANALYSIS == 1)
116 void StackUsageAnalysisInit(u32 addr);
117 #else
118 #define StackUsageAnalysisInit(...)
119 #endif
120 /**
121   * @}
122   */
123 
124 
125 /**
126   * @}
127   */
128 
129 /**
130   * @}
131   */
132 
133 #ifdef __cplusplus
134 }
135 #endif
136 
137 #endif
138