summaryrefslogtreecommitdiffstats
path: root/org.rtems.cdt.toolchain/templates/serial/src/Basename.c
diff options
context:
space:
mode:
Diffstat (limited to 'org.rtems.cdt.toolchain/templates/serial/src/Basename.c')
-rw-r--r--org.rtems.cdt.toolchain/templates/serial/src/Basename.c162
1 files changed, 162 insertions, 0 deletions
diff --git a/org.rtems.cdt.toolchain/templates/serial/src/Basename.c b/org.rtems.cdt.toolchain/templates/serial/src/Basename.c
new file mode 100644
index 0000000..def460a
--- /dev/null
+++ b/org.rtems.cdt.toolchain/templates/serial/src/Basename.c
@@ -0,0 +1,162 @@
+/*
+ * File Name : $(baseName).c
+ * Author : $(author)
+ * Version :
+ * Description : A simple serial and shell test program if defined TEST_COM1;
+ * A serial remote debug test program otherwise
+ * Copyright : $(copyright)
+ */
+
+#define CONFIGURE_INIT
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <string.h> /* String function definitions */
+#include <unistd.h> /* UNIX standard function definitions */
+#include <fcntl.h> /* File control definitions */
+#include <errno.h> /* Error number definitions */
+#include <termios.h> /* POSIX terminal control definitions */
+
+#include <rtems.h>
+#include <rtems/shell.h>
+
+// BSP specific include
+#include <bsp.h>
+#include <bsp/uart.h>
+#include <bsp/tty_drv.h>
+
+
+extern rtems_task Init(rtems_task_argument argument);
+
+#define CONFIGURE_APPLICATION_EXTRA_DRIVERS TTY1_DRIVER_TABLE_ENTRY
+
+#ifdef RTEMS_BSP_HAS_IDE_DRIVER
+#include <libchip/ata.h> /* for ata driver prototype */
+#include <libchip/ide_ctrl.h> /* for general ide driver prototype */
+#endif
+
+#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
+#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
+#ifdef RTEMS_BSP_HAS_IDE_DRIVER
+#define CONFIGURE_APPLICATION_NEEDS_IDE_DRIVER
+#endif
+#define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK
+#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
+
+/*
+ * these values are higher than needed...
+ */
+#define CONFIGURE_MAXIMUM_TASKS 20
+#define CONFIGURE_MAXIMUM_SEMAPHORES 20
+#define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 20
+#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 20
+#define STACK_CHECKER_ON
+#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
+
+#define CONFIGURE_EXTRA_TASK_STACKS (6 * RTEMS_MINIMUM_STACK_SIZE)
+
+#define CONFIGURE_MALLOC_STATISTICS
+
+
+#include <rtems/confdefs.h>
+
+
+#define CONFIGURE_SHELL_COMMANDS_INIT
+#define CONFIGURE_SHELL_COMMANDS_ALL
+
+#include <rtems/shellconfig.h>
+
+extern int BSPConsolePort;
+
+/* Temporarily worked around the issue with remote_debug in i386.
+ "int remote_debug;" is defined in m68k-stub.c, but only declared
+ in i386-stub.c. Also except "remote_debug = !(remote_debug);", nowhere else
+ value is assigned to remote_debug.
+ */
+int remote_debug = 1;
+
+/*
+ * Setup GDB as described in c\src\lib\libbsp\i386\shared\comm\GDB.HOWTO.
+ *
+ * Later found similar function: init_remote_gdb in
+ * c\src\lib\libbsp\i386\shared\comm\gdb_glue.c. But it does not fit with the
+ * following hardware configuration:
+ * there exist VGA console and COM1, but not COM2.
+ */
+void setupRemoteGDB(void) {
+ // Initialize GDB glue
+ /*
+ if(BSPConsolePort != BSP_UART_COM2) {
+ // If com2 is not used as console use it for debugging
+ i386_stub_glue_init(BSP_UART_COM2);
+ } else { // Otherwise use com1 */
+ i386_stub_glue_init(BSP_UART_COM1);
+ //}
+
+ // Initialize GDB stub itself
+ set_debug_traps();
+
+ // Initialize GDB break in capability
+ // It has to be called after set_debug_traps
+ i386_stub_glue_init_breakin();
+
+ // Put breakpoint in
+ breakpoint();
+}
+
+void testIO(char *devName) {
+ char buffer[256];
+
+ #ifdef TEST_COM1
+ printf("*** Simple COM1 Test (9600 8N1) ***\n");
+ #else
+ printf("*** Simple Remote Debug Test ***\n");
+ #endif
+
+ int fd = open(devName, O_RDWR | O_NOCTTY | _FNDELAY);
+
+ int numBytes = write(fd, "Hello, I'm waiting for input...\r\n", 33);
+ if (numBytes < 0) {
+ printf("\nFailed to write to %s!\n", devName);
+ }
+
+ numBytes = read(fd, buffer, 255);
+ if (numBytes < 0) {
+ printf("\nFailed to read from %s!\n", devName);
+
+ } else {
+ buffer[numBytes] = 0; // terminate
+ printf(buffer);
+ }
+
+ close(fd);
+ }
+
+void startShell(void) {
+ printf("\n====== starting shell ======\n");
+ rtems_shell_init(
+ "SHLL", /* task_name */
+ RTEMS_MINIMUM_STACK_SIZE * 4, /* task_stacksize */
+ 100, /* task_priority */
+ "/dev/console", /* devname */
+ 0, /* forever */
+ 1 /* wait */
+ );
+}
+
+rtems_task Init(rtems_task_argument ignored) {
+#ifdef TEST_COM1
+ char devName[] = "/dev/ttyS1";
+#else
+ char devName[] = "/dev/console";
+
+ setupRemoteGDB();
+#endif
+
+ testIO(devName);
+
+ startShell();
+
+ exit( 0 );
+}