Fixes and improvements from Anthony Asterisk

- First in 8051def.h,  it appears the uip_arch-asm.S file was copied from z80 and am unsure it will work properly.  I modified the 8051def.h to prevent the UIP code from using these routines.
- In dma.c the config routine provides access to all of the DMA channel options, except for the word mode flag.  In order to maintain compatibility with any existing code I created a second routine and converted the original routine into a wrapper routine with a fixed word mode value.
- uart.c::uart0_init was missing blocking access to the higher baud rates.  I am not sure why, so I corrected this.
- I also copied over to header files that provide some useful macros from the msp430 cpu.  The files are lpm.h and hwconf.h.  The lpm.h is for switching power modes, I think.  The hwconf.h has various macros for configuring port I/O.  By porting these files the led/button api's can be ported with minimal modifications.
This commit is contained in:
zdshelby 2009-12-22 09:28:14 +00:00
parent e032f7ac2c
commit c5ecde4ca0
7 changed files with 213 additions and 22 deletions

View file

@ -70,8 +70,13 @@ typedef unsigned int size_t;
* @see uip_arch.h * @see uip_arch.h
* @see uip_arch-asm.S * @see uip_arch-asm.S
*/ */
#define UIP_ARCH_ADD32 1 /*
#define UIP_ARCH_CHKSUM 1 * DO NOT USE UIP_ARCH flags!
* uip_arch code was copied from z80 directory but NOT ported
*/
#define UIP_ARCH_ADD32 0
#define UIP_ARCH_CHKSUM 0
#define UIP_ARCH_IPCHKSUM #define UIP_ARCH_IPCHKSUM
#define CC_CONF_ASSIGN_AGGREGATE(dest, src) \ #define CC_CONF_ASSIGN_AGGREGATE(dest, src) \

View file

@ -700,4 +700,6 @@ __xdata __at (0xDFD9) unsigned char RFD_SHADOW;
__xdata __at (0xDFF9) unsigned char U1BUF_SHADOW; __xdata __at (0xDFF9) unsigned char U1BUF_SHADOW;
__xdata __at (0xDFBA) unsigned int ADC_SHADOW;
#endif /*REG_CC2430*/ #endif /*REG_CC2430*/

View file

