Просмотр исходного кода

remove HAL dependency, remove Peripheral_typedef

Juraj Ďuďák 2 лет назад
Родитель
Сommit
96d7fa6f0c
5 измененных файлов с 77 добавлено и 29 удалено
  1. 22 0
      Core/Inc/app_interface.h
  2. 45 20
      Core/Src/main.c
  3. 1 1
      Modules/nbus
  4. 1 1
      Modules/one-wire-memory
  5. 8 7
      test/app.py

+ 22 - 0
Core/Inc/app_interface.h

@@ -0,0 +1,22 @@
+/*
+ * app_interface.h
+ *
+ *  Created on: Nov 22, 2023
+ *      Author: juraj
+ */
+
+#ifndef INC_APP_INTERFACE_H_
+#define INC_APP_INTERFACE_H_
+
+
+void led_on();
+void led_off();
+void led_toggle();
+void uart_receive_it(uint8_t *data, int n);
+void uart_abort_receive();
+void timer_uart_start(int n);
+void timer_uart_stop();
+void uart_send(uint8_t *data, int n);
+
+
+#endif /* INC_APP_INTERFACE_H_ */

+ 45 - 20
Core/Src/main.c

@@ -22,7 +22,13 @@
 /* Private includes ----------------------------------------------------------*/
 /* USER CODE BEGIN Includes */
 #include "nbus_app.h"
+#if MODULE == MODULE_FSR
 #include "app_adc.h"
+#endif
+#if MODULE == MODULE_DUMMY
+#include "app_dummy.h"
+#endif
+#include "app_interface.h"
 /* USER CODE END Includes */
 
 /* Private typedef -----------------------------------------------------------*/
@@ -68,7 +74,7 @@ static void MX_ADC_Init(void);
 
 /* Private user code ---------------------------------------------------------*/
 /* USER CODE BEGIN 0 */
-void uart_send(uint8_t *data, int n)
+inline void uart_send(uint8_t *data, int n)
 {
 #if USE_USART_DMA_TX == 1
 		HAL_UART_Transmit_DMA(&huart2, data, n);
@@ -77,26 +83,45 @@ void uart_send(uint8_t *data, int n)
 #endif
 }
 
