Modify the order for serial configure and semaphore

This commit is contained in:
songyanguang 2025-06-08 19:42:00 -07:00
parent a20a2d5327
commit 1703db93cb
5 changed files with 50 additions and 42 deletions

View File

@ -117,6 +117,7 @@ bool MQTT_Connect(void)
uint8_t TryConnect_time = 10; //尝试登录次数
KPrintf("%s enter\n", __func__);
memset(&Platform_mqtt,0,sizeof(Platform_mqtt));
#ifdef XIUOS_PLATFORM
sprintf(Platform_mqtt.ClientID,"%s",CLIENTID); //客户端ID存入缓冲区
@ -183,7 +184,7 @@ bool MQTT_Connect(void)
MQTT_Send(Platform_mqtt.Pack_buff,Platform_mqtt.Fixed_len + Platform_mqtt.Variable_len + Platform_mqtt.Payload_len);
MdelayKTask(50);
MQTT_Recv(mqtt_rxbuf, 4);
if(mqtt_rxbuf[0] == parket_connetAck[0] && mqtt_rxbuf[1] == parket_connetAck[1]) //连接成功
if(mqtt_rxbuf[0] == parket_connetAck[0] && mqtt_rxbuf[1] == parket_connetAck[1] && mqtt_rxbuf[2] == parket_connetAck[2] && mqtt_rxbuf[3] == parket_connetAck[3]) //连接成功
{
return true;
}
@ -215,6 +216,8 @@ bool MQTT_SubscribeTopic(uint8_t *topic_name)
{
uint8_t TrySub_time = 10; //尝试订阅次数
KPrintf("%s topic_name=%s\n", __func__, topic_name);
Platform_mqtt.Fixed_len = 1; //SUBSCRIBE报文,固定报头长度暂定为1
Platform_mqtt.Variable_len = 2;//SUBSCRIBE报文,可变报头长度=2,2为字节报文标识符
Platform_mqtt.Payload_len = 0; //SUBSCRIBE报文,负载数据长度暂定为0

View File

@ -102,8 +102,6 @@ CONFIG_KERNEL_CONSOLEBUF_SIZE=128
# Command shell
#
# CONFIG_TOOL_SHELL is not set
# CONFIG_SHELL_ENTER_CR_AND_LF is not set
# CONFIG_SHELL_ENTER_CRLF is not set
#
# Kernel data structure Manage
@ -167,8 +165,8 @@ CONFIG_FS_VFS_DEVFS=y
# OTA function
#
CONFIG_TOOL_USING_OTA=y
CONFIG_MCUBOOT_BOOTLOADER=y
# CONFIG_MCUBOOT_APPLICATION is not set
# CONFIG_MCUBOOT_BOOTLOADER is not set
CONFIG_MCUBOOT_APPLICATION=y
CONFIG_OTA_BY_PLATFORM=y
# CONFIG_OTA_BY_TCPSERVER is not set
# CONFIG_OTA_BY_NONE is not set
@ -311,7 +309,7 @@ CONFIG_XIUOS_PLATFORM=y
# xiuos platform mqtt connection parameter configuration.
#
CONFIG_CLIENTID="D001"
CONFIG_USERNAME="xiuosiot"
CONFIG_USERNAME="ch32v208"
CONFIG_PASSWORD="xiuosiot"
CONFIG_PLATFORM_SERVERIP="47.115.50.232"
CONFIG_PLATFORM_SERVERPORT="1883"

View File

@ -27,7 +27,7 @@ MEMORY
FLASH-160K + RAM-32K
*/
FLASH_FAST (rx) : ORIGIN = 0x00000000, LENGTH = 32K
FLASH (rx) : ORIGIN = 0x00048000, LENGTH = 156K
FLASH (rx) : ORIGIN = 0x00050000, LENGTH = 156K
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 64K
}

View File

