Skip to content

Commit 8932a16

Browse files
committed
ft2004 bsp 增加gtimer 支持,修正can驱动初始化问题
1 parent 33a50d0 commit 8932a16

File tree

11 files changed

+229
-20
lines changed

11 files changed

+229
-20
lines changed

bsp/ft2004/.config

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ CONFIG_RT_USING_HOOK=y
2121
CONFIG_RT_USING_IDLE_HOOK=y
2222
CONFIG_RT_IDLE_HOOK_LIST_SIZE=4
2323
CONFIG_IDLE_THREAD_STACK_SIZE=4096
24+
CONFIG_SYSTEM_THREAD_STACK_SIZE=4096
2425
CONFIG_RT_USING_TIMER_SOFT=y
2526
CONFIG_RT_TIMER_THREAD_PRIO=4
2627
CONFIG_RT_TIMER_THREAD_STACK_SIZE=512
@@ -30,6 +31,7 @@ CONFIG_RT_TIMER_THREAD_STACK_SIZE=512
3031
#
3132
# CONFIG_RT_KSERVICE_USING_STDLIB is not set
3233
# CONFIG_RT_KSERVICE_USING_TINY_SIZE is not set
34+
# CONFIG_RT_USING_ASM_MEMCPY is not set
3335
CONFIG_RT_DEBUG=y
3436
CONFIG_RT_DEBUG_COLOR=y
3537
# CONFIG_RT_DEBUG_INIT_CONFIG is not set
@@ -75,6 +77,7 @@ CONFIG_RT_USING_INTERRUPT_INFO=y
7577
CONFIG_RT_USING_CONSOLE=y
7678
CONFIG_RT_CONSOLEBUF_SIZE=4096
7779
CONFIG_RT_CONSOLE_DEVICE_NAME="uart1"
80+
# CONFIG_RT_PRINTF_LONGLONG is not set
7881
CONFIG_RT_VER_NUM=0x40004
7982
CONFIG_ARCH_ARM=y
8083
CONFIG_RT_USING_CPU_FFS=y
@@ -159,6 +162,8 @@ CONFIG_RT_USING_DEVICE_IPC=y
159162
CONFIG_RT_PIPE_BUFSZ=512
160163
# CONFIG_RT_USING_SYSTEM_WORKQUEUE is not set
161164
CONFIG_RT_USING_SERIAL=y
165+
CONFIG_RT_USING_SERIAL_V1=y
166+
# CONFIG_RT_USING_SERIAL_V2 is not set
162167
CONFIG_RT_SERIAL_USING_DMA=y
163168
CONFIG_RT_SERIAL_RB_BUFSZ=256
164169
CONFIG_RT_USING_CAN=y
@@ -219,7 +224,7 @@ CONFIG_RT_USING_POSIX=y
219224
# CONFIG_RT_USING_POSIX_GETLINE is not set
220225
# CONFIG_RT_USING_POSIX_AIO is not set
221226
# CONFIG_RT_USING_MODULE is not set
222-
CONFIG_RT_LIBC_FIXED_TIMEZONE=8
227+
CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8
223228

224229
#
225230
# Network
@@ -249,6 +254,7 @@ CONFIG_NETDEV_IPV6=0
249254
CONFIG_RT_USING_LWIP=y
250255
# CONFIG_RT_USING_LWIP141 is not set
251256
# CONFIG_RT_USING_LWIP202 is not set
257+
# CONFIG_RT_USING_LWIP203 is not set
252258
CONFIG_RT_USING_LWIP212=y
253259
# CONFIG_RT_USING_LWIP_IPV6 is not set
254260
CONFIG_RT_LWIP_MEM_ALIGNMENT=4

bsp/ft2004/applications/main.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,8 @@ void demo_core(void)
6262

6363
int main(void)
6464
{
65-
int count = 1;
66-
6765
#ifdef RT_USING_SMP
6866
demo_core();
6967
#endif
70-
71-
while (count++)
72-
{
73-
rt_thread_mdelay(2000);
74-
}
75-
7668
return RT_EOK;
7769
}

