Skip to content

File x430_device.c

FileList > src > x430_device.c

Go to the source code of this file

  • #include "x430.h"
  • #include <stdbool.h>
  • #include <stddef.h>
  • #include <stdint.h>
  • #include "x430_internal.h"

Classes

Type Name
struct x430_align_device
struct x430_align_device_ctx

Public Functions

Type Name
void x430_copy (uint8_t * destination, const uint8_t * source, uint16_t length)
Copies length bytes (no <string.h>).
uint8_t x430_device_alert (const struct x430_device * device)
Status error alert: DXL2_ERR_ALERT_BIT when Hardware Error Status is not 0.
void x430_device_attach (struct x430_device * device, struct x430_bus * bus)
Records the bus of a device on x430_bus_attach() .
struct x430_bus * x430_device_bus (const struct x430_device * device)
Bus of the device, NULL when it is not attached.
uint8_t x430_device_byte (const struct x430_device * device, uint16_t address)
Control Table byte address , below ::X430_IMAGE_DIRECT (stored at its own index).
bool x430_device_ready (const struct x430_device * device)
True for a device that completed x430_device_init() (device may be NULL).
void x430_device_store (struct x430_device * device, uint16_t address, int32_t value)
Store value into the register that starts ataddress (none: no effect).
int32_t x430_device_value (const struct x430_device * device, uint16_t address)
Value of the register that starts at address , 0 when none starts there.
void x430_device_watchdog (struct x430_device * device, uint32_t idle_ms)
Bus Watchdog check; idle_ms is the time since the last instruction packet.
void x430_fill (uint8_t * destination, uint8_t value, uint16_t length)
Sets length bytes tovalue (no <string.h>).

Public Static Functions

Type Name
int32_t x430_abs (int32_t value)
void x430_apply_eeprom (struct x430_device * device)
Takes the writable EEPROM registers from the valid EEPROM block.
int x430_check (const struct x430_device * device)
X430_OK for an initialized device, else the status code to return.
int x430_check2 (const struct x430_device * device, const void * a, const void * b)
Like x430_check() , anda andb must not be NULL.
bool x430_check_value (const struct x430_device_ctx * m, const struct x430_reg * reg, int32_t value)
uint8_t x430_check_write (const struct x430_device * device, const struct x430_reg * reg, int32_t value, uint8_t options)
Error code for writing value toreg , DXL2_ERR_NONE when allowed.
uint16_t x430_crc16 (uint16_t crc, const uint8_t * data, uint16_t length)
CRC-16 crc continued overlength bytes, bit by bit (no table in flash).
uint8_t x430_enable_torque (struct x430_device * device, bool sync_goal)
Torque Enable = 1 through the write hook (startup, Drive Mode bit 3).
uint8_t x430_event (struct x430_device * device, enum x430_event event)
int32_t x430_get (const struct x430_device_ctx * m, uint16_t address)
void x430_indirect_reg (const struct x430_indirect_block * block, uint32_t entry, struct x430_reg * reg)
Indirect Address register entry ofblock (generated, not in the model table).
bool x430_is_touched (const uint8_t * touched, uint16_t index)
True when register index is marked intouched .
void x430_load_factory (struct x430_device_ctx * m, uint16_t first, uint16_t last)
void x430_load_identity (struct x430_device_ctx * m)
void x430_mark_touched (const struct x430_device_ctx * m, uint16_t address, uint16_t length, uint8_t * touched, bool indirect)
Marks every register touched by the write (bit = register index).
uint32_t x430_merge (const struct x430_device_ctx * m, const struct x430_reg * reg, uint16_t address, uint16_t length, const uint8_t * data, bool indirect)
New raw value of reg after writingdata ataddress: the bytes of the write that land in the register replace the current bytes.
void x430_nvm_apply (struct x430_device * device, enum x430_nvm_slot slot, const struct x430_reg * reg)
Register reg from the valid blockslot into the image (unchanged if the read fails).
void x430_nvm_header (uint8_t * header, enum x430_nvm_slot slot, uint16_t size)
Header of a block: magic "X430", model number, format, slot, payload size.
bool x430_nvm_read (struct x430_device * device, enum x430_nvm_slot slot, uint16_t offset, uint8_t * data, uint16_t length)
Part of block slot through the read hook (the caller checked that there is one).
uint8_t x430_nvm_store (struct x430_device * device, enum x430_nvm_slot slot, uint16_t size)
Writes block slot: header, the firstsize bytes of the image, CRC, in three parts with increasing offsets.
bool x430_nvm_valid (struct x430_device * device, enum x430_nvm_slot slot, uint16_t size)
True when block slot with a payload ofsize bytes is stored and valid for this model: header and CRC are checked in chunks of X430_NVM_CHUNK bytes on the stack.
uint8_t x430_peek (const struct x430_device_ctx * m, uint16_t address)
Control Table byte address ; 0 for a reserved address.
void x430_put (struct x430_device_ctx * m, uint16_t address, int32_t value)
uint32_t x430_raw_get (const uint8_t * table, uint16_t address, uint8_t size)
void x430_raw_put (uint8_t * table, uint16_t address, uint8_t size, uint32_t value)
struct x430_reg x430_reg_by_index (uint16_t index)
Register number index (below X430_REGISTER_COUNT).
uint16_t x430_reg_find (uint16_t address, struct x430_reg * reg)
Register that contains address , inreg ; returns its number, X430_REGISTER_COUNT for a reserved address.
bool x430_reg_start (uint16_t address, struct x430_reg * reg)
Register that starts at address: true with the register, false when none does.
void x430_reg_store (struct x430_device_ctx * m, const struct x430_reg * reg, int32_t value)
Stores value into registerreg (truncated to its size).
int32_t x430_reg_value (const struct x430_device_ctx * m, const struct x430_reg * reg)
Value of register reg (sign-extended).
uint16_t x430_resolve (const struct x430_device_ctx * m, uint16_t address)
Address that address really accesses (Indirect Data resolved).
uint16_t x430_slot (uint16_t address)
Index of Control Table byte address in the compact image, X430_IMAGE_SIZE for a reserved address outside every segment.
void x430_startup (struct x430_device * device)
RAM area to its startup state, then the Startup Configuration.
void x430_store_raw_bytes (struct x430_device_ctx * m, uint16_t address, uint16_t length, const uint8_t * data)
Bytes of a write through Indirect Data whose Indirect Address points at Indirect Data storage itself: they are kept as plain bytes.
void x430_sync_goal (struct x430_device * device)
Torque on: Goal Position takes the Present Position, so the actuator holds where it is instead of jumping to an old goal (behaviour of the X series).
int32_t x430_to_value (const struct x430_reg * reg, uint32_t raw)
Sign-extends a raw register value.
bool x430_torque_on (const struct x430_device_ctx * m)
bool x430_touches_indirect (uint16_t address, uint16_t length)
True when [address, address + length) overlaps an Indirect Data block.
uint8_t x430_write (struct x430_device * device, uint16_t address, uint16_t length, const uint8_t * data, uint8_t options)
WRITE without the argument checks ( x430_device_write() , REG_WRITE, ACTION).

