serialhdl: Calculate baudadjust from MCU's baud instead of host baud
Store the baud rate the MCU is configured for in the "identify" data and use that rate when calculating the baudadjust parameter. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
4988ba9a71
commit
777a0b817b
|
@ -39,8 +39,7 @@ defs_serialqueue = """
|
|||
double sent_time, receive_time;
|
||||
};
|
||||
|
||||
struct serialqueue *serialqueue_alloc(int serial_fd, double baud_adjust
|
||||
, int write_only);
|
||||
struct serialqueue *serialqueue_alloc(int serial_fd, int write_only);
|
||||
void serialqueue_exit(struct serialqueue *sq);
|
||||
struct command_queue *serialqueue_alloc_commandqueue(void);
|
||||
void serialqueue_send(struct serialqueue *sq, struct command_queue *cq
|
||||
|
@ -49,6 +48,7 @@ defs_serialqueue = """
|
|||
, struct command_queue *cq, uint32_t *data, int len
|
||||
, uint64_t min_clock, uint64_t req_clock);
|
||||
void serialqueue_pull(struct serialqueue *sq, struct pull_queue_message *pqm);
|
||||
void serialqueue_set_baud_adjust(struct serialqueue *sq, double baud_adjust);
|
||||
void serialqueue_set_clock_est(struct serialqueue *sq, double est_clock
|
||||
, double last_ack_time, uint64_t last_ack_clock);
|
||||
void serialqueue_flush_ready(struct serialqueue *sq);
|
||||
|
|
|
@ -9,7 +9,7 @@ import serial
|
|||
import msgproto, chelper
|
||||
|
||||
class SerialReader:
|
||||
BITS_PER_BYTE = 10
|
||||
BITS_PER_BYTE = 10.
|
||||
def __init__(self, reactor, serialport, baud):
|
||||
self.reactor = reactor
|
||||
self.serialport = serialport
|
||||
|
@ -60,22 +60,17 @@ class SerialReader:
|
|||
logging.info("Starting serial connect")
|
||||
self.ser = serial.Serial(self.serialport, self.baud, timeout=0)
|
||||
stk500v2_leave(self.ser)
|
||||
baud_adjust = float(self.BITS_PER_BYTE) / self.baud
|
||||
self.serialqueue = self.ffi_lib.serialqueue_alloc(
|
||||
self.ser.fileno(), baud_adjust, 0)
|
||||
self.serialqueue = self.ffi_lib.serialqueue_alloc(self.ser.fileno(), 0)
|
||||
SerialBootStrap(self)
|
||||
self.background_thread = threading.Thread(target=self._bg_thread)
|
||||
self.background_thread.start()
|
||||
def connect_file(self, debugoutput, dictionary, pace=False):
|
||||
self.ser = debugoutput
|
||||
self.msgparser.process_identify(dictionary, decompress=False)
|
||||
baud_adjust = 0.
|
||||
est_clock = 1000000000000.
|
||||
if pace:
|
||||
baud_adjust = float(self.BITS_PER_BYTE) / self.baud
|
||||
est_clock = self.msgparser.config['CLOCK_FREQ']
|
||||
self.serialqueue = self.ffi_lib.serialqueue_alloc(
|
||||
self.ser.fileno(), baud_adjust, 1)
|
||||
self.serialqueue = self.ffi_lib.serialqueue_alloc(self.ser.fileno(), 1)
|
||||
self.est_clock = est_clock
|
||||
self.last_ack_time = time.time()
|
||||
self.last_ack_clock = 0
|
||||
|
@ -241,6 +236,11 @@ class SerialBootStrap:
|
|||
logging.info("MCU version: %s" % (self.serial.msgparser.version,))
|
||||
self.serial.unregister_callback('identify_response')
|
||||
self.serial.register_callback(self.serial.handle_unknown, '#unknown')
|
||||
mcu_baud = float(self.serial.msgparser.config.get('SERIAL_BAUD', 0.))
|
||||
if mcu_baud:
|
||||
baud_adjust = self.serial.BITS_PER_BYTE / mcu_baud
|
||||
self.serial.ffi_lib.serialqueue_set_baud_adjust(
|
||||
self.serial.serialqueue, baud_adjust)
|
||||
get_status = self.serial.msgparser.lookup_command('get_status')
|
||||
self.serial.status_cmd = get_status.encode()
|
||||
with self.serial.lock:
|
||||
|
|
|
@ -770,11 +770,10 @@ background_thread(void *data)
|
|||
|
||||
// Create a new 'struct serialqueue' object
|
||||
struct serialqueue *
|
||||
serialqueue_alloc(int serial_fd, double baud_adjust, int write_only)
|
||||
serialqueue_alloc(int serial_fd, int write_only)
|
||||
{
|
||||
struct serialqueue *sq = malloc(sizeof(*sq));
|
||||
memset(sq, 0, sizeof(*sq));
|
||||
sq->baud_adjust = baud_adjust;
|
||||
|
||||
// Reactor setup
|
||||
sq->serial_fd = serial_fd;
|
||||
|
@ -961,6 +960,14 @@ exit:
|
|||
pthread_mutex_unlock(&sq->lock);
|
||||
}
|
||||
|
||||
void
|
||||
serialqueue_set_baud_adjust(struct serialqueue *sq, double baud_adjust)
|
||||
{
|
||||
pthread_mutex_lock(&sq->lock);
|
||||
sq->baud_adjust = baud_adjust;
|
||||
pthread_mutex_unlock(&sq->lock);
|
||||
}
|
||||
|
||||
// Set the estimated clock rate of the mcu on the other end of the
|
||||
// serial port
|
||||
void
|
||||
|
|
|
@ -43,8 +43,7 @@ struct pull_queue_message {
|
|||
};
|
||||
|
||||
struct serialqueue;
|
||||
struct serialqueue *serialqueue_alloc(int serial_fd, double baud_adjust
|
||||
, int write_only);
|
||||
struct serialqueue *serialqueue_alloc(int serial_fd, int write_only);
|
||||
void serialqueue_exit(struct serialqueue *sq);
|
||||
struct command_queue *serialqueue_alloc_commandqueue(void);
|
||||
void serialqueue_send_batch(struct serialqueue *sq, struct command_queue *cq
|
||||
|
@ -56,6 +55,7 @@ void serialqueue_encode_and_send(struct serialqueue *sq, struct command_queue *c
|
|||
, uint32_t *data, int len
|
||||
, uint64_t min_clock, uint64_t req_clock);
|
||||
void serialqueue_pull(struct serialqueue *sq, struct pull_queue_message *pqm);
|
||||
void serialqueue_set_baud_adjust(struct serialqueue *sq, double baud_adjust);
|
||||
void serialqueue_set_clock_est(struct serialqueue *sq, double est_clock
|
||||
, double last_ack_time, uint64_t last_ack_clock);
|
||||
void serialqueue_flush_ready(struct serialqueue *sq);
|
||||
|
|
|
@ -153,7 +153,7 @@ def build_identify(cmd_by_id, msg_to_id, responses, static_strings
|
|||
data['commands'] = sorted(cmd_by_id.keys())
|
||||
data['responses'] = sorted(responses)
|
||||
data['static_strings'] = static_strings
|
||||
configlist = ['MCU', 'CLOCK_FREQ']
|
||||
configlist = ['MCU', 'CLOCK_FREQ', 'SERIAL_BAUD']
|
||||
data['config'] = dict((i, config['CONFIG_'+i]) for i in configlist
|
||||
if 'CONFIG_'+i in config)
|
||||
data['version'] = version
|
||||
|
|
Loading…
Reference in New Issue