source: rtems-docs/c-user/example_application.rst @ 464d541

5
Last change on this file since 464d541 was 4da4a15, checked in by Chris Johns <chrisj@…>, on 11/09/16 at 00:42:10

c-user: Fix header levels. Minor fixes.

  • Property mode set to 100644
File size: 2.3 KB
Line 
1.. comment SPDX-License-Identifier: CC-BY-SA-4.0
2
3.. COMMENT: COPYRIGHT (c) 1989-2011.
4.. COMMENT: On-Line Applications Research Corporation (OAR).
5.. COMMENT: All rights reserved.
6
7Example Application
8*******************
9
10.. code-block:: c
11    :linenos:
12
13    /*
14    *  This file contains an example of a simple RTEMS
15    *  application.  It instantiates the RTEMS Configuration
16    *  Information using confdef.h and contains two tasks:
17    *  a user initialization task and a simple task.
18    */
19
20    #include <rtems.h>
21
22    rtems_task user_application(rtems_task_argument argument);
23
24    rtems_task init_task(
25        rtems_task_argument ignored
26    )
27    {
28        rtems_id          tid;
29        rtems_status_code status;
30        rtems_name        name;
31
32        name = rtems_build_name( 'A', 'P', 'P', '1' )
33
34        status = rtems_task_create(
35            name, 1, RTEMS_MINIMUM_STACK_SIZE,
36            RTEMS_NO_PREEMPT, RTEMS_FLOATING_POINT, &tid
37        );
38        if ( status != RTEMS_STATUS_SUCCESSFUL ) {
39            printf( "rtems_task_create failed with status of %d.\n", status );
40            exit( 1 );
41        }
42
43        status = rtems_task_start( tid, user_application, 0 );
44        if ( status != RTEMS_STATUS_SUCCESSFUL ) {
45            printf( "rtems_task_start failed with status of %d.\n", status );
46            exit( 1 );
47        }
48
49        status = rtems_task_delete( SELF );    /* should not return */
50
51        printf( "rtems_task_delete returned with status of %d.\n", status );
52        exit( 1 );
53    }
54
55    rtems_task user_application(rtems_task_argument argument)
56    {
57        /* application specific initialization goes here */
58        while ( 1 )  {              /* infinite loop */
59            /*  APPLICATION CODE GOES HERE
60             *
61             *  This code will typically include at least one
62             *  directive which causes the calling task to
63             *  give up the processor.
64             */
65        }
66    }
67
68    /* The Console Driver supplies Standard I/O. */
69    #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
70    /* The Clock Driver supplies the clock tick. */
71    #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
72    #define CONFIGURE_MAXIMUM_TASKS 2
73    #define CONFIGURE_INIT_TASK_NAME rtems_build_name( 'E', 'X', 'A', 'M' )
74    #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
75    #define CONFIGURE_INIT
76    #include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.