ATxmega Core
Loading...
Searching...
No Matches
hwbp_core.c File Reference
#include "cpu.h"
#include "hwbp_core.h"
#include "hwbp_core_regs.h"
#include "hwbp_core_types.h"
#include "hwbp_core_com.h"
#include "hwbp_sync.h"
Include dependency graph for hwbp_core.c:

Macros

#define VH   1
 
#define VL   14
 
#define CMD_READ   0x01
 
#define CMD_READ_OK   0x01
 
#define CMD_READ_ERROR   0x09
 
#define CMD_WRITE   0x02
 
#define CMD_WRITE_OK   0x02
 
#define CMD_WRITE_ERROR   0x0A
 
#define EVENT   0x03
 
#define F_CPU   32000000
 
#define EEPROM_ADD_MEM_IN_USE   0
 
#define EEPROM_ADD_R_OPERATION_CTRL   1
 
#define EEPROM_ADD_R_FW_VERSION_H   2
 
#define EEPROM_ADD_R_CORE_VERSION_H   3
 
#define EEPROM_ADD_SN_HIGH   4
 
#define EEPROM_ADD_SN_LOW   5
 
#define EEPROM_ADD_CLOCK_CONFIG   6
 
#define EEPROM_ADD_R_DEVICE_NAME   7
 
#define EEPROM_ADD_APP_REG   32
 
#define R_DEVICE_NAME_SIZE   25
 
#define EEPROM_RST_USE_REGS_DEF   0xDF
 
#define EEPROM_RST_USE_REGS_EE   0xEE
 
#define CTS_TIMEOUT_MS   3000
 
#define check_checksum(array, leng, checksum_)
 

Functions

static void parse_and_reply (uint8_t *packet_p, uint16_t len)
 
static void xmit_error (uint8_t header, uint8_t *packet)
 
static void xmit (uint8_t add, uint8_t header, bool use_core_timestamp)
 
static void write_device_name_to_eeprom (const uint8_t *dev_name)
 
static void read_device_name_to_register (void)
 
void core_func_start_core (const uint16_t who_am_i, const uint8_t hwH, const uint8_t hwL, const uint8_t fwH, const uint8_t fwL, const uint8_t assembly, uint8_t *pointer_to_app_regs, const uint16_t app_mem_size_to_save, const uint8_t num_of_app_registers, const uint8_t *device_name, const bool device_is_able_to_repeat_clock, const bool device_is_able_to_generate_clock, const uint8_t default_timestamp_offset)
 It is mandatory that this function is the first of the application code.
 
void core_func_catastrophic_error_detected (void)
 
 ISR (TCC1_OVF_vect, ISR_NAKED)
 
 ISR (TCC1_CCA_vect, ISR_NAKED)
 
void core_func_update_user_timestamp (uint32_t seconds, uint16_t useconds)
 Used to create a specific timestamp that can be used when sending Events.
 
void core_func_read_user_timestamp (uint32_t *seconds, uint16_t *useconds)
 Used to read the current user timestamps.
 
void core_func_mark_user_timestamp (void)
 Used to save the current timestamp.
 
void core_func_send_event (uint8_t add, bool use_core_timestamp)
 Used to send an Event.
 
bool hwbp_read_common_reg (uint8_t add, uint8_t type)
 Read from a common register.
 
bool hwbp_write_common_reg (uint8_t add, uint8_t type, uint8_t *content, uint16_t n_elements)
 Write to an common register.
 
bool core_save_all_registers_to_eeprom (void)
 Used to save all registers to non-volatile memory.
 
bool hwbp_write_common_reg_RESET_APP (void *a)
 Write to common register RESET_APP.
 
bool core_bool_device_is_repeater (void)
 Used to know if the device is repeating the harp timestamp clock.
 
bool core_bool_device_is_generator (void)
 Used to know if the device is generating the harp timestamp clock.
 
bool core_bool_clock_is_locked (void)
 Used to check if the timestamp register is locked.
 
bool core_device_to_clock_repeater (void)
 Used to set the device as a repeater.
 
bool core_device_to_clock_generator (void)
 Used to set the device as a generator.
 
bool core_clock_to_lock (void)
 Used to lock the timestamp register.
 
bool core_clock_to_unlock (void)
 Used to unlock the timestamp register.
 
void hwbp_read_common_reg_CONFIG (void)
 Read from common register CONFIG.
 
bool hwbp_write_common_reg_CONFIG (void *a)
 Write to common register CONFIG.
 
uint32_t core_func_read_R_TIMESTAMP_SECOND (void)
 Used to get the content of register R_TIMESTAMP_SECOND.
 
uint16_t core_func_read_R_TIMESTAMP_MICRO (void)
 Used to get the content of register R_TIMESTAMP_MICRO.
 
void core_func_leave_speed_mode_and_go_to_standby_mode (void)
 Used to leave the speed mode.
 
bool core_bool_is_visual_enabled (void)
 Return "true" if the LEDs can be ON.
 
bool core_bool_speed_mode_is_in_use (void)
 Return "true" if the device is in Speed Mode.
 
bool core_bool_device_is_active (void)
 Return "true" if the device is in Active Mode.
 
bool core_bool_device_is_synchronized (void)
 Return "true" if the device is synchronized.
 

Variables

uint8_t reply_buff [MAX_PACKET_SIZE]
 
uint8_t com_mode
 
uint8_t rx_timeout
 
uint8_t rx_cmd_ready
 
uint8_t cmd_len_buff1
 
uint8_t cmd_len_buff2
 
bool rx_temp_cmd_ready = false
 
uint8_t rxbuff_hwbp_uart_buff1 []
 
uint8_t rxbuff_hwbp_uart_buff2 []
 
uint8_t rxbuff_hwbp_uart_temp_buff1 []
 
uint8_t hwbp_uart_rx_pointer_buff1
 
uint8_t hwbp_uart_rx_pointer_buff2
 
uint8_t rxbuff_hwbp_usb []
 
uint16_t hwbp_usb_rx_pointer
 
uint8_t app_regs_type []
 
uint16_t app_regs_n_elements []
 
uint8_t * app_regs_pointer []
 
static bool sending_registers = false
 
static bool sending_com_registers = false
 
static uint8_t sending_register_add
 
static uint8_t sending_com_register_add
 
static uint8_t default_device_name [25]
 
static bool enables_serial_number_update = false
 
struct CommonBank commonbank
 
static uint8_t regs_type []
 
static uint16_t regs_n_elements []
 
static uint8_t * regs_pointer []
 
static uint16_t core_app_mem_size_to_save
 
static uint8_t * core_pointer_to_app_regs
 
static uint8_t core_num_of_app_registers
 
static uint8_t _500us_cca_values [] = {15, 16, 16, 15, 16, 15, 16, 16}
 
static uint8_t _500us_cca_index = 0
 
static uint8_t shutdown_counter = 0
 
uint8_t device_lost_sync_counter
 
uint16_t CTS_timeout_counter = 0
 
uint8_t hwbp_uart_tail
 
uint8_t hwbp_uart_head
 
static uint8_t * reg_p
 
bool clock_was_just_updated_externaly
 
static uint32_t user_R_TIMESTAMP_SECOND = 0
 
static uint16_t user_TCC1_CNT = 0
 

Macro Definition Documentation

◆ check_checksum

#define check_checksum ( array,
leng,
checksum_ )
Value:
checksum_ = 0; for (uint8_t iii = 0; iii < leng; iii++) checksum_ += array[iii];

◆ CMD_READ

#define CMD_READ   0x01

◆ CMD_READ_ERROR

#define CMD_READ_ERROR   0x09

◆ CMD_READ_OK

#define CMD_READ_OK   0x01

◆ CMD_WRITE

#define CMD_WRITE   0x02

◆ CMD_WRITE_ERROR

#define CMD_WRITE_ERROR   0x0A

◆ CMD_WRITE_OK

#define CMD_WRITE_OK   0x02

◆ CTS_TIMEOUT_MS

#define CTS_TIMEOUT_MS   3000

◆ EEPROM_ADD_APP_REG

#define EEPROM_ADD_APP_REG   32

◆ EEPROM_ADD_CLOCK_CONFIG

#define EEPROM_ADD_CLOCK_CONFIG   6

◆ EEPROM_ADD_MEM_IN_USE

