From d4b3436d21f618dd7ae331c32d4db4ee679bdc0c Mon Sep 17 00:00:00 2001 From: barner Date: Fri, 22 Dec 2006 17:19:22 +0000 Subject: [PATCH] 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 loadable_prg.ko - Watch the module print "Tick, Tack, Tick, ..." on the second serial port. --- platform/stk501/Makefile | 10 ++ platform/stk501/Makefile.stk501 | 26 +++ platform/stk501/contiki-conf.h | 89 ++++++++++ .../contiki-stk501-default-init-lowlevel.c | 48 ++++++ .../stk501/contiki-stk501-default-init-net.c | 54 +++++++ platform/stk501/contiki-stk501-main.c | 152 ++++++++++++++++++ platform/stk501/contiki-stk501.h | 58 +++++++ platform/stk501/loadable_prg.c | 67 ++++++++ 8 files changed, 504 insertions(+) create mode 100644 platform/stk501/Makefile create mode 100644 platform/stk501/Makefile.stk501 create mode 100644 platform/stk501/contiki-conf.h create mode 100644 platform/stk501/contiki-stk501-default-init-lowlevel.c create mode 100644 platform/stk501/contiki-stk501-default-init-net.c create mode 100644 platform/stk501/contiki-stk501-main.c create mode 100644 platform/stk501/contiki-stk501.h create mode 100644 platform/stk501/loadable_prg.c diff --git a/platform/stk501/Makefile b/platform/stk501/Makefile new file mode 100644 index 000000000..121ae9876 --- /dev/null +++ b/platform/stk501/Makefile @@ -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 diff --git a/platform/stk501/Makefile.stk501 b/platform/stk501/Makefile.stk501 new file mode 100644 index 000000000..8dd9e98ca --- /dev/null +++ b/platform/stk501/Makefile.stk501 @@ -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 diff --git a/platform/stk501/contiki-conf.h b/platform/stk501/contiki-conf.h new file mode 100644 index 000000000..9ee8f1e4b --- /dev/null +++ b/platform/stk501/contiki-conf.h @@ -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 + * + * @(#)$$ + */ +#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); +} diff --git a/platform/stk501/contiki-stk501-default-init-net.c b/platform/stk501/contiki-stk501-default-init-net.c new file mode 100644 index 000000000..bcc7b1336 --- /dev/null +++ b/platform/stk501/contiki-stk501-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-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); +} diff --git a/platform/stk501/contiki-stk501-main.c b/platform/stk501/contiki-stk501-main.c new file mode 100644 index 000000000..1fcc1522e --- /dev/null +++ b/platform/stk501/contiki-stk501-main.c @@ -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 +#include + +#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; +} diff --git a/platform/stk501/contiki-stk501.h b/platform/stk501/contiki-stk501.h new file mode 100644 index 000000000..651aa9415 --- /dev/null +++ b/platform/stk501/contiki-stk501.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(); +} + +const struct process *autostart_processes[] = {&test_process1};