master/master.c
changeset 1543 373cd456dc26
parent 1516 e3b09f847512
child 1544 cfcaf46c5b3f
equal deleted inserted replaced
1528:dbc617badc33 1543:373cd456dc26
   669     // check, if the datagram is already queued
   669     // check, if the datagram is already queued
   670     list_for_each_entry(queued_datagram, &master->datagram_queue, queue) {
   670     list_for_each_entry(queued_datagram, &master->datagram_queue, queue) {
   671         if (queued_datagram == datagram) {
   671         if (queued_datagram == datagram) {
   672             datagram->skip_count++;
   672             datagram->skip_count++;
   673             if (master->debug_level)
   673             if (master->debug_level)
   674                 EC_DBG("skipping datagram %x.\n", (unsigned int) datagram);
   674                 EC_DBG("skipping datagram %p.\n", datagram);
   675             datagram->state = EC_DATAGRAM_QUEUED;
   675             datagram->state = EC_DATAGRAM_QUEUED;
   676             return;
   676             return;
   677         }
   677         }
   678     }
   678     }
   679 
   679 
   783         // pad frame
   783         // pad frame
   784         while (cur_data - frame_data < ETH_ZLEN - ETH_HLEN)
   784         while (cur_data - frame_data < ETH_ZLEN - ETH_HLEN)
   785             EC_WRITE_U8(cur_data++, 0x00);
   785             EC_WRITE_U8(cur_data++, 0x00);
   786 
   786 
   787         if (unlikely(master->debug_level > 1))
   787         if (unlikely(master->debug_level > 1))
   788             EC_DBG("frame size: %u\n", cur_data - frame_data);
   788             EC_DBG("frame size: %zu\n", cur_data - frame_data);
   789 
   789 
   790         // send frame
   790         // send frame
   791         ec_device_send(&master->main_device, cur_data - frame_data);
   791         ec_device_send(&master->main_device, cur_data - frame_data);
   792 #ifdef EC_HAVE_CYCLES
   792 #ifdef EC_HAVE_CYCLES
   793         cycles_sent = get_cycles();
   793         cycles_sent = get_cycles();
   837     const uint8_t *cur_data;
   837     const uint8_t *cur_data;
   838     ec_datagram_t *datagram;
   838     ec_datagram_t *datagram;
   839 
   839 
   840     if (unlikely(size < EC_FRAME_HEADER_SIZE)) {
   840     if (unlikely(size < EC_FRAME_HEADER_SIZE)) {
   841         if (master->debug_level) {
   841         if (master->debug_level) {
   842             EC_DBG("Corrupted frame received (size %u < %u byte):\n",
   842             EC_DBG("Corrupted frame received (size %zu < %u byte):\n",
   843                     size, EC_FRAME_HEADER_SIZE);
   843                     size, EC_FRAME_HEADER_SIZE);
   844             ec_print_data(frame_data, size);
   844             ec_print_data(frame_data, size);
   845         }
   845         }
   846         master->stats.corrupted++;
   846         master->stats.corrupted++;
   847         ec_master_output_stats(master);
   847         ec_master_output_stats(master);
   854     frame_size = EC_READ_U16(cur_data) & 0x07FF;
   854     frame_size = EC_READ_U16(cur_data) & 0x07FF;
   855     cur_data += EC_FRAME_HEADER_SIZE;
   855     cur_data += EC_FRAME_HEADER_SIZE;
   856 
   856 
   857     if (unlikely(frame_size > size)) {
   857     if (unlikely(frame_size > size)) {
   858         if (master->debug_level) {
   858         if (master->debug_level) {
   859             EC_DBG("Corrupted frame received (invalid frame size %u for "
   859             EC_DBG("Corrupted frame received (invalid frame size %zu for "
   860                     "received size %u):\n", frame_size, size);
   860                     "received size %zu):\n", frame_size, size);
   861             ec_print_data(frame_data, size);
   861             ec_print_data(frame_data, size);
   862         }
   862         }
   863         master->stats.corrupted++;
   863         master->stats.corrupted++;
   864         ec_master_output_stats(master);
   864         ec_master_output_stats(master);
   865         return;
   865         return;
   875         cur_data += EC_DATAGRAM_HEADER_SIZE;
   875         cur_data += EC_DATAGRAM_HEADER_SIZE;
   876 
   876 
   877         if (unlikely(cur_data - frame_data
   877         if (unlikely(cur_data - frame_data
   878                      + data_size + EC_DATAGRAM_FOOTER_SIZE > size)) {
   878                      + data_size + EC_DATAGRAM_FOOTER_SIZE > size)) {
   879             if (master->debug_level) {
   879             if (master->debug_level) {
   880                 EC_DBG("Corrupted frame received (invalid data size %u):\n",
   880                 EC_DBG("Corrupted frame received (invalid data size %zu):\n",
   881                         data_size);
   881                         data_size);
   882                 ec_print_data(frame_data, size);
   882                 ec_print_data(frame_data, size);
   883             }
   883             }
   884             master->stats.corrupted++;
   884             master->stats.corrupted++;
   885             ec_master_output_stats(master);
   885             ec_master_output_stats(master);
  1585 {
  1585 {
  1586     ec_domain_t *domain, *last_domain;
  1586     ec_domain_t *domain, *last_domain;
  1587     unsigned int index;
  1587     unsigned int index;
  1588 
  1588 
  1589     if (master->debug_level)
  1589     if (master->debug_level)
  1590         EC_DBG("ecrt_master_create_domain(master = 0x%x)\n", (u32) master);
  1590         EC_DBG("ecrt_master_create_domain(master = 0x%p)\n", master);
  1591 
  1591 
  1592     if (!(domain = (ec_domain_t *) kmalloc(sizeof(ec_domain_t), GFP_KERNEL))) {
  1592     if (!(domain = (ec_domain_t *) kmalloc(sizeof(ec_domain_t), GFP_KERNEL))) {
  1593         EC_ERR("Error allocating domain memory!\n");
  1593         EC_ERR("Error allocating domain memory!\n");
  1594         return ERR_PTR(-ENOMEM);
  1594         return ERR_PTR(-ENOMEM);
  1595     }
  1595     }
  1631     uint32_t domain_offset;
  1631     uint32_t domain_offset;
  1632     ec_domain_t *domain;
  1632     ec_domain_t *domain;
  1633     int ret;
  1633     int ret;
  1634 
  1634 
  1635     if (master->debug_level)
  1635     if (master->debug_level)
  1636         EC_DBG("ecrt_master_activate(master = 0x%x)\n", (u32) master);
  1636         EC_DBG("ecrt_master_activate(master = 0x%p)\n", master);
  1637 
  1637 
  1638     down(&master->master_sem);
  1638     down(&master->master_sem);
  1639 
  1639 
  1640     // finish all domains
  1640     // finish all domains
  1641     domain_offset = 0;
  1641     domain_offset = 0;
  1642     list_for_each_entry(domain, &master->domains, list) {
  1642     list_for_each_entry(domain, &master->domains, list) {
  1643         ret = ec_domain_finish(domain, domain_offset);
  1643         ret = ec_domain_finish(domain, domain_offset);
  1644         if (ret < 0) {
  1644         if (ret < 0) {
  1645             up(&master->master_sem);
  1645             up(&master->master_sem);
  1646             EC_ERR("Failed to finish domain 0x%08X!\n", (u32) domain);
  1646             EC_ERR("Failed to finish domain 0x%p!\n", domain);
  1647             return ret;
  1647             return ret;
  1648         }
  1648         }
  1649         domain_offset += domain->data_size;
  1649         domain_offset += domain->data_size;
  1650     }
  1650     }
  1651     
  1651     
  1661     ec_master_eoe_stop(master);
  1661     ec_master_eoe_stop(master);
  1662 #endif
  1662 #endif
  1663     ec_master_thread_stop(master);
  1663     ec_master_thread_stop(master);
  1664 
  1664 
  1665     if (master->debug_level)
  1665     if (master->debug_level)
  1666         EC_DBG("FSM datagram is %x.\n", (unsigned int) &master->fsm_datagram);
  1666         EC_DBG("FSM datagram is %p.\n", &master->fsm_datagram);
  1667 
  1667 
  1668     master->injection_seq_fsm = 0;
  1668     master->injection_seq_fsm = 0;
  1669     master->injection_seq_rt = 0;
  1669     master->injection_seq_rt = 0;
  1670 
  1670 
  1671     master->send_cb = master->app_send_cb;
  1671     master->send_cb = master->app_send_cb;
  1749                         datagram->cycles_sent) * 1000 / cpu_khz;
  1749                         datagram->cycles_sent) * 1000 / cpu_khz;
  1750 #else
  1750 #else
  1751                 time_us = (unsigned int) ((master->main_device.jiffies_poll -
  1751                 time_us = (unsigned int) ((master->main_device.jiffies_poll -
  1752                             datagram->jiffies_sent) * 1000000 / HZ);
  1752                             datagram->jiffies_sent) * 1000000 / HZ);
  1753 #endif
  1753 #endif
  1754                 EC_DBG("TIMED OUT datagram %08x, index %02X waited %u us.\n",
  1754                 EC_DBG("TIMED OUT datagram %p, index %02X waited %u us.\n",
  1755                         (unsigned int) datagram, datagram->index, time_us);
  1755                         datagram, datagram->index, time_us);
  1756             }
  1756             }
  1757         }
  1757         }
  1758     }
  1758     }
  1759 
  1759 
  1760     master->frames_timed_out = frames_timed_out;
  1760     master->frames_timed_out = frames_timed_out;
  1786     ec_slave_config_t *sc;
  1786     ec_slave_config_t *sc;
  1787     unsigned int found = 0;
  1787     unsigned int found = 0;
  1788 
  1788 
  1789 
  1789 
  1790     if (master->debug_level)
  1790     if (master->debug_level)
  1791         EC_DBG("ecrt_master_slave_config(master = 0x%x, alias = %u, "
  1791         EC_DBG("ecrt_master_slave_config(master = 0x%p, alias = %u, "
  1792                 "position = %u, vendor_id = 0x%08x, product_code = 0x%08x)\n",
  1792                 "position = %u, vendor_id = 0x%08x, product_code = 0x%08x)\n",
  1793                 (u32) master, alias, position, vendor_id, product_code);
  1793                 master, alias, position, vendor_id, product_code);
  1794 
  1794 
  1795     list_for_each_entry(sc, &master->configs, list) {
  1795     list_for_each_entry(sc, &master->configs, list) {
  1796         if (sc->alias == alias && sc->position == position) {
  1796         if (sc->alias == alias && sc->position == position) {
  1797             found = 1;
  1797             found = 1;
  1798             break;
  1798             break;
  1849 
  1849 
  1850 void ecrt_master_callbacks(ec_master_t *master,
  1850 void ecrt_master_callbacks(ec_master_t *master,
  1851         void (*send_cb)(void *), void (*receive_cb)(void *), void *cb_data)
  1851         void (*send_cb)(void *), void (*receive_cb)(void *), void *cb_data)
  1852 {
  1852 {
  1853     if (master->debug_level)
  1853     if (master->debug_level)
  1854         EC_DBG("ecrt_master_callbacks(master = 0x%x, send_cb = 0x%x, "
  1854         EC_DBG("ecrt_master_callbacks(master = 0x%p, send_cb = 0x%p, "
  1855                 " receive_cb = 0x%x, cb_data = 0x%x)\n", (u32) master,
  1855                 " receive_cb = 0x%p, cb_data = 0x%p)\n", master,
  1856                 (u32) send_cb, (u32) receive_cb, (u32) cb_data);
  1856                 send_cb, receive_cb, cb_data);
  1857 
  1857 
  1858     master->app_send_cb = send_cb;
  1858     master->app_send_cb = send_cb;
  1859     master->app_receive_cb = receive_cb;
  1859     master->app_receive_cb = receive_cb;
  1860     master->app_cb_data = cb_data;
  1860     master->app_cb_data = cb_data;
  1861 }
  1861 }