Macros

Type Name
define X430_CRC_POLYNOMIAL 0x8005U
CRC-16 of the persistent blocks: polynomial 0x8005, initial value 0, as dxl2_crc16().
define X430_ID_MAX 252U
Highest DYNAMIXEL ID a device may have (253 is reserved, 254 is broadcast).
define X430_NVM_CHUNK 16U
Bytes read per hook call while a persistent block is checked (at least the header).
define X430_NVM_FORMAT 1U
Persistent block format version.
define X430_PULSES_PER_TURN 4096
Turn size of Present Position in pulses.
define X430_TOUCHED_BYTES ((X430\_REGISTER\_COUNT + 7U) / 8U)
Bytes of the register-touched bit set (one bit per register number).

Public Functions Documentation

function x430_copy

Copies length bytes (no <string.h>).

void x430_copy (
    uint8_t * destination,
    const uint8_t * source,
    uint16_t length
) 


function x430_device_alert

Status error alert: DXL2_ERR_ALERT_BIT when Hardware Error Status is not 0.

uint8_t x430_device_alert (
    const struct x430_device * device
) 


function x430_device_attach

Records the bus of a device on x430_bus_attach() .

void x430_device_attach (
    struct x430_device * device,
    struct x430_bus * bus
) 


function x430_device_bus

Bus of the device, NULL when it is not attached.

struct x430_bus * x430_device_bus (
    const struct x430_device * device
) 


function x430_device_byte

Control Table byte address , below ::X430_IMAGE_DIRECT (stored at its own index).

uint8_t x430_device_byte (
    const struct x430_device * device,
    uint16_t address
) 


function x430_device_ready

True for a device that completed x430_device_init() (device may be NULL).

bool x430_device_ready (
    const struct x430_device * device
) 


function x430_device_store

Store value into the register that starts ataddress (none: no effect).

void x430_device_store (
    struct x430_device * device,
    uint16_t address,
    int32_t value
) 


