pure sdk for main
This commit is contained in:
@@ -0,0 +1,538 @@
|
||||
#include "sys_config.h"
|
||||
#include "basic_include.h"
|
||||
#include "hal/netdev.h"
|
||||
#include "lib/atcmd/libatcmd.h"
|
||||
#include "lib/umac/ieee80211.h"
|
||||
#include "lib/bus/xmodem/xmodem.h"
|
||||
#include "lib/lmac/lmac_def.h"
|
||||
#if BLE_SUPPORT
|
||||
#include "lib/ble/ble_demo.h"
|
||||
#include "lib/ble/ble_def.h"
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_UMAC4
|
||||
#include "lwip/ip_addr.h"
|
||||
#include "lwip/icmp.h"
|
||||
#include "lwip/apps/lwiperf.h"
|
||||
#endif
|
||||
|
||||
#include "syscfg.h"
|
||||
|
||||
int32 sys_atcmd_loaddef(const char *cmd, char *argv[], uint32 argc)
|
||||
{
|
||||
syscfg_loaddef();
|
||||
atcmd_ok;
|
||||
mcu_reset();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32 sys_atcmd_goto_boot(const char *cmd, char *argv[], uint32 argc)
|
||||
{
|
||||
os_printf("system goto boot\r\n");
|
||||
|
||||
system_goto_boot();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32 sys_atcmd_reset(const char *cmd, char *argv[], uint32 argc)
|
||||
{
|
||||
atcmd_ok;
|
||||
|
||||
if (argc >= 1) {
|
||||
uint32 run_addr, reset_usb=0, param = 0;
|
||||
sys_errlog_flush(0xffffffff, 0, 0);
|
||||
disable_irq();
|
||||
mcu_watchdog_feed();
|
||||
if (argc >= 1) run_addr = os_atoh(argv[0]);
|
||||
if (argc >= 2) reset_usb = os_atoh(argv[1]);
|
||||
if (argc >= 3) param = os_atoh(argv[2]);
|
||||
mcu_watchdog_feed();
|
||||
// os_printf("reset addr=%08x, rst_usb=%d, param=%d\r\n", run_addr, reset_usb, param);
|
||||
if (reset_usb) {
|
||||
pmu_clr_direct_run_pengding2();
|
||||
} else {
|
||||
pmu_set_direct_run_pengding2();
|
||||
}
|
||||
|
||||
((void (*)(uint32))run_addr)(param);
|
||||
} else {
|
||||
mcu_reset();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32 sys_atcmd_jtag(const char *cmd, char *argv[], uint32 argc)
|
||||
{
|
||||
jtag_map_set(1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32 sys_syscfg_dump_hdl(const char *cmd, char *argv[], uint32 argc)
|
||||
{
|
||||
void syscfg_dump(void);
|
||||
syscfg_dump();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32 sys_heap_dump_hdl(const char *cmd, char *argv[], uint32 argc)
|
||||
{
|
||||
if(argc == 0){
|
||||
sysheap_dump(&sram_heap);
|
||||
}else{
|
||||
if(os_strcmp(argv[1], "psram") == 0){
|
||||
sysheap_dump(&psram_heap);
|
||||
}else{
|
||||
sysheap_dump(&sram_heap);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#ifdef CONFIG_UMAC4
|
||||
int32 sys_atcmd_ping(const char *cmd, char *argv[], uint32 argc) //need: #define LWIP_RAW 1
|
||||
{
|
||||
int32 loop_cnt = 10;
|
||||
int32 pkt_size = 32;
|
||||
if(argc > 0){
|
||||
if(argc > 1) loop_cnt = os_atoi(argv[1]);
|
||||
if(argc > 2) pkt_size = os_atoi(argv[2]);
|
||||
lwip_ping(argv[0], pkt_size, loop_cnt);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32 sys_atcmd_icmp_mntr(const char *cmd, char *argv[], uint32 argc)
|
||||
{
|
||||
struct netdev *ndev;
|
||||
if(argc == 2){
|
||||
ndev = (struct netdev *)dev_get(HG_WIFI0_DEVID + os_atoi(argv[0]));
|
||||
if(ndev){
|
||||
netdev_ioctl(ndev, NETDEV_IOCTL_ENABLE_ICMPMNTR, os_atoi(argv[1]), 0);
|
||||
return ATCMD_RESULT_OK;
|
||||
}
|
||||
}
|
||||
return ATCMD_RESULT_ERR;
|
||||
}
|
||||
|
||||
int32 sys_atcmd_iperf2(const char *cmd, char *argv[], uint32 argc)
|
||||
{
|
||||
int32 ret = 0;
|
||||
|
||||
if (argc == 1 && argv[0][0] == '?') {
|
||||
os_printf(" *********iperf usage*********\n");
|
||||
os_printf(" TCP client:at+iperf2=c,ip,port,time\n");
|
||||
os_printf(" TCP server:at+iperf2=s,port\n");
|
||||
os_printf(" UDP client:at+iperf2=u,c,ip,port,time,bandwidth,packet_len\n");
|
||||
os_printf(" UDP server:at+iperf2=u,s,port\n");
|
||||
os_printf(" *******************************\n");
|
||||
} else {
|
||||
if (argc > 0) {
|
||||
if(os_strlen(argv[0]) != 1) {
|
||||
os_printf("%s,%d:Invaild param1,must be c or s or u\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
if (argv[0][0] == 'c' || argv[0][0] == 'C') {
|
||||
if (argc < 4) {
|
||||
os_printf("TCP client mode requires 4 parameters: mode,ip,port,time\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
os_printf("%s:iperf2 TCP CLIENT mode,remote IP:%s,port:%d,time:%d\n",
|
||||
__FUNCTION__, argv[1], os_atoi(argv[2]), os_atoi(argv[3]));
|
||||
ret = sys_lwiperf_tcp_client_start(argv[1], os_atoi(argv[2]), os_atoi(argv[3]));
|
||||
} else if (argv[0][0] == 's' || argv[0][0] == 'S') {
|
||||
if (argc < 2) {
|
||||
os_printf("TCP server mode requires 2 parameters: mode port\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
os_printf("%s:iperf2 TCP Server mode,port:%d\n", __FUNCTION__, os_atoi(argv[1]));
|
||||
ret = sys_lwiperf_tcp_server_start(os_atoi(argv[1]));
|
||||
} else if (argv[0][0] == 'u' || argv[0][0] == 'U') {//UDP
|
||||
if (argc < 2) {
|
||||
os_printf("UDP mode requires at least 2 arguments.\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
if(os_strlen(argv[1]) != 1) {
|
||||
os_printf("%s,%d:Invaild param2,must be c or s\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
if (argv[1][0] == 'c' || argv[1][0] == 'C') {
|
||||
if (argc < 7) {
|
||||
os_printf("UDP client mode requires 7 parameters: u c ip port time bandwidth packet_len\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
os_printf("%s:iperf2 UDP CLIENT mode,remote IP:%s,port:%d,time:%d,bandwidth:%u,len:%d\n",
|
||||
__FUNCTION__,
|
||||
argv[2],//ip
|
||||
os_atoi(argv[3]), //port
|
||||
os_atoi(argv[4]), //time
|
||||
os_atoi(argv[5]),//bandwidth
|
||||
os_atoi(argv[6]));//packet_len
|
||||
ret = sys_lwiperf_udp_client_start(argv[2], os_atoi(argv[3]), os_atoi(argv[4]),
|
||||
os_atoi(argv[5]), os_atoi(argv[6]));//UDP CLIENT
|
||||
} else if (argv[1][0] == 's' || argv[1][0] == 'S') {
|
||||
if (argc < 3) {
|
||||
os_printf("UDP server mode requires 4 parameters: u s port\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
os_printf("%s:iperf2 UDP SERVER mode,port:%d\n",
|
||||
__FUNCTION__, os_atoi(argv[2])); //port
|
||||
ret = sys_lwiperf_udp_server_start(os_atoi(argv[2]));//UDP SERVER
|
||||
} else {
|
||||
os_printf("Unknow iperf udp mode:%s\n", argv[1]);
|
||||
return -ENOENT;
|
||||
}
|
||||
} else {
|
||||
os_printf("Unknow iperf mode:%s\n", argv[0]);
|
||||
return -ENOENT;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32 sys_wifi_atcmd_set_channel(const char *cmd, char *argv[], uint32 argc)
|
||||
{
|
||||
int32 chan = 0, chan_max;
|
||||
|
||||
if (argc == 1 && argv[0][0] == '?') {
|
||||
atcmd_resp("%d", ieee80211_conf_get_channel(sys_cfgs.wifi_mode));
|
||||
} else if (argc == 1) {
|
||||
chan = os_atoi(argv[0]);
|
||||
#ifdef TXW4002ACK803
|
||||
chan_max = 16;
|
||||
#else
|
||||
chan_max = 13;
|
||||
#endif
|
||||
if ((chan < 1) || (chan > chan_max)) {
|
||||
atcmd_printf("+CHANNEL: ERROR, INVALID CHANNEL %d\r\n", chan);
|
||||
return ATCMD_RESULT_DONE;
|
||||
}
|
||||
|
||||
if (sys_cfgs.wifi_mode == WIFI_MODE_AP) {
|
||||
ieee80211_conf_set_channel(WIFI_MODE_AP, chan);
|
||||
sys_cfgs.channel = ieee80211_conf_get_channel(WIFI_MODE_AP);
|
||||
} else if (sys_cfgs.wifi_mode == WIFI_MODE_STA || sys_cfgs.wifi_mode == WIFI_MODE_APSTA) {
|
||||
ieee80211_conf_set_channel(WIFI_MODE_STA, chan);
|
||||
sys_cfgs.channel = ieee80211_conf_get_channel(WIFI_MODE_STA);
|
||||
}
|
||||
syscfg_save();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32 sys_wifi_atcmd_set_encrypt(const char *cmd, char *argv[], uint32 argc)
|
||||
{
|
||||
int32 ret = -1;
|
||||
if (argc == 1 && argv[0][0] == '?') {
|
||||
if (sys_cfgs.key_mgmt == WPA_KEY_MGMT_NONE) {
|
||||
ret = 0;
|
||||
} else if (sys_cfgs.key_mgmt == WPA_KEY_MGMT_PSK) {
|
||||
ret = 1;
|
||||
} else if (sys_cfgs.key_mgmt == WPA_KEY_MGMT_SAE) {
|
||||
ret = 2;
|
||||
} else if (sys_cfgs.key_mgmt == WPA_KEY_MGMT_OWE) {
|
||||
ret = 3;
|
||||
}
|
||||
atcmd_resp("%d", ret);
|
||||
} else if (argc == 1) {
|
||||
if ('1' == argv[0][0]) {
|
||||
sys_cfgs.key_mgmt = WPA_KEY_MGMT_PSK;
|
||||
ieee80211_conf_set_keymgmt(sys_cfgs.wifi_mode, sys_cfgs.key_mgmt);
|
||||
syscfg_save();
|
||||
} else if ('2' == argv[0][0]) {
|
||||
sys_cfgs.key_mgmt = WPA_KEY_MGMT_SAE;
|
||||
ieee80211_conf_set_keymgmt(sys_cfgs.wifi_mode, sys_cfgs.key_mgmt);
|
||||
syscfg_save();
|
||||
} else if ('3' == argv[0][0]) {
|
||||
sys_cfgs.key_mgmt = WPA_KEY_MGMT_OWE;
|
||||
ieee80211_conf_set_keymgmt(sys_cfgs.wifi_mode, sys_cfgs.key_mgmt);
|
||||
syscfg_save();
|
||||
} else if ('0' == argv[0][0]) {
|
||||
sys_cfgs.key_mgmt = WPA_KEY_MGMT_NONE;
|
||||
ieee80211_conf_set_keymgmt(sys_cfgs.wifi_mode, sys_cfgs.key_mgmt);
|
||||
syscfg_save();
|
||||
} else {
|
||||
os_printf("encrypt atcmd err\r\n");
|
||||
return ATCMD_RESULT_ERR;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32 sys_wifi_atcmd_set_ssid(const char *cmd, char *argv[], uint32 argc)
|
||||
{
|
||||
if (argc == 1 && argv[0][0] == '?') {
|
||||
atcmd_resp("%s", sys_cfgs.ssid);
|
||||
} else if (argc == 1) {
|
||||
os_memset(sys_cfgs.bssid, 0, 6);
|
||||
os_strncpy(sys_cfgs.ssid, argv[0], SSID_MAX_LEN);
|
||||
ieee80211_conf_set_bssid(sys_cfgs.wifi_mode, NULL);
|
||||
if (os_strlen(sys_cfgs.passwd) > 0) {
|
||||
wpa_passphrase(sys_cfgs.ssid, sys_cfgs.passwd, sys_cfgs.psk);
|
||||
}
|
||||
ieee80211_conf_set_ssid(sys_cfgs.wifi_mode, sys_cfgs.ssid);
|
||||
ieee80211_conf_set_psk(sys_cfgs.wifi_mode, sys_cfgs.psk);
|
||||
os_printf("set new ssid:%s\r\n", sys_cfgs.ssid);
|
||||
syscfg_save();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32 sys_wifi_atcmd_set_key(const char *cmd, char *argv[], uint32 argc)
|
||||
{
|
||||
if (argc == 1 && argv[0][0] == '?') {
|
||||
atcmd_resp("%s", sys_cfgs.passwd);
|
||||
} else if (argc == 1) {
|
||||
// psk need 8 bytes at less
|
||||
if (os_strlen(argv[0]) < 8) {
|
||||
os_printf("psk need 8 bytes at less\r\n");
|
||||
return ATCMD_RESULT_ERR;
|
||||
} else {
|
||||
os_strncpy(sys_cfgs.passwd, argv[0], PASSWD_MAX_LEN);
|
||||
wpa_passphrase(sys_cfgs.ssid, sys_cfgs.passwd, sys_cfgs.psk);
|
||||
ieee80211_conf_set_psk(sys_cfgs.wifi_mode, sys_cfgs.psk);
|
||||
#ifdef CONFIG_SAE
|
||||
ieee80211_conf_set_passwd(sys_cfgs.wifi_mode, sys_cfgs.passwd);
|
||||
#endif
|
||||
os_printf("set new key:%s\r\n", sys_cfgs.passwd);
|
||||
syscfg_save();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32 sys_wifi_atcmd_set_wifimode(const char *cmd, char *argv[], uint32 argc)
|
||||
{
|
||||
if (argc == 1 && argv[0][0] == '?') {
|
||||
atcmd_resp("%s", sys_cfgs.wifi_mode == WIFI_MODE_AP ? "ap" : (sys_cfgs.wifi_mode == WIFI_MODE_APSTA ? "apsta" : "sta"));
|
||||
} else if (argc == 1) {
|
||||
if (os_strcasecmp(argv[0], "ap") == 0 && sys_cfgs.wifi_mode != WIFI_MODE_AP) {
|
||||
sys_cfgs.wifi_mode = WIFI_MODE_AP;
|
||||
ieee80211_iface_stop(WIFI_MODE_STA);
|
||||
wificfg_flush(WIFI_MODE_AP);
|
||||
netdev_set_wifi_mode((struct netdev *)dev_get(HG_WIFI0_DEVID), WIFI_MODE_AP);
|
||||
ieee80211_iface_start(WIFI_MODE_AP);
|
||||
} else if (os_strcasecmp(argv[0], "sta") == 0 && sys_cfgs.wifi_mode != WIFI_MODE_STA) {
|
||||
sys_cfgs.wifi_mode = WIFI_MODE_STA;
|
||||
ieee80211_iface_stop(WIFI_MODE_AP);
|
||||
wificfg_flush(WIFI_MODE_STA);
|
||||
netdev_set_wifi_mode((struct netdev *)dev_get(HG_WIFI0_DEVID), WIFI_MODE_STA);
|
||||
ieee80211_iface_start(WIFI_MODE_STA);
|
||||
} else if (os_strcasecmp(argv[0], "apsta") == 0 && sys_cfgs.wifi_mode != WIFI_MODE_APSTA) {
|
||||
sys_cfgs.wifi_mode = WIFI_MODE_APSTA;
|
||||
wificfg_flush(WIFI_MODE_AP);
|
||||
ieee80211_iface_start(WIFI_MODE_AP);
|
||||
wificfg_flush(WIFI_MODE_STA);
|
||||
netdev_set_wifi_mode((struct netdev *)dev_get(HG_WIFI0_DEVID), WIFI_MODE_APSTA);
|
||||
ieee80211_iface_start(WIFI_MODE_STA);
|
||||
}
|
||||
os_printf("set wifi mode:%s\r\n", argv[0]);
|
||||
syscfg_save();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32 sys_wifi_atcmd_loaddef(const char *cmd, char *argv[], uint32 argc)
|
||||
{
|
||||
syscfg_loaddef();
|
||||
mcu_reset();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32 sys_wifi_atcmd_scan(const char *cmd, char *argv[], uint32 argc)
|
||||
{
|
||||
if (argc == 2) {
|
||||
struct ieee80211_scandata scan;
|
||||
os_memset(&scan, 0, sizeof(scan));
|
||||
scan.chan_bitmap = 0xffff;
|
||||
scan.scan_cnt = os_atoi(argv[0]);
|
||||
scan.scan_time = os_atoi(argv[1]);
|
||||
ieee80211_scan(sys_cfgs.wifi_mode, 1, &scan);
|
||||
} else {
|
||||
ieee80211_scan(sys_cfgs.wifi_mode, 1, NULL);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32 sys_wifi_atcmd_pair(const char *cmd, char *argv[], uint32 argc)
|
||||
{
|
||||
uint32 magic = os_atoi(argv[0]);
|
||||
ieee80211_pairing(sys_cfgs.wifi_mode, magic);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32 sys_wifi_atcmd_aphide(const char *cmd, char *argv[], uint32 argc)
|
||||
{
|
||||
if (argc == 1 && argv[0][0] == '?') {
|
||||
atcmd_resp("%d", sys_cfgs.ap_hide);
|
||||
} else if (argc == 1) {
|
||||
sys_cfgs.ap_hide = os_atoi(argv[0]);
|
||||
ieee80211_conf_set_aphide(sys_cfgs.wifi_mode, sys_cfgs.ap_hide);
|
||||
syscfg_save();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32 sys_wifi_atcmd_hwmode(const char *cmd, char *argv[], uint32 argc)
|
||||
{
|
||||
if (argc == 1 && argv[0][0] == '?') {
|
||||
atcmd_resp("%d", sys_cfgs.wifi_hwmode);
|
||||
} else if (argc == 1) {
|
||||
sys_cfgs.wifi_hwmode = os_atoi(argv[0]);
|
||||
ieee80211_conf_set_hwmode(sys_cfgs.wifi_mode, sys_cfgs.wifi_hwmode);
|
||||
syscfg_save();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32 sys_ble_atcmd_blenc(const char *cmd, char *argv[], uint32 argc)
|
||||
{
|
||||
#if BLE_SUPPORT
|
||||
extern void *g_ops;
|
||||
|
||||
uint8 mode = 0;
|
||||
struct lmac_ops *lops = (struct lmac_ops *)g_ops;
|
||||
struct bt_ops *bt_ops = (struct bt_ops *)lops->btops;
|
||||
|
||||
if (argc == 1) {
|
||||
mode = os_atoi(argv[0]);
|
||||
switch (mode) {
|
||||
case 0:
|
||||
if (ble_demo_stop(bt_ops)) {
|
||||
return ATCMD_RESULT_ERR;
|
||||
} else {
|
||||
os_printf("\n\nble close \r\n\n");
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
if (ble_demo_start(bt_ops, mode - 1)) {
|
||||
return ATCMD_RESULT_ERR;
|
||||
} else {
|
||||
os_printf("\n\nset ble mode = %d \r\n\n", mode);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32 sys_wifi_atcmd_ft(const char *cmd, char *argv[], uint32 argc)
|
||||
{
|
||||
#ifdef CONFIG_IEEE80211R
|
||||
struct ieee80211_ft_param ft;
|
||||
uint8 ifidx = (sys_cfgs.wifi_mode == WIFI_MODE_APSTA ? WIFI_MODE_STA : sys_cfgs.wifi_mode);
|
||||
|
||||
os_memset(&ft, 0, sizeof(ft));
|
||||
str2mac(argv[0], ft.bssid_new);
|
||||
os_printf("FT_start: target_bssid= "MACSTR" argc= %d\r\n", MAC2STR(ft.bssid_new), argc);
|
||||
ieee80211_conf_set_ft(ifidx, &ft);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32 sys_ble_atcmd_set_coexist_en(const char *cmd, char *argv[], uint32 argc)
|
||||
{
|
||||
#if BLE_SUPPORT
|
||||
extern void *g_ops;
|
||||
uint8 coexist, dec_duty;
|
||||
|
||||
struct lmac_ops *lops = (struct lmac_ops *)g_ops;
|
||||
struct bt_ops *bt_ops = (struct bt_ops *)lops->btops;
|
||||
|
||||
if (argc == 1 && argv[0][0] == '?') {
|
||||
atcmd_resp("coexist,dec_duty");
|
||||
} else if (argc == 2) {
|
||||
coexist = os_atoi(argv[0]);
|
||||
dec_duty = os_atoi(argv[1]);
|
||||
if (ble_set_coexist_en(bt_ops, coexist, dec_duty)) {
|
||||
return ATCMD_RESULT_ERR;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32 sys_wifi_atcmd_wificsa(const char *cmd, char *argv[], uint32 argc)
|
||||
{
|
||||
if (argc == 4) {
|
||||
struct ieee80211_csa_param csa;
|
||||
csa.mode = os_atoi(argv[1]);
|
||||
csa.chan = os_atoi(argv[2]);
|
||||
csa.count = os_atoi(argv[3]);
|
||||
return ieee80211_conf_set_csa(os_atoi(argv[0]), &csa);
|
||||
}else{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if WIFI_REPEATER_SUPPORT
|
||||
int32 sys_wifi_atcmd_set_rssid(const char *cmd, char *argv[], uint32 argc)
|
||||
{
|
||||
if (argc == 1 && argv[0][0] == '?') {
|
||||
atcmd_resp("%s", sys_cfgs.r_ssid);
|
||||
} else if (argc == 1) {
|
||||
sys_cfgs.cfg_init = 1;
|
||||
os_strncpy(sys_cfgs.r_ssid, argv[0], SSID_MAX_LEN);
|
||||
wpa_passphrase(sys_cfgs.r_ssid, sys_cfgs.r_passwd, sys_cfgs.r_psk);
|
||||
syscfg_save();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32 sys_wifi_atcmd_set_rkey(const char *cmd, char *argv[], uint32 argc)
|
||||
{
|
||||
if (argc == 1 && argv[0][0] == '?') {
|
||||
atcmd_resp("%s", sys_cfgs.r_passwd);
|
||||
} else if (argc == 1) {
|
||||
// psk need 8 bytes at less
|
||||
if (os_strlen(argv[0]) < 8) {
|
||||
atcmd_printf("need 8 bytes at less\r\n");
|
||||
return ATCMD_RESULT_ERR;
|
||||
} else {
|
||||
sys_cfgs.cfg_init = 1;
|
||||
sys_cfgs.r_key_mgmt = sys_cfgs.key_mgmt;
|
||||
os_strncpy(sys_cfgs.r_passwd, argv[0], PASSWD_MAX_LEN);
|
||||
wpa_passphrase(sys_cfgs.r_ssid, sys_cfgs.r_passwd, sys_cfgs.r_psk);
|
||||
syscfg_save();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
int32 sys_wifi_atcmd_reboot_test_mode(const char *cmd, char *argv[], uint32 argc)
|
||||
{
|
||||
if (argc == 1 && argv[0][0] == '1') {
|
||||
system_reboot_test_mode();
|
||||
atcmd_ok;
|
||||
mcu_reset();
|
||||
} else {
|
||||
system_reboot_normal_mode();
|
||||
atcmd_ok;
|
||||
mcu_reset();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32 sys_wifi_atcmd_dhcpd_lease_time(const char *cmd, char *argv[], uint32 argc)
|
||||
{
|
||||
if (argc == 1 && argv[0][0] == '?') {
|
||||
atcmd_resp("%d", sys_cfgs.dhcpd_lease_time);
|
||||
} else if (argc == 1) {
|
||||
sys_cfgs.dhcpd_lease_time = os_atoi(argv[0]);
|
||||
os_printf("DHCP lease time set to %d\r\n", sys_cfgs.dhcpd_lease_time);
|
||||
syscfg_save();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,294 @@
|
||||
#include "sys_config.h"
|
||||
#include "typesdef.h"
|
||||
#include "errno.h"
|
||||
#include "list.h"
|
||||
#include "dev.h"
|
||||
#include "devid.h"
|
||||
#include "osal/task.h"
|
||||
#include "osal/sleep.h"
|
||||
#include "osal/string.h"
|
||||
#include "osal/irq.h"
|
||||
#include "hal/dma.h"
|
||||
#include "hal/crc.h"
|
||||
#include "lib/common/common.h"
|
||||
#include "lib/heap/sysheap.h"
|
||||
|
||||
extern void *krhino_mm_alloc(size_t size, void *caller);
|
||||
extern void krhino_mm_free(void *ptr);
|
||||
|
||||
__bobj uint64 cpu_loading_tick;
|
||||
#ifdef M2M_DMA
|
||||
__bobj struct dma_device *m2mdma;
|
||||
#endif
|
||||
|
||||
void cpu_loading_print(uint8 all, struct os_task_info *tsk_info, uint32 size)
|
||||
{
|
||||
uint32 i = 0;
|
||||
uint32 diff_tick = 0;
|
||||
uint32 irq_time = 0;
|
||||
uint32 count;
|
||||
uint64 jiff = os_jiffies();
|
||||
|
||||
if(tsk_info == NULL) return;
|
||||
diff_tick = DIFF_JIFFIES(cpu_loading_tick, jiff);
|
||||
cpu_loading_tick = jiff;
|
||||
|
||||
irq_time = irq_status();
|
||||
os_printf("--------------------------------------------------------------------\r\n");
|
||||
os_printf("Task Runtime Statistic, interval:%dms\r\n", os_jiffies_to_msecs(diff_tick));
|
||||
os_printf("PID Name %%CPU(Time) Stack Prio Status\r\n");
|
||||
os_printf("--------------------------------------------------------------------\r\n");
|
||||
if(irq_time > 0){
|
||||
count = 100 * os_msecs_to_jiffies(irq_time/1000);
|
||||
os_printf("SYS IRQ: %dms, %d%%\r\n", (irq_time/1000), (count/diff_tick));
|
||||
os_printf("--------------------------------------------------------------------\r\n");
|
||||
}
|
||||
|
||||
count = os_task_runtime(tsk_info, size);
|
||||
for (i = 0; i < count; i++) {
|
||||
if (tsk_info[i].time > 0 || all) {
|
||||
os_printf("%2d %-12s\t%2d%%(%6d) %4d %2d (%08x) %s\r\n",
|
||||
tsk_info[i].id,
|
||||
tsk_info[i].name ? tsk_info[i].name : "----",
|
||||
#ifdef CSKY_OS
|
||||
(tsk_info[i].time * 100) / diff_tick,
|
||||
#elif defined(OHOS)
|
||||
tsk_info[i].time,
|
||||
#endif
|
||||
|
||||
tsk_info[i].time,
|
||||
tsk_info[i].stack * 4,
|
||||
tsk_info[i].prio,
|
||||
tsk_info[i].arg,
|
||||
tsk_info[i].status);
|
||||
}
|
||||
}
|
||||
os_printf("--------------------------------------------------------------------\r\n");
|
||||
}
|
||||
|
||||
int strncasecmp(const char *s1, const char *s2, size_t n)
|
||||
{
|
||||
size_t i = 0;
|
||||
|
||||
for (i = 0; i < n && s1[i] && s2[i]; i++) {
|
||||
if (s1[i] == s2[i] || s1[i] + 32 == s2[i] || s1[i] - 32 == s2[i]) {
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return (i != n);
|
||||
}
|
||||
|
||||
int strcasecmp(const char *s1, const char *s2)
|
||||
{
|
||||
while (*s1 || *s2) {
|
||||
if (*s1 == *s2 || *s1 + 32 == *s2 || *s1 - 32 == *s2) {
|
||||
s1++; s2++;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef M2M_DMA
|
||||
void hw_memcpy(void *dest, const void *src, uint32 size)
|
||||
{
|
||||
if (dest && src) {
|
||||
if (m2mdma && size > 45) {
|
||||
#ifdef MEM_TRACE
|
||||
#ifdef PSRAM_HEAP
|
||||
struct sys_heap *heap = sysheap_valid_addr(&psram_heap, dest) ? &psram_heap : &sram_heap;
|
||||
#else
|
||||
struct sys_heap *heap = &sram_heap;
|
||||
#endif
|
||||
int32 ret = sysheap_of_check(heap, dest, size);
|
||||
if (ret == -1) {
|
||||
//os_printf("%s: WARING: OF CHECK 0x%x\r\n", dest, __FUNCTION__);
|
||||
} else {
|
||||
if (!ret) {
|
||||
os_printf("check addr fail: %x, size:%d \r\n", dest, size);
|
||||
}
|
||||
ASSERT(ret == 1);
|
||||
}
|
||||
#endif
|
||||
dma_memcpy(m2mdma, dest, src, size);
|
||||
} else {
|
||||
os_memcpy(dest, src, size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void hw_memcpy0(void *dest, const void *src, uint32 size)
|
||||
{
|
||||
if (m2mdma && size > 45) {
|
||||
#ifdef MEM_TRACE
|
||||
#ifdef PSRAM_HEAP
|
||||
struct sys_heap *heap = sysheap_valid_addr(&psram_heap, dest) ? &psram_heap : &sram_heap;
|
||||
#else
|
||||
struct sys_heap *heap = &sram_heap;
|
||||
#endif
|
||||
int32 ret = sysheap_of_check(heap, dest, size);
|
||||
if (ret == -1) {
|
||||
//os_printf("%s: WARING: OF CHECK 0x%x\r\n", dest, __FUNCTION__);
|
||||
} else {
|
||||
if (!ret) {
|
||||
os_printf("check addr fail: %x, size:%d \r\n", dest, size);
|
||||
}
|
||||
ASSERT(ret == 1);
|
||||
}
|
||||
#endif
|
||||
dma_memcpy(m2mdma, dest, src, size);
|
||||
} else {
|
||||
os_memcpy(dest, src, size);
|
||||
}
|
||||
}
|
||||
|
||||
void hw_memset(void *dest, uint8 val, uint32 n)
|
||||
{
|
||||
if (dest) {
|
||||
if (m2mdma && n > 12) {
|
||||
#ifdef MEM_TRACE
|
||||
#ifdef PSRAM_HEAP
|
||||
struct sys_heap *heap = sysheap_valid_addr(&psram_heap, dest) ? &psram_heap : &sram_heap;
|
||||
#else
|
||||
struct sys_heap *heap = &sram_heap;
|
||||
#endif
|
||||
int32 ret = sysheap_of_check(heap, dest, n);
|
||||
if (ret == -1) {
|
||||
//os_printf("%s: WARING: OF CHECK 0x%x\r\n", dest, __FUNCTION__);
|
||||
} else {
|
||||
if (!ret) {
|
||||
os_printf("check addr fail: %x, size:%d \r\n", dest, n);
|
||||
}
|
||||
ASSERT(ret == 1);
|
||||
}
|
||||
#endif
|
||||
dma_memset(m2mdma, dest, val, n);
|
||||
} else {
|
||||
os_memset(dest, val, n);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void *os_memdup(const void *ptr, uint32 len)
|
||||
{
|
||||
void *p;
|
||||
if (!ptr || len == 0) {
|
||||
return NULL;
|
||||
}
|
||||
p = os_malloc(len);
|
||||
if (p) {
|
||||
hw_memcpy(p, ptr, len);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
int32 os_random_bytes(uint8 *data, int32 len)
|
||||
{
|
||||
int32 i = 0;
|
||||
int32 seed;
|
||||
#ifdef TXW4002ACK803
|
||||
seed = csi_coret_get_value() ^ (csi_coret_get_value() << 8) ^ (csi_coret_get_value() >> 8);
|
||||
#else
|
||||
seed = csi_coret_get_value() ^ sysctrl_get_trng() ^ (sysctrl_get_trng() >> 8);
|
||||
#endif
|
||||
for (i = 0; i < len; i++) {
|
||||
seed = seed * 214013L + 2531011L;
|
||||
data[i] = (uint8)(((seed >> 16) & 0x7fff) & 0xff);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32 hw_crc(enum CRC_DEV_TYPE type, uint8 *data, uint32 len)
|
||||
{
|
||||
uint32 crc = 0xffff;
|
||||
struct crc_dev_req req;
|
||||
struct crc_dev *crcdev = (struct crc_dev *)dev_get(HG_CRC_DEVID);
|
||||
if (crcdev) {
|
||||
req.type = type;
|
||||
req.data = data;
|
||||
req.len = len;
|
||||
//ASSERT((uint32)data % 4 == 0); // crc模块数据地址必须4字节对齐检查
|
||||
crc_dev_calc(crcdev, &req, &crc, 0);
|
||||
} else {
|
||||
os_printf("no crc dev\r\n");
|
||||
crc = (uint32)os_jiffies();
|
||||
}
|
||||
return crc;
|
||||
}
|
||||
|
||||
int ffs(int x)
|
||||
{
|
||||
int r = 1;
|
||||
|
||||
if (!x) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!(x & 0xffff)) {
|
||||
x >>= 16;
|
||||
r += 16;
|
||||
}
|
||||
if (!(x & 0xff)) {
|
||||
x >>= 8;
|
||||
r += 8;
|
||||
}
|
||||
if (!(x & 0xf)) {
|
||||
x >>= 4;
|
||||
r += 4;
|
||||
}
|
||||
if (!(x & 3)) {
|
||||
x >>= 2;
|
||||
r += 2;
|
||||
}
|
||||
if (!(x & 1)) {
|
||||
x >>= 1;
|
||||
r += 1;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
int fls(int x)
|
||||
{
|
||||
int r = 32;
|
||||
|
||||
if (!x) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!(x & 0xffff0000u)) {
|
||||
x <<= 16;
|
||||
r -= 16;
|
||||
}
|
||||
if (!(x & 0xff000000u)) {
|
||||
x <<= 8;
|
||||
r -= 8;
|
||||
}
|
||||
if (!(x & 0xf0000000u)) {
|
||||
x <<= 4;
|
||||
r -= 4;
|
||||
}
|
||||
if (!(x & 0xc0000000u)) {
|
||||
x <<= 2;
|
||||
r -= 2;
|
||||
}
|
||||
if (!(x & 0x80000000u)) {
|
||||
x <<= 1;
|
||||
r -= 1;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
uint32 scatter_data_size(scatter_data *data, uint32 count)
|
||||
{
|
||||
uint32 size = 0;
|
||||
uint32 i = 0;
|
||||
for (i = 0; i < count; i++) {
|
||||
size += data[i].size;
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
#include "typesdef.h"
|
||||
#include "osal/irq.h"
|
||||
#include "osal/string.h"
|
||||
#include "lib/common/dsleepdata.h"
|
||||
|
||||
#ifdef CONFIG_SLEEP
|
||||
|
||||
struct system_sleepdata {
|
||||
uint32 magic1;
|
||||
uint32 cur_addr;
|
||||
uint32 regions[SYSTEM_SLEEPDATA_ID_MAX];
|
||||
uint32 magic2;
|
||||
};
|
||||
|
||||
extern size_t __sleep_data_start;
|
||||
extern size_t __sleep_data_stop;
|
||||
|
||||
__init void sys_sleepdata_init(void)
|
||||
{
|
||||
uint32 flags;
|
||||
uint32 start = (uint32)&__sleep_data_start;
|
||||
//uint32 end = (uint32)&__sleep_data_stop;
|
||||
struct system_sleepdata *sdata = (struct system_sleepdata *)start;
|
||||
flags = disable_irq();
|
||||
if (sdata->magic1 != 0x1A2B3C4D || sdata->magic2 != 0xD4C3B2A1) {
|
||||
dump_hex("sleepdata_init: ", ((uint8 *)&__sleep_data_stop) + 4 , 4, 1);
|
||||
os_memset(sdata, 0, sizeof(struct system_sleepdata));
|
||||
sdata->magic1 = 0x1A2B3C4D;
|
||||
sdata->magic2 = 0xD4C3B2A1;
|
||||
sdata->cur_addr = start + sizeof(struct system_sleepdata);
|
||||
}
|
||||
enable_irq(flags);
|
||||
}
|
||||
|
||||
void *sys_sleepdata_request(uint8 id, uint32 size)
|
||||
{
|
||||
void *ptr = NULL;
|
||||
uint32 flags;
|
||||
uint32 start = (uint32)&__sleep_data_start;
|
||||
uint32 end = (uint32)&__sleep_data_stop;
|
||||
struct system_sleepdata *sdata = (struct system_sleepdata *)start;
|
||||
|
||||
size = ALIGN(size, 4);
|
||||
flags = disable_irq();
|
||||
if (id < SYSTEM_SLEEPDATA_ID_MAX) {
|
||||
os_printf("regions(%d)=0x%x cur_addr=0x%x size=%d end=0x%x\r\n",
|
||||
id, sdata->regions[id], sdata->cur_addr, size, end);
|
||||
if (sdata->regions[id] == 0) {
|
||||
if (sdata->cur_addr + size < end) {
|
||||
os_memset(sdata->cur_addr, 0, size);
|
||||
sdata->regions[id] = sdata->cur_addr;
|
||||
sdata->cur_addr += size;
|
||||
}
|
||||
}
|
||||
ptr = (void *)sdata->regions[id];
|
||||
}
|
||||
enable_irq(flags);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
__dsleep_text void sys_sleepdata_reset(void)
|
||||
{
|
||||
uint32 flags;
|
||||
uint32 *start = (uint32 *)&__sleep_data_start;
|
||||
flags = disable_irq();
|
||||
*start = 0;
|
||||
enable_irq(flags);
|
||||
}
|
||||
|
||||
uint32 sys_sleepdata_freesize(void)
|
||||
{
|
||||
uint32 flags;
|
||||
uint32 fsize = 0;
|
||||
uint32 start = (uint32)&__sleep_data_start;
|
||||
uint32 end = (uint32)&__sleep_data_stop;
|
||||
struct system_sleepdata *sdata = (struct system_sleepdata *)start;
|
||||
|
||||
flags = disable_irq();
|
||||
fsize = end - sdata->cur_addr;
|
||||
enable_irq(flags);
|
||||
return fsize;
|
||||
}
|
||||
|
||||
void *sys_sleepdata_get(uint8 id)
|
||||
{
|
||||
uint32 start = (uint32)&__sleep_data_start;
|
||||
struct system_sleepdata *sdata = (struct system_sleepdata *)start;
|
||||
if (id < SYSTEM_SLEEPDATA_ID_MAX) {
|
||||
return (void *)sdata->regions[id];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,151 @@
|
||||
#include "typesdef.h"
|
||||
#include "list.h"
|
||||
#include "dev.h"
|
||||
#include "devid.h"
|
||||
#include "errno.h"
|
||||
#include "osal/irq.h"
|
||||
#include "osal/string.h"
|
||||
#include "lib/common/rbuffer.h"
|
||||
|
||||
int32 rbuffer_init(struct rbuffer *rb, uint32 size, void *buff)
|
||||
{
|
||||
ASSERT(buff && size > 1);
|
||||
os_memset(rb, 0, sizeof(struct rbuffer));
|
||||
rb->qsize = size;
|
||||
rb->rbq = buff;
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
void rbuffer_destroy(struct rbuffer *rb)
|
||||
{
|
||||
rbuffer_reset(rb);
|
||||
rb->qsize = 0;
|
||||
}
|
||||
|
||||
void rbuffer_reset(struct rbuffer *rb)
|
||||
{
|
||||
uint32 flag = disable_irq();
|
||||
rb->wpos = 0;
|
||||
rb->rpos = 0;
|
||||
enable_irq(flag);
|
||||
}
|
||||
|
||||
int32 rbuffer_set(struct rbuffer *rb, void *data, uint32 length)
|
||||
{
|
||||
uint32 len;
|
||||
uint32 rpos, wpos;
|
||||
uint32 flag;
|
||||
|
||||
if (rb->rbq == NULL) {
|
||||
return -ENOBUFS;
|
||||
}
|
||||
|
||||
flag = disable_irq();
|
||||
rpos = rb->rpos;
|
||||
wpos = rb->wpos;
|
||||
enable_irq(flag);
|
||||
|
||||
len = ((wpos < rpos) ? (rpos - wpos - 1) : ((rb)->qsize - wpos + rpos - 1));
|
||||
if (len < length) {
|
||||
return -ENOBUFS;
|
||||
}
|
||||
|
||||
if (wpos < rpos) {
|
||||
os_memcpy(rb->rbq + wpos, data, length);
|
||||
} else {
|
||||
len = rb->qsize - wpos;
|
||||
if (len < length) { //rewind
|
||||
os_memcpy(rb->rbq + wpos, data, len);
|
||||
os_memcpy(rb->rbq, data + len, length - len);
|
||||
} else {
|
||||
os_memcpy(rb->rbq + wpos, data, length);
|
||||
}
|
||||
}
|
||||
|
||||
wpos += length;
|
||||
if (wpos >= rb->qsize) {
|
||||
wpos -= rb->qsize;
|
||||
}
|
||||
|
||||
flag = disable_irq();
|
||||
rb->wpos = wpos;
|
||||
enable_irq(flag);
|
||||
return length;
|
||||
}
|
||||
|
||||
int32 rbuffer_set_force(struct rbuffer *rb, void *data, uint32 length)
|
||||
{
|
||||
uint32 flag;
|
||||
uint32 len;
|
||||
|
||||
if (rb->rbq == NULL || (rb->qsize - 1) < length) {
|
||||
return -ENOBUFS;
|
||||
}
|
||||
|
||||
flag = disable_irq();
|
||||
len = RB_IDLE(rb);
|
||||
if (len < length) {
|
||||
rb->rpos = RB_NPOS(rb, rpos, length - len);
|
||||
}
|
||||
enable_irq(flag);
|
||||
return rbuffer_set(rb, data, length);
|
||||
}
|
||||
|
||||
int32 rbuffer_get(struct rbuffer *rb, void *buff, uint32 size)
|
||||
{
|
||||
int32 len = 0; // right length
|
||||
int32 count = 0;
|
||||
uint32 rpos, wpos;
|
||||
uint32 flag;
|
||||
|
||||
flag = disable_irq();
|
||||
rpos = rb->rpos;
|
||||
wpos = rb->wpos;
|
||||
enable_irq(flag);
|
||||
|
||||
if (rb->rbq == NULL || rpos == wpos) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
count = ((rpos <= wpos) ? (wpos - rpos) : ((rb)->qsize - rpos + wpos));
|
||||
if (count > size) {
|
||||
count = size;
|
||||
}
|
||||
|
||||
if (rpos <= wpos) {
|
||||
os_memcpy(buff, rb->rbq + rpos, count);
|
||||
} else {
|
||||
len = rb->qsize - rpos;
|
||||
if (len >= count) {
|
||||
os_memcpy(buff, rb->rbq + rpos, count);
|
||||
} else {
|
||||
os_memcpy(buff, rb->rbq + rpos, len);
|
||||
os_memcpy(buff + len, rb->rbq, count - len);
|
||||
}
|
||||
}
|
||||
|
||||
rpos += count;
|
||||
if (rpos >= rb->qsize) {
|
||||
rpos -= rb->qsize;
|
||||
}
|
||||
|
||||
flag = disable_irq();
|
||||
rb->rpos = rpos;
|
||||
enable_irq(flag);
|
||||
return count;
|
||||
}
|
||||
|
||||
int32 rbuffer_alloc(struct rbuffer *rb, uint32 size)
|
||||
{
|
||||
void *buff = os_malloc(size);
|
||||
ASSERT(buff);
|
||||
return rbuffer_init(rb, size, buff);
|
||||
}
|
||||
|
||||
void rbuffer_free(struct rbuffer *rb)
|
||||
{
|
||||
rb->qsize = 0;
|
||||
os_free(rb->rbq);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,548 @@
|
||||
#include "basic_include.h"
|
||||
#include "lib/heap/sysheap.h"
|
||||
|
||||
#ifndef PRINT_LEVEL_DEFAULT
|
||||
#define PRINT_LEVEL_DEFAULT (6)
|
||||
#endif
|
||||
|
||||
#ifndef PRINT_BUFF_SIZE
|
||||
#define PRINT_BUFF_SIZE (256)
|
||||
#endif
|
||||
|
||||
__bobj static osprint_hook __print_hook;
|
||||
__bobj static void *__print_hook_priv;
|
||||
__bobj void *console_handle;
|
||||
__bobj int8 __disable_print__;
|
||||
__bobj int8 __disable_print_color__;
|
||||
__bobj int8 __print_level__;
|
||||
__bobj char _print_buff_p[PRINT_BUFF_SIZE];
|
||||
|
||||
static const char *__print_color__[] = {
|
||||
"\e[40;31;7m", //KERN_EMERG : Red
|
||||
"\e[40;31;7m", //KERN_ALERT : Red
|
||||
"\e[40;31;7m", //KERN_CRIT : Red
|
||||
"\e[40;31m", //KERN_ERR : Red
|
||||
"\e[40;33m", //KERN_WARNING: Yellow
|
||||
"\e[40;32m", //KERN_NOTICE : Green
|
||||
"\e[40;37m", //KERN_INFO : Default
|
||||
"\e[40;37m", //KERN_DEBUG : Default
|
||||
"\e[0m", //END
|
||||
};
|
||||
|
||||
int printf(const char *format, ...) __alias(hgprintf);
|
||||
int puts(const char *s) __alias(hgputs);
|
||||
int __wrap_printf(const char *format, ...) __alias(hgprintf);
|
||||
int __cskyvprintfprintf(const char *format, ...) __alias(hgprintf);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
int32 hexchr2int(char c)
|
||||
{
|
||||
if (c >= '0' && c <= '9') {
|
||||
return c - '0';
|
||||
}
|
||||
if (c >= 'a' && c <= 'f') {
|
||||
return c - 'a' + 10;
|
||||
}
|
||||
if (c >= 'A' && c <= 'F') {
|
||||
return c - 'A' + 10;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32 hex2char(char *hex_str)
|
||||
{
|
||||
int a, b;
|
||||
a = hexchr2int(*hex_str++);
|
||||
if (a < 0) {
|
||||
return -1;
|
||||
}
|
||||
b = hexchr2int(*hex_str++);
|
||||
if (b < 0) {
|
||||
return -1;
|
||||
}
|
||||
return (a << 4) | b;
|
||||
}
|
||||
|
||||
int32 hex2bin(char *hex_str, uint8 *bin, uint32 len)
|
||||
{
|
||||
uint32 i = 0;
|
||||
uint32 str_len = 0;
|
||||
int32 a;
|
||||
char *ipos = hex_str;
|
||||
uint8 *opos = bin;
|
||||
|
||||
if (!hex_str || !bin) {
|
||||
return i;
|
||||
}
|
||||
|
||||
str_len = os_strlen(hex_str);
|
||||
for (i = 0; i < len && (i * 2) + 2 <= str_len; i++) {
|
||||
a = hex2char(ipos);
|
||||
if (a < 0) {
|
||||
return i;
|
||||
}
|
||||
*opos++ = (uint8)a;
|
||||
ipos += 2;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
void str2mac(char *macstr, uint8 *mac)
|
||||
{
|
||||
mac[0] = hex2char(macstr);
|
||||
mac[1] = hex2char(macstr + 3);
|
||||
mac[2] = hex2char(macstr + 6);
|
||||
mac[3] = hex2char(macstr + 9);
|
||||
mac[4] = hex2char(macstr + 12);
|
||||
mac[5] = hex2char(macstr + 15);
|
||||
}
|
||||
|
||||
uint32 str2ip(char *ipstr)
|
||||
{
|
||||
char *ptr = ipstr;
|
||||
uint32 ip = os_atoi(ipstr);
|
||||
do {
|
||||
if (*ptr == '.') {
|
||||
ptr++;
|
||||
ip = (ip << 8 | os_atoi(ptr));
|
||||
}
|
||||
ptr++;
|
||||
} while (*ptr);
|
||||
return os_htonl(ip);
|
||||
}
|
||||
|
||||
uint64 _os_atoh(char *str, int8 count)
|
||||
{
|
||||
uint64 val = 0;
|
||||
int32 s = 0;
|
||||
int8 cnt = 1;
|
||||
|
||||
if (os_strlen(str) > 2 && str[0] == '0' && (str[1] == 'x' || str[1] == 'X')) {
|
||||
str += 2;
|
||||
}
|
||||
|
||||
while (*str && cnt++ <= count) {
|
||||
s = hexchr2int(*str);
|
||||
if (s == -1) {
|
||||
break;
|
||||
}
|
||||
val = (val << 4) + s;
|
||||
str++;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
|
||||
uint32 os_atoh(char *str)
|
||||
{
|
||||
return (uint32)_os_atoh(str, 8);
|
||||
}
|
||||
|
||||
uint64 os_atohl(char *str)
|
||||
{
|
||||
return _os_atoh(str, 16);
|
||||
}
|
||||
|
||||
char *os_strdup(const char *s)
|
||||
{
|
||||
size_t len;
|
||||
char *d;
|
||||
|
||||
if (s == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
len = strlen(s);
|
||||
d = os_malloc(len + 1);
|
||||
if (d == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
os_memcpy(d, s, len);
|
||||
d[len] = '\0';
|
||||
return d;
|
||||
}
|
||||
|
||||
void print_redirect(osprint_hook print, void *priv)
|
||||
{
|
||||
uint32 flag = disable_irq();
|
||||
__print_hook = print;
|
||||
__print_hook_priv = priv;
|
||||
enable_irq(flag);
|
||||
}
|
||||
|
||||
void print_level(int8 level)
|
||||
{
|
||||
__print_level__ = level;
|
||||
}
|
||||
|
||||
void disable_print(int8_t dis)
|
||||
{
|
||||
__disable_print__ = dis;
|
||||
}
|
||||
|
||||
void disable_print_color(int8 dis)
|
||||
{
|
||||
__disable_print_color__ = dis;
|
||||
}
|
||||
|
||||
static void hgprintf_uart(char *str, int32 len)
|
||||
{
|
||||
int32 off = 0;
|
||||
if (len == 0) { len = os_strlen(str); }
|
||||
while (off < len) {
|
||||
uart_putc((struct uart_device *)console_handle, str[off++]);
|
||||
}
|
||||
}
|
||||
|
||||
void hgprintf_out(char *str, int32 len, uint8 level)
|
||||
{
|
||||
osprint_hook _print;
|
||||
void *_print_priv;
|
||||
uint8 color = 0;
|
||||
|
||||
uint32 flag = disable_irq();
|
||||
_print_priv = __print_hook_priv;
|
||||
_print = __print_hook;
|
||||
enable_irq(flag);
|
||||
|
||||
if (__print_level__ && level > __print_level__) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (level > 7)
|
||||
level = 7;
|
||||
|
||||
if(level && !__disable_print_color__)
|
||||
color = level;
|
||||
|
||||
if (_print) {
|
||||
if (color) _print(_print_priv, (char *)__print_color__[color]);
|
||||
_print(_print_priv, str);
|
||||
if (color) _print(_print_priv, (char *)__print_color__[8]);
|
||||
} else {
|
||||
if (color) hgprintf_uart((char *)__print_color__[color], 0);
|
||||
hgprintf_uart(str, len);
|
||||
if (color) hgprintf_uart((char *)__print_color__[8], 0);
|
||||
}
|
||||
|
||||
if (color) sys_errlog_save((char *)__print_color__[color], 0, level);
|
||||
sys_errlog_save(str, len, level);
|
||||
if (color) sys_errlog_save((char *)__print_color__[8], 0, level);
|
||||
}
|
||||
|
||||
void hgvprintf(const char *fmt, va_list ap)
|
||||
{
|
||||
int32 ret = 0;
|
||||
int32 len = 0;
|
||||
uint8 level = 0;
|
||||
uint8 tick = 0;
|
||||
struct timeval tv;
|
||||
struct tm *tm_t;
|
||||
|
||||
if (__disable_print__) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (fmt[0] == 2) {
|
||||
tick = 1;
|
||||
fmt++;
|
||||
}
|
||||
|
||||
if (fmt[0] == 1) {
|
||||
level = fmt[1] - '0';
|
||||
fmt += 2;
|
||||
}
|
||||
|
||||
if (__print_level__ && level > __print_level__) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (tick) {
|
||||
gettimeofday(&tv, NULL);
|
||||
if (tv.tv_sec > 1704038400) {
|
||||
tv.tv_sec += 8 * 3600; //时区
|
||||
tm_t = localtime((time_t *)&tv.tv_sec);
|
||||
len = os_sprintf(_print_buff_p, "[%02d/%02d %02d:%02d:%02d-%03d]",
|
||||
(uint32)(tm_t->tm_mon + 1), (uint32)tm_t->tm_mday, (uint32)tm_t->tm_hour,
|
||||
(uint32)tm_t->tm_min, (uint32)tm_t->tm_sec, (uint32)(tv.tv_usec / 1000));
|
||||
} else {
|
||||
len = os_sprintf(_print_buff_p, "[%llu]", os_jiffies_to_msecs(os_jiffies()));
|
||||
}
|
||||
}
|
||||
|
||||
ret = vsnprintf(_print_buff_p + len, (PRINT_BUFF_SIZE - 2 - len), fmt, ap);
|
||||
if (ret < 0 || ret > (PRINT_BUFF_SIZE - 2 - len)) {
|
||||
len = PRINT_BUFF_SIZE - 1;
|
||||
_print_buff_p[len - 1] = '\n';
|
||||
_print_buff_p[len - 2] = '\r';
|
||||
} else {
|
||||
len += ret;
|
||||
}
|
||||
|
||||
if (len > 0) {
|
||||
if (_print_buff_p[len - 1] == '\n' && _print_buff_p[len - 2] != '\r') {
|
||||
_print_buff_p[len - 1] = '\r';
|
||||
_print_buff_p[len++] = '\n';
|
||||
}
|
||||
_print_buff_p[len] = 0;
|
||||
hgprintf_out(_print_buff_p, len, level);
|
||||
}
|
||||
}
|
||||
void hgprintf(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
hgvprintf(fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
int hgputs(const char *s)
|
||||
{
|
||||
hgprintf("%s", s);
|
||||
return os_strlen(s) + 1;
|
||||
}
|
||||
|
||||
void dump_hex(char *str, uint8 *data, uint32 len, int32 newline)
|
||||
{
|
||||
int i = 0;
|
||||
if (data && len) {
|
||||
if (str) _os_printf("%s", str);
|
||||
for (i = 0; i < len; i++) {
|
||||
if (i > 0 && newline) {
|
||||
if ((i & 0x7) == 0) _os_printf(" ");
|
||||
if ((i & 0xf) == 0) _os_printf("\r\n");
|
||||
}
|
||||
_os_printf("%02x ", data[i] & 0xFF);
|
||||
}
|
||||
_os_printf("\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
void dump_key(char *str, uint8 *key, uint32 len, uint32 sp)
|
||||
{
|
||||
int32 i = 0;
|
||||
if (key && len) {
|
||||
if (str) _os_printf("%s", str);
|
||||
for (i = 0; i < len; i++) {
|
||||
if (sp) {
|
||||
_os_printf("%02x ", key[i]);
|
||||
} else {
|
||||
_os_printf("%02x", key[i]);
|
||||
}
|
||||
}
|
||||
_os_printf("\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
void dump_memory(char *title, uint32 *data, uint32 len)
|
||||
{
|
||||
int i = 0;
|
||||
if (data && len) {
|
||||
if (title) _os_printf("%s", title);
|
||||
for (i = 0; i < len; i++) {
|
||||
if ((i & 0x7) == 0) _os_printf("0x%x: ", data+i);
|
||||
if ((i & 0x7) == 7) _os_printf("\r\n");
|
||||
_os_printf("%x ", data[i]);
|
||||
}
|
||||
_os_printf("\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
// str_buf申请的空间需要比key_len多1byte,sprintf会额外在字符串结束添加0
|
||||
void key_str(uint8 *key, uint32 key_len, uint8 *str_buf)
|
||||
{
|
||||
int32 i = 0;
|
||||
for (i = 0; i < key_len; i++) {
|
||||
os_sprintf(str_buf + i * 2, "%02x", key[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void *_os_memcpy(void *str1, const void *str2, int32 n)
|
||||
{
|
||||
#ifdef PSRAM_HEAP
|
||||
struct sys_heap *heap = sysheap_valid_addr(&psram_heap, str1) ? &psram_heap : &sram_heap;
|
||||
#else
|
||||
struct sys_heap *heap = &sram_heap;
|
||||
#endif
|
||||
|
||||
int32 ret = sysheap_of_check(heap, str1, n);
|
||||
if (ret == -1) {
|
||||
//os_printf("%s: WARING: OF CHECK 0x%x\r\n", str1, __FUNCTION__);
|
||||
} else {
|
||||
if (!ret) {
|
||||
os_printf("check addr fail: %x, size:%d \r\n", str1, n);
|
||||
}
|
||||
ASSERT(ret == 1);
|
||||
}
|
||||
return memcpy(str1, str2, n);
|
||||
}
|
||||
|
||||
char *_os_strcpy(char *dest, const char *src)
|
||||
{
|
||||
#ifdef PSRAM_HEAP
|
||||
struct sys_heap *heap = sysheap_valid_addr(&psram_heap, dest) ? &psram_heap : &sram_heap;
|
||||
#else
|
||||
struct sys_heap *heap = &sram_heap;
|
||||
#endif
|
||||
|
||||
int32 n = strlen(src) + 1; // +'\0'
|
||||
int32 ret = sysheap_of_check(heap, dest, n);
|
||||
if (ret == -1) {
|
||||
//os_printf("%s: WARING: OF CHECK 0x%x\r\n", dest, __FUNCTION__);
|
||||
} else {
|
||||
if (!ret) {
|
||||
os_printf("check addr fail: %x, size:%d \r\n", dest, n);
|
||||
}
|
||||
ASSERT(ret == 1);
|
||||
}
|
||||
return strcpy(dest, src);
|
||||
}
|
||||
|
||||
void *_os_memset(void *str, int c, int32 n)
|
||||
{
|
||||
#ifdef PSRAM_HEAP
|
||||
struct sys_heap *heap = sysheap_valid_addr(&psram_heap, str) ? &psram_heap : &sram_heap;
|
||||
#else
|
||||
struct sys_heap *heap = &sram_heap;
|
||||
#endif
|
||||
|
||||
int32 ret = sysheap_of_check(heap, str, n);
|
||||
if (ret == -1) {
|
||||
//os_printf("%s: WARING: OF CHECK 0x%x\r\n", str, __FUNCTION__);
|
||||
} else {
|
||||
if (!ret) {
|
||||
os_printf("check addr fail: %x, size:%d \r\n", str, n);
|
||||
}
|
||||
ASSERT(ret == 1);
|
||||
}
|
||||
return memset(str, c, n);
|
||||
}
|
||||
|
||||
void *_os_memmove(void *str1, const void *str2, size_t n)
|
||||
{
|
||||
#ifdef PSRAM_HEAP
|
||||
struct sys_heap *heap = sysheap_valid_addr(&psram_heap, str1) ? &psram_heap : &sram_heap;
|
||||
#else
|
||||
struct sys_heap *heap = &sram_heap;
|
||||
#endif
|
||||
|
||||
int32 ret = sysheap_of_check(heap, str1, n);
|
||||
if (ret == -1) {
|
||||
//os_printf("%s: WARING: OF CHECK 0x%x\r\n", str1, __FUNCTION__);
|
||||
} else {
|
||||
if (!ret) {
|
||||
os_printf("check addr fail: %x, size:%d \r\n", str1, n);
|
||||
}
|
||||
ASSERT(ret == 1);
|
||||
}
|
||||
return memmove(str1, str2, n);
|
||||
}
|
||||
|
||||
char *_os_strncpy(char *dest, const char *src, int32 n)
|
||||
{
|
||||
#ifdef PSRAM_HEAP
|
||||
struct sys_heap *heap = sysheap_valid_addr(&psram_heap, dest) ? &psram_heap : &sram_heap;
|
||||
#else
|
||||
struct sys_heap *heap = &sram_heap;
|
||||
#endif
|
||||
|
||||
int32 ret = sysheap_of_check(heap, dest, n);
|
||||
if (ret == -1) {
|
||||
//os_printf("%s: WARING: OF CHECK 0x%x\r\n", dest, __FUNCTION__);
|
||||
} else {
|
||||
ASSERT(ret == 1);
|
||||
if (!ret) {
|
||||
os_printf("check addr fail: %x, size:%d \r\n", dest, n);
|
||||
}
|
||||
}
|
||||
return strncpy(dest, src, n);
|
||||
}
|
||||
|
||||
int _os_sprintf(char *str, const char *format, ...)
|
||||
{
|
||||
#ifdef PSRAM_HEAP
|
||||
struct sys_heap *heap = sysheap_valid_addr(&psram_heap, str) ? &psram_heap : &sram_heap;
|
||||
#else
|
||||
struct sys_heap *heap = &sram_heap;
|
||||
#endif
|
||||
|
||||
int ret, len, check_len;
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, format);
|
||||
len = vsprintf(str, format, ap);
|
||||
va_end(ap);
|
||||
check_len = len + 1; // +'\0'
|
||||
ret = sysheap_of_check(heap, str, check_len);
|
||||
if (ret == 0) {
|
||||
os_printf("check addr fail: %x, size:%d \r\n", str, len);
|
||||
ASSERT(ret == 1);
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
int _os_vsnprintf(char *s, size_t n, const char *format, va_list arg)
|
||||
{
|
||||
#ifdef PSRAM_HEAP
|
||||
struct sys_heap *heap = sysheap_valid_addr(&psram_heap, s) ? &psram_heap : &sram_heap;
|
||||
#else
|
||||
struct sys_heap *heap = &sram_heap;
|
||||
#endif
|
||||
|
||||
int len = vsnprintf(s, n, format, arg);
|
||||
int check_len = (len < n) ? len + 1 : n;
|
||||
int ret = sysheap_of_check(heap, s, check_len);
|
||||
if (ret == 0) {
|
||||
os_printf("check addr fail: %x, size:%d \r\n", s, len);
|
||||
ASSERT(ret == 1);
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
int _os_snprintf(char *str, size_t size, const char *format, ...)
|
||||
{
|
||||
#ifdef PSRAM_HEAP
|
||||
struct sys_heap *heap = sysheap_valid_addr(&psram_heap, str) ? &psram_heap : &sram_heap;
|
||||
#else
|
||||
struct sys_heap *heap = &sram_heap;
|
||||
#endif
|
||||
|
||||
int ret, len;
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, format);
|
||||
len = vsnprintf(str, size, format, ap);
|
||||
va_end(ap);
|
||||
int check_len = len = (len < size) ? len + 1 : size;
|
||||
ret = sysheap_of_check(heap, str, check_len);
|
||||
if (ret == 0) {
|
||||
os_printf("check addr fail: %x, size:%d \r\n", str, len);
|
||||
ASSERT(ret == 1);
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
int32 os_strtok(char *str, char *separator, char *argv[], int argv_size)
|
||||
{
|
||||
int32 cnt = 0;
|
||||
char *ptr = str;
|
||||
|
||||
if (str == NULL || separator == NULL || argv == NULL || argv_size <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
argv[cnt++] = ptr;
|
||||
ptr = os_strstr(ptr, separator);
|
||||
while (ptr && cnt < argv_size) {
|
||||
*ptr = 0;
|
||||
ptr += os_strlen(separator);
|
||||
if (os_strlen(ptr) == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
argv[cnt++] = ptr;
|
||||
ptr = os_strstr(ptr, separator);
|
||||
}
|
||||
return cnt;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
#include "typesdef.h"
|
||||
#include "list.h"
|
||||
#include "dev.h"
|
||||
#include "devid.h"
|
||||
#include "osal/sleep.h"
|
||||
#include "hal/timer_device.h"
|
||||
#include "lib/common/ticker_api.h"
|
||||
|
||||
void os_sleep_us(int us)
|
||||
{
|
||||
uint32 ms = us / 1000;
|
||||
us = us % 1000;
|
||||
if (ms > 0) {
|
||||
os_sleep_ms(ms);
|
||||
}
|
||||
delay_us(us);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user