#define EEPROM_ADD_MEM_IN_USE   0

◆ EEPROM_ADD_R_CORE_VERSION_H

#define EEPROM_ADD_R_CORE_VERSION_H   3

◆ EEPROM_ADD_R_DEVICE_NAME

#define EEPROM_ADD_R_DEVICE_NAME   7

◆ EEPROM_ADD_R_FW_VERSION_H

#define EEPROM_ADD_R_FW_VERSION_H   2

◆ EEPROM_ADD_R_OPERATION_CTRL

#define EEPROM_ADD_R_OPERATION_CTRL   1

◆ EEPROM_ADD_SN_HIGH

#define EEPROM_ADD_SN_HIGH   4

◆ EEPROM_ADD_SN_LOW

#define EEPROM_ADD_SN_LOW   5

◆ EEPROM_RST_USE_REGS_DEF

#define EEPROM_RST_USE_REGS_DEF   0xDF

◆ EEPROM_RST_USE_REGS_EE

#define EEPROM_RST_USE_REGS_EE   0xEE

◆ EVENT

#define EVENT   0x03

◆ F_CPU

#define F_CPU   32000000

◆ R_DEVICE_NAME_SIZE

#define R_DEVICE_NAME_SIZE   25

◆ VH

#define VH   1

◆ VL

#define VL   14

Function Documentation

◆ core_bool_clock_is_locked()

bool core_bool_clock_is_locked ( void )

Used to check if the timestamp register is locked.

◆ core_bool_device_is_active()

bool core_bool_device_is_active ( void )

Return "true" if the device is in Active Mode.

◆ core_bool_device_is_generator()

bool core_bool_device_is_generator ( void )

Used to know if the device is generating the harp timestamp clock.

◆ core_bool_device_is_repeater()

bool core_bool_device_is_repeater ( void )

Used to know if the device is repeating the harp timestamp clock.

◆ core_bool_device_is_synchronized()

bool core_bool_device_is_synchronized ( void )

Return "true" if the device is synchronized.

◆ core_bool_is_visual_enabled()

bool core_bool_is_visual_enabled ( void )

Return "true" if the LEDs can be ON.

◆ core_bool_speed_mode_is_in_use()

bool core_bool_speed_mode_is_in_use ( void )

Return "true" if the device is in Speed Mode.

◆ core_clock_to_lock()

bool core_clock_to_lock ( void )

Used to lock the timestamp register.

◆ core_clock_to_unlock()

bool core_clock_to_unlock ( void )

Used to unlock the timestamp register.

◆ core_device_to_clock_generator()

bool core_device_to_clock_generator ( void )

Used to set the device as a generator.

◆ core_device_to_clock_repeater()

bool core_device_to_clock_repeater ( void )

Used to set the device as a repeater.

◆ core_func_catastrophic_error_detected()

void core_func_catastrophic_error_detected ( void )

Call this function in case of error A power up or reset must be performed to remove the device from this state

◆ core_func_leave_speed_mode_and_go_to_standby_mode()

void core_func_leave_speed_mode_and_go_to_standby_mode ( void )

Used to leave the speed mode.

◆ core_func_mark_user_timestamp()

void core_func_mark_user_timestamp ( void )

Used to save the current timestamp.

◆ core_func_read_R_TIMESTAMP_MICRO()

uint16_t core_func_read_R_TIMESTAMP_MICRO ( void )

Used to get the content of register R_TIMESTAMP_MICRO.

◆ core_func_read_R_TIMESTAMP_SECOND()

uint32_t core_func_read_R_TIMESTAMP_SECOND ( void )

Used to get the content of register R_TIMESTAMP_SECOND.

◆ core_func_read_user_timestamp()

void core_func_read_user_timestamp ( uint32_t * seconds,
uint16_t * useconds )

Used to read the current user timestamps.

◆ core_func_send_event()

void core_func_send_event ( uint8_t add,
bool use_core_timestamp )

Used to send an Event.

◆ core_func_start_core()

void core_func_start_core ( const uint16_t who_am_i,
const uint8_t hwH,
const uint8_t hwL,
const uint8_t fwH,
const uint8_t fwL,
const uint8_t assembly,
uint8_t * pointer_to_app_regs,
const uint16_t app_mem_size_to_save,
const uint8_t num_of_app_registers,
const uint8_t * device_name,
const bool device_is_able_to_repeat_clock,
const bool device_is_able_to_generate_clock,
const uint8_t default_timestamp_offset )

It is mandatory that this function is the first of the application code.

◆ core_func_update_user_timestamp()

void core_func_update_user_timestamp ( uint32_t seconds,
uint16_t useconds )

Used to create a specific timestamp that can be used when sending Events.

◆ core_save_all_registers_to_eeprom()

bool core_save_all_registers_to_eeprom ( void )

Used to save all registers to non-volatile memory.

◆ hwbp_read_common_reg()

bool hwbp_read_common_reg ( uint8_t add,
uint8_t type )

Read from a common register.

◆ hwbp_read_common_reg_CONFIG()

void hwbp_read_common_reg_CONFIG ( void )

Read from common register CONFIG.

◆ hwbp_write_common_reg()

bool hwbp_write_common_reg ( uint8_t add,
uint8_t type,
uint8_t * content,
uint16_t n_elements )

Write to an common register.

◆ hwbp_write_common_reg_CONFIG()

bool hwbp_write_common_reg_CONFIG ( void * a)

Write to common register CONFIG.

◆ hwbp_write_common_reg_RESET_APP()

bool hwbp_write_common_reg_RESET_APP ( void * a)

Write to common register RESET_APP.

◆ ISR() [1/2]

ISR ( TCC1_CCA_vect ,
ISR_NAKED  )

◆ ISR() [2/2]

ISR ( TCC1_OVF_vect ,
ISR_NAKED  )

◆ parse_and_reply()

static void parse_and_reply ( uint8_t * packet_p,
uint16_t len )
static

◆ read_device_name_to_register()

static void read_device_name_to_register ( void )
static

◆ write_device_name_to_eeprom()

static void write_device_name_to_eeprom ( const uint8_t * dev_name)
static

◆ xmit()

static void xmit ( uint8_t add,
uint8_t header,
bool use_core_timestamp )
static

◆ xmit_error()

static void xmit_error ( uint8_t header,
uint8_t * packet )
static

Variable Documentation

◆ _500us_cca_index

uint8_t _500us_cca_index = 0
static

◆ _500us_cca_values

uint8_t _500us_cca_values[] = {15, 16, 16, 15, 16, 15, 16, 16}
static

◆ app_regs_n_elements

uint16_t app_regs_n_elements[]
extern

◆ app_regs_pointer

uint8_t* app_regs_pointer[]
extern

◆ app_regs_type

uint8_t app_regs_type[]
extern

◆ clock_was_just_updated_externaly

bool clock_was_just_updated_externaly
extern

◆ cmd_len_buff1

uint8_t cmd_len_buff1
extern

◆ cmd_len_buff2

uint8_t cmd_len_buff2
extern

◆ com_mode

uint8_t com_mode
extern

◆ commonbank

struct CommonBank commonbank

◆ core_app_mem_size_to_save

uint16_t core_app_mem_size_to_save
static

◆ core_num_of_app_registers

uint8_t core_num_of_app_registers
static

◆ core_pointer_to_app_regs

uint8_t* core_pointer_to_app_regs
static

◆ CTS_timeout_counter

uint16_t CTS_timeout_counter = 0

◆ default_device_name

uint8_t default_device_name[25]
static

◆ device_lost_sync_counter

uint8_t device_lost_sync_counter
extern

◆ enables_serial_number_update

bool enables_serial_number_update = false
static

◆ hwbp_uart_head

uint8_t hwbp_uart_head
extern

◆ hwbp_uart_rx_pointer_buff1

uint8_t hwbp_uart_rx_pointer_buff1
extern

◆ hwbp_uart_rx_pointer_buff2

uint8_t hwbp_uart_rx_pointer_buff2
extern

◆ hwbp_uart_tail

uint8_t hwbp_uart_tail
extern

◆ hwbp_usb_rx_pointer

uint16_t hwbp_usb_rx_pointer
extern

◆ reg_p

uint8_t* reg_p
static

◆ regs_n_elements

