Changes between Initial Version and Version 1 of TBR/UserManual/Simple_Serial_Test_Program


Ignore:
Timestamp:
Nov 6, 2008, 10:13:29 AM (13 years ago)
Author:
Robert
Comment:

New page: {{{ /* * File name: init.c * * A simple serial and shell test program. * * COPYRIGHT (c) 2008. * RobertF * * The license and distribution terms for this file may be * foun...

Legend:

Unmodified
Added
Removed
Modified
  • TBR/UserManual/Simple_Serial_Test_Program

    v1 v1  
     1= Simple Serial Test Program =
     2
     3
     4{{{
     5/*
     6 *  File name: init.c
     7 *
     8 *  A simple serial and shell test program.
     9 *
     10 *  COPYRIGHT (c) 2008.
     11 *  RobertF
     12 *
     13 *  The license and distribution terms for this file may be
     14 *  found in the file LICENSE in this distribution or at
     15 *  http://www.rtems.com/license/LICENSE.
     16 *
     17 */
     18
     19#define CONFIGURE_INIT
     20
     21#include <stdio.h>
     22#include <stdlib.h>
     23
     24#include <string.h>  /* String function definitions */
     25#include <unistd.h>  /* UNIX standard function definitions */
     26#include <fcntl.h>   /* File control definitions */
     27#include <errno.h>   /* Error number definitions */
     28#include <termios.h> /* POSIX terminal control definitions */
     29
     30#include <rtems.h>
     31#include <rtems/shell.h>
     32#include <bsp.h>
     33#include <bsp/tty_drv.h>
     34
     35
     36extern rtems_task Init(rtems_task_argument argument);
     37
     38#define CONFIGURE_APPLICATION_EXTRA_DRIVERS  TTY1_DRIVER_TABLE_ENTRY
     39
     40#ifdef RTEMS_BSP_HAS_IDE_DRIVER
     41#include <libchip/ata.h> /* for ata driver prototype */
     42#include <libchip/ide_ctrl.h> /* for general ide driver prototype */
     43#endif
     44
     45#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
     46#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
     47#ifdef RTEMS_BSP_HAS_IDE_DRIVER
     48#define CONFIGURE_APPLICATION_NEEDS_IDE_DRIVER
     49#endif
     50#define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK
     51#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
     52
     53/*
     54 * these values are higher than needed...
     55 */
     56#define CONFIGURE_MAXIMUM_TASKS             20
     57#define CONFIGURE_MAXIMUM_SEMAPHORES        20
     58#define CONFIGURE_MAXIMUM_MESSAGE_QUEUES    20
     59#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 20
     60#define STACK_CHECKER_ON
     61#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
     62
     63#define CONFIGURE_EXTRA_TASK_STACKS         (6 * RTEMS_MINIMUM_STACK_SIZE)
     64
     65#define CONFIGURE_MALLOC_STATISTICS
     66
     67
     68#include <rtems/confdefs.h>
     69
     70
     71#define CONFIGURE_SHELL_COMMANDS_INIT
     72#define CONFIGURE_SHELL_COMMANDS_ALL
     73
     74#include <rtems/shellconfig.h>
     75
     76
     77void testCom1(void) {
     78  char buffer[256];
     79
     80  printf("*** Simple COM1 Test (9600 8N1) ***\n");
     81
     82  int fd = open("/dev/ttyS1", O_RDWR | O_NOCTTY | _FNDELAY);
     83
     84  printf("\nOpened COM1, fd=%d\n\n", fd);
     85
     86  int numBytes = write(fd, "Hello, I'm waiting for input...\r\n", 33);
     87
     88  if (numBytes < 0) {
     89    printf("\nFailed to send from COM1!\n");
     90  }
     91
     92  numBytes = read(fd, buffer, 255);
     93
     94  if (numBytes < 0) {
     95    printf("\nFailed to read from COM1!\n");
     96
     97  } else {
     98    buffer[numBytes] = 0; // terminate
     99    printf(buffer);
     100  }
     101}
     102
     103rtems_task Init(rtems_task_argument ignored) {
     104
     105  testCom1();
     106
     107  printf("\n====== starting shell ======\n");
     108  rtems_shell_init(
     109    "SHLL",                          /* task_name */
     110    RTEMS_MINIMUM_STACK_SIZE * 4,    /* task_stacksize */
     111    100,                             /* task_priority */
     112    "/dev/console",                  /* devname */
     113    0,                               /* forever */
     114    1                                /* wait */
     115  );
     116
     117  exit( 0 );
     118}
     119}}}