2016-04-11 7 views
0

Ich habe zwei Dateien mit Code.Senden von Daten über eine Warteschlange in FreeRTOS

  1. Ethernet
  2. CAN

Und zwischen diesen Dateien würde ich das Senden von Daten mögen. So , in den CAN-Datei I-Struktur erstellt:

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; 

Und ich versuchte Initialise dieser Struktur mit meinen Testwert.

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; 

Und ich erstellte neue Aufgabe, während ich Daten alle 1s sende.

xQueueSend (fronta_gyroskop, (void *) &toSend , 10); 

In Ethernet-Datei ich initialisieren Warteschlange. In Ethernet-Datei:

  1. Initialise Warteschlange
  2. Erstellt erhalten Struktur für Daten
  3. Daten empfangen von der Warteschlange

-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; 

Und ich Daten in Aufgabe erhalten alle 1 Sekunde .

if (xQueueReceive(fronta_gyroskop, &gyro, 20)){ 
} 

Aber die Werte in Kreisel sind nicht meine Werte (1,2,3,4,5,6), aber die Werte sind zufällige 32-Bit-Werte. Irgendeine Idee, was mache ich falsch?

EDIT

CAN-Seite 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); 
    } 
} 
+0

Überprüfen Sie die Werte in 'if (xQueueReceive (fronta_gyroskop, & gyro, 20))'? Bist du dir sicher "fronta_gyroskop! = NULL"? – LPs

+0

Ja. Ich überprüfe innen velues (Kreisel). [link] (http://s23.postimg.org/afygiemxn/check.jpg) – Jirka

Antwort

0

Das Problem ist

xQueueSend (fronta_gyroskop, (void *) &toSend , 10); 

Sie senden die Adresse des Zeigers an die Daten.

Daten senden Sie Adresse von Daten direkt senden müssen:

xQueueSend (fronta_gyroskop, (void *) &data , 10); 
+0

Ouu. Also habe ich xQueueSend folgendermaßen korrigiert: xQueueSend (fronta_gyroskop, (void *) & data, 10); Jetzt sind erste und zweite Werte wahr, aber andere Werte sind falsch. Hier ist ein Screenshot der Werte. [link] (http://s15.postimg.org/q3l72tugb/values.jpg) – Jirka

+0

@Jirka Was ist 'Daten' Anwendungsbereich? Ist es lokal (Stapel zugeordnet) in eine Funktion oder global? – LPs

+0

'Daten' ist global Hier ist meine CAN-Datei: [CAN DATEI] (http://paste.ofcode.org/79BfWQ8sXqbfZ5UPiMLjgB) Und hier ist meine ETH-Datei: [ETH DATEI] (http: //paste.ofcode .org/tMJNjCZgpnxcauhUw6Xps2) – Jirka

0

Ok. Problem wurde gelöst.

Falsche Initialisierung der Warteschlange.

Hier ist gut init.

fronta_gyroskop = xQueueCreate(6, sizeof(struct ethernetData)); 
+0

Gut zu wissen ... – LPs

Verwandte Themen