A library implementing IEEE 802.15.4 PHY functionality for the MCR20A transceiver. The PHY sublayer provides two services: the PHY data service and the PHY management service interfacing to the PHY sublayer management entity (PLME) service access point (SAP) (known as PLME-SAP). The PHY data service enables the transmission and reception of PHY protocol data units (PSDUs) over the media (radio).

Fork of fsl_phy_mcr20a by Freescale

The Freescale PHY Layer deals with the physical burst which is to be sent and/or received. It performs modulation and demodulation, transmitter and receiver switching, fragmentation, scrambling, interleaving, and error correction coding. The communication to the upper protocol layers is carried out through the Layer 1 Interface.

The PHY Layer is capable of executing the following sequences:

  • I (Idle)
  • R (Receive Sequence conditionally followed by a TxAck)
  • T (Transmit Sequence)
  • C (Standalone CCA)
  • CCCA (Continuous CCA)
  • TR (Transmit/Receive Sequence - transmit unconditionally followed by either an R or RxAck)

In addition to these sequences the PHY Layer also integrates a packet processor which determines whether the packet is MAC-compliant, and if it is, whether it is addressed to the end device. Another feature of the packet processor is Source Address Matching which can be viewed as an extension of packet filtering; however its function is very specific to its intended application (data-polling and indirect queue management by a PAN Coordinator).

Documentation

MCR20A PHY Reference Manual

PHY/PhyInterface.h

Committer:
andreikovacs
Date:
2015-08-18
Revision:
0:764779eedf2d

File content as of revision 0:764779eedf2d:

/*!
* Copyright (c) 2015, Freescale Semiconductor, Inc.
* All rights reserved.
*
* \file PhyInterface.h
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* o Redistributions of source code must retain the above copyright notice, this list
*   of conditions and the following disclaimer.
*
* o Redistributions in binary form must reproduce the above copyright notice, this
*   list of conditions and the following disclaimer in the documentation and/or
*   other materials provided with the distribution.
*
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
*   contributors may be used to endorse or promote products derived from this
*   software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef _PHY_INTERFACE_H
#define _PHY_INTERFACE_H


/************************************************************************************
*************************************************************************************
* Include
*************************************************************************************
************************************************************************************/

#include "PhyTypes.h"
//#include "Messaging.h"
#include "PhyConfig.h"

/************************************************************************************
*************************************************************************************
* Public macros
*************************************************************************************
************************************************************************************/

/* Constants */
#ifndef gMaxPhyTimers_c
#define gMaxPhyTimers_c                 (5)
#endif

#ifdef gPHY_802_15_4g_d
#define gPhySeqStartAsap_c              (0xFFFFFFFFFFFFFFFF)
#else
#define gPhySeqStartAsap_c              (0xFFFFFFFF)
#endif

/* XCVR active/idle power modes */
#define gPhyDefaultActivePwrMode_c gPhyPwrAutodoze_c /* Do not change! */
#define gPhyDefaultIdlePwrMode_c   gPhyPwrAutodoze_c

/************************************************************************************
*************************************************************************************
* Public prototypes
*************************************************************************************
************************************************************************************/

/************************************************************************************
*************************************************************************************
* Public type definitions
*************************************************************************************
************************************************************************************/

typedef enum
{
#include "PhyMessages.h"
}phyMessageId_t;

typedef enum{
    gPhyPwrIdle_c,
    gPhyPwrAutodoze_c,
    gPhyPwrDoze_c,
    gPhyPwrHibernate_c,
    gPhyPwrReset_c
}phyPwrMode_t;

typedef  struct pdDataReq_tag
{ 
    phyTime_t               startTime;  // absolute  
    uint32_t                txDuration; // relative
    phySlottedMode_t        slottedTx;
    phyCCAType_t            CCABeforeTx;
    phyAckRequired_t        ackRequired;
    uint8_t                 psduLength;
#ifdef gPHY_802_15_4g_d 
    phyPHR_t                phyHeader;
    uint8_t                 macDataIndex;
    uint8_t                 fillFifoBlockLength;    
#endif  // gPHY_802_15_4g_d 
    uint8_t *               pPsdu; 
} pdDataReq_t;

