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

📄 os_dep.c

📁 UCOS在ARM7TDMI上的移植。与它的官方版不同的是
💻 C
字号:
/***********************************************************************************************
*				操作系统相关的一些接口函数
*
*
*				Create by ZHW, 050925
*	
*
*************************************************************************************************/

#include "os_dep.h"

//os used memory and look up table define
///////////////////////////////////////////////////////////////////////
//task
//////////////////////////////////////////////////////////////////////
// statcks
OS_STK g_drvTaskStack[TSK_DRV_STACK_SIZE];
OS_STK g_mmiTaskStack[TSK_MMI_STACK_SIZE];


struct task_def_struct{
	void (*task)(void *pd);
	OS_STK* pstack;
};
//LUT
//statck grows down direction
const struct task_def_struct g_allTask[OS_MAX_TASKS] = 
{
	{0,						0											},		//tskid 0
	{0,						0											},		//tskid 1
	{0,						0											},		//tskid 2
	{0,						0											},		//tskid 3
	{0,						0											},		//tskid 4
	{TSK_DRV_START_FUNC,	g_drvTaskStack+TSK_DRV_STACK_SIZE			},		//tskid 5
	{TSK_MMI_START_FUNC,	g_mmiTaskStack+TSK_MMI_STACK_SIZE			},		//tskid 6
	{0,						0											},		//tskid 7
	{0,						0											},		//tskid 8
	{0,						0											},		//tskid 9
	{0,						0											},		//tskid 10
	{0,						0											},		//tskid 11
	{0,						0											},		//tskid 12
	//the last two task is used by os(stat task and idle task)
};	


///////////////////////////////////////////////////////////////////////
//mailboxs
///////////////////////////////////////////////////////////////////////
void* g_drvMailbox[MB_DRV_SIZE];
void* g_mmiMailbox[MB_MMI_SIZE];

struct mailBoxParam
{
	void** mbxstart;
	INT32U mbxsize;
};
const struct mailBoxParam g_mailBoxParam[OS_MAX_QS] = 
{
	{g_drvMailbox,			MB_DRV_SIZE		},			//mailbox id 0
	{g_mmiMailbox,			MB_MMI_SIZE		}			//mailbox id 1
};

//filled is os_Main
OS_EVENT* g_allMailBoxEventPoint[OS_MAX_QS];	//arranged by mailbox id


//////////////////////////////////////////////////////////////////////
//memory pool
///////////////////////////////////////////////////////////////////////
//memory pool 定义必须连续并按顺序,BLOCK_SIZE也要求递增
INT32U g_memPool0[((MEM_0_BLOCK_SIZE+3)/4)*MEM_0_BLOCK_COUNT];
INT32U g_memPool1[((MEM_1_BLOCK_SIZE+3)/4)*MEM_1_BLOCK_COUNT];
INT32U g_memPool2[((MEM_2_BLOCK_SIZE+3)/4)*MEM_2_BLOCK_COUNT];
INT32U g_memPool3[((MEM_3_BLOCK_SIZE+3)/4)*MEM_3_BLOCK_COUNT];

struct memory_pool_struct{
	INT16U blocksize;
	INT16U blockcount;
	INT32U* startaddr;
};


const struct memory_pool_struct g_allMemPartitionParam[OS_MAX_MEM_PART] = 
{
	{MEM_0_BLOCK_SIZE,		MEM_0_BLOCK_COUNT,		g_memPool0},
	{MEM_1_BLOCK_SIZE,		MEM_1_BLOCK_COUNT,		g_memPool1},
	{MEM_2_BLOCK_SIZE,		MEM_2_BLOCK_COUNT,		g_memPool2},
	{MEM_3_BLOCK_SIZE,		MEM_3_BLOCK_COUNT,		g_memPool3},
};

//filled in os_Main
OS_MEM*	g_allMemPartition[OS_MAX_MEM_PART];

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

INT8U sta_tsk(INT8U tskid, void* pdata)
{
	return OSTaskCreate(g_allTask[tskid].task, pdata, g_allTask[tskid].pstack, tskid);

}

void os_free(void *pt)
{
	int index;
	for(index = OS_MAX_MEM_PART-1;index>=0;index--)
	{
		if(pt>=g_allMemPartition[index]->OSMemAddr)	//belong to this patition
		{
			OSMemPut(g_allMemPartition[index], pt);
			return;
		}
	}
}


void* os_malloc(INT16U count)
{
	void* pt;
	int index;
	INT8U err;
	for(index = 0;index<OS_MAX_MEM_PART;index++)	//因为BLOCK_SIZE是递增的
	{
		if(count<=g_allMemPartition[index]->OSMemBlkSize)	//belong to this patition
		{
			pt = OSMemGet(g_allMemPartition[index], &err);
			return pt;
		}
	}
	return 0;	//error occur
}


INT8U os_receiveMessage( INT8U msgboxid, void** pmsg)
{
	INT8U err;
	*pmsg = OSQPend(g_allMailBoxEventPoint[msgboxid], 0, &err);
	return err;
}


INT8U os_sendMessage(INT8U msgboxid, void* msg)
{
	return OSQPost(g_allMailBoxEventPoint[msgboxid], msg);
}




void os_Main(void)
{
	int index;
	INT8U err;
	//init
	OSInit();
	//creat mailbox
	for(index=0;index<OS_MAX_QS;index++)
	{
		if(g_mailBoxParam[index].mbxstart != 0)
		{
			g_allMailBoxEventPoint[index] = OSQCreate(g_mailBoxParam[index].mbxstart, g_mailBoxParam[index].mbxsize);
		}
	}
	
	//creat mempool
	for(index=0;index<OS_MAX_MEM_PART;index++)
	{
		if(g_allMemPartitionParam[index].blocksize != 0)
		{
			g_allMemPartition[index] = OSMemCreate((void*)(g_allMemPartitionParam[index].startaddr), g_allMemPartitionParam[index].blockcount, g_allMemPartitionParam[index].blocksize, &err);
		}
	}
	
	//create first task
	sta_tsk(TSKID_DRV, 0);
	
	OSStart();
	
}

void OS_CPU_IRQ_ISR_Handler(void)
{
	extern void int_irqHandle(void);
	int_irqHandle();
}



⌨️ 快捷键说明

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