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

@ -143,19 +143,17 @@ 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)
@ -169,15 +167,23 @@ 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)

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

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