tr6260 split

This commit is contained in:
Tester23
2025-08-14 16:10:01 +02:00
parent 7411067694
commit 507cefba3e
3 changed files with 99 additions and 29 deletions

View File

@@ -11,7 +11,7 @@ CSRCS += hal/tr6260/hal_generic_tr6260.c
CSRCS += hal/tr6260/hal_main_tr6260.c
CSRCS += hal/tr6260/hal_pins_tr6260.c
CSRCS += hal/tr6260/hal_wifi_tr6260.c
CSRCS += hal/ecr6600/hal_ota_ecr6600.c
CSRCS += hal/tr6260/hal_ota_tr6260.c
OBK_SRCS =
include $(OBK_PATH)/../platforms/obk_main.mk

View File

@@ -1,4 +1,4 @@
#if PLATFORM_ECR6600 || PLATFORM_TR6260
#if PLATFORM_ECR6600
#include "../../obk_config.h"
#include "../../new_common.h"
@@ -7,42 +7,18 @@
#include "../../httpserver/new_http.h"
#include "../hal_ota.h"
#if PLATFORM_TR6260
#include "otaHal.h"
#include "drv_spiflash.h"
#define OTA_INIT otaHal_init
#define OTA_WRITE otaHal_write
#define OTA_DONE(x) otaHal_done()
int HAL_FlashRead(char*buffer, int readlen, int startaddr) {
int res;
res = hal_spiflash_read(startaddr, (uint8_t*)buffer, readlen);
return res;
}
#elif PLATFORM_ECR6600
#include "flash.h"
extern int ota_init(void);
extern int ota_write(unsigned char* data, unsigned int len);
extern int ota_done(bool reset);
#define OTA_INIT ota_init
#define OTA_WRITE ota_write
#define OTA_DONE(x) ota_done(x)
int HAL_FlashRead(char*buffer, int readlen, int startaddr) {
int res;
res = drv_spiflash_read(startaddr, (uint8_t*)buffer, readlen);
return res;
}
#endif
int http_rest_post_flash(http_request_t* request, int startaddr, int maxaddr)
{
int total = 0;
@@ -66,7 +42,7 @@ int http_rest_post_flash(http_request_t* request, int startaddr, int maxaddr)
goto update_ota_exit;
}
if (OTA_INIT() != 0)
if (ota_init() != 0)
{
ret = -1;
goto update_ota_exit;
@@ -74,7 +50,7 @@ int http_rest_post_flash(http_request_t* request, int startaddr, int maxaddr)
do
{
if (OTA_WRITE((unsigned char*)writebuf, writelen) != 0)
if (ota_write((unsigned char*)writebuf, writelen) != 0)
{
ret = -1;
goto update_ota_exit;
@@ -100,7 +76,7 @@ update_ota_exit:
if (ret != -1)
{
ADDLOG_INFO(LOG_FEATURE_OTA, "OTA is successful");
OTA_DONE(0);
ota_done(0);
}
else
{

View File

@@ -0,0 +1,94 @@
#if PLATFORM_TR6260
#include "../../obk_config.h"
#include "../../new_common.h"
#include "../../new_cfg.h"
#include "../../logging/logging.h"
#include "../../httpserver/new_http.h"
#include "../hal_ota.h"
#include "otaHal.h"
#include "drv_spiflash.h"
int HAL_FlashRead(char*buffer, int readlen, int startaddr) {
int res;
res = hal_spiflash_read(startaddr, (uint8_t*)buffer, readlen);
return res;
}
int http_rest_post_flash(http_request_t* request, int startaddr, int maxaddr)
{
int total = 0;
int towrite = request->bodylen;
char* writebuf = request->bodystart;
int writelen = request->bodylen;
ADDLOG_DEBUG(LOG_FEATURE_OTA, "OTA post len %d", request->contentLength);
int ret = 0;
if (request->contentLength > 0)
{
towrite = request->contentLength;
}
else
{
ret = -1;
ADDLOG_ERROR(LOG_FEATURE_OTA, "Content-length is 0");
goto update_ota_exit;
}
if (otaHal_init() != 0)
{
ret = -1;
goto update_ota_exit;
}
do
{
if (otaHal_write((unsigned char*)writebuf, writelen) != 0)
{
ret = -1;
goto update_ota_exit;
}
delay_ms(10);
ADDLOG_DEBUG(LOG_FEATURE_OTA, "Writelen %i at %i", writelen, total);
total += writelen;
startaddr += writelen;
towrite -= writelen;
if (towrite > 0)
{
writebuf = request->received;
writelen = recv(request->fd, writebuf, request->receivedLenmax, 0);
if (writelen < 0)
{
ADDLOG_DEBUG(LOG_FEATURE_OTA, "recv returned %d - end of data - remaining %d", writelen, towrite);
ret = -1;
}
}
} while ((towrite > 0) && (writelen >= 0));
update_ota_exit:
if (ret != -1)
{
ADDLOG_INFO(LOG_FEATURE_OTA, "OTA is successful");
otaHal_done(0);
}
else
{
ADDLOG_ERROR(LOG_FEATURE_OTA, "OTA failed. Reboot to retry");
return http_rest_error(request, ret, "error");
}
ADDLOG_DEBUG(LOG_FEATURE_OTA, "%d total bytes written", total);
http_setup(request, httpMimeTypeJson);
hprintf255(request, "{\"size\":%d}", total);
poststr(request, NULL);
CFG_IncrementOTACount();
return 0;
}
#endif