Artemis Teensy Flight Software
The software on the Teensy in the Artemis cubesat.
rfm23.h
Go to the documentation of this file.
1 
7 #ifndef _RFM23_H
8 #define _RFM23_H
9 
10 #include "helpers.h"
11 #include <RHHardwareSPI1.h>
12 #include <RH_RF22.h>
13 #include <TeensyThreads.h>
14 #include <support/packetcomm.h>
15 
16 #undef RH_RF22_MAX_MESSAGE_LEN
18 #define RH_RF22_MAX_MESSAGE_LEN 50
20 #define MINIMUM_TIMEOUT 100
21 
22 namespace Artemis {
23 namespace Devices {
25  class RFM23 {
26  public:
28  struct __attribute__((packed)) rfm23_config {
30  uint16_t freq;
32  uint8_t tx_power;
34  struct {
36  uint8_t spi_miso;
38  uint8_t spi_mosi;
40  uint8_t spi_sck;
42  uint8_t nirq;
44  uint8_t cs;
46  uint8_t tx_on;
48  uint8_t rx_on;
49  } pins;
50  };
51 
52  RFM23(uint8_t slaveSelectPin, uint8_t interruptPin,
53  RHGenericSPI &spi = hardware_spi1);
54  bool init(rfm23_config cfg, Threads::Mutex *mtx);
55  void reset();
56  bool send(PacketComm &packet);
57  int32_t recv(PacketComm &packet, uint16_t timeout);
58 
59  private:
67  RH_RF22 rfm23;
69  Threads::Mutex *spi_mtx;
71  rfm23_config config;
72  };
73 } // namespace Devices
74 } // namespace Artemis
75 
76 #endif // _RFM23_H
The RFM23 radio class.
Definition: rfm23.h:25
RFM23(uint8_t slaveSelectPin, uint8_t interruptPin, RHGenericSPI &spi=hardware_spi1)
Construct a new RFM23 object. Wraps the RH_RFM23 constructor.
Definition: rfm23.cpp:18
bool init(rfm23_config cfg, Threads::Mutex *mtx)
Initialize the RFM23 radio.
Definition: rfm23.cpp:32
int32_t recv(PacketComm &packet, uint16_t timeout)
Receive a packet from the radio.
Definition: rfm23.cpp:138
bool send(PacketComm &packet)
Sends a packet through the radio.
Definition: rfm23.cpp:95
void reset()
Resets the radio.
Definition: rfm23.cpp:76
Definition: packetcomm.h:13
The header file for helper functions.
PacketComm packet
The packet used throughout the channel.
Definition: pdu_channel.cpp:19
The RFM23 radio configuration.
Definition: rfm23.h:28
uint16_t freq
The receive/transmit center frequency.
Definition: rfm23.h:30
uint8_t cs
The chip select pin used on the SPI interface.
Definition: rfm23.h:44
uint8_t spi_sck
The clock pin used on the SPI interface.
Definition: rfm23.h:40
uint8_t tx_power
The transmit power, set as a macro.
Definition: rfm23.h:32
uint8_t nirq
The interrupt pin.
Definition: rfm23.h:42
uint8_t spi_mosi
The MOSI pin used on the SPI interface.
Definition: rfm23.h:38
uint8_t tx_on
The transmit enable pin.
Definition: rfm23.h:46
uint8_t rx_on
The receive enable pin.
Definition: rfm23.h:48
uint8_t spi_miso
The MISO pin used on the SPI interface.
Definition: rfm23.h:36