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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [CORTEX_AT91SAM3U256_IAR/] [system/] [led.c] - Blame information for rev 590

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

Line No. Rev Author Line
1 580 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
//         Headers
32
//------------------------------------------------------------------------------
33
 
34
#include "led.h"
35
#include <board.h>
36
#include <pio/pio.h>
37
 
38
//------------------------------------------------------------------------------
39
//         Local Variables
40
//------------------------------------------------------------------------------
41
 
42
#ifdef PINS_LEDS
43
static const Pin pinsLeds[] = {PINS_LEDS};
44
static const unsigned int numLeds = PIO_LISTSIZE(pinsLeds);
45
#endif
46
 
47
//------------------------------------------------------------------------------
48
//         Global Functions
49
//------------------------------------------------------------------------------
50
 
51
//------------------------------------------------------------------------------
52
/// Configures the pin associated with the given LED number. If the LED does
53
/// not exist on the board, the function does nothing.
54
/// \param led  Number of the LED to configure.
55
/// \return 1 if the LED exists and has been configured; otherwise 0.
56
//------------------------------------------------------------------------------
57
unsigned char LED_Configure(unsigned int led)
58
{
59
#ifdef PINS_LEDS
60
    // Check that LED exists
61
    if (led >= numLeds) {
62
 
63
        return 0;
64
    }
65
 
66
    // Configure LED
67
    return (PIO_Configure(&pinsLeds[led], 1));
68
#else
69
    return 0;
70
#endif
71
}
72
 
73
//------------------------------------------------------------------------------
74
/// Turns the given LED on if it exists; otherwise does nothing.
75
/// \param led  Number of the LED to turn on.
76
/// \return 1 if the LED has been turned on; 0 otherwise.
77
//------------------------------------------------------------------------------
78
unsigned char LED_Set(unsigned int led)
79
{
80
#ifdef PINS_LEDS
81
    // Check if LED exists
82
    if (led >= numLeds) {
83
 
84
        return 0;
85
    }
86
 
87
    // Turn LED on
88
    if (pinsLeds[led].type == PIO_OUTPUT_0) {
89
 
90
        PIO_Set(&pinsLeds[led]);
91
    }
92
    else {
93
 
94
        PIO_Clear(&pinsLeds[led]);
95
    }
96
 
97
    return 1;
98
#else
99
    return 0;
100
#endif
101
}
102
 
103
//------------------------------------------------------------------------------
104
/// Turns a LED off.
105
/// \param led  Number of the LED to turn off.
106
/// \param 1 if the LED has been turned off; 0 otherwise.
107
//------------------------------------------------------------------------------
108
unsigned char LED_Clear(unsigned int led)
109
{
110
#ifdef PINS_LEDS
111
    // Check if LED exists
112
    if (led >= numLeds) {
113
 
114
        return 0;
115
    }
116
 
117
    // Turn LED off
118
    if (pinsLeds[led].type == PIO_OUTPUT_0) {
119
 
120
        PIO_Clear(&pinsLeds[led]);
121
    }
122
    else {
123
 
124
        PIO_Set(&pinsLeds[led]);
125
    }
126
 
127
    return 1;
128
#else
129
    return 0;
130
#endif
131
}
132
 
133
//------------------------------------------------------------------------------
134
/// Toggles the current state of a LED.
135
/// \param led  Number of the LED to toggle.
136
/// \return 1 if the LED has been toggled; otherwise 0.
137
//------------------------------------------------------------------------------
138
unsigned char LED_Toggle(unsigned int led)
139
{
140
#ifdef PINS_LEDS
141
    // Check if LED exists
142
    if (led >= numLeds) {
143
 
144
        return 0;
145
    }
146
 
147
    // Toggle LED
148
    if (PIO_GetOutputDataStatus(&pinsLeds[led])) {
149
 
150
        PIO_Clear(&pinsLeds[led]);
151
    }
152
    else {
153
 
154
        PIO_Set(&pinsLeds[led]);
155
    }
156
 
157
    return 1;
158
#else
159
    return 0;
160
#endif
161
}
162
 

powered by: WebSVN 2.1.0

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