P2P Transmitter
Loading...
Searching...
No Matches
main.c File Reference

Program entrypoint and synchronization controller Point-to-Point Laser Diode Transmitter https://github.com/CyberSamurai0/P2P-Transmitter. More...

#include "packet.h"
#include "packet-queue.h"
#include <stdlib.h>
#include <stdio.h>
#include "pico/stdlib.h"
#include "hardware/gpio.h"
#include <sys/select.h>
#include "pico/cyw43_arch.h"

Macros

#define USE_ONBOARD_LED   1
 If the Pi Pico module used does not have an onboard LED, set this to 0.
 
#define TX_PIN   0
 
#define RX_PIN   1
 
#define BAUD_RATE   20
 
#define PACKET_CACHE_SIZE   8
 
#define TX_PacketLength   12
 

Functions

void setOnboardLED (bool state)
 Sets the Raspberry Pi Pico W onboard LED to be on or off.
 
void cachePacket (Packet *p)
 Add a Packet to PacketCache and set its identifier to its index within the cache.
 
int64_t TX_FinishedSendingBit (alarm_id_t id, __unused void *user_data)
 Callback function to trigger transmission of the next bit in the sequence.
 
int64_t RX_ReadNextBit (alarm_id_t id, __unused void *user_data)
 
void RX_PinStateChanged (uint gpio, uint32_t events)
 
void stdinCharsAvailable (void *queue)
 
int main ()
 Entrypoint function for the program.
 

Variables

PacketPacketCache [PACKET_CACHE_SIZE] = {NULL}
 Caches the most recently transmitted packets to support retransmission.
 
int PacketCacheIndex = 0
 The current usable index of PacketCache. This should reset to 0 if it exceeds the length of PacketCache.
 
PacketTX_Packet = NULL
 Contains a pointer to the packet we are currently transmitting.
 
bool TX_PacketBits [TX_PacketLength] = {}
 
uint8_t TX_BitIndex = 0
 Contains the index of the bit within the packet that we are currently transmitting.
 
alarm_id_t TX_Alarm = 0
 Stores the alarm_id used to delay sending the next bit without sleeping.
 
bool RX_PacketBits [TX_PacketLength-1] = {}
 
uint8_t RX_BitIndex = 0
 
alarm_id_t RX_Alarm = 0
 
bool RX_Started = 0
 

Detailed Description

Program entrypoint and synchronization controller Point-to-Point Laser Diode Transmitter https://github.com/CyberSamurai0/P2P-Transmitter.

Macro Definition Documentation

◆ USE_ONBOARD_LED

#define USE_ONBOARD_LED   1

If the Pi Pico module used does not have an onboard LED, set this to 0.

Todo
Adjust configuration based on your own hardware!

Function Documentation

◆ cachePacket()

void cachePacket ( Packet * p)

Add a Packet to PacketCache and set its identifier to its index within the cache.

Warning
Packets should not be cached until they have been dequeued (transmitted), otherwise we may free them too early
Parameters
pPointer to the Packet to be cached

◆ main()

int main ( )

Entrypoint function for the program.

Returns
Status code

State of the onboard LED, used for status indication

Store created Packets until they can be transmitted in sequence

Warning
This is always zero because we are never computing parity for created packets

◆ RX_ReadNextBit()

int64_t RX_ReadNextBit ( alarm_id_t id,
__unused void * user_data )
Warning
we are maxing out at 8 bits here!

◆ setOnboardLED()

void setOnboardLED ( bool state)

Sets the Raspberry Pi Pico W onboard LED to be on or off.

Parameters
stateBoolean representing whether the light should be on or off

◆ TX_FinishedSendingBit()

int64_t TX_FinishedSendingBit ( alarm_id_t id,
__unused void * user_data )

Callback function to trigger transmission of the next bit in the sequence.

Parameters
idThe alarm_id_t that expired, triggering this function
user_dataAllow passing additional values without use of globals