diff --git a/platform/avr-raven/Makefile.avr-raven b/platform/avr-raven/Makefile.avr-raven new file mode 100644 index 000000000..93fa1736c --- /dev/null +++ b/platform/avr-raven/Makefile.avr-raven @@ -0,0 +1,39 @@ +CONTIKI_TARGET_DIRS = . rf230 apps net loader +CONTIKI_CORE=contiki-raven-main +CONTIKI_TARGET_MAIN = ${CONTIKI_CORE}.o + +CONTIKI_TARGET_SOURCEFILES += rs232.c slip.c cfs-eeprom.c eeprom.c random.c \ + mmem.c contiki-raven-main.c contiki-raven-default-init-net.c + +CONTIKIAVR=$(CONTIKI)/cpu/avr +CONTIKIBOARD=. + +CONTIKI_PLAT_DEFS = -DF_CPU=8000000UL -DAUTO_CRC_PADDING=2 + +MCU=atmega1284p +AVRDUDE_PROGRAMMER=jtag2 + +# For usb devices, you may either use PORT=usb, or (e.g. if you have more than one +# programmer connected) you can use the following trick to find out the serial number: +# +# The example is for an JTAGICE mkII used to program an ATmega128: +# avrdude -v -P usb:xxxx -c jtag2 -p atmega128 +AVRDUDE_PORT=usb:00B000000D79 + + + +# Additional avrdude options +# Verify off +AVRDUDE_OPTIONS=-V + + +include $(CONTIKIAVR)/Makefile.avr + +# Source for AT86RF230 +include $(CONTIKI)/cpu/avr/radio/rf230/Makefile.rf230 + +# Source for Atmel/Cisco 802.15.4'ish MAC +include $(CONTIKI)/cpu/avr/radio/mac/Makefile.mac + +# Source for IEEE 802.15.4 manager interface +include $(CONTIKI)/cpu/avr/radio/ieee-manager/Makefile.ieee-manager diff --git a/platform/avr-raven/avr-raven-eeprom.hex b/platform/avr-raven/avr-raven-eeprom.hex new file mode 100755 index 000000000..a8d3cdcfb --- /dev/null +++ b/platform/avr-raven/avr-raven-eeprom.hex @@ -0,0 +1,65 @@ +:100000000011223344556677FFFFFFFFFFFFFFFF1C +:10001000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0 +:10002000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE0 +:10003000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD0 +:10004000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC0 +:10005000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFB0 +:10006000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA0 +:10007000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF90 +:10008000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF80 +:10009000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF70 +:1000A000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF60 +:1000B000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF50 +:1000C000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF40 +:1000D000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF30 +:1000E000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF20 +:1000F000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF10 +:10010000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF +:10011000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEF +:10012000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFDF +:10013000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFCF +:10014000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFBF +:10015000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFAF +:10016000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF9F +:10017000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF8F +:10018000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7F +:10019000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF6F +:1001A000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5F +:1001B000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF4F +:1001C000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3F +:1001D000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF2F +:1001E000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF1F +:1001F000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0F +:10020000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE +:10021000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEE +:10022000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFDE +:10023000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFCE +:10024000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFBE +:10025000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFAE +:10026000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF9E +:10027000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF8E +:10028000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7E +:10029000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF6E +:1002A000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5E +:1002B000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF4E +:1002C000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3E +:1002D000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF2E +:1002E000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF1E +:1002F000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0E +:10030000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD +:10031000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFED +:10032000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFDD +:10033000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFCD +:10034000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFBD +:10035000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFAD +:10036000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF9D +:10037000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF8D +:10038000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7D +:10039000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF6D +:1003A000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D +:1003B000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF4D +:1003C000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3D +:1003D000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF2D +:1003E000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF1D +:1003F000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0D +:00000001FF diff --git a/platform/avr-raven/contiki-conf.h b/platform/avr-raven/contiki-conf.h new file mode 100644 index 000000000..d85d1ccc6 --- /dev/null +++ b/platform/avr-raven/contiki-conf.h @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2006, Technical University of Munich + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the Contiki operating system. + * + * @(#)$$ + */ + +/** + * \file + * Configuration for sample STK 501 Contiki kernel + * + * \author + * Simon Barner + +typedef int32_t s32_t; + +/* + * MCU and clock rate + */ +#define MCU_MHZ 8 +#define PLATFORM PLATFORM_AVR + +/* Clock ticks per second */ +#define CLOCK_CONF_SECOND 125 + +/* COM port to be used for SLIP connection */ +#define SLIP_PORT RS232_PORT_0 + +/* Pre-allocated memory for loadable modules heap space (in bytes)*/ +#define MMEM_CONF_SIZE 256 + +/* Use the following address for code received via the codeprop + * facility + */ +#define EEPROMFS_ADDR_CODEPROP 0x8000 + +#define CCIF +#define CLIF + +#define RIMEADDR_CONF_SIZE 8 +#define RIMEBUF_CONF_HDR_SIZE 0 + +/* 0 for IPv6, or 1 for HC1, 2 for HC01 */ +#define SICSLOWPAN_CONF_COMPRESSION_IPV6 0 +#define SICSLOWPAN_CONF_COMPRESSION_HC1 1 +#define SICSLOWPAN_CONF_COMPRESSION_HC01 2 + +#define SICSLOWPAN_CONF_COMPRESSION SICSLOWPAN_CONF_COMPRESSION_HC01 +#define SICSLOWPAN_CONF_MAX_ADDR_CONTEXTS 2 +#define SICSLOWPAN_CONF_FRAG 1 + +#define SICSLOWPAN_CONF_MAXAGE 5 + +#define UIP_CONF_LL_802154 1 +#define UIP_CONF_LLH_LEN 0 + +#define UIP_CONF_MAX_CONNECTIONS 2 +#define UIP_CONF_MAX_LISTENPORTS 2 +#define UIP_CONF_UDP_CONNS 2 + +#define UIP_CONF_IP_FORWARD 0 +#define UIP_CONF_FWCACHE_SIZE 0 + +#define UIP_CONF_IPV6 1 +#define UIP_CONF_IPV6_CHECKS 1 +#define UIP_CONF_IPV6_QUEUE_PKT 1 +#define UIP_CONF_IPV6_REASSEMBLY 0 +#define UIP_CONF_NETIF_MAX_ADDRESSES 3 +#define UIP_CONF_ND6_MAX_PREFIXES 3 +#define UIP_CONF_ND6_MAX_NEIGHBORS 4 +#define UIP_CONF_ND6_MAX_DEFROUTERS 2 + +#define UIP_CONF_UDP 1 +#define UIP_CONF_UDP_CHECKSUMS 1 + +#define UIP_CONF_TCP 1 +#define UIP_CONF_TCP_SPLIT 1 + + +typedef unsigned short clock_time_t; +typedef unsigned char u8_t; +typedef unsigned short u16_t; +typedef unsigned long u32_t; +typedef unsigned short uip_stats_t; +typedef unsigned long off_t; + +void clock_delay(unsigned int us2); +void clock_wait(int ms10); +void clock_set_seconds(unsigned long s); +unsigned long clock_seconds(void); + +#endif /* __CONTIKI_CONF_H__ */ diff --git a/platform/avr-raven/contiki-raven-default-init-lowlevel.c b/platform/avr-raven/contiki-raven-default-init-lowlevel.c new file mode 100644 index 000000000..a2e0cfc84 --- /dev/null +++ b/platform/avr-raven/contiki-raven-default-init-lowlevel.c @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2006, Technical University of Munich + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the Contiki operating system. + * + * Author: Simon Barner + * + * @(#)$$ + */ +#include "contiki-raven.h" + +void +init_lowlevel(void) +{ + /* Configure default slip port with 19200 baud */ + //rs232_init(RS232_PORT_0, USART_BAUD_19200, USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8); + + /* Second rs232 port for debugging */ + rs232_init(RS232_PORT_1, USART_BAUD_57600, USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8); + + /* Redirect stdout to second port */ + rs232_redirect_stdout (RS232_PORT_1); +} diff --git a/platform/avr-raven/contiki-raven-default-init-net.c b/platform/avr-raven/contiki-raven-default-init-net.c new file mode 100644 index 000000000..39a7a161f --- /dev/null +++ b/platform/avr-raven/contiki-raven-default-init-net.c @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2006, Technical University of Munich + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the Contiki operating system. + * + * Author: Simon Barner + * + * @(#)$$ + */ + +#include "contiki-raven.h" +#include "contiki-net.h" + + +void +init_net(void) +{ + + uip_ipaddr_t ipprefix; + + uip_ip6addr(&ipprefix, 0xaaaa, 0, 0, 0, 0, 0, 0, 0); + + uip_netif_addr_add(&ipprefix, UIP_DEFAULT_PREFIX_LEN, 0, AUTOCONF); + uip_nd6_prefix_add(&ipprefix, UIP_DEFAULT_PREFIX_LEN, 0); + +} diff --git a/platform/avr-raven/contiki-raven-main.c b/platform/avr-raven/contiki-raven-main.c new file mode 100644 index 000000000..fb60fa03e --- /dev/null +++ b/platform/avr-raven/contiki-raven-main.c @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2006, Technical University of Munich + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the Contiki operating system. + * + * @(#)$$ + */ + +/** + * \file + * Sample Contiki kernel for STK 501 development board + * + * \author + * Simon Barner +#include + +#include "lib/mmem.h" +#include "loader/symbols-def.h" +#include "loader/symtab.h" +#include +#include "mac.h" +#include "sicslowmac.h" +#include "sicslowpan.h" +#include "ieee-15-4-manager.h" + +#include "contiki.h" +#include "contiki-net.h" +#include "contiki-lib.h" + +#include "dev/rs232.h" +#include "dev/serial.h" +#include "dev/slip.h" + +#include "raven-lcd.h" + +#include "sicslowmac.h" + + +PROCINIT(&etimer_process, &mac_process, &tcpip_process, &raven_lcd_process); + + +void +init_lowlevel(void) +{ + /* First rs232 port for Raven 3290 port */ + rs232_init(RS232_PORT_0, USART_BAUD_38400, + USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8); + + /* Set input handler for 3290 port */ + rs232_set_input(0,raven_lcd_serial_input); + + /* Second rs232 port for debugging */ + rs232_init(RS232_PORT_1, USART_BAUD_57600, + USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8); + + /* Redirect stdout to second port */ + rs232_redirect_stdout(RS232_PORT_1); +} + + +int +main(void) +{ + //calibrate_rc_osc_32k(); //CO: Had to comment this out + + /* Initialize hardware */ + init_lowlevel(); + + /* Clock */ + clock_init(); + + + /* Process subsystem */ + process_init(); + + /* Register initial processes */ + procinit_init(); + + /* Autostart processes */ + autostart_start(autostart_processes); + + //Give ourselves a prefix + init_net(); + + printf_P(PSTR("\n********BOOTING CONTIKI*********\n")); + + printf_P(PSTR("System online.\n")); + + /* Main scheduler loop */ + while(1) { + process_run(); + } + + return 0; +} diff --git a/platform/avr-raven/contiki-raven.h b/platform/avr-raven/contiki-raven.h new file mode 100644 index 000000000..e640944a5 --- /dev/null +++ b/platform/avr-raven/contiki-raven.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2006, Technical University of Munich + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the Contiki operating system. + * + * @(#)$$ + */ + +/** + * \file + * Sample Contiki kernel for STK 501 development board + * + * \author + * Simon Barner + */ +#include +#include "dev/rs232.h" +#include "contiki.h" + +PROCESS(test_process1, "Test process"); +PROCESS_THREAD(test_process1, ev, data) +{ + static struct etimer etimer; + + PROCESS_BEGIN(); + + rs232_print (RS232_PORT_1, "test_process 1 starting\n"); + + while(1) { + etimer_set(&etimer, CLOCK_SECOND); + PROCESS_WAIT_UNTIL(etimer_expired(&etimer)); + rs232_print (RS232_PORT_1, "Tick\n"); + etimer_set(&etimer, CLOCK_SECOND); + PROCESS_WAIT_UNTIL(etimer_expired(&etimer)); + rs232_print (RS232_PORT_1, "Tack\n"); + } + + PROCESS_END(); +} + + +CLIF struct process * const autostart_processes[] = {&test_process1}; diff --git a/platform/avr-ravenlcd/Makefile b/platform/avr-ravenlcd/Makefile new file mode 100644 index 000000000..684005ebc --- /dev/null +++ b/platform/avr-ravenlcd/Makefile @@ -0,0 +1,79 @@ +# Hey Emacs, this is a -*- makefile -*- +############################################################################### +# Makefile for the RES-Raven-Mega3290 project +############################################################################### + +## General Flags +PROJECT = ravenlcd_3290 +MCU = atmega3290 +TARGET = $(PROJECT).elf +CC = avr-gcc + +## Options common to compile, link and assembly rules +COMMON = -mmcu=$(MCU) +COMMON += -DF_CPU=8000000UL + +## Compile options common for all C compilation units. +CFLAGS = $(COMMON) $(CEXTRA) +CFLAGS += -D AVRGCC -Wall -gstabs -Os -fsigned-char +CFLAGS += -MD -MP -MT $(*F).o -MF dep/$(@F).d +CFLAGS += -fshort-enums + +## Assembly specific flags +ASMFLAGS = $(COMMON) +ASMFLAGS += -x assembler-with-cpp -Wa,-gstabs + +## Linker flags +LDFLAGS = $(COMMON) +LDFLAGS += -Wl,-Map=$(PROJECT).map,--cref + +## Intel Hex file production flags +HEX_FLASH_FLAGS = -R .eeprom + +HEX_EEPROM_FLAGS = -j .eeprom +HEX_EEPROM_FLAGS += --set-section-flags=.eeprom="alloc,load" +HEX_EEPROM_FLAGS += --change-section-lma .eeprom=0 + +## Include Directories +INCLUDES = + +## Objects that must be built in order to link +SRC = adc.c key.c lcd.c raven3290.c uart.c menu.c sleep.c beep.c temp.c timer.c + +OBJECTS = $(SRC:.c=.o) + +## Objects explicitly added by the user +LINKONLYOBJECTS = + +## Build +all: $(TARGET) $(PROJECT).hex $(PROJECT).eep $(PROJECT).lss size + +## Compile: create object files from C source files. +.c.o: + $(CC) $(INCLUDES) $(CFLAGS) -c $< + +##Link +$(TARGET): $(OBJECTS) + $(CC) $(LDFLAGS) $(OBJECTS) $(LINKONLYOBJECTS) $(LIBDIRS) $(LIBS) -o $(TARGET) + +%.hex: $(TARGET) + avr-objcopy -O ihex $(HEX_FLASH_FLAGS) $< $@ + +%.eep: $(TARGET) + avr-objcopy $(HEX_EEPROM_FLAGS) -O ihex $< $@ || exit 0 + +%.lss: $(TARGET) + avr-objdump -h -S $< > $@ + +size: ${TARGET} + @echo + @avr-size -C --mcu=${MCU} ${TARGET} + +## Clean target +.PHONY: clean +clean: + -rm -rf $(OBJECTS) $(PROJECT).elf dep/* $(PROJECT).hex $(PROJECT).eep $(PROJECT).map $(PROJECT).lss + +## Other dependencies +-include $(shell mkdir dep 2>/dev/null) $(wildcard dep/*) + diff --git a/platform/avr-ravenlcd/adc.c b/platform/avr-ravenlcd/adc.c new file mode 100644 index 000000000..1ed20ee13 --- /dev/null +++ b/platform/avr-ravenlcd/adc.c @@ -0,0 +1,139 @@ +/* + * Copyright (c) 2008 Swedish Institute of Computer Science + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of the copyright holders nor the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +/** + * \file + * + * \brief + * Functions to control the ADC of the MCU. This is used to read the + * joystick. + * + * \author + * Mike Vidales mavida404@gmail.com + * + */ + +#include "adc.h" + +/** + * \addtogroup lcd + * \{ +*/ + +static bool adc_initialized; +static bool adc_conversion_started; + +/*---------------------------------------------------------------------------*/ + +/** + * \brief This function will init the ADC with the following parameters. + * + * \param chan Determines the ADC channel to open. + * \param trig Sets what type of trigger is needed. + * \param ref Sets the proper reference voltage. + * \param prescale Sets the prescale to be used against the XTAL choice. + * + * \return 0 +*/ +int +adc_init(adc_chan_t chan, adc_trig_t trig, adc_ref_t ref, adc_ps_t prescale) +{ + /* Enable ADC module */ + PRR &= ~(1 << PRADC); + + /* Configure */ + ADCSRA = (1< +#include +#include +#include + +#define adc_conversion_ongoing (ADCSRA |= (1< + +/** \name Definition of Port Pin for beeper. */ +/** \{ */ +#define BEEP_PORT PORTB +#define BEEP_DDR DDRB +#define BEEP_PIN PINB +#define BEEP_BIT 5 +/** \} */ + +void beep(void); + +#endif /* BEEP_H */ diff --git a/platform/avr-ravenlcd/doc/Doxyfile b/platform/avr-ravenlcd/doc/Doxyfile new file mode 100644 index 000000000..e87bf474f --- /dev/null +++ b/platform/avr-ravenlcd/doc/Doxyfile @@ -0,0 +1,240 @@ +# Doxyfile 1.4.1 + +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- +PROJECT_NAME = "Contiki 6LoWPAN Menu" +PROJECT_NUMBER = +OUTPUT_DIRECTORY = . +CREATE_SUBDIRS = NO +OUTPUT_LANGUAGE = English +USE_WINDOWS_ENCODING = NO +BRIEF_MEMBER_DESC = YES +REPEAT_BRIEF = YES +ABBREVIATE_BRIEF = +ALWAYS_DETAILED_SEC = NO +INLINE_INHERITED_MEMB = NO +FULL_PATH_NAMES = YES +STRIP_FROM_PATH = ../ +STRIP_FROM_INC_PATH = +SHORT_NAMES = YES +JAVADOC_AUTOBRIEF = YES +MULTILINE_CPP_IS_BRIEF = NO +DETAILS_AT_TOP = YES +INHERIT_DOCS = YES +DISTRIBUTE_GROUP_DOC = NO +TAB_SIZE = 8 +ALIASES = +OPTIMIZE_OUTPUT_FOR_C = YES +OPTIMIZE_OUTPUT_JAVA = NO +SUBGROUPING = YES +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- +EXTRACT_ALL = NO +EXTRACT_PRIVATE = NO +EXTRACT_STATIC = YES +EXTRACT_LOCAL_CLASSES = NO +EXTRACT_LOCAL_METHODS = NO +HIDE_UNDOC_MEMBERS = YES +HIDE_UNDOC_CLASSES = YES +HIDE_FRIEND_COMPOUNDS = NO +HIDE_IN_BODY_DOCS = NO +INTERNAL_DOCS = NO +CASE_SENSE_NAMES = YES +HIDE_SCOPE_NAMES = NO +SHOW_INCLUDE_FILES = YES +INLINE_INFO = YES +SORT_MEMBER_DOCS = YES +SORT_BRIEF_DOCS = NO +SORT_BY_SCOPE_NAME = NO +GENERATE_TODOLIST = YES +GENERATE_TESTLIST = YES +GENERATE_BUGLIST = NO +GENERATE_DEPRECATEDLIST= NO +ENABLED_SECTIONS = +MAX_INITIALIZER_LINES = 30 +SHOW_USED_FILES = NO +SHOW_DIRECTORIES = YES +FILE_VERSION_FILTER = +#--------------------------------------------------------------------------- +# configuration options related to warning and progress messages +#--------------------------------------------------------------------------- +QUIET = NO +WARNINGS = YES +WARN_IF_UNDOCUMENTED = NO +WARN_IF_DOC_ERROR = YES +WARN_NO_PARAMDOC = NO +WARN_FORMAT = "$file:$line: $text" +WARN_LOGFILE = +#--------------------------------------------------------------------------- +# configuration options related to the input files +#--------------------------------------------------------------------------- +INPUT = ../adc.c \ + ../beep.c \ + ../key.c \ + ../lcd.c \ + ../menu.c \ + ../raven3290.c \ + ../sleep.c \ + ../temp.c \ + ../timer.c \ + ../uart.c \ + ../adc.h \ + ../beep.h \ + ../key.h \ + ../lcd.h \ + ../menu.h \ + ../main.h \ + ../sleep.h \ + ../temp.h \ + ../timer.h \ + ../uart.h + +FILE_PATTERNS = +RECURSIVE = NO +EXCLUDE = +EXCLUDE_SYMLINKS = NO +EXCLUDE_PATTERNS = +EXAMPLE_PATH = +EXAMPLE_PATTERNS = +EXAMPLE_RECURSIVE = NO +IMAGE_PATH = ./pics +INPUT_FILTER = +FILTER_PATTERNS = +FILTER_SOURCE_FILES = NO +#--------------------------------------------------------------------------- +# configuration options related to source browsing +#--------------------------------------------------------------------------- +SOURCE_BROWSER = YES +INLINE_SOURCES = NO +STRIP_CODE_COMMENTS = NO +REFERENCED_BY_RELATION = YES +REFERENCES_RELATION = YES +VERBATIM_HEADERS = YES +#--------------------------------------------------------------------------- +# configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- +ALPHABETICAL_INDEX = YES +COLS_IN_ALPHA_INDEX = 5 +IGNORE_PREFIX = +#--------------------------------------------------------------------------- +# configuration options related to the HTML output +#--------------------------------------------------------------------------- +GENERATE_HTML = YES +HTML_OUTPUT = html +HTML_FILE_EXTENSION = .html +HTML_HEADER = +HTML_FOOTER = +HTML_STYLESHEET = +HTML_ALIGN_MEMBERS = YES +GENERATE_HTMLHELP = YES +CHM_FILE = +HHC_LOCATION = +GENERATE_CHI = YES +BINARY_TOC = YES +TOC_EXPAND = YES +DISABLE_INDEX = NO +ENUM_VALUES_PER_LINE = 4 +GENERATE_TREEVIEW = YES +TREEVIEW_WIDTH = 250 +#--------------------------------------------------------------------------- +# configuration options related to the LaTeX output +#--------------------------------------------------------------------------- +GENERATE_LATEX = YES +LATEX_OUTPUT = latex +LATEX_CMD_NAME = latex +MAKEINDEX_CMD_NAME = makeindex +COMPACT_LATEX = YES +PAPER_TYPE = a4wide +EXTRA_PACKAGES = +LATEX_HEADER = +PDF_HYPERLINKS = YES +USE_PDFLATEX = YES +LATEX_BATCHMODE = NO +LATEX_HIDE_INDICES = NO +#--------------------------------------------------------------------------- +# configuration options related to the RTF output +#--------------------------------------------------------------------------- +GENERATE_RTF = NO +RTF_OUTPUT = rtf +COMPACT_RTF = NO +RTF_HYPERLINKS = NO +RTF_STYLESHEET_FILE = +RTF_EXTENSIONS_FILE = +#--------------------------------------------------------------------------- +# configuration options related to the man page output +#--------------------------------------------------------------------------- +GENERATE_MAN = NO +MAN_OUTPUT = man +MAN_EXTENSION = .3 +MAN_LINKS = NO +#--------------------------------------------------------------------------- +# configuration options related to the XML output +#--------------------------------------------------------------------------- +GENERATE_XML = NO +XML_OUTPUT = xml +XML_SCHEMA = +XML_DTD = +XML_PROGRAMLISTING = YES +#--------------------------------------------------------------------------- +# configuration options for the AutoGen Definitions output +#--------------------------------------------------------------------------- +GENERATE_AUTOGEN_DEF = NO +#--------------------------------------------------------------------------- +# configuration options related to the Perl module output +#--------------------------------------------------------------------------- +GENERATE_PERLMOD = NO +PERLMOD_LATEX = NO +PERLMOD_PRETTY = YES +PERLMOD_MAKEVAR_PREFIX = +#--------------------------------------------------------------------------- +# Configuration options related to the preprocessor +#--------------------------------------------------------------------------- +ENABLE_PREPROCESSING = YES +MACRO_EXPANSION = NO +EXPAND_ONLY_PREDEF = NO +SEARCH_INCLUDES = YES +INCLUDE_PATH = +INCLUDE_FILE_PATTERNS = +PREDEFINED = DOXYGEN +EXPAND_AS_DEFINED = +SKIP_FUNCTION_MACROS = YES +#--------------------------------------------------------------------------- +# Configuration::additions related to external references +#--------------------------------------------------------------------------- +TAGFILES = +GENERATE_TAGFILE = +ALLEXTERNALS = NO +EXTERNAL_GROUPS = YES +PERL_PATH = /usr/bin/perl +#--------------------------------------------------------------------------- +# Configuration options related to the dot tool +#--------------------------------------------------------------------------- +CLASS_DIAGRAMS = NO +HIDE_UNDOC_RELATIONS = YES +HAVE_DOT = YES +CLASS_GRAPH = NO +COLLABORATION_GRAPH = NO +GROUP_GRAPHS = NO +UML_LOOK = NO +TEMPLATE_RELATIONS = NO +INCLUDE_GRAPH = NO +INCLUDED_BY_GRAPH = NO +CALL_GRAPH = NO +GRAPHICAL_HIERARCHY = NO +DIRECTORY_GRAPH = NO +DOT_IMAGE_FORMAT = png +DOT_PATH = +DOTFILE_DIRS = +MAX_DOT_GRAPH_WIDTH = 1024 +MAX_DOT_GRAPH_HEIGHT = 1024 +MAX_DOT_GRAPH_DEPTH = 0 +DOT_TRANSPARENT = NO +DOT_MULTI_TARGETS = NO +GENERATE_LEGEND = YES +DOT_CLEANUP = YES +#--------------------------------------------------------------------------- +# Configuration::additions related to the search engine +#--------------------------------------------------------------------------- +SEARCHENGINE = NO diff --git a/platform/avr-ravenlcd/doc/Makefile b/platform/avr-ravenlcd/doc/Makefile new file mode 100644 index 000000000..895bcf707 --- /dev/null +++ b/platform/avr-ravenlcd/doc/Makefile @@ -0,0 +1,12 @@ +# This target requires and graphviz and doxygen +dox: + doxygen Doxyfile + + +pdf: + $(MAKE) -C latex refman.pdf + +upload: dox #pdf +# scp -C latex/refman.pdf adamdunkels@shell.sourceforge.net:/home/groups/c/co/contiki/htdocs/ +# tar czfv - html | ssh adamdunkels@shell.sourceforge.net "cd /home/groups/c/co/contiki/htdocs/; tar xfz -" + (cd html; rsync -rv . kloster.sics.se:/home/adam/public_html/contiki/docs) diff --git a/platform/avr-ravenlcd/doc/pics/caution.gif b/platform/avr-ravenlcd/doc/pics/caution.gif new file mode 100644 index 000000000..c58de8e86 Binary files /dev/null and b/platform/avr-ravenlcd/doc/pics/caution.gif differ diff --git a/platform/avr-ravenlcd/doc/pics/contiki_menu_3290.jpg b/platform/avr-ravenlcd/doc/pics/contiki_menu_3290.jpg new file mode 100644 index 000000000..a5b2699f5 Binary files /dev/null and b/platform/avr-ravenlcd/doc/pics/contiki_menu_3290.jpg differ diff --git a/platform/avr-ravenlcd/key.c b/platform/avr-ravenlcd/key.c new file mode 100644 index 000000000..f656acbbc --- /dev/null +++ b/platform/avr-ravenlcd/key.c @@ -0,0 +1,204 @@ +/* + * Copyright (c) 2008 Swedish Institute of Computer Science + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of the copyright holders nor the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +/** + * \file + * + * \brief + * This file provides joystick operations. Combined with ADC functions. + * + * \author + * Mike Vidales mavida404@gmail.com + * + */ + +#include "key.h" +#include "uart.h" +#include "main.h" +#include "adc.h" + +/** + * \addtogroup lcd + * \{ +*/ + +/*---------------------------------------------------------------------------*/ + +/** + * \brief This will intialize the joystick and the ADC for button readings. +*/ +void +key_init(void) +{ + /* Disable digital input buffer for joystick signal */ + DIDR0 |= (1 << ADC1D); + + /* Enter is input w/pullup */ + ENTER_DDR &= ~(1< +#include +#include + + + +/** \name Port definition for reading the joystick input. */ +/** \{ */ +#define KEY_PORT PINF +#define KEY_PUR PORTF +#define KEY_DDR DDRF +#define KEY_PIN PINF1 +/** \} */ + +/** \name Port defininition for the joystick Enter button. */ +/** \{ */ +#define ENTER_PORT PINE +#define ENTER_PUR PORTE +#define ENTER_DDR DDRE +#define ENTER_PIN PINE2 +/** \} */ + +/** \name Valid Key States. */ +/** \{ */ +#define KEY_STATE_UP 0x01 +#define KEY_STATE_DOWN 0x02 +#define KEY_STATE_LEFT 0x04 +#define KEY_STATE_RIGHT 0x08 +#define KEY_STATE_ENTER 0x10 +#define KEY_STATE_NO_KEY 0x00 +#define KEY_STATE_DONE 0x20 +/** \} */ + +typedef enum { + KEY_UP = 0x01, + KEY_DOWN = 0x02, + KEY_LEFT = 0x04, + KEY_RIGHT = 0x08, + KEY_ENTER = 0x10, + KEY_NO_KEY = 0x00 +}key_state_t; + +extern key_state_t button; + +/* Initialize the joystick */ +void key_init(void); +void key_deinit(void); +key_state_t key_task(void); +key_state_t key_state_get(void); +uint8_t is_button(void); +uint8_t get_button(void); + +#endif /* __KEY_H__ */ diff --git a/platform/avr-ravenlcd/lcd.c b/platform/avr-ravenlcd/lcd.c new file mode 100644 index 000000000..0fe92b80a --- /dev/null +++ b/platform/avr-ravenlcd/lcd.c @@ -0,0 +1,895 @@ +/* + * Copyright (c) 2008 Swedish Institute of Computer Science + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of the copyright holders nor the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +/** + * \file + * + * \brief + * This file provides Raven LCD support. + * + * \author + * Mike Vidales mavida404@gmail.com + * + */ + +#include "lcd.h" + +/** + * \addtogroup lcd + * \{ +*/ + +typedef enum { + LCD_DUTY_STATIC = 0, + LCD_DUTY_HALF = 1, + LCD_DUTY_THIRD = 2, + LCD_DUTY_QUART = 3 +} lcd_duty_t; + +typedef enum { + LCD_PM_0_12 = 0x0, + LCD_PM_0_14 = 0x1, + LCD_PM_0_16 = 0x2, + LCD_PM_0_18 = 0x3, + LCD_PM_0_20 = 0x4, + LCD_PM_0_22 = 0x5, + LCD_PM_0_23 = 0x6, + LCD_PM_0_24 = 0x7, + LCD_PM_0_26 = 0x8, + LCD_PM_0_28 = 0x9, + LCD_PM_0_30 = 0xA, + LCD_PM_0_32 = 0xB, + LCD_PM_0_34 = 0xC, + LCD_PM_0_36 = 0xD, + LCD_PM_0_38 = 0xE, + LCD_PM_0_39 = 0xF +} lcd_pm_t; + +#if defined( DOXYGEN ) +static const seg_map[]; +static const LCD_character_table[]; +static const seg_inf[]; +static const lcd_symbol_chart[LCD_SYMBOL_COUNT]; +#else /* !DOXYGEN */ +/** \name Mapping of segments for different characters */ +/** \{ */ +static const unsigned char seg_map[] PROGMEM = { + NUM_LCD_SYMBOL_A|NUM_LCD_SYMBOL_B|NUM_LCD_SYMBOL_C|NUM_LCD_SYMBOL_D|NUM_LCD_SYMBOL_E|NUM_LCD_SYMBOL_F , /* 0 */ + NUM_LCD_SYMBOL_B|NUM_LCD_SYMBOL_C , /* 1 */ + NUM_LCD_SYMBOL_A|NUM_LCD_SYMBOL_B| NUM_LCD_SYMBOL_D|NUM_LCD_SYMBOL_E| NUM_LCD_SYMBOL_G, /* 2 */ + NUM_LCD_SYMBOL_A|NUM_LCD_SYMBOL_B|NUM_LCD_SYMBOL_C|NUM_LCD_SYMBOL_D| NUM_LCD_SYMBOL_G, /* 3 */ + NUM_LCD_SYMBOL_B|NUM_LCD_SYMBOL_C| NUM_LCD_SYMBOL_F|NUM_LCD_SYMBOL_G, /* 4 */ + NUM_LCD_SYMBOL_A| NUM_LCD_SYMBOL_C|NUM_LCD_SYMBOL_D| NUM_LCD_SYMBOL_F|NUM_LCD_SYMBOL_G, /* 5 */ + NUM_LCD_SYMBOL_A| NUM_LCD_SYMBOL_C|NUM_LCD_SYMBOL_D|NUM_LCD_SYMBOL_E|NUM_LCD_SYMBOL_F|NUM_LCD_SYMBOL_G, /* 6 */ + NUM_LCD_SYMBOL_A|NUM_LCD_SYMBOL_B|NUM_LCD_SYMBOL_C , /* 7 */ + NUM_LCD_SYMBOL_A|NUM_LCD_SYMBOL_B|NUM_LCD_SYMBOL_C|NUM_LCD_SYMBOL_D|NUM_LCD_SYMBOL_E|NUM_LCD_SYMBOL_F|NUM_LCD_SYMBOL_G, /* 8 */ + NUM_LCD_SYMBOL_A|NUM_LCD_SYMBOL_B|NUM_LCD_SYMBOL_C|NUM_LCD_SYMBOL_D| NUM_LCD_SYMBOL_F|NUM_LCD_SYMBOL_G, /* 9 */ + NUM_LCD_SYMBOL_A|NUM_LCD_SYMBOL_B|NUM_LCD_SYMBOL_C| NUM_LCD_SYMBOL_E|NUM_LCD_SYMBOL_F|NUM_LCD_SYMBOL_G, /* A */ + NUM_LCD_SYMBOL_C|NUM_LCD_SYMBOL_D|NUM_LCD_SYMBOL_E|NUM_LCD_SYMBOL_F|NUM_LCD_SYMBOL_G, /* B */ + NUM_LCD_SYMBOL_A| NUM_LCD_SYMBOL_D|NUM_LCD_SYMBOL_E|NUM_LCD_SYMBOL_F , /* C */ + NUM_LCD_SYMBOL_B|NUM_LCD_SYMBOL_C|NUM_LCD_SYMBOL_D|NUM_LCD_SYMBOL_E| NUM_LCD_SYMBOL_G, /* D */ + NUM_LCD_SYMBOL_A| NUM_LCD_SYMBOL_D|NUM_LCD_SYMBOL_E|NUM_LCD_SYMBOL_F|NUM_LCD_SYMBOL_G, /* E */ + NUM_LCD_SYMBOL_A| NUM_LCD_SYMBOL_E|NUM_LCD_SYMBOL_F|NUM_LCD_SYMBOL_G, /* F */ + 0, /* ' ' (space) */ + NUM_LCD_SYMBOL_G /* - (minus) */ +}; +/** \} */ + +/* Look-up tables for 14-segment characters */ +static const unsigned int LCD_character_table[] PROGMEM = /* Character definitions table. */ +{ + 0x0000, /* '*' (?) */ + 0x2830, /* '+' */ + 0x0000, /* ',' (Not defined) */ + 0x0810, /* '-' */ + 0x0200, /* '.' */ + 0x0240, /* '/' */ + 0x93C5, /* '0' */ + 0x80C0, /* '1' */ + 0x1994, /* '2' */ + 0x9894, /* '3' */ + 0x8891, /* '4' */ + 0x9815, /* '5' */ + 0x9915, /* '6' */ + 0x8084, /* '7' */ + 0x9995, /* '8' */ + 0x9895, /* '9' */ + 0x0000, /* ':' (Not defined) */ + 0x0000, /* ';' (Not defined) */ + 0x0000, /* '<' (Not defined) */ + 0x0000, /* '=' (Not defined) */ + 0x0202, /* '>' */ + 0x0000, /* '?' (Not defined) */ + 0x8E53, /* '@' (redefined as '%') */ + 0x8995, /* 'A' (+ 'a') */ + 0xB8A4, /* 'B' (+ 'b') */ + 0x1105, /* 'C' (+ 'c') */ + 0xB0A4, /* 'D' (+ 'd') */ + 0x1915, /* 'E' (+ 'e') */ + 0x0915, /* 'F' (+ 'f') */ + 0x9905, /* 'G' (+ 'g') */ + 0x8991, /* 'H' (+ 'h') */ + 0x2020, /* 'I' (+ 'i') */ + 0x9180, /* 'J' (+ 'j') */ + 0x0551, /* 'K' (+ 'k') */ + 0x1101, /* 'L' (+ 'l') */ + 0x81C3, /* 'M' (+ 'm') */ + 0x8583, /* 'N' (+ 'n') */ + 0x9185, /* 'O' (+ 'o') */ + 0x0995, /* 'P' (+ 'p') */ + 0x9585, /* 'Q' (+ 'q') */ + 0x0D95, /* 'R' (+ 'r') */ + 0x1406, /* 'S' (+ 's') */ + 0x2024, /* 'T' (+ 't') */ + 0x9181, /* 'U' (+ 'u') */ + 0x0341, /* 'V' (+ 'v') */ + 0x8781, /* 'W' (+ 'w') */ + 0x0642, /* 'X' (+ 'x') */ + 0x2042, /* 'Y' (+ 'y') */ + 0x1244, /* 'Z' (+ 'z') */ + 0x0000, /* '[' (Not defined) */ + 0x0000, /* '\' (Not defined) */ + 0x0000, /* ']' (Not defined) */ + 0x0000, /* '^' (Not defined) */ + 0x0000, /* '_' (Not defined) */ + 0x0004, /* A */ + 0x0080, /* B */ + 0x8000, /* C */ + 0x1000, /* D */ + 0x0100, /* E */ + 0x0001, /* F */ + 0x0002, /* G */ + 0x0020, /* H */ + 0x0040, /* J */ + 0x0800, /* K */ + 0x0400, /* L */ + 0x2000, /* M */ + 0x0200, /* N */ + 0x0010, /* O */ + 0x0000, + 0x0000, + 0x0000 +}; + +/** \brief Seven segment reference guide in flash. */ +static const unsigned char seg_inf[] PROGMEM = { + 2<<5|19, /* A */ + 1<<5|19, /* B */ + 1<<5|9, /* C */ + 2<<5|4, /* D */ + 2<<5|9, /* E */ + 2<<5|14, /* F */ + 1<<5|14 /* G */ +}; + +/** \brief LCD symbol chart located in flash. */ +static const lcd_symbol_t lcd_symbol_chart[LCD_SYMBOL_COUNT] PROGMEM= { + /* Raven */ + LCD_SYMBOL_RAVEN , + + /* Audio */ + LCD_SYMBOL_BELL , + LCD_SYMBOL_TONE , + LCD_SYMBOL_MIC , + LCD_SYMBOL_SPEAKER , + + /* Status */ + LCD_SYMBOL_KEY , + LCD_SYMBOL_ATT , + + /* Time */ + LCD_SYMBOL_SUN , + LCD_SYMBOL_MOON , + LCD_SYMBOL_AM , + LCD_SYMBOL_PM , + + /* Radio comus */ + LCD_SYMBOL_RX , + LCD_SYMBOL_TX , + LCD_SYMBOL_IP , + LCD_SYMBOL_PAN , + LCD_SYMBOL_ZLINK , + LCD_SYMBOL_ZIGBEE , + + /* Antenna status */ + LCD_SYMBOL_ANT_FOOT, + LCD_SYMBOL_ANT_SIG1, + LCD_SYMBOL_ANT_SIG2, + LCD_SYMBOL_ANT_SIG3, + LCD_SYMBOL_ANT_DIS , + + /* Battery status */ + LCD_SYMBOL_BAT_CONT, + LCD_SYMBOL_BAT_CAP1, + LCD_SYMBOL_BAT_CAP2, + LCD_SYMBOL_BAT_CAP3, + + /* Envelope status */ + LCD_SYMBOL_ENV_OP , + LCD_SYMBOL_ENV_CL , + LCD_SYMBOL_ENV_MAIN, + + /* Temperature */ + LCD_SYMBOL_C , + LCD_SYMBOL_F , + + /* Numeric */ + LCD_SYMBOL_MINUS , + LCD_SYMBOL_DOT , + LCD_SYMBOL_COL +}; +#endif /* !DOXYGEN */ + +/** LCD text buffer */ +static unsigned char lcd_text[20]; + +/** Textd buffer read pointer for text field in LCD display. When ptr>0 characters in front will be cleared (space) */ +static int lcd_text_rd_ptr = 0; + +/** Text pointer for writing new chars to text buffer */ +static int lcd_text_wr_ptr = 0; + +static bool lcd_scroll_enable; +static int lcd_scroll_prescale; +static int lcd_scroll_prescale_value; +static int lcd_num_print(uint16_t numb, bool negative, lcd_padding_t padding); +static void lcd_nmb_print_dig(uint8_t val, int dig); +static int lcd_text_sl(void); +static int lcd_text_put(const char* s, int pos); +static int lcd_char_put(unsigned char c, int pos); + +/*---------------------------------------------------------------------------*/ + +/** + * \brief This function will initialize the proper settings for the LCD driver. + * + * This ATmega3290p can directly support an LCD through register mapping. + * + * \return 0 +*/ +int +lcd_init(void) +{ + /* + * Configuring LCD with Extern clock (TOSC, 32.768kHz) + * 32786 Hz 32786 Hz + * frame_rate = ------------------ = ------------- = 32 Hz + * 8 * .prescl * .div 8 * 16 * 8 + */ + + lcd_config_t lcd_config ; + lcd_config.blanking = LCD_BLANKING_OFF; + lcd_config.buffer = LCD_BUFFER_ON; + lcd_config.wave = LCD_WAVE_LOW_POWER; + lcd_config.clock = LCD_CLOCK_EXTERN; + lcd_config.bias = LCD_BIAS_HALF; + lcd_config.prescl = LCD_PRESCL_16; + lcd_config.div = LCD_DIV_8; + lcd_config.drive = LCD_DRIVE_450; + lcd_config.contrast = LCD_CONTRAST_3_30; + + /* Enable module */ + PRR &= ~(1 << PRLCD); + + /* Configure and enable LCD controller */ + LCDCRB = lcd_config.lcdcrb|(LCD_PM_0_39<>= (lcd_config.prescl == 0) ? 4 : (5+lcd_config.prescl); + lcd_scroll_prescale_value /= (lcd_config.div+1); + lcd_scroll_prescale_value = (lcd_scroll_prescale_value==0) ? 1 : lcd_scroll_prescale_value; + lcd_scroll_prescale = lcd_scroll_prescale_value; + + return 0; +} + +/*---------------------------------------------------------------------------*/ + +/** + * \brief This will disable the LCD operation. +*/ +void +lcd_deinit(void) +{ + while (!(LCDCRA & (1<= 10){ + inNumber -= 10; + newByte++; + } + + newByte = newByte << 4; + newByte = (newByte | inNumber); + + return newByte; +} + +/*---------------------------------------------------------------------------*/ + +/** + * \brief This will put a HEX value on the LCD that represents the input + * parameter. + * + * \param numb Number to display as HEX. + * \param padding This pads the location to place the value on the LCD. + * + * \return lcd_num_print() +*/ +int +lcd_num_puthex(uint16_t numb, lcd_padding_t padding) +{ + return lcd_num_print(numb, false, padding); +} + +/*---------------------------------------------------------------------------*/ + +/** + * \brief This will put a DEC value on the LCD that represents the input + * parameter. + * + * \param numb Number to display as DEC. + * \param padding This pads the location to place the value on the LCD. + * + * \return lcd_num_print() +*/ +int +lcd_num_putdec(int numb, lcd_padding_t padding) +{ + uint16_t bcd; + + /* Check for overflow */ + if (numb > 9999) { + numb = 9999; + } else if (numb < -9999) { + numb = -9999; + } + + /* Convert to BCD */ + bcd = itobcd(abs(numb)); + + /* Print */ + return lcd_num_print(bcd, (bool)(numb<0), padding); +} + +/*---------------------------------------------------------------------------*/ + +/** + * \brief This will clear numbers displayed on the LCD. + * + * \return 0 +*/ +int +lcd_num_clr(void) +{ + volatile unsigned char* lcd_data = (volatile unsigned char*)0xEC; + int i,j; + + for (i=0;i<4;++i){ + for (j=0;j<7;++j){ + lcd_data[pgm_read_byte(&seg_inf[j])&0x1F] &= ~((pgm_read_byte(&seg_inf[j])>>5)<<(i*2)); + } + } + return 0; +} + +/*---------------------------------------------------------------------------*/ + +/** + * \brief This will put a string of characters out to the LCD. + * + * \param s First character pointer of string. + * + * \return 0 +*/ +int +lcd_puts(const char* s) +{ + strcpy((char*)lcd_text, s); + lcd_text_wr_ptr = strlen(s); + lcd_text_rd_ptr = 0; + + lcd_text_put((char*)&lcd_text[lcd_text_rd_ptr], 1); + + lcd_scroll_enable = (lcd_text_wr_ptr > 7) ? true : false; + + return 0; +} + +/*---------------------------------------------------------------------------*/ + +/** + * \brief This will put a string of characters of a certain length out to the LCD. + * + * \param length Length of string to print. + * \param s First character pointer of string. + * + * \return 0 +*/ +int +lcd_puta(size_t length, const uint8_t *s) +{ + memcpy((void*)lcd_text, (void const*)s, length); + lcd_text_wr_ptr = length; + lcd_text_rd_ptr = 0; + + lcd_text_put((char*)&lcd_text[lcd_text_rd_ptr], 1); + + lcd_scroll_enable = (lcd_text_wr_ptr > 7) ? true : false; + + return 0; +} + +/*---------------------------------------------------------------------------*/ + +/** + * \brief This will put a string out to the LCD from Flash. + * + * \param s First character pointer of the string located in Flash + * + * \return 0 +*/ +int +lcd_puts_P(const char *s) +{ + strcpy_P((char*)lcd_text, s); + lcd_text_wr_ptr = strlen_P(s); + lcd_text_rd_ptr = 0; + + lcd_text_put((char*)&lcd_text[lcd_text_rd_ptr], 1); + + lcd_scroll_enable = (lcd_text_wr_ptr > 7) ? true : false; + + return 0; +} + +/*---------------------------------------------------------------------------*/ + +/** + * \brief This will put a single character out to the LCD. + * + * \param c Character to display on LCD. + * + * \return 0 +*/ +int +lcd_putchar(unsigned char c) +{ + lcd_text[lcd_text_wr_ptr++] = c; + lcd_text[lcd_text_wr_ptr] = 0; + + lcd_text_put((char*)&lcd_text[lcd_text_rd_ptr], 1); + + lcd_scroll_enable = (lcd_text_wr_ptr > 7) ? true : false; + + return 0; +} + +/*---------------------------------------------------------------------------*/ + +/** + * \brief This will enable any of the symbols on the Raven LCD. + * + * \param symbol Specific symbol to enable on the LCD. +*/ +void +lcd_symbol_set(lcd_symbol_t symbol) +{ + unsigned char mem_offset; + unsigned char bit_offset; + volatile unsigned char* lcd_data = (volatile unsigned char*)0xEC; + + /* Symbol format = bbbnnnnn where b is bit and n is offset */ + bit_offset = (symbol >> 5); + mem_offset = (symbol & 0x1F); + if ( mem_offset >= 20 ){ + return; /* Data out of range of the LCD registers */ + } + lcd_data = lcd_data + mem_offset; /* Point to the relevant LCDDR */ + + *lcd_data = *lcd_data | ( 1 << bit_offset); +} + +/*---------------------------------------------------------------------------*/ + +/** + * \brief This will clear any symbol on the Raven LCD. + * + * \param symbol Specific symbol to clear from the LCD. +*/ +void +lcd_symbol_clr(lcd_symbol_t symbol) +{ + unsigned char offset; + unsigned char setbit; + volatile unsigned char* lcd_data = (volatile unsigned char*)0xEC; + + /* symbol format = bbbnnnnn where b is bit and n is offset */ + setbit = (symbol >> 5); + offset = (symbol & 0x1F); + if ( offset >= 20 ){ + return; /* data out of range of the LCD registers */ + } + + lcd_data = lcd_data + offset; /* Point to the relevant LCDDR */ + + *lcd_data = *lcd_data & ~( 1 << setbit); +} + +/*---------------------------------------------------------------------------*/ + +/** + * \brief This will enable a group of symbols from the lcd_symbol_chart. + * + * \param start Position of table to start from. + * \param count Number of symbols to enable from start position. +*/ +void +lcd_symbol_set_group(int start, int count) +{ + count = (start + count)>LCD_SYMBOL_COUNT ? + LCD_SYMBOL_COUNT - start : + count; + int i; + + for(i=start; iLCD_SYMBOL_COUNT ? + LCD_SYMBOL_COUNT - start : + count; + int i; + + for(i=start; i>4*i]), i); + + /* If rest of number is zero */ + if (++i<4) { + if (numb >> 4*i == 0) { + if (negative == true) { /* print a 'minus' in the next digit field */ + lcd_nmb_print_dig(pgm_read_byte(&seg_map[(padding == LCD_NUM_PADDING_ZERO) ? LCD_SEV_SEG_INDEX_0 : LCD_SEV_SEG_INDEX_MINUS]), i++); + if (padding == LCD_NUM_PADDING_ZERO) { + lcd_symbol_set(LCD_SYMBOL_MINUS); + } + } else { + lcd_symbol_clr(LCD_SYMBOL_MINUS); + } + while (i<4){ + lcd_nmb_print_dig(pgm_read_byte(&seg_map[(padding == LCD_NUM_PADDING_ZERO) ? LCD_SEV_SEG_INDEX_0 : LCD_SEV_SEG_INDEX_SPACE]), i++); + } + } + } else { + if (negative == true) { + lcd_symbol_set(LCD_SYMBOL_MINUS); + } else { + lcd_symbol_clr(LCD_SYMBOL_MINUS); + } + } + } + return 0; +} + +/*---------------------------------------------------------------------------*/ + +/** + * \brief This will print a number according to the segment map of the LCD. + * + * \param val Number that is to be matched to appropriate segments. + * \param dig Segment to enable +*/ +static void +lcd_nmb_print_dig(uint8_t val, int dig) +{ + volatile unsigned char* lcd_data = (volatile unsigned char*)0xEC; + int j; + + for (j=0;j<7;++j){ + if (val & (1<>5)<<(dig*2); + } + else { + lcd_data[pgm_read_byte(&seg_inf[j])&0x1F] &= ~((pgm_read_byte(&seg_inf[j])>>5)<<(dig*2)); + } + } +} + +/*---------------------------------------------------------------------------*/ + +/** + * \brief This will scroll the test on the LCD. + * + * \return 0 +*/ +static int +lcd_text_sl(void) +{ + static int pos = 1; + if (lcd_text[lcd_text_rd_ptr] == 0) { + lcd_text_rd_ptr = 0; + pos = 7; + } + else { + if (pos){ + pos--; + } + else { + lcd_text_rd_ptr++; + } + } + + lcd_text_put((char*)&lcd_text[lcd_text_rd_ptr], pos); + return 0; +} + +/*---------------------------------------------------------------------------*/ + +/** + * \brief This will put test out to the LCD at a certain location padded with + * spaces. + * + * \param s First character pointer to the string of test to print. + * \param pos Count of spaces entered before printing the text. + * + * \return 0 +*/ +static int +lcd_text_put(const char* s, int pos) +{ + int i; + + /* Pad with spaces in front if offset > 0 */ + for (i=1; i 7){ + return EOF; + } + + /* Lookup character table for segmet data */ + if (((c >= '*') && (c <= 'z')) || (c == ' ')){ + if (c >= 'a' ){ + c &= ~0x20; /* c is in character_table. Convert to upper if necessarry. */ + } + if (c == ' ') { + c = 0x00; + } + else { + c -= '*'; + } + if ( c > 0x35 ){ + return EOF; /* c points outside array */ + } + else{ + seg = pgm_read_dword(&LCD_character_table[c]); + } + } + else { + return EOF; /* ASCII code out of range */ + } + + + /* Adjust mask according to digit */ + segMask = 0x4008; /* masking out two bits */ + + i = pos-1; /*i used as pointer offset */ + i >>= 1; + lcd_data += i; /* Point to the first relevant LCDDR; i = {0,0,1,1,2,2} */ + + i = 4; /*i used as loop counter */ + do{ + nibble = seg & 0x000F; + nibbleMask = segMask & 0x000F; + + seg >>= 4; + segMask >>= 4; + + if (pos & 0x01) { + mask = 0xF0 | nibbleMask; + } + else { + nibble <<= 4; + mask = 0x0F | ( nibbleMask <<4 ); + } + lcd_reg = *lcd_data; + *lcd_data |= (lcd_reg & mask) | nibble; /* Write new bit values */ + + lcd_reg = *lcd_data; + *lcd_data &= (lcd_reg & mask) | nibble; + + lcd_data += 5; + } while ( --i ); + + return 0; +} + +/*---------------------------------------------------------------------------*/ + +/** + * \brief This is the LCD Start of Frame Interrupt Subroutine. + * + * This interrupt fires at the beginning of a new frame. +*/ +ISR +(LCD_vect) +{ + if (lcd_scroll_enable) { + if (--lcd_scroll_prescale == 0) { + lcd_text_sl(); + lcd_scroll_prescale = lcd_scroll_prescale_value; + } + } +} + +/*---------------------------------------------------------------------------*/ + +/** + * \brief Turns the Raven nose LED on. +*/ +void +led_on(void) +{ + DDRB |= 0x80; + PORTB &= ~0x80; +} + +/*---------------------------------------------------------------------------*/ + +/** + * \brief Turns the Raven nose LED off. +*/ +void +led_off(void) +{ + DDRB &= ~0x80; + PORTB |= 0x80; +} + +/*---------------------------------------------------------------------------*/ + +/** + * \brief This will add the passed in number to any of the four locations of + * the four digit segment display on the LCD. + * + * \param numb Number to display. + * \param pos Position to display number. +*/ +void +lcd_single_print_dig(uint8_t numb, uint8_t pos) +{ + lcd_nmb_print_dig(pgm_read_byte(&seg_map[numb]), pos); +} + +/** \} */ diff --git a/platform/avr-ravenlcd/lcd.h b/platform/avr-ravenlcd/lcd.h new file mode 100644 index 000000000..b14d5827c --- /dev/null +++ b/platform/avr-ravenlcd/lcd.h @@ -0,0 +1,351 @@ +/* + * Copyright (c) 2008 Swedish Institute of Computer Science + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of the copyright holders nor the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +/** + * \file + * + * \brief + * This file provides Raven LCD support. + * + * \author + * Mike Vidales mavida404@gmail.com + * + */ + +#ifndef __LCD_H__ +#define __LCD_H__ + +#include +#include +#include + +#include +#include +#include +#include +#include + + +#define LCD_SYMBOL_FISRT 0 +#define LCD_SYMBOL_COUNT 34 + +/* Duplicate usage of segments */ +#define LCD_SYMBOL_ARR_UP LCD_SYMBOL_ENV_OP +#define LCD_SYMBOL_ARR_DN LCD_SYMBOL_ENV_CL + +#define LCD_CLCK_FRQ 32768 + +/** @name Constant defines for making seg_map[] table */ +/** @{ */ +/* + - a - + f b + |-g-| + e c + - d - +*/ +#define NUM_LCD_SYMBOL_A 0x01 +#define NUM_LCD_SYMBOL_B 0x02 +#define NUM_LCD_SYMBOL_C 0x04 +#define NUM_LCD_SYMBOL_D 0x08 +#define NUM_LCD_SYMBOL_E 0x10 +#define NUM_LCD_SYMBOL_F 0x20 +#define NUM_LCD_SYMBOL_G 0x40 +/** @} */ + +/** @name Constant defines for indexing seg_map[] table */ +/** @{ */ +#define LCD_SEV_SEG_INDEX_0 (0) +#define LCD_SEV_SEG_INDEX_1 (1) +#define LCD_SEV_SEG_INDEX_2 (2) +#define LCD_SEV_SEG_INDEX_3 (3) +#define LCD_SEV_SEG_INDEX_4 (4) +#define LCD_SEV_SEG_INDEX_5 (5) +#define LCD_SEV_SEG_INDEX_6 (6) +#define LCD_SEV_SEG_INDEX_7 (7) +#define LCD_SEV_SEG_INDEX_8 (8) +#define LCD_SEV_SEG_INDEX_9 (9) +#define LCD_SEV_SEG_INDEX_A (10) +#define LCD_SEV_SEG_INDEX_B (11) +#define LCD_SEV_SEG_INDEX_C (12) +#define LCD_SEV_SEG_INDEX_D (13) +#define LCD_SEV_SEG_INDEX_E (14) +#define LCD_SEV_SEG_INDEX_F (15) +#define LCD_SEV_SEG_INDEX_SPACE (16) +#define LCD_SEV_SEG_INDEX_MINUS (17) +/** @} */ + +#define lcd_symbol_set_all() lcd_symbol_set_group(0, sizeof(lcd_symbol_chart)) +#define lcd_symbol_clr_all() lcd_symbol_clr_group(0, sizeof(lcd_symbol_chart)) + +typedef enum { + LCD_NUM_PADDING_ZERO, + LCD_NUM_PADDING_SPACE +} lcd_padding_t; + +typedef enum { +/* name = (bit_number << bit_number_offset) | mem_offset*/ + /* Raven */ + LCD_SYMBOL_RAVEN = (7<<5) | 3, + + /* Audio */ + LCD_SYMBOL_BELL = (2<<5) | 17, + LCD_SYMBOL_TONE = (6<<5) | 17, + LCD_SYMBOL_MIC = (3<<5) | 3, + LCD_SYMBOL_SPEAKER = (2<<5) | 18, + + /* Status */ + LCD_SYMBOL_KEY = (3<<5) | 2, + LCD_SYMBOL_ATT = (7<<5) | 2, + + /* Time */ + LCD_SYMBOL_SUN = (6<<5) | 13, + LCD_SYMBOL_MOON = (6<<5) | 3, + LCD_SYMBOL_AM = (2<<5) | 15, + LCD_SYMBOL_PM = (6<<5) | 15, + + /* Radio commuication status */ + LCD_SYMBOL_RX = (6<<5) | 18, + LCD_SYMBOL_TX = (5<<5) | 13, + LCD_SYMBOL_IP = (7<<5) | 13, + LCD_SYMBOL_PAN = (7<<5) | 18, + LCD_SYMBOL_ZLINK = (5<<5) | 8, + LCD_SYMBOL_ZIGBEE = (5<<5) | 3, + + /* Antenna status */ + LCD_SYMBOL_ANT_FOOT= (5<<5) | 18, + LCD_SYMBOL_ANT_SIG1= (3<<5) | 0, + LCD_SYMBOL_ANT_SIG2= (7<<5) | 0, + LCD_SYMBOL_ANT_SIG3= (3<<5) | 1, + LCD_SYMBOL_ANT_DIS = (7<<5) | 1, + + /* Battery status */ + LCD_SYMBOL_BAT_CONT= (4<<5) | 18, + LCD_SYMBOL_BAT_CAP1= (4<<5) | 3, + LCD_SYMBOL_BAT_CAP2= (4<<5) | 8, + LCD_SYMBOL_BAT_CAP3= (4<<5) | 13, + + /* Envelope status */ + LCD_SYMBOL_ENV_OP = (6<<5) | 8, + LCD_SYMBOL_ENV_CL = (0<<5) | 4, + LCD_SYMBOL_ENV_MAIN= (2<<5) | 4, + + /* Temperature */ + LCD_SYMBOL_C = (6<<5) | 16, + LCD_SYMBOL_F = (2<<5) | 16, + + /* Numeric */ + LCD_SYMBOL_MINUS = (7<<5) | 8, + LCD_SYMBOL_DOT = (4<<5) | 4, + LCD_SYMBOL_COL = (6<<5) | 4, +} lcd_symbol_t; + +typedef enum { + LCD_WAVE_DEFAULT = 0, + LCD_WAVE_LOW_POWER = 1 +} lcd_wave_t; + +typedef enum { + LCD_BUFFER_ON = 0, + LCD_BUFFER_OFF = 1 +} lcd_buffer_t; + +typedef enum { + LCD_BLANKING_OFF = 0, + LCD_BLANKING_ON = 1 +} lcd_blanking_t; + +typedef enum { + LCD_CLOCK_SYSTEM = 0, + LCD_CLOCK_EXTERN = 1 +} lcd_clock_t; + +typedef enum { + LCD_BIAS_THIRD = 0, + LCD_BIAS_HALF = 1 +} lcd_bias_t; + +typedef enum { + LCD_PRESCL_16 = 0x0, + LCD_PRESCL_64 = 0x1, + LCD_PRESCL_128 = 0x2, + LCD_PRESCL_256 = 0x3, + LCD_PRESCL_512 = 0x4, + LCD_PRESCL_1024 = 0x5, + LCD_PRESCL_2048 = 0x6, + LCD_PRESCL_4096 = 0x7, +} lcd_prescl_t; + +typedef enum { + LCD_DIV_1 = 0, + LCD_DIV_2 = 1, + LCD_DIV_3 = 2, + LCD_DIV_4 = 3, + LCD_DIV_5 = 4, + LCD_DIV_6 = 5, + LCD_DIV_7 = 6, + LCD_DIV_8 = 7 +} lcd_div_t; + +/** Bit LCDDC2:0 and LCMDT */ +typedef enum { + LCD_DRIVE_300 = 0x0, + LCD_DRIVE_70 = 0x2, + LCD_DRIVE_150 = 0x4, + LCD_DRIVE_450 = 0x6, + LCD_DRIVE_575 = 0x8, + LCD_DRIVE_850 = 0xA, + LCD_DRIVE_1150 = 0xC, + LCD_DRIVE_HALF = 0xE, + LCD_DRIVE_FULL = 0xF +} lcd_drive_t; + +typedef enum { + LCD_CONTRAST_2_60 = 0x0, + LCD_CONTRAST_2_65 = 0x1, + LCD_CONTRAST_2_70 = 0x2, + LCD_CONTRAST_2_75 = 0x3, + LCD_CONTRAST_2_80 = 0x4, + LCD_CONTRAST_2_85 = 0x5, + LCD_CONTRAST_2_90 = 0x6, + LCD_CONTRAST_2_95 = 0x7, + LCD_CONTRAST_3_00 = 0x8, + LCD_CONTRAST_3_05 = 0x9, + LCD_CONTRAST_3_10 = 0xA, + LCD_CONTRAST_3_15 = 0xB, + LCD_CONTRAST_3_20 = 0xC, + LCD_CONTRAST_3_25 = 0xD, + LCD_CONTRAST_3_30 = 0xE, + LCD_CONTRAST_3_35 = 0xF +} lcd_contrast_t; + +typedef struct { + union { + struct { + unsigned int blanking: 1; + unsigned int : 1; + unsigned int buffer : 1; + unsigned int : 3; + unsigned int wave : 1; + unsigned int : 1; + }; + uint8_t lcdcra; + }; + union { + struct { + unsigned int : 6; + unsigned int bias : 1; + unsigned int clock : 1; + }; + uint8_t lcdcrb; + }; + union { + struct { + unsigned int div : 3; + unsigned int : 1; + unsigned int prescl : 3; + unsigned int : 1; + }; + uint8_t lcdfrr; + }; + union { + struct { + unsigned int contrast: 4; + unsigned int drive : 4; + }; + uint8_t lcdccr; + }; +} lcd_config_t; + +/*========================= PUBLIC VARIABLES =========================*/ + + +/*========================= PUBLIC FUNCTIONS =========================*/ + +/** Initialization and configuration of the LCD controller + * + * Example: + * \code + * + * Configuring LCD with Extern clock (TOSC, 32.768kHz) + * 32786 Hz 32786 Hz + * frame_rate = ------------------ = ------------- = 32 Hz + * 8 * .prescl * .div 8 * 16 * 8 + * + * lcd_config_t lcd_config = { + * .wave = LCD_WAVE_LOW_POWER, + * .buffer = LCD_BUFFER_ON, + * .blanking = LCD_BLANKING_OFF, + * .clock = LCD_CLOCK_EXTERN, + * .bias = LCD_BIAS_HALF, + * .prescl = LCD_PRESCL_16, + * .div = LCD_DIV_8, + * .drive = LCD_DRIVE_450, + * .contrast = LCD_CONTRAST_3_30 + * }; + * + * lcd_init(lcd_config); + * \endcode +*/ +int lcd_init(void); +void lcd_deinit(void); +uint8_t itobcd(uint8_t inNumber); + +/** @name Numeric functions */ +/** @{ */ +int lcd_num_puthex(uint16_t numb, lcd_padding_t padding); +int lcd_num_putdec(int numb, lcd_padding_t padding); +int lcd_num_clr(void); +void lcd_single_print_dig(uint8_t numb, uint8_t pos); +/** @} */ + +/** @name Text functions */ +/** @{ */ +int lcd_puts(const char* s); +int lcd_puts_P(const char *s); +int lcd_puta(size_t length, const uint8_t *s); +int lcd_putchar(unsigned char c); +/** @} */ + +/** @name Symbol functions */ +/** @{ */ +void lcd_symbol_set(lcd_symbol_t symbol); +void lcd_symbol_set_group(int start, int count); +void lcd_symbol_clr(lcd_symbol_t symbol); +void lcd_symbol_clr_group(int start, int count); +/** @} */ + +/** @name LED Functions */ +/** @{ */ +void led_on(void); +void led_off(void); +/** @} */ + +#endif /* __LCD_H__ */ + diff --git a/platform/avr-ravenlcd/main.h b/platform/avr-ravenlcd/main.h new file mode 100644 index 000000000..fd6b0dd37 --- /dev/null +++ b/platform/avr-ravenlcd/main.h @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2008 Swedish Institute of Computer Science + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of the copyright holders nor the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +/** + * \file + * + * \brief + * This is the main file for the Raven LCD application. Contains binary + * command definitions. + * + * \author + * Mike Vidales mavida404@gmail.com + * + */ + +#ifndef __MAIN_H__ +#define __MAIN_H__ + +/** \name Logical defines */ +/** \{ */ +#define BOOL char +#define FALSE 0 +#define TRUE (!false) + +#define PING_ATTEMPTS (4) +/** \} */ + +/** \name These are GUI to Radio Binary commands. */ +/** \{ */ +#define NULL_CMD (0) +#define SEND_TEMP (0x80) +#define SEND_PING (0x81) +/** \} */ + +/** \name These are the Radio to GUI binary commands. */ +/** \{ */ +#define REPORT_PING (0xC0) +#define REPORT_PING_BEEP (0xC1) +#define REPORT_TEXT_MSG (0xC2) +/** \} */ + + +#endif /* __MAIN_H__ */ diff --git a/platform/avr-ravenlcd/menu.c b/platform/avr-ravenlcd/menu.c new file mode 100644 index 000000000..56d41f030 --- /dev/null +++ b/platform/avr-ravenlcd/menu.c @@ -0,0 +1,399 @@ +/* + * Copyright (c) 2008 Swedish Institute of Computer Science + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of the copyright holders nor the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +/** + * \file + * + * \brief + * This file operates the menu flow chart described in the readme + * notes. This will create the proper commands needed to control the 1284p. + * + * \author + * Mike Vidales mavida404@gmail.com + * + */ + +#include "menu.h" +#include "main.h" +#include "lcd.h" +#include "key.h" +#include "uart.h" +#include "sleep.h" +#include "temp.h" + +uint8_t ping_count; +uint8_t ping_response; +bool ping_mode; +bool timeout_flag; +bool temp_flag; +bool temp_mode; +bool auto_temp; + +/** + * \addtogroup lcd + * \{ +*/ + +/*---------------------------------------------------------------------------*/ + +/** + * \brief This function will convert decimal to ascii. + * + * \param val Decimal value to convert. + * \param str Address location to store converted value. +*/ +void +dectoascii(uint8_t val, char *str) +{ + *(str+1) = (val % 10) + '0'; + *str = (val / 10) + '0'; +} + +/*---------------------------------------------------------------------------*/ + +/** + * \brief This will convert a signed decimal number to ASCII. + * + * \param n Signed number + * \param str Pointer to store converted value. + * + * \return *p Address of stored conversion. +*/ +uint8_t +*signed_dectoascii(int16_t n, uint8_t *str) +{ + uint8_t * p = str; + uint8_t neg = 0; + + if(n < 0){ + neg = 1; + n = -n; + } + + *p-- = 0x00; + + /* Determine the unit of conversion. */ + if(temp_mode == TEMP_UNIT_CELCIUS){ + /* Add ASCII C to string. */ + *p-- = 'C'; + } + else{ + /* Add ASCII F to string. */ + *p-- = 'F'; + } + + /* Add a space before unit symbol. */ + *p-- = ' '; + + /* For zero, just print zero. */ + if (!n){ + *p = '0'; + return p; + } + + while (n){ + *p-- = (n%10) + '0'; + n/= 10; + } + + if (neg){ + *p-- = '-'; + } + + return ++p; +} + +/*---------------------------------------------------------------------------*/ + +/** + * \brief This will start a sleep operation. + * + * \param val Used for rembering the new menu to display after a wakeup. +*/ +void +menu_run_sleep(uint8_t *val) +{ + /* Turn off LED */ + led_off(); + + /* Turn off Timer 1, SPI, uart */ + PRR |= (1 << PRTIM1) | (1 << PRSPI); + + /* Turn off the LCD display for sleeping */ + lcd_deinit(); + + /* Turn off A/D converter */ + key_deinit(); + + /* Go to sleep now */ + sleep_now(); + + /* Wake up LCD Display */ + lcd_init(); + + /* Tell user we're waking up */ + lcd_puts_P(PSTR("WAKE---")); + + /* Turn on Raven logo */ + lcd_symbol_set(LCD_SYMBOL_RAVEN); + + /* Wake up ADC */ + key_init(); + + /* Wake up radio */ + sleep_wakeup(); + + /* Wait for buttons up */ + while (key_state_get() != KEY_NO_KEY) + ; + if (is_button()){ + get_button(); + } + + /* Print last menu tex */ + lcd_puts_P((char *)&val); +} + +/*---------------------------------------------------------------------------*/ + +/** + * \brief This will setup a ping request command to the 1284p and reset the ping counter. + * + * \param val place holder +*/ +void +menu_ping_request(uint8_t * val) +{ + uint8_t i; + ping_mode = true; + ping_count = 0; + ping_response = 0; + + /* Initialize the numerical display with dashes */ + for(i=0; i<4; i++){ + lcd_single_print_dig(LCD_SEV_SEG_INDEX_MINUS, i); + } + + menu_send_ping(); + + /* Reset the timer for 1 sec resolution between pings. */ + TCNT1 = 0; +} + +/*---------------------------------------------------------------------------*/ + +/** + * \brief This will send the ping request to the 1284p via the serial port. + * + * \return ping_count The number of ping attempts. +*/ +uint8_t +menu_send_ping(void) +{ + /* + * Check for previous ping timeout. If menu_send_ping() was called before receiving + * a response, update the LCD. + */ + timeout_flag = true; + ping_count++; + /* Send the ping command with one byte payload of the current sequence number. */ + uart_serial_send_frame(SEND_PING, 1, (uint8_t *)&ping_count); + return ping_count; +} + +/*---------------------------------------------------------------------------*/ + +/** + * \brief This will stop the ping request. +*/ +void +menu_stop_ping(void) +{ + ping_mode = false; +} + +/*---------------------------------------------------------------------------*/ + +/** + * \brief This will enable or disable the JTAG debug interface to allow for + * proper temperature sensor readings. + * + * \param val Flag to trigger the proper debug mode. +*/ +void +menu_debug_mode(uint8_t *val) +{ + uint8_t sreg = SREG; + cli(); + if(*val){ + /* Could use inline ASM to meet timing requirements. */ + MCUCR |= (1 << JTD); + MCUCR |= (1 << JTD); + /* Needed for timing critical JTD disable. */ + temp_init(); + } + else{ + /* Could use inline ASM to meet timing requirements. */ + MCUCR &= ~(1 << JTD); + MCUCR &= ~(1 << JTD); + } + SREG = sreg; +} + +/*---------------------------------------------------------------------------*/ + +/** + * \brief This will display the temperature in degrees F or C. + * + * \param val Flag to trigger F or C temperature conversion. +*/ +void +menu_read_temp(uint8_t *val) +{ + if(*val){ + temp_mode = TEMP_UNIT_CELCIUS; + } + else{ + temp_mode = TEMP_UNIT_FAHRENHEIT; + } + + temp_flag = true; + + menu_display_temp(); +} + +/*---------------------------------------------------------------------------*/ + +/** + * \brief This will display the temperature in degrees F or C. +*/ +void +menu_display_temp(void) +{ + int16_t result = temp_get(temp_mode); + + /* Display the temp result on the lower 4 digit display with the proper symbol. */ + if(temp_mode == TEMP_UNIT_CELCIUS){ + lcd_symbol_clr(LCD_SYMBOL_F); + lcd_symbol_set(LCD_SYMBOL_C); + } + else{ + lcd_symbol_clr(LCD_SYMBOL_C); + lcd_symbol_set(LCD_SYMBOL_F); + } + + /* Check for the DEBUG JTAG enable bit and display a CAUTION symbol to the user. */ + /* CAUTION represents false value. */ + if(MCUCR & 0x80){ + lcd_symbol_clr(LCD_SYMBOL_ATT); + } + else{ + lcd_symbol_set(LCD_SYMBOL_ATT); + } + + lcd_num_putdec(result, LCD_NUM_PADDING_SPACE); +} + +/*---------------------------------------------------------------------------*/ + +/** + * \brief This will clear the temperature displayed in the 4 digit LCD segments. +*/ +void +menu_clear_temp(void) +{ + temp_flag = false; + lcd_symbol_clr(LCD_SYMBOL_F); + lcd_symbol_clr(LCD_SYMBOL_C); + lcd_symbol_clr(LCD_SYMBOL_ATT); + lcd_num_clr(); +} + +/*---------------------------------------------------------------------------*/ + +/** + * \brief This will setup the current temperature for transfer to the ATmega1284p via a binary + * command transfer. + * + * \param val This is used to determine sending once or auto based on the timer. +*/ +void +menu_prepare_temp(uint8_t *val) +{ + if(*val){ + /* Only send the temp value once. */ + auto_temp = false; + } + else{ + /* Auto send the temp value based on TIMER1 interval. */ + auto_temp = true; + } + + menu_send_temp(); +} + +/*---------------------------------------------------------------------------*/ + +/** + * \brief This will stop the auto sending of temperature data. +*/ +void +menu_stop_temp(void) +{ + auto_temp = false; +} + +/*---------------------------------------------------------------------------*/ + +/** + * \brief This will send the data via the serial port. +*/ +void +menu_send_temp(void) +{ + int16_t result; + uint8_t str[10]; + uint8_t * p = 0; + + /* Turn on nose LED for activity indicator */ + led_on(); + + /* Get the latest temp value. */ + result = temp_get(temp_mode); + + /* Convert signed decimal number to ASCII. */ + p = signed_dectoascii(result, (str + 10)); + + /* Send frame via serial port. */ + uart_serial_send_frame(SEND_TEMP, strlen((char *)p), p); + + led_off(); +} + +/** \} */ diff --git a/platform/avr-ravenlcd/menu.h b/platform/avr-ravenlcd/menu.h new file mode 100644 index 000000000..78a9279bc --- /dev/null +++ b/platform/avr-ravenlcd/menu.h @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2008 Swedish Institute of Computer Science + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of the copyright holders nor the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +/** + * \file + * + * \brief + * This file operates the menu flow chart described in the readme + * notes. This will create the proper commands needed to control the 1284p. + * + * \author + * Mike Vidales mavida404@gmail.com + * + */ + +#ifndef MENU_H +#define MENU_H + +#include +#include + +/** \brief Pointer to function, used to dispatch a menu-driven function. See tmenu_item */ +typedef void (*tmenufunc)(uint8_t *); + +/** \brief This structure defines the joystick operation within the menu_items[]. */ +typedef struct { + const char * PROGMEM text; /**< Menu text to display. */ + uint8_t left; /**< Contains next menu position for left. */ + uint8_t right; /**< Contains next menu position for right. */ + uint8_t up; /**< Contains next menu position for up. */ + uint8_t down; /**< Contains next menu position for down. */ + uint8_t *state; /**< State variable used as argument for menu enter function. */ + tmenufunc enter_func; /**< Pointer to function to call when enter button is pressed. */ +} tmenu_item; + +extern uint8_t ping_response; +extern bool ping_mode; +extern bool timeout_flag; +extern bool temp_flag; +extern bool auto_temp; +extern const PROGMEM tmenu_item menu_items[]; + +void menu_run_sleep(uint8_t *val); +void dectoascii(uint8_t val, char *str); +uint8_t *signed_dectoascii(int16_t n, uint8_t *str); +void menu_ping_request(uint8_t * val); +uint8_t menu_send_ping(void); +void menu_stop_ping(void); +void menu_debug_mode(uint8_t *val); +void menu_read_temp(uint8_t *val); +void menu_display_temp(void); +void menu_clear_temp(void); +void menu_prepare_temp(uint8_t *val); +void menu_stop_temp(void); +void menu_send_temp(void); + +#endif /* MENU_H */ diff --git a/platform/avr-ravenlcd/raven3290.c b/platform/avr-ravenlcd/raven3290.c new file mode 100644 index 000000000..a122f44d4 --- /dev/null +++ b/platform/avr-ravenlcd/raven3290.c @@ -0,0 +1,389 @@ +/** + * \mainpage ATmega3290p LCD Driver Software for Raven + * + * + * \section intro_lcd LCD Introduction + * + * This Raven LCD Driver application software was designed for a user interface + * to the Contiki 6LoWPAN collaboration on board the ATmega3290p. The + * LCD functionality uses the binary command set described in the release notes. + * These binary commands can also be found in a list of main.h. + * + * \section compile_lcd Compiling Raven LCD Driver + * + * Raven LCD Driver can be compiled on the following platforms: + * + * -# WinAvr + AVR Studio (AVR-GCC). The @b ravenlcd_3290.aps file is used by AVR + * Studio. If you have WinAVR and AVR Studio installed, ravenlcd can be + * compiled and developed using free tools. The Makefile.avr-ravenlcd is not + * used with AVR Studio. + * -# AVR-GCC on Linux. The Makefile.avr-ravenlcd file is to be used for Linux. + * Be sure you have a recent toolchain installed, including patches + * required for GCC/avr-libc to recognize new devices. The avr-libc + * webpage includes a concise guide on how to patch and build the AVR + * toolchain. + * -# IAR EWB-AVR. is currently not supported. + * + * \section fuses Board fuse settings + * + * The Raven LCD (3290p device) requires the proper fuse settings to function + * properly. These settings have been summarized below: + * -# Raven LCD (3290p device) + * -# Extended: 0xFF (No Brown Out) + * -# High: 0x99 (JTAG and ISP enabled, No OCDEN or EEPROM saving required) + * -# Low: 0xE2 (Use Int RC OSC - Start-up Time:6CK + 65ms) + * + * \section notes Operation Release Notes + * + * After programming the Raven LCD 3290p with the proper image, you will be introduced to + * the menu in the picture below: + * + * \image html contiki_menu_3290.jpg + * + * Operating the menu requires that the matching command set has been programmed into + * the ATmega1284 application. This will allow the menu to communicate properly and control the + * Contiki 6LoWPAN applcation. + * + * During normal operation, you will need to make note of these IMPORTANT operating instructions: + * -# Temp Sensor - The temperature sensor shares the same GPIO as the JTAG interface for the 3290p. + * This requires the JTAG feature to be disabled in order to have proper temperature readings. + * -# Debug Menu - The DEBUG menu setting is used to configure this JTAG feature. + * -# If the JTAG feature is enabled during a temperature reading attempt, + * the menu will signal a caution symbol to the user letting them know the JTAG + * feature needs to be disabled. + * \image html caution.gif + * -# Temp Data - Once the temperature reading is proper, the user can send this reading + * to the webserver for Sensor Reading Data (Once or Auto). The webserver will + * only update the html data when refreshed. + * + * \section binary Binary Command Description + * + * Using the binary commmand list described in main.h, the 3290p will contruct a binary + * command serial frame to control the 1284p. An example command frame is contructed below: + * -# 0x01,0x01,0x81,0x01,0x04 - Send Ping Request number 1 to 1284p + * -# 0x01 - Start of binary command frame + * -# 0x01 - Length of binary command payload + * -# 0x81 - Binary command SEND_PING + * -# 0x01 - Payload value (eg. ping Request number 1) + * -# 0x04 - End of binary command frame + * + * The following commands are used to control the 1284p. + * -# SEND_TEMP - (0x80) + * -# SEND_PING - (0x81) + * + * The following commands are used to update the 3290p. + * -# REPORT_PING - (0xC0) + * -# REPORT_PING_BEEP - (0xC1) + * -# REPORT_TEXT_MSG - (0xC2) +*/ +/* + * Copyright (c) 2008 Swedish Institute of Computer Science + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of the copyright holders nor the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +/** + * \file + * + * \brief + * This is the main file for the Raven LCD application. + * + * \author + * Mike Vidales mavida404@gmail.com + * + */ + +#include "lcd.h" +#include "key.h" +#include "main.h" +#include "uart.h" +#include "timer.h" +#include "menu.h" +#include "temp.h" + +/** \defgroup lcd LCD Functions and data + * \{ +*/ + +#if defined( DOXYGEN ) +const char menu_text0[]; +const char menu_text1[]; +const char menu_text2[]; +const char menu_text3[]; +const char menu_text4[]; +const char menu_text5[]; +const char menu_text6[]; +const char menu_text7[]; +const char menu_text8[]; +const char menu_text9[]; +const char menu_text10[]; +const char menu_text11[]; +const char menu_text12[]; +const char menu_text13[]; +const char menu_text14[]; +const char menu_text15[]; +const tmenu_item menu_items[16]; +#else /* !DOXYGEN */ +/** \brief This is the menu text in Flash. See menu_items[] for menu operation. */ +const char menu_text0[] PROGMEM = "CONTIKI"; +const char menu_text1[] PROGMEM = "6LOWPAN"; +const char menu_text2[] PROGMEM = "PING"; +const char menu_text3[] PROGMEM = "PINGING"; +const char menu_text4[] PROGMEM = "TEMP"; +const char menu_text5[] PROGMEM = "MODE "; +const char menu_text6[] PROGMEM = "DEG F"; +const char menu_text7[] PROGMEM = "DEG C"; +const char menu_text8[] PROGMEM = "SEND"; +const char menu_text9[] PROGMEM = "ONCE"; +const char menu_text10[] PROGMEM = "AUTO"; +const char menu_text11[] PROGMEM = "DEBUG"; +const char menu_text12[] PROGMEM = "DBG ON"; +const char menu_text13[] PROGMEM = "DBG OFF"; +const char menu_text14[] PROGMEM = "SENT"; +const char menu_text15[] PROGMEM = "SENDING"; + +/*---------------------------------------------------------------------------*/ + +/** + * \brief Menus for user interface + * + * This constructs the Raven 3290p menu for the Contiki and 6lowpan collaboration. This + * follows the struct description of tmenu_item. + * + * { text, left, right, up, down, *state, tmenufunc enter_func} +*/ +const PROGMEM tmenu_item menu_items[16] = { + {menu_text0, 0, 2, 0, 0, 0, 0 }, + {menu_text1, 0, 2, 0, 0, 0, 0 }, + {menu_text2, 0, 3, 11, 4, 0, menu_ping_request }, + {menu_text3, 2, 2, 2, 2, 0, 0 }, + {menu_text4, 0, 5, 2, 11, 0, 0 }, + {menu_text5, 4, 6, 8, 8, 0, 0 }, + {menu_text6, 5, 5, 7, 7, (uint8_t*)1, menu_read_temp }, + {menu_text7, 5, 5, 6, 6, (uint8_t*)0, menu_read_temp }, + {menu_text8, 4, 9, 5, 5, 0, 0 }, + {menu_text9, 8, 14, 10, 10, (uint8_t*)0, menu_prepare_temp }, + {menu_text10, 8, 15, 9, 9, (uint8_t*)1, menu_prepare_temp }, + {menu_text11, 0, 12, 4, 2, 0, 0 }, + {menu_text12, 11, 11, 13, 13, (uint8_t*)1, menu_debug_mode }, + {menu_text13, 11, 11, 12, 12, (uint8_t*)0, menu_debug_mode }, + {menu_text14, 9, 14, 14, 14, 0, 0 }, + {menu_text15, 10, 15, 15, 15, 0, 0 }, +}; +#endif /* !DOXYGEN */ + +key_state_t button=KEY_STATE_NO_KEY; +tmenu_item menu; +uint8_t count; +uint8_t timeout_count; + +/*---------------------------------------------------------------------------*/ + +/** + * \brief This will read the menu_items[] from the index requested. + * + * \param ndx Position index of menu_items[] lookup. +*/ +void +read_menu(uint8_t ndx) +{ + /* Reads menu structure from Flash area */ + uint8_t i; + uint8_t *src = (uint8_t*)&menu_items[ndx]; + uint8_t *dest = (uint8_t*)&menu; + + for (i=0;iravenlcd_329025-Apr-2008 11:07:1628-Aug-2008 17:12:52241025-Apr-2008 11:07:1644, 13, 0, 569AVR GCCdefault\ravenlcd_3290.elfC:\Atmel\cisco\branches\macipv6\apps\ravenlcd_3290\JTAGICE mkIIATmega3290PfalseR00R01R02R03R04R05R06R07R08R09R10R11R12R13R14R15R16R17R18R19R20R21R22R23R24R25R26R27R28R29R30R31Auto00menuresultstrpnpayloadnumb0uart.cadc.ckey.clcd.cmenu.craven3290.csleep.cbeep.ctimer.ctemp.cdefault\ravenlcd_3290.lssdefault\ravenlcd_3290.mapdefaultNOatmega3290p111ravenlcd_3290.elfdefault\0.\-Wall -gdwarf-2 -std=gnu99 -DF_CPU=8000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enumsdefault1C:\Programme\WinAVR-20080610\bin\avr-gcc.exeC:\Programme\WinAVR-20080610\utils\bin\make.exeC:\Atmel\cisco\branches\macipv6\apps\ravenlcd_3290\uart.cC:\Atmel\cisco\branches\macipv6\apps\ravenlcd_3290\adc.cC:\Atmel\cisco\branches\macipv6\apps\ravenlcd_3290\key.cC:\Atmel\cisco\branches\macipv6\apps\ravenlcd_3290\lcd.cC:\Atmel\cisco\branches\macipv6\apps\ravenlcd_3290\menu.cC:\Atmel\cisco\branches\macipv6\apps\ravenlcd_3290\raven3290.cC:\Atmel\cisco\branches\macipv6\apps\ravenlcd_3290\sleep.cC:\Atmel\cisco\branches\macipv6\apps\ravenlcd_3290\beep.cC:\Atmel\cisco\branches\macipv6\apps\ravenlcd_3290\timer.cC:\Atmel\cisco\branches\macipv6\apps\ravenlcd_3290\temp.c00000raven3290.c25900001sleep.c25700002lcd.c25900003timer.c25900004adc.c25900005menu.c25900006temp.c25900007key.c25900008uart.c259 diff --git a/platform/avr-ravenlcd/sleep.c b/platform/avr-ravenlcd/sleep.c new file mode 100644 index 000000000..c9d07106b --- /dev/null +++ b/platform/avr-ravenlcd/sleep.c @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2008 Swedish Institute of Computer Science + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of the copyright holders nor the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +/** + * \file + * + * \brief + * This controls the sleep operation for the LCD. + * + * \author + * Mike Vidales mavida404@gmail.com + * + */ + +#include +#include +#include +#include +#include "sleep.h" +#include "uart.h" + +/** + * \addtogroup lcd + * \{ +*/ + +/*---------------------------------------------------------------------------*/ + +/** + * \brief Prepares for and executes sleep. This function sets up the + * processor to enter sleep mode, and to wake up when the joystick + * button (PE2/PCINT2) is pressed. +*/ +void +sleep_now(void) +{ + /* Disable watchdog */ + wdt_disable(); + + /* Setup sleep mode */ + set_sleep_mode(SLEEP_MODE_PWR_DOWN); + + /* Enable wakeup interrupt */ + EIMSK |= (1 << PCIE0); + /* Enable PCINT2 as interrupt */ + PCMSK0 |= (1 << PCINT2); + + /* Go to sleep now */ + sleep_mode(); + + /* Disable the interrupt for the enter button */ + EIMSK &= ~(1 << PCIE0); +} + +/*---------------------------------------------------------------------------*/ + +/** + * \brief This will send a single character forever to the ATmega1284p to cause a wakeup. + * + * The 1284p polls the USART for new data during each sleep cycle. Upon receiving a + * character from the user LCD, it will wake up and send an acknowledgement frame. +*/ +void +sleep_wakeup(void) +{ + /* First, clear the input buffer and get any chars waiting */ + while(rx_char_ready()){ + uart_get_char_rx(); + } + + /* Flood 1284p with serial chars until it responds. */ + for(;;){ + uart_send_byte('x'); + if (rx_char_ready()) + break; + } + /* Get a frame back */ + uart_serial_rcv_frame(true); +} + +/*---------------------------------------------------------------------------*/ + +/** + * \brief This is the wake up button interrupt. When this interrupt fires, + * nothing is done. The program will simply continue from the end of the sleep + * command. +*/ +ISR +(PCINT0_vect) +{ + +} + +/** \} */ diff --git a/platform/avr-ravenlcd/sleep.h b/platform/avr-ravenlcd/sleep.h new file mode 100644 index 000000000..abf4b0fe6 --- /dev/null +++ b/platform/avr-ravenlcd/sleep.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2008 Swedish Institute of Computer Science + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of the copyright holders nor the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +/** + * \file + * + * \brief + * This controls the sleep operation for the LCD. + * + * \author + * Mike Vidales mavida404@gmail.com + * + */ + +#ifndef __SLEEP_H__ +#define __SLEEP_H__ + +/* Prototypes */ +void sleep_now(void); +void sleep_wakeup(void); + +#endif /* __SLEEP_H__ */ diff --git a/platform/avr-ravenlcd/temp.c b/platform/avr-ravenlcd/temp.c new file mode 100644 index 000000000..c617f72c2 --- /dev/null +++ b/platform/avr-ravenlcd/temp.c @@ -0,0 +1,222 @@ +/* + * Copyright (c) 2008 Swedish Institute of Computer Science + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of the copyright holders nor the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +/** + * \file + * + * \brief + * Driver for the on board temperature sensor. + * + * \author + * Mike Vidales mavida404@gmail.com + * + */ + +#include "key.h" +#include "temp.h" +#include + +/** + * \addtogroup lcd + * \{ +*/ + +/** Type used together with find_temp() to find temperature */ +typedef enum { + TEMP_ZERO_OFFSET_CELCIUS = -15, + TEMP_ZERO_OFFSET_FAHRENHEIT = 0 +} temp_zero_offset_t; + +#if defined( DOXYGEN ) +static uint16_t temp_table_celcius[]; +static uint16_t temp_table_fahrenheit[]; +#else /* !DOXYGEN */ +/** Celcius temperatures (ADC-value) from -15 to 60 degrees */ +static uint16_t temp_table_celcius[] PROGMEM = { + 923,917,911,904,898,891,883,876,868,860,851,843,834,825,815, + 806,796,786,775,765,754,743,732,720,709,697,685,673,661,649, + 636,624,611,599,586,574,562,549,537,524,512,500,488,476,464, + 452,440,429,418,406,396,385,374,364,354,344,334,324,315,306, + 297,288,279,271,263,255,247,240,233,225,219,212,205,199,193, + 187, +}; + +/** Fahrenheit temperatures (ADC-value) from 0 to 140 degrees */ +static uint16_t temp_table_fahrenheit[] PROGMEM = { + 938, 935, 932, 929, 926, 923, 920, 916, 913, 909, 906, 902, 898, + 894, 891, 887, 882, 878, 874, 870, 865, 861, 856, 851, 847, 842, + 837, 832, 827, 822, 816, 811, 806, 800, 795, 789, 783, 778, 772, + 766, 760, 754, 748, 742, 735, 729, 723, 716, 710, 703, 697, 690, + 684, 677, 670, 663, 657, 650, 643, 636, 629, 622, 616, 609, 602, + 595, 588, 581, 574, 567, 560, 553, 546, 539, 533, 526, 519, 512, + 505, 498, 492, 485, 478, 472, 465, 459, 452, 446, 439, 433, 426, + 420, 414, 408, 402, 396, 390, 384, 378, 372, 366, 360, 355, 349, + 344, 338, 333, 327, 322, 317, 312, 307, 302, 297, 292, 287, 282, + 277, 273, 268, 264, 259, 255, 251, 246, 242, 238, 234, 230, 226, + 222, 219, 215, 211, 207, 204, 200, 197, 194, 190, 187, +}; +#endif /* !DOXYGEN */ + +/** Flag indicating initialized or not */ +bool temp_initialized = false; + +/** \brief Find array index corresponding to input ADC value + * + * Returned array index is actual temperature + zero offset. To + * get actual temperature, the zero offset (\ref temp_zero_offset_t) + * has to be subtracted. + * + * \param[in] value Value to seracah for in table + * \param[in] array Pointer to array in which to look for ADC value + * \param[in] count Size of array + * + * + * \return EOF on error + */ +static int find_temp(int16_t value, uint16_t* array, int count); + +/*---------------------------------------------------------------------------*/ + +/** + * \brief This will initialize the digital IO and adc channel for temperture readings. + * + * \retval 0 Place holder for returning status. +*/ +int +temp_init(void) +{ + /* Disable the Digital IO for the analog readings. */ + DIDR0 |= (1 << ADC4D); + + /* Temp sens power pin as output */ + TEMP_DDR |= (1 << TEMP_BIT_PWR); + + /* Power off temp sensor */ + TEMP_PORT &= ~(1 << TEMP_BIT_PWR); + + /* Temp sens input, no pullup */ + TEMP_DDR &= ~(1 << TEMP_BIT_IN); + TEMP_PORT &= ~(1 << TEMP_BIT_IN); + + temp_initialized = true; + + return 0; +} + +/*---------------------------------------------------------------------------*/ + +/** + * \brief This will disable temperature readings by reseting the initialed flag. +*/ +void +temp_deinit(void) +{ + temp_initialized = false; +} + +/*---------------------------------------------------------------------------*/ + +/** + * \brief This will turn on the adc channel for reading the temp sensor. + * + * After the raw adc value is stored, it will be used to lookup a degree conversion + * based on the tables for F or C. + * + * \param unit Used to determine what unit needs to be appended with the value. + * + * \return EOF This is an uninitialized adc error. + * \retval temp The newly converted value in degrees F or C. +*/ +int16_t +temp_get(temp_unit_t unit) +{ + int16_t res; + int16_t temp; + + /* Return if temp sensor driver not initialized */ + if (temp_initialized == false) { + return EOF; + } + + /* Power up sensor */ + TEMP_PORT |= (1 << TEMP_BIT_PWR); + + /* Init ADC and measure */ + adc_init(ADC_CHAN_ADC4, ADC_TRIG_FREE_RUN, ADC_REF_AVCC, ADC_PS_128); + adc_conversion_start(); + while ((res = adc_result_get(ADC_ADJ_RIGHT)) == EOF ){ + ; + } + adc_deinit(); + /* Re-init the adc for buttons. */ + key_init(); + + /* Power down sensor */ + TEMP_PORT &= ~(1 << TEMP_BIT_PWR); + + /* Get corresponding temperature from table */ + if (unit == TEMP_UNIT_CELCIUS) { + temp = find_temp(res, temp_table_celcius, sizeof(temp_table_celcius)/sizeof(int)) + TEMP_ZERO_OFFSET_CELCIUS; + } else /*unit == TEMP_UNIT_FAHRENHEIT*/{ + temp = find_temp(res, temp_table_fahrenheit, sizeof(temp_table_fahrenheit)/sizeof(int)) + TEMP_ZERO_OFFSET_FAHRENHEIT; + } + + return temp; +} + +/*---------------------------------------------------------------------------*/ + +/** + * \brief Find array index corresponding to input ADC value + * + * Returned array index is actual temperature + zero offset. To + * get actual temperature, the zero offset (\ref temp_zero_offset_t) + * has to be subtracted. + * + * \param[in] value Value to search for in table + * \param[in] array Pointer to array in which to look for ADC value + * \param[in] count Size of array + * + * \return EOF on error +*/ +static int +find_temp(int16_t value, uint16_t* array, int count) +{ + int i = 0; + int table_val = 0; + do{ + table_val = pgm_read_word(&array[i]); + if (table_val < value) { + return i; + } + } while(++i +#include +#include +#include "adc.h" + +#define PROGMEM_DECLARE(x) x __attribute__((__progmem__)) + +/** \addtogroup grNTC */ +/** \{ */ +/** Type used with \ref temp_get() to select temperature unit */ +typedef enum { + TEMP_UNIT_CELCIUS, + TEMP_UNIT_FAHRENHEIT +} temp_unit_t; + +/** \name Definition of Port Pin for temp sensor. */ +/** \{ */ +#define TEMP_PORT PORTF +#define TEMP_DDR DDRF +#define TEMP_PIN PINF +#define TEMP_BIT_IN 4 +#define TEMP_BIT_PWR 6 +/** \} */ + +/** \brief Initialize the temperature sensor + * + * \return EOF on error + */ +int temp_init(void); + + +/** \brief De-initialize the temperature sensor + * + */ +void temp_deinit(void); + +/** \brief Read current temperature + * + * \param[in] unit Selected temperature unit (\ref temp_unit_t) + * + * + * \return EOF on error + */ +int16_t temp_get(temp_unit_t unit); +/** \} */ +#endif /* __TEMP_H__ */ diff --git a/platform/avr-ravenlcd/timer.c b/platform/avr-ravenlcd/timer.c new file mode 100644 index 000000000..b055d8c90 --- /dev/null +++ b/platform/avr-ravenlcd/timer.c @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2008 Swedish Institute of Computer Science + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of the copyright holders nor the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +/** + * \file + * + * \brief + * This file will configure the timer during LCD operation. + * + * \author + * Mike Vidales mavida404@gmail.com + * + */ + +#include "lcd.h" +#include "timer.h" + +/** + * \addtogroup lcd + * \{ +*/ + +bool timer_flag; + +/*---------------------------------------------------------------------------*/ + +/** + * \brief TIMER1 init for timer used by LCD. + * + * The FPU of 8MHz with a prescaler of 1024 equals 7812.5 timer ticks creating a + * resolution of 128us per tick. + * + * NOTE: The TIMER1 interrupt is not enabled in this routine +*/ +void +timer_init(void) +{ + /* + * Set TIMER1 output compare mode to clear on compare match for OC1A. Also + * set the pre-scaler to 1024. + */ + TCCR1B = (1 << WGM12)|(1 << CS12)|(1 << CS10); + + /* Set TIMER1 output compare register approx. 1 sec resolution. */ + OCR1A = _1_SEC; +} + +/*---------------------------------------------------------------------------*/ + +/** + * \brief Start the timer. +*/ +void +timer_start(void) +{ + /* Clear TIMER1 timer counter value. */ + TCNT1 = 0; + + /* Enable TIMER1 output compare interrupt. */ + TIMSK1 = (1 << OCIE1A); +} + +/*---------------------------------------------------------------------------*/ + +/** + * \brief Stop the timer. +*/ +void +timer_stop(void) +{ + /* Disable TIMER1 output compare interrupt. */ + TIMSK1 &= ~(1 << OCIE1A); +} + +/*---------------------------------------------------------------------------*/ + +/** + * \brief This is the interrupt subroutine for the TIMER1 output match comparison. +*/ +ISR +(TIMER1_COMPA_vect) +{ + /* Set the irq flag. */ + timer_flag = true; +} + +/** \} */ diff --git a/platform/avr-ravenlcd/timer.h b/platform/avr-ravenlcd/timer.h new file mode 100644 index 000000000..cd8f691a9 --- /dev/null +++ b/platform/avr-ravenlcd/timer.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2008 Swedish Institute of Computer Science + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of the copyright holders nor the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +/** + * \file + * + * \brief + * This file supports the timer functionality for the LCD. + * + * \author + * Mike Vidales mavida404@gmail.com + * + */ + +#ifndef TIMER_H +#define TIMER_H + +extern bool timer_flag; + +#define _1_SEC (0x1E84); + +void timer_init(void); +void timer_start(void); +void timer_stop(void); + +#endif /* TIMER_H */ \ No newline at end of file diff --git a/platform/avr-ravenlcd/uart.c b/platform/avr-ravenlcd/uart.c new file mode 100644 index 000000000..ef2a74470 --- /dev/null +++ b/platform/avr-ravenlcd/uart.c @@ -0,0 +1,450 @@ +/* + * Copyright (c) 2008 Swedish Institute of Computer Science + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of the copyright holders nor the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +/** + * \file + * + * \brief + * Handles the control of the USART for communication with the ATmega1284p + * for sending commands. + * + * \author + * Mike Vidales mavida404@gmail.com + * + */ + +#include "uart.h" +#include "lcd.h" +#include "main.h" +#include "menu.h" +#include "beep.h" + +/** + * \addtogroup lcd + * \{ +*/ + +#define TIMEOUT (0xff) + +/** \brief The RX circular buffer, for storing characters from serial port. */ +tcirc_buf rxbuf; + +/*---------------------------------------------------------------------------*/ + +/** + * \brief This will intialize the circular buffer head and tail of tcirc_buf struct. + * + * \param cbuf Pointer to buffer to initialize. +*/ +void +uart_init_circ_buf(tcirc_buf *cbuf) +{ + cbuf->head = cbuf->tail = 0; +} + +/*---------------------------------------------------------------------------*/ + +/** + * \brief This will add a new character to the circular buffer. + * + * \param cbuf Pointer to buffer where character will be stored. + * \param ch Character to store into buffer. +*/ +void +uart_add_to_circ_buf(tcirc_buf *cbuf, uint8_t ch) +{ + /* Add char to buffer */ + uint8_t newhead = cbuf->head; + newhead++; + if (newhead >= BUFSIZE){ + newhead = 0; + } + if (newhead == cbuf->tail){ + /* Buffer full, quit it */ + return; + } + + cbuf->buf[cbuf->head] = ch; + cbuf->head = newhead; +} + +/*---------------------------------------------------------------------------*/ + +/** + * \brief This will get a character from the buffer requested. + * + * \param cbuf Pointer to buffer to get character from. + * + * \return retval Return character from buffer. +*/ +uint8_t +uart_get_from_circ_buf(tcirc_buf *cbuf) +{ + /* Get char from buffer. */ + /* Be sure to check first that there is a char in buffer. */ + uint8_t newtail = cbuf->tail; + uint8_t retval = cbuf->buf[newtail]; + + newtail++; + if (newtail >= BUFSIZE){ + /* Rollover */ + newtail = 0; + } + cbuf->tail = newtail; + + return retval; +} + +/*---------------------------------------------------------------------------*/ + +/** + * \brief This will clear the RX buffer. +*/ +void +uart_clear_rx_buf(void) +{ + rxbuf.tail = rxbuf.head = 0; +} + +/** + * \brief This will check for a character in the requested buffer. + * + * \param cbuf Pointer to buffer to check for any characters. + * + * \return True if buffer empty. +*/ +uint8_t +uart_circ_buf_has_char(tcirc_buf *cbuf) +{ + /* Return true if buffer empty */ + return (cbuf->head != cbuf->tail); +} + +/*---------------------------------------------------------------------------*/ + +/** + * \brief This will convert a nibble to a hex value. + * + * \param val Value to convert to hex. + * + * \return val Converted hex value +*/ +uint8_t +ntohex(uint8_t val) +{ + /* Convert nibble to hex */ + if (val > 9){ + return val + 'A' - 10; + } + else{ + return val + '0'; + } +} + +/*---------------------------------------------------------------------------*/ + +/** + * \brief Convert integer to hex value. + * + * \param val Value to convert to hex. + * \param str Location to store converted value. +*/ +void +itohex(uint8_t val,char *str) +{ + *str++ = ntohex(val >> 8); + *str = ntohex(val & 0x0f); +} + +/*---------------------------------------------------------------------------*/ + +/** + * \brief This will wait for a new character from the ATmega1284p and timeout + * if no new character is received. + * + * \retval TIMEOUT Returns if timeout has occured. + * \return retval Character returned upon seeing rx_char_ready() +*/ +uint8_t +uart_get_char_rx(void) +{ + /* Gets a serial char, and waits for timeout */ + uint32_t timex = 5000000; + uint8_t retval; + + while (!rx_char_ready()){ + if (!timex--){ + /* Timeout, return timeout */ + return TIMEOUT; + } + } + + retval = uart_get_from_circ_buf(&rxbuf); + return retval; +} + +/*---------------------------------------------------------------------------*/ + +/** + * \brief Initialize UART to 38400 Baud Rate and only + * enable UART for transmission. +*/ +void +uart_init(void) +{ + /* For Mega3290P, enable the uart peripheral */ + PRR &= ~(1 << PRUSART0); + + uart_clear_rx_buf(); + /* 38400 baud @ 8 MHz internal RC oscillator (error = 0.2%) */ + UBRR0 = BAUD_RATE_38400; + + /* 8 bit character size, 1 stop bit and no parity mode */ + UCSR0C = ( 3 << UCSZ00); + + /* Enable RX,TX and RX interrupt on USART */ + UCSR0B = (1 << RXEN0)|(1 << TXEN0)|(1 << RXCIE0); +} + +/*---------------------------------------------------------------------------*/ + +/** + * \brief Turn off UART for sleep mode. +*/ +void +uart_deinit(void) +{ + /* Disable RX,TX and RX interrupt on USART */ + UCSR0B = 0; + + /* for Mega3290P, disable the uart peripheral */ + PRR |= (1 << PRUSART0); +} + +/*---------------------------------------------------------------------------*/ + +/** + * \brief Send one byte over the uart. This is called to send binary commands. + * + * \param byte The byte of data to send out the uart. +*/ +void +uart_send_byte(uint8_t byte) +{ + /* Wait for last char to be gone... */ + while(!(UCSR0A & (1 << UDRE0))) + ; + UDR0 = byte; +} + +/*---------------------------------------------------------------------------*/ + +/** + * \brief This is the USART RX complete interrupt. +*/ +ISR +(USART_RX_vect) +{ + /* Get byte from serial port, put in Rx Buffer. */ + uint8_t retval; + + retval = UDR0; + uart_add_to_circ_buf(&rxbuf, retval); +} + +/*---------------------------------------------------------------------------*/ + +/** + * \brief This function builds and sends a binary command frame to the + * ATmega1284p. + * + * \param cmd Command to send. + * \param payload_length Length of data to be sent with command. + * \param payload Pointer to data to send. +*/ +void +uart_serial_send_frame(uint8_t cmd, uint8_t payload_length, uint8_t *payload) +{ + /* Send a frame to 1284p */ + int8_t i; + + uart_send_byte(SOF_CHAR); + uart_send_byte(payload_length); + uart_send_byte(cmd); + for (i=0;i<=payload_length-1;i++){ + uart_send_byte(payload[i]); + } + uart_send_byte(EOF_CHAR); +} + +/*---------------------------------------------------------------------------*/ + +/** + * \brief This displays a time out message to the user based on the parameter + * reason x. + * + * \param x Reason for USART time out. +*/ +void +uart_timeout_msg(uint8_t x) +{ + char str[20] = "TO "; + + dectoascii(x, str+3); + lcd_puts(str); +} + +/*---------------------------------------------------------------------------*/ + +/** + * \brief This will receive a frame from the ATmega1284p and parse the incoming + * data. + * + * If the incoming data is a binary command acknowledgement, then this will not + * parse any data. If the incoming data is test reports, the menu will store the + * data for end of test metrics. + * + * \param wait_for_ack Flag used to wait for acknowledgement when receving a serial + * frame. +*/ +void +uart_serial_rcv_frame(uint8_t wait_for_ack) +{ + /* Gets a serial frame, if any, and displays data appropriately */ + /* If wait_for_ack is true, this funtion will wait for serial chars. */ + volatile uint8_t ch; + volatile uint8_t length; + volatile uint8_t cmd; + volatile uint8_t payload[10]; + uint16_t i; + + if (!wait_for_ack && !rx_char_ready()){ + return; + } + + /* Check for SOF */ + ch = uart_get_char_rx(); + if (ch != SOF_CHAR){ + return uart_timeout_msg(1); + } + + /* Turn on nose LED for activity indicator */ + led_on(); + + /* Get length byte */ + ch = uart_get_char_rx(); + if (ch == TIMEOUT){ + return uart_timeout_msg(2); + } + /* Check for ACK Frame */ + if (ch >= 0x80){ + /* This is an ack frame, just get it and go away. */ + ch = uart_get_char_rx(); + if (ch != EOF_CHAR){ + uart_timeout_msg(3); + } + led_off(); + return; + } + + length = ch; + if (length > 10){ + /* invalid length */ + return; + } + + /* Get cmd byte */ + ch = uart_get_char_rx(); + if (ch == TIMEOUT){ + return uart_timeout_msg(5); + } + cmd = ch; + + /* Get payload */ + for (i=0;i + +/** \name ASCII characters defined */ +/** \{ */ +#define SOF_CHAR (0x01) /**< Start-of-frame character. */ +#define EOF_CHAR (0x04) /**< End-of-frame character. */ +#define TERM_CHAR (0x14) /**< Control-T ASCII value for entering terminal mode. */ +/** \} */ + + +/** \name Define Lengths. */ +/** \{ */ +#define MAX_CMD_LENGTH (0x0A) +#define ACK_LENGTH (0x02) +/** \} */ + +/** \name Define IO result values. */ +/** \{ */ +#define IO_SUCCESS (0) +#define IO_FAIL (1) +/** \} */ + +#define LEN_BYTE (0) +#define CMD_BYTE (1) +#define BAUD_RATE_38400 (12) + +/* Macros & Defines */ + +#define BUFSIZE 80 + +/** \brief Circular buffer structure */ +typedef struct { + volatile uint8_t head; /**< Index to last available character in buffer. */ + volatile uint8_t tail; /**< Index to first available character in buffer. */ + uint8_t buf[BUFSIZE]; /**< The actual buffer used for storing characters. */ +} tcirc_buf; + +extern tcirc_buf rxbuf; +#define rx_char_ready() (rxbuf.head != rxbuf.tail) + +/* Serial port functions */ +void uart_init(void); +void uart_deinit(void); +uint8_t uart_circ_buf_has_char(tcirc_buf *cbuf); +void uart_clear_rx_buf(void); +uint8_t uart_get_char_rx(void); +void uart_send_byte(uint8_t byte); +void uart_serial_send_frame(uint8_t cmd, uint8_t payload_length, uint8_t *payload); +void uart_serial_rcv_frame(uint8_t wait_for_it); + +#endif /* __UART_H__ */ diff --git a/platform/avr-ravenusb/Makefile.avr-ravenusb b/platform/avr-ravenusb/Makefile.avr-ravenusb new file mode 100644 index 000000000..57db281cf --- /dev/null +++ b/platform/avr-ravenusb/Makefile.avr-ravenusb @@ -0,0 +1,61 @@ +CONTIKI_TARGET_DIRS = . rf230 apps net loader +CONTIKI_CORE=contiki-raven-main +CONTIKI_TARGET_MAIN = ${CONTIKI_CORE}.o + +#USB Ethernet Interface + USB Serial Port TX Only +USB = uart_usb_lib.c \ + cdc_task.c \ + rndis_task.c \ + rndis.c \ + usb_descriptors.c \ + usb_drv.c \ + usb_specific_request.c \ + usb_standard_request.c \ + usb_task.c \ + scsi_decoder.c \ + ctrl_access.c \ + storage_task.c \ + avr_flash.c + +CONTIKI_TARGET_SOURCEFILES += slip.c cfs-eeprom.c eeprom.c random.c \ + mmem.c contiki-raven-default-init-lowlevel.c \ + contiki-raven-default-init-net.c contiki-raven-main.c \ + sicslow_ethernet.c \ + $(USB) + +USB_INCLUDES = -I$(CONTIKI_CPU)/dev/usb + +CONTIKIAVR=$(CONTIKI)/cpu/avr +CONTIKIBOARD=. + +CONTIKI_PLAT_DEFS = -DF_CPU=8000000UL -DAVRGCC -DAUTO_CRC_PADDING=2 + + +MCU=at90usb1287 +AVRDUDE_PROGRAMMER=jtag2 + +# For usb devices, you may either use PORT=usb, or (e.g. if you have more than one +# programmer connected) you can use the following trick to find out the serial number: +# +# The example is for an JTAGICE mkII used to program an ATmega128: +# avrdude -v -P usb:xxxx -c jtag2 -p atmega128 +AVRDUDE_PORT=usb:00B000000D79 + + + +# Additional avrdude options +# Verify off +AVRDUDE_OPTIONS=-V + + +include $(CONTIKIAVR)/Makefile.avr + +# Source for AT86RF230 +include $(CONTIKI)/cpu/avr/radio/rf230/Makefile.rf230 + +# Source for Atmel/Cisco 802.15.4'ish MAC +include $(CONTIKI)/cpu/avr/radio/mac/Makefile.mac + +# Source for IEEE 802.15.4 manager interface +include $(CONTIKI)/cpu/avr/radio/ieee-manager/Makefile.ieee-manager + diff --git a/platform/avr-ravenusb/avr-ravenusb-eeprom.hex b/platform/avr-ravenusb/avr-ravenusb-eeprom.hex new file mode 100755 index 000000000..1e9f10f29 --- /dev/null +++ b/platform/avr-ravenusb/avr-ravenusb-eeprom.hex @@ -0,0 +1,65 @@ +:10000000000002AABBCCDDEEFFFFFFFFFFFFFFFFFA +:10001000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0 +:10002000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE0 +:10003000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD0 +:10004000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC0 +:10005000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFB0 +:10006000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA0 +:10007000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF90 +:10008000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF80 +:10009000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF70 +:1000A000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF60 +:1000B000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF50 +:1000C000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF40 +:1000D000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF30 +:1000E000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF20 +:1000F000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF10 +:10010000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF +:10011000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEF +:10012000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFDF +:10013000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFCF +:10014000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFBF +:10015000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFAF +:10016000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF9F +:10017000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF8F +:10018000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7F +:10019000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF6F +:1001A000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5F +:1001B000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF4F +:1001C000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3F +:1001D000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF2F +:1001E000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF1F +:1001F000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0F +:10020000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE +:10021000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEE +:10022000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFDE +:10023000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFCE +:10024000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFBE +:10025000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFAE +:10026000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF9E +:10027000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF8E +:10028000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7E +:10029000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF6E +:1002A000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5E +:1002B000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF4E +:1002C000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3E +:1002D000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF2E +:1002E000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF1E +:1002F000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0E +:10030000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD +:10031000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFED +:10032000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFDD +:10033000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFCD +:10034000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFBD +:10035000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFAD +:10036000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF9D +:10037000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF8D +:10038000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7D +:10039000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF6D +:1003A000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D +:1003B000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF4D +:1003C000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3D +:1003D000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF2D +:1003E000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF1D +:1003F000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0D +:00000001FF diff --git a/platform/avr-ravenusb/contiki-conf.h b/platform/avr-ravenusb/contiki-conf.h new file mode 100644 index 000000000..98f6e3c2c --- /dev/null +++ b/platform/avr-ravenusb/contiki-conf.h @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2006, Technical University of Munich + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the Contiki operating system. + * + * @(#)$$ + */ + +/** + * \file + * Configuration for sample STK 501 Contiki kernel + * + * \author + * Simon Barner + +typedef int32_t s32_t; + +/* + * MCU and clock rate + */ +#define MCU_MHZ 8 +#define PLATFORM PLATFORM_AVR +#define RAVEN_REVISION RAVENUSB_C + +/* Cock ticks per second */ +#define CLOCK_CONF_SECOND 125 + +/* Maximum time interval (used for timers) */ +#define INFINITE_TIME 0xffff + +/* COM port to be used for SLIP connection */ +#define SLIP_PORT RS232_PORT_0 + +/* Pre-allocated memory for loadable modules heap space (in bytes)*/ +#define MMEM_CONF_SIZE 256 + +/* Use the following address for code received via the codeprop + * facility + */ +#define EEPROMFS_ADDR_CODEPROP 0x8000 + +#define CCIF +#define CLIF + +#define RIMEADDR_CONF_SIZE 8 + +/* 0 for IPv6, or 1 for HC1, 2 for HC01 */ +#define SICSLOWPAN_CONF_COMPRESSION_IPV6 0 +#define SICSLOWPAN_CONF_COMPRESSION_HC1 1 +#define SICSLOWPAN_CONF_COMPRESSION_HC01 2 + +#define SICSLOWPAN_CONF_COMPRESSION SICSLOWPAN_CONF_COMPRESSION_HC01 +#define SICSLOWPAN_CONF_MAX_ADDR_CONTEXTS 2 +#define SICSLOWPAN_CONF_FRAG 1 + +#define SICSLOWPAN_CONF_MAXAGE 5 + +#define UIP_CONF_LL_802154 1 +#define UIP_CONF_LLH_LEN 14 + +#define UIP_CONF_MAX_CONNECTIONS 4 +#define UIP_CONF_MAX_LISTENPORTS 4 + +#define UIP_CONF_IP_FORWARD 0 +#define UIP_CONF_FWCACHE_SIZE 0 + +#define UIP_CONF_IPV6 1 +#define UIP_CONF_IPV6_CHECKS 1 +#define UIP_CONF_IPV6_QUEUE_PKT 0 +#define UIP_CONF_IPV6_REASSEMBLY 0 +#define UIP_CONF_NETIF_MAX_ADDRESSES 3 +#define UIP_CONF_ND6_MAX_PREFIXES 3 +#define UIP_CONF_ND6_MAX_NEIGHBORS 4 +#define UIP_CONF_ND6_MAX_DEFROUTERS 2 + +#define UIP_CONF_UDP 1 +#define UIP_CONF_UDP_CHECKSUMS 1 + +#define UIP_CONF_TCP 1 +#define UIP_CONF_TCP_SPLIT 1 + +#define UIP_CONF_STATISTICS 1 + +typedef unsigned short clock_time_t; +typedef unsigned char u8_t; +typedef unsigned short u16_t; +typedef unsigned long u32_t; +typedef unsigned short uip_stats_t; +typedef unsigned long off_t; + +void clock_delay(unsigned int us2); +void clock_wait(int ms10); +void clock_set_seconds(unsigned long s); +unsigned long clock_seconds(void); + +#endif /* __CONTIKI_CONF_H__ */ diff --git a/platform/avr-ravenusb/contiki-raven-default-init-lowlevel.c b/platform/avr-ravenusb/contiki-raven-default-init-lowlevel.c new file mode 100644 index 000000000..a888673bf --- /dev/null +++ b/platform/avr-ravenusb/contiki-raven-default-init-lowlevel.c @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2006, Technical University of Munich + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the Contiki operating system. + * + * Author: Simon Barner + * + * @(#)$$ + */ +#include "contiki-raven.h" + +#include "contiki.h" +#include "usb_drv.h" +#include "usb_descriptors.h" +#include "usb_specific_request.h" +#include + +uint8_t checkForFinger(void); + +void +init_lowlevel(void) +{ + Leds_init(); + Leds_off(); + + if (checkForFinger()) { + usb_mode = mass_storage; + } + + return; + +} + + +uint8_t checkForFinger(void) +{ + uint8_t tests; + uint8_t matches; + + /* + Three pads on RZUSBSTICK go: GND PD3 PD2 + + We pulse PD3, and check for that pattern on PD2. + + A (moist) finger across those three pads should be enough + to bridge these + */ + + //Output + DDRD |= 1< 70) { + return 1; + } + + return 0; +} diff --git a/platform/avr-ravenusb/contiki-raven-default-init-net.c b/platform/avr-ravenusb/contiki-raven-default-init-net.c new file mode 100644 index 000000000..8da620889 --- /dev/null +++ b/platform/avr-ravenusb/contiki-raven-default-init-net.c @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2006, Technical University of Munich + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the Contiki operating system. + * + * Author: Simon Barner + * + * @(#)$$ + */ + +#include "contiki-raven.h" + +#include "mac.h" +#include "sicslowpan.h" +extern uint64_t rndis_ethernet_addr; + +void +init_net(void) +{ + + /* Set the Ethernet address to the 15.4 MAC address low 5 bytes...*/ + rndis_ethernet_addr = macLongAddr & 0x0000ffffffffffffUL; + /* Set as locally administed address */ + rndis_ethernet_addr |= 0x020000000000UL; + + ieee15_4ManagerAddress.set_long_addr(rndis_ethernet_addr); +} + + diff --git a/platform/avr-ravenusb/contiki-raven-main.c b/platform/avr-ravenusb/contiki-raven-main.c new file mode 100644 index 000000000..df7e44092 --- /dev/null +++ b/platform/avr-ravenusb/contiki-raven-main.c @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2006, Technical University of Munich + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the Contiki operating system. + * + * @(#)$$ + */ + +/** + * \file + * Sample Contiki kernel for STK 501 development board + * + * \author + * Simon Barner +#include +#include + + +#include "lib/mmem.h" +#include "loader/symbols-def.h" +#include "loader/symtab.h" +#include +#include "mac.h" +#include "sicslowmac.h" +#include "sicslowpan.h" +#include "ieee-15-4-manager.h" + +#include "contiki.h" +#include "contiki-net.h" +#include "contiki-lib.h" +#include "contiki-raven.h" + +#include "usb_task.h" +#include "serial/cdc_task.h" +#include "rndis/rndis_task.h" +#include "storage/storage_task.h" + +PROCINIT(&etimer_process, &mac_process); + +int +main(void) +{ + /* + * GCC depends on register r1 set to 0. + */ + asm volatile ("clr r1"); + + /* Initialize hardware */ + init_lowlevel(); + + /* Clock */ + clock_init(); + + printf_P(PSTR("\n\n\n********BOOTING CONTIKI*********\n")); + + /* Process subsystem */ + process_init(); + + /* Register initial processes */ + procinit_init(); + + /* Setup USB */ + process_start(&usb_process, NULL); + process_start(&cdc_process, NULL); + process_start(&rndis_process, NULL); + process_start(&storage_process, NULL); + + printf_P(PSTR("System online.\n")); + + //Fix MAC address + init_net(); + + /* Main scheduler loop */ + while(1) { + process_run(); + } + + return 0; +} + + + + + diff --git a/platform/avr-ravenusb/contiki-raven.h b/platform/avr-ravenusb/contiki-raven.h new file mode 100644 index 000000000..9d62f4956 --- /dev/null +++ b/platform/avr-ravenusb/contiki-raven.h @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2006, Technical University of Munich + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the Contiki operating system. + * + * @(#)$$ + */ + +/** + * \file + * Sample Contiki kernel for STK 501 development board + * + * \author + * Simon Barner + */ +#include +#include "dev/rs232.h" +#include "contiki.h" + +PROCESS(test_process1, "Test process"); +PROCESS_THREAD(test_process1, ev, data) +{ + static struct etimer etimer; + + PROCESS_BEGIN(); + + rs232_print (RS232_PORT_1, "test_process 1 starting\n"); + + while(1) { + etimer_set(&etimer, CLOCK_SECOND); + PROCESS_WAIT_UNTIL(etimer_expired(&etimer)); + rs232_print (RS232_PORT_1, "Tick\n"); + etimer_set(&etimer, CLOCK_SECOND); + PROCESS_WAIT_UNTIL(etimer_expired(&etimer)); + rs232_print (RS232_PORT_1, "Tack\n"); + } + + PROCESS_END(); +} + + +CLIF struct process * const autostart_processes[] = {&test_process1};