Skip to content

Commit 479d206

Browse files
jlaitinejerpelea
authored andcommitted
system/cdcacm: Support sercon and serdis in CONFIG_BUILD_KERNEL
- Put sercon and serdis in separate source files, so that the main functions can be compiled in also in kernel build. - Don't store the ttyacm handle in the application, it is stored in kernel side in case of the system_cdcacm Signed-off-by: Jukka Laitinen <[email protected]>
1 parent 10cab6b commit 479d206

File tree

5 files changed

+87
-85
lines changed

5 files changed

+87
-85
lines changed

system/cdcacm/CMakeLists.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
# ##############################################################################
2222

2323
if(CONFIG_SYSTEM_CDCACM)
24-
nuttx_add_application(NAME sercon SRCS cdcacm_main.c)
25-
26-
nuttx_add_application(NAME serdis)
24+
nuttx_add_application(NAME sercon SRCS sercon_main.c)
25+
nuttx_add_application(NAME serdis SRCS serdis_main.c)
2726
endif()

system/cdcacm/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ include $(APPDIR)/Make.defs
2424

2525
# USB CDC/ACM serial mass storage add-on
2626

27-
MAINSRC = cdcacm_main.c
27+
MAINSRC = sercon_main.c serdis_main.c
2828

2929
PROGNAME = sercon serdis
3030
PRIORITY = SCHED_PRIORITY_DEFAULT

system/cdcacm/cdcacm.h

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -93,24 +93,6 @@
9393
#define TRACE_BITSET (TRACE_INIT_BITS|TRACE_ERROR_BITS|TRACE_CLASS_BITS|\
9494
TRACE_TRANSFER_BITS|TRACE_CONTROLLER_BITS|TRACE_INTERRUPT_BITS)
9595

96-
/****************************************************************************
97-
* Public Types
98-
****************************************************************************/
99-
100-
/* All global variables used by this add-on are packed into a structure in
101-
* order to avoid name collisions.
102-
*/
103-
104-
struct cdcacm_state_s
105-
{
106-
/* This is the handle that references to this particular USB CDC/ACM driver
107-
* instance. The value of the driver handle must be remembered between the
108-
* 'sercon' and 'msdis' commands.
109-
*/
110-
111-
FAR void *handle;
112-
};
113-
11496
/****************************************************************************
11597
* Public Data
11698
****************************************************************************/
Lines changed: 2 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/****************************************************************************
2-
* apps/system/cdcacm/cdcacm_main.c
2+
* apps/system/cdcacm/sercon_main.c
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*
@@ -37,16 +37,6 @@
3737

3838
#include "cdcacm.h"
3939

40-
/****************************************************************************
41-
* Private Data
42-
****************************************************************************/
43-
44-
/* All global variables used by this add-on are packed into a structure in
45-
* order to avoid name collisions.
46-
*/
47-
48-
static struct cdcacm_state_s g_cdcacm;
49-
5040
/****************************************************************************
5141
* Public Functions
5242
****************************************************************************/
@@ -64,16 +54,6 @@ int main(int argc, FAR char *argv[])
6454
struct boardioc_usbdev_ctrl_s ctrl;
6555
int ret;
6656

67-
/* Check if there is a non-NULL USB mass storage device handle
68-
* (meaning that the USB mass storage device is already configured).
69-
*/
70-
71-
if (g_cdcacm.handle)
72-
{
73-
printf("sercon:: ERROR: Already connected\n");
74-
return EXIT_FAILURE;
75-
}
76-
7757
/* Then, in any event, enable trace data collection as configured BEFORE
7858
* enabling the CDC/ACM device.
7959
*/
@@ -87,7 +67,7 @@ int main(int argc, FAR char *argv[])
8767
ctrl.usbdev = BOARDIOC_USBDEV_CDCACM;
8868
ctrl.action = BOARDIOC_USBDEV_CONNECT;
8969
ctrl.instance = CONFIG_SYSTEM_CDCACM_DEVMINOR;
90-
ctrl.handle = &g_cdcacm.handle;
70+
ctrl.handle = NULL;
9171

