Reputation: 63
I have got two files with code.
And between this files I would like sending data. So, in the CAN file I created structure:
struct screenData {
uint16_t gyroskop_x;
uint16_t gyroskop_y;
uint16_t gyroskop_z;
uint16_t euler_x;
uint16_t euler_y;
uint16_t euler_z;
} data;
And I tried initialise of this structure with my test values.
struct screenData * toSend;
data.gyroskop_x = 1;
data.gyroskop_y = 2;
data.gyroskop_z = 3;
data.euler_x = 4;
data.euler_y = 5;
data.euler_z = 6;
toSend = &data;
And I created new task, whrere I sending data every 1s.
xQueueSend ( fronta_gyroskop, ( void * ) &toSend , 10 );
In ethernet file I initialise queue. In ethernet file:
Code
xQueueHandle fronta_gyroskop = 0;
extern void init_queue(void)
{
fronta_gyroskop = xQueueCreate(6, sizeof(struct ethernetData *));
}
struct ethernetData {
uint16_t gyroskop_x;
uint16_t gyroskop_y;
uint16_t gyroskop_z;
uint16_t euler_x;
uint16_t euler_y;
uint16_t euler_z;
} gyro;
And in task I receive data every 1second.
if (xQueueReceive(fronta_gyroskop, &gyro, 20)){
}
But the values in gyro aren't my values (1,2,3,4,5,6), but the values are random 32bit values. Any idea, what I doing wrong?
EDIT
CAN side code
#include "Tasky/Ethernet.h"
void *fronta_gyroskop;
can_mb_conf_t tx_mailbox;
can_mb_conf_t rx_mailbox;
/** Receive status */
volatile uint32_t g_ul_recv_status = 0;
void CAN0_Handler(void)
{
uint32_t ul_status;
ul_status = can_mailbox_get_status(CAN0, 0);
if (ul_status & CAN_MSR_MRDY) {
rx_mailbox.ul_status = ul_status;
can_mailbox_read(CAN0, &rx_mailbox);
g_ul_recv_status = 1;
}
}
struct screenData {
uint16_t gyroskop_x;
uint16_t gyroskop_y;
uint16_t gyroskop_z;
uint16_t euler_x;
uint16_t euler_y;
uint16_t euler_z;
} data;
extern void task_can_read(void *pvParameters)
{
UNUSED(pvParameters);
const portTickType xDelayTime = 10;
uint8_t nacti = 1;
/* init test value to sending */
struct screenData * toSend;
data.gyroskop_x = 1;
data.gyroskop_y = 2;
data.gyroskop_z = 3;
data.euler_x = 4;
data.euler_y = 5;
data.euler_z = 6;
toSend = &data;
for (;;){
if (!g_ul_recv_status) {
//puts("zadna zprava na CAN sbernici\r");
} else {
if ((rx_mailbox.ul_id >> 18) == FIRST_GYRO_ID) //rotation to 11bit number
{
//calculate
nacti = 1;
}
if ((rx_mailbox.ul_id >> 18) == SECOND_GYRO_ID)
{
//calculate
xQueueSend ( fronta_gyroskop, ( void * ) &data , 10 ); //send data over queue
nacti = 0;
}
if (nacti == 1)
{
rx_mailbox.ul_id = CAN_MID_MIDvA(SECOND_GYRO_ID);
can_mailbox_init(CAN0, &rx_mailbox);
}
if (nacti == 0)
{
rx_mailbox.ul_id = CAN_MID_MIDvA(FIRST_GYRO_ID);
can_mailbox_init(CAN0, &rx_mailbox);
}
g_ul_recv_status = 0; //clear flag
}
vTaskDelay(xDelayTime);
}
}
ETH code
#include "Tasky/CAN_TASKs.h"
struct tcp_pcb *output = NULL;
void *dataeth;
struct netif gs_net_if;
uint32_t g_ip_mode;
int8_t g_c_ipconfig[];
struct ethernetData {
uint16_t gyroskop_x;
uint16_t gyroskop_y;
uint16_t gyroskop_z;
uint16_t euler_x;
uint16_t euler_y;
uint16_t euler_z;
} gyro;
/************************************************************************/
/* INIT QUEU to analyze data from TCPIP */
/************************************************************************/
xQueueHandle fronta_gyroskop = 0;
extern void init_fronta_ethernet(void)
{
fronta_gyroskop = xQueueCreate(6, sizeof(struct ethernetData *));
}
/************************************************************************/
/* TASK of FREERTOS to TCPIP */
/************************************************************************/
extern void TCP_connection(void *pvParameters)
{
UNUSED(pvParameters);
const portTickType xDelayTime = 1000 / portTICK_RATE_MS;
uint16_t trest[6];
while (1){
if (xQueueReceive(fronta_gyroskop, &gyro, 10)){ //receive data over queue
tcp_write(output, (void *)&gyro, sizeof(gyro), TCP_WRITE_FLAG_COPY); //Write data for sending (but does not send it immediately)
tcp_sent(output, NULL); //Used to specify the function that should be called when TCP data has been successfully delivered to the remote host
tcp_output(output); //Find out what we can send and send it.
}
vTaskDelay(xDelayTime);
}
}
Upvotes: 1
Views: 3837
Reputation: 63
Ok. Problem was solved.
Wrong initialization of queue.
fronta_gyroskop = xQueueCreate(6, sizeof(struct ethernetData *));
Here is good init.
fronta_gyroskop = xQueueCreate(6, sizeof(struct ethernetData));
Upvotes: 1
Reputation: 16223
The problem is
xQueueSend ( fronta_gyroskop, ( void * ) &toSend , 10 );
You are sending address of pointer to data.
To send data you must send address of data directly:
xQueueSend ( fronta_gyroskop, ( void * ) &data , 10 );
Upvotes: 0