summaryrefslogtreecommitdiff
path: root/led/event_server/init.c
blob: 5aa82df445e0fc2e2ef64927f43771569876da34 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
 *  COPYRIGHT (c) 1989-2009.
 *  On-Line Applications Research Corporation (OAR).
 *
 *  The license and distribution terms for this file may be
 *  found in the file LICENSE in this distribution or at
 *  http://www.rtems.com/license/LICENSE.
 */

#include <bsp.h>
#include <inttypes.h>
#include <stdio.h>

#include "../led.h"

rtems_task Test_task(
  rtems_task_argument unused
)
{
  rtems_event_set   events;
  rtems_status_code status;

  for ( ; ; ) {
    events = 0;
    status = rtems_event_receive(
      (RTEMS_EVENT_1 | RTEMS_EVENT_2),
      RTEMS_EVENT_ANY,
      RTEMS_NO_TIMEOUT,
      &events
    );

    if ( events == RTEMS_EVENT_1 ) {
      LED_OFF();
    } else if ( events == RTEMS_EVENT_2 ) {
      LED_ON();
    } else {
      fprintf( stderr, "Incorrect event set 0x%08" PRIx32 "\n", events );
    }
  }
}

rtems_task Init(
  rtems_task_argument argument
)
{
  uint32_t          count = 0;
  rtems_event_set   events;
  rtems_status_code status;
  rtems_id          task_id;
  rtems_name        task_name;

  puts( "\n\n*** LED BLINKER -- event receive server ***" );

  LED_INIT();

  task_name = rtems_build_name( 'T', 'A', '1', ' ' );

  status = rtems_task_create(
    task_name, 1, RTEMS_MINIMUM_STACK_SIZE * 2, RTEMS_DEFAULT_MODES,
    RTEMS_DEFAULT_ATTRIBUTES, &task_id
  );

  status = rtems_task_start( task_id, Test_task, 1 );

  for (count=0; ; count++) {

    events = ( (count % 2) == 0 ) ?  RTEMS_EVENT_1 : RTEMS_EVENT_2;
    status = rtems_event_send( task_id, events );
    if ( status != RTEMS_SUCCESSFUL )
      fputs( "send did not work\n", stderr );

    status = rtems_task_wake_after( rtems_clock_get_ticks_per_second() );
  }

  status = rtems_task_delete( RTEMS_SELF );
}

/**************** START OF CONFIGURATION INFORMATION ****************/

#define CONFIGURE_INIT
#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER

#define CONFIGURE_MAXIMUM_TASKS             2

#define CONFIGURE_RTEMS_INIT_TASKS_TABLE

#define CONFIGURE_EXTRA_TASK_STACKS         (RTEMS_MINIMUM_STACK_SIZE)

#include <rtems/confdefs.h>

/****************  END OF CONFIGURATION INFORMATION  ****************/