mfg-token.h

Go to the documentation of this file.
00001 /** @file hal/micro/cortexm3/mfg-token.h
00002  * @brief Cortex-M3 Manufacturing token system 
00003  *
00004  * <!--(C) COPYRIGHT 2010 STMicroelectronics. All rights reserved.        -->
00005  */
00006  
00007 #ifndef __MFG_TOKEN_H__
00008 #define __MFG_TOKEN_H__
00009  
00010 
00011 // The manufacturing tokens live in the Info Blocks, while all other tokens
00012 // live in the Simulated EEPROM.  This requires the token names to be defined
00013 // as different data (mfg tokens are memory address, all others are an enum).
00014 
00015 
00016 #define DEFINETOKENS
00017 
00018 /**
00019  * @description Macro for translating token defs into address variables
00020  * that point to the correct location in the Info Blocks.  (This is the
00021  * extern, the actual definition is found in hal/micro/cortexm3/token.c)
00022  *
00023  * @param name: The name of the token.
00024  *
00025  * @param TOKEN_##name##_ADDRESS: The address in EEPROM at which the token
00026  * will be stored.  This parameter is generated with a macro above.
00027  */
00028 #define TOKEN_MFG(name,creator,iscnt,isidx,type,arraysize,...) \
00029   extern const int16u TOKEN_##name;
00030   #include "hal/micro/cortexm3/token-manufacturing.h"
00031 #undef TOKEN_MFG
00032 
00033 /**
00034  * @description Macro for translating token definitions into size variables.
00035  * This provides a convenience for abstracting the 'sizeof(type)' anywhere.
00036  *
00037  * @param name: The name of the token.
00038  *
00039  * @param type: The token type.  The types are found in token-stack.h.
00040  */
00041 #define TOKEN_MFG(name,creator,iscnt,isidx,type,arraysize,...) \
00042   TOKEN_##name##_SIZE = sizeof(type),
00043   enum {
00044     #include "hal/micro/cortexm3/token-manufacturing.h"
00045   };
00046 #undef TOKEN_MFG
00047 #undef TOKEN_DEF
00048   
00049 /**
00050  * @description Macro for typedef'ing the CamelCase token type found in
00051  * token-stack.h to a capitalized TOKEN style name that ends in _TYPE.
00052  * This macro allows other macros below to use 'token##_TYPE' to declare
00053  * a local copy of that token.
00054  *
00055  * @param name: The name of the token.
00056  *
00057  * @param type: The token type.  The types are found in token-stack.h.
00058  */
00059 #define TOKEN_MFG(name,creator,iscnt,isidx,type,arraysize,...) \
00060   typedef type TOKEN_##name##_TYPE;
00061   #include "hal/micro/cortexm3/token-manufacturing.h"
00062 #undef TOKEN_MFG
00063 
00064 #undef TOKEN_NEXT_ADDRESS  
00065   
00066 #define DEFINEADDRESSES
00067 /**
00068  * @description Macro for creating a 'region' element in the enum below.  This
00069  * creates an element in the enum that provides a starting point (address) for
00070  * subsequent tokens to align against.  ( See hal/micro/cortexm3/token.c for
00071  * the instances of TOKEN_NEXT_ADDRESS() );
00072  *
00073  * @param region: The name to give to the element in the address enum..
00074  *
00075  * @param address: The address in EEPROM where the region begins.
00076  */
00077 #define TOKEN_NEXT_ADDRESS(region, address)      \
00078   TOKEN_##region##_NEXT_ADDRESS = ((address) - 1),
00079 
00080 /**
00081  * @description Macro for creating ADDRESS and END elements for each token in
00082  * the enum below.  The ADDRESS element is linked to from the the normal
00083  * TOKEN_##name macro and provides the value passed into the internal token
00084  * system calls.  The END element is a placeholder providing the starting
00085  * point for the ADDRESS of the next dynamically positioned token.
00086  *
00087  * @param name: The name of the token.
00088  *
00089  * @param arraysize: The number of elements in an indexed token (arraysize=1
00090  * for scalar tokens).
00091  */
00092 #define TOKEN_MFG(name,creator,iscnt,isidx,type,arraysize,...) \
00093   TOKEN_##name##_ADDRESS,                                      \
00094   TOKEN_##name##_END = TOKEN_##name##_ADDRESS +                \
00095                        (TOKEN_##name##_SIZE * arraysize) - 1,
00096 
00097 /**
00098  * @description The enum that operates on the two macros above.  Also provides
00099  * an indentifier so the address of the top of the token system can be known.
00100  */
00101 enum {
00102   #include "hal/micro/cortexm3/token-manufacturing.h"
00103 };
00104 #undef TOKEN_MFG
00105 #undef DEFINEADDRESSES
00106 
00107 #undef DEFINETOKENS
00108 
00109 
00110 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00111 /**
00112  * @description Copies the token value from non-volatile storage into a RAM
00113  * location.  This is the internal function that the exposed API
00114  * (halCommonGetMfgToken) expands out to.  The
00115  * API simplifies the access into this function by hiding the size parameter.
00116  *
00117  * @param data: A pointer to where the data being read should be placed.
00118  *
00119  * @param token: The name of the token to get data from.  On this platform
00120  * that name is defined as an address.
00121  *
00122  * @param index: The index to access.  If the token being accessed is not an
00123  * indexed token, this parameter is set by the API to be 0x7F.
00124  *
00125  * @param len: The length of the token being worked on.  This value is
00126  * automatically set by the API to be the size of the token.
00127  */
00128 void halInternalGetMfgTokenData(void *data, int16u token, int8u index, int8u len);
00129 
00130 /**
00131  * @description Sets the value of a token in non-volatile storage.  This is
00132  * the internal function that the exposed API (halCommonSetMfgToken)
00133  * expands out to.  The API simplifies the access into this function
00134  * by hiding the size parameter.
00135  *
00136  * <b>NOTE:</b> CIB manufacturing tokens can only be written by on-chip
00137  * code if the token is currently unprogrammed.
00138  *
00139  * <b>REMEMBER:</b> The flash hardware requires writing to 16bit aligned
00140  * addresses with a length that is multiples of 16bits.
00141  *
00142  * @param token: The name of the token to get data from.  On this platform
00143  * that name is defined as an address.
00144  *
00145  * @param data: A pointer to the data being written.
00146  *
00147  * @param len: The length of the token being worked on.  This value is
00148  * automatically set by the API to be the size of the token.
00149  */
00150 void halInternalSetMfgTokenData(int16u token, void *data, int8u len);
00151 
00152 #define halCommonGetMfgToken( data, token )                    \
00153   halInternalGetMfgTokenData(data, token, 0x7F, token##_SIZE)
00154 
00155 #define halCommonGetIndexedMfgToken( data, token, index )      \
00156   halInternalGetMfgTokenData(data, token, index, token##_SIZE)
00157 
00158 #define halCommonSetMfgToken( token, data )                    \
00159   halInternalSetMfgTokenData(token, data, token##_SIZE)
00160 
00161 #endif //DOXYGEN_SHOULD_SKIP_THIS
00162 
00163 #endif //__MFG_TOKEN_H__

Generated on Mon Apr 11 14:23:40 2011 for Contiki 2.5 by  doxygen 1.6.1