Sam Shi / Mbed 2 deprecated unytefont

Dependencies:   Adafruit_GFX_customizedfont BLE_API USBDevice mbed

Fork of mbed-os-example-mbed5-blinky by mbed-os-examples

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers flc.c Source File

flc.c

00001 /*******************************************************************************
00002  * Copyright (C) 2014 Maxim Integrated Products, Inc., All Rights Reserved.
00003  *
00004  * Permission is hereby granted, free of charge, to any person obtaining a
00005  * copy of this software and associated documentation files (the "Software"),
00006  * to deal in the Software without restriction, including without limitation
00007  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00008  * and/or sell copies of the Software, and to permit persons to whom the
00009  * Software is furnished to do so, subject to the following conditions:
00010  *
00011  * The above copyright notice and this permission notice shall be included
00012  * in all copies or substantial portions of the Software.
00013  *
00014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00015  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00016  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00017  * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
00018  * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00019  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00020  * OTHER DEALINGS IN THE SOFTWARE.
00021  *
00022  * Except as contained in this notice, the name of Maxim Integrated 
00023  * Products, Inc. shall not be used except as stated in the Maxim Integrated 
00024  * Products, Inc. Branding Policy.
00025  *
00026  * The mere transfer of this software does not imply any licenses
00027  * of trade secrets, proprietary technology, copyrights, patents,
00028  * trademarks, maskwork rights, or any other form of intellectual
00029  * property whatsoever. Maxim Integrated Products, Inc. retains all 
00030  * ownership rights.
00031  *******************************************************************************
00032  */
00033 
00034 /* $Revision: 3277 $ $Date: 2014-10-02 13:39:01 -0500 (Thu, 02 Oct 2014) $ */
00035 
00036 #include "./mxc_config.h"
00037 
00038 #include <stdint.h>
00039 #include <string.h>
00040 
00041 #include "./flc.h "
00042 #include "./icc_regs.h"
00043 
00044 
00045 int32_t FLC_Erase(uint32_t address, uint8_t erase_code, uint8_t unlock_key)
00046 {
00047     if(!MXC_ICC->ctrl_stat_f.enable) {
00048         return -1;
00049     }
00050 
00051     mxc_flc_ctrl_t fcntl = MXC_FLC->ctrl_f;
00052     fcntl.erase_code = 0; /* clear erase code */
00053     fcntl.auto_incre_mode = 0; /* clear burst */
00054     MXC_FLC->ctrl_f = fcntl;
00055 
00056     fcntl.flsh_unlock = unlock_key;
00057     fcntl.erase_code = erase_code;
00058     MXC_FLC->ctrl_f = fcntl;
00059 
00060     MXC_FLC->faddr = (address & MXC_FLC_PAGE_ERASE_MSK); /* set bank address */
00061 
00062     fcntl = MXC_FLC->ctrl_f;
00063     fcntl.page_erase = 1; /* set and start erase operation */
00064     MXC_FLC->ctrl_f = fcntl;
00065     
00066     do {
00067         fcntl = MXC_FLC->ctrl_f;
00068     } while (fcntl.pending); /* wait until done */
00069     
00070     fcntl = MXC_FLC->ctrl_f;
00071     fcntl.erase_code = 0; /* lock flash */
00072     fcntl.flsh_unlock = 0;
00073     MXC_FLC->ctrl_f = fcntl;
00074 
00075     return 0;
00076 }
00077 
00078 int32_t FLC_WriteBlock(uint32_t address, const void *data, uint32_t length, uint8_t unlock_key)
00079 {
00080     uint32_t *word = (uint32_t *) data;
00081 
00082     if(!MXC_ICC->ctrl_stat_f.enable) {
00083         return -1;
00084     }
00085 
00086     if(address & 3) { /* address needs to be aligned with word */
00087         return -1;
00088     }
00089 
00090     length = length & 0xfffffffc;
00091 
00092     mxc_flc_ctrl_t fcntl = MXC_FLC->ctrl_f;
00093     fcntl.erase_code = 0; /* clear erase code */
00094     fcntl.auto_incre_mode = 0; /* clear burst */
00095     MXC_FLC->ctrl_f = fcntl;
00096 
00097     fcntl.flsh_unlock = unlock_key; /* set unlock */
00098     MXC_FLC->ctrl_f = fcntl;
00099 
00100     while (length)
00101     {
00102         MXC_FLC->faddr = address;
00103         MXC_FLC->fdata = *word;
00104         
00105         fcntl = MXC_FLC->ctrl_f;
00106         fcntl.write = 1;
00107         MXC_FLC->ctrl_f = fcntl;
00108 
00109         address += 4;
00110         word++;
00111         length -= 4;
00112 
00113         do {
00114             fcntl = MXC_FLC->ctrl_f;
00115         } while (fcntl.pending);
00116     }
00117 
00118     fcntl = MXC_FLC->ctrl_f;
00119     fcntl.erase_code = 0; /* lock flash */
00120     fcntl.flsh_unlock = 0;
00121     MXC_FLC->ctrl_f = fcntl;
00122 
00123     return 0;
00124 }
00125