PHiLIP
Application

Files

file  app_common.h
 For common application functions.
 
file  app_reg.h
 Accessing application registers.
 
file  app_shell_if.h
 Protocol for application communication.
 
file  map_if.h
 Handles memory map specific interface functions.
 
file  app_common.c
 For common application functions.
 
file  app_reg.c
 Accessing application registers.
 
file  app_shell_if.c
 Protocol for application communication.
 
file  map_if.c
 Handles memory map specific interface functions.
 

Macros

#define DIS_INT   __disable_irq();
 Disables interrupts.
 
#define EN_INT   __enable_irq();
 Enables interrupts.
 
#define SOFT_RESET   soft_reset()
 Resets device. More...
 
#define TICK_BIT_OFFSET   16
 Bit shifting ticks.
 
#define RX_END_CHAR   '\n'
 Parse on newline.
 
#define TX_END_STR   "\n"
 Send newline at end of transmission.
 
#define READ_REG_CMD   "rr "
 The command to read application registers.
 
#define WRITE_REG_CMD   "wr "
 The command to write application registers.
 
#define EXECUTE_CMD   "ex\n"
 The command to execute and commit changes in the registers.
 
#define RESET_CMD   "mcu_rst\n"
 The command to provide a software reset to the applications.
 
#define VERSION_CMD   "-v\n"
 Prints the version of the interface.
 
#define VERSION_CMD2   "version\n"
 Prints the version of the interface.
 
#define VERSION_CMD3   "ver\n"
 Prints the version of the interface.
 
#define VERSION_CMD4   "--v\n"
 Prints the version of the interface.
 
#define HELP_CMD   "help\n"
 Prints a help menu.
 
#define MEMORY_MAP_CMD   "mm "
 Gives properties of the memory map for a given index.
 
#define MM_SIZE_CMD   "mm_size\n"
 Gives the amount of records in the memory map.
 
#define READ_KEY_CMD   "r "
 Reads values given a record name.
 
#define WRITE_KEY_CMD   "w "
 Writes a value to a record name.
 

Functions

void delay_us (uint16_t micros)
 Imprecise blocking delay in microseconds. More...
 
void copy_until_same (void *dest, void *src, size_t size)
 Copies and compares data until copied data matches. More...
 
void soft_reset ()
 Wrapper function to provide software reset.
 
uint64_t get_tick ()
 Gets tick value in amount to system tick (72 MHz).
 
uint32_t get_tick32 ()
 Gets tick value in amount to system tick (72 MHz) in 32bit.
 
uint32_t get_tick32_div (uint8_t div)
 Gets 32 bit tick shifted down by an amount. More...
 
void init_app_reg (map_t *reg)
 Initializes application registers. More...
 
error_t execute_reg_change ()
 Executes or commits all register changes on the periphs. More...
 
uint32_t get_reg_size ()
 Gets the total size of the register map in bytes. More...
 
void unprotected_read_uint8 (uint32_t index, uint8_t *data)
 An unprotected read from the register map. More...
 
error_t read_reg (uint32_t index, uint8_t *data)
 Reads a register from the register map. More...
 
error_t read_regs (uint32_t index, uint8_t *data, uint16_t size)
 Reads multiple registers from the register map. More...
 
error_t write_reg (uint32_t index, uint8_t data, uint8_t access)
 Writes a register from the register map. More...
 
error_t write_regs (uint32_t index, uint8_t *data, uint16_t size, uint8_t access)
 Writes multiple register from the register map. More...
 
void add_index (uint16_t *i)
 Adds a number and wraps around if register size exceeded. More...
 
void sub_index (uint16_t *i)
 Subtracts a number and wraps around if 0. More...
 
error_t parse_command (char *str, uint16_t buf_size, uint8_t access)
 Parses a string and executes commands. More...
 
error_t get_mm (uint16_t index, char *str)
 Gets parameters of a record in the memory map. More...
 
error_t get_mm_val (char *mm_name, uint32_t array_index, uint32_t *data)
 Gets the value of a record in the memory map. More...
 
error_t set_mm_val (char *mm_name, uint32_t array_index, uint32_t data, uint8_t access)
 Sets the value of a record in the memory map. More...
 

Detailed Description

Macro Definition Documentation

#define SOFT_RESET   soft_reset()

Resets device.

Note
This is a software reset, if the reset pin is being held the device may not complete reset until released.

Function Documentation

void add_index ( uint16_t *  i)

Adds a number and wraps around if register size exceeded.

Parameters
[in,out]iindex to increment
void copy_until_same ( void *  dest,
void *  src,
size_t  size 
)

Copies and compares data until copied data matches.

Parameters
[out]destDestination address to copy to
[in]srcSource address to copy
[in]sizeSize of bytes to copy
Note
Used for data concurrency issues without blocking interrupts.
void delay_us ( uint16_t  micros)

Imprecise blocking delay in microseconds.

Parameters
[in]microsNumber of microseconds to delay
error_t execute_reg_change ( )

Executes or commits all register changes on the periphs.

Precondition
All initializations must be called first.
Returns
0 if success
ERRNO error code
error_t get_mm ( uint16_t  index,
char *  str 
)

Gets parameters of a record in the memory map.

Parameters
[in]indexindex of the record to get
[out]strstring to put the record information
Returns
0 on success
EOVERFLOW invalid record index
error_t get_mm_val ( char *  mm_name,
uint32_t  array_index,
uint32_t *  data 
)

Gets the value of a record in the memory map.

Parameters
[in]mm_namename of the record
[in]array_indexindex if the record is an array
[out]datadata from the record
Returns
0 on success
EINVAL Invalid value
ERANGE invalid number range of array
uint32_t get_reg_size ( )

Gets the total size of the register map in bytes.

Returns
Number of bytes in register map
uint32_t get_tick32_div ( uint8_t  div)

Gets 32 bit tick shifted down by an amount.

Parameters
[in]divDivisor, divide ticks by 2^n
void init_app_reg ( map_t reg)

Initializes application registers.

Parameters
[in]regPointer to register memory map
Note
Populates system user registers and assigns register pointers.
error_t parse_command ( char *  str,
uint16_t  buf_size,
uint8_t  access 
)

Parses a string and executes commands.

Parameters
[in]strString with the command
[in]buf_sizeThe max size of the string buffer
[in]accessThe callers access level
Returns
0 on 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
Warning
May protect interrupts and cause jitter.
error_t read_reg ( uint32_t  index,
uint8_t *  data 
)

Reads a register from the register map.

Parameters
[in]indexThe index of the register map to start to read
[out]dataPointer to data that was read
Returns
0 on success
EOVERFLOW if trying to read out of range
error_t read_regs ( uint32_t  index,
uint8_t *  data,
uint16_t  size 
)

Reads multiple registers from the register map.

Parameters
[in]indexThe index of the register map to start to read
[out]dataPointer to data that was read
[in]sizeThe amount of bytes to read
Returns
0 on success
EOVERFLOW if trying to read out of range
Warning
Multiple writes to data may occur so don't pass hardware register addresses.
error_t set_mm_val ( char *  mm_name,
uint32_t  array_index,
uint32_t  data,
uint8_t  access 
)

Sets the value of a record in the memory map.

Parameters
[in]mm_namename of the record
[in]array_indexindex if the record is an array
[in]datadata for the record
[in]accessaccess level of the calling function
Returns
0 on success
EINVAL Invalid value
ERANGE invalid number range of array
void sub_index ( uint16_t *  i)

Subtracts a number and wraps around if 0.

Parameters
[in,out]iindex to decrement
void unprotected_read_uint8 ( uint32_t  index,
uint8_t *  data 
)

An unprotected read from the register map.

Parameters
[in]indexThe index of the register map to start to read
[out]dataPointer to data that was read
Returns
0 on success
EOVERFLOW if trying to read out of range

This is a direct read from the register without any protection, the purpose is for speed. This should also be used for entering data directly to hardware registers.

Warning
No interrupt protection or memory protection.
error_t write_reg ( uint32_t  index,
uint8_t  data,
uint8_t  access 
)

Writes a register from the register map.

Parameters
[in]indexThe index of the register map to start to write
[out]dataPointer to data that was write
[in]accessThe access level of the caller
Returns
0 on success
EOVERFLOW if trying to read out of range
EACCESS caller does not have write access
Warning
Has interrupt protected to safely write, can cause jitter.
error_t write_regs ( uint32_t  index,
uint8_t *  data,
uint16_t  size,
uint8_t  access 
)

Writes multiple register from the register map.

Parameters
[in]indexThe index of the register map to start to write
[out]dataPointer to data that was write
[in]sizeThe amount of bytes to write
[in]accessThe access level of the caller
Returns
0 on success
EOVERFLOW if trying to read out of range
EACCESS caller does not have write access
Warning
Has interrupt protected to safely write, can cause jitter.