bsp_stk.c

Go to the documentation of this file.
00001 /***************************************************************************/
00035 #include <string.h>
00036 #include "em_device.h"
00037 #include "em_cmu.h"
00038 #include "em_gpio.h"
00039 #include "bsp.h"
00040 #if defined( BSP_STK_USE_EBI )
00041 #include "em_ebi.h"
00042 #endif
00043 
00044 #if defined( BSP_STK )
00045 
00046 
00047 /***************************************************************************/
00052 /***************************************************************************/
00058 /**************************************************************************/
00064 int BSP_Disable(void)
00065 {
00066   BSP_BccDeInit();
00067   BSP_EbiDeInit();
00068 
00069   return BSP_STATUS_OK;
00070 }
00073 /**************************************************************************/
00081 int BSP_EbiInit(void)
00082 {
00083 #if defined( BSP_STK_USE_EBI )
00084   /* ------------------------------------------ */
00085   /* NAND Flash, Bank0, Base Address 0x80000000 */
00086   /* Micron flash NAND256W3A                    */
00087   /* ------------------------------------------ */
00088 
00089   EBI_Init_TypeDef ebiConfig =
00090   {   ebiModeD8A8,       /* 8 bit address, 8 bit data */
00091       ebiActiveLow,      /* ARDY polarity */
00092       ebiActiveLow,      /* ALE polarity */
00093       ebiActiveLow,      /* WE polarity */
00094       ebiActiveLow,      /* RE polarity */
00095       ebiActiveLow,      /* CS polarity */
00096       ebiActiveLow,      /* BL polarity */
00097       false,             /* disble BL */
00098       true,              /* enable NOIDLE */
00099       false,             /* disable ARDY */
00100       true,              /* disable ARDY timeout */
00101       EBI_BANK0,         /* enable bank 0 */
00102       0,                 /* no chip select */
00103       0,                 /* addr setup cycles */
00104       0,                 /* addr hold cycles */
00105       false,             /* disable half cycle ALE strobe */
00106       0,                 /* read setup cycles */
00107       2,                 /* read strobe cycles */
00108       1,                 /* read hold cycles */
00109       false,             /* disable page mode */
00110       false,             /* disable prefetch */
00111       false,             /* disable half cycle REn strobe */
00112       0,                 /* write setup cycles */
00113       2,                 /* write strobe cycles */
00114       1,                 /* write hold cycles */
00115       false,             /* enable the write buffer */
00116       false,             /* disable half cycle WEn strobe */
00117       ebiALowA24,        /* ALB - Low bound, address lines */
00118       ebiAHighA26,       /* APEN - High bound, address lines */
00119       ebiLocation1,      /* Use Location 1 */
00120       true,              /* enable EBI */
00121   };
00122 
00123   /* Enable clocks */
00124   CMU_ClockEnable(cmuClock_HFPER, true);
00125   CMU_ClockEnable(cmuClock_GPIO, true);
00126   CMU_ClockEnable(cmuClock_EBI, true);
00127 
00128   /* Enable GPIO's */
00129   /* ALE and CLE */
00130   GPIO_PinModeSet(gpioPortC, 1, gpioModePushPull, 0);
00131   GPIO_PinModeSet(gpioPortC, 2, gpioModePushPull, 0);
00132 
00133   /* WP, CE and R/B */
00134   GPIO_PinModeSet(gpioPortD, 13, gpioModePushPull, 0);   /* active low write-protect */
00135   GPIO_PinModeSet(gpioPortD, 14, gpioModePushPull, 1);   /* active low chip-enable */
00136   GPIO_PinModeSet(gpioPortD, 15, gpioModeInput, 0);      /* ready/busy */
00137 
00138   /* IO pins */
00139   GPIO_PinModeSet(gpioPortE, 8, gpioModePushPull, 0);
00140   GPIO_PinModeSet(gpioPortE, 9, gpioModePushPull, 0);
00141   GPIO_PinModeSet(gpioPortE, 10, gpioModePushPull, 0);
00142   GPIO_PinModeSet(gpioPortE, 11, gpioModePushPull, 0);
00143   GPIO_PinModeSet(gpioPortE, 12, gpioModePushPull, 0);
00144   GPIO_PinModeSet(gpioPortE, 13, gpioModePushPull, 0);
00145   GPIO_PinModeSet(gpioPortE, 14, gpioModePushPull, 0);
00146   GPIO_PinModeSet(gpioPortE, 15, gpioModePushPull, 0);
00147 
00148   /* WE and RE */
00149   GPIO_PinModeSet(gpioPortF, 8, gpioModePushPull, 1);
00150   GPIO_PinModeSet(gpioPortF, 9, gpioModePushPull, 1);
00151 
00152   /* NAND Power Enable */
00153   GPIO_PinModeSet(gpioPortB, 15, gpioModePushPull, 1);
00154 
00155   EBI_Init(&ebiConfig);
00156   EBI->NANDCTRL = (EBI_NANDCTRL_BANKSEL_BANK0 | EBI_NANDCTRL_EN);
00157 
00158   return BSP_STATUS_OK;
00159 #else
00160   return BSP_STATUS_NOT_IMPLEMENTED;
00161 #endif
00162 }
00163 
00164 /**************************************************************************/
00174 int BSP_EbiDeInit( void )
00175 {
00176 #if defined( BSP_STK_USE_EBI )
00177   return BSP_STATUS_OK;
00178 #else
00179   return BSP_STATUS_NOT_IMPLEMENTED;
00180 #endif
00181 }
00182 
00184 /**************************************************************************/
00192 int BSP_Init( uint32_t flags )
00193 {
00194   if ( flags & BSP_INIT_BCC )
00195   {
00196     BSP_BccInit();
00197   }
00198 
00199   return BSP_STATUS_OK;
00200 }
00203 /**************************************************************************/
00213 float BSP_CurrentGet( void )
00214 {
00215    BCP_Packet pkt;
00216    float      *pcurrent;
00217 
00218    pkt.type          = BSP_BCP_CURRENT_REQ;
00219    pkt.payloadLength = 0;
00220 
00221    /* Send Request/Get reply */
00222    BSP_BccPacketSend( &pkt );
00223    BSP_BccPacketReceive( &pkt );
00224 
00225    /* Process reply */
00226    pcurrent = (float *)pkt.data;
00227    if ( pkt.type != BSP_BCP_CURRENT_REPLY )
00228    {
00229       *pcurrent = 0.0f;
00230    }
00231 
00232    return *pcurrent;
00233 }
00234 
00235 /**************************************************************************/
00245 float BSP_VoltageGet( void )
00246 {
00247    BCP_Packet pkt;
00248    float      *pvoltage;
00249 
00250    pkt.type          = BSP_BCP_VOLTAGE_REQ;
00251    pkt.payloadLength = 0;
00252 
00253    /* Send Request/Get reply */
00254    BSP_BccPacketSend( &pkt );
00255    BSP_BccPacketReceive( &pkt );
00256 
00257    /* Process reply */
00258    pvoltage = (float *)pkt.data;
00259    if ( pkt.type != BSP_BCP_VOLTAGE_REPLY )
00260    {
00261       *pvoltage = 0.0f;
00262    }
00263 
00264    return *pvoltage;
00265 }
00266 
00270 #endif /* BSP_STK */