diff --git a/.vscode/settings.json b/.vscode/settings.json index 90ba40d6528ec7344c1a88db73b171668fb8c090..a974669b50c990f6c801bc1da8ff1bd53b86ccbd 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -40,6 +40,7 @@ "xosc.h": "c", "gps.h": "c", "pio_xor.h": "c", - "dma.h": "c" + "dma.h": "c", + "sync.h": "c" } } diff --git a/GPS/GPS.c b/GPS/GPS.c index e602baf70a7c594722f93a5cde39761e6e5d54ee..9d347fb7cc33a1cd0aa375890a5fe36951d507e3 100644 --- a/GPS/GPS.c +++ b/GPS/GPS.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. ); diff --git a/GPS/GPS.h b/GPS/GPS.h index 5ac7b5be48509ab39acea9dbf7fc7ba86ae90efe..6b2a29493c56dda86f608eb68d5984948b620c0a 100644 --- a/GPS/GPS.h +++ b/GPS/GPS.h @@ -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; diff --git a/GPS/pio.pio b/GPS/pio.pio index 0b2f78b22d0894cb8c44b67cfb20807bda88fb53..02a052c6861d2a114ba29edfc1187cbc3c462efa 100644 --- a/GPS/pio.pio +++ b/GPS/pio.pio @@ -1,5 +1,5 @@ .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 diff --git a/PA_PIO.c b/PA_PIO.c index 3a69c67d7bf114a329655b2bfe2b8f0ef9c0132c..3713d81ec23ae7618c77d4154abe74ed0000c626 100644 --- a/PA_PIO.c +++ b/PA_PIO.c @@ -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); + // } + } diff --git a/PIO_XOR/pio_xor.pio b/PIO_XOR/pio_xor.pio index 69273ab53461b863cbc357a8eccb4974c570ea8b..1f182e2d7c15ee8119123b47413716efaea7797e 100644 --- a/PIO_XOR/pio_xor.pio +++ b/PIO_XOR/pio_xor.pio @@ -1,7 +1,8 @@ .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 diff --git a/test.py b/test.py index 31dfa03647ee28f243c2275a076f615deb252d88..91538b0a05d69eafe9752e1c98d27e57fcf887a0 100644 --- a/test.py +++ b/test.py @@ -1,4 +1,4 @@ -input_str = '$GLGSV,1,1,00,1*78*78$' +input_str = '$' # Compute bytewise XOR xor_result = 0