Merge branch 'prepare_for_master' of https://gitlink.org.cn/xuos/xiuos into prepare_for_master

This commit is contained in:
huang 2023-09-11 11:19:52 +08:00
commit 4d2e4498cc
112 changed files with 8457 additions and 2366 deletions

View File

@ -72,6 +72,24 @@ menu "test app"
endif
endif
menuconfig USER_TEST_SOCKET
select BSP_USING_LWIP
bool "Config test socket(lwip)"
default n
menuconfig USER_TEST_UART
select BSP_USING_UART
select BSP_USING_UART6
bool "Config test uart"
default n
if USER_TEST_UART
if ADD_XIZI_FEATURES
config UART_DEV_DRIVER
string "Set uart dev path"
default "/dev/usart6_dev6"
endif
endif
menuconfig USER_TEST_RS485
select BSP_USING_UART
select BSP_USING_GPIO

View File

@ -46,7 +46,16 @@ ifeq ($(CONFIG_ADD_XIZI_FEATURES),y)
endif
ifeq ($(CONFIG_USER_TEST_I2C),y)
SRC_FILES += test_i2c.c
ifeq ($(CONFIG_BOARD_EDU_RISCV64_EVB),y)
SRC_FILES += test_i2c_riscv.c
endif
ifeq ($(CONFIG_BOARD_EDU_ARM32_EVB),y)
SRC_FILES += test_i2c_arm.c
endif
endif
ifeq ($(CONFIG_USER_TEST_UART),y)
SRC_FILES += test_uart.c
endif
ifeq ($(CONFIG_USER_TEST_GPIO),y)
@ -62,7 +71,12 @@ ifeq ($(CONFIG_ADD_XIZI_FEATURES),y)
endif
ifeq ($(CONFIG_USER_TEST_RS485),y)
SRC_FILES += test_rs485.c
ifeq ($(CONFIG_BOARD_EDU_RISCV64_EVB),y)
SRC_FILES += test_rs485_riscv.c
endif
ifeq ($(CONFIG_BOARD_EDU_ARM32_EVB),y)
SRC_FILES += test_rs485_arm.c
endif
endif
ifeq ($(CONFIG_USER_TEST_HWTIMER),y)
@ -113,6 +127,10 @@ ifeq ($(CONFIG_ADD_XIZI_FEATURES),y)
SRC_FILES += test_rbtree/test_rbtree.c
endif
ifeq ($(CONFIG_USER_TEST_SOCKET),y)
SRC_FILES += test_socket.c
endif
ifeq ($(CONFIG_USER_TEST_WEBSERVER),y)
SRC_FILES +=
endif

View File

@ -22,7 +22,7 @@
#include <transform.h>
#ifdef ADD_XIZI_FEATURES
#define BSP_LED_PIN 134
#define BSP_LED_PIN 29
#define NULL_PARAMETER 0
static uint16_t pin_fd=0;
@ -37,7 +37,7 @@ void LedFlip(void *parameter)
void TestHwTimer(void)
{
x_ticks_t period = 100000;
x_ticks_t period = 1;
pin_fd = PrivOpen(HWTIMER_PIN_DEV_DRIVER, O_RDWR);
if(pin_fd<0) {

View File

@ -57,7 +57,7 @@ void TestMasterI2c(void)
{
char recv_buff[13] = { 0 };
int iic_fd = open_iic();
int iic_fd = OpenIic();
if (iic_fd < 0) {
printf("[%s] Error open iic\n", __func__);
return;
@ -78,7 +78,7 @@ void TestSlaveI2c(void)
{
char send_buff[] = "Hello, World";
int iic_fd = open_iic();
int iic_fd = OpenIic();
for (int transmit_cnt = 0; transmit_cnt < nr_transmit; transmit_cnt++) {
// wait if you like.

View File

@ -0,0 +1,81 @@
/*
* Copyright (c) 2020 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file: test_i2c.c
* @brief: a application of i2c function
* @version: 1.1
* @author: AIIT XUOS Lab
* @date: 2022/12/17
*/
#include <stdio.h>
#include <string.h>
#include <transform.h>
#include <sleep.h>
#ifdef ADD_XIZI_FEATURES
#define I2C_SLAVE_ADDRESS (0x44U)
void TestI2C(void)
{
// config IIC pin(SCL:34.SDA:35) in menuconfig
int iic_fd = PrivOpen(I2C_DEV_DRIVER, O_RDWR);
if (iic_fd < 0)
{
printf("open iic_fd fd error:%d\n", iic_fd);
return;
}
printf("IIC open successful!\n");
// init iic
uint16 iic_address = I2C_SLAVE_ADDRESS;
struct PrivIoctlCfg ioctl_cfg;
ioctl_cfg.ioctl_driver_type = I2C_TYPE;
ioctl_cfg.args = (void *)&iic_address;
if (0 != PrivIoctl(iic_fd, OPE_INT, &ioctl_cfg))
{
printf("ioctl iic fd error %d\n", iic_fd);
PrivClose(iic_fd);
return;
}
printf("IIC configure successful!\n");
// I2C read and write
uint8_t data[32];
while (1)
{
PrivWrite(iic_fd, NONE, 0);
msleep(40);
PrivRead(iic_fd, data, 4);
float result = ((data[2] << 8 | data[3]) >> 2) * 165.0 /( (1 << 14) - 1) - 40.0;
int temperature = result*10;
printf("Temperature : %d.%d ℃\n", temperature/10, temperature%10);
result = ((data[0] << 8 | data[1] ) & 0x3fff) * 100.0 / ( (1 << 14) - 1);
int humidity = result*10;
printf("Humidity : %d.%d %%RH\n", humidity/10, humidity%10);
printf("HS300X origin data1:0x%2x%2x%2x%2x\n", data[0],data[1],data[2],data[3]);
msleep(1000);
}
PrivClose(iic_fd);
return;
}
PRIV_SHELL_CMD_FUNCTION(TestI2C, a iic test sample, PRIV_SHELL_CMD_MAIN_ATTR);
#endif

View File

@ -0,0 +1,173 @@
/*
* Copyright (c) 2020 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file: test_rs485.c
* @brief: a application of rs485 function
* @version: 1.1
* @author: AIIT XUOS Lab
* @date: 2022/12/17
*/
#include <stdio.h>
#include <string.h>
#include <transform.h>
#ifdef ADD_XIZI_FEATURES
//edu-arm board dir pin PG01----no.67 in XiZi_IIoT/board/edu_arm32/third_party_driver/gpio/connect_gpio.c
#define BSP_485_DIR_PIN 67
static int pin_fd;
static int uart_fd;
static char write_485_data[] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
static char read_485_data[8] = {0};
/**
* @description: Set Uart 485 Input
* @return
*/
static void Set485Input(void)
{
struct PinStat pin_stat;
pin_stat.pin = BSP_485_DIR_PIN;
pin_stat.val = GPIO_LOW;
PrivWrite(pin_fd, &pin_stat, 1);
}
/**
* @description: Set Uart 485 Output
* @return
*/
static void Set485Output(void)
{
struct PinStat pin_stat;
pin_stat.pin = BSP_485_DIR_PIN;
pin_stat.val = GPIO_HIGH;
PrivWrite(pin_fd, &pin_stat, 1);
}
/**
* @description: Control Framework Serial Write
* @param write_data - write data
* @param length - length
* @return
*/
void Rs485Write(uint8_t *write_data, int length)
{
Set485Output();
PrivTaskDelay(20);
PrivWrite(uart_fd, write_data, length);
PrivTaskDelay(15);
Set485Input();
}
/**
* @description: Control Framework Serial Read
* @param read_data - read data
* @param length - length
* @return read data size
*/
int Rs485Read(uint8_t *read_data, int length)
{
int data_size = 0;
int data_recv_size = 0;
while (data_size < length) {
data_recv_size = PrivRead(uart_fd, read_data + data_size, length - data_size);
data_size += data_recv_size;
}
//need to wait 30ms , make sure write cmd again and receive data successfully
PrivTaskDelay(30);
return data_size;
}
void Test485(void)
{
int read_data_length = 0;
pin_fd = PrivOpen(RS485_PIN_DEV_DRIVER, O_RDWR);
if (pin_fd < 0) {
printf("open pin fd error:%d\n", pin_fd);
return;
}
uart_fd = PrivOpen(RS485_UART_DEV_DRIVER, O_RDWR);
if (uart_fd < 0) {
printf("open pin fd error:%d\n", uart_fd);
return;
}
printf("uart and pin fopen success\n");
//config dir pin in board
struct PinParam pin_parameter;
memset(&pin_parameter, 0, sizeof(struct PinParam));
pin_parameter.cmd = GPIO_CONFIG_MODE;
pin_parameter.pin = BSP_485_DIR_PIN;
pin_parameter.mode = GPIO_CFG_OUTPUT;
struct PrivIoctlCfg ioctl_cfg;
ioctl_cfg.ioctl_driver_type = PIN_TYPE;
ioctl_cfg.args = (void *)&pin_parameter;
if (0 != PrivIoctl(pin_fd, OPE_CFG, &ioctl_cfg)) {
printf("ioctl pin fd error %d\n", pin_fd);
PrivClose(pin_fd);
return;
}
struct SerialDataCfg uart_cfg;
memset(&uart_cfg, 0, sizeof(struct SerialDataCfg));
uart_cfg.serial_baud_rate = BAUD_RATE_115200;
uart_cfg.serial_data_bits = DATA_BITS_8;
uart_cfg.serial_stop_bits = STOP_BITS_1;
uart_cfg.serial_parity_mode = PARITY_NONE;
uart_cfg.serial_bit_order = BIT_ORDER_LSB;
uart_cfg.serial_invert_mode = NRZ_NORMAL;
uart_cfg.serial_buffer_size = SERIAL_RB_BUFSZ;
uart_cfg.serial_timeout = -1;
uart_cfg.is_ext_uart = 0;
ioctl_cfg.ioctl_driver_type = SERIAL_TYPE;
ioctl_cfg.args = (void *)&uart_cfg;
if (0 != PrivIoctl(uart_fd, OPE_INT, &ioctl_cfg)) {
printf("ioctl uart fd error %d\n", uart_fd);
PrivClose(uart_fd);
return;
}
Rs485Write(write_485_data, sizeof(write_485_data));
while(1) {
printf("ready to read data\n");
read_data_length = Rs485Read(read_485_data, sizeof(read_485_data));
printf("%s read data length %d\n", __func__, read_data_length);
for (int i = 0; i < read_data_length; i ++) {
printf("i %d read data 0x%x\n", i, read_485_data[i]);
}
Rs485Write(read_485_data, read_data_length);
memset(read_485_data, 0, sizeof(read_485_data));
printf("read data done\n");
}
PrivClose(pin_fd);
PrivClose(uart_fd);
return;
}
PRIV_SHELL_CMD_FUNCTION(Test485, a RS485 test sample, PRIV_SHELL_CMD_MAIN_ATTR);
#endif

View File

@ -88,15 +88,16 @@ void Test485(void)
pin_dir.val = GPIO_HIGH;
PrivWrite(pin_fd,&pin_dir,0);
PrivWrite(uart_fd,"Hello world!\n",sizeof("Hello world!\n"));
PrivTaskDelay(100);
printf("Send: Hello world!\n");
PrivTaskDelay(1000);
pin_dir.val = GPIO_LOW;
PrivWrite(pin_fd,&pin_dir,0);
char recv_buff[100];
memset(recv_buff,0,sizeof(recv_buff));
PrivRead(uart_fd,recv_buff,20);
printf("%s",recv_buff);
PrivTaskDelay(100);
printf("Recv: %s\n",recv_buff);
PrivTaskDelay(1000);
}
PrivClose(pin_fd);
PrivClose(uart_fd);

View File

@ -0,0 +1,347 @@
/*
* Copyright (c) 2020 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
#include <argparse.h>
#include <stdbool.h>
#include <transform.h>
#include "lwip/sockets.h"
#include "sys_arch.h"
#define IPERF_PORT 5001
#define IPERF_BUFSZ (4 * 1024)
enum IperfMode {
IPERF_MODE_STOP = (1 << 0),
IPERF_MODE_SERVER = (1 << 1),
IPERF_MODE_CLIENT = (1 << 2),
};
struct AtomicIperfMode {
/* pthread_mutex_t here is a int */
pthread_mutex_t mtx;
enum IperfMode mode;
};
static struct AtomicIperfMode* GetGlobalIperfMode()
{
/* init when used */
static struct AtomicIperfMode g_iperf_mode = {
-1,
IPERF_MODE_STOP,
};
if (g_iperf_mode.mtx < 0) {
/* mtx is a static obj, so there is only creation but not destruction */
PrivMutexCreate(&g_iperf_mode.mtx, NULL);
/* init lwip if necessary */
lwip_config_tcp(0, lwip_ipaddr, lwip_netmask, lwip_gwaddr);
}
return &g_iperf_mode;
}
static enum IperfMode GetGlobalMode()
{
enum IperfMode mode = IPERF_MODE_STOP;
struct AtomicIperfMode* g_mode = GetGlobalIperfMode();
PrivMutexObtain(&g_mode->mtx);
mode = g_mode->mode;
PrivMutexAbandon(&g_mode->mtx);
return mode;
}
static void SetGlobalMode(enum IperfMode mode)
{
struct AtomicIperfMode* g_mode = GetGlobalIperfMode();
PrivMutexObtain(&g_mode->mtx);
g_mode->mode = mode;
PrivMutexAbandon(&g_mode->mtx);
}
struct IperfParam {
char host[16];
int port;
};
static void* TestIperfServer(void* param)
{
struct IperfParam* iperf_param = (struct IperfParam*)param;
int sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock < 0) {
printf("[%s] Err: Can't create socker.\n", __func__);
return NULL;
}
uint8_t* recv_data = (uint8_t*)malloc(IPERF_BUFSZ);
if (recv_data == NULL) {
KPrintf("[%s] No memory to alloc buffer!\n", __func__);
goto __exit;
}
struct sockaddr_in server_addr, client_addr;
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(iperf_param->port);
server_addr.sin_addr.s_addr = INADDR_ANY;
memset(&(server_addr.sin_zero), 0x0, sizeof(server_addr.sin_zero));
if (bind(sock, (struct sockaddr*)&server_addr, sizeof(struct sockaddr)) == -1) {
KPrintf("[%s] Err: Unable to bind socket: %d!\n", __func__, sock);
goto __exit;
}
if (listen(sock, 5) == -1) {
KPrintf("[%s] Err: Listen error!\n", __func__);
goto __exit;
}
struct timeval timeout = {
.tv_sec = 3,
.tv_usec = 0,
};
fd_set readset;
while (GetGlobalMode() == IPERF_MODE_SERVER) {
FD_ZERO(&readset);
FD_SET(sock, &readset);
if (select(sock + 1, &readset, NULL, NULL, &timeout) == 0) {
continue;
}
socklen_t sin_size = sizeof(struct sockaddr_in);
struct sockaddr_in client_addr;
int connection = accept(sock, (struct sockaddr*)&client_addr, &sin_size);
printf("[%s] Info: New client connected from (%s, %d)\n", __func__,
inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port));
int flag = 1;
setsockopt(connection,
IPPROTO_TCP, /* set option at TCP level */
TCP_NODELAY, /* name of option */
(void*)&flag, /* the cast is historical cruft */
sizeof(int)); /* length of option value */
int recvlen = 0;
int tick_beg = PrivGetTickTime();
int tick_end = tick_beg;
while (GetGlobalMode() == IPERF_MODE_SERVER) {
int bytes_received = recv(connection, recv_data, IPERF_BUFSZ, 0);
if (bytes_received == 0) {
KPrintf("client disconnected (%s, %d)\n",
inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port));
break;
} else if (bytes_received < 0) {
KPrintf("recv error, client: (%s, %d)\n",
inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port));
break;
}
recvlen += bytes_received;
tick_end = PrivGetTickTime();
if (tick_end - tick_beg >= 5000) {
double speed;
// int integer, decimal;
speed = (double)(recvlen / (tick_end - tick_beg));
speed = speed / 1000.0f;
printf("[%s]: %2.4f MBps!\n", __func__, speed);
tick_beg = tick_end;
recvlen = 0;
}
}
if (connection >= 0)
closesocket(connection);
connection = -1;
}
__exit:
if (sock >= 0)
closesocket(sock);
if (recv_data)
free(recv_data);
return NULL;
}
static void* TestIperfClient(void* param)
{
struct IperfParam* iperf_param = (struct IperfParam*)param;
uint8_t* send_buf
= (uint8_t*)malloc(IPERF_BUFSZ);
if (NONE == send_buf) {
printf("[%s] Err: Unable to alloc buffer\n", __func__);
return NULL;
}
for (int i = 0; i < IPERF_BUFSZ; i++) {
send_buf[i] = i & 0xff;
}
struct sockaddr_in addr;
while (GetGlobalMode() == IPERF_MODE_CLIENT) {
int sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock < 0) {
printf("[%s] Warning: Can't create socker.\n", __func__);
PrivTaskDelay(1000);
continue;
}
addr.sin_family = PF_INET;
addr.sin_port = htons(iperf_param->port);
addr.sin_addr.s_addr = inet_addr((char*)iperf_param->host);
int ret = connect(sock, (const struct sockaddr*)&addr, sizeof(addr));
if (ret == -1) {
printf("[%s] Warning: Connect to iperf server faile, Waiting for the server to open!\n", __func__);
closesocket(sock);
DelayKTask(TICK_PER_SECOND);
continue;
}
printf("[%s] Connect to iperf server successful!\n", __func__);
int flag = 1;
setsockopt(sock,
IPPROTO_TCP, /* set option at TCP level */
TCP_NODELAY, /* name of option */
(void*)&flag, /* the cast is historical cruft */
sizeof(int)); /* length of option value */
int tick_beg = PrivGetTickTime();
int tick_end = tick_beg;
int sentlen = 0;
while (GetGlobalMode() == IPERF_MODE_CLIENT) {
tick_end = PrivGetTickTime();
/* Print every 5 second */
if (tick_end - tick_beg >= 5000) {
double speed;
speed = (double)(sentlen / (tick_end - tick_beg));
speed = speed / 1000.0f;
printf("[%s]: %2.4f MBps!\n", __func__, speed);
tick_beg = tick_end;
sentlen = 0;
}
ret = send(sock, send_buf, IPERF_BUFSZ, 0);
if (ret > 0) {
sentlen += ret;
}
if (ret < 0)
break;
}
closesocket(sock);
printf("[%s] Info: Disconnected, iperf server shut down!\n", __func__);
}
free(send_buf);
return NULL;
}
enum IperfParamEnum {
IPERF_PARAM_SERVER = 's',
IPERF_PARAM_CLIENT = 'c',
IPERF_PARAM_STOP = 0,
IPERF_PARAM_IPADDR = 0,
IPERF_PARAM_PORT = 'p',
};
void TestSocket(int argc, char* argv[])
{
lwip_config_tcp(0, lwip_ipaddr, lwip_netmask, lwip_gwaddr);
static char usage_info[] = "Run either a iperf server or iperf client.";
static char program_info[] = "Lwip socket test task, a simple iperf.";
static const char* const usages[] = {
"TestIperf -c [--ip arg] [-p arg]",
"TestIperf -s [-p arg]",
NULL,
};
static struct IperfParam iperf_param = {
.host = "255.255.255.255",
.port = 5001,
};
enum IperfMode mode = 0;
char* ip_ptr = NULL;
bool is_help = false;
struct argparse_option options[] = {
OPT_HELP(&is_help),
OPT_GROUP("Bit Options"),
OPT_BIT(IPERF_PARAM_SERVER, "server", &mode, "start a iperf server", NULL, IPERF_MODE_SERVER, 0),
OPT_BIT(IPERF_PARAM_CLIENT, "client", &mode, "start a iperf client", NULL, IPERF_MODE_CLIENT, 0),
OPT_BIT(IPERF_PARAM_STOP, "stop", &mode, "stop iperf", NULL, IPERF_MODE_STOP, OPT_NONEG),
OPT_GROUP("Param Options"),
OPT_STRING(IPERF_PARAM_IPADDR, "ip", &ip_ptr, "server IP if iperf is a client", NULL, 0, 0),
OPT_INTEGER(IPERF_PARAM_PORT, "port", &iperf_param.port, "server PORT needed for iperf", NULL, 0, 0),
OPT_END(),
};
struct argparse argparse;
argparse_init(&argparse, options, usages, 0);
argparse_describe(&argparse, usage_info, program_info);
argc = argparse_parse(&argparse, argc, (const char**)argv);
/* help task */
if (is_help) {
return;
}
/* stop iperf task */
if (mode & IPERF_MODE_STOP) {
SetGlobalMode(IPERF_MODE_STOP);
return;
}
if (mode & IPERF_MODE_SERVER && mode & IPERF_MODE_CLIENT) {
printf("[%s] Err: Can't run iperf server and client at one time.\n", __func__);
}
/* iperf server or iperf client*/
struct AtomicIperfMode* iperf_mode = GetGlobalIperfMode();
PrivMutexObtain(&iperf_mode->mtx);
if (iperf_mode->mode != IPERF_MODE_STOP) {
PrivMutexAbandon(&iperf_mode->mtx);
printf("[%s] Err: There is already a iperf running, please stop it before running a new one\n", __func__);
return;
}
if (mode & IPERF_MODE_SERVER) {
iperf_mode->mode = IPERF_MODE_SERVER;
} else if (mode & IPERF_MODE_CLIENT) {
if (ip_ptr == NONE) {
PrivMutexAbandon(&iperf_mode->mtx);
printf("[%s] Err: Iperf client must assign a server ip.\n", __func__);
return;
} else {
memset(iperf_param.host, 0, sizeof(iperf_param.host));
strncpy(iperf_param.host, ip_ptr, sizeof(iperf_param.host));
}
iperf_mode->mode = IPERF_MODE_CLIENT;
}
PrivMutexAbandon(&iperf_mode->mtx);
pthread_t thd;
mode = GetGlobalMode();
if (mode == IPERF_MODE_SERVER) {
printf("[%s] Running iperf server at port %d.\n", __func__, iperf_param.port);
PrivTaskCreate(&thd, NULL, TestIperfServer, (void*)&iperf_param);
} else if (mode == IPERF_MODE_CLIENT) {
printf("[%s] Running iperf client to server at %s:%d.\n", __func__, iperf_param.host, iperf_param.port);
PrivTaskCreate(&thd, NULL, TestIperfClient, (void*)&iperf_param);
}
PrivTaskStartup(&thd);
}
PRIV_SHELL_CMD_FUNCTION(TestSocket, Test socket using iperf, PRIV_SHELL_CMD_MAIN_ATTR | SHELL_CMD_PARAM_NUM(8));

View File

@ -0,0 +1,95 @@
/*
* Copyright (c) 2020 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file: test_uart.c
* @brief: a application of uart function, uart6 for edu-arm32
* @version: 3.0
* @author: AIIT XUOS Lab
* @date: 2023/8/11
*/
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <transform.h>
#include <argparse.h>
#ifdef ADD_XIZI_FEATURES
void TestUart(int argc, char* argv[])
{
static char program_info[] = "App Test uart, sending a message through uart and receive messages from uart.";
static const char* const usages[] = {
"TestUart -m arg",
NULL,
};
bool is_help = false;
char* msg = NULL;
struct argparse_option options[] = {
OPT_HELP(&is_help),
OPT_STRING('m', "message", &msg, "MESSAGE to send through uart.", NULL, 0, 0),
OPT_END(),
};
struct argparse argparse;
argparse_init(&argparse, options, usages, 0);
argparse_describe(&argparse, NULL, program_info);
argc = argparse_parse(&argparse, argc, (const char**)argv);
if (is_help) {
return;
}
int uart_fd = PrivOpen(UART_DEV_DRIVER, O_RDWR);
if (uart_fd < 0) {
printf("open pin fd error:%d\n", uart_fd);
return;
}
printf("[%s] Info: Uart and pin fopen success\n", __func__);
struct SerialDataCfg uart_cfg;
memset(&uart_cfg, 0, sizeof(struct SerialDataCfg));
uart_cfg.serial_baud_rate = BAUD_RATE_115200;
uart_cfg.serial_data_bits = DATA_BITS_8;
uart_cfg.serial_stop_bits = STOP_BITS_1;
uart_cfg.serial_parity_mode = PARITY_NONE;
uart_cfg.serial_bit_order = BIT_ORDER_LSB;
uart_cfg.serial_invert_mode = NRZ_NORMAL;
uart_cfg.serial_buffer_size = SERIAL_RB_BUFSZ;
uart_cfg.serial_timeout = -1;
uart_cfg.is_ext_uart = 0;
struct PrivIoctlCfg ioctl_cfg;
ioctl_cfg.ioctl_driver_type = SERIAL_TYPE;
ioctl_cfg.args = (void*)&uart_cfg;
if (0 != PrivIoctl(uart_fd, OPE_INT, &ioctl_cfg)) {
printf("[%s] Err: ioctl uart fd error %d\n", __func__, uart_fd);
PrivClose(uart_fd);
return;
}
PrivWrite(uart_fd, msg, strlen(msg));
char recv_buf[100];
while (1) {
memset(recv_buf, 0, sizeof(recv_buf));
PrivRead(uart_fd, recv_buf, sizeof(recv_buf));
printf("[%s] Info: Recv from uart: %s\n", __func__, recv_buf);
}
PrivClose(uart_fd);
return;
}
PRIV_SHELL_CMD_FUNCTION(TestUart, a uart test sample, PRIV_SHELL_CMD_MAIN_ATTR);
#endif

View File

@ -1,5 +1,5 @@
#include <cstdio>
#include <transform.h>
// #include <transform.h>
#include <stdio.h>
#include "tensorflow/lite/micro/all_ops_resolver.h"

View File

@ -26,3 +26,4 @@ void mnist_app(void);
int tfmnist(void) {
mnist_app();
}
PRIV_SHELL_CMD_FUNCTION(tfmnist, a tenorflow_lite_for_microcontroller sample, PRIV_SHELL_CMD_FUNC_ATTR);

View File

@ -24,23 +24,10 @@
#include "lv_demo_calendar.h"
#include <transform.h>
// extern void lv_example_chart_2(void);
// extern void lv_example_img_1(void);
// extern void lv_example_img_2(void);
// extern void lv_example_img_3(void);
// extern void lv_example_img_4(void);
// extern void lv_example_line_1(void);
// extern void lv_example_aoteman(void);
extern void lv_example_show(void);
void* lvgl_thread(void *parameter)
{
/* display demo; you may replace with your LVGL application at here */
lv_demo_calendar();
// lv_example_img_1();
// lv_example_chart_2();
// lv_example_table_1();
// lv_example_line_1();
// lv_example_aoteman();
/* handle the tasks of LVGL */
lv_example_show();
while(1)
{
lv_task_handler();
@ -48,12 +35,12 @@ void* lvgl_thread(void *parameter)
}
}
pthread_t lvgl_task;
static pthread_t lvgl_task;
static int lvgl_demo_init(void)
{
pthread_attr_t attr;
attr.schedparam.sched_priority = 25;
attr.stacksize = 4096;
attr.stacksize = 8192;
PrivTaskCreate(&lvgl_task, &attr, lvgl_thread, NULL);

View File

@ -52,7 +52,7 @@ int lv_port_init(void)
#endif
#ifndef PKG_USING_LVGL_INDEV_DEVICE
lv_port_indev_init();
// lv_port_indev_init();
#endif
return 0;

View File

@ -17,12 +17,21 @@
extern int FrameworkInit();
extern void ApplicationOtaTaskInit(void);
#ifdef OTA_BY_PLATFORM
extern int OtaTask(void);
#endif
int main(void)
{
printf("Hello, world! \n");
FrameworkInit();
printf("Hello, world! \n");
FrameworkInit();
#ifdef APPLICATION_OTA
ApplicationOtaTaskInit();
ApplicationOtaTaskInit();
#endif
#ifdef OTA_BY_PLATFORM
OtaTask();
#endif
return 0;
}

View File

@ -28,10 +28,14 @@ void TvocTb600bTvoc10(void)
{
struct SensorQuantity *tvoc = SensorQuantityFind(SENSOR_QUANTITY_TB600B_TVOC, SENSOR_QUANTITY_TVOC);
SensorQuantityOpen(tvoc);
int32_t result = 0;
result = SensorQuantityReadValue(tvoc);
for(int i = 0; i < 10;i++)
{
PrivTaskDelay(1000);
SensorQuantityReadValue(tvoc);
}
printf("tvoc concentration is : %dppb\n", result);
SensorQuantityClose(tvoc);
}
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0),tvoc, TvocTb600bTvoc10, read data from tvoc sensor);

View File

@ -39,7 +39,7 @@ void* ttf_thread(void *parameter)
}
}
pthread_t lvgl_task;
static pthread_t lvgl_task;
static int ttf_demo_init(void)
{
pthread_attr_t attr;

View File

@ -23,7 +23,7 @@ if ADD_XIZI_FEATURES
config ADAPTER_EC200T_DRIVER
string "EC200T device uart driver path"
default "/dev/usart2_dev2"
default "/dev/uart8_dev8"
depends on !ADAPTER_EC200T_DRIVER_EXTUART
if ADAPTER_EC200T_DRIVER_EXTUART

View File

@ -163,8 +163,12 @@ static int Ec200tIoctl(struct Adapter *adapter, int cmd, void *args)
serial_cfg.serial_parity_mode = PARITY_NONE;
serial_cfg.serial_bit_order = STOP_BITS_1;
serial_cfg.serial_invert_mode = NRZ_NORMAL;
#ifdef TOOL_USING_OTA
serial_cfg.serial_timeout = OTA_RX_TIMEOUT;
#else
//serial receive timeout 10s
serial_cfg.serial_timeout = 10000;
serial_cfg.serial_timeout = 100000;
#endif
serial_cfg.is_ext_uart = 0;
#ifdef ADAPTER_EC200T_DRIVER_EXT_PORT
serial_cfg.is_ext_uart = 1;

View File

@ -6,7 +6,7 @@ menuconfig SUPPORT_CONNECTION_FRAMEWORK
if SUPPORT_CONNECTION_FRAMEWORK
config CONNECTION_FRAMEWORK_DEBUG
bool "Using connection framework debug log function"
default y
default n
menuconfig CONNECTION_INDUSTRIAL_NETWORK
bool "Using industrial network"

View File

@ -124,7 +124,9 @@ int ParseATReply(char *str, const char *format, ...)
void ATSprintf(int fd, const char *format, va_list params)
{
last_cmd_len = vsnprintf(send_buf, sizeof(send_buf), format, params);
#ifdef CONNECTION_FRAMEWORK_DEBUG
printf("AT send %s len %u\n",send_buf, last_cmd_len);
#endif
PrivWrite(fd, send_buf, last_cmd_len);
}
@ -264,29 +266,34 @@ int AtSetReplyCharNum(ATAgentType agent, unsigned int num)
int EntmSend(ATAgentType agent, const char *data, int len)
{
char send_buf[128];
if(len > 128){
printf("send length %d more then max 128 Bytes.\n",len);
if(len > 256){
printf("send length %d more then max 256 Bytes.\n",len);
return -1;
}
char *send_buff = (char *)PrivMalloc(256);
PrivMutexObtain(&agent->lock);
memset(send_buf, 0, 128);
memset(send_buff, 0, 256);
agent->receive_mode = ENTM_MODE;
memcpy(send_buf, data, len);
// memcpy(send_buf + len, "!@", 2);
memcpy(send_buff, data, len);
PrivWrite(agent->fd, send_buf, len);
PrivWrite(agent->fd, send_buff, len);
PrivMutexAbandon(&agent->lock);
printf("entm send %s length %d\n",send_buf, len);
#ifdef CONNECTION_FRAMEWORK_DEBUG
printf("entm send length %d\n", len);
#endif
PrivFree(send_buff);
return 0;
}
int EntmRecv(ATAgentType agent, char *rev_buffer, int buffer_len, int timeout_s)
{
struct timespec abstime;
uint32 real_recv_len = 0;
abstime.tv_sec = timeout_s;
if(buffer_len > ENTM_RECV_MAX){
@ -299,21 +306,25 @@ int EntmRecv(ATAgentType agent, char *rev_buffer, int buffer_len, int timeout_s)
PrivMutexAbandon(&agent->lock);
//PrivTaskDelay(1000);
if (PrivSemaphoreObtainWait(&agent->entm_rx_notice, &abstime)) {
#ifdef CONNECTION_FRAMEWORK_DEBUG
printf("wait sem[%d] timeout\n",agent->entm_rx_notice);
#endif
agent->entm_recv_len = 0;
return -1;
}
PrivMutexObtain(&agent->lock);
#ifdef CONNECTION_FRAMEWORK_DEBUG
printf("EntmRecv once len %d.\n", agent->entm_recv_len);
#endif
memcpy(rev_buffer, agent->entm_recv_buf, agent->entm_recv_len);
memset(agent->entm_recv_buf, 0, ENTM_RECV_MAX);
real_recv_len = agent->entm_recv_len;
agent->entm_recv_len = 0;
agent->read_len = 0;
PrivMutexAbandon(&agent->lock);
return buffer_len;
return real_recv_len;
}
static int GetCompleteATReply(ATAgentType agent)
@ -321,21 +332,22 @@ static int GetCompleteATReply(ATAgentType agent)
uint32_t read_len = 0;
char ch = 0, last_ch = 0;
bool is_full = false;
int res;
PrivMutexObtain(&agent->lock);
memset(agent->maintain_buffer, 0x00, agent->maintain_max);
agent->maintain_len = 0;
memset(agent->entm_recv_buf, 0x00, 256);
memset(agent->entm_recv_buf, 0x00, ENTM_RECV_MAX);
agent->entm_recv_len = 0;
PrivMutexAbandon(&agent->lock);
while (1) {
PrivRead(agent->fd, &ch, 1);
res = PrivRead(agent->fd, &ch, 1);
#ifdef CONNECTION_FRAMEWORK_DEBUG
if(ch != 0) {
if((res == 1) && (ch != 0)) {
printf(" %c (0x%x)\n", ch, ch);
}
#endif
@ -343,14 +355,28 @@ static int GetCompleteATReply(ATAgentType agent)
PrivMutexObtain(&agent->lock);
if (agent->receive_mode == ENTM_MODE) {
if (agent->entm_recv_len < ENTM_RECV_MAX) {
agent->entm_recv_buf[agent->entm_recv_len] = ch;
agent->entm_recv_len++;
if(agent->entm_recv_len < agent->read_len) {
#ifdef TOOL_USING_MQTT
if((res == 1) && (agent->entm_recv_len < agent->read_len))
{
agent->entm_recv_buf[agent->entm_recv_len] = ch;
agent->entm_recv_len++;
PrivMutexAbandon(&agent->lock);
continue;
} else {
}
#else
agent->entm_recv_buf[agent->entm_recv_len] = ch;
agent->entm_recv_len++;
if(agent->entm_recv_len < agent->read_len)
{
PrivMutexAbandon(&agent->lock);
continue;
}
#endif
else
{
#ifdef CONNECTION_FRAMEWORK_DEBUG
printf("ENTM_MODE recv %d Bytes done.\n",agent->entm_recv_len);
#endif
agent->receive_mode = DEFAULT_MODE;
PrivSemaphoreAbandon(&agent->entm_rx_notice);
}

View File

@ -28,6 +28,12 @@
#define REPLY_TIME_OUT 10
#ifdef TOOL_USING_OTA
#define ENTM_RECV_MAX OTA_RX_BUFFERSIZE
#else
#define ENTM_RECV_MAX 256
#endif
enum ReceiveMode
{
DEFAULT_MODE = 0,
@ -70,7 +76,6 @@ struct ATAgent
#endif
pthread_t at_handler;
#define ENTM_RECV_MAX 256
char entm_recv_buf[ENTM_RECV_MAX];
uint32 entm_recv_len;
enum ReceiveMode receive_mode;

View File

@ -129,6 +129,9 @@ uint8_t lora_recv_data[ADAPTER_LORA_TRANSFER_DATA_LENGTH];
struct LoraDataFormat client_recv_data_format[ADAPTER_LORA_CLIENT_NUM];
static sem_t gateway_recv_data_sem;
static sem_t gateway_send_cmd_sem;
static sem_t client_recv_cmd_sem;
static sem_t client_send_data_sem;
struct LoraDataFormat gateway_recv_data_format;
static int recv_error_cnt = 0;
@ -315,6 +318,8 @@ static int LoraGatewaySendCmd(struct Adapter *adapter, uint8_t client_id, uint16
return -1;
}
PrivSemaphoreAbandon(&gateway_send_cmd_sem);
return 0;
}
@ -410,6 +415,7 @@ static int LoraClientSendData(struct Adapter *adapter, void *send_buf, int lengt
return -1;
}
PrivSemaphoreAbandon(&client_send_data_sem);
return 0;
}
@ -462,7 +468,7 @@ static int LoraClientDataAnalyze(struct Adapter *adapter, void *send_buf, int le
struct timespec abstime;
abstime.tv_sec = DEFAULT_SEM_TIMEOUT;
ret = PrivSemaphoreObtainWait(&adapter->sem, &abstime);
ret = PrivSemaphoreObtainWait(&client_recv_cmd_sem, NULL);
if (0 == ret) {
//only handle this client_id information from gateway
if ((client_recv_data_format[client_id - 1].client_id == adapter->net_role_id) &&
@ -653,9 +659,15 @@ static int LoraReceiveDataCheck(struct Adapter *adapter, uint8_t *recv_data, uin
static void *LoraReceiveTask(void *parameter)
{
int ret = 0;
struct timespec abstime;
abstime.tv_sec = DEFAULT_SEM_TIMEOUT;
struct Adapter *lora_adapter = (struct Adapter *)parameter;
while (1) {
#ifdef AS_LORA_GATEWAY_ROLE
PrivSemaphoreObtainWait(&gateway_send_cmd_sem, NULL);
#endif
memset(lora_recv_data, 0, ADAPTER_LORA_TRANSFER_DATA_LENGTH);
ret = AdapterDeviceRecv(lora_adapter, lora_recv_data, ADAPTER_LORA_TRANSFER_DATA_LENGTH);
@ -675,8 +687,10 @@ static void *LoraReceiveTask(void *parameter)
if (ret < 0) {
continue;
}
PrivSemaphoreAbandon(&lora_adapter->sem);
#ifdef AS_LORA_CLIENT_ROLE
PrivSemaphoreAbandon(&client_recv_cmd_sem);
PrivSemaphoreObtainWait(&client_send_data_sem, &abstime);
#endif
}
return 0;
@ -702,7 +716,7 @@ void LoraGatewayProcess(struct Adapter *lora_adapter, struct LoraGatewayParam *g
printf("LoraGatewaySendCmd client ID %d error\n", gateway->client_id[i]);
continue;
}
ret = PrivSemaphoreObtainWait(&gateway_recv_data_sem, &abstime);
if (0 == ret) {
printf("LoraGatewayProcess receive client %d data done\n", gateway->client_id[i]);
@ -904,9 +918,13 @@ int AdapterLoraInit(void)
adapter->done = product_info->model_done;
#endif
PrivSemaphoreCreate(&adapter->sem, 0, 0);
#ifdef AS_LORA_GATEWAY_ROLE
PrivSemaphoreCreate(&gateway_recv_data_sem, 0, 0);
PrivSemaphoreCreate(&gateway_send_cmd_sem, 0, 0);
#else//AS_LORA_CLIENT_ROLE
PrivSemaphoreCreate(&client_recv_cmd_sem, 0, 0);
PrivSemaphoreCreate(&client_send_data_sem, 0, 0);
#endif
PrivMutexCreate(&adapter->lock, 0);
@ -944,9 +962,9 @@ int AdapterLoraTest(void)
PrivTaskStartup(&lora_recv_data_task);
#ifdef ADD_NUTTX_FEATURES
lora_gateway_attr.priority = 19;
lora_gateway_attr.priority = 20;
#else
lora_gateway_attr.schedparam.sched_priority = 19;
lora_gateway_attr.schedparam.sched_priority = 20;
#endif
PrivTaskCreate(&lora_gateway_task, &lora_gateway_attr, &LoraGatewayTask, (void *)adapter);
@ -966,9 +984,9 @@ int AdapterLoraTest(void)
PrivTaskStartup(&lora_recv_data_task);
#ifdef ADD_NUTTX_FEATURES
lora_client_attr.priority = 19;
lora_client_attr.priority = 20;
#else
lora_client_attr.schedparam.sched_priority = 19;
lora_client_attr.schedparam.sched_priority = 20;
#endif
//create lora client task

View File

@ -67,7 +67,7 @@ typedef enum
struct ControlDevice
{
char *dev_name;
char dev_name[20];
int status;
//to do

View File

@ -180,7 +180,7 @@ int SerialRead(uint8_t *read_data, int length)
int data_recv_size = 0;
while (data_size < length) {
data_recv_size = PrivRead(uart_fd, read_data + data_recv_size, length);
data_recv_size = PrivRead(uart_fd, read_data + data_size, length - data_size);
data_size += data_recv_size;
}
@ -190,3 +190,33 @@ int SerialRead(uint8_t *read_data, int length)
return data_size;
#endif
}
int ControlFileDataStore(uint8 *data, int data_length)
{
int data_file_fd = -1;
struct stat data_file_status;
int i = 0;
//Step1 : open data file from SD card or other store device
data_file_fd = PrivOpen(FILE_NAME, O_RDONLY);
if (data_file_fd < 0) {
printf("Open data file %s failed\n", FILE_NAME);
PrivClose(data_file_fd);
return -1;
}
if (0 != fstat(data_file_fd, &data_file_status)) {
printf("Get data file information failed!\n");
PrivClose(data_file_fd);
return -1;
}
lseek(data_file_fd, data_file_status.st_size, SEEK_SET);
//Step2 : write data to file in SD card or other store device
FatfsPrintf(GetFileDescriptor(data_file_fd), data, data_length);
//Step3 : close data file from SD card or other store device
PrivClose(data_file_fd);
return 0;
}

View File

@ -48,6 +48,9 @@ extern "C" {
#endif
#endif
#define FILE_NAME "plc_data.csv"
extern void FatfsPrintf(struct FileDescriptor *fdp, const void *src, size_t len);
/*Control Framework Socket Init*/
void SocketInit(char *ip, char *mask, char *gw);
@ -60,6 +63,9 @@ void SerialWrite(uint8_t *write_data, int length);
/*Control Framework Serial Read*/
int SerialRead(uint8_t *read_data, int length);
/*Control Framework Store data in SD Card*/
int ControlFileDataStore(uint8 *data, int data_length);
#ifdef __cplusplus
}
#endif

View File

@ -26,6 +26,7 @@ extern int AdapterEthercatInit(void);
extern int AdapterZigbeeInit(void);
extern int AdapterLoraInit(void);
extern int Bmp180AltitudeInit(void);
extern int D124VoiceInit(void);
extern int Hs300xTemperatureInit(void);
extern int Hs300xHumidityInit(void);
@ -83,6 +84,10 @@ static struct InitDesc framework[] =
static struct InitDesc sensor_desc[] =
{
#ifdef SENSOR_DEVICE_BMP180
{ "bmp180_altitude", Bmp180AltitudeInit},
#endif
#ifdef SENSOR_DEVICE_D124
{ "d124_voice", D124VoiceInit },
#endif

View File

@ -9,7 +9,7 @@ config KPU_DEV_DRIVER
config CAMERA_DEV_DRIVER
string "Set camera dev path for kpu"
default "/dev/ov2640"
default "/dev/camera_dev"
config KPU_LCD_DEV_DRIVER
string "Set lcd dev path for kpu"

View File

@ -69,12 +69,28 @@ static int SensorDeviceRead(struct SensorDevice *sdev, size_t len)
return 0;
}
/**
* @description: Write sensor device
* @param sdev - sensor device pointer
* @param buf - the buffer of write data
* @param len - the length of the write data
* @return success: 0 , failure: -1
*/
static int SensorDeviceWrite(struct SensorDevice *sdev, const void *buf, size_t len)
{
//Read i2c device data from i2c device address
if (PrivWrite(sdev->fd, buf, len) < 0)
return -1;
return 0;
}
static struct SensorDone done =
{
SensorDeviceOpen,
NULL,
SensorDeviceRead,
NULL,
SensorDeviceWrite,
NULL,
};
@ -109,7 +125,8 @@ static int32_t ReadHumidity(struct SensorQuantity *quant)
float result = 0.0;
if (quant->sdev->done->read != NULL) {
if (quant->sdev->status == SENSOR_DEVICE_PASSIVE) {
quant->sdev->done->read(quant->sdev, 4);
quant->sdev->done->write(quant->sdev, NONE, 0);
PrivTaskDelay(50);
quant->sdev->done->read(quant->sdev, 4); /* It takes two reads to get the data right */
result = ((quant->sdev->buffer[0] << 8 | quant->sdev->buffer[1] ) & 0x3fff) * 100.0 / ( (1 << 14) - 1);

View File

@ -68,12 +68,28 @@ static int SensorDeviceRead(struct SensorDevice *sdev, size_t len)
return 0;
}
/**
* @description: Write sensor device
* @param sdev - sensor device pointer
* @param buf - the buffer of write data
* @param len - the length of the write data
* @return success: 0 , failure: -1
*/
static int SensorDeviceWrite(struct SensorDevice *sdev, const void *buf, size_t len)
{
//Read i2c device data from i2c device address
if (PrivWrite(sdev->fd, buf, len) < 0)
return -1;
return 0;
}
static struct SensorDone done =
{
SensorDeviceOpen,
NULL,
SensorDeviceRead,
NULL,
SensorDeviceWrite,
NULL,
};
@ -108,7 +124,7 @@ static int32_t ReadTemperature(struct SensorQuantity *quant)
float result;
if (quant->sdev->done->read != NULL) {
if (quant->sdev->status == SENSOR_DEVICE_PASSIVE) {
quant->sdev->done->read(quant->sdev, 4);
quant->sdev->done->write(quant->sdev, NONE, 0);
PrivTaskDelay(50);
quant->sdev->done->read(quant->sdev, 4); /* It takes two reads to get the data right */
result = ((quant->sdev->buffer[2] << 8 | quant->sdev->buffer[3]) >> 2) * 165.0 /( (1 << 14) - 1) - 40.0;

View File

@ -206,7 +206,7 @@ static int PrivLcdIoctl(int fd, int cmd, void *args)
int PrivIoctl(int fd, int cmd, void *args)
{
int ret;
int ret = -ERROR;
struct PrivIoctlCfg *ioctl_cfg = (struct PrivIoctlCfg *)args;
switch (ioctl_cfg->ioctl_driver_type)
{

View File

@ -66,7 +66,7 @@ int timer_create(clockid_t clockid, struct sigevent * evp, timer_t * timerid)
}
memset(timer_name, 0, sizeof(timer_name));
snprintf(timer_name, sizeof(timer_name), "timer_%d", clockid);
snprintf(timer_name, sizeof(timer_name), "timer_%ld", clockid);
sem_init(&timer_sem, 0, 0);

View File

@ -14,4 +14,5 @@ menu "app lib"
source "$APP_DIR/lib/lvgl/Kconfig"
source "$APP_DIR/lib/embedded_database/Kconfig"
source "$APP_DIR/lib/lorawan/Kconfig"
source "$APP_DIR/lib/mqtt/Kconfig"
endmenu

View File

@ -18,4 +18,8 @@ ifeq ($(CONFIG_LIB_USING_LORAWAN),y)
SRC_DIR += lorawan
endif
ifeq ($(CONFIG_TOOL_USING_MQTT),y)
SRC_DIR += mqtt
endif
include $(KERNEL_ROOT)/compiler.mk

View File

@ -866,5 +866,7 @@ menu "lib using LVGL"
endmenu
endif
source "$APP_DIR/lib/lvgl/examples/Kconfig"
endmenu

View File

@ -0,0 +1,8 @@
menu "lvgl image display parameter settings"
menuconfig LVGL_WIDTH
int "Set the width of the image."
default 320
menuconfig LVGL_HEIGHT
int "set the height of the image."
default 320
endmenu

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

View File

@ -1,14 +1,15 @@
#include "../../lv_examples.h"
#include <transform.h>
#if LV_USE_IMG && LV_BUILD_EXAMPLES
void lv_example_aoteman(void)
void lv_example_show(void)
{
LV_IMG_DECLARE(aoteman);
LV_IMG_DECLARE(xiuos);
lv_obj_t * img1 = lv_img_create(lv_scr_act());
lv_img_set_src(img1, &aoteman);
lv_img_set_src(img1, &xiuos);
lv_obj_align(img1, LV_ALIGN_CENTER, 0, -20);
lv_obj_set_size(img1, 320, 240);
lv_obj_set_size(img1, LVGL_WIDTH, LVGL_HEIGHT);
lv_obj_t * img2 = lv_img_create(lv_scr_act());
lv_img_set_src(img2, LV_SYMBOL_OK "Accept");

View File

@ -0,0 +1,33 @@
menu "lib using MQTT"
menuconfig TOOL_USING_MQTT
bool "Enable support MQTT function"
default n
select SUPPORT_CONNECTION_FRAMEWORK
select CONNECTION_ADAPTER_4G
if TOOL_USING_MQTT
menu "MQTT connection parameter configuration."
config PLATFORM_PRODUCTKEY
string "Product Key, used to identify a product."
default "iv74vebCdJC"
config CLIENT_DEVICENAME
string "Device name, used to identify a client device."
default "D001"
config CLIENT_DEVICESECRET
string "Device secret, used for device authentication and data encryption."
default "d2e613c4f714b6b0774bd7b68eeceae3"
config PLATFORM_SERVERIP
string "mqtt platform server ip."
default "101.133.196.127"
config PLATFORM_SERVERPORT
string "mqtt platform server port."
default "1883"
endmenu
endif
endmenu

View File

@ -0,0 +1,3 @@
SRC_FILES := platform_mqtt.c utils_hmacsha1.c
include $(KERNEL_ROOT)/compiler.mk

View File

@ -0,0 +1,438 @@
/*
* Copyright (c) 2020 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file: platform_mqtt.c
* @brief: platform_mqtt.c file
* @version: 1.0
* @author: AIIT XUOS Lab
* @date: 2023/7/27
*
*/
#include <string.h>
#include <stdint.h>
#include <adapter.h>
#include <transform.h>
#include "platform_mqtt.h"
MQTT_TCB Platform_mqtt; //创建一个用于连接云平台mqtt的结构体
static struct Adapter *adapter;
static const uint8_t parket_connetAck[] = {0x20,0x02,0x00,0x00}; //连接成功服务器回应报文
static const uint8_t parket_disconnet[] = {0xE0,0x00}; //客户端主动断开连接发送报文
static const uint8_t parket_heart[] = {0xC0,0x00}; //客户端发送保活心跳包
static const uint8_t parket_subAck[] = {0x90,0x03,0x00,0x0A,0x01}; //订阅成功服务器回应报文
static const uint8_t parket_unsubAck[] = {0xB0,0x02,0x00,0x0A}; //取消订阅成功服务器回应报文
static uint8_t mqtt_rxbuf[16];
/*******************************************************************************
* : AdapterNetActive
* : 使,TCP服务器并进入透传模式使4G方式
* :
* : 0,
*******************************************************************************/
int AdapterNetActive(void)
{
int ret = 0;
uint32_t baud_rate = BAUD_RATE_115200;
adapter = AdapterDeviceFindByName(ADAPTER_4G_NAME);
adapter->socket.socket_id = 0;
ret = AdapterDeviceOpen(adapter);
if (ret < 0)
{
goto out;
}
ret = AdapterDeviceControl(adapter, OPE_INT, &baud_rate);
if (ret < 0)
{
goto out;
}
ret = AdapterDeviceConnect(adapter, CLIENT, PLATFORM_SERVERIP, PLATFORM_SERVERPORT, IPV4);
if (ret < 0)
{
goto out;
}
out:
if (ret < 0)
{
AdapterDeviceClose(adapter);
}
return ret;
}
/*******************************************************************************
* : MQTT_Send
* : MQTT client数据发送函数
* : buf:,buflen:
* : 0,-1
*******************************************************************************/
int MQTT_Send(const uint8_t* buf, int buflen)
{
return AdapterDeviceSend(adapter, buf, buflen) ;
}
/*******************************************************************************
* : MQTT_Recv
* : MQTT client数据接收函数
* : buf:,buflen:
* : ,-1
*******************************************************************************/
int MQTT_Recv(uint8_t* buf, int buflen)
{
return AdapterDeviceRecv(adapter, buf, buflen) ;
}
/*******************************************************************************
* : MQTT_Connect
* : MQTT服务器
* :
* : 0,1
*******************************************************************************/
int MQTT_Connect(void)
{
uint8_t TryConnect_time = 10; //尝试登录次数
uint8_t passwdtemp[PASSWARD_SIZE];
memset(&Platform_mqtt,0,sizeof(Platform_mqtt));
sprintf(Platform_mqtt.ClientID,"%s|securemode=3,signmethod=hmacsha1|",CLIENT_DEVICENAME); //构建客户端ID并存入缓冲区
sprintf(Platform_mqtt.Username,"%s&%s",CLIENT_DEVICENAME,PLATFORM_PRODUCTKEY); //构建用户名并存入缓冲区
memset(passwdtemp,0,sizeof(passwdtemp));
sprintf(passwdtemp,"clientId%sdeviceName%sproductKey%s",CLIENT_DEVICENAME,CLIENT_DEVICENAME,PLATFORM_PRODUCTKEY); //构建加密时的明文
utils_hmac_sha1(passwdtemp,strlen(passwdtemp),Platform_mqtt.Passward,(char *)CLIENT_DEVICESECRET,strlen(CLIENT_DEVICESECRET)); //以DeviceSecret为秘钥对temp中的明文进行hmacsha1加密即为密码
Platform_mqtt.MessageID = 0; //报文标识符清零,CONNECT报文虽然不需要添加报文标识符,但是CONNECT报文是第一个发送的报文,在此清零报文标识符为后续报文做准备
Platform_mqtt.Fixed_len = 1; //CONNECT报文固定报头长度暂定为1
Platform_mqtt.Variable_len = 10; //CONNECT报文可变报头长度为10
Platform_mqtt.Payload_len = (2+strlen(Platform_mqtt.ClientID)) + (2+strlen(Platform_mqtt.Username)) + (2+strlen(Platform_mqtt.Passward)); //CONNECT报文中负载长度
Platform_mqtt.Remaining_len = Platform_mqtt.Variable_len + Platform_mqtt.Payload_len; //剩余长度=可变报头长度+负载长度
memset(Platform_mqtt.Pack_buff,0,sizeof(Platform_mqtt.Pack_buff));
Platform_mqtt.Pack_buff[0] = 0x10; //CONNECT报文 固定报头第1个字节0x10
do{
if((Platform_mqtt.Remaining_len/128) == 0)
{
Platform_mqtt.Pack_buff[Platform_mqtt.Fixed_len] = Platform_mqtt.Remaining_len;
}
else
{
Platform_mqtt.Pack_buff[Platform_mqtt.Fixed_len] = (Platform_mqtt.Remaining_len%128)|0x80;
}
Platform_mqtt.Fixed_len++;
Platform_mqtt.Remaining_len = Platform_mqtt.Remaining_len/128;
}while(Platform_mqtt.Remaining_len);
Platform_mqtt.Pack_buff[Platform_mqtt.Fixed_len+0] = 0x00; //CONNECT报文,可变报头第1个字节:固定0x00
Platform_mqtt.Pack_buff[Platform_mqtt.Fixed_len+1] = 0x04; //CONNECT报文,可变报头第2个字节:固定0x04
Platform_mqtt.Pack_buff[Platform_mqtt.Fixed_len+2] = 0x4D; //CONNECT报文,可变报头第3个字节:固定0x4D,大写字母M
Platform_mqtt.Pack_buff[Platform_mqtt.Fixed_len+3] = 0x51; //CONNECT报文,可变报头第4个字节:固定0x51,大写字母Q
Platform_mqtt.Pack_buff[Platform_mqtt.Fixed_len+4] = 0x54; //CONNECT报文,可变报头第5个字节:固定0x54,大写字母T
Platform_mqtt.Pack_buff[Platform_mqtt.Fixed_len+5] = 0x54; //CONNECT报文,可变报头第6个字节:固定0x54,大写字母T
Platform_mqtt.Pack_buff[Platform_mqtt.Fixed_len+6] = 0x04; //CONNECT报文,可变报头第7个字节:固定0x04
Platform_mqtt.Pack_buff[Platform_mqtt.Fixed_len+7] = 0xC2; //CONNECT报文,可变报头第8个字节:使能用户名和密码校验,不使用遗嘱功能,不保留会话功能
Platform_mqtt.Pack_buff[Platform_mqtt.Fixed_len+8] = KEEPALIVE_TIME/256; //CONNECT报文,可变报头第9个字节:保活时间高字节
Platform_mqtt.Pack_buff[Platform_mqtt.Fixed_len+9] = KEEPALIVE_TIME%256; //CONNECT报文,可变报头第10个字节:保活时间低字节,单位s
/* CLIENT_ID */
Platform_mqtt.Pack_buff[Platform_mqtt.Fixed_len+10] = strlen(Platform_mqtt.ClientID)/256; //客户端ID长度高字节
Platform_mqtt.Pack_buff[Platform_mqtt.Fixed_len+11] = strlen(Platform_mqtt.ClientID)%256; //客户端ID长度低字节
memcpy(&Platform_mqtt.Pack_buff[Platform_mqtt.Fixed_len+12],Platform_mqtt.ClientID,strlen(Platform_mqtt.ClientID)); //复制过来客户端ID字串
/* USER_NAME */
Platform_mqtt.Pack_buff[Platform_mqtt.Fixed_len+12+strlen(Platform_mqtt.ClientID)] = strlen(Platform_mqtt.Username)/256; //用户名长度高字节
Platform_mqtt.Pack_buff[Platform_mqtt.Fixed_len+13+strlen(Platform_mqtt.ClientID)] = strlen(Platform_mqtt.Username)%256; //用户名长度低字节
memcpy(&Platform_mqtt.Pack_buff[Platform_mqtt.Fixed_len+14+strlen(Platform_mqtt.ClientID)],Platform_mqtt.Username,strlen(Platform_mqtt.Username)); //复制过来用户名字串
/* PASSWARD */
Platform_mqtt.Pack_buff[Platform_mqtt.Fixed_len+14+strlen(Platform_mqtt.ClientID)+strlen(Platform_mqtt.Username)] = strlen(Platform_mqtt.Passward)/256; //密码长度高字节
Platform_mqtt.Pack_buff[Platform_mqtt.Fixed_len+15+strlen(Platform_mqtt.ClientID)+strlen(Platform_mqtt.Username)] = strlen(Platform_mqtt.Passward)%256; //密码长度低字节
memcpy(&Platform_mqtt.Pack_buff[Platform_mqtt.Fixed_len+16+strlen(Platform_mqtt.ClientID)+strlen(Platform_mqtt.Username)],Platform_mqtt.Passward,strlen(Platform_mqtt.Passward)); //复制过来密码字串
while(TryConnect_time > 0)
{
memset(mqtt_rxbuf,0,sizeof(mqtt_rxbuf));
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]) //连接成功
{
return 0;
}
TryConnect_time--;
}
return 1;
}
/*******************************************************************************
* : MQTT_Disconnect
* : MQTT服务器的连接
* :
* :
*******************************************************************************/
void MQTT_Disconnect(void)
{
while(MQTT_Send(parket_disconnet,sizeof(parket_disconnet)) < 0);
}
/*******************************************************************************
* : MQTT_SubscribeTopic
* : MQTT订阅单个主题
* : topic_name:
* : 0,1
*******************************************************************************/
int MQTT_SubscribeTopic(uint8_t *topic_name)
{
uint8_t TrySub_time = 10; //尝试订阅次数
Platform_mqtt.Fixed_len = 1; //SUBSCRIBE报文,固定报头长度暂定为1
Platform_mqtt.Variable_len = 2;//SUBSCRIBE报文,可变报头长度=2,2为字节报文标识符
Platform_mqtt.Payload_len = 0; //SUBSCRIBE报文,负载数据长度暂定为0
Platform_mqtt.Payload_len = strlen(topic_name) + 2 + 1; //每个需要订阅的topic除了本身的字符串长度,还包含表示topic字符串长度的2字节,以及订阅等级1字节
Platform_mqtt.Remaining_len = Platform_mqtt.Variable_len + Platform_mqtt.Payload_len; //计算剩余长度=可变报头长度+负载长度
memset(Platform_mqtt.Pack_buff,0,sizeof(Platform_mqtt.Pack_buff));
Platform_mqtt.Pack_buff[0]=0x82; //SUBSCRIBE报文,固定报头第1个字节0x82
do{
if((Platform_mqtt.Remaining_len/128) == 0)
{
Platform_mqtt.Pack_buff[Platform_mqtt.Fixed_len] = Platform_mqtt.Remaining_len;
}
else
{
Platform_mqtt.Pack_buff[Platform_mqtt.Fixed_len] = (Platform_mqtt.Remaining_len%128)|0x80;
}
Platform_mqtt.Fixed_len++;
Platform_mqtt.Remaining_len = Platform_mqtt.Remaining_len/128;
}while(Platform_mqtt.Remaining_len);
Platform_mqtt.Pack_buff[Platform_mqtt.Fixed_len+0] = Platform_mqtt.MessageID/256; //报文标识符高字节
Platform_mqtt.Pack_buff[Platform_mqtt.Fixed_len+1] = Platform_mqtt.MessageID%256; //报文标识符低字节
Platform_mqtt.MessageID++; //每用一次MessageID加1
Platform_mqtt.Pack_buff[Platform_mqtt.Fixed_len+2] = strlen(topic_name)/256; //主题长度高字节
Platform_mqtt.Pack_buff[Platform_mqtt.Fixed_len+3] = strlen(topic_name)%256; //主题长度低字节
memcpy(&Platform_mqtt.Pack_buff[Platform_mqtt.Fixed_len+4],topic_name,strlen(topic_name)); //复制主题字串
Platform_mqtt.Pack_buff[Platform_mqtt.Fixed_len+4+strlen(topic_name)] = 0; //QOS等级设置为0
while(TrySub_time > 0)
{
memset(mqtt_rxbuf,0,sizeof(mqtt_rxbuf));
MQTT_Send(Platform_mqtt.Pack_buff,Platform_mqtt.Fixed_len + Platform_mqtt.Variable_len + Platform_mqtt.Payload_len);
MdelayKTask(50);
MQTT_Recv(mqtt_rxbuf, 5);
if(mqtt_rxbuf[0] == parket_subAck[0] && mqtt_rxbuf[1] == parket_subAck[1]) //订阅成功
{
return 0;
}
TrySub_time--;
}
return 1;
}
/*******************************************************************************
* : MQTT_UnSubscribeTopic
* : MQTT取消订阅单个主题
* : topic_name:
* : 0,1
*******************************************************************************/
int MQTT_UnSubscribeTopic(uint8_t *topic_name)
{
uint8_t TryUnSub_time = 10; //尝试取消订阅次数
Platform_mqtt.Fixed_len = 1; //UNSUBSCRIBE报文,固定报头长度暂定为1
Platform_mqtt.Variable_len = 2; //UNSUBSCRIBE报文,可变报头长度=2,2为字节报文标识符
Platform_mqtt.Payload_len = strlen(topic_name) + 2; //每个需要取消的订阅topic除了本身的字符串长度,还包含表示topic字符串长度的2字节
Platform_mqtt.Remaining_len = Platform_mqtt.Variable_len + Platform_mqtt.Payload_len; //计算剩余长度=可变报头长度+负载长度
memset(Platform_mqtt.Pack_buff,0,sizeof(Platform_mqtt.Pack_buff));
Platform_mqtt.Pack_buff[0]=0xA0; //UNSUBSCRIBE报文,固定报头第1个字节0xA0
do{
if((Platform_mqtt.Remaining_len/128) == 0)
{
Platform_mqtt.Pack_buff[Platform_mqtt.Fixed_len] = Platform_mqtt.Remaining_len;
}
else
{
Platform_mqtt.Pack_buff[Platform_mqtt.Fixed_len] = (Platform_mqtt.Remaining_len%128)|0x80;
}
Platform_mqtt.Fixed_len++;
Platform_mqtt.Remaining_len = Platform_mqtt.Remaining_len/128;
}while(Platform_mqtt.Remaining_len);
Platform_mqtt.Pack_buff[Platform_mqtt.Fixed_len+0] = Platform_mqtt.MessageID/256; //报文标识符高字节
Platform_mqtt.Pack_buff[Platform_mqtt.Fixed_len+1] = Platform_mqtt.MessageID%256; //报文标识符低字节
Platform_mqtt.MessageID++; //每用一次MessageID加1
Platform_mqtt.Pack_buff[Platform_mqtt.Fixed_len+2] = strlen(topic_name)/256; //主题长度高字节
Platform_mqtt.Pack_buff[Platform_mqtt.Fixed_len+3] = strlen(topic_name)%256; //主题长度低字节
memcpy(&Platform_mqtt.Pack_buff[Platform_mqtt.Fixed_len+4],topic_name,strlen(topic_name)); //复制主题字串
while(TryUnSub_time > 0)
{
memset(mqtt_rxbuf,0,sizeof(mqtt_rxbuf));
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_unsubAck[0] && mqtt_rxbuf[1] == parket_unsubAck[1]) //取消订阅成功
{
return 0;
}
TryUnSub_time--;
}
return 1;
}
/*******************************************************************************
* : MQTT_PublishDataQs0
* : 0Publish报文
* : topic_name:
data:
data_len:
* : Qs=0
*******************************************************************************/
void MQTT_PublishDataQs0(uint8_t *topic_name,uint8_t *data, uint16_t data_len)
{
Platform_mqtt.Fixed_len = 1; //PUBLISH等级0报文固定报头长度暂定为1
Platform_mqtt.Variable_len = 2 + strlen(topic_name); //PUBLISH等级0报文,可变报头长度=2字节topic长度标识字节+topic字符串的长度
Platform_mqtt.Payload_len = data_len; //PUBLISH等级0报文,负载数据长度=data_len
Platform_mqtt.Remaining_len = Platform_mqtt.Variable_len + Platform_mqtt.Payload_len; //计算剩余长度=可变报头长度+负载长度
memset(Platform_mqtt.Pack_buff,0,sizeof(Platform_mqtt.Pack_buff));
Platform_mqtt.Pack_buff[0]=0x30; //PUBLISH等级0报文固定报头第1个字节0x30
do{
if((Platform_mqtt.Remaining_len/128) == 0)
{
Platform_mqtt.Pack_buff[Platform_mqtt.Fixed_len] = Platform_mqtt.Remaining_len;
}
else
{
Platform_mqtt.Pack_buff[Platform_mqtt.Fixed_len] = (Platform_mqtt.Remaining_len%128)|0x80;
}
Platform_mqtt.Fixed_len++;
Platform_mqtt.Remaining_len = Platform_mqtt.Remaining_len/128;
}while(Platform_mqtt.Remaining_len);
Platform_mqtt.Pack_buff[Platform_mqtt.Fixed_len+0]=strlen(topic_name)/256; //主题长度高字节
Platform_mqtt.Pack_buff[Platform_mqtt.Fixed_len+1]=strlen(topic_name)%256; //主题长度低字节
memcpy(&Platform_mqtt.Pack_buff[Platform_mqtt.Fixed_len+2],topic_name,strlen(topic_name)); //复制主题字串
memcpy(&Platform_mqtt.Pack_buff[Platform_mqtt.Fixed_len+2+strlen(topic_name)],data,data_len); //复制data数据
MQTT_Send(Platform_mqtt.Pack_buff, Platform_mqtt.Fixed_len + Platform_mqtt.Variable_len + Platform_mqtt.Payload_len);
}
/*******************************************************************************
* : MQTT_PublishDataQs1
* : 1Publish报文
* : topic_name:
data:
data_len:
* :
*******************************************************************************/
void MQTT_PublishDataQs1(uint8_t *topic_name,uint8_t *data, uint16_t data_len)
{
Platform_mqtt.Fixed_len = 1; //PUBLISH等级1报文固定报头长度暂定为1
Platform_mqtt.Variable_len = 2 + 2 + strlen(topic_name); //PUBLISH等级1报文,可变报头长度=2字节消息标识符+2字节topic长度标识字节+topic字符串的长度
Platform_mqtt.Payload_len = data_len; //PUBLISH等级1报文,负载数据长度=data_len
Platform_mqtt.Remaining_len = Platform_mqtt.Variable_len + Platform_mqtt.Payload_len; //计算剩余长度=可变报头长度+负载长度
Platform_mqtt.Pack_buff[0] = 0x32; //等级1的Publish报文固定报头第1个字节0x32
do{
if(Platform_mqtt.Remaining_len/128 == 0)
{
Platform_mqtt.Pack_buff[Platform_mqtt.Fixed_len] = Platform_mqtt.Remaining_len;
}
else
{
Platform_mqtt.Pack_buff[Platform_mqtt.Fixed_len] = (Platform_mqtt.Remaining_len%128)|0x80;
}
Platform_mqtt.Fixed_len++;
Platform_mqtt.Remaining_len = Platform_mqtt.Remaining_len/128;
}while(Platform_mqtt.Remaining_len);
Platform_mqtt.Pack_buff[Platform_mqtt.Fixed_len+0] = strlen(topic_name)/256; //主题长度高字节
Platform_mqtt.Pack_buff[Platform_mqtt.Fixed_len+1] = strlen(topic_name)%256; //主题长度低字节
memcpy(&Platform_mqtt.Pack_buff[Platform_mqtt.Fixed_len+2],topic_name,strlen(topic_name)); //复制主题字串
Platform_mqtt.Pack_buff[Platform_mqtt.Fixed_len+2+strlen(topic_name)] = Platform_mqtt.MessageID/256; //报文标识符高字节
Platform_mqtt.Pack_buff[Platform_mqtt.Fixed_len+3+strlen(topic_name)] = Platform_mqtt.MessageID%256; //报文标识符低字节
Platform_mqtt.MessageID++; //每用一次MessageID加1
memcpy(&Platform_mqtt.Pack_buff[Platform_mqtt.Fixed_len+4+strlen(topic_name)],data,strlen(data)); //复制data数据
MQTT_Send(Platform_mqtt.Pack_buff,Platform_mqtt.Fixed_len + Platform_mqtt.Variable_len + Platform_mqtt.Payload_len);
}
/*******************************************************************************
* : MQTT_SendHeart
* :
* :
* : 0,
*******************************************************************************/
int MQTT_SendHeart(void)
{
uint8_t TrySentHeart_time = 10; //尝试发送心跳保活次数
while(TrySentHeart_time > 0)
{
memset(mqtt_rxbuf,0,sizeof(mqtt_rxbuf));
MQTT_Send(parket_heart,sizeof(parket_heart));
MdelayKTask(50);
MQTT_Recv(mqtt_rxbuf, 2);
if(mqtt_rxbuf[0] == 0xD0 && mqtt_rxbuf[1] == 0x00)
{
return 0;
}
TrySentHeart_time--;
}
return 1;
}
/*******************************************************************************
* : MQTT_DealPublishData
* : 0,topic信息
* : redata:,data_len:
* :
*******************************************************************************/
void MQTT_DealPublishData(uint8_t *data, uint16_t data_len)
{
uint8_t i;
uint16_t cmdpos,cmdlen;
for(i = 1;i < 5;i++)
{
if((data[i] & 0x80) == 0)
break;
}
cmdpos = 1+i+2;
cmdlen = data_len-(1+i+2);
if(data_len <= CMD_SIZE)
{
memset(Platform_mqtt.cmdbuff, 0, CMD_SIZE);
memcpy(Platform_mqtt.cmdbuff, &data[cmdpos], cmdlen);
}
}

View File

@ -0,0 +1,62 @@
/*
* Copyright (c) 2020 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file: platform_mqtt.h
* @brief: platform_mqtt.h file
* @version: 1.0
* @author: AIIT XUOS Lab
* @date: 2023/7/27
*
*/
#ifndef _PLATFORM_MQTT_H_
#define _PLATFORM_MQTT_H_
#include <stdint.h>
#include "utils_hmacsha1.h"
#define KEEPALIVE_TIME 300 //保活时间(单位s),300s
#define HEART_TIME 120000 //空闲时发送心跳包的时间间隔(单位ms),120s
#define PACK_SIZE 512 //存放报文数据缓冲区大小
#define CMD_SIZE 3072 //保存推送的PUBLISH报文中的数据缓冲区大小
#define CLIENTID_SIZE 64 //存放客户端ID的缓冲区大小
#define USERNAME_SIZE 64 //存放用户名的缓冲区大小
#define PASSWARD_SIZE 64 //存放密码的缓冲区大小
typedef struct{
uint8_t ClientID[CLIENTID_SIZE]; //存放客户端ID的缓冲区
uint8_t Username[USERNAME_SIZE]; //存放用户名的缓冲区
uint8_t Passward[PASSWARD_SIZE]; //存放密码的缓冲区
uint8_t Pack_buff[PACK_SIZE]; //存放发送报文数据缓冲区
uint16_t MessageID; //记录报文标识符
uint16_t Fixed_len; //固定报头长度
uint16_t Variable_len; //可变报头长度
uint16_t Payload_len; //有效负荷长度
uint16_t Remaining_len; //保存报文剩余长度字节
uint8_t cmdbuff[CMD_SIZE]; //保存推送的PUBLISH报文中的数据缓冲区
}MQTT_TCB;
extern MQTT_TCB Platform_mqtt; //外部变量声明
int AdapterNetActive(void);
int MQTT_Send(const uint8_t* buf, int buflen);
int MQTT_Recv(uint8_t* buf, int buflen);
int MQTT_Connect(void);
void MQTT_Disconnect(void);
int MQTT_SubscribeTopic(uint8_t *topic_name);
int MQTT_UnSubscribeTopic(uint8_t *topic_name);
void MQTT_PublishDataQs0(uint8_t *topic_name,uint8_t *data, uint16_t data_len);
void MQTT_PublishDataQs1(uint8_t *topic_name,uint8_t *data, uint16_t data_len);
int MQTT_SendHeart(void);
void MQTT_DealPublishData(uint8_t *data, uint16_t data_len);
#endif

View File

@ -0,0 +1,399 @@
/*
* Copyright (c) 2020 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file: utils_hmacsha1.c
* @brief: utils_hmacsha1.c file
* @version: 1.0
* @author: AIIT XUOS Lab
* @date: 2023/7/27
*
*/
#include "utils_hmacsha1.h"
#define KEY_IOPAD_SIZE 64
#define SHA1_DIGEST_SIZE 20
static void utils_sha1_zeroize(void *v, size_t n);
static void utils_sha1_init(iot_sha1_context *ctx);
static void utils_sha1_free(iot_sha1_context *ctx);
static void utils_sha1_clone(iot_sha1_context *dst, const iot_sha1_context *src);
static void utils_sha1_starts(iot_sha1_context *ctx);
static void utils_sha1_process(iot_sha1_context *ctx, const unsigned char data[64]);
static void utils_sha1_update(iot_sha1_context *ctx, const unsigned char *input, size_t ilen);
static void utils_sha1_finish(iot_sha1_context *ctx, unsigned char output[20]);
static void utils_sha1(const unsigned char *input, size_t ilen, unsigned char output[20]);
static int8_t utils_hb2hex(uint8_t hb);
const char * base64char = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
/* Implementation that should never be optimized out by the compiler */
static void utils_sha1_zeroize(void *v, size_t n)
{
volatile unsigned char *p = v;
while(n--) {
*p++ = 0;
}
}
/* 32-bit integer manipulation macros (big endian) */
#ifndef IOT_SHA1_GET_UINT32_BE
#define IOT_SHA1_GET_UINT32_BE(n,b,i) \
{ \
(n) = ( (uint32_t) (b)[(i) ] << 24 ) \
| ( (uint32_t) (b)[(i) + 1] << 16 ) \
| ( (uint32_t) (b)[(i) + 2] << 8 ) \
| ( (uint32_t) (b)[(i) + 3] ); \
}
#endif
#ifndef IOT_SHA1_PUT_UINT32_BE
#define IOT_SHA1_PUT_UINT32_BE(n,b,i) \
{ \
(b)[(i) ] = (unsigned char) ( (n) >> 24 ); \
(b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \
(b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \
(b)[(i) + 3] = (unsigned char) ( (n) ); \
}
#endif
void utils_sha1_init(iot_sha1_context *ctx)
{
memset(ctx, 0, sizeof(iot_sha1_context));
}
void utils_sha1_free(iot_sha1_context *ctx)
{
if(ctx == NULL) {
return;
}
utils_sha1_zeroize(ctx, sizeof(iot_sha1_context));
}
void utils_sha1_clone(iot_sha1_context *dst,
const iot_sha1_context *src)
{
*dst = *src;
}
/* SHA-1 context setup */
void utils_sha1_starts(iot_sha1_context *ctx)
{
ctx->total[0] = 0;
ctx->total[1] = 0;
ctx->state[0] = 0x67452301;
ctx->state[1] = 0xEFCDAB89;
ctx->state[2] = 0x98BADCFE;
ctx->state[3] = 0x10325476;
ctx->state[4] = 0xC3D2E1F0;
}
void utils_sha1_process(iot_sha1_context *ctx, const unsigned char data[64])
{
uint32_t temp, W[16], A, B, C, D, E;
IOT_SHA1_GET_UINT32_BE(W[ 0], data, 0);
IOT_SHA1_GET_UINT32_BE(W[ 1], data, 4);
IOT_SHA1_GET_UINT32_BE(W[ 2], data, 8);
IOT_SHA1_GET_UINT32_BE(W[ 3], data, 12);
IOT_SHA1_GET_UINT32_BE(W[ 4], data, 16);
IOT_SHA1_GET_UINT32_BE(W[ 5], data, 20);
IOT_SHA1_GET_UINT32_BE(W[ 6], data, 24);
IOT_SHA1_GET_UINT32_BE(W[ 7], data, 28);
IOT_SHA1_GET_UINT32_BE(W[ 8], data, 32);
IOT_SHA1_GET_UINT32_BE(W[ 9], data, 36);
IOT_SHA1_GET_UINT32_BE(W[10], data, 40);
IOT_SHA1_GET_UINT32_BE(W[11], data, 44);
IOT_SHA1_GET_UINT32_BE(W[12], data, 48);
IOT_SHA1_GET_UINT32_BE(W[13], data, 52);
IOT_SHA1_GET_UINT32_BE(W[14], data, 56);
IOT_SHA1_GET_UINT32_BE(W[15], data, 60);
#define S(x,n) ((x << n) | ((x & 0xFFFFFFFF) >> (32 - n)))
#define R(t) \
( \
temp = W[( t - 3 ) & 0x0F] ^ W[( t - 8 ) & 0x0F] ^ \
W[( t - 14 ) & 0x0F] ^ W[ t & 0x0F], \
( W[t & 0x0F] = S(temp,1) ) \
)
#define P(a,b,c,d,e,x) \
{ \
e += S(a,5) + F(b,c,d) + K + x; b = S(b,30); \
}
A = ctx->state[0];
B = ctx->state[1];
C = ctx->state[2];
D = ctx->state[3];
E = ctx->state[4];
#define F(x,y,z) (z ^ (x & (y ^ z)))
#define K 0x5A827999
P(A, B, C, D, E, W[0]);
P(E, A, B, C, D, W[1]);
P(D, E, A, B, C, W[2]);
P(C, D, E, A, B, W[3]);
P(B, C, D, E, A, W[4]);
P(A, B, C, D, E, W[5]);
P(E, A, B, C, D, W[6]);
P(D, E, A, B, C, W[7]);
P(C, D, E, A, B, W[8]);
P(B, C, D, E, A, W[9]);
P(A, B, C, D, E, W[10]);
P(E, A, B, C, D, W[11]);
P(D, E, A, B, C, W[12]);
P(C, D, E, A, B, W[13]);
P(B, C, D, E, A, W[14]);
P(A, B, C, D, E, W[15]);
P(E, A, B, C, D, R(16));
P(D, E, A, B, C, R(17));
P(C, D, E, A, B, R(18));
P(B, C, D, E, A, R(19));
#undef K
#undef F
#define F(x,y,z) (x ^ y ^ z)
#define K 0x6ED9EBA1
P(A, B, C, D, E, R(20));
P(E, A, B, C, D, R(21));
P(D, E, A, B, C, R(22));
P(C, D, E, A, B, R(23));
P(B, C, D, E, A, R(24));
P(A, B, C, D, E, R(25));
P(E, A, B, C, D, R(26));
P(D, E, A, B, C, R(27));
P(C, D, E, A, B, R(28));
P(B, C, D, E, A, R(29));
P(A, B, C, D, E, R(30));
P(E, A, B, C, D, R(31));
P(D, E, A, B, C, R(32));
P(C, D, E, A, B, R(33));
P(B, C, D, E, A, R(34));
P(A, B, C, D, E, R(35));
P(E, A, B, C, D, R(36));
P(D, E, A, B, C, R(37));
P(C, D, E, A, B, R(38));
P(B, C, D, E, A, R(39));
#undef K
#undef F
#define F(x,y,z) ((x & y) | (z & (x | y)))
#define K 0x8F1BBCDC
P(A, B, C, D, E, R(40));
P(E, A, B, C, D, R(41));
P(D, E, A, B, C, R(42));
P(C, D, E, A, B, R(43));
P(B, C, D, E, A, R(44));
P(A, B, C, D, E, R(45));
P(E, A, B, C, D, R(46));
P(D, E, A, B, C, R(47));
P(C, D, E, A, B, R(48));
P(B, C, D, E, A, R(49));
P(A, B, C, D, E, R(50));
P(E, A, B, C, D, R(51));
P(D, E, A, B, C, R(52));
P(C, D, E, A, B, R(53));
P(B, C, D, E, A, R(54));
P(A, B, C, D, E, R(55));
P(E, A, B, C, D, R(56));
P(D, E, A, B, C, R(57));
P(C, D, E, A, B, R(58));
P(B, C, D, E, A, R(59));
#undef K
#undef F
#define F(x,y,z) (x ^ y ^ z)
#define K 0xCA62C1D6
P(A, B, C, D, E, R(60));
P(E, A, B, C, D, R(61));
P(D, E, A, B, C, R(62));
P(C, D, E, A, B, R(63));
P(B, C, D, E, A, R(64));
P(A, B, C, D, E, R(65));
P(E, A, B, C, D, R(66));
P(D, E, A, B, C, R(67));
P(C, D, E, A, B, R(68));
P(B, C, D, E, A, R(69));
P(A, B, C, D, E, R(70));
P(E, A, B, C, D, R(71));
P(D, E, A, B, C, R(72));
P(C, D, E, A, B, R(73));
P(B, C, D, E, A, R(74));
P(A, B, C, D, E, R(75));
P(E, A, B, C, D, R(76));
P(D, E, A, B, C, R(77));
P(C, D, E, A, B, R(78));
P(B, C, D, E, A, R(79));
#undef K
#undef F
ctx->state[0] += A;
ctx->state[1] += B;
ctx->state[2] += C;
ctx->state[3] += D;
ctx->state[4] += E;
}
/* SHA-1 process buffer */
void utils_sha1_update(iot_sha1_context *ctx, const unsigned char *input, size_t ilen)
{
size_t fill;
uint32_t left;
if(ilen == 0) {
return;
}
left = ctx->total[0] & 0x3F;
fill = 64 - left;
ctx->total[0] += (uint32_t) ilen;
ctx->total[0] &= 0xFFFFFFFF;
if(ctx->total[0] < (uint32_t) ilen) {
ctx->total[1]++;
}
if(left && ilen >= fill) {
memcpy((void *)(ctx->buffer + left), input, fill);
utils_sha1_process(ctx, ctx->buffer);
input += fill;
ilen -= fill;
left = 0;
}
while(ilen >= 64) {
utils_sha1_process(ctx, input);
input += 64;
ilen -= 64;
}
if(ilen > 0) {
memcpy((void *)(ctx->buffer + left), input, ilen);
}
}
static const unsigned char iot_sha1_padding[64] = {
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
/* SHA-1 final digest */
void utils_sha1_finish(iot_sha1_context *ctx, unsigned char output[20])
{
uint32_t last, padn;
uint32_t high, low;
unsigned char msglen[8];
high = (ctx->total[0] >> 29)
| (ctx->total[1] << 3);
low = (ctx->total[0] << 3);
IOT_SHA1_PUT_UINT32_BE(high, msglen, 0);
IOT_SHA1_PUT_UINT32_BE(low, msglen, 4);
last = ctx->total[0] & 0x3F;
padn = (last < 56) ? (56 - last) : (120 - last);
utils_sha1_update(ctx, iot_sha1_padding, padn);
utils_sha1_update(ctx, msglen, 8);
IOT_SHA1_PUT_UINT32_BE(ctx->state[0], output, 0);
IOT_SHA1_PUT_UINT32_BE(ctx->state[1], output, 4);
IOT_SHA1_PUT_UINT32_BE(ctx->state[2], output, 8);
IOT_SHA1_PUT_UINT32_BE(ctx->state[3], output, 12);
IOT_SHA1_PUT_UINT32_BE(ctx->state[4], output, 16);
}
/* output = SHA-1(input buffer) */
void utils_sha1(const unsigned char *input, size_t ilen, unsigned char output[20])
{
iot_sha1_context ctx;
utils_sha1_init(&ctx);
utils_sha1_starts(&ctx);
utils_sha1_update(&ctx, input, ilen);
utils_sha1_finish(&ctx, output);
utils_sha1_free(&ctx);
}
inline int8_t utils_hb2hex(uint8_t hb)
{
hb = hb & 0xF;
return (int8_t)(hb < 10 ? '0' + hb : hb - 10 + 'a');
}
void utils_hmac_sha1(const char *msg, int msg_len, char *digest, const char *key, int key_len)
{
iot_sha1_context context;
unsigned char k_ipad[KEY_IOPAD_SIZE]; /* inner padding - key XORd with ipad */
unsigned char k_opad[KEY_IOPAD_SIZE]; /* outer padding - key XORd with opad */
unsigned char out[SHA1_DIGEST_SIZE];
int i;
if((NULL == msg) || (NULL == digest) || (NULL == key)) {
return;
}
if(key_len > KEY_IOPAD_SIZE) {
return;
}
/* start out by storing key in pads */
memset(k_ipad, 0, sizeof(k_ipad));
memset(k_opad, 0, sizeof(k_opad));
memcpy(k_ipad, key, key_len);
memcpy(k_opad, key, key_len);
/* XOR key with ipad and opad values */
for(i = 0; i < KEY_IOPAD_SIZE; i++) {
k_ipad[i] ^= 0x36;
k_opad[i] ^= 0x5c;
}
/* perform inner SHA */
utils_sha1_init(&context); /* init context for 1st pass */
utils_sha1_starts(&context); /* setup context for 1st pass */
utils_sha1_update(&context, k_ipad, KEY_IOPAD_SIZE); /* start with inner pad */
utils_sha1_update(&context, (unsigned char *) msg, msg_len); /* then text of datagram */
utils_sha1_finish(&context, out); /* finish up 1st pass */
/* perform outer SHA */
utils_sha1_init(&context); /* init context for 2nd pass */
utils_sha1_starts(&context); /* setup context for 2nd pass */
utils_sha1_update(&context, k_opad, KEY_IOPAD_SIZE); /* start with outer pad */
utils_sha1_update(&context, out, SHA1_DIGEST_SIZE); /* then results of 1st hash */
utils_sha1_finish(&context, out); /* finish up 2nd pass */
for(i = 0; i < SHA1_DIGEST_SIZE; ++i) {
digest[i * 2] = utils_hb2hex(out[i] >> 4);
digest[i * 2 + 1] = utils_hb2hex(out[i]);
}
}

View File

@ -0,0 +1,41 @@
/*
* Copyright (c) 2020 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file: utils_hmacsha1.h
* @brief: utils_hmacsha1.h file
* @version: 1.0
* @author: AIIT XUOS Lab
* @date: 2023/7/27
*
*/
#ifndef UTILS_HMACSHA1_H_
#define UTILS_HMACSHA1_H_
#include "stdio.h"
#include "stdint.h"
#include "stdlib.h"
#include "string.h"
/* SHA-1 context structure */
typedef struct {
uint32_t total[2]; /* number of bytes processed */
uint32_t state[5]; /* intermediate digest state */
unsigned char buffer[64]; /* data block being processed */
} iot_sha1_context;
void utils_hmac_sha1(const char *msg, int msg_len, char *digest, const char *key, int key_len);
#endif

View File

@ -1,3 +1,3 @@
SRC_FILES := cache.c isr.c mmu.c
SRC_FILES := cache.c isr.c abstraction_mmu.c
include $(KERNEL_ROOT)/compiler.mk

View File

@ -0,0 +1,206 @@
/*
* Copyright (c) 2020 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file: abstraction_mmu.c
* @brief: the general management of system mmu
* @version: 3.0
* @author: AIIT XUOS Lab
* @date: 2023/4/27
*
*/
#include <abstraction_mmu.h>
AbstractionMmu abstraction_mmu;
volatile uint32_t global_L1_pte_table[4096];
/**
* @description: write cmd to CP15 register
* @param reg_type - CP15 register type
* @param val - ops val pointer
* @return
*/
static void MmuCp15Write(uint8_t reg_type, uint32_t *val)
{
uint32_t write_val = *val;
switch (reg_type) {
case AM_MMU_CP15_TTBCR:
TTBCR_W(write_val);
AM_ISB;
case AM_MMU_CP15_TTBR0:
TTBR0_W(write_val);
AM_ISB;
default:
break;
}
}
/**
* @description: read CP15 register from mmu
* @param reg_type - CP15 register type
* @param val - ops val pointer
* @return
*/
static void MmuCp15Read(uint8_t reg_type, uint32_t *val)
{
uint32_t read_val = 0;
switch (reg_type) {
case AM_MMU_CP15_TTBCR:
TTBCR_R(read_val);
case AM_MMU_CP15_TTBR0:
TTBR0_R(read_val);
default:
break;
}
*val = read_val;
}
/**
* @description: write or read CP15 register to set mmu
* @param ops_type - CP15 write or read
* @param reg_type - CP15 register type
* @param val - ops val pointer
* @return
*/
static void MmuRegOps(uint8_t ops_type, uint8_t reg_type, uint32_t *val)
{
switch (ops_type) {
case AM_MMU_CP15_WRITE:
MmuCp15Write(reg_type, val);
case AM_MMU_CP15_READ:
MmuCp15Read(reg_type, val);
default:
break;
}
}
/**
* @description: Init abstraction_mmu function
* @param mmu - abstraction mmu pointer
* @param ttb_base - ttb base pointer
* @return success : 0 error : -1
*/
static int _AbstractionMmuInit(AbstractionMmu *mmu, uint32_t *ttb_base)
{
mmu_init();
return 0;
}
/**
* @description: map L1 or L2 page table section
* @param mmu - abstraction mmu pointer
* @param section_size - section size
* @return success : 0 error : -1
*/
static int _AbstractionMmuSectionMap(AbstractionMmu *mmu, uint32_t section_size)
{
uint32_t vaddr_length = mmu->vaddr_end - mmu->vaddr_start + 1;
mmu_map_l1_range(mmu->paddr_start, mmu->vaddr_start, vaddr_length,
mmu->mmu_memory_type, mmu->mmu_shareability, mmu->mmu_access);
mmu->mmu_status = 1;
return 0;
}
/**
* @description: unmap L1 or L2 page table section
* @param mmu - abstraction mmu pointer
* @param vaddr_start - virtual address start
* @param vaddr_size - virtual address size
* @return success : 0 error : -1
*/
static int _AbstractionMmuSectionUnmap(AbstractionMmu *mmu, uint32_t vaddr_start, uint32_t vaddr_size)
{
uint32_t *l1_umap_ventry = mmu->ttb_vbase + (vaddr_start >> AM_MMU_L1_SECTION_SHIFT);
uint32_t vaddr_end = vaddr_start + vaddr_size - 1;
uint32_t umap_count = (vaddr_end >> AM_MMU_L1_SECTION_SHIFT) - (vaddr_start >> AM_MMU_L1_SECTION_SHIFT) + 1;
while (umap_count) {
AM_DMB;
*l1_umap_ventry = 0;
AM_DSB;
umap_count--;
l1_umap_ventry += (1 << AM_MMU_L1_SECTION_SHIFT);//1MB section
}
AM_DSB;
CLEARTLB(0);//clear TLB data and configure
AM_DSB;
AM_ISB;
mmu->mmu_status = 0;
return 0;
}
/**
* @description: switch ttb base by re-write ttbr register
* @param mmu - abstraction mmu pointer
* @return success : 0 error : -1
*/
static int _AbstractionMmuTtbSwitch(AbstractionMmu *mmu)
{
uint32_t ttbr, ttbcr;
MmuRegOps(AM_MMU_CP15_READ, AM_MMU_CP15_TTBCR, &ttbcr);
/* Set TTBR0 with inner/outer write back write allocate and not shareable, [4:3]=01, [1]=0, [6,0]=01 */
ttbr = ((mmu->ttb_pbase & 0xFFFFC000UL) | 0x9UL);
/* enable TTBR0 */
ttbcr = 0;
AM_DSB;
MmuRegOps(AM_MMU_CP15_WRITE, AM_MMU_CP15_TTBR0, &ttbr);
MmuRegOps(AM_MMU_CP15_WRITE, AM_MMU_CP15_TTBCR, &ttbcr);
return 0;
}
/**
* @description: get physical address transformed from virtual address
* @param mmu - abstraction mmu pointer
* @param vaddr - virtual address pointer
* @param paddr - physical address pointer
* @return success : 0 error : -1
*/
static int _AbstracktonMmuTransform(AbstractionMmu *mmu, uint32_t *vaddr, uint32_t *paddr)
{
uint32_t virtualAddress = *vaddr;
if (mmu->mmu_status) {
mmu_virtual_to_physical(virtualAddress, paddr);
}
return 0;
}
static struct AbstractionMmuDone mmu_done = {
.AbstractionMmuInit = _AbstractionMmuInit,
.AbstractionMmuSectionMap = _AbstractionMmuSectionMap,
.AbstractionMmuSectionUnmap = _AbstractionMmuSectionUnmap,
.AbstractionMmuTtbSwitch = _AbstractionMmuTtbSwitch,
.AbstracktonMmuTransform = _AbstracktonMmuTransform,
};
/**
* @description: init abstraciton mmu info when system start
* @return success : 0 error : -1
*/
int SysInitAbstractionMmu(void)
{
abstraction_mmu.mmu_done = &mmu_done;
}

View File

@ -0,0 +1,114 @@
/*
* Copyright (c) 2020 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file: mmu.h
* @brief: the general management of system mmu
* @version: 3.0
* @author: AIIT XUOS Lab
* @date: 2023/5/24
*
*/
#include <stdint.h>
#include <mmu.h>
#define ARCH_ARM
#ifdef ARCH_ARM
/* ARM System Registers */
#define AM_DSB __asm__ volatile("dsb" ::: "memory")
#define AM_DMB __asm__ volatile("dmb" ::: "memory")
#define AM_ISB __asm__ volatile("isb" ::: "memory")
#define AM_WFI __asm__ volatile("wfi" ::: "memory")
#define AM_BARRIER __asm__ volatile("":::"memory")
#define AM_WFE __asm__ volatile("wfe" ::: "memory")
#define AM_SEV __asm__ volatile("sev" ::: "memory")
#define TTBR0_R(val) __asm__ volatile("mrc p15, 0, %0, c2, c0, 0" : "=r"(val))
#define TTBR0_W(val) __asm__ volatile("mcr p15, 0, %0, c2, c0, 0" ::"r"(val))
#define TTBCR_R(val) __asm__ volatile("mrc p15, 0, %0, c2, c0, 2" : "=r"(val))
#define TTBCR_W(val) __asm__ volatile("mcr p15, 0, %0, c2, c0, 2" ::"r"(val))
#define CLEARTLB(val) __asm__ volatile("mcr p15, 0, %0, c8, c7, 0" ::"r"(val))
#endif
#define AM_MMU_L1_PAGE_TABLE_SIZE (4 * 4096)
#define AM_MMU_L1_SECTION_SHIFT 20
typedef enum
{
AM_MMU_CP15_WRITE = 0,
AM_MMU_CP15_READ,
}MmuCP15OpsType;
typedef enum
{
AM_MMU_CP15_TTBCR = 0,
AM_MMU_CP15_TTBR0,
AM_MMU_CP15_CLEARTLB,
}MmuCP15RegType;
typedef enum
{
AM_StronglyOrdered = 0,
AM_Device,
AM_OuterInner_WB_WA,
AM_OuterInner_WT,
AM_Noncacheable,
}MmuMemoryType;
typedef enum
{
AM_Noaccess = 0,
AM_Read_Write,
AM_Read,
}MmuAccess;
typedef enum
{
AM_Shareable = 1,
AM_Nonshareable = 0
}MmuShareability;
struct AbstractionMmuDone
{
int (*AbstractionMmuInit)(AbstractionMmu *mmu, uint32_t *ttb_base);
int (*AbstractionMmuSectionMap)(AbstractionMmu *mmu, uint32_t section_size);
int (*AbstractionMmuSectionUnmap)(AbstractionMmu *mmu, uint32_t vaddr_start, uint32_t vaddr_size);
int (*AbstractionMmuTtbSwitch)(AbstractionMmu *mmu);
int (*AbstracktonMmuTransform)(AbstractionMmu *mmu, uint32_t *vaddr, uint32_t *paddr);
};
typedef struct
{
uint32_t ttb_vbase;
uint32_t ttb_pbase;
uint32_t vaddr_start;
uint32_t vaddr_end;
uint32_t paddr_start;
uint32_t paddr_end;
uint32_t vpaddr_offset;
uint32_t pte_attr;
uint32_t mmu_status;
MmuMemoryType mmu_memory_type;
MmuAccess mmu_access;
MmuShareability mmu_shareability;
struct AbstractionMmuDone *mmu_done;
int lock;
int link_list;
}AbstractionMmu;

View File

@ -1,4 +1,23 @@
/*
* Copyright (c) 2020 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file: cache.c
* @brief: the general management of system cache
* @version: 3.0
* @author: AIIT XUOS Lab
* @date: 2023/4/27
*
*/
void InvalidInsCache()
{

View File

@ -0,0 +1,20 @@
/*
* Copyright (c) 2020 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file: memory.c
* @brief: the general management of system memory
* @version: 3.0
* @author: AIIT XUOS Lab
* @date: 2023/4/27
*
*/

View File

@ -14,6 +14,7 @@
#define PMP_H
#include <xs_klist.h>
#include <stddef.h>
#define PMP_MAX_ENTRY_NUMBER 16
#define PMP_ENTRY_RESERVE 6
@ -40,11 +41,11 @@
struct PmpEntry
{
uint8_t pmpcfg;
uint8 pmpcfg;
#if defined(ARCH_RISCV64)
uint64_t pmpaddr;
uint64 pmpaddr;
#else
uint32_t pmpaddr;
uint32 pmpaddr;
#endif
};
@ -53,8 +54,8 @@ struct PmpRegionNapot
{
x_ubase start ;
x_ubase end;
uint16_t swap_count;
uint8_t region_type;
uint16 swap_count;
uint8 region_type;
struct PmpEntry entry;
DoubleLinklistType link;
@ -64,8 +65,8 @@ struct PmpRegionTor
{
x_ubase start ;
x_ubase end;
uint16_t swap_count;
uint8_t region_type;
uint16 swap_count;
uint8 region_type;
struct PmpEntry entry[2];
DoubleLinklistType link;
@ -73,8 +74,8 @@ struct PmpRegionTor
struct Pmp
{
uint8_t count;
uint8_t reserve;
uint8 count;
uint8 reserve;
struct PmpEntry pmp_entry_reserve[PMP_ENTRY_RESERVE];
DoubleLinklistType tor_list;
@ -82,7 +83,7 @@ struct Pmp
};
x_err_t PmpAddTorRegion(void *task_pmp, x_ubase start , size_t size , uint8_t flag );
x_err_t PmpAddTorRegion(void *task_pmp, x_ubase start , size_t size , uint8 flag );
x_err_t PmpInitIsolation(void **task_pmp, x_ubase stack_start , size_t stack_size);
void PmpFree(void *task_pmp);
void PmpClear(void);

View File

@ -281,7 +281,7 @@ struct pbuf* low_level_input(struct netif* netif)
extern void LwipSetIPTest(int argc, char* argv[]);
int HwEthInit(void)
{
// lwip_config_tcp(0, lwip_ipaddr, lwip_netmask, lwip_gwaddr);
// lwip_config_tcp(0, lwip_ipaddr, lwip_netmask, lwip_gwaddr);
LwipSetIPTest(1, NULL);
return EOK;
}

View File

@ -263,7 +263,7 @@ err_t ethernetif_init(struct netif* netif)
if (EOK != lwip_netdev_add(netif)) {
SYS_KDEBUG_LOG(NETDEV_DEBUG, ("[%s] LWIP add netdev failed.\n", __func__));
} else {
printf("[%s] Add Netdev successful\n", __func__);
// printf("[%s] Add Netdev successful\n", __func__);
}
return LL_OK;
}

View File

@ -191,8 +191,8 @@ static uint32 SpiLoraWrite(void *dev, struct BusBlockWriteParam *write_param)
KPrintf("SpiLoraWrite ERROR:The message is too long!\n");
return ERROR;
} else {
SX1276SetTxPacket(write_param->buffer, write_param->size);
while(SX1276Process() != RF_TX_DONE);
SX1276SetTx(write_param->buffer, write_param->size);
KPrintf("SpiLoraWrite success!\n");
}
@ -210,24 +210,12 @@ static uint32 SpiLoraRead(void *dev, struct BusBlockReadParam *read_param)
NULL_PARAM_CHECK(dev);
NULL_PARAM_CHECK(read_param);
int read_times = 100;
SX1276StartRx();
KPrintf("SpiLoraRead Ready!\n");
while (read_times) {
if (SX1276Process() != RF_RX_DONE) {
read_times --;
MdelayKTask(500);
} else {
break;
}
}
int ret = SX1276GetRx(read_param->buffer, (uint16 *)&read_param->read_length);
if (read_times > 0) {
SX1276GetRxPacket(read_param->buffer, (uint16 *)&read_param->read_length);
} else {
read_param->read_length = 0;
if (ret < 0) {
return 0;
}
return read_param->read_length;

View File

@ -494,6 +494,7 @@ int HwSpiInit(void)
return ret;
}
#ifdef TEST_SPI
/*Just for lora test*/
static struct Bus *bus;
static struct HardwareDev *dev;
@ -578,4 +579,4 @@ void TestLoraOpen(void)
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
TestLoraOpen, TestLoraOpen, open lora device and read parameters);
#endif

View File

@ -50,6 +50,9 @@ uint8_t SX1276Regs[0x70];
static bool LoRaOn = true;
static bool LoRaOnState = false;
static int sx1276_tx_sem, sx1276_rx_sem;
static int sx1276_radio_task;
void SX1276Reset(void)
{
uint32_t startTick;
@ -200,6 +203,20 @@ void SX1276GetRxPacket(void *buffer, uint16_t *size)
}
}
int SX1276GetRx(void *buffer, uint16_t *size)
{
int ret = -1;
SX1276StartRx();
//receive timeout 10s
ret = KSemaphoreObtain(sx1276_rx_sem, 10000);
if (0 == ret) {
SX1276LoRaSetRFState(RFLR_STATE_IDLE);
SX1276GetRxPacket(buffer, size);
}
return ret;
}
void SX1276SetTxPacket(const void *buffer, uint16_t size)
{
if(LoRaOn == false) {
@ -209,6 +226,14 @@ void SX1276SetTxPacket(const void *buffer, uint16_t size)
}
}
void SX1276SetTx(const void *buffer, uint16_t size)
{
SX1276SetTxPacket(buffer, size);
KSemaphoreObtain(sx1276_tx_sem, WAITING_FOREVER);
SX1276StartRx();
}
uint8_t SX1276GetRFState(void)
{
if(LoRaOn == false) {
@ -236,6 +261,20 @@ uint32_t SX1276Process(void)
}
}
static void Sx1276RadioEntry(void *parameter)
{
uint32_t result;
while(1) {
result = SX1276Process();
if (RF_RX_DONE == result) {
KSemaphoreAbandon(sx1276_rx_sem);
}
if (RF_TX_DONE == result) {
KSemaphoreAbandon(sx1276_tx_sem);
}
}
}
uint32_t SX1276ChannelEmpty(void)
{
if(LoRaOn == false) {
@ -277,6 +316,12 @@ void SX1276Init(void)
SX1276_SetLoRaOn(LoRaOn);
SX1276LoRaInit();
#endif
sx1276_rx_sem = KSemaphoreCreate(0);
sx1276_tx_sem = KSemaphoreCreate(0);
sx1276_radio_task = KTaskCreate("radio", Sx1276RadioEntry , NONE, 2048, 20);
StartupKTask(sx1276_radio_task);
}
#endif

View File

@ -80,8 +80,12 @@ void SX1276StartRx( void ); //开始接收
void SX1276GetRxPacket( void *buffer, uint16_t *size ); //得到接收的数据
int SX1276GetRx(void *buffer, uint16_t *size); //应用接收数据,无数据时阻塞
void SX1276SetTxPacket( const void *buffer, uint16_t size ); //发送数据
void SX1276SetTx( const void *buffer, uint16_t size ); //应用发送数据
uint8_t SX1276GetRFState( void ); //得到RFLRState状态
void SX1276SetRFState( uint8_t state ); //设置RFLRState状态RFLRState的值决定了下面的函数处理哪一步的代码

View File

@ -13,6 +13,21 @@ menuconfig BSP_USING_UART3
default "usart3_dev3"
endif
menuconfig BSP_USING_UART4
bool "Enable USART4 for RS485"
default y
if BSP_USING_UART4
config SERIAL_BUS_NAME_4
string "serial bus 4 name"
default "usart4"
config SERIAL_DRV_NAME_4
string "serial bus 4 driver name"
default "usart4_drv"
config SERIAL_4_DEVICE_NAME_0
string "serial bus 4 device 0 name"
default "usart4_dev4"
endif
menuconfig BSP_USING_UART6
bool "Enable USART6"
default n

View File

@ -50,6 +50,14 @@ Modification:
#define USART3_TX_PIN (GPIO_PIN_10)
#endif
#if defined(BSP_USING_UART4)
#define USART4_RX_PORT (GPIO_PORT_E)
#define USART4_RX_PIN (GPIO_PIN_07)
#define USART4_TX_PORT (GPIO_PORT_G)
#define USART4_TX_PIN (GPIO_PIN_00)
#endif
#if defined(BSP_USING_UART6)
#define USART6_RX_PORT (GPIO_PORT_H)
#define USART6_RX_PIN (GPIO_PIN_06)
@ -72,6 +80,12 @@ static x_err_t UartGpioInit(CM_USART_TypeDef *USARTx)
GPIO_SetFunc(USART3_TX_PORT, USART3_TX_PIN, GPIO_FUNC_32);
break;
#endif
#ifdef BSP_USING_UART4
case (uint32)CM_USART4:
GPIO_SetFunc(USART4_RX_PORT, USART4_RX_PIN, GPIO_FUNC_33);
GPIO_SetFunc(USART4_TX_PORT, USART4_TX_PIN, GPIO_FUNC_32);
break;
#endif
#ifdef BSP_USING_UART6
case (uint32)CM_USART6:
GPIO_SetFunc(USART6_RX_PORT, USART6_RX_PIN, GPIO_FUNC_37);
@ -123,6 +137,32 @@ void Uart3RxErrIrqHandler(void)
}
#endif
#ifdef BSP_USING_UART4
struct SerialBus serial_bus_4;
struct SerialDriver serial_driver_4;
struct SerialHardwareDevice serial_device_4;
void Uart4RxIrqHandler(void)
{
x_base lock = 0;
lock = DISABLE_INTERRUPT();
SerialSetIsr(&serial_device_4, SERIAL_EVENT_RX_IND);
ENABLE_INTERRUPT(lock);
}
void Uart4RxErrIrqHandler(void)
{
x_base lock = 0;
lock = DISABLE_INTERRUPT();
UartRxErrIsr(&serial_bus_4, &serial_driver_4, &serial_device_4);
ENABLE_INTERRUPT(lock);
}
#endif
#ifdef BSP_USING_UART6
struct SerialBus serial_bus_6;
struct SerialDriver serial_driver_6;
@ -499,6 +539,57 @@ int HwUsartInit(void)
}
#endif
#ifdef BSP_USING_UART4
static struct SerialCfgParam serial_cfg_4;
memset(&serial_cfg_4, 0, sizeof(struct SerialCfgParam));
static struct SerialDevParam serial_dev_param_4;
memset(&serial_dev_param_4, 0, sizeof(struct SerialDevParam));
static struct UsartHwCfg serial_hw_cfg_4;
memset(&serial_hw_cfg_4, 0, sizeof(struct UsartHwCfg));
serial_driver_4.drv_done = &drv_done;
serial_driver_4.configure = SerialDrvConfigure;
serial_device_4.hwdev_done = &hwdev_done;
serial_cfg_4.data_cfg = data_cfg_init;
//default irq configure
serial_hw_cfg_4.uart_device = CM_USART4;
serial_hw_cfg_4.usart_clock = FCG3_PERIPH_USART4;
serial_hw_cfg_4.rx_err_irq.irq_config.irq_num = BSP_UART4_RXERR_IRQ_NUM;
serial_hw_cfg_4.rx_err_irq.irq_config.irq_prio = BSP_UART4_RXERR_IRQ_PRIO;
serial_hw_cfg_4.rx_err_irq.irq_config.int_src = INT_SRC_USART4_EI;
serial_hw_cfg_4.rx_irq.irq_config.irq_num = BSP_UART4_RX_IRQ_NUM;
serial_hw_cfg_4.rx_irq.irq_config.irq_prio = BSP_UART4_RX_IRQ_PRIO;
serial_hw_cfg_4.rx_irq.irq_config.int_src = INT_SRC_USART4_RI;
serial_hw_cfg_4.rx_err_irq.irq_callback = Uart4RxErrIrqHandler;
serial_hw_cfg_4.rx_irq.irq_callback = Uart4RxIrqHandler;
hc32_install_irq_handler(&serial_hw_cfg_4.rx_err_irq.irq_config, serial_hw_cfg_4.rx_err_irq.irq_callback, 0);
serial_cfg_4.hw_cfg.private_data = (void *)&serial_hw_cfg_4;
serial_driver_4.private_data = (void *)&serial_cfg_4;
serial_dev_param_4.serial_work_mode = SIGN_OPER_INT_RX;
serial_device_4.haldev.private_data = (void *)&serial_dev_param_4;
ret = BoardSerialBusInit(&serial_bus_4, &serial_driver_4, SERIAL_BUS_NAME_4, SERIAL_DRV_NAME_4);
if (EOK != ret) {
KPrintf("HwUartInit uart4 error ret %u\n", ret);
return ERROR;
}
ret = BoardSerialDevBend(&serial_device_4, (void *)&serial_cfg_4, SERIAL_BUS_NAME_4, SERIAL_4_DEVICE_NAME_0);
if (EOK != ret) {
KPrintf("HwUartInit uart4 error ret %u\n", ret);
return ERROR;
}
#endif
#ifdef BSP_USING_UART6
static struct SerialCfgParam serial_cfg_6;
memset(&serial_cfg_6, 0, sizeof(struct SerialCfgParam));

View File

@ -1,4 +1,5 @@
export CFLAGS := -mcmodel=medany -march=rv64imafdc -mabi=lp64d -fno-common -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -O0 -ggdb -fgnu89-inline -Werror
export CFLAGS := -mcmodel=medany -march=rv64imafdc -mabi=lp64d -fno-common -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -O1 -fgnu89-inline -Wformat -Wuninitialized
# export CFLAGS := -mcmodel=medany -march=rv64imafdc -mabi=lp64d -fno-common -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -O0 -ggdb -fgnu89-inline -Werror -Wformat -Wuninitialized
export AFLAGS := -c -mcmodel=medany -march=rv64imafdc -mabi=lp64d -x assembler-with-cpp -ggdb
export LFLAGS := -mcmodel=medany -march=rv64imafdc -mabi=lp64d -nostartfiles -Wl,--gc-sections,-Map=XiZi-edu-riscv64.map,-cref,-u,_start -T $(BSP_ROOT)/link.lds
@ -14,12 +15,12 @@ endif
export APPLFLAGS := -mcmodel=medany -march=rv64imafdc -mabi=lp64d -nostartfiles -Wl,--gc-sections,-Map=XiZi-edu-riscv64.map,-cref,-u, -T $(BSP_ROOT)/link_userspace.lds
export CXXFLAGS := -mcmodel=medany -march=rv64imafdc -mabi=lp64d -fno-common -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -O0 -ggdb -Werror
export CXXFLAGS := -mcmodel=medany -march=rv64imafdc -mabi=lp64d -fno-common -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -O0 -ggdb -Werror -std=gnu++11
export CROSS_COMPILE ?=/opt/gnu-mcu-eclipse/riscv-none-gcc/8.2.0-2.1-20190425-1021/bin/riscv-none-embed-
export DEFINES := -DHAVE_CCONFIG_H -DHAVE_SIGINFO
export DEFINES := -DHAVE_CCONFIG_H -DHAVE_SIGINFO -DRISCV_LWIP
export ARCH = risc-v
export MCU = k210

View File

@ -25,11 +25,12 @@
#ifndef _BSP_ATOMIC_H
#define _BSP_ATOMIC_H
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
#define SPINLOCK_INIT \
{ \
0 \
@ -63,7 +64,7 @@ extern "C" {
typedef struct _spinlock
{
int lock;
int32_t lock;
} spinlock_t;
typedef struct _semaphore

View File

@ -2,6 +2,7 @@
config BSP_USING_W5500
bool "Using w5500"
select BSP_USING_LWIP
default y
config BSP_WIZ_RST_PIN
@ -15,3 +16,8 @@ config BSP_WIZ_INT_PIN
config BSP_WIZ_USE_IPERF
bool "Using iperf"
default y
menuconfig BSP_USING_LWIP
bool "Using LwIP device"
default n
select RESOURCES_LWIP

View File

@ -1,3 +1,4 @@
SRC_FILES := socket.c connect_w5500.c w5500.c wizchip_conf.c spi_interface.c wiz_ping.c connect_w5500_test.c wiz_iperf.c
# SRC_FILES := socket.c connect_w5500.c w5500.c wizchip_conf.c spi_interface.c wiz_ping.c connect_w5500_test.c wiz_iperf.c
SRC_FILES := socket.c connect_w5500.c w5500.c wizchip_conf.c spi_interface.c wiz_ping.c connect_w5500_test.c w5x00_lwip.c wiz_iperf.c
include $(KERNEL_ROOT)/compiler.mk

View File

@ -5,8 +5,8 @@
#include <dev_pin.h>
#include <drv_io_config.h>
#include <fpioa.h>
#include <string.h>
#include <stdlib.h>
#include <string.h>
#include <xs_base.h>
#include "gpio_common.h"
@ -14,6 +14,10 @@
#include "socket.h"
#include "w5500.h"
#include "connect_ethernet.h"
#include <sys.h>
#define SPI_LORA_FREQUENCY 10000000
// spi operations
@ -23,242 +27,329 @@ extern void spi_select_cs(void);
extern void spi_deselete_cs(void);
// global configurations for w5500 tcp connection
uint32_t get_gbuf_size() {
static const uint32_t g_wiznet_buf_size = 2048;
return g_wiznet_buf_size;
uint32_t get_gbuf_size()
{
static const uint32_t g_wiznet_buf_size = 2048;
return g_wiznet_buf_size;
}
wiz_NetInfo *get_gnetinfo() {
static wiz_NetInfo g_wiz_netinfo = {.mac = {0x00, 0x08, 0xdc, 0x11, 0x11, 0x11},
.ip = {192, 168, 130, 77},
.sn = {255, 255, 254, 0},
.gw = {192, 168, 130, 1},
.dns = {0, 0, 0, 0},
.dhcp = NETINFO_STATIC};
return &g_wiz_netinfo;
wiz_NetInfo* get_gnetinfo()
{
static wiz_NetInfo g_wiz_netinfo = { .mac = { 0x00, 0x08, 0xdc, 0x11, 0x11, 0x11 },
.ip = { 192, 168, 130, 77 },
.sn = { 255, 255, 254, 0 },
.gw = { 192, 168, 130, 1 },
.dns = { 0, 0, 0, 0 },
.dhcp = NETINFO_STATIC };
return &g_wiz_netinfo;
}
int network_init() {
wiz_NetInfo check_wiz_netinfo;
check_wiz_netinfo.dhcp = NETINFO_STATIC;
ctlnetwork(CN_SET_NETINFO, (void *)get_gnetinfo());
ctlnetwork(CN_GET_NETINFO, (void *)&check_wiz_netinfo);
int network_init()
{
wiz_NetInfo check_wiz_netinfo;
check_wiz_netinfo.dhcp = NETINFO_STATIC;
ctlnetwork(CN_SET_NETINFO, (void*)get_gnetinfo());
ctlnetwork(CN_GET_NETINFO, (void*)&check_wiz_netinfo);
if (memcmp(get_gnetinfo(), &check_wiz_netinfo, sizeof(wiz_NetInfo)) != 0) {
KPrintf(
"mac: %d; ip: %d; gw: %d; sn: %d; dns: %d; dhcp: %d;\n",
memcmp(&get_gnetinfo()->mac, &check_wiz_netinfo.mac, sizeof(uint8_t) * 6),
memcmp(&get_gnetinfo()->ip, &check_wiz_netinfo.ip, sizeof(uint8_t) * 4),
memcmp(&get_gnetinfo()->sn, &check_wiz_netinfo.sn, sizeof(uint8_t) * 4),
memcmp(&get_gnetinfo()->gw, &check_wiz_netinfo.gw, sizeof(uint8_t) * 4),
memcmp(&get_gnetinfo()->dns, &check_wiz_netinfo.dns, sizeof(uint8_t) * 4),
memcmp(&get_gnetinfo()->dhcp, &check_wiz_netinfo.dhcp, sizeof(uint8_t)));
KPrintf("WIZCHIP set network information fail.\n");
return ERROR;
}
uint8_t tmpstr[6];
ctlwizchip(CW_GET_ID, (void *)tmpstr);
KPrintf("=== %s NET CONF ===\r\n", (char *)tmpstr);
KPrintf("MAC: %02X:%02X:%02X:%02X:%02X:%02X\r\n", get_gnetinfo()->mac[0],
get_gnetinfo()->mac[1], get_gnetinfo()->mac[2], get_gnetinfo()->mac[3],
get_gnetinfo()->mac[4], get_gnetinfo()->mac[5]);
KPrintf("SIP: %d.%d.%d.%d\r\n", get_gnetinfo()->ip[0], get_gnetinfo()->ip[1],
get_gnetinfo()->ip[2], get_gnetinfo()->ip[3]);
KPrintf("GAR: %d.%d.%d.%d\r\n", get_gnetinfo()->gw[0], get_gnetinfo()->gw[1],
get_gnetinfo()->gw[2], get_gnetinfo()->gw[3]);
KPrintf("SUB: %d.%d.%d.%d\r\n", get_gnetinfo()->sn[0], get_gnetinfo()->sn[1],
get_gnetinfo()->sn[2], get_gnetinfo()->sn[3]);
KPrintf("DNS: %d.%d.%d.%d\r\n", get_gnetinfo()->dns[0], get_gnetinfo()->dns[1],
get_gnetinfo()->dns[2], get_gnetinfo()->dns[3]);
KPrintf("======================\r\n");
if (memcmp(get_gnetinfo(), &check_wiz_netinfo, sizeof(wiz_NetInfo)) != 0) {
KPrintf(
"mac: %d; ip: %d; gw: %d; sn: %d; dns: %d; dhcp: %d;\n",
memcmp(&get_gnetinfo()->mac, &check_wiz_netinfo.mac, sizeof(uint8_t) * 6),
memcmp(&get_gnetinfo()->ip, &check_wiz_netinfo.ip, sizeof(uint8_t) * 4),
memcmp(&get_gnetinfo()->sn, &check_wiz_netinfo.sn, sizeof(uint8_t) * 4),
memcmp(&get_gnetinfo()->gw, &check_wiz_netinfo.gw, sizeof(uint8_t) * 4),
memcmp(&get_gnetinfo()->dns, &check_wiz_netinfo.dns, sizeof(uint8_t) * 4),
memcmp(&get_gnetinfo()->dhcp, &check_wiz_netinfo.dhcp, sizeof(uint8_t)));
KPrintf("WIZCHIP set network information fail.\n");
return ERROR;
}
uint8_t tmpstr[6];
ctlwizchip(CW_GET_ID, (void*)tmpstr);
KPrintf("=== %s NET CONF ===\r\n", (char*)tmpstr);
KPrintf("MAC: %02X:%02X:%02X:%02X:%02X:%02X\r\n", get_gnetinfo()->mac[0],
get_gnetinfo()->mac[1], get_gnetinfo()->mac[2], get_gnetinfo()->mac[3],
get_gnetinfo()->mac[4], get_gnetinfo()->mac[5]);
KPrintf("SIP: %d.%d.%d.%d\r\n", get_gnetinfo()->ip[0], get_gnetinfo()->ip[1],
get_gnetinfo()->ip[2], get_gnetinfo()->ip[3]);
KPrintf("GAR: %d.%d.%d.%d\r\n", get_gnetinfo()->gw[0], get_gnetinfo()->gw[1],
get_gnetinfo()->gw[2], get_gnetinfo()->gw[3]);
KPrintf("SUB: %d.%d.%d.%d\r\n", get_gnetinfo()->sn[0], get_gnetinfo()->sn[1],
get_gnetinfo()->sn[2], get_gnetinfo()->sn[3]);
KPrintf("DNS: %d.%d.%d.%d\r\n", get_gnetinfo()->dns[0], get_gnetinfo()->dns[1],
get_gnetinfo()->dns[2], get_gnetinfo()->dns[3]);
KPrintf("======================\r\n");
return EOK;
return EOK;
}
/****************** spi init ******************/
static struct Bus *w5500_spi_bus;
int w5500_spi_init() {
x_err_t ret = EOK;
static struct Bus* w5500_spi_bus;
int w5500_spi_init()
{
x_err_t ret = EOK;
w5500_spi_bus = BusFind(SPI_BUS_NAME_1);
w5500_spi_bus->owner_haldev =
BusFindDevice(w5500_spi_bus, SPI_1_DEVICE_NAME_0);
w5500_spi_bus->owner_driver = BusFindDriver(w5500_spi_bus, SPI_1_DRV_NAME);
w5500_spi_bus = BusFind(SPI_BUS_NAME_1);
w5500_spi_bus->owner_haldev = BusFindDevice(w5500_spi_bus, SPI_1_DEVICE_NAME_0);
w5500_spi_bus->owner_driver = BusFindDriver(w5500_spi_bus, SPI_1_DRV_NAME);
w5500_spi_bus->match(w5500_spi_bus->owner_driver,
w5500_spi_bus->owner_haldev);
w5500_spi_bus->match(w5500_spi_bus->owner_driver,
w5500_spi_bus->owner_haldev);
struct BusConfigureInfo configure_info;
struct SpiMasterParam spi_master_param;
spi_master_param.spi_data_bit_width = 8;
spi_master_param.spi_work_mode = SPI_MODE_0 | SPI_MSB;
spi_master_param.spi_maxfrequency = SPI_LORA_FREQUENCY;
spi_master_param.spi_data_endian = 0;
struct BusConfigureInfo configure_info;
struct SpiMasterParam spi_master_param;
spi_master_param.spi_data_bit_width = 8;
spi_master_param.spi_work_mode = SPI_MODE_0 | SPI_MSB;
spi_master_param.spi_maxfrequency = SPI_LORA_FREQUENCY;
spi_master_param.spi_data_endian = 0;
configure_info.configure_cmd = OPE_CFG;
configure_info.private_data = (void *)&spi_master_param;
ret = BusDrvConfigure(w5500_spi_bus->owner_driver, &configure_info);
if (ret) {
KPrintf("spi drv OPE_CFG error drv %8p cfg %8p\n",
configure_info.configure_cmd = OPE_CFG;
configure_info.private_data = (void*)&spi_master_param;
ret = BusDrvConfigure(w5500_spi_bus->owner_driver, &configure_info);
if (ret) {
KPrintf("spi drv OPE_CFG error drv %8p cfg %8p\n",
w5500_spi_bus->owner_driver, &spi_master_param);
return ERROR;
}
return ERROR;
}
configure_info.configure_cmd = OPE_INT;
ret = BusDrvConfigure(w5500_spi_bus->owner_driver, &configure_info);
if (ret) {
KPrintf("spi drv OPE_INT error drv %8p\n", w5500_spi_bus->owner_driver);
return ERROR;
}
configure_info.configure_cmd = OPE_INT;
ret = BusDrvConfigure(w5500_spi_bus->owner_driver, &configure_info);
if (ret) {
KPrintf("spi drv OPE_INT error drv %8p\n", w5500_spi_bus->owner_driver);
return ERROR;
}
return EOK;
return EOK;
}
void spi_write_byte(uint8_t tx_data) {
struct BusBlockWriteParam write_param;
write_param.buffer = &tx_data;
write_param.size = 1;
BusDevWriteData(w5500_spi_bus->owner_haldev, &write_param);
void spi_write_byte(uint8_t tx_data)
{
struct BusBlockWriteParam write_param;
uint8_t data = tx_data;
write_param.buffer = &data;
write_param.size = 1;
BusDevWriteData(w5500_spi_bus->owner_haldev, &write_param);
}
uint8_t spi_read_byte(void) {
uint8_t result = 0;
struct BusBlockReadParam read_param;
read_param.buffer = &result;
read_param.size = 1;
BusDevReadData(w5500_spi_bus->owner_haldev, &read_param);
return result;
uint8_t spi_read_byte(void)
{
uint8_t result = 0;
struct BusBlockReadParam read_param;
read_param.buffer = &result;
read_param.size = 1;
BusDevReadData(w5500_spi_bus->owner_haldev, &read_param);
return result;
}
void spi_write_burst(uint8_t *tx_buf, uint16_t len) {
struct BusBlockWriteParam write_param;
write_param.buffer = tx_buf;
write_param.size = len;
BusDevWriteData(w5500_spi_bus->owner_haldev, &write_param);
void spi_write_burst(uint8_t* tx_buf, uint16_t len)
{
struct BusBlockWriteParam write_param;
write_param.buffer = tx_buf;
write_param.size = len;
BusDevWriteData(w5500_spi_bus->owner_haldev, &write_param);
}
void spi_read_burst(uint8_t *rx_buf, uint16_t len) {
struct BusBlockReadParam read_param;
read_param.buffer = rx_buf;
read_param.size = len;
BusDevReadData(w5500_spi_bus->owner_haldev, &read_param);
void spi_read_burst(uint8_t* rx_buf, uint16_t len)
{
struct BusBlockReadParam read_param;
read_param.buffer = rx_buf;
read_param.size = len;
BusDevReadData(w5500_spi_bus->owner_haldev, &read_param);
}
/****************** chip init ******************/
void wiz_reset() {
gpiohs_set_drive_mode(WIZ_RST_PIN, GPIO_DM_OUTPUT);
gpiohs_set_pin(WIZ_RST_PIN, GPIO_PV_LOW);
MdelayKTask(20);
void wiz_reset()
{
gpiohs_set_drive_mode(WIZ_RST_PIN, GPIO_DM_OUTPUT);
gpiohs_set_pin(WIZ_RST_PIN, GPIO_PV_LOW);
MdelayKTask(20);
gpiohs_set_pin(WIZ_RST_PIN, GPIO_PV_HIGH);
MdelayKTask(20);
gpiohs_set_pin(WIZ_RST_PIN, GPIO_PV_HIGH);
MdelayKTask(20);
}
void wiz_spi_handler_reg() {
// spi ops registration
#if (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_SPI_VDM_) || \
(_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_SPI_FDM_)
/* register SPI device CS select callback function */
gpiohs_set_drive_mode(SPI1_CS0_PIN, GPIO_DM_OUTPUT);
reg_wizchip_cs_cbfunc(spi_select_cs, spi_deselete_cs);
void wiz_spi_handler_reg()
{
// spi ops registration
#if (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_SPI_VDM_) || (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_SPI_FDM_)
/* register SPI device CS select callback function */
gpiohs_set_drive_mode(SPI1_CS0_PIN, GPIO_DM_OUTPUT);
reg_wizchip_cs_cbfunc(spi_select_cs, spi_deselete_cs);
#else
#if (_WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_SIP_) != _WIZCHIP_IO_MODE_SIP_
#error "Unknown _WIZCHIP_IO_MODE_"
#else
reg_wizchip_cs_cbfunc(wizchip_select, wizchip_deselect);
reg_wizchip_cs_cbfunc(wizchip_select, wizchip_deselect);
#endif
#endif
reg_wizchip_spi_cbfunc(spi_read_byte, spi_write_byte);
reg_wizchip_cris_cbfunc(spi_enter_cris, spi_exit_cris);
reg_wizchip_spiburst_cbfunc(spi_read_burst, spi_write_burst);
reg_wizchip_spi_cbfunc(spi_read_byte, spi_write_byte);
reg_wizchip_cris_cbfunc(spi_enter_cris, spi_exit_cris);
reg_wizchip_spiburst_cbfunc(spi_read_burst, spi_write_burst);
}
int wiz_chip_cfg_init() {
uint8_t mem_size[2][8] = {{2, 2, 2, 2, 2, 2, 2, 2}, {2, 2, 2, 2, 2, 2, 2, 2}};
int wiz_chip_cfg_init()
{
uint8_t mem_size[2][8] = { { 2, 2, 2, 2, 2, 2, 2, 2 }, { 2, 2, 2, 2, 2, 2, 2, 2 } };
/* reset WIZnet chip internal PHY, configures PHY mode. */
if (ctlwizchip(CW_INIT_WIZCHIP, (void *)mem_size) == -1) {
KPrintf("WIZCHIP initialize failed.");
return ERROR;
}
/* reset WIZnet chip internal PHY, configures PHY mode. */
if (ctlwizchip(CW_INIT_WIZCHIP, (void*)mem_size) == -1) {
KPrintf("WIZCHIP initialize failed.");
return ERROR;
}
struct wiz_NetTimeout_t net_timeout;
net_timeout.retry_cnt = 5;
net_timeout.time_100us = 20000;
ctlnetwork(CN_SET_TIMEOUT, (void *)&net_timeout);
struct wiz_NetTimeout_t net_timeout;
net_timeout.retry_cnt = 5;
net_timeout.time_100us = 20000;
ctlnetwork(CN_SET_TIMEOUT, (void*)&net_timeout);
return EOK;
return EOK;
}
/****************** interrupt handle ******************/
void wiz_irq_handler() {}
int wiz_interrupt_init() {
int32_t ret = -ERROR;
struct Bus *pin_bus = PinBusInitGet();
struct PinParam pin_param;
struct BusConfigureInfo pin_configure_info;
pin_configure_info.configure_cmd = OPE_CFG;
pin_configure_info.private_data = (void *)&pin_param;
pin_param.cmd = GPIO_CONFIG_MODE;
pin_param.pin = BSP_WIZ_INT_PIN;
pin_param.mode = GPIO_CFG_INPUT_PULLUP;
ret = BusDrvConfigure(pin_bus->owner_driver, &pin_configure_info);
if (ret != EOK) {
KPrintf("config pin_param %d input failed!\n", pin_param.pin);
return -ERROR;
}
pin_param.cmd = GPIO_IRQ_REGISTER;
pin_param.pin = BSP_WIZ_INT_PIN;
pin_param.irq_set.irq_mode = GPIO_IRQ_EDGE_FALLING;
pin_param.irq_set.hdr = wiz_irq_handler;
pin_param.irq_set.args = NONE;
ret = BusDrvConfigure(pin_bus->owner_driver, &pin_configure_info);
if (ret != EOK) {
KPrintf("register pin_param %d irq failed!\n", pin_param.pin);
return -ERROR;
}
pin_param.cmd = GPIO_IRQ_DISABLE;
pin_param.pin = BSP_WIZ_INT_PIN;
ret = BusDrvConfigure(pin_bus->owner_driver, &pin_configure_info);
if (ret != EOK) {
KPrintf("disable pin_param %d irq failed!\n", pin_param.pin);
return -ERROR;
}
// 4. enable interuption
pin_param.cmd = GPIO_IRQ_ENABLE;
pin_param.pin = BSP_WIZ_INT_PIN;
ret = BusDrvConfigure(pin_bus->owner_driver, &pin_configure_info);
if (ret != EOK) {
KPrintf("enable pin_param %d irq failed!\n", pin_param.pin);
return -ERROR;
}
return EOK;
return EOK;
#ifdef BSP_USING_LWIP
#include <sys.h>
static inline void spi_if_clr(void)
{
setSn_IR(0, 0x1F);
setSIR(0);
}
int HwWiznetInit(void) {
wiz_reset();
void wiz_irq_handler()
{
static x_base eth_irq_lock;
eth_irq_lock = DISABLE_INTERRUPT();
if (EOK != w5500_spi_init()) {
return ERROR;
}
if (*get_eth_recv_sem() > 0) {
sys_sem_signal(get_eth_recv_sem());
}
wiz_spi_handler_reg();
ENABLE_INTERRUPT(eth_irq_lock);
}
#else
void wiz_irq_handler()
{
static x_base eth_irq_lock;
eth_irq_lock = DISABLE_INTERRUPT();
if (EOK != wiz_chip_cfg_init()) {
return ERROR;
}
printf("=");
uint8_t ir = getIR();
setSIR(0x00);
setIR(0x00);
network_init();
ENABLE_INTERRUPT(eth_irq_lock);
}
#endif
return EOK;
void wizchip_interrupt_init(uint8_t socket, void (*callback)(void*))
{
int ret_val;
uint8_t reg_val1;
reg_val1 = (SIK_CONNECTED | SIK_DISCONNECTED | SIK_RECEIVED | SIK_TIMEOUT); // except SendOK
ret_val = wiz_ctlsocket(socket, CS_SET_INTMASK, (void*)&reg_val1);
#if (_WIZCHIP_ == W5100S)
reg_val = (1 << socket);
#elif (_WIZCHIP_ == W5500)
uint16_t reg_val2 = ((1 << socket) << 8);
#endif
ret_val = ctlwizchip(CW_SET_INTRMASK, (void*)&reg_val2);
(void)ret_val;
}
int wiz_interrupt_init()
{
int32_t ret = -ERROR;
wizchip_interrupt_init(0, wiz_irq_handler);
struct Bus* pin_bus = PinBusInitGet();
struct PinParam pin_param;
struct BusConfigureInfo pin_configure_info;
pin_configure_info.configure_cmd = OPE_CFG;
pin_configure_info.private_data = (void*)&pin_param;
pin_param.cmd = GPIO_CONFIG_MODE;
pin_param.pin = BSP_WIZ_INT_PIN;
pin_param.mode = GPIO_CFG_INPUT_PULLUP;
ret = BusDrvConfigure(pin_bus->owner_driver, &pin_configure_info);
if (ret != EOK) {
KPrintf("config pin_param %d input failed!\n", pin_param.pin);
return -ERROR;
}
pin_param.cmd = GPIO_IRQ_REGISTER;
pin_param.pin = BSP_WIZ_INT_PIN;
pin_param.irq_set.irq_mode = GPIO_IRQ_EDGE_FALLING;
pin_param.irq_set.hdr = wiz_irq_handler;
pin_param.irq_set.args = NONE;
ret = BusDrvConfigure(pin_bus->owner_driver, &pin_configure_info);
if (ret != EOK) {
KPrintf("register pin_param %d irq failed!\n", pin_param.pin);
return -ERROR;
}
pin_param.cmd = GPIO_IRQ_DISABLE;
pin_param.pin = BSP_WIZ_INT_PIN;
ret = BusDrvConfigure(pin_bus->owner_driver, &pin_configure_info);
if (ret != EOK) {
KPrintf("disable pin_param %d irq failed!\n", pin_param.pin);
return -ERROR;
}
// 4. enable interuption
pin_param.cmd = GPIO_IRQ_ENABLE;
pin_param.pin = BSP_WIZ_INT_PIN;
ret = BusDrvConfigure(pin_bus->owner_driver, &pin_configure_info);
if (ret != EOK) {
KPrintf("enable pin_param %d irq failed!\n", pin_param.pin);
return -ERROR;
}
return EOK;
}
int HwWiznetInit(void)
{
wiz_reset();
if (EOK != w5500_spi_init()) {
return ERROR;
}
wiz_spi_handler_reg();
if (EOK != wiz_chip_cfg_init()) {
return ERROR;
}
extern uint8_t wiz_mac[6];
setSHAR(wiz_mac);
ctlwizchip(CW_RESET_PHY, 0);
wiz_interrupt_init(0, wiz_irq_handler);
setSn_RXBUF_SIZE(0, 16);
setSn_TXBUF_SIZE(0, 16);
#define SOCK_ANY_PORT_NUM 0xC000
setSn_MR(0, Sn_MR_MFEN | Sn_MR_MACRAW | Sn_MR_MIP6B | Sn_MR_MMB);
wiz_socket(0, Sn_MR_MACRAW, SOCK_ANY_PORT_NUM, SOCK_IO_NONBLOCK);
uint8_t sock_iomode = SOCK_IO_NONBLOCK;
wiz_ctlsocket(0, CS_SET_IOMODE, &sock_iomode);
uint8_t sock_sr = 0;
while (1) {
sock_sr = getSn_SR(0);
SYS_KDEBUG_LOG(WIZNET_DEBUG, ("[%s] sock_sr: %x, MACRAW: %x\n", __func__, sock_sr, SOCK_MACRAW));
if (sock_sr == SOCK_MACRAW) {
SYS_KDEBUG_LOG(WIZNET_DEBUG, ("Socket 0 MACRAW mode established\r\n"));
break;
}
}
network_init();
return EOK;
}

View File

@ -54,7 +54,7 @@
//! THE POSSIBILITY OF SUCH DAMAGE.
//
//*****************************************************************************
//#include <stdio.h>
// #include <stdio.h>
#include "w5500.h"
#define _W5500_SPI_VDM_OP_ 0x00
@ -65,191 +65,198 @@
#if (_WIZCHIP_ == 5500)
////////////////////////////////////////////////////
uint8_t WIZCHIP_READ(uint32_t AddrSel) {
uint8_t ret;
uint8_t spi_data[3];
uint8_t WIZCHIP_READ(uint32_t AddrSel)
{
uint8_t ret = 0;
uint8_t spi_data[3];
WIZCHIP_CRITICAL_ENTER();
WIZCHIP.CS._select();
WIZCHIP_CRITICAL_ENTER();
WIZCHIP.CS._select();
AddrSel |= (_W5500_SPI_READ_ | _W5500_SPI_VDM_OP_);
AddrSel |= (_W5500_SPI_READ_ | _W5500_SPI_VDM_OP_);
if (!WIZCHIP.IF.SPI._read_burst ||
!WIZCHIP.IF.SPI._write_burst) // byte operation
{
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x00FF0000) >> 16);
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x0000FF00) >> 8);
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x000000FF) >> 0);
} else // burst operation
{
spi_data[0] = (AddrSel & 0x00FF0000) >> 16;
spi_data[1] = (AddrSel & 0x0000FF00) >> 8;
spi_data[2] = (AddrSel & 0x000000FF) >> 0;
WIZCHIP.IF.SPI._write_burst(spi_data, 3);
}
ret = WIZCHIP.IF.SPI._read_byte();
WIZCHIP.CS._deselect();
WIZCHIP_CRITICAL_EXIT();
return ret;
}
void WIZCHIP_WRITE(uint32_t AddrSel, uint8_t wb) {
uint8_t spi_data[4];
WIZCHIP_CRITICAL_ENTER();
WIZCHIP.CS._select();
AddrSel |= (_W5500_SPI_WRITE_ | _W5500_SPI_VDM_OP_);
// if(!WIZCHIP.IF.SPI._read_burst || !WIZCHIP.IF.SPI._write_burst) // byte
// operation
if (!WIZCHIP.IF.SPI._write_burst) // byte operation
{
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x00FF0000) >> 16);
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x0000FF00) >> 8);
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x000000FF) >> 0);
WIZCHIP.IF.SPI._write_byte(wb);
} else // burst operation
{
spi_data[0] = (AddrSel & 0x00FF0000) >> 16;
spi_data[1] = (AddrSel & 0x0000FF00) >> 8;
spi_data[2] = (AddrSel & 0x000000FF) >> 0;
spi_data[3] = wb;
WIZCHIP.IF.SPI._write_burst(spi_data, 4);
}
WIZCHIP.CS._deselect();
WIZCHIP_CRITICAL_EXIT();
}
void WIZCHIP_READ_BUF(uint32_t AddrSel, uint8_t *pBuf, uint16_t len) {
uint8_t spi_data[3];
uint16_t i;
WIZCHIP_CRITICAL_ENTER();
WIZCHIP.CS._select();
AddrSel |= (_W5500_SPI_READ_ | _W5500_SPI_VDM_OP_);
if (!WIZCHIP.IF.SPI._read_burst ||
!WIZCHIP.IF.SPI._write_burst) // byte operation
{
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x00FF0000) >> 16);
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x0000FF00) >> 8);
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x000000FF) >> 0);
for (i = 0; i < len; i++)
pBuf[i] = WIZCHIP.IF.SPI._read_byte();
} else // burst operation
{
spi_data[0] = (AddrSel & 0x00FF0000) >> 16;
spi_data[1] = (AddrSel & 0x0000FF00) >> 8;
spi_data[2] = (AddrSel & 0x000000FF) >> 0;
WIZCHIP.IF.SPI._write_burst(spi_data, 3);
WIZCHIP.IF.SPI._read_burst(pBuf, len);
}
WIZCHIP.CS._deselect();
WIZCHIP_CRITICAL_EXIT();
}
void WIZCHIP_WRITE_BUF(uint32_t AddrSel, uint8_t *pBuf, uint16_t len) {
uint8_t spi_data[3];
uint16_t i;
WIZCHIP_CRITICAL_ENTER();
WIZCHIP.CS._select();
AddrSel |= (_W5500_SPI_WRITE_ | _W5500_SPI_VDM_OP_);
if (!WIZCHIP.IF.SPI._write_burst) // byte operation
{
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x00FF0000) >> 16);
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x0000FF00) >> 8);
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x000000FF) >> 0);
for (i = 0; i < len; i++)
WIZCHIP.IF.SPI._write_byte(pBuf[i]);
} else // burst operation
{
spi_data[0] = (AddrSel & 0x00FF0000) >> 16;
spi_data[1] = (AddrSel & 0x0000FF00) >> 8;
spi_data[2] = (AddrSel & 0x000000FF) >> 0;
WIZCHIP.IF.SPI._write_burst(spi_data, 3);
WIZCHIP.IF.SPI._write_burst(pBuf, len);
}
WIZCHIP.CS._deselect();
WIZCHIP_CRITICAL_EXIT();
}
uint16_t getSn_TX_FSR(uint8_t sn) {
uint16_t val = 0, val1 = 0;
do {
val1 = WIZCHIP_READ(Sn_TX_FSR(sn));
val1 = (val1 << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_TX_FSR(sn), 1));
if (val1 != 0) {
val = WIZCHIP_READ(Sn_TX_FSR(sn));
val = (val << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_TX_FSR(sn), 1));
if (!WIZCHIP.IF.SPI._read_burst || !WIZCHIP.IF.SPI._write_burst) // byte operation
{
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x00FF0000) >> 16);
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x0000FF00) >> 8);
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x000000FF) >> 0);
} else // burst operation
{
spi_data[0] = (AddrSel & 0x00FF0000) >> 16;
spi_data[1] = (AddrSel & 0x0000FF00) >> 8;
spi_data[2] = (AddrSel & 0x000000FF) >> 0;
WIZCHIP.IF.SPI._write_burst(spi_data, 3);
}
} while (val != val1);
return val;
ret = WIZCHIP.IF.SPI._read_byte();
WIZCHIP.CS._deselect();
WIZCHIP_CRITICAL_EXIT();
return ret;
}
uint16_t getSn_RX_RSR(uint8_t sn) {
uint16_t val = 0, val1 = 0;
void WIZCHIP_WRITE(uint32_t AddrSel, uint8_t wb)
{
uint8_t spi_data[4];
do {
val1 = WIZCHIP_READ(Sn_RX_RSR(sn));
val1 = (val1 << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_RX_RSR(sn), 1));
if (val1 != 0) {
val = WIZCHIP_READ(Sn_RX_RSR(sn));
val = (val << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_RX_RSR(sn), 1));
WIZCHIP_CRITICAL_ENTER();
WIZCHIP.CS._select();
AddrSel |= (_W5500_SPI_WRITE_ | _W5500_SPI_VDM_OP_);
// if(!WIZCHIP.IF.SPI._read_burst || !WIZCHIP.IF.SPI._write_burst) // byte
// operation
if (!WIZCHIP.IF.SPI._write_burst) // byte operation
{
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x00FF0000) >> 16);
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x0000FF00) >> 8);
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x000000FF) >> 0);
WIZCHIP.IF.SPI._write_byte(wb);
} else // burst operation
{
spi_data[0] = (AddrSel & 0x00FF0000) >> 16;
spi_data[1] = (AddrSel & 0x0000FF00) >> 8;
spi_data[2] = (AddrSel & 0x000000FF) >> 0;
spi_data[3] = wb;
WIZCHIP.IF.SPI._write_burst(spi_data, 4);
}
} while (val != val1);
return val;
WIZCHIP.CS._deselect();
WIZCHIP_CRITICAL_EXIT();
}
void wiz_send_data(uint8_t sn, uint8_t *wizdata, uint16_t len) {
uint16_t ptr = 0;
uint32_t addrsel = 0;
void WIZCHIP_READ_BUF(uint32_t AddrSel, uint8_t* pBuf, uint16_t len)
{
uint8_t spi_data[3];
uint16_t i;
if (len == 0)
return;
ptr = getSn_TX_WR(sn);
// M20140501 : implict type casting -> explict type casting
// addrsel = (ptr << 8) + (WIZCHIP_TXBUF_BLOCK(sn) << 3);
addrsel = ((uint32_t)ptr << 8) + (WIZCHIP_TXBUF_BLOCK(sn) << 3);
//
WIZCHIP_WRITE_BUF(addrsel, wizdata, len);
WIZCHIP_CRITICAL_ENTER();
WIZCHIP.CS._select();
ptr += len;
setSn_TX_WR(sn, ptr);
AddrSel |= (_W5500_SPI_READ_ | _W5500_SPI_VDM_OP_);
if (!WIZCHIP.IF.SPI._read_burst || !WIZCHIP.IF.SPI._write_burst) // byte operation
{
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x00FF0000) >> 16);
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x0000FF00) >> 8);
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x000000FF) >> 0);
for (i = 0; i < len; i++)
pBuf[i] = WIZCHIP.IF.SPI._read_byte();
} else // burst operation
{
spi_data[0] = (AddrSel & 0x00FF0000) >> 16;
spi_data[1] = (AddrSel & 0x0000FF00) >> 8;
spi_data[2] = (AddrSel & 0x000000FF) >> 0;
WIZCHIP.IF.SPI._write_burst(spi_data, 3);
WIZCHIP.IF.SPI._read_burst(pBuf, len);
}
WIZCHIP.CS._deselect();
WIZCHIP_CRITICAL_EXIT();
}
void wiz_recv_data(uint8_t sn, uint8_t *wizdata, uint16_t len) {
uint16_t ptr = 0;
uint32_t addrsel = 0;
void WIZCHIP_WRITE_BUF(uint32_t AddrSel, uint8_t* pBuf, uint16_t len)
{
uint8_t spi_data[3];
uint16_t i;
if (len == 0)
return;
ptr = getSn_RX_RD(sn);
// M20140501 : implict type casting -> explict type casting
// addrsel = ((ptr << 8) + (WIZCHIP_RXBUF_BLOCK(sn) << 3);
addrsel = ((uint32_t)ptr << 8) + (WIZCHIP_RXBUF_BLOCK(sn) << 3);
//
WIZCHIP_READ_BUF(addrsel, wizdata, len);
ptr += len;
WIZCHIP_CRITICAL_ENTER();
WIZCHIP.CS._select();
setSn_RX_RD(sn, ptr);
AddrSel |= (_W5500_SPI_WRITE_ | _W5500_SPI_VDM_OP_);
if (!WIZCHIP.IF.SPI._write_burst) // byte operation
{
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x00FF0000) >> 16);
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x0000FF00) >> 8);
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x000000FF) >> 0);
for (i = 0; i < len; i++)
WIZCHIP.IF.SPI._write_byte(pBuf[i]);
} else // burst operation
{
spi_data[0] = (AddrSel & 0x00FF0000) >> 16;
spi_data[1] = (AddrSel & 0x0000FF00) >> 8;
spi_data[2] = (AddrSel & 0x000000FF) >> 0;
WIZCHIP.IF.SPI._write_burst(spi_data, 3);
WIZCHIP.IF.SPI._write_burst(pBuf, len);
}
WIZCHIP.CS._deselect();
WIZCHIP_CRITICAL_EXIT();
}
void wiz_recv_ignore(uint8_t sn, uint16_t len) {
uint16_t ptr = 0;
uint16_t getSn_TX_FSR(uint8_t sn)
{
uint16_t val = 0, val1 = 0;
ptr = getSn_RX_RD(sn);
ptr += len;
setSn_RX_RD(sn, ptr);
do {
val1 = WIZCHIP_READ(Sn_TX_FSR(sn));
val1 = (val1 << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_TX_FSR(sn), 1));
if (val1 != 0) {
val = WIZCHIP_READ(Sn_TX_FSR(sn));
val = (val << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_TX_FSR(sn), 1));
}
} while (val != val1);
return val;
}
uint16_t getSn_RX_RSR(uint8_t sn)
{
uint16_t val = 0, val1 = 0;
do {
val1 = WIZCHIP_READ(Sn_RX_RSR(sn));
val1 = (val1 << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_RX_RSR(sn), 1));
if (val1 != 0) {
val = WIZCHIP_READ(Sn_RX_RSR(sn));
val = (val << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_RX_RSR(sn), 1));
}
} while (val != val1);
return val;
}
void wiz_send_data(uint8_t sn, uint8_t* wizdata, uint16_t len)
{
uint16_t ptr = 0;
uint32_t addrsel = 0;
if (len == 0)
return;
ptr = getSn_TX_WR(sn);
// M20140501 : implict type casting -> explict type casting
// addrsel = (ptr << 8) + (WIZCHIP_TXBUF_BLOCK(sn) << 3);
addrsel = ((uint32_t)ptr << 8) + (WIZCHIP_TXBUF_BLOCK(sn) << 3);
//
WIZCHIP_WRITE_BUF(addrsel, wizdata, len);
ptr += len;
setSn_TX_WR(sn, ptr);
}
void wiz_recv_data(uint8_t sn, uint8_t* wizdata, uint16_t len)
{
uint16_t ptr = 0;
uint32_t addrsel = 0;
if (len == 0)
return;
ptr = getSn_RX_RD(sn);
// M20140501 : implict type casting -> explict type casting
// addrsel = ((ptr << 8) + (WIZCHIP_RXBUF_BLOCK(sn) << 3);
addrsel = ((uint32_t)ptr << 8) + (WIZCHIP_RXBUF_BLOCK(sn) << 3);
//
WIZCHIP_READ_BUF(addrsel, wizdata, len);
ptr += len;
setSn_RX_RD(sn, ptr);
}
void wiz_recv_ignore(uint8_t sn, uint16_t len)
{
uint16_t ptr = 0;
ptr = getSn_RX_RD(sn);
ptr += len;
setSn_RX_RD(sn, ptr);
}
#endif

