#include "iap_driver.h"
#include "driver_config.h"
#include "uart.h"
/* Flash offset where the configuration is stored */
#define CONFIG_FLASH_OFFSET 0x1000
#define CONFIG_FLASH_SECTOR (CONFIG_FLASH_OFFSET >> 12)
#define CONFIG_FLASH_SECTOR_SIZE 1
#define CONFIG_FLASH_OFFSET2 0x2000
#define CONFIG_FLASH_SECTOR2 (CONFIG_FLASH_OFFSET >> 12)
#define CONFIG_FLASH_SECTOR_SIZE2 1
static uint8_t demo_messg[] = "Dane zapamietane przez IAP";
static uint8_t dana = 9;
int main(void)
{
__e_iap_status iap_status;
uint8_t *wsk;
uint8_t liczba = 0;
char *tmp_tekst;
int8_t tmp[2];
UARTInit(115200);
/* Init the IAP driver */
iap_init();
// --- Zapamietanie demo_messg --- //
/* Prepare the sector for erase */
iap_status = (__e_iap_status) iap_prepare_sector(CONFIG_FLASH_SECTOR,
(CONFIG_FLASH_SECTOR + CONFIG_FLASH_SECTOR_SIZE));
if (iap_status != CMD_SUCCESS)
UARTSend( "Prepre error\n\r", sizeof("Prepre error\n\r") );
/* Erase the sector */
iap_status = (__e_iap_status) iap_erase_sector(CONFIG_FLASH_SECTOR,
(CONFIG_FLASH_SECTOR + CONFIG_FLASH_SECTOR_SIZE));
if (iap_status != CMD_SUCCESS)
UARTSend( "Erase sector\n\r", sizeof("Erase sector\r\n") );
/* Prepare the sector for writing */
iap_status = (__e_iap_status) iap_prepare_sector(CONFIG_FLASH_SECTOR,
(CONFIG_FLASH_SECTOR + CONFIG_FLASH_SECTOR_SIZE));
if (iap_status != CMD_SUCCESS)
UARTSend( "Prepre sector write error\n\r", sizeof("Prepre sector write error\n\r") );
/* Write data to flash */
iap_status = (__e_iap_status) iap_copy_ram_to_flash(&demo_messg,
(void *)CONFIG_FLASH_OFFSET, 256);
if (iap_status != CMD_SUCCESS)
UARTSend( "Write error\n\r", sizeof("Write error\n\r") );
// --- Zapamietanie dana --- //
/* Prepare the sector for erase */
iap_status = (__e_iap_status) iap_prepare_sector(CONFIG_FLASH_SECTOR2,
(CONFIG_FLASH_SECTOR2 + CONFIG_FLASH_SECTOR_SIZE2));
if (iap_status != CMD_SUCCESS)
UARTSend( "Prepre error\n\r", sizeof("Prepre error\n\r") );
/* Erase the sector */
iap_status = (__e_iap_status) iap_erase_sector(CONFIG_FLASH_SECTOR2,
(CONFIG_FLASH_SECTOR2 + CONFIG_FLASH_SECTOR_SIZE2));
if (iap_status != CMD_SUCCESS)
UARTSend( "Erase sector\n\r", sizeof("Erase sector\r\n") );
/* Prepare the sector for writing */
iap_status = (__e_iap_status) iap_prepare_sector(CONFIG_FLASH_SECTOR2,
(CONFIG_FLASH_SECTOR2 + CONFIG_FLASH_SECTOR_SIZE2));
if (iap_status != CMD_SUCCESS)
UARTSend( "Prepre sector write error\n\r", sizeof("Prepre sector write error\n\r") );
iap_status = (__e_iap_status) iap_copy_ram_to_flash(&dana,
(void *)CONFIG_FLASH_OFFSET2, 256);
if (iap_status != CMD_SUCCESS)
UARTSend( "Write error\n\r", sizeof("Write error\n\r") );
// --- Wyswietlenie tekstu zapamietanego --- ///
wsk = (uint8_t *) CONFIG_FLASH_OFFSET;
UARTSend( "Zapamietany tekst: ", sizeof("Zapamietany tekst: ") );
tmp_tekst = wsk;
UARTSend( tmp_tekst, sizeof("Dane zapamietane przez IAP") );
UARTSend( "\n\r", sizeof("\n\r") );
// --- Wyswietlenie liczby zapamietanej --- ///
wsk = (uint8_t *) CONFIG_FLASH_OFFSET2;
liczba = *wsk;
// zamiana liczby na tekst
tmp[0] = '0' + liczba;
tmp[1] ='\0';
UARTSend( "Zapamietana liczba: ", sizeof("Zapamietana liczba: ") );
UARTSend( tmp, 2 );
if ( *wsk == 9)
UARTSend( "dziewiec\n\r", sizeof("dziewiec\n\r") );
else
UARTSend( "Nie dziewiec\n\r", sizeof("Nie dziewiec\n\r") );
while(1)
{
}
return 0 ;
}
|