SAM4L tickless implementation: Bug fix and update the demo project to exercise the fix.

This commit is contained in:
Richard Barry 2014-09-16 12:24:14 +00:00
parent 4f03f7d1bb
commit b3c040fc27
7 changed files with 715 additions and 159 deletions

View File

@ -2,7 +2,7 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
<ProjectVersion>6.1</ProjectVersion>
<ProjectVersion>6.2</ProjectVersion>
<ToolchainName>com.Atmel.ARMGCC.C</ToolchainName>
<ProjectGuid>{dfc77570-bc67-4ee7-8143-c34e75167169}</ProjectGuid>
<avrdevice>ATSAM4LC4C</avrdevice>
@ -30,6 +30,7 @@
<option id="common.services.basic.sleepmgr" value="Add" config="" content-id="Atmel.ASF" />
<option id="sam.drivers.ast" value="Add" config="" content-id="Atmel.ASF" />
<option id="sam.drivers.bpm" value="Add" config="" content-id="Atmel.ASF" />
<option id="sam.drivers.eic" value="Add" config="" content-id="Atmel.ASF" />
</options>
<configurations>
<configuration key="config.compiler.armgcc.create_aux" value="no" default="no" content-id="Atmel.ASF" />
@ -123,11 +124,13 @@
<file path="src/asf/sam/drivers/ast/ast.c" framework="" version="" source="sam\drivers\ast\ast.c" changed="False" content-id="Atmel.ASF" />
<file path="src/asf/sam/drivers/ast/ast.h" framework="" version="" source="sam\drivers\ast\ast.h" changed="False" content-id="Atmel.ASF" />
<file path="src/config/conf_ast.h" framework="" version="" source="sam\drivers\ast\module_config\conf_ast.h" changed="False" content-id="Atmel.ASF" />
<file path="src/ASF/sam/drivers/eic/eic.c" framework="" version="3.6.0" source="sam\drivers\eic\eic.c" changed="False" content-id="Atmel.ASF" />
<file path="src/ASF/sam/drivers/eic/eic.h" framework="" version="3.6.0" source="sam\drivers\eic\eic.h" changed="False" content-id="Atmel.ASF" />
</files>
<documentation help="" />
<offline-documentation help="" />
<dependencies>
<content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.5.1" />
<content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.6.0" />
</dependencies>
</framework-data>
</AsfFrameworkConfig>
@ -136,7 +139,7 @@
<com_atmel_avrdbg_tool_samice>
<ToolType>com.atmel.avrdbg.tool.samice</ToolType>
<ToolName>J-Link</ToolName>
<ToolNumber>000480008423</ToolNumber>
<ToolNumber>480008423</ToolNumber>
<Channel>
<host>127.0.0.1</host>
<port>1882</port>
@ -154,7 +157,7 @@
<JtagDevicesAfter>0</JtagDevicesAfter>
<JtagInstrBitsBefore>0</JtagInstrBitsBefore>
<JtagInstrBitsAfter>0</JtagInstrBitsAfter>
<SwdClock>32000</SwdClock>
<SwdClock>5950000</SwdClock>
</InterfaceProperties>
</ToolOptions>
</com_atmel_avrdbg_tool_samice>
@ -202,6 +205,7 @@
<Value>../src</Value>
<Value>../src/config</Value>
<Value>../src/asf/sam/drivers/ast</Value>
<Value>../src/ASF/sam/drivers/eic</Value>
</ListValues>
</armgcc.compiler.directories.IncludePaths>
<armgcc.compiler.optimization.level>Optimize for size (-Os)</armgcc.compiler.optimization.level>
@ -226,30 +230,7 @@
<armgcc.assembler.general.AssemblerFlags>-D__ATSAM4LC4C__ -D__ATSAM4LC4C__ -D__ATSAM4LC4C__ -D__ATSAM4LC4C__ -D__ATSAM4LC4C__ -D__ATSAM4LC4C__</armgcc.assembler.general.AssemblerFlags>
<armgcc.assembler.general.IncludePaths>
<ListValues>
<Value>../src/asf/sam/utils/preprocessor</Value>
<Value>../src/asf/sam/drivers/lcdca/example/sam4lc4c_sam4l_ek</Value>
<Value>../src/asf/sam/utils/cmsis/sam4l/include</Value>
<Value>../src/asf/common/services/sleepmgr</Value>
<Value>../src/asf/sam/utils</Value>
<Value>../src/asf/common/boards</Value>
<Value>../src/asf/sam/drivers/flashcalw</Value>
<Value>../src/asf/sam/boards</Value>
<Value>../src/asf/common/services/clock</Value>
<Value>../src/asf/sam/drivers/bpm</Value>
<Value>../src/asf/thirdparty/CMSIS/Include</Value>
<Value>../src/asf/sam/boards/sam4l_ek</Value>
<Value>../src/asf/sam/utils/header_files</Value>
<Value>../src/asf/common/services/ioport</Value>
<Value>../src/asf/sam/utils/cmsis/sam4l/source/templates</Value>
<Value>../src/asf/common/utils</Value>
<Value>../src/asf/thirdparty/CMSIS/Lib/GCC</Value>
<Value>../src</Value>
<Value>../src/config</Value>
<Value>../src/asf/sam/drivers/ast</Value>
<Value>%24(ToolchainDir)\..\..\CMSIS_Atmel</Value>
<Value>%24(ToolchainDir)\..\..\CMSIS_Atmel\CMSIS\Include</Value>
<Value>%24(ToolchainDir)\..\..\CMSIS_Atmel\Device\ATMEL</Value>
<Value>%24(ToolchainDir)\..\..\CMSIS_Atmel\Device\ATMEL\sam4l\include</Value>
<Value>../src/ASF/sam/drivers/eic</Value>
</ListValues>
</armgcc.assembler.general.IncludePaths>
<armgcc.preprocessingassembler.general.AssemblerFlags>-DARM_MATH_CM4=true -DBOARD=SAM4L_EK -D__ATSAM4LC4C__ -D__ATSAM4LC4C__ -D__ATSAM4LC4C__ -D__ATSAM4LC4C__ -D__ATSAM4LC4C__ -D__ATSAM4LC4C__ -D__ATSAM4LC4C__</armgcc.preprocessingassembler.general.AssemblerFlags>
@ -279,6 +260,7 @@
<Value>%24(ToolchainDir)\..\..\CMSIS_Atmel\CMSIS\Include</Value>
<Value>%24(ToolchainDir)\..\..\CMSIS_Atmel\Device\ATMEL</Value>
<Value>%24(ToolchainDir)\..\..\CMSIS_Atmel\Device\ATMEL\sam4l\include</Value>
<Value>../src/ASF/sam/drivers/eic</Value>
</ListValues>
</armgcc.preprocessingassembler.general.IncludePaths>
</ArmGcc>
@ -326,6 +308,7 @@
<Value>../../../Source/include</Value>
<Value>../../../Source/portable/GCC/ARM_CM3</Value>
<Value>../../Common/include</Value>
<Value>../src/ASF/sam/drivers/eic</Value>
</ListValues>
</armgcc.compiler.directories.IncludePaths>
<armgcc.compiler.optimization.OtherFlags>-fdata-sections</armgcc.compiler.optimization.OtherFlags>
@ -349,30 +332,7 @@
<armgcc.assembler.general.AssemblerFlags>-D__ATSAM4LC4C__ -D__ATSAM4LC4C__ -D__ATSAM4LC4C__ -D__ATSAM4LC4C__ -D__ATSAM4LC4C__ -D__ATSAM4LC4C__</armgcc.assembler.general.AssemblerFlags>
<armgcc.assembler.general.IncludePaths>
<ListValues>
<Value>../src/asf/sam/utils/preprocessor</Value>
<Value>../src/asf/sam/drivers/lcdca/example/sam4lc4c_sam4l_ek</Value>
<Value>../src/asf/sam/utils/cmsis/sam4l/include</Value>
<Value>../src/asf/common/services/sleepmgr</Value>
<Value>../src/asf/sam/utils</Value>
<Value>../src/asf/common/boards</Value>
<Value>../src/asf/sam/drivers/flashcalw</Value>
<Value>../src/asf/sam/boards</Value>
<Value>../src/asf/common/services/clock</Value>
<Value>../src/asf/sam/drivers/bpm</Value>
<Value>../src/asf/thirdparty/CMSIS/Include</Value>
<Value>../src/asf/sam/boards/sam4l_ek</Value>
<Value>../src/asf/sam/utils/header_files</Value>
<Value>../src/asf/common/services/ioport</Value>
<Value>../src/asf/sam/utils/cmsis/sam4l/source/templates</Value>
<Value>../src/asf/common/utils</Value>
<Value>../src/asf/thirdparty/CMSIS/Lib/GCC</Value>
<Value>../src</Value>
<Value>../src/config</Value>
<Value>../src/asf/sam/drivers/ast</Value>
<Value>%24(ToolchainDir)\..\..\CMSIS_Atmel</Value>
<Value>%24(ToolchainDir)\..\..\CMSIS_Atmel\CMSIS\Include</Value>
<Value>%24(ToolchainDir)\..\..\CMSIS_Atmel\Device\ATMEL</Value>
<Value>%24(ToolchainDir)\..\..\CMSIS_Atmel\Device\ATMEL\sam4l\include</Value>
<Value>../src/ASF/sam/drivers/eic</Value>
</ListValues>
</armgcc.assembler.general.IncludePaths>
<armgcc.assembler.debugging.DebugLevel>Default (-g)</armgcc.assembler.debugging.DebugLevel>
@ -403,6 +363,7 @@
<Value>%24(ToolchainDir)\..\..\CMSIS_Atmel\CMSIS\Include</Value>
<Value>%24(ToolchainDir)\..\..\CMSIS_Atmel\Device\ATMEL</Value>
<Value>%24(ToolchainDir)\..\..\CMSIS_Atmel\Device\ATMEL\sam4l\include</Value>
<Value>../src/ASF/sam/drivers/eic</Value>
</ListValues>
</armgcc.preprocessingassembler.general.IncludePaths>
<armgcc.preprocessingassembler.debugging.DebugLevel>Default (-Wa,-g)</armgcc.preprocessingassembler.debugging.DebugLevel>
@ -429,6 +390,7 @@
<Folder Include="src\asf\sam\drivers\" />
<Folder Include="src\asf\sam\drivers\ast\" />
<Folder Include="src\asf\sam\drivers\bpm\" />
<Folder Include="src\asf\sam\drivers\eic\" />
<Folder Include="src\asf\sam\drivers\flashcalw\" />
<Folder Include="src\asf\sam\utils\" />
<Folder Include="src\asf\sam\utils\cmsis\" />
@ -819,6 +781,12 @@
<SubType>compile</SubType>
<Link>src\Common-Demo-Source\semtest.c</Link>
</Compile>
<Compile Include="src\asf\sam\drivers\eic\eic.c">
<SubType>compile</SubType>
</Compile>
<None Include="src\asf\sam\drivers\eic\eic.h">
<SubType>compile</SubType>
</None>
<Compile Include="src\config\FreeRTOSConfig.h">
<SubType>compile</SubType>
</Compile>

View File

@ -377,6 +377,7 @@ enum sleepmgr_mode xSleepMode;
ulAlarmValue = ulAlarmValueForOneTick;
ulCompleteTickPeriods++;
}
ast_write_counter_value( AST, 0 );
ast_write_alarm0_value( AST, ulAlarmValue );
}

View File

@ -59,6 +59,9 @@
#include <compiler.h>
#include <status_codes.h>
// From module: EIC - External Interrupt Controller
#include <eic.h>
// From module: FLASHCALW Controller Software Driver
#include <flashcalw.h>
@ -68,7 +71,7 @@
// From module: IOPORT - General purpose I/O service
#include <ioport.h>
// From module: Interrupt management - SAM3 implementation
// From module: Interrupt management - SAM implementation
#include <interrupt.h>
// From module: Part identification macros

View File

@ -0,0 +1,244 @@
/**
* \file
*
* \brief EIC driver for SAM
*
* Copyright (c) 2012 Atmel Corporation. All rights reserved.
*
* \asf_license_start
*
* \page License
*
* 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 Atmel may not be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* 4. This software may only be redistributed and used in connection with an
* Atmel microcontroller product.
*
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
*
* \asf_license_stop
*
*/
#include "eic.h"
#include "sysclk.h"
#include "sleepmgr.h"
/// @cond 0
/**INDENT-OFF**/
#ifdef __cplusplus
extern "C" {
#endif
/**INDENT-ON**/
/// @endcond
/**
* \defgroup sam_drivers_eic_group External Interrupt Controller(EIC)
*
* See \ref sam_eic_quickstart.
*
* EIC allows pins to be configured as external interrupts.
*
* @{
*/
/**
* \internal
* \brief EIC callback function pointer array
*/
eic_callback_t eic_callback_pointer[EIC_NUMBER_OF_LINES];
/**
* \brief Write the EIC hardware with specified configuration value.
*
* \param eic Base address of the EIC module
* \param eic_line_conf Configuration parameters of the EIC module
* (see \ref eic_line_config)
* \param line_number Number of line to config
*/
void eic_line_set_config(Eic *eic, uint8_t line_number,
struct eic_line_config *eic_line_conf)
{
/* Set up mode level */
eic->EIC_MODE = (eic_line_conf->eic_mode == EIC_MODE_LEVEL_TRIGGERED)
? (eic->EIC_MODE | (1 << line_number))
: (eic->EIC_MODE & ~(1 << line_number));
/* Set up edge type */
eic->EIC_EDGE = (eic_line_conf->eic_edge == EIC_EDGE_RISING_EDGE)
? (eic->EIC_EDGE | (1 << line_number))
: (eic->EIC_EDGE & ~(1 << line_number));
/* Set up level */
eic->EIC_LEVEL = (eic_line_conf->eic_level == EIC_LEVEL_HIGH_LEVEL)
? (eic->EIC_LEVEL | (1 << line_number))
: (eic->EIC_LEVEL & ~(1 << line_number));
/* Set up if filter is used */
eic->EIC_FILTER = (eic_line_conf->eic_filter == EIC_FILTER_ENABLED)
? (eic->EIC_FILTER | (1 << line_number))
: (eic->EIC_FILTER & ~(1 << line_number));
/* Set up which mode is used : asynchronous mode/ synchronous mode */
eic->EIC_ASYNC = (eic_line_conf->eic_async == EIC_ASYNCH_MODE)
? (eic->EIC_ASYNC | (1 << line_number))
: (eic->EIC_ASYNC & ~(1 << line_number));
}
/**
* \brief Disable the EIC module
*
* \param eic Base address of the EIC module
*/
void eic_disable(Eic *eic)
{
sysclk_disable_peripheral_clock(eic);
sleepmgr_unlock_mode(SLEEPMGR_BACKUP);
}
/**
* \brief Enable the EIC module
*
* \param eic Base address of the EIC module
*/
void eic_enable(Eic *eic)
{
sysclk_enable_peripheral_clock(eic);
sleepmgr_lock_mode(SLEEPMGR_BACKUP);
}
/**
* \brief Set callback for given EIC line
*
* \param eic Base address of the EIC module
* \param line_number Number of line.
* \param callback callback function pointer.
* \param irq_line interrupt line.
* \param irq_level interrupt level.
*/
void eic_line_set_callback(Eic *eic, uint8_t line_number,
eic_callback_t callback, uint8_t irq_line, uint8_t irq_level)
{
eic_callback_pointer[line_number] = callback;
irq_register_handler((IRQn_Type)irq_line, irq_level);
eic_line_enable_interrupt(eic, line_number);
}
/**
* \internal
* \brief Common EIC line interrupt handler
*
* The optional callback used by the interrupt handler is set by the
* eic_line_set_callback() function.
*
* \param line_number EIC linel number to handle interrupt for
*/
static void eic_line_interrupt(uint8_t line_number)
{
if (eic_callback_pointer[line_number]) {
eic_callback_pointer[line_number]();
} else {
Assert(false); /* Catch unexpected interrupt */
}
}
/**
* \brief Interrupt handler for EIC NMI.
*/
void NMI_Handler(void)
{
eic_line_interrupt(0);
}
/**
* \brief Interrupt handler for EIC line 1.
*/
void EIC_1_Handler(void)
{
eic_line_interrupt(1);
}
/**
* \brief Interrupt handler for EIC line 2.
*/
void EIC_2_Handler(void)
{
eic_line_interrupt(2);
}
/**
* \brief Interrupt handler for EIC line 3.
*/
void EIC_3_Handler(void)
{
eic_line_interrupt(3);
}
/**
* \brief Interrupt handler for EIC line 4.
*/
void EIC_4_Handler(void)
{
eic_line_interrupt(4);
}
/**
* \brief Interrupt handler for EIC line 5.
*/
void EIC_5_Handler(void)
{
eic_line_interrupt(5);
}
/**
* \brief Interrupt handler for EIC line 6.
*/
void EIC_6_Handler(void)
{
eic_line_interrupt(6);
}
/**
* \brief Interrupt handler for EIC line 7.
*/
void EIC_7_Handler(void)
{
eic_line_interrupt(7);
}
/**
* \brief Interrupt handler for EIC line 8.
*/
void EIC_8_Handler(void)
{
eic_line_interrupt(8);
}
//@}
/// @cond 0
/**INDENT-OFF**/
#ifdef __cplusplus
}
#endif
/**INDENT-ON**/
/// @endcond

