Skip to content

Commit 11f2d5e

Browse files
tmediccixiaoxiang781216
authored andcommitted
examples/rmtchar: Implement RX and/or TX using the RMT char driver
The RMT (remote control) character driver is used to send and/or receive data packets. Eventually, this app can be used to perform a loopback test to validate the RMT driver implementation.
1 parent dcfb4d0 commit 11f2d5e

File tree

9 files changed

+1042
-0
lines changed

9 files changed

+1042
-0
lines changed

examples/rmtchar/CMakeLists.txt

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# ##############################################################################
2+
# apps/examples/rmtchar/CMakeLists.txt
3+
#
4+
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
5+
# license agreements. See the NOTICE file distributed with this work for
6+
# additional information regarding copyright ownership. The ASF licenses this
7+
# file to you under the Apache License, Version 2.0 (the "License"); you may not
8+
# use this file except in compliance with the License. You may obtain a copy of
9+
# the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16+
# License for the specific language governing permissions and limitations under
17+
# the License.
18+
#
19+
# ##############################################################################
20+
21+
if(CONFIG_EXAMPLES_RMTCHAR)
22+
nuttx_add_application(
23+
NAME
24+
rmtchar
25+
STACKSIZE
26+
${CONFIG_DEFAULT_TASK_STACKSIZE}
27+
MODULE
28+
${CONFIG_EXAMPLES_RMTCHAR}
29+
SRCS
30+
rmtchar_common.c
31+
rmtchar_main.c)
32+
if(CONFIG_EXAMPLES_RMTCHAR_TX)
33+
target_sources(apps PRIVATE rmtchar_transmitter.c)
34+
endif()
35+
if(CONFIG_EXAMPLES_RMTCHAR_RX)
36+
target_sources(apps PRIVATE rmtchar_receiver.c)
37+
endif()
38+
endif()

examples/rmtchar/Kconfig

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#
2+
# For a description of the syntax of this configuration file,
3+
# see the file kconfig-language.txt in the NuttX tools repository.
4+
#
5+
6+
config EXAMPLES_RMTCHAR
7+
tristate "RMT character driver test"
8+
default n
9+
depends on RMT
10+
---help---
11+
Enable the RMT character driver test
12+
13+
if EXAMPLES_RMTCHAR
14+
15+
config EXAMPLES_RMTCHAR_TX
16+
bool "Use RMT transmitter"
17+
default n
18+
---help---
19+
This should be set if the RMT device supports a transmitter.
20+
21+
if EXAMPLES_RMTCHAR_TX
22+
23+
config EXAMPLES_RMTCHAR_TX_DEVPATH
24+
string "RMT transmitter character device path"
25+
default "/dev/rmt0"
26+
---help---
27+
The default path to the RMT transmitter character device.
28+
Default: /dev/rmt0
29+
30+
config EXAMPLES_RMTCHAR_TXSTACKSIZE
31+
int "Transmitter thread stack size"
32+
default DEFAULT_TASK_STACKSIZE
33+
---help---
34+
This is the stack size to use when starting the transmitter thread.
35+
36+
endif # EXAMPLES_RMTCHAR_TX
37+
38+
config EXAMPLES_RMTCHAR_RX
39+
bool "Use RMT receiver"
40+
default n
41+
---help---
42+
This should be set if the RMT device supports a receiver.
43+
44+
if EXAMPLES_RMTCHAR_RX
45+
46+
config EXAMPLES_RMTCHAR_RX_DEVPATH
47+
string "RMT receiver character device path"
48+
default "/dev/rmt1"
49+
---help---
50+
The default path to the RMT receiver character device.
51+
Default: /dev/rmt1
52+
53+
config EXAMPLES_RMTCHAR_RXSTACKSIZE
54+
int "Receiver thread stack size"
55+
default DEFAULT_TASK_STACKSIZE
56+
---help---
57+
This is the stack size to use when starting the receiver thread.
58+
59+
endif # EXAMPLES_RMTCHAR_RX
60+
61+
config EXAMPLES_RMTCHAR_ITEMS
62+
int "Number of words to transmit or receive"
63+
default 64
64+
---help---
65+
This is the total amount of words to be transmitted or
66+
received by the RMT RX device.
67+
68+
endif

