diff --git a/bacnet-stack/ports/rx62n/BACnet_Ethernet_RX62N.hwp b/bacnet-stack/ports/rx62n/BACnet_Ethernet_RX62N.hwp new file mode 100644 index 00000000..414a3346 --- /dev/null +++ b/bacnet-stack/ports/rx62n/BACnet_Ethernet_RX62N.hwp @@ -0,0 +1,310 @@ +[HIMDBVersion] +2.0 +[DATABASE_VERSION] +"2.8" +[PROJECT_DETAILS] +"BACnet_Ethernet_RX62N" "C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N" "C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N.hwp" "RX" "Renesas RX Standard" "Application" "" "" +[INFORMATION] +"No project information available" +[TOOL_CHAIN] +"Renesas RX Standard Toolchain" "1.0.1.0" +[CONFIGURATIONS] +"Debug" "C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\Debug" +[BUILD_PHASES] +"Renesas OptLinker" 1 +"Renesas RX Assembler" 1 +"Renesas RX C/C++ Compiler" 1 +"Renesas RX C/C++ Library Generator" 1 +"Renesas RX Configurator" 1 +[TOOL_ENVIRONMENT] +[EXTENSIONS] +"Absolute file" "ABS" +"Assembly include file" "INC" +"Assembly list file" "LST" +"Assembly source file" "S" +"Assembly source file" "SRC" +"Binary file" "BIN" +"C header file" "H" +"C source file" "C" +"C++ header file" "HPP" +"C++ source file" "CC" +"C++ source file" "CP" +"C++ source file" "CPP" +"CPU information file" "CPU" +"Calling information file" "CAL" +"Configuration file" "CFG" +"Debug information file" "DBG" +"Hex file" "HEX" +"Library file" "LIB" +"Library information file" "LBP" +"Linkage map file" "MAP" +"Linkage symbol file" "FSY" +"Object file" "OBJ" +"Optimize map file" "bls" +"Preprocessed C source file" "P" +"Preprocessed C++ source file" "PP" +"Relocatable file" "REL" +"Rts information file" "RTS" +"S-Record file" "MOT" +"Stack information file" "SNI" +"TD include object file" "RTI" +[FILE_GROUPS] +"Absolute file" "BIN" "NONE" "" +"Assembly include file" "TEXT" "EDITOR" "" +"Assembly list file" "TEXT" "EDITOR" "" +"Assembly source file" "TEXT" "EDITOR" "" +"Binary file" "BIN" "NONE" "" +"C header file" "TEXT" "EDITOR" "" +"C source file" "TEXT" "EDITOR" "" +"C++ header file" "TEXT" "EDITOR" "" +"C++ source file" "TEXT" "EDITOR" "" +"CPU information file" "BIN" "NONE" "" +"Calling information file" "BIN" "NONE" "" +"Configuration file" "TEXT" "EDITOR" "" +"Debug information file" "BIN" "NONE" "" +"Hex file" "TEXT" "EDITOR" "" +"Library file" "BIN" "NONE" "" +"Library information file" "TEXT" "EDITOR" "" +"Linkage map file" "TEXT" "EDITOR" "" +"Linkage symbol file" "TEXT" "EDITOR" "" +"Object file" "BIN" "NONE" "" +"Optimize map file" "BIN" "NONE" "" +"Preprocessed C source file" "TEXT" "EDITOR" "" +"Preprocessed C++ source file" "TEXT" "EDITOR" "" +"Relocatable file" "BIN" "NONE" "" +"Rts information file" "BIN" "NONE" "" +"S-Record file" "TEXT" "EDITOR" "" +"Stack information file" "BIN" "NONE" "" +"TD include object file" "BIN" "NONE" "" +[ASSOCIATED_APPLICATIONS] +[TOOLCHAIN_PHASE] +"Renesas OptLinker" +"Renesas RX Assembler" +"Renesas RX C/C++ Compiler" +"Renesas RX C/C++ Library Generator" +"Renesas RX Configurator" +[UTILITY_PHASE] +[CUSTOM_PHASES] +[CUSTOM_PHASE_INPUT_GROUP] +[CUSTOM_PHASE_OUTPUT_SYNTAX] +[BUILD_ORDER] +"Renesas RX C/C++ Library Generator" 1 +"Renesas RX C/C++ Compiler" 1 +"Renesas RX Assembler" 1 +"Renesas OptLinker" 1 +"Renesas RX Configurator" 0 +[BUILD_PHASE_DETAILS] +"Renesas OptLinker" "Object file|Library file|Relocatable file" 0 +"Renesas RX Assembler" "Assembly source file|Linkage symbol file" 1 +"Renesas RX C/C++ Compiler" "C source file|C++ source file" 1 +"Renesas RX C/C++ Library Generator" "" 0 +"Renesas RX Configurator" "Configuration file" 0 +[BUILD_FILE_ORDER_Assembly source file] +"Renesas RX Assembler" 1 +[BUILD_FILE_ORDER_C source file] +"Renesas RX C/C++ Compiler" 1 +[BUILD_FILE_ORDER_C++ source file] +"Renesas RX C/C++ Compiler" 1 +[BUILD_FILE_ORDER_Linkage symbol file] +"Renesas RX Assembler" 1 +[SCRAP] +"Project Generator Setup File" "" +[MAPPINGS] +"Assembly source file" "Renesas RX Assembler" "Renesas RX C/C++ Compiler" +"Library file" "Renesas OptLinker" "Renesas RX C/C++ Library Generator" +"Object file" "Renesas OptLinker" "Renesas RX Assembler" +"Object file" "Renesas OptLinker" "Renesas RX C/C++ Compiler" +[PROJECT_FILES] +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\demo\handler\h_dcc.c" "User" "C source file|BACnet|Handler" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\demo\handler\h_npdu.c" "User" "C source file|BACnet|Handler" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\demo\handler\h_rd.c" "User" "C source file|BACnet|Handler" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\demo\handler\h_rp.c" "User" "C source file|BACnet|Handler" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\demo\handler\h_rpm.c" "User" "C source file|BACnet|Handler" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\demo\handler\h_whohas.c" "User" "C source file|BACnet|Handler" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\demo\handler\h_whois.c" "User" "C source file|BACnet|Handler" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\demo\handler\h_wp.c" "User" "C source file|BACnet|Handler" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\demo\handler\noserv.c" "User" "C source file|BACnet|Handler" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\demo\handler\s_iam.c" "User" "C source file|BACnet|Handler" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\demo\handler\s_ihave.c" "User" "C source file|BACnet|Handler" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\demo\handler\txbuf.c" "User" "C source file|BACnet|Handler" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\RPDL\Interrupt_ADC_10.c" "User" "C source file|RPDL" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\RPDL\Interrupt_ADC_12.c" "User" "C source file|RPDL" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\RPDL\Interrupt_BSC.c" "User" "C source file|RPDL" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\RPDL\Interrupt_CMT.c" "User" "C source file|RPDL" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\RPDL\Interrupt_DMAC.c" "User" "C source file|RPDL" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\RPDL\Interrupt_IIC.c" "User" "C source file|RPDL" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\RPDL\Interrupt_INTC.c" "User" "C source file|RPDL" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\RPDL\Interrupt_MTU.c" "User" "C source file|RPDL" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\RPDL\Interrupt_POE.c" "User" "C source file|RPDL" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\RPDL\Interrupt_SCI.c" "User" "C source file|RPDL" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\RPDL\Interrupt_SPI.c" "User" "C source file|RPDL" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\RPDL\Interrupt_TMR.c" "User" "C source file|RPDL" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\RPDL\Interrupt_WDT.c" "User" "C source file|RPDL" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\RPDL\Interrupt_not_RPDL.c" "User" "C source file|RPDL" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\bacnet\bacnet.c" "User" "C source file" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\bacnet\bacnet.h" "User" "C header file" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\bacnet\bo.c" "User" "C source file" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\bacnet\device.c" "User" "C source file" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\bacnet\ethernet.c" "User" "C source file" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\bacnet\hardware.h" "User" "C header file" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\bacnet\led.c" "User" "C source file" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\bacnet\led.h" "User" "C header file" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\bacnet\main.c" "User" "C source file" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\bacnet\timer-hdw.c" "User" "C source file" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\bacnet\timer.c" "User" "C source file" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\bacnet\timer.h" "User" "C header file" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\bsp\GlyphLib_v2.lib" "User" "Library file" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\bsp\YRDKRX62N_RSPI_API.c" "User" "C source file|bsp" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\bsp\dbsct.c" "User" "C source file|bsp" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\bsp\hwsetup.c" "User" "C source file|bsp" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\bsp\lcd.c" "User" "C source file|bsp" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\bsp\resetprg.c" "User" "C source file|bsp" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\bsp\sbrk.c" "User" "C source file|bsp" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\bsp\switch.c" "User" "C source file|bsp" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\driver\phy.c" "User" "C source file|driver" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\driver\r_ether.c" "User" "C source file|driver" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\src\abort.c" "User" "C source file|BACnet|Core" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\src\apdu.c" "User" "C source file|BACnet|Core" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\src\bacapp.c" "User" "C source file" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\src\bacdcode.c" "User" "C source file|BACnet|Core" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\src\bacerror.c" "User" "C source file|BACnet|Core" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\src\bacint.c" "User" "C source file|BACnet|Core" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\src\bacprop.c" "User" "C source file|BACnet|Core" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\src\bacreal.c" "User" "C source file|BACnet|Core" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\src\bacstr.c" "User" "C source file|BACnet|Core" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\src\datetime.c" "User" "C source file|BACnet|Core" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\src\dcc.c" "User" "C source file|BACnet|Core" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\src\iam.c" "User" "C source file|BACnet|Core" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\src\ihave.c" "User" "C source file|BACnet|Core" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\src\memcopy.c" "User" "C source file|BACnet|Core" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\src\npdu.c" "User" "C source file|BACnet|Core" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\src\rd.c" "User" "C source file|BACnet|Core" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\src\reject.c" "User" "C source file|BACnet|Core" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\src\rp.c" "User" "C source file|BACnet|Core" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\src\rpm.c" "User" "C source file|BACnet|Core" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\src\version.c" "User" "C source file|BACnet|Core" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\src\whohas.c" "User" "C source file|BACnet|Core" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\src\whois.c" "User" "C source file|BACnet|Core" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\src\wp.c" "User" "C source file|BACnet|Core" 2 +[FOLDER] +"C header file" "C header file" +"C source file" "C source file" +"C source file|BACnet" "" +"C source file|BACnet|Core" "" +"C source file|BACnet|Handler" "" +"C source file|RPDL" "" +"C source file|bsp" "" +"C source file|driver" "" +"C source file|user-app" "" +"Library file" "Library file" +[GENERAL_DATA_PROJECT] +"USE_CUSTOM_LINKAGE_ORDER" "0" +[ON_DEMAND_COMPONENTS_LOADED] +[SYNC_SESSION_NAMES] +[SESSIONS] +"DefaultSession" "C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\DefaultSession.hsf" 0 +"JLink" "C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\JLink.hsf" 0 +[GENERAL_DATA_SESSION_DefaultSession] +[GENERAL_DATA_SESSION_JLink] +[OPTIONS_Debug_Renesas OptLinker] +"Single Shot" "0c5147307f9dbc10" 5 +[OPTIONS_Debug_Renesas RX Assembler] +"Assembly source file" "091c6ad95f42bc10" 4 +"Linkage symbol file" "091c6ad95f42bc10" 4 +[OPTIONS_Debug_Renesas RX C/C++ Compiler] +"C source file" "0e4b370aaf9dbc10" 2 +"C++ source file" "0e4b370aaf9dbc10" 3 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\demo\handler\h_dcc.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\demo\handler\h_npdu.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\demo\handler\h_rd.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\demo\handler\h_rp.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\demo\handler\h_rpm.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\demo\handler\h_whohas.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\demo\handler\h_whois.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\demo\handler\h_wp.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\demo\handler\noserv.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\demo\handler\s_iam.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\demo\handler\s_ihave.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\demo\handler\txbuf.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\RPDL\Interrupt_ADC_10.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\RPDL\Interrupt_ADC_12.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\RPDL\Interrupt_BSC.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\RPDL\Interrupt_CMT.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\RPDL\Interrupt_DMAC.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\RPDL\Interrupt_IIC.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\RPDL\Interrupt_INTC.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\RPDL\Interrupt_MTU.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\RPDL\Interrupt_POE.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\RPDL\Interrupt_SCI.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\RPDL\Interrupt_SPI.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\RPDL\Interrupt_TMR.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\RPDL\Interrupt_WDT.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\RPDL\Interrupt_not_RPDL.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\bacnet\bacnet.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\bacnet\bo.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\bacnet\device.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\bacnet\ethernet.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\bacnet\led.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\bacnet\main.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\bacnet\timer-hdw.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\bacnet\timer.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\bsp\YRDKRX62N_RSPI_API.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\bsp\dbsct.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\bsp\hwsetup.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\bsp\lcd.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\bsp\resetprg.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\bsp\sbrk.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\bsp\switch.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\driver\phy.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\ports\rx62n\BACnet_Ethernet_RX62N\BACnet_Ethernet_RX62N\src\driver\r_ether.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\src\abort.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\src\apdu.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\src\bacapp.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\src\bacdcode.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\src\bacerror.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\src\bacint.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\src\bacprop.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\src\bacreal.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\src\bacstr.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\src\datetime.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\src\dcc.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\src\iam.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\src\ihave.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\src\memcopy.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\src\npdu.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\src\rd.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\src\reject.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\src\rp.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\src\rpm.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\src\version.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\src\whohas.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\src\whois.c" "0e4b370aaf9dbc10" 2 +"C:\Documents and Settings\VMWare\My Documents\bacnet-stack\src\wp.c" "0e4b370aaf9dbc10" 2 +[OPTIONS_Debug_Renesas RX C/C++ Library Generator] +"Single Shot" "0bffac16d909bc10" 1 +[OPTIONS_Debug_Renesas RX Configurator] +"Single Shot" "0f2016307f9dbc10" 6 +[OPTIONS_Debug] +"" 0 +"[V|VERSION|1] [B|COMMAND|1] [S|SPEC|UITRON4] [S|OUTPUTPATH|^"$(CONFIGDIR)^"] [S|CPU|RX600] [S|ENDIAN|LITTLE] [S|FINT_REGISTER|0] [S|PATCH|RX610]" 6 +"[V|VERSION|1] [B|DEBUG|1] [S|OUTPUTPATH|^"$(CONFIGDIR)\$(FILELEAF).obj^"] [B|LISTFILE|0] [S|CPU|RX600] [S|ENDIAN|LITTLE] [S|FINT_REGISTER|0] [S|PATCH|RX610]" 4 +"[V|VERSION|1] [S|LANG|CPP] [B|SJIS|1] [S|INCLUDE|^"$(PROJDIR)\src\bacnet^"|^"$(PROJDIR)\..\..\..\..\include^"|^"$(PROJDIR)\src\bsp^"|^"$(PROJDIR)\src\driver^"|^"$(PROJDIR)\src\RPDL^"] [S|DEFINE|BACDL_ETHERNET|MAX_TSM_TRANSACTIONS=0] [S|OUTPUTPATH|^"$(CONFIGDIR)\$(FILELEAF).obj^"] [B|DEBUG|1] [S|OPTIMIZE|0] [B|SIZE|1] [B|MAP|0] [I|INLINE|100] [I|LOOP|2] [S|MISRA2004_CHECK_RULE|ALL] [S|MISRA2004_RULE|1.1|3.4|4.1|5.2|5.3|5.4|5.5|5.6|5.7|6.1|6.2|6.3|6.4|6.5|7.1|8.1|8.2|8.3|8.5|8.6|8.7|8.8|8.11|8.12|9.2|9.3|10.1|10.2|10.3|10.4|10.5|10.6|11.1|11.2|11.3|11.4|11.5|12.1|12.2|12.3|12.4|12.5|12.6|12.7|12.8|12.9|12.10|12.11|12.12|12.13|13.1|13.2|13.3|13.4|13.7|14.1|14.2|14.3|14.4|14.5|14.6|14.7|14.8|14.9|14.10|15.1|15.2|15.3|15.4|15.5|16.1|16.2|16.3|16.4|16.5|16.6|16.8|16.9|17.3|17.4|17.5|17.6|18.1|18.2|18.4|19.1|20.2|20.4|20.5|20.7|20.8|20.9|20.10|20.11|20.12] [S|MISRA1998_CHECK_RULE|ALL] [S|MISRA1998_RULE|1|5|8|12|13|14|17|18|19|20|21|22|24|28|29|31|32|33|34|35|36|37|38|39|40|42|43|44|45|46|48|49|50|51|53|54|55|56|57|58|59|60|61|62|63|64|65|68|69|70|71|72|73|74|75|76|77|78|79|80|82|83|84|85|99|101|102|103|104|105|106|108|110|111|112|113|115|118|119|121|122|123|124|125|126|127] [S|MISRA_GROUP_FILE_PATH|^"$(PROJDIR)\$(PROJECTNAME).rde^"] [S|CPU|RX600] [S|BASE|00000000=NONE] [S|PATCH|RX610] +" 3 +"[V|VERSION|1] [S|LANG|C] [B|SJIS|1] [S|INCLUDE|^"$(PROJDIR)\src\bacnet^"|^"$(PROJDIR)\..\..\..\..\include^"|^"$(PROJDIR)\src\bsp^"|^"$(PROJDIR)\src\driver^"|^"$(PROJDIR)\src\RPDL^"] [S|DEFINE|BACDL_ETHERNET|MAX_TSM_TRANSACTIONS=0] [S|OUTPUTPATH|^"$(CONFIGDIR)\$(FILELEAF).obj^"] [B|DEBUG|1] [S|OPTIMIZE|0] [B|SIZE|1] [B|MAP|0] [I|INLINE|100] [I|LOOP|2] [S|MISRA2004_CHECK_RULE|ALL] [S|MISRA2004_RULE|1.1|3.4|4.1|5.2|5.3|5.4|5.5|5.6|5.7|6.1|6.2|6.3|6.4|6.5|7.1|8.1|8.2|8.3|8.5|8.6|8.7|8.8|8.11|8.12|9.2|9.3|10.1|10.2|10.3|10.4|10.5|10.6|11.1|11.2|11.3|11.4|11.5|12.1|12.2|12.3|12.4|12.5|12.6|12.7|12.8|12.9|12.10|12.11|12.12|12.13|13.1|13.2|13.3|13.4|13.7|14.1|14.2|14.3|14.4|14.5|14.6|14.7|14.8|14.9|14.10|15.1|15.2|15.3|15.4|15.5|16.1|16.2|16.3|16.4|16.5|16.6|16.8|16.9|17.3|17.4|17.5|17.6|18.1|18.2|18.4|19.1|20.2|20.4|20.5|20.7|20.8|20.9|20.10|20.11|20.12] [S|MISRA1998_CHECK_RULE|ALL] [S|MISRA1998_RULE|1|5|8|12|13|14|17|18|19|20|21|22|24|28|29|31|32|33|34|35|36|37|38|39|40|42|43|44|45|46|48|49|50|51|53|54|55|56|57|58|59|60|61|62|63|64|65|68|69|70|71|72|73|74|75|76|77|78|79|80|82|83|84|85|99|101|102|103|104|105|106|108|110|111|112|113|115|118|119|121|122|123|124|125|126|127] [S|MISRA_GROUP_FILE_PATH|^"$(PROJDIR)\$(PROJECTNAME).rde^"] [S|CPU|RX600] [S|BASE|00000000=NONE] [S|PATCH|RX610] +" 2 +"[V|VERSION|1] [S|MODE|BUILD/CHANGED] [S|EXISTOUTPUTPATH|^"$(CONFIGDIR)\$(PROJECTNAME).lib^"] [B|RUNTIME|1] [B|STDIO|1] [B|STDLIB|1] [B|STRING|1] [B|NEW|1] [S|OUTPUTPATH|^"$(CONFIGDIR)\$(PROJECTNAME).lib^"] [B|SIZE|1] [I|INLINE|100] [I|LOOP|2] [S|CPU|RX600] [S|BASE|00000000=NONE] [S|PATCH|RX610] +" 1 +"[V|VERSION|6] [S|INPUTLIBRARY|^"$(PROJDIR)\src\RPDL\RX62N_library.lib^"] [S|PRELINK|SKIP] [S|FORM|STYPE] [S|BYTE_COUNT_VALUE|FF] [B|DEBUG|1] [S|ROM|(D,R)|(D_1,R_1)|(D_2,R_2)] [S|CRC|NONE|DEFAULT|00000000] [S|SHOW|METHODCUSTOM|] [S|OUTPUT|^"$(CONFIGDIR)\$(PROJECTNAME).mot^"] [I|SPACE|^"FF^"] [B|OPTIMIZE|0] [S|START|B_RX_DESC,B_TX_DESC,B_RX_BUFF_1,B_TX_BUFF_1,B_1,R_1,B_2,R_2,B,R,SU,SI(01000)|PResetPRG,C_1,C_2,C,C$*,D*,P,W*(0FFF80000)|C_FLASH_CONFIG_PARAMS_1(0FFFFFF00)|FIXEDVECT(0FFFFFFD0)] +" 5 +[EXCLUDED_FILES_Debug] +[LINKAGE_ORDER_Debug] +[GENERAL_DATA_CONFIGURATION_Debug] +[GENERAL_DATA_CONFIGURATION_SESSION_Debug_DefaultSession] +[SESSION_DATA_CONFIGURATION_SESSION_Debug_DefaultSession] +"MEMORY_MAPPING_OPTIONS" "" +[GENERAL_DATA_CONFIGURATION_SESSION_Debug_JLink] +[SESSION_DATA_CONFIGURATION_SESSION_Debug_JLink] +"MEMORY_MAPPING_OPTIONS" "" +[EXT_DEBUGGER_INFO] +0 "" "" "" "" +[END] diff --git a/bacnet-stack/ports/rx62n/bacnet.c b/bacnet-stack/ports/rx62n/bacnet.c new file mode 100644 index 00000000..3b77325f --- /dev/null +++ b/bacnet-stack/ports/rx62n/bacnet.c @@ -0,0 +1,120 @@ +/************************************************************************** +* +* Copyright (C) 2011 Steve Karg +* +* Permission is hereby granted, free of charge, to any person obtaining +* a copy of this software and associated documentation files (the +* "Software"), to deal in the Software without restriction, including +* without limitation the rights to use, copy, modify, merge, publish, +* distribute, sublicense, and/or sell copies of the Software, and to +* permit persons to whom the Software is furnished to do so, subject to +* the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +* +*********************************************************************/ +#include +#include +/* hardware layer includes */ +#include "hardware.h" +#include "timer.h" +#include "led.h" +/* BACnet Stack includes */ +#include "datalink.h" +#include "npdu.h" +#include "handlers.h" +#include "client.h" +#include "txbuf.h" +#include "dcc.h" +#include "iam.h" +#include "device.h" +#include "bo.h" +/* me */ +#include "bacnet.h" + +/* timer for device communications control */ +static struct itimer DCC_Timer; +#define DCC_CYCLE_SECONDS 1 + +void bacnet_init( + void) +{ + /* initialize objects */ + Device_Init(); + + /* set up our confirmed service unrecognized service handler - required! */ + apdu_set_unrecognized_service_handler_handler + (handler_unrecognized_service); + /* we need to handle who-is to support dynamic device binding */ + apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS, handler_who_is); + apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_HAS, handler_who_has); + /* Set the handlers for any confirmed services that we support. */ + /* We must implement read property - it's required! */ + apdu_set_confirmed_handler(SERVICE_CONFIRMED_READ_PROPERTY, + handler_read_property); + apdu_set_confirmed_handler(SERVICE_CONFIRMED_READ_PROP_MULTIPLE, + handler_read_property_multiple); + apdu_set_confirmed_handler(SERVICE_CONFIRMED_REINITIALIZE_DEVICE, + handler_reinitialize_device); + apdu_set_confirmed_handler(SERVICE_CONFIRMED_WRITE_PROPERTY, + handler_write_property); + /* handle communication so we can shutup when asked */ + apdu_set_confirmed_handler(SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL, + handler_device_communication_control); + /* start the cyclic 1 second timer for DCC */ + timer_interval_start_seconds(&DCC_Timer, DCC_CYCLE_SECONDS); + /* Hello World! */ + Send_I_Am(&Handler_Transmit_Buffer[0]); +} + +static uint8_t PDUBuffer[MAX_MPDU]; +void bacnet_task( + void) +{ + uint16_t pdu_len; + BACNET_ADDRESS src; /* source address */ + uint8_t i; + BACNET_BINARY_PV binary_value = BINARY_INACTIVE; + BACNET_POLARITY polarity; + bool out_of_service; + + /* Binary Output */ + for (i = 0; i < MAX_BINARY_OUTPUTS; i++) { + out_of_service = Binary_Output_Out_Of_Service(i); + if (!out_of_service) { + binary_value = Binary_Output_Present_Value(i); + polarity = Binary_Output_Polarity(i); + if (polarity != POLARITY_NORMAL) { + if (binary_value == BINARY_ACTIVE) { + binary_value = BINARY_INACTIVE; + } else { + binary_value = BINARY_ACTIVE; + } + } + if (binary_value == BINARY_ACTIVE) { + led_on(i); + } else { + led_off(i); + } + } + } + /* handle the communication timer */ + if (timer_interval_expired(&DCC_Timer)) { + timer_interval_reset(&DCC_Timer); + dcc_timer_seconds(DCC_CYCLE_SECONDS); + } + /* handle the messaging */ + pdu_len = datalink_receive(&src, &PDUBuffer[0], sizeof(PDUBuffer), 0); + if (pdu_len) { + npdu_handler(&src, &PDUBuffer[0], pdu_len); + } +} diff --git a/bacnet-stack/ports/rx62n/bacnet.h b/bacnet-stack/ports/rx62n/bacnet.h new file mode 100644 index 00000000..ee352604 --- /dev/null +++ b/bacnet-stack/ports/rx62n/bacnet.h @@ -0,0 +1,41 @@ +/************************************************************************** +* +* Copyright (C) 2010 Steve Karg +* +* Permission is hereby granted, free of charge, to any person obtaining +* a copy of this software and associated documentation files (the +* "Software"), to deal in the Software without restriction, including +* without limitation the rights to use, copy, modify, merge, publish, +* distribute, sublicense, and/or sell copies of the Software, and to +* permit persons to whom the Software is furnished to do so, subject to +* the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*********************************************************************/ +#ifndef BACNET_H +#define BACNET_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + + void bacnet_init( + void); + void bacnet_task( + void); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif diff --git a/bacnet-stack/ports/rx62n/bo.c b/bacnet-stack/ports/rx62n/bo.c new file mode 100644 index 00000000..a8af0727 --- /dev/null +++ b/bacnet-stack/ports/rx62n/bo.c @@ -0,0 +1,499 @@ +/************************************************************************** +* +* Copyright (C) 2011 Steve Karg +* +* Permission is hereby granted, free of charge, to any person obtaining +* a copy of this software and associated documentation files (the +* "Software"), to deal in the Software without restriction, including +* without limitation the rights to use, copy, modify, merge, publish, +* distribute, sublicense, and/or sell copies of the Software, and to +* permit persons to whom the Software is furnished to do so, subject to +* the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +* +*********************************************************************/ + +/* Binary Output Objects - customize for your use */ + +#include +#include +#include +#include "bacdef.h" +#include "bacdcode.h" +#include "bacenum.h" +#include "config.h" /* the custom stuff */ +#include "wp.h" +#include "hardware.h" +#include "led.h" +#include "bo.h" +#include "handlers.h" + +#ifndef MAX_BINARY_OUTPUTS +#define MAX_BINARY_OUTPUTS 2 +#endif + +/* When all the priorities are level null, the present value returns */ +/* the Relinquish Default value */ +#define RELINQUISH_DEFAULT BINARY_INACTIVE +/* Here is our Priority Array.*/ +static uint8_t Binary_Output_Level[MAX_BINARY_OUTPUTS][BACNET_MAX_PRIORITY]; +/* Writable out-of-service allows others to play with our Present Value */ +/* without changing the physical output */ +static uint8_t Out_Of_Service[MAX_BINARY_OUTPUTS]; +/* polarity - normal or inverse */ +static uint8_t Polarity[MAX_BINARY_OUTPUTS]; + +/* These three arrays are used by the ReadPropertyMultiple handler */ +static const int Binary_Output_Properties_Required[] = { + PROP_OBJECT_IDENTIFIER, + PROP_OBJECT_NAME, + PROP_OBJECT_TYPE, + PROP_PRESENT_VALUE, + PROP_STATUS_FLAGS, + PROP_EVENT_STATE, + PROP_OUT_OF_SERVICE, + PROP_POLARITY, + PROP_PRIORITY_ARRAY, + PROP_RELINQUISH_DEFAULT, + -1 +}; + +static const int Binary_Output_Properties_Optional[] = { + PROP_ACTIVE_TEXT, + PROP_INACTIVE_TEXT, + -1 +}; + +static const int Binary_Output_Properties_Proprietary[] = { + -1 +}; + +void Binary_Output_Property_Lists( + const int **pRequired, + const int **pOptional, + const int **pProprietary) +{ + if (pRequired) + *pRequired = Binary_Output_Properties_Required; + if (pOptional) + *pOptional = Binary_Output_Properties_Optional; + if (pProprietary) + *pProprietary = Binary_Output_Properties_Proprietary; + + return; +} + +/* we simply have 0-n object instances. */ +bool Binary_Output_Valid_Instance( + uint32_t object_instance) +{ + if (object_instance < MAX_BINARY_OUTPUTS) + return true; + + return false; +} + +/* we simply have 0-n object instances. */ +unsigned Binary_Output_Count( + void) +{ + return MAX_BINARY_OUTPUTS; +} + +/* we simply have 0-n object instances. */ +uint32_t Binary_Output_Index_To_Instance( + unsigned index) +{ + return index; +} + +/* we simply have 0-n object instances. */ +unsigned Binary_Output_Instance_To_Index( + uint32_t object_instance) +{ + unsigned index = MAX_BINARY_OUTPUTS; + + if (object_instance < MAX_BINARY_OUTPUTS) + index = object_instance; + + return index; +} + +static BACNET_BINARY_PV Present_Value( + unsigned int index) +{ + BACNET_BINARY_PV value = RELINQUISH_DEFAULT; + BACNET_BINARY_PV current_value = RELINQUISH_DEFAULT; + unsigned i = 0; + + if (index < MAX_BINARY_OUTPUTS) { + for (i = 0; i < BACNET_MAX_PRIORITY; i++) { + current_value = (BACNET_BINARY_PV) Binary_Output_Level[index][i]; + if (current_value != BINARY_NULL) { + value = (BACNET_BINARY_PV) Binary_Output_Level[index][i]; + break; + } + } + } + + return value; +} + +BACNET_BINARY_PV Binary_Output_Present_Value( + uint32_t object_instance) +{ + unsigned index = 0; + + index = Binary_Output_Instance_To_Index(object_instance); + + return Present_Value(index); +} + +bool Binary_Output_Present_Value_Set( + uint32_t instance, + BACNET_BINARY_PV binary_value, + unsigned priority) +{ /* 0..15 */ + bool status = false; + + if (instance < MAX_BINARY_OUTPUTS) { + if (priority < BACNET_MAX_PRIORITY) { + Binary_Output_Level[instance][priority] = (uint8_t) binary_value; + status = true; + } + } + + return status; +} + +static void Binary_Output_Polarity_Set( + uint32_t instance, + BACNET_POLARITY polarity) +{ + if (instance < MAX_BINARY_OUTPUTS) { + if (polarity < MAX_POLARITY) { + Polarity[instance] = polarity; + } + } +} + +BACNET_POLARITY Binary_Output_Polarity( + uint32_t instance) +{ + BACNET_POLARITY polarity = POLARITY_NORMAL; + + if (instance < MAX_BINARY_OUTPUTS) { + polarity = (BACNET_POLARITY) Polarity[instance]; + } + + return polarity; +} + +static void Binary_Output_Out_Of_Service_Set( + uint32_t instance, + bool flag) +{ + if (instance < MAX_BINARY_OUTPUTS) { + Out_Of_Service[instance] = flag; + } +} + +bool Binary_Output_Out_Of_Service( + uint32_t instance) +{ + bool flag = false; + + if (instance < MAX_BINARY_OUTPUTS) { + flag = Out_Of_Service[instance]; + } + + return flag; +} + +/* note: the object name must be unique within this device */ +char *Binary_Output_Name( + uint32_t object_instance) +{ + static char text_string[32]; /* okay for single thread */ + + if (object_instance < MAX_BINARY_OUTPUTS) { + sprintf(text_string, "BO-%lu", object_instance); + return text_string; + } + + return NULL; +} + +/* return apdu len, or -1 on error */ +int Binary_Output_Read_Property( + BACNET_READ_PROPERTY_DATA * rpdata) +{ + int len = 0; + int apdu_len = 0; /* return value */ + BACNET_BIT_STRING bit_string; + BACNET_CHARACTER_STRING char_string; + BACNET_BINARY_PV present_value = BINARY_INACTIVE; + unsigned object_index = 0; + unsigned i = 0; + bool state = false; + uint8_t *apdu = NULL; + + if ((rpdata->application_data == NULL) || + (rpdata->application_data_len == 0)) { + return 0; + } + apdu = rpdata->application_data; + switch (rpdata->object_property) { + /* object id, object name, object type are handled in Device object */ + case PROP_PRESENT_VALUE: + present_value = + Binary_Output_Present_Value(rpdata->object_instance); + apdu_len = encode_application_enumerated(&apdu[0], present_value); + break; + case PROP_STATUS_FLAGS: + /* note: see the details in the standard on how to use these */ + bitstring_init(&bit_string); + bitstring_set_bit(&bit_string, STATUS_FLAG_IN_ALARM, false); + bitstring_set_bit(&bit_string, STATUS_FLAG_FAULT, false); + bitstring_set_bit(&bit_string, STATUS_FLAG_OVERRIDDEN, false); + bitstring_set_bit(&bit_string, STATUS_FLAG_OUT_OF_SERVICE, false); + apdu_len = encode_application_bitstring(&apdu[0], &bit_string); + break; + case PROP_EVENT_STATE: + /* note: see the details in the standard on how to use this */ + apdu_len = + encode_application_enumerated(&apdu[0], EVENT_STATE_NORMAL); + break; + case PROP_OUT_OF_SERVICE: + object_index = + Binary_Output_Instance_To_Index(rpdata->object_instance); + state = Out_Of_Service[object_index]; + apdu_len = encode_application_boolean(&apdu[0], state); + break; + case PROP_POLARITY: + object_index = + Binary_Output_Instance_To_Index(rpdata->object_instance); + apdu_len = + encode_application_enumerated(&apdu[0], + Polarity[object_index]); + break; + case PROP_PRIORITY_ARRAY: + /* Array element zero is the number of elements in the array */ + if (rpdata->array_index == 0) + apdu_len = + encode_application_unsigned(&apdu[0], BACNET_MAX_PRIORITY); + /* if no index was specified, then try to encode the entire list */ + /* into one packet. */ + else if (rpdata->array_index == BACNET_ARRAY_ALL) { + object_index = + Binary_Output_Instance_To_Index(rpdata->object_instance); + for (i = 0; i < BACNET_MAX_PRIORITY; i++) { + /* FIXME: check if we have room before adding it to APDU */ + present_value = (BACNET_BINARY_PV) + Binary_Output_Level[object_index][i]; + if (present_value == BINARY_NULL) { + len = encode_application_null(&apdu[apdu_len]); + } else { + len = + encode_application_enumerated(&apdu[apdu_len], + present_value); + } + /* add it if we have room */ + if ((apdu_len + len) < MAX_APDU) + apdu_len += len; + else { + rpdata->error_class = ERROR_CLASS_SERVICES; + rpdata->error_code = ERROR_CODE_NO_SPACE_FOR_OBJECT; + apdu_len = BACNET_STATUS_ERROR; + break; + } + } + } else { + object_index = + Binary_Output_Instance_To_Index(rpdata->object_instance); + if (rpdata->array_index <= BACNET_MAX_PRIORITY) { + present_value = (BACNET_BINARY_PV) + Binary_Output_Level[object_index][rpdata->array_index - + 1]; + if (present_value == BINARY_NULL) { + apdu_len = encode_application_null(&apdu[apdu_len]); + } else { + apdu_len = + encode_application_enumerated(&apdu[apdu_len], + present_value); + } + } else { + rpdata->error_class = ERROR_CLASS_PROPERTY; + rpdata->error_code = ERROR_CODE_INVALID_ARRAY_INDEX; + apdu_len = BACNET_STATUS_ERROR; + } + } + break; + case PROP_RELINQUISH_DEFAULT: + present_value = RELINQUISH_DEFAULT; + apdu_len = encode_application_enumerated(&apdu[0], present_value); + break; + case PROP_ACTIVE_TEXT: + characterstring_init_ansi(&char_string, "on"); + apdu_len = + encode_application_character_string(&apdu[0], &char_string); + break; + case PROP_INACTIVE_TEXT: + characterstring_init_ansi(&char_string, "off"); + apdu_len = + encode_application_character_string(&apdu[0], &char_string); + break; + default: + rpdata->error_class = ERROR_CLASS_PROPERTY; + rpdata->error_code = ERROR_CODE_UNKNOWN_PROPERTY; + apdu_len = BACNET_STATUS_ERROR; + break; + } + /* only array properties can have array options */ + if ((apdu_len >= 0) && (rpdata->object_property != PROP_PRIORITY_ARRAY) && + (rpdata->array_index != BACNET_ARRAY_ALL)) { + rpdata->error_class = ERROR_CLASS_PROPERTY; + rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; + apdu_len = BACNET_STATUS_ERROR; + } + + return apdu_len; +} + +/* returns true if successful */ +bool Binary_Output_Write_Property( + BACNET_WRITE_PROPERTY_DATA * wp_data) +{ + bool status = false; /* return value */ + unsigned int priority = 0; + BACNET_BINARY_PV level = BINARY_NULL; + int len = 0; + BACNET_APPLICATION_DATA_VALUE value; + + /* decode the some of the request */ + len = + bacapp_decode_application_data(wp_data->application_data, + wp_data->application_data_len, &value); + /* FIXME: len < application_data_len: more data? */ + if (len < 0) { + /* error while decoding - a value larger than we can handle */ + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; + return false; + } + switch (wp_data->object_property) { + case PROP_PRESENT_VALUE: + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_ENUMERATED, + &wp_data->error_class, &wp_data->error_code); + if (status) { + priority = wp_data->priority; + /* Command priority 6 is reserved for use by Minimum On/Off + algorithm and may not be used for other purposes in any + object. */ + if (priority && (priority <= BACNET_MAX_PRIORITY) && + (priority != 6 /* reserved */ ) && + (value.type.Enumerated <= MAX_BINARY_PV)) { + level = (BACNET_BINARY_PV) value.type.Enumerated; + priority--; + Binary_Output_Present_Value_Set(wp_data->object_instance, + level, priority); + } else if (priority == 6) { + /* Command priority 6 is reserved for use by Minimum On/Off + algorithm and may not be used for other purposes in any + object. */ + status = false; + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED; + } else { + status = false; + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; + } + } else { + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_NULL, + &wp_data->error_class, &wp_data->error_code); + if (status) { + level = BINARY_NULL; + priority = wp_data->priority; + if (priority && (priority <= BACNET_MAX_PRIORITY)) { + priority--; + Binary_Output_Present_Value_Set(wp_data-> + object_instance, level, priority); + } else if (priority == 6) { + status = false; + /* Command priority 6 is reserved for use by Minimum On/Off + algorithm and may not be used for other purposes in any + object. */ + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED; + } else { + status = false; + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; + } + } + } + break; + case PROP_OUT_OF_SERVICE: + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN, + &wp_data->error_class, &wp_data->error_code); + if (status) { + Binary_Output_Out_Of_Service_Set(wp_data->object_instance, + value.type.Boolean); + } + break; + case PROP_POLARITY: + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_ENUMERATED, + &wp_data->error_class, &wp_data->error_code); + if (status) { + if (value.type.Enumerated < MAX_POLARITY) { + Binary_Output_Polarity_Set(wp_data->object_instance, + (BACNET_POLARITY) value.type.Enumerated); + } else { + status = false; + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; + } + } + break; + default: + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED; + break; + } + /* not using len at this time */ + len = len; + + return status; +} + +void Binary_Output_Init( + void) +{ + unsigned i, j; + + /* initialize all the analog output priority arrays to NULL */ + for (i = 0; i < MAX_BINARY_OUTPUTS; i++) { + Binary_Output_Polarity_Set(i, POLARITY_NORMAL); + Binary_Output_Out_Of_Service_Set(i, false); + for (j = 0; j < BACNET_MAX_PRIORITY; j++) { + Binary_Output_Present_Value_Set(i, BINARY_NULL, j); + } + } + + return; +} diff --git a/bacnet-stack/ports/rx62n/device.c b/bacnet-stack/ports/rx62n/device.c new file mode 100644 index 00000000..d2eb3d0c --- /dev/null +++ b/bacnet-stack/ports/rx62n/device.c @@ -0,0 +1,964 @@ +/************************************************************************** +* +* Copyright (C) 2011 Steve Karg +* +* Permission is hereby granted, free of charge, to any person obtaining +* a copy of this software and associated documentation files (the +* "Software"), to deal in the Software without restriction, including +* without limitation the rights to use, copy, modify, merge, publish, +* distribute, sublicense, and/or sell copies of the Software, and to +* permit persons to whom the Software is furnished to do so, subject to +* the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +* +*********************************************************************/ + +#include +#include +#include /* for memmove */ +#include "bacdef.h" +#include "bacdcode.h" +#include "bacstr.h" +#include "bacenum.h" +#include "bacapp.h" +#include "config.h" /* the custom stuff */ +#include "apdu.h" +#include "wp.h" /* WriteProperty handling */ +#include "rp.h" /* ReadProperty handling */ +#include "dcc.h" /* DeviceCommunicationControl handling */ +#include "version.h" +#include "device.h" /* me */ +#include "handlers.h" +#include "datalink.h" +#include "address.h" +/* os specfic includes */ +#include "timer.h" +/* objects */ +#include "device.h" +#include "bo.h" + +/* forward prototype */ +int Device_Read_Property_Local( + BACNET_READ_PROPERTY_DATA * rpdata); +bool Device_Write_Property_Local( + BACNET_WRITE_PROPERTY_DATA * wp_data); + +static struct my_object_functions { + BACNET_OBJECT_TYPE Object_Type; + object_init_function Object_Init; + object_count_function Object_Count; + object_index_to_instance_function Object_Index_To_Instance; + object_valid_instance_function Object_Valid_Instance; + object_name_function Object_Name; + read_property_function Object_Read_Property; + write_property_function Object_Write_Property; + rpm_property_lists_function Object_RPM_List; +} Object_Table[] = { + { + OBJECT_DEVICE, NULL, /* don't init - recursive! */ + Device_Count, Device_Index_To_Instance, + Device_Valid_Object_Instance_Number, Device_Name, + Device_Read_Property_Local, Device_Write_Property_Local, + Device_Property_Lists}, { + OBJECT_BINARY_OUTPUT, Binary_Output_Init, Binary_Output_Count, + Binary_Output_Index_To_Instance, Binary_Output_Valid_Instance, + Binary_Output_Name, Binary_Output_Read_Property, + Binary_Output_Write_Property, Binary_Output_Property_Lists}, { + MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL} +}; + +/* note: you really only need to define variables for + properties that are writable or that may change. + The properties that are constant can be hard coded + into the read-property encoding. */ +static uint32_t Object_Instance_Number = 12345; +static BACNET_DEVICE_STATUS System_Status = STATUS_OPERATIONAL; +static BACNET_REINITIALIZED_STATE Reinitialize_State = BACNET_REINIT_IDLE; +static char My_Object_Name[MAX_DEV_NAME_LEN + 1] = "SimpleServer"; +static char Model_Name[MAX_DEV_MOD_LEN + 1] = "RX62N"; +static char Application_Software_Version[MAX_DEV_VER_LEN + 1] = "1.0"; +static char Location[MAX_DEV_LOC_LEN + 1] = "USA"; +static char Description[MAX_DEV_DESC_LEN + 1] = "Renesas Rulz!"; +static uint32_t Database_Revision = 0; + +/* These three arrays are used by the ReadPropertyMultiple handler */ +static const int Device_Properties_Required[] = { + PROP_OBJECT_IDENTIFIER, + PROP_OBJECT_NAME, + PROP_OBJECT_TYPE, + PROP_SYSTEM_STATUS, + PROP_VENDOR_NAME, + PROP_VENDOR_IDENTIFIER, + PROP_MODEL_NAME, + PROP_FIRMWARE_REVISION, + PROP_APPLICATION_SOFTWARE_VERSION, + PROP_PROTOCOL_VERSION, + PROP_PROTOCOL_REVISION, + PROP_PROTOCOL_SERVICES_SUPPORTED, + PROP_PROTOCOL_OBJECT_TYPES_SUPPORTED, + PROP_OBJECT_LIST, + PROP_MAX_APDU_LENGTH_ACCEPTED, + PROP_SEGMENTATION_SUPPORTED, + PROP_APDU_TIMEOUT, + PROP_NUMBER_OF_APDU_RETRIES, + PROP_MAX_MASTER, + PROP_MAX_INFO_FRAMES, + PROP_DEVICE_ADDRESS_BINDING, + PROP_DATABASE_REVISION, + -1 +}; + +static const int Device_Properties_Optional[] = { + PROP_DESCRIPTION, + -1 +}; + +static const int Device_Properties_Proprietary[] = { + -1 +}; + +static struct my_object_functions *Device_Objects_Find_Functions( + BACNET_OBJECT_TYPE Object_Type) +{ + struct my_object_functions *pObject = NULL; + + pObject = &Object_Table[0]; + while (pObject->Object_Type < MAX_BACNET_OBJECT_TYPE) { + /* handle each object type */ + if (pObject->Object_Type == Object_Type) { + return (pObject); + } + + pObject++; + } + + return (NULL); +} + +static int Read_Property_Common( + struct my_object_functions *pObject, + BACNET_READ_PROPERTY_DATA * rpdata) +{ + int apdu_len = BACNET_STATUS_ERROR; + BACNET_CHARACTER_STRING char_string; + char *pString = ""; + uint8_t *apdu = NULL; + + if ((rpdata->application_data == NULL) || + (rpdata->application_data_len == 0)) { + return 0; + } + apdu = rpdata->application_data; + switch (rpdata->object_property) { + case PROP_OBJECT_IDENTIFIER: + /* Device Object exception: requested instance + may not match our instance if a wildcard */ + if (rpdata->object_type == OBJECT_DEVICE) { + rpdata->object_instance = Object_Instance_Number; + } + apdu_len = + encode_application_object_id(&apdu[0], rpdata->object_type, + rpdata->object_instance); + break; + case PROP_OBJECT_NAME: + if (pObject->Object_Name) { + pString = pObject->Object_Name(rpdata->object_instance); + } + characterstring_init_ansi(&char_string, pString); + apdu_len = + encode_application_character_string(&apdu[0], &char_string); + break; + case PROP_OBJECT_TYPE: + apdu_len = + encode_application_enumerated(&apdu[0], rpdata->object_type); + break; + default: + if (pObject->Object_Read_Property) { + apdu_len = pObject->Object_Read_Property(rpdata); + } + break; + } + + return apdu_len; +} + +static unsigned property_list_count( + const int *pList) +{ + unsigned property_count = 0; + + if (pList) { + while (*pList != -1) { + property_count++; + pList++; + } + } + + return property_count; +} + +/** For a given object type, returns the special property list. + * This function is used for ReadPropertyMultiple calls which want + * just Required, just Optional, or All properties. + * @ingroup ObjIntf + * + * @param object_type [in] The desired BACNET_OBJECT_TYPE whose properties + * are to be listed. + * @param pPropertyList [out] Reference to the structure which will, on return, + * list, separately, the Required, Optional, and Proprietary object + * properties with their counts. + */ +void Device_Objects_Property_List( + BACNET_OBJECT_TYPE object_type, + struct special_property_list_t *pPropertyList) +{ + struct my_object_functions *pObject = NULL; + + pPropertyList->Required.pList = NULL; + pPropertyList->Optional.pList = NULL; + pPropertyList->Proprietary.pList = NULL; + + /* If we can find an entry for the required object type + * and there is an Object_List_RPM fn ptr then call it + * to populate the pointers to the individual list counters. + */ + + pObject = Device_Objects_Find_Functions(object_type); + if ((pObject != NULL) && (pObject->Object_RPM_List != NULL)) { + pObject->Object_RPM_List(&pPropertyList->Required.pList, + &pPropertyList->Optional.pList, &pPropertyList->Proprietary.pList); + } + + /* Fetch the counts if available otherwise zero them */ + pPropertyList->Required.count = + pPropertyList->Required.pList == + NULL ? 0 : property_list_count(pPropertyList->Required.pList); + + pPropertyList->Optional.count = + pPropertyList->Optional.pList == + NULL ? 0 : property_list_count(pPropertyList->Optional.pList); + + pPropertyList->Proprietary.count = + pPropertyList->Proprietary.pList == + NULL ? 0 : property_list_count(pPropertyList->Proprietary.pList); + + return; +} + +void Device_Property_Lists( + const int **pRequired, + const int **pOptional, + const int **pProprietary) +{ + if (pRequired) + *pRequired = Device_Properties_Required; + if (pOptional) + *pOptional = Device_Properties_Optional; + if (pProprietary) + *pProprietary = Device_Properties_Proprietary; + + return; +} + +unsigned Device_Count( + void) +{ + return 1; +} + +uint32_t Device_Index_To_Instance( + unsigned index) +{ + index = index; + return Object_Instance_Number; +} + +bool Device_Reinitialize( + BACNET_REINITIALIZE_DEVICE_DATA * rd_data) +{ + bool status = false; + + if (characterstring_ansi_same(&rd_data->password, "rehmite")) { + Reinitialize_State = rd_data->state; + dcc_set_status_duration(COMMUNICATION_ENABLE, 0); + /* Note: you could use a mix of state + and password to multiple things */ + /* note: you probably want to restart *after* the + simple ack has been sent from the return handler + so just set a flag from here */ + status = true; + } else { + rd_data->error_class = ERROR_CLASS_SECURITY; + rd_data->error_code = ERROR_CODE_PASSWORD_FAILURE; + } + + return status; +} + +BACNET_REINITIALIZED_STATE Device_Reinitialized_State( + void) +{ + return Reinitialize_State; +} + +/* methods to manipulate the data */ +uint32_t Device_Object_Instance_Number( + void) +{ + return Object_Instance_Number; +} + +bool Device_Set_Object_Instance_Number( + uint32_t object_id) +{ + bool status = true; /* return value */ + + if (object_id <= BACNET_MAX_INSTANCE) { + Object_Instance_Number = object_id; + } else + status = false; + + return status; +} + +bool Device_Valid_Object_Instance_Number( + uint32_t object_id) +{ + /* BACnet allows for a wildcard instance number */ + return ((Object_Instance_Number == object_id) || + (object_id == BACNET_MAX_INSTANCE)); +} + +char *Device_Name( + uint32_t object_instance) +{ + if (object_instance == Object_Instance_Number) { + return My_Object_Name; + } + + return NULL; +} + +const char *Device_Object_Name( + void) +{ + return My_Object_Name; +} + +bool Device_Set_Object_Name( + const char *name, + size_t length) +{ + bool status = false; /*return value */ + + /* FIXME: All the object names in a device must be unique. + Disallow setting the Device Object Name to any objects in + the device. */ + if (length < sizeof(My_Object_Name)) { + /* Make the change and update the database revision */ + memmove(My_Object_Name, name, length); + My_Object_Name[length] = 0; + Device_Inc_Database_Revision(); + status = true; + } + + return status; +} + +BACNET_DEVICE_STATUS Device_System_Status( + void) +{ + return System_Status; +} + +int Device_Set_System_Status( + BACNET_DEVICE_STATUS status, + bool local) +{ + /*return value - 0 = ok, -1 = bad value, -2 = not allowed */ + int result = -1; + + if (status < MAX_DEVICE_STATUS) { + System_Status = status; + result = 0; + } + + return result; +} + +const char *Device_Description( + void) +{ + return Description; +} + +bool Device_Set_Description( + const char *name, + size_t length) +{ + bool status = false; /*return value */ + + if (length < sizeof(Description)) { + memmove(Description, name, length); + Description[length] = 0; + status = true; + } + + return status; +} + +const char *Device_Location( + void) +{ + return Location; +} + +bool Device_Set_Location( + const char *name, + size_t length) +{ + bool status = false; /*return value */ + + if (length < sizeof(Location)) { + memmove(Location, name, length); + Location[length] = 0; + status = true; + } + + return status; +} + +uint8_t Device_Protocol_Version( + void) +{ + return BACNET_PROTOCOL_VERSION; +} + +uint8_t Device_Protocol_Revision( + void) +{ + return BACNET_PROTOCOL_REVISION; +} + +uint16_t Device_Vendor_Identifier( + void) +{ + return BACNET_VENDOR_ID; +} + +BACNET_SEGMENTATION Device_Segmentation_Supported( + void) +{ + return SEGMENTATION_NONE; +} + +uint32_t Device_Database_Revision( + void) +{ + return Database_Revision; +} + +void Device_Inc_Database_Revision( + void) +{ + Database_Revision++; +} + +/* Since many network clients depend on the object list */ +/* for discovery, it must be consistent! */ +unsigned Device_Object_List_Count( + void) +{ + unsigned count = 0; /* number of objects */ + struct my_object_functions *pObject = NULL; + + /* initialize the default return values */ + pObject = &Object_Table[0]; + while (pObject->Object_Type < MAX_BACNET_OBJECT_TYPE) { + if (pObject->Object_Count) { + count += pObject->Object_Count(); + } + pObject++; + } + + return count; +} + +bool Device_Object_List_Identifier( + unsigned array_index, + int *object_type, + uint32_t * instance) +{ + bool status = false; + unsigned count = 0; + unsigned object_index = 0; + struct my_object_functions *pObject = NULL; + + /* array index zero is length - so invalid */ + if (array_index == 0) { + return status; + } + object_index = array_index - 1; + /* initialize the default return values */ + pObject = &Object_Table[0]; + while (pObject->Object_Type < MAX_BACNET_OBJECT_TYPE) { + if (pObject->Object_Count && pObject->Object_Index_To_Instance) { + object_index -= count; + count = pObject->Object_Count(); + if (object_index < count) { + *object_type = pObject->Object_Type; + *instance = pObject->Object_Index_To_Instance(object_index); + status = true; + break; + } + } + pObject++; + } + + return status; +} + +/** Determine if we have an object with the given object_name. + * If the object_type and object_instance pointers are not null, + * and the lookup succeeds, they will be given the resulting values. + * @param object_name [in] The desired Object Name to look for. + * @param object_type [out] The BACNET_OBJECT_TYPE of the matching Object. + * @param object_instance [out] The object instance number of the matching Object. + * @return True on success or else False if not found. + */ +bool Device_Valid_Object_Name( + const char *object_name, + int *object_type, + uint32_t * object_instance) +{ + bool found = false; + int type = 0; + uint32_t instance; + unsigned max_objects = 0, i = 0; + bool check_id = false; + char *name = NULL; + + max_objects = Device_Object_List_Count(); + for (i = 0; i < max_objects; i++) { + check_id = Device_Object_List_Identifier(i, &type, &instance); + if (check_id) { + name = Device_Valid_Object_Id(type, instance); + if (strcmp(name, object_name) == 0) { + found = true; + if (object_type) { + *object_type = type; + } + if (object_instance) { + *object_instance = instance; + } + break; + } + } + } + + return found; +} + +/* returns the name or NULL if not found */ +char *Device_Valid_Object_Id( + int object_type, + uint32_t object_instance) +{ + char *name = NULL; /* return value */ + struct my_object_functions *pObject = NULL; + + pObject = Device_Objects_Find_Functions((BACNET_OBJECT_TYPE) object_type); + if ((pObject) && (pObject->Object_Name)) { + name = pObject->Object_Name(object_instance); + } + + return name; +} + +/* return the length of the apdu encoded or BACNET_STATUS_ERROR for error */ +int Device_Read_Property_Local( + BACNET_READ_PROPERTY_DATA * rpdata) +{ + int apdu_len = 0; /* return value */ + int len = 0; /* apdu len intermediate value */ + BACNET_BIT_STRING bit_string; + BACNET_CHARACTER_STRING char_string; + unsigned i = 0; + int object_type = 0; + uint32_t instance = 0; + unsigned count = 0; + uint8_t *apdu = NULL; + struct my_object_functions *pObject = NULL; + bool found = false; + + if ((rpdata->application_data == NULL) || + (rpdata->application_data_len == 0)) { + return 0; + } + apdu = rpdata->application_data; + switch (rpdata->object_property) { + case PROP_DESCRIPTION: + characterstring_init_ansi(&char_string, Description); + apdu_len = + encode_application_character_string(&apdu[0], &char_string); + break; + case PROP_SYSTEM_STATUS: + apdu_len = + encode_application_enumerated(&apdu[0], + Device_System_Status()); + break; + case PROP_VENDOR_NAME: + characterstring_init_ansi(&char_string, BACNET_VENDOR_NAME); + apdu_len = + encode_application_character_string(&apdu[0], &char_string); + break; + case PROP_VENDOR_IDENTIFIER: + apdu_len = encode_application_unsigned(&apdu[0], BACNET_VENDOR_ID); + break; + case PROP_MODEL_NAME: + characterstring_init_ansi(&char_string, Model_Name); + apdu_len = + encode_application_character_string(&apdu[0], &char_string); + break; + case PROP_FIRMWARE_REVISION: + characterstring_init_ansi(&char_string, BACnet_Version); + apdu_len = + encode_application_character_string(&apdu[0], &char_string); + break; + case PROP_APPLICATION_SOFTWARE_VERSION: + characterstring_init_ansi(&char_string, + Application_Software_Version); + apdu_len = + encode_application_character_string(&apdu[0], &char_string); + break; + case PROP_LOCATION: + characterstring_init_ansi(&char_string, Location); + apdu_len = + encode_application_character_string(&apdu[0], &char_string); + break; + case PROP_PROTOCOL_VERSION: + apdu_len = + encode_application_unsigned(&apdu[0], BACNET_PROTOCOL_VERSION); + break; + case PROP_PROTOCOL_REVISION: + apdu_len = + encode_application_unsigned(&apdu[0], + BACNET_PROTOCOL_REVISION); + break; + case PROP_PROTOCOL_SERVICES_SUPPORTED: + /* Note: list of services that are executed, not initiated. */ + bitstring_init(&bit_string); + for (i = 0; i < MAX_BACNET_SERVICES_SUPPORTED; i++) { + /* automatic lookup based on handlers set */ + bitstring_set_bit(&bit_string, (uint8_t) i, + apdu_service_supported((BACNET_SERVICES_SUPPORTED) i)); + } + apdu_len = encode_application_bitstring(&apdu[0], &bit_string); + break; + case PROP_PROTOCOL_OBJECT_TYPES_SUPPORTED: + /* Note: this is the list of objects that can be in this device, + not a list of objects that this device can access */ + bitstring_init(&bit_string); + for (i = 0; i < MAX_ASHRAE_OBJECT_TYPE; i++) { + /* FIXME: if ReadProperty used an array of Functions... */ + /* initialize all the object types to not-supported */ + bitstring_set_bit(&bit_string, (uint8_t) i, false); + } + /* set the object types with objects to supported */ + i = 0; + pObject = &Object_Table[i]; + while (pObject->Object_Type < MAX_BACNET_OBJECT_TYPE) { + if ((pObject->Object_Count) && (pObject->Object_Count() > 0)) { + bitstring_set_bit(&bit_string, pObject->Object_Type, true); + } + pObject++; + } + apdu_len = encode_application_bitstring(&apdu[0], &bit_string); + break; + case PROP_OBJECT_LIST: + count = Device_Object_List_Count(); + /* Array element zero is the number of objects in the list */ + if (rpdata->array_index == 0) + apdu_len = encode_application_unsigned(&apdu[0], count); + /* if no index was specified, then try to encode the entire list */ + /* into one packet. Note that more than likely you will have */ + /* to return an error if the number of encoded objects exceeds */ + /* your maximum APDU size. */ + else if (rpdata->array_index == BACNET_ARRAY_ALL) { + for (i = 1; i <= count; i++) { + if (Device_Object_List_Identifier(i, &object_type, + &instance)) { + len = + encode_application_object_id(&apdu[apdu_len], + object_type, instance); + apdu_len += len; + /* assume next one is the same size as this one */ + /* can we all fit into the APDU? */ + if ((apdu_len + len) >= MAX_APDU) { + /* Abort response */ + rpdata->error_code = + ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED; + apdu_len = BACNET_STATUS_ABORT; + break; + } + } else { + /* error: internal error? */ + rpdata->error_class = ERROR_CLASS_SERVICES; + rpdata->error_code = ERROR_CODE_OTHER; + apdu_len = BACNET_STATUS_ERROR; + break; + } + } + } else { + found = + Device_Object_List_Identifier(rpdata->array_index, + &object_type, &instance); + if (found) { + apdu_len = + encode_application_object_id(&apdu[0], object_type, + instance); + } else { + rpdata->error_class = ERROR_CLASS_PROPERTY; + rpdata->error_code = ERROR_CODE_INVALID_ARRAY_INDEX; + apdu_len = BACNET_STATUS_ERROR; + } + } + break; + case PROP_MAX_APDU_LENGTH_ACCEPTED: + apdu_len = encode_application_unsigned(&apdu[0], MAX_APDU); + break; + case PROP_SEGMENTATION_SUPPORTED: + apdu_len = + encode_application_enumerated(&apdu[0], + Device_Segmentation_Supported()); + break; + case PROP_APDU_TIMEOUT: + apdu_len = encode_application_unsigned(&apdu[0], apdu_timeout()); + break; + case PROP_NUMBER_OF_APDU_RETRIES: + apdu_len = encode_application_unsigned(&apdu[0], apdu_retries()); + break; + case PROP_DEVICE_ADDRESS_BINDING: + /* FIXME: encode the list here, if it exists */ + break; + case PROP_DATABASE_REVISION: + apdu_len = + encode_application_unsigned(&apdu[0], Database_Revision); + break; + default: + rpdata->error_class = ERROR_CLASS_PROPERTY; + rpdata->error_code = ERROR_CODE_UNKNOWN_PROPERTY; + apdu_len = BACNET_STATUS_ERROR; + break; + } + /* only array properties can have array options */ + if ((apdu_len >= 0) && (rpdata->object_property != PROP_OBJECT_LIST) && + (rpdata->array_index != BACNET_ARRAY_ALL)) { + rpdata->error_class = ERROR_CLASS_PROPERTY; + rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; + apdu_len = BACNET_STATUS_ERROR; + } + + return apdu_len; +} + +/** Looks up the requested Object and Property, and encodes its Value in an APDU. + * @ingroup ObjIntf + * If the Object or Property can't be found, sets the error class and code. + * + * @param rpdata [in,out] Structure with the desired Object and Property info + * on entry, and APDU message on return. + * @return The length of the APDU on success, else BACNET_STATUS_ERROR + */ +int Device_Read_Property( + BACNET_READ_PROPERTY_DATA * rpdata) +{ + int apdu_len = BACNET_STATUS_ERROR; + struct my_object_functions *pObject = NULL; + + /* initialize the default return values */ + rpdata->error_class = ERROR_CLASS_OBJECT; + rpdata->error_code = ERROR_CODE_UNKNOWN_OBJECT; + pObject = Device_Objects_Find_Functions(rpdata->object_type); + if (pObject) { + if (pObject->Object_Valid_Instance && + pObject->Object_Valid_Instance(rpdata->object_instance)) { + apdu_len = Read_Property_Common(pObject, rpdata); + } else { + rpdata->error_class = ERROR_CLASS_OBJECT; + rpdata->error_code = ERROR_CODE_UNKNOWN_OBJECT; + } + } else { + rpdata->error_class = ERROR_CLASS_OBJECT; + rpdata->error_code = ERROR_CODE_UNSUPPORTED_OBJECT_TYPE; + } + + return apdu_len; +} + +/* returns true if successful */ +bool Device_Write_Property_Local( + BACNET_WRITE_PROPERTY_DATA * wp_data) +{ + bool status = false; /* return value */ + int len = 0; + BACNET_APPLICATION_DATA_VALUE value; + int temp; + + /* decode the some of the request */ + len = + bacapp_decode_application_data(wp_data->application_data, + wp_data->application_data_len, &value); + /* FIXME: len < application_data_len: more data? */ + if (len < 0) { + /* error while decoding - a value larger than we can handle */ + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; + return false; + } + switch (wp_data->object_property) { + case PROP_OBJECT_IDENTIFIER: + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_OBJECT_ID, + &wp_data->error_class, &wp_data->error_code); + if (status) { + if ((value.type.Object_Id.type == OBJECT_DEVICE) && + (Device_Set_Object_Instance_Number(value.type.Object_Id. + instance))) { + /* we could send an I-Am broadcast to let the world know */ + status = true; + } else { + status = false; + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; + } + } + break; + case PROP_SYSTEM_STATUS: + status = + WPValidateArgType(&value, BACNET_APPLICATION_TAG_ENUMERATED, + &wp_data->error_class, &wp_data->error_code); + if (status) { + temp = Device_Set_System_Status((BACNET_DEVICE_STATUS) + value.type.Enumerated, false); + if (temp != 0) { + status = false; + wp_data->error_class = ERROR_CLASS_PROPERTY; + if (temp == -1) { + wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; + } else { + wp_data->error_code = + ERROR_CODE_OPTIONAL_FUNCTIONALITY_NOT_SUPPORTED; + } + } + } + break; + case PROP_OBJECT_NAME: + status = + WPValidateString(&value, MAX_DEV_NAME_LEN, false, + &wp_data->error_class, &wp_data->error_code); + if (status) { + Device_Set_Object_Name(characterstring_value(&value.type. + Character_String), + characterstring_length(&value.type.Character_String)); + } + break; + case PROP_LOCATION: + status = + WPValidateString(&value, MAX_DEV_LOC_LEN, true, + &wp_data->error_class, &wp_data->error_code); + if (status) { + Device_Set_Location(characterstring_value(&value.type. + Character_String), + characterstring_length(&value.type.Character_String)); + } + break; + + case PROP_DESCRIPTION: + status = + WPValidateString(&value, MAX_DEV_DESC_LEN, true, + &wp_data->error_class, &wp_data->error_code); + if (status) { + Device_Set_Description(characterstring_value(&value.type. + Character_String), + characterstring_length(&value.type.Character_String)); + } + break; + default: + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED; + break; + } + /* not using len at this time */ + len = len; + + return status; +} + +/** Looks up the requested Object and Property, and set the new Value in it, + * if allowed. + * If the Object or Property can't be found, sets the error class and code. + * @ingroup ObjIntf + * + * @param wp_data [in,out] Structure with the desired Object and Property info + * and new Value on entry, and APDU message on return. + * @return True on success, else False if there is an error. + */ +bool Device_Write_Property( + BACNET_WRITE_PROPERTY_DATA * wp_data) +{ + bool status = false; + struct my_object_functions *pObject = NULL; + + /* initialize the default return values */ + wp_data->error_class = ERROR_CLASS_OBJECT; + wp_data->error_code = ERROR_CODE_UNKNOWN_OBJECT; + pObject = Device_Objects_Find_Functions(wp_data->object_type); + if (pObject != NULL) { + if (pObject->Object_Valid_Instance && + pObject->Object_Valid_Instance(wp_data->object_instance)) { + if (pObject->Object_Write_Property) { + status = pObject->Object_Write_Property(wp_data); + } else { + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED; + } + } else { + wp_data->error_class = ERROR_CLASS_OBJECT; + wp_data->error_code = ERROR_CODE_UNKNOWN_OBJECT; + } + } else { + wp_data->error_class = ERROR_CLASS_OBJECT; + wp_data->error_code = ERROR_CODE_UNSUPPORTED_OBJECT_TYPE; + } + + return status; +} + +/** Initialize the Device Object and each of its child Object instances. + * @ingroup ObjIntf + */ +void Device_Init( + void) +{ + struct my_object_functions *pObject = NULL; + + pObject = &Object_Table[0]; + while (pObject->Object_Type < MAX_BACNET_OBJECT_TYPE) { + if (pObject->Object_Init) { + pObject->Object_Init(); + } + pObject++; + } + dcc_set_status_duration(COMMUNICATION_ENABLE, 0); +} diff --git a/bacnet-stack/ports/rx62n/ethernet.c b/bacnet-stack/ports/rx62n/ethernet.c new file mode 100644 index 00000000..d54ba2a1 --- /dev/null +++ b/bacnet-stack/ports/rx62n/ethernet.c @@ -0,0 +1,252 @@ +/************************************************************************** +* +* Copyright (C) 2011 Steve Karg +* +* Permission is hereby granted, free of charge, to any person obtaining +* a copy of this software and associated documentation files (the +* "Software"), to deal in the Software without restriction, including +* without limitation the rights to use, copy, modify, merge, publish, +* distribute, sublicense, and/or sell copies of the Software, and to +* permit persons to whom the Software is furnished to do so, subject to +* the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +* +*********************************************************************/ +#include /* for standard integer types uint8_t etc. */ +#include /* for the standard bool type. */ +#include "bacdef.h" +#include "ethernet.h" +#include "bacint.h" +#include "hardware.h" + +/** @file rx62n/ethernet.c Provides Renesas RX62N-specific functions + for BACnet/Ethernet. */ + +/* commonly used comparison address for ethernet */ +static uint8_t Ethernet_Broadcast[MAX_MAC_LEN] = + { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; + +/* IEEE maintains list of 48-bit MAC "addresses" AKA EUI-48 identifiers. + An EUI-48 is structured into an initial 3-octet OUI + (Organizationally Unique Identifier) and an additional 3 octets + assigned by the OUI holder. */ +/* see [RFC5342] for current information and registration procedures. */ +/* The OUI 00-00-5E has been allocated to IANA. */ +/* my local device data - MAC address */ +static uint8_t Ethernet_MAC_Address[MAX_MAC_LEN] = + {0x00, 0x00, 0x5E, 0x00, 0x00, 0x01}; + +/* status of the link */ +static int32_t Ethernet_Status = R_ETHER_ERROR; + +bool ethernet_valid( + void) +{ + if (Ethernet_Status != R_ETHER_OK) { + Ethernet_Status = R_Ether_Open(0, Ethernet_MAC_Address); + } + + return (Ethernet_Status != R_ETHER_ERROR); +} + +void ethernet_cleanup( + void) +{ + R_Ether_Close(0); + Ethernet_Status = R_ETHER_ERROR; + + return; +} + +bool ethernet_init( + char *interface_name) +{ + interface_name = interface_name; + Ethernet_Status = R_Ether_Open(0, Ethernet_MAC_Address); + + return (Ethernet_Status == R_ETHER_OK); +} + +int ethernet_send( + uint8_t * mtu, + int mtu_len) +{ + int bytes = 0; + + /* Send the packet */ + bytes = R_Ether_Write(0, mtu, mtu_len); + + return bytes; + +} + +/* function to send a packet out the 802.2 socket */ +/* returns number of bytes sent on success, negative on failure */ +int ethernet_send_pdu( + BACNET_ADDRESS * dest, /* destination address */ + BACNET_NPDU_DATA * npdu_data, /* network information */ + uint8_t * pdu, /* any data to be sent - may be null */ + unsigned pdu_len) +{ /* number of bytes of data */ + int i = 0; /* counter */ + int bytes = 0; + BACNET_ADDRESS src = { 0 }; /* source address for npdu */ + uint8_t mtu[MAX_MPDU] = { 0 }; /* our buffer */ + int mtu_len = 0; + + (void) npdu_data; + /* load the BACnet address for NPDU data */ + for (i = 0; i < 6; i++) { + src.mac[i] = Ethernet_MAC_Address[i]; + src.mac_len++; + } + + /* don't waste time if the socket is not valid */ + if (!ethernet_valid()) { + return -1; + } + /* load destination ethernet MAC address */ + if (dest->mac_len == 6) { + for (i = 0; i < 6; i++) { + mtu[i] = dest->mac[i]; + } + } else { + return -2; + } + + /* load source ethernet MAC address */ + if (src.mac_len == 6) { + for (i = 0; i < 6; i++) { + mtu[6 + i] = src.mac[i]; + } + } else { + return -3; + } + /* Logical PDU portion */ + mtu[14] = 0x82; /* DSAP for BACnet */ + mtu[15] = 0x82; /* SSAP for BACnet */ + mtu[16] = 0x03; /* Control byte in header */ + mtu_len = 17; + if ((mtu_len + pdu_len) > MAX_MPDU) { + return -4; + } + memcpy(&mtu[mtu_len], pdu, pdu_len); + mtu_len += pdu_len; + /* packet length - only the logical portion, not the address */ + encode_unsigned16(&mtu[12], 3 + pdu_len); + + /* Send the packet */ + bytes = R_Ether_Write(0, mtu, mtu_len); + + return bytes; +} + +/* receives an 802.2 framed packet */ +/* returns the number of octets in the PDU, or zero on failure */ +uint16_t ethernet_receive( + BACNET_ADDRESS * src, /* source address */ + uint8_t * pdu, /* PDU data */ + uint16_t max_pdu, /* amount of space available in the PDU */ + unsigned timeout) +{ /* number of milliseconds to wait for a packet */ + int received_bytes; + uint8_t buf[MAX_MPDU] = { 0 }; /* data */ + uint16_t pdu_len = 0; /* return value */ + + /* Make sure the socket is open */ + if (!ethernet_valid()) + return 0; + + received_bytes = R_Ether_Read(0, (void *)buf); + + if (received_bytes == 0) + return 0; + + /* the signature of an 802.2 BACnet packet */ + if ((buf[14] != 0x82) && (buf[15] != 0x82)) { + return 0; + } + /* copy the source address */ + src->mac_len = 6; + memmove(src->mac, &buf[6], 6); + + /* check destination address for when */ + /* the Ethernet card is in promiscious mode */ + if ((memcmp(&buf[0], Ethernet_MAC_Address, 6) != 0) + && (memcmp(&buf[0], Ethernet_Broadcast, 6) != 0)) { + return 0; + } + + (void) decode_unsigned16(&buf[12], &pdu_len); + pdu_len -= 3 /* DSAP, SSAP, LLC Control */ ; + /* copy the buffer into the PDU */ + if (pdu_len < max_pdu) + memmove(&pdu[0], &buf[17], pdu_len); + /* ignore packets that are too large */ + else + pdu_len = 0; + + + return pdu_len; +} + +void ethernet_set_my_address( + BACNET_ADDRESS * my_address) +{ + int i = 0; + + for (i = 0; i < 6; i++) { + Ethernet_MAC_Address[i] = my_address->mac[i]; + } + + return; +} + +void ethernet_get_my_address( + BACNET_ADDRESS * my_address) +{ + int i = 0; + + my_address->mac_len = 0; + for (i = 0; i < 6; i++) { + my_address->mac[i] = Ethernet_MAC_Address[i]; + my_address->mac_len++; + } + my_address->net = 0; /* DNET=0 is local only, no routing */ + my_address->len = 0; + for (i = 0; i < MAX_MAC_LEN; i++) { + my_address->adr[i] = 0; + } + + return; +} + +void ethernet_get_broadcast_address( + BACNET_ADDRESS * dest) +{ /* destination address */ + int i = 0; /* counter */ + + if (dest) { + for (i = 0; i < 6; i++) { + dest->mac[i] = Ethernet_Broadcast[i]; + } + dest->mac_len = 6; + dest->net = BACNET_BROADCAST_NETWORK; + dest->len = 0; /* always zero when DNET is broadcast */ + for (i = 0; i < MAX_MAC_LEN; i++) { + dest->adr[i] = 0; + } + } + + return; +} diff --git a/bacnet-stack/ports/rx62n/hardware.h b/bacnet-stack/ports/rx62n/hardware.h new file mode 100644 index 00000000..4dbcd457 --- /dev/null +++ b/bacnet-stack/ports/rx62n/hardware.h @@ -0,0 +1,46 @@ +/************************************************************************** +* +* Copyright (C) 2011 Steve Karg +* +* Permission is hereby granted, free of charge, to any person obtaining +* a copy of this software and associated documentation files (the +* "Software"), to deal in the Software without restriction, including +* without limitation the rights to use, copy, modify, merge, publish, +* distribute, sublicense, and/or sell copies of the Software, and to +* permit persons to whom the Software is furnished to do so, subject to +* the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +* +*********************************************************************/ +#ifndef HARDWARE_H +#define HARDWARE_H + +/* IO Port RPDL function definitions */ +#include "r_pdl_io_port.h" +/* CMT RPDL function definitions */ +#include "r_pdl_cmt.h" +/* General RPDL function definitions */ +#include "r_pdl_definitions.h" +/* Evaluation Board Definitions */ +#include "YRDKRX62N.h" +/* Ethernet driver */ +#include "r_ether.h" +/* LCD Driver */ +#include "lcd.h" + +/* there are 4..15 LEDs on the board */ +#define MAX_LEDS 16 +/* use the LEDS as binary outputs */ +#define MAX_BINARY_OUTPUTS 16 + +#endif diff --git a/bacnet-stack/ports/rx62n/led.c b/bacnet-stack/ports/rx62n/led.c new file mode 100644 index 00000000..ce68789e --- /dev/null +++ b/bacnet-stack/ports/rx62n/led.c @@ -0,0 +1,235 @@ +/************************************************************************** +* +* Copyright (C) 2011 Steve Karg +* +* Permission is hereby granted, free of charge, to any person obtaining +* a copy of this software and associated documentation files (the +* "Software"), to deal in the Software without restriction, including +* without limitation the rights to use, copy, modify, merge, publish, +* distribute, sublicense, and/or sell copies of the Software, and to +* permit persons to whom the Software is furnished to do so, subject to +* the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*********************************************************************/ +#include +#include "hardware.h" +#include "timer.h" +#include "led.h" + +static struct itimer Off_Delay_Timer[MAX_LEDS]; +static bool LED_Status[MAX_LEDS]; + +#define LED_OFF (0) + + +/************************************************************************* +* Description: Turn on an LED +* Returns: none +* Notes: none +*************************************************************************/ +void led_on( + uint8_t index) +{ + switch (index) { + case 4: + R_IO_PORT_Write( LED4, LED_ON ); + break; + case 5: + R_IO_PORT_Write( LED5, LED_ON ); + break; + case 6: + R_IO_PORT_Write( LED6, LED_ON ); + break; + case 7: + R_IO_PORT_Write( LED7, LED_ON ); + break; + case 8: + R_IO_PORT_Write( LED8, LED_ON ); + break; + case 9: + R_IO_PORT_Write( LED9, LED_ON ); + break; + case 10: + R_IO_PORT_Write( LED10, LED_ON ); + break; + case 11: + R_IO_PORT_Write( LED11, LED_ON ); + break; + case 12: + R_IO_PORT_Write( LED12, LED_ON ); + break; + case 13: + R_IO_PORT_Write( LED13, LED_ON ); + break; + case 14: + R_IO_PORT_Write( LED14, LED_ON ); + break; + case 15: + R_IO_PORT_Write( LED15, LED_ON ); + break; + default: + break; + } + if (index < MAX_LEDS) { + LED_Status[index] = LED_ON; + timer_interval_no_expire(&Off_Delay_Timer[index]); + } +} + +/************************************************************************* +* Description: Turn off an LED +* Returns: none +* Notes: none +*************************************************************************/ +void led_off( + uint8_t index) +{ + switch (index) { + case 4: + R_IO_PORT_Write( LED4, LED_OFF ); + break; + case 5: + R_IO_PORT_Write( LED5, LED_OFF ); + break; + case 6: + R_IO_PORT_Write( LED6, LED_OFF ); + break; + case 7: + R_IO_PORT_Write( LED7, LED_OFF ); + break; + case 8: + R_IO_PORT_Write( LED8, LED_OFF ); + break; + case 9: + R_IO_PORT_Write( LED9, LED_OFF ); + break; + case 10: + R_IO_PORT_Write( LED10, LED_OFF ); + break; + case 11: + R_IO_PORT_Write( LED11, LED_OFF ); + break; + case 12: + R_IO_PORT_Write( LED12, LED_OFF ); + break; + case 13: + R_IO_PORT_Write( LED13, LED_OFF ); + break; + case 14: + R_IO_PORT_Write( LED14, LED_OFF ); + break; + case 15: + R_IO_PORT_Write( LED15, LED_OFF ); + break; + default: + break; + } + if (index < MAX_LEDS) { + LED_Status[index] = LED_OFF; + timer_interval_no_expire(&Off_Delay_Timer[index]); + } +} + +/************************************************************************* +* Description: Get the state of the LED +* Returns: true if on, false if off. +* Notes: none +*************************************************************************/ +bool led_state( + uint8_t index) +{ + bool state = false; + + if (index < MAX_LEDS) { + state = LED_Status[index]; + } + + return state; +} + +/************************************************************************* +* Description: Toggle the state of the setup LED +* Returns: none +* Notes: none +*************************************************************************/ +void led_toggle( + uint8_t index) +{ + if (led_state(index)) { + led_off(index); + } else { + led_on(index); + } +} + +/************************************************************************* +* Description: Delay before going off to give minimum brightness. +* Returns: none +* Notes: none +*************************************************************************/ +void led_off_delay( + uint8_t index, + uint32_t delay_ms) +{ + if (index < MAX_LEDS) { + timer_interval_start(&Off_Delay_Timer[index], delay_ms); + } +} + +/************************************************************************* +* Description: Turn on, and delay before going off. +* Returns: none +* Notes: none +*************************************************************************/ +void led_on_interval( + uint8_t index, + uint16_t interval_ms) +{ + if (index < MAX_LEDS) { + led_on(index); + timer_interval_start(&Off_Delay_Timer[index], interval_ms); + } +} + +/************************************************************************* +* Description: Task for blinking LED +* Returns: none +* Notes: none +*************************************************************************/ +void led_task( + void) +{ + uint8_t i; /* loop counter */ + + for (i = 0; i < MAX_LEDS; i++) { + if (timer_interval_expired(&Off_Delay_Timer[i])) { + timer_interval_no_expire(&Off_Delay_Timer[i]); + led_off(i); + } + } +} + +/************************************************************************* +* Description: Initialize the LED hardware +* Returns: none +* Notes: none +*************************************************************************/ +void led_init( + void) +{ + unsigned i = 0; + + for (i = 0; i < MAX_LEDS; i++) { + led_on_interval(i, 500); + } +} diff --git a/bacnet-stack/ports/rx62n/led.h b/bacnet-stack/ports/rx62n/led.h new file mode 100644 index 00000000..7a1ffaec --- /dev/null +++ b/bacnet-stack/ports/rx62n/led.h @@ -0,0 +1,56 @@ +/************************************************************************** +* +* Copyright (C) 2009 Steve Karg +* +* Permission is hereby granted, free of charge, to any person obtaining +* a copy of this software and associated documentation files (the +* "Software"), to deal in the Software without restriction, including +* without limitation the rights to use, copy, modify, merge, publish, +* distribute, sublicense, and/or sell copies of the Software, and to +* permit persons to whom the Software is furnished to do so, subject to +* the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*********************************************************************/ +#ifndef LED_H +#define LED_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + + void led_on( + uint8_t index); + void led_on_interval( + uint8_t index, + uint16_t interval_ms); + void led_off( + uint8_t index); + void led_off_delay( + uint8_t index, + uint32_t delay_ms); + void led_toggle( + uint8_t index); + bool led_state( + uint8_t index); + void led_task( + void); + void led_init( + void); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif diff --git a/bacnet-stack/ports/rx62n/main.c b/bacnet-stack/ports/rx62n/main.c new file mode 100644 index 00000000..a71b7a17 --- /dev/null +++ b/bacnet-stack/ports/rx62n/main.c @@ -0,0 +1,47 @@ +/************************************************************************ +* +* Copyright (C) 2011 Steve Karg +* +* Permission is hereby granted, free of charge, to any person obtaining +* a copy of this software and associated documentation files (the +* "Software"), to deal in the Software without restriction, including +* without limitation the rights to use, copy, modify, merge, publish, +* distribute, sublicense, and/or sell copies of the Software, and to +* permit persons to whom the Software is furnished to do so, subject to +* the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +* +*************************************************************************/ +#include +#include +#include "hardware.h" +#include "ethernet.h" +#include "timer.h" +#include "led.h" + +/** Main function of BACnet demo for RX62N evaluation board */ +int main(void) +{ + InitialiseLCD(); + ClearLCD(); + DisplayLCD(LCD_LINE1, "BACnet Demo"); + /* our stuff */ + timer_init(); + led_init(); + ethernet_init(NULL); + bacnet_init(); + for (;;) { + bacnet_task(); + led_task(); + } +} diff --git a/bacnet-stack/ports/rx62n/readme.txt b/bacnet-stack/ports/rx62n/readme.txt new file mode 100644 index 00000000..149f27db --- /dev/null +++ b/bacnet-stack/ports/rx62n/readme.txt @@ -0,0 +1,8 @@ +BACnet Etherent +Demonstrates the Ethernet peripheral by implmenting BACnet over Ethernet +on the RX62N Development Kit. The project is compiled with the RX Standard +Toolchain, and the default drivers included with the RX62N kit. +  +The project does not use any additional hardware. +  +The project was tested using a BACnet/IP to BACnet Ethernet router, using the bacnet-tools from the BACnet Protocol Stack site. diff --git a/bacnet-stack/ports/rx62n/timer-hdw.c b/bacnet-stack/ports/rx62n/timer-hdw.c new file mode 100644 index 00000000..6c99ec86 --- /dev/null +++ b/bacnet-stack/ports/rx62n/timer-hdw.c @@ -0,0 +1,106 @@ +/************************************************************************** +* +* Copyright (C) 2011 Steve Karg +* +* Permission is hereby granted, free of charge, to any person obtaining +* a copy of this software and associated documentation files (the +* "Software"), to deal in the Software without restriction, including +* without limitation the rights to use, copy, modify, merge, publish, +* distribute, sublicense, and/or sell copies of the Software, and to +* permit persons to whom the Software is furnished to do so, subject to +* the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*********************************************************************/ +#include +#include +#include "hardware.h" +#include "timer.h" + +/* counter for the the timer which wraps every 49.7 days */ +static volatile uint32_t Millisecond_Counter; +static volatile uint8_t Millisecond_Counter_Byte; +/* forward prototype for interrupt service routine */ +void int_cmt0_isr(void); + +/************************************************************************* +* Description: Timer Interrupt Handler +* Returns: nothing +* Notes: none +*************************************************************************/ +static void timer_interrupt_handler( + void) +{ + Millisecond_Counter++; + Millisecond_Counter_Byte++; +} + +/************************************************************************* +* Description: Timer Interrupt Service Routine +* Returns: nothing +* Notes: none +*************************************************************************/ +void int_cmt0_isr(void) +{ + timer_interrupt_handler(); +} + +/************************************************************************* +* Description: returns the current millisecond count +* Returns: none +* Notes: This method only disables the timer overflow interrupt. +*************************************************************************/ +uint32_t timer_milliseconds( + void) +{ + uint32_t timer_value; /* return value */ + + timer_value = Millisecond_Counter; + + return timer_value; +} + +/************************************************************************* +* Description: returns the current millisecond count +* Returns: none +* Notes: This method only disables the timer overflow interrupt. +*************************************************************************/ +uint8_t timer_milliseconds_byte( + void) +{ + return Millisecond_Counter; +} + +/************************************************************************* +* Description: Initialization for Timer +* Returns: none +* Notes: none +*************************************************************************/ +void timer_init( + void) +{ + /* Declare error flag */ + bool err = true; + + /* CMT is configured for a 1ms interval, and executes the callback + function CB_CompareMatch on every compare match */ + err &= R_CMT_Create( + 3, + PDL_CMT_PERIOD, + 1E-3, + int_cmt0_isr, + 3 + ); + + /* Halt in while loop when RPDL errors detected */ + while(!err); +} diff --git a/bacnet-stack/ports/rx62n/timer.c b/bacnet-stack/ports/rx62n/timer.c new file mode 100644 index 00000000..679529e0 --- /dev/null +++ b/bacnet-stack/ports/rx62n/timer.c @@ -0,0 +1,431 @@ +/************************************************************************** +* +* Copyright (C) 2009 Steve Karg +* +* Permission is hereby granted, free of charge, to any person obtaining +* a copy of this software and associated documentation files (the +* "Software"), to deal in the Software without restriction, including +* without limitation the rights to use, copy, modify, merge, publish, +* distribute, sublicense, and/or sell copies of the Software, and to +* permit persons to whom the Software is furnished to do so, subject to +* the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*********************************************************************/ +#include +#include +#include "timer.h" + +/* generic elapsed timer handling */ +/* interval not to exceed 49.7 days */ +/* interval of 1ms may be 0 to 1ms */ + +/************************************************************************* +* Description: Sets the start time for an elapsed timer +* Returns: the value of the start timer +* Notes: none +*************************************************************************/ +void timer_elapsed_start( + struct etimer *t) +{ + uint32_t now = timer_milliseconds(); + + if (t) { + t->start = now; + } +} + +/************************************************************************* +* Description: Gets the amount of elapsed time in milliseconds +* Returns: elapsed time in milliseconds +* Notes: none +*************************************************************************/ +uint32_t timer_elapsed_time( + struct etimer *t) +{ + uint32_t now = timer_milliseconds(); + uint32_t delta = 0; + + if (t) { + delta = now - t->start; + } + + return delta; +} + +/************************************************************************* +* Description: Sets the start time with an offset +* Returns: elapsed time in milliseconds +* Notes: none +*************************************************************************/ +void timer_elapsed_start_offset( + struct etimer *t, + uint32_t offset) +{ + uint32_t now = timer_milliseconds(); + + if (t) { + t->start = now + offset; + } +} + +/************************************************************************* +* Description: Tests to see if time has elapsed +* Returns: true if time has elapsed +* Notes: none +*************************************************************************/ +bool timer_elapsed_milliseconds( + struct etimer *t, + uint32_t milliseconds) +{ + return (timer_elapsed_time(t) >= milliseconds); +} + +/************************************************************************* +* Description: Tests to see if time has elapsed +* Returns: true if time has elapsed +* Notes: none +*************************************************************************/ +bool timer_elapsed_seconds( + struct etimer * t, + uint32_t seconds) +{ + uint32_t milliseconds = seconds; + + milliseconds *= 1000L; + + return timer_elapsed_milliseconds(t, milliseconds); +} + +/************************************************************************* +* Description: Tests to see if time has elapsed +* Returns: true if time has elapsed +* Notes: none +*************************************************************************/ +bool timer_elapsed_minutes( + struct etimer * t, + uint32_t minutes) +{ + uint32_t milliseconds = minutes; + + milliseconds *= 1000L; + milliseconds *= 60L; + + return timer_elapsed_milliseconds(t, milliseconds); +} + +/************************************************************************* +* Description: Tests to see if time has elapsed +* Returns: true if time has elapsed +* Notes: none +*************************************************************************/ +bool timer_elapsed_milliseconds_short( + struct etimer * t, + uint16_t value) +{ + uint32_t milliseconds; + + milliseconds = value; + + return (timer_elapsed_time(t) >= milliseconds); +} + +/************************************************************************* +* Description: Tests to see if time has elapsed +* Returns: true if time has elapsed +* Notes: none +*************************************************************************/ +bool timer_elapsed_seconds_short( + struct etimer * t, + uint16_t value) +{ + return timer_elapsed_seconds(t, value); +} + +/************************************************************************* +* Description: Tests to see if time has elapsed +* Returns: true if time has elapsed +* Notes: none +*************************************************************************/ +bool timer_elapsed_minutes_short( + struct etimer * t, + uint16_t value) +{ + return timer_elapsed_minutes(t, value); +} + +/************************************************************************* +* Description: Starts an interval timer +* Returns: nothing +* Notes: none +*************************************************************************/ +void timer_interval_start( + struct itimer *t, + uint32_t interval) +{ + if (t) { + t->start = timer_milliseconds(); + t->interval = interval; + } +} + +/************************************************************************* +* Description: Starts an interval timer +* Returns: nothing +* Notes: none +*************************************************************************/ +void timer_interval_start_seconds( + struct itimer *t, + uint32_t seconds) +{ + uint32_t interval = seconds; + + interval *= 1000L; + timer_interval_start(t, interval); +} + +/************************************************************************* +* Description: Starts an interval timer +* Returns: nothing +* Notes: none +*************************************************************************/ +void timer_interval_start_minutes( + struct itimer *t, + uint32_t minutes) +{ + uint32_t interval = minutes; + + interval *= 1000L; + interval *= 60L; + timer_interval_start(t, interval); +} + +/************************************************************************* +* Description: Determines the amount of time that has elapsed +* Returns: elapsed milliseconds +* Notes: none +*************************************************************************/ +uint32_t timer_interval_elapsed( + struct itimer *t) +{ + uint32_t now = timer_milliseconds(); + uint32_t delta = 0; + + if (t) { + delta = now - t->start; + } + + return delta; +} + +/************************************************************************* +* Description: Determines the amount of time that has elapsed +* Returns: elapsed milliseconds +* Notes: none +*************************************************************************/ +uint32_t timer_interval( + struct itimer * t) +{ + uint32_t interval = 0; + + if (t) { + interval = t->interval; + } + + return interval; +} + +/************************************************************************* +* Description: Tests to see if time has elapsed +* Returns: true if time has elapsed +* Notes: none +*************************************************************************/ +bool timer_interval_expired( + struct itimer * t) +{ + bool expired = false; + + if (t) { + if (t->interval) { + expired = timer_interval_elapsed(t) >= t->interval; + } + } + + return expired; +} + +/************************************************************************* +* Description: Sets the interval value to zero so it never expires +* Returns: nothing +* Notes: none +*************************************************************************/ +void timer_interval_no_expire( + struct itimer *t) +{ + if (t) { + t->interval = 0; + } +} + +/************************************************************************* +* Description: Adds another interval to the start time. Used for cyclic +* timers that won't lose ticks. +* Returns: nothing +* Notes: none +*************************************************************************/ +void timer_interval_reset( + struct itimer *t) +{ + if (t) { + t->start += t->interval; + } +} + +/************************************************************************* +* Description: Restarts the timer with the same interval +* Returns: nothing +* Notes: none +*************************************************************************/ +void timer_interval_restart( + struct itimer *t) +{ + if (t) { + t->start = timer_milliseconds(); + } +} + +/************************************************************************* +* Description: Return the elapsed time +* Returns: number of milliseconds elapsed +* Notes: only up to 255ms elapsed +**************************************************************************/ +uint8_t timer_milliseconds_delta( + uint8_t start) +{ + return (timer_milliseconds_byte() - start); +} + +/************************************************************************* +* Description: Mark the start of a delta timer +* Returns: mark timer starting tick +* Notes: only up to 255ms elapsed +**************************************************************************/ +uint8_t timer_milliseconds_mark( + void) +{ + return timer_milliseconds_byte(); +} + +#ifdef TEST +#include +#include + +#include "ctest.h" + +static uint32_t Milliseconds; + +uint32_t timer_milliseconds( + void) +{ + return Milliseconds; +} + +uint32_t timer_milliseconds_set( + uint32_t value) +{ + uint32_t old_value = Milliseconds; + + Milliseconds = value; + + return old_value; +} + +void testElapsedTimer( + Test * pTest) +{ + struct etimer t; + uint32_t test_time = 0; + + timer_milliseconds_set(test_time); + timer_elapsed_start(&t); + ct_test(pTest, timer_elapsed_time(&t) == test_time); + test_time = 0xffff; + timer_milliseconds_set(test_time); + ct_test(pTest, timer_elapsed_time(&t) == test_time); + test_time = 0xffffffff; + timer_milliseconds_set(test_time); + ct_test(pTest, timer_elapsed_time(&t) == test_time); +} + +void testIntervalTimer( + Test * pTest) +{ + struct itimer t; + uint32_t interval = 0; + uint32_t test_time = 0; + + timer_milliseconds_set(test_time); + timer_interval_start(&t, interval); + test_time = 0xffff; + timer_milliseconds_set(test_time); + ct_test(pTest, timer_interval(&t) == interval); + ct_test(pTest, timer_interval_elapsed(&t) == test_time); + test_time = 0xffffffff; + timer_milliseconds_set(test_time); + ct_test(pTest, timer_interval(&t) == interval); + ct_test(pTest, timer_interval_elapsed(&t) == test_time); + test_time = 0; + timer_milliseconds_set(test_time); + interval = 0xffff; + timer_interval_start(&t, interval); + ct_test(pTest, timer_interval(&t) == interval); + interval = 0xffffffff; + timer_interval_start(&t, interval); + ct_test(pTest, timer_interval(&t) == interval); + + interval = 0; + timer_interval_start_seconds(&t, interval); + ct_test(pTest, timer_interval(&t) == interval); + interval = 60L; + timer_interval_start_seconds(&t, interval); + interval *= 1000L; + ct_test(pTest, timer_interval(&t) == interval); + +} + + +#ifdef TEST_TIMER +int main( + void) +{ + Test *pTest; + bool rc; + + pTest = ct_create("Timer", NULL); + + /* individual tests */ + rc = ct_addTestFunction(pTest, testElapsedTimer); + assert(rc); + rc = ct_addTestFunction(pTest, testIntervalTimer); + assert(rc); + + + ct_setStream(pTest, stdout); + ct_run(pTest); + (void) ct_report(pTest); + + ct_destroy(pTest); + + return 0; +} +#endif +#endif diff --git a/bacnet-stack/ports/rx62n/timer.h b/bacnet-stack/ports/rx62n/timer.h new file mode 100644 index 00000000..dac54d47 --- /dev/null +++ b/bacnet-stack/ports/rx62n/timer.h @@ -0,0 +1,115 @@ +/************************************************************************** +* +* Copyright (C) 2009 Steve Karg +* +* Permission is hereby granted, free of charge, to any person obtaining +* a copy of this software and associated documentation files (the +* "Software"), to deal in the Software without restriction, including +* without limitation the rights to use, copy, modify, merge, publish, +* distribute, sublicense, and/or sell copies of the Software, and to +* permit persons to whom the Software is furnished to do so, subject to +* the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*********************************************************************/ +#ifndef TIMER_H +#define TIMER_H + +#include +#include + +/* Timer Module */ + +/* elapsed timer structure */ +struct etimer { + uint32_t start; +}; +/* interval timer structure */ +struct itimer { + uint32_t start; + uint32_t interval; +}; + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + + /* these 3 functions are created in the hardware specific module */ + void timer_init( + void); + uint32_t timer_milliseconds( + void); + uint8_t timer_milliseconds_byte( + void); + + /* these functions are in the generic timer.c module */ + + /* elapsed timer */ + void timer_elapsed_start( + struct etimer *t); + void timer_elapsed_start_offset( + struct etimer *t, + uint32_t offset); + uint32_t timer_elapsed_time( + struct etimer *t); + bool timer_elapsed_milliseconds( + struct etimer *t, + uint32_t value); + bool timer_elapsed_seconds( + struct etimer *t, + uint32_t value); + bool timer_elapsed_minutes( + struct etimer *t, + uint32_t value); + bool timer_elapsed_milliseconds_short( + struct etimer *t, + uint16_t value); + bool timer_elapsed_seconds_short( + struct etimer *t, + uint16_t value); + bool timer_elapsed_minutes_short( + struct etimer *t, + uint16_t value); + + /* interval timer */ + void timer_interval_start( + struct itimer *t, + uint32_t interval); + void timer_interval_start_seconds( + struct itimer *t, + uint32_t interval); + void timer_interval_start_minutes( + struct itimer *t, + uint32_t interval); + bool timer_interval_expired( + struct itimer *t); + uint32_t timer_interval( + struct itimer *t); + uint32_t timer_interval_elapsed( + struct itimer *t); + void timer_interval_no_expire( + struct itimer *t); + void timer_interval_reset( + struct itimer *t); + void timer_interval_restart( + struct itimer *t); + + /* special for 8-bit microcontrollers - limited to 255ms */ + uint8_t timer_milliseconds_delta( + uint8_t start); + uint8_t timer_milliseconds_mark( + void); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif