Hi,
I want to add a Task that interval every 100 ms operate 1'st. My code are as follows:
#include <string.h>
#include <ti/sysbios/knl/Task.h>
#include <ti/sysbios/knl/Clock.h>
#include <ti/sysbios/knl/Event.h>
#include <ti/sysbios/knl/Queue.h>
#include "hci_tl.h"
#include "gatt.h"
#include "linkdb.h"
#include "gapgattserver.h"
#include "gattservapp.h"
#include "devinfoservice.h"
#if defined(FEATURE_OAD) || defined(IMAGE_INVALIDATE)
#include "oad_target.h"
#include "oad.h"
#endif //FEATURE_OAD || IMAGE_INVALIDATE
#include "peripheral.h"
#include "gapbondmgr.h"
#include "osal_snv.h"
#include "icall_apimsg.h"
#include "util.h"
#ifdef USE_RCOSC
#include "rcosc_calibration.h"
#endif //USE_RCOSC
#ifdef USE_CORE_SDK
#include <ti/display/Display.h>
#else // !USE_CORE_SDK
#include <ti/mw/display/Display.h>
#endif // USE_CORE_SDK
#include "board_key.h"
#include "board.h"
#include "serial_port_service.h"
#include "spp_ble_server.h"
#include "inc/sdi_task.h"
#include "inc/sdi_tl_uart.h"
#if defined( DEBUG_SW_TRACE )
#include <driverlib/ioc.h>
#endif // USE_FPGA | DEBUG_SW_TRACE
#include "icall_api.h"
#define CTT_ICALL_EVT ICALL_MSG_EVENT_ID // Event_Id_31
#define CTT_QUEUE_EVT UTIL_QUEUE_EVENT_ID // Event_Id_30
#define CTT_PERIODIC_EVT Event_Id_07
#define CTT_ALL_EVENTS (CTT_ICALL_EVT | \
CTT_QUEUE_EVT | \
CTT_PERIODIC_EVT)
#define CTTTASK_STACK_SIZE 800
#define CTTTASK_PRIORITY 2
// How often to perform periodic event (in msec)
#define CTT_PERIODIC_EVT_PERIOD 100
static void CTT_init(void);
static void CTTTask_Fxn(UArg a0, UArg a1);
static void CTTTask_clockHandler(UArg a11);
static ICall_EntityID selfEntity;
static ICall_SyncHandle syncEvent;
static Clock_Struct periodicClock;
Char cttTaskStack[CTTTASK_STACK_SIZE];
Task_Struct cttTaskStruct;
int Don_test1;
long Don_test2;
uint32_t Don_test3;
void CTTTask_createTask(void)
{
Task_Params ctttaskParams;
// Configure and create the SDI task.
Task_Params_init(&ctttaskParams);
ctttaskParams.stack = cttTaskStack;
ctttaskParams.stackSize = CTTTASK_STACK_SIZE;
ctttaskParams.priority = CTTTASK_PRIORITY;
Task_construct(&cttTaskStruct, CTTTask_Fxn, &ctttaskParams, NULL);
}
void CTTTask_Fxn(UArg a0, UArg a1)
{
Don_test1 = 0;
Don_test2 = 1;
CTT_init();
for(;;)
{
uint32_t events;
// Wait for an event to be posted
events = Event_pend(syncEvent, Event_Id_NONE, CTT_ALL_EVENTS,
ICALL_TIMEOUT_FOREVER);
Don_test3 = events;
if(events)
{
// ICall_EntityID dest;
// ICall_ServiceEnum src;
// ICall_HciExtEvt *pMsg = NULL;
Don_test1++;
Don_test2 = Don_test2 + Don_test1;
}
}
}
static void CTT_init(void)
{
ICall_registerApp(&selfEntity, &syncEvent);
Util_constructClock(&periodicClock, CTTTask_clockHandler,
CTT_PERIODIC_EVT_PERIOD, 0, false, CTT_PERIODIC_EVT);
}
static void CTTTask_clockHandler(UArg a11)
{
// Wake up the application.
Event_post(syncEvent, a11);
}
My questions are as follows:
1, My code jest run CTTTask_Fxn(UArg a0, UArg a1) program 1'st, not interval every 100 ms operate 1'st.
2, How to modify my program, let it interval every 100 ms operate 1'st.
Any idea how can I solve the problem? Every help would be really appreciated!
Thanks in advance.
Don
da qin zheng sheng:
可以考虑使用硬件定时器中断。
Susan Yang:
您需要使用Util_startClock
void Util_startClock ( Clock_Struct *pClock )Start a clock.Parameters pClock - pointer to clock struct
Liu Don:
回复 da qin zheng sheng:
使用硬件定時中斷是個不錯的建議,請問有建議的範例程式可以參考的嗎??
在cc2640R2F程式中,硬體中斷似乎是最高優先權,程式運作過程中會影響原先在Task中運作的藍芽程式嗎??
Liu Don:
回复 Susan Yang:
我有增加"Util_startClock(&periodicClock)"指令於我的"CTT_init(void)"副程式中,但似乎沒有效果,程式一樣只執行我的CTTTask_Fxn(UArg a0, UArg a1)副程式一次而以,並沒有辦法每隔100ms執行我的CTTTask_Fxn(UArg a0, UArg a1)副程式。
目前程式如下:
請問我還有哪個地方欠缺考慮的嗎??
#include <string.h>#include <ti/sysbios/knl/Task.h>
#include <ti/sysbios/knl/Clock.h>
#include <ti/sysbios/knl/Event.h>
#include <ti/sysbios/knl/Queue.h>#include "hci_tl.h"
#include "gatt.h"
#include "linkdb.h"
#include "gapgattserver.h"
#include "gattservapp.h"
#include "devinfoservice.h"#if defined(FEATURE_OAD) || defined(IMAGE_INVALIDATE)
#include "oad_target.h"
#include "oad.h"
#endif //FEATURE_OAD || IMAGE_INVALIDATE#include "peripheral.h"
#include "gapbondmgr.h"#include "osal_snv.h"
#include "icall_apimsg.h"#include "util.h"
#ifdef USE_RCOSC
#include "rcosc_calibration.h"
#endif //USE_RCOSC#ifdef USE_CORE_SDK#include <ti/display/Display.h>
#else // !USE_CORE_SDK#include <ti/mw/display/Display.h>
#endif // USE_CORE_SDK
#include "board_key.h"#include "board.h"
#include "serial_port_service.h"
#include "spp_ble_server.h"
#include "inc/sdi_task.h"
#include "inc/sdi_tl_uart.h"#if defined( DEBUG_SW_TRACE )
#include <driverlib/ioc.h>
#endif // USE_FPGA | DEBUG_SW_TRACE#include "icall_api.h"
#define CTT_ICALL_EVTICALL_MSG_EVENT_ID // Event_Id_31
#define CTT_QUEUE_EVTUTIL_QUEUE_EVENT_ID // Event_Id_30
#define CTT_PERIODIC_EVTEvent_Id_07#define CTT_ALL_EVENTS(CTT_ICALL_EVT| \CTT_QUEUE_EVT| \CTT_PERIODIC_EVT)
#define CTTTASK_STACK_SIZE800
#define CTTTASK_PRIORITY2// How often to perform periodic event (in msec)
#define CTT_PERIODIC_EVT_PERIOD100static void CTT_init(void);
static void CTTTask_Fxn(UArg a0, UArg a1);
static void CTTTask_clockHandler(UArg a11);static ICall_EntityID selfEntity;
static ICall_SyncHandle syncEvent;static Clock_Struct periodicClock;
Char cttTaskStack[CTTTASK_STACK_SIZE];
Task_Struct cttTaskStruct;
int Don_test1;
long Don_test2;
uint32_t Don_test3;void CTTTask_createTask(void)
{Task_Params ctttaskParams;
// Configure and create the SDI task.Task_Params_init(&ctttaskParams);ctttaskParams.stack = cttTaskStack;ctttaskParams.stackSize = CTTTASK_STACK_SIZE;ctttaskParams.priority = CTTTASK_PRIORITY;
Task_construct(&cttTaskStruct, CTTTask_Fxn, &ctttaskParams, NULL);
}void CTTTask_Fxn(UArg a0, UArg a1)
{Don_test1 = 0;Don_test2 = 1;
CTT_init();
for(;;){uint32_t events;
// Wait for an event to be postedevents = Event_pend(syncEvent, Event_Id_NONE, CTT_ALL_EVENTS,ICALL_TIMEOUT_FOREVER);
Don_test3 = events;
if(events){
//ICall_EntityID dest;
//ICall_ServiceEnum src;
//ICall_HciExtEvt *pMsg = NULL;
Don_test1++;Don_test2 = Don_test2 + Don_test1;}
}
}static void CTT_init(void)
{ICall_registerApp(&selfEntity, &syncEvent);
Util_startClock(&periodicClock);
Util_constructClock(&periodicClock, CTTTask_clockHandler,CTT_PERIODIC_EVT_PERIOD, 0, false, CTT_PERIODIC_EVT);
}static void CTTTask_clockHandler(UArg a11)
{// Wake up the application.Event_post(syncEvent, a11);
}非常感謝您的回覆~
Don
user5329684:
回复 Liu Don:
Util_startClock只是one-shot clock,需要反复调用startClock,如果需要实现interval operation