Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
PolyORB-HI-C
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
6
Issues
6
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
TASTE
PolyORB-HI-C
Commits
68751956
Commit
68751956
authored
Mar 10, 2020
by
Rafal Babski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
linux_serial_minimal - code refactor
parent
6c0c1325
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
44 deletions
+32
-44
src/drivers/linux_serial_minimal.c
src/drivers/linux_serial_minimal.c
+32
-44
No files found.
src/drivers/linux_serial_minimal.c
View file @
68751956
...
...
@@ -12,12 +12,10 @@
#include <po_hi_protected.h>
#include <drivers/po_hi_driver_serial_common.h>
/* po-hi-c related files */
#include <activity.h>
#include <marshallers.h>
#include <deployment.h>
/* generated files */
#include <linux/ioctl.h>
#include <termios.h>
#include <sys/types.h>
...
...
@@ -28,19 +26,6 @@
#include <stdlib.h>
#include <stdio.h>
/* Linux-specific files */
static
void
show_data
(
const
uint8_t
*
data
,
size_t
length
)
{
printf
(
"Data: %ul bytes: hex ["
,
length
);
size_t
i
;
for
(
i
=
0
;
i
<
length
;
++
i
)
{
printf
(
"%02ul "
,
(
unsigned
int
)(
data
[
i
]));
}
printf
(
"]
\n
"
);
}
/* Set parity bits in struct termios according to configuration.
* If the configuration does not exist, then parity is disabled.
*/
...
...
@@ -52,25 +37,25 @@ static void setup_parity_bits(struct termios* tty, __po_hi_c_serial_conf_t* seri
{
if
(
serialconf
->
parity
==
__po_hi_c_odd
)
{
printf
(
"Setting parity odd
\n
"
);
__PO_HI_DEBUG_DEBUG
(
"Setting parity odd
\n
"
);
tty
->
c_cflag
|=
PARODD
;
}
else
{
printf
(
"Setting parity even
\n
"
);
__PO_HI_DEBUG_DEBUG
(
"Setting parity even
\n
"
);
tty
->
c_cflag
&=
~
PARODD
;
}
tty
->
c_cflag
|=
PARENB
;
}
else
{
printf
(
"Setting parity disabled
\n
"
);
tty
->
c_cflag
&=
~
PARENB
;
// shut off parity
__PO_HI_DEBUG_DEBUG
(
"Setting parity disabled
\n
"
);
tty
->
c_cflag
&=
~
PARENB
;
// shut off parity
}
}
else
{
printf
(
"Setting parity disabled
\n
"
);
__PO_HI_DEBUG_DEBUG
(
"Setting parity disabled
\n
"
);
tty
->
c_cflag
&=
~
PARENB
;
}
}
...
...
@@ -78,6 +63,7 @@ static void setup_parity_bits(struct termios* tty, __po_hi_c_serial_conf_t* seri
/* Set character size in struct termios according to configuration.
* If the configuration does not exist, then character with is 8 bits.
*/
static
void
setup_bit_size
(
struct
termios
*
tty
,
__po_hi_c_serial_conf_t
*
serialconf
)
{
if
(
serialconf
->
exist
.
bits
)
...
...
@@ -85,25 +71,30 @@ static void setup_bit_size(struct termios* tty, __po_hi_c_serial_conf_t* serialc
switch
(
serialconf
->
bits
)
{
case
5
:
printf
(
"Setting bit 5
\n
"
);
__PO_HI_DEBUG_DEBUG
(
"Setting bit 5
\n
"
);
tty
->
c_cflag
|=
CS5
;
break
;
case
6
:
printf
(
"Setting bit 6
\n
"
);
__PO_HI_DEBUG_DEBUG
(
"Setting bit 6
\n
"
);
tty
->
c_cflag
|=
CS6
;
break
;
case
7
:
printf
(
"Setting bit 7
\n
"
);
__PO_HI_DEBUG_DEBUG
(
"Setting bit 7
\n
"
);
tty
->
c_cflag
|=
CS7
;
break
;
case
8
:
printf
(
"Setting bit 8
\n
"
);
__PO_HI_DEBUG_DEBUG
(
"Setting bit 8
\n
"
);
tty
->
c_cflag
|=
CS8
;
break
;
default:
printf
(
"Setting bit 8
\n
"
);
__PO_HI_DEBUG_DEBUG
(
"Setting bit 8
\n
"
);
tty
->
c_cflag
|=
CS8
;
break
;
}
}
else
...
...
@@ -127,7 +118,6 @@ static void setup_termios(struct termios* tty, __po_hi_device_id id)
setup_bit_size
(
tty
,
serialconf
);
tty
->
c_cflag
&=
~
CSTOPB
;
tty
->
c_cflag
&=
~
CRTSCTS
;
tty
->
c_lflag
&=
~
ICANON
;
tty
->
c_lflag
&=
~
ECHOE
;
...
...
@@ -161,21 +151,25 @@ static void setup_termios(struct termios* tty, __po_hi_device_id id)
cfsetispeed
(
tty
,
B38400
);
__PO_HI_DEBUG_DEBUG
(
"[LINUX SERIAL] Set speed to 38400
\n
"
);
break
;
case
__po_hi_c_b57600
:
cfsetospeed
(
tty
,
B57600
);
cfsetispeed
(
tty
,
B57600
);
__PO_HI_DEBUG_DEBUG
(
"[LINUX SERIAL] Set speed to 57600
\n
"
);
break
;
case
__po_hi_c_b115200
:
cfsetospeed
(
tty
,
B115200
);
cfsetispeed
(
tty
,
B115200
);
__PO_HI_DEBUG_DEBUG
(
"[LINUX SERIAL] Set speed to 115200
\n
"
);
break
;
case
__po_hi_c_b230400
:
cfsetospeed
(
tty
,
B230400
);
cfsetispeed
(
tty
,
B230400
);
__PO_HI_DEBUG_DEBUG
(
"[LINUX SERIAL] Set speed to 115200
\n
"
);
break
;
}
}
else
...
...
@@ -194,7 +188,7 @@ static int encode_packet(uint8_t* data, const uint8_t* msg_content, const int ms
{
if
(
msg_length
<=
8
)
{
printf
(
"Encoding packet Not enaugh msg_length, %d
\n
"
,
msg_length
);
__PO_HI_DEBUG_DEBUG
(
"Encoding packet Not enaugh msg_length, %d
\n
"
,
msg_length
);
// the message is empty
return
0
;
}
...
...
@@ -204,9 +198,6 @@ static int encode_packet(uint8_t* data, const uint8_t* msg_content, const int ms
// last four bytes of msg_content - actual msg length
uint32_t
*
length_ptr
=
(
uint32_t
*
)(
msg_content
+
(
msg_length
-
4
));
printf
(
"Encoding packet, msg_length=%d
\n
"
,
msg_length
);
printf
(
"Actual length = %ul
\n
"
,
*
length_ptr
);
int
length
=
0
;
data
[
length
++
]
=
PACKET_START_BYTE
;
...
...
@@ -226,7 +217,6 @@ static int encode_packet(uint8_t* data, const uint8_t* msg_content, const int ms
data
[
length
++
]
=
PACKET_STOP_BYTE
;
printf
(
"Result packet length %d
\n
"
,
length
);
return
length
;
}
...
...
@@ -347,7 +337,6 @@ void __po_hi_c_driver_linux_serial_minimal_init (__po_hi_device_id id)
return
;
}
#define PACKET_DECODER_BUFFER_SIZE 100
enum
PACKET_DECODER_STATE
...
...
@@ -363,21 +352,21 @@ static enum PACKET_DECODER_STATE packet_decoder_state;
static
void
process_packet
(
uint8_t
*
data
,
int
size
)
{
__PO_HI_DEBUG_
CRITICAL
(
"[LINUX SERIAL] Processing packet
\n
"
);
__PO_HI_DEBUG_
DEBUG
(
"[LINUX SERIAL] Processing packet
\n
"
);
__po_hi_c_driver_linux_serial_minimal_request
.
port
=
(
__po_hi_local_port_t
)
7
;
__PO_HI_DEBUG_
CRITICAL
(
"[LINUX SERIAL] Copying data (%d bytes)
\n
"
,
size
);
__PO_HI_DEBUG_
DEBUG
(
"[LINUX SERIAL] Copying data (%d bytes)
\n
"
,
size
);
memcpy
(
&
__po_hi_c_driver_linux_serial_minimal_request
.
vars
,
data
,
size
);
uint8_t
*
request_size_pointer
=
((
uint8_t
*
)
&
__po_hi_c_driver_linux_serial_minimal_request
.
vars
)
+
size
;
__PO_HI_DEBUG_
CRITICAL
(
"[LINUX SERIAL] Copying size (%d bytes)
\n
"
,
size
);
__PO_HI_DEBUG_
DEBUG
(
"[LINUX SERIAL] Copying size (%d bytes)
\n
"
,
size
);
memcpy
(
request_size_pointer
,
&
size
,
4
);
__PO_HI_DEBUG_
CRITICAL
(
"[LINUX SERIAL] Packet deliver
\n
"
,
size
);
__PO_HI_DEBUG_
DEBUG
(
"[LINUX SERIAL] Packet deliver
\n
"
,
size
);
__po_hi_main_deliver
(
&
__po_hi_c_driver_linux_serial_minimal_request
);
}
static
int
process_character
(
uint8_t
c
)
{
__PO_HI_DEBUG_
CRITICAL
(
"[LINUX SERIAL] Processing character
\n
"
);
__PO_HI_DEBUG_
DEBUG
(
"[LINUX SERIAL] Processing character
\n
"
);
int
result
=
0
;
switch
(
packet_decoder_state
)
{
...
...
@@ -432,7 +421,7 @@ void __po_hi_c_driver_linux_serial_minimal_poller (const __po_hi_device_id dev_i
{
if
(
read
(
po_hi_c_driver_serial_fd_read
,
local_buffer
,
1
)
==
1
)
{
__PO_HI_DEBUG_CRITICAL
(
"[LINUX SERIAL] Received one character %02x !
\n
"
,
(
unsigned
int
)
local_buffer
[
0
]
);
__PO_HI_DEBUG_DEBUG
(
"[LINUX SERIAL] Received one character %02x !
\n
"
,
(
unsigned
int
)
local_buffer
[
0
]
);
if
(
process_character
(
local_buffer
[
0
]))
{
break
;
...
...
@@ -446,7 +435,6 @@ void __po_hi_c_driver_linux_serial_minimal_poller (const __po_hi_device_id dev_i
}
}
__po_hi_msg_t
__po_hi_c_driver_linux_serial_minimal_sender_msg
;
int
__po_hi_c_driver_linux_serial_minimal_sender
(
__po_hi_task_id
task_id
,
__po_hi_port_t
port
)
...
...
@@ -490,8 +478,8 @@ int __po_hi_c_driver_linux_serial_minimal_sender (__po_hi_task_id task_id, __po
if
(
po_hi_c_driver_serial_sending_wait
!=
0
)
{
__PO_HI_DEBUG_
CRITICAL
(
" [LINUX SERIAL] write %d bytes in loop to device
\n
"
,
length
);
show_data
(
data
,
length
);
__PO_HI_DEBUG_
DEBUG
(
" [LINUX SERIAL] write %d bytes in loop to device
\n
"
,
length
);
for
(
n
=
0
;
n
<
length
;
n
++
)
{
write
(
po_hi_c_driver_serial_fd_write
,
&
(
data
[
n
]),
1
);
...
...
@@ -501,15 +489,15 @@ int __po_hi_c_driver_linux_serial_minimal_sender (__po_hi_task_id task_id, __po
if
(
n
<=
0
)
{
__PO_HI_DEBUG_
DEBUG
(
" [LINUX SERIAL] failed to write !
\n
"
);
__PO_HI_DEBUG_
CRITICAL
(
" [LINUX SERIAL] failed to write !
\n
"
);
}
}
}
else
{
__PO_HI_DEBUG_
CRITICAL
(
" [LINUX SERIAL] write %d bytes to device
\n
"
,
length
);
show_data
(
data
,
length
);
__PO_HI_DEBUG_
DEBUG
(
" [LINUX SERIAL] write %d bytes to device
\n
"
,
length
);
n
=
write
(
po_hi_c_driver_serial_fd_write
,
data
,
length
);
fsync
(
po_hi_c_driver_serial_fd_write
);
...
...
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