function x430_device_value

Value of the register that starts at address , 0 when none starts there.

int32_t x430_device_value (
    const struct x430_device * device,
    uint16_t address
) 


function x430_device_watchdog

Bus Watchdog check; idle_ms is the time since the last instruction packet.

void x430_device_watchdog (
    struct x430_device * device,
    uint32_t idle_ms
) 


function x430_fill

Sets length bytes tovalue (no <string.h>).

void x430_fill (
    uint8_t * destination,
    uint8_t value,
    uint16_t length
) 


Public Static Functions Documentation

function x430_abs

static int32_t x430_abs (
    int32_t value
) 

function x430_apply_eeprom

Takes the writable EEPROM registers from the valid EEPROM block.

static void x430_apply_eeprom (
    struct x430_device * device
) 


function x430_check

X430_OK for an initialized device, else the status code to return.

static int x430_check (
    const struct x430_device * device
) 


function x430_check2

Like x430_check() , anda andb must not be NULL.

static int x430_check2 (
    const struct x430_device * device,
    const void * a,
    const void * b
) 


function x430_check_value

static bool x430_check_value (
    const struct x430_device_ctx * m,
    const struct x430_reg * reg,
    int32_t value
) 

function x430_check_write

Error code for writing value toreg , DXL2_ERR_NONE when allowed.

static uint8_t x430_check_write (
    const struct x430_device * device,
    const struct x430_reg * reg,
    int32_t value,
    uint8_t options
) 


function x430_crc16

CRC-16 crc continued overlength bytes, bit by bit (no table in flash).

static uint16_t x430_crc16 (
    uint16_t crc,
    const uint8_t * data,
    uint16_t length
) 

Started from 0 over a whole block it equals dxl2_crc16() of the block.


function x430_enable_torque

Torque Enable = 1 through the write hook (startup, Drive Mode bit 3).

static uint8_t x430_enable_torque (
    struct x430_device * device,
    bool sync_goal
) 


function x430_event

static uint8_t x430_event (
    struct x430_device * device,
    enum x430_event event
) 

function x430_get

static int32_t x430_get (
    const struct x430_device_ctx * m,
    uint16_t address
) 

function x430_indirect_reg

Indirect Address register entry ofblock (generated, not in the model table).

static void x430_indirect_reg (
    const struct x430_indirect_block * block,
    uint32_t entry,
    struct x430_reg * reg
) 


function x430_is_touched

True when register index is marked intouched .

static bool x430_is_touched (
    const uint8_t * touched,
    uint16_t index
) 


function x430_load_factory

static void x430_load_factory (
    struct x430_device_ctx * m,
    uint16_t first,
    uint16_t last
) 

function x430_load_identity

static void x430_load_identity (
    struct x430_device_ctx * m
) 

function x430_mark_touched

Marks every register touched by the write (bit = register index).

static void x430_mark_touched (
    const struct x430_device_ctx * m,
    uint16_t address,
    uint16_t length,
    uint8_t * touched,
    bool indirect
) 


function x430_merge

New raw value of reg after writingdata ataddress: the bytes of the write that land in the register replace the current bytes.

static uint32_t x430_merge (
    const struct x430_device_ctx * m,
    const struct x430_reg * reg,
    uint16_t address,
    uint16_t length,
    const uint8_t * data,
    bool indirect
) 


function x430_nvm_apply

Register reg from the valid blockslot into the image (unchanged if the read fails).

static void x430_nvm_apply (
    struct x430_device * device,
    enum x430_nvm_slot slot,
    const struct x430_reg * reg
) 


function x430_nvm_header

Header of a block: magic "X430", model number, format, slot, payload size.

static void x430_nvm_header (
    uint8_t * header,
    enum x430_nvm_slot slot,
    uint16_t size
) 


function x430_nvm_read

Part of block slot through the read hook (the caller checked that there is one).

static bool x430_nvm_read (
    struct x430_device * device,
    enum x430_nvm_slot slot,
    uint16_t offset,
    uint8_t * data,
    uint16_t length
) 


function x430_nvm_store

Writes block slot: header, the firstsize bytes of the image, CRC, in three parts with increasing offsets.

static uint8_t x430_nvm_store (
    struct x430_device * device,
    enum x430_nvm_slot slot,
    uint16_t size
) 

Result Fail when a part fails (the rest is not written).


function x430_nvm_valid

True when block slot with a payload ofsize bytes is stored and valid for this model: header and CRC are checked in chunks of X430_NVM_CHUNK bytes on the stack.

