diff --git a/.vscode/settings.json b/.vscode/settings.json index 992389d4db51c9c63e53306e681357c4f7d01b8a..21b26d262448d16aeb78f3c75d341ac33ab024d6 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -35,5 +35,10 @@ "raspberry-pi-pico.cmakeAutoConfigure": true, "raspberry-pi-pico.useCmakeTools": false, "raspberry-pi-pico.cmakePath": "${HOME}/.pico-sdk/cmake/v3.29.9/bin/cmake", - "raspberry-pi-pico.ninjaPath": "${HOME}/.pico-sdk/ninja/v1.12.1/ninja" + "raspberry-pi-pico.ninjaPath": "${HOME}/.pico-sdk/ninja/v1.12.1/ninja", + "files.associations": { + "xosc.h": "c", + "gps.h": "c", + "pio_xor.h": "c" + } } diff --git a/GPS/GPS.c b/GPS/GPS.c index 803e25e76e811a1c248e5a7e35c5c11ea317a4f5..2264dc8142d11112cd3f95fecd93e590c9df9045 100644 --- a/GPS/GPS.c +++ b/GPS/GPS.c @@ -262,8 +262,8 @@ 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, false, 8); - sm_config_set_out_shift(&c, true, false, 8); + sm_config_set_in_shift(&c, true, true, 8); + sm_config_set_out_shift(&c, true, true, 8); /* Associates the pins connected to "in" instruction */ sm_config_set_in_pins(&c, DATA_PIN); /* Write configuration to the State Machine */ @@ -273,7 +273,7 @@ int gps_init( PIO pio, uint32_t baudrate){ /* 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; } diff --git a/GPS/pio.pio b/GPS/pio.pio index 092bf0b04b94d76cf36c5b8183bd7c50681a4f88..6d5c246d830106a69fee65e5c14fa9f519cd6940 100644 --- a/GPS/pio.pio +++ b/GPS/pio.pio @@ -1,20 +1,18 @@ .program pio - pull BLOCK ; Get initial argument: Delimiter char out X, 32 ; Copy this char in X scratch register .wrap_target skip: wait 0 PIN 0 [31]; Wait Start bit ;set PINS 0b010 [31] ; Let the start bit pass before sampling - set Y, 6 [15] ; Sample in the middle of data bits + set Y, 7 [15] ; 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 jmp Y-- read_bit ; Repeat 7 time - in PINS 1 ; Read the last bit - in NULL, 24 ; Fill the rest with zeroes + ;in NULL, 24 ; Fill the rest with zeroes wait 1 PIN 0 ; Wait stop bit mov Y, ISR - push ; Send the received Byte to the FIFO jmp X!=Y skip ; Repeat reception if not end of Packet - irq WAIT (0) ; Generate IRQ if end of Packet + ;irq WAIT 0 ; Generate IRQ if end of Packet .wrap \ No newline at end of file diff --git a/PA_PIO.c b/PA_PIO.c index 4cf4cbe8fa2841faa7f474f916bbaa89c272762b..58a37b9bc0656ba026d3a025bcae1270e29d2c0b 100644 --- a/PA_PIO.c +++ b/PA_PIO.c @@ -5,17 +5,21 @@ #include "comparator/comparator.h" #include "hardware/pio.h" #include "PIO_XOR/pio_xor.h" - +#include "hardware/sync.h" int main() { stdio_init_all(); sleep_ms(2000); - // gps_init(pio0, 9600); + int gps_sm = gps_init(pio0, 9600); // comparator_init(pio0, 1000, 2); test_pio_xor(); + char rx_gps = 0; while (true) { - tight_loop_contents(); + 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); } } diff --git a/PIO_XOR/CMakeLists.txt b/PIO_XOR/CMakeLists.txt index 9ee859f5ff77b12b8ed9e9d81832c9d9f9373302..4d4b3c9772657fd832e7b515d2b8fa86c6c21af5 100644 --- a/PIO_XOR/CMakeLists.txt +++ b/PIO_XOR/CMakeLists.txt @@ -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) +target_link_libraries(PIO_XOR pico_stdlib hardware_pio hardware_dma hardware_gpio hardware_timer hardware_adc) pico_generate_pio_header(PIO_XOR ${PROJECT_SOURCE_DIR}/PIO_XOR/pio_xor.pio) diff --git a/PIO_XOR/pio_xor.c b/PIO_XOR/pio_xor.c index eeffbebbe1b04934af7c88a95c4c0011e98055cd..5ae8a630893fc8c16c976095bf87acff6aadd2cf 100644 --- a/PIO_XOR/pio_xor.c +++ b/PIO_XOR/pio_xor.c @@ -1,34 +1,19 @@ #include "pio_xor.h" void test_pio_xor(void){ - sleep_ms(1000); uint sm = pio_claim_unused_sm(pio0, true); printf("sm = %i\n",sm); - uint offset = pio_add_program(pio0, &pio_xor_program); - printf("------- Offset = %x\n", offset); + int offset = pio_add_program(pio0, &pio_xor_program); + printf("------- Offset = %i\n", offset); pio_sm_config c = pio_xor_program_get_default_config(offset); - - sm_config_set_clkdiv_int_frac8(&c, 1, 0); + pio_gpio_init(pio0, 13); + pio_sm_set_consecutive_pindirs(pio0, sm, 13, 1, false); + 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_in_shift(&c, false, false, 8); pio_sm_init(pio0, sm, offset, &c); /* Enable the state machine */ pio_sm_set_enabled(pio0, sm, 1); - /* Write the separator (that will trigger an interrupt) */ - - pio_sm_put(pio0, sm, 0b1110010011100100); - - printf("for input 0b11: %x\n", pio_sm_get_blocking(pio0,0)); - //pio_sm_put(pio0, sm, 0b10); - printf("for input 0b10: %x\n", pio_sm_get_blocking(pio0,0)); - //pio_sm_put(pio0, sm, 0b01); - printf("for input 0b01: %x\n", pio_sm_get_blocking(pio0,0)); - //pio_sm_put(pio0, sm, 0b00); - printf("for input 0b00: %x\n", pio_sm_get_blocking(pio0,0)); - printf("for input 0b11: %x\n", pio_sm_get_blocking(pio0,0)); - //pio_sm_put(pio0, sm, 0b10); - printf("for input 0b10: %x\n", pio_sm_get_blocking(pio0,0)); - //pio_sm_put(pio0, sm, 0b01); - printf("for input 0b01: %x\n", pio_sm_get_blocking(pio0,0)); - //pio_sm_put(pio0, sm, 0b00); - printf("for input 0b00: %x\n", pio_sm_get_blocking(pio0,0)); } \ No newline at end of file diff --git a/PIO_XOR/pio_xor.h b/PIO_XOR/pio_xor.h index dfe9cd55d3cc5f427b4af5da17e86489293c140c..5229f6c58ec13c9db4d25f52cc36200243f11856 100644 --- a/PIO_XOR/pio_xor.h +++ b/PIO_XOR/pio_xor.h @@ -5,6 +5,7 @@ #include <string.h> #include "pico/stdlib.h" #include "hardware/pio.h" +#include "hardware/adc.h" #include "pio_xor.pio.h" void test_pio_xor(void); diff --git a/PIO_XOR/pio_xor.pio b/PIO_XOR/pio_xor.pio index 139dc90a658eb28e812b2303b5637d752da7160a..95ea777e6acd1996c2142dd851cc156e34974d04 100644 --- a/PIO_XOR/pio_xor.pio +++ b/PIO_XOR/pio_xor.pio @@ -1,12 +1,18 @@ .program pio_xor - pull BLOCK + ;pull BLOCK .wrap_target + pull IfEmpty + repeat: mov X, ISR ; 1: Copy ISR in X mov ISR, NULL ; Set ISR to all zeros - out ISR, 2 ; 2: ISR[0] = last byte bit, ISR[1] = new byte bit - mov Y, ISR ; 3: Copy ISR in Y - ; 4: Computation of XOR + irq wait 4 ; Wait pin sampling from uart + in PINS, 1 + out Y, 1 ; 2: ISR[0] = last byte bit, ISR[1] = new byte bit + in Y, 1 + mov Y, ISR ; 3: Copy ISR in Y + + ; 4: Computation of XOR jmp !Y is_zero ; if Y = 00; out = 0 jmp Y-- once ; decrement once once: @@ -26,7 +32,41 @@ send: mov ISR, X ; 6: Copy X (Last iteration's ISR) into ISR in Y, 1 ; 7: Push the new byte into ISR - mov X, ISR ; - push - mov ISR, X -.wrap \ No newline at end of file + jmp !OSRE repeat + push +.wrap + +; .program pio_xor +; .wrap_target +; pull IFEMPTY ; Changes OSR only when a full byte has been treated +; mov X, ISR ; 1: Copy ISR in X +; mov ISR, NULL ; Set ISR to all zeros +; wait 1 IRQ 5 +; out PINS, 1 ; 2: ISR[1] = new wbyte bit +; out ISR, 1 ; --- ISR[0] = last byte bit, +; mov Y, ISR ; 3: Copy ISR in Y +; ; 4: Computation of XOR + +; jmp !Y is_zero ; if Y = 00; out = 0 +; jmp Y-- once ; decrement once +; once: +; jmp !Y is_one +; jmp Y-- twice ; decrement twice +; twice: +; jmp !Y is_one ; If Y-2 <= 0 ; out = 1 +; jmp is_zero ; else out = 0 + +; is_zero: +; set Y, 0 +; jmp send +; is_one: +; set Y, 1 +; jmp send + +; send: +; mov ISR, X ; 6: Copy X (Last iteration's ISR) into ISR +; in Y, 1 ; 7: Push the new byte into ISR +; mov X, ISR ; +; push IFFULL; should setup autopush instead +; mov ISR, X +; .wrap \ No newline at end of file diff --git a/PIO_XOR/test.pio b/PIO_XOR/test.pio new file mode 100644 index 0000000000000000000000000000000000000000..42353c59278d3a8d11738a9f2485b91582cf1585 --- /dev/null +++ b/PIO_XOR/test.pio @@ -0,0 +1,32 @@ +.program pio_xor + pull BLOCK +.wrap_target + mov X, ISR ; 1: Copy ISR in X + mov ISR, NULL ; Set ISR to all zeros + out ISR, 2 ; 2: ISR[0] = last byte bit, ISR[1] = new byte bit + mov Y, ISR ; 3: Copy ISR in Y + ; 4: Computation of XOR + + jmp !Y is_zero ; if Y = 00; out = 0 + jmp Y-- once ; decrement once + once: + jmp !Y is_one + jmp Y-- twice ; decrement twice + twice: + jmp !Y is_one ; If Y-2 <= 0 ; out = 1 + jmp is_zero ; else out = 0 + + is_zero: + set Y, 0 + jmp send + is_one: + set Y, 1 + jmp send + + send: + mov ISR, X ; 6: Copy X (Last iteration's ISR) into ISR + in Y, 1 ; 7: Push the new byte into ISR + mov X, ISR ; + push + mov ISR, X +.wrap