Add stk500 platform and changes suggested by Daniel Willmann
This commit is contained in:
parent
e953b66f78
commit
e2ad2acde4
@ -44,7 +44,7 @@
|
||||
* The RAM needed for each entry depends on script enabling and buffer sizes; see struct httpd_state below.
|
||||
* Typical range is 100 - 200 bytes per connection
|
||||
*/
|
||||
#if CONTIKI_TARGET_SKY
|
||||
#if CONTIKI_TARGET_SKY || CONTIKI_TARGET_STK500
|
||||
#define WEBSERVER_CONF_CONNS 2
|
||||
#define WEBSERVER_CONF_NAMESIZE 16
|
||||
#define WEBSERVER_CONF_BUFSIZE 40
|
||||
|
@ -38,6 +38,7 @@
|
||||
#include "dev/rs232.h"
|
||||
#include "elfloader-arch.h"
|
||||
#include "lib/mmem.h"
|
||||
#include <string.h> //memset
|
||||
|
||||
#define R_AVR_NONE 0
|
||||
#define R_AVR_32 1
|
||||
@ -116,7 +117,7 @@ BOOTLOADER_SECTION void
|
||||
elfloader_arch_write_rom(int fd, unsigned short textoff, unsigned int size, char *mem)
|
||||
{
|
||||
unsigned char buf[SPM_PAGESIZE];
|
||||
unsigned short* flashptr = mem;
|
||||
unsigned short* flashptr = (unsigned short *) mem;
|
||||
|
||||
|
||||
// Sanity-check size of loadable module
|
||||
@ -127,7 +128,7 @@ elfloader_arch_write_rom(int fd, unsigned short textoff, unsigned int size, char
|
||||
// Seek to patched module and burn it to flash (in chunks of
|
||||
// size SPM_PAGESIZE, i.e. 256 bytes on the ATmega128)
|
||||
cfs_seek(fd, textoff, CFS_SEEK_SET);
|
||||
for (flashptr=mem; flashptr < mem + size; flashptr += SPM_PAGESIZE) {
|
||||
for (flashptr=(unsigned short *)mem; flashptr < (unsigned short *) mem + size; flashptr += SPM_PAGESIZE) {
|
||||
memset (buf, 0, SPM_PAGESIZE);
|
||||
cfs_read(fd, buf, SPM_PAGESIZE);
|
||||
|
||||
|
@ -177,8 +177,8 @@ endif
|
||||
# $(STRIP) --strip-unneeded -g -x $@
|
||||
|
||||
%.co: %.c
|
||||
cp ${CONTIKI}/tools/empty-symbols.c symbols.c
|
||||
cp ${CONTIKI}/tools/empty-symbols.h symbols.h
|
||||
cp $(CONTIKI)/tools/empty-symbols.c symbols.c
|
||||
cp $(CONTIKI)/tools/empty-symbols.h symbols.h
|
||||
$(CC) $(CFLAGS) -DAUTOSTART_ENABLE -c $< -o $@
|
||||
|
||||
%-stripped.o: %.o
|
||||
@ -191,8 +191,15 @@ endif
|
||||
$(OBJCOPY) -O srec $< $@
|
||||
|
||||
### Upload image
|
||||
#Let avrdude use defaults if port or programmer not defined
|
||||
ifdef AVRDUDE_PORT
|
||||
AVRDUDE_PORT:=-P $(AVRDUDE_PORT)
|
||||
endif
|
||||
ifdef AVRDUDE_PROGRAMMER
|
||||
AVRDUDE_PROGRAMMER:=-c $(AVRDUDE_PROGRAMMER)
|
||||
endif
|
||||
%.u: %.hex
|
||||
avrdude ${AVRDUDE_OPTIONS} -P ${AVRDUDE_PORT} -c ${AVRDUDE_PROGRAMMER} -p ${MCU} -U flash:w:$<
|
||||
avrdude $(AVRDUDE_OPTIONS) $(AVRDUDE_PORT) $(AVRDUDE_PROGRAMMER) -p $(MCU) -U flash:w:$<
|
||||
|
||||
symbols.c:
|
||||
cp ${CONTIKI}/tools/empty-symbols.c symbols.c
|
||||
|
@ -6,13 +6,25 @@
|
||||
#include <avr/pgmspace.h>
|
||||
#include "dev/usb/usb_drv.h"
|
||||
|
||||
//Not all AVR toolchains alias MCUSR to the older MSUSCR name
|
||||
//#if defined (__AVR_ATmega8__) || defined (__AVR_ATmega8515__) || defined (__AVR_ATmega16__)
|
||||
#if !defined (MCUSR) && defined (MCUCSR)
|
||||
#warning *** MCUSR not defined, using MCUCSR instead ***
|
||||
#define MCUSR MCUCSR
|
||||
#endif
|
||||
|
||||
volatile uint32_t Boot_Key ATTR_NO_INIT;
|
||||
|
||||
bool
|
||||
bootloader_is_present(void) {
|
||||
#if defined(RAMPZ)
|
||||
return pgm_read_word_far(BOOTLOADER_START_ADDRESS)!=0xFFFF;
|
||||
#else
|
||||
/* Probably can just return false when < 64K flash */
|
||||
// return pgm_read_word_near(BOOTLOADER_START_ADDRESS)!=0xFFFF;
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
Jump_To_Bootloader(void)
|
||||
{
|
||||
|
@ -148,6 +148,102 @@
|
||||
TIMSK0 = _BV (OCIE0A);
|
||||
#endif /* AVR_CONF_USE32KCRYSTAL */
|
||||
|
||||
#elif defined (__AVR_ATmega644__) || defined (__AVR_ATmega328P__)
|
||||
|
||||
#define OCRSetup() \
|
||||
/* Set counter to zero */ \
|
||||
TCNT0 = 0; \
|
||||
\
|
||||
/* \
|
||||
* Set comparison register: \
|
||||
* Crystal freq. is 8000000,\
|
||||
* pre-scale factor is 256, i.e. we have 125 "ticks" / sec: \
|
||||
* 8000000 = 256 * 250 * 125 \
|
||||
*/ \
|
||||
OCR0A = 250; \
|
||||
\
|
||||
/* \
|
||||
* Set timer control register: \
|
||||
* - prescale: 256 (CS02) \
|
||||
* - counter reset via comparison register (WGM01) \
|
||||
*/ \
|
||||
TCCR0A = _BV(WGM01); \
|
||||
TCCR0B = _BV(CS02); \
|
||||
\
|
||||
/* Clear interrupt flag register */ \
|
||||
TIFR0 = 0x00; \
|
||||
\
|
||||
/* \
|
||||
* Raise interrupt when value in OCR0 is reached. Note that the \
|
||||
* counter value in TCNT0 is cleared automatically. \
|
||||
*/ \
|
||||
TIMSK0 = _BV (OCIE0A);
|
||||
|
||||
#define AVR_OUTPUT_COMPARE_INT TIMER0_COMPA_vect
|
||||
|
||||
#elif defined (__AVR_ATmega8515__) || defined (__AVR_ATmega16__) || defined (__AVR_ATmega32__)
|
||||
|
||||
#define AVR_OUTPUT_COMPARE_INT TIMER0_COMP_vect
|
||||
|
||||
#define OCRSetup() \
|
||||
/* Set counter to zero */ \
|
||||
TCNT0 = 0; \
|
||||
\
|
||||
/* \
|
||||
* Set comparison register: \
|
||||
* Crystal freq. is 8000000,\
|
||||
* pre-scale factor is 256, i.e. we have 125 "ticks" / sec: \
|
||||
* 8000000 = 256 * 250 * 125 \
|
||||
*/ \
|
||||
OCR0 = 250; \
|
||||
\
|
||||
/* \
|
||||
* Set timer control register: \
|
||||
* - prescale: 256 (CS02) \
|
||||
* - counter reset via comparison register (WGM01) \
|
||||
*/ \
|
||||
TCCR0 = _BV(CS02) | _BV(WGM01); \
|
||||
\
|
||||
/* Clear interrupt flag register */ \
|
||||
TIFR = 0x00; \
|
||||
\
|
||||
/* \
|
||||
* Raise interrupt when value in OCR0 is reached. Note that the \
|
||||
* counter value in TCNT0 is cleared automatically. \
|
||||
*/ \
|
||||
TIMSK = _BV (OCIE0);
|
||||
|
||||
#elif defined (__AVR_ATmega8__)
|
||||
|
||||
#define AVR_OUTPUT_COMPARE_INT TIMER2_COMP_vect
|
||||
|
||||
#define OCRSetup() \
|
||||
/* Set counter to zero */ \
|
||||
TCNT2 = 0; \
|
||||
\
|
||||
/* \
|
||||
* Set comparison register: \
|
||||
* Crystal freq. is 8000000,\
|
||||
* pre-scale factor is 256, i.e. we have 125 "ticks" / sec: \
|
||||
* 8000000 = 256 * 250 * 125 \
|
||||
*/ \
|
||||
OCR2 = 250; \
|
||||
\
|
||||
/* \
|
||||
* Set timer control register: \
|
||||
* - prescale: 256 (CS21 CS22) \
|
||||
* - counter reset via comparison register (WGM21) \
|
||||
*/ \
|
||||
TCCR2 = _BV(CS22) | _BV(CS21) | _BV(WGM21); \
|
||||
\
|
||||
/* Clear interrupt flag register */ \
|
||||
TIFR = 0x00; \
|
||||
\
|
||||
/* \
|
||||
* Raise interrupt when value in OCR2 is reached. Note that the \
|
||||
* counter value in TCNT2 is cleared automatically. \
|
||||
*/ \
|
||||
TIMSK = _BV (OCIE2);
|
||||
#else
|
||||
#error "Setup CPU in clock-avr.h"
|
||||
#endif
|
||||
|
@ -42,6 +42,14 @@
|
||||
#include "dev/slip.h"
|
||||
#include "dev/rs232.h"
|
||||
|
||||
/*ATmega32 and smaller have UBRRH/UCSRC at the same I/O address.
|
||||
*USART_UCSRC_SEL (bit7) selects writing to UBRHH(0) or UCSRC(1).
|
||||
*It is OR'd in below so if not defined we can just set it to zero.
|
||||
*/
|
||||
#ifndef USART_UCSRC_SEL
|
||||
#define USART_UCSRC_SEL 0x00
|
||||
#endif
|
||||
|
||||
#ifdef RS232_CONF_PRINTF_BUFFER_LENGTH
|
||||
#define RS232_PRINTF_BUFFER_LENGTH RS232_CONF_PRINTF_BUFFER_LENGTH
|
||||
#else
|
||||
@ -52,17 +60,17 @@
|
||||
#define ADD_CARRAGE_RETURNS_TO_SERIAL_OUTPUT 1
|
||||
#endif
|
||||
|
||||
#if defined (__AVR_ATmega128__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega1281__) || defined(__AVR_ATmega128RFA1__)
|
||||
typedef struct {
|
||||
volatile uint8_t * UDR;
|
||||
volatile uint8_t * UBRRH;
|
||||
volatile uint8_t * UBRRL;
|
||||
volatile uint8_t * UCSRB;
|
||||
volatile uint8_t * UCSRC;
|
||||
volatile uint8_t * udr;
|
||||
volatile uint8_t * ubrrh;
|
||||
volatile uint8_t * ubrrl;
|
||||
volatile uint8_t * ucsrb;
|
||||
volatile uint8_t * ucsrc;
|
||||
volatile uint8_t txwait;
|
||||
int (* input_handler)(unsigned char);
|
||||
} rs232_t;
|
||||
|
||||
#if defined (__AVR_ATmega128__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega1281__) || defined(__AVR_ATmega128RFA1__)
|
||||
static rs232_t rs232_ports[2] = {
|
||||
{ // UART0
|
||||
&UDR0,
|
||||
@ -84,6 +92,49 @@ static rs232_t rs232_ports[2] = {
|
||||
NULL
|
||||
}
|
||||
};
|
||||
#elif defined (__AVR_AT90USB1287__)
|
||||
/* Has only UART1, map it to port 0 */
|
||||
static rs232_t rs232_ports[1] = {
|
||||
{ // UART1
|
||||
&UDR1,
|
||||
&UBRR1H,
|
||||
&UBRR1L,
|
||||
&UCSR1B,
|
||||
&UCSR1C,
|
||||
0,
|
||||
NULL
|
||||
}
|
||||
};
|
||||
#elif defined (__AVR_ATmega8__) || defined (__AVR_ATmega8515__) \
|
||||
|| defined (__AVR_ATmega16__) || defined (__AVR_ATmega32__)
|
||||
static rs232_t rs232_ports[1] = {
|
||||
{ // UART0
|
||||
&UDR,
|
||||
&UBRRH,
|
||||
&UBRRL,
|
||||
&UCSRB,
|
||||
&UCSRC,
|
||||
0,
|
||||
NULL
|
||||
}
|
||||
};
|
||||
#elif defined (__AVR_ATmega644__) || defined (__AVR_ATmega328P__)
|
||||
static rs232_t rs232_ports[1] = {
|
||||
{ // UART0
|
||||
&UDR0,
|
||||
&UBRR0H,
|
||||
&UBRR0L,
|
||||
&UCSR0B,
|
||||
&UCSR0C,
|
||||
0,
|
||||
NULL
|
||||
}
|
||||
};
|
||||
#else
|
||||
#error Please define the UART registers for your MCU!
|
||||
#endif
|
||||
|
||||
#if defined (__AVR_ATmega128__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega1281__) || defined(__AVR_ATmega128RFA1__)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
ISR(USART0_TX_vect)
|
||||
{
|
||||
@ -95,7 +146,7 @@ ISR(USART0_RX_vect)
|
||||
{
|
||||
unsigned char c;
|
||||
|
||||
c = *(rs232_ports[RS232_PORT_0].UDR);
|
||||
c = *(rs232_ports[RS232_PORT_0].udr);
|
||||
|
||||
if(rs232_ports[RS232_PORT_0].input_handler != NULL) {
|
||||
rs232_ports[RS232_PORT_0].input_handler(c);
|
||||
@ -112,25 +163,68 @@ ISR(USART1_RX_vect)
|
||||
{
|
||||
unsigned char c;
|
||||
|
||||
c = *(rs232_ports[RS232_PORT_1].UDR);
|
||||
c = *(rs232_ports[RS232_PORT_1].udr);
|
||||
|
||||
if(rs232_ports[RS232_PORT_1].input_handler != NULL) {
|
||||
rs232_ports[RS232_PORT_1].input_handler(c);
|
||||
}
|
||||
}
|
||||
|
||||
#elif defined (__AVR_AT90USB1287__)
|
||||
/* Has only UART1, map it to port 0 */
|
||||
typedef struct {
|
||||
volatile uint8_t * UDR;
|
||||
volatile uint8_t * UBRRH;
|
||||
volatile uint8_t * UBRRL;
|
||||
volatile uint8_t * UCSRB;
|
||||
volatile uint8_t * UCSRC;
|
||||
volatile uint8_t txwait;
|
||||
int (* input_handler)(unsigned char);
|
||||
} rs232_t;
|
||||
#elif defined (__AVR_ATmega644__)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
ISR(USART0_TX_vect)
|
||||
{
|
||||
rs232_ports[RS232_PORT_0].txwait = 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
ISR(USART0_RX_vect)
|
||||
{
|
||||
unsigned char c;
|
||||
|
||||
c = *(rs232_ports[RS232_PORT_0].udr);
|
||||
|
||||
if(rs232_ports[RS232_PORT_0].input_handler != NULL) {
|
||||
rs232_ports[RS232_PORT_0].input_handler(c);
|
||||
}
|
||||
}
|
||||
#elif defined (__AVR_ATmega8__) || defined (__AVR_ATmega16__) || defined (__AVR_ATmega32__)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
ISR(USART_TXC_vect)
|
||||
{
|
||||
rs232_ports[RS232_PORT_0].txwait = 0;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
ISR(USART_RXC_vect)
|
||||
{
|
||||
unsigned char c;
|
||||
|
||||
c = *(rs232_ports[RS232_PORT_0].udr);
|
||||
|
||||
if(rs232_ports[RS232_PORT_0].input_handler != NULL) {
|
||||
rs232_ports[RS232_PORT_0].input_handler(c);
|
||||
}
|
||||
}
|
||||
|
||||
#elif defined (__AVR_ATmega8515__) || defined (__AVR_ATmega328P__)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
ISR(USART_TX_vect)
|
||||
{
|
||||
rs232_ports[RS232_PORT_0].txwait = 0;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
ISR(USART_RX_vect)
|
||||
{
|
||||
unsigned char c;
|
||||
|
||||
c = *(rs232_ports[RS232_PORT_0].udr);
|
||||
|
||||
if(rs232_ports[RS232_PORT_0].input_handler != NULL) {
|
||||
rs232_ports[RS232_PORT_0].input_handler(c);
|
||||
}
|
||||
}
|
||||
#elif defined (__AVR_AT90USB1287__)
|
||||
static rs232_t rs232_ports[1] = {
|
||||
{ // UART1
|
||||
&UDR1,
|
||||
@ -153,7 +247,7 @@ ISR(USART1_RX_vect)
|
||||
{
|
||||
unsigned char c;
|
||||
|
||||
c = *(rs232_ports[RS232_PORT_0].UDR);
|
||||
c = *(rs232_ports[RS232_PORT_0].udr);
|
||||
|
||||
if(rs232_ports[RS232_PORT_0].input_handler != NULL) {
|
||||
rs232_ports[RS232_PORT_0].input_handler(c);
|
||||
@ -167,14 +261,14 @@ ISR(USART1_RX_vect)
|
||||
void
|
||||
rs232_init (uint8_t port, uint8_t bd, uint8_t ffmt)
|
||||
{
|
||||
*(rs232_ports[port].UBRRH) = (uint8_t)(bd>>8);
|
||||
*(rs232_ports[port].UBRRL) = (uint8_t)bd;
|
||||
*(rs232_ports[port].ubrrh) = (uint8_t)(bd>>8);
|
||||
*(rs232_ports[port].ubrrl) = (uint8_t)bd;
|
||||
|
||||
/*
|
||||
* - Enable receiver and transmitter,
|
||||
* - Enable interrupts for receiver and transmitter
|
||||
*/
|
||||
*(rs232_ports[port].UCSRB) = USART_INTERRUPT_RX_COMPLETE | USART_INTERRUPT_TX_COMPLETE | \
|
||||
*(rs232_ports[port].ucsrb) = USART_INTERRUPT_RX_COMPLETE | USART_INTERRUPT_TX_COMPLETE | \
|
||||
USART_RECEIVER_ENABLE | USART_TRANSMITTER_ENABLE;
|
||||
|
||||
/*
|
||||
@ -184,7 +278,7 @@ rs232_init (uint8_t port, uint8_t bd, uint8_t ffmt)
|
||||
* - charater size (9 bits are currently not supported)
|
||||
* - clock polarity
|
||||
*/
|
||||
*(rs232_ports[port].UCSRC) = ffmt;
|
||||
*(rs232_ports[port].ucsrc) = USART_UCSRC_SEL | ffmt;
|
||||
|
||||
rs232_ports[port].txwait = 0;
|
||||
|
||||
@ -230,7 +324,7 @@ void
|
||||
rs232_send(uint8_t port, unsigned char c)
|
||||
{
|
||||
rs232_ports[port].txwait = 1;
|
||||
*(rs232_ports[port].UDR) = c;
|
||||
*(rs232_ports[port].udr) = c;
|
||||
while(rs232_ports[port].txwait);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
@ -50,11 +50,21 @@
|
||||
#include "dev/rs232_at90usb1287.h"
|
||||
#elif defined (__AVR_ATmega128RFA1__)
|
||||
#include "dev/rs232_atmega128rfa1.h"
|
||||
#elif defined (__AVR_ATmega644__) || defined (__AVR_ATmega328P__)
|
||||
#include "dev/rs232_atmega644.h"
|
||||
#elif defined (__AVR_ATmega8__) || defined (__AVR_ATmega8515__) \
|
||||
|| defined (__AVR_ATmega16__) || defined (__AVR_ATmega32__)
|
||||
#include "dev/rs232_atmega32.h"
|
||||
#else
|
||||
#error "Please implement a rs232 header for your MCU (or set the MCU type \
|
||||
in contiki-conf.h)."
|
||||
#endif
|
||||
|
||||
/******************************************************************************/
|
||||
/*** Baud rates */
|
||||
/******************************************************************************/
|
||||
#define BAUD_RATE(x) (F_CPU/16/x-1)
|
||||
|
||||
/**
|
||||
* \brief Initialize the RS232 module
|
||||
*
|
||||
|
147
cpu/avr/dev/rs232_atmega32.h
Normal file
147
cpu/avr/dev/rs232_atmega32.h
Normal file
@ -0,0 +1,147 @@
|
||||
/*
|
||||
* 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
|
||||
* AVR specific definitions for the rs232 port.
|
||||
*
|
||||
* \author
|
||||
* Simon Barner <barner@in.tum.de>
|
||||
* Daniel Willmann <daniel@totalueberwachung.de>
|
||||
*/
|
||||
|
||||
#ifndef __RS232_ATMEGA32__
|
||||
#define __RS232_ATMEGA32__
|
||||
/******************************************************************************/
|
||||
/*** Includes */
|
||||
/******************************************************************************/
|
||||
#include <avr/io.h>
|
||||
|
||||
/******************************************************************************/
|
||||
/*** RS232 ports */
|
||||
/******************************************************************************/
|
||||
#define RS232_PORT_0 0
|
||||
|
||||
/******************************************************************************/
|
||||
/*** Baud rates */
|
||||
/******************************************************************************/
|
||||
#if F_CPU == 16000000
|
||||
/* Single speed operation (U2X = 0)*/
|
||||
#define USART_BAUD_2400 416
|
||||
#define USART_BAUD_4800 207
|
||||
#define USART_BAUD_9600 103
|
||||
#define USART_BAUD_14400 68
|
||||
#define USART_BAUD_19200 51
|
||||
#define USART_BAUD_28800 34
|
||||
#define USART_BAUD_38400 25
|
||||
#define USART_BAUD_57600 16
|
||||
#define USART_BAUD_76800 12
|
||||
#define USART_BAUD_115200 8
|
||||
#define USART_BAUD_230400 3
|
||||
#define USART_BAUD_250000 3
|
||||
#define USART_BAUD_500000 1
|
||||
#define USART_BAUD_1000000 0
|
||||
#elif F_CPU == 8000000
|
||||
/* Single speed operation (U2X = 0)*/
|
||||
#define USART_BAUD_2400 207
|
||||
#define USART_BAUD_4800 103
|
||||
#define USART_BAUD_9600 51
|
||||
#define USART_BAUD_14400 34
|
||||
#define USART_BAUD_19200 25
|
||||
#define USART_BAUD_28800 16
|
||||
#define USART_BAUD_38400 12
|
||||
#define USART_BAUD_57600 8
|
||||
#define USART_BAUD_76800 6
|
||||
#define USART_BAUD_115200 3
|
||||
#define USART_BAUD_230400 1
|
||||
#define USART_BAUD_250000 1
|
||||
#define USART_BAUD_500000 0
|
||||
#else
|
||||
#error "Please define the baud rates for your CPU clock: ATmega32 handbook p. \
|
||||
163-166 or set the rate in contiki-conf.h"
|
||||
#endif
|
||||
|
||||
|
||||
/******************************************************************************/
|
||||
/*** Interrupt settings */
|
||||
/******************************************************************************/
|
||||
#define USART_INTERRUPT_RX_COMPLETE _BV (RXCIE)
|
||||
#define USART_INTERRUPT_TX_COMPLETE _BV (TXCIE)
|
||||
#define USART_INTERRUPT_DATA_REG_EMPTY _BV (UDRIE)
|
||||
|
||||
/******************************************************************************/
|
||||
/*** Receiver / transmitter */
|
||||
/******************************************************************************/
|
||||
#define USART_RECEIVER_ENABLE _BV (RXEN)
|
||||
#define USART_TRANSMITTER_ENABLE _BV (TXEN)
|
||||
|
||||
/******************************************************************************/
|
||||
/*** Register select */
|
||||
/******************************************************************************/
|
||||
#define USART_UCSRC_SEL _BV (URSEL)
|
||||
|
||||
/******************************************************************************/
|
||||
/*** Mode select */
|
||||
/******************************************************************************/
|
||||
#define USART_MODE_ASYNC 0x00
|
||||
#define USART_MODE_SYNC _BV (UMSEL)
|
||||
|
||||
/******************************************************************************/
|
||||
/*** Parity */
|
||||
/******************************************************************************/
|
||||
#define USART_PARITY_NONE 0x00
|
||||
#define USART_PARITY_EVEN _BV (UPM1)
|
||||
#define USART_PARITY_ODD _BV (UPM1) | _BV (UPM0)
|
||||
|
||||
/******************************************************************************/
|
||||
/*** Stop bits */
|
||||
/******************************************************************************/
|
||||
#define USART_STOP_BITS_1 0x00
|
||||
#define USART_STOP_BITS_2 _BV (USBS)
|
||||
|
||||
/******************************************************************************/
|
||||
/*** Character size */
|
||||
/******************************************************************************/
|
||||
#define USART_DATA_BITS_5 0x00
|
||||
#define USART_DATA_BITS_6 _BV (UCSZ0)
|
||||
#define USART_DATA_BITS_7 _BV (UCSZ1)
|
||||
#define USART_DATA_BITS_8 _BV (UCSZ1) | _BV (UCSZ0)
|
||||
// #define USART_DATA_BITS_9 (needs also UCSZ2 bit in UCSRnB)
|
||||
|
||||
/******************************************************************************/
|
||||
/*** Clock polarity */
|
||||
/******************************************************************************/
|
||||
#define USART_RISING_XCKN_EDGE 0x00
|
||||
#define USART_FALLING_XCKN_EDGE _BV (UCPOL)
|
||||
|
||||
#endif /* #ifndef __RS232_ATMEGA32__ */
|
141
cpu/avr/dev/rs232_atmega644.h
Normal file
141
cpu/avr/dev/rs232_atmega644.h
Normal file
@ -0,0 +1,141 @@
|
||||
/*
|
||||
* 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
|
||||
* AVR specific definitions for the rs232 port.
|
||||
*
|
||||
* \author
|
||||
* Simon Barner <barner@in.tum.de
|
||||
*/
|
||||
|
||||
#ifndef __RS232_ATMEGA644__
|
||||
#define __RS232_ATMEGA644__
|
||||
/******************************************************************************/
|
||||
/*** Includes */
|
||||
/******************************************************************************/
|
||||
#include <avr/io.h>
|
||||
|
||||
/******************************************************************************/
|
||||
/*** RS232 ports */
|
||||
/******************************************************************************/
|
||||
#define RS232_PORT_0 0
|
||||
|
||||
/******************************************************************************/
|
||||
/*** Baud rates */
|
||||
/******************************************************************************/
|
||||
#if F_CPU == 16000000
|
||||
/* Single speed operation (U2X = 0)*/
|
||||
#define USART_BAUD_2400 416
|
||||
#define USART_BAUD_4800 207
|
||||
#define USART_BAUD_9600 103
|
||||
#define USART_BAUD_14400 68
|
||||
#define USART_BAUD_19200 51
|
||||
#define USART_BAUD_28800 34
|
||||
#define USART_BAUD_38400 25
|
||||
#define USART_BAUD_57600 16
|
||||
#define USART_BAUD_76800 12
|
||||
#define USART_BAUD_115200 8
|
||||
#define USART_BAUD_230400 3
|
||||
#define USART_BAUD_250000 3
|
||||
#define USART_BAUD_500000 1
|
||||
#define USART_BAUD_1000000 0
|
||||
#elif F_CPU == 8000000
|
||||
/* Single speed operation (U2X = 0)*/
|
||||
#define USART_BAUD_2400 207
|
||||
#define USART_BAUD_4800 103
|
||||
#define USART_BAUD_9600 51
|
||||
#define USART_BAUD_14400 34
|
||||
#define USART_BAUD_19200 25
|
||||
#define USART_BAUD_28800 16
|
||||
#define USART_BAUD_38400 12
|
||||
#define USART_BAUD_57600 8
|
||||
#define USART_BAUD_76800 6
|
||||
#define USART_BAUD_115200 3
|
||||
#define USART_BAUD_230400 1
|
||||
#define USART_BAUD_250000 1
|
||||
#define USART_BAUD_500000 0
|
||||
#else
|
||||
#error "Please define the baud rates for your CPU clock: ATmega644 handbook p. \
|
||||
187-190 or set the rate in contiki-conf.h"
|
||||
#endif
|
||||
|
||||
|
||||
/******************************************************************************/
|
||||
/*** Interrupt settings */
|
||||
/******************************************************************************/
|
||||
#define USART_INTERRUPT_RX_COMPLETE _BV (RXCIE0)
|
||||
#define USART_INTERRUPT_TX_COMPLETE _BV (TXCIE0)
|
||||
#define USART_INTERRUPT_DATA_REG_EMPTY _BV (UDRIE0)
|
||||
|
||||
/******************************************************************************/
|
||||
/*** Receiver / transmitter */
|
||||
/******************************************************************************/
|
||||
#define USART_RECEIVER_ENABLE _BV (RXEN0)
|
||||
#define USART_TRANSMITTER_ENABLE _BV (TXEN0)
|
||||
|
||||
/******************************************************************************/
|
||||
/*** Mode select */
|
||||
/******************************************************************************/
|
||||
#define USART_MODE_ASYNC 0x00
|
||||
#define USART_MODE_SYNC _BV (UMSEL00)
|
||||
|
||||
/******************************************************************************/
|
||||
/*** Parity */
|
||||
/******************************************************************************/
|
||||
#define USART_PARITY_NONE 0x00
|
||||
#define USART_PARITY_EVEN _BV (UPM01)
|
||||
#define USART_PARITY_ODD _BV (UPM01) | _BV (UPM00)
|
||||
|
||||
/******************************************************************************/
|
||||
/*** Stop bits */
|
||||
/******************************************************************************/
|
||||
#define USART_STOP_BITS_1 0x00
|
||||
#define USART_STOP_BITS_2 _BV (USBS)
|
||||
|
||||
/******************************************************************************/
|
||||
/*** Character size */
|
||||
/******************************************************************************/
|
||||
#define USART_DATA_BITS_5 0x00
|
||||
#define USART_DATA_BITS_6 _BV (UCSZ00)
|
||||
#define USART_DATA_BITS_7 _BV (UCSZ01)
|
||||
#define USART_DATA_BITS_8 _BV (UCSZ01) | _BV (UCSZ00)
|
||||
// #define USART_DATA_BITS_9 (needs also UCSZ2 bit in UCSRnB)
|
||||
|
||||
/******************************************************************************/
|
||||
/*** Clock polarity */
|
||||
/******************************************************************************/
|
||||
#define USART_RISING_XCKN_EDGE 0x00
|
||||
#define USART_FALLING_XCKN_EDGE _BV (UCPOL0)
|
||||
|
||||
#endif /* #ifndef __RS232_ATMEGA644__ */
|
@ -70,6 +70,13 @@
|
||||
#define ETIFR TIFR3
|
||||
#define TICIE3 ICIE3
|
||||
#endif
|
||||
|
||||
#if defined(__AVR_ATmega328P__) || defined(__AVR_ATmega644__)
|
||||
#define TIMSK TIMSK1
|
||||
#define TICIE1 ICIE1
|
||||
#define TIFR TIFR1
|
||||
#endif
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifdef TCNT3
|
||||
ISR (TIMER3_COMPA_vect) {
|
||||
@ -84,8 +91,13 @@ ISR (TIMER3_COMPA_vect) {
|
||||
ENERGEST_OFF(ENERGEST_TYPE_IRQ);
|
||||
}
|
||||
|
||||
#else
|
||||
#error "No Timer3 in rtimer-arch.c"
|
||||
#elif RTIMER_ARCH_PRESCALER
|
||||
#warning "No Timer3 in rtimer-arch.c - using Timer1 instead"
|
||||
ISR (TIMER1_COMPA_vect) {
|
||||
TIMSK &= ~((1<<TICIE1)|(1<<OCIE1A)|(1<<OCIE1B)|(1<<TOIE1));
|
||||
|
||||
rtimer_run_next();
|
||||
}
|
||||
|
||||
#endif
|
||||
/*---------------------------------------------------------------------------*/
|
||||
@ -113,14 +125,40 @@ rtimer_arch_init(void)
|
||||
/* Reset counter */
|
||||
TCNT3 = 0;
|
||||
|
||||
/* Start clock, maximum prescaler */
|
||||
/* Start clock, maximum prescaler (1024)*/
|
||||
TCCR3B |= 5;
|
||||
|
||||
#else
|
||||
#error "No Timer3 in rtimer-arch.c"
|
||||
#elif RTIMER_ARCH_PRESCALER
|
||||
/* Leave timer1 alone if PRESCALER set to zero */
|
||||
/* Obviously you can not then use rtimers */
|
||||
|
||||
TIMSK &= ~((1<<TICIE1)|(1<<OCIE1A)|(1<<OCIE1B)|(1<<TOIE1));
|
||||
TIFR |= (1 << ICF1) | (1 << OCF1A) | (1 << OCF1B) | (1 << TOV1);
|
||||
|
||||
/* Default timer behaviour */
|
||||
TCCR1A = 0;
|
||||
TCCR1B = 0;
|
||||
|
||||
/* Reset counter */
|
||||
TCNT1 = 0;
|
||||
|
||||
/* Start clock */
|
||||
#if RTIMER_ARCH_PRESCALER==1024
|
||||
TCCR1B |= 5;
|
||||
#elif RTIMER_ARCH_PRESCALER==256
|
||||
TCCR1B |= 4;
|
||||
#elif RTIMER_ARCH_PRESCALER==64
|
||||
TCCR1B |= 3;
|
||||
#elif RTIMER_ARCH_PRESCALER==8
|
||||
TCCR1B |= 2;
|
||||
#elif RTIMER_ARCH_PRESCALER==1
|
||||
TCCR1B |= 1;
|
||||
#else
|
||||
#error PRESCALER factor not supported.
|
||||
#endif
|
||||
|
||||
#endif /* TCNT3 */
|
||||
|
||||
/* Restore interrupt state */
|
||||
SREG = sreg;
|
||||
}
|
||||
@ -142,8 +180,11 @@ rtimer_arch_schedule(rtimer_clock_t t)
|
||||
/* Enable interrupt on OCR3A match */
|
||||
ETIMSK |= (1 << OCIE3A);
|
||||
|
||||
#else
|
||||
#error "No Timer3 in rtimer-arch.c"
|
||||
#elif RTIMER_ARCH_PRESCALER
|
||||
/* Set compare register */
|
||||
OCR1A = t;
|
||||
TIFR |= (1 << ICF1) | (1 << OCF1A) | (1 << OCF1B) | (1 << TOV1);
|
||||
TIMSK |= (1 << OCIE1A);
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -36,15 +36,21 @@
|
||||
|
||||
#include <avr/interrupt.h>
|
||||
|
||||
/* Will affect radio on/off timing for cx-mac */
|
||||
#define RTIMER_ARCH_SECOND (8192)
|
||||
/* Nominal ARCH_SECOND is F_CPU/prescaler, e.g. 8000000/1024 = 7812 */
|
||||
#ifndef RTIMER_ARCH_PRESCALER
|
||||
#define RTIMER_ARCH_PRESCALER 1024UL
|
||||
#endif
|
||||
#define RTIMER_ARCH_SECOND (F_CPU/RTIMER_ARCH_PRESCALER)
|
||||
|
||||
/* Use TCNT1 if TCNT3 not available.
|
||||
* Setting RTIMER_ARCH_PRESCALER to 0 will leave timer1 alone.
|
||||
* Obviously this will disable rtimers.
|
||||
*/
|
||||
|
||||
|
||||
/* Handle that not all AVRs have TCNT3 - this should be configuratble
|
||||
in contiki-conf later! */
|
||||
#ifdef TCNT3
|
||||
#define rtimer_arch_now() (TCNT3)
|
||||
#elif RTIMER_ARCH_PRESCALER
|
||||
#define rtimer_arch_now() (TCNT1)
|
||||
#else
|
||||
#define rtimer_arch_now() (0)
|
||||
#endif
|
||||
|
@ -64,6 +64,13 @@
|
||||
#include <avr/wdt.h>
|
||||
#include <avr/interrupt.h>
|
||||
|
||||
//Not all AVR toolchains alias MCUSR to the older MSUSCR name
|
||||
//#if defined (__AVR_ATmega8__) || defined (__AVR_ATmega8515__) || defined (__AVR_ATmega16__)
|
||||
#if !defined (MCUSR) && defined (MCUCSR)
|
||||
#warning *** MCUSR not defined, using MCUCSR instead ***
|
||||
#define MCUSR MCUCSR
|
||||
#endif
|
||||
|
||||
#if WATCHDOG_CONF_BALANCE && WATCHDOG_CONF_TIMEOUT >= 0
|
||||
static int stopped = 0;
|
||||
#endif
|
||||
@ -129,4 +136,4 @@ watchdog_reboot(void)
|
||||
ISR(WDT_vect)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
7
platform/stk500/Makefile
Normal file
7
platform/stk500/Makefile
Normal file
@ -0,0 +1,7 @@
|
||||
all: contiki-stk500-main.out
|
||||
upload: contiki-stk500-main.u
|
||||
|
||||
CONTIKI=../..
|
||||
TARGET=stk500
|
||||
|
||||
include $(CONTIKI)/Makefile.include
|
19
platform/stk500/Makefile.stk500
Normal file
19
platform/stk500/Makefile.stk500
Normal file
@ -0,0 +1,19 @@
|
||||
CONTIKI_TARGET_DIRS = . dev apps loader
|
||||
CONTIKI_TARGET_MAIN = contiki-stk500-main.o
|
||||
|
||||
CONTIKI_SOURCEFILES += rs232.c contiki-stk500-main.c
|
||||
|
||||
CONTIKI_NO_NET=1
|
||||
CONTIKIAVR=$(CONTIKI)/cpu/avr
|
||||
CONTIKIBOARD=.
|
||||
|
||||
//MCU=atmega8
|
||||
MCU=atmega8515
|
||||
//MCU=atmega644
|
||||
//MCU=atmega328p
|
||||
//MCU=atmega16
|
||||
//MCU=atmega32
|
||||
|
||||
CONTIKI_PLAT_DEFS = -DF_CPU=8000000UL -DAUTO_CRC_PADDING=2
|
||||
|
||||
include $(CONTIKIAVR)/Makefile.avr
|
75
platform/stk500/contiki-conf.h
Normal file
75
platform/stk500/contiki-conf.h
Normal file
@ -0,0 +1,75 @@
|
||||
#ifndef __CONTIKI_CONF_H__
|
||||
#define __CONTIKI_CONF_H__
|
||||
|
||||
#include<stdint.h>
|
||||
|
||||
#define CCIF
|
||||
#define CLIF
|
||||
|
||||
typedef unsigned short clock_time_t;
|
||||
#define CLOCK_CONF_SECOND 125
|
||||
/* Maximum tick interval is 0xffff/125 = 524 seconds */
|
||||
#define RIME_CONF_BROADCAST_ANNOUNCEMENT_MAX_TIME CLOCK_CONF_SECOND * 524UL /* Default uses 600UL */
|
||||
#define COLLECT_CONF_BROADCAST_ANNOUNCEMENT_MAX_TIME CLOCK_CONF_SECOND * 524UL /* Default uses 600UL */
|
||||
|
||||
|
||||
#define SLIP_PORT 0
|
||||
|
||||
#if UIP_CONF_IPV6
|
||||
#define RIMEADDR_CONF_SIZE 8
|
||||
#define UIP_CONF_ICMP6 1
|
||||
#define UIP_CONF_UDP 1
|
||||
#define UIP_CONF_TCP 1
|
||||
#define UIP_CONF_IPV6_RPL 0
|
||||
|
||||
/* See uip-ds6.h */
|
||||
#define UIP_CONF_DS6_NBR_NBU 20
|
||||
#define UIP_CONF_DS6_DEFRT_NBU 2
|
||||
#define UIP_CONF_DS6_PREFIX_NBU 3
|
||||
#define UIP_CONF_DS6_ROUTE_NBU 20
|
||||
#define UIP_CONF_DS6_ADDR_NBU 3
|
||||
#define UIP_CONF_DS6_MADDR_NBU 0
|
||||
#define UIP_CONF_DS6_AADDR_NBU 0
|
||||
|
||||
#define NETSTACK_CONF_NETWORK sicslowpan_driver
|
||||
#define NETSTACK_CONF_MAC nullmac_driver
|
||||
#define SICSLOWPAN_CONF_COMPRESSION SICSLOWPAN_COMPRESSION_HC06
|
||||
#define NETSTACK_CONF_RDC sicslowmac_driver
|
||||
#define NETSTACK_CONF_FRAMER framer_802154
|
||||
#define NETSTACK_CONF_RADIO rf230_driver
|
||||
#define CHANNEL_802_15_4 26
|
||||
/* AUTOACK receive mode gives better rssi measurements, even if ACK is never requested */
|
||||
#define RF230_CONF_AUTOACK 1
|
||||
/* Request 802.15.4 ACK on all packets sent (else autoretry). This is primarily for testing. */
|
||||
#define SICSLOWPAN_CONF_ACK_ALL 0
|
||||
/* Number of auto retry attempts 0-15 (0 implies don't use extended TX_ARET_ON mode with CCA) */
|
||||
#define RF230_CONF_AUTORETRIES 2
|
||||
#define SICSLOWPAN_CONF_FRAG 1
|
||||
/* Most browsers reissue GETs after 3 seconds which stops fragment reassembly so a longer MAXAGE does no good */
|
||||
#define SICSLOWPAN_CONF_MAXAGE 3
|
||||
/* How long to wait before terminating an idle TCP connection. Smaller to allow faster sleep. Default is 120 seconds */
|
||||
#define UIP_CONF_WAIT_TIMEOUT 5
|
||||
|
||||
#else
|
||||
/* ip4 should build but is largely untested */
|
||||
#define RIMEADDR_CONF_SIZE 2
|
||||
#define NETSTACK_CONF_NETWORK rime_driver
|
||||
#endif /* UIP_CONF_IPV6 */
|
||||
|
||||
void clock_delay(unsigned int us2);
|
||||
|
||||
void clock_wait(int ms10);
|
||||
|
||||
void clock_set_seconds(unsigned long s);
|
||||
unsigned long clock_seconds(void);
|
||||
|
||||
typedef unsigned short uip_stats_t;
|
||||
|
||||
typedef uint8_t u8_t;
|
||||
typedef int8_t s8_t;
|
||||
typedef uint16_t u16_t;
|
||||
typedef int16_t s16_t;
|
||||
typedef uint32_t u32_t;
|
||||
typedef int32_t s32_t;
|
||||
|
||||
#endif /* __CONTIKI_CONF_H__ */
|
237
platform/stk500/contiki-stk500-main.c
Normal file
237
platform/stk500/contiki-stk500-main.c
Normal file
@ -0,0 +1,237 @@
|
||||
|
||||
/* Copyright (c) 2008, Daniel Willmann <daniel@totalueberwachung.de>
|
||||
* 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. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 OS
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
#include "contiki.h"
|
||||
#include "dev/rs232.h"
|
||||
|
||||
#include <avr/io.h>
|
||||
#include <stdio.h>
|
||||
#include <dev/watchdog.h>
|
||||
#include <avr/pgmspace.h>
|
||||
|
||||
#define PRINTA(FORMAT,args...) printf_P(PSTR(FORMAT),##args)
|
||||
#define DEBUG 0
|
||||
#if DEBUG
|
||||
#define PRINTD PRINTA
|
||||
#else
|
||||
#define PRINTD(...)
|
||||
#endif
|
||||
|
||||
/* Test rtimers, also stack monitor and time stamps */
|
||||
#define TESTRTIMER 1
|
||||
#if TESTRTIMER
|
||||
#define STAMPS 30
|
||||
#define STACKMONITOR 128
|
||||
|
||||
uint8_t rtimerflag=1;
|
||||
uint16_t rtime;
|
||||
struct rtimer rt;
|
||||
void rtimercycle(void) {rtimerflag=1;}
|
||||
#endif /* TESTRTIMER */
|
||||
|
||||
#if defined (__AVR_ATmega8__)
|
||||
FUSES =
|
||||
{
|
||||
.low = 0xe0,
|
||||
.high = 0xd9,
|
||||
};
|
||||
#elif defined (__AVR_ATmega16__)
|
||||
FUSES =
|
||||
{
|
||||
.low = 0xe0,
|
||||
.high = 0x99,
|
||||
};
|
||||
#elif defined (__AVR_ATmega644__)
|
||||
FUSES =
|
||||
{
|
||||
.low = 0xe0,
|
||||
.high = 0x99,
|
||||
.extended = 0xff,
|
||||
};
|
||||
|
||||
//MCU=atmega8515
|
||||
//MCU=atmega328p
|
||||
//MCU=atmega32
|
||||
#endif
|
||||
|
||||
|
||||
PROCESS(led_process, "LED process");
|
||||
PROCESS_THREAD(led_process, ev, data)
|
||||
{
|
||||
static struct etimer etimer;
|
||||
|
||||
PROCESS_BEGIN();
|
||||
while (1) {
|
||||
PRINTD("LED1\r\n");
|
||||
PORTB |= (1<<PB1);
|
||||
PORTD |= (1<<PD3);
|
||||
etimer_set(&etimer, CLOCK_SECOND*0.5);
|
||||
PROCESS_WAIT_UNTIL(etimer_expired(&etimer));
|
||||
PORTB &= ~(1<<PB1);
|
||||
PORTD &= ~(1<<PD3);
|
||||
etimer_set(&etimer, CLOCK_SECOND*0.5);
|
||||
PROCESS_WAIT_UNTIL(etimer_expired(&etimer));
|
||||
}
|
||||
|
||||
PROCESS_END();
|
||||
}
|
||||
|
||||
PROCESS(led2_process, "LED process");
|
||||
PROCESS_THREAD(led2_process, ev, data)
|
||||
{
|
||||
static struct etimer etimer;
|
||||
|
||||
PROCESS_BEGIN();
|
||||
while (1) {
|
||||
PRINTD("LED2\r\n");
|
||||
PORTB |= (1<<PB0);
|
||||
PORTD |= (1<<PD2);
|
||||
etimer_set(&etimer, CLOCK_SECOND*0.3);
|
||||
PROCESS_WAIT_UNTIL(etimer_expired(&etimer));
|
||||
PORTB &= ~(1<<PB0);
|
||||
PORTD &= ~(1<<PD2);
|
||||
etimer_set(&etimer, CLOCK_SECOND*0.3);
|
||||
PROCESS_WAIT_UNTIL(etimer_expired(&etimer));
|
||||
}
|
||||
|
||||
PROCESS_END();
|
||||
}
|
||||
|
||||
void led_init()
|
||||
{
|
||||
DDRB |= (1<<PB1)|(1<<PB0);
|
||||
PORTB &= ~((1<<PB1)|(1<<PB0));
|
||||
DDRD |= (1<<PD2)|(1<<PD3);
|
||||
PORTD &= ~((1<<PD2)|(1<<PD3));
|
||||
}
|
||||
|
||||
/* These can also be explicitly started below */
|
||||
PROCINIT(&etimer_process, &led_process, &led2_process);
|
||||
|
||||
void
|
||||
initialize(void)
|
||||
{
|
||||
watchdog_init();
|
||||
watchdog_start();
|
||||
|
||||
#if STACKMONITOR
|
||||
/* Simple stack pointer highwater monitor. Checks for magic numbers in the main
|
||||
* loop. In conjuction with TESTRTIMER, never-used stack will be printed
|
||||
* every STACKMONITOR seconds.
|
||||
*/
|
||||
{
|
||||
extern uint16_t __bss_end;
|
||||
uint16_t p=(uint16_t)&__bss_end;
|
||||
do {
|
||||
*(uint16_t *)p = 0x4242;
|
||||
p+=4;
|
||||
} while (p<SP-4); //don't overwrite our own stack
|
||||
}
|
||||
#endif
|
||||
|
||||
/* rtimers needed for radio cycling */
|
||||
rtimer_init();
|
||||
|
||||
rs232_init(RS232_PORT_0, BAUD_RATE(38400), USART_DATA_BITS_8 | USART_PARITY_NONE | USART_STOP_BITS_1);
|
||||
rs232_redirect_stdout(RS232_PORT_0);
|
||||
|
||||
clock_init();
|
||||
sei();
|
||||
|
||||
/* Initialize drivers and event kernel */
|
||||
process_init();
|
||||
|
||||
led_init();
|
||||
|
||||
#if 0
|
||||
procinit_init();
|
||||
#else
|
||||
process_start(&etimer_process, NULL);
|
||||
process_start(&led_process, NULL);
|
||||
process_start(&led2_process, NULL);
|
||||
#endif
|
||||
|
||||
PRINTA(CONTIKI_VERSION_STRING " started\r\n");
|
||||
|
||||
/* Comment this out if autostart_processes not defined at link */
|
||||
/* Note AUTOSTART_PROCESSES(...) is only effective in the .co module */
|
||||
autostart_start(autostart_processes);
|
||||
|
||||
}
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
initialize();
|
||||
|
||||
while(1) {
|
||||
process_run();
|
||||
|
||||
#if TESTRTIMER
|
||||
/* Timeout can be increased up to 8 seconds maximum.
|
||||
* A one second cycle is convenient for triggering the various debug printouts.
|
||||
* The triggers are staggered to avoid printing everything at once.
|
||||
*/
|
||||
if (rtimerflag) {
|
||||
rtimer_set(&rt, RTIMER_NOW()+ RTIMER_ARCH_SECOND*1UL, 1,(void *) rtimercycle, NULL);
|
||||
rtimerflag=0;
|
||||
|
||||
#if STAMPS
|
||||
if ((rtime%STAMPS)==0) {
|
||||
PRINTA("%us ",rtime);
|
||||
}
|
||||
#endif
|
||||
rtime+=1;
|
||||
|
||||
#if STACKMONITOR
|
||||
if ((rtime%STACKMONITOR)==3) {
|
||||
extern uint16_t __bss_end;
|
||||
uint16_t p=(uint16_t)&__bss_end;
|
||||
do {
|
||||
if (*(uint16_t *)p != 0x4242) {
|
||||
PRINTA("Never-used stack > %d bytes\n",p-(uint16_t)&__bss_end);
|
||||
break;
|
||||
}
|
||||
p+=4;
|
||||
} while (p<RAMEND-4);
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
#endif /* TESTRTIMER */
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user