Skip to content

Commit

Permalink
Merge pull request OpenEtherCATsociety#187 from lounick/rtems5-integr…
Browse files Browse the repository at this point in the history
…ation

Rtems5 integration
  • Loading branch information
hefloryd authored Jul 10, 2018
2 parents b1e4b6c + 9421750 commit 5b2c51b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
10 changes: 7 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ endif()

set(SOEM_INCLUDE_INSTALL_DIR include/soem)
set(SOEM_LIB_INSTALL_DIR lib)
set(BUILD_TESTS TRUE)

if(WIN32)
set(OS "win32")
Expand Down Expand Up @@ -41,6 +42,7 @@ elseif(${CMAKE_SYSTEM_NAME} MATCHES "rtems")
message("Building for RTEMS")
set(OS "rtems")
set(SOEM_LIB_INSTALL_DIR ${LIB_DIR})
set(BUILD_TESTS FALSE)
endif()

message("OS is ${OS}")
Expand Down Expand Up @@ -74,6 +76,8 @@ install(FILES
${OSHW_HEADERS}
DESTINATION ${SOEM_INCLUDE_INSTALL_DIR})

add_subdirectory(test/linux/slaveinfo)
add_subdirectory(test/linux/eepromtool)
add_subdirectory(test/linux/simple_test)
if(BUILD_TESTS)
add_subdirectory(test/linux/slaveinfo)
add_subdirectory(test/linux/eepromtool)
add_subdirectory(test/linux/simple_test)
endif()
24 changes: 18 additions & 6 deletions oshw/rtems/nicdrv.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,11 @@ int ecx_setupnic(ecx_portt *port, const char *ifname, int secondary)
sprintf(fname, "/dev/bpf%i", i);
*bpf = open(fname, O_RDWR);
}

if(*bpf == -1)
{
/* Failed to open bpf */
perror("Could not open bpf\n");
return 0;
}

Expand All @@ -164,40 +165,52 @@ int ecx_setupnic(ecx_portt *port, const char *ifname, int secondary)
if (ioctl(*bpf, BIOCSBLEN, &buffer_len) == -1) {
perror("BIOCGBLEN");
}
assert(buffer_len >= 1518);

if (buffer_len < 1518) {
printf("buffer_len %d < 1518\n", buffer_len);
return 0;
}

/* connect bpf to NIC by name */
strcpy(ifr.ifr_name, ifname);
assert(ioctl(*bpf, BIOCSETIF, &ifr) == 0);
if(ioctl(*bpf, BIOCSETIF, &ifr) == -1) {
perror("BIOCSETIF");
return 0;
}

/* Set required bpf options */

/* Activate immediate mode */
if (ioctl(*bpf, BIOCIMMEDIATE, &true_val) == -1) {
perror("BIOCIMMEDIATE");
return 0;
}

/* Set interface in promiscuous mode */
if (ioctl(*bpf, BIOCPROMISC, &true_val) == -1) {
perror("BIOCPROMISC");
return 0;
}

/* Allow to have custom source address */
if (ioctl(*bpf, BIOCSHDRCMPLT, &true_val) == -1) {
perror("BIOCSHDRCMPLT");
return 0;
}

/* Listen only to incomming messages */
uint direction = BPF_D_IN;
if (ioctl(*bpf, BIOCSDIRECTION, &direction) == -1) {
perror("BIOCSDIRECTION");
return 0;
}

/* Set read timeout */
timeout.tv_sec = 0;
timeout.tv_usec = 1;
timeout.tv_usec = 11000;
if (ioctl(*bpf, BIOCSRTIMEOUT, &timeout) == -1) {
perror("BIOCSRTIMEOUT");
return 0;
}

/* setup ethernet headers in tx buffers so we don't have to repeat it */
Expand All @@ -207,9 +220,8 @@ int ecx_setupnic(ecx_portt *port, const char *ifname, int secondary)
port->rxbufstat[i] = EC_BUF_EMPTY;
}
ec_setupheader(&(port->txbuf2));
if (r == 0) rval = 1;

return rval;
return 1;
}

/** Close sockets used
Expand Down

0 comments on commit 5b2c51b

Please sign in to comment.