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

@ -98,15 +98,29 @@ clock_set_seconds(unsigned long sec)
seconds = sec; seconds = sec;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void #define CLOCK_INIT(XX) \
clock_init(void) void \
{ clock_init(void) \
ticks = 0; { \
seconds = 0; ticks = 0; \
pic32_timer1_init(CLOCK_SECOND); seconds = 0; \
pic32_timer1_enable_irq(); pic32_timer##XX##_init(CLOCK_SECOND);\
pic32_timer1_start(); pic32_timer##XX##_enable_irq(); \
pic32_timer##XX##_start(); \
} }
#if PIC32_TIMER_CLOCK == 1
CLOCK_INIT(1)
#elif PIC32_TIMER_CLOCK == 2
CLOCK_INIT(2)
#elif PIC32_TIMER_CLOCK == 3
CLOCK_INIT(3)
#elif PIC32_TIMER_CLOCK == 4
CLOCK_INIT(4)
#elif PIC32_TIMER_CLOCK == 5
CLOCK_INIT(5)
#endif
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void
clock_delay_usec(uint16_t dt) clock_delay_usec(uint16_t dt)
@ -139,6 +153,16 @@ clock_delay(unsigned int delay)
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#if PIC32_TIMER_CLOCK == 1
TIMER_INTERRUPT(1, clock_callback); TIMER_INTERRUPT(1, clock_callback);
#elif PIC32_TIMER_CLOCK == 2
TIMER_INTERRUPT(2, clock_callback);
#elif PIC32_TIMER_CLOCK == 3
TIMER_INTERRUPT(3, clock_callback);
#elif PIC32_TIMER_CLOCK == 4
TIMER_INTERRUPT(4, clock_callback);
#elif PIC32_TIMER_CLOCK == 5
TIMER_INTERRUPT(5, clock_callback);
#endif
/** @} */ /** @} */

View File

@ -54,7 +54,7 @@
#include <dev/serial-line.h> #include <dev/serial-line.h>
#define DEBUG 1 #define DEBUG 0
#if DEBUG #if DEBUG
#include <stdio.h> #include <stdio.h>
#define PRINTF(...) printf(__VA_ARGS__) #define PRINTF(...) printf(__VA_ARGS__)
@ -62,7 +62,7 @@
#define PRINTF(...) #define PRINTF(...)
#endif #endif
#define DEBUG_UART(XX) \ #define DEBUG_UART(XX, YY) \
void \ void \
_mon_putc(char c) \ _mon_putc(char c) \
{ \ { \
@ -77,20 +77,20 @@
PRINTF("Initializing debug uart: %lubps\n", ubr); \ PRINTF("Initializing debug uart: %lubps\n", ubr); \
} \ } \
\ \
UART_INTERRUPT(XX, 2, pic32_uart##XX##_write); UART_INTERRUPT(XX, YY, pic32_uart##XX##_write);
#ifdef __USE_UART_PORT1A_FOR_DEBUG__ #ifdef __USE_UART_PORT1A_FOR_DEBUG__
DEBUG_UART(1A); DEBUG_UART(1A, 0);
#elif defined __USE_UART_PORT1B_FOR_DEBUG__ #elif defined __USE_UART_PORT1B_FOR_DEBUG__
DEBUG_UART(1B); DEBUG_UART(1B, 2);
#elif defined __USE_UART_PORT2A_FOR_DEBUG__ #elif defined __USE_UART_PORT2A_FOR_DEBUG__
DEBUG_UART(2A); DEBUG_UART(2A, 1);
#elif defined __USE_UART_PORT2B_FOR_DEBUG__ #elif defined __USE_UART_PORT2B_FOR_DEBUG__
DEBUG_UART(2B); DEBUG_UART(2B, 2);
#elif defined __USE_UART_PORT3A_FOR_DEBUG__ #elif defined __USE_UART_PORT3A_FOR_DEBUG__
DEBUG_UART(3A); DEBUG_UART(3A, 1);
#elif defined __USE_UART_PORT3B_FOR_DEBUG__ #elif defined __USE_UART_PORT3B_FOR_DEBUG__
DEBUG_UART(3B); DEBUG_UART(3B, 2);
#else #else
DEBUG_UART(1A); DEBUG_UART(1A);
#endif #endif

View File

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

View File

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

View File

@ -60,7 +60,7 @@
#define PRINTF(...) #define PRINTF(...)
#endif #endif
#define SLIP_UART(XX) \ #define SLIP_UART(XX, YY) \
void \ void \
slip_arch_writeb(unsigned char c) \ slip_arch_writeb(unsigned char c) \
{ \ { \
@ -75,20 +75,20 @@
PRINTF("Initializing slip uart: %lubps\n", ubr); \ PRINTF("Initializing slip uart: %lubps\n", ubr); \
} \ } \
\ \
UART_INTERRUPT(XX, 0, slip_input_byte); UART_INTERRUPT(XX, YY, slip_input_byte);
#ifdef __USE_UART_PORT1A_FOR_SLIP__ #ifdef __USE_UART_PORT1A_FOR_SLIP__
SLIP_UART(1A); SLIP_UART(1A, 0);
#elif defined __USE_UART_PORT1B_FOR_SLIP__ #elif defined __USE_UART_PORT1B_FOR_SLIP__
SLIP_UART(1B); SLIP_UART(1B, 2);
#elif defined __USE_UART_PORT2A_FOR_SLIP__ #elif defined __USE_UART_PORT2A_FOR_SLIP__
SLIP_UART(2A); SLIP_UART(2A, 1);
#elif defined __USE_UART_PORT2B_FOR_SLIP__ #elif defined __USE_UART_PORT2B_FOR_SLIP__
SLIP_UART(2B); SLIP_UART(2B, 2);
#elif defined __USE_UART_PORT3A_FOR_SLIP__ #elif defined __USE_UART_PORT3A_FOR_SLIP__
SLIP_UART(3A); SLIP_UART(3A, 1);
#elif defined __USE_UART_PORT3B_FOR_SLIP__ #elif defined __USE_UART_PORT3B_FOR_SLIP__
SLIP_UART(3B); SLIP_UART(3B, 2);
#else #else
SLIP_UART(1A); SLIP_UART(1A);
#endif #endif

View File

@ -14,8 +14,36 @@ CONTIKI_TARGET_DIRS = . dev dev/mrf24j40 apps net
CONTIKI_TARGET_MAIN = ${addprefix $(OBJECTDIR)/,contiki-main.o} CONTIKI_TARGET_MAIN = ${addprefix $(OBJECTDIR)/,contiki-main.o}
CONTIKI_PLAT_DEFS += -D __USE_TIMER__ CONTIKI_PLAT_DEFS += -D __USE_TIMER__
CONTIKI_PLAT_DEFS += -D __USE_TIMER_1__
CONTIKI_PLAT_DEFS += -D __USE_TIMER_23__ ifndef PIC32_TIMER_CLOCK
CONTIKI_PLAT_DEFS += -D __USE_TIMER_1__ -D PIC32_TIMER_CLOCK=1
endif
ifeq ($(PIC32_TIMER_CLOCK),1)
CONTIKI_PLAT_DEFS += -D __USE_TIMER_1__ -D PIC32_TIMER_CLOCK=1
endif
ifeq ($(PIC32_TIMER_CLOCK),2)
CONTIKI_PLAT_DEFS += -D __USE_TIMER_2__ -D PIC32_TIMER_CLOCK=2
endif
ifeq ($(PIC32_TIMER_CLOCK),3)
CONTIKI_PLAT_DEFS += -D __USE_TIMER_3__ -D PIC32_TIMER_CLOCK=3
endif
ifeq ($(PIC32_TIMER_CLOCK),4)
CONTIKI_PLAT_DEFS += -D __USE_TIMER_4__ -D PIC32_TIMER_CLOCK=4
endif
ifeq ($(PIC32_TIMER_CLOCK),5)
CONTIKI_PLAT_DEFS += -D __USE_TIMER_5__ -D PIC32_TIMER_CLOCK=5
endif
ifndef PIC32_TIMER_RTIMER
CONTIKI_PLAT_DEFS += -D __USE_TIMER_23__ -D PIC32_TIMER_RTIMER=23
endif
ifeq ($(PIC32_TIMER_RTIMER),23)
CONTIKI_PLAT_DEFS += -D __USE_TIMER_23__ -D PIC32_TIMER_RTIMER=23
endif
ifeq ($(PIC32_TIMER_RTIMER),45)
CONTIKI_PLAT_DEFS += -D __USE_TIMER_45__ -D PIC32_TIMER_RTIMER=45
endif
CONTIKI_PLAT_DEFS += -D __USE_UART__ CONTIKI_PLAT_DEFS += -D __USE_UART__
CONTIKI_PLAT_DEFS += -D __USE_UART_PORT1A__ CONTIKI_PLAT_DEFS += -D __USE_UART_PORT1A__
CONTIKI_PLAT_DEFS += -D __USE_UART_PORT1B__ CONTIKI_PLAT_DEFS += -D __USE_UART_PORT1B__

View File

@ -116,8 +116,8 @@ main(int argc, char **argv)
PRINTF("Initialising Node: %d\n", SEEDEYE_ID); PRINTF("Initialising Node: %d\n", SEEDEYE_ID);
printf("CPU Clock: %uMhz\n", pic32_clock_get_system_clock() / 1000000); PRINTF("CPU Clock: %uMhz\n", pic32_clock_get_system_clock() / 1000000);
printf("Peripheral Clock: %uMhz\n", pic32_clock_get_peripheral_clock() / 1000000); PRINTF("Peripheral Clock: %uMhz\n", pic32_clock_get_peripheral_clock() / 1000000);
random_init(SEEDEYE_ID); random_init(SEEDEYE_ID);

View File

@ -51,8 +51,8 @@
#define MRF24J40_PAN_COORDINATOR #define MRF24J40_PAN_COORDINATOR
#endif /* SEEDEYE_ID == 1 */ #endif /* SEEDEYE_ID == 1 */
#define UART_DEBUG_BAUDRATE 230400 #define UART_DEBUG_BAUDRATE 115200
#define UART_SLIP_BAUDRATE 230400 #define UART_SLIP_BAUDRATE 115200
#define PLATFORM_HAS_BATTERY 1 #define PLATFORM_HAS_BATTERY 1
#define PLATFORM_HAS_BUTTON 1 #define PLATFORM_HAS_BUTTON 1