Platform library for RETRO
Embed:
(wiki syntax)
Show/hide line numbers
Utils.cpp
00001 /* 00002 * (C) Copyright 2015 Valentin Ivanov. All rights reserved. 00003 * 00004 * This file is part of the RetroPlatform Library 00005 * 00006 * The RetroPlatform Library is free software: you can redistribute it and/or modify 00007 * it under the terms of the GNU Lesser General Public License as published by 00008 * the Free Software Foundation, either version 3 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public License 00017 * along with this program. If not, see <http://www.gnu.org/licenses/> 00018 * 00019 * This library is inspired by Gamebuino Library (http://gamebuino.com) 00020 * from Aurélien Rodot. 00021 */ 00022 #include "mbed.h" 00023 #include "Utils.h" 00024 00025 uint8_t constrain(uint8_t val, uint8_t minimum, uint8_t maximum ) 00026 { 00027 if( val < minimum ) 00028 return minimum; 00029 if( val > maximum ) 00030 return maximum; 00031 00032 return val; 00033 } 00034 00035 uint8_t max(uint8_t val1, uint8_t val2 ) 00036 { 00037 if( val1 < val2 ) 00038 return val2; 00039 00040 return val1; 00041 } 00042 00043 uint8_t min(uint8_t val1, uint8_t val2 ) 00044 { 00045 if( val1 < val2 ) 00046 return val1; 00047 00048 return val2; 00049 } 00050 00051 #define IAP_LOCATION 0x1fff1ff1 00052 typedef void (*IAP_call)(unsigned int [], unsigned int []); 00053 00054 IAP_call iap_entry = reinterpret_cast<IAP_call>(IAP_LOCATION); 00055 unsigned int IAP_command[ 5 ]; 00056 unsigned int IAP_result[ 5 ]; 00057 00058 int write_eeprom( char *source_addr, char *target_addr, int size ) 00059 { 00060 IAP_command[ 0 ] = 61; 00061 IAP_command[ 1 ] = (unsigned int)target_addr; // Destination EEPROM address where data bytes are to be written. This address should be a 256 byte boundary. 00062 IAP_command[ 2 ] = (unsigned int)source_addr; // Source RAM address from which data bytes are to be read. This address should be a word boundary. 00063 IAP_command[ 3 ] = size; // Number of bytes to be written. Should be 256 | 512 | 1024 | 4096. 00064 IAP_command[ 4 ] = SystemCoreClock / 1000; // CPU Clock Frequency (CCLK) in kHz. 00065 00066 iap_entry( IAP_command, IAP_result ); 00067 00068 return ( (int)IAP_result[ 0 ] ); 00069 } 00070 00071 int read_eeprom( char *source_addr, char *target_addr, int size ) 00072 { 00073 IAP_command[ 0 ] = 62; 00074 IAP_command[ 1 ] = (unsigned int)source_addr; // Source EEPROM address from which data bytes are to be read. This address should be a word boundary. 00075 IAP_command[ 2 ] = (unsigned int)target_addr; // Destination RAM address where data bytes are to be written. This address should be a 256 byte boundary. 00076 IAP_command[ 3 ] = size; // Number of bytes to be written. Should be 256 | 512 | 1024 | 4096. 00077 IAP_command[ 4 ] = SystemCoreClock / 1000; // CPU Clock Frequency (CCLK) in kHz. 00078 00079 iap_entry( IAP_command, IAP_result ); 00080 00081 return ( (int)IAP_result[ 0 ] ); 00082 }
Generated on Tue Jul 12 2022 23:21:39 by 1.7.2