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

Direct feedback in SM1 via MOV instruction

parent c0ea6980
No related branches found
No related tags found
No related merge requests found
......@@ -40,6 +40,7 @@
"xosc.h": "c",
"gps.h": "c",
"pio_xor.h": "c",
"dma.h": "c"
"dma.h": "c",
"sync.h": "c"
}
}
......@@ -12,7 +12,7 @@ uint8_t bufferA_selected = 1;
int nmea_dma_channel;
int test_val = 0xabbacafe;
volatile char test_val = 0;
dma_channel_config c;
......@@ -29,10 +29,23 @@ gps_t gps = {0};
int xor_dma_channel = 0;
dma_channel_config xor_dma_c;
int other_xor_dma_channel = 0;
dma_channel_config other_xor_dma_c;
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;
}
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));
printf("final checksummmmm: %x\n", reverseByte(test_val));
if (pio_interrupt_get(gps_pio, 0)) {
pio_sm_put(pio0,1, 0);
......@@ -319,15 +332,34 @@ void init_nmea_dma(uint sm){
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_read_increment(&xor_dma_c, false);
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
(io_rw_8*)&pio0_hw->txf[1]+3, // The initial write address
&test_val, // The initial read address
128, // Number of transfers; in this case each is 1 byte.
false // Start immediately.
);
printf("------- XOR DMA Started\n");
printf("Configuring XOR DMA...\n");
other_xor_dma_channel = dma_claim_unused_channel(true);
printf("------- Using DMA Channel %i\n", other_xor_dma_channel);
other_xor_dma_c = dma_channel_get_default_config(other_xor_dma_channel);
channel_config_set_transfer_data_size(&other_xor_dma_c, DMA_SIZE_8);
channel_config_set_read_increment(&other_xor_dma_c, false);
channel_config_set_write_increment(&other_xor_dma_c, false);
channel_config_set_dreq(&other_xor_dma_c, pio_get_dreq(gps_pio, sm, false));
dma_channel_configure(
other_xor_dma_channel, // Channel to be configured
&other_xor_dma_c, // The configuration we just created
&test_val,
(io_rw_8*)&pio0_hw->rxf[1],
128, // Number of transfers; in this case each is 1 byte.
false // Start immediately.
);
......
......@@ -19,8 +19,13 @@
extern char * nmea_buffer_pointer;
extern volatile char test_val;
extern volatile int interrupt;
unsigned char reverseByte(unsigned char byte);
typedef struct{
uint8_t sat;
time_t time;
......
.program pio
out X, 32 ; Copy this char in X scratch register
;out X, 32 ; Copy this char in X scratch register
.wrap_target
skip:
......@@ -9,8 +9,8 @@
irq clear 4
in PINS 1 [29] ; Read a single data bit, then wait for one period
jmp Y-- read_bit ; Repeat 7 time
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
; jmp X!=Y skip ; Repeat reception if not end of Packet
; irq WAIT 0 ; Generate IRQ if end of Packet
.wrap
......@@ -7,14 +7,6 @@
#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()
{
......@@ -26,22 +18,24 @@ int main()
char rx_gps = 0;
int read = 0;
char checksum = 0;
char old = 0;
while (true) {
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);
if(read == 0){
pio_sm_put(pio0,1, 0);
}
// sleep_us(100);
// if(interrupt){
// char checksum = read ;
// printf("calculated checksum = %x\n", reverseByte(checksum));
// interrupt = 0;
// }
// else {
// pio_sm_put(pio0,1, read<<24);
// }
}
......
.program pio_xor
;pull BLOCK
;mov OSR, NULL
.wrap_target
pull IfEmpty
pull NoBlock
repeat:
mov X, ISR ; 1: Copy ISR in X
mov ISR, NULL ; Set ISR to all zeros
......@@ -33,6 +34,9 @@
mov ISR, X ; 6: Copy X (Last iteration's ISR) into ISR
in Y, 1 ; 7: Push the new byte into ISR
jmp !OSRE repeat
in NULL, 24
mov OSR, ISR
mov x, OSR
push
.wrap
......
input_str = '$GLGSV,1,1,00,1*78*78$'
input_str = '$'
# Compute bytewise XOR
xor_result = 0
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment