mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-09-23 12:15:32 +08:00
resolve Conflicts
bsp/nrf52832/board/Sconscript bsp/nrf52832/startups/Sconscript bsp/raspberry-pi/raspi4-32/driver/SConscript
This commit is contained in:
@@ -326,7 +326,7 @@ static const struct dfs_filesystem_ops _device_fs =
|
||||
|
||||
int devfs_init(void)
|
||||
{
|
||||
/* register rom file system */
|
||||
/* register device file system */
|
||||
dfs_register(&_device_fs);
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -62,7 +62,7 @@ struct romfs_dirent *dfs_romfs_lookup(struct romfs_dirent *root_dirent, const ch
|
||||
return root_dirent;
|
||||
}
|
||||
|
||||
/* goto root directy entries */
|
||||
/* goto root directory entries */
|
||||
dirent = (struct romfs_dirent *)root_dirent->data;
|
||||
dirent_size = root_dirent->size;
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ if RT_USING_I2C
|
||||
default y
|
||||
|
||||
if RT_USING_I2C_BITOPS
|
||||
config RT_I2C_BITOPS_DEBUG
|
||||
config RT_I2C_BITOPS_DEBUG
|
||||
bool "Use simulate I2C debug message"
|
||||
default n
|
||||
endif
|
||||
@@ -291,6 +291,11 @@ endif
|
||||
config RT_USING_TOUCH
|
||||
bool "Using Touch device drivers"
|
||||
default n
|
||||
if RT_USING_TOUCH
|
||||
config RT_TOUCH_PIN_IRQ
|
||||
bool "touch irq use pin irq"
|
||||
default n
|
||||
endif
|
||||
|
||||
menuconfig RT_USING_HWCRYPTO
|
||||
bool "Using Hardware Crypto drivers"
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <rthw.h>
|
||||
#include <rtthread.h>
|
||||
#include <rtdevice.h>
|
||||
|
||||
#define DBG_TAG "audio"
|
||||
@@ -45,7 +44,7 @@ static rt_err_t _audio_send_replay_frame(struct rt_audio_device *audio)
|
||||
position = audio->replay->pos;
|
||||
dst_size = buf_info->block_size;
|
||||
|
||||
/* check repaly queue is empty */
|
||||
/* check replay queue is empty */
|
||||
if (rt_data_queue_peak(&audio->replay->queue, (const void **)&data, &src_size) != RT_EOK)
|
||||
{
|
||||
/* ack stop event */
|
||||
@@ -237,7 +236,7 @@ static rt_err_t _audio_dev_init(struct rt_device *dev)
|
||||
if (replay->mp == RT_NULL)
|
||||
{
|
||||
rt_free(replay);
|
||||
LOG_E("create memory pool for repaly failed");
|
||||
LOG_E("create memory pool for replay failed");
|
||||
return -RT_ENOMEM;
|
||||
}
|
||||
|
||||
@@ -590,7 +589,6 @@ int rt_audio_samplerate_to_speed(rt_uint32_t bitValue)
|
||||
speed = 192000;
|
||||
break;
|
||||
default:
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,9 +9,7 @@
|
||||
*/
|
||||
|
||||
#include <rthw.h>
|
||||
#include <rtthread.h>
|
||||
#include <rtdevice.h>
|
||||
|
||||
#include "audio_pipe.h"
|
||||
|
||||
static void _rt_pipe_resume_writer(struct rt_audio_pipe *pipe)
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
/**
|
||||
* Pipe Device
|
||||
*/
|
||||
#include <rtthread.h>
|
||||
#include <rtdevice.h>
|
||||
|
||||
#ifndef RT_PIPE_BUFSZ
|
||||
@@ -71,6 +70,6 @@ rt_err_t rt_audio_pipe_detach(struct rt_audio_pipe *pipe);
|
||||
#ifdef RT_USING_HEAP
|
||||
rt_err_t rt_audio_pipe_create(const char *name, rt_int32_t flag, rt_size_t size);
|
||||
void rt_audio_pipe_destroy(struct rt_audio_pipe *pipe);
|
||||
#endif
|
||||
#endif
|
||||
#endif /* RT_USING_HEAP */
|
||||
|
||||
#endif /* __AUDIO_PIPE_H__ */
|
||||
|
||||
@@ -375,8 +375,6 @@ static rt_size_t i2c_bit_xfer(struct rt_i2c_bus_device *bus,
|
||||
rt_int32_t i, ret;
|
||||
rt_uint16_t ignore_nack;
|
||||
|
||||
LOG_D("send start condition");
|
||||
i2c_start(ops);
|
||||
for (i = 0; i < num; i++)
|
||||
{
|
||||
msg = &msgs[i];
|
||||
@@ -387,6 +385,11 @@ static rt_size_t i2c_bit_xfer(struct rt_i2c_bus_device *bus,
|
||||
{
|
||||
i2c_restart(ops);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_D("send start condition");
|
||||
i2c_start(ops);
|
||||
}
|
||||
ret = i2c_bit_send_address(bus, msg);
|
||||
if ((ret != RT_EOK) && !ignore_nack)
|
||||
{
|
||||
@@ -423,8 +426,11 @@ static rt_size_t i2c_bit_xfer(struct rt_i2c_bus_device *bus,
|
||||
ret = i;
|
||||
|
||||
out:
|
||||
LOG_D("send stop condition");
|
||||
i2c_stop(ops);
|
||||
if (!(msg->flags & RT_I2C_NO_STOP))
|
||||
{
|
||||
LOG_D("send stop condition");
|
||||
i2c_stop(ops);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -49,6 +49,8 @@ struct rt_alarm
|
||||
rt_uint32_t flag;
|
||||
rt_alarm_callback_t callback;
|
||||
struct tm wktime;
|
||||
|
||||
void *user_data;
|
||||
};
|
||||
|
||||
struct rt_alarm_setup
|
||||
|
||||
@@ -23,6 +23,7 @@ extern "C" {
|
||||
#define RT_I2C_NO_START (1u << 4)
|
||||
#define RT_I2C_IGNORE_NACK (1u << 5)
|
||||
#define RT_I2C_NO_READ_ACK (1u << 6) /* when I2C reading, we do not ACK */
|
||||
#define RT_I2C_NO_STOP (1u << 7)
|
||||
|
||||
struct rt_i2c_msg
|
||||
{
|
||||
@@ -83,6 +84,17 @@ rt_size_t rt_i2c_master_recv(struct rt_i2c_bus_device *bus,
|
||||
rt_uint16_t flags,
|
||||
rt_uint8_t *buf,
|
||||
rt_uint32_t count);
|
||||
|
||||
rt_inline rt_err_t rt_i2c_bus_lock(struct rt_i2c_bus_device *bus, rt_tick_t timeout)
|
||||
{
|
||||
return rt_mutex_take(&bus->lock, timeout);
|
||||
}
|
||||
|
||||
rt_inline rt_err_t rt_i2c_bus_unlock(struct rt_i2c_bus_device *bus)
|
||||
{
|
||||
return rt_mutex_release(&bus->lock);
|
||||
}
|
||||
|
||||
int rt_i2c_core_init(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -71,6 +71,7 @@ rt_size_t rt_ringbuffer_put_force(struct rt_ringbuffer *rb, const rt_uint8_t *pt
|
||||
rt_size_t rt_ringbuffer_putchar(struct rt_ringbuffer *rb, const rt_uint8_t ch);
|
||||
rt_size_t rt_ringbuffer_putchar_force(struct rt_ringbuffer *rb, const rt_uint8_t ch);
|
||||
rt_size_t rt_ringbuffer_get(struct rt_ringbuffer *rb, rt_uint8_t *ptr, rt_uint16_t length);
|
||||
rt_size_t rt_ringbuffer_peak(struct rt_ringbuffer *rb, rt_uint8_t **ptr);
|
||||
rt_size_t rt_ringbuffer_getchar(struct rt_ringbuffer *rb, rt_uint8_t *ch);
|
||||
rt_size_t rt_ringbuffer_data_len(struct rt_ringbuffer *rb);
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
* 2012-06-02 Bernard the first version
|
||||
* 2018-08-02 Tanek split run and sleep modes, support custom mode
|
||||
* 2019-04-28 Zero-Free improve PM mode and device ops interface
|
||||
* 2020-11-23 zhangsz update pm mode select
|
||||
*/
|
||||
|
||||
#include <rthw.h>
|
||||
@@ -214,8 +215,6 @@ static void _pm_change_sleep_mode(struct rt_pm *pm, rt_uint8_t mode)
|
||||
*/
|
||||
void rt_system_power_manager(void)
|
||||
{
|
||||
rt_uint8_t mode;
|
||||
|
||||
if (_pm_init_flag == 0)
|
||||
return;
|
||||
|
||||
@@ -223,8 +222,7 @@ void rt_system_power_manager(void)
|
||||
_pm_frequency_scaling(&_pm);
|
||||
|
||||
/* Low Power Mode Processing */
|
||||
mode = _pm_select_sleep_mode(&_pm);
|
||||
_pm_change_sleep_mode(&_pm, mode);
|
||||
_pm_change_sleep_mode(&_pm, _pm.sleep_mode);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -248,6 +246,7 @@ void rt_pm_request(rt_uint8_t mode)
|
||||
pm = &_pm;
|
||||
if (pm->modes[mode] < 255)
|
||||
pm->modes[mode] ++;
|
||||
_pm_select_sleep_mode(pm);
|
||||
rt_hw_interrupt_enable(level);
|
||||
}
|
||||
|
||||
@@ -273,6 +272,7 @@ void rt_pm_release(rt_uint8_t mode)
|
||||
pm = &_pm;
|
||||
if (pm->modes[mode] > 0)
|
||||
pm->modes[mode] --;
|
||||
_pm_select_sleep_mode(pm);
|
||||
rt_hw_interrupt_enable(level);
|
||||
}
|
||||
|
||||
@@ -516,6 +516,10 @@ void rt_system_pm_init(const struct rt_pm_ops *ops,
|
||||
pm->device_pm = RT_NULL;
|
||||
pm->device_pm_number = 0;
|
||||
|
||||
#if IDLE_THREAD_STACK_SIZE <= 256
|
||||
#error "[pm.c ERR] IDLE Stack Size Too Small!"
|
||||
#endif
|
||||
|
||||
_pm_init_flag = 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,13 +8,22 @@
|
||||
* 2012-10-27 heyuanjie87 first version.
|
||||
* 2013-05-17 aozima initial alarm event & mutex in system init.
|
||||
* 2020-10-15 zhangsz add alarm flags hour minute second.
|
||||
* 2020-11-09 zhangsz fix alarm set when modify rtc time.
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <rtdevice.h>
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
#define RT_RTC_YEARS_MAX 137
|
||||
#ifdef RT_USING_SOFT_RTC
|
||||
#define RT_ALARM_DELAY 0
|
||||
#else
|
||||
#define RT_ALARM_DELAY 2
|
||||
#endif
|
||||
#define RT_ALARM_STATE_INITED 0x02
|
||||
#define RT_ALARM_STATE_START 0x01
|
||||
#define RT_ALARM_STATE_STOP 0x00
|
||||
@@ -40,10 +49,12 @@ static rt_err_t alarm_set(struct rt_alarm *alarm)
|
||||
rt_err_t ret;
|
||||
|
||||
device = rt_device_find("rtc");
|
||||
|
||||
if (device == RT_NULL)
|
||||
{
|
||||
return (RT_ERROR);
|
||||
}
|
||||
|
||||
if (alarm->flag & RT_ALARM_STATE_START)
|
||||
wkalarm.enable = RT_TRUE;
|
||||
else
|
||||
@@ -102,7 +113,7 @@ static void alarm_wakeup(struct rt_alarm *alarm, struct tm *now)
|
||||
{
|
||||
alarm->wktime.tm_hour = now->tm_hour;
|
||||
alarm->wktime.tm_min = now->tm_min;
|
||||
alarm->wktime.tm_sec = alarm->wktime.tm_sec + 1;
|
||||
alarm->wktime.tm_sec = now->tm_sec + 1;
|
||||
if (alarm->wktime.tm_sec > 59)
|
||||
{
|
||||
alarm->wktime.tm_sec = 0;
|
||||
@@ -125,7 +136,7 @@ static void alarm_wakeup(struct rt_alarm *alarm, struct tm *now)
|
||||
alarm->wktime.tm_hour = now->tm_hour;
|
||||
if (alarm->wktime.tm_sec == now->tm_sec)
|
||||
{
|
||||
alarm->wktime.tm_min = alarm->wktime.tm_min + 1;
|
||||
alarm->wktime.tm_min = now->tm_min + 1;
|
||||
if (alarm->wktime.tm_min > 59)
|
||||
{
|
||||
alarm->wktime.tm_min = 0;
|
||||
@@ -144,7 +155,7 @@ static void alarm_wakeup(struct rt_alarm *alarm, struct tm *now)
|
||||
if ((alarm->wktime.tm_min == now->tm_min) &&
|
||||
(alarm->wktime.tm_sec == now->tm_sec))
|
||||
{
|
||||
alarm->wktime.tm_hour = alarm->wktime.tm_hour + 1;
|
||||
alarm->wktime.tm_hour = now->tm_hour + 1;
|
||||
if (alarm->wktime.tm_hour > 23)
|
||||
{
|
||||
alarm->wktime.tm_hour = 0;
|
||||
@@ -214,7 +225,11 @@ static void alarm_update(rt_uint32_t event)
|
||||
{
|
||||
/* get time of now */
|
||||
timestamp = time(RT_NULL);
|
||||
localtime_r(×tamp, &now);
|
||||
#ifdef _WIN32
|
||||
_gmtime32_s(&now, ×tamp);
|
||||
#else
|
||||
gmtime_r(×tamp, &now);
|
||||
#endif
|
||||
|
||||
for (next = _container.head.next; next != &_container.head; next = next->next)
|
||||
{
|
||||
@@ -224,7 +239,11 @@ static void alarm_update(rt_uint32_t event)
|
||||
}
|
||||
|
||||
timestamp = time(RT_NULL);
|
||||
localtime_r(×tamp, &now);
|
||||
#ifdef _WIN32
|
||||
_gmtime32_s(&now, ×tamp);
|
||||
#else
|
||||
gmtime_r(×tamp, &now);
|
||||
#endif
|
||||
sec_now = alarm_mkdaysec(&now);
|
||||
|
||||
for (next = _container.head.next; next != &_container.head; next = next->next)
|
||||
@@ -232,7 +251,6 @@ static void alarm_update(rt_uint32_t event)
|
||||
alarm = rt_list_entry(next, struct rt_alarm, list);
|
||||
/* calculate seconds from 00:00:00 */
|
||||
sec_alarm = alarm_mkdaysec(&alarm->wktime);
|
||||
|
||||
if (alarm->flag & RT_ALARM_STATE_START)
|
||||
{
|
||||
sec_tmp = sec_alarm - sec_now;
|
||||
@@ -256,6 +274,7 @@ static void alarm_update(rt_uint32_t event)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* enable the alarm after now first */
|
||||
if (sec_next < 24 * 3600)
|
||||
{
|
||||
@@ -328,7 +347,12 @@ static rt_err_t alarm_setup(rt_alarm_t alarm, struct tm *wktime)
|
||||
setup = &alarm->wktime;
|
||||
*setup = *wktime;
|
||||
timestamp = time(RT_NULL);
|
||||
localtime_r(×tamp, &now);
|
||||
|
||||
#ifdef _WIN32
|
||||
_gmtime32_s(&now, ×tamp);
|
||||
#else
|
||||
gmtime_r(×tamp, &now);
|
||||
#endif
|
||||
|
||||
/* if these are a "don't care" value,we set them to now*/
|
||||
if ((setup->tm_sec > 59) || (setup->tm_sec < 0))
|
||||
@@ -525,21 +549,28 @@ rt_err_t rt_alarm_control(rt_alarm_t alarm, int cmd, void *arg)
|
||||
rt_err_t rt_alarm_start(rt_alarm_t alarm)
|
||||
{
|
||||
rt_int32_t sec_now, sec_old, sec_new;
|
||||
rt_err_t ret = RT_ERROR;
|
||||
rt_err_t ret = RT_EOK;
|
||||
time_t timestamp;
|
||||
struct tm now;
|
||||
|
||||
if (alarm == RT_NULL)
|
||||
return (ret);
|
||||
return (RT_ERROR);
|
||||
rt_mutex_take(&_container.mutex, RT_WAITING_FOREVER);
|
||||
|
||||
if (!(alarm->flag & RT_ALARM_STATE_START))
|
||||
{
|
||||
if (alarm_setup(alarm, &alarm->wktime) != RT_EOK)
|
||||
{
|
||||
ret = RT_ERROR;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
timestamp = time(RT_NULL);
|
||||
localtime_r(×tamp, &now);
|
||||
#ifdef _WIN32
|
||||
_gmtime32_s(&now, ×tamp);
|
||||
#else
|
||||
gmtime_r(×tamp, &now);
|
||||
#endif
|
||||
|
||||
alarm->flag |= RT_ALARM_STATE_START;
|
||||
|
||||
@@ -592,10 +623,10 @@ _exit:
|
||||
*/
|
||||
rt_err_t rt_alarm_stop(rt_alarm_t alarm)
|
||||
{
|
||||
rt_err_t ret = RT_ERROR;
|
||||
rt_err_t ret = RT_EOK;
|
||||
|
||||
if (alarm == RT_NULL)
|
||||
return (ret);
|
||||
return (RT_ERROR);
|
||||
rt_mutex_take(&_container.mutex, RT_WAITING_FOREVER);
|
||||
if (!(alarm->flag & RT_ALARM_STATE_START))
|
||||
goto _exit;
|
||||
@@ -694,23 +725,59 @@ static void rt_alarmsvc_thread_init(void *param)
|
||||
}
|
||||
}
|
||||
|
||||
struct _alarm_flag
|
||||
{
|
||||
const char* name;
|
||||
rt_uint32_t flag;
|
||||
};
|
||||
|
||||
static const struct _alarm_flag _alarm_flag_tbl[] =
|
||||
{
|
||||
{"N", 0xffff}, /* none */
|
||||
{"O", RT_ALARM_ONESHOT}, /* only alarm onece */
|
||||
{"D", RT_ALARM_DAILY}, /* alarm everyday */
|
||||
{"W", RT_ALARM_WEEKLY}, /* alarm weekly at Monday or Friday etc. */
|
||||
{"Mo", RT_ALARM_MONTHLY}, /* alarm monthly at someday */
|
||||
{"Y", RT_ALARM_YAERLY}, /* alarm yearly at a certain date */
|
||||
{"H", RT_ALARM_HOUR}, /* alarm each hour at a certain min:second */
|
||||
{"M", RT_ALARM_MINUTE}, /* alarm each minute at a certain second */
|
||||
{"S", RT_ALARM_SECOND}, /* alarm each second */
|
||||
};
|
||||
|
||||
static rt_uint8_t _alarm_flag_tbl_size = sizeof(_alarm_flag_tbl) / sizeof(_alarm_flag_tbl[0]);
|
||||
|
||||
static rt_uint8_t get_alarm_flag_index(rt_uint32_t alarm_flag)
|
||||
{
|
||||
for (rt_uint8_t index = 0; index < _alarm_flag_tbl_size; index++)
|
||||
{
|
||||
alarm_flag &= 0xff00;
|
||||
if (alarm_flag == _alarm_flag_tbl[index].flag)
|
||||
{
|
||||
return index;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void rt_alarm_dump(void)
|
||||
{
|
||||
rt_list_t *next;
|
||||
rt_alarm_t alarm;
|
||||
rt_uint8_t index = 0;
|
||||
|
||||
rt_kprintf("| alarm_id | YYYY-MM-DD hh:mm:ss | weekday | flags |\n");
|
||||
rt_kprintf("+----------+---------------------+---------+---------+\n");
|
||||
rt_kprintf("| id | YYYY-MM-DD hh:mm:ss | week | flag | en |\n");
|
||||
rt_kprintf("+----+---------------------+------+------+----+\n");
|
||||
for (next = _container.head.next; next != &_container.head; next = next->next)
|
||||
{
|
||||
alarm = rt_list_entry(next, struct rt_alarm, list);
|
||||
rt_kprintf("| No %5d | %04d-%02d-%02d %02d:%02d:%02d | %7d | 0x%04x |\n",
|
||||
rt_uint8_t flag_index = get_alarm_flag_index(alarm->flag);
|
||||
rt_kprintf("| %2d | %04d-%02d-%02d %02d:%02d:%02d | %2d | %2s | %2d |\n",
|
||||
index++, alarm->wktime.tm_year + 1900, alarm->wktime.tm_mon + 1, alarm->wktime.tm_mday,
|
||||
alarm->wktime.tm_hour, alarm->wktime.tm_min, alarm->wktime.tm_sec,
|
||||
alarm->wktime.tm_wday, alarm->flag);
|
||||
alarm->wktime.tm_wday, _alarm_flag_tbl[flag_index].name, alarm->flag & RT_ALARM_STATE_START);
|
||||
}
|
||||
rt_kprintf("+----------+---------------------+---------+---------+\n");
|
||||
rt_kprintf("+----+---------------------+------+------+----+\n");
|
||||
}
|
||||
|
||||
FINSH_FUNCTION_EXPORT_ALIAS(rt_alarm_dump, __cmd_alarm_dump, dump alarm info);
|
||||
|
||||
@@ -11,8 +11,7 @@
|
||||
#include <time.h>
|
||||
#include <string.h>
|
||||
#include <rtthread.h>
|
||||
|
||||
#include <drivers/rtc.h>
|
||||
#include <rtdevice.h>
|
||||
|
||||
#ifdef RT_USING_SOFT_RTC
|
||||
|
||||
@@ -28,9 +27,37 @@ static struct rt_device soft_rtc_dev;
|
||||
static rt_tick_t init_tick;
|
||||
static time_t init_time;
|
||||
|
||||
#ifdef RT_USING_ALARM
|
||||
|
||||
static struct rt_rtc_wkalarm wkalarm;
|
||||
static struct rt_timer alarm_time;
|
||||
|
||||
static void alarm_timeout(void *param)
|
||||
{
|
||||
rt_alarm_update(param, 1);
|
||||
}
|
||||
|
||||
static void soft_rtc_alarm_update(struct rt_rtc_wkalarm *palarm)
|
||||
{
|
||||
rt_tick_t next_tick;
|
||||
|
||||
if (palarm->enable)
|
||||
{
|
||||
next_tick = RT_TICK_PER_SECOND;
|
||||
rt_timer_control(&alarm_time, RT_TIMER_CTRL_SET_TIME, &next_tick);
|
||||
rt_timer_start(&alarm_time);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_timer_stop(&alarm_time);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
static rt_err_t soft_rtc_control(rt_device_t dev, int cmd, void *args)
|
||||
{
|
||||
time_t *time;
|
||||
time_t *t;
|
||||
struct tm time_temp;
|
||||
|
||||
RT_ASSERT(dev != RT_NULL);
|
||||
@@ -39,16 +66,27 @@ static rt_err_t soft_rtc_control(rt_device_t dev, int cmd, void *args)
|
||||
switch (cmd)
|
||||
{
|
||||
case RT_DEVICE_CTRL_RTC_GET_TIME:
|
||||
time = (time_t *) args;
|
||||
*time = init_time + (rt_tick_get() - init_tick) / RT_TICK_PER_SECOND;
|
||||
t = (time_t *) args;
|
||||
*t = init_time + (rt_tick_get() - init_tick) / RT_TICK_PER_SECOND;
|
||||
break;
|
||||
|
||||
case RT_DEVICE_CTRL_RTC_SET_TIME:
|
||||
{
|
||||
time = (time_t *) args;
|
||||
init_time = *time - (rt_tick_get() - init_tick) / RT_TICK_PER_SECOND;
|
||||
t = (time_t *) args;
|
||||
init_time = *t - (rt_tick_get() - init_tick) / RT_TICK_PER_SECOND;
|
||||
#ifdef RT_USING_ALARM
|
||||
soft_rtc_alarm_update(&wkalarm);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
#ifdef RT_USING_ALARM
|
||||
case RT_DEVICE_CTRL_RTC_GET_ALARM:
|
||||
*((struct rt_rtc_wkalarm *)args) = wkalarm;
|
||||
break;
|
||||
case RT_DEVICE_CTRL_RTC_SET_ALARM:
|
||||
wkalarm = *((struct rt_rtc_wkalarm *)args);
|
||||
soft_rtc_alarm_update(&wkalarm);
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
||||
return RT_EOK;
|
||||
@@ -78,6 +116,15 @@ int rt_soft_rtc_init(void)
|
||||
/* make sure only one 'rtc' device */
|
||||
RT_ASSERT(!rt_device_find("rtc"));
|
||||
|
||||
#ifdef RT_USING_ALARM
|
||||
rt_timer_init(&alarm_time,
|
||||
"alarm",
|
||||
alarm_timeout,
|
||||
&soft_rtc_dev,
|
||||
0,
|
||||
RT_TIMER_FLAG_SOFT_TIMER|RT_TIMER_FLAG_ONE_SHOT);
|
||||
#endif
|
||||
|
||||
init_tick = rt_tick_get();
|
||||
init_time = mktime(&time_new);
|
||||
|
||||
|
||||
@@ -892,9 +892,9 @@ static rt_int32_t sdio_init_card(struct rt_mmcsd_host *host, rt_uint32_t ocr)
|
||||
|
||||
if (card->flags & CARD_FLAG_HIGHSPEED)
|
||||
{
|
||||
mmcsd_set_clock(host, 50000000);
|
||||
}
|
||||
else
|
||||
mmcsd_set_clock(host, card->host->freq_max > 50000000 ? 50000000 : card->host->freq_max);
|
||||
}
|
||||
else
|
||||
{
|
||||
mmcsd_set_clock(host, card->cis.max_tran_speed);
|
||||
}
|
||||
|
||||
@@ -35,7 +35,8 @@ static char *const sensor_name_str[] =
|
||||
"forc_", /* Force sensor */
|
||||
"dust_", /* Dust sensor */
|
||||
"eco2_", /* eCO2 sensor */
|
||||
"gnss_" /* GPS/GNSS sensor */
|
||||
"gnss_", /* GPS/GNSS sensor */
|
||||
"tof_" /* TOF sensor */
|
||||
};
|
||||
|
||||
/* Sensor interrupt correlation function */
|
||||
|
||||
@@ -48,6 +48,7 @@ extern "C" {
|
||||
#define RT_SENSOR_CLASS_DUST (14) /* Dust sensor */
|
||||
#define RT_SENSOR_CLASS_ECO2 (15) /* eCO2 sensor */
|
||||
#define RT_SENSOR_CLASS_GNSS (16) /* GPS/GNSS sensor */
|
||||
#define RT_SENSOR_CLASS_TOF (17) /* TOF sensor */
|
||||
|
||||
/* Sensor vendor types */
|
||||
|
||||
|
||||
@@ -50,6 +50,7 @@ static void sensor_show_data(rt_size_t num, rt_sensor_t sensor, struct rt_sensor
|
||||
LOG_I("num:%3d, light:%5d lux, timestamp:%5d", num, sensor_data->data.light, sensor_data->timestamp);
|
||||
break;
|
||||
case RT_SENSOR_CLASS_PROXIMITY:
|
||||
case RT_SENSOR_CLASS_TOF:
|
||||
LOG_I("num:%3d, distance:%5d, timestamp:%5d", num, sensor_data->data.proximity, sensor_data->timestamp);
|
||||
break;
|
||||
case RT_SENSOR_CLASS_HR:
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
* 2018-12-08 Ernest Chen add DMA choice
|
||||
* 2020-09-14 WillianChan add a line feed to the carriage return character
|
||||
* when using interrupt tx
|
||||
* 2020-12-14 Meco Man add function of setting window's size(TIOCSWINSZ)
|
||||
*/
|
||||
|
||||
#include <rthw.h>
|
||||
@@ -221,7 +222,10 @@ rt_inline int _serial_poll_rx(struct rt_serial_device *serial, rt_uint8_t *data,
|
||||
*data = ch;
|
||||
data ++; length --;
|
||||
|
||||
if (ch == '\n') break;
|
||||
if(serial->parent.open_flag & RT_DEVICE_FLAG_STREAM)
|
||||
{
|
||||
if (ch == '\n') break;
|
||||
}
|
||||
}
|
||||
|
||||
return size - length;
|
||||
@@ -1009,7 +1013,7 @@ static rt_err_t rt_serial_control(struct rt_device *dev,
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
#ifdef RT_USING_POSIX
|
||||
#ifdef RT_USING_POSIX_TERMIOS
|
||||
case TCGETA:
|
||||
{
|
||||
@@ -1101,8 +1105,7 @@ static rt_err_t rt_serial_control(struct rt_device *dev,
|
||||
break;
|
||||
case TCXONC:
|
||||
break;
|
||||
#endif
|
||||
#ifdef RT_USING_POSIX
|
||||
#endif /*RT_USING_POSIX_TERMIOS*/
|
||||
case FIONREAD:
|
||||
{
|
||||
rt_size_t recved = 0;
|
||||
@@ -1115,7 +1118,15 @@ static rt_err_t rt_serial_control(struct rt_device *dev,
|
||||
*(rt_size_t *)args = recved;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
case TIOCSWINSZ:
|
||||
{
|
||||
struct winsize* p_winsize;
|
||||
|
||||
p_winsize = (struct winsize*)args;
|
||||
rt_kprintf("\x1b[8;%d;%dt", p_winsize->ws_col, p_winsize->ws_row);
|
||||
}
|
||||
break;
|
||||
#endif /*RT_USING_POSIX*/
|
||||
default :
|
||||
/* control device */
|
||||
ret = serial->ops->control(serial, cmd, args);
|
||||
|
||||
@@ -193,6 +193,40 @@ rt_size_t rt_ringbuffer_get(struct rt_ringbuffer *rb,
|
||||
}
|
||||
RTM_EXPORT(rt_ringbuffer_get);
|
||||
|
||||
/**
|
||||
* peak data from ring buffer
|
||||
*/
|
||||
rt_size_t rt_ringbuffer_peak(struct rt_ringbuffer *rb, rt_uint8_t **ptr)
|
||||
{
|
||||
RT_ASSERT(rb != RT_NULL);
|
||||
|
||||
*ptr = RT_NULL;
|
||||
|
||||
/* whether has enough data */
|
||||
rt_size_t size = rt_ringbuffer_data_len(rb);
|
||||
|
||||
/* no data */
|
||||
if (size == 0)
|
||||
return 0;
|
||||
|
||||
*ptr = &rb->buffer_ptr[rb->read_index];
|
||||
|
||||
if(rb->buffer_size - rb->read_index > size)
|
||||
{
|
||||
rb->read_index += size;
|
||||
return size;
|
||||
}
|
||||
|
||||
size = rb->buffer_size - rb->read_index;
|
||||
|
||||
/* we are going into the other side of the mirror */
|
||||
rb->read_mirror = ~rb->read_mirror;
|
||||
rb->read_index = 0;
|
||||
|
||||
return size;
|
||||
}
|
||||
RTM_EXPORT(rt_ringbuffer_peak);
|
||||
|
||||
/**
|
||||
* put a character into ring buffer
|
||||
*/
|
||||
|
||||
@@ -424,6 +424,6 @@ int rt_work_sys_workqueue_init(void)
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
INIT_DEVICE_EXPORT(rt_work_sys_workqueue_init);
|
||||
INIT_PREV_EXPORT(rt_work_sys_workqueue_init);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -16,12 +16,9 @@
|
||||
#include <rtdbg.h>
|
||||
|
||||
/* ISR for touch interrupt */
|
||||
static void irq_callback(void *args)
|
||||
void rt_hw_touch_isr(rt_touch_t touch)
|
||||
{
|
||||
rt_touch_t touch;
|
||||
|
||||
touch = (rt_touch_t)args;
|
||||
|
||||
RT_ASSERT(touch);
|
||||
if (touch->parent.rx_indicate == RT_NULL)
|
||||
{
|
||||
return;
|
||||
@@ -35,9 +32,17 @@ static void irq_callback(void *args)
|
||||
touch->parent.rx_indicate(&touch->parent, 1);
|
||||
}
|
||||
|
||||
#ifdef RT_TOUCH_PIN_IRQ
|
||||
static void touch_irq_callback(void *param)
|
||||
{
|
||||
rt_hw_touch_isr((rt_touch_t)param);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* touch interrupt initialization function */
|
||||
static rt_err_t rt_touch_irq_init(rt_touch_t touch)
|
||||
{
|
||||
#ifdef RT_TOUCH_PIN_IRQ
|
||||
if (touch->config.irq_pin.pin == RT_PIN_NONE)
|
||||
{
|
||||
return -RT_EINVAL;
|
||||
@@ -47,18 +52,19 @@ static rt_err_t rt_touch_irq_init(rt_touch_t touch)
|
||||
|
||||
if (touch->config.irq_pin.mode == PIN_MODE_INPUT_PULLDOWN)
|
||||
{
|
||||
rt_pin_attach_irq(touch->config.irq_pin.pin, PIN_IRQ_MODE_RISING, irq_callback, (void *)touch);
|
||||
rt_pin_attach_irq(touch->config.irq_pin.pin, PIN_IRQ_MODE_RISING, touch_irq_callback, (void *)touch);
|
||||
}
|
||||
else if (touch->config.irq_pin.mode == PIN_MODE_INPUT_PULLUP)
|
||||
{
|
||||
rt_pin_attach_irq(touch->config.irq_pin.pin, PIN_IRQ_MODE_FALLING, irq_callback, (void *)touch);
|
||||
rt_pin_attach_irq(touch->config.irq_pin.pin, PIN_IRQ_MODE_FALLING, touch_irq_callback, (void *)touch);
|
||||
}
|
||||
else if (touch->config.irq_pin.mode == PIN_MODE_INPUT)
|
||||
{
|
||||
rt_pin_attach_irq(touch->config.irq_pin.pin, PIN_IRQ_MODE_RISING_FALLING, irq_callback, (void *)touch);
|
||||
rt_pin_attach_irq(touch->config.irq_pin.pin, PIN_IRQ_MODE_RISING_FALLING, touch_irq_callback, (void *)touch);
|
||||
}
|
||||
|
||||
rt_pin_irq_enable(touch->config.irq_pin.pin, PIN_IRQ_ENABLE);
|
||||
#endif
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
@@ -66,19 +72,23 @@ static rt_err_t rt_touch_irq_init(rt_touch_t touch)
|
||||
/* touch interrupt enable */
|
||||
static void rt_touch_irq_enable(rt_touch_t touch)
|
||||
{
|
||||
#ifdef RT_TOUCH_PIN_IRQ
|
||||
if (touch->config.irq_pin.pin != RT_PIN_NONE)
|
||||
{
|
||||
rt_pin_irq_enable(touch->config.irq_pin.pin, RT_TRUE);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/* touch interrupt disable */
|
||||
static void rt_touch_irq_disable(rt_touch_t touch)
|
||||
{
|
||||
#ifdef RT_TOUCH_PIN_IRQ
|
||||
if (touch->config.irq_pin.pin != RT_PIN_NONE)
|
||||
{
|
||||
rt_pin_irq_enable(touch->config.irq_pin.pin, RT_FALSE);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static rt_err_t rt_touch_open(rt_device_t dev, rt_uint16_t oflag)
|
||||
|
||||
@@ -66,7 +66,9 @@ struct rt_touch_info
|
||||
|
||||
struct rt_touch_config
|
||||
{
|
||||
#ifdef RT_TOUCH_PIN_IRQ
|
||||
struct rt_device_pin_mode irq_pin; /* Interrupt pin, The purpose of this pin is to notification read data */
|
||||
#endif
|
||||
char *dev_name; /* The name of the communication device */
|
||||
void *user_data;
|
||||
};
|
||||
@@ -103,6 +105,9 @@ int rt_hw_touch_register(rt_touch_t touch,
|
||||
rt_uint32_t flag,
|
||||
void *data);
|
||||
|
||||
/* if you doesn't use pin device. you must call this function in your touch irq callback */
|
||||
void rt_hw_touch_isr(rt_touch_t touch);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -9,10 +9,7 @@
|
||||
*/
|
||||
|
||||
#include <rthw.h>
|
||||
#include <rtthread.h>
|
||||
#include <rtservice.h>
|
||||
#include <rtdevice.h>
|
||||
|
||||
#include "drivers/usb_device.h"
|
||||
#include "audio.h"
|
||||
|
||||
|
||||
@@ -9,10 +9,7 @@
|
||||
*/
|
||||
|
||||
#include <rthw.h>
|
||||
#include <rtthread.h>
|
||||
#include <rtservice.h>
|
||||
#include <rtdevice.h>
|
||||
|
||||
#include "drivers/usb_device.h"
|
||||
#include "audio.h"
|
||||
|
||||
|
||||
@@ -13,8 +13,6 @@
|
||||
*/
|
||||
|
||||
#include <rthw.h>
|
||||
#include <rtthread.h>
|
||||
#include <rtservice.h>
|
||||
#include <rtdevice.h>
|
||||
#include <drivers/serial.h>
|
||||
#include "drivers/usb_device.h"
|
||||
|
||||
@@ -11,13 +11,9 @@
|
||||
*/
|
||||
|
||||
#include <rthw.h>
|
||||
#include <rtthread.h>
|
||||
#include <rtservice.h>
|
||||
#include <rtdevice.h>
|
||||
|
||||
#include "drivers/usb_common.h"
|
||||
#include "drivers/usb_device.h"
|
||||
|
||||
#include "hid.h"
|
||||
|
||||
#ifdef RT_USB_DEVICE_HID
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <rtservice.h>
|
||||
#include "drivers/usb_device.h"
|
||||
#include "mstorage.h"
|
||||
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
* 2017-11-16 ZYH first version
|
||||
*/
|
||||
#include <rthw.h>
|
||||
#include <rtthread.h>
|
||||
#include <rtservice.h>
|
||||
#include <rtdevice.h>
|
||||
#include <drivers/usb_device.h>
|
||||
#include "winusb.h"
|
||||
|
||||
@@ -5,20 +5,22 @@
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2020-09-05 Meco Man fix bugs
|
||||
* 2020-09-05 Meco Man fix bugs
|
||||
* 2020-12-16 Meco Man add useconds_t
|
||||
*/
|
||||
#ifndef __TYPES_H__
|
||||
#define __TYPES_H__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef int32_t clockid_t;
|
||||
typedef int32_t key_t; /* Used for interprocess communication. */
|
||||
typedef int32_t pid_t; /* Used for process IDs and process group IDs. */
|
||||
typedef int32_t clockid_t;
|
||||
typedef int32_t key_t; /* Used for interprocess communication. */
|
||||
typedef int32_t pid_t; /* Used for process IDs and process group IDs. */
|
||||
#ifndef ARCH_CPU_64BIT
|
||||
typedef signed int ssize_t; /* Used for a count of bytes or an error indication. */
|
||||
typedef signed int ssize_t; /* Used for a count of bytes or an error indication. */
|
||||
#else
|
||||
typedef long signed int ssize_t; /* Used for a count of bytes or an error indication. */
|
||||
typedef long signed int ssize_t; /* Used for a count of bytes or an error indication. */
|
||||
#endif
|
||||
typedef unsigned long useconds_t; /* microseconds (unsigned) */
|
||||
|
||||
#endif
|
||||
|
||||
@@ -5,11 +5,13 @@
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2020-12-16 Meco Man add usleep
|
||||
*/
|
||||
#ifndef _SYS_UNISTD_H
|
||||
#define _SYS_UNISTD_H
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <rtconfig.h>
|
||||
#include "types.h"
|
||||
|
||||
#ifdef RT_USING_DFS
|
||||
|
||||
@@ -68,4 +70,7 @@
|
||||
int isatty (int fd);
|
||||
char * ttyname (int desc);
|
||||
|
||||
unsigned int sleep(unsigned int seconds);
|
||||
int usleep(useconds_t usec);
|
||||
|
||||
#endif /* _SYS_UNISTD_H */
|
||||
|
||||
@@ -36,6 +36,12 @@ struct timeval {
|
||||
};
|
||||
#endif /* _TIMEVAL_DEFINED */
|
||||
|
||||
#if !defined __GNUC__ && !defined __ICCARM__
|
||||
struct timespec {
|
||||
time_t tv_sec; /* seconds */
|
||||
long tv_nsec; /* and nanoseconds */
|
||||
};
|
||||
#endif
|
||||
|
||||
struct timezone {
|
||||
int tz_minuteswest; /* minutes west of Greenwich */
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
#ifndef _TERMIOS_H__
|
||||
#define _TERMIOS_H__
|
||||
|
||||
#include <rtconfig.h>
|
||||
|
||||
#ifdef RT_USING_POSIX_TERMIOS
|
||||
#include <sys/types.h>
|
||||
#include <posix_termios.h>
|
||||
|
||||
@@ -5,20 +5,21 @@
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2020-12-16 Meco Man add useconds_t
|
||||
*/
|
||||
#ifndef __TYPES_H__
|
||||
#define __TYPES_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <rtthread.h>
|
||||
|
||||
typedef rt_int32_t clockid_t;
|
||||
typedef rt_int32_t key_t; /* Used for interprocess communication. */
|
||||
typedef rt_int32_t pid_t; /* Used for process IDs and process group IDs. */
|
||||
typedef int32_t clockid_t;
|
||||
typedef int32_t key_t; /* Used for interprocess communication. */
|
||||
typedef int32_t pid_t; /* Used for process IDs and process group IDs. */
|
||||
#ifndef ARCH_CPU_64BIT
|
||||
typedef signed int ssize_t; /* Used for a count of bytes or an error indication. */
|
||||
typedef signed int ssize_t; /* Used for a count of bytes or an error indication. */
|
||||
#else
|
||||
typedef long signed int ssize_t; /* Used for a count of bytes or an error indication. */
|
||||
typedef long signed int ssize_t; /* Used for a count of bytes or an error indication. */
|
||||
#endif
|
||||
typedef unsigned long useconds_t; /* microseconds (unsigned) */
|
||||
|
||||
#endif
|
||||
|
||||
@@ -5,10 +5,14 @@
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2020-12-16 Meco Man add usleep
|
||||
*/
|
||||
#ifndef _SYS_UNISTD_H
|
||||
#define _SYS_UNISTD_H
|
||||
|
||||
#include <rtconfig.h>
|
||||
#include "types.h"
|
||||
|
||||
#ifdef RT_USING_DFS
|
||||
|
||||
#define STDIN_FILENO 0 /* standard input file descriptor */
|
||||
@@ -40,4 +44,7 @@
|
||||
int isatty (int fd);
|
||||
char * ttyname (int desc);
|
||||
|
||||
unsigned int sleep(unsigned int seconds);
|
||||
int usleep(useconds_t usec);
|
||||
|
||||
#endif /* _SYS_UNISTD_H */
|
||||
|
||||
@@ -64,7 +64,7 @@ static sem_t *posix_sem_find(const char* name)
|
||||
|
||||
for (iter = posix_sem_list; iter != RT_NULL; iter = iter->next)
|
||||
{
|
||||
object = (rt_object_t)&(iter->sem);
|
||||
object = (rt_object_t)iter->sem;
|
||||
|
||||
if (strncmp(object->name, name, RT_NAME_MAX) == 0)
|
||||
{
|
||||
|
||||
@@ -5,10 +5,10 @@
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2020-12-16 Meco Man add usleep
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <rtthread.h>
|
||||
|
||||
#include <rthw.h>
|
||||
#include <unistd.h>
|
||||
|
||||
unsigned int sleep(unsigned int seconds)
|
||||
@@ -21,3 +21,10 @@ unsigned int sleep(unsigned int seconds)
|
||||
|
||||
return seconds - delta_tick/RT_TICK_PER_SECOND;
|
||||
}
|
||||
|
||||
int usleep(useconds_t usec)
|
||||
{
|
||||
rt_thread_mdelay(usec / 1000u);
|
||||
rt_hw_us_delay(usec % 1000u);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -821,24 +821,17 @@ int at_recvfrom(int socket, void *mem, size_t len, int flags, struct sockaddr *f
|
||||
goto __exit;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (sock->state == AT_SOCKET_CONNECT)
|
||||
{
|
||||
|
||||
/* get receive buffer to receiver ring buffer */
|
||||
rt_mutex_take(sock->recv_lock, RT_WAITING_FOREVER);
|
||||
recv_len = at_recvpkt_get(&(sock->recvpkt_list), (char *) mem, len);
|
||||
rt_mutex_release(sock->recv_lock);
|
||||
if (recv_len > 0)
|
||||
{
|
||||
/* get receive buffer to receiver ring buffer */
|
||||
rt_mutex_take(sock->recv_lock, RT_WAITING_FOREVER);
|
||||
recv_len = at_recvpkt_get(&(sock->recvpkt_list), (char *) mem, len);
|
||||
rt_mutex_release(sock->recv_lock);
|
||||
if (recv_len > 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_D("received data exit, current socket (%d) is closed by remote.", socket);
|
||||
result = 0;
|
||||
goto __exit;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -156,6 +156,16 @@ static int lwip_netdev_set_dns_server(struct netdev *netif, uint8_t dns_num, ip_
|
||||
static int lwip_netdev_set_dhcp(struct netdev *netif, rt_bool_t is_enabled)
|
||||
{
|
||||
netdev_low_level_set_dhcp_status(netif, is_enabled);
|
||||
|
||||
if(RT_TRUE == is_enabled)
|
||||
{
|
||||
dhcp_start((struct netif *)netif->user_data);
|
||||
}
|
||||
else
|
||||
{
|
||||
dhcp_stop((struct netif *)netif->user_data);
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
#endif /* RT_LWIP_DHCP */
|
||||
|
||||
@@ -163,6 +163,16 @@ static int lwip_netdev_set_dns_server(struct netdev *netif, uint8_t dns_num, ip_
|
||||
static int lwip_netdev_set_dhcp(struct netdev *netif, rt_bool_t is_enabled)
|
||||
{
|
||||
netdev_low_level_set_dhcp_status(netif, is_enabled);
|
||||
|
||||
if(RT_TRUE == is_enabled)
|
||||
{
|
||||
dhcp_start((struct netif *)netif->user_data);
|
||||
}
|
||||
else
|
||||
{
|
||||
dhcp_stop((struct netif *)netif->user_data);
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
#endif /* RT_LWIP_DHCP */
|
||||
|
||||
@@ -78,7 +78,7 @@ int netdev_register(struct netdev *netdev, const char *name, void *user_data)
|
||||
netdev->addr_callback = RT_NULL;
|
||||
|
||||
/* fill network interface device */
|
||||
rt_strncpy(netdev->name, name, rt_strlen(name));
|
||||
rt_strncpy(netdev->name, name, RT_NAME_MAX);
|
||||
netdev->user_data = user_data;
|
||||
|
||||
/* initialize current network interface device single list */
|
||||
@@ -260,7 +260,7 @@ struct netdev *netdev_get_by_name(const char *name)
|
||||
for (node = &(netdev_list->list); node; node = rt_slist_next(node))
|
||||
{
|
||||
netdev = rt_slist_entry(node, struct netdev, list);
|
||||
if (netdev && (rt_strncmp(netdev->name, name, rt_strlen(netdev->name)) == 0))
|
||||
if (netdev && (rt_strncmp(netdev->name, name, RT_NAME_MAX) == 0))
|
||||
{
|
||||
rt_hw_interrupt_enable(level);
|
||||
return netdev;
|
||||
@@ -856,7 +856,7 @@ void netdev_low_level_set_dhcp_status(struct netdev *netdev, rt_bool_t is_enable
|
||||
static void netdev_list_if(void)
|
||||
{
|
||||
#define NETDEV_IFCONFIG_MAC_MAX_LEN 6
|
||||
#define NETDEV_IFCONFIG_IEMI_MAX_LEN 8
|
||||
#define NETDEV_IFCONFIG_IMEI_MAX_LEN 8
|
||||
|
||||
rt_ubase_t index;
|
||||
rt_slist_t *node = RT_NULL;
|
||||
@@ -887,16 +887,22 @@ static void netdev_list_if(void)
|
||||
rt_kprintf("%02x ", netdev->hwaddr[index]);
|
||||
}
|
||||
}
|
||||
else if (netdev->hwaddr_len == NETDEV_IFCONFIG_IEMI_MAX_LEN)
|
||||
else if (netdev->hwaddr_len == NETDEV_IFCONFIG_IMEI_MAX_LEN)
|
||||
{
|
||||
rt_kprintf("IMEI: ");
|
||||
for (index = 0; index < netdev->hwaddr_len; index++)
|
||||
{
|
||||
/* two numbers are displayed at one time*/
|
||||
if (netdev->hwaddr[index] < 10 && index != netdev->hwaddr_len - 1)
|
||||
rt_kprintf("0");
|
||||
|
||||
rt_kprintf("%d", netdev->hwaddr[index]);
|
||||
{
|
||||
rt_kprintf("%02d", netdev->hwaddr[index]);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_kprintf("%d", netdev->hwaddr[index]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,6 +41,13 @@ struct sal_socket_table
|
||||
struct sal_socket **sockets;
|
||||
};
|
||||
|
||||
/* record the netdev and res table*/
|
||||
struct sal_netdev_res_table
|
||||
{
|
||||
struct addrinfo *res;
|
||||
struct netdev *netdev;
|
||||
};
|
||||
|
||||
#ifdef SAL_USING_TLS
|
||||
/* The global TLS protocol options */
|
||||
static struct sal_proto_tls *proto_tls;
|
||||
@@ -50,6 +57,7 @@ static struct sal_proto_tls *proto_tls;
|
||||
static struct sal_socket_table socket_table;
|
||||
static struct rt_mutex sal_core_lock;
|
||||
static rt_bool_t init_ok = RT_FALSE;
|
||||
static struct sal_netdev_res_table sal_dev_res_tbl[SAL_SOCKETS_NUM];
|
||||
|
||||
#define IS_SOCKET_PROTO_TLS(sock) (((sock)->protocol == PROTOCOL_TLS) || \
|
||||
((sock)->protocol == PROTOCOL_DTLS))
|
||||
@@ -90,6 +98,11 @@ do {
|
||||
((pf) = (struct sal_proto_family *) (netdev)->sal_user_data) != RT_NULL && \
|
||||
(pf)->netdb_ops->ops) \
|
||||
|
||||
#define SAL_NETDBOPS_VALID(netdev, pf, ops) \
|
||||
((netdev) && \
|
||||
((pf) = (struct sal_proto_family *) (netdev)->sal_user_data) != RT_NULL && \
|
||||
(pf)->netdb_ops->ops) \
|
||||
|
||||
/**
|
||||
* SAL (Socket Abstraction Layer) initialize.
|
||||
*
|
||||
@@ -116,6 +129,9 @@ int sal_init(void)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*init the dev_res table */
|
||||
rt_memset(sal_dev_res_tbl, 0, sizeof(sal_dev_res_tbl));
|
||||
|
||||
/* create sal socket lock */
|
||||
rt_mutex_init(&sal_core_lock, "sal_lock", RT_IPC_FLAG_FIFO);
|
||||
|
||||
@@ -309,12 +325,13 @@ struct sal_socket *sal_get_socket(int socket)
|
||||
{
|
||||
struct sal_socket_table *st = &socket_table;
|
||||
|
||||
socket = socket - SAL_SOCKET_OFFSET;
|
||||
|
||||
if (socket < 0 || socket >= (int) st->max_socket)
|
||||
{
|
||||
return RT_NULL;
|
||||
}
|
||||
|
||||
socket = socket - SAL_SOCKET_OFFSET;
|
||||
/* check socket structure valid or not */
|
||||
RT_ASSERT(st->sockets[socket]->magic == SAL_SOCKET_MAGIC);
|
||||
|
||||
@@ -975,7 +992,7 @@ int sal_closesocket(int socket)
|
||||
|
||||
/* clsoesocket operation not need to vaild network interface status */
|
||||
/* valid the network interface socket opreation */
|
||||
SAL_NETDEV_SOCKETOPS_VALID(sock->netdev, pf, socket);
|
||||
SAL_NETDEV_SOCKETOPS_VALID(sock->netdev, pf, closesocket);
|
||||
|
||||
if (pf->skt_ops->closesocket((int) sock->user_data) == 0)
|
||||
{
|
||||
@@ -1086,10 +1103,12 @@ int sal_getaddrinfo(const char *nodename,
|
||||
{
|
||||
struct netdev *netdev = netdev_default;
|
||||
struct sal_proto_family *pf;
|
||||
int ret = 0;
|
||||
rt_uint32_t i = 0;
|
||||
|
||||
if (SAL_NETDEV_NETDBOPS_VALID(netdev, pf, getaddrinfo))
|
||||
{
|
||||
return pf->netdb_ops->getaddrinfo(nodename, servname, hints, res);
|
||||
ret = pf->netdb_ops->getaddrinfo(nodename, servname, hints, res);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1097,30 +1116,56 @@ int sal_getaddrinfo(const char *nodename,
|
||||
netdev = netdev_get_first_by_flags(NETDEV_FLAG_UP);
|
||||
if (SAL_NETDEV_NETDBOPS_VALID(netdev, pf, getaddrinfo))
|
||||
{
|
||||
return pf->netdb_ops->getaddrinfo(nodename, servname, hints, res);
|
||||
ret = pf->netdb_ops->getaddrinfo(nodename, servname, hints, res);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = -1;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
if(ret == RT_EOK)
|
||||
{
|
||||
/*record the netdev and res*/
|
||||
for(i = 0; i < SAL_SOCKETS_NUM; i++)
|
||||
{
|
||||
if(sal_dev_res_tbl[i].res == RT_NULL)
|
||||
{
|
||||
sal_dev_res_tbl[i].res = *res;
|
||||
sal_dev_res_tbl[i].netdev = netdev;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
RT_ASSERT((i < SAL_SOCKETS_NUM));
|
||||
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void sal_freeaddrinfo(struct addrinfo *ai)
|
||||
{
|
||||
struct netdev *netdev = netdev_default;
|
||||
struct sal_proto_family *pf;
|
||||
struct netdev *netdev = RT_NULL;
|
||||
struct sal_proto_family *pf = RT_NULL;
|
||||
rt_uint32_t i = 0;
|
||||
|
||||
if (SAL_NETDEV_NETDBOPS_VALID(netdev, pf, freeaddrinfo))
|
||||
/*when use the multi netdev, it must free the ai use the getaddrinfo netdev */
|
||||
for(i = 0; i < SAL_SOCKETS_NUM; i++)
|
||||
{
|
||||
if(sal_dev_res_tbl[i].res == ai)
|
||||
{
|
||||
netdev = sal_dev_res_tbl[i].netdev;
|
||||
sal_dev_res_tbl[i].res = RT_NULL;
|
||||
sal_dev_res_tbl[i].netdev = RT_NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
RT_ASSERT((i < SAL_SOCKETS_NUM));
|
||||
|
||||
if (SAL_NETDBOPS_VALID(netdev, pf, freeaddrinfo))
|
||||
{
|
||||
pf->netdb_ops->freeaddrinfo(ai);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* get the first network interface device with up status */
|
||||
netdev = netdev_get_first_by_flags(NETDEV_FLAG_UP);
|
||||
if (SAL_NETDEV_NETDBOPS_VALID(netdev, pf, freeaddrinfo))
|
||||
{
|
||||
pf->netdb_ops->freeaddrinfo(ai);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user