source: rtems-eclipse-plug-in/org.rtems.cdt.toolchain/templates/serial/src/Basename.c @ 52a6839

initial-import base
Last change on this file since 52a6839 was 52a6839, checked in by Joel Sherrill <joel.sherrill@…>, on Nov 20, 2008 at 4:33:19 PM

Initial import.

  • Property mode set to 100644
File size: 4.3 KB
Line 
1/*
2 *  File Name   : $(baseName).c
3 *  Author      : $(author)
4 *  Version     :
5 *  Description : A simple serial and shell test program if defined TEST_COM1;
6 *                A serial remote debug test program otherwise
7 *  Copyright   : $(copyright)
8 */
9
10#define CONFIGURE_INIT
11
12#include <stdio.h>
13#include <stdlib.h>
14
15#include <string.h>  /* String function definitions */
16#include <unistd.h>  /* UNIX standard function definitions */
17#include <fcntl.h>   /* File control definitions */
18#include <errno.h>   /* Error number definitions */
19#include <termios.h> /* POSIX terminal control definitions */
20
21#include <rtems.h>
22#include <rtems/shell.h>
23
24// BSP specific include
25#include <bsp.h>
26#include <bsp/uart.h>
27#include <bsp/tty_drv.h>
28
29
30extern rtems_task Init(rtems_task_argument argument);
31
32#define CONFIGURE_APPLICATION_EXTRA_DRIVERS  TTY1_DRIVER_TABLE_ENTRY
33
34#ifdef RTEMS_BSP_HAS_IDE_DRIVER
35#include <libchip/ata.h> /* for ata driver prototype */
36#include <libchip/ide_ctrl.h> /* for general ide driver prototype */
37#endif
38
39#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
40#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
41#ifdef RTEMS_BSP_HAS_IDE_DRIVER
42#define CONFIGURE_APPLICATION_NEEDS_IDE_DRIVER
43#endif
44#define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK
45#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
46
47/*
48 * these values are higher than needed...
49 */
50#define CONFIGURE_MAXIMUM_TASKS             20
51#define CONFIGURE_MAXIMUM_SEMAPHORES        20
52#define CONFIGURE_MAXIMUM_MESSAGE_QUEUES    20
53#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 20
54#define STACK_CHECKER_ON
55#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
56
57#define CONFIGURE_EXTRA_TASK_STACKS         (6 * RTEMS_MINIMUM_STACK_SIZE)
58
59#define CONFIGURE_MALLOC_STATISTICS
60
61
62#include <rtems/confdefs.h>
63
64
65#define CONFIGURE_SHELL_COMMANDS_INIT
66#define CONFIGURE_SHELL_COMMANDS_ALL
67
68#include <rtems/shellconfig.h>
69
70extern int BSPConsolePort;
71
72/* Temporarily worked around the issue with remote_debug in i386.
73   "int     remote_debug;" is defined in m68k-stub.c, but only declared
74   in i386-stub.c. Also except "remote_debug = !(remote_debug);", nowhere else
75   value is assigned to remote_debug.
76 */
77int remote_debug = 1;
78
79/*
80 * Setup GDB as described in c\src\lib\libbsp\i386\shared\comm\GDB.HOWTO.
81 *
82 * Later found similar function: init_remote_gdb in
83 * c\src\lib\libbsp\i386\shared\comm\gdb_glue.c. But it does not fit with the
84 * following hardware configuration:
85 *       there exist VGA console and COM1, but not COM2.
86 */
87void setupRemoteGDB(void) {
88   // Initialize GDB glue
89   /*
90   if(BSPConsolePort != BSP_UART_COM2) {
91        // If com2 is not used as console use it for debugging
92       i386_stub_glue_init(BSP_UART_COM2);
93   } else { // Otherwise use com1  */
94       i386_stub_glue_init(BSP_UART_COM1);
95   //}
96
97   // Initialize GDB stub itself
98   set_debug_traps();
99
100   // Initialize GDB break in capability
101   // It has to be called after set_debug_traps
102   i386_stub_glue_init_breakin();
103
104   // Put breakpoint in
105   breakpoint();
106}
107
108void testIO(char *devName) {
109  char buffer[256];
110
111  #ifdef TEST_COM1
112    printf("*** Simple COM1 Test (9600 8N1) ***\n");
113  #else
114    printf("*** Simple Remote Debug Test ***\n");
115  #endif
116
117  int fd = open(devName, O_RDWR | O_NOCTTY | _FNDELAY);
118
119  int numBytes = write(fd, "Hello, I'm waiting for input...\r\n", 33);
120  if (numBytes < 0) {
121    printf("\nFailed to write to %s!\n", devName);
122  }
123
124  numBytes = read(fd, buffer, 255);
125  if (numBytes < 0) {
126    printf("\nFailed to read from %s!\n", devName);
127
128  } else {
129    buffer[numBytes] = 0; // terminate
130    printf(buffer);
131  }
132
133  close(fd);
134 }
135
136void startShell(void) {
137  printf("\n====== starting shell ======\n");
138  rtems_shell_init(
139    "SHLL",                          /* task_name */
140    RTEMS_MINIMUM_STACK_SIZE * 4,    /* task_stacksize */
141    100,                             /* task_priority */
142    "/dev/console",                  /* devname */
143    0,                               /* forever */
144    1                                /* wait */
145  );
146}
147
148rtems_task Init(rtems_task_argument ignored) {
149#ifdef TEST_COM1
150  char devName[] = "/dev/ttyS1";
151#else
152  char devName[] = "/dev/console";
153
154  setupRemoteGDB();
155#endif
156
157  testIO(devName);
158
159  startShell();
160
161  exit( 0 );
162}
Note: See TracBrowser for help on using the repository browser.