v2.2.1:libnxembeddedtools.ul_dv package

Submodules

libnxembeddedtools.ul_dv.io_extender module

Driver for PCA9554 gpio extender:

Usage:

To configure any gpio extender PCA9554, you have four functions:

1- the function: set_direction(direction, position, length): Used to set the direction of the gpios, we can set one or more gpios starting from the position index.

2- the function: get_direction(position): Used to read the direction of any gpio.

3- the function: set_outvalue(value, position, length): Used to set the value of the gpios, we can set one or more gpios starting from the position index.

4- the function: get_iovalue(position): Used to read the value of any gpio.

Example

 

from io_extender import PCA9554 from libnxembeddedtools.i2c.i2c_lib import I2cLib from i2c.i2cllra import I2CLowLevelRegisterAccess

i2c = I2cLib()

address = 0x24 extender_24 = I2CLowLevelRegisterAccess(i2c, address)

#make direction of bit in position 7 to Input position = 7 #make direction of one bit starting from the 7th bit to Input length = 1 io_ext24.set_direction(“I”, position, length)

#make direction of bit in position 4 to Output position = 4 #make direction of 3 bits starting from the 4th bit to Output length = 3 #bits 4, 5, 6 to Output io_ext24.set_direction(“O”, position, length)

#set value of bit 4, 5, 6 to ‘0’ io_ext24.set_outvalue(0, position, length)

class libnxembeddedtools.ul_dv.io_extender.IO_EXTENDER

Bases: object

Abstract class that represents a GPIO controller

NAME = 'GpioExtender API'
abstract get_direction(position)

Retrieves a gpio direction

abstract get_iovalue(position, length)

Retrieves a gpio value

abstract set_direction(direction, position, length)

Changes a gpio direction

abstract set_outvalue(value, position, length)

Changes a gpio value

class libnxembeddedtools.ul_dv.io_extender.PCA9554(low_level_reg_access)

Bases: IO_EXTENDER

get_direction(position)

get direction of a gpio

Parameters:

position – position of gpio

Returns:

“O” for output or “I” for input

Return type:

char

get_iovalue(position, length)

get a gpio’s value

Parameters:
  • position – position of gpio

  • length – how many gpio to get

Returns:

gpio’s value ‘0’ or ‘1’

Return type:

int

set_direction(direction, position, length)

set gpio directions

Parameters:
  • direction – gpio direction “I” for input or “O” for output

  • position – first gpio’s position from 0 to 7

  • length – how many gpio to be set

set_outvalue(value, position, length)

set gpio’s value

Parameters:
  • value – gpio’s value ‘0’ or ‘1’

  • position – first gpio’s position from 0 to 7

  • length – how many gpio to be set

libnxembeddedtools.ul_dv.program_angie module

Driver for ANGIE Programing:

Usage:

We have 3 main functions:

  1. program_angie(): This function programs ANGIE if its not programed

  2. program_fx2(): This function programs ANGIE’s microcontroller the EZ-USB FX2

  3. program_fpga(): This function programs ANGIE’s FPGA

Example

from libnxembeddedtools.ul_dv.program_angie import ProgramAngie

angie = ProgramAngie() angie.program_angie()

class libnxembeddedtools.ul_dv.program_angie.ProgramAngie

Bases: object

program_angie()
program_fpga(dev, ep, binfilename)
program_fx2(dev, hexfilename)
readHex(filename)

Read an hex file and return a raw var

u32tobytes(ibuf)

Convert a list of u32 into chunck of bytes

libnxembeddedtools.ul_dv.si5351c module

Driver for SI5351C

Usage:

The Clock generator class has three main functions :

1. pll_src(): Connects each PLL (A or B) to its clock source (XTAL or CLKIN) and sets CLKIN division value if used. 2. clk_gen(): Generates any frequency between 10Mhz and 110Mhz, Connects one of the PLLs (A or B) to one or both of the outputs (BSM clock or/and external output clock) 3. bypass_clkin(): Connects the external CLKIN clock directly to both BSM clock and external output clock.

