Merge branch 'master' of git://git.devl.org/git/malvira/libmc1322x into uart-upstream

Conflicts:
	cpu/mc1322x/lib/include/uart.h
	cpu/mc1322x/src/default_lowlevel.c
This commit is contained in:
Mariano Alvira 2011-07-08 19:21:15 -04:00
commit e2d74fa0a5
15 changed files with 367 additions and 25 deletions

Binary file not shown.

View File

@ -2,7 +2,8 @@ import graph;
size(350,250,IgnoreAspect);
file fin=input("./1000pkt-64len.csv");
real[][] A=dimension(csv(fin),0,2);
fin.csv();
real[][] A=fin.dimension(0,2);
real[][] pdr=transpose(A);
int[] lqi = sequence(100);

View File

@ -163,6 +163,7 @@ 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));

View File

@ -44,7 +44,7 @@
#include "kbi.h"
#include "maca.h"
#include "packet.h"
#include "uart1.h"
#include "uart.h"
#include "utils.h"
#include "asm.h"

View File

@ -33,11 +33,94 @@
*
*/
#ifndef UART1_H
#define UART1_H
#ifndef UART_H
#define UART_H
#include <stdint.h>
/* Timer registers are all 16-bit wide with 16-bit access only */
#define UART1_BASE (0x80005000)
#define UART2_BASE (0x8000B000)
struct UART_struct {
union {
uint32_t CON;
struct UART_CON {
uint32_t :16;
uint32_t TST:1;
uint32_t MRXR:1;
uint32_t MTXR:1;
uint32_t FCE:1;
uint32_t FCP:1;
uint32_t XTIM:1;
uint32_t :2;
uint32_t TXOENB:1;
uint32_t CONTX:1;
uint32_t SB:1;
uint32_t ST2:1;
uint32_t EP:1;
uint32_t PEN:1;
uint32_t RXE:1;
uint32_t TXE:1;
} CONbits;
};
union {
uint32_t STAT;
struct UART_STAT {
uint32_t :24;
uint32_t TXRDY:1;
uint32_t RXRDY:1;
uint32_t RUE:1;
uint32_t ROE:1;
uint32_t TOE:1;
uint32_t FE:1;
uint32_t PE:1;
uint32_t SE:1;
} USTATbits;
};
union {
uint32_t DATA;
struct UART_DATA {
uint32_t :24;
uint32_t DATA:8;
} DATAbits;
};
union {
uint32_t RXCON;
struct UART_URXCON {
uint32_t :26;
uint32_t LVL:6;
} RXCONbits;
};
union {
uint32_t TXCON;
struct UART_TXCON {
uint32_t :26;
uint32_t LVL:6;
} TXCONbits;
};
union {
uint32_t CTS;
struct UART_CTS {
uint32_t :27;
uint32_t LVL:5;
} CTSbits;
};
union {
uint32_t BR;
struct UART_BR {
uint32_t INC:16;
uint32_t MOD:16;
} BRbits;
};
};
static volatile struct UART_struct * const UART1 = (void *) (UART1_BASE);
static volatile struct UART_struct * const UART2 = (void *) (UART2_BASE);
/* Old uart definitions, for compatibility */
#ifndef REG_NO_COMPAT
#define UCON (0)
/* UCON bits */
#define UCON_SAMP 10
@ -51,9 +134,6 @@
#define UCTS (0x14)
#define UBRCNT (0x18)
#define UART1_BASE (0x80005000)
#define UART2_BASE (0x8000b000)
#define UART1_UCON ((volatile uint32_t *) ( UART1_BASE + UCON ))
#define UART1_USTAT ((volatile uint32_t *) ( UART1_BASE + USTAT ))
#define UART1_UDATA ((volatile uint32_t *) ( UART1_BASE + UDATA ))
@ -70,6 +150,8 @@
#define UART2_UCTS ((volatile uint32_t *) ( UART2_BASE + UCTS ))
#define UART2_UBRCNT ((volatile uint32_t *) ( UART2_BASE + UBRCNT ))
#endif /* REG_NO_COMPAT */
/* The mc1322x has a 32 byte hardware FIFO for transmitted characters.
* Currently it is always filled from a larger RAM buffer. It would be
* possible to eliminate that overhead by filling directly from a chain
@ -95,6 +177,9 @@ extern volatile uint32_t u1_rx_head, u1_rx_tail;
#endif
uint8_t uart1_getc(void);
extern volatile uint32_t u2_head, u2_tail;
void uart2_putc(char c);
#define uart2_can_get() (*UART2_URXCON > 0)
uint8_t uart2_getc(void);
#endif

78
cpu/mc1322x/lib/uart2.c Normal file
View File

@ -0,0 +1,78 @@
/*
* 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.
*
*
*/
#include <mc1322x.h>
#include <stdint.h>
volatile char u2_tx_buf[64];
volatile uint32_t u2_head, u2_tail;
void uart2_isr(void) {
while( *UART1_UTXCON != 0 ) {
if (u2_head == u2_tail) {
disable_irq(UART2);
return;
}
*UART2_UDATA = u2_tx_buf[u2_tail];
u2_tail++;
if (u2_tail >= sizeof(u2_tx_buf))
u2_tail = 0;
}
}
void uart2_putc(char c) {
/* disable UART2 since */
/* UART2 isr modifies u2_head and u2_tail */
disable_irq(UART2);
if( (u2_head == u2_tail) &&
(*UART2_UTXCON != 0)) {
*UART2_UDATA = c;
} else {
u2_tx_buf[u2_head] = c;
u2_head += 1;
if (u2_head >= sizeof(u2_tx_buf))
u2_head = 0;
if (u2_head == u2_tail) { /* drop chars when no room */
if (u2_head) { u2_head -=1; } else { u2_head = sizeof(u2_tx_buf); }
}
enable_irq(UART1);
}
}
uint8_t uart2_getc(void) {
while(uart2_can_get() == 0) { continue; }
return *UART2_UDATA;
}

View File

@ -45,11 +45,12 @@ void default_vreg_init(void) {
*CRM_VREG_CNTL = 0x00000ff8; /* start the regulators */
}
void uart1_init(uint16_t inc, uint16_t mod, uint8_t samp) {
void uart1_init(volatile uint16_t inc, volatile uint16_t mod, volatile uint8_t samp) {
/* UART must be disabled to set the baudrate */
*UART1_UCON = 0;
*UART1_UBRCNT = ( inc << 16 ) | mod;
UART1->CON = 0;
UART1->BR = ( inc << 16 ) | mod;
/* TX and CTS as outputs */
GPIO->PAD_DIR_SET.GPIO_14 = 1;
@ -90,3 +91,34 @@ void uart1_init(uint16_t inc, uint16_t mod, uint8_t samp) {
/* enable UART1 interrupts in the interrupt controller */
enable_irq(UART1);
}
void uart2_init(volatile uint16_t inc, volatile uint16_t mod, volatile uint8_t samp) {
/* UART must be disabled to set the baudrate */
UART2->CON = 0;
UART2->BR = ( inc << 16 ) | mod;
/* see Section 11.5.1.2 Alternate Modes */
/* you must enable the peripheral first BEFORE setting the function in GPIO_FUNC_SEL */
/* From the datasheet: "The peripheral function will control operation of the pad IF */
/* THE PERIPHERAL IS ENABLED. Can override with U2_ENABLE_DEFAULT. */
UART2->CON = (1 << 0) | (1 << 1); /* enable receive, transmit */
if(samp == UCON_SAMP_16X)
set_bit(*UART2_UCON, samp);
/* set GPIO18-19 to UART (UART2 TX and RX)*/
GPIO->FUNC_SEL.GPIO_18 = 1;
GPIO->FUNC_SEL.GPIO_19 = 1;
/* interrupt when there are this number or more bytes free in the TX buffer*/
UART2->TXCON = 16;
UART2->RXCON = 16;
u2_head = 0; u2_tail = 0;
/* tx and rx interrupts are enabled in the UART by default */
/* see status register bits 13 and 14 */
/* enable UART2 interrupts in the interrupt controller */
enable_irq(UART2);
}

View File

@ -42,6 +42,7 @@
void default_vreg_init(void);
void uart1_init(uint16_t inc, uint16_t mod, uint8_t samp);
void uart2_init(uint16_t inc, uint16_t mod, uint8_t samp);
void irq_register_timer_handler(int timer, void (*isr)(void));

View File

@ -74,6 +74,9 @@ void irq(void)
if(bit_is_set(pending, INT_NUM_UART1)) {
if(uart1_isr != 0) { uart1_isr(); }
}
if(bit_is_set(pending, INT_NUM_UART2)) {
if(uart2_isr != 0) { uart2_isr(); }
}
if(bit_is_set(pending, INT_NUM_CRM)) {
if(rtc_wu_evt() && (rtc_isr != 0)) { rtc_isr(); }
if(kbi_evnt(4) && (kbi4_isr != 0)) { kbi4_isr(); }

View File

@ -8,13 +8,15 @@ COBJS := tests.o put.o
# all of the target programs to build
TARGETS := blink-red blink-green blink-blue blink-white blink-allio \
uart1-loopback \
u1u2-loopback \
tmr tmr-ints \
sleep \
printf \
asm \
adc \
pwm \
wdt
wdt \
xtal-trim
# these targets are built with space reserved for variables needed by ROM services
# this space is initialized with a rom call to rom_data_init

View File

@ -0,0 +1,58 @@
/*
* Copyright (c) 2010, Mariano Alvira <mar@devl.org> and other contributors
* to the MC1322x project (http://mc1322x.devl.org)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of libmc1322x: see http://mc1322x.devl.org
* for details.
*
*
*/
#include <mc1322x.h>
#include <board.h>
#include "tests.h"
#include "config.h"
void main(void) {
uart1_init(INC,MOD,SAMP);
uart2_init(INC,MOD,SAMP);
while(1) {
if(uart1_can_get()) {
/* Receive buffer isn't empty */
/* read a byte and write it to the transmit buffer */
uart2_putc(uart1_getc());
}
if(uart2_can_get()) {
uart1_putc(uart2_getc());
}
}
}

View File

@ -0,0 +1,71 @@
/*
* 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.
*
*
*/
#include <mc1322x.h>
#include <board.h>
#include <stdio.h>
#include "config.h"
#include "tests.h"
int main(void)
{
uint8_t ctune_4pf, ctune, ftune;
ctune_4pf = 0;
ctune = 0;
ftune = 0;
uart1_init(INC,MOD,SAMP);
print_welcome("pwm test\r\n");
pack_XTAL_CNTL(ctune_4pf, ctune, ftune, IBIAS);
for(;;) {
switch(uart1_getc()) {
case '[': if(ctune > 0) ctune -= 1; break;
case ']': if(ctune < 15) ctune += 1; break;
case '-': if(ftune > 0) ftune -= 1; break;
case '=': if(ftune < 31) ftune += 1; break;
case ' ': if(ctune_4pf) { ctune_4pf = 0; } else { ctune_4pf = 1;} break;
}
printf("ctune_4pf %d; ctune %d; ftune %d\n\r", ctune_4pf, ctune, ftune);
pack_XTAL_CNTL(ctune_4pf, ctune, ftune, IBIAS);
}
}

View File

@ -6,10 +6,12 @@ my $oui;
my $addr = "0x1e000";
my $iab;
my $term = "/dev/ttyUSB1";
my $index = 0;
GetOptions ('iab=s' => \$iab,
'oui=s' => \$oui,
'term=s' => \$term,
'index=s' => \$index,
) or die 'bad options';
my $bin = shift;
@ -59,7 +61,7 @@ reverse @words;
my $word1 = sprintf("%02X%02X%02X%02X",$words[4],$words[5],$words[6],$words[7]);
my $word2 = sprintf("%02X%02X%02X%02X",$words[0],$words[1],$words[2],$words[3]);
my $cmd = "mc1322x-load.pl -e -f $bin -z -t $term -c 'bbmc -l redbee-econotag reset' $addr,0x$word1,0x$word2 &";
my $cmd = "mc1322x-load.pl -e -f $bin -z -t $term -c 'bbmc -i $index -l redbee-econotag reset' $addr,0x$word1,0x$word2 &";
print "$cmd\n";
system($cmd);

View File

@ -47,6 +47,7 @@ my $network = 230; # 802.15.4 no FCS
my $newpacket = 0;
my $len = 0;
my $file_empty = 1;
print pack('LSSLLLL',($magic,$major,$minor,$zone,$sig,$snaplen,$network));
@ -75,9 +76,13 @@ while(1) {
$newpacket = 0;
print pack('LLLL',($sec,$usec,$len,$len));
print STDERR "new packet: $sec $usec $len " . ($len) . "\n\r";
# This header starts the file
if ($file_empty == 1) {
$file_empty = 0;
}
# packet payload
}
# packet payload (don't start the file with a payload)
if ($file_empty == 0) {
print STDERR "dataline: ";
print STDERR $str . "\n\r";
@ -85,6 +90,8 @@ while(1) {
print pack ('C',hex($data));
}
}
}
$str = '';
}
}

View File

@ -44,7 +44,8 @@ for (my $t=0; $t<$terms; $t++) {
my $word2 = sprintf("%02X%02X%02X%02X",$words[0],$words[1],$words[2],$words[3]);
my $ftdi_num = $terms - $t - 1;
my $cmd = "mc1322x-load.pl -e -f $bin -z -t /dev/ttyUSB$dev_num -c 'bbmc -l redbee-econotag -i $ftdi_num reset' $addr,0x$word1,0x$word2 &";
my $cmd = "../burn-mac.pl --iab=a8c --term=/dev/ttyUSB$dev_num --index=$ftdi_num $bin $dev_num";
print "$cmd\n";
system($cmd);
}