Selaa lähdekoodia

rely on circular UART RX FIFO buffer in app

Juraj Ďuďák 3 viikkoa sitten
vanhempi
commit
1b21f45e6e
3 muutettua tiedostoa jossa 14 lisäystä ja 37 poistoa
  1. 0 2
      include/nbus_app.h
  2. 7 17
      include/nbus_types.h
  3. 7 18
      src/nbus_app.c

+ 0 - 2
include/nbus_app.h

@@ -21,8 +21,6 @@ extern "C"
     void nbus_init_app(void *hw_interface, void *hw_config);
     void nbus_stack(void);
     void nbus_init_memory_driver(nBus_MemoryDriver *memDriver);
-
-    void nbus_cb_UART_RX(int);
     void nbus_cb_TIM_periodElapsed(void);
 
 #ifdef __cplusplus

+ 7 - 17
include/nbus_types.h

@@ -116,20 +116,6 @@ typedef struct __attribute__((packed))
     uint8_t type : 3;
 } nBus_sensorByte_t;
 
-/**
- * @brief Stavy komunikačného rozhrania počas behu programu.
- */
-typedef enum
-{
-    /** Čaká sa na príjem dát. Nasledujúci stav: UART_RX_RECEIVING */
-    UART_RX_WAIT,
-    /** Dáta sa prijímajú. Nasledujúci stav: UART_RX_RECEIVED */
-    UART_RX_RECEIVING,
-    /** Dáta sú prijané, v ďašom cykle sa budú spracovať. Nasledujúci stav:
-       UART_RX_WAIT*/
-    UART_RX_RECEIVED
-} nBus_Uart_RX_state;
-
 /**
  * @brief Určuje typ nBUS príkazu.
  */
@@ -232,6 +218,13 @@ typedef struct
      * pre ukočenie načítania, ktoré bolo sputené cez uart_receive
      */
     uint8_t (*loop_callback)(nBusStateCallbackType_t);
+    /**
+     * @brief Načítanie pripraveného paketu pre spracovanie v nBUS.
+     * @param 1 parameter: smerník na RX buffer. Funkcia read_rx_packet sem skopíruje obsah RX baffera, ak je dostupný.
+     * @param 2 parameter:  bude obsahovať dĺžku prijatého paketu.
+     * @return 1 - v príapde, že dáta sú pripravené, 0 - v rpípade, že žiadne dáta nie sú v RC buffri UART
+     */
+    uint8_t (*read_rx_packet)(uint8_t *, uint8_t *);
 
 } nBusPlatformInterface_t;
 
@@ -276,9 +269,6 @@ typedef struct
     nBus_functionCode_t function_code;
     volatile nBusCommandType_t request_type;
 
-    /** @brief Flag pre signalizaciu ukoncenia primu dat cez UART. */
-    volatile nBus_Uart_RX_state uart_state;
-
     nBus_response_t send_response;
 
     /** @brief CRC8 sucet pre datovy ramec */

+ 7 - 18
src/nbus_app.c

@@ -99,6 +99,7 @@ static void process_request()
     // spracovanie broadcast komunikacie
     if ((request_type == BROADCAST_SPECIFIC_SENSORS || request_type == BROADCAST_GLOBAL))
     {
+    	nBus.hw_platform->led_on();
         nbus_slave_broadcast(&nBus, request_type);
         return;
     }
@@ -162,17 +163,7 @@ static void nbus_blink_LED(uint8_t delay)
 /* ----------------------- CALLBACKS----------------------- */
 /* -------------------------------------------------------- */
 
-/**
- * @brief UART receive complete.
- * This callback have to called from application, when RX data is ready.
- * @param int size Size of received packet
- * Received packet is located in uBus.rx_buffer
- */
-void nbus_cb_UART_RX(int size)
-{
-    nBus.rx_length = size;
-    nBus.uart_state = UART_RX_RECEIVED;
-}
+
 
 /* -------------------------------------------------------- */
 /* ------------------ PUBLIC FUNCTIONS-------------------- */
@@ -195,8 +186,6 @@ void nbus_init(nBusAppInterface_t *interface, nBusPlatformInterface_t *hw)
     nBus.data_timebase = 0;
     nBus.measure_active = MEASURE_STOPPED;
 
-    nBus.uart_state = UART_RX_WAIT;
-
     nBus.interface = interface;
 
     receivePacket();
@@ -272,19 +261,19 @@ void nbus_init_memory_driver(nBus_MemoryDriver *memDriver)
  */
 void nbus_stack(void)
 {
+	uint8_t packet_len = 0;
 
 #if USE_ARDUINO_FRAMWORK == 0
     nbus_blink_LED(50);
     while (1)
 #endif
     {
-        if (nBus.uart_state == UART_RX_RECEIVED)
+    	while(nBus.hw_platform->read_rx_packet(nBus.rx_buffer, &packet_len))
         {
-
+    		nBus.rx_length = packet_len;
             process_request();
-            nBus.hw_platform->led_off();
-            nBus.uart_state = UART_RX_WAIT;
             send_response();
+            nBus.hw_platform->led_off();
         }
 
         if (nBus.hw_platform->loop_callback != NULL)
@@ -292,7 +281,7 @@ void nbus_stack(void)
 
             if (nBus.hw_platform->loop_callback(CallbackType_SENSOR) == 1)
             {
-                nBus.interface->read();
+            	nBus.interface->read();
             }
 
             nBus.hw_platform->loop_callback(CallbackType_UART);