view target-utils/dspdump/dspops.c @ 681:0815661d6e3e

doc/Loadtools-performance: typo fix
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 09 Mar 2020 07:24:28 +0000
parents 27b5526ba1a8
children
line wrap: on
line source

#include "types.h"
#include "leadapi.h"
#include "dumpagent.h"

wait_for_dsp_ready()
{
	unsigned cnt;

	for (cnt = 0; cnt < 10000; cnt++)
		if (DOWNLOAD_STATUS == LEAD_READY)
			return(0);
	return(-1);
}

boot_dsp_dump_agent()
{
	const u16 *src;
	volatile u16 *api;
	unsigned n;

	/* put it into reset first */
	CLKM_CNTL_RST |= CLKM_LEAD_RST;
	/* generous 1 ms for the reset pulse */
	wait_ARM_cycles(13000);
	/* lift it out of reset */
	CLKM_CNTL_RST &= ~CLKM_LEAD_RST;
	/* another generous 1 ms */
	wait_ARM_cycles(13000);
	/* bootloader should be ready for us now */
	if (wait_for_dsp_ready() < 0) {
		printf("ERROR: DSP bootloader not ready out of reset\n");
		return(-1);
	}
	/* upload the agent code */
	src = dsp_agent_code;
	api = (volatile u16 *) APIF_ADDR;
	for (n = 0; n < DSP_DUMPCODE_LEN; n++)
		*api++ = *src++;
	DOWNLOAD_EXT_PAGE = 0;
	DOWNLOAD_SIZE = DSP_DUMPCODE_LEN;
	DOWNLOAD_ADDR = DSP_DUMPCODE_START;
	DOWNLOAD_STATUS = BLOCK_READY;
	if (wait_for_dsp_ready() < 0) {
		printf("ERROR: DSP bl not ready after block write\n");
		return(-1);
	}
	/* start it! */
	DOWNLOAD_EXT_PAGE = 0;
	DOWNLOAD_SIZE = 0;
	DOWNLOAD_ADDR = DSP_DUMPCODE_START;
	DOWNLOAD_STATUS = BLOCK_READY;
	if (wait_for_dsp_ready() < 0) {
		printf("ERROR: DSP not ready after commanded jump to agent\n");
		return(-1);
	}
}

dsp_read_op(mode, addr, blklen)
	u16 mode, blklen;
	u32 addr;
{
	int rc;

	APIRAM_FIRST_WORD = mode;
	DOWNLOAD_STATUS = PAGE_SELECTION;
	rc = wait_for_dsp_ready();
	if (rc < 0)
		return(rc);
	DOWNLOAD_EXT_PAGE = addr >> 16;
	DOWNLOAD_SIZE = blklen;
	DOWNLOAD_ADDR = addr;
	DOWNLOAD_STATUS = BLOCK_READY;
	rc = wait_for_dsp_ready();
	return(rc);
}