Skip to content

Commit 33ab629

Browse files
committed
Merge branch 'master' of https://github.com/RT-Thread/rt-thread
2 parents 79fafcc + f4a92e5 commit 33ab629

File tree

51 files changed

+4472
-549
lines changed

Some content is hidden

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

51 files changed

+4472
-549
lines changed

components/drivers/core/device.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
* 2013-07-09 Grissiom add ref_count support
1414
* 2016-04-02 Bernard fix the open_flag initialization issue.
1515
* 2021-03-19 Meco Man remove rt_device_init_all()
16+
* 2024-09-15 milo fix log format issue
17+
* fix reopen with a different oflag issue
1618
*/
1719

1820
#include <rtthread.h>
@@ -195,8 +197,8 @@ rt_err_t rt_device_init(rt_device_t dev)
195197
result = device_init(dev);
196198
if (result != RT_EOK)
197199
{
198-
LOG_E("To initialize device:%s failed. The error code is %d",
199-
dev->parent.name, result);
200+
LOG_E("To initialize device:%.*s failed. The error code is %d",
201+
RT_NAME_MAX, dev->parent.name, result);
200202
}
201203
else
202204
{
@@ -233,8 +235,8 @@ rt_err_t rt_device_open(rt_device_t dev, rt_uint16_t oflag)
233235
result = device_init(dev);
234236
if (result != RT_EOK)
235237
{
236-
LOG_E("To initialize device:%s failed. The error code is %d",
237-
dev->parent.name, result);
238+
LOG_E("To initialize device:%.*s failed. The error code is %d",
239+
RT_NAME_MAX, dev->parent.name, result);
238240

239241
return result;
240242
}
@@ -252,7 +254,7 @@ rt_err_t rt_device_open(rt_device_t dev, rt_uint16_t oflag)
252254

253255
/* device is not opened or opened by other oflag, call device_open interface */
254256
if (!(dev->open_flag & RT_DEVICE_OFLAG_OPEN) ||
255-
((dev->open_flag & RT_DEVICE_OFLAG_MASK) != (oflag & RT_DEVICE_OFLAG_MASK)))
257+
((dev->open_flag & RT_DEVICE_OFLAG_MASK) != ((oflag & RT_DEVICE_OFLAG_MASK) | RT_DEVICE_OFLAG_OPEN)))
256258
{
257259
if (device_open != RT_NULL)
258260
{

components/drivers/include/drivers/adc.h

Lines changed: 97 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,75 @@
1414
#define __ADC_H__
1515

1616
#include <rtthread.h>
17+
/**
18+
* @addtogroup Drivers RTTHREAD Driver
19+
* @defgroup ADC ADC
20+
*
21+
* @brief ADC driver api
22+
*
23+
* <b>Example</b>
24+
* @code {.c}
25+
* #define ADC_DEV_NAME "adc1"
26+
* #define ADC_DEV_CHANNEL 5
27+
* #define REFER_VOLTAGE 330
28+
* #define CONVERT_BITS (1 << 12)
29+
*
30+
* static int adc_vol_sample(int argc, char *argv[])
31+
* {
32+
* rt_adc_device_t adc_dev;
33+
* rt_uint32_t value, vol;
34+
*
35+
* rt_err_t ret = RT_EOK;
36+
*
37+
* adc_dev = (rt_adc_device_t)rt_device_find(ADC_DEV_NAME);
38+
* if (adc_dev == RT_NULL)
39+
* {
40+
* rt_kprintf("adc sample run failed! can't find %s device!\n", ADC_DEV_NAME);
41+
* return RT_ERROR;
42+
* }
43+
*
44+
* ret = rt_adc_enable(adc_dev, ADC_DEV_CHANNEL);
45+
*
46+
* value = rt_adc_read(adc_dev, ADC_DEV_CHANNEL);
47+
* rt_kprintf("the value is :%d \n", value);
48+
*
49+
* vol = value * REFER_VOLTAGE / CONVERT_BITS;
50+
* rt_kprintf("the voltage is :%d.%02d \n", vol / 100, vol % 100);
51+
*
52+
* ret = rt_adc_disable(adc_dev, ADC_DEV_CHANNEL);
53+
*
54+
* return ret;
55+
* }
56+
* MSH_CMD_EXPORT(adc_vol_sample, adc voltage convert sample);
57+
*
58+
* @endcode
59+
*
60+
* @ingroup Drivers
61+
*/
62+
1763

64+
/*!
65+
* @addtogroup ADC
66+
* @{
67+
*/
1868
#define RT_ADC_INTERN_CH_TEMPER (-1)
1969
#define RT_ADC_INTERN_CH_VREF (-2)
2070
#define RT_ADC_INTERN_CH_VBAT (-3)
2171

2272
struct rt_adc_device;
73+
/**
74+
* @brief Configure the adc device
75+
*/
2376
struct rt_adc_ops
2477
{
2578
rt_err_t (*enabled)(struct rt_adc_device *device, rt_int8_t channel, rt_bool_t enabled);
2679
rt_err_t (*convert)(struct rt_adc_device *device, rt_int8_t channel, rt_uint32_t *value);
2780
rt_uint8_t (*get_resolution)(struct rt_adc_device *device);
2881
rt_int16_t (*get_vref) (struct rt_adc_device *device);
2982
};
30-
83+
/**
84+
* @brief adc device
85+
*/
3186
struct rt_adc_device
3287
{
3388
struct rt_device parent;
@@ -43,10 +98,51 @@ typedef enum
4398
RT_ADC_CMD_GET_VREF = RT_DEVICE_CTRL_BASE(ADC) + 4, /* get reference voltage */
4499
} rt_adc_cmd_t;
45100

101+
/**
102+
* @brief register the adc device
103+
* @param adc adc device
104+
* @param name device name
105+
* @param ops device ops
106+
* @param user_data device private data
107+
* @return rt_err_t error code
108+
* @ingroup ADC
109+
*/
46110
rt_err_t rt_hw_adc_register(rt_adc_device_t adc,const char *name, const struct rt_adc_ops *ops, const void *user_data);
111+
112+
/**
113+
* @brief read the adc value
114+
* @param dev adc device
115+
* @param channel adc channel
116+
* @return rt_uint32_t adc value
117+
* @ingroup ADC
118+
*/
47119
rt_uint32_t rt_adc_read(rt_adc_device_t dev, rt_int8_t channel);
120+
121+
/**
122+
* @brief enable the adc channel
123+
* @param dev adc device
124+
* @param channel adc channel
125+
* @return rt_err_t error code
126+
* @ingroup ADC
127+
*/
48128
rt_err_t rt_adc_enable(rt_adc_device_t dev, rt_int8_t channel);
129+
130+
/**
131+
* @brief disable the adc channel
132+
* @param dev adc device
133+
* @param channel adc channel
134+
* @return rt_err_t error code
135+
* @ingroup ADC
136+
*/
49137
rt_err_t rt_adc_disable(rt_adc_device_t dev, rt_int8_t channel);
138+
139+
/**
140+
* @brief get the adc resolution
141+
* @param dev adc device
142+
* @param channel adc channel
143+
* @return rt_int16_t adc resolution
144+
* @ingroup ADC
145+
*/
50146
rt_int16_t rt_adc_voltage(rt_adc_device_t dev, rt_int8_t channel);
51147

52148
#endif /* __ADC_H__ */

components/drivers/include/drivers/pic.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ void rt_pic_default_name(struct rt_pic *pic);
148148
struct rt_pic *rt_pic_dynamic_cast(void *ptr);
149149

150150
rt_err_t rt_pic_linear_irq(struct rt_pic *pic, rt_size_t irq_nr);
151+
rt_err_t rt_pic_cancel_irq(struct rt_pic *pic);
151152

152153
int rt_pic_config_ipi(struct rt_pic *pic, int ipi_index, int hwirq);
153154
int rt_pic_config_irq(struct rt_pic *pic, int irq_index, int hwirq);

components/drivers/ofw/fdt.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,15 @@ rt_uint64_t rt_fdt_translate_address(void *fdt, int nodeoffset, rt_uint64_t addr
8585

8686
if (parent >= 0)
8787
{
88-
ranges = fdt_getprop(fdt, nodeoffset, "ranges", &length);
88+
ranges = fdt_getprop(fdt, parent, "ranges", &length);
8989
}
9090

9191
if (ranges && length > 0)
9292
{
93-
local.addr_cells = fdt_address_cells(fdt, nodeoffset);
94-
local.size_cells = fdt_size_cells(fdt, nodeoffset);
95-
cpu.addr_cells = fdt_io_addr_cells(fdt, nodeoffset);
96-
cpu.size_cells = fdt_io_size_cells(fdt, nodeoffset);
93+
local.addr_cells = fdt_address_cells(fdt, parent);
94+
local.size_cells = fdt_size_cells(fdt, parent);
95+
cpu.addr_cells = fdt_io_addr_cells(fdt, parent);
96+
cpu.size_cells = fdt_io_size_cells(fdt, parent);
9797

9898
group_len = local.addr_cells + cpu.addr_cells + local.size_cells;
9999

@@ -105,7 +105,7 @@ rt_uint64_t rt_fdt_translate_address(void *fdt, int nodeoffset, rt_uint64_t addr
105105

106106
if (local.addr <= address && local.addr + local.size > address)
107107
{
108-
ret += address - cpu.addr;
108+
ret = address - local.addr + cpu.addr;
109109
break;
110110
}
111111

@@ -247,9 +247,9 @@ static rt_err_t fdt_reserved_memory_reg(int nodeoffset, const char *uname)
247247

248248
rt_bool_t is_nomap = fdt_getprop(_fdt, nodeoffset, "no-map", RT_NULL) ? RT_TRUE : RT_FALSE;
249249
base = rt_fdt_translate_address(_fdt, nodeoffset, base);
250-
rt_memblock_reserve_memory(uname, base, base + size, is_nomap);
251250

252-
len -= t_len;
251+
rt_memblock_reserve_memory(fdt_get_name(_fdt, nodeoffset, RT_NULL),
252+
base, base + size, is_nomap);
253253
}
254254
}
255255
}

components/drivers/pic/Kconfig

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
menuconfig RT_USING_PIC
22
bool "Using Programmable Interrupt Controller (PIC)"
3-
select RT_USING_BITMAP
3+
select RT_USING_ADT
4+
select RT_USING_ADT_BITMAP
45
depends on RT_USING_DM
56
default n
67

@@ -22,12 +23,31 @@ config RT_PIC_ARM_GIC
2223
select RT_USING_OFW
2324
default n
2425

26+
config RT_PIC_ARM_GIC_V2M
27+
bool "ARM GIC V2M" if RT_PIC_ARM_GIC && RT_PCI_MSI
28+
depends on RT_USING_OFW
29+
default n
30+
2531
config RT_PIC_ARM_GIC_V3
2632
bool "ARM GICv3"
2733
depends on RT_USING_PIC
2834
select RT_USING_OFW
2935
default n
3036

37+
config RT_PIC_ARM_GIC_V3_ITS
38+
bool "ARM GICv3 ITS (Interrupt Translation Service)" if RT_PIC_ARM_GIC_V3 && RT_PCI_MSI
39+
depends on RT_USING_OFW
40+
select RT_USING_ADT_REF
41+
default n
42+
43+
config RT_PIC_ARM_GIC_V3_ITS_IRQ_MAX
44+
int "IRQ maximum used"
45+
depends on RT_PIC_ARM_GIC_V3_ITS
46+
default 127 if ARCH_CPU_64BIT
47+
default 63
48+
help
49+
Recommended to be based on the bit length (full bits) of maximum usage.
50+
3151
config RT_PIC_ARM_GIC_MAX_NR
3252
int
3353
depends on RT_USING_PIC

components/drivers/pic/SConscript

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,15 @@ if GetDepend(['RT_PIC_ARM_GIC']) or GetDepend(['RT_PIC_ARM_GIC_V3']):
1616
if GetDepend(['RT_PIC_ARM_GIC']):
1717
src += ['pic-gicv2.c']
1818

19+
if GetDepend(['RT_PIC_ARM_GIC_V2M']):
20+
src += ['pic-gicv2m.c']
21+
1922
if GetDepend(['RT_PIC_ARM_GIC_V3']):
2023
src += ['pic-gicv3.c']
2124

25+
if GetDepend(['RT_PIC_ARM_GIC_V3_ITS']):
26+
src += ['pic-gicv3-its.c']
27+
2228
group = DefineGroup('DeviceDrivers', src, depend = [''], CPPPATH = CPPPATH)
2329

2430
Return('group')

components/drivers/pic/pic-gic-common.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@
88
* 2023-01-30 GuEe-GUI first version
99
*/
1010

11-
#ifndef __IRQ_GIC_COMMON_H__
12-
#define __IRQ_GIC_COMMON_H__
11+
#ifndef __PIC_GIC_COMMON_H__
12+
#define __PIC_GIC_COMMON_H__
1313

1414
#include <rtdef.h>
15+
16+
#ifdef RT_PCI_MSI
17+
#include <drivers/pci_msi.h>
18+
#endif
1519
#include <drivers/ofw.h>
1620

1721
#define GIC_SGI_NR 16
@@ -52,4 +56,4 @@ rt_err_t gicv2m_ofw_probe(struct rt_ofw_node *ic_np, const struct rt_ofw_node_id
5256
rt_err_t gicv3_its_ofw_probe(struct rt_ofw_node *ic_np, const struct rt_ofw_node_id *id);
5357
#endif
5458

55-
#endif /* __IRQ_GIC_COMMON_H__ */
59+
#endif /* __PIC_GIC_COMMON_H__ */

components/drivers/pic/pic-gicv2.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ static void gicv2_cpu_init(struct gicv2 *gic)
128128

129129
#ifdef ARCH_SUPPORT_HYP
130130
_gicv2_eoi_mode_ns = RT_TRUE;
131+
#else
132+
_gicv2_eoi_mode_ns = !!rt_ofw_bootargs_select("pic.gicv2_eoimode", 0);
131133
#endif
132134

133135
if (_gicv2_eoi_mode_ns)

0 commit comments

Comments
 (0)