OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [Common/] [drivers/] [Atmel/] [at91lib/] [utility/] [led.c] - Blame information for rev 609

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 608 jeremybenn
/* ----------------------------------------------------------------------------
2
 *         ATMEL Microcontroller Software Support
3
 * ----------------------------------------------------------------------------
4
 * Copyright (c) 2008, Atmel Corporation
5
 *
6
 * All rights reserved.
7
 *
8
 * Redistribution and use in source and binary forms, with or without
9
 * modification, are permitted provided that the following conditions are met:
10
 *
11
 * - Redistributions of source code must retain the above copyright notice,
12
 * this list of conditions and the disclaimer below.
13
 *
14
 * Atmel's name may not be used to endorse or promote products derived from
15
 * this software without specific prior written permission.
16
 *
17
 * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
20
 * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
23
 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 * ----------------------------------------------------------------------------
28
 */
29
 
30
/*
31
    Title: LED implementation
32
 
33
    About: Purpose
34
        Implementation of LED-related functionalities.
35
*/
36
 
37
//------------------------------------------------------------------------------
38
//         Headers
39
//------------------------------------------------------------------------------
40
 
41
#include "led.h"
42
#include <board.h>
43
#include <pio/pio.h>
44
 
45
//------------------------------------------------------------------------------
46
//         Internal variables
47
//------------------------------------------------------------------------------
48
 
49
#ifdef PINS_LEDS
50
static const Pin pinsLeds[] = {PINS_LEDS};
51
static const unsigned int numLeds = PIO_LISTSIZE(pinsLeds);
52
#endif
53
 
54
//------------------------------------------------------------------------------
55
//         Exported functions
56
//------------------------------------------------------------------------------
57
/*
58
    Function: LED_Configure
59
        Configures the pin associated with the given LED number.
60
 
61
    Parameters:
62
        led - Number of the LED to configure.
63
 
64
    Returns:
65
        1 if the LED exists and has been configured; otherwise 0.
66
*/
67
unsigned char LED_Configure(unsigned int led)
68
{
69
#ifdef PINS_LEDS
70
    // Check that LED exists
71
    if (led >= numLeds) {
72
 
73
        return 0;
74
    }
75
 
76
    // Configure LED
77
    return (PIO_Configure(&pinsLeds[led], 1));
78
#else
79
    return 0;
80
#endif
81
}
82
 
83
/*
84
    Function: LED_Set
85
        Turns a LED on.
86
 
87
    Parameters:
88
        led - Number of the LED to turn on.
89
 
90
    Returns:
91
        1 if the LED has been turned on; 0 otherwise.
92
*/
93
unsigned char LED_Set(unsigned int led)
94
{
95
#ifdef PINS_LEDS
96
    // Check if LED exists
97
    if (led >= numLeds) {
98
 
99
        return 0;
100
    }
101
 
102
    // Turn LED on
103
    if (pinsLeds[led].type == PIO_OUTPUT_0) {
104
 
105
        PIO_Set(&pinsLeds[led]);
106
    }
107
    else {
108
 
109
        PIO_Clear(&pinsLeds[led]);
110
    }
111
 
112
    return 1;
113
#else
114
    return 0;
115
#endif
116
}
117
 
118
/*
119
    Function: LED_Clear
120
        Turns a LED off.
121
 
122
    Parameters:
123
        led - Number of the LED to turn off.
124
 
125
    Returns:
126
        1 if the LED has been turned off; 0 otherwise.
127
*/
128
unsigned char LED_Clear(unsigned int led)
129
{
130
#ifdef PINS_LEDS
131
    // Check if LED exists
132
    if (led >= numLeds) {
133
 
134
        return 0;
135
    }
136
 
137
    // Turn LED off
138
    if (pinsLeds[led].type == PIO_OUTPUT_0) {
139
 
140
        PIO_Clear(&pinsLeds[led]);
141
    }
142
    else {
143
 
144
        PIO_Set(&pinsLeds[led]);
145
    }
146
 
147
    return 1;
148
#else
149
    return 0;
150
#endif
151
}
152
 
153
/*
154
    Function: LED_Toggle
155
        Toggles the current state of a LED.
156
 
157
    Parameters:
158
        led - Number of the LED to toggle.
159
 
160
    Returns:
161
        1 if the LED has been toggled; otherwise 0.
162
*/
163
unsigned char LED_Toggle(unsigned int led)
164
{
165
#ifdef PINS_LEDS
166
    // Check if LED exists
167
    if (led >= numLeds) {
168
 
169
        return 0;
170
    }
171
 
172
    // Toggle LED
173
    if (PIO_GetOutputDataStatus(&pinsLeds[led])) {
174
 
175
        PIO_Clear(&pinsLeds[led]);
176
    }
177
    else {
178
 
179
        PIO_Set(&pinsLeds[led]);
180
    }
181
 
182
    return 1;
183
#else
184
    return 0;
185
#endif
186
}
187
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.