src/nvram.c
author dejoigny
Tue, 16 May 2006 17:21:14 +0200
changeset 7 126e37bcca0f
parent 0 4472ee7c6c3e
permissions -rw-r--r--
ajout filtrage msgs
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     1
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     2
This file is part of CanFestival, a library implementing CanOpen Stack.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     3
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     4
 Author: CANopen Canada (canfestival@canopencanada.ca)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     5
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     6
See COPYING file for copyrights details.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     7
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     8
This library is free software; you can redistribute it and/or
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     9
modify it under the terms of the GNU Lesser General Public
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    10
License as published by the Free Software Foundation; either
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    11
version 2.1 of the License, or (at your option) any later version.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    12
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    13
This library is distributed in the hope that it will be useful,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    14
but WITHOUT ANY WARRANTY; without even the implied warranty of
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    16
Lesser General Public License for more details.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    17
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    18
You should have received a copy of the GNU Lesser General Public
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    19
License along with this library; if not, write to the Free Software
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    20
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    21
*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    22
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    23
	nvram.c
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    24
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    25
	save the content of the dictionnary into non-volatile memory
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    26
	the order of storage must be the same as the order of retrieving
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    27
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    28
	note (1)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    29
	may need to store/retrieve specific data from non-volatile
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    30
	in that case, we need to address where it is stored
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    31
	without storing the address in a vector
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    32
	- solution 1 : walk throught the list without action until the
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    33
	sought object is found.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    34
	 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    35
*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    36
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    37
#include <stdio.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    38
#include <data.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    39
#include <applicfg.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    40
#include <objdictdef.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    41
#include "can_driver.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    42
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    43
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    44
int canSaveData(indextable *dict, int max_index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    45
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    46
	int i, j;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    47
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    48
	if (nvram_open() < 0)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    49
		return -1;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    50
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    51
	subindex  *pSubindex;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    52
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    53
	for(i=0; i<max_index; i++)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    54
	{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    55
		pSubindex = dict[i].pSubindex;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    56
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    57
		for(j=0; j<dict[i].bSubCount; j++)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    58
		{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    59
			/* check pSubindex[j].bAccessType */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    60
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    61
			nvram_write(pSubindex[j].bDataType,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    62
				pSubindex[j].bAccessType,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    63
				pSubindex[j].pObject);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    64
		}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    65
	}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    66
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    67
	nvram_close();
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    68
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    69
	return 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    70
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    71
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    72
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    73
int canReadData(indextable *dict, int max_index)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    74
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    75
	int i, j;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    76
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    77
	subindex *pSubindex;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    78
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    79
	union
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    80
	{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    81
		UNS8   u8;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    82
		UNS16  u16;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    83
		UNS32  u32;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    84
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    85
		float  r4;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    86
		double r8;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    87
	} object;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    88
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    89
	if (nvram_open() < 0)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    90
		return -1;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    91
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    92
	for(i=0; i<max_index; i++)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    93
	{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    94
		pSubindex = dict[i].pSubindex;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    95
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    96
		for(j=0; j<dict[i].bSubCount; j++)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    97
		{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    98
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    99
			nvram_read(pSubindex[j].bDataType,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   100
				pSubindex[j].bAccessType,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   101
				(void *)&object);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   102
		}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   103
	}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   104
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   105
	nvram_close();
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   106
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   107
	return 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   108
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   109