From 492bd36b32ac8d240430e4879fadd980b0675ba2 Mon Sep 17 00:00:00 2001 From: Rahul Daga Date: Thu, 13 Aug 2015 10:51:05 +0530 Subject: [PATCH 1/3] platform/mikro-e: add minimal platform files for mikro-e Change-Id: If5b1de77213c4889a0e3df3a8a79124202079fa1 Signed-off-by: Rahul Daga Signed-off-by: Abhijit Mahajani platform/mikro-e/contiki-conf.h: rename RITIMER_CLOCK_LT to RTIMER_CLOCK_DIFF to match the new define name Signed-off-by: Michal Tusnio --- platform/mikro-e/Makefile.mikro-e | 15 ++++++ platform/mikro-e/contiki-conf.h | 48 +++++++++++++++++ platform/mikro-e/contiki-mikro-e-main.c | 68 +++++++++++++++++++++++++ platform/mikro-e/leds-arch.c | 53 +++++++++++++++++++ 4 files changed, 184 insertions(+) create mode 100755 platform/mikro-e/Makefile.mikro-e create mode 100755 platform/mikro-e/contiki-conf.h create mode 100755 platform/mikro-e/contiki-mikro-e-main.c create mode 100755 platform/mikro-e/leds-arch.c diff --git a/platform/mikro-e/Makefile.mikro-e b/platform/mikro-e/Makefile.mikro-e new file mode 100755 index 00000000000..712acce9aed --- /dev/null +++ b/platform/mikro-e/Makefile.mikro-e @@ -0,0 +1,15 @@ +ifndef CONTIKI + $(error CONTIKI not defined! You must specify where CONTIKI resides!) +endif + +PIC32_MODEL=32MX470F512H + +CONTIKI_PLAT_DEFS += -D __USE_TIMER__ +CONTIKI_PLAT_DEFS += -D __USE_TIMER_1__ -D PIC32_TIMER_CLOCK=1 +CONTIKI_PLAT_DEFS += -D __USE_TIMER_23__ -D PIC32_TIMER_RTIMER=23 + +CONTIKI_TARGET_SOURCEFILES = contiki-mikro-e-main.c leds-arch.c + +CONTIKI_SOURCEFILES += $(CONTIKI_TARGET_SOURCEFILES) + +include $(CONTIKI)/cpu/pic32/Makefile.pic32 diff --git a/platform/mikro-e/contiki-conf.h b/platform/mikro-e/contiki-conf.h new file mode 100755 index 00000000000..917c42e2b2b --- /dev/null +++ b/platform/mikro-e/contiki-conf.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2015, Imagination Technologies Limited and/or its + * affiliated group companies. + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef CONTIKI_CONF_H +#define CONTIKI_CONF_H + +#include + +#define CCIF +#define CLIF + +typedef uint16_t uip_stats_t; +typedef uint32_t clock_time_t; +typedef uint32_t rtimer_clock_t; + +#define RTIMER_CLOCK_DIFF(a,b) ((int32_t)((a)-(b)) < 0) + +#define CLOCK_CONF_SECOND 1024 + +#endif /* CONTIKI_CONF_H */ diff --git a/platform/mikro-e/contiki-mikro-e-main.c b/platform/mikro-e/contiki-mikro-e-main.c new file mode 100755 index 00000000000..2cc9ba3d8c0 --- /dev/null +++ b/platform/mikro-e/contiki-mikro-e-main.c @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2015, Imagination Technologies Limited and/or its + * affiliated group companies. + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* TODO: add documentation */ +#include +#include +#include +#include +#include + +/*---------------------------------------------------------------------------*/ +int +main(int argc, char **argv) +{ + int32_t r; + + pic32_init(); + watchdog_init(); + clock_init(); + process_init(); + process_start(&etimer_process, NULL); + ctimer_init(); + rtimer_init(); + + autostart_start(autostart_processes); + watchdog_start(); + + while(1) { + do { + watchdog_periodic(); + r = process_run(); + } while(r > 0); + watchdog_stop(); + asm volatile("wait"); + watchdog_start(); + } + + return 0; +} +/*---------------------------------------------------------------------------*/ diff --git a/platform/mikro-e/leds-arch.c b/platform/mikro-e/leds-arch.c new file mode 100755 index 00000000000..09601f40037 --- /dev/null +++ b/platform/mikro-e/leds-arch.c @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2015, Imagination Technologies Limited and/or its + * affiliated group companies. + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "contiki-conf.h" +#include "dev/leds.h" + +/* Dummy definitions for led methods in dev/leds.h used in cpu/pic32 files */ + +/*---------------------------------------------------------------------------*/ +void +leds_arch_init(void) +{ +} +/*---------------------------------------------------------------------------*/ +unsigned char +leds_arch_get(void) +{ + return 0; +} +/*---------------------------------------------------------------------------*/ +void +leds_arch_set(unsigned char leds) +{ +} +/*---------------------------------------------------------------------------*/ From fbf9e614a6101b803908dfc12969c0dc5159f7f6 Mon Sep 17 00:00:00 2001 From: Rahul Daga Date: Thu, 13 Aug 2015 20:32:56 +0530 Subject: [PATCH 2/3] platform/mikro-e: add platform init code Currently only uart pins are configured in the platform initialisation code. Change-Id: Iac6b72abb0a4654cb126c2c42e89e9bedb252a46 Signed-off-by: Rahul Daga Signed-off-by: Abhijit Mahajani --- platform/mikro-e/Makefile.mikro-e | 2 +- platform/mikro-e/contiki-mikro-e-main.c | 4 ++ platform/mikro-e/platform-init.c | 68 +++++++++++++++++++++++++ platform/mikro-e/platform-init.h | 37 ++++++++++++++ 4 files changed, 110 insertions(+), 1 deletion(-) create mode 100755 platform/mikro-e/platform-init.c create mode 100755 platform/mikro-e/platform-init.h diff --git a/platform/mikro-e/Makefile.mikro-e b/platform/mikro-e/Makefile.mikro-e index 712acce9aed..b0f3d416903 100755 --- a/platform/mikro-e/Makefile.mikro-e +++ b/platform/mikro-e/Makefile.mikro-e @@ -8,7 +8,7 @@ CONTIKI_PLAT_DEFS += -D __USE_TIMER__ CONTIKI_PLAT_DEFS += -D __USE_TIMER_1__ -D PIC32_TIMER_CLOCK=1 CONTIKI_PLAT_DEFS += -D __USE_TIMER_23__ -D PIC32_TIMER_RTIMER=23 -CONTIKI_TARGET_SOURCEFILES = contiki-mikro-e-main.c leds-arch.c +CONTIKI_TARGET_SOURCEFILES = contiki-mikro-e-main.c leds-arch.c platform-init.c CONTIKI_SOURCEFILES += $(CONTIKI_TARGET_SOURCEFILES) diff --git a/platform/mikro-e/contiki-mikro-e-main.c b/platform/mikro-e/contiki-mikro-e-main.c index 2cc9ba3d8c0..693ba988292 100755 --- a/platform/mikro-e/contiki-mikro-e-main.c +++ b/platform/mikro-e/contiki-mikro-e-main.c @@ -35,6 +35,8 @@ #include #include #include +#include + /*---------------------------------------------------------------------------*/ int @@ -45,6 +47,8 @@ main(int argc, char **argv) pic32_init(); watchdog_init(); clock_init(); + platform_init(); + process_init(); process_start(&etimer_process, NULL); ctimer_init(); diff --git a/platform/mikro-e/platform-init.c b/platform/mikro-e/platform-init.c new file mode 100755 index 00000000000..1da7ad3785d --- /dev/null +++ b/platform/mikro-e/platform-init.c @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2015, Imagination Technologies Limited and/or its + * affiliated group companies. + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "platform-init.h" +#include +#include + +/*---------------------------------------------------------------------------*/ +void +platform_init() +{ + /* Disable interrupts */ + ASM_DIS_INT; + + /* Unlock sequence */ + SYSKEY = 0; + SYSKEY = 0xaa996655; + SYSKEY = 0x556699aa; + CFGCONbits.IOLOCK = 0; + + /* Configure remappable pins */ + + /* Uart1 Rx : RPF4 */ + TRISFSET = _TRISF_TRISF4_MASK; + U1RXR = 0b0010; + + /* Uart1 Tx : RPF5 */ + TRISFCLR = _TRISF_TRISF5_MASK; + RPF5R = 0b0011; + + /* TODO : Configure SPI and other pins */ + + /* Lock again */ + CFGCONbits.IOLOCK = 1; + SYSKEY = 0; + + /* Enable interrupts */ + ASM_EN_INT; +} +/*---------------------------------------------------------------------------*/ diff --git a/platform/mikro-e/platform-init.h b/platform/mikro-e/platform-init.h new file mode 100755 index 00000000000..5ddb5984d48 --- /dev/null +++ b/platform/mikro-e/platform-init.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2015, Imagination Technologies Limited and/or its + * affiliated group companies. + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef PLATFORM_INIT_H +#define PLATFORM_INIT_H + +void platform_init(); + +#endif /* PLATFORM_INIT_H */ From 69328f724ad8b6619a412d56bca59c7bf79c0247 Mon Sep 17 00:00:00 2001 From: Rahul Daga Date: Thu, 13 Aug 2015 21:00:58 +0530 Subject: [PATCH 3/3] platform/mikro-e: set up uart3 for debug Change-Id: I18f6c239509e70739fcda68248051036e622fe65 Signed-off-by: Rahul Daga Signed-off-by: Abhijit Mahajani platform/mikro-e: fix incorrect configurations for uart pins RPF4 is Tx and RPF5 is Rx according to platform specs whereas the current code incorrectly configures F4 as Rx and F5 as Tx. Change-Id: I032f8ae811f77148c78a9f45363117b13fae8649 Signed-off-by: Rahul Daga Signed-off-by: Abhijit Mahajani --- platform/mikro-e/Makefile.mikro-e | 4 ++++ platform/mikro-e/contiki-mikro-e-main.c | 4 ++++ platform/mikro-e/platform-init.c | 12 ++++++------ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/platform/mikro-e/Makefile.mikro-e b/platform/mikro-e/Makefile.mikro-e index b0f3d416903..9e966bd4886 100755 --- a/platform/mikro-e/Makefile.mikro-e +++ b/platform/mikro-e/Makefile.mikro-e @@ -8,6 +8,10 @@ CONTIKI_PLAT_DEFS += -D __USE_TIMER__ CONTIKI_PLAT_DEFS += -D __USE_TIMER_1__ -D PIC32_TIMER_CLOCK=1 CONTIKI_PLAT_DEFS += -D __USE_TIMER_23__ -D PIC32_TIMER_RTIMER=23 +CONTIKI_PLAT_DEFS += -D __USE_UART__ +CONTIKI_PLAT_DEFS += -D __USE_UART_PORT3__ +CONTIKI_PLAT_DEFS += -D __USE_UART_PORT3_FOR_DEBUG__ + CONTIKI_TARGET_SOURCEFILES = contiki-mikro-e-main.c leds-arch.c platform-init.c CONTIKI_SOURCEFILES += $(CONTIKI_TARGET_SOURCEFILES) diff --git a/platform/mikro-e/contiki-mikro-e-main.c b/platform/mikro-e/contiki-mikro-e-main.c index 693ba988292..6420de27f6b 100755 --- a/platform/mikro-e/contiki-mikro-e-main.c +++ b/platform/mikro-e/contiki-mikro-e-main.c @@ -36,7 +36,9 @@ #include #include #include +#include +#define UART_DEBUG_BAUDRATE 115200 /*---------------------------------------------------------------------------*/ int @@ -54,6 +56,8 @@ main(int argc, char **argv) ctimer_init(); rtimer_init(); + dbg_setup_uart(UART_DEBUG_BAUDRATE); + autostart_start(autostart_processes); watchdog_start(); diff --git a/platform/mikro-e/platform-init.c b/platform/mikro-e/platform-init.c index 1da7ad3785d..3a3d9ec869d 100755 --- a/platform/mikro-e/platform-init.c +++ b/platform/mikro-e/platform-init.c @@ -48,13 +48,13 @@ platform_init() /* Configure remappable pins */ - /* Uart1 Rx : RPF4 */ - TRISFSET = _TRISF_TRISF4_MASK; - U1RXR = 0b0010; + /* Uart3 Tx : RPF4 */ + TRISFCLR = _TRISF_TRISF4_MASK; + RPF4R = 0b0001; - /* Uart1 Tx : RPF5 */ - TRISFCLR = _TRISF_TRISF5_MASK; - RPF5R = 0b0011; + /* Uart3 Rx : RPF5 */ + TRISFSET = _TRISF_TRISF5_MASK; + U3RXR = 0b0010; /* TODO : Configure SPI and other pins */