forked from SZV10X_Software/SZV103_FM33A0xxEV_SiZhu

周巍
2024-04-11 91ef77c00ed797b1048c5187f416e351e646a009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
 
/******************************************************************************
 * Copyright (C) 2014-2015 HangZhou SiZhu Co.,LTD.
 *
 *-----------------------------------------------------------------------------
 * File:                 main.c
 * Description:        main test code used for test all hardware
 * Author:              Lishoujian (867693272@qq.com)
 * Date:                Jan 8, 2015
 *****************************************************************************/
 
//eMBPoll()Öе÷ÓÃ״̬»ú½ÓÊÜÊý¾Ý´¦ÀíºóÇл»µ½·¢ËÍ״̬£¬ÔÚµ±Ç°ÏµÍ³¹¤×÷ģʽÏ»ᵼÖ³¬Ê±´íÎó£¬Òò´Ë²»Ê¹ÓÃ״̬»ú¡£
 
//MODBUS¸ÄΪDMA·½Ê½½ÓÊÕ£¬ÐÞ¸Ä4´¦¡£
//Ò»¡¢eMBEnable()ÄڵĶ¨Ê±Æ÷ºÍ½ÓÊÜÖжϿªÆôº¯ÊýpvMBFrameStartCur(  )×¢ÊÍ¡£
//¶þ¡¢485Çý¶¯ÖжÏÅäÖøÄΪDMA¡£
//Èý¡¢eMBPoll()ÖÐʹÓÃxMBRTUReceiveCheck();
//ËÄ¡¢eMBRTUSend()ÄÚÊý¾Ý·¢ËÍÖжϿªÆôvMBPortSerialEnable( FALSE, TRUE )×¢ÊÍ¡£
 
/* ----------------------- Platform includes --------------------------------*/
#include "main.h"
#include "ad421.h"
 
#define            DEBUG_V20
#define            DEBUG_TEM_AND_PRE
#define            DATA_UPDATA
#define            DEBUG_KEY_AND_LED
#define            DEBUG_MODBUS
 
#define            OLED_SHOW
 
//
volatile u16 TempBuf[16] __attribute__((at(0x08007800)))   = {0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88,0x99,0xaa,0xbb,0xcc,0xdd,0xee,0xff};
/******************************************
 * func:    main
 * desc:    main test code used for test all hardware
 * input:   none
 * output:  none
 * return:  none
 *****************************************/
