This file contains definitions and services related to the LED features of the EVK1100 board.
Definition in file led.c.
#include <avr32/io.h>
#include "preprocessor.h"
#include "compiler.h"
#include "evk1100.h"
#include "led.h"
Go to the source code of this file.
Data Structures | |
| struct | tLED_DESCRIPTOR |
| Structure describing LED hardware connections. More... | |
Defines | |
| #define | INSERT_LED_DESCRIPTOR(LED_NO, unused) |
Functions | |
| void | LED_Display (U32 leds) |
| Sets the state of all LEDs. | |
| void | LED_Display_Field (U32 field, U32 leds) |
| Sets as a bit-field the state of the specified LEDs. | |
| void | LED_Display_Mask (U32 mask, U32 leds) |
| Sets the state of the specified LEDs. | |
| U8 | LED_Get_Intensity (U32 led) |
| Gets the intensity of the specified LED. | |
| void | LED_Off (U32 leds) |
| Turns off the specified LEDs. | |
| void | LED_On (U32 leds) |
| Turns on the specified LEDs. | |
| U32 | LED_Read_Display (void) |
| Gets the last state of all LEDs set through the LED API. | |
| U32 | LED_Read_Display_Field (U32 field) |
| Gets as a bit-field the last state of the specified LEDs set through the LED API. | |
| U32 | LED_Read_Display_Mask (U32 mask) |
| Gets the last state of the specified LEDs set through the LED API. | |
| void | LED_Set_Intensity (U32 leds, U8 intensity) |
| Sets the intensity of the specified LEDs. | |
| Bool | LED_Test (U32 leds) |
| Tests the last state of the specified LEDs set through the LED API. | |
| void | LED_Toggle (U32 leds) |
| Toggles the specified LEDs. | |
Variables | |
| static tLED_DESCRIPTOR | LED_DESCRIPTOR [LED_COUNT] |
| Hardware descriptors of all LEDs. | |
| static volatile U32 | LED_State = (1 << LED_COUNT) - 1 |
| Saved state of all LEDs. | |
| #define INSERT_LED_DESCRIPTOR | ( | LED_NO, | |||
| unused | ) |
Value:
{ \
{LED##LED_NO##_GPIO / 32, 1 << (LED##LED_NO##_GPIO % 32)},\
{LED##LED_NO##_PWM, LED##LED_NO##_PWM_FUNCTION } \
},
| void LED_Display | ( | U32 | leds | ) |
Sets the state of all LEDs.
| leds | New state of all LEDs (1 bit per LED). |
Definition at line 94 of file led.c.
References tLED_DESCRIPTOR::GPIO, LED_COUNT, LED_State, tLED_DESCRIPTOR::PIN_MASK, and tLED_DESCRIPTOR::PORT.
00095 { 00096 tLED_DESCRIPTOR *led_descriptor; 00097 volatile avr32_gpio_port_t *led_gpio_port; 00098 00099 leds &= (1 << LED_COUNT) - 1; 00100 LED_State = leds; 00101 for (led_descriptor = &LED_DESCRIPTOR[0]; 00102 led_descriptor < LED_DESCRIPTOR + LED_COUNT; 00103 led_descriptor++) 00104 { 00105 led_gpio_port = &AVR32_GPIO.port[led_descriptor->GPIO.PORT]; 00106 if (leds & 1) 00107 { 00108 led_gpio_port->ovrc = led_descriptor->GPIO.PIN_MASK; 00109 } 00110 else 00111 { 00112 led_gpio_port->ovrs = led_descriptor->GPIO.PIN_MASK; 00113 } 00114 led_gpio_port->oders = led_descriptor->GPIO.PIN_MASK; 00115 led_gpio_port->gpers = led_descriptor->GPIO.PIN_MASK; 00116 leds >>= 1; 00117 } 00118 }
| void LED_Display_Field | ( | U32 | field, | |
| U32 | leds | |||
| ) |
Sets as a bit-field the state of the specified LEDs.
| field | LEDs of which to set the state (1 bit per LED). | |
| leds | New state of the specified LEDs (1 bit per LED, beginning with the first specified LED). |
Definition at line 232 of file led.c.
References LED_Display_Mask().
00233 { 00234 LED_Display_Mask(field, leds << ctz(field)); 00235 }
| void LED_Display_Mask | ( | U32 | mask, | |
| U32 | leds | |||
| ) |
Sets the state of the specified LEDs.
| mask | LEDs of which to set the state (1 bit per LED). | |
| leds | New state of the specified LEDs (1 bit per LED). |
Definition at line 127 of file led.c.
References tLED_DESCRIPTOR::GPIO, LED_COUNT, LED_State, tLED_DESCRIPTOR::PIN_MASK, and tLED_DESCRIPTOR::PORT.
Referenced by LED_Display_Field().
00128 { 00129 tLED_DESCRIPTOR *led_descriptor = &LED_DESCRIPTOR[0] - 1; 00130 volatile avr32_gpio_port_t *led_gpio_port; 00131 U8 led_shift; 00132 00133 mask &= (1 << LED_COUNT) - 1; 00134 Wr_bits(LED_State, mask, leds); 00135 while (mask) 00136 { 00137 led_shift = 1 + ctz(mask); 00138 led_descriptor += led_shift; 00139 led_gpio_port = &AVR32_GPIO.port[led_descriptor->GPIO.PORT]; 00140 leds >>= led_shift - 1; 00141 if (leds & 1) 00142 { 00143 led_gpio_port->ovrc = led_descriptor->GPIO.PIN_MASK; 00144 } 00145 else 00146 { 00147 led_gpio_port->ovrs = led_descriptor->GPIO.PIN_MASK; 00148 } 00149 led_gpio_port->oders = led_descriptor->GPIO.PIN_MASK; 00150 led_gpio_port->gpers = led_descriptor->GPIO.PIN_MASK; 00151 leds >>= 1; 00152 mask >>= led_shift; 00153 } 00154 }
| U8 LED_Get_Intensity | ( | U32 | led | ) |
Gets the intensity of the specified LED.
| led | LED of which to get the intensity (1 bit per LED; only the least significant set bit is used). |
Definition at line 238 of file led.c.
References tLED_DESCRIPTOR::CHANNEL, LED_COUNT, and tLED_DESCRIPTOR::PWM.
00239 { 00240 tLED_DESCRIPTOR *led_descriptor; 00241 00242 // Check that the argument value is valid. 00243 led = ctz(led); 00244 led_descriptor = &LED_DESCRIPTOR[led]; 00245 if (led >= LED_COUNT || led_descriptor->PWM.CHANNEL < 0) return 0; 00246 00247 // Return the duty cycle value if the LED PWM channel is enabled, else 0. 00248 return (AVR32_PWM.sr & (1 << led_descriptor->PWM.CHANNEL)) ? 00249 AVR32_PWM.channel[led_descriptor->PWM.CHANNEL].cdty : 0; 00250 }
| void LED_Off | ( | U32 | leds | ) |
Turns off the specified LEDs.
| leds | LEDs to turn off (1 bit per LED). |
Definition at line 163 of file led.c.
References tLED_DESCRIPTOR::GPIO, LED_COUNT, LED_State, tLED_DESCRIPTOR::PIN_MASK, and tLED_DESCRIPTOR::PORT.
00164 { 00165 tLED_DESCRIPTOR *led_descriptor = &LED_DESCRIPTOR[0] - 1; 00166 volatile avr32_gpio_port_t *led_gpio_port; 00167 U8 led_shift; 00168 00169 leds &= (1 << LED_COUNT) - 1; 00170 Clr_bits(LED_State, leds); 00171 while (leds) 00172 { 00173 led_shift = 1 + ctz(leds); 00174 led_descriptor += led_shift; 00175 led_gpio_port = &AVR32_GPIO.port[led_descriptor->GPIO.PORT]; 00176 led_gpio_port->ovrs = led_descriptor->GPIO.PIN_MASK; 00177 led_gpio_port->oders = led_descriptor->GPIO.PIN_MASK; 00178 led_gpio_port->gpers = led_descriptor->GPIO.PIN_MASK; 00179 leds >>= led_shift; 00180 } 00181 }
| void LED_On | ( | U32 | leds | ) |
Turns on the specified LEDs.
| leds | LEDs to turn on (1 bit per LED). |
Definition at line 184 of file led.c.
References tLED_DESCRIPTOR::GPIO, LED_COUNT, LED_State, tLED_DESCRIPTOR::PIN_MASK, and tLED_DESCRIPTOR::PORT.
00185 { 00186 tLED_DESCRIPTOR *led_descriptor = &LED_DESCRIPTOR[0] - 1; 00187 volatile avr32_gpio_port_t *led_gpio_port; 00188 U8 led_shift; 00189 00190 leds &= (1 << LED_COUNT) - 1; 00191 Set_bits(LED_State, leds); 00192 while (leds) 00193 { 00194 led_shift = 1 + ctz(leds); 00195 led_descriptor += led_shift; 00196 led_gpio_port = &AVR32_GPIO.port[led_descriptor->GPIO.PORT]; 00197 led_gpio_port->ovrc = led_descriptor->GPIO.PIN_MASK; 00198 led_gpio_port->oders = led_descriptor->GPIO.PIN_MASK; 00199 led_gpio_port->gpers = led_descriptor->GPIO.PIN_MASK; 00200 leds >>= led_shift; 00201 } 00202 }
| U32 LED_Read_Display | ( | void | ) |
| U32 LED_Read_Display_Field | ( | U32 | field | ) |
Gets as a bit-field the last state of the specified LEDs set through the LED API.
| field | LEDs of which to get the state (1 bit per LED). |
Definition at line 226 of file led.c.
References LED_State.
00227 { 00228 return Rd_bitfield(LED_State, field); 00229 }
| U32 LED_Read_Display_Mask | ( | U32 | mask | ) |
Gets the last state of the specified LEDs set through the LED API.
| mask | LEDs of which to get the state (1 bit per LED). |
Definition at line 121 of file led.c.
References LED_State.
00122 { 00123 return Rd_bits(LED_State, mask); 00124 }
| void LED_Set_Intensity | ( | U32 | leds, | |
| U8 | intensity | |||
| ) |
Sets the intensity of the specified LEDs.
| leds | LEDs of which to set the intensity (1 bit per LED). | |
| intensity | New intensity of the specified LEDs (0x00 to 0xFF). |
Definition at line 253 of file led.c.
References tLED_DESCRIPTOR::CHANNEL, tLED_DESCRIPTOR::FUNCTION, tLED_DESCRIPTOR::GPIO, LED_COUNT, tLED_DESCRIPTOR::PIN_MASK, tLED_DESCRIPTOR::PORT, and tLED_DESCRIPTOR::PWM.
00254 { 00255 tLED_DESCRIPTOR *led_descriptor = &LED_DESCRIPTOR[0] - 1; 00256 volatile avr32_pwm_channel_t *led_pwm_channel; 00257 volatile avr32_gpio_port_t *led_gpio_port; 00258 U8 led_shift; 00259 00260 // For each specified LED... 00261 for (leds &= (1 << LED_COUNT) - 1; leds; leds >>= led_shift) 00262 { 00263 // Select the next specified LED and check that it has a PWM channel. 00264 led_shift = 1 + ctz(leds); 00265 led_descriptor += led_shift; 00266 if (led_descriptor->PWM.CHANNEL < 0) continue; 00267 00268 // Initialize or update the LED PWM channel. 00269 led_pwm_channel = &AVR32_PWM.channel[led_descriptor->PWM.CHANNEL]; 00270 if (!(AVR32_PWM.sr & (1 << led_descriptor->PWM.CHANNEL))) 00271 { 00272 led_pwm_channel->cmr = (AVR32_PWM_CPRE_MCK << AVR32_PWM_CPRE_OFFSET) & 00273 ~(AVR32_PWM_CALG_MASK | 00274 AVR32_PWM_CPOL_MASK | 00275 AVR32_PWM_CPD_MASK); 00276 led_pwm_channel->cprd = 0x000000FF; 00277 led_pwm_channel->cdty = intensity; 00278 AVR32_PWM.ena = 1 << led_descriptor->PWM.CHANNEL; 00279 } 00280 else 00281 { 00282 AVR32_PWM.isr; 00283 while (!(AVR32_PWM.isr & (1 << led_descriptor->PWM.CHANNEL))); 00284 led_pwm_channel->cupd = intensity; 00285 } 00286 00287 // Switch the LED pin to its PWM function. 00288 led_gpio_port = &AVR32_GPIO.port[led_descriptor->GPIO.PORT]; 00289 if (led_descriptor->PWM.FUNCTION & 0x1) 00290 { 00291 led_gpio_port->pmr0s = led_descriptor->GPIO.PIN_MASK; 00292 } 00293 else 00294 { 00295 led_gpio_port->pmr0c = led_descriptor->GPIO.PIN_MASK; 00296 } 00297 if (led_descriptor->PWM.FUNCTION & 0x2) 00298 { 00299 led_gpio_port->pmr1s = led_descriptor->GPIO.PIN_MASK; 00300 } 00301 else 00302 { 00303 led_gpio_port->pmr1c = led_descriptor->GPIO.PIN_MASK; 00304 } 00305 led_gpio_port->gperc = led_descriptor->GPIO.PIN_MASK; 00306 } 00307 }
| Bool LED_Test | ( | U32 | leds | ) |
Tests the last state of the specified LEDs set through the LED API.
| leds | LEDs of which to test the state (1 bit per LED). |
TRUE if at least one of the specified LEDs has a state on, else FALSE.Definition at line 157 of file led.c.
References LED_State.
00158 { 00159 return Tst_bits(LED_State, leds); 00160 }
| void LED_Toggle | ( | U32 | leds | ) |
Toggles the specified LEDs.
| leds | LEDs to toggle (1 bit per LED). |
Definition at line 205 of file led.c.
References tLED_DESCRIPTOR::GPIO, LED_COUNT, LED_State, tLED_DESCRIPTOR::PIN_MASK, and tLED_DESCRIPTOR::PORT.
00206 { 00207 tLED_DESCRIPTOR *led_descriptor = &LED_DESCRIPTOR[0] - 1; 00208 volatile avr32_gpio_port_t *led_gpio_port; 00209 U8 led_shift; 00210 00211 leds &= (1 << LED_COUNT) - 1; 00212 Tgl_bits(LED_State, leds); 00213 while (leds) 00214 { 00215 led_shift = 1 + ctz(leds); 00216 led_descriptor += led_shift; 00217 led_gpio_port = &AVR32_GPIO.port[led_descriptor->GPIO.PORT]; 00218 led_gpio_port->ovrt = led_descriptor->GPIO.PIN_MASK; 00219 led_gpio_port->oders = led_descriptor->GPIO.PIN_MASK; 00220 led_gpio_port->gpers = led_descriptor->GPIO.PIN_MASK; 00221 leds >>= led_shift; 00222 } 00223 }
tLED_DESCRIPTOR LED_DESCRIPTOR[LED_COUNT] [static] |
volatile U32 LED_State = (1 << LED_COUNT) - 1 [static] |
Saved state of all LEDs.
Definition at line 85 of file led.c.
Referenced by LED_Display(), LED_Display_Mask(), LED_Off(), LED_On(), LED_Read_Display(), LED_Read_Display_Field(), LED_Read_Display_Mask(), LED_Test(), and LED_Toggle().
1.5.3-20071008