Add new plattform definition for the STK 501 board featuring an

Atmel ATmega128.

Very brief instructions:

- Configure your programmer etc. in Makefile.stk501
- Use 'make upload' to flash your STK501.
- Setup a SLIP connection to your board (on the first serial port)
  and make sure you can ping it.
- Use 'make loadable_prg.ko' to build a demo module.
- gcc -ocodeprop ../../tools/codeprop.c
- ./codeprop <IP of STK> loadable_prg.ko
- Watch the module print "Tick, Tack, Tick, ..." on the second
  serial port.
This commit is contained in:
barner 2006-12-22 17:19:22 +00:00
parent 94eecb64f1
commit d4b3436d21
8 changed files with 504 additions and 0 deletions

10
platform/stk501/Makefile Normal file
View file

@ -0,0 +1,10 @@
# $$
all: contiki-stk501-main.out loadable_prg.ko
upload: contiki-stk501-main.eep contiki-stk501-main.u
CONTIKI=../..
TARGET=stk501
APPS=codeprop
include $(CONTIKI)/Makefile.include

View file

@ -0,0 +1,26 @@
CONTIKI_TARGET_DIRS = . dev apps net loader
CONTIKI_CORE=contiki-stk501-main
CONTIKI_TARGET_MAIN = ${CONTIKI_CORE}.o
CONTIKI_TARGET_SOURCEFILES += rs232.c slip.c cfs-eeprom.c eeprom.c random.c \
mmem.c contiki-stk501-default-init-lowlevel.c \
contiki-stk501-default-init-net.c
CONTIKIAVR=$(CONTIKI)/cpu/avr
CONTIKIBOARD=.
MCU=atmega128
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:00A0000010EB
# Additional avrdude options
# Verify off
AVRDUDE_OPTIONS=-V
include $(CONTIKIAVR)/Makefile.avr

View file

@ -0,0 +1,89 @@
/*
* 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 <barner@in.tum.de
*/
#ifndef __CONTIKI_CONF_H__
#define __CONTIKI_CONF_H__
/*
* MCU and clock rate
*/
#define MCU_MHZ 16
#define PLATFORM PLATFORM_AVR
/* Cock 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 UIP_CONF_PINGADDRCONF 0
#define UIP_CONF_MAX_CONNECTIONS 4
#define UIP_CONF_MAX_LISTENPORTS 4
#define UIP_CONF_BUFFER_SIZE 100
#define UIP_CONF_TCP_SPLIT 1
#define UIP_CONF_FWCACHE_SIZE 2
#define UIP_CONF_BROADCAST 1
#define UIP_UDP 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__ */

View file

@ -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 <barner@in.tum.de>
*
* @(#)$$
*/
#include "contiki-stk501.h"
void
init_lowlevel(void)
{
/* Configure default slip port with 115200 baud */
rs232_init(RS232_PORT_0, USART_BAUD_115200, USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8);
/* Second rs232 port for debugging */
rs232_init(RS232_PORT_1, USART_BAUD_9600, USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8);
/* Redirect stdout to second port */
rs232_redirect_stdout (RS232_PORT_1);
}

View file

@ -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 <barner@in.tum.de>
*
* @(#)$$
*/
#include "contiki-stk501.h"
static struct uip_fw_netif slipif =
{UIP_FW_NETIF(10,100,0,0, 255,255,0,0, slip_send)};
void
init_net(void)
{
uip_ipaddr_t hostaddr;
rs232_set_input (SLIP_PORT, slip_input_byte);
process_start(&slip_process, NULL);
uip_ipaddr(&hostaddr, 10, 100, 0, 2);
uip_sethostaddr(&hostaddr);
uip_fw_register(&slipif);
// uip_fw_default(&slipif);
}

View file

@ -0,0 +1,152 @@
/*
* 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 <barner@in.tum.de
*/
#include <avr/pgmspace.h>
#include <stdio.h>
#include "contiki-stk501.h"
#include "cfs/cfs-eeprom.h"
#include "lib/mmem.h"
#include "loader/symbols-def.h"
#include "loader/symtab.h"
#include "codeprop.h"
#include "sys/mt.h"
/* Uncomment to enable demonstration of multi-threading libary */
/* #define MT_DEMO */
PROCINIT(&etimer_process, &tcpip_process, &uip_fw_process, &cfs_eeprom_process);
#ifdef MT_DEMO
static struct mt_thread threads[3];
static
void thread_handler1 (void* data) {
while (1) {
rs232_print_p (RS232_PORT_1, PSTR ("Thread 1. Data: ") );
rs232_printf (RS232_PORT_1, "0x%x, %d\n", data, *(uint8_t*)data );
mt_yield ();
}
}
static
void thread_handler2 (void* data) {
while (1) {
rs232_print_p (RS232_PORT_1, PSTR ("Thread 2. Data: "));
rs232_printf (RS232_PORT_1, "0x%x, %d\n", data, *(uint8_t*)data );
mt_yield ();
}
}
#endif
PROCESS(contiki_stk501_main_init_process, "Contiki STK501 init process");
PROCESS_THREAD(contiki_stk501_main_init_process, ev, data)
{
PROCESS_BEGIN();
/* Network support (uIP) */
init_net();
/* Initalize heap allocator */
mmem_init ();
/* Code propagator */
process_start(&codeprop_process, NULL);
/* Multi-threading support */
#ifdef MT_DEMO
mt_init ();
#endif
PROCESS_END();
}
#ifdef MT_DEMO
static uint8_t d1=1, d2=2, d3=3;
#endif
int
main(void)
{
/*
* GCC depends on register r1 set to 0.
*/
asm volatile ("clr r1");
/* Initialize hardware */
init_lowlevel();
/* Clock */
clock_init();
/* Process subsystem */
process_init();
/* Register initial processes */
procinit_init();
/* Perform rest of initializations */
process_start(&contiki_stk501_main_init_process, NULL);
rs232_print_p (RS232_PORT_1, PSTR ("Initialized.\n"));
#ifdef MT_DEMO
mt_start (&threads[0], thread_handler1, &d1);
mt_start (&threads[1], thread_handler2, &d2);
mt_start (&threads[2], thread_handler2, &d3);
uint8_t i;
#endif
/* Main scheduler loop */
while(1) {
process_run();
#ifdef MT_DEMO
for (i=0; i<3; ++i) {
mt_exec (&threads[i]);
}
#endif
}
return 0;
}

View file

@ -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 <barner@in.tum.de
*/
#ifndef __CONTIKI_STK501_H__
#define __CONTIKI_STK501_H__
#include "contiki.h"
#include "contiki-net.h"
#include "contiki-lib.h"
#include "dev/rs232.h"
#include "dev/serial.h"
#include "dev/slip.h"
void init_lowlevel(void);
void init_net(void);
#endif /* #ifndef __CONTIKI_STK501_H__ */

View file

@ -0,0 +1,67 @@
/*
* 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 loadable module
*
* \author
* Simon Barner <barner@in.tum.de>
*/
#include <stdio.h>
#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();
}
const struct process *autostart_processes[] = {&test_process1};