>The 1st function pll_src() must be executed before the 2nd one clk_gen(), in order to connect the PLLs to their clock source. >The 3rd function bypass_clkin() functions independently.

Once the clock generator is configured, we need to choose the BSM clock source. There is two possible clock sources: 1. “CLK_OSC” : CPU ring oscillator clock. 2. “CLK0” : Clock generator clock.

To do this, we need to configure the gpio_extenders and exactly the gpio CLK_SEL0, using the set_direction() method.

Example

 

First of all, we import the libraries and we configure our low level access class:

from si5351c import SI5351C from libnxembeddedtools.i2c.i2c_lib import I2cLib from i2c.i2cllra import I2CLowLevelRegisterAccess

i2c = I2cLib()

clk_gen_llra = I2CLowLevelRegisterAccess(i2c, 0x60) clk_gen = SI5351C(clk_gen_llra)

#To connect PLLA to XTAL source:

pll_chosen = “A” pll_src_1 = “XTAL” clk_gen.pll_src(pll_chosen, pll_src_1)

#To connect PLLA to XTAL source and PLLB to CLKIN source:

pll_chosen = “AB” pll_src_1 = “XTAL” pll_src_2 = “CLKIN” clk_gen.pll_src(pll_chosen, pll_src_1, pll_src_2)

#To generate a clock frequency:

freq = 50E6 #50Mhz pll = “A” ms = “MS0” clk_gen.clk_gen(pll, freq, ms) print(“PLLA to CLK0: ok”)

class libnxembeddedtools.ul_dv.si5351c.SI5351C(i2c_low_level_register_access)

Bases: object

bypass_clkin(div)

Bypass CLKIN to CLK_OUT and sets the frequency divider

Parameters:

div (int) – frequency divider value

clk0123_cfg()

Clkx config: enable/disable | power up/down

clk_gen(pll, freq, ms, r_div=1)

Sets bsm clock frequency

Parameters:
  • pll (char) – pll ‘A’ or ‘B’ (source for MS)

  • freq (int) – frequency to be generated {10Mhz to 110Mhz}

  • ms (string) – MS ‘0’ or ‘1’ (MS0 for CLK0 and MS1 for CLK1)

  • r_div (int, optional) – frequency divider value. Defaults to 1.

ms_input_src(ms_src, ms, clk_pdn=0, integer_mode=0, clk_invert=0)

Connect each MSx to its PLLx source

Parameters:
  • ms_src (char) – MSx source: PLL ‘A’ or ‘B’

  • ms (string) – Target MSx

  • clk_pdn (int, optional) – Power down clock. Defaults to 0.

  • integer_mode (int, optional) – Choose integer mode. Defaults to 0.

  • clk_invert (int, optional) – Clock invert. Defaults to 0.

ms_ratio(ms, req_freq, vco_freq=750000000.0, denominator_limit=1048576)

Calculate MSx ratio and p1, p2 and p3 values

Parameters:
  • ms (string) – _description_

  • req_freq (int) – MSx output frequency

  • vco_freq (int, optional) – MSx input frequency. Defaults to 750Mhz.

  • denominator_limit (int, optional) – denominator limit. Defaults to 2**20.

Returns:

p1 [19,16] bits

Return type:

int

pll_ratio(pll, ref_freq, vco_freq=750000000.0, denominator_limit=1048576)

Calculate PLLx ratio and p1, p2 and p3 values

Parameters:
  • pll (char) – Target PLL

  • ref_freq (int) – PLL input frequency

  • vco_freq (int, optional) – PLL output frequency. Defaults to 750Mhz.

  • denominator_limit (int, optional) – denominator limit. Defaults to 2**20.

Returns:

Reference input frequency for MSx

Return type:

int

pll_src(pll, pll_src, pll_src_2=None, clkin_div=1)

Connect each PLLx to its source and sets CLKIN_DIV value

Parameters:
  • pll (char) – pll ‘A’ or ‘B’

  • pll_src (string) – pll clock source “XTAL” or “CLKIN”

  • pll_src_2 (string, optional) – pll clock source “XTAL” or “CLKIN”. Defaults to None.

  • clkin_div (int, optional) – CLKIN divider value. Defaults to 1.

r_divider(div, ms, p1_msb_1)

Sets R divider value

Parameters:
  • div (int) – frequency divider value. Defaults to 1.

  • ms (string) – MSx which frequency to be divided

  • p1_msb_1 (int) – p1 [19,16] bits

libnxembeddedtools.ul_dv.ul_dv module

NG-ULTRA Devkit

class libnxembeddedtools.ul_dv.ul_dv.NgULTRADevKit

Bases: object

A class that represents a NG-ULTRA Devkit

get_boot_src()

Gets the chip boot_src signal state

Returns:

The current mode (“SPI” or “SPACEWIRE”)

Return type:

string

get_flash_mode()

Gets the chip flash_mode signal state

Returns:

The current mode (“SEQUENTIAL” or “TMR”)

Return type:

str

get_flash_number()

Gets the chip flash_num signal state

Returns:

The current flash id.

Return type:

int

Flash id goes from 0 to 3.

get_mode()

Gets the chip mode signal state

Returns:

The current mode (“Normal0” or “Normal1” or “Invalid”)

Return type:

string

get_por_reset()

Gets the por_reset signal state

Returns:

0 if the line is set to 0L (por_reset asserted). 1 if the line is set to 1L (por_reset unasserted)

Return type:

int

por_reset_pulse(tempo_s=0)

Make a por_reset pulse (tempo_s wide)

Parameters:

tempo_s (float) – The number of seconds during which the por_reset is set to low

set_boot_src(value)

Sets the chip boot src

Parameters:

value (int) – One of “SPI” or “SPACEWIRE”. If None, Use the jumper config.

set_boot_src_direction(direction)

Sets the boot_src gpio direction

Parameters:

direction (str) – Allowed: “I” and “O”. If “I” put the boot_src GPIOs in input. If “O” put the boot_src GPIOs in output.

set_flash_mode(value)

Sets the chip flash_mode

Parameters:

value (str) – One of “SEQUENTIAL” and “TMR”. If None, use the jumper configuration.

set_flash_mode_direction(direction)

Sets the flash_mode gpio direction

Parameters:

direction (str) – Allowed: “I” and “O”. If “I” put the flash_mode GPIOs in input. If “O” put the flash_mode GPIOs in output.

set_flash_number(value)

Sets the chip flash_num

Parameters:

value (int) – The flash id. If None, use the jumper configuration.

Flash id goes from 0 to 3.

set_flash_number_direction(direction)

Sets the flash_number gpio direction

Parameters: direction(string): Allowed: “I” and “O”. If “I” put the flash_num GPIOs in input. If “O” put the flash_num GPIOs in output.

set_mode(value)

Sets the chip mode

Parameters:

value (str) – One of “Normal0” or “Normal1”. If None, use the jumper configuration.

set_mode_direction(direction)

Sets the mode gpio direction

Parameters:

direction (str) – Allowed: “I” and “O”. If “I” put the mode GPIOs in input. If “O” put the mode GPIOs in output.

set_por_reset(value=None)

Sets the hard_reset/por signal

Parameters:

value (int) – If 0 or 1, put the por_reset line to requested value. If None, put the por_reset GPIO in input.

set_por_reset_direction(direction)

Sets the por_reset gpio direction

Parameters:

direction (str) – Allowed: “I” and “O”. If “I” put the por_reset GPIO in input. If “O” put the por_reset GPIO in output.

Module contents

© NanoXplore 2022