PHiLIP
Periph

Files

file  adc.h
 Controls the adc peripheral.
 
file  gpio.h
 GPIO management.
 
file  i2c.h
 Controls the i2c peripheral.
 
file  led_flash.h
 Flashes the LED, the most important thing in embedded.
 
file  pwm_dac.h
 Controls the pwm and dac peripheral.
 
file  rtc.h
 Controls the rtc peripheral.
 
file  spi.h
 Controls the spi peripheral.
 
file  sys.h
 System control and management.
 
file  tmr.c
 Controls the timer peripheral.
 
file  trace.h
 Used for logging traces.
 
file  uart.h
 Controls the uart peripherals.
 
file  wdt.h
 Handles watchdog timer periph.
 
file  adc.c
 Controls the adc peripheral.
 
file  gpio.c
 GPIO management.
 
file  i2c.c
 Controls the i2c peripheral.
 
file  led_flash.c
 Flashes the LED, the most important thing in embedded.
 
file  pwm_dac.c
 Controls the pwm and dac peripheral.
 
file  rtc.c
 Controls the rtc peripheral.
 
file  spi.c
 Controls the spi peripheral.
 
file  sys.c
 System control and management.
 
file  tmr.c
 Controls the timer peripheral.
 
file  trace.c
 Used for logging traces.
 
file  uart.c
 Controls the uart peripherals.
 
file  wdt.c
 Handles watchdog timer periph.
 

Data Structures

struct  gpio_dev
 Parameters for gpio control. More...
 
struct  i2c_dev
 The parameters for reg control. More...
 
struct  pwm_dev
 The parameters for pwm control. More...
 
struct  dac_dev
 The parameters for dac control. More...
 
struct  spi_dev
 The parameters for spi control. More...
 
struct  uart_dev_t
 The parameters for uart control. More...
 

Macros

#define SPI_NO_DATA_BYTE   0xFE
 SPI data not available byte.
 
#define DMA_HOLDOFF_NS   200
 
#define INT_HOLDOFF_NS   1000
 
#define OVERFLOW_TICK_VAL   0x10000
 
#define UART_IF_BUF_SIZE   (1024)
 Size allocated for if uart buffer.
 
#define UART_DUT_BUF_SIZE   (128)
 Size allocated for dut uart buffer.
 
#define START_WAIT_FLASHES   (6 * 2)
 How long it takes to indicate the start of led flashing.
 
#define WAIT_FLASHES   (2 * 2)
 How long it takes to indicate the next led flashing state.
 
#define MAJOR_FLASHES   ((FW_REV_MAJOR + 1) * 2)
 Start flash waits longer than the normal waits.
 
#define MINOR_FLASHES   ((FW_REV_MINOR + 1) * 2)
 Start flash waits longer than the normal waits.
 
#define PATCH_FLASHES   ((FW_REV_PATCH + 1) * 2)
 Start flash waits longer than the normal waits.
 
#define FLASH_TIME_MS   150
 How long the led takes to toggle in ms.
 

Enumerations

enum  DUT_IC_EDGE { DUT_IC_EDGE_BOTH, DUT_IC_EDGE_RISING, DUT_IC_EDGE_FALLING }
 Edge select for DUT_IC. More...
 
enum  EVENT_SOURCES {
  SOURCE_NONE, SOURCE_DEBUG0, SOURCE_DEBUG1, SOURCE_DEBUG2,
  SOURCE_DUT_IC
}
 The sources of an event. More...
 
enum  EVENT_TYPE { EVENT_TYPE_FALLING, EVENT_TYPE_RISING }
 Type of trigger causing the event. More...
 
enum  GPIO_IO_TYPE { GPIO_IN, GPIO_OUT_PP, GPIO_OUT_OD, GPIO_INTERRUPT }
 enum for the type of gpio setting. More...
 
enum  I2C_STATE {
  I2C_INITIALIZED, I2C_READING_DATA, I2C_WRITE_ADDRESS_RECEIVED, I2C_WRITE_1ST_REG_BYTE_RECEIVED,
  I2C_WRITING_DATA, I2C_ADDR_NACK, I2C_STOPPED
}
 The state settings of the I2C. More...
 
enum  FLASH_STATE {
  FLASH_START, FLASH_MAJOR, FLASH_WAIT_MAJOR, FLASH_MINOR,
  FLASH_WAIT_MINOR, FLASH_PATCH
}
 The states of flashing the led. More...
 
enum  SPI_STATE {
  SPI_INITIALIZED, SPI_FRAME_STARTED, SPI_WRITING, SPI_READING,
  SPI_TRANSFERING, SPI_FRAME_FINISHED
}
 The state settings of the SPI. More...
 
enum  SPI_IF_TYPE { SPI_IF_TYPE_REG, SPI_IF_TYPE_HS, SPI_IF_TYPE_ECHO, SPI_IF_TYPE_CONST }
 Interface type for the spi. More...
 
enum  UART_IF_TYPE { UART_IF_TYPE_ECHO, UART_IF_TYPE_ECHO_EXT, UART_IF_TYPE_REG, UART_IF_TYPE_TX }
 The type of interface mode the uart is using. More...
 
enum  APP_UART_DATABITS { APP_UART_DATABITS_8, APP_UART_DATABITS_7 }
 The amount of databits. More...
 
enum  APP_UART_PARITY { APP_UART_PARITY_NONE, APP_UART_PARITY_EVEN, APP_UART_PARITY_ODD }
 The uart paraity select. More...
 

Functions

void init_dut_adc (map_t *reg)
 Initializes adc registers and peripheral. More...
 
void init_dut_adc_msp ()
 Only for use with the STM32xxxx_HAL_Driver.
 
void deinit_dut_adc_msp ()
 Only for use with the STM32xxxx_HAL_Driver.
 
error_t commit_dut_adc ()
 Commits the adc registers and executes operations. More...
 
void poll_dut_adc ()
 Updated the map with ADC values. More...
 
void init_gpio (map_t *reg)
 Initializes gpio directions, states and interrupt settings. More...
 
error_t commit_debug ()
 Commits the gpio registers and executes operations. More...
 
void update_debug_inputs ()
 Updates the DEBUG input levels.
 
error_t init_basic_gpio (basic_gpio_t gpio, GPIO_TypeDef *port, uint32_t pin)
 Initializes a basic gpio. More...
 
void init_dut_i2c (map_t *reg)
 Initializes i2c registers. More...
 
error_t commit_dut_i2c ()
 Commits the i2c registers and executes operations. More...
 
void update_dut_i2c_inputs ()
 Updates the i2c input levels.
 
void init_dut_i2c_msp ()
 Only for use with the STM32xxxx_HAL_Driver.
 
void deinit_dut_i2c_msp ()
 Only for use with the STM32xxxx_HAL_Driver.
 
void init_led_flash ()
 Initialize LED0 gpio.
 
void flash_fw_version ()
 Flashes the firmware major, minor, and patch version (+1) on on the led. More...
 
void init_dut_pwm_dac (map_t *reg)
 Initializes pwm and dac registers. More...
 
error_t commit_dut_pwm ()
 Commits the dut pwm registers and executes operations. More...
 
error_t commit_dut_dac ()
 Commits the dut dac registers and executes operations. More...
 
void update_dut_pwm_inputs ()
 Updates the pwm input levels.
 
void update_dut_dac_inputs ()
 Updates the dac input levels.
 
void init_dut_pwm_dac_msp ()
 Only for use with the STM32xxxx_HAL_Driver.
 
void postinit_dut_pwm_dac_msp ()
 Only for use with the STM32xxxx_HAL_Driver.
 
void deinit_dut_pwm_dac_msp ()
 Only for use with the STM32xxxx_HAL_Driver.
 
void init_rtc (map_t *reg)
 Initializes rtc registers. More...
 
error_t commit_rtc ()
 Commits the rtc registers and executes operations. More...
 
void update_rtc ()
 Updates the rtc time.
 
void init_dut_spi (map_t *reg)
 Initializes spi registers. More...
 
error_t commit_dut_spi ()
 Commits the spi registers and executes operations. More...
 
void update_dut_spi_inputs ()
 Updates the spi input levels.
 
void init_dut_spi_msp ()
 Only for use with the STM32xxxx_HAL_Driver.
 
