Contiki 2.5
mfg-token.h
Go to the documentation of this file.
1 /** @file hal/micro/cortexm3/mfg-token.h
2  * @brief Cortex-M3 Manufacturing token system
3  *
4  * <!--(C) COPYRIGHT 2010 STMicroelectronics. All rights reserved. -->
5  */
6 
7 #ifndef __MFG_TOKEN_H__
8 #define __MFG_TOKEN_H__
9 
10 
11 // The manufacturing tokens live in the Info Blocks, while all other tokens
12 // live in the Simulated EEPROM. This requires the token names to be defined
13 // as different data (mfg tokens are memory address, all others are an enum).
14 
15 
16 #define DEFINETOKENS
17 
18 /**
19  * @description Macro for translating token defs into address variables
20  * that point to the correct location in the Info Blocks. (This is the
21  * extern, the actual definition is found in hal/micro/cortexm3/token.c)
22  *
23  * @param name: The name of the token.
24  *
25  * @param TOKEN_##name##_ADDRESS: The address in EEPROM at which the token
26  * will be stored. This parameter is generated with a macro above.
27  */
28 #define TOKEN_MFG(name,creator,iscnt,isidx,type,arraysize,...) \
29  extern const int16u TOKEN_##name;
31 #undef TOKEN_MFG
32 
33 /**
34  * @description Macro for translating token definitions into size variables.
35  * This provides a convenience for abstracting the 'sizeof(type)' anywhere.
36  *
37  * @param name: The name of the token.
38  *
39  * @param type: The token type. The types are found in token-stack.h.
40  */
41 #define TOKEN_MFG(name,creator,iscnt,isidx,type,arraysize,...) \
42  TOKEN_##name##_SIZE = sizeof(type),
43  enum {
45  };
46 #undef TOKEN_MFG
47 #undef TOKEN_DEF
48 
49 /**
50  * @description Macro for typedef'ing the CamelCase token type found in
51  * token-stack.h to a capitalized TOKEN style name that ends in _TYPE.
52  * This macro allows other macros below to use 'token##_TYPE' to declare
53  * a local copy of that token.
54  *
55  * @param name: The name of the token.
56  *
57  * @param type: The token type. The types are found in token-stack.h.
58  */
59 #define TOKEN_MFG(name,creator,iscnt,isidx,type,arraysize,...) \
60  typedef type TOKEN_##name##_TYPE;
62 #undef TOKEN_MFG
63 
64 #undef TOKEN_NEXT_ADDRESS
65 
66 #define DEFINEADDRESSES
67 /**
68  * @description Macro for creating a 'region' element in the enum below. This
69  * creates an element in the enum that provides a starting point (address) for
70  * subsequent tokens to align against. ( See hal/micro/cortexm3/token.c for
71  * the instances of TOKEN_NEXT_ADDRESS() );
72  *
73  * @param region: The name to give to the element in the address enum..
74  *
75  * @param address: The address in EEPROM where the region begins.
76  */
77 #define TOKEN_NEXT_ADDRESS(region, address) \
78  TOKEN_##region##_NEXT_ADDRESS = ((address) - 1),
79 
80 /**
81  * @description Macro for creating ADDRESS and END elements for each token in
82  * the enum below. The ADDRESS element is linked to from the the normal
83  * TOKEN_##name macro and provides the value passed into the internal token
84  * system calls. The END element is a placeholder providing the starting
85  * point for the ADDRESS of the next dynamically positioned token.
86  *
87  * @param name: The name of the token.
88  *
89  * @param arraysize: The number of elements in an indexed token (arraysize=1
90  * for scalar tokens).
91  */
92 #define TOKEN_MFG(name,creator,iscnt,isidx,type,arraysize,...) \
93  TOKEN_##name##_ADDRESS, \
94  TOKEN_##name##_END = TOKEN_##name##_ADDRESS + \
95  (TOKEN_##name##_SIZE * arraysize) - 1,
96 
97 /**
98  * @description The enum that operates on the two macros above. Also provides
99  * an indentifier so the address of the top of the token system can be known.
100  */
101 enum {
103 };
104 #undef TOKEN_MFG
105 #undef DEFINEADDRESSES
106 
107 #undef DEFINETOKENS
108 
109 
110 #ifndef DOXYGEN_SHOULD_SKIP_THIS
111 /**
112  * @description Copies the token value from non-volatile storage into a RAM
113  * location. This is the internal function that the exposed API
114  * (halCommonGetMfgToken) expands out to. The
115  * API simplifies the access into this function by hiding the size parameter.
116  *
117  * @param data: A pointer to where the data being read should be placed.
118  *
119  * @param token: The name of the token to get data from. On this platform
120  * that name is defined as an address.
121  *
122  * @param index: The index to access. If the token being accessed is not an
123  * indexed token, this parameter is set by the API to be 0x7F.
124  *
125  * @param len: The length of the token being worked on. This value is
126  * automatically set by the API to be the size of the token.
127  */
128 void halInternalGetMfgTokenData(void *data, int16u token, int8u index, int8u len);
129 
130 /**
131  * @description Sets the value of a token in non-volatile storage. This is
132  * the internal function that the exposed API (halCommonSetMfgToken)
133  * expands out to. The API simplifies the access into this function
134  * by hiding the size parameter.
135  *
136  * <b>NOTE:</b> CIB manufacturing tokens can only be written by on-chip
137  * code if the token is currently unprogrammed.
138  *
139  * <b>REMEMBER:</b> The flash hardware requires writing to 16bit aligned
140  * addresses with a length that is multiples of 16bits.
141  *
142  * @param token: The name of the token to get data from. On this platform
143  * that name is defined as an address.
144  *
145  * @param data: A pointer to the data being written.
146  *
147  * @param len: The length of the token being worked on. This value is
148  * automatically set by the API to be the size of the token.
149  */
150 void halInternalSetMfgTokenData(int16u token, void *data, int8u len);
151 
152 #define halCommonGetMfgToken( data, token ) \
153  halInternalGetMfgTokenData(data, token, 0x7F, token##_SIZE)
154 
155 #define halCommonGetIndexedMfgToken( data, token, index ) \
156  halInternalGetMfgTokenData(data, token, index, token##_SIZE)
157 
158 #define halCommonSetMfgToken( token, data ) \
159  halInternalSetMfgTokenData(token, data, token##_SIZE)
160 
161 #endif //DOXYGEN_SHOULD_SKIP_THIS
162 
163 #endif //__MFG_TOKEN_H__