bsp.c
100 lines
| 2.7 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; | ||||
int bsp_init() | ||||
{ | ||||
bsp_GPIO_init(); | ||||
coresetCpuFreq(20000000); | ||||
currentCpuFreq=coregetCpuFreq(); | ||||
coresetCpuFreq(60000000); | ||||
currentCpuFreq=coregetCpuFreq(); | ||||
bsp_uart_init(); | ||||
bsp_iic_init(); | ||||
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); | ||||
} | ||||
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); | ||||
} | ||||
void consoleputc(char c) | ||||
{ | ||||
uartputc(UART0,c); | ||||
} | ||||
char consolegetc() | ||||
{ | ||||
return uartgetc(UART0); | ||||
} | ||||