Skip to content
Snippets Groups Projects
Commit c0ea6980 authored by Giovanni Mangano's avatar Giovanni Mangano
Browse files

Wors with manual feedback SM1 tx to SM1 rx

parent cec52af5
No related branches found
No related tags found
No related merge requests found
......@@ -39,6 +39,7 @@
"files.associations": {
"xosc.h": "c",
"gps.h": "c",
"pio_xor.h": "c"
"pio_xor.h": "c",
"dma.h": "c"
}
}
#include "GPS.h"
char * nmea_buffer_pointer;
char nmea_buffer_A[128];
char * nmea_buffer_pointer = nmea_buffer_A;
char nmea_buffer_B[128];
uint8_t bufferA_selected = 1;
int nmea_dma_channel;
int test_val = 0xabbacafe;
dma_channel_config c;
PIO gps_pio;
......@@ -22,11 +26,16 @@ gps_t gps_data = {0};
gps_t gps = {0};
int xor_dma_channel = 0;
dma_channel_config xor_dma_c;
volatile void __not_in_flash_func (pio_irq0_gps_handler)(void)
{
interrupt = 1;
printf("GPS HANDLER: interrupt : %x\n", pio_interrupt_get(gps_pio, 0));
if (pio_interrupt_get(gps_pio, 0)) {
pio_sm_put(pio0,1, 0);
/* Stop DMA */
while(!pio_sm_is_rx_fifo_empty(gps_pio, 0));
dma_channel_abort(nmea_dma_channel);
......@@ -44,7 +53,15 @@ volatile void __not_in_flash_func (pio_irq0_gps_handler)(void)
nmea_buffer_pointer = nmea_buffer_A;
}
/* Restart DMA */
dma_channel_configure(nmea_dma_channel, &c, nmea_buffer_pointer, (io_rw_8*)&pio0_hw->rxf[0], 128, true);
dma_channel_configure(
xor_dma_channel, // Channel to be configured
&xor_dma_c, // The configuration we just created
(io_rw_8*)&pio0_hw->txf[1], // The initial write address
nmea_buffer_pointer, // The initial read address
128, // Number of transfers; in this case each is 1 byte.
false // Start immediately.
);
dma_channel_configure(nmea_dma_channel, &c, nmea_buffer_pointer+1, (io_rw_8*)&pio0_hw->rxf[0]+3, 128, true);
/* Let the PIO read again */
pio_interrupt_clear(gps_pio, 0);
/* Parse NMEA phrase */
......@@ -262,18 +279,18 @@ int gps_init( PIO pio, uint32_t baudrate){
irq_add_shared_handler(PIO0_IRQ_0, pio_irq0_gps_handler, PICO_SHARED_IRQ_HANDLER_DEFAULT_ORDER_PRIORITY);
irq_set_enabled(PIO0_IRQ_0, true);
/* Shift registers configuration */
sm_config_set_in_shift(&c, true, true, 8);
sm_config_set_out_shift(&c, true, true, 8);
sm_config_set_in_shift(&c, true, false, 32);
sm_config_set_out_shift(&c, true, true, 32);
/* Associates the pins connected to "in" instruction */
sm_config_set_in_pins(&c, DATA_PIN);
/* Write configuration to the State Machine */
pio_sm_init(gps_pio, gps_sm, offset, &c);
/* Enable the state machine */
pio_sm_put(gps_pio, gps_sm, '\n'<<24);
pio_sm_set_enabled(gps_pio, gps_sm, 1);
/* Write the separator (that will trigger an interrupt) */
pio_sm_put(gps_pio, gps_sm, '\n');
printf("------- Initialized GPS SM\n");
//init_nmea_dma(gps_sm);
init_nmea_dma(gps_sm);
return gps_sm;
}
......@@ -285,15 +302,34 @@ void init_nmea_dma(uint sm){
channel_config_set_transfer_data_size(&c, DMA_SIZE_8);
channel_config_set_read_increment(&c, false);
channel_config_set_write_increment(&c, true);
channel_config_set_dreq(&c, pio_get_dreq(gps_pio, 0, false));
channel_config_set_dreq(&c, pio_get_dreq(gps_pio, sm, false));
dma_channel_configure(
nmea_dma_channel, // Channel to be configured
&c, // The configuration we just created
nmea_buffer_pointer, // The initial write address
(io_rw_8*)&pio0_hw->rxf[sm], // The initial read address
nmea_buffer_pointer+1, // The initial write address
(io_rw_8*)&pio0_hw->rxf[sm]+3, // The initial read address
128, // Number of transfers; in this case each is 1 byte.
true // Start immediately.
);
printf("------- GPS DMA Started\n");
printf("Configuring XOR DMA...\n");
xor_dma_channel = dma_claim_unused_channel(true);
printf("------- Using DMA Channel %i\n", xor_dma_channel);
xor_dma_c = dma_channel_get_default_config(xor_dma_channel);
channel_config_set_transfer_data_size(&xor_dma_c, DMA_SIZE_8);
channel_config_set_read_increment(&xor_dma_c, true);
channel_config_set_write_increment(&xor_dma_c, false);
channel_config_set_dreq(&xor_dma_c, pio_get_dreq(gps_pio, sm, false));
dma_channel_configure(
xor_dma_channel, // Channel to be configured
&xor_dma_c, // The configuration we just created
(io_rw_8*)&pio0_hw->txf[1], // The initial write address
nmea_buffer_pointer, // The initial read address
128, // Number of transfers; in this case each is 1 byte.
false // Start immediately.
);
printf("------- XOR DMA Started\n");
}
\ No newline at end of file
......@@ -17,6 +17,10 @@
#define GPS_2D_FIX 1
#define GPS_3D_FIX 3
extern char * nmea_buffer_pointer;
extern volatile int interrupt;
typedef struct{
uint8_t sat;
time_t time;
......
......@@ -4,15 +4,13 @@
.wrap_target
skip:
wait 0 PIN 0 [31]; Wait Start bit
;set PINS 0b010 [31] ; Let the start bit pass before sampling
set Y, 7 [15] ; Sample in the middle of data bits
set Y, 7 [13] ; Sample in the middle of data bits
read_bit:
irq clear 4
in PINS 1 [31] ; Read a single data bit, then wait for one period
in PINS 1 [29] ; Read a single data bit, then wait for one period
jmp Y-- read_bit ; Repeat 7 time
;in NULL, 24 ; Fill the rest with zeroes
wait 1 PIN 0 ; Wait stop bit
mov Y, ISR
mov Y, ISR
push
jmp X!=Y skip ; Repeat reception if not end of Packet
;irq WAIT 0 ; Generate IRQ if end of Packet
.wrap
\ No newline at end of file
irq WAIT 0 ; Generate IRQ if end of Packet
.wrap
......@@ -7,6 +7,15 @@
#include "PIO_XOR/pio_xor.h"
#include "hardware/sync.h"
unsigned char reverseByte(unsigned char byte) {
unsigned char reversed = 0;
for (int i = 0; i < 8; i++) {
reversed = (reversed << 1) | (byte & 1); // Shift left and add LSB
byte >>= 1; // Shift byte to right
}
return reversed;
}
int main()
{
stdio_init_all();
......@@ -15,11 +24,26 @@ int main()
// comparator_init(pio0, 1000, 2);
test_pio_xor();
char rx_gps = 0;
int read = 0;
char checksum = 0;
while (true) {
pio_sm_put_blocking(pio0, 1, rx_gps);
printf("for input 0b00: %x\n", pio_sm_get_blocking(pio0,1));
rx_gps = pio_sm_get_blocking(pio0, gps_sm)>>24;
printf("received %c\n", rx_gps);
read = pio_sm_get_blocking(pio0,1);
printf("res = %08x\n", read);
sleep_us(100);
if(interrupt){
//read = pio_sm_get_blocking(pio0,1);
char checksum = read ;
printf("calculated checksum = %x\n", reverseByte(checksum));
//pio_sm_put(pio0,1, 0<<24);
//read = pio_sm_get_blocking(pio0,1);
interrupt = 0;
}
else {
pio_sm_put(pio0,1, read<<24);
}
}
}
......@@ -9,6 +9,6 @@ target_include_directories(PIO_XOR PUBLIC
"${PROJECT_SOURCE_DIR}/build/"
)
target_link_libraries(PIO_XOR pico_stdlib hardware_pio hardware_dma hardware_gpio hardware_timer hardware_adc)
target_link_libraries(PIO_XOR pico_stdlib GPS hardware_pio hardware_dma hardware_gpio hardware_timer hardware_adc)
pico_generate_pio_header(PIO_XOR ${PROJECT_SOURCE_DIR}/PIO_XOR/pio_xor.pio)
......@@ -11,9 +11,10 @@ void test_pio_xor(void){
sm_config_set_in_pins(&c, 13);
sm_config_set_clkdiv_int_frac8(&c, 1, 0);
sm_config_set_out_shift(&c, true, false, 8);
sm_config_set_out_shift(&c, false, false, 8);
sm_config_set_in_shift(&c, false, false, 8);
pio_sm_init(pio0, sm, offset, &c);
/* Enable the state machine */
pio_sm_put(pio0, sm, 0);
pio_sm_set_enabled(pio0, sm, 1);
}
\ No newline at end of file
......@@ -6,6 +6,8 @@
#include "pico/stdlib.h"
#include "hardware/pio.h"
#include "hardware/adc.h"
#include "../GPS/GPS.h"
#include "hardware/dma.h"
#include "pio_xor.pio.h"
void test_pio_xor(void);
......
......@@ -19,7 +19,7 @@
jmp !Y is_one
jmp Y-- twice ; decrement twice
twice:
jmp !Y is_one ; If Y-2 <= 0 ; out = 1
jmp !Y is_one ; If Y-2 >= 0 ; out = 1
jmp is_zero ; else out = 0
is_zero:
......
input_str = '$GLGSV,1,1,00,1*78*78$'
# Compute bytewise XOR
xor_result = 0
for char in input_str:
xor_result ^= ord(char) # XOR each character's ASCII value
# Display the result
print(hex(xor_result))
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment