To call Azure Marketplace Translation (and Speech) service
Dependencies: EthernetInterface-FRDM HTTPClient-SSL R_BSP SDFileSystem TLV320_RBSP USBHost mbed-rtos mbed-src
RomRamFileSystem.h
00001 /******************************************************************************* 00002 * DISCLAIMER 00003 * This software is supplied by Renesas Electronics Corporation and is only 00004 * intended for use with Renesas products. No other uses are authorized. This 00005 * software is owned by Renesas Electronics Corporation and is protected under 00006 * all applicable laws, including copyright laws. 00007 * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING 00008 * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT 00009 * LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE 00010 * AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED. 00011 * TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS 00012 * ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE 00013 * FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR 00014 * ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE 00015 * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 00016 * Renesas reserves the right, without notice, to make changes to this software 00017 * and to discontinue the availability of this software. By using this software, 00018 * you agree to the additional terms and conditions found by accessing the 00019 * following link: 00020 * http://www.renesas.com/disclaimer* 00021 * Copyright (C) 2015 Renesas Electronics Corporation. All rights reserved. 00022 *******************************************************************************/ 00023 #ifndef MBED_ROMRAMFILESYSTEM_H 00024 #define MBED_ROMRAMFILESYSTEM_H 00025 00026 #include "FATFileSystem.h" 00027 00028 #define NUM_OF_SECTORS (1000) 00029 #define SECTOR_SIZE (512) 00030 00031 #if defined(TARGET_RZ_A1H) 00032 #define ROM_START_ADDRESS (0x18000000uL) // for GR-PEACH 00033 #define ROM_END_ADDRESS (0x1FFFFFFFuL) // for GR-PEACH 00034 #else 00035 #define ROM_START_ADDRESS (0xFFFFFFFFuL) 00036 #define ROM_END_ADDRESS (0xFFFFFFFFuL) 00037 #endif 00038 00039 using namespace mbed; 00040 00041 class RomRamFileSystem : public FATFileSystem { 00042 public: 00043 // NUM_OF_SECTORS sectors, each 512 bytes 00044 char *sectors[NUM_OF_SECTORS]; 00045 00046 RomRamFileSystem(const char* name) : FATFileSystem(name) { 00047 memset(sectors, 0, sizeof(sectors)); 00048 } 00049 00050 virtual ~RomRamFileSystem() { 00051 for (int i = 0; i < NUM_OF_SECTORS; i++) { 00052 if ((sectors[i] != NULL) && (isRomAddress(sectors[i]) == false)) { 00053 free(sectors[i]); 00054 } 00055 } 00056 } 00057 00058 // read a sector in to the buffer, return 0 if ok 00059 virtual int disk_read(uint8_t *buffer, uint64_t sector, uint8_t count) { 00060 for (uint64_t sec_no = sector; sec_no < (sector + count); sec_no++) { 00061 if (sectors[sec_no] == NULL) { 00062 // nothing allocated means sector is empty 00063 memset(buffer, 0, SECTOR_SIZE); 00064 } else { 00065 memcpy(buffer, sectors[sec_no], SECTOR_SIZE); 00066 } 00067 buffer += SECTOR_SIZE; 00068 } 00069 return 0; 00070 } 00071 00072 // write a sector from the buffer, return 0 if ok 00073 virtual int disk_write(const uint8_t *buffer, uint64_t sector, uint8_t count) { 00074 for (uint64_t sec_no = sector; sec_no < (sector + count); sec_no++) { 00075 bool all_zero = true; 00076 for (int i = 0; i < SECTOR_SIZE; i++) { 00077 if (buffer[i] != NULL) { 00078 all_zero = false; 00079 break; 00080 } 00081 } 00082 if (all_zero != false) { 00083 if (sectors[sec_no] != NULL) { 00084 if (isRomAddress(sectors[sec_no]) == false) { 00085 free(sectors[sec_no]); 00086 } 00087 sectors[sec_no] = NULL; 00088 } 00089 return 0; 00090 } 00091 // allocate a sector if needed, and write 00092 if (isRomAddress((char *)buffer) == false) { 00093 if ((sectors[sec_no] == NULL) || (isRomAddress(sectors[sec_no]) != false)) { 00094 char *sec = (char*)malloc(SECTOR_SIZE); 00095 if (sec == NULL) { 00096 return 1; // out of memory 00097 } 00098 sectors[sec_no] = sec; 00099 } 00100 memcpy(sectors[sec_no], buffer, SECTOR_SIZE); 00101 } else { 00102 if (isRomAddress(sectors[sec_no]) == false) { 00103 free(sectors[sec_no]); 00104 } 00105 sectors[sec_no] = (char *)buffer; 00106 } 00107 buffer += SECTOR_SIZE; 00108 } 00109 return 0; 00110 } 00111 00112 // return the number of sectors 00113 virtual uint64_t disk_sectors() { 00114 return NUM_OF_SECTORS; 00115 } 00116 00117 void dump(FILE *fp) { 00118 for (int i = 0; i < NUM_OF_SECTORS; i++) { 00119 fwrite(§ors[i], sizeof(int), 1, fp); 00120 if (sectors[i] != NULL) { 00121 fwrite(sectors[i], sizeof(char), SECTOR_SIZE, fp); 00122 } 00123 } 00124 } 00125 00126 void load(FILE *fp) { 00127 int sec_info = 0; 00128 for (int i = 0; i < NUM_OF_SECTORS; i++) { 00129 fread(&sec_info, sizeof(int), 1, fp); 00130 if (sec_info != 0) { 00131 char *sec = (char *)malloc(SECTOR_SIZE); 00132 fread(sec, sizeof(char), SECTOR_SIZE, fp); 00133 sectors[i] = sec; 00134 } 00135 } 00136 } 00137 00138 private: 00139 bool isRomAddress(char * address) { 00140 if (((uint32_t)address >= ROM_START_ADDRESS) 00141 && ((uint32_t)address <= (ROM_END_ADDRESS - SECTOR_SIZE + 1))) { 00142 return true; 00143 } 00144 return false; 00145 } 00146 }; 00147 #endif
Generated on Fri Jul 15 2022 04:07:23 by 1.7.2