Ejemplo n.º 1
0
void A110x2500Radio::begin(uint8_t address, channel_t channel, power_t power)
{
  gDataTransmitting = false;
  gDataReceived = false;
  Task_Params taskParams;
  Error_Block eb;
  Error_init(&eb);
  GateMutex_construct(&mygate, NULL);

  sem = Semaphore_create(0, NULL, &eb);
  // Configure the radio and set the default address, channel, and TX power.
  A110LR09Init(&gPhyInfo, &gSpi, gGdo);
  setAddress(address);
  setChannel(channel);
  setPower(power);

  Task_Params_init(&taskParams);
  taskParams.priority = Task_numPriorities - 1;

  taskParams.stackSize = 0x800;
  Task_create(serviceInterrupt, &taskParams, &eb);

  attachInterrupt(RF_GDO0, gdo0Isr, FALLING);
  sleep();
}
Ejemplo n.º 2
0
// Initialize as a master
void TwoWire::begin(void)
{
    I2C_Params params;

    /* return if I2C already started */
    if (begun == TRUE) return;

    I2C_Params_init(&params);
    params.transferMode = I2C_MODE_BLOCKING;
    params.bitRate = I2C_400kHz;

    i2c = Board_openI2C(i2cModule, &params);

    if (i2c != NULL) {
        GateMutex_construct(&gate, NULL);
        gateEnterCount = 0;
        begun = TRUE;
    }
}
/*
 *  ======== USBMSCHFatFsTiva_open ========
 */
USBMSCHFatFs_Handle USBMSCHFatFsTiva_open(USBMSCHFatFs_Handle handle,
                                          unsigned char drv,
                                          USBMSCHFatFs_Params *params)
{
    unsigned int                    key;
    DRESULT                         dresult;
    FRESULT                         fresult;
    USBMSCHFatFsTiva_Object        *object = handle->object;
    USBMSCHFatFsTiva_HWAttrs const *hwAttrs = handle->hwAttrs;
    union {
        Task_Params                 taskParams;
        Semaphore_Params            semParams;
        GateMutex_Params            gateParams;
        Hwi_Params                  hwiParams;
    } paramsUnion;

    /* Determine if the device was already opened */
    key = Hwi_disable();
    if (object->driveNumber != DRIVE_NOT_MOUNTED) {
        Hwi_restore(key);
        return (NULL);
    }
    /* Mark as being used */
    object->driveNumber = drv;
    Hwi_restore(key);

    /* Store the USBMSCHFatFs parameters */
    if (params == NULL) {
        /* No params passed in, so use the defaults */
        params = (USBMSCHFatFs_Params *) &USBMSCHFatFs_defaultParams;
    }

    /* Initialize the USB stack for host mode. */
    USBStackModeSet(0, eUSBModeHost, NULL);

    /* Register host class drivers */
    USBHCDRegisterDrivers(0, usbHCDDriverList, numHostClassDrivers);

    /* Open an instance of the MSC host driver */
    object->MSCInstance = USBHMSCDriveOpen(0, USBMSCHFatFsTiva_cbMSCHandler);
    if (!(object->MSCInstance)) {
        Log_print0(Diags_USER1,"USBMSCHFatFs: Error initializing the MSC Host");
        USBMSCHFatFsTiva_close(handle);
        return (NULL);
    }

    /* Create the Hwi object to service interrupts */
    Hwi_Params_init(&(paramsUnion.hwiParams));
    paramsUnion.hwiParams.priority = hwAttrs->intPriority;

    Hwi_construct(&(object->hwi), hwAttrs->intNum, USBMSCHFatFsTiva_hwiHandler,
                 &(paramsUnion.hwiParams), NULL);

    /* Initialize USB power configuration */
    USBHCDPowerConfigInit(0, USBHCD_VBUS_AUTO_HIGH | USBHCD_VBUS_FILTER);

    /* Enable the USB stack */
    USBHCDInit(0, object->memPoolHCD, HCDMEMORYPOOLSIZE);

    /* RTOS primitives */
    Semaphore_Params_init(&(paramsUnion.semParams));
    paramsUnion.semParams.mode = Semaphore_Mode_BINARY;
    Semaphore_construct(&(object->semUSBConnected), 0, &(paramsUnion.semParams));

    GateMutex_Params_init(&(paramsUnion.gateParams));
    paramsUnion.gateParams.instance->name = "USB Library Access";
    GateMutex_construct(&(object->gateUSBLibAccess), &(paramsUnion.gateParams));

    paramsUnion.gateParams.instance->name = "USB Wait";
    GateMutex_construct(&(object->gateUSBWait), &(paramsUnion.gateParams));

    /*
     * Note that serviceUSBHost() should not be run until the USB Stack has been
     * initialized!!
     */
    Task_Params_init(&(paramsUnion.taskParams));

    /*
     * If serviceTaskStackPtr is null, then Task_construct performs a
     * Memory_alloc - requiring a Heap
     */
    paramsUnion.taskParams.stack = params->serviceTaskStackPtr;

    /*
     * If service priority passed in is higher than what is configured by the
     * Task module, then use the highest priority available.
     */
    if (Task_numPriorities - 1 < params->servicePriority) {
        paramsUnion.taskParams.priority = (Task_numPriorities - 1);
    }
    else {
        paramsUnion.taskParams.priority = params->servicePriority;
    }

    /* If no stack size is passed in, then use the default task stack size */
    if (params->serviceTaskStackSize) {
        paramsUnion.taskParams.stackSize = params->serviceTaskStackSize;
    }
    else {
        paramsUnion.taskParams.stackSize = Task_defaultStackSize;
    }

    Task_construct(&(object->taskHCDMain),USBMSCHFatFsTiva_serviceUSBHost,
                   &(paramsUnion.taskParams), NULL);

    /* Register the new disk_*() functions */
    dresult = disk_register(drv,
                            USBMSCHFatFsTiva_diskInitialize,
                            USBMSCHFatFsTiva_diskStatus,
                            USBMSCHFatFsTiva_diskRead,
                            USBMSCHFatFsTiva_diskWrite,
                            USBMSCHFatFsTiva_diskIOctl);

    /* Check for drive errors */
    if (dresult != RES_OK) {
        Log_error0("USBMSCHFatFs: disk functions not registered");
        USBMSCHFatFsTiva_close(handle);
        return (NULL);
    }

    /* Mount the FatFs (this function does not access the SDCard yet...) */
    fresult = f_mount(drv, &(object->filesystem));
    if (fresult != FR_OK) {
        Log_error1("USBMSCHFatFs: drive %d not mounted", drv);
        USBMSCHFatFsTiva_close(handle);
        return (NULL);
    }

    Log_print1(Diags_USER1, "USBMSCHFatFs: drive %d opened", drv);

    return (handle);
}