From 1145fa9ba9a71c424b41e30b39f6d24a6fd27d1b Mon Sep 17 00:00:00 2001 From: maralvira Date: Wed, 9 Jun 2010 14:43:22 +0000 Subject: [PATCH] initial mc1322x commit based on commit aac3a355451d899f02737f2907af8c874ee4feba of git://git.devl.org/git/malvira/contiki-mc1322x.git --- cpu/mc1322x/COPYING | 35 ++++ cpu/mc1322x/CREDITS | 9 + cpu/mc1322x/Makefile.mc1322x | 115 ++++++++++++ cpu/mc1322x/README.subtree | 39 ++++ cpu/mc1322x/TODO | 12 ++ cpu/mc1322x/clock.c | 128 +++++++++++++ cpu/mc1322x/contiki-crm.c | 121 +++++++++++++ cpu/mc1322x/contiki-maca.c | 277 +++++++++++++++++++++++++++++ cpu/mc1322x/contiki-maca.h | 43 +++++ cpu/mc1322x/contiki-mc1322x-conf.h | 61 +++++++ cpu/mc1322x/contiki-misc.c | 42 +++++ cpu/mc1322x/contiki-uart.c | 43 +++++ cpu/mc1322x/contiki-uart.h | 41 +++++ cpu/mc1322x/dbg-io.c | 61 +++++++ cpu/mc1322x/debug-uart.c | 12 ++ cpu/mc1322x/debug-uart.h | 27 +++ cpu/mc1322x/leds-arch.c | 80 +++++++++ cpu/mc1322x/mc1322x.lds | 261 +++++++++++++++++++++++++++ cpu/mc1322x/mtarch.h | 64 +++++++ cpu/mc1322x/rtimer-arch.c | 90 ++++++++++ cpu/mc1322x/rtimer-arch.h | 61 +++++++ cpu/mc1322x/slip-uart1.c | 97 ++++++++++ cpu/mc1322x/watchdog.c | 63 +++++++ 23 files changed, 1782 insertions(+) create mode 100644 cpu/mc1322x/COPYING create mode 100644 cpu/mc1322x/CREDITS create mode 100644 cpu/mc1322x/Makefile.mc1322x create mode 100644 cpu/mc1322x/README.subtree create mode 100644 cpu/mc1322x/TODO create mode 100644 cpu/mc1322x/clock.c create mode 100644 cpu/mc1322x/contiki-crm.c create mode 100644 cpu/mc1322x/contiki-maca.c create mode 100644 cpu/mc1322x/contiki-maca.h create mode 100644 cpu/mc1322x/contiki-mc1322x-conf.h create mode 100644 cpu/mc1322x/contiki-misc.c create mode 100644 cpu/mc1322x/contiki-uart.c create mode 100644 cpu/mc1322x/contiki-uart.h create mode 100644 cpu/mc1322x/dbg-io.c create mode 100644 cpu/mc1322x/debug-uart.c create mode 100644 cpu/mc1322x/debug-uart.h create mode 100644 cpu/mc1322x/leds-arch.c create mode 100644 cpu/mc1322x/mc1322x.lds create mode 100644 cpu/mc1322x/mtarch.h create mode 100644 cpu/mc1322x/rtimer-arch.c create mode 100644 cpu/mc1322x/rtimer-arch.h create mode 100644 cpu/mc1322x/slip-uart1.c create mode 100644 cpu/mc1322x/watchdog.c diff --git a/cpu/mc1322x/COPYING b/cpu/mc1322x/COPYING new file mode 100644 index 000000000..84939c28e --- /dev/null +++ b/cpu/mc1322x/COPYING @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010, Mariano Alvira and other contributors + * to the MC1322x project (http://mc1322x.devl.org) and Contiki. + * + * 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 OS. + * + * $Id: COPYING,v 1.1 2010/06/09 14:43:22 maralvira Exp $ + */ + diff --git a/cpu/mc1322x/CREDITS b/cpu/mc1322x/CREDITS new file mode 100644 index 000000000..24ededbbd --- /dev/null +++ b/cpu/mc1322x/CREDITS @@ -0,0 +1,9 @@ +MC13224v library code, test routines, and handy tools + +http://mc1322x.devl.org +Mariano Alvira mar@devl.org + +Parts of the build system came from U-boot and Darrel Harmon's +"darrell's loader" for the AT91RM9200. Other parts from the Contiki +OS. + diff --git a/cpu/mc1322x/Makefile.mc1322x b/cpu/mc1322x/Makefile.mc1322x new file mode 100644 index 000000000..67336ea53 --- /dev/null +++ b/cpu/mc1322x/Makefile.mc1322x @@ -0,0 +1,115 @@ +# -*- makefile -*- + +# Adapted from Makefile.msp430 +# Adapted from Makefile.at91sam7 + +### Define the CPU directory +CONTIKI_CPU=$(CONTIKI)/cpu/mc1322x + +### Define the source files we have in the AT91SAM7S port + +CONTIKI_CPU_DIRS = . lib src board dev ../arm/common/dbg-io + +MC1322X = debug-uart.c rtimer-arch.c watchdog.c contiki-crm.c contiki-maca.c contiki-misc.c leds-arch.c leds.c contiki-uart.c slip-uart1.c + +DBG_IO = dbg-printf.c dbg-snprintf.c dbg-sprintf.c strformat.c + +CPU_LIBS = $(notdir $(wildcard $(CONTIKI_CPU)/lib/*.c)) +CPU_SRCS = $(notdir $(wildcard $(CONTIKI_CPU)/src/*.c)) $(notdir $(wildcard $(CONTIKI_CPU)/src/*.S)) + +CONTIKI_TARGET_SOURCEFILES += $(MC1322X) $(DBG_IO) $(CPU_LIBS) $(CPU_SRCS) $(SYSAPPS) $(ELFLOADER) \ + $(TARGETLIBS) $(UIPDRIVERS) $(USB) + +CONTIKI_SOURCEFILES += $(CONTIKI_TARGET_SOURCEFILES) + +THREADS = + +CROSS=arm-linux- + +### Compiler definitions +CC = $(CROSS)gcc +LD = $(CROSS)gcc +AS = $(CROSS)as +AR = $(CROSS)ar +NM = $(CROSS)nm +OBJCOPY = $(CROSS)objcopy +STRIP = $(CROSS)strip + +PROJECT_OBJECTFILES += ${addprefix $(OBJECTDIR)/,$(CONTIKI_TARGET_MAIN:.c=.o)} + +TEXT_BASE = 0x00400000 +export TEXT_BASE +LINKERSCRIPT = $(CONTIKI_CPU)/mc1322x.lds + +STARTUP=$(OBJECTDIR)/start.o + +ARCH_FLAGS= -mcpu=arm7tdmi-s -mthumb-interwork -march=armv4t -mtune=arm7tdmi-s -DCONFIG_ARM -D__ARM__ #-Wcast-align +THUMB_FLAGS= -mthumb -mcallee-super-interworking +ARM_FLAGS= + +CFLAGSNO = -I. -I$(CONTIKI)/core -I$(CONTIKI_CPU) -I$(CONTIKI_CPU)/loader \ + -I$(CONTIKI_CPU)/dbg-io \ + -I$(CONTIKI)/platform/$(TARGET) \ + -I$(CONTIKI_CPU)/lib/include \ + -I$(CONTIKI_CPU)/src \ + -I$(CONTIKI_CPU)/board \ + ${addprefix -I,$(APPDIRS)} \ + -DWITH_ASCII -DMCK=$(MCK) \ + -Werror $(ARCH_FLAGS) -g + +CFLAGS += $(CFLAGSNO) -Os -DRUN_AS_SYSTEM -DROM_RUN -fno-strict-aliasing -fno-common -ffixed-r8 -msoft-float -DTEXT_BASE=$(TEXT_BASE) -fno-builtin-printf -fno-builtin-sprintf +LDFLAGS += -T $(LINKERSCRIPT) -nostartfiles -static -Wl,-Map=contiki-$(TARGET).map,-export-dynamic +AFLAGS := $(AFLAGS_DEBUG) -D__ASSEMBLY__ $(CPPFLAGS) -gstabs + +CDEPFLAGS = $(CFLAGS) -D __MAKING_DEPS__ + +### Setup directory search path for source files + +CUSTOM_RULE_C_TO_OBJECTDIR_O=yes +CUSTOM_RULE_C_TO_O=yes + +CFLAGS += -I$(OBJECTDIR) -I$(CONTIKI_CPU)/board -DBOARD=$(TARGET) + +$(OBJECTDIR)/board.h: $(OBJECTDIR) + ln -sf ../$(CONTIKI_CPU)/board/$(TARGET).h $(OBJECTDIR)/board.h + + +$(OBJECTDIR)/isr.o: $(CONTIKI_CPU)/src/isr.c + $(CC) $(CFLAGS) $(ARM_FLAGS) $< -c -o $@ + +%.o: %.c + $(CC) $(CFLAGS) $(THUMB_FLAGS) $< -c + +$(OBJECTDIR)/%.o: %.c + $(CC) $(CFLAGS) $(THUMB_FLAGS) -c $< -o $@ + +CUSTOM_RULE_S_TO_OBJECTDIR_O = yes +%.o: %.S + $(CC) $(CFLAGS) $(AFLAGS) $(ARM_FLAGS) $< -c + +$(OBJECTDIR)/%.o: %.S + $(CC) $(CFLAGS) $(AFLAGS) $(ARM_FLAGS) $< -c -o $@ + +CUSTOM_RULE_C_TO_CO=yes + +%.co: %.c + $(CC) $(CFLAGS) -DAUTOSTART_ENABLE $(THUMB_FLAGS) $< -c -o $@ + +.PRECIOUS: %.bin %_$(TARGET).bin + +%.ihex: %.$(TARGET) + $(OBJCOPY) $^ -O ihex $@ + +%_$(TARGET).bin: %.elf + $(OBJCOPY) -O binary $< $@ + +symbols.c: + @${CONTIKI}/tools/make-empty-symbols + +%.$(TARGET): %_$(TARGET).bin + @ + +%.elf: $(OBJECTDIR)/board.h %.co $(PROJECT_OBJECTFILES) contiki-$(TARGET).a $(STARTUP) $(OBJECTDIR)/symbols.o + $(CC) $(LDFLAGS) $(CFLAGS) -nostartfiles -o $@ $(filter-out %.a,$^) $(filter %.a,$^) $(filter %.a,$^) + + diff --git a/cpu/mc1322x/README.subtree b/cpu/mc1322x/README.subtree new file mode 100644 index 000000000..7b79e35b9 --- /dev/null +++ b/cpu/mc1322x/README.subtree @@ -0,0 +1,39 @@ +The Contiki MC1322x port includes libmc1322x as a subtree. This makes +pulling updates to libmc1322x easy, but pushing changes from contiki +to libmc1322x is not so easy. However, this should not stop you from +implementing core features in contiki first, (especially if you are in +a bind). The way to do this is to make files prefixed with contiki-* +in cpu/mc1322x and add them to Makefile.mc1322x. + +For instance, if you need a routine called sleep, but libmc1322x +doesn't have that yet, you could implement sleep in +contiki-crm.c. Feel free to use as many contiki specific things in +here as you want. We can pull these changes directly into the contiki +tree. There is nothing stopping you from making changes to the lib +files --- in fact you should if that is the right thing to do (and +then push your changes upstream). The subtree merge should make it +easy to still pull updates. + +You'll also notice that the libmc1322x build system is still +present. This allows you to cd ./tests and make all of the libmc1322x +unit tests as normal. This is a handy way to perform a sainity check +on all of the mc1322x specific code. + +The subtree was set up as follows: + +From: +http://www.kernel.org/pub/software/scm/git/docs/howto/using-merge-subtree.html + +Moved mc1322x.lds to mc1322x.lds.contiki + +Setup with: + +git remote add -f libmc1322x git://git.devl.org/git/malvira/libmc1322x.git +git read-tree --prefix=cpu/mc1322x -u libmc1322x/master +git commit -m "Merge libmc1322x as a subdirectory" + + +And to do subsequent merges from libmc1322x do: + +git pull -s subtree libmc1322x master + diff --git a/cpu/mc1322x/TODO b/cpu/mc1322x/TODO new file mode 100644 index 000000000..593ed8735 --- /dev/null +++ b/cpu/mc1322x/TODO @@ -0,0 +1,12 @@ +- openocd flashing + use run_algorithm to hook ROM NVM functions + see flash/stm32x.c + +- add timestamp to received packets + +- add a way to set modes: tx_only, rx_only, txrx. (so you can be lazy + and have blocks of code that don't need to handle rx packets) + +- beacon sync + +- CCA and ED. diff --git a/cpu/mc1322x/clock.c b/cpu/mc1322x/clock.c new file mode 100644 index 000000000..fc2e417b9 --- /dev/null +++ b/cpu/mc1322x/clock.c @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2010, Mariano Alvira and other contributors + * to the MC1322x project (http://mc1322x.devl.org) and Contiki. + * + * 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 OS. + * + * $Id: clock.c,v 1.1 2010/06/09 14:43:22 maralvira Exp $ + */ + +#include +#include +#include +#include "dev/leds.h" + +#include "contiki-conf.h" +#include "mc1322x.h" + +#include "contiki-conf.h" + +#define MAX_TICKS (~((clock_time_t)0) / 2) + +static volatile clock_time_t current_clock = 0; + +volatile unsigned long seconds = 0; + +void +clock_init() +{ + /* timer setup */ + /* CTRL */ +#define COUNT_MODE 1 /* use rising edge of primary source */ +#define PRIME_SRC 0xf /* Perip. clock with 128 prescale (for 24Mhz = 187500Hz)*/ +#define SEC_SRC 0 /* don't need this */ +#define ONCE 0 /* keep counting */ +#define LEN 1 /* count until compare then reload with value in LOAD */ +#define DIR 0 /* count up */ +#define CO_INIT 0 /* other counters cannot force a re-initialization of this counter */ +#define OUT_MODE 0 /* OFLAG is asserted while counter is active */ + + *TMR_ENBL = 0; /* tmrs reset to enabled */ + *TMR0_SCTRL = 0; + *TMR0_CSCTRL =0x0040; + *TMR0_LOAD = 0; /* reload to zero */ + *TMR0_COMP_UP = 1875; /* trigger a reload at the end */ + *TMR0_CMPLD1 = 1875; /* compare 1 triggered reload level, 10HZ maybe? */ + *TMR0_CNTR = 0; /* reset count register */ + *TMR0_CTRL = (COUNT_MODE<<13) | (PRIME_SRC<<9) | (SEC_SRC<<7) | (ONCE<<6) | (LEN<<5) | (DIR<<4) | (CO_INIT<<3) | (OUT_MODE); + *TMR_ENBL = 0xf; /* enable all the timers --- why not? */ + + enable_irq(TMR); + +} + +void tmr0_isr(void) { + if(bit_is_set(*TMR(0,CSCTRL),TCF1)) { + current_clock++; + if((current_clock % CLOCK_CONF_SECOND) == 0) { + seconds++; +#if BLINK_SECONDS + leds_toggle(LEDS_GREEN); +#endif + } + + if(etimer_pending() && + (etimer_next_expiration_time() - current_clock - 1) > MAX_TICKS) { + etimer_request_poll(); + } + + + /* clear the compare flags */ + clear_bit(*TMR(0,SCTRL),TCF); + clear_bit(*TMR(0,CSCTRL),TCF1); + clear_bit(*TMR(0,CSCTRL),TCF2); + return; + } else { + /* this timer didn't create an interrupt condition */ + return; + } +} + +clock_time_t +clock_time(void) +{ + return current_clock; +} + +unsigned long +clock_seconds(void) +{ + return seconds; +} + +/* clock delay from cc2430 */ +/* I don't see any documentation about how this routine is suppose to behave */ +void +clock_delay(unsigned int len) +{ + unsigned int i; + for(i = 0; i< len; i++) { + asm("nop"); + } +} diff --git a/cpu/mc1322x/contiki-crm.c b/cpu/mc1322x/contiki-crm.c new file mode 100644 index 000000000..7eda30218 --- /dev/null +++ b/cpu/mc1322x/contiki-crm.c @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2010, Mariano Alvira and other contributors + * to the MC1322x project (http://mc1322x.devl.org) and Contiki. + * + * 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 OS. + * + * $Id: contiki-crm.c,v 1.1 2010/06/09 14:43:22 maralvira Exp $ + */ + +#include "mc1322x.h" + +#define CRM_DEBUG 1 +#if CRM_DEBUG +#define PRINTF(...) printf(__VA_ARGS__) +#else +#define PRINTF(...) +#endif + +uint32_t cal_rtc_secs; /* calibrated 2khz rtc seconds */ + +void sleep(uint32_t opts, uint32_t mode) +{ + + /* the maca must be off before going to sleep */ + /* otherwise the mcu will reboot on wakeup */ +// maca_off(); + *CRM_SLEEP_CNTL = opts; + *CRM_SLEEP_CNTL = (opts | mode); + + /* wait for the sleep cycle to complete */ + while(!bit_is_set(*CRM_STATUS,0)) { continue; } + /* write 1 to sleep_sync --- this clears the bit (it's a r1wc bit) and powers down */ + set_bit(*CRM_STATUS,0); + + /* now we are asleep */ + /* and waiting for something to wake us up */ + /* you did tell us how to wake up right? */ + + /* waking up */ + while(!bit_is_set(*CRM_STATUS,0)) { continue; } + /* write 1 to sleep_sync --- this clears the bit (it's a r1wc bit) and finishes the wakeup */ + set_bit(*CRM_STATUS,0); + + /* you may also need to do other recovery */ + /* such as interrupt handling */ + /* peripheral init */ + /* and turning the radio back on */ + +} + +/* turn on the 32kHz crystal */ +/* once you start the 32xHz crystal it can only be stopped with a reset (hard or soft) */ +void enable_32khz_xtal(void) +{ + static volatile uint32_t rtc_count; + PRINTF("enabling 32kHz crystal\n\r"); + /* first, disable the ring osc */ + ring_osc_off(); + /* enable the 32kHZ crystal */ + xtal32_on(); + + /* set the XTAL32_EXISTS bit */ + /* the datasheet says to do this after you've check that RTC_COUNT is changing */ + /* the datasheet is not correct */ + xtal32_exists(); + + /* now check that the crystal starts */ + /* this blocks until it starts */ + /* it would be better to timeout and return an error */ + rtc_count = *CRM_RTC_COUNT; + PRINTF("waiting for xtal\n\r"); + while(*CRM_RTC_COUNT == rtc_count) { + continue; + } + /* RTC has started up */ + PRINTF("32kHZ xtal started\n\r"); + +} + +void cal_ring_osc(void) +{ + uint32_t cal_factor; + PRINTF("performing ring osc cal\n\r"); + PRINTF("crm_status: 0x%0x\n\r",*CRM_STATUS); + PRINTF("sys_cntl: 0x%0x\n\r",*CRM_SYS_CNTL); + *CRM_CAL_CNTL = (1<<16) | (20000); + while((*CRM_STATUS & (1<<9)) == 0); + PRINTF("ring osc cal complete\n\r"); + PRINTF("cal_count: 0x%0x\n\r",*CRM_CAL_COUNT); + cal_factor = (REF_OSC*1000) / *CRM_CAL_COUNT; + cal_rtc_secs = (NOMINAL_RING_OSC_SEC * cal_factor)/100; + PRINTF("cal factor: %d\n\r", cal_factor); + PRINTF("hib_wake_secs: %d\n\r", cal_rtc_secs); + set_bit(*CRM_STATUS,9); +} diff --git a/cpu/mc1322x/contiki-maca.c b/cpu/mc1322x/contiki-maca.c new file mode 100644 index 000000000..94be1793b --- /dev/null +++ b/cpu/mc1322x/contiki-maca.c @@ -0,0 +1,277 @@ +/* + * Copyright (c) 2010, Mariano Alvira and other contributors + * to the MC1322x project (http://mc1322x.devl.org) and Contiki. + * + * 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 OS. + * + * $Id: contiki-maca.c,v 1.1 2010/06/09 14:43:22 maralvira Exp $ + */ + +#include +#include +#include + +/* contiki */ +#include "radio.h" +#include "sys/process.h" +#include "net/rime/packetbuf.h" +#include "net/netstack.h" + +#include "mc1322x.h" +#include "contiki-conf.h" + +#define CONTIKI_MACA_DEBUG 0 +#if CONTIKI_MACA_DEBUG +#define PRINTF(...) printf(__VA_ARGS__) +#else +#define PRINTF(...) +#endif + +#ifndef MACA_RAW_PREPEND +#define MACA_RAW_PREPEND 0xff +#endif + +#ifndef BLOCKING_TX +#define BLOCKING_TX 1 +#endif + +static volatile uint8_t tx_complete; + +/* contiki mac driver */ + +int contiki_maca_init(void); +int contiki_maca_on_request(void); +int contiki_maca_off_request(void); +int contiki_maca_read(void *buf, unsigned short bufsize); +int contiki_maca_prepare(const void *payload, unsigned short payload_len); +int contiki_maca_transmit(unsigned short transmit_len); +int contiki_maca_send(const void *payload, unsigned short payload_len); +int contiki_maca_channel_clear(void); +int contiki_maca_receiving_packet(void); +int contiki_maca_pending_packet(void); + +const struct radio_driver contiki_maca_driver = +{ + .init = contiki_maca_init, + .prepare = contiki_maca_prepare, + .transmit = contiki_maca_transmit, + .send = contiki_maca_send, + .read = contiki_maca_read, + .receiving_packet = contiki_maca_receiving_packet, + .pending_packet = contiki_maca_pending_packet, + .channel_clear = contiki_maca_channel_clear, + .on = contiki_maca_on_request, + .off = contiki_maca_off_request, +}; + +static volatile uint8_t contiki_maca_request_on = 0; +static volatile uint8_t contiki_maca_request_off = 0; + +static process_event_t event_data_ready; + +volatile packet_t *prepped_p; + +int contiki_maca_init(void) { + prepped_p = 0; + trim_xtal(); + vreg_init(); + contiki_maca_init(); + set_channel(0); /* channel 11 */ + set_power(0x12); /* 0x12 is the highest, not documented */ + return 1; +} + +/* CCA not implemented */ +int contiki_maca_channel_clear(void) { + return 1; +} + +/* not sure how to check if a reception is in progress */ +int contiki_maca_receiving_packet(void) { + return 0; +} + +int contiki_maca_pending_packet(void) { + if (rx_head != NULL) { + return 1; + } else { + return 0; + } +} + +int contiki_maca_on_request(void) { + contiki_maca_request_on = 1; + contiki_maca_request_off = 0; + return 1; +} + +int contiki_maca_off_request(void) { + contiki_maca_request_on = 0; + contiki_maca_request_off = 1; + return 1; +} + +/* it appears that the mc1332x radio cannot */ +/* receive packets where the last three bits of the first byte */ +/* is equal to 2 --- even in promiscuous mode */ +int contiki_maca_read(void *buf, unsigned short bufsize) { + volatile uint32_t i; + volatile packet_t *p; + + if((p = rx_packet())) { + PRINTF("maca read"); +#if CONTIKI_MACA_RAW_MODE + /* offset + 1 and size - 1 to strip the raw mode prepended byte */ + /* work around since maca can't receive acks bigger than five bytes */ + PRINTF(" raw mode"); + p->length -= 1; + p->offset += 1; +#endif + PRINTF(": p->length 0x%0x bufsize 0x%0x \n\r", p->length, bufsize); + if((p->length) < bufsize) bufsize = (p->length); + memcpy(buf, (uint8_t *)(p->data + p->offset), bufsize); +#if CONTIKI_MACA_DEBUG + for( i = p->offset ; i < (bufsize + p->offset) ; i++) { + PRINTF(" %02x",p->data[i]); + } +#endif + PRINTF("\n\r"); + free_packet(p); + return bufsize; + } else { + return 0; + } +} + +int contiki_maca_prepare(const void *payload, unsigned short payload_len) { + volatile int i; + volatile packet_t *p; + + if ((prepped_p == 0) + && (p = get_free_packet())) { + PRINTF("contiki maca prepare"); + maca_on(); +#if CONTIKI_MACA_RAW_MODE + p->offset = 1; + p->length = payload_len + 1; +#else + p->offset = 0; + p->length = payload_len; +#endif + if(payload_len > MAX_PACKET_SIZE) return RADIO_TX_ERR; + memcpy((uint8_t *)(p->data + p->offset), payload, payload_len); +#if CONTIKI_MACA_RAW_MODE + p->offset = 0; + p->data[0] = CONTIKI_MACA_PREPEND_BYTE; + PRINTF(" raw mode"); +#endif +#if CONTIKI_MACA_DEBUG + PRINTF(": sending %d bytes\n\r", payload_len); + for(i = p->offset ; i < (p->length + p->offset); i++) { + PRINTF(" %02x",p->data[i]); + } + PRINTF("\n\r"); +#endif + + prepped_p = p; + + return RADIO_TX_OK; + } else { + PRINTF("couldn't get free packet for contiki_maca_send\n\r"); + return RADIO_TX_ERR; + } +} + +int contiki_maca_transmit(unsigned short transmit_len) { + PRINTF("contiki maca transmit\n\r"); +#if BLOCKING_TX + tx_complete = 0; +#endif + tx_packet(prepped_p); + prepped_p = 0; +#if BLOCKING_TX + /* block until tx_complete, set by contiki_maca_tx_callback */ + /* there are many places in contiki that rely on the */ + /* transmit call to block */ + while(!tx_complete && (tx_head != 0)); +#endif +} + +int contiki_maca_send(const void *payload, unsigned short payload_len) { + contiki_maca_prepare(payload, payload_len); + contiki_maca_transmit(payload_len); + return RADIO_TX_OK; +} + +PROCESS(contiki_maca_process, "maca process"); +PROCESS_THREAD(contiki_maca_process, ev, data) +{ + volatile uint32_t i; + int len; + + PROCESS_BEGIN(); + + while (1) { + PROCESS_WAIT_EVENT_UNTIL(ev == event_data_ready); +// PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_POLL); + + /* check if there is a request to turn the radio on or off */ + if(contiki_maca_request_on == 1) { + contiki_maca_request_on = 0; + maca_on(); + } + + if(contiki_maca_request_off == 1) { + contiki_maca_request_off = 0; + maca_off(); + } + + if (rx_head != NULL) { + packetbuf_clear(); + len = contiki_maca_read(packetbuf_dataptr(), PACKETBUF_SIZE); + if(len > 0) { + packetbuf_set_datalen(len); + NETSTACK_RDC.input(); + } + } + + }; + + PROCESS_END(); +} + +void maca_rx_callback(volatile packet_t *p __attribute((unused))) { + process_post(&contiki_maca_process, event_data_ready, NULL); +} + +#if BLOCKING_TX +void maca_tx_callback(volatile packet_t *p __attribute((unused))) { + tx_complete = 1; +} +#endif diff --git a/cpu/mc1322x/contiki-maca.h b/cpu/mc1322x/contiki-maca.h new file mode 100644 index 000000000..136645b57 --- /dev/null +++ b/cpu/mc1322x/contiki-maca.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2010, Mariano Alvira and other contributors + * to the MC1322x project (http://mc1322x.devl.org) and Contiki. + * + * 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 OS. + * + * $Id: contiki-maca.h,v 1.1 2010/06/09 14:43:22 maralvira Exp $ + */ + +#ifndef CONTIKI_MACA_H +#define CONTIKI_MACA_H + +PROCESS_NAME(contiki_maca_process); + +extern const struct radio_driver contiki_maca_driver; + +#endif diff --git a/cpu/mc1322x/contiki-mc1322x-conf.h b/cpu/mc1322x/contiki-mc1322x-conf.h new file mode 100644 index 000000000..f664a7574 --- /dev/null +++ b/cpu/mc1322x/contiki-mc1322x-conf.h @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2010, Mariano Alvira and other contributors + * to the MC1322x project (http://mc1322x.devl.org) and Contiki. + * + * 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 OS. + * + * $Id: contiki-mc1322x-conf.h,v 1.1 2010/06/09 14:43:22 maralvira Exp $ + */ + +#ifndef __CONTIKI_MC1322X_CONF_H__ +#define __CONTIKI_MC1322X_CONF_H__ + +typedef int32_t s32_t; + +/* + * MCU and clock rate + */ +#define MCU_MHZ 24 +#define PLATFORM PLATFORM_MC1322X + +/* Pre-allocated memory for loadable modules heap space (in bytes)*/ +#define MMEM_CONF_SIZE 256 + +typedef uint32_t clock_time_t; +typedef unsigned char u8_t; +typedef unsigned short u16_t; +typedef unsigned long u32_t; +typedef unsigned short uip_stats_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 diff --git a/cpu/mc1322x/contiki-misc.c b/cpu/mc1322x/contiki-misc.c new file mode 100644 index 000000000..0486ed6f5 --- /dev/null +++ b/cpu/mc1322x/contiki-misc.c @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2010, Mariano Alvira and other contributors + * to the MC1322x project (http://mc1322x.devl.org) and Contiki. + * + * 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 OS. + * + * $Id: contiki-misc.c,v 1.1 2010/06/09 14:43:22 maralvira Exp $ + */ + +#include +#include "contiki.h" + +int raise(void) +{ + return 0; +} diff --git a/cpu/mc1322x/contiki-uart.c b/cpu/mc1322x/contiki-uart.c new file mode 100644 index 000000000..9f096a9e3 --- /dev/null +++ b/cpu/mc1322x/contiki-uart.c @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2010, Mariano Alvira and other contributors + * to the MC1322x project (http://mc1322x.devl.org) and Contiki. + * + * 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 OS. + * + * $Id: contiki-uart.c,v 1.1 2010/06/09 14:43:22 maralvira Exp $ + */ + +int (*uart1_input_handler)(unsigned char c) = 0; + +void +uart1_set_input(int (*input)(unsigned char c)) +{ + uart1_input_handler = input; +} + diff --git a/cpu/mc1322x/contiki-uart.h b/cpu/mc1322x/contiki-uart.h new file mode 100644 index 000000000..b40268ff3 --- /dev/null +++ b/cpu/mc1322x/contiki-uart.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2010, Mariano Alvira and other contributors + * to the MC1322x project (http://mc1322x.devl.org) and Contiki. + * + * 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 OS. + * + * $Id: contiki-uart.h,v 1.1 2010/06/09 14:43:22 maralvira Exp $ + */ + +#ifndef CONTIKI_UART_H +#define CONTIKI_UART_H + +extern int (*uart1_input_handler)(unsigned char c); + +#endif diff --git a/cpu/mc1322x/dbg-io.c b/cpu/mc1322x/dbg-io.c new file mode 100644 index 000000000..a8cdba188 --- /dev/null +++ b/cpu/mc1322x/dbg-io.c @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2010, Mariano Alvira and other contributors + * to the MC1322x project (http://mc1322x.devl.org) and Contiki. + * + * 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 OS. + * + * $Id: dbg-io.c,v 1.1 2010/06/09 14:43:22 maralvira Exp $ + */ + +#include +#include + +#include "uart1.h" +#include "contiki-conf.h" + +#undef putc +#undef puts + +int +putc(int c, FILE *f) +{ + dbg_putchar(c); + return c; +} + +int +puts(const char *s) +{ + unsigned int i=0; + while(s && *s!=0) { + dbg_putchar(*s++); i++; + } + return i; +} + diff --git a/cpu/mc1322x/debug-uart.c b/cpu/mc1322x/debug-uart.c new file mode 100644 index 000000000..796ed6986 --- /dev/null +++ b/cpu/mc1322x/debug-uart.c @@ -0,0 +1,12 @@ +#include "contiki-conf.h" + +unsigned int +dbg_send_bytes(const unsigned char *s, unsigned int len) +{ + unsigned int i=0; + while(s && *s!=0) { + if( i >= len) { break; } + dbg_putchar(*s++); i++; + } + return i; +} diff --git a/cpu/mc1322x/debug-uart.h b/cpu/mc1322x/debug-uart.h new file mode 100644 index 000000000..628e99e8f --- /dev/null +++ b/cpu/mc1322x/debug-uart.h @@ -0,0 +1,27 @@ +#ifndef __DEBUG_UART_H__1V2039076V__ +#define __DEBUG_UART_H__1V2039076V__ + +#ifndef dbg_setup_uart +#define dbg_setup_uart dbg_setup_uart_default +#endif + +void +dbg_setup_uart(); + +void +dbg_set_input_handler(void (*handler)(const char *inp, unsigned int len)); + +unsigned int +dbg_send_bytes(const unsigned char *seq, unsigned int len); + + +void +dbg_putchar(const char ch); + +void +dbg_blocking_putchar(const char ch); + +void +dbg_drain(); + +#endif /* __DEBUG_UART_H__1V2039076V__ */ diff --git a/cpu/mc1322x/leds-arch.c b/cpu/mc1322x/leds-arch.c new file mode 100644 index 000000000..92cc33211 --- /dev/null +++ b/cpu/mc1322x/leds-arch.c @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2010, Mariano Alvira and other contributors + * to the MC1322x project (http://mc1322x.devl.org) and Contiki. + * + * 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 OS. + * + * $Id: leds-arch.c,v 1.1 2010/06/09 14:43:22 maralvira Exp $ + */ + +#include "contiki-conf.h" +#include "dev/leds.h" +#include "mc1322x.h" +#include "board.h" + +#define LED_ARCH_RED (1ULL << LED_RED) +#define LED_ARCH_GREEN (1ULL << LED_GREEN) +#define LED_ARCH_BLUE (1ULL << LED_BLUE) + +#define LED_ARCH_YELLOW (LED_ARCH_RED | LED_ARCH_GREEN ) +#define LED_ARCH_PURPLE (LED_ARCH_RED | LED_ARCH_BLUE) +#define LED_ARCH_CYAN ( LED_ARCH_GREEN | LED_ARCH_BLUE) +#define LED_ARCH_WHITE (LED_ARCH_RED | LED_ARCH_GREEN | LED_ARCH_BLUE) + +/*FIXME: this is broken --- don't set all of the GPIO direction */ +void leds_arch_init(void) +{ + gpio_pad_dir(LED_ARCH_WHITE); +} + +unsigned char leds_arch_get(void) +{ + uint64_t led = (((uint64_t)*GPIO_DATA1) << 32) | *GPIO_DATA0; + + return ((led & LED_ARCH_RED) ? 0 : LEDS_RED) + | ((led & LED_ARCH_GREEN) ? 0 : LEDS_GREEN) + | ((led & LED_ARCH_BLUE) ? 0 : LEDS_BLUE) + | ((led & LED_ARCH_YELLOW) ? 0 : LEDS_YELLOW); + +} + +/*FIXME: this is broken --- it hits the entire GPIO data register and breaks the button sensor */ +void leds_arch_set(unsigned char leds) +{ + uint64_t led; + + led = (led & ~(LED_ARCH_RED|LED_ARCH_GREEN|LED_ARCH_YELLOW|LED_ARCH_BLUE)) + | ((leds & LEDS_RED) ? LED_ARCH_RED : 0) + | ((leds & LEDS_GREEN) ? LED_ARCH_GREEN : 0) + | ((leds & LEDS_BLUE) ? LED_ARCH_BLUE : 0) + | ((leds & LEDS_YELLOW) ? LED_ARCH_YELLOW : 0); + + gpio_data(led); +} + diff --git a/cpu/mc1322x/mc1322x.lds b/cpu/mc1322x/mc1322x.lds new file mode 100644 index 000000000..2b233bf64 --- /dev/null +++ b/cpu/mc1322x/mc1322x.lds @@ -0,0 +1,261 @@ +/* Script for -z combreloc: combine and sort reloc sections */ +OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", + "elf32-littlearm") +OUTPUT_ARCH(arm) +SEARCH_DIR("=/usr/local/lib"); SEARCH_DIR("=/lib"); SEARCH_DIR("=/usr/lib"); +SECTIONS +{ + +SYS_STACK_SIZE = 1024; +IRQ_STACK_SIZE = 256; +FIQ_STACK_SIZE = 256; +SVC_STACK_SIZE = 256; +ABT_STACK_SIZE = 16; +UND_STACK_SIZE = 16; +HEAP_SIZE = 1024; + + /* Read-only sections, merged into text segment: */ + PROVIDE (__executable_start = 0x00400000); . = 0x00400000; + .text : + { + *start*.o (.text) + *(.irq) + *(.text .stub .text.* .gnu.linkonce.t.*) + /* .gnu.warning sections are handled specially by elf32.em. */ + *(.gnu.warning) + *(.glue_7t) *(.glue_7) *(.vfp11_veneer) *(.v4_bx) + } =0 + + .stack : { + __stack_start__ = . ; + + . += IRQ_STACK_SIZE; + . = ALIGN (4); + __irq_stack_top__ = . ; + + . += FIQ_STACK_SIZE; + . = ALIGN (4); + __fiq_stack_top__ = . ; + + . += SVC_STACK_SIZE; + . = ALIGN (4); + __svc_stack_top__ = . ; + + . += ABT_STACK_SIZE; + . = ALIGN (4); + __abt_stack_top__ = . ; + + . += UND_STACK_SIZE; + . = ALIGN (4); + __und_stack_top__ = . ; + + . += SYS_STACK_SIZE; + . = ALIGN (4); + __sys_stack_top__ = . ; + + __stack_end__ = .; + } + + .interp : { *(.interp) } + .note.gnu.build-id : { *(.note.gnu.build-id) } + .hash : { *(.hash) } + .gnu.hash : { *(.gnu.hash) } + .dynsym : { *(.dynsym) } + .dynstr : { *(.dynstr) } + .gnu.version : { *(.gnu.version) } + .gnu.version_d : { *(.gnu.version_d) } + .gnu.version_r : { *(.gnu.version_r) } + .rel.dyn : + { + *(.rel.init) + *(.rel.text .rel.text.* .rel.gnu.linkonce.t.*) + *(.rel.fini) + *(.rel.rodata .rel.rodata.* .rel.gnu.linkonce.r.*) + *(.rel.data.rel.ro* .rel.gnu.linkonce.d.rel.ro.*) + *(.rel.data .rel.data.* .rel.gnu.linkonce.d.*) + *(.rel.tdata .rel.tdata.* .rel.gnu.linkonce.td.*) + *(.rel.tbss .rel.tbss.* .rel.gnu.linkonce.tb.*) + *(.rel.ctors) + *(.rel.dtors) + *(.rel.got) + *(.rel.bss .rel.bss.* .rel.gnu.linkonce.b.*) + } + .rela.dyn : + { + *(.rela.init) + *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*) + *(.rela.fini) + *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*) + *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*) + *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*) + *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*) + *(.rela.ctors) + *(.rela.dtors) + *(.rela.got) + *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*) + } + .rel.plt : { *(.rel.plt) } + .rela.plt : { *(.rela.plt) } + .init : + { + KEEP (*(.init)) + } =0 + .plt : { *(.plt) } + .fini : + { + KEEP (*(.fini)) + } =0 + PROVIDE (__etext = .); + PROVIDE (_etext = .); + PROVIDE (etext = .); + .rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) } + .rodata1 : { *(.rodata1) } + .eh_frame_hdr : { *(.eh_frame_hdr) } + .eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) } + .gcc_except_table : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) } + /* Adjust the address for the data segment. We want to adjust up to + the same address within the page on the next page up. */ + +/* . = ALIGN (CONSTANT (MAXPAGESIZE)) - ((CONSTANT (MAXPAGESIZE) - .) & (CONSTANT (MAXPAGESIZE) - 1)); . = DATA_SEGMENT_ALIGN (CONSTANT (MAXPAGESIZE), CONSTANT (COMMONPAGESIZE)); */ + + . = ALIGN(4); + . = DATA_SEGMENT_ALIGN(4,4); + + /* Exception handling */ + .eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) } + .gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) } + /* Thread Local Storage sections */ + .tdata : { *(.tdata .tdata.* .gnu.linkonce.td.*) } + .tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) } + .preinit_array : + { + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP (*(.preinit_array)) + PROVIDE_HIDDEN (__preinit_array_end = .); + } + .init_array : + { + PROVIDE_HIDDEN (__init_array_start = .); + KEEP (*(SORT(.init_array.*))) + KEEP (*(.init_array)) + PROVIDE_HIDDEN (__init_array_end = .); + } + .fini_array : + { + PROVIDE_HIDDEN (__fini_array_start = .); + KEEP (*(.fini_array)) + KEEP (*(SORT(.fini_array.*))) + PROVIDE_HIDDEN (__fini_array_end = .); + } + .ctors : + { + /* gcc uses crtbegin.o to find the start of + the constructors, so we make sure it is + first. Because this is a wildcard, it + doesn't matter if the user does not + actually link against crtbegin.o; the + linker won't look for a file to match a + wildcard. The wildcard also means that it + doesn't matter which directory crtbegin.o + is in. */ + KEEP (*crtbegin.o(.ctors)) + KEEP (*crtbegin?.o(.ctors)) + /* We don't want to include the .ctor section from + the crtend.o file until after the sorted ctors. + The .ctor section from the crtend file contains the + end of ctors marker and it must be last */ + KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors)) + KEEP (*(SORT(.ctors.*))) + KEEP (*(.ctors)) + } + .dtors : + { + KEEP (*crtbegin.o(.dtors)) + KEEP (*crtbegin?.o(.dtors)) + KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors)) + KEEP (*(SORT(.dtors.*))) + KEEP (*(.dtors)) + } + .jcr : { KEEP (*(.jcr)) } + .data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro* .gnu.linkonce.d.rel.ro.*) } + .dynamic : { *(.dynamic) } + . = DATA_SEGMENT_RELRO_END (0, .); + .got : { *(.got.plt) *(.got) } + .data : + { + __data_start = . ; + *(.data .data.* .gnu.linkonce.d.*) + SORT(CONSTRUCTORS) + } + .data1 : { *(.data1) } + _edata = .; PROVIDE (edata = .); + __bss_start = .; + __bss_start__ = .; + .bss : + { + *(.dynbss) + *(.bss .bss.* .gnu.linkonce.b.*) + *(COMMON) + /* Align here to ensure that the .bss section occupies space up to + _end. Align after .bss to ensure correct alignment even if the + .bss section disappears because there are no input sections. + FIXME: Why do we need it? When there is no .bss section, we don't + pad the .data section. */ + . = ALIGN(. != 0 ? 32 / 8 : 1); + } + _bss_end__ = . ; __bss_end__ = . ; + . = ALIGN(32 / 8); + + .heap : { + __heap_start__ = . ; + *(.heap); + . += HEAP_SIZE; + . = ALIGN (4); + __heap_end__ = . ; + } + + + . = ALIGN(32 / 8); + __end__ = . ; + _end = .; PROVIDE (end = .); + . = DATA_SEGMENT_END (.); + /* Stabs debugging sections. */ + .stab 0 : { *(.stab) } + .stabstr 0 : { *(.stabstr) } + .stab.excl 0 : { *(.stab.excl) } + .stab.exclstr 0 : { *(.stab.exclstr) } + .stab.index 0 : { *(.stab.index) } + .stab.indexstr 0 : { *(.stab.indexstr) } + .comment 0 : { *(.comment) } + /* DWARF debug sections. + Symbols in the DWARF debugging sections are relative to the beginning + of the section so we begin them at 0. */ + /* DWARF 1 */ + .debug 0 : { *(.debug) } + .line 0 : { *(.line) } + /* GNU DWARF 1 extensions */ + .debug_srcinfo 0 : { *(.debug_srcinfo) } + .debug_sfnames 0 : { *(.debug_sfnames) } + /* DWARF 1.1 and DWARF 2 */ + .debug_aranges 0 : { *(.debug_aranges) } + .debug_pubnames 0 : { *(.debug_pubnames) } + /* DWARF 2 */ + .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) } + .debug_abbrev 0 : { *(.debug_abbrev) } + .debug_line 0 : { *(.debug_line) } + .debug_frame 0 : { *(.debug_frame) } + .debug_str 0 : { *(.debug_str) } + .debug_loc 0 : { *(.debug_loc) } + .debug_macinfo 0 : { *(.debug_macinfo) } + /* SGI/MIPS DWARF 2 extensions */ + .debug_weaknames 0 : { *(.debug_weaknames) } + .debug_funcnames 0 : { *(.debug_funcnames) } + .debug_typenames 0 : { *(.debug_typenames) } + .debug_varnames 0 : { *(.debug_varnames) } + /* DWARF 3 */ + .debug_pubtypes 0 : { *(.debug_pubtypes) } + .debug_ranges 0 : { *(.debug_ranges) } + .gnu.attributes 0 : { KEEP (*(.gnu.attributes)) } + .note.gnu.arm.ident 0 : { KEEP (*(.note.gnu.arm.ident)) } + /DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) } +} diff --git a/cpu/mc1322x/mtarch.h b/cpu/mc1322x/mtarch.h new file mode 100644 index 000000000..ccea2ac8a --- /dev/null +++ b/cpu/mc1322x/mtarch.h @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2010, Mariano Alvira and other contributors + * to the MC1322x project (http://mc1322x.devl.org) and Contiki. + * + * 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 OS. + * + * $Id: mtarch.h,v 1.1 2010/06/09 14:43:22 maralvira Exp $ + */ + +/** + * \file + * AVR specific implementation of multithreading architecture + * \author + * Adam Dunkels + * \author + * Simon Barner + * + * @(#)$Id: mtarch.h,v 1.1 2010/06/09 14:43:22 maralvira Exp $ + */ + +#ifndef __MTARCH_H__ +#define __MTARCH_H__ + +#include "contiki-conf.h" + +#ifdef MTARCH_CONF_STACKSIZE +#define MTARCH_STACKSIZE MTARCH_CONF_STACKSIZE +#else +#define MTARCH_STACKSIZE 128 +#endif + +struct mtarch_thread { + unsigned char stack[MTARCH_STACKSIZE]; + unsigned char *sp; +}; + +#endif /* __MTARCH_H__ */ + diff --git a/cpu/mc1322x/rtimer-arch.c b/cpu/mc1322x/rtimer-arch.c new file mode 100644 index 000000000..15bc930a0 --- /dev/null +++ b/cpu/mc1322x/rtimer-arch.c @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2010, Mariano Alvira and other contributors + * to the MC1322x project (http://mc1322x.devl.org) and Contiki. + * + * 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 OS. + * + * $Id: rtimer-arch.c,v 1.1 2010/06/09 14:43:22 maralvira Exp $ + */ + +/** + * \file + * mc1322x-specific rtimer code + * \author + * Mariano Alvira + */ + +#include + +/* contiki */ +#include "sys/energest.h" +#include "sys/rtimer.h" + +/* mc1322x */ +#include "utils.h" + +#define DEBUG 0 +#if DEBUG +#include +#define PRINTF(...) printf(__VA_ARGS__) +#else +#define PRINTF(...) +#endif + +void rtc_isr(void) { + PRINTF("rtc_wu_irq\n\r"); + PRINTF("now is %u\n", rtimer_arch_now()); + disable_rtc_wu(); + disable_rtc_wu_irq(); + rtimer_run_next(); + clear_rtc_wu_evt(); +} + +void +rtimer_arch_init(void) +{ +} + +void +rtimer_arch_schedule(rtimer_clock_t t) +{ + volatile uint32_t now; + now = rtimer_arch_now(); + PRINTF("rtimer_arch_schedule time %u; now is %u\n", t,now); + if(now>t) { + *CRM_RTC_TIMEOUT = 1; + } else { + *CRM_RTC_TIMEOUT = t - now; + } + + clear_rtc_wu_evt(); + enable_rtc_wu(); + enable_rtc_wu_irq(); + PRINTF("rtimer_arch_schedule CRM_RTC_TIMEOUT is %u\n", *CRM_RTC_TIMEOUT); +} diff --git a/cpu/mc1322x/rtimer-arch.h b/cpu/mc1322x/rtimer-arch.h new file mode 100644 index 000000000..e135bb2e9 --- /dev/null +++ b/cpu/mc1322x/rtimer-arch.h @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2010, Mariano Alvira and other contributors + * to the MC1322x project (http://mc1322x.devl.org) and Contiki. + * + * 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 OS. + * + * $Id: rtimer-arch.h,v 1.1 2010/06/09 14:43:22 maralvira Exp $ + */ + +/** + * \file + * Header file for the mc1322x-specific rtimer code + * \author + * Mariano Alvira + */ + +#ifndef __RTIMER_ARCH_H__ +#define __RTIMER_ARCH_H__ + +/* contiki */ +#include "sys/rtimer.h" + +/* mc1322x */ +#include "crm.h" +#include "utils.h" + +#if USE_32KHZ_XTAL +#define RTIMER_ARCH_SECOND 32768 +#else +#define RTIMER_ARCH_SECOND 2000 /* bogus value --- you should set xmac_config after calibration */ +#endif + +#define rtimer_arch_now() (*CRM_RTC_COUNT) + +#endif /* __RTIMER_ARCH_H__ */ diff --git a/cpu/mc1322x/slip-uart1.c b/cpu/mc1322x/slip-uart1.c new file mode 100644 index 000000000..d3b6b394c --- /dev/null +++ b/cpu/mc1322x/slip-uart1.c @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2006, Swedish Institute of Computer Science + * Copyright (c) 2010, Mariano Alvira and other contributors + * to the MC1322x project (http://mc1322x.devl.org) and Contiki. + * + * 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 OS. + * + * $Id: slip-uart1.c,v 1.1 2010/06/09 14:43:22 maralvira Exp $ + */ + +/* + * Machine dependent mc1322x SLIP routines for UART1. + */ + +#include "contiki.h" +#include "dev/slip.h" + +#include "mc1322x.h" + +/*---------------------------------------------------------------------------*/ +void +slip_arch_writeb(unsigned char c) +{ + uart1_putc(c); +} +/*---------------------------------------------------------------------------*/ +/* + * The serial line is used to transfer IP packets using slip. To make + * it possible to send debug output over the same line we send debug + * output as slip frames (i.e delimeted by SLIP_END). + * + */ +/*---------------------------------------------------------------------------*/ +#if WITH_UIP +int +putchar(int c) +{ +#define SLIP_END 0300 + static char debug_frame = 0; + + if (!debug_frame) { /* Start of debug output */ + slip_arch_writeb(SLIP_END); + slip_arch_writeb('\r'); /* Type debug line == '\r' */ + debug_frame = 1; + } + + slip_arch_writeb((char)c); + + /* + * Line buffered output, a newline marks the end of debug output and + * implicitly flushes debug output. + */ + if (c == '\n') { + slip_arch_writeb(SLIP_END); + debug_frame = 0; + } + + return c; +} +#endif +/*---------------------------------------------------------------------------*/ +/** + * Initalize the RS232 port and the SLIP driver. + * + */ +void +slip_arch_init(unsigned long ubr) +{ + uart1_set_input(slip_input_byte); +} +/*---------------------------------------------------------------------------*/ diff --git a/cpu/mc1322x/watchdog.c b/cpu/mc1322x/watchdog.c new file mode 100644 index 000000000..ba48c6732 --- /dev/null +++ b/cpu/mc1322x/watchdog.c @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2010, Mariano Alvira and other contributors + * to the MC1322x project (http://mc1322x.devl.org) and Contiki. + * + * 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 OS. + * + * $Id: watchdog.c,v 1.1 2010/06/09 14:43:22 maralvira Exp $ + */ + +#include "dev/watchdog.h" + +/*---------------------------------------------------------------------------*/ +void +watchdog_init(void) +{ +} +/*---------------------------------------------------------------------------*/ +void +watchdog_start(void) +{ +} +/*---------------------------------------------------------------------------*/ +void +watchdog_periodic(void) +{ +} +/*---------------------------------------------------------------------------*/ +void +watchdog_stop(void) +{ +} +/*---------------------------------------------------------------------------*/ +void +watchdog_reboot(void) +{ +} +/*---------------------------------------------------------------------------*/