boards/msb-430h: switched to periph/uart driver
This commit is contained in:
parent
ed71388532
commit
daa716aaf8
@ -23,6 +23,8 @@
|
|||||||
#include "cpu.h"
|
#include "cpu.h"
|
||||||
#include "irq.h"
|
#include "irq.h"
|
||||||
#include "board.h"
|
#include "board.h"
|
||||||
|
#include "msp430_stdio.h"
|
||||||
|
#include "periph_conf.h"
|
||||||
#include "kernel_internal.h"
|
#include "kernel_internal.h"
|
||||||
#include "msp430.h"
|
#include "msp430.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
@ -31,35 +33,6 @@ static volatile uint32_t __msp430_cpu_speed = MSP430_INITIAL_CPU_SPEED;
|
|||||||
|
|
||||||
void msp430_init_dco(void);
|
void msp430_init_dco(void);
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
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)
|
static void msb_ports_init(void)
|
||||||
{
|
{
|
||||||
/* Port 1: Free port, for energy saving all outputs are set to zero. */
|
/* Port 1: Free port, for energy saving all outputs are set to zero. */
|
||||||
@ -79,9 +52,9 @@ static void msb_ports_init(void)
|
|||||||
/* 0 - P2.6 [IN ] - SDC Protect */
|
/* 0 - P2.6 [IN ] - SDC Protect */
|
||||||
/* 0 - P2.7 [IN ] - SDC Detect */
|
/* 0 - P2.7 [IN ] - SDC Detect */
|
||||||
|
|
||||||
P3SEL = 0xC0; /* Port3 Pins 6 & 7 for USART */
|
P3SEL = 0x00; /* Port3 Pins 6 & 7 for USART */
|
||||||
P3OUT = 0x49; /* Port3 Output register: 01001001: 0x49 */
|
P3OUT = 0x00; /* Port3 Output register: 01001001: 0x49 */
|
||||||
P3DIR = 0xAB; /* Port3 Direction: 10101011: 0xAB */
|
P3DIR = 0xFF; /* Port3 Direction: 10101011: 0xAB */
|
||||||
/* 1 - P3.0 */
|
/* 1 - P3.0 */
|
||||||
/* 1 - P3.1 */
|
/* 1 - P3.1 */
|
||||||
/* 0 - P3.2 */
|
/* 0 - P3.2 */
|
||||||
@ -134,21 +107,6 @@ void msp430_set_cpu_speed(uint32_t speed)
|
|||||||
disableIRQ();
|
disableIRQ();
|
||||||
__msp430_cpu_speed = speed;
|
__msp430_cpu_speed = speed;
|
||||||
msp430_init_dco();
|
msp430_init_dco();
|
||||||
uint16_t br;
|
|
||||||
UCTL1 = SWRST | CHAR; /* 8-bit character */
|
|
||||||
UTCTL1 |= SSEL1 | URXSE; /* UCLK = MCLK */
|
|
||||||
/* activate */
|
|
||||||
U1ME |= UTXE1 | URXE1; /* Enable USART1 TXD/RXD */
|
|
||||||
br = (uint16_t)(__msp430_cpu_speed / 115200uL);
|
|
||||||
UBR01 = br; /* set baudrate */
|
|
||||||
UBR11 = br >> 8;
|
|
||||||
UMCTL1 = calc_umctl(br); /* set modulation */
|
|
||||||
|
|
||||||
ME2 |= (UTXE1 | URXE1);
|
|
||||||
UCTL1 &= ~SWRST;
|
|
||||||
|
|
||||||
IE2 |= URXIE1;
|
|
||||||
//clock_init();
|
|
||||||
enableIRQ();
|
enableIRQ();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -244,5 +202,8 @@ void board_init(void)
|
|||||||
|
|
||||||
LED_RED_ON;
|
LED_RED_ON;
|
||||||
|
|
||||||
msp430_set_cpu_speed(7372800uL);
|
msp430_set_cpu_speed(CLOCK_CORECLOCK);
|
||||||
|
|
||||||
|
/* finally initialize the STDIO */
|
||||||
|
msp430_stdio_init();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,85 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2014 INRIA
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ingroup boards
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @file
|
|
||||||
* @brief msb-430 common putchar implementation
|
|
||||||
*
|
|
||||||
* @author Oliver Hahm <oliver.hahm@inria.fr>
|
|
||||||
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include "board.h"
|
|
||||||
#include "kernel.h"
|
|
||||||
|
|
||||||
#include "board_uart0.h"
|
|
||||||
|
|
||||||
#define UART1_TX TXBUF1
|
|
||||||
#define UART1_WAIT_TXDONE() while( (UTCTL1 & TXEPT) == 0 ) { _NOP(); }
|
|
||||||
|
|
||||||
int getchar(void)
|
|
||||||
{
|
|
||||||
#ifdef MODULE_UART0
|
|
||||||
return uart0_readc();
|
|
||||||
#else
|
|
||||||
return U1RXBUF;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
int putchar(int c)
|
|
||||||
{
|
|
||||||
UART1_TX = c;
|
|
||||||
UART1_WAIT_TXDONE();
|
|
||||||
|
|
||||||
if (c == 10) {
|
|
||||||
UART1_WAIT_TXDONE();
|
|
||||||
}
|
|
||||||
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
|
|
||||||
void usart0irq(void);
|
|
||||||
/**
|
|
||||||
* \brief the interrupt function
|
|
||||||
*/
|
|
||||||
void __attribute__((interrupt(USART1RX_VECTOR))) usart0irq(void)
|
|
||||||
{
|
|
||||||
U1TCTL &= ~URXSE; /* Clear the URXS signal */
|
|
||||||
U1TCTL |= URXSE; /* Re-enable URXS - needed here?*/
|
|
||||||
/* Check status register for receive errors. */
|
|
||||||
if(U1RCTL & RXERR) {
|
|
||||||
if (U1RCTL & FE) {
|
|
||||||
puts("rx framing error");
|
|
||||||
}
|
|
||||||
if (U1RCTL & OE) {
|
|
||||||
puts("rx overrun error");
|
|
||||||
}
|
|
||||||
if (U1RCTL & PE) {
|
|
||||||
puts("rx parity error");
|
|
||||||
}
|
|
||||||
if (U1RCTL & BRK) {
|
|
||||||
puts("rx break error");
|
|
||||||
}
|
|
||||||
/* Clear error flags by forcing a dummy read. */
|
|
||||||
volatile int c = U1RXBUF;
|
|
||||||
(void) c;
|
|
||||||
}
|
|
||||||
#ifdef MODULE_UART0
|
|
||||||
else if (uart0_handler_pid != KERNEL_PID_UNDEF) {
|
|
||||||
volatile int c = U1RXBUF;
|
|
||||||
uart0_handle_incoming(c);
|
|
||||||
uart0_notify_thread();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
@ -46,6 +46,15 @@ extern "C" {
|
|||||||
*/
|
*/
|
||||||
#define HW_TIMER (0)
|
#define HW_TIMER (0)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Standard input/output device configuration
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define STDIO (0)
|
||||||
|
#define STDIO_BAUDRATE (115200U)
|
||||||
|
#define STDIO_RX_BUFSIZE (64U)
|
||||||
|
/** @} */
|
||||||
|
|
||||||
//MSB430 core
|
//MSB430 core
|
||||||
#define MSP430_INITIAL_CPU_SPEED 7372800uL
|
#define MSP430_INITIAL_CPU_SPEED 7372800uL
|
||||||
#define F_CPU MSP430_INITIAL_CPU_SPEED
|
#define F_CPU MSP430_INITIAL_CPU_SPEED
|
||||||
|
|||||||
@ -25,6 +25,16 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Clock configuration
|
||||||
|
*
|
||||||
|
* @todo Move all clock configuration code here from the board.h
|
||||||
|
*/
|
||||||
|
#define CLOCK_CORECLOCK (7372800U)
|
||||||
|
|
||||||
|
#define CLOCK_CMCLK CLOCK_CORECLOCK /* no divider programmed */
|
||||||
|
/** @} */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Timer configuration
|
* @brief Timer configuration
|
||||||
* @{
|
* @{
|
||||||
@ -35,6 +45,27 @@ extern "C" {
|
|||||||
#define TIMER_ISR_CCX (TIMERA1_VECTOR)
|
#define TIMER_ISR_CCX (TIMERA1_VECTOR)
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief UART configuration
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define UART_NUMOF (1U)
|
||||||
|
#define UART_0_EN (1U)
|
||||||
|
|
||||||
|
#define UART_DEV (USART_1)
|
||||||
|
#define UART_IE (SFR->IE2)
|
||||||
|
#define UART_IF (SFR->IFG2)
|
||||||
|
#define UART_IE_RX_BIT (1 << 4)
|
||||||
|
#define UART_IE_TX_BIT (1 << 5)
|
||||||
|
#define UART_ME (SFR->ME2)
|
||||||
|
#define UART_ME_BITS (0x30)
|
||||||
|
#define UART_PORT (PORT_3)
|
||||||
|
#define UART_RX_PIN (1 << 6)
|
||||||
|
#define UART_TX_PIN (1 << 7)
|
||||||
|
#define UART_RX_ISR (USART1RX_VECTOR)
|
||||||
|
#define UART_TX_ISR (USART1TX_VECTOR)
|
||||||
|
/** @} */
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user