📄 knmi.c
字号:
//=================================================================//// knmi.c//// NMI test - checks NMI interrupt and NMI configuration////=================================================================//####ECOSGPLCOPYRIGHTBEGIN####// -------------------------------------------// This file is part of eCos, the Embedded Configurable Operating System.// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.//// eCos 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 or (at your option) any later version.//// eCos 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 eCos; if not, write to the Free Software Foundation, Inc.,// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.//// As a special exception, if other files instantiate templates or use macros// or inline functions from this file, or you compile this file and link it// with other works to produce a work based on this file, this file does not// by itself cause the resulting work to be covered by the GNU General Public// License. However the source code for this file must still be made available// in accordance with section (3) of the GNU General Public License.//// This exception does not invalidate any other reasons why a work based on// this file might be covered by the GNU General Public License.//// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.// at http://sources.redhat.com/ecos/ecos-license/// -------------------------------------------//####ECOSGPLCOPYRIGHTEND####//=================================================================//#####DESCRIPTIONBEGIN####//// Author(s): Uwe Kindler// Contributors: Uwe Kindler// Date: 2004-02-14// Description: Test of NMI switch, ISR, DSR and interrupt creat, attach// and configure//####DESCRIPTIONEND####//===========================================================================//===========================================================================// INCLUDES//===========================================================================#include <cyg/infra/diag.h>#include <cyg/hal/hal_diag.h>#include <cyg/hal/hal_arch.h> /* CYGNUM_HAL_STACK_SIZE_TYPICAL */#include <cyg/infra/testcase.h>#include <cyg/kernel/kapi.h> /* All the kernel specific stuff *///// check if kernel API C is present - it's required for this test//#ifdef CYGFUN_KERNEL_API_C#include <cyg/hal/hal_intr.h>#include "testaux.h"//===========================================================================// DEFINES//===========================================================================#define ONE_SHOT 0#define SECONDS(_s_) ((_s_) * 100)//===========================================================================// LOCALS// DESCRIPTTION:// Now declare (and allocate space for) some kernel stuf//===========================================================================cyg_thread thread_nmi_obj; // space for thread objectcyg_uint32 thread_nmi_stack[1024]; // stacks 4096 bytecyg_handle_t thread_nmi_hdl; cyg_thread_entry_t thread_nmi_entry; // and now variables for the procedure which is the threadcyg_sem_t sem_nmi;cyg_uint8 isr_cnt = 0;cyg_handle_t int_nmi_hdl;cyg_interrupt int_nmi;cyg_handle_t sys_clk_hdl;cyg_handle_t ctr_hdl;cyg_alarm alarm_obj;cyg_handle_t alarm_hdl;//===========================================================================// NMI ISR//===========================================================================cyg_uint32 nmi_ISR(cyg_vector_t vector, cyg_addrword_t pdata){ diag_printf("NMI ISR executes\n"); isr_cnt++; if ((isr_cnt % 4) != 0) { return CYG_ISR_HANDLED; } else { return CYG_ISR_HANDLED | CYG_ISR_CALL_DSR; }}//===========================================================================// NMI DSR//===========================================================================void nmi_DSR( cyg_vector_t vector, cyg_ucount32 count, cyg_addrword_t pdata){ diag_printf("NMI DSR executes\n"); if (isr_cnt < 8) { cyg_interrupt_configure(CYGNUM_HAL_INTERRUPT_NMI, false, true); CYG_TEST_INFO("NMI triggers on rising edge"); } else { cyg_semaphore_post(&sem_nmi); // wake up nmi thread }}//===========================================================================// NMI THREAD//===========================================================================void thread_nmi_entry(cyg_addrword_t data){ diag_printf("Test of NMI switch and interrupt ISR/DSR handling\n" "Hit the NMI switch 4 times - every time you release\n" "the switch an interrupt should occur. After 4\n" "interrupts the DSR will be called which reconfigures\n" "the interrupt.\n"); diag_printf("Now hit the NMI switch again 4 times. An interrupt\n" "should now occur when you press the switch down.\n" "After 4 interrupts the DSR will be called which wakes\n" "up a waiting thread - the test should be passed now.\n"); diag_printf("!!! This test times out after 30 seconds !!!\n\n"); CYG_TEST_INFO("NMI triggers on falling edge"); cyg_semaphore_wait(&sem_nmi); // wait for semaphore from NMI interrupt CYG_TEST_PASS_FINISH("NMI test OK"); // test passed}//===========================================================================// ALARM HANDLER// DESCRIPTION:// If this alarm handler executes the test fail.//===========================================================================void alarm_handler(cyg_handle_t alarm_hdl, cyg_addrword_t data){ CYG_TEST_FAIL_FINISH("Timeout");}//===========================================================================// APPLICATION MAIN STARTING POINT// DESCRIPTTION:// Main starting point for the application//===========================================================================externC void cyg_start (void ){ CYG_TEST_INIT(); cyg_semaphore_init(&sem_nmi,0); // initialise semaphores sys_clk_hdl = cyg_real_time_clock(); cyg_clock_to_counter(sys_clk_hdl, &ctr_hdl); // get sys clock counter handle cyg_alarm_create(ctr_hdl, alarm_handler, (cyg_addrword_t)123, &alarm_hdl, &alarm_obj); cyg_alarm_initialize(alarm_hdl, cyg_current_time() + SECONDS(30), ONE_SHOT); // alarm should execute only once // // create NMI interrupt // cyg_interrupt_create(CYGNUM_HAL_INTERRUPT_NMI, CYGNUM_HAL_INT_PRIO_HIGHEST, 0, nmi_ISR, nmi_DSR, &int_nmi_hdl, &int_nmi ); cyg_interrupt_attach(int_nmi_hdl); // // create and start threads // cyg_thread_create(4, thread_nmi_entry, (cyg_addrword_t) 2, "Thread NMI", (void *) thread_nmi_stack, 4096, &thread_nmi_hdl, &thread_nmi_obj); cyg_thread_resume(thread_nmi_hdl); cyg_interrupt_configure(CYGNUM_HAL_INTERRUPT_NMI, false, false); cyg_scheduler_start(); CYG_TEST_FAIL_FINISH("Not reached");}#else // def CYGFUN_KERNEL_API_C#define N_A_MSG "Kernel C API layer disabled"#endif // def CYGFUN_KERNEL_API_C#ifdef N_A_MSGexternC void cyg_start( void ){ CYG_TEST_INIT(); CYG_TEST_NA( N_A_MSG);}#endif // N_A_MSG//---------------------------------------------------------------------------// End of serial1.c
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -