官方示例中有一个专门针对Swi的例子,它演示了Swi的几种提交方法,基本针对Swi的几种提交方法写的程序,在读此程序之前请先阅读
这篇日志
。
先上代码:
/* XDC module Headers */
#include <xdc/std.h>
#include <xdc/runtime/System.h>
/* BIOS module Headers */
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Swi.h>
#include <ti/sysbios/knl/Task.h>
#include <ti/sysbios/knl/Clock.h>
#include <ti/sysbios/knl/Semaphore.h>
/* Example/Board Header files */
#include "Board.h"
#define TASKSTACKSIZE 512
Task_Struct task0Struct;
Char task0Stack[TASKSTACKSIZE];
Swi_Struct swi0Struct, swi1Struct;
Swi_Handle swi0Handle, swi1Handle;
Clock_Struct clk0Struct;
Semaphore_Struct sem0Struct;
Semaphore_Handle sem0Handle;
/*
* ======== swi0Fxn =======
*/
Void swi0Fxn(UArg arg0, UArg arg1)
{
System_printf("Enter swi0Fxn, a0 = %d, a1 = %d\n", (Int)arg0, (Int)arg1);
System_printf("swi0 trigger = %d\n", Swi_getTrigger());
System_printf("swi0 pri = %d\n", Swi_getPri(swi0Handle));
System_printf("Exit swi0Fxn\n");
}
/*
* ======== swi1Fxn =======
*/
Void swi1Fxn(UArg arg0, UArg arg1)
{
System_printf("Enter swi1Fxn, a0 = %d, a1 = %d\n", (Int)arg0, (Int)arg1);
System_printf("swi1 trigger = %d\n", Swi_getTrigger());
System_printf("swi1 pri = %d\n", Swi_getPri(swi1Handle));
System_printf("Exit swi1Fxn\n");
}
/*
* ======== clk0Fxn =======
*/
Void clk0Fxn(UArg arg0)
{
Swi_post(swi0Handle);
Swi_post(swi1Handle);
Semaphore_post(sem0Handle);
}
/*
* ======== task0Fxn =======
*/
Void task0Fxn(UArg arg0, UArg arg1)
{
UInt key;
/* wait for swis to be posted from Clock function */
Semaphore_pend(sem0Handle, BIOS_WAIT_FOREVER);
System_printf("Running tsk0Fxn\n");
key = Swi_disable(); /* swis are disabled */
Swi_inc(swi0Handle); /* swi0 trigger = 1 */
Swi_inc(swi0Handle); /* swi0 trigger = 2 */
Swi_restore(key); /* swi0 runs */
Swi_or(swi1Handle, 0x100);