/*
 * Copyright (c) 2010-2012 Digi International Inc.,
 * All rights not expressly granted are reserved.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
 * =======================================================================
 */

/**
	@addtogroup hal_msp430
	@{
	@file xbee/platform_msp430.h
	Header for MSP430 platforms

	This file is automatically included by xbee/platform.h.

	@todo need a configure script to find location of endian.h?
	@todo figure out a way to handle XBEE_NATIVE_64BIT
	@todo better way to determine timer resolution?
*/

#ifndef __XBEE_PLATFORM_MSP430
#define __XBEE_PLATFORM_MSP430
	#include "msp430_mcu.h"

	#define INTERRUPT_ENABLE		HAL_ENABLE_INTERRUPTS()
	#define INTERRUPT_DISABLE		HAL_DISABLE_INTERRUPTS()

	#include <strings.h>

	#define strcmpi			strcasecmp
	#define strncmpi		strncasecmp

	//// Load platform's endian header to learn whether we're big or little.
	//#include <sys/types.h>
	// CodeWarrior doesn't have an endian.h, so define its macros here.
	#define LITTLE_ENDIAN	1234
	#define BIG_ENDIAN		4321
	#define PDP_ENDIAN		3412

	#define BYTE_ORDER		LITTLE_ENDIAN

	// macro used to declare a packed structure (no alignment of elements)
	#define PACKED_STRUCT		struct __attribute__ ((__packed__))

	#define _f_memcpy		memcpy
	#define _f_memset		memset

	// MSP430 doesn't have automatic __FUNCTION__ macro.
	#define __FUNCTION__		"xbee"

	// stdint.h for int8_t, uint8_t, int16_t, etc. types
	#include <stdint.h>
	#include <stdbool.h>
	#include "ComTypeDefs.h"
	//typedef int bool_t;

	//// inttypes.h for PRIx16, PRIx32, etc. macros
	//#include <inttypes.h>
	//// CodeWarrior printf doesn't like "h" modifier, so define these
	//// format specifiers and don't use the defaults.
	//#define PRId16				"d"
	//#define PRIu16				"u"
	//#define PRIx16				"x"
	//#define PRIX16				"X"

	// compiler natively supports 64-bit integers
	#define XBEE_NATIVE_64BIT

// Elements needed to keep track of serial port settings.  Must have a
// baudrate member, other fields are platform-specific.
typedef struct xbee_serial_t
{
	uint32_t		baudrate;
	int				fd;
	//char			device[40];		// /dev/ttySxx
} xbee_serial_t;

// Unix epoch is 1/1/1970
#define ZCL_TIME_EPOCH_DELTA	ZCL_TIME_EPOCH_DELTA_1970

// Tick Timer resolution
#define XBEE_MS_TIMER_RESOLUTION 10

#endif		// __XBEE_PLATFORM_MSP430
