Contiki 2.5
timer.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008 Swedish Institute of Computer Science
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in
12  * the documentation and/or other materials provided with the
13  * distribution.
14  * * Neither the name of the copyright holders nor the names of
15  * contributors may be used to endorse or promote products derived
16  * from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  */
30 /**
31  * \file
32  *
33  * \brief
34  * This file will configure the timer during LCD operation.
35  *
36  * \author
37  * Mike Vidales mavida404@gmail.com
38  *
39  */
40 
41 #include "lcd.h"
42 #include "timer.h"
43 
44 /**
45  * \addtogroup lcd
46  * \{
47 */
48 
49 bool timer_flag;
50 
51 /*---------------------------------------------------------------------------*/
52 
53 /**
54  * \brief TIMER1 init for timer used by LCD.
55  *
56  * The FPU of 8MHz with a prescaler of 1024 equals 7812.5 timer ticks creating a
57  * resolution of 128us per tick.
58  *
59  * NOTE: The TIMER1 interrupt is not enabled in this routine
60 */
61 void
63 {
64  /*
65  * Set TIMER1 output compare mode to clear on compare match for OC1A. Also
66  * set the pre-scaler to 1024.
67  */
68  TCCR1B = (1 << WGM12)|(1 << CS12)|(1 << CS10);
69 
70  /* Set TIMER1 output compare register approx. 1 sec resolution. */
71  OCR1A = _1_SEC;
72 }
73 
74 /*---------------------------------------------------------------------------*/
75 
76 /**
77  * \brief Start the timer.
78 */
79 void
81 {
82  /* Clear TIMER1 timer counter value. */
83  TCNT1 = 0;
84 
85  /* Enable TIMER1 output compare interrupt. */
86  TIMSK1 = (1 << OCIE1A);
87 }
88 
89 /*---------------------------------------------------------------------------*/
90 
91 /**
92  * \brief Stop the timer.
93 */
94 void
96 {
97  /* Disable TIMER1 output compare interrupt. */
98  TIMSK1 &= ~(1 << OCIE1A);
99 }
100 
101 /*---------------------------------------------------------------------------*/
102 
103 /**
104  * \brief This is the interrupt subroutine for the TIMER1 output match comparison.
105 */
106 ISR
107 (TIMER1_COMPA_vect)
108 {
109  /* Set the irq flag. */
110  timer_flag = true;
111 }
112 
113 /** \} */