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

4.11
Last change on this file since a26bba5 was a26bba5, checked in by Joel Sherrill <joel.sherrill@…>, on Mar 3, 2011 at 6:00:34 PM

2011-03-03 Joel Sherrill <joel.sherrilL@…>

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