forked from SZV10X_Software/SZV103_FM33A0xxEV_SiZhu

jinlicong
2024-05-16 5ac1d0febb8de5e91ce2463baea68ddac3f66091
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
#include "system_general_para.h"
#include "main.h"
#include "extern_rtc.h"
 
//uint8_t read_data_buf_A_l[200] ={0};
//uint8_t read_data_buf_B_l[200] ={0};
//uint8_t read_data_buf_C_l[200] ={0};
 
__IO FlagStatus sys_run_period = RESET; // ÏµÍ³¼¤»îÖÜÆÚ
 
SYS_DELAY_SEC_PARA_T sys_delay_sec_para_g = { .gprs_timeout_para.delay_flag = RESET,  \
        .gprs_timeout_para.delay_time = 0,    \
        .sys_active_time.delay_flag = RESET,     \
        .sys_active_time.delay_time = SYS_WAKE_UP_TIME,    \
        .sys_restart_delay_time.delay_flag = RESET,     \
        .sys_restart_delay_time.delay_time = 180,    \
    
};
 
FUN_START_CTRL_PARA_T sys_fun_run_ctrl_g;
 
 
/*******************³£ÓõĴúÂ빤¾ß********************************/
/******************************************
 * func: ucharcmp
 * desc: Á½×éÊý¾Ý±È½Ï£¬²»Ïàͬ·µ»ØFAIL,Ïàͬ·µ»ØPASS
 * input: none
 * output: none
 * return: none
 *****************************************/
ErrorStatus  ucharcmp(uint8_t *dataA,uint8_t *dataB,uint16_t data_length)
{
    uint16_t index_i=0;
    ErrorStatus return_flag=FAIL;
    for(index_i=0;index_i<data_length;index_i++)
    {
        if((*(dataA + index_i))!=(*(dataB + index_i)) )        
        {
            return_flag = FAIL;
            break;
        }else
        {
            
        }
                
    }
    
    if(index_i ==data_length)
    {
        return_flag = PASS;
    }
    
    return  return_flag;
}
 
 
 
/******************************************
 * func: arrayA_2_arrayB
 * desc: array A TO array B
 * input: none
 * output: none
 * return: none
 *****************************************/
void arrayA_2_arrayB(uint8_t * aA , uint8_t * aB, uint16_t len, BIG_OR_LITTLE_ENDIAN mode)  
{
    uint16_t index;
    uint8_t *ptra,*ptrb;
    
    if(mode==LITTLE_ENDIAN)
    {
        ptra = aA;
        ptrb = aB;
        for(index = 0; index < len; index ++)
        {
            *ptrb = *ptra;
            ptrb ++;
            ptra ++;
        }    
    }else if(mode==BIG_ENDIAN)
    {
        ptra = aA + len - 1;
        ptrb = aB;
        for(index = 0; index < len; index ++)
        {
            *ptrb = *ptra;
            ptrb ++;
            ptra --;
        }    
        
    }
}
 
 
 
 
/******************************************
 * func: IntervalTriggerHandle
 * desc: ¼ä¸ô´¥·¢£¬Ö»¿¼ÂÇ1ÌìÄڵ쬼ä¸ôʱ³¤³¬¹ý1ÌìµÄ²»¿¼ÂÇ£¬±ÈÈç1ÌìÄڵļä¸ô60·ÖÖÓ´¥·¢Ò»´Î
 * input: IntervalTime¼ä¸ôʱ¼ä£¬µ¥Î»·Ö  ; IntervalFirstTimeBCDÊ×´Îʱ¼ä,ʱ£¬·Ö£¬Ê±ÔÚǰ 
 * output: FlagStatus  SET±íʾÉúЧ
 * return: none
 *****************************************/
FlagStatus IntervalTriggerHandle(sClockBCD sys_clockBCD_in,uint16_t IntervalTime,uint8_t *IntervalFirstTimeBCD)
{
    //¼ä¸ôÉϱ¨ÔÝʱ²»¿¼ÂǼä¸ô³¬¹ý1440·ÖÖÓ£¬Ò²¾ÍÊdz¬¹ý1Ìì¡£
    uint16_t  FirstTime; //Ê×´ÎÉϱ¨Ê±¼ä£¬ÕÛËã³É·ÖÖÓ
    uint16_t  NextTime; //Ï´ÎÉϱ¨Ê±¼ä£¬·ÖÖÓ
    uint16_t  CurrentTime;//µ±Ç°Ê±¼ä£¬ÕÛËã³É·ÖÖÓ
    uint16_t  Count_i=0;
    uint16_t  ComparisonsNumber;
    
 
    if(IntervalTime==0)
    {
        return RESET;
    }
    
    FirstTime = (uint16_t)BCD_2_DECIMAL(IntervalFirstTimeBCD[0]) * 60 + BCD_2_DECIMAL(IntervalFirstTimeBCD[1]);
    
    CurrentTime = (uint16_t)BCD_2_DECIMAL(sys_clockBCD_in.hour) *60 + BCD_2_DECIMAL(sys_clockBCD_in.min);
    NextTime = FirstTime; 
    
    ComparisonsNumber = (IntervalTime !=0)? 1440/IntervalTime +1 : 1;
    
    if(sys_clockBCD_in.sec == 0) //ΪÁ˼õÉÙ×ÊÔ´ÀË·Ñ£¬Ö»ÓÐÔÚÃëÖÓ=0ʱÅжÏ
    {
        for(Count_i =0;Count_i<ComparisonsNumber;Count_i++)  
        {            
            if(NextTime == CurrentTime )
            {
                return SET;                                
            }
            else
            {
                NextTime = NextTime + IntervalTime; //Ï´ÎÉϱ¨Ê±¼äµã
                if(NextTime>=1440)
                {
                    NextTime -=1440;
                }
            }            
        }
    }
    
    return RESET;
}
 
//IO¿ÚÑÓ³ÙÏû¶¶¼ì²â
FlagStatus IO_JitterEliminationCheck(GPIO_Type* GPIOx, uint32_t GPIO_Pin,uint16_t delay_time_ms,BitAction bit_status)
{
    if(delay_time_ms>1000)  //Ŀǰ×î´ó¼ì²â1000msÑÓʱ£¬Ì«´ó×îϵͳÔì³ÉÓ°Ïì
        return RESET;
    
    if(GPIO_ReadInputDataBit(GPIOx, GPIO_Pin) == bit_status){
        if(delay_time_ms > 0)
            delay_ms(delay_time_ms);
        if(GPIO_ReadInputDataBit(GPIOx, GPIO_Pin) == bit_status){
            return SET;
        }else{
            return RESET;
        }
        
    }else{
        return RESET;
    }
    
}