传输两个缓冲区(Transmitte Two buffers Consequtively)

编程入门 行业动态 更新时间:2024-10-15 14:15:49
传输两个缓冲区(Transmitte Two buffers Consequtively)

我有两个字符缓冲区,我正在收集数据。

TxBuffer[1400]; TxBuffer2[1400]

我有一种情况是,一个缓冲区将在uart上一次传输,而在另一个缓冲区上我将收集数据,在传输一个缓冲区后,其他缓冲区应该传输。 有没有办法做到这一点,不使用memset。 我的代码流程如下。

将从buff1中的传感器收集数据 此时buff2将发送 发送buff2后,buff1应该发送 当buff1正在传输时,将在buff2上收集数据。

如上所述,我想添加我尝试过的内容,如下所示。 我在一个缓冲区中使用了两个指向特定地址偏移的char指针,如下所示。

unsigned char *block1_ptr = &TxBuffer[Sensor1_Data]; unsigned char *block2_ptr = &TxBuffer[Sensor1_Data +700];

一个1ms我从传感器收集我的数据到这个缓冲区。 如下。

Sensor1_dataptr = Sensor1_GetData(); *block1_ptr = Sensor1_dataptr->datax0; block1_ptr++; *block1_ptr = Sensor1_dataptr->datax1; block1_ptr++; *block1_ptr = Sensor1_dataptr->datay0; block1_ptr++; *block1_ptr = Sensor1_dataptr->datay1; block1_ptr++; *block1_ptr = Sensor1_dataptr->dataz0; block1_ptr++; *block1_ptr = Sensor1_dataptr->dataz1; block1_ptr++;

像这样我也在收集其他传感器的数据。 收集数据后,我通过dma发送给uart。 我的问题是,我必须在一个缓冲区中收集数据而其他缓冲区正在传输,反之亦然,但是如何更改缓冲区,因为tx每隔50ms发生一次,每1ms收集一次数据。 我的dma配置。 如下,

dmaconfig->source = &TxBuffer[Sensor1_Data]; dmaconfig->destination = &UCA0TXBUF; dmaconfig->size = 1400; DMAInit(dmaconfig); DMA_TRIGGER();

我试过有一个标志,当dma完成Tx后会重置。 另外,我保持一个条件如下

if(flag == set) { Transmit_buff = &TxBuffer[1400]; }else{ &TxBuffer[1400]; }

当我从传感器收集数据时,我正在设置标记。但是它不起作用。

I have Two character Buffers, on which I am gathering data.

TxBuffer[1400]; TxBuffer2[1400]

I have a situation is that, One buffer will be transmitting at a time over uart and on the other buffer I will be felling data,after one buffer is transmitted other buffer should transmit. Is there any way to do it, Without using memset.? My code flow is as below.

Data will be collected from sensors in buff1 at this time the buff2 will be transmitting after buff2 is transmitted, the buff1 should transmit when buff1 is transmitting , data will be collected on buff2.

As per above I would like add what i have tried, as below. I took 2 char pointers pointing to particular address offset in one buffer as below.

unsigned char *block1_ptr = &TxBuffer[Sensor1_Data]; unsigned char *block2_ptr = &TxBuffer[Sensor1_Data +700];

and one 1ms I am collecting my data from sensor to this buffer. as below.

Sensor1_dataptr = Sensor1_GetData(); *block1_ptr = Sensor1_dataptr->datax0; block1_ptr++; *block1_ptr = Sensor1_dataptr->datax1; block1_ptr++; *block1_ptr = Sensor1_dataptr->datay0; block1_ptr++; *block1_ptr = Sensor1_dataptr->datay1; block1_ptr++; *block1_ptr = Sensor1_dataptr->dataz0; block1_ptr++; *block1_ptr = Sensor1_dataptr->dataz1; block1_ptr++;

as like this I am also collecting data from other sensor as well. After collecting data I am sending to uart over dma. My problem is , I have to collect data in one buffer while other is transmitting and vice versa, but how to change buffer, as tx happens at arond every 50ms and collecting of data every 1ms. My dma config. is as below,

dmaconfig->source = &TxBuffer[Sensor1_Data]; dmaconfig->destination = &UCA0TXBUF; dmaconfig->size = 1400; DMAInit(dmaconfig); DMA_TRIGGER();

I have Tried To have one flag that will reset when dma is done with Tx. Also I am keeping one condition as follows

if(flag == set) { Transmit_buff = &TxBuffer[1400]; }else{ &TxBuffer[1400]; }

I am setting flag while I am collecting data from sensors.But it's not working.

最满意答案

你可以使用缓冲区指针,交换它们而不是复制数据,也许就像这样

int main(void) { char Buff1[180]; char Buff2[180]; char *prxbuf = Buff1; char *ptxbuf = Buff2; char *temp; while (1) { // receive using prxbuf // transmit using ptxbuf // swap the buffer pointers temp = prxbuf; prxbuf = ptxbuf; ptxbuf = temp; } return 0; }

You can use buffer pointers, and swap them instead of copying the data, perhaps like this

int main(void) { char Buff1[180]; char Buff2[180]; char *prxbuf = Buff1; char *ptxbuf = Buff2; char *temp; while (1) { // receive using prxbuf // transmit using ptxbuf // swap the buffer pointers temp = prxbuf; prxbuf = ptxbuf; ptxbuf = temp; } return 0; }

更多推荐

本文发布于:2023-08-07 06:00:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1461556.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:缓冲区   两个   Transmitte   buffers   Consequtively

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!