File x430_bus.c¶
FileList > src > x430_bus.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_bus |
| struct | x430_align_bus_ctx |
Public Types¶
| Type | Name |
|---|---|
| enum | x430_target Origin of an instruction for one device. |
Public Functions¶
| Type | Name |
|---|---|
| bool | x430_bus_id_taken (const struct x430_bus * bus, const struct x430_device * except, uint8_t id) True when another device on bus usesid (bus may be NULL). |
| uint32_t | x430_bus_millis (const struct x430_bus * bus) Milliseconds from the port of bus ; 0 without bus or clock. |
| size_t | x430_frame_status (uint8_t * tx, size_t capacity, uint8_t id, uint16_t count) Completes a status packet in place (no second buffer): header, id , the byte stuffing of instruction, error and data, the length field and the CRC. |
Public Static Functions¶
| Type | Name |
|---|---|
| bool | x430_answers (const struct x430_device * device, uint8_t needed) Status Return Level rule: true when the device answers at needed . |
| void | x430_broadcast (struct x430_bus_ctx * m, const struct dxl2_packet * packet) |
| void | x430_broadcast_ping (struct x430_bus_ctx * m, const struct dxl2_packet * packet) Broadcast PING: every device answers, lowest ID first. |
| int | x430_check (const struct x430_bus * bus) X430_OK for an initialized bus, else the status code to return. |
| void | x430_delay_status (const struct x430_bus_ctx * m, const struct x430_device * device) |
| void | x430_dispatch (struct x430_bus_ctx * m, const struct dxl2_packet * packet) Packet dispatcher, called with the bus lock held. |
| void | x430_execute (struct x430_bus_ctx * m, struct x430_device * device, const struct dxl2_packet * packet, enum x430_target target) |
| bool | x430_factory_reset_check (const struct dxl2_packet * packet, enum x430_target target, uint8_t * error) FACTORY_RESET parameter check; true when the reset may run after the answer. |
| struct x430_device * | x430_find (const struct x430_bus_ctx * m, uint8_t id) Attached device with primary ID id , NULL if none. |
| bool | x430_group_read (struct x430_bus_ctx * m, struct x430_device * device, uint16_t address, uint16_t length) Read for a group instruction; sends the status of one device. |
| void | x430_handler (const struct dxl2_packet * packet, void * context) Packet handler given to DXL2-C. |
| uint8_t | x430_id_of (const struct x430_device * device) |
| uint16_t | x430_instruction (struct x430_bus_ctx * m, struct x430_device * device, const struct dxl2_packet * packet, enum x430_target target, uint8_t * error, bool * answer_first) Executes an instruction for one device; returns the status data length. |
| void | x430_lock (const struct x430_bus_ctx * m) |
| bool | x430_magic_ok (const uint8_t * parameters, uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4) |
| uint32_t | x430_millis (const struct x430_bus_ctx * m) |
| void | x430_send_status (struct x430_bus_ctx * m, const struct x430_device * device, uint8_t id, uint8_t error, uint16_t length) Sends the status packet whose length data bytes are at X430_TX_DATA (none on error). |
| bool | x430_stuffed_at (const uint8_t * tx, uint32_t index) True when the body byte at index ends the pattern FF FF FD (Protocol 2.0 byte stuffing). |
| void | x430_sync_read (struct x430_bus_ctx * m, const struct dxl2_packet * packet) |
| void | x430_sync_write (struct x430_bus_ctx * m, const struct dxl2_packet * packet) |
| int | x430_take_write_result (struct x430_bus_ctx * m) Status of an entry point that may have sent status packets. |
| void | x430_turn_add (struct x430_bus_ctx * m, uint8_t id, uint16_t address, uint16_t length, uint8_t * after) Adds one entry of a SYNC_READ / BULK_READ request in request order. |
| void | x430_turn_cancel (struct x430_bus_ctx * m) Ends the pending read: its remaining hosted devices stay silent. |
| void | x430_turn_heard (struct x430_bus_ctx * m, uint8_t id) Status packet of device id received from the bus (another bus, or an echo). |
| void | x430_turn_run (struct x430_bus_ctx * m) Answers the pending entries whose turn has come, up to one that waits for another bus. |
| void | x430_unlock (const struct x430_bus_ctx * m) |
| void | x430_write_tx (struct x430_bus_ctx * m, size_t length) Writes length bytes of the TX buffer with the application writer; records a failure. |
Macros¶
| Type | Name |
|---|---|
| define | X430_BULK_READ_ENTRY 5UOne BULK_READ entry: ID, address, length. |
| define | X430_FAST_HEADER 8UFast read: header, reserved, ID, length, instruction. |
| define | X430_FAST_SEGMENT_OVERHEAD 4UFast read: bytes around the data of one device (error, ID, CRC). |
| define | X430_LEVEL_ALL 2U |
| define | X430_LEVEL_PING 0UStatus Return Level needed for an answer: PING always, READs from level 1, the rest at 2. |
| define | X430_LEVEL_READ 1U |
| define | X430_OPTION_PARAMS 5UParameters of CLEAR and BACKUP: option and four magic bytes. |
| define | X430_READ_PARAMS 4UParameters of READ and of the SYNC_READ header: address and length. |
| define | X430_STATUS_DATA_MAX (DXL2\_MAX\_PARAMETER\_SIZE - 1U)Largest data length of a status packet (the error byte comes first). |
| define | X430_STUFFING 0xFDUByte stuffing: the byte inserted after FF FF FD inside the body. |
| define | X430_TX_BODY 7UStatus packet in the TX buffer: offset of the instruction, the first byte stuffing covers. |
| define | X430_TX_DATA 9UStatus packet in the TX buffer: offset of the status data. |
| define | X430_TX_ERROR 8UStatus packet in the TX buffer: offset of the error byte. |
| define | X430_TX_LENGTH 5ULength field of a packet: offset in the packet. |
| define | X430_WRITE_HEADER 2UParameters of WRITE before the data: address. |
Public Types Documentation¶
enum x430_target¶
Origin of an instruction for one device.
Public Functions Documentation¶
function x430_bus_id_taken¶
True when another device on bus usesid (bus may be NULL).
bool x430_bus_id_taken (
const struct x430_bus * bus,
const struct x430_device * except,
uint8_t id
)
function x430_bus_millis¶
Milliseconds from the port of bus ; 0 without bus or clock.
function x430_frame_status¶
Completes a status packet in place (no second buffer): header, id , the byte stuffing of instruction, error and data, the length field and the CRC.
The result is byte for byte the packet of dxl2_encode(). A status whose stuffed form does not fit capacity becomes a Data Length Error without data (the alert bit is kept).
Parameters:
txPacket buffer: error byte at offset 8,countdata bytes from 9.capacitySize oftx, at least 9 +countand at least 11 bytes.idID of the answering device.countStatus data bytes.
Returns:
Packet length (at least 11).
Public Static Functions Documentation¶
function x430_answers¶
Status Return Level rule: true when the device answers at needed .
function x430_broadcast¶
function x430_broadcast_ping¶
Broadcast PING: every device answers, lowest ID first.
function x430_check¶
X430_OK for an initialized bus, else the status code to return.
function x430_delay_status¶
function x430_dispatch¶
Packet dispatcher, called with the bus lock held.
function x430_execute¶
static void x430_execute (
struct x430_bus_ctx * m,
struct x430_device * device,
const struct dxl2_packet * packet,
enum x430_target target
)
function x430_factory_reset_check¶
FACTORY_RESET parameter check; true when the reset may run after the answer.
static bool x430_factory_reset_check (
const struct dxl2_packet * packet,
enum x430_target target,
uint8_t * error
)
function x430_find¶
Attached device with primary ID id , NULL if none.
function x430_group_read¶
Read for a group instruction; sends the status of one device.
static bool x430_group_read (
struct x430_bus_ctx * m,
struct x430_device * device,
uint16_t address,
uint16_t length
)
True when it answered.
function x430_handler¶
Packet handler given to DXL2-C.
function x430_id_of¶
function x430_instruction¶
Executes an instruction for one device; returns the status data length.
static uint16_t x430_instruction (
struct x430_bus_ctx * m,
struct x430_device * device,
const struct dxl2_packet * packet,
enum x430_target target,
uint8_t * error,
bool * answer_first
)
function x430_lock¶
function x430_magic_ok¶
static bool x430_magic_ok (
const uint8_t * parameters,
uint8_t b1,
uint8_t b2,
uint8_t b3,
uint8_t b4
)
function x430_millis¶
function x430_send_status¶
Sends the status packet whose length data bytes are at X430_TX_DATA (none on error).
static void x430_send_status (
struct x430_bus_ctx * m,
const struct x430_device * device,
uint8_t id,
uint8_t error,
uint16_t length
)
function x430_stuffed_at¶
True when the body byte at index ends the pattern FF FF FD (Protocol 2.0 byte stuffing).
index is at least X430_TX_DATA: the pattern lies inside the body.
function x430_sync_read¶
function x430_sync_write¶
function x430_take_write_result¶
Status of an entry point that may have sent status packets.
function x430_turn_add¶
Adds one entry of a SYNC_READ / BULK_READ request in request order.
static void x430_turn_add (
struct x430_bus_ctx * m,
uint8_t id,
uint16_t address,
uint16_t length,
uint8_t * after
)
after holds the turn of this entry (X430_TURN_NOW or the ID before it) and is updated for the next entry. An entry of another bus, or one this bus cannot take, makes the next entry wait for its status packet.
function x430_turn_cancel¶
Ends the pending read: its remaining hosted devices stay silent.
function x430_turn_heard¶
Status packet of device id received from the bus (another bus, or an echo).
function x430_turn_run¶
Answers the pending entries whose turn has come, up to one that waits for another bus.
function x430_unlock¶
function x430_write_tx¶
Writes length bytes of the TX buffer with the application writer; records a failure.
Macro Definition Documentation¶
define X430_BULK_READ_ENTRY¶
One BULK_READ entry: ID, address, length.
define X430_FAST_HEADER¶
Fast read: header, reserved, ID, length, instruction.
define X430_FAST_SEGMENT_OVERHEAD¶
Fast read: bytes around the data of one device (error, ID, CRC).
define X430_LEVEL_ALL¶
define X430_LEVEL_PING¶
Status Return Level needed for an answer: PING always, READs from level 1, the rest at 2.
define X430_LEVEL_READ¶
define X430_OPTION_PARAMS¶
Parameters of CLEAR and BACKUP: option and four magic bytes.
define X430_READ_PARAMS¶
Parameters of READ and of the SYNC_READ header: address and length.
define X430_STATUS_DATA_MAX¶
Largest data length of a status packet (the error byte comes first).
define X430_STUFFING¶
Byte stuffing: the byte inserted after FF FF FD inside the body.
define X430_TX_BODY¶
Status packet in the TX buffer: offset of the instruction, the first byte stuffing covers.
define X430_TX_DATA¶
Status packet in the TX buffer: offset of the status data.
define X430_TX_ERROR¶
Status packet in the TX buffer: offset of the error byte.
define X430_TX_LENGTH¶
Length field of a packet: offset in the packet.
define X430_WRITE_HEADER¶
Parameters of WRITE before the data: address.
The documentation for this class was generated from the following file src/x430_bus.c