-void led_on(){
+
+inline void led_on(){
 	HAL_GPIO_WritePin(LD3_GPIO_Port, LD3_Pin, GPIO_PIN_SET);
 }
 
-void led_off(){
+inline void led_off(){
 	HAL_GPIO_WritePin(LD3_GPIO_Port, LD3_Pin, GPIO_PIN_RESET);
 }
 
-void led_toggle(){
+inline void led_toggle(){
 	HAL_GPIO_TogglePin(LD3_GPIO_Port, LD3_Pin);
 }
 
-void uart_receive_it(uint8_t *data, int n)
+inline void uart_receive_it(uint8_t *data, int n)
 {
 	HAL_UART_Receive_IT(&huart2, data, n);
 }
 
-void uart_abort_receive(){
+inline void uart_abort_receive(){
 	HAL_UART_AbortReceive_IT(&huart2);
 }
+
+inline void timer_uart_start(int n){
+	htim22.Instance->CNT = 1;
+	htim22.Instance->ARR = 40*n + 400; // (10*n + 100)us
+	HAL_TIM_Base_Start_IT(&htim22);
+}
+
+inline void timer_uart_stop(){
+	HAL_TIM_Base_Stop_IT(&htim22);
+}
+
+static inline void nbus_app_UART_RX(UART_HandleTypeDef *huart){
+	nbus_cb_UART_RX();
+}
+
+static inline void nbus_app_TIM_periodElapsed(TIM_HandleTypeDef *htim){
+	nbus_cb_TIM_periodElapsed();
+}
 /* USER CODE END 0 */
 
 /**
@@ -152,34 +177,32 @@ int main(void)
 		  led_on,
 		  led_off,
 		  led_toggle,
+		  timer_uart_start,
+		  timer_uart_stop
   };
 
-
-
-  Peripheral_typeDef periph;
-  //periph.huart = &huart2;
-  periph.uart_timer = &htim22;
-  periph.measure_timer = &htim21;	// TODO ?
-  //periph.adc = NULL;
-  //periph.led = &Led;
 #if MODULE_MASTER == 1
   periph.rtc = &hrtc;
 #endif
 
 
-  //nBusAppInterface_t *dummy = getDummyDriver();
+#if MODULE == MODULE_DUMMY
+  nbus_init(getDummyDriver(), &hw_platform);
+  nbus_init_app(NULL, NULL);
+#endif
 
 #if MODULE == MODULE_FSR
-  nbus_init(&periph, getMcuAdcDriver(), &hw_platform);
+  nbus_init(getMcuAdcDriver(), &hw_platform);
+  nbus_init_app(&hadc, NULL);
 #endif
 
 #if MODULE == MODULE_IMU
-  nbus_init(&periph, getImuDriver());
+  nbus_init(getImuDriver(), &hw_platform);
+  nbus_init_app(&hspi, NULL);
 #endif
 
-  HAL_UART_RegisterCallback(&huart2, HAL_UART_RX_COMPLETE_CB_ID, nbus_cb_UART_RX);
-
-  nbus_init_app(&hadc, NULL);
+  HAL_UART_RegisterCallback(&huart2, HAL_UART_RX_COMPLETE_CB_ID, nbus_app_UART_RX);
+  HAL_TIM_RegisterCallback(&htim22, HAL_TIM_PERIOD_ELAPSED_CB_ID, nbus_app_TIM_periodElapsed);
 
   nBus_MemoryDriver memory_ec20 = {
   		DS28EC20_init,
@@ -189,8 +212,10 @@ int main(void)
   		DS28EC20_writeData2B,
 		DS28EC20_getId
   };
+
   memory_ec20.init(ONE_WIRE_GPIO_Port, ONE_WIRE_Pin);
   nbus_init_memory_driver(&memory_ec20,16);
+
   nbus_stack();
 
   /* USER CODE END 2 */

+ 1 - 1
Modules/nbus

@@ -1 +1 @@
-Subproject commit 80d063752f58ff0cfce21bff25d1df393bed5455
+Subproject commit 851a5ffdd60b4b8621f389542fa82fa91de36957

+ 1 - 1
Modules/one-wire-memory

@@ -1 +1 @@
-Subproject commit 9200beb0ae0591ff038e0014ad946f2e019eff37
+Subproject commit 9d08aa557d3f29bc1705bb6f8964f4e863bb74a7

+ 8 - 7
test/app.py

@@ -15,8 +15,7 @@ class AppTest:
         version = chr(resp[3])+chr(resp[4])+chr(resp[5])
         print("Version: "+version)
 
-    def cmd_echo(self):
-        msg=[65,66,67,68,69,70]
+    def cmd_echo(self, msg):        
         resp = self.serial_port.request(self.module, 0, CMD_ECHO,msg)
         echo = ""
         for r in range(len(msg)):
@@ -94,17 +93,19 @@ class AppTest:
 if __name__ == "__main__":
     
     app = AppTest(0x05, 0x0)
-    # app.cmd_version()
-    # app.cmd_version()
-    # app.cmd_echo()
-
+    #app.cmd_version()
+    #app.cmd_version()
+    app.cmd_echo([65,66,67,68,69,70])
+    app.cmd_echo([10,11,12])
+    
+    
     app.cmd_module_start()
 
     pocet = app.cmd_sensor_cnt()
     print("pocet senzorov=", pocet)
     app.cmd_sensor_get_data_all(pocet)
 
-    # quit()
+    
     for i in range(pocet):
         d=app.cmd_sensor_get_data(i+1)
         print("Data", i+1, ":\t", d)