TI SYS/BIOS cortex A8 开发

/*
 * hwihookexample.c
 *
 *  Created on: 2013-4-25
 *      Author: Administrator
 *
 *   This example demonstrates basic Hwi hook usage.
 */

#include <xdc/std.h>
#include <xdc/runtime/Error.h>
#include <xdc/runtime/System.h>
#include <xdc/runtime/Timestamp.h>

#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>
#include <ti/sysbios/hal/Timer.h>
#include <ti/sysbios/hal/Hwi.h>

extern Timer_Handle myTimer;
volatile Bool myEnd2Flag = FALSE;
int myHookSetId1, myHookSetId2;
Error_Block eb;

//Error_init(&eb);

/*HookSet 1 functions*/

/*myRegister1
 * invoked during Hwi module startup before main()
 * for each HookSet
 * */

void myRegister1(int hookSetId)
{
	System_printf("myRegister1: assigned hookSet Id =%d\n",hookSetId);
	myHookSetId1 = hookSetId;
}


/**==========myCreate1=========
 * invoked during Hwi module startup before main()
 * for statically created Hwis
 * */
void myCreate1(Hwi_Handle hwi, Error_Block *eb)
{
	Ptr pEnv;
	pEnv = Hwi_getHookContext(hwi, myHookSetId1);
	/* pEnv should be 0 at this point. If not, there's a bug. */
	System_printf("myCreate1: pEnv = 0x%x, time = %d\n", pEnv, Timestamp_get32());
	Hwi_setHookContext(hwi, myHookSetId1, (Ptr)0xdead1);
}

/* ======== myBegin1 ========
* invoked before Timer Hwi func */
void myBegin1(Hwi_Handle hwi)
{
	Ptr pEnv;
	pEnv = Hwi_getHookContext(hwi, myHookSetId1);
	System_printf("myBegin1: pEnv = 0x%x, time = %d\n", pEnv, Timestamp_get32());
	Hwi_setHookContext(hwi, myHookSetId1, (Ptr)0xbeef1);
}
/* ======== myEnd1 ========
* invoked after Timer Hwi func */
void myEnd1(Hwi_Handle hwi)
{
	Ptr pEnv;
	pEnv = Hwi_getHookContext(hwi, myHookSetId1);
	System_printf("myEnd1: pEnv = 0x%x, time = %d\n", pEnv, Timestamp_get32());
	Hwi_setHookContext(hwi, myHookSetId1, (Ptr)0xc0de1);
}

/* HookSet 2 functions */
/* ======== myRegister2 ========
* invoked during Hwi module startup before main
* for each HookSet */

void myRegister2(int hookSetId)
{
	System_printf("myRegister2: assigned hookSet Id = %d\n", hookSetId);
	myHookSetId2 = hookSetId;
}

/* ======== myCreate2 ========
* invoked during Hwi module startup before main
* for statically created Hwis */
void myCreate2(Hwi_Handle hwi, Error_Block *eb)
{
	Ptr pEnv;
	pEnv = Hwi_getHookContext(hwi, myHookSetId2);
	/* pEnv should be 0 at this point. If not, there's a bug. */
	System_printf("myCreate2: pEnv = 0x%x, time = %d\n", pEnv, Timestamp_get32());
	Hwi_setHookContext(hwi, myHookSetId2, (Ptr)0xdead2);
}

/* ======== myBegin2 ========
* invoked before Timer Hwi func */
void myBegin2(Hwi_Handle hwi)
{
	Ptr pEnv;
	pEnv = Hwi_getHookContext(hwi, myHookSetId2);
	System_printf("myBegin2: pEnv = 0x%x, time = %d\n", pEnv, Timestamp_get32());
	Hwi_setHookContext(hwi, myHookSetId2, (Ptr)0xbeef2);
}

/* ======== myEnd2 ========
* invoked after Timer Hwi func */
void myEnd2(Hwi_Handle hwi)
{
	Ptr pEnv;
	pEnv = Hwi_getHookContext(hwi, myHookSetId2);
	System_printf("myEnd2: pEnv = 0x%x, time = %d\n", pEnv, Timestamp_get32());
	Hwi_setHookContext(hwi, myHookSetId2, (Ptr)0xc0de2);
	myEnd2Flag = TRUE;
}

