Compare commits
No commits in common. "11baa1c185655692ea3fb7562d1e2fbd66ea1c10" and "bbe259c29a744a7a4307045b29605d683ce03023" have entirely different histories.
11baa1c185
...
bbe259c29a
@ -108,14 +108,7 @@ drivers:
|
|||||||
eic_arch_wakeupen7: false
|
eic_arch_wakeupen7: false
|
||||||
eic_arch_wakeupen8: false
|
eic_arch_wakeupen8: false
|
||||||
eic_arch_wakeupen9: false
|
eic_arch_wakeupen9: false
|
||||||
optional_signals:
|
optional_signals: []
|
||||||
- identifier: EXTERNAL_IRQ_0:EXTINT/0
|
|
||||||
pad: PA00
|
|
||||||
mode: Enabled
|
|
||||||
configuration: null
|
|
||||||
definition: Atmel:SAMD21_Drivers:0.0.1::SAMD21E17A-MF::optional_signal_definition::EIC.EXTINT.0
|
|
||||||
name: EIC/EXTINT/0
|
|
||||||
label: EXTINT/0
|
|
||||||
variant: null
|
variant: null
|
||||||
clocks:
|
clocks:
|
||||||
domain_group:
|
domain_group:
|
||||||
@ -716,12 +709,6 @@ drivers:
|
|||||||
clocks:
|
clocks:
|
||||||
domain_group: null
|
domain_group: null
|
||||||
pads:
|
pads:
|
||||||
PA00:
|
|
||||||
name: PA00
|
|
||||||
definition: Atmel:SAMD21_Drivers:0.0.1::SAMD21E17A-MF::pad::PA00
|
|
||||||
mode: Digital input
|
|
||||||
user_label: PA00
|
|
||||||
configuration: null
|
|
||||||
OUT_LED_TX:
|
OUT_LED_TX:
|
||||||
name: PA06
|
name: PA06
|
||||||
definition: Atmel:SAMD21_Drivers:0.0.1::SAMD21E17A-MF::pad::PA06
|
definition: Atmel:SAMD21_Drivers:0.0.1::SAMD21E17A-MF::pad::PA06
|
||||||
|
|||||||
@ -21,7 +21,6 @@
|
|||||||
#define GPIO_PIN_FUNCTION_G 6
|
#define GPIO_PIN_FUNCTION_G 6
|
||||||
#define GPIO_PIN_FUNCTION_H 7
|
#define GPIO_PIN_FUNCTION_H 7
|
||||||
|
|
||||||
#define PA00 GPIO(GPIO_PORTA, 0)
|
|
||||||
#define OUT_LED_TX GPIO(GPIO_PORTA, 6)
|
#define OUT_LED_TX GPIO(GPIO_PORTA, 6)
|
||||||
#define OUT_XBEE_REMOTE_RESET GPIO(GPIO_PORTA, 7)
|
#define OUT_XBEE_REMOTE_RESET GPIO(GPIO_PORTA, 7)
|
||||||
#define IN_UART_TX GPIO(GPIO_PORTA, 8)
|
#define IN_UART_TX GPIO(GPIO_PORTA, 8)
|
||||||
|
|||||||
@ -682,10 +682,6 @@
|
|||||||
#endif
|
#endif
|
||||||
// </e>
|
// </e>
|
||||||
|
|
||||||
#ifndef CONFIG_EIC_EXTINT_MAP
|
|
||||||
#define CONFIG_EIC_EXTINT_MAP {0, PIN_PA00}, {0, 32},
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// <<< end of configuration section >>>
|
// <<< end of configuration section >>>
|
||||||
|
|
||||||
#endif // HPL_EIC_CONFIG_H
|
#endif // HPL_EIC_CONFIG_H
|
||||||
|
|||||||
@ -25,19 +25,6 @@ void EXTERNAL_IRQ_0_init(void)
|
|||||||
{
|
{
|
||||||
_gclk_enable_channel(EIC_GCLK_ID, CONF_GCLK_EIC_SRC);
|
_gclk_enable_channel(EIC_GCLK_ID, CONF_GCLK_EIC_SRC);
|
||||||
|
|
||||||
// Set pin direction to input
|
|
||||||
gpio_set_pin_direction(PA00, GPIO_DIRECTION_IN);
|
|
||||||
|
|
||||||
gpio_set_pin_pull_mode(PA00,
|
|
||||||
// <y> Pull configuration
|
|
||||||
// <id> pad_pull_config
|
|
||||||
// <GPIO_PULL_OFF"> Off
|
|
||||||
// <GPIO_PULL_UP"> Pull-up
|
|
||||||
// <GPIO_PULL_DOWN"> Pull-down
|
|
||||||
GPIO_PULL_OFF);
|
|
||||||
|
|
||||||
gpio_set_pin_function(PA00, PINMUX_PA00A_EIC_EXTINT0);
|
|
||||||
|
|
||||||
ext_irq_init();
|
ext_irq_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -10,17 +10,11 @@
|
|||||||
#include "driver_init.h"
|
#include "driver_init.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
static void button_on_PA00_pressed(void)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Example of using EXTERNAL_IRQ_0
|
* Example of using EXTERNAL_IRQ_0
|
||||||
*/
|
*/
|
||||||
void EXTERNAL_IRQ_0_example(void)
|
void EXTERNAL_IRQ_0_example(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
ext_irq_register(PIN_PA00, button_on_PA00_pressed);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -33,7 +33,7 @@
|
|||||||
|
|
||||||
#include "hal_ext_irq.h"
|
#include "hal_ext_irq.h"
|
||||||
|
|
||||||
#define EXT_IRQ_AMOUNT 2
|
#define EXT_IRQ_AMOUNT 0
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Driver version
|
* \brief Driver version
|
||||||
|
|||||||
@ -69,7 +69,7 @@ static int ffs(int v)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define EXT_IRQ_AMOUNT 2
|
#define EXT_IRQ_AMOUNT 0
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief EXTINTx and pin number map
|
* \brief EXTINTx and pin number map
|
||||||
|
|||||||
21
main.cpp
21
main.cpp
@ -35,7 +35,6 @@ int main()
|
|||||||
App::Logging::setup();
|
App::Logging::setup();
|
||||||
|
|
||||||
radio::HwInstance radio_hw;
|
radio::HwInstance radio_hw;
|
||||||
SKULLC_LOG_DEBUG("Begin.");
|
|
||||||
|
|
||||||
/* Replace with your application code */
|
/* Replace with your application code */
|
||||||
while (true)
|
while (true)
|
||||||
@ -52,26 +51,6 @@ int main()
|
|||||||
|
|
||||||
SKULLC_LOG_INFO("Status: %d", radio_status);
|
SKULLC_LOG_INFO("Status: %d", radio_status);
|
||||||
|
|
||||||
static int transitioned = 0;
|
|
||||||
if (radio_status == 0x08 && transitioned == 0)
|
|
||||||
{
|
|
||||||
SKULLC_LOG_DEBUG("Transitioning...");
|
|
||||||
radio_hw.set_current_state(radio::HwInstance::States::PLL_ON);
|
|
||||||
transitioned = 1;
|
|
||||||
}
|
|
||||||
else if (radio_status == 0x09 && transitioned == 1)
|
|
||||||
{
|
|
||||||
SKULLC_LOG_DEBUG("Transitioning 2...");
|
|
||||||
radio_hw.set_current_state(radio::HwInstance::States::RX_ON);
|
|
||||||
transitioned = 2;
|
|
||||||
}
|
|
||||||
else if (radio_status == 0x09 && transitioned == 1)
|
|
||||||
{
|
|
||||||
SKULLC_LOG_DEBUG("Transitioning 2...");
|
|
||||||
radio_hw.set_current_state(radio::HwInstance::States::RX_ON);
|
|
||||||
transitioned = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
delay_ms(1000);
|
delay_ms(1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,22 +14,6 @@ namespace radio
|
|||||||
|
|
||||||
struct HwInstance
|
struct HwInstance
|
||||||
{
|
{
|
||||||
enum class States : std::uint8_t
|
|
||||||
{
|
|
||||||
P_ON = 0,
|
|
||||||
BUSY_RX,
|
|
||||||
BUSY_TX,
|
|
||||||
RX_ON,
|
|
||||||
TRX_OFF,
|
|
||||||
PLL_ON,
|
|
||||||
SLEEP,
|
|
||||||
PREP_DEEP_SLEEP,
|
|
||||||
BUSY_RX_AACK,
|
|
||||||
BUSY_TX_ARET,
|
|
||||||
RX_AACK_ON,
|
|
||||||
TX_ARET_ON
|
|
||||||
};
|
|
||||||
|
|
||||||
static HwInstance* instance();
|
static HwInstance* instance();
|
||||||
|
|
||||||
HwInstance();
|
HwInstance();
|
||||||
@ -42,13 +26,9 @@ struct HwInstance
|
|||||||
|
|
||||||
uint8_t register_read(const Registers& address);
|
uint8_t register_read(const Registers& address);
|
||||||
void register_write(const Registers& address, const uint8_t value);
|
void register_write(const Registers& address, const uint8_t value);
|
||||||
|
|
||||||
States current_state() const;
|
|
||||||
bool set_current_state(const States& new_state);
|
|
||||||
private:
|
private:
|
||||||
spi_m_sync_descriptor* m_spi = nullptr;
|
spi_m_sync_descriptor* m_spi = nullptr;
|
||||||
io_descriptor* m_spi_io = nullptr;
|
io_descriptor* m_spi_io = nullptr;
|
||||||
States m_current_state = States::P_ON;
|
|
||||||
|
|
||||||
void m_wait_transition_complete();
|
void m_wait_transition_complete();
|
||||||
};
|
};
|
||||||
|
|||||||
@ -7,13 +7,11 @@
|
|||||||
#include "radio_hardware_instance.h"
|
#include "radio_hardware_instance.h"
|
||||||
#include "radio_gpio.h"
|
#include "radio_gpio.h"
|
||||||
#include "radio_spi.h"
|
#include "radio_spi.h"
|
||||||
#include "utility_logging.hpp"
|
|
||||||
|
|
||||||
#include <hal_delay.h>
|
#include <hal_delay.h>
|
||||||
#include <hal_ext_irq.h>
|
#include <hal_ext_irq.h>
|
||||||
#include <utility_assert.hpp>
|
#include <utility_assert.hpp>
|
||||||
#include <utility_staticpointer.hpp>
|
#include <utility_staticpointer.hpp>
|
||||||
#include <optional>
|
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
@ -55,7 +53,6 @@ HwInstance::HwInstance()
|
|||||||
|
|
||||||
ext_irq_enable(IN_RADIO_IRQ);
|
ext_irq_enable(IN_RADIO_IRQ);
|
||||||
ext_irq_register(IN_RADIO_IRQ, _irq_handler);
|
ext_irq_register(IN_RADIO_IRQ, _irq_handler);
|
||||||
ext_irq_register(0, _irq_handler);
|
|
||||||
|
|
||||||
gpio_set_pin_level(OUT_RADIO_RST, true);
|
gpio_set_pin_level(OUT_RADIO_RST, true);
|
||||||
delay_ms(10);
|
delay_ms(10);
|
||||||
@ -75,12 +72,13 @@ HwInstance::HwInstance()
|
|||||||
// clear interrupts.
|
// clear interrupts.
|
||||||
register_read(Registers::IRQ_STATUS);
|
register_read(Registers::IRQ_STATUS);
|
||||||
|
|
||||||
set_current_state(States::TRX_OFF);
|
m_wait_transition_complete();
|
||||||
|
|
||||||
|
register_write(Registers::TRX_STATE, 0x08);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HwInstance::irq_handler()
|
void HwInstance::irq_handler()
|
||||||
{
|
{
|
||||||
SKULLC_LOG_DEBUG("IRQ set.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t HwInstance::register_read(const Registers& address)
|
uint8_t HwInstance::register_read(const Registers& address)
|
||||||
@ -113,78 +111,6 @@ void HwInstance::register_write(const Registers& address, const uint8_t value)
|
|||||||
gpio_set_pin_level(OUT_RADIO_CS, true);
|
gpio_set_pin_level(OUT_RADIO_CS, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HwInstance::set_current_state(const States& new_state)
|
|
||||||
{
|
|
||||||
if (new_state == m_current_state)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
m_wait_transition_complete();
|
|
||||||
bool can_transition = false;
|
|
||||||
std::optional<std::uint8_t> trx_state_value = std::nullopt;
|
|
||||||
|
|
||||||
switch (m_current_state)
|
|
||||||
{
|
|
||||||
case States::P_ON:
|
|
||||||
if (new_state == States::TRX_OFF)
|
|
||||||
{
|
|
||||||
can_transition = true;
|
|
||||||
trx_state_value = 0x08;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case States::TRX_OFF:
|
|
||||||
if (new_state == States::RX_ON)
|
|
||||||
{
|
|
||||||
can_transition = true;
|
|
||||||
trx_state_value = 0x06;
|
|
||||||
}
|
|
||||||
else if (new_state == States::PLL_ON)
|
|
||||||
{
|
|
||||||
can_transition = true;
|
|
||||||
trx_state_value = 0x09;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case States::RX_ON:
|
|
||||||
if (new_state == States::PLL_ON)
|
|
||||||
{
|
|
||||||
can_transition = true;
|
|
||||||
trx_state_value = 0x09;
|
|
||||||
}
|
|
||||||
else if (new_state == States::TRX_OFF)
|
|
||||||
{
|
|
||||||
can_transition = true;
|
|
||||||
trx_state_value = 0x08;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case States::PLL_ON:
|
|
||||||
if (new_state == States::RX_ON)
|
|
||||||
{
|
|
||||||
can_transition = true;
|
|
||||||
trx_state_value = 0x06;
|
|
||||||
}
|
|
||||||
else if (new_state == States::TRX_OFF)
|
|
||||||
{
|
|
||||||
can_transition = true;
|
|
||||||
trx_state_value = 0x08;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
SKULLC_ASSERT_DEBUG(false);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (can_transition)
|
|
||||||
{
|
|
||||||
register_write(Registers::TRX_STATE, *trx_state_value);
|
|
||||||
m_wait_transition_complete();
|
|
||||||
m_current_state = new_state;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void HwInstance::m_wait_transition_complete()
|
void HwInstance::m_wait_transition_complete()
|
||||||
{
|
{
|
||||||
while (true)
|
while (true)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user