[rtc] use gmtime_r to replace gmtime (#6012)

* [rtc] use gmtime_r to replace gmtime
This commit is contained in:
Man, Jianting (Meco)
2022-06-22 13:41:06 +08:00
committed by GitHub
parent 4f1f8566f4
commit 2c10d5ad01
56 changed files with 2873 additions and 2907 deletions
+10 -10
View File
@@ -49,21 +49,21 @@ static rt_err_t set_rtc_time_stamp(time_t time_stamp)
{
RTC_TimeTypeDef RTC_TimeStruct = {0};
RTC_DateTypeDef RTC_DateStruct = {0};
struct tm *p_tm;
struct tm now;
p_tm = gmtime(&time_stamp);
if (p_tm->tm_year < 100)
gmtime_r(&time_stamp, &now);
if (now.tm_year < 100)
{
return -RT_ERROR;
}
RTC_TimeStruct.u8_Seconds = dec2hex(p_tm->tm_sec);
RTC_TimeStruct.u8_Minutes = dec2hex(p_tm->tm_min);
RTC_TimeStruct.u8_Hours = dec2hex(p_tm->tm_hour);
RTC_DateStruct.u8_Date = dec2hex(p_tm->tm_mday);
RTC_DateStruct.u8_Month = dec2hex(p_tm->tm_mon + 1);
RTC_DateStruct.u8_Year = dec2hex(p_tm->tm_year - 100);
RTC_DateStruct.u8_WeekDay = dec2hex(p_tm->tm_wday) + 1;
RTC_TimeStruct.u8_Seconds = dec2hex(now.tm_sec);
RTC_TimeStruct.u8_Minutes = dec2hex(now.tm_min);
RTC_TimeStruct.u8_Hours = dec2hex(now.tm_hour);
RTC_DateStruct.u8_Date = dec2hex(now.tm_mday);
RTC_DateStruct.u8_Month = dec2hex(now.tm_mon + 1);
RTC_DateStruct.u8_Year = dec2hex(now.tm_year - 100);
RTC_DateStruct.u8_WeekDay = dec2hex(now.tm_wday) + 1;
HAL_RTC_SetTime(&RTC_TimeStruct);
HAL_RTC_SetDate(&RTC_DateStruct);
+9 -9
View File
@@ -38,7 +38,7 @@ static rt_err_t rt_rtc_control(rt_device_t dev, int cmd, void *args)
{
time_t *time;
struct tm time_temp;
struct tm* time_new;
struct tm time_new;
am_hal_rtc_time_t hal_time;
RT_ASSERT(dev != RT_NULL);
@@ -71,16 +71,16 @@ static rt_err_t rt_rtc_control(rt_device_t dev, int cmd, void *args)
case RT_DEVICE_CTRL_RTC_SET_TIME:
time = (time_t *)args;
time_new = gmtime(time);
gmtime_r(time, &time_new);
hal_time.ui32Hour = time_new->tm_hour;
hal_time.ui32Minute = time_new->tm_min;
hal_time.ui32Second = time_new->tm_sec;
hal_time.ui32Hour = time_new.tm_hour;
hal_time.ui32Minute = time_new.tm_min;
hal_time.ui32Second = time_new.tm_sec;
hal_time.ui32Hundredths = 00;
hal_time.ui32Weekday = time_new->tm_wday;
hal_time.ui32DayOfMonth = time_new->tm_mday;
hal_time.ui32Month = time_new->tm_mon + 1;
hal_time.ui32Year = time_new->tm_year + 1900 - 2000;
hal_time.ui32Weekday = time_new.tm_wday;
hal_time.ui32DayOfMonth = time_new.tm_mday;
hal_time.ui32Month = time_new.tm_mon + 1;
hal_time.ui32Year = time_new.tm_year + 1900 - 2000;
hal_time.ui32Century = 0;
am_hal_rtc_time_set(&hal_time);
+5 -5
View File
@@ -49,22 +49,22 @@ static rt_err_t set_rtc_time_stamp(time_t time_stamp)
{
#if defined (SOC_SERIES_AT32F435) || defined (SOC_SERIES_AT32F437) || \
defined (SOC_SERIES_AT32F415)
struct tm *p_tm;
struct tm now;
p_tm = gmtime(&time_stamp);
if (p_tm->tm_year < 100)
gmtime_r(&time_stamp, &now);
if (now.tm_year < 100)
{
return -RT_ERROR;
}
/* set time */
if(ertc_time_set(p_tm->tm_hour, p_tm->tm_min, p_tm->tm_sec, ERTC_AM) != SUCCESS)
if(ertc_time_set(now.tm_hour, now.tm_min, now.tm_sec, ERTC_AM) != SUCCESS)
{
return -RT_ERROR;
}
/* set date */
if(ertc_date_set(p_tm->tm_year - 100, p_tm->tm_mon + 1, p_tm->tm_mday, p_tm->tm_wday + 1) != SUCCESS)
if(ertc_date_set(now.tm_year - 100, now.tm_mon + 1, now.tm_mday, now.tm_wday + 1) != SUCCESS)
{
return -RT_ERROR;
}
+1 -11
View File
@@ -55,9 +55,7 @@ static void __rtc_init(rtc_init_t *init)
static rt_err_t es32f0_rtc_control(rt_device_t dev, int cmd, void *args)
{
rt_err_t result = RT_EOK;
struct tm time_temp;
struct tm *pNow;
rtc_date_t date;
rtc_time_t time;
@@ -76,15 +74,7 @@ static rt_err_t es32f0_rtc_control(rt_device_t dev, int cmd, void *args)
break;
case RT_DEVICE_CTRL_RTC_SET_TIME:
rt_enter_critical();
/* converts calendar time time into local time. */
pNow = gmtime((const time_t *)args);
/* copy the statically located variable */
memcpy(&time_temp, pNow, sizeof(struct tm));
/* unlock scheduler. */
rt_exit_critical();
gmtime_r((const time_t *)args, &time_temp);
time.hour = time_temp.tm_hour;
time.minute = time_temp.tm_min;
time.second = time_temp.tm_sec;
+1 -11
View File
@@ -54,9 +54,7 @@ static void __rtc_init(rtc_init_t *init)
static rt_err_t es32f0_rtc_control(rt_device_t dev, int cmd, void *args)
{
rt_err_t result = RT_EOK;
struct tm time_temp;
struct tm *pNow;
rtc_date_t date;
rtc_time_t time;
@@ -75,15 +73,7 @@ static rt_err_t es32f0_rtc_control(rt_device_t dev, int cmd, void *args)
break;
case RT_DEVICE_CTRL_RTC_SET_TIME:
rt_enter_critical();
/* converts calendar time time into local time. */
pNow = gmtime((const time_t *)args);
/* copy the statically located variable */
memcpy(&time_temp, pNow, sizeof(struct tm));
/* unlock scheduler. */
rt_exit_critical();
gmtime_r((const time_t *)args, &time_temp);
time.hour = time_temp.tm_hour;
time.minute = time_temp.tm_min;
time.second = time_temp.tm_sec;
+8 -8
View File
@@ -45,18 +45,18 @@ static time_t get_timestamp(void)
static int set_timestamp(time_t timestamp)
{
struct tm *p_tm;
struct tm now;
snvs_hp_rtc_datetime_t rtcDate = {0};
p_tm = gmtime(&timestamp);
gmtime_r(&timestamp, &now);
rtcDate.second = p_tm->tm_sec ;
rtcDate.minute = p_tm->tm_min ;
rtcDate.hour = p_tm->tm_hour;
rtcDate.second = now.tm_sec ;
rtcDate.minute = now.tm_min ;
rtcDate.hour = now.tm_hour;
rtcDate.day = p_tm->tm_mday;
rtcDate.month = p_tm->tm_mon + 1;
rtcDate.year = p_tm->tm_year + 1900;
rtcDate.day = now.tm_mday;
rtcDate.month = now.tm_mon + 1;
rtcDate.year = now.tm_year + 1900;
if (SNVS_HP_RTC_SetDatetime(SNVS, &rtcDate) != kStatus_Success)
{
+14 -14
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -181,19 +181,19 @@ void rt_hw_uart_init(void)
struct serial_configure config = RT_SERIAL_CONFIG_DEFAULT;
#ifdef RT_USING_UART5
uart = &uart5;
serial5.ops = &ls1b_uart_ops;
serial5.config = config;
rt_hw_interrupt_install(uart->IRQ, uart_irq_handler, &serial5, "UART5");
/* register UART5 device */
rt_hw_serial_register(&serial5,
"uart5",
//RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_DMA_RX,
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX,
uart);
uart = &uart5;
serial5.ops = &ls1b_uart_ops;
serial5.config = config;
rt_hw_interrupt_install(uart->IRQ, uart_irq_handler, &serial5, "UART5");
/* register UART5 device */
rt_hw_serial_register(&serial5,
"uart5",
//RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_DMA_RX,
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX,
uart);
#endif /* RT_USING_UART5 */
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -7,7 +7,7 @@
* Date Author Notes
* 2011-08-09 lgnq first version for LS1B DC
* 2015-07-06 chinesebear modified for loongson 1c
* 2018-01-06 sundm75 modified for smartloong
* 2018-01-06 sundm75 modified for smartloong
*/
#include <rtthread.h>
@@ -78,13 +78,13 @@ int caclulate_freq(rt_uint32_t XIN, rt_uint32_t PCLK)
pix_div = (pix_div>>24)&0xff;
rt_kprintf("old pll_clk=%d, pix_div=%d\n", pll_clk, pix_div);
divider_int = pll_clk/(1000000) *PCLK/1000;
divider_int = pll_clk/(1000000) *PCLK/1000;
if(divider_int%1000>=500)
divider_int = divider_int/1000+1;
else
divider_int = divider_int/1000;
rt_kprintf("divider_int = %d\n", divider_int);
/* check whether divisor is too small. */
if (divider_int < 1) {
rt_kprintf("Warning: clock source is too slow.Try smaller resolution\n");
@@ -102,9 +102,9 @@ int caclulate_freq(rt_uint32_t XIN, rt_uint32_t PCLK)
regval &= ~0x80000030; //PIX_DIV_VALID PIX_SEL 置0
regval &= ~(0x3f<<24); //PIX_DIV 清零
regval |= divider_int << 24;
PLL_DIV_PARAM = regval;
PLL_DIV_PARAM = regval;
regval |= 0x80000030; //PIX_DIV_VALID PIX_SEL 置1
PLL_DIV_PARAM = regval;
PLL_DIV_PARAM = regval;
}
rt_kprintf("new PLL_FREQ=0x%x, PLL_DIV_PARAM=0x%x\n", PLL_FREQ, PLL_DIV_PARAM);
rt_thread_delay(10);
@@ -115,11 +115,11 @@ static rt_err_t rt_dc_init(rt_device_t dev)
{
int i, out, mode=-1;
int val;
rt_kprintf("PWM initied\n");
/* Set the back light PWM. */
pwminit();
for (i=0; i<sizeof(vga_mode)/sizeof(struct vga_struct); i++)
{
if (vga_mode[i].hr == FB_XSIZE && vga_mode[i].vr == FB_YSIZE)
@@ -140,7 +140,7 @@ static rt_err_t rt_dc_init(rt_device_t dev)
DC_FB_CONFIG = 0x0;
DC_FB_CONFIG = 0x3; // // framebuffer configuration RGB565
DC_DITHER_CONFIG = 0x0; //颜色抖动配置寄存器
DC_DITHER_TABLE_LOW = 0x0; //颜色抖动查找表低位寄存器
DC_DITHER_TABLE_LOW = 0x0; //颜色抖动查找表低位寄存器
DC_DITHER_TABLE_HIGH = 0x0; //颜色抖动查找表高位寄存器
DC_PANEL_CONFIG = 0x80001311; //液晶面板配置寄存器
DC_PANEL_TIMING = 0x0;
@@ -165,10 +165,10 @@ static rt_err_t rt_dc_init(rt_device_t dev)
#elif defined(CONFIG_VIDEO_12BPP)
DC_FB_CONFIG = 0x00100101;
DC_FB_BUFFER_STRIDE = (FB_XSIZE*2+255)&(~255);
#else
#else
DC_FB_CONFIG = 0x00100104;
DC_FB_BUFFER_STRIDE = (FB_XSIZE*4+255)&(~255);
#endif
#endif
return RT_EOK;
}
@@ -200,7 +200,7 @@ static rt_err_t rt_dc_control(rt_device_t dev, int cmd, void *args)
break;
case RTGRAPHIC_CTRL_POWEROFF:
break;
case RTGRAPHIC_CTRL_GET_INFO:
case RTGRAPHIC_CTRL_GET_INFO:
rt_memcpy(args, &_dc_info, sizeof(_dc_info));
break;
case RTGRAPHIC_CTRL_SET_MODE:
@@ -213,7 +213,7 @@ static rt_err_t rt_dc_control(rt_device_t dev, int cmd, void *args)
void rt_hw_dc_init(void)
{
rt_device_t dc = rt_malloc(sizeof(struct rt_device));
if (dc == RT_NULL)
if (dc == RT_NULL)
{
rt_kprintf("dc == RT_NULL\n");
return; /* no memory yet */
@@ -232,10 +232,10 @@ void rt_hw_dc_init(void)
dc->close = RT_NULL;
dc->control = rt_dc_control;
dc->user_data = (void*)&_dc_info;
/* register Display Controller device to RT-Thread */
rt_device_register(dc, "dc", RT_DEVICE_FLAG_RDWR);
rt_device_init(dc);
}
@@ -250,7 +250,7 @@ int rtgui_lcd_init(void)
pin_set_purpose(76, PIN_PURPOSE_OTHER);
pin_set_remap(76, PIN_REMAP_DEFAULT);
/* init Display Controller */
rt_hw_dc_init();
@@ -259,7 +259,7 @@ int rtgui_lcd_init(void)
/* set Display Controller device as rtgui graphic driver */
rtgui_graphic_set_device(dc);
return 0;
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -7,9 +7,9 @@
* Date Author Notes
* 2011-08-08 lgnq first version for LS1B
* 2015-07-06 chinesebear modified for loongson 1c
* 2018-01-06 sundm75 modified for smartloong
* 2018-01-06 sundm75 modified for smartloong
*/
#ifndef __DISPLAY_CONTROLLER_H__
#define __DISPLAY_CONTROLLER_H__
@@ -19,31 +19,31 @@
#define DC_BASE 0xBC301240 //Display Controller
/* Frame Buffer registers */
#define DC_FB_CONFIG __REG32(DC_BASE + 0x000)
#define DC_FB_BUFFER_ADDR0 __REG32(DC_BASE + 0x020)
#define DC_FB_BUFFER_STRIDE __REG32(DC_BASE + 0x040)
#define DC_FB_BUFFER_ORIGIN __REG32(DC_BASE + 0x060)
#define DC_DITHER_CONFIG __REG32(DC_BASE + 0x120)
#define DC_DITHER_TABLE_LOW __REG32(DC_BASE + 0x140)
#define DC_DITHER_TABLE_HIGH __REG32(DC_BASE + 0x160)
#define DC_PANEL_CONFIG __REG32(DC_BASE + 0x180)
#define DC_PANEL_TIMING __REG32(DC_BASE + 0x1A0)
#define DC_HDISPLAY __REG32(DC_BASE + 0x1C0)
#define DC_HSYNC __REG32(DC_BASE + 0x1E0)
#define DC_VDISPLAY __REG32(DC_BASE + 0x240)
#define DC_VSYNC __REG32(DC_BASE + 0x260)
#define DC_FB_BUFFER_ADDR1 __REG32(DC_BASE + 0x340)
#define DC_FB_CONFIG __REG32(DC_BASE + 0x000)
#define DC_FB_BUFFER_ADDR0 __REG32(DC_BASE + 0x020)
#define DC_FB_BUFFER_STRIDE __REG32(DC_BASE + 0x040)
#define DC_FB_BUFFER_ORIGIN __REG32(DC_BASE + 0x060)
#define DC_DITHER_CONFIG __REG32(DC_BASE + 0x120)
#define DC_DITHER_TABLE_LOW __REG32(DC_BASE + 0x140)
#define DC_DITHER_TABLE_HIGH __REG32(DC_BASE + 0x160)
#define DC_PANEL_CONFIG __REG32(DC_BASE + 0x180)
#define DC_PANEL_TIMING __REG32(DC_BASE + 0x1A0)
#define DC_HDISPLAY __REG32(DC_BASE + 0x1C0)
#define DC_HSYNC __REG32(DC_BASE + 0x1E0)
#define DC_VDISPLAY __REG32(DC_BASE + 0x240)
#define DC_VSYNC __REG32(DC_BASE + 0x260)
#define DC_FB_BUFFER_ADDR1 __REG32(DC_BASE + 0x340)
/* Display Controller driver for 1024x768 16bit */
#define FB_XSIZE 480
#define FB_YSIZE 272
#define FB_XSIZE 480
#define FB_YSIZE 272
#define CONFIG_VIDEO_16BPP
#define OSC 24000000 /* Hz */
#define OSC 24000000 /* Hz */
#define K1BASE 0xA0000000
#define KSEG1(addr) ((void *)(K1BASE | (rt_uint32_t)(addr)))
#define HW_FB_ADDR KSEG1(_rt_framebuffer)
#define K1BASE 0xA0000000
#define KSEG1(addr) ((void *)(K1BASE | (rt_uint32_t)(addr)))
#define HW_FB_ADDR KSEG1(_rt_framebuffer)
struct vga_struct
{
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -90,7 +90,7 @@ rt_err_t ls1c_pin_attach_irq(struct rt_device *device, rt_int32_t pin,
break;
}
gpio_set_irq_type(gpio, type);
rt_sprintf(irq_name, "PIN_%d", gpio);
rt_hw_interrupt_install(LS1C_GPIO_TO_IRQ(gpio), (rt_isr_handler_t)hdr, args, irq_name);
+11 -11
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -59,17 +59,17 @@ static rt_err_t get(struct rt_device_pwm *device, struct rt_pwm_configuration *c
{
rt_err_t result = RT_EOK;
struct rt_ls1c_pwm *ls1c_pwm_device = (struct rt_ls1c_pwm *)device;
if (configuration->channel > (PWM_CHANNEL_MAX - 1))
{
result = -RT_EIO;
goto _exit;
}
configuration->period = ls1c_pwm_device->period[configuration->channel];
configuration->pulse = ls1c_pwm_device->pulse[configuration->channel];
rt_kprintf("drv_pwm.c get channel %d: period: %d, pulse: %d\n", configuration->channel, configuration->period, configuration->pulse);
_exit:
return result;
}
@@ -84,7 +84,7 @@ static rt_err_t control(struct rt_device_pwm *device, int cmd, void *arg)
if (cmd == PWM_CMD_ENABLE)
{
rt_kprintf("PWM_CMD_ENABLE\n");
pwm_info_t pwm_info;
switch ( configuration->channel)
{
@@ -107,9 +107,9 @@ static rt_err_t control(struct rt_device_pwm *device, int cmd, void *arg)
default:
break;
}
pwm_info.mode = PWM_MODE_NORMAL;
pwm_info.duty = ( (float)configuration->pulse ) / ((float)configuration->period );
pwm_info.period_ns = configuration->period;
pwm_info.mode = PWM_MODE_NORMAL;
pwm_info.duty = ( (float)configuration->pulse ) / ((float)configuration->period );
pwm_info.period_ns = configuration->period;
pwm_init(&pwm_info);
pwm_enable(&pwm_info);
}
@@ -138,9 +138,9 @@ static rt_err_t control(struct rt_device_pwm *device, int cmd, void *arg)
default:
break;
}
pwm_info.mode = PWM_MODE_NORMAL;
pwm_info.duty = ( (float)configuration->pulse ) / ((float)configuration->period );
pwm_info.period_ns = configuration->period;
pwm_info.mode = PWM_MODE_NORMAL;
pwm_info.duty = ( (float)configuration->pulse ) / ((float)configuration->period );
pwm_info.period_ns = configuration->period;
pwm_init(&pwm_info);
pwm_disable(&pwm_info);
}
+33 -33
View File
@@ -1,10 +1,10 @@
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* Date Author Notes
* 2018-05-05 sundm75 first version
*/
@@ -21,56 +21,56 @@
#if defined(RT_USING_RTC)
#ifdef RT_RTC_DEBUG
#define rtc_debug(format,args...) rt_kprintf(format, ##args)
#define rtc_debug(format,args...) rt_kprintf(format, ##args)
#else
#define rtc_debug(format,args...)
#endif
static struct rt_device rtc;
RTC_TypeDef * RTC_Handler;
RTC_TypeDef * RTC_Handler;
static time_t get_timestamp(void)
static time_t get_timestamp(void)
{
struct tm tm_new = {0};
RTC_TimeTypeDef rtcDate;
RTC_GetTime(RTC_Handler, &rtcDate);
tm_new.tm_sec = rtcDate.Seconds;
tm_new.tm_min = rtcDate.Minutes;
struct tm tm_new = {0};
RTC_TimeTypeDef rtcDate;
RTC_GetTime(RTC_Handler, &rtcDate);
tm_new.tm_sec = rtcDate.Seconds;
tm_new.tm_min = rtcDate.Minutes;
tm_new.tm_hour = rtcDate.Hours;
tm_new.tm_mday = rtcDate.Date;
tm_new.tm_mon = rtcDate.Month- 1;
tm_new.tm_year = rtcDate.Year + 2000 - 1900;
tm_new.tm_mday = rtcDate.Date;
tm_new.tm_mon = rtcDate.Month- 1;
tm_new.tm_year = rtcDate.Year + 2000 - 1900;
return timegm(&tm_new);
}
static int set_timestamp(time_t timestamp)
{
struct tm *p_tm;
RTC_TimeTypeDef rtcDate;
p_tm = gmtime(&timestamp);
rtcDate.Seconds= p_tm->tm_sec ;
rtcDate.Minutes= p_tm->tm_min ;
rtcDate.Hours= p_tm->tm_hour;
struct tm now;
RTC_TimeTypeDef rtcDate;
rtcDate.Date= p_tm->tm_mday;
rtcDate.Month= p_tm->tm_mon + 1;
rtcDate.Year= p_tm->tm_year + 1900 - 2000;
RTC_SetTime(RTC_Handler, &rtcDate);
gmtime_r(&timestamp, &now);
rtcDate.Seconds= now.tm_sec ;
rtcDate.Minutes= now.tm_min ;
rtcDate.Hours= now.tm_hour;
rtcDate.Date= now.tm_mday;
rtcDate.Month= now.tm_mon + 1;
rtcDate.Year= now.tm_year + 1900 - 2000;
RTC_SetTime(RTC_Handler, &rtcDate);
rt_kprintf("\r\nrtcDate is %d.%d.%d - %d:%d:%d",rtcDate.Year, rtcDate.Month, rtcDate.Date, rtcDate.Hours, rtcDate.Minutes, rtcDate.Seconds);
return RT_EOK;
}
rt_uint8_t RTC_Init(void)
{
RTC_Handler = RTC;
{
RTC_Handler = RTC;
return 0;
}
@@ -90,7 +90,7 @@ static rt_size_t rt_rtc_read(
void* buffer,
rt_size_t size)
{
return 0;
}
@@ -109,7 +109,7 @@ static rt_err_t rt_rtc_control(rt_device_t dev, int cmd, void *args)
switch (cmd)
{
case RT_DEVICE_CTRL_RTC_GET_TIME:
*(rt_uint32_t *)args = get_timestamp();
rtc_debug("RTC: get rtc_time %x\n", *(rt_uint32_t *)args);
break;
+5 -5
View File
@@ -1,18 +1,18 @@
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* Date Author Notes
* 2018-05-05 sundm75 first version
*/
#ifndef __DRV_RTC_H__
#define __DRV_RTC_H__
#include <rtthread.h>
#include <rtdevice.h>
#include <rtthread.h>
#include <rtdevice.h>
int rt_hw_rtc_init(void);
+2 -2
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -32,7 +32,7 @@ struct ls1c_spi_cs
* 初始化并注册龙芯1c的spi总线
* @SPI SPI总线,比如LS1C_SPI_0, LS1C_SPI_1
* @spi_bus_name 总线名字
* @ret
* @ret
*/
rt_err_t ls1c_spi_bus_register(rt_uint8_t SPI, const char *spi_bus_name);
+2 -2
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -9,7 +9,7 @@
* 2018-10-29 XY
* 2019-04-11 sundm75 modify for ls1c300 & RTGUI
*/
#include "drv_touch.h"
#define TOUCH_I2C_NAME "i2c1"
+2 -2
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -8,7 +8,7 @@
* 2018-02-08 Zhangyihong the first version
* 2018-10-29 XY
*/
#ifndef __DRV_TOUCH_H__
#define __DRV_TOUCH_H__
+6 -6
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -161,15 +161,15 @@ static rt_err_t watchdog_ctrl(rt_watchdog_t *wdt, int cmd, void *arg)
return RT_EOK;
}
struct rt_watchdog_ops watchdog_ops =
struct rt_watchdog_ops watchdog_ops =
{
.init = &watchdog_init,
.init = &watchdog_init,
.control = &watchdog_ctrl,
};
int wdt_exit(void *priv_data)
{
return 0;
int wdt_exit(void *priv_data)
{
return 0;
}
int rt_hw_wdt_init(void)
+16 -16
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -10,7 +10,7 @@
#include <rtthread.h>
#include <rtdevice.h>
#include "ls1c_i2c.h"
#include "ls1c_i2c.h"
#include "../libraries/ls1c_pin.h"
#ifdef RT_USING_I2C
@@ -26,30 +26,30 @@ rt_size_t rt_i2c_master_xfer(struct rt_i2c_bus_device *bus,
rt_uint32_t num)
{
struct ls1c_i2c_bus * i2c_bus = (struct ls1c_i2c_bus *)bus;
ls1c_i2c_info_t i2c_info;
ls1c_i2c_info_t i2c_info;
struct rt_i2c_msg *msg;
int i;
rt_int32_t ret = RT_EOK;
i2c_info.clock = 50000; // 50kb/s
i2c_info.clock = 50000; // 50kb/s
i2c_info.I2Cx = i2c_bus->u32Module;
i2c_init(&i2c_info);
for (i = 0; i < num; i++)
{
msg = &msgs[i];
if (msg->flags == RT_I2C_RD)
{
i2c_send_start_and_addr(&i2c_info, msg->addr, LS1C_I2C_DIRECTION_READ);
i2c_receive_ack(&i2c_info);
i2c_receive_data(&i2c_info, (rt_uint8_t *)msg->buf, msg->len);
i2c_send_stop(&i2c_info);
i2c_send_start_and_addr(&i2c_info, msg->addr, LS1C_I2C_DIRECTION_READ);
i2c_receive_ack(&i2c_info);
i2c_receive_data(&i2c_info, (rt_uint8_t *)msg->buf, msg->len);
i2c_send_stop(&i2c_info);
}
else if(msg->flags == RT_I2C_WR)
{
i2c_send_start_and_addr(&i2c_info, msg->addr, LS1C_I2C_DIRECTION_WRITE);
i2c_receive_ack(&i2c_info);
i2c_send_data(&i2c_info, (rt_uint8_t *)msg->buf, msg->len);
i2c_send_stop(&i2c_info);
i2c_send_start_and_addr(&i2c_info, msg->addr, LS1C_I2C_DIRECTION_WRITE);
i2c_receive_ack(&i2c_info);
i2c_send_data(&i2c_info, (rt_uint8_t *)msg->buf, msg->len);
i2c_send_stop(&i2c_info);
}
ret++;
}
@@ -85,7 +85,7 @@ static const struct rt_i2c_bus_device_ops ls1c_i2c_ops =
#ifdef RT_USING_I2C0
static struct ls1c_i2c_bus ls1c_i2c_bus_0 =
static struct ls1c_i2c_bus ls1c_i2c_bus_0 =
{
{1},
LS1C_I2C_0,
@@ -93,7 +93,7 @@ static struct ls1c_i2c_bus ls1c_i2c_bus_0 =
#endif
#ifdef RT_USING_I2C1
static struct ls1c_i2c_bus ls1c_i2c_bus_1 =
static struct ls1c_i2c_bus ls1c_i2c_bus_1 =
{
{1},
LS1C_I2C_1,
@@ -101,7 +101,7 @@ static struct ls1c_i2c_bus ls1c_i2c_bus_1 =
#endif
#ifdef RT_USING_I2C2
static struct ls1c_i2c_bus ls1c_i2c_bus_2 =
static struct ls1c_i2c_bus ls1c_i2c_bus_2 =
{
{1},
LS1C_I2C_2,
+2 -2
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -15,4 +15,4 @@
int rt_i2c_init(void);
#endif
#endif
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -579,7 +579,7 @@ struct pbuf *rt_eth_rx(rt_device_t device)
if (synopGMAC_is_rx_desc_valid(status) || SYNOP_PHY_LOOPBACK)
{
dma_addr1 = plat_dma_map_single(gmacdev, (void *)data1, RX_BUF_SIZE);
len = synopGMAC_get_rx_desc_frame_length(status)-4; //Not interested in Ethernet CRC bytes
len = synopGMAC_get_rx_desc_frame_length(status)-4; //Not interested in Ethernet CRC bytes
pbuf = pbuf_alloc(PBUF_LINK, len, PBUF_RAM);
if (pbuf == 0) rt_kprintf("===error in pbuf_alloc\n");
rt_memcpy(pbuf->payload, (char *)data1, len);
+2 -2
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -20,4 +20,4 @@
int rt_hw_eth_init(void);
#endif /*__SYNOPGMAC__H*/
#endif /*__SYNOPGMAC__H*/
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -21,35 +21,35 @@
struct net_device_stats
{
unsigned long rx_packets; /* total packets received */
unsigned long tx_packets; /* total packets transmitted */
unsigned long rx_bytes; /* total bytes received */
unsigned long tx_bytes; /* total bytes transmitted */
unsigned long rx_errors; /* bad packets received */
unsigned long tx_errors; /* packet transmit problems */
unsigned long rx_dropped; /* no space in linux buffers */
unsigned long tx_dropped; /* no space available in linux */
unsigned long multicast; /* multicast packets received */
unsigned long collisions;
unsigned long rx_packets; /* total packets received */
unsigned long tx_packets; /* total packets transmitted */
unsigned long rx_bytes; /* total bytes received */
unsigned long tx_bytes; /* total bytes transmitted */
unsigned long rx_errors; /* bad packets received */
unsigned long tx_errors; /* packet transmit problems */
unsigned long rx_dropped; /* no space in linux buffers */
unsigned long tx_dropped; /* no space available in linux */
unsigned long multicast; /* multicast packets received */
unsigned long collisions;
/* detailed rx_errors: */
unsigned long rx_length_errors;
unsigned long rx_over_errors; /* receiver ring buff overflow */
unsigned long rx_crc_errors; /* recved pkt with crc error */
unsigned long rx_frame_errors; /* recv'd frame alignment error */
unsigned long rx_fifo_errors; /* recv'r fifo overrun */
unsigned long rx_missed_errors; /* receiver missed packet */
/* detailed rx_errors: */
unsigned long rx_length_errors;
unsigned long rx_over_errors; /* receiver ring buff overflow */
unsigned long rx_crc_errors; /* recved pkt with crc error */
unsigned long rx_frame_errors; /* recv'd frame alignment error */
unsigned long rx_fifo_errors; /* recv'r fifo overrun */
unsigned long rx_missed_errors; /* receiver missed packet */
/* detailed tx_errors */
unsigned long tx_aborted_errors;
unsigned long tx_carrier_errors;
unsigned long tx_fifo_errors;
unsigned long tx_heartbeat_errors;
unsigned long tx_window_errors;
/* for cslip etc */
unsigned long rx_compressed;
unsigned long tx_compressed;
/* detailed tx_errors */
unsigned long tx_aborted_errors;
unsigned long tx_carrier_errors;
unsigned long tx_fifo_errors;
unsigned long tx_heartbeat_errors;
unsigned long tx_window_errors;
/* for cslip etc */
unsigned long rx_compressed;
unsigned long tx_compressed;
};
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -14,8 +14,8 @@
//#define GMAC_DEBUG
#include <rtthread.h>
#ifdef GMAC_DEBUG
#define DEBUG_MES rt_kprintf
#ifdef GMAC_DEBUG
#define DEBUG_MES rt_kprintf
#else
#define DEBUG_MES(...)
#endif
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -8,7 +8,7 @@
* 2017-08-24 chinesebear first version
*/
#ifndef SYNOP_GMAC_NETWORK_INTERFACE_H
#define SYNOP_GMAC_NETWORK_INTERFACE_H 1
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -8,7 +8,7 @@
* 2017-08-24 chinesebear first version
*/
#include "synopGMAC_plat.h"
#include "synopGMAC_Dev.h"
#include <rthw.h>
@@ -16,58 +16,58 @@
extern void flush_cache(unsigned long start_addr, unsigned long size);
dma_addr_t __attribute__((weak)) gmac_dmamap(unsigned long va,u32 size)
{
return VA_TO_PA (va);
//return UNCACHED_TO_PHYS(va);
return VA_TO_PA (va);
//return UNCACHED_TO_PHYS(va);
}
/**
* This is a wrapper function for Memory allocation routine. In linux Kernel
* This is a wrapper function for Memory allocation routine. In linux Kernel
* it it kmalloc function
* @param[in] bytes in bytes to allocate
*/
void *plat_alloc_memory(u32 bytes)
void *plat_alloc_memory(u32 bytes)
{
//return (void*)malloc((size_t)bytes, M_DEVBUF, M_DONTWAIT);
void *buf = (void*)rt_malloc((u32)bytes);
void *buf = (void*)rt_malloc((u32)bytes);
flush_cache((unsigned long)buf, bytes);
return buf;
flush_cache((unsigned long)buf, bytes);
return buf;
}
/**
* This is a wrapper function for consistent dma-able Memory allocation routine.
* This is a wrapper function for consistent dma-able Memory allocation routine.
* In linux Kernel, it depends on pci dev structure
* @param[in] bytes in bytes to allocate
*/
//void *plat_alloc_consistent_dmaable_memory(struct synopGMACdevice *dev, u32 size, u32 *addr)
void *plat_alloc_consistent_dmaable_memory(synopGMACdevice *pcidev, u32 size, u32 *addr)
//void *plat_alloc_consistent_dmaable_memory(struct synopGMACdevice *dev, u32 size, u32 *addr)
void *plat_alloc_consistent_dmaable_memory(synopGMACdevice *pcidev, u32 size, u32 *addr)
{
void *buf;
buf = (void*)rt_malloc((u32)(size+16));
//CPU_IOFlushDCache( buf,size, SYNC_W);
unsigned long i = (unsigned long)buf;
// rt_kprintf("size = %d\n", size);
// rt_kprintf("bufaddr = %p\n", buf);
// rt_kprintf("i%%16 == %d\n", i%16);
if(i%16 == 8){
i += 8;
}
else if(i%16 == 4){
i += 12;
}
else if(i%16 == 12){
i += 4;
}
void *buf;
buf = (void*)rt_malloc((u32)(size+16));
//CPU_IOFlushDCache( buf,size, SYNC_W);
unsigned long i = (unsigned long)buf;
// rt_kprintf("size = %d\n", size);
// rt_kprintf("bufaddr = %p\n", buf);
// rt_kprintf("i%%16 == %d\n", i%16);
if(i%16 == 8){
i += 8;
}
else if(i%16 == 4){
i += 12;
}
else if(i%16 == 12){
i += 4;
}
flush_cache(i, size);
*addr =gmac_dmamap(i, size);
buf = (unsigned char *)CACHED_TO_UNCACHED(i);
// rt_kprintf("bufaddr = %p\n", buf);
return buf;
flush_cache(i, size);
*addr =gmac_dmamap(i, size);
buf = (unsigned char *)CACHED_TO_UNCACHED(i);
// rt_kprintf("bufaddr = %p\n", buf);
return buf;
}
@@ -78,46 +78,46 @@ void *plat_alloc_consistent_dmaable_memory(synopGMACdevice *pcidev, u32 size, u3
*/
//void plat_free_consistent_dmaable_memory(void * addr)
void plat_free_consistent_dmaable_memory(synopGMACdevice *pcidev, u32 size, void * addr,u32 dma_addr)
//void plat_free_consistent_dmaable_memory(void * addr)
void plat_free_consistent_dmaable_memory(synopGMACdevice *pcidev, u32 size, void * addr,u32 dma_addr)
{
rt_free((void*)PHYS_TO_CACHED(UNCACHED_TO_PHYS(addr)));
rt_free((void*)PHYS_TO_CACHED(UNCACHED_TO_PHYS(addr)));
return;
}
/**
* This is a wrapper function for Memory free routine. In linux Kernel
* This is a wrapper function for Memory free routine. In linux Kernel
* it it kfree function
* @param[in] buffer pointer to be freed
*/
void plat_free_memory(void *buffer)
void plat_free_memory(void *buffer)
{
rt_free(buffer);
return ;
rt_free(buffer);
return ;
}
dma_addr_t plat_dma_map_single(void *hwdev, void *ptr,
u32 size)
u32 size)
{
unsigned long addr = (unsigned long) ptr;
unsigned long addr = (unsigned long) ptr;
//CPU_IOFlushDCache(addr,size, direction);
flush_cache(addr, size);
flush_cache(addr, size);
return gmac_dmamap(addr, size);
}
/**
* This is a wrapper function for platform dependent delay
* Take care while passing the argument to this function
* This is a wrapper function for platform dependent delay
* Take care while passing the argument to this function
* @param[in] buffer pointer to be freed
*/
void plat_delay(u32 delay)
{
while (delay--);
return;
while (delay--);
return;
}
File diff suppressed because it is too large Load Diff
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -22,4 +22,4 @@ typedef signed int s32;
typedef u32 dma_addr_t;
#endif /*__TYPES__H*/
#endif /*__TYPES__H*/
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+7 -7
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -10,20 +10,20 @@
#ifndef __TOUCH_H__
#define __TOUCH_H__
#define RT_TOUCH_NORMAL 0
#define RT_TOUCH_CALIBRATION_DATA 1
#define RT_TOUCH_CALIBRATION 2
#define RT_TOUCH_NORMAL 0
#define RT_TOUCH_CALIBRATION_DATA 1
#define RT_TOUCH_CALIBRATION 2
//#define SAVE_CALIBRATION
rt_uint16_t touch_read_x(void);
rt_uint16_t touch_read_y(void);
void touch_config(void);
rt_err_t rtgui_touch_hw_init(const char * spi_device_name);
#endif
+1 -1
View File
@@ -128,7 +128,6 @@ static rt_err_t rt_rtc_ioctl(rt_device_t dev, int cmd, void *args)
hw_rtc = dev->user_data;
t = (time_t *)args;
time = *gmtime(t);
rtctm.sys_toyread0 = hw_rtc->sys_toyread0;
rtctm.sys_toyread1 = hw_rtc->sys_toyread1;
@@ -141,6 +140,7 @@ static rt_err_t rt_rtc_ioctl(rt_device_t dev, int cmd, void *args)
*t = timegm(&tmptime);
break;
case RT_DEVICE_CTRL_RTC_SET_TIME:
gmtime_r(t, &time);
tmptime.tm_hour = time.tm_hour;
tmptime.tm_min = time.tm_min;
tmptime.tm_sec = time.tm_sec;
+10 -10
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2020, RT-Thread Development Team
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -18,15 +18,15 @@
#include "drv_uart.h"
#define TRUE 1
#define FALSE 0
const struct serial_configure config_uart0 = {
BAUD_RATE_115200, /* 921600 bits/s */
DATA_BITS_8, /* 8 databits */
STOP_BITS_1, /* 1 stopbit */
PARITY_NONE, /* No parity */
BIT_ORDER_LSB, /* LSB first sent */
NRZ_NORMAL, /* Normal mode */
RT_SERIAL_RB_BUFSZ, /* Buffer size */
0
const struct serial_configure config_uart0 = {
BAUD_RATE_115200, /* 921600 bits/s */
DATA_BITS_8, /* 8 databits */
STOP_BITS_1, /* 1 stopbit */
PARITY_NONE, /* No parity */
BIT_ORDER_LSB, /* LSB first sent */
NRZ_NORMAL, /* Normal mode */
RT_SERIAL_RB_BUFSZ, /* Buffer size */
0
};
struct rt_uart_ls2k
{
+1 -1
View File
@@ -38,7 +38,7 @@
#define PM1_STS HWREG32(PM1_BASE)
#define PM1_EN HWREG32(PM1_BASE + 0x04)
#define PM1_CNT HWREG32(PM1_BASE + 0x08)
/*
* Watch Dog Configuration Registers
*/
+4 -4
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -172,15 +172,15 @@
/* Which connector port. */
#define PORT_TP 0x00
#define PORT_AUI 0x01
#define PORT_MII 0x02
#define PORT_MII 0x02
#define PORT_FIBRE 0x03
#define PORT_BNC 0x04
/* Which transceiver to use. */
#define XCVR_INTERNAL 0x00
#define XCVR_EXTERNAL 0x01
#define XCVR_DUMMY1 0x02
#define XCVR_DUMMY2 0x03
#define XCVR_DUMMY1 0x02
#define XCVR_DUMMY2 0x03
#define XCVR_DUMMY3 0x04
#define AUTONEG_DISABLE 0x00
File diff suppressed because it is too large Load Diff
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -42,7 +42,7 @@ struct net_device_stats
unsigned long tx_fifo_errors;
unsigned long tx_heartbeat_errors;
unsigned long tx_window_errors;
/* for cslip etc */
unsigned long rx_compressed;
unsigned long tx_compressed;
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -13,7 +13,7 @@
//#define GMAC_DEBUG
#include <rtthread.h>
#ifdef GMAC_DEBUG
#ifdef GMAC_DEBUG
#define DEBUG_MES rt_kprintf
#else
#define DEBUG_MES(...)
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -57,17 +57,17 @@ typedef int bool;
#define VA_TO_PA(x) CACHED_TO_PHYS(x)
/* sw
#define TR0(fmt, args...) printk(KERN_CRIT "SynopGMAC: " fmt, ##args)
#define TR0(fmt, args...) printk(KERN_CRIT "SynopGMAC: " fmt, ##args)
#ifdef DEBUG
#undef TR
# define TR(fmt, args...) printk(KERN_CRIT "SynopGMAC: " fmt, ##args)
#else
# define TR(fmt, args...) // not debugging: nothing
# define TR(fmt, args...) // not debugging: nothing
#endif
*/
/*
#define TR0(fmt, args...) printf("SynopGMAC: " fmt, ##args)
#define TR0(fmt, args...) printf("SynopGMAC: " fmt, ##args)
*/
/*
@@ -75,20 +75,20 @@ typedef int bool;
#undef TR
# define TR(fmt, args...) printf("SynopGMAC: " fmt, ##args)
#else
//# define TR(fmt, args...) // not debugging: nothing
#define TR(fmt, args...) printf("SynopGMAC: " fmt, ##args)
//# define TR(fmt, args...) // not debugging: nothing
#define TR(fmt, args...) printf("SynopGMAC: " fmt, ##args)
#endif
*/
//sw: nothing to display
#define TR0(fmt, args...) //rt_kprintf(fmt, ##args)
#define TR(fmt, args...) //rt_kprintf(fmt, ##args)
#define TR0(fmt, args...) //rt_kprintf(fmt, ##args)
#define TR(fmt, args...) //rt_kprintf(fmt, ##args)
//typedef int bool;
enum synopGMAC_boolean
{
{
false = 0,
true = 1
true = 1
};
#define DEFAULT_DELAY_VARIABLE 10
@@ -117,7 +117,7 @@ struct Network_interface_data
/**
* These are the wrapper function prototypes for OS/platform related routines
*/
*/
void * plat_alloc_memory(u32 );
void plat_free_memory(void *);
@@ -128,10 +128,10 @@ void plat_delay(u32);
/**
* The Low level function to read register contents from Hardware.
*
* @param[in] pointer to the base of register map
*
* @param[in] pointer to the base of register map
* @param[in] Offset from the base
* \return Returns the register contents
* \return Returns the register contents
*/
static u32 synopGMACReadReg(u64 RegBase, u32 RegOffset)
{
@@ -151,11 +151,11 @@ static u32 synopGMACReadReg(u64 RegBase, u32 RegOffset)
/**
* The Low level function to write to a register in Hardware.
*
* @param[in] pointer to the base of register map
*
* @param[in] pointer to the base of register map
* @param[in] Offset from the base
* @param[in] Data to be written
* \return void
* @param[in] Data to be written
* \return void
*/
static void synopGMACWriteReg(u64 RegBase, u32 RegOffset, u32 RegData )
{
@@ -173,18 +173,18 @@ static void synopGMACWriteReg(u64 RegBase, u32 RegOffset, u32 RegData )
/**
* The Low level function to set bits of a register in Hardware.
*
* @param[in] pointer to the base of register map
*
* @param[in] pointer to the base of register map
* @param[in] Offset from the base
* @param[in] Bit mask to set bits to logical 1
* \return void
* @param[in] Bit mask to set bits to logical 1
* \return void
*/
static void synopGMACSetBits(u64 RegBase, u32 RegOffset, u32 BitPos)
{
//u64 addr = (u64)RegBase + (u64)RegOffset;
u32 data;
data = synopGMACReadReg(RegBase, RegOffset);
data |= BitPos;
data |= BitPos;
synopGMACWriteReg(RegBase, RegOffset, data);
// writel(data,(void *)addr);
#if SYNOP_REG_DEBUG
@@ -196,17 +196,17 @@ static void synopGMACSetBits(u64 RegBase, u32 RegOffset, u32 BitPos)
/**
* The Low level function to clear bits of a register in Hardware.
*
* @param[in] pointer to the base of register map
*
* @param[in] pointer to the base of register map
* @param[in] Offset from the base
* @param[in] Bit mask to clear bits to logical 0
* \return void
* @param[in] Bit mask to clear bits to logical 0
* \return void
*/
static void synopGMACClearBits(u64 RegBase, u32 RegOffset, u32 BitPos)
{
u32 data;
data = synopGMACReadReg(RegBase, RegOffset);
data &= (~BitPos);
data &= (~BitPos);
synopGMACWriteReg(RegBase, RegOffset, data);
#if SYNOP_REG_DEBUG
TR("%s !!!!!!!!!!!!! RegOffset = 0x%08x RegData = 0x%08x\n", __FUNCTION__, RegOffset, data );
@@ -216,24 +216,24 @@ static void synopGMACClearBits(u64 RegBase, u32 RegOffset, u32 BitPos)
/**
* The Low level function to Check the setting of the bits.
*
* @param[in] pointer to the base of register map
*
* @param[in] pointer to the base of register map
* @param[in] Offset from the base
* @param[in] Bit mask to set bits to logical 1
* @param[in] Bit mask to set bits to logical 1
* \return returns TRUE if set to '1' returns FALSE if set to '0'. Result undefined there are no bit set in the BitPos argument.
*
*
*/
static bool synopGMACCheckBits(u64 RegBase, u32 RegOffset, u32 BitPos)
{
u32 data;
data = synopGMACReadReg(RegBase, RegOffset);
data &= BitPos;
data &= BitPos;
if(data)
if(data)
{
return true;
}
else
else
{
return false;
}
+8 -8
View File
@@ -43,18 +43,18 @@ static time_t get_timestamp(void)
static int set_timestamp(time_t timestamp)
{
struct tm *p_tm;
struct tm now;
rtc_datetime_t rtcDate;
p_tm = gmtime(&timestamp);
gmtime_r(&timestamp, &now);
rtcDate.second = p_tm->tm_sec ;
rtcDate.minute = p_tm->tm_min ;
rtcDate.hour = p_tm->tm_hour;
rtcDate.second = now.tm_sec ;
rtcDate.minute = now.tm_min ;
rtcDate.hour = now.tm_hour;
rtcDate.day = p_tm->tm_mday;
rtcDate.month = p_tm->tm_mon + 1;
rtcDate.year = p_tm->tm_year + 1900;
rtcDate.day = now.tm_mday;
rtcDate.month = now.tm_mon + 1;
rtcDate.year = now.tm_year + 1900;
/* RTC time counter has to be stopped before setting the date & time in the TSR register */
RTC_StopTimer(RTC);
@@ -200,7 +200,7 @@ static rt_err_t nu_rtc_is_date_valid(const time_t t)
/* Register rt-thread device.control() entry. */
static rt_err_t nu_rtc_control(rt_device_t dev, int cmd, void *args)
{
struct tm tm_out, *tm_in;
struct tm tm_out, tm_in;
time_t *time;
S_RTC_TIME_DATA_T hw_time;
@@ -236,13 +236,13 @@ static rt_err_t nu_rtc_control(rt_device_t dev, int cmd, void *args)
if (nu_rtc_is_date_valid(*time) != RT_EOK)
return -(RT_ERROR);
tm_in = gmtime(time);
hw_time.u32Year = CONV_FROM_TM_YEAR(tm_in->tm_year);
hw_time.u32Month = CONV_FROM_TM_MON(tm_in->tm_mon);
hw_time.u32Day = tm_in->tm_mday;
hw_time.u32Hour = tm_in->tm_hour;
hw_time.u32Minute = tm_in->tm_min;
hw_time.u32Second = tm_in->tm_sec;
gmtime_r(time, &tm_in);
hw_time.u32Year = CONV_FROM_TM_YEAR(tm_in.tm_year);
hw_time.u32Month = CONV_FROM_TM_MON(tm_in.tm_mon);
hw_time.u32Day = tm_in.tm_mday;
hw_time.u32Hour = tm_in.tm_hour;
hw_time.u32Minute = tm_in.tm_min;
hw_time.u32Second = tm_in.tm_sec;
hw_time.u32TimeScale = RTC_CLOCK_24;
hw_time.u32AmPm = 0;
@@ -203,7 +203,7 @@ static rt_err_t nu_rtc_is_date_valid(const time_t t)
/* Register rt-thread device.control() entry. */
static rt_err_t nu_rtc_control(rt_device_t dev, int cmd, void *args)
{
struct tm tm_out, *tm_in;
struct tm tm_out, tm_in;
time_t *time;
S_RTC_TIME_DATA_T hw_time;
@@ -239,13 +239,13 @@ static rt_err_t nu_rtc_control(rt_device_t dev, int cmd, void *args)
if (nu_rtc_is_date_valid(*time) != RT_EOK)
return -(RT_ERROR);
tm_in = gmtime(time);
hw_time.u32Year = CONV_FROM_TM_YEAR(tm_in->tm_year);
hw_time.u32Month = CONV_FROM_TM_MON(tm_in->tm_mon);
hw_time.u32Day = tm_in->tm_mday;
hw_time.u32Hour = tm_in->tm_hour;
hw_time.u32Minute = tm_in->tm_min;
hw_time.u32Second = tm_in->tm_sec;
gmtime_r(time, &tm_in);
hw_time.u32Year = CONV_FROM_TM_YEAR(tm_in.tm_year);
hw_time.u32Month = CONV_FROM_TM_MON(tm_in.tm_mon);
hw_time.u32Day = tm_in.tm_mday;
hw_time.u32Hour = tm_in.tm_hour;
hw_time.u32Minute = tm_in.tm_min;
hw_time.u32Second = tm_in.tm_sec;
hw_time.u32TimeScale = RTC_CLOCK_24;
hw_time.u32AmPm = 0;
@@ -202,7 +202,7 @@ static rt_err_t nu_rtc_is_date_valid(const time_t t)
/* Register rt-thread device.control() entry. */
static rt_err_t nu_rtc_control(rt_device_t dev, int cmd, void *args)
{
struct tm tm_out, *tm_in;
struct tm tm_out, tm_in;
time_t *time;
S_RTC_TIME_DATA_T hw_time;
@@ -238,13 +238,13 @@ static rt_err_t nu_rtc_control(rt_device_t dev, int cmd, void *args)
if (nu_rtc_is_date_valid(*time) != RT_EOK)
return -(RT_ERROR);
tm_in = gmtime(time);
hw_time.u32Year = CONV_FROM_TM_YEAR(tm_in->tm_year);
hw_time.u32Month = CONV_FROM_TM_MON(tm_in->tm_mon);
hw_time.u32Day = tm_in->tm_mday;
hw_time.u32Hour = tm_in->tm_hour;
hw_time.u32Minute = tm_in->tm_min;
hw_time.u32Second = tm_in->tm_sec;
gmtime_r(time, &tm_in);
hw_time.u32Year = CONV_FROM_TM_YEAR(tm_in.tm_year);
hw_time.u32Month = CONV_FROM_TM_MON(tm_in.tm_mon);
hw_time.u32Day = tm_in.tm_mday;
hw_time.u32Hour = tm_in.tm_hour;
hw_time.u32Minute = tm_in.tm_min;
hw_time.u32Second = tm_in.tm_sec;
hw_time.u32TimeScale = RTC_CLOCK_24;
hw_time.u32AmPm = 0;
@@ -221,7 +221,7 @@ static rt_err_t nu_rtc_is_date_valid(const time_t t)
/* Register rt-thread device.control() entry. */
static rt_err_t nu_rtc_control(rt_device_t dev, int cmd, void *args)
{
struct tm tm_out, *tm_in;
struct tm tm_out, tm_in;
time_t *time;
S_RTC_TIME_DATA_T hw_time = {0};
@@ -261,14 +261,14 @@ static rt_err_t nu_rtc_control(rt_device_t dev, int cmd, void *args)
if (nu_rtc_is_date_valid(*time) != RT_EOK)
return -(RT_ERROR);
tm_in = gmtime(time);
hw_time.u32Year = CONV_FROM_TM_YEAR(tm_in->tm_year);
hw_time.u32cMonth = CONV_FROM_TM_MON(tm_in->tm_mon);
hw_time.u32cDay = tm_in->tm_mday;
hw_time.u32cHour = tm_in->tm_hour;
hw_time.u32cMinute = tm_in->tm_min;
hw_time.u32cSecond = tm_in->tm_sec;
hw_time.u32cDayOfWeek = tm_in->tm_wday;
gmtime_r(time, &tm_in);
hw_time.u32Year = CONV_FROM_TM_YEAR(tm_in.tm_year);
hw_time.u32cMonth = CONV_FROM_TM_MON(tm_in.tm_mon);
hw_time.u32cDay = tm_in.tm_mday;
hw_time.u32cHour = tm_in.tm_hour;
hw_time.u32cMinute = tm_in.tm_min;
hw_time.u32cSecond = tm_in.tm_sec;
hw_time.u32cDayOfWeek = tm_in.tm_wday;
hw_time.u8cClockDisplay = RTC_CLOCK_24;
hw_time.u8cAmPm = 0;
@@ -203,7 +203,7 @@ static rt_err_t nu_rtc_is_date_valid(const time_t t)
/* Register rt-thread device.control() entry. */
static rt_err_t nu_rtc_control(rt_device_t dev, int cmd, void *args)
{
struct tm tm_out, *tm_in;
struct tm tm_out, tm_in;
time_t *time;
S_RTC_TIME_DATA_T hw_time;
@@ -239,13 +239,13 @@ static rt_err_t nu_rtc_control(rt_device_t dev, int cmd, void *args)
if (nu_rtc_is_date_valid(*time) != RT_EOK)
return -(RT_ERROR);
tm_in = gmtime(time);
hw_time.u32Year = CONV_FROM_TM_YEAR(tm_in->tm_year);
hw_time.u32Month = CONV_FROM_TM_MON(tm_in->tm_mon);
hw_time.u32Day = tm_in->tm_mday;
hw_time.u32Hour = tm_in->tm_hour;
hw_time.u32Minute = tm_in->tm_min;
hw_time.u32Second = tm_in->tm_sec;
gmtime_r(time, &tm_in);
hw_time.u32Year = CONV_FROM_TM_YEAR(tm_in.tm_year);
hw_time.u32Month = CONV_FROM_TM_MON(tm_in.tm_mon);
hw_time.u32Day = tm_in.tm_mday;
hw_time.u32Hour = tm_in.tm_hour;
hw_time.u32Minute = tm_in.tm_min;
hw_time.u32Second = tm_in.tm_sec;
hw_time.u32TimeScale = RTC_CLOCK_24;
hw_time.u32AmPm = 0;
+9 -9
View File
@@ -193,16 +193,16 @@ static time_t raspi_get_timestamp(void)
static int raspi_set_timestamp(time_t timestamp)
{
struct tm *tblock;
tblock = gmtime(&timestamp);
struct tm tblock;
gmtime_r(&timestamp, &tblock);
buf[0] = 0;
buf[1] = tblock->tm_sec;
buf[2] = tblock->tm_min;
buf[3] = tblock->tm_hour;
buf[4] = tblock->tm_wday;
buf[5] = tblock->tm_mday;
buf[6] = tblock->tm_mon;
buf[7] = tblock->tm_year;
buf[1] = tblock.tm_sec;
buf[2] = tblock.tm_min;
buf[3] = tblock.tm_hour;
buf[4] = tblock.tm_wday;
buf[5] = tblock.tm_mday;
buf[6] = tblock.tm_mon;
buf[7] = tblock.tm_year;
i2c_write(buf, 8);
+9 -9
View File
@@ -40,16 +40,16 @@ static time_t raspi_get_timestamp(void)
static int raspi_set_timestamp(time_t timestamp)
{
struct tm *tblock;
tblock = gmtime(&timestamp);
struct tm tblock;
gmtime_r(&timestamp, &tblock);
buf[0] = 0;
buf[1] = tblock->tm_sec;
buf[2] = tblock->tm_min;
buf[3] = tblock->tm_hour;
buf[4] = tblock->tm_wday;
buf[5] = tblock->tm_mday;
buf[6] = tblock->tm_mon;
buf[7] = tblock->tm_year;
buf[1] = tblock.tm_sec;
buf[2] = tblock.tm_min;
buf[3] = tblock.tm_hour;
buf[4] = tblock.tm_wday;
buf[5] = tblock.tm_mday;
buf[6] = tblock.tm_mon;
buf[7] = tblock.tm_year;
bcm283x_i2c_write((PER_BASE + BCM283X_BSC0_BASE) ,buf, 8);
return RT_EOK;
}
+11 -13
View File
@@ -69,24 +69,22 @@ static rt_err_t ra_get_secs(void *args)
static rt_err_t set_rtc_time_stamp(time_t time_stamp)
{
struct tm *p_tm;
struct tm now;
rtc_time_t g_current_time = {0};
p_tm = gmtime(&time_stamp);
if (p_tm->tm_year < 100)
gmtime_r(&time_stamp, &now);
if (now.tm_year < 100)
{
return -RT_ERROR;
}
g_current_time.tm_sec = p_tm->tm_sec ;
g_current_time.tm_min = p_tm->tm_min ;
g_current_time.tm_hour = p_tm->tm_hour;
g_current_time.tm_mday = p_tm->tm_mday;
g_current_time.tm_mon = p_tm->tm_mon;
g_current_time.tm_year = p_tm->tm_year;
g_current_time.tm_wday = p_tm->tm_wday;
g_current_time.tm_yday = p_tm->tm_yday;
g_current_time.tm_sec = now.tm_sec ;
g_current_time.tm_min = now.tm_min ;
g_current_time.tm_hour = now.tm_hour;
g_current_time.tm_mday = now.tm_mday;
g_current_time.tm_mon = now.tm_mon;
g_current_time.tm_year = now.tm_year;
g_current_time.tm_wday = now.tm_wday;
g_current_time.tm_yday = now.tm_yday;
if (R_RTC_CalendarTimeSet(&g_rtc_ctrl, &g_current_time) != FSP_SUCCESS)
{
+9 -10
View File
@@ -63,17 +63,16 @@ static time_t swm_get_rtc_time_stamp(void)
static rt_err_t swm_set_rtc_time_stamp(time_t time_stamp)
{
RTC_DateTime set_datetime = {0};
struct tm *p_tm;
struct tm now;
p_tm = gmtime(&time_stamp);
set_datetime.Second = p_tm->tm_sec;
set_datetime.Minute = p_tm->tm_min;
set_datetime.Hour = p_tm->tm_hour;
set_datetime.Date = p_tm->tm_mday;
set_datetime.Month = p_tm->tm_mon;
set_datetime.Year = p_tm->tm_year;
// set_datetime.Day = p_tm->tm_wday;
gmtime_r(&time_stamp, &now);
set_datetime.Second = now.tm_sec;
set_datetime.Minute = now.tm_min;
set_datetime.Hour = now.tm_hour;
set_datetime.Date = now.tm_mday;
set_datetime.Month = now.tm_mon;
set_datetime.Year = now.tm_year;
// set_datetime.Day = now.tm_wday;
RTC_Stop(RTC);
while (RTC->CFGABLE == 0)
+13 -13
View File
@@ -50,23 +50,23 @@ static int wm_set_timestamp(time_t timestamp)
int ctrl1 = 0;
int ctrl2 = 0;
struct tm *tblock;
struct tm tblock;
tblock = gmtime(&timestamp);
gmtime_r(&timestamp, &tblock);
ctrl2 = tls_reg_read32(HR_PMU_RTC_CTRL2); /* disable */
ctrl2 &= ~(1 << 16);
tls_reg_write32(HR_PMU_RTC_CTRL2, ctrl2);
ctrl1 |= tblock->tm_sec;
ctrl1 |= tblock->tm_min << 8;
ctrl1 |= tblock->tm_hour << 16;
ctrl1 |= tblock->tm_mday << 24;
ctrl1 |= tblock.tm_sec;
ctrl1 |= tblock.tm_min << 8;
ctrl1 |= tblock.tm_hour << 16;
ctrl1 |= tblock.tm_mday << 24;
tls_reg_write32(HR_PMU_RTC_CTRL1, ctrl1);
ctrl2 = 0;
ctrl2 |= tblock->tm_mon;
ctrl2 |= tblock->tm_year << 8;
ctrl2 |= tblock.tm_mon;
ctrl2 |= tblock.tm_year << 8;
tls_reg_write32(HR_PMU_RTC_CTRL2, ctrl2);
ctrl2 = tls_reg_read32(HR_PMU_RTC_CTRL2);/* enable */
@@ -80,21 +80,21 @@ static int wm_alarm_set_timestamp(struct rt_rtc_wkalarm *wkalarm)
{
int ctrl1 = 0;
int ctrl2 = 0;
struct tm *tblock;
struct tm tblock;
time_t timestamp = 0;
timestamp = wm_get_timestamp();
tblock = gmtime(&timestamp);
gmtime_r(&timestamp, &tblock);
tls_irq_enable(PMU_RTC_INT);
ctrl1 |= wkalarm->tm_sec;
ctrl1 |= wkalarm->tm_min << 8;
ctrl1 |= wkalarm->tm_hour << 16;
ctrl1 |= tblock->tm_mday << 24;
ctrl1 |= tblock.tm_mday << 24;
ctrl2 |= tblock->tm_mon;
ctrl2 |= tblock->tm_year << 8;
ctrl2 |= tblock.tm_mon;
ctrl2 |= tblock.tm_year << 8;
tls_reg_write32(HR_PMU_RTC_CTRL2, ctrl2 | BIT(16));
+1 -12
View File
@@ -944,22 +944,11 @@ DRESULT disk_ioctl(BYTE drv, BYTE ctrl, void *buff)
DWORD get_fattime(void)
{
DWORD fat_time = 0;
time_t now;
struct tm *p_tm;
struct tm tm_now;
/* get current time */
now = time(RT_NULL);
/* lock scheduler. */
rt_enter_critical();
/* converts calendar time time into local time. */
p_tm = gmtime(&now);
/* copy the statically located variable */
rt_memcpy(&tm_now, p_tm, sizeof(struct tm));
/* unlock scheduler. */
rt_exit_critical();
gmtime_r(&now, &tm_now);
fat_time = (DWORD)(tm_now.tm_year - 80) << 25 |
(DWORD)(tm_now.tm_mon + 1) << 21 |
+5 -5
View File
@@ -126,7 +126,7 @@ static rt_size_t rtc_read(rt_device_t dev, rt_off_t pos, void* buffer, rt_size_t
static rt_err_t rtc_control(rt_device_t dev, int cmd, void *args)
{
struct tm tm, *tm_ptr;
struct tm tmp;
time_t *time;
RT_ASSERT(dev != RT_NULL);
@@ -135,14 +135,14 @@ static rt_err_t rtc_control(rt_device_t dev, int cmd, void *args)
{
case RT_DEVICE_CTRL_RTC_GET_TIME:
/* read device */
rt_hw_rtc_get(&tm);
*((rt_time_t *)args) = timegm(&tm);
rt_hw_rtc_get(&tmp);
*((rt_time_t *)args) = timegm(&tmp);
break;
case RT_DEVICE_CTRL_RTC_SET_TIME:
/* write device */
tm_ptr = gmtime(time);
rt_hw_rtc_set(tm_ptr);
gmtime_r(time, &tmp);
rt_hw_rtc_set(&tmp);
break;
}