- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
下面的 C 代码中有两个中断。
第一个是通过 Key0 的使用,它具有以下属性:一旦按下 Key0,就会写入“D”。此后不久,一旦程序自行恢复,就会写入“d”,这是假设我仍然按住按钮。释放此按钮后,会打印出“U”。
如果我不按住按钮,则会打印出“dU”,使代码变成“DdU”。
第二个是通过使用切换键,它具有以下属性:一旦我们切换切换键,程序就会打印一个“S”。此后不久,打印出一个“s”。
现在我的问题如下:当先使用 key0,然后使用切换键时,Key0 能够中断程序,同时切换键被忽略。所以我们只得到“DdU”,而“S”和“s”都被忽略。
现在我不明白为什么反之亦然不适用。确实如此,但只是在一定程度上。第一次切换时,“S”被写入,“D”和“d”被跳过。 “s”被写下来,但现在令人困惑的部分=>为什么“U”被写在最后?为什么 key0 的“D”和“d”被忽略,而“U”却没有被忽略?
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/* Include header file for alt_irq_register() */
#include <sys/alt_irq.h>
/* Define the null pointer */
#define NULL_POINTER ( (void *) 0)
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void out_char_uart_0( int c )
{
/* Wait until transmitter is ready */
while( (UART_0[2] & 0x40) == 0 );
/* Now send character */
UART_0[1] = c & 0xff;
}
/* This simple subroutine stalls
* execution for a short while. */
void somedelay( void )
{
int i = DELAYPARAM;
while( (i = i - 1) > 0);
}
/* This simple subroutine stalls
* execution for a long while. */
void bigdelay( void )
{
int j = BIGDELAYPARAM;
while( (j = j - 1) > 0) somedelay();
}
void keys_isr( void * context )
{
/* Read edge capture register of the de2_pio_keys4 device. */
int edges = *de2_pio_keys4_edgecap;
/* Clear edge capture register - writing
* any value clears all bits. */
*de2_pio_keys4_edgecap = 0;
/* If action on KEY0 */
if( edges & 1 )
{
/* If KEY0 is pressed now */
if( (*de2_pio_keys4_base & 1) == 0 )
{
/* Turn on green LED LEDG0
* in software copy of LED bits. */
myleds = myleds | 1;
/* Copy software LED bits to actual LEDs. */
*de2_pio_greenled9 = myleds;
/* Print an upper-case 'D' using out_char_uart_0. */
out_char_uart_0( 'D' );
/* Wait a long while */
bigdelay();
/* Print a lower-case 'd' using out_char_uart_0. */
out_char_uart_0( 'd' );
}
/* If KEY0 is released now */
else if( (*de2_pio_keys4_base & 1) != 0 )
{
/* Turn off green LED LEDG0
* in software copy of LED bits. */
myleds = myleds & 0xffffe;
/* Print an 'U' using out_char_uart_0. */
out_char_uart_0( 'U' );
/* Copy software LED bits to actual LEDs. */
*de2_pio_greenled9 = myleds;
}
}
}
/*
* Initialize de2_pio_keys4 for interrupts.
*/
void keysinit_int( void )
{
/* Declare a temporary for checking return values
* from system-calls and library functions. */
register int ret_val_check;
/* Disable interrupts for de2_pio_keys4,
* if they were enabled.
*
* The function alt_irq_disable returns an int,
* which always has the value 0.
* We use a type cast to void to tell the compiler
* that we really want to ignore the return value. */
(void) alt_ic_irq_disable( 0, de2_pio_keys4_intindex );
/* Allow interrupts from KEY0 only. */
*de2_pio_keys4_intmask = 1;
/* Set up Altera's interrupt wrapper for
* interrupts from the de2_pio_keys4 dev-ice.
* The function alt_irq_register will enable
* interrupts from de2_pio_keys4.
* Return value is zero for success,
* nonzero for failure. */
ret_val_check = alt_ic_isr_register(0,de2_pio_keys4_intindex,keys_isr,NULL_POINTER,NULL_POINTER );
/* If there was an error, terminate the program. */
if( ret_val_check != 0 ) n2_fatal_error();
}
/*
* Interrupt handler for timer_1.
* The parameters are ignored here, but are
* required for correct compilation.
* The type alt_u32 is an Altera-defined
* unsigned integer type.
*/
void timer_isr( void * context )
{
*timer_1_status = 0; /* Acknowledge interrupt */
tick( &mytime );
puttime( &mytime );
}
/*
* Initialize timer_1 for regular interrupts,
* once every timeout period.
* The timeout period is defined above,
* see definition of TIMER_1_TIMEOUT
*/
void timerinit_int( void )
{
/* Declare a local temporary variable
* for checking return values
* from system-calls and library functions. */
register int ret_val_check;
/* Disable interrupts for timer_1,
* if they were enabled.
*
* The function alt_irq_disable returns an int,
* which always has the value 0.
* We use a type cast to void to tell the compiler
* that we really want to ignore the return value. */
(void) alt_ic_irq_disable( 0, timer_1_intindex );
*timer_1_period_low = TIMER_1_TIMEOUT & 0xffff;
*timer_1_period_high = TIMER_1_TIMEOUT >> 16;
*timer_1_control = 7;
/* START bit (must always be a 1)
* CONT bit (timer restarts on timeout)
* ITO bit (interrupt on timeout) */
/* Set up Altera's interrupt wrapper for
* interrupts from the timer_1 device.
* Return value is zero for success,
* nonzero for failure. */
ret_val_check = alt_ic_isr_register(0,timer_1_intindex,timer_isr,NULL_POINTER,NULL_POINTER );
/* If there was an error, terminate the program. */
if( ret_val_check != 0 ) n2_fatal_error();
}
void irq_handler_toggles(void * context)
{
/* Acknowledge the interrupt. */
*de2_pio_toggles18_edgecap = 1;
/* Light up the LED, print S, wait, turn off the LED and print s. */
*de2_pio_redled18_base = 1;
out_char_uart_0('S');
bigdelay();
*de2_pio_redled18_base = 0;
out_char_uart_0('s');
}
void toggles_init()
{
/* Declare a temporary for checking return values
* from system-calls and library functions. */
register int ret_val_check;
/*
* Register the interrupt handler.
*/
ret_val_check = alt_ic_isr_register(0,de2_pio_toggles18_intindex,irq_handler_toggles,NULL_POINTER,NULL_POINTER);
/* If there was an error, terminate the program. */
if( ret_val_check != 0 ) n2_fatal_error();
/* Set up the mask for the keys.*/
*de2_pio_toggles18_intmask = 1;
}
int main()
{
/* Remove unwanted interrupts.
* initfix_int is supplied by KTH.
* A nonzero return value indicates failure. */
if( intfix() != 0 ) n2_fatal_error();
/* Initialize de2_pio_keys4 for
* interrupts. */
keysinit_int();
/* Initialize the toggle switches. */
toggles_init();
/* Initialize timer_1 for
* continuous timeout interrupts. */
timerinit_int();
/* Loop forever. */
while( 1 )
{
out_char_uart_0('_'); /* print an underscore */
/* Programmed delay between underscores.
* Defined earlier in this file. */
somedelay();
}
}
最佳答案
难道不是因为Ss的优先级高于Dd而被忽略吗?而切换开关没有第三个输出来忽略“U”?
关于c - C 中的中断处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29212874/
#include using namespace std; class C{ private: int value; public: C(){ value = 0;
这个问题已经有答案了: What is the difference between char a[] = ?string?; and char *p = ?string?;? (8 个回答) 已关闭
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 7 年前。 此帖子已于 8 个月
除了调试之外,是否有任何针对 c、c++ 或 c# 的测试工具,其工作原理类似于将独立函数复制粘贴到某个文本框,然后在其他文本框中输入参数? 最佳答案 也许您会考虑单元测试。我推荐你谷歌测试和谷歌模拟
我想在第二台显示器中移动一个窗口 (HWND)。问题是我尝试了很多方法,例如将分辨率加倍或输入负值,但它永远无法将窗口放在我的第二台显示器上。 关于如何在 C/C++/c# 中执行此操作的任何线索 最
我正在寻找 C/C++/C## 中不同类型 DES 的现有实现。我的运行平台是Windows XP/Vista/7。 我正在尝试编写一个 C# 程序,它将使用 DES 算法进行加密和解密。我需要一些实
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
有没有办法强制将另一个 窗口置于顶部? 不是应用程序的窗口,而是另一个已经在系统上运行的窗口。 (Windows, C/C++/C#) 最佳答案 SetWindowPos(that_window_ha
假设您可以在 C/C++ 或 Csharp 之间做出选择,并且您打算在 Windows 和 Linux 服务器上运行同一服务器的多个实例,那么构建套接字服务器应用程序的最明智选择是什么? 最佳答案 如
你们能告诉我它们之间的区别吗? 顺便问一下,有什么叫C++库或C库的吗? 最佳答案 C++ 标准库 和 C 标准库 是 C++ 和 C 标准定义的库,提供给 C++ 和 C 程序使用。那是那些词的共同
下面的测试代码,我将输出信息放在注释中。我使用的是 gcc 4.8.5 和 Centos 7.2。 #include #include class C { public:
很难说出这里问的是什么。这个问题是含糊的、模糊的、不完整的、过于宽泛的或修辞性的,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开它,visit the help center 。 已关
我的客户将使用名为 annoucement 的结构/类与客户通信。我想我会用 C++ 编写服务器。会有很多不同的类继承annoucement。我的问题是通过网络将这些类发送给客户端 我想也许我应该使用
我在 C# 中有以下函数: public Matrix ConcatDescriptors(IList> descriptors) { int cols = descriptors[0].Co
我有一个项目要编写一个函数来对某些数据执行某些操作。我可以用 C/C++ 编写代码,但我不想与雇主共享该函数的代码。相反,我只想让他有权在他自己的代码中调用该函数。是否可以?我想到了这两种方法 - 在
我使用的是编写糟糕的第 3 方 (C/C++) Api。我从托管代码(C++/CLI)中使用它。有时会出现“访问冲突错误”。这使整个应用程序崩溃。我知道我无法处理这些错误[如果指针访问非法内存位置等,
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 7 年前。
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的,因为
我有一些 C 代码,将使用 P/Invoke 从 C# 调用。我正在尝试为这个 C 函数定义一个 C# 等效项。 SomeData* DoSomething(); struct SomeData {
这个问题已经有答案了: Why are these constructs using pre and post-increment undefined behavior? (14 个回答) 已关闭 6
我是一名优秀的程序员,十分优秀!