def _create_uart_object(): ret_value = True for bus_name, bus in Profile.get_buses().iteritems(): try: if bus['bus'] == 'uart': device_path = bus['path'] if utility.mount_on_fpga(device_path): class_name = 'Axi4Uart' createok = XObject.create_object(bus_name, class_name, device_path) else: class_name = 'UartBus' createok = XObject.create_object(bus_name, class_name, device_path) if createok: logger.boot("create the %s uart object %s" % (bus_name, class_name)) else: logger.boot( "warning: can not find the %s uart class %s in this project code" % (bus_name, class_name)) ret_value = False except Exception as e: logger.boot("error: create %s uart object fail:\n%s" % (bus_name, traceback.format_exc())) ret_value = False return ret_value
def uart_param_config(name, baud_rate, data_bits, parity, stop_bits, timestamp): """ Set uart bus parameter Args: baud_rate(int) : UART baud rate data_bits(int) : Data width 5/6/7/8 parity_type(str) : parity type. "ODD"/"EVNE"/"NONE" stop_bits(float) : stop bit width. 1/2 time_insert(str) : PL UART Insert timestamp Control, "TS"/"NONE" Returns: bool: True | False, True for success, False for adc read failed """ try: uart = XObject.get_object(name) isok = True if utility.mount_on_fpga(uart.name): uart.disable() uart.enable() uart.config(baud_rate, data_bits, parity, stop_bits, timestamp) else: isok = uart.config(baud_rate, data_bits, parity, stop_bits) return isok except Exception as e: logger.error("the %s uart param config execute error:%s" % (name, repr(e))) return False
def __init__(self, name, channel=None): self._name = name self._profile = Profile.get_bus_by_path(name) self._channel = None if channel == 'none' else channel if utility.mount_on_fpga(name) is None: self._bus = CI2cBus(name) else: self._bus = Axi4I2c(name) self._bus.config(int(self._profile["rate"]))
def uart_close(uart_id): try: uart = XObject.get_object(uart_id) if utility.mount_on_fpga(uart.name): uart.disable() else: uart.close() return True except Exception as e: logger.error("close the %s uart error:%s" % (uart_id, repr(e))) return False
def _init_uart(): ret_value = True initconfig = Profile.get_initconfig() for name, param in initconfig['uart'].iteritems(): try: obj = XObject.get_object(name) if obj is None: logger.boot("warning: can not find the %s uart object" % (name)) continue baudrate = int(param['baudrate']) databits = int(param['databits']) stopbits = int(param['stopbits']) parity = param['parity'].upper() if utility.mount_on_fpga(obj.name): timestamp = param['timestamp'].upper() obj.disable() obj.enable() ret = obj.config(baudrate, databits, parity, stopbits, timestamp) else: ret = obj.config(baudrate, databits, parity, stopbits) if ret is False: logger.boot("error: init the %s uart param:%s fail" % (name, param)) ret_value = False else: logger.boot("init the %s uart success, param:%s" % (name, param)) except Exception as e: logger.boot("error: %s _init_uart execute error:\n%s" % (name, traceback.format_exc())) ret_value = False return ret_value
def enable(self): if utility.mount_on_fpga(self._name) is not None: return self._bus.enable()
def config(self, rate): if utility.mount_on_fpga(self._name) is not None: return self._bus.config(int(rate))