819 // check, if the datagram is already queued |
819 // check, if the datagram is already queued |
820 list_for_each_entry(queued_datagram, &master->datagram_queue, queue) { |
820 list_for_each_entry(queued_datagram, &master->datagram_queue, queue) { |
821 if (queued_datagram == datagram) { |
821 if (queued_datagram == datagram) { |
822 datagram->skip_count++; |
822 datagram->skip_count++; |
823 if (master->debug_level) |
823 if (master->debug_level) |
824 EC_DBG("skipping datagram %x.\n", (unsigned int) datagram); |
824 EC_DBG("skipping datagram %p.\n", datagram); |
825 datagram->state = EC_DATAGRAM_QUEUED; |
825 datagram->state = EC_DATAGRAM_QUEUED; |
826 return; |
826 return; |
827 } |
827 } |
828 } |
828 } |
829 |
829 |
932 // pad frame |
932 // pad frame |
933 while (cur_data - frame_data < ETH_ZLEN - ETH_HLEN) |
933 while (cur_data - frame_data < ETH_ZLEN - ETH_HLEN) |
934 EC_WRITE_U8(cur_data++, 0x00); |
934 EC_WRITE_U8(cur_data++, 0x00); |
935 |
935 |
936 if (unlikely(master->debug_level > 1)) |
936 if (unlikely(master->debug_level > 1)) |
937 EC_DBG("frame size: %u\n", cur_data - frame_data); |
937 EC_DBG("frame size: %zu\n", cur_data - frame_data); |
938 |
938 |
939 // send frame |
939 // send frame |
940 ec_device_send(&master->main_device, cur_data - frame_data); |
940 ec_device_send(&master->main_device, cur_data - frame_data); |
941 #ifdef EC_HAVE_CYCLES |
941 #ifdef EC_HAVE_CYCLES |
942 cycles_sent = get_cycles(); |
942 cycles_sent = get_cycles(); |
986 const uint8_t *cur_data; |
986 const uint8_t *cur_data; |
987 ec_datagram_t *datagram; |
987 ec_datagram_t *datagram; |
988 |
988 |
989 if (unlikely(size < EC_FRAME_HEADER_SIZE)) { |
989 if (unlikely(size < EC_FRAME_HEADER_SIZE)) { |
990 if (master->debug_level) { |
990 if (master->debug_level) { |
991 EC_DBG("Corrupted frame received (size %u < %u byte):\n", |
991 EC_DBG("Corrupted frame received (size %zu < %u byte):\n", |
992 size, EC_FRAME_HEADER_SIZE); |
992 size, EC_FRAME_HEADER_SIZE); |
993 ec_print_data(frame_data, size); |
993 ec_print_data(frame_data, size); |
994 } |
994 } |
995 master->stats.corrupted++; |
995 master->stats.corrupted++; |
996 ec_master_output_stats(master); |
996 ec_master_output_stats(master); |
1003 frame_size = EC_READ_U16(cur_data) & 0x07FF; |
1003 frame_size = EC_READ_U16(cur_data) & 0x07FF; |
1004 cur_data += EC_FRAME_HEADER_SIZE; |
1004 cur_data += EC_FRAME_HEADER_SIZE; |
1005 |
1005 |
1006 if (unlikely(frame_size > size)) { |
1006 if (unlikely(frame_size > size)) { |
1007 if (master->debug_level) { |
1007 if (master->debug_level) { |
1008 EC_DBG("Corrupted frame received (invalid frame size %u for " |
1008 EC_DBG("Corrupted frame received (invalid frame size %zu for " |
1009 "received size %u):\n", frame_size, size); |
1009 "received size %zu):\n", frame_size, size); |
1010 ec_print_data(frame_data, size); |
1010 ec_print_data(frame_data, size); |
1011 } |
1011 } |
1012 master->stats.corrupted++; |
1012 master->stats.corrupted++; |
1013 ec_master_output_stats(master); |
1013 ec_master_output_stats(master); |
1014 return; |
1014 return; |
1024 cur_data += EC_DATAGRAM_HEADER_SIZE; |
1024 cur_data += EC_DATAGRAM_HEADER_SIZE; |
1025 |
1025 |
1026 if (unlikely(cur_data - frame_data |
1026 if (unlikely(cur_data - frame_data |
1027 + data_size + EC_DATAGRAM_FOOTER_SIZE > size)) { |
1027 + data_size + EC_DATAGRAM_FOOTER_SIZE > size)) { |
1028 if (master->debug_level) { |
1028 if (master->debug_level) { |
1029 EC_DBG("Corrupted frame received (invalid data size %u):\n", |
1029 EC_DBG("Corrupted frame received (invalid data size %zu):\n", |
1030 data_size); |
1030 data_size); |
1031 ec_print_data(frame_data, size); |
1031 ec_print_data(frame_data, size); |
1032 } |
1032 } |
1033 master->stats.corrupted++; |
1033 master->stats.corrupted++; |
1034 ec_master_output_stats(master); |
1034 ec_master_output_stats(master); |
1801 { |
1801 { |
1802 ec_domain_t *domain, *last_domain; |
1802 ec_domain_t *domain, *last_domain; |
1803 unsigned int index; |
1803 unsigned int index; |
1804 |
1804 |
1805 if (master->debug_level) |
1805 if (master->debug_level) |
1806 EC_DBG("ecrt_master_create_domain(master = 0x%x)\n", (u32) master); |
1806 EC_DBG("ecrt_master_create_domain(master = 0x%p)\n", master); |
1807 |
1807 |
1808 if (!(domain = (ec_domain_t *) kmalloc(sizeof(ec_domain_t), GFP_KERNEL))) { |
1808 if (!(domain = (ec_domain_t *) kmalloc(sizeof(ec_domain_t), GFP_KERNEL))) { |
1809 EC_ERR("Error allocating domain memory!\n"); |
1809 EC_ERR("Error allocating domain memory!\n"); |
1810 return ERR_PTR(-ENOMEM); |
1810 return ERR_PTR(-ENOMEM); |
1811 } |
1811 } |
1847 uint32_t domain_offset; |
1847 uint32_t domain_offset; |
1848 ec_domain_t *domain; |
1848 ec_domain_t *domain; |
1849 int ret; |
1849 int ret; |
1850 |
1850 |
1851 if (master->debug_level) |
1851 if (master->debug_level) |
1852 EC_DBG("ecrt_master_activate(master = 0x%x)\n", (u32) master); |
1852 EC_DBG("ecrt_master_activate(master = 0x%p)\n", master); |
1853 |
1853 |
1854 if (master->active) { |
1854 if (master->active) { |
1855 EC_WARN("%s: Master already active!\n", __func__); |
1855 EC_WARN("%s: Master already active!\n", __func__); |
1856 return 0; |
1856 return 0; |
1857 } |
1857 } |
1862 domain_offset = 0; |
1862 domain_offset = 0; |
1863 list_for_each_entry(domain, &master->domains, list) { |
1863 list_for_each_entry(domain, &master->domains, list) { |
1864 ret = ec_domain_finish(domain, domain_offset); |
1864 ret = ec_domain_finish(domain, domain_offset); |
1865 if (ret < 0) { |
1865 if (ret < 0) { |
1866 up(&master->master_sem); |
1866 up(&master->master_sem); |
1867 EC_ERR("Failed to finish domain 0x%08X!\n", (u32) domain); |
1867 EC_ERR("Failed to finish domain 0x%p!\n", domain); |
1868 return ret; |
1868 return ret; |
1869 } |
1869 } |
1870 domain_offset += domain->data_size; |
1870 domain_offset += domain->data_size; |
1871 } |
1871 } |
1872 |
1872 |
1882 ec_master_eoe_stop(master); |
1882 ec_master_eoe_stop(master); |
1883 #endif |
1883 #endif |
1884 ec_master_thread_stop(master); |
1884 ec_master_thread_stop(master); |
1885 |
1885 |
1886 if (master->debug_level) |
1886 if (master->debug_level) |
1887 EC_DBG("FSM datagram is %x.\n", (unsigned int) &master->fsm_datagram); |
1887 EC_DBG("FSM datagram is %p.\n", &master->fsm_datagram); |
1888 |
1888 |
1889 master->injection_seq_fsm = 0; |
1889 master->injection_seq_fsm = 0; |
1890 master->injection_seq_rt = 0; |
1890 master->injection_seq_rt = 0; |
1891 |
1891 |
1892 master->send_cb = master->app_send_cb; |
1892 master->send_cb = master->app_send_cb; |
2040 datagram->cycles_sent) * 1000 / cpu_khz; |
2040 datagram->cycles_sent) * 1000 / cpu_khz; |
2041 #else |
2041 #else |
2042 time_us = (unsigned int) ((master->main_device.jiffies_poll - |
2042 time_us = (unsigned int) ((master->main_device.jiffies_poll - |
2043 datagram->jiffies_sent) * 1000000 / HZ); |
2043 datagram->jiffies_sent) * 1000000 / HZ); |
2044 #endif |
2044 #endif |
2045 EC_DBG("TIMED OUT datagram %08x, index %02X waited %u us.\n", |
2045 EC_DBG("TIMED OUT datagram %p, index %02X waited %u us.\n", |
2046 (unsigned int) datagram, datagram->index, time_us); |
2046 datagram, datagram->index, time_us); |
2047 } |
2047 } |
2048 } |
2048 } |
2049 } |
2049 } |
2050 |
2050 |
2051 master->frames_timed_out = frames_timed_out; |
2051 master->frames_timed_out = frames_timed_out; |
2077 ec_slave_config_t *sc; |
2077 ec_slave_config_t *sc; |
2078 unsigned int found = 0; |
2078 unsigned int found = 0; |
2079 |
2079 |
2080 |
2080 |
2081 if (master->debug_level) |
2081 if (master->debug_level) |
2082 EC_DBG("ecrt_master_slave_config(master = 0x%x, alias = %u, " |
2082 EC_DBG("ecrt_master_slave_config(master = 0x%p, alias = %u, " |
2083 "position = %u, vendor_id = 0x%08x, product_code = 0x%08x)\n", |
2083 "position = %u, vendor_id = 0x%08x, product_code = 0x%08x)\n", |
2084 (u32) master, alias, position, vendor_id, product_code); |
2084 master, alias, position, vendor_id, product_code); |
2085 |
2085 |
2086 list_for_each_entry(sc, &master->configs, list) { |
2086 list_for_each_entry(sc, &master->configs, list) { |
2087 if (sc->alias == alias && sc->position == position) { |
2087 if (sc->alias == alias && sc->position == position) { |
2088 found = 1; |
2088 found = 1; |
2089 break; |
2089 break; |
2140 |
2140 |
2141 void ecrt_master_callbacks(ec_master_t *master, |
2141 void ecrt_master_callbacks(ec_master_t *master, |
2142 void (*send_cb)(void *), void (*receive_cb)(void *), void *cb_data) |
2142 void (*send_cb)(void *), void (*receive_cb)(void *), void *cb_data) |
2143 { |
2143 { |
2144 if (master->debug_level) |
2144 if (master->debug_level) |
2145 EC_DBG("ecrt_master_callbacks(master = 0x%x, send_cb = 0x%x, " |
2145 EC_DBG("ecrt_master_callbacks(master = 0x%p, send_cb = 0x%p, " |
2146 " receive_cb = 0x%x, cb_data = 0x%x)\n", (u32) master, |
2146 " receive_cb = 0x%p, cb_data = 0x%p)\n", master, |
2147 (u32) send_cb, (u32) receive_cb, (u32) cb_data); |
2147 send_cb, receive_cb, cb_data); |
2148 |
2148 |
2149 master->app_send_cb = send_cb; |
2149 master->app_send_cb = send_cb; |
2150 master->app_receive_cb = receive_cb; |
2150 master->app_receive_cb = receive_cb; |
2151 master->app_cb_data = cb_data; |
2151 master->app_cb_data = cb_data; |
2152 } |
2152 } |