source: examples-v2/led/timer_server/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.6 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_server_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_server ***" );
57
58  LED_INIT();
59
60  status = rtems_timer_initiate_server(
61    1, 
62    RTEMS_MINIMUM_STACK_SIZE * 2,
63    RTEMS_DEFAULT_ATTRIBUTES
64  );
65
66  if ( status != RTEMS_SUCCESSFUL )
67    fputs( "timer create server failed\n", stderr );
68
69  status = rtems_timer_create(rtems_build_name( 'T', 'M', 'R', '1' ), &Timer1);
70  if ( status != RTEMS_SUCCESSFUL )
71    fputs( "Timer1 create failed\n", stderr );
72
73  status = rtems_timer_create(rtems_build_name( 'T', 'M', 'R', '2' ), &Timer2);
74  if ( status != RTEMS_SUCCESSFUL )
75    fputs( "Timer2 create failed\n", stderr );
76
77  Timer_Routine(Timer1, NULL);
78
79  status = rtems_task_wake_after( rtems_clock_get_ticks_per_second() );
80
81  Timer_Routine(Timer2, NULL);
82
83#if defined(__LED_PRINTING)
84  while (1) {
85    int _led_do_print;
86    int _led_value;
87
88    status = rtems_task_wake_after( 10 );
89
90    /* technically the following 4 statements are a critical section */
91    _led_do_print = led_do_print;
92    _led_value = led_value;
93    led_do_print = 0;
94    led_value = 0;
95   
96    if ( _led_do_print ) {
97      if ( _led_value )
98        LED_ON();
99      else
100        LED_OFF();
101
102    }
103  }
104#endif
105
106  status = rtems_task_delete( RTEMS_SELF );
107}
108
109
110/**************** START OF CONFIGURATION INFORMATION ****************/
111
112#define CONFIGURE_INIT
113#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
114#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
115
116#define CONFIGURE_MAXIMUM_TASKS         2
117#define CONFIGURE_MAXIMUM_TIMERS        2
118
119#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
120
121#define CONFIGURE_EXTRA_TASK_STACKS         (3 * RTEMS_MINIMUM_STACK_SIZE)
122
123#include <rtems/confdefs.h>
124
125/****************  END OF CONFIGURATION INFORMATION  ****************/
Note: See TracBrowser for help on using the repository browser.