|
|
@@ -148,16 +148,7 @@ static void process_request(){
|
|
|
|
|
|
}
|
|
|
|
|
|
-/* -------------------------------------------------------- */
|
|
|
-/* ----------------------- CALLBACKS----------------------- */
|
|
|
-/* -------------------------------------------------------- */
|
|
|
-
|
|
|
-void nbus_cb_UART_RX(int size){
|
|
|
- nBus.rx_length = size;
|
|
|
- nBus.uart_state = UART_RX_RECEIVED;
|
|
|
-}
|
|
|
-
|
|
|
-void nbus_blink_LED(uint8_t delay) {
|
|
|
+static void nbus_blink_LED(uint8_t delay) {
|
|
|
nBus.hw_platform->led_on();
|
|
|
nBus.hw_platform->delay_ms(delay);
|
|
|
nBus.hw_platform->led_off();
|
|
|
@@ -168,11 +159,33 @@ void nbus_blink_LED(uint8_t delay) {
|
|
|
nBus.hw_platform->delay_ms(delay);
|
|
|
}
|
|
|
|
|
|
+/* -------------------------------------------------------- */
|
|
|
+/* ----------------------- CALLBACKS----------------------- */
|
|
|
+/* -------------------------------------------------------- */
|
|
|
+
|
|
|
+/**
|
|
|
+ * @brief UART receive complete
|
|
|
+ * @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-------------------- */
|
|
|
/* -------------------------------------------------------- */
|
|
|
|
|
|
+/**
|
|
|
+ * @brief Initialize of nBus stack
|
|
|
+ * @param interface Driver for module application.
|
|
|
+ * Every application have to implement base functions as Init, Reset, GetData, SetData, GetParam, SetParam, .... @see nBusAppInterface_t
|
|
|
+ * These are application dependent functions.
|
|
|
+ * @param hw Application level implementation of base functions (uart_receive, uart_transmit, led_on/off/toggle, ...).
|
|
|
+ * These are MCU dependent functions.
|
|
|
+ */
|
|
|
void nbus_init(nBusAppInterface_t *interface, nBusPlatformInterface_t *hw){
|
|
|
nBus.hw_platform = hw;
|
|
|
|
|
|
@@ -188,16 +201,45 @@ void nbus_init(nBusAppInterface_t *interface, nBusPlatformInterface_t *hw){
|
|
|
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * @brief Initialize concrete application, if it is needed.
|
|
|
+ * This function call "init()" function from nBusPlatformInterface_t, and this function is implemented in concrete application.
|
|
|
+ * @param hw_interface Pointer to hardware definition structure. In STM32 it can be hSPI, hUART, hADC, ...
|
|
|
+ * @param hw_config configuration for hardware structure object.
|
|
|
+ */
|
|
|
void nbus_init_app(void *hw_interface, void *hw_config){
|
|
|
nBus.interface->init(hw_interface, hw_config);
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * @brief Init memory driver for storing module/sensor parameters.
|
|
|
+ * Implementation of memory driver is independent from nBus. To provide nonvolatile parameters store, is nneded implement this driver.
|
|
|
+ * @param memDriver Memory driver for bas operation: read/write 1/2/4 byte from/to memory
|
|
|
+ * @param capacity TBD
|
|
|
+ * @todo imeplement capacity parameter
|
|
|
+ */
|
|
|
void nbus_init_memory_driver(nBus_MemoryDriver *memDriver, uint16_t capacity){
|
|
|
nbus_memory_init(memDriver);
|
|
|
nBus.memoryInterface = getnbusMemoryInterface();
|
|
|
nbus_blink_LED(100);
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * @brief Run protocol stack.
|
|
|
+ * This is infinity protocol loop.
|
|
|
+ * When stack is started (or reset) it blink as boot sign.
|
|
|
+ *
|
|
|
+ * Content of loop:
|
|
|
+ * - if data was received: process request. Determine addressee and type of request
|
|
|
+ * - execute request or discard request
|
|
|
+ * - send response (only for unicast requests)
|
|
|
+ *
|
|
|
+ * In each iteration, the state of application flags are performed. The state of application is noticed from loop_callback() (if it is defined).
|
|
|
+ * Meaning of return values:
|
|
|
+ * - 0 - No event occurs,
|
|
|
+ * - 1 - data from connected sensors are prepared, it will be read with read() function automatically.
|
|
|
+ * - 2 - communication error/timeout. The reception of packed process will be reset.
|
|
|
+ */
|
|
|
void nbus_stack(void){
|
|
|
|
|
|
nbus_blink_LED(50);
|
|
|
@@ -214,9 +256,14 @@ void nbus_stack(void){
|
|
|
#endif
|
|
|
}
|
|
|
|
|
|
- if (nBus.uart_state != UART_RX_RECEIVING && nBus.hw_platform->loop_callback != NULL) {
|
|
|
- if (nBus.hw_platform->loop_callback() == 1){
|
|
|
+ if (nBus.hw_platform->loop_callback != NULL) {
|
|
|
+ switch (nBus.hw_platform->loop_callback()){
|
|
|
+ case 1:
|
|
|
nBus.interface->read();
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ nBus.uart_state = UART_RX_WAIT;
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
}
|