Пример #1
0
/**
 * Startup thread
 *
 * Creates the main program thread based on variables defined by the program.
 *
 * @param args - Size (in bytes) of arguments passed to the program by the kernel.
 * @param argp - Pointer to arguments passed by the kernel.
 */
int _start(SceSize args, void *argp)
{
	void (*_main_func)(SceSize args, void *argp) = _main;
	void (*_init_func)(void) = _init;

	if ((&module_info != NULL) && (module_info.modattribute & 0x1000)) {
		/* If we're running in kernel mode, the addresses of our _main() thread
		   and _init() function must also reside in kernel mode. */
		_main_func = (void *) ((u32) _main_func | 0x80000000);
		_init_func = (void *) ((u32) _init_func | 0x80000000);
	}

	/* Call _init() here, because an app may have code that needs to run in
	   kernel mode, but want their main() thread to run in user mode.  If they
	   define "constructors" they can do any kernel mode initialization here
	   before their app is switched. */
	_init_func();

	if (&sce_newlib_nocreate_thread_in_start != NULL) {
		/* The program does not want main() to be run in a seperate thread. */
		_main_func(args, argp);
		return 1;
	}

	int priority = DEFAULT_THREAD_PRIORITY;
	unsigned int attribute = DEFAULT_THREAD_ATTRIBUTE;
	unsigned int stackSize = DEFAULT_THREAD_STACK_KB_SIZE * 1024;
	const char *threadName = DEFAULT_MAIN_THREAD_NAME;

	if (&sce_newlib_priority != NULL) {
		priority = sce_newlib_priority;
	}
	if (&sce_newlib_attribute != NULL) {
		attribute = sce_newlib_attribute;
	}
	if (&sce_newlib_stack_kb_size != NULL) {
		stackSize = sce_newlib_stack_kb_size * 1024;
	}
	if (&sce_newlib_main_thread_name != NULL) {
		threadName = sce_newlib_main_thread_name;
	}

	/* Does the _main() thread belong to the User, VSH, or USB/WLAN APIs? */
	if (attribute & (PSP_THREAD_ATTR_USER | PSP_THREAD_ATTR_USBWLAN | PSP_THREAD_ATTR_VSH)) {
		/* Remove the kernel mode addressing from the pointer to _main(). */
		_main_func = (void *) ((u32) _main_func & 0x7fffffff);
	}

	SceUID thid;
	thid = sceKernelCreateThread(threadName, (void *) _main_func, priority, stackSize, attribute, 0);
	sceKernelStartThread(thid, args, argp);

	return 0;
}
Пример #2
0
int main(void)
{
	/* initialize LED and debug unit */
	led_init();
	sysirq_init();
	AT91F_DBGU_Init();

	AT91F_PIOA_CfgPMC();
	wdt_init();
	pit_init();
	blinkcode_init();

	/* initialize USB */
	req_ctx_init();
	usbcmd_gen_init();
	udp_open();

	/* call application specific init function */
	_init_func();

	// Enable User Reset and set its minimal assertion to 960 us
	AT91C_BASE_RSTC->RSTC_RMR =
	    AT91C_RSTC_URSTEN | (0x4 << 8) | (unsigned int)(0xA5 << 24);

#ifdef DEBUG_CLOCK_PA6
	AT91F_PMC_EnablePCK(AT91C_BASE_PMC, 0, AT91C_PMC_CSS_PLL_CLK);
	AT91F_PIO_CfgPeriph(AT91C_BASE_PIOA, 0, AT91C_PA6_PCK0);
#endif

	/* switch on first led */
	led_switch(2, 1);

	DEBUGPCRF("entering main (idle) loop");
	while (1) {
		/* Call application specific main idle function */
		_main_func();
		dbgu_rb_flush();
		
		/* restart watchdog timer */
		wdt_restart();
#ifdef CONFIG_IDLE
		//cpu_idle();
#endif
	}
}