Ejemplo n.º 1
0
void vbv_release(Handle vbv)
{
    vbv_t* v;
    
    v = (vbv_t*)vbv;
    printf("vbv releasae\n");
    if (v)
    {
        if (v->mutex != NULL)
        {
        	semaphore_delete(v->mutex, SEM_DEL_ALWAYS);
            v->mutex = NULL;
        }

        if (v->vbv_buf != NULL)
        {
            mem_pfree(v->vbv_buf);
            v->vbv_buf = NULL;
        }

        if (v->frame_fifo.in_frames)
        {
            mem_free(v->frame_fifo.in_frames);
            v->frame_fifo.in_frames = NULL;
        }

        mem_free(v);
    }

    return;	
}
Ejemplo n.º 2
0
int test4(void)
{
    thread_id tid;
    sem_id sid;
    status_t err;
    int res = 1;

    /* create new semaphore */
    sid = semaphore_create(NULL, 1, 0);
    if(sid == INVALID_SEMID)
        return 0;

    /* create thread */
    tid = sys_create_thread(thread_func, &sid, false, 0);
    if(tid == INVALID_THREADID)
        return 0;

    /* wait for created thread count up semaphore */
    err = semaphore_down_timeout(sid, 1, 1000);
    if(err != NO_ERROR)
        res = 0;

    /* delete semaphore */
    err = semaphore_delete(sid);
    if(err != NO_ERROR)
        res = 0;

    return res;
}
Ejemplo n.º 3
0
void sensor_delay_ms(uint32_t msecs)
{
	if (msecs >= CONVERT_TICKS_TO_MS(1)) {
		T_SEMAPHORE sem = semaphore_create(0);
		semaphore_take(sem, (int)msecs + 1); /* details in FIRE-5618 */
		semaphore_delete(sem);
	} else {
		wait_ticks(msecs * AON_CNT_TICK_PER_MS);
	}
}
Ejemplo n.º 4
0
Archivo: sem.c Proyecto: wolf623/c_code
int main(int argc, char *argv[])
{
	char msg = 'x';
	int i = 0;
	#if 1
	key_t key;
	#if 0
	key = ftok("/home/lm/network/sem/sem.c", 1);
	if(key == -1)
	{
		printf("%s(): ftok failed(%d), %s\n", __FUNCTION__, key, strerror(errno));
		return -1;
	}
	#else
	key = IPC_PRIVATE;
	#endif

	if(semid == 0)
		semid = semget(key, nsem, 0666|IPC_CREAT);
	
	if(semid == -1)
	{
		printf("%s(): semget failed, %s\n", __FUNCTION__, strerror(errno));
		return -1;
	}
	#else
	semaphore_create_and_post();
	#endif
	semaphore_initial();
	semaphore_getsemval();
	semaphore_getpid();
	semaphore_getncnt();
	semaphore_getzcnt();
	//semaphore_setipcstat();
	semaphore_getipcstat();
	
	for(i=0; i<10; i++)
	{
		//if(semaphore_p() != 0)
		//	return -1;
		printf("%c", msg);
		fflush(stdout);
		//sleep(rand()%3);
		printf("%c", msg);
		fflush(stdout);
		//if(semaphore_v() != 0)
		//		return -1;
		//sleep(rand()%2);
	}
	
	semaphore_delete();
	
	return 0;
}
Ejemplo n.º 5
0
void sensor_delay_ms(uint32_t msecs)
{
	if (msecs >= CONVERT_TICKS_TO_MS(1)) {
		T_SEMAPHORE sem = semaphore_create(0);
/* Ensure that we will wait at least 'msecs' millisecond as if semaphore_take is called
 * right before the timer tick interrupt it will be released immediately */
		semaphore_take(sem, (int)msecs + 1);
		semaphore_delete(sem);
	} else {
		wait_ticks(msecs * AON_CNT_TICK_PER_MS);
	}
}
Ejemplo n.º 6
0
Archivo: thread.c Proyecto: aosp/dvp
void thread_main_func_translate(uint32_t argc, void* argv)
{
    thread_t  sosal_thread_hdl = argv;

    /* Run client main func */
    sosal_thread_hdl->exit_code = sosal_thread_hdl->client_func(sosal_thread_hdl->client_arg);

    sosal_thread_hdl->bTaskReady = true_e;
#ifdef JOIN_SEMAPHORE
    {
        semaphore_t         *semaphore_hdl;

        semaphore_hdl = sosal_thread_hdl->join_semaphore;
        SOSAL_PRINT(SOSAL_ZONE_THREAD, "thread_main_func_translate semaphore post (%d)\n", sosal_thread_hdl->join_number);
        while(sosal_thread_hdl->join_number) {
            semaphore_post(semaphore_hdl);  /* signal next join task in the queue to continue */
            sosal_thread_hdl->join_number--;
        }
        SOSAL_PRINT(SOSAL_ZONE_THREAD, "thread_main_func_translate semaphore delete (%d)\n", sosal_thread_hdl->join_number);
        semaphore_delete(semaphore_hdl);
        mutex_deinit(sosal_thread_hdl->join_mutex);
    }
    /* extra task memory releasing */
    free(sosal_thread_hdl->join_semaphore);
    sosal_thread_hdl->join_semaphore = NULL;
    free(sosal_thread_hdl->join_mutex);
#else
    /* Event mode signaling */
    //SOSAL_PRINT(SOSAL_ZONE_THREAD, "thread_main_func_translate send ready event\n");
    event_set(sosal_thread_hdl->exit_event);

    // Wait all task to receive join event
    while (sosal_thread_hdl->pAckList) {
        ack_t     *pAck;
        pAck = sosal_thread_hdl->pAckList;
        //SOSAL_PRINT(SOSAL_ZONE_THREAD, "thread_main_func_translate waits for ack\n");
        event_wait(pAck->exit_event_ack, EVENT_FOREVER);
        SOSAL_PRINT(SOSAL_ZONE_THREAD, "thread_main_func_translate ack received\n");
        sosal_thread_hdl->pAckList = pAck->next;
        sosal_free_ack(pAck);
    }
    event_deinit(sosal_thread_hdl->exit_event);
    //SOSAL_PRINT(SOSAL_ZONE_THREAD, "thread_main_func_translate event deinited\n");

    /* extra task memory releasing */
    free(sosal_thread_hdl->exit_event);
#endif


    free(sosal_thread_hdl);
    sosal_thread_hdl = NULL;
    SOSAL_PRINT(SOSAL_ZONE_THREAD, "thread_main_func_translate clean up\n");
}
Ejemplo n.º 7
0
/**
 * Delete a queue.
 *
 * Free a whole queue.
 * @param queue - The queue to free.
 */
void queue_delete(T_QUEUE queue, OS_ERR_TYPE* err)
{
    OS_ERR_TYPE _err;
    queue_impl_t * q = (queue_impl_t*) queue;
    T_EXEC_LEVEL execLvl = _getExecLevel();
    uint32_t data;
    T_QUEUE_MESSAGE p_msg = &data;

    /* check execution level */
    if ((E_EXEC_LVL_FIBER == execLvl) || (E_EXEC_LVL_TASK == execLvl))
    {
        lock_pool();
        if (queue_used(q) && q->sema != NULL)
        {

            /* first empty the queue before to delete it to free all the elements */
            do{
                queue_get_message(q, &p_msg, OS_NO_WAIT, &_err);
            }while(_err == E_OS_OK);

            if(_err == E_OS_ERR_EMPTY)
            {
                semaphore_delete(q->sema, &_err);
                q->sema = NULL;
                if( _err == E_OS_OK)
                {
                    queue_free(q);
                    error_management (err, E_OS_OK);
                }
                else
                {
                    panic(E_OS_ERR_UNKNOWN);    // Panic because we should never reach this point.
                }
            }
            else
            {
                error_management (err, E_OS_ERR);
            }
        }
        else
        {
            error_management (err, E_OS_ERR);
        }
        unlock_pool();
    }
    else
    {
        error_management (err, E_OS_ERR_NOT_ALLOWED);
    }
    return;
}
Ejemplo n.º 8
0
/*
*************************************************************************
*
*	semaphore_create()
*
*	Description:	This procedure creates a semaphore for the given
*					key_t value.  It returns the semaphore ID.
*
*	Return value:	upon success, positive, non-zero, value for sem_id
*					upon error -1
*	
*************************************************************************
*/
 int semaphore_create( key_t key )
 {
        int sema_id;
        union semun sem_union;
	struct sembuf sem_b;

	sem_b.sem_num = 0;
	sem_b.sem_op = 1;	/* V */
	sem_b.sem_flg = 0;
        sem_union.val = 1;

        /*
        ** Exclusively create the semaphore
        */
        if ((sema_id = semget( (key_t) key, 1, 0666 | IPC_CREAT | IPC_EXCL)) != -1) {
            if (semctl(sema_id, 0, SETVAL, sem_union) != -1) {
                return(sema_id);
            } else {
                perror("Initialize semaphore failed");
                (void) semaphore_delete(sema_id);
                return(-1);
            }
        /*
        ** Someone else created it, so just open it
        **
        ** Note, race condition here between someone creating it and trying to 
        ** init it to 1 and someone opening it and then quickly getting it in 
        ** read/write
        **
        ** Race condition only exists at first create because semaphore stays
        ** created until system is rebooted.
        */
        } else {
            return(semget((key_t) key, 1, 0666 | IPC_CREAT));
        }
 }
