Sunday, February 12, 2017

Advance MACRO Function in Embedded C Programming.

 In Embedded system C programing MACRO functions are very powerful, It can do the things which traditional  C functions Can't. As an embedded programmer its very help full if you can use these advantages of MACRO functions. You can even create a macro functions as template of function and simply use it, depends on input argument you can even change the operation of that particular function.

Macros can also accept parameters and return values. Macros that do so are called macro functions. To create a macro function, simply define a macro with a parameter that has whatever name you like, such as my_val. For example, one macro defined in the standard libraries is abs, which returns the absolute value of its parameter. Let us define our own version, ABS, below. (Note that we are defining it in uppercase not only to avoid conflicting with abs, but also because all macros should be defined in uppercase, in the GNU coding style.) 

#define ABS(my_val) ((my_val) < 0) ? -(my_val) : (my_val)

-From Examples of GNU

Whenever we think about MACRO function, most of the time we are assuming the functions (ABS) mentioned in above example?? , If we think little bit out of box, we can found a huge advantages of MACRO function, which even change the way we use to write Embedded C programs. The use of macro functions are very simple, you just keep in mind that wherever you use macro function it just replace  function call with function definition. Syntax of macro function is as mentioned below.

#define MACRO_Function_Name ( Argument_1, Argument_2... Argument_n )  \
 { \
/* Function Definitions */  \

The main Advantages of MACRO functions are,

To explain this in more detail please considered following example MACRO function to calculate Checksum with supports any Data type and different operation to calculate Checksum.

1. Argument type, For a MACRO function you can pass any C keyword, operators, variable names, Identifiers.. etc. as the input argument  of MACRO functions. Its give a huge flexibility in writing General functions.
Eg:- To calculate the check sum of  input argument with different types such as  char and long, you can use the

2.Can change the definition of a Macro function in certain C files, where you like to function it differently.
Eg:- If the name of the MACRO function to calculate check sun is GET_CHECK_SUM, and if you like to do a simple addition in a particular C file or in a function , then just redefine at the top of  file or in the function. Because C is a Top to bottem

#define GET_CHECK_SUM ( a, b)  a+b

  The main thing you need to remember while creating a MACRO functions are,
  • Please put back slash / Line break ( \ ) at the end of each line of macro function, not required on last line of the function.
  • In most of the IDE using for embedded development its difficult to debug a macro function, So my suggestion is to convert this macro function to traditional function and once issue was debugged change same to macro function. If your IDE supports then its ok.
  • If you are declaring any variable in MACRO function, Make sure that its name is unique, else it will considered it as a local variable.
  • Make sure to put semicolon (;) after each statements.
  • do not do any assignment  operation on input arguments if they are constants. You can do any assignment  operation on input arguments if you passing local or global variable on MACRO function call.

Please give your suggestion and follow us if you are interested, which encourage us to create new topics for you. And Thankyou for your support.

Monday, July 4, 2011


                                                 The MIFARE Classic RFID card is fundamentally just a memory storage device, where the memory is divided into segments and blocks with simple security mechanisms for access control. MIFARE is the NXP Semiconductors-owned trademark of a series of chips widely used in contactless smart cards and proximity cards.They are ASIC based and have limited computational power. Thanks to their reliability and low cost, those cards are widely used for electronic wallet, access control, corporate ID cards, transportation or stadium ticketing.

                                                  The MIFAR Classic Crypto algorithm is a highly cost efficient authentication and data encryption method. It has been designed for maximum performance while providing basic levels of data security. In combination with a sophisticated key diversification technique and appropriate system level security measures, this product can be used for reloadable time-based smart cards or stored-value fare collection concepts.The MIFARE Classic 1k offers 1024 bytes of data storage, split into 16 sectors; each sector is protected by two different keys, called A and B. They can be programmed for operations like reading, writing, increasing value blocks, etc.). MIFARE Classic 4k offers 4096 bytes split into forty sectors, of which 32 are same size as in the 1K with eight more that are quadruple size sectors. MIFARE Classic mini offers 320 bytes split into five sectors. For each of these card types, 16 bytes per sector are reserved for the keys and access conditions and can not normally be used for user data. Also, the very first 16 bytes contain the serial number of the card and certain other manufacturer data and are read only. That brings the net storage capacity of these cards down to 752 bytes for Classic 1k, 3440 bytes for Classic 4k, and 224 bytes for Mini.

                                              This wide range of chips offers varying degrees of functionality, performance, security and strength of encryption, so that system integrators can choose the appropriate solution in terms of chip security and back end system to address their requirements. MIFARE Classic provides a benchmark in cost competitiveness as well as proven contactless performance, while MIFARE Plus™ enables an optimal future-proof migration path when necessary. Both MIFARE Plus and our high-end product MIFARE DESFire™ EV1 offer strong AES encryption and are certified according to Common Criteria EAL 4+

MIFARE Plus :-   The MIFARE Plus features multiple levels of security, including Advanced Encryption Standard (AES) encryption, and an easy migration path from existing MIFARE Classic implementations.
Security is at the heart of MIFARE Plus, which is the only smart card IC of its class to offer strong AES encryption for authentication, integrity and confidentiality, based on a 128-bit key length. MIFARE Plus chips comprise a number of additional security features which, when used optimally in the infrastructure, provide a system that prevents individuals from being identified and tracked by others.These features are enabled through the support of secure Random Identifiers (RIDs) next to 7 Byte Unique Identifiers (UIDs). MIFARE Plus also offers an originality function, which improves verification of cards and enables active measures against emulators.The crypto architecture of MIFARE Plus was reviewed by multiple independent parties and the chip itself received Common Criteria certification EAL 4+. In its highest security level, MIFARE Plus is not using any part of the compromised Crypto1 algorithm which is utilized in MIFARE Classic.In order to speed up and ease the migration process for existing infrastructures based on MIFARE Classic, the MIFARE Plus chip on its lowest security level will be backwards compatible with MIFARE Classic.Cards using chips in this lowest security level can be switched to a higher security level after issuance. it cannot be switched back to a lower security level.The switch itself is protected by an AES key that shall be different for each card, so switching to a higher level cannot be done unless this AES-secured key is known.

MIFARE DESFire:- Taking advantage of the extremely secure and standardised triple-DES( Data Encryption Standard) crypto method, MIFARE DESFire is designated for growing and open intermodal transport schemes. In combination with the MIFARE DESFire SAM (Secure Application Module in the terminal / reader), MIFARE DESFire provides highest levels of performance and security in both cards as well as in the infrastructure along with simple key handling.

SmartMX:As the first smart card controller platform of its kind, the SmartMX™ portfolio incorporates three interface options as an integral part of a highly secure smart card controller portfolio – ISO/IEC 7816 Contact Interface, ISO/IEC 14443A Contactless Interface and USB 2.0 LS Interface.

MIFARE Ultralight:- MIFARE Ultralight enables users to benefit from non-reloadable limited-use tickets through the appropriate usage of the One-Time-Programmable (OTP) memory area in combination with the ISO Unique IDentifier (UID) on a secure infrastructure. Additionally, MIFARE Ultralight offers maximum flexibility to realise time-based tickets (e.g. single-day tickets), zone-based tickets, multiple-ride tickets (e.g. 10-trip tickets) or even single-ride tickets.



Please give your suggestion and follow us if you are interested, which encourage us to create new topics for you. And Thankyou for your support.