|
|
@@ -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){
|