Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cm510_controller_fw
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
humanoides
cm510_controller_fw
Commits
2c76c427
Commit
2c76c427
authored
9 years ago
by
Laia Freixas Mateu
Browse files
Options
Downloads
Plain Diff
Merge branch 'master' of
https://gitlab.iri.upc.edu/humanoides/cm510_controller_fw
parents
9511fecc
b79950ec
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
communications/src/dynamixel_master.c
+3
-43
3 additions, 43 deletions
communications/src/dynamixel_master.c
communications/src/serial_console.c
+68
-27
68 additions, 27 deletions
communications/src/serial_console.c
controllers/include/cm510_cfg.h
+1
-1
1 addition, 1 deletion
controllers/include/cm510_cfg.h
with
72 additions
and
71 deletions
communications/src/dynamixel_master.c
+
3
−
43
View file @
2c76c427
...
@@ -61,6 +61,7 @@ void dyn_master_set_rx_mode(void)
...
@@ -61,6 +61,7 @@ void dyn_master_set_rx_mode(void)
/* interrupt handlers */
/* interrupt handlers */
ISR
(
USART0_TX_vect
)
ISR
(
USART0_TX_vect
)
{
{
cli
();
if
(
dyn_master_sent_bytes
==
dyn_master_tx_buffer
[
3
]
+
4
)
if
(
dyn_master_sent_bytes
==
dyn_master_tx_buffer
[
3
]
+
4
)
{
{
dyn_master_set_rx_mode
();
dyn_master_set_rx_mode
();
...
@@ -71,6 +72,7 @@ ISR(USART0_TX_vect)
...
@@ -71,6 +72,7 @@ ISR(USART0_TX_vect)
UDR0
=
dyn_master_tx_buffer
[
dyn_master_sent_bytes
];
UDR0
=
dyn_master_tx_buffer
[
dyn_master_sent_bytes
];
dyn_master_sent_bytes
++
;
dyn_master_sent_bytes
++
;
}
}
sei
();
}
}
ISR
(
USART0_RX_vect
)
ISR
(
USART0_RX_vect
)
...
@@ -127,7 +129,6 @@ uint8_t dyn_master_send(void)
...
@@ -127,7 +129,6 @@ uint8_t dyn_master_send(void)
uint8_t
dyn_master_wait_reception
(
void
)
uint8_t
dyn_master_wait_reception
(
void
)
{
{
// set timeout
// set timeout
dyn_master_start_timeout
();
// wait for the status packet
// wait for the status packet
if
(
dyn_master_rx_no_answer
)
if
(
dyn_master_rx_no_answer
)
{
{
...
@@ -136,6 +137,7 @@ uint8_t dyn_master_wait_reception(void)
...
@@ -136,6 +137,7 @@ uint8_t dyn_master_wait_reception(void)
}
}
else
else
{
{
dyn_master_start_timeout
();
while
(
dyn_master_packet_ready
==
0x00
)
while
(
dyn_master_packet_ready
==
0x00
)
{
{
if
(
dyn_master_timeout
())
if
(
dyn_master_timeout
())
...
@@ -278,12 +280,6 @@ uint8_t dyn_master_ping(uint8_t id)
...
@@ -278,12 +280,6 @@ uint8_t dyn_master_ping(uint8_t id)
dyn_master_set_rx_mode
();
dyn_master_set_rx_mode
();
return
error
;
return
error
;
}
}
// wait for the transmission to end
if
((
error
=
dyn_master_wait_transmission
())
!=
DYN_SUCCESS
)
{
dyn_master_set_rx_mode
();
return
error
;
}
// wait for the replay within the given timeout
// wait for the replay within the given timeout
error
=
dyn_master_wait_reception
();
error
=
dyn_master_wait_reception
();
...
@@ -328,12 +324,6 @@ uint8_t dyn_master_read_table(uint8_t id,uint16_t address,uint16_t length,uint8_
...
@@ -328,12 +324,6 @@ uint8_t dyn_master_read_table(uint8_t id,uint16_t address,uint16_t length,uint8_
dyn_master_set_rx_mode
();
dyn_master_set_rx_mode
();
return
error
;
return
error
;
}
}
// wait for the transmission to end
if
((
error
=
dyn_master_wait_transmission
())
!=
DYN_SUCCESS
)
{
dyn_master_set_rx_mode
();
return
error
;
}
// wait for the replay within the given timeout
// wait for the replay within the given timeout
if
(
dyn_master_return_level
!=
no_return
&&
id
!=
DYN_BROADCAST_ID
)
if
(
dyn_master_return_level
!=
no_return
&&
id
!=
DYN_BROADCAST_ID
)
{
{
...
@@ -382,12 +372,6 @@ uint8_t dyn_master_write_table(uint8_t id, uint16_t address, uint16_t length, ui
...
@@ -382,12 +372,6 @@ uint8_t dyn_master_write_table(uint8_t id, uint16_t address, uint16_t length, ui
dyn_master_set_rx_mode
();
dyn_master_set_rx_mode
();
return
error
;
return
error
;
}
}
// wait for the transmission to end
if
((
error
=
dyn_master_wait_transmission
())
!=
DYN_SUCCESS
)
{
dyn_master_set_rx_mode
();
return
error
;
}
// wait for the replay within the given timeout
// wait for the replay within the given timeout
if
(
dyn_master_return_level
==
return_all
&&
id
!=
DYN_BROADCAST_ID
)
if
(
dyn_master_return_level
==
return_all
&&
id
!=
DYN_BROADCAST_ID
)
error
=
dyn_master_wait_reception
();
error
=
dyn_master_wait_reception
();
...
@@ -416,12 +400,6 @@ uint8_t dyn_master_reg_write(uint8_t id, uint16_t address, uint16_t length, uint
...
@@ -416,12 +400,6 @@ uint8_t dyn_master_reg_write(uint8_t id, uint16_t address, uint16_t length, uint
dyn_master_set_rx_mode
();
dyn_master_set_rx_mode
();
return
error
;
return
error
;
}
}
// wait for the transmission to end
if
((
error
=
dyn_master_wait_transmission
())
!=
DYN_SUCCESS
)
{
dyn_master_set_rx_mode
();
return
error
;
}
// wait for the replay within the given timeout
// wait for the replay within the given timeout
if
(
dyn_master_return_level
==
return_all
&&
id
!=
DYN_BROADCAST_ID
)
if
(
dyn_master_return_level
==
return_all
&&
id
!=
DYN_BROADCAST_ID
)
error
=
dyn_master_wait_reception
();
error
=
dyn_master_wait_reception
();
...
@@ -447,12 +425,6 @@ uint8_t dyn_master_action(void)
...
@@ -447,12 +425,6 @@ uint8_t dyn_master_action(void)
dyn_master_set_rx_mode
();
dyn_master_set_rx_mode
();
return
error
;
return
error
;
}
}
// wait for the transmission to end
if
((
error
=
dyn_master_wait_transmission
())
!=
DYN_SUCCESS
)
{
dyn_master_set_rx_mode
();
return
error
;
}
return
error
;
return
error
;
}
}
...
@@ -475,12 +447,6 @@ uint8_t dyn_master_sync_write(uint8_t num,uint8_t *ids,uint16_t address, uint16_
...
@@ -475,12 +447,6 @@ uint8_t dyn_master_sync_write(uint8_t num,uint8_t *ids,uint16_t address, uint16_
dyn_master_set_rx_mode
();
dyn_master_set_rx_mode
();
return
error
;
return
error
;
}
}
// wait for the transmission to end
if
((
error
=
dyn_master_wait_transmission
())
!=
DYN_SUCCESS
)
{
dyn_master_set_rx_mode
();
return
error
;
}
return
error
;
return
error
;
}
}
...
@@ -511,12 +477,6 @@ uint8_t dyn_master_bulk_read(uint8_t num,uint8_t *ids,uint16_t *address, uint16_
...
@@ -511,12 +477,6 @@ uint8_t dyn_master_bulk_read(uint8_t num,uint8_t *ids,uint16_t *address, uint16_
dyn_master_set_rx_mode
();
dyn_master_set_rx_mode
();
return
error
;
return
error
;
}
}
// wait for the transmission to end
if
((
error
=
dyn_master_wait_transmission
())
!=
DYN_SUCCESS
)
{
dyn_master_set_rx_mode
();
return
error
;
}
// wait for the replay within the given timeout
// wait for the replay within the given timeout
if
(
dyn_master_return_level
!=
no_return
)
if
(
dyn_master_return_level
!=
no_return
)
{
{
...
...
This diff is collapsed.
Click to expand it.
communications/src/serial_console.c
+
68
−
27
View file @
2c76c427
...
@@ -3,21 +3,40 @@
...
@@ -3,21 +3,40 @@
#include
<stdio.h>
#include
<stdio.h>
/* private variables */
/* private variables */
volatile
uint8_t
serial_console_buffer
[
SERIAL_CONSOLE_MAX_BUFFER_LEN
];
volatile
uint8_t
serial_console_rx_buffer
[
SERIAL_CONSOLE_MAX_BUFFER_LEN
];
volatile
uint8_t
serial_console_read_ptr
;
volatile
uint8_t
serial_console_rx_read_ptr
;
volatile
uint8_t
serial_console_write_ptr
;
volatile
uint8_t
serial_console_rx_write_ptr
;
volatile
uint8_t
serial_console_num_data
;
volatile
uint8_t
serial_console_rx_num_data
;
volatile
uint8_t
serial_console_tx_buffer
[
SERIAL_CONSOLE_MAX_BUFFER_LEN
];
volatile
uint8_t
serial_console_tx_read_ptr
;
volatile
uint8_t
serial_console_tx_write_ptr
;
volatile
uint8_t
serial_console_tx_num_data
;
volatile
uint8_t
serial_console_sending
;
static
FILE
*
device
;
static
FILE
*
device
;
/* interrupt handlers */
/* interrupt handlers */
SIGNAL
(
USART1_RX_vect
)
SIGNAL
(
USART1_RX_vect
)
{
{
if
(
serial_console_num_data
<
SERIAL_CONSOLE_MAX_BUFFER_LEN
)
cli
();
serial_console_rx_buffer
[
serial_console_rx_write_ptr
]
=
UDR1
;
serial_console_rx_write_ptr
=
(
serial_console_rx_write_ptr
+
1
)
%
SERIAL_CONSOLE_MAX_BUFFER_LEN
;
if
(
serial_console_rx_num_data
<
SERIAL_CONSOLE_MAX_BUFFER_LEN
)
serial_console_rx_num_data
++
;
sei
();
}
SIGNAL
(
USART1_TX_vect
)
{
cli
();
if
(
serial_console_tx_num_data
>
0
)
{
{
serial_console_buffer
[
serial_console_
write_ptr
]
=
UDR1
;
UDR1
=
serial_console_
tx_
buffer
[
serial_console_
tx_read_ptr
]
;
serial_console_
write
_ptr
=
(
serial_console_
write
_ptr
+
1
)
%
SERIAL_CONSOLE_MAX_BUFFER_LEN
;
serial_console_
tx_read
_ptr
=
(
serial_console_
tx_read
_ptr
+
1
)
%
SERIAL_CONSOLE_MAX_BUFFER_LEN
;
serial_console_num_data
++
;
serial_console_
tx_
num_data
--
;
}
}
else
serial_console_sending
=
0x00
;
sei
();
}
}
/* private functions */
/* private functions */
...
@@ -32,14 +51,25 @@ void serial_console_set_baudrate(uint32_t baudrate)
...
@@ -32,14 +51,25 @@ void serial_console_set_baudrate(uint32_t baudrate)
int
serial_console_putchar
(
char
c
,
FILE
*
dev
)
int
serial_console_putchar
(
char
c
,
FILE
*
dev
)
{
{
if
(
c
==
'\n'
)
cli
();
if
(
c
==
'\n'
)
{
{
while
((
UCSR1A
&
(
1
<<
UDRE1
))
==
0x00
);
serial_console_tx_buffer
[
serial_console_tx_write_ptr
]
=
'\r'
;
UDR1
=
'\r'
;
serial_console_tx_write_ptr
=
(
serial_console_tx_write_ptr
+
1
)
%
SERIAL_CONSOLE_MAX_BUFFER_LEN
;
serial_console_tx_num_data
++
;
}
}
serial_console_tx_buffer
[
serial_console_tx_write_ptr
]
=
c
;
while
((
UCSR1A
&
(
1
<<
UDRE1
))
==
0x00
);
serial_console_tx_write_ptr
=
(
serial_console_tx_write_ptr
+
1
)
%
SERIAL_CONSOLE_MAX_BUFFER_LEN
;
UDR1
=
c
;
serial_console_tx_num_data
++
;
if
(
serial_console_sending
==
0x00
)
{
UDR1
=
serial_console_tx_buffer
[
serial_console_tx_read_ptr
];
serial_console_tx_read_ptr
=
(
serial_console_tx_read_ptr
+
1
)
%
SERIAL_CONSOLE_MAX_BUFFER_LEN
;
serial_console_tx_num_data
--
;
serial_console_sending
=
0x01
;
}
sei
();
return
0
;
return
0
;
}
}
...
@@ -48,14 +78,22 @@ int serial_console_getchar(FILE *dev)
...
@@ -48,14 +78,22 @@ int serial_console_getchar(FILE *dev)
{
{
int8_t
rx
;
int8_t
rx
;
while
(
serial_console_num_data
==
0
);
cli
();
rx
=
serial_console_buffer
[
serial_console_read_ptr
];
if
(
serial_console_rx_num_data
>
0
)
serial_console_read_ptr
=
(
serial_console_read_ptr
+
1
)
%
SERIAL_CONSOLE_MAX_BUFFER_LEN
;
{
serial_console_num_data
--
;
rx
=
serial_console_rx_buffer
[
serial_console_rx_read_ptr
];
if
(
rx
==
'\r'
)
serial_console_rx_read_ptr
=
(
serial_console_rx_read_ptr
+
1
)
%
SERIAL_CONSOLE_MAX_BUFFER_LEN
;
rx
=
'\n'
;
serial_console_rx_num_data
--
;
if
(
rx
==
'\r'
)
return
rx
;
rx
=
'\n'
;
sei
();
return
rx
;
}
else
{
sei
();
return
-
1
;
}
}
}
/* pubic functions */
/* pubic functions */
...
@@ -78,7 +116,7 @@ void serial_console_init(uint32_t baudrate)
...
@@ -78,7 +116,7 @@ void serial_console_init(uint32_t baudrate)
// bit4: enable rx
// bit4: enable rx
// bit3: enable tx
// bit3: enable tx
// bit2: set sendding size(0 = 8bit)
// bit2: set sendding size(0 = 8bit)
UCSR1B
=
0
b1
0
011000
;
UCSR1B
=
0
b1
1
011000
;
// set UART register C
// set UART register C
// bit6: communication mode (1 = synchronize, 0 = asynchronize)
// bit6: communication mode (1 = synchronize, 0 = asynchronize)
...
@@ -88,10 +126,13 @@ void serial_console_init(uint32_t baudrate)
...
@@ -88,10 +126,13 @@ void serial_console_init(uint32_t baudrate)
UCSR1C
=
0
b00000110
;
UCSR1C
=
0
b00000110
;
// initialize
// initialize
UDR1
=
0xFF
;
serial_console_rx_read_ptr
=
0
;
serial_console_read_ptr
=
0
;
serial_console_rx_write_ptr
=
0
;
serial_console_write_ptr
=
0
;
serial_console_rx_num_data
=
0
;
serial_console_num_data
=
0
;
serial_console_tx_read_ptr
=
0
;
serial_console_tx_write_ptr
=
0
;
serial_console_tx_num_data
=
0
;
serial_console_sending
=
0x00
;
// set baudrate
// set baudrate
serial_console_set_baudrate
(
baudrate
);
serial_console_set_baudrate
(
baudrate
);
...
...
This diff is collapsed.
Click to expand it.
controllers/include/cm510_cfg.h
+
1
−
1
View file @
2c76c427
...
@@ -16,7 +16,7 @@
...
@@ -16,7 +16,7 @@
#define DYN_MASTER_MAX_TX_BUFFER_LEN 128
#define DYN_MASTER_MAX_TX_BUFFER_LEN 128
#define DYN_MASTER_MAX_RX_BUFFER_LEN 128
#define DYN_MASTER_MAX_RX_BUFFER_LEN 128
#define DYN_MASTER_DEFAULT_BAUDRATE 1000000
#define DYN_MASTER_DEFAULT_BAUDRATE 1000000
#define DYN_MASTER_DEFAULT_TIMEOUT_US 1000
0
#define DYN_MASTER_DEFAULT_TIMEOUT_US 1000
#define SERIAL_CONSOLE_MAX_BUFFER_LEN 128
#define SERIAL_CONSOLE_MAX_BUFFER_LEN 128
// motion configuration parameters
// motion configuration parameters
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment