source: examples-v2/led/sem_server/init.c

Last change on this file was 28912ca, checked in by Joel Sherrill <joel.sherrill@…>, on May 15, 2012 at 9:18:13 PM

examples-v2 - Remove CVS Ids (scripted)

  • Property mode set to 100644
File size: 2.9 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2009.
3 *  On-Line Applications Research Corporation (OAR).
4 *
5 *  The license and distribution terms for this file may be
6 *  found in the file LICENSE in this distribution or at
7 *  http://www.rtems.com/license/LICENSE.
8 */
9
10#include <stdio.h>
11#include <bsp.h>
12#include <assert.h>
13
14#include "../led.h"
15
16rtems_id   Sem_id;
17
18rtems_task Test_task(
19  rtems_task_argument unused
20)
21{
22  rtems_status_code status;
23
24  for ( ; ; ) {
25
26    /* Semaphore not available, ensured to block */
27    status = rtems_semaphore_obtain(
28      Sem_id,
29      RTEMS_DEFAULT_OPTIONS,
30      RTEMS_NO_TIMEOUT
31    );
32    if ( status != RTEMS_SUCCESSFUL )
33      fputs( "Task - obtain did not work\n", stderr );
34
35    LED_ON();
36
37    status = rtems_task_wake_after( rtems_clock_get_ticks_per_second() );
38    assert( status == RTEMS_SUCCESSFUL );
39
40    /* Transfers semaphore to Init task */
41    status = rtems_semaphore_release( Sem_id );
42    if ( status != RTEMS_SUCCESSFUL )
43      fputs( "Task - release did not work\n", stderr );
44  }
45}
46
47rtems_task Init(
48  rtems_task_argument argument
49)
50{
51  rtems_status_code status;
52  rtems_id          task_id;
53  rtems_name        task_name;
54
55  puts( "\n\n*** LED BLINKER -- semaphore ping/pong ***" );
56
57  LED_INIT();
58
59  status = rtems_semaphore_create(
60    rtems_build_name( 'S', 'E', 'M', ' ' ),
61    0,  /* created locked */
62    RTEMS_DEFAULT_ATTRIBUTES,
63    0,
64    &Sem_id
65  );
66  assert( status == RTEMS_SUCCESSFUL );
67
68  task_name = rtems_build_name( 'T', 'A', '1', ' ' );
69
70  status = rtems_task_create(
71    task_name, 1, RTEMS_MINIMUM_STACK_SIZE * 2, RTEMS_DEFAULT_MODES,
72    RTEMS_DEFAULT_ATTRIBUTES, &task_id
73  );
74  assert( status == RTEMS_SUCCESSFUL );
75
76  status = rtems_task_start( task_id, Test_task, 1 );
77  assert( status == RTEMS_SUCCESSFUL );
78
79  while (1) {
80
81    LED_OFF();
82    status = rtems_task_wake_after( rtems_clock_get_ticks_per_second() );
83    assert( status == RTEMS_SUCCESSFUL );
84
85    /* Transfers semaphore to TA1 */
86    status = rtems_semaphore_release( Sem_id );
87    if ( status != RTEMS_SUCCESSFUL )
88      fputs( "init - release did not work\n", stderr );
89
90    /* Semaphore not available, ensured to block */
91    status = rtems_semaphore_obtain(
92      Sem_id,
93      RTEMS_DEFAULT_OPTIONS,
94      RTEMS_NO_TIMEOUT
95    );
96    if ( status != RTEMS_SUCCESSFUL )
97      fputs( "init - obtain did not work\n", stderr );
98
99  }
100
101  status = rtems_task_delete( RTEMS_SELF );
102  assert( status == RTEMS_SUCCESSFUL );
103}
104
105/**************** START OF CONFIGURATION INFORMATION ****************/
106#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
107#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
108
109#define CONFIGURE_MAXIMUM_TASKS         2
110#define CONFIGURE_MAXIMUM_SEMAPHORES    1
111
112#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
113
114#define CONFIGURE_EXTRA_TASK_STACKS         (3 * RTEMS_MINIMUM_STACK_SIZE)
115
116#define CONFIGURE_INIT
117#include <rtems/confdefs.h>
118/****************  END OF CONFIGURATION INFORMATION  ****************/
Note: See TracBrowser for help on using the repository browser.