bsp_stk.c

Go to the documentation of this file.
00001 /***************************************************************************/
00018 #include <string.h>
00019 #include "em_device.h"
00020 #include "em_cmu.h"
00021 #include "em_gpio.h"
00022 #include "bsp.h"
00023 #if defined( BSP_STK_USE_EBI )
00024 #include "em_ebi.h"
00025 #endif
00026 
00027 #if defined( BSP_STK )
00028 
00029 
00030 /***************************************************************************/
00035 /***************************************************************************/
00041 /**************************************************************************/
00047 int BSP_Disable(void)
00048 {
00049   BSP_BccDeInit();
00050   BSP_EbiDeInit();
00051 
00052   return BSP_STATUS_OK;
00053 }
00056 /**************************************************************************/
00064 int BSP_EbiInit(void)
00065 {
00066 #if defined( BSP_STK_USE_EBI )
00067   /* ------------------------------------------ */
00068   /* NAND Flash, Bank0, Base Address 0x80000000 */
00069   /* Micron flash NAND256W3A                    */
00070   /* ------------------------------------------ */
00071 
00072   EBI_Init_TypeDef ebiConfig =
00073   {   ebiModeD8A8,       /* 8 bit address, 8 bit data */
00074       ebiActiveLow,      /* ARDY polarity */
00075       ebiActiveLow,      /* ALE polarity */
00076       ebiActiveLow,      /* WE polarity */
00077       ebiActiveLow,      /* RE polarity */
00078       ebiActiveLow,      /* CS polarity */
00079       ebiActiveLow,      /* BL polarity */
00080       false,             /* disble BL */
00081       true,              /* enable NOIDLE */
00082       false,             /* disable ARDY */
00083       true,              /* disable ARDY timeout */
00084       EBI_BANK0,         /* enable bank 0 */
00085       0,                 /* no chip select */
00086       0,                 /* addr setup cycles */
00087       0,                 /* addr hold cycles */
00088       false,             /* disable half cycle ALE strobe */
00089       0,                 /* read setup cycles */
00090       2,                 /* read strobe cycles */
00091       1,                 /* read hold cycles */
00092       false,             /* disable page mode */
00093       false,             /* disable prefetch */
00094       false,             /* disable half cycle REn strobe */
00095       0,                 /* write setup cycles */
00096       2,                 /* write strobe cycles */
00097       1,                 /* write hold cycles */
00098       false,             /* enable the write buffer */
00099       false,             /* disable half cycle WEn strobe */
00100       ebiALowA24,        /* ALB - Low bound, address lines */
00101       ebiAHighA26,       /* APEN - High bound, address lines */
00102       ebiLocation1,      /* Use Location 1 */
00103       true,              /* enable EBI */
00104   };
00105 
00106   /* Enable clocks */
00107   CMU_ClockEnable(cmuClock_HFPER, true);
00108   CMU_ClockEnable(cmuClock_GPIO, true);
00109   CMU_ClockEnable(cmuClock_EBI, true);
00110 
00111   /* Enable GPIO's */
00112   /* ALE and CLE */
00113   GPIO_PinModeSet(gpioPortC, 1, gpioModePushPull, 0);
00114   GPIO_PinModeSet(gpioPortC, 2, gpioModePushPull, 0);
00115 
00116   /* WP, CE and R/B */
00117   GPIO_PinModeSet(gpioPortD, 13, gpioModePushPull, 0);   /* active low write-protect */
00118   GPIO_PinModeSet(gpioPortD, 14, gpioModePushPull, 1);   /* active low chip-enable */
00119   GPIO_PinModeSet(gpioPortD, 15, gpioModeInput, 0);      /* ready/busy */
00120 
00121   /* IO pins */
00122   GPIO_PinModeSet(gpioPortE, 8, gpioModePushPull, 0);
00123   GPIO_PinModeSet(gpioPortE, 9, gpioModePushPull, 0);
00124   GPIO_PinModeSet(gpioPortE, 10, gpioModePushPull, 0);
00125   GPIO_PinModeSet(gpioPortE, 11, gpioModePushPull, 0);
00126   GPIO_PinModeSet(gpioPortE, 12, gpioModePushPull, 0);
00127   GPIO_PinModeSet(gpioPortE, 13, gpioModePushPull, 0);
00128   GPIO_PinModeSet(gpioPortE, 14, gpioModePushPull, 0);
00129   GPIO_PinModeSet(gpioPortE, 15, gpioModePushPull, 0);
00130 
00131   /* WE and RE */
00132   GPIO_PinModeSet(gpioPortF, 8, gpioModePushPull, 1);
00133   GPIO_PinModeSet(gpioPortF, 9, gpioModePushPull, 1);
00134 
00135   /* NAND Power Enable */
00136   GPIO_PinModeSet(gpioPortB, 15, gpioModePushPull, 1);
00137 
00138   EBI_Init(&ebiConfig);
00139   EBI->NANDCTRL = (EBI_NANDCTRL_BANKSEL_BANK0 | EBI_NANDCTRL_EN);
00140 
00141   return BSP_STATUS_OK;
00142 #else
00143   return BSP_STATUS_NOT_IMPLEMENTED;
00144 #endif
00145 }
00146 
00147 /**************************************************************************/
00157 int BSP_EbiDeInit( void )
00158 {
00159 #if defined( BSP_STK_USE_EBI )
00160   return BSP_STATUS_OK;
00161 #else
00162   return BSP_STATUS_NOT_IMPLEMENTED;
00163 #endif
00164 }
00165 
00167 /**************************************************************************/
00175 int BSP_Init( uint32_t flags )
00176 {
00177   if ( flags & BSP_INIT_BCC )
00178   {
00179     BSP_BccInit();
00180   }
00181 
00182   return BSP_STATUS_OK;
00183 }
00186 /**************************************************************************/
00196 float BSP_CurrentGet( void )
00197 {
00198    BCP_Packet pkt;
00199    float      *pcurrent;
00200 
00201    pkt.type          = BSP_BCP_CURRENT_REQ;
00202    pkt.payloadLength = 0;
00203 
00204    /* Send Request/Get reply */
00205    BSP_BccPacketSend( &pkt );
00206    BSP_BccPacketReceive( &pkt );
00207 
00208    /* Process reply */
00209    pcurrent = (float *)pkt.data;
00210    if ( pkt.type != BSP_BCP_CURRENT_REPLY )
00211    {
00212       *pcurrent = 0.0f;
00213    }
00214 
00215    return *pcurrent;
00216 }
00217 
00218 /**************************************************************************/
00228 float BSP_VoltageGet( void )
00229 {
00230    BCP_Packet pkt;
00231    float      *pvoltage;
00232 
00233    pkt.type          = BSP_BCP_VOLTAGE_REQ;
00234    pkt.payloadLength = 0;
00235 
00236    /* Send Request/Get reply */
00237    BSP_BccPacketSend( &pkt );
00238    BSP_BccPacketReceive( &pkt );
00239 
00240    /* Process reply */
00241    pvoltage = (float *)pkt.data;
00242    if ( pkt.type != BSP_BCP_VOLTAGE_REPLY )
00243    {
00244       *pvoltage = 0.0f;
00245    }
00246 
00247    return *pvoltage;
00248 }
00249 
00253 #endif /* BSP_STK */