// -----------------------------------------------------------------------------
//! \brief      This routine closes the transport layer
//!
//! \return     void
// -----------------------------------------------------------------------------
void NPITL_closeTL(void)
{
    _npiCSKey_t key;
    key = NPIUtil_EnterCS();
    
    // Clear NPI Task Call backs
    memset(&taskCBs, 0, sizeof(taskCBs));
  
    // Free Transport Layer RX/TX buffers
    npiBufSize = 0;
    NPIUTIL_FREE(npiRxBuf);
    NPIUTIL_FREE(npiTxBuf);
  
    // Close Transport Layer 
    transportClose();
    
#ifdef POWER_SAVING  
    // Close PIN Handle
    PIN_close(hNpiHandshakePins);
#ifdef NPI_SW_HANDSHAKING_DEBUG
    PIN_close(hNpiProfilingDebugPin);
#endif //NPI_SW_HANDSHAKING
    // Release Power Management
    NPITL_relPM();
#endif //POWER_SAVING

    NPIUtil_ExitCS(key);
}
/*******************************************************************************
 * @fn          bspSpiOpen
 *
 * @brief       Open the RTOS SPI driver
 *
 * @param       none
 *
 * @return      none
 */
void bspSpiOpen(void)
{
  if (hSpiPin != NULL)
  {
    // Remove IO configuration of SPI lines
    PIN_close(hSpiPin);

    hSpiPin = NULL;
  }

  if (spiHandle == NULL)
  {
    /*  Configure SPI as master, 1 mHz bit rate*/
    SPI_Params_init(&spiParams);
    spiParams.bitRate = 1000000;
    spiParams.mode         = SPI_MASTER;
    spiParams.transferMode = SPI_MODE_BLOCKING;

    /* Attempt to open SPI. */
    spiHandle = SPI_open(Board_SPI0, &spiParams);

    if (spiHandle == NULL)
    {
      Task_exit();
    }
  }

  nUsers++;
}
// -----------------------------------------------------------------------------
//! \brief      This routine is used to handle an MRDY transition from a task
//!             context. Certain operations such as UART_read() cannot be
//!             performed from a HWI context
//!
//! \return     void
// -----------------------------------------------------------------------------
void NPITL_handleRemRdyEvent(void)
{
	_npiCSKey_t key;
	key = NPIUtil_EnterCS();
	//If the UART port is closed, then open it
    if(HS_GPIO_STATE & handshakingState)
    {
    	NPITL_setPM();
    	//Close the GPIO, then
    	//Open the UART
    	 PIN_close(hNpiHandshakePins);
    	 transportOpen(npiTLParams.portBoardID,
					  &npiTLParams.portParams.uartParams,
					  NPITL_transmissionCallBack, NPITL_chirpRecievedCB);
    	 handshakingState |=  HS_WAITFORCHIRP|HS_UART_STATE;
    	 //Clear GPIO flag, we are no longer in this state
    	 handshakingState &= ~HS_GPIO_STATE;
    }
    else
    {
    	//Once UART is open
        //Handle the RemRdy Event
        transportRemRdyEvent();
    }
    NPIUtil_ExitCS(key);
}
// -----------------------------------------------------------------------------
//! \brief      This routine closes the transport layer
//!
//! \return     void
// -----------------------------------------------------------------------------
void NPITL_closeTL(void)
{
    _npiCSKey_t key;
    key = NPIUtil_EnterCS();
    
    // Clear NPI Task Call backs
    memset(&taskCBs, 0, sizeof(taskCBs));
  
    // Free Transport Layer RX/TX buffers
    npiBufSize = 0;
    NPIUTIL_FREE(npiRxBuf);
    NPIUTIL_FREE(npiTxBuf);
  
    // Close Transport Layer 
    transportClose();
    
#if (NPI_FLOW_CTRL == 1)
    // Clear mrdy and srdy PIN IDs
    remRdyPIN = (IOID_UNUSED & IOC_IOID_MASK); // Set to 0x000000FF
    locRdyPIN = (IOID_UNUSED & IOC_IOID_MASK); // Set to 0x000000FF
    
    // Clear PIN IDs from PIN Configuration
    npiHandshakePinsCfg[REM_RDY_PIN_IDX] &= ~remRdyPIN; 
    npiHandshakePinsCfg[LOC_RDY_PIN_IDX] &= ~locRdyPIN;
    
    // Close PIN Handle
    PIN_close(hNpiHandshakePins);
    
    // Release Power Management
    NPITL_relPM();
#endif // NPI_FLOW_CTRL = 1

    NPIUtil_ExitCS(key);
}
// -----------------------------------------------------------------------------
//! \brief      This routine calls the UART transport open
//!
//! \param[in]  initiatorState - Whether the UART is being opened by initiator
//!             or responder. 1 - initiator 0 - responsder
//!
//! \return     void
// -----------------------------------------------------------------------------
void NPITL_openTransportPort(hsTransactionRole role)
{
  NPITL_setPM();
  // Close the RxPin
  PIN_close(hNpiUartRxPin);
  transportOpen(npiTLParams.portBoardID,
                &npiTLParams.portParams.uartParams, role);
  trasnportLayerState = TL_busy;
}
/**
 * @fn      SBL_resetTarget
 *
 * @brief   Forces target device to boot from flash image instead of SBL. This
 *          function can be called before SBL_open() or after SBL_open()
 *
 * @param   rstPinID - Board Pin ID of reset PIN
 * @param   blPinID  - Board Pin ID of boot loader PIN
 *
 * @return  uint8_t - SBL_SUCCESS, SBL_FAILURE
 */
uint8_t SBL_resetTarget(uint32_t rstPinID, uint32_t blPinID)
{
  uint8_t openedPins = 0;
  
  if (hsblPins == NULL)
  {
    // Must open pins if SBL_open() has not yet been called
    openedPins = 1;
    
    // Assign PIN IDs to reset and bl
    rstPIN = (rstPinID & IOC_IOID_MASK);
    blPIN = (blPinID & IOC_IOID_MASK);
    
    // Add PIN IDs to PIN Configuration
    sblPinsCfg[RST_PIN_IDX] |= rstPIN;
    sblPinsCfg[BL_PIN_IDX] |= blPIN;
    
    // Initialize SBL Pins
    hsblPins = PIN_open(&sblPins, sblPinsCfg);
    if (hsblPins == NULL)
    {
      return SBL_FAILURE;
    }
  }
  
  // Guarantee that Boot Loader Pin is high during reset toggle
  PIN_setOutputValue(hsblPins, blPIN, 1);
  
  // Set reset PIN low
  PIN_setOutputValue(hsblPins, rstPIN, 0);
  
  SBL_utilDelay(15);
  
  // Release Reset PIN 
  PIN_setOutputValue(hsblPins, rstPIN, 1);

  // Must close Pins if opened in function
  if (openedPins)
  {
    // Clear SBL PIN IDs
    rstPIN = (IOID_UNUSED & IOC_IOID_MASK); // Set to 0x000000FF
    blPIN = (IOID_UNUSED & IOC_IOID_MASK); // Set to 0x000000FF
    
    // Clear PIN IDs from PIN Configuration
    sblPinsCfg[RST_PIN_IDX] &= ~rstPIN; 
    sblPinsCfg[BL_PIN_IDX] &= ~blPIN;
    
    // Close PIN Handle
    PIN_close(hsblPins);
    hsblPins = NULL;
  }
  
  return SBL_SUCCESS;
}
/*******************************************************************************
 * @fn          devpkLcdClose
 *
 * @brief       Turns of the display and releases the LCD control pins
 *
 * @return      true if success
 */
void devpkLcdClose(void)
{
  if (hLcdPin != NULL)
  {
    // Turn off the display
    PIN_setOutputValue(hLcdPin,Board_DEVPK_LCD_DISP,0);

    PIN_close(hLcdPin);
    hLcdPin = NULL;

    bspSpiClose();
  }
}
/*!
 *  @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;
}
/**
 * @fn      SBL_close
 *
 * @brief   Closes SBL port
 *
 * @param   None.
 *
 * @return  uint8_t - SBL_SUCCESS, SBL_FAILURE
 */