void deinit_dut_spi_msp ()
 Only for use with the STM32xxxx_HAL_Driver.
 
void GPIO_NSS_INT ()
 Interrupt callback for the spi line raise or lower. More...
 
void init_sys (map_t *reg)
 Initializes system registers. More...
 
error_t commit_sys ()
 Commits the system registers and executes operations. More...
 
void update_tick ()
 Updates the tick count to the app reg. More...
 
void init_dut_ic (map_t *reg)
 Initializes timer registers and peripheral. More...
 
void init_dut_ic_msp ()
 Only for use with the STM32xxxx_HAL_Driver.
 
void deinit_dut_ic_msp ()
 Only for use with the STM32xxxx_HAL_Driver.
 
error_t commit_dut_ic ()
 Commits the adc registers and executes operations. More...
 
void poll_dut_ic ()
 Polls for high speed input capture values. More...
 
void update_dut_ic_inputs ()
 Updates the dut_ic input level.
 
void init_trace (map_t *reg)
 Initializes trace register. More...
 
void store_gpio_trace (uint8_t tick_div, uint8_t source, uint16_t value)
 Stores an gpio toggle event. More...
 
void store_tick_from_buf (uint8_t source, uint16_t value, uint32_t tick)
 Stores an ticks saved from a buffer. More...
 
void init_dut_uart (map_t *reg)
 Initializes dut uart registers. More...
 
void init_if_uart ()
 Initializes interface uart registers.
 
error_t commit_dut_uart ()
 Commits the dut uart registers and executes operations. More...
 
error_t poll_dut_uart ()
 Polls for any commands from the dut uart. More...
 
error_t poll_if_uart ()
 Polls for any commands from the interface uart. More...
 
void update_dut_uart_inputs ()
 Updates the uart input levels.
 
void GPIO_CTS_INT ()
 This function handles dut_cts event interrupt.
 
void init_dut_uart_msp ()
 Only for use with the STM32xxxx_HAL_Driver.
 
void deinit_dut_uart_msp ()
 Only for use with the STM32xxxx_HAL_Driver.
 
void init_if_uart_msp ()
 Only for use with the STM32xxxx_HAL_Driver.
 
void deinit_if_uart_msp ()
 Only for use with the STM32xxxx_HAL_Driver.
 
void init_wdt ()
 Initializes the watchdog timer.
 
void reset_wdt ()
 Resets the watchdog timer.
 

Detailed Description

Macro Definition Documentation

#define DMA_HOLDOFF_NS   200

Time it takes for a DMA to load value

#define INT_HOLDOFF_NS   1000

Time it takes for a interrupt to load value

#define OVERFLOW_TICK_VAL   0x10000

16 bit timer will overflow to this value

Enumeration Type Documentation

The amount of databits.

Enumerator
APP_UART_DATABITS_8 

8 bits mode

APP_UART_DATABITS_7 

7 bits mode

The uart paraity select.

Enumerator
APP_UART_PARITY_NONE 

No parity

APP_UART_PARITY_EVEN 

Even parity

APP_UART_PARITY_ODD 

Odd parity

Edge select for DUT_IC.

Enumerator
DUT_IC_EDGE_BOTH 

Interrupt on both edges

DUT_IC_EDGE_RISING 

Interrupt on rising edge using DMA

DUT_IC_EDGE_FALLING 

Interrupt on falling edge using DMA

The sources of an event.

Enumerator
SOURCE_NONE 

No source selected, should be invalid

SOURCE_DEBUG0 

Source is from DEBUG0 pin

SOURCE_DEBUG1 

Source is from DEBUG1 pin

SOURCE_DEBUG2 

Source is from DEBUG2 pin

SOURCE_DUT_IC 

Source is from DUT_IC pin

enum EVENT_TYPE

Type of trigger causing the event.

Enumerator
EVENT_TYPE_FALLING 

Falling edge interrupt

EVENT_TYPE_RISING 

Rising edge interrupt

The states of flashing the led.

Enumerator
FLASH_START 

Start flash waits longer than the normal waits

FLASH_MAJOR 

Flashes the major version + 1

FLASH_WAIT_MAJOR 

Waits a short time to indicate then next flashes

FLASH_MINOR 

Flashes the minor version + 1

FLASH_WAIT_MINOR 

Waits a short time to indicate then next flashes

FLASH_PATCH 

Flashes the patch version + 1

enum for the type of gpio setting.

Enumerator
GPIO_IN 

gpio is high impedance input

GPIO_OUT_PP 

gpio is push pull output

GPIO_OUT_OD 

gpio is open drain output

GPIO_INTERRUPT 

gpio interrupts and saves event

enum I2C_STATE

The state settings of the I2C.

Enumerator
I2C_INITIALIZED 

reg has been initialized

I2C_READING_DATA 

reg currently reading data

I2C_WRITE_ADDRESS_RECEIVED 

reg received write address

I2C_WRITE_1ST_REG_BYTE_RECEIVED 

reg waiting for next addr byte

I2C_WRITING_DATA 

reg currently writing data

I2C_ADDR_NACK 

reg has nacked

I2C_STOPPED 

reg stopped successfully

Interface type for the spi.

Enumerator
SPI_IF_TYPE_REG 

Access registers with spi

SPI_IF_TYPE_HS 

Preloads reg address to 0 for high speed tests

SPI_IF_TYPE_ECHO 

Echos SPI bytes

SPI_IF_TYPE_CONST 

Always output user reg 0

enum SPI_STATE

The state settings of the SPI.

Enumerator
SPI_INITIALIZED 

spi has been initialized

SPI_FRAME_STARTED 

spi NSS pin just lowered

SPI_WRITING 

spi writing to reg

SPI_READING 

spi reading reg

SPI_TRANSFERING 

spi transferring data

SPI_FRAME_FINISHED 

spi cs pin up and finished

The type of interface mode the uart is using.

Enumerator
UART_IF_TYPE_ECHO 

uart echos

UART_IF_TYPE_ECHO_EXT 

uart echos and adds one

UART_IF_TYPE_REG 

uart reads application registers

UART_IF_TYPE_TX 

uart constantly transmits

Function Documentation

error_t commit_debug ( )

Commits the gpio registers and executes operations.

Precondition
gpio must first be initialized with init_gpio()
Returns
0 if OK
EINVAL if invalid setting
Note
Only executes actions if the gpio[x].mode.init is clear.
error_t commit_dut_adc ( )

Commits the adc registers and executes operations.

Precondition
adc must first be initialized with init_adc()
Returns
0 success
-EINVAL invalid value
Note
Only executes actions if the adc.mode.init == 0.
error_t commit_dut_dac ( )

Commits the dut dac registers and executes operations.

Precondition
dac must first be initialized with init_dut_pwm_dac()
Returns
0 if OK
EINVAL value is too large
Note
Only executes actions if the dac.mode.init is clear.
error_t commit_dut_i2c ( )

Commits the i2c registers and executes operations.

Precondition
i2c must first be initialized with init_dut_i2c()
Returns
0 if OK
Note
Only executes actions if the i2c.mode.init is clear.
error_t commit_dut_ic ( )

Commits the adc registers and executes operations.

Returns
0 success
-EINVAL invalid value
Note
Only executes actions if the tmr.mode.init == 0.
error_t commit_dut_pwm ( )

Commits the dut pwm registers and executes operations.

Precondition
pwm must first be initialized with init_dut_pwm_dac()
Returns
0 if OK
EINVAL value is too large
EOVERFLOW ticks exceed the period
Note
Only executes actions if the pwm.mode.init is clear.
error_t commit_dut_spi ( )

Commits the spi registers and executes operations.

Precondition
spi must first be initialized with init_dut_spi()
Returns
0 if OK
Note
Only executes actions if the spi.mode.init is clear.
error_t commit_dut_uart ( )

Commits the dut uart registers and executes operations.

Precondition
uart must first be initialized with init_dut_uart()
Returns
0 Success
Note
Only executes actions if the uart.mode.init is set.
error_t commit_rtc ( )

Commits the rtc registers and executes operations.

Precondition
rtc must first be initialized with init_rtc()
Returns
0 on success
Note
Only executes actions if the rtc.mode.init is clear.
error_t commit_sys ( )

Commits the system registers and executes operations.

