|
|
@@ -40,28 +40,35 @@ static uint8_t crc8x_fast(void const *mem, uint16_t len) {
|
|
|
|
|
|
|
|
|
inline static void receiveOneByte(){
|
|
|
- HAL_UART_AbortReceive_IT(nBus.periph->huart);
|
|
|
- HAL_UART_Receive_IT(nBus.periph->huart, nBus.rx_buffer, 1);
|
|
|
+ //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;
|
|
|
}
|
|
|
|
|
|
inline static void receiveNBytes(uint8_t n){
|
|
|
nBus.rx_length = n;
|
|
|
- HAL_UART_Receive_IT(nBus.periph->huart, nBus.rx_buffer, nBus.rx_length);
|
|
|
+ //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;
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
+ //HAL_GPIO_WritePin(nBus.periph->led->port, nBus.periph->led->pin, GPIO_PIN_RESET);
|
|
|
+ nBus.hw_platform->led_off();
|
|
|
}
|
|
|
|
|
|
#if MODULE_MASTER == 1
|
|
|
@@ -164,14 +171,16 @@ static void process_request(){
|
|
|
/* -------------------------------------------------------- */
|
|
|
/* ----------------------- CALLBACKS----------------------- */
|
|
|
/* -------------------------------------------------------- */
|
|
|
-static void nbus_cb_UART_RX(UART_HandleTypeDef *huart){
|
|
|
+//static void nbus_cb_UART_RX(UART_HandleTypeDef *huart){
|
|
|
+void nbus_cb_UART_RX(){
|
|
|
if(nBus.uart_state == UART_RX_PAYLOAD) {
|
|
|
nBus.uart_state = UART_RECEIVED;
|
|
|
HAL_TIM_Base_Stop_IT(nBus.periph->uart_timer);
|
|
|
}
|
|
|
|
|
|
if(nBus.uart_state == UART_RX_1B) {
|
|
|
- HAL_GPIO_WritePin(nBus.periph->led->port, nBus.periph->led->pin, GPIO_PIN_SET);
|
|
|
+ //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]);
|
|
|
|
|
|
@@ -187,14 +196,17 @@ static void nbus_cb_UART_RX(UART_HandleTypeDef *huart){
|
|
|
}
|
|
|
|
|
|
static void nbus_cb_TIM_periodElapsed_base(TIM_HandleTypeDef *htim) {
|
|
|
- HAL_GPIO_TogglePin(nBus.periph->led->port, nBus.periph->led->pin);
|
|
|
+ //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) {
|
|
|
if(nBus.uart_state == UART_RX_PAYLOAD) {
|
|
|
- HAL_GPIO_WritePin(nBus.periph->led->port, nBus.periph->led->pin, GPIO_PIN_RESET);
|
|
|
+ //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);
|
|
|
+ //HAL_UART_AbortReceive_IT(nBus.periph->huart);
|
|
|
+ nBus.hw_platform->uart_abort_receive();
|
|
|
receiveOneByte();
|
|
|
}
|
|
|
}
|
|
|
@@ -205,12 +217,14 @@ static void nbus_cb_TIM_periodElapsed(TIM_HandleTypeDef *htim) {
|
|
|
/* ------------------ PUBLIC FUNCTIONS-------------------- */
|
|
|
/* -------------------------------------------------------- */
|
|
|
|
|
|
-void nbus_init(Peripheral_typeDef *periph, nBusAppInterface_t *interface){
|
|
|
+void nbus_init(Peripheral_typeDef *periph, nBusAppInterface_t *interface, nBusPlatformInterface_t *hw){
|
|
|
nBus.periph = periph;
|
|
|
+ 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);
|
|
|
- HAL_UART_RegisterCallback(nBus.periph->huart, HAL_UART_RX_COMPLETE_CB_ID, nbus_cb_UART_RX);
|
|
|
+ // 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;
|