NXP / fsl_phy_mcr20a

Fork of fsl_phy_mcr20a by Freescale

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers XcvrSpi.cpp Source File

XcvrSpi.cpp

00001 /*!
00002 * Copyright (c) 2015, Freescale Semiconductor, Inc.
00003 * All rights reserved.
00004 *
00005 * \file XcvrSpi.c
00006 *
00007 * Redistribution and use in source and binary forms, with or without modification,
00008 * are permitted provided that the following conditions are met:
00009 *
00010 * o Redistributions of source code must retain the above copyright notice, this list
00011 *   of conditions and the following disclaimer.
00012 *
00013 * o Redistributions in binary form must reproduce the above copyright notice, this
00014 *   list of conditions and the following disclaimer in the documentation and/or
00015 *   other materials provided with the distribution.
00016 *
00017 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
00018 *   contributors may be used to endorse or promote products derived from this
00019 *   software without specific prior written permission.
00020 *
00021 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00022 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00023 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00024 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
00025 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00026 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00027 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
00028 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00029 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00030 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00031 */
00032 
00033 
00034 /*****************************************************************************
00035 *                               INCLUDED HEADERS                            *
00036 *---------------------------------------------------------------------------*
00037 * Add to this section all the headers that this module needs to include.    *
00038 * Note that it is not a good practice to include header files into header   *
00039 * files, so use this section only if there is no other better solution.     *
00040 *---------------------------------------------------------------------------*
00041 *****************************************************************************/
00042 
00043 #include "mbed.h"
00044 #include "EmbeddedTypes.h "
00045 
00046 #if defined(TARGET_K64F)
00047   SPI spi(PTD2, PTD3, PTD1);
00048 #elif defined(TARGET_NUCLEO_F401RE)
00049   SPI spi(SPI_MOSI, SPI_MISO, SPI_SCK);
00050 #else
00051   "SPI not defined for this platform"
00052 #endif
00053 
00054 DigitalOut RF_CS(D10);
00055 DigitalOut RF_RST(D5);          
00056 DigitalOut RF_SLP_TR(D7);       // Not used in FSL
00057 InterruptIn RF_IRQ (D2);        // FSL              //(D9); // Atmel Radio
00058 DigitalIn RF_IRQ_PIN (D2);
00059 
00060 extern "C" void PHY_InterruptHandler(void);
00061     
00062 extern "C" void RF_IRQ_Init(void) {
00063     RF_IRQ.mode(PullUp);
00064     RF_IRQ.fall(&PHY_InterruptHandler);
00065 }
00066 
00067 extern "C" void RF_IRQ_Enable(void) {
00068     RF_IRQ.enable_irq();
00069 }
00070 extern "C" void RF_IRQ_Disable(void) {
00071     RF_IRQ.disable_irq();
00072 }
00073 
00074 extern "C" bool_t RF_isIRQ_Pending(void) {
00075         return !RF_IRQ_PIN.read();
00076 }
00077 
00078 extern "C" void RF_RST_Set(int state) {
00079     RF_RST = state;
00080 }
00081 
00082 extern "C" void RF_SLP_TR_Set(int state) {
00083     RF_SLP_TR = state;
00084 }
00085 
00086 extern "C" void RF_CS_while_active(void) {
00087     
00088     while(!RF_CS);
00089 }
00090 
00091 /*****************************************************************************
00092 *                             PRIVATE MACROS                                *
00093 *---------------------------------------------------------------------------*
00094 * Add to this section all the access macros, registers mappings, bit access *
00095 * macros, masks, flags etc ...
00096 *---------------------------------------------------------------------------*
00097 *****************************************************************************/
00098 
00099 /*****************************************************************************/
00100 /*****************************************************************************/
00101 extern "C" void spi_master_init(uint32_t instance)
00102 {
00103 
00104 }
00105 
00106 /*****************************************************************************/
00107 /*****************************************************************************/
00108 extern "C" void spi_master_configure_speed(uint32_t instance, uint32_t freq)
00109 {
00110     //spi.frequency(8000000);
00111         spi.frequency(freq);
00112 }
00113 
00114 /*****************************************************************************/
00115 /*****************************************************************************/
00116 extern "C" void spi_master_transfer(uint32_t instance,
00117                          uint8_t * sendBuffer,
00118                          uint8_t * receiveBuffer,
00119                          size_t transferByteCount)
00120 {
00121     volatile uint8_t dummy;
00122 
00123     if( !transferByteCount )
00124         return;
00125 
00126     if( !sendBuffer && !receiveBuffer )
00127         return;
00128 
00129     while( transferByteCount-- )
00130     {
00131         if( sendBuffer )
00132         {
00133             dummy = *sendBuffer;
00134             sendBuffer++;
00135         }
00136         else
00137         {
00138             dummy = 0xFF;
00139         }
00140 
00141         dummy = spi.write(dummy);
00142         
00143         if( receiveBuffer )
00144         {
00145             *receiveBuffer = dummy;
00146             receiveBuffer++;
00147         }
00148     }
00149 }
00150 
00151 extern "C" void gXcvrAssertCS_d(void)
00152 {
00153     RF_CS = 0;
00154 }
00155 
00156 extern "C" void gXcvrDeassertCS_d(void)
00157 {
00158     RF_CS = 1;
00159 }