Cleanup and refactoring of the STM32w port
This is a general cleanup of things like code style issues and code structure of the STM32w port to make it more like the rest of Contiki is structured.
This commit is contained in:
parent
12b3d02ba1
commit
a5046e83c7
118 changed files with 4470 additions and 4281 deletions
|
@ -1,3 +1,9 @@
|
|||
/**
|
||||
* \addtogroup stm32w-cpu
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010, STMicroelectronics.
|
||||
* All rights reserved.
|
||||
|
@ -27,10 +33,9 @@
|
|||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki OS
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Machine dependent STM32W UART1 code.
|
||||
|
@ -41,53 +46,42 @@
|
|||
* \since
|
||||
* 03.04.2010
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
//#include <io.h>
|
||||
//#include <signal.h>
|
||||
|
||||
#include "sys/energest.h"
|
||||
#include "dev/uart1.h"
|
||||
#include "dev/watchdog.h"
|
||||
|
||||
#include "lib/ringbuf.h"
|
||||
|
||||
#include "dev/leds.h"
|
||||
|
||||
static int (*uart1_input_handler)(unsigned char c);
|
||||
static int (*uart1_input_handler) (unsigned char c);
|
||||
|
||||
void uart1_rx_interrupt(void);
|
||||
|
||||
void uart1_tx_interrupt(void);
|
||||
|
||||
static volatile uint8_t transmitting;
|
||||
|
||||
#ifdef UART1_CONF_TX_WITH_INTERRUPT
|
||||
#define TX_WITH_INTERRUPT UART1_CONF_TX_WITH_INTERRUPT
|
||||
#else /* UART1_CONF_TX_WITH_INTERRUPT */
|
||||
#define TX_WITH_INTERRUPT 1
|
||||
#define TX_WITH_INTERRUPT 1
|
||||
#endif /* UART1_CONF_TX_WITH_INTERRUPT */
|
||||
|
||||
|
||||
#if TX_WITH_INTERRUPT
|
||||
|
||||
#ifdef UART1_CONF_TX_BUFSIZE
|
||||
#define UART1_TX_BUFSIZE UART1_CONF_TX_BUFSIZE
|
||||
#else /* UART1_CONF_TX_BUFSIZE */
|
||||
#define UART1_TX_BUFSIZE 64
|
||||
#endif /* UART1_CONF_TX_BUFSIZE */
|
||||
|
||||
static struct ringbuf txbuf;
|
||||
static uint8_t txbuf_data[UART1_TX_BUFSIZE];
|
||||
#endif /* TX_WITH_INTERRUPT */
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
//uint8_t
|
||||
//uart1_active(void)
|
||||
//{
|
||||
// return ((~ UTCTL1) & TXEPT) | transmitting;
|
||||
//}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
uart1_set_input(int (*input)(unsigned char c))
|
||||
uart1_set_input(int (*input) (unsigned char c))
|
||||
{
|
||||
uart1_input_handler = input;
|
||||
}
|
||||
|
@ -97,21 +91,23 @@ uart1_writeb(unsigned char c)
|
|||
{
|
||||
watchdog_periodic();
|
||||
#if TX_WITH_INTERRUPT
|
||||
|
||||
/* Put the outgoing byte on the transmission buffer. If the buffer
|
||||
is full, we just keep on trying to put the byte into the buffer
|
||||
until it is possible to put it there. */
|
||||
/*
|
||||
* Put the outgoing byte on the transmission buffer. If the buffer
|
||||
* is full, we just keep on trying to put the byte into the buffer
|
||||
* until it is possible to put it there.
|
||||
*/
|
||||
while(ringbuf_put(&txbuf, c) == 0);
|
||||
|
||||
/* If there is no transmission going, we need to start it by putting
|
||||
the first byte into the UART. */
|
||||
/*
|
||||
* If there is no transmission going, we need to start it by putting
|
||||
* the first byte into the UART.
|
||||
*/
|
||||
if(transmitting == 0) {
|
||||
transmitting = 1;
|
||||
transmitting = 1;
|
||||
SC1_DATA = ringbuf_get(&txbuf);
|
||||
INT_SC1FLAG = INT_SCTXFREE;
|
||||
INT_SC1CFG |= INT_SCTXFREE;
|
||||
}
|
||||
|
||||
#else /* TX_WITH_INTERRUPT */
|
||||
|
||||
/* Loop until the transmission buffer is available. */
|
||||
|
@ -119,107 +115,97 @@ uart1_writeb(unsigned char c)
|
|||
|
||||
/* Transmit the data. */
|
||||
SC1_DATA = c;
|
||||
|
||||
|
||||
INT_SC1FLAG = INT_SCTXFREE;
|
||||
#endif /* TX_WITH_INTERRUPT */
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#if ! WITH_UIP /* If WITH_UIP is defined, putchar() is defined by the SLIP driver */
|
||||
#if ! WITH_UIP
|
||||
/* If WITH_UIP is defined, putchar() is defined by the SLIP driver */
|
||||
#endif /* ! WITH_UIP */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
/*
|
||||
* Initalize the RS232 port.
|
||||
*
|
||||
*/
|
||||
void
|
||||
uart1_init(unsigned long ubr)
|
||||
{
|
||||
|
||||
GPIO_PBCFGL &= 0xF00F;
|
||||
GPIO_PBCFGL |= 0x0490;
|
||||
|
||||
uint16_t uartper = (uint32_t)24e6/(2*ubr);
|
||||
uint32_t rest = (uint32_t)24e6%(2*ubr);
|
||||
|
||||
SC1_UARTFRAC = 0;
|
||||
|
||||
if(rest > (2*ubr)/4 && rest < (3*2*ubr)/4){
|
||||
SC1_UARTFRAC = 1; // + 0.5
|
||||
}
|
||||
else if(rest >= (3*2*ubr)/4){
|
||||
uartper++; // + 1
|
||||
}
|
||||
|
||||
SC1_UARTPER = uartper;
|
||||
|
||||
SC1_UARTCFG = SC_UART8BIT;
|
||||
|
||||
SC1_MODE = SC1_MODE_UART;
|
||||
|
||||
SC1_INTMODE = SC_RXVALLEVEL | SC_TXFREELEVEL; // Receive buffer has data interrupt mode and Transmit buffer free interrupt mode: Level triggered.
|
||||
|
||||
INT_SC1CFG = INT_SCRXVAL; // Receive buffer has data interrupt enable
|
||||
uint16_t uartper;
|
||||
|
||||
uint32_t rest;
|
||||
|
||||
GPIO_PBCFGL &= 0xF00F;
|
||||
GPIO_PBCFGL |= 0x0490;
|
||||
|
||||
uartper = (uint32_t) 24e6 / (2 * ubr);
|
||||
rest = (uint32_t) 24e6 % (2 * ubr);
|
||||
|
||||
SC1_UARTFRAC = 0;
|
||||
if(rest > (2 * ubr) / 4 && rest < (3 * 2 * ubr) / 4) {
|
||||
SC1_UARTFRAC = 1; /* + 0.5 */
|
||||
} else if(rest >= (3 * 2 * ubr) / 4) {
|
||||
uartper++; /* + 1 */
|
||||
}
|
||||
|
||||
SC1_UARTPER = uartper;
|
||||
SC1_UARTCFG = SC_UART8BIT;
|
||||
SC1_MODE = SC1_MODE_UART;
|
||||
/*
|
||||
* Receive buffer has data interrupt mode and Transmit buffer free interrupt
|
||||
* mode: Level triggered.
|
||||
*/
|
||||
SC1_INTMODE = SC_RXVALLEVEL | SC_TXFREELEVEL;
|
||||
INT_SC1CFG = INT_SCRXVAL; /* Receive buffer has data interrupt enable */
|
||||
transmitting = 0;
|
||||
|
||||
|
||||
#if TX_WITH_INTERRUPT
|
||||
ringbuf_init(&txbuf, txbuf_data, sizeof(txbuf_data));
|
||||
#endif /* TX_WITH_INTERRUPT */
|
||||
|
||||
|
||||
ringbuf_init(&txbuf, txbuf_data, sizeof(txbuf_data));
|
||||
#endif /* TX_WITH_INTERRUPT */
|
||||
|
||||
INT_SC1FLAG = 0xFFFF;
|
||||
|
||||
INT_CFGSET = INT_SC1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void uart1_rx_interrupt(void);
|
||||
void uart1_tx_interrupt(void);
|
||||
|
||||
void halSc1Isr(void)
|
||||
void
|
||||
halSc1Isr(void)
|
||||
{
|
||||
|
||||
ENERGEST_ON(ENERGEST_TYPE_IRQ);
|
||||
|
||||
if(INT_SC1FLAG & INT_SCRXVAL){
|
||||
|
||||
if(INT_SC1FLAG & INT_SCRXVAL) {
|
||||
uart1_rx_interrupt();
|
||||
INT_SC1FLAG = INT_SCRXVAL;
|
||||
INT_SC1FLAG = INT_SCRXVAL;
|
||||
}
|
||||
#if TX_WITH_INTERRUPT
|
||||
else if(INT_SC1FLAG & INT_SCTXFREE){
|
||||
#if TX_WITH_INTERRUPT
|
||||
else if(INT_SC1FLAG & INT_SCTXFREE) {
|
||||
uart1_tx_interrupt();
|
||||
INT_SC1FLAG = INT_SCTXFREE;
|
||||
}
|
||||
#endif /* TX_WITH_INTERRUPT */
|
||||
|
||||
}
|
||||
#endif /* TX_WITH_INTERRUPT */
|
||||
|
||||
|
||||
ENERGEST_OFF(ENERGEST_TYPE_IRQ);
|
||||
|
||||
}
|
||||
|
||||
void uart1_rx_interrupt(void)
|
||||
/*--------------------------------------------------------------------------*/
|
||||
void
|
||||
uart1_rx_interrupt(void)
|
||||
{
|
||||
uint8_t c;
|
||||
|
||||
uint8_t c;
|
||||
|
||||
c = SC1_DATA;
|
||||
|
||||
if(uart1_input_handler != NULL) {
|
||||
uart1_input_handler(c);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#if TX_WITH_INTERRUPT
|
||||
void uart1_tx_interrupt(void)
|
||||
void
|
||||
uart1_tx_interrupt(void)
|
||||
{
|
||||
|
||||
if(ringbuf_elements(&txbuf) == 0) {
|
||||
transmitting = 0;
|
||||
INT_SC1CFG &= ~INT_SCTXFREE;
|
||||
} else {
|
||||
SC1_DATA = ringbuf_get(&txbuf);
|
||||
}
|
||||
|
||||
}
|
||||
#endif /* TX_WITH_INTERRUPT */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @} */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue