Skip to content

Commit

Permalink
update rda5981x
Browse files Browse the repository at this point in the history
  • Loading branch information
shileiyu committed Jun 19, 2018
1 parent 06b1412 commit cff2753
Show file tree
Hide file tree
Showing 22 changed files with 299 additions and 62 deletions.
20 changes: 11 additions & 9 deletions board/uno-91h/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,54 +18,56 @@ const hal_logic_partition_t hal_partitions[] =
{
.partition_owner = HAL_FLASH_EMBEDDED,
.partition_description = "Application",
.partition_start_addr = 0x18001000,
.partition_length = 0xBF000, // 764K bytes
.partition_start_addr = 0x18004000,
.partition_length = 0x1f4000,//0xBF000, // 764K bytes
.partition_options = PAR_OPT_READ_EN | PAR_OPT_WRITE_EN,
},
#if 0
#if 1
[HAL_PARTITION_OTA_TEMP] =
{
.partition_owner = HAL_FLASH_EMBEDDED,
.partition_description = "OTA Storage",
.partition_start_addr = 0x18100000,
.partition_length = 0x100000, //1M bytes
.partition_start_addr = 0x181f8000, //0x18100000,
.partition_length = 0xAF000,//700k //0x1f4000, // 2000k //0x100000, //1M bytes
.partition_options = PAR_OPT_READ_EN | PAR_OPT_WRITE_EN,
},
#endif
[HAL_PARTITION_PARAMETER_1] =
{
.partition_owner = HAL_FLASH_EMBEDDED,
.partition_description = "PARAMETER1",
.partition_start_addr = 0x180C0000,
.partition_start_addr = 0x183ec000,//0x180C0000,
.partition_length = 0x1000, //4k bytes
.partition_options = PAR_OPT_READ_EN | PAR_OPT_WRITE_EN,
},
[HAL_PARTITION_PARAMETER_2] =
{
.partition_owner = HAL_FLASH_EMBEDDED,
.partition_description = "PARAMETER2",
.partition_start_addr = 0x180C1000,
.partition_start_addr = 0x183ed000,//0x180C1000,
.partition_length = 0x2000, //8k bytes
.partition_options = PAR_OPT_READ_EN | PAR_OPT_WRITE_EN,
},
[HAL_PARTITION_PARAMETER_3] =
{
.partition_owner = HAL_FLASH_EMBEDDED,
.partition_description = "PARAMETER3",
.partition_start_addr = 0x180C3000,
.partition_start_addr = 0x183ef000,//0x180C3000,
.partition_length = 0x1000, //4k bytes
.partition_options = PAR_OPT_READ_EN | PAR_OPT_WRITE_EN,
},
[HAL_PARTITION_PARAMETER_4] =
{
.partition_owner = HAL_FLASH_EMBEDDED,
.partition_description = "PARAMETER4",
.partition_start_addr = 0x180C4000,
.partition_start_addr = 0x183F0000, //0x180C4000,
.partition_length = 0x1000, //4k bytes
.partition_options = PAR_OPT_READ_EN | PAR_OPT_WRITE_EN,
},
};

extern uart_dev_t uart_0;
void board_init(void)
{
hal_uart_init(&uart_0);
}
7 changes: 4 additions & 3 deletions board/uno-91h/uno-91h.mk
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ GLOBAL_INCLUDES += .
GLOBAL_DEFINES += STDIO_UART=0
GLOBAL_DEFINES += RHINO_CONFIG_TICK_TASK=0 RHINO_CONFIG_WORKQUEUE=0

#CURRENT_TIME = $(shell /bin/date +%Y%m%d.%H%M)
CURRENT_TIME = $(/bin/date +%Y%m%d.%H%M)
CONFIG_SYSINFO_KERNEL_VERSION = AOS-R-1.3.0
CURRENT_TIME := $(shell $(DATE) +%Y%m%d.%H%M)
#CURRENT_TIME = $(/bin/date +%Y%m%d.%H%M)
#CURRENT_TIME = 20180425.2039
#CONFIG_SYSINFO_KERNEL_VERSION = AOS-R-1.0.1

