qleds.c

00001 /*
00002  * Copyright (c) 2007, Swedish Institute of Computer Science
00003  * All rights reserved. 
00004  *
00005  * Redistribution and use in source and binary forms, with or without 
00006  * modification, are permitted provided that the following conditions 
00007  * are met: 
00008  * 1. Redistributions of source code must retain the above copyright 
00009  *    notice, this list of conditions and the following disclaimer. 
00010  * 2. Redistributions in binary form must reproduce the above copyright 
00011  *    notice, this list of conditions and the following disclaimer in the 
00012  *    documentation and/or other materials provided with the distribution. 
00013  * 3. Neither the name of the Institute nor the names of its contributors 
00014  *    may be used to endorse or promote products derived from this software 
00015  *    without specific prior written permission. 
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 
00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 
00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
00027  * SUCH DAMAGE. 
00028  *
00029  * @(#)$Id: qleds.c,v 1.1 2007/02/02 14:07:34 bg- Exp $
00030  */
00031 
00032 #include "contiki.h"
00033 
00034 #include "dev/leds.h"
00035 
00036 #include <avr/io.h>
00037 
00038 void
00039 leds_init(void)
00040 {
00041 #ifdef CB_GATEWAY
00042   DDRE  |= LEDS_CONF_GREEN | LEDS_CONF_YELLOW;
00043   PORTE |= LEDS_CONF_GREEN | LEDS_CONF_YELLOW; /* LEDS off */
00044 #else
00045   DDRB  |= LEDS_CONF_ORANGE | LEDS_CONF_GREEN;
00046   DDRE  |= LEDS_CONF_RED | LEDS_CONF_YELLOW;
00047 
00048   PORTB &= ~(LEDS_CONF_ORANGE | LEDS_CONF_GREEN);
00049   PORTE &= ~(LEDS_CONF_RED | LEDS_CONF_YELLOW);
00050 #endif
00051 }
00052 
00053 void
00054 leds_on(unsigned char leds)
00055 {
00056 #ifdef CB_GATEWAY
00057   if (leds & LEDS_GREEN)
00058     PORTE &= ~LEDS_CONF_GREEN;
00059   if (leds & LEDS_YELLOW)
00060     PORTE &= ~LEDS_CONF_YELLOW;
00061 #else
00062   if (leds & LEDS_ORANGE)
00063     PORTB |= LEDS_CONF_ORANGE;
00064   if (leds & LEDS_GREEN)
00065     PORTB |= LEDS_CONF_GREEN;
00066 
00067   if (leds & LEDS_RED)
00068     PORTE |= LEDS_CONF_RED;
00069   if (leds & LEDS_YELLOW)
00070     PORTE |= LEDS_CONF_YELLOW;
00071 #endif
00072 }
00073 
00074 void
00075 leds_off(unsigned char leds)
00076 {
00077 #ifdef CB_GATEWAY
00078   if (leds & LEDS_GREEN)
00079     PORTE |= LEDS_CONF_GREEN;
00080   if (leds & LEDS_YELLOW)
00081     PORTE |= LEDS_CONF_YELLOW;
00082 #else
00083   if (leds & LEDS_ORANGE)
00084     PORTB &= ~LEDS_CONF_ORANGE;
00085   if (leds & LEDS_GREEN)
00086     PORTB &= ~LEDS_CONF_GREEN;
00087 
00088   if (leds & LEDS_RED)
00089     PORTE &= ~LEDS_CONF_RED;
00090   if (leds & LEDS_YELLOW)
00091     PORTE &= ~LEDS_CONF_YELLOW;
00092 #endif
00093 }
00094 
00095 void
00096 leds_toggle(unsigned char leds)
00097 {
00098   /*
00099    * Synonym: void leds_invert(unsigned char leds);
00100    */
00101   asm(".global leds_invert\nleds_invert:\n");
00102 
00103 #ifdef CB_GATEWAY
00104   if (leds & LEDS_GREEN)
00105     PORTE ^= ~LEDS_CONF_GREEN;
00106   if (leds & LEDS_YELLOW)
00107     PORTE ^= ~LEDS_CONF_YELLOW;
00108 #else
00109   if (leds & LEDS_ORANGE)
00110     PORTB ^= LEDS_CONF_ORANGE;
00111   if (leds & LEDS_GREEN)
00112     PORTB ^= LEDS_CONF_GREEN;
00113 
00114   if (leds & LEDS_RED)
00115     PORTE ^= LEDS_CONF_RED;
00116   if (leds & LEDS_YELLOW)
00117     PORTE ^= LEDS_CONF_YELLOW;
00118 #endif
00119 }

Generated on Mon Apr 11 14:23:42 2011 for Contiki 2.5 by  doxygen 1.6.1