Răsfoiți Sursa

remove HAL dependency

Juraj Ďuďák 2 ani în urmă
părinte
comite
851a5ffdd6
4 a modificat fișierele cu 17 adăugiri și 92 ștergeri
  1. 3 2
      Inc/nbus_app.h
  2. 1 1
      Inc/nbus_memory.h
  3. 2 49
      Inc/nbus_types.h
  4. 11 40
      Src/nbus_app.c

+ 3 - 2
Inc/nbus_app.h

@@ -22,13 +22,14 @@
 #include "memory_ec20.h"
 
 
-void nbus_init(Peripheral_typeDef *periph, nBusAppInterface_t *interface, nBusPlatformInterface_t *hw);
+void nbus_init(nBusAppInterface_t *interface, nBusPlatformInterface_t *hw);
 void nbus_init_app(void *hw_interface, void *hw_config);
 void nbus_stack(void);
 void nbus_init_memory_driver(nBus_MemoryDriver *memDriver, uint16_t capacity);
 
 
-void nbus_cb_UART_RX();
+void nbus_cb_UART_RX(void);
+void nbus_cb_TIM_periodElapsed(void);
 
 #endif
 

+ 1 - 1
Inc/nbus_memory.h

@@ -13,7 +13,7 @@
 
 
 typedef struct{
-	uint8_t (*init)(GPIO_TypeDef*, uint16_t);
+	uint8_t (*init)(void*, uint16_t);
 	uint32_t (*read_word)(uint16_t);
 	uint16_t (*read_half_word)(uint16_t);
 	/**

+ 2 - 49
Inc/nbus_types.h

@@ -43,50 +43,6 @@ typedef enum {
 } DataReadyTypedef;
 
 
-/**
- * @brief Definícia periférií pre protokol uBUS.
- */
-typedef struct {
-    /** @brief Handler pre rozhranie UART */
-    //UART_HandleTypeDef* huart;
-
-    /**
-    * @brief Časovač pre detekciu timeoutu na UART.
-    */
-    TIM_HandleTypeDef* uart_timer;
-
-    /**
-    * @brief Časovač časovú značku merania. Rozlíšenie: 0.1ms
-    */
-    TIM_HandleTypeDef* measure_timer;
-
-    // doplnkove periferie
-
-#if SELF_MONITORING == 1
-    // in case of error in this place, set the macro SELF_MONITORING to 0
-    /**
-     * @brief ADC periféria pre monitorovanie vnúterného stavu modulu.
-     *
-     * Táto vlastnosť je aktívna len v prípade ak má makro SELF_MONITORING hodnotu 1
-     */
-    ADC_HandleTypeDef* adc;
-#else
-    void* adc;
-#endif
-
-    /**
-     * @brief Definícia pinu pre signalizačnú LED diódu
-     */
-   // McuPin_typeDef* led;
-
-#if MODULE_MASTER == 1
-    RTC_HandleTypeDef *rtc;
-#endif
-
-
-} Peripheral_typeDef;
-
-
 
 typedef struct __attribute__((packed)) {
 	uint8_t function : 5;
@@ -148,6 +104,8 @@ typedef struct{
 	void (*led_on)(void);
 	void (*led_off)(void);
 	void (*led_toggle)(void);
+	void (*timer_uart_start)(int);
+	void (*timer_uart_stop)(void);
 
 }nBusPlatformInterface_t;
 
@@ -201,11 +159,6 @@ typedef struct {
 
     volatile nBusMeasurementActive_t measure_active;
 
-    /**
-     * @brief Periférie protokolu uBUS.
-     */
-    Peripheral_typeDef* periph;
-
     volatile uint32_t data_timebase;
 
     nBusAppInterface_t *interface;

+ 11 - 40
Src/nbus_app.c

@@ -38,11 +38,8 @@ static uint8_t crc8x_fast(void const *mem, uint16_t len) {
 }
 
 
-
 inline static void receiveOneByte(){
-	//HAL_UART_AbortReceive_IT(nBus.periph->huart);
 	nBus.hw_platform->uart_abort_receive();
-	//HAL_UART_Receive_IT(nBus.periph->huart, nBus.rx_buffer, 1);
 	nBus.hw_platform->uart_receive(nBus.rx_buffer, 1);
 	nBus.uart_state = UART_RX_1B;
 	nBus.rx_length = 1;
@@ -50,7 +47,6 @@ inline static void receiveOneByte(){
 
 inline static void receiveNBytes(uint8_t n){
 	nBus.rx_length = n;
-	//HAL_UART_Receive_IT(nBus.periph->huart, nBus.rx_buffer, nBus.rx_length);
 	nBus.hw_platform->uart_receive(nBus.rx_buffer, nBus.rx_length);
 	nBus.uart_state = UART_RX_PAYLOAD;
 }
@@ -59,15 +55,7 @@ inline static void send_response(){
 	if(nBus.send_response == SEND_RESPONSE) {
 		nBus.tx_buffer[0] -= 1;		// prvý bajt sa nepočíta
 		nBus.hw_platform->uart_transmit(nBus.tx_buffer, nBus.tx_length);
-		/*
-#if USE_USART_DMA_TX == 1
-		HAL_UART_Transmit_DMA(nBus.periph->huart, nBus.tx_buffer, nBus.tx_length);
-#else
-		HAL_UART_Transmit(nBus.periph->huart, nBus.tx_buffer, nBus.tx_length, 10);
-#endif
-*/
 	}
-	//HAL_GPIO_WritePin(nBus.periph->led->port, nBus.periph->led->pin, GPIO_PIN_RESET);
 	nBus.hw_platform->led_off();
 }
 
@@ -171,23 +159,19 @@ static void process_request(){
 /* -------------------------------------------------------- */
 /* ----------------------- CALLBACKS----------------------- */
 /* -------------------------------------------------------- */
-//static void nbus_cb_UART_RX(UART_HandleTypeDef *huart){
-void nbus_cb_UART_RX(){
+
+void nbus_cb_UART_RX(void){
 	if(nBus.uart_state == UART_RX_PAYLOAD) {
 		nBus.uart_state = UART_RECEIVED;
-		HAL_TIM_Base_Stop_IT(nBus.periph->uart_timer);
+		nBus.hw_platform->timer_uart_stop();
 	}
 
 	if(nBus.uart_state == UART_RX_1B) {
-		//HAL_GPIO_WritePin(nBus.periph->led->port, nBus.periph->led->pin, GPIO_PIN_SET);
 		nBus.hw_platform->led_on();
 		if(nBus.rx_buffer[0] > 0) {
 			receiveNBytes(nBus.rx_buffer[0]);
-
-			HAL_TIM_Base_Stop_IT(nBus.periph->uart_timer);
-			nBus.periph->uart_timer->Instance->CNT = 1;
-			nBus.periph->uart_timer->Instance->ARR = 40*nBus.rx_buffer[0] + 400;
-			HAL_TIM_Base_Start_IT(nBus.periph->uart_timer);
+			nBus.hw_platform->timer_uart_stop();
+			nBus.hw_platform->timer_uart_start(nBus.rx_buffer[0]);
 		} else {
 			receiveOneByte();
 		}
@@ -195,17 +179,11 @@ void nbus_cb_UART_RX(){
 
 }
 
-static void nbus_cb_TIM_periodElapsed_base(TIM_HandleTypeDef *htim) {
-	//HAL_GPIO_TogglePin(nBus.periph->led->port, nBus.periph->led->pin);
-	nBus.hw_platform->led_toggle();
-}
 
-static void nbus_cb_TIM_periodElapsed(TIM_HandleTypeDef *htim) {
+void nbus_cb_TIM_periodElapsed(void) {
 	if(nBus.uart_state == UART_RX_PAYLOAD) {
-		//HAL_GPIO_WritePin(nBus.periph->led->port, nBus.periph->led->pin, GPIO_PIN_RESET);
 		nBus.hw_platform->led_off();
-		HAL_TIM_Base_Stop_IT(nBus.periph->uart_timer);
-		//HAL_UART_AbortReceive_IT(nBus.periph->huart);
+		nBus.hw_platform->timer_uart_stop();
 		nBus.hw_platform->uart_abort_receive();
 		receiveOneByte();
 	}
@@ -217,32 +195,25 @@ static void nbus_cb_TIM_periodElapsed(TIM_HandleTypeDef *htim) {
 /* ------------------ PUBLIC FUNCTIONS-------------------- */
 /* -------------------------------------------------------- */
 
-void nbus_init(Peripheral_typeDef *periph, nBusAppInterface_t *interface, nBusPlatformInterface_t *hw){
-  nBus.periph = periph;
+void nbus_init(nBusAppInterface_t *interface, nBusPlatformInterface_t *hw){
   nBus.hw_platform = hw;
 
-  HAL_TIM_RegisterCallback(nBus.periph->uart_timer, HAL_TIM_PERIOD_ELAPSED_CB_ID, nbus_cb_TIM_periodElapsed);
-  HAL_TIM_RegisterCallback(nBus.periph->measure_timer, HAL_TIM_PERIOD_ELAPSED_CB_ID, nbus_cb_TIM_periodElapsed_base);
-  // TODO vymysiet ako to urobit
-  //HAL_UART_RegisterCallback(nBus.periph->huart, HAL_UART_RX_COMPLETE_CB_ID, nbus_cb_UART_RX);
-
   nBus.rx_length = 0;
   nBus.data_timebase = 0;
   nBus.measure_active = MEASURE_STOPPED;
 
   // init restart timer
   nBus.uart_state = UART_RX_1B;
-  HAL_TIM_Base_Start_IT(periph->uart_timer);
-  HAL_TIM_Base_Stop_IT(periph->uart_timer);
+  nBus.hw_platform->timer_uart_start(100);	 // dummy value
+  nBus.hw_platform->timer_uart_stop();
 
   nBus.interface = interface;
+  receiveOneByte();
 
 }
 
 void nbus_init_app(void *hw_interface, void *hw_config){
 	nBus.interface->init(hw_interface, hw_config);
-
-	receiveOneByte();
 }
 
 void nbus_init_memory_driver(nBus_MemoryDriver *memDriver, uint16_t capacity){