Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
np_apis.c
00001 /* 00002 * np_apis.c 00003 * 00004 * Created on: July 14, 2016 00005 * Author: Alan.Lin 00006 * 00007 * Copyright: NexPack Ltd. 00008 */ 00009 00010 #include "np_apis.h" 00011 #include "np_app_ncn_interface.h" 00012 #include "np_app_spi.h" 00013 #include "np_system.h" 00014 00015 MDK_REGISTER_CMD *mdk_cmd_func_table_ptr; 00016 uint8_t mdk_cmd_func_number; 00017 00018 /* 00019 * Description: APP to set firmware version of APP by the api 00020 * Parameter: null 00021 * Return: null 00022 */ 00023 void np_api_set_app_version(uint8_t HV, uint8_t MV, uint8_t LV) { 00024 mdk_app_version[0] = HV; 00025 mdk_app_version[1] = MV; 00026 mdk_app_version[2] = LV; 00027 } 00028 00029 /* 00030 * Description: APP to register processing function of command by the api 00031 * Parameter: 00032 * cmd_func_table: pointer of the space for hold the pointer of processing functions. 00033 * num : the number of the processing function. 00034 * 00035 * Return: 0-success; 1-fail 00036 */ 00037 uint8_t np_api_register(MDK_REGISTER_CMD* cmd_func_table, uint8_t num) { 00038 uint8_t t_i = 0; 00039 uint8_t t_num = num; 00040 00041 for ( ; t_i < t_num; t_i++ ) { 00042 if ( (cmd_func_table[t_i].command > 0x27ff) || (cmd_func_table[t_i].command < 0x2700) ) { 00043 return 1; 00044 } 00045 } 00046 mdk_cmd_func_table_ptr = cmd_func_table; 00047 mdk_cmd_func_number = num; 00048 00049 return 0; 00050 } 00051 00052 /* 00053 * Description: APP to upload message to Phone/ble by the api 00054 * Parameter : 00055 * rcmd : The command of the message. 00056 * pData: Pointer of the space for hold the parameter of the message. 00057 * pLen : The length of the "pData" 00058 * 00059 * Return : 0-success; 1-fail 00060 */ 00061 uint8_t np_api_upload(uint16_t rcmd, uint8_t *pData, uint8_t pLen) { 00062 // Over the fifo buffer 00063 if ( spi_post_buf.used_buffer_length + pLen > FIFO_BUFFER_OVERLOAD ) 00064 return 1; 00065 np_function_ncn_interface_post_message(rcmd, pData, pLen); 00066 00067 return 0; 00068 } 00069 00070 /* 00071 * Description: APP to upload data to Gateway by the api 00072 * Parameter : 00073 * rcmd : The command of the message. 00074 * pData: Pointer of the space for hold the parameter of the message. 00075 * pLen : The length of the "pData" 00076 * 00077 * Return : 0-success; 1-fail 00078 00079 */ 00080 uint8_t np_api_upload_to_station(uint16_t rcmd, uint8_t *pData, uint8_t pLen) { 00081 // Over the fifo buffer 00082 if ( spi_post_buf.used_buffer_length + pLen > FIFO_BUFFER_OVERLOAD ) 00083 return 1; 00084 np_function_ncn_interface_post_message_to_station(rcmd, pData, pLen); 00085 00086 return 0; 00087 } 00088 00089 /* 00090 * Description:APP set a manually output address for next POST message 00091 * Parameter: null 00092 * Return: null 00093 */ 00094 void np_api_set_post_address(uint8_t address) { 00095 source_address = address; 00096 } 00097 00098 /* 00099 * Description: system initial ,include MDK initial and app initial 00100 * Parameter: null 00101 * Return: null 00102 */ 00103 void np_api_setup(app_function np_app_setup){ 00104 np_system_initial(np_app_setup); 00105 } 00106 00107 /* 00108 * Description: system loop function, will loop forever. 00109 * Parameter: null 00110 * Return: null 00111 */ 00112 void np_api_loop(app_function np_app_loop){ 00113 np_system_loop(np_app_loop); 00114 } 00115 00116 /* 00117 * Description: initialize 00118 * Parameter: null 00119 * Return: null 00120 */ 00121 void np_api_init(){ 00122 np_sys_init(); 00123 } 00124 00125 /* 00126 * Description: signal ready 00127 * Parameter: null 00128 * Return: null 00129 */ 00130 void np_api_start(){ 00131 np_sys_start(); 00132 } 00133 00134 /* 00135 * Description: bootloader check 00136 * Parameter: null 00137 * Return: null 00138 */ 00139 void np_api_bsl_chk(){ 00140 np_sys_bsl_chk(); 00141 } 00142 00143 #if 0 00144 /* 00145 * Description: API to set auto enter lpm0 mode 00146 * Parameter: null 00147 * Return: null 00148 */ 00149 void np_api_lpm0_automode_set(void) { 00150 np_function_lpm0_automode_set(); 00151 } 00152 00153 /* 00154 * Description: API to set auto exit lpm0 mode 00155 * Parameter: null 00156 * Return: null 00157 */ 00158 void np_api_lpm0_automode_clear(void) { 00159 np_function_lpm0_automode_clear(); 00160 } 00161 00162 00163 uint8_t np_api_lpm_mode_get(void){ 00164 return np_function_pm_mode_get(); 00165 } 00166 00167 /* 00168 * Description: API to get the sleep status about sleeping on lpm0 or lpm4 00169 * Parameter: null 00170 * Return: LPM0/LPM4/LPM_NONE 00171 */ 00172 uint8_t np_api_lpm_status_get(void){ 00173 return np_function_get_lpm_status(); 00174 } 00175 00176 void np_mdk_set_run_the_loop(uint8_t t_data){ 00177 np_function_set_run_the_loop(t_data); 00178 } 00179 00180 void np_mdk_start_loop_head_set(void){ 00181 wakeup_run_loop_flag = 1; 00182 } 00183 00184 void np_mdk_lpm4_automode_clear_flag(void){ 00185 np_function_lpm4_automode_clear(); 00186 } 00187 00188 void np_api_lpm4_automode_set(void) { 00189 if(np_function_pm_mode_get() & LPM_0){ 00190 np_mdk_set_run_the_loop(TRUE);//if developer set lpm4 on interrupt and firmware is running on lpm0,need wakup lpm0 and enter lpm4 00191 } 00192 00193 np_function_lpm4_automode_set(); 00194 developer_lpm4_setting = 1; 00195 } 00196 00197 void np_api_lpm4_automode_clear(void) { 00198 np_mdk_lpm4_automode_clear_flag(); 00199 np_mdk_start_loop_head_set(); 00200 developer_lpm4_setting = 0; 00201 } 00202 00203 void np_mdk_exit_lpm4_work(void){ 00204 np_function_exit_lpm4_work(); 00205 } 00206 00207 #endif
Generated on Tue Jul 12 2022 12:58:33 by
1.7.2