boards/wsn430-xxx: now using periph UART driver
This commit is contained in:
parent
bb204add17
commit
2bd250e912
@ -13,6 +13,7 @@
|
||||
#include "kernel_internal.h"
|
||||
#include "msp430.h"
|
||||
#include "debug.h"
|
||||
#include "msp430_stdio.h"
|
||||
|
||||
volatile static uint32_t __msp430_cpu_speed = MSP430_INITIAL_CPU_SPEED;
|
||||
|
||||
@ -25,30 +26,6 @@ typedef enum {
|
||||
MCLK_8MHZ_SCLK_8MHZ = 8000000uL
|
||||
}speed_t;
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static uint8_t calc_umctl(uint16_t br) {
|
||||
// from TI slaa049
|
||||
register uint8_t CMOD = 256 * br - 256 * (br + 1) / 2;
|
||||
register uint8_t c = 0;
|
||||
register int i = 0;
|
||||
register uint8_t a = CMOD;
|
||||
a <<= 1;
|
||||
do {
|
||||
if( a & 0x80 ) { // Overflow to integer?
|
||||
a = a - 128 + CMOD; // Yes, subtract 1.000000
|
||||
c |= 0x80;
|
||||
}
|
||||
else {
|
||||
a += CMOD; // No, add fraction
|
||||
}
|
||||
if( i == 7 ) {
|
||||
return c;
|
||||
}
|
||||
i++;
|
||||
c >>= 1;
|
||||
} while(1);
|
||||
}
|
||||
|
||||
static void msb_ports_init(void)
|
||||
{
|
||||
// Port 1: GDO, Flash, BSL TX
|
||||
@ -90,24 +67,6 @@ void msp430_set_cpu_speed(uint32_t speed)
|
||||
disableIRQ();
|
||||
__msp430_cpu_speed = speed;
|
||||
msp430_init_dco();
|
||||
uint16_t br;
|
||||
|
||||
U0CTL = SWRST;
|
||||
U0CTL = SWRST | CHAR; // 8-bit character
|
||||
U0TCTL = SSEL1 | TXEPT; // UCLK = SCLK
|
||||
U0RCTL = 0;
|
||||
// activate
|
||||
ME1 |= UTXE0 + URXE0; // Enable USART0 TXD/RXD
|
||||
br = (uint16_t)((__msp430_cpu_speed & 0xFFFFF0) / 115200uL);
|
||||
UBR00 = br; // set baudrate
|
||||
UBR10 = br>>8;
|
||||
UMCTL0 = calc_umctl(br); // set modulation
|
||||
|
||||
U0CTL &= ~SWRST;
|
||||
|
||||
//URCTL0 |= URXEIE; // allow chars to interrupt
|
||||
IE1 |= URXIE0; // enable rx interrupt
|
||||
IFG1 &= ~UTXIFG0;
|
||||
enableIRQ();
|
||||
}
|
||||
|
||||
@ -152,4 +111,7 @@ void board_init(void)
|
||||
LED_RED_ON;
|
||||
|
||||
msp430_set_cpu_speed(MCLK_8MHZ_SCLK_8MHZ);
|
||||
|
||||
/* initialize the STDIO */
|
||||
msp430_stdio_init();
|
||||
}
|
||||
|
||||
@ -25,6 +25,16 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Clock configuration
|
||||
*
|
||||
* @todo Move all clock configuration code here from the board.h
|
||||
*/
|
||||
#define CLOCK_CORECLOCK (8000000U)
|
||||
|
||||
#define CLOCK_CMCLK CLOCK_CORECLOCK /* no divider programmed */
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @brief Timer configuration
|
||||
* @{
|
||||
@ -35,6 +45,27 @@ extern "C" {
|
||||
#define TIMER_ISR_CCX (TIMERA1_VECTOR)
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @brief UART configuration
|
||||
* @{
|
||||
*/
|
||||
#define UART_NUMOF (1U)
|
||||
#define UART_0_EN (1U)
|
||||
|
||||
#define UART_DEV (USART_0)
|
||||
#define UART_IE (SFR->IE1)
|
||||
#define UART_IF (SFR->IFG1)
|
||||
#define UART_IE_RX_BIT (1 << 6)
|
||||
#define UART_IE_TX_BIT (1 << 7)
|
||||
#define UART_ME (SFR->ME1)
|
||||
#define UART_ME_BITS (0xc0)
|
||||
#define UART_PORT (PORT_3)
|
||||
#define UART_RX_PIN (1 << 4)
|
||||
#define UART_TX_PIN (1 << 5)
|
||||
#define UART_RX_ISR (USART1RX_VECTOR)
|
||||
#define UART_TX_ISR (USART1TX_VECTOR)
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -1,73 +0,0 @@
|
||||
/*
|
||||
* uart0.c - Implementation of the uart.
|
||||
* Copyright (C) 2013 Milan Babel <babel@inf.fu-berlin.de>
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "board.h"
|
||||
|
||||
#define UART0_TX U0TXBUF
|
||||
#define UART0_WAIT_TXDONE() while( (U0TCTL & TXEPT) == 0 ) { _NOP(); }
|
||||
|
||||
#include "kernel.h"
|
||||
|
||||
#include "board_uart0.h"
|
||||
|
||||
int putchar(int c)
|
||||
{
|
||||
UART0_TX = c;
|
||||
UART0_WAIT_TXDONE();
|
||||
|
||||
if (c == 10) {
|
||||
UART0_TX = 13;
|
||||
UART0_WAIT_TXDONE();
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
int getchar(void)
|
||||
{
|
||||
#ifdef MODULE_UART0
|
||||
return uart0_readc();
|
||||
#else
|
||||
return U0RXBUF;
|
||||
#endif
|
||||
}
|
||||
|
||||
void usart0irq(void);
|
||||
/**
|
||||
* \brief the interrupt function
|
||||
*/
|
||||
void __attribute__((interrupt(USART0RX_VECTOR))) usart0irq(void) {
|
||||
volatile int dummy = 0;
|
||||
/* Check status register for receive errors. */
|
||||
if(U0RCTL & RXERR) {
|
||||
if (U0RCTL & FE) {
|
||||
puts("rx framing error");
|
||||
}
|
||||
if (U0RCTL & OE) {
|
||||
puts("rx overrun error");
|
||||
}
|
||||
if (U0RCTL & PE) {
|
||||
puts("rx parity error");
|
||||
}
|
||||
if (U0RCTL & BRK) {
|
||||
puts("rx break error");
|
||||
}
|
||||
/* Clear error flags by forcing a dummy read. */
|
||||
dummy = U0RXBUF;
|
||||
(void)dummy;
|
||||
}
|
||||
#ifdef MODULE_UART0
|
||||
else if (uart0_handler_pid != KERNEL_PID_UNDEF) {
|
||||
dummy = U0RXBUF;
|
||||
uart0_handle_incoming(dummy);
|
||||
uart0_notify_thread();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@ -54,6 +54,15 @@ extern "C" {
|
||||
*/
|
||||
#define HW_TIMER (0)
|
||||
|
||||
/**
|
||||
* @brief Standard input/output device configuration
|
||||
* @{
|
||||
*/
|
||||
#define STDIO (0)
|
||||
#define STDIO_BAUDRATE (115200U)
|
||||
#define STDIO_RX_BUFSIZE (64U)
|
||||
/** @} */
|
||||
|
||||
//MSB430 core
|
||||
#define MSP430_INITIAL_CPU_SPEED 800000uL
|
||||
#define F_CPU MSP430_INITIAL_CPU_SPEED
|
||||
|
||||
@ -34,6 +34,11 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* for correct inclusion of <msp430.h> */
|
||||
#ifndef __MSP430F1611__
|
||||
#define __MSP430F1611__
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Xtimer configuration
|
||||
* @{
|
||||
@ -49,10 +54,14 @@ extern "C" {
|
||||
*/
|
||||
#define HW_TIMER (0)
|
||||
|
||||
/* for correct inclusion of <msp430.h> */
|
||||
#ifndef __MSP430F1611__
|
||||
#define __MSP430F1611__
|
||||
#endif
|
||||
/**
|
||||
* @brief Standard input/output device configuration
|
||||
* @{
|
||||
*/
|
||||
#define STDIO (0)
|
||||
#define STDIO_BAUDRATE (115200U)
|
||||
#define STDIO_RX_BUFSIZE (64U)
|
||||
/** @} */
|
||||
|
||||
/* MSB430 core */
|
||||
#define MSP430_INITIAL_CPU_SPEED 800000uL
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user