00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00034
00035
00036 #include "globals.h"
00037 #include "slave.h"
00038 #include "master.h"
00039 #include "pdo.h"
00040 #include "sync.h"
00041
00042
00043
00046 void ec_sync_init(
00047 ec_sync_t *sync,
00048 ec_slave_t *slave
00049 )
00050 {
00051 sync->slave = slave;
00052 sync->physical_start_address = 0x0000;
00053 sync->default_length = 0x0000;
00054 sync->control_register = 0x00;
00055 sync->enable = 0x00;
00056 ec_pdo_list_init(&sync->pdos);
00057 }
00058
00059
00060
00063 void ec_sync_init_copy(
00064 ec_sync_t *sync,
00065 const ec_sync_t *other
00066 )
00067 {
00068 sync->slave = other->slave;
00069 sync->physical_start_address = other->physical_start_address;
00070 sync->default_length = other->default_length;
00071 sync->control_register = other->control_register;
00072 sync->enable = other->enable;
00073 ec_pdo_list_init(&sync->pdos);
00074 ec_pdo_list_copy(&sync->pdos, &other->pdos);
00075 }
00076
00077
00078
00081 void ec_sync_clear(
00082 ec_sync_t *sync
00083 )
00084 {
00085 ec_pdo_list_clear(&sync->pdos);
00086 }
00087
00088
00089
00094 void ec_sync_page(
00095 const ec_sync_t *sync,
00096 uint8_t sync_index,
00097 uint16_t data_size,
00098 const ec_sync_config_t *sync_config,
00099 uint8_t pdo_xfer,
00101 uint8_t *data
00102 )
00103 {
00104
00105
00106 uint16_t enable = ((sync->enable & 0x01) || pdo_xfer)
00107 && data_size
00108 && ((sync->enable & 0x04) == 0);
00109 uint8_t control = sync->control_register;
00110
00111 if (sync_config) {
00112
00113 switch (sync_config->dir) {
00114 case EC_DIR_OUTPUT:
00115 case EC_DIR_INPUT:
00116 EC_WRITE_BIT(&control, 2,
00117 sync_config->dir == EC_DIR_OUTPUT ? 1 : 0);
00118 EC_WRITE_BIT(&control, 3, 0);
00119 break;
00120 default:
00121 break;
00122 }
00123
00124 switch (sync_config->watchdog_mode) {
00125 case EC_WD_ENABLE:
00126 case EC_WD_DISABLE:
00127 EC_WRITE_BIT(&control, 6,
00128 sync_config->watchdog_mode == EC_WD_ENABLE);
00129 break;
00130 default:
00131 break;
00132 }
00133 }
00134
00135 EC_SLAVE_DBG(sync->slave, 1, "SM%u: Addr 0x%04X, Size %3u,"
00136 " Ctrl 0x%02X, En %u\n",
00137 sync_index, sync->physical_start_address,
00138 data_size, control, enable);
00139
00140 EC_WRITE_U16(data, sync->physical_start_address);
00141 EC_WRITE_U16(data + 2, data_size);
00142 EC_WRITE_U8 (data + 4, control);
00143 EC_WRITE_U8 (data + 5, 0x00);
00144 EC_WRITE_U16(data + 6, enable);
00145 }
00146
00147
00148
00153 int ec_sync_add_pdo(
00154 ec_sync_t *sync,
00155 const ec_pdo_t *pdo
00156 )
00157 {
00158 return ec_pdo_list_add_pdo_copy(&sync->pdos, pdo);
00159 }
00160
00161
00162
00167 ec_direction_t ec_sync_default_direction(
00168 const ec_sync_t *sync
00169 )
00170 {
00171 switch ((sync->control_register & 0x0C) >> 2) {
00172 case 0x0: return EC_DIR_INPUT;
00173 case 0x1: return EC_DIR_OUTPUT;
00174 default: return EC_DIR_INVALID;
00175 }
00176 }
00177
00178