The following document contains information on Cypress products. Colophon The products described in this document are designed, developed and manufactured as contemplated for general use, including without limitation, ordinary industrial use, general office use, personal use, and household use, but are not designed, developed and manufactured as contemplated (1) for any use that includes fatal risks or dangers that, unless extremely high safety is secured, could have a serious effect to the public, and could lead directly to death, personal injury, severe physical damage or other loss (i.e., nuclear reaction control in nuclear facility, aircraft flight control, air traffic control, mass transport control, medical life support system, missile launch control in weapon system), or (2) for any use where chance of failure is intolerable (i.e., submersible repeater and artificial satellite). Please note that Spansion will not be liable to you and/or any third party for any claims or damages arising in connection with above-mentioned uses of the products. Any semiconductor devices have an inherent chance of failure. You must protect against injury, damage or loss from such failures by incorporating safety design measures into your facility and equipment such as redundancy, fire protection, and prevention of over-current levels and other abnormal operating conditions. If any products described in this document represent goods or technologies subject to certain restrictions on export under the Foreign Exchange and Foreign Trade Law of Japan, the US Export Administration Regulations or the applicable laws of any other country, the prior authorization by the respective government entity will be required for export of those products. Trademarks and Notice The contents of this document are subject to change without notice. This document may contain information on a Spansion product under development by Spansion. Spansion reserves the right to change or discontinue work on any product without notice. The information in this document is provided as is without warranty or guarantee of any kind as to its accuracy, completeness, operability, fitness for particular purpose, merchantability, non-infringement of third-party rights, or any other warranty, express, implied, or statutory. Spansion assumes no liability for any damages of any kind arising out of the use of the information in this document. ® ® ® TM Copyright © 2013 Spansion Inc. All rights reserved. Spansion , the Spansion logo, MirrorBit , MirrorBit Eclipse , TM ORNAND and combinations thereof, are trademarks and registered trademarks of Spansion LLC in the United States and other countries. Other names used are for informational purposes only and may be trademarks of their respective owners. Fujitsu Semiconductor Design (Chengdu) Co., Ltd. Application Note MCU-AN-500112-E-10 F²MC-8FX FAMILY 8-BIT MICROCONTROLLER MB95410H/470H SERIES ONE PHASE POWER METER (RN8209) SOLUTION IC CARD AND ESAM OPERATION APPLICATION NOTE IC Card and ESAM Operation V1.0.0 Revision History Revision History Versio n Date Updated by Modifications 1.0.0 6/1/2011 Funny Chen First Draft : Write the user manual of IC card and ESAM function. This manual contains 13 pages. Specifications are subject to change without notice. For further information please contact each office. All Rights Reserved. The contents of this document are subject to change without notice. Customers are advised to consult with sales representatives before ordering. The information, such as descriptions of function and application circuit examples, in this document are presented solely for the purpose of reference to show examples of operations and uses of FUJITSU SEMICONDUCTOR device; FUJITSU SEMICONDUCTOR does not warrant proper operation of the device with respect to use based on such information. When you develop equipment incorporating the device based on such information, you must assume any responsibility arising out of such use of the information. FUJITSU SEMICONDUCTOR assumes no liability for any damages whatsoever arising out of the use of the information. Any information in this document, including descriptions of function and schematic diagrams, shall not be construed as license of the use or exercise of any intellectual property right, such as patent right or copyright, or any other right of FUJITSU SEMICONDUCTOR or any third party or does FUJITSU SEMICONDUCTOR warrant non-infringement of any third-party's intellectual property right or other right by using such information. FUJITSU SEMICONDUCTOR assumes no liability for any infringement of the intellectual property rights or other rights of third parties which would result from the use of information contained herein. The products described in this document are designed, developed and manufactured as contemplated for general use, including without limitation, ordinary industrial use, general office use, personal use, and household use, but are not designed, developed and manufactured as contemplated (1) for use accompanying fatal risks or dangers that, unless extremely high safety is secured, could have a serious effect to the public, and could lead directly to death, personal injury, severe physical damage or other loss (i.e., nuclear reaction control in nuclear facility, aircraft flight control, air traffic control, mass transport control, medical life support system, missile launch control in weapon system), or (2) for use requiring extremely high reliability (i.e., submersible repeater and artificial satellite). Please note that FUJITSU SEMICONDUCTOR will not be liable against you and/or any third party for any claims or damages arising in connection with above-mentioned uses of the products. Any semiconductor devices have an inherent chance of failure. You must protect against injury, damage or loss from such failures by incorporating safety design measures into your facility and equipment such as redundancy, fire protection, and prevention of over-current levels and other abnormal operating conditions. Exportation/release of any products described in this document may require necessary procedures in accordance with the regulations of the Foreign Exchange and Foreign Trade Control Law of Japan and/or US export control laws. The company names and brand names herein are the trademarks or registered trademarks of their respective owners. © 2011 Fujitsu Semiconductor Design (Chengdu) Co., Ltd. MCU-AN-500112-E-10 – Page 2 IC Card and ESAM Operation V1.1.0 Contents Contents REVISION HISTORY ............................................................................................................ 2 CONTENTS .......................................................................................................................... 3 1 INTRODUCTION .............................................................................................................. 4 2 BACKGROUND ............................................................................................................... 5 2.1 Overview ................................................................................................................. 5 2.2 Communication Protocol ......................................................................................... 5 3 HW DIAGRAM ................................................................................................................. 6 3.1 The HW diagram of prepayment function ................................................................ 6 4 HW REFERENCE SCH .................................................................................................... 7 5 FW DIAGRAM .................................................................................................................. 8 5.1 ISO7816-3-2006 Protocol ........................................................................................ 8 5.2 TimeCOS_PBOC Protocol ...................................................................................... 8 5.3 Firmware System Diagram ...................................................................................... 9 6 FW FUNCTION LIST...................................................................................................... 10 6.1 API ........................................................................................................................ 10 6.2 HAL ....................................................................................................................... 11 7 ADDITIONAL INFORMATION ....................................................................................... 12 8 APPENDIX ..................................................................................................................... 13 8.1 List of Figures and Tables ..................................................................................... 13 MCU-AN-500112-E-10 – Page 3 IC Card and ESAM Operation V1.0.0 Chapter 1 Introduction 1 Introduction This application note describes how to use One Phase Power Meter (RN8209) solution’s IC Card and ESAM function. Chapter 2 explains the background. Chapter 3 explains the HW diagram of IC Card and ESAM function. Chapter 4 explains the HW reference SCH. Chapter 5 explains the FW diagram. Chapter 6 explains the FW function list. MCU-AN-500112-E-10 – Page 4 IC Card and ESAM Operation V1.1.0 Chapter 2 Background 2 Background Background of Prepayment Function 2.1 Overview Prepayment function is realized by the communication between IC card and ESAM module. 2.2 Communication Protocol Byte communication protocol refers to ISO7816-3-2006 protocol, and frame structure refers to TimeCOS_PBOC protocol. MCU-AN-500112-E-10 – Page 5 IC Card and ESAM Operation V1.0.0 Chapter 3 HW Diagram 3 HW Diagram Hardware diagram of prepayment system 3.1 The HW diagram of prepayment function IC card communication interface MB95F418 ESAM module Figure 3-1: Hardware Diagram MCU-AN-500112-E-10 – Page 6 IC Card and ESAM Operation V1.1.0 Chapter 4 HW Reference SCH 4 HW Reference SCH Hardware reference SCH of prepayment system VDD P1 VCC IO RST CLK KEY GND R50 R51 10K 10K 6 5 4 3 2 1 IC_VCC IC_IO IC_RST MCU_CLK IC_KEY C29 IC_CARD_PORT 103 Figure 4-1: IC Card Interface Circuit 103 SAM_IO Q21 2N5551B 1 2 3 4 U11 GNDVCC NC1 RST IO CLK NC2 NC3 8 7 6 5 C C27 10K R48 1K SAM_VCC 2 E R46 3 VDD IC_VCC SAM_RST MCU_CLK ESAM Figure 4-2: ESAM Module Circuit MCU-AN-500112-E-10 – Page 7 IC Card and ESAM Operation V1.0.0 Chapter 5 FW diagram 5 FW diagram Firmware system diagram of AMR system 5.1 ISO7816-3-2006 Protocol Communication protocol’s character frame is shown in Figure 5-1. According to Figure 5-1, a character consists of ten consecutive moments numbered 1 to 10. Each moment is either at state H or at state L. ⎯ Before moment 1, the electrical circuit I/O shall be at state H. ⎯ Moment 1 shall be at state L. It is the character start. ⎯ Moments 2 to 9 shall encode a byte according to a coding convention(send the LSB first). ⎯ Moment 10 shall encode the character parity. ⎯ After moment 10, both the card and the interface device shall remain in reception mode (in error-free operation) for a certain time of “pause”, so that the electrical circuit I/O remains at state H. Figure 5-1: Character Format Data 5.2 TimeCOS_PBOC Protocol Figure 5-2: Command and Response Frame Format MCU-AN-500112-E-10 – Page 8 IC Card and ESAM Operation V1.1.0 Chapter 5 FW diagram 5.3 Firmware System Diagram Start Init IC card module Init ESAM module Card insert? N Y Active card and reset Y Identity authen OK? Read command code N Excute the communication between IC card and ESAM, and release IC End Figure 5-3: Firmware System Diagram MCU-AN-500112-E-10 – Page 9 IC Card and ESAM Operation V1.0.0 Chapter 6 FW Function List 6 FW Function List 6.1 API Table 6-1: FW API List Function Prototype Description void IC_Card_Init(void) Initialization for IC card connection INT8U active_card(INT8U* receivebuffer) Active IC card void release_card(void) Release IC card INT8U user_card_process(void) Process user card INT8U user_card_01_process(void) Process build-user card INT8U user_card_02_03_process(void) Process purchase card and complementary card INT8U key_card_process(INT8U cardtype) Process key card INT8U cur_para_set_card_process(void) Process current parameter set card INT8U esam_data_copy_card_process(void) Process ESAM data copy card INT8U para_preset_card_process(void) Process parameter preset card INT8U meter_num_set_card_process(void) Process meter number set card INT8U increase_charge_card_process(void) Process increase charge card INT8U relay_test_card_process(void) Process relay test card INT8U sys_identity_authen(void) Identity authen between IC card and ESAM INT8U card_process(void) Process card void Esam_Init(void) Initialization for ESAM connection void ActiveEsam(void) Active ESAM module void ReleaseEsam(void) Release ESAM module void GetUserNum(INT8U* buffer) Get user number from ESAM void GetMeterNum(INT8U* buffer) Get meter number from ESAM void UpdateEsamBalance(INT8U decValue) Update ESAM balance void GetEsamBalance(void) Get ESAM balance MCU-AN-500112-E-10 – Page 10 IC Card and ESAM Operation V1.1.0 Chapter 6 FW Function List 6.2 HAL Table 6-2: FW HAL List Function Prototype Description void CardPortResetRx(void) Reset IC card RX procedure to RX standby mode void CardPortResetTx(void) Reset IC card TX procedure to TX standby mode INT8U IsCardPortDataReady(void) Check if any data received from IC card port INT8U CardPortDataRead(void) Retrieve a data byte from FIFO of IC card port INT8U IsCardPortTxBusy(void) Check if card port is busy in the middle of TX INT8U IC_SAM_send_data(INT8U mode, INT8U length, INT8U* buffer) INT8U IC_SAM_receive_data(INT8U mode, INT8U length, INT8U* buffer) void IC_SAM_send_byte(INT8U mode, INT8U data) Send data to IC card or ESAM void EsamPortResetRx(void) Reset Esam procedure to RX standby mode void EsamPortResetTx(void) Reset Esam procedure to TX standby mode INT8U IsEsamPortDataReady(void) Check if any data received from ESAM port INT8U EsamPortDataRead(void) Retrieve a data byte from FIFO of ESAM port INT8U IsEsamPortTxBusy(void) Check if ESAM port is busy in the middle of TX Receive data from IC card or ESAM send a byte data to IC card or ESAM MCU-AN-500112-E-10 – Page 11 IC Card and ESAM Operation V1.0.0 Chapter 7 Additional Information 7 Additional Information For more Information on FUJITSU semiconductor products, visit the following websites: English version address: http://www.fujitsu.com/cn/fsp/services/mcu/mb95/application_notes.html Chinese version address: http://www.fujitsu.com/cn/fss/services/mcu/mb95/application_notes.html MCU-AN-500112-E-10 – Page 12 IC Card and ESAM Operation V1.1.0 Chapter 8 Appendix 8 Appendix 8.1 List of Figures and Tables Table 6-1: FW API List ......................................................................................................... 10 Table 6-2: FW HAL List ........................................................................................................ 11 Figure 3-1: Hardware Diagram ............................................................................................... 6 Figure 4-1: IC Card Interface Circuit....................................................................................... 7 Figure 4-2: ESAM Module Circuit ........................................................................................... 7 Figure 5-1: Character Format Data ........................................................................................ 8 Figure 5-2: Command and Response Frame Format ............................................................. 8 Figure 5-3: Firmware System Diagram ................................................................................... 9 MCU-AN-500112-E-10 – Page 13