fixed problems with uart and sd cards.

This commit is contained in:
nvt-se 2008-10-28 12:42:53 +00:00
parent 1de0d38ccb
commit 1fdb3c21f0
5 changed files with 149 additions and 137 deletions

View file

@ -1,95 +1,100 @@
#ifndef CONTIKI_CONF_H
#define CONTIKI_CONF_H
#define HAVE_STDINT_H
#include "msp430def.h"
#define ENERGEST_CONF_ON 1
#define IRQ_PORT1 0x01
#define IRQ_PORT2 0x02
#define IRQ_ADC 0x03
// MSB430 SD Card driver
#define SD_CACHE 1
#define SD_READ_ANY 1
#define SD_WRITE 1
// MSP430 Infomemory
#define INFOMEM_START 0x1000
#define INFOMEM_BLOCK_SIZE 128
#define INFOMEM_NODE_ID 0x0000 /* - 0x0004 */
#define CFS_SD_CONF_OFFSET 0x0000
#define CC_CONF_REGISTER_ARGS 1
#define CC_CONF_FUNCTION_POINTER_ARGS 1
#define CC_CONF_INLINE inline
#define CC_CONF_VA_ARGS 1
#define CCIF
#define CLIF
/* Clear channel assessment timeout for sending with the CC1020 radio. (ms) */
#define CC1020_CONF_CCA_TIMEOUT 50
// Clock
typedef unsigned short clock_time_t;
#define CLOCK_CONF_SECOND 64
#define F_CPU 2457600uL // CPU target speed in Hz
#define BAUD2UBR(baud) (F_CPU/(baud))
#include "ctk/ctk-vncarch.h"
#define LOG_CONF_ENABLED 0
/**
* The statistics data type.
*
* This datatype determines how high the statistics counters are able
* to count.
*/
typedef uint16_t uip_stats_t;
typedef int bool;
#define TRUE 1
#define FALSE 0
#define UIP_CONF_ICMP_DEST_UNREACH 1
#define UIP_CONF_DHCP_LIGHT
#define UIP_CONF_LLH_LEN 0
#define UIP_CONF_BUFFER_SIZE 116
#define UIP_CONF_RECEIVE_WINDOW (UIP_CONF_BUFFER_SIZE - 40)
#define UIP_CONF_MAX_CONNECTIONS 4
#define UIP_CONF_MAX_LISTENPORTS 8
#define UIP_CONF_UDP_CONNS 8
#define UIP_CONF_FWCACHE_SIZE 20
#define UIP_CONF_BROADCAST 1
#define UIP_ARCH_IPCHKSUM 1
#define UIP_CONF_UDP_CHECKSUMS 1
#define UIP_CONF_PINGADDRCONF 0
#define UIP_CONF_LOGGING 0
#define LOADER_CONF_ARCH "loader/loader-arch.h"
#define ELFLOADER_CONF_DATAMEMORY_SIZE 100
#define ELFLOADER_CONF_TEXTMEMORY_SIZE 0x1000
/* LEDs ports MSB430 */
#define LEDS_PxDIR P5DIR
#define LEDS_PxOUT P5OUT
#define LEDS_CONF_RED 0x80
#define LEDS_CONF_GREEN 0x00
#define LEDS_CONF_YELLOW 0x00
#define SD_LED_READ_ON (LEDS_PxOUT &=~LEDS_CONF_RED)
#define SD_LED_READ_OFF (LEDS_PxOUT |= LEDS_CONF_RED)
#define SD_LED_WRITE_ON SD_LED_READ_ON
#define SD_LED_WRITE_OFF SD_LED_READ_OFF
#define SPI_WRITE SD_WRITE
#define SPI_DMA_READ 0
#define SPI_DMA_WRITE 0
#endif /* !CONTIKI_CONF_H */
#ifndef CONTIKI_CONF_H
#define CONTIKI_CONF_H
#define HAVE_STDINT_H
#include "msp430def.h"
#define WITH_SDC 1
#define ENERGEST_CONF_ON 1
#define IRQ_PORT1 0x01
#define IRQ_PORT2 0x02
#define IRQ_ADC 0x03
// MSP430 Infomemory
#define INFOMEM_START 0x1000
#define INFOMEM_BLOCK_SIZE 128
#define INFOMEM_NODE_ID 0x0000 /* - 0x0004 */
#define CFS_SD_CONF_OFFSET 0x0000
#define CC_CONF_REGISTER_ARGS 1
#define CC_CONF_FUNCTION_POINTER_ARGS 1
#define CC_CONF_INLINE inline
#define CC_CONF_VA_ARGS 1
#define CCIF
#define CLIF
/* Clear channel assessment timeout for sending with the CC1020 radio. (ms) */
#define CC1020_CONF_CCA_TIMEOUT 50
// Clock
typedef unsigned short clock_time_t;
#define CLOCK_CONF_SECOND 64
#define F_CPU 2457600uL // CPU target speed in Hz
#define BAUD2UBR(baud) (F_CPU/(baud))
#include "ctk/ctk-vncarch.h"
#define LOG_CONF_ENABLED 0
/**
* The statistics data type.
*
* This datatype determines how high the statistics counters are able
* to count.
*/
typedef uint16_t uip_stats_t;
typedef int bool;
#define TRUE 1
#define FALSE 0
#define UIP_CONF_ICMP_DEST_UNREACH 1
#define UIP_CONF_DHCP_LIGHT
#define UIP_CONF_LLH_LEN 0
#define UIP_CONF_BUFFER_SIZE 116
#define UIP_CONF_RECEIVE_WINDOW (UIP_CONF_BUFFER_SIZE - 40)
#define UIP_CONF_MAX_CONNECTIONS 4
#define UIP_CONF_MAX_LISTENPORTS 8
#define UIP_CONF_UDP_CONNS 8
#define UIP_CONF_FWCACHE_SIZE 20
#define UIP_CONF_BROADCAST 1
#define UIP_ARCH_IPCHKSUM 1
#define UIP_CONF_UDP_CHECKSUMS 1
#define UIP_CONF_PINGADDRCONF 0
#define UIP_CONF_LOGGING 0
#define LOADER_CONF_ARCH "loader/loader-arch.h"
#define ELFLOADER_CONF_DATAMEMORY_SIZE 100
#define ELFLOADER_CONF_TEXTMEMORY_SIZE 0x1000
/* LEDs ports MSB430 */
#define LEDS_PxDIR P5DIR
#define LEDS_PxOUT P5OUT
#define LEDS_CONF_RED 0x80
#define LEDS_CONF_GREEN 0x00
#define LEDS_CONF_YELLOW 0x00
#define SD_LED_READ_ON (LEDS_PxOUT &=~LEDS_CONF_RED)
#define SD_LED_READ_OFF (LEDS_PxOUT |= LEDS_CONF_RED)
#define SD_LED_WRITE_ON SD_LED_READ_ON
#define SD_LED_WRITE_OFF SD_LED_READ_OFF
// MSB430 SD Card driver
#define SD_READ_BYTE 0
#define SD_READ_ANY 1
#define SD_INFO 0
#define SD_WRITE 1
#define SD_FIND_FILE 0
#define SD_ERASE 0
#define SD_CACHE 0
#define SPI_WRITE SD_WRITE
#define SPI_DMA_READ 0
#define SPI_DMA_WRITE 0
#endif /* !CONTIKI_CONF_H */

