Skip to content

Commit

Permalink
Merge pull request #32 from matwey/fix/31_v2
Browse files Browse the repository at this point in the history
Reimplement cha_loop to improve stream stop
  • Loading branch information
matwey authored Mar 26, 2023
2 parents 11ca449 + 56c5d37 commit 6552ac9
Show file tree
Hide file tree
Showing 7 changed files with 322 additions and 141 deletions.
22 changes: 18 additions & 4 deletions include/cha.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,24 @@ struct cha {

struct cha_loop {
struct cha* cha;
struct frame_decoder fd;
struct libusb_transfer* transfer[3];
size_t active_transfers;

ov_packet_decoder_callback callback;
void* user_data;

int count;
int max_count;
int break_loop;
enum cha_loop_state {
RUNNING = 0,
FATAL_ERROR = 1,
BREAK_LOOP = 2,
COUNT_LIMIT = 3,
END_OF_STREAM = 4,
HOST_READ_OFF = 5
} state;
int complete;
struct frame_decoder fd;
};

int cha_init(struct cha* cha, struct fwpkg* fwpkg);
Expand All @@ -36,19 +45,24 @@ int cha_switch_config_mode(struct cha* cha);
int cha_switch_fifo_mode(struct cha* cha);
int cha_write_reg_by_name(struct cha* cha, enum reg_name name, uint8_t val);
int cha_read_reg_by_name(struct cha* cha, enum reg_name name, uint8_t* val);
int cha_cast_reg_by_name(struct cha* cha, enum reg_name name, uint8_t val);
int cha_write_reg32_by_name(struct cha* cha, enum reg_name name, uint32_t val);
int cha_read_reg32_by_name(struct cha* cha, enum reg_name name, uint32_t* val);
int cha_write_ulpi(struct cha* cha, uint8_t addr, uint8_t val);
int cha_read_ulpi(struct cha* cha, uint8_t addr, uint8_t* val);
int cha_get_usb_speed(struct cha* cha, enum ov_usb_speed* speed);
int cha_set_usb_speed(struct cha* cha, enum ov_usb_speed speed);
int cha_start_stream(struct cha* cha);
int cha_halt_stream(struct cha* cha);
int cha_stop_stream(struct cha* cha);
int cha_set_reg(struct cha* cha, struct reg* reg);
void cha_destroy(struct cha* cha);

int cha_loop_init(struct cha_loop* loop, struct cha* cha, struct ov_packet* packet, size_t packet_size, ov_packet_decoder_callback callback, void* user_data);
int cha_loop_run(struct cha_loop* loop, int count);
ov_packet_decoder_callback cha_loop_set_callback(struct cha_loop* loop, ov_packet_decoder_callback callback, void* user_data);
void cha_loop_break(struct cha_loop* loop);
int cha_set_reg(struct cha* cha, struct reg* reg);
void cha_destroy(struct cha* cha);
void cha_loop_destroy(struct cha_loop* loop);

const char* cha_get_error_string(struct cha* cha);

Expand Down
43 changes: 31 additions & 12 deletions include/decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@

#include <openvizsla.h>

struct decoder_ops {
void (*packet) (void*, struct ov_packet*);
void (*bus_frame) (void*, uint16_t, uint8_t);
};

struct packet_decoder {
struct ov_packet* packet;
size_t buf_actual_length;
size_t buf_length;
char* error_str;

ov_packet_decoder_callback callback;
void* user_data;
struct decoder_ops ops;
void* user_data;

enum packet_decoder_state {
NEED_PACKET_MAGIC,
Expand All @@ -28,25 +30,42 @@ struct packet_decoder {
NEED_PACKET_TIMESTAMP_HI,
NEED_PACKET_DATA
} state;

size_t buf_actual_length;
size_t buf_length;

char* error_str;
};

int packet_decoder_init(struct packet_decoder* pd, struct ov_packet* p, size_t size, ov_packet_decoder_callback callback, void* data);
int packet_decoder_init(struct packet_decoder* pd, struct ov_packet* p, size_t size, const struct decoder_ops* ops, void* user_data);
int packet_decoder_proc(struct packet_decoder* pd, uint8_t* buf, size_t size);

struct frame_decoder {
struct packet_decoder pd;

char* error_str;

enum frame_decoder_state {
NEED_FRAME_MAGIC,
NEED_FRAME_LENGTH,
NEED_FRAME_DATA
NEED_SDRAM_FRAME_LENGTH,
NEED_SDRAM_FRAME_DATA,
NEED_BUS_FRAME_ADDR_HI,
NEED_BUS_FRAME_ADDR_LO,
NEED_BUS_FRAME_VALUE,
NEED_BUS_FRAME_CHECKSUM
} state;
size_t required_length;

union {
struct {
uint16_t required_length;
} sdram;
struct {
uint16_t addr;
uint8_t value;
uint8_t checksum;
} bus;
};
};

int frame_decoder_init(struct frame_decoder* fd, struct ov_packet* p, size_t size, ov_packet_decoder_callback callback, void* data);
int frame_decoder_init(struct frame_decoder* fd, struct ov_packet* p, size_t size, const struct decoder_ops* ops, void* user_data);
int frame_decoder_proc(struct frame_decoder* fd, uint8_t* buf, size_t size);

#endif // _DECODER_H
1 change: 1 addition & 0 deletions include/openvizsla.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ OPENVIZSLA_EXPORT int ov_set_usb_speed(struct ov_device* ov, enum ov_usb_speed s
OPENVIZSLA_EXPORT int ov_capture_start(struct ov_device* ov, struct ov_packet* packet, size_t packet_size, ov_packet_decoder_callback callback, void* user_data);
OPENVIZSLA_EXPORT int ov_capture_dispatch(struct ov_device* ov, int count);
OPENVIZSLA_EXPORT void ov_capture_breakloop(struct ov_device* ov);
OPENVIZSLA_EXPORT ov_packet_decoder_callback ov_capture_set_callback(struct ov_device* ov, ov_packet_decoder_callback callback, void* user_data);
OPENVIZSLA_EXPORT int ov_capture_stop(struct ov_device* ov);

OPENVIZSLA_EXPORT int ov_load_firmware(struct ov_device* ov, const char* filename);
Expand Down
Loading

0 comments on commit 6552ac9

Please sign in to comment.