examples/rmtchar/Make.defs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
############################################################################
2+
# apps/examples/rmtchar/Make.defs
3+
#
4+
# Licensed to the Apache Software Foundation (ASF) under one or more
5+
# contributor license agreements. See the NOTICE file distributed with
6+
# this work for additional information regarding copyright ownership. The
7+
# ASF licenses this file to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance with the
9+
# License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16+
# License for the specific language governing permissions and limitations
17+
# under the License.
18+
#
19+
############################################################################
20+
21+
ifneq ($(CONFIG_EXAMPLES_RMTCHAR),)
22+
CONFIGURED_APPS += $(APPDIR)/examples/rmtchar
23+
endif

examples/rmtchar/Makefile

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
############################################################################
2+
# apps/examples/rmtchar/Makefile
3+
#
4+
# Licensed to the Apache Software Foundation (ASF) under one or more
5+
# contributor license agreements. See the NOTICE file distributed with
6+
# this work for additional information regarding copyright ownership. The
7+
# ASF licenses this file to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance with the
9+
# License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16+
# License for the specific language governing permissions and limitations
17+
# under the License.
18+
#
19+
############################################################################
20+
21+
include $(APPDIR)/Make.defs
22+
23+
# rmt character driver test
24+
25+
ifeq ($(CONFIG_EXAMPLES_RMTCHAR_TX),y)
26+
CSRCS += rmtchar_transmitter.c
27+
endif
28+
ifeq ($(CONFIG_EXAMPLES_RMTCHAR_RX),y)
29+
CSRCS += rmtchar_receiver.c
30+
endif
31+
CSRCS += rmtchar_common.c
32+
MAINSRC = rmtchar_main.c
33+
34+
# Touchscreen built-in application info
35+
36+
PROGNAME = rmtchar
37+
PRIORITY = SCHED_PRIORITY_DEFAULT
38+
STACKSIZE = $(CONFIG_DEFAULT_TASK_STACKSIZE)
39+
MODULE = $(CONFIG_EXAMPLES_RMTCHAR)
40+
41+
include $(APPDIR)/Application.mk

examples/rmtchar/rmtchar.h

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
/****************************************************************************
2+
* apps/examples/rmtchar/rmtchar.h
3+
*
4+
* Licensed to the Apache Software Foundation (ASF) under one or more
5+
* contributor license agreements. See the NOTICE file distributed with
6+
* this work for additional information regarding copyright ownership. The
7+
* ASF licenses this file to you under the Apache License, Version 2.0 (the
8+
* "License"); you may not use this file except in compliance with the
9+
* License. You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16+
* License for the specific language governing permissions and limitations
17+
* under the License.
18+
*
19+
****************************************************************************/
20+
21+
#ifndef __APPS_EXAMPLES_RMTCHAR_RMTCHAR_H
22+
#define __APPS_EXAMPLES_RMTCHAR_RMTCHAR_H
23+
24+
/****************************************************************************
25+
* Included Files
26+
****************************************************************************/
27+
28+
#include <nuttx/config.h>
29+
#include <pthread.h>
30+
31+
/****************************************************************************
32+
* Pre-processor Definitions
33+
****************************************************************************/
34+
35+
/* Configuration */
36+
37+
#ifndef CONFIG_EXAMPLES_RMTCHAR_TX_DEVPATH
38+
# define CONFIG_EXAMPLES_RMTCHAR_TX_DEVPATH "/dev/rmt0"
39+
#endif
40+
41+
#ifndef CONFIG_EXAMPLES_RMTCHAR_RX_DEVPATH
42+
# define CONFIG_EXAMPLES_RMTCHAR_RX_DEVPATH "/dev/rmt1"
43+
#endif
44+
45+
/****************************************************************************
46+
* Public Types
47+
****************************************************************************/
48+
49+
struct rmtchar_state_s
50+
{
51+
bool initialized;
52+
int rmtchar_items;
53+
#ifdef CONFIG_EXAMPLES_RMTCHAR_TX
54+
FAR char *txdevpath;
55+
#endif
56+
#ifdef CONFIG_EXAMPLES_RMTCHAR_RX
57+
FAR char *rxdevpath;
58+
#endif
59+
};
60+
61+
struct rmt_item32_s
62+
{
63+
union
64+
{
65+
struct
66+
{
67+
uint32_t duration0 : 15; /* Duration of level0 */
68+
uint32_t level0 : 1; /* Level of the first part */
69+
uint32_t duration1 : 15; /* Duration of level1 */
70+
uint32_t level1 : 1; /* Level of the second part */
71+
};
72+
uint32_t val; /* Equivalent unsigned value for the RMT item */
73+
};
74+
};
75+
76+
/****************************************************************************
77+
* Public Data
78+
****************************************************************************/
79+
80+
/****************************************************************************
81+
* Public Function Prototypes
82+
****************************************************************************/
83+
84+
/****************************************************************************
85+
* Name: rmtchar_transmitter()
86+
*
87+
* Description:
88+
* This is the entry point for the transmitter thread.
89+
*
90+
****************************************************************************/
91+
92+
#ifdef CONFIG_EXAMPLES_RMTCHAR_TX
93+
pthread_addr_t rmtchar_transmitter(pthread_addr_t arg);
94+
#endif
95+
96+
/****************************************************************************
97+
* Name: rmtchar_receiver()
98+
*
99+
* Description:
100+
* This is the entry point for the receiver thread.
101+
*
102+
****************************************************************************/
103+
104+
#ifdef CONFIG_EXAMPLES_RMTCHAR_RX
105+
pthread_addr_t rmtchar_receiver(pthread_addr_t arg);
106+
#endif
107+
108+
/****************************************************************************
109+
* Name: print_items
110+
*
111+
* Description:
112+
* This function prints the level and duration of RMT items stored in a
113+
* buffer. It iterates over the buffer, printing the level and duration of
114+
* each item in a formatted manner.
115+
*
116+
* Input Parameters:
117+
* buf - Pointer to the buffer containing the RMT items.
118+
* len - The number of RMT items in the buffer.
119+
*
120+
* Returned Value:
121+
* None.
122+
*
123+
****************************************************************************/
124+
125+
void print_items(struct rmt_item32_s *buf, int len);
126+
127+
#endif /* __APPS_EXAMPLES_RMTCHAR_RMTCHAR_H */

