-
Notifications
You must be signed in to change notification settings - Fork 28
/
mible_mcu.c
executable file
·190 lines (160 loc) · 4.68 KB
/
mible_mcu.c
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
/*
* mible_mcu.c
*
* Created on: 2020Äê10ÔÂ26ÈÕ
* Author: mi
*/
#include <string.h>
#include "mible_mcu.h"
#include "mible_log.h"
__WEAK mible_status_t mible_mcu_cmd_send(mible_mcu_cmd_t cmd, void* arg)
{
mible_status_t ret = MI_SUCCESS;
switch(cmd) {
case MIBLE_MCU_GET_VERSION:
break;
case MIBLE_MCU_READ_DFUINFO:
break;
case MIBLE_MCU_WRITE_DFUINFO:
break;
case MIBLE_MCU_WRITE_FIRMWARE:
break;
case MIBLE_MCU_VERIFY_FIRMWARE:
break;
case MIBLE_MCU_UPGRADE_FIRMWARE:
break;
case MIBLE_MCU_TRANSFER:
break;
default:
break;
}
return ret;
}
__WEAK mible_status_t mible_mcu_cmd_wait(mible_mcu_cmd_t cmd, void* arg)
{
mible_status_t ret = MI_SUCCESS;
switch(cmd) {
case MIBLE_MCU_GET_VERSION:
ret = MI_ERR_NOT_FOUND;
break;
case MIBLE_MCU_READ_DFUINFO:
ret = MI_ERR_NOT_FOUND;
break;
case MIBLE_MCU_WRITE_DFUINFO:
break;
case MIBLE_MCU_WRITE_FIRMWARE:
break;
case MIBLE_MCU_VERIFY_FIRMWARE:
break;
case MIBLE_MCU_UPGRADE_FIRMWARE:
break;
case MIBLE_MCU_TRANSFER:
break;
default:
break;
}
return ret;
}
PT_THREAD(mible_mcu_get_info(pt_t * pt, uint8_t *buf))
{
mible_status_t ret;
PT_BEGIN(pt);
if(MI_SUCCESS != mible_mcu_cmd_send(MIBLE_MCU_GET_VERSION, NULL))
goto EXIT;
PT_WAIT_UNTIL(pt, MI_ERR_BUSY != (ret = mible_mcu_cmd_wait(MIBLE_MCU_GET_VERSION, (void*)buf)));
if(ret != MI_SUCCESS){
MI_LOG_WARNING("mible_mcu_get_info fail %d\n", ret);
goto EXIT;
}
PT_END(pt);
EXIT:
PT_EXIT(pt);
}
PT_THREAD(mible_mcu_read_dfuinfo(pt_t * pt, uint8_t* m_dfu_info, uint8_t len))
{
mible_status_t ret;
PT_BEGIN(pt);
if(MI_SUCCESS != mible_mcu_cmd_send(MIBLE_MCU_READ_DFUINFO, NULL))
goto EXIT;
PT_WAIT_UNTIL(pt, MI_ERR_BUSY != (ret = mible_mcu_cmd_wait(MIBLE_MCU_READ_DFUINFO, (void*)m_dfu_info)));
if(ret != MI_SUCCESS){
MI_LOG_WARNING("mible_mcu_read_dfuinfo fail %d\n", ret);
goto EXIT;
}
PT_END(pt);
EXIT:
PT_EXIT(pt);
}
PT_THREAD(mible_mcu_write_dfuinfo(pt_t * pt, uint8_t* m_dfu_info, uint8_t len))
{
mible_status_t ret;
PT_BEGIN(pt);
if(MI_SUCCESS != mible_mcu_cmd_send(MIBLE_MCU_WRITE_DFUINFO, (void*)m_dfu_info))
goto EXIT;
PT_WAIT_UNTIL(pt, MI_ERR_BUSY != (ret = mible_mcu_cmd_wait(MIBLE_MCU_WRITE_DFUINFO, NULL)));
if(ret != MI_SUCCESS){
MI_LOG_WARNING("mible_mcu_write_dfuinfo fail %d\n", ret);
goto EXIT;
}
PT_END(pt);
EXIT:
PT_EXIT(pt);
}
PT_THREAD(mible_mcu_upgrade_firmware(pt_t * pt))
{
mible_status_t ret;
PT_BEGIN(pt);
if(MI_SUCCESS != mible_mcu_cmd_send(MIBLE_MCU_UPGRADE_FIRMWARE, NULL))
goto EXIT;
PT_WAIT_UNTIL(pt, MI_ERR_BUSY != (ret = mible_mcu_cmd_wait(MIBLE_MCU_UPGRADE_FIRMWARE, NULL)));
if(ret != MI_SUCCESS){
MI_LOG_WARNING("mible_mcu_upgrade_firmware fail %d\n", ret);
goto EXIT;
}
PT_END(pt);
EXIT:
PT_EXIT(pt);
}
PT_THREAD(mible_mcu_verify_firmware(pt_t * pt))
{
mible_status_t ret;
PT_BEGIN(pt);
if(MI_SUCCESS != mible_mcu_cmd_send(MIBLE_MCU_VERIFY_FIRMWARE, NULL))
goto EXIT;
PT_WAIT_UNTIL(pt, MI_ERR_BUSY != (ret = mible_mcu_cmd_wait(MIBLE_MCU_VERIFY_FIRMWARE, NULL)));
if(ret != MI_SUCCESS){
MI_LOG_WARNING("mible_mcu_verify_firmware fail %d\n", ret);
goto EXIT;
}
PT_END(pt);
EXIT:
PT_EXIT(pt);
}
PT_THREAD(mible_mcu_nvm_write(pt_t * pt, void * p_data, uint32_t length, uint32_t address))
{
mible_status_t ret;
mible_mcu_nvminfo_t nvminfo = {
.address = address,
.length = length,
.p_data = p_data
};
PT_BEGIN(pt);
MI_LOG_DEBUG("mible_mcu_nvm_write addr %08x, len %d\n", nvminfo.address, nvminfo.length);
if(MI_SUCCESS != mible_mcu_cmd_send(MIBLE_MCU_WRITE_FIRMWARE, (void*)&nvminfo))
goto EXIT;
PT_WAIT_UNTIL(pt, MI_ERR_BUSY != (ret = mible_mcu_cmd_wait(MIBLE_MCU_WRITE_FIRMWARE, NULL)));
if(ret != MI_SUCCESS){
MI_LOG_WARNING("mible_mcu_nvm_write fail %d\n", ret);
goto EXIT;
}
if(MI_SUCCESS != mible_mcu_cmd_send(MIBLE_MCU_TRANSFER, (void*)&nvminfo))
goto EXIT;
PT_WAIT_UNTIL(pt, MI_ERR_BUSY != (ret = mible_mcu_cmd_wait(MIBLE_MCU_TRANSFER, NULL)));
if(ret != MI_SUCCESS){
MI_LOG_WARNING("mible_mcu_nvm_write transfer fail %d\n", ret);
goto EXIT;
}
PT_END(pt);
EXIT:
PT_EXIT(pt);
}