uint8_t SBL_close(void)
{
  // Clear SBL PIN IDs
  rstPIN = (IOID_UNUSED & IOC_IOID_MASK); // Set to 0x000000FF
  blPIN = (IOID_UNUSED & IOC_IOID_MASK); // Set to 0x000000FF
  
  // Clear PIN IDs from PIN Configuration
  sblPinsCfg[RST_PIN_IDX] &= ~rstPIN; 
  sblPinsCfg[BL_PIN_IDX] &= ~blPIN;
  
  // Close PIN Handle
  PIN_close(hsblPins);
  hsblPins = NULL;
  
  // Close SBL Transport Layer
  SBL_TL_close();
  
  return SBL_SUCCESS;
}
Example #10
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);
}
Example #11
0
// -----------------------------------------------------------------------------
//! \brief      This routine closes the transport layer
//!
//! \return     void
// -----------------------------------------------------------------------------
void NPITL_closeTL(void)
{
    _npiCSKey_t key;
    key = NPIUtil_EnterCS();
    
    // Clear NPI Task Call backs
    memset(&taskCBs, 0, sizeof(taskCBs));
  
    // Free Transport Layer RX/TX buffers
    npiBufSize = 0;
    NPIUTIL_FREE(npiRxBuf);
    NPIUTIL_FREE(npiTxBuf);
  
    // Close the RxPin
    PIN_close(hNpiUartRxPin);
    // Close UART transport Layer 
    transportClose();
    trasnportLayerState = TL_closed;
    
    NPITL_relPM();

    NPIUtil_ExitCS(key);
}
Example #12
0
void taskFxn(UArg a0, UArg a1) {

  Hwi_Params hwiParams;
  Hwi_Params_init(&hwiParams);
  hwiParams.enableInt = true;

  Hwi_construct(&hwi, INT_AUX_ADC, adcIsr, &hwiParams, NULL);

  UART_Params uParams;
  // Initialize default values
  UART_Params_init(&uParams);
  // Configure custom data, don't care about read params as not used
  // 115.2kBaud, Text, blocking mode
  uHandle = UART_open(Board_UART,&uParams);

  // Set up pins
  pinHandle = PIN_open(&pinState, alsPins);

  // Enable clock for ADC digital and analog interface (not currently enabled in driver)
  AUXWUCClockEnable(AUX_WUC_MODCLKEN0_SOC_M|AUX_WUC_MODCLKEN0_AUX_ADI4_M);
  // Connect AUX IO7 (DIO23) as analog input. Light sensor on SmartRF06EB
  AUXADCSelectInput(ADC_COMPB_IN_AUXIO7);


  // Set up ADC
  AUXADCEnableSync(AUXADC_REF_FIXED, AUXADC_SAMPLE_TIME_2P7_US, AUXADC_TRIGGER_MANUAL);

  // Disallow STANDBY mode while using the ADC.
  Power_setConstraint(Power_SB_DISALLOW);

  uint8_t currentSample = 0;

  while(currentSample < SAMPLECOUNT) {

    //Sleep 100ms in IDLE mode
    Task_sleep(100 * 1000 / Clock_tickPeriod);

    // Trigger ADC sampling
    AUXADCGenManualTrigger();
    // Wait in IDLE until done
    Semaphore_pend(hSem, BIOS_WAIT_FOREVER );

    adcSamples[currentSample++] = singleSample;

  }

  // Disable ADC
  AUXADCDisable();
  // Allow STANDBY mode again
  Power_releaseConstraint(Power_SB_DISALLOW);

  // Restore pins to values in BoardGpioTable
  PIN_close(pinHandle);

  // Log data through UART
  uint8_t i;
  for(i = 0; i<SAMPLECOUNT; i++ ) {
    UART_write(uHandle, &adcSamples[i], SAMPLESIZE);

  }

  // Goto STANDBY forever
  Task_sleep(BIOS_WAIT_FOREVER);

}