コード例 #1
0
ファイル: main.c プロジェクト: spacemanspiff/Hermes--cIOS
int main(void)
{

current_port= ((u32) use_usb_port1)!=0;
// changes IOS vector interrupt to crt0.s routine

//swi_mload_led_on();

syscall_base=swi_mload_get_syscall_base();
os_sync_after_write((void *) &syscall_base, 4);

swi_mload_call_func((void *) copy_int_vect, (void *) swi_mload_get_ios_base(), NULL);


heaphandle = os_heap_create(heapspace, sizeof(heapspace));

void* timer1_queuespace = os_heap_alloc(heaphandle, 0x80);

timer1_queuehandle = os_message_queue_create(timer1_queuespace, 32);



    if(tiny_ehci_init()<0) return -1;
	
  
    ehc_loop();

	return 0;
}
コード例 #2
0
ファイル: usb_os.c プロジェクト: spacemanspiff/Hermes--cIOS
int usb_os_init(void)
{
        heap = os_heap_create(heap_space2, 0xe000);
		//heap = os_heap_create((void*)0x13890000, 0x8000);
        if(heap<0)
        {
          return -1;
        }
        return 0;
}
コード例 #3
0
ファイル: mem.c プロジェクト: shadowbladeZ/fat-module
s32 Mem_Init(void)
{
	/* Heap already created */
	if (hid >= 0)
		return 0;

	/* Create heap */
	hid = os_heap_create(heapspace, sizeof(heapspace));

	return (hid >= 0) ? 0 : -1;
}
コード例 #4
0
ファイル: main.c プロジェクト: spacemanspiff/Hermes--cIOS
int main(void)
{
int n=0x0;
int tid=0;
u32 message;


	heaphandle = os_heap_create(heapspace, sizeof(heapspace));

	void* queuespace = os_heap_alloc(heaphandle, 0x20);

	queuehandle = os_message_queue_create(queuespace, 8);

	os_sync_before_read((void *) 0x13740000, 16 );
	
	 tid=os_create_timer(1000*1000, 1000*1000*1, queuehandle, 0x666);
	 
	 // count to 0
	 *((u32 *) 0x13740000)=0;
	 n=0;

	 
    // create a thread to reset the counter 
	int my_thread_id=os_thread_create( (void *) thread_start, NULL, &thread_stack[1024], 1024, 0x28, 1);

	if(my_thread_id>=0) os_thread_continue(my_thread_id);
	
	while(1)
		{

		n++; // counter ++

		os_message_queue_receive(queuehandle,(void *) &message, 0);
		// here i can receive 0x555 (from thread_start timer) or 0x666 message (from tid timer)
	
		if(message==0x555) n=0;

		os_sync_before_read((void *) 0x13740000, 16 );

		*((u32 *) 0x13740000)=n;
		*((u32 *) 0x13740004)= os_get_thread_id();
		*((u32 *) 0x13740008)= os_thread_get_priority();

		os_sync_after_write((void *) 0x13740000, 16 );

	
		//os_stop_timer(tid);
		//os_restart_timer(tid,1000*500);
		}

	return 0;
}
コード例 #5
0
ファイル: main.c プロジェクト: spacemanspiff/Hermes--cIOS
int main(void)
{
int fd,n,mounted=0;
int inited=0;
ipcmessage* message;


	memset(&my_reent, 0, sizeof(struct _reent));
	memset(my_filestr, 0, sizeof(FILE_STRUCT)*5);
	memset(file_table, 0, 4*2*5);

	memset(&dir_state_internal,0,sizeof(DIR_STATE_STRUCT));

	dir_internal.device=0;
	dir_internal.dirStruct=&dir_state_internal;

	

	heaphandle = os_heap_create(heapspace, sizeof(heapspace));

	void* queuespace = os_heap_alloc(heaphandle, 0x20);

	queuehandle = os_message_queue_create(queuespace, 8);

	 void* timer1_queuespace = os_heap_alloc(heaphandle, 0x40);

	timer1_queuehandle = os_message_queue_create(timer1_queuespace, 16);
	timer1_id=os_create_timer(1000*1000, 1, timer1_queuehandle, 0x666);
	os_stop_timer(timer1_id);

	 
	extern DISC_INTERFACE __io_wiisd;
	inited=__io_wiisd.startup();
	msleep(100);

	os_device_register(DEVICE, queuehandle);
	while(1)
		{
		int result = 1;
		int ack = 1;

		os_message_queue_receive(queuehandle,(void *) &message, 0);
		
		switch( message->command )
		{
		
	    case IOS_OPEN:
			{
			result = -6;

                                //debug_printf("%s try open %sfor fd %d\n",DEVICE,message->open.device,message->open.resultfd);
				// Checking device name
				if (0 == strcmp(message->open.device, DEVICE))
                                  {
									result = message->open.resultfd;        
                                  }
				else
				if (0 == strcmp(message->open.device, DEVICE"/log"))
                                  {
								  if(inited && !mounted) 
										mounted=fatMountSimple("sd", &__io_wiisd);

								  if(mounted)
									{
									static char log_name[]="sd:/log000.txt";
									for(n=0;n<5;n++) if(my_filestr[n].inUse==0) break;
									fd=-1;
									if(n!=5)
										{
										my_reent._errno=0;
										fd=_FAT_open_r(&my_reent, &my_filestr[n], log_name, O_CREAT | O_TRUNC | O_RDWR, 0);
										log_name[9]++;
										if(log_name[9]>='9') {log_name[9]='0';log_name[8]++;}
										if(log_name[8]>='9') {log_name[8]='0';log_name[7]++;}
										if(log_name[7]>='9') {log_name[7]='0';log_name[8]='0';log_name[9]='0';}

										}
									
									if(fd<0) result=-1; 
									else 
										{
										result=file_table[n][0]=message->open.resultfd;
										file_table[n][1]= fd;
										}
									}
                        
                                  }
				else if (0 == memcmp(message->open.device, DEVICE"/", sizeof(DEVICE)))
                                        
				{
				if(inited && !mounted) 
					mounted=fatMountSimple("sd", &__io_wiisd);

				if(mounted)
					{
					for(n=0;n<5;n++) if(my_filestr[n].inUse==0) break;
					fd=-1;
					if(n!=5)
						{
						my_reent._errno=0;
						fd=_FAT_open_r(&my_reent, &my_filestr[n], message->open.device+sizeof(DEVICE),
							message->open.mode, 0);	
							
						}

					if(fd<0) result=-1; 
					else 
						{
						result=file_table[n][0]=message->open.resultfd;
						file_table[n][1]= fd;
						}
					}
				}
			
					
			}	
			break;

		case IOS_IOCTLV:
			{
			result = -1;

			ioctlv *vec = message->ioctlv.vector;

                                int i,in = message->ioctlv.num_in,io= message->ioctlv.num_io;
                               
                                os_sync_before_read( vec, (in+io)*sizeof(ioctlv));

                                for(i=0;i<in+io;i++){
                                        os_sync_before_read( vec[i].data, vec[i].len);
                                      
                                }

			#if 0
			// list the directory content to directory.txt
			switch(message->ioctl.command )
				{
				
				case 0xcacafea:
				if(inited && !mounted) 
						mounted=fatMountSimple("sd", &__io_wiisd);

				if(mounted)
					{
					my_reent._errno=0;
					
					result=-666;
					if(_FAT_diropen_r(&my_reent, &dir_internal, "sd:/"))
						{
						static char log_name2[]="sd:/directory.txt";
						char filename[768];

						result = 0;
						my_reent._errno=0;
						fd=_FAT_open_r(&my_reent, &my_filestr[4], log_name2, O_CREAT | O_TRUNC | O_RDWR, 0);
						my_reent._errno=0;
						while(!_FAT_dirnext_r (&my_reent, &dir_internal, filename, &filestat))
							{
							my_reent._errno=0;
							
							if(fd>=0)
								{
								if(filestat.st_mode & S_IFDIR)_FAT_write_r (&my_reent, fd, "[", 1); // es directorio
								_FAT_write_r (&my_reent, fd, filename, strlen(filename));
								if(filestat.st_mode & S_IFDIR)_FAT_write_r (&my_reent, fd, "]", 1); // es directorio
								_FAT_write_r (&my_reent, fd, "\n", 1);
								
								}
							
							}
							my_reent._errno=0;
							if(fd>=0) _FAT_close_r (&my_reent, fd);fd=-1;

						  _FAT_dirclose_r(&my_reent, &dir_internal);
						}

					
					}
				break;
				}
			#endif
				for(i=in;i<in+io;i++){
											os_sync_after_write( vec[i].data, vec[i].len);
									}
			
			}
			break;

		case IOS_CLOSE:
			{
			result = -1;
			if(mounted)
				{
				my_reent._errno=0;
				for(n=0;n<5;n++)
					{
					if(message->fd==file_table[n][0])
						{
						fd=file_table[n][1];
						file_table[n][0]=file_table[n][1]=0;
						_FAT_close_r (&my_reent, fd);
						result = 0;
						break;
						}
					}

				for(n=0;n<5;n++) if(my_filestr[n].inUse!=0) break;
					  
				if(n==5) {fatUnmount ("sd");mounted=0;}
				
				}
				else result=-6;
				
			}	
			break;

		case IOS_READ:
			{
			
			result=-1;
			if(mounted)
				{
				my_reent._errno=0;
				for(n=0;n<5;n++)
					{
					if(message->fd==file_table[n][0])
						{
						fd=file_table[n][1];
						result=_FAT_read_r (&my_reent, fd, message->write.data, message->write.length);
						}
					}
				}
			os_sync_after_write( message->write.data, message->write.length);
			}	
			break;

		case IOS_WRITE:
			{
		
			os_sync_before_read( message->write.data, message->write.length);

			result=-1;
			if(mounted)
				{
				my_reent._errno=0;
				for(n=0;n<5;n++)
					{
					if(message->fd==file_table[n][0])
						{
						fd=file_table[n][1];
						result=_FAT_write_r (&my_reent, fd, message->write.data, message->write.length);
						}
					}
				}		
			}	
			break;

		case IOS_SEEK:
			{
			result=-1;
			if(mounted)
				{
				my_reent._errno=0;
				for(n=0;n<5;n++)
					{
					if(message->fd==file_table[n][0])
						{
						fd=file_table[n][1];
						result=_FAT_seek_r (&my_reent, fd, message->seek.offset, message->seek.origin);
						}
					}
				}		
			}
			break;

		default:
			result=-1;
			break;

		}

		if (ack)
			os_message_queue_ack( (void*)message, result );

		}

	return 0;
}