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 #define HAVE_STDINT_H
#include "msp430def.h" #include "msp430def.h"
#define WITH_SDC 1
#define ENERGEST_CONF_ON 1 #define ENERGEST_CONF_ON 1
#define IRQ_PORT1 0x01 #define IRQ_PORT1 0x01
#define IRQ_PORT2 0x02 #define IRQ_PORT2 0x02
#define IRQ_ADC 0x03 #define IRQ_ADC 0x03
// MSB430 SD Card driver
#define SD_CACHE 1
#define SD_READ_ANY 1
#define SD_WRITE 1
// MSP430 Infomemory // MSP430 Infomemory
#define INFOMEM_START 0x1000 #define INFOMEM_START 0x1000
#define INFOMEM_BLOCK_SIZE 128 #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_ON SD_LED_READ_ON
#define SD_LED_WRITE_OFF SD_LED_READ_OFF #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_WRITE SD_WRITE
#define SPI_DMA_READ 0 #define SPI_DMA_READ 0
#define SPI_DMA_WRITE 0 #define SPI_DMA_WRITE 0

View file

@ -143,19 +143,17 @@ uart_set_handler(unsigned mode, fp_uart_handler fpHandler)
int int
uart_lock(unsigned mode) uart_lock(unsigned mode)
{ {
if (uart_mode == mode) { // already locked?
uart_lockcnt++; if(uart_mode != mode && uart_lockcnt > 0) {
return 1;
}
if (uart_lockcnt == 0) {
uart_set_mode(mode);
uart_lockcnt++;
return 1;
}
return 0; return 0;
} }
// increase lock count
uart_lockcnt++;
// switch mode (if neccessary)
uart_set_mode(mode);
return 1;
}
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
int int
uart_lock_wait(unsigned mode) uart_lock_wait(unsigned mode)
@ -169,15 +167,23 @@ uart_lock_wait(unsigned mode)
int int
uart_unlock(unsigned mode) 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; 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); uart_set_mode(UART_MODE_DEFAULT);
} }
return 1; return 1;
} }
return 0;
}
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void
uart_set_mode(unsigned mode) uart_set_mode(unsigned mode)

View file

@ -52,10 +52,8 @@ Berlin, 2007
*/ */
/** /**
* @file ScatterWeb.Uart.h * \file Header file for for the MSB430 UART driver.
* @author Michael Baar <baar@inf.fu-berlin.de> * \author Michael Baar <baar@inf.fu-berlin.de>
*
* Header file for MSP430 UART driver.
*/ */
#ifndef MSB430_UART_H #ifndef MSB430_UART_H

View file

@ -28,7 +28,7 @@
* *
* This file is part of the Contiki operating system. * 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 /** \addtogroup esbrs232
@ -78,12 +78,11 @@ rs232_send(char c)
int int
putchar(int c) putchar(int c)
{ {
if (uart_lock(UART_MODE_RS232)) { if(uart_get_mode() == UART_MODE_RS232) {
/* Loop until the transmission buffer is available. */ /* Loop until the transmission buffer is available. */
UART_WAIT_TX(); UART_WAIT_TX();
/* Transmit the data. */ /* Transmit the data. */
UART_TX = c; UART_TX = c;
uart_unlock(UART_MODE_RS232);
return c; return c;
} else { } else {
return -1; return -1;
@ -109,10 +108,14 @@ rs232_set_speed(enum rs232_speed speed)
void void
rs232_print(char *cptr) rs232_print(char *cptr)
{ {
// lock UART for print operation
if (uart_lock(UART_MODE_RS232)) {
while(*cptr != 0) { while(*cptr != 0) {
rs232_send(*cptr); rs232_send(*cptr);
++cptr; ++cptr;
} }
uart_unlock(UART_MODE_RS232);
}
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void

View file

@ -28,7 +28,7 @@
* *
* This file is part of the Contiki operating system. * 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 /** \addtogroup esb