source: examples-v2/led/timer/init.c @ 778e80d

4.11examples-v2-4-10-branch
Last change on this file since 778e80d was 778e80d, checked in by Glenn Humphrey <glenn.humphrey@…>, on Oct 12, 2009 at 8:59:26 PM

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

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