Пример #1
0
// -----------------------------------------------------------------------------
//! \brief   Creates a queue node and puts the node in RTOS queue.
//!
//! \param   msgQueue - queue handle.
//! \param   sem - thread's event processing semaphore that queue is
//!                associated with.
//! \param   pMsg - pointer to message to be queued
//!
//! \return  TRUE if message was queued, FALSE otherwise.
// -----------------------------------------------------------------------------
uint8_t NPIUtil_enqueueMsg(Queue_Handle msgQueue, Semaphore_Handle sem,
                           uint8_t *pMsg)
{
  queueRec_t *pRec;
  
  // Allocated space for queue node.
  if (pRec = NPIUTIL_MALLOC(sizeof(queueRec_t)))
  {
    pRec->pData = pMsg;
  
    Queue_enqueue(msgQueue, &pRec->_elem);
    
    // Wake up the application thread event handler.
    if (sem)
    {
      Semaphore_post(sem);
    }
    
    return TRUE;
  }
  
  // Free the message.
  NPIUTIL_FREE(pMsg);
  
  return FALSE;
}
Пример #2
0
// -----------------------------------------------------------------------------
//! \brief      This routine initializes the transport layer and opens the port
//!             of the device. Note that based on project defines, either the
//!             UART, or SPI driver can be used.
//!
//! \param[in]  params - Transport Layer parameters
//!
//! \return     void
// -----------------------------------------------------------------------------
void NPITL_openTL(NPITL_Params *params)
{
    _npiCSKey_t key;
    key = NPIUtil_EnterCS();
    
    // Set NPI Task Call backs
    memcpy(&taskCBs, &params->npiCallBacks, sizeof(params->npiCallBacks));
    
    // Allocate memory for Transport Layer Tx/Rx buffers
    npiBufSize = params->npiTLBufSize;
    npiRxBuf = NPIUTIL_MALLOC(params->npiTLBufSize);
    memset(npiRxBuf, 0, npiBufSize);
    npiTxBuf = NPIUTIL_MALLOC(params->npiTLBufSize);
    memset(npiTxBuf, 0, npiBufSize);

    // This will be updated to be able to select SPI/UART TL at runtime
    // Now only compile time with the NPI_USE_[UART,SPI] flag

#if defined(NPI_USE_UART)
#elif defined(NPI_USE_SPI)
    transportOpen(params->portBoardID, 
                  &params->portParams.spiParams, 
                  NPITL_transmissionCallBack);
#endif //NPI_USE_UART
    
	hNpiHandshakePins = PIN_open(&npiHandshakePins, npiHandshakePinsCfg);
	PIN_registerIntCb(hNpiHandshakePins, NPITL_remRdyPINHwiFxn);
	PIN_setConfig(hNpiHandshakePins,
				  PIN_BM_IRQ,
				  Board_UART_RX | PIN_IRQ_BOTHEDGES);

	// Enable wakeup
	PIN_setConfig(hNpiHandshakePins,
				  PINCC26XX_BM_WAKEUP,
				  Board_UART_RX | PINCC26XX_WAKEUP_NEGEDGE);
#ifdef NPI_SW_HANDSHAKING_DEBUG
	hNpiProfilingDebugPin= PIN_open(&npiProfilingDebugPin, npiProfilingDebugPinCfg);
#endif //NPI_SW_HANDSHAKING_DEBUG

	npiTLParams = *params;	//Keep a copy of TLParams local to the TL so that the UART can be closed/reopened
#ifndef POWER_SAVING
    // This call will start repeated Uart Reads when Power Savings is disabled
    transportRead();
#endif 

    NPIUtil_ExitCS(key);
}
Пример #3
0
// -----------------------------------------------------------------------------
//! \brief      This routine initializes the transport layer and opens the port
//!             of the device. Note that based on project defines, either the
//!             UART, or SPI driver can be used.
//!
//! \param[in]  params - Transport Layer parameters
//!
//! \return     void
// -----------------------------------------------------------------------------
void NPITL_openTL(NPITL_Params *params)
{
    _npiCSKey_t key;
    key = NPIUtil_EnterCS();
    
    // Set NPI Task Call backs
    memcpy(&taskCBs, &params->npiCallBacks, sizeof(params->npiCallBacks));
    
    // Allocate memory for Transport Layer Tx/Rx buffers
    npiBufSize = params->npiTLBufSize;
    npiRxBuf = NPIUTIL_MALLOC(params->npiTLBufSize);
    memset(npiRxBuf, 0, npiBufSize);
    npiTxBuf = NPIUTIL_MALLOC(params->npiTLBufSize);
    memset(npiTxBuf, 0, npiBufSize);
    
    
    hNpiUartRxPin = PIN_open(&npiUartRxPin, npiUartRxPinCfg);
    PIN_registerIntCb(hNpiUartRxPin, NPITL_rxPinHwiFxn);
    PIN_setConfig(hNpiUartRxPin, 
                  PIN_BM_IRQ, 
                  Board_UART_RX | PIN_IRQ_BOTHEDGES);

    // Enable wakeup
    PIN_setConfig(hNpiUartRxPin, 
                  PINCC26XX_BM_WAKEUP, 
                  Board_UART_RX | PINCC26XX_WAKEUP_NEGEDGE);
    //Note that open TL is only called when NPI task is being initialized
    //transportLayerState variable defaults to closed.
#ifdef SWHS_DEBUG  
    //Open Profiling Pin if in debug mode 
    hNpiProfilingPin = PIN_open(&npiProfilingPin, npiProfilingPinCfg);
#endif //SWHS_DEBUG
    //Keep a copy of TLParams local to the TL so that the UART can be closed/reopened
    npiTLParams = *params;
    //Here we will initialize the transport which will setup the callbacks
    //This call does not open the UART
    transportInit( &npiTLParams.portParams.uartParams, 
                   NPITL_transmissionCallBack,
                   NPITL_handshakeCompleteCallBack);
    
    NPIUtil_ExitCS(key);
}
// -----------------------------------------------------------------------------
//! \brief   Creates a queue node and puts the node in RTOS queue.
//!
//! \param   msgQueue - queue handle.
//! \param   event - thread's event processing synchronization object that
//!                  queue is associated with.
//! \param   eventFlag - events to signal with synchronization object associated
//!                      with this pMsg.
//! \param   sem - thread's event processing semaphore that queue is
//!                associated with.
//! \param   pMsg - pointer to message to be queued
//!
//! \return  TRUE if message was queued, FALSE otherwise.
// -----------------------------------------------------------------------------
uint8_t NPIUtil_enqueueMsg(Queue_Handle msgQueue, 
#ifdef ICALL_EVENTS
                           Event_Handle event,
                           uint32_t eventFlags,
#else //!ICALL_EVENTS
                           Semaphore_Handle sem,
#endif //ICALL_EVENTS
                           uint8_t *pMsg)
{
  queueRec_t *pRec;
  
  // Allocated space for queue node.
  if (pRec = NPIUTIL_MALLOC(sizeof(queueRec_t)))
  {
    pRec->pData = pMsg;
  
    Queue_enqueue(msgQueue, &pRec->_elem);
    
    // Wake up the application thread event handler.
#ifdef ICALL_EVENTS
    if (event)
    {
      Event_post(event, eventFlags);
    }
#else //!ICALL_EVENTS
    if (sem)
    {
      Semaphore_post(sem);
    }
#endif //ICALL_EVENTS
    
    return TRUE;
  }
  
  // Free the message.
  NPIUTIL_FREE(pMsg);
  
  return FALSE;
}
// -----------------------------------------------------------------------------
//! \brief      This routine initializes the transport layer and opens the port
//!             of the device. Note that based on project defines, either the
//!             UART, or SPI driver can be used.
//!
//! \param[in]  params - Transport Layer parameters
//!
//! \return     void
// -----------------------------------------------------------------------------
void NPITL_openTL(NPITL_Params *params)
{
    _npiCSKey_t key;
    key = NPIUtil_EnterCS();
    
    // Set NPI Task Call backs
    memcpy(&taskCBs, &params->npiCallBacks, sizeof(params->npiCallBacks));
    
    // Allocate memory for Transport Layer Tx/Rx buffers
    npiBufSize = params->npiTLBufSize;
    npiRxBuf = NPIUTIL_MALLOC(params->npiTLBufSize);
    memset(npiRxBuf, 0, npiBufSize);
    npiTxBuf = NPIUTIL_MALLOC(params->npiTLBufSize);
    memset(npiTxBuf, 0, npiBufSize);

    // This will be updated to be able to select SPI/UART TL at runtime
    // Now only compile time with the NPI_USE_[UART,SPI] flag
#if defined(NPI_USE_UART)
    transportOpen(params->portBoardID, 
                  &params->portParams.uartParams, 
                  NPITL_transmissionCallBack);
#elif defined(NPI_USE_SPI)
    transportOpen(params->portBoardID, 
                  &params->portParams.spiParams, 
                  NPITL_transmissionCallBack);
#endif //NPI_USE_UART
    
#if (NPI_FLOW_CTRL == 1)
    // Assign PIN IDs to remRdy and locRrdy
#ifdef NPI_MASTER
    remRdyPIN = (params->srdyPinID & IOC_IOID_MASK);
    locRdyPIN = (params->mrdyPinID & IOC_IOID_MASK);
#else
    remRdyPIN = (params->mrdyPinID & IOC_IOID_MASK);
    locRdyPIN = (params->srdyPinID & IOC_IOID_MASK);
#endif //NPI_MASTER
    
    // Add PIN IDs to PIN Configuration
    npiHandshakePinsCfg[REM_RDY_PIN_IDX] |= remRdyPIN;
    npiHandshakePinsCfg[LOC_RDY_PIN_IDX] |= locRdyPIN;
    
    // Initialize LOCRDY/REMRDY. Enable int after callback registered
    hNpiHandshakePins = PIN_open(&npiHandshakePins, npiHandshakePinsCfg);
    PIN_registerIntCb(hNpiHandshakePins, NPITL_remRdyPINHwiFxn);
    PIN_setConfig(hNpiHandshakePins, 
                  PIN_BM_IRQ, 
                  remRdyPIN | PIN_IRQ_BOTHEDGES);

    // Enable wakeup
    PIN_setConfig(hNpiHandshakePins, 
                  PINCC26XX_BM_WAKEUP, 
                  remRdyPIN | PINCC26XX_WAKEUP_NEGEDGE);
    
    remRdy_state = PIN_getInputValue(remRdyPIN);
    
    // If MRDY is already low then we must initiate a read because there was
    // a prior MRDY negedge that was missed
    if (!remRdy_state) 
    {
        NPITL_setPM();
        if (taskCBs.remRdyCB)
        {
            transportRemRdyEvent();
            LocRDY_ENABLE();
        }
    }
#endif // NPI_FLOW_CTRL = 1

#if (NPI_FLOW_CTRL == 0)
    // This call will start repeated Uart Reads when Power Savings is disabled
    transportRead();
#endif // NPI_FLOW_CTRL = 0

    NPIUtil_ExitCS(key);
}