Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
Software for White Rabbit PTP Core
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
32
Issues
32
List
Board
Labels
Milestones
Merge Requests
7
Merge Requests
7
CI / CD
CI / CD
Pipelines
Schedules
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
Software for White Rabbit PTP Core
Commits
fadea1c1
Commit
fadea1c1
authored
May 04, 2023
by
Tristan Gingold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
console: enable binary/tty mode only on ertm14
parent
d2408d81
Pipeline
#4502
passed with stage
in 2 minutes and 59 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
9 deletions
+35
-9
console-uart.c
dev/console-uart.c
+23
-9
console-uart.h
include/dev/console-uart.h
+12
-0
No files found.
dev/console-uart.c
View file @
fadea1c1
...
...
@@ -28,14 +28,16 @@ static int con_rx_internal(struct console_device* dev)
{
struct
console_uart_priv_data
*
priv
=
(
struct
console_uart_priv_data
*
)
dev
->
priv
;
#ifdef CONFIG_CONSOLE_UART_MODE
if
(
priv
->
state
==
CON_STATE_ESC_FLUSH
)
{
priv
->
state
=
CON_STATE_IDLE
;
return
priv
->
prev_char
;
}
#endif
int
rx_char
=
suart_read_byte
(
&
priv
->
uart_dev
);
#ifdef CONFIG_CONSOLE_UART_MODE
if
(
rx_char
<
0
)
return
rx_char
;
...
...
@@ -74,6 +76,7 @@ static int con_rx_internal(struct console_device* dev)
}
priv
->
state
=
CON_STATE_IDLE
;
}
#endif
return
rx_char
;
}
...
...
@@ -83,14 +86,16 @@ static int con_uart_put_string(struct console_device* dev, const char *s)
char
c
;
int
count
=
0
;
#ifdef CONFIG_CONSOLE_UART_MODE
// binary mode uses different API
if
(
dev
->
flags
&
CONSOLE_FLAGS_MODE_BINARY
)
return
0
;
#endif
while
(
(
c
=
*
s
++
)
!=
0
)
{
if
(
(
dev
->
flags
&
CONSOLE_FLAGS_INSERT_CRLF
)
&&
c
==
'\n'
)
suart_write_byte
(
&
priv
->
uart_dev
,
'\r'
);
if
(
(
dev
->
flags
&
CONSOLE_FLAGS_INSERT_CRLF
)
&&
c
==
'\n'
)
suart_write_byte
(
&
priv
->
uart_dev
,
'\r'
);
suart_write_byte
(
&
priv
->
uart_dev
,
c
);
count
++
;
...
...
@@ -101,8 +106,10 @@ static int con_uart_put_string(struct console_device* dev, const char *s)
static
int
con_uart_getc
(
struct
console_device
*
dev
)
{
#ifdef CONFIG_CONSOLE_UART_MODE
if
(
dev
->
flags
&
CONSOLE_FLAGS_MODE_BINARY
)
return
0
;
#endif
return
con_rx_internal
(
dev
);
}
...
...
@@ -115,12 +122,6 @@ void console_uart_set_crlf_mode(int on)
console_uart_dev
.
flags
&=
~
CONSOLE_FLAGS_INSERT_CRLF
;
}
void
console_set_mode_switch_hook
(
struct
console_device
*
dev
,
void
(
*
callback
)(
int
)
)
{
struct
console_uart_priv_data
*
priv
=
(
struct
console_uart_priv_data
*
)
dev
->
priv
;
priv
->
mode_switch_hook
=
callback
;
}
void
console_uart_init
(
struct
console_device
*
dev
,
struct
console_uart_priv_data
*
priv
,
unsigned
addr
,
...
...
@@ -133,20 +134,32 @@ void console_uart_init(struct console_device *dev,
dev
->
get_char
=
con_uart_getc
;
dev
->
put_string
=
con_uart_put_string
;
#ifdef CONFIG_CONSOLE_UART_MODE
priv
->
prev_char
=
0
;
priv
->
state
=
CON_STATE_IDLE
;
priv
->
mode_switch_hook
=
NULL
;
#endif
console_register_device
(
dev
);
}
#ifdef CONFIG_CONSOLE_UART_MODE
void
console_set_mode_switch_hook
(
struct
console_device
*
dev
,
void
(
*
callback
)(
int
)
)
{
struct
console_uart_priv_data
*
priv
=
(
struct
console_uart_priv_data
*
)
dev
->
priv
;
priv
->
mode_switch_hook
=
callback
;
}
void
console_force_mode
(
struct
console_device
*
dev
,
int
mode
)
{
struct
console_uart_priv_data
*
priv
=
(
struct
console_uart_priv_data
*
)
dev
->
priv
;
dev
->
flags
&=
~
(
CONSOLE_FLAGS_MODE_BINARY
|
CONSOLE_FLAGS_MODE_TTY
);
dev
->
flags
|=
mode
;
#ifdef CONFIG_CONSOLE_UART_MODE
priv
->
state
=
CON_STATE_IDLE
;
#endif
}
int
console_get_mode
(
struct
console_device
*
dev
)
...
...
@@ -187,3 +200,4 @@ int console_binary_recv_byte( struct console_device *dev )
return
rx_byte
;
}
#endif
include/dev/console-uart.h
View file @
fadea1c1
...
...
@@ -14,16 +14,26 @@
#include "dev/console.h"
#include "dev/simple_uart.h"
/* Add a binary/ascii mode to the uart console.
Only for ertm14. */
#ifdef CONFIG_TARGET_ERTM14
#define CONFIG_CONSOLE_UART_MODE 1
#endif
#ifdef CONFIG_CONSOLE_UART_MODE
#define CON_STATE_IDLE 0
#define CON_STATE_ESC_PENDING 1 // previous char was escape, waiting for control code
#define CON_STATE_ESC_FLUSH 2 // previous char was an unrecognized escape sequence, pass both to the user
#endif
struct
console_uart_priv_data
{
struct
simple_uart_device
uart_dev
;
#ifdef CONFIG_CONSOLE_UART_MODE
uint8_t
state
;
uint8_t
prev_char
;
void
(
*
mode_switch_hook
)(
int
is_binary
);
#endif
};
void
console_uart_init
(
struct
console_device
*
dev
,
...
...
@@ -37,6 +47,7 @@ extern struct console_device console_uart_dev;
void
console_uart_set_crlf_mode
(
int
on
);
#ifdef CONFIG_CONSOLE_UART_MODE
void
console_force_mode
(
struct
console_device
*
dev
,
int
mode
);
int
console_get_mode
(
struct
console_device
*
dev
);
...
...
@@ -44,6 +55,7 @@ int console_binary_send_byte( struct console_device *dev, uint8_t b );
int
console_binary_recv_byte
(
struct
console_device
*
dev
);
void
console_set_mode_switch_hook
(
struct
console_device
*
dev
,
void
(
*
callback
)(
int
)
);
#endif
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment