2009-11-28 21:05:36 +01:00
|
|
|
/**
|
2009-11-29 11:03:08 +01:00
|
|
|
******************************************************************************
|
2010-07-16 21:53:35 +02:00
|
|
|
* @addtogroup PIOS PIOS Core hardware abstraction layer
|
|
|
|
* @{
|
|
|
|
* @addtogroup PIOS_IRQ IRQ Setup Functions
|
|
|
|
* @brief STM32 Hardware code to enable and disable interrupts
|
|
|
|
* @{
|
2009-11-28 21:05:36 +01:00
|
|
|
*
|
2009-11-29 11:03:08 +01:00
|
|
|
* @file pios_irq.c
|
2010-01-31 18:56:54 +01:00
|
|
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
|
|
|
* Parts by Thorsten Klose (tk@midibox.org) (tk@midibox.org)
|
2009-11-29 11:03:08 +01:00
|
|
|
* @brief IRQ Enable/Disable routines
|
|
|
|
* @see The GNU Public License (GPL) Version 3
|
2009-11-29 13:38:42 +01:00
|
|
|
*
|
2009-11-29 11:03:08 +01:00
|
|
|
*****************************************************************************/
|
2009-11-28 21:05:36 +01:00
|
|
|
/*
|
|
|
|
* 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 3 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, write to the Free Software Foundation, Inc.,
|
|
|
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
2009-11-29 06:16:47 +01:00
|
|
|
|
2009-11-28 21:05:36 +01:00
|
|
|
/* Project Includes */
|
|
|
|
#include "pios.h"
|
|
|
|
|
2010-03-11 13:38:51 +01:00
|
|
|
#if defined(PIOS_INCLUDE_IRQ)
|
2010-02-28 07:47:49 +01:00
|
|
|
|
2009-11-29 06:16:47 +01:00
|
|
|
|
|
|
|
/* Private Function Prototypes */
|
|
|
|
|
|
|
|
|
2009-11-28 21:05:36 +01:00
|
|
|
/* Local Variables */
|
|
|
|
/* The nesting counter ensures, that interrupts won't be enabled so long nested functions disable them */
|
2009-12-24 04:09:37 +01:00
|
|
|
static uint32_t nested_ctr;
|
2009-11-28 21:05:36 +01:00
|
|
|
|
|
|
|
/* Stored priority level before IRQ has been disabled (important for co-existence with vPortEnterCritical) */
|
2009-12-24 04:09:37 +01:00
|
|
|
static uint32_t prev_primask;
|
2009-11-28 21:05:36 +01:00
|
|
|
|
2009-11-29 06:16:47 +01:00
|
|
|
|
2009-11-29 15:21:50 +01:00
|
|
|
/**
|
|
|
|
* Disables all interrupts (nested)
|
|
|
|
* \return < 0 On errors
|
|
|
|
*/
|
2009-12-24 04:09:37 +01:00
|
|
|
int32_t PIOS_IRQ_Disable(void)
|
2009-11-28 21:05:36 +01:00
|
|
|
{
|
|
|
|
/* Get current priority if nested level == 0 */
|
|
|
|
if(!nested_ctr) {
|
2009-12-08 03:13:21 +01:00
|
|
|
__asm volatile ( \
|
|
|
|
" mrs %0, primask\n" \
|
|
|
|
: "=r" (prev_primask) \
|
|
|
|
);
|
2009-11-28 21:05:36 +01:00
|
|
|
}
|
|
|
|
|
2010-01-31 17:48:23 +01:00
|
|
|
/* Disable interrupts */
|
2009-12-08 03:13:21 +01:00
|
|
|
__asm volatile ( \
|
|
|
|
" mov r0, #1 \n" \
|
|
|
|
" msr primask, r0\n" \
|
|
|
|
:::"r0" \
|
|
|
|
);
|
2009-11-28 21:05:36 +01:00
|
|
|
|
|
|
|
++nested_ctr;
|
|
|
|
|
|
|
|
/* No error */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-11-29 06:16:47 +01:00
|
|
|
|
2009-11-29 08:15:59 +01:00
|
|
|
/**
|
2009-11-29 15:21:50 +01:00
|
|
|
* Enables all interrupts (nested)
|
|
|
|
* \return < 0 on errors
|
2009-12-08 03:13:21 +01:00
|
|
|
* \return -1 on nesting errors (PIOS_IRQ_Disable() hasn't been called before)
|
2009-11-29 08:15:59 +01:00
|
|
|
*/
|
2009-12-24 04:09:37 +01:00
|
|
|
int32_t PIOS_IRQ_Enable(void)
|
2009-11-28 21:05:36 +01:00
|
|
|
{
|
|
|
|
/* Check for nesting error */
|
|
|
|
if(nested_ctr == 0) {
|
|
|
|
/* Nesting error */
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Decrease nesting level */
|
|
|
|
--nested_ctr;
|
|
|
|
|
|
|
|
/* Set back previous priority once nested level reached 0 again */
|
|
|
|
if(nested_ctr == 0) {
|
|
|
|
__asm volatile ( \
|
|
|
|
" msr primask, %0\n" \
|
|
|
|
:: "r" (prev_primask) \
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* No error */
|
|
|
|
return 0;
|
2009-11-29 06:16:47 +01:00
|
|
|
}
|
2010-02-28 07:47:49 +01:00
|
|
|
|
|
|
|
#endif
|
2010-07-16 07:31:11 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
* @}
|
|
|
|
*/
|