Объединить разработки CAN и STM32 в master
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
* @file balsam_can.h
|
||||
* @brief Legacy Balsam 167 extended-CAN register frames.
|
||||
* @brief CAN_Bal_2812 extended-CAN register space.
|
||||
*
|
||||
* The wire layout is taken from Balsam_167_periph/Source/Internal/ecan.c:
|
||||
* The wire layout is used by BALZAM Src/balzam_7/CanSetupBalzam7.c:
|
||||
* one big-endian address/mask word followed by three big-endian register words.
|
||||
*/
|
||||
#ifndef BALSAM_CAN_H
|
||||
@@ -34,7 +34,7 @@ typedef struct {
|
||||
uint16_t values[BALSAM_CAN_REGISTER_COUNT];
|
||||
} balsam_can_frame_t;
|
||||
|
||||
/** Return non-zero for the command/data/terminal IDs used by Balsam 167. */
|
||||
/** Return non-zero for the command/data/terminal IDs used by CAN_Bal_2812. */
|
||||
int balsam_can_is_id(uint32_t can_id);
|
||||
|
||||
/**
|
||||
@@ -44,11 +44,11 @@ int balsam_can_is_id(uint32_t can_id);
|
||||
int balsam_can_decode(uint32_t can_id, const uint8_t *data, size_t size,
|
||||
balsam_can_frame_t *output);
|
||||
|
||||
/** Human-readable Russian name of a Balsam device. */
|
||||
/** Human-readable Russian name of a CAN_Bal_2812 device. */
|
||||
const char *balsam_can_device_name(uint8_t device);
|
||||
|
||||
/**
|
||||
* Format the register name from the Balsam 167 data table into output.
|
||||
* Format the register name from the CAN_Bal_2812 data table into output.
|
||||
* Returns the required length (excluding NUL); an empty string means unknown.
|
||||
*/
|
||||
size_t balsam_can_register_name(uint8_t device, uint16_t address,
|
||||
|
||||
@@ -73,6 +73,49 @@ PCAN_ABI_API const char *pcan_abi_balsam_device_name(uint8_t device);
|
||||
PCAN_ABI_API size_t pcan_abi_balsam_register_name(
|
||||
uint8_t device, uint16_t address, char *output, size_t output_size);
|
||||
|
||||
/* PM35/TMS320F28335 direct RS232/485 register terminal. */
|
||||
PCAN_ABI_API uint16_t pcan_abi_periph28335_crc16(
|
||||
const uint8_t *data, size_t size);
|
||||
PCAN_ABI_API size_t pcan_abi_periph28335_append_crc(
|
||||
const uint8_t *payload, size_t payload_size,
|
||||
uint8_t *output, size_t output_size);
|
||||
PCAN_ABI_API size_t pcan_abi_periph28335_build_read(
|
||||
uint8_t controller, uint16_t start, uint16_t count,
|
||||
uint8_t *output, size_t output_size);
|
||||
PCAN_ABI_API size_t pcan_abi_periph28335_build_write(
|
||||
uint8_t controller, uint16_t address, uint16_t value,
|
||||
uint8_t *output, size_t output_size);
|
||||
PCAN_ABI_API size_t pcan_abi_periph28335_build_command(
|
||||
uint8_t controller, uint8_t command_index,
|
||||
uint8_t *output, size_t output_size);
|
||||
PCAN_ABI_API size_t pcan_abi_periph28335_expected_read_size(uint16_t count);
|
||||
PCAN_ABI_API int pcan_abi_periph28335_decode_read(
|
||||
const uint8_t *data, size_t size, uint8_t controller, uint16_t count,
|
||||
uint16_t *output, size_t output_count);
|
||||
PCAN_ABI_API int pcan_abi_periph28335_validate_write(
|
||||
const uint8_t *response, size_t response_size,
|
||||
const uint8_t *request, size_t request_size);
|
||||
PCAN_ABI_API size_t pcan_abi_periph28335_project_count(void);
|
||||
PCAN_ABI_API const char *pcan_abi_periph28335_project_name(
|
||||
size_t project_index);
|
||||
PCAN_ABI_API const char *pcan_abi_periph28335_command_name(
|
||||
size_t project_index, size_t command_index);
|
||||
|
||||
/* PM67/TMS320F2812 legacy memory upload. */
|
||||
PCAN_ABI_API uint16_t pcan_abi_tms2812_crc16(
|
||||
const uint8_t *data, size_t size);
|
||||
PCAN_ABI_API size_t pcan_abi_tms2812_build_upload(
|
||||
uint8_t controller, uint32_t word_address, uint32_t byte_count,
|
||||
uint8_t *output, size_t output_size);
|
||||
PCAN_ABI_API size_t pcan_abi_tms2812_expected_upload_size(
|
||||
uint32_t byte_count);
|
||||
PCAN_ABI_API int pcan_abi_tms2812_validate_upload(
|
||||
const uint8_t *data, size_t size, uint8_t controller,
|
||||
uint32_t byte_count);
|
||||
PCAN_ABI_API int pcan_abi_tms2812_decode_upload(
|
||||
const uint8_t *data, size_t size, uint8_t controller,
|
||||
uint32_t byte_count, uint8_t *output, size_t output_size);
|
||||
|
||||
PCAN_ABI_API size_t pcan_abi_frame_encode(uint8_t sequence, uint8_t flags,
|
||||
uint32_t can_id,
|
||||
const uint8_t *data, uint8_t dlc,
|
||||
|
||||
68
c/set-protocol/include/periph28335.h
Normal file
68
c/set-protocol/include/periph28335.h
Normal file
@@ -0,0 +1,68 @@
|
||||
/**
|
||||
* @file periph28335.h
|
||||
* @brief Shared PM35/TMS320F28335 register protocol.
|
||||
*
|
||||
* The protocol is independent from PM67/TMS320F2812 CAN and RS channels.
|
||||
* It implements the direct RS232/485 register terminal used by PM35.
|
||||
*/
|
||||
#ifndef PERIPH28335_H
|
||||
#define PERIPH28335_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define PERIPH28335_REGISTER_COUNT 128U
|
||||
#define PERIPH28335_REQUEST_SIZE 8U
|
||||
#define PERIPH28335_COMMAND_COUNT 17U
|
||||
|
||||
typedef enum {
|
||||
PERIPH28335_OK = 0,
|
||||
PERIPH28335_ERROR_ARGUMENT = -1,
|
||||
PERIPH28335_ERROR_RANGE = -2,
|
||||
PERIPH28335_ERROR_LENGTH = -3,
|
||||
PERIPH28335_ERROR_CRC = -4,
|
||||
PERIPH28335_ERROR_HEADER = -5,
|
||||
PERIPH28335_ERROR_CAPACITY = -6
|
||||
} periph28335_status_t;
|
||||
|
||||
uint16_t periph28335_crc16_modbus(const uint8_t *data, size_t size);
|
||||
|
||||
size_t periph28335_append_crc(const uint8_t *payload, size_t payload_size,
|
||||
uint8_t *output, size_t output_size);
|
||||
|
||||
size_t periph28335_build_read_registers(
|
||||
uint8_t controller, uint16_t start, uint16_t count,
|
||||
uint8_t *output, size_t output_size);
|
||||
|
||||
size_t periph28335_build_write_register(
|
||||
uint8_t controller, uint16_t address, uint16_t value,
|
||||
uint8_t *output, size_t output_size);
|
||||
|
||||
size_t periph28335_build_command(
|
||||
uint8_t controller, uint8_t command_index,
|
||||
uint8_t *output, size_t output_size);
|
||||
|
||||
size_t periph28335_expected_read_response_size(uint16_t count);
|
||||
|
||||
int periph28335_decode_read_response(
|
||||
const uint8_t *data, size_t size, uint8_t controller, uint16_t count,
|
||||
uint16_t *output, size_t output_count);
|
||||
|
||||
int periph28335_validate_write_response(
|
||||
const uint8_t *response, size_t response_size,
|
||||
const uint8_t *request, size_t request_size);
|
||||
|
||||
size_t periph28335_project_count(void);
|
||||
const char *periph28335_project_name(size_t project_index);
|
||||
const char *periph28335_command_name(size_t project_index,
|
||||
size_t command_index);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* PERIPH28335_H */
|
||||
19
c/set-protocol/include/set_crc.h
Normal file
19
c/set-protocol/include/set_crc.h
Normal file
@@ -0,0 +1,19 @@
|
||||
/** @file set_crc.h @brief Shared checksums used by legacy SET controllers. */
|
||||
#ifndef SET_CRC_H
|
||||
#define SET_CRC_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** CRC-16/Modbus: reflected polynomial 0xA001, initial value 0xFFFF. */
|
||||
uint16_t set_crc16_modbus(const uint8_t *data, size_t size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* SET_CRC_H */
|
||||
@@ -17,10 +17,11 @@ enum set_plot_operation {
|
||||
SET_PLOT_DRAG = 4, /* initial,deltaPixels,length,low,high,inverted -> clamped value */
|
||||
SET_PLOT_TICK_STEP = 5, /* range,lengthPixels -> nice step */
|
||||
SET_PLOT_DELTA = 6, /* A,B,multiplier -> (B-A)*multiplier */
|
||||
SET_PLOT_DB_DELTA = 7 /* A,B -> 20*log10(abs(B/A)); zero is invalid */
|
||||
SET_PLOT_DB_DELTA = 7, /* A,B -> 20*log10(abs(B/A)); zero is invalid */
|
||||
SET_PLOT_LIMITS = 8 /* xMin,xMax,yMin,yMax -> validated unchanged limits */
|
||||
};
|
||||
|
||||
/** Version of this plot ABI, independently of the transport ABI. */
|
||||
/** Version of this additive plot ABI, independently of the transport ABI. */
|
||||
PCAN_ABI_API uint32_t set_plot_abi_version(void);
|
||||
/** Evaluates one operation. Returns output count, or 0 for invalid arguments.
|
||||
* TRANSFORM rejects malformed viewports; invalid gesture values return the
|
||||
|
||||
@@ -28,6 +28,15 @@ PCAN_ABI_API int set_spectrum_analyze(const double *times, const double *values,
|
||||
size_t max_size, int window, int filter, double low_hz, double high_hz, int remove_mean,
|
||||
double *amplitudes, size_t capacity, double *meta);
|
||||
|
||||
/** Find the strongest non-DC local maximum above both the absolute floor and
|
||||
* relative_threshold * median(non-DC amplitudes). The caller supplies scratch
|
||||
* storage of at least count-1 doubles. peak = {frequency_hz, amplitude}.
|
||||
* Returns 1 when found, 0 when no narrow-band peak exists, -1 on invalid input.
|
||||
*/
|
||||
PCAN_ABI_API int set_spectrum_dominant_peak(const double *amplitudes, size_t count,
|
||||
double bin_hz, double relative_threshold, double absolute_floor,
|
||||
double *scratch, size_t scratch_capacity, double *peak, size_t peak_capacity);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -48,6 +48,13 @@ PCAN_ABI_API int set_trend_watch_ack(
|
||||
PCAN_ABI_API int set_trend_watch_values(
|
||||
const uint8_t *payload, size_t size, uint16_t *words, size_t capacity);
|
||||
|
||||
/** Decode the complete GAS_WATCH_DATA payload including its device timestamp.
|
||||
* This is the preferred ABI for GUI ports; the older values-only symbol remains
|
||||
* available for binary compatibility.
|
||||
*/
|
||||
PCAN_ABI_API int set_trend_watch_decode(const uint8_t *payload, size_t size,
|
||||
uint32_t *timestamp_ms, uint16_t *words, size_t capacity);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
#define SETPROTOCOL_H
|
||||
|
||||
#include "balsam_can.h"
|
||||
#include "periph28335.h"
|
||||
#include "tms2812.h"
|
||||
|
||||
/* Основной SET protocol v2. */
|
||||
#include "set_protocol.h"
|
||||
|
||||
49
c/set-protocol/include/tms2812.h
Normal file
49
c/set-protocol/include/tms2812.h
Normal file
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* @file tms2812.h
|
||||
* @brief Shared PM67/TMS320F2812 legacy upload protocol.
|
||||
*/
|
||||
#ifndef TMS2812_H
|
||||
#define TMS2812_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define TMS2812_CMD_UPLOAD 52U
|
||||
#define TMS2812_UPLOAD_REQUEST_SIZE 12U
|
||||
#define TMS2812_UPLOAD_RESPONSE_OVERHEAD 8U
|
||||
|
||||
typedef enum {
|
||||
TMS2812_OK = 0,
|
||||
TMS2812_ERROR_ARGUMENT = -1,
|
||||
TMS2812_ERROR_RANGE = -2,
|
||||
TMS2812_ERROR_LENGTH = -3,
|
||||
TMS2812_ERROR_CRC = -4,
|
||||
TMS2812_ERROR_HEADER = -5,
|
||||
TMS2812_ERROR_CAPACITY = -6
|
||||
} tms2812_status_t;
|
||||
|
||||
uint16_t tms2812_crc16(const uint8_t *data, size_t size);
|
||||
|
||||
size_t tms2812_build_upload_request(
|
||||
uint8_t controller, uint32_t word_address, uint32_t byte_count,
|
||||
uint8_t *output, size_t output_size);
|
||||
|
||||
size_t tms2812_expected_upload_response_size(uint32_t byte_count);
|
||||
|
||||
int tms2812_validate_upload_response(
|
||||
const uint8_t *data, size_t size, uint8_t controller,
|
||||
uint32_t byte_count);
|
||||
|
||||
int tms2812_decode_upload_response(
|
||||
const uint8_t *data, size_t size, uint8_t controller,
|
||||
uint32_t byte_count, uint8_t *output, size_t output_size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* TMS2812_H */
|
||||
Reference in New Issue
Block a user