HLS: Change write burst code to something without critical warnings. Avoid zero memcopy
@@ -126,15 +126,22 @@ typedef struct snap_4KiB_t {
snap_membus_t buf[SNAP_4KiB_WORDS]; /* temporary storage buffer */
snap_membus_t *mem; /* source where data comes from */
unsigned short max_lines; /* size of the memory buffer */
+ unsigned short free_lines;
unsigned short m_idx; /* read position for source */
unsigned char b_idx; /* read position for buffer */
} snap_4KiB_t;
+static inline int snap_4KiB_empty(snap_4KiB_t *buf)
+{
+ return buf->b_idx == 0;
+}
+
static void snap_4KiB_rinit(snap_4KiB_t *buf, snap_membus_t *mem,
unsigned short max_lines)
{
buf->mem = mem;
buf->max_lines = max_lines;
+ buf->free_lines = max_lines;
buf->m_idx = 0;
buf->b_idx = SNAP_4KiB_WORDS;
}
@@ -144,6 +151,7 @@ static void snap_4KiB_winit(snap_4KiB_t *buf, snap_membus_t *mem,
{
buf->mem = mem;
buf->max_lines = max_lines;
+ buf->free_lines = max_lines;
buf->m_idx = 0;
buf->b_idx = 0;
}
@@ -180,21 +188,26 @@ static void snap_4KiB_get(snap_4KiB_t *buf, snap_membus_t *line)
/**
* Writing beyond the available memory is blocked, still we accept
* data in the local buffer, but that will not be written out.
+ * Normally I would have written that with tocopy = MIN(free_lines, buf->b_idx)
+ * but that produced hardware with bad timing.
*/
static void snap_4KiB_flush(snap_4KiB_t *buf)
{
- unsigned short free_lines = buf->max_lines - buf->m_idx;
- unsigned short tocopy = MIN(free_lines, buf->b_idx);
+ unsigned short tocopy = MIN(buf->b_idx, buf->free_lines);
-#if defined(CONFIG_4KIB_DEBUG)
- fprintf(stderr, "4KiB buffer %d lines, writing %d bytes "
- "free: %d bmax: %d mmax: %d\n",
- tocopy, tocopy * sizeof(snap_membus_t),
- free_lines, SNAP_4KiB_WORDS, buf->max_lines);
-#endif
+ switch (tocopy) {
+ case 0:
+ break;
+ case SNAP_4KiB_WORDS:
+ memcpy(buf->mem + buf->m_idx, buf->buf,
+ SNAP_4KiB_WORDS * sizeof(snap_membus_t));
+ break;
+ default:
memcpy(buf->mem + buf->m_idx, buf->buf,
tocopy * sizeof(snap_membus_t));
-
+ break;
+ }
+ buf->free_lines -= tocopy;
buf->m_idx += tocopy;
buf->b_idx = 0;
}
@@ -291,8 +304,8 @@ static void write_table3(snap_membus_t *mem, unsigned int max_lines,
snap_4KiB_put(&buf, d[1]);
snap_4KiB_put(&buf, d[2]);
}
+
/* FIXME Tryout for 0 entries ... */
- if (t3_used != 0)
snap_4KiB_flush(&buf);
}