uint16_t regs_n_elements[]
static
Initial value:
= {
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
25,
1,
1,
1,
16,
8,
1
}

◆ regs_pointer

uint8_t* regs_pointer[]
static
Initial value:
= {
(uint8_t*)(&commonbank.R_WHO_AM_I),
(uint8_t*)(&commonbank.R_HW_VERSION_H),
(uint8_t*)(&commonbank.R_HW_VERSION_L),
(uint8_t*)(&commonbank.R_FW_VERSION_H),
(uint8_t*)(&commonbank.R_FW_VERSION_L),
(uint8_t*)(&commonbank.R_RESET_DEV),
(uint8_t*)(&commonbank.R_CLOCK_CONFIG),
(uint8_t*)(commonbank.R_UID),
(uint8_t*)(commonbank.R_TAG),
(uint8_t*)(&commonbank.R_HEARTBEAT)
}
struct CommonBank commonbank
Definition hwbp_core.c:94
uint8_t R_OPERATION_CTRL
Definition hwbp_core_regs.h:19
uint8_t R_TIMESTAMP_OFFSET
Definition hwbp_core_regs.h:24
uint8_t R_RESET_DEV
Definition hwbp_core_regs.h:20
uint16_t R_HEARTBEAT
Definition hwbp_core_regs.h:27
uint16_t R_SERIAL_NUMBER
Definition hwbp_core_regs.h:22
uint8_t R_ASSEMBLY_VERSION
Definition hwbp_core_regs.h:12
uint16_t R_TIMESTAMP_MICRO
Definition hwbp_core_regs.h:18
uint8_t R_HW_VERSION_L
Definition hwbp_core_regs.h:11
uint8_t R_CORE_VERSION_L
Definition hwbp_core_regs.h:14
uint16_t R_WHO_AM_I
Definition hwbp_core_regs.h:9
uint8_t R_DEVICE_NAME[25]
Definition hwbp_core_regs.h:21
uint32_t R_TIMESTAMP_SECOND
Definition hwbp_core_regs.h:17
uint8_t R_CORE_VERSION_H
Definition hwbp_core_regs.h:13
uint8_t R_FW_VERSION_H
Definition hwbp_core_regs.h:15
uint8_t R_CLOCK_CONFIG
Definition hwbp_core_regs.h:23
uint8_t R_UID[16]
Definition hwbp_core_regs.h:25
uint8_t R_TAG[8]
Definition hwbp_core_regs.h:26
uint8_t R_HW_VERSION_H
Definition hwbp_core_regs.h:10
uint8_t R_FW_VERSION_L
Definition hwbp_core_regs.h:16

◆ regs_type

uint8_t regs_type[]
static
Initial value:
= {
}
#define TYPE_U8
Definition hwbp_core_types.h:9
#define TYPE_U16
Definition hwbp_core_types.h:11
#define TYPE_U32
Definition hwbp_core_types.h:13

◆ reply_buff

uint8_t reply_buff[MAX_PACKET_SIZE]

◆ rx_cmd_ready

uint8_t rx_cmd_ready
extern

◆ rx_temp_cmd_ready

bool rx_temp_cmd_ready = false

◆ rx_timeout

uint8_t rx_timeout
extern

◆ rxbuff_hwbp_uart_buff1

uint8_t rxbuff_hwbp_uart_buff1[]
extern

◆ rxbuff_hwbp_uart_buff2

uint8_t rxbuff_hwbp_uart_buff2[]
extern

◆ rxbuff_hwbp_uart_temp_buff1

uint8_t rxbuff_hwbp_uart_temp_buff1[]
extern

◆ rxbuff_hwbp_usb

uint8_t rxbuff_hwbp_usb[]
extern

◆ sending_com_register_add

uint8_t sending_com_register_add
static

◆ sending_com_registers

bool sending_com_registers = false
static

◆ sending_register_add

uint8_t sending_register_add
static

◆ sending_registers

bool sending_registers = false
static

◆ shutdown_counter

uint8_t shutdown_counter = 0
static

◆ user_R_TIMESTAMP_SECOND

uint32_t user_R_TIMESTAMP_SECOND = 0
static

◆ user_TCC1_CNT

uint16_t user_TCC1_CNT = 0
static