2 ******************************************************************************
3 * @addtogroup PIOS PIOS Core hardware abstraction layer
5 * @addtogroup PIOS_RFM22B Radio Functions
6 * @brief PIOS COM interface for for the RFM22B radio
9 * @file pios_rfm22b_com.c
10 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
11 * @brief Implements a driver the the RFM22B driver
12 * @see The GNU Public License (GPL) Version 3
14 *****************************************************************************/
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 3 of the License, or
19 * (at your option) any later version.
21 * This program is distributed in the hope that it will be useful, but
22 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
23 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
26 * You should have received a copy of the GNU General Public License along
27 * with this program; if not, write to the Free Software Foundation, Inc.,
28 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33 #ifdef PIOS_INCLUDE_RFM22B_COM
35 #include <pios_rfm22b_priv.h>
37 /* Provide a COM driver */
38 static void PIOS_RFM22B_COM_ChangeBaud(uint32_t rfm22b_id
, uint32_t baud
);
39 static void PIOS_RFM22B_COM_RegisterRxCallback(uint32_t rfm22b_id
, pios_com_callback rx_in_cb
, uint32_t context
);
40 static void PIOS_RFM22B_COM_RegisterTxCallback(uint32_t rfm22b_id
, pios_com_callback tx_out_cb
, uint32_t context
);
41 static void PIOS_RFM22B_COM_TxStart(uint32_t rfm22b_id
, uint16_t tx_bytes_avail
);
42 static void PIOS_RFM22B_COM_RxStart(uint32_t rfm22b_id
, uint16_t rx_bytes_avail
);
43 static bool PIOS_RFM22B_COM_Available(uint32_t rfm22b_com_id
);
46 const struct pios_com_driver pios_rfm22b_com_driver
= {
47 .set_baud
= PIOS_RFM22B_COM_ChangeBaud
,
48 .tx_start
= PIOS_RFM22B_COM_TxStart
,
49 .rx_start
= PIOS_RFM22B_COM_RxStart
,
50 .bind_tx_cb
= PIOS_RFM22B_COM_RegisterTxCallback
,
51 .bind_rx_cb
= PIOS_RFM22B_COM_RegisterRxCallback
,
52 .available
= PIOS_RFM22B_COM_Available
56 * Changes the baud rate of the RFM22B peripheral without re-initialising.
58 * @param[in] rfm22b_id The defice ID
59 * @param[in] baud Requested baud rate
61 static void PIOS_RFM22B_COM_ChangeBaud(__attribute__((unused
)) uint32_t rfm22b_id
,
62 __attribute__((unused
)) uint32_t baud
)
66 * Start a receive from the COM device
68 * @param[in] rfm22b_dev The device ID.
69 * @param[in] rx_bytes_available The number of bytes available to receive
71 static void PIOS_RFM22B_COM_RxStart(__attribute__((unused
)) uint32_t rfm22b_id
,
72 __attribute__((unused
)) uint16_t rx_bytes_avail
)
76 * Start a transmit from the COM device
78 * @param[in] rfm22b_dev The device ID.
79 * @param[in] tx_bytes_available The number of bytes available to transmit
81 static void PIOS_RFM22B_COM_TxStart(__attribute__((unused
)) uint32_t rfm22b_id
,
82 __attribute__((unused
)) uint16_t tx_bytes_avail
)
87 * Register the callback to pass received data to
89 * @param[in] rfm22b_dev The device ID.
90 * @param[in] rx_in_cb The Rx callback function.
91 * @param[in] context The callback context.
93 static void PIOS_RFM22B_COM_RegisterRxCallback(uint32_t rfm22b_id
, pios_com_callback rx_in_cb
, uint32_t context
)
95 struct pios_rfm22b_dev
*rfm22b_dev
= (struct pios_rfm22b_dev
*)rfm22b_id
;
97 if (!PIOS_RFM22B_Validate(rfm22b_dev
)) {
102 * Order is important in these assignments since ISR uses _cb
103 * field to determine if it's ok to dereference _cb and _context
105 rfm22b_dev
->rx_in_context
= context
;
106 rfm22b_dev
->rx_in_cb
= rx_in_cb
;
110 * Register the callback to get data from.
112 * @param[in] rfm22b_dev The device ID.
113 * @param[in] rx_in_cb The Tx callback function.
114 * @param[in] context The callback context.
116 static void PIOS_RFM22B_COM_RegisterTxCallback(uint32_t rfm22b_id
, pios_com_callback tx_out_cb
, uint32_t context
)
118 struct pios_rfm22b_dev
*rfm22b_dev
= (struct pios_rfm22b_dev
*)rfm22b_id
;
120 if (!PIOS_RFM22B_Validate(rfm22b_dev
)) {
125 * Order is important in these assignments since ISR uses _cb
126 * field to determine if it's ok to dereference _cb and _context
128 rfm22b_dev
->tx_out_context
= context
;
129 rfm22b_dev
->tx_out_cb
= tx_out_cb
;
133 * See if the COM port is alive
135 * @param[in] rfm22b_dev The device ID.
136 * @return True of the device is available.
138 static bool PIOS_RFM22B_COM_Available(uint32_t rfm22b_id
)
140 return PIOS_RFM22B_LinkStatus(rfm22b_id
);
143 #endif /* PIOS_INCLUDE_RFM22B_COM */