Fixes after STM32 example merge
This commit is contained in:
parent
3bf5ed37c8
commit
c660369a43
@ -11,13 +11,11 @@
|
|||||||
static void blink(void* args);
|
static void blink(void* args);
|
||||||
static void modbus(void* args);
|
static void modbus(void* args);
|
||||||
|
|
||||||
uint32_t HAL_GetTick(void)
|
uint32_t HAL_GetTick(void) {
|
||||||
{
|
|
||||||
return xTaskGetTickCount();
|
return xTaskGetTickCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void) {
|
||||||
{
|
|
||||||
BSP_Init();
|
BSP_Init();
|
||||||
|
|
||||||
xTaskCreate(blink, "blink", 128, NULL, 4, NULL);
|
xTaskCreate(blink, "blink", 128, NULL, 4, NULL);
|
||||||
@ -28,10 +26,8 @@ int main(void)
|
|||||||
for (;;) {}
|
for (;;) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void blink(void* args)
|
static void blink(void* args) {
|
||||||
{
|
for (;;) {
|
||||||
for(;;)
|
|
||||||
{
|
|
||||||
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_SET);
|
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_SET);
|
||||||
vTaskDelay(500);
|
vTaskDelay(500);
|
||||||
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET);
|
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET);
|
||||||
@ -40,15 +36,19 @@ static void blink(void* args)
|
|||||||
}
|
}
|
||||||
|
|
||||||
nmbs_t nmbs;
|
nmbs_t nmbs;
|
||||||
nmbs_server_t nmbs_server =
|
nmbs_server_t nmbs_server = {
|
||||||
{
|
|
||||||
.id = 0x01,
|
.id = 0x01,
|
||||||
.coils = {0,},
|
.coils =
|
||||||
.regs = {0,},
|
{
|
||||||
|
0,
|
||||||
|
},
|
||||||
|
.regs =
|
||||||
|
{
|
||||||
|
0,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
static void modbus(void* args)
|
static void modbus(void* args) {
|
||||||
{
|
|
||||||
#if TEST_SERVER
|
#if TEST_SERVER
|
||||||
nmbs_server_init(&nmbs, &nmbs_server);
|
nmbs_server_init(&nmbs, &nmbs_server);
|
||||||
#endif
|
#endif
|
||||||
@ -68,8 +68,7 @@ static void modbus(void* args)
|
|||||||
nmbs_set_destination_rtu_address(&nmbs, 0x01);
|
nmbs_set_destination_rtu_address(&nmbs, 0x01);
|
||||||
nmbs_error status = nmbs_read_holding_registers(&nmbs, 0, 32, regs_test);
|
nmbs_error status = nmbs_read_holding_registers(&nmbs, 0, 32, regs_test);
|
||||||
status = nmbs_write_multiple_registers(&nmbs, 0, 32, regs_test);
|
status = nmbs_write_multiple_registers(&nmbs, 0, 32, regs_test);
|
||||||
if(status != NMBS_ERROR_NONE)
|
if (status != NMBS_ERROR_NONE) {
|
||||||
{
|
|
||||||
while (true) {}
|
while (true) {}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -1,14 +1,14 @@
|
|||||||
#include "blackpill/blackpill.h"
|
#include "blackpill/blackpill.h"
|
||||||
#include "wizchip.h"
|
#include "wizchip.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "FreeRTOS.h"
|
#include "FreeRTOS.h"
|
||||||
#include "task.h"
|
|
||||||
#include <socket.h>
|
|
||||||
#include "nanomodbus.h"
|
#include "nanomodbus.h"
|
||||||
#include "nmbs/port.h"
|
#include "nmbs/port.h"
|
||||||
|
#include "task.h"
|
||||||
|
#include <socket.h>
|
||||||
|
|
||||||
extern SPI_HandleTypeDef hspi1;
|
extern SPI_HandleTypeDef hspi1;
|
||||||
|
|
||||||
@ -20,45 +20,32 @@ wiz_NetInfo net_info = {
|
|||||||
.dns = {0, 0, 0, 0},
|
.dns = {0, 0, 0, 0},
|
||||||
}; // Network information.
|
}; // Network information.
|
||||||
|
|
||||||
uint8_t transaction_buf_sizes[] = {
|
uint8_t transaction_buf_sizes[] = {2, 2, 2, 2, 2, 2, 2, 2}; // All 2kB buffer setting for each sockets
|
||||||
2, 2, 2, 2, 2, 2, 2, 2
|
|
||||||
}; // All 2kB buffer setting for each sockets
|
|
||||||
|
|
||||||
#if USE_HAL_SPI_REGISTER_CALLBACKS == 0
|
#if USE_HAL_SPI_REGISTER_CALLBACKS == 0
|
||||||
|
|
||||||
void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi)
|
void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef* hspi) {
|
||||||
{
|
|
||||||
wizchip_dma_rx_cplt((void*) hspi);
|
wizchip_dma_rx_cplt((void*) hspi);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi)
|
void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef* hspi) {
|
||||||
{
|
|
||||||
wizchip_dma_tx_cplt((void*) hspi);
|
wizchip_dma_tx_cplt((void*) hspi);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
uint32_t HAL_GetTick(void)
|
uint32_t HAL_GetTick(void) {
|
||||||
{
|
|
||||||
return xTaskGetTickCount();
|
return xTaskGetTickCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void blink(void* args);
|
static void blink(void* args);
|
||||||
static void modbus(void* args);
|
static void modbus(void* args);
|
||||||
|
|
||||||
int main(void)
|
int main(void) {
|
||||||
{
|
|
||||||
BSP_Init();
|
BSP_Init();
|
||||||
wizchip_register_hal(
|
wizchip_register_hal(&hspi1, (fHalSpiTransaction) HAL_SPI_Receive, (fHalSpiTransaction) HAL_SPI_Transmit,
|
||||||
&hspi1,
|
(fHalSpiTransactionDma) HAL_SPI_Receive_DMA, (fHalSpiTransactionDma) HAL_SPI_Transmit_DMA,
|
||||||
(fHalSpiTransaction) HAL_SPI_Receive,
|
GPIOA, GPIO_PIN_15, (fHalGpioWritePin) HAL_GPIO_WritePin);
|
||||||
(fHalSpiTransaction) HAL_SPI_Transmit,
|
|
||||||
(fHalSpiTransactionDma) HAL_SPI_Receive_DMA,
|
|
||||||
(fHalSpiTransactionDma) HAL_SPI_Transmit_DMA,
|
|
||||||
GPIOA,
|
|
||||||
GPIO_PIN_15,
|
|
||||||
(fHalGpioWritePin) HAL_GPIO_WritePin
|
|
||||||
);
|
|
||||||
|
|
||||||
wizchip_init(transaction_buf_sizes, transaction_buf_sizes);
|
wizchip_init(transaction_buf_sizes, transaction_buf_sizes);
|
||||||
setSHAR(net_info.mac);
|
setSHAR(net_info.mac);
|
||||||
@ -71,15 +58,11 @@ int main(void)
|
|||||||
|
|
||||||
vTaskStartScheduler();
|
vTaskStartScheduler();
|
||||||
|
|
||||||
while(true)
|
while (true) {}
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void blink(void* args)
|
static void blink(void* args) {
|
||||||
{
|
for (;;) {
|
||||||
for(;;)
|
|
||||||
{
|
|
||||||
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_SET);
|
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_SET);
|
||||||
vTaskDelay(500);
|
vTaskDelay(500);
|
||||||
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET);
|
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET);
|
||||||
@ -88,22 +71,24 @@ static void blink(void* args)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static nmbs_t nmbs;
|
static nmbs_t nmbs;
|
||||||
static nmbs_server_t nmbs_server =
|
static nmbs_server_t nmbs_server = {
|
||||||
{
|
|
||||||
.id = 0x01,
|
.id = 0x01,
|
||||||
.coils = {0,},
|
.coils =
|
||||||
.regs = {0,},
|
|
||||||
};
|
|
||||||
static void modbus(void* args)
|
|
||||||
{
|
{
|
||||||
|
0,
|
||||||
|
},
|
||||||
|
.regs =
|
||||||
|
{
|
||||||
|
0,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
static void modbus(void* args) {
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
nmbs_server_init(&nmbs, &nmbs_server);
|
nmbs_server_init(&nmbs, &nmbs_server);
|
||||||
|
|
||||||
for(;;)
|
for (;;) {
|
||||||
{
|
switch ((status = getSn_SR(MB_SOCKET))) {
|
||||||
switch ((status = getSn_SR(MB_SOCKET)))
|
|
||||||
{
|
|
||||||
case SOCK_ESTABLISHED:
|
case SOCK_ESTABLISHED:
|
||||||
nmbs_server_poll(&nmbs);
|
nmbs_server_poll(&nmbs);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
#include <string.h>
|
|
||||||
#include "nmbs/port.h"
|
#include "nmbs/port.h"
|
||||||
#include "FreeRTOS.h"
|
#include "FreeRTOS.h"
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#ifdef NMBS_TCP
|
#ifdef NMBS_TCP
|
||||||
static int32_t read_socket(uint8_t* buf, uint16_t count, int32_t byte_timeout_ms, void* arg);
|
static int32_t read_socket(uint8_t* buf, uint16_t count, int32_t byte_timeout_ms, void* arg);
|
||||||
@ -20,15 +20,18 @@ uint8_t rtu_rx_b[MB_RX_BUF_SIZE];
|
|||||||
|
|
||||||
static nmbs_server_t* server;
|
static nmbs_server_t* server;
|
||||||
|
|
||||||
static nmbs_error server_read_coils(uint16_t address, uint16_t quantity, nmbs_bitfield coils_out, uint8_t unit_id, void* arg);
|
static nmbs_error server_read_coils(uint16_t address, uint16_t quantity, nmbs_bitfield coils_out, uint8_t unit_id,
|
||||||
static nmbs_error server_read_holding_registers(uint16_t address, uint16_t quantity, uint16_t* registers_out, uint8_t unit_id, void* arg);
|
void* arg);
|
||||||
|
static nmbs_error server_read_holding_registers(uint16_t address, uint16_t quantity, uint16_t* registers_out,
|
||||||
|
uint8_t unit_id, void* arg);
|
||||||
static nmbs_error server_write_single_coil(uint16_t address, bool value, uint8_t unit_id, void* arg);
|
static nmbs_error server_write_single_coil(uint16_t address, bool value, uint8_t unit_id, void* arg);
|
||||||
static nmbs_error server_write_multiple_coils(uint16_t address, uint16_t quantity, const nmbs_bitfield coils, uint8_t unit_id, void* arg);
|
static nmbs_error server_write_multiple_coils(uint16_t address, uint16_t quantity, const nmbs_bitfield coils,
|
||||||
|
uint8_t unit_id, void* arg);
|
||||||
static nmbs_error server_write_single_register(uint16_t address, uint16_t value, uint8_t unit_id, void* arg);
|
static nmbs_error server_write_single_register(uint16_t address, uint16_t value, uint8_t unit_id, void* arg);
|
||||||
static nmbs_error server_write_multiple_registers(uint16_t address, uint16_t quantity, const uint16_t* registers, uint8_t unit_id, void* arg);
|
static nmbs_error server_write_multiple_registers(uint16_t address, uint16_t quantity, const uint16_t* registers,
|
||||||
|
uint8_t unit_id, void* arg);
|
||||||
|
|
||||||
nmbs_error nmbs_server_init(nmbs_t* nmbs, nmbs_server_t* _server)
|
nmbs_error nmbs_server_init(nmbs_t* nmbs, nmbs_server_t* _server) {
|
||||||
{
|
|
||||||
nmbs_platform_conf conf;
|
nmbs_platform_conf conf;
|
||||||
nmbs_callbacks cb;
|
nmbs_callbacks cb;
|
||||||
|
|
||||||
@ -60,8 +63,7 @@ nmbs_error nmbs_server_init(nmbs_t* nmbs, nmbs_server_t* _server)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
nmbs_error status = nmbs_server_create(nmbs, server->id, &conf, &cb);
|
nmbs_error status = nmbs_server_create(nmbs, server->id, &conf, &cb);
|
||||||
if(status != NMBS_ERROR_NONE)
|
if (status != NMBS_ERROR_NONE) {
|
||||||
{
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,8 +73,7 @@ nmbs_error nmbs_server_init(nmbs_t* nmbs, nmbs_server_t* _server)
|
|||||||
return NMBS_ERROR_NONE;
|
return NMBS_ERROR_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
nmbs_error nmbs_client_init(nmbs_t* nmbs)
|
nmbs_error nmbs_client_init(nmbs_t* nmbs) {
|
||||||
{
|
|
||||||
nmbs_platform_conf conf;
|
nmbs_platform_conf conf;
|
||||||
|
|
||||||
nmbs_platform_conf_create(&conf);
|
nmbs_platform_conf_create(&conf);
|
||||||
@ -88,8 +89,7 @@ nmbs_error nmbs_client_init(nmbs_t* nmbs)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
nmbs_error status = nmbs_client_create(nmbs, &conf);
|
nmbs_error status = nmbs_client_create(nmbs, &conf);
|
||||||
if(status != NMBS_ERROR_NONE)
|
if (status != NMBS_ERROR_NONE) {
|
||||||
{
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,27 +100,21 @@ nmbs_error nmbs_client_init(nmbs_t* nmbs)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static nmbs_server_t* get_server(uint8_t id)
|
static nmbs_server_t* get_server(uint8_t id) {
|
||||||
{
|
if (id == server->id) {
|
||||||
if(id == server->id)
|
|
||||||
{
|
|
||||||
return server;
|
return server;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static nmbs_error server_read_coils(uint16_t address, uint16_t quantity, nmbs_bitfield coils_out, uint8_t unit_id, void* arg)
|
static nmbs_error server_read_coils(uint16_t address, uint16_t quantity, nmbs_bitfield coils_out, uint8_t unit_id,
|
||||||
{
|
void* arg) {
|
||||||
nmbs_server_t* server = get_server(unit_id);
|
nmbs_server_t* server = get_server(unit_id);
|
||||||
|
|
||||||
for(size_t i = 0; i < quantity; i++)
|
for (size_t i = 0; i < quantity; i++) {
|
||||||
{
|
if ((address >> 3) > COIL_BUF_SIZE) {
|
||||||
if((address>>3) > COIL_BUF_SIZE)
|
|
||||||
{
|
|
||||||
return NMBS_ERROR_INVALID_REQUEST;
|
return NMBS_ERROR_INVALID_REQUEST;
|
||||||
}
|
}
|
||||||
nmbs_bitfield_write(coils_out, address, nmbs_bitfield_read(server->coils, address));
|
nmbs_bitfield_write(coils_out, address, nmbs_bitfield_read(server->coils, address));
|
||||||
@ -129,14 +123,12 @@ static nmbs_error server_read_coils(uint16_t address, uint16_t quantity, nmbs_bi
|
|||||||
return NMBS_ERROR_NONE;
|
return NMBS_ERROR_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static nmbs_error server_read_holding_registers(uint16_t address, uint16_t quantity, uint16_t* registers_out, uint8_t unit_id, void* arg)
|
static nmbs_error server_read_holding_registers(uint16_t address, uint16_t quantity, uint16_t* registers_out,
|
||||||
{
|
uint8_t unit_id, void* arg) {
|
||||||
nmbs_server_t* server = get_server(unit_id);
|
nmbs_server_t* server = get_server(unit_id);
|
||||||
|
|
||||||
for(size_t i = 0; i < quantity; i++)
|
for (size_t i = 0; i < quantity; i++) {
|
||||||
{
|
if (address > REG_BUF_SIZE) {
|
||||||
if(address > REG_BUF_SIZE)
|
|
||||||
{
|
|
||||||
return NMBS_ERROR_INVALID_REQUEST;
|
return NMBS_ERROR_INVALID_REQUEST;
|
||||||
}
|
}
|
||||||
registers_out[i] = server->regs[address++];
|
registers_out[i] = server->regs[address++];
|
||||||
@ -144,24 +136,20 @@ static nmbs_error server_read_holding_registers(uint16_t address, uint16_t quant
|
|||||||
return NMBS_ERROR_NONE;
|
return NMBS_ERROR_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static nmbs_error server_write_single_coil(uint16_t address, bool value, uint8_t unit_id, void* arg)
|
static nmbs_error server_write_single_coil(uint16_t address, bool value, uint8_t unit_id, void* arg) {
|
||||||
{
|
|
||||||
uint8_t coil = 0;
|
uint8_t coil = 0;
|
||||||
if(value)
|
if (value) {
|
||||||
{
|
|
||||||
coil |= 0x01;
|
coil |= 0x01;
|
||||||
}
|
}
|
||||||
return server_write_multiple_coils(address, 1, &coil, unit_id, arg);
|
return server_write_multiple_coils(address, 1, &coil, unit_id, arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
static nmbs_error server_write_multiple_coils(uint16_t address, uint16_t quantity, const nmbs_bitfield coils, uint8_t unit_id, void* arg)
|
static nmbs_error server_write_multiple_coils(uint16_t address, uint16_t quantity, const nmbs_bitfield coils,
|
||||||
{
|
uint8_t unit_id, void* arg) {
|
||||||
nmbs_server_t* server = get_server(unit_id);
|
nmbs_server_t* server = get_server(unit_id);
|
||||||
|
|
||||||
for(size_t i = 0; i < quantity; i++)
|
for (size_t i = 0; i < quantity; i++) {
|
||||||
{
|
if ((address >> 3) > COIL_BUF_SIZE) {
|
||||||
if((address>>3) > COIL_BUF_SIZE)
|
|
||||||
{
|
|
||||||
return NMBS_ERROR_INVALID_REQUEST;
|
return NMBS_ERROR_INVALID_REQUEST;
|
||||||
}
|
}
|
||||||
nmbs_bitfield_write(server->coils, address, nmbs_bitfield_read(coils, i));
|
nmbs_bitfield_write(server->coils, address, nmbs_bitfield_read(coils, i));
|
||||||
@ -170,20 +158,17 @@ static nmbs_error server_write_multiple_coils(uint16_t address, uint16_t quantit
|
|||||||
return NMBS_ERROR_NONE;
|
return NMBS_ERROR_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static nmbs_error server_write_single_register(uint16_t address, uint16_t value, uint8_t unit_id, void* arg)
|
static nmbs_error server_write_single_register(uint16_t address, uint16_t value, uint8_t unit_id, void* arg) {
|
||||||
{
|
|
||||||
uint16_t reg = value;
|
uint16_t reg = value;
|
||||||
return server_write_multiple_registers(address, 1, ®, unit_id, arg);
|
return server_write_multiple_registers(address, 1, ®, unit_id, arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
static nmbs_error server_write_multiple_registers(uint16_t address, uint16_t quantity, const uint16_t* registers, uint8_t unit_id, void* arg)
|
static nmbs_error server_write_multiple_registers(uint16_t address, uint16_t quantity, const uint16_t* registers,
|
||||||
{
|
uint8_t unit_id, void* arg) {
|
||||||
nmbs_server_t* server = get_server(unit_id);
|
nmbs_server_t* server = get_server(unit_id);
|
||||||
|
|
||||||
for(size_t i = 0; i < quantity; i++)
|
for (size_t i = 0; i < quantity; i++) {
|
||||||
{
|
if (address > REG_BUF_SIZE) {
|
||||||
if(address > REG_BUF_SIZE)
|
|
||||||
{
|
|
||||||
return NMBS_ERROR_INVALID_REQUEST;
|
return NMBS_ERROR_INVALID_REQUEST;
|
||||||
}
|
}
|
||||||
server->regs[address++] = registers[i];
|
server->regs[address++] = registers[i];
|
||||||
@ -192,66 +177,53 @@ static nmbs_error server_write_multiple_registers(uint16_t address, uint16_t qua
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef NMBS_TCP
|
#ifdef NMBS_TCP
|
||||||
int32_t read_socket(uint8_t *buf, uint16_t count, int32_t byte_timeout_ms, void *arg)
|
int32_t read_socket(uint8_t* buf, uint16_t count, int32_t byte_timeout_ms, void* arg) {
|
||||||
{
|
|
||||||
uint32_t tick_start = HAL_GetTick();
|
uint32_t tick_start = HAL_GetTick();
|
||||||
while(recv(MB_SOCKET, buf, count) != count)
|
while (recv(MB_SOCKET, buf, count) != count) {
|
||||||
{
|
if (HAL_GetTick() - tick_start >= (uint32_t) byte_timeout_ms) {
|
||||||
if(HAL_GetTick() - tick_start >= (uint32_t)byte_timeout_ms)
|
|
||||||
{
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t write_socket(const uint8_t *buf, uint16_t count, int32_t byte_timeout_ms, void *arg)
|
int32_t write_socket(const uint8_t* buf, uint16_t count, int32_t byte_timeout_ms, void* arg) {
|
||||||
{
|
|
||||||
return send(MB_SOCKET, buf, count);
|
return send(MB_SOCKET, buf, count);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef NMBS_RTU
|
#ifdef NMBS_RTU
|
||||||
static int32_t read_serial(uint8_t* buf, uint16_t count, int32_t byte_timeout_ms, void* arg)
|
static int32_t read_serial(uint8_t* buf, uint16_t count, int32_t byte_timeout_ms, void* arg) {
|
||||||
{
|
|
||||||
#if MB_UART_DMA
|
#if MB_UART_DMA
|
||||||
uint32_t tick_start = HAL_GetTick();
|
uint32_t tick_start = HAL_GetTick();
|
||||||
while(uxQueueMessagesWaiting(rtu_rx_q) < count)
|
while (uxQueueMessagesWaiting(rtu_rx_q) < count) {
|
||||||
{
|
if (HAL_GetTick() - tick_start >= (uint32_t) byte_timeout_ms) {
|
||||||
if(HAL_GetTick() - tick_start >= (uint32_t)byte_timeout_ms)
|
|
||||||
{
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for(int i = 0; i < count; i++)
|
for (int i = 0; i < count; i++) {
|
||||||
{
|
|
||||||
xQueueReceive(rtu_rx_q, buf + i, 1);
|
xQueueReceive(rtu_rx_q, buf + i, 1);
|
||||||
}
|
}
|
||||||
return count;
|
return count;
|
||||||
#else
|
#else
|
||||||
HAL_StatusTypeDef status = HAL_UART_Receive(&MB_UART, buf, count, byte_timeout_ms);
|
HAL_StatusTypeDef status = HAL_UART_Receive(&MB_UART, buf, count, byte_timeout_ms);
|
||||||
if(status == HAL_OK)
|
if (status == HAL_OK) {
|
||||||
{
|
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
static int32_t write_serial(const uint8_t* buf, uint16_t count, int32_t byte_timeout_ms, void* arg)
|
static int32_t write_serial(const uint8_t* buf, uint16_t count, int32_t byte_timeout_ms, void* arg) {
|
||||||
{
|
|
||||||
#if MB_UART_DMA
|
#if MB_UART_DMA
|
||||||
HAL_UART_Transmit_DMA(&MB_UART, buf, count);
|
HAL_UART_Transmit_DMA(&MB_UART, buf, count);
|
||||||
#else
|
#else
|
||||||
HAL_StatusTypeDef status = HAL_UART_Transmit(&MB_UART, buf, count, byte_timeout_ms);
|
HAL_StatusTypeDef status = HAL_UART_Transmit(&MB_UART, buf, count, byte_timeout_ms);
|
||||||
if(status == HAL_OK)
|
if (status == HAL_OK) {
|
||||||
{
|
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -259,13 +231,10 @@ static int32_t write_serial(const uint8_t* buf, uint16_t count, int32_t byte_tim
|
|||||||
|
|
||||||
|
|
||||||
#if MB_UART_DMA
|
#if MB_UART_DMA
|
||||||
void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size)
|
void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef* huart, uint16_t Size) {
|
||||||
{
|
|
||||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||||
if(huart == &MB_UART)
|
if (huart == &MB_UART) {
|
||||||
{
|
for (int i = 0; i < Size; i++) {
|
||||||
for(int i = 0; i < Size; i++)
|
|
||||||
{
|
|
||||||
xQueueSendFromISR(rtu_rx_q, rtu_rx_b + i, &xHigherPriorityTaskWoken);
|
xQueueSendFromISR(rtu_rx_q, rtu_rx_b + i, &xHigherPriorityTaskWoken);
|
||||||
}
|
}
|
||||||
HAL_UARTEx_ReceiveToIdle_DMA(huart, rtu_rx_b, MB_RX_BUF_SIZE);
|
HAL_UARTEx_ReceiveToIdle_DMA(huart, rtu_rx_b, MB_RX_BUF_SIZE);
|
||||||
|
|||||||
@ -27,3 +27,11 @@ Tested on Mac OS Sonoma(Apple Silicon) & Windows 10 but other os having same too
|
|||||||
- CMake
|
- CMake
|
||||||
- cortex-debug
|
- cortex-debug
|
||||||
|
|
||||||
|
## Building
|
||||||
|
|
||||||
|
```
|
||||||
|
mkdir build
|
||||||
|
cd build
|
||||||
|
cmake ..
|
||||||
|
make -j16
|
||||||
|
```
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user