mirror of
https://github.com/apache/nuttx.git
synced 2026-06-06 16:50:55 +08:00
Finish the high priority, nested interrupt handler test (does not work)
This commit is contained in:
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user