Definition in file flash_example.c.
#include "compiler.h"
#include "print_funcs.h"
#include "board.h"
#include "power_clocks_lib.h"
#include "flashc.h"
Go to the source code of this file.
Data Structures | |
struct | nvram_data_t |
Structure type containing variables to store in NVRAM using a specific memory map. More... | |
Functions | |
static void | flash_rw_example (const char *caption, nvram_data_t *nvram_data) |
This is an example demonstrating flash read / write data accesses using the FLASHC driver. | |
int | main (void) |
Main function running the example on both the flash array and the User page. | |
static void | print_nvram_variables (nvram_data_t *nvram_data) |
Prints the variables stored in NVRAM. | |
Variables | |
static nvram_data_t | flash_nvram_data |
NVRAM data structure located in the flash array. | |
static nvram_data_t | user_nvram_data |
NVRAM data structure located in the User page. |
static void flash_rw_example | ( | const char * | caption, | |
nvram_data_t * | nvram_data | |||
) | [static] |
This is an example demonstrating flash read / write data accesses using the FLASHC driver.
caption | Caption to print before running the example. | |
nvram_data | Pointer to the NVRAM data structure to use in the example. |
Definition at line 167 of file flash_example.c.
References flashc_memcpy(), flashc_memset, and print_nvram_variables().
Referenced by main().
00168 { 00169 static const U8 write_data[8] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}; 00170 00171 print_dbg(caption); 00172 00173 print_dbg("Initial values of NVRAM variables:\n"); 00174 print_nvram_variables(nvram_data); 00175 00176 print_dbg("\nClearing NVRAM variables..."); 00177 flashc_memset((void *)nvram_data, 0x00, 8, sizeof(*nvram_data), TRUE); 00178 print_dbg("\nNVRAM variables cleared:\n"); 00179 print_nvram_variables(nvram_data); 00180 00181 print_dbg("\nWriting new values to NVRAM variables..."); 00182 flashc_memcpy((void *)&nvram_data->var8, &write_data, sizeof(nvram_data->var8), TRUE); 00183 flashc_memcpy((void *)&nvram_data->var16, &write_data, sizeof(nvram_data->var16), TRUE); 00184 flashc_memcpy((void *)&nvram_data->var8_3, &write_data, sizeof(nvram_data->var8_3), TRUE); 00185 flashc_memcpy((void *)&nvram_data->var32, &write_data, sizeof(nvram_data->var32), TRUE); 00186 print_dbg("\nNVRAM variables written:\n"); 00187 print_nvram_variables(nvram_data); 00188 }
int main | ( | void | ) |
Main function running the example on both the flash array and the User page.
Definition at line 194 of file flash_example.c.
References flash_nvram_data, flash_rw_example(), and user_nvram_data.
00195 { 00196 // Switch main clock to external oscillator 0 (crystal). 00197 pcl_switch_to_osc(PCL_OSC0, FOSC0, OSC0_STARTUP); 00198 00199 // Initialize the debug USART module. 00200 init_dbg_rs232(FOSC0); 00201 00202 // Apply the example to the flash array. 00203 flash_rw_example("\x0C=== Using a piece of the flash array as NVRAM ==================================\n", 00204 &flash_nvram_data); 00205 00206 // Apply the example to the User page. 00207 flash_rw_example("\n\n=== Using a piece of the User page as NVRAM ====================================\n", 00208 &user_nvram_data); 00209 00210 while (TRUE); 00211 }
static void print_nvram_variables | ( | nvram_data_t * | nvram_data | ) | [static] |
Prints the variables stored in NVRAM.
nvram_data | Pointer to the NVRAM data structure to print. |
Definition at line 141 of file flash_example.c.
References nvram_data_t::var16, nvram_data_t::var32, nvram_data_t::var8, and nvram_data_t::var8_3.
Referenced by flash_rw_example().
00142 { 00143 print_dbg("var8:\t0x"); 00144 print_dbg_char_hex(nvram_data->var8); 00145 00146 print_dbg("\nvar16:\t0x"); 00147 print_dbg_short_hex(nvram_data->var16); 00148 00149 print_dbg("\nvar8_3:\t0x"); 00150 print_dbg_char_hex(nvram_data->var8_3[0]); 00151 print_dbg_char_hex(nvram_data->var8_3[1]); 00152 print_dbg_char_hex(nvram_data->var8_3[2]); 00153 00154 print_dbg("\nvar32:\t0x"); 00155 print_dbg_hex(nvram_data->var32); 00156 00157 print_dbg_char('\n'); 00158 }
nvram_data_t flash_nvram_data [static] |
NVRAM data structure located in the flash array.
Definition at line 124 of file flash_example.c.
Referenced by main().
nvram_data_t user_nvram_data [static] |
NVRAM data structure located in the User page.
Definition at line 134 of file flash_example.c.
Referenced by main().