SingingCat 0
application
transmit.c
1#include "sx1262/sx1262.h"
2#include "sx1262/sx126x.h"
3#include "sx1262/sx126x_hal.h"
4#include "mculibrary.h"
5#include "networkif.h"
6#include "metrics/metrics.h"
7static volatile byte transmitting = 0;
8int sx1262_transmit_fail_counter = 0;
9void sx1262_done_transmit() {
10 transmitting = 0;
11 printf("[sx1262] lora transmit lock released\r\n");
12}
13int sx1262_is_transmitting() {
14 return transmitting;
15}
16int sx1262_busy(struct network_context *nctx) {
17 return transmitting;
18}
19
20// called by irq handler if chip signals it is done
21void transmit_complete_irq() {
22 transmitting = 1;
23 printf("[sx1262] Transmit complete\r\n");
24 sx1262_switch_to_rx();
25}
26
27// afaict: set transmit buffer offset to 0 and write to it at that address, then trigger transmit
28int sx1262_transmit(struct network_context *nctx, const uint8_t *buf, uint16_t size) {
29 if (size > 255) {
30 printf("[sx1262] LoRA maximum packet size is 255 bytes. attempt to send %i bytes\r\n", size);
31 return 1;
32 }
33 sx1262_clear_rx_mode();
34 printf("[sx1262] Transmitting %i bytes\r\n", size);
35 // goto standby mode so not to overwrite buffer in case we just receive one now..
36
37 sx1262_set_lora_packet_type(nctx);
38
39 // txparams
40 sx126x_set_tx_params(nctx, 22, SX126X_RAMP_200_US);
41 // set buf address & write
43 sx126x_write_buffer(nctx, 0, buf, size);
44 //setmodulationparams
45 sx1262_set_lora_parameters(nctx);
46 //setpacketparams
47 sx1262_set_packet_params(nctx, size);
48
49 //setioirqparams
50 //sync work value
51 sx126x_set_tx(nctx, 3000); // try for max. 3 seconds
52 transmitting = 2;
53 // clear irq txdone flag
54 print_chip_status(nctx, 1);
55 IncMetric_PKTS_LORA_CTR_OUT;
56 return 0;
57}
SX126x radio driver definition.
sx126x_status_t sx126x_set_tx(struct network_context *nctx, const uint32_t timeout_in_ms)
Set the chip in transmission mode.
Definition: sx126x.c:258
sx126x_status_t sx126x_write_buffer(struct network_context *nctx, const uint8_t offset, const uint8_t *buffer, const uint8_t size)
Write data into radio Tx buffer memory space.
Definition: sx126x.c:426
sx126x_status_t sx126x_set_buffer_base_address(struct network_context *nctx, const uint8_t tx_base_address, const uint8_t rx_base_address)
Set buffer start addresses for both Tx and Rx operations.
Definition: sx126x.c:675
sx126x_status_t sx126x_set_tx_params(struct network_context *nctx, const int8_t pwr_in_dbm, const sx126x_ramp_time_t ramp_time)
Set the parameters for TX power and power amplifier ramp time.
Definition: sx126x.c:587
Hardware Abstraction Layer for SX126x.