typedef  struct pdDataCnf_tag
{
    phyStatus_t             status;
} pdDataCnf_t;

typedef  struct pdDataInd_tag
{
    phyTimeTimestamp_t      timeStamp;
    uint8_t                 ppduLinkQuality;
    uint8_t                 psduLength;
    uint8_t *               pPsdu;
#ifdef gPHY_802_15_4g_d 
    uint32_t                crcValue;
    bool_t                  crcValid;
#endif
} pdDataInd_t;

typedef  struct pdIndQueueInsertReq_tag
{
    uint8_t                 index;
    uint16_t                checksum;
} pdIndQueueInsertReq_t;

typedef  struct pdIndQueueInsertCnf_tag
{
    phyStatus_t             status;
} pdIndQueueInsertCnf_t;

typedef  struct pdIndQueueRemoveReq_tag
{
    uint8_t                 index;
} pdIndQueueRemoveReq_t;

typedef  struct plmeEdReq_tag
{
    phyTime_t               startTime;  // absolute
} plmeEdReq_t;

typedef  struct plmeCcaReq_tag
{
    phyCCAType_t            ccaType;
    phyContCCAMode_t        contCcaMode;
} plmeCcaReq_t;

typedef  struct plmeCcaCnf_tag
{
    phyStatus_t             status;
} plmeCcaCnf_t;

typedef  struct plmeEdCnf_tag
{
    phyStatus_t             status;
    uint8_t                 energyLevel;
    uint8_t                 energyLeveldB;
} plmeEdCnf_t;

typedef  struct plmeSetTRxStateReq_tag
{
    phyState_t              state;
    phySlottedMode_t        slottedMode;
    phyTime_t               startTime;   // absolute
    uint32_t                rxDuration;  // relative
} plmeSetTRxStateReq_t;

typedef struct phyTimeEvent_tag
{
    phyTimeTimestamp_t timestamp; // absolute
    phyTimeCallback_t  callback;
    uint32_t           parameter;
}phyTimeEvent_t;

typedef  struct plmeSetTRxStateCnf_tag
{
    phyStatus_t             status;
} plmeSetTRxStateCnf_t;

typedef  struct plmeSetReq_tag
{
    phyPibId_t              PibAttribute;
    uint64_t                PibAttributeValue;
} plmeSetReq_t;

typedef  struct plmeSetCnf_tag
{
    phyStatus_t             status;
    phyPibId_t              PibAttribute;
} plmeSetCnf_t;

typedef  struct plmeGetReq_tag
{
    phyPibId_t              PibAttribute;
    uint64_t *              pPibAttributeValue;
} plmeGetReq_t;

typedef  struct plmeGetCnf_tag
{
    phyStatus_t             status;
    phyPibId_t              PibAttribute;
    uint64_t                PibAttributeValue;
} plmeGetCnf_t;

typedef  struct macToPlmeMessage_tag
{
    phyMessageId_t             msgType;
    uint8_t                    macInstance;
    union
    {
        plmeEdReq_t                edReq;
        plmeCcaReq_t               ccaReq;
        plmeSetTRxStateReq_t       setTRxStateReq;
        plmeSetReq_t               setReq;
        plmeGetReq_t               getReq;
    }msgData;
} macToPlmeMessage_t;

typedef  struct macToPdDataMessage_tag
{
    phyMessageId_t             msgType;
    uint8_t                    macInstance;
    union
    {
        pdDataReq_t             dataReq;
        pdIndQueueInsertReq_t   indQueueInsertReq;
        pdIndQueueRemoveReq_t   indQueueRemoveReq;
    }msgData;
} macToPdDataMessage_t;

