硬汉嵌入式论坛

 找回密码
 立即注册
查看: 4428|回复: 7
收起左侧

[FreeRTOS] xTaskResumeFromISR函数在串口中断中的使用

[复制链接]

5

主题

33

回帖

92

积分

初级会员

积分
92
发表于 2017-4-21 11:56:54 | 显示全部楼层 |阅读模式
  1. curTime=xTaskGetTickCount();
  2.         interval=curTime-lastTime;
  3.         lastTime=curTime;
  4.         if(interval>=5)  
  5.         {
  6.             flaggps=0;
  7.             xYieldRequired = xTaskResumeFromISR(xgps);
  8.             
  9.         }
  10.         
  11.         if (USART_GetITStatus(COM_USART[COM], USART_IT_RXNE) != RESET)
  12.         {
  13.                 gps_raw_data[flaggps] = USART_ReceiveData(COM_USART[COM]);  //???? ???????
  14.               flaggps++;
  15.         }
  16.         if( xYieldRequired == pdTRUE )
  17.      {
  18.          portYIELD_FROM_ISR(xYieldRequired);
  19.      }
复制代码
这是串口接收中断中的一部分,运行之后就会卡在这个位置。
  1. #if( configASSERT_DEFINED == 1 )
  2.     void vPortValidateInterruptPriority( void )
  3.     {
  4.     uint32_t ulCurrentInterrupt;
  5.     uint8_t ucCurrentPriority;
  6.         /* Obtain the number of the currently executing interrupt. */
  7.         ulCurrentInterrupt = vPortGetIPSR();
  8.         /* Is the interrupt number a user defined interrupt? */
  9.         if( ulCurrentInterrupt >= portFIRST_USER_INTERRUPT_NUMBER )
  10.         {
  11.             /* Look up the interrupt's priority. */
  12.             ucCurrentPriority = pcInterruptPriorityRegisters[ ulCurrentInterrupt ];
  13.             /* The following assertion will fail if a service routine (ISR) for
  14.             an interrupt that has been assigned a priority above
  15.             configMAX_SYSCALL_INTERRUPT_PRIORITY calls an ISR safe FreeRTOS API
  16.             function.  ISR safe FreeRTOS API functions must *only* be called
  17.             from interrupts that have been assigned a priority at or below
  18.             configMAX_SYSCALL_INTERRUPT_PRIORITY.
  19.             Numerically low interrupt priority numbers represent logically high
  20.             interrupt priorities, therefore the priority of the interrupt must
  21.             be set to a value equal to or numerically *higher* than
  22.             configMAX_SYSCALL_INTERRUPT_PRIORITY.
  23.             Interrupts that    use the FreeRTOS API must not be left at their
  24.             default priority of    zero as that is the highest possible priority,
  25.             which is guaranteed to be above configMAX_SYSCALL_INTERRUPT_PRIORITY,
  26.             and    therefore also guaranteed to be invalid.
  27.             FreeRTOS maintains separate thread and ISR API functions to ensure
  28.             interrupt entry is as fast and simple as possible.
  29.             The following links provide detailed information:
  30.             http://www.freertos.org/RTOS-Cortex-M3-M4.html
  31.             http://www.freertos.org/FAQHelp.html */
  32.             configASSERT( ucCurrentPriority >= ucMaxSysCallPriority );   //这里
  33.         }
复制代码
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
107046
QQ
发表于 2017-4-21 18:05:58 | 显示全部楼层
关于这个问题,着重看下我们FreeRTOS教程的第12章,详细 讲解了:
http://www.armbbs.cn/forum.php?mod=viewthread&tid=17658
回复

使用道具 举报

5

主题

33

回帖

92

积分

初级会员

积分
92
 楼主| 发表于 2017-4-24 11:22:57 | 显示全部楼层

回 eric2013 的帖子

eric2013:
关于这个问题,着重看下我们FreeRTOS教程的第12章,详细 讲解了:
http://www.armbbs.cn/forum.php?mod=viewthread&tid=17658
加上了NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
Freertosconfig.h设置
  1. #ifdef __NVIC_PRIO_BITS
  2.     /* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */
  3.     #define configPRIO_BITS               __NVIC_PRIO_BITS
  4. #else
  5.     #define configPRIO_BITS               4        /* 15 priority levels */
  6. #endif
  7. /* The lowest interrupt priority that can be used in a call to a "set priority"
  8. function. */
  9. #define configLIBRARY_LOWEST_INTERRUPT_PRIORITY            0x0f
  10. /* The highest interrupt priority that can be used by any interrupt service
  11. routine that makes calls to interrupt safe FreeRTOS API functions.  DO NOT CALL
  12. INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER
  13. PRIORITY THAN THIS! (higher priorities are lower numeric values. */
  14. #define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY    0x01
  15. /* Interrupt priorities used by the kernel port layer itself.  These are generic
  16. to all Cortex-M ports, and do not rely on any particular library functions. */
  17. #define configKERNEL_INTERRUPT_PRIORITY         ( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
  18. /* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!!
  19. See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */
  20. #define configMAX_SYSCALL_INTERRUPT_PRIORITY     ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
  21.    
  22. /* Normal assert() semantics without relying on the provision of an assert.h
  23. header file. */
  24. #define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); }
复制代码


现在停在
  1. static void prvTaskExitError( void )
  2. {
  3.     /* A function that implements a task must not exit or attempt to return to
  4.     its caller as there is nothing to return to.  If a task wants to exit it
  5.     should instead call vTaskDelete( NULL ).
  6.     Artificially force an assert() to be triggered if configASSERT() is
  7.     defined, then stop here so application writers can catch the error. */
  8.     这一句configASSERT( uxCriticalNesting == ~0UL );
  9.     portDISABLE_INTERRUPTS();
  10.     for( ;; );
  11. }
复制代码
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
107046
QQ
发表于 2017-4-24 11:27:50 | 显示全部楼层
中断里面调用FreeRTOS的API函数,一定要是FromISR结尾的函数,也就是
xTaskGetTickCountFromISR,不能是xTaskGetTickCount
回复

使用道具 举报

5

主题

33

回帖

92

积分

初级会员

积分
92
 楼主| 发表于 2017-4-24 13:19:18 | 显示全部楼层

回 eric2013 的帖子

eric2013:
中断里面调用FreeRTOS的API函数,一定要是FromISR结尾的函数,也就是
xTaskGetTickCountFromISR,不能是xTaskGetTickCount
不考虑xTaskResumeFromISR(xgps);这句代码,使用xTaskGetTickCountFromISR会死机,使用xTaskGetTickCount不会死机,还会得到正确的Tick。
  1. void UART4_IRQHandler(void)
  2. {
  3. //    _IRQHandler(COM4);
  4.       _gps(COM4);
  5. //      ano_dtt(COM4);
  6. }
复制代码
  1. void _gps(uint8_t COM)
  2. {
  3.       BaseType_t xYieldRequired;
  4.    
  5.       static uint32_t lastTime =0;
  6.         uint32_t curTime;
  7.         uint32_t interval = 0;
  8.         
  9.         curTime=xTaskGetTickCountFromISR();
  10.         interval=curTime-lastTime;
  11.         lastTime=curTime;
  12.         if(interval>=5)  
  13.         {
  14.             flaggps=0;
  15.             xYieldRequired = xTaskResumeFromISR(xgps);
  16.             if( xYieldRequired == pdTRUE )
  17.      {
  18.          portYIELD_FROM_ISR(xYieldRequired);
  19.      }
  20.         }
  21.         
  22.         if (USART_GetITStatus(COM_USART[COM], USART_IT_RXNE) != RESET)
  23.         {
  24.                 gps_raw_data[flaggps] = USART_ReceiveData(COM_USART[COM]);  //???? ???????
  25.               flaggps++;
  26.         }
  27.         
  28. //        
  29. }
复制代码
回复

使用道具 举报

5

主题

33

回帖

92

积分

初级会员

积分
92
 楼主| 发表于 2017-4-24 13:34:29 | 显示全部楼层
。。。。
回复

使用道具 举报

5

主题

33

回帖

92

积分

初级会员

积分
92
 楼主| 发表于 2017-4-24 13:46:24 | 显示全部楼层
心酸///
回复

使用道具 举报

5

主题

33

回帖

92

积分

初级会员

积分
92
 楼主| 发表于 2017-4-24 14:08:29 | 显示全部楼层
不管怎么样,现在一切正常了,但是使用一个非中断api一个中断api,居然可以正常运行。
curTime=xTaskGetTickCount();
xYieldRequired = xTaskResumeFromISR(xgps);
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2024-5-15 13:49 , Processed in 0.319514 second(s), 25 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表