@ -35,7 +35,7 @@ dma_init(void)
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#ifdef HAVE_DMA #ifdef HAVE_DMA
/** /**
* Configure a DMA channel. * Configure a DMA channel except word mode.
* *
* \param channel channel ID; * \param channel channel ID;
* \param src source address; * \param src source address;
@ -55,6 +55,33 @@ xDMAHandle
dma_config(uint8_t channel, void *src, dma_inc_t src_inc, void *dst, dma_inc_t dst_inc, dma_config(uint8_t channel, void *src, dma_inc_t src_inc, void *dst, dma_inc_t dst_inc,
uint16_t length, dma_vlen_t vlen_mode, dma_type_t t_mode, dma_trigger_t trigger, uint16_t length, dma_vlen_t vlen_mode, dma_type_t t_mode, dma_trigger_t trigger,
struct process * proc) struct process * proc)
{
return dma_config2(channel,src,src_inc, dst, dst_inc, length, 0, vlen_mode, t_mode, trigger, proc);
}
/*---------------------------------------------------------------------------*/
/**
* Configure a DMA channel.
*
* \param channel channel ID;
* \param src source address;
* \param src_inc source increment mode;
* \param dst dest address;
* \param dst_inc dest increment mode;
* \param length maximum length;
* \param word_mode set to 1 for 16-bits per transfer;
* \param vlen_mode variable length mode;
* \param t_mode DMA transfer mode;
* \param trigger DMA trigger;
* \param proc process that is upon interrupt;
*
* \return Handle to DMA channel
* \return 0 invalid channel
*/
xDMAHandle
dma_config2(uint8_t channel, void *src, dma_inc_t src_inc, void *dst, dma_inc_t dst_inc,
uint16_t length, uint8_t word_mode, dma_vlen_t vlen_mode, dma_type_t t_mode, dma_trigger_t trigger,
struct process * proc)
{ {
if((!channel) || (channel > 4)) { if((!channel) || (channel > 4)) {
return 0; return 0;
@ -70,7 +97,7 @@ dma_config(uint8_t channel, void *src, dma_inc_t src_inc, void *dst, dma_inc_t d
dma_conf[channel].dst_l = ((uint16_t) dst); dma_conf[channel].dst_l = ((uint16_t) dst);
dma_conf[channel].len_h = vlen_mode + (length >> 8); dma_conf[channel].len_h = vlen_mode + (length >> 8);
dma_conf[channel].len_l = length; dma_conf[channel].len_l = length;
dma_conf[channel].t_mode = (t_mode << 5) + trigger; dma_conf[channel].t_mode = ((word_mode&0x1)<<7) | (t_mode << 5) | trigger;
dma_conf[channel].addr_mode = (src_inc << 6) + (dst_inc << 4) + 2; /*DMA has priority*/ dma_conf[channel].addr_mode = (src_inc << 6) + (dst_inc << 4) + 2; /*DMA has priority*/
/*Callback is defined*/ /*Callback is defined*/
@ -176,7 +203,7 @@ dma_config_print(xDMAHandle channel)
uint8_t *ptr = (uint8_t *)&(dma_conf[ch_id]); uint8_t *ptr = (uint8_t *)&(dma_conf[ch_id]);
for(i = 0; i< 8; i++) { for(i = 0; i< 8; i++) {
if(i != 0) { if(i != 0) {
printf(":%x", *ptr++); printf(":%02x", *ptr++);
} }
} }
printf("\n"); printf("\n");
@ -216,7 +243,6 @@ dma_ISR(void) __interrupt (DMA_VECTOR)
spi_rx_dma_callback(); spi_rx_dma_callback();
} }
#endif #endif
#ifdef HAVE_DMA #ifdef HAVE_DMA
for(i = 0; i < 4; i++) { for(i = 0; i < 4; i++) {
if((DMAIRQ & (1 << i + 1)) != 0) { if((DMAIRQ & (1 << i + 1)) != 0) {

89
cpu/cc2430/dev/hwconf.h Normal file
View file

@ -0,0 +1,89 @@
/*
* Copyright (c) 2005, Swedish Institute of Computer Science
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
* @(#)$Id: hwconf.h,v 1.1 2009/12/22 09:28:15 zdshelby Exp $
*/
#ifndef __HWCONF_H__
#define __HWCONF_H__
#include "sys/cc.h"
#include <cc2430_sfr.h>
extern uint8_t p0ien;
extern uint8_t p2ien;
#define HWCONF_PIN(name, port, bit) \
static CC_INLINE void name##_SELECT() { P##port##SEL &= ~(1 << bit);} \
static CC_INLINE void name##_SELECT_IO() { P##port##SEL &= ~(1 << bit);} \
static CC_INLINE void name##_SELECT_PM() { P##port##SEL |= 1 << bit;} \
static CC_INLINE void name##_SET() { P##port##_##bit = 1; } \
static CC_INLINE void name##_CLEAR() { P##port##_##bit = 0; } \
static CC_INLINE unsigned char name##_READ() { return P##port##_##bit; } \
static CC_INLINE void name##_MAKE_OUTPUT() { P##port##DIR |= 1 << bit;} \
static CC_INLINE void name##_MAKE_INPUT() { P##port##DIR &= ~(1 << bit); }
#define HWCONF_IRQ_XXX(name, port, bit) \
static CC_INLINE void name##_ENABLE_IRQ() { \
if ( port == 2 ) { PICTL |= P2IEN; p2ien |= 1<<bit; } \
if (( port == 0) && ( bit <4)) { PICTL |= P0IENL; p0ien |= 1<<bit; } \
if ((port == 0) && ( bit >=4)) { PICTL |= P0IENH; p0ien |= 1<<bit; } \
if ( port == 1) { P##port##IEN |= 1 << bit; } \
} \
static CC_INLINE void name##_DISABLE_IRQ() { \
if ( port == 2 ) { \
p2ien &= ~(1<<bit); \
if (p2ien==0) PICTL &= ~P2IEN; \
} \
if (( port == 0) && ( bit <4)) { \
p0ien &= ~(1<<bit); \
if ((p0ien&0xf)==0) PICTL &= ~P0IENL; \
} \
if (( port == 0) && ( bit >=4)) { \
p0ien &= ~(1<<bit); \
if ((p0ien&0xf0)==0) PICTL &= ~P0IENH; \
} \
if ( port == 1) { P##port##IEN &= ~(1 << bit); } \
} \
static CC_INLINE int name##_IRQ_ENABLED() {return P##port##IEN & (1 << bit);} \
static CC_INLINE int name##_CHECK_IRQ() {return P##port##IFG & (1 << bit);} \
static CC_INLINE int name##_IRQ_PORT() {return IRQ_PORT##port;}
#define HWCONF_IRQ(name, port, bit) \
static CC_INLINE void name##_ENABLE_IRQ() { \
if ( port == 1) { P##port##IEN |= 1 << bit; } \
} \
static CC_INLINE void name##_DISABLE_IRQ() { \
if ( port == 1) { P##port##IEN &= ~(1 << bit); } \
} \
static CC_INLINE int name##_IRQ_ENABLED() {return P##port##IEN & (1 << bit);} \
static CC_INLINE int name##_CHECK_IRQ() {return P##port##IFG & (1 << bit);} \
static CC_INLINE int name##_IRQ_PORT() {return IRQ_PORT##port;}
#endif /* __HWCONF_H__ */

63
cpu/cc2430/dev/lpm.h Normal file
View file

@ -0,0 +1,63 @@
/*
* Copyright (c) 2005, Swedish Institute of Computer Science
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
* @(#)$Id: lpm.h,v 1.1 2009/12/22 09:28:15 zdshelby Exp $
*/
#ifndef __LPM_H__
#define __LPM_H__
#include <io.h>
#include "contiki-conf.h"
#ifdef LPM_CONF_ON
#define LPM_ON LPM_CONF_ON
#else
#define LPM_ON LPM1
#endif /* LPM_CONF_ON */
#ifdef LPM_CONF_OFF
#define LPM_OFF LPM_CONF_OFF
#else
#define LPM_OFF LPM1_EXIT
#endif /* LPM_CONF_OFF */
#define LPM_SLEEP() do { if(lpm_status == LPM_STATUS_ON) LPM_ON; } while(0)
#define LPM_AWAKE() do { if(lpm_status == LPM_STATUS_ON) LPM_OFF; } while(0)
extern unsigned char lpm_status;
void lpm_on(void);
void lpm_off(void);
#define LPM_STATUS_OFF 0
#define LPM_STATUS_ON 1
#endif /* __LPM_H__ */

View file

@ -13,9 +13,19 @@ static int (*uart1_input_handler)(unsigned char c);
void void
uart0_init(uint32_t speed) uart0_init(uint32_t speed)
{ {
if(speed != 115200) { if(speed == 115200) {
return; U0BAUD=216; /*115200*/
U0GCR =11; /*LSB first and 115200*/
} }
else if(speed == 38400) {
U0BAUD=59; /*38400*/
U0GCR =10; /*LSB first and 38400*/
}
else if(speed == 9600) {
U0BAUD= 59; /* 9600 */
U0GCR = 8; /*LSB first and 9600*/
}
else { return; }
#ifdef UART0_ALTERNATIVE_2 #ifdef UART0_ALTERNATIVE_2
PERCFG |= U0CFG; /*alternative port 2 = P1.5-2*/ PERCFG |= U0CFG; /*alternative port 2 = P1.5-2*/
@ -39,20 +49,6 @@ uart0_init(uint32_t speed)
P0DIR &= ~0x14; /*CTS & RX in*/ P0DIR &= ~0x14; /*CTS & RX in*/
#endif #endif
if(speed == 115200) {
U0BAUD=216; /*115200*/
U0GCR =11; /*LSB first and 115200*/
}
if(speed == 38400) {
U0BAUD=59; /*38400*/
U0GCR =10; /*LSB first and 38400*/
}
if(speed == 9600) {
U0BAUD= 59; /* 9600 */
U0GCR = 8; /*LSB first and 9600*/
}
#ifdef UART0_RTSCTS #ifdef UART0_RTSCTS
U0UCR = 0x42; /*defaults: 8N1, RTS/CTS, high stop bit*/ U0UCR = 0x42; /*defaults: 8N1, RTS/CTS, high stop bit*/

10
cpu/cc2430/io.h Normal file
View file

@ -0,0 +1,10 @@
#ifndef __IO_H__
#define __IO_H__
#include <cc2430_sfr.h>
#ifndef BV
#define BV(x) (1<<(x))
#endif
#endif /* __IO_H__ */