Contiki-NG
antenna-sw.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015, Zolertia
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the Institute nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 */
30/*---------------------------------------------------------------------------*/
31/**
32 * \addtogroup remote-antenna
33 * @{
34 *
35 * Driver for the RE-Mote RF switch, to enable either the built-in 2.4GHz RF
36 * interface of the CC2538, or the CC1200 Sub-1GHz RF interface, both routed to
37 * the RP-SMA connector for an external antenna.
38 * When the 2.4GHz RF interface is enabled, the CC1200 is powered down.
39 * When the CC1200 is enabled, alternatively the 2.4GHz can be also used if
40 * placing an 0Ohm resistor (R19), to connect either via a non-mounted chip
41 * antenna, or with an external antenna connected to a non-mounted U.Fl
42 * connector with a pigtail.
43 *
44 * RF switch state:
45 * - LOW: 2.4GHz RF interface on RP-SMA connector, CC1200 powered-off.
46 * - HIGH: Sub-1GHz RF interface on RP-SMA connector.
47 * @{
48 *
49 * \file
50 * Driver for the RE-Mote RF antenna switch
51 */
52/*---------------------------------------------------------------------------*/
53#include "contiki.h"
54#include "dev/gpio.h"
55#include "antenna-sw.h"
56
57#include <stdint.h>
58/*---------------------------------------------------------------------------*/
59#define ANTENNA_RF_SW_PORT_BASE GPIO_PORT_TO_BASE(ANTENNA_RF_SW_PORT)
60#define ANTENNA_RF_SW_PIN_MASK GPIO_PIN_MASK(ANTENNA_RF_SW_PIN)
61/*---------------------------------------------------------------------------*/
62static uint8_t initialized = 0;
63/*---------------------------------------------------------------------------*/
64void
66{
67 /* Software controlled */
68 GPIO_SOFTWARE_CONTROL(ANTENNA_RF_SW_PORT_BASE,
69 ANTENNA_RF_SW_PIN_MASK);
70
71 /* Set pin to output */
72 GPIO_SET_OUTPUT(ANTENNA_RF_SW_PORT_BASE, ANTENNA_RF_SW_PIN_MASK);
73
74 /* Set the antenna selector to a default position */
75 GPIO_WRITE_PIN(ANTENNA_RF_SW_PORT_BASE, ANTENNA_RF_SW_PIN_MASK,
76 ANTENNA_SW_SELECT_DEFAULT);
77
78 initialized = 1;
79}
80/*---------------------------------------------------------------------------*/
81int
83{
84 if(!initialized) {
85 return ANTENNA_SW_SELECT_ERROR;
86 }
87
88 /* Set the antenna selector */
89 return GPIO_READ_PIN(ANTENNA_RF_SW_PORT_BASE, ANTENNA_RF_SW_PIN_MASK);
90}
91/*---------------------------------------------------------------------------*/
92int
94{
95 if(!initialized) {
96 return ANTENNA_SW_SELECT_ERROR;
97 }
98
99 if(val != ANTENNA_SW_SELECT_SUBGHZ && val != ANTENNA_SW_SELECT_2_4GHZ) {
100 return ANTENNA_SW_SELECT_ERROR;
101 }
102
103 if(val & antenna_sw_get()) {
104 return val;
105 }
106
107 /* Set the antenna selector */
108 GPIO_WRITE_PIN(ANTENNA_RF_SW_PORT_BASE, ANTENNA_RF_SW_PIN_MASK, val);
109
110 return val;
111}
112/*---------------------------------------------------------------------------*/
113/**
114 * @}
115 * @}
116 */
Header file for the RE-Mote RF antenna switch.
Header file with register and macro declarations for the cc2538 GPIO module.
#define GPIO_SOFTWARE_CONTROL(PORT_BASE, PIN_MASK)
Configure the pin to be software controlled with PIN_MASK of port with PORT_BASE.
Definition: gpio.h:258
#define GPIO_WRITE_PIN(PORT_BASE, PIN_MASK, value)
Set pins with PIN_MASK of port with PORT_BASE to value.
Definition: gpio.h:134
#define GPIO_SET_OUTPUT(PORT_BASE, PIN_MASK)
Set pins with PIN_MASK of port with PORT_BASE to output.
Definition: gpio.h:85
#define GPIO_READ_PIN(PORT_BASE, PIN_MASK)
Read pins with PIN_MASK of port with PORT_BASE.
Definition: gpio.h:147
int antenna_sw_get(void)
Function to read the current status of the RF switch.
Definition: antenna-sw.c:82
int antenna_sw_select(uint8_t val)
Function to select between the 2.4GHz or Sub-1GHz RF interface.
Definition: antenna-sw.c:93
void antenna_sw_config(void)
Init function for the antenna switch.
Definition: antenna-sw.c:65