initial mc1322x commit

based on commit aac3a355451d899f02737f2907af8c874ee4feba of

git://git.devl.org/git/malvira/contiki-mc1322x.git
This commit is contained in:
maralvira 2010-06-10 14:55:39 +00:00
parent 285f508cc9
commit 419906a769
50 changed files with 5952 additions and 0 deletions

65
cpu/mc1322x/dev/uart1.h Normal file
View file

@ -0,0 +1,65 @@
/*
* Copyright (c) 2010, Mariano Alvira <mar@devl.org> 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: uart1.h,v 1.1 2010/06/10 14:55:39 maralvira Exp $
*/
/*
This file exists as a work-around for the hardware dependant calls
to slip_arch_init.
Current the prototype for slip_arch_init is slip_arch_init(urb)
and a typical call is something like
slip_arch_init(BAUD2URB(115200))
BAUD2UBR is hardware specific, however. Furthermore, for the sky
platform it's typically defined with #include "dev/uart1.h" (see
rpl-boarder-router/slip-bridge.c), a sky specific file. dev/uart1.h
includes msp430.h which includes the sky contiki-conf.h which
defines BAUD2UBR.
To me, the correct think to pass is simply the baudrate and have the
hardware specific conversion happen inside slip_arch_init.
Notably, most implementations just ignore the passed parameter
anyway. (except AVR)
*/
#ifndef DEV_UART1_H
#define DEV_UART1_H
#define BAUD2UBR(x) x
#endif

View file

@ -0,0 +1,8 @@
# -*- makefile -*-
CFLAGS += -I$(LIBMC1322X)/include
LIBOBJS = $(patsubst %.c,%.o,$(wildcard $(LIBMC1322X)/*.c))
$(LIBMC1322X)/libmc1322x.a: $(LIBOBJS)
$(AR) rcs $(LIBMC1322X)/libmc1322x.a $(LIBOBJS)

100
cpu/mc1322x/lib/gpio.c Normal file
View file

@ -0,0 +1,100 @@
/*
* Copyright (c) 2010, Mariano Alvira <mar@devl.org> and other contributors
* to the MC1322x project (http://mc1322x.devl.org)
* 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 libmc1322x: see http://mc1322x.devl.org
* for details.
*
* $Id: gpio.c,v 1.1 2010/06/10 14:55:39 maralvira Exp $
*/
#include <mc1322x.h>
#include <types.h>
inline void gpio_pad_dir(volatile uint64_t data)
{
*GPIO_PAD_DIR0 = (data & 0xffffffff);
*GPIO_PAD_DIR1 = (data >> 32);
}
inline void gpio_data(volatile uint64_t data)
{
*GPIO_DATA0 = (data & 0xffffffff);
*GPIO_DATA1 = (data >> 32);
}
inline uint64_t gpio_data_get(volatile uint64_t bits) {
uint64_t rdata = 0;
rdata = *GPIO_DATA0 & (bits & 0xffffffff);
rdata |= (*GPIO_DATA1 & (bits >> 32)) << 32;
return rdata;
}
inline void gpio_pad_pu_en(volatile uint64_t data)
{
*GPIO_PAD_PU_EN0 = (data & 0xffffffff);
*GPIO_PAD_PU_EN1 = (data >> 32);
}
inline void gpio_data_sel(volatile uint64_t data)
{
*GPIO_DATA_SEL0 = (data & 0xffffffff);
*GPIO_DATA_SEL1 = (data >> 32);
}
inline void gpio_pad_pu_sel(volatile uint64_t data)
{
*GPIO_PAD_PU_SEL0 = (data & 0xffffffff);
*GPIO_PAD_PU_SEL1 = (data >> 32);
}
inline void gpio_data_set(volatile uint64_t data)
{
*GPIO_DATA_SET0 = (data & 0xffffffff);
*GPIO_DATA_SET1 = (data >> 32);
}
inline void gpio_data_reset(volatile uint64_t data)
{
*GPIO_DATA_RESET0 = (data & 0xffffffff);
*GPIO_DATA_RESET1 = (data >> 32);
}
inline void gpio_pad_dir_set(volatile uint64_t data)
{
*GPIO_PAD_DIR_SET0 = (data & 0xffffffff);
*GPIO_PAD_DIR_SET1 = (data >> 32);
}
inline void gpio_pad_dir_reset(volatile uint64_t data)
{
*GPIO_PAD_DIR_RESET0 = (data & 0xffffffff);
*GPIO_PAD_DIR_RESET1 = (data >> 32);
}

View file

@ -0,0 +1,138 @@
/*
* Copyright (c) 2010, Mariano Alvira <mar@devl.org> and other contributors
* to the MC1322x project (http://mc1322x.devl.org)
* 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 libmc1322x: see http://mc1322x.devl.org
* for details.
*
* $Id: crm.h,v 1.1 2010/06/10 14:55:39 maralvira Exp $
*/
#ifndef CRM_H
#define CRM_H
#include <types.h>
#define CRM_BASE (0x80003000)
#define CRM_SYS_CNTL ((volatile uint32_t *) (CRM_BASE+0x00))
#define CRM_WU_CNTL ((volatile uint32_t *) (CRM_BASE+0x04))
#define CRM_SLEEP_CNTL ((volatile uint32_t *) (CRM_BASE+0x08))
#define CRM_BS_CNTL ((volatile uint32_t *) (CRM_BASE+0x0c))
#define CRM_COP_CNTL ((volatile uint32_t *) (CRM_BASE+0x10))
#define CRM_COP_SERVICE ((volatile uint32_t *) (CRM_BASE+0x14))
#define CRM_STATUS ((volatile uint32_t *) (CRM_BASE+0x18))
#define CRM_MOD_STATUS ((volatile uint32_t *) (CRM_BASE+0x1c))
#define CRM_WU_COUNT ((volatile uint32_t *) (CRM_BASE+0x20))
#define CRM_WU_TIMEOUT ((volatile uint32_t *) (CRM_BASE+0x24))
#define CRM_RTC_COUNT ((volatile uint32_t *) (CRM_BASE+0x28))
#define CRM_RTC_TIMEOUT ((volatile uint32_t *) (CRM_BASE+0x2c))
#define CRM_CAL_CNTL ((volatile uint32_t *) (CRM_BASE+0x34))
#define CRM_CAL_COUNT ((volatile uint32_t *) (CRM_BASE+0x38))
#define CRM_RINGOSC_CNTL ((volatile uint32_t *) (CRM_BASE+0x3c))
#define CRM_XTAL_CNTL ((volatile uint32_t *) (CRM_BASE+0x40))
#define CRM_XTAL32_CNTL ((volatile uint32_t *) (CRM_BASE+0x44))
#define CRM_VREG_CNTL ((volatile uint32_t *) (CRM_BASE+0x48))
#define CRM_SW_RST ((volatile uint32_t *) (CRM_BASE+0x50))
/* CRM_SYS_CNTL bit locations */
#define XTAL32_EXISTS 5
/* CRM_WU_CNTL bit locations */
#define EXT_WU_IEN 20 /* 4 bits */
#define EXT_WU_EN 4 /* 4 bits */
#define EXT_WU_EDGE 8 /* 4 bits */
#define EXT_WU_POL 12 /* 4 bits */
#define TIMER_WU_EN 0
#define RTC_WU_EN 1
#define TIMER_WU_IEN 16
#define RTC_WU_IEN 17
/* CRM_STATUS bit locations */
#define EXT_WU_EVT 4 /* 4 bits, rw1c */
#define RTC_WU_EVT 3 /* rw1c */
/* RINGOSC_CNTL bit locations */
#define ROSC_CTUNE 9 /* 4 bits */
#define ROSC_FTUNE 4 /* 4 bits */
#define ROSC_EN 0
#define ring_osc_on() (set_bit(*CRM_RINGOSC_CNTL,ROSC_EN))
#define ring_osc_off() (clear_bit(*CRM_RINGOSC_CNTL,ROSC_EN))
#define REF_OSC 24000000ULL /* reference osc. frequency */
#define NOMINAL_RING_OSC_SEC 2000 /* nominal ring osc. frequency */
extern uint32_t cal_rtc_secs; /* calibrated 2khz rtc seconds */
/* XTAL32_CNTL bit locations */
#define XTAL32_GAIN 4 /* 2 bits */
#define XTAL32_EN 0
#define xtal32_on() (set_bit(*CRM_XTAL32_CNTL,XTAL32_EN))
#define xtal32_off() (clear_bit(*CRM_XTAL32_CNTL,XTAL32_EN))
#define xtal32_exists() (set_bit(*CRM_SYS_CNTL,XTAL32_EXISTS))
/* enable external wake-ups on kbi 4-7 */
/* see kbi.h for other kbi specific macros */
#define enable_ext_wu(kbi) (set_bit(*CRM_WU_CNTL,(EXT_WU_EN+kbi-4)))
#define disable_ext_wu(kbi) (clear_bit(*CRM_WU_CNTL,(EXT_WU_EN+kbi-4)))
#define is_ext_wu_evt(kbi) (bit_is_set(*CRM_STATUS,(EXT_WU_EVT+kbi-4)))
#define clear_ext_wu_evt(kbi) (set_bit(*CRM_STATUS,(EXT_WU_EVT+kbi-4))) /* r1wc bit */
/* enable wake-up timer */
#define enable_timer_wu_irq() ((set_bit(*CRM_WU_CNTL,(TIMER_WU_IEN))))
#define disable_timer_wu_irq() ((clear_bit(*CRM_WU_CNTL,(TIMER_WU_IEN))))
#define enable_timer_wu() ((set_bit(*CRM_WU_CNTL,(TIMER_WU_EN))))
#define disable_timer_wu() ((clear_bit(*CRM_WU_CNTL,(TIMER_WU_EN))))
/* enable wake-up from RTC compare */
#define enable_rtc_wu_irq() (set_bit(*CRM_WU_CNTL,RTC_WU_IEN))
#define disable_rtc_wu_irq() (clear_bit(*CRM_WU_CNTL,RTC_WU_IEN))
#define enable_rtc_wu() ((set_bit(*CRM_WU_CNTL,(RTC_WU_EN))))
#define disable_rtc_wu() ((clear_bit(*CRM_WU_CNTL,(RTC_WU_EN))))
#define clear_rtc_wu_evt() (set_bit(*CRM_STATUS,RTC_WU_EVT))
#define rtc_wu_evt() (bit_is_set(*CRM_STATUS,RTC_WU_EVT))
#define SLEEP_MODE_HIBERNATE bit(0)
#define SLEEP_MODE_DOZE bit(1)
#define SLEEP_PAD_PWR bit(7)
#define SLEEP_RETAIN_MCU bit(6)
#define sleep_ram_retain(x) (x<<4) /* 0-3 */
#define SLEEP_RAM_8K sleep_ram_retain(0)
#define SLEEP_RAM_32K sleep_ram_retain(1)
#define SLEEP_RAM_64K sleep_ram_retain(2)
#define SLEEP_RAM_96K sleep_ram_retain(3)
#define pack_XTAL_CNTL(ctune4pf, ctune, ftune, ibias) \
(*CRM_XTAL_CNTL = ((ctune4pf << 25) | (ctune << 21) | ( ftune << 16) | (ibias << 8) | 0x52))
#endif

View file

@ -0,0 +1,90 @@
/*
* Copyright (c) 2010, Mariano Alvira <mar@devl.org> and other contributors
* to the MC1322x project (http://mc1322x.devl.org)
* 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 libmc1322x: see http://mc1322x.devl.org
* for details.
*
* $Id: gpio.h,v 1.1 2010/06/10 14:55:39 maralvira Exp $
*/
#ifndef GPIO_H
#define GPIO_H
#define GPIO_PAD_DIR0 ((volatile uint32_t *) 0x80000000)
#define GPIO_PAD_DIR1 ((volatile uint32_t *) 0x80000004)
#define GPIO_DATA0 ((volatile uint32_t *) 0x80000008)
#define GPIO_DATA1 ((volatile uint32_t *) 0x8000000c)
#define GPIO_PAD_PU_EN0 ((volatile uint32_t *) 0x80000010)
#define GPIO_PAD_PU_EN1 ((volatile uint32_t *) 0x80000014)
#define GPIO_FUNC_SEL0 ((volatile uint32_t *) 0x80000018) /* GPIO 15 - 0; 2 bit blocks */
#define GPIO_FUNC_SEL1 ((volatile uint32_t *) 0x8000001c) /* GPIO 16 - 31; 2 bit blocks */
#define GPIO_FUNC_SEL2 ((volatile uint32_t *) 0x80000020) /* GPIO 32 - 47; 2 bit blocks */
#define GPIO_FUNC_SEL3 ((volatile uint32_t *) 0x80000024) /* GPIO 48 - 63; 2 bit blocks */
#define GPIO_DATA_SEL0 ((volatile uint32_t *) 0x80000028)
#define GPIO_DATA_SEL1 ((volatile uint32_t *) 0x8000002c)
#define GPIO_PAD_PU_SEL0 ((volatile uint32_t *) 0x80000030)
#define GPIO_PAD_PU_SEL1 ((volatile uint32_t *) 0x80000034)
#define GPIO_DATA_SET0 ((volatile uint32_t *) 0x80000048)
#define GPIO_DATA_SET1 ((volatile uint32_t *) 0x8000004c)
#define GPIO_DATA_RESET0 ((volatile uint32_t *) 0x80000050)
#define GPIO_DATA_RESET1 ((volatile uint32_t *) 0x80000054)
#define GPIO_PAD_DIR_SET0 ((volatile uint32_t *) 0x80000058)
#define GPIO_PAD_DIR_SET1 ((volatile uint32_t *) 0x8000005c)
#define GPIO_PAD_DIR_RESET0 ((volatile uint32_t *) 0x80000060)
#define GPIO_PAD_DIR_RESET1 ((volatile uint32_t *) 0x80000064)
inline void gpio_pad_dir(volatile uint64_t data);
inline void gpio_data(volatile uint64_t data);
inline uint64_t gpio_data_get(volatile uint64_t bits);
inline void gpio_pad_pu_en(volatile uint64_t data);
inline void gpio_data_sel(volatile uint64_t data);
inline void gpio_data_pu_sel(volatile uint64_t data);
inline void gpio_data_set(volatile uint64_t data);
inline void gpio_data_reset(volatile uint64_t data);
inline void gpio_pad_dir_set(volatile uint64_t data);
inline void gpio_pad_dir_reset(volatile uint64_t data);
/* select pullup or pulldown for GPIO 0-31 (b=0-31) */
#define gpio_sel0_pullup(b) (set_bit(*GPIO_PAD_PU_SEL0,b))
#define gpio_sel0_pulldown(b) (clear_bit(*GPIO_PAD_PU_SEL0,b))
/* select pullup or pulldown for GPIO 32-63 (b=32-63) */
#define gpio_sel1_pullup(b) (set_bit(*GPIO_PAD_PU_SEL1,b-32))
#define gpio_sel1_pulldown(b) (clear_bit(*GPIO_PAD_PU_SEL1,b-32))
/* enable/disable pullup for GPIO 0-31 (b=0-31) */
#define gpio_pu0_enable(b) (set_bit(*GPIO_PAD_PU_EN0,b))
#define gpio_pu0_disable(b) (clear_bit(*GPIO_PAD_PU_EN0,b))
/* enable/disable pullup for GPIO 32-63 (b=32-63) */
#define gpio_pu1_enable(b) (set_bit(*GPIO_PAD_PU_EN1,b-32))
#define gpio_pu1_disable(b) (clear_bit(*GPIO_PAD_PU_EN1,b-32))
#endif

View file

@ -0,0 +1,96 @@
/*
* Copyright (c) 2010, Mariano Alvira <mar@devl.org> and other contributors
* to the MC1322x project (http://mc1322x.devl.org)
* 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 libmc1322x: see http://mc1322x.devl.org
* for details.
*
* $Id: isr.h,v 1.1 2010/06/10 14:55:39 maralvira Exp $
*/
#ifndef ISR_H
#define ISR_H
#define INTBASE (0x80020000)
#define INTCNTL_OFF (0x0)
#define INTENNUM_OFF (0x8)
#define INTDISNUM_OFF (0xC)
#define INTENABLE_OFF (0x10)
#define INTSRC_OFF (0x30)
#define INTFRC_OFF (0x34)
#define NIPEND_OFF (0x38)
#define INTCNTL ((volatile uint32_t *) (INTBASE + INTCNTL_OFF))
#define INTENNUM ((volatile uint32_t *) (INTBASE + INTENNUM_OFF))
#define INTDISNUM ((volatile uint32_t *) (INTBASE + INTDISNUM_OFF))
#define INTENABLE ((volatile uint32_t *) (INTBASE + INTENABLE_OFF))
#define INTSRC ((volatile uint32_t *) (INTBASE + INTSRC_OFF))
#define INTFRC ((volatile uint32_t *) (INTBASE + INTFRC_OFF))
#define NIPEND ((volatile uint32_t *) (INTBASE + NIPEND_OFF))
enum interrupt_nums {
INT_NUM_ASM = 0,
INT_NUM_UART1,
INT_NUM_UART2,
INT_NUM_CRM,
INT_NUM_I2C,
INT_NUM_TMR,
INT_NUM_SPIF,
INT_NUM_MACA,
INT_NUM_SSI,
INT_NUM_ADC,
INT_NUM_SPI,
};
#define global_irq_disable() (set_bit(*INTCNTL,20))
#define global_irq_enable() (clear_bit(*INTCNTL,20))
#define enable_irq(irq) (*INTENNUM = INT_NUM_##irq)
#define disable_irq(irq) (*INTDISNUM = INT_NUM_##irq)
#define safe_irq_disable(x) volatile uint32_t saved_irq; saved_irq = *INTENABLE; disable_irq(x)
#define irq_restore() *INTENABLE = saved_irq
extern void tmr0_isr(void) __attribute__((weak));
extern void tmr1_isr(void) __attribute__((weak));
extern void tmr2_isr(void) __attribute__((weak));
extern void tmr3_isr(void) __attribute__((weak));
extern void rtc_isr(void) __attribute__((weak));
extern void kbi4_isr(void) __attribute__((weak));
extern void kbi5_isr(void) __attribute__((weak));
extern void kbi6_isr(void) __attribute__((weak));
extern void kbi7_isr(void) __attribute__((weak));
extern void uart1_isr(void) __attribute__((weak));
extern void maca_isr(void) __attribute__((weak));
#endif

View file

@ -0,0 +1,54 @@
/*
* Copyright (c) 2010, Mariano Alvira <mar@devl.org> and other contributors
* to the MC1322x project (http://mc1322x.devl.org)
* 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 libmc1322x: see http://mc1322x.devl.org
* for details.
*
* $Id: kbi.h,v 1.1 2010/06/10 14:55:39 maralvira Exp $
*/
#ifndef KBI_H
#define KBI_H
#define enable_irq_kbi(k) (set_bit(*CRM_WU_CNTL,(EXT_WU_IEN+k-4)))
#define disable_irq_kbi(k) (clear_bit(*CRM_WU_CNTL,(EXT_WU_IEN+k-4)))
#define kbi_evnt(k) (bit_is_set(*CRM_STATUS,(EXT_WU_EVT+k-4)))
#define kbi_edge(k) (set_bit(*CRM_WU_CNTL,(EXT_WU_EDGE+k-4)))
#define kbi_level(k) (clear_bit(*CRM_WU_CNTL,(EXT_WU_EDGE+k-4)))
#define kbi_pol_neg(k) (clear_bit(*CRM_WU_CNTL,(EXT_WU_POL+k-4)))
#define kbi_pol_pos(k) (set_bit(*CRM_WU_CNTL,(EXT_WU_POL+k-4)))
/* you have to clear these events by writing a one to them */
#define clear_kbi_evnt(k) (set_bit(*CRM_STATUS,(EXT_WU_EVT+k-4)))
#endif

View file

@ -0,0 +1,517 @@
/*
* Copyright (c) 2010, Mariano Alvira <mar@devl.org> and other contributors
* to the MC1322x project (http://mc1322x.devl.org)
* 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 libmc1322x: see http://mc1322x.devl.org
* for details.
*
* $Id: maca.h,v 1.1 2010/06/10 14:55:39 maralvira Exp $
*/
#ifndef _MACA_H_
#define _MACA_H_
#include <packet.h>
#include <types.h>
#include <utils.h>
/* maca initialization and on off routines */
void maca_init(void);
void maca_off(void);
void maca_on(void);
/* run periodically to make sure the maca is still doing right */
void check_maca(void);
/* maca configuration interface */
void set_power(uint8_t power);
void set_channel(uint8_t chan);
#define DEMOD_DCD 1 /* -96dBm, 22.2mA */
#define DEMOD_NCD 0 /* -100dBm, 24.2mA */
void set_demodulator_type(uint8_t demod);
/* set_fcs_mode(NO_FCS) to disable checksum filtering */
extern volatile uint8_t fcs_mode;
#define set_fcs_mode(x) fcs_mode = (x)
/* maca packet interface */
void tx_packet(volatile packet_t *p);
volatile packet_t* rx_packet(void);
volatile packet_t* get_free_packet(void);
void free_packet(volatile packet_t *p);
void free_all_packets(void);
extern volatile packet_t *rx_head, *tx_head;
extern volatile uint32_t maca_entry;
extern void maca_rx_callback(volatile packet_t *p) __attribute__((weak));
extern void maca_tx_callback(volatile packet_t *p) __attribute__((weak));
/* maca lowlevel routines */
/* most applications won't need to use them */
void reset_maca(void);
void init_phy(void);
void flyback_init(void);
void ResumeMACASync(void);
void radio_init(void);
uint32_t init_from_flash(uint32_t addr);
#define MAX_PACKET_SIZE (MAX_PAYLOAD_SIZE + 2) /* packet includes 2 bytes of checksum */
/* maca register and field defines */
#define MACA_BASE (0x80004000)
#define MACA_RESET ((volatile uint32_t *) (MACA_BASE+0x04))
#define MACA_RANDOM ((volatile uint32_t *) (MACA_BASE+0x08))
#define MACA_CONTROL ((volatile uint32_t *) (MACA_BASE+0x0c))
/* MACA_CONTROL bits and fields */
#define ISM 20
#define PRECOUNT 16 /* preamble reapeat counter */
#define PRECOUNT_MASK bit_mask(4,PRECOUNT)
#define RTSO 15 /* reset slot counter */
#define ROLE 13 /* set if PAN coordinator */
#define NOFC 12 /* set to disable FCS */
enum {
USE_FCS = 0,
NO_FCS = 1,
};
#define PRM 11 /* set for promiscuous mode */
#define REL 10 /* 1 for relative, 0 for absolute */
#define ASAP 9 /* 1 start now, 0 timer start */
#define BCN 8 /* 1 beacon only, 0 for a */
#define AUTO 7 /* 1 continuous rx, rx only once */
#define LFSR 6 /* 1 use polynomial for Turbolink */
#define TM 5
#define MODE 3
#define MODE_MASK bit_mask(2,MODE)
#define NO_CCA 0
#define NO_SLOT_CCA 1
#define SLOT_CCA 2
#define SEQUENCE 0
#define SEQUENCE_MASK bit_mask(3,SEQUENCE)
/* end of MACA_CONTROL bits and fields */
#define MACA_STATUS ((volatile uint32_t *) (MACA_BASE+0x10))
/* MACA_STATUS bits and fields */
#define STATUS_TIMEOUT 15
#define CRC 14
#define BUSY 13
#define OVR 12
#define CODE 0
#define CODE_MASK bit_mask(4,CODE)
/* status codes */
#define SUCCESS 0
#define CODE_TIMEOUT 1
#define CHANNEL_BUSY 2
#define CRC_FAILED 3
#define ABORTED 4
#define NO_ACK 5
#define NO_DATA 6
#define LATE_START 7
#define EXT_TIMEOUT 8
#define EXT_PND_TIMEOUT 9
#define PLL_UNLOCK 12
#define EXTERNAL_ABORT 13
#define NOT_COMPLETED 14
#define DMA_BUS_ERROR 15
/* end of MACA_CONTROL bits and fields */
#define MACA_FRMPND ((volatile uint32_t *) (MACA_BASE+0x14))
#define MACA_TMREN ((volatile uint32_t *) (MACA_BASE+0x40))
#define MACA_TMRDIS ((volatile uint32_t *) (MACA_BASE+0x44))
#define MACA_CLK ((volatile uint32_t *) (MACA_BASE+0x48))
#define MACA_STARTCLK ((volatile uint32_t *) (MACA_BASE+0x4c))
#define MACA_CPLCLK ((volatile uint32_t *) (MACA_BASE+0x50))
#define MACA_SFTCLK ((volatile uint32_t *) (MACA_BASE+0x54))
#define MACA_CLKOFFSET ((volatile uint32_t *) (MACA_BASE+0x58))
#define MACA_RELCLK ((volatile uint32_t *) (MACA_BASE+0x5c))
#define MACA_CPLTIM ((volatile uint32_t *) (MACA_BASE+0x60))
#define MACA_SLOTOFFSET ((volatile uint32_t *) (MACA_BASE+0x64))
#define MACA_TIMESTAMP ((volatile uint32_t *) (MACA_BASE+0x68))
#define MACA_DMARX ((volatile uint32_t *) (MACA_BASE+0x80))
#define MACA_DMATX ((volatile uint32_t *) (MACA_BASE+0x84))
#define MACA_DMAPOLL ((volatile uint32_t *) (MACA_BASE+0x88))
#define MACA_TXLEN ((volatile uint32_t *) (MACA_BASE+0x8c))
#define MACA_TXSEQNR ((volatile uint32_t *) (MACA_BASE+0x90))
#define MACA_SETRXLVL ((volatile uint32_t *) (MACA_BASE+0x94))
#define MACA_GETRXLVL ((volatile uint32_t *) (MACA_BASE+0x98))
#define MACA_IRQ ((volatile uint32_t *) (MACA_BASE+0xc0))
#define MACA_CLRIRQ ((volatile uint32_t *) (MACA_BASE+0xc4))
#define MACA_SETIRQ ((volatile uint32_t *) (MACA_BASE+0xc8))
#define MACA_MASKIRQ ((volatile uint32_t *) (MACA_BASE+0xcc))
#define MACA_MACPANID ((volatile uint32_t *) (MACA_BASE+0x100))
#define MACA_MAC16ADDR ((volatile uint32_t *) (MACA_BASE+0x104))
#define MACA_MAC64HI ((volatile uint32_t *) (MACA_BASE+0x108))
#define MACA_MAC64LO ((volatile uint32_t *) (MACA_BASE+0x10c))
#define MACA_FLTREJ ((volatile uint32_t *) (MACA_BASE+0x110))
#define MACA_CLKDIV ((volatile uint32_t *) (MACA_BASE+0x114))
#define MACA_WARMUP ((volatile uint32_t *) (MACA_BASE+0x118))
#define MACA_PREAMBLE ((volatile uint32_t *) (MACA_BASE+0x11c))
#define MACA_WHITESEED ((volatile uint32_t *) (MACA_BASE+0x120))
#define MACA_FRAMESYNC0 ((volatile uint32_t *) (MACA_BASE+0x124))
#define MACA_FRAMESYNC1 ((volatile uint32_t *) (MACA_BASE+0x128))
#define MACA_TXACKDELAY ((volatile uint32_t *) (MACA_BASE+0x140))
#define MACA_RXACKDELAY ((volatile uint32_t *) (MACA_BASE+0x144))
#define MACA_EOFDELAY ((volatile uint32_t *) (MACA_BASE+0x148))
#define MACA_CCADELAY ((volatile uint32_t *) (MACA_BASE+0x14c))
#define MACA_RXEND ((volatile uint32_t *) (MACA_BASE+0x150))
#define MACA_TXCCADELAY ((volatile uint32_t *) (MACA_BASE+0x154))
#define MACA_KEY3 ((volatile uint32_t *) (MACA_BASE+0x158))
#define MACA_KEY2 ((volatile uint32_t *) (MACA_BASE+0x15c))
#define MACA_KEY1 ((volatile uint32_t *) (MACA_BASE+0x160))
#define MACA_KEY0 ((volatile uint32_t *) (MACA_BASE+0x164))
#define MACA_OPTIONS ((volatile uint32_t *) (MACA_BASE+0x180))
/******************************************************************************/
/* everything under this comment is messy, needs cleaning, and will */
/* probably change in the future */
/******************************************************************************/
#define control_pre_count (7<<16) /* preamble reapeat counter */
#define control_rst_slot (1<<15) /* reset slot counter */
#define control_role (1<<13) /* set if PAN coordinator */
#define control_nofc (1<<12) /* set to disable FCS */
#define control_prm (1<<11) /* set for promiscuous mode */
#define control_relative (1<<10) /* 1 for relative, 0 for absolute */
#define control_asap (1<<9) /* 1 start now, 0 timer start */
#define control_bcn (1<<8) /* 1 beacon only, 0 for a */
#define control_auto (1<<7) /* 1 continuous rx, rx only once */
#define control_lfsr (1<<6) /* 1 use polynomial for Turbolink */
#define gMACA_Clock_DIV_c 95
//rom_base_adr equ 0x00000000 ; rom base address
//ram_base_adr equ 0x00400000 ; ram base address
//ram0_base_adr equ 0x00400000 ; ram0 base address (2K words = 8K
//bytes)
//ram1_base_adr equ 0x00402000 ; ram1 base address (6K words = 24K
//bytes)
//ram2_base_adr equ 0x00408000 ; ram2 base address (8K words = 32K
//bytes)
//ram3_base_adr equ 0x00410000 ; ram3 base address (8K words
enum {
cc_success = 0,
cc_timeout = 1,
cc_channel_busy = 2,
cc_crc_fail = 3,
cc_aborted = 4,
cc_no_ack = 5,
cc_no_data = 6,
cc_late_start = 7,
cc_ext_timeout = 8,
cc_ext_pnd_timeout = 9,
cc_nc1 = 10,
cc_nc2 = 11,
cc_nc3 = 12,
cc_cc_external_abort= 13,
cc_not_completed = 14,
cc_bus_error = 15
};
//control codes for mode bits
enum {
control_mode_no_cca = 0,
control_mode_non_slotted = (1<<3),
control_mode_slotted = (1<<4)
};
//control codes for sequence bits
enum {
control_seq_nop = 0,
control_seq_abort = 1,
control_seq_wait = 2,
control_seq_tx = 3,
control_seq_rx = 4,
control_seq_txpoll = 5,
control_seq_cca = 6,
control_seq_ed = 7
};
#define maca_version (*((volatile uint32_t *)(0x80004000)))
#define maca_reset (*((volatile uint32_t *)(0x80004004)))
#define maca_random (*((volatile uint32_t *)(0x80004008)))
#define maca_control (*((volatile uint32_t *)(0x8000400c)))
#define maca_status (*((volatile uint32_t *)(0x80004010)))
#define maca_frmpnd (*((volatile uint32_t *)(0x80004014)))
#define maca_edvalue (*((volatile uint32_t *)(0x8000401c)))
#define maca_tmren (*((volatile uint32_t *)(0x80004040)))
#define maca_tmrdis (*((volatile uint32_t *)(0x80004044)))
#define maca_clk (*((volatile uint32_t *)(0x80004048)))
#define maca_startclk (*((volatile uint32_t *)(0x8000404c)))
#define maca_cplclk (*((volatile uint32_t *)(0x80004050)))
#define maca_sftclk (*((volatile uint32_t *)(0x80004054)))
#define maca_clkoffset (*((volatile uint32_t *)(0x80004058)))
#define maca_relclk (*((volatile uint32_t *)(0x8000405c)))
#define maca_cpltim (*((volatile uint32_t *)(0x80004060)))
#define maca_slotoffset (*((volatile uint32_t *)(0x80004064)))
#define maca_timestamp (*((volatile uint32_t *)(0x80004068)))
#define maca_dmarx (*((volatile uint32_t *)(0x80004080)))
#define maca_dmatx (*((volatile uint32_t *)(0x80004084)))
#define maca_dmatxpoll (*((volatile uint32_t *)(0x80004088)))
#define maca_txlen (*((volatile uint32_t *)(0x8000408c)))
#define maca_txseqnr (*((volatile uint32_t *)(0x80004090)))
#define maca_setrxlvl (*((volatile uint32_t *)(0x80004094)))
#define maca_getrxlvl (*((volatile uint32_t *)(0x80004098)))
#define maca_irq (*((volatile uint32_t *)(0x800040c0)))
#define maca_clrirq (*((volatile uint32_t *)(0x800040c4)))
#define maca_setirq (*((volatile uint32_t *)(0x800040c8)))
#define maca_maskirq (*((volatile uint32_t *)(0x800040cc)))
#define maca_panid (*((volatile uint32_t *)(0x80004100)))
#define maca_addr16 (*((volatile uint32_t *)(0x80004104)))
#define maca_maca64hi (*((volatile uint32_t *)(0x80004108)))
#define maca_maca64lo (*((volatile uint32_t *)(0x8000410c)))
#define maca_fltrej (*((volatile uint32_t *)(0x80004110)))
#define maca_divider (*((volatile uint32_t *)(0x80004114)))
#define maca_warmup (*((volatile uint32_t *)(0x80004118)))
#define maca_preamble (*((volatile uint32_t *)(0x8000411c)))
#define maca_whiteseed (*((volatile uint32_t *)(0x80004120)))
#define maca_framesync (*((volatile uint32_t *)(0x80004124)))
#define maca_framesync2 (*((volatile uint32_t *)(0x80004128)))
#define maca_txackdelay (*((volatile uint32_t *)(0x80004140)))
#define maca_rxackdelay (*((volatile uint32_t *)(0x80004144)))
#define maca_eofdelay (*((volatile uint32_t *)(0x80004148)))
#define maca_ccadelay (*((volatile uint32_t *)(0x8000414c)))
#define maca_rxend (*((volatile uint32_t *)(0x80004150)))
#define maca_txccadelay (*((volatile uint32_t *)(0x80004154)))
#define maca_key3 (*((volatile uint32_t *)(0x80004158)))
#define maca_key2 (*((volatile uint32_t *)(0x80004158)))
#define maca_key1 (*((volatile uint32_t *)(0x80004158)))
#define maca_key0 (*((volatile uint32_t *)(0x80004158)))
typedef union maca_version_reg_tag
{
struct
{
uint32_t MINOR:8;
uint32_t RESERVED1:8;
uint32_t MAJOR:8;
uint32_t RESERVED2:8;
} Bits;
uint32_t Reg;
} maca_version_reg_t;
#define maca_version_reg_st ((maca_version_reg_t)(maca_version))
typedef union maca_reset_reg_tag
{
struct
{
uint32_t RESERVED:30;
uint32_t CLK_ON:1;
uint32_t RST:1;
} Bits;
uint32_t Reg;
} maca_reset_reg_t;
#define maca_reset_reg_st ((maca_reset_reg_t)(maca_reset))
/* typedef union maca_ctrl_reg_tag */
/* { */
/* struct */
/* { */
/* uint32_t RESERVED:11; */
/* uint32_t ISM:1; */
/* uint32_t PRE_COUNT:4; */
/* uint32_t RSTO:1; */
/* uint32_t RSV:1; */
/* uint32_t ROLE:1; */
/* uint32_t NOFC:1; */
/* uint32_t PRM:1; */
/* uint32_t rel:1; */
/* uint32_t ASAP:1; */
/* uint32_t BCN:1; */
/* uint32_t AUTO:1; */
/* uint32_t LFSR:1; */
/* uint32_t TM:1; */
/* uint32_t MODE:2; */
/* uint32_t SEQUENCE:3; */
/* } Bits; */
/* uint32_t Reg; */
/* } maca_ctrl_reg_t; */
#define maca_control_ism (1<<20)
#define maca_control_zigbee (~maca_control_ism)
#define maca_ctrl_reg_st ((maca_ctrl_reg_t *)(&maca_reset))
#define _set_maca_test_mode(x) (maca_ctrl_reg_st->Bits.TM = x)
#define _set_maca_sequence(x) (maca_ctrl_reg_st->Bits.SEQUENCE = x)
#define _set_maca_asap(x) (maca_ctrl_reg_st->Bits.ASAP = x)
#define MACA_CTRL_ZIGBEE_MODE (0)
#define MACA_CTRL_ISM_MODE (1)
#define MACA_CTRL_PRM_NORMAL_MODE (0)
#define MACA_CTRL_PRM_PROMISCUOUS_MODE (1)
#define MACA_CTRL_BCN_ALL (0)
#define MACA_CTRL_BCN_BEACON (1)
#define MACA_CTRL_TM_NORMAL (0)
#define MACA_CTRL_TM_TEST (1)
#define MACA_CTRL_MODE_NO_CCA (0)
#define MACA_CTRL_MODE_NON_SLOTTED (1)
#define MACA_CTRL_MODE_SLOTTED (2)
typedef enum maca_freq_chann_tag
{
SMAC_CHANN_11 = 0,
SMAC_CHANN_12,
SMAC_CHANN_13,
SMAC_CHANN_14,
SMAC_CHANN_15,
SMAC_CHANN_16,
SMAC_CHANN_17,
SMAC_CHANN_18,
SMAC_CHANN_19,
SMAC_CHANN_20,
SMAC_CHANN_21,
SMAC_CHANN_22,
SMAC_CHANN_23,
SMAC_CHANN_24,
SMAC_CHANN_25,
SMAC_CHANN_26,
MAX_SMAC_CHANNELS
} maca_freq_chann_t;
/* Sequence complete codes */
enum maca_complete_code {
maca_cc_success = 0,
maca_cc_timeout = 1,
maca_cc_channel_busy = 2,
maca_cc_crc_fail = 3,
maca_cc_aborted = 4,
maca_cc_no_ack = 5,
maca_cc_no_data = 6,
maca_cc_late_start = 7,
maca_cc_ext_timeout = 8,
maca_cc_ext_pnd_timeout = 9,
maca_cc_nc1 = 10,
maca_cc_nc2 = 11,
maca_cc_nc3 = 12,
maca_cc_cc_external_abort= 13,
maca_cc_not_completed = 14,
maca_cc_bus_error = 15
};
/* control sequence codes */
enum maca_ctrl_seq {
maca_ctrl_seq_nop = 0,
maca_ctrl_seq_abort = 1,
maca_ctrl_seq_wait = 2,
maca_ctrl_seq_tx = 3,
maca_ctrl_seq_rx = 4,
maca_ctrl_seq_txpoll = 5,
maca_ctrl_seq_cca = 6,
maca_ctrl_seq_ed = 7
};
/* transmission modes */
enum maca_ctrl_modes {
maca_ctrl_mode_no_cca = 0,
maca_ctrl_mode_non_slotted_csma_ca = 1,
maca_ctrl_mode_slotted_csma_ca = 2,
};
/* MACA_CONTROL bits */
enum maca_ctrl_bits {
maca_ctrl_seq = 0, /* 3 bits */
maca_ctrl_mode = 3, /* 2 bits */
maca_ctrl_tm = 5,
maca_ctrl_lfsr = 6,
maca_ctrl_auto = 7,
maca_ctrl_bcn = 8,
maca_ctrl_asap = 9,
maca_ctrl_rel = 10,
maca_ctrl_prm = 11,
maca_ctrl_nofc = 12,
maca_ctrl_role = 13,
/* 14 reserved */
maca_ctrl_rsto = 15,
maca_ctrl_pre_count = 16, /* 4 bits */
maca_ctrl_ism = 20,
};
/* MACA_IRQ bits */
enum maca_irqs {
maca_irq_acpl = 0,
maca_irq_poll = 1,
maca_irq_di = 2,
maca_irq_wu = 3,
maca_irq_rst = 4,
maca_irq_lvl = 9,
maca_irq_sftclk = 10,
maca_irq_flt = 11,
maca_irq_crc = 12,
maca_irq_cm = 13,
maca_irq_sync = 14,
maca_irq_strt = 15,
};
/* MACA_RESET bits */
enum maca_reset_bits {
maca_reset_rst = 0,
maca_reset_clkon = 1,
};
/* MACA_TMREN bits */
enum maca_tmren_bits {
maca_tmren_strt = 0,
maca_tmren_cpl = 1,
maca_tmren_sft = 2,
};
enum maca_status_bits {
maca_status_ovr = 12,
maca_status_busy = 13,
maca_status_crc = 14,
maca_status_to = 15,
};
#define action_complete_irq() bit_is_set(*MACA_IRQ,maca_irq_acpl)
#define filter_failed_irq() bit_is_set(*MACA_IRQ,maca_irq_flt)
#define checksum_failed_irq() bit_is_set(*MACA_IRQ,maca_irq_crc)
#define data_indication_irq() bit_is_set(*MACA_IRQ,maca_irq_di)
#define softclock_irq() bit_is_set(*MACA_IRQ,maca_irq_sftclk)
#define poll_irq() bit_is_set(*MACA_IRQ,maca_irq_poll)
#define status_is_not_completed() ((*MACA_STATUS & 0xffff) == maca_cc_not_completed)
#define status_is_success() ((*MACA_STATUS & 0xffff) == maca_cc_success)
#define SMAC_MACA_CNTL_INIT_STATE ( control_prm | control_nofc | control_mode_non_slotted )
#define MACA_WRITE(reg, src) (reg = src)
#define MACA_READ(reg) reg
#endif // _MACA_H_

View file

@ -0,0 +1,51 @@
/*
* Copyright (c) 2010, Mariano Alvira <mar@devl.org> and other contributors
* to the MC1322x project (http://mc1322x.devl.org)
* 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 libmc1322x: see http://mc1322x.devl.org
* for details.
*
* $Id: mc1322x.h,v 1.1 2010/06/10 14:55:39 maralvira Exp $
*/
#ifndef MC1322X_H
#define MC1322X_H
#include "types.h"
#include "isr.h"
#include "gpio.h"
#include "crm.h"
#include "nvm.h"
#include "tmr.h"
#include "kbi.h"
#include "maca.h"
#include "packet.h"
#include "uart1.h"
#include "utils.h"
#endif

View file

@ -0,0 +1,82 @@
/*
* Copyright (c) 2010, Mariano Alvira <mar@devl.org> and other contributors
* to the MC1322x project (http://mc1322x.devl.org)
* 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 libmc1322x: see http://mc1322x.devl.org
* for details.
*
* $Id: nvm.h,v 1.1 2010/06/10 14:55:39 maralvira Exp $
*/
#ifndef NVM_H
#define NVM_H
#include "types.h"
typedef enum
{
gNvmType_NoNvm_c,
gNvmType_SST_c,
gNvmType_ST_c,
gNvmType_ATM_c,
gNvmType_Max_c
} nvmType_t;
typedef enum
{
gNvmErrNoError_c = 0,
gNvmErrInvalidInterface_c,
gNvmErrInvalidNvmType_c,
gNvmErrInvalidPointer_c,
gNvmErrWriteProtect_c,
gNvmErrVerifyError_c,
gNvmErrAddressSpaceOverflow_c,
gNvmErrBlankCheckError_c,
gNvmErrRestrictedArea_c,
gNvmErrMaxError_c
} nvmErr_t;
typedef enum
{
gNvmInternalInterface_c,
gNvmExternalInterface_c,
gNvmInterfaceMax_c
} nvmInterface_t;
/* ROM code seems to be THUMB */
/* need to be in a THUMB block before calling them */
extern nvmErr_t (*nvm_detect)(nvmInterface_t nvmInterface,nvmType_t* pNvmType);
extern nvmErr_t (*nvm_read)(nvmInterface_t nvmInterface , nvmType_t nvmType , void *pDest, uint32_t address, uint32_t numBytes);
extern nvmErr_t (*nvm_write)(nvmInterface_t nvmInterface, nvmType_t nvmType ,void *pSrc, uint32_t address, uint32_t numBytes);
/* sector bit field selects which sector to erase */
/* SST flash has 32 sectors 4096 bytes each */
/* bit 0 is the first sector, bit 31 is the last */
extern nvmErr_t (*nvm_erase)(nvmInterface_t nvmInterface, nvmType_t nvmType ,uint32_t sectorBitfield);
extern void(*nvm_setsvar)(uint32_t zero_for_awesome);
#endif //NVM_H

View file

@ -0,0 +1,64 @@
/*
* Copyright (c) 2010, Mariano Alvira <mar@devl.org> and other contributors
* to the MC1322x project (http://mc1322x.devl.org)
* 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 libmc1322x: see http://mc1322x.devl.org
* for details.
*
* $Id: packet.h,v 1.1 2010/06/10 14:55:39 maralvira Exp $
*/
#ifndef PACKET_H
#define PACKET_H
/* does not include 2 byte FCS checksum */
#ifndef MAX_PAYLOAD_SIZE
#define MAX_PAYLOAD_SIZE 125
#endif
#define PACKET_STATS 0
struct packet {
uint8_t length; /* does not include FCS checksum */
volatile struct packet * left;
volatile struct packet * right;
/* offset into data for first byte of the packet payload */
/* On TX this should be 0 */
/* On RX this should be 1 since the maca puts the length as the first byte*/
uint8_t offset;
#if PACKET_STATS
uint8_t seen;
uint8_t post_tx;
uint8_t get_free;
uint8_t rxd;
#endif
uint8_t data[MAX_PAYLOAD_SIZE+2+1]; /* +2 for FCS; + 1 since maca returns the length as the first byte */
};
typedef struct packet packet_t;
#endif

View file

@ -0,0 +1,127 @@
/*
* Copyright (c) 2010, Mariano Alvira <mar@devl.org> and other contributors
* to the MC1322x project (http://mc1322x.devl.org)
* 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 libmc1322x: see http://mc1322x.devl.org
* for details.
*
* $Id: tmr.h,v 1.1 2010/06/10 14:55:39 maralvira Exp $
*/
#include "utils.h"
/* Timer registers are all 16-bit wide with 16-bit access only */
#define TMR_OFFSET (0x20)
#define TMR_BASE (0x80007000)
#define TMR0_BASE (TMR_BASE)
#define TMR1_BASE (TMR_BASE + TMR_OFFSET*1)
#define TMR2_BASE (TMR_BASE + TMR_OFFSET*2)
#define TMR3_BASE (TMR_BASE + TMR_OFFSET*3)
#define TMR_REGOFF_COMP1 (0x0)
#define TMR_REGOFF_COMP2 (0x2)
#define TMR_REGOFF_CAPT (0x4)
#define TMR_REGOFF_LOAD (0x6)
#define TMR_REGOFF_HOLD (0x8)
#define TMR_REGOFF_CNTR (0xa)
#define TMR_REGOFF_CTRL (0xc)
#define TMR_REGOFF_SCTRL (0xe)
#define TMR_REGOFF_CMPLD1 (0x10)
#define TMR_REGOFF_CMPLD2 (0x12)
#define TMR_REGOFF_CSCTRL (0x14)
#define TMR_REGOFF_ENBL (0x1e)
/* one enable register to rule them all */
#define TMR_ENBL ((volatile uint16_t *) (TMR0_BASE + TMR_REGOFF_ENBL))
/* Timer 0 registers */
#define TMR0_COMP1 ((volatile uint16_t *) (TMR0_BASE + TMR_REGOFF_COMP1))
#define TMR0_COMP_UP TMR0_COMP1
#define TMR0_COMP2 (TMR0_BASE + TMR_REGOFF_COMP2)
#define TMR0_COMP_DOWN TMR0_COMP2
#define TMR0_CAPT ((volatile uint16_t *) (TMR0_BASE + TMR_REGOFF_CAPT))
#define TMR0_LOAD ((volatile uint16_t *) (TMR0_BASE + TMR_REGOFF_LOAD))
#define TMR0_HOLD ((volatile uint16_t *) (TMR0_BASE + TMR_REGOFF_HOLD))
#define TMR0_CNTR ((volatile uint16_t *) (TMR0_BASE + TMR_REGOFF_CTRL))
#define TMR0_CTRL ((volatile uint16_t *) (TMR0_BASE + TMR_REGOFF_CTRL))
#define TMR0_SCTRL ((volatile uint16_t *) (TMR0_BASE + TMR_REGOFF_SCTRL))
#define TMR0_CMPLD1 ((volatile uint16_t *) (TMR0_BASE + TMR_REGOFF_CMPLD1))
#define TMR0_CMPLD2 ((volatile uint16_t *) (TMR0_BASE + TMR_REGOFF_CMPLD2))
#define TMR0_CSCTRL ((volatile uint16_t *) (TMR0_BASE + TMR_REGOFF_CSCTRL))
/* Timer 1 registers */
#define TMR1_COMP1 ((volatile uint16_t *) (TMR1_BASE + TMR_REGOFF_COMP1))
#define TMR1_COMP_UP TMR1_COMP1
#define TMR1_COMP2 ((volatile uint16_t *) (TMR1_BASE + TMR_REGOFF_COMP2))
#define TMR1_COMP_DOWN TMR1_COMP2
#define TMR1_CAPT ((volatile uint16_t *) (TMR1_BASE + TMR_REGOFF_CAPT))
#define TMR1_LOAD ((volatile uint16_t *) (TMR1_BASE + TMR_REGOFF_LOAD))
#define TMR1_HOLD ((volatile uint16_t *) (TMR1_BASE + TMR_REGOFF_HOLD))
#define TMR1_CNTR ((volatile uint16_t *) (TMR1_BASE + TMR_REGOFF_CTRL))
#define TMR1_CTRL ((volatile uint16_t *) (TMR1_BASE + TMR_REGOFF_CTRL))
#define TMR1_SCTRL ((volatile uint16_t *) (TMR1_BASE + TMR_REGOFF_SCTRL))
#define TMR1_CMPLD1 ((volatile uint16_t *) (TMR1_BASE + TMR_REGOFF_CMPLD1))
#define TMR1_CMPLD2 ((volatile uint16_t *) (TMR1_BASE + TMR_REGOFF_CMPLD2))
#define TMR1_CSCTRL ((volatile uint16_t *) (TMR1_BASE + TMR_REGOFF_CSCTRL))
/* Timer 2 registers */
#define TMR2_COMP1 ((volatile uint16_t *) (TMR2_BASE + TMR_REGOFF_COMP1))
#define TMR2_COMP_UP TMR2_COMP1
#define TMR2_COMP2 ((volatile uint16_t *) (TMR2_BASE + TMR_REGOFF_COMP2))
#define TMR2_COMP_DOWN TMR2_COMP2
#define TMR2_CAPT ((volatile uint16_t *) (TMR2_BASE + TMR_REGOFF_CAPT))
#define TMR2_LOAD ((volatile uint16_t *) (TMR2_BASE + TMR_REGOFF_LOAD))
#define TMR2_HOLD ((volatile uint16_t *) (TMR2_BASE + TMR_REGOFF_HOLD))
#define TMR2_CNTR ((volatile uint16_t *) (TMR2_BASE + TMR_REGOFF_CTRL))
#define TMR2_CTRL ((volatile uint16_t *) (TMR2_BASE + TMR_REGOFF_CTRL))
#define TMR2_SCTRL ((volatile uint16_t *) (TMR2_BASE + TMR_REGOFF_SCTRL))
#define TMR2_CMPLD1 ((volatile uint16_t *) (TMR2_BASE + TMR_REGOFF_CMPLD1))
#define TMR2_CMPLD2 ((volatile uint16_t *) (TMR2_BASE + TMR_REGOFF_CMPLD2))
#define TMR2_CSCTRL ((volatile uint16_t *) (TMR2_BASE + TMR_REGOFF_CSCTRL))
/* Timer 3 registers */
#define TMR3_COMP1 ((volatile uint16_t *) (TMR3_BASE + TMR_REGOFF_COMP1))
#define TMR3_COMP_UP TMR3_COMP1
#define TMR3_COMP2 ((volatile uint16_t *) (TMR3_BASE + TMR_REGOFF_COMP2))
#define TMR3_COMP_DOWN TMR3_COMP2
#define TMR3_CAPT ((volatile uint16_t *) (TMR3_BASE + TMR_REGOFF_CAPT))
#define TMR3_LOAD ((volatile uint16_t *) (TMR3_BASE + TMR_REGOFF_LOAD))
#define TMR3_HOLD ((volatile uint16_t *) (TMR3_BASE + TMR_REGOFF_HOLD))
#define TMR3_CNTR ((volatile uint16_t *) (TMR3_BASE + TMR_REGOFF_CTRL))
#define TMR3_CTRL ((volatile uint16_t *) (TMR3_BASE + TMR_REGOFF_CTRL))
#define TMR3_SCTRL ((volatile uint16_t *) (TMR3_BASE + TMR_REGOFF_SCTRL))
#define TMR3_CMPLD1 ((volatile uint16_t *) (TMR3_BASE + TMR_REGOFF_CMPLD1))
#define TMR3_CMPLD2 ((volatile uint16_t *) (TMR3_BASE + TMR_REGOFF_CMPLD2))
#define TMR3_CSCTRL ((volatile uint16_t *) (TMR3_BASE + TMR_REGOFF_CSCTRL))
#define TCF 15
#define TCF1 4
#define TCF2 5
#define TMR(num, reg) CAT2(TMR,num,_##reg)

View file

@ -0,0 +1,48 @@
/*
* Copyright (c) 2010, Mariano Alvira <mar@devl.org> and other contributors
* to the MC1322x project (http://mc1322x.devl.org)
* 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 libmc1322x: see http://mc1322x.devl.org
* for details.
*
* $Id: types.h,v 1.1 2010/06/10 14:55:39 maralvira Exp $
*/
#ifndef _TYPES_H
#define _TYPES_H
typedef signed char int8_t;
typedef unsigned char uint8_t;
typedef signed short int16_t;
typedef unsigned short uint16_t;
typedef signed int int32_t;
typedef unsigned int uint32_t;
typedef signed long long int int64_t;
typedef unsigned long long int uint64_t;
#endif

View file

@ -0,0 +1,80 @@
/*
* Copyright (c) 2010, Mariano Alvira <mar@devl.org> and other contributors
* to the MC1322x project (http://mc1322x.devl.org)
* 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 libmc1322x: see http://mc1322x.devl.org
* for details.
*
* $Id: uart1.h,v 1.1 2010/06/10 14:55:39 maralvira Exp $
*/
#ifndef UART1_H
#define UART1_H
#include <types.h>
#define UCON (0)
/* UCON bits */
#define UCON_SAMP 10
#define UCON_SAMP_8X 0
#define UCON_SAMP_16X 1
#define USTAT (0x04)
#define UDATA (0x08)
#define URXCON (0x0c)
#define UTXCON (0x10)
#define UCTS (0x14)
#define UBRCNT (0x18)
#define UART1_BASE (0x80005000)
#define UART2_BASE (0x8000b000)
#define UART1_UCON ((volatile uint32_t *) ( UART1_BASE + UCON ))
#define UART1_USTAT ((volatile uint32_t *) ( UART1_BASE + USTAT ))
#define UART1_UDATA ((volatile uint32_t *) ( UART1_BASE + UDATA ))
#define UART1_URXCON ((volatile uint32_t *) ( UART1_BASE + URXCON ))
#define UART1_UTXCON ((volatile uint32_t *) ( UART1_BASE + UTXCON ))
#define UART1_UCTS ((volatile uint32_t *) ( UART1_BASE + UCTS ))
#define UART1_UBRCNT ((volatile uint32_t *) ( UART1_BASE + UBRCNT ))
#define UART2_UCON ((volatile uint32_t *) ( UART2_BASE + UCON ))
#define UART2_USTAT ((volatile uint32_t *) ( UART2_BASE + USTAT ))
#define UART2_UDATA ((volatile uint32_t *) ( UART2_BASE + UDATA ))
#define UART2_URXCON ((volatile uint32_t *) ( UART2_BASE + URXCON ))
#define UART2_UTXCON ((volatile uint32_t *) ( UART2_BASE + UTXCON ))
#define UART2_UCTS ((volatile uint32_t *) ( UART2_BASE + UCTS ))
#define UART2_UBRCNT ((volatile uint32_t *) ( UART2_BASE + UBRCNT ))
extern volatile uint32_t u1_head, u1_tail;
void uart1_putc(char c);
#define uart1_can_get() (*UART1_URXCON > 0)
uint8_t uart1_getc(void);
#endif

View file

@ -0,0 +1,58 @@
/*
* Copyright (c) 2010, Mariano Alvira <mar@devl.org> and other contributors
* to the MC1322x project (http://mc1322x.devl.org)
* 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 libmc1322x: see http://mc1322x.devl.org
* for details.
*
* $Id: utils.h,v 1.1 2010/06/10 14:55:39 maralvira Exp $
*/
#ifndef UTILS_H
#define UTILS_H
#define mem32(x) ((volatile uint32_t *)(x))
#define mem16(x) ((volatile uint16_t *)(x))
#define CAT2(x, y, z) x##y##z
#define STR(x) #x
#define STR2(x) STR(x)
#define bit(bit) (1 << bit)
#define bit_is_set(val, bit) (((val & (1 << bit)) >> bit) == 1)
#define clear_bit(val, bit) (val = (val & ~(1 << bit)))
#define set_bit(val, bit) (val = (val | (1 << bit)))
#define ones(num) ( (1ULL << num) - 1 )
#define bit_mask(length, shift) (ones(length) << shift)
#define get_field(val, field) ((val & field##_MASK) >> field)
//#define bitfield(name, length, shift) ( #define #name length #define #name##_MASK bit_mask(length, shift))
#define bitfield(name, length, shift) ( define #name length )
#endif /* UTILS_H */

1213
cpu/mc1322x/lib/maca.c Normal file

File diff suppressed because it is too large Load diff

57
cpu/mc1322x/lib/nvm.c Normal file
View file

@ -0,0 +1,57 @@
/*
* Copyright (c) 2010, Mariano Alvira <mar@devl.org> and other contributors
* to the MC1322x project (http://mc1322x.devl.org)
* 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 libmc1322x: see http://mc1322x.devl.org
* for details.
*
* $Id: nvm.c,v 1.1 2010/06/10 14:55:39 maralvira Exp $
*/
#include "nvm.h"
nvmErr_t (*nvm_detect)
(nvmInterface_t nvmInterface,nvmType_t* pNvmType)
= (void *) 0x00006cb9;
nvmErr_t (*nvm_read)
(nvmInterface_t nvmInterface , nvmType_t nvmType , void *pDest, uint32_t address, uint32_t numBytes)
= (void *) 0x00006d69;
nvmErr_t (*nvm_write)
(nvmInterface_t nvmInterface, nvmType_t nvmType ,void *pSrc, uint32_t address, uint32_t numBytes)
= (void *) 0x00006ec5;
nvmErr_t (*nvm_erase)
(nvmInterface_t nvmInterface, nvmType_t nvmType ,uint32_t sectorBitfield)
= (void*) 0x00006e05;
void(*nvm_setsvar)
(uint32_t zero_for_awesome)
= (void *)0x00007085;

77
cpu/mc1322x/lib/uart1.c Normal file
View file

@ -0,0 +1,77 @@
/*
* Copyright (c) 2010, Mariano Alvira <mar@devl.org> and other contributors
* to the MC1322x project (http://mc1322x.devl.org)
* 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 libmc1322x: see http://mc1322x.devl.org
* for details.
*
* $Id: uart1.c,v 1.1 2010/06/10 14:55:39 maralvira Exp $
*/
#include <mc1322x.h>
#include <types.h>
volatile char u1_tx_buf[1024];
volatile uint32_t u1_head, u1_tail;
void uart1_isr(void) {
while( *UART1_UTXCON != 0 ) {
if (u1_head == u1_tail) {
disable_irq(UART1);
return;
}
*UART1_UDATA = u1_tx_buf[u1_tail];
u1_tail++;
if (u1_tail >= sizeof(u1_tx_buf))
u1_tail = 0;
}
}
void uart1_putc(char c) {
/* disable UART1 since */
/* UART1 isr modifies u1_head and u1_tail */
disable_irq(UART1);
if( (u1_head == u1_tail) &&
(*UART1_UTXCON != 0)) {
*UART1_UDATA = c;
} else {
u1_tx_buf[u1_head] = c;
u1_head += 1;
if (u1_head >= sizeof(u1_tx_buf))
u1_head = 0;
if (u1_head == u1_tail) /* drop chars when no room */
return;
enable_irq(UART1);
}
}
uint8_t uart1_getc(void) {
while(uart1_can_get() == 0) { continue; }
return *UART1_UDATA;
}

View file

@ -0,0 +1,44 @@
MC1322X := ..
# all off the common objects for each target
# a COBJ is made for EACH board and goes the obj_$(BOARD)_board directory
# board specific code is OK in these files
COBJS := tests.o put.o
# all of the target programs to build
TARGETS := blink-red blink-green blink-blue blink-white blink-allio \
uart1-loopback \
tmr tmr-ints \
sleep \
printf
# these targets are built with space reserved for variables needed by ROM services
# this space is initialized with a rom call to rom_data_init
TARGETS_WITH_ROM_VARS := nvm-read nvm-write romimg flasher \
rftest-rx rftest-tx \
per
##################################################
# you shouldn't need to edit anything below here #
##################################################
# This Makefile includes the default rule at the top
# it needs to be included first
-include $(MC1322X)/Makefile.include
# this rule will become the default_goal if
# $(MC1322X)/Makefile.include doesn't exist it will try to update the
# submodule, check if $(MC1322X) exists, and if it does
# try make again
submodule:
git submodule update --init
if [ ! -d $(MC1322X) ] ; then echo "*** cannot find MC1322X directory $(MC1322X)" ; exit 2; fi
$(MAKE)
.PHONY: submodule

View file

@ -0,0 +1,66 @@
/*
* Copyright (c) 2010, Mariano Alvira <mar@devl.org> and other contributors
* to the MC1322x project (http://mc1322x.devl.org)
* 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 libmc1322x: see http://mc1322x.devl.org
* for details.
*
* $Id: blink-allio.c,v 1.1 2010/06/10 14:55:39 maralvira Exp $
*/
#include <mc1322x.h>
#include <board.h>
#define DELAY 400000
void main(void) {
*GPIO_FUNC_SEL0 = 0xffffffff;
*GPIO_FUNC_SEL1 = 0xffffffff;
*GPIO_FUNC_SEL2 = 0xffffffff;
*GPIO_FUNC_SEL3 = 0xffffffff;
*GPIO_PAD_DIR0 = 0xffffffff;
*GPIO_PAD_DIR1 = 0xffffffff;
volatile uint32_t i;
while(1) {
*GPIO_DATA0 = 0xffffffff;
*GPIO_DATA1 = 0xffffffff;
for(i=0; i<DELAY; i++) { continue; }
*GPIO_DATA0 = 0x00000000;
*GPIO_DATA1 = 0x00000000;
for(i=0; i<DELAY; i++) { continue; }
};
}

View file

@ -0,0 +1,61 @@
/*
* Copyright (c) 2010, Mariano Alvira <mar@devl.org> and other contributors
* to the MC1322x project (http://mc1322x.devl.org)
* 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 libmc1322x: see http://mc1322x.devl.org
* for details.
*
* $Id: blink-blue.c,v 1.1 2010/06/10 14:55:39 maralvira Exp $
*/
#include <mc1322x.h>
#include <board.h>
#define DELAY 400000
#define LED (1ULL << LED_BLUE)
void main(void) {
volatile uint32_t i;
gpio_pad_dir(LED);
while(1) {
gpio_data(LED);
for(i=0; i<DELAY; i++) { continue; }
gpio_data(0);
for(i=0; i<DELAY; i++) { continue; }
};
}

View file

@ -0,0 +1,61 @@
/*
* Copyright (c) 2010, Mariano Alvira <mar@devl.org> and other contributors
* to the MC1322x project (http://mc1322x.devl.org)
* 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 libmc1322x: see http://mc1322x.devl.org
* for details.
*
* $Id: blink-green.c,v 1.1 2010/06/10 14:55:39 maralvira Exp $
*/
#include <mc1322x.h>
#include <board.h>
#define DELAY 400000
#define LED (1ULL << LED_GREEN)
void main(void) {
volatile uint32_t i;
gpio_pad_dir(LED);
while(1) {
gpio_data(LED);
for(i=0; i<DELAY; i++) { continue; }
gpio_data(0);
for(i=0; i<DELAY; i++) { continue; }
};
}

View file

@ -0,0 +1,61 @@
/*
* Copyright (c) 2010, Mariano Alvira <mar@devl.org> and other contributors
* to the MC1322x project (http://mc1322x.devl.org)
* 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 libmc1322x: see http://mc1322x.devl.org
* for details.
*
* $Id: blink-red.c,v 1.1 2010/06/10 14:55:39 maralvira Exp $
*/
#include <mc1322x.h>
#include <board.h>
#define DELAY 400000
#define LED (1ULL << LED_RED)
void main(void) {
volatile uint32_t i;
gpio_pad_dir(LED);
while(1) {
gpio_data(LED);
for(i=0; i<DELAY; i++) { continue; }
gpio_data(0);
for(i=0; i<DELAY; i++) { continue; }
};
}

View file

@ -0,0 +1,63 @@
/*
* Copyright (c) 2010, Mariano Alvira <mar@devl.org> and other contributors
* to the MC1322x project (http://mc1322x.devl.org)
* 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 libmc1322x: see http://mc1322x.devl.org
* for details.
*
* $Id: blink-white.c,v 1.1 2010/06/10 14:55:39 maralvira Exp $
*/
#include <mc1322x.h>
#include <board.h>
#include "led.h"
#define DELAY 400000
#define LED LED_WHITE
void main(void) {
volatile uint32_t i;
gpio_pad_dir(LED);
while(1) {
gpio_data(LED);
for(i=0; i<DELAY; i++) { continue; }
gpio_data(0);
for(i=0; i<DELAY; i++) { continue; }
};
}

View file

@ -0,0 +1,75 @@
/*
* Copyright (c) 2010, Mariano Alvira <mar@devl.org> and other contributors
* to the MC1322x project (http://mc1322x.devl.org)
* 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 libmc1322x: see http://mc1322x.devl.org
* for details.
*
* $Id: config.h,v 1.1 2010/06/10 14:55:39 maralvira Exp $
*/
#ifndef CONFIG_H
#define CONFIG_H
/* Baud rate */
#define MOD 9999
/* 230400 bps, INC=767, MOD=9999, 24Mhz 16x samp */
/* 115200 bps, INC=767, MOD=9999, 24Mhz 8x samp */
#define INC 767
/* 921600 bps, MOD=9999, 24Mhz 16x samp */
//#define INC 3071
#define SAMP UCON_SAMP_8X
//#define SAMP UCON_SAMP_16X
/* use uart1 for console */
#define uart_init uart1_init
/* nvm-read */
#define READ_ADDR 0x1E000
#define READ_NBYTES 8
/* nvm-write */
#define WRITE_NBYTES 8
#define WRITE_ADDR 0x1e000
#define WRITEVAL0 0xdeadbeef
#define WRITEVAL1 0xdeadbeef
/* romimg */
#define DUMP_BASE 0x00000000
#define DUMP_LEN 0x00014000
/* flasher */
/* if both BOOT_OK and BOOT_SECURE are 0 then flash image will not be bootable */
/* if both are 1 then flash image will be secure */
#define BOOT_OK 1
#define BOOT_SECURE 0
/* sleep */
#undef USE_32KHZ /* board should have a HAS_32KHZ define */
#endif

248
cpu/mc1322x/tests/flasher.c Normal file
View file

@ -0,0 +1,248 @@
/*
* Copyright (c) 2010, Mariano Alvira <mar@devl.org> and other contributors
* to the MC1322x project (http://mc1322x.devl.org)
* 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 libmc1322x: see http://mc1322x.devl.org
* for details.
*
* $Id: flasher.c,v 1.1 2010/06/10 14:55:39 maralvira Exp $
*/
#include <mc1322x.h>
#include <board.h>
#include "tests.h"
#include "config.h"
#define DEBUG 1
#if DEBUG
#define dbg_putchr(...) putchr(__VA_ARGS__)
#define dbg_putstr(...) putstr(__VA_ARGS__)
#define dbg_put_hex(...) put_hex(__VA_ARGS__)
#define dbg_put_hex16(...) put_hex16(__VA_ARGS__)
#define dbg_put_hex32(...) put_hex32(__VA_ARGS__)
#else
#define dbg_putchr(...)
#define dbg_putstr(...)
#define dbg_put_hex(...)
#define dbg_put_hex16(...)
#define dbg_put_hex32(...)
#endif
uint8_t getc(void)
{
volatile uint8_t c;
while(*UART1_URXCON == 0);
c = *UART1_UDATA;
return c;
}
void flushrx(void);
uint32_t to_u32(volatile uint32_t *c);
enum parse_states {
SCAN_X,
READ_CHARS,
PROCESS,
MAX_STATE,
};
void main(void) {
nvmType_t type=0;
nvmErr_t err;
volatile uint8_t c;
volatile uint32_t i;
volatile uint32_t buf[4];
volatile uint32_t len=0;
volatile uint32_t state = SCAN_X;
volatile uint32_t addr,data;
uart_init(INC, MOD, SAMP);
disable_irq(UART1);
vreg_init();
dbg_putstr("Detecting internal nvm\n\r");
err = nvm_detect(gNvmInternalInterface_c, &type);
dbg_putstr("nvm_detect returned: 0x");
dbg_put_hex(err);
dbg_putstr(" type is: 0x");
dbg_put_hex32(type);
dbg_putstr("\n\r");
/* erase the flash */
err = nvm_erase(gNvmInternalInterface_c, type, 0x4fffffff);
dbg_putstr("nvm_erase returned: 0x");
dbg_put_hex(err);
dbg_putstr("\n\r");
dbg_putstr(" type is: 0x");
dbg_put_hex32(type);
dbg_putstr("\n\r");
/* say we are ready */
len = 0;
putstr("ready");
flushrx();
/* read the length */
for(i=0; i<4; i++) {
c = uart1_getc();
/* bail if the first byte of the length is zero */
len += (c<<(i*8));
}
dbg_putstr("len: ");
dbg_put_hex32(len);
dbg_putstr("\n\r");
/* write the OKOK magic */
#if BOOT_OK
((uint8_t *)buf)[0] = 'O'; ((uint8_t *)buf)[1] = 'K'; ((uint8_t *)buf)[2] = 'O'; ((uint8_t *)buf)[3] = 'K';
#elif BOOT_SECURE
((uint8_t *)buf)[0] = 'S'; ((uint8_t *)buf)[1] = 'E'; ((uint8_t *)buf)[2] = 'C'; ((uint8_t *)buf)[3] = 'U';
#else
((uint8_t *)buf)[0] = 'N'; ((uint8_t *)buf)[1] = 'O'; ((uint8_t *)buf)[2] = 'N'; ((uint8_t *)buf)[3] = 'O';
#endif
dbg_putstr(" type is: 0x");
dbg_put_hex32(type);
dbg_putstr("\n\r");
err = nvm_write(gNvmInternalInterface_c, type, (uint8_t *)buf, 0, 4);
dbg_putstr("nvm_write returned: 0x");
dbg_put_hex(err);
dbg_putstr("\n\r");
/* write the length */
err = nvm_write(gNvmInternalInterface_c, type, (uint8_t *)&len, 4, 4);
/* read a byte, write a byte */
/* byte at a time will make this work as a contiki process better */
/* for OTAP */
for(i=0; i<len; i++) {
c = getc();
err = nvm_write(gNvmInternalInterface_c, type, (uint8_t *)&c, 8+i, 1);
}
putstr("flasher done\n\r");
state = SCAN_X; addr=0;
while((c=getc())) {
if(state == SCAN_X) {
/* read until we see an 'x' */
if(c==0) { break; }
if(c!='x'){ continue; }
/* go to read_chars once we have an 'x' */
state = READ_CHARS;
i = 0;
}
if(state == READ_CHARS) {
/* read all the chars up to a ',' */
((uint8_t *)buf)[i++] = c;
/* after reading a ',' */
/* goto PROCESS state */
if((c == ',') || (c == 0)) { state = PROCESS; }
}
if(state == PROCESS) {
if(addr==0) {
/*interpret the string as the starting address */
addr = to_u32(buf);
} else {
/* string is data to write */
data = to_u32(buf);
putstr("writing addr ");
put_hex32(addr);
putstr(" data ");
put_hex32(data);
putstr("\n\r");
err = nvm_write(gNvmInternalInterface_c, 1, (uint8_t *)&data, addr, 4);
addr += 4;
}
/* look for the next 'x' */
state=SCAN_X;
}
}
while(1) {continue;};
}
void flushrx(void)
{
volatile uint8_t c;
while(*UART1_URXCON !=0) {
c = *UART1_UDATA;
}
}
/* Convert from ASCII hex. Returns
the value, or 16 if it was space/newline, or
32 if some other character. */
uint8_t from_hex(uint8_t ch)
{
if(ch==' ' || ch=='\r' || ch=='\n')
return 16;
if(ch < '0')
goto bad;
if(ch <= '9')
return ch - '0';
ch |= 0x20;
if(ch < 'a')
goto bad;
if(ch <= 'f')
return ch - 'a' + 10;
bad:
return 32;
}
uint32_t to_u32(volatile uint32_t *c)
{
volatile uint32_t ret=0;
volatile uint32_t i,val;
/* c should be /x\d+,/ */
i=1; /* skip x */
while(((uint8_t *)c)[i] != ',') {
ret = ret<<4;
val = from_hex(((uint8_t *)c)[i++]);
ret += val;
}
return ret;
}

44
cpu/mc1322x/tests/led.h Normal file
View file

@ -0,0 +1,44 @@
/*
* Copyright (c) 2010, Mariano Alvira <mar@devl.org> and other contributors
* to the MC1322x project (http://mc1322x.devl.org)
* 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 libmc1322x: see http://mc1322x.devl.org
* for details.
*
* $Id: led.h,v 1.1 2010/06/10 14:55:39 maralvira Exp $
*/
#ifndef LED_H
#define LED_H
#define LED_YELLOW ((1ULL << LED_RED) | (1ULL << LED_GREEN) )
#define LED_PURPLE ((1ULL << LED_RED) | (1ULL << LED_BLUE))
#define LED_CYAN ( (1ULL << LED_GREEN) | (1ULL << LED_BLUE))
#define LED_WHITE ((1ULL << LED_RED) | (1ULL << LED_GREEN) | (1ULL << LED_BLUE))
#endif

View file

@ -0,0 +1,80 @@
/*
* Copyright (c) 2010, Mariano Alvira <mar@devl.org> and other contributors
* to the MC1322x project (http://mc1322x.devl.org)
* 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 libmc1322x: see http://mc1322x.devl.org
* for details.
*
* $Id: nvm-read.c,v 1.1 2010/06/10 14:55:39 maralvira Exp $
*/
#include <mc1322x.h>
#include <board.h>
#include "tests.h"
#include "config.h"
void main(void) {
nvmType_t type=0;
nvmErr_t err;
uint32_t buf[READ_NBYTES/4];
uint32_t i;
uart_init(INC, MOD, SAMP);
print_welcome("nvm-read");
vreg_init();
putstr("Detecting internal nvm\n\r");
err = nvm_detect(gNvmInternalInterface_c, &type);
putstr("nvm_detect returned: 0x");
put_hex(err);
putstr(" type is: 0x");
put_hex32(type);
putstr("\n\r");
nvm_setsvar(0);
err = nvm_read(gNvmInternalInterface_c, type, (uint8_t *)buf, READ_ADDR, READ_NBYTES);
putstr("nvm_read returned: 0x");
put_hex(err);
putstr("\n\r");
for(i=0; i<READ_NBYTES/4; i++) {
putstr("0x");
put_hex32(buf[i]);
putstr("\n\r");
}
while(1) {continue;};
}

View file

@ -0,0 +1,99 @@
/*
* Copyright (c) 2010, Mariano Alvira <mar@devl.org> and other contributors
* to the MC1322x project (http://mc1322x.devl.org)
* 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 libmc1322x: see http://mc1322x.devl.org
* for details.
*
* $Id: nvm-write.c,v 1.1 2010/06/10 14:55:39 maralvira Exp $
*/
#include <mc1322x.h>
#include <board.h>
#include "tests.h"
#include "config.h"
void main(void) {
nvmType_t type=0;
nvmErr_t err;
uint32_t buf[WRITE_NBYTES/4];
uint32_t i;
uart_init(INC, MOD, SAMP);
print_welcome("nvm-write");
vreg_init();
putstr("Detecting internal nvm\n\r");
err = nvm_detect(gNvmInternalInterface_c, &type);
putstr("nvm_detect returned: 0x");
put_hex(err);
putstr(" type is: 0x");
put_hex32(type);
putstr("\n\r");
buf[0] = WRITEVAL0;
buf[1] = WRITEVAL1;
err = nvm_erase(gNvmInternalInterface_c, type, 0x40000000); /* erase sector 30 --- sector 31 is the 'secret zone' */
putstr("nvm_erase returned: 0x");
put_hex(err);
putstr("\n\r");
err = nvm_write(gNvmInternalInterface_c, type, (uint8_t *)buf, WRITE_ADDR, WRITE_NBYTES);
putstr("nvm_write returned: 0x");
put_hex(err);
putstr("\n\r");
putstr("writing\n\r");
for(i=0; i<WRITE_NBYTES/4; i++) {
putstr("0x");
put_hex32(buf[i]);
putstr("\n\r");
buf[i] = 0x00000000; /* clear buf for the read */
}
err = nvm_read(gNvmInternalInterface_c, type, (uint8_t *)buf, WRITE_ADDR, WRITE_NBYTES);
putstr("nvm_read returned: 0x");
put_hex(err);
putstr("\n\r");
putstr("reading\n\r");
for(i=0; i<WRITE_NBYTES/4; i++) {
putstr("0x");
put_hex32(buf[i]);
putstr("\n\r");
}
while(1) {continue;};
}

173
cpu/mc1322x/tests/per.c Normal file
View file

@ -0,0 +1,173 @@
/*
* Copyright (c) 2010, Mariano Alvira <mar@devl.org> and other contributors
* to the MC1322x project (http://mc1322x.devl.org)
* 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 libmc1322x: see http://mc1322x.devl.org
* for details.
*
* $Id: per.c,v 1.1 2010/06/10 14:55:39 maralvira Exp $
*/
#include <mc1322x.h>
#include <board.h>
#include <stdio.h>
#include "tests.h"
#include "config.h"
/* This program communicates with itself and determines the packet */
/* error rate (PER) under a variety of powers and packet sizes */
/* Each test the packets are sent and received as fast as possible */
/* The program first scans on channel 11 and attempts to open a test */
/* session with a node. After opening a session, the nodes begin the */
/* test sequence */
/* how long to wait between session requests */
#define SESSION_REQ_TIMEOUT 10000 /* phony seconds */
enum STATES {
SCANNING,
MAX_STATE
};
typedef uint32_t ptype_t;
enum PACKET_TYPE {
PACKET_SESS_REQ,
MAX_PACKET_TYPE
};
/* get protocol level packet type */
/* this is not 802.15.4 packet type */
ptype_t get_packet_type(packet_t * p __attribute__((unused))) {
return MAX_PACKET_TYPE;
}
typedef uint32_t session_id_t;
/* phony get_time */
uint32_t get_time(void) {
static volatile int32_t cur_time = 0;
cur_time++;
return cur_time;
}
#define random_short_addr() (*MACA_RANDOM & ones(sizeof(uint16_t)*8))
void build_session_req(volatile packet_t *p) {
static uint8_t count = 0;
p->length = 4; p->offset = 0;
p->data[0] = 0xff;
p->data[1] = 0x01;
p->data[2] = 0x02;
p->data[3] = count++;
return;
}
void session_req(uint16_t addr __attribute__((unused))) {
static volatile int time = 0;
volatile packet_t *p;
if((get_time() - time) > SESSION_REQ_TIMEOUT) {
time = get_time();
if((p = get_free_packet())) {
build_session_req(p);
tx_packet(p);
}
}
return;
}
session_id_t open_session(uint16_t addr __attribute((unused))) { return 0; }
void main(void) {
uint32_t state;
volatile packet_t *p;
session_id_t sesid;
ptype_t type;
uint16_t addr, my_addr;
/* trim the reference osc. to 24MHz */
pack_XTAL_CNTL(CTUNE_4PF, CTUNE, FTUNE, IBIAS);
uart_init(INC, MOD, SAMP);
vreg_init();
maca_init();
set_power(0x0f); /* 0dbm */
set_channel(0); /* channel 11 */
/* generate a random short address */
my_addr = random_short_addr();
/* sets up tx_on, should be a board specific item */
*GPIO_FUNC_SEL2 = (0x01 << ((44-16*2)*2));
gpio_pad_dir_set( 1ULL << 44 );
print_welcome("Packet error test");
state = SCANNING;
while(1) {
switch(state) {
case SCANNING:
if((p = rx_packet())) {
/* extract what we need and free the packet */
printf("Recv: ");
print_packet(p);
type = get_packet_type((packet_t *) p);
addr = 0; /* FIXME */
free_packet(p);
/* pick a new address if someone else is using ours */
if(addr == my_addr) {
my_addr = random_short_addr();
printf("DUP addr received, changing to new addr 0x%x02\n\r",my_addr);
}
/* if we have a packet */
/* check if it's a session request beacon */
if(type == PACKET_SESS_REQ) {
/* try to start a session */
sesid = open_session(addr);
}
} else {
session_req(my_addr);
}
break;
default:
break;
}
}
}

136
cpu/mc1322x/tests/printf.c Normal file
View file

@ -0,0 +1,136 @@
/*
* Copyright (c) 2010, Mariano Alvira <mar@devl.org> and other contributors
* to the MC1322x project (http://mc1322x.devl.org)
* 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 libmc1322x: see http://mc1322x.devl.org
* for details.
*
* $Id: printf.c,v 1.1 2010/06/10 14:55:39 maralvira Exp $
*/
#include <mc1322x.h>
#include <board.h>
#include <stdio.h>
#include <math.h>
#include "tests.h"
#include "config.h"
#define print_size(x) do { \
printf("sizeof("); \
printf(#x); \
printf("): %d\n", sizeof(x)); \
} while(0)
FILE *stderr;
void __assert_fail(void) {
return;
}
int fputs(const char *s, FILE *stream) {
return 0;
}
size_t fwrite(const void *ptr, size_t size, size_t nmemb,
FILE *stream) {
return 0;
}
int main(void)
{
char *ptr = "Hello world!";
char *np = 0;
int i = 5;
unsigned int bs = sizeof(int)*8;
int mi;
// char buf[80];
uart_init(INC, MOD, SAMP);
print_size(int8_t);
print_size(uint8_t);
print_size(int16_t);
print_size(uint16_t);
print_size(int32_t);
print_size(uint32_t);
print_size(int64_t);
print_size(uint64_t);
mi = (1 << (bs-1)) + 1;
printf("%s\n", ptr);
printf("printf test\n");
printf("%s is null pointer\n", np);
printf("%d = 5\n", i);
printf("%d = - max int\n", mi);
printf("char %c = 'a'\n", 'a');
printf("hex %x = ff\n", 0xff);
printf("hex %02x = 00\n", 0);
printf("signed %d = unsigned %u = hex %x\n", -3, -3, -3);
printf("%d %s(s)", 0, "message");
printf("\n");
printf("%d %s(s) with %%\n", 0, "message");
printf("sqrt(5) * 100 = %d\n", (int) (sqrt(5)*100));
// sprintf(buf, "justif: \"%-10s\"\n", "left"); printf("%s", buf);
// sprintf(buf, "justif: \"%10s\"\n", "right"); printf("%s", buf);
// sprintf(buf, " 3: %04d zero padded\n", 3); printf("%s", buf);
// sprintf(buf, " 3: %-4d left justif.\n", 3); printf("%s", buf);
// sprintf(buf, " 3: %4d right justif.\n", 3); printf("%s", buf);
// sprintf(buf, "-3: %04d zero padded\n", -3); printf("%s", buf);
// sprintf(buf, "-3: %-4d left justif.\n", -3); printf("%s", buf);
// sprintf(buf, "-3: %4d right justif.\n", -3); printf("%s", buf);
while(1) { continue; }
}
/*
* this should display (on 32bit int machine) :
*
* Hello world!
* printf test
* (null) is null pointer
* 5 = 5
* -2147483647 = - max int
* char a = 'a'
* hex ff = ff
* hex 00 = 00
* signed -3 = unsigned 4294967293 = hex fffffffd
* 0 message(s)
* 0 message(s) with %
* justif: "left "
* justif: " right"
* 3: 0003 zero padded
* 3: 3 left justif.
* 3: 3 right justif.
* -3: -003 zero padded
* -3: -3 left justif.
* -3: -3 right justif.
*/

73
cpu/mc1322x/tests/put.c Normal file
View file

@ -0,0 +1,73 @@
/*
* Copyright (c) 2010, Mariano Alvira <mar@devl.org> and other contributors
* to the MC1322x project (http://mc1322x.devl.org)
* 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 libmc1322x: see http://mc1322x.devl.org
* for details.
*
* $Id: put.c,v 1.1 2010/06/10 14:55:39 maralvira Exp $
*/
#include <mc1322x.h>
#include <board.h>
const uint8_t hex[16]={'0','1','2','3','4','5','6','7',
'8','9','a','b','c','d','e','f'};
void putchr(char c) {
while(*UART1_UTXCON == 31);
/* wait for there to be room in the buffer */
// while( *UART1_UTXCON == 0 ) { continue; }
*UART1_UDATA = c;
}
void putstr(char *s) {
while(s && *s!=0) {
putchr(*s++);
}
}
void put_hex(uint8_t x)
{
putchr(hex[x >> 4]);
putchr(hex[x & 15]);
}
void put_hex16(uint16_t x)
{
put_hex((x >> 8) & 0xFF);
put_hex((x) & 0xFF);
}
void put_hex32(uint32_t x)
{
put_hex((x >> 24) & 0xFF);
put_hex((x >> 16) & 0xFF);
put_hex((x >> 8) & 0xFF);
put_hex((x) & 0xFF);
}

45
cpu/mc1322x/tests/put.h Normal file
View file

@ -0,0 +1,45 @@
/*
* Copyright (c) 2010, Mariano Alvira <mar@devl.org> and other contributors
* to the MC1322x project (http://mc1322x.devl.org)
* 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 libmc1322x: see http://mc1322x.devl.org
* for details.
*
* $Id: put.h,v 1.1 2010/06/10 14:55:39 maralvira Exp $
*/
#ifndef PUT_H
#define PUT_H
void putchr(char c);
void putstr(char *s);
void put_hex(uint8_t x);
void put_hex16(uint16_t x);
void put_hex32(uint32_t x);
#endif

View file

@ -0,0 +1,91 @@
/*
* Copyright (c) 2010, Mariano Alvira <mar@devl.org> and other contributors
* to the MC1322x project (http://mc1322x.devl.org)
* 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 libmc1322x: see http://mc1322x.devl.org
* for details.
*
* $Id: rftest-rx.c,v 1.1 2010/06/10 14:55:39 maralvira Exp $
*/
#include <mc1322x.h>
#include <board.h>
#include <stdio.h>
#include "tests.h"
#include "config.h"
#define LED LED_GREEN
void maca_rx_callback(volatile packet_t *p) {
(void)p;
gpio_data_set(1ULL<< LED);
gpio_data_reset(1ULL<< LED);
}
void main(void) {
volatile packet_t *p;
gpio_data(0);
gpio_pad_dir_set( 1ULL << LED );
/* read from the data register instead of the pad */
/* this is needed because the led clamps the voltage low */
gpio_data_sel( 1ULL << LED);
/* trim the reference osc. to 24MHz */
trim_xtal();
uart_init(INC, MOD, SAMP);
vreg_init();
maca_init();
/* sets up tx_on, should be a board specific item */
// *GPIO_FUNC_SEL2 = (0x01 << ((44-16*2)*2));
gpio_pad_dir_set( 1ULL << 44 );
set_power(0x0f); /* 0dbm */
set_channel(0); /* channel 11 */
print_welcome("rftest-rx");
while(1) {
/* call check_maca() periodically --- this works around */
/* a few lockup conditions */
check_maca();
if((p = rx_packet())) {
/* print and free the packet */
printf("rftest-rx --- ");
print_packet(p);
free_packet(p);
}
}
}

View file

@ -0,0 +1,110 @@
/*
* Copyright (c) 2010, Mariano Alvira <mar@devl.org> and other contributors
* to the MC1322x project (http://mc1322x.devl.org)
* 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 libmc1322x: see http://mc1322x.devl.org
* for details.
*
* $Id: rftest-tx.c,v 1.1 2010/06/10 14:55:39 maralvira Exp $
*/
#include <mc1322x.h>
#include <board.h>
#include <stdio.h>
#include "tests.h"
#include "config.h"
#define LED LED_RED
/* 802.15.4 PSDU is 127 MAX */
/* 2 bytes are the FCS */
/* therefore 125 is the max payload length */
#define PAYLOAD_LEN 16
#define DELAY 100000
void fill_packet(volatile packet_t *p) {
static volatile uint8_t count=0;
volatile uint8_t i;
p->length = PAYLOAD_LEN;
p->offset = 0;
for(i=0; i<PAYLOAD_LEN; i++) {
p->data[i] = count++;
}
/* acks get treated differently, even in promiscuous mode */
/* setting the third bit makes sure that we never send an ack */
/* or any valid 802.15.4-2006 packet */
p->data[0] |= (1 << 3);
}
void main(void) {
volatile uint32_t i;
volatile packet_t *p;
/* trim the reference osc. to 24MHz */
trim_xtal();
uart_init(INC, MOD, SAMP);
vreg_init();
maca_init();
set_channel(0); /* channel 11 */
// set_power(0x0f); /* 0xf = -1dbm, see 3-22 */
// set_power(0x11); /* 0x11 = 3dbm, see 3-22 */
set_power(0x12); /* 0x12 is the highest, not documented */
/* sets up tx_on, should be a board specific item */
*GPIO_FUNC_SEL2 = (0x01 << ((44-16*2)*2));
gpio_pad_dir_set( 1ULL << 44 );
print_welcome("rftest-tx");
while(1) {
/* call check_maca() periodically --- this works around */
/* a few lockup conditions */
check_maca();
p = get_free_packet();
if(p) {
fill_packet(p);
printf("rftest-tx --- ");
print_packet(p);
tx_packet(p);
for(i=0; i<DELAY; i++) { continue; }
}
}
}

View file

@ -0,0 +1,53 @@
/*
* Copyright (c) 2010, Mariano Alvira <mar@devl.org> and other contributors
* to the MC1322x project (http://mc1322x.devl.org)
* 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 libmc1322x: see http://mc1322x.devl.org
* for details.
*
* $Id: romimg.c,v 1.1 2010/06/10 14:55:39 maralvira Exp $
*/
#include <mc1322x.h>
#include <board.h>
#include "tests.h"
#include "config.h"
void main(void) {
volatile uint8_t *data;
uart_init(INC, MOD, SAMP);
for(data = DUMP_BASE; data < ((uint8_t *)(DUMP_BASE+DUMP_LEN)); data++) {
uart1_putc(*data);
}
while(1);
}

173
cpu/mc1322x/tests/sleep.c Normal file
View file

@ -0,0 +1,173 @@
/*
* Copyright (c) 2010, Mariano Alvira <mar@devl.org> and other contributors
* to the MC1322x project (http://mc1322x.devl.org)
* 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 libmc1322x: see http://mc1322x.devl.org
* for details.
*
* $Id: sleep.c,v 1.1 2010/06/10 14:55:39 maralvira Exp $
*/
#include <mc1322x.h>
#include <board.h>
#include "tests.h"
#include "config.h"
void main(void) {
uart_init(INC,MOD,SAMP);
*mem32(0x00401ffc) = 0x01234567;
*mem32(0x00407ffc) = 0xdeadbeef;
*mem32(0x0040fffc) = 0xface00ff;
*mem32(0x00410000) = 0xabcd0123;
putstr("sleep test\n\r");
putstr("0x00401ffc: ");
put_hex32(*mem32(0x00401ffc));
putstr("\r\n");
putstr("0x00407ffc: ");
put_hex32(*mem32(0x00407ffc));
putstr("\r\n");
putstr("0x0040fffc: ");
put_hex32(*mem32(0x0040fffc));
putstr("\r\n");
putstr("0x00410000: ");
put_hex32(*mem32(0x00410000));
putstr("\r\n");
/* radio must be OFF before sleeping */
/* otherwise MCU will not wake up properly */
/* this is undocumented behavior */
// radio_off();
#if USE_32KHZ
/* turn on the 32kHz crystal */
putstr("enabling 32kHz crystal\n\r");
/* you have to hold it's hand with this on */
/* once you start the 32xHz crystal it can only be stopped with a reset (hard or soft) */
/* first, disable the ring osc */
clear_bit(*CRM_RINGOSC_CNTL,0);
/* enable the 32kHZ crystal */
set_bit(*CRM_XTAL32_CNTL,0);
/* 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 */
set_bit(*CRM_SYS_CNTL,5);
{
static volatile uint32_t old;
old = *CRM_RTC_COUNT;
putstr("waiting for xtal\n\r");
while(*CRM_RTC_COUNT == old) {
continue;
}
/* RTC has started up */
set_bit(*CRM_SYS_CNTL,5);
putstr("32kHZ xtal started\n\r");
}
#endif
/* go to sleep */
// *CRM_WU_CNTL = 0; /* don't wake up */
*CRM_WU_CNTL = 0x1; /* enable wakeup from wakeup timer */
// *CRM_WU_TIMEOUT = 1875000; /* wake 10 sec later if doze */
#if USE_32KHZ
*CRM_WU_TIMEOUT = 327680*2;
#else
*CRM_WU_TIMEOUT = 20000; /* wake 10 sec later if hibernate ring osc */
#endif
/* hobby board: 2kHz = 11uA; 32kHz = 11uA */
// *CRM_SLEEP_CNTL = 1; /* hibernate, RAM page 0 only, don't retain state, don't power GPIO */ /* approx. 2kHz = 2.0uA */
/* hobby board: 2kHz = 18uA; 32kHz = 19uA */
// *CRM_SLEEP_CNTL = 0x41; /* hibernate, RAM page 0 only, retain state, don't power GPIO */ /* approx. 2kHz = 10.0uA */
/* hobby board: 2kHz = 20uA; 32kHz = 21uA */
// *CRM_SLEEP_CNTL = 0x51; /* hibernate, RAM page 0&1 only, retain state, don't power GPIO */ /* approx. 2kHz = 11.7uA */
/* hobby board: 2kHz = 22uA; 32kHz = 22.5uA */
// *CRM_SLEEP_CNTL = 0x61; /* hibernate, RAM page 0,1,2 only, retain state, don't power GPIO */ /* approx. 2kHz = 13.9uA */
/* hobby board: 2kHz = 24uA; 32kHz = 25uA */
*CRM_SLEEP_CNTL = 0x71; /* hibernate, all RAM pages, retain state, don't power GPIO */ /* approx. 2kHz = 16.1uA */
// *CRM_SLEEP_CNTL = 0xf1; /* hibernate, all RAM pages, retain state, power GPIO */ /* consumption depends on GPIO hookup */
// *CRM_SLEEP_CNTL = 2; /* doze , RAM page 0 only, don't retain state, don't power GPIO */ /* approx. 69.2 uA */
// *CRM_SLEEP_CNTL = 0x42; /* doze , RAM page 0 only, retain state, don't power GPIO */ /* approx. 77.3uA */
// *CRM_SLEEP_CNTL = 0x52; /* doze , RAM page 0&1 only, retain state, don't power GPIO */ /* approx. 78.9uA */
// *CRM_SLEEP_CNTL = 0x62; /* doze , RAM page 0,1,2 only, retain state, don't power GPIO */ /* approx. 81.2uA */
// *CRM_SLEEP_CNTL = 0x72; /* doze , all RAM pages, retain state, don't power GPIO */ /* approx. 83.4uA - possibly with periodic refresh*/
// *CRM_SLEEP_CNTL = 0xf2; /* doze , all RAM pages, retain state, power GPIO */ /* consumption depends on GPIO hookup */
/* wait for the sleep cycle to complete */
while((*CRM_STATUS & 0x1) == 0) { continue; }
/* write 1 to sleep_sync --- this clears the bit (it's a r1wc bit) and powers down */
*CRM_STATUS = 1;
/* asleep */
/* wait for the awake cycle to complete */
while((*CRM_STATUS & 0x1) == 0) { continue; }
/* write 1 to sleep_sync --- this clears the bit (it's a r1wc bit) and finishes wakeup */
*CRM_STATUS = 1;
putstr("\n\r\n\r\n\r");
putstr("0x00401ffc: ");
put_hex32(*mem32(0x00401ffc));
putstr("\r\n");
putstr("0x00407ffc: ");
put_hex32(*mem32(0x00407ffc));
putstr("\r\n");
putstr("0x0040fffc: ");
put_hex32(*mem32(0x0040fffc));
putstr("\r\n");
putstr("0x00410000: ");
put_hex32(*mem32(0x00410000));
putstr("\r\n");
*GPIO_PAD_DIR0 = LED_RED;
#define DELAY 400000
volatile uint32_t i;
while(1) {
*GPIO_DATA0 = LED_RED;
for(i=0; i<DELAY; i++) { continue; }
*GPIO_DATA0 = 0;
for(i=0; i<DELAY; i++) { continue; }
};
}

80
cpu/mc1322x/tests/tests.c Normal file
View file

@ -0,0 +1,80 @@
/*
* Copyright (c) 2010, Mariano Alvira <mar@devl.org> and other contributors
* to the MC1322x project (http://mc1322x.devl.org)
* 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 libmc1322x: see http://mc1322x.devl.org
* for details.
*
* $Id: tests.c,v 1.1 2010/06/10 14:55:39 maralvira Exp $
*/
#include <mc1322x.h>
#include <stdio.h>
#include "put.h"
#include "tests.h"
void print_welcome(char* testname) {
printf("mc1322x-test: %s\n\r",testname);
printf("board: %s\n\r", STR2(BOARD));
}
void print_packet(volatile packet_t *p) {
volatile uint8_t i,j,k;
#define PER_ROW 16
if(p) {
printf("len 0x%02x",p->length);
for(j=0, k=0; j <= ((p->length)%PER_ROW); j++) {
printf("\n\r");
for(i=0; i < PER_ROW; i++, k++) {
if(k >= p->length ) {
printf("\n\r");
return;
}
printf("%02x ",p->data[j*PER_ROW + i + p->offset]);
}
}
}
printf("\n\r");
return;
}
void dump_regs(uint32_t base, uint32_t len) {
volatile uint32_t i;
printf("base +0 +4 +8 +c +10 +14 +18 +1c \n\r");
for (i = 0; i < len; i ++) {
if ((i & 7) == 0) {
printf("%02lx",(uint32_t)(4 * i));
}
printf(" %08lx",(uint32_t)*mem32(base+(4*i)));
if ((i & 7) == 7)
printf(NL);
}
printf(NL);
}

48
cpu/mc1322x/tests/tests.h Normal file
View file

@ -0,0 +1,48 @@
/*
* Copyright (c) 2010, Mariano Alvira <mar@devl.org> and other contributors
* to the MC1322x project (http://mc1322x.devl.org)
* 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 libmc1322x: see http://mc1322x.devl.org
* for details.
*
* $Id: tests.h,v 1.1 2010/06/10 14:55:39 maralvira Exp $
*/
#ifndef TESTS_H
#define TESTS_H
#include "put.h"
#include "led.h"
#define NL "\033[K\r\n"
void print_welcome(char* testname);
void dump_regs(uint32_t base, uint32_t len);
void print_packet(volatile packet_t *p);
#endif

View file

@ -0,0 +1,102 @@
/*
* Copyright (c) 2010, Mariano Alvira <mar@devl.org> and other contributors
* to the MC1322x project (http://mc1322x.devl.org)
* 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 libmc1322x: see http://mc1322x.devl.org
* for details.
*
* $Id: tmr-ints.c,v 1.1 2010/06/10 14:55:39 maralvira Exp $
*/
#include <mc1322x.h>
#include <board.h>
#include "tests.h"
#include "config.h"
volatile uint8_t led;
#define LED LED_PURPLE
#define led_init() do { gpio_pad_dir_set(LED_WHITE); gpio_data_reset(LED_WHITE); } while(0);
#define led_on() do { led = 1; gpio_data_set(LED); } while(0);
#define led_off() do { led = 0; gpio_data_reset(LED); } while(0);
void toggle_led(void) {
if(0 == led) {
led_on();
led = 1;
} else {
led_off();
}
}
void tmr0_isr(void) {
toggle_led();
*TMR0_SCTRL = 0;
*TMR0_CSCTRL = 0x0040; /* clear compare flag */
}
void main(void) {
/* pin direction */
led_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 = 18750; /* trigger a reload at the end */
*TMR0_CMPLD1 = 18750; /* 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? */
led_on();
enable_irq(TMR);
while(1) {
/* sit here and let the interrupts do the work */
continue;
};
}

86
cpu/mc1322x/tests/tmr.c Normal file
View file

@ -0,0 +1,86 @@
/*
* Copyright (c) 2010, Mariano Alvira <mar@devl.org> and other contributors
* to the MC1322x project (http://mc1322x.devl.org)
* 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 libmc1322x: see http://mc1322x.devl.org
* for details.
*
* $Id: tmr.c,v 1.1 2010/06/10 14:55:39 maralvira Exp $
*/
#include <mc1322x.h>
#include <board.h>
#include "tests.h"
#include "config.h"
#define LED LED_YELLOW
void main(void) {
/* pin direction */
gpio_pad_dir_set(LED_WHITE);
/* all LEDs off */
gpio_data_reset(LED_WHITE);
/* 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_LOAD = 0; /* reload to zero */
*TMR0_COMP_UP = 18750; /* trigger a reload at the end */
*TMR0_CMPLD1 = 18750; /* 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? */
while(1) {
/* blink on */
gpio_data_set(LED);
while((*TMR0_SCTRL >> 15) == 0) { continue; }
*TMR0_SCTRL = 0; /*clear bit 15, and all the others --- should be ok, but clearly not "the right thing to do" */
/* blink off */
gpio_data_reset(LED);
while((*TMR0_SCTRL >> 15) == 0) { continue; }
*TMR0_SCTRL = 0; /*clear bit 15, and all the others --- should be ok, but clearly not "the right thing to do" */
};
}

View file

@ -0,0 +1,54 @@
/*
* Copyright (c) 2010, Mariano Alvira <mar@devl.org> and other contributors
* to the MC1322x project (http://mc1322x.devl.org)
* 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 libmc1322x: see http://mc1322x.devl.org
* for details.
*
* $Id: uart1-loopback.c,v 1.1 2010/06/10 14:55:39 maralvira Exp $
*/
#include <mc1322x.h>
#include <board.h>
#include "tests.h"
#include "config.h"
void main(void) {
uart1_init(INC,MOD,SAMP);
while(1) {
if(uart1_can_get()) {
/* Receive buffer isn't empty */
/* read a byte and write it to the transmit buffer */
uart1_putc(uart1_getc());
}
}
}

View file

@ -0,0 +1,10 @@
LDFLAGS = -lftdi
TARGETS = bbmc
CFLAGS = -Wall -Wextra #-Werror
all: $(TARGETS)
clean:
-rm $(TARGETS)

View file

@ -0,0 +1,497 @@
/*
* Copyright (c) 2010, Mariano Alvira <mar@devl.org> and other contributors
* to the MC1322x project (http://mc1322x.devl.org)
* 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 libmc1322x: see http://mc1322x.devl.org
* for details.
*
* $Id: bbmc.c,v 1.1 2010/06/10 14:55:39 maralvira Exp $
*/
/* control reset and VREF2 lines */
#include <stdio.h>
#include <string.h>
#include <getopt.h>
#include <ftdi.h>
#define DEBUG 0
#define low(x) (1 << x)
#define high(x) (1 << (x + 8))
#define REDBEE_ECONOTAG_RESET high(2)
#define REDBEE_ECONOTAG_VREF2L high(7)
#define REDBEE_ECONOTAG_VREF2H high(6)
#define REDBEE_ECONOTAG_INTERFACE INTERFACE_A
#define REDBEE_USB_RESET high(2)
#define REDBEE_USB_VREF2L low(5)
#define REDBEE_USB_VREF2H low(6)
#define REDBEE_USB_INTERFACE INTERFACE_B
#define BOARD REDBEE_USB
#define STR(x) #x
#define STR2(x) STR(x)
#define CAT(x,y) x##y
#define CAT2(x, y, z) x##y##z
#define dir(x) ( CAT(x,_RESET) | CAT(x,_VREF2L) | CAT(x,_VREF2H))
#define interface(x) ( CAT(x,_INTERFACE) )
#define reset_release(x) ( CAT(x,_RESET) )
#define reset_set(x) ( 0 )
#define vref2_normal(x) ( CAT(x,_VREF2H) )
#define vref2_erase(x) ( CAT(x,_VREF2L) )
/* fgets input buffer length: for prompts and such */
#define BUF_LEN 32
struct layout {
char *name;
char *desc;
enum ftdi_interface interface;
uint16_t dir;
uint16_t reset_release;
uint16_t reset_set;
uint16_t vref2_normal;
uint16_t vref2_erase;
};
int print_and_prompt( struct ftdi_device_list *devlist );
int bb_mpsee(struct ftdi_context *ftdic, uint16_t dir, uint16_t val);
void reset(struct ftdi_context *ftdic, const struct layout * l);
void erase(struct ftdi_context *ftdic, const struct layout * l);
void usage(void);
#define std_layout(x) \
.interface = interface(x), \
.dir = dir(x), \
.reset_release = reset_release(x), \
.reset_set = reset_set(x), \
.vref2_normal = vref2_normal(x), \
.vref2_erase = vref2_erase(x),
static struct layout layouts[] =
{
{ .name = "redbee-econotag",
.desc = "Redbee Econotag",
std_layout(REDBEE_ECONOTAG)
},
{ .name = "redbee-usb",
.desc = "Redbee USB stick",
std_layout(REDBEE_USB)
},
{ .name = NULL, /* end of table */ },
};
struct command {
char *name;
char *desc;
void (*cmd)(struct ftdi_context *ftdic, const struct layout * l);
};
static const struct command commands[] =
{
{
.name = "reset",
.desc = "Toggles reset pin",
.cmd = reset,
},
{
.name = "erase",
.desc = "Sets VREF2 erase mode; toggles reset; waits 2 sec.; sets normal; toggles reset again",
.cmd = erase,
},
{ .name = NULL, /* end of table */ },
};
struct layout * find_layout(char * str)
{
uint32_t i = 0;
while(layouts[i].name != NULL) {
if(strcmp(layouts[i].name, str) == 0) { return &layouts[i]; }
i++;
}
return NULL;
}
static uint32_t vendid = 0x0403; uint32_t prodid = 0x6010;
int main(int argc, char **argv)
{
struct ftdi_context ftdic;
struct ftdi_device_list *devlist;
int dev_index = -1; int num_devs;
char layout_str[BUF_LEN];
struct layout layout;
struct layout *l = NULL;
int i, ret;
/* overrides for layout parameters */
int interface = -1;
int dir = -1;
int reset_release = -1;
int reset_set = -1;
int vref2_normal = -1;
int vref2_erase = -1;
layout.name = NULL;
while (1) {
int c;
int option_index = 0;
static struct option long_options[] = {
{"layout", required_argument, 0, 'l'},
{"index", required_argument, 0, 'i'},
{"vendor", required_argument, 0, 'v'},
{"product", required_argument, 0, 'p'},
{"dir", required_argument, 0, 0 },
{"reset_release", required_argument, 0, 0 },
{"reset_set", required_argument, 0, 0 },
{"vref2_normal", required_argument, 0, 0 },
{"vref2_erase", required_argument, 0, 0 },
{"interface", required_argument, 0, 0 },
{"help", no_argument, 0, '?'},
{0, 0, 0, 0}
};
c = getopt_long (argc, argv, "i:l:v:p:",
long_options, &option_index);
if (c == -1)
break;
switch (c) {
/* process long opts */
case 0:
if(strcmp(long_options[option_index].name, "interface") == 0) {
sscanf(optarg, "%i", &interface);
}
if(strcmp(long_options[option_index].name, "dir") == 0) {
sscanf(optarg, "%i", &dir);
}
if (strcmp(long_options[option_index].name, "reset_release") == 0) {
sscanf(optarg, "%i", &reset_release);
}
if (strcmp(long_options[option_index].name, "reset_set") == 0) {
sscanf(optarg, "%i", &reset_set);
}
if (strcmp(long_options[option_index].name, "vref2_normal") == 0) {
sscanf(optarg, "%i", &vref2_normal);
}
if (strcmp(long_options[option_index].name, "vref2_erase") == 0) {
sscanf(optarg, "%i", &vref2_erase);
}
break;
case 'l':
strncpy(layout_str, optarg, BUF_LEN);
break;
case 'i':
dev_index = atoi(optarg);
break;
case 'v':
sscanf(optarg, "%i", &vendid);
break;
case 'p':
sscanf(optarg, "%i", &prodid);
break;
default:
usage();
break;
}
}
if( !(l = find_layout(layout_str)) &&
!((interface >= 0) &&
(dir >= 0) &&
(reset_release >= 0) &&
(reset_set >= 0) &&
(vref2_normal >= 0) &&
(vref2_erase >= 0))
) {
printf("*** You must specify a layout or a complete set of overrides\n");
return EXIT_FAILURE;
}
if(l) {
memcpy(&layout, l, sizeof(struct layout));
}
#define override(x) if(x > 0) { layout.x = x; }
override(interface);
override(dir);
override(reset_release); override(reset_set);
override(vref2_normal); override(vref2_erase);
if ((num_devs = ftdi_usb_find_all(&ftdic, &devlist, vendid, prodid)) < 0)
{
fprintf(stderr, "ftdi_usb_find_all failed: %d (%s)\n",
num_devs,
ftdi_get_error_string(&ftdic));
return EXIT_FAILURE;
}
if (ftdi_init(&ftdic) < 0)
{
fprintf(stderr, "ftdi_init failed\n");
return EXIT_FAILURE;
}
if (ftdi_set_interface(&ftdic, layout.interface) < 0) {
fprintf(stderr, "couldn't set interface %d\n", layout.interface);
return EXIT_FAILURE;
}
printf("Found %d devices with vendor id 0x%04x product id 0x%04x\n",
num_devs, vendid, prodid);
if(num_devs == 0) { return EXIT_SUCCESS; }
if(num_devs == 1) { dev_index = 0; }
while( (dev_index < 0) || (dev_index >= num_devs)){
dev_index = print_and_prompt(devlist);
}
if(layout.name != NULL) {
printf("Opening device %d interface %d using layout %s\n",
dev_index, layout.interface, layout.name);
} else {
printf("Opening device %d interface %d without a layout.\n",
dev_index, layout.interface);
}
if( (ret = ftdi_usb_open_desc_index(
&ftdic,
vendid,
prodid,
NULL,
NULL,
dev_index)) < 0) {
fprintf(stderr, "couldn't open dev_index %d\n", dev_index);
return EXIT_FAILURE;
}
for(i = 0; commands[i].name != NULL; i++) {
if( (argv[optind] != NULL) &&
(strcmp(commands[i].name, argv[optind]) == 0)) { break; }
}
if(commands[i].name != NULL) {
commands[i].cmd(&ftdic, &layout);
} else {
printf("invalid command\n");
ftdi_list_free(&devlist);
ftdi_deinit(&ftdic);
return EXIT_FAILURE;
}
printf("done.\n");
ftdi_list_free(&devlist);
ftdi_deinit(&ftdic);
return EXIT_SUCCESS;
}
void usage(void)
{
int i;
printf( "Usage: bbmc [options|overrides] -l|--layout layout command \n");
printf( "Commands:\n");
for(i = 0; commands[i].name != NULL; i++) {
printf( " %s: %s\n", commands[i].name, commands[i].desc);
}
printf("\n");
printf( "Required options:\n");
printf( " -l|--layout\t specifiy which board layout to use\n");
printf( " \t layout is not necessary with a full\n");
printf( " \t set of overrides\n");
printf( "\nLayout overrides:\n");
printf( " --interface\t\t FTDI interface to use\n");
printf( " --dir\t\t direction (1 is output)\n");
printf( " --reset_release\t reset release command\n");
printf( " --reset_set\t\t reset set command\n");
printf( " --vref2_normal\t vref2 normal\n");
printf( " --vref2_erase\t vref2 erase\n");
printf("\n");
printf( "Layouts:\n");
for(i = 0; layouts[i].name != NULL; i++) {
printf( "\t%s: %s\n", layouts[i].name, layouts[i].desc);
printf("\n");
printf( "\t\tinterface: \t0x%04x\n", layouts[i].interface);
printf( "\t\tdir: \t\t0x%04x\n", layouts[i].dir);
printf( "\t\treset release: \t0x%04x\n", layouts[i].reset_release);
printf( "\t\treset hold: \t0x%04x\n", layouts[i].reset_set);
printf( "\t\tvref2 normal: \t0x%04x\n", layouts[i].vref2_normal);
printf( "\t\tvref2 erase: \t0x%04x\n", layouts[i].vref2_erase);
printf("\n");
}
printf("\n");
printf( "Options:\n");
printf( " -i|--index specifiy which device to use (default 0)\n");
printf( " -v|--vendor set vendor id (default 0x0403)\n");
printf( " -p|--product set vendor id (default 0x6010)\n");
}
int print_and_prompt( struct ftdi_device_list *devlist )
{
int i, ret;
struct ftdi_context ftdic;
struct ftdi_device_list *curdev;
char manufacturer[128], description[128], serial[128];
char input[BUF_LEN]; char *s;
int sel = -1;
printf("\n");
i = 0;
for (curdev = devlist; curdev != NULL; i++)
{
printf(" [%d] ", i);
if (0 > (ret = ftdi_usb_get_strings(&ftdic,
curdev->dev,
manufacturer, 128,
description, 128,
serial, 128)))
{
fprintf(stderr, "ftdi_usb_get_strings failed: %d (%s)\n",
ret, ftdi_get_error_string(&ftdic));
return EXIT_FAILURE;
}
printf("Manufacturer: %s, Description: %s, Serial %s\n",
manufacturer, description, serial);
curdev = curdev->next;
}
printf("\nUse which device? ");
s = fgets(input, BUF_LEN, stdin);
if (s != NULL) {
size_t last = strlen (input) - 1;
if (input[last] == '\n') input[last] = '\0';
}
sscanf(s, "%i",&sel);
return sel;
}
void reset(struct ftdi_context *ftdic, const struct layout * l)
{
/* using MPSSE since it give access to high GPIO*/
/* set as inputs for now */
ftdi_set_bitmode(ftdic, 0 , BITMODE_MPSSE);
printf("toggle reset\n");
bb_mpsee(ftdic, l->dir, (l->reset_release | l->vref2_normal));
bb_mpsee(ftdic, l->dir, (l->reset_set | l->vref2_normal));
bb_mpsee(ftdic, l->dir, (l->reset_release | l->vref2_normal));
return;
}
void erase(struct ftdi_context *ftdic, const struct layout * l)
{
printf("setting VREF2 erase\n");
/* using MPSSE since it give access to high GPIO*/
/* set as inputs for now */
ftdi_set_bitmode(ftdic, 0 , BITMODE_MPSSE);
bb_mpsee(ftdic, l->dir, (l->reset_release | l->vref2_normal));
bb_mpsee(ftdic, l->dir, (l->reset_release | l->vref2_erase));
printf("toggle reset\n");
bb_mpsee(ftdic, l->dir, (l->reset_set | l->vref2_erase));
bb_mpsee(ftdic, l->dir, (l->reset_release | l->vref2_erase));
printf("waiting for erase\n");
sleep(2);
printf("setting VREF2 normal\n");
bb_mpsee(ftdic, l->dir, (l->reset_release | l->vref2_normal));
reset(ftdic, l);
return;
}
int bb_mpsee(struct ftdi_context *ftdic, uint16_t dir, uint16_t val)
{
uint8_t buf[3];
int ret;
/* command "set data bits low byte" */
buf[0] = 0x80;
buf[1] = (val & 0xff);
buf[2] = dir & 0xff;
#if DEBUG
fprintf(stderr,"write %x %x %x\n",buf[0],buf[1],buf[2]);
#endif
if ((ret = (ftdi_write_data(ftdic, buf, 3))) < 0)
{
perror("ft2232_write error");
fprintf(stderr, "ft2232_write command %x\n", buf[0]);
return EXIT_FAILURE;
}
/* command "set data bits high byte" */
buf[0] = 0x82;
buf[1] = (val >> 8);
buf[2] = dir >> 8;
#if DEBUG
fprintf(stderr,"write %x %x %x\n",buf[0],buf[1],buf[2]);
#endif
if ((ret = (ftdi_write_data(ftdic, buf, 3))) < 0)
{
perror("ft2232_write error");
fprintf(stderr, "ft2232_write command %x\n", buf[0]);
return EXIT_FAILURE;
}
return 0;
}

31
cpu/mc1322x/tools/map2dot.pl Executable file
View file

@ -0,0 +1,31 @@
#!/usr/bin/perl
# Try:
# gcc -static -o test test.c -Wl,--print-map | perl parse-map.pl | unflatten -l 3 | dot -Tpng > map.png
#
# This won't show all edges! An archive member is only listed the first
# time it needs to get included. But this shows at least one reason why each
# archive member appears in the final object.
my $flag = 0;
my $line = "";
print "digraph map {\n";
print "rankdir = LR;";
while(<>)
{
$flag++ if /^Archive member included because of file \(symbol\)$/;
$flag++ if /^$/;
next unless $flag == 2;
chomp ($line .= $_);
if ($line =~ /^(\S+)\s+(\S+)\s+\(([^)]+)\)$/s) {
$line = "";
my $archive_member = $1;
my $because_file = $2;
my $because_symbol = $3;
$archive_member =~ s|.*/([^/]+)|$1|;
$because_file =~ s|.*/([^/]+)|$1|;
print "\"$because_file\" -> \"$archive_member\";\n";
}
}
print "}\n";

134
cpu/mc1322x/tools/mc1322x-load.pl Executable file
View file

@ -0,0 +1,134 @@
#!/usr/bin/perl -w
use Device::SerialPort;
use Term::ReadKey;
use Getopt::Long;
use Time::HiRes qw(usleep);
use strict;
my $filename = '';
my $second = '';
my $term = '/dev/ttyUSB0';
my $baud = '115200';
my $verbose;
my $rts = 'rts';
GetOptions ('file=s' => \$filename,
'secondfile=s' => \$second,
'terminal=s' => \$term,
'verbose' => \$verbose,
'baud=s' => \$baud,
'rts=s' => \$rts,
) or die 'bad options';
$| = 1;
if($filename eq '') {
print "Example usage: mc1322x-load.pl -f foo.bin -t /dev/ttyS0 -b 9600\n";
print " or : mc1322x-load.pl -f flasher.bin -s flashme.bin 0x1e000,0x11223344,0x55667788\n";
print " -f required: binary file to load\n";
print " -s optional: secondary binary file to send\n";
print " -t default: /dev/ttyUSB0\n";
print " -b default: 115200\n";
print " -r [none|rts] flow control default: rts\n";
print " anything on the command line is sent\n";
print " after all of the files.\n";
exit;
}
if (!(-e $filename)) { die "file $filename not found\n"; }
if (($second ne '') && !(-e $second)) { die "secondary file $second not found\n"; }
my $ob = Device::SerialPort->new ($term) or die "Can't start $term\n";
# next test will die at runtime unless $ob
$ob->baudrate($baud);
$ob->parity('none');
$ob->databits(8);
$ob->stopbits(1);
if($rts eq 'rts') {
$ob->handshake('rts');
} else {
$ob->handshake('none');
}
$ob->read_const_time(1000); # 1 second per unfulfilled "read" call
$ob->rts_active(1);
my $s = 0;
while(1) {
my $c; my $count; my $ret = ''; my $test='';
if($s == 1) { print "secondary send...\n"; }
$ob->write(pack('C','0'));
if($s == 1) {
$test = 'ready';
} else {
$test = 'CONNECT';
}
until($ret =~ /$test$/) {
($count,$c) = $ob->read(1);
if ($count == 0) {
print '.';
$ob->write(pack('C','0'));
next;
}
$ret .= $c;
}
print $ret . "\n";
if (-e $filename) {
my $size = -s $filename;
print ("Size: $size bytes\n");
$ob->write(pack('V',$size));
open(FILE, $filename) or die($!);
print "Sending $filename\n";
my $i = 1;
while(read(FILE, $c, 1)) {
$i++;
usleep(50); # this is as fast is it can go...
usleep(50) if ($s==1);
$ob->write($c);
}
}
last if ($s==1);
if((-e $second)) {
$s=1; $filename = $second;
} else {
last;
}
}
print "done sending files.\n";
if(scalar(@ARGV)!=0) {
print "sending " ;
print @ARGV;
print ",\n";
$ob->write(@ARGV);
$ob->write(',');
}
my $c; my $count;
while(1) {
($count, $c) = $ob->read(1);
print $c if (defined($count) && ($count != 0));
}
$ob -> close or die "Close failed: $!\n";
ReadMode 0;
undef $ob; # closes port AND frees memory in perl
exit;

View file

@ -0,0 +1,91 @@
#!/usr/bin/perl -w
use Device::SerialPort;
use Term::ReadKey;
use Getopt::Long;
use Time::HiRes qw(usleep gettimeofday);
use strict;
my $filename = '';
my $second = '';
my $term = '/dev/ttyUSB0';
my $baud = '115200';
my $verbose;
GetOptions (
'terminal=s' => \$term,
'baud=s' => \$baud,
);
$| = 1;
# TODO: add help argument
# print "Example usage: rftestrx2pcap.pl -t /dev/ttyS0 -b 9600\n";
# exit;
my $ob = Device::SerialPort->new ($term) or die "Can't start $term\n";
# next test will die at runtime unless $ob
$ob->baudrate($baud);
$ob->parity('none');
$ob->databits(8);
$ob->stopbits(1);
$ob->read_const_time(1000); # 1 second per unfulfilled "read" call
my $str = '';
my ($sec, $usec, $len);
my @frame;
my $magic = 0xa1b2c3d4;
my $major = 2;
my $minor = 4;
my $zone = 0;
my $sig = 0;
my $snaplen = 0xffff;
my $network = 195; # 802.15.4
print pack('LSSLLLL',($magic,$major,$minor,$zone,$sig,$snaplen,$network));
while(1) {
my ($count, $c) = $ob->read(1);
if (defined($count) && ($count != 0)) {
$str .= $c;
# match if ends in \n or \r and process line
if(($str =~ /\n$/) ||
($str =~ /\r$/)) {
if($str =~ /^rftest/) {
#new packet
($sec, $usec) = gettimeofday;
print STDERR "rftestline: $sec $usec $str";
} elsif($str =~ /^\s*data/) {
#packet payload
print STDERR "dataline: ";
print STDERR $str;
$str =~ /data: 0x\d+ (.+)/;
my @data = split(' ',$1);
($len, @data) = @data;
#write out pcap entry
print pack('LLLL',($sec,$usec,scalar(@data),scalar(@data)+2));
print STDERR "new packet: $sec $usec " . scalar(@data) . " " . (scalar(@data)+2) . "\n\r";
@frame = @data[0,1];
print pack ('CC',(hex($frame[0]),hex($frame[1])));
print STDERR "$frame[0] $frame[1] ";
foreach my $data (@data[2..scalar(@data)-1]) {
print pack ('C',hex($data));
print STDERR "$data ";
}
print STDERR "\n\r";
}
print STDERR "\n\r";
$str = '';
}
}
}
$ob -> close or die "Close failed: $!\n";
ReadMode 0;
undef $ob; # closes port AND frees memory in perl
exit;

View file

@ -0,0 +1,67 @@
#!/usr/bin/perl -w
use strict;
my $verbose = 1;
####
# Feed data on stdin from a RIME collect sink
#
# Enters data into rimeaddr.rrd
#
# Creates rimeaddr.rrd from a template if data shows up from a source and
# rimeaddr.rrd doesn't exist
#
# default template is read from default.rrdtmpl
#
# if rimeaddr.rrdtmpl exisits, that is used instead.
####
#
# Templates are shell scripts that create the desired rrd
#
####
# Data messages are in the form of:
#
# Sink got message from 1.0, seqno 109, hops 0: len 12 'GPIO29-High'
#
#
my $datapattern = 'Sink got message from ([\d\.]+), seqno \d+, hops \d+: len \d+ \'([\w\d]+-[\w\d]+)\'';
sub rrdcreate {
my ($newrrd_filename, $tmpl_filename) = @_;
open FILE, "$tmpl_filename" or die $!;
my $tmpl = <FILE>;
chomp $tmpl;
print "using template $tmpl found in $tmpl_filename\n" if $verbose;
`rrdtool create $newrrd_filename $tmpl`;
}
while(<>) {
next if($_ !~ /$datapattern/);
print("rimeaddr $1 data $2\n") if $verbose;
my ($ds,$data) = split(/-/,$2);
print("ds: $ds, data: $data\n") if $verbose;
if(-e "$1.rrd") {
# an rrd already exists for this device
# do an update
`rrdtool update $1.rrd -t $ds N:$data`
} else {
# an rrd for this device doesn't exist yet
# find a template and make it
my $tmpl = "DS:speed:COUNTER:600:U:U RRA:AVERAGE:0.5:6:10";
print "creating new rrd $1.rrd... " if $verbose;
if(-e "$1.rrdtmpl") {
rrdcreate("$1.rrd","$1.rrdtmpl");
`rrdtool update $1.rrd -t $ds N:$data`
} elsif(-e "default.rrdtmpl") {
rrdcreate("$1.rrd","default.rrdtmpl");
`rrdtool update $1.rrd -t $ds N:$data`
} else {
print "can't create rrd for $1: no template found\n";
}
}
}

View file

@ -0,0 +1 @@
-s 1 DS:GPIO29:GAUGE:600:U:U RRA:LAST:0.99:1:3600

View file

@ -0,0 +1,70 @@
#!/usr/bin/perl -w
# CGI script that creates a fill-out form
# and echoes back its values.
use CGI qw/:standard/;
# configs
# paths
my $meshpath = "/home/malvira/work";
my $wwwpath = "/var/www";
my $hostname = "hotdog.redwirellc.com";
# aliases
my %aliases = (
"2.0" => {
alias => "Lower Door",
ds=> {
"GPIO29" => "Lock (0 - locked, 1 - unlocked)",
},
},
"4.0" => {
alias => "Upper Door",
},
"1.0" => {
alias => "Hotdog (datasink)",
},
);
opendir(MESHDIR, $meshpath);
my @files = readdir(MESHDIR);
print header;
print start_html('Collect Mesh');
foreach my $file (@files) {
next if $file !~ /([\d\.]+)\.rrd$/;
my $addr = $1;
print hr;
print h1("$addr: $aliases{$addr}{'alias'}");
my @info = split(/\n/,qx(rrdtool info $meshpath/$addr.rrd));
my %dses;
foreach my $info (@info) {
next if $info !~ /ds\[([\w\d]+)\]\.([\w\d_]+)\s+=\s+([\w\d]+)/;
$dses{$1}{$2} = $3;
}
my $lastupdate = qx(rrdtool lastupdate $meshpath/$addr.rrd);
$lastupdate =~ /([\w\d]+)\s+(\d+):\s+([\w\d]+)/;
print localtime($2) . " $1 $3<br>";
foreach my $ds (keys(%dses)) {
print h2("$ds: $aliases{$addr}{'ds'}{$ds}");
qx(rrdtool graph $wwwpath/$addr-$ds.png --start end-60min DEF:$ds=$meshpath/$addr.rrd:$ds:LAST LINE2:$ds#00a000:\"$ds\");
print img({src=>"http://$hostname/$addr-$ds.png"});
}
}
print hr;
print end_html;
#/var/www/demo.png --title="Door" --start end-60min
# --imginfo '<IMG SRC=http://localhost/demo.png>'
# DEF:door=/home/malvira/work/2.0.rrd:GPIO29:LAST
# LINE2:door#00a000:"Door lock">