⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 osthreads.c

📁 KaOS is a real-time operating system that has been implemented with the basic real-time constraints
💻 C
字号:
void sdthread()
{
	os_thread *thread, *temp_thread, *next_thread;
	char c;
	UCHAR *buffer;
	//FILE* file;
	//DIR* dir;
	register UINT progSize, i;
	//UCHAR filename[22] = "test.txt";
	thread = g_currthread;

	DDRB |= 0b00000100;
	
	while (1)
	{
		c = MmcInit();
		if (c == 0)
		{
			PORTB.2 = 1;
		}
		else
		{
			PORTB.2 = 0;
		}
		if (c == 0 && PINB.1 == 0)
		{
			PORTB.2 = 0;
			// we want to load a new program
			temp_thread = g_usedthreads;
			while (temp_thread != NULL)
			{
				// kill any thread but the null/sd thread
				if (temp_thread != thread)
				{
					next_thread = temp_thread->next;
					TerminateThread(temp_thread);
					temp_thread = next_thread;
				}
				else
				{
					temp_thread = temp_thread->next;
				}
			}
			os_reset_stack();
			
			// grab some stack space
			//file = (FILE*)os_alloc_stack(sizeof(FILE));
			
			//dir = (DIR*)os_alloc_stack(sizeof(DIR));
			
			//dir->directoryID = 0;
			
			//fopen(dir, file, filename, FOPEN_CREATE);
			//dread(dir,file);
			buffer = (UCHAR*)os_alloc_stack(512);
			
			// read in the first sector. The first 2 bytes are the size of the program
			mmc_read_sector(0, buffer);
			progSize = (((int)buffer[0]) << 8) | buffer[1];
			
			// just write 0x00 and jmp to 0x01
			buffer[0] = buffer[1] = 0;
			
			// write the first sector
			WriteSector(0, (UINT*)buffer);
			
			for (i = 512; i < progSize; i += 512)
			{
				mmc_read_sector(i, buffer);
		   		WriteSector(i, (UINT*)buffer);
			}
			os_reset_stack();
			#asm("cli");
			temp_thread = CreateThread(1, 255, 150, 150);
			#asm("sei");
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -