master/master.c
changeset 1312 74853e018898
parent 1303 448f2e9fa483
child 1313 ed15eef57d5c
equal deleted inserted replaced
1311:bf7c62bc533f 1312:74853e018898
  1298 
  1298 
  1299 /******************************************************************************
  1299 /******************************************************************************
  1300  *  Realtime interface
  1300  *  Realtime interface
  1301  *****************************************************************************/
  1301  *****************************************************************************/
  1302 
  1302 
  1303 ec_domain_t *ecrt_master_create_domain(ec_master_t *master /**< master */)
  1303 ec_domain_t *ecrt_master_create_domain_err(
       
  1304         ec_master_t *master /**< master */
       
  1305         )
  1304 {
  1306 {
  1305     ec_domain_t *domain, *last_domain;
  1307     ec_domain_t *domain, *last_domain;
  1306     unsigned int index;
  1308     unsigned int index;
  1307 
  1309 
  1308     if (master->debug_level)
  1310     if (master->debug_level)
  1309         EC_DBG("ecrt_master_create_domain(master = 0x%x)\n", (u32) master);
  1311         EC_DBG("ecrt_master_create_domain(master = 0x%x)\n", (u32) master);
  1310 
  1312 
  1311     if (!(domain = (ec_domain_t *) kmalloc(sizeof(ec_domain_t), GFP_KERNEL))) {
  1313     if (!(domain = (ec_domain_t *) kmalloc(sizeof(ec_domain_t), GFP_KERNEL))) {
  1312         EC_ERR("Error allocating domain memory!\n");
  1314         EC_ERR("Error allocating domain memory!\n");
  1313         return NULL;
  1315         return ERR_PTR(-ENOMEM);
  1314     }
  1316     }
  1315 
  1317 
  1316     down(&master->master_sem);
  1318     down(&master->master_sem);
  1317 
  1319 
  1318     if (list_empty(&master->domains)) {
  1320     if (list_empty(&master->domains)) {
  1329 
  1331 
  1330     if (master->debug_level)
  1332     if (master->debug_level)
  1331         EC_DBG("Created domain %u.\n", domain->index);
  1333         EC_DBG("Created domain %u.\n", domain->index);
  1332 
  1334 
  1333     return domain;
  1335     return domain;
       
  1336 }
       
  1337 
       
  1338 /*****************************************************************************/
       
  1339 
       
  1340 ec_domain_t *ecrt_master_create_domain(
       
  1341         ec_master_t *master /**< master */
       
  1342         )
       
  1343 {
       
  1344     ec_domain_t *d = ecrt_master_create_domain_err(master);
       
  1345     return IS_ERR(d) ? NULL : d;
  1334 }
  1346 }
  1335 
  1347 
  1336 /*****************************************************************************/
  1348 /*****************************************************************************/
  1337 
  1349 
  1338 int ecrt_master_activate(ec_master_t *master)
  1350 int ecrt_master_activate(ec_master_t *master)
  1460     master->frames_timed_out = frames_timed_out;
  1472     master->frames_timed_out = frames_timed_out;
  1461 }
  1473 }
  1462 
  1474 
  1463 /*****************************************************************************/
  1475 /*****************************************************************************/
  1464 
  1476 
  1465 ec_slave_config_t *ecrt_master_slave_config(ec_master_t *master,
  1477 ec_slave_config_t *ecrt_master_slave_config_err(ec_master_t *master,
  1466         uint16_t alias, uint16_t position, uint32_t vendor_id,
  1478         uint16_t alias, uint16_t position, uint32_t vendor_id,
  1467         uint32_t product_code)
  1479         uint32_t product_code)
  1468 {
  1480 {
  1469     ec_slave_config_t *sc;
  1481     ec_slave_config_t *sc;
  1470     unsigned int found = 0;
  1482     unsigned int found = 0;
  1486         if (sc->vendor_id != vendor_id || sc->product_code != product_code) {
  1498         if (sc->vendor_id != vendor_id || sc->product_code != product_code) {
  1487             EC_ERR("Slave type mismatch. Slave was configured as"
  1499             EC_ERR("Slave type mismatch. Slave was configured as"
  1488                     " 0x%08X/0x%08X before. Now configuring with"
  1500                     " 0x%08X/0x%08X before. Now configuring with"
  1489                     " 0x%08X/0x%08X.\n", sc->vendor_id, sc->product_code,
  1501                     " 0x%08X/0x%08X.\n", sc->vendor_id, sc->product_code,
  1490                     vendor_id, product_code);
  1502                     vendor_id, product_code);
  1491             return NULL;
  1503             return ERR_PTR(-ENOENT);
  1492         }
  1504         }
  1493     } else {
  1505     } else {
  1494         if (master->debug_level)
  1506         if (master->debug_level)
  1495             EC_DBG("Creating slave configuration for %u:%u, 0x%08X/0x%08X.\n",
  1507             EC_DBG("Creating slave configuration for %u:%u, 0x%08X/0x%08X.\n",
  1496                     alias, position, vendor_id, product_code);
  1508                     alias, position, vendor_id, product_code);
  1497 
  1509 
  1498         if (!(sc = (ec_slave_config_t *) kmalloc(sizeof(ec_slave_config_t),
  1510         if (!(sc = (ec_slave_config_t *) kmalloc(sizeof(ec_slave_config_t),
  1499                         GFP_KERNEL))) {
  1511                         GFP_KERNEL))) {
  1500             EC_ERR("Failed to allocate memory for slave configuration.\n");
  1512             EC_ERR("Failed to allocate memory for slave configuration.\n");
  1501             return NULL;
  1513             return ERR_PTR(-ENOMEM);
  1502         }
  1514         }
  1503 
  1515 
  1504         ec_slave_config_init(sc, master,
  1516         ec_slave_config_init(sc, master,
  1505                 alias, position, vendor_id, product_code);
  1517                 alias, position, vendor_id, product_code);
  1506 
  1518 
  1513 
  1525 
  1514         up(&master->master_sem);
  1526         up(&master->master_sem);
  1515     }
  1527     }
  1516 
  1528 
  1517     return sc;
  1529     return sc;
       
  1530 }
       
  1531 
       
  1532 /*****************************************************************************/
       
  1533 
       
  1534 ec_slave_config_t *ecrt_master_slave_config(ec_master_t *master,
       
  1535         uint16_t alias, uint16_t position, uint32_t vendor_id,
       
  1536         uint32_t product_code)
       
  1537 {
       
  1538     ec_slave_config_t *sc = ecrt_master_slave_config_err(master, alias,
       
  1539             position, vendor_id, product_code);
       
  1540     return IS_ERR(sc) ? NULL : sc;
  1518 }
  1541 }
  1519 
  1542 
  1520 /*****************************************************************************/
  1543 /*****************************************************************************/
  1521 
  1544 
  1522 void ecrt_master_callbacks(ec_master_t *master, int (*request_cb)(void *),
  1545 void ecrt_master_callbacks(ec_master_t *master, int (*request_cb)(void *),