dlms server protocol stack application note 2read.pudn.com/downloads519/sourcecode/embedded...sample...
TRANSCRIPT
APPLICATION NOTE
REJxxxxxxx-0600 Rev.6.00 Page 1 of 21
7/14/2011
RX200 Series
DLMS Server Protocol Stack
Introduction
This application note provides users with the guide on how to use the DLMS server protocol stack application
programming interface (API) that run on the RX200 MCU. By referring to this manual, users can embedded the DLMS
protocol function into their energy meter platform. This application note will also provide a brief theory about the
DLMS protocol.
Target Device
RX200 Series
Contents
1. DLMS/COSEM Protocol .................................................................................................................... 2
2. DLMS Server Protocol Stack Library ................................................................................................ 4
3. Sample Program ............................................................................................................................. 13
RX200 Series DLMS Server Protocol Stack
REJxxxxxxx-0600 Rev.6.00 Page 2 of 21
7/14/2011
1. DLMS/COSEM Protocol
DLMS is known as Device Language Message Specification is an application layer specification, for supporting
messaging between meter devices with a computer integrated environment. COSEM stands for the Companion
Specification for Energy Metering; it is an interface model of communicating energy meter metering equipment.
Together DLMS/COSEM represents protocol standard for a machine in computer integrated environment to
communicate with utility meters. The standard is described in the sets of specifications which mainly consist of 3 books.
They are The Green Book that the architecture and protocols to transport the model, The Blue Book which describes the
COSEM meter object model and the object identification system and The Yellow Book - describes the DLMS-COSEM
conformance testing process. These specifications set a standard for data exchange between PC and meters.
Data exchange between data collection systems and metering equipment using the COSEM interface object model is
based on the client/server paradigm. Utilities meter will play the role as server in DLMS/COSEM and the PC device,
such as Automatic Meter Reader, will act as clients. Data exchange takes place via exchanging messages
(SERVICE.requests / .responses) between the set of Client/Server application. In general, the client and the server
application are located in separate devices; exchanging messages therefore is done via a protocol stack, or
communication profile. The diagram of the Client/Server relationship is as shown in figure 1 below:
Server Application (Energy Meter)
Client Application(Automatic Meter Reader)
ServerCOSEM Application Layer
ClientCOSEM Application Layer
ServerData Link Layer
ClientData Link Layer
Physical LayerPhysical Layer
Physical Channel
COSEM Object Layer
Figure 1 DLMS/COSEM Client/Server Relationship Diagram
Physical channel as shown in the diagram above can be direct serial connection, Infra red with LED or using TCP/IP
protocol. Physical Layer is the lowest layer in the DLMS/COSEM protocol which is basically the interface between
Devices and the physical channel. The physical layer is dependable on user device application and is not included in
this version of server stack. In the context of energy meter, the physical layer is usually defined in standard IEC 62056-
21 which describe the hardware and protocol specifications for local meter data exchange
Data link layers are the interface between Application Layer and Physical Layer. The data link designed in this stack is
based on the 3-layer, connection-oriented, HDLC-based, asynchronous communication profile. This specification
supports the following communication environments:
RX200 Series DLMS Server Protocol Stack
REJxxxxxxx-0600 Rev.6.00 Page 3 of 21
7/14/2011
• point-to-point and point-to-multipoint configurations;
• dedicated and switched data transmission facilities;
• half-duplex and full-duplex connections;
• Asynchronous start/stop transmission, with 1 start bit, 8 data bits, no parity, 1 stop bit. DLMS Application Layer is independent of the lower layers and thus mode of connection. The application layer is to
provide an inter-operable messaging system for the Object modeling layer and the data exchange method. The main
component of the COSEM application layer is the COSEM Application Service Object. It contains three mandatory
components both on the client and on the server side, which is the Association Control Service Element (ACSE), the
extended DLMS Application Service Element (xDLMS_ASE) and the Control Function, CF. the ACSE is for user to
establish, maintain and release the application associations. The task of xDLMS_ASE is to provide data transfer
services between server/client. The CF specifies how the services invoke the appropriated service primitives of the
ACSE, the xDLMS_ASE and the Services of the supporting layer. Physical Layer, Data Link Layer and COSEM
Application Layer are explained in detail in the Green Book.
Object layer is where the modeling of the COSEM interface objects happens. The object layer covers the data model of
the metering equipment and the rules of data identification. The data model will provides the view of the functionality
of the meter. The set of different and customized interface classes (ICs) and object model can be created by
manufacturer to its individual products. The object layer is explained in the Blue Book.
RX200 Series DLMS Server Protocol Stack
REJxxxxxxx-0600 Rev.6.00 Page 4 of 21
7/14/2011
2. DLMS Server Protocol Stack Library
The DLMS Server Stack is an implementation of the DLMS/COSEM Protocol which makes the Electricity Meters
DLMS compliant. The stack is implemented in the programming language C. This section provides the usage manual of
this stack library.
The stack library package is released as version 1.0 which includes: • DLMSLib.lib – the library file containing the functions of the DLMS protocol
• DLMS_User.h – the header file which contain the functions APIs prototype and the structures definition.
2.1 Block Diagrams/ Context Diagrams:
The DLMS Server Stack version 1.0 support the lower layer of the Data Link and the Application Layer as explained in
the Green Book. The data link layer is implemented base on the 3-layer, connection-oriented, HDLC-based,
asynchronous communication profile in the chapter 8 of the Green Book. The Physical Interface used is RS-232.
The COSEM Application Layer designed in this stack supports only LN services which passed the Yellow Book AL
test plans. These services are GET and SET. This version of the software has not covered the COSEM object layer in
the Blue Book.
The block diagrams of the supported layers in this stack are shown in figure 2 below:
Server Application (Energy Meter)
Client Application(Automatic Meter Reader)
Server
COSEM Application Layer
Client
COSEM Application Layer
ServerData Link Layer, HLDC based
ClientData Link Layer, HLDC based
Physical LayerPhysical Layer
Physical Channel
COSEM Object Layer
* - DLMS Server Protocol Stack Library v 1.0
Figure 2 DLMS Server Protocol Stack Library v1.0
RX200 Series DLMS Server Protocol Stack
REJxxxxxxx-0600 Rev.6.00 Page 5 of 21
7/14/2011
2.2 Library Memory Size:
The following are compiled using 2nd
optimize level.
• CODE – 9041 bytes
• ROM – 529 bytes
• RAM – 508 bytes
2.3 User Memory Usage:
• Data Receive Buffer >=120 bytes*
• Data Transmit Buffer >=120 bytes*
• Server PDU buffer >= 80 bytes*
*Minimum byte to pass CTTv2.2 Data Link and Application Layer
2.4 Data Type Define
In the DLMS Server Stack library, a single set of data type is defined for the standard C data type in file
“DLMS_User.h”. This set of data type is used in all the APIs in this library. The headers file “DLMS_User.h” must be
included whenever the user wishes to use any of the API. The definitions of the data types are as below:
;typedef signed char Integer8;
;typedef unsigned char Unsigned8;
;typedef signed int Integer16;
;typedef unsigned int Unsigned16;
;typedef signed long Integer32;
;typedef unsigned long Unsigned32;
2.5 Data Structure
Data structures for the DLMS Server Stack library are defined in the file “DLMS_User.h”. These sets of structures are
used by the user to pass in the relevant data into the library. The header file “DLMS_User.h” must be included
whenever the user wishes to use any of the Server Stack API. The definitions of the structures are as below:
2.5.1 st_Association
Data structure to define the security level of a client.
Typedef name Structure Members Description Data Type
client_SAP Service Access Point of the client Unsigned8 st_Association
security_level Security level of the client Unsigned8
2.5.2 st_LogicalDevice
Data structure to define associations of a logical device.
Typedef name Structure Members Description Data Type
server_SAP Service Access Point of the server Unsigned8
*associations Definitions of associations st_Association
st_LogicalDevice
association_number The number of associations Unsigned8
RX200 Series DLMS Server Protocol Stack
REJxxxxxxx-0600 Rev.6.00 Page 6 of 21
7/14/2011
2.5.3 st_ServerConfig
Data structure of the setup configuration parameters for the server device.
Typedef name Structure Members Description Data Type
*SerialRx_Buffer Pointer to the buffer for data received from client Unsigned8
SerialRx_Size Receive data buffer length Unsigned16
*SerialTx_Buffer Pointer to the buffer for data to be transmit to client Unsigned8
SerialTx_Size Transmit data buffer length Unsigned16
SerialTx_FuncPtr Pointer to the user functions for transmitting
response data.
fn_SerialTx
*Server_Buffer Pointer to the PDU buffer for server device. Unsigned8
Server_BufferSize Server PDU buffer maximum size Unsigned16
AdressByteMode Address mode supported by the server, setting
defined in enumeration et_PhysicalAddressMode.
Unsigned8
*ServerPhysicalAddres
s
Physical address of the server Unsigned8
Response_Timeout* The max time waited by a station for the return frame
from the peer station. 1 = 1ms
Unsigned16
Inactivity_Timeout* The time out which started each time n byte is sent/
received from physical layer. 1 = 1ms
Unsigned16
Interframe_Timeout* The max permitted time between start and stop bit of
subsequent bytes within a frame. 1 = 1ms
Unsigned16
Security_Level Security mode by the server, setting defined in
enumeration et_SecurityMode
Unsigned8
*ServerPassword Password required for server accessed. Not
applicable in NO_SECURITY.
Unsigned8
st_ServerConfig
ServerPassword_Len Password length. Not applicable in NO_SECURITY. Unsigned16
*Timeout value can be set base on trigger of the function DataLinkTimeoutCount().
2.5.4 st_Cosem_Attr_Desc
COSEM attribute descriptor structure for the purpose for object layer interface class(IC), attribute type and OBIS code
analyzing.
Typedef name Structure Members Description Data Type
Class_ID[2] COSEM Interface class ID Unsigned8
Instance_ID[6] COSEM Object Instance ID (OBIS) Unsigned8
st_Cosem_Attr_Desc
Attr_ID COSEM Object Attribute ID Unsigned16
2.6 Enumeration
Enumerations for the DLMS Server Stack library are defined in the file “DLMS_User.h”. These sets of enumeration are
used by the user to identify or pass the relevant setting from and to the library. The header file “DLMS_User.h” must be
included whenever the user wishes to use any of the Server Stack API. The definitions of the enumerations are as
below:
RX200 Series DLMS Server Protocol Stack
REJxxxxxxx-0600 Rev.6.00 Page 7 of 21
7/14/2011
2.6.1 et_Datalink_State
Data link status flag. These values can be set/read to or from the library variable DATALINK_State.
enum name Members Value Description
DATALINK_STATE_BEGIN 0 State begins. Datalink ready to receive data.
Must be set by user when Physical layer
transmitting data complete
DATALINK_STATE_RECIEVING 1 Datalink receiving data. No process should
be done.
DATALINK_STATE_TRANSMITING 2 Datalink transmitted data. Must be set by
user when transmitting response data
et_Datalink_State
DATALINK_STATE_READY 3 One frame of data is received from client
and ready to be decoded.
2.6.2 et_HDLC_FrameType
HDLC Frame type returned by the server. These values is returned by function DLMSRequestDecode().
enum name Members Value Description
FRAME_INVALID -1 Corrupted frame sent by client. Do not reply when
DLMSRequestDecode() return this value.
FRAME_SNRM 1 Set Normal Response Mode*
FRAME_UA 2 Unnumbered Acknowledge*
FRAME_I 3 Information Frame*
FRAME_UI, 4 Unnumbered Information Frame*
FRAME_RR, 5 Receive Ready*
FRAME_DISC, 6 Disconnect Command*
FRAME_DM, 7 Disconnect Mode Response*
FRAME_RNR, 8 Receive Not Ready*
et_Datalink_State
FRAME_FRMR 9 Frame reject response*
*Refer to The Green Book for detail explanation for these HDLC frame type.
2.6.3 et_PhysicalAddressMode
Physical address mode supported by the server. These values are set to AdressByteMode in structure st_ServerConfig.
enum name Members Value Description
PHYADD_1BYTE_NOT_SUPPORTED 0 Server support only 4 byte address et_PhysicalAddressMode
PHYADD_1BYTE_SUPPORTED 1 Server able to support only 1 byte,
2 bytes and 4 bytes address
2.6.4 et_SecurityMode
Security mode of the server. These values are set to Security_Level in structure st_ServerConfig.
enum name Members Value Description
NO_SECURITY 0 Server in no security mode. No password authentication
from client required.
et_SecurityMode
LOW_LEVEL_SECURITY 1 Server in low security mode. Password authentication
match to *ServerPassword requiered
RX200 Series DLMS Server Protocol Stack
REJxxxxxxx-0600 Rev.6.00 Page 8 of 21
7/14/2011
2.7 Extern Variable from the Server Stack
These variables must be set by the user so that the server library can process correctly.
Variable name Description Data Type
DATALINK_State Read for Datalink state status.
This variable must be set by user to:
DATALINK_STATE_BEGIN when the user function finishes
transmitting the data to client.
DATALINK_STATE_TRANSMITING when the user function
is transmitting the data to client.
Extern Unsigned8
OBIS_DataLength Data length of OBIS service request by client. This variable
must be set when the server response OBIS data to client.
Extern Unsigned16
2.8 Library Function API
The DLMS Server Stack library functions APIs prototypes are declared in file “DLMS_User.h”. These functions are
called in the user source code to set the device as DLMS server.
2.8.1 DLMSInit ()
Function Prototype:
void DLMSInit ( st_ServerConfig ServerConfig,
st_LogicalDevice LogicalDevice,
st_Association *associations);
Parameter(s):
I/O Data Type Name Description
I st_ServerConfig ServerConfig Structure to configure the server
I st_LogicalDevice LogicalDevice Configuration of the logical device
I st_Association *associations Configuration of Application Associations of the logical device
Return value:
Data Type Name Description
- - -
Description:
Initialization function to configure the server, the information of the logical device in the server and the AA
model of this logical device.
RX200 Series DLMS Server Protocol Stack
REJxxxxxxx-0600 Rev.6.00 Page 9 of 21
7/14/2011
2.8.2 COSEMObjectLayerInit ()
Function Prototype:
void COSEMObjectLayerInit( Unsigned8 *Buffer,
Unsigned16 Buffer_Size,
fn_OBIS OBIS_FuncPtr);
Parameter(s):
I/O Data Type Name Description
I Unsigned8 *Buffer Pointer to the OBIS data buffer
I Unsigned16 Buffer_Size Size of OBIS data buffer
I fn_OBIS OBIS_FuncPtr Function pointer for the user customized OBIS service
function.
Return value:
Data Type Name Description
- - -
Description:
Initialization function for the user customized Object layer. User can pass their relevant OBIS service
function and output data to be response to the client by calling this function.
2.8.3 DLMSRequestDecode ()
Function Prototype:
Integer8 DLMSRequestDecode(void);
Parameter(s):
I/O Data Type Name Description
- - - -
Return value:
Data Type Name Description
Integer8 Frame Type Frame type of the decoded data
Description:
Decode the data received from the physical layer. This functions should be called after checking the
DATALINK_State = DATALINK_STATE_READY, where the single frame of data is ready in the buffer.
2.8.4 DLMSResponseReply ()
Function Prototype:
void DLMSResponseReply(void);
Parameter(s):
I/O Data Type Name Description
- - - -
Return value:
Data Type Name Description
- - -
Description:
Encode the response data to the client and position them into the user buffer pointed by *SerialTx_Buffer
in structure st_ServerConfig. This function will call the user functions for data transmit and OBIS decode.
RX200 Series DLMS Server Protocol Stack
REJxxxxxxx-0600 Rev.6.00 Page 10 of 21
7/14/2011
2.8.5 DataLinkReceiveByte ()
Function Prototype:
void DataLinkReceiveByte(Unsigned8 Byte);
Parameter(s):
I/O Data Type Name Description
I Unsigned8 Byte Input byte receive from the physical layer
Return value:
Data Type Name Description
- - -
Description:
Call this function whenever user’s physical layer received a byte from the physical channel. In serial IO
case, this function can be called in the serial receive interrupt service routine.
2.8.6 DataLinkTimeoutCount ()
Function Prototype:
void DataLinkTimeoutCount(void);
Parameter(s):
I/O Data Type Name Description
- - - -
Return value:
Data Type Name Description
- - -
Description:
This function manages (increase/reset) the counter value for timeout purpose. Ideally, this function should
be called for every 1ms trigger*.
*timer trigger can be set base on the values in Response_Timeout, Inactivity_Timeout, Interframe_Timeout.
2.8.7 COSEMObjectLayerInit ()
Function Prototype:
void COSEMObjectLayerInit( Unsigned8 *Buffer,
Unsigned16 Buffer_Size,
fn_OBIS OBIS_FuncPtr);
Parameter(s):
I/O Data Type Name Description
I Unsigned8 *Buffer Pointer to the OBIS data buffer
I Unsigned16 Buffer_Size Size of OBIS data buffer
I fn_OBIS OBIS_FuncPtr Function pointer for the user customized OBIS service
function.
Return value:
Data Type Name Description
- - -
Description:
Initialization function for the user customized Object layer. User can pass their relevant OBIS service
function and output data to be response to the client by calling this function.
RX200 Series DLMS Server Protocol Stack
REJxxxxxxx-0600 Rev.6.00 Page 11 of 21
7/14/2011
2.9 User Function API
The User functions APIs structure prototypes are declared in file “DLMS_User.h”. These functions called within the
DLMS server library. User need to create this function base on the description in this section and pass them into the
library.
2.9.1 fn_SerialTx ()
Function Prototype:
void (*fn_SerialTx)(Unsigned8* BlockPtr, Integer16 Length);
Parameter(s):
I/O Data Type Name Description
I Unsigned8 *BlockPtr Pointer to the data to be transmit
I Integer16 Length Length of the data to be transmit
Return value:
Data Type Name Description
- - -
Description:
This function is created by the user in physical layer to transmit the response data encode by the server
stack to the physical channel. The block of data to be respond is pointed by *BlockPtr and the total byte of
the block is indicated in parameter Length. Please set the DATALINK_State parameter to
DATALINK_STATE_TRANSMITING while transmitting the data and to DATALINK_STATE_BEGIN after
transmit process complete.
2.9.2 fn_OBIS ()
Function Prototype:
typedef void (*fn_OBIS)(st_Cosem_Attr_Desc *Cosem_Attr_Desc, Unsigned8 *Data);
Parameter(s):
I/O Data Type Name Description
I st_Cosem_Attr_Desc *BlockPtr Pointer to the COSEM attribute descriptor for user customize
OBIS service feature
I/O Unsigned8 *Data Pointer to the data to be set into the server device
Return value:
Data Type Name Description
- - -
Description:
This function is created by the user in object layer to decode the relevant OBIS code and take nessecary
service action. If the client is getting data from the server, the data should be placed into the buffer pointed
in *Buffer and please set the OBIS_DataLength to indicate the total length of the OBIS data to return so that
AL in server stack can take necessary action. If the client is setting data into the server, the data to be set is
pointer in pointer *Data.
RX200 Series DLMS Server Protocol Stack
REJxxxxxxx-0600 Rev.6.00 Page 12 of 21
7/14/2011
2.10 Flowchart
This section shows the flowchart of how the DLMS server stack function should be called. StartDLMSInit();Configurest_ServerConfig
DATALINK_State ==DATALINK_STATE_READY?FrameType =DLMSRequestDecode();FrameType !=FRAME_INVALID?
DLMSResponseReply();
DataLinkReceiveByte()NoYes
Yes *fn_SerialTx();*fn_OBIS();OBIS_DataLength = Length;
* - User Function
Figure 3 Flowchart DLMS Server Stack Functions Calling
RX200 Series DLMS Server Protocol Stack
REJxxxxxxx-0600 Rev.6.00 Page 13 of 21
7/14/2011
3. Sample Program
This section describe about the sample source code and HEW workspace that have been created by using RSK RX210.
The tool chain used is RX Standard Toolchain 1.1.0.0.
3.1 File Structure
Figure below shows the file structure of the workspace.
+�DLMS_code_rx210
+� DLMS_code_rx210
| +�src
| | -�DLMS_code_rx210.c
| | -�main.h
| | -�typedefine.h
| | -�dbsct.c
| | -�hwsetup.c
| | -�hwsetup.h
| | -�resetprg.c
| | -�stacksct.h
| | -�sbrk.c
| | -�sbrk.h
| | +�DLMS
| | | -�r_dlms_user.h
| | | -�r_dlms_datalink_layer.h
| | | -�r_object_layer.c
| | | -�r_object_layer.h
| | | -�r_object_layer_3ph.c
| | | -�r_physical_layer.c
| | | -�r_physical_layer.h
| | | -�r_real_time_clock.c
| | | -�r_real_time_clock.h
| | | -�r_serial.c
| | | -�r_serial.h
| | +�RPDL
| -�DLMS_code_rx210.hwp
| -�DefaultSession.hsf
| +�DLMS_lib_rx
| -� DLMS_lib_rx.lib
| -�DLMS_User.h
-� DLMS_code_rx210.hws
Figure 4 Sample Workspace File Structure
RX200 startup files and driver source files
DLMS object layer and other related files
Sample main files that call the library functions
DLMS Server Protocol Stack Library
HEW workspace file
RPDL files, refer to the workspace
RX200 Series DLMS Server Protocol Stack
REJxxxxxxx-0600 Rev.6.00 Page 14 of 21
7/14/2011
3.2 Main Function
/****************************************************************************
Includes <System Includes> , "Project Includes"
*****************************************************************************/
/* Peripheral driver function prototypes */
#include "r_pdl_cgc.h"
#include "r_pdl_cmt.h"
/* PDL device-specific definitions */
#include "r_pdl_definitions.h"
#include "hwsetup.h"
#include "r_main.h"
/* Headers of DLMS */
#include "r_dlms_user.h"
#include "r_object_layer.h"
/* Physical Layer - serial driver*/
#include "r_serial.h"
#include "r_physical_layer.h"
/****************************************************************************
Typedef definitions
*****************************************************************************/
/*****************************************************************************
Macro definitions
*****************************************************************************/
#define MAX_TRANSMIT_BUFFER_SIZE 120
#define MAX_RECIEVE_BUFFER_SIZE 120
#define MAX_SERVER_BUFFER_SIZE 80
#define ASSOCIATION_NUMBEER 2
/*****************************************************************************
Private global variables and functions
Unsigned8 g_RxBuffer[MAX_RECIEVE_BUFFER_SIZE];
Unsigned8 g_TxBuffer[MAX_TRANSMIT_BUFFER_SIZE];
Unsigned8 g_ServerBuffer[MAX_SERVER_BUFFER_SIZE];
st_ServerConfig g_UserServerConfig;
Unsigned8 g_ServerPhysicalAddress[] = {0x03,0x23,0x00,0x23};
Unsigned8 g_ServerPassword[] = {'A','B','C','D','E','F','G','H'};
st_LogicalDevice g_ManagementLogicalDevice;
st_Association g_Associations[ASSOCIATION_NUMBEER];
/****************************************************************************
Function Name: main
Description: Main function to DLMS server programe
Parameters: None
Return value: None
*****************************************************************************/
Figure 5 Main() Sample Code(1)
RX200 Series DLMS Server Protocol Stack
REJxxxxxxx-0600 Rev.6.00 Page 15 of 21
7/14/2011
void main(void) {
Integer8 frame_type=0;
/* Use Hardware Setup */
HardwareSetup();
/* Physical layer established*/
PhysicalLinkConnect();
/* Initialise Logical devices*/
g_Associations[0].client_SAP = 0x10;
g_Associations[0].security_level = NO_SECURITY;
g_Associations[1].client_SAP = 0x20;
g_Associations[1].security_level = LOW_LEVEL_SECURITY;
g_ManagementLogicalDevice.sever_SAP = 0x01;
g_ManagementLogicalDevice.associations = g_Associations;
g_ManagementLogicalDevice.association_number = ASSOCIATION_NUMBEER;
/* Setup server station */
g_UserServerConfig.SerialRx_Buffer = g_RxBuffer;
g_UserServerConfig.SerialRx_Size = MAX_RECIEVE_BUFFER_SIZE;
g_UserServerConfig.SerialTx_Buffer = g_TxBuffer;
g_UserServerConfig.SerialTx_Size = MAX_TRANSMIT_BUFFER_SIZE;
g_UserServerConfig.SerialTx_FuncPtr = SerialTxBlock;
g_UserServerConfig.Server_Buffer = g_ServerBuffer;
g_UserServerConfig.Server_BufferSize = MAX_SERVER_BUFFER_SIZE;;
g_UserServerConfig.AdressByteMode = PHYADD_1BYTE_SUPPORTED;
g_UserServerConfig.ServerPhysicalAddress = g_ServerPhysicalAddress;
g_UserServerConfig.Response_Timeout = 5000;
g_UserServerConfig.Inactivity_Timeout = 5000;
g_UserServerConfig.Interframe_Timeout = 100;
g_UserServerConfig.Security_Level = NO_SECURITY;
g_UserServerConfig.ServerPassword = g_ServerPassword;
g_UserServerConfig.ServerPassword_Len = 8;
/* Initialize */
DLMSInit(g_UserServerConfig, g_ManagementLogicalDevice, g_Associations);
COSEMObjectLayerInit(&OBIS_Get_Area.Buffer[0],SERVICE_DATA_BUFFER_LEN,ObjectO
BISDecode);
ObjectLayerMemInit();
/* DLMS communication loop */
while (1)
{
if (DATALINK_State == DATALINK_STATE_READY)
{
frame_type = DLMSRequestDecode();
}
//if (frame_type != FRAME_INVALID){
if (frame_type > 0)
{
DLMSResponseReply();
}
};
ObjectLayerMemFree();
}
Figure 6 Main() Sample Code (2)
RX200 Series DLMS Server Protocol Stack
REJxxxxxxx-0600 Rev.6.00 Page 16 of 21
7/14/2011
3.3 Renesas Peripheral Driver Library
The Renesas Peripheral Driver Library (RPDL) is a unified API for controlling the peripheral modules on the
microcontrollers made by Renesas Electronics.
Figure 7 System configuration, with all peripherals supported by RPDL
In the sample source code, RPDL is used for all the following peripherals: CGC, SCI in asynchronous mode, CMT and
RTC. The following two sections give an example how to use RPDL drive SCI.
3.4 SerialTx_FuncPtr User Function
/***************************************************************************
* Function Name: SerialTxBlock
* Description : Transmit block of data through serial communication
* Arguments : Unsigned8* BlockPtr //Pointer to block start address
* Integer16 Length //Length of the data
* Return Value : none
****************************************************************************/
void SerialTxBlock(Unsigned8* BlockPtr, Integer16 Length){
R_SCI_Send(
0, //Select SCI0
PDL_SCI_DMAC_DTC_TRIGGER_DISABLE, // Channel configuration
BlockPtr, // Data start address
Length, // Data count
PDL_NO_FUNC // Callback function
);
/*Set Datalink Flag to indicate Datalink Transmitting*/
DATALINK_State = DATALINK_STATE_BEGIN;
}
Figure 8 SerialTx_FuncPtr Sample Code
RX200 Series DLMS Server Protocol Stack
REJxxxxxxx-0600 Rev.6.00 Page 17 of 21
7/14/2011
3.5 Serial Receiving Interrupt Service Routine
/*****************************************************************************
*
* Function Name: SerialRxISR
* Description : Interupt Service Routine(ISR) when data is recieved from
serial
* communication. Copy data from UART buffer to local global
* variable rcv_buf[].
* Arguments : n1
* Return Value : n1
******************************************************************************
/
void SerialRxISR(void)
{
DataLinkReceiveByte(g_rcv_byte);
R_SCI_Receive(
0, // Channel selection
PDL_SCI_DMAC_DTC_TRIGGER_DISABLE, // Channel configuration
&g_rcv_byte, // Data start address
1, // Receive threshold
SerialRxISR, // Callback function
PDL_NO_FUNC // Callback function
);
}
Figure 9 Serial Transmit Interrupt Service Routine Sample Code
RX200 Series DLMS Server Protocol Stack
REJxxxxxxx-0600 Rev.6.00 Page 18 of 21
7/14/2011
Website and Support
Renesas Electronics Website
http://www.renesas.com/ Inquiries
http://www.renesas.com/inquiry
All trademarks and registered trademarks are the property of their respective owners.
Revision Record
Description
Rev.
Date Page Summary
1.00 Nov.9.10 — First edition issued
2.00 Jul.13.11 — Edited for RX210
General Precautions in the Handling of MPU/MCU Products
The following usage notes are applicable to all MPU/MCU products from Renesas. For detailed usage notes on the
products covered by this manual, refer to the relevant sections of the manual. If the descriptions under General
Precautions in the Handling of MPU/MCU Products and in the body of the manual differ from each other, the
description in the body of the manual takes precedence.
1. Handling of Unused Pins
Handle unused pins in accord with the directions given under Handling of Unused Pins in the manual.
The input pins of CMOS products are generally in the high-impedance state. In operation with an
unused pin in the open-circuit state, extra electromagnetic noise is induced in the vicinity of LSI, an
associated shoot-through current flows internally, and malfunctions occur due to the false
recognition of the pin state as an input signal become possible. Unused pins should be handled as
described under Handling of Unused Pins in the manual.
2. Processing at Power-on
The state of the product is undefined at the moment when power is supplied.
The states of internal circuits in the LSI are indeterminate and the states of register settings and
pins are undefined at the moment when power is supplied.
In a finished product where the reset signal is applied to the external reset pin, the states of pins
are not guaranteed from the moment when power is supplied until the reset process is completed.
In a similar way, the states of pins in a product that is reset by an on-chip power-on reset function
are not guaranteed from the moment when power is supplied until the power reaches the level at
which resetting has been specified.
3. Prohibition of Access to Reserved Addresses
Access to reserved addresses is prohibited.
The reserved addresses are provided for the possible future expansion of functions. Do not access
these addresses; the correct operation of LSI is not guaranteed if they are accessed.
4. Clock Signals
After applying a reset, only release the reset line after the operating clock signal has become stable.
When switching the clock signal during program execution, wait until the target clock signal has
stabilized.
When the clock signal is generated with an external resonator (or from an external oscillator)
during a reset, ensure that the reset line is only released after full stabilization of the clock signal.
Moreover, when switching to a clock signal produced with an external resonator (or by an external
oscillator) while program execution is in progress, wait until the target clock signal is stable.
5. Differences between Products
Before changing from one product to another, i.e. to one with a different type number, confirm that the
change will not lead to problems.
The characteristics of MPU/MCU in the same group but having different type numbers may differ
because of the differences in internal memory capacity and layout pattern. When changing to
products of different type numbers, implement a system-evaluation test for each of the products.
Notice1. All information included in this document is current as of the date this document is issued. Such information, however, is subject to change without any prior notice. Before purchasing or using any Renesas
Electronics products listed herein, please confirm the latest product information with a Renesas Electronics sales office. Also, please pay regular and careful attention to additional and different information to
be disclosed by Renesas Electronics such as that disclosed through our website.
2. Renesas Electronics does not assume any liability for infringement of patents, copyrights, or other intellectual property rights of third parties by or arising from the use of Renesas Electronics products or
technical information described in this document. No license, express, implied or otherwise, is granted hereby under any patents, copyrights or other intellectual property rights of Renesas Electronics or
others.
3. You should not alter, modify, copy, or otherwise misappropriate any Renesas Electronics product, whether in whole or in part.
4. Descriptions of circuits, software and other related information in this document are provided only to illustrate the operation of semiconductor products and application examples. You are fully responsible for
the incorporation of these circuits, software, and information in the design of your equipment. Renesas Electronics assumes no responsibility for any losses incurred by you or third parties arising from the
use of these circuits, software, or information.
5. When exporting the products or technology described in this document, you should comply with the applicable export control laws and regulations and follow the procedures required by such laws and
regulations. You should not use Renesas Electronics products or the technology described in this document for any purpose relating to military applications or use by the military, including but not limited to
the development of weapons of mass destruction. Renesas Electronics products and technology may not be used for or incorporated into any products or systems whose manufacture, use, or sale is
prohibited under any applicable domestic or foreign laws or regulations.
6. Renesas Electronics has used reasonable care in preparing the information included in this document, but Renesas Electronics does not warrant that such information is error free. Renesas Electronics
assumes no liability whatsoever for any damages incurred by you resulting from errors in or omissions from the information included herein.
7. Renesas Electronics products are classified according to the following three quality grades: "Standard", "High Quality", and "Specific". The recommended applications for each Renesas Electronics product
depends on the product's quality grade, as indicated below. You must check the quality grade of each Renesas Electronics product before using it in a particular application. You may not use any Renesas
Electronics product for any application categorized as "Specific" without the prior written consent of Renesas Electronics. Further, you may not use any Renesas Electronics product for any application for
which it is not intended without the prior written consent of Renesas Electronics. Renesas Electronics shall not be in any way liable for any damages or losses incurred by you or third parties arising from the
use of any Renesas Electronics product for an application categorized as "Specific" or for which the product is not intended where you have failed to obtain the prior written consent of Renesas Electronics.
The quality grade of each Renesas Electronics product is "Standard" unless otherwise expressly specified in a Renesas Electronics data sheets or data books, etc.
"Standard": Computers; office equipment; communications equipment; test and measurement equipment; audio and visual equipment; home electronic appliances; machine tools;
personal electronic equipment; and industrial robots.
"High Quality": Transportation equipment (automobiles, trains, ships, etc.); traffic control systems; anti-disaster systems; anti-crime systems; safety equipment; and medical equipment not specifically
designed for life support.
"Specific": Aircraft; aerospace equipment; submersible repeaters; nuclear reactor control systems; medical equipment or systems for life support (e.g. artificial life support devices or systems), surgical
implantations, or healthcare intervention (e.g. excision, etc.), and any other applications or purposes that pose a direct threat to human life.
8. You should use the Renesas Electronics products described in this document within the range specified by Renesas Electronics, especially with respect to the maximum rating, operating supply voltage
range, movement power voltage range, heat radiation characteristics, installation and other product characteristics. Renesas Electronics shall have no liability for malfunctions or damages arising out of the
use of Renesas Electronics products beyond such specified ranges.
9. Although Renesas Electronics endeavors to improve the quality and reliability of its products, semiconductor products have specific characteristics such as the occurrence of failure at a certain rate and
malfunctions under certain use conditions. Further, Renesas Electronics products are not subject to radiation resistance design. Please be sure to implement safety measures to guard them against the
possibility of physical injury, and injury or damage caused by fire in the event of the failure of a Renesas Electronics product, such as safety design for hardware and software including but not limited to
redundancy, fire control and malfunction prevention, appropriate treatment for aging degradation or any other appropriate measures. Because the evaluation of microcomputer software alone is very difficult,
please evaluate the safety of the final products or system manufactured by you.
10. Please contact a Renesas Electronics sales office for details as to environmental matters such as the environmental compatibility of each Renesas Electronics product. Please use Renesas Electronics
products in compliance with all applicable laws and regulations that regulate the inclusion or use of controlled substances, including without limitation, the EU RoHS Directive. Renesas Electronics assumes
no liability for damages or losses occurring as a result of your noncompliance with applicable laws and regulations.
11. This document may not be reproduced or duplicated, in any form, in whole or in part, without prior written consent of Renesas Electronics.
12. Please contact a Renesas Electronics sales office if you have any questions regarding the information contained in this document or Renesas Electronics products, or if you have any other inquiries.
(Note 1) "Renesas Electronics" as used in this document means Renesas Electronics Corporation and also includes its majority-owned subsidiaries.
(Note 2) "Renesas Electronics product(s)" means any product developed or manufactured by or for Renesas Electronics.
http://www.renesas.com
Refer to "http://www.renesas.com/" for the latest and detailed information.
Renesas Electronics America Inc. 2880 Scott Boulevard Santa Clara, CA 95050-2554, U.S.A.Tel: +1-408-588-6000, Fax: +1-408-588-6130
Renesas Electronics Canada Limited1101 Nicholson Road, Newmarket, Ontario L3Y 9C3, CanadaTel: +1-905-898-5441, Fax: +1-905-898-3220
Renesas Electronics Europe LimitedDukes Meadow, Millboard Road, Bourne End, Buckinghamshire, SL8 5FH, U.KTel: +44-1628-585-100, Fax: +44-1628-585-900
Renesas Electronics Europe GmbH
Arcadiastrasse 10, 40472 Düsseldorf, Germany Tel: +49-211-6503-0, Fax: +49-211-6503-1327
Renesas Electronics (China) Co., Ltd.7th Floor, Quantum Plaza, No.27 ZhiChunLu Haidian District, Beijing 100083, P.R.China Tel: +86-10-8235-1155, Fax: +86-10-8235-7679
Renesas Electronics (Shanghai) Co., Ltd.Unit 204, 205, AZIA Center, No.1233 Lujiazui Ring Rd., Pudong District, Shanghai 200120, China Tel: +86-21-5877-1818, Fax: +86-21-6887-7858 / -7898
Renesas Electronics Hong Kong LimitedUnit 1601-1613, 16/F., Tower 2, Grand Century Place, 193 Prince Edward Road West, Mongkok, Kowloon, Hong KongTel: +852-2886-9318, Fax: +852 2886-9022/9044
Renesas Electronics Taiwan Co., Ltd.7F, No. 363 Fu Shing North Road Taipei, Taiwan, R.O.C.Tel: +886-2-8175-9600, Fax: +886 2-8175-9670
Renesas Electronics Singapore Pte. Ltd. 1 harbourFront Avenue, #06-10, keppel Bay Tower, Singapore 098632Tel: +65-6213-0200, Fax: +65-6278-8001
Renesas Electronics Malaysia Sdn.Bhd. Unit 906, Block B, Menara Amcorp, Amcorp Trade Centre, No. 18, Jln Persiaran Barat, 46050 Petaling Jaya, Selangor Darul Ehsan, MalaysiaTel: +60-3-7955-9390, Fax: +60-3-7955-9510
Renesas Electronics Korea Co., Ltd.11F., Samik Lavied' or Bldg., 720-2 Yeoksam-Dong, Kangnam-Ku, Seoul 135-080, KoreaTel: +82-2-558-3737, Fax: +82-2-558-5141
SALES OFFICES
© 2010 Renesas Electronics Corporation. All rights reserved.
Colophon 1.0