Compare commits
22 Commits
ddba6725bb
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 7c650d6a95 | |||
| e322b295f2 | |||
| 9e41b69d33 | |||
| 5c43e31a24 | |||
| e224dc15c4 | |||
| 04aa49e13b | |||
| b6378ff0de | |||
| 581fea8b69 | |||
| 3c3af1ba04 | |||
| 1a7ca4e82f | |||
| 5fb0d50bb9 | |||
| 1c30a79e63 | |||
| 4cef0291a7 | |||
| 4d87e095e9 | |||
| 2317f458b6 | |||
| 8a3e35f311 | |||
| 51601be546 | |||
| 69de01e9b3 | |||
| bb9e195485 | |||
| d1afed99c5 | |||
| 22e88bc7f5 | |||
| d7f91ac9bb |
@@ -1,12 +1,13 @@
|
||||
name: CC2530 Zigbee Firmware Build
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main # Triggers the action when code is pushed to the main branch
|
||||
pull_request:
|
||||
branches:
|
||||
- main # Triggers the action for pull requests targeting the main branch
|
||||
workflow_dispatch:
|
||||
# push:
|
||||
# branches:
|
||||
# - main # Triggers the action when code is pushed to the main branch
|
||||
# pull_request:
|
||||
# branches:
|
||||
# - main # Triggers the action for pull requests targeting the main branch
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
82
.gitea/workflows/sdcc.yml
Normal file
82
.gitea/workflows/sdcc.yml
Normal file
@@ -0,0 +1,82 @@
|
||||
name: SDCC Build for CC2530
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
# push:
|
||||
# branches:
|
||||
# - main
|
||||
# pull_request:
|
||||
# branches:
|
||||
# - main
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest # Runs on the latest Ubuntu version available
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
github-server-url: ${{ vars.GIT_SERVER_URL }}
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y build-essential libgmp-dev libmpfr-dev libncurses-dev git subversion bison flex libboost-graph-dev gcc python3
|
||||
|
||||
# - name: Clone SDCC repository
|
||||
# run: |
|
||||
# git clone https://github.com/sdcc-team/sdcc.git
|
||||
# cd sdcc
|
||||
|
||||
- name: Checkout SDCC using SVN
|
||||
run: |
|
||||
# Use SVN to checkout SDCC at a specific revision
|
||||
# svn co -r [rev] svn://svn.code.sf.net/p/sdcc/code/trunk/sdcc
|
||||
svn co -r 9092 svn://svn.code.sf.net/p/sdcc/code/trunk/sdcc
|
||||
|
||||
- name: Modify incl.mk and Makefile.in
|
||||
run: |
|
||||
# Modify sdcc/device/lib/incl.mk to add the "huge" model
|
||||
sed -i 's/MODELS = small medium large/MODELS = small large huge/' sdcc/device/lib/incl.mk
|
||||
|
||||
# Modify sdcc/device/lib/Makefile.in to add the "model-mcs51-stack-auto" target
|
||||
sed -i 's/TARGETS += models small-mcs51-stack-auto/TARGETS += models model-mcs51-stack-auto/' sdcc/device/lib/Makefile.in
|
||||
|
||||
- name: Fix config.sub and config.guess for 8051
|
||||
run: |
|
||||
# Download config.sub and config.guess from a working version of the tools
|
||||
wget https://git.savannah.gnu.org/cgit/config.git/plain/config.sub -O sdcc/config.sub
|
||||
wget https://git.savannah.gnu.org/cgit/config.git/plain/config.guess -O sdcc/config.guess
|
||||
|
||||
|
||||
- name: Build SDCC
|
||||
run: |
|
||||
cd sdcc
|
||||
# Set CFLAGS to disable treating warnings as errors
|
||||
export CFLAGS="$CFLAGS -Wno-error"
|
||||
# ./configure --target=8051 --with-arch=8051 --prefix=/usr/local
|
||||
./configure --disable-gbz80-port --disable-z80-port --disable-ds390-port --disable-ds400-port --disable-pic14-port --disable-pic16-port --disable-hc08-port --disable-r2k-port --disable-z180-port --disable-sdcdb --disable-ucsim --prefix=/usr/local
|
||||
|
||||
make
|
||||
sudo make install
|
||||
|
||||
- name: Verify SDCC installation
|
||||
run: |
|
||||
sdcc --version # Verifies if SDCC was installed successfully
|
||||
|
||||
- name: Compile using Makefile
|
||||
run: |
|
||||
cd $GITHUB_WORKSPACE # Navigate to the root of your repo (where the Makefile is located)
|
||||
make # Run the make command to build the project using the Makefile
|
||||
|
||||
# - name: Upload compiled hex file
|
||||
# uses: actions/upload-artifact@v2
|
||||
# with:
|
||||
# name: cc2530-firmware
|
||||
# path: output.ihx # Replace with the actual output file name if different (e.g., .ihx)
|
||||
|
||||
- name: Clean up compiled files
|
||||
run: |
|
||||
cd $GITHUB_WORKSPACE # Navigate back to the project directory
|
||||
make clean # Run the 'make clean' command to delete the compiled files
|
||||
44
Makefile
44
Makefile
@@ -1,24 +1,38 @@
|
||||
# Path to Z-Stack SDK
|
||||
ZSTACK_DIR = ./include
|
||||
|
||||
# Include path for the Z-Stack SDK
|
||||
# INCLUDE_DIRS = -I$(ZSTACK_DIR)/Components/hal/CC2530 \
|
||||
# -I$(ZSTACK_DIR)/Components/zigbee
|
||||
INCLUDE_DIRS = -I$(ZSTACK_DIR)
|
||||
|
||||
# Compiler settings
|
||||
CC = msp430-elf-gcc # MSP430 compiler
|
||||
CFLAGS = -Wall -Os # Enable all warnings, Optimize for size
|
||||
LDFLAGS =
|
||||
LIBS = -lZStack -lhal # ZStack for Zigbee communication, lhal for Hardware Abstraction Layer library
|
||||
CC = sdcc # sdcc compiler
|
||||
CFLAGS = -mmcs51 -DSDCC $(INCLUDE_DIRS) # add include paths to compiler flags
|
||||
|
||||
SRCS = main.c zigbee_comm.c sensors/bme280.c sensors/wind_vane.c sensors/rain_gauge.c sensors/anemometer.c
|
||||
HEADERS = main.h zigbee_comm.h sensors/bme280.h sensors/wind_vane.h sensors/rain_gauge.h sensors/anemometer.h config.h
|
||||
OBJS = $(SRCS:.c=.o) # create a list of object files from the source files
|
||||
# Source files (all .c files in the directory)
|
||||
SRC=$(wildcard *.c)
|
||||
|
||||
all: main.elf
|
||||
# Headers
|
||||
HEADERS = main.h zigbee_comm.h sensors/bme280.h sensors/wind_vane.h sensors/rain_gauge.h sensors/anemometer.h config.h include/hal_types.h include/hal_defs.h include/hal_timer.h include/ZComDef.h include/OSAL.h include/i2c.h
|
||||
|
||||
main.elf: $(OBJS)
|
||||
$(CC) $(LDFLAGS) $(OBJS) $(LIBS) -o $@
|
||||
# Object files (replace .c with .o)
|
||||
OBJS = $(SRC:.c=.o)
|
||||
|
||||
# Output file
|
||||
OUTPUT=output.ihx
|
||||
|
||||
# Default target: compile and generate the hex file
|
||||
all: $(OUTPUT)
|
||||
|
||||
# Rule to build the output file
|
||||
$(OUTPUT): $(OBJS)
|
||||
$(CC) $(CFLAGS) $(OBJS) -o $(OUTPUT)
|
||||
|
||||
# Rule to build object files from source files
|
||||
%.o: %.c $(HEADERS)
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
# Clean generated files
|
||||
clean:
|
||||
rm -f main.elf $(OBJS)
|
||||
|
||||
# Optionally add a rule to flash your device (if applicable)
|
||||
# flash: main.elf
|
||||
# ./flash_tool main.elf # This is just a placeholder if needed
|
||||
rm -f $(OUTPUT) $(OBJS) *.asm *.lst *.sym
|
||||
33
Makefile.old
Normal file
33
Makefile.old
Normal file
@@ -0,0 +1,33 @@
|
||||
# Path to Z-Stack SDK
|
||||
ZSTACK_DIR = ./include
|
||||
|
||||
# Include path for the Z-Stack SDK
|
||||
# INCLUDE_DIRS = -I$(ZSTACK_DIR)/Components/hal/CC2530 \
|
||||
# -I$(ZSTACK_DIR)/Components/zigbee
|
||||
INCLUDE_DIRS = -I$(ZSTACK_DIR)
|
||||
|
||||
# Compiler settings
|
||||
CC = msp430-elf-gcc # MSP430 compiler
|
||||
# CFLAGS (C Compiler flags)
|
||||
CFLAGS = $(INCLUDE_DIRS) -Wall -O2 # Enable all warnings, Optimize for size
|
||||
LDFLAGS =
|
||||
LIBS = -lZStack -lhal # ZStack for Zigbee communication, lhal for Hardware Abstraction Layer library
|
||||
|
||||
SRCS = main.c zigbee_comm.c sensors/bme280.c sensors/wind_vane.c sensors/rain_gauge.c sensors/anemometer.c include/hal_timer.c
|
||||
HEADERS = main.h zigbee_comm.h sensors/bme280.h sensors/wind_vane.h sensors/rain_gauge.h sensors/anemometer.h config.h include/hal_types.h include/hal_defs.h include/hal_timer.h include/ZComDef.h include/OSAL.h include/i2c.h
|
||||
OBJS = $(SRCS:.c=.o) # create a list of object files from the source files
|
||||
|
||||
all: main.elf
|
||||
|
||||
main.elf: $(OBJS)
|
||||
$(CC) $(LDFLAGS) $(OBJS) $(LIBS) -o $@
|
||||
|
||||
%.o: %.c $(HEADERS)
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
clean:
|
||||
rm -f main.elf $(OBJS)
|
||||
|
||||
# Optionally add a rule to flash your device (if applicable)
|
||||
# flash: main.elf
|
||||
# ./flash_tool main.elf # This is just a placeholder if needed
|
||||
1821
include/OSAL.c
Normal file
1821
include/OSAL.c
Normal file
File diff suppressed because it is too large
Load Diff
361
include/OSAL.h
Normal file
361
include/OSAL.h
Normal file
@@ -0,0 +1,361 @@
|
||||
/******************************************************************************
|
||||
Filename: OSAL.h
|
||||
Revised: $Date: 2014-06-30 16:38:56 -0700 (Mon, 30 Jun 2014) $
|
||||
Revision: $Revision: 39297 $
|
||||
|
||||
Description: This API allows the software components in the Z-Stack to be
|
||||
written independently of the specifics of the operating system,
|
||||
kernel, or tasking environment (including control loops or
|
||||
connect-to-interrupt systems).
|
||||
|
||||
|
||||
Copyright 2004-2014 Texas Instruments Incorporated. All rights reserved.
|
||||
|
||||
IMPORTANT: Your use of this Software is limited to those specific rights
|
||||
granted under the terms of a software license agreement between the user
|
||||
who downloaded the software, his/her employer (which must be your employer)
|
||||
and Texas Instruments Incorporated (the "License"). You may not use this
|
||||
Software unless you agree to abide by the terms of the License. The License
|
||||
limits your use, and you acknowledge, that the Software may not be modified,
|
||||
copied or distributed unless embedded on a Texas Instruments microcontroller
|
||||
or used solely and exclusively in conjunction with a Texas Instruments radio
|
||||
frequency transceiver, which is integrated into your product. Other than for
|
||||
the foregoing purpose, you may not use, reproduce, copy, prepare derivative
|
||||
works of, modify, distribute, perform, display or sell this Software and/or
|
||||
its documentation for any purpose.
|
||||
|
||||
YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
|
||||
PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
||||
INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
|
||||
NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
|
||||
TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
|
||||
NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
|
||||
LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
|
||||
INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
|
||||
OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
|
||||
OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
|
||||
(INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
|
||||
|
||||
Should you have any questions regarding your right to use this Software,
|
||||
contact Texas Instruments Incorporated at www.TI.com.
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef OSAL_H
|
||||
#define OSAL_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/*********************************************************************
|
||||
* INCLUDES
|
||||
*/
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
#include "comdef.h"
|
||||
#include "OSAL_Memory.h"
|
||||
#include "OSAL_Timers.h"
|
||||
|
||||
#ifdef USE_ICALL
|
||||
#include <ICall.h>
|
||||
#endif /* USE_ICALL */
|
||||
|
||||
/*********************************************************************
|
||||
* MACROS
|
||||
*/
|
||||
#if ( UINT_MAX == 65535 ) /* 8-bit and 16-bit devices */
|
||||
#define osal_offsetof(type, member) ((uint16) &(((type *) 0)->member))
|
||||
#else /* 32-bit devices */
|
||||
#define osal_offsetof(type, member) ((uint32) &(((type *) 0)->member))
|
||||
#endif
|
||||
|
||||
#define OSAL_MSG_NEXT(msg_ptr) ((osal_msg_hdr_t *) (msg_ptr) - 1)->next
|
||||
|
||||
#define OSAL_MSG_Q_INIT(q_ptr) *(q_ptr) = NULL
|
||||
|
||||
#define OSAL_MSG_Q_EMPTY(q_ptr) (*(q_ptr) == NULL)
|
||||
|
||||
#define OSAL_MSG_Q_HEAD(q_ptr) (*(q_ptr))
|
||||
|
||||
#define OSAL_MSG_LEN(msg_ptr) ((osal_msg_hdr_t *) (msg_ptr) - 1)->len
|
||||
|
||||
#define OSAL_MSG_ID(msg_ptr) ((osal_msg_hdr_t *) (msg_ptr) - 1)->dest_id
|
||||
|
||||
/*********************************************************************
|
||||
* CONSTANTS
|
||||
*/
|
||||
|
||||
/*** Interrupts ***/
|
||||
#define INTS_ALL 0xFF
|
||||
|
||||
/*********************************************************************
|
||||
* TYPEDEFS
|
||||
*/
|
||||
#ifdef USE_ICALL
|
||||
typedef ICall_MsgHdr osal_msg_hdr_t;
|
||||
#else /* USE_ICALL */
|
||||
typedef struct
|
||||
{
|
||||
void *next;
|
||||
#ifdef OSAL_PORT2TIRTOS
|
||||
/* Limited OSAL port to TI-RTOS requires compatibility with ROM
|
||||
* code compiled with USE_ICALL compile flag. */
|
||||
uint32 reserved;
|
||||
#endif /* OSAL_PORT2TIRTOS */
|
||||
uint16 len;
|
||||
uint8 dest_id;
|
||||
} osal_msg_hdr_t;
|
||||
#endif /* USE_ICALL */
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8 event;
|
||||
uint8 status;
|
||||
} osal_event_hdr_t;
|
||||
|
||||
typedef void * osal_msg_q_t;
|
||||
|
||||
#ifdef USE_ICALL
|
||||
/* High resolution timer callback function type */
|
||||
typedef void (*osal_highres_timer_cback_t)(void *arg);
|
||||
#endif /* USE_ICALL */
|
||||
|
||||
/*********************************************************************
|
||||
* GLOBAL VARIABLES
|
||||
*/
|
||||
#ifdef USE_ICALL
|
||||
extern ICall_Semaphore osal_semaphore;
|
||||
extern ICall_EntityID osal_entity;
|
||||
extern uint_least32_t osal_tickperiod;
|
||||
extern void (*osal_eventloop_hook)(void);
|
||||
#endif /* USE_ICALL */
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
* FUNCTIONS
|
||||
*/
|
||||
|
||||
/*** Message Management ***/
|
||||
|
||||
/*
|
||||
* Task Message Allocation
|
||||
*/
|
||||
extern uint8 * osal_msg_allocate(uint16 len );
|
||||
|
||||
/*
|
||||
* Task Message Deallocation
|
||||
*/
|
||||
extern uint8 osal_msg_deallocate( uint8 *msg_ptr );
|
||||
|
||||
/*
|
||||
* Send a Task Message
|
||||
*/
|
||||
extern uint8 osal_msg_send( uint8 destination_task, uint8 *msg_ptr );
|
||||
|
||||
/*
|
||||
* Push a Task Message to head of queue
|
||||
*/
|
||||
extern uint8 osal_msg_push_front( uint8 destination_task, uint8 *msg_ptr );
|
||||
|
||||
/*
|
||||
* Receive a Task Message
|
||||
*/
|
||||
extern uint8 *osal_msg_receive( uint8 task_id );
|
||||
|
||||
/*
|
||||
* Find in place a matching Task Message / Event.
|
||||
*/
|
||||
extern osal_event_hdr_t *osal_msg_find(uint8 task_id, uint8 event);
|
||||
|
||||
/*
|
||||
* Count the number of queued OSAL messages matching Task ID / Event.
|
||||
*/
|
||||
extern uint8 osal_msg_count(uint8 task_id, uint8 event);
|
||||
|
||||
/*
|
||||
* Enqueue a Task Message
|
||||
*/
|
||||
extern void osal_msg_enqueue( osal_msg_q_t *q_ptr, void *msg_ptr );
|
||||
|
||||
/*
|
||||
* Enqueue a Task Message Up to Max
|
||||
*/
|
||||
extern uint8 osal_msg_enqueue_max( osal_msg_q_t *q_ptr, void *msg_ptr, uint8 max );
|
||||
|
||||
/*
|
||||
* Dequeue a Task Message
|
||||
*/
|
||||
extern void *osal_msg_dequeue( osal_msg_q_t *q_ptr );
|
||||
|
||||
/*
|
||||
* Push a Task Message to head of queue
|
||||
*/
|
||||
extern void osal_msg_push( osal_msg_q_t *q_ptr, void *msg_ptr );
|
||||
|
||||
/*
|
||||
* Extract and remove a Task Message from queue
|
||||
*/
|
||||
extern void osal_msg_extract( osal_msg_q_t *q_ptr, void *msg_ptr, void *prev_ptr );
|
||||
|
||||
#ifdef USE_ICALL
|
||||
extern ICall_Errno osal_service_entry(ICall_FuncArgsHdr *args);
|
||||
#endif /* USE_ICALL */
|
||||
|
||||
|
||||
/*** Task Synchronization ***/
|
||||
|
||||
/*
|
||||
* Set a Task Event
|
||||
*/
|
||||
extern uint8 osal_set_event( uint8 task_id, uint16 event_flag );
|
||||
|
||||
|
||||
/*
|
||||
* Clear a Task Event
|
||||
*/
|
||||
extern uint8 osal_clear_event( uint8 task_id, uint16 event_flag );
|
||||
|
||||
|
||||
/*** Interrupt Management ***/
|
||||
|
||||
/*
|
||||
* Register Interrupt Service Routine (ISR)
|
||||
*/
|
||||
extern uint8 osal_isr_register( uint8 interrupt_id, void (*isr_ptr)( uint8* ) );
|
||||
|
||||
/*
|
||||
* Enable Interrupt
|
||||
*/
|
||||
extern uint8 osal_int_enable( uint8 interrupt_id );
|
||||
|
||||
/*
|
||||
* Disable Interrupt
|
||||
*/
|
||||
extern uint8 osal_int_disable( uint8 interrupt_id );
|
||||
|
||||
|
||||
/*** Task Management ***/
|
||||
|
||||
#ifdef USE_ICALL
|
||||
/*
|
||||
* Enroll dispatcher registered entity ID
|
||||
*/
|
||||
extern void osal_enroll_dispatchid(uint8 taskid,
|
||||
ICall_EntityID dispatchid);
|
||||
|
||||
/*
|
||||
* Enroll an OSAL task to use another OSAL task's enrolled entity ID
|
||||
* when sending a message.
|
||||
*/
|
||||
extern void osal_enroll_senderid(uint8 taskid, ICall_EntityID dispatchid);
|
||||
|
||||
/*
|
||||
* Enroll entity ID to be used as sender entity ID for non OSAL task
|
||||
*/
|
||||
extern void osal_enroll_notasksender(ICall_EntityID dispatchid);
|
||||
#endif /* USE_ICALL */
|
||||
|
||||
/*
|
||||
* Initialize the Task System
|
||||
*/
|
||||
extern uint8 osal_init_system( void );
|
||||
|
||||
/*
|
||||
* System Processing Loop
|
||||
*/
|
||||
#if defined (ZBIT)
|
||||
extern __declspec(dllexport) void osal_start_system( void );
|
||||
#else
|
||||
extern void osal_start_system( void );
|
||||
#endif
|
||||
|
||||
/*
|
||||
* One Pass Throu the OSAL Processing Loop
|
||||
*/
|
||||
extern void osal_run_system( void );
|
||||
|
||||
/*
|
||||
* Get the active task ID
|
||||
*/
|
||||
extern uint8 osal_self( void );
|
||||
|
||||
|
||||
/*** Helper Functions ***/
|
||||
|
||||
/*
|
||||
* String Length
|
||||
*/
|
||||
extern int osal_strlen( char *pString );
|
||||
|
||||
/*
|
||||
* Memory copy
|
||||
*/
|
||||
extern void *osal_memcpy( void*, const void GENERIC *, unsigned int );
|
||||
|
||||
/*
|
||||
* Memory Duplicate - allocates and copies
|
||||
*/
|
||||
extern void *osal_memdup( const void GENERIC *src, unsigned int len );
|
||||
|
||||
/*
|
||||
* Reverse Memory copy
|
||||
*/
|
||||
extern void *osal_revmemcpy( void*, const void GENERIC *, unsigned int );
|
||||
|
||||
/*
|
||||
* Memory compare
|
||||
*/
|
||||
extern uint8 osal_memcmp( const void GENERIC *src1, const void GENERIC *src2, unsigned int len );
|
||||
|
||||
/*
|
||||
* Memory set
|
||||
*/
|
||||
extern void *osal_memset( void *dest, uint8 value, int len );
|
||||
|
||||
/*
|
||||
* Build a uint16 out of 2 bytes (0 then 1).
|
||||
*/
|
||||
extern uint16 osal_build_uint16( uint8 *swapped );
|
||||
|
||||
/*
|
||||
* Build a uint32 out of sequential bytes.
|
||||
*/
|
||||
extern uint32 osal_build_uint32( uint8 *swapped, uint8 len );
|
||||
|
||||
/*
|
||||
* Convert long to ascii string
|
||||
*/
|
||||
#if !defined ( ZBIT ) && !defined ( ZBIT2 ) && !defined (UBIT)
|
||||
extern uint8 *_ltoa( uint32 l, uint8 * buf, uint8 radix );
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Random number generator
|
||||
*/
|
||||
extern uint16 osal_rand( void );
|
||||
|
||||
/*
|
||||
* Buffer an uint32 value - LSB first.
|
||||
*/
|
||||
extern uint8* osal_buffer_uint32( uint8 *buf, uint32 val );
|
||||
|
||||
/*
|
||||
* Buffer an uint24 value - LSB first
|
||||
*/
|
||||
extern uint8* osal_buffer_uint24( uint8 *buf, uint24 val );
|
||||
|
||||
/*
|
||||
* Is all of the array elements set to a value?
|
||||
*/
|
||||
extern uint8 osal_isbufset( uint8 *buf, uint8 val, uint8 len );
|
||||
|
||||
/*********************************************************************
|
||||
*********************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* OSAL_H */
|
||||
642
include/OSAL_Memory.c
Normal file
642
include/OSAL_Memory.c
Normal file
@@ -0,0 +1,642 @@
|
||||
/**************************************************************************************************
|
||||
Filename: OSAL_Memory.c
|
||||
Revised: $Date: 2014-11-24 18:26:24 -0800 (Mon, 24 Nov 2014) $
|
||||
Revision: $Revision: 41234 $
|
||||
|
||||
Description: OSAL Heap Memory management functions. There is an Application Note that
|
||||
should be read before studying and/or modifying this module:
|
||||
SWRA204 "Heap Memory Management"
|
||||
|
||||
Copyright 2004-2010 Texas Instruments Incorporated. All rights reserved.
|
||||
|
||||
IMPORTANT: Your use of this Software is limited to those specific rights
|
||||
granted under the terms of a software license agreement between the user
|
||||
who downloaded the software, his/her employer (which must be your employer)
|
||||
and Texas Instruments Incorporated (the "License"). You may not use this
|
||||
Software unless you agree to abide by the terms of the License. The License
|
||||
limits your use, and you acknowledge, that the Software may not be modified,
|
||||
copied or distributed unless embedded on a Texas Instruments microcontroller
|
||||
or used solely and exclusively in conjunction with a Texas Instruments radio
|
||||
frequency transceiver, which is integrated into your product. Other than for
|
||||
the foregoing purpose, you may not use, reproduce, copy, prepare derivative
|
||||
works of, modify, distribute, perform, display or sell this Software and/or
|
||||
its documentation for any purpose.
|
||||
|
||||
YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
|
||||
PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
||||
INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
|
||||
NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
|
||||
TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
|
||||
NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
|
||||
LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
|
||||
INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
|
||||
OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
|
||||
OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
|
||||
(INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
|
||||
|
||||
Should you have any questions regarding your right to use this Software,
|
||||
contact Texas Instruments Incorporated at www.TI.com.
|
||||
**************************************************************************************************/
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Includes
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "comdef.h"
|
||||
#include "OSAL.h"
|
||||
#include "OSAL_Memory.h"
|
||||
#include "OnBoard.h"
|
||||
#include "hal_mcu.h"
|
||||
#include "hal_assert.h"
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Constants
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#define OSALMEM_IN_USE 0x8000
|
||||
#if (MAXMEMHEAP & OSALMEM_IN_USE)
|
||||
#error MAXMEMHEAP is too big to manage!
|
||||
#endif
|
||||
|
||||
#define OSALMEM_HDRSZ sizeof(osalMemHdr_t)
|
||||
|
||||
// Round a value up to the ceiling of OSALMEM_HDRSZ for critical dependencies on even multiples.
|
||||
#define OSALMEM_ROUND(X) ((((X) + OSALMEM_HDRSZ - 1) / OSALMEM_HDRSZ) * OSALMEM_HDRSZ)
|
||||
|
||||
/* Minimum wasted bytes to justify splitting a block before allocation.
|
||||
* Adjust accordingly to attempt to balance the tradeoff of wasted space and runtime throughput
|
||||
* spent splitting blocks into sizes that may not be practically usable when sandwiched between
|
||||
* two blocks in use (and thereby not able to be coalesced.)
|
||||
* Ensure that this size is an even multiple of OSALMEM_HDRSZ.
|
||||
*/
|
||||
#if !defined OSALMEM_MIN_BLKSZ
|
||||
#define OSALMEM_MIN_BLKSZ (OSALMEM_ROUND((OSALMEM_HDRSZ * 2)))
|
||||
#endif
|
||||
|
||||
#if !defined OSALMEM_LL_BLKSZ
|
||||
#if defined NONWK
|
||||
#define OSALMEM_LL_BLKSZ (OSALMEM_ROUND(6) + (1 * OSALMEM_HDRSZ))
|
||||
#else
|
||||
/*
|
||||
* Profiling the sample apps with default settings shows the following long-lived allocations
|
||||
* which should live at the bottom of the small-block bucket so that they are never iterated over
|
||||
* by osal_mem_alloc/free(), nor ever considered for coalescing, etc. This saves significant
|
||||
* run-time throughput (on 8051 SOC if not also MSP). This is dynamic "dead space" and is not
|
||||
* available to the small-block bucket heap.
|
||||
*
|
||||
* Adjust this size accordingly to accomodate application-specific changes including changing the
|
||||
* size of long-lived objects profiled by sample apps and long-lived objects added by application.
|
||||
*/
|
||||
#if defined ZCL_KEY_ESTABLISH_OLD // CBKE no longer uses long lived memory allocations.
|
||||
#define OSALMEM_LL_BLKSZ (OSALMEM_ROUND(526) + (32 * OSALMEM_HDRSZ))
|
||||
#elif defined TC_LINKKEY_JOIN
|
||||
#define OSALMEM_LL_BLKSZ (OSALMEM_ROUND(454) + (21 * OSALMEM_HDRSZ))
|
||||
#elif ((defined SECURE) && (SECURE != 0))
|
||||
#define OSALMEM_LL_BLKSZ (OSALMEM_ROUND(418) + (19 * OSALMEM_HDRSZ))
|
||||
#else
|
||||
#define OSALMEM_LL_BLKSZ (OSALMEM_ROUND(417) + (19 * OSALMEM_HDRSZ))
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Adjust accordingly to attempt to accomodate the block sizes of the vast majority of
|
||||
* very high frequency allocations/frees by profiling the system runtime.
|
||||
* This default of 16 accomodates the OSAL timers block, osalTimerRec_t, and many others.
|
||||
* Ensure that this size is an even multiple of OSALMEM_MIN_BLKSZ for run-time efficiency.
|
||||
*/
|
||||
#if !defined OSALMEM_SMALL_BLKSZ
|
||||
#define OSALMEM_SMALL_BLKSZ (OSALMEM_ROUND(16))
|
||||
#endif
|
||||
#if !defined OSALMEM_SMALL_BLKCNT
|
||||
#define OSALMEM_SMALL_BLKCNT 8
|
||||
#endif
|
||||
|
||||
/*
|
||||
* These numbers setup the size of the small-block bucket which is reserved at the front of the
|
||||
* heap for allocations of OSALMEM_SMALL_BLKSZ or smaller.
|
||||
*/
|
||||
|
||||
// Size of the heap bucket reserved for small block-sized allocations.
|
||||
// Adjust accordingly to attempt to accomodate the vast majority of very high frequency operations.
|
||||
#define OSALMEM_SMALLBLK_BUCKET ((OSALMEM_SMALL_BLKSZ * OSALMEM_SMALL_BLKCNT) + OSALMEM_LL_BLKSZ)
|
||||
// Index of the first available osalMemHdr_t after the small-block heap which will be set in-use in
|
||||
// order to prevent the small-block bucket from being coalesced with the wilderness.
|
||||
#define OSALMEM_SMALLBLK_HDRCNT (OSALMEM_SMALLBLK_BUCKET / OSALMEM_HDRSZ)
|
||||
// Index of the first available osalMemHdr_t after the small-block heap which will be set in-use in
|
||||
#define OSALMEM_BIGBLK_IDX (OSALMEM_SMALLBLK_HDRCNT + 1)
|
||||
// The size of the wilderness after losing the small-block heap, the wasted header to block the
|
||||
// small-block heap from being coalesced, and the wasted header to mark the end of the heap.
|
||||
#define OSALMEM_BIGBLK_SZ (MAXMEMHEAP - OSALMEM_SMALLBLK_BUCKET - OSALMEM_HDRSZ*2)
|
||||
// Index of the last available osalMemHdr_t at the end of the heap which will be set to zero for
|
||||
// fast comparisons with zero to determine the end of the heap.
|
||||
#define OSALMEM_LASTBLK_IDX ((MAXMEMHEAP / OSALMEM_HDRSZ) - 1)
|
||||
|
||||
// For information about memory profiling, refer to SWRA204 "Heap Memory Management", section 1.5.
|
||||
#if !defined OSALMEM_PROFILER
|
||||
#define OSALMEM_PROFILER FALSE // Enable/disable the memory usage profiling buckets.
|
||||
#endif
|
||||
#if !defined OSALMEM_PROFILER_LL
|
||||
#define OSALMEM_PROFILER_LL FALSE // Special profiling of the Long-Lived bucket.
|
||||
#endif
|
||||
|
||||
#if OSALMEM_PROFILER
|
||||
#define OSALMEM_INIT 'X'
|
||||
#define OSALMEM_ALOC 'A'
|
||||
#define OSALMEM_REIN 'F'
|
||||
#endif
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Typedefs
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
// The 15 LSB's of 'val' indicate the total item size, including the header, in 8-bit bytes.
|
||||
unsigned len : 15;
|
||||
// The 1 MSB of 'val' is used as a boolean to indicate in-use or freed.
|
||||
unsigned inUse : 1;
|
||||
} osalMemHdrHdr_t;
|
||||
|
||||
typedef union {
|
||||
/* Dummy variable so compiler forces structure to alignment of largest element while not wasting
|
||||
* space on targets when the halDataAlign_t is smaller than a UINT16.
|
||||
*/
|
||||
halDataAlign_t alignDummy;
|
||||
uint16 val;
|
||||
osalMemHdrHdr_t hdr;
|
||||
} osalMemHdr_t;
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Local Variables
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#if !defined ( ZBIT ) && defined ewarm
|
||||
static __no_init osalMemHdr_t theHeap[MAXMEMHEAP / OSALMEM_HDRSZ];
|
||||
static __no_init osalMemHdr_t *ff1; // First free block in the small-block bucket.
|
||||
#else
|
||||
static osalMemHdr_t theHeap[MAXMEMHEAP / OSALMEM_HDRSZ];
|
||||
static osalMemHdr_t *ff1; // First free block in the small-block bucket.
|
||||
#endif
|
||||
|
||||
static uint8 osalMemStat; // Discrete status flags: 0x01 = kicked.
|
||||
|
||||
#if OSALMEM_METRICS
|
||||
static uint16 blkMax; // Max cnt of all blocks ever seen at once.
|
||||
static uint16 blkCnt; // Current cnt of all blocks.
|
||||
static uint16 blkFree; // Current cnt of free blocks.
|
||||
static uint16 memAlo; // Current total memory allocated.
|
||||
static uint16 memMax; // Max total memory ever allocated at once.
|
||||
#endif
|
||||
|
||||
#if OSALMEM_PROFILER
|
||||
#define OSALMEM_PROMAX 8
|
||||
/* The profiling buckets must differ by at least OSALMEM_MIN_BLKSZ; the
|
||||
* last bucket must equal the max alloc size. Set the bucket sizes to
|
||||
* whatever sizes necessary to show how your application is using memory.
|
||||
*/
|
||||
static uint16 proCnt[OSALMEM_PROMAX] = {
|
||||
OSALMEM_SMALL_BLKSZ, 48, 112, 176, 192, 224, 256, 65535 };
|
||||
static uint16 proCur[OSALMEM_PROMAX] = { 0 };
|
||||
static uint16 proMax[OSALMEM_PROMAX] = { 0 };
|
||||
static uint16 proTot[OSALMEM_PROMAX] = { 0 };
|
||||
static uint16 proSmallBlkMiss;
|
||||
#endif
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Global Variables
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#ifdef DPRINTF_HEAPTRACE
|
||||
extern int dprintf(const char *fmt, ...);
|
||||
#endif /* DPRINTF_HEAPTRACE */
|
||||
|
||||
/**************************************************************************************************
|
||||
* @fn osal_mem_init
|
||||
*
|
||||
* @brief This function is the OSAL heap memory management initialization callback.
|
||||
*
|
||||
* input parameters
|
||||
*
|
||||
* None.
|
||||
*
|
||||
* output parameters
|
||||
*
|
||||
* None.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void osal_mem_init(void)
|
||||
{
|
||||
HAL_ASSERT(((OSALMEM_MIN_BLKSZ % OSALMEM_HDRSZ) == 0));
|
||||
HAL_ASSERT(((OSALMEM_LL_BLKSZ % OSALMEM_HDRSZ) == 0));
|
||||
HAL_ASSERT(((OSALMEM_SMALL_BLKSZ % OSALMEM_HDRSZ) == 0));
|
||||
|
||||
#if OSALMEM_PROFILER
|
||||
(void)osal_memset(theHeap, OSALMEM_INIT, MAXMEMHEAP);
|
||||
#endif
|
||||
|
||||
// Setup a NULL block at the end of the heap for fast comparisons with zero.
|
||||
theHeap[OSALMEM_LASTBLK_IDX].val = 0;
|
||||
|
||||
// Setup the small-block bucket.
|
||||
ff1 = theHeap;
|
||||
ff1->val = OSALMEM_SMALLBLK_BUCKET; // Set 'len' & clear 'inUse' field.
|
||||
// Set 'len' & 'inUse' fields - this is a 'zero data bytes' lifetime allocation to block the
|
||||
// small-block bucket from ever being coalesced with the wilderness.
|
||||
theHeap[OSALMEM_SMALLBLK_HDRCNT].val = (OSALMEM_HDRSZ | OSALMEM_IN_USE);
|
||||
|
||||
// Setup the wilderness.
|
||||
theHeap[OSALMEM_BIGBLK_IDX].val = OSALMEM_BIGBLK_SZ; // Set 'len' & clear 'inUse' field.
|
||||
|
||||
#if ( OSALMEM_METRICS )
|
||||
/* Start with the small-block bucket and the wilderness - don't count the
|
||||
* end-of-heap NULL block nor the end-of-small-block NULL block.
|
||||
*/
|
||||
blkCnt = blkFree = 2;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**************************************************************************************************
|
||||
* @fn osal_mem_kick
|
||||
*
|
||||
* @brief This function is the OSAL task initialization callback.
|
||||
* @brief Kick the ff1 pointer out past the long-lived OSAL Task blocks.
|
||||
* Invoke this once after all long-lived blocks have been allocated -
|
||||
* presently at the end of osal_init_system().
|
||||
*
|
||||
* input parameters
|
||||
*
|
||||
* None.
|
||||
*
|
||||
* output parameters
|
||||
*
|
||||
* None.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void osal_mem_kick(void)
|
||||
{
|
||||
halIntState_t intState;
|
||||
osalMemHdr_t *tmp = osal_mem_alloc(1);
|
||||
|
||||
HAL_ASSERT((tmp != NULL));
|
||||
HAL_ENTER_CRITICAL_SECTION(intState); // Hold off interrupts.
|
||||
|
||||
/* All long-lived allocations have filled the LL block reserved in the small-block bucket.
|
||||
* Set 'osalMemStat' so searching for memory in this bucket from here onward will only be done
|
||||
* for sizes meeting the OSALMEM_SMALL_BLKSZ criteria.
|
||||
*/
|
||||
ff1 = tmp - 1; // Set 'ff1' to point to the first available memory after the LL block.
|
||||
osal_mem_free(tmp);
|
||||
osalMemStat = 0x01; // Set 'osalMemStat' after the free because it enables memory profiling.
|
||||
|
||||
HAL_EXIT_CRITICAL_SECTION(intState); // Re-enable interrupts.
|
||||
}
|
||||
|
||||
/**************************************************************************************************
|
||||
* @fn osal_mem_alloc
|
||||
*
|
||||
* @brief This function implements the OSAL dynamic memory allocation functionality.
|
||||
*
|
||||
* input parameters
|
||||
*
|
||||
* @param size - the number of bytes to allocate from the HEAP.
|
||||
*
|
||||
* output parameters
|
||||
*
|
||||
* None.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
#ifdef DPRINTF_OSALHEAPTRACE
|
||||
void *osal_mem_alloc_dbg( uint16 size, const char *fname, unsigned lnum )
|
||||
#else /* DPRINTF_OSALHEAPTRACE */
|
||||
void *osal_mem_alloc( uint16 size )
|
||||
#endif /* DPRINTF_OSALHEAPTRACE */
|
||||
{
|
||||
osalMemHdr_t *prev = NULL;
|
||||
osalMemHdr_t *hdr;
|
||||
halIntState_t intState;
|
||||
uint8 coal = 0;
|
||||
|
||||
size += OSALMEM_HDRSZ;
|
||||
|
||||
// Calculate required bytes to add to 'size' to align to halDataAlign_t.
|
||||
if ( sizeof( halDataAlign_t ) == 2 )
|
||||
{
|
||||
size += (size & 0x01);
|
||||
}
|
||||
else if ( sizeof( halDataAlign_t ) != 1 )
|
||||
{
|
||||
const uint8 mod = size % sizeof( halDataAlign_t );
|
||||
|
||||
if ( mod != 0 )
|
||||
{
|
||||
size += (sizeof( halDataAlign_t ) - mod);
|
||||
}
|
||||
}
|
||||
|
||||
HAL_ENTER_CRITICAL_SECTION( intState ); // Hold off interrupts.
|
||||
|
||||
// Smaller allocations are first attempted in the small-block bucket, and all long-lived
|
||||
// allocations are channeled into the LL block reserved within this bucket.
|
||||
if ((osalMemStat == 0) || (size <= OSALMEM_SMALL_BLKSZ))
|
||||
{
|
||||
hdr = ff1;
|
||||
}
|
||||
else
|
||||
{
|
||||
hdr = (theHeap + OSALMEM_BIGBLK_IDX);
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
if ( hdr->hdr.inUse )
|
||||
{
|
||||
coal = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( coal != 0 )
|
||||
{
|
||||
#if ( OSALMEM_METRICS )
|
||||
blkCnt--;
|
||||
blkFree--;
|
||||
#endif
|
||||
|
||||
prev->hdr.len += hdr->hdr.len;
|
||||
|
||||
if ( prev->hdr.len >= size )
|
||||
{
|
||||
hdr = prev;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( hdr->hdr.len >= size )
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
coal = 1;
|
||||
prev = hdr;
|
||||
}
|
||||
}
|
||||
|
||||
hdr = (osalMemHdr_t *)((uint8 *)hdr + hdr->hdr.len);
|
||||
|
||||
if ( hdr->val == 0 )
|
||||
{
|
||||
hdr = NULL;
|
||||
break;
|
||||
}
|
||||
} while (1);
|
||||
|
||||
if ( hdr != NULL )
|
||||
{
|
||||
uint16 tmp = hdr->hdr.len - size;
|
||||
|
||||
// Determine whether the threshold for splitting is met.
|
||||
if ( tmp >= OSALMEM_MIN_BLKSZ )
|
||||
{
|
||||
// Split the block before allocating it.
|
||||
osalMemHdr_t *next = (osalMemHdr_t *)((uint8 *)hdr + size);
|
||||
next->val = tmp; // Set 'len' & clear 'inUse' field.
|
||||
hdr->val = (size | OSALMEM_IN_USE); // Set 'len' & 'inUse' field.
|
||||
|
||||
#if ( OSALMEM_METRICS )
|
||||
blkCnt++;
|
||||
if ( blkMax < blkCnt )
|
||||
{
|
||||
blkMax = blkCnt;
|
||||
}
|
||||
memAlo += size;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
#if ( OSALMEM_METRICS )
|
||||
memAlo += hdr->hdr.len;
|
||||
blkFree--;
|
||||
#endif
|
||||
|
||||
hdr->hdr.inUse = TRUE;
|
||||
}
|
||||
|
||||
#if ( OSALMEM_METRICS )
|
||||
if ( memMax < memAlo )
|
||||
{
|
||||
memMax = memAlo;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ( OSALMEM_PROFILER )
|
||||
#if !OSALMEM_PROFILER_LL
|
||||
if (osalMemStat != 0) // Don't profile until after the LL block is filled.
|
||||
#endif
|
||||
{
|
||||
uint8 idx;
|
||||
|
||||
for ( idx = 0; idx < OSALMEM_PROMAX; idx++ )
|
||||
{
|
||||
if ( hdr->hdr.len <= proCnt[idx] )
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
proCur[idx]++;
|
||||
if ( proMax[idx] < proCur[idx] )
|
||||
{
|
||||
proMax[idx] = proCur[idx];
|
||||
}
|
||||
proTot[idx]++;
|
||||
|
||||
/* A small-block could not be allocated in the small-block bucket.
|
||||
* When this occurs significantly frequently, increase the size of the
|
||||
* bucket in order to restore better worst case run times. Set the first
|
||||
* profiling bucket size in proCnt[] to the small-block bucket size and
|
||||
* divide proSmallBlkMiss by the corresponding proTot[] size to get % miss.
|
||||
* Best worst case time on TrasmitApp was achieved at a 0-15% miss rate
|
||||
* during steady state Tx load, 0% during idle and steady state Rx load.
|
||||
*/
|
||||
if ((hdr->hdr.len <= OSALMEM_SMALL_BLKSZ) && (hdr >= (theHeap + OSALMEM_BIGBLK_IDX)))
|
||||
{
|
||||
proSmallBlkMiss++;
|
||||
}
|
||||
}
|
||||
|
||||
(void)osal_memset((uint8 *)(hdr+1), OSALMEM_ALOC, (hdr->hdr.len - OSALMEM_HDRSZ));
|
||||
#endif
|
||||
|
||||
if ((osalMemStat != 0) && (ff1 == hdr))
|
||||
{
|
||||
ff1 = (osalMemHdr_t *)((uint8 *)hdr + hdr->hdr.len);
|
||||
}
|
||||
|
||||
hdr++;
|
||||
}
|
||||
|
||||
HAL_EXIT_CRITICAL_SECTION( intState ); // Re-enable interrupts.
|
||||
|
||||
HAL_ASSERT(((size_t)hdr % sizeof(halDataAlign_t)) == 0);
|
||||
|
||||
#ifdef DPRINTF_OSALHEAPTRACE
|
||||
dprintf("osal_mem_alloc(%u)->%lx:%s:%u\n", size, (unsigned) hdr, fname, lnum);
|
||||
#endif /* DPRINTF_OSALHEAPTRACE */
|
||||
return (void *)hdr;
|
||||
}
|
||||
|
||||
/**************************************************************************************************
|
||||
* @fn osal_mem_free
|
||||
*
|
||||
* @brief This function implements the OSAL dynamic memory de-allocation functionality.
|
||||
*
|
||||
* input parameters
|
||||
*
|
||||
* @param ptr - A valid pointer (i.e. a pointer returned by osal_mem_alloc()) to the memory to free.
|
||||
*
|
||||
* output parameters
|
||||
*
|
||||
* None.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
#ifdef DPRINTF_OSALHEAPTRACE
|
||||
void osal_mem_free_dbg(void *ptr, const char *fname, unsigned lnum)
|
||||
#else /* DPRINTF_OSALHEAPTRACE */
|
||||
void osal_mem_free(void *ptr)
|
||||
#endif /* DPRINTF_OSALHEAPTRACE */
|
||||
{
|
||||
osalMemHdr_t *hdr = (osalMemHdr_t *)ptr - 1;
|
||||
halIntState_t intState;
|
||||
|
||||
#ifdef DPRINTF_OSALHEAPTRACE
|
||||
dprintf("osal_mem_free(%lx):%s:%u\n", (unsigned) ptr, fname, lnum);
|
||||
#endif /* DPRINTF_OSALHEAPTRACE */
|
||||
|
||||
HAL_ASSERT(((uint8 *)ptr >= (uint8 *)theHeap) && ((uint8 *)ptr < (uint8 *)theHeap+MAXMEMHEAP));
|
||||
HAL_ASSERT(hdr->hdr.inUse);
|
||||
|
||||
HAL_ENTER_CRITICAL_SECTION( intState ); // Hold off interrupts.
|
||||
hdr->hdr.inUse = FALSE;
|
||||
|
||||
if (ff1 > hdr)
|
||||
{
|
||||
ff1 = hdr;
|
||||
}
|
||||
|
||||
#if OSALMEM_PROFILER
|
||||
#if !OSALMEM_PROFILER_LL
|
||||
if (osalMemStat != 0) // Don't profile until after the LL block is filled.
|
||||
#endif
|
||||
{
|
||||
uint8 idx;
|
||||
|
||||
for (idx = 0; idx < OSALMEM_PROMAX; idx++)
|
||||
{
|
||||
if (hdr->hdr.len <= proCnt[idx])
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
proCur[idx]--;
|
||||
}
|
||||
|
||||
(void)osal_memset((uint8 *)(hdr+1), OSALMEM_REIN, (hdr->hdr.len - OSALMEM_HDRSZ) );
|
||||
#endif
|
||||
#if OSALMEM_METRICS
|
||||
memAlo -= hdr->hdr.len;
|
||||
blkFree++;
|
||||
#endif
|
||||
|
||||
HAL_EXIT_CRITICAL_SECTION( intState ); // Re-enable interrupts.
|
||||
}
|
||||
|
||||
#if OSALMEM_METRICS
|
||||
/*********************************************************************
|
||||
* @fn osal_heap_block_max
|
||||
*
|
||||
* @brief Return the maximum number of blocks ever allocated at once.
|
||||
*
|
||||
* @param none
|
||||
*
|
||||
* @return Maximum number of blocks ever allocated at once.
|
||||
*/
|
||||
uint16 osal_heap_block_max( void )
|
||||
{
|
||||
return blkMax;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn osal_heap_block_cnt
|
||||
*
|
||||
* @brief Return the current number of blocks now allocated.
|
||||
*
|
||||
* @param none
|
||||
*
|
||||
* @return Current number of blocks now allocated.
|
||||
*/
|
||||
uint16 osal_heap_block_cnt( void )
|
||||
{
|
||||
return blkCnt;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn osal_heap_block_free
|
||||
*
|
||||
* @brief Return the current number of free blocks.
|
||||
*
|
||||
* @param none
|
||||
*
|
||||
* @return Current number of free blocks.
|
||||
*/
|
||||
uint16 osal_heap_block_free( void )
|
||||
{
|
||||
return blkFree;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn osal_heap_mem_used
|
||||
*
|
||||
* @brief Return the current number of bytes allocated.
|
||||
*
|
||||
* @param none
|
||||
*
|
||||
* @return Current number of bytes allocated.
|
||||
*/
|
||||
uint16 osal_heap_mem_used( void )
|
||||
{
|
||||
return memAlo;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined (ZTOOL_P1) || defined (ZTOOL_P2)
|
||||
/*********************************************************************
|
||||
* @fn osal_heap_high_water
|
||||
*
|
||||
* @brief Return the highest byte ever allocated in the heap.
|
||||
*
|
||||
* @param none
|
||||
*
|
||||
* @return Highest number of bytes ever used by the stack.
|
||||
*/
|
||||
uint16 osal_heap_high_water( void )
|
||||
{
|
||||
#if ( OSALMEM_METRICS )
|
||||
return memMax;
|
||||
#else
|
||||
return MAXMEMHEAP;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
/**************************************************************************************************
|
||||
*/
|
||||
145
include/OSAL_Memory.h
Normal file
145
include/OSAL_Memory.h
Normal file
@@ -0,0 +1,145 @@
|
||||
/**************************************************************************************************
|
||||
Filename: OSAL_Memory.h
|
||||
Revised: $Date: 2010-07-28 08:42:48 -0700 (Wed, 28 Jul 2010) $
|
||||
Revision: $Revision: 23160 $
|
||||
|
||||
Description: This module defines the OSAL memory control functions.
|
||||
|
||||
|
||||
Copyright 2004-2007 Texas Instruments Incorporated. All rights reserved.
|
||||
|
||||
IMPORTANT: Your use of this Software is limited to those specific rights
|
||||
granted under the terms of a software license agreement between the user
|
||||
who downloaded the software, his/her employer (which must be your employer)
|
||||
and Texas Instruments Incorporated (the "License"). You may not use this
|
||||
Software unless you agree to abide by the terms of the License. The License
|
||||
limits your use, and you acknowledge, that the Software may not be modified,
|
||||
copied or distributed unless embedded on a Texas Instruments microcontroller
|
||||
or used solely and exclusively in conjunction with a Texas Instruments radio
|
||||
frequency transceiver, which is integrated into your product. Other than for
|
||||
the foregoing purpose, you may not use, reproduce, copy, prepare derivative
|
||||
works of, modify, distribute, perform, display or sell this Software and/or
|
||||
its documentation for any purpose.
|
||||
|
||||
YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
|
||||
PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
||||
INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
|
||||
NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
|
||||
TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
|
||||
NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
|
||||
LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
|
||||
INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
|
||||
OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
|
||||
OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
|
||||
(INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
|
||||
|
||||
Should you have any questions regarding your right to use this Software,
|
||||
contact Texas Instruments Incorporated at www.TI.com.
|
||||
**************************************************************************************************/
|
||||
|
||||
#ifndef OSAL_MEMORY_H
|
||||
#define OSAL_MEMORY_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/*********************************************************************
|
||||
* INCLUDES
|
||||
*/
|
||||
#include "comdef.h"
|
||||
|
||||
/*********************************************************************
|
||||
* CONSTANTS
|
||||
*/
|
||||
|
||||
#if !defined ( OSALMEM_METRICS )
|
||||
#define OSALMEM_METRICS FALSE
|
||||
#endif
|
||||
|
||||
/*********************************************************************
|
||||
* MACROS
|
||||
*/
|
||||
|
||||
#define osal_stack_used() OnBoard_stack_used()
|
||||
|
||||
/*********************************************************************
|
||||
* TYPEDEFS
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
* GLOBAL VARIABLES
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
* FUNCTIONS
|
||||
*/
|
||||
|
||||
/*
|
||||
* Initialize memory manager.
|
||||
*/
|
||||
void osal_mem_init( void );
|
||||
|
||||
/*
|
||||
* Setup efficient search for the first free block of heap.
|
||||
*/
|
||||
void osal_mem_kick( void );
|
||||
|
||||
/*
|
||||
* Allocate a block of memory.
|
||||
*/
|
||||
#ifdef DPRINTF_OSALHEAPTRACE
|
||||
void *osal_mem_alloc_dbg( uint16 size, const char *fname, unsigned lnum );
|
||||
#define osal_mem_alloc(_size ) osal_mem_alloc_dbg(_size, __FILE__, __LINE__)
|
||||
#else /* DPRINTF_OSALHEAPTRACE */
|
||||
void *osal_mem_alloc( uint16 size );
|
||||
#endif /* DPRINTF_OSALHEAPTRACE */
|
||||
|
||||
/*
|
||||
* Free a block of memory.
|
||||
*/
|
||||
#ifdef DPRINTF_OSALHEAPTRACE
|
||||
void osal_mem_free_dbg( void *ptr, const char *fname, unsigned lnum );
|
||||
#define osal_mem_free(_ptr ) osal_mem_free_dbg(_ptr, __FILE__, __LINE__)
|
||||
#else /* DPRINTF_OSALHEAPTRACE */
|
||||
void osal_mem_free( void *ptr );
|
||||
#endif /* DPRINTF_OSALHEAPTRACE */
|
||||
|
||||
#if ( OSALMEM_METRICS )
|
||||
/*
|
||||
* Return the maximum number of blocks ever allocated at once.
|
||||
*/
|
||||
uint16 osal_heap_block_max( void );
|
||||
|
||||
/*
|
||||
* Return the current number of blocks now allocated.
|
||||
*/
|
||||
uint16 osal_heap_block_cnt( void );
|
||||
|
||||
/*
|
||||
* Return the current number of free blocks.
|
||||
*/
|
||||
uint16 osal_heap_block_free( void );
|
||||
|
||||
/*
|
||||
* Return the current number of bytes allocated.
|
||||
*/
|
||||
uint16 osal_heap_mem_used( void );
|
||||
#endif
|
||||
|
||||
#if defined (ZTOOL_P1) || defined (ZTOOL_P2)
|
||||
/*
|
||||
* Return the highest number of bytes ever used in the heap.
|
||||
*/
|
||||
uint16 osal_heap_high_water( void );
|
||||
#endif
|
||||
|
||||
/*********************************************************************
|
||||
*********************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* #ifndef OSAL_MEMORY_H */
|
||||
615
include/OSAL_Timers.c
Normal file
615
include/OSAL_Timers.c
Normal file
@@ -0,0 +1,615 @@
|
||||
/**************************************************************************************************
|
||||
Filename: OSAL_Timers.c
|
||||
Revised: $Date: 2014-06-16 15:12:16 -0700 (Mon, 16 Jun 2014) $
|
||||
Revision: $Revision: 39036 $
|
||||
|
||||
Description: OSAL Timer definition and manipulation functions.
|
||||
|
||||
|
||||
Copyright 2004-2012 Texas Instruments Incorporated. All rights reserved.
|
||||
|
||||
IMPORTANT: Your use of this Software is limited to those specific rights
|
||||
granted under the terms of a software license agreement between the user
|
||||
who downloaded the software, his/her employer (which must be your employer)
|
||||
and Texas Instruments Incorporated (the "License"). You may not use this
|
||||
Software unless you agree to abide by the terms of the License. The License
|
||||
limits your use, and you acknowledge, that the Software may not be modified,
|
||||
copied or distributed unless embedded on a Texas Instruments microcontroller
|
||||
or used solely and exclusively in conjunction with a Texas Instruments radio
|
||||
frequency transceiver, which is integrated into your product. Other than for
|
||||
the foregoing purpose, you may not use, reproduce, copy, prepare derivative
|
||||
works of, modify, distribute, perform, display or sell this Software and/or
|
||||
its documentation for any purpose.
|
||||
|
||||
YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
|
||||
PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
||||
INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
|
||||
NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
|
||||
TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
|
||||
NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
|
||||
LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
|
||||
INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
|
||||
OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
|
||||
OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
|
||||
(INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
|
||||
|
||||
Should you have any questions regarding your right to use this Software,
|
||||
contact Texas Instruments Incorporated at www.TI.com.
|
||||
**************************************************************************************************/
|
||||
|
||||
/*********************************************************************
|
||||
* INCLUDES
|
||||
*/
|
||||
|
||||
#include "comdef.h"
|
||||
#include "OnBoard.h"
|
||||
#include "OSAL.h"
|
||||
#include "OSAL_Timers.h"
|
||||
#include "hal_timer.h"
|
||||
|
||||
/*********************************************************************
|
||||
* MACROS
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
* CONSTANTS
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
* TYPEDEFS
|
||||
*/
|
||||
|
||||
typedef union {
|
||||
uint32 time32;
|
||||
uint16 time16[2];
|
||||
uint8 time8[4];
|
||||
} osalTime_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
void *next;
|
||||
osalTime_t timeout;
|
||||
uint16 event_flag;
|
||||
uint8 task_id;
|
||||
uint32 reloadTimeout;
|
||||
} osalTimerRec_t;
|
||||
|
||||
/*********************************************************************
|
||||
* GLOBAL VARIABLES
|
||||
*/
|
||||
|
||||
osalTimerRec_t *timerHead;
|
||||
|
||||
/*********************************************************************
|
||||
* EXTERNAL VARIABLES
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
* EXTERNAL FUNCTIONS
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
* LOCAL VARIABLES
|
||||
*/
|
||||
// Milliseconds since last reboot
|
||||
static uint32 osal_systemClock;
|
||||
|
||||
/*********************************************************************
|
||||
* LOCAL FUNCTION PROTOTYPES
|
||||
*/
|
||||
osalTimerRec_t *osalAddTimer( uint8 task_id, uint16 event_flag, uint32 timeout );
|
||||
osalTimerRec_t *osalFindTimer( uint8 task_id, uint16 event_flag );
|
||||
void osalDeleteTimer( osalTimerRec_t *rmTimer );
|
||||
|
||||
/*********************************************************************
|
||||
* FUNCTIONS
|
||||
*********************************************************************/
|
||||
|
||||
/*********************************************************************
|
||||
* @fn osalTimerInit
|
||||
*
|
||||
* @brief Initialization for the OSAL Timer System.
|
||||
*
|
||||
* @param none
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
void osalTimerInit( void )
|
||||
{
|
||||
osal_systemClock = 0;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn osalAddTimer
|
||||
*
|
||||
* @brief Add a timer to the timer list.
|
||||
* Ints must be disabled.
|
||||
*
|
||||
* @param task_id
|
||||
* @param event_flag
|
||||
* @param timeout
|
||||
*
|
||||
* @return osalTimerRec_t * - pointer to newly created timer
|
||||
*/
|
||||
osalTimerRec_t * osalAddTimer( uint8 task_id, uint16 event_flag, uint32 timeout )
|
||||
{
|
||||
osalTimerRec_t *newTimer;
|
||||
osalTimerRec_t *srchTimer;
|
||||
|
||||
// Look for an existing timer first
|
||||
newTimer = osalFindTimer( task_id, event_flag );
|
||||
if ( newTimer )
|
||||
{
|
||||
// Timer is found - update it.
|
||||
newTimer->timeout.time32 = timeout;
|
||||
|
||||
return ( newTimer );
|
||||
}
|
||||
else
|
||||
{
|
||||
// New Timer
|
||||
newTimer = osal_mem_alloc( sizeof( osalTimerRec_t ) );
|
||||
|
||||
if ( newTimer )
|
||||
{
|
||||
// Fill in new timer
|
||||
newTimer->task_id = task_id;
|
||||
newTimer->event_flag = event_flag;
|
||||
newTimer->timeout.time32 = timeout;
|
||||
newTimer->next = (void *)NULL;
|
||||
newTimer->reloadTimeout = 0;
|
||||
|
||||
// Does the timer list already exist
|
||||
if ( timerHead == NULL )
|
||||
{
|
||||
// Start task list
|
||||
timerHead = newTimer;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Add it to the end of the timer list
|
||||
srchTimer = timerHead;
|
||||
|
||||
// Stop at the last record
|
||||
while ( srchTimer->next )
|
||||
srchTimer = srchTimer->next;
|
||||
|
||||
// Add to the list
|
||||
srchTimer->next = newTimer;
|
||||
}
|
||||
|
||||
return ( newTimer );
|
||||
}
|
||||
else
|
||||
{
|
||||
return ( (osalTimerRec_t *)NULL );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn osalFindTimer
|
||||
*
|
||||
* @brief Find a timer in a timer list.
|
||||
* Ints must be disabled.
|
||||
*
|
||||
* @param task_id
|
||||
* @param event_flag
|
||||
*
|
||||
* @return osalTimerRec_t *
|
||||
*/
|
||||
osalTimerRec_t *osalFindTimer( uint8 task_id, uint16 event_flag )
|
||||
{
|
||||
osalTimerRec_t *srchTimer;
|
||||
|
||||
// Head of the timer list
|
||||
srchTimer = timerHead;
|
||||
|
||||
// Stop when found or at the end
|
||||
while ( srchTimer )
|
||||
{
|
||||
if ( srchTimer->event_flag == event_flag &&
|
||||
srchTimer->task_id == task_id )
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
// Not this one, check another
|
||||
srchTimer = srchTimer->next;
|
||||
}
|
||||
|
||||
return ( srchTimer );
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn osalDeleteTimer
|
||||
*
|
||||
* @brief Delete a timer from a timer list.
|
||||
*
|
||||
* @param table
|
||||
* @param rmTimer
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void osalDeleteTimer( osalTimerRec_t *rmTimer )
|
||||
{
|
||||
// Does the timer list really exist
|
||||
if ( rmTimer )
|
||||
{
|
||||
// Clear the event flag and osalTimerUpdate() will delete
|
||||
// the timer from the list.
|
||||
rmTimer->event_flag = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn osal_start_timerEx
|
||||
*
|
||||
* @brief
|
||||
*
|
||||
* This function is called to start a timer to expire in n mSecs.
|
||||
* When the timer expires, the calling task will get the specified event.
|
||||
*
|
||||
* @param uint8 taskID - task id to set timer for
|
||||
* @param uint16 event_id - event to be notified with
|
||||
* @param uint32 timeout_value - in milliseconds.
|
||||
*
|
||||
* @return SUCCESS, or NO_TIMER_AVAIL.
|
||||
*/
|
||||
uint8 osal_start_timerEx( uint8 taskID, uint16 event_id, uint32 timeout_value )
|
||||
{
|
||||
halIntState_t intState;
|
||||
osalTimerRec_t *newTimer;
|
||||
|
||||
HAL_ENTER_CRITICAL_SECTION( intState ); // Hold off interrupts.
|
||||
|
||||
// Add timer
|
||||
newTimer = osalAddTimer( taskID, event_id, timeout_value );
|
||||
|
||||
HAL_EXIT_CRITICAL_SECTION( intState ); // Re-enable interrupts.
|
||||
|
||||
return ( (newTimer != NULL) ? SUCCESS : NO_TIMER_AVAIL );
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn osal_start_reload_timer
|
||||
*
|
||||
* @brief
|
||||
*
|
||||
* This function is called to start a timer to expire in n mSecs.
|
||||
* When the timer expires, the calling task will get the specified event
|
||||
* and the timer will be reloaded with the timeout value.
|
||||
*
|
||||
* @param uint8 taskID - task id to set timer for
|
||||
* @param uint16 event_id - event to be notified with
|
||||
* @param UNINT16 timeout_value - in milliseconds.
|
||||
*
|
||||
* @return SUCCESS, or NO_TIMER_AVAIL.
|
||||
*/
|
||||
uint8 osal_start_reload_timer( uint8 taskID, uint16 event_id, uint32 timeout_value )
|
||||
{
|
||||
halIntState_t intState;
|
||||
osalTimerRec_t *newTimer;
|
||||
|
||||
HAL_ENTER_CRITICAL_SECTION( intState ); // Hold off interrupts.
|
||||
|
||||
// Add timer
|
||||
newTimer = osalAddTimer( taskID, event_id, timeout_value );
|
||||
if ( newTimer )
|
||||
{
|
||||
// Load the reload timeout value
|
||||
newTimer->reloadTimeout = timeout_value;
|
||||
}
|
||||
|
||||
HAL_EXIT_CRITICAL_SECTION( intState ); // Re-enable interrupts.
|
||||
|
||||
return ( (newTimer != NULL) ? SUCCESS : NO_TIMER_AVAIL );
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn osal_stop_timerEx
|
||||
*
|
||||
* @brief
|
||||
*
|
||||
* This function is called to stop a timer that has already been started.
|
||||
* If ZSUCCESS, the function will cancel the timer and prevent the event
|
||||
* associated with the timer from being set for the calling task.
|
||||
*
|
||||
* @param uint8 task_id - task id of timer to stop
|
||||
* @param uint16 event_id - identifier of the timer that is to be stopped
|
||||
*
|
||||
* @return SUCCESS or INVALID_EVENT_ID
|
||||
*/
|
||||
uint8 osal_stop_timerEx( uint8 task_id, uint16 event_id )
|
||||
{
|
||||
halIntState_t intState;
|
||||
osalTimerRec_t *foundTimer;
|
||||
|
||||
HAL_ENTER_CRITICAL_SECTION( intState ); // Hold off interrupts.
|
||||
|
||||
// Find the timer to stop
|
||||
foundTimer = osalFindTimer( task_id, event_id );
|
||||
if ( foundTimer )
|
||||
{
|
||||
osalDeleteTimer( foundTimer );
|
||||
}
|
||||
|
||||
HAL_EXIT_CRITICAL_SECTION( intState ); // Re-enable interrupts.
|
||||
|
||||
return ( (foundTimer != NULL) ? SUCCESS : INVALID_EVENT_ID );
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn osal_get_timeoutEx
|
||||
*
|
||||
* @brief
|
||||
*
|
||||
* @param uint8 task_id - task id of timer to check
|
||||
* @param uint16 event_id - identifier of timer to be checked
|
||||
*
|
||||
* @return Return the timer's tick count if found, zero otherwise.
|
||||
*/
|
||||
uint32 osal_get_timeoutEx( uint8 task_id, uint16 event_id )
|
||||
{
|
||||
halIntState_t intState;
|
||||
uint32 rtrn = 0;
|
||||
osalTimerRec_t *tmr;
|
||||
|
||||
HAL_ENTER_CRITICAL_SECTION( intState ); // Hold off interrupts.
|
||||
|
||||
tmr = osalFindTimer( task_id, event_id );
|
||||
|
||||
if ( tmr )
|
||||
{
|
||||
rtrn = tmr->timeout.time32;
|
||||
}
|
||||
|
||||
HAL_EXIT_CRITICAL_SECTION( intState ); // Re-enable interrupts.
|
||||
|
||||
return rtrn;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn osal_timer_num_active
|
||||
*
|
||||
* @brief
|
||||
*
|
||||
* This function counts the number of active timers.
|
||||
*
|
||||
* @return uint8 - number of timers
|
||||
*/
|
||||
uint8 osal_timer_num_active( void )
|
||||
{
|
||||
halIntState_t intState;
|
||||
uint8 num_timers = 0;
|
||||
osalTimerRec_t *srchTimer;
|
||||
|
||||
HAL_ENTER_CRITICAL_SECTION( intState ); // Hold off interrupts.
|
||||
|
||||
// Head of the timer list
|
||||
srchTimer = timerHead;
|
||||
|
||||
// Count timers in the list
|
||||
while ( srchTimer != NULL )
|
||||
{
|
||||
num_timers++;
|
||||
srchTimer = srchTimer->next;
|
||||
}
|
||||
|
||||
HAL_EXIT_CRITICAL_SECTION( intState ); // Re-enable interrupts.
|
||||
|
||||
return num_timers;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn osalTimerUpdate
|
||||
*
|
||||
* @brief Update the timer structures for a timer tick.
|
||||
*
|
||||
* @param none
|
||||
*
|
||||
* @return none
|
||||
*********************************************************************/
|
||||
void osalTimerUpdate( uint32 updateTime )
|
||||
{
|
||||
halIntState_t intState;
|
||||
osalTimerRec_t *srchTimer;
|
||||
osalTimerRec_t *prevTimer;
|
||||
|
||||
osalTime_t timeUnion;
|
||||
timeUnion.time32 = updateTime;
|
||||
|
||||
HAL_ENTER_CRITICAL_SECTION( intState ); // Hold off interrupts.
|
||||
// Update the system time
|
||||
osal_systemClock += updateTime;
|
||||
HAL_EXIT_CRITICAL_SECTION( intState ); // Re-enable interrupts.
|
||||
|
||||
// Look for open timer slot
|
||||
if ( timerHead != NULL )
|
||||
{
|
||||
// Add it to the end of the timer list
|
||||
srchTimer = timerHead;
|
||||
prevTimer = (void *)NULL;
|
||||
|
||||
// Look for open timer slot
|
||||
while ( srchTimer )
|
||||
{
|
||||
osalTimerRec_t *freeTimer = NULL;
|
||||
|
||||
HAL_ENTER_CRITICAL_SECTION( intState ); // Hold off interrupts.
|
||||
|
||||
// To minimize time in this critical section, avoid 32-bit math
|
||||
if ((timeUnion.time16[1] == 0) && (timeUnion.time8[1] == 0))
|
||||
{
|
||||
// If upper 24 bits are zero, check lower 8 bits for roll over
|
||||
if (srchTimer->timeout.time8[0] >= timeUnion.time8[0])
|
||||
{
|
||||
// 8-bit math
|
||||
srchTimer->timeout.time8[0] -= timeUnion.time8[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
// 32-bit math
|
||||
if (srchTimer->timeout.time32 > timeUnion.time32)
|
||||
{
|
||||
srchTimer->timeout.time32 -= timeUnion.time32;
|
||||
}
|
||||
else
|
||||
{
|
||||
srchTimer->timeout.time32 = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 32-bit math
|
||||
if (srchTimer->timeout.time32 > timeUnion.time32)
|
||||
{
|
||||
srchTimer->timeout.time32 -= timeUnion.time32;
|
||||
}
|
||||
else
|
||||
{
|
||||
srchTimer->timeout.time32 = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Check for reloading
|
||||
if ( (srchTimer->timeout.time16[0] == 0) && (srchTimer->timeout.time16[1] == 0) &&
|
||||
(srchTimer->reloadTimeout) && (srchTimer->event_flag) )
|
||||
{
|
||||
// Notify the task of a timeout
|
||||
osal_set_event( srchTimer->task_id, srchTimer->event_flag );
|
||||
|
||||
// Reload the timer timeout value
|
||||
srchTimer->timeout.time32 = srchTimer->reloadTimeout;
|
||||
}
|
||||
|
||||
// When timeout or delete (event_flag == 0)
|
||||
if ( ((srchTimer->timeout.time16[0] == 0) && (srchTimer->timeout.time16[1] == 0)) ||
|
||||
(srchTimer->event_flag == 0) )
|
||||
{
|
||||
// Take out of list
|
||||
if ( prevTimer == NULL )
|
||||
{
|
||||
timerHead = srchTimer->next;
|
||||
}
|
||||
else
|
||||
{
|
||||
prevTimer->next = srchTimer->next;
|
||||
}
|
||||
|
||||
// Setup to free memory
|
||||
freeTimer = srchTimer;
|
||||
|
||||
// Next
|
||||
srchTimer = srchTimer->next;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Get next
|
||||
prevTimer = srchTimer;
|
||||
srchTimer = srchTimer->next;
|
||||
}
|
||||
|
||||
HAL_EXIT_CRITICAL_SECTION( intState ); // Re-enable interrupts.
|
||||
|
||||
if ( freeTimer )
|
||||
{
|
||||
if ( (freeTimer->timeout.time16[0] == 0) && (freeTimer->timeout.time16[1] == 0) )
|
||||
{
|
||||
osal_set_event( freeTimer->task_id, freeTimer->event_flag );
|
||||
}
|
||||
osal_mem_free( freeTimer );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef POWER_SAVING
|
||||
/*********************************************************************
|
||||
* @fn osal_adjust_timers
|
||||
*
|
||||
* @brief Update the timer structures for elapsed ticks.
|
||||
*
|
||||
* @param none
|
||||
*
|
||||
* @return none
|
||||
*********************************************************************/
|
||||
void osal_adjust_timers( void )
|
||||
{
|
||||
uint32 eTime;
|
||||
|
||||
if ( timerHead != NULL )
|
||||
{
|
||||
// Compute elapsed time (msec)
|
||||
eTime = TimerElapsed() / TICK_COUNT;
|
||||
|
||||
if ( eTime )
|
||||
{
|
||||
osalTimerUpdate( eTime );
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* POWER_SAVING */
|
||||
|
||||
#if defined POWER_SAVING || defined USE_ICALL
|
||||
/*********************************************************************
|
||||
* @fn osal_next_timeout
|
||||
*
|
||||
* @brief
|
||||
*
|
||||
* Search timer table to return the lowest timeout value. If the
|
||||
* timer list is empty, then the returned timeout will be zero.
|
||||
*
|
||||
* @param none
|
||||
*
|
||||
* @return none
|
||||
*********************************************************************/
|
||||
uint32 osal_next_timeout( void )
|
||||
{
|
||||
uint32 nextTimeout;
|
||||
osalTimerRec_t *srchTimer;
|
||||
|
||||
if ( timerHead != NULL )
|
||||
{
|
||||
// Head of the timer list
|
||||
srchTimer = timerHead;
|
||||
nextTimeout = OSAL_TIMERS_MAX_TIMEOUT;
|
||||
|
||||
// Look for the next timeout timer
|
||||
while ( srchTimer != NULL )
|
||||
{
|
||||
if (srchTimer->timeout.time32 < nextTimeout)
|
||||
{
|
||||
nextTimeout = srchTimer->timeout.time32;
|
||||
}
|
||||
// Check next timer
|
||||
srchTimer = srchTimer->next;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// No timers
|
||||
nextTimeout = 0;
|
||||
}
|
||||
|
||||
return ( nextTimeout );
|
||||
}
|
||||
#endif // POWER_SAVING || USE_ICALL
|
||||
|
||||
/*********************************************************************
|
||||
* @fn osal_GetSystemClock()
|
||||
*
|
||||
* @brief Read the local system clock.
|
||||
*
|
||||
* @param none
|
||||
*
|
||||
* @return local clock in milliseconds
|
||||
*/
|
||||
uint32 osal_GetSystemClock( void )
|
||||
{
|
||||
return ( osal_systemClock );
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
*********************************************************************/
|
||||
146
include/OSAL_Timers.h
Normal file
146
include/OSAL_Timers.h
Normal file
@@ -0,0 +1,146 @@
|
||||
/**************************************************************************************************
|
||||
Filename: OSAL_Timers.h
|
||||
Revised: $Date: 2011-09-16 19:09:24 -0700 (Fri, 16 Sep 2011) $
|
||||
Revision: $Revision: 27618 $
|
||||
|
||||
Description: This file contains the OSAL Timer definition and manipulation functions.
|
||||
|
||||
|
||||
Copyright 2004-2009 Texas Instruments Incorporated. All rights reserved.
|
||||
|
||||
IMPORTANT: Your use of this Software is limited to those specific rights
|
||||
granted under the terms of a software license agreement between the user
|
||||
who downloaded the software, his/her employer (which must be your employer)
|
||||
and Texas Instruments Incorporated (the "License"). You may not use this
|
||||
Software unless you agree to abide by the terms of the License. The License
|
||||
limits your use, and you acknowledge, that the Software may not be modified,
|
||||
copied or distributed unless embedded on a Texas Instruments microcontroller
|
||||
or used solely and exclusively in conjunction with a Texas Instruments radio
|
||||
frequency transceiver, which is integrated into your product. Other than for
|
||||
the foregoing purpose, you may not use, reproduce, copy, prepare derivative
|
||||
works of, modify, distribute, perform, display or sell this Software and/or
|
||||
its documentation for any purpose.
|
||||
|
||||
YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
|
||||
PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
||||
INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
|
||||
NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
|
||||
TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
|
||||
NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
|
||||
LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
|
||||
INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
|
||||
OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
|
||||
OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
|
||||
(INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
|
||||
|
||||
Should you have any questions regarding your right to use this Software,
|
||||
contact Texas Instruments Incorporated at www.TI.com.
|
||||
**************************************************************************************************/
|
||||
|
||||
#ifndef OSAL_TIMERS_H
|
||||
#define OSAL_TIMERS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/*********************************************************************
|
||||
* INCLUDES
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
* MACROS
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
* CONSTANTS
|
||||
* the unit is chosen such that the 320us tick equivalent can fit in
|
||||
* 32 bits.
|
||||
*/
|
||||
#define OSAL_TIMERS_MAX_TIMEOUT 0x28f5c28e /* unit is ms*/
|
||||
|
||||
/*********************************************************************
|
||||
* TYPEDEFS
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
* GLOBAL VARIABLES
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
* FUNCTIONS
|
||||
*/
|
||||
|
||||
/*
|
||||
* Initialization for the OSAL Timer System.
|
||||
*/
|
||||
extern void osalTimerInit( void );
|
||||
|
||||
/*
|
||||
* Set a Timer
|
||||
*/
|
||||
extern uint8 osal_start_timerEx( uint8 task_id, uint16 event_id, uint32 timeout_value );
|
||||
|
||||
/*
|
||||
* Set a timer that reloads itself.
|
||||
*/
|
||||
extern uint8 osal_start_reload_timer( uint8 taskID, uint16 event_id, uint32 timeout_value );
|
||||
|
||||
/*
|
||||
* Stop a Timer
|
||||
*/
|
||||
extern uint8 osal_stop_timerEx( uint8 task_id, uint16 event_id );
|
||||
|
||||
/*
|
||||
* Get the tick count of a Timer.
|
||||
*/
|
||||
extern uint32 osal_get_timeoutEx( uint8 task_id, uint16 event_id );
|
||||
|
||||
/*
|
||||
* Simulated Timer Interrupt Service Routine
|
||||
*/
|
||||
|
||||
extern void osal_timer_ISR( void );
|
||||
|
||||
/*
|
||||
* Adjust timer tables
|
||||
*/
|
||||
extern void osal_adjust_timers( void );
|
||||
|
||||
/*
|
||||
* Update timer tables
|
||||
*/
|
||||
extern void osalTimerUpdate( uint32 updateTime );
|
||||
|
||||
/*
|
||||
* Count active timers
|
||||
*/
|
||||
extern uint8 osal_timer_num_active( void );
|
||||
|
||||
/*
|
||||
* Set the hardware timer interrupts for sleep mode.
|
||||
* These functions should only be called in OSAL_PwrMgr.c
|
||||
*/
|
||||
extern void osal_sleep_timers( void );
|
||||
extern void osal_unsleep_timers( void );
|
||||
|
||||
/*
|
||||
* Read the system clock - returns milliseconds
|
||||
*/
|
||||
extern uint32 osal_GetSystemClock( void );
|
||||
|
||||
/*
|
||||
* Get the next OSAL timer expiration.
|
||||
* This function should only be called in OSAL_PwrMgr.c
|
||||
*/
|
||||
extern uint32 osal_next_timeout( void );
|
||||
|
||||
/*********************************************************************
|
||||
*********************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* OSAL_TIMERS_H */
|
||||
489
include/ZComDef.h
Normal file
489
include/ZComDef.h
Normal file
@@ -0,0 +1,489 @@
|
||||
/**************************************************************************************************
|
||||
Filename: ZComDef.h
|
||||
Revised: $Date: 2014-11-24 23:50:22 -0800 (Mon, 24 Nov 2014) $
|
||||
Revision: $Revision: 41235 $
|
||||
|
||||
Description: Type definitions and macros.
|
||||
|
||||
|
||||
Copyright 2004-2014 Texas Instruments Incorporated. All rights reserved.
|
||||
|
||||
IMPORTANT: Your use of this Software is limited to those specific rights
|
||||
granted under the terms of a software license agreement between the user
|
||||
who downloaded the software, his/her employer (which must be your employer)
|
||||
and Texas Instruments Incorporated (the "License"). You may not use this
|
||||
Software unless you agree to abide by the terms of the License. The License
|
||||
limits your use, and you acknowledge, that the Software may not be modified,
|
||||
copied or distributed unless embedded on a Texas Instruments microcontroller
|
||||
or used solely and exclusively in conjunction with a Texas Instruments radio
|
||||
frequency transceiver, which is integrated into your product. Other than for
|
||||
the foregoing purpose, you may not use, reproduce, copy, prepare derivative
|
||||
works of, modify, distribute, perform, display or sell this Software and/or
|
||||
its documentation for any purpose.
|
||||
|
||||
YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
|
||||
PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
||||
INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
|
||||
NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
|
||||
TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
|
||||
NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
|
||||
LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
|
||||
INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
|
||||
OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
|
||||
OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
|
||||
(INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
|
||||
|
||||
Should you have any questions regarding your right to use this Software,
|
||||
contact Texas Instruments Incorporated at www.TI.com.
|
||||
**************************************************************************************************/
|
||||
|
||||
#ifndef ZCOMDEF_H
|
||||
#define ZCOMDEF_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
* INCLUDES
|
||||
*/
|
||||
#include "comdef.h"
|
||||
#include "saddr.h"
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
* CONSTANTS
|
||||
*/
|
||||
#define osal_cpyExtAddr(a, b) sAddrExtCpy((a), (const uint8 *)(b))
|
||||
#define osal_ExtAddrEqual(a, b) sAddrExtCmp((const uint8 *)(a), (const uint8 *)(b))
|
||||
#define osal_copyAddress(a, b) sAddrCpy( (sAddr_t *)(a), (const sAddr_t *)(b) )
|
||||
|
||||
/*********************************************************************
|
||||
* CONSTANTS
|
||||
*/
|
||||
|
||||
// Build Device Types - Used during compilation
|
||||
// These are the types of devices to build
|
||||
// Bit masked into ZSTACK_DEVICE_BUILD
|
||||
#define DEVICE_BUILD_COORDINATOR 0x01
|
||||
#define DEVICE_BUILD_ROUTER 0x02
|
||||
#define DEVICE_BUILD_ENDDEVICE 0x04
|
||||
|
||||
/*** Return Values ***/
|
||||
#define ZSUCCESS SUCCESS
|
||||
|
||||
/*** Component IDs ***/
|
||||
#define COMPID_OSAL 0
|
||||
#define COMPID_MTEL 1
|
||||
#define COMPID_MTSPCI 2
|
||||
#define COMPID_NWK 3
|
||||
#define COMPID_NWKIF 4
|
||||
#define COMPID_MACCB 5
|
||||
#define COMPID_MAC 6
|
||||
#define COMPID_APP 7
|
||||
#define COMPID_TEST 8
|
||||
|
||||
#define COMPID_RTG 9
|
||||
#define COMPID_DATA 11
|
||||
|
||||
/* Temp CompIDs for testing */
|
||||
#define COMPID_TEST_NWK_STARTUP 20
|
||||
#define COMPID_TEST_SCAN_CONFIRM 21
|
||||
#define COMPID_TEST_ASSOC_CONFIRM 22
|
||||
#define COMPID_TEST_REMOTE_DATA_CONFIRM 23
|
||||
|
||||
// OSAL NV Item IDs
|
||||
#define ZCD_NV_EX_LEGACY 0x0000
|
||||
#define ZCD_NV_EX_ADDRMGR 0x0001
|
||||
#define ZCD_NV_EX_BINDING_TABLE 0x0002
|
||||
#define ZCD_NV_EX_DEVICE_LIST 0x0003
|
||||
|
||||
// OSAL NV item IDs
|
||||
#define ZCD_NV_EXTADDR 0x0001
|
||||
#define ZCD_NV_BOOTCOUNTER 0x0002
|
||||
#define ZCD_NV_STARTUP_OPTION 0x0003
|
||||
#define ZCD_NV_START_DELAY 0x0004
|
||||
|
||||
// NWK Layer NV item IDs
|
||||
#define ZCD_NV_NIB 0x0021
|
||||
#define ZCD_NV_DEVICE_LIST 0x0022
|
||||
#define ZCD_NV_ADDRMGR 0x0023
|
||||
#define ZCD_NV_POLL_RATE_OLD16 0x0024 // Deprecated when poll rate changed from 16 to 32 bits
|
||||
#define ZCD_NV_POLL_RATE 0x0035
|
||||
#define ZCD_NV_QUEUED_POLL_RATE 0x0025
|
||||
#define ZCD_NV_RESPONSE_POLL_RATE 0x0026
|
||||
#define ZCD_NV_REJOIN_POLL_RATE 0x0027
|
||||
#define ZCD_NV_DATA_RETRIES 0x0028
|
||||
#define ZCD_NV_POLL_FAILURE_RETRIES 0x0029
|
||||
#define ZCD_NV_STACK_PROFILE 0x002A
|
||||
#define ZCD_NV_INDIRECT_MSG_TIMEOUT 0x002B
|
||||
#define ZCD_NV_ROUTE_EXPIRY_TIME 0x002C
|
||||
#define ZCD_NV_EXTENDED_PAN_ID 0x002D
|
||||
#define ZCD_NV_BCAST_RETRIES 0x002E
|
||||
#define ZCD_NV_PASSIVE_ACK_TIMEOUT 0x002F
|
||||
#define ZCD_NV_BCAST_DELIVERY_TIME 0x0030
|
||||
#define ZCD_NV_NWK_MODE 0x0031
|
||||
#define ZCD_NV_CONCENTRATOR_ENABLE 0x0032
|
||||
#define ZCD_NV_CONCENTRATOR_DISCOVERY 0x0033
|
||||
#define ZCD_NV_CONCENTRATOR_RADIUS 0x0034
|
||||
// 0x0035 used above for new 32 bit Poll Rate
|
||||
#define ZCD_NV_CONCENTRATOR_RC 0x0036
|
||||
#define ZCD_NV_NWK_MGR_MODE 0x0037
|
||||
#define ZCD_NV_SRC_RTG_EXPIRY_TIME 0x0038
|
||||
#define ZCD_NV_ROUTE_DISCOVERY_TIME 0x0039
|
||||
#define ZCD_NV_NWK_ACTIVE_KEY_INFO 0x003A
|
||||
#define ZCD_NV_NWK_ALTERN_KEY_INFO 0x003B
|
||||
#define ZCD_NV_ROUTER_OFF_ASSOC_CLEANUP 0x003C
|
||||
#define ZCD_NV_NWK_LEAVE_REQ_ALLOWED 0x003D
|
||||
#define ZCD_NV_NWK_CHILD_AGE_ENABLE 0x003E
|
||||
#define ZCD_NV_DEVICE_LIST_KA_TIMEOUT 0x003F
|
||||
|
||||
// APS Layer NV item IDs
|
||||
#define ZCD_NV_BINDING_TABLE 0x0041
|
||||
#define ZCD_NV_GROUP_TABLE 0x0042
|
||||
#define ZCD_NV_APS_FRAME_RETRIES 0x0043
|
||||
#define ZCD_NV_APS_ACK_WAIT_DURATION 0x0044
|
||||
#define ZCD_NV_APS_ACK_WAIT_MULTIPLIER 0x0045
|
||||
#define ZCD_NV_BINDING_TIME 0x0046
|
||||
#define ZCD_NV_APS_USE_EXT_PANID 0x0047
|
||||
#define ZCD_NV_APS_USE_INSECURE_JOIN 0x0048
|
||||
#define ZCD_NV_COMMISSIONED_NWK_ADDR 0x0049
|
||||
|
||||
#define ZCD_NV_APS_NONMEMBER_RADIUS 0x004B // Multicast non_member radius
|
||||
#define ZCD_NV_APS_LINK_KEY_TABLE 0x004C
|
||||
#define ZCD_NV_APS_DUPREJ_TIMEOUT_INC 0x004D
|
||||
#define ZCD_NV_APS_DUPREJ_TIMEOUT_COUNT 0x004E
|
||||
#define ZCD_NV_APS_DUPREJ_TABLE_SIZE 0x004F
|
||||
|
||||
// System statistics and metrics NV ID
|
||||
#define ZCD_NV_DIAGNOSTIC_STATS 0x0050
|
||||
|
||||
// Additional NWK Layer NV item IDs
|
||||
#define ZCD_NV_NWK_PARENT_INFO 0x0051
|
||||
#define ZCD_NV_NWK_ENDDEV_TIMEOUT_DEF 0x0052
|
||||
#define ZCD_NV_END_DEV_TIMEOUT_VALUE 0x0053
|
||||
#define ZCD_NV_END_DEV_CONFIGURATION 0x0054
|
||||
|
||||
#define ZCD_NV_BDBNODEISONANETWORK 0x0055 //bdbNodeIsOnANetwork attribute
|
||||
#define ZCD_NV_BDBREPORTINGCONFIG 0x0056
|
||||
|
||||
// Security NV Item IDs
|
||||
#define ZCD_NV_SECURITY_LEVEL 0x0061
|
||||
#define ZCD_NV_PRECFGKEY 0x0062
|
||||
#define ZCD_NV_PRECFGKEYS_ENABLE 0x0063
|
||||
#define ZCD_NV_SECURITY_MODE 0x0064
|
||||
#define ZCD_NV_SECURE_PERMIT_JOIN 0x0065
|
||||
#define ZCD_NV_APS_LINK_KEY_TYPE 0x0066
|
||||
#define ZCD_NV_APS_ALLOW_R19_SECURITY 0x0067
|
||||
#define ZCD_NV_DISTRIBUTED_KEY 0x0068 //Default distributed nwk key Id. Nv ID not in use
|
||||
|
||||
#define ZCD_NV_IMPLICIT_CERTIFICATE 0x0069
|
||||
#define ZCD_NV_DEVICE_PRIVATE_KEY 0x006A
|
||||
#define ZCD_NV_CA_PUBLIC_KEY 0x006B
|
||||
#define ZCD_NV_KE_MAX_DEVICES 0x006C
|
||||
|
||||
#define ZCD_NV_USE_DEFAULT_TCLK 0x006D
|
||||
//deprecated: TRUSTCENTER_ADDR (16-bit) 0x006E
|
||||
#define ZCD_NV_RNG_COUNTER 0x006F
|
||||
#define ZCD_NV_RANDOM_SEED 0x0070
|
||||
#define ZCD_NV_TRUSTCENTER_ADDR 0x0071
|
||||
|
||||
#define ZCD_NV_CERT_283 0x0072
|
||||
#define ZCD_NV_PRIVATE_KEY_283 0x0073
|
||||
#define ZCD_NV_PUBLIC_KEY_283 0x0074
|
||||
|
||||
#define ZCD_NV_NWK_SEC_MATERIAL_TABLE_START 0x0075
|
||||
#define ZCD_NV_NWK_SEC_MATERIAL_TABLE_END 0x0080
|
||||
|
||||
|
||||
// ZDO NV Item IDs
|
||||
#define ZCD_NV_USERDESC 0x0081
|
||||
#define ZCD_NV_NWKKEY 0x0082
|
||||
#define ZCD_NV_PANID 0x0083
|
||||
#define ZCD_NV_CHANLIST 0x0084
|
||||
#define ZCD_NV_LEAVE_CTRL 0x0085
|
||||
#define ZCD_NV_SCAN_DURATION 0x0086
|
||||
#define ZCD_NV_LOGICAL_TYPE 0x0087
|
||||
#define ZCD_NV_NWKMGR_MIN_TX 0x0088
|
||||
#define ZCD_NV_NWKMGR_ADDR 0x0089
|
||||
|
||||
#define ZCD_NV_ZDO_DIRECT_CB 0x008F
|
||||
|
||||
// ZCL NV item IDs
|
||||
#define ZCD_NV_SCENE_TABLE 0x0091
|
||||
#define ZCD_NV_MIN_FREE_NWK_ADDR 0x0092
|
||||
#define ZCD_NV_MAX_FREE_NWK_ADDR 0x0093
|
||||
#define ZCD_NV_MIN_FREE_GRP_ID 0x0094
|
||||
#define ZCD_NV_MAX_FREE_GRP_ID 0x0095
|
||||
#define ZCD_NV_MIN_GRP_IDS 0x0096
|
||||
#define ZCD_NV_MAX_GRP_IDS 0x0097
|
||||
#define ZCD_NV_OTA_BLOCK_REQ_DELAY 0x0098
|
||||
|
||||
// Non-standard NV item IDs
|
||||
#define ZCD_NV_SAPI_ENDPOINT 0x00A1
|
||||
|
||||
// NV Items Reserved for Commissioning Cluster Startup Attribute Set (SAS):
|
||||
// 0x00B1 - 0x00BF: Parameters related to APS and NWK layers
|
||||
// 0x00C1 - 0x00CF: Parameters related to Security
|
||||
// 0x00D1 - 0x00DF: Current key parameters
|
||||
#define ZCD_NV_SAS_SHORT_ADDR 0x00B1
|
||||
#define ZCD_NV_SAS_EXT_PANID 0x00B2
|
||||
#define ZCD_NV_SAS_PANID 0x00B3
|
||||
#define ZCD_NV_SAS_CHANNEL_MASK 0x00B4
|
||||
#define ZCD_NV_SAS_PROTOCOL_VER 0x00B5
|
||||
#define ZCD_NV_SAS_STACK_PROFILE 0x00B6
|
||||
#define ZCD_NV_SAS_STARTUP_CTRL 0x00B7
|
||||
|
||||
#define ZCD_NV_SAS_TC_ADDR 0x00C1
|
||||
#define ZCD_NV_SAS_TC_MASTER_KEY 0x00C2
|
||||
#define ZCD_NV_SAS_NWK_KEY 0x00C3
|
||||
#define ZCD_NV_SAS_USE_INSEC_JOIN 0x00C4
|
||||
#define ZCD_NV_SAS_PRECFG_LINK_KEY 0x00C5
|
||||
#define ZCD_NV_SAS_NWK_KEY_SEQ_NUM 0x00C6
|
||||
#define ZCD_NV_SAS_NWK_KEY_TYPE 0x00C7
|
||||
#define ZCD_NV_SAS_NWK_MGR_ADDR 0x00C8
|
||||
|
||||
#define ZCD_NV_SAS_CURR_TC_MASTER_KEY 0x00D1
|
||||
#define ZCD_NV_SAS_CURR_NWK_KEY 0x00D2
|
||||
#define ZCD_NV_SAS_CURR_PRECFG_LINK_KEY 0x00D3
|
||||
|
||||
// NV Items Reserved for Trust Center Link Key Table entries
|
||||
// 0x0101 - 0x01FF
|
||||
#define ZCD_NV_TCLK_SEED 0x0101 //Seed
|
||||
#define ZCD_NV_TCLK_JOIN_DEV 0x0102 //Nv Id where Joining device store their APS key. Key is in plain text.
|
||||
#define ZCD_NV_TCLK_DEFAULT 0x0103 //Not accually a Nv Item but Id used by SecMgr
|
||||
|
||||
#define ZCD_NV_TCLK_IC_TABLE_START 0x0104 //IC keys, refered with shift byte
|
||||
#define ZCD_NV_TCLK_IC_TABLE_END 0x0110
|
||||
|
||||
#define ZCD_NV_TCLK_TABLE_START 0x0111 //Entries to store users of the keys
|
||||
#define ZCD_NV_TCLK_TABLE_END 0x01FF
|
||||
|
||||
// NV Items Reserved for APS Link Key Table entries
|
||||
// 0x0201 - 0x02FF
|
||||
#define ZCD_NV_APS_LINK_KEY_DATA_START 0x0201 // APS key data
|
||||
#define ZCD_NV_APS_LINK_KEY_DATA_END 0x02FF
|
||||
|
||||
// NV items used to duplicate system elements
|
||||
#define ZCD_NV_DUPLICATE_BINDING_TABLE 0x0300
|
||||
#define ZCD_NV_DUPLICATE_DEVICE_LIST 0x0301
|
||||
#define ZCD_NV_DUPLICATE_DEVICE_LIST_KA_TIMEOUT 0x0302
|
||||
|
||||
// NV Items Reserved for Proxy Table entries
|
||||
// 0x0310 - 0x033F
|
||||
#define ZCD_NV_PROXY_TABLE_START 0x0310
|
||||
#define ZCD_NV_PROXY_TABLE_END 0x033F
|
||||
|
||||
// NV Items Reserved for applications (user applications)
|
||||
// 0x0401 – 0x0FFF
|
||||
|
||||
|
||||
// ZCD_NV_STARTUP_OPTION values
|
||||
// These are bit weighted - you can OR these together.
|
||||
// Setting one of these bits will set their associated NV items
|
||||
// to code initialized values.
|
||||
#define ZCD_STARTOPT_DEFAULT_CONFIG_STATE 0x01
|
||||
#define ZCD_STARTOPT_DEFAULT_NETWORK_STATE 0x02
|
||||
#define ZCD_STARTOPT_AUTO_START 0x04
|
||||
#define ZCD_STARTOPT_CLEAR_CONFIG ZCD_STARTOPT_DEFAULT_CONFIG_STATE
|
||||
#define ZCD_STARTOPT_CLEAR_STATE ZCD_STARTOPT_DEFAULT_NETWORK_STATE
|
||||
//FrameCounter should be persistence across factory new resets, this should not
|
||||
//used as part of FN reset procedure. Set to reset the FrameCounter of all
|
||||
//Nwk Security Material
|
||||
#define ZCD_STARTOPT_CLEAR_NWK_FRAME_COUNTER 0x80
|
||||
|
||||
#define ZCL_KE_IMPLICIT_CERTIFICATE_LEN 48
|
||||
#define ZCL_KE_CA_PUBLIC_KEY_LEN 22
|
||||
#define ZCL_KE_DEVICE_PRIVATE_KEY_LEN 21
|
||||
|
||||
/*********************************************************************
|
||||
* TYPEDEFS
|
||||
*/
|
||||
|
||||
/*** Data Types ***/
|
||||
typedef uint8 byte;
|
||||
typedef uint16 UINT16;
|
||||
typedef int16 INT16;
|
||||
|
||||
enum
|
||||
{
|
||||
AddrNotPresent = 0,
|
||||
AddrGroup = 1,
|
||||
Addr16Bit = 2,
|
||||
Addr64Bit = 3,
|
||||
AddrBroadcast = 15
|
||||
};
|
||||
|
||||
#define Z_EXTADDR_LEN 8
|
||||
|
||||
typedef byte ZLongAddr_t[Z_EXTADDR_LEN];
|
||||
|
||||
typedef struct
|
||||
{
|
||||
union
|
||||
{
|
||||
uint16 shortAddr;
|
||||
ZLongAddr_t extAddr;
|
||||
} addr;
|
||||
byte addrMode;
|
||||
} zAddrType_t;
|
||||
|
||||
// Redefined Generic Status Return Values for code backwards compatibility
|
||||
#define ZSuccess SUCCESS
|
||||
#define ZFailure FAILURE
|
||||
#define ZInvalidParameter INVALIDPARAMETER
|
||||
|
||||
// ZStack status values must start at 0x10, after the generic status values (defined in comdef.h)
|
||||
#define ZMemError 0x10
|
||||
#define ZBufferFull 0x11
|
||||
#define ZUnsupportedMode 0x12
|
||||
#define ZMacMemError 0x13
|
||||
|
||||
#define ZSapiInProgress 0x20
|
||||
#define ZSapiTimeout 0x21
|
||||
#define ZSapiInit 0x22
|
||||
|
||||
#define ZNotAuthorized 0x7E
|
||||
|
||||
#define ZMalformedCmd 0x80
|
||||
#define ZUnsupClusterCmd 0x81
|
||||
|
||||
// OTA Status values
|
||||
#define ZOtaAbort 0x95
|
||||
#define ZOtaImageInvalid 0x96
|
||||
#define ZOtaWaitForData 0x97
|
||||
#define ZOtaNoImageAvailable 0x98
|
||||
#define ZOtaRequireMoreImage 0x99
|
||||
|
||||
// APS status values
|
||||
#define ZApsFail 0xb1
|
||||
#define ZApsTableFull 0xb2
|
||||
#define ZApsIllegalRequest 0xb3
|
||||
#define ZApsInvalidBinding 0xb4
|
||||
#define ZApsUnsupportedAttrib 0xb5
|
||||
#define ZApsNotSupported 0xb6
|
||||
#define ZApsNoAck 0xb7
|
||||
#define ZApsDuplicateEntry 0xb8
|
||||
#define ZApsNoBoundDevice 0xb9
|
||||
#define ZApsNotAllowed 0xba
|
||||
#define ZApsNotAuthenticated 0xbb
|
||||
|
||||
// Security status values
|
||||
#define ZSecNoKey 0xa1
|
||||
#define ZSecOldFrmCount 0xa2
|
||||
#define ZSecMaxFrmCount 0xa3
|
||||
#define ZSecCcmFail 0xa4
|
||||
#define ZSecFailure 0xad
|
||||
|
||||
|
||||
// NWK status values
|
||||
#define ZNwkInvalidParam 0xc1
|
||||
#define ZNwkInvalidRequest 0xc2
|
||||
#define ZNwkNotPermitted 0xc3
|
||||
#define ZNwkStartupFailure 0xc4
|
||||
#define ZNwkAlreadyPresent 0xc5
|
||||
#define ZNwkSyncFailure 0xc6
|
||||
#define ZNwkTableFull 0xc7
|
||||
#define ZNwkUnknownDevice 0xc8
|
||||
#define ZNwkUnsupportedAttribute 0xc9
|
||||
#define ZNwkNoNetworks 0xca
|
||||
#define ZNwkLeaveUnconfirmed 0xcb
|
||||
#define ZNwkNoAck 0xcc // not in spec
|
||||
#define ZNwkNoRoute 0xcd
|
||||
|
||||
// MAC status values
|
||||
#define ZMacSuccess 0x00
|
||||
#define ZMacBeaconLoss 0xe0
|
||||
#define ZMacChannelAccessFailure 0xe1
|
||||
#define ZMacDenied 0xe2
|
||||
#define ZMacDisableTrxFailure 0xe3
|
||||
#define ZMacFailedSecurityCheck 0xe4
|
||||
#define ZMacFrameTooLong 0xe5
|
||||
#define ZMacInvalidGTS 0xe6
|
||||
#define ZMacInvalidHandle 0xe7
|
||||
#define ZMacInvalidParameter 0xe8
|
||||
#define ZMacNoACK 0xe9
|
||||
#define ZMacNoBeacon 0xea
|
||||
#define ZMacNoData 0xeb
|
||||
#define ZMacNoShortAddr 0xec
|
||||
#define ZMacOutOfCap 0xed
|
||||
#define ZMacPANIDConflict 0xee
|
||||
#define ZMacRealignment 0xef
|
||||
#define ZMacTransactionExpired 0xf0
|
||||
#define ZMacTransactionOverFlow 0xf1
|
||||
#define ZMacTxActive 0xf2
|
||||
#define ZMacUnAvailableKey 0xf3
|
||||
#define ZMacUnsupportedAttribute 0xf4
|
||||
#define ZMacUnsupported 0xf5
|
||||
#define ZMacSrcMatchInvalidIndex 0xff
|
||||
|
||||
typedef Status_t ZStatus_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8 txCounter; // Counter of transmission success/failures
|
||||
uint8 txCost; // Average of sending rssi values if link staus is enabled
|
||||
// i.e. NWK_LINK_STATUS_PERIOD is defined as non zero
|
||||
uint8 rxLqi; // average of received rssi values
|
||||
// needs to be converted to link cost (1-7) before used
|
||||
uint8 inKeySeqNum; // security key sequence number
|
||||
uint32 inFrmCntr; // security frame counter..
|
||||
uint16 txFailure; // higher values indicate more failures
|
||||
} linkInfo_t;
|
||||
|
||||
/*********************************************************************
|
||||
* Global System Messages
|
||||
*/
|
||||
|
||||
#define SPI_INCOMING_ZTOOL_PORT 0x21 // Raw data from ZTool Port (not implemented)
|
||||
#define SPI_INCOMING_ZAPP_DATA 0x22 // Raw data from the ZAPP port (see serialApp.c)
|
||||
#define MT_SYS_APP_MSG 0x23 // Raw data from an MT Sys message
|
||||
#define MT_SYS_APP_RSP_MSG 0x24 // Raw data output for an MT Sys message
|
||||
#define MT_SYS_OTA_MSG 0x25 // Raw data output for an MT OTA Rsp
|
||||
#define MT_SYS_APP_PB_ZCL_CMD 0x26 // MT APP PB ZCL command
|
||||
|
||||
#define AF_DATA_CONFIRM_CMD 0xFD // Data confirmation
|
||||
#define AF_REFLECT_ERROR_CMD 0xFE // Reflected message error message
|
||||
#define AF_INCOMING_MSG_CMD 0x1A // Incoming MSG type message
|
||||
#define AF_INCOMING_KVP_CMD 0x1B // Incoming KVP type message
|
||||
#define AF_INCOMING_GRP_KVP_CMD 0x1C // Incoming Group KVP type message
|
||||
|
||||
//#define KEY_CHANGE 0xC0 // Key Events
|
||||
|
||||
#define ZDO_NEW_DSTADDR 0xD0 // ZDO has received a new DstAddr for this app
|
||||
#define ZDO_STATE_CHANGE 0xD1 // ZDO has changed the device's network state
|
||||
#define ZDO_MATCH_DESC_RSP_SENT 0xD2 // ZDO match descriptor response was sent
|
||||
#define ZDO_CB_MSG 0xD3 // ZDO incoming message callback
|
||||
#define ZDO_NETWORK_REPORT 0xD4 // ZDO received a Network Report message
|
||||
#define ZDO_NETWORK_UPDATE 0xD5 // ZDO received a Network Update message
|
||||
#define ZDO_ADDR_CHANGE_IND 0xD6 // ZDO was informed of device address change
|
||||
|
||||
#define NM_CHANNEL_INTERFERE 0x31 // NwkMgr received a Channel Interference message
|
||||
#define NM_ED_SCAN_CONFIRM 0x32 // NwkMgr received an ED Scan Confirm message
|
||||
#define SAPS_CHANNEL_CHANGE 0x33 // Stub APS has changed the device's channel
|
||||
#define ZCL_INCOMING_MSG 0x34 // Incoming ZCL foundation message
|
||||
#define ZCL_KEY_ESTABLISH_IND 0x35 // ZCL Key Establishment Completion Indication
|
||||
#define ZCL_OTA_CALLBACK_IND 0x36 // ZCL OTA Completion Indication
|
||||
|
||||
|
||||
// OSAL System Message IDs/Events Reserved for applications (user applications)
|
||||
// 0xE0 – 0xFC
|
||||
|
||||
/*********************************************************************
|
||||
* GLOBAL VARIABLES
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
* FUNCTIONS
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
*********************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* ZCOMDEF_H */
|
||||
161
include/comdef.h
Normal file
161
include/comdef.h
Normal file
@@ -0,0 +1,161 @@
|
||||
/**************************************************************************************************
|
||||
Filename: comdef.h
|
||||
Revised: $Date: 2010-07-28 08:42:48 -0700 (Wed, 28 Jul 2010) $
|
||||
Revision: $Revision: 23160 $
|
||||
|
||||
Description: Type definitions and macros.
|
||||
|
||||
|
||||
Copyright 2004-2008 Texas Instruments Incorporated. All rights reserved.
|
||||
|
||||
IMPORTANT: Your use of this Software is limited to those specific rights
|
||||
granted under the terms of a software license agreement between the user
|
||||
who downloaded the software, his/her employer (which must be your employer)
|
||||
and Texas Instruments Incorporated (the "License"). You may not use this
|
||||
Software unless you agree to abide by the terms of the License. The License
|
||||
limits your use, and you acknowledge, that the Software may not be modified,
|
||||
copied or distributed unless embedded on a Texas Instruments microcontroller
|
||||
or used solely and exclusively in conjunction with a Texas Instruments radio
|
||||
frequency transceiver, which is integrated into your product. Other than for
|
||||
the foregoing purpose, you may not use, reproduce, copy, prepare derivative
|
||||
works of, modify, distribute, perform, display or sell this Software and/or
|
||||
its documentation for any purpose.
|
||||
|
||||
YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
|
||||
PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
||||
INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
|
||||
NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
|
||||
TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
|
||||
NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
|
||||
LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
|
||||
INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
|
||||
OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
|
||||
OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
|
||||
(INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
|
||||
|
||||
Should you have any questions regarding your right to use this Software,
|
||||
contact Texas Instruments Incorporated at www.TI.com.
|
||||
**************************************************************************************************/
|
||||
|
||||
#ifndef COMDEF_H
|
||||
#define COMDEF_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
* INCLUDES
|
||||
*/
|
||||
|
||||
/* HAL */
|
||||
#include "hal_types.h"
|
||||
#include "hal_defs.h"
|
||||
|
||||
/*********************************************************************
|
||||
* Lint Keywords
|
||||
*/
|
||||
#define VOID (void)
|
||||
|
||||
#define NULL_OK
|
||||
#define INP
|
||||
#define OUTP
|
||||
#define UNUSED
|
||||
#define ONLY
|
||||
#define READONLY
|
||||
#define SHARED
|
||||
#define KEEP
|
||||
#define RELAX
|
||||
|
||||
/*********************************************************************
|
||||
* CONSTANTS
|
||||
*/
|
||||
|
||||
#ifndef false
|
||||
#define false 0
|
||||
#endif
|
||||
|
||||
#ifndef true
|
||||
#define true 1
|
||||
#endif
|
||||
|
||||
#ifndef CONST
|
||||
#define CONST const
|
||||
#endif
|
||||
|
||||
#ifndef GENERIC
|
||||
#define GENERIC
|
||||
#endif
|
||||
|
||||
/*** Generic Status Return Values ***/
|
||||
#define SUCCESS 0x00
|
||||
#define FAILURE 0x01
|
||||
#define INVALIDPARAMETER 0x02
|
||||
#define INVALID_TASK 0x03
|
||||
#define MSG_BUFFER_NOT_AVAIL 0x04
|
||||
#define INVALID_MSG_POINTER 0x05
|
||||
#define INVALID_EVENT_ID 0x06
|
||||
#define INVALID_INTERRUPT_ID 0x07
|
||||
#define NO_TIMER_AVAIL 0x08
|
||||
#define NV_ITEM_UNINIT 0x09
|
||||
#define NV_OPER_FAILED 0x0A
|
||||
#define INVALID_MEM_SIZE 0x0B
|
||||
#define NV_BAD_ITEM_LEN 0x0C
|
||||
#define NV_INVALID_DATA 0x0D
|
||||
|
||||
/*** NV Error Mask ***/
|
||||
#define NV_NIB_INIT_FAILURE 0x01
|
||||
#define NV_ADDR_MGR_INIT_FAILURE 0x02
|
||||
#define NV_ASSOC_INIT_FAILURE 0x04
|
||||
#define NV_BIND_TBL_INIT_FAILURE 0x08
|
||||
#define NV_GRPS_INIT_FAILURE 0x10
|
||||
#define NV_SEC_MGR_FAILURE 0x20
|
||||
|
||||
/*********************************************************************
|
||||
* TYPEDEFS
|
||||
*/
|
||||
|
||||
// Generic Status return
|
||||
typedef uint8 Status_t;
|
||||
|
||||
// Data types
|
||||
typedef int32 int24;
|
||||
typedef uint32 uint24;
|
||||
|
||||
/*********************************************************************
|
||||
* Global System Events
|
||||
*/
|
||||
|
||||
#define SYS_EVENT_MSG 0x8000 // A message is waiting event
|
||||
|
||||
/*********************************************************************
|
||||
* Global Generic System Messages
|
||||
*/
|
||||
|
||||
#define KEY_CHANGE 0xC0 // Key Events
|
||||
|
||||
// OSAL System Message IDs/Events Reserved for applications (user applications)
|
||||
// 0xE0 – 0xFC
|
||||
|
||||
/*********************************************************************
|
||||
* MACROS
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
* GLOBAL VARIABLES
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
* FUNCTIONS
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
*********************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* COMDEF_H */
|
||||
84
include/hw_types.h
Normal file
84
include/hw_types.h
Normal file
@@ -0,0 +1,84 @@
|
||||
/******************************************************************************
|
||||
* Filename: hw_types.h
|
||||
* Revised: $Date: 2013-10-07 00:18:15 -0700 (Mon, 07 Oct 2013) $
|
||||
* Revision: $Revision: 10757 $
|
||||
*
|
||||
* Description: Common types and macros.
|
||||
*
|
||||
* Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* Neither the name of Texas Instruments Incorporated nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
#ifndef __HW_TYPES_H__
|
||||
#define __HW_TYPES_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Define a boolean type, and values for true and false.
|
||||
//
|
||||
//*****************************************************************************
|
||||
typedef unsigned char tBoolean;
|
||||
|
||||
#ifndef true
|
||||
#define true 1
|
||||
#endif
|
||||
|
||||
#ifndef false
|
||||
#define false 0
|
||||
#endif
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Macros for hardware access, both direct and via the bit-band region.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define HWREG(x) \
|
||||
(*((volatile uint32_t *)(x)))
|
||||
#define HWREGH(x) \
|
||||
(*((volatile uint16_t *)(x)))
|
||||
#define HWREGB(x) \
|
||||
(*((volatile unsigned char *)(x)))
|
||||
#define HWREGBITW(x, b) \
|
||||
HWREG(((uint32_t)(x) & 0xF0000000) | 0x02000000 | \
|
||||
(((uint32_t)(x) & 0x000FFFFF) << 5) | ((b) << 2))
|
||||
#define HWREGBITH(x, b) \
|
||||
HWREGH(((uint32_t)(x) & 0xF0000000) | 0x02000000 | \
|
||||
(((uint32_t)(x) & 0x000FFFFF) << 5) | ((b) << 2))
|
||||
#define HWREGBITB(x, b) \
|
||||
HWREGB(((uint32_t)(x) & 0xF0000000) | 0x02000000 | \
|
||||
(((uint32_t)(x) & 0x000FFFFF) << 5) | ((b) << 2))
|
||||
|
||||
|
||||
#endif // __HW_TYPES_H__
|
||||
181
include/i2c.h
Normal file
181
include/i2c.h
Normal file
@@ -0,0 +1,181 @@
|
||||
/******************************************************************************
|
||||
* Filename: i2c.h
|
||||
* Revised: $Date: 2013-01-21 06:25:21 -0800 (Mon, 21 Jan 2013) $
|
||||
* Revision: $Revision: 9178 $
|
||||
*
|
||||
* Description: Prototypes for the I2C Driver.
|
||||
*
|
||||
*
|
||||
* Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* Neither the name of Texas Instruments Incorporated nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __I2C_H__
|
||||
#define __I2C_H__
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// If building with a C++ compiler, make all of the definitions in this header
|
||||
// have a C binding.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include "hw_types.h"
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Defines for the API.
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Interrupt defines.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define I2C_INT_MASTER 0x00000001
|
||||
#define I2C_INT_SLAVE 0x00000002
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// I2C Master commands.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define I2C_MASTER_CMD_SINGLE_SEND \
|
||||
0x00000007
|
||||
#define I2C_MASTER_CMD_SINGLE_RECEIVE \
|
||||
0x00000007
|
||||
#define I2C_MASTER_CMD_BURST_SEND_START \
|
||||
0x00000003
|
||||
#define I2C_MASTER_CMD_BURST_SEND_CONT \
|
||||
0x00000001
|
||||
#define I2C_MASTER_CMD_BURST_SEND_FINISH \
|
||||
0x00000005
|
||||
#define I2C_MASTER_CMD_BURST_SEND_ERROR_STOP \
|
||||
0x00000004
|
||||
#define I2C_MASTER_CMD_BURST_RECEIVE_START \
|
||||
0x0000000b
|
||||
#define I2C_MASTER_CMD_BURST_RECEIVE_CONT \
|
||||
0x00000009
|
||||
#define I2C_MASTER_CMD_BURST_RECEIVE_FINISH \
|
||||
0x00000005
|
||||
#define I2C_MASTER_CMD_BURST_RECEIVE_ERROR_STOP \
|
||||
0x00000004
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// I2C Master error status.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define I2C_MASTER_ERR_NONE 0
|
||||
#define I2C_MASTER_ERR_ADDR_ACK 0x00000004
|
||||
#define I2C_MASTER_ERR_DATA_ACK 0x00000008
|
||||
#define I2C_MASTER_ERR_ARB_LOST 0x00000010
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// I2C Slave action requests
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define I2C_SLAVE_ACT_NONE 0
|
||||
#define I2C_SLAVE_ACT_RREQ 0x00000001 // Master has sent data
|
||||
#define I2C_SLAVE_ACT_TREQ 0x00000002 // Master has requested data
|
||||
#define I2C_SLAVE_ACT_RREQ_FBR 0x00000005 // Master has sent first byte
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Miscellaneous I2C driver definitions.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define I2C_MASTER_MAX_RETRIES 1000 // Number of retries
|
||||
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// I2C Slave interrupts.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#define I2C_SLAVE_INT_STOP 0x00000004 // Stop Condition Interrupt.
|
||||
#define I2C_SLAVE_INT_START 0x00000002 // Start Condition Interrupt.
|
||||
#define I2C_SLAVE_INT_DATA 0x00000001 // Data Interrupt.
|
||||
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Prototypes for the APIs.
|
||||
//
|
||||
//*****************************************************************************
|
||||
extern void I2CIntRegister(void (*pfnHandler)(void));
|
||||
extern void I2CIntUnregister(void);
|
||||
extern bool I2CMasterBusBusy(void);
|
||||
extern bool I2CMasterBusy(void);
|
||||
extern void I2CMasterControl(uint32_t ui32Cmd);
|
||||
extern uint32_t I2CMasterDataGet(void);
|
||||
extern void I2CMasterDataPut(uint8_t ui8Data);
|
||||
extern void I2CMasterDisable(void);
|
||||
extern void I2CMasterEnable(void);
|
||||
extern uint32_t I2CMasterErr(void);
|
||||
extern void I2CMasterInitExpClk(uint32_t ui32I2CClk, bool bFast);
|
||||
extern void I2CMasterIntClear(void);
|
||||
extern void I2CMasterIntDisable(void);
|
||||
extern void I2CMasterIntEnable(void);
|
||||
extern bool I2CMasterIntStatus(bool bMasked);
|
||||
extern void I2CMasterSlaveAddrSet(uint8_t ui8SlaveAddr,
|
||||
bool bReceive);
|
||||
extern uint32_t I2CSlaveDataGet(void);
|
||||
extern void I2CSlaveDataPut(uint8_t ui8Data);
|
||||
extern void I2CSlaveDisable(void);
|
||||
extern void I2CSlaveEnable(void);
|
||||
extern void I2CSlaveInit(uint8_t ui8SlaveAddr);
|
||||
extern void I2CSlaveIntClear(void);
|
||||
extern void I2CSlaveIntDisable(void);
|
||||
extern void I2CSlaveIntEnable(void);
|
||||
extern void I2CSlaveIntClearEx(uint32_t ui32IntFlags);
|
||||
extern void I2CSlaveIntDisableEx(uint32_t ui32IntFlags);
|
||||
extern void I2CSlaveIntEnableEx(uint32_t ui32IntFlags);
|
||||
extern bool I2CSlaveIntStatus(bool bMasked);
|
||||
extern uint32_t I2CSlaveIntStatusEx(bool bMasked);
|
||||
extern uint32_t I2CSlaveStatus(void);
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Mark the end of the C bindings section for C++ compilers.
|
||||
//
|
||||
//*****************************************************************************
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // __I2C_H__
|
||||
227
include/saddr.c
Normal file
227
include/saddr.c
Normal file
@@ -0,0 +1,227 @@
|
||||
/****************************************************************************
|
||||
Filename: saddr.c
|
||||
Revised: $Date: 2014-11-06 11:03:55 -0800 (Thu, 06 Nov 2014) $
|
||||
Revision: $Revision: 41021 $
|
||||
|
||||
Description: Zigbee and 802.15.4 device address utility functions.
|
||||
|
||||
|
||||
Copyright 2005-2014 Texas Instruments Incorporated. All rights reserved.
|
||||
|
||||
IMPORTANT: Your use of this Software is limited to those specific rights
|
||||
granted under the terms of a software license agreement between the user
|
||||
who downloaded the software, his/her employer (which must be your employer)
|
||||
and Texas Instruments Incorporated (the "License"). You may not use this
|
||||
Software unless you agree to abide by the terms of the License. The License
|
||||
limits your use, and you acknowledge, that the Software may not be modified,
|
||||
copied or distributed unless embedded on a Texas Instruments microcontroller
|
||||
or used solely and exclusively in conjunction with a Texas Instruments radio
|
||||
frequency transceiver, which is integrated into your product. Other than for
|
||||
the foregoing purpose, you may not use, reproduce, copy, prepare derivative
|
||||
works of, modify, distribute, perform, display or sell this Software and/or
|
||||
its documentation for any purpose.
|
||||
|
||||
YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
|
||||
PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
||||
INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
|
||||
NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
|
||||
TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
|
||||
NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
|
||||
LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
|
||||
INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
|
||||
OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
|
||||
OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
|
||||
(INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
|
||||
|
||||
Should you have any questions regarding your right to use this Software,
|
||||
contact Texas Instruments Incorporated at www.TI.com.
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* INCLUDES
|
||||
*/
|
||||
#include "hal_types.h"
|
||||
#include "OSAL.h"
|
||||
#include "saddr.h"
|
||||
|
||||
#include "R2R_FlashJT.h"
|
||||
#if defined (CC26XX)
|
||||
#include "R2F_FlashJT.h"
|
||||
#endif /* CC26XX */
|
||||
|
||||
/****************************************************************************
|
||||
* @fn sAddrCmp
|
||||
*
|
||||
* @brief Compare two device addresses.
|
||||
*
|
||||
* input parameters
|
||||
*
|
||||
* @param pAddr1 - Pointer to first address.
|
||||
* @param pAddr2 - Pointer to second address.
|
||||
*
|
||||
* output parameters
|
||||
*
|
||||
* @return TRUE if addresses are equal, FALSE otherwise
|
||||
*/
|
||||
bool sAddrCmp(const sAddr_t *pAddr1, const sAddr_t *pAddr2)
|
||||
{
|
||||
if (pAddr1->addrMode != pAddr2->addrMode)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
else if (pAddr1->addrMode == SADDR_MODE_NONE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
else if (pAddr1->addrMode == SADDR_MODE_SHORT)
|
||||
{
|
||||
return (bool) (pAddr1->addr.shortAddr == pAddr2->addr.shortAddr);
|
||||
}
|
||||
else if (pAddr1->addrMode == SADDR_MODE_EXT)
|
||||
{
|
||||
return (MAP_sAddrExtCmp(pAddr1->addr.extAddr, pAddr2->addr.extAddr));
|
||||
}
|
||||
else
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* @fn sAddrIden
|
||||
*
|
||||
* @brief Check if two device addresses are identical.
|
||||
*
|
||||
* This routine is virtually the same as sAddrCmp, which is used
|
||||
* to determine if two different addresses are the same. However,
|
||||
* this routine can be used to determine if an address is the
|
||||
* same as a previously stored address. The key difference is in
|
||||
* the former case, if the address mode is "none", then the
|
||||
* assumption is that the two addresses can not be the same. But
|
||||
* in the latter case, the address mode itself is being compared.
|
||||
* So two addresses can be identical even if the address mode is
|
||||
* "none", as long as the address mode of both addresses being
|
||||
* compared is "none".
|
||||
*
|
||||
* input parameters
|
||||
*
|
||||
* @param pAddr1 - Pointer to first address.
|
||||
* @param pAddr2 - Pointer to second address.
|
||||
*
|
||||
* output parameters
|
||||
*
|
||||
* @return TRUE if addresses are identical, FALSE otherwise
|
||||
*/
|
||||
bool sAddrIden(const sAddr_t *pAddr1, const sAddr_t *pAddr2)
|
||||
{
|
||||
// first check if the address modes are the same
|
||||
if (pAddr1->addrMode != pAddr2->addrMode)
|
||||
{
|
||||
// no, so no point in comparing any further
|
||||
return FALSE;
|
||||
}
|
||||
// the address modes are the same; check if there is no address
|
||||
else if (pAddr1->addrMode == SADDR_MODE_NONE)
|
||||
{
|
||||
// no address, so no need to compare any further as both addresses have the
|
||||
// same address mode but no address, so they are identical
|
||||
return TRUE;
|
||||
}
|
||||
// there's an address; check if it is short
|
||||
else if (pAddr1->addrMode == SADDR_MODE_SHORT)
|
||||
{
|
||||
// compare short addresses
|
||||
return (bool) (pAddr1->addr.shortAddr == pAddr2->addr.shortAddr);
|
||||
}
|
||||
// there's an address; check if it is extended
|
||||
else if (pAddr1->addrMode == SADDR_MODE_EXT)
|
||||
{
|
||||
// compare extended addresses
|
||||
return (MAP_sAddrExtCmp(pAddr1->addr.extAddr, pAddr2->addr.extAddr));
|
||||
}
|
||||
else // unknown error
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* @fn sAddrCpy
|
||||
*
|
||||
* @brief Copy a device address.
|
||||
*
|
||||
* input parameters
|
||||
*
|
||||
* @param pSrc - Pointer to address to copy.
|
||||
*
|
||||
* output parameters
|
||||
*
|
||||
* @param pDest - Pointer to address of copy.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void sAddrCpy(sAddr_t *pDest, const sAddr_t *pSrc)
|
||||
{
|
||||
pDest->addrMode = pSrc->addrMode;
|
||||
|
||||
if (pDest->addrMode == SADDR_MODE_EXT)
|
||||
{
|
||||
MAP_sAddrExtCpy(pDest->addr.extAddr, pSrc->addr.extAddr);
|
||||
}
|
||||
else
|
||||
{
|
||||
pDest->addr.shortAddr = pSrc->addr.shortAddr;
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* @fn sAddrExtCmp
|
||||
*
|
||||
* @brief Compare two extended addresses.
|
||||
*
|
||||
* input parameters
|
||||
*
|
||||
* @param pAddr1 - Pointer to first address.
|
||||
* @param pAddr2 - Pointer to second address.
|
||||
*
|
||||
* output parameters
|
||||
*
|
||||
* @return TRUE if addresses are equal, FALSE otherwise
|
||||
*/
|
||||
bool sAddrExtCmp(const uint8 * pAddr1, const uint8 * pAddr2)
|
||||
{
|
||||
uint8 i;
|
||||
|
||||
for (i = SADDR_EXT_LEN; i != 0; i--)
|
||||
{
|
||||
if (*pAddr1++ != *pAddr2++)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* @fn sAddrExtCpy
|
||||
*
|
||||
* @brief Copy an extended address.
|
||||
*
|
||||
* input parameters
|
||||
*
|
||||
* @param pSrc - Pointer to address to copy.
|
||||
*
|
||||
* output parameters
|
||||
*
|
||||
* @param pDest - Pointer to address of copy.
|
||||
*
|
||||
* @return pDest + SADDR_EXT_LEN.
|
||||
*/
|
||||
void *sAddrExtCpy(uint8 * pDest, const uint8 * pSrc)
|
||||
{
|
||||
return osal_memcpy(pDest, pSrc, SADDR_EXT_LEN);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
175
include/saddr.h
Normal file
175
include/saddr.h
Normal file
@@ -0,0 +1,175 @@
|
||||
/**************************************************************************************************
|
||||
Filename: saddr.h
|
||||
Revised: $Date: 2009-12-10 08:32:15 -0800 (Thu, 10 Dec 2009) $
|
||||
Revision: $Revision: 21311 $
|
||||
|
||||
Description: Zigbee and 802.15.4 device address utility functions.
|
||||
|
||||
|
||||
Copyright 2005-2010 Texas Instruments Incorporated. All rights reserved.
|
||||
|
||||
IMPORTANT: Your use of this Software is limited to those specific rights
|
||||
granted under the terms of a software license agreement between the user
|
||||
who downloaded the software, his/her employer (which must be your employer)
|
||||
and Texas Instruments Incorporated (the "License"). You may not use this
|
||||
Software unless you agree to abide by the terms of the License. The License
|
||||
limits your use, and you acknowledge, that the Software may not be modified,
|
||||
copied or distributed unless embedded on a Texas Instruments microcontroller
|
||||
or used solely and exclusively in conjunction with a Texas Instruments radio
|
||||
frequency transceiver, which is integrated into your product. Other than for
|
||||
the foregoing purpose, you may not use, reproduce, copy, prepare derivative
|
||||
works of, modify, distribute, perform, display or sell this Software and/or
|
||||
its documentation for any purpose.
|
||||
|
||||
YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
|
||||
PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
||||
INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
|
||||
NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
|
||||
TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
|
||||
NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
|
||||
LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
|
||||
INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
|
||||
OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
|
||||
OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
|
||||
(INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
|
||||
|
||||
Should you have any questions regarding your right to use this Software,
|
||||
contact Texas Instruments Incorporated at www.TI.com.
|
||||
**************************************************************************************************/
|
||||
|
||||
#ifndef SADDR_H
|
||||
#define SADDR_H
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* MACROS
|
||||
*/
|
||||
|
||||
/* Extended address length */
|
||||
#define SADDR_EXT_LEN 8
|
||||
|
||||
/* Address modes */
|
||||
#define SADDR_MODE_NONE 0 /* Address not present */
|
||||
#define SADDR_MODE_SHORT 2 /* Short address */
|
||||
#define SADDR_MODE_EXT 3 /* Extended address */
|
||||
|
||||
/****************************************************************************
|
||||
* TYPEDEFS
|
||||
*/
|
||||
|
||||
/* Extended address */
|
||||
typedef uint8 sAddrExt_t[SADDR_EXT_LEN];
|
||||
|
||||
/* Combined short/extended device address */
|
||||
typedef struct
|
||||
{
|
||||
union
|
||||
{
|
||||
uint16 shortAddr; /* Short address */
|
||||
sAddrExt_t extAddr; /* Extended address */
|
||||
} addr;
|
||||
uint8 addrMode; /* Address mode */
|
||||
} sAddr_t;
|
||||
|
||||
/****************************************************************************
|
||||
* @fn sAddrCmp
|
||||
*
|
||||
* @brief Compare two device addresses.
|
||||
*
|
||||
* input parameters
|
||||
*
|
||||
* @param pAddr1 - Pointer to first address.
|
||||
* @param pAddr2 - Pointer to second address.
|
||||
*
|
||||
* output parameters
|
||||
*
|
||||
* @return TRUE if addresses are equal, FALSE otherwise
|
||||
*/
|
||||
extern bool sAddrCmp(const sAddr_t *pAddr1, const sAddr_t *pAddr2);
|
||||
|
||||
/****************************************************************************
|
||||
* @fn sAddrIden
|
||||
*
|
||||
* @brief Check if two device addresses are identical.
|
||||
*
|
||||
* This routine is virtually the same as sAddrCmp, which is used
|
||||
* to determine if two different addresses are the same. However,
|
||||
* this routine can be used to determine if an address is the
|
||||
* same as a previously stored address. The key difference is in
|
||||
* the former case, if the address mode is "none", then the
|
||||
* assumption is that the two addresses can not be the same. But
|
||||
* in the latter case, the address mode itself is being compared.
|
||||
* So two addresses can be identical even if the address mode is
|
||||
* "none", as long as the address mode of both addresses being
|
||||
* compared is the "none".
|
||||
*
|
||||
* input parameters
|
||||
*
|
||||
* @param pAddr1 - Pointer to first address.
|
||||
* @param pAddr2 - Pointer to second address.
|
||||
*
|
||||
* output parameters
|
||||
*
|
||||
* @return TRUE if addresses are identical, FALSE otherwise
|
||||
*/
|
||||
extern bool sAddrIden(const sAddr_t *pAddr1, const sAddr_t *pAddr2);
|
||||
|
||||
/****************************************************************************
|
||||
* @fn sAddrCpy
|
||||
*
|
||||
* @brief Copy a device address.
|
||||
*
|
||||
* input parameters
|
||||
*
|
||||
* @param pSrc - Pointer to address to copy.
|
||||
*
|
||||
* output parameters
|
||||
*
|
||||
* @param pDest - Pointer to address of copy.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
extern void sAddrCpy(sAddr_t *pDest, const sAddr_t *pSrc);
|
||||
|
||||
/****************************************************************************
|
||||
* @fn sAddrExtCmp
|
||||
*
|
||||
* @brief Compare two extended addresses.
|
||||
*
|
||||
* input parameters
|
||||
*
|
||||
* @param pAddr1 - Pointer to first address.
|
||||
* @param pAddr2 - Pointer to second address.
|
||||
*
|
||||
* output parameters
|
||||
*
|
||||
* @return TRUE if addresses are equal, FALSE otherwise
|
||||
*/
|
||||
extern bool sAddrExtCmp(const uint8 * pAddr1, const uint8 * pAddr2);
|
||||
|
||||
/****************************************************************************
|
||||
* @fn sAddrExtCpy
|
||||
*
|
||||
* @brief Copy an extended address.
|
||||
*
|
||||
* input parameters
|
||||
*
|
||||
* @param pSrc - Pointer to address to copy.
|
||||
*
|
||||
* output parameters
|
||||
*
|
||||
* @param pDest - Pointer to address of copy.
|
||||
*
|
||||
* @return pDest + SADDR_EXT_LEN.
|
||||
*/
|
||||
void *sAddrExtCpy(uint8 * pDest, const uint8 * pSrc);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* SADDR_H */
|
||||
5
main.c
5
main.c
@@ -1,10 +1,11 @@
|
||||
#include "hal_types.h"
|
||||
#include "hal_defs.h"
|
||||
#include "hal_gpio.h"
|
||||
// #include "hal_gpio.h"
|
||||
#include "hal_timer.h"
|
||||
#include "ZComDef.h"
|
||||
#include "OSAL.h"
|
||||
#include "ZStack.h"
|
||||
// #include "ZStack.h"
|
||||
#include "i2c.h"
|
||||
// Include necessary libraries for the sensors (BME280, Wind Vane, etc.)
|
||||
#include "bme280.h"
|
||||
#include "wind_vane.h"
|
||||
|
||||
Reference in New Issue
Block a user