CodePudding user response:
My program mainly, timer timing, every 30 s inquiries to the sensor readings, I joined the RINGBUFFER where data reception (circular buffer array) into the timer interrupt, program will be stuck, I can be normal in an array of data can also be normal from the circular buffer array readout, RINGBUFFER is the main reference of wit cloud code;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
C
* @ file ringbuffer.* @ brief Loop buffer processing
* @ Author Gizwits
* @ the date 2017-07-19
* @ version V03030000
* @ copyright Gizwits
*
* @ note Gizwits is only for smart hardware
* Gizwits Smart Cloud for Smart Products
* the Links Value Added | | Open | Neutral | Safety | Own | | Free Ecology
* www.gizwits.com
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# include "ringBuffer. H"
# include "is common. H"
Rb_t DataRecievce;
Uint8_t rbBuf [18].
/* * * * * * * * * *
Create a circular buffer function of the
* * * * * * * * * * * * * * * * * * * */
Void RingbufferInit (void)
{
DataRecievce. RbCapacity=18;
DataRecievce. RbBuff=rbBuf;
If (0==rbCreate (& amp; DataRecievce))
{
Printf (" rbCreate success \ n ");
}
}
Int8_t ICACHE_FLASH_ATTR rbCreate rb_t * (rb)
{
If (NULL==rb)
{
return -1;
}
Rb - & gt; RbHead=rb - & gt; RbBuff;
Rb - & gt; RbTail=rb - & gt; RbBuff;
return 0;
}
/* * * * * * *
Ring buffer delete function
* * * * * * * * * */
Int8_t ICACHE_FLASH_ATTR rbDelete rb_t * (rb)
{
If (NULL==rb)
{
return -1;
}
Rb - & gt; RbBuff=NULL;
Rb - & gt; RbHead=NULL;
Rb - & gt; RbTail=NULL;
Rb - & gt; RbCapacity=0;
return 0;
}
/* * * *
Obtain the ring buffer capacity
* * * *
Int32_t ICACHE_FLASH_ATTR rbCapacity rb_t * (rb)
{
If (NULL==rb)
{
return -1;
}
The return of rb - & gt; RbCapacity;
}
/* * * * * * *
* * * * * * */
Int32_t ICACHE_FLASH_ATTR rbCanRead rb_t * (rb)
{
If (NULL==rb)
{
return -1;
}
If (rb - & gt; RbHead==rb - & gt; RbTail)
{
return 0;
}
If (rb - & gt; RbHead & lt; Rb - & gt; RbTail)
{
The return of rb - & gt; RbTail - rb - & gt; RbHead;
}
Return rbCapacity (rb) - (rb - & gt; RbHead - rb - & gt; RbTail);
}
Int32_t ICACHE_FLASH_ATTR rbCanWrite rb_t * (rb)
{
If (NULL==rb)
{
return -1;
}
Return rbCapacity (rb) - rbCanRead (rb);
}
Int32_t ICACHE_FLASH_ATTR rbRead (rb_t * rb, void * data, size_t count)
{
Int32_t copySz=0;
If (NULL==rb)
{
The return of 16;
}
If (NULL==data)
{
The return of 8;
}
If (rb - & gt; RbHead & lt;=rb - & gt; RbTail)
{
CopySz=min (count, rbCanRead (rb));
Memcpy (data, rb - & gt; RbHead copySz);
Rb - & gt; RbHead +=copySz;
Return copySz;
}
The else
{
If (count & lt; RbCapacity (rb) - (rb - & gt; RbHead - rb - & gt; RbBuff))
{
CopySz=count;
Memcpy (data, rb - & gt; RbHead copySz);
Rb - & gt; RbHead +=copySz;
Return copySz;
}
The else
{
CopySz=rbCapacity (rb) - (rb - & gt; RbHead - rb - & gt; RbBuff);
Memcpy (data, rb - & gt; RbHead copySz);
Rb - & gt; RbHead=rb - & gt; RbBuff;
CopySz +=rbRead (rb, (char *) data + copySz, count - copySz);
Return copySz;
}
}
}
//will be a certain length of data (count) address (data) from a paragraph written ring buffer
Int32_t ICACHE_FLASH_ATTR rbWrite (rb_t * rb, const void * data, size_t count)
{
Int32_t tailAvailSz=0;
If ((NULL==rb) | | (NULL==data))
{
return -1;
}
If (count & gt;=rbCanWrite (rb))
{
The return - 2;
}
If (rb - & gt; RbHead & lt;=rb - & gt; RbTail)
{
TailAvailSz=rbCapacity (rb) - (rb - & gt; RbTail - rb - & gt; RbBuff);//the number of the writeable=annular array capacity - (the tail pointer address - first annular array)
If (count & lt;=tailAvailSz)
{
Memcpy (rb - & gt; RbTail, data, count);
Rb - & gt; RbTail +=count;
If (rb - & gt; RbTail==rb - & gt; RbBuff + rbCapacity (rb))
{
Rb - & gt; RbTail=rb - & gt; RbBuff;
}
Return the count.
}
The else
{
Memcpy (rb - & gt; RbTail, data, tailAvailSz);
Rb - & gt; RbTail=rb - & gt; RbBuff;
Return tailAvailSz + rbWrite (rb, (char *) data + tailAvailSz, count - tailAvailSz);
}
}
The else
{
Memcpy (rb - & gt; RbTail, data, count);
Rb - & gt; RbTail +=count;
Return the count.
}
}
Clouds above is wit RINGBUFFER code
Below is I to the sensor information and receive response code (part)
//serial port interrupt service routine 2
Void USART2_IRQHandler (void)
{
If ((__HAL_UART_GET_FLAG (& amp; Huart2, UART_FLAG_RXNE)!=RESET))
{
Uart2_buff [uart2_p + +]=USART2 - & gt; DR.//in the array
}
If ((__HAL_UART_GET_FLAG (& amp; Huart2, UART_FLAG_IDLE)!=RESET))
{
__HAL_UART_CLEAR_IDLEFLAG (& amp; Huart2);
RbWrite (& amp; DataRecievce uart2_buff, uart2_p);//write loop buffer series
}
}
Void getWinddirectionData ()
{
AskCmd ((u8 *) WinddirectionAsk); nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull