diff --git a/platform/mikro-e/Makefile.mikro-e b/platform/mikro-e/Makefile.mikro-e new file mode 100755 index 00000000000..9e966bd4886 --- /dev/null +++ b/platform/mikro-e/Makefile.mikro-e @@ -0,0 +1,19 @@ +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_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) + +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..f9e2a0c2ed7 --- /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..47e23ea03d1 --- /dev/null +++ b/platform/mikro-e/contiki-mikro-e-main.c @@ -0,0 +1,78 @@ +/* + * 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. + */ + +/* + The mikro-e platform is based on the PIC32MX470F512H with MIPS32 core. + */ +#include +#include +#include +#include +#include +#include +#include + +#define UART_DEBUG_BAUDRATE 115200 + +/*---------------------------------------------------------------------------*/ +int +main(int argc, char **argv) +{ + int32_t r; + + pic32_init(); + watchdog_init(); + clock_init(); + platform_init(); + + process_init(); + process_start(&etimer_process, NULL); + ctimer_init(); + rtimer_init(); + + dbg_setup_uart(UART_DEBUG_BAUDRATE); + + 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) +{ +} +/*---------------------------------------------------------------------------*/ diff --git a/platform/mikro-e/platform-init.c b/platform/mikro-e/platform-init.c new file mode 100755 index 00000000000..3a3d9ec869d --- /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 */ + + /* Uart3 Tx : RPF4 */ + TRISFCLR = _TRISF_TRISF4_MASK; + RPF4R = 0b0001; + + /* Uart3 Rx : RPF5 */ + TRISFSET = _TRISF_TRISF5_MASK; + U3RXR = 0b0010; + + /* 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 */