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

CRC OK with gps, bitreversed

parent 7748c882
No related branches found
No related tags found
No related merge requests found
...@@ -35,5 +35,10 @@ ...@@ -35,5 +35,10 @@
"raspberry-pi-pico.cmakeAutoConfigure": true, "raspberry-pi-pico.cmakeAutoConfigure": true,
"raspberry-pi-pico.useCmakeTools": false, "raspberry-pi-pico.useCmakeTools": false,
"raspberry-pi-pico.cmakePath": "${HOME}/.pico-sdk/cmake/v3.29.9/bin/cmake", "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"
}
} }
...@@ -262,8 +262,8 @@ int gps_init( PIO pio, uint32_t baudrate){ ...@@ -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_add_shared_handler(PIO0_IRQ_0, pio_irq0_gps_handler, PICO_SHARED_IRQ_HANDLER_DEFAULT_ORDER_PRIORITY);
irq_set_enabled(PIO0_IRQ_0, true); irq_set_enabled(PIO0_IRQ_0, true);
/* Shift registers configuration */ /* Shift registers configuration */
sm_config_set_in_shift(&c, true, false, 8); sm_config_set_in_shift(&c, true, true, 8);
sm_config_set_out_shift(&c, true, false, 8); sm_config_set_out_shift(&c, true, true, 8);
/* Associates the pins connected to "in" instruction */ /* Associates the pins connected to "in" instruction */
sm_config_set_in_pins(&c, DATA_PIN); sm_config_set_in_pins(&c, DATA_PIN);
/* Write configuration to the State Machine */ /* Write configuration to the State Machine */
...@@ -273,7 +273,7 @@ int gps_init( PIO pio, uint32_t baudrate){ ...@@ -273,7 +273,7 @@ int gps_init( PIO pio, uint32_t baudrate){
/* Write the separator (that will trigger an interrupt) */ /* Write the separator (that will trigger an interrupt) */
pio_sm_put(gps_pio, gps_sm, '\n'); pio_sm_put(gps_pio, gps_sm, '\n');
printf("------- Initialized GPS SM\n"); printf("------- Initialized GPS SM\n");
init_nmea_dma(gps_sm); //init_nmea_dma(gps_sm);
return gps_sm; return gps_sm;
} }
......
.program pio .program pio
pull BLOCK ; Get initial argument: Delimiter char
out X, 32 ; Copy this char in X scratch register out X, 32 ; Copy this char in X scratch register
.wrap_target .wrap_target
skip: skip:
wait 0 PIN 0 [31]; Wait Start bit wait 0 PIN 0 [31]; Wait Start bit
;set PINS 0b010 [31] ; Let the start bit pass before sampling ;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: read_bit:
irq clear 4
in PINS 1 [31] ; Read a single data bit, then wait for one period in PINS 1 [31] ; Read a single data bit, then wait for one period
jmp Y-- read_bit ; Repeat 7 time 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 wait 1 PIN 0 ; Wait stop bit
mov Y, ISR mov Y, ISR
push ; Send the received Byte to the FIFO
jmp X!=Y skip ; Repeat reception if not end of Packet 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 .wrap
\ No newline at end of file
...@@ -5,17 +5,21 @@ ...@@ -5,17 +5,21 @@
#include "comparator/comparator.h" #include "comparator/comparator.h"
#include "hardware/pio.h" #include "hardware/pio.h"
#include "PIO_XOR/pio_xor.h" #include "PIO_XOR/pio_xor.h"
#include "hardware/sync.h"
int main() int main()
{ {
stdio_init_all(); stdio_init_all();
sleep_ms(2000); sleep_ms(2000);
// gps_init(pio0, 9600); int gps_sm = gps_init(pio0, 9600);
// comparator_init(pio0, 1000, 2); // comparator_init(pio0, 1000, 2);
test_pio_xor(); test_pio_xor();
char rx_gps = 0;
while (true) { 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);
} }
} }
...@@ -9,6 +9,6 @@ target_include_directories(PIO_XOR PUBLIC ...@@ -9,6 +9,6 @@ target_include_directories(PIO_XOR PUBLIC
"${PROJECT_SOURCE_DIR}/build/" "${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) pico_generate_pio_header(PIO_XOR ${PROJECT_SOURCE_DIR}/PIO_XOR/pio_xor.pio)
#include "pio_xor.h" #include "pio_xor.h"
void test_pio_xor(void){ void test_pio_xor(void){
sleep_ms(1000);
uint sm = pio_claim_unused_sm(pio0, true); uint sm = pio_claim_unused_sm(pio0, true);
printf("sm = %i\n",sm); printf("sm = %i\n",sm);
uint offset = pio_add_program(pio0, &pio_xor_program); int offset = pio_add_program(pio0, &pio_xor_program);
printf("------- Offset = %x\n", offset); printf("------- Offset = %i\n", offset);
pio_sm_config c = pio_xor_program_get_default_config(offset); pio_sm_config c = pio_xor_program_get_default_config(offset);
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_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); pio_sm_init(pio0, sm, offset, &c);
/* Enable the state machine */ /* Enable the state machine */
pio_sm_set_enabled(pio0, sm, 1); 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
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include <string.h> #include <string.h>
#include "pico/stdlib.h" #include "pico/stdlib.h"
#include "hardware/pio.h" #include "hardware/pio.h"
#include "hardware/adc.h"
#include "pio_xor.pio.h" #include "pio_xor.pio.h"
void test_pio_xor(void); void test_pio_xor(void);
......
.program pio_xor .program pio_xor
pull BLOCK ;pull BLOCK
.wrap_target .wrap_target
pull IfEmpty
repeat:
mov X, ISR ; 1: Copy ISR in X mov X, ISR ; 1: Copy ISR in X
mov ISR, NULL ; Set ISR to all zeros mov ISR, NULL ; Set ISR to all zeros
out ISR, 2 ; 2: ISR[0] = last byte bit, ISR[1] = new byte bit
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 mov Y, ISR ; 3: Copy ISR in Y
; 4: Computation of XOR
; 4: Computation of XOR
jmp !Y is_zero ; if Y = 00; out = 0 jmp !Y is_zero ; if Y = 00; out = 0
jmp Y-- once ; decrement once jmp Y-- once ; decrement once
once: once:
...@@ -26,7 +32,41 @@ ...@@ -26,7 +32,41 @@
send: send:
mov ISR, X ; 6: Copy X (Last iteration's ISR) into ISR mov ISR, X ; 6: Copy X (Last iteration's ISR) into ISR
in Y, 1 ; 7: Push the new byte into ISR in Y, 1 ; 7: Push the new byte into ISR
mov X, ISR ; jmp !OSRE repeat
push push
mov ISR, X
.wrap .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
.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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment