PokittoLib is the library needed for programming the Pokitto DIY game console (www.pokitto.com)

Dependents:   YATTT sd_map_test cPong SnowDemo ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers PokittoClock.cpp Source File

PokittoClock.cpp

Go to the documentation of this file.
00001 /**************************************************************************/
00002 /*!
00003     @file     PokittoClock.cpp
00004     @author   Jonne Valola
00005 
00006     @section LICENSE
00007 
00008     Software License Agreement (BSD License)
00009 
00010     Copyright (c) 2015, Jonne Valola
00011     All rights reserved.
00012 
00013     Redistribution and use in source and binary forms, with or without
00014     modification, are permitted provided that the following conditions are met:
00015     1. Redistributions of source code must retain the above copyright
00016     notice, this list of conditions and the following disclaimer.
00017     2. Redistributions in binary form must reproduce the above copyright
00018     notice, this list of conditions and the following disclaimer in the
00019     documentation and/or other materials provided with the distribution.
00020     3. Neither the name of the copyright holders nor the
00021     names of its contributors may be used to endorse or promote products
00022     derived from this software without specific prior written permission.
00023 
00024     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
00025     EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00026     WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00027     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
00028     DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00029     (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00030     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00031     ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00032     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00033     SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00034 */
00035 /**************************************************************************/
00036 
00037 #include "PokittoCore.h "
00038 #include "pinmap.h"
00039 #include "HWLCD.h "
00040 #include "Pokitto_settings.h "
00041 #include "wait_api.h"
00042 
00043 uint32_t pt_count=0;
00044 uint32_t* ptimer;
00045 
00046 extern "C" {
00047 void SysTick_Handler(void) {
00048     //interrupt happens when systick has counted down to zero
00049     #if PROJ_GAMEBOY > 0
00050     uint32_t a;
00051     a = *ptimer;
00052     *ptimer = a + 1;
00053     #endif
00054     pt_count+=10;                        // increment counter
00055 }}
00056 
00057 using namespace Pokitto;
00058 
00059 uint32_t Core::refreshtime;
00060 
00061 void Core::initClock() {
00062         // to get 1000 interrupts per second the reload value should be 48000
00063     #if PROJ_GAMEBOY > 0
00064     ptimer = &pt_count;
00065     SysTick->LOAD = 480000-1;
00066     #else
00067     #ifdef _OSCT
00068     SysTick->LOAD = (480000*3/_OSCT)-1;
00069     #else
00070     SysTick->LOAD = 480000-1;
00071     #endif
00072     #endif
00073     SysTick->VAL  = 0;
00074     SysTick->CTRL  = 4 | 2 | 1; //CLKSOURCE=CPU clock | TICKINT | ENABLE
00075     pt_count = 0;
00076 }
00077 
00078 uint32_t Core::getTime() {
00079     return pt_count;
00080 }
00081 
00082 void Core::wait(uint16_t ms) {
00083     wait_ms(ms);
00084 }
00085 
00086