1.add an API of finding the first user task in xiuos task manage list; 2.add restart application after ota

This commit is contained in:
Wang_Weigen 2021-11-10 17:31:39 +08:00
parent f3d527cf70
commit eb14677832
11 changed files with 86 additions and 4 deletions

View File

@ -1,12 +1,12 @@
# OTA README
xiuos当前的ota功能允许应用bin文件可以通过4G实现远程的bin文件更新限制1、bin文件存放在设备SD卡并且应用从SD卡启动2、暂且支持4G实现3、暂时只支持aiit终端
xiuos当前的ota功能允许应用bin文件可以通过4G实现远程的bin文件更新限制1、bin文件存放在设备SD卡并且应用从SD卡启动2、暂且支持4G实现3、暂时只支持aiit终端;4、只支持xiuos内核)。
## 文件说明
| 名称 | 说明 |
| -- | -- |
| ota.c| 设备OTA代码 |
| ota.c| xiuos设备OTA代码 |
| ota_server.c | pc服务端的实例代码供参考 |

View File

@ -22,6 +22,8 @@
#include <transform.h>
#include <adapter.h>
extern int main(void);
struct ota_header_t
{
int16 frame_flag; ///< frame start flag 2 Bytes
@ -47,7 +49,8 @@ struct ota_data
struct ota_frame_t frame;
};
pthread_t ota_ktask;
pthread_t ota_task;
pthread_t restart_main;
/**
* @description: CRC16 check
@ -117,6 +120,26 @@ static int CrcFileCheck(uint32 crc_check, unsigned long total_len)
return ret;
}
static void RestartApplication(void)
{
pthread_attr_t attr;
attr.schedparam.sched_priority = 10;
attr.stacksize = 2048;
while(1)
{
unsigned long pid = PrivUserTaskSearch();
if (pid > 0)
{
PrivTaskDelete(pid, 0);
}
else
{
break;
}
}
PrivTaskCreate(&restart_main, &attr, (void *)main, NULL);
}
static int OtaDataRecv(struct Adapter* adapter)
{
struct ota_data recv_msg;
@ -172,6 +195,7 @@ try_again:
}
}
close(fd);
RestartApplication();
return ret;
}
@ -233,6 +257,6 @@ void ApplicationOtaTaskInit(void)
attr.schedparam.sched_priority = 10;
attr.stacksize = 2048;
PrivTaskCreate(&ota_ktask, &attr, OtaKTaskEntry, NULL);
PrivTaskCreate(&ota_task, &attr, OtaKTaskEntry, NULL);
}

View File

@ -79,6 +79,11 @@ int PrivTaskStartup(pthread_t *thread)
{
return 0;
}
/* private API of xiuos to search the first user task in manage list */
int PrivUserTaskSearch(void)
{
return UserTaskSearch();
}
int PrivTaskDelete(pthread_t thread, int sig)
{

View File

@ -171,6 +171,7 @@ int PrivTaskStartup(pthread_t *thread);
int PrivTaskDelete(pthread_t thread, int sig);
void PrivTaskQuit(void *value_ptr);
int PrivTaskDelay(int32_t ms);
int PrivUserTaskSearch(void);
/*********************driver*************************/

View File

@ -99,6 +99,7 @@ int pthread_setcanceltype(int type, int *oldtype)
int pthread_kill(pthread_t thread, int sig)
{
/* This api should not be used, and will not be supported */
UserTaskDelete(thread);
return -1;
}

View File

@ -60,6 +60,7 @@ int32_t UserTaskCreate(UtaskType utask);
long UserTaskStartup(int32_t id);
long UserTaskDelete(int32_t id);
long UserTaskSearch(void);
void UserTaskQuit(void);
long UserTaskDelay(int32_t ms);
long UserGetTaskName(int32_t id ,char *name);
@ -185,6 +186,7 @@ int32_t UserTaskCreate(UtaskType utask);
#define UserTaskDelete KTaskDelete
#define UserTaskQuit KTaskQuit
#define UserTaskDelay MdelayKTask
#define UserTaskSearch UTaskSearch
long UserGetTaskName(int32_t id ,char *name);
int32_t UserGetTaskID(void);

View File

@ -60,6 +60,17 @@ x_err_t UserTaskDelete(int32_t id){
return (x_err_t)KSwitch1(KS_USER_TASK_DELETE,(uintptr_t)id);
}
/**
* This function will find the first user task in task manage list.
*
* @param
*
* @return task id on success; EINVALED on failure
*/
x_err_t UserTaskSearch(void){
return KSwitch0(KS_USER_TASK_SEARCH);
}
void UserTaskQuit(void){
KSwitch0(KS_USER_TASK_EXECEXIT);
return ;

View File

@ -159,6 +159,7 @@ int32 KTaskCreate(const char *name,
void KTaskQuit(void);
#ifdef SEPARATE_COMPILE
int UTaskSearch(void);
int32 UTaskCreate(const char *name,
void (*entry)(void *parameter),
void *parameter,

View File

@ -33,6 +33,7 @@ enum KernelServiceEnum
KS_USER_TASK_CREATE ,
KS_USER_TASK_STARTUP ,
KS_USER_TASK_DELETE,
KS_USER_TASK_SEARCH,
KS_USER_TASK_EXECEXIT,
KS_USER_TASK_CORE_COMBINE,
KS_USER_TASK_CORE_UNCOMBINE,

View File

@ -120,6 +120,11 @@ uintptr_t KsTaskDelete(uint32_t knum,uintptr_t *param, uint8_t num)
return (uintptr_t)ret;
}
uintptr_t KsUserTaskSerach(uint32_t knum,uintptr_t *param, uint8_t num )
{
return (uintptr_t)UTaskSearch();
}
extern void KTaskQuit(void);
uintptr_t KsTaskQuit(uint32_t knum,uintptr_t *param, uint8_t num )
{
@ -567,6 +572,7 @@ struct KernelService g_service_table[256] __attribute__ ((section (".g_service_
[KS_USER_TASK_CREATE] = { KsTaskCreate, 5 },
[KS_USER_TASK_STARTUP] = { KsStartupTask, 1 },
[KS_USER_TASK_DELETE] = { KsTaskDelete, 1 },
[KS_USER_TASK_SEARCH] = { KsUserTaskSerach, 0 },
[KS_USER_TASK_EXECEXIT] = { KsTaskQuit, 0 },
[KS_USER_TASK_CORE_COMBINE] = { KsTaskCoreCombine, 2 },
[KS_USER_TASK_CORE_UNCOMBINE] = { KsTaskCoreUnCombine, 1 },

View File

@ -1052,6 +1052,36 @@ x_err_t KTaskWakeup(int32 id)
#ifdef SEPARATE_COMPILE
/**
* find the first user task in manage list.
*
* @param
*
* @note in interrupt status,this function is not permitted to call.
*/
int UTaskSearch(void)
{
x_base lock = 0;
KTaskDescriptorType temp_task = NONE;
struct SysDoubleLinklistNode *node = NONE;
lock = CriticalAreaLock();
DOUBLE_LINKLIST_FOR_EACH(node,&xiaoshan_task_head)
{
temp_task = SYS_DOUBLE_LINKLIST_ENTRY(node, struct TaskDescriptor, link);
if (1 == temp_task->task_dync_sched_member.isolation_flag)
{
CriticalAreaUnLock(lock);
return temp_task->id.id;
}
}
CriticalAreaUnLock(lock);
return -1;
}
/**
*
* This function init a user task in dynamic way .