bsp.c
236 lines
| 5.7 KiB
| text/x-c
|
CLexer
jeandet@pc-de-jeandet3.lab-lpp.local
|
r16 | /*------------------------------------------------------------------------------ | ||
-- This file is a part of the libuc, microcontroler library | ||||
-- Copyright (C) 2011, Alexis Jeandet | ||||
-- | ||||
-- This program is free software; you can redistribute it and/or modify | ||||
-- it under the terms of the GNU General Public License as published by | ||||
-- the Free Software Foundation; either version 3 of the License, or | ||||
-- (at your option) any later version. | ||||
-- | ||||
-- This program is distributed in the hope that it will be useful, | ||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
-- GNU General Public License for more details. | ||||
-- | ||||
-- You should have received a copy of the GNU General Public License | ||||
-- along with this program; if not, write to the Free Software | ||||
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||||
------------------------------------------------------------------------------- | ||||
-- Author : Alexis Jeandet | ||||
-- Mail : alexis.jeandet@gmail.com | ||||
-------------------------------------------------------------------------------*/ | ||||
#include "bsp.h" | ||||
#include "core.h" | ||||
unsigned int OSC0 =24000000; | ||||
unsigned int INTOSC =4000000; | ||||
unsigned int RTCOSC =32768; | ||||
unsigned int currentCpuFreq=0; | ||||
float VREF0 =(float)3.3; | ||||
uartDev UART0=(uartDev)0; | ||||
uartDev UART1=(uartDev)0; | ||||
uartDev UART2=(uartDev)0; | ||||
uartDev UART3=(uartDev)0; | ||||
i2cDev IIC0=(i2cDev)0; | ||||
i2cDev IIC1=(i2cDev)0; | ||||
i2cDev IIC2=(i2cDev)0; | ||||
sspDev SSP0=(sspDev)0; | ||||
sspDev SSP1=(sspDev)0; | ||||
sdcardDev SDCARD0; | ||||
blkdevice BLKDEVSDCARD0; | ||||
dikpartition PART0; | ||||
FAT32fs fs0; | ||||
ucdirent root; | ||||
ads1278Dev adc0; | ||||
eeprom24lc0xDev eeprom0; | ||||
#define __delay(t) for(volatile int i=0;i<t;i++); | ||||
int bsp_init() | ||||
{ | ||||
bsp_GPIO_init(); | ||||
LEDS_ON; | ||||
coresetCpuFreq(8000000); | ||||
currentCpuFreq=coregetCpuFreq(); | ||||
coresetCpuFreq(55 MHz); | ||||
currentCpuFreq=coregetCpuFreq(); | ||||
bsp_uart_init(); | ||||
//bsp_iic_init(); | ||||
bsp_ssp_init(); | ||||
bsp_SD_init(); | ||||
bsp_adc_init(); | ||||
return 0; | ||||
} | ||||
void bsp_GPIO_init() | ||||
{ | ||||
LPC_SC->PCONP |= ( 1 << 15 ); // power up GPIO | ||||
LPC_GPIO0->FIODIR |=(1<<15) + (1<<17) + (1<<18); | ||||
LEDS_OFF; | ||||
} | ||||
void bsp_uart_init() | ||||
{ | ||||
LPC_SC->PCONP |= ( 1 << 24 ); // power up UART3 | ||||
LPC_SC->PCONP |= ( 1 << 4 ); // power up UART1 | ||||
LPC_PINCON->PINSEL0 |= (1<<4); | ||||
LPC_PINCON->PINSEL0 &= ~(1<<5); | ||||
LPC_PINCON->PINSEL0 |= (1<<6); | ||||
LPC_PINCON->PINSEL0 &= ~(1<<7); | ||||
LPC_PINCON->PINSEL0 |= (1<<20); | ||||
LPC_PINCON->PINSEL0 &= ~(1<<21); | ||||
LPC_PINCON->PINSEL0 |= (1<<22); | ||||
LPC_PINCON->PINSEL0 &= ~(1<<23); | ||||
UART0= uartopen(0); | ||||
uartsetup(UART0,115200,8,1,uartNoParity); | ||||
UART2= uartopen(2); | ||||
uartsetup(UART2,115200,8,1,uartNoParity); | ||||
} | ||||
void bsp_ssp_init() | ||||
{ | ||||
SSP1 = sspopen(1); | ||||
ssppowerup(SSP1); | ||||
sspsetpclkfactor(SSP1,1); | ||||
sspsetup(SSP1,8,FFSPI|CLKINHLOW|CKfirstEdge,loopbackOFF|MASTERMODE, 22 MHz); | ||||
enableSSP(SSP1); | ||||
LPC_PINCON->PINSEL0 |= (2<<12); //SSEL1 on P0.6 | ||||
LPC_PINCON->PINSEL0 |= (2<<14); //SCK1 on P0.7 | ||||
LPC_PINCON->PINSEL0 |= (2<<16); //MISO1 on P0.8 | ||||
LPC_PINCON->PINSEL0 |= (2<<18); //MOSI1 on P0.9 | ||||
LPC_GPIO0->FIODIR |= (1<<6) + (1<<7) + (1<<9); | ||||
SSP0 = sspopen(0); | ||||
ssppowerup(SSP0); | ||||
sspsetpclkfactor(SSP0,1); | ||||
sspsetup(SSP0,8,FFSPI|CLKINHLOW|CKfirstEdge,loopbackOFF|MASTERMODE, 350000); | ||||
enableSSP(SSP0); | ||||
LPC_PINCON->PINSEL3 |= (3<<14); //MISO0 on P1.23 | ||||
LPC_PINCON->PINSEL3 |= (3<<16); //MOSI0 on P1.24 | ||||
LPC_PINCON->PINSEL3 |= (3<<8); //SCK0 on P1.20 | ||||
LPC_GPIO1->FIODIR |= (1<<24) + (1<<20); | ||||
LPC_PINCON->PINMODE3 &= ~(1<<14); | ||||
LPC_PINCON->PINMODE3 &= ~(1<<15); | ||||
//LPC_PINCON->PINSEL3 |= (3<<10); //SSEL0 on P1.21 disable for SDCARD -> need to send dummy clock | ||||
} | ||||
void bsp_iic_init() | ||||
{ | ||||
LPC_SC->PCONP |= ( 1 << 7 ); // power up IIC0 | ||||
LPC_PINCON->PINSEL1 |= (1<<22); | ||||
LPC_PINCON->PINSEL1 &= ~(1<<23); | ||||
LPC_PINCON->PINSEL1 |= (1<<24); | ||||
LPC_PINCON->PINSEL1 &= ~(1<<25); | ||||
IIC0 = i2copen(0); | ||||
i2csetdatarate(IIC0,100000); | ||||
eeprom24lc0xopen(&eeprom0,IIC0,0,2048); | ||||
} | ||||
void bsp_adc_init() | ||||
{ | ||||
LPC_GPIO0->FIODIR |=(1<<24); // ADS1278 Clkdiv pin on p0.24 | ||||
LPC_GPIO0->FIOSET = 1<<24; //Set ADS1278 Clkdiv pin to high freq mode | ||||
LPC_GPIO0->FIODIR |=(1<<23); // ADS1278 Synch pin on p0.23 | ||||
LPC_GPIO0->FIOSET = 1<<23; //Set ADS1278 Synch | ||||
LPC_GPIO2->FIODIR |=(1); // ADS1278 FSYNCH pin on p2.0 | ||||
LPC_GPIO2->FIOCLR =(1); | ||||
LPC_GPIO2->FIODIR |=(1<<1); // ADS1278 Mode1 pin on p2.1 | ||||
LPC_GPIO2->FIODIR |=(1<<2); // ADS1278 Mode0 pin on p2.2 | ||||
LPC_GPIO2->FIOSET = 1<<1; //High resolution mode Mode0=1 Mode1=0 | ||||
LPC_GPIO2->FIOCLR = 1<<2; | ||||
ads1278open(&adc0,SSP1); | ||||
} | ||||
void bsp_SD_init() | ||||
{ | ||||
LPC_GPIO1->FIODIR |=(1<<21); // SD card chip select on p1.19 | ||||
LPC_GPIO1->FIOSET = 1<<21; //unselect SD card | ||||
LPC_GPIO3->FIODIR &= ~(1<<25); | ||||
sdcardmake(&SDCARD0,SSP0,&sspgetnc,&sspputnc,&sspsetdatarate,&sspgetdatarate); | ||||
sdcardmakeblkdev(&BLKDEVSDCARD0,&SDCARD0,&bspsdcardselect,&bsppowersdcard,&bspsdcardpresent,&bspsdcardwriteprotected); | ||||
BLKDEVSDCARD0.initialize(&BLKDEVSDCARD0); | ||||
mbropen(&BLKDEVSDCARD0,&PART0,1); | ||||
fat32open(&fs0,&PART0); | ||||
fat32mkdirent(&fs0,&root); | ||||
} | ||||
void consoleputc(char c) | ||||
{ | ||||
uartputc(UART0,c); | ||||
} | ||||
char consolegetc() | ||||
{ | ||||
return uartgetc(UART0); | ||||
} | ||||
void vs10XXclearXCS(){} | ||||
void vs10XXsetXCS(){} | ||||
int vs10XXDREQ() | ||||
{ | ||||
return 1; | ||||
} | ||||
void bsppowersdcard(char onoff) //always ON | ||||
{ | ||||
} | ||||
char bspsdcardpresent() | ||||
{ | ||||
return (((LPC_GPIO3->FIOPIN >> 25) & 1) ^1); | ||||
} | ||||
char bspsdcardwriteprotected() | ||||
{ | ||||
return 0; | ||||
} | ||||
void bspsdcardselect(char YESNO) | ||||
{ | ||||
LPC_GPIO1->FIOPIN = ((YESNO & 1)^1)<<21; | ||||
} | ||||
void bsp_ads1278_Synch() | ||||
{ | ||||
LPC_GPIO0->FIOCLR = 1<<23; | ||||
for(volatile int i =0;i<5;i++); | ||||
LPC_GPIO0->FIOSET = 1<<23; | ||||
} | ||||
void bsp_ads1278_Sample() | ||||
{ | ||||
LPC_GPIO2->FIOCLR =(1); | ||||
LPC_GPIO2->FIOSET =(1); | ||||
for(volatile int i =0;i<5;i++); | ||||
LPC_GPIO2->FIOCLR =(1); | ||||
} | ||||
int bsp_ads1278_Ready() | ||||
{ | ||||
return !(LPC_GPIO2->FIOPIN & 1); | ||||
} | ||||