/*
 *  ======== WiFiCC3100_close ========
 */
void WiFiCC3100_close(WiFi_Handle handle)
{
    unsigned int              key;
    WiFiCC3100_Object        *object = handle->object;
    WiFiCC3100_HWAttrs const *hwAttrs = handle->hwAttrs;

#if defined(MSP430WARE) || defined(MSP432WARE)
    MAP_GPIO_disableInterrupt(hwAttrs->irqPort, hwAttrs->irqPin);
#else
    GPIOIntDisable(hwAttrs->irqPort, hwAttrs->irqPin);
#endif

#if !defined(MSP430WARE)
    Hwi_destruct(&(object->wifiHwi));
#endif

    Semaphore_destruct(&(object->readSemaphore));
    Semaphore_destruct(&(object->writeSemaphore));

    Log_print0(Diags_USER1, "WiFi Object closed.");

    key = Hwi_disable();
    object->spiState = WiFiCC3100_SPI_UNINITIALIZED;
    object->isOpen = false;
    Hwi_restore(key);
}
示例#2
0
/*
 *  ======== GateMutex_Instance_finalize ========
 */
Void GateMutex_Instance_finalize(GateMutex_Object *obj )
{
    Semaphore_Handle sem;

    sem = GateMutex_Instance_State_sem(obj);
    Semaphore_destruct(Semaphore_struct(sem));
}
示例#3
0
/*
 *  ======== Lck_Instance_finalize ========
 */
Void Lck_Instance_finalize(Lck_Object *obj )
{
    Semaphore_Handle sem;

    sem = Lck_Instance_State_sem(obj);
    Semaphore_destruct(Semaphore_struct(sem));
}
/*!
 *  @brief Function to close a given CC26XX I2C peripheral specified by the
 *         I2C handle.
 *
 *  After calling the close function, the I2C is disabled.
 *
 *  @pre    I2CCC26XX_open() has to be called first.
 *          Calling context: Task
 *
 *  @param handle An I2C_Handle returned by I2C_open()
 *
 *  @note  The generic I2C API should be used when accessing the I2CCC26XX.
 *
 *  @sa     I2CCC26XX_open(), I2C_close(), I2C_open()
 */
void I2CCC26XX_close(I2C_Handle handle)
{
    unsigned int             key;
    I2CCC26XX_Object         *object;
    I2CCC26XX_HWAttrs const  *hwAttrs;

    /* Get the pointer to the object and hwAttrs */
    hwAttrs = handle->hwAttrs;
    object = handle->object;

    /* Check to see if a I2C transaction is in progress */
    Assert_isTrue(object->headPtr == NULL, NULL);

    /* Deallocate pins */
    PIN_close(hPin);

    /* Mask I2C interrupts */
    I2CMasterIntDisable(hwAttrs->baseAddr);

    /* Disable the I2C Master */
    I2CMasterDisable(hwAttrs->baseAddr);

    /* Release power constraint*/
    threadSafeStdbyDisRelease();

    /* Power off the I2C module */
    Power_releaseDependency(hwAttrs->powerMngrId);

    Hwi_destruct(&(object->hwi));
    Semaphore_destruct(&(object->mutex));
    if (object->transferMode == I2C_MODE_BLOCKING) {
        Semaphore_destruct(&(object->transferComplete));
    }

    /* Unregister power post notification object */
    Power_unregisterNotify(&object->i2cPostObj);

    /* Mark the module as available */
    key = Hwi_disable();
    object->isOpen = false;
    Hwi_restore(key);

    Log_print1(Diags_USER1, "I2C: Object closed 0x%x", hwAttrs->baseAddr);

    return;
}
示例#5
0
/*
 *  ======== SemProcessSupport_Instance_finalize ========
 */
Void SemProcessSupport_Instance_finalize(SemProcessSupport_Handle sem)
{
    Semaphore_Handle bios6sem;
 
    bios6sem = SemProcessSupport_Instance_State_sem(sem);

    Semaphore_destruct(
            Semaphore_struct(bios6sem));
}
示例#6
0
/*
 *  ======== pthread_exit ========
 */
