Skip to content

Commit 07aaefe

Browse files
committed
mesa_modbus: Updates related to V2 PktUART. Use the new setup and reset
Should maybe refuse to work with midules < V2 Signed-off-by: andypugh <andy@bodgesoc.org>
1 parent b29811f commit 07aaefe

2 files changed

Lines changed: 5 additions & 27 deletions

File tree

src/hal/drivers/mesa-hostmot2/modbus/mesa_modbus.c

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -433,31 +433,10 @@ int do_setup(hm2_modbus_inst_t *inst){
433433
inst->rxdelay = inst->hal->rxdelay;
434434
inst->drive_delay = inst->hal->drive_delay;
435435

436-
switch (inst->parity) {
437-
case 1:
438-
txmode = 0x60020; //Drive enable auto, odd parity
439-
rxmode = 0x6000C; //RX Enable, Rx Mask, odd parity
440-
break;
441-
case 2:
442-
txmode = 0x20020; //Drive enable auto, even parity
443-
rxmode = 0x2000C; //RX Enable, Rx Mask, even parity
444-
break;
445-
case 0:
446-
default:
447-
txmode = 0x20; //Drive enable auto, no parity
448-
rxmode = 0x0C; //RX Enable, Rx Mask, no parity
449-
break;
450-
}
436+
437+
retval = hm2_pktuart_setup_rx(inst->port, inst->baudrate, inst->baudrate *2, inst->parity, inst->rxdelay, 1, 1);
438+
retval += hm2_pktuart_setup_tx(inst->port, inst->baudrate, inst->parity, inst->txdelay, 1, 1, inst->drive_delay);
451439

452-
txmode |= inst->txdelay << 8;
453-
rxmode |= inst->rxdelay << 8;
454-
clocklow = hm2_pktuart_get_clock(inst->port);
455-
rtapi_print_msg(RTAPI_MSG_INFO, "Clocklow = %d\n", clocklow);
456-
filter = (clocklow * 0.5 / inst->baudrate);
457-
if (filter > 0xFF) filter = 0xFF;
458-
rxmode |= (filter << 22);
459-
rtapi_print_msg(RTAPI_MSG_INFO, "txmode = %08X rxmode = %08X, rxdelay = %i, txdelay = %i\n", txmode, rxmode, inst->rxdelay, inst->txdelay);
460-
retval=hm2_pktuart_setup(inst->port, inst->baudrate , txmode, rxmode, 1, 1);
461440
if (retval<0)
462441
{
463442
rtapi_print_msg(RTAPI_MSG_ERR, COMP_NAME"PktUART setup problem: %d\n", retval);
@@ -495,7 +474,7 @@ void do_timeout(hm2_modbus_inst_t *inst){
495474
}
496475
if (inst->iter++ > 1000){
497476
rtapi_print_msg(RTAPI_MSG_INFO, "\n %i TIMEOUT_RESET %i\n", inst->iter, inst->state);
498-
hm2_pktuart_setup(inst->port, -1, -1, -1, 1, 1);
477+
hm2_pktuart_reset(inst->port);
499478
inst->state = RESET_WAIT;
500479
inst->iter = 0;
501480
*(inst->hal->last_err) = 11;
@@ -576,7 +555,7 @@ void process(void *arg, long period) {
576555
if (inst->fsizes[inst->frame_index] & 0xC000) { // indicates an overrun
577556
rtapi_print_msg(RTAPI_MSG_INFO, "RESET\n");
578557
inst->state = START;
579-
hm2_pktuart_setup(inst->port, -1, -1, -1, 0, 1); // reset
558+
hm2_pktuart_reset(inst->port);
580559
break;
581560
}
582561
r = hm2_pktuart_queue_read_data(inst->port, inst->rxdata, inst->fsizes[inst->frame_index] & 0x3FF);

src/hal/drivers/mesa-hostmot2/modbus/relayboard.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,3 @@ static const hm2_modbus_chan_descriptor_t channels[] = {
2727
Use 3 to see a lot of information about the modbus
2828
internal workings. 1 is default (errors only) */
2929

30-
#define DEBUG 1

0 commit comments

Comments
 (0)