View File

@ -0,0 +1,248 @@
/**
* Copyright (c) 2022 WIZnet Co.,Ltd
*
* SPDX-License-Identifier: BSD-3-Clause
*/
/**
* ----------------------------------------------------------------------------------------------------
* Includes
* ----------------------------------------------------------------------------------------------------
*/
#include <stdio.h>
#include "connect_ethernet.h"
#include "socket.h"
#include "netif/etharp.h"
#include <sys.h>
#include <xs_kdbg.h>
#include <xizi.h>
/**
* ----------------------------------------------------------------------------------------------------
* Macros
* ----------------------------------------------------------------------------------------------------
*/
/**
* ----------------------------------------------------------------------------------------------------
* Variables
* ----------------------------------------------------------------------------------------------------
*/
uint8_t wiz_mac[6] = { 0x00, 0x08, 0xDC, 0x12, 0x34, 0x56 };
static const uint32_t ethernet_polynomial_le = 0xedb88320U;
static sys_mutex_t wiz_trans_mtx;
/**
* ----------------------------------------------------------------------------------------------------
* Functions
* ----------------------------------------------------------------------------------------------------
*/
void* ethernetif_config_enet_set(uint8_t enet_port)
{
return NONE;
}
void Time_Update_LwIP(void)
{
// no need to do
}
static inline void spi_if_clr(void)
{
setSn_IR(0, 0x1F);
setSIR(0);
}
// macraw func
uint16_t macraw_send(const uint8_t* buf, uint16_t len)
{
uint8_t sock_num = 0;
uint16_t ret = 0;
if (len > getSn_TxMAX(sock_num)) {
ret = getSn_TxMAX(sock_num);
} else {
ret = len;
}
wiz_send_data(sock_num, (uint8_t*)buf, len);
WIZCHIP_WRITE(Sn_CR(sock_num), Sn_CR_SEND);
while (WIZCHIP_READ(Sn_CR(sock_num))) {
}
while (WIZCHIP_READ(Sn_IR(sock_num)) & Sn_IR_SENDOK != Sn_IR_SENDOK) {
}
WIZCHIP_WRITE(Sn_IR(sock_num), Sn_IR_SENDOK);
return ret;
}
uint16_t macraw_recv(uint8_t* buf, uint16_t len)
{
uint8_t sock_num = 0;
uint16_t lowlevel_len = getSn_RX_RSR(sock_num);
if (lowlevel_len <= 0 || len <= 0) {
return 0;
}
uint16_t data_len = 0;
uint8_t macraw_head[2];
uint16_t ptr = getSn_RX_RD(sock_num);
uint32_t addrsel = ((uint32_t)ptr << 8) + (WIZCHIP_RXBUF_BLOCK(sock_num) << 3);
WIZCHIP_READ_BUF(addrsel, macraw_head, 2);
ptr += 2;
data_len = (macraw_head[0] << 8) + macraw_head[1] - 2;
if (data_len > 1514) {
KPrintf("[%s:%d] Info: data recved oversize: %d\n", __func__, __LINE__, data_len);
wiz_recv_ignore(sock_num, data_len);
// wiz_sock_close(sock_num);
// wiz_socket(sock_num, Sn_MR_MACRAW, 0xC000, 0);
return 0;
}
addrsel = ((uint32_t)ptr << 8) + (WIZCHIP_RXBUF_BLOCK(sock_num) << 3);
WIZCHIP_READ_BUF(addrsel, buf, data_len);
ptr += data_len;
setSn_RX_RD(sock_num, ptr);
WIZCHIP_WRITE(Sn_CR(sock_num), Sn_CR_RECV);
while (WIZCHIP_READ(Sn_CR(sock_num)))
;
return data_len;
}
void netif_link_callback(struct netif* netif)
{
printf("netif link status changed %s\n", netif_is_link_up(netif) ? "up" : "down");
}
void netif_status_callback(struct netif* netif)
{
printf("netif status changed %s\n", ip4addr_ntoa(netif_ip4_addr(netif)));
}
static int32_t wiz_transmit_pbuf(struct pbuf* p)
{
static uint8_t addr[4] = { 0xFF, 0xFF, 0xFF, 0xFF };
int32_t send_ret = 0;
while (1) {
spi_if_clr();
if ((send_ret = wiz_sock_sendto(0, (uint8_t*)p->payload, p->len, addr, 0)) <= 0) {
SYS_KDEBUG_LOG(WIZNET_DEBUG, ("[%s] data send failed: %d, sock: %x\n", __func__, send_ret, getSn_SR(0)));
return -ERROR;
}
if (p->len == p->tot_len) {
break;
}
p = p->next;
}
return EOK;
}
static struct pbuf* wiz_read_receive_pbuf(struct pbuf* buf)
{
#define RX_FRAME_SIZE 1542
static uint8_t rx_frame[RX_FRAME_SIZE];
static uint8_t addr[4] = { 0xFF, 0xFF, 0xFF, 0xFF };
uint16_t port = 0;
uint16_t lowlevel_len = getSn_RX_RSR(0);
if (lowlevel_len <= 0) {
return NULL;
}
int32_t data_len = wiz_sock_recvfrom(0, rx_frame, RX_FRAME_SIZE, addr, &port);
if (data_len > 0 && data_len <= RX_FRAME_SIZE) {
buf = pbuf_alloc(PBUF_RAW, data_len, PBUF_POOL);
if (buf == NULL) {
return NULL;
}
memcpy(buf->payload, rx_frame, data_len);
} else {
return NULL;
}
return buf;
}
void ethernetif_input(void* netif_arg)
{
struct netif* netif = (struct netif*)netif_arg;
struct pbuf* p = NULL;
for (;;) {
sys_arch_sem_wait(get_eth_recv_sem(), WAITING_FOREVER);
while (1) {
sys_mutex_lock(&wiz_trans_mtx);
spi_if_clr();
p = NULL;
p = wiz_read_receive_pbuf(p);
sys_mutex_unlock(&wiz_trans_mtx);
if (p != NULL) {
// SYS_KDEBUG_LOG(WIZNET_DEBUG, ("[%s:%d] Info Recved package with size %d\n", __func__, __LINE__, p->len));
if (ERR_OK != netif->input(p, netif)) {
pbuf_free(p);
}
p = NULL;
} else {
break;
}
}
}
}
static err_t spi_if_linkoutput(struct netif* netif, struct pbuf* p)
{
sys_mutex_lock(&wiz_trans_mtx);
if (!(getSn_SR(0) & SOCK_MACRAW)) {
SYS_KDEBUG_LOG(WIZNET_DEBUG, ("[%s:%d] err socket state %d\n", __func__, __LINE__, p->len));
wiz_sock_close(0);
setSn_MR(0, Sn_MR_MFEN | Sn_MR_MACRAW | Sn_MR_MIP6B | Sn_MR_MMB);
wiz_socket(0, Sn_MR_MACRAW, 0, SOCK_IO_NONBLOCK);
}
int32_t ret = wiz_transmit_pbuf(p);
sys_mutex_unlock(&wiz_trans_mtx);
if (ret != EOK) {
return ERR_USE;
}
/* TODO: Set up result value */
return ERR_OK;
}
err_t netif_initialize(struct netif* netif)
{
sys_mutex_new(&wiz_trans_mtx);
netif->linkoutput = spi_if_linkoutput;
// netif->linkoutput = netif_output;
netif->output = etharp_output;
netif->mtu = ETHERNET_MTU;
netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_ETHERNET | NETIF_FLAG_IGMP | NETIF_FLAG_MLD6;
netif->flags |= NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP;
SMEMCPY(netif->hwaddr, wiz_mac, sizeof(netif->hwaddr));
netif->hwaddr_len = sizeof(netif->hwaddr);
netif->name[0] = 'e';
netif->name[1] = '0';
return ERR_OK;
}

