bsp.c
174 lines
| 4.2 KiB
| text/x-c
|
CLexer
r6 | /*------------------------------------------------------------------------------ | |||
-- 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 =12000000; | ||||
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; | ||||
r10 | sspDev* SSP0=(sspDev*)0; | |||
sspDev* SSP1=(sspDev*)0; | ||||
sdcardDev SDCARD0; | ||||
blkdevice BLKDEVSDCARD0; | ||||
eeprom24lc0xDev eeprom0; | ||||
r6 | int bsp_init() | |||
{ | ||||
bsp_GPIO_init(); | ||||
coresetCpuFreq(20000000); | ||||
currentCpuFreq=coregetCpuFreq(); | ||||
coresetCpuFreq(60000000); | ||||
currentCpuFreq=coregetCpuFreq(); | ||||
bsp_uart_init(); | ||||
bsp_iic_init(); | ||||
r10 | bsp_ssp_init(); | |||
bsp_SD_init(); | ||||
r6 | return 0; | |||
} | ||||
void bsp_GPIO_init() | ||||
{ | ||||
LPC_SC->PCONP |= ( 1 << 15 ); // power up GPIO | ||||
LPC_GPIO2->FIODIR |=255; | ||||
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,38400,8,1,uartNoParity); | ||||
UART2= uartopen(2); | ||||
uartsetup(UART2,38400,8,1,uartNoParity); | ||||
} | ||||
r10 | void bsp_ssp_init() | |||
{ | ||||
SSP0 = sspopen(0); // power up SSP0 | ||||
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 | ||||
} | ||||
r6 | 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); | ||||
r10 | eeprom24lc0xopen(&eeprom0,IIC0,0,2048); | |||
} | ||||
void bsp_SD_init() | ||||
{ | ||||
LPC_GPIO1->FIODIR |=1<<21; //SD chip select on P1.21 | ||||
LPC_GPIO1->FIOSET = 1<<21; //unselect SD card | ||||
LPC_GPIO3->FIODIR |=1<<26; | ||||
LPC_GPIO3->FIODIR &= ~(1<<25); | ||||
LPC_GPIO3->FIOCLR |=1<<26; | ||||
sdcardmake(&SDCARD0,SSP0,&sspgetnc,&sspputnc,&sspsetdatarate); | ||||
sdcardmakeblkdev(&BLKDEVSDCARD0,&SDCARD0,&bspsdcardselect,&bsppowersdcard,&bspsdcardpresent,&bspsdcardwriteprotected); | ||||
//BLKDEVSDCARD0.initialize(&BLKDEVSDCARD0,0); | ||||
r6 | } | |||
void consoleputc(char c) | ||||
{ | ||||
uartputc(UART0,c); | ||||
} | ||||
char consolegetc() | ||||
{ | ||||
return uartgetc(UART0); | ||||
} | ||||
r10 | 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; | ||||
} | ||||