bsp/ft2004/drivers/board.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,6 @@ struct mem_desc platform_mem_desc[] = {
6868

6969
const rt_uint32_t platform_mem_desc_size = sizeof(platform_mem_desc) / sizeof(platform_mem_desc[0]);
7070

71-
rt_uint32_t platform_get_gic_dist_base(void)
72-
{
73-
return FT_GICV3_DISTRIBUTOR_BASEADDRESS;
74-
}
75-
7671
static rt_uint32_t timerStep;
7772

7873
void rt_hw_timer_isr(int vector, void *parameter)

bsp/ft2004/drivers/drv_can.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ int rt_hw_can_init(void)
188188

189189
#ifdef BSP_USING_CAN1
190190
drv_can1.can_handle.Config.InstanceId = 1;
191-
drv_can0.device.config.baud_rate = 1000000;
191+
drv_can1.device.config.ticks = 20000;
192+
drv_can1.device.config.baud_rate = 1000000;
192193
rt_sem_init(&drv_can1.recv_semaphore, "can1_recv", 0, RT_IPC_FLAG_FIFO);
193194
rt_hw_can_register(&drv_can1.device,
194195
drv_can1.name,

bsp/ft2004/drivers/drv_usart.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ static void Ft_Os_Uart_Callback(void *Args, u32 Event, u32 EventData)
8585

8686
if (FUART_EVENT_RECV_DATA == Event || FUART_EVENT_RECV_TOUT == Event)
8787
{
88-
rt_hw_serial_isr(serial, RT_SERIAL_EVENT_RX_IND);
88+
if (serial->serial_rx)
89+
rt_hw_serial_isr(serial, RT_SERIAL_EVENT_RX_IND);
8990
}
9091
else if (FUART_EVENT_RECV_ERROR == Event)
9192
{

bsp/ft2004/drivers/ft2004.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,18 @@
1414

1515
#include <rthw.h>
1616
#include <rtthread.h>
17+
#include "ft_parameters.h"
1718

1819
#define ARM_GIC_NR_IRQS 160
1920
#define ARM_GIC_MAX_NR 1
2021
#define MAX_HANDLERS 160
2122
#define GIC_IRQ_START 0
22-
23+
#define GIC_ACK_INTID_MASK 0x000003ff
2324
rt_uint64_t get_main_cpu_affval(void);
2425

26+
rt_inline rt_uint32_t platform_get_gic_dist_base(void)
27+
{
28+
return FT_GICV3_DISTRIBUTOR_BASEADDRESS;
29+
}
30+
2531
#endif // !

bsp/ft2004/drivers/gtimer.c

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
/*
2+
* Copyright (c) 2006-2021, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2021-03-30 huijie.feng first version
9+
*/
10+
11+
#include "cp15.h"
12+
#include <rtdef.h>
13+
14+
/** Set CNTFRQ
15+
* This function assigns the given value to PL1 Physical Timer Counter Frequency Register (CNTFRQ).
16+
* @param value: CNTFRQ Register value to set
17+
*/
18+
static inline void __set_cntfrq(rt_uint32_t value)
19+
{
20+
__set_cp(15, 0, value, 14, 0, 0);
21+
}
22+
23+
/** Get CNTFRQ
24+
* This function returns the value of the PL1 Physical Timer Counter Frequency Register (CNTFRQ).
25+
* return CNTFRQ Register value
26+
*/
27+
static inline rt_uint32_t __get_cntfrq(void)
28+
{
29+
rt_uint32_t result;
30+
__get_cp(15, 0, result, 14, 0 , 0);
31+
return result;
32+
}
33+
34+
/** Set CNTP_TVAL
35+
* This function assigns the given value to PL1 Physical Timer Value Register (CNTP_TVAL).
36+
* param value: CNTP_TVAL Register value to set
37+
*/
38+
static inline void __set_cntp_tval(rt_uint32_t value)
39+
{
40+
__set_cp(15, 0, value, 14, 2, 0);
41+
}
42+
43+
/** Get CNTP_TVAL
44+
* This function returns the value of the PL1 Physical Timer Value Register (CNTP_TVAL).
45+
* return CNTP_TVAL Register value
46+
*/
47+
static inline rt_uint32_t __get_cntp_tval(void)
48+
{
49+
rt_uint32_t result;
50+
__get_cp(15, 0, result, 14, 2, 0);
51+
return result;
52+
}
53+
54+
/** Get CNTPCT
55+
* This function returns the value of the 64 bits PL1 Physical Count Register (CNTPCT).
56+
* return CNTPCT Register value
57+
*/
58+
static inline rt_uint64_t __get_cntpct(void)
59+
{
60+
rt_uint64_t result;
61+
__get_cp64(15, 0, result, 14);
62+
return result;
63+
}
64+
65+
/** Set CNTP_CVAL
66+
* This function assigns the given value to 64bits PL1 Physical Timer CompareValue Register (CNTP_CVAL).
67+
* param value: CNTP_CVAL Register value to set
68+
*/
69+
static inline void __set_cntp_cval(rt_uint64_t value)
70+
{
71+
__set_cp64(15, 2, value, 14);
72+
}
73+
74+
/** Get CNTP_CVAL
75+
* This function returns the value of the 64 bits PL1 Physical Timer CompareValue Register (CNTP_CVAL).
76+
* return CNTP_CVAL Register value
77+
*/
78+
static inline rt_uint64_t __get_cntp_cval(void)
79+
{
80+
rt_uint64_t result;
81+
__get_cp64(15, 2, result, 14);
82+
return result;
83+
}
84+
85+
/** Set CNTP_CTL
86+
* This function assigns the given value to PL1 Physical Timer Control Register (CNTP_CTL).
87+
* param value: CNTP_CTL Register value to set
88+
*/
89+
static inline void __set_cntp_ctl(uint32_t value)
90+
{
91+
__set_cp(15, 0, value, 14, 2, 1);
92+
}
93+
94+
/** Get CNTP_CTL register
95+
* return CNTP_CTL Register value
96+
*/
97+
static inline rt_uint32_t __get_cntp_ctl(void)
98+
{
99+
rt_uint32_t result;
100+
__get_cp(15, 0, result, 14, 2, 1);
101+
return result;
102+
}
103+
104+
/** Configures the frequency the timer shall run at.
105+
* param value The timer frequency in Hz.
106+
*/
107+
void gtimer_set_counter_frequency(rt_uint32_t value)
108+
{
109+
__set_cntfrq(value);
110+
__asm__ volatile ("isb 0xF":::"memory");
111+
}
112+
113+
/** Get the frequency the timer shall run at.
114+
* return timer frequency in Hz.
115+
*/
116+
rt_uint32_t gtimer_get_counter_frequency(void)
117+
{
118+
return(__get_cntfrq());
119+
}
120+
121+
/** Sets the reset value of the timer.
122+
* param value: The value the timer is loaded with.
123+
*/
124+
void gtimer_set_load_value(rt_uint32_t value)
125+
{
126+
__set_cntp_tval(value);
127+
__asm__ volatile ("isb 0xF":::"memory");
128+
}
129+
130+
/** Get the current counter value.
131+
* return Current counter value.
132+
*/
133+
rt_uint32_t gtimer_get_current_value(void)
134+
{
135+
return(__get_cntp_tval());
136+
}
137+
138+
/** Get the current physical counter value.
139+
* return Current physical counter value.
140+
*/
141+
rt_uint64_t gtimer_get_current_physical_value(void)
142+
{
143+
return(__get_cntpct());
144+
}
145+
146+
/** Set the physical compare value.
147+
* param value: New physical timer compare value.
148+
*/
149+
void gtimer_set_physical_compare_value(rt_uint64_t value)
150+
{
151+
__set_cntp_cval(value);
152+
__asm__ volatile ("isb 0xF":::"memory");
153+
}
154+
155+
/** Get the physical compare value.
156+
* return Physical compare value.
157+
*/
158+
rt_uint64_t gtimer_get_physical_compare_value(void)
159+
{
160+
return(__get_cntp_cval());
161+
}
162+
163+
/** Configure the timer by setting the control value.
164+
* param value: New timer control value.
165+
*/
166+
void gtimer_set_control(rt_uint32_t value)
167+
{
168+
__set_cntp_ctl(value);
169+
__asm__ volatile ("isb 0xF":::"memory");
170+
}
171+
172+
/** Get the control value.
173+
* return Control value.
174+
*/
175+
rt_uint32_t gtimer_get_control(void)
176+
{
177+
return(__get_cntp_ctl());
178+
}
179+

bsp/ft2004/drivers/gtimer.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright (c) 2006-2021, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2021-03-30 huijie.feng first version
9+
*/
10+
11+
#ifndef __GTIMER_H__
12+
#define __GTIMER_H__
13+
14+
#include <rtdef.h>
15+
16+
void gtimer_set_counter_frequency(rt_uint32_t value);
17+
rt_uint32_t gtimer_get_counter_frequency(void);
18+
void gtimer_set_load_value(rt_uint32_t value);
19+
rt_uint32_t gtimer_get_current_value(void);
20+
rt_uint64_t gtimer_get_current_physical_value(void);
21+
void gtimer_set_physical_compare_value(rt_uint64_t value);
22+
rt_uint64_t gtimer_get_physical_compare_value(void);
23+
void gtimer_set_control(rt_uint32_t value);
24+
rt_uint32_t gtimer_get_control(void);
25+
26+
#endif
27+

bsp/ft2004/drivers/secondary_cpu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* SPDX-License-Identifier: Apache-2.0.
55
*
66
* @Date: 2021-05-26 10:09:45
7-
* @LastEditTime: 2021-05-26 10:31:44
7+
* @LastEditTime: 2021-08-16 16:32:08
88
* @Description:  This files is for
99
*
1010
* @Modify History:

bsp/ft2004/rtconfig.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#define RT_USING_IDLE_HOOK
1919
#define RT_IDLE_HOOK_LIST_SIZE 4
2020
#define IDLE_THREAD_STACK_SIZE 4096
21+
#define SYSTEM_THREAD_STACK_SIZE 4096
2122
#define RT_USING_TIMER_SOFT
2223
#define RT_TIMER_THREAD_PRIO 4
2324
#define RT_TIMER_THREAD_STACK_SIZE 512
@@ -107,6 +108,7 @@
107108
#define RT_USING_DEVICE_IPC
108109
#define RT_PIPE_BUFSZ 512
109110
#define RT_USING_SERIAL
111+
#define RT_USING_SERIAL_V1
110112
#define RT_SERIAL_USING_DMA
111113
#define RT_SERIAL_RB_BUFSZ 256
112114
#define RT_USING_CAN
@@ -131,7 +133,7 @@
131133

132134
#define RT_USING_LIBC
133135
#define RT_USING_POSIX
134-
#define RT_LIBC_FIXED_TIMEZONE 8
136+
#define RT_LIBC_DEFAULT_TIMEZONE 8
135137

136138
/* Network */
137139

0 commit comments

Comments
 (0)