添加一些oem_tool的注释 ram工具下载成功后自动重启
This commit is contained in:
@@ -150,6 +150,8 @@ uint8_t gpio_func_sel(uint8_t gpio)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 输出inid
|
||||||
|
// sig_type gpio信号的类型 number,外设或内设的编号
|
||||||
uint8_t get_matrix_signal_inid(uint8_t sig_type, uint8_t number)
|
uint8_t get_matrix_signal_inid(uint8_t sig_type, uint8_t number)
|
||||||
{
|
{
|
||||||
uint8_t inid = 0xff;
|
uint8_t inid = 0xff;
|
||||||
@@ -284,6 +286,8 @@ uint8_t get_matrix_signal_inid(uint8_t sig_type, uint8_t number)
|
|||||||
return inid;
|
return inid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 输出outid
|
||||||
|
// sig_type gpio信号的类型 number,外设或内设的编号
|
||||||
uint8_t get_matrix_signal_outid(uint8_t sig_type, uint8_t number)
|
uint8_t get_matrix_signal_outid(uint8_t sig_type, uint8_t number)
|
||||||
{
|
{
|
||||||
uint8_t outid = 0xff;
|
uint8_t outid = 0xff;
|
||||||
@@ -537,6 +541,8 @@ uint8_t get_matrix_signal_outid(uint8_t sig_type, uint8_t number)
|
|||||||
return outid;
|
return outid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 如果buf中的字符全是空白或者以 # 开头则返回1
|
||||||
uint8_t is_comments_and_blankline(char *buf)
|
uint8_t is_comments_and_blankline(char *buf)
|
||||||
{
|
{
|
||||||
char *ptr = buf;
|
char *ptr = buf;
|
||||||
@@ -556,8 +562,10 @@ uint8_t is_comments_and_blankline(char *buf)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// buf 是一行字符 如果这行字符在几种类型之中,返回类型代码,否则返回0xff
|
||||||
uint8_t get_category_info(char *buf)
|
uint8_t get_category_info(char *buf)
|
||||||
{
|
{
|
||||||
|
// 以 空格 分割字符串
|
||||||
char *start = strtok(buf, " ");
|
char *start = strtok(buf, " ");
|
||||||
category_type_t category = CATEGORY_MAX;
|
category_type_t category = CATEGORY_MAX;
|
||||||
|
|
||||||
@@ -568,9 +576,11 @@ uint8_t get_category_info(char *buf)
|
|||||||
if (!strcmp(start, "general")) {
|
if (!strcmp(start, "general")) {
|
||||||
category = CATEGORY_GENERAL;
|
category = CATEGORY_GENERAL;
|
||||||
} else if(!strcmp(start, "rc_hdr")) {
|
} else if(!strcmp(start, "rc_hdr")) {
|
||||||
|
// 如果类型为 rc_hdr 则初始化一份配置表
|
||||||
category = CATEGORY_RC_HDR;
|
category = CATEGORY_RC_HDR;
|
||||||
oem_debug_print("============= resource counter:%d =============\n",
|
oem_debug_print("============= resource counter:%d =============\n",
|
||||||
oem_tool.rc_cnt);
|
oem_tool.rc_cnt);
|
||||||
|
// 一个 iot_board_info_v1_t 结构体即可包含所有的硬件配置
|
||||||
void *temp = malloc(sizeof(iot_board_info_v1_t));
|
void *temp = malloc(sizeof(iot_board_info_v1_t));
|
||||||
if (temp == NULL) {
|
if (temp == NULL) {
|
||||||
die("not enough memory");
|
die("not enough memory");
|
||||||
@@ -620,12 +630,15 @@ uint8_t get_category_info(char *buf)
|
|||||||
return category;
|
return category;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 把配置写入 iot_board_info_v1_t 结构体中
|
||||||
|
// category 类型, number 外设或内设的编号, core 使用的核心, purpose 用途
|
||||||
uint8_t set_peripheral_allot(uint8_t category, uint8_t number,
|
uint8_t set_peripheral_allot(uint8_t category, uint8_t number,
|
||||||
uint8_t core, uint8_t purpose)
|
uint8_t core, uint8_t purpose)
|
||||||
{
|
{
|
||||||
switch (category) {
|
switch (category) {
|
||||||
case CATEGORY_GPIO:
|
case CATEGORY_GPIO:
|
||||||
for (uint8_t i = 0; i < IOT_PIN_MAX_NUM_V1; i++) {
|
for (uint8_t i = 0; i < IOT_PIN_MAX_NUM_V1; i++) {
|
||||||
|
// 如果找到已配置的编号相同的gpio或者找到一个未配置的gpio,返回其在数组中的index
|
||||||
if (oem_tool.rc.rc_ptr->pin[i].gpio == number ||
|
if (oem_tool.rc.rc_ptr->pin[i].gpio == number ||
|
||||||
oem_tool.rc.rc_ptr->pin[i].gpio == 0xff) {
|
oem_tool.rc.rc_ptr->pin[i].gpio == 0xff) {
|
||||||
oem_tool.rc.pin_idx = i;
|
oem_tool.rc.pin_idx = i;
|
||||||
@@ -637,6 +650,7 @@ uint8_t set_peripheral_allot(uint8_t category, uint8_t number,
|
|||||||
}
|
}
|
||||||
oem_debug_print("pin array current index:%d\n", oem_tool.rc.pin_idx);
|
oem_debug_print("pin array current index:%d\n", oem_tool.rc.pin_idx);
|
||||||
/* gpio index maybe greater than IOT_PIN_MAX_NUM_V1 */
|
/* gpio index maybe greater than IOT_PIN_MAX_NUM_V1 */
|
||||||
|
// 配置这个gpio
|
||||||
oem_tool.rc.rc_ptr->pin[oem_tool.rc.pin_idx].gpio = number;
|
oem_tool.rc.rc_ptr->pin[oem_tool.rc.pin_idx].gpio = number;
|
||||||
oem_tool.rc.rc_ptr->pin[oem_tool.rc.pin_idx].core = core;
|
oem_tool.rc.rc_ptr->pin[oem_tool.rc.pin_idx].core = core;
|
||||||
oem_tool.rc.rc_ptr->pin[oem_tool.rc.pin_idx].purpose = purpose;
|
oem_tool.rc.rc_ptr->pin[oem_tool.rc.pin_idx].purpose = purpose;
|
||||||
@@ -699,6 +713,7 @@ uint8_t set_peripheral_allot(uint8_t category, uint8_t number,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 如果外设或内设编号number大于范围 则退出程序
|
||||||
void rc_quantity_boundary_check(uint8_t category, uint8_t number)
|
void rc_quantity_boundary_check(uint8_t category, uint8_t number)
|
||||||
{
|
{
|
||||||
uint8_t out_of_bounds = 0;
|
uint8_t out_of_bounds = 0;
|
||||||
@@ -757,11 +772,14 @@ void rc_quantity_boundary_check(uint8_t category, uint8_t number)
|
|||||||
g_category_string[category], number, out_of_bounds);
|
g_category_string[category], number, out_of_bounds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 设置gpio的参数到 iot_board_info_v1_t 结构体中,str是从配置文件中读取的关键字
|
||||||
|
// 通过这个函数设置的gpio,func都是0
|
||||||
uint8_t set_gpio_matrix_signal(uint8_t category, uint8_t number,
|
uint8_t set_gpio_matrix_signal(uint8_t category, uint8_t number,
|
||||||
char *str, uint8_t gpio, uint8_t core)
|
char *str, uint8_t gpio, uint8_t core)
|
||||||
{
|
{
|
||||||
uint8_t sig_type = SIGNAL_MAX;
|
uint8_t sig_type = SIGNAL_MAX;
|
||||||
uint8_t inid = 0xff, outid = 0xff;
|
uint8_t inid = 0xff, outid = 0xff;
|
||||||
|
// func好像没用到 都是返回0
|
||||||
uint8_t func = gpio_func_sel(gpio);
|
uint8_t func = gpio_func_sel(gpio);
|
||||||
|
|
||||||
if (!strcmp(str, "tx")) {
|
if (!strcmp(str, "tx")) {
|
||||||
@@ -856,6 +874,7 @@ uint8_t set_gpio_matrix_signal(uint8_t category, uint8_t number,
|
|||||||
outid = get_matrix_signal_outid(sig_type, number);
|
outid = get_matrix_signal_outid(sig_type, number);
|
||||||
inid = get_matrix_signal_inid(sig_type, number);
|
inid = get_matrix_signal_inid(sig_type, number);
|
||||||
|
|
||||||
|
// 找到gpio在结数组中的index
|
||||||
for (uint8_t i = 0; i < IOT_PIN_MAX_NUM_V1; i++) {
|
for (uint8_t i = 0; i < IOT_PIN_MAX_NUM_V1; i++) {
|
||||||
if (oem_tool.rc.rc_ptr->pin[i].gpio == gpio ||
|
if (oem_tool.rc.rc_ptr->pin[i].gpio == gpio ||
|
||||||
oem_tool.rc.rc_ptr->pin[i].gpio == 0xff) {
|
oem_tool.rc.rc_ptr->pin[i].gpio == 0xff) {
|
||||||
@@ -885,6 +904,9 @@ uint8_t set_gpio_matrix_signal(uint8_t category, uint8_t number,
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 解析细节,差分模式是把之前的拷贝一份再把改动部分覆盖之前的
|
||||||
uint8_t get_detail_info(char *buf, uint8_t category)
|
uint8_t get_detail_info(char *buf, uint8_t category)
|
||||||
{
|
{
|
||||||
char *str_ptr[3] = {0};
|
char *str_ptr[3] = {0};
|
||||||
@@ -899,18 +921,24 @@ uint8_t get_detail_info(char *buf, uint8_t category)
|
|||||||
/* special category */
|
/* special category */
|
||||||
if (category == CATEGORY_GENERAL) {
|
if (category == CATEGORY_GENERAL) {
|
||||||
if (!strcmp(str_ptr[0], "bid")) {
|
if (!strcmp(str_ptr[0], "bid")) {
|
||||||
|
// board_id 可以用于区分模块用途 是sta iic 3ps还是cco
|
||||||
|
// 比subid 更详细 subid用于区分芯片
|
||||||
oemcfg.board_id = atoi(str_ptr[1]);
|
oemcfg.board_id = atoi(str_ptr[1]);
|
||||||
} else if (!strcmp(str_ptr[0], "mid")) {
|
} else if (!strcmp(str_ptr[0], "mid")) {
|
||||||
|
// 0:sta 1:cco 2:iic 3:3ps
|
||||||
oemcfg.base_cfg.module_type = atoi(str_ptr[1]);
|
oemcfg.base_cfg.module_type = atoi(str_ptr[1]);
|
||||||
} else if (!strcmp(str_ptr[0], "vid")) {
|
} else if (!strcmp(str_ptr[0], "vid")) {
|
||||||
/* vid is text data, two characters */
|
/* vid is text data, two characters */
|
||||||
|
// 芯片厂家缩写
|
||||||
oemcfg.misc_cfg.vendor_id = htons(*(uint16_t*)str_ptr[1]);
|
oemcfg.misc_cfg.vendor_id = htons(*(uint16_t*)str_ptr[1]);
|
||||||
} else if (!strcmp(str_ptr[0], "fver")) {
|
} else if (!strcmp(str_ptr[0], "fver")) {
|
||||||
|
// ?
|
||||||
oemcfg.board_cfg_ver = atoi(str_ptr[1]);
|
oemcfg.board_cfg_ver = atoi(str_ptr[1]);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
} else if (category == CATEGORY_RC_HDR) {
|
} else if (category == CATEGORY_RC_HDR) {
|
||||||
if (!strcmp(str_ptr[0], "hw_ver")) {
|
if (!strcmp(str_ptr[0], "hw_ver")) {
|
||||||
|
// 硬件识别码
|
||||||
oem_tool.rc.rc_ptr->hdr.hw_version = oem_atoi(str_ptr[1]);
|
oem_tool.rc.rc_ptr->hdr.hw_version = oem_atoi(str_ptr[1]);
|
||||||
} else if (!strcmp(str_ptr[0], "mode")) {
|
} else if (!strcmp(str_ptr[0], "mode")) {
|
||||||
oem_tool.rc.rc_ptr->hdr.mode = atoi(str_ptr[1]) ? 1 : 0;
|
oem_tool.rc.rc_ptr->hdr.mode = atoi(str_ptr[1]) ? 1 : 0;
|
||||||
@@ -926,6 +954,7 @@ uint8_t get_detail_info(char *buf, uint8_t category)
|
|||||||
if (oem_tool.rc.rc_ptr->hdr.mode) {
|
if (oem_tool.rc.rc_ptr->hdr.mode) {
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
uint8_t len_hdr = sizeof(iot_oem_rc_hdr_v1_t);
|
uint8_t len_hdr = sizeof(iot_oem_rc_hdr_v1_t);
|
||||||
|
// 找到 diff_hw_ver 所在的 iot_board_info_v1_t 结构体
|
||||||
for (i = 0; i < oem_tool.rc_cnt; i++) {
|
for (i = 0; i < oem_tool.rc_cnt; i++) {
|
||||||
if (oem_tool.rc_list[i]->hdr.hw_version == diff_hw_ver) {
|
if (oem_tool.rc_list[i]->hdr.hw_version == diff_hw_ver) {
|
||||||
break;
|
break;
|
||||||
@@ -934,6 +963,7 @@ uint8_t get_detail_info(char *buf, uint8_t category)
|
|||||||
if (i == oem_tool.rc_cnt) {
|
if (i == oem_tool.rc_cnt) {
|
||||||
die("diff hw version not match, line:%d", oem_tool.line_num);
|
die("diff hw version not match, line:%d", oem_tool.line_num);
|
||||||
}
|
}
|
||||||
|
// 把之前的复制一份
|
||||||
memcpy((uint8_t *)oem_tool.rc.rc_ptr + len_hdr,
|
memcpy((uint8_t *)oem_tool.rc.rc_ptr + len_hdr,
|
||||||
(uint8_t *)oem_tool.rc_list[i] + len_hdr,
|
(uint8_t *)oem_tool.rc_list[i] + len_hdr,
|
||||||
sizeof(iot_board_info_v1_t) - len_hdr);
|
sizeof(iot_board_info_v1_t) - len_hdr);
|
||||||
@@ -948,12 +978,14 @@ uint8_t get_detail_info(char *buf, uint8_t category)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (is_peripheral_gpio_map) {
|
if (is_peripheral_gpio_map) {
|
||||||
|
// 通过外设来设置gpio
|
||||||
uint8_t gpio = atoi(str_ptr[1]);
|
uint8_t gpio = atoi(str_ptr[1]);
|
||||||
if (set_gpio_matrix_signal(category, oem_tool.rc.device_last, str_ptr[0],
|
if (set_gpio_matrix_signal(category, oem_tool.rc.device_last, str_ptr[0],
|
||||||
gpio, oem_tool.rc.core_last)) {
|
gpio, oem_tool.rc.core_last)) {
|
||||||
die("signal info error, line:%d", oem_tool.line_num);
|
die("signal info error, line:%d", oem_tool.line_num);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// 配置gpio
|
||||||
uint8_t number = atoi(str_ptr[0]);
|
uint8_t number = atoi(str_ptr[0]);
|
||||||
uint8_t core = atoi(str_ptr[1]);
|
uint8_t core = atoi(str_ptr[1]);
|
||||||
uint8_t purpose = atoi(str_ptr[2]);
|
uint8_t purpose = atoi(str_ptr[2]);
|
||||||
@@ -966,6 +998,7 @@ uint8_t get_detail_info(char *buf, uint8_t category)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uint8_t genereate_diff_content(iot_board_info_v1_t *rc,
|
uint8_t genereate_diff_content(iot_board_info_v1_t *rc,
|
||||||
iot_board_info_v1_t *rc_d)
|
iot_board_info_v1_t *rc_d)
|
||||||
{
|
{
|
||||||
@@ -1306,6 +1339,7 @@ void oem_bin_file_parse_hw_all()
|
|||||||
/* get all resource */
|
/* get all resource */
|
||||||
oem_tool.rc_list[oem_tool.rc_cnt] = &oemcfg.board_cfg_v1;
|
oem_tool.rc_list[oem_tool.rc_cnt] = &oemcfg.board_cfg_v1;
|
||||||
again:
|
again:
|
||||||
|
// 如果存在下一个的话,读取下一个
|
||||||
if (oem_tool.rc_list[oem_tool.rc_cnt]->hdr.have_next) {
|
if (oem_tool.rc_list[oem_tool.rc_cnt]->hdr.have_next) {
|
||||||
printf("find next rc, offset:%d\n", oem_tool.buf.len_total);
|
printf("find next rc, offset:%d\n", oem_tool.buf.len_total);
|
||||||
oem_tool.rc_cnt++;
|
oem_tool.rc_cnt++;
|
||||||
@@ -1314,6 +1348,7 @@ again:
|
|||||||
die("not enough memory");
|
die("not enough memory");
|
||||||
}
|
}
|
||||||
oem_tool.rc_list[oem_tool.rc_cnt] = (iot_board_info_v1_t *)temp;
|
oem_tool.rc_list[oem_tool.rc_cnt] = (iot_board_info_v1_t *)temp;
|
||||||
|
// 读取buf中剩余的空间
|
||||||
hdr_ptr = (iot_oem_rc_hdr_v1_t *)&oem_tool.buf.buf[oem_tool.buf.len_total];
|
hdr_ptr = (iot_oem_rc_hdr_v1_t *)&oem_tool.buf.buf[oem_tool.buf.len_total];
|
||||||
|
|
||||||
if (hdr_ptr->mode == 0) {
|
if (hdr_ptr->mode == 0) {
|
||||||
|
@@ -164,7 +164,7 @@ ram_config_param_t ram_param = {
|
|||||||
.print = 0, /* print bits map */
|
.print = 0, /* print bits map */
|
||||||
.c_type = RAM_CHIP_TYPE, /* chip type */
|
.c_type = RAM_CHIP_TYPE, /* chip type */
|
||||||
.c_subid = 0, /* write efuse subid if not 0 */
|
.c_subid = 0, /* write efuse subid if not 0 */
|
||||||
.reboot = 0, /* not reboot after download finish */
|
.reboot = 1, /* not reboot after download finish */
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct ram_buf
|
typedef struct ram_buf
|
||||||
|
Reference in New Issue
Block a user