• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Chipsea Technologies (Shenzhen) Corp., Ltd. All rights reserved.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifdef CFG_AON
16 
17 /*chipsea_ohos proguard begin*/
18 #include "cs_proguard.h"
19 /*chipsea_ohos proguard end*/
20 #include "aon_sram.h"
21 
pm_app_static_save(void * aon_app_static)22 void pm_app_static_save(void *aon_app_static)
23 {
24     AppStatic app_static;
25     AonAppStatic *save_app_static = (AonAppStatic *)aon_app_static;
26 #ifndef CFG_BLE_ONLY
27 #if APP_SUPPORT_A2DP_SBC == 1 || APP_SUPPORT_A2DP_AAC == 1 || APP_SUPPORT_A2DP_SOURCE == 1
28     app_static.btstatic.t_a2dp_state =t_a2dp_state;
29 #endif
30 #if APP_SUPPORT_HFP == 1
31     app_static.btstatic.s_hfp_state =s_hfp_state;
32     app_static.btstatic.s_hfp_scocodec = s_hfp_scocodec;
33 #endif
34     for(uint8_t i = 0; i<HANDLER_REG_MAX;i++){
35         app_static.btstatic.handler_register_list[i] = handler_register_list[i];
36     }
37     for(uint8_t i = 0; i<LINK_MAX;i++){
38         app_static.btstatic.app_bt_connect_struct[i] = app_bt_connect_struct[i];
39         //app_static.btstatic.app_bt_connect_struct[i].reconnect.reconnect_mode = RECONNECT_IDLE;
40         app_static.btstatic.app_con_ptr[i] = app_con_ptr[i];
41     }
42     app_static.btstatic.s_bt_state =s_bt_state;
43     app_static.btstatic.bt_scan_mode = bt_scan_mode;
44     app_static.btstatic.cs_host_log = cs_host_log;
45 #if APP_SUPPORT_AES == 1
46     for(uint8_t i = 0; i < 8;i++){
47         app_static.btstatic.secret_key[i] = secret_key[i];
48     }
49 #endif
50 #endif
51 #if PLF_BLE_STACK == 1
52     app_static.blestatic.aon_ble_enabled = ble_enabled;
53     app_static.blestatic.aon_ble_app_env = app_env;
54     app_static.blestatic.aon_ble_app_user_info = ble_user_info;
55     AppBlePrfEnv *app_ble_prf_env = &app_static.ble_prf_env;
56     memcpy((uint8_t *)&app_ble_prf_env->prf_env, (uint8_t *)&prf_env, sizeof(struct prf_env_tag));
57     uint8_t i =0;
58 #if BLE_APP_HID
59     if (prf_env.prf[i].env != NULL) {
60         struct bass_env_tag *bass_env = PRF_ENV_GET(BASS, bass);
61         memcpy((uint8_t *)&app_ble_prf_env->bass_env, (uint8_t *)bass_env, sizeof(app_ble_prf_env->bass_env));
62         i++;
63     }
64     if (prf_env.prf[i].env != NULL) {
65         struct hogpd_env_tag *hogpd_env = PRF_ENV_GET(HOGPD, hogpd);
66         //dbg("hogpd_env->state %x\n",hogpd_env->state[0]);
67         //dbg("0x%x,%x, %x, %x,0x%x",prf_env.prf[i].desc.state,prf_env.prf[i].desc.state[0],prf_env.prf[i].desc.idx_max,prf_env.prf[i].desc.msg_cnt,prf_env.prf[i].desc.msg_handler_tab);
68         memcpy((uint8_t *)&app_ble_prf_env->hogpd_env, (uint8_t *)hogpd_env, sizeof(app_ble_prf_env->hogpd_env));
69         i++;
70     }
71 #endif //(BLE_APP_HID)
72 #if BLE_APP_SMARTCONFIG
73     if (prf_env.prf[i].env != NULL) {
74         struct smartconfig_env_tag *smartconfig_env = PRF_ENV_GET(SMARTCONFIG, smartconfig);
75         memcpy((uint8_t *)&app_ble_prf_env->smartconfig_env, (uint8_t *)smartconfig_env, sizeof(app_ble_prf_env->smartconfig_env));
76 
77         i++;
78     }
79 #endif // (BLE_APP_SMARTCONFIG)
80     ASSERT_ERR(sizeof(app_static) < AON_APP_STATIC_LEN);
81 #endif //(PLF_BLE_STACK == 1)
82     app_static.bt_lp_level = bt_lp_level;
83     save_app_static->len = sizeof(app_static);
84     memset(save_app_static->app_static, 0, save_app_static->len);
85     memcpy(save_app_static->app_static, (uint8_t *)&app_static, save_app_static->len);
86 
87     //TRACE("AON:app static save len = %d ,addr 0x%x\n",save_app_static->len,save_app_static);
88 }
89 
pm_app_static_restore(void * aon_app_static)90 void pm_app_static_restore(void *aon_app_static)
91 {
92     AppStatic app_static;
93     AonAppStatic *restore_app_static = (AonAppStatic *)aon_app_static;
94 
95     if(restore_app_static->len == sizeof(app_static)){
96         memcpy((uint8_t *)&app_static, restore_app_static->app_static, restore_app_static->len);
97     }else{
98         TRACE("AON:app static restore error!\n");
99         return;
100     }
101 #ifndef CFG_BLE_ONLY
102 #if APP_SUPPORT_A2DP_SBC == 1 || APP_SUPPORT_A2DP_AAC == 1 || APP_SUPPORT_A2DP_SOURCE == 1
103     t_a2dp_state = app_static.btstatic.t_a2dp_state;
104 #endif
105 #if APP_SUPPORT_HFP == 1
106     s_hfp_state = app_static.btstatic.s_hfp_state;
107     s_hfp_scocodec = app_static.btstatic.s_hfp_scocodec;
108 #endif
109     for(uint8_t i = 0; i<HANDLER_REG_MAX;i++){
110         handler_register_list[i] = app_static.btstatic.handler_register_list[i];
111     }
112     for(uint8_t i = 0; i<LINK_MAX;i++){
113         app_bt_connect_struct[i] = app_static.btstatic.app_bt_connect_struct[i];
114         app_con_ptr[i] = app_static.btstatic.app_con_ptr[i];
115     }
116     s_bt_state = app_static.btstatic.s_bt_state;
117     bt_scan_mode = app_static.btstatic.bt_scan_mode;
118     cs_host_log = app_static.btstatic.cs_host_log;
119 #if APP_SUPPORT_AES == 1
120     for(uint8_t i = 0; i < 8;i++){
121         secret_key[i] = app_static.btstatic.secret_key[i];
122     }
123 #endif
124 #endif
125 #if PLF_BLE_STACK == 1
126     ble_enabled = app_static.blestatic.aon_ble_enabled;
127     app_env = app_static.blestatic.aon_ble_app_env;
128     ble_user_info = app_static.blestatic.aon_ble_app_user_info;
129     AppBlePrfEnv *app_ble_prf_env = NULL;
130     app_ble_prf_env = &app_static.ble_prf_env;
131 
132     memcpy((uint8_t *)&prf_env, (uint8_t *)&app_ble_prf_env->prf_env, sizeof(struct prf_env_tag));
133     uint8_t i =0;
134 #if BLE_APP_HID
135     if (prf_env.prf[i].env != NULL) {
136         struct bass_env_tag* bass_env = NULL;
137         bass_env = (struct bass_env_tag* ) ke_malloc(sizeof(struct bass_env_tag), KE_MEM_ATT_DB);
138         memcpy((uint8_t *)bass_env, (uint8_t *)&app_ble_prf_env->bass_env, sizeof(app_ble_prf_env->bass_env));
139         prf_env.prf[i].env = (prf_env_t*) bass_env;
140         prf_env.prf[i].desc.state = bass_env->state;
141         i++;
142     }
143     if (prf_env.prf[i].env != NULL) {
144         struct hogpd_env_tag *hogpd_env = NULL;
145         hogpd_env = (struct hogpd_env_tag* ) ke_malloc(sizeof(struct hogpd_env_tag), KE_MEM_ATT_DB);
146         memcpy((uint8_t *)hogpd_env, (uint8_t *)&app_ble_prf_env->hogpd_env, sizeof(app_ble_prf_env->hogpd_env));
147         prf_env.prf[i].env = (prf_env_t*) hogpd_env;
148         prf_env.prf[i].desc.state = hogpd_env->state;
149         //dbg("hogpd_env->state %x\n",hogpd_env->state[0]);
150         //dbg("0x%x,%x, %x, %x,0x%x",prf_env.prf[i].desc.state,prf_env.prf[i].desc.state[0],prf_env.prf[i].desc.idx_max,prf_env.prf[i].desc.msg_cnt,prf_env.prf[i].desc.msg_handler_tab);
151         i++;
152     }
153 #endif // (BLE_APP_HID)
154 #if BLE_APP_SMARTCONFIG
155     if (prf_env.prf[i].env != NULL) {
156         struct smartconfig_env_tag* smartconfig_env =
157                 (struct smartconfig_env_tag* ) ke_malloc(sizeof(struct smartconfig_env_tag), KE_MEM_ATT_DB);
158         memcpy((uint8_t*)smartconfig_env, (uint8_t*)&app_ble_prf_env->smartconfig_env, sizeof(app_ble_prf_env->smartconfig_env));
159         prf_env.prf[i].env = (prf_env_t*) smartconfig_env;
160         prf_env.prf[i].desc.state = &smartconfig_env->state;
161         i++;
162     }
163 #endif // (BLE_APP_SMARTCONFIG)
164 #endif  //(PLF_BLE_STACK == 1)
165     bt_lp_level = app_static.bt_lp_level;
166     //TRACE("AON:app static restore\n");
167 }
168 
169 #endif
170