Esempio n. 1
0
eResult framework_CreateMutex(void ** mutexHandle)
{
	tLinuxMutex_t *mutex = (tLinuxMutex_t *)framework_AllocMem(sizeof(tLinuxMutex_t));
	
	mutex->lock = (pthread_mutex_t*)framework_AllocMem(sizeof(pthread_mutex_t));
	mutex->cond = (pthread_cond_t*)framework_AllocMem(sizeof(pthread_cond_t));
	
	pthread_mutex_init(mutex->lock,NULL);
	pthread_cond_init(mutex->cond,NULL);
	
	*mutexHandle = mutex;
	
	return FRAMEWORK_SUCCESS;
}
Esempio n. 2
0
LPCUSBSIO_API int32_t I2C_CancelAllRequest(LPC_HANDLE handle)
{
    LPCUSBSIO_I2C_Ctrl_t *dev = (LPCUSBSIO_I2C_Ctrl_t *) handle;
    uint32_t lMapLenght = 0x00, i;
    LPCUSBSIO_Request_t** lRequest = NULL;
    void* Notifier = NULL;

    framework_LockMutex(dev->RequestMapLock);

    //1rst call => we get map lenght
    map_getAll(dev->request_map, NULL, (int*)&lMapLenght);

    lRequest = framework_AllocMem(lMapLenght * sizeof(LPCUSBSIO_Request_t));
    //2nd call => we get all object in map
    map_getAll(dev->request_map, (void **) lRequest, (int*) &lMapLenght);

    for (i = 0x00; i < lMapLenght; i++)
    {
        //Cancel request
        if (NULL != (*lRequest)[i].notifier)
        {
			(*lRequest)[i].status = LPCUSBSIO_REQ_CANCELED;
			Notifier = (*lRequest)[i].notifier;
			framework_LockMutex(Notifier);
			framework_NotifyMutex(Notifier, 0);
			framework_UnlockMutex(Notifier);
			Notifier = NULL;
        }
    }
    framework_FreeMem(lRequest);
    framework_UnlockMutex(dev->RequestMapLock);
    return 0;    
}
Esempio n. 3
0
eResult framework_CreateThread(void** threadHandle, void * (* threadedFunc)(void *) , void * ctx)
{
	tLinuxThread_t *linuxThread = (tLinuxThread_t *)framework_AllocMem(sizeof(tLinuxThread_t));
	
	linuxThread->ctx = ctx;
	linuxThread->threadedFunc = threadedFunc;
	framework_CreateMutex(&(linuxThread->mutexCanDelete));
	
	if (pthread_create(&(linuxThread->thread), NULL, thread_object_func, linuxThread))
	{
		printf("Cannot create Thread\n");
		framework_DeleteMutex(linuxThread->mutexCanDelete);
		framework_FreeMem(linuxThread);
		
		return FRAMEWORK_FAILED;
	}
	pthread_detach(linuxThread->thread);
	
	*threadHandle = linuxThread;
	
	return FRAMEWORK_SUCCESS;
}
Esempio n. 4
0
LPCUSBSIO_API LPC_HANDLE I2C_Open(uint32_t index)
{
    hid_device *pHid = NULL;
    LPCUSBSIO_I2C_Ctrl_t *dev = NULL;
    struct hid_device_info *cur_dev;

    cur_dev = GetDevAtIndex(index);

    if (cur_dev) 
    {
        pHid = hid_open_path(cur_dev->path);

        if (pHid) 
        {
            dev = framework_AllocMem(sizeof(LPCUSBSIO_I2C_Ctrl_t));
            memset(dev, 0, sizeof(LPCUSBSIO_I2C_Ctrl_t));
            dev->hidDev = pHid;
            dev->hidInfo = cur_dev;
            dev->sesionId = rand();
            map_create(&dev->request_map);
            memcpy(&dev->fwVersion[0], g_fwInitVer, strlen(g_fwInitVer));

            /* insert at top */
            dev->next = g_Ctrl.devList;
            g_Ctrl.devList = dev;
            /* Set all calls to this hid device as blocking. */
            // hid_set_nonblocking(dev->hidDev, 0);
            framework_CreateMutex(&dev->SendLock);
            framework_CreateMutex(&dev->RequestMapLock);
            framework_CreateMutex(&dev->NotifierContainerLock);
            dev->thread_exit = 0x00;
            framework_CreateThread(&dev->ResponsethreadHandle , WaitRequestResponse, dev);

        }
    }
    
    return (LPC_HANDLE) dev;
}