typedef  struct plmeToMacMessage_tag
{
    phyMessageId_t             msgType;
    uint8_t                    macInstance;
    union
    {
        plmeCcaCnf_t            ccaCnf;
        plmeEdCnf_t             edCnf;
        plmeSetTRxStateCnf_t    setTRxStateCnf;
        plmeSetCnf_t            setCnf;
        plmeGetCnf_t            getCnf;
    }msgData;
} plmeToMacMessage_t;

typedef  struct pdDataToMacMessage_tag
{
    phyMessageId_t             msgType;
    uint8_t                    macInstance;
    union
    {
        pdDataCnf_t             dataCnf;
        pdDataInd_t             dataInd;
        pdIndQueueInsertCnf_t   indQueueInsertCnf;
    }msgData;
} pdDataToMacMessage_t;

typedef  struct phyMessageHeader_tag
{
    phyMessageId_t             msgType;
    uint8_t                    macInstance;
} phyMessageHeader_t;

typedef struct phyRxParams_tag {
    phyTime_t   timeStamp;
    uint8_t     psduLength;
    uint8_t     linkQuality;
#ifdef gPHY_802_15_4g_d     
    uint8_t     headerLength; 
    uint8_t     macDataIndex;
    uint8_t     unfillFifoBlockLength;  
    phyPHR_t    phyHeader;
#else
    phySlottedMode_t phyRxMode;
    pdDataToMacMessage_t *pRxData;
#endif  // gPHY_802_15_4g_d  
} phyRxParams_t;

typedef struct phyChannelParams_tag {
    union{
        phyStatus_t channelStatus;
        uint8_t     energyLeveldB;
    };
#ifdef gPHY_802_15_4g_d
    uint8_t     ccaThreshold;
    uint8_t     ccaParam;
#endif   // gPHY_802_15_4g_d    
} phyChannelParams_t;

typedef struct phyTxParams_tag {
  uint8_t           numOfCca;
  phyAckRequired_t  ackRequired;
} phyTxParams_t;

typedef phyStatus_t ( * PD_MAC_SapHandler_t)(pdDataToMacMessage_t * pMsg, instanceId_t instanceId);

typedef phyStatus_t ( * PLME_MAC_SapHandler_t)(plmeToMacMessage_t * pMsg, instanceId_t instanceId);

#ifdef __cplusplus
extern "C" {
#endif 

/************************************************************************************
*************************************************************************************
* Public memory declarations
*************************************************************************************
************************************************************************************/
extern const uint8_t gPhyIndirectQueueSize_c;

/************************************************************************************
*************************************************************************************
* Public functions
*************************************************************************************
************************************************************************************/

void Phy_Init( void );

instanceId_t BindToPHY( instanceId_t macInstance );

// SAPs
void Phy_RegisterSapHandlers(PD_MAC_SapHandler_t pPD_MAC_SapHandler, PLME_MAC_SapHandler_t pPLME_MAC_SapHandler, instanceId_t instanceId);

phyStatus_t MAC_PD_SapHandler(macToPdDataMessage_t * pMsg, instanceId_t phyInstance);

phyStatus_t MAC_PLME_SapHandler(macToPlmeMessage_t * pMsg, instanceId_t phyInstance);

// PHY Time
void PhyTime_Maintenance ( void );

void PhyTime_RunCallback ( void );

void PhyTime_ISR         ( void );

phyTimeStatus_t PhyTime_TimerInit ( void (*cb)(void) );

phyTimeTimestamp_t PhyTime_GetTimestamp ( void );

phyTimeTimerId_t   PhyTime_ScheduleEvent( phyTimeEvent_t *pEvent );

phyTimeStatus_t    PhyTime_CancelEvent  ( phyTimeTimerId_t timerId );

phyTimeStatus_t    PhyTime_CancelEventsWithParam ( uint32_t param );

#ifdef __cplusplus
}
#endif 
    
#endif  /* _PHY_INTERFACE_H */