Esempio n. 1
0
xdc_Void A110x2500Radio::serviceInterrupt(xdc_UArg arg0, xdc_UArg arg1) {
  while(1) {
    Semaphore_pend(sem, BIOS_WAIT_FOREVER);

    GateMutex_enter(GateMutex_handle(&mygate));

    // Note: It is assumed that interrupts are disabled.

    // The GDO0 ISR will only look for the EOP edge. Therefore, if the radio
    // is not transmitting the EOP, it must be receiving an EOP signal.
    if (gDataTransmitting)
    {
      /**
       *  Note: GDO0 is issued prior to the transmitter being completely
       *  finished. The state machine will remain in TX_END until transmission
       *  completes. The following waits for TX_END to correct the hardware
       *  behavior.
       */ 
      while (CC1101GetMarcState(&gPhyInfo.cc1101) == eCC1101MarcStateTx_end);
      gDataTransmitting = false;
    }
    else
    {
      gDataReceived = true;
      readDataStream();
    }

    // Always go back to sleep.
    sleep();
    GateMutex_leave(GateMutex_handle(&mygate), 0);
  }
}
/*
 *  ======== USBMSCHFatFsTiva_diskWrite ========
 *  This function writes sector(s) to the disk drive
 *
 *  @param  drv     Drive Number
 *
 *  @param  buf     Pointer to a buffer from which data is read
 *
 *  @param  sector  Sector number to write to
 *
 *  @param  count   Number of sectors to be written
 */
DRESULT USBMSCHFatFsTiva_diskWrite(BYTE drv, const BYTE *buf,
                                   DWORD sector, BYTE count)
{
    unsigned int                key;
    uint32_t                    driveWrite;
    USBMSCHFatFsTiva_Object    *object = USBMSCHFatFs_config->object;

    Log_print2(Diags_USER1, "USBMSCHFatFs: diskWrite: Sector %d, Count %d",
                             sector, count);

    if (!count) {
        Log_print0(Diags_USER1, "USBMSCHFatFs: diskWrite: ERROR");
        return (RES_PARERR);
    }

    if (object->state != USBMSCHFatFsTiva_CONNECTED) {
        Log_print0(Diags_USER1, "USBMSCHFatFs: diskWrite: not initialized");
        return (RES_NOTRDY);
    }

    key = GateMutex_enter(GateMutex_handle(&(object->gateUSBLibAccess)));
    driveWrite = USBHMSCBlockWrite(object->MSCInstance, sector, (uint8_t *)buf, count);
    GateMutex_leave(GateMutex_handle(&(object->gateUSBLibAccess)), key);

    if (driveWrite == 0) {
        Log_print0(Diags_USER2, "USBMSCHFatFs: diskWrite: OK");
        return (RES_OK);
    }
    else {
        Log_print0(Diags_USER2, "USBMSCHFatFs: diskWrite: ERROR");
        return (RES_ERROR);
    }
}
/*
 *  ======== USBMSCHFatFsTiva_diskInitialize ========
 *  This function checks the USB Drive to see if it's ready to be accessed.
 *
 *  This function attempts to read the USBHMSCDriveReady() function up to 10
 *  times to get a good return code. For some reason the first attempt to read
 *  this function doesn't return a good response value. Generally, you should
 *  get a good response on the second attempt.
 *  A gateMutex lock is required to prevent concurrent access to the USB
 *  Library's state machine variables within MSCInstance.
 *
 *  @param  drv Drive Number
 *
 *  @return Returns the disk status to the FatFs module
 */
DSTATUS USBMSCHFatFsTiva_diskInitialize(BYTE drv)
{
    unsigned char               i;
    unsigned int                key;
    uint32_t                    driveReady;
    USBMSCHFatFsTiva_Object    *object = USBMSCHFatFs_config->object;

    /* Determine if the USB Drive is ready up to 10 times */
    for (i = 0; i < 10; i++ ) {

        key = GateMutex_enter(GateMutex_handle(&(object->gateUSBLibAccess)));
        driveReady = USBHMSCDriveReady(object->MSCInstance);
        GateMutex_leave(GateMutex_handle(&(object->gateUSBLibAccess)), key);

        if (driveReady == 0) {
            Log_print1(Diags_USER1, "USBMSCHFatFs: disk initialization: "
                                    "ready after %d tries", i);

            return (0x00); /* Disk OK */
        }
    }

    Log_print0(Diags_USER1, "USBMSCHFatFs: disk initialization: not ready");
    return (STA_NOINIT);
}
/*
 *  ======== USBMSCHFatFsTiva_diskRead ========
 *  This function reads sector(s) from the disk drive
 *
 *  @param  drv     Drive Number
 *
 *  @param  buf     Pointer to a buffer to which data is written
 *
 *  @param  sector  Sector number to read from
 *
 *  @param  count   Number of sectors to be read
 */
DRESULT USBMSCHFatFsTiva_diskRead(BYTE drv, BYTE *buf,
                                  DWORD sector, BYTE count)
{
    unsigned int                key;
    uint32_t                    driveRead;
    USBMSCHFatFsTiva_Object    *object = USBMSCHFatFs_config->object;

    Log_print2(Diags_USER1, "USBMSCHFatFs: diskRead: Sector %d, Count %d",
                             sector, count);

    if (object->state != USBMSCHFatFsTiva_CONNECTED) {
        Log_print0(Diags_USER1, "USBMSCHFatFs: diskRead: not initialized");
        return (RES_NOTRDY);
    }

    /* READ BLOCK */
    key = GateMutex_enter(GateMutex_handle(&(object->gateUSBLibAccess)));
    driveRead = USBHMSCBlockRead(object->MSCInstance, sector, buf, count);
    GateMutex_leave(GateMutex_handle(&(object->gateUSBLibAccess)), key);

    if (driveRead == 0) {
        Log_print0(Diags_USER2, "USBMSCHFatFs: diskRead: OK");
        return (RES_OK);
    }
    else {
        Log_print0(Diags_USER2, "USBMSCHFatFs: diskRead: ERROR");
        return (RES_ERROR);
    }
}
Esempio n. 5
0
/*
 *  ======== USBKBD_putChar ========
 */
int USBKBD_putChar(int ch, unsigned int timeout)
{
    /* Indicate failure */
    int retValue = 0;
    unsigned int key;

    switch (state) {
    case USBKBD_STATE_UNCONFIGURED:
        USBKBD_waitForConnect(timeout);
        break;

    case USBKBD_STATE_SUSPENDED:
        /* Acquire lock */
        key = GateMutex_enter(gateKeyboard);

        state = USBKBD_STATE_SENDING;
        USBDHIDKeyboardRemoteWakeupRequest((void *)&keyboardDevice);

        if (waitUntilSent(timeout)) {
            retValue = sendChar(ch, timeout);
        }

        /* Release lock */
        GateMutex_leave(gateKeyboard, key);
        break;

    case USBKBD_STATE_SENDING:
    case USBKBD_STATE_IDLE:
        /* Acquire lock */
        key = GateMutex_enter(gateKeyboard);

        retValue = sendChar(ch, timeout);

        /* Release lock */
        GateMutex_leave(gateKeyboard, key);
        break;

    default:
        break;
    }

    return (retValue);
}
Esempio n. 6
0
void TwoWire::beginTransmission(uint8_t address)
{
    WireContext *wc = getWireContext();

    GateMutex_enter(GateMutex_handle(&gate));
    gateEnterCount++;

    if (wc->idle) {
        wc->i2cTransaction.slaveAddress = address;
        wc->idle = false;
    }
}
/*
 *  ======== USBMSCHFatFsTiva_serviceUSBHost ========
 *  Task to periodically service the USB Stack
 *
 *  USBHCDMain handles the USB Stack's statemachine. For example it handles the
 *  enumeration process when a device connects.
 *  Future USB library improvement goal is to remove this polling requirement..
 */
static void USBMSCHFatFsTiva_serviceUSBHost(UArg arg0, UArg arg1)
{
    unsigned int                key;
    USBMSCHFatFsTiva_Object    *object = USBMSCHFatFs_config->object;

    while (true) {
        key = GateMutex_enter(GateMutex_handle(&(object->gateUSBLibAccess)));
        USBHCDMain();
        GateMutex_leave(GateMutex_handle(&(object->gateUSBLibAccess)), key);

        /* Future enhancement to remove the Task_sleep */
        Task_sleep(10);
    }
}
Esempio n. 8
0
/*
 *  ======== USBCDCMOUSE_sendData ========
 */
unsigned int USBCDCMOUSE_sendData(const unsigned char *pStr,
                                  unsigned int length,
                                  unsigned int timeout)
{
    unsigned int retValue = 0;
    unsigned int key;

    if (USB_getConnectionInformation() & USB_ENUMERATED) {
        key = GateMutex_enter(gateTxSerial);
        retValue = txData(pStr, length, timeout);
        GateMutex_leave(gateTxSerial, key);
    }

    return (retValue);
}
Esempio n. 9
0
/*
 *  ======== USBKBD_waitForConnect ========
 */
bool USBKBD_waitForConnect(unsigned int timeout)
{
    bool ret = true;
    unsigned int key;

    /* Need exclusive access to prevent a race condition */
    key = GateMutex_enter(gateUSBWait);

    if (state == USBKBD_STATE_UNCONFIGURED) {
        if (!Semaphore_pend(semUSBConnected, timeout)) {
            ret = false;
        }
    }

    GateMutex_leave(gateUSBWait, key);

    return (ret);
}
Esempio n. 10
0
/*
 *  ======== USBCDCMOUSE_waitForConnect ========
 */
bool USBCDCMOUSE_waitForConnect(unsigned int timeout)
{
    bool ret = true;
    unsigned int key;

    /* Need exclusive access to prevent a race condition */
    key = GateMutex_enter(gateUSBWait);

    if (!(USB_getConnectionInformation() & USB_ENUMERATED)) {
        if (!Semaphore_pend(semUSBConnected, timeout)) {
            ret = false;
        }
    }

    GateMutex_leave(gateUSBWait, key);

    return (ret);
}
/*
 *  ======== USBMSCHFatFsTiva_waitForConnect ========
 */
bool USBMSCHFatFsTiva_waitForConnect(USBMSCHFatFs_Handle handle,
                                     unsigned int timeout)
{
    unsigned int                key;
    bool                        ret = true;
    USBMSCHFatFsTiva_Object    *object = handle->object;

    /* Need exclusive access to prevent a race condition */
    key = GateMutex_enter(GateMutex_handle(&(object->gateUSBWait)));

    if (object->state == USBMSCHFatFsTiva_NO_DEVICE) {
        if (!Semaphore_pend(Semaphore_handle(&(object->semUSBConnected)),
                                             timeout)) {
            ret = false;
        }
    }

    GateMutex_leave(GateMutex_handle(&(object->gateUSBWait)), key);

    return (ret);
}
Esempio n. 12
0
/*
 *  ======== sendState ========
 */
static int sendState(USBCDCMOUSE_State *mouseState,
                     unsigned int timeout)
{
    unsigned int key;
    int retValue;
    MouseReport mouseReport = {0};

    /* Set the bit packed button values */
    mouseReport.buttons |= (mouseState->button1) ? 0x01 : 0;
    mouseReport.buttons |= (mouseState->button2) ? 0x02 : 0;
    mouseReport.buttons |= (mouseState->button3) ? 0x04 : 0;
    mouseReport.dX = mouseState->deltaX;
    mouseReport.dY = mouseState->deltaY;

    /* Acquire lock */
    key = GateMutex_enter(gateMouse);
    USBHID_sendReport((void*)&mouseReport, M_INTFNUM);
    retValue = Semaphore_pend(semMouse, timeout);

    /* Release lock */
    GateMutex_leave(gateMouse, key);

    return (retValue);
}
Esempio n. 13
0
/*
 *  ======== NameServerMessageQ_get ========
 */
Int NameServerMessageQ_get(NameServerMessageQ_Object *obj,
                           String instanceName,
                           String name,
                           Ptr value,
                           UInt32 *valueLen,
                           ISync_Handle syncHandle,
                           Error_Block *eb)
{
    Int len;
    Int status;
    IArg key;
    MessageQ_QueueId queueId;
    NameServerMsg    *msg;
    Semaphore_Handle semRemoteWait = NameServerMessageQ_module->semRemoteWait;
    GateMutex_Handle gateMutex = NameServerMessageQ_module->gateMutex;

    /* enter gate - prevent multiple threads from entering */
    key = GateMutex_enter(gateMutex);

    /* alloc a message from specified heap */
    msg = (NameServerMsg *)MessageQ_alloc(NameServerMessageQ_heapId,
                                          sizeof(NameServerMsg));
    
    /* make sure message is not NULL */
    if (msg == NULL) {
        Error_raise(eb, NameServerMessageQ_E_outOfMemory,
                    NameServerMessageQ_heapId, 0);
        return (NameServer_E_OSFAILURE);
    }
    
    /* make sure this is a request message */
    msg->request = NameServerMessageQ_REQUEST;
    msg->requestStatus = 0;

    /* get the length of instanceName */
    len = strlen(instanceName);

    /* assert length is smaller than max (must have room for null character) */
    Assert_isTrue(len < MAXNAMEINCHAR, NameServerMessageQ_A_nameIsTooLong);

    /* copy the name of instance into putMsg */
    strncpy((Char *)msg->instanceName, instanceName, len);

    /* get the length of name */
    len = strlen(name);

    /* assert length is smaller than max (must have room for null character) */
    Assert_isTrue(len < MAXNAMEINCHAR, NameServerMessageQ_A_nameIsTooLong);

    /* copy the name of nameserver entry into putMsg */
    strncpy((Char *)msg->name, name, len);

    /* determine the queueId based upon the processor */
    queueId = MessageQ_openQueueId(MESSAGEQ_INDEX, obj->remoteProcId);

    /* set the reply procId */
    MessageQ_setReplyQueue(
        (MessageQ_Handle)NameServerMessageQ_module->msgHandle,
        (MessageQ_Msg)msg);
    
    /* send message to remote processor. */
    status = MessageQ_put(queueId, (MessageQ_Msg)msg);

    /* make sure message sent successfully */
    if (status < 0) {
        /* free the message */
        MessageQ_free((MessageQ_Msg)msg);

        return (NameServer_E_FAIL);
    }

    /* pend here until we get a response back from remote processor */
    status = Semaphore_pend(semRemoteWait, NameServerMessageQ_timeout);

    if (status == FALSE) {
        /* return timeout failure */
        return (NameServer_E_OSFAILURE);
    }

    /* get the message */
    msg = NameServerMessageQ_module->msg;

    if (msg->requestStatus) {
        /* name is found */

        /* set length to amount of data that was copied */
        *valueLen = sizeof(Bits32);
    
        /* set the contents of value */
        memcpy(value, &(msg->value), sizeof(Bits32));

        /* set the status to success */
        status = NameServer_S_SUCCESS;
    }
    else {
        /* name is not found */

        /* set status to not found */
        status = NameServer_E_NOTFOUND;
    }

    /* free the message */
    MessageQ_free((MessageQ_Msg)msg);

    /* leave the gate */
    GateMutex_leave(gateMutex, key);
    
    /* return success status */
    return (status);
}
Esempio n. 14
0
File: os.c Progetto: ianjuch/ee149
/**
 * \brief try to obtain the exclusive ownership on the mutex
 *
 * Attempts to obtain exclusive ownership of the specified mutex.
 * If the calling thread already owns the mutex, an internal counter is incremented
 * and a successful status is returned.
 *
 * \param[in] p_handle      Handle to a mutex control block
 * \param[out] p_handle     Key for nested mutex (SYS/BIOS)
 *                          If OS doesnt support, assign -1 to it in your implementation
 *
 * \return   e_SUCCESS on success, e_FAILURE on error
 *
 * \sa OS_mutex_create, OS_mutex_delete, OS_mutex_unlock
 * \note
 *
 * \warning
 */
e_ret_status OS_mutex_lock(handle p_handle, handle p_key)
{
    sInt32 key = GateMutex_enter(p_handle);
    *(sInt32 *)p_key = key;
    return e_SUCCESS;
}