60 lines
2.9 KiB
C
60 lines
2.9 KiB
C
/** @file set_wavegen.h Transactional table upload and cyclic DAC playback. */
|
|
#ifndef SET_WAVEGEN_H
|
|
#define SET_WAVEGEN_H
|
|
#include "pcan_abi.h"
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
#define SET_WAVE_MAX 4096u
|
|
#define SET_WAVE_MAX_RATE 1000000u
|
|
#define SET_WAVE_BLOCK_MAX 120u
|
|
#define SET_WAVE_BASE 0x1300u
|
|
#define SET_WAVE_DATA 0xA000u
|
|
typedef struct {
|
|
void *context;
|
|
/* Return 0 on success. Samples remain owned by state until stop returns.
|
|
* start must arrange periodic output, typically DAC + timer + DMA.
|
|
* stop must quiesce DMA before returning and set output to zero. */
|
|
int (*start)(void *, const uint16_t *, size_t, uint32_t);
|
|
void (*stop)(void *);
|
|
} set_wave_port;
|
|
typedef struct {
|
|
uint16_t *samples;
|
|
size_t capacity;
|
|
uint16_t count, received, ready, running, rate_high;
|
|
uint32_t rate;
|
|
set_wave_port port;
|
|
} set_wave_state;
|
|
void set_wave_init(set_wave_state *, uint16_t *, size_t, const set_wave_port *);
|
|
/* Atomic sample-block transfer. values=NULL builds a read; otherwise a write.
|
|
* At most 120 words: request <=249 bytes, response <=245 bytes. */
|
|
PCAN_ABI_API size_t set_wave_block_request(unsigned device,unsigned index,
|
|
const uint16_t *values,size_t count,uint8_t *out,size_t capacity);
|
|
PCAN_ABI_API int set_wave_block_response(const uint8_t *request,size_t request_size,
|
|
const uint8_t *reply,size_t reply_size,uint16_t *words,size_t capacity);
|
|
size_t set_wave_block_rtu(set_wave_state *,unsigned device,const uint8_t *,size_t,
|
|
uint8_t *,size_t);
|
|
/* Relative register callbacks for set_regmap; status=8 words, samples=4096.
|
|
* These are the same state/validation used by the legacy RTU wrapper. */
|
|
PCAN_ABI_API unsigned set_wave_read(void *,uint16_t,uint16_t,uint16_t *);
|
|
PCAN_ABI_API unsigned set_wave_write(void *,uint16_t,uint16_t);
|
|
PCAN_ABI_API unsigned set_wave_samples_read(void *,uint16_t,uint16_t,uint16_t *);
|
|
PCAN_ABI_API unsigned set_wave_samples_write(void *,uint16_t,uint16_t);
|
|
/* Caller serializes calls in the main loop. Returns complete reply size,
|
|
* 0 for unrelated/invalid frames. CRC verified before all state changes. */
|
|
size_t set_wave_rtu(set_wave_state *, unsigned device, const uint8_t *, size_t,
|
|
uint8_t *, size_t);
|
|
/* Thin host transport ABI. Operations: 0=status, 1=stop, 2=sample rate,
|
|
* 3=begin upload(count), 4=sample(index,value), 5=commit, 6=start.
|
|
* 7=read a sample(index) for verification. Return 8 or 0. */
|
|
PCAN_ABI_API size_t set_wave_request(unsigned device,unsigned operation,unsigned index,
|
|
unsigned value,uint8_t *out,size_t capacity);
|
|
/* Return 0=need more bytes, positive=word count, negative=invalid/exception.
|
|
* Validates exact echo/read shape, CRC, address and signature on status. */
|
|
PCAN_ABI_API int set_wave_response(const uint8_t *request,const uint8_t *reply,
|
|
size_t size,uint16_t *words,size_t capacity);
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
#endif
|