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

@ -4,17 +4,14 @@
#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
// 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
@ -88,6 +85,14 @@ typedef int bool;
#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

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;
}
if (uart_lockcnt == 0) {
uart_set_mode(mode);
uart_lockcnt++;
return 1;
}
// already locked?
if(uart_mode != mode && uart_lockcnt > 0) {
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 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;
@ -109,10 +108,14 @@ rs232_set_speed(enum rs232_speed speed)
void
rs232_print(char *cptr)
{
// lock UART for print operation
if (uart_lock(UART_MODE_RS232)) {
while(*cptr != 0) {
rs232_send(*cptr);
++cptr;
}
uart_unlock(UART_MODE_RS232);
}
}
/*---------------------------------------------------------------------------*/
void

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