Freescale Semiconductor
Technical Information Center, CH370
1300 N. Alma School Road
Chandler, Arizona 85224
+1-800-521-6274 or +1-480-768-2130
support@freescale.com
Freescale Semiconductor Japan Ltd.
Headquarters
ARCO Tower 15F
1-8-1, Shimo-Meguro, Meguro-ku,
Tokyo 153-0064, Japan
0120 191014 or +81 3 5437 9125
support.japan@freescale.com
Asia/Pacific:
Freescale Semiconductor Hong Kong Ltd.
Technical Information Center
2 Dai King Street
Tai Po Industrial Estate
Tai Po, N.T., Hong Kong
+800 2666 8080
support.asia@freescale.com
For Literature Requests Only:
Freescale Semiconductor Literature Distribution Center
P.O. Box 5405
Denver, Colorado 80217
1-800-521-6274 or 303-675-2140
Fax: 303-675-2150
LDCForFreescaleSemiconductor@hibbertgroup.com
Information in this document is provided solely to enable system and software implementers to use
Freescale Semiconductor products. There are no express or implied copyright licenses granted
hereunder to design or fabricate any integrated circuits or integrated circuits based on the information
in this document.
Freescale Semiconductor reserves the right to make changes without further notice to any products
herein. Freescale Semiconductor makes no warranty, representation or guarantee regarding the
suitability of its products for any particular purpose, nor does Freescale Semiconductor assume any
liability arising out of the application or use of any product or circuit, and specifically disclaims any
and all liability, including without limitation consequential or incidental damages. “Typical” parameters
that may be provided in Freescale Semiconductor data sheets and/or specifications can and do vary
in different applications and actual performance may vary over time. All operating parameters,
including “Typicals”, must be validated for each customer application by customer’s technical
experts. Freescale Semiconductor does not convey any license under its patent rights nor the rights
of others. Freescale Semiconductor products are not designed, intended, or authorized for use as
components in systems intended for surgical implant into the body, or other applications intended to
support or sustain life, or for any other application in which the failure of the Freescale Semiconductor
product could create a situation where personal injury or death may occur. Should Buyer purchase
or use Freescale Semiconductor products for any such unintended or unauthorized application,
Buyer shall indemnify and hold Freescale Semiconductor and its officers, employees, subsidiaries,
affiliates, and distributors harmless against all claims, costs, damages, and expenses, and
reasonable attorney fees arising out of, directly or indirectly, any claim of personal injury or death
associated with such unintended or unauthorized use, even if such claim alleges that Freescale
Semiconductor was negligent regarding the design or manufacture of the part.
ARM is the registered trademark of ARM Limited. ARM7TDMI-S is the trademark of ARM Limited.
IAR Systems, IAR Embedded Workbench, C-SPY, visualSTATE, From Idea to Target, IAR KickStart
Kit, IAR PowerPac, IAR YellowSuite, and IAR are trademarks or registered trademarks owned by IAR
Systems AB.
Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other
product or service names are the property of their respective owners.
This guide provides a description of the Freescale MC1322x Simple Media Access Controller (MC1322x
SMAC).
Audience
This document is intended for application developers building IEEE 802.15.4 PHY compliant wireless
applications.
The MC1322x SMAC is incorporated in the Freescale BeeKit Wireless Connectivity Toolkit. The
incorporation of the MC1322x SMAC into BeeKit makes it easier for users to employ and customize the
MC1322x SMAC and associated applications.
The MC1322x SMAC is not the same SMAC used for the MC1319x and MC1321x. The primary
differences are as follows:
•MC1322x SMAC does not have blocking functions
•MC1322x SMAC has a new Radio Management module which allows management of multiple
messages depending on the application needs
•MC1322x file and directory structure are different
•MC1322x API is different
Organization
This document is organized into three (3) chapters.
Chapter 1MC1322x SMAC Introduction — This chapter introduces the MC1322x SMAC
features and functionality.
Chapter 2MC1322x SMAC Software Architecture — This chapter describes the MC1322x
SMAC software architecture.
Chapter 3MC1322x SMAC Primitives — This chapter provides a detailed description of
MC1322x SMAC primitives.
Revision History
The following table summarizes revisions to this document since the previous release. (Rev 1.6)
Revision History
LocationRevision
Chapter 3Added new function
Freescale Semiconductoriii
MC1322x SMAC Reference Manual, Rev. 1.7
Definitions, Acronyms, and Abbreviations
The following list defines the acronyms and abbreviations used in this document.
AESAdvanced Encryption Standard
APIApplication Programming Interface
ASMAdvanced Security Module
BDM debuggerA debugger using the BDM interface for communication with the MCU. An
example is the P&E BDM Multilink debugger for HCS08
S19S - Record. 'S19' is the file extension used for the Freescale binary image format.
The S19 file encapsulates the binary image as a list of ASCII records. Each record
contains a length -, address -, data - and checksum field. The 16 bit address field
allows a memory space for up to 64 KB. The S19 can be generated with
CodeWarrior IDE and is the product from the linking process. S19 does not
contain additional information for a debugger (where to look for source files)
Safe Mode BootThe Embedded Bootloader boots up using safe default system values
SMACSimple Media Access Controller
ivFreescale Semiconductor
MC1322x SMAC Reference Manual, Rev. 1.7
Chapter 1
MC1322x SMAC Introduction
The Freescale MC1322x Simple Media Access Controller (MC1322x SMAC) is a simple ANSI C based
code stack available as sample source code. The MC1322x SMAC can be used for developing proprietary
RF transceiver applications using the Freescale MC1322x Platform in a Package (PiP). The MC1322x
SMAC is designed to work with the MC1322x MCUs. See Section 1.1, “Available Devices” for more
information.
The MC1322x SMAC is incorporated in the Freescale BeeKit Wireless Connectivity Toolkit. The
incorporation of the MC1322x SMAC into BeeKit makes it easier for users to employ and customize the
MC1322x SMAC and associated applications, see the MC1322x SMAC Demonstration Applications User’s Guide (22xSMACDAUG) for more information on these applications.
To use any of the existing applications available in the MC1322x SMAC, users must first generate the
applications as projects in a BeeKit solution. For more information about BeeKit, BeeKit Projects, and
BeeKit Solutions, refer to the BeeKit Wireless Connectivity Toolkit User’s Guide (BKWCTKUG) and the
BeeKit on-line help.
The following is a list of MC1322x SMAC based demonstration applications:
•Wireless UART
•Connectivity
•Accelerometer
•Low Power Bell
•Generic Application
•Simple ZTC
•Repeater
•Weather Station
•OTAP Programmer
For more details on running the MC1322x SMAC demonstration applications, refer to the MC1322x SMAC Demonstration Applications User’s Guide. (22xSMACDAUG)
For more details about the MC1322x device, refer to the appropriate MC1322x Reference Manual
(MC1322xRM) and/or Data Sheet (MC1322x).
MC1322x SMAC Reference Manual, Rev. 1.7
Freescale Semiconductor1-1
MC1322x SMAC Introduction
1.1Available Devices
The MC1322x family is available as two part numbers. These device types differ only in their ROM
contents, all other device hardware, performance, and specifications are identical:
•MC13224V - this is the original version and is the generic part type.
— The MC13224V is intended for most IEEE 802.15.4 applications including MAC-based,
ZigBee-2007 Profile 1, and ZigBee RF4CE targets.
— It has a more complete set of peripheral drivers in ROM.
•MC13226V - this is a more recent version and is provided specifically for ZigBee-2007 Profile 2
(Pro) applications. Only the onboard ROM image has been changed to optimize ROM usage for
the ZigBee Pro profile and maximize the amount of available RAM for application use.
— The IEEE MAC/PHY functionality has been streamlined to include only that functionality
required by the ZigBee specification. The MAC functionality is 802.15.4 compatible.
— For a typical application, up to 20 kbytes more of RAM is available versus the M13224V
— Some drivers present in the MC13224 ROM have been removed and these include the ADC,
LCDfont, and SSI drivers. These drivers are still available as library functions, but now
compile into the RAM space.
— The Low Level Component (LLC) functionality has also been streamlined for the ZigBee
specification
NOTE
•When running the Freescale IEEE 802.15.4 MAC (or a related stack) on
the MC1322x platform, neither beaconing or GTS are supported.
•See the MC1322x Reference Manual (Document No MC1322xRM), for
information on using applications on these devices.
1.2Features
•Compact footprint:
— Read Only - Code: ~5 Kb
— Read Only - Data: ~0.5 Kb
— Read Write - Data: ~2.5 Kb
•No blocking functions. (A blocking function means that the calling function will not return until
the routine is complete. Non-blocking functions return immediately, allowing core processing to
occur concurrently. A callback mechanism is included with the non-blocking functions to allow
synchronization.)
•Very-low power, proprietary, bi-directional RF communication link
•ANSI C source code targeted for the MC1322x core
•Easy-to-use sample application included
•Support for AES128 security for the transmission/reception of secured data in the SMAC packets
1-2Freescale Semiconductor
MC1322x SMAC Reference Manual, Rev. 1.7
MC1322x SMAC Introduction
1.3MCU Resource Requirements
The MCU requires an external reference clock with allowed values from 13 MHz to 26 MHz.
Besides the memory resources, the SMAC uses the MACA module and thus all radio portions of the
MC1322x device. Depending on the demonstration, other resources are used such as the ADC, KBI, GPIO,
Timers and others.
1.4Introducing BeeKit
The Freescale BeeKit Wireless Connectivity Toolkit is a comprehensive Codebase of wireless networking
libraries, application templates, and sample applications. The BeeKit Graphical User Interface (GUI), part
of the BeeKit Wireless Connectivity Toolkit, allows users to create, modify, and update various wireless
networking implementations.
The MC1322x SMAC is released in an independent Codebase that is part of the Freescale BeeKit Wireless
Connectivity Toolkit. To create a project for the MC1322x SMAC, users must employ the BeeKit
Codebase that contains the MC1322x SMAC code. For more information on BeeKit, refer to the BeeKit Wireless Connectivity Toolkit User’s Guide (BKWCTKUG).
For more information on the Codebase as it applies to MC1322x SMAC, refer to the MC1322x SMAC Demonstration Application User's Guide. (22xSMACDAUG)
1.4.1BeeKit Concepts
This section highlights some basic BeeKit terms and concepts. Again, for a more detailed description of
BeeKit, refer to the BeeKit Wireless Connectivity Toolkit User’s Guide (BKWCTKUG).
CodebaseA group of source files, configuration files, and generation rules that serve as a
repository from which all BeeKit demos, templates, and other applications are
generated.
SolutionA group of projects which are linked to a specific folder within the file structure
of the computer and in this file structure, all other projects will generate their own
folders.
BeeKit ProjectA specific group of files in a directory tree that BeeKit can export for the
developer. An XML Project File in the tree describes the content and organization
of the project..
XML Project FileA BeeKit generated XML file ready to import into CodeWarrior or IAR´s
Embedded Workbench IDE.
Figure 1-1 shows the folder structure of a typical project generated using MC1322x SMAC Codebase for
BeeKit.
Freescale Semiconductor1-3
MC1322x SMAC Reference Manual, Rev. 1.7
MC1322x SMAC Introduction
Figure 1-1. Example Project Folder Structure
1-4Freescale Semiconductor
MC1322x SMAC Reference Manual, Rev. 1.7
Chapter 2
MC1322x SMAC Software Architecture
This chapter describes the MC1322x SMAC software architecture. The MC1322x SMAC Codebase is
different than the S08 targeted SMAC Codebase. BeeKit can use the MC1322x SMAC codebase to create
projects to be compiled with the IAR Embedded Workbench IDE.
2.1MC1322x SMAC Block Diagram
The Freescale MC1322x is a Platform in a Package (PiP) which integrates an RF transceiver modem,
MCU, AES ciphering and is fully compliant with the IEEE 802.15.4 standard. The MC1322x SMAC uses
its advanced, integrated functionality to provide a simple and high performance software package for IEEE
802.15.4 PHY wireless connectivity.
Figure 2-1 shows the MC1322x SMAC block diagram and the various MC1322x SMAC software
components. It is important to note the optional MC1322x SMAC modules:
•Security Module
•Over The Air Programmer (OTAP) Module
Figure 2-1. MC1322x SMAC Block Diagram
Freescale Semiconductor2-1
MC1322x SMAC Reference Manual, Rev. 1.7
MC1322x SMAC Software Architecture
Security, and OTAP modules and their APIs are included in the BeeKit project when the following
MC1322x SMAC BeeKit properties are set to True:
•Security Enabled
•OTAP Enabled
An API is implemented in the MC1322x SMAC as a C header file (.h) that allows access to the code. The
code includes the API to specific functions.
2.2Hardware Support
This section describes the MC1322x SMAC hardware support
The MC1322x SMAC only supports the Freescale MC1322x transceivers and the MC1322x SMAC
projects only support the following Freescale development boards:
•MC1322x Sensor Node (MC13224 and MC13226)
•MC1322x Network Node (MC13224 and MC13226)
•MC1322x Low Power Node (MC13224 only)
•MC1322x USB (MC13224 only)
The changes required in the software to support any of the Freescale transceivers are generated
automatically by BeeKit after exporting a solution with the projects correctly configured. For more
information on exporting projects, see the BeeKit Wireless Connectivity Toolkit User’s Guide
(BKWCTKUG) and the BeeKit on-line help.
2.3Optional Modules
2.3.1OTAP Module
The Over the Air Programmer (OTAP) application allows users to update a board’s FLASH remotely
without a physical connection. Given an OTAP enabled application and an OTAP programmer, users can
replace an existing application on a board with a new application. Two boards are required for the OTAP
application:
•One board used as the OTAP Programmer
•One board used as the OTAP-enabled target
Freescale recommends that both of the images to be flashed are OTAP-enabled applications.
The following summarizes what users will accomplish with the OTAP application:
•On the OTAP Programmer Board:
— Download and run the OTAP Programmer software
— Download an OTAP-enabled application via the UART.
– The downloaded application must have its OTAP module property enabled when the project
is generated in BeeKit
— Any of the MC1322x development boards can be used as the OTAP Programmer
2-2Freescale Semiconductor
MC1322x SMAC Reference Manual, Rev. 1.7
MC1322x SMAC Software Architecture
•OTAP-enabled target Board (The board having its firmware updated.)
— Download and run an OTAP-enabled application on the board. The currently loaded
application will be replaced by the new application using the OTAP Programmer.
– The application being replaced must have its OTAP module property enabled when the
project is generated in BeeKit.
— Any of the MC1322x development boards can be used as an OTAP enabled target board.
2.3.2Security Module
The security module is a software component that allows the ciphering and deciphering of messages
through its API. This section describes the procedure for implementing security in a MC1322x SMAC
application.
The MC1322x SMAC security management module allows implementation of wireless security
mechanisms. The MC1322x SMAC security module defines all functions required to cipher and decipher
the messages to be sent or received with the MC1322x SMAC on the MC1322x transceiver. The cipher
process is executed by the ASM module which implements the AES algorithm. It can perform CTR, CBC,
and CCM. CCM is a combination of CTR and CBC. For further details about the security implemented on
22x SMAC and the MC1322x, see Annex B of the IEEE standard 802.15.4-2003.
To enable security features, the security module must first be initialized, then the key and counter must be
set. After that, plain/cipher text can be ciphered/deciphered.
NOTE
The resulting ciphered/deciphered text is put on the same buffer where the
plain text is provided, for CBC and CCM modes which generate Message
Authentication Code, the provided buffer must also allocate 16 extra bytes
for the MAC.
This section describes the MC1322x SMAC messages, their types, operations and states. Send and receive
are basic functions of the MC1322x SMAC and they are implemented as messages. Energy detection and
radio idle time out are also implemented as messages. That is why messages are the core of the MC1322x
SMAC and it is important to explain the messages in detail both in how are they structured and how they
are processed and interfaced.
Freescale Semiconductor2-3
MC1322x SMAC Reference Manual, Rev. 1.7
MC1322x SMAC Software Architecture
Messages are processed by the Radio Management module. The Radio Management module has a circular
queue with the messages that need to be processed as a FIFO structure. The messages are attended in the
same order as they arrive.
Messages are added to the message queue using the following functions:
•MCPSDataRequest (for TX messages)
•MLMERXEnableRequest (for RX messages)
•MLMEEnergyDetect (for ED messages)
These functions call the Radio Management handle_new_message function.
Because the messages are processed by their states, the process_radio_msg function must also be called
periodically to run the message state machine.
2.4.1Message Types
The MC1322x SMAC defines four types of messages:
•Reception (RX)
•Transmission (TX)
•Energy Detect (ED)
•Time out (TO)
These types of messages are directly related with radio operation. Messages types are defined at the
enumeration msg_type_t declared in the RadioManagement.h file. Each type of message has its own life
cycle. This cycle is defined by the different states that a message can take. The following code declared at
the RadioManagement.h file describes each message state:
Messages passed to the Radio Management module are in an initial state of “requested”. Then they are
commanded to the MACA module in the MC1322x PiP to request that the radio perform the indicated
command. Then the Radio Management module processes the messages depending on the MACA
interrupts. The general model for the Messages State Machine is shown in Figure 2-2.
Figure 2-2. General Message State Machine
2.4.3Message Constraints
Messages are not copied when they are attached to the messages queue. A pointer to the message is added
to the queue. An application developer must consider the following:
•Message data must not be modified during the period from putting the message in the message
queue until it is in a final state (The final state is any of the following states: action complete,
aborted or timeout occurs). Modifying data of a message before the message is on a final state
could cause a corrupted TX or RX.
•Message objects must be declared in a context such that they are not destroyed in the middle of
processing.
•Once a message goes to a final state, it is removed from the queue. If a message does not go to a
final state, the next message on the queue is not processed. For example, a reception message
without timeout does not allow the next message to be processed until the radio receives something
or the message is aborted.
•If a function (MCPSDataRequest, MLMERXEnableRequest or MLMEEnergyDetect) tries to add a message
to the queue and it is full, the return value will be the gFailNoResourcesAvailable_c error. When
calling this function, validate the return value to ensure that the message was added to the queue.
2-6Freescale Semiconductor
MC1322x SMAC Reference Manual, Rev. 1.7
MC1322x SMAC Software Architecture
The Radio Management module can catch and hold as many messages as the queue can hold at any given
time. The queue size is defined by the MAX_NUM_MSG declared in the RadioManagement.c file.
The process_radio_msg function must be called in order to process the messages. If this function is not
properly called, message processing will not work as expected. The application must periodically call
process_radio_msg at least until the message queue is empty.
2.5MC1322x SMAC Data Types
The following list shows the fundamental data types and the naming convention used in MC1322x SMAC:
uint8_tUnsigned 8 bit definition
uint16_tUnsigned 16 bit definition
uint32_tUnsigned 32 bit definition
int8_tSigned 8 bit definition
int16_tSigned 16 bit definition
int32_tSigned 32 bit definition
Usage
These data types are used in the MC1322x SMAC project as well as in the applications projects. They are
defined in the typedef.h file.
2.5.1message_t
This type defines a structure to store the messages information. It is located in the RadioManagement.h file
and is defined as follows:
u8StatusThe status of the message, it is formed by three bits for the message type and 5 bits
for the message state, this is defined with the msg_status_t type. There are four
types of messages: TX, RX, Time Out and Energy Detect. The application must
not write to this member, it is initialized when the message is passed to
MCPSDataRequest, MLMERXEnableRequest or MLMEEnergyDetect function
and updated by the process_radio_msg function.
* pu8Buffer A pointer to the data buffer to transmit or receive.
Freescale Semiconductor2-7
MC1322x SMAC Reference Manual, Rev. 1.7
MC1322x SMAC Software Architecture
u8BufSize Depending on the type of message this field means: the length of the buffer to be
transmitted; the maximum bytes to receive, at the end of the reception this field
stores the number of bytes received; the channel where the ED must be assessed.
cbDataIndicationA pointer to the function that will be called when a message is completed, it can
be NULL
Usage
This data type is used by an application as follows:
1. The application declares as many message_t global variables as messages are required. For
example, the application can declare one for TX and one for RX
2. The application creates one data buffer for each message using the smac_pdu_size macro; for
example if the TX message will have 18 bytes of data the buffer would be declared as uint8_t
data[smac_pdu_size(18)];
3. The application initiates the message using the MSG_INIT macro. This macro is used as follow:
MSG_INIT([the message], [pointer to the data buffer], [callback pointer]); MSG_INIT is defined
in RadioManagement.h as:
/* Process messages in the queue */
process_radio_msg();
...
/* Put in the queue a message to be transmitted */
if([Need to transmit a message]){
MCPSDataRequest(&a_TX_msg);
}
...
if([Need to receive a message]){
/* Put in the queue an RX message to put the transceiver in reception */
MLMERXEnableRequest(&a_RX_msg, TIME_OUT);
}
...
}
}
MC1322x SMAC Software Architecture
The following code snippets examples can be used for application development:
Validates if a TX message is complete:
((MSG_[Type of message]_ACTION_COMPLETE_SUCCESS == [message name].u8Status.msg_state) ||
(MSG_[Type of message]_ACTION_COMPLETE_FAIL == [message name].u8Status.msg_state))
This macro obtains the message type:
get_pmsg_type([pointer to the message])
This macro reads a message state:
get_pmsg_state([pointer to the message])
This macro reads a message buffer:
tx_pmsg_payload_buffer([Pointer to the message], [Position in the buffer])
This macro sets a message size:
set_pmsg_size([Pointer to the message], [Size in bytes])
Freescale Semiconductor2-9
MC1322x SMAC Reference Manual, Rev. 1.7
MC1322x SMAC Software Architecture
2-10Freescale Semiconductor
MC1322x SMAC Reference Manual, Rev. 1.7
Chapter 3
MC1322x SMAC Primitives
The following sections provide a detailed description of MC1322x SMAC primitives and common data
types associated with the three MC1322x SMAC APIs.
3.1Common Data Types
This section highlights common data types used at MC1322x SMAC code.
3.1.1callback_t
This is the type defined for general callbacks, that is a function that is that is passed as an argument to other
code. It allows the MC1322x SMAC API to call a subroutine (or function) defined in the application layer.
This type is defined for void functions that do not receive parameters.
typedef void(*callback_t)(void);
This type is used at MLMEHibernateRequest, MLMEDozeRequest, MLMEScanRequest functions and
also at objects of type message among others.
3.1.2FuncReturn_t
This is the most common return type at the MC1322x SMAC functions. FuncReturn_t is an enumeration
defined as follows:
BuckRegStateThe following arguments determine the required configuration of the buck
regulator:
BUCK_DISABLE
BUCK_BYPASS
BUCK_ENABLE
Returns
NONE
3-2Freescale Semiconductor
MC1322x SMAC Reference Manual, Rev. 1.7
MC1322x SMAC Primitives
Usage
Call ConfigureBuckRegulator with the required parameters.
NOTE
Do not enable the buck regulator when the operating voltage is lower than
2.5 volts. See the MC1322x Reference Manual for more details.
3.2.2DRVConfigureRTC
This primitive allows configuring the Real Time Clock (RTC) to call back a function with a rate defined
by the RTC using the indicated reference clock.
mTimingRefThis argument indicates to reference clock to be used, it could be:
– gTimerRef_2Khz_c or
– gTimerRef_32Khz_c
mTimeoutTime out referenced to the main clock. The value is on RTC ticks.
pfUserCallbackFnIs the pointer to the function that must be executed.
Returns
gFailOutOfRange_cIf mTimingRef is not a valid reference or pfUserCallbackFn is equal to
NULL.
gFailNoValidCondition_c If the hardware does not get configured after some retries.
gSuccess_c If pfUserCallbackFn was successfully associated with the RTC interrupt.
gFail_cIf it was not possible to associate pfUserCallbackFn with the RTC
interrupt.
Usage
Call DRVConfigureRTC with the required parameters.
3.2.3MCPSDataRequest
This data primitive is used to send a packet.
Prototype
FuncReturn_t MCPSDataRequest (message_t *msg);
Freescale Semiconductor3-3
MC1322x SMAC Reference Manual, Rev. 1.7
MC1322x SMAC Primitives
Arguments
msgPointer to the message to be transmitted.
Returns
gFailNoResourcesAvailable_c When there is no space in the messages queue.
gSuccess_cWhen the message can be added to the message queue.
Usage
•The application creates a message object
•The application associates a buffer to be transmitted with such message object
•Calls MCPSDataRequest() passing the message as parameter. Success response means that the
message has been added to the message queue, to validate the successful transition of the message
check the [msg].u8Status.msg_state
•Ensure that the process_radio_msg() is called because this function processes the pending
messages
This function does not perform blocking which is different than previous SMAC versions.
NOTE
Consider all the possible messages states as explained in chapter two to
implement the proper logic. Example, if the transmission was not successful
the application may want to transmit again like in the following code:
...
if(MSG_TX_ACTION_COMPLETE_FAIL == [The TX message].u8Status.msg_state) {
MCPSDataRequest([Pointer to the TX message]);
}
...
3.2.4MLMEDozeRequest
Doze request allow the user to put the SoC Doze Mode. Review the appropriate MC1322x Reference
Manual for details regarding low power modes.
gFailNoValidCondition_cWhen there is no wakeup source configured.
gSuccess_cIf the action is performed.
Usage
•Configures a wakeup source using MLMESetWakeupSource
•Ensure there is and assigned interrupt handler if needed (CrmAssignHandler can be used)
•Call MLMEDozeRequest
3.2.5MLMEEnergyDetect
This call starts an energy detect (ED)/ Clear Channel Assessment (CCA) cycle and returns the energy value
for a given channel. This function receives a message as a parameter and shall be treated similar to a TX
or RX message. When an ED message goes to a successful final state, the energy detect value can be read
from the data buffer of the message. To properly process an ED message as well as a TX or RX message,
process_radio_msg must be periodically called, at least until all the messages in the message queue are
empty.
Energy detect values range from 0x00 to 0xFF.
0x00The channel has practically no activity
0xFFThe channel has heavy traffic and is very busy
u8channelThe channel to be assessed. Valid values are from gChannel11_c to
gChannel26_c.
Returns
gFailOutOfRange_cIf msg is a NULL value.
gFailNoResourcesAvailable_c When there is no space in the messages queue.
gSuccess_c When the message can be added to the message queue.
Usage
•Create a message object
•Associate a buffer with such message object, this buffer will used to store the energy detect value.
Use the macro MSG_INIT
Freescale Semiconductor3-5
MC1322x SMAC Reference Manual, Rev. 1.7
MC1322x SMAC Primitives
•Set the message type to energy detect by using [msg].u8Status.msg_type = ED;
•Call MLMEEnergyDetect() passing the message and the channel to be asses as parameters.
Success response means that the message has been added to the message queue, to validate the
successful transition of the message check the [msg].u8Status.msg_state
•Ensure that the process_radio_msg() is called since this function processes the pending messages
•When the message is on a MSG_ED_ACTION_COMPLETE_SUCCESS state, read the energy
detect value at [msg].pu8Buffer->u8Data[0].
This function does not perform blocking which is different than previous SMAC versions.
NOTE
To perform energy detect on two or more channels use the
MLMEScanRequest function. See the MLMEScanRequest description for
more details.
3.2.6MLMEGetChannelRequest
This function returns the current channel, if an error is detected it returns 255.
Prototype
uint8_t MLMEGetChannelRequest (void);
Arguments
None.
Returns
gChannel11_c to gChannel26_c The current RF channel.
0xFFIf current channel could not be detected
Usage
Call MLMEGetPromiscuousMode.
3.2.7MLMEGetPromiscuousMode
This function returns the current state of promiscuous mode.
Prototype
bool_t MLMEGetPromiscuousMode(void);
Arguments
None.
3-6Freescale Semiconductor
MC1322x SMAC Reference Manual, Rev. 1.7
MC1322x SMAC Primitives
Returns
TRUEIf promiscuous mode is active.
FALSEIf promiscuous mode is inactive.
Usage
Call MLMEGetPromiscuousMode.
3.2.8MLMEGetRficVersion
This function is used to read the version number of different hardware and software modules inside the
MC1322x.
EntityThe module for which the version is required. The actual possible values are:
– HW_MACA_MC1322X_ID
– SW_SMAC_VERSION
– SW_BOOTSTRAP_VERSION
BufferA pointer to the buffer where the version will be written.
Returns
gFailOutOfRange_cIf the requested Entity is not part of the stored ones.
gSuccess_cIf the action is performed.
Usage
•Declares a variable to store the version.
•Calls the MLMEGetRficVersion() passing the required Entity identifier and the pointer to store the
version.
3.2.9MLMEHibernateRequest
This call places the radio into Hibernate mode. Refer to the MC1322x Reference Manual for more
information on the operation modes. This low power mode retains the 96Kb of RAM. If no fail is returned,
gSuccess_c is returned after the system wakes up.
u8ReturnValueA pointer to a 8 bit value where the LQI value will be stored.
Returns
gSuccess_cThis function always return gSuccess_c.
3-8Freescale Semiconductor
MC1322x SMAC Reference Manual, Rev. 1.7
MC1322x SMAC Primitives
Usage
Simply calls the MLMELinkQuality () then read the LQI value at u8ReturnValue.
NOTE
To get a reliable value from this function, at least one reception must occur
before calling it. The LQI value will keep its value until a new message is
received.
3.2.11MLMEPAOutputAdjust
This function adjusts the output power of the transmitter. Table 3-1 shows the output power at the antenna,
minimum (0x00) to maximum (0x11).
gFailOutOfRange_cIf u8Power exceeds the maximum power value (0x11).
gFailNoValidCondition_cIf the requested power value in conjunction with the actual channel and external
power amplifier (enabled/disabled) do not match a valid configuration.
gSuccess_cIf the action is performed.
Usage
This function can be called with an argument between 0x00 and 0x12. Tab le 3-1 shows these values.
Tabl e 3-1. U8PaValu e
u8Power
0x00-30 dBmYes
0x01-28 dBmYes
0x02-27 dBmYes
0x03-26 dBmYes
0x04-24 dBmYes
0x05-21 dBmYes
Typical Output Power
1322x-SRB (dBm)
Use for Power
Lock Mode
Freescale Semiconductor3-9
0x06-19 dBmYes
0x07-17 dBmYes
0x08-16 dBmNo
MC1322x SMAC Reference Manual, Rev. 1.7
MC1322x SMAC Primitives
Table 3-1. U8PaValue (continued)
0x09-15 dBmNo
0x0A-11 dBmNo
0x0B-10 dBmNo
0x0C-4.5 dBmYes
0x0D-3 dBmNo
0x0E-1.5 dBmNo
0x0F-1 dBmNo
0x101.7 dBmNo
0x113 dBmNo
3.2.12MLMEPHYResetIndication
This is an empty function that must be filled by the user, it is called by the MLMEPHYSoftReset, before
resetting the device.
Prototype
void MLMEPhyResetIndication(void);
Arguments
None
Returns
void
Usage
Fills the logic for this function or leaves it void.
3.2.13MLMEPHYSoftReset
The MLMEPHYSoftReset function is called to perform a soft reset to the SoC. This function differs from
previous SMAC where just the radio is reset.
Prototype
void MLMEPHYSoftReset(void);
Arguments
None
3-10Freescale Semiconductor
MC1322x SMAC Reference Manual, Rev. 1.7
MC1322x SMAC Primitives
Returns
None
Usage
Simply calls the MLMEPHYSoftReset () function directly.
NOTE
This function resets the complete MC1322x PiP. The behavior is the same
as a power on reset.
3.2.14MLMEPHYXtalAdjust
This function adjusts the external oscillator supply by a trim value. For more information about the trim
value, see the MC1322x Reference Manual and Data Sheet.
u8CorseTrim8 bit value representing the coarse trim value to the oscillator. Max value is 0x1f.
u8FineTrim8 bit value representing the fine trim value to the oscillator. Max value is 0x1f.
Returns
gFailOutOfRange_cIf TrimValue exceeds the maximum trim value.
gSuccess_cIf the action is performed.
Usage
Simply calls the MLMEMCXtalAdjust () function directly, passing the appropriate trim values.
3.2.15MLMERadioInit
This function initializes the Radio parameters.
Prototype
FuncReturn_t MLMERadioInit(void);
Arguments
None
Returns
gSuccess_c
Freescale Semiconductor3-11
MC1322x SMAC Reference Manual, Rev. 1.7
MC1322x SMAC Primitives
Usage
Use this function like a generic MCU initialization prior commanding the transceiver.
3.2.16MLMERXDisableRequest
Returns the radio to idle mode from receive mode. When there are not messages in the message queue the
transceiver is in idle state, in that case there is not need to call this function in order to force an idle state.
gFailNoValidCondition_cIf the argument message is not a RX message.
gFailOutOfRange_cIf the message is not currently allocated at the messages queue
gSuccess_cWhen the message was aborted or disabled.
Usage
Simply calls MLMERXDisableRequest () passing the message to be disabled as parameter.
NOTE
This function can be used to abort the reception of a message prior to a
timeout event or to disable the receiver after it was turned on without a
timeout.
3.2.17MLMERXEnableRequest
Adds a message to the messages queue in order to put the radio into receive mode on the selected channel.
This function specifies a message structure to hold a message not yet received. This function commands
the transceiver to reception mode.
msgPointer to the message where the received data will be stored.
timeoutTimeout value. After this time the transceiver will go to idle state if there is no
message reception. Use zero value for receive without a timeout. The timeout
value is given in MACA CLK ticks. If this is a 250 KHz frequency, then each
count on the Timeout value represents 4 micro seconds.
3-12Freescale Semiconductor
MC1322x SMAC Reference Manual, Rev. 1.7
MC1322x SMAC Primitives
Returns
{gFailNoResourcesAvailable_c} When there is no space in the messages queue.
{gSuccess_c}When the message can be added to the message queue.
Usage
•Create a message object
•Associate a buffer with such message object, this buffer will used to store the received data. Use
the macro MSG_INIT
•Set length to the maximum bytes to receive in that buffer, this can be done by accessing direct to
the message [msg].u8BufSize = [length] or using the macro set_rx_datasize([message],[length])
•Call MLMERXEnableRequest() passing the message as parameter. Success response means that
the message has been added to the message queue, to validate the successful transition of the
message check the [msg].u8Status.msg_state
•Ensure that the process_radio_msg() is called since this function processes the pending messages
This function does not perform blocking which is different than previous SMAC versions.
Notes
u32Timeout value of zero causes the receiver to never timeout and stay in receive mode until a data packet
is received or the MLMERXDisableRequest function is called. At those points, the radio returns to idle
mode.
NOTE
Consider all the possible messages states as explained in Chapter 2,
MC1322x SMAC Software Architecture, in order to implement the proper
message state handling logic. For instance, consider the following example
for handling of the different receive action messages states..
u16ChannelsA bit mapped mask indicating which channels are going to be scanned, LSB
corresponds to gChannel11_c while MSB corresponds to gChannel26_c.
cbFnA callback function to notify that the scan has finished, this callback function
receive the best channel as argument. The best channel will be the one with the
lowest energy detect reading from the selected set at u16Channels.
Returns
gSuccess_c
Usage
Call this function with the callback function used to notify the processing finish. The energy values per
channel are stored at the global array u8ScanValPerChann each element in the array corresponds to each
channel. u8ScanValPerChann[CHANNEL11] is the energy value at channel 11 while
u8ScanValPerChann[CHANNEL26] is the energy value at channel 26.
NOTE
The values stored at u8ScanValPerChann are valid only if the specific
channel is active at u16Channels.
3.2.19MLMESetChannelRequest
This sets the actual frequency that the radio transmits and receives on.
SMAC appends 0xFF7E as the first two bytes of the packet to identify its own packets from other packets
in the same PHY layer. When promiscuous mode is off SMAC filters the received packets and just allows
those beginning with 0xFF7E; when promiscuous mode is on SMAC let pass all the messages beginning
or not with 0xFF7E. MLMESetPromiscuousMode allows setting or clearing the promiscuous mode.
u8ModeThis argument indicates which of the three wakeup sources must been activated,
any combination is possible: one, two, all, etc. (the flags that indicate each one of
the options are: gTimerWuEn_c, gRTCWuEn_c and gExtWuKBI_c).
u8KBIPolThis argument indicates the polarity at KBI which will awake the device.
Freescale Semiconductor3-15
MC1322x SMAC Reference Manual, Rev. 1.7
MC1322x SMAC Primitives
u8KBIEdgeThis argument indicates the edge at KBI which will awake the device.
Returns
gSuccess_c If a wakeup source is configured.
gFailNoValidCondition_cThe fail is return if there was no wakeup source defined at u8Mode.
Usage
Call MLMESetWakeupSource with the flags of each one of the desired wakeup sources.
3.2.22MLMETestMode
By employing this function, users can execute a test of the radio. Some basic test modes are necessary to
help MC1322x SMAC users evaluate their hardware. Test mode implements the following:
•Force_idle — Places the radio back into idle mode
•Continuos RX — Places the radio into receive mode and allows developers to look for any spectral
issues related to the RX section of the radio. Also, this mode can be used to measure the static RX
current for the radio
•Continuos TX — Allows an RF engineer to characterize the TX output power and look for issues
related to this CW mode
Prototype
void MLMETestMode (Test_Mode_t u8Mode);
Arguments
u8ModeThe test mode to start
– SMAC_TEST_MODE_IDLE
– SMAC_TEST_MODE_CONTINUOUS_TX_NOMOD
– SMAC_TEST_MODE_CONTINUOUS_TX_MOD.
Returns
void
Usage
Call the MLMETestMode() function with the packet to be transmitted and the mode to be executed. See
the notes for a list of modes implemented.
Notes
This following is a list of the modes implemented (defined as Macros):
•SMAC_TEST_MODE_IDLE: Forces the radio to back to the original IDLE mode.
3-16Freescale Semiconductor
MC1322x SMAC Reference Manual, Rev. 1.7
MC1322x SMAC Primitives
•SMAC_TEST_MODE_CONTINUOUS_TX_NOMOD: Sets the radio into continuous
unmodulated TX.
•SMAC_TEST_MODE_CONTINUOUS_TX_MOD: Sets the device to continuous modulated TX.
To stop continuous transmission simply call MLMETestMode(SMAC_TEST_MODE_IDLE).This action will set the
transceiver to idle state.
If this function is called in the middle of a TX or RX operation the corresponding message will be aborted.
3.3Security - Module API
This section describes the functions available for the application from the security module. The ciphering
process is base on AES-128 and supporting three operation modes:
•CTR
•CBC
•CCM
For further details about MC1322x Advanced Security Module, refer to the MC1322x Reference Manual.
3.3.1CipherConfigure
The CipherConfigure function sets the key, counter, and cipher mode.
u8CipherModeThe cipher mode to use (gCTRMode_c, gCBCMode_c or gCCMMode_c).
pCipherKeyA pointer to the 128 bits key.
pCtrValueA pointer to the 128 counter value.
Returns
gFailTest_c CipherEngineInit has not been executed or self test failed.
gFailOutOfRange_cu8CipherMode is not a valid value.
gSuccess_cConfiguration action was performed
3.3.2CipherEngineInit
Call the CipherEngineInit function to initiate the security module. This function allows carrying out a self
test to verify encryption engine operation.
Function
FuncReturn_t CipherEngineInit(void)
Returns
gFailTest_c Cipher Engine Self Test failed.
gSuccess_cCipher Engine Self Test succeed.
Figure 3-1 shows the security CTR and CBC modes. CCM mode combines the CTR mode for protecting
the privacy of data and the CBC mode to generate a MAC to protect the data from unauthorized
modifications.
Figure 3-1. CTR and CBC Ciphering Modes
3-18Freescale Semiconductor
MC1322x SMAC Reference Manual, Rev. 1.7
MC1322x SMAC Primitives
3.3.3CipherMsg and CipherMsgU8
CipherMsg or CipherMsgU8 cipher a message in blocks of 16 bytes. The CipherMsg function uses
approximately 66 cycles to cipher 128 bits. For an external 24 MHz clock, this happens in approximately
5.5 µs. In the CTR and CCM modes, the cipher data is stored in the buffer that is received as a parameter.
When the function completes, the buffer of plain text contains the cipher text. For the CBC and CCM
modes, the MAC is written in the last 16 bytes of the buffer, then the u8BufferLenght must be 16 bytes
longer than the data size.
cipher_mode_t is an enumeration, cipher_key_t and ctr_value_t are structures defined at
SecurityMngmnt.h as it is shown:
Arguments
pu32CipherBufferA pointer to 32bit data buffer where the data to be ciphered is stored. The
ciphertext will be stored at the same buffer.
pu8CipherBufferA pointer to 8bit data buffer where the data to be ciphered is stored. The ciphertext
will be stored at the same buffer.
u8BufferLengthBuffer´s length in bytes.
Returns
gFailTest_c CipherEngineInit has not been executed or self test failed.
gFailOutOfRange_cOne or more of the following conditions were true:
– Buffer length exceeds the maximum value
– Buffer length is not a multiple of 128 bits
– Buffer length is zero
gFailCorruptedASM hardware does not respond.
gSuccess_cCiphering action was performed.
Freescale Semiconductor3-19
MC1322x SMAC Reference Manual, Rev. 1.7
MC1322x SMAC Primitives
3.3.4DecipherMsg and DecipherMsgU8
The DecipherMsg and DecipherMsgU8 routine allows decipher encrypted messages in CTR and CCM
modes. For the CBC and CCM modes, it authenticates the data through the authentication code value.
CipherMsg([Pointer to 32bit data buffer], [length of the buffer]);
...
DecipherMsg([Pointer to 32bit cipherdata buffer], [length of the buffer]);
...
CipherMsgU8([Pointer to 8bit data buffer], [length of the buffer]);
...
DecipherMsgU8([Pointer to 8bit cipherdata buffer], [length of the buffer]);
...
3.4OTAP - Module API
This section details the functions required to use the OTAP module from the application. Only one function
is currently provided. For more details about how an application uses the OTAP module, see the MC1322x SMAC Demonstration Applications User’s Guide (22xSMACDAUG).
3.4.1OTAP_data_indication_execute
OTAP_data_indication_execute must be called at the application data execution. This function identifies
an incoming messages that pretend to put the application in OTAP mode.
Prototype
void OTAP_execute(void)
Arguments
None
Returns
None
Usage
OTAP_data_indication_execute must be called to process received telegrams. The following example
code is taken from the repeater demo.
...
/************************************************************************************
* data_indication_execute function
*
* This function process an incoming message.
*
************************************************************************************/
void data_indication_execute(void)
{
if( ( (MSG_RX_TIMEOUT_FAIL == RX_msg.u8Status.msg_state) ||
The global variable gbOtapExecute controls the execution of the OTAP and
this variable is set or reset by OTAP module, it does not write to it.
3-22Freescale Semiconductor
NOTE
MC1322x SMAC Reference Manual, Rev. 1.7
MC1322x SMAC Primitives
3.4.3OTAP_Init
OTAP_Init must be called at the application data execution. This function identifies an incoming message
which pretends to put the application on OTAP mode.
Prototype
void OTAP_Init(message_t * pRxMsg)
Arguments
pRxMsgA message of RX type, OTAP will check the incoming data on this message, this
message can be the same RX message from the application or the application shall
copy the data from its buffer to the pRxMsg´s buffer, the easiest solution is to
share the RX message between the application and the OTAP module.
Returns
None
Usage
OTAP_Init must be called at the end of the initialization section as shown on the following sample code.
This section describes support functions included with the MC1322x SMAC Codebase, accessible through
the MC1322x.a library. For more details about module configuration and these functions, see the MC1322x Reference Manual (MC1322xRM).
3.5.1ConfigureRfCtlSignals
ConfigureRfCtlSignals the the functionality for RF signals: ANT1, ANT2, TXON and RXON.
This signals are also configured at the initialization based on the
gDualPortRFOperation_c property value.
3-24Freescale Semiconductor
MC1322x SMAC Reference Manual, Rev. 1.7
MC1322x SMAC Primitives
3.5.2SetEdCcaThreshold
SetEdCcaThreshold sets the threshold value for CCA which is the same threshold used to indicate a valid
ED value.
Prototype
void SetEdCcaThreshold(uint8_t u8CcaThreshold);
Arguments
u8CcaThresholdCCA and ED threshold value.
Returns
None
Usage
Call this function with TRUE or FALSE, depending on the desired mode.
...
SetEdCcaThreshold(0x40);
...
NOTE
If SetEdCcaThreshold is not called, the threshold value keeps its default
value 0x39.
3.5.3SetComplementaryPAState
SetComplementaryPAState enables (argument equals TRUE) or disables (argument equals FALSE) the
complementary PA.
Prototype
void SetComplementaryPAState(bool_t state);
Arguments
stateEnable or disable the complementary PA.
Returns
None
Freescale Semiconductor3-25
MC1322x SMAC Reference Manual, Rev. 1.7
MC1322x SMAC Primitives
Usage
Call this function with TRUE or FALSE, depending on the desired mode.
...
SetComplementaryPAState(FALSE);
...
NOTE
gEnableComplementaryPAOutput_c property is used in the BeeKit
Platform Editor to configure the complementary PA.
3.5.4SetDemulatorMode
SetDemulatorMode selects either Non-coherent Detect (NCD) or Differential Chip Detect (DCD) mode.
If the SetDemulatorMode option is not used, by default, the SMAC uses DCD.
Prototype
void SetDemulatorMode(DemTypes_t demodulator);
Arguments
demodulatorChooses the type of demodulator.
Returns
None
Usage
Call this function with NCD or DCD, depending on the desired mode.
...
SetDemulatorMode(NCD);
...
3-26Freescale Semiconductor
MC1322x SMAC Reference Manual, Rev. 1.7
MC1322x SMAC Primitives
3.5.5SetPowerLevelLockMode
SetPowerLevelLockMode enables (argument equals TRUE) or disables (argument equals FALSE) the PA
lock mode to be used when using an external PA.
Prototype
uint8_t SetPowerLevelLockMode(bool_t state);
Arguments
stateEnable or disable the PA Lock Mode.
Returns
gSuccess_cThe requested mode was set.
0xffThe requested mode was NOT set, due to an invalid condition.
Usage
Call this function with TRUE or FALSE, depending on the desired mode.
...
SetPowerLevelLockMode(FALSE);
...
NOTE
When setting Lock Mode the following conditions must be true:
•Current channel different than gChannel26_c
•Current power level must be one of the available levels (when using
Lock Mode) as shown in Tabl e 3-1.
3.5.6RadioInit
This function initializes the radio and it is called inside of the MLMERadioInit function. It is also used at
the application level in the SMAC Low Power Bell Tx demonstration application as part of the procedure
to set the low power modes.