mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-12-28 07:51:19 +01:00
Merge pull request #3766 from haukepetersen/rm_econotag
boards: removed support for redbee-econotag
This commit is contained in:
commit
128d9db0a5
@ -1,5 +0,0 @@
|
||||
MODULE =$(BOARD)_base
|
||||
|
||||
DIRS = drivers
|
||||
|
||||
include $(RIOTBASE)/Makefile.base
|
||||
@ -1 +0,0 @@
|
||||
FEATURES_MCU_GROUP = arm7
|
||||
@ -1,39 +0,0 @@
|
||||
## the cpu to build for
|
||||
export CPU = mc1322x
|
||||
|
||||
# Target triple for the build. Use arm-none-eabi if you are unsure.
|
||||
export TARGET_TRIPLE ?= arm-none-eabi
|
||||
|
||||
# toolchain config
|
||||
export PREFIX = $(if $(TARGET_TRIPLE),$(TARGET_TRIPLE)-)
|
||||
|
||||
export CC = $(PREFIX)gcc
|
||||
export AR = $(PREFIX)ar
|
||||
export CFLAGS += -march=armv4t -mtune=arm7tdmi-s -mlong-calls \
|
||||
-msoft-float -mthumb-interwork -fno-strict-aliasing -fno-common \
|
||||
-ffixed-r8 -ffunction-sections -ffreestanding -fno-builtin \
|
||||
-nodefaultlibs -Wall -Wstrict-prototypes \
|
||||
-Os -pipe
|
||||
export CFLAGS_MTHUMB ?= -mthumb
|
||||
# TODO add -mthumb
|
||||
export AFLAGS = -Wa,-gstabs $(CFLAGS)
|
||||
export AS = $(PREFIX)as
|
||||
export LINK = $(PREFIX)gcc
|
||||
export SIZE = $(PREFIX)size
|
||||
export OBJCOPY = $(PREFIX)objcopy
|
||||
FLASHER = mc1322x-load.pl
|
||||
TERM = pyterm
|
||||
LINKFLAGS += -mcpu=arm7tdmi-s -static -lgcc -nostartfiles -Wl,--gc-sections -T$(RIOTBASE)/cpu/$(CPU)/mc1322x.lds
|
||||
|
||||
ifeq ($(strip $(PORT)),)
|
||||
export PORT = /dev/ttyUSB0
|
||||
endif
|
||||
export FFLAGS = -t $(PORT) -f $(HEXFILE) -c 'bbmc -l redbee-econotag reset'
|
||||
export OFLAGS = -O binary --gap-fill=0xff
|
||||
export TERMFLAGS += -p "$(PORT)"
|
||||
|
||||
export INCLUDES += -I$(RIOTCPU)/$(CPU)/include/ -I$(RIOTBOARD)/$(BOARD)/include/
|
||||
export INCLUDES += -I$(RIOTCPU)/$(CPU)/maca/include
|
||||
export INCLUDES += -I$(RIOTBOARD)/$(BOARD)/drivers/include
|
||||
|
||||
export UNDEF += $(BINDIR)cpu/startup.o
|
||||
@ -1,11 +0,0 @@
|
||||
Flashing:
|
||||
tools/mc1322x-load.pl -f <path/to/binary> -t /dev/<tty-device>
|
||||
|
||||
more information: https://github.com/malvira/libmc1322x/wiki/libmc1322x#loading-images-to-ram-with-mc1322x-loadpl
|
||||
|
||||
Erase:
|
||||
cd tools/ftditools/
|
||||
make
|
||||
./bbmc -l redbee-econotag erase
|
||||
|
||||
more information: https://github.com/malvira/libmc1322x/wiki/bbmc
|
||||
@ -1,23 +0,0 @@
|
||||
/*
|
||||
* board_init.c - redbee-econotag initialization code
|
||||
* Copyright (C) 2013 Oliver Hahm <oliver.hahm@inria.fr>
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
void board_init(void)
|
||||
{
|
||||
asm("nop");
|
||||
}
|
||||
|
||||
void bl_init_clks(void)
|
||||
{
|
||||
// dummy to compile
|
||||
}
|
||||
|
||||
void bl_init_ports(void)
|
||||
{
|
||||
// dummy to compile
|
||||
}
|
||||
@ -1,7 +0,0 @@
|
||||
MODULE =$(BOARD)_base
|
||||
|
||||
include $(RIOTBOARD)/$(BOARD)/Makefile.include
|
||||
|
||||
INCLUDES += -Iinclude
|
||||
|
||||
include $(RIOTBASE)/Makefile.base
|
||||
@ -1,65 +0,0 @@
|
||||
/*
|
||||
* nvm.h - non-volatile memory specific definitions
|
||||
* Copyright (C) 2013 Thomas Eichinger <thomas.eichinger@fu-berlin.de>
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
#ifndef NVM_H_
|
||||
#define NVM_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum
|
||||
{
|
||||
g_nvm_type_no_nvm_c = 0,
|
||||
g_nvm_type_SST_c,
|
||||
g_nvm_type_ST_c,
|
||||
g_nvm_type_ATM_c,
|
||||
g_nvm_type_Max_c
|
||||
} nvm_type_t;
|
||||
|
||||
|
||||
typedef enum
|
||||
{
|
||||
g_nvm_err_no_error_c = 0,
|
||||
g_nvm_err_invalid_interface_c,
|
||||
g_nvm_err_onvalid_nvm_type_c,
|
||||
g_nvm_err_invalid_pointer_c,
|
||||
g_nvm_err_write_protect_c,
|
||||
g_nvm_err_verify_error_c,
|
||||
g_nvm_err_address_space_overflow_c,
|
||||
g_nvm_err_blank_check_error_c,
|
||||
g_nvm_err_restricted_area_c,
|
||||
g_nvm_err_max_error_c
|
||||
} nvm_err_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
g_nvm_internal_interface_c = 0,
|
||||
g_nvm_external_interface_c,
|
||||
g_nvm_interface_max_c
|
||||
} nvm_interface_t;
|
||||
|
||||
/* ROM code seems to be THUMB */
|
||||
/* need to be in a THUMB block before calling them */
|
||||
extern nvm_err_t (*nvm_detect)(nvm_interface_t nvm_interface,nvm_type_t* p_nvm_type);
|
||||
extern nvm_err_t (*nvm_read)(nvm_interface_t nvm_interface , nvm_type_t nvm_type , void *p_dest, uint32_t address, uint32_t num_bytes);
|
||||
extern nvm_err_t (*nvm_write)(nvm_interface_t nvm_interface, nvm_type_t nvm_type ,void *p_src, uint32_t address, uint32_t num_bytes);
|
||||
/* 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 nvm_err_t (*nvm_erase)(nvm_interface_t nvm_interface, nvm_type_t nvm_type ,uint32_t sector_bitfield);
|
||||
extern void(*nvm_setsvar)(uint32_t zero_for_awesome);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NVM_H_ */
|
||||
@ -1,112 +0,0 @@
|
||||
/*
|
||||
* uart.h - UART driver for redbee
|
||||
* Copyright (C) 2013 Thomas Eichinger <thomas.eichinger@fu-berlin.de>
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
#ifndef UART_H_
|
||||
#define UART_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*-----------------------------------------------------------------*/
|
||||
/* UART */
|
||||
#define UART1_BASE (0x80005000)
|
||||
#define UART2_BASE (0x8000B000)
|
||||
|
||||
struct UART_struct {
|
||||
union {
|
||||
uint32_t CON;
|
||||
struct UART_CON {
|
||||
uint32_t TXE: 1; /*< Tx Enable */
|
||||
uint32_t RXE: 1; /*< Rx Enable */
|
||||
uint32_t PEN: 1; /*< Parity Enable */
|
||||
uint32_t EP: 1; /*< Even Parity (1=Odd, 0=Even) */
|
||||
uint32_t ST2: 1; /*< Enable 2 Stop Bits */
|
||||
uint32_t SB: 1; /*< Send Break */
|
||||
uint32_t CONTX: 1; /*< Continuous Tx (Test Mode) */
|
||||
uint32_t TXOENB: 1; /*< TXD Outbut Disable */
|
||||
uint32_t : 2; /*< reserved */
|
||||
uint32_t XTIM: 1; /*< Times of Oversampling */
|
||||
uint32_t FCP: 1; /*< Flow Control Polarity */
|
||||
uint32_t FCE: 1; /*< Flow Control Enable */
|
||||
uint32_t MTXR: 1; /*< enable/disable TxRDY Interrupts */
|
||||
uint32_t MRXR: 1; /*< enable/disable RxRDY Interrupts */
|
||||
uint32_t TST: 1; /*< Test Loop-Back */
|
||||
uint32_t : 16; /*< reserved */
|
||||
} CONbits;
|
||||
};
|
||||
union {
|
||||
uint32_t STAT;
|
||||
struct UART_STAT {
|
||||
uint32_t SE: 1; /*< Start Bit Error */
|
||||
uint32_t PE: 1; /*< Parity Bit Error */
|
||||
uint32_t FE: 1; /*< Frame/Stop Bit Error */
|
||||
uint32_t TOE: 1; /*< Tx FIFO Overrun Error */
|
||||
uint32_t ROE: 1; /*< Rx FIFO Overrun Error */
|
||||
uint32_t RUE: 1; /*< Rx FIFO Underrun Error */
|
||||
uint32_t RXRDY: 1; /*< Receiver is causing Interrupts */
|
||||
uint32_t TXRDY: 1; /*< Transmitter is causing Interrupts */
|
||||
uint32_t : 24;
|
||||
} USTATbits;
|
||||
};
|
||||
union {
|
||||
uint32_t DATA;
|
||||
struct UART_DATA {
|
||||
uint32_t DATA: 8;
|
||||
uint32_t : 24;
|
||||
} DATAbits;
|
||||
};
|
||||
union {
|
||||
uint32_t RXCON;
|
||||
struct UART_URXCON {
|
||||
uint32_t LVL: 6;
|
||||
uint32_t : 26;
|
||||
} RXCONbits;
|
||||
};
|
||||
union {
|
||||
uint32_t TXCON;
|
||||
struct UART_TXCON {
|
||||
uint32_t LVL: 6;
|
||||
uint32_t : 26;
|
||||
} TXCONbits;
|
||||
};
|
||||
union {
|
||||
uint32_t CTS;
|
||||
struct UART_CTS {
|
||||
uint32_t LVL: 5;
|
||||
uint32_t : 27;
|
||||
} CTSbits;
|
||||
};
|
||||
|
||||
uint32_t BR; /*< BR is 32bit access only */
|
||||
};
|
||||
|
||||
static volatile struct UART_struct *const UART1 = (void *)(UART1_BASE);
|
||||
static volatile struct UART_struct *const UART2 = (void *)(UART2_BASE);
|
||||
|
||||
void uart_init(volatile struct UART_struct *uart, uint32_t baud);
|
||||
void uart_set_baudrate(volatile struct UART_struct *uart, uint32_t baud);
|
||||
void uart_flow_ctl(volatile struct UART_struct *uart, uint8_t on);
|
||||
|
||||
#undef UART0_BUFSIZE
|
||||
#define UART0_BUFSIZE (32)
|
||||
|
||||
void uart1_putc(uint8_t c);
|
||||
uint8_t uart1_getc(void);
|
||||
|
||||
void uart2_putc(uint8_t c);
|
||||
uint8_t uart2_getc(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,23 +0,0 @@
|
||||
/*
|
||||
* nvm.c - non-volatile memory implementations
|
||||
* Copyright (C) 2013 Thomas Eichinger <thomas.eichinger@fu-berlin.de>
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*
|
||||
* This file is part of RIOT.
|
||||
*/
|
||||
|
||||
#include "nvm.h"
|
||||
|
||||
nvm_err_t (*nvm_detect) (nvm_interface_t nvm_interface, nvm_type_t* p_nvm_type)
|
||||
= (void*) 0x00006cb9;
|
||||
nvm_err_t (*nvm_read) (nvm_interface_t nvm_interface, nvm_type_t nvm_type, void *p_dest, uint32_t address, uint32_t num_bytes)
|
||||
= (void*) 0x00006d69;
|
||||
nvm_err_t (*nvm_write) (nvm_interface_t nvm_interface, nvm_type_t nvm_type, void *p_src, uint32_t address, uint32_t numb_bytes)
|
||||
= (void*) 0x00006ec5;
|
||||
nvm_err_t (*nvm_erase) (nvm_interface_t nvm_interface, nvm_type_t nvm_type, uint32_t sector_bitfield)
|
||||
= (void*) 0x00006e05;
|
||||
void (*nvm_setsvar) (uint32_t zero_is_for_winners)
|
||||
= (void*) 0x00007085;
|
||||
@ -1,178 +0,0 @@
|
||||
/*
|
||||
* redbee_uart.c - UART driver for redbee
|
||||
* Copyright (C) 2013 Thomas Eichinger <thomas.eichinger@fu-berlin.de>
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
#include "mc1322x.h"
|
||||
#include "uart.h"
|
||||
#include "gpio.h"
|
||||
|
||||
#define MOD_ 9999
|
||||
#define CLK_ 24000000
|
||||
#define DIV_ 16 /* uart->CON.XTIM = 0 is 16x oversample (datasheet is incorrect) */
|
||||
#define BAUTRATE_UART1 115200
|
||||
#define BAUTRATE_UART2 115200
|
||||
|
||||
void uart_set_baudrate(volatile struct UART_struct *uart, uint32_t baudrate)
|
||||
{
|
||||
uint64_t inc = 0;
|
||||
|
||||
/* calculate inc following equation 13-1 from datasheet */
|
||||
/* multiply by another 10 to get a fixed point*/
|
||||
inc = ((uint64_t) baudrate * DIV_ * MOD_ * 10 / CLK_) - 10;
|
||||
/* add 5 and div by 10 to get a proper rounding */
|
||||
inc = (inc + 5) / 10;
|
||||
|
||||
/* disable UARTx to set baudrate */
|
||||
uart->CONbits.TXE = 0;
|
||||
uart->CONbits.RXE = 0;
|
||||
|
||||
/* set baudrate */
|
||||
/* BR register is 32bit access only */
|
||||
uart->BR = (((uint16_t) inc << 16) | MOD_);
|
||||
|
||||
/* reenable UARTx again */
|
||||
/* uart->CON.XTIM = 0 is 16x oversample (datasheet is incorrect) */
|
||||
uart->CONbits.XTIM = 0;
|
||||
uart->CONbits.TXE = 1;
|
||||
uart->CONbits.RXE = 1;
|
||||
}
|
||||
|
||||
void uart_flow_ctl(volatile struct UART_struct *uart, uint8_t on)
|
||||
{
|
||||
if (on) {
|
||||
/* enable flow control */
|
||||
if (uart == UART1) {
|
||||
/* CTS and RTS directions */
|
||||
GPIO->PAD_DIR_SET.U1CTS = 1;
|
||||
GPIO->PAD_DIR_RESET.U1RTS = 1;
|
||||
/* function select to uart */
|
||||
GPIO->FUNC_SEL.U1CTS = 1;
|
||||
GPIO->FUNC_SEL.U1RTS = 1;
|
||||
}
|
||||
else {
|
||||
/* UART2 */
|
||||
/* CTS and RTS directions */
|
||||
GPIO->PAD_DIR_SET.U2CTS = 1;
|
||||
GPIO->PAD_DIR_RESET.U2RTS = 1;
|
||||
/* function select to uart */
|
||||
GPIO->FUNC_SEL.U2CTS = 1;
|
||||
GPIO->FUNC_SEL.U2RTS = 1;
|
||||
}
|
||||
|
||||
/* enable flow control */
|
||||
uart->CONbits.FCE = 1;
|
||||
}
|
||||
else {
|
||||
/* disable flow control */
|
||||
uart->CONbits.FCE = 0;
|
||||
|
||||
if (uart == UART1) {
|
||||
/* CTS and RTS directions */
|
||||
GPIO->PAD_DIR_RESET.U1CTS = 1;
|
||||
GPIO->PAD_DIR_RESET.U1RTS = 1;
|
||||
/* function select to GPIO */
|
||||
GPIO->FUNC_SEL.U1CTS = 3;
|
||||
GPIO->FUNC_SEL.U1RTS = 3;
|
||||
}
|
||||
else {
|
||||
/* CTS and RTS directions */
|
||||
GPIO->PAD_DIR_RESET.U2CTS = 1;
|
||||
GPIO->PAD_DIR_RESET.U2RTS = 1;
|
||||
/* function select to GPIO */
|
||||
GPIO->FUNC_SEL.U2CTS = 3;
|
||||
GPIO->FUNC_SEL.U2RTS = 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void uart_init(volatile struct UART_struct *uart, uint32_t baudrate)
|
||||
{
|
||||
/* enable the uart so we can set the gpio mode */
|
||||
/* has to be enabled before setting the function with GPIO->FUNC_SEL */
|
||||
uart->CONbits.TXE = 1;
|
||||
uart->CONbits.RXE = 1;
|
||||
|
||||
if (uart == UART1) {
|
||||
/* TX and RX direction */
|
||||
GPIO->PAD_DIR_SET.U1TX = 1;
|
||||
GPIO->PAD_DIR_RESET.U1RX = 1;
|
||||
|
||||
/* set function selection to UART */
|
||||
GPIO->FUNC_SEL.U1TX = 1;
|
||||
GPIO->FUNC_SEL.U1RX = 1;
|
||||
|
||||
UART1->CONbits.TXE = 1; /*< enable transmit */
|
||||
UART1->CONbits.RXE = 1; /*< enable receive */
|
||||
|
||||
UART1->CONbits.FCE = 1; /*< enable flowcontrol */
|
||||
UART1->CONbits.MRXR = 1; /*< disable Rx interrupt */
|
||||
UART1->CTSbits.LVL = 31; /*< drop cts when tx buffer at trigger level */
|
||||
GPIO->FUNC_SEL.U1CTS = 1; /*< set GPIO 16 to UART1 CTS */
|
||||
GPIO->FUNC_SEL.U1RTS = 1; /*< set GPIO 17 to UART1 RTS */
|
||||
|
||||
ITC->INTENABLEbits.UART1 = 1;
|
||||
|
||||
}
|
||||
else {
|
||||
/* UART2 */
|
||||
/* TX and RX direction */
|
||||
GPIO->PAD_DIR_SET.U2TX = 1;
|
||||
GPIO->PAD_DIR_RESET.U2RX = 1;
|
||||
|
||||
/* set function selection to UART */
|
||||
GPIO->FUNC_SEL.U2TX = 1;
|
||||
GPIO->FUNC_SEL.U2RX = 1;
|
||||
|
||||
UART2->CONbits.TXE = 1; /*< enable transmit */
|
||||
UART2->CONbits.RXE = 1; /*< enable receive */
|
||||
|
||||
UART2->CONbits.FCE = 1; /*< enable flowcontrol */
|
||||
UART2->CONbits.MRXR = 1; /*< disable Rx interrupt */
|
||||
UART2->CTSbits.LVL = 31; /*< drop cts when tx buffer at trigger level */
|
||||
GPIO->FUNC_SEL.U2CTS = 1; /*< set GPIO 20 to UART2 CTS */
|
||||
GPIO->FUNC_SEL.U2RTS = 1; /*< set GPIO 21 to UART2 RTS */
|
||||
|
||||
ITC->INTENABLEbits.UART2 = 1;
|
||||
}
|
||||
|
||||
uart_set_baudrate(uart, baudrate);
|
||||
|
||||
}
|
||||
|
||||
int uart0_puts(uint8_t *astring, uint32_t length)
|
||||
{
|
||||
uint32_t i = 0;
|
||||
|
||||
for (; i < length; i++) {
|
||||
uart1_putc(astring[i]);
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
void stdio_flush(void)
|
||||
{
|
||||
ITC->INTENABLEbits.UART1 = 0;
|
||||
ITC->INTENABLEbits.UART2 = 0;
|
||||
|
||||
while (UART1->RXCON != 0 || UART2->RXCON != 0) {
|
||||
UART1->DATA;
|
||||
UART2->DATA;
|
||||
}
|
||||
while (UART1->TXCON != 0 || UART2->TXCON != 0) {
|
||||
/* wait */
|
||||
}
|
||||
|
||||
ITC->INTENABLEbits.UART1 = 1;
|
||||
ITC->INTENABLEbits.UART2 = 1;
|
||||
}
|
||||
|
||||
void bl_uart_init(void)
|
||||
{
|
||||
uart_init(UART1, BAUTRATE_UART1);
|
||||
}
|
||||
@ -1,56 +0,0 @@
|
||||
/*
|
||||
* uart1.c - UART1 driver for redbee
|
||||
* Copyright (C) 2013 Oliver Hahm <oliver.hahm@inria.fr>
|
||||
* 2013 Thomas Eichinger <thomas.eichinger@fu-berlin.de>
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
#include "mc1322x.h"
|
||||
#include "board_uart0.h"
|
||||
#include "uart.h"
|
||||
|
||||
void uart1_isr(void)
|
||||
{
|
||||
if (UART1->USTATbits.RXRDY == 1) {
|
||||
#ifdef MODULE_UART0
|
||||
|
||||
if (uart0_handler_pid != KERNEL_PID_UNDEF) {
|
||||
uint32_t i = 0;
|
||||
while (UART1->RXCON != 0) {
|
||||
uart0_handle_incoming(UART1->DATA);
|
||||
|
||||
if (++i >= UART0_BUFSIZE) {
|
||||
uart0_notify_thread();
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
|
||||
uart0_notify_thread();
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void uart1_putc(uint8_t c)
|
||||
{
|
||||
/* while uart fifo is full */
|
||||
while (UART1->TXCON == 0) {
|
||||
/* wait */
|
||||
}
|
||||
|
||||
UART1->DATA = c;
|
||||
}
|
||||
|
||||
uint8_t uart1_getc(void)
|
||||
{
|
||||
/* while uart fifo is empty */
|
||||
while (UART1->RXCON == 0) {
|
||||
/* wait */
|
||||
}
|
||||
|
||||
return UART1->DATA;
|
||||
}
|
||||
@ -1,56 +0,0 @@
|
||||
/*
|
||||
* uart1.c - UART1 driver for redbee
|
||||
* Copyright (C) 2013 Oliver Hahm <oliver.hahm@inria.fr>
|
||||
* 2013 Thomas Eichinger <thomas.eichinger@fu-berlin.de>
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
#include "mc1322x.h"
|
||||
#include "board_uart0.h"
|
||||
#include "uart.h"
|
||||
|
||||
void uart2_isr(void)
|
||||
{
|
||||
if (UART2->USTATbits.RXRDY == 1) {
|
||||
#ifdef MODULE_UART0
|
||||
|
||||
if (uart0_handler_pid != KERNEL_PID_UNDEF) {
|
||||
uint32_t i = 0;
|
||||
while (UART2->RXCON != 0) {
|
||||
uart0_handle_incoming(UART2->DATA);
|
||||
|
||||
if (++i >= UART0_BUFSIZE) {
|
||||
uart0_notify_thread();
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
|
||||
uart0_notify_thread();
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void uart2_putc(uint8_t c)
|
||||
{
|
||||
/* while uart fifo is full */
|
||||
while (UART2->TXCON == 0) {
|
||||
/* wait */
|
||||
}
|
||||
|
||||
UART2->DATA = c;
|
||||
}
|
||||
|
||||
uint8_t uart2_getc(void)
|
||||
{
|
||||
/* while uart fifo is empty */
|
||||
while (UART2->RXCON == 0) {
|
||||
/* wait */
|
||||
}
|
||||
|
||||
return UART2->DATA;
|
||||
}
|
||||
@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Thomas Eichinger <thomas.eichinger@fu-berlin.de>
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup boards_redbee-econotag Redbee Econotag
|
||||
* @ingroup boards
|
||||
* @brief Support for the Redbee Econotag board
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Basic definitions for the Redbee Econotag board
|
||||
*
|
||||
* @author Thomas Eichinger <thomas.eichinger@fu-berlin.de>
|
||||
*/
|
||||
|
||||
#ifndef REDBEE_ECONOTAG_BOARD_H_
|
||||
#define REDBEE_ECONOTAG_BOARD_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define F_CPU (24000000) /**< CPU target speed in Hz */
|
||||
|
||||
#define CTUNE 0xb
|
||||
#define IBIAS 0x1f
|
||||
#define FTUNE 0x7
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
/** @} */
|
||||
@ -1,24 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2014 INRIA
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser General
|
||||
* Public License v2.1. See the file LICENSE in the top level directory for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup boards_redbee-econotag
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Redbee Econotag peripheral configuration
|
||||
*
|
||||
* @author Oliver Hahm <oliver.hahm@inria.fr>
|
||||
*/
|
||||
|
||||
#ifndef PERIPH_CONF_H_
|
||||
#define PERIPH_CONF_H_
|
||||
|
||||
/* make Travis happy: #ifdef __cplusplus extern "C" { #endif */
|
||||
|
||||
#endif /* PERIPH_CONF_H_ */
|
||||
@ -1,17 +0,0 @@
|
||||
INSTALL= /usr/local/bin
|
||||
|
||||
################
|
||||
|
||||
LDLIBS = -lftdi
|
||||
|
||||
TARGETS = bbmc
|
||||
|
||||
CFLAGS = -Wall -Wextra #-Werror
|
||||
|
||||
all: $(TARGETS)
|
||||
|
||||
clean:
|
||||
-rm -f $(TARGETS)
|
||||
|
||||
install: all
|
||||
cp bbmc $(INSTALL)
|
||||
@ -1,571 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
/* control reset and VREF2 lines */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdint.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 FLEXIBITY_USB_RESET high(2)
|
||||
#define FLEXIBITY_USB_VREF2L high(7)
|
||||
#define FLEXIBITY_USB_VREF2H high(6)
|
||||
#define FLEXIBITY_USB_INTERFACE INTERFACE_A
|
||||
|
||||
#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 = "flexibity",
|
||||
.desc = "Flexibity USB Interface",
|
||||
std_layout(FLEXIBITY_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;
|
||||
|
||||
#if __APPLE__
|
||||
static void restore_ftdi_kext(void)
|
||||
{
|
||||
system("sudo kextload /System/Library/Extensions/FTDIUSBSerialDriver.kext");
|
||||
}
|
||||
#endif
|
||||
|
||||
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, "%11i", &interface);
|
||||
}
|
||||
|
||||
if (strcmp(long_options[option_index].name, "dir") == 0) {
|
||||
sscanf(optarg, "%11i", &dir);
|
||||
}
|
||||
|
||||
if (strcmp(long_options[option_index].name, "reset_release") == 0) {
|
||||
sscanf(optarg, "%11i", &reset_release);
|
||||
}
|
||||
|
||||
if (strcmp(long_options[option_index].name, "reset_set") == 0) {
|
||||
sscanf(optarg, "%11i", &reset_set);
|
||||
}
|
||||
|
||||
if (strcmp(long_options[option_index].name, "vref2_normal") == 0) {
|
||||
sscanf(optarg, "%11i", &vref2_normal);
|
||||
}
|
||||
|
||||
if (strcmp(long_options[option_index].name, "vref2_erase") == 0) {
|
||||
sscanf(optarg, "%11i", &vref2_erase);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'l':
|
||||
strncpy(layout_str, optarg, BUF_LEN);
|
||||
break;
|
||||
|
||||
case 'i':
|
||||
dev_index = atoi(optarg);
|
||||
break;
|
||||
|
||||
case 'v':
|
||||
sscanf(optarg, "%11i", &vendid);
|
||||
break;
|
||||
|
||||
case 'p':
|
||||
sscanf(optarg, "%11i", &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 ((ret = ftdi_set_interface(&ftdic, layout.interface)) < 0) {
|
||||
fprintf(stderr, "couldn't set interface %d, err %d (%s)\n", layout.interface, ret, ftdi_get_error_string(&ftdic));
|
||||
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) {
|
||||
#if __APPLE__
|
||||
|
||||
if ((ret == -5) && (0 == system("sudo kextunload /System/Library/Extensions/FTDIUSBSerialDriver.kext"))) {
|
||||
// Try again without the FTDI kext loaded this time
|
||||
atexit(&restore_ftdi_kext);
|
||||
ret = ftdi_usb_open_desc_index(
|
||||
&ftdic,
|
||||
vendid,
|
||||
prodid,
|
||||
NULL,
|
||||
NULL,
|
||||
dev_index
|
||||
);
|
||||
}
|
||||
|
||||
if (ret)
|
||||
#endif // __APPLE__
|
||||
{
|
||||
fprintf(stderr, "couldn't open dev_index %d, err %d (%s)\n", dev_index, ret, ftdi_get_error_string(&ftdic));
|
||||
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;
|
||||
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);
|
||||
|
||||
int ret = ftdi_usb_get_strings(&ftdic,
|
||||
curdev->dev,
|
||||
manufacturer, 128,
|
||||
description, 128,
|
||||
serial, 128);
|
||||
if (0 > ret) {
|
||||
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') {
|
||||
/* cppcheck: input is accessed later via *s */
|
||||
/* cppcheck-suppress unreadVariable */
|
||||
input[last] = '\0';
|
||||
}
|
||||
|
||||
sscanf(s, "%11i", &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];
|
||||
|
||||
/* 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 ((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;
|
||||
|
||||
}
|
||||
@ -1,385 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2012, Maxim Osipov <maxim.osipov@gmail.com>
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <termios.h>
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
char *filename;
|
||||
char *second;
|
||||
char *term = "/dev/ttyUSB0";
|
||||
int baud = B115200;
|
||||
int verbose = 0;
|
||||
char *rts = "rts";
|
||||
char *command;
|
||||
int first_delay = 50;
|
||||
int second_delay = 100;
|
||||
int do_exit = 0;
|
||||
int zerolen = 0;
|
||||
char *args = NULL;
|
||||
|
||||
struct stat sbuf;
|
||||
struct termios options;
|
||||
char buf[256];
|
||||
int pfd;
|
||||
int ffd;
|
||||
int sfd;
|
||||
|
||||
void help(void);
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int c = 0;
|
||||
int r = 0;
|
||||
int i = 0;
|
||||
uint32_t s = 0;
|
||||
opterr = 0;
|
||||
|
||||
/* Parse options */
|
||||
while ((c = getopt(argc, argv, "f:s:zt:vu:r:c:a:b:eh")) != -1) {
|
||||
switch (c) {
|
||||
case 'f':
|
||||
filename = optarg;
|
||||
break;
|
||||
|
||||
case 's':
|
||||
second = optarg;
|
||||
break;
|
||||
|
||||
case 'z':
|
||||
zerolen = 1;
|
||||
break;
|
||||
|
||||
case 't':
|
||||
term = optarg;
|
||||
break;
|
||||
|
||||
case 'v':
|
||||
verbose = 1;
|
||||
break;
|
||||
|
||||
case 'u':
|
||||
if (strcmp(optarg, "115200")) {
|
||||
baud = B115200;
|
||||
}
|
||||
else if (strcmp(optarg, "57600")) {
|
||||
baud = B115200;
|
||||
}
|
||||
else if (strcmp(optarg, "19200")) {
|
||||
baud = B19200;
|
||||
}
|
||||
else if (strcmp(optarg, "9600")) {
|
||||
baud = B9600;
|
||||
}
|
||||
else {
|
||||
printf("Unknown baud rate %s!\n", optarg);
|
||||
return -1;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
rts = optarg;
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
command = optarg;
|
||||
break;
|
||||
|
||||
case 'a':
|
||||
first_delay = atoi(optarg);
|
||||
break;
|
||||
|
||||
case 'b':
|
||||
second_delay = atoi(optarg);
|
||||
break;
|
||||
|
||||
case 'e':
|
||||
do_exit = 1;
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
case '?':
|
||||
help();
|
||||
return 0;
|
||||
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
/* Get other arguments */
|
||||
if (optind < argc) {
|
||||
args = argv[optind];
|
||||
}
|
||||
|
||||
/* Print settings */
|
||||
if (verbose) {
|
||||
printf("Primary file (RAM): %s\n", filename);
|
||||
printf("Secondary file (Flash): %s\n", second);
|
||||
printf("Zero secondary file: %s\n", zerolen == 1 ? "Yes" : "No");
|
||||
printf("Port: %s\n", term);
|
||||
printf("Baud rate: %i\n", baud);
|
||||
printf("Flow control: %s\n", rts);
|
||||
printf("Reset command: %s\n", command);
|
||||
printf("Exit after load: %s\n", do_exit == 1 ? "Yes" : "No");
|
||||
printf("Delay 1: %i\n", first_delay);
|
||||
printf("Delay 2: %i\n", second_delay);
|
||||
}
|
||||
|
||||
/* Open and configure serial port */
|
||||
pfd = open(term, O_RDWR | O_NOCTTY | O_NDELAY);
|
||||
|
||||
if (pfd == -1) {
|
||||
printf("Cannot open serial port %s!\n", term);
|
||||
return -1;
|
||||
}
|
||||
|
||||
fcntl(pfd, F_SETFL, FNDELAY);
|
||||
tcgetattr(pfd, &options);
|
||||
cfsetispeed(&options, baud);
|
||||
options.c_cflag |= (CLOCAL | CREAD);
|
||||
options.c_cflag &= ~PARENB;
|
||||
options.c_cflag &= ~CSTOPB;
|
||||
options.c_cflag &= ~CSIZE;
|
||||
options.c_cflag |= CS8;
|
||||
|
||||
if (strcmp(rts, "rts")) {
|
||||
options.c_cflag &= ~CRTSCTS;
|
||||
}
|
||||
else {
|
||||
options.c_cflag |= CRTSCTS;
|
||||
}
|
||||
|
||||
options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
|
||||
options.c_oflag &= ~OPOST;
|
||||
tcsetattr(pfd, TCSANOW, &options);
|
||||
|
||||
/* Reset the board if we can */
|
||||
printf("Reset the board to enter bootloader (waiting for CONNECT)...\n");
|
||||
|
||||
if (command) {
|
||||
printf("Performing reset: %s\n", command);
|
||||
system(command);
|
||||
}
|
||||
|
||||
/* Primary bootloader wait loop */
|
||||
i = 0;
|
||||
|
||||
while (1) {
|
||||
/* Wait for CONNECT */
|
||||
write(pfd, (const void *)"\0", 1);
|
||||
sleep(1);
|
||||
r = read(pfd, &buf[i], sizeof(buf) - 1 - i);
|
||||
|
||||
if (r > 0) {
|
||||
buf[i + r] = '\0';
|
||||
printf("%s", &buf[i]);
|
||||
fflush(stdout);
|
||||
|
||||
if (strstr(&buf[i], "CONNECT")) {
|
||||
printf("\n");
|
||||
break;
|
||||
}
|
||||
|
||||
i += r;
|
||||
|
||||
if (i >= sizeof(buf) - 1) {
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
printf(".");
|
||||
fflush(stdout);
|
||||
}
|
||||
}
|
||||
|
||||
/* Send primary file */
|
||||
if (!filename) {
|
||||
printf("Please specify firmware file name (-f option)!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (stat(filename, &sbuf)) {
|
||||
printf("Cannot open firmware file %s!\n", filename);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ffd = open(filename, O_RDONLY);
|
||||
|
||||
if (ffd == -1) {
|
||||
printf("Cannot open firmware file %s!\n", filename);
|
||||
return -1;
|
||||
}
|
||||
|
||||
s = sbuf.st_size;
|
||||
printf("Sending %s (%i bytes)...\n", filename, s);
|
||||
write(pfd, (const void *)&s, 4);
|
||||
i = 0;
|
||||
r = read(ffd, buf, 1);
|
||||
|
||||
while (r > 0) {
|
||||
do {
|
||||
usleep(first_delay);
|
||||
c = write(pfd, (const void *)buf, r);
|
||||
}
|
||||
while (c < r);
|
||||
|
||||
i += r;
|
||||
printf("Written %i\r", i);
|
||||
fflush(stdout);
|
||||
r = read(ffd, buf, 1);
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
|
||||
/* Secondary loader wait loop */
|
||||
if (second || zerolen) {
|
||||
/* Wait for ready */
|
||||
printf("Sending secondary file (waiting for ready)...\n");
|
||||
i = 0;
|
||||
|
||||
while (1) {
|
||||
sleep(1);
|
||||
r = read(pfd, &buf[i], sizeof(buf) - 1 - i);
|
||||
|
||||
if (r > 0) {
|
||||
buf[i + r] = '\0';
|
||||
printf("%s", &buf[i]);
|
||||
fflush(stdout);
|
||||
|
||||
if (strstr(buf, "ready")) {
|
||||
printf("\n");
|
||||
break;
|
||||
}
|
||||
|
||||
i += r;
|
||||
|
||||
if (i >= sizeof(buf) - 1) {
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
printf(".");
|
||||
fflush(stdout);
|
||||
}
|
||||
}
|
||||
|
||||
/* Send secondary file */
|
||||
if (second) {
|
||||
if (stat(second, &sbuf)) {
|
||||
printf("Cannot open secondary file %s!\n", second);
|
||||
return -1;
|
||||
}
|
||||
|
||||
sfd = open(second, O_RDONLY);
|
||||
|
||||
if (sfd == -1) {
|
||||
printf("Cannot open secondary file %s!\n", second);
|
||||
return -1;
|
||||
}
|
||||
|
||||
s = sbuf.st_size;
|
||||
printf("Sending %s (%i bytes)...\n", second, s);
|
||||
write(pfd, (const void *)&s, 4);
|
||||
i = 0;
|
||||
r = read(sfd, buf, 1);
|
||||
|
||||
while (r > 0) {
|
||||
do {
|
||||
usleep(second_delay);
|
||||
c = write(pfd, (const void *)buf, r);
|
||||
}
|
||||
while (c < r);
|
||||
|
||||
i += r;
|
||||
printf("Written %i\r", i);
|
||||
fflush(stdout);
|
||||
r = read(sfd, buf, 1);
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
}
|
||||
else if (zerolen) {
|
||||
s = 0;
|
||||
printf("Sending %i...\n", s);
|
||||
write(pfd, (const void *)&s, 4);
|
||||
}
|
||||
}
|
||||
|
||||
/* Send the remaining arguments */
|
||||
if (args) {
|
||||
printf("Sending %s\n", args);
|
||||
write(pfd, (const void *)args, strlen(args));
|
||||
r = write(pfd, (const void *)",", 1);
|
||||
}
|
||||
|
||||
/* Drop in echo mode */
|
||||
if (!do_exit) {
|
||||
while (1) {
|
||||
r = read(pfd, buf, sizeof(buf));
|
||||
|
||||
if (r > 0) {
|
||||
buf[r] = '\0';
|
||||
printf("%s", buf);
|
||||
fflush(stdout);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void help(void)
|
||||
{
|
||||
printf("Example usage: mc1322x-load -f foo.bin -t /dev/ttyS0 -b 9600\n");
|
||||
printf(" or : mc1322x-load -f flasher.bin -s flashme.bin 0x1e000,0x11223344,0x55667788\n");
|
||||
printf(" or : mc1322x-load -f flasher.bin -z 0x1e000,0x11223344,0x55667788\n");
|
||||
printf(" -f required: binary file to load\n");
|
||||
printf(" -s optional: secondary binary file to send\n");
|
||||
printf(" -z optional: send a zero length file as secondary\n");
|
||||
printf(" -t, terminal default: /dev/ttyUSB0\n");
|
||||
printf(" -u, baud rate default: 115200\n");
|
||||
printf(" -r [none|rts] flow control default: rts\n");
|
||||
printf(" -c command to run for autoreset: \n");
|
||||
printf(" e.g. -c 'bbmc -l redbee-econotag -i 0 reset'\n");
|
||||
printf(" -e exit instead of dropping to terminal display\n");
|
||||
printf(" -a first intercharacter delay, passed to usleep\n");
|
||||
printf(" -b second intercharacter delay, passed to usleep\n");
|
||||
printf("\n");
|
||||
printf("Anything on the command line is sent after all of the files.\n\n");
|
||||
}
|
||||
@ -1,170 +0,0 @@
|
||||
#!/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';
|
||||
my $command = '';
|
||||
my $first_delay = 50;
|
||||
my $second_delay = 100;
|
||||
my $do_exit;
|
||||
my $zerolen;
|
||||
|
||||
GetOptions ('file=s' => \$filename,
|
||||
'secondfile=s' => \$second,
|
||||
'zerolen' => \$zerolen,
|
||||
'terminal=s' => \$term,
|
||||
'verbose' => \$verbose,
|
||||
'u|baud=s' => \$baud,
|
||||
'rts=s' => \$rts,
|
||||
'command=s' => \$command,
|
||||
'a=s' => \$first_delay,
|
||||
'b=s' => \$second_delay,
|
||||
'exit' => \$do_exit,
|
||||
) 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 " or : mc1322x-load.pl -f flasher.bin -z 0x1e000,0x11223344,0x55667788\n";
|
||||
print " -f required: binary file to load\n";
|
||||
print " -s optional: secondary binary file to send\n";
|
||||
print " -z optional: send a zero length file as secondary\n";
|
||||
print " -t, terminal default: /dev/ttyUSB0\n";
|
||||
print " -u, --baud baud rate default: 115200\n";
|
||||
print " -r [none|rts] flow control default: rts\n";
|
||||
print " -c command to run for autoreset: \n";
|
||||
print " e.g. -c 'bbmc -l redbee-econotag -i 0 reset'\n";
|
||||
print " -e exit instead of dropping to terminal display\n";
|
||||
print " -a first intercharacter delay, passed to usleep\n";
|
||||
print " -b second intercharacter delay, passed to usleep\n";
|
||||
print "\n";
|
||||
print "anything on the command line is sent\n";
|
||||
print "after all of the files.\n\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;
|
||||
my $reset = 0;
|
||||
my $size = 0;
|
||||
|
||||
while(1) {
|
||||
|
||||
my $c; my $count; my $ret = ''; my $test='';
|
||||
|
||||
if($s == 1) { print "secondary send...\n"; }
|
||||
|
||||
$ob->write(pack('C','0'));
|
||||
|
||||
if(($command ne '') &&
|
||||
($reset eq 0)) {
|
||||
$reset++;
|
||||
system($command);
|
||||
}
|
||||
|
||||
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 || (defined($zerolen) && ($s == 1))) {
|
||||
|
||||
if(defined($zerolen) && ($s == 1)) {
|
||||
$size = 0;
|
||||
} else {
|
||||
$size = -s $filename;
|
||||
}
|
||||
|
||||
print ("Size: $size bytes\n");
|
||||
$ob->write(pack('V',$size));
|
||||
|
||||
if(($s == 0) ||
|
||||
((!defined($zerolen)) && ($s == 1))) {
|
||||
open(FILE, $filename) or die($!);
|
||||
print "Sending $filename\n";
|
||||
|
||||
my $i = 1;
|
||||
while(read(FILE, $c, 1)) {
|
||||
$i++;
|
||||
usleep($first_delay) if ( $s == 0 ) && ($first_delay != 0);
|
||||
usleep($second_delay) if ( $s == 1 ) && ($second_delay != 0);
|
||||
$ob->write($c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
last if ($s==1);
|
||||
if((-e $second) || defined($zerolen)) {
|
||||
$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(',');
|
||||
}
|
||||
|
||||
if(defined($do_exit)) {
|
||||
exit;
|
||||
}
|
||||
|
||||
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;
|
||||
@ -144,15 +144,10 @@ arm_irq_handler:
|
||||
MRS R1, CPSR
|
||||
MSR SPSR, R1
|
||||
|
||||
.if (CPU != mc1322x)
|
||||
/* jump into vic interrupt */
|
||||
mov r0, #0xffffff00 /* lpc23xx */
|
||||
ldr r0, [r0]
|
||||
add lr,pc,#4
|
||||
.else
|
||||
/* mc1322x seems to lack a VIC, distinction of IRQ has to be done in SW */
|
||||
ldr r0, =isr /* mc1322x */
|
||||
.endif
|
||||
|
||||
mov pc, r0
|
||||
|
||||
|
||||
@ -1,14 +0,0 @@
|
||||
MODULE =cpu
|
||||
|
||||
DIRS = $(RIOTCPU)/arm7_common
|
||||
ifneq (,$(filter mc1322x_adc,$(USEMODULE)))
|
||||
DIRS += adc
|
||||
endif
|
||||
ifneq (,$(filter mc1322x_asm,$(USEMODULE)))
|
||||
DIRS += asm
|
||||
endif
|
||||
ifneq (,$(filter mc1322x,$(USEMODULE)))
|
||||
DIRS += maca
|
||||
endif
|
||||
|
||||
include $(RIOTBASE)/Makefile.base
|
||||
@ -1,8 +0,0 @@
|
||||
INCLUDES += -I$(RIOTCPU)/$(CPU)/include
|
||||
INCLUDES += -I$(RIOTCPU)/$(CPU)/maca/include
|
||||
|
||||
include $(RIOTCPU)/arm7_common/Makefile.include
|
||||
|
||||
export UNDEF += $(BINDIR)cpu/mc1322x_syscalls.o $(BINDIR)cpu/syscalls.o
|
||||
|
||||
export USEMODULE += arm7_common
|
||||
@ -1,5 +0,0 @@
|
||||
INCLUDES = -I$(RIOTBASE)/cpu/mc1322x/adc/include
|
||||
|
||||
MODULE =mc1322x_adc
|
||||
|
||||
include $(RIOTBASE)/Makefile.base
|
||||
@ -1,189 +0,0 @@
|
||||
/*
|
||||
* adc.c - implementation of the Analog to Digital Converter module of the mc1322x MCU
|
||||
* Copyright (C) 2013 Thomas Eichinger <thomas.eichinger@fu-berlin.de>
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
#include "mc1322x-adc.h"
|
||||
#include "gpio.h"
|
||||
|
||||
#define ADC_CLOCK_DIVIDER_300kHz 0x50
|
||||
|
||||
#ifndef REF_OSC
|
||||
#define REF_OSC 24000000UL /* reference osc. frequency */
|
||||
#endif
|
||||
|
||||
#define ADC_PRESCALE_CLK 1000000 /* targeted prescale clk */
|
||||
#define ADC_PRESCALE_VALUE ((REF_OSC / ADC_PRESCALE_CLK)-1)
|
||||
|
||||
#define ADC_CONVERT_TIME 23 /* function of prescale clk. has to be >= 20us */
|
||||
|
||||
#define ADC_NUM_CHANS 8
|
||||
|
||||
/**
|
||||
* Initializes the ADC module.
|
||||
*
|
||||
* Analog Clk set to 300kHz
|
||||
* Prescale Clk set to 1MHz
|
||||
* Convert Time set to 23us
|
||||
* Not using timers or IRQs
|
||||
*/
|
||||
void adc_init(void)
|
||||
{
|
||||
/* configure frequencies */
|
||||
ADC->CLOCK_DIVIDER = ADC_CLOCK_DIVIDER_300kHz;
|
||||
ADC->PRESCALE = ADC_PRESCALE_VALUE;
|
||||
|
||||
/* power on */
|
||||
ADC->CONTROLbits.ON = 0x1;
|
||||
|
||||
/* ON-TIME must be >= 10us */
|
||||
ADC->ON_TIME = 0xa;
|
||||
|
||||
/* should be >= 20us (6 ADC clks) */
|
||||
ADC->CONVERT_TIME = ADC_CONVERT_TIME;
|
||||
|
||||
/* automated mode */
|
||||
ADC->MODE = 0x0;
|
||||
|
||||
/* don't use IRQs */
|
||||
ADC->FIFO_CONTROL = 0x0;
|
||||
|
||||
/* disable all input channels */
|
||||
ADC->SEQ_1 = 0x0;
|
||||
/* sequence using convert time */
|
||||
ADC->SEQ_1bits.SEQ_MODE = 0x0;
|
||||
/* enable battery reference voltage channel */
|
||||
ADC->SEQ_1bits.BATT = 0x1;
|
||||
|
||||
/* disable all input channels */
|
||||
ADC->SEQ_2 = 0x0;
|
||||
/* sequence using convert time */
|
||||
ADC->SEQ_2bits.SEQ_MODE = 0x0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up a given channel 0...7 for ADC usage.
|
||||
*
|
||||
* \param channel The channel to set up
|
||||
*/
|
||||
void adc_setup_channel(uint8_t channel)
|
||||
{
|
||||
switch (channel) {
|
||||
case 0:
|
||||
ADC->SEQ_1bits.CH0 = 0x1;
|
||||
GPIO->FUNC_SEL.ADC0 = 0x1;
|
||||
GPIO->PAD_DIR.ADC0 = 0x0;
|
||||
GPIO->PAD_KEEP.ADC0 = 0x0;
|
||||
GPIO->PAD_PU_EN.ADC0 = 0;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
ADC->SEQ_1bits.CH1 = 0x1;
|
||||
GPIO->FUNC_SEL.ADC1 = 0x1;
|
||||
GPIO->PAD_DIR.ADC1 = 0x0;
|
||||
GPIO->PAD_KEEP.ADC1 = 0x0;
|
||||
GPIO->PAD_PU_EN.ADC1 = 0;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
ADC->SEQ_1bits.CH2 = 0x1;
|
||||
GPIO->FUNC_SEL.ADC2 = 0x1;
|
||||
GPIO->PAD_DIR.ADC2 = 0x0;
|
||||
GPIO->PAD_KEEP.ADC2 = 0x0;
|
||||
GPIO->PAD_PU_EN.ADC2 = 0;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
ADC->SEQ_1bits.CH3 = 0x1;
|
||||
GPIO->FUNC_SEL.ADC3 = 0x1;
|
||||
GPIO->PAD_DIR.ADC3 = 0x0;
|
||||
GPIO->PAD_KEEP.ADC3 = 0x0;
|
||||
GPIO->PAD_PU_EN.ADC3 = 0;
|
||||
break;
|
||||
|
||||
case 4:
|
||||
ADC->SEQ_1bits.CH4 = 0x1;
|
||||
GPIO->FUNC_SEL.ADC4 = 0x1;
|
||||
GPIO->PAD_DIR.ADC4 = 0x0;
|
||||
GPIO->PAD_KEEP.ADC4 = 0x0;
|
||||
GPIO->PAD_PU_EN.ADC4 = 0;
|
||||
break;
|
||||
|
||||
case 5:
|
||||
ADC->SEQ_1bits.CH5 = 0x1;
|
||||
GPIO->FUNC_SEL.ADC5 = 0x1;
|
||||
GPIO->PAD_DIR.ADC5 = 0x0;
|
||||
GPIO->PAD_KEEP.ADC5 = 0x0;
|
||||
GPIO->PAD_PU_EN.ADC5 = 0;
|
||||
break;
|
||||
|
||||
case 6:
|
||||
ADC->SEQ_1bits.CH6 = 0x1;
|
||||
GPIO->FUNC_SEL.ADC6 = 0x1;
|
||||
GPIO->PAD_DIR.ADC6 = 0x0;
|
||||
GPIO->PAD_KEEP.ADC6 = 0x0;
|
||||
GPIO->PAD_PU_EN.ADC6 = 0;
|
||||
break;
|
||||
|
||||
case 7:
|
||||
ADC->SEQ_1bits.CH7 = 0x1;
|
||||
GPIO->FUNC_SEL.ADC7 = 0x1;
|
||||
GPIO->PAD_DIR.ADC7 = 0x0;
|
||||
GPIO->PAD_KEEP.ADC7 = 0x0;
|
||||
GPIO->PAD_PU_EN.ADC7 = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from the ADC FIFO
|
||||
* Reads a 16 bit value from the ADC FIFO.
|
||||
* Bits 15:12 contain the channel the value origin.
|
||||
* Bits 11:0 contain the actual measured value.
|
||||
*
|
||||
* \return 16 Bits containing the channel and the measurement.
|
||||
*/
|
||||
uint16_t adc_read(void)
|
||||
{
|
||||
/* wait for ADC result */
|
||||
while (ADC->FIFO_STATUSbits.EMPTY) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* upper 4 bits contain channel number */
|
||||
return ADC->FIFO_READ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flushes any measured values from the ADC FIFO until FIFO is empty.
|
||||
*/
|
||||
void adc_flush(void)
|
||||
{
|
||||
while (!ADC->FIFO_STATUSbits.EMPTY) {
|
||||
ADC->FIFO_READ;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* When using several channels simultaniously this function can read
|
||||
* values from the ADC FIFO and store them in an array sorted by the
|
||||
* channel number.
|
||||
*
|
||||
* \param channels_read An array of 8 uint16_t the measured values get
|
||||
* stored into. The user could use ADC_NUM_CHANS
|
||||
* to asure compliancy.
|
||||
*/
|
||||
void adc_service(uint16_t *channels_read)
|
||||
{
|
||||
while (!ADC->FIFO_STATUSbits.EMPTY) {
|
||||
uint16_t tmp = ADC->FIFO_READ;
|
||||
|
||||
if ((tmp >> 12) < ADC_NUM_CHANS) {
|
||||
channels_read[tmp >> 12] = tmp & 0x0fff;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,140 +0,0 @@
|
||||
/*
|
||||
* mc1322x-adc.h - Structure definition for registers of the
|
||||
* Analog to Digital Converter module of the mc1322x MCU
|
||||
* Copyright (C) 2013 Thomas Eichinger <thomas.eichinger@fu-berlin.de>
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*
|
||||
* This file is part of RIOT.
|
||||
*/
|
||||
|
||||
#ifndef MC1322X_ADC_H
|
||||
#define MC1322X_ADC_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "adc_legacy.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define ADC_BASE (0x8000D000)
|
||||
|
||||
/* Structure-based register definitions */
|
||||
/* ADC registers are all 16-bit wide with 16-bit access only */
|
||||
struct ADC_struct {
|
||||
union {
|
||||
uint16_t COMP[8];
|
||||
struct {
|
||||
uint16_t COMP_0;
|
||||
uint16_t COMP_1;
|
||||
uint16_t COMP_2;
|
||||
uint16_t COMP_3;
|
||||
uint16_t COMP_4;
|
||||
uint16_t COMP_5;
|
||||
uint16_t COMP_6;
|
||||
uint16_t COMP_7;
|
||||
};
|
||||
};
|
||||
uint16_t BAT_COMP_OVER;
|
||||
uint16_t BAT_COMP_UNDER;
|
||||
union {
|
||||
uint16_t SEQ_1;
|
||||
struct ADC_SEQ_1 {
|
||||
uint16_t CH0: 1;
|
||||
uint16_t CH1: 1;
|
||||
uint16_t CH2: 1;
|
||||
uint16_t CH3: 1;
|
||||
uint16_t CH4: 1;
|
||||
uint16_t CH5: 1;
|
||||
uint16_t CH6: 1;
|
||||
uint16_t CH7: 1;
|
||||
uint16_t BATT: 1;
|
||||
uint16_t : 6;
|
||||
uint16_t SEQ_MODE: 1;
|
||||
} SEQ_1bits;
|
||||
};
|
||||
union {
|
||||
uint16_t SEQ_2;
|
||||
struct ADC_SEQ_2 {
|
||||
uint16_t CH0: 1;
|
||||
uint16_t CH1: 1;
|
||||
uint16_t CH2: 1;
|
||||
uint16_t CH3: 1;
|
||||
uint16_t CH4: 1;
|
||||
uint16_t CH5: 1;
|
||||
uint16_t CH6: 1;
|
||||
uint16_t CH7: 1;
|
||||
uint16_t : 7;
|
||||
uint16_t SEQ_MODE: 1;
|
||||
} SEQ_2bits;
|
||||
};
|
||||
union {
|
||||
uint16_t CONTROL;
|
||||
struct ADC_CONTROL {
|
||||
uint16_t ON: 1;
|
||||
uint16_t TIMER1_ON: 1;
|
||||
uint16_t TIMER2_ON: 1;
|
||||
uint16_t SOFT_RESET: 1;
|
||||
uint16_t AD1_VREFHL_EN: 1;
|
||||
uint16_t AD2_VREFHL_EN: 1;
|
||||
uint16_t : 6;
|
||||
uint16_t COMPARE_IRQ_MASK: 1;
|
||||
uint16_t SEQ1_IRQ_MASK: 1;
|
||||
uint16_t SEQ2_IRQ_MASK: 1;
|
||||
uint16_t FIFO_IRQ_MASK: 1;
|
||||
} CONTROLbits;
|
||||
};
|
||||
uint16_t TRIGGERS;
|
||||
uint16_t PRESCALE;
|
||||
uint16_t reserved1;
|
||||
uint16_t FIFO_READ;
|
||||
uint16_t FIFO_CONTROL;
|
||||
union {
|
||||
uint16_t FIFO_STATUS;
|
||||
struct ADC_FIFO_STATUS {
|
||||
uint16_t LEVEL: 4;
|
||||
uint16_t FULL: 1;
|
||||
uint16_t EMPTY: 1;
|
||||
uint16_t : 10;
|
||||
} FIFO_STATUSbits;
|
||||
};
|
||||
uint16_t reserved2[5];
|
||||
uint16_t SR_1_HIGH;
|
||||
uint16_t SR_1_LOW;
|
||||
uint16_t SR_2_HIGH;
|
||||
uint16_t SR_2_LOW;
|
||||
uint16_t ON_TIME;
|
||||
uint16_t CONVERT_TIME;
|
||||
uint16_t CLOCK_DIVIDER;
|
||||
uint16_t reserved3;
|
||||
union {
|
||||
uint16_t OVERRIDE;
|
||||
struct ADC_OVERRIDE {
|
||||
uint16_t MUX1: 4;
|
||||
uint16_t MUX2: 4;
|
||||
uint16_t AD1_ON: 1;
|
||||
uint16_t AD2_ON: 1;
|
||||
uint16_t : 6;
|
||||
} OVERRIDEbits;
|
||||
};
|
||||
uint16_t IRQ;
|
||||
uint16_t MODE;
|
||||
uint16_t RESULT_1;
|
||||
uint16_t RESULT_2;
|
||||
};
|
||||
|
||||
static volatile struct ADC_struct *const ADC = (void *)(ADC_BASE);
|
||||
|
||||
/* function prototypes */
|
||||
void adc_setup_channel(uint8_t channel);
|
||||
void adc_flush(void);
|
||||
void adc_service(uint16_t *channels_read);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* MC1322X_ADC_H */
|
||||
@ -1,5 +0,0 @@
|
||||
INCLUDES = -I$(RIOTBASE)/cpu/mc1322x/asm/include
|
||||
|
||||
MODULE =mc1322x_asm
|
||||
|
||||
include $(RIOTBASE)/Makefile.base
|
||||
@ -1,181 +0,0 @@
|
||||
/*
|
||||
* asm.c - implementation of some basic encryptions using the mc1322x ASM module
|
||||
* Copyright (C) 2013 Thomas Eichinger <thomas.eichinger@fu-berlin.de>
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
#include "asm.h"
|
||||
|
||||
/**
|
||||
* Turns on the ASM module and runs a self test.
|
||||
* The self test needs 3330 clocks.
|
||||
*/
|
||||
void asm_turn_on(void)
|
||||
{
|
||||
ASM->CONTROL_1_bits.ON = 1;
|
||||
ASM->CONTROL_1_bits.NORMAL_MODE = 1;
|
||||
ASM->CONTROL_1_bits.SELF_TEST = 1;
|
||||
ASM->CONTROL_0_bits.START = 1;
|
||||
|
||||
/* if the self test fails, this will never be true */
|
||||
while (!ASM->STATUS_bits.TEST_PASS) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ASM->CONTROL_1_bits.SELF_TEST = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns the ASM module off.
|
||||
*/
|
||||
void asm_turn_off(void)
|
||||
{
|
||||
ASM->CONTROL_1_bits.ON = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* For CTR encryption/decryption run this on each 128 bit block with the same CTR instance.
|
||||
* This function blocks until the encryption/decryption finished after 13 clocks.
|
||||
*
|
||||
* \param keys The 128 bit key. \sa asm_keys_t
|
||||
* \param data A 128 bit block to encrypt/decrypt. Holds the encrypted/decrypted
|
||||
* data when finished \sa asm_data_t
|
||||
* \param ctr Structure holding the counter for the encryption/decrpytion. The user
|
||||
* is responsible to provide a decend counter function. \sa asm_ctr_t
|
||||
*/
|
||||
void asm_ctr_encryption_blocking(asm_keys_t *keys, asm_data_t *data, asm_ctr_t *ctr)
|
||||
{
|
||||
ASM->ENC_KEY_0 = keys->value_0;
|
||||
ASM->ENC_KEY_1 = keys->value_1;
|
||||
ASM->ENC_KEY_2 = keys->value_2;
|
||||
ASM->ENC_KEY_3 = keys->value_3;
|
||||
|
||||
ASM->CONTROL_1_bits.CTR = 1;
|
||||
|
||||
ASM->DATA_0 = data->value_0;
|
||||
ASM->DATA_1 = data->value_1;
|
||||
ASM->DATA_2 = data->value_2;
|
||||
ASM->DATA_3 = data->value_3;
|
||||
|
||||
ASM->COUNTER_0 = ctr->value_0;
|
||||
ASM->COUNTER_1 = ctr->value_1;
|
||||
ASM->COUNTER_2 = ctr->value_2;
|
||||
ASM->COUNTER_3 = ctr->value_3;
|
||||
|
||||
ASM->CONTROL_0_bits.START = 1;
|
||||
|
||||
while (!ASM->STATUS_bits.DONE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
data->value_0 = ASM->COUNTER_RESULT_0;
|
||||
data->value_1 = ASM->COUNTER_RESULT_1;
|
||||
data->value_2 = ASM->COUNTER_RESULT_2;
|
||||
data->value_3 = ASM->COUNTER_RESULT_3;
|
||||
}
|
||||
|
||||
/**
|
||||
* Usage of the MAC functions.
|
||||
* 1. Initialize with the keys. ( asm_cbc_mac_init(keys) )
|
||||
* 2. Update for each 128 bit block of data ( asm_cbc_mac_update(data) )
|
||||
* 3. Finish and read the computed data ( asm_cbc_mac_finish(data) )
|
||||
*/
|
||||
|
||||
/**
|
||||
* Initialize a MAC stream.
|
||||
* \param keys Holding the 128 bit key \sa asm_keys_t
|
||||
*/
|
||||
void asm_cbc_mac_init(asm_keys_t *keys)
|
||||
{
|
||||
ASM->CONTROL_0_bits.CLEAR = 1;
|
||||
|
||||
ASM->ENC_KEY_0 = keys->value_0;
|
||||
ASM->ENC_KEY_1 = keys->value_1;
|
||||
ASM->ENC_KEY_2 = keys->value_2;
|
||||
ASM->ENC_KEY_3 = keys->value_3;
|
||||
|
||||
ASM->CONTROL_1_bits.CBC = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a MAC stream.
|
||||
* \param data Structure holding 128 bits of data. \sa asm_data_t
|
||||
*/
|
||||
void asm_cbc_mac_update_blocking(asm_data_t *data)
|
||||
{
|
||||
ASM->DATA_0 = data->value_0;
|
||||
ASM->DATA_1 = data->value_1;
|
||||
ASM->DATA_2 = data->value_2;
|
||||
ASM->DATA_3 = data->value_3;
|
||||
|
||||
ASM->CONTROL_0_bits.START = 1;
|
||||
|
||||
while (!ASM->STATUS_bits.DONE) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finishes a MAC stream
|
||||
* \param data Structure holding the result of the MAC computation. \sa asm_data_t
|
||||
*/
|
||||
void asm_cbc_mac_finish(asm_data_t *data)
|
||||
{
|
||||
data->value_0 = ASM->CBC_MAC_RESULT_0;
|
||||
data->value_1 = ASM->CBC_MAC_RESULT_1;
|
||||
data->value_2 = ASM->CBC_MAC_RESULT_2;
|
||||
data->value_3 = ASM->CBC_MAC_RESULT_3;
|
||||
|
||||
ASM->CONTROL_0_bits.CLEAR = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize a MAC stream for combined mode.
|
||||
* \param keys Holding the 128 bit key \sa asm_keys_t
|
||||
*/
|
||||
void asm_ctr_cbc_mac_init(asm_keys_t *keys)
|
||||
{
|
||||
asm_cbc_mac_init(keys);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a MAC stream and encrypts data.
|
||||
* \param data Structure holding 128 bits of data to use in MAC stream and to encrypt.
|
||||
Holds the encrypted data when finished. \sa asm_data_t
|
||||
* \param ctr Structure holding the counter for the encryption/decrpytion. The user
|
||||
* is responsible to provide a decend counter function. \sa asm_ctr_t
|
||||
*/
|
||||
void asm_ctr_cbc_mac_update(asm_data_t *data, asm_ctr_t *ctr)
|
||||
{
|
||||
ASM->DATA_0 = data->value_0;
|
||||
ASM->DATA_1 = data->value_1;
|
||||
ASM->DATA_2 = data->value_2;
|
||||
ASM->DATA_3 = data->value_3;
|
||||
|
||||
ASM->COUNTER_0 = ctr->value_0;
|
||||
ASM->COUNTER_1 = ctr->value_1;
|
||||
ASM->COUNTER_2 = ctr->value_2;
|
||||
ASM->COUNTER_3 = ctr->value_3;
|
||||
|
||||
ASM->CONTROL_0_bits.START = 1;
|
||||
|
||||
while (!ASM->STATUS_bits.DONE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
data->value_0 = ASM->COUNTER_RESULT_0;
|
||||
data->value_1 = ASM->COUNTER_RESULT_1;
|
||||
data->value_2 = ASM->COUNTER_RESULT_2;
|
||||
data->value_3 = ASM->COUNTER_RESULT_3;
|
||||
}
|
||||
/**
|
||||
* Finishes a MAC stream for combined mode
|
||||
* \param data Structure holding the result of the MAC computation. \sa asm_data_t
|
||||
*/
|
||||
void asm_ctr_cbc_mac_finish(asm_data_t *data)
|
||||
{
|
||||
asm_cbc_mac_finish(data);
|
||||
}
|
||||
@ -1,111 +0,0 @@
|
||||
/*
|
||||
* asm.h - defines registers for the Advanced Security Module of the mc1322x
|
||||
* Copyright (C) 2013 Thomas Eichinger <thomas.eichinger@fu-berlin.de>
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
#ifndef ASM_H
|
||||
#define ASM_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define ASM_BASE_ADDRESS 0x80008000
|
||||
|
||||
struct ASM_struct {
|
||||
uint32_t ENC_KEY_0; ///< Encryption key 0:31
|
||||
uint32_t ENC_KEY_1; ///< Encryption key 32:63
|
||||
uint32_t ENC_KEY_2; ///< Encryption key 64:95
|
||||
uint32_t ENC_KEY_3; ///< Encryption key 96:127
|
||||
uint32_t DATA_0; ///< Data 0:31
|
||||
uint32_t DATA_1; ///< Data 32:63
|
||||
uint32_t DATA_2; ///< Data 64:95
|
||||
uint32_t DATA_3; ///< Data 96:127
|
||||
uint32_t COUNTER_0; ///< Counter 0:31
|
||||
uint32_t COUNTER_1; ///< Counter 32:63
|
||||
uint32_t COUNTER_2; ///< Counter 64:95
|
||||
uint32_t COUNTER_3; ///< Counter 96:127
|
||||
uint32_t COUNTER_RESULT_0; ///< Result of CTR calculation 0:31
|
||||
uint32_t COUNTER_RESULT_1; ///< Result of CTR calculation 32:63
|
||||
uint32_t COUNTER_RESULT_2; ///< Result of CTR calculation 64:95
|
||||
uint32_t COUNTER_RESULT_3; ///< Result of CTR calculation 96:127
|
||||
uint32_t CBC_MAC_RESULT_0; ///< Result of CBC-MAC 0:31
|
||||
uint32_t CBC_MAC_RESULT_1; ///< Result of CBC-MAC 32:63
|
||||
uint32_t CBC_MAC_RESULT_2; ///< Result of CBC-MAC 64:95
|
||||
uint32_t CBC_MAC_RESULT_3; ///< Result of CBC-MAC 96:127
|
||||
union {
|
||||
uint32_t CONTROL_0; ///< Control 0 register
|
||||
struct ASM_CONTROL_0 {
|
||||
uint32_t : 24;
|
||||
uint32_t START: 1; ///< Start calculation
|
||||
uint32_t CLEAR: 1; ///< Clear all configurations
|
||||
uint32_t LOAD_MAC: 1; ///< Load an initila MAC value to continue
|
||||
uint32_t : 4;
|
||||
uint32_t CLEAR_IRQ; ///< Clear ASM IRQ bit
|
||||
} CONTROL_0_bits;
|
||||
};
|
||||
union {
|
||||
uint32_t CONTROL_1; ///< Control 1 register
|
||||
struct ASM_CONTROL_1 {
|
||||
uint32_t ON: 1; ///< Turn ASM module on
|
||||
uint32_t NORMAL_MODE: 1;///< exit boot mode
|
||||
uint32_t BYPASS: 1; ///< Data passes through unmodified
|
||||
uint32_t : 21;
|
||||
uint32_t CBC: 1; ///< enable CBC-MAC mode
|
||||
uint32_t CTR: 1; ///< enable CTR mode
|
||||
uint32_t SELF_TEST: 1; ///< switch to self test mode
|
||||
uint32_t : 4;
|
||||
uint32_t MASK_IRQ: 1; ///< disables the ASM IRQ
|
||||
} CONTROL_1_bits;
|
||||
};
|
||||
union {
|
||||
uint32_t STATUS; ///< status register
|
||||
struct ASM_STATUS {
|
||||
uint32_t : 24;
|
||||
uint32_t DONE: 1; ///< operation is done
|
||||
uint32_t TEST_PASS: 1; ///< self test did pass
|
||||
uint32_t : 6;
|
||||
} STATUS_bits;
|
||||
};
|
||||
uint32_t reserved;
|
||||
uint32_t CBC_MAC_0; ///< Result of MAC calculation 0:31
|
||||
uint32_t CBC_MAC_1; ///< Result of MAC calculation 32:63
|
||||
uint32_t CBC_MAC_2; ///< Result of MAC calculation 64:95
|
||||
uint32_t CBC_MAC_3; ///< Result of MAC calculation 96:127
|
||||
};
|
||||
|
||||
static volatile struct ASM_struct *const ASM = (void *)(ASM_BASE_ADDRESS);
|
||||
|
||||
struct ASM_Container {
|
||||
uint32_t value_0;
|
||||
uint32_t value_1;
|
||||
uint32_t value_2;
|
||||
uint32_t value_3;
|
||||
};
|
||||
typedef struct ASM_Container asm_keys_t;
|
||||
typedef struct ASM_Container asm_data_t;
|
||||
typedef struct ASM_Container asm_ctr_t;
|
||||
|
||||
/* function prototypes */
|
||||
|
||||
void asm_turn_on(void);
|
||||
void asm_turn_off(void);
|
||||
void asm_ctr_encryption_blocking(asm_keys_t *keys, asm_data_t *data, asm_ctr_t *ctr);
|
||||
void asm_cbc_mac_init(asm_keys_t *keys);
|
||||
void asm_cbc_mac_update_blocking(asm_data_t *data);
|
||||
void asm_cbc_mac_finish(asm_data_t *data);
|
||||
void asm_ctr_cbc_mac_init(asm_keys_t *keys);
|
||||
void asm_ctr_cbc_mac_update(asm_data_t *data, asm_ctr_t *ctr);
|
||||
void asm_ctr_cbc_mac_finish(asm_data_t *data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* ASM_H */
|
||||
@ -1,45 +0,0 @@
|
||||
/*
|
||||
* cpu.c - MC1322X architecture common support functions
|
||||
* Copyright (C) 2013 Oliver Hahm <oliver.hahm@inria.fr>
|
||||
* Copyright (C) 2013 Thomas Eichinger <thomas.eichinger@fu-berlin.de>
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
#include "mc1322x.h"
|
||||
#include "cpu.h"
|
||||
#include "lpm.h"
|
||||
#include "arm_cpu.h"
|
||||
|
||||
__attribute__((naked,noreturn)) void arm_reset(void)
|
||||
{
|
||||
dINT();
|
||||
CRM->SW_RST = SW_RST_VAL;
|
||||
while(1);
|
||||
}
|
||||
|
||||
enum lpm_mode lpm_set(enum lpm_mode target) {
|
||||
(void) target;
|
||||
return LPM_ON;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
** Function name: install_irq
|
||||
**
|
||||
** Descriptions: Install interrupt handler.
|
||||
** A wrapper to register_isr to be consistant to lpc2387
|
||||
** implementation.
|
||||
** parameters: Interrupt number, interrupt handler address,
|
||||
** interrupt priority
|
||||
** Returned value: true or false, return false if IntNum is out of range
|
||||
**
|
||||
******************************************************************************/
|
||||
|
||||
bool install_irq(int int_number, void *handler_addr, int priority)
|
||||
{
|
||||
(void) priority;
|
||||
register_isr(int_number, handler_addr);
|
||||
return (true);
|
||||
}
|
||||
@ -1,75 +0,0 @@
|
||||
/*
|
||||
* gpio.c - GPIO driver for redbee
|
||||
* Copyright (C) 2013 Thomas Eichinger <thomas.eichinger@fu-berlin.de>
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*
|
||||
* This file is part of RIOT.
|
||||
*/
|
||||
|
||||
#include "gpio.h"
|
||||
|
||||
static inline void gpio_pad_dir(volatile uint64_t data)
|
||||
{
|
||||
GPIO->PAD_DIR0 = (data & 0xffffffff);
|
||||
GPIO->PAD_DIR1 = (data >> 32);
|
||||
}
|
||||
|
||||
static inline void gpio_data(volatile uint64_t data)
|
||||
{
|
||||
GPIO->DATA0 = (data & 0xffffffff);
|
||||
GPIO->DATA1 = (data >> 32);
|
||||
}
|
||||
|
||||
static 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;
|
||||
}
|
||||
|
||||
static inline void gpio_pad_pu_en(volatile uint64_t data)
|
||||
{
|
||||
GPIO->PAD_PU_EN0 = (data & 0xffffffff);
|
||||
GPIO->PAD_PU_EN1 = (data >> 32);
|
||||
}
|
||||
|
||||
static inline void gpio_data_sel(volatile uint64_t data)
|
||||
{
|
||||
GPIO->DATA_SEL0 = (data & 0xffffffff);
|
||||
GPIO->DATA_SEL1 = (data >> 32);
|
||||
}
|
||||
|
||||
static inline void gpio_pad_pu_sel(volatile uint64_t data)
|
||||
{
|
||||
GPIO->PAD_PU_SEL0 = (data & 0xffffffff);
|
||||
GPIO->PAD_PU_SEL1 = (data >> 32);
|
||||
}
|
||||
|
||||
static inline void gpio_data_set(volatile uint64_t data)
|
||||
{
|
||||
GPIO->DATA_SET0 = (data & 0xffffffff);
|
||||
GPIO->DATA_SET1 = (data >> 32);
|
||||
}
|
||||
|
||||
static inline void gpio_data_reset(volatile uint64_t data)
|
||||
{
|
||||
GPIO->DATA_RESET0 = (data & 0xffffffff);
|
||||
GPIO->DATA_RESET1 = (data >> 32);
|
||||
}
|
||||
|
||||
static inline void gpio_pad_dir_set(volatile uint64_t data)
|
||||
{
|
||||
GPIO->PAD_DIR_SET0 = (data & 0xffffffff);
|
||||
GPIO->PAD_DIR_SET1 = (data >> 32);
|
||||
}
|
||||
|
||||
static inline void gpio_pad_dir_reset(volatile uint64_t data)
|
||||
{
|
||||
GPIO->PAD_DIR_RESET0 = (data & 0xffffffff);
|
||||
GPIO->PAD_DIR_RESET1 = (data >> 32);
|
||||
}
|
||||
@ -1,164 +0,0 @@
|
||||
/*
|
||||
* hwtimer_cpu.c - architecture dependent hardware timer functionality
|
||||
* Copyright (C) 2013 Oliver Hahm <oliver.hahm@inria.fr>
|
||||
* Copyright (C) 2013 Thomas Eichinger <thomas.eichinger@fu-berlin.de>
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include "mc1322x.h"
|
||||
#include "cpu.h"
|
||||
#include "arch/hwtimer_arch.h"
|
||||
#include "irq.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/* High level interrupt handler */
|
||||
static void (*int_handler)(int);
|
||||
|
||||
#define TMRx_ANY_INTERRUPT 0xa800
|
||||
|
||||
void tmr_isr(void) {
|
||||
/* detemine which timer caused the interrupt */
|
||||
if (TMR0->SCTRLbits.TCF && TMR0->SCTRLbits.TCFIE) {
|
||||
TMR0->SCTRLbits.TCF = 0;
|
||||
TMR0->CSCTRLbits.TCF1 = 0;
|
||||
TMR0->ENBL &= ~(1<<0);
|
||||
int_handler(0);
|
||||
}
|
||||
else if (TMR1->SCTRLbits.TCF && TMR1->SCTRLbits.TCFIE) {
|
||||
TMR1->SCTRLbits.TCF = 0;
|
||||
TMR1->CSCTRLbits.TCF1 = 0;
|
||||
TMR0->ENBL &= ~(1<<1);
|
||||
int_handler(1);
|
||||
}
|
||||
else if (TMR2->SCTRLbits.TCF && TMR2->SCTRLbits.TCFIE) {
|
||||
TMR2->SCTRLbits.TCF = 0;
|
||||
TMR2->CSCTRLbits.TCF1 = 0;
|
||||
TMR0->ENBL &= ~(1<<2);
|
||||
int_handler(2);
|
||||
}
|
||||
else if (TMR3->SCTRLbits.TCF && TMR3->SCTRLbits.TCFIE) {
|
||||
TMR3->SCTRLbits.TCF = 0;
|
||||
TMR3->CSCTRLbits.TCF1 = 0;
|
||||
TMR0->ENBL &= ~(1<<3);
|
||||
int_handler(3);
|
||||
}
|
||||
}
|
||||
|
||||
void timer_x_init(volatile struct TMR_struct* const TMRx) {
|
||||
/* Reset the timer */
|
||||
|
||||
/* Clear status */
|
||||
TMRx->SCTRL = 0;
|
||||
/* disable interrupt */
|
||||
TMRx->CSCTRL =0x0000;
|
||||
/* Reload/initialize to zero */
|
||||
TMRx->LOAD = 0;
|
||||
|
||||
/* disable comparison */
|
||||
TMRx->COMP1 = 0;
|
||||
TMRx->CMPLD1 = 0;
|
||||
|
||||
/* set counter to zero */
|
||||
TMRx->CNTR = TMRx->LOAD;
|
||||
|
||||
/* set timer control bits */
|
||||
TMRx->CTRLbits.COUNT_MODE = 1; /* use rising edge of primary source */
|
||||
TMRx->CTRLbits.PRIMARY_CNT_SOURCE = 0x0f; /* Perip. clock with 128 prescale (for 24MHz = 187500Hz) */
|
||||
TMRx->CTRLbits.SECONDARY_CNT_SOURCE = 0x00; /* don't need this */
|
||||
TMRx->CTRLbits.ONCE = 0x01; /* don't keep counting */
|
||||
TMRx->CTRLbits.LENGTH = 0x00; /* continue counting */
|
||||
TMRx->CTRLbits.DIR = 0x00; /* count up */
|
||||
TMRx->CTRLbits.CO_INIT = 0x00; /* other counters cannot force a reinitialization of this counter*/
|
||||
TMRx->CTRLbits.OUTPUT_MODE = 0x00; /* OFLAG is asserted while counter is active */
|
||||
}
|
||||
|
||||
void hwtimer_arch_init(void (*handler)(int), uint32_t fcpu) {
|
||||
int_handler = handler;
|
||||
|
||||
/* TODO: do scaling voodoo */
|
||||
(void) fcpu;
|
||||
|
||||
/* disable all timers */
|
||||
TMR0->ENBL = 0;
|
||||
timer_x_init(TMR0);
|
||||
timer_x_init(TMR1);
|
||||
timer_x_init(TMR2);
|
||||
timer_x_init(TMR3);
|
||||
|
||||
register_isr(INT_NUM_TMR, &tmr_isr);
|
||||
hwtimer_arch_enable_interrupt();
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void hwtimer_arch_enable_interrupt(void) {
|
||||
/* this enables timer interrupts in general by using the ITC.
|
||||
* Timer specific interrupt control is given by the TMRx structs. */
|
||||
//enable_irq(INT_NUM_TMR);
|
||||
ITC->INTENABLEbits.TMR = 1;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void hwtimer_arch_disable_interrupt(void) {
|
||||
/* this disables timer interrupts in general by using the ITC.
|
||||
* Timer specific interrupt control is given by the TMRx structs. */
|
||||
//disable_irq(INT_NUM_TMR);
|
||||
ITC->INTENABLEbits.TMR = 0;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void hwtimer_arch_set(unsigned long offset, short timer) {
|
||||
/* get corresponding struct for the given ::timer parameter */
|
||||
struct TMR_struct* tmr = (void *) TMR_BASE + (timer * TMR_OFFSET);
|
||||
|
||||
/* disable IRQs and save the status register */
|
||||
uint32_t cpsr = disableIRQ();
|
||||
|
||||
TMR0->ENBL &= ~(1<<timer); /* disable timer */
|
||||
tmr->COMP1 = tmr->CNTR + offset; /* load the current value + offset into the compare register */
|
||||
tmr->CSCTRLbits.TCF1 = 0; /* reset compare flag */
|
||||
tmr->CSCTRLbits.TCF1EN = 1; /* enable intterupts when TCF1 is set \ */
|
||||
TMR0->ENBL |= (1<<timer); /* enable timer */
|
||||
tmr->SCTRLbits.TCFIE = 1; /* enable interrupts when TCF is one - do we need both?*/
|
||||
|
||||
/* restore status register */
|
||||
restoreIRQ(cpsr);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void hwtimer_arch_set_absolute(unsigned long value, short timer) {
|
||||
/* get corresponding struct for the given ::timer parameter */
|
||||
struct TMR_struct* tmr = (void *) TMR_BASE + (timer * TMR_OFFSET);
|
||||
|
||||
/* disable IRQs and save the status register */
|
||||
uint32_t cpsr = disableIRQ();
|
||||
|
||||
TMR0->ENBL &= ~(1<<timer); /* disable timer */
|
||||
tmr->COMP1 = value; /* load the value into the compare register */
|
||||
tmr->CSCTRLbits.TCF1 = 0; /* reset compare flag */
|
||||
tmr->CSCTRLbits.TCF1EN = 1; /* enable interrupts when TCF1 is set \ */
|
||||
TMR0->ENBL |= (1<<timer); /* enable timer */
|
||||
tmr->SCTRLbits.TCFIE = 1; /* enable interrupts when TCF is one - do we need both?*/
|
||||
|
||||
/* restore status register */
|
||||
restoreIRQ(cpsr);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void hwtimer_arch_unset(short timer) {
|
||||
/* get corresponding struct for the given ::timer parameter */
|
||||
struct TMR_struct* tmr = (void *) TMR_BASE + (timer + TMR_OFFSET);
|
||||
|
||||
tmr->CSCTRLbits.TCF1 = 0; /* reset compare flag */
|
||||
tmr->CSCTRLbits.TCF1EN = 0; /* disable interrupts for TCF1 */
|
||||
tmr->SCTRLbits.TCFIE = 0; /* disable interrupts for TCF */
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
unsigned long hwtimer_arch_now(void) {
|
||||
return TMR0->CNTR;
|
||||
}
|
||||
@ -1,49 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Oliver Hahm <oliver.hahm@inria.fr>
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup mc1322x Freescale MC1322x
|
||||
* @ingroup cpu
|
||||
* @brief Freescale MC1322x specific code
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef CPU_H
|
||||
#define CPU_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "arm_cpu.h"
|
||||
#include "mc1322x.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief End of user stack memory
|
||||
*/
|
||||
extern uintptr_t __stack_start;
|
||||
|
||||
/**
|
||||
* @brief Install a interrupt service routine
|
||||
*
|
||||
* @param[in] int_number interrupt source
|
||||
* @param[in] handler_addr interrupt function
|
||||
* @param[in] priority interrupt priority
|
||||
*
|
||||
* @return true on success
|
||||
* @return false on error
|
||||
*/
|
||||
bool install_irq(int int_number, void *handler_addr, int priority);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CPU_H */
|
||||
/** @} */
|
||||
@ -1,79 +0,0 @@
|
||||
/*
|
||||
* cpu.h - mc1322x specific definitions
|
||||
* Copyright (C) 2013 Oliver Hahm <oliver.hahm@inria.fr>
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
#ifndef CPUCONF_H_
|
||||
#define CPUCONF_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup conf
|
||||
* @ingroup mc1322x
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief MC1322X CPUconfiguration
|
||||
*
|
||||
* @author Oliver Hahm <oliver.hahm@inria.fr>
|
||||
*/
|
||||
|
||||
/**
|
||||
* @name Stdlib configuration
|
||||
* @{
|
||||
*/
|
||||
#define __FOPEN_MAX__ 4
|
||||
#define __FILENAME_MAX__ 12
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @name Kernel configuration
|
||||
* @{
|
||||
*/
|
||||
#define THREAD_EXTRA_STACKSIZE_PRINTF_FLOAT (4096)
|
||||
#define THREAD_EXTRA_STACKSIZE_PRINTF (2048)
|
||||
|
||||
#ifndef THREAD_STACKSIZE_DEFAULT
|
||||
#define THREAD_STACKSIZE_DEFAULT (512)
|
||||
#endif
|
||||
|
||||
#define THREAD_STACKSIZE_IDLE (160)
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @name Compiler specifics
|
||||
* @{
|
||||
*/
|
||||
#define CC_CONF_INLINE inline
|
||||
#define CC_CONF_USED __attribute__((used))
|
||||
#define CC_CONF_NONNULL(...) __attribute__((nonnull(__VA_ARGS__)))
|
||||
#define CC_CONF_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @name UART0 buffer size definition for compatibility reasons
|
||||
*
|
||||
* TODO: remove once the remodeling of the uart0 driver is done
|
||||
* @{
|
||||
*/
|
||||
#ifndef UART0_BUFSIZE
|
||||
#define UART0_BUFSIZE (64)
|
||||
#endif
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
#endif /* CPUCONF_H_ */
|
||||
@ -1,166 +0,0 @@
|
||||
/*
|
||||
* gpio.h - GPIO driver for redbee
|
||||
* Copyright (C) 2013 Thomas Eichinger <thomas.eichinger@fu-berlin.de>
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
#ifndef GPIO_H
|
||||
#define GPIO_H
|
||||
|
||||
// TODO: why do we need to include this for macro expansion?
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Structure-based GPIO access
|
||||
Example usage:
|
||||
|
||||
GPIO->FUNC_SEL0 |= 0x00008000; // set a whole register
|
||||
|
||||
GPIO->FUNC_SEL_08 = 2; // set just one pin
|
||||
|
||||
#define MY_PIN GPIO_08
|
||||
GPIO->FUNC_SEL.MY_PIN = 2; // same, to allow #define for pin names
|
||||
GPIO->DATA.MY_PIN = 1;
|
||||
|
||||
gpio_set(GPIO_08); // efficiently set or clear a single output bit
|
||||
gpio_reset(GPIO_08);
|
||||
*/
|
||||
|
||||
// GPIO to Function Alias macros:
|
||||
|
||||
#define ADC0 GPIO_30
|
||||
#define ADC1 GPIO_31
|
||||
#define ADC2 GPIO_32
|
||||
#define ADC3 GPIO_33
|
||||
#define ADC4 GPIO_34
|
||||
#define ADC5 GPIO_35
|
||||
#define ADC6 GPIO_36
|
||||
#define ADC7 GPIO_37
|
||||
#define TDO GPIO_49
|
||||
#define TDI GPIO_48
|
||||
#define TCK GPIO_47
|
||||
#define TMS GPIO_46
|
||||
#define U2RTS GPIO_21
|
||||
#define U2CTS GPIO_20
|
||||
#define U2RX GPIO_19
|
||||
#define U2TX GPIO_18
|
||||
#define U1RTS GPIO_17
|
||||
#define U1CTS GPIO_16
|
||||
#define U1RX GPIO_15
|
||||
#define U1TX GPIO_14
|
||||
#define SDA GPIO_13
|
||||
#define SCL GPIO_12
|
||||
#define TMR3 GPIO_11
|
||||
#define TMR2 GPIO_10
|
||||
#define TMR1 GPIO_09
|
||||
#define TMR0 GPIO_08
|
||||
#define SCK GPIO_07
|
||||
#define MOSI GPIO_06
|
||||
#define MISO GPIO_05
|
||||
#define SS GPIO_04
|
||||
#define BTCK GPIO_03
|
||||
#define FSYN GPIO_02
|
||||
#define SSIRX GPIO_01
|
||||
#define SSITX GPIO_00
|
||||
#define KBI7 GPIO_29
|
||||
#define KBI6 GPIO_28
|
||||
#define KBI5 GPIO_27
|
||||
#define KBI4 GPIO_26
|
||||
#define KBI3 GPIO_25
|
||||
#define KBI2 GPIO_24
|
||||
#define KBI1 GPIO_23
|
||||
#define KBI0 GPIO_22
|
||||
#define TXON GPIO_44
|
||||
#define RXON GPIO_45
|
||||
#define ANT1 GPIO_42
|
||||
#define ANT2 GPIO_43
|
||||
#define VREF2H GPIO_38
|
||||
#define VREF2L GPIO_39
|
||||
#define VREF1H GPIO_40
|
||||
#define VREF1L GPIO_41
|
||||
#define MDO0 GPIO_51
|
||||
#define MDO1 GPIO_52
|
||||
#define MDO2 GPIO_53
|
||||
#define MDO3 GPIO_54
|
||||
#define MDO4 GPIO_55
|
||||
#define MDO5 GPIO_56
|
||||
#define MDO6 GPIO_57
|
||||
#define MDO7 GPIO_58
|
||||
#define MSEO0 GPIO_59
|
||||
#define MSEO1 GPIO_60
|
||||
#define RDY GPIO_61
|
||||
#define EVTO GPIO_62
|
||||
#define MCKO GPIO_50
|
||||
#define EVTI GPIO_63
|
||||
|
||||
|
||||
#define _V(x,n,i) uint32_t x##_##i : n;
|
||||
#define _REP(x,n) \
|
||||
_V(x,n,00) _V(x,n,01) _V(x,n,02) _V(x,n,03) _V(x,n,04) _V(x,n,05) _V(x,n,06) _V(x,n,07) \
|
||||
_V(x,n,08) _V(x,n,09) _V(x,n,10) _V(x,n,11) _V(x,n,12) _V(x,n,13) _V(x,n,14) _V(x,n,15) \
|
||||
_V(x,n,16) _V(x,n,17) _V(x,n,18) _V(x,n,19) _V(x,n,20) _V(x,n,21) _V(x,n,22) _V(x,n,23) \
|
||||
_V(x,n,24) _V(x,n,25) _V(x,n,26) _V(x,n,27) _V(x,n,28) _V(x,n,29) _V(x,n,30) _V(x,n,31) \
|
||||
_V(x,n,32) _V(x,n,33) _V(x,n,34) _V(x,n,35) _V(x,n,36) _V(x,n,37) _V(x,n,38) _V(x,n,39) \
|
||||
_V(x,n,40) _V(x,n,41) _V(x,n,42) _V(x,n,43) _V(x,n,44) _V(x,n,45) _V(x,n,46) _V(x,n,47) \
|
||||
_V(x,n,48) _V(x,n,49) _V(x,n,50) _V(x,n,51) _V(x,n,52) _V(x,n,53) _V(x,n,54) _V(x,n,55) \
|
||||
_V(x,n,56) _V(x,n,57) _V(x,n,58) _V(x,n,59) _V(x,n,60) _V(x,n,61) _V(x,n,62) _V(x,n,63)
|
||||
|
||||
struct GPIO_struct {
|
||||
#define _IO(x) \
|
||||
union { struct { uint32_t x##0; uint32_t x##1; }; \
|
||||
struct { _REP(x, 1) }; \
|
||||
struct GPIO_##x { _REP(GPIO, 1) } x; };
|
||||
#define _IO_2bit(x) \
|
||||
union { struct { uint32_t x##0; uint32_t x##1; uint32_t x##2; uint32_t x##3; }; \
|
||||
struct { _REP(x, 2) }; \
|
||||
struct GPIO_##x { _REP(GPIO, 2) } x; };
|
||||
|
||||
_IO(PAD_DIR);
|
||||
_IO(DATA);
|
||||
_IO(PAD_PU_EN);
|
||||
_IO_2bit(FUNC_SEL);
|
||||
_IO(DATA_SEL);
|
||||
_IO(PAD_PU_SEL);
|
||||
_IO(PAD_HYST_EN);
|
||||
_IO(PAD_KEEP);
|
||||
_IO(DATA_SET);
|
||||
_IO(DATA_RESET);
|
||||
_IO(PAD_DIR_SET);
|
||||
_IO(PAD_DIR_RESET);
|
||||
};
|
||||
#undef _IO
|
||||
#undef _IO_2bit
|
||||
|
||||
/* Build an enum lookup to map GPIO_08 -> 8 */
|
||||
#undef _V
|
||||
#define _V(x,n,i) __NUM_GPIO_GPIO_##i,
|
||||
enum { _REP(0,0) };
|
||||
|
||||
/* Macros to set or reset a data pin in the fastest possible way */
|
||||
#define gpio_set(gpio_xx) __gpio_set(gpio_xx)
|
||||
#define __gpio_set(gpio_xx) \
|
||||
((__NUM_GPIO_##gpio_xx < 32) \
|
||||
? (GPIO->DATA_SET0 = (1 << (__NUM_GPIO_##gpio_xx - 0))) \
|
||||
: (GPIO->DATA_SET1 = (1 << (__NUM_GPIO_##gpio_xx - 32))))
|
||||
#define gpio_reset(gpio_xx) __gpio_reset(gpio_xx)
|
||||
#define __gpio_reset(gpio_xx) \
|
||||
((__NUM_GPIO_##gpio_xx < 32) \
|
||||
? (GPIO->DATA_RESET0 = (1 << (__NUM_GPIO_##gpio_xx - 0))) \
|
||||
: (GPIO->DATA_RESET1 = (1 << (__NUM_GPIO_##gpio_xx - 32))))
|
||||
|
||||
#undef _REP
|
||||
#undef _V
|
||||
|
||||
static volatile struct GPIO_struct * const GPIO = (void *) (0x80000000);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,451 +0,0 @@
|
||||
/*
|
||||
* mc1322x.h - mc1322x specific definitions
|
||||
* Copyright (C) 2013, 2014 Oliver Hahm <oliver.hahm@inria.fr>
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
#ifndef MC1322X_H
|
||||
#define MC1322X_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*-----------------------------------------------------------------*/
|
||||
/* System Management */
|
||||
#define SW_RST_VAL (0x87651234)
|
||||
|
||||
#define CRM_BASE (0x80003000)
|
||||
|
||||
/* Structure-based CRM access */
|
||||
struct CRM_struct {
|
||||
union {
|
||||
uint32_t SYS_CNTL;
|
||||
struct CRM_SYS_CNTL {
|
||||
uint32_t PWR_SOURCE:2;
|
||||
uint32_t PADS_1P8V_SEL:1;
|
||||
uint32_t :1;
|
||||
uint32_t JTAG_SECU_OFF:1;
|
||||
uint32_t XTAL32_EXISTS:1;
|
||||
uint32_t :2;
|
||||
uint32_t XTAL_CLKDIV:6;
|
||||
uint32_t :18;
|
||||
} SYS_CNTLbits;
|
||||
};
|
||||
union {
|
||||
uint32_t WU_CNTL;
|
||||
struct CRM_WU_CNTL {
|
||||
uint32_t TIMER_WU_EN:1;
|
||||
uint32_t RTC_WU_EN:1;
|
||||
uint32_t HOST_WAKE:1;
|
||||
uint32_t AUTO_ADC:1;
|
||||
uint32_t EXT_WU_EN:4;
|
||||
uint32_t EXT_WU_EDGE:4;
|
||||
uint32_t EXT_WU_POL:4;
|
||||
uint32_t TIMER_WU_IEN:1;
|
||||
uint32_t RTC_WU_IEN:1;
|
||||
uint32_t :2;
|
||||
uint32_t EXT_WU_IEN:4;
|
||||
uint32_t :4;
|
||||
uint32_t EXT_OUT_POL:4;
|
||||
} WU_CNTLbits;
|
||||
};
|
||||
union {
|
||||
uint32_t SLEEP_CNTL;
|
||||
struct CRM_SLEEP_CNTL {
|
||||
uint32_t HIB:1;
|
||||
uint32_t DOZE:1;
|
||||
uint32_t :2;
|
||||
uint32_t RAM_RET:2;
|
||||
uint32_t MCU_RET:1;
|
||||
uint32_t DIG_PAD_EN:1;
|
||||
uint32_t :24;
|
||||
} SLEEP_CNTLbits;
|
||||
};
|
||||
union {
|
||||
uint32_t BS_CNTL;
|
||||
struct CRM_BS_CNTL {
|
||||
uint32_t BS_EN:1;
|
||||
uint32_t WAIT4IRQ:1;
|
||||
uint32_t BS_MAN_EN:1;
|
||||
uint32_t :2;
|
||||
uint32_t ARM_OFF_TIME:6;
|
||||
uint32_t :18;
|
||||
} BS_CNTLbits;
|
||||
};
|
||||
union {
|
||||
uint32_t COP_CNTL;
|
||||
struct CRM_COP_CNTL {
|
||||
uint32_t COP_EN:1;
|
||||
uint32_t COP_OUT:1;
|
||||
uint32_t COP_WP:1;
|
||||
uint32_t :5;
|
||||
uint32_t COP_TIMEOUT:7;
|
||||
uint32_t :1;
|
||||
uint32_t COP_COUNT:7;
|
||||
uint32_t :9;
|
||||
} COP_CNTLbits;
|
||||
};
|
||||
uint32_t COP_SERVICE;
|
||||
union {
|
||||
uint32_t STATUS;
|
||||
struct CRM_STATUS {
|
||||
uint32_t SLEEP_SYNC:1;
|
||||
uint32_t HIB_WU_EVT:1;
|
||||
uint32_t DOZE_WU_EVT:1;
|
||||
uint32_t RTC_WU_EVT:1;
|
||||
uint32_t EXT_WU_EVT:4;
|
||||
uint32_t :1;
|
||||
uint32_t CAL_DONE:1;
|
||||
uint32_t COP_EVT:1;
|
||||
uint32_t :6;
|
||||
uint32_t VREG_BUCK_RDY:1;
|
||||
uint32_t VREG_1P8V_RDY:1;
|
||||
uint32_t VREG_1P5V_RDY:1;
|
||||
uint32_t :12;
|
||||
} STATUSbits;
|
||||
};
|
||||
union {
|
||||
uint32_t MOD_STATUS;
|
||||
struct CRM_MOD_STATUS {
|
||||
uint32_t ARM_EN:1;
|
||||
uint32_t MACA_EN:1;
|
||||
uint32_t ASM_EN:1;
|
||||
uint32_t SPI_EN:1;
|
||||
uint32_t GPIO_EN:1;
|
||||
uint32_t UART1_EN:1;
|
||||
uint32_t UART2_EN:1;
|
||||
uint32_t TMR_EN:1;
|
||||
uint32_t RIF_EN:1;
|
||||
uint32_t I2C_EN:1;
|
||||
uint32_t SSI_EN:1;
|
||||
uint32_t SPIF_EN:1;
|
||||
uint32_t ADC_EN:1;
|
||||
uint32_t :1;
|
||||
uint32_t JTA_EN:1;
|
||||
uint32_t NEX_EN:1;
|
||||
uint32_t :1;
|
||||
uint32_t AIM_EN:1;
|
||||
uint32_t :14;
|
||||
} MOD_STATUSbits;
|
||||
};
|
||||
uint32_t WU_COUNT;
|
||||
uint32_t WU_TIMEOUT;
|
||||
uint32_t RTC_COUNT;
|
||||
uint32_t RTC_TIMEOUT;
|
||||
uint32_t reserved1;
|
||||
union {
|
||||
uint32_t CAL_CNTL;
|
||||
struct CRM_CAL_CNTL {
|
||||
uint32_t CAL_TIMEOUT:16;
|
||||
uint32_t CAL_EN:1;
|
||||
uint32_t CAL_IEN:1;
|
||||
uint32_t :14;
|
||||
} CAL_CNTLbits;
|
||||
};
|
||||
uint32_t CAL_COUNT;
|
||||
union {
|
||||
uint32_t RINGOSC_CNTL;
|
||||
struct CRM_RINGOSC_CNTL {
|
||||
uint32_t ROSC_EN:1;
|
||||
uint32_t :3;
|
||||
uint32_t ROSC_FTUNE:5;
|
||||
uint32_t ROSC_CTUNE:4;
|
||||
uint32_t :19;
|
||||
} RINGOSC_CNTLbits;
|
||||
};
|
||||
union {
|
||||
uint32_t XTAL_CNTL;
|
||||
struct CRM_XTAL_CNTL {
|
||||
uint32_t :8;
|
||||
uint32_t XTAL_IBIAS_SEL:4;
|
||||
uint32_t :4;
|
||||
uint32_t XTAL_FTUNE:5;
|
||||
uint32_t XTAL_CTUNE:5;
|
||||
uint32_t :6;
|
||||
} XTAL_CNTLbits;
|
||||
};
|
||||
union {
|
||||
uint32_t XTAL32_CNTL;
|
||||
struct CRM_XTAL32_CNTL {
|
||||
uint32_t XTAL32_EN:1;
|
||||
uint32_t :3;
|
||||
uint32_t XTAL32_GAIN:2;
|
||||
uint32_t :26;
|
||||
} XTAL32_CNTLbits;
|
||||
};
|
||||
union {
|
||||
uint32_t VREG_CNTL;
|
||||
struct CRM_VREG_CNTL {
|
||||
uint32_t BUCK_EN:1;
|
||||
uint32_t BUCK_SYNC_REC_EN:1;
|
||||
uint32_t BUCK_BYPASS_EN:1;
|
||||
uint32_t VREG_1P5V_EN:2;
|
||||
uint32_t VREG_1P5V_SEL:2;
|
||||
uint32_t VREG_1P8V_EN:1;
|
||||
uint32_t BUCK_CLKDIV:4;
|
||||
uint32_t :20;
|
||||
} VREG_CNTLbits;
|
||||
};
|
||||
uint32_t reserved2;
|
||||
uint32_t SW_RST;
|
||||
uint32_t reserved3;
|
||||
uint32_t reserved4;
|
||||
uint32_t reserved5;
|
||||
uint32_t reserved6;
|
||||
};
|
||||
|
||||
static volatile struct CRM_struct * const CRM = (void*) (CRM_BASE);
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------*/
|
||||
/* TIMERS */
|
||||
|
||||
/* 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)
|
||||
|
||||
struct TMR_struct {
|
||||
uint16_t COMP1;
|
||||
uint16_t COMP2;
|
||||
uint16_t CAPT;
|
||||
uint16_t LOAD;
|
||||
uint16_t HOLD;
|
||||
uint16_t CNTR;
|
||||
union {
|
||||
uint16_t CTRL;
|
||||
struct TMR_CTRL {
|
||||
uint16_t OUTPUT_MODE:3;
|
||||
uint16_t CO_INIT:1;
|
||||
uint16_t DIR:1;
|
||||
uint16_t LENGTH:1;
|
||||
uint16_t ONCE:1;
|
||||
uint16_t SECONDARY_CNT_SOURCE:2;
|
||||
uint16_t PRIMARY_CNT_SOURCE:4;
|
||||
uint16_t COUNT_MODE:3;
|
||||
} CTRLbits;
|
||||
};
|
||||
union {
|
||||
uint16_t SCTRL;
|
||||
struct TMR_SCTRL {
|
||||
uint16_t OEN:1;
|
||||
uint16_t OPS:1;
|
||||
uint16_t FORCE:1;
|
||||
uint16_t VAL:1;
|
||||
uint16_t EEOF:1;
|
||||
uint16_t MSTR:1;
|
||||
uint16_t CAPTURE_MODE:2;
|
||||
uint16_t INPUT:1;
|
||||
uint16_t IPS:1;
|
||||
uint16_t IEFIE:1;
|
||||
uint16_t IEF:1;
|
||||
uint16_t TOFIE:1;
|
||||
uint16_t TOF:1;
|
||||
uint16_t TCFIE:1;
|
||||
uint16_t TCF:1;
|
||||
} SCTRLbits;
|
||||
};
|
||||
uint16_t CMPLD1;
|
||||
uint16_t CMPLD2;
|
||||
union {
|
||||
uint16_t CSCTRL;
|
||||
struct TMR_CSCTRL {
|
||||
uint16_t CL1:2;
|
||||
uint16_t CL2:2;
|
||||
uint16_t TCF1:1;
|
||||
uint16_t TCF2:1;
|
||||
uint16_t TCF1EN:1;
|
||||
uint16_t TCF2EN:1;
|
||||
uint16_t :5;
|
||||
uint16_t FILT_EN:1;
|
||||
uint16_t DBG_EN:2;
|
||||
} CSCTRLbits;
|
||||
};
|
||||
|
||||
uint16_t reserved[4];
|
||||
|
||||
union {
|
||||
uint16_t ENBL;
|
||||
struct TMR_ENBL {
|
||||
union {
|
||||
struct {
|
||||
uint16_t ENBL:4;
|
||||
};
|
||||
struct {
|
||||
uint16_t ENBL3:1;
|
||||
uint16_t ENBL2:1;
|
||||
uint16_t ENBL1:1;
|
||||
uint16_t ENBL0:1;
|
||||
};
|
||||
};
|
||||
uint16_t :12;
|
||||
} ENBLbits;
|
||||
};
|
||||
};
|
||||
|
||||
static volatile struct TMR_struct * const TMR0 = (void *) (TMR0_BASE);
|
||||
static volatile struct TMR_struct * const TMR1 = (void *) (TMR1_BASE);
|
||||
static volatile struct TMR_struct * const TMR2 = (void *) (TMR2_BASE);
|
||||
static volatile struct TMR_struct * const TMR3 = (void *) (TMR3_BASE);
|
||||
|
||||
/* Get timer pointer from timer number */
|
||||
#define TMR_ADDR(x) (*(volatile struct TMR_struct *)(((uint32_t)(x) * TMR_OFFSET) + TMR_BASE))
|
||||
|
||||
/* Get timer number from the timer pointer. */
|
||||
#define TMR_NUM(x) (((uint32_t)(x) - TMR_BASE) / TMR_OFFSET)
|
||||
|
||||
/*-----------------------------------------------------------------*/
|
||||
/* Interrupts */
|
||||
#define INTBASE (0x80020000)
|
||||
|
||||
/* Structure-based ITC access */
|
||||
#define __INTERRUPT_union(x) \
|
||||
union { \
|
||||
uint32_t x; \
|
||||
struct ITC_##x { \
|
||||
uint32_t ASM:1; \
|
||||
uint32_t UART1:1; \
|
||||
uint32_t UART2:1; \
|
||||
uint32_t CRM:1; \
|
||||
uint32_t I2C:1; \
|
||||
uint32_t TMR:1; \
|
||||
uint32_t SPIF:1; \
|
||||
uint32_t MACA:1; \
|
||||
uint32_t SSI:1; \
|
||||
uint32_t ADC:1; \
|
||||
uint32_t SPI:1; \
|
||||
uint32_t :21; \
|
||||
} x##bits; \
|
||||
};
|
||||
|
||||
struct ITC_struct {
|
||||
union {
|
||||
uint32_t INTCNTL;
|
||||
struct ITC_INTCNTL {
|
||||
uint32_t :19;
|
||||
uint32_t FIAD:1;
|
||||
uint32_t NIAD:1;
|
||||
uint32_t :11;
|
||||
} INTCNTLbits;
|
||||
};
|
||||
uint32_t NIMASK;
|
||||
uint32_t INTENNUM;
|
||||
uint32_t INTDISNUM;
|
||||
__INTERRUPT_union(INTENABLE);
|
||||
__INTERRUPT_union(INTTYPE);
|
||||
uint32_t reserved[4];
|
||||
uint32_t NIVECTOR;
|
||||
uint32_t FIVECTOR;
|
||||
__INTERRUPT_union(INTSRC);
|
||||
__INTERRUPT_union(INTFRC);
|
||||
__INTERRUPT_union(NIPEND);
|
||||
__INTERRUPT_union(FIPEND);
|
||||
};
|
||||
#undef __INTERRUPT_union
|
||||
|
||||
static volatile struct ITC_struct * const ITC = (void *) (INTBASE);
|
||||
|
||||
/* Old register definitions, for compatibility */
|
||||
#ifndef REG_NO_COMPAT
|
||||
|
||||
#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)
|
||||
|
||||
static volatile uint32_t * const INTCNTL = ((volatile uint32_t *) (INTBASE + INTCNTL_OFF));
|
||||
static volatile uint32_t * const INTENNUM = ((volatile uint32_t *) (INTBASE + INTENNUM_OFF));
|
||||
static volatile uint32_t * const INTDISNUM = ((volatile uint32_t *) (INTBASE + INTDISNUM_OFF));
|
||||
static volatile uint32_t * const INTENABLE = ((volatile uint32_t *) (INTBASE + INTENABLE_OFF));
|
||||
static volatile uint32_t * const INTSRC = ((volatile uint32_t *) (INTBASE + INTSRC_OFF));
|
||||
static volatile uint32_t * const INTFRC = ((volatile uint32_t *) (INTBASE + INTFRC_OFF));
|
||||
static volatile uint32_t * const 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 = irq)
|
||||
#define disable_irq(irq) (*INTDISNUM = irq)
|
||||
|
||||
#define safe_irq_disable(x) volatile uint32_t saved_irq; saved_irq = *INTENABLE; disable_irq(x)
|
||||
#define irq_restore() *INTENABLE = saved_irq
|
||||
|
||||
#endif /* REG_NO_COMPAT */
|
||||
|
||||
/* Macro to safely disable all interrupts for a block of code.
|
||||
Use it like this:
|
||||
disable_int({
|
||||
asdf = 1234;
|
||||
printf("hi\r\n");
|
||||
});
|
||||
*/
|
||||
#define __int_top() volatile uint32_t saved_intenable
|
||||
#define __int_disable() saved_intenable = ITC->INTENABLE; ITC->INTENABLE = 0
|
||||
#define __int_enable() ITC->INTENABLE = saved_intenable
|
||||
#define disable_int(x) do { \
|
||||
__int_top(); \
|
||||
__int_disable(); \
|
||||
x; \
|
||||
__int_enable(); } while(0)
|
||||
|
||||
extern void register_isr(uint8_t interrupt, void (*isr)(void));
|
||||
|
||||
extern void tmr_isr(void) __attribute__((weak));
|
||||
|
||||
extern void crm_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 cal_isr(void) __attribute__((weak));
|
||||
|
||||
extern void uart1_isr(void) __attribute__((weak));
|
||||
extern void uart2_isr(void) __attribute__((weak));
|
||||
|
||||
extern void maca_isr(void) __attribute__((weak));
|
||||
|
||||
extern void asm_isr(void) __attribute__((weak));
|
||||
|
||||
extern void i2c_isr(void) __attribute__((weak));
|
||||
|
||||
extern void spif_isr(void) __attribute__((weak));
|
||||
|
||||
extern void ssi_isr(void) __attribute__((weak));
|
||||
|
||||
extern void adc_isr(void) __attribute__((weak));
|
||||
|
||||
extern void spi_isr(void) __attribute__((weak));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* MC1322X_H */
|
||||
@ -1,44 +0,0 @@
|
||||
/*
|
||||
* isr.c - mc1322x specific isr
|
||||
* Copyright (C) 2013 Thomas Eichinger <thomas.eichinger@fu-berlin.de>
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
#include "mc1322x.h"
|
||||
|
||||
#define MAX_IRQ_INDEX 10
|
||||
|
||||
static void (*isr_funcs[11])(void) = {
|
||||
asm_isr,
|
||||
uart1_isr,
|
||||
uart2_isr,
|
||||
crm_isr,
|
||||
i2c_isr,
|
||||
tmr_isr,
|
||||
spif_isr,
|
||||
maca_isr,
|
||||
ssi_isr,
|
||||
adc_isr,
|
||||
spi_isr
|
||||
};
|
||||
|
||||
void register_isr(uint8_t interrupt, void (*isr)(void)) {
|
||||
if (interrupt <= MAX_IRQ_INDEX) {
|
||||
isr_funcs[interrupt] = isr;
|
||||
}
|
||||
}
|
||||
|
||||
void isr(void)
|
||||
{
|
||||
/* pending interrupt? */
|
||||
while (ITC->NIPEND) {
|
||||
/* get interrupt source, range 0-10 */
|
||||
/* call corresponding ISR */
|
||||
if (isr_funcs[ITC->NIVECTOR]) {
|
||||
(isr_funcs[ITC->NIVECTOR])();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,7 +0,0 @@
|
||||
INCLUDES += -I$(RIOTCPU)/$(CPU)/include \
|
||||
-I$(RIOTCPU)/$(CPU)/maca/include \
|
||||
-I$(RIOTBOARDS)/redbee-econotag/drivers/include
|
||||
|
||||
MODULE = mc1322x
|
||||
|
||||
include $(RIOTBASE)/Makefile.base
|
||||
@ -1,546 +0,0 @@
|
||||
/*
|
||||
* maca.h - The MACA driver for the Redbee EconoTag
|
||||
* Copyright (C) 2013 Thomas Eichinger <thomas.eichinger@fu-berlin.de>
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
#ifndef MACA_H_
|
||||
#define MACA_H_
|
||||
#include <stdint.h>
|
||||
|
||||
#include "radio/types.h"
|
||||
|
||||
#include "maca_packet.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Broadcast address
|
||||
*/
|
||||
#define MC1322X_BROADCAST_ADDRESS (0xFFFF)
|
||||
|
||||
/*********************************************************/
|
||||
/* function definitions */
|
||||
/*********************************************************/
|
||||
|
||||
/* functions for the initialization and turning on and off of the MACA */
|
||||
void maca_init ( void );
|
||||
void maca_on ( void );
|
||||
void maca_off ( void );
|
||||
|
||||
/* function to check if MACA is running right */
|
||||
void maca_check ( void );
|
||||
|
||||
/* functions to configure MACA */
|
||||
void maca_set_power ( uint8_t power );
|
||||
void maca_set_channel ( uint8_t channel );
|
||||
radio_address_t maca_set_address (radio_address_t addr );
|
||||
radio_address_t maca_get_address ( void );
|
||||
uint16_t maca_set_pan(uint16_t pan);
|
||||
uint16_t maca_get_pan(void);
|
||||
|
||||
/* get Link Quality Indicator */
|
||||
extern uint8_t (*get_lqi) ( void );
|
||||
|
||||
|
||||
/* interface to configure demodulator */
|
||||
#define MACA_DEMOD_DCD 1 /* -96dBm, 22.2mA */
|
||||
#define MACA_DEMOD_NCD 0 /* -100dBm, 24.2mA */
|
||||
void set_demodulator_type ( uint8_t type );
|
||||
|
||||
/* macro for setting checksum filtering */
|
||||
extern volatile uint8_t fcs_mode;
|
||||
#define MACA_SET_FCS_MODE(x) fcs_mode = (x)
|
||||
|
||||
/* MACA_SET_PRM_MODE(PROMISC) to disable address filtering */
|
||||
/* MACA_SET_PRM_MODE(AUTOACK) to enable address filtering AND autoack */
|
||||
extern volatile uint8_t prm_mode;
|
||||
#define MACA_SET_PRM_MODE(x) prm_mode = (x)
|
||||
|
||||
/* functions working on maca_packet_t */
|
||||
void maca_set_tx_packet ( volatile maca_packet_t *packet );
|
||||
volatile maca_packet_t* maca_get_rx_packet ( void );
|
||||
volatile maca_packet_t* maca_get_free_packet ( void );
|
||||
void maca_free_packet ( volatile maca_packet_t *packet );
|
||||
void maca_free_all_packets ( void );
|
||||
|
||||
extern volatile maca_packet_t *maca_rx_head, *maca_tx_head;
|
||||
extern volatile uint32_t maca_entry;
|
||||
|
||||
extern void maca_rx_callback ( volatile maca_packet_t *packet ) __attribute__((weak));
|
||||
extern void maca_tx_callback ( volatile maca_packet_t *packet ) __attribute__((weak));
|
||||
|
||||
/* internal lowlevel MACA functions */
|
||||
void _maca_reset ( void );
|
||||
void _maca_init_phy ( void );
|
||||
void _maca_flyback_init ( void );
|
||||
void _maca_resume_maca_sync ( void );
|
||||
void _maca_radio_init ( void );
|
||||
uint32_t _maca_init_from_flash ( uint32_t address );
|
||||
|
||||
#define MACA_MAX_PACKET_SIZE (MACA_MAX_PAYLOAD_SIZE + 2) /* +2 for checksum */
|
||||
|
||||
/*********************************************************/
|
||||
/* register definitions */
|
||||
/*********************************************************/
|
||||
|
||||
#define MACA_BASE_ADDRESS (0x80004000)
|
||||
|
||||
struct MACA_struct {
|
||||
union {
|
||||
// Reset the MACA Module
|
||||
uint32_t RESET;
|
||||
struct MACA_RESET {
|
||||
uint32_t RST:1; // MACA Reset
|
||||
uint32_t CLK_ON:1; // MACA Clk on/off
|
||||
uint32_t :30;
|
||||
} RESETbits;
|
||||
};
|
||||
union {
|
||||
// Write: random generator seed
|
||||
// Read: get random data
|
||||
uint32_t RANDOM;
|
||||
struct MACA_RANDOM {
|
||||
uint32_t :32;
|
||||
} RANDOMbits;
|
||||
};
|
||||
union {
|
||||
// Control register of the MACA
|
||||
uint32_t CONTROL;
|
||||
struct MACA_CONTROL {
|
||||
uint32_t SEQUENCE :3; // set new mode of operation (see MACA_CONTROL_SEQUENCE_*)
|
||||
uint32_t MODE :2; // transmission access mode (see MACA_CONTROL_MODE_*)
|
||||
uint32_t TM :1; // test mode (see MACA_CONTROL_TM_*)
|
||||
uint32_t :1; // LFSR reserved
|
||||
uint32_t AUTO :1; // restart Rx automatically (see MACA_CONTROL_AUTO_*)
|
||||
uint32_t BCN :1; // filter beacon only (see MACA_CONTROL_BCN_*)
|
||||
uint32_t ASAP :1; // start action sequence ASAP (see MACA_CONTROL_ASAP_*)
|
||||
uint32_t REL :1; // clk selector (see MACA_CONTROL_REL_*)
|
||||
uint32_t PRM :1; // promiscuous mode (see MACA_CONTROL_PRM_*)
|
||||
uint32_t NOFC :1; // no frame check (see MACA_CONTROL_NOFC_*)
|
||||
uint32_t ROLE :1; // current role
|
||||
uint32_t :1; // reserved
|
||||
uint32_t RSTO :1; // reset slot offset (see MACA_CONTROL_RSTO_*)
|
||||
uint32_t PRE_COUNT :4; // preamble repeat counter (btween 0-15)
|
||||
uint32_t ISM :1; // ISM reserved
|
||||
uint32_t :11;
|
||||
} CONTROLbits;
|
||||
};
|
||||
union {
|
||||
uint32_t STATUS;
|
||||
struct
|
||||
{
|
||||
uint32_t COMPLETE_CODE :4; // complete code (see MACA_STATUS_COMPLETECODE_*)
|
||||
uint32_t :8; // reserved
|
||||
uint32_t OVR :1; // Rx buffer overrun (see MACA_STATUS_OVR_*)
|
||||
uint32_t BUSY :1; // channel busy detection (see MACA_STATUS_BUSY_*)
|
||||
uint32_t CRC :1; // checksum failed (see MACA_STATUS_CRC_*)
|
||||
uint32_t TO :1; // time-out (see MACA_STATUS_TO_*)
|
||||
uint32_t :16; // reserved
|
||||
} STATUSbits;
|
||||
};
|
||||
union {
|
||||
uint32_t FRMPND;
|
||||
struct
|
||||
{
|
||||
uint32_t PND :1; // Ack Frame Pending Status (see MACA_FRMPND_PND_*)
|
||||
uint32_t :31; // reserved
|
||||
} FRMPNbits;
|
||||
};
|
||||
union {
|
||||
uint32_t MC1322x_ID;
|
||||
struct
|
||||
{
|
||||
uint32_t MC1322x_ID :8; // the 9bit MC1322x ID (see MACA_MC1322x_ID_*)
|
||||
uint32_t :24; // reserved
|
||||
} MC1322x_IDbits;
|
||||
};
|
||||
union {
|
||||
uint32_t TMREN;
|
||||
struct
|
||||
{
|
||||
uint32_t STRT :1; // enable start clk circuit (see MACA_TMREN_STRT_*)
|
||||
uint32_t CPL :1; // enable complete clk circuit (see MACA_TMREN_CPL_*)
|
||||
uint32_t SFT :1; // enable soft complete clk circ (see MACA_TMREN_SFT_*)
|
||||
uint32_t :29; // reserved
|
||||
} TMRENbits;
|
||||
};
|
||||
union {
|
||||
uint32_t TMRDIS;
|
||||
struct
|
||||
{
|
||||
uint32_t STRT :1; // disable start clk circuit (see MACA_TMRDIS_STRT_*)
|
||||
uint32_t CPL :1; // disable complete clk circuit (see MACA_TMRDIS_CPL_*)
|
||||
uint32_t SFT :1; // disable soft complete clk circ (see MACA_TMRDIS_SFT_*)
|
||||
uint32_t STRT_OFF :1; // abort start clk (see MACA_TMRDIS_STRTOFF_*)
|
||||
uint32_t CPL_OFF :1; // abort complete clk (see MACA_TMRDIS_CPLOFF_*)
|
||||
uint32_t SFT_OFF :1; // abort soft complete clk (see MACA_TMRDIS_SFT_OFF_*)
|
||||
uint32_t :26; // reserved
|
||||
} TMRDISbits;
|
||||
};
|
||||
uint32_t CLK; // sets a new absolute clock value
|
||||
// Ensure that the timers are not active
|
||||
uint32_t STARTCLK; // see (9.7.10)
|
||||
uint32_t CPLCLK; // see (9.7.11)
|
||||
uint32_t SFTCLK; // see (9.7.12)
|
||||
uint32_t CLKOFFSET; // see (9.7.13)
|
||||
uint32_t RELCLK; // see (9.7.14)
|
||||
uint32_t CPLTIM; // see (9.7.15)
|
||||
union {
|
||||
uint32_t SLOTOFFSET; // see (9.7.16)
|
||||
struct
|
||||
{
|
||||
uint32_t TX_SLOT_OFFSET :12;
|
||||
uint32_t :4;
|
||||
uint32_t RX_SLOT_OFFSEt :12;
|
||||
uint32_t :4;
|
||||
} SLOTOFFSETbits;
|
||||
};
|
||||
uint32_t TIMESTAMP; // see (9.7.17)
|
||||
uint32_t DMARX; // see (9.7.18)
|
||||
uint32_t DMATX; // see (9.7.19)
|
||||
uint32_t DMAPOLL; // see (9.7.20)
|
||||
union {
|
||||
uint32_t TXLEN; // see (9.7.21)
|
||||
struct
|
||||
{
|
||||
uint32_t TX_LEN :15; // Tx payload length
|
||||
uint32_t :17; // reserved
|
||||
} TXLENbits;
|
||||
};
|
||||
union {
|
||||
uint32_t TXSEQNR; // see (9.7.22)
|
||||
struct
|
||||
{
|
||||
uint32_t TXSEQN :8; // Tx sequ. number
|
||||
uint32_t :24; // reserved
|
||||
} TXSEQNRbits;
|
||||
};
|
||||
union {
|
||||
uint32_t SETRXLVL; // see (9.7.23)
|
||||
struct
|
||||
{
|
||||
uint32_t FIFO_LVL :16; // FIFO level
|
||||
uint32_t :16; // reserved
|
||||
} SETRXLVLbits;
|
||||
};
|
||||
union {
|
||||
uint32_t GETRXLVL; // see (9.7.24)
|
||||
struct
|
||||
{
|
||||
uint32_t RECVBYTES :16; // received bytes
|
||||
uint32_t :16; // reserved
|
||||
} GETRXLVLbits;
|
||||
};
|
||||
union {
|
||||
uint32_t IRQ; // read only see (9.7.25)
|
||||
struct
|
||||
{
|
||||
uint32_t ACPL :1; // Action Complete Interrupt
|
||||
uint32_t POLL :1; // Poll Indication Interrupt
|
||||
uint32_t DI :1; // Data Indication Interrupt
|
||||
uint32_t :6; // reserved
|
||||
uint32_t LVL :1; // FIFO Level Interrupt
|
||||
uint32_t SFT :1; // Soft Complete Clk Interrupt
|
||||
uint32_t FLT :1; // Filter Failed Interrupt
|
||||
uint32_t CRC :1; // Checksum Failed Interrupt
|
||||
uint32_t CM :1; // Complete Clock Interrupt
|
||||
uint32_t SYNC :1; // Sync Detected Interrupt
|
||||
uint32_t STRT :1; // Action Started Interrupt
|
||||
uint32_t :16; // reserved
|
||||
} IRQbits;
|
||||
};
|
||||
union {
|
||||
uint32_t CLRIRQ; // write only see (9.7.26)
|
||||
// write 1 to clear
|
||||
struct
|
||||
{
|
||||
uint32_t ACPL :1; // Clear Action Complete Interrupt
|
||||
uint32_t POLL :1; // Clear Poll Indication Interrupt
|
||||
uint32_t DI :1; // Clear Data Indication Interrupt
|
||||
uint32_t :6; // reserved
|
||||
uint32_t LVL :1; // Clear FIFO Level Interrupt
|
||||
uint32_t SFT :1; // Clear Soft Complete Clk Interrupt
|
||||
uint32_t FLT :1; // Clear Filter Failed Interrupt
|
||||
uint32_t CRC :1; // Clear Checksum Failed Interrupt
|
||||
uint32_t CM :1; // Clear Complete Clock Interrupt
|
||||
uint32_t SYNC :1; // Clear Sync Detected Interrupt
|
||||
uint32_t STRT :1; // Clear Action Started Interrupt
|
||||
uint32_t :16; // reserved
|
||||
} CLRIRQbits;
|
||||
};
|
||||
union {
|
||||
uint32_t SETIRQ; // write only see (9.7.27)
|
||||
// write 1 to set IRQ
|
||||
struct
|
||||
{
|
||||
uint32_t ACPL :1; // Trigger Action Complete Interrupt
|
||||
uint32_t POLL :1; // Trigger Poll Indication Interrupt
|
||||
uint32_t DI :1; // Trigger Data Indication Interrupt
|
||||
uint32_t :6; // reserved
|
||||
uint32_t LVL :1; // Trigger FIFO Level Interrupt
|
||||
uint32_t SFT :1; // Trigger Soft Complete Clk Interrupt
|
||||
uint32_t FLT :1; // Trigger Filter Failed Interrupt
|
||||
uint32_t CRC :1; // Trigger Checksum Failed Interrupt
|
||||
uint32_t CM :1; // Trigger Complete Clock Interrupt
|
||||
uint32_t SYNC :1; // Trigger Sync Detected Interrupt
|
||||
uint32_t STRT :1; // Trigger Action Started Interrupt
|
||||
uint32_t :16; // reserved
|
||||
} SETIRQbits;
|
||||
};
|
||||
union {
|
||||
uint32_t MASKIRQ; // write only see (9.7.28)
|
||||
// write 1 to enable IRQ
|
||||
struct
|
||||
{
|
||||
uint32_t ACPL :1; // Enable Action Complete Interrupt
|
||||
uint32_t POLL :1; // Enable Poll Indication Interrupt
|
||||
uint32_t DI :1; // Enable Data Indication Interrupt
|
||||
uint32_t WU :1; // reserved but needed??
|
||||
uint32_t RST :1; // reserved but needed??
|
||||
uint32_t :4; // reserved
|
||||
uint32_t LVL :1; // Enable FIFO Level Interrupt
|
||||
uint32_t SFT :1; // Enable Soft Complete Clk Interrupt
|
||||
uint32_t FLT :1; // Enable Filter Failed Interrupt
|
||||
uint32_t CRC :1; // Enable Checksum Failed Interrupt
|
||||
uint32_t CM :1; // Enable Complete Clock Interrupt
|
||||
uint32_t SYNC :1; // Enable Sync Detected Interrupt
|
||||
uint32_t STRT :1; // Enable Action Started Interrupt
|
||||
uint32_t :16; // reserved
|
||||
} MASKIRQbits;
|
||||
};
|
||||
union {
|
||||
uint32_t MACPANID; // see (9.7.29)
|
||||
struct
|
||||
{
|
||||
uint32_t PANID :16; // MAC PAN ID for the 802.15.4 std network
|
||||
} MACPANIDbits;
|
||||
};
|
||||
union {
|
||||
uint32_t MAC16ADDR; // see (9.7.30)
|
||||
struct
|
||||
{
|
||||
uint32_t ADDR :16; // reflects the MAC short address
|
||||
} MAC16ADDRbits;
|
||||
};
|
||||
uint32_t MAC64HI; // see (9.7.31)
|
||||
uint32_t MAC64LO; // see (9.7.32)
|
||||
union {
|
||||
uint32_t FLTREJ; // see (9.7.33)
|
||||
struct
|
||||
{
|
||||
uint32_t BCN :1; // Reject Beacon packets
|
||||
uint32_t DATA :1; // Reject Data packets
|
||||
uint32_t ACK :1; // Reject ACK packets
|
||||
uint32_t CMD :1; // Reject MAC CMD packets
|
||||
uint32_t :4; // reserved
|
||||
uint32_t POLL :1; // Accept POLL packets
|
||||
uint32_t :7; // reserved
|
||||
uint32_t FC_MASK :16; // Frame Control Mask
|
||||
} FLTREJbits;
|
||||
};
|
||||
union {
|
||||
uint32_t CLKDIV; // see (9.7.34)
|
||||
struct
|
||||
{
|
||||
uint32_t Divider :16; // prescale value for the MACA transmit clk
|
||||
uint32_t :16; // reserved
|
||||
} CLKDIVbits;
|
||||
};
|
||||
union {
|
||||
uint32_t WARMUP; // see (9.7.35)
|
||||
struct
|
||||
{
|
||||
uint32_t Rx_WARMUP :12; // receiver warmup time
|
||||
uint32_t :4; // reserved
|
||||
uint32_t Tx_WARMUP :12; // transmitter warmuptime
|
||||
uint32_t :4; // reserved
|
||||
} WARMUPbits;
|
||||
};
|
||||
uint32_t PREAMBLE; // see (9.7.36)
|
||||
uint32_t FRAMESYNC0; // see (9.7.37)
|
||||
uint32_t FRAMESYNC1; // see (9.7.38)
|
||||
union {
|
||||
uint32_t TXACKDELAY; // see (9.7.39)
|
||||
struct
|
||||
{
|
||||
uint32_t TXACKDELAY :12; // Tx Acknowledgement Delay
|
||||
uint32_t :4; // reserved
|
||||
uint32_t TXPOLLDELAY :12; // Tx Poll Delay
|
||||
uint32_t :4; // reserved
|
||||
} TXACKDELAYbits;
|
||||
};
|
||||
union {
|
||||
uint32_t RXACKDELAY; // see (9.7.40)
|
||||
struct
|
||||
{
|
||||
uint32_t RXACKDELAY :12; // Rx Acknowledgement Delay
|
||||
uint32_t :4; // reserved
|
||||
uint32_t RXAUTODELAY :12; // time to disable receiver before restarting
|
||||
uint32_t :4; // reserved
|
||||
} RXACKDELAYbits;
|
||||
};
|
||||
union {
|
||||
uint32_t EOFDELAY; // see (9.7.41)
|
||||
struct
|
||||
{
|
||||
uint32_t EOFDELAY :12; // End Of Frame Delay
|
||||
uint32_t :20; // reserved
|
||||
} EOFDELAYbits;
|
||||
};
|
||||
union {
|
||||
uint32_t CCADELAY; // see (9.7.42)
|
||||
struct
|
||||
{
|
||||
uint32_t CCADELAY :12; // CCA Delay
|
||||
uint32_t :4; // reserved
|
||||
uint32_t CCALENGTH :12; // Length of time to perform CCA
|
||||
uint32_t :4; // reserved
|
||||
} CCADELAYbits;
|
||||
};
|
||||
union {
|
||||
uint32_t RXEND; // see (9.7.43)
|
||||
struct
|
||||
{
|
||||
uint32_t RXACK_END :12; // Rx Acknowledgement Window End in Normal Mode
|
||||
uint32_t :4; // reserved
|
||||
uint32_t RXSLOTTED_END :12; // Rx Acknowledgement Window End in slotted CSMA-CA mode
|
||||
uint32_t :4; // reserved
|
||||
} RXENDbits;
|
||||
};
|
||||
union {
|
||||
uint32_t TXCCADELAY; // see (9.7.44)
|
||||
struct
|
||||
{
|
||||
uint32_t TXCCADELAY :12; // Delay from end of CCA to Tx start
|
||||
uint32_t :20; // reserved
|
||||
} TXCCADELAYbits;
|
||||
};
|
||||
uint32_t KEY3; // see (9.7.45)
|
||||
uint32_t KEY2; // see (9.7.45)
|
||||
uint32_t KEY1; // see (9.7.45)
|
||||
uint32_t KEY0; // see (9.7.45)
|
||||
union {
|
||||
uint32_t OPTIONS; // see (9.7.46)
|
||||
struct
|
||||
{
|
||||
uint32_t POLL :1; // enables writing to DMAPOLL
|
||||
uint32_t PLL_TX :1; // responde to PLL unlock only while transmition
|
||||
uint32_t PLL_IGNORE :1; // ignore PLL unlock signal
|
||||
uint32_t SEED_KEY :1; // generation can be seeded
|
||||
uint32_t :28; // reserved
|
||||
} OPTIONSbits;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
static volatile struct MACA_struct * const MACA = (void *) (MACA_BASE_ADDRESS + 0x04); // +4 because base + 0x00 is reserved
|
||||
|
||||
#define MACA_CONTROL_SEQUENCE_NOP 0
|
||||
#define MACA_CONTROL_SEQUENCE_ABORT 1
|
||||
#define MACA_CONTROL_SEQUENCE_WAIT 2
|
||||
#define MACA_CONTROL_SEQUENCE_TX 3
|
||||
#define MACA_CONTROL_SEQUENCE_RX 4
|
||||
#define MACA_CONTROL_SEQUENCE_TXPOLL 5
|
||||
#define MACA_CONTROL_SEQUENCE_CCA 6
|
||||
#define MACA_CONTROL_SEQUENCE_ED 7
|
||||
|
||||
#define MACA_CONTROL_MODE_NOCCA 0
|
||||
#define MACA_CONTROL_MODE_NONSLOTTED_CSMACA 1
|
||||
#define MACA_CONTROL_MODE_SLOTTED_CSMACA 2
|
||||
#define MACA_CONTROL_MODE_RESERVED 3
|
||||
|
||||
#define MACA_CONTROL_TM_NORMAL 0
|
||||
#define MACA_CONTROL_TM_TM 1
|
||||
|
||||
#define MACA_CONTROL_AUTO_OFF 0
|
||||
#define MACA_CONTROL_AUTO_ON 1
|
||||
|
||||
#define MACA_CONTROL_BCN_OFF 0
|
||||
#define MACA_CONTROL_BCN_ON 1
|
||||
|
||||
#define MACA_CONTROL_ASAP_OFF 0
|
||||
#define MACA_CONTROL_ASAP_ON 1
|
||||
|
||||
#define MACA_CONTROL_REL_ABSOLUTE 0
|
||||
#define MACA_CONTROL_REL_RELATIVE 1
|
||||
|
||||
#define MACA_CONTROL_PRM_OFF 0
|
||||
#define MACA_CONTROL_PRM_ON 1
|
||||
|
||||
#define MACA_CONTROL_NOFC_OFF 0
|
||||
#define MACA_CONTROL_USE_FCS 0
|
||||
#define MACA_CONTROL_NOFC_ON 1
|
||||
#define MACA_CONTROL_NO_FCS 1
|
||||
|
||||
#define MACA_CONTROL_ROLE_NOPAN 0
|
||||
#define MACA_CONTROL_ROLE_PAN 1
|
||||
|
||||
#define MACA_CONTROL_RSTO_DONOT_RST 0
|
||||
#define MACA_CONTROL_RSTO_DO_RST 1
|
||||
|
||||
#define MACA_STATUS_COMPLETECODE_SUCCESS 0
|
||||
#define MACA_STATUS_COMPLETECODE_TIMEOUT 1
|
||||
#define MACA_STATUS_COMPLETECODE_CHANBUSY 2
|
||||
#define MACA_STATUS_COMPLETECODE_CRC_FAIL 3
|
||||
#define MACA_STATUS_COMPLETECODE_ABORTED 4
|
||||
#define MACA_STATUS_COMPLETECODE_NOACK 5
|
||||
#define MACA_STATUS_COMPLETECODE_NODATA 6
|
||||
#define MACA_STATUS_COMPLETECODE_LATESTART 7
|
||||
#define MACA_STATUS_COMPLETECODE_EXTTIMEOUT 8
|
||||
#define MACA_STATUS_COMPLETECODE_EXTPNDTIMEOUT 9
|
||||
#define MACA_STATUS_COMPLETECODE_PLLUNLOCK 12
|
||||
#define MACA_STATUS_COMPLETECODE_EXTABORT 13
|
||||
#define MACA_STATUS_COMPLETECODE_NOTCOMPLETE 14
|
||||
#define MACA_STATUS_COMPLETECODE_DMABUSERROR 15
|
||||
|
||||
#define MACA_STATUS_OVR_FALSE 0
|
||||
#define MACA_STATUS_OVR_TRUE 1
|
||||
|
||||
#define MACA_STATUS_BUSY_FALSE 0
|
||||
#define MACA_STATUS_BUSY_TRUE 1
|
||||
|
||||
#define MACA_STATUS_CRC_OK 0
|
||||
#define MACA_STATUS_CRC_ERROR 1
|
||||
|
||||
#define MACA_STATUS_TO_FALSE 0
|
||||
#define MACA_STATUS_TO_TRUE 1
|
||||
|
||||
#define MACA_FRMPND_PND_NODATA 0
|
||||
#define MACA_FRMPND_PND_DATAAVAIL 1
|
||||
|
||||
#define MACA_MC1322x_ID_ENGINEERING 0
|
||||
#define MACA_MC1322x_ID_MC13224_1 1
|
||||
#define MACA_MC1322x_ID_MC13224_2 9
|
||||
#define MACA_MC1322x_ID_MC13226 17
|
||||
|
||||
|
||||
#define MACA_TMREN_STRT_ENABLE 1
|
||||
|
||||
#define MACA_TMREN_CPL_ENABLE 1
|
||||
|
||||
#define MACA_TMREN_SFT_ENABLE 1
|
||||
|
||||
#define MACA_TMRDIS_STRT_DISABLE 1
|
||||
|
||||
#define MACA_TMRDIS_CPL_DISABLE 1
|
||||
|
||||
#define MACA_TMRDIS_SFT_DISABLE 1
|
||||
|
||||
#define MACA_TMRDIS_STRTOFF_ABORT 1
|
||||
|
||||
#define MACA_TMRDIS_CPLOFF_ABORT 1
|
||||
|
||||
#define MACA_TMRDIS_SFTOFF_ABORT 1
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // MACA_H_
|
||||
@ -1,57 +0,0 @@
|
||||
/*
|
||||
* maca_packet.h - defines a rxtx packet for the MACA driver
|
||||
* Copyright (C) 2013 Thomas Eichinger <thomas.eichinger@fu-berlin.de>
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
#ifndef PACKET_H
|
||||
#define PACKET_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* does not include 2 byte FCS checksum */
|
||||
#ifndef MACA_MAX_PAYLOAD_SIZE
|
||||
#define MACA_MAX_PAYLOAD_SIZE 125
|
||||
#endif
|
||||
|
||||
#define PACKET_STATS 0
|
||||
|
||||
/**
|
||||
* @brief MC1322x internal MACA packet format */
|
||||
struct packet {
|
||||
uint8_t length; /**< does not include FCS checksum */
|
||||
volatile struct packet *left; /**< pointer to left neighbor in queue */
|
||||
volatile struct packet *right; /**< pointer to right neighbor in queue */
|
||||
uint8_t offset; /**< 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 lqi; /**< link quality indicator */
|
||||
uint8_t status; /**< packet status */
|
||||
uint32_t rx_time; /**< receiving timestamp */
|
||||
#if PACKET_STATS
|
||||
uint8_t seen;
|
||||
uint8_t post_tx;
|
||||
uint8_t get_free;
|
||||
uint8_t rxd;
|
||||
#endif
|
||||
uint8_t data[MACA_MAX_PAYLOAD_SIZE+2+1]; /**< +2 for FCS; + 1 since maca
|
||||
* returns the length as the
|
||||
* first byte */
|
||||
};
|
||||
typedef struct packet maca_packet_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,271 +0,0 @@
|
||||
/* vim: set syntax=rpcgen : */
|
||||
/* Script for -z combreloc: combine and sort reloc sections */
|
||||
OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", "elf32-littlearm")
|
||||
OUTPUT_ARCH(arm)
|
||||
ENTRY(_startup)
|
||||
|
||||
MEMORY
|
||||
{
|
||||
ram (rwx) : org = 0x00400000, l = 96K
|
||||
}
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
|
||||
SYS_STACK_SIZE = 1024;
|
||||
IRQ_STACK_SIZE = 256;
|
||||
FIQ_STACK_SIZE = 256;
|
||||
SVC_STACK_SIZE = 256;
|
||||
ABT_STACK_SIZE = 16;
|
||||
UND_STACK_SIZE = 16;
|
||||
HEAP_SIZE = 4096;
|
||||
|
||||
/* Read-only sections, merged into text segment: */
|
||||
PROVIDE (__executable_start = 0x00400000); . = 0x00400000;
|
||||
.text :
|
||||
{
|
||||
*(.startup)
|
||||
*(.irq)
|
||||
*(.text .stub .text.* .gnu.linkonce.t.*)
|
||||
/* .gnu.warning sections are handled specially by elf32.em. */
|
||||
*(.gnu.warning)
|
||||
*(.glue_7t) *(.glue_7) *(.vfp11_veneer) *(.v4_bx)
|
||||
} =0
|
||||
|
||||
.interp : { *(.interp) }
|
||||
.note.gnu.build-id : { *(.note.gnu.build-id) }
|
||||
.hash : { *(.hash) }
|
||||
.gnu.hash : { *(.gnu.hash) }
|
||||
.dynsym : { *(.dynsym) }
|
||||
.dynstr : { *(.dynstr) }
|
||||
.gnu.version : { *(.gnu.version) }
|
||||
.gnu.version_d : { *(.gnu.version_d) }
|
||||
.gnu.version_r : { *(.gnu.version_r) }
|
||||
.rel.dyn :
|
||||
{
|
||||
*(.rel.init)
|
||||
*(.rel.text .rel.text.* .rel.gnu.linkonce.t.*)
|
||||
*(.rel.fini)
|
||||
*(.rel.rodata .rel.rodata.* .rel.gnu.linkonce.r.*)
|
||||
*(.rel.data.rel.ro* .rel.gnu.linkonce.d.rel.ro.*)
|
||||
*(.rel.data .rel.data.* .rel.gnu.linkonce.d.*)
|
||||
*(.rel.tdata .rel.tdata.* .rel.gnu.linkonce.td.*)
|
||||
*(.rel.tbss .rel.tbss.* .rel.gnu.linkonce.tb.*)
|
||||
*(.rel.ctors)
|
||||
*(.rel.dtors)
|
||||
*(.rel.got)
|
||||
*(.rel.bss .rel.bss.* .rel.gnu.linkonce.b.*)
|
||||
}
|
||||
.rela.dyn :
|
||||
{
|
||||
*(.rela.init)
|
||||
*(.rela.text .rela.text.* .rela.gnu.linkonce.t.*)
|
||||
*(.rela.fini)
|
||||
*(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*)
|
||||
*(.rela.data .rela.data.* .rela.gnu.linkonce.d.*)
|
||||
*(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*)
|
||||
*(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*)
|
||||
*(.rela.ctors)
|
||||
*(.rela.dtors)
|
||||
*(.rela.got)
|
||||
*(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*)
|
||||
}
|
||||
.rel.plt : { *(.rel.plt) }
|
||||
.rela.plt : { *(.rela.plt) }
|
||||
.init :
|
||||
{
|
||||
KEEP (*(.init))
|
||||
} =0
|
||||
.plt : { *(.plt) }
|
||||
.fini :
|
||||
{
|
||||
KEEP (*(.fini))
|
||||
} =0
|
||||
PROVIDE (__etext = .);
|
||||
PROVIDE (_etext = .);
|
||||
PROVIDE (etext = .);
|
||||
.rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) }
|
||||
.rodata1 : { *(.rodata1) }
|
||||
.eh_frame_hdr : { *(.eh_frame_hdr) }
|
||||
.eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) }
|
||||
.gcc_except_table : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) }
|
||||
/* Adjust the address for the data segment. We want to adjust up to
|
||||
the same address within the page on the next page up. */
|
||||
|
||||
/* . = ALIGN (CONSTANT (MAXPAGESIZE)) - ((CONSTANT (MAXPAGESIZE) - .) & (CONSTANT (MAXPAGESIZE) - 1)); . = DATA_SEGMENT_ALIGN (CONSTANT (MAXPAGESIZE), CONSTANT (COMMONPAGESIZE)); */
|
||||
|
||||
. = ALIGN(4);
|
||||
. = DATA_SEGMENT_ALIGN(4,4);
|
||||
|
||||
/* Exception handling */
|
||||
.eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) }
|
||||
.gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) }
|
||||
/* Thread Local Storage sections */
|
||||
.tdata : { *(.tdata .tdata.* .gnu.linkonce.td.*) }
|
||||
.tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) }
|
||||
.preinit_array :
|
||||
{
|
||||
PROVIDE_HIDDEN (__preinit_array_start = .);
|
||||
KEEP (*(.preinit_array))
|
||||
PROVIDE_HIDDEN (__preinit_array_end = .);
|
||||
}
|
||||
.init_array :
|
||||
{
|
||||
PROVIDE_HIDDEN (__init_array_start = .);
|
||||
KEEP (*(SORT(.init_array.*)))
|
||||
KEEP (*(.init_array))
|
||||
PROVIDE_HIDDEN (__init_array_end = .);
|
||||
}
|
||||
.fini_array :
|
||||
{
|
||||
PROVIDE_HIDDEN (__fini_array_start = .);
|
||||
KEEP (*(.fini_array))
|
||||
KEEP (*(SORT(.fini_array.*)))
|
||||
PROVIDE_HIDDEN (__fini_array_end = .);
|
||||
}
|
||||
.ctors :
|
||||
{
|
||||
/* gcc uses crtbegin.o to find the start of
|
||||
the constructors, so we make sure it is
|
||||
first. Because this is a wildcard, it
|
||||
doesn't matter if the user does not
|
||||
actually link against crtbegin.o; the
|
||||
linker won't look for a file to match a
|
||||
wildcard. The wildcard also means that it
|
||||
doesn't matter which directory crtbegin.o
|
||||
is in. */
|
||||
KEEP (*crtbegin.o(.ctors))
|
||||
KEEP (*crtbegin?.o(.ctors))
|
||||
/* We don't want to include the .ctor section from
|
||||
the crtend.o file until after the sorted ctors.
|
||||
The .ctor section from the crtend file contains the
|
||||
end of ctors marker and it must be last */
|
||||
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))
|
||||
KEEP (*(SORT(.ctors.*)))
|
||||
KEEP (*(.ctors))
|
||||
}
|
||||
.dtors :
|
||||
{
|
||||
KEEP (*crtbegin.o(.dtors))
|
||||
KEEP (*crtbegin?.o(.dtors))
|
||||
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))
|
||||
KEEP (*(SORT(.dtors.*)))
|
||||
KEEP (*(.dtors))
|
||||
}
|
||||
.jcr : { KEEP (*(.jcr)) }
|
||||
.data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro* .gnu.linkonce.d.rel.ro.*) }
|
||||
.dynamic : { *(.dynamic) }
|
||||
. = DATA_SEGMENT_RELRO_END (0, .);
|
||||
.got : { *(.got.plt) *(.got) }
|
||||
.data :
|
||||
{
|
||||
/* changed from __data_start = . ; */
|
||||
_data = . ;
|
||||
*(.data .data.* .gnu.linkonce.d.*)
|
||||
SORT(CONSTRUCTORS)
|
||||
}
|
||||
.data1 : { *(.data1) }
|
||||
_edata = .; PROVIDE (edata = .);
|
||||
|
||||
.stack : {
|
||||
__stack_start__ = . ;
|
||||
|
||||
. += IRQ_STACK_SIZE;
|
||||
. = ALIGN (4);
|
||||
__irq_stack_top__ = . ;
|
||||
|
||||
. += FIQ_STACK_SIZE;
|
||||
. = ALIGN (4);
|
||||
__fiq_stack_top__ = . ;
|
||||
|
||||
. += SVC_STACK_SIZE;
|
||||
. = ALIGN (4);
|
||||
__svc_stack_top__ = . ;
|
||||
|
||||
. += ABT_STACK_SIZE;
|
||||
. = ALIGN (4);
|
||||
__abt_stack_top__ = . ;
|
||||
|
||||
. += UND_STACK_SIZE;
|
||||
. = ALIGN (4);
|
||||
__und_stack_top__ = . ;
|
||||
|
||||
. += SYS_STACK_SIZE;
|
||||
. = ALIGN (4);
|
||||
__sys_stack_top__ = . ;
|
||||
|
||||
__stack_end__ = .;
|
||||
}
|
||||
|
||||
|
||||
__bss_start = .;
|
||||
__bss_start__ = .;
|
||||
.bss :
|
||||
{
|
||||
*(.dynbss)
|
||||
*(.bss .bss.* .gnu.linkonce.b.*)
|
||||
*(COMMON)
|
||||
/* Align here to ensure that the .bss section occupies space up to
|
||||
_end. Align after .bss to ensure correct alignment even if the
|
||||
.bss section disappears because there are no input sections.
|
||||
FIXME: Why do we need it? When there is no .bss section, we don't
|
||||
pad the .data section. */
|
||||
. = ALIGN(. != 0 ? 32 / 8 : 1);
|
||||
}
|
||||
/* changed from _bss_end__ = . ; __bss_end__ = . ; */
|
||||
__bss_end = . ; __bss_end__ = . ;
|
||||
. = ALIGN(32 / 8);
|
||||
|
||||
.heap : {
|
||||
__heap_start__ = . ; PROVIDE(__heap_start = .);
|
||||
*(.heap);
|
||||
. += HEAP_SIZE;
|
||||
. = ALIGN (4);
|
||||
__heap_end__ = . ; PROVIDE(__heap_end = .);
|
||||
}
|
||||
|
||||
|
||||
. = ALIGN(32 / 8);
|
||||
__end__ = . ;
|
||||
_end = .; PROVIDE (end = .);
|
||||
. = DATA_SEGMENT_END (.);
|
||||
/* Stabs debugging sections. */
|
||||
.stab 0 : { *(.stab) }
|
||||
.stabstr 0 : { *(.stabstr) }
|
||||
.stab.excl 0 : { *(.stab.excl) }
|
||||
.stab.exclstr 0 : { *(.stab.exclstr) }
|
||||
.stab.index 0 : { *(.stab.index) }
|
||||
.stab.indexstr 0 : { *(.stab.indexstr) }
|
||||
.comment 0 : { *(.comment) }
|
||||
/* DWARF debug sections.
|
||||
Symbols in the DWARF debugging sections are relative to the beginning
|
||||
of the section so we begin them at 0. */
|
||||
/* DWARF 1 */
|
||||
.debug 0 : { *(.debug) }
|
||||
.line 0 : { *(.line) }
|
||||
/* GNU DWARF 1 extensions */
|
||||
.debug_srcinfo 0 : { *(.debug_srcinfo) }
|
||||
.debug_sfnames 0 : { *(.debug_sfnames) }
|
||||
/* DWARF 1.1 and DWARF 2 */
|
||||
.debug_aranges 0 : { *(.debug_aranges) }
|
||||
.debug_pubnames 0 : { *(.debug_pubnames) }
|
||||
/* DWARF 2 */
|
||||
.debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
|
||||
.debug_abbrev 0 : { *(.debug_abbrev) }
|
||||
.debug_line 0 : { *(.debug_line) }
|
||||
.debug_frame 0 : { *(.debug_frame) }
|
||||
.debug_str 0 : { *(.debug_str) }
|
||||
.debug_loc 0 : { *(.debug_loc) }
|
||||
.debug_macinfo 0 : { *(.debug_macinfo) }
|
||||
/* SGI/MIPS DWARF 2 extensions */
|
||||
.debug_weaknames 0 : { *(.debug_weaknames) }
|
||||
.debug_funcnames 0 : { *(.debug_funcnames) }
|
||||
.debug_typenames 0 : { *(.debug_typenames) }
|
||||
.debug_varnames 0 : { *(.debug_varnames) }
|
||||
/* DWARF 3 */
|
||||
.debug_pubtypes 0 : { *(.debug_pubtypes) }
|
||||
.debug_ranges 0 : { *(.debug_ranges) }
|
||||
.gnu.attributes 0 : { KEEP (*(.gnu.attributes)) }
|
||||
.note.gnu.arm.ident 0 : { KEEP (*(.note.gnu.arm.ident)) }
|
||||
/DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) }
|
||||
}
|
||||
@ -1,46 +0,0 @@
|
||||
/*
|
||||
* mc1322x_syscalls.c - MCU dependent syscall implementation
|
||||
* Copyright (C) 2013 Oliver Hahm <oliver.hahm@inria.fr>
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include "irq.h"
|
||||
|
||||
extern uintptr_t __heap_start; ///< start of heap memory space
|
||||
extern uintptr_t __heap_end; ///< maximum for end of heap memory space
|
||||
|
||||
/// current position in heap
|
||||
static caddr_t heap = (caddr_t)&__heap_start;
|
||||
/// maximum position in heap
|
||||
static const caddr_t heap_max = (caddr_t)&__heap_end;
|
||||
// start position in heap
|
||||
static const caddr_t heap_start = (caddr_t)&__heap_start;
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
caddr_t _sbrk_r(struct _reent *r, ptrdiff_t incr)
|
||||
{
|
||||
uint32_t cpsr = disableIRQ();
|
||||
|
||||
/* check all heaps for a chunk of the requested size */
|
||||
caddr_t new_heap = heap + incr;
|
||||
|
||||
if( new_heap <= heap_max ) {
|
||||
caddr_t prev_heap = heap;
|
||||
heap = new_heap;
|
||||
|
||||
r->_errno = 0;
|
||||
restoreIRQ(cpsr);
|
||||
return prev_heap;
|
||||
}
|
||||
restoreIRQ(cpsr);
|
||||
|
||||
r->_errno = ENOMEM;
|
||||
return NULL;
|
||||
}
|
||||
@ -1,203 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
The following lincence is for all parts of this code done by
|
||||
Martin Thomas. Code from others used here may have other license terms.
|
||||
|
||||
Copyright (C) 2004 Martin THOMAS
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
! The above copyright notice and this permission notice shall be included in all
|
||||
! copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* startup.s - mc1322x specific startup code
|
||||
* Copyright (C) 2013 Thomas Eichinger <thomas.eichinger@fu-berlin.de>
|
||||
*
|
||||
* This source code is licensed under the GNU Lesser General Public License,
|
||||
* Version 2. See the file LICENSE for more details.
|
||||
*
|
||||
* This file is part of RIOT.
|
||||
*/
|
||||
|
||||
/* Standard definitions of Mode bits and Interrupt (I & F) flags in PSRs (program status registers) */
|
||||
.set USR_MODE, 0x10 /* Normal User Mode */
|
||||
.set FIQ_MODE, 0x11 /* FIQ Processing Fast Interrupts Mode */
|
||||
.set IRQ_MODE, 0x12 /* IRQ Processing Standard Interrupts Mode */
|
||||
.set SVC_MODE, 0x13 /* Supervisor Processing Software Interrupts Mode */
|
||||
.set ABT_MODE, 0x17 /* Abort Processing memory Faults Mode */
|
||||
.set UND_MODE, 0x1B /* Undefined Processing Undefined Instructions Mode */
|
||||
.set SYS_MODE, 0x1F /* System Running Priviledged Operating System Tasks Mode */
|
||||
|
||||
.set IRQ_DISABLE, 0x80 /* when I bit is set, IRQ is disabled (program status registers) */
|
||||
.set FIQ_DISABLE, 0x40 /* when F bit is set, FIQ is disabled (program status registers) */
|
||||
|
||||
|
||||
.section .startup
|
||||
|
||||
.set _rom_data_init, 0x108d0
|
||||
.global _startup
|
||||
.func _startup
|
||||
|
||||
_startup:
|
||||
b _begin /* reset - _start */
|
||||
ldr PC, Undef_Addr /* Undefined Instruction */
|
||||
ldr PC, SWI_Addr /* Software Interrupt */
|
||||
ldr PC, PAbt_Addr /* Prefetch Abort */
|
||||
ldr PC, DAbt_Addr /* Data Abort */
|
||||
ldr PC, _not_used
|
||||
ldr PC, IRQ_Addr /* Interrupt Request Interrupt (load from VIC) */
|
||||
ldr PC, _fiq
|
||||
|
||||
/* these vectors are used for rom patching */
|
||||
.org 0x20
|
||||
.code 16
|
||||
_RPTV_0_START:
|
||||
bx lr /* do nothing */
|
||||
|
||||
.org 0x60
|
||||
_RPTV_1_START:
|
||||
bx lr /* do nothing */
|
||||
|
||||
.org 0xa0
|
||||
_RPTV_2_START:
|
||||
bx lr /* do nothing */
|
||||
|
||||
.org 0xe0
|
||||
_RPTV_3_START:
|
||||
bx lr /* do nothing */
|
||||
|
||||
.org 0x120
|
||||
ROM_var_start: .word 0
|
||||
.org 0x7ff
|
||||
ROM_var_end: .word 0
|
||||
|
||||
.code 32
|
||||
.align
|
||||
_begin:
|
||||
/* FIQ mode stack */
|
||||
msr CPSR_c, #(FIQ_MODE | IRQ_DISABLE | FIQ_DISABLE)
|
||||
ldr sp, =__fiq_stack_top__ /* set the FIQ stack pointer */
|
||||
|
||||
/* IRQ mode stack */
|
||||
msr CPSR_c, #(IRQ_MODE | IRQ_DISABLE | FIQ_DISABLE)
|
||||
ldr sp, =__irq_stack_top__ /* set the IRQ stack pointer */
|
||||
|
||||
/* Supervisor mode stack */
|
||||
msr CPSR_c, #(SVC_MODE | IRQ_DISABLE | FIQ_DISABLE)
|
||||
ldr sp, =__svc_stack_top__ /* set the SVC stack pointer */
|
||||
|
||||
/* Undefined mode stack */
|
||||
msr CPSR_c, #(UND_MODE | IRQ_DISABLE | FIQ_DISABLE)
|
||||
ldr sp, =__und_stack_top__ /* set the UND stack pointer */
|
||||
|
||||
/* Abort mode stack */
|
||||
msr CPSR_c, #(ABT_MODE | IRQ_DISABLE | FIQ_DISABLE)
|
||||
ldr sp, =__abt_stack_top__ /* set the ABT stack pointer */
|
||||
|
||||
/* System mode stack */
|
||||
msr CPSR_c, #(SYS_MODE | IRQ_DISABLE | FIQ_DISABLE)
|
||||
ldr sp, =__sys_stack_top__ /* set the SYS stack pointer */
|
||||
|
||||
/* call the rom_data_init function in ROM */
|
||||
/* initializes ROM_var space defined by ROM_var_start and ROM_var_end */
|
||||
/* this area is used by ROM functions (e.g. nvm_read) */
|
||||
ldr r12,=_rom_data_init
|
||||
mov lr,pc
|
||||
bx r12
|
||||
|
||||
msr CPSR_c, #(SYS_MODE)
|
||||
|
||||
/* Clear BSS */
|
||||
clear_bss:
|
||||
ldr r0, _bss_start /* find start of bss segment */
|
||||
ldr r1, _bss_end /* stop here */
|
||||
mov r2, #0x00000000 /* clear */
|
||||
clbss_l:
|
||||
str r2, [r0] /* clear loop... */
|
||||
add r0, r0, #4
|
||||
cmp r0, r1
|
||||
blt clbss_l
|
||||
|
||||
bl bootloader
|
||||
b kernel_init
|
||||
|
||||
/* Exception vector handlers branching table */
|
||||
Undef_Addr: .word UNDEF_Routine
|
||||
SWI_Addr: .word ctx_switch
|
||||
PAbt_Addr: .word PABT_Routine
|
||||
DAbt_Addr: .word DABT_Routine
|
||||
_not_used: .word not_used
|
||||
IRQ_Addr: .word arm_irq_handler
|
||||
_fiq: .word fiq
|
||||
.balignl 16, 0xdeadbeef
|
||||
|
||||
/*
|
||||
* These are defined in the board-specific linker script.
|
||||
*/
|
||||
.globl _bss_start
|
||||
_bss_start:
|
||||
.word __bss_start
|
||||
|
||||
.globl _bss_end
|
||||
_bss_end:
|
||||
.word _end
|
||||
|
||||
.align 5
|
||||
not_used:
|
||||
|
||||
.align 5
|
||||
/*irq:
|
||||
//
|
||||
// .align 5*/
|
||||
fiq:
|
||||
|
||||
.align 5
|
||||
@ -1,246 +0,0 @@
|
||||
/*
|
||||
* syscalls.c - arm system calls
|
||||
* Copyright (C) 2013 Oliver Hahm <oliver.hahm@inria.fr>
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @ingroup cpu_arm7_common
|
||||
* @brief LPC2387 NewLib system calls implementation
|
||||
*
|
||||
* @author Michael Baar <michael.baar@fu-berlin.de>
|
||||
*
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/unistd.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "arm_cpu.h"
|
||||
#include "board_uart0.h"
|
||||
/* core */
|
||||
#include "kernel.h"
|
||||
#include "irq.h"
|
||||
#if defined MODULE_RTC
|
||||
#include "periph/rtc.h"
|
||||
#elif defined MODULE_VTIMER
|
||||
#include "vtimer.h"
|
||||
#endif
|
||||
|
||||
#define DEBUG_SYSCALLS 0
|
||||
#if DEBUG_SYSCALLS
|
||||
#define PRINTF(...) printf(__VA_ARGS__)
|
||||
#else
|
||||
#define PRINTF(...)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @name Heaps (defined in linker script)
|
||||
* @{
|
||||
*/
|
||||
|
||||
extern uintptr_t __heap1_start; ///< start of heap memory space
|
||||
extern uintptr_t __heap1_max; ///< maximum for end of heap memory space
|
||||
extern uintptr_t __heap2_start; ///< start of heap memory space
|
||||
extern uintptr_t __heap2_max; ///< maximum for end of heap memory space
|
||||
extern uintptr_t __heap3_start; ///< start of heap memory space
|
||||
extern uintptr_t __heap3_max; ///< maximum for end of heap memory space
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void __assert_func(const char *file, int line, const char *func, const char *failedexpr)
|
||||
{
|
||||
printf("#!assertion %s failed\n\t%s() in %s:%d\n", failedexpr, func, file, line);
|
||||
_exit(3);
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void __assert(const char *file, int line, const char *failedexpr)
|
||||
{
|
||||
__assert_func(file, line, "?", failedexpr);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int _isatty_r(struct _reent *r, int fd)
|
||||
{
|
||||
r->_errno = 0;
|
||||
|
||||
if (fd == STDOUT_FILENO || fd == STDERR_FILENO) {
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
_off_t _lseek_r(struct _reent *r, int fd, _off_t pos, int whence)
|
||||
{
|
||||
/* to get rid of gcc warnings */
|
||||
(void) fd;
|
||||
(void) pos;
|
||||
(void) whence;
|
||||
_off_t result = -1;
|
||||
PRINTF("lseek [%i] pos %li whence %i\n", fd, pos, whence);
|
||||
|
||||
r->_errno = ENODEV;
|
||||
|
||||
PRINTF("lseek returned %li (0 is success)\n", result);
|
||||
return result;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int _open_r(struct _reent *r, const char *name, int mode)
|
||||
{
|
||||
/* to get rid of gcc warnings */
|
||||
(void) name;
|
||||
(void) mode;
|
||||
int ret = -1;
|
||||
PRINTF("open '%s' mode %#x\n", name, mode);
|
||||
|
||||
r->_errno = ENODEV; // no such device
|
||||
|
||||
PRINTF("open [%i] errno %i\n", ret, r->_errno);
|
||||
return ret;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int _stat_r(struct _reent *r, char *name, struct stat *st)
|
||||
{
|
||||
/* to get rid of gcc warnings */
|
||||
(void) name;
|
||||
(void) st;
|
||||
int ret = -1;
|
||||
PRINTF("_stat_r '%s' \n", name);
|
||||
r->_errno = ENODEV; // no such device
|
||||
PRINTF("_stat_r [%i] errno %i\n", ret, r->_errno);
|
||||
return ret;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int _fstat_r(struct _reent *r, int fd, struct stat *st)
|
||||
{
|
||||
int ret = -1;
|
||||
|
||||
r->_errno = 0;
|
||||
memset(st, 0, sizeof(*st));
|
||||
|
||||
if (fd == STDOUT_FILENO || fd == STDERR_FILENO) {
|
||||
st->st_mode = S_IFCHR;
|
||||
ret = 0;
|
||||
}
|
||||
else {
|
||||
r->_errno = ENODEV;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int _write_r(struct _reent *r, int fd, const void *data, unsigned int count)
|
||||
{
|
||||
int result = EOF;
|
||||
r->_errno = EBADF;
|
||||
|
||||
switch(fd) {
|
||||
case STDOUT_FILENO:
|
||||
case STDERR_FILENO:
|
||||
result = uart0_puts((char *)data, count);
|
||||
break;
|
||||
|
||||
default:
|
||||
PRINTF("write [%i] data @%p count %i\n", fd, data, count);
|
||||
|
||||
PRINTF("write [%i] returned %i errno %i\n", fd, result, r->_errno);
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int _read_r(struct _reent *r, int fd, void *buffer, unsigned int count)
|
||||
{
|
||||
/* to get rid of gcc warnings */
|
||||
(void) fd;
|
||||
(void) buffer;
|
||||
(void) count;
|
||||
int result = -1;
|
||||
r->_errno = EBADF;
|
||||
PRINTF("read [%i] buffer @%p count %i\n", fd, buffer, count);
|
||||
PRINTF("read [%i] returned %i\n", fd, result);
|
||||
|
||||
return result;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int _close_r(struct _reent *r, int fd)
|
||||
{
|
||||
(void) fd;
|
||||
int result = -1;
|
||||
r->_errno = EBADF;
|
||||
PRINTF("close [%i]\n", fd);
|
||||
PRINTF("close returned %i errno %i\n", result, errno);
|
||||
|
||||
return result;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int _unlink_r(struct _reent *r, char *path)
|
||||
{
|
||||
/* get rid of gcc warnings */
|
||||
(void) path;
|
||||
|
||||
int result = -1;
|
||||
r->_errno = ENODEV;
|
||||
PRINTF("unlink '%s'\n", path);
|
||||
PRINTF("unlink returned %i errno %i\n", result, errno);
|
||||
|
||||
return result;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void _exit(int n)
|
||||
{
|
||||
printf("#!exit %i: resetting\n", n);
|
||||
|
||||
stdio_flush();
|
||||
arm_reset();
|
||||
|
||||
while (1);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
pid_t _getpid(void)
|
||||
{
|
||||
return (pid_t) sched_active_pid;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
__attribute__ ((weak))
|
||||
int _kill_r(struct _reent *r, int pid, int sig)
|
||||
{
|
||||
(void) r;
|
||||
(void) pid;
|
||||
(void) sig;
|
||||
/* not implemented */
|
||||
r->_errno = ESRCH; /* no such process */
|
||||
return -1;
|
||||
}
|
||||
|
||||
void _init(void) {}
|
||||
void _fini(void) {}
|
||||
|
||||
/**
|
||||
* @brief Send a signal to a thread
|
||||
*
|
||||
* @param[in] pid the pid to send to
|
||||
* @param[in] sig the signal to send
|
||||
*
|
||||
* @return TODO
|
||||
*/
|
||||
__attribute__ ((weak))
|
||||
int _kill(int pid, int sig)
|
||||
{
|
||||
(void) pid;
|
||||
(void) sig;
|
||||
/* not implemented */
|
||||
errno = ESRCH; /* no such process */
|
||||
return -1;
|
||||
}
|
||||
@ -8,7 +8,7 @@ BOARD ?= native
|
||||
RIOTBASE ?= $(CURDIR)/../..
|
||||
|
||||
BOARD_INSUFFICIENT_MEMORY := airfy-beacon chronos msb-430 msb-430h nrf51dongle \
|
||||
nrf6310 nucleo-f334 pca10000 pca10005 redbee-econotag \
|
||||
nrf6310 nucleo-f334 pca10000 pca10005 \
|
||||
stm32f0discovery telosb wsn430-v1_3b wsn430-v1_4 \
|
||||
yunjia-nrf51822 z1
|
||||
|
||||
|
||||
@ -5,8 +5,6 @@ include ../Makefile.tests_common
|
||||
BOARD_BLACKLIST := arduino-mega2560 chronos msb-430 msb-430h telosb \
|
||||
wsn430-v1_3b wsn430-v1_4 z1
|
||||
|
||||
BOARD_INSUFFICIENT_MEMORY := redbee-econotag
|
||||
|
||||
USEPKG += libcoap
|
||||
|
||||
include $(RIOTBASE)/Makefile.include
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
APPLICATION = posix_semaphore
|
||||
include ../Makefile.tests_common
|
||||
|
||||
BOARD_INSUFFICIENT_MEMORY := msb-430 msb-430h mbed_lpc1768 redbee-econotag chronos stm32f0discovery \
|
||||
BOARD_INSUFFICIENT_MEMORY := msb-430 msb-430h mbed_lpc1768 chronos stm32f0discovery \
|
||||
pca10000 pca10005 yunjia-nrf51822 nrf6310 spark-core
|
||||
|
||||
USEMODULE += posix
|
||||
|
||||
@ -9,7 +9,4 @@ USEMODULE += timex
|
||||
# The MSP-430 toolchain lacks sscanf:
|
||||
BOARD_BLACKLIST := chronos msb-430 msb-430h telosb wsn430-v1_3b wsn430-v1_4 z1
|
||||
|
||||
# Too little RAM
|
||||
BOARD_BLACKLIST += redbee-econotag
|
||||
|
||||
include $(RIOTBASE)/Makefile.include
|
||||
|
||||
@ -2,7 +2,7 @@ APPLICATION = thread_cooperation
|
||||
include ../Makefile.tests_common
|
||||
|
||||
BOARD_INSUFFICIENT_MEMORY := chronos msb-430 msb-430h mbed_lpc1768 \
|
||||
redbee-econotag stm32f0discovery pca10000 pca10005 \
|
||||
stm32f0discovery pca10000 pca10005 \
|
||||
yunjia-nrf51822 spark-core airfy-beacon nucleo-f334 \
|
||||
nrf51dongle nrf6310
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@ APPLICATION = unittests
|
||||
include ../Makefile.tests_common
|
||||
|
||||
BOARD_INSUFFICIENT_MEMORY := airfy-beacon chronos msb-430 msb-430h pca10000 \
|
||||
pca10005 redbee-econotag spark-core stm32f0discovery \
|
||||
pca10005 spark-core stm32f0discovery \
|
||||
telosb wsn430-v1_3b wsn430-v1_4 z1 nucleo-f334 \
|
||||
yunjia-nrf51822 samr21-xpro arduino-mega2560 \
|
||||
airfy-beacon nrf51dongle nrf6310
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user