pic32 minor cleanups

This commit is contained in:
Giovanni evilaliv3 Pellerano 2013-05-17 14:32:39 +02:00
parent 5af6540980
commit c33d51e762
9 changed files with 125 additions and 66 deletions

View file

@ -99,13 +99,13 @@
void pic32_timer##XY##_stop(void); \
uint32_t pic32_timer##XY##_get_val(void);
#define TIMER_INTERRUPT(XX, CALLBACK) \
TIMER_ISR(_TIMER_##XX##_VECTOR) \
{ \
ENERGEST_ON(ENERGEST_TYPE_IRQ); \
CALLBACK(); \
ENERGEST_OFF(ENERGEST_TYPE_IRQ); \
IFS0CLR = _IFS0_T##XX##IF_MASK; \
#define TIMER_INTERRUPT(XX, CALLBACK) \
TIMER_ISR(_TIMER_##XX##_VECTOR) \
{ \
ENERGEST_ON(ENERGEST_TYPE_IRQ); \
CALLBACK(); \
ENERGEST_OFF(ENERGEST_TYPE_IRQ); \
IFS0CLR = _IFS0_T##XX##IF_MASK; \
}
#ifdef __USE_TIMER_1__

View file

@ -76,7 +76,8 @@
#include <p32xxxx.h>
#include "contiki.h"
#include "lib/ringbuf.h"
#include "dev/leds.h"
/*---------------------------------------------------------------------------*/
#define UART_PORT_INIT_XA(XX, YY, ZZ) \
@ -84,7 +85,7 @@
pic32_uart##XX##A_init(uint32_t baudrate, uint16_t byte_format) \
{ \
/* Disable Interrupts: RX, TX, ERR */ \
IEC##ZZ##CLR = _IEC##ZZ##_U##XX##ARXIE_MASK; \
IEC##ZZ##CLR = _IEC##ZZ##_U##XX##AEIE_MASK | _IEC##ZZ##_U##XX##ATXIE_MASK | _IEC##ZZ##_U##XX##ARXIE_MASK; \
IFS##ZZ##CLR = _IFS##ZZ##_U##XX##AEIF_MASK | _IFS##ZZ##_U##XX##ATXIF_MASK | _IFS##ZZ##_U##XX##ARXIF_MASK; \
\
/* Clear thant Set Pri and Sub priority */ \
@ -101,8 +102,8 @@
U##XX##AMODESET = byte_format & 0x07; /* Number of bit, Parity and Stop bits */ \
\
/* Status bits */ \
U##XX##ASTA = 0; /* TX & RX interrupt modes */ \
U##XX##ASTASET = _U##XX##ASTA_UTXEN_MASK | _U##XX##ASTA_URXEN_MASK; /* Enable TX, RX */ \
U##XX##ASTA = 0; \
U##XX##ASTASET = _U##XX##ASTA_URXEN_MASK | _U##XX##ASTA_UTXEN_MASK; /* Enable RX and TX */ \
\
IEC##ZZ##SET = _IEC##ZZ##_U##XX##ARXIE_MASK; \
\
@ -117,7 +118,7 @@
pic32_uart##XX##B_init(uint32_t baudrate, uint16_t byte_format) \
{ \
/* Disable Interrupts: RX, TX, ERR */ \
IEC##ZZ##CLR = _IEC##ZZ##_U##XX##BRXIE_MASK; \
IEC##ZZ##CLR = _IEC##ZZ##_U##XX##BEIE_MASK | _IEC##ZZ##_U##XX##BTXIE_MASK | _IEC##ZZ##_U##XX##BRXIE_MASK; \
IFS##ZZ##CLR = _IFS##ZZ##_U##XX##BEIF_MASK | _IFS##ZZ##_U##XX##BTXIF_MASK | _IFS##ZZ##_U##XX##BRXIF_MASK; \
\
/* Clear thant Set Pri and Sub priority */ \
@ -134,8 +135,8 @@
U##XX##BMODESET = byte_format & 0x07; /* Number of bit, Parity and Stop bits */ \
\
/* Status bits */ \
U##XX##BSTA = 0; /* TX & RX interrupt modes */ \
U##XX##BSTASET = _U##XX##BSTA_UTXEN_MASK | _U##XX##BSTA_URXEN_MASK; /* Enable TX, RX */ \
U##XX##BSTA = 0; \
U##XX##BSTASET = _U##XX##BSTA_URXEN_MASK | _U##XX##BSTA_UTXEN_MASK; /* Enable RX and TX */ \
\
IEC##ZZ##SET = _IEC##ZZ##_U##XX##BRXIE_MASK; \
\
@ -150,9 +151,13 @@
int8_t \
pic32_uart##XX##_write(uint8_t data) \
{ \
while(U##XX##STAbits.UTXBF); \
volatile uint8_t wait; \
\
do { \
wait = U##XX##STAbits.UTXBF; \
} while(wait); \
\
U##XX##TXREG = data; \
while(!U##XX##STAbits.TRMT); \
\
return UART_NO_ERROR; \
}

View file

@ -66,6 +66,8 @@
#include <stdint.h>
#include "dev/leds.h"
#define BAUD2UBR(x) x
/* Returned Messages */
@ -77,21 +79,21 @@
int8_t pic32_uart##XX##_init(uint32_t baudrate, uint16_t byte_format); \
int8_t pic32_uart##XX##_write(uint8_t data);
#define UART_INTERRUPT(XX, Y, CALLBACK) \
ISR(_UART_##XX##_VECTOR) \
{ \
volatile uint8_t byte; \
if(IFS##Y##bits.U##XX##RXIF) { \
if((U##XX##STAbits.PERR == 0) && (U##XX##STAbits.FERR == 0)) { \
CALLBACK(U##XX##RXREG); \
} else { \
byte = U##XX##RXREG; /* NULL READ */ \
} \
IFS##Y##CLR = _IFS##Y##_U##XX##RXIF_MASK; \
} \
if(U##XX##STAbits.OERR) { \
U##XX##STACLR = _U##XX##STA_OERR_MASK; \
} \
#define UART_INTERRUPT(XX, YY, CALLBACK) \
ISR(_UART_##XX##_VECTOR) \
{ \
volatile uint8_t byte; \
if(IFS##YY##bits.U##XX##RXIF) { \
if((U##XX##STAbits.PERR == 0) && (U##XX##STAbits.FERR == 0)) { \
CALLBACK(U##XX##RXREG); \
} else { \
byte = U##XX##RXREG; /* NULL READ */ \
} \
IFS##YY##CLR = _IFS##YY##_U##XX##RXIF_MASK; \
} \
if(U##XX##STAbits.OERR) { \
U##XX##STACLR = _U##XX##STA_OERR_MASK; \
} \
}
#ifdef __USE_UART_PORT1A__