Precondition
sys must first be initialized with init_sys()
Returns
0 if OK
Note
Only executes actions if the sys.mode.init is clear. Update will always be reset.
void flash_fw_version ( )

Flashes the firmware major, minor, and patch version (+1) on on the led.

Precondition
Must be called within a tick context, 1 ms or so.
void GPIO_NSS_INT ( )

Interrupt callback for the spi line raise or lower.

Interrupt callback for the spi line raise or lower.

error_t init_basic_gpio ( basic_gpio_t  gpio,
GPIO_TypeDef *  port,
uint32_t  pin 
)

Initializes a basic gpio.

Parameters
[in]gpioParameters of GPIO such as input with pullup
[in]port...GPIO port
[in]pin...GPIO pin
Returns
0 OK
EINVAL if invalid setting
void init_dut_adc ( map_t reg)

Initializes adc registers and peripheral.

Parameters
[in]regPointer to live register memory map
Note
Instantiates the dut_adc module device.
void init_dut_i2c ( map_t reg)

Initializes i2c registers.

Parameters
[in]regPointer to register memory map
Note
Populates i2c defaults registers and assigns i2c register pointers.
void init_dut_ic ( map_t reg)

Initializes timer registers and peripheral.

Parameters
[in]regPointer to register memory map
Note
Instantiates the dut_i2c module device.
void init_dut_pwm_dac ( map_t reg)

Initializes pwm and dac registers.

Parameters
[in]regPointer to live register memory map
Note
Populates pwm defaults registers and assigns pwm and dac register pointers.
void init_dut_spi ( map_t reg)

Initializes spi registers.

Parameters
[in]regPointer to live register memory map
Note
Populates spi defaults registers and assigns spi register pointers.
void init_dut_uart ( map_t reg)

Initializes dut uart registers.

Parameters
[in]regPointer to live register memory map
Note
Populates dut uart defaults registers and assigns uart register pointers.
void init_gpio ( map_t reg)

Initializes gpio directions, states and interrupt settings.

Parameters
[in]regPointer to register memory map
void init_rtc ( map_t reg)

Initializes rtc registers.

Parameters
[in]regPointer to live register memory map
Note
Populates rtc defaults registers and assigns rtc register pointers.
void init_sys ( map_t reg)

Initializes system registers.

Parameters
[in]regPointer to register memory map
Note
Populates system defaults registers and assigns system register pointers.
void init_trace ( map_t reg)

Initializes trace register.

Parameters
[in]regPointer to live register memory map
Note
No saved reg is needed since nothing is configurable
void poll_dut_adc ( )

Updated the map with ADC values.

Note
Since the adc_t does not interact with any interrupts protections are not needed or used.
void poll_dut_ic ( )

Polls for high speed input capture values.

Since values must be transferred before the buffer overflows, either in DMA or INT mode this must be called at a rate faster that buffer overflow can occur.

error_t poll_dut_uart ( )

Polls for any commands from the dut uart.

Precondition
uart must first be initialized with init_dut_uart()
Returns
0 Success
EPROTONOSUPPORT command not supported
EACCES caller doesn't have access
EMSGSIZE message size too big
EINVAL Invalid value
EOVERFLOW invalid address
ERANGE invalid number range
ENODATA not enough data
error_t poll_if_uart ( )

Polls for any commands from the interface uart.

Precondition
uart must first be initialized with init_if_uart()
Returns
0 Success
EPROTONOSUPPORT command not supported
EACCES caller doesn't have access
EMSGSIZE message size too big
EINVAL Invalid value
EOVERFLOW invalid address
ERANGE invalid number range
ENODATA not enough data
void store_gpio_trace ( uint8_t  tick_div,
uint8_t  source,
uint16_t  value 
)

Stores an gpio toggle event.

Note
May be called from interrupt context.
Parameters
[in]tick_divDivides ticks by power of 2
[in]sourceThe source of the event
[in]valueThe value from the event
void store_tick_from_buf ( uint8_t  source,
uint16_t  value,
uint32_t  tick 
)

Stores an ticks saved from a buffer.

Assume tick_div is 0

Parameters
[in]sourceThe source of the event
[in]valueThe value from the event
[in]tickValue of the tick
void update_tick ( )

Updates the tick count to the app reg.

Note
May have concurrent access issues.