9272
ret = boardctl(BOARDIOC_USBDEV_CONTROL, (uintptr_t)&ctrl);
9373
if (ret < 0)
@@ -100,44 +80,3 @@ int main(int argc, FAR char *argv[])
10080
printf("sercon: Successfully registered the CDC/ACM serial driver\n");
10181
return EXIT_SUCCESS;
10282
}
103-
104-
/****************************************************************************
105-
* serdis_main
106-
*
107-
* Description:
108-
* This is a program entry point that will disconnect the CDC/ACM serial
109-
* device.
110-
****************************************************************************/
111-
112-
int serdis_main(int argc, char *argv[])
113-
{
114-
struct boardioc_usbdev_ctrl_s ctrl;
115-
116-
/* First check if the USB mass storage device is already connected */
117-
118-
if (!g_cdcacm.handle)
119-
{
120-
printf("serdis: ERROR: Not connected\n");
121-
return EXIT_FAILURE;
122-
}
123-
124-
/* Then, in any event, disable trace data collection as configured BEFORE
125-
* enabling the CDC/ACM device.
126-
*/
127-
128-
usbtrace_enable(0);
129-
130-
/* Then disconnect the device and uninitialize the USB mass storage
131-
* driver
132-
*/
133-
134-
ctrl.usbdev = BOARDIOC_USBDEV_CDCACM;
135-
ctrl.action = BOARDIOC_USBDEV_DISCONNECT;
136-
ctrl.instance = CONFIG_SYSTEM_CDCACM_DEVMINOR;
137-
ctrl.handle = &g_cdcacm.handle;
138-
139-
boardctl(BOARDIOC_USBDEV_CONTROL, (uintptr_t)&ctrl);
140-
g_cdcacm.handle = NULL;
141-
printf("serdis: Disconnected\n");
142-
return EXIT_SUCCESS;
143-
}

system/cdcacm/serdis_main.c

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/****************************************************************************
2+
* apps/system/cdcacm/serdis_main.c
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Licensed to the Apache Software Foundation (ASF) under one or more
7+
* contributor license agreements. See the NOTICE file distributed with
8+
* this work for additional information regarding copyright ownership. The
9+
* ASF licenses this file to you under the Apache License, Version 2.0 (the
10+
* "License"); you may not use this file except in compliance with the
11+
* License. You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18+
* License for the specific language governing permissions and limitations
19+
* under the License.
20+
*
21+
****************************************************************************/
22+
23+
/****************************************************************************
24+
* Included Files
25+
****************************************************************************/
26+
27+
#include <nuttx/config.h>
28+
29+
#include <sys/types.h>
30+
#include <sys/boardctl.h>
31+
32+
#include <stdio.h>
33+
#include <debug.h>
34+
35+
#include <nuttx/usb/usbdev.h>
36+
#include <nuttx/usb/cdcacm.h>
37+
38+
#include "cdcacm.h"
39+
40+
/****************************************************************************
41+
* Public Functions
42+
****************************************************************************/
43+
44+
/****************************************************************************
45+
* serdis_main
46+
*
47+
* Description:
48+
* This is a program entry point that will disconnect the CDC/ACM serial
49+
* device.
50+
****************************************************************************/
51+
52+
int main(int argc, char *argv[])
53+
{
54+
struct boardioc_usbdev_ctrl_s ctrl;
55+
int ret;
56+
57+
/* Disable trace data collection as configured before disabling the
58+
* CDC/ACM device.
59+
*/
60+
61+
usbtrace_enable(0);
62+
63+
/* Then disconnect the device and uninitialize the USB mass storage
64+
* driver
65+
*/
66+
67+
ctrl.usbdev = BOARDIOC_USBDEV_CDCACM;
68+
ctrl.action = BOARDIOC_USBDEV_DISCONNECT;
69+
ctrl.instance = CONFIG_SYSTEM_CDCACM_DEVMINOR;
70+
ctrl.handle = NULL;
71+
72+
ret = boardctl(BOARDIOC_USBDEV_CONTROL, (uintptr_t)&ctrl);
73+
if (ret < 0)
74+
{
75+
printf("serdis: ERROR: "
76+
"Failed to disconnect the CDC/ACM serial device: %d\n", -ret);
77+
return EXIT_FAILURE;
78+
}
79+
80+
printf("serdis: Disconnected\n");
81+
return EXIT_SUCCESS;
82+
}

0 commit comments

Comments
 (0)