Commit 1552bf6e authored by Projects's avatar Projects

Added an example application (button tester).

parent 2266bb33
......@@ -25,6 +25,7 @@
*/
#include "buttons.h"
#include "irq_dispatcher.h"
void GPIO_EVEN_IRQHandler(void)
{
......@@ -35,9 +36,8 @@ void GPIO_EVEN_IRQHandler(void)
// Clean only even interrupts
GPIO_IntClear(iflags);
GPIO_PinOutToggle(gpioPortE, 12);
//GPIOINT_IRQDispatcher(iflags);
gpio_irq_dispatcher(iflags);
}
void GPIO_ODD_IRQHandler(void)
......@@ -47,16 +47,16 @@ void GPIO_ODD_IRQHandler(void)
// Get all odd interrupts
iflags = GPIO_IntGetEnabled() & 0x0000AAAA;
// Clean only even interrupts
// Clean only odd interrupts
GPIO_IntClear(iflags);
GPIO_PinOutToggle(gpioPortE, 11);
//GPIOINT_IRQDispatcher(iflags);
gpio_irq_dispatcher(iflags);
}
void buttons_init(void)
{
// Configure interrupt pin as input with pull-up
// TODO there are external pull-ups - we should disable either int or ext
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);
......
......@@ -10,7 +10,7 @@
####################################################################
DEVICE = EFM32GG330F1024
PROJECTNAME = freertos_blink
PROJECTNAME = freertos
# Name of interface configuration file used by OpenOCD
OOCD_IFACE ?= stlink-v2-1
......@@ -133,9 +133,17 @@ C_SRC += \
../common/emlib/src/em_rmu.c \
../common/emlib/src/em_rtc.c \
../common/emlib/src/em_system.c \
../common/emlib/src/em_usart.c \
../common/emdrv/sleep/src/sleep.c \
../common/drivers/lcd.c \
../common/drivers/buttons.c \
../common/gfx/font_helv11.c \
../common/gfx/font_helv17.c \
../common/gfx/font_helv17b.c \
../common/gfx/font_xm4x5.c \
../common/gfx/font_xm4x6.c \
../common/gfx/graphics.c \
../common/udelay.c \
FreeRTOS/Source/timers.c \
FreeRTOS/Source/tasks.c \
FreeRTOS/Source/queue.c \
......@@ -143,7 +151,11 @@ FreeRTOS/Source/list.c \
FreeRTOS/Source/croutine.c \
FreeRTOS/Source/portable/MemMang/heap_1.c \
FreeRTOS/Source/portable/GCC/ARM_CM3/port.c \
src/apps/application.c \
src/apps/clock.c \
src/apps/menu.c \
src/main.c \
src/irq_dispatcher.c \
src/low_power_tick_management.c
s_SRC +=
......
/*
* 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
*/
/**
* User application data structures and routines.
*/
#include "application.h"
#include "event.h"
#include <FreeRTOSConfig.h>
///> Capacity of event queue
#define APP_QUEUE_LEN 16
///> Shared application stack size
#define APP_STACK_SIZE (configMINIMAL_STACK_SIZE)
///> Prioriuty of application task
#define APP_PRIORITY (tskIDLE_PRIORITY + 1)
xTaskHandle appTask;
xQueueHandle appQueue;
void startMain(Application* app) {
appQueue = xQueueCreate(APP_QUEUE_LEN, sizeof(Event));
if(!appQueue) {
// TODO oops..
}
xTaskCreate(app->main, (const signed char*)app->name, APP_STACK_SIZE, NULL,
APP_PRIORITY, &appTask);
if(!appTask) {
// TODO oops..
}
}
/*
* 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
*/
/**
* User application data structures and routines.
*/
#ifndef APPLICATION_H
#define APPLICATION_H
#include <FreeRTOS.h>
#include <task.h>
#include <queue.h>
///> Shared application task handle
extern xTaskHandle appTask;
///> Shared application event queue
extern xQueueHandle appQueue;
/**
* @brief An application entry, used by the menu application.
*/
typedef struct {
///> Application name
const char* name;
// TODO const char* icon;
/**
* @brief Main application routine.
* @params Optional parameters, dependendent on application.
*/
void (*main)(void* params);
} Application;
/**
* @brief Initializes the application task and event queue.
* After that runs one as the main application.
* @param app is the application to be run as the main one.
*/
void startMain(Application* app);
#endif /* APPLICATION_H */
/*
* 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
*/
/**
* Clock application.
*/
#include "clock.h"
#include "event.h"
#include <gfx/graphics.h>
#include <em_gpio.h> // TODO remove in final version
void clock_main(void* params) {
Event evt;
while( 1 ) {
if(xQueueReceive(appQueue, &evt, 0)) {
switch(evt.type) {
case BUTTON_PRESSED:
if(evt.data.button == BUT_TL)
GPIO_PinOutToggle(gpioPortE, 11);
break;
default: // suppress warnings
break;
}
}
}
}
Application clock = {
.name = "Clock",
.main = clock_main
};
/*
* 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
*/
/**
* Clock application.
*/
#include "application.h"
extern Application clock;
/*
* 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
*/
/**
* Clock application.
*/
#include "clock.h"
#include "event.h"
#include <gfx/graphics.h>
#include <drivers/lcd.h>
void clock_main(void* params) {
Event evt;
while( 1 ) {
if(xQueueReceive(appQueue, &evt, 0)) {
switch(evt.type) {
case BUTTON_PRESSED:
lcd_clear();
switch(evt.data.button)
{
case BUT_TL:
text(&font_helv11, 0, 0, "top left button");
break;
case BUT_TR:
text(&font_helv11, 0, 0, "top right button");
break;
case BUT_BL:
text(&font_helv11, 0, 0, "bottom left button");
break;
case BUT_BR:
text(&font_helv11, 0, 0, "botton right button");
break;
}
lcd_update();
break;
default: // suppress warnings
break;
}
}
}
}
Application clock = {
.name = "Clock",
.main = clock_main
};
/*
* 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
*/
/**
* Clock application.
*/
#include "application.h"
extern Application clock;
/*
* 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 Application event definitions.
*/
/**
* Possible event types.
*/
typedef enum {
BUTTON_PRESSED,
SENSOR
} EV_TYPE;
/**
* Button markings.
*/
typedef enum {
BUT_TL, // top left
BUT_TR, // top right
BUT_BL, // bottom left
BUT_BR // bottom right
} BUTTON;
/**
* Structure describing events received by applications.
*/
typedef struct {
///> Determines the source of event
EV_TYPE type;
///> Data dependent on the event type
union {
BUTTON button;
} data;
} Event;
/*
* 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
*/
/**
* Menu application.
*/
#include "menu.h"
#include "clock.h"
#include "event.h"
#include <gfx/graphics.h>
void menu_main(void* params) {
Event evt;
while( 1 ) {
// Run the clock application as the default one
clock.main(NULL);
// Once it is deactivated - display the menu
// TODO
if(xQueueReceive(appQueue, &evt, 0)) {
switch(evt.type) {
default: // suppress warnings
break;
}
}
}
}
Application menu = {
.name = "Menu",
.main = menu_main
};
/*
* 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
*/
/**
* Menu application.
*/
#include "application.h"
extern Application menu;
/*
* 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
*/
/**
* Interrupt service routines dispatchers. An abstraction layer between
* hardware interrupts and operating system.
*/
#include "irq_dispatcher.h"
#include <apps/application.h>
#include <apps/event.h>
void gpio_irq_dispatcher(uint32_t flags)
{
// We have not woken a task at the start of the ISR
portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
// Fill the event data
Event evt;
evt.type = BUTTON_PRESSED;
switch(flags)
{
case 0x01: evt.data.button = BUT_BL; break;
case 0x40: evt.data.button = BUT_TR; break;
case 0x80: evt.data.button = BUT_BR; break;
case 0x0100: evt.data.button = BUT_TL; break;
// Unexpected event, do not send it
default: return;
}
// Post the byte to the back of the queue
xQueueSendToBackFromISR( appQueue, &evt, &xHigherPriorityTaskWoken );
/* Did sending to the queue unblock a higher priority task? */
/*if( xHigherPriorityTaskWoken )*/
/*{*/
/*[> Actual macro used here is port specific. <]*/
/*[>taskYIELD_FROM_ISR();<]*/
/*}*/
}
/*
* 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
*/
/**
* Interrupt service routines dispatchers. An abstraction layer between
* hardware interrupts and operating system.
*/
#ifndef IRQ_DISPATCHER_H
#define IRQ_DISPATCHER_H
#include <stdint.h>
/**
* @brief GPIO interrupt requests dispatcher.
*/
void gpio_irq_dispatcher(uint32_t flags);
#endif /* IRQ_DISPATCHER_H */
......@@ -24,19 +24,14 @@
* @brief Main file.
*/
#include <FreeRTOSConfig.h>
#include <FreeRTOS.h>
#include <task.h>
#include <em_chip.h>
#include <em_gpio.h>
#include <em_cmu.h>
#include <sleep.h>
#include <apps/menu.h>
#include <drivers/buttons.h>
#define STACK_SIZE_FOR_TASK (configMINIMAL_STACK_SIZE + 10)
#define TASK_PRIORITY (tskIDLE_PRIORITY + 1)
#include <drivers/lcd.h>
int main(void)
{
......@@ -48,6 +43,7 @@ int main(void)
CMU_ClockEnable(cmuClock_GPIO, true);
buttons_init();
lcd_init();
GPIO_PinModeSet(gpioPortE, 11, gpioModePushPull, 0);
GPIO_PinModeSet(gpioPortE, 12, gpioModePushPull, 0);
......@@ -59,6 +55,8 @@ int main(void)
SLEEP_SleepBlockBegin((SLEEP_EnergyMode_t)(configSLEEP_MODE+1));
#endif
startMain(&menu);
// Start FreeRTOS Scheduler
vTaskStartScheduler();
......
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