view target-utils/loadagent/binflash.c @ 1014:961efadd530a default tip

fc-shell TCH DL handler: add support for CSD modes TCH DL capture mechanism in FC Tourmaline firmware has been extended to support CSD modes in addition to speech - add the necessary support on the host tools side. It needs to be noted that this mechanism in its present state does NOT provide the debug utility value that was sought: as we learned only after the code was implemented, TI's DSP has a misfeature in that the buffer we are reading (a_dd_0[]) is zeroed out when the IDS block is enabled, i.e., we are reading all zeros and not the real DL bits we were after. But since the code has already been written, we are keeping it - perhaps we can do some tests with IDS disabled.
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 26 Nov 2024 06:27:43 +0000
parents b34384991094
children
line wrap: on
line source

/*
 * Here we are going to implement our new binary protocol
 * for flash programming.
 */

#include "types.h"

void
binary_flash_prog_main(program_func)
	int (*program_func)();
{
	u8 buf[2048] __attribute__ ((aligned (2)));
	u32 flash_offset;
	unsigned nbytes, p;
	int c;

	for (;;) {
		do
			c = serial_in_poll();
		while (c < 0);
		if (c == 0x04)
			return;
		if (c != 0x01) {
			serial_out(0x15);	/* NAK */
			printf("ERROR: invalid command opcode\n");
			return;
		}
		/* receive header */
		for (p = 0; p < 6; p++) {
			c = serial_in_timeout(1000000);		/* 0.6 s */
			if (c < 0) {
intermediate_timeout:		serial_out(0x15);	/* NAK */
				printf("ERROR: timeout receiving command\n");
				return;
			}
			buf[p] = c;
		}
		flash_offset =  ((u32) buf[0] << 24) |
				((u32) buf[1] << 16) |
				((u32) buf[2] << 8) |
				 (u32) buf[3];
		if (flash_offset & 1) {
			serial_out(0x15);	/* NAK */
			printf("ERROR: odd flash offset\n");
			return;
		}
		nbytes = ((u32) buf[4] << 8) | (u32) buf[5];
		if (nbytes & 1) {
			serial_out(0x15);	/* NAK */
			printf("ERROR: odd byte count\n");
			return;
		}
		if (nbytes > sizeof buf) {
			serial_out(0x15);	/* NAK */
			printf("ERROR: byte count exceeds buffer\n");
			return;
		}
		/* receive data */
		for (p = 0; p < nbytes; p++) {
			c = serial_in_timeout(1000000);		/* 0.6 s */
			if (c < 0)
				goto intermediate_timeout;
			buf[p] = c;
		}
		c = program_func(flash_offset, nbytes >> 1, buf);
		if (c < 0)
			return;
		serial_out(0x06);	/* ACK */
	}
}