Skip to content

Commit 77f0814

Browse files
committed
Merge branch 'master' of https://github.com/RT-Thread/rt-thread into fix_bug_of_dataqueue
2 parents 967cc96 + e3d1ed4 commit 77f0814

File tree

305 files changed

+38620
-1651
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

305 files changed

+38620
-1651
lines changed

bsp/ls2kdev/drivers/board.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,36 @@
1616
#include "exception.h"
1717
#include "drv_uart.h"
1818
#include "board.h"
19+
#include "ls2k1000.h"
20+
1921
/**
2022
* this function will reset CPU
2123
*
2224
*/
2325
void rt_hw_cpu_reset(void)
2426
{
27+
WDT_EN = 0x01;
28+
WDT_TIMER = 0x01;
29+
WDT_SET = 0x01;
2530
rt_kprintf("reboot system...\n");
2631
while (1);
2732
}
33+
MSH_CMD_EXPORT_ALIAS(rt_hw_cpu_reset, reboot, reset cpu);
34+
2835

2936
/**
3037
* this function will shutdown CPU
3138
*
3239
*/
3340
void rt_hw_cpu_shutdown(void)
3441
{
42+
PM1_STS &= 0xffffffff;
43+
PM1_CNT = 0x3c00;
3544
rt_kprintf("shutdown...\n");
3645

3746
while (1);
3847
}
48+
MSH_CMD_EXPORT_ALIAS(rt_hw_cpu_shutdown, poweroff, shutdown cpu);
3949

4050

4151
/**

bsp/ls2kdev/drivers/ls2k1000.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <mips.h>
55
#include "interrupt.h"
6+
#include <rthw.h>
67

78
#define APB_BASE CKSEG1ADDR(0xbfe00000)
89

@@ -24,6 +25,28 @@
2425

2526
#define GEN_CONFIG0_REG (0xFFFFFFFFBfe10420)
2627

28+
29+
/*
30+
* General PM Configuration Register
31+
*/
32+
#define PMCON_BASE (APB_BASE | (0x7 << 12))
33+
34+
/*
35+
* Power Management1 Configuration Registers
36+
*/
37+
#define PM1_BASE (PMCON_BASE + 0x0C)
38+
#define PM1_STS HWREG32(PM1_BASE)
39+
#define PM1_EN HWREG32(PM1_BASE + 0x04)
40+
#define PM1_CNT HWREG32(PM1_BASE + 0x08)
41+
42+
/*
43+
* Watch Dog Configuration Registers
44+
*/
45+
#define WDT_BASE (PMCON_BASE + 0x30)
46+
#define WDT_EN HWREG32(WDT_BASE)
47+
#define WDT_SET HWREG32(WDT_BASE + 0x04)
48+
#define WDT_TIMER HWREG32(WDT_BASE + 0x08)
49+
2750
void rt_hw_timer_handler(void);
2851
void rt_hw_uart_init(void);
2952

bsp/nrf5x/libraries/drivers/SConscript

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ if GetDepend(['BSP_USING_PWM']):
3232
if GetDepend(['BSP_USING_WDT']):
3333
src += ['drv_wdt.c']
3434

35+
if GetDepend(['BSP_USING_ONCHIP_RTC']):
36+
src += ['drv_rtc.c']
37+
3538
path = [cwd]
3639

3740
group = DefineGroup('Drivers', src, depend = [''], CPPPATH = path)
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
/*
2+
* Copyright (c) 2006-2018, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2020-09-08 Chenyingchun first version
9+
*/
10+
11+
#include "board.h"
12+
#include <rtthread.h>
13+
#include <rtdevice.h>
14+
15+
#include <nrfx_rtc.h>
16+
#include <nrfx_clock.h>
17+
18+
#ifdef BSP_USING_ONCHIP_RTC
19+
20+
#define LOG_TAG "drv.rtc"
21+
#define DBG_LVL DBG_LOG
22+
#include <rtdbg.h>
23+
24+
/* 2018-01-30 14:44:50 = RTC_TIME_INIT(2018, 1, 30, 14, 44, 50) */
25+
#define RTC_TIME_INIT(year, month, day, hour, minute, second) \
26+
{.tm_year = year - 1900, .tm_mon = month - 1, .tm_mday = day, .tm_hour = hour, .tm_min = minute, .tm_sec = second}
27+
28+
#ifndef ONCHIP_RTC_TIME_DEFAULT
29+
#define ONCHIP_RTC_TIME_DEFAULT RTC_TIME_INIT(2018, 1, 1, 0, 0 ,0)
30+
#endif
31+
32+
#ifndef RTC_INSTANCE_ID
33+
#define RTC_INSTANCE_ID (2)
34+
#endif
35+
36+
#define TICK_FREQUENCE_HZ (RT_TICK_PER_SECOND) // RTC tick frequence, in HZ
37+
38+
static struct rt_device rtc;
39+
static time_t init_time;
40+
static uint32_t tick = 0;
41+
42+
static void rtc_callback(nrfx_rtc_int_type_t int_type)
43+
{
44+
static uint32_t count = 0;
45+
46+
if (int_type == NRFX_RTC_INT_TICK)
47+
{
48+
count++;
49+
if((count % TICK_FREQUENCE_HZ) == 0)
50+
{
51+
tick++;
52+
}
53+
}
54+
}
55+
56+
static rt_err_t rt_rtc_config(struct rt_device *dev)
57+
{
58+
#define SYSTICK_CLOCK_HZ (32768UL)
59+
#define RTC_PRESCALER ((uint32_t) (NRFX_ROUNDED_DIV(SYSTICK_CLOCK_HZ, TICK_FREQUENCE_HZ) - 1))
60+
61+
const nrfx_rtc_t rtc_instance = NRFX_RTC_INSTANCE(RTC_INSTANCE_ID);
62+
nrf_clock_lf_src_set(NRF_CLOCK, (nrf_clock_lfclk_t)NRFX_CLOCK_CONFIG_LF_SRC);
63+
nrfx_clock_lfclk_start();
64+
65+
//Initialize RTC instance
66+
nrfx_rtc_config_t config = NRFX_RTC_DEFAULT_CONFIG;
67+
config.prescaler = RTC_PRESCALER;
68+
69+
nrfx_rtc_init(&rtc_instance, &config, rtc_callback);
70+
71+
nrfx_rtc_tick_enable(&rtc_instance, true);
72+
73+
//Power on RTC instance
74+
nrfx_rtc_enable(&rtc_instance);
75+
76+
return RT_EOK;
77+
}
78+
79+
static rt_err_t rt_rtc_control(rt_device_t dev, int cmd, void *args)
80+
{
81+
time_t *time;
82+
RT_ASSERT(dev != RT_NULL);
83+
84+
switch (cmd)
85+
{
86+
case RT_DEVICE_CTRL_RTC_GET_TIME:
87+
{
88+
time = (time_t *) args;
89+
*time = init_time + tick;
90+
break;
91+
}
92+
case RT_DEVICE_CTRL_RTC_SET_TIME:
93+
{
94+
time = (time_t *) args;
95+
init_time = *time - tick;
96+
break;
97+
}
98+
}
99+
return RT_EOK;
100+
}
101+
102+
103+
#ifdef RT_USING_DEVICE_OPS
104+
const static struct rt_device_ops rtc_ops =
105+
{
106+
RT_NULL,
107+
RT_NULL,
108+
RT_NULL,
109+
RT_NULL,
110+
RT_NULL,
111+
rt_rtc_control
112+
};
113+
#endif
114+
115+
static rt_err_t rt_hw_rtc_register(rt_device_t device, const char *name, rt_uint32_t flag)
116+
{
117+
struct tm time_new = ONCHIP_RTC_TIME_DEFAULT;
118+
119+
RT_ASSERT(device != RT_NULL);
120+
121+
init_time = mktime(&time_new);
122+
if (rt_rtc_config(device) != RT_EOK)
123+
{
124+
return -RT_ERROR;
125+
}
126+
#ifdef RT_USING_DEVICE_OPS
127+
device->ops = &rtc_ops;
128+
#else
129+
device->init = RT_NULL;
130+
device->open = RT_NULL;
131+
device->close = RT_NULL;
132+
device->read = RT_NULL;
133+
device->write = RT_NULL;
134+
device->control = rt_rtc_control;
135+
#endif
136+
device->type = RT_Device_Class_RTC;
137+
device->rx_indicate = RT_NULL;
138+
device->tx_complete = RT_NULL;
139+
device->user_data = RT_NULL;
140+
141+
/* register a character device */
142+
rt_device_register(device, name, flag);
143+
144+
return RT_EOK;
145+
}
146+
147+
int rt_hw_rtc_init(void)
148+
{
149+
rt_err_t result;
150+
result = rt_hw_rtc_register(&rtc, "rtc", RT_DEVICE_FLAG_RDWR);
151+
if (result != RT_EOK)
152+
{
153+
LOG_E("rtc register err code: %d", result);
154+
return result;
155+
}
156+
LOG_D("rtc init success");
157+
return RT_EOK;
158+
}
159+
INIT_DEVICE_EXPORT(rt_hw_rtc_init);
160+
161+
#endif /* BSP_USING_ONCHIP_RTC */
162+

