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