View File

@ -0,0 +1,310 @@
/**
* \file
*
* \brief EIC driver for SAM
*
* Copyright (c) 2012 Atmel Corporation. All rights reserved.
*
* \asf_license_start
*
* \page License
*
* 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 Atmel may not be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* 4. This software may only be redistributed and used in connection with an
* Atmel microcontroller product.
*
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
*
* \asf_license_stop
*
*/
#ifndef EIC_H_INCLUDED
#define EIC_H_INCLUDED
#include "compiler.h"
/// @cond 0
/**INDENT-OFF**/
#ifdef __cplusplus
extern "C" {
#endif
/**INDENT-ON**/
/// @endcond
/** Number of available EIC lines, device dependent. */
#if SAM4L
#define EIC_NUMBER_OF_LINES 9
#else
#error 'This device does not support EIC driver'
#endif
/** \name External Interrupt lines */
/* @{ */
#define EXT_NMI 0
#define EXT_INT1 1
#define EXT_INT2 2
#define EXT_INT3 3
#define EXT_INT4 4
#define EXT_INT5 5
#define EXT_INT6 6
#define EXT_INT7 7
#define EXT_INT8 8
/* @} */
/** \name Mode Trigger Options */
/* @{ */
#define EIC_MODE_EDGE_TRIGGERED 0
#define EIC_MODE_LEVEL_TRIGGERED 1
/* @{ */
/** \name Edge level Options */
/* @{ */
#define EIC_EDGE_FALLING_EDGE 0
#define EIC_EDGE_RISING_EDGE 1
/* @{ */
/** \name Level Options */
/* @{ */
#define EIC_LEVEL_LOW_LEVEL 0
#define EIC_LEVEL_HIGH_LEVEL 1
/* @{ */
/** \name Filter Options */
/* @{ */
#define EIC_FILTER_ENABLED 1
#define EIC_FILTER_DISABLED 0
/* @{ */
/** \name Synch Mode Options */
/* @{ */
#define EIC_SYNCH_MODE 0
#define EIC_ASYNCH_MODE 1
/* @{ */
/** Configuration parameters of the EIC module. */
struct eic_line_config {
/** Mode : \ref EIC_MODE_EDGE_TRIGGERED or \ref EIC_MODE_LEVEL_TRIGGERED */
uint8_t eic_mode;
/** Edge : \ref EIC_EDGE_FALLING_EDGE or \ref EIC_EDGE_RISING_EDGE */
uint8_t eic_edge;
/** Level : \ref EIC_LEVEL_LOW_LEVEL or \ref EIC_LEVEL_HIGH_LEVEL */
uint8_t eic_level;
/** Filter: \ref EIC_FILTER_DISABLED or \ref EIC_FILTER_ENABLED */
uint8_t eic_filter;
/** Async: \ref EIC_ASYNCH_MODEmode or \ref EIC_SYNCH_MODE */
uint8_t eic_async;
};
typedef void (*eic_callback_t)(void);
void eic_disable(Eic *eic);
void eic_enable(Eic *eic);
void eic_line_set_config(Eic *eic, uint8_t line_number,
struct eic_line_config *eic_line_conf);
void eic_line_set_callback(Eic *eic, uint8_t line_number,
eic_callback_t callback, uint8_t irq_line, uint8_t irq_level);
/**
* \brief Enable the external interrupt on specified line.
*
* \param eic Base address of the EIC module
* \param line_number The number of enabled line
*/
static inline void eic_line_enable(Eic *eic, uint8_t line_number)
{
eic->EIC_EN = 1 << line_number;
}
/**
* \brief Disable the external interrupt on specified line.
*
* \param eic Base address of the EIC module
* \param line_number The number of disabled line
*/
static inline void eic_line_disable(Eic *eic, uint8_t line_number)
{
eic->EIC_DIS = 1 << line_number;
}
/**
* \brief Tells whether an EIC line is enabled.
*
* \param eic Base address of the EIC module
* \param line_number Line number to test
*
* \return Whether an EIC line is enabled.
*/
static inline bool eic_line_is_enabled(Eic *eic, uint8_t line_number)
{
return (eic->EIC_CTRL & (1 << line_number)) != 0;
}
/**
* \brief Enables the external interrupt from specified pin propagate from
* EIC to interrupt controller.
*
* \param eic Base address of the EIC (i.e. EIC).
* \param line_number Line number to test
*/
static inline void eic_line_enable_interrupt(Eic *eic,
uint8_t line_number)
{
eic->EIC_IER = 1 << line_number;
}
/**
* \brief Disables the external interrupt from specified pin propagate from
* EIC to interrupt controller.
*
* \param eic Base address of the EIC (i.e. EIC).
* \param line_number Line number to test
*/
static inline void eic_line_disable_interrupt(Eic *eic,
uint8_t line_number)
{
eic->EIC_IDR = 1 << line_number;
eic->EIC_IMR;
}
/**
* \brief Tells whether an EIC interrupt line is enabled.
*
* \param eic Base address of the EIC module
* \param line_number Line number to test
*
* \return Whether an EIC interrupt line is enabled.
*/
static inline bool eic_line_interrupt_is_enabled(Eic *eic,
uint8_t line_number)
{
return (eic->EIC_IMR & (1 << line_number)) != 0;
}
/**
* \brief Clear the interrupt flag of specified pin.
* Call this function once you've handled the interrupt.
*
* \param eic Base address of the EIC (i.e. EIC).
* \param line_number Line number to test
*/
static inline void eic_line_clear_interrupt(Eic *eic,
uint8_t line_number)
{
eic->EIC_ICR = 1 << line_number;
eic->EIC_ISR;
}
/**
* \brief Tells whether an EIC interrupt line is pending.
*
* \param eic Base address of the EIC module
* \param line_number Line number to test
*
* \return Whether an EIC interrupt line is pending.
*/
static inline bool eic_line_interrupt_is_pending(Eic *eic,
uint8_t line_number)
{
return (eic->EIC_ISR & (1 << line_number)) != 0;
}
/// @cond 0
/**INDENT-OFF**/
#ifdef __cplusplus
}
#endif
/**INDENT-ON**/
/// @endcond
/**
* \page sam_eic_quickstart Quickstart guide for SAM EIC driver
*
* This is the quickstart guide for the \ref eic_group "SAM EIC driver",
* with step-by-step instructions on how to configure and use the driver in a
* selection of use cases.
*
* The use cases contain several code fragments. The code fragments in the
* steps for setup can be copied into a custom initialization function, while
* the steps for usage can be copied into, e.g., the main application function.
*
* \section eic_basic_use_case Basic use case
* In this basic use case, the EIC module and single line are configured for:
* - Falling edge trigger and async mode
* - Interrupt-based handling
* - EIC_LINE_5 as input
*
* \subsection sam_eic_quickstart_prereq Prerequisites
* -# \ref sysclk_group "System Clock Management (Sysclock)"
*
* \section eic_basic_use_case_setup Setup steps
* \subsection eic_basic_use_case_setup_code Example code
* Add to application C-file:
* \code
* void eic_callback(void)
* {
* // Check if EIC push button line interrupt line is pending
* if (eic_line_interrupt_is_pending(EIC, GPIO_PUSH_BUTTON_EIC_LINE)) {
* eic_line_clear_interrupt(EIC, GPIO_PUSH_BUTTON_EIC_LINE);
* bToggle = 1;
* }
* }
* void eic_setup(void)
* {
* eic_enable(EIC);
*
* eic_line_set_config(EIC, GPIO_PUSH_BUTTON_EIC_LINE, &eic_line_conf);
*
* eic_line_set_callback(EIC, GPIO_PUSH_BUTTON_EIC_LINE, set_toggle_flag, EIC_5_IRQn, 1);
*
* eic_line_enable(EIC, GPIO_PUSH_BUTTON_EIC_LINE);
* }
* \endcode
*
* \subsection eic_basic_use_case_setup_flow Workflow
* -# Define the interrupt callback function in the application:
* - \code
* void eic_callback(void)
* {
* // Check if EIC push button line interrupt line is pending
* if (eic_line_interrupt_is_pending(EIC, GPIO_PUSH_BUTTON_EIC_LINE)) {
* eic_line_clear_interrupt(EIC, GPIO_PUSH_BUTTON_EIC_LINE);
* bToggle = 1;
* }
* }
* \endcode
* -# Enable EIC module:
* - \code eic_enable(EIC); \endcode
* - \note Including enable module clock and lock sleep mode.
* -# Configure EIC line with specified mode:
* - \code aeic_line_set_config(EIC, GPIO_PUSH_BUTTON_EIC_LINE, &eic_line_conf); \endcode
* -# Set the EIC callback function and enable EIC interrupt.
* - \code eic_line_set_callback(EIC, GPIO_PUSH_BUTTON_EIC_LINE, set_toggle_flag, EIC_5_IRQn, 1); \endcode
* -# Enable EIC line:
* - \code eic_line_enable(EIC, GPIO_PUSH_BUTTON_EIC_LINE); \endcode
*/
#endif // EIC_H_INCLUDED

View File

@ -50,4 +50,6 @@
/** Enable LCD backlight */
#define CONF_BOARD_BL
#define CONF_BOARD_EIC
#endif /* CONF_BOARD_H_INCLUDED */

View File

@ -112,6 +112,10 @@ void vApplicationIdleHook( void );
void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );
void vApplicationTickHook( void );
/* A handler for a button interrupt. The button's only purpose is to bring the
CPU out of sleep mode early. */
static void prvButtonISR( void );
/*-----------------------------------------------------------*/
/* See the documentation page for this demo on the FreeRTOS.org web site for
@ -137,9 +141,33 @@ int main( void )
}
/*-----------------------------------------------------------*/
static void prvButtonISR( void )
{
/* The button doesn't do anything other than providing a means for brining
the MCU out of sleep mode early. */
if( eic_line_interrupt_is_pending( EIC, GPIO_PUSH_BUTTON_EIC_LINE ) )
{
eic_line_clear_interrupt( EIC, GPIO_PUSH_BUTTON_EIC_LINE );
}
}
/*-----------------------------------------------------------*/
static void prvSetupHardware( void )
{
extern void SystemCoreClockUpdate( void );
struct eic_line_config xEICLineConfiguration;
/* Configure the external interrupt controller so button pushes can
generate interrupts. */
xEICLineConfiguration.eic_mode = EIC_MODE_EDGE_TRIGGERED;
xEICLineConfiguration.eic_edge = EIC_EDGE_FALLING_EDGE;
xEICLineConfiguration.eic_level = EIC_LEVEL_LOW_LEVEL;
xEICLineConfiguration.eic_filter = EIC_FILTER_DISABLED;
xEICLineConfiguration.eic_async = EIC_ASYNCH_MODE;
eic_enable( EIC );
eic_line_set_config( EIC, GPIO_PUSH_BUTTON_EIC_LINE, &xEICLineConfiguration );
eic_line_set_callback( EIC, GPIO_PUSH_BUTTON_EIC_LINE, prvButtonISR, EIC_5_IRQn, 0 );
eic_line_enable( EIC, GPIO_PUSH_BUTTON_EIC_LINE );
/* ASF function to setup clocking. */
sysclk_init();