Example #1
0
s32 __MLoad_Initialize(u32 *queuehandle)
{
	void *buffer = NULL;
	s32   ret;

	/* Initialize memory heap */
	Mem_Init();

	/* Initialize timer subsystem */
	Timer_Init();

	/* Allocate queue buffer */
	buffer = Mem_Alloc(0x20);
	if (!buffer)
		return IPC_ENOMEM;

	/* Create message queue */
	ret = os_message_queue_create(buffer, 8);
	if (ret < 0)
		return ret;

	/* Enable PPC HW access */
	os_ppc_access(1);

	/* Software interrupt */
	os_software_IRQ(9);

	/* Register devices */
	os_device_register(DEVICE_NAME, ret);

	/* Copy queue handler */
	*queuehandle = ret;

	return 0;
}
int ehci_int_working_callback_part2(void)
{
static int message=0;

	message=-ETIMEDOUT;

	os_message_queue_receive(ehci1_queuehandle, (void*)&message, 0); // waits for interrupt or timeout

	ehci_writel (0, &ehci->regs->intr_enable); // disable interrupts flags
	working_callback=NULL;	// disable callback

	os_stop_timer(private_timer_id); // stops the timeout timer
	os_destroy_timer(private_timer_id);
    private_timer_id=-1;
	

	if(message==0) // build message response
		{
		message=remote_message;
		}
	else message=-ETIMEDOUT;
	
	os_software_IRQ(DEV_EHCI); // enable and mask interrupt flag
 
	return message;
}
void init_thread_ehci(void)
{
	disable_EHCI_IRQ();


	ehci1_queuehandle= os_message_queue_create( USB_Alloc(4*32)/*os_heap_alloc(heaphandle, 4*32)*/, 32);

	os_unregister_event_handler(DEV_EHCI);
	os_register_event_handler(DEV_EHCI, ehci1_queuehandle, 0); // register interrupt event handler

	enable_EHCI_IRQ();
	os_software_IRQ(DEV_EHCI);

}
void ehci_int_working_callback_part1( int (*callback)(u32 flags), u32 timeout)
{

	private_timer_id=os_create_timer(timeout, 1000*1000*100, ehci1_queuehandle, 1);

	swi_mload_set_register(0x0d800038,(1<<DEV_EHCI)); // clear interrupt flag
	swi_mload_clr_register(0x0d80003c,(1<<DEV_EHCI)); // unmask interrupt flag

	working_callback=callback;
	
	ehci_writel (INTR_MASK, &ehci->regs->intr_enable);

	os_software_IRQ(DEV_EHCI); // enable and mask interrupt flag
	
}