Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: pkg/board/microchip_esk/src/ee_board.c
- ===================================================================
- --- pkg/board/microchip_esk/src/ee_board.c (revision 0)
- +++ pkg/board/microchip_esk/src/ee_board.c (revision 0)
- @@ -0,0 +1,77 @@
- +/* ###*B*###
- + * ERIKA Enterprise - a tiny RTOS for small microcontrollers
- + *
- + * Copyright (C) 2002-2008 Evidence Srl
- + *
- + * This file is part of ERIKA Enterprise.
- + *
- + * ERIKA Enterprise is free software; you can redistribute it
- + * and/or modify it under the terms of the GNU General Public License
- + * version 2 as published by the Free Software Foundation,
- + * (with a special exception described below).
- + *
- + * Linking this code statically or dynamically with other modules is
- + * making a combined work based on this code. Thus, the terms and
- + * conditions of the GNU General Public License cover the whole
- + * combination.
- + *
- + * As a special exception, the copyright holders of this library give you
- + * permission to link this code with independent modules to produce an
- + * executable, regardless of the license terms of these independent
- + * modules, and to copy and distribute the resulting executable under
- + * terms of your choice, provided that you also meet, for each linked
- + * independent module, the terms and conditions of the license of that
- + * module. An independent module is a module which is not derived from
- + * or based on this library. If you modify this code, you may extend
- + * this exception to your version of the code, but you are not
- + * obligated to do so. If you do not wish to do so, delete this
- + * exception statement from your version.
- + *
- + * ERIKA Enterprise is distributed in the hope that it will be
- + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
- + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- + * GNU General Public License version 2 for more details.
- + *
- + * You should have received a copy of the GNU General Public License
- + * version 2 along with ERIKA Enterprise; if not, write to the
- + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- + * Boston, MA 02110-1301 USA.
- + * ###*E*### */
- +
- +/*
- + * ## Author: 2014 Angelo Compagnucci <angelo.compagnucci@gmail.com>
- + *
- + */
- +
- +#include "ee_internal.h"
- +#include "board/microchip_esk/inc/ee_board.h"
- +
- +#if defined __PIC32__
- +#include "cpu/pic32/inc/ee_irqstub.h"
- +#include "mcu/microchip_pic32/inc/ee_mcu.h"
- +#else
- +#error "Unsupported pic on esk board"
- +#endif
- +
- +
- +/* ************************************************************************* */
- +/* Buttons */
- +/* ************************************************************************* */
- +
- +#ifdef __USE_BUTTONS__
- +
- +void (*EE_button_callback)(void);
- +EE_UINT8 EE_button_mask;
- +
- +ISR2(EE_ESK_IRQ_HANDLER_NAME)
- +{
- + // Execute callback function
- + if (EE_button_callback != NULL) {
- + EE_button_callback();
- + }
- +
- + /* reset CN interrupt flag */
- + IFS1bits.CNIF = 0;
- +}
- +
- +#endif
- Index: pkg/board/microchip_esk/inc/ee_internal.h
- ===================================================================
- --- pkg/board/microchip_esk/inc/ee_internal.h (revision 0)
- +++ pkg/board/microchip_esk/inc/ee_internal.h (revision 0)
- @@ -0,0 +1,46 @@
- +/* ###*B*###
- + * ERIKA Enterprise - a tiny RTOS for small microcontrollers
- + *
- + * Copyright (C) 2002-2008 Evidence Srl
- + *
- + * This file is part of ERIKA Enterprise.
- + *
- + * ERIKA Enterprise is free software; you can redistribute it
- + * and/or modify it under the terms of the GNU General Public License
- + * version 2 as published by the Free Software Foundation,
- + * (with a special exception described below).
- + *
- + * Linking this code statically or dynamically with other modules is
- + * making a combined work based on this code. Thus, the terms and
- + * conditions of the GNU General Public License cover the whole
- + * combination.
- + *
- + * As a special exception, the copyright holders of this library give you
- + * permission to link this code with independent modules to produce an
- + * executable, regardless of the license terms of these independent
- + * modules, and to copy and distribute the resulting executable under
- + * terms of your choice, provided that you also meet, for each linked
- + * independent module, the terms and conditions of the license of that
- + * module. An independent module is a module which is not derived from
- + * or based on this library. If you modify this code, you may extend
- + * this exception to your version of the code, but you are not
- + * obligated to do so. If you do not wish to do so, delete this
- + * exception statement from your version.
- + *
- + * ERIKA Enterprise is distributed in the hope that it will be
- + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
- + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- + * GNU General Public License version 2 for more details.
- + *
- + * You should have received a copy of the GNU General Public License
- + * version 2 along with ERIKA Enterprise; if not, write to the
- + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- + * Boston, MA 02110-1301 USA.
- + * ###*E*### */
- +
- +/*
- + * Author: 2014 Angelo Compagnucci <angelo.compagnucci@gmail.com>
- + *
- + */
- +
- +#include "board/microchip_esk/inc/ee_board.h"
- Index: pkg/board/microchip_esk/inc/ee_esk_pic32_hal.h
- ===================================================================
- --- pkg/board/microchip_esk/inc/ee_esk_pic32_hal.h (revision 0)
- +++ pkg/board/microchip_esk/inc/ee_esk_pic32_hal.h (revision 0)
- @@ -0,0 +1,69 @@
- +/* ###*B*###
- + * ERIKA Enterprise - a tiny RTOS for small microcontrollers
- + *
- + * Copyright (C) 2002-2008 Evidence Srl
- + *
- + * This file is part of ERIKA Enterprise.
- + *
- + * ERIKA Enterprise is free software; you can redistribute it
- + * and/or modify it under the terms of the GNU General Public License
- + * version 2 as published by the Free Software Foundation,
- + * (with a special exception described below).
- + *
- + * Linking this code statically or dynamically with other modules is
- + * making a combined work based on this code. Thus, the terms and
- + * conditions of the GNU General Public License cover the whole
- + * combination.
- + *
- + * As a special exception, the copyright holders of this library give you
- + * permission to link this code with independent modules to produce an
- + * executable, regardless of the license terms of these independent
- + * modules, and to copy and distribute the resulting executable under
- + * terms of your choice, provided that you also meet, for each linked
- + * independent module, the terms and conditions of the license of that
- + * module. An independent module is a module which is not derived from
- + * or based on this library. If you modify this code, you may extend
- + * this exception to your version of the code, but you are not
- + * obligated to do so. If you do not wish to do so, delete this
- + * exception statement from your version.
- + *
- + * ERIKA Enterprise is distributed in the hope that it will be
- + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
- + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- + * GNU General Public License version 2 for more details.
- + *
- + * You should have received a copy of the GNU General Public License
- + * version 2 along with ERIKA Enterprise; if not, write to the
- + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- + * Boston, MA 02110-1301 USA.
- + * ###*E*### */
- +
- +/*
- + * Author: 2014 Angelo Compagnucci <angelo.compagnucci@gmail.com>
- + *
- + */
- +
- +
- +#include "mcu/microchip_pic32/inc/ee_mcu.h"
- +
- +
- +/* Configure button pins for digital inputs */
- +#define EE_esk_AD_Confict_Solve() AD1PCFG = 0x00099000;
- +
- +/* enabling interrupt notifications on S3/RD6, S4/RD13, and S6/RD7 */
- +/* the interrupt notification cannot be enabled on S5/RA7 */
- +#define EE_esk_cn_1_int_en() CNENbits.CNEN15 = 1; CNPUEbits.CNPUE15 = 1 /* S0/RD6 */
- +#define EE_esk_cn_2_int_en() CNENbits.CNEN16 = 1; CNPUEbits.CNPUE16 = 1 /* S1/RD7 */
- +#define EE_esk_cn_4_int_en() CNENbits.CNEN19 = 1; CNPUEbits.CNPUE19 = 1 /* S2/RD13 */
- +
- +/* Enable Change Notice module */
- +#define EE_esk_cn_pri() CNCON = 0x8000
- +
- +/* Set Interrupt priority level=5 and Subpriority level=3 */
- +#define EE_esk_cn_pri_lev() IPC6SET = 0x00170000;
- +
- +/* IRQ Handler */
- +#define EE_ESK_IRQ_HANDLER_NAME _CHANGE_NOTICE_VECTOR
- +
- +/* Interrupt vector */
- +#define EE_ESK_INT_VECT _ADC_VECTOR
- Index: pkg/board/microchip_esk/inc/ee_board.h
- ===================================================================
- --- pkg/board/microchip_esk/inc/ee_board.h (revision 0)
- +++ pkg/board/microchip_esk/inc/ee_board.h (revision 0)
- @@ -0,0 +1,149 @@
- +/* ###*B*###
- + * ERIKA Enterprise - a tiny RTOS for small microcontrollers
- + *
- + * Copyright (C) 2002-2008 Evidence Srl
- + *
- + * This file is part of ERIKA Enterprise.
- + *
- + * ERIKA Enterprise is free software; you can redistribute it
- + * and/or modify it under the terms of the GNU General Public License
- + * version 2 as published by the Free Software Foundation,
- + * (with a special exception described below).
- + *
- + * Linking this code statically or dynamically with other modules is
- + * making a combined work based on this code. Thus, the terms and
- + * conditions of the GNU General Public License cover the whole
- + * combination.
- + *
- + * As a special exception, the copyright holders of this library give you
- + * permission to link this code with independent modules to produce an
- + * executable, regardless of the license terms of these independent
- + * modules, and to copy and distribute the resulting executable under
- + * terms of your choice, provided that you also meet, for each linked
- + * independent module, the terms and conditions of the license of that
- + * module. An independent module is a module which is not derived from
- + * or based on this library. If you modify this code, you may extend
- + * this exception to your version of the code, but you are not
- + * obligated to do so. If you do not wish to do so, delete this
- + * exception statement from your version.
- + *
- + * ERIKA Enterprise is distributed in the hope that it will be
- + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
- + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- + * GNU General Public License version 2 for more details.
- + *
- + * You should have received a copy of the GNU General Public License
- + * version 2 along with ERIKA Enterprise; if not, write to the
- + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- + * Boston, MA 02110-1301 USA.
- + * ###*E*### */
- +
- +/*
- + * Author: 2014 Angelo Compagnucci <angelo.compagnucci@gmail.com>
- + *
- + */
- +
- +#ifndef __INCLUDE_MICROCHIP_esk_BOARD_H__
- +#define __INCLUDE_MICROCHIP_esk_BOARD_H__
- +
- +
- +#if defined __PIC32__
- +#include "board/microchip_esk/inc/ee_esk_pic32_hal.h"
- +#else
- +#error "Unsupported pic on esk board"
- +#endif
- +
- +
- +/* ************************************************************************* */
- +/* Buttons */
- +/* ************************************************************************* */
- +
- +#ifdef __USE_BUTTONS__
- +
- +extern void (*EE_button_callback)(void);
- +extern EE_UINT8 EE_button_mask;
- +
- +__INLINE__ void __ALWAYS_INLINE__ EE_buttons_init( void(*isr_callback)(void), EE_UINT8 mask ) {
- + /* set BUTTON pins (S0/RD6-S1/RD7-S2/RD13) as inputs */
- + TRISDbits.TRISD6 = 1;
- + TRISDbits.TRISD7 = 1;
- + TRISDbits.TRISD13 = 1;
- +
- + /* Solve conflict againd AD module */
- + EE_esk_AD_Confict_Solve();
- +
- + /* Enable Interrupt */
- + if (isr_callback != NULL) {
- + /* Enable Change Notice module */
- + EE_esk_cn_pri();
- +
- + if (mask & 0x01)
- + EE_esk_cn_1_int_en(); /* S0/RD6 */
- + if (mask & 0x02)
- + EE_esk_cn_2_int_en(); /* S1/RD7 */
- + if (mask & 0x04)
- + EE_esk_cn_4_int_en(); /* S2/RD13 */
- +
- + /* Set interrupt priority Level and Sublevel */
- + EE_esk_cn_pri_lev();
- +
- + IFS1bits.CNIF = 1;
- + IEC1bits.CNIE = 1;
- + }
- +
- + /* Save callback */
- + EE_button_callback = isr_callback;
- +}
- +
- +__INLINE__ EE_UINT8 __ALWAYS_INLINE__ EE_button_get_S1( void ) {
- + if (PORTDbits.RD6)
- + return 0;
- + else
- + return 1;
- +}
- +__INLINE__ EE_UINT8 __ALWAYS_INLINE__ EE_button_get_S2( void ) {
- + if (PORTDbits.RD7)
- + return 0;
- + else
- + return 1;
- +}
- +__INLINE__ EE_UINT8 __ALWAYS_INLINE__ EE_button_get_S3( void ) {
- + if (PORTDbits.RD13)
- + return 0;
- + else
- + return 1;
- +}
- +
- +#endif
- +
- +
- +/* ************************************************************************* */
- +/* LEDs */
- +/* ************************************************************************* */
- +
- +#ifdef __USE_LEDS__
- +
- +__INLINE__ void __ALWAYS_INLINE__ EE_leds_init(void) {
- + /* set LEDs (D0-D2) drive state low */
- + LATD &= 0xFFF8;
- + /* set LED pins (D0-D2) as outputs */
- + TRISD &= 0xFFF8;
- +}
- +
- +__INLINE__ void __ALWAYS_INLINE__ EE_leds_on(void) { LATD |= 0x0007; }
- +__INLINE__ void __ALWAYS_INLINE__ EE_leds_off(void) { LATD &= 0xFFF8; }
- +
- +__INLINE__ void __ALWAYS_INLINE__ EE_leds( EE_UINT8 data ) { LATD &= 0xFFF8; LATD |= data; }
- +
- +__INLINE__ void __ALWAYS_INLINE__ EE_led_0_on(void) { LATDbits.LATD0 = 1; }
- +__INLINE__ void __ALWAYS_INLINE__ EE_led_0_off(void) { LATDbits.LATD0 = 0; }
- +__INLINE__ void __ALWAYS_INLINE__ EE_led_1_on(void) { LATDbits.LATD1 = 1; }
- +__INLINE__ void __ALWAYS_INLINE__ EE_led_1_off(void) { LATDbits.LATD1 = 0; }
- +__INLINE__ void __ALWAYS_INLINE__ EE_led_2_on(void) { LATDbits.LATD2 = 1; }
- +__INLINE__ void __ALWAYS_INLINE__ EE_led_2_off(void) { LATDbits.LATD2 = 0; }
- +
- +__INLINE__ EE_UINT8 __ALWAYS_INLINE__ EE_led_is_on(EE_UINT8 led) { return PORTD & (1 << led); }
- +
- +#endif
- +
- +#endif
- Index: pkg/board/microchip_esk/cfg/cfg.mk
- ===================================================================
- --- pkg/board/microchip_esk/cfg/cfg.mk (revision 0)
- +++ pkg/board/microchip_esk/cfg/cfg.mk (revision 0)
- @@ -0,0 +1,50 @@
- +# ###*B*###
- +# ERIKA Enterprise - a tiny RTOS for small microcontrollers
- +#
- +# Copyright (C) 2002-2008 Evidence Srl
- +#
- +# This file is part of ERIKA Enterprise.
- +#
- +# ERIKA Enterprise is free software; you can redistribute it
- +# and/or modify it under the terms of the GNU General Public License
- +# version 2 as published by the Free Software Foundation,
- +# (with a special exception described below).
- +#
- +# Linking this code statically or dynamically with other modules is
- +# making a combined work based on this code. Thus, the terms and
- +# conditions of the GNU General Public License cover the whole
- +# combination.
- +#
- +# As a special exception, the copyright holders of this library give you
- +# permission to link this code with independent modules to produce an
- +# executable, regardless of the license terms of these independent
- +# modules, and to copy and distribute the resulting executable under
- +# terms of your choice, provided that you also meet, for each linked
- +# independent module, the terms and conditions of the license of that
- +# module. An independent module is a module which is not derived from
- +# or based on this library. If you modify this code, you may extend
- +# this exception to your version of the code, but you are not
- +# obligated to do so. If you do not wish to do so, delete this
- +# exception statement from your version.
- +#
- +# ERIKA Enterprise is distributed in the hope that it will be
- +# useful, but WITHOUT ANY WARRANTY; without even the implied warranty
- +# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- +# GNU General Public License version 2 for more details.
- +#
- +# You should have received a copy of the GNU General Public License
- +# version 2 along with ERIKA Enterprise; if not, write to the
- +# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- +# Boston, MA 02110-1301 USA.
- +# ###*E*###
- +
- +## Author: 2014 Angelo Compagnucci <angelo.compagnucci@gmail.com>
- +
- +ifeq ($(call iseeopt, __MICROCHIP_ESK__), yes)
- +EE_SRCS += pkg/board/microchip_esk/src/ee_board.c
- +
- +ifeq ($(call iseeopt, __USE_BUTTONS__), yes)
- +OPT_LINK += -u__CNInterrupt
- +endif
- +
- +endif
- Index: pkg/ee_internal.h
- ===================================================================
- --- pkg/ee_internal.h (revision 2913)
- +++ pkg/ee_internal.h (working copy)
- @@ -283,6 +283,10 @@
- #include "board/ee_miniflex/inc/ee_internal.h"
- #endif
- +#ifdef __MICROCHIP_ESK__
- +#include "board/microchip_esk/inc/ee_internal.h"
- +#endif
- +
- /* MICO32 */
- #ifdef __LM32__
- #include "board/fpg-eye/inc/ee_internal.h"
- Index: pkg/ee.h
- ===================================================================
- --- pkg/ee.h (revision 2913)
- +++ pkg/ee.h (working copy)
- @@ -322,6 +322,10 @@
- #include "board/ipermob_board_v2/inc/ee_board.h"
- #endif
- +#ifdef __MICROCHIP_ESK__
- +#include "board/microchip_esk/inc/ee_board.h"
- +#endif
- +
- /* MICO32 */
- #ifdef __FPG_EYE__
- #include "board/fpg-eye/inc/ee_board.h"
- Index: examples/pic32/esk/pic32_esk_base/conf.oil
- ===================================================================
- --- examples/pic32/esk/pic32_esk_base/conf.oil (revision 0)
- +++ examples/pic32/esk/pic32_esk_base/conf.oil (revision 0)
- @@ -0,0 +1,107 @@
- +/* ###*B*###
- + * ERIKA Enterprise - a tiny RTOS for small microcontrollers
- + *
- + * Copyright (C) 2002-2008 Evidence Srl
- + *
- + * This file is part of ERIKA Enterprise.
- + *
- + * ERIKA Enterprise is free software; you can redistribute it
- + * and/or modify it under the terms of the GNU General Public License
- + * version 2 as published by the Free Software Foundation,
- + * (with a special exception described below).
- + *
- + * Linking this code statically or dynamically with other modules is
- + * making a combined work based on this code. Thus, the terms and
- + * conditions of the GNU General Public License cover the whole
- + * combination.
- + *
- + * As a special exception, the copyright holders of this library give you
- + * permission to link this code with independent modules to produce an
- + * executable, regardless of the license terms of these independent
- + * modules, and to copy and distribute the resulting executable under
- + * terms of your choice, provided that you also meet, for each linked
- + * independent module, the terms and conditions of the license of that
- + * module. An independent module is a module which is not derived from
- + * or based on this library. If you modify this code, you may extend
- + * this exception to your version of the code, but you are not
- + * obligated to do so. If you do not wish to do so, delete this
- + * exception statement from your version.
- + *
- + * ERIKA Enterprise is distributed in the hope that it will be
- + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
- + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- + * GNU General Public License version 2 for more details.
- + *
- + * You should have received a copy of the GNU General Public License
- + * version 2 along with ERIKA Enterprise; if not, write to the
- + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- + * Boston, MA 02110-1301 USA.
- + * ###*E*### */
- +
- +
- +CPU mySystem {
- +
- + OS myOs {
- + EE_OPT = "DEBUG";
- +
- + CPU_DATA = PIC32 {
- + APP_SRC = "code.c";
- + MULTI_STACK = FALSE;
- + ICD2 = TRUE;
- + };
- + MCU_DATA = PIC32 {
- + MODEL = PIC32MX795F512L;
- + };
- +
- + BOARD_DATA = NO_BOARD {
- + };
- +
- + KERNEL_TYPE = FP;
- +
- + EE_OPT = "__ADD_LIBS__";
- + EE_OPT = "__USE_TIMER__";
- + EE_OPT = "__USE_EE_TIMER_1__";
- + EE_OPT = "__MICROCHIP_ESK__";
- + EE_OPT = "__USE_LEDS__";
- + EE_OPT = "__USE_BUTTONS__";
- + };
- +
- + COUNTER myCounter;
- +
- + TASK TaskLed1 {
- + PRIORITY = 1;
- + STACK = SHARED;
- + SCHEDULE = FULL;
- + };
- +
- + TASK TaskLed2 {
- + PRIORITY = 2;
- + STACK = SHARED;
- + SCHEDULE = FULL;
- + };
- +
- + TASK TaskLed3 {
- + PRIORITY = 3;
- + STACK = SHARED;
- + SCHEDULE = FULL;
- + };
- +
- + COUNTER myCounter;
- +
- + ALARM AlarmLed1 {
- + COUNTER = myCounter;
- + ACTION = ACTIVATETASK { TASK = TaskLed1; };
- + };
- +
- + ALARM AlarmLed2 {
- + COUNTER = myCounter;
- + ACTION = ACTIVATETASK { TASK = TaskLed2; };
- + };
- +
- + ALARM AlarmLed3 {
- + COUNTER = myCounter;
- + ACTION = ACTIVATETASK { TASK = TaskLed3; };
- + };
- +
- +
- +};
- Index: examples/pic32/esk/pic32_esk_base/template.xml
- ===================================================================
- --- examples/pic32/esk/pic32_esk_base/template.xml (revision 0)
- +++ examples/pic32/esk/pic32_esk_base/template.xml (revision 0)
- @@ -0,0 +1,25 @@
- +<?xml version="1.0" encoding="ISO-8859-1"?>
- +
- +<evidence_example version="1" ID="pic32_ESK_Devices">
- +
- + <category>pic32/ESK</category>
- + <title>Devices Demo</title>
- +
- + <small_descr>
- + This is the demo to test the Microchip Ethernet Starter Kit board and its devices.
- + </small_descr>
- +
- + <long_descr>
- + A minimal EEB demo that demostrates the functions for:
- + <ul>
- + <li>Leds; </li>
- + <li>Buttons; </li>
- + </ul>
- + </long_descr>
- +
- + <file_section>
- + <file name="code.c"/>
- + <file name="conf.oil"/>
- + </file_section>
- +
- +</evidence_example>
- Index: examples/pic32/esk/pic32_esk_base/code.c
- ===================================================================
- --- examples/pic32/esk/pic32_esk_base/code.c (revision 0)
- +++ examples/pic32/esk/pic32_esk_base/code.c (revision 0)
- @@ -0,0 +1,173 @@
- +/* ###*B*###
- + * ERIKA Enterprise - a tiny RTOS for small microcontrollers
- + *
- + * Copyright (C) 2002-2008 Evidence Srl
- + *
- + * This file is part of ERIKA Enterprise.
- + *
- + * ERIKA Enterprise is free software; you can redistribute it
- + * and/or modify it under the terms of the GNU General Public License
- + * version 2 as published by the Free Software Foundation,
- + * (with a special exception described below).
- + *
- + * Linking this code statically or dynamically with other modules is
- + * making a combined work based on this code. Thus, the terms and
- + * conditions of the GNU General Public License cover the whole
- + * combination.
- + *
- + * As a special exception, the copyright holders of this library give you
- + * permission to link this code with independent modules to produce an
- + * executable, regardless of the license terms of these independent
- + * modules, and to copy and distribute the resulting executable under
- + * terms of your choice, provided that you also meet, for each linked
- + * independent module, the terms and conditions of the license of that
- + * module. An independent module is a module which is not derived from
- + * or based on this library. If you modify this code, you may extend
- + * this exception to your version of the code, but you are not
- + * obligated to do so. If you do not wish to do so, delete this
- + * exception statement from your version.
- + *
- + * ERIKA Enterprise is distributed in the hope that it will be
- + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
- + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- + * GNU General Public License version 2 for more details.
- + *
- + * You should have received a copy of the GNU General Public License
- + * version 2 along with ERIKA Enterprise; if not, write to the
- + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- + * Boston, MA 02110-1301 USA.
- + * ###*E*### */
- +
- + /*
- + * Author: 2014 Angelo Compagnucci <angelo.compagnucci@gmail.com>
- + *
- + */
- +
- +#include <ee.h>
- +#include "cpu/pic32/inc/ee_irqstub.h"
- +#include "mcu/microchip_pic32/inc/ee_timer.h"
- +
- +
- +/* Initial Configuration (fuse bits)
- + *
- + * Main Clock -> SYSCLK = Crystal_Freq / FPLLIDIV * FPLLMUL / FPLLODIV
- + * Peripheral Clock -> PBCLK = SYSCLK / FPBDIV
- +*/
- +#pragma config POSCMOD = HS
- +#pragma config FNOSC = PRIPLL
- +#pragma config FPLLMUL = MUL_20 /* PLL Multiplier */
- +#pragma config FPLLIDIV = DIV_2 /* PLL Input Divider */
- +#pragma config FPLLODIV = DIV_1 /* PLL Output Divider */
- +#pragma config FWDTEN = OFF /* Watchdog Off */
- +#pragma config FPBDIV = DIV_2 /* SYSCLK = 80MHz, PBCLK = 40MHz */
- +
- +
- +/* ************************************************************************** */
- +/* Macros */
- +/* ************************************************************************** */
- +
- +/* Timer definitions */
- +#define TICK_PERIOD 20000
- +
- +
- +/* ************************************************************************** */
- +/* Functions */
- +/* ************************************************************************** */
- +
- +/* Clear the Timer1 interrupt status flag */
- +void T1_clear(void)
- +{
- + IFS0bits.T1IF = 0;
- +}
- +
- +
- +/* This is an ISR Type 2 which is attached to the Timer 1 peripheral IRQ pin
- + * The ISR simply calls CounterTick to implement the timing reference
- + */
- +void T1_cbk(void)
- +{
- + /* clear the interrupt source */
- + T1_clear();
- +
- + /* count the interrupts, waking up expired alarms */
- + CounterTick(myCounter);
- +}
- +
- +
- +/* Program the Timer1 peripheral to raise interrupts */
- +void T1_program(void)
- +{
- + EE_timer_soft_init(EE_TIMER_1,30000);
- + EE_timer_set_callback(EE_TIMER_1,&T1_cbk);
- + EE_timer_start(EE_TIMER_1);
- +}
- +
- +
- +
- +/* ************************************************************************** */
- +/* Tasks */
- +/* ************************************************************************** */
- +TASK(TaskLed1)
- +{
- + if (EE_led_is_on(0)){
- + EE_led_0_off();
- + } else {
- + EE_led_0_on();
- + }
- +}
- +
- +TASK(TaskLed2)
- +{
- + if (EE_led_is_on(1)){
- + EE_led_1_off();
- + } else {
- + EE_led_1_on();
- + }
- +}
- +
- +TASK(TaskLed3)
- +{
- + if (EE_led_is_on(2)){
- + EE_led_2_off();
- + } else {
- + EE_led_2_on();
- + }
- +}
- +
- +
- +void my_button(void)
- +{
- + /* Light up all LEDs */
- + if (EE_button_get_S1() == 1)
- + EE_leds_on();
- +}
- +
- +
- +
- +/* ************************************************************************** */
- +/* MAIN */
- +/* ************************************************************************** */
- +int main(void)
- +{
- + /* */
- + EE_system_init();
- +
- + /* Init leds */
- + EE_leds_init();
- +
- + /* Init devices */
- + EE_buttons_init(&my_button, 0x01);
- +
- + /* Program Timer 1 to raise interrupts */
- + T1_program();
- +
- + /* Program cyclic alarms which will fire after an initial offset, and after that periodically */
- + SetRelAlarm(AlarmLed1, 1, 10);
- + SetRelAlarm(AlarmLed2, 3, 10);
- + SetRelAlarm(AlarmLed3, 6, 10);
- +
- + /* Forever loop: background activities (if any) should go here */
- + for (;;);
- +
- + return 0;
- +}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement