1 /* -------------------------------- Arctic Core ------------------------------
\r
2 * Arctic Core - the open source AUTOSAR platform http://arccore.com
\r
4 * Copyright (C) 2009 ArcCore AB <contact@arccore.com>
\r
6 * This source code is free software; you can redistribute it and/or modify it
\r
7 * under the terms of the GNU General Public License version 2 as published by the
\r
8 * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.
\r
10 * This program is distributed in the hope that it will be useful, but
\r
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\r
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
\r
14 * -------------------------------- Arctic Core ------------------------------*/
\r
18 * Just a simple example that uses the NvM API's.
\r
24 /* ----------------------------[includes]------------------------------------*/
\r
25 #include "Std_Types.h"
\r
30 #include "NvM_Cbk.h"
\r
35 /* ----------------------------[private define]------------------------------*/
\r
37 /* STD_ON - Block_2_Native will be written. Block_2_Native will only
\r
39 * STD_OFF - Block_2_Native's will be called at every startup since no
\r
40 * data is ever written to the block
\r
42 #define WRITE_BLOCK_2 STD_OFF
\r
44 /* ----------------------------[private macro]-------------------------------*/
\r
46 #define PATTERN_FILL(_block,_st_val) patternFill(_block,sizeof(_block),_st_val)
\r
47 #define PATTERN_VERIFY(_block,_st_val) patternVerify(_block,sizeof(_block),_st_val)
\r
49 #define BUSY_WAIT(_block,_var) \
\r
51 NvM_GetErrorStatus(_block, &_var); \
\r
52 } while( _var != NVM_REQ_OK );
\r
55 /* ----------------------------[private typedef]-----------------------------*/
\r
56 /* ----------------------------[private function prototypes]-----------------*/
\r
57 /* ----------------------------[private variables]---------------------------*/
\r
60 uint8 TEST_RamBlock_Dataset_0[20];
\r
61 uint8 TEST_RamBlock_Dataset_1[2];
\r
62 uint8 TEST_tmpRam[100];
\r
64 uint8 Block_2_RamBlock[10];
\r
66 /* ----------------------------[private functions]---------------------------*/
\r
68 static void nvmApplication(void);
\r
71 * Fill memory with a increasing number starting with startVal
\r
77 static void patternFill( uint8 *bPtr, uint32 numBytes, uint8 startVal )
\r
80 for(i=0;i< numBytes; i++) {
\r
81 bPtr[i] = startVal++;
\r
86 * Verify a pattern filled by patternFill.
\r
93 static int patternVerify( uint8 *bPtr, uint32 numBytes, uint8 startVal )
\r
96 for(i=0;i< numBytes; i++, startVal++) {
\r
97 if( bPtr[i] != startVal ) {
\r
106 /* ----------------------------[public functions]----------------------------*/
\r
108 void MultiBlock_Callback(uint8 ServiceId, NvM_RequestResultType JobResult) {
\r
116 void Block_Dataset_SingleCallback( void ) {
\r
123 void Block_2_InitCallback( void ) {
\r
124 PATTERN_FILL(Block_2_RamBlock,10);
\r
129 * The application task
\r
131 TASK(Application) {
\r
140 static void nvmApplication(void) {
\r
141 NvM_RequestResultType errorStatus;
\r
144 static int counter = 0;
\r
146 /* Verify that a block read during NvM_ReadAll() is there */
\r
147 rv = PATTERN_VERIFY(Block_2_RamBlock,10);
\r
150 currBlock = NVM_Block_1_Dataset_HANDLE;
\r
153 * Write some pattern to Dataset 0
\r
155 PATTERN_FILL(TEST_RamBlock_Dataset_0,0);
\r
156 NvM_WriteBlock(currBlock,TEST_RamBlock_Dataset_0);
\r
157 BUSY_WAIT(currBlock,&errorStatus);
\r
159 memset(TEST_RamBlock_Dataset_0,0,sizeof(TEST_RamBlock_Dataset_0));
\r
160 NvM_ReadBlock(currBlock,TEST_RamBlock_Dataset_0);
\r
161 BUSY_WAIT(currBlock,&errorStatus);
\r
163 rv = PATTERN_VERIFY(TEST_RamBlock_Dataset_0,0);
\r
167 * Write some pattern to Dataset 1
\r
169 rv = NvM_SetDataIndex(currBlock,1);
\r
170 assert( rv == E_OK );
\r
171 BUSY_WAIT(currBlock,&errorStatus);
\r
173 PATTERN_FILL(TEST_RamBlock_Dataset_0,5);
\r
174 NvM_WriteBlock(currBlock,TEST_RamBlock_Dataset_0);
\r
175 BUSY_WAIT(currBlock,&errorStatus);
\r
177 memset(TEST_RamBlock_Dataset_0,0,sizeof(TEST_RamBlock_Dataset_0));
\r
178 NvM_ReadBlock(currBlock,TEST_RamBlock_Dataset_0);
\r
179 BUSY_WAIT(currBlock,&errorStatus);
\r
181 rv = PATTERN_VERIFY(TEST_RamBlock_Dataset_0,5);
\r
186 * Back to Dataset 0 and check data.
\r
188 NvM_SetDataIndex(currBlock,0);
\r
189 assert( rv == E_OK );
\r
190 BUSY_WAIT(currBlock,&errorStatus);
\r
192 NvM_ReadBlock(currBlock,TEST_RamBlock_Dataset_0);
\r
193 BUSY_WAIT(currBlock,&errorStatus);
\r
195 rv = PATTERN_VERIFY(TEST_RamBlock_Dataset_0,0);
\r
199 #if (WRITE_BLOCK_2 == STD_ON)
\r
201 currBlock = NVM_Block_2_Native_HANDLE;
\r
203 rv = NvM_WriteBlock(currBlock,NULL);
\r
204 assert( rv == E_OK );
\r
207 NvM_GetErrorStatus(currBlock, &errorStatus);
\r
208 } while( errorStatus != NVM_REQ_OK );
\r