nkjnm

Dependencies:   MAX44000 nexpaq_mdk

Fork of LED_Demo by Maxim nexpaq

Committer:
nexpaq
Date:
Sat Sep 17 16:21:40 2016 +0000
Revision:
0:b86eda0e990d
checking in to share

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nexpaq 0:b86eda0e990d 1 /*
nexpaq 0:b86eda0e990d 2 * np_apis.c
nexpaq 0:b86eda0e990d 3 *
nexpaq 0:b86eda0e990d 4 * Created on: July 14, 2016
nexpaq 0:b86eda0e990d 5 * Author: Alan.Lin
nexpaq 0:b86eda0e990d 6 *
nexpaq 0:b86eda0e990d 7 * Copyright: NexPack Ltd.
nexpaq 0:b86eda0e990d 8 */
nexpaq 0:b86eda0e990d 9
nexpaq 0:b86eda0e990d 10 #include "np_apis.h"
nexpaq 0:b86eda0e990d 11 #include "np_app_ncn_interface.h"
nexpaq 0:b86eda0e990d 12 #include "np_app_spi.h"
nexpaq 0:b86eda0e990d 13 #include "np_system.h"
nexpaq 0:b86eda0e990d 14
nexpaq 0:b86eda0e990d 15 MDK_REGISTER_CMD *mdk_cmd_func_table_ptr;
nexpaq 0:b86eda0e990d 16 uint8_t mdk_cmd_func_number;
nexpaq 0:b86eda0e990d 17
nexpaq 0:b86eda0e990d 18 /*
nexpaq 0:b86eda0e990d 19 * Description: APP to set firmware version of APP by the api
nexpaq 0:b86eda0e990d 20 * Parameter: null
nexpaq 0:b86eda0e990d 21 * Return: null
nexpaq 0:b86eda0e990d 22 */
nexpaq 0:b86eda0e990d 23 void np_api_set_app_version(uint8_t HV, uint8_t MV, uint8_t LV) {
nexpaq 0:b86eda0e990d 24 mdk_app_version[0] = HV;
nexpaq 0:b86eda0e990d 25 mdk_app_version[1] = MV;
nexpaq 0:b86eda0e990d 26 mdk_app_version[2] = LV;
nexpaq 0:b86eda0e990d 27 }
nexpaq 0:b86eda0e990d 28
nexpaq 0:b86eda0e990d 29 /*
nexpaq 0:b86eda0e990d 30 * Description: APP to register processing function of command by the api
nexpaq 0:b86eda0e990d 31 * Parameter:
nexpaq 0:b86eda0e990d 32 * cmd_func_table: pointer of the space for hold the pointer of processing functions.
nexpaq 0:b86eda0e990d 33 * num : the number of the processing function.
nexpaq 0:b86eda0e990d 34 *
nexpaq 0:b86eda0e990d 35 * Return: 0-success; 1-fail
nexpaq 0:b86eda0e990d 36 */
nexpaq 0:b86eda0e990d 37 uint8_t np_api_register(MDK_REGISTER_CMD* cmd_func_table, uint8_t num) {
nexpaq 0:b86eda0e990d 38 uint8_t t_i = 0;
nexpaq 0:b86eda0e990d 39 uint8_t t_num = num;
nexpaq 0:b86eda0e990d 40
nexpaq 0:b86eda0e990d 41 for ( ; t_i < t_num; t_i++ ) {
nexpaq 0:b86eda0e990d 42 if ( (cmd_func_table[t_i].command > 0x27ff) || (cmd_func_table[t_i].command < 0x2700) ) {
nexpaq 0:b86eda0e990d 43 return 1;
nexpaq 0:b86eda0e990d 44 }
nexpaq 0:b86eda0e990d 45 }
nexpaq 0:b86eda0e990d 46 mdk_cmd_func_table_ptr = cmd_func_table;
nexpaq 0:b86eda0e990d 47 mdk_cmd_func_number = num;
nexpaq 0:b86eda0e990d 48
nexpaq 0:b86eda0e990d 49 return 0;
nexpaq 0:b86eda0e990d 50 }
nexpaq 0:b86eda0e990d 51
nexpaq 0:b86eda0e990d 52 /*
nexpaq 0:b86eda0e990d 53 * Description: APP to upload message to Phone/ble by the api
nexpaq 0:b86eda0e990d 54 * Parameter :
nexpaq 0:b86eda0e990d 55 * rcmd : The command of the message.
nexpaq 0:b86eda0e990d 56 * pData: Pointer of the space for hold the parameter of the message.
nexpaq 0:b86eda0e990d 57 * pLen : The length of the "pData"
nexpaq 0:b86eda0e990d 58 *
nexpaq 0:b86eda0e990d 59 * Return : 0-success; 1-fail
nexpaq 0:b86eda0e990d 60 */
nexpaq 0:b86eda0e990d 61 uint8_t np_api_upload(uint16_t rcmd, uint8_t *pData, uint8_t pLen) {
nexpaq 0:b86eda0e990d 62 // Over the fifo buffer
nexpaq 0:b86eda0e990d 63 if ( spi_post_buf.used_buffer_length + pLen > FIFO_BUFFER_OVERLOAD )
nexpaq 0:b86eda0e990d 64 return 1;
nexpaq 0:b86eda0e990d 65 np_function_ncn_interface_post_message(rcmd, pData, pLen);
nexpaq 0:b86eda0e990d 66
nexpaq 0:b86eda0e990d 67 return 0;
nexpaq 0:b86eda0e990d 68 }
nexpaq 0:b86eda0e990d 69
nexpaq 0:b86eda0e990d 70 /*
nexpaq 0:b86eda0e990d 71 * Description: APP to upload data to Gateway by the api
nexpaq 0:b86eda0e990d 72 * Parameter :
nexpaq 0:b86eda0e990d 73 * rcmd : The command of the message.
nexpaq 0:b86eda0e990d 74 * pData: Pointer of the space for hold the parameter of the message.
nexpaq 0:b86eda0e990d 75 * pLen : The length of the "pData"
nexpaq 0:b86eda0e990d 76 *
nexpaq 0:b86eda0e990d 77 * Return : 0-success; 1-fail
nexpaq 0:b86eda0e990d 78
nexpaq 0:b86eda0e990d 79 */
nexpaq 0:b86eda0e990d 80 uint8_t np_api_upload_to_station(uint16_t rcmd, uint8_t *pData, uint8_t pLen) {
nexpaq 0:b86eda0e990d 81 // Over the fifo buffer
nexpaq 0:b86eda0e990d 82 if ( spi_post_buf.used_buffer_length + pLen > FIFO_BUFFER_OVERLOAD )
nexpaq 0:b86eda0e990d 83 return 1;
nexpaq 0:b86eda0e990d 84 np_function_ncn_interface_post_message_to_station(rcmd, pData, pLen);
nexpaq 0:b86eda0e990d 85
nexpaq 0:b86eda0e990d 86 return 0;
nexpaq 0:b86eda0e990d 87 }
nexpaq 0:b86eda0e990d 88
nexpaq 0:b86eda0e990d 89 /*
nexpaq 0:b86eda0e990d 90 * Description:APP set a manually output address for next POST message
nexpaq 0:b86eda0e990d 91 * Parameter: null
nexpaq 0:b86eda0e990d 92 * Return: null
nexpaq 0:b86eda0e990d 93 */
nexpaq 0:b86eda0e990d 94 void np_api_set_post_address(uint8_t address) {
nexpaq 0:b86eda0e990d 95 source_address = address;
nexpaq 0:b86eda0e990d 96 }
nexpaq 0:b86eda0e990d 97
nexpaq 0:b86eda0e990d 98 /*
nexpaq 0:b86eda0e990d 99 * Description: system initial ,include MDK initial and app initial
nexpaq 0:b86eda0e990d 100 * Parameter: null
nexpaq 0:b86eda0e990d 101 * Return: null
nexpaq 0:b86eda0e990d 102 */
nexpaq 0:b86eda0e990d 103 void np_api_setup(app_function np_app_setup){
nexpaq 0:b86eda0e990d 104 np_system_initial(np_app_setup);
nexpaq 0:b86eda0e990d 105 }
nexpaq 0:b86eda0e990d 106
nexpaq 0:b86eda0e990d 107 /*
nexpaq 0:b86eda0e990d 108 * Description: system loop function, will loop forever.
nexpaq 0:b86eda0e990d 109 * Parameter: null
nexpaq 0:b86eda0e990d 110 * Return: null
nexpaq 0:b86eda0e990d 111 */
nexpaq 0:b86eda0e990d 112 void np_api_loop(app_function np_app_loop){
nexpaq 0:b86eda0e990d 113 np_system_loop(np_app_loop);
nexpaq 0:b86eda0e990d 114 }
nexpaq 0:b86eda0e990d 115
nexpaq 0:b86eda0e990d 116 /*
nexpaq 0:b86eda0e990d 117 * Description: initialize
nexpaq 0:b86eda0e990d 118 * Parameter: null
nexpaq 0:b86eda0e990d 119 * Return: null
nexpaq 0:b86eda0e990d 120 */
nexpaq 0:b86eda0e990d 121 void np_api_init(){
nexpaq 0:b86eda0e990d 122 np_sys_init();
nexpaq 0:b86eda0e990d 123 }
nexpaq 0:b86eda0e990d 124
nexpaq 0:b86eda0e990d 125 /*
nexpaq 0:b86eda0e990d 126 * Description: signal ready
nexpaq 0:b86eda0e990d 127 * Parameter: null
nexpaq 0:b86eda0e990d 128 * Return: null
nexpaq 0:b86eda0e990d 129 */
nexpaq 0:b86eda0e990d 130 void np_api_start(){
nexpaq 0:b86eda0e990d 131 np_sys_start();
nexpaq 0:b86eda0e990d 132 }
nexpaq 0:b86eda0e990d 133
nexpaq 0:b86eda0e990d 134 /*
nexpaq 0:b86eda0e990d 135 * Description: bootloader check
nexpaq 0:b86eda0e990d 136 * Parameter: null
nexpaq 0:b86eda0e990d 137 * Return: null
nexpaq 0:b86eda0e990d 138 */
nexpaq 0:b86eda0e990d 139 void np_api_bsl_chk(){
nexpaq 0:b86eda0e990d 140 np_sys_bsl_chk();
nexpaq 0:b86eda0e990d 141 }
nexpaq 0:b86eda0e990d 142
nexpaq 0:b86eda0e990d 143 #if 0
nexpaq 0:b86eda0e990d 144 /*
nexpaq 0:b86eda0e990d 145 * Description: API to set auto enter lpm0 mode
nexpaq 0:b86eda0e990d 146 * Parameter: null
nexpaq 0:b86eda0e990d 147 * Return: null
nexpaq 0:b86eda0e990d 148 */
nexpaq 0:b86eda0e990d 149 void np_api_lpm0_automode_set(void) {
nexpaq 0:b86eda0e990d 150 np_function_lpm0_automode_set();
nexpaq 0:b86eda0e990d 151 }
nexpaq 0:b86eda0e990d 152
nexpaq 0:b86eda0e990d 153 /*
nexpaq 0:b86eda0e990d 154 * Description: API to set auto exit lpm0 mode
nexpaq 0:b86eda0e990d 155 * Parameter: null
nexpaq 0:b86eda0e990d 156 * Return: null
nexpaq 0:b86eda0e990d 157 */
nexpaq 0:b86eda0e990d 158 void np_api_lpm0_automode_clear(void) {
nexpaq 0:b86eda0e990d 159 np_function_lpm0_automode_clear();
nexpaq 0:b86eda0e990d 160 }
nexpaq 0:b86eda0e990d 161
nexpaq 0:b86eda0e990d 162
nexpaq 0:b86eda0e990d 163 uint8_t np_api_lpm_mode_get(void){
nexpaq 0:b86eda0e990d 164 return np_function_pm_mode_get();
nexpaq 0:b86eda0e990d 165 }
nexpaq 0:b86eda0e990d 166
nexpaq 0:b86eda0e990d 167 /*
nexpaq 0:b86eda0e990d 168 * Description: API to get the sleep status about sleeping on lpm0 or lpm4
nexpaq 0:b86eda0e990d 169 * Parameter: null
nexpaq 0:b86eda0e990d 170 * Return: LPM0/LPM4/LPM_NONE
nexpaq 0:b86eda0e990d 171 */
nexpaq 0:b86eda0e990d 172 uint8_t np_api_lpm_status_get(void){
nexpaq 0:b86eda0e990d 173 return np_function_get_lpm_status();
nexpaq 0:b86eda0e990d 174 }
nexpaq 0:b86eda0e990d 175
nexpaq 0:b86eda0e990d 176 void np_mdk_set_run_the_loop(uint8_t t_data){
nexpaq 0:b86eda0e990d 177 np_function_set_run_the_loop(t_data);
nexpaq 0:b86eda0e990d 178 }
nexpaq 0:b86eda0e990d 179
nexpaq 0:b86eda0e990d 180 void np_mdk_start_loop_head_set(void){
nexpaq 0:b86eda0e990d 181 wakeup_run_loop_flag = 1;
nexpaq 0:b86eda0e990d 182 }
nexpaq 0:b86eda0e990d 183
nexpaq 0:b86eda0e990d 184 void np_mdk_lpm4_automode_clear_flag(void){
nexpaq 0:b86eda0e990d 185 np_function_lpm4_automode_clear();
nexpaq 0:b86eda0e990d 186 }
nexpaq 0:b86eda0e990d 187
nexpaq 0:b86eda0e990d 188 void np_api_lpm4_automode_set(void) {
nexpaq 0:b86eda0e990d 189 if(np_function_pm_mode_get() & LPM_0){
nexpaq 0:b86eda0e990d 190 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
nexpaq 0:b86eda0e990d 191 }
nexpaq 0:b86eda0e990d 192
nexpaq 0:b86eda0e990d 193 np_function_lpm4_automode_set();
nexpaq 0:b86eda0e990d 194 developer_lpm4_setting = 1;
nexpaq 0:b86eda0e990d 195 }
nexpaq 0:b86eda0e990d 196
nexpaq 0:b86eda0e990d 197 void np_api_lpm4_automode_clear(void) {
nexpaq 0:b86eda0e990d 198 np_mdk_lpm4_automode_clear_flag();
nexpaq 0:b86eda0e990d 199 np_mdk_start_loop_head_set();
nexpaq 0:b86eda0e990d 200 developer_lpm4_setting = 0;
nexpaq 0:b86eda0e990d 201 }
nexpaq 0:b86eda0e990d 202
nexpaq 0:b86eda0e990d 203 void np_mdk_exit_lpm4_work(void){
nexpaq 0:b86eda0e990d 204 np_function_exit_lpm4_work();
nexpaq 0:b86eda0e990d 205 }
nexpaq 0:b86eda0e990d 206
nexpaq 0:b86eda0e990d 207 #endif