examples/rmtchar/rmtchar_common.c

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/****************************************************************************
2+
* apps/examples/rmtchar/rmtchar_common.c
3+
*
4+
* Licensed to the Apache Software Foundation (ASF) under one or more
5+
* contributor license agreements. See the NOTICE file distributed with
6+
* this work for additional information regarding copyright ownership. The
7+
* ASF licenses this file to you under the Apache License, Version 2.0 (the
8+
* "License"); you may not use this file except in compliance with the
9+
* License. You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16+
* License for the specific language governing permissions and limitations
17+
* under the License.
18+
*
19+
****************************************************************************/
20+
21+
/****************************************************************************
22+
* Included Files
23+
****************************************************************************/
24+
25+
#include <nuttx/config.h>
26+
27+
#include <sys/types.h>
28+
#include <stdio.h>
29+
#include <fcntl.h>
30+
#include <pthread.h>
31+
#include <errno.h>
32+
#include <debug.h>
33+
#include <unistd.h>
34+
35+
#include "rmtchar.h"
36+
37+
/****************************************************************************
38+
* Pre-processor Definitions
39+
****************************************************************************/
40+
41+
/****************************************************************************
42+
* Private Types
43+
****************************************************************************/
44+
45+
/****************************************************************************
46+
* Private Function Prototypes
47+
****************************************************************************/
48+
49+
/****************************************************************************
50+
* Private Data
51+
****************************************************************************/
52+
53+
/****************************************************************************
54+
* Public Data
55+
****************************************************************************/
56+
57+
/****************************************************************************
58+
* Private Functions
59+
****************************************************************************/
60+
61+
/****************************************************************************
62+
* Public Functions
63+
****************************************************************************/
64+
65+
/****************************************************************************
66+
* Name: print_items
67+
*
68+
* Description:
69+
* This function prints the level and duration of RMT items stored in a
70+
* buffer. It iterates over the buffer, printing the level and duration of
71+
* each item in a formatted manner.
72+
*
73+
* Input Parameters:
74+
* buf - Pointer to the buffer containing the RMT items.
75+
* len - The number of RMT items in the buffer.
76+
*
77+
* Returned Value:
78+
* None.
79+
*
80+
****************************************************************************/
81+
82+
void print_items(struct rmt_item32_s *buf, int len)
83+
{
84+
int i;
85+
86+
for (i = 0; i < len; i++, buf++)
87+
{
88+
printf("\t[%d]:\tL %d\tD %d\t", i, buf->level0, buf->duration0);
89+
printf("L %d\t D %d\n", buf->level1, buf->duration1);
90+
}
91+
}

0 commit comments

Comments
 (0)