/* ======== myTimerFunc ========
* Timer interrupt handler */
void myTimerFunc(UArg arg)
{
System_printf("Entering myTimerHwi\n");
}

/* ======== myTaskFunc ======== */
void myTaskFunc(UArg arg0, UArg arg1)
{
	System_printf("Entering myTask.\n");
	Timer_start(myTimer);
	/* wait for timer interrupt and myEnd2 to complete */
	while (!myEnd2Flag) {
		;
		}
	System_printf("myTask exiting ...\n");
}

/* ======== myIdleFunc ======== */
void myIdleFunc()
{
	System_printf("Entering myIdleFunc().\n");
	System_exit(0);
}

/* ======== main ======== */
int main(int argc, char* argv[])
{
	System_printf("Starting HwiHookExample...\n");
	BIOS_start();
	return (0);
}


/* pull in Timestamp to print time in hook functions */
xdc.useModule('xdc.runtime.Timestamp');

var xdc_runtime_Error = xdc.useModule('xdc.runtime.Error');
/* Disable Clock so that ours is the only Timer allocated */
var BIOS = xdc.useModule('ti.sysbios.BIOS');
BIOS.clockEnabled = false;
var Idle = xdc.useModule('ti.sysbios.knl.Idle');
Idle.addFunc('&myIdleFunc');
/* Create myTask with default task params */
var Task = xdc.useModule('ti.sysbios.knl.Task');
var taskParams = new Task.Params();
Program.global.myTask = Task.create('&myTaskFunc', taskParams);
/* Create myTimer as source of Hwi */
var Timer = xdc.useModule('ti.sysbios.hal.Timer');
var timerParams = new Timer.Params();
timerParams.startMode = Timer.StartMode_USER;
timerParams.runMode = Timer.RunMode_ONESHOT;
timerParams.period = 1000; // 1ms
Program.global.myTimer = Timer.create(Timer.ANY, "&myTimerFunc", timerParams);
var ti_sysbios_timers_dmtimer_Timer = xdc.useModule('ti.sysbios.timers.dmtimer.Timer');
ti_sysbios_timers_dmtimer_Timer.checkFrequency = false;
/* Define and add two Hwi HookSets
* Notice, no deleteFxn is provided.
*/
var Hwi = xdc.useModule('ti.sysbios.hal.Hwi');
/* Hook Set 1 */
Hwi.addHookSet({
registerFxn: '&myRegister1',
createFxn: '&myCreate1',
beginFxn: '&myBegin1',
endFxn: '&myEnd1',
});
/* Hook Set 2 */
Hwi.addHookSet({
registerFxn: '&myRegister2',
createFxn: '&myCreate2',
beginFxn: '&myBegin2',
endFxn: '&myEnd2',
});
BIOS.libType = BIOS.LibType_Custom;

Hwi,Swi和Task线程选择性得提供了指针在线程生命周期用来插入用户代码。

钩函数只能被静态得声明(在XDCtools的配置代码里面),因此他们可以被使能当构函数没有被提供时,造成运行时间提前。


除了寄存器构函数外,所有的构函数被对象调用,该对象与参数,Hwi Object,Swi object 和Task object。其他参数被提供给一些线程类特殊的构函数。


一个独立的钩函数获得对应的内容指针值通过下面的线程类型特殊api函数,Swi_getHookContext()

和Task_getHookContext()。每个APIs函数拿hook ID作为参数。


The hook context pointers are accessed using Hwi_getHookContext() using the index provided to the
three Register hook functions.
Just prior to invoking your ISR functions, the Begin Hook functions are invoked in the following order:
1. beginHookFunc0();
2. beginHookFunc1();
3. beginHookFunc2();
Likewise, upon return from your ISR functions the End Hook functions are invoked in the following order:
1. endHookFunc0();
2. endHookFunc1();
3. endHookFunc2();


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值