@ -444,6 +444,27 @@ static uint32 SerialDevOpen(void *dev)
return ERROR;
}
serial_dev->haldev.dev_sem = KSemaphoreCreate(0);
if (serial_dev->haldev.dev_sem < 0)
{
KPrintf("SerialDevOpen create sem failed .\n");
if (serial_dev->serial_fifo.serial_rx->serial_rx_buffer)
{
x_free(serial_dev->serial_fifo.serial_rx->serial_rx_buffer);
}
if (serial_dev->serial_fifo.serial_rx)
{
x_free(serial_dev->serial_fifo.serial_rx);
}
if (serial_dev->serial_fifo.serial_tx)
{
x_free(serial_dev->serial_fifo.serial_tx);
}
return ERROR;
}
if (NONE == serial_dev->serial_fifo.serial_rx)
{
if (SIGN_OPER_INT_RX & serial_dev_param->serial_set_mode)
@ -596,27 +617,6 @@ static uint32 SerialDevOpen(void *dev)
#endif
}
serial_dev->haldev.dev_sem = KSemaphoreCreate(0);
if (serial_dev->haldev.dev_sem < 0)
{
KPrintf("SerialDevOpen create sem failed .\n");
if (serial_dev->serial_fifo.serial_rx->serial_rx_buffer)
{
x_free(serial_dev->serial_fifo.serial_rx->serial_rx_buffer);
}
if (serial_dev->serial_fifo.serial_rx)
{
x_free(serial_dev->serial_fifo.serial_rx);
}
if (serial_dev->serial_fifo.serial_tx)
{
x_free(serial_dev->serial_fifo.serial_tx);
}
return ERROR;
}
return EOK;
}

View File

@ -450,6 +450,12 @@ static void Update(void)
/*进行新版本的升级*/
else
{
if(XIUOS_FLAH_ADDRESS == DOWN_FLAH_ADDRESS)
{
mcuboot.flash_deinit();
return;
}
if(UpdateNewApplication() == true) /*如果实际发生了flash搬移,操作完成后再重启一次*/
{
mcuboot.flash_deinit();
@ -912,9 +918,7 @@ static void mqttCloudInteraction(void* parameter)
mcuboot.flash_init();
memset(p_ota_info, 0, sizeof(ota_info_t));
mcuboot.op_flash_read(FLAG_FLAH_ADDRESS, (void*)p_ota_info, sizeof(ota_info_t));
#ifdef MCUBOOT_BOOTLOADER
p_ota_info->status = OTA_STATUS_BOOT_DOWNLOAD;
#else
#ifndef MCUBOOT_BOOTLOADER
p_ota_info->status = OTA_STATUS_DOWNLOADING;
#endif
UpdateOTAFlag(p_ota_info);
@ -922,17 +926,6 @@ static void mqttCloudInteraction(void* parameter)
sprintf(topicdatabuff[0],"ota/%s/update",CLIENTID);
sprintf(topicdatabuff[1],"ota/%s/files",CLIENTID);
#if 1 //debug
if((AdapterNetActive() == 0) )
{
KPrintf("mqttCloudInteraction write OTA flag and reboot\n");
p_ota_info->status = OTA_STATUS_BOOT_DOWNLOAD;
UpdateOTAFlag(p_ota_info);
MdelayKTask(2000);
mcuboot.op_reset();
}
#endif
reconnect:
if((AdapterNetActive() == 0) && MQTT_Connect() && MQTT_SubscribeTopic(topicdatabuff[0]) && MQTT_SubscribeTopic(topicdatabuff[1]))
{
@ -988,6 +981,19 @@ reconnect:
if(sscanf(ptr2,"{\"fileSize\":%d,\"version\":\"%11s\",\"fileId\":%d,\"md5\"",&platform_ota.size,platform_ota.version,&platform_ota.streamId)==3)
{
KPrintf("OTA firmware information:file size is %d,file id is %d,file version is %s!\r\n",platform_ota.size,platform_ota.streamId,platform_ota.version);
#ifndef MCUBOOT_BOOTLOADER
if(XIUOS_FLAH_ADDRESS == DOWN_FLAH_ADDRESS)
{
KPrintf("mqttCloudInteraction write OTA flag and reboot\n");
p_ota_info->status = OTA_STATUS_BOOT_DOWNLOAD;
UpdateOTAFlag(p_ota_info);
MQTT_Disconnect();
mcuboot.flash_deinit();
MdelayKTask(2000);
mcuboot.op_reset();
}
#endif
KPrintf("------Start the firmware file transfer!------\r\n");
KPrintf("---------------------------------------------\r\n");
if(platform_ota.size > APP_FLASH_SIZE)
@ -1501,6 +1507,7 @@ void ota_entry(void)
}
else
{
Update();
BootLoaderJumpApp();
}
}