Skip to content

Commit

Permalink
Improve cha_start_stream
Browse files Browse the repository at this point in the history
  • Loading branch information
matwey committed Sep 16, 2024
1 parent cb1a535 commit 0f52542
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions src/cha.c
Original file line number Diff line number Diff line change
Expand Up @@ -402,37 +402,58 @@ int cha_set_usb_speed(struct cha* cha, enum ov_usb_speed speed) {
}

int cha_start_stream(struct cha* cha) {
const uint32_t ring_base = 0;
const uint32_t ring_end = 0x01000000;

int ret = 0;

ret = cha_write_reg32_by_name(cha, SDRAM_SINK_RING_BASE, 0);
ret = cha_write_reg32_by_name(cha, SDRAM_SINK_RING_BASE, ring_base);
if (ret == -1)
return ret;

ret = cha_write_reg32_by_name(cha, SDRAM_SINK_RING_END, 0x01000000);
ret = cha_write_reg32_by_name(cha, SDRAM_SINK_RING_END, ring_end);
if (ret == -1)
return ret;

ret = cha_write_reg32_by_name(cha, SDRAM_HOST_READ_RING_BASE, 0);
ret = cha_write_reg32_by_name(cha, SDRAM_HOST_READ_RING_BASE, ring_base);
if (ret == -1)
return ret;

ret = cha_write_reg32_by_name(cha, SDRAM_HOST_READ_RING_END, 0x01000000);
ret = cha_write_reg32_by_name(cha, SDRAM_HOST_READ_RING_END, ring_end);
if (ret == -1)
return ret;

ret = cha_write_reg_by_name(cha, SDRAM_SINK_PTR_READ, 0);
if (ret == -1)
return ret;

/*
* SDRAM SINK takes octets from CSTREAM and writes the data to SDRAM
* using internal FIFO. When SDRAM_SINK_GO is set to 1, then
* SDRAM_SINK_WPTR is reset to SDRAM_SINK_RING_BASE.
*/

ret = cha_write_reg_by_name(cha, SDRAM_SINK_GO, 1);
if (ret == -1)
return ret;

ret = cha_write_reg_by_name(cha, SDRAM_HOST_READ_GO, 1);
/*
* CSTREAM takes data from the USB phy and forward the data as 0xA0
* packages to SDRAM SINK
*/

ret = cha_write_reg_by_name(cha, CSTREAM_CFG, 1);
if (ret == -1)
return ret;

ret = cha_cast_reg_by_name(cha, CSTREAM_CFG, 1);
/*
* SDRAM HOST READ takes existing data from SDRAM and forms 0xD0
* packages via internal FIFO. When SDRAM_HOST_READ_GO is set to 1,
* then SDRAM_HOST_READ_RPTR_STATUS is reset to
* SDRAM_HOST_READ_RING_BASE.
*/

ret = cha_cast_reg_by_name(cha, SDRAM_HOST_READ_GO, 1);
if (ret == -1)
return ret;

Expand All @@ -456,11 +477,11 @@ int cha_stop_stream(struct cha* cha) {
if (ret == -1)
return ret;

ret = cha_write_reg_by_name(cha, SDRAM_SINK_GO, 0);
ret = cha_write_reg_by_name(cha, CSTREAM_CFG, 0);
if (ret == -1)
return ret;

ret = cha_write_reg_by_name(cha, CSTREAM_CFG, 0);
ret = cha_write_reg_by_name(cha, SDRAM_SINK_GO, 0);
if (ret == -1)
return ret;

Expand Down

0 comments on commit 0f52542

Please sign in to comment.