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

4.11examples-v2-4-10-branch
Last change on this file since c7ee085 was c7ee085, checked in by Glenn Humphrey <glenn.humphrey@…>, on Dec 17, 2009 at 8:09:11 PM

2009-12-17 Glenn Humphrey <glenn.humphrey@…>

  • delay/init.c, event_server/init.c, msg_server/init.c, posix_cond_server/test.c, posix_delay_nanosleep/test.c, posix_delay_sleep/test.c, posix_mutex_server/test.c, ratemon1/init.c, ratemon2/init.c, ratemon_cond_server/test.c, sem_server/init.c, timeout_event/init.c: Cleaned up the led examples to produce similiar output.
  • timer_server/.cvsignore: New file.
  • 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  task_name = rtems_build_name( 'T', 'A', '1', ' ' );
62
63  status = rtems_semaphore_create(
64    rtems_build_name( 'S', 'E', 'M', ' ' ),
65    0,  /* created locked */
66    RTEMS_DEFAULT_ATTRIBUTES,
67    0,
68    &Sem_id
69  );
70  assert( status == RTEMS_SUCCESSFUL );
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
109#define CONFIGURE_INIT
110#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
111#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
112
113#define CONFIGURE_MAXIMUM_TASKS         2
114#define CONFIGURE_MAXIMUM_SEMAPHORES    1
115
116#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
117
118#define CONFIGURE_EXTRA_TASK_STACKS         (3 * RTEMS_MINIMUM_STACK_SIZE)
119
120#include <rtems/confdefs.h>
121
122/****************  END OF CONFIGURATION INFORMATION  ****************/
Note: See TracBrowser for help on using the repository browser.