void pthread_exit(void *retval)
{
    pthread_Obj      *thread = (pthread_Obj *)pthread_self();

    /*
     *  This function terminates the calling thread and returns
     *  a value via retval that (if the thread is joinable) is available to
     *  another thread that calls pthread_join().
     *
     *  Any clean-up handlers that have not yet been popped, are popped
     *  (in the reverse of the order in which they were pushed) and executed.
     */
    thread->ret = retval;

    /*
     *  Don't bother disabling the Task scheduler while the thread
     *  is exiting.  It will be up to the application to not make
     *  such calls as pthread_cancel() or pthread_detach() while the
     *  thread is exiting.
     */

    /* Pop and execute the cleanup handlers */
    while (thread->cleanupList != NULL) {
        _pthread_cleanup_pop(thread->cleanupList, 1);
    }

    /* Cleanup any pthread specific data */
    _pthread_removeThreadKeys((pthread_t)thread);

    if (!thread->detached) {
        Semaphore_post(Semaphore_handle(&(thread->joinSem)));

        /* Set this task's priority to -1 to stop it from running. */
        Task_setPri(thread->task, -1);
    }
    else {
        /* Free memory */
#if ti_sysbios_posix_Settings_supportsMutexPriority__D
        Queue_destruct(&(thread->mutexList));
#endif
        Semaphore_destruct(&(thread->joinSem));

        Memory_free(Task_Object_heap(), thread, sizeof(pthread_Obj));

        /*
         *  Don't call Task_delete on the calling thread.  Task_exit()
         *  will put the task on the terminated queue, and if
         *  Task_deleteTerminatedTasks is TRUE, the task will be cleaned
         *  up automatically.
         */
        Task_exit();
    }
}
示例#7
0
/*
 *  ======== pthread_cancel ========
 *  The specification of this API is that it be used as a means for one thread
 *  to termintate the execution of another thread.  There is no mention of
 *  returning an error if the argument, pthread, is the same thread as the
 *  calling thread.
 */
int pthread_cancel(pthread_t pthread)
{
    pthread_Obj  *thread = (pthread_Obj *)pthread;
    UInt          key;

    /*
     *  Cancel the thread.  Only asynchronous cancellation is supported,
     *  since functions that would normally be cancellation points (eg,
     *  printf()), are not cancellation points for BIOS.
     */
    key = Task_disable();

    /* Indicate that cancellation is requested. */
    thread->cancelPending = 1;

    if (thread->cancelState == PTHREAD_CANCEL_ENABLE) {
        /* Set this task's priority to -1 to stop it from running. */
        Task_setPri(thread->task, -1);

        Task_restore(key);

        /* Pop and execute the cleanup handlers */
        while (thread->cleanupList != NULL) {
            _pthread_cleanup_pop(thread->cleanupList, 1);
        }

        /* Cleanup any pthread specific data */
        _pthread_removeThreadKeys(pthread);

        if (thread->detached) {
            /* Free memory */
#if ti_sysbios_posix_Settings_supportsMutexPriority__D
            Queue_destruct(&(thread->mutexList));
#endif
            Semaphore_destruct(&(thread->joinSem));
            Task_delete(&(thread->task));

            Memory_free(Task_Object_heap(), thread, sizeof(pthread_Obj));
        }
        else {
            /* pthread_join() will clean up. */
            thread->ret = PTHREAD_CANCELED;
            Semaphore_post(Semaphore_handle(&(thread->joinSem)));
        }
    }
    else {
        Task_restore(key);
    }

    return (0);
}
示例#8
0
/*
 *  ======== _pthread_runStub ========
 */
