Simulated product dispenser

Dependencies:   HTS221

Fork of mbed-cloud-workshop-connect-HTS221 by Jim Carver

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers pal_plat_internalFlash.cpp Source File

pal_plat_internalFlash.cpp

00001 /*******************************************************************************
00002  * Copyright 2016, 2017 ARM Ltd.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  *******************************************************************************/
00016 
00017 #include "mbed.h"
00018 #include "flash_api.h"
00019 #include "pal.h"
00020 #include "pal_plat_internalFlash.h"
00021 
00022 
00023 ////////////////////////////PRIVATE///////////////////////////////////
00024 PAL_PRIVATE FlashIAP flash;
00025 PAL_PRIVATE palStatus_t pal_platFlashErrorTranslation(int32_t status);
00026 ////////////////////////////END PRIVATE////////////////////////////////
00027 
00028 palStatus_t pal_plat_internalFlashInit(void)
00029 {
00030     uint32_t status = 0;
00031     palStatus_t ret = PAL_SUCCESS;
00032     status = flash.init();
00033     if (status != 0)
00034     {
00035         ret = pal_platFlashErrorTranslation(status);
00036     }
00037     return ret;
00038 }
00039 
00040 
00041 palStatus_t pal_plat_internalFlashDeInit(void)
00042 {
00043     uint32_t status = 0;
00044     palStatus_t ret = PAL_SUCCESS;
00045     status = flash.deinit();
00046     if (status != 0)
00047     {
00048         ret = pal_platFlashErrorTranslation(status);
00049     }
00050     return ret;
00051 }
00052 
00053 
00054 palStatus_t pal_plat_internalFlashWrite(const size_t size, const uint32_t address, const uint32_t * buffer)
00055 {
00056     uint32_t status = 0;
00057     palStatus_t ret = PAL_SUCCESS;
00058 
00059     status = flash.program(buffer, address, size);
00060     if (status != 0)
00061     {
00062         ret = pal_platFlashErrorTranslation(status);
00063     }
00064     return ret;
00065 }
00066 
00067 
00068 palStatus_t pal_plat_internalFlashRead(const size_t size, const uint32_t address, uint32_t * buffer)
00069 {
00070     uint32_t status = 0;
00071     palStatus_t ret = PAL_SUCCESS;
00072     status = flash.read(buffer, address, size);
00073     if (status != 0)
00074     {
00075         ret = pal_platFlashErrorTranslation(status);
00076     }
00077     return ret;
00078 }
00079 
00080 
00081 palStatus_t pal_plat_internalFlashErase(uint32_t address, size_t size)
00082 {
00083     uint32_t status = 0;
00084     palStatus_t ret = PAL_SUCCESS;
00085 
00086     status = flash.erase(address, size);
00087     if (status != 0)
00088     {
00089         ret = pal_platFlashErrorTranslation(status);
00090     }
00091     return ret;
00092 }
00093 
00094 
00095 size_t pal_plat_internalFlashGetPageSize(void)
00096 {
00097     size_t ret = flash.get_page_size();
00098     return ret;
00099 }
00100 
00101 
00102 size_t pal_plat_internalFlashGetSectorSize(uint32_t address)
00103 {
00104     size_t ret = flash.get_sector_size(address);
00105     return ret;
00106 }
00107 
00108 
00109 PAL_PRIVATE palStatus_t pal_platFlashErrorTranslation(int32_t status)
00110 {
00111     return PAL_ERR_INTERNAL_FLASH_GENERIC_FAILURE;//ALL mbedOS error are -1
00112 }
00113