forked from SZV10X_Software/SZV103_FM33A0xxEV_SiZhu

jinlicong
2024-06-19 6e3f1f560d618b37ee1a47fa2b0f682b70c3ef1c
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
#include "upper_com_iap_pro.h"
#include "upper_com.h"
#include "flash.h"
#include "bootloader_iap.h"
 
 
 
 
 
/*IAP¸üгÌÐòÁ÷³Ì£º9601 -> 9604 -> 9602 -> 9603 -> 9600*/
 
 
 
ErrorStatus_STM32 UC_IapResetHandler(u16 data_category_ID,uint8_t *DataPtr,UC_RECV_DATA_UNION_T *uc_respond_data_p)  
{
    /*¹Ø±ÕÈ«²¿ÍâÉè*/
    __disable_irq();//¹Ø±ÕÈ«¾ÖÖжÏʹÄÜ    
    delay_ms(100);
    RMU->SOFTRST = 0x5C5CAABB; //?Èí¼þ¸´Î»
    return SUCCESS_0;
}
 
/******************************************
 * func: UC_IapConfigSetHander
 * desc: IAPÏà¹ØµÄһЩÅäÖòÎÊýÉèÖÃ
 * input:  pInputData£º²ÎÊýÊý¾Ý£¬Ïê¼ûBOOTLOAD_PARA_STRUCT½á¹¹Ìå
 * output: none
 * return: SUCCESS_0£º³É¹¦  ERROR_1/ÆäËû£ºÊ§°Ü
 *****************************************/
ErrorStatus_STM32 UC_IapConfigSetHandler(u16 data_category_ID,uint8_t *DataPtr,UC_RECV_DATA_UNION_T *uc_respond_data_p)  
{
    uint8_t return_flag = SUCCESS_0;
    uint32_t data_len = uc_recv_para_g.uc_recv_buf_union.uc_protocol_head_s.data_field_length - UC_PROTOCOL_TABLE_ID_LENGTH;//¼õÈ¥±íºÅ
    
    return_flag = BootLoader_IapConfigSetHander(DataPtr,data_len);
    if(return_flag == SUCCESS_0){
        uc_respond_data_p->uc_recv_buf[UC_PROTOCOL_HEAD_LENGTH + UC_PROTOCOL_TABLE_ID_LENGTH] = 0;
    }else{
        uc_respond_data_p->uc_recv_buf[UC_PROTOCOL_HEAD_LENGTH + UC_PROTOCOL_TABLE_ID_LENGTH] = return_flag;
    }
    uc_respond_data_p->uc_protocol_head_s.data_field_length = UC_PROTOCOL_TABLE_ID_LENGTH + 1;
    
    return (ErrorStatus_STM32)return_flag;
}
 
ErrorStatus_STM32 UC_IapConfigLzmaSetHandler(u16 data_category_ID,uint8_t *DataPtr,UC_RECV_DATA_UNION_T *uc_respond_data_p)  
{
    uint8_t return_flag = SUCCESS_0;
    uint32_t data_len = uc_recv_para_g.uc_recv_buf_union.uc_protocol_head_s.data_field_length - UC_PROTOCOL_TABLE_ID_LENGTH;//¼õÈ¥±íºÅ
    return_flag = BootLoader_IapConfigLzmaSetHander(DataPtr,data_len);
    if(return_flag == SUCCESS_0){
        uc_respond_data_p->uc_recv_buf[UC_PROTOCOL_HEAD_LENGTH + UC_PROTOCOL_TABLE_ID_LENGTH] = 0;
    }else{
        uc_respond_data_p->uc_recv_buf[UC_PROTOCOL_HEAD_LENGTH + UC_PROTOCOL_TABLE_ID_LENGTH] = return_flag;
    }
    uc_respond_data_p->uc_protocol_head_s.data_field_length = UC_PROTOCOL_TABLE_ID_LENGTH + 1;
    
    return (ErrorStatus_STM32)return_flag;
}
 
/******************************************
 * func: UC_IapDiffDataHander
 * desc: ÕýʽдÈë²îÒìÊý¾Ý£¨´æ´¢ÔÚÆ¬ÍâFlash£©
 * input:  pInputData£º²îÒìÊý¾Ý£¬ÓÉÉÏλ»ú´ÓHexÎļþÌáÈ¡
 * output: none
 * return: SUCCESS_0£º³É¹¦  ERROR_1/ÆäËû£ºÊ§°Ü
 *****************************************/
ErrorStatus_STM32 UC_IapDiffDataHandler(u16 data_category_ID,uint8_t *DataPtr,UC_RECV_DATA_UNION_T *uc_respond_data_p)  
{
    uint8_t return_flag = SUCCESS_0;
    uint32_t offset_addr = (DataPtr[3] << 24) | (DataPtr[2] << 16) | (DataPtr[1] << 8) | DataPtr[0];
    uint32_t data_len = uc_recv_para_g.uc_recv_buf_union.uc_protocol_head_s.data_field_length - 4 //¼õÈ¥µØÖ·
                            - UC_PROTOCOL_TABLE_ID_LENGTH;//¼õÈ¥±íºÅ
    //Êý¾Ý´Ó[4]¿ªÊ¼
    return_flag = BootLoader_IapDiffDataHandler(&DataPtr[4],offset_addr,data_len);
    
    if(return_flag == SUCCESS_0){
        uc_respond_data_p->uc_recv_buf[UC_PROTOCOL_HEAD_LENGTH + UC_PROTOCOL_TABLE_ID_LENGTH] = 0;
    }else{
        uc_respond_data_p->uc_recv_buf[UC_PROTOCOL_HEAD_LENGTH + UC_PROTOCOL_TABLE_ID_LENGTH] = return_flag;
    }
    uc_respond_data_p->uc_protocol_head_s.data_field_length = UC_PROTOCOL_TABLE_ID_LENGTH + 1;
    
    return (ErrorStatus_STM32)return_flag;
}
/******************************************
 * func: UC_IapConfigCheckHander
 * desc: IAPÍê³ÉºóºË²éÊý¾ÝºÍ²ÎÊý
 * input:  none
 * output: none
 * return: SUCCESS_0£º³É¹¦  ERROR_1/ÆäËû£ºÊ§°Ü
 *****************************************/