static void _pthread_runStub(UArg arg0, UArg arg1)
{
    UInt         key;
    Ptr          arg;
    pthread_Obj *thread = (pthread_Obj *)(xdc_uargToPtr(arg1));

    arg = Task_getEnv(thread->task);
    thread->ret = thread->fxn(arg);

    /* Pop and execute the cleanup handlers */
    while (thread->cleanupList != NULL) {
        _pthread_cleanup_pop(thread->cleanupList, 1);
    }

    /* Cleanup any pthread specific data */
    _pthread_removeThreadKeys((pthread_t)thread);

    key = Task_disable();

    if (!thread->detached) {
        Semaphore_post(Semaphore_handle(&(thread->joinSem)));

        /*
         * Set this task's priority to -1 to prevent it from being put
         * on the terminated queue (and deleted if Task.deleteTerminatedTasks
         * is true). pthread_join() will delete the Task object.
         */
        Task_setPri(thread->task, -1);
        Task_restore(key);
    }
    else {
        Task_restore(key);

        /* Free memory */
#if ti_sysbios_posix_Settings_supportsMutexPriority__D
        Queue_destruct(&(thread->mutexList));
#endif
        Semaphore_destruct(&(thread->joinSem));

        Memory_free(Task_Object_heap(), thread, sizeof(pthread_Obj));

        /* The system will have to clean up the Task object */
    }

    /* Task_exit() is called when returning from this function */
}
示例#9
0
/*
 *  ======== pthread_join ========
 *  Wait for thread to terminate.
 *
 *  If multiple threads simultaneously try to join with the same
 *  thread, the results are undefined.  We will return an error.
 *
 *  If the thread calling pthread_join() is canceled, then the target
 *  thread will remain joinable (i.e., it will not be detached).
 */
int pthread_join(pthread_t pthread, void **thread_return)
{
    pthread_Obj  *thread = (pthread_Obj *)pthread;
    UInt          key;

    key = Task_disable();

    if ((thread->joinThread != NULL) || (thread->detached != 0)) {
        /*
         *  Error - Another thread has already called pthread_join()
         *  for this thread, or the thread is in the detached state.
         */
        Task_restore(key);
        return (EINVAL);
    }

    if (pthread == pthread_self()) {
        Task_restore(key);
        return (EDEADLK);
    }

    /*
     *  Allow pthread_join() to be called from a BIOS Task.  If we
     *  set joinThread to pthread_self(), we could get NULL if the
     *  Task arg1 is 0.  All we need is a non-NULL value for joinThread.
     */
    thread->joinThread = Task_self();

    Task_restore(key);

    Semaphore_pend(Semaphore_handle(&(thread->joinSem)), BIOS_WAIT_FOREVER);

    if (thread_return) {
        *thread_return = thread->ret;
    }

#if ti_sysbios_posix_Settings_supportsMutexPriority__D
    Queue_destruct(&(thread->mutexList));
#endif
    Semaphore_destruct(&(thread->joinSem));

    Task_delete(&(thread->task));

    Memory_free(Task_Object_heap(), thread, sizeof(pthread_Obj));
    return (0);
}
/*
 *  ======== USBMSCHFatFsTiva_close ========
 */
void USBMSCHFatFsTiva_close(USBMSCHFatFs_Handle handle)
{
    unsigned int                key;
    DRESULT                     dresult;
    FRESULT                     fresult;
    USBMSCHFatFsTiva_Object    *object = handle->object;

    /* Unmount the FatFs drive */
    fresult = f_mount(object->driveNumber, NULL);
    if (fresult != FR_OK) {
        Log_print0(Diags_USER1, "USBMSCHFatFs: could not unmount FatFs volume");
    }

    /* Close USB Drive */
    USBHMSCDriveClose(object->MSCInstance);

    /* Unregister the disk_*() functions */
    dresult = disk_unregister(object->driveNumber);
    if (dresult != RES_OK) {
        Log_print0(Diags_USER1, "USBMSCHFatFs: error unregistering disk "
                                "functions");
    }

    /* Delete the HCDMain service task*/
    Task_destruct(&(object->taskHCDMain));

    /* Delete the semaphore */
    Semaphore_destruct(&(object->semUSBConnected));

    /* Delete the gate */
    GateMutex_destruct(&(object->gateUSBLibAccess));

    /* Delete the gate */
    GateMutex_destruct(&(object->gateUSBWait));

    /* Delete the hwi */
    Hwi_destruct(&(object->hwi));

    Log_print1(Diags_USER1, "USBMSCHFatFs: drive %d closed",
                             object->driveNumber);

    key = Hwi_disable();
    object->driveNumber = DRIVE_NOT_MOUNTED;
    Hwi_restore(key);
}
示例#11
0
/*!
 *  @brief  Function to close a given CC26XX SPI peripheral specified by the
 *          SPI handle.
 *
 *  Will disable the SPI, disable all SPI interrupts and release the
 *  dependency on the corresponding power domain.
 *
 *  @pre    SPICC26XXDMA_open() has to be called first.
 *          Calling context: Task
 *
 *  @param  handle  A SPI_Handle returned from SPI_open()
 *
 *  @sa     SPICC26XXDMA_open
 */
