/******************************************************************
*  Copyright (C) 2009 Ram Narula  
*  Filename: generalInit.h
*  Version: 0.1
*  Date: 14 July 2009
*  Information: http://www.xduino.com/    
******************************************************************/
/******************************************************************
*   This file is part of Xduino
*
*   Xduino is free software: you can redistribute it and/or modify
*   it under the terms of the GNU Lesser General Public License as published by
*   the Free Software Foundation, either version 3 of the License, or
*   (at your option) any later version.
*	
*   Xduino 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 Lesser General Public License for more details.
*
*   You should have received a copy of the GNU Lesser General Public License
*   along with Xduino.  If not, see .
******************************************************************/


// load this library only once
#ifndef generalInit_h
#define generalInit_h


/* Includes --- initialization provided by STMicroelectronics */
/* Include files are in C format (not C++) */
extern "C" {
	#include "stm32f10x_lib.h"
	void TimingDelay_Decrement(void);
}
ErrorStatus HSEStartUpStatus;
#include "STMicro.h"

/* get array size */ 
template
int ARRAYSIZE(T(&)[size]){return size;}

vu32 TimingDelay;	//for using on timer interrupt for delay functions

// function prototype
void doInit(void);

/* General initialization no input, no output */
void doInit(void)
{
	RCC_Configuration();   
	NVIC_Configuration();
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); 
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); 
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE); 
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);
	//My board has pins upto GPIOD if your board has more you can add more lines
}


void TimingDelay_Decrement(void)
{
  if (TimingDelay) TimingDelay--;
} 

#endif