int main(void)
{
    /*µØÖ·×ª»»*/
    SCB->VTOR = FLASH_BASE | 0x8000; /* Vector Table Relocation in Internal FLASH. */
    /*ÍâÉè³õʼ»¯*/
    All_clock_Init();
    Delay_init();    
    All_GPIO_Init();        //¶Ë¿Ú³õʼ»¯
     All_SPI_Init();
    /*test for ads1120*/
    
    /*²ÎÊý³õʼ»¯*/
    para_init();
    /*´®¿Ú ÐèÒªÔÚ²ÎÊýºóÃæ½øÐгõʼ»¯*/
    all_uart_init();
    /*ϵͳÍâÉè³õʼ»¯*/
    system_init_detection();
 
// //    while(1);
//    data_save_test();
    while(1)
    {
        //IWDG_Init();
        while(SYSTEM_ONLY_WORK_MODE == v20_system_para_g.system_mode)
        {
            
            //³õʼ»¯¶¨Ê±Æ÷£¬¿ªÊ¼ÖÜÆÚÐÔ¹¤×÷
            //All_clock_Init();
            work_process_para_init();    
            
            while(SYSTEM_ONLY_WORK_MODE == v20_system_para_g.system_mode )
            {
                
                // µÈ´ýʱ¼äÖÜÆÚµ½
                
                if( (system_time_ev_g.time_period_flag == TRUE) && (v20_system_para_g.system_extern_power_connect_flag == ACTIVE) )
                {
                    // All_GPIO_Init();
                    // Test_GPIO_High;
                    //****************²âÁ¿Î¶ÈѹÁ¦ + *********************//
          Pulse_Output();
                    lower_pluse_out();
                    current_output();
                    
                     measure_process_new_state1();    
// #ifdef DEBUG_TEM_AND_PRE
//                                          
// #endif
 
// #ifdef    OLED_SHOW         
//                     
// #endif
                    measure_process_new_state2(1);
                    pressure_and_temperature_process(3,1);
                    
                    
                    //get_pushdown_flag();
                    //ת»»Êý¾Ý
                    //µÃµ½Ë²Ê±½á¹û,ת»»½á¹û
                          
#ifdef DATA_UPDATA
                    /*Ìúµç´æ´¢Êý¾Ý*/
                    data_trans_reg();
            
#endif
                     sys_menu();  
                 //    flash_save_process();
             
#ifdef     DEBUG_MODBUS
                    //¼ì²é´®¿ÚÊý¾Ý
                    rx_pc_485_task();
                    bt_process(1);
 
#endif    
 
 
#if    1                
                     
                    gprs_handle();
#endif
 
 
                    //create_log_process();
                    /*ϵͳ
                    ¼ì²é*/
                    system_working_detection();
                //    while(1);
                    system_time_ev_g.time_period_flag = FALSE;
                    system_jump();
    //            GPIO_IPD_Init();
                    /*¿´ÃŹ·Î¹¹·*/
                    IWDG_Feed();
    //            PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI);
                    
                    
                 }
 
                /*²»½ÓÍâµçµÄÇé¿öÏÂÐÝÃß*/
                
        
            }
        }
        
        while(SYSTEM_LOWPOWER_WORK_MODE == v20_system_para_g.system_mode)
        {
            //³õʼ»¯¶¨Ê±Æ÷£¬¿ªÊ¼ÖÜÆÚÐÔ¹¤×÷
            low_power_process_para_init();
            while(SYSTEM_LOWPOWER_WORK_MODE == v20_system_para_g.system_mode )
            {
                
                if( (system_time_ev_g.time_period_flag == TRUE) && (v20_system_para_g.system_extern_power_connect_flag == NOACTIVE) )
                {
 
                    
                    All_GPIO_Lowpower_Init();        //¶Ë¿Ú³õʼ»¯
                    lower_pluse_out();
                    current_output();
                    
                    measure_process_new_low_power_state1();    
                    
                    measure_process_new_low_power_state2(1);
 
                    
/*´æ´¢µÄÊÇÉÏÒ»ÃëµÄÊý¾Ý£¬Ö»ÊÇÕë¶ÔµÍ¹¦ºÄģʽÏÂ*/
 
                
                    /*GPRSÊý¾Ý´¦Àíº¯Êý*/
#if    1                   
                    gprs_handle();
#endif
 
/*µÈ´ýʱ£¬´¦Àí±ðµÄÊÂÎñ*/
#ifdef DEBUG_TEM_AND_PRE
 
                    pressure_and_temperature_process(60,0);
#endif                    
                    
                data_trans_reg();
#ifdef     DEBUG_MODBUS
                //¼ì²é´®¿ÚÊý¾ÝºÍÀ¶ÑÀͨÐÅÊý¾Ý
                /*ÈÕÖ¾´æ´¢*/
                create_log_process();
                
                    bt_process(0);     
#endif    
                /*flash ´æ´¢Êý¾Ý*/
                //    flash_save_process();    
                sys_menu();        
                //ת»»Êý¾Ý
                //µÃµ½Ë²Ê±½á¹û,ת»»½á¹û
 
                    system_working_detection();
                
                    system_time_ev_g.time_period_flag = FALSE;
                    
                    /*¿´ÃŹ·Î¹¹·*/
                    IWDG_Feed();
                    if(0 == system_connect())
                    {
                        GPIO_IPD_Init();
                        //ex_rtc_nv_config_disable();
                        PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI);
                        
                        All_clock_Init();    
                    
                    }
                
                }
            }
            
        }
 
 
        /*DEBUG MODE*/
        while(SYSTEM_DEBUG_MODE == v20_system_para_g.system_mode)
        {
            system_debug_para_init();
            //system_in_debug_fpga_init();
            while(SYSTEM_DEBUG_MODE == v20_system_para_g.system_mode )
            {
                debug_pc_485_task();
                delay_ms(10);
                v20_system_para_g.system_mode = debug_task();
                /*¿´ÃŹ·Î¹¹·*/
                IWDG_Feed();
            }
            system_debug_para_out();
                
        }
        
        /*UPDATA  MODE*/
        while(SYSTEM_UPDATA_MODE == v20_system_para_g.system_mode)
        {
            
            while(SYSTEM_UPDATA_MODE == v20_system_para_g.system_mode )
            {
 
                enter_void();
            }
 
            
                
        }
    }
}