Skip to content
Snippets Groups Projects
Commit 3c22d183 authored by giovanni.mangano's avatar giovanni.mangano
Browse files

Works with 2 pios

parent 36c5b49c
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,7 @@ char nmea_buffer_A[128];
char * nmea_buffer_pointer = nmea_buffer_A;
char checksum;
char nmea_buffer_B[128];
......@@ -45,15 +46,11 @@ 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);
/* Stop DMA */
while(!pio_sm_is_rx_fifo_empty(gps_pio, 0));
dma_channel_abort(nmea_dma_channel);
/* Change buffer */
char checksum = 0;
char checksum_temp = 0;
if(bufferA_selected){
bufferA_selected = 0;
......@@ -65,15 +62,6 @@ volatile void __not_in_flash_func (pio_irq0_gps_handler)(void)
memset(nmea_buffer_A, 0, 128);
nmea_buffer_pointer = nmea_buffer_A;
}
/* Restart DMA */
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);
......@@ -109,8 +97,6 @@ volatile void __not_in_flash_func (pio_irq0_gps_handler)(void)
}
//printf("%s\n", nmea_buffer_B);
}
printf("checksum = %x\n",checksum);
irq_clear(PIO0_IRQ_0);
}
}
......@@ -327,41 +313,41 @@ void init_nmea_dma(uint sm){
);
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, 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]+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.
);
printf("------- XOR 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, 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]+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.
// );
// printf("------- XOR DMA Started\n");
}
\ No newline at end of file
......@@ -23,6 +23,8 @@ extern volatile char test_val;
extern volatile int interrupt;
extern char checksum;
unsigned char reverseByte(unsigned char byte);
......
.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:
wait 0 PIN 0 [31]; Wait Start bit
set Y, 7 [13] ; Sample in the middle of data bits
read_bit:
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
......@@ -12,32 +12,21 @@ int main()
{
stdio_init_all();
sleep_ms(2000);
test_pio_xor(9600);
int gps_sm = gps_init(pio0, 9600);
// comparator_init(pio0, 1000, 2);
test_pio_xor();
char rx_gps = 0;
//comparator_init(pio0, 1000, 2);
int read = 0;
char checksum = 0;
char old = 0;
char final_xor = '\n' ^ '\r' ^ '*' ^ '$' ;
while (true) {
read = pio_sm_get_blocking(pio0,1);
printf("res = %08x\n", read);
if(read == 0){
pio_sm_put(pio0,1, 0);
read = pio_sm_get_blocking(pio1,0);
if(interrupt){
char hex[3];
printf("Read checksum = %x\n",checksum);
snprintf(hex, sizeof(hex), "%02X", (char)checksum);
printf("PIO Checksum = %02x\n", final_xor ^ reverseByte(read>>24) ^ hex[0] ^ hex[1] );
pio_sm_put_blocking(pio1, 0, 0x24<<24);
interrupt = 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);
// }
}
}
#include "pio_xor.h"
void test_pio_xor(void){
uint sm = pio_claim_unused_sm(pio0, true);
void test_pio_xor(uint32_t baudrate){
uint sm = pio_claim_unused_sm(pio1, true);
printf("sm = %i\n",sm);
int offset = pio_add_program(pio0, &pio_xor_program);
int offset = pio_add_program(pio1, &pio_xor_program);
printf("------- Offset = %i\n", 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);
pio_gpio_init(pio1, 13);
pio_sm_set_consecutive_pindirs(pio1, sm, 13, 1, false);
sm_config_set_in_pins(&c, 13);
int clock_freq = clock_get_hz(clk_sys);
sm_config_set_clkdiv_int_frac8(&c, 1, 0);
int sm_frequency = baudrate*32;
int sm_divider_int = clock_freq/sm_frequency;
float sm_divider_float = ((float)clock_freq/sm_frequency) - sm_divider_int;
printf("------- State machine divider = %i - %f\n", sm_divider_int, sm_divider_float);
sm_config_set_clkdiv_int_frac8(&c, sm_divider_int, sm_divider_float);
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);
pio_sm_init(pio1, sm, offset, &c);
/* Enable the state machine */
pio_sm_put(pio0, sm, 0);
pio_sm_set_enabled(pio0, sm, 1);
pio_sm_put(pio1, sm, 0);
pio_sm_set_enabled(pio1, sm, 1);
}
\ No newline at end of file
......@@ -10,6 +10,6 @@
#include "hardware/dma.h"
#include "pio_xor.pio.h"
void test_pio_xor(void);
void test_pio_xor(uint32_t baudrate);
#endif
\ No newline at end of file
.program pio_xor
;pull BLOCK
;mov OSR, NULL
.wrap_target
pull NoBlock
wait 0 PIN 0 [31]; Wait Start bit
nop [15]
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
irq wait 4 ; Wait pin sampling from uart
in PINS, 1
in PINS, 1 [11]
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 is_zero_long; if Y = 00; out = 0
jmp Y-- once ; decrement once
once:
jmp !Y is_one
jmp !Y is_one_long
jmp Y-- twice ; decrement twice
twice:
jmp !Y is_one ; If Y-2 >= 0 ; out = 1
jmp is_zero ; else out = 0
jmp !Y is_one_fast; If Y-2 >= 0 ; out = 1
jmp is_zero_fast ; else out = 0
is_zero:
set Y, 0
is_zero_long:
set Y, 0 [9]
jmp send
is_one:
set Y, 1
is_zero_fast:
set Y, 0 [3]
jmp send
is_one_long:
set Y, 1 [7]
jmp send
is_one_fast:
set Y, 1 [5]
jmp send
send:
......@@ -38,39 +42,5 @@
mov OSR, ISR
mov x, OSR
push
wait 1 PIN 0; Wait Stop bit
.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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment