This commit is contained in:
huxi
2025-12-03 11:12:34 +08:00
parent c23ae4f24c
commit bc195654bf
8163 changed files with 3799544 additions and 92 deletions
+199
View File
@@ -0,0 +1,199 @@
#ifdef SUPPORT_MS_EXTENSIONS_APP
#pragma bss_seg(".cbuf.data.bss")
#pragma data_seg(".cbuf.data")
#pragma const_seg(".cbuf.text.const")
#pragma code_seg(".cbuf.text")
#endif
#include "lib_include.h"
#include "circular_buf.h"
#if 1
#define CPU_SR_ALLOC()
//#pragma code_seg(".cbuf_code")
u32 cbuf_read(cbuffer_t *cbuffer, void *buf, u32 len)
{
CPU_SR_ALLOC();
u32 r_len = len;
u32 copy_len;
if (!cbuffer) {
return 0;
}
if ((u32)cbuffer->read_ptr >= (u32)cbuffer->end) {
cbuffer->read_ptr = (u8 *)cbuffer->begin;
}
if (cbuffer->data_len < len) {
/* memset(buf, 0, len); */
return 0;
}
copy_len = (u32)cbuffer->end - (u32)cbuffer->read_ptr;
if (copy_len > len) {
copy_len = len;
}
len -= copy_len;
memcpy(buf, cbuffer->read_ptr, copy_len);
//printf_data(cbuffer->read_ptr,copy_len) ;
if (len == 0) {
cbuffer->read_ptr += copy_len;
} else {
memcpy((u8 *)buf + copy_len, cbuffer->begin, len);
//printf_data(cbuffer->begin,len);
cbuffer->read_ptr = cbuffer->begin + len;
}
local_irq_disable();
cbuffer->tmp_len = cbuffer->data_len -= r_len;
cbuffer->tmp_len = cbuffer->data_len;
local_irq_enable();
return r_len;
}
u32 cbuf_is_write_able(cbuffer_t *cbuffer, u32 len)
{
u32 w_len;
if (!cbuffer) {
return 0;
}
w_len = cbuffer->total_len - cbuffer->data_len;
if (w_len < len) {
return 0;
}
return w_len;
}
u32 cbuf_write(cbuffer_t *cbuffer, void *buf, u32 len)
{
CPU_SR_ALLOC();
u32 length;
u32 remain_len;
if (!cbuffer) {
return 0;
}
if ((cbuffer->total_len - cbuffer->data_len) < len) {
len = cbuffer->total_len - cbuffer->data_len ;
if (len == 0) {
return 0;
}
}
length = (u32)cbuffer->end - (u32)cbuffer->write_ptr;
if (length >= len) {
memcpy(cbuffer->write_ptr, buf, len);
cbuffer->write_ptr += len;
} else {
remain_len = len - length;
memcpy(cbuffer->write_ptr, buf, length);
memcpy(cbuffer->begin, ((u8 *)buf) + length, remain_len);
cbuffer->write_ptr = (u8 *)cbuffer->begin + remain_len;
}
local_irq_disable();
cbuffer->data_len += len;
cbuffer->tmp_len = cbuffer->data_len ;
cbuffer->tmp_ptr = cbuffer->write_ptr ;
local_irq_enable();
return len;
}
void cbuf_init(cbuffer_t *cbuffer, void *buf, u32 size)
{
cbuffer->data_len = 0;
cbuffer->tmp_len = 0 ;
cbuffer->begin = buf;
cbuffer->read_ptr = buf;
cbuffer->write_ptr = buf;
cbuffer->tmp_ptr = buf;
cbuffer->end = (u8 *)buf + size;
cbuffer->total_len = size;
}
void cbuf_clear(cbuffer_t *cbuffer)
{
CPU_SR_ALLOC();
local_irq_disable();
cbuffer->read_ptr = cbuffer->begin;
cbuffer->tmp_ptr = cbuffer->write_ptr = cbuffer->begin;
cbuffer->data_len = 0;
cbuffer->tmp_len = 0 ;
local_irq_enable();
}
u32 cbuf_get_data_size(cbuffer_t *cbuffer)
{
//printf(">>cbuf_dat_len:%x\n",cbuffer->data_len);
return cbuffer->data_len;
}
#define CBUF_ENTER_CRITICAL local_irq_disable
#define CBUF_EXIT_CRITICAL local_irq_enable
void cbuf_read_alloc_len_updata(cbuffer_t *cbuffer, u32 len)
{
CBUF_ENTER_CRITICAL();
cbuffer->read_ptr += len;
if ((u32)cbuffer->read_ptr >= (u32)cbuffer->end) {
cbuffer->read_ptr = (u8 *)cbuffer->begin + ((u32)cbuffer->read_ptr - (u32)cbuffer->end);
}
cbuffer->tmp_len = cbuffer->data_len -= len;
CBUF_EXIT_CRITICAL();
}
u32 cbuf_read_alloc_len(cbuffer_t *cbuffer, void *buf, u32 len)
{
u32 r_len = len;
u32 copy_len;
if (!cbuffer) {
return 0;
}
if ((u32)cbuffer->read_ptr >= (u32)cbuffer->end) {
cbuffer->read_ptr = (u8 *)cbuffer->begin;
}
if (cbuffer->data_len < len) {
/* memset(buf, 0, len); */
return 0;
}
copy_len = (u32)cbuffer->end - (u32)cbuffer->read_ptr;
if (copy_len > len) {
copy_len = len;
}
len -= copy_len;
memcpy(buf, cbuffer->read_ptr, copy_len);
//printf_data(cbuffer->read_ptr,copy_len) ;
if (len == 0) {
/* cbuffer->read_ptr += copy_len; */
} else {
memcpy((u8 *)buf + copy_len, cbuffer->begin, len);
//printf_data(cbuffer->begin,len);
/* cbuffer->read_ptr = cbuffer->begin + len; */
}
return r_len;
}
#endif
+606
View File
@@ -0,0 +1,606 @@
#ifdef SUPPORT_MS_EXTENSIONS_APP
#pragma bss_seg(".lbuf.data.bss")
#pragma data_seg(".lbuf.data")
#pragma const_seg(".lbuf.text.const")
#pragma code_seg(".lbuf.text")
#endif
/* ******************************************
*
* |offset| hentry | priv | data|
* | ret |
* | |
* |---------align--------|
*
* *****************************************/
#include "lbuf.h"
#include "common.h"
#define LOG_TAG_CONST LBUF
#define LOG_TAG "[LBUF]"
#define LOG_ERROR_ENABLE
#define LOG_DEBUG_ENABLE
#define LOG_INFO_ENABLE
/* #define LOG_DUMP_ENABLE */
#define LOG_CLI_ENABLE
#include "debug.h"
#ifdef ALIGN
#undef ALIGN
#endif
#define ALIGN(a, b) \
({ \
int m = (u32)(a) & ((b)-1); \
int ret = (u32)(a) + (m?((b)-m):0); \
ret;\
})
//计算数据包的最小长度和hentry管理结构体放一起后要对齐的偏移,lbuf管理结构体的默认对齐是4,但数据包的对齐可以任意指定所以需要进行对齐偏移计算
#define LBUF_OFFSET(head) \
({ \
int m = (sizeof(struct hentry)+head->priv_len) & (head->align-1); \
m?(head->align-m):0;\
})
//根据hentry结构体大小得到hentry结构体地址
#define __get_entry(lbuf) \
(struct hentry *)((u8 *)lbuf - sizeof(struct hentry))
#if LBUF_DEBUG
#define lbuf_entry_check0(head, entry,rets) \
do { \
ASSERT(entry->magic_a == 0x12345678 && entry->magic_b == 0x23456789, \
"%d,%x,%x,%x\n", __LINE__, entry->magic_a, entry->magic_b,rets); \
ASSERT(head->magic_a == 0x87654321 && head->magic_b == 0x98765432, \
"%d,%p,%x,%x,%x,%x\n", __LINE__, head, head->total_size, head->magic_a, head->magic_b,rets); \
} while(0)
#define lbuf_entry_check(head, entry) \
do { \
ASSERT(entry->magic_a == 0x12345678 && entry->magic_b == 0x23456789, \
"%d,%x,%x\n", __LINE__, entry->magic_a, entry->magic_b); \
ASSERT(head->magic_a == 0x87654321 && head->magic_b == 0x98765432, \
"%d,%p,%x,%x,%x\n", __LINE__, head, head->total_size, head->magic_a, head->magic_b); \
} while(0)
#else
#define lbuf_entry_check0(head, entry,rets) do { } while (0)
#define lbuf_entry_check(head, entry) do { } while (0)
#endif
struct hfree {
struct list_head entry;
u32 len;
};
struct hentry {
#if LBUF_DEBUG
int magic_a;
#endif
struct list_head entry;
#ifdef LBUFF_MALLOC_LARGE_MEM
u32 len;
///hentry结构体与lbuf_head结构体的头地址的偏移
u32 offset;
#else
u16 len;
///hentry结构体与lbuf_head结构体的头地址的偏移
u16 offset;
#endif
///需要被读的次数
u8 ref;
///需要映射的通道
u8 channel_map;
#if LBUF_DEBUG
int magic_b;
#endif
int rets;
};
struct lbuff_head *lbuf_init(void *buf, u32 len, int align, int priv_head_len)
{
struct hfree *free;
//首地址4对齐
struct lbuff_head *head = (struct lbuff_head *)ALIGN(buf, 4);
//用户使用的地址按照用户的需求进行对齐
free = (struct hfree *)ALIGN(head + 1, align);
free->len = len - ((u8 *)free - (u8 *)buf);
head->align = align;
head->priv_len = priv_head_len;
head->last_addr = 0;
#if LBUF_DEBUG
head->magic_a = 0x87654321;
head->magic_b = 0x98765432;
#endif
head->total_size = len;
spin_lock_init(&head->lock);
INIT_LIST_HEAD(&head->head);
INIT_LIST_HEAD(&head->free);
list_add_tail(&free->entry, &head->free);
//log_info("0000000000000000lbuf_init: %p,%x\n", head, (u32)head + len);
return head;
}
int lbuf_avaliable(struct lbuff_head *head, int size)
{
struct hfree *p;
int avaliable = 0;
spin_lock(&head->lock);
int offset = LBUF_OFFSET(head);
size = ALIGN(sizeof(struct hentry) + head->priv_len + offset + size, head->align);
list_for_each_entry(p, &head->free, entry) {
avaliable += p->len / size;
}
spin_unlock(&head->lock);
return avaliable;
}
void lbuf_state(struct lbuff_head *head, struct lbuff_state *state)
{
struct hfree *p, *max = NULL;
state->num = 0;
state->fragment = 0;
state->avaliable = 0 ;
spin_lock(&head->lock);
list_for_each_entry(p, &head->free, entry) {
state->fragment ++;
state->avaliable += p->len;
state->num++;
// log_info("lbuf_state: %x, %x\n", p, p->len);
if (!max || max->len < p->len) {
max = p;
}
}
if (!max) {
state->max_continue_len = 0;
} else {
int offset = LBUF_OFFSET(head);
state->max_continue_len = max->len -
sizeof(struct hentry) - head->priv_len - offset;
}
spin_unlock(&head->lock);
}
void lbuf_dump(struct lbuff_head *head)
{
int total_size = 0;
struct hfree *p, *n;
struct hentry *h;
spin_lock(&head->lock);
list_for_each_entry_safe(p, n, &head->free, entry) {
/* log_info("fragment: %x, %x\n", (u32)p, p->len); */
total_size += p->len;
}
list_for_each_entry(h, &head->head, entry) {
/* log_info("alloc: %x, %x, call_from: %x\n", h, h->len, h->rets); */
}
log_info("lbuf_state:%x,%x\n", head->total_size, total_size);
spin_unlock(&head->lock);
}
u32 lbuf_free_space(struct lbuff_head *head)
{
int max_len = 0;
struct hfree *p;
spin_lock(&head->lock);
///找到最大的内存块
list_for_each_entry(p, &head->free, entry) {
if (max_len < p->len) {
max_len = p->len;
}
}
spin_unlock(&head->lock);
int len = sizeof(struct hentry) + LBUF_OFFSET(head) + head->priv_len;
if (max_len >= len) {
max_len -= len;
max_len &= ~(head->align - 1);
return max_len;
}
return 0;
}
void *lbuf_alloc(struct lbuff_head *head, u32 len)
{
int offset;
int max_len = 0;
void *ret = NULL;
struct hfree *p;
struct hfree *new;
struct hfree *free = NULL, *free_0 = NULL;
struct hentry *entry;
u32 rets_addr;
__asm__ volatile("%0 = rets ;" : "=r"(rets_addr));
/* printf("lbuf_alloc:0x%x %d\n", rets_addr, len); */
//计算数据包的最小长度和hentry管理结构体放一起后要对齐的偏移
offset = LBUF_OFFSET(head);
//申请的内存需要对齐的长度
len = ALIGN(sizeof(*entry) + head->priv_len + offset + len, head->align);
spin_lock(&head->lock);
list_for_each_entry(p, &head->free, entry) {
//长度越界检查
if ((u8 *)p <= (u8 *)head || (u8 *)p > (u8 *)head + head->total_size) {
asm("trigger");
log_info("alloc-er1: %x, %x, %x\n", (u32)head->free.next, (u32)p, p->len);
}
//在hfree管理块中寻找一块足够长度的内存块
if (p->len < len) {
continue;
}
//找到了
if (!free || free->len > p->len) {
free = p;
}
//尽量找一块是在上一次内存分割后面的内存块,避免内存碎片
if ((u32)p > head->last_addr && !free_0) {
free_0 = p;
break;
}
}
p = free_0 ? free_0 : free;
if (p) {
head->last_addr = (u32)p;
//剩余的长度可以进行hfree结构体管理的内存分配
if (p->len > len + sizeof(struct hfree)) {
new = (struct hfree *)((u8 *)p + len);
new->len = p->len - len;
//hfree管理的内存进行分割
__list_add(&new->entry, p->entry.prev, p->entry.next);
} else {
len = p->len;
__list_del_entry(&p->entry);
}
//进行hentry结构体管理的内存分配
entry = (struct hentry *)((u8 *)p + offset);
entry->len = len;
entry->offset = (u8 *)entry - (u8 *)head;
entry->channel_map = 0;
entry->ref = 1;
#if LBUF_DEBUG
entry->magic_a = 0x12345678;
entry->magic_b = 0x23456789;
#endif
INIT_LIST_HEAD(&entry->entry);
//返回hentry结构体后面的地址进行存储数据包
ret = entry + 1;
}
spin_unlock(&head->lock);
if (ret == NULL) {
/*log_info("alloc-err: %x\n", len);*/
/*putchar('#');*/
}
return ret;
}
int lbuf_remain_space(struct lbuff_head *head)
{
int max_len = 0;
struct hfree *p;
spin_lock(&head->lock);
list_for_each_entry(p, &head->free, entry) {
max_len += p->len;
}
spin_unlock(&head->lock);
return max_len;
}
void *lbuf_realloc(void *lbuf, int size)
{
int len;
int offset;
int head_len;
struct hentry *new;
struct hentry *entry = __get_entry(lbuf);
struct lbuff_head *head = (struct lbuff_head *)((u8 *)entry - entry->offset);
lbuf_entry_check(head, entry);
// log_info("realloc: %x, %x\n", entry->len, size);
///把size变成align的倍数
size = ALIGN(size, head->align);
ASSERT(size <= entry->len);
///不能大于原来的len
if (size >= entry->len) {
return NULL;
}
offset = LBUF_OFFSET(head);
///计算一个数据包的头结构的偏移长度
head_len = offset + sizeof(*entry) + head->priv_len;
///是否能放下两个最小的数据头
if (entry->len - size < 2 * head_len) {
return lbuf;
}
///是否能够放下hfree结构体
if (entry->len - size < sizeof(struct hfree)) {
return lbuf;
}
len = entry->len;
///实际的长度为数据头长度+分配的长度
entry->len = head_len + size;
new = (struct hentry *)((u8 *)lbuf + head->priv_len + size + offset);
new->channel_map = 0;
new->ref = 1;
new->len = len - entry->len;
new->offset = (u8 *)new - (u8 *)head;
#if LBUF_DEBUG
new->magic_a = 0x12345678;
new->magic_b = 0x23456789;
#endif
//初始化hentry的内核链表结构体
INIT_LIST_HEAD(&new->entry);
///释放new指向的内存空间,即释放重新分配size大小空间后的剩余的空间
lbuf_free(new + 1);
return lbuf;
}
int lbuf_empty(struct lbuff_head *head)
{
if (list_empty(&head->head)) {
return 1;
}
return 0;
}
void lbuf_clear(struct lbuff_head *head)
{
struct hentry *p, *n;
spin_lock(&head->lock);
list_for_each_entry_safe(p, n, &head->head, entry) {
lbuf_free(p + 1);
}
spin_unlock(&head->lock);
}
int lbuf_real_size(void *lbuf)
{
struct hentry *entry = __get_entry(lbuf);
return entry->len;
}
void lbuf_inc_ref(void *lbuf)
{
struct hentry *entry = __get_entry(lbuf);
entry->ref++;
}
void lbuf_push(void *lbuf, u8 channel_map)
{
int i;
//根据hentry结构体大小得到hentry结构体地址
struct hentry *p = __get_entry(lbuf);
//根据offset得到head结构体地址
struct lbuff_head *head = (struct lbuff_head *)((u8 *)p - p->offset);
lbuf_entry_check(head, p);
ASSERT(channel_map != 0);
spin_lock(&head->lock);
///检测需要被读的次数
p->ref = 0;
for (i = 0; i < 8; i++) {
if (channel_map & BIT(i)) {
p->ref++;
}
}
p->channel_map = channel_map;
///检测hentry管理结构体的内存是否被破坏
if (list_empty(&p->entry)) {
lbuf_entry_check(head, p);
ASSERT(((u32)p->entry.next & 0x03) == 0, "%p,%p", head, p->entry.next);
ASSERT(((u32)p->entry.prev & 0x03) == 0, "%p,%p", head, p->entry.prev);
ASSERT(((u32)head->head.prev & 0x03) == 0, "%p,%x,%p", head, head->total_size, head->head.prev);
ASSERT(((u32)head->head.next & 0x03) == 0, "%p,%x,%p", head, head->total_size, head->head.next);
///把hentry链表添加到lbuf_head结构体
list_add_tail(&p->entry, &head->head);
}
lbuf_entry_check(head, p);
spin_unlock(&head->lock);
}
int lbuf_traversal(struct lbuff_head *head)
{
struct hentry *p;
int num = 0;
spin_lock(&head->lock);
list_for_each_entry(p, &head->head, entry) {
num++;
}
spin_unlock(&head->lock);
return num;
}
void *lbuf_pop(struct lbuff_head *head, u8 channel)
{
struct hentry *p;
spin_lock(&head->lock);
//从头进行查找符合通道映射值的hentry内存块
list_for_each_entry(p, &head->head, entry) {
if (p->channel_map & channel) {
//对应的通道映射值置0
p->channel_map &= ~channel;
spin_unlock(&head->lock);
lbuf_entry_check(head, p);
return p + 1;
}
}
spin_unlock(&head->lock);
return NULL;
}
void lbuf_free_check(void *lbuf, u32 rets)
{
struct hentry *entry;
struct lbuff_head *head;
if (lbuf == NULL) {
return;
}
entry = __get_entry(lbuf);
head = (struct lbuff_head *)((u8 *)entry - entry->offset);
lbuf_entry_check0(head, entry, rets);
}
int lbuf_free(void *lbuf)
{
int ret = 0;
int offset;
struct hfree *p;
struct hfree *new;
struct hfree *prev = NULL;
struct hfree *next;
struct hentry *entry;
struct lbuff_head *head;
u32 rets_addr;
__asm__ volatile("%0 = rets ;" : "=r"(rets_addr));
if (lbuf == NULL) {
return 0;
}
///得到hentry
entry = __get_entry(lbuf);
///得到lbuf_head
head = (struct lbuff_head *)((u8 *)entry - entry->offset);
lbuf_entry_check0(head, entry, rets_addr);
offset = LBUF_OFFSET(head);
///得到hfree入口地址并初始化
new = (struct hfree *)((u8 *)entry - offset);
int len = entry->len;
spin_lock(&head->lock);
///异常!该数据包的通道映射还没有被读完,ref--后返回
if (--entry->ref > 0) {
goto _exit;
}
#if LBUF_DEBUG
entry->magic_a = 0x01234567;
#endif
///删除lbuf_head的hentry
__list_del_entry(&entry->entry);
new->len = len;
///hfree轮询
list_for_each_entry(p, &head->free, entry) {
///地址越界检查
if ((u8 *)p <= (u8 *)head || (u8 *)p > (u8 *)head + head->total_size) {
asm("trigger");
log_info("free-err1: %x, %x, %x, %x, %x, %x %x\n", rets_addr, (u32)lbuf, new->len, head, head->free.next, (u32)p, p->len, rets_addr);
goto _exit;
}
if ((p <= new) && ((u8 *)p + p->len > (u8 *)new)) {
asm("trigger");
log_info("free-err: %x, %x, %x, %x %x\n", (u32)lbuf, new->len, (u32)p, p->len, rets_addr);
goto _exit;
}
//按地址高低进行排序,把释放的内存块放入hfree链表
if (p > new) {
__list_add(&new->entry, p->entry.prev, &p->entry);
goto __free;
}
}
///加入hfree链表尾部
list_add_tail(&new->entry, &head->free);
__free:
///得到hfree结构体
prev = list_entry(new->entry.prev, struct hfree, entry);
next = list_entry(new->entry.next, struct hfree, entry);
///两块紧挨的内存块进行合并
if ((u32)prev + prev->len == (u32)new) {
prev->len += new->len;
__list_del_entry(&new->entry);
new = prev;
}
if ((u32)new + new->len == (u32)next) {
new->len += next->len;
__list_del_entry(&next->entry);
}
ret = 1;
_exit:
spin_unlock(&head->lock);
return ret;
}
+165
View File
@@ -0,0 +1,165 @@
#ifdef SUPPORT_MS_EXTENSIONS_APP
#pragma bss_seg(".msg.data.bss")
#pragma data_seg(".msg.data")
#pragma const_seg(".msg.text.const")
#pragma code_seg(".msg.text")
#endif
#include "msg.h"
#include "circular_buf.h"
#include "common.h"
#include "printf.h"
#include "os/os_cpu.h"
#include "wdt.h"
static cbuffer_t msg_cbuf;
static u32 msg_pool[MAX_POOL];
void sys_nop_delay(void)
{
//__builtin_pi32v2_nop();
__asm__ volatile("nop");
}
int task_get_msg(u16 timeout, int len, int *msg)
{
int msg_value = 0;
u8 param_len = 0;
int i = 0;
int param;
u32 event, event_to_msg;
//debug
for (i = 0; i < len; i++) {
msg[i] = 0xffff;
}
//get_msg
wdt_clear();
CPU_SR_ALLOC();
OS_ENTER_CRITICAL();
#if USE_EVENT_EN
event = get_event();
if (event != NO_EVENT) {
clear_one_event(event);
event_to_msg = evnet2msg[event];
msg[0] = event_to_msg;
//printf("event_mag %d\n ", event_to_msg);
OS_EXIT_CRITICAL();
return MSG_NO_ERROR;
}
#endif
if (2 != cbuf_read(&msg_cbuf, (void *)&msg_value, 2)) {
/* memset(msg, NO_MSG, len); */
OS_EXIT_CRITICAL();
/*get no msg,cpu enter idle*/
sys_nop_delay();
return MSG_NO_ERROR;
}
//msg[0] = msg_value;
//param_len = msg_value >> 12;
param_len = msg_value;
for (i = 0 ; i < param_len; i++) {
cbuf_read(&msg_cbuf, (void *)&param, 4);
if (i < len) {
msg[i] = param;
}
}
if (i >= len) {
puts("msg_buf_not_enc\n");
OS_EXIT_CRITICAL();
return MSG_BUF_NOT_ENOUGH;
}
OS_EXIT_CRITICAL();
return MSG_NO_ERROR;
}
#if USB_HID_MODULE_CONTROL
extern void rcsp_hid_loop_resume(void);
#else
extern void stack_run_loop_resume();
#endif
int task_post_msg_base(const char *name, int argc, int cmd, int *argv)
{
u16 msg_value = 0x0fff;
int i = 0;
int param_len = 0;
int param = 0;
if (0xff == cmd) {
printf("cmd == 0xff\n");
#if USB_HID_MODULE_CONTROL
rcsp_hid_loop_resume();
#else
stack_run_loop_resume();
#endif
return MSG_NO_ERROR;
}
CPU_SR_ALLOC();
OS_ENTER_CRITICAL();
//va_list argptr;
//va_start(argptr, argc);
/* printf("msg:cnt:%x\n", argc); */
for (i = 0; i < argc + 1; ++i) {
if (i == 0) {
param_len = argc;
msg_value = param_len & 0xffff;
/* printf("msg[0]:%x\n",msg_value); */
if (cbuf_write(&msg_cbuf, (void *)&msg_value, 2) != 2) {
ASSERT(0, "stack message full! %d\n", __LINE__);
}
} else {
//param = va_arg(argptr, int);
if (i == 1) {
param = cmd;
} else {
param = argv[i - 2];
}
/* printf("msg[%d]:%x\n", i, param); */
if (cbuf_write(&msg_cbuf, (void *)&param, 4) != 4) {
ASSERT(0, "stack message full! %d\n", __LINE__);
}
}
}
//va_end(argptr);
OS_EXIT_CRITICAL();
#if USB_HID_MODULE_CONTROL
rcsp_hid_loop_resume();
#else
stack_run_loop_resume();
#endif
return MSG_NO_ERROR;
}
int task_post_msg(char *name, int argc, ...)
{
int argv[8];
va_list argptr;
ASSERT(argc <= 8);
va_start(argptr, argc);
u8 i;
for (i = 0; i < argc; i++) {
argv[i] = va_arg(argptr, int);
}
va_end(argptr);
//puts("msg_push:\n");
//put_buf((u8 *)argv,argc*4);
return task_post_msg_base(name, argc, argv[0], &argv[1]);
}
void task_clear_all_message(void)
{
cbuf_clear(&msg_cbuf);
}
void task_message_init(void)
{
cbuf_init(&msg_cbuf, msg_pool, sizeof(msg_pool));
cbuf_clear(&msg_cbuf);
}
@@ -0,0 +1,475 @@
#ifdef SUPPORT_MS_EXTENSIONS_APP
#pragma bss_seg(".sys_timer.data.bss")
#pragma data_seg(".sys_timer.data")
#pragma const_seg(".sys_timer.text.const")
#pragma code_seg(".sys_timer.text")
#endif
#include "sys_timer.h"
#include "timer.h"
#include "jiffies.h"
#include "spinlock.h"
//#include "cpu.h"
#define TIMER_US_ENABLE 0
void (*sys_timer_delay_handler)();
struct list_head timer_head;
struct list_head timer_us_head;
/* volatile unsigned long jiffies; */
volatile unsigned long jiffies_us;
void *get_sys_timer_head()
{
return &timer_head;
}
u32 get_jiffies(u8 mode, u32 timer_ms)
{
if (mode == 1) {
jiffies += timer_ms / 10;
}
return jiffies;
}
bool __timer_find(struct sys_timer *timer)
{
struct sys_timer *p;
list_for_each_entry(p, &timer_head, entry) {
if (p == timer) {
return TRUE;
}
}
return FALSE;
}
#if TIMER_US_ENABLE
bool __timer_us_find(struct sys_timer *timer)
{
struct sys_timer *p;
list_for_each_entry(p, &timer_us_head, entry) {
if (p == timer) {
return TRUE;
}
}
return FALSE;
}
#endif
void __timer_insert(struct sys_timer *timer)
{
struct sys_timer *p;
list_for_each_entry(p, &timer_head, entry) {
if (p == timer) {
list_del(&p->entry);
break;
}
}
list_for_each_entry(p, &timer_head, entry) {
if (p->jiffies > timer->jiffies) {
__list_add(&timer->entry, p->entry.prev, &p->entry);
return;
}
}
list_add_tail((struct list_head *)&timer->entry, (struct list_head *)&timer_head);
}
#if TIMER_US_ENABLE
void __timer_us_insert(struct sys_timer *timer)
{
struct sys_timer *p;
list_for_each_entry(p, &timer_us_head, entry) {
if (p == timer) {
list_del(&p->entry);
break;
}
}
list_for_each_entry(p, &timer_us_head, entry) {
if (p->jiffies > timer->jiffies) {
__list_add(&timer->entry, p->entry.prev, &p->entry);
return;
}
}
list_add_tail((struct list_head *)&timer->entry, (struct list_head *)&timer_us_head);
}
#endif
#if TIMER_US_ENABLE
void sys_timer_us_register(struct sys_timer *timer, u32 us_sec,
void (*fun)(struct sys_timer *timer), u8 delay_do)
{
local_irq_disable();
timer->loop = 0;
timer->delay_do = delay_do;
timer->fun = fun;
timer->jiffies = jiffies_us + msecs_to_jiffies_10(us_sec);
//printf("timer->jiffies=%d,%d\n", jiffies_us, timer->jiffies);
__timer_us_insert(timer);
local_irq_enable();
}
#endif
void sys_hi_timer_schedule()
{
struct sys_timer *p, *n;
local_irq_disable();
/* jiffies++; */
list_for_each_entry_safe(p, n, &timer_head, entry) {
if (time_before(jiffies, p->jiffies)) {
break;
}
//putchar('s');
if (sys_timer_delay_handler) {
sys_timer_delay_handler();
}
}
local_irq_enable();
}
#if TIMER_US_ENABLE
static void sys_timer_us_schedule()
{
struct sys_timer *p, *n;
u8 do_fun_flag = 0;
local_irq_disable();
jiffies_us++;
list_for_each_entry_safe(p, n, &timer_us_head, entry) {
if (time_before(jiffies_us, p->jiffies)) {
break;
}
if (sys_timer_delay_handler) {
sys_timer_delay_handler();
}
}
local_irq_enable();
}
void loop_timer_us_schedule()
{
struct sys_timer *p, *n;
u8 do_fun_flag = 0;
local_irq_disable();
list_for_each_entry_safe(p, n, &timer_us_head, entry) {
if (time_before(jiffies_us, p->jiffies)) {
break;
}
sys_timer_us_remove(p);
do_fun_flag = 0xaa;
break;
}
local_irq_enable();
if (do_fun_flag == 0xaa) {
ASSERT(p->fun != NULL);
p->fun(p);
}
}
#endif
static DEFINE_SPINLOCK(lock);
#if (defined(CONFIG_CPU_BD47) || defined(CONFIG_CPU_BR29)) && defined(BLE_APP_LOW_RAM_USED) // bd47 内存紧缺
#define TIMER_POOL_NUM_CONFIG 5
#else
#define TIMER_POOL_NUM_CONFIG 10
#endif
static struct sys_timer timer_pool[TIMER_POOL_NUM_CONFIG] = {0};
static u16 global_id = 0;
static struct sys_timer *__sys_timer_get(void *priv, void (*func)(void *priv),
u32 msec, int timeout)
{
struct sys_timer *t = NULL;
spin_lock(&lock);
int i;
for (i = 0; i < ARRAY_SIZE(timer_pool); i++) {
if (timer_pool[i].used == 0) {
timer_pool[i].used = 1;
t = &timer_pool[i];
spin_unlock(&lock);
goto __next;
}
}
spin_unlock(&lock);
if (i == ARRAY_SIZE(timer_pool)) {
/* puts("<<<tiemr pool full>>>\n"); */
}
__next:
t->priv = priv;
t->func = func;
t->msec = msec;
t->del = 0;
//t->posting = 0;
t->timeout = timeout;
t->jiffies = jiffies + msecs_to_jiffies(msec);
t->id = ++global_id;
if (t->id == 0) {
t->id = (u16)func;
}
return t;
}
static int __timer_put(struct sys_timer *timer)
{
if (timer >= timer_pool && timer < timer_pool + ARRAY_SIZE(timer_pool)) {
timer->used = 0;
return 1;
}
return 0;
}
static void __id_check(struct sys_timer *t, struct list_head *head)
{
struct sys_timer *p;
__again:
list_for_each_entry(p, head, entry) {
if (t->id == p->id) {
t->id++;
goto __again;
}
}
}
static u16 __sys_timer_add(void *priv, void (*func)(void *priv), u32 msec, int timeout)
{
struct sys_timer *t;
t = __sys_timer_get(priv, func, msec, timeout);
if (!t) {
return 0;
}
spin_lock(&lock);
__id_check(t, &timer_head);
struct sys_timer *p;
list_for_each_entry(p, &timer_head, entry) {
//printf("p->jiffies:%x t->jiffies:%x\n",p-jiffies,t->jiffies);
if (p->jiffies > t->jiffies) {
__list_add(&t->entry, p->entry.prev, &p->entry);
goto _LOOP_RET;
}
}
list_add_tail(&t->entry, &timer_head);
_LOOP_RET:
spin_unlock(&lock);
/* if(func == lmp_connection_timeout){ */
/* mpu_set(0, (u32)t + sizeof(struct list_head), (u32)t + sizeof(struct list_head) + 4 - 1, 0, "Cxr"); */
/* } */
//log_debug("add id : %d", t->id);
//os_sem_post(&sys_timer_sem);
return t->id;
}
static void __timer_del(struct sys_timer *timer)
{
spin_lock(&lock);
__list_del_entry(&timer->entry);
int ret = __timer_put(timer);
spin_unlock(&lock);
/* if (!ret) {
free(timer);
} */
}
static void __sys_timer_del(struct list_head *head, u16 id)
{
const char *task;
struct sys_timer *p;
spin_lock(&lock);
list_for_each_entry(p, head, entry) {
if (p->id == id) {
__list_del_entry(&p->entry);
__timer_put(p);
//p->del = 1;
break;
}
}
spin_unlock(&lock);
}
u16 sys_timer_add(void *priv, void (*func)(void *priv), u32 msec)
{
int rets;
__asm__ volatile("%0 = rets" :"=r"(rets));
/* printf("add rts : 0x%x / %d", rets, msec); */
return __sys_timer_add(priv, func, msec, 0);
}
u16 sys_timeout_add(void *priv, void (*func)(void *priv), u32 msec)
{
int rets;
__asm__ volatile("%0 = rets" :"=r"(rets));
/* printf("add ot rts : 0x%x / %d", rets, msec); */
return __sys_timer_add(priv, func, msec, 1);
}
void sys_timer_del(u16 t)
{
__sys_timer_del(&timer_head, t);
}
void sys_timeout_del(u16 t)
{
__sys_timer_del(&timer_head, t);
}
int sys_timer_modify(u16 id, u32 msec)
{
struct sys_timer *p;
spin_lock(&lock);
list_for_each_entry(p, &timer_head, entry) {
if (p->id == id) {
p->msec = msec;
p->jiffies = jiffies + msecs_to_jiffies(msec);
break;
}
}
spin_unlock(&lock);
//os_sem_post(&sys_timer_sem);
return 0;
}
void sys_timer_set_user_data(u16 id, void *priv)
{
struct sys_timer *p;
spin_lock(&lock);
list_for_each_entry(p, &timer_head, entry) {
if (p->id == id) {
p->priv = priv;
}
}
spin_unlock(&lock);
}
sys_timer sys_timer_register(u32 msec, void (*callback)(void *))
{
return sys_timeout_add(NULL, callback, msec);
}
void sys_timer_change_period(sys_timer timer, u32 msec)
{
sys_timer_modify(timer, msec);
}
void sys_timer_set_context(sys_timer timer, void *context)
{
sys_timer_set_user_data(timer, context);
}
sys_timer sys_timer_register_periodic(u32 msec, void (*callback)(void *))
{
return sys_timer_add(NULL, callback, msec);
}
void sys_timer_re_run(u16 id)
{
struct sys_timer *p;
spin_lock(&lock);
list_for_each_entry(p, &timer_head, entry) {
if (p->id == id) {
p->jiffies = jiffies + msecs_to_jiffies(p->msec);
break;
}
}
spin_unlock(&lock);
//os_sem_post(&sys_timer_sem);
}
void sys_timer_reset(sys_timer timer)
{
sys_timer_re_run(timer);
}
void sys_timer_remove(sys_timer timer)
{
sys_timeout_del(timer);
}
void sys_timer_schedule()
{
struct sys_timer *p, *n;
u8 do_fun_flag = 0;
#if TIMER_US_ENABLE
loop_timer_us_schedule();
#endif
/* jiffies++; */
spin_lock(&lock);
list_for_each_entry_safe(p, n, &timer_head, entry) {
if (time_after(jiffies, p->jiffies)) {
spin_unlock(&lock);
if (p->func) {
p->func(p->priv);
}
spin_lock(&lock);
if (p->timeout) {
spin_unlock(&lock);
__timer_del(p);
spin_lock(&lock);
} else {
p->jiffies = jiffies + msecs_to_jiffies(p->msec);
}
}
}
spin_unlock(&lock);
}
void sys_timer_init()
{
INIT_LIST_HEAD(&timer_head);
#if TIMER_US_ENABLE
INIT_LIST_HEAD(&timer_us_head);
#endif
sys_tmr_init(sys_timer_schedule);
}
@@ -0,0 +1,58 @@
#ifdef SUPPORT_MS_EXTENSIONS_APP
#pragma bss_seg(".version.data.bss")
#pragma data_seg(".version.data")
#pragma const_seg(".version.text.const")
#pragma code_seg(".version.text")
#endif
#include "lib_include.h"
__attribute__((section(".version_tag1"), used))
#if defined(EDR_UPDATA_SUPPORT_CONNECT)
static const char version_type_tag[] = "edr_ota2";
#elif defined(BLE_UPDATA_SUPPORT_CONNECT)
static const char version_type_tag[] = "ble_ota";
#elif (1 == USB_HOST_MODULE_CONTROL)
//二级loader修改
#if defined(CONFIG_CPU_BR25) || defined(CONFIG_CPU_BR27)
static const char version_type_tag[] = "usb_update2/usb_sec_ota";
#else
static const char version_type_tag[] = "usb_update2";
#endif
#elif (1 == SD_MODULE_CONTROL)
//二级loader修改
#if defined(CONFIG_CPU_BR25) || defined(CONFIG_CPU_BR27)
static const char version_type_tag[] = "sd_update2/sd_sec_ota";
#else
static const char version_type_tag[] = "sd_update2";
#endif
#elif (1 == BLE_GATT_UPDATA_MODULE_CONTROL)
static const char version_type_tag[] = "ble_app_ota";
#elif (1 == SPP_UPDATA_MODULE_CONTROL)
static const char version_type_tag[] = "spp_app_ota";
#elif (1 == UART_UPDATA_MODULE_CONTROL)
static const char version_type_tag[] = "uart_update";
#elif (1 == UART_UPDATA_USER_MODULE_CONTROL)
static const char version_type_tag[] = "user_uart_update";
#elif defined(EX_FLASH_UPDATE_SUPPORT_EN)
static const char version_type_tag[] = "nor_ota";
#elif (1 == USER_LC_FLASH_UPDATA_MODULE_CONTROL)
static const char version_type_tag[] = "lcflash_ota";
#elif (1 == USB_HID_MODULE_CONTROL)
static const char version_type_tag[] = "usb_hid_ota";
#elif (1 == DEV_NORFLASH_UPDATA_MODULE_CONTROL)
static const char version_type_tag[] = "dev_nor_ota";
#elif (1 == NET_UPDATA_MODULE_CONTROL)
static const char version_type_tag[] = "net_ota";
#elif (1 == USB_HID_MODULE_CONTROL)
static const char version_type_tag[] = "usb_hid_ota";
#endif
__attribute__((section(".version_tag2"), used))
static const char version_date_tag[] = __DATE__;
__attribute__((section(".version_tag3"), used))
static const char version_time_tag[] = __TIME__;
@@ -0,0 +1,148 @@
#ifdef SUPPORT_MS_EXTENSIONS_APP
#pragma bss_seg(".lib_btctrler_config.data.bss")
#pragma data_seg(".lib_btctrler_config.data")
#pragma const_seg(".lib_btctrler_config.text.const")
#pragma code_seg(".lib_btctrler_config.text")
#endif
//#include "system/includes.h"
#include "btcontroller_config.h"
#include "btstack/bt_profile_config.h"
#include "printf.h"
const int config_stack_modules = BT_BTSTACK_LE;
#ifdef EDR_UPDATA_SUPPORT_CONNECT
const int config_btctler_modules = BT_MODULE_CLASSIC;
#elif defined (BLE_UPDATA_SUPPORT_CONNECT) || defined (BLE_GATT_UPDATA_MODULE_CONTROL)
const int config_btctler_modules = BT_MODULE_LE;
#else
const int config_btctler_modules = 0;
#endif
const int config_rf_slot_unit = 625;
const int config_btctler_le_tws = 0;
const int CONFIG_BTCTLER_TWS_ENABLE = 0;
const int config_btctler_mode = BT_NORMAL;
const int config_btctler_hci_standard = 0;
const int CONFIG_BLE_SYNC_WORD_BIT = 30;
const int clock_tree_auto_disable_all_pll = 0;
#ifdef BLE_UPDATA_SUPPORT_CONNECT
const int config_btctler_single_carrier_en = 1;
#else
const int config_btctler_single_carrier_en = 0;
#endif
const u8 ble_debug_enable = 0x00;
const u8 rx_fre_offset_adjust_enable = 1;
const int CONFIG_PAGE_POWER = 4;
const int CONFIG_PAGE_SCAN_POWER = 7;
const int CONFIG_INQUIRY_POWER = 7;
const int CONFIG_INQUIRY_SCAN_POWER = 7;
const int CONFIG_TEST_DUT_CODE = 0;
const int CONFIG_TEST_FCC_CODE = 0;
const int CONFIG_TEST_DUT_ONLY_BOX_CODE = 0;
#if defined (BLE_GATT_UPDATA_MODULE_CONTROL)
const uint64_t config_btctler_le_features = LE_2M_PHY | LE_DATA_PACKET_LENGTH_EXTENSION;//(LE_ENCRYPTION);
#else
const uint64_t config_btctler_le_features = LE_DATA_PACKET_LENGTH_EXTENSION;
#endif
const int config_btctler_le_roles = (LE_ADV | LE_SLAVE);
//固定使用正常发射功率的等级:0-使用不同模式的各自等级;1~10-固定发射功率等级
const int config_force_bt_pwr_tab_using_normal_level = 0;
const int config_btctler_eir_version_info_len = 21;
const int CONFIG_WIFI_DETECT_ENABLE = 0;
const int config_btctler_le_afh_en = 0;
const int config_btctler_le_rx_nums = 8;
const int config_btctler_le_acl_packet_length = 251;
const int config_btctler_le_acl_total_nums = 3;
const int config_btctler_le_hw_nums = 1;
const int config_update_mode = 0xff;
//BT
const int IRQ_BT_TIMEBASE_IP = 6;
const int IRQ_BLE_EVENT_IP = 5;
const int IRQ_BLE_RX_IP = 5;
const int IRQ_BREDR_IP = 4;
const int IRQ_BT_RXMCH_IP = 4;
const int config_rf_oob = 0;
#if defined (BLE_GATT_UPDATA_MODULE_CONTROL) || defined (BLE_UPDATA_SUPPORT_CONNECT)
#if defined(CONFIG_CPU_BD47) || defined(CONFIG_CPU_BR29)
#if defined(BLE_APP_LOW_RAM_USED) // bd47内存紧缺
static u8 app_le_pool[800] __attribute__((aligned(4)));
#else
static u8 app_le_pool[1300] __attribute__((aligned(4)));
#endif
#else
static u8 app_le_pool[1820] __attribute__((aligned(4)));
#endif
extern u16 get_le_pool_len(void);
u8 *get_le_pool_addr(void)
{
u16 len = 0;
len = get_le_pool_len();
printf("le pool len %d\n", len);
if (len > sizeof(app_le_pool)) {
ASSERT(0, "le_pool is small\n");
}
return &app_le_pool;
}
#endif
const u32 __VERSION_BEGIN = 0;
const char log_tag_const_v_Analog = 0;
const char log_tag_const_i_Analog = 0;
const char log_tag_const_w_Analog = 0;
const char log_tag_const_d_Analog = 0;
const char log_tag_const_e_Analog = 0;
const char log_tag_const_v_LL_ISO = 0;
const char log_tag_const_i_LL_ISO = 0;
const char log_tag_const_d_LL_ISO = 0;
const char log_tag_const_w_LL_ISO = 0;
const char log_tag_const_e_LL_ISO = 0;
const char log_tag_const_i_LL_EXT_ADV = 0;
const char log_tag_const_e_LL_EXT_ADV = 0;
const char log_tag_const_d_LL_EXT_ADV = 0;
const char log_tag_const_i_LL_PADV = 0;
const char log_tag_const_i_AES = 0;
const int config_btctler_dual_a2dp = 0;
const int CONFIG_LMP_NAME_REQ_ENABLE = 0;
const int CONFIG_BREDR_INQUIRY = 0;
const int config_bredr_afh_user = 0;
const int CONFIG_LMP_MASTER_ESCO_ENABLE = 0;
const int config_bt_security_vulnerability = 0;
const int CONFIG_BTCTLER_FAST_CONNECT_ENABLE = 0;
const int config_btctler_bredr_master = 0;
const int CONFIG_A2DP_MAX_BUF_SIZE = 0;
const u32 config_vendor_le_bb = 0;
// Master multi-link
const int config_btctler_le_master_multilink = 0;
const int ble_disable_wait_enable = 1;
const int config_btctler_le_slave_conn_update_winden = 2500;//range:100 to 2500
const int config_le_sm_support_enable = 1; //是否支持加密配对
const int config_btctler_le_iso_tx = 1024;
const int config_btctler_le_iso_rx = 0;
const int config_bb_optimized_ctrl = 0;
+239
View File
@@ -0,0 +1,239 @@
#ifdef SUPPORT_MS_EXTENSIONS_APP
#pragma bss_seg(".loader_main.data.bss")
#pragma data_seg(".loader_main.data")
#pragma const_seg(".loader_main.text.const")
#pragma code_seg(".loader_main.text")
#endif
#include "common.h"
#include "clock.h"
#include "irq.h"
#include "wdt.h"
#include "uart.h"
#include "printf.h"
#include "dec.h"
#include "jlfs.h"
#include "delay.h"
#include "upgrade.h"
#include "sys_timer.h"
#include "exception.h"
#include "update_main.h"
#include "norflash.h"
#include "mask_api.h"
#if (UPDIFF_FLASH_UPDATE_SUPPORT_EN||COMBAK_FLASH_UPDATE_SUPPORT_EN) && \
(defined(CONFIG_CPU_BR52))
#include "charge_hw.h"
#endif
#define LOG_TAG_CONST LOADER_MAIN
#define LOG_TAG "[LOADER_MAIN]"
#define LOG_ERROR_ENABLE
#define LOG_DEBUG_ENABLE
#define LOG_INFO_ENABLE
/* #define LOG_DUMP_ENABLE */
#define LOG_CLI_ENABLE
#include "debug.h"
/* #define IO_N 3 */
/* void test_io(int x) */
/* { */
/* JL_PORTB->DIR &= ~BIT(IO_N); */
/* #<{(| mdelay(20); |)}># */
/* for (int i = 0; i < x; i++) */
/* { */
/* JL_PORTB->OUT ^= BIT(IO_N); */
/* } */
/* JL_PORTB->OUT |= BIT(IO_N); */
/* } */
#include "power/p33.h"
#include "gpio.h"
extern u32 get_power_pin_multi(u32 *gpio, u8 *level, u32 cnt);
#define PP_N 3//最多记录power_pin脚数
typedef struct {
u32 gpio[PP_N];
u8 level[PP_N];
} PowerPin;
static PowerPin pp_handle = {0};
//================================================//
// 不可屏蔽中断使能配置(UNMASK_IRQ) //
// Only For AC701N //
//================================================//
const int CONFIG_CPU_UNMASK_IRQ_ENABLE = 0;
struct flash_platform_data inside_flash_pdata;
void soft_irq_handler(void)
{
printf("%s\n", __func__);
}
u32 stack_magic[4] sec(.stack_magic);
u32 stack_magic0[4] sec(.stack_magic0);
extern void flash_fs_v2_update_init(void);
extern void p33_pinr_tmr_restart(void);
extern u8 p33_get_reset_pin(void);
void exception_analyze(unsigned int *sp);
void exception_irq_handler(void);
void port_init();
int norflash_dev_open(struct dev_node *node, struct device **device, void *arg);
int norflash_no_sr_mode_write_protect(u8 sr_mode, u8 wr_en_mode, u32 sr1, u32 sr2);
__attribute__((weak))
void save_sfr_before_soft_reset(void)
{
}
int main(void)
{
u8 val[16];
u8 pll_scr = 0;
save_sfr_before_soft_reset();
#if defined(CONFIG_CPU_BD49) || defined(CONFIG_CPU_BD47) || defined(CONFIG_CPU_BD45) || defined(CONFIG_CPU_SH58)
mask_api_init(putchar, exception_analyze);
#else
mask_api_init(putchar, NULL);
#endif
#if defined(CONFIG_CPU_WL83)
switch_sysclk(HSB_SEL_PLL_96M);
#else
/* JL_CLOCK->CLK_CON0 |= BIT(8); //OSC24M -> STD24M */
uart_init("PA05", 2000000); //debug串口
/* uart_init("PC05", 2000000); //debug串口 */
#endif
printf("\n >>>[test]:func = %s,line= %d\n", __FUNCTION__, __LINE__);
memset((u8 *)&inside_flash_pdata, 0, sizeof(struct flash_platform_data));
inside_flash_pdata.spi_pdata.width = 2;
inside_flash_pdata.spi_pdata.clk_div = 3;
inside_flash_pdata.read_mode = 0;
#if defined(CONFIG_CPU_BR35)
inside_flash_pdata.spi_pdata.port = !!(JL_SFC_IOMC->IOMC0 & BIT(1));
#endif
inside_flash_pdata.flash_type = DEV_FLASH_INTERNAL_NORFLASH;
void *device;
norflash_dev_open(NULL, (void *)&device, &inside_flash_pdata);
/* norflash_init(&inside_flash_pdata); */
// by xuebo
#if !defined(CONFIG_CPU_WL83)
sys_clk_init(OSC_FREQ, SYS_CLK);
#endif
#if defined(CONFIG_CPU_SH58) && USB_HOST_MODULE_CONTROL
set_sys_clk(96000000); //SH58 U盘升级需要提高系统时钟
#endif
printf(">>>[test]:+++++++++++++\n");
#if (UPDIFF_FLASH_UPDATE_SUPPORT_EN||COMBAK_FLASH_UPDATE_SUPPORT_EN) && \
(defined(CONFIG_CPU_BR52) || defined(CONFIG_CPU_BR56) || defined(CONFIG_CPU_BR50))
asm("btbclr");
q32DSP(0)->PMU_CON1 &= ~BIT(8); //open bpu
SFR(JL_HSBCLK->HSB_SEL, 0, 3, 6);//sys 96MHz
#endif
flash_fs_v2_update_init(); //存在偏移情况,先提前获取。
#ifdef __DEBUG
#if !defined(CONFIG_CPU_WL83)
u8 *ptr = jlfs_get_isd_cfg_ptr();
memset(val, 0, sizeof(val));
dec_isd_cfg_ini("PLL_SRC", val, ptr);
if (strcmp((char *)val, "LRC") == 0) {
pll_scr = 2;
}
u32 ut_buad = 0;
char uttx[8] = {0};
memset(uttx, 0, sizeof(uttx));
dec_isd_cfg_ini("UTTX", uttx, ptr);
dec_isd_cfg_ini("UTBD", &ut_buad, ptr);
uart_init(uttx, ut_buad);
/* reset_source_dump(); */
#endif
#endif
#if (UPDIFF_FLASH_UPDATE_SUPPORT_EN||COMBAK_FLASH_UPDATE_SUPPORT_EN) && \
(defined(CONFIG_CPU_BR52))
loader_charge_init();
#endif
/* uart_init("USBDP", 1000000); //debug串口 */
log_info("\n****************** Hello Ota loader DATE:%s TIME:%s *****************\n\n", __DATE__, __TIME__);
#if defined(CONFIG_CPU_BD49) || defined(CONFIG_CPU_SH58)
power_early_init(NULL);
#endif
//解除写保护
norflash_no_sr_mode_write_protect(0, 0, 0, 0);
//关闭长按复位,打印复位寄存器值方便查看 2023_10_07 by phewlee
p33_get_reset_pin();
reset_pin_close();
p33_get_reset_pin();
extern void lrc_init(void);
lrc_init();
wdt_init(WDT_4s);
/*初始化异常中断*/
request_irq(IRQ_EXCEPTION_IDX, 2, exception_irq_handler, 0);
debug_init();
/* request_irq(IRQ_SOFT0_IDX, 2, soft_irq_handler, 0); */
/* */
/* irq_set_pending(IRQ_SOFT0_IDX); */
/* while(1); */
/*初始化sys_timer*/
sys_timer_init();
//ldoin长按复位功能如果开启,定时出现启动
#if !defined(CONFIG_CPU_BD49) && !defined(CONFIG_CPU_BD47) && !defined(CONFIG_CPU_BD45)
sys_timer_add(NULL, (void *)p33_pinr_tmr_restart, 500);
#endif
//获取POWER_PIN参数, 防止部分触摸ic掉电一半再上电状态异常
#if (0 == UART_UPDATE_ONLY_TEST_MODE && UPDATE_GET_POWER_PIN)
if (get_power_pin_multi(&pp_handle.gpio[0], &pp_handle.level[0], PP_N)) {
for (int i = 0; i < PP_N; i++) {
printf(">>>[test]:gpio[%d] = %d\n", i, pp_handle.gpio[i]);
if (pp_handle.gpio[i] == 0) {
break;
}
gpio_set_direction(pp_handle.gpio[i], 0);
gpio_set_die(pp_handle.gpio[i], 1);
//先输出低是为了释放该io的电容的电,达到快速拉低目的,防止部分触摸ic掉电一半再上电状态异常;
gpio_set_output_value(pp_handle.gpio[i], 0);
udelay(100);
gpio_set_output_value(pp_handle.gpio[i], pp_handle.level[i]);
}
}
#endif
update_main();
while (1) {
putchar('o');
udelay(1000 * 1000);
};
return 0;
}
+261
View File
@@ -0,0 +1,261 @@
#ifdef SUPPORT_MS_EXTENSIONS_APP
#pragma bss_seg(".log_config.data.bss")
#pragma data_seg(".log_config.data")
#pragma const_seg(".log_config.text.const")
#pragma code_seg(".log_config.text")
#endif
#include "typedef.h"
#ifdef __SUPPORT_OUTSIDE_FLASH
const u8 support_operat_outside_flash = 1;
#else
const u8 support_operat_outside_flash = 0;
#endif
#ifdef __FLASH_SUPPORT_CONTINUE_READ_MODE
const u8 flash_support_continue_read_mode = 1;
#else
const u8 flash_support_continue_read_mode = 0;
#endif
#ifdef __FLASH_SUPPORT_4BIT_MODE
const u8 flash_support_4bit_mode = 1;
#else
const u8 flash_support_4bit_mode = 0;
#endif
#ifdef __DEBUG
const char libs_debug AT(.LOG_TAG_CONST) = TRUE; //打印总开关
#else
const char libs_debug AT(.LOG_TAG_CONST) = FALSE; //打印总开关
#endif
#define CONFIG_DEBUG_LIBS(X) (X & libs_debug)
const char log_tag_const_i_FLASH AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_d_FLASH AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_e_FLASH AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_i_DEBUG AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_d_DEBUG AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_e_DEBUG AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
#if defined(CONFIG_CPU_SH58) || (defined(CONFIG_CPU_BR29) && defined(BLE_APP_LOW_RAM_USED))
const char log_tag_const_i_FS_V2_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_d_FS_V2_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_e_FS_V2_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
#else
const char log_tag_const_i_FS_V2_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
const char log_tag_const_d_FS_V2_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
const char log_tag_const_e_FS_V2_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
#endif
const char log_tag_const_i_EFUSE_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
const char log_tag_const_d_EFUSE_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
const char log_tag_const_e_EFUSE_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
#if defined(CONFIG_CPU_SH58)
const char log_tag_const_i_DEV_UP AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_d_DEV_UP AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_e_DEV_UP AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
#else
const char log_tag_const_i_DEV_UP AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
const char log_tag_const_d_DEV_UP AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
const char log_tag_const_e_DEV_UP AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
#endif
const char log_tag_const_i_FS AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_d_FS AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_e_FS AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_i_SFC AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_d_SFC AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_e_SFC AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
#if defined(CONFIG_CPU_SH58)
const char log_tag_const_i_SD AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_d_SD AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_e_SD AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
#else
const char log_tag_const_i_SD AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
const char log_tag_const_d_SD AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
const char log_tag_const_e_SD AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
#endif
const char log_tag_const_i_LOADER AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
const char log_tag_const_d_LOADER AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
const char log_tag_const_e_LOADER AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
const char log_tag_const_i_LOADER_MAIN AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
const char log_tag_const_d_LOADER_MAIN AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
const char log_tag_const_e_LOADER_MAIN AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
const char log_tag_const_i_MAIN AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_d_MAIN AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_e_MAIN AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_i_APP_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_d_APP_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_e_APP_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_i_RCSP AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_d_RCSP AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_e_RCSP AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_i_USER_LC_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
const char log_tag_const_d_USER_LC_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
const char log_tag_const_e_USER_LC_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
const char log_tag_const_i_EX_NOR_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
const char log_tag_const_d_EX_NOR_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
const char log_tag_const_e_EX_NOR_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
const char log_tag_const_i_USB_UP AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_d_USB_UP AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_e_USB_UP AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_i_UT_ANALYZE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
const char log_tag_const_d_UT_ANALYZE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
const char log_tag_const_e_UT_ANALYZE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
const char log_tag_const_i_BT_CFG_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_d_BT_CFG_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_e_BT_CFG_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_i_UT_UPDATE_DRIVER AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
const char log_tag_const_d_UT_UPDATE_DRIVER AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
const char log_tag_const_e_UT_UPDATE_DRIVER AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
const char log_tag_const_i_UT_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
const char log_tag_const_d_UT_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
const char log_tag_const_e_UT_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
const char log_tag_const_i_BT_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
const char log_tag_const_d_BT_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
const char log_tag_const_e_BT_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
const char log_tag_const_i_UPDATE_MAIN AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
const char log_tag_const_d_UPDATE_MAIN AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
const char log_tag_const_e_UPDATE_MAIN AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
const char log_tag_const_i_UPDATE_AREA AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_d_UPDATE_AREA AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_e_UPDATE_AREA AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_i_HCI_LMP AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_d_HCI_LMP AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_e_HCI_LMP AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_i_HCI_STD AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_d_HCI_STD AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_e_HCI_STD AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_i_LMP AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_d_LMP AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_e_LMP AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_i_LBUF AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_d_LBUF AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_e_LBUF AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_i_MISC AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_d_MISC AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_e_MISC AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_i_BDMGR AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_d_BDMGR AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_e_BDMGR AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_i_RF AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_d_RF AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_e_RF AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_i_LE_BB AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_d_LE_BB AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_e_LE_BB AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_i_LE5_BB AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_d_LE5_BB AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_e_LE5_BB AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_i_Thread AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_d_Thread AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_e_Thread AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_i_LL AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_d_LL AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_e_LL AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_i_LL_E AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_d_LL_E AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_e_LL_E AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_i_LL_S AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_d_LL_S AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_e_LL_S AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_i_LL_PHY AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_d_LL_PHY AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_e_LL_PHY AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_i_LL_ADV AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_d_LL_ADV AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_e_LL_ADV AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_i_LL_SCAN AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_d_LL_SCAN AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_e_LL_SCAN AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_i_LL_INIT AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_d_LL_INIT AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_e_LL_INIT AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_i_LL_AFH AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_d_LL_AFH AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_e_LL_AFH AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_i_HCI_LL5 AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_d_HCI_LL5 AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_e_HCI_LL5 AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_i_HCI_LL AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_d_HCI_LL AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_e_HCI_LL AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
const char log_tag_const_i_BLE_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
const char log_tag_const_d_BLE_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
const char log_tag_const_e_BLE_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
const char log_tag_const_i_RESERVED_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
const char log_tag_const_d_RESERVED_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
const char log_tag_const_e_RESERVED_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
const char log_tag_const_i_EX_API_CODE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
const char log_tag_const_d_EX_API_CODE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
const char log_tag_const_e_EX_API_CODE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
const char log_tag_const_i_RESET AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
const char log_tag_const_d_RESET AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
const char log_tag_const_e_RESET AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
const char log_tag_const_i_DECOM AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
const char log_tag_const_d_DECOM AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
const char log_tag_const_e_DECOM AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
const char log_tag_const_i_COMBAK_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
const char log_tag_const_d_COMBAK_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
const char log_tag_const_e_COMBAK_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
const char log_tag_const_i_UPDIFF AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
const char log_tag_const_d_UPDIFF AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
const char log_tag_const_e_UPDIFF AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
const char log_tag_const_i_UPDIFF_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
const char log_tag_const_d_UPDIFF_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
const char log_tag_const_e_UPDIFF_UPDATE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(1);
@@ -0,0 +1,341 @@
#ifdef SUPPORT_MS_EXTENSIONS_APP
#pragma bss_seg(".ex_flash_update.data.bss")
#pragma data_seg(".ex_flash_update.data")
#pragma const_seg(".ex_flash_update.text.const")
#pragma code_seg(".ex_flash_update.text")
#endif
#include "update_main.h"
#include "power/p33.h"
#include "common.h"
#include "norflash.h"
#include "device.h"
#include "jlfs.h"
#include "dec.h"
#include "gpio.h"
/* #include "uart_protocol_analyze.h" */
#define LOG_TAG_CONST EX_NOR_UPDATE
#define LOG_TAG "[EX_NOR_UPDATE]"
#define LOG_ERROR_ENABLE
#define LOG_DEBUG_ENABLE
#define LOG_INFO_ENABLE
/* #define LOG_DUMP_ENABLE */
#define LOG_CLI_ENABLE
#include "debug.h"
//============================================================//
/* APP NorFlash 升级模型(APP_NORFLASH_UPDATA)
________ ________ ________
| | | | | |
| | ufw | | ufw | |
| APP | ---------> | CHIP | --------> |NorFlash|
| | ops | | ops | |
|________| |________| |________|
^ |
|______________________|
ota.bin
*/
//============================================================//
//需要获取信息:
//whick SPI HW
//which CS
//src addr, len
//dest addr, len
typedef struct _ex_flash_update_info {
u32 src_file_addr;
u32 src_file_len;
} ex_flash_update_info_parm;
static ex_flash_update_info_parm ex_update_info = {0};
#define EX_FLAHS_NEW_OPS 1
#if EX_FLAHS_NEW_OPS
static void *device;
static struct flash_platform_data ex_norflash_data = {
.flash_type = DEV_FLASH_EXTERNAL_NORFLASH,
.read_mode = 1,
.power_io_level = 1,
.spi_pdata = {
.clk_div = 3,
},
};
#else // EX_FLAHS_NEW_OPS
#include "ex_norflash.h"
#define EX_FLASH_USE_SFC 1
#if (EX_FLASH_USE_SFC == 0)
extern struct spi_platform_data spi_p_data;
static struct norflash_dev_platform_data ex_norflash_data = {
.spi_hw_num = 0, //只支持SPI1或SPI2
.spi_cs_port = IO_PORTC_03, //cs的引脚
.spi_read_width = 1, //flash读数据的线宽
.spi_pdata = &spi_p_data,
};
#endif
#endif // EX_FLAHS_NEW_OPS
static u8 ex_norflash_init = 0;
static u32 ex_nor_file_offset = 0;
static volatile u32 mutil_ufw_offset = 0;
extern struct flash_platform_data inside_flash_pdata;
extern int sfc_spi_init(u32 data_width, u32 read_mode, u32 div);
extern int sfc_spi_read(u32 addr, void *buf, u32 len);
void DcuInitial(void);
void IcuInitial(void);
void mdelay(u32 msec);
static u16 ex_flash_open(void)
{
return !ex_norflash_init;
}
#if EX_FLAHS_NEW_OPS
static u16 ex_flash_read(void *fp, void *buf, u32 rlen)
{
if (ex_norflash_init == 0) {
return (u16) - 1;
}
u32 len;
wdt_clear();
if (device) {
norflash_select_device(ex_norflash_data.spi_pdata.spi_idx, ex_norflash_data.spi_pdata.port);
len = dev_bulk_read(device, buf, ex_update_info.src_file_addr + ex_nor_file_offset, rlen);
norflash_select_device(0, inside_flash_pdata.spi_pdata.port);
}
return len;
}
#else // EX_FLAHS_NEW_OPS
static u16 ex_flash_read(void *fp, void *buf, u32 rlen)
{
if (ex_norflash_init == 0) {
return (u16) - 1;
}
u32 len;
wdt_clear();
#if (EX_FLASH_USE_SFC == 0)
len = _norflash_read(ex_update_info.src_file_addr + ex_nor_file_offset, buf, rlen);
#else
len = sfc_spi_read(ex_update_info.src_file_addr + ex_nor_file_offset, buf, rlen);
#endif
if (len != rlen) {
return 0;
}
return len;
}
#endif // EX_FLAHS_NEW_OPS
static int ex_flash_seek(void *fp, u8 type, u32 offset)
{
if (type == SEEK_SET) {
offset += mutil_ufw_offset;
ex_nor_file_offset = offset;
} else if (type == SEEK_CUR) {
ex_nor_file_offset += offset;
}
/* printf(">>>[test]:ex_nor_file_offset = %d\n", ex_nor_file_offset); */
return 0;//FR_OK;
}
//ufw嵌套ufw格式处理
void mutil_cpu_set_offset(u32 offset)
{
mutil_ufw_offset = offset;
ex_nor_file_offset = mutil_ufw_offset; //预先设置好偏移
}
static void ex_flash_update_parm_set(void *priv)
{
UPDATA_PARM *p = (UPDATA_PARM *)priv;
memcpy((u8 *)(&ex_update_info), p->parm_priv, sizeof(ex_flash_update_info_parm));
put_buf(&ex_update_info, sizeof(ex_flash_update_info_parm));
printf("\n >>>[test]:func = %s,line= %d, file_addr = %d\n", __FUNCTION__, __LINE__, ex_update_info.src_file_addr);
}
/* #if (EX_FLASH_USE_SFC == 0) */
static u8 ex_flash_find_delimiter(u8 *string)
{
u8 i = 0;
for (; i < strlen(string); i++) {
if (string[i] == '_') {
return i + 1;
}
}
return 0;
}
static u32 ex_flash_get_cfg_from_isd_config(struct flash_platform_data *exflash_cfg)
{
u8 *ptr = jlfs_get_isd_cfg_ptr();
u8 val[32] = {0};
memset(val, 0, sizeof(val));
u8 *pdata = val;
if (dec_isd_cfg_ini("EX_FLASH", val, ptr)) {
exflash_cfg->spi_pdata.cs_port = get_gpio(pdata);
pdata += ex_flash_find_delimiter(pdata);
exflash_cfg->spi_pdata.spi_idx = pdata[0] - '0';
exflash_cfg->spi_pdata.port = pdata[1] - 'A';
pdata += ex_flash_find_delimiter(pdata);
exflash_cfg->power_io = get_gpio(pdata);
} else {
return 0;
}
pdata = val;
if (dec_isd_cfg_ini("EX_FLASH_IO", val, ptr)) {
exflash_cfg->spi_pdata.width = pdata[0] - '0';
pdata += ex_flash_find_delimiter(pdata);
exflash_cfg->spi_pdata.clk_port = get_gpio(pdata);
pdata += ex_flash_find_delimiter(pdata);
exflash_cfg->spi_pdata.do_port = get_gpio(pdata);
pdata += ex_flash_find_delimiter(pdata);
exflash_cfg->spi_pdata.di_port = get_gpio(pdata);
pdata += ex_flash_find_delimiter(pdata);
exflash_cfg->spi_pdata.d2_port = get_gpio(pdata);
pdata += ex_flash_find_delimiter(pdata);
exflash_cfg->spi_pdata.d3_port = get_gpio(pdata);
} else {
return 0;
}
return 1;
}
/* #endif */
#if EX_FLAHS_NEW_OPS
int ex_flash_update_init(void)
{
int ret = -1;
if (ex_flash_get_cfg_from_isd_config(&ex_norflash_data)) {
device = dev_open("norflash", &ex_norflash_data);
if (device) {
ex_norflash_init = 1;
ret = 0;
} else {
printf("ex flash open fail\n");
}
}
return ret;
}
#else // EX_FLAHS_NEW_OPS
/* u8 t[1024]; */
void sfc1_io_init(u32 data_width);
int ex_flash_update_init(void)
{
sfc1_io_init(4);
if (ex_flash_get_cfg_from_isd_config(&ex_norflash_data)) {
//flash POWER ON
if (ex_norflash_data.spi_power_pin < IO_PORT_MAX) {
gpio_set_direction(ex_norflash_data.spi_power_pin, 0);
gpio_set_output_value(ex_norflash_data.spi_power_pin, 1);
}
log_info("spi_power_pin = %d\n", ex_norflash_data.spi_power_pin);
log_info("spi_cs_pin = %d\n", ex_norflash_data.spi_cs_port);
log_info("spi_hw_num = %d\n", ex_norflash_data.spi_hw_num);
log_info("spi_port_num = %d\n", ex_norflash_data.spi_pdata->port);
_norflash_init(NULL, &ex_norflash_data);
_norflash_open();
ex_norflash_init = 1;
} else {
log_info("EXFLASH tag find fail\n");
return -1;
}
#if EX_FLASH_USE_SFC
/* JL_PORTC->OUT |= BIT(8); */
/* JL_PORTC->HD |= BIT(8); */
/* JL_PORTC->HD0 |= BIT(8); */
/* JL_PORTC->DIR &= ~BIT(8); */
sfc_spi_init(4, 0, 3);
mdelay(20);
IcuInitial();
DcuInitial();
/* sfc_spi_read(0, t, 512); */
/* put_buf(t, 512); */
/* printf(">>>[test]:aaaaaaaaaaaaa!\n"); */
/* sfc_spi_read(512, t, 512); */
/* put_buf(t, 512); */
/* printf(">>>[test]:bbbbbbbb!\n"); */
/* sfc_spi_read(512 * 2, t, 512); */
/* put_buf(t, 512); */
/* printf(">>>[test]:cccccccc!\n"); */
/* sfc_spi_read(512 * 3, t, 512); */
/* put_buf(t, 512); */
/* printf(">>>[test]:dddddddd!\n"); */
/* while(1); */
ex_norflash_init = 1;
return 0;
#else
return 0;
#endif
}
#endif // EX_FLAHS_NEW_OPS
#if (EX_FLASH_USE_SFC == 0)
static void ex_flash_close(void)
{
if (ex_norflash_init) {
#if (0 == EX_FLAHS_NEW_OPS)
_norflash_close();
#endif // EX_FLAHS_NEW_OPS
ex_norflash_init = 0;
}
}
#endif
void ex_flash_update_state_cbk(u32 status, void *priv)
{
switch (status) {
case UPDATE_PARM: //升级需要的参数
log_info("EX_FLASH_UPDATE_SPARM_SET...\n");
ex_flash_update_parm_set(priv);
break;
case UPDATE_START: //测试盒edr升级需要根据priv判断是否恢复基带
log_info("EX_FLASH_UPDATE_START...\n");
ex_flash_update_init();
mdelay(20); //初始化后做延时,否则可能因为不稳定导致读取外置flash数据有问题
norflash_select_device(0, inside_flash_pdata.spi_pdata.port); //后续需要获取内置flash数据的话,这里需要做切换
break;
case UPDATE_END: //升级结束需要保存结果到Ram给SDK获取,并回复主机升级结果
if (*((u8 *)priv) == UPDATE_ERR_NONE) {
set_updata_result(USER_NORFLASH_UFW_UPDATA, UPDATA_SUCCESSFULLY);
} else {
set_updata_result(USER_NORFLASH_UFW_UPDATA, UPDATA_DEV_ERR);
}
/* ex_flash_update_result_report(*((u8 *)priv)); */
#if (EX_FLASH_USE_SFC == 0)
ex_flash_close();
#endif
/* cpu_reset(); */
update_reset();
break;
}
}
update_op_api_t ex_flash_op_api = {
.f_open = ex_flash_open,
.f_read = ex_flash_read,
.f_seek = ex_flash_seek,
.notify_update_content_size = NULL,
};
update_mode_info_t update_mode_info = {
.type = USER_NORFLASH_UFW_UPDATA,
.state_cbk = ex_flash_update_state_cbk,
.file_op = &ex_flash_op_api,
};
#if EX_FLAHS_NEW_OPS
REGISTER_DEVICES(device_table) = {
{"norflash", &norflash_dev_ops, NULL},
};
#endif // EX_FLAHS_NEW_OPS
@@ -0,0 +1,395 @@
#ifdef SUPPORT_MS_EXTENSIONS_APP
#pragma bss_seg(".update_main.data.bss")
#pragma data_seg(".update_main.data")
#pragma const_seg(".update_main.text.const")
#pragma code_seg(".update_main.text")
#endif
#include "common.h"
#include "crc.h"
#include "update_main.h"
#include "lib_include.h"
#include "power/p33.h"
#include "dec.h"
#include "jlfs.h"
#include "gpio.h"
#include "power/power_reset.h"
#define LOG_TAG_CONST UPDATE_MAIN
#define LOG_TAG "[UPDATE_MAIN]"
#define LOG_ERROR_ENABLE
#define LOG_DEBUG_ENABLE
#define LOG_INFO_ENABLE
#define LOG_DUMP_ENABLE
#define LOG_CLI_ENABLE
#include "debug.h"
extern update_mode_info_t update_mode_info;
extern void update_get_record_form_flash(u8 *ram);
extern void update_get_record_form_flash_v2(u8 **p);
extern u8 *update_param_ext_get(UPDATA_PARM *p, u8 ext_type);
extern int update_loop(update_op_api_t *update_op);
extern void user_api_special_handle_info_set(UPDATA_PARM *p);
void ram_protect_close(void);
void bredr_bd_close();
void ll_hci_destory(void);
void update_enter_jump_maskrom(void);
void latch_reset(void);
static u8 latch_flag = 0;
void jump_mode_check(u8 *p);
extern void latch_unlock(void);
extern void reserved_area_update_file_disable(void);
#define __this (&update_mode_info)
// 从扩展升级参数中取出信息,判断是否不升级升级预留区域
static u8 reserved_update_check(u8 *p)
{
u8 *reserved_zone_update_flag = update_param_ext_get((UPDATA_PARM *)p, EXT_RESERVED_UPDATE);
if (reserved_zone_update_flag && reserved_zone_update_flag[0]) {
reserved_area_update_file_disable();
}
return 0;
}
u8 new_sdk_update_again_flag_get(u8 *p)
{
u8 *update_again_flag = update_param_ext_get((UPDATA_PARM *)p, EXT_NEW_SDK_UPD_AGAIN);
if (update_again_flag && update_again_flag[0]) {
return update_again_flag[0];
}
return 0;
}
//检查ram里的update信息
bool update_check(void)
{
u16 crc_cal;
//check_updata_parm is valid
UPDATA_PARM *p = (UPDATA_PARM *)UPDATE_FLAG_ADDR; //定位到ram1最后地址
log_info("update param:");
log_info_hexdump((u8 *)p, sizeof(UPDATA_PARM));
log_info("update param priv:");
log_info_hexdump(p->parm_priv, 32);
crc_cal = chip_crc16(((u8 *)p) + 2, sizeof(UPDATA_PARM) - 2);
if (crc_cal && crc_cal == p->parm_crc) {
if ((NON_DEV_UPDATA != p->parm_type) && (UPDATA_READY == p->parm_result)) {
log_info("update_check ture\n");
return TRUE;
}
}
return FALSE;
}
#define SDK_JUMP_FLAG "SDKJUMP"
#define OTA_JUMP_FLAG "OTAJUMP"
UPDATE_MODE uart_update_judge_startup_mode(void)
{
#if defined(UART_USE_SEC_MODE) && UART_USE_SEC_MODE
// 由一级loader跳转
if (strcmp((const char *)UART_UPDATE_FLAG_ADDR, OTA_JUMP_FLAG) == 0)
#else
// 由SDK跳转
if (strcmp((const char *)UART_UPDATE_FLAG_ADDR, SDK_JUMP_FLAG) == 0)
#endif
{
memset((u8 *)UART_UPDATE_FLAG_ADDR, 0, 4);
return UPDATE_JUMP;
}
return UPDATE_POWERON; // 复位或者断电重启
}
//写升级标志到ram to SDK, 通知SDK升级结果
void set_updata_result(u16 type, u16 result)
{
UPDATA_PARM *p;
log_info("set update result :0x%x 0x%x\n", type, result);
p = (UPDATA_PARM *)UPDATE_FLAG_ADDR;
memset(p, 0x0, sizeof(UPDATA_PARM));
p->parm_result = result;
p->magic = type;
p->parm_crc = chip_crc16(((u8 *)p) + 2, sizeof(UPDATA_PARM) - 2);
}
#define LATCH_IO_NUM 10
/* static u32 latch_io[LATCH_IO_NUM] = {0}; */
static u8 val[LATCH_IO_NUM * 7 + 1] = {0};
//格式为PB01&0_PB02&1 &0\1表示输出低或者高
#if UPDATE_COMPATIBILITY_EN
static void mutual_get_update_latch_io(u8 *pos)
{
if (!pos) {
return;
}
for (int i = 0; i < 4; i++) {
u32 keep_io = get_gpio(&pos[i * 5]);
printf(" latch_io[%d] = %d, %s\n", i, keep_io, &pos[i * 5]);
if (keep_io < IO_PORT_MAX) {
gpio_set_direction(keep_io, 0);
gpio_set_output_value(keep_io, 1);
}
}
}
#endif
static u32 update_set_latch_io(void)
{
u8 *ptr = jlfs_get_isd_cfg_ptr();
#if UPDATE_COMPATIBILITY_EN
if (dec_isd_cfg_ini("SD_LATCH_IO", (void *)val, ptr)) {
u8 *pos = &val[0];
mutual_get_update_latch_io(pos);
return 0;
}
#endif
if (dec_isd_cfg_ini("LATCH_IO", (void *)val, ptr)) {
put_buf(val, sizeof(val));
int len = strlen((const char *)val);
int i = 0;
u8 *val_s = &val[0];
char *pos = (char *)&val[0];
u8 io_arg[10];
while (1) {
if (len < i * 7) {
break;
}
//获取‘&’的位置,获取高低电平设置
char *level = strchr((const char *)pos, '&');
#if UPDATE_COMPATIBILITY_EN
if (level == NULL) {
mutual_get_update_latch_io(pos);
break;
}
#endif
u8 value = (u8)(level[1] - '0');
//获取IO的字符串,传给gpio();
u32 io_len = (u32)(level - pos);
memset(io_arg, 0, sizeof(io_arg));
memcpy(io_arg, pos, io_len);
u32 keep_io = get_gpio((const char *)io_arg);
//设置IO状态
printf(" latch_io[%d] = %d, %s, value = %d\n", i, keep_io, io_arg, value);
#ifdef IO_PORT_USB_MASK
if (keep_io == IO_PORT_DP || keep_io == IO_PORT_DM) {
gpio_set_direction(keep_io, 1);
gpio_set_pull_up(keep_io, value);
gpio_set_pull_down(keep_io, !value);
} else
#endif
{
gpio_set_direction(keep_io, 0);
gpio_set_output_value(keep_io, value);
}
//基指针偏移
pos = strchr((const char *)pos, '_');
if (pos == NULL) {
break;
}
pos ++;
i++;
}
return i;
} else {
return -1;
}
}
static void update_set_latch()
{
if (update_set_latch_io() != -1) {
latch_unlock();
}
}
#if defined(CONFIG_CPU_BD49)
struct boot_soft_flag_t boot_flag = {0};
#endif
void update_main()
{
UPDATA_PARM *p = (UPDATA_PARM *)UPDATE_FLAG_ADDR;
UPDATE_MODE mode = UPDATE_JUMP;
UPDATA_RESULT result = UPDATA_RESULT_FAIL;
#if !UART_UPDATE_ONLY_TEST_MODE
//update_check
if (update_check() == FALSE) { //RAM中的结构体不存在, 判断为断电重新上电
log_info("Ota Start PowerOn\n");
mode = UPDATE_POWERON;
} else {
#if (UART_UPDATA_MODULE_CONTROL || UART_UPDATA_USER_MODULE_CONTROL)
mode = uart_update_judge_startup_mode();
#endif
}
log_info("mode : %d\n", mode);
#if UPDIFF_FLASH_UPDATE_SUPPORT_EN
update_get_record_form_flash_v2(&p); //从flash里把参数读出来,遍历整个flash
#else
update_get_record_form_flash((u8 *)&p); //从flash里把参数读出来
#endif
#if 0
/* TODO */
u8 *data = update_param_ext_get(p, EXT_RF_PA_INFO);
put_buf(data, 3);
#endif
#endif
jump_mode_check((u8 *)p);
if (latch_flag) {
#if defined(CONFIG_CPU_BD49)
memset(&boot_flag, 0, sizeof(struct boot_soft_flag_t));
u8 *romio_info = update_param_ext_get((UPDATA_PARM *)p, EXT_KEEP_ROMIO_INFO);
if (romio_info) {
memcpy(&boot_flag, romio_info, sizeof(struct boot_soft_flag_t));
}
#endif
}
reserved_update_check((u8 *)p);
user_api_special_handle_info_set(p);
#if defined(CONFIG_CPU_BR35)
u16 type = p->parm_type;
u8 update_again_flag = new_sdk_update_again_flag_get(p);
#endif
#if (defined(CONFIG_CPU_BR35) && (USER_LC_FLASH_UPDATA_MODULE_CONTROL || EX_FLASH_UPDATE_SUPPORT_EN))
extern void ota_get_sys_clk(u8 * param);
u8 *tmp_buf = update_param_ext_get((UPDATA_PARM *)p, EXT_SYS_CLK_PARAM);
if (tmp_buf) {
ota_get_sys_clk(tmp_buf);
}
#endif
update_set_latch(); //升级前解除latch,处理SD卡和外置flash这种需要动IO的升级方式
/* mode = UPDATE_POWERON; */
//给各升级模块传递参数
log_info(">>>[test]:UPDATE_STEP: SET UPDATE_PARM\n");
__this->state_cbk(UPDATE_PARM, p);
log_info(">>>[test]:UPDATE_STEP: UPDATE_START, mode = 0x%x\n", mode);
__this->state_cbk(UPDATE_START, &mode);
#if !UART_UPDATE_ONLY_TEST_MODE
//loop
log_info(">>>[test]:UPDATE_STEP: update_loop\n");
result = update_loop((update_op_api_t *)__this->file_op);
log_info(">>>[test]:UPDATE_STEP: UPDATE_END, result = 0x%x\n", result);
//end
#if (defined(CONFIG_CPU_BR35) && (defined(EDR_UPDATA_SUPPORT_CONNECT) || defined(BLE_UPDATA_SUPPORT_CONNECT)))
if (update_again_flag) {
set_updata_result(type, UPDATA_DEV_ERR);
update_reset();
}
#endif
__this->state_cbk(UPDATE_END, &result); //不同升级完成之后可能需要执行不同操作
#endif
}
__attribute__((weak))
u8 *get_isd_cfg_ptr(void)
{
return jlfs_get_isd_cfg_ptr();
}
u32 get_update_jump_flag()
{
u8 *ptr = jlfs_get_isd_cfg_ptr();
u32 u32Val;
u8 val[16] = {0};
printf("\n >>>[test]:func = %s,line= %d\n", __FUNCTION__, __LINE__);
if (dec_isd_cfg_ini("UPDATE_JUMP", (void *)val, ptr)) {
put_buf(val, 16);
/* u32Val = (u32) (((u8 *)val)[0] - '0'); */
u32Val = (u32)val[0];
printf("update_jump = %d, vol[0] = %d\n", u32Val, val[0]);
return u32Val;
} else {
return 0;
}
}
void jump_mode_check(u8 *p)
{
u8 *p_latch_flag = NULL;
if (latch_flag == 0) {
p_latch_flag = update_param_ext_get((UPDATA_PARM *)p, EXT_JUMP_FLAG);
if (p_latch_flag) {
latch_flag = p_latch_flag[0];
}
}
printf(">>>[test]:latch_flag = %d\n", latch_flag);
}
u32 update_get_lrc_hz(void)
{
u32 lrc_hz = 0;
UPDATA_PARM *p = (UPDATA_PARM *)UPDATE_FLAG_ADDR;
memcpy(&lrc_hz, &p->parm_priv[sizeof(p->parm_priv) - sizeof(lrc_hz)], sizeof(lrc_hz));
return lrc_hz;
}
__attribute__((weak))
void system_reset(enum RESET_FLAG flag)
{
cpu_reset();
}
void update_reset(void)
{
printf("\n >>>[test]:func = %s,line= %d\n", __FUNCTION__, __LINE__);
/* 寄存器不会复位 */
#if (0 == UART_UPDATE_ONLY_TEST_MODE)
/* u8 *p = NULL; */
/* UPDATA_PARM *p = (UPDATA_PARM *)UPDATE_FLAG_ADDR; */
/* update_get_record_form_flash((u8 *)&p); //从flash里把参数读出来 */
/* jump_mode_check((u8 *)p); */
if (latch_flag) {
puts("latch reset...\n");
void latch_reset(void);
latch_reset();
} else
#endif
{
printf(">>>[test]:cpu_reset\n");
system_reset(UPDATE_FLAG);
}
}
#if defined(CONFIG_CPU_BD49)
struct boot_soft_flag_t *latch_info_get(void)
{
int k = 0;
int len = sizeof(struct boot_soft_flag_t);
u8 *romio_info = NULL;
u8 *p = &boot_flag;
for (int i = 0; i < len; i++) {
if (p[i] != 0) {
k = 1;
break;
}
}
if (k) {
romio_info = &boot_flag;
}
return (struct boot_soft_flag_t *)romio_info;
}
#endif