ErrorStatus_STM32 UC_IapConfigCheckHandler(u16 data_category_ID,uint8_t *DataPtr,UC_RECV_DATA_UNION_T *uc_respond_data_p)  
{
    uint8_t return_flag = SUCCESS_0;
    return_flag = BootLoader_IapConfigCheckHandler();
    if(return_flag == SUCCESS_0){
        uc_respond_data_p->uc_recv_buf[UC_PROTOCOL_HEAD_LENGTH + UC_PROTOCOL_TABLE_ID_LENGTH] = 0;
    }else{
        uc_respond_data_p->uc_recv_buf[UC_PROTOCOL_HEAD_LENGTH + UC_PROTOCOL_TABLE_ID_LENGTH] = return_flag;
    }
    uc_respond_data_p->uc_protocol_head_s.data_field_length = UC_PROTOCOL_TABLE_ID_LENGTH + 1;
    
    return (ErrorStatus_STM32)return_flag;
}
/******************************************
 * func: UC_IapDiffMapSetHander
 * desc: IAPÏà¹ØµÄ²îÒì±í²ÎÊýÉèÖÃ
 * input:  pInputData£º²ÎÊýÊý¾Ý£¬Ïê¼ûÉÏλ»úЭÒé
 * output: none
 * return: SUCCESS_0£º³É¹¦  ERROR_1/ÆäËû£ºÊ§°Ü
 *****************************************/
ErrorStatus_STM32 UC_IapDiffMapSetHandler(u16 data_category_ID,uint8_t *DataPtr,UC_RECV_DATA_UNION_T *uc_respond_data_p)  
{
    uint8_t return_flag = SUCCESS_0;
    uint32_t offset_addr = (DataPtr[3] << 24) | (DataPtr[2] << 16) | (DataPtr[1] << 8) | DataPtr[0];
    uint32_t data_len = uc_recv_para_g.uc_recv_buf_union.uc_protocol_head_s.data_field_length - 4 //¼õÈ¥µØÖ·
                        - UC_PROTOCOL_TABLE_ID_LENGTH;//¼õÈ¥±íºÅ
        //Êý¾Ý´ÓpInputData[4]¿ªÊ¼
    return_flag = BootLoader_IapDiffMapSetHandler(&DataPtr[4],offset_addr,data_len);
    if(return_flag == SUCCESS_0){
        uc_respond_data_p->uc_recv_buf[UC_PROTOCOL_HEAD_LENGTH + UC_PROTOCOL_TABLE_ID_LENGTH] = 0;
    }else{
        uc_respond_data_p->uc_recv_buf[UC_PROTOCOL_HEAD_LENGTH + UC_PROTOCOL_TABLE_ID_LENGTH] = return_flag;
    }
    uc_respond_data_p->uc_protocol_head_s.data_field_length = UC_PROTOCOL_TABLE_ID_LENGTH + 1;
    
    return (ErrorStatus_STM32)return_flag;
}
 
 
 
/*ÉÏλ»úдÊý¾Ý´¦Àíº¯Êý*/
void Upper_ComputerIapHandler(UC_RECV_DATA_UNION_T *uc_recv_data_union_p,UC_RECV_DATA_UNION_T *uc_respond_data_p)
{
    uint16_t    data_category_ID;
    uint8_t    *data_p;
 
        uc_respond_data_p->uc_protocol_head_s.data_table_id = uc_recv_data_union_p->uc_protocol_head_s.data_table_id;
        data_category_ID= BSWAP_16(uc_recv_data_union_p->uc_protocol_head_s.data_table_id);
        data_p = uc_recv_data_union_p->uc_recv_buf + UC_PROTOCOL_HEAD_LENGTH +sizeof (uc_recv_data_union_p->uc_protocol_head_s.data_table_id);
        switch(data_category_ID)
            {
                case UIC_APP_RESET : UC_IapResetHandler(data_category_ID,data_p,uc_respond_data_p) ;break;
                case UIC_APP_CONFIG : UC_IapConfigSetHandler(data_category_ID,data_p,uc_respond_data_p) ;break;
                case UIC_APP_DIFF_DATA : UC_IapDiffDataHandler(data_category_ID,data_p,uc_respond_data_p) ;break;
                case UIC_APP_CONFIG_CHECK : UC_IapConfigCheckHandler(data_category_ID,data_p,uc_respond_data_p) ;break;
                case UIC_APP_DIFF_MAP : UC_IapDiffMapSetHandler(data_category_ID,data_p,uc_respond_data_p) ;break;
                case UIC_APP_CONFIG_LZMA : UC_IapConfigLzmaSetHandler(data_category_ID,data_p,uc_respond_data_p) ;break;
                default : break;
                
            }    
        
}