source: examples-v2/led/timer/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.3 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
15#include "../led.h"
16
17volatile int led_do_print;
18volatile int led_value;
19rtems_id     Timer1;
20rtems_id     Timer2;
21
22void LED_Change_Routine( void ) {
23  int _led_do_print;
24  int _led_value;
25
26  /* technically the following 4 statements are a critical section */
27  _led_do_print = led_do_print;
28  _led_value = led_value;
29  led_do_print = 0;
30  led_value = 0;
31 
32  if ( _led_do_print ) {
33    if ( _led_value == 1 )
34      LED_OFF();
35    else
36      LED_ON();
37  }
38}
39
40rtems_timer_service_routine Timer_Routine( rtems_id id, void *ignored )
41{
42  rtems_status_code status;
43
44  if ( id == Timer1 )
45    led_value = 1;
46  else
47    led_value = 2;
48  led_do_print = 1;
49
50  status = rtems_timer_fire_after(
51    id,
52    2 * rtems_clock_get_ticks_per_second(),
53    Timer_Routine,
54    NULL
55  );
56}
57
58rtems_task Init(
59  rtems_task_argument argument
60)
61{
62  rtems_status_code status;
63
64  puts( "\n\n*** LED BLINKER -- timer ***" );
65
66  LED_INIT();
67
68  status = rtems_timer_create(rtems_build_name( 'T', 'M', 'R', '1' ), &Timer1);
69  if ( status != RTEMS_SUCCESSFUL )
70    fputs( "Timer1 create failed\n", stderr );
71
72  status = rtems_timer_create(rtems_build_name( 'T', 'M', 'R', '2' ), &Timer2);
73  if ( status != RTEMS_SUCCESSFUL )
74    fputs( "Timer2 create failed\n", stderr );
75
76  Timer_Routine(Timer1, NULL);
77  LED_Change_Routine();
78
79  status = rtems_task_wake_after( rtems_clock_get_ticks_per_second() );
80
81  Timer_Routine(Timer2, NULL);
82  LED_Change_Routine();
83
84  while (1) {
85    status = rtems_task_wake_after( 10 );
86    LED_Change_Routine();
87  }
88
89  status = rtems_task_delete( RTEMS_SELF );
90}
91
92
93/**************** START OF CONFIGURATION INFORMATION ****************/
94
95#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
96#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
97
98#define CONFIGURE_MAXIMUM_TASKS         1
99#define CONFIGURE_MAXIMUM_TIMERS        2
100
101#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
102
103#define CONFIGURE_EXTRA_TASK_STACKS         (3 * RTEMS_MINIMUM_STACK_SIZE)
104
105#define CONFIGURE_INIT
106#include <rtems/confdefs.h>
107/****************  END OF CONFIGURATION INFORMATION  ****************/
Note: See TracBrowser for help on using the repository browser.