Part Number: TMS320C6678
Other Parts Discussed in Thread: SYSBIOS
Tool/software: Code Composer Studio
In my project , I use a void* pointer to replace the Semaphore_Handle . When I call this pointer in the Semaphore_pend function ,the function be executed correctly but the count of semaphore is not reduced . For a comparison , I define a Semaphore_Handle and call the Semaphore_pend function directly . In this case, the count of semaphore is reduced from 1 to 0. My doubt is that in the first case, the number of semaphore has not changed, but the Semaphore_pend function can be executed correctly.
The following is my main.c which includes the key codes.
/*
* ======== main.c ========
*/
#include <xdc/std.h>
#include <xdc/runtime/Error.h>
#include <xdc/runtime/System.h>
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>
#include <ti/sysbios/knl/Semaphore.h>
Semaphore_Handle timerSemaphore;
Semaphore_Handle MutexSemaphore;
typedef void* HANDLE;
typedef HANDLE osiLockObj_t;
typedef unsigned int osiTime_t;
typedef void* rlOsiMutexHdl_t;
typedef unsigned int rlUInt32_t;
typedef rlUInt32_t rlOsiTime_t;
#define RL_OSI_WAIT_FOREVER (0xFFFFU)
typedef struct rlDriverData
{
rlOsiMutexHdl_t globalMutex;
}rlDriverData_t;
static rlDriverData_t rl_driverData = {0};
__declspec(dllexport) int osiLockObjCreate(osiLockObj_t* pLockObj, char* pName)
{
Semaphore_Params semaParams;
Semaphore_Params_init(&semaParams);
semaParams.mode = Semaphore_Mode_BINARY;//Semaphore_Mode_COUNTING
MutexSemaphore = Semaphore_create(1, &semaParams, NULL);
memcpy(*pLockObj , MutexSemaphore , sizeof(MutexSemaphore));
return 0;
}
__declspec(dllexport) int osiLockObjLock(osiLockObj_t* pLockObj , osiTime_t Timeout)
{
Semaphore_Handle Semaphore;
Semaphore = (Semaphore_Handle)rl_driverData.globalMutex;
Semaphore_pend(Semaphore,Timeout);
Semaphore_pend(timerSemaphore,Timeout);
return 0;
}
/*
* ======== taskFxn ========
*/
Void taskFxn(UArg a0, UArg a1)
{
osiLockObjLock(&rl_driverData.globalMutex, (rlOsiTime_t)RL_OSI_WAIT_FOREVER);
System_printf("enter taskFxn()\n");
Task_sleep(10);
System_printf("exit taskFxn()\n");
System_flush(); /* force SysMin output to console */
}
/*
* ======== main ========
*/
Int main()
{
Task_Handle task;
Error_Block eb;
Semaphore_Params semaParams;
System_printf("enter main()\n");
osiLockObjCreate(&rl_driverData.globalMutex, "GlobalLockObj");
memcpy(rl_driverData.globalMutex , MutexSemaphore , sizeof(MutexSemaphore));
Semaphore_Params_init(&semaParams);
semaParams.mode = Semaphore_Mode_BINARY;//Semaphore_Mode_COUNTING
timerSemaphore = Semaphore_create(1, &semaParams, NULL);
Error_init(&eb);
task = Task_create(taskFxn, NULL, &eb);
if (task == NULL) {
System_printf("Task_create() failed!\n");
BIOS_exit(0);
}
BIOS_start(); /* does not return */
return(0);
}