Finish the high priority, nested interrupt handler test (does not work)
This commit is contained in:
parent
090a1c0bf6
commit
483a4d8d2b
@ -172,21 +172,25 @@ struct stm32_tim_priv_s
|
||||
|
||||
/* Get a 16-bit register value by offset */
|
||||
|
||||
static inline uint16_t stm32_getreg16(FAR struct stm32_tim_dev_s *dev, uint8_t offset)
|
||||
static inline uint16_t stm32_getreg16(FAR struct stm32_tim_dev_s *dev,
|
||||
uint8_t offset)
|
||||
{
|
||||
return getreg16(((struct stm32_tim_priv_s *)dev)->base + offset);
|
||||
}
|
||||
|
||||
/* Put a 16-bit register value by offset */
|
||||
|
||||
static inline void stm32_putreg16(FAR struct stm32_tim_dev_s *dev, uint8_t offset, uint16_t value)
|
||||
static inline void stm32_putreg16(FAR struct stm32_tim_dev_s *dev, uint8_t offset,
|
||||
uint16_t value)
|
||||
{
|
||||
putreg16(value, ((struct stm32_tim_priv_s *)dev)->base + offset);
|
||||
}
|
||||
|
||||
/* Modify a 16-bit register value by offset */
|
||||
|
||||
static inline void stm32_modifyreg16(FAR struct stm32_tim_dev_s *dev, uint8_t offset, uint16_t clearbits, uint16_t setbits)
|
||||
static inline void stm32_modifyreg16(FAR struct stm32_tim_dev_s *dev,
|
||||
uint8_t offset, uint16_t clearbits,
|
||||
uint16_t setbits)
|
||||
{
|
||||
modifyreg16(((struct stm32_tim_priv_s *)dev)->base + offset, clearbits, setbits);
|
||||
}
|
||||
@ -195,7 +199,8 @@ static inline void stm32_modifyreg16(FAR struct stm32_tim_dev_s *dev, uint8_t of
|
||||
* 32-bit registers (CNT, ARR, CRR1-4) in the 32-bit timers TIM2-5.
|
||||
*/
|
||||
|
||||
static inline uint32_t stm32_getreg32(FAR struct stm32_tim_dev_s *dev, uint8_t offset)
|
||||
static inline uint32_t stm32_getreg32(FAR struct stm32_tim_dev_s *dev,
|
||||
uint8_t offset)
|
||||
{
|
||||
return getreg32(((struct stm32_tim_priv_s *)dev)->base + offset);
|
||||
}
|
||||
@ -204,7 +209,8 @@ static inline uint32_t stm32_getreg32(FAR struct stm32_tim_dev_s *dev, uint8_t o
|
||||
* 32-bit registers (CNT, ARR, CRR1-4) in the 32-bit timers TIM2-5.
|
||||
*/
|
||||
|
||||
static inline void stm32_putreg32(FAR struct stm32_tim_dev_s *dev, uint8_t offset, uint32_t value)
|
||||
static inline void stm32_putreg32(FAR struct stm32_tim_dev_s *dev, uint8_t offset,
|
||||
uint32_t value)
|
||||
{
|
||||
putreg32(value, ((struct stm32_tim_priv_s *)dev)->base + offset);
|
||||
}
|
||||
@ -232,6 +238,7 @@ static void stm32_tim_disable(FAR struct stm32_tim_dev_s *dev)
|
||||
}
|
||||
|
||||
/* Reset timer into system default state, but do not affect output/input pins */
|
||||
|
||||
static void stm32_tim_reset(FAR struct stm32_tim_dev_s *dev)
|
||||
{
|
||||
((struct stm32_tim_priv_s *)dev)->mode = STM32_TIM_MODE_DISABLED;
|
||||
@ -302,18 +309,21 @@ static int stm32_tim_setclock(FAR struct stm32_tim_dev_s *dev, uint32_t freq)
|
||||
return prescaler;
|
||||
}
|
||||
|
||||
static void stm32_tim_setperiod(FAR struct stm32_tim_dev_s *dev, uint32_t period)
|
||||
static void stm32_tim_setperiod(FAR struct stm32_tim_dev_s *dev,
|
||||
uint32_t period)
|
||||
{
|
||||
ASSERT(dev);
|
||||
stm32_putreg32(dev, STM32_BTIM_ARR_OFFSET, period);
|
||||
}
|
||||
|
||||
static int stm32_tim_setisr(FAR struct stm32_tim_dev_s *dev, int (*handler)(int irq, void *context), int source)
|
||||
static int stm32_tim_setisr(FAR struct stm32_tim_dev_s *dev,
|
||||
int (*handler)(int irq, void *context),
|
||||
int source)
|
||||
{
|
||||
int vectorno;
|
||||
|
||||
ASSERT(dev);
|
||||
ASSERT(source==0);
|
||||
ASSERT(source == 0);
|
||||
|
||||
switch (((struct stm32_tim_priv_s *)dev)->base)
|
||||
{
|
||||
@ -353,6 +363,7 @@ static int stm32_tim_setisr(FAR struct stm32_tim_dev_s *dev, int (*handler)(int
|
||||
#endif
|
||||
#if STM32_NATIM > 0
|
||||
/* TODO: add support for multiple sources and callbacks */
|
||||
|
||||
#if CONFIG_STM32_TIM1
|
||||
case STM32_TIM1_BASE:
|
||||
vectorno = STM32_IRQ_TIM1UP;
|
||||
@ -471,7 +482,8 @@ static int stm32_tim_setmode(FAR struct stm32_tim_dev_s *dev, stm32_tim_mode_t m
|
||||
return OK;
|
||||
}
|
||||
|
||||
static int stm32_tim_setchannel(FAR struct stm32_tim_dev_s *dev, uint8_t channel, stm32_tim_channel_t mode)
|
||||
static int stm32_tim_setchannel(FAR struct stm32_tim_dev_s *dev, uint8_t channel,
|
||||
stm32_tim_channel_t mode)
|
||||
{
|
||||
uint16_t ccmr_val = 0;
|
||||
uint16_t ccer_val = stm32_getreg16(dev, STM32_GTIM_CCER_OFFSET);
|
||||
@ -719,7 +731,8 @@ static int stm32_tim_setchannel(FAR struct stm32_tim_dev_s *dev, uint8_t channel
|
||||
return OK;
|
||||
}
|
||||
|
||||
static int stm32_tim_setcompare(FAR struct stm32_tim_dev_s *dev, uint8_t channel, uint32_t compare)
|
||||
static int stm32_tim_setcompare(FAR struct stm32_tim_dev_s *dev, uint8_t channel,
|
||||
uint32_t compare)
|
||||
{
|
||||
ASSERT(dev);
|
||||
|
||||
@ -758,6 +771,7 @@ static int stm32_tim_getcapture(FAR struct stm32_tim_dev_s *dev, uint8_t channel
|
||||
case 4:
|
||||
return stm32_getreg32(dev, STM32_GTIM_CCR4_OFFSET);
|
||||
}
|
||||
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
|
@ -164,6 +164,8 @@ struct stm32_tim_ops_s
|
||||
int (*setcompare)(FAR struct stm32_tim_dev_s *dev, uint8_t channel, uint32_t compare);
|
||||
int (*getcapture)(FAR struct stm32_tim_dev_s *dev, uint8_t channel);
|
||||
|
||||
/* Timer interupts */
|
||||
|
||||
int (*setisr)(FAR struct stm32_tim_dev_s *dev, int (*handler)(int irq, void *context), int source);
|
||||
void (*enableint)(FAR struct stm32_tim_dev_s *dev, int source);
|
||||
void (*disableint)(FAR struct stm32_tim_dev_s *dev, int source);
|
||||
@ -176,11 +178,11 @@ struct stm32_tim_ops_s
|
||||
|
||||
/* Power-up timer and get its structure */
|
||||
|
||||
EXTERN FAR struct stm32_tim_dev_s * stm32_tim_init(int timer);
|
||||
FAR struct stm32_tim_dev_s *stm32_tim_init(int timer);
|
||||
|
||||
/* Power-down timer, mark it as unused */
|
||||
|
||||
EXTERN int stm32_tim_deinit(FAR struct stm32_tim_dev_s * dev);
|
||||
int stm32_tim_deinit(FAR struct stm32_tim_dev_s * dev);
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
if ARCH_BOARD_VIEWTOOL_STM32F107
|
||||
|
||||
config VIEWTOOLS_HIGHPRI
|
||||
config VIEWTOOL_HIGHPRI
|
||||
bool "High priority interrupt test"
|
||||
default n
|
||||
depends on ARCH_CHIP_STM32F103VCT6 && ARCH_HIPRI_INTERRUPT
|
||||
@ -16,4 +16,23 @@ config VIEWTOOLS_HIGHPRI
|
||||
(ARCH_CHIP_STM32F103VCT6) but should be easily ported to other STM32
|
||||
architectures.
|
||||
|
||||
endif
|
||||
if VIEWTOOL_HIGHPRI
|
||||
|
||||
config VIEWTOOL_TIM6_FREQUENCY
|
||||
int "TIM6 Frequency"
|
||||
default 36000000
|
||||
---help---
|
||||
TIM6 is used to drive the high priority, nested interrupt in the
|
||||
test enabled with VIEWTOOL_HIGHPRI. This setting specifies the
|
||||
frequency of the TIM6 input clock.
|
||||
|
||||
config VIEWTOOL_TIM6_PERIOD
|
||||
int "TIM6 Period"
|
||||
default 36000
|
||||
---help---
|
||||
TIM6 is used to drive the high priority, nested interrupt in the
|
||||
test enabled with VIEWTOOL_HIGHPRI. This setting specifies
|
||||
period of the TIM6 interrupt in units of VIEWTOOL_TIM6_FREQUENCY.
|
||||
|
||||
endif # VIEWTOOL_HIGHPRI
|
||||
endif # ARCH_BOARD_VIEWTOOL_STM32F107
|
||||
|
@ -340,7 +340,9 @@ CONFIG_ARCH_BUTTONS=y
|
||||
#
|
||||
# Board-Specific Options
|
||||
#
|
||||
CONFIG_VIEWTOOLS_HIGHPRI=y
|
||||
CONFIG_VIEWTOOL_HIGHPRI=y
|
||||
CONFIG_VIEWTOOL_TIM6_FREQUENCY=36000000
|
||||
CONFIG_VIEWTOOL_TIM6_PERIOD=36000
|
||||
|
||||
#
|
||||
# RTOS Features
|
||||
|
@ -33,8 +33,8 @@
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
#ifndef __CONFIGS_VIEWTOOLS_STM32F107_INCLUDE_BOARD_STM32F103VCT6_H
|
||||
#define __CONFIGS_VIEWTOOLS_STM32F107_INCLUDE_BOARD_STM32F103VCT6_H 1
|
||||
#ifndef __CONFIGS_VIEWTOOL_STM32F107_INCLUDE_BOARD_STM32F103VCT6_H
|
||||
#define __CONFIGS_VIEWTOOL_STM32F107_INCLUDE_BOARD_STM32F103VCT6_H 1
|
||||
|
||||
/************************************************************************************
|
||||
* Included Files
|
||||
@ -137,4 +137,4 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
#endif /* __ASSEMBLY__ */
|
||||
#endif /* __CONFIGS_VIEWTOOLS_STM32F107_INCLUDE_BOARD_STM32F103VCT6_H */
|
||||
#endif /* __CONFIGS_VIEWTOOL_STM32F107_INCLUDE_BOARD_STM32F103VCT6_H */
|
||||
|
@ -33,8 +33,8 @@
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
#ifndef __CONFIGS_VIEWTOOLS_STM32F107_INCLUDE_BOARD_STM32F107VCT6_H
|
||||
#define __CONFIGS_VIEWTOOLS_STM32F107_INCLUDE_BOARD_STM32F107VCT6_H 1
|
||||
#ifndef __CONFIGS_VIEWTOOL_STM32F107_INCLUDE_BOARD_STM32F107VCT6_H
|
||||
#define __CONFIGS_VIEWTOOL_STM32F107_INCLUDE_BOARD_STM32F107VCT6_H 1
|
||||
|
||||
/************************************************************************************
|
||||
* Included Files
|
||||
@ -140,4 +140,4 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
#endif /* __ASSEMBLY__ */
|
||||
#endif /* __CONFIGS_VIEWTOOLS_STM32F107_INCLUDE_BOARD_STM32F107VCT6_H */
|
||||
#endif /* __CONFIGS_VIEWTOOL_STM32F107_INCLUDE_BOARD_STM32F107VCT6_H */
|
||||
|
@ -33,8 +33,8 @@
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
#ifndef __CONFIGS_VIEWTOOLS_STM32F107_INCLUDE_BOARD_H
|
||||
#define __CONFIGS_VIEWTOOLS_STM32F107_INCLUDE_BOARD_H 1
|
||||
#ifndef __CONFIGS_VIEWTOOL_STM32F107_INCLUDE_BOARD_H
|
||||
#define __CONFIGS_VIEWTOOL_STM32F107_INCLUDE_BOARD_H 1
|
||||
|
||||
/************************************************************************************
|
||||
* Included Files
|
||||
@ -222,4 +222,4 @@ xcpt_t up_irqbutton(int id, xcpt_t irqhandler);
|
||||
#endif
|
||||
|
||||
#endif /* __ASSEMBLY__ */
|
||||
#endif /* __CONFIGS_VIEWTOOLS_STM32F107_INCLUDE_BOARD_H */
|
||||
#endif /* __CONFIGS_VIEWTOOL_STM32F107_INCLUDE_BOARD_H */
|
||||
|
@ -54,7 +54,7 @@ ifeq ($(CONFIG_ARCH_BUTTONS),y)
|
||||
CSRCS += stm32_buttons.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_VIEWTOOLS_HIGHPRI),y)
|
||||
ifeq ($(CONFIG_VIEWTOOL_HIGHPRI),y)
|
||||
CSRCS += stm32_highpri.c
|
||||
endif
|
||||
|
||||
|
@ -43,19 +43,25 @@
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <nuttx/arch.h>
|
||||
|
||||
#include <arch/irq.h>
|
||||
#include <arch/chip/chip.h>
|
||||
#include <arch/board/board.h>
|
||||
|
||||
#include "up_internal.h"
|
||||
#include "ram_vectors.h"
|
||||
#include "stm32_tim.h"
|
||||
|
||||
#include "viewtool_stm32f107.h"
|
||||
|
||||
#ifdef CONFIG_VIEWTOOLS_HIGHPRI
|
||||
#ifdef CONFIG_VIEWTOOL_HIGHPRI
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
/* Configuration ************************************************************/
|
||||
|
||||
#ifndef CONFIG_ARCH_CHIP_STM32F103VCT6
|
||||
# warning This only only been verified with CONFIG_ARCH_CHIP_STM32F103VCT6
|
||||
#endif
|
||||
@ -72,10 +78,36 @@
|
||||
# error CONFIG_STM32_TIM6 is required
|
||||
#endif
|
||||
|
||||
#ifndef VIEWTOOL_TIM6_FREQUENCY
|
||||
# warning VIEWTOOL_TIM6_FREQUENCY defaulting to STM32_APB1_TIM6_CLKIN
|
||||
# define VIEWTOOL_TIM6_FREQUENCY STM32_APB1_TIM6_CLKIN
|
||||
#endif
|
||||
|
||||
#ifndef VIEWTOOL_TIM6_PERIOD
|
||||
# warning VIEWTOOL_TIM6_PERIOD defaulting to 1MS
|
||||
# define VIEWTOOL_TIM6_PERIOD (VIEWTOOL_TIM6_FREQUENCY / 1000)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
struct highpri_s
|
||||
{
|
||||
FAR struct stm32_tim_dev_s *dev; /* TIM6 driver instance */
|
||||
volatile uint64_t enabled;
|
||||
volatile uint64_t nested;
|
||||
volatile uint64_t other;
|
||||
volatile uint64_t handler;
|
||||
volatile uint64_t thread;
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
static struct highpri_s g_highpri;
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
@ -84,12 +116,46 @@
|
||||
* Name: tim6_handler
|
||||
*
|
||||
* Description:
|
||||
* This is the handler for the nested
|
||||
* This is the handler for the high speed TIM6 interrupt.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void tim6_handler(void)
|
||||
{
|
||||
uint8_t basepri;
|
||||
|
||||
/* Acknowledge the timer interrupt */
|
||||
|
||||
STM32_TIM_ACKINT(g_highpri.dev, 0);
|
||||
|
||||
/* Increment the count associated with the current basepri */
|
||||
|
||||
basepri = getbasepri();
|
||||
switch (basepri)
|
||||
{
|
||||
case 0: /* BASEPRI==0 disabled all masking */
|
||||
g_highpri.enabled++;
|
||||
break;
|
||||
|
||||
case NVIC_SYSH_DISABLE_PRIORITY: /* Normal interrupts are disabled */
|
||||
g_highpri.nested++;
|
||||
break;
|
||||
|
||||
default: /* There should not be any other values of BASEPRI */
|
||||
g_highpri.other++;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Check if we are in an interrupt handle */
|
||||
|
||||
if (current_regs)
|
||||
{
|
||||
g_highpri.handler++;
|
||||
}
|
||||
else
|
||||
{
|
||||
g_highpri.thread++;
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
@ -109,30 +175,86 @@ void tim6_handler(void)
|
||||
|
||||
int highpri_main(int argc, char *argv[])
|
||||
{
|
||||
FAR struct stm32_tim_dev_s *dev;
|
||||
uint64_t enabled;
|
||||
uint64_t nested;
|
||||
uint64_t other;
|
||||
uint64_t handler;
|
||||
uint64_t thread;
|
||||
uint64_t total;
|
||||
int prescaler;
|
||||
int ret;
|
||||
|
||||
printf("highpri_main: Started\n");
|
||||
|
||||
/* Attach the TIM6 ram vector */
|
||||
/* Configure basic timer TIM6 and enable interrupts */
|
||||
|
||||
dev = stm32_tim_init(6);
|
||||
if (!dev)
|
||||
{
|
||||
fprintf(stderr, "highpri_main: ERROR: stm32_tim_init(6) failed\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
g_highpri.dev = dev;
|
||||
|
||||
prescaler = STM32_TIM_SETCLOCK(dev, VIEWTOOL_TIM6_FREQUENCY);
|
||||
printf("TIM6 CLKIN=%d Hz, Frequency=%d Hz, prescaler=%d\n",
|
||||
STM32_APB1_TIM6_CLKIN, VIEWTOOL_TIM6_FREQUENCY, prescaler);
|
||||
|
||||
STM32_TIM_SETPERIOD(dev, VIEWTOOL_TIM6_PERIOD);
|
||||
printf("TIM6 period=%d cyles; interrupt rate=%d Hz\n",
|
||||
VIEWTOOL_TIM6_PERIOD, VIEWTOOL_TIM6_FREQUENCY/VIEWTOOL_TIM6_PERIOD);
|
||||
|
||||
/* Attach and enable the TIM6 ram vector */
|
||||
|
||||
ret = up_ramvec_attach(STM32_IRQ_TIM6, tim6_handler);
|
||||
if (ret < 0)
|
||||
{
|
||||
fprintf(stderr, "highpri_main: ERROR: up_ramvec_attach failed: %d\n", ret);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* Configure TIM6 and enable interrupts */
|
||||
#warning Missing logic
|
||||
up_enable_irq(STM32_IRQ_TIM6);
|
||||
STM32_TIM_ENABLEINT(dev, 0);
|
||||
|
||||
/* Monitor interrupts */
|
||||
|
||||
for (;;)
|
||||
{
|
||||
/* Wait a bit */
|
||||
/* Flush stdout and wait a bit */
|
||||
|
||||
fflush(stdout);
|
||||
sleep(1);
|
||||
|
||||
/* Sample counts so that they are not volatile. Missing a count now
|
||||
* and then is a normal consequence of this design.
|
||||
*/
|
||||
|
||||
enabled = g_highpri.enabled;
|
||||
nested = g_highpri.nested;
|
||||
other = g_highpri.other;
|
||||
handler = g_highpri.handler;
|
||||
thread = g_highpri.thread;
|
||||
|
||||
/* Then print out what is happening */
|
||||
#warning Missing logic
|
||||
|
||||
total = enabled + nested + other;
|
||||
printf(" Enabled: %lld (%d%%)\n",
|
||||
enabled, (int)((100*enabled + (total / 2)) / total));
|
||||
printf(" Nested: %lld (%d%%)\n",
|
||||
nested, (int)((100*nested + (total / 2)) / total));
|
||||
printf(" Other: %lld (%d%%)\n\n",
|
||||
other, (int)((100*other + (total / 2)) / total));
|
||||
|
||||
total = handler + thread;
|
||||
printf(" Handler: %lld (%d%%)\n",
|
||||
handler, (int)((100*handler + (total / 2)) / total));
|
||||
printf(" Thread: %lld (%d%%)\n\n",
|
||||
thread, (int)((100*thread + (total / 2)) / total));
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_VIEWTOOLS_HIGHPRI */
|
||||
#endif /* CONFIG_VIEWTOOL_HIGHPRI */
|
||||
|
@ -32,8 +32,8 @@
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************/
|
||||
#ifndef __CONFIGS_VIEWTOOLS_STM32F107_SRC_INTERNAL_H
|
||||
#define __CONFIGS_VIEWTOOLS_STM32F107_SRC_INTERNAL_H
|
||||
#ifndef __CONFIGS_VIEWTOOL_STM32F107_SRC_INTERNAL_H
|
||||
#define __CONFIGS_VIEWTOOL_STM32F107_SRC_INTERNAL_H
|
||||
|
||||
/******************************************************************************
|
||||
* Included Files
|
||||
@ -114,4 +114,4 @@ void weak_function stm32_spiinitialize(void);
|
||||
void stm32_ledinit(void);
|
||||
|
||||
#endif /* __ASSEMBLY__ */
|
||||
#endif /* __CONFIGS_VIEWTOOLS_STM32F107_SRC_INTERNAL_H */
|
||||
#endif /* __CONFIGS_VIEWTOOL_STM32F107_SRC_INTERNAL_H */
|
||||
|
Loading…
Reference in New Issue
Block a user