Application Note: JN-AN-1155 JenNet Home Alarm System This Application Note provides software to demonstrate a Home Alarm System, operating as a JenNet wireless network, with the following features: Controller device (with LCD panel) to manage the alarm system Multiple alarm devices for sounding alarms Multiple sensor devices reacting to digital inputs for monitoring contacts or PIR sensors All devices include tamper detection reporting The Application Note also incorporates features from the following Application Notes, demonstrating their use in a complete system: JN-AN-1116 JenNet Controlled Network Membership : Allows Coordinator node to exert control over which new devices are able to join its network JN-AN-1086 JenNet Over Network Download : Allows device software to be updated by transmitting it through the network while network continues to run Application Overview The JenNet Home Alarm System uses boards from the NXP JN5148-EK010 Evaluation Kit to build a typical alarm system comprising a control panel, motion sensors and alarms, as illustrated in the diagram below. The devices of the system are then described. Alarm Motion Sensor Motion Sensor Control Panel Motion Sensor Motion Sensor Alarm JN-AN-1155 (v1.0) 14-Mar-2011 NXP Laboratories UK 2011 1
Controller Device JenNet Home Alarm System The controller device acts as the control panel providing the user interface for the system via an LCD panel and buttons. These can be used to monitor the status of the system and arm or disarm it. The controller device also features a piezo-sounder to generate warning tones while the system is being armed and disarmed, in addition to a local alarm indication. The controller device also acts as the network Coordinator node, forming the JenNet network for the other devices to join. The controller device needs to be permanently powered. The LCD panel and button interface is used to control other devices joining the network - this ensures that alarm and sensor devices only join the correct network. The device application runs on the evaluation kit controller board which provides the LCD panel and buttons for the user interface, with the piezo-sounder being added via the 40-pin expansion connector on the board. Alarm Devices An alarm device is responsible for sounding the alarm using a piezo-sounder when motion or tampering is detected in the system under control of the controller device. There may be more than one alarm device in a system. The alarm devices act as network Router nodes extending the JenNet network for other nodes to join. An alarm device therefore needs to be permanently powered. The device application runs on evaluation kit sensor boards with the piezo-sounder being added via the 40-pin expansion connector on a board. Sensor Devices A sensor device is used to monitor contact points or a PIR detector, and to report activity to the controller device. The sensor devices act as End Device nodes in the JenNet network, entering sleep mode to preserve power when not active. A sensor device may therefore be battery-powered. The device application runs on evaluation kit sensor boards. 2 NXP Laboratories UK 2011 JN-AN-1155 (v1.0) 14-Mar-2011
Hardware Configuration The Application Note software is written to run on the controller board and sensor boards included in the JN5148-EK010 evaluation kit. For the purposes of this Application Note, some pins on each board s 40-pin expansion connector (J4) need to be connected together for example, to add a piezo-sounder. The required pin connections are detailed below. Controller Device Configuration The controller device application runs on the evaluation kit controller board (with LCD panel). The following modifications should be made on the board s 40-pin expansion connector: The tamper detection circuit is formed by connecting pins 15 and 16 together. The piezo-sounder ground should be connected to pin 40 with the input connected to pin 14. This configuration is illustrated in the following diagram: Alarm Device Configuration The alarm device application runs on evaluation kit sensor boards. The 40-pin expansion connector of each of these boards should be configured in an identical fashion to the controller device (described above). Sensor Device Configuration The sensor device application runs on evaluation kit sensor boards. The following modifications should be made on the 40-pin expansion connector of each of these boards: The tamper detection circuit operates on pulse counter 0 of the JN5148 microcontroller. For the purposes of this Application Note, pulse counter 0 can be connected to switch SW1 by connecting together pins 2 and 10 of the 40-pin expansion connector. The motion sensor detection circuit operates on pulse counter 1 of the JN5148 microcontroller. For the purposes of this Application Note, pulse counter 1 should be connected to switch SW2 by connecting together pins 9 and 11 of the 40-pin expansion connector. This configuration is illustrated in the following diagram: JN-AN-1155 (v1.0) 14-Mar-2011 NXP Laboratories UK 2011 3
Running the Application The application is best demonstrated by programming the pre-built binary files into the evaluation kits boards as described in the Building and Loading the Application section at the end of this document. Controller Device Initialisation When the controller device is started, the Initialisation screen will be displayed: Home Alarm System NXP OK LED1 will flash rapidly while the system controller establishes the network in its role as the Coordinator. Pressing switch SW1 below OK will display the Status screen, which is the main screen of the application. This screen displays the current status of the devices in the system while the system is unarmed. Until additional devices are allowed to join the network, it will only display an entry for the controller device (the dash indicates normal status for the controller device): Control - Arm Det Pin Sys Adding Additional Devices In order to allow the additional alarm and sensor devices into the network, the network must be opened by means of the System screen. Pressing switch SW4 below Sys on the Status screen will prompt for a PIN before allowing access to the System screen: SYSTEM Enter current PIN 1 2 3 4 The 4-digit PIN can be entered by pressing the switches SW1 through SW4 below the corresponding numbers on the display. The default PIN for a new system is 1234. Once 4 digits have been entered, the display will update to allow the number to be accepted: 4 NXP Laboratories UK 2011 JN-AN-1155 (v1.0) 14-Mar-2011
SYSTEM Enter current PIN 1 2 3 4 OK Clear Cancel Pressing SW3 below Cancel will abort the attempt to access the System screen and return to the Status screen. Entering an incorrect PIN or pressing SW2 below Clear will clear the entered PIN to allow another attempt to enter the correct PIN. Pressing SW1 below OK will accept the entered PIN and, if correct, display the System screen: SYSTEM Network closed OK Open Rst Rst Pressing SW1 below OK will return to the Status screen. Pressing SW2 below Open will open the network, allowing other nodes to request permission to join. The network remains open for a limited time, as indicated on the display in seconds: SYSTEM Network open 120 OK Close Rst Rst The network may be closed at any time by pressing SW2 below Close on the display. Note: The Rst options in the System screen will be described later in this document. An alarm or sensor device may then be started. When a device detects the network and attempts to join, the Authorisation screen will be displayed on the controller device: AUTHORISE Address 00158d00 000e69c2 Accept Reject The MAC address of the device requesting authorisation will be displayed on the screen. The MAC address is a 64-bit number which is unique to each device. To accept the node into the network, press SW1 below Accept on the display. To reject the node, press SW3 below Reject. The display will then return to the System screen. JN-AN-1155 (v1.0) 14-Mar-2011 NXP Laboratories UK 2011 5
Once the Authorisation screen has been displayed for a device, the network is automatically closed - only one device may be accepted into the system at a time. Additional devices can be added by opening the network once again from the System screen. While devices are attempting to join the network, they will flash their LED1 rapidly. On sensor devices, LED1 may stop flashing from time-to-time as End Device nodes sleep between network scan attempts. When all devices have been added to the system, pressing OK will return to the Status screen. System Operation Once alarm and sensor devices have been added to the network, the system can be controlled in the following way. Status Screen The Status screen shows the status of all devices in the network. A fully configured system will appear as follows: Control - Landing T Alarm1 Alarm2 - Bed1 - Bed2 - - Hall - Bed3 - Dining Lounge L M Kitchen - Arm Det Pin Sys Each device s status is indicated by a letter: - indicates that the device is operating normally L indicates that the device has been lost and is no longer reporting to the controller device T indicates that the device has been tampered with and should be investigated M indicates that motion has been detected by a sensor node j indicates that the device has just joined or re-joined the network x indicates that the device has just received new software via the UART s indicates that the device has started downloading software over the radio f indicates that the device has finished downloading software over the radio Pressing a switch will change the display screen as follows: Arm displays the Arming screens that allow the system to be armed Det displays the Detail screens, allowing device details to be reviewed Pin displays the PIN screen, allowing the PIN to be changed Sys displays the System screen for advanced system operations 6 NXP Laboratories UK 2011 JN-AN-1155 (v1.0) 14-Mar-2011
Arming Screens These screens allow the system to be armed. The first screen will request the current PIN before arming the system: DISARMED Enter PIN to arm 1 2 3 4 OK Clear Cancel Pressing Cancel will return to the Status screen without arming the system. Pressing Clear will clear the PIN, if entered incorrectly. Pressing OK for the correct PIN will display the Arming screen or for an incorrect pin will request that the PIN be re-entered. ARMING 30 Enter PIN to disarm 1 2 3 4 The Arming screen displays a countdown during which the alarm will not be sounded. The system can be disarmed again during this time by entering the correct PIN. Once the countdown reaches 0, the Armed screen is displayed: ARMED Enter PIN to disarm 1 2 3 4 In the Armed screen, the PIN may be entered to disarm the system. If motion is detected while the system is armed, the Activating Alarm screen will be displayed with a countdown. If the correct PIN is not entered before the countdown reaches 0, the alarm will be sounded: ACTIVATING ALARM 30 Enter PIN to disarm 1 2 3 4 JN-AN-1155 (v1.0) 14-Mar-2011 NXP Laboratories UK 2011 7
If the alarm sounds, the Alarm screen will be displayed. Entering the correct PIN will silence the alarm: ALARM Enter PIN to disarm 1 2 3 4 Note: There is a short period after arming the system during which an alarm will not be raised if motion is detected (see Arming screen above). This period allows motion detected when exiting the building to be cleared from the system. Detail Screens The Detail screens provide detailed information on each device in the system: 07 of 11 Sensor Address 00158d00 000e69c2 Name Bed2 Sw Snsr Snsr Ver 93 94 OK Next Num Name The top row displays the number of the device in the system and its device type. The second and third rows display the device s address. The fourth row displays the name assigned to the device. The fifth and sixth rows display the software and version information loaded into the device. Three data columns span these two rows but only one or two columns are ever displayed. The left-most column indicates the software currently running on the device, the centre column indicates the software that has been downloaded to the device (which it may update to) and the right-most column (not shown) indicates the software currently being downloaded to the device. Pressing the switches will perform the following actions: OK: Returns to the Status screen Next: Displays the details for the next device in the system Num: Allows the numeric part of the name to be changed for alarm and sensor devices (the value may be in the range 1 to 9, or there may be no numeric part) Name: Allows the name of a sensor device to be changed to indicate its location. Changing the name automatically removes the numeric part of the name. The name may be one of the following: Bath, Bed, Dining, Garage, Hall, Kitchen, Lounge, Sensor, Study, Toilet 8 NXP Laboratories UK 2011 JN-AN-1155 (v1.0) 14-Mar-2011
Set PIN Screens The Set PIN screens allow the PIN to be changed. The system will first prompt for the current PIN: SET PIN Enter current PIN 1 2 3 4 OK Clear Cancel Once the correct PIN has been entered, a new PIN can be provided: SET PIN Enter new PIN 4 3 2 1 OK Clear Cancel The system will then return to the System screen. System Screen The System screen allows access to system configuration options. The current PIN must be entered to access this screen: SYSTEM Network closed OK Open Rst Rst The buttons below the options perform the following tasks: OK: Returns to the status screen. Open/Close: Opens and closes the network to control whether new nodes are able to join, as described in the section Adding Additional Devices. Rst: Pressing both buttons marked Rst together will fully reset the controller to a factory condition, removing all nodes in the system from memory. Nodes will need to be reauthorised in order to rejoin the network. JN-AN-1155 (v1.0) 14-Mar-2011 NXP Laboratories UK 2011 9
Tamper Detection If tampering is detected on a device, an alarm will be sounded on the controller device. If the system is armed, the alarm devices will also sound an alarm. If an alarm device detects it has been tampered with, it will sound an alarm locally. The controller device will request the current PIN in order to silence the tamper alarm: TAMPER Enter PIN to disarm 1 2 3 4 While the tamper circuit is broken, the Status screen will display a T next to the device. However, the alarm will not be sounded again for that device while the tamper circuit remains broken. Lost Device Detection If the controller device does not receive regular communications from a device, it will consider the device to be lost from the system. An alarm will be sounded on the controller device. If the system is armed, the alarm devices will also sound an alarm. The controller device will request the current PIN in order to silence the lost device alarm: TAMPER Enter PIN to disarm 1 2 3 4 While the device is lost, the Status screen will display an L next to the device. However, the alarm will not be sounded again for that device while it remains lost. Lost Controller Detection If an alarm device detects that it is no longer in communication with the controller device, it will sound an alarm for a period of time. When alarm or sensor devices lose contact with the network, they will only attempt to re-join the network that they originally joined and will do this for a limited period of time. If the controller device needs to be replaced in a system, it may be necessary to wait for this period until the alarms and sensors can be re-introduced to the system. 10 NXP Laboratories UK 2011 JN-AN-1155 (v1.0) 14-Mar-2011
Device Indicators The devices in the system also indicate their status locally using LEDs as follows: Controller Device LED1 is flashed rapidly while the network is being formed. LED1 then lights briefly whenever data is transmitted or received over the radio. LED2 is lit whenever the controller device is sounding its alarm. Alarm Device LED1 is flashed rapidly while the alarm device is attempting to join the network. LED1 then lights briefly whenever data is transmitted or received over the radio. LED2 is lit whenever the alarm device is sounding its alarm. Sensor Device LED1 is flashed rapidly while the alarm device is attempting to join the network, but it may stop while sleeping between scan attempts. LED1 then lights briefly whenever data is transmitted or received over the radio. LED2 is lit (while awake) whenever the sensor device detects motion. System Update The software in the devices can be updated using the Over Network Download features of the application. These features are accessed via UART0 on the controller device running at 115200 baud, 8 data bits, no parity, one stop bit. A standard terminal application such as HyperTerminal can be used for this. Software Download The process is initiated by entering Ctrl-r into the terminal application. The message XMODEM erasing software... will be displayed while the Flash memory is erased in preparation for the new software. This will be followed by the message XMODEM receive (Ctrl-x to cancel)... when the controller device is ready to receive the software image. This can be cancelled at any time by pressing Ctrl-x and will automatically cancel after approximately 4 minutes if no data is transferred. Once in receive mode, updated sensor software may be transferred using the XMODEM protocol in CRC or 1K mode via the terminal application. When the software has been transferred into the controller device, from there it will begin to be downloaded through the network as indicated by the frequent flashing of LED1 on all devices. The sensor software must be downloaded into all devices in the system including the alarm devices. The progress of the download can be monitored on the Detail screens of the controller device. The process should then be repeated with the new alarm device software - this software will not be downloaded by sensor devices. JN-AN-1155 (v1.0) 14-Mar-2011 NXP Laboratories UK 2011 11
Finally, new controller device software can be transferred which will not be transferred through the network to any devices. The alarm system will continue to operate as normal while software is downloaded (although sensor devices will stay awake while downloading). Software Activation When all devices have downloaded their new software, it can be activated by pressing Ctrl-y in the terminal window. The message ACTIVATING will be output together with a countdown time to the activation. When the time is reached to activate the software, the devices will begin to leave the network, reboot running their new software and then re-join the network. 12 NXP Laboratories UK 2011 JN-AN-1155 (v1.0) 14-Mar-2011
Software Design This Application Note makes use of the Jenie API used to construct JenNet network applications. This API is centred around the use of a standard set of callback functions. The Application Note JenNet Tutorial (JN-AN-1085) provides a step-by-step introduction to creating JenNet applications using the Jenie API. Network Operation The network is formed and maintained automatically by the JenNet networking stack. Once the stack is started, nodes automatically form and join the JenNet tree network. If nodes detect that their position in the network is lost, they automatically attempt to re-join the network using the self-healing features of JenNet. Messages transmitted by the application make use of the end-to-end acknowledgements provided by JenNet. The application implements re-try mechanisms if an ack is not received when expected. For an introduction to programming JenNet networks using the Jenie APIs, refer to the Application Note JenNet Tutorial (JN-AN-1085). Controlled Network Membership Operation The software design used to exert control over which nodes are permitted to join the network is based upon the Application Note JenNet Controlled Network Membership (JN-AN-1116), which contains more detailed documentation on this functionality. Coordinator Node The Coordinator node of the JenNet network is able to exert control over which other nodes are able to join the network. This is done by using vapi_regnwkauthorisecallback() to register a function with JenNet that will be called each time a node attempts to join the network. The callback function bcoordinator_cbauthorisenetwork() then allows the application to accept or reject a node s request to join the network. The Coordinator stores a table of node addresses that have been authorised to join the network in both RAM and Flash memory. Any node requesting to join that is already recorded in the authorisation table is always allowed to re-join. Unauthorised nodes requesting to join while the network is closed (as controlled from the System screen) are always rejected. Once the network is opened from the System screen, the next node that attempts to join is initially rejected and the network closed again. However the address of this node is retained and presented to the user on the Authorisation screen to accept or reject. When the user accepts a node, its address is added to the authorisation table - the next time it attempts to join, it will be automatically accepted. The Coordinator also includes additional information in the beacon responses that it issues to nodes which are attempting to discover a network to join. This data comprises the least significant 16 bits of the Coordinator s address and is set using the JenNet function vapi_setuserbeaconbits(). Devices authorised to join the network retain this value as described in the next section. JN-AN-1155 (v1.0) 14-Mar-2011 NXP Laboratories UK 2011 13
Router and End Device Nodes Routers and End Device nodes access the beacon response data by using the vapi_regbeaconnotifycallback() function to register a callback function with JenNet that will be called each time a beacon response is received while the node is trying to find a network to join. The benddevice_cbbeaconnotify() and brouter_cbbeaconnotify() functions are registered according to the node type. If the node has never been authorised to join a network, all the beacon responses are accepted in the callback function and the beacon data is retained to be used if the node succeeds in joining a network. When a node first succeeds in joining a network, as indicated by the NETWORK_UP event, it loops through the previously retained beacon responses looking for the response that came from the node s new parent. When found, the 16 bits from the Coordinator s address are stored in RAM and Flash memory, to be used if the node ever needs to re-join the network. Router nodes then set this same value in their beacon responses using the function vapi_setuserbeaconbits(), so that nodes joining Routers have access to the same data. If an authorised node needs to re-join its network, it will reject any beacon responses from nodes that are not in the network which the authorised node previously belonged to. This streamlines the joining process and reduces the risk of the node being picked up by a different alarm system operating within radio range. This feature is time-limited - if the node fails to join within a certain period of time, the 16-bit value is erased from RAM and Flash memory, allowing the node to join any network once again. This allows nodes to be recovered if the Coordinator node needs to be replaced. Implementation Differences The main differences between this implementation and that of the Application Note Controlled Network Membership (JN-AN-1116) are as follows: JN-AN-1116 JenNet Controlled Network Membership New nodes are accepted into the network for a short timeperiod following a button press. Joining devices use the scan sort callback to access beacon responses. Authorised devices retain the joined network ID until the node is reset with a button held. The Coordinator node retains the authorised device table until reset with a button held. JN-AN-1155 JenNet Home Alarm System The user accepts new nodes into the network using the LCD and button interface. Joining devices use the beacon notify callback to access beacon responses. Authorised devices retain the joined network ID until the node fails to re-join the network within a certain time period. The Coordinator node retains the authorised device table until reset via the System screen. 14 NXP Laboratories UK 2011 JN-AN-1155 (v1.0) 14-Mar-2011
Alarm System Operation The general operation of the system is based upon that of the Application Note JenNet Over Network Download (JN-AN-1086), which was used as a template for this Application Note. The documentation for JenNet Over Network Download includes detailed information on the design of that software. The following sections describe how this Application Note makes use of the features of JenNet Over Network Download. Task Management JenNet Over Network Download provides a simple task system allowing tasks to be scheduled on a single or repeating basis together with a re-try mechanism. The tasks are mostly used to generate communications between nodes at regular intervals or in response to certain events. The following tasks provide the core of the Alarm System operation: Report Task The report task is scheduled to occur at regular intervals allowing each device to report its current status to the controller device. In JenNet Over Network Download, this task allows each node to inform the Coordinator node of the software currently being run and downloaded. This Application Note adds to this report the current state of the motion and tamper sensors, together with flags for changed values. If sensor readings change, the report task is immediately activated so that the controller device is updated and can react appropriately at the earliest opportunity. The controller device retains the most recent report from each device in the network and also records the time when the report was received. This is used by the controller device to detect lost devices - if a report is not received from a device for a multiple of the report interval, the controller device considers the device to be lost. Similarly if the sending device s report task fails, due to no acknowledgement being received from the controller device, it will consider the network to be lost. In the case of the alarm device, this will cause the alarm to be sounded locally. The task system has been extended in this Application Note to allow failed tasks to be reported to the application. The controller device s response indicates whether the system is armed to the other devices in the network. Sensor devices use this information to optimise their battery life. Alarm Task This task is not present in JenNet Over Network Download. The controller device activates this task when the alarm devices need to sound or silence their alarms. Once activated, the controller device works through the alarm devices sending commands to control the alarm sound to each alarm device in turn. JN-AN-1155 (v1.0) 14-Mar-2011 NXP Laboratories UK 2011 15
Sensor Operation This section describes how the sensors are operated. Motion Sensor The sensor devices use pulse counter 1 of the JN5148 microcontroller to sense motion. It is possible to connect this digital input to a PIR detector or simple contact switch. While the system is armed and no motion is previously detected, the pulse counter is configured to generate an interrupt when new motion is detected. This will immediately wake the sensor device, if it is asleep. While the system is unarmed or motion has already been detected, the pulse counter is configured to continue counting pulses but without waking from sleep. Upon waking, the pulse counter is read. If motion has begun or ceased, the report task is activated to inform the controller device. Using the pulse counter in this way allows the device to sleep for regular periods for the majority of its operation. The sensor device will only be woken immediately from sleep if motion is detected while the system is armed. This allows the battery life of the sensor devices to be predictable and efficient. Tamper Sensor In the sensor devices, the tamper detection works in a similar way to the motion detection but operates on pulse counter 0 and will always wake immediately upon detecting tampering, even when the system is not armed. In the controller and alarm devices, the tamper detection works by connecting two DIO pins together - one operates as an input and one as an output. Each time vjenie_cbmain() is called, the output pin is toggled and then the input pin is read. If the value on the input pin does not match that set by the output then the tamper connection has been broken. When tampering is detected or ended, the report task is activated to inform the controller device. In practice, the tamper detection circuit could be connected to electrical contacts or a microswitch in the casing for the various devices. 16 NXP Laboratories UK 2011 JN-AN-1155 (v1.0) 14-Mar-2011
Over Network Download Operation The Over Network Download features of the application closely follow those of the Application Note JenNet Over Network Download (JN-AN-1086), which contains detailed information for the software design. The general principle of the Over Network Download is as follows: 1. The End Device software is transferred into the Flash memory of the Coordinator node using the XMODEM protocol over a UART, creating an inactive software image. 2. This End Device software image is downloaded via the network by all other nodes in the network from parent to child. The Routers download this software so that they can make it available for any End Device children to download. 3. Next the Router software is transferred and downloaded in a similar fashion, but End Devices will not download this software. 4. The Coordinator software is then transferred, but Routers and End Devices will not download this software. 5. Finally, the Coordinator is issued with a command to activate the new software images. This activation is scheduled at a point in the future and the countdown passed to all nodes in the system. When the activation time is reached, the nodes leave the network, transfer the inactive software image to the active image and then reset to run the downloaded software. The following tasks are used to control this process: Report Task When nodes send their report message to the Coordinator, the Coordinator s response indicates which inactive software image is currently held by the Coordinator. If the reporting node finds that the Coordinator node has software which it needs to download then a query task is activated. The Coordinator s report response also includes the current value of the activation countdown timer that allows nodes to synchronise the activation of new software across the network. Query Task The query task generates a message to a node s parent to query the inactive software held by the parent. If the parent has software which the child needs to download, the download task is scheduled to download the software from the parent over the air, otherwise the sequence will be repeated the next time the node reports until its parent does have the software available. Download Task The download task regularly requests a chunk of the software image from its parent until the download is completed. The download task repeats at regular intervals. The gaps between the requests allow the normal operation of the Alarm System to function even while software is being downloaded. JN-AN-1155 (v1.0) 14-Mar-2011 NXP Laboratories UK 2011 17
Implementation Differences In JenNet Over Network Download (JN-AN-1086), the report task plays no part in controlling the download process but the query task is always running. This means that End Devices are expending energy by transmitting both report and query messages on a regular basis. The query response also includes the activation countdown timer used to synchronise the activation of new software. In this Application Note, the Coordinator s report reply message indicates if there is new software available to download. Child devices only run the query task when this is the case. This extends battery life in End Devices and reduces radio traffic throughout the network. On-Air Security All packets transmitted on-air are automatically encrypted by JenNet using a 128-bit security key. 18 NXP Laboratories UK 2011 JN-AN-1155 (v1.0) 14-Mar-2011
Module Overview The software is built from the following modules: Coordinator Controller Modules These modules are specific to the Coordinator/Controller device and are located in the Coordinator_Controller\Source folder of the Application Note. Coordinator.c/h This is the main module for the Coordinator node containing the standard set of Jenie API callback functions and provides the following functionality: Forms the network used by the application Controls which nodes are allowed into the network Monitors the status of other nodes in the network reacting to motion, tampering and lost nodes Controls the sounding of alarms on alarm devices Controls the LCD panel, buttons and sounds used to provide the user interface Provides the UART XMODEM interface used to update software using the over network download mechanism. Display.c/h This module provides code used to maintain the LCD panel with functions to display text and numeric values on the screen. This module is constructed in such a way as to allow the screens to be output to a UART (though this functionality is not currently implemented). Button.c/h This module provides code used to monitor the buttons so that the Coordinator node can react to button presses. Router Alarm Modules These modules are specific to the Router/Alarm devices and are located in the Router_Alarm\Source folder of the Application Note. Router.c/h This is the main module for the Router node containing the standard set of Jenie API callback functions and provides the following functionality: Joins the network formed by the Coordinator, extending the network for other nodes to join Reports tampering to the Coordinator and sounds a local alarm if tampered with or contact with the network is lost Sounds alarm tones as controlled by the Coordinator node JN-AN-1155 (v1.0) 14-Mar-2011 NXP Laboratories UK 2011 19
End Device Sensor Modules JenNet Home Alarm System These modules are specific to the End Device/Sensor devices and are located in the EndDevice_Sensor\Source folder of the Application Note. EndDevice.c/h This is the main module for the End Device node containing the standard set of Jenie API callback functions and provides the following functionality: Joins the network formed by the Coordinator Sleeps for the majority of the time, waking on a regular basis or upon pulse counter changes to report the motion and tamper sensor states to the Coordinator. Common Modules The modules are shared by one or more of the devices and are located in the Common\Source folder of the Application Note: Application.h This header file contains many defines used throughout the application, including defines for: Specifying the parameters of the network to join UARTs to be used by the application Timing values for various functions and tasks Child.c/h This module contains code used by devices that act as children in the network (Routers and End Devices). It provides the following functionality: Regularly reports current status to the Coordinator node Downloads new software from its parent device when available Flash.c/h This module is used to read and write data to the Flash memory during over network download while preserving the device s MAC address. Node.c/h This module contains the code that is common to all the node types. It provides the following functionality: Tracks the status of the node in the network Handles the control of LED0 to indicate network activity Provides debugging functions when enabled 20 NXP Laboratories UK 2011 JN-AN-1155 (v1.0) 14-Mar-2011
Parent.c/h This module contains code used by devices that act as parents in the network (Coordinator and Routers). It provides child devices with new software during over network download. Piezo.c/h This module provides functions to operate the piezo-sounders used by the controller and alarm devices. Task.c/h This module provides the task functions used to operate the simple task system. UartIO.c/h This module provides basic UART support for debugging and is also used by the XMODEM file transfer protocol. Xmodem.c/h This module implements the XMODEM file transfer protocol used to load new software into the Coordinator node. Extending the Application Extending the PIN The PIN used by this application can only be set using the digits 1 to 4, so that it can operate on the evaluation kit controller board which only has 4 buttons. Additional buttons could be used to allow the use of digits 0 to 9, increasing the security of the system. If additional buttons are made available in this way, the storage of the PIN in Flash memory will need to be updated, as it is stored in a single byte for efficiency. The storage is handled in the vcoordinator_flashwrite() and vcoordinator_flashread() functions. Compatibility The software provided with this Application Note has been tested with the following evaluation kits and SDK (Software Developer s Kit) versions: Product Type Part Number Version Evaluation Kits JN5148-EK010 - SDK Libraries JN-SW-4040 v1.5 SDK Toolchain JN-SW-4041 v1.1 JN-AN-1155 (v1.0) 14-Mar-2011 NXP Laboratories UK 2011 21
Building and Loading the Application The software provided with this Application Note can be built for the JN5148 device using the Eclipse IDE or makefiles. In order to build the supplied software, the application s folder must be placed in the folder: <JN5148_SDK_ROOT>\Application where <JN5148_SDK_ROOT> is the path into which the JN5148 SDK was installed (by default, this is C:\Jennic). The Application directory is automatically created when you install the SDK. Build the applications for the Co-ordinator, Router and End Device as described in the appropriate section below, depending on whether you intend to use Eclipse or makefiles. Using Eclipse (JN5148 Only) To build the application and load it into JN5148 boards, follow the instructions below: 1. Ensure that the project directory is located in <JN5148_SDK_ROOT>\Application where <JN5148_SDK_ROOT> is the path into which the JN5148 SDK was installed. 2. Start the Eclipse platform and import the relevant project files (.project and.cproject) as follows: a) In Eclipse, follow the menu path File>Import to display the Import dialogue box. b) In the dialogue box, expand General, select Existing Projects into Workspace and click Next. c) Enable Select root directory, browse to the Application directory and click OK. d) In the Projects box, select the project to be imported and click Finish. 3. Build the application. To do this, ensure that the project is highlighted in the left panel of Eclipse and use the drop-down list associated with the hammer icon in the Eclipse toolbar to select the relevant build configuration once selected, the application will automatically build. Repeat this to build the other applications. The binary files will be created in the relevant Build directories for the applications, the resulting filenames indicating the chip type (JN5148). 4. Load the resulting binary files into the boards. You can do this using the JN51xx Flash Programmer, which can be launched from within Eclipse or used directly (and is described in the JN51xx Flash Programmer User Guide (JN-UG-3007)). 22 NXP Laboratories UK 2011 JN-AN-1155 (v1.0) 14-Mar-2011
Using Makefiles The application for each node type (Co-ordinator, Router, End Device) has its own Build directory, which contains the makefiles for the application. To build an application and load it into a JN5148 board, follow the instructions below: 1. Ensure that the project directory is located in <JN5148_SDK_ROOT>\Application where <JN5148_SDK_ROOT> is the path into which the JN5148 SDK was installed. 2. Navigate to the Build directory for the application to be built and at the command prompt, enter: make clean all Note that for the JN5148 device, you can alternatively enter the above command from the top level of the project directory, which will build the binaries for all the applications. The binary file will be created in the relevant Build directory for the application, the resulting filename indicating the chip type (JN5148) for which the application was built. 3. Load the resulting binary file into the board. To do this, use the JN51xx Flash Programmer, described in the JN51xx Flash Programmer User Guide (JN-UG-3007). JN-AN-1155 (v1.0) 14-Mar-2011 NXP Laboratories UK 2011 23
Revision History Version Notes 1.0 First release Important Notice Jennic reserves the right to make corrections, modifications, enhancements, improvements and other changes to its products and services at any time, and to discontinue any product or service without notice. Customers should obtain the latest relevant information before placing orders, and should verify that such information is current and complete. All products are sold subject to Jennic s terms and conditions of sale, supplied at the time of order acknowledgment. Information relating to device applications, and the like, is intended as suggestion only and may be superseded by updates. It is the customer s responsibility to ensure that their application meets their own specifications. Jennic makes no representation and gives no warranty relating to advice, support or customer product design. Jennic assumes no responsibility or liability for the use of any of its products, conveys no license or title under any patent, copyright or mask work rights to these products, and makes no representations or warranties that these products are free from patent, copyright or mask work infringement, unless otherwise specified. Jennic products are not intended for use in life support systems/appliances or any systems where product malfunction can reasonably be expected to result in personal injury, death, severe property damage or environmental damage. Jennic customers using or selling Jennic products for use in such applications do so at their own risk and agree to fully indemnify Jennic for any damages resulting from such use. All trademarks are the property of their respective owners. NXP Laboratories UK Ltd (Formerly Jennic Ltd) Furnival Street Sheffield S1 4QT United Kingdom Tel: +44 (0)114 281 2655 Fax: +44 (0)114 281 2951 E-mail: info@jennic.com For the contact details of your local Jennic office or distributor, refer to the Jennic web site: www.nxp.com/jennic 24 NXP Laboratories UK 2011 JN-AN-1155 (v1.0) 14-Mar-2011