View file

@ -80,7 +80,7 @@ uart_configure(unsigned mode)
UART_WAIT_TXDONE(); // wait till all buffered data has been transmitted
// configure
if (mode == UART_MODE_RS232) {
if(mode == UART_MODE_RS232) {
P5OUT |= 0x01;
// unselect SPI
P3SEL |= 0xC0;
@ -90,7 +90,7 @@ uart_configure(unsigned mode)
UTCTL1 |= SSEL1; // UCLK = MCLK
// activate
U1ME |= UTXE1 | URXE1; // Enable USART1 TXD/RXD
} else if( mode == UART_MODE_SPI ) {
} else if(mode == UART_MODE_SPI) {
P3SEL &= ~0xC0; // unselect RS232
// to SPI mode
UCTL1 = SWRST | CHAR | SYNC | MM; // 8-bit SPI Master
@ -131,7 +131,7 @@ uart_set_handler(unsigned mode, fp_uart_handler fpHandler)
{
// store setting
uart_handler[mode] = fpHandler;
if (mode == uart_mode) {
if(mode == uart_mode) {
if (fpHandler == NULL) {
IE2 &= ~URXIE1; // Disable USART1 RX interrupt
} else {
@ -143,24 +143,22 @@ uart_set_handler(unsigned mode, fp_uart_handler fpHandler)
int
uart_lock(unsigned mode)
{
if (uart_mode == mode) {
uart_lockcnt++;
return 1;
// already locked?
if(uart_mode != mode && uart_lockcnt > 0) {
return 0;
}
if (uart_lockcnt == 0) {
uart_set_mode(mode);
uart_lockcnt++;
return 1;
}
return 0;
// increase lock count
uart_lockcnt++;
// switch mode (if neccessary)
uart_set_mode(mode);
return 1;
}
/*---------------------------------------------------------------------------*/
int
uart_lock_wait(unsigned mode)
{
while (UART_WAIT_LOCK(mode)) {
while(UART_WAIT_LOCK(mode)) {
_NOP();
}
return uart_lock(mode);
@ -169,21 +167,29 @@ uart_lock_wait(unsigned mode)
int
uart_unlock(unsigned mode)
{
if (uart_lockcnt == 0 || mode != uart_mode) {
if((uart_lockcnt == 0) || (mode != uart_mode)) {
uart_lockcnt = 0;
uart_set_mode(UART_MODE_DEFAULT);
return 0;
}
if (--uart_lockcnt == 0) {
// decrement lock
if (uart_lockcnt > 0) {
uart_lockcnt--;
// if no more locks, switch back to default mode
if(uart_lockcnt == 0) {
uart_set_mode(UART_MODE_DEFAULT);
}
return 1;
}
return 1;
return 0;
}
/*---------------------------------------------------------------------------*/
void
uart_set_mode(unsigned mode)
{
// do nothing if mode already set
if (mode == uart_mode) {
if(mode == uart_mode) {
return;
}
@ -191,7 +197,7 @@ uart_set_mode(unsigned mode)
uart_configure(mode); // configure uart parameters
uart_mode = mode;
if (uart_handler[mode] != NULL) {
if(uart_handler[mode] != NULL) {
IE2 |= URXIE1; // Enable USART1 RX interrupt
}
}
@ -208,7 +214,7 @@ uart_rx(void)
fp_uart_handler handler = uart_handler[uart_mode];
int c;
if (!(IFG2 & URXIFG1)) {
if(!(IFG2 & URXIFG1)) {
// If start edge detected, toggle & return
uart_edge = 1;
U1TCTL &= ~URXSE;
@ -217,9 +223,9 @@ uart_rx(void)
return;
}
uart_edge = 0;
if (!(URCTL1 & RXERR)) {
if(!(URCTL1 & RXERR)) {
c = UART_RX;
if (handler(c)) {
if(handler(c)) {
_BIC_SR_IRQ(LPM3_bits);
}
} else {

View file

@ -52,10 +52,8 @@ Berlin, 2007
*/
/**
* @file ScatterWeb.Uart.h
* @author Michael Baar <baar@inf.fu-berlin.de>
*
* Header file for MSP430 UART driver.
* \file Header file for for the MSB430 UART driver.
* \author Michael Baar <baar@inf.fu-berlin.de>
*/
#ifndef MSB430_UART_H
@ -65,9 +63,9 @@ Berlin, 2007
#define UART_TX TXBUF1
#define UART_RESET_RX() do { U1IFG &= ~URXIFG1; } while(0)
#define UART_RESET_RXTX() do { U1IFG &= ~(URXIFG1 | UTXIFG1); } while(0)
#define UART_WAIT_RX() while( (U1IFG & URXIFG1) == 0 ) { _NOP(); }
#define UART_WAIT_TX() while( (U1IFG & UTXIFG1) == 0 ) { _NOP(); }
#define UART_WAIT_TXDONE() while( (UTCTL1 & TXEPT) == 0 ) { _NOP(); }
#define UART_WAIT_RX() while((U1IFG & URXIFG1) == 0) { _NOP(); }
#define UART_WAIT_TX() while((U1IFG & UTXIFG1) == 0) { _NOP(); }
#define UART_WAIT_TXDONE() while((UTCTL1 & TXEPT) == 0) { _NOP(); }
/**
* @brief Operating state

View file

@ -28,7 +28,7 @@
*
* This file is part of the Contiki operating system.
*
* @(#)$Id: rs232.c,v 1.6 2008/09/19 12:18:04 nvt-se Exp $
* @(#)$Id: rs232.c,v 1.7 2008/10/28 12:42:53 nvt-se Exp $
*/
/** \addtogroup esbrs232
@ -78,12 +78,11 @@ rs232_send(char c)
int
putchar(int c)
{
if (uart_lock(UART_MODE_RS232)) {
if(uart_get_mode() == UART_MODE_RS232) {
/* Loop until the transmission buffer is available. */
UART_WAIT_TX();
/* Transmit the data. */
UART_TX = c;
uart_unlock(UART_MODE_RS232);
return c;
} else {
return -1;
@ -95,7 +94,7 @@ rs232_set_speed(enum rs232_speed speed)
{
// baud
const unsigned char br_table[5][3] = {
{0x00, 0x01, 0x00}, // 9600
{0x00, 0x01, 0x00}, // 9600
{0x80, 0x00, 0x00}, // 19200
{0x40, 0x00, 0x00}, // 38400
{0x2a, 0x00, 0x5b}, // 57600
@ -109,9 +108,13 @@ rs232_set_speed(enum rs232_speed speed)
void
rs232_print(char *cptr)
{
while(*cptr != 0) {
rs232_send(*cptr);
++cptr;
// lock UART for print operation
if (uart_lock(UART_MODE_RS232)) {
while(*cptr != 0) {
rs232_send(*cptr);
++cptr;
}
uart_unlock(UART_MODE_RS232);
}
}
/*---------------------------------------------------------------------------*/

View file

@ -28,7 +28,7 @@
*
* This file is part of the Contiki operating system.
*
* @(#)$Id: rs232.h,v 1.3 2008/09/19 12:18:04 nvt-se Exp $
* @(#)$Id: rs232.h,v 1.4 2008/10/28 12:42:53 nvt-se Exp $
*/
/** \addtogroup esb
@ -50,11 +50,11 @@
#define __RS232_H__
enum rs232_speed {
RS232_9600 = 0,
RS232_19200 = 1,
RS232_38400 = 2,
RS232_57600 = 3,
RS232_115200 = 4
RS232_9600 = 0,
RS232_19200 = 1,
RS232_38400 = 2,
RS232_57600 = 3,
RS232_115200 = 4
};
/**