Newer
Older
Florian Pose
committed
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
size_t *size /**< Datengre des Puffers, spter
Gre der gelesenen Daten */
)
{
ec_command_t command;
size_t data_size;
cycles_t start, end, timeout;
// Read "written bit" of Sync-Manager
start = get_cycles();
timeout = (cycles_t) 100 * cpu_khz; // 100ms
while (1)
{
ec_command_init_nprd(&command, slave->station_address, 0x808, 8);
if (unlikely(ec_master_simple_io(slave->master, &command))) {
EC_ERR("Mailbox checking failed on slave %i!\n",
slave->ring_position);
return -1;
}
end = get_cycles();
if (EC_READ_U8(command.data + 5) & 8) break; // Written bit is high
if ((end - start) >= timeout) {
EC_ERR("Mailbox check - Slave %i timed out.\n",
slave->ring_position);
return -1;
}
udelay(100);
}
if (unlikely(slave->master->debug_level) > 1)
EC_DBG("SDO download took %ius.\n", ((u32) (end - start) * 1000
/ cpu_khz));
ec_command_init_nprd(&command, slave->station_address, 0x18F6, 0xF6);
if (unlikely(ec_master_simple_io(slave->master, &command))) {
EC_ERR("Mailbox receiving failed on slave %i!\n",
slave->ring_position);
return -1;
}
if (EC_READ_U8(command.data + 5) != type) { // nicht CoE
EC_ERR("Invalid mailbox response (non-CoE) at slave %i!\n",
slave->ring_position);
return -1;
}
if ((data_size = EC_READ_U16(command.data)) > *size) {
EC_ERR("CoE data does not fit in buffer (%i > %i).\n",
data_size, *size);
return -1;
}
memcpy(prot_data, command.data + 6, data_size);
*size = data_size;
return 0;
}
/*****************************************************************************/
/* Emacs-Konfiguration
;;; Local Variables: ***
Florian Pose
committed
;;; c-basic-offset:4 ***