LwIP test application added (echo server)
authorPremysl Houdek <houdepre@fel.cvut.cz>
Fri, 6 Nov 2015 17:15:12 +0000 (18:15 +0100)
committerPavel Pisa <pisa@cmp.felk.cvut.cz>
Sat, 7 Nov 2015 00:38:54 +0000 (01:38 +0100)
Signed-off-by: Premysl Houdek <houdepre@fel.cvut.cz>
rtems-omk-template/applwiptest/Makefile [new file with mode: 0644]
rtems-omk-template/applwiptest/Makefile.omk [new file with mode: 0644]
rtems-omk-template/applwiptest/app_def.h [new file with mode: 0644]
rtems-omk-template/applwiptest/init.c [new file with mode: 0644]
rtems-omk-template/applwiptest/system.h [new file with mode: 0644]
rtems-omk-template/applwiptest/task_1.c [new file with mode: 0644]

diff --git a/rtems-omk-template/applwiptest/Makefile b/rtems-omk-template/applwiptest/Makefile
new file mode 100644 (file)
index 0000000..76b56fd
--- /dev/null
@@ -0,0 +1,14 @@
+# Generic directory or leaf node makefile for OCERA make framework
+
+ifndef MAKERULES_DIR
+MAKERULES_DIR := $(shell ( old_pwd="" ;  while [ ! -e Makefile.rules ] ; do if [ "$$old_pwd" = `pwd`  ] ; then exit 1 ; else old_pwd=`pwd` ; cd -L .. 2>/dev/null ; fi ; done ; pwd ) )
+endif
+
+ifeq ($(MAKERULES_DIR),)
+all : default
+.DEFAULT::
+       @echo -e "\nThe Makefile.rules has not been found in this or parent directory\n"
+else
+include $(MAKERULES_DIR)/Makefile.rules
+endif
+
diff --git a/rtems-omk-template/applwiptest/Makefile.omk b/rtems-omk-template/applwiptest/Makefile.omk
new file mode 100644 (file)
index 0000000..284a1b5
--- /dev/null
@@ -0,0 +1,21 @@
+default_CONFIG += CONFIG_OC_BUILD4RTEMS=y
+default_CONFIG += CONFIG_OC_GDBSTUB=n
+default_CONFIG += CONFIG_OC_APP_APPLWIPTEST=x
+
+ifeq ($(CONFIG_OC_APP_APPLWIPTEST),y)
+
+bin_PROGRAMS = applwiptest
+
+#lib_LIBRARIES = 
+
+#include_HEADERS = 
+
+applwiptest_SOURCES += init.c task_1.c
+
+#appfoo_EMBEDTARFILES = rootfs
+
+lib_LOADLIBES += bar lwip
+
+endif
+
+
diff --git a/rtems-omk-template/applwiptest/app_def.h b/rtems-omk-template/applwiptest/app_def.h
new file mode 100644 (file)
index 0000000..6527316
--- /dev/null
@@ -0,0 +1,39 @@
+#ifndef _APP_DEF_H
+#define _APP_DEF_H
+
+#ifndef COND_EXTERN
+  #ifdef CONFIGURE_INIT
+    #define COND_EXTERN
+  #else
+    #define COND_EXTERN extern
+  #endif
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+COND_EXTERN rtems_id   Task_1_id;           /* Task 1 id */
+COND_EXTERN rtems_name Task_1_name;         /* Task 1 name */
+
+rtems_task Task_1(
+  rtems_task_argument argument
+);
+
+void bad_rtems_status(rtems_status_code status, int fail_level, const char *text);
+
+static inline
+void check_rtems_status(rtems_status_code status, int fail_level, const char *text)
+{
+   if(!rtems_is_status_successful(status))
+     bad_rtems_status(status, fail_level, text);
+}
+
+#define TASK_1_PRIORITY     30
+#define SHELL_TASK_PRIORITY 50
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /*_APP_DEF_H*/
diff --git a/rtems-omk-template/applwiptest/init.c b/rtems-omk-template/applwiptest/init.c
new file mode 100644 (file)
index 0000000..ace8cda
--- /dev/null
@@ -0,0 +1,126 @@
+/*  Init
+ *
+ *  This routine is the initialization task for this test program.
+ *  It is called from init_exec and has the responsibility for creating
+ *  and starting the tasks that make up the test.  If the time of day
+ *  clock is required for the test, it should also be set to a known
+ *  value by this function.
+ *
+ *  Input parameters:  NONE
+ *
+ *  Output parameters:  NONE
+ *
+ *  COPYRIGHT (c) 1989-1999.
+ *  On-Line Applications Research Corporation (OAR).
+ *
+ *  The license and distribution terms for this file may be
+ *  found in the file LICENSE in this distribution or at
+ *  http://www.rtems.com/license/LICENSE.
+ *
+ *  $Id: init.c,v 1.12.4.1 2003/09/04 18:46:30 joel Exp $
+ */
+
+#define CONFIGURE_INIT
+#include <system_def.h>
+#include "system.h"
+#include "app_def.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <rtems/error.h>
+#include <rtems/monitor.h>
+#include <rtems/shell.h>
+#include "arch/eth_lwip.h"
+
+#define CONFIGURE_SHELL_COMMANDS_INIT
+#define CONFIGURE_SHELL_COMMANDS_ALL
+#define CONFIGURE_SHELL_MOUNT_MSDOS
+
+#include <rtems/shellconfig.h>
+
+#define BUILD_VERSION_STRING(major,minor,patch) \
+        __XSTRING(major) "." __XSTRING(minor) "." __XSTRING(patch)
+
+#define RTEMS_VER_CODE VER_CODE(__RTEMS_MAJOR__ ,__RTEMS_MINOR__ ,__RTEMS_REVISION__)
+
+#if RTEMS_VER_CODE < VER_CODE(4,7,99)
+  #define rtems_shell_add_cmd shell_add_cmd
+  #define rtems_shell_init(m_task_name,m_task_stacksize,m_task_priority,m_devname,m_forever,m_wait,m_login_check) \
+                shell_init(m_task_name,m_task_stacksize,m_task_priority,m_devname,B19200 | CS8,m_forever)
+#elif RTEMS_VER_CODE < VER_CODE(4,9,99)
+  #define rtems_shell_init(m_task_name,m_task_stacksize,m_task_priority,m_devname,m_forever,m_wait,m_login_check) \
+          rtems_shell_init(m_task_name,m_task_stacksize,m_task_priority,m_devname,m_forever,m_wait)
+#endif
+
+void 
+bad_rtems_status(rtems_status_code status, int fail_level, const char *text)
+{
+  printf("ERROR: %s status %s", text, rtems_status_text(status));
+  status = rtems_task_delete( RTEMS_SELF );
+}
+
+int testcmd_forshell(int argc, char **argv)
+{
+  int i;
+  printf("Command %s called\n",argv[0]);
+  for(i=1;i<argc;i++)
+    if(argv[i])
+      printf("%s",argv[i]);
+  printf("\n");
+  return 0;
+}
+
+rtems_task Init(
+  rtems_task_argument ignored
+)
+{
+  rtems_status_code status;
+
+  printf( "\n\nRTEMS v "
+          BUILD_VERSION_STRING(__RTEMS_MAJOR__ ,__RTEMS_MINOR__ ,__RTEMS_REVISION__)
+         "\n");
+  
+  rtems_monitor_init(RTEMS_MONITOR_SUSPEND|RTEMS_MONITOR_GLOBAL);
+  /*rtems_capture_cli_init (0);*/
+
+  printf( "Starting application " SW_VER_ID " v "
+          BUILD_VERSION_STRING(SW_VER_MAJOR,SW_VER_MINOR,SW_VER_PATCH)
+         "\n" );
+    
+  eth_lwip_init(0);
+  printf("*** LwIP Init done ***\n");
+
+  Task_1_name = rtems_build_name( 'T', 'S', 'K', '1' );
+    
+  status = rtems_task_create(
+     Task_1_name,
+     TASK_1_PRIORITY,
+     RTEMS_MINIMUM_STACK_SIZE+0x10000,
+     RTEMS_DEFAULT_MODES /*& ~(RTEMS_TIMESLICE_MASK) | RTEMS_TIMESLICE*/,
+     RTEMS_DEFAULT_ATTRIBUTES,
+     &Task_1_id
+  );
+  check_rtems_status(status, 0, "rtems_task_create of Task_1");
+
+  status = rtems_task_start( Task_1_id, Task_1, 0 );
+  check_rtems_status(status, 0, "rtems_task_start of Task_1\n");
+
+  rtems_shell_init("SHLL",RTEMS_MINIMUM_STACK_SIZE+0x1000,
+              SHELL_TASK_PRIORITY,"/dev/console",1,0, NULL);
+
+  rtems_shell_add_cmd("testcmd", "app",
+                "test command for shell",
+                testcmd_forshell);
+  rtems_shell_add_cmd("ethstat", "app",
+                "show tms570 ethernet status",
+                eth_lwip_get_netif_status_cmd);
+  rtems_shell_add_cmd("dhcpinfo", "app",
+                "show tms570 ethernet status",
+                eth_lwip_get_dhcp_info);                
+
+  //rtems_monitor_wakeup();
+
+  status = rtems_task_delete( RTEMS_SELF );
+  
+  printf( "*** END OF TEST2 ***\n" );
+  exit( 0 );
+}
diff --git a/rtems-omk-template/applwiptest/system.h b/rtems-omk-template/applwiptest/system.h
new file mode 100644 (file)
index 0000000..1282cbd
--- /dev/null
@@ -0,0 +1,73 @@
+/*  system.h
+ *
+ *  This include file contains information that is included in every
+ *  function in the test set.
+ *
+ *  COPYRIGHT (c) 1989-1999.
+ *  On-Line Applications Research Corporation (OAR).
+ *
+ *  The license and distribution terms for this file may be
+ *  found in the file LICENSE in this distribution or at
+ *  http://www.rtems.com/license/LICENSE.
+ *
+ *  $Id: system.h,v 1.13.6.1 2003/09/04 18:46:30 joel Exp $
+ */
+
+#include <rtems.h>
+
+/* functions */
+
+rtems_task Init(
+  rtems_task_argument argument
+);
+
+/* configuration information */
+
+#include <bsp.h> /* for device driver prototypes */
+
+#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
+#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
+#define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK
+
+#define TICKS_PER_SECOND 1000
+
+#define CONFIGURE_MAXIMUM_TIMERS                 32
+#define CONFIGURE_MAXIMUM_MESSAGE_QUEUES         32
+#define CONFIGURE_MAXIMUM_SEMAPHORES             32
+#define CONFIGURE_MAXIMUM_TASKS                  32
+#define CONFIGURE_MAXIMUM_PERIODS                4
+#define CONFIGURE_MAXIMUM_USER_EXTENSIONS        2
+#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 32
+/*#define CONFIGURE_MAXIMUM_DRIVERS (CONFIGURE_NUMBER_OF_DRIVERS+10)*/
+#define CONFIGURE_MAXIMUM_DRIVERS                32
+
+#ifdef RTEMS_POSIX_API
+#define CONFIGURE_MAXIMUM_POSIX_THREADS          32
+#define CONFIGURE_MAXIMUM_POSIX_MUTEXES          20
+#define CONFIGURE_MAXIMUM_POSIX_SEMAPHORES       10
+#define CONFIGURE_MAXIMUM_POSIX_KEYS             4
+#define CONFIGURE_MAXIMUM_POSIX_KEY_VALUE_PAIRS  8
+#endif /*RTEMS_POSIX_API*/
+
+#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
+
+#define CONFIGURE_APPLICATION_NEEDS_NULL_DRIVER
+#define CONFIGURE_APPLICATION_NEEDS_ZERO_DRIVER
+
+#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
+/*#define CONFIGURE_USE_MINIIMFS_AS_BASE_FILESYSTEM*/
+
+#define CONFIGURE_MICROSECONDS_PER_TICK 1000
+
+#define CONFIGURE_EXTRA_TASK_STACKS     (10 * (RTEMS_MINIMUM_STACK_SIZE + 2 * 1024))
+
+#define CONFIGURE_INIT_TASK_STACK_SIZE  (10*1024)
+#define CONFIGURE_INIT_TASK_PRIORITY    120
+#define CONFIGURE_INIT_TASK_INITIAL_MODES (RTEMS_PREEMPT | \
+                                           RTEMS_NO_TIMESLICE | \
+                                           RTEMS_NO_ASR | \
+                                           RTEMS_INTERRUPT_LEVEL(0))
+
+#include <rtems/confdefs.h>
+
+/* end of include file */
diff --git a/rtems-omk-template/applwiptest/task_1.c b/rtems-omk-template/applwiptest/task_1.c
new file mode 100644 (file)
index 0000000..ab91d3a
--- /dev/null
@@ -0,0 +1,112 @@
+#include <system_def.h>
+#include "system.h"
+#include "app_def.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <rtems/untar.h>
+#include <rtems/error.h>
+#include <rtems/mw_uid.h>
+#include <errno.h>
+
+#include <lwip/init.h>
+#include "lwip/err.h"
+#include "lwip/tcp.h"
+#include <netif/etharp.h>
+#include <lwip/tcp_impl.h>
+
+#include "lwip/tcpip.h"
+#include "arch/eth_lwip.h"
+#include "lwip/api.h"
+#include "lwip/netbuf.h"
+#include "lwip/netdb.h"
+#include "lwip/netifapi.h"
+#include "lwip/pppapi.h"
+#include "lwip/sockets.h"
+#include "lwip/sys.h"
+
+void lwip_echo_task(rtems_task_argument arg)
+{
+  int clientfd = (int) arg;
+  char buffer[1024];
+  int nbytes;
+  printf("ECHO THREAD STARTED %d\n", clientfd);
+  do{
+    nbytes=lwip_recv(clientfd, buffer, sizeof(buffer),0);
+    if (nbytes>0) lwip_send(clientfd, buffer, nbytes, 0);
+  } while (nbytes>0);
+  lwip_close(clientfd);
+  printf("ECHO THREAD STOPPED %d\n", clientfd);
+  rtems_task_delete( RTEMS_SELF );
+}
+
+void lwip_echo_server(void)
+{
+  int lSocket;
+  struct sockaddr_in sLocalAddr;
+
+  lSocket = lwip_socket(AF_INET, SOCK_STREAM, 0);
+  if (lSocket < 0) return;
+
+  memset((char *)&sLocalAddr, 0, sizeof(sLocalAddr));
+  sLocalAddr.sin_family = AF_INET;
+  sLocalAddr.sin_len = sizeof(sLocalAddr);
+  sLocalAddr.sin_addr.s_addr = htonl(INADDR_ANY);
+  sLocalAddr.sin_port = 23;
+
+  if (lwip_bind(lSocket, (struct sockaddr *)&sLocalAddr, sizeof(sLocalAddr)) < 0) {
+          lwip_close(lSocket);
+          return;
+  }
+
+  if ( lwip_listen(lSocket, 20) != 0 ){
+          lwip_close(lSocket);
+          return;
+  }
+
+  while (1)
+  {
+        int clientfd;
+        struct sockaddr_in client_addr;
+        int addrlen=sizeof(client_addr);
+        rtems_id id;
+        rtems_status_code res;
+
+        clientfd = lwip_accept(lSocket, (struct sockaddr*)&client_addr, (socklen_t)&addrlen);
+        if (clientfd>0){
+          res = rtems_task_create(rtems_build_name('E', 'C', 'H', '0'+(clientfd & 7)),
+            90, RTEMS_MINIMUM_STACK_SIZE+2048, RTEMS_PREEMPT, 0, &id );
+
+          if (res != RTEMS_SUCCESSFUL) {
+            lwip_close(clientfd);
+            printf("ECHO THREAD NOT CREATED %d\n", clientfd);
+            continue;
+          }
+          res = rtems_task_start(id, (rtems_task_entry)lwip_echo_task, (rtems_task_argument)clientfd);
+          if (res != RTEMS_SUCCESSFUL) {
+            rtems_task_delete(id);
+            lwip_close(clientfd);
+            continue;
+          }
+        }
+  }
+  lwip_close(lSocket);
+}
+
+rtems_task Task_1(
+  rtems_task_argument argument
+)
+{
+  printf("*** Starting up Task_1 ***\n");
+  
+  int loops = 3;
+  rtems_status_code status;
+  while(loops--){
+    eth_lwip_get_dhcp_info();
+    status = rtems_task_wake_after(rtems_clock_get_ticks_per_second()*5);
+  }
+  printf("*** Start Echo server ***\n");
+  lwip_echo_server();
+  printf("*** Echo server ended ***\n");
+  rtems_task_suspend( RTEMS_SELF );
+}
+