1 /**************************************************************************//**
2  * @file     plm.h
3  * @version  V3.00
4  * @brief    Product life cycle management
5  *
6  * @copyright SPDX-License-Identifier: Apache-2.0
7  * @copyright Copyright (C) 2020 Nuvoton Technology Corp. All rights reserved.
8  *****************************************************************************/
9 #ifndef __PLM_H__
10 #define __PLM_H__
11 
12 #ifdef __cplusplus
13 extern "C"
14 {
15 #endif
16 
17 
18 /** @addtogroup Standard_Driver Standard Driver
19   @{
20 */
21 
22 /** @addtogroup PLM_Driver PLM Driver
23   @{
24 */
25 
26 /** @addtogroup PLM_EXPORTED_CONSTANTS PLM Exported Constants
27   @{
28 */
29 
30 typedef enum
31 {
32     PLM_VENDOR = 0,
33     PLM_OEM = 1,
34     PLM_DEPLOYED = 3,
35     PLM_RMA = 7
36 } PLM_STAGE_T;
37 
38 #define PLM_VCODE   (0x475A0000ul)  /*!< The key code for PLM_CTL write. */
39 
40 /**@}*/ /* end of group FVC_EXPORTED_CONSTANTS */
41 
42 
43 /** @addtogroup FVC_EXPORTED_FUNCTIONS FVC Exported Functions
44   @{
45 */
46 
47 
48 /**
49   * @brief      Get product life-cycle stage
50   * @return     Current stage of PLM
51   * @details    This function is used to Get PLM stage.
52   */
53 #define PLM_GetStage()  (PLM->STS & PLM_STS_STAGE_Msk)
54 
55 
56 /**
57   * @brief      Set product life-cycle stage
58   * @param[in]  stage   Product life-cycle stage. It could be:
59   *                     \ref PLM_VENDOR
60   *                     \ref PLM_OEM
61   *                     \ref PLM_DEPLOYED
62   *                     \ref PLM_RMA
63   * @retval     0   Successful
64   * @retval     -1  Failed
65   * @details    This function is used to set PLM stage. It could be only be VENDOR, OEM, DEPLOYED and RMA.
66   *             The setting of PLM cannot be rollback.
67   */
PLM_SetStage(PLM_STAGE_T stage)68 __STATIC_INLINE int32_t PLM_SetStage(PLM_STAGE_T stage)
69 {
70 
71     /* Do nothing when stage is not changed */
72     if(PLM_GetStage() == stage)
73         return 0;
74 
75     PLM->CTL = PLM_VCODE | (stage);
76 
77     /* The dirty flag should be set when PLM stage set successfully. */
78     if(PLM->STS & PLM_STS_DIRTY_Msk)
79         return -1;
80 
81     return 0;
82 }
83 
84 /**@}*/ /* end of group PLM_EXPORTED_FUNCTIONS */
85 
86 /**@}*/ /* end of group PLM_Driver */
87 
88 /**@}*/ /* end of group Standard_Driver */
89 
90 #ifdef __cplusplus
91 }
92 #endif
93 
94 #endif /* __PLM_H__ */
95