static bool x430_nvm_valid (
    struct x430_device * device,
    enum x430_nvm_slot slot,
    uint16_t size
) 


function x430_peek

Control Table byte address ; 0 for a reserved address.

static uint8_t x430_peek (
    const struct x430_device_ctx * m,
    uint16_t address
) 


function x430_put

static void x430_put (
    struct x430_device_ctx * m,
    uint16_t address,
    int32_t value
) 

function x430_raw_get

static uint32_t x430_raw_get (
    const uint8_t * table,
    uint16_t address,
    uint8_t size
) 

function x430_raw_put

static void x430_raw_put (
    uint8_t * table,
    uint16_t address,
    uint8_t size,
    uint32_t value
) 

function x430_reg_by_index

Register number index (below X430_REGISTER_COUNT).

static struct x430_reg x430_reg_by_index (
    uint16_t index
) 

The registers are numbered in address order: the model table, then the Indirect Address registers of each block.


function x430_reg_find

Register that contains address , inreg ; returns its number, X430_REGISTER_COUNT for a reserved address.

static uint16_t x430_reg_find (
    uint16_t address,
    struct x430_reg * reg
) 

Binary search in the model table (its first register starts at 0), arithmetic in the Indirect Address blocks: bounded by log2(register_count) + indirect_count steps.


function x430_reg_start

Register that starts at address: true with the register, false when none does.

static bool x430_reg_start (
    uint16_t address,
    struct x430_reg * reg
) 


function x430_reg_store

Stores value into registerreg (truncated to its size).

static void x430_reg_store (
    struct x430_device_ctx * m,
    const struct x430_reg * reg,
    int32_t value
) 


function x430_reg_value

Value of register reg (sign-extended).

static int32_t x430_reg_value (
    const struct x430_device_ctx * m,
    const struct x430_reg * reg
) 


function x430_resolve

Address that address really accesses (Indirect Data resolved).

static uint16_t x430_resolve (
    const struct x430_device_ctx * m,
    uint16_t address
) 


function x430_slot

Index of Control Table byte address in the compact image, X430_IMAGE_SIZE for a reserved address outside every segment.

static uint16_t x430_slot (
    uint16_t address
) 

Bounded: segment_count steps.


function x430_startup

RAM area to its startup state, then the Startup Configuration.

static void x430_startup (
    struct x430_device * device
) 


function x430_store_raw_bytes

Bytes of a write through Indirect Data whose Indirect Address points at Indirect Data storage itself: they are kept as plain bytes.

static void x430_store_raw_bytes (
    struct x430_device_ctx * m,
    uint16_t address,
    uint16_t length,
    const uint8_t * data
) 


function x430_sync_goal

Torque on: Goal Position takes the Present Position, so the actuator holds where it is instead of jumping to an old goal (behaviour of the X series).

static void x430_sync_goal (
    struct x430_device * device
) 


function x430_to_value

Sign-extends a raw register value.

static int32_t x430_to_value (
    const struct x430_reg * reg,
    uint32_t raw
) 


function x430_torque_on

static bool x430_torque_on (
    const struct x430_device_ctx * m
) 

function x430_touches_indirect

True when [address, address + length) overlaps an Indirect Data block.

static bool x430_touches_indirect (
    uint16_t address,
    uint16_t length
) 


function x430_write

WRITE without the argument checks ( x430_device_write() , REG_WRITE, ACTION).

static uint8_t x430_write (
    struct x430_device * device,
    uint16_t address,
    uint16_t length,
    const uint8_t * data,
    uint8_t options
) 


Macro Definition Documentation

define X430_CRC_POLYNOMIAL

CRC-16 of the persistent blocks: polynomial 0x8005, initial value 0, as dxl2_crc16().

#define X430_CRC_POLYNOMIAL `0x8005U`


define X430_ID_MAX

Highest DYNAMIXEL ID a device may have (253 is reserved, 254 is broadcast).

#define X430_ID_MAX `252U`


define X430_NVM_CHUNK

Bytes read per hook call while a persistent block is checked (at least the header).

#define X430_NVM_CHUNK `16U`


define X430_NVM_FORMAT

Persistent block format version.

#define X430_NVM_FORMAT `1U`


define X430_PULSES_PER_TURN

Turn size of Present Position in pulses.

#define X430_PULSES_PER_TURN `4096`


define X430_TOUCHED_BYTES

Bytes of the register-touched bit set (one bit per register number).

#define X430_TOUCHED_BYTES `((X430_REGISTER_COUNT + 7U) / 8U)`



The documentation for this class was generated from the following file src/x430_device.c