Jenie API Reference Manual
Jenie API Reference Manual
Reference Manual
JN-RM-2035
Revision 1.8
17 March 2010
Jenie API
Reference Manual Jennic
Contents
About this Manual 9
Organisation 9
Conventions 10
Acronyms and Abbreviations 10
Related Documents 11
Feedback Address 11
1. Jenie Overview 13
1.1 Core Functionality 13
1.2 Hardware Functionality 14
2. Jenie Functions 15
2.1 “Application to Stack” Functions 16
2.1.1 Network Management Functions 16
eJenie_Start 17
eJenie_Leave 18
eJenie_RegisterServices 19
eJenie_RequestServices 20
eJenie_BindService 21
eJenie_UnBindService 22
eJenie_SetPermitJoin 23
bJenie_GetPermitJoin 24
eJenie_SetSecurityKey 25
2.1.2 Data Transfer Functions 26
eJenie_SendData 27
eJenie_SendDataToBoundService 29
eJenie_PollParent 30
2.1.3 System Functions 31
vJPDM_SaveContext 32
eJPDM_RestoreContext 33
vJPDM_EraseAllContext 34
eJenie_SetSleepPeriod 35
eJenie_Sleep 36
eJenie_RadioPower 38
u32Jenie_GetVersion 39
2.1.4 Statistics Functions 40
u16Jenie_GetRoutingTableSize 41
eJenie_GetRoutingTableEntry 42
u8Jenie_GetNeighbourTableSize 43
eJenie_GetNeighbourTableEntry 44
vJPI_UartSetControl 91
vJPI_UartSetInterrupt 92
vJPI_UartSetRTSCTS 93
vJPI_UartReset 94
u8JPI_UartReadLineStatus 95
u8JPI_UartReadModemStatus 96
u8JPI_UartReadInterruptStatus 97
vJPI_UartWriteData 98
u8JPI_UartReadData 99
vJPI_Uart0RegisterCallback 100
vJPI_Uart1RegisterCallback 101
3.5 Timers 102
vJPI_TimerEnable 104
vJPI_TimerDisable 106
vJPI_TimerStart 107
vJPI_TimerStop 109
vJPI_TimerStartCapture 110
u32JPI_TimerReadCapture 111
u8JPI_TimerFired 112
vJPI_Timer0RegisterCallback 113
vJPI_Timer1RegisterCallback 114
vJPI_Timer2RegisterCallback (JN5148 Only) 115
3.6 Wake Timers 116
vJPI_WakeTimerEnable 118
vJPI_WakeTimerStart 119
vJPI_WakeTimerStop 120
u32JPI_WakeTimerRead 121
u8JPI_WakeTimerStatus 122
u8JPI_WakeTimerFiredStatus 123
u32JPI_WakeTimerCalibrate 124
3.7 Serial Peripheral Interface (SPI) 125
vJPI_SpiConfigure 126
vJPI_SpiReadConfiguration 128
vJPI_SpiRestoreConfiguration 129
vJPI_SpiSelect 130
vJPI_SpiStop 131
vJPI_SpiStartTransfer32 132
u32JPI_SpiReadTransfer32 133
vJPI_SpiStartTransfer16 134
u16JPI_SpiReadTransfer16 135
vJPI_SpiStartTransfer8 136
u8JPI_SpiReadTransfer8 137
bJPI_SpiPollBusy 138
vJPI_SpiWaitBusy 139
vJPI_SpiRegisterCallback 140
Appendices 161
A. Global Network Parameters 161
B. Enumerated Types and Defines 164
B.1 For Core Jenie Functions 164
B.2 For Jenie Peripheral Interface Functions 166
C. Data Types 178
D. Stack Events 180
D.1 Stack Management Events 180
D.2 Data Events 182
E. Integrated Peripheral Interrupt Handling 184
E.1 Callback Function Prototype and Parameters 184
E.2 Handling Wake Interrupts 188
F. JenNet API 191
F.1 JenNet Functions 192
eApi_SendDataToExtNwk 193
vNwk_DeleteChild 194
vApi_SetScanSleep 195
vApi_SetBcastTTL 196
vApi_SetPurgeRoute 197
vApi_SetPurgeInterval 198
vNwk_SetBeaconCalming 199
vApi_SetUserBeaconBits 200
u16Api_GetUserBeaconBits 201
u8Api_GetLastPktLqi 202
u16Api_GetDepth 203
u8Api_GetStackState 204
u32Api_GetVersion 205
vApi_RegBeaconNotifyCallback 206
vApi_RegLocalAuthoriseCallback 207
vApi_RegNwkAuthoriseCallback 208
vApi_RegScanSortCallback 209
F.2 JenNet Network Parameters 210
G. Link Quality Indication (LQI) 214
Organisation
This manual consists of 3 chapters and 7 appendices, as follows:
Chapter 1 introduces the Jenie API.
Chapter 2 details the main functions of the Jenie API.
Chapter 3 details the Jenie Peripherals Interface (JPI) functions of the API.
The Appendices provide ancillary information needed to use the Jenie API:
global network parameters, enumerated types, data types, stack events,
hardware interrupts and LQI values. In addition, an appendix is provided which
describes functions and network parameters of the JenNet layer, which sits
below Jenie in the stack.
Related Documents
[1] Jenie Application Templates Application Note (JN-AN-1061)
[2] Jenie Tutorial Application Note (JN-AN-1085)
[3] Jenie API User Guide (JN-UG-3042)
[4] JenNet Stack User Guide (JN-UG-3041)
[5] IEEE 802.15.4 Wireless Networks User Guide (JN-UG-3024)
[6] Board API Reference Manual (JN-RM-2003)
[7] Application Queue API Reference Manual (JN-RM-2025)
Feedback Address
If you wish to comment on this manual, or any other Jennic user documentation,
please provide your feedback by writing to us (quoting the manual reference number
and version) at the following postal address or e-mail address:
Applications
Jennic Ltd
Furnival Street
Sheffield S1 4QT
United Kingdom
[email protected]
1. Jenie Overview
Jennic’s proprietary Jenie software provides an easy-to-use interface for developing
wireless network applications for the Jennic JN5139 and JN5148 wireless
microcontrollers. The Jenie Application Programming Interface (API) comprises C
functions for controlling the wireless network and the on-chip hardware peripherals of
the JN5139/JN5148 device. This functionality is outlined below.
2. Jenie Functions
This chapter details the core functions of the Jenie API (Application Programming
Interface). These functions are divided into two categories, according to how they are
called:
“Application to Stack” functions, described in Section 2.1.
“Stack to Application” functions, described in Section 2.2.
In addition, each of the above categories is sub-divided into functions that deal with
management tasks, data transfer tasks and system tasks (see Chapter 1 for an
overview of these three areas).
eJenie_Start
teJenieStatusCode eJenie_Start(
teJenieDeviceType eDevType);
Description
This function is normally (but not always) called from eJenie_CbInit() and starts the
stack on the device.
On the Co-ordinator, this will start a network.
On an End Device or Router, starting the stack causes the node to find and join a
network.
On a sleeping End Device, once the device has woken from sleep with memory
contents held, this function will cause the stack to resume without the device needing to
re-associate with its parent.
The appropriate behaviour of this function for a given node type requires the
application to be linked with the relevant Jenie library file - Jenie_TreeCRLib.a for
the Co-ordinator or a Router, Jenie_TreeEDLib.a for an End Device.
Parameters
eDevType Indicates the role of the device in the network - one of Co-
ordinator, Router, End Device:
E_JENIE_COORDINATOR
E_JENIE_ROUTER
E_JENIE_END_DEVICE
Returns
One of:
E_JENIE_SUCCESS
E_JENIE_ERR_INVLD_PARAM
For explanations, refer to Appendix B.
teJenieStatusCode eJenie_Leave(void);
Description
This function disassociates the node from its parent and therefore causes the device
to leave the network.
On leaving the network, the device enters the idle state in which vJenie_CbMain()
is called regularly, but the device does not necessarily attempt to establish or join a
network. The device will remain in the idle state until eJenie_Start() is called.
Parameters
None
Returns
One of:
E_JENIE_SUCCESS
E_JENIE_ERR_UNKNOWN
E_JENIE_ERR_STACK_BUSY
For explanations, refer to Appendix B.
eJenie_RegisterServices
teJenieStatusCode eJenie_RegisterServices(
uint32 u32Services);
Description
This function is used to register the services available on the local node.
To do this, a list of supported services is submitted to the network as a 32-bit value
based on the network’s Service Profile, in which each bit position corresponds to a
particular service in the network. Here, a bit value of ‘1’ indicates the corresponding
service is supported, while ‘0’ indicates the service is not supported.
If the local node is the Co-ordinator or a Router, the registered services are held locally
and this function can return immediately with status code success or failure.
If the local node is an End Device, the registered services are submitted to its parent
and the status code is deferred - it is eventually received as the stack management
event E_JENIE_REG_SVC_RSP via a call to the callback function
vJenie_CbStackMgmtEvent().
This function will not successfully return until the network is up and running. Until the
network is up, the function will return the error code E_JENIE_ERR_STACK_BUSY.
Parameters
u32Services 32-bit value detailing the services to be registered (see above)
Returns
One of:
E_JENIE_SUCCESS
E_JENIE_DEFERRED
E_JENIE_ERR_UNKNOWN
E_JENIE_ERR_STACK_BUSY
For explanations, refer to Appendix B.
teJenieStatusCode eJenie_RequestServices(
uint32 u32Services
bool_t bMatchAll);
Description
This function is used to find remote nodes that have the specified services. The
remote nodes will respond individually.
The requested services are specified as a 32-bit value based on the network’s
Service Profile, in which each bit position corresponds to a particular service in the
network. Here, a bit value of ‘1’ indicates the corresponding service is requested,
while ‘0’ indicates the service is not requested.
You must also specify whether all of the requested services or at least one of the
requested services must be present on the remote node for the latter to generate a
response.
The function returns almost immediately but will not be successful until the network
is up and running. Until the network is up, the function will return the error code
E_JENIE_ERR_STACK_BUSY.
Responses from the remote nodes will be received as a series of
E_JENIE_SVC_REQ_RSP stack events via the callback function
vJenie_CbStackMgmtEvent().
Parameters
u32Services 32-bit value detailing the requested services (see above)
bMatchAll Indicates whether ALL or ANY of the requested services
should be present on the remote node to warrant a response:
TRUE: All the requested services should be present
FALSE: Any of the requested services should be present
Returns
One of:
E_JENIE_ERR_INVLD_PARAM
E_JENIE_DEFERRED
E_JENIE_ERR_UNKNOWN
E_JENIE_ERR_STACK_BUSY
For explanations, refer to Appendix B.
eJenie_BindService
teJenieStatusCode eJenie_BindService(
uint8 u8SrcService,
uint64 u64DestAddr,
uint8 u8DestService);
Description
This function is used to bind a local service to the specified service on the specified
remote node. Among the parameters of this function, you must specify the address
of the remote node (u64DestAddr) and the remote service (u8DestService). These
two pieces of information will have been obtained from the event
E_JENIE_SVC_REQ_RSP received as the result of a service request submitted
using the function eJenie_RequestServices().
Once a service binding has been created, messages can be sent to the remote
service(s) using the function eJenie_SendDataToBoundService().
If you wish to subsequently unbind two services, use the eJenie_UnBindService()
function.
Parameters
u8SrcService Service ID of local service to be bound
u64DestAddr Address of the remote node which contains the bound service
u8DestService Service ID of the service to be bound to on the remote node
Returns
One of:
E_JENIE_SUCCESS
E_JENIE_ERR_INVLD_PARAM
E_JENIE_ERR_STACK_RSRC
For explanations, refer to Appendix B.
teJenieStatusCode eJenie_UnBindService(
uint8 u8SrcService,
uint64 u64DestAddr,
uint8 u8DestService);
Description
This function is used to unbind a local service from the specified service on the
specified remote node. The services must have been previously bound using the
function eJenie_BindService(). Among the parameters, you must specify the local
service (u8SrcService), the address of the remote node (u64DestAddr) and the
remote service (u8DestService) to be unbound. These parameters can be used as
described in the table below to remove one or more bindings in one function call:
Once the services have been unbound, messages can no longer be sent to the
remote service(s) using the function eJenie_SendDataToBoundService().
Parameters
u8SrcService Service ID of local service to be unbound
u64DestAddr Address of the remote node which contains the bound service
u8DestService Service ID of the service to be unbound on the remote node
Returns
One of:
E_JENIE_SUCCESS
E_JENIE_ERR_INVLD_PARAM
E_JENIE_ERR_STACK_RSRC
For explanations, refer to Appendix B.
eJenie_SetPermitJoin
teJenieStatusCode eJenie_SetPermitJoin(
bool_t bAssociate);
Description
This function is used to enable or disable "permit joining" on the Co-ordinator or a
Router - that is, it configures the device to allow or forbid other devices (End Devices
or Routers) to associate with it, and therefore to join the network.
Parameters
bAssociate “Permit joining” status to set:
TRUE - allow joinings
FALSE - forbid joinings
Returns
E_JENIE_SUCCESS
bool_t bJenie_GetPermitJoin(void);
Description
This function is used to obtain the current "permit joining" state of the Co-ordinator or
Router - that is, whether the device is currently allowing other devices (End Devices
or Routers) to associate with it, and therefore to join the network.
Parameters
None
Returns
One of:
TRUE - joinings allowed
FALSE - joinings forbidden
eJenie_SetSecurityKey
teJenieStatusCode eJenie_SetSecurityKey(
tsJenieSecKey *pKey,
uint64 u64Addr);
Description
This function is used to enable security and set a key value for encrypting/decrypting
data during communications between the local node and the specified remote node
- that is, the local node will encode the data with the specified key and the remote will
decode the data with the same key. Note that this function must therefore also be
called on the remote node to set the same key value.
The function should be called from within the callback function vJenie_CbInit() and
should not be called from within vJenie_CbConfigureNetwork().
When security is enabled, the data that is encrypted is the payload of the
IEEE 802.15.4 MAC frame.
This function can also be used to disable security in communications with the
specified remote node by specifying a NULL security key pointer.
Parameters
*pKey Pointer to a security key. A NULL pointer disables security.
u64Addr Address of remote node associated with specified key -
ignored in current release (see Caution above).
Returns
One of:
E_JENIE_SUCCESS
E_JENIE_ERR_INVLD_PARAM
For explanations, refer to Appendix B.
eJenie_SendData
Description
This function is used to send data to the specified remote node. This type of send
requires the address of the destination node - this is the 64-bit IEEE/MAC address of
the device. This address will have been previously obtained as the result of a Service
Discovery implemented using eJenie_RequestServices().
A data broadcast to all Router nodes can also be performed using this function - in
this case, the destination address must be set to zero and TXOPTION_BDCAST must
be selected in the transmission options (u8TxFlags).
The maximum payload data size depends on the type of transmission (and therefore
the JenNet frame type) and whether security has been enabled (using the function
eJenie_SetSecurityKey()), as follows:
This function will not successfully return until the network is up and running. Until the
network is up, the function will return the error code E_JENIE_ERR_STACK_BUSY.
A call to this function will (eventually) result in an E_JENIE_PACKET_SENT or
E_JENIE_PACKET_FAILED event to indicate the success or failure of the sent
message reaching the first hop to the destination, unless the transmission option
TXOPTION_SILENT or TXOPTION_BDCAST has been set in which case these
events are not generated.
Parameters
u64DestAddr Address of the destination node. For a broadcast or to send
data to the Co-ordinator, this parameter must be set to zero
(for a broadcast, u8TxFlags must also be set appropriately)
*pu8Payload Pointer to the data to be sent
u16Length Length of data to be sent, in bytes (for limits, see above)
u8TxFlags Sets the transmission options. These options are detailed in
Table 2 on page 165. The values can be logical ORed to
simultaneously specify more than one option
eJenie_SendDataToBoundService
teJenieStatusCode eJenie_SendDataToBoundService(
uint8 u8Service,
uint8 *pu8Payload,
uint16 u16Length,
uint8 u8TxFlags);
Description
This function is used to send data from a local service to a remote service, where
these services have previously been bound using eJenie_BindService(). Only the
local service needs to be specified.
The maximum payload data size depends on whether security has been enabled
(using the function eJenie_SetSecurityKey()), as follows:
If security is disabled, the maximum data size is 74 bytes.
If security is enabled, the maximum data size is 53 bytes.
This function will not successfully return until the network is up and running. Until the
network is up, the function will return the error code E_JENIE_ERR_STACK_BUSY.
A call to this function will (eventually) result in an E_JENIE_PACKET_SENT or
E_JENIE_PACKET_FAILED event to indicate the success or failure of the sent
message reaching the first hop to the destination.
Parameters
u8Service Service ID of local service from which data is to be sent
*pu8Payload Pointer to the data to be sent
u16Length Length of data to be sent, in bytes (for limits, see above)
u8TxFlags Sets the transmission options. These options are detailed in
Table 2 on page 165. The values can be logical ORed to
simultaneously specify more than one option
Returns
One of:
E_JENIE_ERR_INVLD_PARAM
E_JENIE_DEFERRED
E_JENIE_ERR_UNKNOWN
E_JENIE_ERR_STACK_BUSY
For explanations, refer to Appendix B.
teJenieStatusCode eJenie_PollParent(void);
Description
This function is used by an End Device to check if its parent is holding pending data
for it. If data is pending, a data event will be received after a short delay via the
callback function vJenie_CbStackDataEvent(). The function can, for example, be
called after the End Device has come out of sleep mode.
The function will not successfully return until the network is up and running. Until the
network is up, the function will return the error code E_JENIE_ERR_STACK_BUSY.
Therefore, the function should not be called until an E_JENIE_NETWORK_UP event
has been generated (and must not be called immediately after a
E_JENIE_STACK_RESET event).
If a call to this function is successful (i.e. it returns a status of E_JENIE_DEFERRED)
then an E_JENIE_POLL_CMPLT event will be generated. If this event contains a
status value of E_JENIE_POLL_DATA_READY, this indicates that data is available
which will follow immediately in a E_JENIE_DATA event. However, this data event
may not deliver all the pending data for the node. You are therefore advised to call
eJenie_PollParent() repeatedly until there is no further pending data, indicated
when the event E_JENIE_POLL_CMPLT contains a status value of
E_JENIE_POLL_NO_DATA.
The E_JENIE_POLL_CMPLT event will also be generated (and the status
E_JENIE_DEFERRED returned) if no response is received from the parent. In this
case, the event also contains a status value of E_JENIE_POLL_NO_DATA.
Parameters
None
Returns
One of:
E_JENIE_DEFERRED
E_JENIE_ERR_UNKNOWN
E_JENIE_ERR_STACK_BUSY
For explanations, refer to Appendix B.
void vJPDM_SaveContext(void);
Description
This function is used to save both network and application context data to external
non-volatile memory. This allows the data to be recovered and the node to resume
normal operation following power loss to the on-chip memory (e.g. power failure or
sleep without memory held). Network and application context save/restore can be
individually enabled but if both are enabled, a single call to this function will save both
sets of context data.
To enable save/restore of network context, the global variable
gJenie_RecoverFromJpdm must be set to TRUE within the callback function
vJenie_CbConfigureNetwork(). The saved data will then be automatically
recovered when the stack is re-started using eJenie_Start().
To enable save/restore of application context, the eJPDM_RestoreContext()
function must be called within the callback function vJenie_CbInit().
Note that for a Router, child tables and routing tables will not be saved.
Parameters
None
Returns
None
eJPDM_RestoreContext
teJenieStatusCode eJPDM_RestoreContext(
tsJPDM_BufferDescription *psDescription);
Description
This function is used to retrieve application context data stored in external non-
volatile memory, where this data was previously saved using the function
vJPDM_SaveContext(). This allows application data to be recovered so that the
node can resume normal operation following power loss to the on-chip memory (e.g.
power failure or sleep without memory held).
The eJPDM_RestoreContext() function must be included in the callback function
vJenie_CbInit() for a cold start:
The first time the application is run, the function registers a buffer in on-chip memory
where the application context data will be stored - this buffer is set up using the macro
JPDM_DECLARE_BUFFER_DESCRIPTION (see below).
When the application is subsequently re-started, the function will recover saved
application context data from external non-volatile memory. The recovered data is
stored in the buffer set up using JPDM_DECLARE_BUFFER_DESCRIPTION.
The above macro is defined as follows:
JPDM_DECLARE_BUFFER_DESCRIPTION(name, ptr, size)
where:
name is a label for the buffer as an ASCII string in quotes
ptr is a pointer to the start of the buffer in on-chip memory
size is the number of bytes in the buffer
Parameters
*psDescription Pointer to descriptor of on-chip memory buffer in which
application context data will be stored.
Returns
One of:
E_JENIE_SUCCESS
E_JENIE_ERR_INVLD_PARAM
For explanations, refer to Appendix B.
The invalid parameter code is returned, for example, if the specified memory buffer
size is too large (it must not be greater than the external memory sector size
determined by the global variable gJpdmSectorSize).
void vJPDM_EraseAllContext(void);
Description
This function can be used to erase all context data (application and network) in
non-volatile memory, previously stored using the function
vJPDM_SaveContext(void).
You are likely to want to do this in order to revert back to the default context data. To
prevent the current context data from automatically being re-saved in non-volatile
memory, you should immediately follow this function call with a software reset, by
calling vJPI_SwReset(). This will ensure that the current context data is lost and the
default context data is restored to RAM.
Parameters
None
Returns
None
eJenie_SetSleepPeriod
teJenieStatusCode eJenie_SetSleepPeriod(
uint32 u32SleepPeriodMs);
Description
This function can be used on an End Device to set the duration for which the device
will sleep when put into sleep mode using the function eJenie_Sleep().
This wake method uses an on-chip wake timer, for which the 32-kHz oscillator must
be running during sleep. Therefore, a sleep mode with oscillator running must be
specified through eJenie_Sleep().
Parameters
u32SleepPeriodMs Sleep duration, in milliseconds
Returns
E_JENIE_SUCCESS
teJenieStatusCode eJenie_Sleep(
teJenNetSleepMode eSleepMode);
Description
This function can be used to put an End Device into sleep mode. The function informs
the stack that the application will be ready to sleep once it has performed any tasks
that remain to be completed. It must be called from vJenie_CbMain() only (and from
no other callback function).
The following sleep options can be specified:
with or without the 32-kHz on-chip oscillator running
with or without preserving the contents of on-chip RAM (memory held)
Note that ‘doze mode’ of the JN5139/JN5148 device is not supported by Jenie/
JenNet.
The device can be pre-configured to sleep for a fixed duration, set using the function
eJenie_SetSleepPeriod(). This wake method uses the on-chip wake timers, for
which the 32-kHz oscillator must be running during sleep. The device can
alternatively be woken from sleep by an event deriving from the on-chip comparators
or DIOs - this method does not require the oscillator to be running during sleep.
Holding memory during sleep enables the device to retain context data which will
allow the device to quickly resume its network operation on waking. However, “sleep
with memory held” consumes more power than “sleep without memory held”. If you
have selected “sleep without memory held”, you can save context data (externally)
before sleeping using the function vJPDM_SaveContext().
On waking from sleep, the network stack calls the function vJenie_CbInit(), and the
device remains in the idle state and does not rejoin the network until this function
calls eJenie_Start(). While in the idle state, vJenie_CbMain() is regularly called by
the network stack, so that other necessary tasks can be performed. If you have
selected “sleep without memory held”, you will need to perform a cold restart and
retrieve the stored application context data by calling the function
eJPDM_RestoreContext() before calling eJenie_Start() in vJenie_CbInit().
Note that if a wake timer (see Section 3.6) is used to wake the device from “sleep
with memory held”, no event is generated via the vJenie_CbHwEvent() function or
the registered system controller callback function (although a wake-up initiated by a
DIO or comparator will generate a hardware event).
In ‘deep sleep’ mode, all switchable power domains are powered off and the 32-kHz
oscillator is stopped. This mode can only be exited by power cycling (switching off
then on) or resetting the chip (a DIO event can be used to trigger a reset).
Parameters
eSleepMode Specifies the required sleep mode, one of:
E_JENIE_SLEEP_OSCON_RAMON
E_JENIE_SLEEP_OSCON_RAMOFF
E_JENIE_SLEEP_OSCOFF_RAMON
E_JENIE_SLEEP_OSCOFF_RAMOFF
E_JENIE_SLEEP_DEEP
Returns
E_JENIE_SUCCESS
E_JENIE_ERR_UNKNOWN
Description
This function can be used to set the transmit power level of the radio transceiver, or
to switch the radio transceiver on or off. The transmit power level can be set to a
value in the range -30 to +18 dBm, in steps of 6 dBm, with the following restrictions
depending on the module type:
Standard module: -30 to 0 dBm (default: 0 dBm)
High-power module: -12 to +18 dBm (default: 18 dBm)
In addition to the above values, 20 and 21 are used to switch the radio transmitter on
and off, respectively (enumerations are available to do this). With the exception of
these two special values, if the specified power level is not a multiple of 6, the power
level set by this function is the nearest multiple of 6 dBm within the valid range.
To set the power level for a high-power module, you must enable high-power mode
using the parameter bHighPower.
Parameters
iPowerLevel Power level as multiple of 6 in the range -30 to +18, or one of:
E_JENIE_RADIO_OFF - switch radio transceiver off
E_JENIE_RADIO_ON - switch radio transceiver on
bHighPower Enables high-power mode for a Jennic high-power module:
TRUE - high-power mode enabled
FALSE - high-power mode disabled
Returns
One of:
E_JENIE_SUCCESS
E_JENIE_ERR_INVLD_PARAM
For explanations, refer to Appendix B.
u32Jenie_GetVersion
uint32 u32Jenie_GetVersion(
teJenieComponent eComponent);
Description
This function is used obtain the version number of the specified component of the
system. The function provides a means of checking that the host device is operating.
Parameters
eComponent Component for which version number is needed, one of:
E_JENIE_COMPONENT_JENIE (Jenie)
E_JENIE_COMPONENT_NETWORK (JenNet)
E_JENIE_COMPONENT_MAC (IEEE 802.15.4)
E_JENIE_COMPONENT_CHIP (JN513x chip)
Returns
Version number of component, as described below:
E_JENIE_COMPONENT_CHIP 31-28 Revision number: 0x0 for R0, 0x1 for R1, etc
u16Jenie_GetRoutingTableSize
uint16 u16Jenie_GetRoutingTableSize(void);
Description
This function obtains the number of valid entries in the local node’s Routing table.
Since the table is likely to become fragmented, the value returned is the number of
valid entries in the table and not the size of the table.
This function is only applicable to routing nodes (Routers and Co-ordinator).
Parameters
None
Returns
Number of valid entries in the local Routing table
teJenieStatusCode eJenie_GetRoutingTableEntry(
uint16 u16EntryNum,
tsJenie_RoutingEntry *psRoutingEntry);
Description
This function is used to obtain the specified entry of the local node’s Routing table.
If the entry exists, the function returns E_JENIE_SUCCESS and populates the
structure of type tsJenie_RoutingEntry pointed to by psRoutingEntry - for details of
this structure, see Appendix C.
If the entry does not exist, the function returns E_JENIE_ERR_INVLD_PARAM
(referring to the u16EntryNum parameter) but fills in the u16TotalEntries field of
the structure pointed to by psRoutingEntry.
Parameters
u16EntryNum Index of the required Routing table entry (this value is a
'logical index' and not the physical location of the entry in the
table).
*psRoutingEntry Pointer to the data structure of type tsJenie_RoutingEntry to
be filled in by Jenie - see Appendix C.
Returns
One of:
E_JENIE_SUCCESS
E_JENIE_ERR_INVLD_PARAM
For explanations, refer to Appendix B.
u8Jenie_GetNeighbourTableSize
uint8 u8Jenie_GetNeighbourTableSize(void);
Description
This function is used to obtain the size (number of entries) of the local node's
Neighbour table. The result includes the node's parent as well as its children.
This function is only applicable to routing nodes (Routers and Co-ordinator).
Parameters
None
Returns
Number of entries in the Neighbour table
teJenieStatusCode eJenie_GetNeighbourTableEntry(
uint8 u8EntryNum,
tsJenie_NeighbourEntry *psNeighbourEntry);
Description
This function is used to obtain the specified entry of the local node’s Neighbour table.
If the entry exists, the function returns E_JENIE_SUCCESS and populates the
structure of type tsJenie_NeighbourEntry pointed to by psNeighbourEntry - for details
of this structure, see Appendix C.
If the entry does not exist, the function returns E_JENIE_ERR_INVLD_PARAM
(referring to the u8EntryNum parameter) but fills in the u8TotalEntries field of the
structure pointed to by psNeighbourEntry.
This function is only applicable to routing nodes (Routers and Co-ordinator).
Note that entry zero of a Neighbour table is always for the node’s parent. Since the
Co-ordinator has no parent, entry zero should never be specified in this function for
the Co-ordinator.
Parameters
u8EntryNum Index of the required Neighbour table entry (this value is a
'logical index' and not the physical location of the entry in the
table).
*psNeighbourEntry Pointer to the data structure of type tsJenie_NeighbourEntry
to be filled in by Jenie - see Appendix C.
Returns
One of:
E_JENIE_SUCCESS
E_JENIE_ERR_INVLD_PARAM
For explanations, refer to Appendix B.
eJenie_ResetNeighbourStats
teJenieStatusCode eJenie_ResetNeighbourStats(
uint16 u16EntryNum);
Description
This function is used to reset the statistics components of the specified Neighbour
table entry on the local node. The components that are reset are:
u8LinkQuality - quality of link with relevant neighbouring node
u16PktsLost - number of unacknowledged packets sent to the node
u16PktsSent - number of acknowledged packets sent to the node
u16PktsRcvd - number of packets received from the node
If the entry is not found, the function returns E_JENIE_ERR_INVLD_PARAM.
Parameters
u16EntryNum Index of the relevant Neighbour table entry (this value is a
'logical index' and not the physical location of the entry in the
table).
Returns
One of:
E_JENIE_SUCCESS
E_JENIE_ERR_INVLD_PARAM
For explanations, refer to Appendix B.
The callback functions are listed below, along with their page references:
Function Page
vJenie_CbConfigureNetwork 47
vJenie_CbInit 48
vJenie_CbMain 49
vJenie_CbStackMgmtEvent 50
vJenie_CbStackDataEvent 51
vJenie_CbHwEvent 52
vJenie_CbConfigureNetwork
void vJenie_CbConfigureNetwork(void);
Description
This function is the first callback of an application and is called before the stack
initialises itself, providing the application with the opportunity to initialise/override
default stack parameters - for full details of these parameters, refer to Appendix A.
The function is only called during a cold start.
Parameters
None
Returns
None
Description
This function is called after the stack has initialised itself. It provides the application
with the opportunity to perform any additional hardware or software initialisation that
may be required.
This callback function should normally include a call to the function eJenie_Start().
Parameters
bWarmStart Specifies whether the device has undergone a cold or warm
start:
TRUE - warm start
FALSE - cold start
Returns
None
vJenie_CbMain
void vJenie_CbMain(void);
Description
This function is the main application task. It is called many times per second by the
stack and provides the opportunity for the application to perform any processing that
is required. This function should be non-blocking.
Parameters
None
Returns
None
void vJenie_CbStackMgmtEvent(
teJenieEventType eEventType,
void *pvEventPrim);
Description
This function is called by the stack to inform the application that one of a number of
stack management events has occurred. For example, the node may have received
a service request response from a remote node.
For further details of the stack management events, refer to Appendix D.1.
Parameters
eEventType The type of stack management event received, one of:
E_JENIE_REG_SVC_RSP
E_JENIE_SVC_REQ_RSP
E_JENIE_POLL_CMPLT
E_JENIE_PACKET_SENT
E_JENIE_PACKET_FAILED
E_JENIE_NETWORK_UP
E_JENIE_STACK_RESET
E_JENIE_CHILD_JOINED
E_JENIE_CHILD_LEAVE
E_JENIE_CHILD_REJECTED
*pvEventPrim Pointer to event primitive (if relevant, or NULL if not)
Returns
None
vJenie_CbStackDataEvent
void vJenie_CbStackDataEvent(
teJenieEventType eEventType,
void *pvEventPrim);
Description
This function is called by the stack to inform the application that one of a number of
stack data events has occurred. For example, the node may have received a
message from a remote node or a response to one of its own messages.
For further details of the data events, refer to Appendix D.2.
Parameters
eEventType The type of data event received, one of:
E_JENIE_DATA
E_JENIE_DATA_TO_SERVICE
E_JENIE_DATA_ACK
E_JENIE_DATA_TO_SERVICE_ACK
*pvEventPrim Pointer to event primitive (if relevant, or NULL if not)
Returns
None
Description
This function is called by the stack to inform the application that a hardware event
has occurred - that is, an event has been generated by an on-chip peripheral of the
JN5139/JN5148 wireless microcontroller.
Parameters
u32DeviceId Indicates the on-chip peripheral that generated the event - see
Appendix E.
u32ItemBitmap Indicates the source within the peripheral that caused the
event - see Appendix E.
Bits 15-8 of this bitmap parameter are also used to deliver a
received data byte to the application when a UART ‘received
data’ or ‘timeout’ interrupt occurs.
Returns
None
u32JPI_Init
uint32 u32JPI_Init(void);
Description
This function initialises the Jenie Peripherals Interface (JPI). The function should be
called after every reset or wake-up, and before any other JPI functions are called.
Parameters
None
Returns
0 if initialisation failed, otherwise a 32-bit version number (most significant 16 bits are
main revision, least significant 16 bits are minor revision)
uint8 u8JPI_PowerStatus(void);
Description
This function obtains various settings for the JN5139/JN5148 device (see below).
Parameters
None
Returns
Returns the status information in bits 0-3 of the 8-bit return value:
4-7 Unused
vJPI_SwReset
Description
This function generates an internal reset, which completely re-starts the system.
Parameters
None
Returns
None
Description
This function drives the ResetN line low for the specified time.
Note that one or more external devices may be connected to the ResetN line.
Therefore, using this function to drive this line low may affect these external devices.
For more information on the ResetN line and external devices, consult the datasheet
for your wireless microcontroller.
Parameters
u8Period Duration for which line will be driven low, in milliseconds
Returns
None
vJPI_HighPowerModuleEnable
Description
This function allows the transmitter and receiver sections of a Jennic high-power
module to be enabled or disabled. The transmitter and receiver sections must both
be enabled or disabled at the same time (enabling only one of them is not supported).
The function must be called before using the radio transceiver on a high-power
module.
The function sets the CCA (Clear Channel Assessment) threshold to suit the gain of
the attached Jennic high-power module.
Note that this function cannot be used with a high-power module from a manufacturer
other than Jennic.
Parameters
bRFTXEn Enable/disable setting for high-power module transmitter
(must be same setting as for bRFRXEn):
TRUE - enable transmitter
FALSE - disable transmitter
bRFRXEn Enable/disable setting for high-power module receiver
(must be same setting as for bRFTXEn):
TRUE - enable receiver
FALSE - disable receiver
Returns
None
void vJPI_SysCtrlRegisterCallback(
PR_HWINT_APPCALLBACK prSysCtrlCallback);
Description
This function registers an application callback that will be called when the System
Controller interrupt is triggered.
A System Controller interrupt can be caused by wake timer, comparator and DIO
events. Note that the System Controller interrupt handler will clear the interrupt
before invoking the callback function to deal with the interrupt. Also note that when a
DIO or comparator event wakes the device from sleep with memory held, the
registered callback function will be called before any other Jenie callback function.
The registered callback function is only preserved during sleep with memory held. If
RAM is powered off during sleep and interrupts are required, the callback function
must be re-registered before calling u32JPI_Init() on waking.
Interrupt handling is described in Appendix E.
Parameters
prSysCtrlCallback Pointer to function to be called when a System Controller
interrupt occurs
Returns
None
The functions are listed below, along with their page references:
Function Page
vJPI_AnalogueConfigure 62
vJPI_AnalogueEnable 63
vJPI_AnalogueDisable 64
vJPI_APRegisterCallback 65
bJPI_APRegulatorEnabled 66
vJPI_AnalogueStartSample 67
u16JPI_AnalogueAdcRead 68
bJPI_AdcPoll 69
vJPI_AnalogueDacOutput 70
bJPI_DacPoll 71
vJPI_ComparatorEnable 72
vJPI_ComparatorDisable 73
bJPI_ComparatorStatus 74
vJPI_ComparatorIntEnable 75
bJPI_ComparatorWakeStatus 76
Description
This function configures common parameters for all on-chip analogue resources.
The analogue peripheral regulator can be enabled - this dedicated power source
minimises digital noise and is sourced from the analogue supply pin VDD1.
Interrupts can be enabled that are generated after each ADC conversion (Analogue
Peripherals interrupts are handled by a callback function registered using
vJPII_APRegisterCallback())
The clock frequency (derived from the chip’s 16-MHz clock) is specified.
The ‘sampling interval’ is specified as a number of clock periods.
The source of the reference voltage, Vref, is specified.
For the ADC, the input signal is integrated over 3 x Sampling Interval. For the ADC
and DACs, the total conversion period (for a single value) is given by
(3 x sampling interval) + (14 x clock period)
Parameters
bAPRegulator Enable/disable analogue peripheral regulator:
E_JPI_AP_REGULATOR_ENABLE
E_JPI_AP_REGULATOR_DISABLE
bIntEnable Enable/disable interrupt when conversion/capture completes:
E_JPI_AP_INT_ENABLE
E_JPI_AP_INT_DISABLE
u8SampleSelect Select sampling interval in terms of divided clock periods:
E_JPI_AP_SAMPLE_2 (2 clock periods)
E_JPI_AP_SAMPLE_4 (4 clock periods)
E_JPI_AP_SAMPLE_6 (6 clock periods)
E_JPI_AP_SAMPLE_8 (8 clock periods)
u8ClockDivRatio Clock divide ratio:
E_JPI_AP_CLOCKDIV_2MHZ (achieves 2 MHz)
E_JPI_AP_CLOCKDIV_1MHZ (achieves 1 MHz)
E_JPI_AP_CLOCKDIV_500KHZ (achieves 500 kHz)
E_JPI_AP_CLOCKDIV_250KHZ (achieves 250 kHz)
(500 kHz is recommended for ADC and 250 kHz for DACs)
bRefSelect Select source of reference voltage, Vref:
E_JPI_AP_EXTREF (external from VREF pin)
E_JPI_AP_INTREF (internal)
Returns
None
vJPI_AnalogueEnable
void vJPI_AnalogueEnable(
teJPI_AnalogueChannel eChan,
bool_t bInputRange,
bool_t bContinuous,
uint8 u8Source,
bool_t bOutputHold,
uint16 u16InitValue);
Description
This function configures and enables the specified analogue device (ADC or DAC).
A parameter is relevant to both ADC and DACs unless otherwise stated. Note that:
The source of Vref is defined using vJPI_AnalogueConfigure().
For the ADC, the internal voltage monitor measures the voltage on the pin VDD1.
The ADC can be configured to operate in single-shot mode or continuous mode.
Only one of the DACs can be enabled at any one time - if both DACs are to be used
concurrently, they can be multiplexed.
For a DAC, the first value to be converted is specified through this function - the
conversion will be started immediately after the function call. Subsequent values must
be specified through vJPI_AnalogueDacOutput().
Parameters
eChan Analogue device to configure and enable:
E_JPI_ANALOGUE_DAC_0 (DAC1)
E_JPI_ANALOGUE_DAC_1 (DAC2)
E_JPI_ANALOGUE_ADC (ADC)
bInputRange Set input voltage range to either 0-Vref or 0-2Vref:
E_JPI_AP_INPUT_RANGE_2 (0-2Vref)
E_JPI_AP_INPUT_RANGE_1 (0-Vref)
bContinuous Enable/disable continuous conversion for ADC:
E_JPI_ADC_CONTINUOUS (continuous mode)
E_JPI_ADC_SINGLE_SHOT (single shot mode)
u8Source Source for ADC conversions:
E_JPI_ADC_SRC_ADC_1 (ADC1 input pin)
E_JPI_ADC_SRC_ADC_2 (ADC2 input pin)
E_JPI_ADC_SRC_ADC_3 (ADC3 input pin)
E_JPI_ADC_SRC_ADC_4 (ADC4 input pin)
E_JPI_ADC_SRC_TEMP (on-chip temperature sensor)
E_JPI_ADC_SRC_VOLT (internal voltage monitor)
bOutputHold Unused - set to 0 (FALSE)
u16InitValue Initial digital value for DAC to convert (only lower 11/12 bits used)
Returns
None
Description
This function disables the specified analogue device (ADC or DAC).
Note that only one of the two DACs can be used at any one time. If both DACs are
to be used, you must alternate between them - use vJPI_AnalogueEnable() to
enable a DAC and then vJPI_AnalogueDisable() to disable the DAC before
enabling the next one using vJPI_AnalogueEnable(), and so on.
Parameters
eChan Analogue device to disable:
E_JPI_ANALOGUE_DAC_0 (DAC1)
E_JPI_ANALOGUE_DAC_1 (DAC2)
E_JPI_ANALOGUE_ADC (ADC)
Returns
None
vJPI_APRegisterCallback
void vJPI_APRegisterCallback(
PR_HWINT_APPCALLBACK prApCallback);
Description
This function registers an application callback that will be called when the Analogue
Peripherals interrupt is triggered.
The registered callback function is only preserved during sleep with memory held. If
RAM is powered off during sleep and interrupts are required, the callback function
must be re-registered before calling u32JPI_Init() on waking.
Interrupt handling is described in Appendix E.
Parameters
prApCallback Pointer to function to be called when the Analogue
Peripherals interrupt occurs
Returns
None
bool_t bJPI_APRegulatorEnabled(void);
Description
This function enquires whether the analogue peripheral regulator has powered up.
The function should be called after enabling the regulator through
vJPI_AnalogueConfigure(). When the regulator is enabled, it will take a little time
to start up - this period is 31.25 µs for the JN5139/JN5148 device.
Parameters
None
Returns
TRUE if powered up, FALSE otherwise
vJPI_AnalogueStartSample
void vJPI_AnalogueStartSample(void);
Description
This function starts the ADC sampling in single-shot or continuous mode, depending
on which mode has been configured using vJPI_AnalogueEnable():
Single-shot mode: ADC will perform a single conversion and then stop (only valid if
DACs are not enabled).
Continuous mode: ADC will perform conversions repeatedly until stopped using the
function vJPI_AnalogueDisable().
If analogue peripheral interrupts have been enabled in vJPI_AnalogueConfigure(),
an interrupt will be triggered when a result becomes available. Alternatively, if
interrupts are disabled, you can use bJPI_AdcPoll() to check for a result. Once a
conversion result becomes available, it should be read with
u16JPI_AnalogueAdcRead().
Parameters
None
Returns
None
uint16 u16JPI_AnalogueAdcRead(void);
Description
This function reads the most recent ADC conversion result. The value is 12 bits wide.
If analogue peripheral interrupts have been enabled in vJPI_AnalogueConfigure(),
you must call this read function from a callback function invoked when an interrupt
has been generated to indicate that an ADC result is ready (this user-defined
callback function is registered using the function vJPI_APRegisterCallback()).
Alternatively, if interrupts have not been enabled, before calling the read function,
you must first check whether a result is ready using the function bJPI_AdcPoll().
Parameters
None
Returns
Most recent ADC conversion result (the result is contained in the least significant
12 bits of the 16-bit returned value)
bJPI_AdcPoll
bool_t bJPI_AdcPoll(void);
Description
This function can be used when the ADC is operating in single-shot mode or
continuous mode, to check whether the ADC is still busy performing a conversion:
In single-shot mode, the poll result indicates whether the sample has been taken and is
ready to be read.
In continuous mode, the poll result indicates whether a new sample is ready to be read.
You may wish to call this function before attempting to read the conversion result
using u16JPI_AnalogueAdcRead(), particularly if you are not using the analogue
peripheral interrupts.
Parameters
None
Returns
TRUE if ADC is busy, FALSE if conversion complete
Description
This function allows the next value for conversion by the specified DAC to be set.
This value will be used for all subsequent conversions until the function is called
again with a new value.Although a 16-bit value must be specified in this function:
For the JN5148 device, only the 12 least significant bits will be used, since the chip
features 12-bit DACs
For the JN5139 device, only the 11 least significant bits will be used, since the chip
features 11-bit DACs
Parameters
u8Dac Identity of DAC:
E_JPI_ANALOGUE_DAC_0 (DAC1)
E_JPI_ANALOGUE_DAC_1 (DAC2)
u16Value Value to convert to analogue - only the 11 or 12 least
significant bits will be used (see above)
Returns
None
bJPI_DacPoll
Description
This function checks whether the enabled DAC is busy performing a conversion.
A short delay (approximately 2 µs) after polling and checking the DAC is included to
prevent lock-ups when further calls are made to the DAC.
Parameters
None
Returns
TRUE if DAC is busy, FALSE if conversion complete
void vJPI_ComparatorEnable(
teJPI_Comparator eComparator,
uint8 u8Hysteresis,
uint8 u8SignalSelect);
Description
This function configures and enables the specified comparator. The reference signal
and hysteresis setting must be specified.
The hysteresis voltage selected should be greater than:
the noise level in the input signal on the comparator '+' pin (COMP1P or COMP2P), if
comparing the signal on this pin with the internal reference voltage or DAC output
the differential noise between the signals on the comparator ‘+’ and ‘-’ pins, if
comparing the signals on these two pins
Note that the same hysteresis setting is used for both comparators, so if this function
is called several times for different comparators, only the hysteresis value from the
final call will be used.
Once enabled using this function, the comparator can be disabled using the function
vJPI_ComparatorDisable().
Parameters
eComparator Identity of comparator:
E_JPI_COMPARATOR_1
E_JPI_COMPARATOR_2
u8Hysteresis Hysteresis setting (controllable from 0 to ±20mV):
JN5139:
E_JPI_COMP_HYSTERESIS_0MV (0 mV)
E_JPI_COMP_HYSTERESIS_5MV (±5 mV)
E_JPI_COMP_HYSTERESIS_10MV (±10 mV)
E_JPI_COMP_HYSTERESIS_20MV (±20 mV)
JN5148:
E_JPI_COMP_HYSTERESIS_0MV (0 mV)
E_JPI_COMP_HYSTERESIS_10MV (±5 mV)
E_JPI_COMP_HYSTERESIS_20MV (±10 mV)
E_JPI_COMP_HYSTERESIS_40MV (±20 mV)
u8SignalSelect Reference signal to compare with input signal on comparator
'+' pin:
E_JPI_COMP_SEL_EXT (Comparator '-' pin)
E_JPI_COMP_SEL_DAC (Related DAC output)
E_JPI_COMP_SEL_BANDGAP (Fixed at Vref)
Returns
None
vJPI_ComparatorDisable
void vJPI_ComparatorDisable(
teJPI_Comparator eComparator);
Description
This function disables the specified comparator.
Parameters
eComparator Identity of comparator:
E_JPI_COMPARATOR_1
E_JPI_COMPARATOR_2
Returns
None
bool_t bJPI_ComparatorStatus(
teJPI_Comparator eComparator);
Description
This function returns the status of the specified comparator.
Parameters
eComparator Identity of comparator:
E_JPI_COMPARATOR_1
E_JPI_COMPARATOR_2
Returns
FALSE if the input signal is lower than reference signal
TRUE if the input signal is higher than reference signal
vJPI_ComparatorIntEnable
void vJPI_ComparatorIntEnable(
teJPI_Comparator eComparator,
bool_t bIntEnable,
bool_t bRisingNotFalling);
Description
This function enables the comparator interrupt for the specified comparator. The
interrupt can be used to wake the device from sleep, and as a normal interrupt.
If enabled, an interrupt is generated on one of the following conditions (which must
be configured):
The input signal rises above the reference signal (plus hysteresis level, if non-zero)
The input signal falls below the reference signal (minus hysteresis level, if non-zero)
Comparator interrupts are handled by the System Controller callback function,
registered using the function vJPI_SysCtrlRegisterCallback().
Parameters
eComparator Identity of comparator:
E_JPI_COMPARATOR_1
E_JPI_COMPARATOR_2
bIntEnable TRUE to enable interrupt
FALSE to disable interrupt
bRisingNotFalling TRUE - interrupt when input signal rises above reference
FALSE - interrupt when input signal falls below reference
Returns
None
uint8 u8JPI_ComparatorWakeStatus(
teJPI_Comparator eComparator);
Description
This function returns the wake-up interrupt status of the specified comparator. The
value is cleared after reading.
Parameters
eComparator Identity of comparator:
E_JPI_COMPARATOR_1
E_JPI_COMPARATOR_2
Returns
0 if wake-up interrupt has not occurred
Non-zero value if wake-up interrupt has occurred
The functions are listed below, along with their page references:
Function Page
vJPI_DioSetDirection 78
vJPI_DioSetOutput 79
vJPI_DioSetPullup 80
u32JPI_DioReadInput 81
vJPI_DioWake 82
u32JPI_DioWakeStatus 84
Description
This function sets the direction for the DIO pins individually as either input or output.
This is done through two bitmaps for inputs and outputs, u32Inputs and u32Outputs
respectively. In these values, each of bits 0 to 20 represents a DIO pin, where bit 0
represents DIO0 and bit 20 represents DIO20 (bits 21-31 are ignored).
Note that:
Not all DIO pins must be defined (in other words, u32Inputs logical ANDed with
u32Outputs does not need to produce all zeros for bits 0-20).
Any DIO pins that are not defined by a call to this function (the relevant bits being
cleared in both bitmaps) will be left in their previous states.
If a bit is set in both u32Inputs and u32Outputs, it will default to becoming an input.
If a DIO is assigned to another peripheral which is enabled, this function call will not
immediately affect the relevant pin. However, the DIO setting specified by this function
will take effect if/when the relevant peripheral is subsequently disabled.
This function does not change the DIO pull-up status - this must be done separately
using vJPI_DioSetPullup().
Parameters
u32Inputs Bitmap of inputs - a bit set means that the corresponding DIO
pin will become an input
u32Outputs Bitmap of outputs - a bit set means that the corresponding DIO
pin will become an output
Returns
None
vJPI_DioSetOutput
Description
This function sets individual DIO outputs on or off. This is done through two bitmaps
for on-pins and off-pins, u32On and u32Off respectively. In these values, each of bits
0 to 20 represents a DIO pin, where bit 0 represents DIO0 and bit 20 represents
DIO20 (bits 21-31 are ignored). Setting a bit in one of these bitmaps configures the
corresponding DIO output as on or off, depending on the bitmap.
Note that:
Not all DIO pins must be defined (in other words, u32On logical ANDed with u32Off
does not need to produce all zeros for bits 0-20).
Any DIO pins that are not defined by a call to this function (the relevant bits being
cleared in both bitmaps) will be left in their previous states.
If a bit is set in both u32On and u32Off, the DIO pin will default to off.
This call has no effect on DIO pins that are not defined as outputs (see
vJPI_DioSetDirection()) until a time when they are re-configured as outputs.
If a DIO is assigned to another peripheral which is enabled, this function call will not
affect the relevant DIO, until a time when the relevant peripheral is disabled.
Parameters
u32On Bitmap of on-pins - a bit set means that the corresponding DIO
pin will be set to on
u32Off Bitmap of off-pins - a bit set means that the corresponding DIO
pin will be set to off
Returns
None
Description
This function sets the pull-ups on individual DIO pins as on or off. A pull-up can be
set irrespective of whether the pin is an input or output. This is done through two
bitmaps for ‘pull-ups on’ and ‘pull-ups off’, u32On and u32Off respectively. In these
values, each of bits 0 to 20 represents a DIO pin, where bit 0 represents DIO0 and
bit 20 represents DIO20 (bits 21-31 are ignored).
Note that:
By default, the pull-ups are enabled (on) at power-up.
Not all DIO pull-ups must be set (in other words, u32On logical ORed with u32Off does
not need to produce all zeros for bits 0-20).
Any DIO pull-ups that are not set by a call to this function (the relevant bits being
cleared in both bitmaps) will be left in their previous states.
If a bit is set in both u32On and u32Off, the corresponding DIO pull-up will default to off.
If a DIO is assigned to another peripheral which is enabled, this function call will not
immediately affect the relevant pin. However, the DIO pull-up setting specified by this
function will take effect if/when the relevant peripheral is subsequently disabled.
Parameters
u32On Bitmap of ‘pull-ups on’ - a bit set means that the corresponding
pull-up will be turned on
u32Off Bitmap of ‘pull-ups off’ - a bit set means that the corresponding
pull-up will be turned off
Returns
None
u32JPI_DioReadInput
uint32 u32JPI_DioReadInput(void);
Description
This function returns the value of each of the DIO input pins (irrespective of whether
the pins are used as inputs, as outputs or by other enabled peripherals).
Parameters
None
Returns
Bitmap:
Each of bits 0-20 corresponds to a DIO pin, where bit 0 represents DIO0 and
bit 20 represents DIO20. The bit is set to 1 if the input is high or to 0 if the input
is low. Bits 21-31 are always 0.
Description
This function configures and enables/disables wake signals (interrupts) on the DIO
input pins.
The function enables/disables wake interrupts on the DIO pins - that is, whether
activity on a DIO input will be able to wake the device from sleep or doze mode. This
is done through two bitmaps for ‘wake enabled’ and ‘wake disabled’, u32Enable and
u32Disable respectively. In these values, each of bits 0 to 20 represents a DIO pin,
where bit 0 represents DIO0 and bit 20 represents DIO20 (bits 21-31 are ignored).
Setting a bit in one of these bitmaps enables/disables wake interrupts on the
corresponding DIO, depending on the bitmap. Note that:
Not all DIO wake interrupts must be defined (in other words, u32Enable logical ORed
with u32Disable does not need to produce all zeros for bits 0-20).
Any DIO wake interrupts that are not defined by a call to this function (the relevant bits
being cleared in both bitmaps) will be left in their previous states.
If a bit is set in both u32Enable and u32Disable, the corresponding DIO wake interrupt
will default to disabled.
This call has no effect on DIO pins that are not defined as inputs (see
vJPI_DioSetDirection()).
DIOs assigned to enabled JN5139/JN5148 peripherals are affected by this function.
The DIO wake interrupt settings made with this function are retained during sleep.
The function also controls whether individual DIOs will generate wake interrupts on
a rising or falling edge of the DIO input. This is done through two bitmaps for ‘rising
edge’ and ‘falling edge’, u32Rising and u32Falling respectively. In these values, each
of bits 0 to 20 represents a DIO pin, where bit 0 represents DIO0 and bit 20
represents DIO20 (bits 21-31 are ignored). Setting a bit in one of these bitmaps
configures wake interrupts on the corresponding DIO to occur on a rising or falling
edge, depending on the bitmap (by default, all DIO wake interrupts are ‘rising edge’).
Note that:
Not all DIO wake interrupts must be configured (in other words, u32Rising logical ORed
with u32Falling does not need to produce all zeros for bits 0-20).
Any DIO wake interrupts that are not configured by a call to this function (the relevant
bits being cleared in both bitmaps) will be left in their previous states.
If a bit is set in both u32Rising and u32Falling, the corresponding DIO wake interrupt
will default to ‘rising edge’.
Note that DIO wake interrupts are handled by the System Controller callback
function, registered using the function vJPI_SysCtrlRegisterCallback().
Parameters
u32Enable Bitmap for wake enable - a bit set means that the wake signal
on the corresponding DIO pin will be enabled
u32Disable Bitmap for wake disable - a bit set means that the wake signal
on the corresponding DIO pin will be disabled
u32Rising Bitmap for rising edge - a bit set means that the wake signal
on the corresponding DIO pin will be triggered on a rising edge
u32Falling Bitmap for falling edge - a bit set means that the wake signal
on the corresponding DIO pin will be triggered on a falling
edge
Returns
None
uint32 u32JPI_DioWakeStatus(void);
Description
This function returns the interrupt status of each of the DIO input pins.
The returned value is a bitmap in which a bit is set if a wake interrupt has occurred
on the corresponding DIO input pin (see below). Bit values are not valid for DIO pins
that are assigned as outputs or assigned to another enabled peripheral. After reading
the interrupt status, the value is cleared.
Parameters
None
Returns
Bitmask:
Each of bits 0-20 corresponds to a DIO pin, where bit 0 represents DIO0 and
bit 20 represents DIO20. The bit is set if an interrupt associated with the pin
has triggered. Bits 21-31 are always 0.
3.4 UARTs
This section details the functions for controlling the UARTs (Universal Asynchronous
Receiver Transmitters). The JN5139/JN5148 device has two 16550-compatible
UARTs, denoted UART0 and UART1, which can be independently enabled. UART0
is also used for the debugger.
Note the following:
UART Pins
Each UART uses four pins, shared with the DIOs, for the following signals: clear-to-
send (CTS) input, request-to-send (RTS) output, transmit data output, receive data
input.
On the JN5148 device, the pins normally used by a UART can alternatively be used
to connect a JTAG emulator for debugging.
The UART functions are listed below, along with their page references:
Function Page
vJPI_UartEnable 87
vJPI_UartDisable 88
vJPI_UartSetClockDivisor 89
vJPI_UartSetBaudDivisor 90
vJPI_UartSetControl 91
vJPI_UartSetInterrupt 92
vJPI_UartSetRTSCTS 93
vJPI_UartReset 94
u8JPI_UartReadLineStatus 95
u8JPI_UartReadModemStatus 96
u8JPI_UartReadInterruptStatus 97
vJPI_UartWriteData 98
u8JPI_UartReadData 99
vJPI_Uart0RegisterCallback 100
vJPI_Uart1RegisterCallback 101
vJPI_UartEnable
Description
This function enables the specified UART. It must be the first UART function called.
Be sure to enable the UART using this function before writing to the UART using the
function vJPI_UartWriteData(), otherwise an exception will result.
If you wish to implement RTS/CTS flow control, you will need to call
vJPI_UartSetRTSCTS() before calling vJPI_UartEnable() in order to take control of
the DIOs used for RTS and CTS. The UARTs use certain DIO lines, as follows:
If a UART uses only the RxD and TxD lines, it is said to operate in 2-wire mode. If, in
addition, it uses the RTS and CTS lines, it is said to operate in 4-wire mode.
Parameters
u8Uart Identity of UART:
E_JPI_UART_0
E_JPI_UART_1
Returns
None
Description
This function disables the specified UART.
Be sure to re-enable the UART using vJPI_UartEnable() before attempting to write
to the UART using the function vJPI_UartWriteData(), otherwise an exception will
result.
Parameters
u8Uart Identity of UART:
E_JPI_UART_0
E_JPI_UART_1
Returns
None
vJPI_UartSetClockDivisor
Description
This function sets the baud rate for the specified UART to one of a number of
standard rates.
The possible baud rates are:
4800 bps
9600 bps
19200 bps
38400 bps
76800 bps
115200 bps
To set the baud rate to other values, use the function vJPI_UartSetBaudDivisor().
Parameters
u8Uart Identity of UART:
E_JPI_UART_0
E_JPI_UART_1
u8BaudRate Desired baud rate:
E_JPI_UART_RATE_4800 (4800 bps)
E_JPI_UART_RATE_9600 (9600 bps)
E_JPI_UART_RATE_19200 (19200 bps)
E_JPI_UART_RATE_38400 (38400 bps)
E_JPI_UART_RATE_76800 (76800 bps)
E_JPI_UART_RATE_115200 (115200 bps)
Returns
None
Description
This function sets an integer divisor to derive the baud rate from a 1-MHz frequency
for the specified UART. The function allows baud rates to be set that are not available
through the function vJPI_UartSetClockDivisor().
The baud rate produced is defined by:
baud rate = 1000000/u16Divisor
For example:
1 1000000
2 500000
9 115200 (approx)
26 38400 (approx)
Parameters
u8Uart Identity of UART:
E_JPI_UART_0
E_JPI_UART_1
u16Divisor Integer divisor (for 1-MHz clock)
Returns
None
vJPI_UartSetControl
Description
This function sets various control bits for the specified UART.
Note that RTS cannot be controlled automatically, but only enabled or disabled under
software control.
Parameters
u8Uart Identity of UART:
E_JPI_UART_0
E_JPI_UART_1
bEvenParity Parity (even or odd):
E_JPI_UART_EVEN_PARITY
E_JPI_UART_ODD_PARITY
bEnableParity Enable/disable parity check:
E_JPI_UART_PARITY_ENABLE
E_JPI_UART_PARITY_DISABLE
u8WordLength Word length:
E_JPI_UART_WORD_LEN_5 (Word is 5 bits)
E_JPI_UART_WORD_LEN_6 (Word is 6 bits)
E_JPI_UART_WORD_LEN_7 (Word is 7 bits)
E_JPI_UART_WORD_LEN_8 (Word is 8 bits)
bOneStopBit Number of stop bits - TRUE for 1 stop bit, FALSE for 1.5 or 2
stop bits, depending on word length - enumerated as:
E_JPI_UART_1_STOP_BIT (TRUE)
E_JPI_UART_2_STOP_BITS (FALSE)
bRtsValue Enable or disable RTS:
E_JPI_UART_RTS_HIGH (TRUE) - Disable RTS
E_JPI_UART_RTS_LOW (FALSE) - Enable RTS
Returns
None
Description
This function enables or disables the interrupts generated by the specified UART and
sets the receive FIFO level - that is, the number of words received by the FIFO in
order to trigger a receive data interrupt.
UART interrupts are handled by callback functions registered using the following
functions:
vJPI_Uart0RegisterCallback() for UART0
vJPI_Uart1RegisterCallback() for UART1
Parameters
u8Uart Identity of UART:
E_JPI_UART_0
E_JPI_UART_1
bEnableModemStatus Enable/disable modem status interrupt (e.g. CTS change
detected) - TRUE for enable, FALSE for disable
bEnableRxLineStatus Enable/disable receive line status interrupt (e.g. framing
error, parity error) - TRUE for enable, FALSE for disable
bEnableTxFifoEmpty Enable/disable interrupt when transmit FIFO empty -
TRUE for enable, FALSE for disable
bEnableRxData Enable/disable interrupt when receive data seen - TRUE
for enable, FALSE for disable
u8FifoLevel Number of received words required to trigger a receive
data interrupt:
E_JPI_UART_FIFO_LEVEL_1 (1 word)
E_JPI_UART_FIFO_LEVEL_4 (4 words)
E_JPI_UART_FIFO_LEVEL_8 (8 words)
E_JPI_UART_FIFO_LEVEL_14 (14 words)
Returns
None
vJPI_UartSetRTSCTS
Description
This function instructs the specified UART to take or release control of the DIO lines
used for RTS/CTS flow control.
UART0: DIO4 for CTS
DIO5 for RTS
UART1: DIO17 for CTS
DIO18 for RTS
The function must be called before vJPI_UartEnable() is called.
If a UART uses these two additional DIO lines, it is said to operate in 4-wire mode,
otherwise it is said to operate in 2-wire mode.
Parameters
u8Uart Identity of UART:
E_JPI_UART_0
E_JPI_UART_1
bRTSCTSEn Take or release control of DIOs for RTS/CTS:
TRUE to take control
FALSE to release control
Returns
None
Description
This function resets the Transmit and Receive FIFOs. The character currently being
transferred is not affected. The Transmit and Receive FIFOs can be reset individually
or together.
The function also sets the FIFO trigger level to single-byte trigger. The FIFO interrupt
trigger level can be set via vJPI_UartSetInterrupt().
Parameters
u8Uart Identity of UART:
E_JPI_UART_0
E_JPI_UART_1
bTxReset Transmit FIFO reset:
TRUE to reset
FALSE not to reset
bRxReset Receive FIFO reset
TRUE to reset
FALSE not to reset
Returns
None
u8JPI_UartReadLineStatus
Description
This function returns line status information for the specified UART as a bitmap.
Note that the following bits are cleared after reading:
E_JPI_UART_LS_ERROR
E_JPI_UART_LS_BI
E_JPI_UART_LS_FE
E_JPI_UART_LS_PE
E_JPI_UART_LS_OE
Parameters
u8Uart Identity of UART:
E_JPI_UART_0
E_JPI_UART_1
Returns
Bitmap:
Bit Description
Description
This function obtains modem status information from the specified UART as a bitmap
which includes the CTS and ‘CTS has changed’ status (which can be extracted as
described below).
Parameters
u8Uart Identity of UART:
E_JPI_UART_0
E_JPI_UART_1
Returns
Bitmap in which:
CTS input status is bit 4 (‘1’ indicates CTS is high, ‘0’ indicates CTS is low).
‘CTS has changed’ status is bit 0 (‘1’ indicates that CTS input has changed). If the
return value logically ANDed with E_JPI_UART_MS_DCTS is non-zero, the CTS input
has changed.
u8JPI_UartReadInterruptStatus
Description
This function returns a pending interrupt for the specified UART as a bitmap.
Interrupts are returned one at a time, so there may need to be multiple calls to this
function. If interrupts are enabled, the interrupt handler processes this activity and
posts each interrupt to the queue or to a callback function.
Parameters
u8Uart Identity of UART:
E_JPI_UART_0
E_JPI_UART_1
Returns
Bitmap:
Description
This function writes a data byte to the Transmit FIFO of the specified UART for
transmission.
Before this function is called, the UART must be enabled using the function
vJPI_UartEnable(), otherwise an exception will result.
Parameters
u8Uart Identity of UART:
E_JPI_UART_0
E_JPI_UART_1
u8Data Byte to transmit
Returns
None
u8JPI_UartReadData
Description
This function returns a single byte read from the Receive FIFO of the specified
UART. If the FIFO is empty, the value is not valid.
Refer to the description of u8JPI_UartReadLineStatus() for details of how to
determine whether the FIFO is empty.
Parameters
u8Uart Identity of UART:
E_JPI_UART_0
E_JPI_UART_1
Returns
Received byte
void vJPI_Uart0RegisterCallback(
PR_HWINT_APPCALLBACK prUart0Callback);
Description
This function registers an application callback that will be called when the UART0
interrupt is triggered.
The registered callback function is only preserved during sleep with memory held. If
RAM is powered off during sleep and interrupts are required, the callback function
must be re-registered before calling u32JPI_Init() on waking.
Interrupt handling is described in Appendix E.
Parameters
prUart0Callback Pointer to function that is to be called when UART0 interrupt
occurs.
Returns
None
vJPI_Uart1RegisterCallback
void vJPI_Uart1RegisterCallback(
PR_HWINT_APPCALLBACK prUart1Callback);
Description
This function registers an application callback that will be called when the UART1
interrupt is triggered.
The registered callback function is only preserved during sleep with memory held. If
RAM is powered off during sleep and interrupts are required, the callback function
must be re-registered before calling u32JPI_Init() on waking.
Interrupt handling is described in Appendix E.
Parameters
prUart1Callback Pointer to function that is to be called when UART1 interrupt
occurs.
Returns
None
The timers normally use the internal 16-MHz clock source of the JN5139/JN5148
device.
Modes of Operation
The timers can be operated in the following modes: Timer, PWM, Delta-Sigma,
Capture. These modes are summarised in the table below, along with the functions
needed for each mode.
PWM As for Timer mode, except the Pulse Width Modu- vJPI_TimerEnable()
lated signal is output on a DIO (which depends on vJPI_TimerStart()
the specific timer used - see DIO Usage below).
DIO Usage
The timers use the JN5139/JN5148 device’s DIO pins as follows:
Timer 0 Timer 1 Timer 2
Function
DIO pin DIO pin DIO pin
8 11 * - Clock/gate input
9 12 - Capture input
The functions are listed below, along with their page references:
Function Page
vJPI_TimerEnable 104
vJPI_TimerDisable 106
vJPI_TimerStart 107
vJPI_TimerStop 109
vJPI_TimerStartCapture 110
u32JPI_TimerReadCapture 111
u8JPI_TimerFired 112
vJPI_Timer0RegisterCallback 113
vJPI_Timer1RegisterCallback 114
vJPI_Timer2RegisterCallback (JN5148 Only) 115
Description
This function configures and enables the specified timer, and must be the first timer
function called. The timer can be used in various modes, described in Table 1 on
page 102.
The parameters of this enable function cover the following features:
Source clock (eClockType): The clock for the timer is normally the internal 16-MHz
system clock, which can be optionally inverted.
Prescaling (u8Prescale): The timer’s source clock is divided down to produce a slower
clock for the timer, the divisor being 2Prescale. Therefore:
Timer clock frequency = Source clock frequency / 2Prescale
Interrupts (mIntMask): Interrupts can be generated in Timer mode on a low-to-high
transition (rising output) and/or on a high-to-low transition (end of the timer period).
Alternatively, timer interrupts can be disabled. If enabled, timer interrupts are handled
by callback functions registered using:
vJPI_Timer0RegisterCallback() for Timer 0
vJPI_Timer1RegisterCallback() for Timer 1
vJPI_Timer2RegisterCallback() for Timer 2 (JN5148 only)
DIOs (bTimerIOEn): Timer 0 uses DIO8-10, Timer 1 uses DIO11-13 and Timer2 uses
DIO11. Use of these pins must be explicitly enabled.
Output (bOutputEn): When operating in PWM mode or Delta-Sigma mode, the timer’s
signal is output on a DIO pin (DIO10 for Timer 0, DIO13 for Timer 1, DIO11 for Timer 2),
which must be enabled. If this option is enabled, the other DIOs associated with the
timer cannot be used for general-purpose input/output.
Parameters
eTimer Identity of timer:
E_JPI_TIMER_0
E_JPI_TIMER_1
E_JPI_TIMER_2 (JN5148 Only)
u8Prescale Prescale index, in range 0 to 16, used to divide down clock
(divisor is 2Prescale)
mIntMask Mask for interrupt generation on timer events:
0x00 to disable timer interrupts
E_JPI_TIMER_INT_PERIOD (interrupt at end of timed period)
E_JPI_TIMER_INT_RISE (interrupt on low-to-high transition)
Returns
None
Description
This function disables the specified timer. As well as stopping the timer from running,
the clock to the timer block is turned off in order to reduce power consumption. This
means that any subsequent attempt to access the timer will be unsuccessful until
vJPI_TimerEnable() is called to re-enable the block.
Parameters
eTimer Identity of timer:
E_JPI_TIMER_0
E_JPI_TIMER_1
E_JPI_TIMER_2 (JN5148 Only)
Returns
None
vJPI_TimerStart
Description
This function starts the specified timer in Timer/PWM mode or Delta-Sigma mode.
Timer mode: During one pulse cycle of this mode, the timer signal starts off low and
then goes high. The output goes low until u16HighPeriod clock periods have passed,
after which it goes high until u16LowPeriod clock periods since the timer was started. If
timer interrupts have been enabled using vJPI_TimerEnable(), an interrupt will be
triggered at the low-high transition and/or at the high-low transition.
This mode is available in ‘single-shot’ and ‘repeat’ versions:
Single-shot mode produces one pulse cycle and stops
Repeat mode produces a train of pulses until the timer is stopped
PWM (Pulse Width Modulation) mode is simply one of the above Timer modes with the
timer output enabled on the appropriate DIO (see below).
Delta-Sigma mode: This mode allows the timer to be used as a low-rate DAC with the
output on the appropriate DIO (see below). An output waveform is produced consisting
of a series of high and low clock cycles that are pseudo-randomly spaced in time. The
number of high clock cycles (u16HighPeriod) within the total period of the waveform
(comprising 65536 clock cycles) should be set to a value which is proportional to the
value to be converted. Placing a Resistor-Capacitor (RC) circuit on the output pin will
then produce an averaged analogue voltage.
This mode is available in ‘normal’ and ‘RTZ’ versions:
Normal Delta-Sigma mode operates as described above.
RTZ (Return-to-Zero) Delta-Sigma mode operates as normal Delta-Sigma mode
but a low clock cycle is inserted after every clock cycle (thus, there are 131072
clock cycles in the total period). Note that this does not affect the setting of
u16HighPeriod.
If the timer signal is to be output (as in the case of PWM and Delta-Sigma modes),
use DIO10 for Timer 0, DIO13 for Timer 1, DIO11 for Timer 2. These DIOs must be
enabled for output in vJPI_TimerEnable(). For Delta-Sigma modes, an RC circuit
must be inserted between the output pin and Ground
Note that the timer is started in Capture mode using a separate function,
vJPI_TimerStartCapture().
For more information on timer operation, refer to the Jenie API User Guide
(JN-UG-3042).
Parameters
eTimer Identity of timer:
E_JPI_TIMER_0
E_JPI_TIMER_1
E_JPI_TIMER_2 (JN5148 only)
Returns
None
vJPI_TimerStop
Description
This function stops the specified timer if it has been started in Timer/PWM mode or
Delta-Sigma mode using vJPI_TimerStart().
Parameters
eTimer Identity of timer:
E_JPI_TIMER_0
E_JPI_TIMER_1
E_JPI_TIMER_2 (JN5148 only)
Returns
None
Description
This function starts the specified timer in Capture mode.
An input signal must be provided on pin DIO9 for Timer 0 or DIO12 for Timer 1
(Capture mode is not available on Timer 2 of the JN5148 device). The incoming
signal is timed and the captured measurements are:
number of clock cycles to the last low-to-high transition of the input signal
number of clock cycles to the last high-to-low transition of the input signal
These values are placed in registers to be read later using the function
vJPI_TimerReadCapture(). They allow the input pulse width to be determined.
Parameters
eTimer Identity of timer:
E_JPI_TIMER_0
E_JPI_TIMER_1
Returns
None
u32JPI_TimerReadCapture
Description
This function stops the timer and provides the results from a 'capture' started using
vJPI_TimerStartCapture().
The values returned are offsets from when the capture was originally started, as
follows:
number of clock cycles to the last low-to-high transition of the input signal
number of clock cycles to the last high-to-low transition of the input signal
The width of the last pulse can be calculated from the difference of these results,
provided that the results were requested during a low period. However, since it is not
possible to be sure of this, the results obtained from this function may not always be
valid for calculating the pulse width.
Parameters
eTimer Identity of timer:
E_JPI_TIMER_0
E_JPI_TIMER_1
Returns
32-bit value in which:
The upper 16 bits (bits 31-16) represent the number of clock cycles up to the last
low-to-high transition.
The lower 16 bits (bits 15-0) represent the number of clock cycles up to the last
high-to-low transition.
Description
This function obtains the interrupt status of the specified timer. The function also
clears interrupt status after reading it.
Parameters
eTimer Identity of timer:
E_JPI_TIMER_0
E_JPI_TIMER_1
E_JPI_TIMER_2 (JN5148 only)
Returns
Bitmap:
Returned value logical ANDed with E_JPI_TIMER_INT_PERIOD - will be
non-zero if interrupt for high-to-low transition (end of period) has been set
Returned value logical ANDed with E_JPI_TIMER_INT_RISE - will be
non-zero if interrupt for low-to-high transition (output rising) has been set
vJPI_Timer0RegisterCallback
void vJPI_Timer0RegisterCallback(
PR_HWINT_APPCALLBACK PrTimer0Callback);
Description
This function registers an application callback that will be called when the Timer 0
interrupt is triggered.
Interrupt handling is described in Appendix E.
Parameters
prTimer0Callback Pointer to function that is to be called when Timer 0 interrupt
occurs
Returns
None
void vJPI_Timer1RegisterCallback(
PR_HWINT_APPCALLBACK PrTimer1Callback);
Description
This function registers an application callback that will be called when the Timer 1
interrupt is triggered.
Interrupt handling is described in Appendix E.
Parameters
prTimer1Callback Pointer to function that is to be called when Timer 1 interrupt
occurs
Returns
None
void vJPI_Timer2RegisterCallback(
PR_HWINT_APPCALLBACK PrTimer2Callback);
Description
This function registers an application callback that will be called when the Timer 2
interrupt is triggered on a JN5148 device.
Interrupt handling is described in Appendix E.
Parameters
prTimer2Callback Pointer to function that is to be called when Timer 2 interrupt
occurs
Returns
None
The wake timers are normally used to time sleep periods and can be programmed to
generate interrupts when the timeout period is reached. They can also be used while
the CPU is running (but there is another set of timers with more functionality that can
operate only while the CPU is running - see Section 3.5).
The functions are listed below, along with their page references:
Function Page
vJPI_WakeTimerEnable 118
vJPI_WakeTimerStart 119
vJPI_WakeTimerStop 120
u32JPI_WakeTimerRead 121
u8JPI_WakeTimerStatus 122
u8JPI_WakeTimerFiredStatus 123
u32JPI_WakeTimerCalibrate 124
Description
This function allows the wake timer interrupt (which is generated when the timer fires)
to be enabled/disabled. If this function is called for a wake timer that is already
running, it will stop the wake timer.
The wake timer can be subsequently started using vJPI_WakeTimerStart().
Wake timer interrupts are handled by the System Controller callback function,
registered using the function vJPI_SysCtrlRegisterCallback().
Parameters
u8Timer Identity of timer:
E_JPI_WAKE_TIMER_0
E_JPI_WAKE_TIMER_1
bIntEnable Interrupt enable/disable:
TRUE to enable interrupt when wake timer fires
FALSE to disable interrupt
Returns
None
vJPI_WakeTimerStart
Description
This function starts the specified wake timer with the specified count value. The wake
timer will count down from this value, which is set according to the desired timer
duration. On reaching zero, the timer ‘fires’, rolls over and continues to count down.
The count value, u32Count, is set as the required number of 32-kHz periods. Thus:
Timer duration (in seconds) = u32Count / 32000
Note that the 32-kHz internal clock, which drives the wake timer, may be running up
to 30% fast or slow. For accurate timings, you are advised to first calibrate the clock
using the function u32JPI_WakeTimerCalibrate() and adjust the specified count
value accordingly.
If you wish to enable interrupts for the wake timer, you must call
vJPI_WakeTimerEnable() before calling vJPI_WakeTimerStart(). The wake timer
can be subsequently stopped using vJPI_WakeTimerStop() and can be read using
u32JPI_WakeTimerRead(). Stopping the timer does not affect interrupts that have
been set using vJPI_WakeTimerEnable().
Parameters
u8Timer Identity of timer:
E_JPI_WAKE_TIMER_0
E_JPI_WAKE_TIMER_1
u32Count Count value in 32-kHz periods, i.e. 32 is 1 millisecond
Returns
None
Description
This function stops the specified wake timer.
Note that no interrupt will be generated.
Parameters
u8Timer Identity of timer:
E_JPI_WAKE_TIMER_0
E_JPI_WAKE_TIMER_1
Returns
None
u32JPI_WakeTimerRead
Description
This function obtains the current value of the specified wake timer counter (which
counts down), without stopping the counter.
Note that on reaching zero, the timer ‘fires’, rolls over to 0xFFFFFFFF and continues
to count down. The count value obtained using this function then allows the
application to calculate the time that has elapsed since the wake timer fired.
Parameters
u8Timer Identity of timer:
E_JPI_WAKE_TIMER_0
E_JPI_WAKE_TIMER_1
Returns
Current value of wake timer counter.
uint8 u8JPI_WakeTimerStatus(void);
Description
This function determines which wake timers are active. It is possible to have more
than one wake timer active at the same time. The function returns a bitmap where
the relevant bits are set to show which wake timers are active.
Note that a timer remains active after its countdown has reached zero (when the
timer rolls over and continues to count down).
Parameters
None
Returns
Bitmap:
Returned value logical ANDed with E_JPI_WAKE_TIMER_MASK_0 will be
non-zero if Wake Timer 0 is active
Returned value logical ANDed with E_JPI_WAKE_TIMER_MASK_1 will be
non-zero if Wake Timer 1 is active
u8JPI_WakeTimerFiredStatus
uint8 u8JPI_WakeTimerFiredStatus(void);
Description
This function determines which wake timers have fired (by having passed zero). The
function returns a bitmap where the relevant bits are set to show which timers have
fired. Any fired timer status is cleared as a result of this call.
Parameters
None
Returns
Bitmap:
Returned value logical ANDed with E_JPI_WAKE_TIMER_MASK_0 will be
non-zero if Wake Timer 0 has fired
Returned value logical ANDed with E_JPI_WAKE_TIMER_MASK_1 will be
non-zero if Wake Timer 1 has fired
uint32 u32JPI_WakeTimerCalibrate(void);
Description
This function requests a calibration of the 32-kHz internal clock (on which the wake
timers run) against the more accurate 16-MHz system clock. Note that the 32-kHz
clock has a tolerance of ±30%.
Wake Timer 0 is used in this calibration and must first be disabled, if necessary.
The returned result, n, is interpreted as follows:
n = 10000 ⇒ clock running at 32 kHz
n > 10000 ⇒ clock running slower than 32 kHz
n < 10000 ⇒ clock running faster than 32 kHz
The returned value can be used to adjust the time interval value used to program a
wake timer. If the required timer duration is T seconds, the count value N that must
be specified in vJPI_WakeTimerStart() is given by N = (10000/n) x 32000 x T.
Note that before calling the calibration function, both wake timers (0 and 1) must be
cleared using the function u8JPI_WakeTimerFiredStatus(), otherwise an incorrect
result will be returned.
Parameters
None
Returns
Calibration measurement, n (see above)
Description
This function configures and enables the SPI master.
The function allows the number of extra SPI slaves (of the master) to be set. By
default, there is one SPI slave (the Flash memory) with a dedicated IO pin for its
select line. Depending on how many additional slaves are enabled, up to four more
select lines can be set, which use DIO pins 0 to 3. For example, if two additional
slaves are enabled, DIO 0 and 1 will be assigned. Note that once reserved for SPI
use, DIO lines cannot be subsequently released by calling this function again (and
specifying a smaller number of SPI slaves).
The following features are also configurable using this function:
Data transfer order - whether the least significant bit is transferred first or last
Clock polarity and phase, which together determine the SPI mode (0, 1, 2 or 3) and
therefore the clock edge on which data is latched (for more information on SPI modes,
refer to the Jenie API User Guide (JN-UG-3042)):
SPI Mode 0: polarity=0, phase=0
SPI Mode 1: polarity=0, phase=1
SPI Mode 2: polarity=1, phase=0
SPI Mode 3: polarity=1, phase=1
Clock divisor - the value (in the range 1 to 63) used to derive the SPI clock from the
16-MHz base clock (the 16-MHz clock is divided by twice the specified value)
SPI interrupt - generated when an API transfer has completed (SPI interrupts are
handled by a callback function registered using vJPI_SpiRegisterCallback()). Note
that interrupts are only worth using if the SPI clock frequency is much less than 16 MHz
Automatic slave selection - enable the programmed slave-select line or lines (see
vJPI_SpiSelect()) to be automatically asserted at the start of a transfer and
de-asserted when the transfer completes. If not enabled, the slave-select lines will
reflect the value set by vJPI_SpiSelect() directly.
Parameters
u8SlaveEnable Number of extra SPI slaves to control. Valid values are 0 to 4
- higher values are truncated to 4
bLsbFirst Enable/disable data transfer with the least significant bit (LSB)
transferred first:
TRUE - enable
FALSE - disable
Note that bPolarity and bPhase are named differently in the library header file JPI.h.
Returns
None
void vJPI_SpiReadConfiguration(
tSpiConfiguration *ptConfiguration);
Description
This function obtains the current configuration of the SPI bus.
This function is intended to be used in a system where the SPI bus is used in multiple
configurations to allow the state to be restored later using the function
vJPI_SpiRestoreConfiguration(). Therefore, no knowledge is needed of the
configuration details.
Parameters
*ptConfiguration Pointer to location to receive obtained SPI configuration
Returns
None
vJPI_SpiRestoreConfiguration
void vJPI_SpiRestoreConfiguration(
tSpiConfiguration *ptConfiguration);
Description
This function restores the SPI bus configuration using the configuration previously
obtained using vJPI_SpiReadConfiguration().
Parameters
*ptConfiguration Pointer to SPI configuration to be restored
Returns
None
Description
This function sets the active slave-select line(s) to use.
The slave-select lines are asserted immediately if “Automatic Slave Selection” is
disabled, or otherwise only during data transfers. The number of valid bits in
u8SlaveMask depends on the setting of u8SlaveEnable in a previous call to
vJPI_SpiConfigure(), as follows:
0 Bit 0
1 Bits 0, 1
2 Bits 0, 1, 2
3 Bits 0, 1, 2, 3
4 Bits 0, 1, 2, 3, 4
Parameters
u8SlaveMask Bitmap - one bit per slave-select line
Returns
None
vJPI_SpiStop
void vJPI_SpiStop(void);
Description
This function clears any active slave-select lines. It has the same effect as
vJPI_SpiSelect(0).
Parameters
None
Returns
None
Description
This function starts a 32-bit data transfer to/from the selected slave(s).
It is assumed that vJPI_SpiSelect() has been called to set the slave(s) to
communicate with. If interrupts are enabled for the SPI master, an interrupt will be
generated when the transfer has completed.
Parameters
u32Out 32 bits of data to transmit
Returns
None
u32JPI_SpiReadTransfer32
uint32 u32JPI_SpiReadTransfer32(void);
Description
This function obtains the received data after a 32-bit SPI transfer has completed.
Parameters
None
Returns
Received data (32 bits)
Description
This function starts a 16-bit data transfer to/from the selected slave(s).
It is assumed that vJPI_SpiSelect() has been called to set the slave(s) to
communicate with. If interrupts are enabled for the SPI master, an interrupt will be
generated when the transfer has completed.
Parameters
u16Out 16 bits of data to transmit
Returns
None
u16JPI_SpiReadTransfer16
uint16 u16JPI_SpiReadTransfer16(void);
Description
This function obtains the received data after a 16-bit SPI transfer has completed.
Parameters
None
Returns
Received data (16 bits)
Description
This function starts an 8-bit transfer to/from the selected slaves(s).
It is assumed that vJPI_SpiSelect() has been called to set the slave(s) to
communicate with. If interrupts are enabled for the SPI master, an interrupt will be
generated when the transfer has completed.
Parameters
u8Out 8 bits of data to transmit
Returns
None
u8JPI_SpiReadTransfer8
uint8 u8JPI_SpiReadTransfer8(void);
Description
This function obtains the received data after a 8-bit SPI transfer has completed.
Parameters
None
Returns
Received data (8 bits)
bool_t bJPI_SpiPollBusy(void);
Description
This function polls the SPI master to determine whether it is currently busy
performing a data transfer.
Parameters
None
Returns
TRUE if the SPI master is performing a transfer, FALSE otherwise
vJPI_SpiWaitBusy
void vJPI_SpiWaitBusy(void);
Description
This function waits for the SPI master to complete a transfer and then returns.
Parameters
None
Returns
None
void vJPI_SpiRegisterCallback(
PR_HWINT_APPCALLBACK prSpiCallback);
Description
This function registers an application callback that will be called when the SPI
interrupt is triggered.
The registered callback function is only preserved during sleep with memory held. If
RAM is powered off during sleep and interrupts are required, the callback function
must be re-registered before calling u32JPI_Init() on waking.
Interrupt handling is described in Appendix E.
Parameters
prSpiCallback Pointer to function to be called when SPI interrupt occurs
Returns
None
The functions are listed below, along with their page references:
Function Page
vJPI_SiConfigure 142
vJPI_SiSetCmdReg 143
vJPI_SiWriteData8 145
vJPI_SiWriteSlaveAddr 146
u8JPI_SiReadData8 147
bJPI_SiPollBusy 148
bJPI_SiPollTransferInProgress 149
bJPI_SiPollRxNack 150
bJPI_SiPollArbitrationLost 151
vJPI_SiRegisterCallback 152
Description
This function is used to enable/disable and configure the 2-wire Serial Interface (SI)
master on the JN5139/JN5148 device. This function must be called to enable the SI
block before any other SI master function is called.
The operating frequency, derived from the 16-MHz system clock using the specified
prescaler u16PreScaler, is given by:
Operating frequency = 16/[(PreScaler + 1) x 5] MHz
SI interrupts are handled by a callback function registered using the function
vJPI_SiRegisterCallback().
Parameters
bSiEnable Enable Serial Interface (master):
TRUE - enable
FALSE - disable
bInterruptEnable Enable Serial interface interrupt:
TRUE - enable
FALSE - disable
u16PreScaler 16-bit clock prescaler (see above)
Returns
None
vJPI_SiSetCmdReg
Description
This function configures the combination of I2C-protocol commands for a transfer on
the SI bus and starts the transfer of the data held in the SI master’s transmit buffer.
Up to four commands can be used to perform an I2C-protocol transfer - Start, Stop,
Write, Read. This function allows these commands to be combined to form a
complete or partial transfer sequence. The valid command combinations that can be
specified are summarised below.
0 0 0 1 Write only
0 0 1 0 Read only
0 1 0 0 Stop only
The above command combinations will result in the function returning TRUE, while
command combinations that are not in the above list are invalid and will result in a
FALSE return code.
The function must be called immediately after vJPI_SiWriteSlaveAddr(), which puts
the destination slave address (for the subsequent data transfer) into the transmit
buffer. It must then be called immediately after vJPI_SiWriteData8() to start the
transfer of data (from the transmit buffer).
To implement a data transfer on the SI bus, you must follow the process described
in the I2C Specification.
Returns
None
vJPI_SiWriteData8
Description
This function writes a single data byte to the Transmit register of the Serial Interface.
The contents of the transmit buffer will not be transmitted on the SI bus until the
function vJPI_SiSetCmdReg() is called.
Parameters
u8Out 8 bits of data to transmit
Returns
None
Description
This function is used in setting up communication with a slave device. In this function,
you must specify the address of the slave (see below) and the operation (read or
write) to be performed on the slave. The function puts this information in the SI
master’s transmit buffer, but the information will be not transmitted on the SI bus until
the function vJPI_SiSetCmdReg() is called.
You must specify a 7-bit slave address and the operation (read or write) to be
performed on the slave. To implement a data transfer on the SI bus, you must follow
the process described in the I2C Specification.
Parameters
u8SlaveAddress 7-bit slave address
bReadStatus Operation to perform on slave (read or write):
TRUE to configure a read
FALSE to configure a write
Returns
None
u8JPI_SiReadData8
uint8 u8JPI_SiReadData8(void);
Description
This function obtains 8-bit data received over the Serial Interface bus.
Parameters
None
Returns
Data read from receive buffer of SI master
bool_t bJPI_SiPollBusy(void);
Description
This function checks whether the SI bus is busy (could be in use by another master).
Parameters
None
Returns
TRUE if busy, FALSE otherwise
bJPI_SiPollTransferInProgress
bool_t bJPI_SiPollTransferInProgress(void);
Description
This function checks whether a transfer is in progress on the SI bus.
Parameters
None
Returns
TRUE if a transfer is in progress, FALSE otherwise
bool_t bJPI_SiPollRxNack(void);
Description
This function checks whether a NACK or an ACK has been received from the slave
device. If a NACK has been received, this indicates that the SI master should stop
sending data to the slave.
Parameters
None
Returns
TRUE if NACK has occurred
FALSE if ACK has occurred
bJPI_SiPollArbitrationLost
bool_t bJPI_SiPollArbitrationLost(void);
Description
This function checks whether arbitration has been lost (by the local master) on the SI
bus.
Parameters
None
Returns
TRUE if arbitration loss has occurred, FALSE otherwise
void vJPI_SiRegisterCallback(
PR_HWINT_APPCALLBACK prSiCallback);
Description
This function registers a user-defined callback function that will be called when a
Serial Interface interrupt is triggered on the SI master.
Note that this function can be used to register the callback function for a SI slave as
well as for the SI master. The SI interrupt handler will determine whether a SI
interrupt has been generated on a master or slave, and then invoke the relevant
callback function.
The registered callback function is only preserved during sleep modes in which RAM
remains powered. If RAM is powered off during sleep and interrupts are required, the
callback function must be re-registered before calling u32JPI_Init() on waking.
Interrupt handling is described in Appendix E.
Parameters
prSiCallback Pointer to function to be called when Serial Interface interrupt
occurs
Returns
None
Description
This function initialises and enables the Intelligent Peripheral (IP) interface on the
JN5139/JN5148 device.
The function allows the clock edges to be selected on which receive data will be
sampled and transmit data will be changed (but see Caution below). It also allows
Intelligent Peripheral interrupts to be enabled/disabled.
The function also requires the byte order (Big or Little Endian) of the data for the IP
interface to be specified.
Parameters
bTxEdge Clock edge that transmit data is changed on (see Caution):
E_JPI_IP_TXPOS_EDGE
(data changed on +ve edge, to be sampled on -ve edge)
E_JPI_IP_TXNEG_EDGE
(data changed on -ve edge, to be sampled on +ve edge)
bRxEdge Clock edge that receive data is sampled on (see Caution):
E_JPI_IP_RXPOS_EDGE
(data sampled on +ve edge)
E_JPI_IP_RXNEG_EDGE
(data sampled on -ve edge)
bEndian Byte order (Big or Little Endian) of data over the IP interface:
E_JPI_IP_BIG_ENDIAN
E_JPI_IP_LITTLE_ENDIAN
Returns
None
bJPI_IpSendData
Description
This function is used to indicate that data is ready to be transmitted across the IP
interface to the remote processor (the SPI master).
The function requires the data length to be specified, as well as a pointer to the buffer
containing the data. The data should be stored in the buffer according to the byte
order (Big or Little Endian) specified in the function vJPI_IpEnable().
The function copies the specified data to a local Transmit buffer, ready to be sent
when the master device initiates the transfer. The IP_INT pin is also asserted to
indicate to the master that data is ready to be sent.
The data length is transmitted in the first 32-bit word of the data payload. It is the
responsibility of the SPI master receiving the data to retrieve the data length from the
payload.
Parameters
u8Length Length of data to be sent (in 32-bit words)
*pau8Data Pointer to a buffer containing the data to be sent
Returns
TRUE if successful, FALSE if unable to send
Description
This function is used to read data received from the remote processor (the SPI
master).
The function must provide a pointer to a buffer to receive the data and a pointer to a
buffer to receive the data length.
Data is stored in the specified buffer according to the specified byte order (Big or
Little Endian) specified in the function vJPI_IpEnable().
After the data has been read, the IP interface will indicate to the SPI master that the
interface is ready to receive more data.
Parameters
*pu8Length Pointer to length of buffer to receive data (in 32-bit words)
*pau8Data Pointer to buffer to receive data
Returns
TRUE if data read successfully, FALSE if unable to read
bJPI_IpTxDone
bool_t bJPI_IpTxDone(void);
Description
This function checks whether data copied to the local Transmit buffer has been sent
to the remote processor (the SPI master).
Parameters
None
Returns
TRUE if data sent, FALSE if incomplete
bool_t bJPI_IpRxDataAvailable(void);
Description
This function checks whether data from the remote processor (the SPI master) has
been received in the local Receive buffer.
Parameters
None
Returns
TRUE if Receive buffer contains data, FALSE otherwise
vJPI_IpRegisterCallback
void vJPI_IpRegisterCallback(
PR_HWINT_APPCALLBACK prIpCallback);
Description
This function registers an application callback that will be called when the Intelligent
Peripheral interrupt is triggered. The Interrupt is triggered when either a transmit or
receive transaction has completed.
The registered callback function is only preserved during sleep modes in which RAM
remains powered. If RAM is powered off during sleep and interrupts are required, the
callback function must be re-registered before calling u32JPI_Init() on waking.
Interrupt handling is described in Appendix E.
Parameters
prIpCallback Pointer to function to be called when Intelligent Peripheral
interrupt occurs
Returns
None
Appendices
The appendices contains all the ancillary information that you need in order to use the
functions of the Jenie API. This information includes global parameters, enumerations,
data types, structures, events and interrupts. In addition, functions and network
parameters of the JenNet layer (which sits below Jenie in the stack) are described.
gJpdmSectorSize Size of sector where context data will 32768 (32K) Size in bytes
be saved in external non-volatile
memory.
Component (teJenieComponent)
typedef enum
{
E_JENIE_COMPONENT_JENIE, /*Jenie*/
E_JENIE_COMPONENT_NETWORK, /*Network level - JenNet*/
E_JENIE_COMPONENT_MAC, /*IEEE 802.15.4*/
E_JENIE_COMPONENT_CHIP /*JN513x chip*/
} teJenieComponent;
TXOPTION #defines
Peripheral (teJPI_Device)
Device types, used to identify interrupt source:
typedef enum
{
E_JPI_DEVICE_TICK_TIMER = 0, /* Tick timer */
E_JPI_DEVICE_SYSCTRL = 2, /* System controller */
E_JPI_DEVICE_BBC, /* Baseband controller */
E_JPI_DEVICE_AES, /* Encryption engine */
E_JPI_DEVICE_PHYCTRL, /* Phy controller */
E_JPI_DEVICE_UART0, /* UART 0 */
E_JPI_DEVICE_UART1, /* UART 1 */
E_JPI_DEVICE_TIMER0, /* Timer 0 */
E_JPI_DEVICE_TIMER1, /* Timer 1 */
E_JPI_DEVICE_SI, /* Serial Interface (2 wire) */
E_JPI_DEVICE_SPIM, /* SPI master */
E_JPI_DEVICE_INTPER, /* Intelligent peripheral */
E_JPI_DEVICE_ANALOGUE /* Analogue peripherals */
} teJPI_Device;
Comparator (teJPI_Comparator)
typedef enum {
E_JPI_COMPARATOR_0,
E_JPI_COMPARATOR_1
} teJPI_Comparator;
Timer (teJPI_Timer)
typedef enum {
E_JPI_TIMER_0,
E_JPI_TIMER_1
} teJPI_Timer;
Comparator #defines
#define E_JPI_COMP_HYSTERESIS_0MV 0
#define E_JPI_COMP_HYSTERESIS_5MV 1
#define E_JPI_COMP_HYSTERESIS_10MV 2
#define E_JPI_COMP_HYSTERESIS_20MV 3
#define E_JPI_AP_COMPARATOR_MASK_1 1
#define E_JPI_AP_COMPARATOR_MASK_2 2
#define E_JPI_COMP_SEL_EXT 0x00
#define E_JPI_COMP_SEL_DAC 0x01
#define E_JPI_COMP_SEL_BANDGAP 0x03
UART #defines
#define E_JPI_UART_0 0
#define E_JPI_UART_1 1
#define E_JPI_UART_RATE_4800 0
#define E_JPI_UART_RATE_9600 1
#define E_JPI_UART_RATE_19200 2
#define E_JPI_UART_RATE_38400 3
#define E_JPI_UART_RATE_76800 4
#define E_JPI_UART_RATE_115200 5
#define E_JPI_UART_WORD_LEN_5 0
#define E_JPI_UART_WORD_LEN_6 1
#define E_JPI_UART_WORD_LEN_7 2
#define E_JPI_UART_WORD_LEN_8 3
#define E_JPI_UART_FIFO_LEVEL_1 0
#define E_JPI_UART_FIFO_LEVEL_4 1
#define E_JPI_UART_FIFO_LEVEL_8 2
#define E_JPI_UART_FIFO_LEVEL_14 3
#define E_JPI_UART_LS_ERROR 0x80
#define E_JPI_UART_LS_TEMT 0x40
#define E_JPI_UART_LS_THRE 0x20
#define E_JPI_UART_LS_BI 0x10
#define E_JPI_UART_LS_FE 0x08
#define E_JPI_UART_LS_PE 0x04
#define E_JPI_UART_LS_OE 0x02
#define E_JPI_UART_LS_DR 0x01
#define E_JPI_UART_MS_DCTS 0x01
#define E_JPI_UART_INT_MODEM 0
#define E_JPI_UART_INT_TX 1
#define E_JPI_UART_INT_RXDATA 2
#define E_JPI_UART_INT_RXLINE 3
#define E_JPI_UART_INT_TIMEOUT 6
#define E_JPI_UART_TX_RESET TRUE
#define E_JPI_UART_RX_RESET TRUE
#define E_JPI_UART_TX_ENABLE FALSE
#define E_JPI_UART_RX_ENABLE FALSE
#define E_JPI_UART_EVEN_PARITY TRUE
#define E_JPI_UART_ODD_PARITY FALSE
#define E_JPI_UART_PARITY_ENABLE TRUE
#define E_JPI_UART_PARITY_DISABLE FALSE
#define E_JPI_UART_1_STOP_BIT TRUE
#define E_JPI_UART_2_STOP_BITS FALSE
#define E_JPI_UART_RTS_HIGH TRUE
#define E_JPI_UART_RTS_LOW FALSE
SPI #defines
#define E_JPI_SPIM_MSB_FIRST FALSE
#define E_JPI_SPIM_LSB_FIRST TRUE
#define E_JPI_SPIM_TXPOS_EDGE FALSE
#define E_JPI_SPIM_TXNEG_EDGE TRUE
#define E_JPI_SPIM_RXPOS_EDGE FALSE
#define E_JPI_SPIM_RXNEG_EDGE TRUE
#define E_JPI_SPIM_INT_ENABLE TRUE
#define E_JPI_SPIM_INT_DISABLE FALSE
#define E_JPI_SPIM_AUTOSLAVE_ENBL TRUE
#define E_JPI_SPIM_AUTOSLAVE_DSABL FALSE
#define E_JPI_SPIM_SLAVE_ENBLE_0 0x1
#define E_JPI_SPIM_SLAVE_ENBLE_1 0x2
#define E_JPI_SPIM_SLAVE_ENBLE_2 0x4
#define E_JPI_SPIM_SLAVE_ENBLE_3 0x8
DIO #defines
#define E_JPI_DIO0_INT 0x00000001
#define E_JPI_DIO1_INT 0x00000002
#define E_JPI_DIO2_INT 0x00000004
#define E_JPI_DIO3_INT 0x00000008
#define E_JPI_DIO4_INT 0x00000010
#define E_JPI_DIO5_INT 0x00000020
#define E_JPI_DIO6_INT 0x00000040
#define E_JPI_DIO7_INT 0x00000080
#define E_JPI_DIO8_INT 0x00000100
#define E_JPI_DIO9_INT 0x00000200
#define E_JPI_DIO10_INT 0x00000400
#define E_JPI_DIO11_INT 0x00000800
#define E_JPI_DIO12_INT 0x00001000
#define E_JPI_DIO13_INT 0x00002000
#define E_JPI_DIO14_INT 0x00004000
#define E_JPI_DIO15_INT 0x00008000
#define E_JPI_DIO16_INT 0x00010000
#define E_JPI_DIO17_INT 0x00020000
#define E_JPI_DIO18_INT 0x00040000
#define E_JPI_DIO19_INT 0x00080000
#define E_JPI_DIO20_INT 0x00100000
Peripheral (teJPI_Device)
Device types, used to identify interrupt source:
typedef enum
{
E_JPI_DEVICE_AUDIOFIFO = 0, /* Sample FIFO */
E_JPI_DEVICE_I2S = 1, /* 4-wire DAI */
E_JPI_DEVICE_SYSCTRL = 2, /* System controller */
E_JPI_DEVICE_BBC = 3, /* Baseband controller */
E_JPI_DEVICE_AES = 4, /* Encryption engine */
E_JPI_DEVICE_PHYCTRL = 5, /* Phy controller */
E_JPI_DEVICE_UART0 = 6, /* UART 0 */
E_JPI_DEVICE_UART1 = 7, /* UART 1 */
E_JPI_DEVICE_TIMER0 = 8, /* Timer 0 */
E_JPI_DEVICE_TIMER1 = 9, /* Timer 1 */
E_JPI_DEVICE_SI = 10, /* 2-wire SI */
E_JPI_DEVICE_SPIM = 11, /* SPI master */
E_JPI_DEVICE_INTPER = 12, /* Intelligent peripheral */
E_JPI_DEVICE_ANALOGUE = 13, /* Analogue peripherals */
E_JPI_DEVICE_TIMER2 = 14, /* Timer 2 */
E_JPI_DEVICE_TICK_TIMER = 15 /* Tick timer */
} teJPI_Device;
Comparator (teJPI_Comparator)
typedef enum {
E_JPI_COMPARATOR_0,
E_JPI_COMPARATOR_1
} teJPI_Comparator;
Timer (teJPI_Timer)
typedef enum {
E_JPI_TIMER_0,
E_JPI_TIMER_1,
E_JPI_TIMER_2
} teJPI_Timer;
Comparator #defines
#define E_JPI_COMP_HYSTERESIS_0MV 0
#define E_JPI_COMP_HYSTERESIS_10MV 1
#define E_JPI_COMP_HYSTERESIS_20MV 2
#define E_JPI_COMP_HYSTERESIS_40MV 3
#define E_JPI_AP_COMPARATOR_MASK_1 1
#define E_JPI_AP_COMPARATOR_MASK_2 2
#define E_JPI_COMP_SEL_EXT 0x00
#define E_JPI_COMP_SEL_DAC 0x01
#define E_JPI_COMP_SEL_BANDGAP 0x03
UART #defines
#define E_JPI_UART_RATE_4800 0
#define E_JPI_UART_RATE_9600 1
#define E_JPI_UART_RATE_19200 2
#define E_JPI_UART_RATE_38400 3
#define E_JPI_UART_RATE_76800 4
#define E_JPI_UART_RATE_115200 5
#define E_JPI_UART_WORD_LEN_5 0
#define E_JPI_UART_WORD_LEN_6 1
#define E_JPI_UART_WORD_LEN_7 2
#define E_JPI_UART_WORD_LEN_8 3
#define E_JPI_UART_FIFO_LEVEL_1 0
#define E_JPI_UART_FIFO_LEVEL_4 1
#define E_JPI_UART_FIFO_LEVEL_8 2
#define E_JPI_UART_FIFO_LEVEL_14 3
#define E_JPI_UART_LS_ERROR 0x80
#define E_JPI_UART_LS_TEMT 0x40
#define E_JPI_UART_LS_THRE 0x20
#define E_JPI_UART_LS_BI 0x10
#define E_JPI_UART_LS_FE 0x08
#define E_JPI_UART_LS_PE 0x04
#define E_JPI_UART_LS_OE 0x02
#define E_JPI_UART_LS_DR 0x01
#define E_JPI_UART_MS_CTS 0x10
#define E_JPI_UART_MS_DCTS 0x01
#define E_JPI_UART_INT_MODEM 0
#define E_JPI_UART_INT_TX 1
#define E_JPI_UART_INT_RXDATA 2
#define E_JPI_UART_INT_RXLINE 3
#define E_JPI_UART_INT_TIMEOUT 6
#define E_JPI_UART_TX_RESET TRUE
#define E_JPI_UART_RX_RESET TRUE
#define E_JPI_UART_TX_ENABLE FALSE
#define E_JPI_UART_RX_ENABLE FALSE
#define E_JPI_UART_EVEN_PARITY TRUE
#define E_JPI_UART_ODD_PARITY FALSE
#define E_JPI_UART_PARITY_ENABLE TRUE
#define E_JPI_UART_PARITY_DISABLE FALSE
#define E_JPI_UART_1_STOP_BIT TRUE
#define E_JPI_UART_2_STOP_BITS FALSE
#define E_JPI_UART_RTS_HIGH TRUE
#define E_JPI_UART_RTS_LOW FALSE
SPI #defines
#define E_JPI_SPIM_MSB_FIRST FALSE
#define E_JPI_SPIM_LSB_FIRST TRUE
#define E_JPI_SPIM_TXPOS_EDGE FALSE
#define E_JPI_SPIM_TXNEG_EDGE TRUE
#define E_JPI_SPIM_RXPOS_EDGE FALSE
#define E_JPI_SPIM_RXNEG_EDGE TRUE
#define E_JPI_SPIM_INT_ENABLE TRUE
#define E_JPI_SPIM_INT_DISABLE FALSE
#define E_JPI_SPIM_AUTOSLAVE_ENBL TRUE
#define E_JPI_SPIM_AUTOSLAVE_DSABL FALSE
#define E_JPI_SPIM_SLAVE_ENBLE_0 0x1
#define E_JPI_SPIM_SLAVE_ENBLE_1 0x2
#define E_JPI_SPIM_SLAVE_ENBLE_2 0x4
#define E_JPI_SPIM_SLAVE_ENBLE_3 0x8
DIO #defines
#define E_JPI_DIO0_INT 0x00000001
#define E_JPI_DIO1_INT 0x00000002
#define E_JPI_DIO2_INT 0x00000004
#define E_JPI_DIO3_INT 0x00000008
#define E_JPI_DIO4_INT 0x00000010
#define E_JPI_DIO5_INT 0x00000020
#define E_JPI_DIO6_INT 0x00000040
#define E_JPI_DIO7_INT 0x00000080
#define E_JPI_DIO8_INT 0x00000100
#define E_JPI_DIO9_INT 0x00000200
#define E_JPI_DIO10_INT 0x00000400
#define E_JPI_DIO11_INT 0x00000800
#define E_JPI_DIO12_INT 0x00001000
#define E_JPI_DIO13_INT 0x00002000
#define E_JPI_DIO14_INT 0x00004000
#define E_JPI_DIO15_INT 0x00008000
#define E_JPI_DIO16_INT 0x00010000
#define E_JPI_DIO17_INT 0x00020000
#define E_JPI_DIO18_INT 0x00040000
#define E_JPI_DIO19_INT 0x00080000
#define E_JPI_DIO20_INT 0x00100000
E_JENIE_POLL_CMPLT Indicates that the End Device has finished polling the tsPollCmplt
parent node for data.
End Devices only
E_JENIE_PACKET_SENT Indicates that a packet has been successfully sent (to NULL
the next node).
E_JENIE_PACKET_FAILED Indicates that a packet send (to the next node) has NULL
failed.
vJenie_CbStackMgmtEvent() has two parameters, the first being the stack event as
described above. The second parameter is a pointer to a data structure that contains
additional information fields. If the additional data is not necessary, the second
parameter is simply a NULL pointer. If a pointer to the primitive is sent, it must be cast
to the appropriate type described below.
tsSvcReqRsp
typedef struct
{
uint64 u64SrcAddress; /* Address of responding node */
uint32 u32Services; /* Services available on node */
} tsSvcReqRsp;
u32Services is a 32-bit value in which each bit position represents a network service
- the bit representations are as in the network’s Service Profile, defined in the header
file Jenie.h. In u32services, ‘1’ indicates that the responding node supports the
corresponding service and ‘0’ indicates that the service is not supported by the node.
tsPollCmplt
typedef struct
{
teJeniePollStatus ePollStatus;
}tsPollCmplt;
tsChildJoined
typedef struct
{
uint64 u64SrcAddress; /* Address of node that has joined */
} tsChildJoined;
tsChildLeave
typedef struct
{
uint64 u64SrcAddress; /* Address of node that has left */
} tsChildLeave;
tsNwkStartUp
typedef struct{
uint64 u64ParentAddress; /*Address of parent node*/
uint64 u64LocalAddress; /*Address of local node*/
uint16 u16Depth; /*Depth of node in the network*/
uint16 u16PanID; /*PAN ID of the network*/
uint8 u8Channel; /*Operating channel */
}tsNwkStartUp
tsData
typedef struct
{
uint64 u64SrcAddress; /* Address of message source */
uint8 u8MsgFlags; /* Flags reserved for future use */
uint16 u16Length; /* Length of data payload, in bytes */
uint8 *pau8Data; /* Pointer to data payload */
}tsData;
tsDataToService
typedef struct
{
uint64 u64SrcAddress; /* Address of message source */
uint8 u8SrcService; /* Service on sending node */
uint8 u8DestService; /* Service on receiving node */
uint8 u8MsgFlags; /* Flags reserved for future use */
uint16 u16Length; /* Length of data payload, in bytes */
uint8 *pau8Data; /* Pointer to data payload */
}tsDataToService;
tsDataAck
typedef struct
{
uint64 u64SrcAddress; /* Address of acknowledgement source */
}tsDataAck;
tsDataToServiceAck
typedef struct
{
uint64 u64SrcAddress; /* Address of sending node */
}tsDataToServiceAck;
For example, you can define your own UART interrupt handler and register this
callback function using the vJPI_Uart0RegisterCallback() function (for UART0).
where
u32DeviceId is an enumerated value indicating the peripheral that generated
the interrupt - see Appendix E.1.1 below
u32ItemBitmap is a 32-bit bitmask indicating the individual interrupt source
within the peripheral (except for the UARTs, for which the parameter returns an
enumerated value) - see Appendix E.1.2 below
Before calling the callback function, the library clears the source of the interrupt, so
there is no possibility of the processor entering a state of permanently trying to handle
the same interrupt due to a malformed callback function. This also means that it is
possible to have a NULL callback function.
The UARTs are the exception to this rule - when generating a 'receive data available'
or 'timeout indication' interrupt, the UARTs will only clear the interrupt when the data
is read from the UART receive buffer. It is therefore vital that (if UART interrupts are
to be enabled) the callback function handles the 'receive data available' and 'timeout
indication' interrupts by reading the data from the UART before returning.
Value Value
Enumeration Interrupt Source
(JN5139) (JN5148)
E_JPI_DEVICE_UART0 6 6 UART0
E_JPI_DEVICE_UART1 7 7 UART1
E_JPI_DEVICE_TIMER0 8 8 Timer 0
E_JPI_DEVICE_TIMER1 9 9 Timer 1
System Controller
Analogue Peripherals
Timers
These values are identical for the two timers.
SPI Master
* When this interrupt occurs, the received data byte is passed to the application via bits 15-8 of
the u32Bitmap parameter of the vJenie_CbHwEvent() callback function. In the case of an
E_JPI_UART_INT_RXDATA interrupt, any other bytes remaining in the UART's FIFO can be
detected by checking the E_JPI_UART_LS_DR bit using the u8JPI_UartReadLineStatus()
function, and then read from the UART using the u8JPI_UartReadData() function.
E.2.2 DIO
There are 21 DIO lines (0-20) on the JN5139/JN5148 wireless microcontroller. The
device can be woken from sleep on the change of state of any DIOs that have been
configured as inputs and as wake sources. The functions for controlling the DIOs are
detailed in Section 3.3.
The directions of the DIOs (input or output) are configured using the function
vJPI_DioSetDirection(). Wake interrupts can then be enabled on DIO inputs using
the function vJPI_DioSetOutput().
F. JenNet API
This appendix details the functions and network parameters of the JenNet API, which
may be used in conjunction with the Jenie API to access features provided by the
underlying JenNet stack layer. The JenNet functions provide additional control over
how nodes join a network, inter-network communication and the operation of the
Jenie/JenNet stack.
If using the JenNet API, your project must include the JenNet header file
SDK\Jenie\Include\JenNetApi.h, as well as SDK\Common\Include\mac_sap.h for
the declarations of the structures MAC_Addr_s and MAC_ExtAddr_s, shown below:
MAC_Addr_s
typedef struct
{
uint8 u8AddrMode; /* Address mode: 2 for short, 3 for extended */
uint16 u16PanId; /* PAN ID */
MAC_Addr_u uAddr; /* Address */
} MAC_Addr_s;
MAC_ExtAddr_s
typedef struct
{
uint32 u32L; /* Low word */
uint32 u32H; /* High word */
} MAC_ExtAddr_s;
eApi_SendDataToExtNwk
teJenNetStatusCode eApi_SendDataToExtNwk(
MAC_Addr_s *psDestAddr,
uint8 *pu8Payload,
uint8 u8Length);
Description
This function is used to request the transmission of a data frame to another node that
is not necessarily in the same network (not necessarily having the same PAN ID).
The destination address is specified using the MAC_Addr_s structure (shown on
page 191), which allows the application to specify the destination PAN ID and either
a 64-bit extended address (IEEE/MAC address) or a 16-bit short address (as used in
IEEE 802.15.4).
If a broadcast short address and a broadcast PAN ID are used, the packet will be
sent to all nodes within radio range, irrespective of which network they are in.
The JenNet parameter bPermitExtNwkPkts is set to FALSE by default. Setting this to
TRUE for the local node enables the reception of external network packets (packets
for which the source PAN ID is not the same as the local PAN ID).
Parameters
*psDestAddr Pointer to address of the destination node
Note that the MAC_Addr_s structure contains the PAN ID and
either a 16-bit short or 64-bit extended address
*pu8Payload Pointer to the data to be sent
u8Length Length of the data to be sent, in bytes
Returns
E_JENNET_DEFERRED
The node successfully passed the packet to the IEEE 802.15.4 MAC layer
E_JENNET_ERROR
The node was not able to pass the request into the IEEE 802.15.4 MAC layer
Description
This function is used on a parent node to force an immediate child to leave the
network by deleting its entry in the local Neighbour table. The node to be removed is
specified using its 64-bit IEEE/MAC address in the MAC_ExtAddr_s structure
(shown on page 191).
There will be a delay before the child node attempts to rejoin a network, as its ‘failed
packet threshold’ must first be exceeded.
Note that vNwk_DeleteChild() is called on the parent node. In contrast, the Jenie
function eJenie_Leave() can be called on a child node to remove itself from the
network.
Parameters
*psNodeAddr Pointer to the IEEE/MAC address of the node to remove
Returns
None
vApi_SetScanSleep
Description
This function allows the application to set the scan sleep duration at run-time. It only
applies to End Devices since Routers/Co-ordinators are not able to sleep.
The scan sleep period is the amount of time for which the End Device sleeps
between channel scans when trying to join the network - that is, if the device fails to
join the network after one scan, it will sleep for this period before scanning again.
Increasing this period will help to preserve battery life in the End Device.
Obtaining no results in the scan sort callback function (registered using
vApi_RegScanSortCallback()) or a STACK_RESET event are useful points at
which to change the scan sleep period.
Parameters
u32ScanSleepDuration Time, in milliseconds, to sleep after scan timeout
Returns
None
Description
This function allows the application to modify the TTL (Time To Live) of broadcast
packets that originate from the local node. The TTL value is defined as the maximum
number of hops of a broadcast message. To allow broadcast packets to propagate
all the way through the network, this value should be set to at least the expected
depth of the network. In fact, the parameter u8MaxTTL should be set as follows:
u8MaxTTL = Desired maximum number of broadcast hops - 1
Parameters
u8MaxTTL Maximum number of hops - 1
Therefore, for a single hop, set this value to 0
Returns
None
vApi_SetPurgeRoute
Description
This function is used to tailor the route maintenance behaviour by allowing route
purging to be enabled/disabled.
By default, all Routers and the Coordinator will periodically check all entries in their
Routing tables for possible stale routes. A stale route is one that has not carried any
traffic in a given period of time. In long thin network topologies, this policy may be
inefficient, as the same routes will be purged by each Router. It may be more efficient
and less traffic intensive to disable this feature on Routers and just leave it enabled
on the Coordinator.
Route maintenance is also configured using the function vApi_SetPurgeInterval().
Parameters
bPurge Enable/disable route purging:
TRUE - enable (default)
FALSE - disable
Returns
None
Description
This function is used together with vApi_SetPurgeRoute() to tailor the automatic
route maintenance. The function can be used to adjust the route maintenance cycle
- it sets the period of time between each route maintenance activity.
The default period is one second, which means that a Routing table entry is
examined every second (even if the entry is not used). The length of time taken to
process the whole Routing table is determined by the table size, which is user-
defined at build time - for example, a Routing table comprising 100 entries will take
100 seconds to process (even if only one of the entries is actually used). Routes will
be interrogated if they have not been used in two cycles, e.g. 200 seconds.
Setting a smaller period will improve clean-up time after network reconfiguration due
to node failure, but will generate more traffic travelling down the tree which could
cause contention with user data flowing up the tree. Setting a larger value will extend
the time taken to clean-up.
This feature may not be required if there is regular traffic generated from all the
network nodes.
Parameters
u32Interval Route maintenance period in units of 100 ms
Returns
None
vNwk_SetBeaconCalming
Description
This function enables/disables ‘beacon calming’.
When a large, dense network attempts to recover from a major failure, large numbers
of beacons are generated which can slow the flow of essential network management
messages. Enabling beacon calming suppresses beacons generated by Routers
that are statistically less able to accept associations. Hence, the speed of network
recovery increases.
Parameters
bState Enable/disable beacon calming:
TRUE - enable
FALSE - disable (default)
Returns
None
Description
This function is used to set the user-defined part of the beacon payload. This can
then be used to control network formation.
The function must be called after the network has started, otherwise the bits will be
cleared.
Parameters
u16Bits 16 bits of user data to be inserted in the beacon payload
Returns
None
u16Api_GetUserBeaconBits
uint16 u16Api_GetUserBeaconBits(void);
Description
This function is used to read the 16-bit user-defined part of a beacon payload. These
user-defined bits can be used for any application functionality, such as to control
network formation.
The contents of beacons received using vApi_RegBeaconNotifyCallback() can be
inspected for the user bits, and beacons accepted or discarded on the basis of these
bits.
Parameters
None
Returns
16 bits of user data read from the beacon payload
uint8 u8Api_GetLastPktLqi(void);
Description
This function returns the LQI value (detected radio signal strength) of the last packet
received, and must be called in the data event handler vJenie_CbStackDataEvent()
in response to a data event. This guarantees that the returned LQI value applies to
the packet which is going to be processed. Calling the function at any other time will
return the LQI value of the last packet processed, which may be one that was routed
or may be a network management packet.
This is the LQI value of the last hop to its destination node.
For further information on the LQI value, including an approximate relationship
between the LQI value and the detected power in dBm, refer to Appendix G.
Parameters
None
Returns
The LQI value of the last packet received
u16Api_GetDepth
uint16 u16Api_GetDepth(void);
Description
This function is used to return the number of hops of the local node from the Co-
ordinator. Since a JenNet network employs a Tree topology, the result is the depth
of the local node in the network.
Parameters
None
Returns
Number of hops from Co-ordinator
uint8 u8Api_GetStackState(void);
Description
This function returns the current state of the JenNet stack and provides a mechanism
for determining the current operation of the stack.
Parameters
None
Returns
The state of the JenNet stack, one of:
E_JENNET_IDLE (0x00)
E_JENNET_ENERGY_SCAN (0x01)
E_JENNET_WAITING_FOR_ENERGY_SCAN (0x02)
E_JENNET_ACTIVE_SCAN (0x03)
E_JENNET_WAITING_FOR_ACTIVE_SCAN (0x04)
E_JENNET_ASSOCIATE (0x05)
E_JENNET_ASSOCIATE_SKIP_ESTABLISH_ROUTE (0x06)
E_JENNET_WAITING_FOR_ASSOCIATE (0x07)
E_JENNET_WAITING_FOR_ASSOCIATE_SKIP_ESTABLISH_ROUTE (0x08)
E_JENNET_START_COORD (0x09)
E_JENNET_START_COORD_SKIP_ESTABLISH_ROUTE (0x0A)
E_JENNET_ESTABLISH_ROUTE (0x0B)
E_JENNET_WAITING_FOR_ESTABLISH_ROUTE (0x0C)
E_JENNET_RUNNING (0x0D)
E_JENNET_WAITING_FOR_BACKOFF (0x0E)
E_JENNET_SLEEP (0x0F)
u32Api_GetVersion
Description
This allows a stack version text string to be obtained.
The Jenie function u32Jenie_GetVersion() is used to gather information on the
stack versions. An extra text string of the version is available through
u32Api_GetVersion().
Parameters
eComponent Set to NETWORK_VERSION to return version data
psVersionInfo Pointer to structure which, if allocated, will hold the
supplementary version string
Returns
None
void vApi_RegBeaconNotifyCallback(
trBeaconNotifyCallback prCallback);
Description
This function registers a user-defined callback function that will be invoked when a
beacon is received. This provides an opportunity for the application to either collect
information about other nodes in the vicinity or prevent the stack from joining
particular parents (by ignoring selected beacons).
The prototype for the callback function is detailed below.
Parameters
prCallback Pointer to callback function
Returns
None
Callback Function
Description
This user-defined callback function is invoked on receipt of a beacon. It can delete the beacon
and extract data from it. If forcing the shape of the network, only beacons from target parents
should be accepted. The beacons can also be saved for possible load balancing activity later.
The execution time of this function should be kept to a minimum.
Parameters
*psBeaconInfo Pointer to the received beacon - for tsScanElement structure, see
Appendix C.
u32NetworkID Network Application ID from beacon
u16ProtocolVersion Stack version from beacon
Returns
TRUE Accept the beacon for sorting
FALSEDelete the beacon
vApi_RegLocalAuthoriseCallback
void vApi_RegLocalAuthoriseCallback(
trAuthoriseCallback prCallback);
Description
This function registers a user-defined callback function that will be invoked when a
node attempts to join the Co-ordinator or a Router. The function provides an
opportunity for the application to prevent potential child nodes from accessing the
network and can be used to force nodes onto other adjacent parents or networks.
Parameters
prCallback Pointer to callback function
Returns
None
Callback Function
Description
This user-defined callback function provides the opportunity to block nodes with specific IEEE/
MAC addresses from joining as children. The passed IEEE/MAC address can be compared
with a list of permitted or forbidden addresses, and then accepted or rejected accordingly. A
rejected node will then attempt to join the network again, until it finds a parent node which
accepts its join request.
Parameters
*psAddr Pointer to IEEE/MAC address
Returns
TRUE Joining process continues
FALSEJoining is denied
void vApi_RegNwkAuthoriseCallback(
trAuthoriseCallback prCallback);
Description
This function registers a user-defined callback function that will be invoked when a
node attempts to join the network. This event only occurs on the Co-ordinator and
provides an opportunity for the application to prevent the joining node from accessing
the network. This mechanism can be used to force nodes onto other adjacent
networks.
Parameters
prCallback Pointer to callback function
Returns
None
Callback Function
Description
This user-defined callback function provides the opportunity to block nodes with specific IEEE/
MAC addresses from joining the network. The Co-ordinator receives the passed IEEE/MAC
address which can be compared with a list of permitted or forbidden addresses, and then
accepted or rejected accordingly. The rejected node will then attempt to join a network again,
until it finds a network which accepts its join request.
Parameters
*psAddr Pointer to the IEEE/MAC address
Returns
TRUE Joining process continues
FALSEJoining is denied
vApi_RegScanSortCallback
void vApi_RegScanSortCallback(
trSortScanCallback prCallback);
Description
This function registers a user-defined callback function that will be invoked when a
network scan completes. Access to the scan list is provided so that the application
can change the order in which the stack attempts to associate with potential parents.
Parameters
prCallback Pointer to callback function
Returns
None
Callback Function
Description
This user-defined callback function provides the opportunity to over-ride the default operation
of the stack and customise the beacon sort algorithm to obain a preferred order of association
attempts. The function is called on completion of an active scan. The stack attempts to
associate with the first entry in the list then steps through the list until an association is
successful. If none are successful, the active scan is re-started.
To delete beacons, use the vApi_RegBeaconNotifyCallback() function and return FALSE to
ignore specific beacons.
The execution time of this function should be kept to a minimum.
Parameters
*pasScanResult Pointer to (input) array of scan results containing suitable parents -
for tsScanElement structure, see Appendix C.
u8ScanListSize Number of suitable parents in the scan results array
*pau8ScanListOrder Pointer to (output) array of uint8 indicating the sorted order of
potential parents from most desirable to least desirable parent
(e.g. 3, 4, 1, 6, 0, 2, 5, 7) - the integers correspond to the positions of
the parents in the initial scan results (*pasScanResult)
Returns
TRUE Control returned to application and scanning process stopped
FALSEControl returned to stack and scan process resumed
The function should normally return FALSE unless the scan process is to be aborted.
The JenNet parameters are detailed in the tables below, according to the node type(s)
to which they apply.
Co-ordinator Parameters
General Parameters
gScanChannels Bitmap (32 bits) of the set of chan- 0x07FFF800 0x00000800 -0x07FFF800
nels to consider when performing an (All Channels)
auto-scan of the 2.4-GHz band for a (Bit 11 set ⇒ Ch 11,
suitable channel to use. The Co- Bit 12 set ⇒ Ch 12,...)
ordinator will select the quietest
channel from those available (auto-
scan must have been enabled via
gChannel.). Other node types will
scan the possible channels to
search for network.
Revision History
1.1 21-Feb-2008 JPI function lists inserted and minor modifications made
1.6 05-June-2009 Updated with JenNet API and other minor corrections
1.7 27-Aug-2009 Updated with minor corrections and new LQI appendix
1.8 17-Mar-2010 Modified for JN5148, JPI function descriptions modified/updated and
various other updates/corrections made
Jennic Ltd
Furnival Street
Sheffield
S1 4QT
United Kingdom
For the contact details of your local Jennic office or distributor, refer to the Jennic web site: