⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 osapi.c

📁 osal for Vxworks,c code
💻 C
📖 第 1 页 / 共 4 页
字号:
               Returns: OS_ERR_INVALID_ID if there the specified ID could not be found            OS_ERROR if the OS call fails            OS_SUCCESS if success---------------------------------------------------------------------------------------*/int32 OS_TaskRegister (void){    int     vxworks_task_id;    int     i;    uint32  task_id;    /* Find Defined Task Id */    vxworks_task_id = taskIdSelf();    for(i = 0; i < OS_MAX_TASKS; i++)    {        if(OS_task_table[i].id == vxworks_task_id)            break;    }    task_id = i;    if(task_id >= OS_MAX_TASKS)    {        return OS_ERR_INVALID_ID;    }    /* Add VxWorks Task Variable */    if(taskVarAdd(OS_task_table[task_id].id, (int*)&OS_task_key) != OK)        return OS_ERROR;    OS_task_key = task_id;    return OS_SUCCESS;}/* end OS_TaskRegister *//*---------------------------------------------------------------------------------------   Name: OS_TaskGetId   Purpose: This function returns the #defined task id of the calling task   Notes: The OS_task_key is initialized by the task switch if AND ONLY IF the           OS_task_key has been registered via OS_TaskRegister(..).  If this is not           called prior to this call, the value will be old and wrong.---------------------------------------------------------------------------------------*/uint32 OS_TaskGetId (void){    return OS_task_key;}/* end OS_TaskGetId *//*--------------------------------------------------------------------------------------    Name: OS_TaskGetIdByName    Purpose: This function tries to find a task Id given the name of a task    Returns: OS_INVALID_POINTER if the pointers passed in are NULL             OS_ERR_NAME_TOO_LONG if th ename to found is too long to begin with             OS_ERR_NAME_NOT_FOUND if the name wasn't found in the table             OS_SUCCESS if SUCCESS---------------------------------------------------------------------------------------*/int32 OS_TaskGetIdByName (uint32 *task_id, const char *task_name){    uint32 i;    if (task_id == NULL || task_name == NULL)        return OS_INVALID_POINTER;        /* we don't want to allow names too long because they won't be found at all */        if (strlen(task_name) > OS_MAX_API_NAME)            return OS_ERR_NAME_TOO_LONG;    for (i = 0; i < OS_MAX_TASKS; i++)    {        if((OS_task_table[i].free != TRUE) &&          (strcmp(OS_task_table[i].name,(char *)task_name) == 0 ))        {            *task_id = i;            return OS_SUCCESS;        }    }    /* The name was not found in the table,     *  or it was, and the task_id isn't valid anymore */    return OS_ERR_NAME_NOT_FOUND;}/* end OS_TaskGetIdByName */     /*---------------------------------------------------------------------------------------    Name: OS_TaskGetInfo    Purpose: This function will pass back a pointer to structure that contains              all of the relevant info (creator, stack size, priority, name) about the              specified task.     Returns: OS_ERR_INVALID_ID if the ID passed to it is invalid             OS_INVALID_POINTER if the task_prop pointer is NULL             OS_SUCCESS if it copied all of the relevant info over ---------------------------------------------------------------------------------------*/int32 OS_TaskGetInfo (uint32 task_id, OS_task_prop_t *task_prop)  {    /* Check to see that the id given is valid */        if (task_id >= OS_MAX_TASKS || OS_task_table[task_id].free == TRUE)        return OS_ERR_INVALID_ID;    if( task_prop == NULL)        return OS_INVALID_POINTER;    /* put the info into the stucture */    semTake(OS_task_table_sem,WAIT_FOREVER);    task_prop -> creator =    OS_task_table[task_id].creator;    task_prop -> stack_size = OS_task_table[task_id].stack_size;    task_prop -> priority =   OS_task_table[task_id].priority;        strcpy(task_prop-> name, OS_task_table[task_id].name);    semGive(OS_task_table_sem);        return OS_SUCCESS;    } /* end OS_TaskGetInfo *//****************************************************************************************                                MESSAGE QUEUE API****************************************************************************************//*---------------------------------------------------------------------------------------   Name: OS_QueueCreate   Purpose: Create a message queue which can be refered to by name or ID   Returns: OS_INVALID_POINTER if a pointer passed in is NULL            OS_ERR_NAME_TOO_LONG if the name passed in is too long            OS_ERR_NO_FREE_IDS if there are already the max queues created            OS_ERR_NAME_TAKEN if the name is already being used on another queue            OS_ERROR if the OS create call fails            OS_SUCCESS if success   Notes: the flahs parameter is unused.---------------------------------------------------------------------------------------*/int32 OS_QueueCreate (uint32 *queue_id, const char *queue_name, uint32 queue_depth,                        uint32 data_size, uint32 flags){    uint32 possible_qid;    uint32 i;         if ( queue_id == NULL || queue_name == NULL)        return OS_INVALID_POINTER;    /* we don't want to allow names too long*/    /* if truncated, two names might be the same */    if (strlen(queue_name) > OS_MAX_API_NAME)            return OS_ERR_NAME_TOO_LONG;   /* Check Parameters */    semTake(OS_queue_table_sem,WAIT_FOREVER);    for(possible_qid = 0; possible_qid < OS_MAX_QUEUES; possible_qid++)    {        if (OS_queue_table[possible_qid].free == TRUE)            break;    }         semGive(OS_queue_table_sem);    if( possible_qid >= OS_MAX_QUEUES || OS_queue_table[possible_qid].free != TRUE)        return OS_ERR_NO_FREE_IDS;    /* Check to see if the name is already taken */    semTake(OS_queue_table_sem,WAIT_FOREVER);    for (i = 0; i < OS_MAX_QUEUES; i++)    {        if (strcmp ((char*)queue_name, OS_queue_table[i].name) == 0)        {            semGive(OS_queue_table_sem);            return OS_ERR_NAME_TAKEN;        }    }    semGive(OS_queue_table_sem);    /* Create VxWorks Message Queue */    OS_queue_table[possible_qid].id = msgQCreate(queue_depth, data_size, MSG_Q_FIFO);    /* check if message Q create failed */    if(OS_queue_table[possible_qid].id == NULL)        return OS_ERROR;        /* Set the queue_id to the id that was found available*/    /* Set the name of the queue, and the creator as well */        *queue_id = possible_qid;        semTake(OS_queue_table_sem,WAIT_FOREVER);   OS_queue_table[*queue_id].free = FALSE;   strcpy( OS_queue_table[*queue_id].name, (char*) queue_name);   OS_queue_table[*queue_id].creator = OS_FindCreator();   semGive(OS_queue_table_sem);    return OS_SUCCESS;} /* end OS_QueueCreate *//*--------------------------------------------------------------------------------------    Name: OS_QueueDelete    Purpose: Deletes the specified message queue.    Returns: OS_ERR_INVALID_ID if the id passed in does not exist             OS_ERROR if the OS call to delete the queue fails              OS_SUCCESS if success    Notes: If There are messages on the queue, they will be lost and any subsequent           calls to QueueGet or QueuePut to this queue will result in errors---------------------------------------------------------------------------------------*/int32 OS_QueueDelete (uint32 queue_id){    /* Check to see if the queue_id given is valid */        if (queue_id >= OS_MAX_QUEUES || OS_queue_table[queue_id].free == TRUE)            return OS_ERR_INVALID_ID;    /* Try to delete the queue */    if (msgQDelete(OS_queue_table[queue_id].id) != OK)            return OS_ERROR;        /*      * Now that the queue is deleted, remove its "presence"     * in OS_message_q_table and OS_message_q_name_table     */            semTake(OS_queue_table_sem,WAIT_FOREVER);    OS_queue_table[queue_id].free = TRUE;    strcpy(OS_queue_table[queue_id].name, "");    OS_queue_table[queue_id].creator = UNINITIALIZED;    OS_queue_table[queue_id].id = NULL;    semGive(OS_queue_table_sem);       return OS_SUCCESS;} /* end OS_QueueDelete *//*---------------------------------------------------------------------------------------   Name: OS_QueueGet   Purpose: Receive a message on a message queue.  Will pend or timeout on the receive.   Returns: OS_ERR_INVALID_ID if the given ID does not exist            OS_ERR_INVALID_POINTER if a pointer passed in is NULL            OS_QUEUE_EMPTY if the Queue has no messages on it to be recieved            OS_QUEUE_TIMEOUT if the timeout was OS_PEND and the time expired            OS_QUEUE_INVALID_SIZE if the size copied from the queue was not correct            OS_SUCCESS if success---------------------------------------------------------------------------------------*/int32 OS_QueueGet (uint32 queue_id, void *data, uint32 size, uint32 *size_copied,                     int32 timeout){    /* msecs rounded to the closest system tick count */    int status = -1;    uint32 sys_ticks;        /* Check Parameters */    if(queue_id >= OS_MAX_QUEUES || OS_queue_table[queue_id].free == TRUE)    {        return OS_ERR_INVALID_ID;    }    else    {        if( (data == NULL) || (size_copied == NULL) )            return OS_INVALID_POINTER;    }        /* Get Message From VxWorks Message Queue */    if(timeout == OS_PEND)    {        status = msgQReceive(OS_queue_table[queue_id].id, data, size, WAIT_FOREVER);    }    else    {        if (timeout == OS_CHECK)        {            status = msgQReceive(OS_queue_table[queue_id].id, data, size, NO_WAIT);                    if( (status == ERROR) && (errno == S_objLib_OBJ_UNAVAILABLE) )                return OS_QUEUE_EMPTY;        }        else        {            sys_ticks = OS_Milli2Ticks(timeout);            status = msgQReceive(OS_queue_table[queue_id].id, data, size, sys_ticks);            if( (status == ERROR) && (errno == S_objLib_OBJ_TIMEOUT) )                return OS_QUEUE_TIMEOUT;        }    }        if(status == ERROR)    {        *size_copied = 0;        return OS_ERROR;    }    else    {        if((uint32)status != size)        {            return OS_QUEUE_INVALID_SIZE;        }        else        {            *size_copied = (uint32)status;            return OS_SUCCESS;        }    }}/* end OS_QueueGet *//*---------------------------------------------------------------------------------------   Name: OS_QueuePut   Purpose: Put a message on a message queue.   Returns: OS_ERR_INVALID_ID if the queue id passed in is not a valid queue            OS_INVALID_POINTER if the data pointer is NULL            OS_QUEUE_FULL if the queue cannot accept another message            OS_ERROR if the OS call returns an error            OS_SUCCESS if SUCCESS                  Notes: The flags parameter is not used.  The message put is always configured to            immediately return an error if the receiving message queue is full.---------------------------------------------------------------------------------------*/int32 OS_QueuePut (uint32 queue_id, void *data, uint32 size, uint32 flags){    /* Check Parameters */    if(queue_id >= OS_MAX_QUEUES || OS_queue_table[queue_id].free == TRUE)        return OS_ERR_INVALID_ID;    if (data == NULL)        return OS_INVALID_POINTER;        /* Get Message From VxWorks Message Queue */    if(msgQSend(OS_queue_table[queue_id].id, data, size, NO_WAIT, MSG_PRI_NORMAL) != OK)    {        if(errno == S_objLib_OBJ_UNAVAILABLE)            return OS_QUEUE_FULL;        else            return OS_ERROR;    }        return OS_SUCCESS;}/* end OS_QueuePut *//*--------------------------------------------------------------------------------------    Name: OS_QueueGetIdByName    Purpose: This function tries to find a queue Id given the name of the queue. The             id of the queue is passed back in queue_id    Returns: OS_INVALID_POINTER if the name or id pointers are NULL             OS_ERR_NAME_TOO_LONG the name passed in is too long             OS_ERR_NAME_NOT_FOUND the name was not found in the table             OS_SUCCESS if success             ---------------------------------------------------------------------------------------*/int32 OS_QueueGetIdByName (uint32 *queue_id, const char *queue_name){    uint32 i;    if(queue_id == NULL || queue_name == NULL)        return OS_INVALID_POINTER;        /* a name too long wouldn't have been allowed in the first place     * so we definitely won't find a name too long*/     if (strlen(queue_name) > OS_MAX_API_NAME)            return OS_ERR_NAME_TOO_LONG;    for (i = 0; i < OS_MAX_QUEUES; i++)    {        if ( OS_queue_table[i].free != TRUE &&                (strcmp(OS_queue_table[i].name, (char*) queue_name) == 0 ))        {            *queue_id = i;            return OS_SUCCESS;        }    }    /* The name was not found in the table,     *  or it was, and the queue_id isn't valid anymore */    return OS_ERR_NAME_NOT_FOUND;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -