Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0+ */
0002 /*
0003  * userspace interface for pi433 radio module
0004  *
0005  * Pi433 is a 433MHz radio module for the Raspberry Pi.
0006  * It is based on the HopeRf Module RFM69CW. Therefore, inside of this
0007  * driver you'll find an abstraction of the rf69 chip.
0008  *
0009  * If needed this driver could also be extended to support other
0010  * devices based on HopeRf rf69 as well as HopeRf modules with a similar
0011  * interface such as RFM69HCW, RFM12, RFM95 and so on.
0012  *
0013  * Copyright (C) 2016 Wolf-Entwicklungen
0014  *  Marcus Wolf <linux@wolf-entwicklungen.de>
0015  */
0016 
0017 #ifndef PI433_H
0018 #define PI433_H
0019 
0020 #include <linux/types.h>
0021 #include "rf69_enum.h"
0022 
0023 /*---------------------------------------------------------------------------*/
0024 
0025 enum option_on_off {
0026     OPTION_OFF,
0027     OPTION_ON
0028 };
0029 
0030 /* IOCTL structs and commands */
0031 
0032 /**
0033  * struct pi433_tx_cfg
0034  * describes the configuration of the radio module for sending data
0035  * @frequency:
0036  * @bit_rate:
0037  * @modulation:
0038  * @data_mode:
0039  * @preamble_length:
0040  * @sync_pattern:
0041  * @tx_start_condition:
0042  * @payload_length:
0043  * @repetitions:
0044  *
0045  * ATTENTION:
0046  * If the contents of 'pi433_tx_cfg' ever change
0047  * incompatibly, then the ioctl number (see define below) must change.
0048  *
0049  * NOTE: struct layout is the same in 64bit and 32bit userspace.
0050  */
0051 #define PI433_TX_CFG_IOCTL_NR   0
0052 struct pi433_tx_cfg {
0053     __u32           frequency;
0054     __u16           bit_rate;
0055     __u32           dev_frequency;
0056     enum modulation     modulation;
0057     enum mod_shaping    mod_shaping;
0058 
0059     enum pa_ramp        pa_ramp;
0060 
0061     enum tx_start_condition tx_start_condition;
0062 
0063     __u16           repetitions;
0064 
0065     /* packet format */
0066     enum option_on_off  enable_preamble;
0067     enum option_on_off  enable_sync;
0068     enum option_on_off  enable_length_byte;
0069     enum option_on_off  enable_address_byte;
0070     enum option_on_off  enable_crc;
0071 
0072     __u16           preamble_length;
0073     __u8            sync_length;
0074     __u8            fixed_message_length;
0075 
0076     __u8            sync_pattern[8];
0077     __u8            address_byte;
0078 };
0079 
0080 /**
0081  * struct pi433_rx_cfg
0082  * describes the configuration of the radio module for receiving data
0083  * @frequency:
0084  * @bit_rate:
0085  * @modulation:
0086  * @data_mode:
0087  * @preamble_length:
0088  * @sync_pattern:
0089  * @tx_start_condition:
0090  * @payload_length:
0091  * @repetitions:
0092  *
0093  * ATTENTION:
0094  * If the contents of 'pi433_rx_cfg' ever change
0095  * incompatibly, then the ioctl number (see define below) must change
0096  *
0097  * NOTE: struct layout is the same in 64bit and 32bit userspace.
0098  */
0099 #define PI433_RX_CFG_IOCTL_NR   1
0100 struct pi433_rx_cfg {
0101     __u32           frequency;
0102     __u16           bit_rate;
0103     __u32           dev_frequency;
0104 
0105     enum modulation     modulation;
0106 
0107     __u8            rssi_threshold;
0108     enum threshold_decrement threshold_decrement;
0109     enum antenna_impedance  antenna_impedance;
0110     enum lna_gain       lna_gain;
0111     enum mantisse       bw_mantisse;    /* normal: 0x50 */
0112     __u8            bw_exponent;    /* during AFC: 0x8b */
0113     enum dagc       dagc;
0114 
0115     /* packet format */
0116     enum option_on_off  enable_sync;
0117 
0118     /* should be used in combination with sync, only */
0119     enum option_on_off  enable_length_byte;
0120 
0121     /* operational with sync, only */
0122     enum address_filtering  enable_address_filtering;
0123 
0124     /* only operational, if sync on and fixed length or length byte is used */
0125     enum option_on_off  enable_crc;
0126 
0127     __u8            sync_length;
0128     __u8            fixed_message_length;
0129     __u32           bytes_to_drop;
0130 
0131     __u8            sync_pattern[8];
0132     __u8            node_address;
0133     __u8            broadcast_address;
0134 };
0135 
0136 #define PI433_IOC_MAGIC 'r'
0137 
0138 #define PI433_IOC_RD_TX_CFG                                             \
0139     _IOR(PI433_IOC_MAGIC, PI433_TX_CFG_IOCTL_NR, char[sizeof(struct pi433_tx_cfg)])
0140 #define PI433_IOC_WR_TX_CFG                                             \
0141     _IOW(PI433_IOC_MAGIC, PI433_TX_CFG_IOCTL_NR, char[sizeof(struct pi433_tx_cfg)])
0142 
0143 #define PI433_IOC_RD_RX_CFG                                             \
0144     _IOR(PI433_IOC_MAGIC, PI433_RX_CFG_IOCTL_NR, char[sizeof(struct pi433_rx_cfg)])
0145 #define PI433_IOC_WR_RX_CFG                                             \
0146     _IOW(PI433_IOC_MAGIC, PI433_RX_CFG_IOCTL_NR, char[sizeof(struct pi433_rx_cfg)])
0147 
0148 #endif /* PI433_H */