void SPICC26XXDMA_close(SPI_Handle handle)
{
    unsigned int                 key;
    SPICC26XX_Object             *object;
    SPICC26XX_HWAttrs const      *hwAttrs;

    /* Get the pointer to the object and hwAttrs */
    hwAttrs = handle->hwAttrs;
    object = handle->object;

    /* Release the uDMA dependency and potentially power down uDMA. */
    UDMACC26XX_close(object->udmaHandle);

    /* Deallocate pins */
    PIN_close(object->pinHandle);

    /* Disable the SPI */
    SSIDisable(hwAttrs->baseAddr);

    /* Destroy the Hwi */
    Hwi_destruct(&(object->hwi));

    /* Release power dependency on SPI. */
    Power_releaseDependency(hwAttrs->powerMngrId);

    if (object->transferMode == SPI_MODE_BLOCKING) {
        Semaphore_destruct(&(object->transferComplete));
    }

    /* Unregister power notification objects */
#ifdef SPICC26XXDMA_WAKEUP_ENABLED
    Power_unregisterNotify(&object->spiPreObj);
#endif
    Power_unregisterNotify(&object->spiPostObj);

    /* Mark the module as available */
    key = Hwi_disable();
    object->isOpen = false;
    Hwi_restore(key);

    Log_print1(Diags_USER1, "SPI:(%p) closed", hwAttrs->baseAddr);
}
Int SystemCfg_delete(SystemCfg_Object **objPtr)
{
    Int                 bufSize;
    List_Elem *         elem = NULL;
    SystemCfg_Object *  obj;
    IArg                key;


    Log_print0(Diags_ENTRY, "--> "FXNN": ()");

    /* remove object from module list */
    key = GateH_enter(Mod_gate);

    while ((elem = List_next(Mod_objList, elem)) != NULL) {
        obj = (SystemCfg_Object *)elem;

        if (obj == *objPtr) {
            List_remove(Mod_objList, elem);
            break;
        }
    }

    GateH_leave(Mod_gate, key);

    /* delete sync object */
    if ((*objPtr)->semH != NULL) {
        Semaphore_destruct(&(*objPtr)->semObj);
        (*objPtr)->semH = NULL;
    }

    /* free the name buffer */
    bufSize = strlen((*objPtr)->remoteProcName) + 1;
    xdc_runtime_Memory_free(NULL, (Ptr)((*objPtr)->remoteProcName), bufSize);

    /* free the object memory */
    xdc_runtime_Memory_free(NULL, (Ptr)(*objPtr), sizeof(SystemCfg_Object));
    *objPtr = NULL;

    Log_print1(Diags_EXIT, "<-- "FXNN": %d", (IArg)SystemCfg_S_SUCCESS);
    return(SystemCfg_S_SUCCESS);
}
示例#13
0
/*
 *  ======== ThreadSupport_Instance_finalize ========
 */
Void ThreadSupport_Instance_finalize(ThreadSupport_Handle obj, Int status)
{
    ti_sysbios_knl_Semaphore_Handle bios6sem;
 
    bios6sem = ThreadSupport_Instance_State_join_sem(obj);

    /* status is equal to the return code from Instance_init */
    switch (status) {
        case 0:
            Task_delete(&(obj->task));

            /* OK to fall through */

        case ThreadSupport_TASK_FAILURE:
            Semaphore_destruct(Semaphore_struct(bios6sem));

            /* OK to fall through */

        case ThreadSupport_PRI_FAILURE:
        default:
            break;
    }
}
示例#14
0
/*
 *  ======== pthread_create ========
 */
int pthread_create(pthread_t *newthread, const pthread_attr_t *attr,
        void *(*startroutine)(void *), void *arg)
{
    Semaphore_Params  semParams;
    Task_Params       taskParams;
    pthread_Obj      *thread = NULL;
    Error_Block       eb;
    pthread_attr_t   *pAttr;

    Error_init(&eb);
    Task_Params_init(&taskParams);

    *newthread = NULL;

    thread = (pthread_Obj *)Memory_alloc(Task_Object_heap(),
            sizeof(pthread_Obj), 0, &eb);

    if (thread == NULL) {
        return (ENOMEM);
    }

    pAttr = (attr == NULL) ? &defaultPthreadAttrs : (pthread_attr_t *)attr;

    taskParams.priority = pAttr->priority;
    taskParams.stack = pAttr->stack;
    taskParams.stackSize = pAttr->stacksize + pAttr->guardsize;

    /* Save the function in arg0 for ROV */
    taskParams.arg0 = (UArg)startroutine;
    taskParams.arg1 = (UArg)thread;
    taskParams.env = arg;
    taskParams.priority = -1;

    thread->detached = (pAttr->detachstate == PTHREAD_CREATE_JOINABLE) ? 0 : 1;
    thread->fxn = startroutine;
    thread->joinThread = NULL;
    thread->cancelState = PTHREAD_CANCEL_ENABLE;
    thread->cancelPending = 0;
    thread->priority = pAttr->priority;
    thread->cleanupList = NULL;

#if ti_sysbios_posix_Settings_supportsMutexPriority__D
    thread->blockedMutex = NULL;
    Queue_elemClear((Queue_Elem *)thread);
    Queue_construct(&(thread->mutexList), NULL);
#endif

    Semaphore_Params_init(&semParams);
    semParams.mode = Semaphore_Mode_BINARY;

    Semaphore_construct(&(thread->joinSem), 0, &semParams);

    thread->task = Task_create((Task_FuncPtr)_pthread_runStub,
            &taskParams, &eb);

    if (thread->task == NULL) {
        Semaphore_destruct(&(thread->joinSem));

#if ti_sysbios_posix_Settings_supportsMutexPriority__D
        Queue_destruct(&(thread->mutexList));
#endif
        Memory_free(Task_Object_heap(), thread, sizeof(pthread_Obj));

        return (ENOMEM);
    }

    *newthread = (pthread_t)thread;
    Task_setPri(thread->task, pAttr->priority);

    return (0);
}
/*
 *  ======== Server_finish ========
 *
 *  1. close remote resources
 *  2. handshake close event
 *  3. delete shared resoures
 *  4. send disconnect event (last event sent)
 *  5. wait for disconnect event
 *  6. unregister notify callback
 *  9. delete semaphore object
 */
Int Server_finish(Void)
{
    Int         status;
    UInt32      event;


    /*
     *  1. close remote resources
     */

    /* delete the RcmServer instance */
    status = RcmServer_delete(&Module.rcmServerH);

    if (status < 0) {
        Log_error1("Server_finish: RcmServer_delete() returned error %d",
            (IArg)status);
        goto leave;
    }

    /* unregister rcm heap with MessageQ */
    status = MessageQ_unregisterHeap(Global_RcmClientHeapId);

    if (status < 0) {
        goto leave;
    }

    /* close the rcm heap */
    status = HeapBufMP_close(&Module.heapH);

    if (status < 0) {
        Log_error1("Server_finish: HeapBufMP_close() returned error %d",
            (IArg)status);
        goto leave;
    }


    /*
     *  2. handshake close event
     */
    status = Notify_sendEvent(Module.hostProcId, Module.lineId,
        Module.eventId, App_CMD_CLOSED, TRUE);

    if (status < 0) {
        goto leave;
    }

    do {
        event = Server_waitForEvent();

        if (event >= App_E_FAILURE) {
            status = -1;
            goto leave;
        }
    } while (event != App_CMD_CLOSED);


    /*
     *  3. delete shared resoures
     */


    /*
     *  4. send disconnect event (last event sent)
     */
    status = Notify_sendEvent(Module.hostProcId, Module.lineId,
        Module.eventId, App_CMD_DONE, TRUE);

    if (status < 0) {
        goto leave;
    }


    /*
     *  5. wait for disconnect event (last event received)
     */
    do {
        event = Server_waitForEvent();

        if (event >= App_E_FAILURE) {
            status = -1;
            goto leave;
        }
    } while (event != App_CMD_DONE);


    /*
     *  6. unregister notify callback
     */
    status = Notify_unregisterEventSingle(Module.hostProcId, Module.lineId,
        Module.eventId);

    if (status < 0) {
        goto leave;
    }


    /*
     *  9. delete semaphore object
     */
    Semaphore_destruct(&Module.semS);
    Module.semH = NULL;


leave:
    return(status);
}