/*
 *               Copyright (C) 2005, BroadOn Communications Corp.
 *
 *  These coded instructions, statements, and computer programs contain
 *  unpublished  proprietary information of BroadOn Communications Corp.,
 *  and  are protected by Federal copyright law. They may not be disclosed
 *  to  third  parties or copied or duplicated in any form, in whole or in
 *  part, without the prior written consent of BroadOn Communications Corp.
 *
 */

#include <types.h>
#include <sc/sc.h>
#include <sc/addr_map.h>
#include <ioslibc.h>
#include "../test.h"

// stacks;

u32 stack0[256];		// cpu0
u32 stack1[256];		// cpu1

// the list of tests;

#define	TEST_KP_TMODE			// use kilopass test modes;
#undef	TEST_KP_READSTRESS		// kilopass read stress, only for lab;

// kilopass tests;
// due to bug in test mode logic, must run at 1/10 of speed;

extern void test_kp_readall(test_t *, u32);
extern void test_kp_testdec(test_t *, u32);
extern void test_kp_spare(test_t *, u32);
extern void test_kp_readstress(test_t *, u32);
extern void test_kp_burn1(test_t *, u32);

// list of tests;

test_t Tests[] = {
#ifdef	TEST_KP_TMODE
	{ TNAME, test_kp_testdec },
	{ TNAME, test_kp_spare },
#endif	// TEST_KP_TMODE
	{ TNAME, test_kp_readall },
#ifdef	TEST_KP_READSTRESS
	{ TNAME, test_kp_readstress },
#endif	// TEST_KP_READSTRESS
	{ TNAME, 0 },
};

// simulator exports;

sim_t Sim = { 0, Tests };

/*
 * cpu0 c-code entry;
 */
void
main0(void)
{
	u32 pass, gpio;
	test_t *tp;
	int n;

	// init audio gpio [3:0] for output;
	// write 0 to indicate test start;

	IO_WRITE(PWR_CTRL_REG, PWR_CTRL_ASSERT_RST << PWR_CTRL_AUD_SHIFT);
	IO_WRITE(PWR_CTRL_REG, PWR_CTRL_CLOCK_ON << PWR_CTRL_AUD_SHIFT);
	wb_flush();
	IO_WRITE(PWR_CTRL_REG, PWR_CTRL_DEASSERT_RST << PWR_CTRL_AUD_SHIFT);
	wb_flush();
	IO_WRITE(AUD_GPIO_DIR_REG, 0x0f);
	IO_WRITE(AUD_GPIO_DATA_REG, 0);
	wb_flush();

	// run through list of tests;

	Sim.sema = 1;
	pass = test_loop(Tests, 1);

	// output test result of first 3 tests on audio gpio[2:0];
	// audio gpio[3]=1 indicates end of test;

	tp = Tests;
	gpio = 0x08;
	for(n = 0; tp->func && (n < 3); tp++, n++) {
		if( !tp->fail)
			gpio |= (1 << n);
	}
	IO_WRITE(AUD_GPIO_DATA_REG, gpio);
	wb_flush();
}

/*
 * cpu1 c-code entry;
 * cpu 1 never let out of reset;
 */
void
main1(void)
{
}