bsp/nrf5x/nrf52832/board/Kconfig

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,39 @@ endif
313313
int
314314
default 1
315315
endif
316+
317+
menuconfig BSP_USING_ONCHIP_RTC
318+
bool "Enable RTC"
319+
select RT_USING_RTC
320+
select RT_USING_LIBC
321+
default n
322+
if BSP_USING_ONCHIP_RTC
323+
config NRFX_CLOCK_ENABLED
324+
int
325+
default 1
326+
config NRFX_CLOCK_DEFAULT_CONFIG_IRQ_PRIORITY
327+
int
328+
default 7
329+
config NRFX_RTC_ENABLED
330+
int
331+
default 1
332+
config NRFX_RTC0_ENABLED
333+
int
334+
default 1
335+
config NRFX_RTC1_ENABLED
336+
int
337+
default 1
338+
config NRFX_RTC2_ENABLED
339+
int
340+
default 1
341+
config RTC_INSTANCE_ID
342+
int
343+
default 2
344+
config RTC_INSTANCE_ID
345+
int "select RTC instance id, must be 0, 1, 2"
346+
range 0 2
347+
default 2
348+
endif
316349
endmenu
317350

318351
endmenu

bsp/nrf5x/nrf52840/board/Kconfig

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,41 @@ menu "On-chip Peripheral Drivers"
346346
int
347347
default 1
348348
endif
349-
endmenu
350349

350+
menuconfig BSP_USING_ONCHIP_RTC
351+
bool "Enable RTC"
352+
select RT_USING_RTC
353+
select RT_USING_LIBC
354+
default n
355+
if BSP_USING_ONCHIP_RTC
356+
config NRFX_CLOCK_ENABLED
357+
int
358+
default 1
359+
config NRFX_CLOCK_DEFAULT_CONFIG_IRQ_PRIORITY
360+
int
361+
default 7
362+
config NRFX_RTC_ENABLED
363+
int
364+
default 1
365+
config NRFX_RTC0_ENABLED
366+
int
367+
default 1
368+
config NRFX_RTC1_ENABLED
369+
int
370+
default 1
371+
config NRFX_RTC2_ENABLED
372+
int
373+
default 1
374+
config RTC_INSTANCE_ID
375+
int
376+
default 2
377+
config RTC_INSTANCE_ID
378+
int "select RTC instance id, must be 0, 1, 2"
379+
range 0 2
380+
default 2
381+
endif
382+
383+
endmenu
351384

352385
choice
353386
prompt "BLE STACK"

0 commit comments

Comments
 (0)