1 | /* |
---|
2 | * Copyright (c) 2014 embedded brains GmbH. All rights reserved. |
---|
3 | * |
---|
4 | * embedded brains GmbH |
---|
5 | * Dornierstr. 4 |
---|
6 | * 82178 Puchheim |
---|
7 | * Germany |
---|
8 | * <rtems@embedded-brains.de> |
---|
9 | * |
---|
10 | * The license and distribution terms for this file may be |
---|
11 | * found in the file LICENSE in this distribution or at |
---|
12 | * http://www.rtems.org/license/LICENSE. |
---|
13 | */ |
---|
14 | |
---|
15 | #include <bsp/console-termios.h> |
---|
16 | #include <bsp/fatal.h> |
---|
17 | |
---|
18 | #include <rtems/console.h> |
---|
19 | |
---|
20 | static rtems_interrupt_lock console_lock = |
---|
21 | RTEMS_INTERRUPT_LOCK_INITIALIZER( "console" ); |
---|
22 | |
---|
23 | static rtems_device_major_number console_major = UINT32_MAX; |
---|
24 | |
---|
25 | static rtems_device_minor_number console_minor; |
---|
26 | |
---|
27 | rtems_status_code console_device_install( |
---|
28 | const char *device_file, |
---|
29 | const rtems_termios_device_handler *handler, |
---|
30 | const rtems_termios_device_flow *flow, |
---|
31 | rtems_termios_device_context *context |
---|
32 | ) |
---|
33 | { |
---|
34 | rtems_interrupt_lock_context lock_context; |
---|
35 | rtems_device_minor_number minor; |
---|
36 | |
---|
37 | rtems_interrupt_lock_acquire( &console_lock, &lock_context ); |
---|
38 | minor = console_minor; |
---|
39 | ++console_minor; |
---|
40 | rtems_interrupt_lock_release( &console_lock, &lock_context ); |
---|
41 | |
---|
42 | return rtems_termios_device_install( |
---|
43 | device_file, |
---|
44 | console_major, |
---|
45 | minor, |
---|
46 | handler, |
---|
47 | flow, |
---|
48 | context |
---|
49 | ); |
---|
50 | } |
---|
51 | |
---|
52 | bool console_device_probe_default(rtems_termios_device_context *context) |
---|
53 | { |
---|
54 | (void) context; |
---|
55 | |
---|
56 | return true; |
---|
57 | } |
---|
58 | |
---|
59 | rtems_device_driver console_initialize( |
---|
60 | rtems_device_major_number major, |
---|
61 | rtems_device_minor_number minor, |
---|
62 | void *arg |
---|
63 | ) |
---|
64 | { |
---|
65 | bool console_device_done = false; |
---|
66 | |
---|
67 | rtems_termios_initialize(); |
---|
68 | |
---|
69 | for ( minor = 0; minor < console_device_count; ++minor ) { |
---|
70 | const console_device *ctx = &console_device_table[ minor ]; |
---|
71 | rtems_status_code sc; |
---|
72 | |
---|
73 | if ( ( *ctx->probe )( ctx->context ) ) { |
---|
74 | sc = rtems_termios_device_install( |
---|
75 | ctx->device_file, |
---|
76 | major, |
---|
77 | minor, |
---|
78 | ctx->handler, |
---|
79 | ctx->flow, |
---|
80 | ctx->context |
---|
81 | ); |
---|
82 | if ( sc != RTEMS_SUCCESSFUL ) { |
---|
83 | bsp_fatal( BSP_FATAL_CONSOLE_INSTALL_0 ); |
---|
84 | } |
---|
85 | |
---|
86 | if ( !console_device_done ) { |
---|
87 | console_device_done = true; |
---|
88 | |
---|
89 | sc = rtems_io_register_name( CONSOLE_DEVICE_NAME, major, minor ); |
---|
90 | if ( sc != RTEMS_SUCCESSFUL ) { |
---|
91 | bsp_fatal( BSP_FATAL_CONSOLE_INSTALL_1 ); |
---|
92 | } |
---|
93 | } |
---|
94 | } |
---|
95 | } |
---|
96 | |
---|
97 | console_major = major; |
---|
98 | console_minor = minor; |
---|
99 | |
---|
100 | return RTEMS_SUCCESSFUL; |
---|
101 | } |
---|