Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Tammo Jan Dijkema
dt_ctrl
Commits
281bd15b
Commit
281bd15b
authored
Aug 23, 2014
by
Jeroen Vreeken
Browse files
Cherry pick DC settings from sercos branch
parent
295c8add
Changes
3
Hide whitespace changes
Inline
Side-by-side
.gitignore
View file @
281bd15b
...
...
@@ -7,6 +7,7 @@
*.tab.h
*.yy.c
*.yy.h
*.il2c.c
*.log
*.lo
*.la
...
...
controller/ec/esc_esi.c
View file @
281bd15b
/*
Copyright (c) 2013,
Daan Vreeken <Daan @ Vitsch . nl> - Vitsch Electronics
Copyright Jeroen Vreeken (pe1rxq@amsat.org), 2013
Copyright Stichting C.A. Muller Radioastronomiestation, 2013
...
...
@@ -37,6 +39,8 @@
#include
<log/log.h>
#include
<controller/controller_sample.h>
#define MAX_RETRIES 1000
ssize_t
esc_esi_eeprom_read
(
struct
ec_dgram_addr
*
ec_addr
,
void
*
buffer
,
size_t
offset
,
size_t
size
)
{
...
...
@@ -46,24 +50,55 @@ ssize_t esc_esi_eeprom_read(struct ec_dgram_addr *ec_addr,
uint32_t
val32
;
int
wordsize
;
size_t
readsize
=
0
;
int
retry
=
0
;
/* See ET1100 pdf, chapter 11.2.2: Assignment to ECAT/PDI */
/* Request use of EEPROM by master (us) */
ec_addr
->
addr
.
position
.
off
=
ESC_ADDR_MAP_ESI_EEPROM_CONFIG
;
val8
=
ESC_ESI_EEPROM_CONFIG_REQUEST_ECAT
;
r
=
ec_datagram_write
(
ec_addr
,
&
val8
,
1
);
if
(
r
!=
1
)
return
-
1
;
/* Make sure ecat side has eeprom control */
ec_addr
->
addr
.
position
.
off
=
ESC_ADDR_MAP_ESI_EEPROM_PDI_STATE
;
do
{
ec_addr
->
addr
.
position
.
off
=
ESC_ADDR_MAP_ESI_EEPROM_CONFIG
;
r
=
ec_datagram_read
(
ec_addr
,
&
val8
,
1
);
if
(
val8
&
ESC_ESI_EEPROM_CONFIG_PDI
&&
r
==
1
)
{
uint8_t
resetval8
=
ESC_ESI_EEPROM_CONFIG_FORCE_ECAT
;
r
=
ec_datagram_write
(
ec_addr
,
&
resetval8
,
1
);
}
while
(
val8
==
ESC_ESI_EEPROM_PDI_BUSY
&&
r
==
1
&&
++
retry
<
MAX_RETRIES
);
if
(
r
!=
1
)
{
readsize
=
-
1
;
goto
err_out
;
}
if
(
retry
==
MAX_RETRIES
)
{
log_send
(
LOG_T_DEBUG
,
"esc_esi_eeprom_read: forcing the PDI "
"off the EEPROM bus"
);
/* Force the PDI off of the EEPROM bus */
ec_addr
->
addr
.
position
.
off
=
ESC_ADDR_MAP_ESI_EEPROM_CONFIG
;
val8
=
ESC_ESI_EEPROM_CONFIG_FORCE_ECAT
;
r
=
ec_datagram_write
(
ec_addr
,
&
val8
,
1
);
if
(
r
!=
1
)
{
readsize
=
-
1
;
goto
err_out
;
}
}
while
(
val8
&
ESC_ESI_EEPROM_CONFIG_PDI
&&
r
==
1
);
if
(
r
!=
1
)
return
-
1
;
/* Finish claiming the bus */
ec_addr
->
addr
.
position
.
off
=
ESC_ADDR_MAP_ESI_EEPROM_CONFIG
;
val8
=
ESC_ESI_EEPROM_CONFIG_REQUEST_ECAT
;
r
=
ec_datagram_write
(
ec_addr
,
&
val8
,
1
);
if
(
r
!=
1
)
{
readsize
=
-
1
;
goto
err_out
;
}
}
/* get status */
ec_addr
->
addr
.
position
.
off
=
ESC_ADDR_MAP_ESI_EEPROM_CONTROL_STATUS
;
r
=
ec_datagram_read
(
ec_addr
,
&
val16
,
2
);
if
(
r
!=
2
)
return
-
1
;
if
(
r
!=
2
)
{
readsize
=
-
1
;
goto
err_out
;
}
status
=
le16toh
(
val16
);
if
(
status
&
ESC_ESI_EEPROM_CONTROL_STATUS_READ_8B
)
{
...
...
@@ -102,7 +137,8 @@ ssize_t esc_esi_eeprom_read(struct ec_dgram_addr *ec_addr,
status
&
ESC_ESI_EEPROM_CONTROL_STATUS_NOT_LOADED
||
status
&
ESC_ESI_EEPROM_CONTROL_STATUS_ACK_ERR
||
status
&
ESC_ESI_EEPROM_CONTROL_STATUS_WRITE_ERR
)
{
return
-
1
;
readsize
=
-
1
;
goto
err_out
;
}
/* read data and copy to client buffer */
...
...
@@ -122,7 +158,14 @@ ssize_t esc_esi_eeprom_read(struct ec_dgram_addr *ec_addr,
buffer
+=
copysize
;
readsize
+=
copysize
;
}
err_out:
/* Give back the EEPROM to the PDI */
ec_addr
->
addr
.
position
.
off
=
ESC_ADDR_MAP_ESI_EEPROM_CONFIG
;
val8
=
ESC_ESI_EEPROM_CONFIG_PDI
;
/* if this fails all hope is lost for the PDI :) */
(
void
)
ec_datagram_write
(
ec_addr
,
&
val8
,
1
);
return
readsize
;
}
...
...
@@ -384,7 +427,6 @@ static int esc_esi_device_fill_dc(struct esc_device *dev)
factor0
=
le16toh
(
dc
->
cycle_time_sync0_factor
);
factor1
=
le16toh
(
dc
->
cycle_time_sync1_factor
);
/* what is the extra byte doing here??? */
activate
=
le16toh
(
dc
->
assign_activate
)
>>
8
;
cyclic
=
le16toh
(
dc
->
assign_activate
)
&
0xff
;
...
...
@@ -410,9 +452,6 @@ static int esc_esi_device_fill_dc(struct esc_device *dev)
else
latch1
=
false
;
/* lots of guessing here: */
// todo: is factor/cycle logic ok?
// todo: what is a negative factor?
if
(
sync_out
)
{
if
(
sync0
&&
!
cycle0
)
{
/* factor and cycle 0? */
...
...
@@ -421,8 +460,17 @@ static int esc_esi_device_fill_dc(struct esc_device *dev)
cycle0
=
period_cycle
*
factor0
;
}
if
(
sync1
&&
factor1
)
{
/* factor? */
shift1
=
cycle0
*
(
factor1
-
1
)
+
shift1
;
if
(
period_cycle
<
cycle0
)
{
log_send
(
LOG_T_WARNING
,
"Period cycle time is smaller than sync0 cycle time. %dns < %dns"
,
period_cycle
,
cycle0
);
}
if
(
factor1
<
0
)
{
shift1
=
(
period_cycle
*
-
factor1
);
shift1
-=
cycle0
;
}
else
{
shift1
=
cycle0
*
(
factor1
-
1
)
+
shift1
;
}
}
}
...
...
@@ -534,8 +582,9 @@ static int esc_esi_device_fill_pdo_cat(struct esc_device *dev,
esc_esi_category_strings_get
(
dev
->
categories
,
pdo
->
string
,
string
,
200
);
log_send
(
LOG_T_DEBUG
,
"
\t
PDO index: 0x%04x, sm: %d, entries: %d, name: %s"
,
le16toh
(
pdo
->
index
),
pdo
->
sm
,
entries
,
string
);
"
\t
PDO index: 0x%04x, sm: %d, entries: %d, name: %s, type: %s"
,
le16toh
(
pdo
->
index
),
pdo
->
sm
,
entries
,
string
,
cat
->
type
==
ESC_ESI_CATEGORY_PDO_RX
?
"RX"
:
"TX"
);
for
(
j
=
0
;
j
<
entries
&&
j
+
i
<
nr
;
j
++
)
{
pdo_entry
=
(
struct
esc_esi_pdo_entry
*
)(
pdo
+
1
+
j
);
...
...
@@ -552,10 +601,14 @@ static int esc_esi_device_fill_pdo_cat(struct esc_device *dev,
if
(
cat
->
type
==
ESC_ESI_CATEGORY_PDO_RX
)
{
dev
->
rx_pdo_sm
=
pdo
->
sm
;
dev
->
rx_pdo
=
true
;
log_send
(
LOG_T_DEBUG
,
"
\t
Using sm%d for rx pdo"
,
dev
->
rx_pdo_sm
);
}
if
(
cat
->
type
==
ESC_ESI_CATEGORY_PDO_TX
)
{
dev
->
tx_pdo_sm
=
pdo
->
sm
;
dev
->
tx_pdo
=
true
;
log_send
(
LOG_T_DEBUG
,
"
\t
Using sm%d for tx pdo"
,
dev
->
tx_pdo_sm
);
}
}
}
...
...
@@ -587,11 +640,8 @@ static int esc_esi_device_fill_pdo(struct esc_device *dev)
}
/*
This function will create a device structure and will
fill
initialize
This function will create a device structure and will initialize
it
according to the ESI data found on the device.
Upon return the rx/tx PDOs will be set, if present a mailbox has been
created, and the device is set to the pre-operational state.
*/
int
esc_esi_device_fill
(
struct
esc_device
*
dev
)
{
...
...
controller/ec/esc_registers.h
View file @
281bd15b
...
...
@@ -56,9 +56,12 @@
#define ESC_ADDR_MAP_WATCHDOG_COUNTER_PDI 0x0443
#define ESC_ADDR_MAP_ESI_EEPROM_CONFIG 0x0500
#define ESC_ESI_EEPROM_CONFIG_REQUEST_ECAT 0x00
#define ESC_ESI_EEPROM_CONFIG_PDI 0x01
#define ESC_ESI_EEPROM_CONFIG_FORCE_ECAT 0x02
#define ESC_ADDR_MAP_ESI_EEPROM_PDI_STATE 0x0501
#define ESC_ESI_EEPROM_PDI_BUSY 0x01
#define ESC_ESI_EEPROM_FREE 0x00
#define ESC_ADDR_MAP_ESI_EEPROM_CONTROL_STATUS 0x0502
#define ESC_ESI_EEPROM_CONTROL_STATUS_READ_8B 0x0001
#define ESC_ESI_EEPROM_CONTROL_STATUS_CMD_READ 0x0100
...
...
Write
Preview
Supports
Markdown
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