Magnificent7 / Hackathon
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers np_app_pm.c Source File

np_app_pm.c

00001 /*
00002  * np_app_pm.c
00003  *
00004  *  Created on: July 14, 2016
00005  *      Author: Alan.Lin
00006  *
00007  *  Copyright: NexPack Ltd.
00008  */
00009 
00010 #include <stdint.h>
00011 
00012 uint8_t run_the_loop = 0;
00013 uint8_t flag_on_lpm = 0;
00014 uint8_t developer_lpm4_setting = 0; //record the developer setting about the lpm4
00015 uint8_t wakeup_run_loop_flag = 0;
00016 #if 0
00017 extern void np_api_enter_lpm4_work();// for developer
00018 extern void np_api_exit_lpm4_work(); // for developer
00019 
00020 void np_function_set_run_the_loop(uint8_t t_data){
00021     run_the_loop = t_data;
00022 }
00023 
00024 uint8_t np_function_get_run_the_loop(void){
00025     return run_the_loop;
00026 }
00027 
00028 /*
00029  * Description: set auto enter lpm0 mode
00030  * Parameter: null
00031  * Return: null
00032  *
00033  * Author: Coody.Liu
00034  *
00035  * Copyright: NexPack.Ltd
00036  */
00037 void np_function_lpm0_automode_set(void) {
00038     np_driver_lpm0_automode_set();
00039 }
00040 
00041 /*
00042  * Description: exit auto exit lpm0 mode
00043  * Parameter: null
00044  * Return: null
00045  *
00046  * Author: Coody.Liu
00047  *
00048  * Copyright: NexPack.Ltd
00049  */
00050 void np_function_lpm0_automode_clear(void) {
00051     np_driver_lpm0_automode_clear();
00052 }
00053 
00054 void np_function_enter_lpm4_work(void){
00055     np_api_enter_lpm4_work();
00056     np_driver_spi_function_close();
00057     np_driver_enable_pin13_io_interrupt();
00058 }
00059 
00060 void np_function_exit_lpm4_work(void){
00061     np_driver_spi_function_open();
00062     np_api_exit_lpm4_work();
00063     //np_driver_disalbe_pin13_io_interrupt();
00064 }
00065 
00066 uint8_t flag_lpm4_enter = 0;
00067 /*
00068  * Description: run the power save mode loop
00069  * Parameter: null
00070  * Return: null
00071  *
00072  * Author: Coody.Liu
00073  *
00074  * Copyright: NexPack.Ltd
00075  */
00076 void np_function_pm_loop(void) {
00077     if(wakeup_run_loop_flag){
00078         return;
00079     }
00080 
00081     if((np_function_pm_mode_get() & LPM_4)){
00082         //v1_0_3--1   please reference the version.txt
00083         if((spi_status != SPI_BUSY)&&(np_app_spi_is_aviable())
00084             &&(spi_post_buf.message_num == 0)&&(spi_get_buf.message_num == 0)){
00085 
00086             flag_on_lpm = LPM_4;
00087             np_function_enter_lpm4_work();
00088             if(wakeup_run_loop_flag){
00089                 np_function_exit_lpm4_work();
00090             }else{//bug: if io interrupt wakeup on here, the module will no way to process.
00091                 __bis_SR_register(LPM4_bits);
00092             }
00093 
00094             flag_on_lpm = LPM_NONE;
00095         }
00096     }else if (np_function_pm_mode_get() & LPM_0){
00097         flag_on_lpm = LPM_0;
00098         __bis_SR_register(LPM0_bits);
00099         flag_on_lpm = LPM_NONE;
00100     }
00101 }
00102 
00103 /*
00104  * Description: set auto enter lpm0 mode
00105  * Parameter: null
00106  * Return: null
00107  *
00108  * Author: Coody.Liu
00109  *
00110  * Copyright: NexPack.Ltd
00111  */
00112 void np_function_lpm4_automode_set(void) {
00113     np_driver_lpm4_automode_set();
00114 }
00115 
00116 /*
00117  * Description: exit auto exit lpm0 mode
00118  * Parameter: null
00119  * Return: null
00120  *
00121  * Author: Coody.Liu
00122  *
00123  * Copyright: NexPack.Ltd
00124  */
00125 void np_function_lpm4_automode_clear(void) {
00126     np_driver_lpm4_automode_clear();
00127 }
00128 
00129 
00130 /*
00131  * Description: get the mode of auto lpm mode (lpm0/lpm4)
00132  * Parameter: null
00133  * Return: null
00134  *
00135  * Author: Coody.Liu
00136  *
00137  * Copyright: NexPack.Ltd
00138  */
00139 uint8_t np_function_pm_mode_get(void) {
00140     return np_driver_lpm_mode_get();
00141 }
00142 
00143 uint8_t np_function_get_lpm_status(void){
00144     return flag_on_lpm;
00145 }
00146 
00147 #endif