Commit b7086673 authored by Projects's avatar Projects

Test for button interrupt handlers.

parent f7df784c
/*
* Copyright (C) 2014 Julian Lewis
* @author Maciej Suminski <maciej.suminski@cern.ch>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program 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 for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @brief Button routines
*/
#include "buttons.h"
void GPIO_EVEN_IRQHandler(void)
{
uint32_t iflags;
// Get all even interrupts
iflags = GPIO_IntGetEnabled() & 0x00005555;
// Clean only even interrupts
GPIO_IntClear(iflags);
GPIO_PinOutToggle(gpioPortE, 12);
//GPIOINT_IRQDispatcher(iflags);
}
void GPIO_ODD_IRQHandler(void)
{
uint32_t iflags;
// Get all odd interrupts
iflags = GPIO_IntGetEnabled() & 0x0000AAAA;
// Clean only even interrupts
GPIO_IntClear(iflags);
GPIO_PinOutToggle(gpioPortE, 11);
//GPIOINT_IRQDispatcher(iflags);
}
void buttons_init(void)
{
// Configure interrupt pin as input with pull-up
GPIO_PinModeSet(BUT_TL_PORT, BUT_TL_PIN, gpioModeInputPull, 1);
GPIO_PinModeSet(BUT_TR_PORT, BUT_TR_PIN, gpioModeInputPull, 1);
GPIO_PinModeSet(BUT_BL_PORT, BUT_BL_PIN, gpioModeInputPull, 1);
GPIO_PinModeSet(BUT_BR_PORT, BUT_BR_PIN, gpioModeInputPull, 1);
// Set falling edge interrupt and clear/enable it
GPIO_IntConfig(BUT_TL_PORT, BUT_TL_PIN, false, true, true);
GPIO_IntConfig(BUT_TR_PORT, BUT_TR_PIN, false, true, true);
GPIO_IntConfig(BUT_BL_PORT, BUT_BL_PIN, false, true, true);
GPIO_IntConfig(BUT_BR_PORT, BUT_BR_PIN, false, true, true);
NVIC_ClearPendingIRQ(GPIO_ODD_IRQn);
NVIC_EnableIRQ(GPIO_ODD_IRQn);
NVIC_ClearPendingIRQ(GPIO_EVEN_IRQn);
NVIC_EnableIRQ(GPIO_EVEN_IRQn);
}
/*
* Copyright (C) 2014 Julian Lewis
* @author Maciej Suminski <maciej.suminski@cern.ch>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program 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 for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @brief Button routines
*/
#ifndef BUTTONS_H
#define BUTTONS_H
#include "em_gpio.h"
// Top left button
#define BUT_TL_PORT gpioPortC
#define BUT_TL_PIN 7
// Top right button
#define BUT_TR_PORT gpioPortA
#define BUT_TR_PIN 0
// Bottom left button
#define BUT_BL_PORT gpioPortC
#define BUT_BL_PIN 6
// Bottom right button
#define BUT_BR_PORT gpioPortA
#define BUT_BR_PIN 8
/**
* @TODO desc
*/
void buttons_init(void);
#endif /* BUTTONS_H */
......@@ -114,6 +114,7 @@ INCLUDEPATHS += \
-IFreeRTOS/Source/include \
-I../common/CMSIS/Include \
-I../common/Device/EnergyMicro/EFM32GG/Include \
-I../common \
-I../common/emlib/inc \
-I../common/emdrv/sleep/inc \
......@@ -133,6 +134,8 @@ C_SRC += \
../common/emlib/src/em_rtc.c \
../common/emlib/src/em_system.c \
../common/emdrv/sleep/src/sleep.c \
../common/drivers/lcd.c \
../common/drivers/buttons.c \
FreeRTOS/Source/timers.c \
FreeRTOS/Source/tasks.c \
FreeRTOS/Source/queue.c \
......
/**************************************************************************//**
* @file
* @brief FreeRTOS Blink Demo for Energy Micro EFM32GG_STK3700 Starter Kit
* @author Energy Micro AS
* @version 3.20.3
******************************************************************************
* @section License
* <b>(C) Copyright 2013 Energy Micro AS, http://www.energymicro.com</b>
*******************************************************************************
/*
* Copyright (C) 2014 Julian Lewis
* @author Maciej Suminski <maciej.suminski@cern.ch>
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
* 4. The source and compiled code may only be used on Energy Micro "EFM32"
* microcontrollers and "EFR4" radios.
* This program 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 for more details.
*
* DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Energy Micro AS has no
* obligation to support this Software. Energy Micro AS is providing the
* Software "AS IS", with no express or implied warranties of any kind,
* including, but not limited to, any implied warranties of merchantability
* or fitness for any particular purpose or warranties against infringement
* of any proprietary rights of a third party.
*
* Energy Micro AS will not be liable for any consequential, incidental, or
* special damages, or any other relief, or for any claim by any third party,
* arising from your use of this Software.
*
*****************************************************************************/
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <stdio.h>
#include <stdlib.h>
/**
* @brief Main file.
*/
#include "FreeRTOSConfig.h"
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "semphr.h"
#include "croutine.h"
#include <FreeRTOSConfig.h>
#include <FreeRTOS.h>
#include <task.h>
#include "em_chip.h"
#include "em_gpio.h"
#include "em_cmu.h"
#include <em_chip.h>
#include <em_gpio.h>
#include <em_cmu.h>
#include <sleep.h>
#include "sleep.h"
#include <drivers/buttons.h>
#define STACK_SIZE_FOR_TASK (configMINIMAL_STACK_SIZE + 10)
#define TASK_PRIORITY (tskIDLE_PRIORITY + 1)
/* Structure with parameters for LedBlink */
typedef struct
{
/* Delay between blink of led */
portTickType delay;
/* Number of led */
int ledNo;
} TaskParams_t;
/**************************************************************************//**
* @brief Simple task which is blinking led
* @param *pParameters pointer to parameters passed to the function
*****************************************************************************/
static void LedBlink(void *pParameters)
{
TaskParams_t * pData = (TaskParams_t*) pParameters;
const portTickType delay = pData->delay;
for (;;)
{
GPIO_PinOutToggle(gpioPortE, pData->ledNo);
vTaskDelay(delay);
}
}
/**************************************************************************//**
* @brief Main function
*****************************************************************************/
int main(void)
{
int i;
/* Chip errata */
// Chip errata
CHIP_Init();
/* Enable clocks */
// Enable clocks
CMU_ClockEnable(cmuClock_HFPER, true);
CMU_ClockEnable(cmuClock_GPIO, true);
buttons_init();
GPIO_PinModeSet(gpioPortE, 11, gpioModePushPull, 0);
GPIO_PinModeSet(gpioPortE, 12, gpioModePushPull, 0);
/* Initialize SLEEP driver, no callbacks are used */
// Initialize SLEEP driver, no callbacks are used
SLEEP_Init(NULL, NULL);
#if (configSLEEP_MODE < 3)
/* do not let to sleep deeper than define */
// do not let to sleep deeper than define
SLEEP_SleepBlockBegin((SLEEP_EnergyMode_t)(configSLEEP_MODE+1));
#endif
/* Parameters value for taks*/
static TaskParams_t parametersToTask1 = { 500 / portTICK_RATE_MS, 11 };
static TaskParams_t parametersToTask2 = { 250 / portTICK_RATE_MS, 12 };
/*Create two task for blinking leds*/
xTaskCreate( LedBlink, (const signed char *) "LedBlink1", STACK_SIZE_FOR_TASK, &parametersToTask1, TASK_PRIORITY, NULL);
xTaskCreate( LedBlink, (const signed char *) "LedBlink2", STACK_SIZE_FOR_TASK, &parametersToTask2, TASK_PRIORITY, NULL);
/*Start FreeRTOS Scheduler*/
// Start FreeRTOS Scheduler
vTaskStartScheduler();
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment