blob: 6896f3834c73fe74d618b067308e7147219495f9 [file] [log] [blame]
b.liud440f9f2025-04-18 10:44:31 +08001/*-----------------------------------------------------------------------------------------------*/
2/**
3 @file ql_absys.h
4 @brief
5 This file declare absys interface
6*/
7/*-----------------------------------------------------------------------------------------------*/
8
9/*-------------------------------------------------------------------------------------------------
10 Copyright (c) 2018 Quectel Wireless Solution, Co., Ltd. All Rights Reserved.
11 Quectel Wireless Solution Proprietary and Confidential.
12-------------------------------------------------------------------------------------------------*/
13
14/*-------------------------------------------------------------------------------------------------
15 EDIT HISTORY
16 This section contains comments describing changes made to the file.
17 Notice that changes are listed in reverse chronological order.
18 $Header: $
19 when who what, where, why
20 -------- --- ----------------------------------------------------------
21 2021.12.20 jessie.lei Created .
22-------------------------------------------------------------------------------------------------*/
23
24
25#ifndef QL_ABSYS_H_
26#define QL_ABSYS_H_
27
28#include <stdbool.h>
29#include <stdint.h>
30#include <errno.h>
31#include "fota_info.h"
32
33#ifdef __cplusplus
34extern "C" {
35#endif
36
37#define PARTITION_NAME_SIZE 16
38
39
40
41//--------------------------------------------------------------------------------------------------
42/**
43 * System ID: The dual system platforms have 2 systems: A and B.
44 *
45 */
46//--------------------------------------------------------------------------------------------------
47typedef enum absystem
48{
49 SYSTEM_A = 0,
50 SYSTEM_B = 1
51} absystem_t;
52
53//--------------------------------------------------------------------------------------------------
54/**
55 * system status
56 */
57//--------------------------------------------------------------------------------------------------
58typedef struct
59{
60 fota_state_t ota_state; ///< the device ota upgrade status
61 bool is_damaged; ///< whether the device have damaged partition
62 uint8_t damaged_partname[PARTITION_NAME_SIZE]; ///< which partition damaged, and tiggered the device A/B system switch
63} sysstatus_t;
64
65//--------------------------------------------------------------------------------------------------
66/**
67 * @brief
68 * get current system status, fota status & A/B partition status.
69 * @Parameter
70 [OUT] sys_state, store the status to this struct for the caller could read current system status.
71 * @return
72 * - On success 0
73 * - On failure -1
74 */
75//--------------------------------------------------------------------------------------------------
76int ql_absys_getstatus(sysstatus_t *sys_state);
77
78//--------------------------------------------------------------------------------------------------
79/**
80 * @brief
81 * get current active system is A or B.
82 * @Parameter
83 [InOut] cur_system, store the current active system info to this enmu.
84 * @return
85 * - On success 0, success to get current active system
86 * - On failure -1, failed to get current active system
87 */
88//--------------------------------------------------------------------------------------------------
89int ql_absys_get_cur_active_part(absystem_t *cur_system);
90
91
92//--------------------------------------------------------------------------------------------------
93/**
94 * @brief
95 * Set flags in fota state file, need the caller do reboot system action atfer this api return 0, then A/B system will be switch atfer reboot.
96 * If fota state is SUCCEED or NEEDSYNC (A/B system is sync), it is okay to switch A/B system, API will be return 0.
97 * If fota state is WRITEDONE (A/B system is not sync), it is okay to switch A/B system and will be set fota state to NEEDSYNC, API will be return 0.
98 * If fota state is UPDATE or BACKUP (A/B system is not sync), indicate the inactive partition is being updated and can not switch A/B, API will be return -2
99 * If fota state is FAILED (A/B system is not sync), indicate the inactive partition was damaged and can not switch A/B, API will be return -3
100 * @Parameter
101 * No parameter
102 * @return
103 * - On success 0 indicate the switch flag was set succeed
104 * - On failure -1 get or set fota state and absys info failed;
105 * -2 indicate the inactive partition was damaged by ota upgrade, could not switch;
106 * -3 indicate the inactive partition is being upgraded or backup is in progress.
107 */
108//--------------------------------------------------------------------------------------------------
109int ql_absys_switch(void);
110
111
112//--------------------------------------------------------------------------------------------------
113/**
114 * @brief
115 * Program a synchronization active slot partition data to non-active partition
116 * @Parameter
117 * No parameter
118 * @return
119 * - On success 0
120 * - On failure -1
121 */
122//--------------------------------------------------------------------------------------------------
123int ql_absys_sync(void);
124
125
126//--------------------------------------------------------------------------------------------------
127/**
128 * @brief
129 * Program a synchronization active slot partition data to non-inactive partition
130 * @Parameter
131 * [IN] cpu_loading_level 0 ql_otad cpuloading 98%
132 * 1 ql_otad cpuloading 55%
133 * 2 ql_otad cpuloading 38%
134 * 3 ql_otad cpuloading 30%
135 * 4 ql_otad cpuloading 25%
136 * 5 ql_otad cpuloading 20%
137 * @return
138 * - On success 0
139 * - On failure -1
140 */
141//--------------------------------------------------------------------------------------------------
142int ql_absys_sync_control(int cpu_loading_level);
143
144
145#ifdef __cplusplus
146}
147#endif
148
149#endif //QL_ABSYS_H_