This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

关于在Zstack中设置定时器的问题

Other Parts Discussed in Thread: CC2530

1、我想在Zstack中循环设置一个定时器,每隔1ms中断一次去执行HalUARTPollDMA看缓存有没有数据,这样可以最大程度的保证DMA缓存只要来了一包数据,就能读出来,从而避免DMA缓存可能存在多包数据而造成的数据解析问题。这是我的想法,请问这种频繁的中断会不会对Osal自身的正常运行机制造成不利的影响?

  • 1msㄧ次太頻繁、肯定對osal造成衝擊
  • 那么,请问这个值设置为多少合适了

  • 这个就要你自己測試看看、建議不要低於200 ms
  • 您可以看一下CC2530 的 _hal_uart_dma.c

    // Minimum delay before allowing sleep and/or clearing DMA ready-out after a DMA ready-in ISR.
    // ST-ticks for 6-msecs plus 1 tick added for when the dmaRdyDly is forced from zero to 0xFF.
    // If a greater delay than 6-msec is configured, then the logic should be changed to use a uint16.
    //efine DMA_PM_DLY 198 // 32768 * 0.006 + 1 -> 198.
    // This delay should be set as short as possible to work with the max expected latency in the sender
    // between its asserting ready-out and its checking of the ready-in response. The RBA Master
    // logic in the internal uart-to-uart bridge app checks for ready-in immediately,
    // so this is just set to zero.

    系统在串口数据到来之前调用HalUARTPollDMA函数轮询串口中是否有数据。当UxDBUF中有数据时,直接利用DMA传输,一一将UxDBUF的数据发送到了rxBuf中了,而HalUARTPollDMA轮询时候只是检查rxBuf中时候有新的数据,就是宏HAL_UART_DMA_NEW_RX_BYTE的作用。当检查到rxBuf中有数据时,则会经过很小的一段时间,这个时间可以通过HAL_UART_DMA_IDLE计算出来,此值为198,乘以32KHz的时钟频率即是!程序中会判断是否经过了这么长时间,如果是,则会置相应串口事件,从而调用串口回调函数,在这个回调函数里面,通常我们会调用HalUARTReadDMA函数将缓冲区中的数据读取出来。
    摘自: blog.csdn.net/.../8597380
  • 恩恩,但是HalUARTPollDMA只会在Osal_run_system每循环一次之后才会调用一次,这样可能导致Osal_run_system一旦被其他任务拖住了,就无法及时的从DMA缓存中读取数据,这样有可能造成好几包数据在DMA缓存堆积甚至可能被覆盖,我就是在想办法如何避免这种情况