CONFIG_SYSINFO_OS_VERSION := $(call get-os-version)

Expand Down
7 changes: 6 additions & 1 deletion platform/mcu/rda5981x/aos/aos.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ extern int aos_framework_init(void);

extern void hw_start_hal(void);

void hal_init()
{
board_init();
}

static void sys_init(void)
{
LOG("sys_init.");
Expand All @@ -25,7 +30,7 @@ static void sys_init(void)
#ifdef BOOTLOADER
main();
#else
//hal_init();
hal_init();
hw_start_hal();
vfs_init();
vfs_device_init();
Expand Down
2 changes: 1 addition & 1 deletion platform/mcu/rda5981x/driver/PeripheralNames.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#define MBED_PERIPHERALNAMES_H

#include "cmsis.h"
#include "pinnames.h"
#include "PinNames.h"

#ifdef __cplusplus
extern "C" {
Expand Down
2 changes: 1 addition & 1 deletion platform/mcu/rda5981x/driver/objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "cmsis.h"
#include "PortNames.h"
#include "PeripheralNames.h"
#include "pinnames.h"
#include "PinNames.h"
#include "gpio_object.h"

#ifdef __cplusplus
Expand Down
8 changes: 6 additions & 2 deletions platform/mcu/rda5981x/driver/rda_flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,17 @@ void rda5981_spi_erase_partition(void *src, r_u32 counts)
if (a64kend > a64k) {
if (atmp == a64k) {
for (; atmp < a64kend; atmp += (0x01UL << 16)) {
core_util_critical_section_enter();
rda5981_spi_flash_erase_64KB_block(atmp);
core_util_critical_section_exit();
}
if (atmp == a4kend)
break;
}
}
core_util_critical_section_enter();
rda5981_spi_flash_erase_4KB_sector(atmp);
core_util_critical_section_exit();
}
}
}
Expand All @@ -102,9 +106,9 @@ int rda5981_erase_flash(r_u32 addr, r_u32 len)
len = ((len+SECTOR_SIZE) & (~(SECTOR_SIZE-1)));
}

core_util_critical_section_enter();
//core_util_critical_section_enter();
rda5981_spi_erase_partition((void*)addr, len);
core_util_critical_section_exit();
//core_util_critical_section_exit();
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion platform/mcu/rda5981x/driver/rda_flash.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


#define SECTOR_SIZE 4096
#define FLASH_SIZE 0x100000
#define FLASH_SIZE 0x400000

#define RDA5991H_PARTITION_TABLE_END_ADDR 0x18001000 //partition table end addr

Expand Down
4 changes: 2 additions & 2 deletions platform/mcu/rda5981x/hal/hw.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ void hal_timer_stop(timer_dev_t *tmr)
}
#endif
extern hal_wifi_module_t aos_wifi_rda59xx;
//extern struct hal_ota_module_s stm32l475_ota_module;
extern struct hal_ota_module_s rda59xx_ota_module;
void hw_start_hal(void)
{
printf("start-----------hal\n");
hal_wifi_register_module(&aos_wifi_rda59xx);
aos_wifi_rda59xx.init(&aos_wifi_rda59xx);
//hal_ota_register_module(&stm32l475_ota_module);
hal_ota_register_module(&rda59xx_ota_module);
}

117 changes: 117 additions & 0 deletions platform/mcu/rda5981x/hal/ota_port.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>

#include <errno.h>
#include <hal/ota.h>
#include <aos/log.h>
#include <hal/soc/soc.h>

#include "rda_def.h"
#include "rda_flash.h"

r_u32 g_crc_result = ~0UL;
r_u32 g_ota_off_set = 0;

#define CRC32_TABLE_ADDR 0xbb5c
#define CRC32_ADDR 0x8dff
#define CRC32_TABLE_ADDR_4 0xbbd8
#define CRC32_ADDR_4 0x8e33
#define IMAGE_MAGIC 0xAEAE

static r_u32 bootrom_crc32(r_u8 *p, r_u32 len)
{
r_u32 func = CRC32_ADDR;
if (rda_ccfg_hwver() >= 4) {
func = CRC32_ADDR_4;
}
return ((r_u32(*)(r_u8 *, r_u32))func)(p, len);
}

static r_u32 crc32(const r_u8 *p, r_u32 len, r_u32 crc)
{
const r_u32 *crc32_tab = (const r_u32 *)CRC32_TABLE_ADDR;

if (rda_ccfg_hwver() >= 4) {
crc32_tab = (const r_u32 *)CRC32_TABLE_ADDR_4;
}
/* Calculate CRC */
while (len--)
{
crc = crc32_tab[((crc & 0xFF) ^ *p++)] ^ (crc >> 8);
}

return crc;
}

static r_s32 rda59xx_ota_init(hal_ota_module_t *m, void *something)
{
printf("========= OTA init ========= \r\n");
g_ota_off_set = *(r_u32*)something;
hal_partition_t pno = HAL_PARTITION_OTA_TEMP;
hal_logic_partition_t *partition_info;
partition_info = hal_flash_get_info(pno);
//g_ota_partition_len = partition_info->partition_length;
if (g_ota_off_set == 0) {
hal_flash_erase(pno, 0, partition_info->partition_length);
} else {
printf("OTA init invalid, offset = %d \r\n", g_ota_off_set);
}

return 0;
}

static r_s32 rda59xx_ota_write(hal_ota_module_t *m, volatile r_u32* off_set, r_u8* in_buf ,r_u32 in_buf_len)
{
r_s32 ret;

hal_partition_t pno = HAL_PARTITION_OTA_TEMP;
printf("========= OTA write start: len: %d ==========\r\n", in_buf_len);
g_crc_result = crc32(in_buf, in_buf_len, g_crc_result);
ret = hal_flash_write(pno, &g_ota_off_set, in_buf, in_buf_len);
g_ota_off_set += in_buf_len;
return ret;
}

static r_s32 rda59xx_ota_read(hal_ota_module_t *m, volatile r_u32* off_set, r_u8* out_buf, r_u32 out_buf_len)
{
hal_partition_t pno = HAL_PARTITION_OTA_TEMP;
hal_flash_read(pno, off_set, out_buf, out_buf_len);

return 0;
}

static r_s32 rda59xx_ota_set_boot(hal_ota_module_t *m, void *something)
{
printf("========= OTA boot set ========= \r\n");
hal_logic_partition_t *partition_info;
hal_partition_t pno = HAL_PARTITION_OTA_TEMP;
ota_finish_param_t *param = (ota_finish_param_t *)something;
if (param==NULL) {
return -1;
}
if (param->result_type == OTA_FINISH) {
partition_info = hal_flash_get_info(pno);
core_util_critical_section_enter();
spi_flash_flush_cache();
r_u32 crc32_check = bootrom_crc32((r_u8 *)partition_info->partition_start_addr, g_ota_off_set);
core_util_critical_section_exit();
printf("rda5981_write_partition_end:0x%08x:0x%08x\r\n", g_crc_result, crc32_check);
if (crc32_check == g_crc_result) {
hal_reboot();
} else {
printf("ERROR!!! check crc32 error\r\n");
}
} else if (param->result_type==OTA_BREAKPOINT) {
printf("OTA package is incomplete!\r\n");
}
return 0;
}

struct hal_ota_module_s rda59xx_ota_module = {
.init = rda59xx_ota_init,
.ota_write = rda59xx_ota_write,
.ota_read = rda59xx_ota_read,
.ota_set_boot = rda59xx_ota_set_boot,
};
2 changes: 1 addition & 1 deletion platform/mcu/rda5981x/hal/rda_ccfg_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ int rda_ccfg_boot(void)
if(!abort_flag) {
rda_ccfg_pdi2c();
}
//rda_ccfg_ck();
rda_ccfg_ck();
#endif /* RDA5991H_HW_VER */
/* Set flash clock */
rda_ccfg_spifck();
Expand Down
7 changes: 4 additions & 3 deletions platform/mcu/rda5981x/hal/spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ int32_t hal_spi_recv(spi_dev_t *spi, uint8_t *data, uint16_t size, uint32_t time
return 0;
}

int32_t hal_spi_send_recv(spi_dev_t *spi, uint8_t *tx_data,
uint8_t *rx_data, uint16_t size, uint32_t timeout)
int32_t hal_spi_send_recv(spi_dev_t *spi, uint8_t *tx_data, uint8_t *rx_data,
uint16_t size, uint32_t timeout)
{
#if 0
uint8_t val;
uint16_t rx_size = size, tx_size = size;

Expand All @@ -76,7 +77,7 @@ int32_t hal_spi_send_recv(spi_dev_t *spi, uint8_t *tx_data,
rx_data++;
rx_size--;
}

#endif
return 0;
}

Expand Down
33 changes: 25 additions & 8 deletions platform/mcu/rda5981x/hal/wifi_port.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ typedef enum {
} scan_type_t;
hal_wifi_ip_stat_t ip_stat;

unsigned int filter_backup = 0;

void wifi_event_cb(WIFI_EVENT evt, void* info)
{
hal_wifi_module_t *m = hal_wifi_get_default_module();
Expand Down Expand Up @@ -274,7 +276,11 @@ static int suspend_soft_ap(hal_wifi_module_t *m)

static int set_channel(hal_wifi_module_t *m, int ch)
{
rda59xx_set_channel(ch);
//unsigned int mode = rda59xx_get_module_state();
//if(mode & STATE_SNIFFER)
// rda59xx_sniffer_set_channel(ch);
//else
rda59xx_set_channel(ch);
return 0;
}

Expand All @@ -290,10 +296,22 @@ static int get_channel(hal_wifi_module_t *m)
return 0;
}

int sniffer_cb(void *data, unsigned short data_len)
{
if(data_cb != NULL)
(*data_cb)((uint8_t*)data, (int)data_len, NULL);
return 0;
}


static void start_monitor(hal_wifi_module_t *m)
{
rda59xx_sniffer_enable((sniffer_handler_t)data_cb);
rda59xx_sniffer_set_filter(1, 1, 0x3fe77);
//if softap smartconfig failed, it will start monitor dirictly
//so add disconnect to end last link
rda59xx_sta_disconnect();
rda59xx_sniffer_enable(sniffer_cb);
rda59xx_sniffer_set_filter(1, 1, 0x27e77);
filter_backup = 0x27e77;
}

static void stop_monitor(hal_wifi_module_t *m)
Expand All @@ -309,11 +327,10 @@ static void register_monitor_cb(hal_wifi_module_t *m, monitor_data_cb_t fn)
static void register_wlan_mgnt_monitor_cb(hal_wifi_module_t *m,
monitor_data_cb_t fn)
{
//mngt_data_cb = fn;
// Workaround for zero config <TODO>
//hal_wifi_register_monitor_cb(NULL, NULL);
//hal_wifi_start_wifi_monitor(NULL);
printf("WiFi HAL %s not implemeted yet!\r\n", __func__);
data_cb = fn;
rda59xx_sniffer_enable(sniffer_cb);
rda59xx_sniffer_set_filter(1, 1, 0x7fe77);
filter_backup = 0x7fe77;
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion platform/mcu/rda5981x/include/pinmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#ifndef MBED_PINMAP_H
#define MBED_PINMAP_H

#include "pinnames.h"
#include "PinNames.h"

#ifdef __cplusplus
extern "C" {
Expand Down
Loading

0 comments on commit cff2753

Please sign in to comment.