Ejemplo n.º 9
0
void fbm_release(Handle h, void* parent)
{
    u32     i;
    fbm_t*  fbm;
    
    fbm = (fbm_t*)h;
    
    if(fbm == NULL)
        return;
        
    if(fbm->mutex)
    {
    	semaphore_delete(fbm->mutex, SEM_DEL_ALWAYS);
        fbm->mutex = NULL;
    }
        
    for(i=0; i<fbm->max_frame_num; i++)
    {
    	if(fbm->is_preview_mode)
    	{
    		if(i == 0)
    		{
    			fbm_free_frame_buffer(&fbm->frames[i].picture);
    			break;
    		}
    	}
    	else
    	{
    		fbm_free_frame_buffer(&fbm->frames[i].picture);
    	}
    }
    
    mem_free(fbm);
    
    return;
}
/**
 * Deletes a monitor object and frees associated memory.
 */
void monitor_delete(monitor_t *monitor) {
  semaphore_delete(monitor->sem_id);
  free(monitor);
}
Ejemplo n.º 11
0
struct sensor_sba_info *sensor_config_bus(int slave_addr, uint8_t dev_id,
					  SBA_BUSID bus_id,
					  SENSOR_BUS_TYPE bus_type, int req_num,
					  BLOCK_TYPE block_type)
{
	struct sensor_sba_req *reqs = NULL;
	struct sensor_sba_info *info = NULL;
	int i;

	reqs = (struct sensor_sba_req *)balloc(
		sizeof(struct sensor_sba_req) * req_num, NULL);
	if (!reqs)
		return NULL;

	info = (struct sensor_sba_info *)balloc(sizeof(struct sensor_sba_info),
						NULL);
	if (!info)
		goto FAIL;

	info->reqs = reqs;
	info->bitmap = 0;
	info->req_cnt = req_num;
	info->dev_id = dev_id;
	info->bus_type = bus_type;
	info->block_type = block_type;

	for (i = 0; i < req_num; i++) {
		reqs[i].req.bus_id = bus_id;
		reqs[i].req.status = 1;

		if (block_type == SPIN) {
			reqs[i].req.callback = sensor_bus_callback_spin;
			reqs[i].complete_flag = 0;
		} else {
			reqs[i].req.callback = sensor_bus_callback_sleep;
			reqs[i].sem = semaphore_create(0);
			if (!reqs[i].sem)
				goto FAIL;
		}

		reqs[i].req.full_duplex = 0;

		reqs[i].req.addr.slave_addr = slave_addr;
	}

	pr_debug(LOG_MODULE_DRV, "%s: Serial BUS[%d] initialized", __func__,
		 bus_id);

	return info;

FAIL:
	for (i = 0; i < req_num; i++) {
		if (reqs[i].sem) {
			semaphore_delete(reqs[i].sem);
			reqs[i].sem = NULL;
		}
	}
	if (reqs)
		bfree(reqs);

	if (info)
		bfree(info);

	pr_debug(LOG_MODULE_DRV, "%s: Serial BUS[%d] init failed", __func__,
		 bus_id);
	return NULL;
}
Ejemplo n.º 12
0
/*******************************************************************************
Name        : Term
Description : API specific terminations
Parameters  : pointer on device and termination parameters
Assumptions : pointer on device is not NULL
Limitations :
Returns     : ST_ErrorCode_t for the API Term function
*******************************************************************************/
static ST_ErrorCode_t Term(stcc_Device_t * const Device_p,
                    const STCC_TermParams_t * const TermParams_p)
{
    ST_ErrorCode_t RetCode, ErrorCode = ST_NO_ERROR;
    task_t *TaskPointer_p;

    if (Device_p->DeviceData_p == NULL)
    {
        CC_Defense(ST_ERROR_BAD_PARAMETER);
        return(ST_ERROR_BAD_PARAMETER);
    }

    /* Is the process stopped */
    if((Device_p->DeviceData_p->CCDecodeStarted)
            && (!TermParams_p->ForceTerminate))
    {
        CC_Defense(STCC_ERROR_DECODER_RUNNING);
        return(STCC_ERROR_DECODER_RUNNING);
    }

    if(Device_p->DeviceData_p->CCDecodeStarted)
    {
        RetCode = STVBI_Disable(Device_p->DeviceData_p->VBIHandle);
        if(RetCode != ST_NO_ERROR)
            ErrorCode = STCC_ERROR_VBI_ACCESS;
        Device_p->DeviceData_p->CCDecodeStarted = FALSE;
    }

    /* Delete CC Task */
    if(Device_p->DeviceData_p->Task.IsRunning)
    {
        Device_p->DeviceData_p->Task.ToBeDeleted = TRUE;

        semaphore_signal((Device_p->DeviceData_p->Task.SemProcessCC_p));
        TaskPointer_p = (Device_p->DeviceData_p->Task.Task_p);


        STOS_TaskWait( &TaskPointer_p, TIMEOUT_INFINITY );
        ErrorCode = STOS_TaskDelete ( TaskPointer_p,
                                      Device_p->DeviceData_p->InitParams.CPUPartition_p,
                                      NULL,
                                      Device_p->DeviceData_p->InitParams.CPUPartition_p);

        if (ErrorCode != ST_NO_ERROR)
        {
            ErrorCode = STCC_ERROR_TASK_CALL;
        }
        Device_p->DeviceData_p->Task.IsRunning = FALSE;
        semaphore_delete((Device_p->DeviceData_p->Task.SemProcessCC_p));
        semaphore_wait((Device_p->DeviceData_p->SemAccess_p));
        semaphore_delete((Device_p->DeviceData_p->SemAccess_p));
    }

    RetCode = STEVT_UnsubscribeDeviceEvent(Device_p->DeviceData_p->EVTHandle,
                                   Device_p->DeviceData_p->InitParams.VTGName,
                                   STVTG_VSYNC_EVT);
    if(RetCode != ST_NO_ERROR)
    {
        ErrorCode = STCC_ERROR_EVT_SUBSCRIBE;
    }
    if(RetCode != ST_NO_ERROR)
    {
        ErrorCode = STCC_ERROR_EVT_SUBSCRIBE;
    }

    RetCode = STEVT_UnsubscribeDeviceEvent(Device_p->DeviceData_p->EVTHandle,
                                   Device_p->DeviceData_p->InitParams.VIDName,
                                   STVID_USER_DATA_EVT);
    if(RetCode != ST_NO_ERROR)
    {
        ErrorCode = STCC_ERROR_EVT_SUBSCRIBE;
    }
    RetCode = STEVT_UnregisterDeviceEvent(Device_p->DeviceData_p->EVTHandle,
                                    Device_p->DeviceName,
                                    STCC_DATA_TO_BE_PRESENTED_EVT);
    if(RetCode != ST_NO_ERROR)
    {
        ErrorCode = STCC_ERROR_EVT_REGISTER;
    }
    RetCode = STVBI_Close(Device_p->DeviceData_p->VBIHandle);
    if(RetCode != ST_NO_ERROR)
    {
        ErrorCode = STCC_ERROR_VBI_ACCESS;
    }

    RetCode = STEVT_Close(Device_p->DeviceData_p->EVTHandle);
    if(RetCode != ST_NO_ERROR)
    {
        ErrorCode = STCC_ERROR_EVT_SUBSCRIBE;
    }

    /* We have succeded to terminate: de-allocate dynamic data structure */
    memory_deallocate(Device_p->DeviceData_p->InitParams.CPUPartition_p,
                    (void *) Device_p->DeviceData_p);
    Device_p->DeviceData_p = NULL;
    if(RetCode != ST_NO_ERROR)
    {
        CC_Defense(ErrorCode);
    }

    return(ErrorCode);
}
Ejemplo n.º 13
0
/*******************************************************************************
Name        : Init
Description : API specific initialisations
Parameters  : pointer on device and initialisation parameters
Assumptions : pointer on device is not NULL
Limitations :
Returns     : ST_ErrorCode_t for the API Init function
*******************************************************************************/
static ST_ErrorCode_t Init(stcc_Device_t * const Device_p,
                    const STCC_InitParams_t * const InitParams_p)
{
    ST_ErrorCode_t ErrCode = ST_NO_ERROR;
    STEVT_OpenParams_t EVTOpenParams;
    STVBI_OpenParams_t VBIOpenParams;
    STEVT_DeviceSubscribeParams_t SubscribeParams;
    U8 ErrorRecovery = STCC_RECOVERY_ERROR_NONE;
    U32 i,j;

    /* Test initialisation parameters and exit if some are invalid. */
    if (InitParams_p->CPUPartition_p == NULL)
    {
        CC_Defense(ST_ERROR_BAD_PARAMETER);
        return(ST_ERROR_BAD_PARAMETER);
    }

    /* Allocate dynamic data structure */
    Device_p->DeviceData_p = (stcc_DeviceData_t *)
       memory_allocate(InitParams_p->CPUPartition_p, sizeof(stcc_DeviceData_t));
    if (Device_p->DeviceData_p == NULL)
    {
        /* Error of allocation */
        CC_Defense(ST_ERROR_NO_MEMORY);
        return(ST_ERROR_NO_MEMORY);
    }

    memset(Device_p->DeviceData_p, 0x00 , sizeof(stcc_DeviceData_t));

    /* Initialise the allocated structure: most of variables are set-up by */
    /* init (handles, init parameters, etc), so just initialise the rest. */
    /* Default inits */
    Device_p->DeviceData_p->InitParams.CPUPartition_p =
                                                InitParams_p->CPUPartition_p;
    Device_p->DeviceData_p->Task.IsRunning                      = FALSE;
    Device_p->DeviceData_p->Task.ToBeDeleted                    = FALSE;
    Device_p->DeviceData_p->CCDecodeStarted                     = FALSE;
    Device_p->DeviceData_p->FirstSlot                           = BAD_SLOT;
    Device_p->DeviceData_p->NbUsedSlot                          = 0;
    Device_p->DeviceData_p->LastPacket708                       = FALSE;

    for(i =0; i<NB_SLOT; i++)
    {
        for(j =0; j<NB_CCDATA; j++)
        {
            Device_p->DeviceData_p->CaptionSlot[i].CC_Data[j].Field = 0x0;
            Device_p->DeviceData_p->CaptionSlot[i].CC_Data[j].Byte1 = 0x0;
            Device_p->DeviceData_p->CaptionSlot[i].CC_Data[j].Byte2 = 0x0;
        }
        Device_p->DeviceData_p->CaptionSlot[i].DataLength           = 0;
        Device_p->DeviceData_p->CaptionSlot[i].PTS.PTS              = 0xfffffff;
        Device_p->DeviceData_p->CaptionSlot[i].SlotAvailable        = 1;
        Device_p->DeviceData_p->CaptionSlot[i].Next                 = BAD_SLOT;
        Device_p->DeviceData_p->CaptionSlot[i].Previous             = BAD_SLOT;
    }

    for(i=0; i<NB_COPIES; i++)
    {
        Device_p->DeviceData_p->Copies[i].Used      = STCC_EMPTY;
        Device_p->DeviceData_p->Copies[i].Length    = 0;
    }

    /* Check bad parameter */
    if ((InitParams_p->MaxOpen > STCC_MAX_OPEN) ||
        (InitParams_p->EvtHandlerName[0] == '\0') ||
        (InitParams_p->VBIName[0] == '\0') ||
        (InitParams_p->VIDName[0] == '\0') ||
        (InitParams_p->VTGName[0] == '\0') ||
        (strlen(InitParams_p->EvtHandlerName) > sizeof(ST_DeviceName_t)) ||
        (strlen(InitParams_p->VBIName) > sizeof(ST_DeviceName_t)) ||
        (strlen(InitParams_p->VTGName) > sizeof(ST_DeviceName_t)) ||
        (strlen(InitParams_p->VIDName) > sizeof(ST_DeviceName_t))
        )
    {
        ErrCode = ST_ERROR_BAD_PARAMETER;
    }

    if (ErrCode == ST_NO_ERROR)
    {
        /* Save Max open & strings */
        Device_p->DeviceData_p->InitParams.MaxOpen = InitParams_p->MaxOpen;
        strcpy(Device_p->DeviceData_p->InitParams.EvtHandlerName,
                            InitParams_p->EvtHandlerName);
        strcpy(Device_p->DeviceData_p->InitParams.VBIName,
                            InitParams_p->VBIName);
        strcpy(Device_p->DeviceData_p->InitParams.VIDName,
                            InitParams_p->VIDName);
        strcpy(Device_p->DeviceData_p->InitParams.VTGName,
                            InitParams_p->VTGName);
    }

    if (ErrCode == ST_NO_ERROR)
    {
        /* Save ouput mode */
        Device_p->DeviceData_p->OutputMode = STCC_OUTPUT_MODE_NONE;
        Device_p->DeviceData_p->FormatMode = STCC_FORMAT_MODE_DETECT;
        ErrCode = STEVT_Open(InitParams_p->EvtHandlerName, &EVTOpenParams,
                             &Device_p->DeviceData_p->EVTHandle);
        if(ErrCode != ST_NO_ERROR)
        {
            ErrCode = ST_ERROR_BAD_PARAMETER;
            ErrorRecovery = STCC_RECOVERY_ERROR_HANDLER;
        }
        if(ErrCode == ST_NO_ERROR)
        {
            /* Open params for VBI */
            VBIOpenParams.Configuration.VbiType = STVBI_VBI_TYPE_CLOSEDCAPTION;
            VBIOpenParams.Configuration.Type.CC.Mode = STVBI_CCMODE_BOTH;
            ErrCode = STVBI_Open(Device_p->DeviceData_p->InitParams.VBIName,
                             &VBIOpenParams,&Device_p->DeviceData_p->VBIHandle);
            if(ErrCode != ST_NO_ERROR)
            {
                ErrCode = STCC_ERROR_VBI_UNKNOWN;
                ErrorRecovery = STCC_RECOVERY_ERROR_VBI_ACCESS;
            }
        }
        if(ErrCode == ST_NO_ERROR)
        {
            /* Subscribe to UserDataEvent */
            SubscribeParams.NotifyCallback = (STEVT_DeviceCallbackProc_t)stcc_UserDataCallBack;
            SubscribeParams.SubscriberData_p = Device_p;

            ErrCode = STEVT_SubscribeDeviceEvent(
                            Device_p->DeviceData_p->EVTHandle,
                            Device_p->DeviceData_p->InitParams.VIDName,
                            STVID_USER_DATA_EVT, &SubscribeParams);
            if(ErrCode != ST_NO_ERROR)
            {
                ErrCode = STCC_ERROR_EVT_SUBSCRIBE;
                ErrorRecovery = STCC_RECOVERY_ERROR_VIDEO_USER_SUB;
            }
        }
        if(ErrCode == ST_NO_ERROR)
        {
            /* Subscribe to VSyncEvent */
            SubscribeParams.NotifyCallback = (STEVT_DeviceCallbackProc_t)stcc_VSyncCallBack;
            ErrCode = STEVT_SubscribeDeviceEvent(
                            Device_p->DeviceData_p->EVTHandle,
                            Device_p->DeviceData_p->InitParams.VTGName,
                            STVTG_VSYNC_EVT, &SubscribeParams);
            if(ErrCode != ST_NO_ERROR)
            {
                ErrCode = STCC_ERROR_EVT_SUBSCRIBE;
                ErrorRecovery = STCC_RECOVERY_ERROR_VTG_SUB;
            }
        }
        if(ErrCode == ST_NO_ERROR)
        {
             ErrCode = STEVT_RegisterDeviceEvent(
                            Device_p->DeviceData_p->EVTHandle,
                            Device_p->DeviceName,
                            STCC_DATA_TO_BE_PRESENTED_EVT,
                            &Device_p->DeviceData_p->Notify_id);
            /* Event register */
            if(ErrCode != ST_NO_ERROR)
            {
                ErrCode = STCC_ERROR_EVT_REGISTER;
                ErrorRecovery = STCC_RECOVERY_ERROR_EVT_REGISTER;
            }

        }
        if(ErrCode == ST_NO_ERROR)
        {

            /* task creation */
            Device_p->DeviceData_p->Task.SemProcessCC_p = semaphore_create_fifo_timeout(0);
            Device_p->DeviceData_p->SemAccess_p = semaphore_create_fifo(1);


    /* CREATE TASK */
            ErrCode = STOS_TaskCreate ((void (*) (void*))stcc_ProcessCaption,
                                       (void *)Device_p,
                                        Device_p->DeviceData_p->InitParams.CPUPartition_p,
                                        STCC_TASK_STACK_SIZE,
                                        NULL,
                                        Device_p->DeviceData_p->InitParams.CPUPartition_p,
                                        &(Device_p->DeviceData_p->Task.Task_p),
                                        NULL,
                                        STCC_TASK_PRIORITY,
                                        "Closed_Caption_ProcessTask",
                                        task_flags_no_min_stack_size);

            if(ErrCode != ST_NO_ERROR)
            {
                return(ST_ERROR_BAD_PARAMETER);
            }
            else
            {
                /* Task created */
                Device_p->DeviceData_p->Task.IsRunning = TRUE;
            }
        }

        switch(ErrorRecovery)
        {
            /* Break are omited volontary to undo what we already done */
            /* No check to undo what succeeded */
            case STCC_RECOVERY_ERROR_TASK_CREATE:
          semaphore_delete((Device_p->DeviceData_p->Task.SemProcessCC_p));
          semaphore_delete((Device_p->DeviceData_p->SemAccess_p));

                STEVT_UnregisterDeviceEvent(
                                Device_p->DeviceData_p->EVTHandle,
                                Device_p->DeviceName,
                                STCC_DATA_TO_BE_PRESENTED_EVT);
            case STCC_RECOVERY_ERROR_EVT_REGISTER:
                STEVT_UnsubscribeDeviceEvent(
                                Device_p->DeviceData_p->EVTHandle,
                                Device_p->DeviceData_p->InitParams.VTGName,
                                STVTG_VSYNC_EVT);
            case STCC_RECOVERY_ERROR_VTG_SUB:
            case STCC_RECOVERY_ERROR_VIDEO_FRAME_SUB:
                STEVT_UnsubscribeDeviceEvent(
                                Device_p->DeviceData_p->EVTHandle,
                                Device_p->DeviceData_p->InitParams.VIDName,
                                STVID_USER_DATA_EVT);
            case STCC_RECOVERY_ERROR_VIDEO_USER_SUB:
                STVBI_Close(Device_p->DeviceData_p->VBIHandle);
            case STCC_RECOVERY_ERROR_VBI_ACCESS:
                STEVT_Close(Device_p->DeviceData_p->EVTHandle);
            case STCC_RECOVERY_ERROR_HANDLER: /* Nothing to undo */
            case STCC_RECOVERY_ERROR_NONE:
            default:
                break;
        }
    }
    if (ErrCode != ST_NO_ERROR)
    {
        CC_Defense(ErrCode);
        /* De-allocate dynamic data structure */
        memory_deallocate(InitParams_p->CPUPartition_p, (void *)
                Device_p->DeviceData_p);
        Device_p->DeviceData_p = NULL;

    }

    STCC_DebugStats.NbUserDataReceived         = 0;
    STCC_DebugStats.NbUserDataParsed           = 0;
    STCC_DebugStats.NBCaptionDataFound         = 0;
    STCC_DebugStats.NBCaptionDataPresented     = 0;

    return(ErrCode);
}
Ejemplo n.º 14
0
static void DeleteSemaphore(ULONG ulHandle)
{
  semaphore_delete((semaphore_t*)ulHandle);
}