/*
Copyright 2006, Freie Universitaet Berlin. All rights reserved.

These sources were developed at the Freie Universität Berlin, Computer
Systems and Telematics group.

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 Freie Universitaet Berlin (FUB) 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 FUB and the contributors on an "as is"
basis, without any representations or warranties of any kind, express
or implied including, but not limited to, representations or
warranties of non-infringement, merchantability or fitness for a
particular purpose. In no event shall FUB 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.

This implementation was developed by the CST group at the FUB.

For documentation and questions please use the web site
http://scatterweb.mi.fu-berlin.de and the mailinglist
scatterweb@lists.spline.inf.fu-berlin.de (subscription via the Website).
Berlin, 2006
*/

/**
 * @file ScatterWeb.CC1020.h
 * @ingroup cc1020
 * @brief The ScatterWeb.CC1020 consists all of the fuctions that constitute
 * 		the chipcon architecture.
 * 
 *  The software for the transceiver CC1020 from Chipcon features:
 *  - Functions to enable & disable the radio. Receive current is around 25 - 30 mA,
 *  transmit current from 60 mA up to over 150 mA (depends on the transmit power)
 *  and sleep current is in the range of uA.
 *  - Setting of transmit power (done in the config). Dont set a value higher than 3200,
 *  because even the transmit power increases the carrier signal gets distorted and
 *  will be worse.
 *  - Interrupt driven Rx&Tx radio MAC logic (sending of packets with CSMA and random 
 *  backoff, CRC-16 checksums, acknowledgement with automatic retransmission).
 * 
 * @version         $Revision: 507 $
 * 
 * $Id: ScatterWeb.CC1020.h 507 2008-02-05 12:56:03Z baar@PCPOOL.MI.FU-BERLIN.DE $
 */

/**
 * @addtogroup	cc1020
 * @{
 */

#ifndef ScatterWeb_CC1020
#define ScatterWeb_CC1020

#define CC1020_RSS 0x42
#define TX_CURRENT 0x87
#define RX_CURRENT 0x86

#define CC1020_NUM_CHANNELS		8

enum cc1020_register {
	CC1020_MAIN          = 0x00,
	CC1020_INTERFACE     = 0x01,
	CC1020_RESET         = 0x02,
	CC1020_SEQUENCING    = 0x03,
	CC1020_FREQ_2A       = 0x04,
	CC1020_FREQ_1A       = 0x05,
	CC1020_FREQ_0A       = 0x06,
	CC1020_CLOCK_A       = 0x07,
	CC1020_FREQ_2B       = 0x08,
	CC1020_FREQ_1B       = 0x09,
	CC1020_FREQ_0B       = 0x0A,
	CC1020_CLOCK_B       = 0x0B,
	CC1020_VCO           = 0x0C,
	CC1020_MODEM         = 0x0D,
	CC1020_DEVIATION     = 0x0E,
	CC1020_AFC_CONTROL   = 0x0F,
	CC1020_FILTER        = 0x10,
	CC1020_VGA1          = 0x11,
	CC1020_VGA2          = 0x12,
	CC1020_VGA3          = 0x13,
	CC1020_VGA4          = 0x14,
	CC1020_LOCK          = 0x15,
	CC1020_FRONTEND      = 0x16,
	CC1020_ANALOG        = 0x17,
	CC1020_BUFF_SWING    = 0x18,
	CC1020_BUFF_CURRENT  = 0x19,
	CC1020_PLL_BW        = 0x1A,
	CC1020_CALIBRATE     = 0x1B,
	CC1020_PA_POWER      = 0x1C,
	CC1020_MATCH         = 0x1D,
	CC1020_PHASE_COMP    = 0x1E,
	CC1020_GAIN_COMP     = 0x1F,
	CC1020_POWERDOWN     = 0x20,
	CC1020_TEST1         = 0x21,
	CC1020_TEST2         = 0x22,
	CC1020_TEST3         = 0x23,
	CC1020_TEST4         = 0x24,
	CC1020_TEST5         = 0x25,
	CC1020_TEST6         = 0x26,
	CC1020_TEST7         = 0x27,
	CC1020_STATUS        = 0x40,
	CC1020_RESET_DONE    = 0x41,
	CC1020_AFC           = 0x43,
	CC1020_GAUSS_FILTER  = 0x44,
	CC1020_STATUS1       = 0x45,
	CC1020_STATUS2       = 0x46,
	CC1020_STATUS3       = 0x47,
	CC1020_STATUS4       = 0x48,
	CC1020_STATUS5       = 0x49,
	CC1020_STATUS6       = 0x4A,
	CC1020_STATUS7       = 0x4B
};


enum CC1020_lock_status {
	LOCK_NOK       = 0x00,
	LOCK_OK        = 0x01,
	LOCK_RECAL_OK  = 0x02,
	LOCK_CONTINOUS = 0x10
};

struct cc1020_config {
  uint8_t	registerValues[41];
  uint8_t	ackTimeout;
};

/**
 * This member supports the ScatterWeb infrastructure
 * and is not intended to be used directly from your code.
 */
void CC1020_init();

/**
 * This member supports the ScatterWeb infrastructure
 * and is not intended to be used directly from your code.
 */
char CC1020_calibrate();

/**
 * This member supports the ScatterWeb infrastructure
 * and is not intended to be used directly from your code.
 */
enum CC1020_lock_status CC1020_setupTX(char TXANALOG);

/**
 * This member supports the ScatterWeb infrastructure
 * and is not intended to be used directly from your code.
 */
enum CC1020_lock_status CC1020_setupRX(char RXANALOG);

/**
 * This member supports the ScatterWeb infrastructure
 * and is not intended to be used directly from your code.
 */
void CC1020_setupPD();

/**
 * This member supports the ScatterWeb infrastructure
 * and is not intended to be used directly from your code.
 */
void CC1020_wakeupTX(char TXANALOG);

/**
 * This member supports the ScatterWeb infrastructure
 * and is not intended to be used directly from your code.
 */
void CC1020_wakeupRX(char RXANALOG);

/**
 * This member supports the ScatterWeb infrastructure
 * and is not intended to be used directly from your code.
 */
uint8_t CC1020_readRegister(uint8_t addr);

/**
 * This member supports the ScatterWeb infrastructure
 * and is not intended to be used directly from your code.
 */
void CC1020_writeRegister(enum cc1020_register addr, uint8_t adata);

/**
 * This member supports the ScatterWeb infrastructure
 * and is not intended to be used directly from your code.
 */
void CC1020_loadSettings(const struct cc1020_config* config);

/**
 * This member supports the ScatterWeb infrastructure
 * and is not intended to be used directly from your code.
 */
void CC1020_writeSettings();

/**
 * This member supports the ScatterWeb infrastructure
 * and is not intended to be used directly from your code.
 */ 
void CC1020_reset();

/**
 * @internal
 */
bool CC1020_changeMode(uint8_t mode);

/**
 * @brief	Select radio channel to use
 */
uint8_t CC1020_selectChannel(uint8_t channel);

uint8_t CC1020_setTxPower(uint8_t power);

#endif
/** @} */