View File

@ -304,7 +304,7 @@ __exit:
if (recv_data) free(recv_data);
}
void iperf_usage(void)
static void iperf_usage(void)
{
KPrintf("Usage: iperf [-s|-c host] [options] [multi-threaded]\n");
KPrintf(" iperf [-h|--stop]\n");
@ -326,7 +326,7 @@ void iperf_usage(void)
return;
}
int iperf(int argc, char **argv)
int wiz_iperf(int argc, char** argv)
{
int mode = 0; /* server mode */
char *host = NULL;
@ -460,6 +460,6 @@ __usage:
return 0;
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
iperf, iperf,
iperf throughput test);
wiz_iperf, wiz_iperf,
iperf throughput test);
#endif

View File

@ -12,8 +12,8 @@
#define PING_BIND_PORT 3000
PINGMSGR PingRequest = {0};
PINGMSGR PingReply = {0};
PINGMSGR PingRequest = { 0 };
PINGMSGR PingReply = { 0 };
static uint16_t ping_RandomID = 0x1234;
static uint16_t ping_RandomSeqNum = 0x4321;
@ -21,7 +21,7 @@ uint8_t ping_reply_received = 0;
uint8_t ping_req = 0;
uint8_t ping_rep = 0;
uint8_t ping_cnt = 0;
uint8_t ping_rep_buf[150] = {0};
uint8_t ping_rep_buf[150] = { 0 };
// ping状态机
#define PING_STA_FREE 0
@ -32,41 +32,43 @@ uint8_t ping_rep_buf[150] = {0};
uint8_t ping_sta = PING_STA_FREE;
//当前ping的设备的序号
// 当前ping的设备的序号
uint8_t ping_socket = 0;
#define bswap_16(A) ((((uint16)(A)&0xff00) >> 8) | (((uint16)(A)&0x00ff) << 8))
#define bswap_16(A) ((((uint16)(A) & 0xff00) >> 8) | (((uint16)(A) & 0x00ff) << 8))
uint16_t htons(uint16_t n) {
union {
int i;
char c;
} u = {1};
return u.c ? bswap_16(n) : n;
uint16_t htons(uint16_t n)
{
union {
int i;
char c;
} u = { 1 };
return u.c ? bswap_16(n) : n;
}
uint16_t checksum(uint8_t *src, uint32_t len) {
uint16_t sum, tsum, i, j;
uint32_t lsum;
uint16_t checksum(uint8_t* src, uint32_t len)
{
uint16_t sum, tsum, i, j;
uint32_t lsum;
j = len >> 1;
lsum = 0;
j = len >> 1;
lsum = 0;
for (i = 0; i < j; i++) {
tsum = src[i * 2];
tsum = tsum << 8;
tsum += src[i * 2 + 1];
lsum += tsum;
}
for (i = 0; i < j; i++) {
tsum = src[i * 2];
tsum = tsum << 8;
tsum += src[i * 2 + 1];
lsum += tsum;
}
if (len % 2) {
tsum = src[i * 2];
lsum += (tsum << 8);
}
if (len % 2) {
tsum = src[i * 2];
lsum += (tsum << 8);
}
sum = lsum;
sum = ~(sum + (lsum >> 16));
return (uint16_t)sum;
sum = lsum;
sum = ~(sum + (lsum >> 16));
return (uint16_t)sum;
}
/**
@ -76,64 +78,64 @@ uint16_t checksum(uint8_t *src, uint32_t len) {
*@param pCount- ping的次数
*@return ping成功次数
*/
uint8_t ping_count(uint8_t sn, uint16_t pCount, uint8_t *addr) {
uint16_t rlen, cnt, i;
uint8_t ping_count(uint8_t sn, uint16_t pCount, uint8_t* addr)
{
uint16_t rlen, cnt, i;
ping_reply_received = 0;
ping_req = 0;
ping_rep = 0;
KPrintf("Ping:%d.%d.%d.%d\r\n", (addr[0]), (addr[1]), (addr[2]), (addr[3]));
ping_reply_received = 0;
ping_req = 0;
ping_rep = 0;
KPrintf("Ping:%d.%d.%d.%d, socket state: %x\r\n", (addr[0]), (addr[1]), (addr[2]), (addr[3]), getSn_SR(sn));
for (i = 0; i < pCount + 1; i++) /*循环ping pCount次*/
{
switch (getSn_SR(sn)) /*获取socket状态*/
for (i = 0; i < pCount + 1; i++) /*循环ping pCount次*/
{
case SOCK_CLOSED: /*socket关闭状态*/
{
wiz_sock_close(sn);
/* Create Socket */
IINCHIP_WRITE(Sn_PROTO(sn), IPPROTO_ICMP); /*设置ICMP 协议*/
if (wiz_socket(sn, Sn_MR_IPRAW, PING_BIND_PORT, 0) !=
0) /*判断ip raw模式socket是否开启*/
switch (getSn_SR(sn)) /*获取socket状态*/
{
}
/* Check socket register */
while (getSn_SR(sn) != SOCK_IPRAW) {
MdelayKTask(50);
};
break;
}
case SOCK_IPRAW: /*ip raw模式*/
{
cnt = 0;
ping_request(sn, addr); /*发送Ping请求*/
ping_req++;
while (1) {
if ((rlen = getSn_RX_RSR(sn)) > 0) {
rlen = ping_reply(sn, addr, rlen); /*获取回复信息*/
ping_rep++;
if (ping_reply_received) {
break;
case SOCK_CLOSED: /*socket关闭状态*/
{
wiz_sock_close(sn);
/* Create Socket */
IINCHIP_WRITE(Sn_PROTO(sn), IPPROTO_ICMP); /*设置ICMP 协议*/
if (wiz_socket(sn, Sn_MR_IPRAW, PING_BIND_PORT, 0) != 0) /*判断ip raw模式socket是否开启*/
{
}
}
if ((cnt > 300)) {
cnt = 0;
/* Check socket register */
while (getSn_SR(sn) != SOCK_IPRAW) {
MdelayKTask(50);
};
break;
} else {
cnt++;
MdelayKTask(10);
}
}
break;
}
default:
break;
case SOCK_IPRAW: /*ip raw模式*/
{
cnt = 0;
ping_request(sn, addr); /*发送Ping请求*/
ping_req++;
while (1) {
if ((rlen = getSn_RX_RSR(sn)) > 0) {
rlen = ping_reply(sn, addr, rlen); /*获取回复信息*/
ping_rep++;
if (ping_reply_received) {
break;
}
}
if ((cnt > 300)) {
cnt = 0;
break;
} else {
cnt++;
MdelayKTask(10);
}
}
break;
}
default:
break;
}
if (ping_req >= pCount) {
wiz_sock_close(sn);
}
}
if (ping_req >= pCount) {
wiz_sock_close(sn);
}
}
return ping_rep;
return ping_rep;
}
/**
@ -142,31 +144,30 @@ uint8_t ping_count(uint8_t sn, uint16_t pCount, uint8_t *addr) {
*@param addr- P地址
*@return
*/
uint8_t ping_request(uint8_t sn, uint8_t *addr) {
uint8_t *buffer;
uint16_t i, temp_len = 0;
ping_reply_received = 0; /*ping 回复初始化标志位*/
PingRequest.Type = PING_REQUEST; /*Ping-Request*/
PingRequest.Code = CODE_ZERO; /*总是 '0'*/
PingRequest.ID = htons(ping_RandomID++); /*设置ping响应ID为随机的整型变量*/
PingRequest.SeqNum =
htons(ping_RandomSeqNum++); /*设置ping响应的序列号为随机整形变量*/
for (i = 0; i < PING_BUF_LEN; i++) {
PingRequest.Data[i] = (i) % 8; /*ping相应的数在'0'~'8*/
}
PingRequest.CheckSum = 0;
/* 计算响应次数*/
PingRequest.CheckSum =
htons(checksum((uint8_t *)&PingRequest, sizeof(PingRequest)));
uint8_t ping_request(uint8_t sn, uint8_t* addr)
{
uint8_t* buffer;
/*发送ping响应到目的方 */
if (wiz_sock_sendto(sn, (uint8_t *)&PingRequest, sizeof(PingRequest), addr,
PING_BIND_PORT) == 0) {
KPrintf("Fail to send ping-reply packet\r\n");
} else {
KPrintf("ping send\n");
}
return 0;
uint16_t i, temp_len = 0;
ping_reply_received = 0; /*ping 回复初始化标志位*/
PingRequest.Type = PING_REQUEST; /*Ping-Request*/
PingRequest.Code = CODE_ZERO; /*总是 '0'*/
PingRequest.ID = htons(ping_RandomID++); /*设置ping响应ID为随机的整型变量*/
PingRequest.SeqNum = htons(ping_RandomSeqNum++); /*设置ping响应的序列号为随机整形变量*/
for (i = 0; i < PING_BUF_LEN; i++) {
PingRequest.Data[i] = (i) % 8; /*ping相应的数在'0'~'8*/
}
PingRequest.CheckSum = 0;
/* 计算响应次数*/
PingRequest.CheckSum = htons(checksum((uint8_t*)&PingRequest, sizeof(PingRequest)));
/*发送ping响应到目的方 */
if (wiz_sock_sendto(sn, (uint8_t*)&PingRequest, sizeof(PingRequest), addr, PING_BIND_PORT) == 0) {
KPrintf("Fail to send ping-reply packet\r\n");
} else {
KPrintf("ping send\n");
}
return 0;
}
/**
@ -175,82 +176,84 @@ uint8_t ping_request(uint8_t sn, uint8_t *addr) {
*@param addr- Ping地址
*@return
*/
uint8_t ping_reply(uint8_t sn, uint8_t *addr, uint16_t rlen) {
uint16_t tmp_checksum;
uint16_t len;
uint16_t i;
uint8_t ping_reply(uint8_t sn, uint8_t* addr, uint16_t rlen)
{
uint16_t tmp_checksum;
uint16_t len;
uint16_t i;
uint16_t port = PING_BIND_PORT;
PINGMSGR PingReply;
uint16_t port = PING_BIND_PORT;
PINGMSGR PingReply;
memset(ping_rep_buf, 0, sizeof(ping_rep_buf));
len = wiz_sock_recvfrom(sn, ping_rep_buf, rlen, addr,
&port); /*从目的端接收数据*/
memset(ping_rep_buf, 0, sizeof(ping_rep_buf));
len = wiz_sock_recvfrom(sn, ping_rep_buf, rlen, addr,
&port); /*从目的端接收数据*/
if (ping_rep_buf[0] == PING_REPLY) {
PingReply.Type = ping_rep_buf[0];
PingReply.Code = ping_rep_buf[1];
PingReply.CheckSum = (ping_rep_buf[3] << 8) + ping_rep_buf[2];
PingReply.ID = (ping_rep_buf[5] << 8) + ping_rep_buf[4];
PingReply.SeqNum = (ping_rep_buf[7] << 8) + ping_rep_buf[6];
if (ping_rep_buf[0] == PING_REPLY) {
PingReply.Type = ping_rep_buf[0];
PingReply.Code = ping_rep_buf[1];
PingReply.CheckSum = (ping_rep_buf[3] << 8) + ping_rep_buf[2];
PingReply.ID = (ping_rep_buf[5] << 8) + ping_rep_buf[4];
PingReply.SeqNum = (ping_rep_buf[7] << 8) + ping_rep_buf[6];
for (i = 0; i < len - 8; i++) {
PingReply.Data[i] = ping_rep_buf[8 + i];
}
tmp_checksum = ~checksum(ping_rep_buf, len); /*检查ping回复的次数*/
if (tmp_checksum != 0xffff) {
KPrintf("tmp_checksum = %x\r\n", tmp_checksum);
for (i = 0; i < len - 8; i++) {
PingReply.Data[i] = ping_rep_buf[8 + i];
}
tmp_checksum = ~checksum(ping_rep_buf, len); /*检查ping回复的次数*/
if (tmp_checksum != 0xffff) {
KPrintf("tmp_checksum = %x\r\n", tmp_checksum);
} else {
KPrintf("Reply from %3d.%3d.%3d.%3d ID=%x Byte=%d\r\n\r\n", (addr[0]),
(addr[1]), (addr[2]), (addr[3]), htons(PingReply.ID), (rlen + 6));
ping_reply_received = 1; /*当退出ping回复循环时设置ping回复标志为1*/
}
} else if (ping_rep_buf[0] == PING_REQUEST) {
PingReply.Code = ping_rep_buf[1];
PingReply.Type = ping_rep_buf[2];
PingReply.CheckSum = (ping_rep_buf[3] << 8) + ping_rep_buf[2];
PingReply.ID = (ping_rep_buf[5] << 8) + ping_rep_buf[4];
PingReply.SeqNum = (ping_rep_buf[7] << 8) + ping_rep_buf[6];
for (i = 0; i < len - 8; i++) {
PingReply.Data[i] = ping_rep_buf[8 + i];
}
tmp_checksum = PingReply.CheckSum; /*检查ping回复次数*/
PingReply.CheckSum = 0;
if (tmp_checksum != PingReply.CheckSum) {
KPrintf(" \n CheckSum is in correct %x shold be %x \n", (tmp_checksum),
htons(PingReply.CheckSum));
} else {
}
KPrintf(
" Request from %d.%d.%d.%d ID:%x SeqNum:%x :data size %d bytes\r\n",
(addr[0]), (addr[1]), (addr[2]), (addr[3]), (PingReply.ID),
(PingReply.SeqNum), (rlen + 6));
ping_reply_received = 1; /* 当退出ping回复循环时设置ping回复标志为1
*/
} else {
KPrintf("Reply from %3d.%3d.%3d.%3d ID=%x Byte=%d\r\n\r\n", (addr[0]),
(addr[1]), (addr[2]), (addr[3]), htons(PingReply.ID), (rlen + 6));
ping_reply_received = 1; /*当退出ping回复循环时设置ping回复标志为1*/
KPrintf(" Unkonwn msg. \n");
}
} else if (ping_rep_buf[0] == PING_REQUEST) {
PingReply.Code = ping_rep_buf[1];
PingReply.Type = ping_rep_buf[2];
PingReply.CheckSum = (ping_rep_buf[3] << 8) + ping_rep_buf[2];
PingReply.ID = (ping_rep_buf[5] << 8) + ping_rep_buf[4];
PingReply.SeqNum = (ping_rep_buf[7] << 8) + ping_rep_buf[6];
for (i = 0; i < len - 8; i++) {
PingReply.Data[i] = ping_rep_buf[8 + i];
}
tmp_checksum = PingReply.CheckSum; /*检查ping回复次数*/
PingReply.CheckSum = 0;
if (tmp_checksum != PingReply.CheckSum) {
KPrintf(" \n CheckSum is in correct %x shold be %x \n", (tmp_checksum),
htons(PingReply.CheckSum));
} else {
}
KPrintf(
" Request from %d.%d.%d.%d ID:%x SeqNum:%x :data size %d bytes\r\n",
(addr[0]), (addr[1]), (addr[2]), (addr[3]), (PingReply.ID),
(PingReply.SeqNum), (rlen + 6));
ping_reply_received = 1; /* 当退出ping回复循环时设置ping回复标志为1
*/
} else {
KPrintf(" Unkonwn msg. \n");
}
return 0;
return 0;
}
void wiz_ping_test(int argc, char *argv[]) {
uint32_t tmp_ip[4];
uint8_t target_ip[4];
uint16_t pCount = 5; //默认ping 5次
void wiz_ping_test(int argc, char* argv[])
{
uint32_t tmp_ip[4];
uint8_t target_ip[4];
uint16_t pCount = 5; // 默认ping 5次
if (argc >= 2) {
KPrintf("This is a Ping test: %s\n", argv[1]);
sscanf(argv[1], "%d.%d.%d.%d", &tmp_ip[0], &tmp_ip[1], &tmp_ip[2],
&tmp_ip[3]);
target_ip[0] = (uint8_t)tmp_ip[0];
target_ip[1] = (uint8_t)tmp_ip[1];
target_ip[2] = (uint8_t)tmp_ip[2];
target_ip[3] = (uint8_t)tmp_ip[3];
if (argc >= 3){
pCount = atoi(argv[2]); //如果ip后面跟具体的数字,代表ping的次数
if (argc >= 2) {
KPrintf("This is a Ping test: %s\n", argv[1]);
sscanf(argv[1], "%d.%d.%d.%d", &tmp_ip[0], &tmp_ip[1], &tmp_ip[2],
&tmp_ip[3]);
target_ip[0] = (uint8_t)tmp_ip[0];
target_ip[1] = (uint8_t)tmp_ip[1];
target_ip[2] = (uint8_t)tmp_ip[2];
target_ip[3] = (uint8_t)tmp_ip[3];
if (argc >= 3) {
pCount = atoi(argv[2]); // 如果ip后面跟具体的数字,代表ping的次数
}
ping_count(ping_socket, pCount, target_ip);
}
ping_count(ping_socket, pCount, target_ip);
}
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
ping, wiz_ping_test, ping to given addr);
wiz_ping, wiz_ping_test, ping to given addr);

View File

@ -0,0 +1,118 @@
/**
* Copyright (c) 2022 WIZnet Co.,Ltd
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _W5x00_LWIP_H_
#define _W5x00_LWIP_H_
/**
* ----------------------------------------------------------------------------------------------------
* Includes
* ----------------------------------------------------------------------------------------------------
*/
#include "lwip/netif.h"
/**
* ----------------------------------------------------------------------------------------------------
* Macros
* ----------------------------------------------------------------------------------------------------
*/
/* LWIP */
#define ETHERNET_MTU 1500
#define SOCKET_MACRAW 0
/**
* ----------------------------------------------------------------------------------------------------
* Variables
* ----------------------------------------------------------------------------------------------------
*/
/**
* ----------------------------------------------------------------------------------------------------
* Functions
* ----------------------------------------------------------------------------------------------------
*/
/*! \brief send an ethernet packet
* \ingroup w5x00_lwip
*
* It is used to send outgoing data to the socket.
*
* \param sn socket number
* \param buf a pointer to the data to send
* \param len the length of data in packet
* \return he sent data size
*/
int32_t send_lwip(uint8_t sn, uint8_t* buf, uint16_t len);
/*! \brief read an ethernet packet
* \ingroup w5x00_lwip
*
* It is used to read incoming data from the socket.
*
* \param sn socket number
* \param buf a pointer buffer to read incoming data
* \param len the length of the data in the packet
* \return the real received data size
*/
int32_t recv_lwip(uint8_t sn, uint8_t* buf, uint16_t len);
/*! \brief callback function
* \ingroup w5x00_lwip
*
* This function is called by ethernet_output() when it wants
* to send a packet on the interface. This function outputs
* the pbuf as-is on the link medium.
*
* \param netif a pre-allocated netif structure
* \param p main packet buffer struct
* \return ERR_OK if data was sent.
*/
err_t netif_output(struct netif* netif, struct pbuf* p);
/*! \brief callback function
* \ingroup w5x00_lwip
*
* Callback function for link.
*
* \param netif a pre-allocated netif structure
*/
void netif_link_callback(struct netif* netif);
/*! \brief callback function
* \ingroup w5x00_lwip
*
* Callback function for status.
*
* \param netif a pre-allocated netif structure
*/
void netif_status_callback(struct netif* netif);
/*! \brief callback function
* \ingroup w5x00_lwip
*
* Callback function that initializes the interface.
*
* \param netif a pre-allocated netif structure
* \return ERR_OK if Network interface initialized
*/
err_t netif_initialize(struct netif* netif);
/*! \brief ethernet frame cyclic redundancy check
* \ingroup w5x00_lwip
*
* Perform cyclic redundancy check on ethernet frame
*
* \param data a pointer to the ethernet frame
* \param length the total length of ethernet frame
* \return an ethernet frame cyclic redundancy check result value
*/
static uint32_t ethernet_frame_crc(const uint8_t* data, int length);
void ethernetif_input(void* netif_arg);
void* ethernetif_config_enet_set(uint8_t enet_port);
void Time_Update_LwIP(void);
#define NETIF_ENET0_INIT_FUNC netif_initialize
#endif /* _W5x00_LWIP_H_ */

View File

@ -191,8 +191,8 @@ static uint32 SpiWriteData(struct SpiHardwareDevice *spi_dev, struct SpiDataStan
for (i = 0; i < spi_datacfg->length; i++) {
tx_buff[i] = ((uint8_t *)spi_datacfg->tx_buff)[i];
}
dmac_set_single_mode(dev_param->spi_dma_param->spi_dmac_txchannel, tx_buff, (void *)(&spi_instance[device_master_id]->dr[0]), DMAC_ADDR_INCREMENT, DMAC_ADDR_NOCHANGE,
DMAC_MSIZE_4, DMAC_TRANS_WIDTH_32, spi_datacfg->length);
dmac_set_single_mode(dev_param->spi_dma_param->spi_dmac_txchannel, tx_buff, (void*)(&spi_instance[device_master_id]->dr[0]), DMAC_ADDR_INCREMENT, DMAC_ADDR_NOCHANGE,
DMAC_MSIZE_4, DMAC_TRANS_WIDTH_32, spi_datacfg->length);
}
spi_instance[device_master_id]->ser = 1U << dev_param->spi_slave_param->spi_cs_select_id;
@ -202,9 +202,9 @@ static uint32 SpiWriteData(struct SpiHardwareDevice *spi_dev, struct SpiDataStan
spi_instance[device_master_id]->ssienr = 0x00;
transfer_done:
if (tx_buff) {
x_free(tx_buff);
}
if (tx_buff != NULL) {
x_free(tx_buff);
}
}
if (spi_datacfg->spi_cs_release) {

View File

@ -1,7 +1,7 @@
if BSP_USING_HWTIMER
config HWTIMER_BUS_NAME_1
string "hwtimer bus name"
default "hwtim1"
default "timer0"
menuconfig ENABLE_TIM1
bool "enable TIM1"
@ -10,10 +10,10 @@ if BSP_USING_HWTIMER
if ENABLE_TIM1
config HWTIMER_1_DEVICE_NAME_1
string "TIM1 dev name"
default "hwtim1_dev1"
default "timer0_dev0"
config HWTIMER_DRIVER_NAME_1
string "TIM1 drv name"
default "hwtim1_drv"
default "timer0_drv"
endif
endif

View File

@ -42,16 +42,10 @@ uint32 HwtimerOpen(void *dev)
{
struct HwtimerHardwareDevice *hwtimer_dev = dev;
ptim2_cb_info = &hwtimer_dev->hwtimer_param.cb_info;
plic_init();
sysctl_enable_irq();
timer_init(TIMER_DEVICE_1);
size_t real_time = timer_set_interval(TIMER_DEVICE_1, TIMER_CHANNEL_1, hwtimer_dev->hwtimer_param.period_millisecond *1000);
KPrintf("timer_set_interval -- real_time : %ld\n", real_time);
timer_irq_register(TIMER_DEVICE_1, TIMER_CHANNEL_1, !hwtimer_dev->hwtimer_param.repeat, 1, timer_callback, NULL);
timer_set_enable(TIMER_DEVICE_1, TIMER_CHANNEL_1, 1);
return EOK;
@ -73,6 +67,34 @@ static const struct HwtimerDevDone dev_done =
.read = NONE,
};
static uint32 HwTimerDrvConfigure(void *drv, struct BusConfigureInfo *configure_info)
{
NULL_PARAM_CHECK(drv);
NULL_PARAM_CHECK(configure_info);
x_err_t ret = EOK;
void* param;
switch (configure_info->configure_cmd)
{
case OPE_CFG: {
size_t real_time = timer_set_interval(TIMER_DEVICE_1, TIMER_CHANNEL_1, *(x_ticks_t *)configure_info->private_data *1000000);
KPrintf("timer_set_interval -- real_time : %ld\n", real_time);
break;
}
case OPE_INT: {
ptim2_cb_info = (struct HwtimerCallBackInfo *)malloc(sizeof(struct HwtimerCallBackInfo));
ptim2_cb_info->timeout_callback = configure_info->private_data;
timer_irq_register(TIMER_DEVICE_1, TIMER_CHANNEL_1, 0, 1, timer_callback, NULL);
break;
}
default:
break;
}
return ret;
}
/*Init hwtimer bus*/
static int BoardHwtimerBusInit(struct HwtimerBus *hwtimer_bus, struct HwtimerDriver *hwtimer_driver)
{
@ -86,7 +108,7 @@ static int BoardHwtimerBusInit(struct HwtimerBus *hwtimer_bus, struct HwtimerDri
}
/*Init the hwtimer driver*/
hwtimer_driver->configure = NONE;
hwtimer_driver->configure = &HwTimerDrvConfigure;
ret = HwtimerDriverInit(hwtimer_driver, HWTIMER_DRIVER_NAME_1);
if (EOK != ret) {
KPrintf("board_hwtimer_init HwtimerDriverInit error %d\n", ret);

View File

@ -111,7 +111,7 @@ uint32_t wdt_init(wdt_device_number_t id, uint64_t time_out_ms, plic_irq_callbac
plic_irq_enable(id ? IRQN_WDT1_INTERRUPT : IRQN_WDT0_INTERRUPT);
plic_irq_register(id ? IRQN_WDT1_INTERRUPT : IRQN_WDT0_INTERRUPT, on_irq, ctx);
wdt_response_mode(id, WDT_CR_RMOD_INTERRUPT);
wdt_response_mode(id, WDT_CR_RMOD_RESET);
uint8_t m_top = wdt_get_top(id, time_out_ms);
wdt_set_timeout(id, m_top);
wdt_enable(id);

View File

@ -21,8 +21,12 @@ CONFIG_BSP_USING_LPUART3=y
CONFIG_SERIAL_BUS_NAME_3="uart3"
CONFIG_SERIAL_DRV_NAME_3="uart3_drv"
CONFIG_SERIAL_3_DEVICE_NAME_0="uart3_dev3"
# CONFIG_BSP_USING_LPUART4 is not set
# CONFIG_BSP_USING_LPUART8 is not set
CONFIG_BSP_USING_LPUART8=y
CONFIG_SERIAL_BUS_NAME_8="uart8"
CONFIG_SERIAL_DRV_NAME_8="uart8_drv"
CONFIG_SERIAL_8_DEVICE_NAME_0="uart8_dev8"
# CONFIG_BSP_USING_CH438 is not set
CONFIG_BSP_USING_GPIO=y
CONFIG_PIN_BUS_NAME="pin"
@ -63,7 +67,7 @@ CONFIG___STACKSIZE__=4096
#
CONFIG_RESOURCES_SERIAL=y
CONFIG_SERIAL_USING_DMA=y
CONFIG_SERIAL_RB_BUFSZ=128
CONFIG_SERIAL_RB_BUFSZ=256
CONFIG_RESOURCES_PIN=y
#
@ -125,7 +129,7 @@ CONFIG_ZOMBIE_KTASK_STACKSIZE=2048
#
CONFIG_KERNEL_CONSOLE=y
CONFIG_KERNEL_BANNER=y
CONFIG_KERNEL_CONSOLEBUF_SIZE=128
CONFIG_KERNEL_CONSOLEBUF_SIZE=256
#
# Kernel Hook
@ -231,6 +235,7 @@ CONFIG_ADD_XIZI_FEATURES=y
# CONFIG_SUPPORT_KNOWING_FRAMEWORK is not set
# CONFIG_SUPPORT_CONTROL_FRAMEWORK is not set
#
# Security
#

View File

@ -507,7 +507,7 @@ static status_t flexspi_config_mcr1(uint32_t instance, flexspi_mem_config_t *con
// Configure MCR1
FLEXSPI->MCR1 = FLEXSPI_MCR1_SEQWAIT(seqWaitTicks) | FLEXSPI_MCR1_AHBBUSWAIT(ahbBusWaitTicks);
return kStatus_Success;
return (status_t)kStatus_Success;
}
@ -647,14 +647,14 @@ uint8_t FLASH_WritePage(uint32_t addr, const uint32_t *buf, uint32_t len)
/*******************************************************************************
* : FLASH_Read
* : FLASH_ReadBuf
* : Flash内容
* : addr:
buf:
len:
* : kStatus_Success
*******************************************************************************/
status_t FLASH_Read(uint32_t addr, uint32_t *buf, uint32_t len)
status_t FLASH_ReadBuf(uint32_t addr, uint32_t *buf, uint32_t len)
{
status_t status;
flexspi_xfer_t flashXfer;
@ -678,206 +678,28 @@ status_t FLASH_Read(uint32_t addr, uint32_t *buf, uint32_t len)
}
/*******************************************************************************
* : flash_erase
* : Flash指定长度的空间
* : addr:
byte_cnt:,4k字节为最小擦除单位
* : kStatus_Success
* : 4k字节的4k字节
*******************************************************************************/
status_t flash_erase(uint32_t start_addr, uint32_t byte_cnt)
{
uint32_t addr;
status_t status;
addr = start_addr;
while(addr < (byte_cnt + start_addr))
{
status = FLASH_EraseSector(addr);
if(status != kStatus_Success)
{
return status;
}
addr += FLASH_GetSectorSize();
}
return status;
}
/*******************************************************************************
* : flash_write
* : flash起始地址写入指定长度的数据
* : addr:
buf:
byte_cnt:
* : kStatus_Success
*******************************************************************************/
status_t flash_write(uint32_t start_addr, uint8_t *buf, uint32_t byte_cnt)
{
uint32_t size;
status_t status;
while(byte_cnt > 0)
{
size = byte_cnt > FLASH_PAGE_SIZE ? FLASH_PAGE_SIZE : byte_cnt;
status = FLASH_WritePage(start_addr, (void *)buf, size);
if(status != kStatus_Success)
{
return status;
}
start_addr += size;
buf += size;
byte_cnt -= size;
}
return kStatus_Success;
}
/*******************************************************************************
* : flash_read
* : Flash内容
* : addr:
buf:
len:
* : kStatus_Success
*******************************************************************************/
status_t flash_read(uint32_t addr, uint8_t *buf, uint32_t len)
{
/* For FlexSPI Memory ReadBack, use IP Command instead of AXI command for security */
if((addr >= 0x60000000) && (addr < 0x61000000))
{
return FLASH_Read(addr, (void *)buf, len);
}
else
{
void* result = memcpy(buf, (void*)addr, len);
if(result == NULL)
{
return (status_t)kStatus_Fail;
}
else
{
return (status_t)kStatus_Success;
}
}
}
/*******************************************************************************
* : flash_copy
* : flash数据在分区之间的拷贝
* : srcAddr:flash的起始地址
dstAddr:flash的起始地址;
imageSize:flash空间大小,
* : kStatus_Success
*******************************************************************************/
status_t flash_copy(uint32_t srcAddr,uint32_t dstAddr, uint32_t imageSize)
{
uint32_t PageNum, Remain, i;
status_t status;
if((srcAddr == dstAddr) || imageSize > APP_FLASH_SIZE)
{
return (status_t)kStatus_Fail;
}
status = flash_erase(dstAddr,imageSize);
if(status != kStatus_Success)
{
KPrintf("Erase flash 0x%08x failure !\r\n",dstAddr);
return status;
}
PageNum = imageSize/FLASH_PAGE_SIZE;
Remain = imageSize%FLASH_PAGE_SIZE;
for(i=0;i<PageNum;i++)
{
memset(buffer, 0, sizeof(buffer));
status = flash_read(srcAddr + i*FLASH_PAGE_SIZE, buffer, sizeof(buffer));
if(status != kStatus_Success)
{
KPrintf("Read flash 0x%08x failure !\r\n", srcAddr + i*FLASH_PAGE_SIZE);
return status;
}
status = flash_write(dstAddr+ i*FLASH_PAGE_SIZE, buffer, FLASH_PAGE_SIZE);
if(status != kStatus_Success)
{
KPrintf("Write flash 0x%08x failure !\r\n", dstAddr + i*FLASH_PAGE_SIZE);
return status;
}
}
if(Remain)
{
memset(buffer, 0, sizeof(buffer));
status = flash_read(srcAddr + i*FLASH_PAGE_SIZE, buffer, Remain);
if(status != kStatus_Success)
{
KPrintf("Read flash 0x%08x failure !\r\n", srcAddr + i*FLASH_PAGE_SIZE);
return status;
}
status = flash_write(dstAddr+ i*FLASH_PAGE_SIZE, buffer, Remain);
if(status != kStatus_Success)
{
KPrintf("Write flash 0x%08x failure !\r\n", dstAddr + i*FLASH_PAGE_SIZE);
return status;
}
}
return (status_t)kStatus_Success;
}
/*******************************************************************************
* : NOR_FLASH_Erase
* : Flash指定长度的空间,imageSize
* : addr:
imageSize:
* : None
*******************************************************************************/
status_t NOR_FLASH_Erase(uint32_t app_base_addr,uint32_t imageSize)
{
uint16_t i;
uint32_t sectorNum = (imageSize%SECTOR_SIZE != 0)? (imageSize/SECTOR_SIZE + 1):(imageSize/SECTOR_SIZE);
for(i=0;i<sectorNum;i++)
{
status_t status = FLASH_EraseSector(app_base_addr+i*SECTOR_SIZE);
if (status != kStatus_Success)
{
KPrintf("Erase_Sector 0x%x faild!\r\n",i*SECTOR_SIZE);
return status;
}
}
return kStatus_Success;
}
/*******************************************************************************
* : NorFlash_Write_PageProgram
* : Flash指定长度的数据
* : pBuffer:
WriteAddr:
NumByteToWrite:(256)
* : kStatus_Success
* : , kStatus_Success,
* : 256
*******************************************************************************/
void NorFlash_Write_PageProgram(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t NumByteToWrite)
status_t NorFlash_Write_PageProgram(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t NumByteToWrite)
{
uint8_t temp_data[256] = {0xff};
memcpy(temp_data,pBuffer,NumByteToWrite);
status_t status = FLASH_WritePage(WriteAddr,(void *)temp_data,FLASH_PAGE_SIZE);
if (status != kStatus_Success)
if(status != kStatus_Success)
{
KPrintf("Write_PageProgram 0x%x faild!\r\n",WriteAddr);
}
return (status_t)kStatus_Success;
}
@ -887,13 +709,14 @@ void NorFlash_Write_PageProgram(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t Num
* : pBuffer:
WriteAddr:(24bit)
NumByteToWrite:(65535)
* :
* : , kStatus_Success,
* : 0XFF,0XFF处写入的数据将失败!
,,!
*******************************************************************************/
void NorFlash_Write_NoCheck(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t NumByteToWrite)
status_t NorFlash_Write_NoCheck(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t NumByteToWrite)
{
uint16_t pageRemain;
uint16_t pageRemain;
status_t status;
pageRemain = 256 - WriteAddr%256;//单页剩余的字节数
@ -904,7 +727,12 @@ void NorFlash_Write_NoCheck(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t NumByte
while(1)
{
NorFlash_Write_PageProgram(pBuffer,WriteAddr,pageRemain);
status = NorFlash_Write_PageProgram(pBuffer,WriteAddr,pageRemain);
if(status != kStatus_Success)
{
KPrintf("Write_PageProgram 0x%x faild!\r\n",WriteAddr);
return status;
}
if(NumByteToWrite == pageRemain)
{
break;//写入结束了
@ -925,25 +753,54 @@ void NorFlash_Write_NoCheck(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t NumByte
}
}
}
return (status_t)kStatus_Success;
}
/*******************************************************************************
* : NorFlash_Write
* : Flash_Erase
* : Flash指定长度的空间,imageSize
* : start_addr:
imageSize:
* : , kStatus_Success,
*******************************************************************************/
status_t Flash_Erase(uint32_t start_addr, uint32_t imageSize)
{
uint16_t i;
status_t status;
uint32_t sectorNum = (imageSize%SECTOR_SIZE != 0)? (imageSize/SECTOR_SIZE + 1):(imageSize/SECTOR_SIZE);
for(i=0;i<sectorNum;i++)
{
status = FLASH_EraseSector(start_addr+i*SECTOR_SIZE);
if (status != kStatus_Success)
{
KPrintf("Erase_Sector 0x%x faild!\r\n",i*SECTOR_SIZE);
return status;
}
}
return (status_t)kStatus_Success;
}
/*******************************************************************************
* : Flash_Write
* : W25QXX在指定地址开始写入指定长度的数据
* : pBuffer:
WriteAddr:(24bit)
WriteAddr:
NumByteToWrite:(65535)
* : None
* : , kStatus_Success,
* :
*******************************************************************************/
void NorFlash_Write(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t NumByteToWrite)
status_t Flash_Write(uint32_t WriteAddr, uint8_t *pBuffer, uint32_t NumByteToWrite)
{
uint32_t secPos;
uint16_t secOff;
uint16_t secRemain;
uint16_t i;
uint8_t *NorFlash_BUF = 0;
status_t status;
NorFlash_BUF = NorFlash_BUFFER;//RAM缓冲区4K
@ -959,7 +816,11 @@ void NorFlash_Write(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t NumByteToWrite)
}
while(1)
{
FLASH_Read(CHIP_FLAH_BASE + secPos*SECTOR_SIZE, (void *)NorFlash_BUF, SECTOR_SIZE);//读出整个扇区的内容
status = FLASH_ReadBuf(CHIP_FLAH_BASE + secPos*SECTOR_SIZE, (void *)NorFlash_BUF, SECTOR_SIZE);//读出整个扇区的内容
if (status != kStatus_Success)
{
return status;
}
for(i=0;i<secRemain;i++)//校验数据
{
if(NorFlash_BUF[secOff+i] != 0xFF)
@ -969,16 +830,28 @@ void NorFlash_Write(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t NumByteToWrite)
}
if(i < secRemain)//需要擦除
{
FLASH_EraseSector(CHIP_FLAH_BASE + secPos*SECTOR_SIZE);
status = FLASH_EraseSector(CHIP_FLAH_BASE + secPos*SECTOR_SIZE);
if (status != kStatus_Success)
{
return status;
}
for(i=0;i<secRemain;i++)//复制
{
NorFlash_BUF[i+secOff] = pBuffer[i];
}
NorFlash_Write_NoCheck(NorFlash_BUF,CHIP_FLAH_BASE + secPos*SECTOR_SIZE,SECTOR_SIZE);//写入整个扇区
status = NorFlash_Write_NoCheck(NorFlash_BUF,CHIP_FLAH_BASE + secPos*SECTOR_SIZE,SECTOR_SIZE);//写入整个扇区
if (status != kStatus_Success)
{
return status;
}
}
else
{
NorFlash_Write_NoCheck(pBuffer,CHIP_FLAH_BASE + WriteAddr,secRemain);//写已经擦除了的,直接写入扇区剩余区间.
status = NorFlash_Write_NoCheck(pBuffer,CHIP_FLAH_BASE + WriteAddr,secRemain);//写已经擦除了的,直接写入扇区剩余区间.
if (status != kStatus_Success)
{
return status;
}
}
if(NumByteToWrite == secRemain)
@ -1003,33 +876,138 @@ void NorFlash_Write(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t NumByteToWrite)
}
}
}
return (status_t)kStatus_Success;
}
/*******************************************************************************
* : Flash_Read
* : Flash内容
* : addr:
buf:
len:
* : kStatus_Success
*******************************************************************************/
status_t Flash_Read(uint32_t addr, uint8_t *buf, uint32_t len)
{
/* For FlexSPI Memory ReadBack, use IP Command instead of AXI command for security */
if((addr >= 0x60000000) && (addr < 0x61000000))
{
return FLASH_ReadBuf(addr, (void *)buf, len);
}
else
{
void* result = memcpy(buf, (void*)addr, len);
if(result == NULL)
{
return (status_t)kStatus_Fail;
}
else
{
return (status_t)kStatus_Success;
}
}
}
/*******************************************************************************
* : Flash_Copy
* : flash数据在分区之间的拷贝
* : srcAddr:flash的起始地址
dstAddr:flash的起始地址;
imageSize:flash空间大小,
* : kStatus_Success
*******************************************************************************/
status_t Flash_Copy(uint32_t srcAddr,uint32_t dstAddr, uint32_t imageSize)
{
uint32_t PageNum, Remain, i;
status_t status;
if((srcAddr == dstAddr) || imageSize > APP_FLASH_SIZE)
{
return (status_t)kStatus_Fail;
}
status = Flash_Erase(dstAddr,imageSize);
if(status != kStatus_Success)
{
KPrintf("Erase flash 0x%08x failure !\r\n",dstAddr);
return status;
}
PageNum = imageSize/FLASH_PAGE_SIZE;
Remain = imageSize%FLASH_PAGE_SIZE;
for(i=0;i<PageNum;i++)
{
memset(buffer, 0, sizeof(buffer));
status = Flash_Read(srcAddr + i*FLASH_PAGE_SIZE, buffer, sizeof(buffer));
if(status != kStatus_Success)
{
KPrintf("Read flash 0x%08x failure !\r\n", srcAddr + i*FLASH_PAGE_SIZE);
return status;
}
status = Flash_Write(dstAddr+ i*FLASH_PAGE_SIZE, buffer, FLASH_PAGE_SIZE);
if(status != kStatus_Success)
{
KPrintf("Write flash 0x%08x failure !\r\n", dstAddr + i*FLASH_PAGE_SIZE);
return status;
}
}
if(Remain)
{
memset(buffer, 0, sizeof(buffer));
status = Flash_Read(srcAddr + i*FLASH_PAGE_SIZE, buffer, Remain);
if(status != kStatus_Success)
{
KPrintf("Read flash 0x%08x failure !\r\n", srcAddr + i*FLASH_PAGE_SIZE);
return status;
}
status = Flash_Write(dstAddr+ i*FLASH_PAGE_SIZE, buffer, Remain);
if(status != kStatus_Success)
{
KPrintf("Write flash 0x%08x failure !\r\n", dstAddr + i*FLASH_PAGE_SIZE);
return status;
}
}
return (status_t)kStatus_Success;
}
/*******************************************************************************
* : NOR_FLASH_Write
* : W25QXX在指定地址开始写入指定长度的数据
* : FlashAddress:Flash地址的指针
Data:
DataLength:
* : 0
* : , kStatus_Success,
*******************************************************************************/
#ifndef USE_HIGHT_SPEED_TRANS
uint32_t NOR_FLASH_Write(uint32_t* FlashAddress, uint8_t* Data ,uint16_t DataLength)
status_t NOR_FLASH_Write(uint32_t* FlashAddress, uint8_t* Data ,uint16_t DataLength)
{
status_t status;
uint32_t WriteAddr;
WriteAddr = *FlashAddress;
NorFlash_Write(Data,WriteAddr,DataLength);
status = Flash_Write(WriteAddr,Data,DataLength);
if (status != kStatus_Success)
{
return status;
}
*FlashAddress += DataLength;
return 0;
return (status_t)kStatus_Success;
}
#else
uint8_t packetNum = 0;
uint32_t dataLen = 0;
uint32_t WriteAddr;
uint8_t dataBuff[5*1024];
uint32_t NOR_FLASH_Write(uint32_t* FlashAddress, uint8_t* Data ,uint16_t DataLength,uint8_t doneFlag)
status_t NOR_FLASH_Write(uint32_t* FlashAddress, uint8_t* Data ,uint16_t DataLength,uint8_t doneFlag)
{
status_t status;
if(!doneFlag)
{
memcpy(&dataBuff[dataLen],Data,DataLength);
@ -1042,7 +1020,11 @@ uint32_t NOR_FLASH_Write(uint32_t* FlashAddress, uint8_t* Data ,uint16_t DataLen
if(dataLen>=SECTOR_SIZE)
{
NorFlash_Write(dataBuff,WriteAddr,dataLen);
status = Flash_Write(WriteAddr,dataBuff,dataLen);
if (status != kStatus_Success)
{
return status;
}
packetNum = 0;
dataLen = 0;
}
@ -1050,10 +1032,14 @@ uint32_t NOR_FLASH_Write(uint32_t* FlashAddress, uint8_t* Data ,uint16_t DataLen
}
else
{
NorFlash_Write(dataBuff,WriteAddr,dataLen);
status = Flash_Write(WriteAddr,dataBuff,dataLen);
if (status != kStatus_Success)
{
return status;
}
packetNum = 0;
dataLen = 0;
}
return (0);
return (status_t)kStatus_Success;;
}
#endif

View File

@ -280,7 +280,7 @@ int32_t Ymodem_Receive(uint8_t *buf, const uint32_t addr)
}
/* erase user application area */
NOR_FLASH_Erase(addr,size);
Flash_Erase(addr,size);
Send_Byte(ACK);
Send_Byte(CRC16);
}
@ -300,9 +300,9 @@ int32_t Ymodem_Receive(uint8_t *buf, const uint32_t addr)
/* Write received data in Flash */
#ifndef USE_HIGHT_SPEED_TRANS
if(NOR_FLASH_Write(&flashdestination, buf, (uint16_t)packet_length) == 0)
if(NOR_FLASH_Write(&flashdestination, buf, (uint16_t)packet_length) == kStatus_Success)
#else
if(NOR_FLASH_Write(&flashdestination, buf, (uint16_t)packet_length, 0) == 0)
if(NOR_FLASH_Write(&flashdestination, buf, (uint16_t)packet_length, 0) == kStatus_Success)
#endif
{
Send_Byte(ACK);
@ -349,7 +349,10 @@ int32_t Ymodem_Receive(uint8_t *buf, const uint32_t addr)
}
}
#ifdef USE_HIGHT_SPEED_TRANS
NOR_FLASH_Write(&flashdestination, buf, (uint16_t) packet_length,1);
if(NOR_FLASH_Write(&flashdestination, buf, (uint16_t) packet_length,1) != kStatus_Success)
{
return -4;
}
#endif
return (int32_t)size;
}
@ -370,13 +373,12 @@ int32_t SerialDownload(const uint32_t addr)
Size = Ymodem_Receive(&tab_1024[0], addr);
if(Size > 0)
{
Serial_PutString("\n\n\r Programming Completed Successfully!\n\r--------------------------------\r\n Name: ");
Serial_PutString("\n\n\rProgramming Completed Successfully!\n\r\r\nName: ");
Serial_PutString(FileName);
Int2Str(Number, Size);
Serial_PutString("\n\r Size: ");
Serial_PutString("\n\rSize: ");
Serial_PutString(Number);
Serial_PutString(" Bytes\r\n");
Serial_PutString("-------------------\n");
}
else if(Size == -1)
{

View File

@ -63,21 +63,19 @@ void FLASH_Init(void);
void FLASH_DeInit(void);
uint8_t FLASH_EraseSector(uint32_t addr);
uint8_t FLASH_WritePage(uint32_t addr, const uint32_t *buf, uint32_t len);
status_t FLASH_Read(uint32_t addr, uint32_t *buf, uint32_t len);
status_t flash_erase(uint32_t start_addr, uint32_t byte_cnt);
status_t flash_write(uint32_t start_addr, uint8_t *buf, uint32_t byte_cnt);
status_t flash_read(uint32_t addr, uint8_t *buf, uint32_t len);
status_t flash_copy(uint32_t srcAddr,uint32_t dstAddr, uint32_t imageSize);
status_t FLASH_ReadBuf(uint32_t addr, uint32_t *buf, uint32_t len);
status_t NorFlash_Write_PageProgram(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t NumByteToWrite);
status_t NorFlash_Write_NoCheck(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t NumByteToWrite);
status_t NOR_FLASH_Erase(uint32_t app_base_addr,uint32_t imageSize);
void NorFlash_Write_PageProgram(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t NumByteToWrite);
void NorFlash_Write_NoCheck(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t NumByteToWrite);
void NorFlash_Write(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t NumByteToWrite);
status_t Flash_Erase(uint32_t start_addr, uint32_t imageSize);
status_t Flash_Write(uint32_t WriteAddr, uint8_t *pBuffer, uint32_t NumByteToWrite);
status_t Flash_Read(uint32_t addr, uint8_t *buf, uint32_t len);
status_t Flash_Copy(uint32_t srcAddr,uint32_t dstAddr, uint32_t imageSize);
#ifndef USE_HIGHT_SPEED_TRANS
uint32_t NOR_FLASH_Write(uint32_t* FlashAddress, uint8_t* Data ,uint16_t DataLength);
status_t NOR_FLASH_Write(uint32_t* FlashAddress, uint8_t* Data ,uint16_t DataLength);
#else
uint32_t NOR_FLASH_Write(uint32_t* FlashAddress, uint8_t* Data ,uint16_t DataLength,uint8_t doneFlag);
status_t NOR_FLASH_Write(uint32_t* FlashAddress, uint8_t* Data ,uint16_t DataLength,uint8_t doneFlag);
#endif
#endif

View File

@ -493,3 +493,15 @@ DWORD GetFatTime(void)
return fat_time;
}
void FatfsPrintf(struct FileDescriptor *fdp, const void *src, size_t len)
{
int i = 0;
for (i = 0; i < len; i ++) {
f_printf(fdp->data, "%d,", ((uint8 *)src)[i]);
}
if (i == len) {
f_printf(fdp->data, "\r\n");
}
}

View File

@ -33,7 +33,7 @@
/ 3: f_lseek() function is removed in addition to 2. */
#define FF_USE_STRFUNC 0
#define FF_USE_STRFUNC 1
/* This option switches string functions, f_gets(), f_putc(), f_puts() and f_printf().
/
/ 0: Disable string functions.

View File

@ -231,9 +231,9 @@ int MountFilesystem(const char *bus_name,
enum FilesystemType fs_type, const char *path)
{
struct MountPoint *mp = NULL, *itr;
struct Bus *bus;
struct Bus* bus = NULL;
HardwareDevType dev;
DriverType drv;
DriverType drv = NULL;
struct SysDoubleLinklistNode *node;
int ret = -EINVAL;

View File

@ -46,6 +46,7 @@ extern "C" {
#define FILESYS_DEBUG 0
#define NETDEV_DEBUG 0
#define WEBNET_DEBUG 0
#define WIZNET_DEBUG 0
#define SYS_KDEBUG_LOG(section, information) \
do { \

View File

@ -61,6 +61,9 @@ enum SmallSizeAllocSize {
#define SMALL_SIZE_32B(ITEMSIZE) ((ITEMSIZE + SIZEOF_DYNAMICALLOCNODE_MEM) * SMALL_NUMBER_32B) /* Calculate the total size for SIZEOF_32B blocks*/
#define SMALL_SIZE_64B(ITEMSIZE) ((ITEMSIZE + SIZEOF_DYNAMICALLOCNODE_MEM) * SMALL_NUMBER_64B) /* Calculate the total size for SIZEOF_64B blocks*/
#define FREE_LIST_LOCK() DISABLE_INTERRUPT()
#define FREE_LIST_UNLOCK(lock) ENABLE_INTERRUPT(lock)
/**
* The structure describes an allocated memory block from dynamic buddy memory.
*/
@ -632,66 +635,65 @@ void *x_malloc(x_size_t size)
register x_base lock = 0;
/* hold lock before allocation */
lock = CriticalAreaLock();
lock = FREE_LIST_LOCK();
/* alignment */
size = ALIGN_MEN_UP(size, MEM_ALIGN_SIZE);
/* alignment */
size = ALIGN_MEN_UP(size, MEM_ALIGN_SIZE);
/* parameter detection */
/* parameter detection */
#ifdef MEM_EXTERN_SRAM
/* parameter detection */
if(size == 0 ){
CriticalAreaUnLock(lock);
return NONE;
}
if((size > ByteManager.dynamic_buddy_manager.dynamic_buddy_end - ByteManager.dynamic_buddy_manager.dynamic_buddy_start - ByteManager.dynamic_buddy_manager.active_memory)){
/* alignment */
size = ALIGN_MEN_UP(size, MEM_ALIGN_SIZE);
goto try_extmem;
}
/* parameter detection */
if (size == 0) {
FREE_LIST_UNLOCK(lock);
return NONE;
}
if ((size > ByteManager.dynamic_buddy_manager.dynamic_buddy_end - ByteManager.dynamic_buddy_manager.dynamic_buddy_start - ByteManager.dynamic_buddy_manager.active_memory)) {
/* alignment */
size = ALIGN_MEN_UP(size, MEM_ALIGN_SIZE);
goto try_extmem;
}
#else
/* parameter detection */
if((size == 0) || (size > ByteManager.dynamic_buddy_manager.dynamic_buddy_end - ByteManager.dynamic_buddy_manager.dynamic_buddy_start - ByteManager.dynamic_buddy_manager.active_memory)) {
CriticalAreaUnLock(lock);
return NONE;
}
/* parameter detection */
if ((size == 0) || (size > ByteManager.dynamic_buddy_manager.dynamic_buddy_end - ByteManager.dynamic_buddy_manager.dynamic_buddy_start - ByteManager.dynamic_buddy_manager.active_memory)) {
FREE_LIST_UNLOCK(lock);
return NONE;
}
#endif
/* determine allocation operation from static segments or dynamic buddy memory */
/* determine allocation operation from static segments or dynamic buddy memory */
#ifdef KERNEL_SMALL_MEM_ALLOC
if(size <= SIZEOF_32B) {
ret = ByteManager.static_manager[0].done->malloc(&ByteManager, SIZEOF_32B);
} else if (size <= SIZEOF_64B) {
ret = ByteManager.static_manager[1].done->malloc(&ByteManager, SIZEOF_64B);
}
if (size <= SIZEOF_32B) {
ret = ByteManager.static_manager[0].done->malloc(&ByteManager, SIZEOF_32B);
} else if (size <= SIZEOF_64B) {
ret = ByteManager.static_manager[1].done->malloc(&ByteManager, SIZEOF_64B);
}
#endif
if (ret == NONE) {
ret = ByteManager.dynamic_buddy_manager.done->malloc(&ByteManager.dynamic_buddy_manager, size, DYNAMIC_BLOCK_NO_EXTMEM_MASK);
if (ret != NONE) {
CHECK(ByteManager.dynamic_buddy_manager.done->JudgeLegal(&ByteManager.dynamic_buddy_manager, ret - SIZEOF_DYNAMICALLOCNODE_MEM));
}
if (ret == NONE) {
ret = ByteManager.dynamic_buddy_manager.done->malloc(&ByteManager.dynamic_buddy_manager, size, DYNAMIC_BLOCK_NO_EXTMEM_MASK);
if (ret != NONE) {
CHECK(ByteManager.dynamic_buddy_manager.done->JudgeLegal(&ByteManager.dynamic_buddy_manager, ret - SIZEOF_DYNAMICALLOCNODE_MEM));
}
#ifdef MEM_EXTERN_SRAM
try_extmem:
if(NONE == ret) {
for(i = 0; i < EXTSRAM_MAX_NUM; i++) {
if(NONE != ExtByteManager[i].done) {
ret = ExtByteManager[i].dynamic_buddy_manager.done->malloc(&ExtByteManager[i].dynamic_buddy_manager, size, DYNAMIC_BLOCK_EXTMEMn_MASK(i + 1));
if (ret){
CHECK(ExtByteManager[i].dynamic_buddy_manager.done->JudgeLegal(&ExtByteManager[i].dynamic_buddy_manager, ret - SIZEOF_DYNAMICALLOCNODE_MEM));
break;
}
}
}
}
try_extmem:
if (NONE == ret) {
for (i = 0; i < EXTSRAM_MAX_NUM; i++) {
if (NONE != ExtByteManager[i].done) {
ret = ExtByteManager[i].dynamic_buddy_manager.done->malloc(&ExtByteManager[i].dynamic_buddy_manager, size, DYNAMIC_BLOCK_EXTMEMn_MASK(i + 1));
if (ret) {
CHECK(ExtByteManager[i].dynamic_buddy_manager.done->JudgeLegal(&ExtByteManager[i].dynamic_buddy_manager, ret - SIZEOF_DYNAMICALLOCNODE_MEM));
break;
}
}
}
}
#endif
}
}
/* release lock */
CriticalAreaUnLock(lock);
return ret;
/* release lock */
FREE_LIST_UNLOCK(lock);
return ret;
}
/**
@ -702,49 +704,49 @@ try_extmem:
*
* @return pointer on success; NULL on failure
*/
void *x_realloc(void *pointer, x_size_t size)
void* x_realloc(void* pointer, x_size_t size)
{
x_size_t newsize = 0;
x_size_t oldsize = 0;
void *newmem = NONE;
struct DynamicAllocNode *oldnode = NONE;
x_size_t newsize = 0;
x_size_t oldsize = 0;
void* newmem = NONE;
struct DynamicAllocNode* oldnode = NONE;
/* the given pointer is NULL */
if (pointer == NONE)
return x_malloc(size);
/* the given pointer is NULL */
if (pointer == NONE)
return x_malloc(size);
/* parameter detection */
if (size == 0) {
x_free(pointer);
return NONE;
}
CHECK(ByteManager.dynamic_buddy_manager.done->JudgeLegal(&ByteManager.dynamic_buddy_manager,pointer));
if (size == 0) {
x_free(pointer);
return NONE;
}
CHECK(ByteManager.dynamic_buddy_manager.done->JudgeLegal(&ByteManager.dynamic_buddy_manager, pointer));
/* alignment and calculate the real size */
/* alignment and calculate the real size */
newsize = ALIGN_MEN_UP(size, MEM_ALIGN_SIZE);
newsize += SIZEOF_DYNAMICALLOCNODE_MEM;
newsize += SIZEOF_DYNAMICALLOCNODE_MEM;
oldnode= PTR2ALLOCNODE((char*)pointer - SIZEOF_DYNAMICALLOCNODE_MEM);
oldnode = PTR2ALLOCNODE((char*)pointer - SIZEOF_DYNAMICALLOCNODE_MEM);
CHECK(ByteManager.done->JudgeAllocated(oldnode));
/* achieve the old memory size */
if(ByteManager.done->JudgeStaticOrDynamic(oldnode)) {
if (ByteManager.done->JudgeStaticOrDynamic(oldnode)) {
oldsize = ((struct segment*)(long)(oldnode->size))->block_size;
} else {
} else {
oldsize = oldnode->size - SIZEOF_DYNAMICALLOCNODE_MEM;
}
}
/* allocate new memory */
newmem = x_malloc(size);
if(newmem == NONE) {
/* allocate new memory */
newmem = x_malloc(size);
if (newmem == NONE) {
return NONE;
}
}
/* copy the old memory and then release old memory pointer */
memcpy((char*)newmem, (char*) pointer,size > oldsize ? oldsize : size);
x_free(pointer);
/* copy the old memory and then release old memory pointer */
memcpy((char*)newmem, (char*)pointer, size > oldsize ? oldsize : size);
x_free(pointer);
return newmem;
return newmem;
}
/**
@ -755,22 +757,22 @@ void *x_realloc(void *pointer, x_size_t size)
*
* @return pointer on success; NULL on failure
*/
void *x_calloc(x_size_t count, x_size_t size)
void* x_calloc(x_size_t count, x_size_t size)
{
void *p = NONE;
void* p = NONE;
/* parameter detection */
if(count * size > ByteManager.dynamic_buddy_manager.dynamic_buddy_end - ByteManager.dynamic_buddy_manager.dynamic_buddy_start - ByteManager.dynamic_buddy_manager.active_memory)
if (count * size > ByteManager.dynamic_buddy_manager.dynamic_buddy_end - ByteManager.dynamic_buddy_manager.dynamic_buddy_start - ByteManager.dynamic_buddy_manager.active_memory)
return NONE;
/* calls x_malloc to allocate count * size memory */
p = x_malloc(count * size);
p = x_malloc(count * size);
/* zero the memory */
if (p)
memset((char*)p, 0, count * size);
/* zero the memory */
if (p)
memset((char*)p, 0, count * size);
return p;
return p;
}
/**
@ -778,52 +780,52 @@ void *x_calloc(x_size_t count, x_size_t size)
*
* @param pointer the memory to be released
*/
void x_free(void *pointer)
void x_free(void* pointer)
{
x_base lock = 0;
struct DynamicAllocNode *node = NONE;
x_base lock = 0;
struct DynamicAllocNode* node = NONE;
/* parameter detection */
if (pointer == NONE) {
return;
}
if (pointer == NONE) {
return;
}
/* hold lock before release */
lock = CriticalAreaLock();
lock = FREE_LIST_LOCK();
if (!ByteManager.dynamic_buddy_manager.done->JudgeLegal(&ByteManager.dynamic_buddy_manager, pointer)) {
CriticalAreaUnLock(lock);
SYS_ERR("[%s] Freeing a unallocated address.\n", __func__);
return;
}
FREE_LIST_UNLOCK(lock);
SYS_ERR("[%s] Freeing a unallocated address.\n", __func__);
return;
}
node = PTR2ALLOCNODE((char*)pointer - SIZEOF_DYNAMICALLOCNODE_MEM);
node = PTR2ALLOCNODE((char*)pointer - SIZEOF_DYNAMICALLOCNODE_MEM);
CHECK(ByteManager.done->JudgeAllocated(node));
/* judge release the memory block ro static_segment or dynamic buddy memory */
#ifdef KERNEL_SMALL_MEM_ALLOC
if(node->flag & STATIC_BLOCK_MASK) {
ByteManager.static_manager->done->release(pointer);
} else
if (node->flag & STATIC_BLOCK_MASK) {
ByteManager.static_manager->done->release(pointer);
} else
#endif
{
{
#ifdef MEM_EXTERN_SRAM
/* judge the pointer is not malloced from extern memory*/
if(0 == (node->flag & 0xFF0000)) {
ByteManager.dynamic_buddy_manager.done->release(&ByteManager,pointer);
}
/* judge the pointer is not malloced from extern memory*/
if (0 == (node->flag & 0xFF0000)) {
ByteManager.dynamic_buddy_manager.done->release(&ByteManager, pointer);
}
/* judge the pointer is malloced from extern memory*/
if(0 != (node->flag & 0xFF0000)) {
ExtByteManager[((node->flag & 0xFF0000) >> 16) - 1].dynamic_buddy_manager.done->release(&ExtByteManager[((node->flag & 0xFF0000) >> 16) - 1],pointer);
}
/* judge the pointer is malloced from extern memory*/
if (0 != (node->flag & 0xFF0000)) {
ExtByteManager[((node->flag & 0xFF0000) >> 16) - 1].dynamic_buddy_manager.done->release(&ExtByteManager[((node->flag & 0xFF0000) >> 16) - 1], pointer);
}
#else
ByteManager.dynamic_buddy_manager.done->release(&ByteManager, pointer);
#endif
}
ByteManager.dynamic_buddy_manager.done->release(&ByteManager, pointer);
#endif
}
/* release the lock */
CriticalAreaUnLock(lock);
/* release the lock */
FREE_LIST_UNLOCK(lock);
}
#ifdef MEM_EXTERN_SRAM
@ -834,43 +836,42 @@ void x_free(void *pointer)
* @param end_phy_address the end physical address for static and dynamic memory
* @param extsram_idx the idx of extsram chip
*/
void ExtSramInitBoardMemory(void *start_phy_address, void *end_phy_address, uint8 extsram_idx)
void ExtSramInitBoardMemory(void* start_phy_address, void* end_phy_address, uint8 extsram_idx)
{
register x_size_t offset = 0;
register x_size_t offset = 0;
NULL_PARAM_CHECK(start_phy_address);
NULL_PARAM_CHECK(end_phy_address);
NULL_PARAM_CHECK(start_phy_address);
NULL_PARAM_CHECK(end_phy_address);
KDEBUG_NOT_IN_INTERRUPT;
struct DynamicBuddyMemory *uheap = &ExtByteManager[extsram_idx].dynamic_buddy_manager;
KDEBUG_NOT_IN_INTERRUPT;
struct DynamicBuddyMemory* uheap = &ExtByteManager[extsram_idx].dynamic_buddy_manager;
/* align begin and end addr to page */
ExtByteManager[extsram_idx].dynamic_buddy_manager.dynamic_buddy_start = ALIGN_MEN_UP((x_ubase)start_phy_address, MM_PAGE_SIZE);
ExtByteManager[extsram_idx].dynamic_buddy_manager.dynamic_buddy_end = ALIGN_MEN_DOWN((x_ubase)end_phy_address, MM_PAGE_SIZE);
KPrintf("%s: 0x%x-0x%x extsram_idx = %d\n",__func__,ExtByteManager[extsram_idx].dynamic_buddy_manager.dynamic_buddy_start,ExtByteManager[extsram_idx].dynamic_buddy_manager.dynamic_buddy_end, extsram_idx);
/* align begin and end addr to page */
ExtByteManager[extsram_idx].dynamic_buddy_manager.dynamic_buddy_start = ALIGN_MEN_UP((x_ubase)start_phy_address, MM_PAGE_SIZE);
ExtByteManager[extsram_idx].dynamic_buddy_manager.dynamic_buddy_end = ALIGN_MEN_DOWN((x_ubase)end_phy_address, MM_PAGE_SIZE);
KPrintf("%s: 0x%x-0x%x extsram_idx = %d\n", __func__, ExtByteManager[extsram_idx].dynamic_buddy_manager.dynamic_buddy_start, ExtByteManager[extsram_idx].dynamic_buddy_manager.dynamic_buddy_end, extsram_idx);
/* parameter detection */
if (ExtByteManager[extsram_idx].dynamic_buddy_manager.dynamic_buddy_start >= ExtByteManager[extsram_idx].dynamic_buddy_manager.dynamic_buddy_end) {
KPrintf("ExtSramInitBoardMemory, wrong address[0x%x - 0x%x]\n",
(x_ubase)start_phy_address, (x_ubase)end_phy_address);
return;
}
if (ExtByteManager[extsram_idx].dynamic_buddy_manager.dynamic_buddy_start >= ExtByteManager[extsram_idx].dynamic_buddy_manager.dynamic_buddy_end) {
KPrintf("ExtSramInitBoardMemory, wrong address[0x%x - 0x%x]\n",
(x_ubase)start_phy_address, (x_ubase)end_phy_address);
return;
}
uheap->mm_total_size = 0;
memset(uheap->mm_freenode_list, 0, SIZEOF_XSFREENODE_MEM * MEM_LINKNRS);
memset(uheap->mm_freenode_list, 0, SIZEOF_XSFREENODE_MEM * MEM_LINKNRS);
/* initialize the freeNodeList */
for (offset = 1; offset < MEM_LINKNRS; offset++) {
uheap->mm_freenode_list[offset - 1].next = &uheap->mm_freenode_list[offset];
uheap->mm_freenode_list[offset].prev = &uheap->mm_freenode_list[offset - 1];
}
ExtByteManager[extsram_idx].dynamic_buddy_manager.done = &DynamicDone;
ExtByteManager[extsram_idx].done = &NodeDone;
/* initialize the freeNodeList */
for (offset = 1; offset < MEM_LINKNRS; offset++) {
uheap->mm_freenode_list[offset - 1].next = &uheap->mm_freenode_list[offset];
uheap->mm_freenode_list[offset].prev = &uheap->mm_freenode_list[offset - 1];
}
ExtByteManager[extsram_idx].dynamic_buddy_manager.done = &DynamicDone;
ExtByteManager[extsram_idx].done = &NodeDone;
/* dynamic buddy memory initialization */
ExtByteManager[extsram_idx].dynamic_buddy_manager.done->init(&ExtByteManager[extsram_idx].dynamic_buddy_manager, ExtByteManager[extsram_idx].dynamic_buddy_manager.dynamic_buddy_start, ExtByteManager[extsram_idx].dynamic_buddy_manager.dynamic_buddy_end - ExtByteManager[extsram_idx].dynamic_buddy_manager.dynamic_buddy_start);
ExtByteManager[extsram_idx].dynamic_buddy_manager.done->init(&ExtByteManager[extsram_idx].dynamic_buddy_manager, ExtByteManager[extsram_idx].dynamic_buddy_manager.dynamic_buddy_start, ExtByteManager[extsram_idx].dynamic_buddy_manager.dynamic_buddy_end - ExtByteManager[extsram_idx].dynamic_buddy_manager.dynamic_buddy_start);
}
#endif
@ -880,49 +881,48 @@ void ExtSramInitBoardMemory(void *start_phy_address, void *end_phy_address, uint
* @param start_phy_address the start physical address for static and dynamic memory
* @param end_phy_address the end physical address for static and dynamic memory
*/
void InitBoardMemory(void *start_phy_address, void *end_phy_address)
void InitBoardMemory(void* start_phy_address, void* end_phy_address)
{
register x_size_t offset = 0;
register x_size_t offset = 0;
NULL_PARAM_CHECK(start_phy_address);
NULL_PARAM_CHECK(end_phy_address);
NULL_PARAM_CHECK(start_phy_address);
NULL_PARAM_CHECK(end_phy_address);
KDEBUG_NOT_IN_INTERRUPT;
struct DynamicBuddyMemory *mheap = &ByteManager.dynamic_buddy_manager;
KDEBUG_NOT_IN_INTERRUPT;
struct DynamicBuddyMemory* mheap = &ByteManager.dynamic_buddy_manager;
/* align begin and end addr to page */
ByteManager.dynamic_buddy_manager.dynamic_buddy_start = ALIGN_MEN_UP((x_ubase)start_phy_address, MM_PAGE_SIZE);
ByteManager.dynamic_buddy_manager.dynamic_buddy_end = ALIGN_MEN_DOWN((x_ubase)end_phy_address, MM_PAGE_SIZE);
//KPrintf("%s: 0x%x-0x%x \n",__func__,ByteManager.dynamic_buddy_manager.dynamic_buddy_start,ByteManager.dynamic_buddy_manager.dynamic_buddy_end);
/* align begin and end addr to page */
ByteManager.dynamic_buddy_manager.dynamic_buddy_start = ALIGN_MEN_UP((x_ubase)start_phy_address, MM_PAGE_SIZE);
ByteManager.dynamic_buddy_manager.dynamic_buddy_end = ALIGN_MEN_DOWN((x_ubase)end_phy_address, MM_PAGE_SIZE);
// KPrintf("%s: 0x%x-0x%x \n",__func__,ByteManager.dynamic_buddy_manager.dynamic_buddy_start,ByteManager.dynamic_buddy_manager.dynamic_buddy_end);
/* parameter detection */
if (ByteManager.dynamic_buddy_manager.dynamic_buddy_start >= ByteManager.dynamic_buddy_manager.dynamic_buddy_end) {
//KPrintf("InitBoardMemory, wrong address[0x%x - 0x%x]\n", (x_ubase)start_phy_address, (x_ubase)end_phy_address);
if (ByteManager.dynamic_buddy_manager.dynamic_buddy_start >= ByteManager.dynamic_buddy_manager.dynamic_buddy_end) {
// KPrintf("InitBoardMemory, wrong address[0x%x - 0x%x]\n", (x_ubase)start_phy_address, (x_ubase)end_phy_address);
SYS_KDEBUG_LOG(KDBG_MEM, ("InitBoardMemory, wrong address[0x%x - 0x%x]\n", (x_ubase)start_phy_address, (x_ubase)end_phy_address));
return;
}
}
mheap->mm_total_size = 0;
memset(mheap->mm_freenode_list, 0, SIZEOF_XSFREENODE_MEM * MEM_LINKNRS);
memset(mheap->mm_freenode_list, 0, SIZEOF_XSFREENODE_MEM * MEM_LINKNRS);
/* initialize the freeNodeList */
for (offset = 1; offset < MEM_LINKNRS; offset++) {
mheap->mm_freenode_list[offset - 1].next = &mheap->mm_freenode_list[offset];
mheap->mm_freenode_list[offset].prev = &mheap->mm_freenode_list[offset - 1];
}
ByteManager.dynamic_buddy_manager.done = &DynamicDone;
ByteManager.static_manager[MM_SEGMENT_32B].done = &StaticDone;
ByteManager.static_manager[MM_SEGMENT_64B].done = &StaticDone;
ByteManager.done = &NodeDone;
/* initialize the freeNodeList */
for (offset = 1; offset < MEM_LINKNRS; offset++) {
mheap->mm_freenode_list[offset - 1].next = &mheap->mm_freenode_list[offset];
mheap->mm_freenode_list[offset].prev = &mheap->mm_freenode_list[offset - 1];
}
ByteManager.dynamic_buddy_manager.done = &DynamicDone;
ByteManager.static_manager[MM_SEGMENT_32B].done = &StaticDone;
ByteManager.static_manager[MM_SEGMENT_64B].done = &StaticDone;
ByteManager.done = &NodeDone;
/* dynamic buddy memory initialization */
ByteManager.dynamic_buddy_manager.done->init(&ByteManager.dynamic_buddy_manager, ByteManager.dynamic_buddy_manager.dynamic_buddy_start, ByteManager.dynamic_buddy_manager.dynamic_buddy_end - ByteManager.dynamic_buddy_manager.dynamic_buddy_start);
ByteManager.dynamic_buddy_manager.done->init(&ByteManager.dynamic_buddy_manager, ByteManager.dynamic_buddy_manager.dynamic_buddy_start, ByteManager.dynamic_buddy_manager.dynamic_buddy_end - ByteManager.dynamic_buddy_manager.dynamic_buddy_start);
/* dynamic static segments initialization */
#ifdef KERNEL_SMALL_MEM_ALLOC
ByteManager.static_manager->done->init(&ByteManager);
ByteManager.static_manager->done->init(&ByteManager);
#endif
}
@ -935,57 +935,55 @@ void InitBoardMemory(void *start_phy_address, void *end_phy_address)
*
* @return pointer on success; NULL on failure
*/
void *x_umalloc(x_size_t size)
void* x_umalloc(x_size_t size)
{
uint8 i = 0;
void *ret = NONE;
register x_base lock = 0;
uint8 i = 0;
void* ret = NONE;
register x_base lock = 0;
#ifdef MEM_EXTERN_SRAM
/* parameter detection */
if(size == 0 ){
return NONE;
}
if((size > ByteManager.dynamic_buddy_manager.dynamic_buddy_end - ByteManager.dynamic_buddy_manager.dynamic_buddy_start - ByteManager.dynamic_buddy_manager.active_memory)){
lock = CriticalAreaLock();
/* alignment */
size = ALIGN_MEN_UP(size, MEM_ALIGN_SIZE);
goto try_extmem;
}
/* parameter detection */
if (size == 0) {
return NONE;
}
if ((size > ByteManager.dynamic_buddy_manager.dynamic_buddy_end - ByteManager.dynamic_buddy_manager.dynamic_buddy_start - ByteManager.dynamic_buddy_manager.active_memory)) {
lock = FREE_LIST_LOCK();
/* alignment */
size = ALIGN_MEN_UP(size, MEM_ALIGN_SIZE);
goto try_extmem;
}
#else
/* parameter detection */
if((size == 0) || (size > UserByteManager.dynamic_buddy_manager.dynamic_buddy_end - UserByteManager.dynamic_buddy_manager.dynamic_buddy_start - UserByteManager.dynamic_buddy_manager.active_memory))
return NONE;
/* parameter detection */
if ((size == 0) || (size > UserByteManager.dynamic_buddy_manager.dynamic_buddy_end - UserByteManager.dynamic_buddy_manager.dynamic_buddy_start - UserByteManager.dynamic_buddy_manager.active_memory))
return NONE;
#endif
/* hold lock before allocation */
lock = CriticalAreaLock();
/* hold lock before allocation */
lock = FREE_LIST_LOCK();
/* alignment */
size = ALIGN_MEN_UP(size, MEM_ALIGN_SIZE);
ret = UserByteManager.dynamic_buddy_manager.done->malloc(&UserByteManager.dynamic_buddy_manager,size,DYNAMIC_BLOCK_NO_EXTMEM_MASK);
if(ret != NONE)
size = ALIGN_MEN_UP(size, MEM_ALIGN_SIZE);
ret = UserByteManager.dynamic_buddy_manager.done->malloc(&UserByteManager.dynamic_buddy_manager, size, DYNAMIC_BLOCK_NO_EXTMEM_MASK);
if (ret != NONE)
CHECK(UserByteManager.dynamic_buddy_manager.done->JudgeLegal(&UserByteManager.dynamic_buddy_manager, ret - SIZEOF_DYNAMICALLOCNODE_MEM));
#ifdef MEM_EXTERN_SRAM
try_extmem:
if(NONE == ret) {
for(i = 0; i < EXTSRAM_MAX_NUM; i++) {
if(NONE != ExtByteManager[i].done) {
ret = ExtByteManager[i].dynamic_buddy_manager.done->malloc(&ExtByteManager[i].dynamic_buddy_manager, size, DYNAMIC_BLOCK_EXTMEMn_MASK(i + 1));
if (ret) {
CHECK(ExtByteManager[i].dynamic_buddy_manager.done->JudgeLegal(&ExtByteManager[i].dynamic_buddy_manager, ret - SIZEOF_DYNAMICALLOCNODE_MEM));
break;
}
}
}
}
if (NONE == ret) {
for (i = 0; i < EXTSRAM_MAX_NUM; i++) {
if (NONE != ExtByteManager[i].done) {
ret = ExtByteManager[i].dynamic_buddy_manager.done->malloc(&ExtByteManager[i].dynamic_buddy_manager, size, DYNAMIC_BLOCK_EXTMEMn_MASK(i + 1));
if (ret) {
CHECK(ExtByteManager[i].dynamic_buddy_manager.done->JudgeLegal(&ExtByteManager[i].dynamic_buddy_manager, ret - SIZEOF_DYNAMICALLOCNODE_MEM));
break;
}
}
}
}
#endif
/* release lock */
CriticalAreaUnLock(lock);
return ret;
/* release lock */
FREE_LIST_UNLOCK(lock);
return ret;
}
/**
@ -996,49 +994,49 @@ try_extmem:
*
* @return pointer on success; NULL on failure
*/
void *x_urealloc(void *pointer, x_size_t size)
void* x_urealloc(void* pointer, x_size_t size)
{
x_size_t newsize = 0;
x_size_t oldsize = 0;
void *newmem = NONE;
struct DynamicAllocNode *oldnode = NONE;
x_size_t newsize = 0;
x_size_t oldsize = 0;
void* newmem = NONE;
struct DynamicAllocNode* oldnode = NONE;
/* the given pointer is NULL */
if (pointer == NONE)
return x_umalloc(size);
/* the given pointer is NULL */
if (pointer == NONE)
return x_umalloc(size);
/* parameter detection */
if (size == 0) {
x_ufree(pointer);
return NONE;
}
CHECK(UserByteManager.dynamic_buddy_manager.done->JudgeLegal(&UserByteManager.dynamic_buddy_manager,pointer));
if (size == 0) {
x_ufree(pointer);
return NONE;
}
CHECK(UserByteManager.dynamic_buddy_manager.done->JudgeLegal(&UserByteManager.dynamic_buddy_manager, pointer));
/* alignment and calculate the real size */
/* alignment and calculate the real size */
newsize = ALIGN_MEN_UP(size, MEM_ALIGN_SIZE);
newsize += SIZEOF_DYNAMICALLOCNODE_MEM;
newsize += SIZEOF_DYNAMICALLOCNODE_MEM;
oldnode= PTR2ALLOCNODE((char*)pointer - SIZEOF_DYNAMICALLOCNODE_MEM);
oldnode = PTR2ALLOCNODE((char*)pointer - SIZEOF_DYNAMICALLOCNODE_MEM);
CHECK(UserByteManager.done->JudgeAllocated(oldnode));
/* achieve the old memory size */
if(UserByteManager.done->JudgeStaticOrDynamic(oldnode)) {
if (UserByteManager.done->JudgeStaticOrDynamic(oldnode)) {
oldsize = ((struct segment*)(oldnode->size))->block_size;
} else {
} else {
oldsize = oldnode->size - SIZEOF_DYNAMICALLOCNODE_MEM;
}
}
/* allocate new memory */
newmem = x_umalloc(size);
if(newmem == NONE) {
/* allocate new memory */
newmem = x_umalloc(size);
if (newmem == NONE) {
return NONE;
}
}
/* copy the old memory and then release old memory pointer */
memcpy((char*)newmem, (char*) pointer,size > oldsize ? oldsize : size);
x_ufree(pointer);
/* copy the old memory and then release old memory pointer */
memcpy((char*)newmem, (char*)pointer, size > oldsize ? oldsize : size);
x_ufree(pointer);
return newmem;
return newmem;
}
/**
@ -1049,22 +1047,22 @@ void *x_urealloc(void *pointer, x_size_t size)
*
* @return pointer on success; NULL on failure
*/
void *x_ucalloc(x_size_t count, x_size_t size)
void* x_ucalloc(x_size_t count, x_size_t size)
{
void *p = NONE;
void* p = NONE;
/* parameter detection */
if(count * size > UserByteManager.dynamic_buddy_manager.dynamic_buddy_end - UserByteManager.dynamic_buddy_manager.dynamic_buddy_start - UserByteManager.dynamic_buddy_manager.active_memory)
if (count * size > UserByteManager.dynamic_buddy_manager.dynamic_buddy_end - UserByteManager.dynamic_buddy_manager.dynamic_buddy_start - UserByteManager.dynamic_buddy_manager.active_memory)
return NONE;
/* calls x_malloc to allocate count * size memory */
p = x_umalloc(count * size);
p = x_umalloc(count * size);
/* zero the memory */
if (p)
memset((char*)p, 0, count * size);
/* zero the memory */
if (p)
memset((char*)p, 0, count * size);
return p;
return p;
}
/**
@ -1072,37 +1070,37 @@ void *x_ucalloc(x_size_t count, x_size_t size)
*
* @param pointer the memory to be released
*/
void x_ufree(void *pointer)
void x_ufree(void* pointer)
{
x_base lock = 0;
struct DynamicAllocNode *node = NONE;
x_base lock = 0;
struct DynamicAllocNode* node = NONE;
/* parameter detection */
if (pointer == NONE)
return ;
CHECK(UserByteManager.dynamic_buddy_manager.done->JudgeLegal(&UserByteManager.dynamic_buddy_manager,pointer));
if (pointer == NONE)
return;
CHECK(UserByteManager.dynamic_buddy_manager.done->JudgeLegal(&UserByteManager.dynamic_buddy_manager, pointer));
/* hold lock before release */
lock = CriticalAreaLock();
node = PTR2ALLOCNODE((char*)pointer-SIZEOF_DYNAMICALLOCNODE_MEM);
lock = FREE_LIST_LOCK();
node = PTR2ALLOCNODE((char*)pointer - SIZEOF_DYNAMICALLOCNODE_MEM);
CHECK(UserByteManager.done->JudgeAllocated(node));
#ifdef MEM_EXTERN_SRAM
/* judge the pointer is not malloced from extern memory*/
if(0 == (node->flag & 0xFF0000)) {
UserByteManager.dynamic_buddy_manager.done->release(&ByteManager,pointer);
}
/* judge the pointer is not malloced from extern memory*/
if (0 == (node->flag & 0xFF0000)) {
UserByteManager.dynamic_buddy_manager.done->release(&ByteManager, pointer);
}
/* judge the pointer is malloced from extern memory*/
if(0 != (node->flag & 0xFF0000)) {
ExtByteManager[((node->flag & 0xFF0000) >> 16) - 1].dynamic_buddy_manager.done->release(&ExtByteManager[((node->flag & 0xFF0000) >> 16) - 1],pointer);
}
/* judge the pointer is malloced from extern memory*/
if (0 != (node->flag & 0xFF0000)) {
ExtByteManager[((node->flag & 0xFF0000) >> 16) - 1].dynamic_buddy_manager.done->release(&ExtByteManager[((node->flag & 0xFF0000) >> 16) - 1], pointer);
}
#else
UserByteManager.dynamic_buddy_manager.done->release(&UserByteManager,pointer);
UserByteManager.dynamic_buddy_manager.done->release(&UserByteManager, pointer);
#endif
/* release the lock */
CriticalAreaUnLock(lock);
/* release the lock */
FREE_LIST_UNLOCK(lock);
}
/**
@ -1213,8 +1211,8 @@ void ShowBuddy(void)
int lock = 0;
struct DynamicFreeNode *debug = NONE;
lock = CriticalAreaLock();
KPrintf("\n\033[41;1mlist memory information\033[0m\n", __func__);
lock = FREE_LIST_LOCK();
KPrintf("\n\033[41;1mlist memory information\033[0m\n", __func__);
for(int level = 0; level < MEM_LINKNRS; level++) {
KPrintf("%s level [%d],memory size[2^%d] \n",__func__, level,level +6);
for (debug = &ByteManager.dynamic_buddy_manager.mm_freenode_list[level]; ; ) {
@ -1258,7 +1256,7 @@ void ShowBuddy(void)
}
#endif
CriticalAreaUnLock(lock);
FREE_LIST_UNLOCK(lock);
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0),
ShowBuddy,ShowBuddy,list memory usage information);

View File

@ -94,7 +94,7 @@ static x_err_t _MsgQueueSend(struct MsgQueue* mq,
NULL_PARAM_CHECK(mq);
NULL_PARAM_CHECK(buffer);
SYS_KDEBUG_LOG(MSGQUEUE_DEBUG, ("[%s] mq_num_msgs: %d, block size: %d, needed size: %d\n", __func__, mq->num_msgs, mq->each_len, size));
SYS_KDEBUG_LOG(MSGQUEUE_DEBUG, ("[%s] mq_num_msgs: %d, block size: %d, needed size: %lu\n", __func__, mq->num_msgs, mq->each_len, size));
if (size > mq->each_len)
return -ERROR;

View File

@ -175,12 +175,12 @@ SWITCH:
HOOK(hook.assign.hook_Assign,(runningtask, new_task));
SYS_KDEBUG_LOG(KDBG_SCHED,
("[%d]switch to priority#%d "
"task:%.*s(sp:0x%08x), "
"from task:%.*s(sp: 0x%08x)\n",
isrManager.done->getCounter(), highest_prio,
NAME_NUM_MAX, new_task->task_base_info.name, new_task->stack_point,
NAME_NUM_MAX, runningtask->task_base_info.name, runningtask->stack_point));
("[%d]switch to priority#%ld "
"task:%.*s(sp:0x%8p), "
"from task:%.*s(sp: 0x%8p)\n",
isrManager.done->getCounter(), highest_prio,
NAME_NUM_MAX, new_task->task_base_info.name, new_task->stack_point,
NAME_NUM_MAX, runningtask->task_base_info.name, runningtask->stack_point));
Assign.smp_assign_done->SwitchToNew(runningtask,new_task);
}
@ -442,12 +442,12 @@ x_err_t YieldOsAssign(void)
HOOK(hook.assign.hook_Assign,(runningtask, new_task));
SYS_KDEBUG_LOG(KDBG_SCHED,
("[%d]switch to priority#%d "
"task:%.*s(sp:0x%08x), "
"from task:%.*s(sp: 0x%08x)\n",
isrManager.done->getCounter(), highest_prio,
NAME_NUM_MAX, new_task->task_base_info.name, new_task->stack_point,
NAME_NUM_MAX, runningtask->task_base_info.name, runningtask->stack_point));
("[%d]switch to priority#%ld "
"task:%.*s(sp:0x%8p), "
"from task:%.*s(sp: 0x%8p)\n",
isrManager.done->getCounter(), highest_prio,
NAME_NUM_MAX, new_task->task_base_info.name, new_task->stack_point,
NAME_NUM_MAX, runningtask->task_base_info.name, runningtask->stack_point));
Assign.smp_assign_done->SwitchToNew(runningtask,new_task);

View File

@ -16,7 +16,9 @@
time_t time(time_t *t)
{
NULL_PARAM_CHECK(t);
if (NULL == t) {
return 0;
}
time_t current = 0;
#ifdef RESOURCES_RTC

View File

@ -1,4 +1,5 @@
import os
import sys
def mergeBinProccess( files, fileSaveName):
bin = b''
@ -17,11 +18,11 @@ def mergeBinProccess( files, fileSaveName):
f.write(bin)
if __name__ == '__main__':
file1 = r'./build/XiZi-kd233_kernel.bin'
file1 = r'./build/XiZi-'+sys.argv[1]+'_kernel.bin'
file1_start_addr = 0
file2 = r'./build/XiZi-kd233_app.bin'
file2 = r'./build/XiZi-'+sys.argv[1]+'_app.bin'
file2_start_addr = 1024 * 1024 + 4096
newfile = r'./build/XiZi-kd233.bin'
newfile = r'./build/XiZi-'+sys.argv[1]+'.bin'
file = [ [file1 , file1_start_addr] , [file2 , file2_start_addr] ]
mergeBinProccess(file, newfile)

View File

@ -128,6 +128,21 @@ KERNELPATHS += \
-I$(BSP_ROOT)/third_party_driver/drivers \
-I$(BSP_ROOT)/third_party_driver/lcd \
-I$(KERNEL_ROOT)/include #
ifeq ($(CONFIG_RESOURCES_LWIP),y)
KERNELPATHS += \
-I$(KERNEL_ROOT)/resources/ethernet/LwIP/include \
-I$(KERNEL_ROOT)/resources/ethernet/LwIP \
-I$(KERNEL_ROOT)/resources/ethernet/LwIP/include/compat \
-I$(KERNEL_ROOT)/resources/ethernet/LwIP/include/lwip \
-I$(KERNEL_ROOT)/resources/ethernet/LwIP/include/netif \
-I$(KERNEL_ROOT)/resources/ethernet/LwIP/include/lwip/apps \
-I$(KERNEL_ROOT)/resources/ethernet/LwIP/include/lwip/priv \
-I$(KERNEL_ROOT)/resources/ethernet/LwIP/include/lwip/prot \
-I$(KERNEL_ROOT)/resources/ethernet/LwIP/arch
KERNELPATHS += -I$(KERNEL_ROOT)/resources/include/netdev
endif
endif
ifeq ($(BSP_ROOT),$(KERNEL_ROOT)/board/kd233)
@ -588,7 +603,8 @@ endif
ifeq ($(CONFIG_TOOL_SHELL), y)
KERNELPATHS +=-I$(KERNEL_ROOT)/tool/shell/letter-shell \
-I$(KERNEL_ROOT)/tool/shell/letter-shell/file_ext #
-I$(KERNEL_ROOT)/tool/shell/letter-shell/file_ext \
-I$(KERNEL_ROOT)/tool/shell/
endif
ifeq ($(CONFIG_TOOL_USING_OTA), y)
@ -596,6 +612,10 @@ KERNELPATHS +=-I$(KERNEL_ROOT)/tool/bootloader/flash \
-I$(KERNEL_ROOT)/tool/bootloader/ota #
endif
ifeq ($(CONFIG_TOOL_USING_MQTT), y)
KERNELPATHS +=-I$(KERNEL_ROOT)/../../APP_Framework/lib/mqtt
endif
ifeq ($(CONFIG_FS_LWEXT4),y)
KERNELPATHS += -I$(KERNEL_ROOT)/fs/lwext4/lwext4_submodule/blockdev/xiuos #
KERNELPATHS += -I$(KERNEL_ROOT)/fs/lwext4/lwext4_submodule/include #

View File

@ -1,31 +1,31 @@
/**
******************************************************************************
* @file lwipopts.h
* @author MCD Application Team
* @version V1.1.0
* @date 31-July-2013
* @brief lwIP Options Configuration.
* This file is based on Utilities\lwip_v1.4.1\src\include\lwip\opt.h
* and contains the lwIP configuration for the STM32F4x7 demonstration.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT 2013 STMicroelectronics</center></h2>
*
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.st.com/software_license_agreement_liberty_v2
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************
*/
******************************************************************************
* @file lwipopts.h
* @author MCD Application Team
* @version V1.1.0
* @date 31-July-2013
* @brief lwIP Options Configuration.
* This file is based on Utilities\lwip_v1.4.1\src\include\lwip\opt.h
* and contains the lwIP configuration for the STM32F4x7 demonstration.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT 2013 STMicroelectronics</center></h2>
*
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.st.com/software_license_agreement_liberty_v2
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************
*/
#ifndef __LWIPOPTS_H__
#define __LWIPOPTS_H__
@ -34,284 +34,300 @@
/* ---------- Debug options ---------- */
#ifndef LWIP_DEBUG
#define LWIP_DEBUG 1
#define LWIP_DEBUG 1
// #define LWIP_SOCKET_DEBUG
// #define LWIP_TCPIP_DEBUG
// #define LWIP_MEMP_DEBUG
// #define LWIP_PBUF_DEBUG
// #define LWIP_TCP_INPUT_DEBUG
// #define LWIP_TCP_OUTPUT_DEBUG
// #define LWIP_NETIF_DEBUG
// #define LWIP_ETHARP_DEBUG
// #define LWIP_API_MSG_DEBUG
#endif
// #define LWIP_SOCKETS_DEBUG 1
#ifdef LWIP_DEBUG
#ifdef LWIP_SYS_DEBUG
#define SYS_DEBUG LWIP_DBG_ON
#define SYS_DEBUG LWIP_DBG_ON
#else
#define SYS_DEBUG LWIP_DBG_OFF
#define SYS_DEBUG LWIP_DBG_OFF
#endif
#ifdef LWIP_ETHARP_DEBUG
#define ETHARP_DEBUG LWIP_DBG_ON
#define ETHARP_DEBUG LWIP_DBG_ON
#else
#define ETHARP_DEBUG LWIP_DBG_OFF
#define ETHARP_DEBUG LWIP_DBG_OFF
#endif
#ifdef LWIP_PPP_DEBUG
#define PPP_DEBUG LWIP_DBG_ON
#define PPP_DEBUG LWIP_DBG_ON
#else
#define PPP_DEBUG LWIP_DBG_OFF
#define PPP_DEBUG LWIP_DBG_OFF
#endif
#ifdef LWIP_MEM_DEBUG
#define MEM_DEBUG LWIP_DBG_ON
#define MEM_DEBUG LWIP_DBG_ON
#else
#define MEM_DEBUG LWIP_DBG_OFF
#define MEM_DEBUG LWIP_DBG_OFF
#endif
#ifdef LWIP_MEMP_DEBUG
#define MEMP_DEBUG LWIP_DBG_ON
#define MEMP_DEBUG LWIP_DBG_ON
#else
#define MEMP_DEBUG LWIP_DBG_OFF
#define MEMP_DEBUG LWIP_DBG_OFF
#endif
#ifdef LWIP_PBUF_DEBUG
#define PBUF_DEBUG LWIP_DBG_ON
#define PBUF_DEBUG LWIP_DBG_ON
#else
#define PBUF_DEBUG LWIP_DBG_OFF
#define PBUF_DEBUG LWIP_DBG_OFF
#endif
#ifdef LWIP_API_LIB_DEBUG
#define API_LIB_DEBUG LWIP_DBG_ON
#define API_LIB_DEBUG LWIP_DBG_ON
#else
#define API_LIB_DEBUG LWIP_DBG_OFF
#define API_LIB_DEBUG LWIP_DBG_OFF
#endif
#ifdef LWIP_API_MSG_DEBUG
#define API_MSG_DEBUG LWIP_DBG_ON
#define API_MSG_DEBUG LWIP_DBG_ON
#else
#define API_MSG_DEBUG LWIP_DBG_OFF
#define API_MSG_DEBUG LWIP_DBG_OFF
#endif
#ifdef LWIP_TCPIP_DEBUG
#define TCPIP_DEBUG LWIP_DBG_ON
#define TCPIP_DEBUG LWIP_DBG_ON
#else
#define TCPIP_DEBUG LWIP_DBG_OFF
#define TCPIP_DEBUG LWIP_DBG_OFF
#endif
#ifdef LWIP_NETIF_DEBUG
#define NETIF_DEBUG LWIP_DBG_ON
#define NETIF_DEBUG LWIP_DBG_ON
#else
#define NETIF_DEBUG LWIP_DBG_OFF
#define NETIF_DEBUG LWIP_DBG_OFF
#endif
#ifdef LWIP_SOCKETS_DEBUG
#define SOCKETS_DEBUG LWIP_DBG_ON
#define SOCKETS_DEBUG LWIP_DBG_ON
#else
#define SOCKETS_DEBUG LWIP_DBG_OFF
#define SOCKETS_DEBUG LWIP_DBG_OFF
#endif
#ifdef LWIP_DNS_DEBUG
#define DNS_DEBUG LWIP_DBG_ON
#define DNS_DEBUG LWIP_DBG_ON
#else
#define DNS_DEBUG LWIP_DBG_OFF
#define DNS_DEBUG LWIP_DBG_OFF
#endif
#ifdef LWIP_AUTOIP_DEBUG
#define AUTOIP_DEBUG LWIP_DBG_ON
#define AUTOIP_DEBUG LWIP_DBG_ON
#else
#define AUTOIP_DEBUG LWIP_DBG_OFF
#define AUTOIP_DEBUG LWIP_DBG_OFF
#endif
#ifdef LWIP_DHCP_DEBUG
#define DHCP_DEBUG LWIP_DBG_ON
#define DHCP_DEBUG LWIP_DBG_ON
#else
#define DHCP_DEBUG LWIP_DBG_OFF
#define DHCP_DEBUG LWIP_DBG_OFF
#endif
#ifdef LWIP_IP_DEBUG
#define IP_DEBUG LWIP_DBG_ON
#define IP_DEBUG LWIP_DBG_ON
#else
#define IP_DEBUG LWIP_DBG_OFF
#define IP_DEBUG LWIP_DBG_OFF
#endif
#ifdef LWIP_IP_REASS_DEBUG
#define IP_REASS_DEBUG LWIP_DBG_ON
#define IP_REASS_DEBUG LWIP_DBG_ON
#else
#define IP_REASS_DEBUG LWIP_DBG_OFF
#define IP_REASS_DEBUG LWIP_DBG_OFF
#endif
#ifdef LWIP_ICMP_DEBUG
#define ICMP_DEBUG LWIP_DBG_ON
#define ICMP_DEBUG LWIP_DBG_ON
#else
#define ICMP_DEBUG LWIP_DBG_OFF
#define ICMP_DEBUG LWIP_DBG_OFF
#endif
#ifdef LWIP_IGMP_DEBUG
#define IGMP_DEBUG LWIP_DBG_ON
#define IGMP_DEBUG LWIP_DBG_ON
#else
#define IGMP_DEBUG LWIP_DBG_OFF
#define IGMP_DEBUG LWIP_DBG_OFF
#endif
#ifdef LWIP_UDP_DEBUG
#define UDP_DEBUG LWIP_DBG_ON
#define UDP_DEBUG LWIP_DBG_ON
#else
#define UDP_DEBUG LWIP_DBG_OFF
#define UDP_DEBUG LWIP_DBG_OFF
#endif
#ifdef LWIP_TCP_DEBUG
#define TCP_DEBUG LWIP_DBG_ON
#define TCP_DEBUG LWIP_DBG_ON
#else
#define TCP_DEBUG LWIP_DBG_OFF
#define TCP_DEBUG LWIP_DBG_OFF
#endif
#ifdef LWIP_TCP_INPUT_DEBUG
#define TCP_INPUT_DEBUG LWIP_DBG_ON
#define TCP_INPUT_DEBUG LWIP_DBG_ON
#else
#define TCP_INPUT_DEBUG LWIP_DBG_OFF
#define TCP_INPUT_DEBUG LWIP_DBG_OFF
#endif
#ifdef LWIP_TCP_OUTPUT_DEBUG
#define TCP_OUTPUT_DEBUG LWIP_DBG_ON
#define TCP_OUTPUT_DEBUG LWIP_DBG_ON
#else
#define TCP_OUTPUT_DEBUG LWIP_DBG_OFF
#define TCP_OUTPUT_DEBUG LWIP_DBG_OFF
#endif
#ifdef LWIP_TCP_RTO_DEBUG
#define TCP_RTO_DEBUG LWIP_DBG_ON
#define TCP_RTO_DEBUG LWIP_DBG_ON
#else
#define TCP_RTO_DEBUG LWIP_DBG_OFF
#define TCP_RTO_DEBUG LWIP_DBG_OFF
#endif
#ifdef LWIP_TCP_CWND_DEBUG
#define TCP_CWND_DEBUG LWIP_DBG_ON
#define TCP_CWND_DEBUG LWIP_DBG_ON
#else
#define TCP_CWND_DEBUG LWIP_DBG_OFF
#define TCP_CWND_DEBUG LWIP_DBG_OFF
#endif
#ifdef LWIP_TCP_WND_DEBUG
#define TCP_WND_DEBUG LWIP_DBG_ON
#define TCP_WND_DEBUG LWIP_DBG_ON
#else
#define TCP_WND_DEBUG LWIP_DBG_OFF
#define TCP_WND_DEBUG LWIP_DBG_OFF
#endif
#ifdef LWIP_TCP_FR_DEBUG
#define TCP_FR_DEBUG LWIP_DBG_ON
#define TCP_FR_DEBUG LWIP_DBG_ON
#else
#define TCP_FR_DEBUG LWIP_DBG_OFF
#define TCP_FR_DEBUG LWIP_DBG_OFF
#endif
#ifdef LWIP_TCP_QLEN_DEBUG
#define TCP_QLEN_DEBUG LWIP_DBG_ON
#define TCP_QLEN_DEBUG LWIP_DBG_ON
#else
#define TCP_QLEN_DEBUG LWIP_DBG_OFF
#define TCP_QLEN_DEBUG LWIP_DBG_OFF
#endif
#ifdef LWIP_TCP_RST_DEBUG
#define TCP_RST_DEBUG LWIP_DBG_ON
#define TCP_RST_DEBUG LWIP_DBG_ON
#else
#define TCP_RST_DEBUG LWIP_DBG_OFF
#define TCP_RST_DEBUG LWIP_DBG_OFF
#endif
#endif /* LWIP_DEBUG */
#define LWIP_TIMEVAL_PRIVATE 0
#define LWIP_NO_UNISTD_H 0
#define LWIP_NO_STDDEF_H 0
#define LWIP_NO_STDINT_H 0
#define LWIP_NO_INTTYPES_H 0
#define LWIP_NO_LIMITS_H 0
#define LWIP_NO_CTYPE_H 0
#define LWIP_SOCKET_SELECT 1
#define LWIP_SOCKET_POLL 1
#define LWIP_TIMEVAL_PRIVATE 0
#define LWIP_NO_UNISTD_H 0
#define LWIP_NO_STDDEF_H 0
#define LWIP_NO_STDINT_H 0
#define LWIP_NO_INTTYPES_H 0
#define LWIP_NO_LIMITS_H 0
#define LWIP_NO_CTYPE_H 0
#define LWIP_SOCKET_SELECT 1
#define LWIP_SOCKET_POLL 1
#define LWIP_DHCP_DOES_ACD_CHECK 0
/**
* SYS_LIGHTWEIGHT_PROT==1: if you want inter-task protection for certain
* critical regions during buffer allocation, deallocation and memory
* allocation and deallocation.
*/
#define SYS_LIGHTWEIGHT_PROT 1
#define SYS_LIGHTWEIGHT_PROT 1
/**
* NO_SYS==1: Provides VERY minimal functionality. Otherwise,
* use lwIP facilities.
*/
#define NO_SYS 0
#define NO_SYS 0
/**
* NO_SYS_NO_TIMERS==1: Drop support for sys_timeout when NO_SYS==1
* Mainly for compatibility to old versions.
*/
#define NO_SYS_NO_TIMERS 0
#define NO_SYS_NO_TIMERS 0
/* ---------- Memory options ---------- */
/* MEM_ALIGNMENT: should be set to the alignment of the CPU for which
lwIP is compiled. 4 byte alignment -> define MEM_ALIGNMENT to 4, 2
byte alignment -> define MEM_ALIGNMENT to 2. */
#define MEM_ALIGNMENT 4
#ifndef RISCV_LWIP
#define MEM_ALIGNMENT 4
#else
#define MEM_ALIGNMENT 8
#endif
/* MEM_SIZE: the size of the heap memory. If the application will send
a lot of data that needs to be copied, this should be set high. */
#define MEM_SIZE (64*1024)
#ifndef RISCV_LWIP
#define MEM_SIZE (64 * 1024)
#else
#define MEM_SIZE (32 * 1024)
#endif
/* MEMP_NUM_PBUF: the number of memp struct pbufs. If the application
sends a lot of data out of ROM (or other static memory), this
should be set high. */
#define MEMP_NUM_PBUF 32
#define MEMP_NUM_PBUF 32
/* MEMP_NUM_UDP_PCB: the number of UDP protocol control blocks. One
per active UDP "connection". */
#define MEMP_NUM_UDP_PCB 4
#define MEMP_NUM_UDP_PCB 4
/* MEMP_NUM_TCP_PCB: the number of simulatenously active TCP
connections. */
#define MEMP_NUM_TCP_PCB 64
#define MEMP_NUM_TCP_PCB 64
/* MEMP_NUM_TCP_PCB_LISTEN: the number of listening TCP
connections. */
#define MEMP_NUM_TCP_PCB_LISTEN 2
/* MEMP_NUM_TCP_SEG: the number of simultaneously queued TCP
segments. */
#define MEMP_NUM_TCP_SEG 256
#define MEMP_NUM_TCP_SEG 256
/* MEMP_NUM_SYS_TIMEOUT: the number of simulateously active
timeouts. */
// #define MEMP_NUM_SYS_TIMEOUT 6
#define MEMP_NUM_SYS_TIMEOUT (LWIP_TCP + IP_REASSEMBLY + LWIP_ARP + (2*LWIP_DHCP) + LWIP_AUTOIP + LWIP_IGMP + LWIP_DNS + PPP_SUPPORT + (LWIP_IPV6 ? (1 + (2*LWIP_IPV6)) : 0))
#define MEMP_NUM_SYS_TIMEOUT (LWIP_TCP + IP_REASSEMBLY + LWIP_ARP + (2 * LWIP_DHCP) + LWIP_AUTOIP + LWIP_IGMP + LWIP_DNS + PPP_SUPPORT + (LWIP_IPV6 ? (1 + (2 * LWIP_IPV6)) : 0))
/* ---------- Pbuf options ---------- */
/* PBUF_POOL_SIZE: the number of buffers in the pbuf pool. */
#define PBUF_POOL_SIZE 255
#define PBUF_POOL_SIZE 255
/* PBUF_POOL_BUFSIZE: the size of each pbuf in the pbuf pool. */
// #define PBUF_POOL_BUFSIZE 1024
#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(TCP_MSS+40+PBUF_LINK_ENCAPSULATION_HLEN+PBUF_LINK_HLEN)
#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(TCP_MSS + 40 + PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN)
/* ---------- ARP options ---------- */
#define LWIP_ARP 1
#define ARP_TABLE_SIZE 10
#define ARP_QUEUEING 1
#define LWIP_ARP 1
#define ARP_TABLE_SIZE 10
#define ARP_QUEUEING 1
/* ---------- TCP options ---------- */
#define LWIP_TCP 1
#define TCP_TTL 255
#define LWIP_TCP 1
#define TCP_TTL 255
/* Controls if TCP should queue segments that arrive out of
order. Define to 0 if your device is low on memory. */
#define TCP_QUEUE_OOSEQ 1
#define TCP_QUEUE_OOSEQ 0
/* TCP Maximum segment size. */
#define TCP_MSS (1500 - 40) /* TCP_MSS = (Ethernet MTU - IP header size - TCP header size) */
#define TCP_MSS (1500 - 40) /* TCP_MSS = (Ethernet MTU - IP header size - TCP header size) */
/* TCP sender buffer space (bytes). */
#define TCP_SND_BUF (11*TCP_MSS)
#define TCP_SND_BUF (11 * TCP_MSS)
/* TCP_SND_QUEUELEN: TCP sender buffer space (pbufs). This must be at least
as much as (2 * TCP_SND_BUF/TCP_MSS) for things to work. */
#define TCP_SND_QUEUELEN (8* TCP_SND_BUF/TCP_MSS)
#define TCP_SND_QUEUELEN (8 * TCP_SND_BUF / TCP_MSS)
/* TCP receive window. */
#define TCP_WND 8192
#define TCP_WND 8192
// #define TCP_WND (12 * TCP_MSS)
/* Maximum number of retransmissions of data segments. */
#define TCP_MAXRTX 12
#define TCP_MAXRTX 12
/* Maximum number of retransmissions of SYN segments. */
#define TCP_SYNMAXRTX 4
#define TCP_SYNMAXRTX 4
/**
* LWIP_TCP_KEEPALIVE==1: Enable TCP_KEEPIDLE, TCP_KEEPINTVL and TCP_KEEPCNT
@ -319,21 +335,21 @@ a lot of data that needs to be copied, this should be set high. */
* in seconds. (does not require sockets.c, and will affect tcp.c)
*/
#ifndef LWIP_TCP_KEEPALIVE
#define LWIP_TCP_KEEPALIVE 1
#define LWIP_TCP_KEEPALIVE 1
#endif
/**
* LWIP_NETIF_HOSTNAME==1: Support netif hostname
*/
#ifndef LWIP_NETIF_HOSTNAME
#define LWIP_NETIF_HOSTNAME 1
#define LWIP_NETIF_HOSTNAME 1
#endif
/**
* LWIP_NETIF_API==1: Support netif api (in netifapi.c)
*/
#ifndef LWIP_NETIF_API
#define LWIP_NETIF_API 1
#define LWIP_NETIF_API 1
#endif
/**
@ -341,7 +357,7 @@ a lot of data that needs to be copied, this should be set high. */
* SO_SNDTIMEO processing.
*/
#ifndef LWIP_SO_SNDTIMEO
#define LWIP_SO_SNDTIMEO 1
#define LWIP_SO_SNDTIMEO 1
#endif
/**
@ -349,47 +365,44 @@ a lot of data that needs to be copied, this should be set high. */
* SO_RCVTIMEO processing.
*/
#ifndef LWIP_SO_RCVTIMEO
#define LWIP_SO_RCVTIMEO 1
#define LWIP_SO_RCVTIMEO 1
#endif
/**
* LWIP_SO_RCVBUF==1: Enable SO_RCVBUF processing.
*/
#ifndef LWIP_SO_RCVBUF
#define LWIP_SO_RCVBUF 1
#define LWIP_SO_RCVBUF 1
#endif
/**
* If LWIP_SO_RCVBUF is used, this is the default value for recv_bufsize.
*/
#ifndef RECV_BUFSIZE_DEFAULT
#define RECV_BUFSIZE_DEFAULT 8192
#define RECV_BUFSIZE_DEFAULT 8192
#endif
/* ---------- ICMP options ---------- */
#define LWIP_ICMP 1
#define LWIP_ICMP 1
/* ---------- DHCP options ---------- */
/* Define LWIP_DHCP to 1 if you want DHCP configuration of
interfaces. DHCP is not implemented in lwIP 0.5.1, however, so
turning this on does currently not work. */
#define LWIP_DHCP 1
#define LWIP_DHCP 1
/* ---------- UDP options ---------- */
#define LWIP_UDP 1
#define UDP_TTL 255
#define LWIP_UDP 1
#define UDP_TTL 255
/* ---------- Statistics options ---------- */
#define LWIP_PROVIDE_ERRNO 1
#define LWIP_PROVIDE_ERRNO 1
/* ---------- link callback options ---------- */
/* LWIP_NETIF_LINK_CALLBACK==1: Support a callback function from an interface
* whenever the link changes (i.e., link down)
*/
#define LWIP_NETIF_LINK_CALLBACK 0
#define LWIP_NETIF_LINK_CALLBACK 0
/*
--------------------------------------
---------- Checksum options ----------
@ -401,41 +414,40 @@ The STM32F4x7 allows computing and verifying the IP, UDP, TCP and ICMP checksums
- To use this feature let the following define uncommented.
- To disable it and process by CPU comment the the checksum.
*/
#define CHECKSUM_BY_HARDWARE
// #define CHECKSUM_BY_HARDWARE
#ifdef CHECKSUM_BY_HARDWARE
/* CHECKSUM_GEN_IP==0: Generate checksums by hardware for outgoing IP packets.*/
#define CHECKSUM_GEN_IP 0
/* CHECKSUM_GEN_UDP==0: Generate checksums by hardware for outgoing UDP packets.*/
#define CHECKSUM_GEN_UDP 0
/* CHECKSUM_GEN_TCP==0: Generate checksums by hardware for outgoing TCP packets.*/
#define CHECKSUM_GEN_TCP 0
/* CHECKSUM_CHECK_IP==0: Check checksums by hardware for incoming IP packets.*/
#define CHECKSUM_CHECK_IP 0
/* CHECKSUM_CHECK_UDP==0: Check checksums by hardware for incoming UDP packets.*/
#define CHECKSUM_CHECK_UDP 0
/* CHECKSUM_CHECK_TCP==0: Check checksums by hardware for incoming TCP packets.*/
#define CHECKSUM_CHECK_TCP 0
/* CHECKSUM_CHECK_ICMP==0: Check checksums by hardware for incoming ICMP packets.*/
#define CHECKSUM_GEN_ICMP 0
/* CHECKSUM_GEN_IP==0: Generate checksums by hardware for outgoing IP packets.*/
#define CHECKSUM_GEN_IP 0
/* CHECKSUM_GEN_UDP==0: Generate checksums by hardware for outgoing UDP packets.*/
#define CHECKSUM_GEN_UDP 0
/* CHECKSUM_GEN_TCP==0: Generate checksums by hardware for outgoing TCP packets.*/
#define CHECKSUM_GEN_TCP 0
/* CHECKSUM_CHECK_IP==0: Check checksums by hardware for incoming IP packets.*/
#define CHECKSUM_CHECK_IP 0
/* CHECKSUM_CHECK_UDP==0: Check checksums by hardware for incoming UDP packets.*/
#define CHECKSUM_CHECK_UDP 0
/* CHECKSUM_CHECK_TCP==0: Check checksums by hardware for incoming TCP packets.*/
#define CHECKSUM_CHECK_TCP 0
/* CHECKSUM_CHECK_ICMP==0: Check checksums by hardware for incoming ICMP packets.*/
#define CHECKSUM_GEN_ICMP 0
#else
/* CHECKSUM_GEN_IP==1: Generate checksums in software for outgoing IP packets.*/
#define CHECKSUM_GEN_IP 1
/* CHECKSUM_GEN_UDP==1: Generate checksums in software for outgoing UDP packets.*/
#define CHECKSUM_GEN_UDP 1
/* CHECKSUM_GEN_TCP==1: Generate checksums in software for outgoing TCP packets.*/
#define CHECKSUM_GEN_TCP 1
/* CHECKSUM_CHECK_IP==1: Check checksums in software for incoming IP packets.*/
#define CHECKSUM_CHECK_IP 1
/* CHECKSUM_CHECK_UDP==1: Check checksums in software for incoming UDP packets.*/
#define CHECKSUM_CHECK_UDP 1
/* CHECKSUM_CHECK_TCP==1: Check checksums in software for incoming TCP packets.*/
#define CHECKSUM_CHECK_TCP 1
/* CHECKSUM_CHECK_ICMP==1: Check checksums by software for incoming ICMP packets.*/
#define CHECKSUM_GEN_ICMP 1
/* CHECKSUM_GEN_IP==1: Generate checksums in software for outgoing IP packets.*/
#define CHECKSUM_GEN_IP 1
/* CHECKSUM_GEN_UDP==1: Generate checksums in software for outgoing UDP packets.*/
#define CHECKSUM_GEN_UDP 1
/* CHECKSUM_GEN_TCP==1: Generate checksums in software for outgoing TCP packets.*/
#define CHECKSUM_GEN_TCP 1
/* CHECKSUM_CHECK_IP==1: Check checksums in software for incoming IP packets.*/
#define CHECKSUM_CHECK_IP 1
/* CHECKSUM_CHECK_UDP==1: Check checksums in software for incoming UDP packets.*/
#define CHECKSUM_CHECK_UDP 1
/* CHECKSUM_CHECK_TCP==1: Check checksums in software for incoming TCP packets.*/
#define CHECKSUM_CHECK_TCP 1
/* CHECKSUM_CHECK_ICMP==1: Check checksums by software for incoming ICMP packets.*/
#define CHECKSUM_GEN_ICMP 1
#endif
/*
----------------------------------------------
---------- Sequential layer options ----------
@ -444,7 +456,11 @@ The STM32F4x7 allows computing and verifying the IP, UDP, TCP and ICMP checksums
/**
* LWIP_NETCONN==1: Enable Netconn API (require to use api_lib.c)
*/
#define LWIP_NETCONN 1
// #ifndef RISCV_LWIP
// #define LWIP_NETCONN 1
// #else
#define LWIP_NETCONN 1
// #endif
/*
------------------------------------
@ -454,76 +470,74 @@ The STM32F4x7 allows computing and verifying the IP, UDP, TCP and ICMP checksums
/**
* LWIP_SOCKET==1: Enable Socket API (require to use sockets.c)
*/
#define LWIP_SOCKET 1
#define LWIP_SOCKET 1
/**
* LWIP_SO_RCVBUF==1: Enable SO_RCVBUF processing.
*/
#define LWIP_SO_RCVBUF 1
#define LWIP_SO_RCVBUF 1
/**
* LWIP_SO_SNDTIMEO==1: Enable send timeout for sockets/netconns and
* SO_SNDTIMEO processing.
*/
/**
* LWIP_SO_SNDTIMEO==1: Enable send timeout for sockets/netconns and
* SO_SNDTIMEO processing.
*/
#ifndef LWIP_SO_SNDTIMEO
#define LWIP_SO_SNDTIMEO 1
#define LWIP_SO_SNDTIMEO 1
#endif
/**
* LWIP_SO_RCVTIMEO==1: Enable receive timeout for sockets/netconns and
* SO_RCVTIMEO processing.
*/
/**
* LWIP_SO_RCVTIMEO==1: Enable receive timeout for sockets/netconns and
* SO_RCVTIMEO processing.
*/
#ifndef LWIP_SO_RCVTIMEO
#define LWIP_SO_RCVTIMEO 1
#define LWIP_SO_RCVTIMEO 1
#endif
/**
* LWIP_SO_LINGER==1: Enable SO_LINGER processing.
*/
/**
* LWIP_SO_LINGER==1: Enable SO_LINGER processing.
*/
// #define LWIP_SO_LINGER 1
/* ---------- IP options ---------- */
/* Define IP_FORWARD to 1 if you wish to have the ability to forward
IP packets across network interfaces. If you are going to run lwIP
on a device with only one network interface, define this to 0. */
#define IP_FORWARD 0
#define IP_FORWARD 0
/* IP reassembly and segmentation.These are orthogonal even
* if they both deal with IP fragments */
#ifdef LWIP_REASSEMBLY_FRAG
#define IP_REASSEMBLY 1
#define IP_FRAG 1
#define IP_REASS_MAX_PBUFS 10
#define MEMP_NUM_REASSDATA 10
#define IP_REASSEMBLY 1
#define IP_FRAG 1
#define IP_REASS_MAX_PBUFS 10
#define MEMP_NUM_REASSDATA 10
#else
#define IP_REASSEMBLY 0
#define IP_FRAG 0
#define IP_REASSEMBLY 0
#define IP_FRAG 0
#endif
/* ---------- ICMP options ---------- */
#define ICMP_TTL 255
#define ICMP_TTL 255
/* ---------- DHCP options ---------- */
/* Define LWIP_DHCP to 1 if you want DHCP configuration of
interfaces. */
#define LWIP_DHCP 1
#define LWIP_DHCP 1
/* 1 if you want to do an ARP check on the offered address
(recommended). */
#define DHCP_DOES_ARP_CHECK (LWIP_DHCP)
#define DHCP_DOES_ARP_CHECK (LWIP_DHCP)
/* ---------- AUTOIP options ------- */
#define LWIP_AUTOIP 0
#define LWIP_DHCP_AUTOIP_COOP (LWIP_DHCP && LWIP_AUTOIP)
#define LWIP_UDPLITE 0
#define UDP_TTL 255
#define LWIP_AUTOIP 0
#define LWIP_DHCP_AUTOIP_COOP (LWIP_DHCP && LWIP_AUTOIP)
#define LWIP_UDPLITE 0
#define UDP_TTL 255
/* ---------- Statistics options ---------- */
#define LWIP_STATS 1
#define LWIP_STATS_DISPLAY 1
#define LWIP_STATS 1
#define LWIP_STATS_DISPLAY 1
/*
---------------------------------
@ -531,27 +545,27 @@ The STM32F4x7 allows computing and verifying the IP, UDP, TCP and ICMP checksums
---------------------------------
*/
#define DEFAULT_RAW_RECVMBOX_SIZE 8
#define DEFAULT_UDP_RECVMBOX_SIZE 8
#define DEFAULT_TCP_RECVMBOX_SIZE 8
#define DEFAULT_ACCEPTMBOX_SIZE 10
#define DEFAULT_RAW_RECVMBOX_SIZE 8
#define DEFAULT_UDP_RECVMBOX_SIZE 8
#define DEFAULT_TCP_RECVMBOX_SIZE 8
#define DEFAULT_ACCEPTMBOX_SIZE 12
#define DEFAULT_THREAD_PRIO 20
#define DEFAULT_THREAD_STACKSIZE 2048
#define DEFAULT_THREAD_PRIO 20
#define DEFAULT_THREAD_STACKSIZE 2048
#define TCPIP_THREAD_NAME "tcp"
#define TCPIP_THREAD_STACKSIZE 2048
#define TCPIP_MBOX_SIZE 16
#define TCPIP_THREAD_PRIO 20
#define TCPIP_THREAD_NAME "tcp"
#define TCPIP_THREAD_STACKSIZE 4096
#define TCPIP_MBOX_SIZE 16
#define TCPIP_THREAD_PRIO 30
/*
----------------------------------------
---------- Lwip Debug options ----------
----------------------------------------
*/
#define LWIP_IPV4 1
#define LWIP_RAW 1
#define LWIP_DNS 1
#define LWIP_IPV4 1
#define LWIP_RAW 1
#define LWIP_DNS 1
#if LWIP_DNS
#define LWIP_RAND rand
@ -561,9 +575,8 @@ The STM32F4x7 allows computing and verifying the IP, UDP, TCP and ICMP checksums
typedef unsigned int nfds_t;
#endif
#define MEMP_LIB_MALLOC 1
#define MEMP_MEM_MALLOC 1
#define MEMP_LIB_MALLOC 1
#define MEMP_MEM_MALLOC 1
#define lw_print KPrintf
#define lw_error KPrintf
@ -572,4 +585,3 @@ typedef unsigned int nfds_t;
#endif /* __LWIPOPTS_H__ */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View File

@ -336,17 +336,23 @@ void lwip_config_input(struct netif* net)
{
sys_thread_t th_id = 0;
th_id = sys_thread_new("eth_input", ethernetif_input, net, LWIP_TASK_STACK_SIZE, 20);
th_id = sys_thread_new("eth_input", ethernetif_input, net, LWIP_TASK_STACK_SIZE, 30);
if (th_id >= 0) {
lw_print("%s %d successfully!\n", __func__, th_id);
} else {
lw_print("%s failed!\n", __func__);
}
// if (th_id >= 0) {
// lw_print("%s %d successfully!\n", __func__, th_id);
// } else {
// lw_print("%s failed!\n", __func__);
// }
}
void lwip_config_tcp(uint8_t enet_port, char* ip, char* mask, char* gw)
{
static char is_init = 0;
if (is_init != 0) {
return;
}
is_init = 1;
sys_sem_new(get_eth_recv_sem(), 0);
ip4_addr_t net_ipaddr, net_netmask, net_gw;
@ -371,7 +377,6 @@ void lwip_config_tcp(uint8_t enet_port, char* ip, char* mask, char* gw)
if (0 == enet_port) {
#ifdef NETIF_ENET0_INIT_FUNC
printf("[%s:%d] call netif_add\n", __func__, __LINE__);
netif_add(&gnetif, &net_ipaddr, &net_netmask, &net_gw, eth_cfg, NETIF_ENET0_INIT_FUNC,
tcpip_input);
#endif
@ -382,7 +387,7 @@ void lwip_config_tcp(uint8_t enet_port, char* ip, char* mask, char* gw)
#endif
}
netif_set_default(&gnetif);
// netif_set_default(&gnetif);
netif_set_up(&gnetif);
lw_print("\r\n************************************************\r\n");

View File

@ -200,7 +200,9 @@ typedef uintptr_t mem_ptr_t;
#include <unistd.h>
#endif
#else /* SSIZE_MAX */
#ifndef RISCV_LWIP
typedef int ssize_t;
#endif
#define SSIZE_MAX INT_MAX
#endif /* SSIZE_MAX */

View File

@ -1,4 +1,4 @@
SRC_FILES := ping.c lwip_ping_demo.c lwip_tcp_demo.c lwip_udp_demo.c tcpecho_raw.c lwip_config_demo.c lwip_dhcp_demo.c iperf.c http_test.c
# SRC_FILES := ping.c lwip_ping_demo.c lwip_tcp_demo.c lwip_udp_demo.c tcpecho_raw.c lwip_config_demo.c lwip_dhcp_demo.c iperf.c
# SRC_FILES := ping.c lwip_ping_demo.c lwip_config_demo.c lwip_dhcp_demo.c iperf.c http_test.c
SRC_FILES := ping.c lwip_ping_demo.c lwip_tcp_demo.c lwip_udp_demo.c tcpecho_raw.c lwip_config_demo.c lwip_dhcp_demo.c iperf.c
include $(KERNEL_ROOT)/compiler.mk

View File

@ -9,7 +9,7 @@ void httpc_app_recv_end(void *arg, httpc_result_t httpc_result, u32_t rx_content
httpc_state_t **req = (httpc_state_t**)arg;
LWIP_DEBUGF(LWIP_DEBUG, ("[HTTPC] Transfer finished. rx_content_len is %lu\r\n", rx_content_len));
printf("[HTTPC] Transfer finished. rx_content_len is %lu\r\n", rx_content_len);
printf("[HTTPC] Transfer finished. rx_content_len is %u\r\n", rx_content_len);
*req = NULL;
}

View File

@ -266,6 +266,8 @@ void iperf_server_worker(void* arg) {
struct sock_conn_cb *sccb = (struct sock_conn_cb *)arg;
x_ticks_t tick1, tick2;
int cur_tid = GetKTaskDescriptor()->id.id;
uint8_t *recv_data = (uint8_t *)malloc(IPERF_BUFSZ);
if(recv_data == NULL) {
KPrintf("[%s] No Memory.\n", __func__);
@ -282,8 +284,6 @@ void iperf_server_worker(void* arg) {
(void *) &flag, /* the cast is historical cruft */
sizeof(int)); /* length of option value */
int cur_tid = GetKTaskDescriptor()->id.id;
tick1 = CurrentTicksGain();
while (param.mode != IPERF_MODE_STOP) {
bytes_received = recv(sccb->connected, recv_data, IPERF_BUFSZ, 0);
@ -393,7 +393,7 @@ __exit:
void iperf_server(void *thread_param)
{
uint8_t *recv_data;
uint8_t* recv_data = NULL;
socklen_t sin_size;
x_ticks_t tick1, tick2;
int sock = -1, connected, bytes_received;

View File

@ -41,10 +41,10 @@ void LwipSetIPTest(int argc, char* argv[])
{
if (argc >= 4) {
printf("lw: [%s] ip %s mask %s gw %s netport %s\n", __func__, argv[1], argv[2], argv[3], argv[4]);
sscanf(argv[1], "%d.%d.%d.%d", &lwip_ipaddr[0], &lwip_ipaddr[1], &lwip_ipaddr[2], &lwip_ipaddr[3]);
sscanf(argv[2], "%d.%d.%d.%d", &lwip_netmask[0], &lwip_netmask[1], &lwip_netmask[2], &lwip_netmask[3]);
sscanf(argv[3], "%d.%d.%d.%d", &lwip_gwaddr[0], &lwip_gwaddr[1], &lwip_gwaddr[2], &lwip_gwaddr[3]);
sscanf(argv[4], "%d", &enet_id);
sscanf(argv[1], "%hhd.%hhd.%hhd.%hhd", &lwip_ipaddr[0], &lwip_ipaddr[1], &lwip_ipaddr[2], &lwip_ipaddr[3]);
sscanf(argv[2], "%hhd.%hhd.%hhd.%hhd", &lwip_netmask[0], &lwip_netmask[1], &lwip_netmask[2], &lwip_netmask[3]);
sscanf(argv[3], "%hhd.%hhd.%hhd.%hhd", &lwip_gwaddr[0], &lwip_gwaddr[1], &lwip_gwaddr[2], &lwip_gwaddr[3]);
sscanf(argv[4], "%hhd", &enet_id);
if (0 == enet_id) {
printf("save eth0 info\n");
@ -59,7 +59,7 @@ void LwipSetIPTest(int argc, char* argv[])
}
} else if (argc == 2) {
printf("lw: [%s] set eth0 ipaddr %s \n", __func__, argv[1]);
sscanf(argv[1], "%d.%d.%d.%d", &lwip_ipaddr[0], &lwip_ipaddr[1], &lwip_ipaddr[2], &lwip_ipaddr[3]);
sscanf(argv[1], "%hhd.%hhd.%hhd.%hhd", &lwip_ipaddr[0], &lwip_ipaddr[1], &lwip_ipaddr[2], &lwip_ipaddr[3]);
memcpy(lwip_eth0_ipaddr, lwip_ipaddr, strlen(lwip_ipaddr));
}
// sys_thread_new("SET ip address", LwipSetIPTask, &enet_id, LWIP_TASK_STACK_SIZE, LWIP_DEMO_TASK_PRIO);

View File

@ -144,13 +144,13 @@ void LwipDHCPTest(void)
/* Print DHCP progress */
if(LwipPrintDHCP(&gnetif))
{
sscanf(ipaddr_ntoa(&gnetif.ip_addr), "%d.%d.%d.%d", &lwip_ipaddr[0], &lwip_ipaddr[1],
sscanf(ipaddr_ntoa(&gnetif.ip_addr), "%hhd.%hhd.%hhd.%hhd", &lwip_ipaddr[0], &lwip_ipaddr[1],
&lwip_ipaddr[2], &lwip_ipaddr[3]);
sscanf(ipaddr_ntoa(&gnetif.netmask), "%d.%d.%d.%d", &lwip_netmask[0], &lwip_netmask[1],
sscanf(ipaddr_ntoa(&gnetif.netmask), "%hhd.%hhd.%hhd.%hhd", &lwip_netmask[0], &lwip_netmask[1],
&lwip_netmask[2], &lwip_netmask[3]);
sscanf(ipaddr_ntoa(&gnetif.gw), "%d.%d.%d.%d", &lwip_gwaddr[0], &lwip_gwaddr[1],
sscanf(ipaddr_ntoa(&gnetif.gw), "%hhd.%hhd.%hhd.%hhd", &lwip_gwaddr[0], &lwip_gwaddr[1],
&lwip_gwaddr[2], &lwip_gwaddr[3]);
break;

View File

@ -47,8 +47,7 @@ void LwipPingTest(int argc, char *argv[])
printf("lw: [%s] ping %s\n", __func__, argv[1]);
if(isdigit(argv[1][0]))
{
if(sscanf(argv[1], "%d.%d.%d.%d", &arg_ip[0], &arg_ip[1], &arg_ip[2], &arg_ip[3]) == EOF)
{
if (sscanf(argv[1], "%hhd.%hhd.%hhd.%hhd", &arg_ip[0], &arg_ip[1], &arg_ip[2], &arg_ip[3]) == EOF) {
lw_notice("input wrong ip\n");
return;
}

View File

@ -28,7 +28,7 @@
#include "tcpecho_raw.h"
char tcp_demo_msg[LWIP_TEST_MSG_SIZE] = { 0 };
char tcp_server_ip[] = {192, 168, 130, 2};
u16_t tcp_server_port = 80;
u32_t tcp_server_port = 80;
int tcp_send_num = 0;
int tcp_send_task_on = 0;
uint32 tcp_interval = 50;
@ -101,14 +101,13 @@ void LwipTcpSendTest(int argc, char *argv[])
strcat(tcp_demo_msg, "\r\n");
if(argc >= 3) {
if(sscanf(argv[2], "%d.%d.%d.%d:%d", &tcp_server_ip[0], &tcp_server_ip[1], &tcp_server_ip[2], &tcp_server_ip[3], &tcp_server_port) == EOK)
{
sscanf(argv[2], "%d.%d.%d.%d", &tcp_server_ip[0], &tcp_server_ip[1], &tcp_server_ip[2], &tcp_server_ip[3]);
if (sscanf(argv[2], "%hhd.%hhd.%hhd.%hhd:%d", &tcp_server_ip[0], &tcp_server_ip[1], &tcp_server_ip[2], &tcp_server_ip[3], &tcp_server_port) == EOK) {
sscanf(argv[2], "%hhd.%hhd.%hhd.%hhd", &tcp_server_ip[0], &tcp_server_ip[1], &tcp_server_ip[2], &tcp_server_ip[3]);
}
sscanf(argv[3], "%d", &tcp_send_num);
sscanf(argv[4], "%d", &tcp_interval);
}
KPrintf("connect ipaddr %d.%d.%d.%d:%d send msg %d times\n", tcp_server_ip[0], tcp_server_ip[1], tcp_server_ip[2], tcp_server_ip[3], tcp_server_port, tcp_send_num);
KPrintf("connect ipaddr %hhd.%hhd.%hhd.%hhd:%hhd send msg %d times\n", tcp_server_ip[0], tcp_server_ip[1], tcp_server_ip[2], tcp_server_ip[3], tcp_server_port, tcp_send_num);
lwip_config_tcp(enet_port, lwip_ipaddr, lwip_netmask, lwip_gwaddr);
memcpy(param.ip, tcp_server_ip, 4);
@ -126,9 +125,9 @@ void LwipTcpRecvTest(void)
{
uint8_t enet_port = 0; ///< test enet port 0
lwip_config_net(enet_port, lwip_ipaddr, lwip_netmask, lwip_gwaddr);
lwip_config_tcp(enet_port, lwip_ipaddr, lwip_netmask, lwip_gwaddr);
uint8_t *recv_data;
uint8_t* recv_data = NULL;
socklen_t sin_size;
int sock = -1, connected, bytes_received, i;
struct sockaddr_in server_addr, client_addr;

View File

@ -19,27 +19,67 @@
*/
#include "board.h"
#include "sys_arch.h"
#include "lwip/udp.h"
#include <shell.h>
#include <sys.h>
#include <xizi.h>
#include "lwip/sockets.h"
#include <stdbool.h>
#include <unistd.h>
#include "lwip/sockets.h"
#include "lwip/udp.h"
#include <argparse.h>
#include <shell.h>
#define PBUF_SIZE 27
static struct udp_pcb *udpecho_raw_pcb;
char udp_server_ip[] = {192, 168, 130, 2};
u16_t udp_server_port = LWIP_TARGET_PORT;
int32 udp_send_num = 0;
int8 udp_send_task_on = 0;
uint32 udp_interval = 50;
#define UDP_BUFFER_SIZE 50
char hello_str[] = {"hello world\r\n"};
char udp_demo_msg[] = "\nThis one is UDP package!!!\n";
char udp_demo_buffer[UDP_BUFFER_SIZE] = { '\0' };
/******************************************************************************/
enum LwipUdpSendParamEnum {
TARGET_IP = 0,
TARGET_PORT = 'p',
SEND_MESSAGE = 'm',
SEND_NUM = 'n',
SEND_INTERVAL = 'i',
};
struct LwipUdpSendParam {
uint32_t num;
uint32_t interval;
uint16_t port;
uint8_t ip[4];
bool task_on;
bool given_ip;
bool given_port;
bool given_msg;
};
struct LwipUdpSendParam* get_udp_test_info()
{
/* init once and init when used. */
static struct LwipUdpSendParam g_udp_send_param = {
.interval = 100,
.num = 10,
.port = LWIP_TARGET_PORT,
.ip = { 127, 0, 0, 1 },
.task_on = false,
.given_ip = false,
.given_port = false,
.given_msg = false,
};
return &g_udp_send_param;
}
static const char* const usages[] = {
"UDPSend [--options arg] [-option arg]",
NULL,
};
static void LwipUDPSendTask(void *arg)
{
@ -56,8 +96,8 @@ static void LwipUDPSendTask(void *arg)
struct sockaddr_in udp_sock;
udp_sock.sin_family = AF_INET;
udp_sock.sin_port = htons(udp_server_port);
udp_sock.sin_addr.s_addr = PP_HTONL(LWIP_MAKEU32(udp_server_ip[0], udp_server_ip[1], udp_server_ip[2], udp_server_ip[3]));
udp_sock.sin_port = htons(get_udp_test_info()->port);
udp_sock.sin_addr.s_addr = PP_HTONL(LWIP_MAKEU32(get_udp_test_info()->ip[0], get_udp_test_info()->ip[1], get_udp_test_info()->ip[2], get_udp_test_info()->ip[3]));
memset(&(udp_sock.sin_zero), 0, sizeof(udp_sock.sin_zero));
if (connect(socket_fd, (struct sockaddr *)&udp_sock, sizeof(struct sockaddr))) {
@ -68,59 +108,81 @@ static void LwipUDPSendTask(void *arg)
KPrintf("UDP connect success, start to send.\n");
KPrintf("\n\nTarget Port:%d\n\n", udp_sock.sin_port);
udp_send_task_on = 1;
get_udp_test_info()->task_on = true;
while(udp_send_num > 0 || udp_send_num == -1) {
sendto(socket_fd, udp_demo_msg, strlen(udp_demo_msg), 0, (struct sockaddr*)&udp_sock, sizeof(struct sockaddr));
KPrintf("Send UDP msg: %s \n", udp_demo_msg);
MdelayKTask(udp_interval);
udp_send_num--;
while (get_udp_test_info()->num > 0 || get_udp_test_info()->num == -1) {
sendto(socket_fd, udp_demo_buffer, strlen(udp_demo_buffer), 0, (struct sockaddr*)&udp_sock, sizeof(struct sockaddr));
KPrintf("Send UDP msg: %s \n", udp_demo_buffer);
MdelayKTask(get_udp_test_info()->interval);
get_udp_test_info()->num--;
}
closesocket(socket_fd);
udp_send_task_on = 0;
get_udp_test_info()->task_on = false;
return;
}
void *LwipUdpSendTest(int argc, char *argv[])
static int LwipUdpSend(int argc, char* argv[])
{
if(udp_send_task_on) {
udp_send_num = 0;
printf("waitting send task exit...\n");
while(udp_send_task_on){
MdelayKTask(1000);
}
udp_send_num = 1;
static char usage_info[] = "Send udp NUM message to IP:PORT with time INTERVAL between each message send.";
static char program_info[] = "UDP SEND TEST DEMO.";
/* Wait if there are former udp task */
if (get_udp_test_info()->task_on) {
KPrintf("[%s] Waiting former udp send task to exit.\n");
}
while (get_udp_test_info()->task_on) {
MdelayKTask(1000);
}
uint8_t enet_port = 0; ///< test enet port 0
memset(udp_demo_msg, 0, sizeof(udp_demo_msg));
get_udp_test_info()->given_ip = false;
get_udp_test_info()->given_port = false;
get_udp_test_info()->given_msg = false;
if(argc == 1) {
KPrintf("lw: [%s] gw %d.%d.%d.%d:%d\n", __func__, udp_server_ip[0], udp_server_ip[1], udp_server_ip[2], udp_server_ip[3], udp_server_port);
strncpy(udp_demo_msg, hello_str, strlen(hello_str));
udp_send_num = 10;
udp_interval = 100;
} else {
strncpy(udp_demo_msg, argv[1], strlen(argv[1]));
strncat(udp_demo_msg, "\r\n", 3);
if(argc >= 3) {
sscanf(argv[2], "%d.%d.%d.%d:%d", &udp_server_ip[0], &udp_server_ip[1], &udp_server_ip[2], &udp_server_ip[3], &udp_server_port);
}
if(argc > 3) {
sscanf(argv[3], "%d", &udp_send_num);
sscanf(argv[4], "%d", &udp_interval);
}
/* Parse options */
char* msg_ptr = NULL;
char* ip_ptr = NULL;
bool is_help = false;
struct argparse_option options[] = {
OPT_HELP(&is_help),
OPT_STRING(SEND_MESSAGE, "message", &msg_ptr, "MESSAGE to send", NULL, 0, 0),
OPT_STRING(TARGET_IP, "ip", &ip_ptr, "target IP to send upd messages", NULL, 0, 0),
OPT_INTEGER(TARGET_PORT, "port", &get_udp_test_info()->port, "target PORT to send udp messages", NULL, 0, 0),
OPT_INTEGER(SEND_NUM, "num", &get_udp_test_info()->num, "send NUM udp messages", NULL, 0, 0),
OPT_INTEGER(SEND_INTERVAL, "interval", &get_udp_test_info()->interval, "time INTERVAL between messages", NULL, 0, 0),
OPT_END(),
};
struct argparse argparse;
argparse_init(&argparse, options, usages, 0);
argparse_describe(&argparse, usage_info, program_info);
argc = argparse_parse(&argparse, argc, (const char**)argv);
if (argc < 0) {
KPrintf("Error options.\n");
return -ERROR;
}
if (is_help) {
return EOK;
}
KPrintf("lw: [%s] gw %d.%d.%d.%d:%d send time %d udp_interval %d\n", __func__, udp_server_ip[0], udp_server_ip[1], udp_server_ip[2], udp_server_ip[3], udp_server_port, udp_send_num, udp_interval);
// translate string to array
sscanf(ip_ptr, "%hhd.%hhd.%hhd.%hhd", &get_udp_test_info()->ip[0], &get_udp_test_info()->ip[1], &get_udp_test_info()->ip[2], &get_udp_test_info()->ip[3]);
int msg_len = strlen(msg_ptr);
strncpy(udp_demo_buffer, msg_ptr, msg_len < UDP_BUFFER_SIZE ? msg_len : UDP_BUFFER_SIZE);
//init lwip and net dirver
lwip_config_net(enet_port, lwip_ipaddr, lwip_netmask, lwip_gwaddr);
/* start task */
KPrintf("[%s] gw %hhd.%hhd.%hhd.%hhd:%d send time %d udp_interval %d\n", __func__,
get_udp_test_info()->ip[0], get_udp_test_info()->ip[1], get_udp_test_info()->ip[2], get_udp_test_info()->ip[3],
get_udp_test_info()->port,
get_udp_test_info()->num,
get_udp_test_info()->interval);
lwip_config_net(0, lwip_ipaddr, lwip_netmask, lwip_gwaddr);
sys_thread_new("udp send", LwipUDPSendTask, NULL, LWIP_TASK_STACK_SIZE, LWIP_DEMO_TASK_PRIO);
return EOK;
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(5),
UDPSend, LwipUdpSendTest, UDPSend msg [ip:port [num [interval]]]);
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(16),
UDPSend, LwipUdpSend, UDPSend Demo);
void LwipUdpRecvTest(void)
{
@ -129,7 +191,7 @@ void LwipUdpRecvTest(void)
//init lwip and net dirver
lwip_config_net(enet_port, lwip_ipaddr, lwip_netmask, lwip_gwaddr);
uint8_t *recv_data;
uint8_t* recv_data = NULL;
socklen_t sin_size;
int sock = -1, connected, bytes_received, i;
struct sockaddr_in server_addr, client_addr;

View File

@ -119,7 +119,7 @@ tcpecho_raw_ack_size(struct tcp_pcb *tpcb, int ack_len)
// ack message
ack_buf = pbuf_alloc(PBUF_TRANSPORT, TCP_ACK_MSG_SIZE, PBUF_RAM);
snprintf(ack_buf->payload, TCP_ACK_MSG_SIZE, "%d\n\0", ack_len);
snprintf(ack_buf->payload, TCP_ACK_MSG_SIZE, "%d\n", ack_len);
ack_buf->len = strlen(ack_buf->payload);
ack_buf->tot_len = strlen(ack_buf->payload);
ack_buf->next = NULL;

Some files were not shown because too many files have changed in this diff Show More