Skip to content
Snippets Groups Projects
Commit 84145774 authored by Paulus Kruger's avatar Paulus Kruger
Browse files

first version

parents
No related branches found
No related tags found
No related merge requests found
cmake_minimum_required(VERSION 3.13)
include(pico_sdk_import.cmake)
project(test_project C CXX ASM)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
pico_sdk_init()
add_executable(test
test.c
)
pico_enable_stdio_usb(test 1)
pico_add_extra_outputs(test)
pico_generate_pio_header(test ${CMAKE_CURRENT_LIST_DIR}/hba_tx.pio)
pico_generate_pio_header(test ${CMAKE_CURRENT_LIST_DIR}/hba_rx.pio)
target_link_libraries(
test pico_stdlib
hardware_pio
pico_multicore
)
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "{}"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright 2020 Stichting Nederlandse Wetenschappelijk Onderzoek Instituten,
ASTRON Netherlands Institute for Radio Astronomy
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
NOTICE 0 → 100644
Citation Notice version 1.0
This Citation Notice is part of the LOFAR software suite.
Parties that use ASTRON Software resulting in papers and/or publications are requested to
refer to the DOI(s) that correspond(s) to the version(s) of the ASTRON Software used:
<List of DOIs>
Parties that use ASTRON Software for purposes that do not result in publications (e.g.
commercial parties) are asked to inform ASTRON about their use of ASTRON Software, by
sending an email to including the DOIs mentioned above in the message.
\ No newline at end of file
# lofar_hbat_pico
Program to control LOFAR high-band antenna tiles (HBAT) using a raspberry pi pico.
GP15 should be connected to the HBAT communication input.
# Building code
## Requirements
pico-sdk
## Instructions
- mkdir build
- cd build
- cmake ../
- make
- Connect pico while pressing BOOTSEL button
- copy test.uf2 to pico
# Controlling tile
Use jupyter scripts in scripts directory
# Program structure
- hba_tx.pio: Load delay from FIFO, thereafter continiously clock data out as they arrive in FIFO
- hba_rx.pio: Load time-out from FIFO, thereafter continiously: wait for first falling edge, measure time between falling edges and push it to FIFO until time-out.
- test.c:
- Main core:
- Put RX FIFO data into RX buffer as they arrive from PIO
- Put TX buffer data in TX FIFO when available
- Second core:
- Transmit RX buffer data over USB serial when available
- Receive TX data from USB serial and put in TX buffer
.program hba_rx
.define public T1 8
start:
pull
mov x,OSR
mov y,OSR
begin:
mov x,y
mov ISR,x
push ;A 0 means when just started
wait 1 pin 0 ;wait for high
wait 0 pin 0 ;wait for low
looplow: ;1+T1 instructions per loop, wait for pin to go high
jmp pin loophigh [T1];wait for high
jmp x-- looplow ;
jmp begin ;timeout, start from beginning
loophigh: ; 1+T1 instructions per loop, wait for pin to go low
jmp x-- loophigh2;
jmp begin; timeout, start from beginning
loophigh2:
jmp pin loophigh [T1];wait for low
capture: ; Push x register, start at 0 again
mov ISR,X
push
mov x,y
jmp looplow;
% c-sdk {
static inline void hba_rx_program_init(PIO pio, uint sm, uint offset, uint pin) {
pio_sm_config c = hba_rx_program_get_default_config(offset);
// Map the state machine's OUT pin group to one pin, namely the `pin`
// parameter to this function.
sm_config_set_out_pins(&c, pin, 1);
// Set this pin's GPIO function (connect PIO to the pad)
pio_gpio_init(pio, pin);
// Set the pin direction to output at the PIO
pio_sm_set_consecutive_pindirs(pio, sm, pin, 1, false); //Comment out when using pullups
// pio_sm_set_consecutive_pindirs()
sm_config_set_jmp_pin(&c, pin); // for JMP
sm_config_set_in_pins(&c, pin); // for WAIT
sm_config_set_in_shift(&c, true, true, 16);
//Make clock slower
// pio->sm[0].clkdiv=(uint32_t) (2.5f*(1<<16));
// pio->sm[0].clkdiv=0xff000000;
sm_config_set_clkdiv(&c, 0x40);
// Load our configuration, and jump to the start of the program
pio_sm_init(pio, sm, offset, &c);
// Set the state machine running
pio_sm_set_enabled(pio, sm, true);
}
%}
.program hba_tx
; Repeatedly get one word of data from the TX FIFO, stalling when the FIFO is
; empty. Write the least significant bit to the OUT pin group.
pull
mov x,OSR
mov y,OSR
set pins, 0
set pindirs, 0 ;High (Input-> should pull high to give high)
.wrap_target
; pull
; set y,7
;bitloop:
out pindirs, 1
; out pins, 1
mov x, y
loop2:
jmp x-- loop2
; jmp y-- bitloop
.wrap
% c-sdk {
static inline void hba_tx_program_init(PIO pio, uint sm, uint offset, uint pin) {
pio_sm_config c = hba_tx_program_get_default_config(offset);
// Map the state machine's OUT pin group to one pin, namely the `pin`
// parameter to this function.
sm_config_set_out_pins(&c, pin, 1);
// Set this pin's GPIO function (connect PIO to the pad)
pio_gpio_init(pio, pin);
// Set the pin direction to output at the PIO
// pio_sm_set_consecutive_pindirs(pio, sm, pin, 1, true); //Comment out when using pullups
sm_config_set_out_shift(&c, true, true, 8);
//Make clock slower
// pio->sm[0].clkdiv=(uint32_t) (2.5f*(1<<16));
// pio->sm[0].clkdiv=0xff000000;
// sm_config_set_clkdiv(&c, 0xff00);
// Load our configuration, and jump to the start of the program
pio_sm_init(pio, sm, offset, &c);
// Set the state machine running
pio_sm_set_enabled(pio, sm, true);
}
%}
# This is a copy of <PICO_SDK_PATH>/external/pico_sdk_import.cmake
# This can be dropped into an external project to help locate this SDK
# It should be include()ed prior to project()
if (DEFINED ENV{PICO_SDK_PATH} AND (NOT PICO_SDK_PATH))
set(PICO_SDK_PATH $ENV{PICO_SDK_PATH})
message("Using PICO_SDK_PATH from environment ('${PICO_SDK_PATH}')")
endif ()
if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT} AND (NOT PICO_SDK_FETCH_FROM_GIT))
set(PICO_SDK_FETCH_FROM_GIT $ENV{PICO_SDK_FETCH_FROM_GIT})
message("Using PICO_SDK_FETCH_FROM_GIT from environment ('${PICO_SDK_FETCH_FROM_GIT}')")
endif ()
if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_PATH} AND (NOT PICO_SDK_FETCH_FROM_GIT_PATH))
set(PICO_SDK_FETCH_FROM_GIT_PATH $ENV{PICO_SDK_FETCH_FROM_GIT_PATH})
message("Using PICO_SDK_FETCH_FROM_GIT_PATH from environment ('${PICO_SDK_FETCH_FROM_GIT_PATH}')")
endif ()
set(PICO_SDK_PATH "${PICO_SDK_PATH}" CACHE PATH "Path to the Raspberry Pi Pico SDK")
set(PICO_SDK_FETCH_FROM_GIT "${PICO_SDK_FETCH_FROM_GIT}" CACHE BOOL "Set to ON to fetch copy of SDK from git if not otherwise locatable")
set(PICO_SDK_FETCH_FROM_GIT_PATH "${PICO_SDK_FETCH_FROM_GIT_PATH}" CACHE FILEPATH "location to download SDK")
if (NOT PICO_SDK_PATH)
if (PICO_SDK_FETCH_FROM_GIT)
include(FetchContent)
set(FETCHCONTENT_BASE_DIR_SAVE ${FETCHCONTENT_BASE_DIR})
if (PICO_SDK_FETCH_FROM_GIT_PATH)
get_filename_component(FETCHCONTENT_BASE_DIR "${PICO_SDK_FETCH_FROM_GIT_PATH}" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}")
endif ()
FetchContent_Declare(
pico_sdk
GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
GIT_TAG master
)
if (NOT pico_sdk)
message("Downloading Raspberry Pi Pico SDK")
FetchContent_Populate(pico_sdk)
set(PICO_SDK_PATH ${pico_sdk_SOURCE_DIR})
endif ()
set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE})
else ()
message(FATAL_ERROR
"SDK location was not specified. Please set PICO_SDK_PATH or set PICO_SDK_FETCH_FROM_GIT to on to fetch from git."
)
endif ()
endif ()
get_filename_component(PICO_SDK_PATH "${PICO_SDK_PATH}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}")
if (NOT EXISTS ${PICO_SDK_PATH})
message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' not found")
endif ()
set(PICO_SDK_INIT_CMAKE_FILE ${PICO_SDK_PATH}/pico_sdk_init.cmake)
if (NOT EXISTS ${PICO_SDK_INIT_CMAKE_FILE})
message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' does not appear to contain the Raspberry Pi Pico SDK")
endif ()
set(PICO_SDK_PATH ${PICO_SDK_PATH} CACHE PATH "Path to the Raspberry Pi Pico SDK" FORCE)
include(${PICO_SDK_INIT_CMAKE_FILE})
File added
%% Cell type:code id: tags:
``` python
import numpy as np;
```
%% Cell type:code id: tags:
``` python
S="0x0000, 0xc0c1, 0xc181, 0x0140, 0xc301, 0x03c0, 0x0280, 0xc241,\
0xc601, 0x06c0, 0x0780, 0xc741, 0x0500, 0xc5c1, 0xc481, 0x0440,\
0xcc01, 0x0cc0, 0x0d80, 0xcd41, 0x0f00, 0xcfc1, 0xce81, 0x0e40,\
0x0a00, 0xcac1, 0xcb81, 0x0b40, 0xc901, 0x09c0, 0x0880, 0xc841,\
0xd801, 0x18c0, 0x1980, 0xd941, 0x1b00, 0xdbc1, 0xda81, 0x1a40,\
0x1e00, 0xdec1, 0xdf81, 0x1f40, 0xdd01, 0x1dc0, 0x1c80, 0xdc41,\
0x1400, 0xd4c1, 0xd581, 0x1540, 0xd701, 0x17c0, 0x1680, 0xd641,\
0xd201, 0x12c0, 0x1380, 0xd341, 0x1100, 0xd1c1, 0xd081, 0x1040,\
0xf001, 0x30c0, 0x3180, 0xf141, 0x3300, 0xf3c1, 0xf281, 0x3240,\
0x3600, 0xf6c1, 0xf781, 0x3740, 0xf501, 0x35c0, 0x3480, 0xf441,\
0x3c00, 0xfcc1, 0xfd81, 0x3d40, 0xff01, 0x3fc0, 0x3e80, 0xfe41,\
0xfa01, 0x3ac0, 0x3b80, 0xfb41, 0x3900, 0xf9c1, 0xf881, 0x3840,\
0x2800, 0xe8c1, 0xe981, 0x2940, 0xeb01, 0x2bc0, 0x2a80, 0xea41,\
0xee01, 0x2ec0, 0x2f80, 0xef41, 0x2d00, 0xedc1, 0xec81, 0x2c40,\
0xe401, 0x24c0, 0x2580, 0xe541, 0x2700, 0xe7c1, 0xe681, 0x2640,\
0x2200, 0xe2c1, 0xe381, 0x2340, 0xe101, 0x21c0, 0x2080, 0xe041,\
0xa001, 0x60c0, 0x6180, 0xa141, 0x6300, 0xa3c1, 0xa281, 0x6240,\
0x6600, 0xa6c1, 0xa781, 0x6740, 0xa501, 0x65c0, 0x6480, 0xa441,\
0x6c00, 0xacc1, 0xad81, 0x6d40, 0xaf01, 0x6fc0, 0x6e80, 0xae41,\
0xaa01, 0x6ac0, 0x6b80, 0xab41, 0x6900, 0xa9c1, 0xa881, 0x6840,\
0x7800, 0xb8c1, 0xb981, 0x7940, 0xbb01, 0x7bc0, 0x7a80, 0xba41,\
0xbe01, 0x7ec0, 0x7f80, 0xbf41, 0x7d00, 0xbdc1, 0xbc81, 0x7c40,\
0xb401, 0x74c0, 0x7580, 0xb541, 0x7700, 0xb7c1, 0xb681, 0x7640,\
0x7200, 0xb2c1, 0xb381, 0x7340, 0xb101, 0x71c0, 0x7080, 0xb041,\
0x5000, 0x90c1, 0x9181, 0x5140, 0x9301, 0x53c0, 0x5280, 0x9241,\
0x9601, 0x56c0, 0x5780, 0x9741, 0x5500, 0x95c1, 0x9481, 0x5440,\
0x9c01, 0x5cc0, 0x5d80, 0x9d41, 0x5f00, 0x9fc1, 0x9e81, 0x5e40,\
0x5a00, 0x9ac1, 0x9b81, 0x5b40, 0x9901, 0x59c0, 0x5880, 0x9841,\
0x8801, 0x48c0, 0x4980, 0x8941, 0x4b00, 0x8bc1, 0x8a81, 0x4a40,\
0x4e00, 0x8ec1, 0x8f81, 0x4f40, 0x8d01, 0x4dc0, 0x4c80, 0x8c41,\
0x4400, 0x84c1, 0x8581, 0x4540, 0x8701, 0x47c0, 0x4680, 0x8641,\
0x8201, 0x42c0, 0x4380, 0x8341, 0x4100, 0x81c1, 0x8081, 0x4040"
```
%% Cell type:code id: tags:
``` python
D=np.array([int(d,16) for d in S.split(',')],dtype='int')
print([hex(d) for d in D[:10]])
```
%% Output
['0x0', '0xc0c1', '0xc181', '0x140', '0xc301', '0x3c0', '0x280', '0xc241', '0xc601', '0x6c0']
%% Cell type:code id: tags:
``` python
#Parity = count the number of 1s, see if it is even
P=[bin(d)[2:].count('1')%2 for d in range(256)]
print(P[:32])
```
%% Output
[0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1]
%% Cell type:code id: tags:
``` python
#First/5th bit = even/odd
B1=np.array([d%2 for d in range(256)])
B2=np.array([(d//16)%2 for d in range(256)])
B1=B1^B2
print(B1[:32])
```
%% Output
[0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0]
%% Cell type:code id: tags:
``` python
#Correction: Difference between first bit and parity
C=(P+B1)%2
print(C[:32])
```
%% Output
[0 0 1 1 1 1 0 0 1 1 0 0 0 0 1 1 0 0 1 1 1 1 0 0 1 1 0 0 0 0 1 1]
%% Cell type:code id: tags:
``` python
D2=D ^ C*0xc001
print([hex(d) for d in D2[:10]])
```
%% Output
['0x0', '0xc0c1', '0x180', '0xc141', '0x300', '0xc3c1', '0x280', '0xc241', '0x600', '0xc6c1']
%% Cell type:code id: tags:
``` python
S2=''
for i in range(256):
S2+=hex(D2[i]);
if i%8<7:
S2+=", "
else:
S2+=",\n"
print(S2)
```
%% Output
0x0, 0xc0c1, 0x180, 0xc141, 0x300, 0xc3c1, 0x280, 0xc241,
0x600, 0xc6c1, 0x780, 0xc741, 0x500, 0xc5c1, 0x480, 0xc441,
0xcc01, 0xcc0, 0xcd81, 0xd40, 0xcf01, 0xfc0, 0xce81, 0xe40,
0xca01, 0xac0, 0xcb81, 0xb40, 0xc901, 0x9c0, 0xc881, 0x840,
0x1800, 0xd8c1, 0x1980, 0xd941, 0x1b00, 0xdbc1, 0x1a80, 0xda41,
0x1e00, 0xdec1, 0x1f80, 0xdf41, 0x1d00, 0xddc1, 0x1c80, 0xdc41,
0xd401, 0x14c0, 0xd581, 0x1540, 0xd701, 0x17c0, 0xd681, 0x1640,
0xd201, 0x12c0, 0xd381, 0x1340, 0xd101, 0x11c0, 0xd081, 0x1040,
0x3000, 0xf0c1, 0x3180, 0xf141, 0x3300, 0xf3c1, 0x3280, 0xf241,
0x3600, 0xf6c1, 0x3780, 0xf741, 0x3500, 0xf5c1, 0x3480, 0xf441,
0xfc01, 0x3cc0, 0xfd81, 0x3d40, 0xff01, 0x3fc0, 0xfe81, 0x3e40,
0xfa01, 0x3ac0, 0xfb81, 0x3b40, 0xf901, 0x39c0, 0xf881, 0x3840,
0x2800, 0xe8c1, 0x2980, 0xe941, 0x2b00, 0xebc1, 0x2a80, 0xea41,
0x2e00, 0xeec1, 0x2f80, 0xef41, 0x2d00, 0xedc1, 0x2c80, 0xec41,
0xe401, 0x24c0, 0xe581, 0x2540, 0xe701, 0x27c0, 0xe681, 0x2640,
0xe201, 0x22c0, 0xe381, 0x2340, 0xe101, 0x21c0, 0xe081, 0x2040,
0x6000, 0xa0c1, 0x6180, 0xa141, 0x6300, 0xa3c1, 0x6280, 0xa241,
0x6600, 0xa6c1, 0x6780, 0xa741, 0x6500, 0xa5c1, 0x6480, 0xa441,
0xac01, 0x6cc0, 0xad81, 0x6d40, 0xaf01, 0x6fc0, 0xae81, 0x6e40,
0xaa01, 0x6ac0, 0xab81, 0x6b40, 0xa901, 0x69c0, 0xa881, 0x6840,
0x7800, 0xb8c1, 0x7980, 0xb941, 0x7b00, 0xbbc1, 0x7a80, 0xba41,
0x7e00, 0xbec1, 0x7f80, 0xbf41, 0x7d00, 0xbdc1, 0x7c80, 0xbc41,
0xb401, 0x74c0, 0xb581, 0x7540, 0xb701, 0x77c0, 0xb681, 0x7640,
0xb201, 0x72c0, 0xb381, 0x7340, 0xb101, 0x71c0, 0xb081, 0x7040,
0x5000, 0x90c1, 0x5180, 0x9141, 0x5300, 0x93c1, 0x5280, 0x9241,
0x5600, 0x96c1, 0x5780, 0x9741, 0x5500, 0x95c1, 0x5480, 0x9441,
0x9c01, 0x5cc0, 0x9d81, 0x5d40, 0x9f01, 0x5fc0, 0x9e81, 0x5e40,
0x9a01, 0x5ac0, 0x9b81, 0x5b40, 0x9901, 0x59c0, 0x9881, 0x5840,
0x4800, 0x88c1, 0x4980, 0x8941, 0x4b00, 0x8bc1, 0x4a80, 0x8a41,
0x4e00, 0x8ec1, 0x4f80, 0x8f41, 0x4d00, 0x8dc1, 0x4c80, 0x8c41,
0x8401, 0x44c0, 0x8581, 0x4540, 0x8701, 0x47c0, 0x8681, 0x4640,
0x8201, 0x42c0, 0x8381, 0x4340, 0x8101, 0x41c0, 0x8081, 0x4040,
%% Cell type:code id: tags:
``` python
```
import numpy as np
def GetDelay(ser,Start=0x1000):
a=0;
D=[]
Start=0x1000
while a!=b'':
a=ser.readline()[:8]
# print(a)
if a==b'': break;
a=str(a,'UTF-8')
a=Start-int(a,16)
# print(a)
if (a==0): break;
D.append(a)
return D;
def NormDelays(D,offset=19,scale=20):
return [(d+offset)//scale for d in D] #shorter (inbetween) delay = waiting for FIFO
def Decode(D2):
previous="0";
res=''
for b in D2[:]:
if b>=6: #Start a new packet
#n=(8-len(res)%8)%8
n=(len(res)//8)*8
#res+=n*"0"
res=res[:n]
previous="0"
# print(n,res,previous)
else:
if previous=="0":
bit="0" if b<=2 else "01"
else:
if b==2: bit="1"
elif b==3: bit="0"
else: bit="01"
# print(previous,b,bit)
previous=bit[-1];
res+=bit;
#print(res)
res=res[2:]
# print("len",len(res)//8)
S=[]
for x in range(len(res)//8):
v1=int(res[x*8:x*8+8],2)
# print(x,res[x*8:x*8+8],v1)
S.append(v1)
return(S)
CRCtab=np.load("CRC_HBAT1.npy")
CRCtabl=[d%256 for d in CRCtab]
CRCtabh=[d//256 for d in CRCtab]
def CRCcheck(S1):
crcl=0;crch=0;
for b in S1:
i=crcl ^ b
crcl=crch ^ CRCtabl[i]
crch=CRCtabh[i]
# print(i,CRCtabh[i])
# crch=crcl ^ CRCtabh[i]
# crcl= CRCtabl[i]
return crch*256+crcl
def MakeBroadcast(data,func=4,reg=0,serv1=1,serv2=16):
assert(len(data)==32)
data2=[func,reg,serv1,serv2]+data
l=len(data2)+1
data2=[0,l]+data2
CRC=CRCcheck(data2)
data2=data2+[CRC%256,CRC//256]
assert(CRCcheck(data2)==0)
return data2
def MakeRequest(serv,data=[],func=5,reg=0):
data2=[func,reg]+data
l=len(data2)+1
data2=[serv,l]+data2
CRC=CRCcheck(data2)
data2=data2+[CRC%256,CRC//256]
assert(CRCcheck(data2)==0)
return data2
#Mlookup=[0x55,0x56,0x59,0x5A,0x65,0x66,0x69,0x6A,0x95,0x96,0x99,0x9A,0xA5,0xA6,0xA9,0xAA]
Mlookup=[0xAA,0x6A,0x9A,0x5A,0xA6,0x66,0x96,0x56,0xA9,0x69,0x99,0x59,0xA5,0x65,0x95,0x55]
def ManchesterEncode(data):
# Inverted: 0=input=high, 1=output=low. Applied at end.
# Data clocked out MSB first, send on wire LSB first!
data2=[0xff,0x0f,0xa8] #------------_______-_- Start sequence
for d in data:
data2+=[Mlookup[d//16]]
data2+=[Mlookup[d%16]]
data2+=[0xfd]
return [255-d for d in data2]
def Loopback(TX2):
#Calculte time between edges
S=''
for b in TX2:
S+="{0:08b}".format(255-b)[::-1]
print("Loopback bits:",S[:30])
T=[0]
for i in range(len(S)-1):
if (S[i]=='1') and (S[i+1]=="0"): T+=[i]
T=np.array(T[1:])
T=T[1:]-T[:-1]
print("Loopback delay:",T[:30])
return T
\ No newline at end of file
sudo minicom -b 115200 -o -D /dev/ttyACM0
This diff is collapsed.
This diff is collapsed.
test.c 0 → 100644
#include <stdio.h>
#include "pico/stdlib.h"
#include "hardware/gpio.h"
#include "pico/binary_info.h"
#include "pico/multicore.h"
#include "hardware/pio.h"
#include "hba_tx.pio.h"
#include "hba_rx.pio.h"
const uint TX_PIN = 14; //25=LED to test
const uint RX_PIN = 14;
#define BUFFERSIZE 512
char buffer1[BUFFERSIZE];
uint16_t buffer2[BUFFERSIZE];
int bcnt1=0,bcnt2=0;
int bcnt3=0,bcnt4=0;
void core1_entry() {
while (1) {
if (bcnt3!=bcnt4) {
printf("%08x\n", buffer2[bcnt4]);
bcnt4++;bcnt4%=BUFFERSIZE;
}
else {
int x = getchar_timeout_us(0);
if (x!=PICO_ERROR_TIMEOUT){
buffer1[bcnt1]=x;
bcnt1++;bcnt1%=BUFFERSIZE;
}
}
}};
int main() {
// bi_decl(bi_program_description("This is a test binary."));
// bi_decl(bi_1pin_with_name(LED_PIN, "On-board LED"));
stdio_init_all();
PIO pio_rx = pio1;
uint offset1 = pio_add_program(pio_rx, &hba_rx_program);
uint sm1 = pio_claim_unused_sm(pio_rx, true);
hba_rx_program_init(pio_rx, sm1, offset1, RX_PIN);
PIO pio_tx = pio0;
uint offset = pio_add_program(pio_tx, &hba_tx_program);
uint sm = pio_claim_unused_sm(pio_tx, true);
hba_tx_program_init(pio_tx, sm, offset, TX_PIN);
// gpio_init(LED_PIN);
// gpio_set_dir(LED_PIN, GPIO_OUT);
gpio_set_pulls(TX_PIN,true,false);
// gpio_set_pulls(RX_PIN,true,false);
pio_sm_put_blocking(pio_tx, sm , 12500); //Bitrate = 150e6 / val. e.g. 15k = 10kHz
pio_sm_put_blocking(pio_rx, sm1, 0x1000); //Timeout
pio_sm_put_blocking(pio_tx, sm, 0x00);
multicore_launch_core1(core1_entry);
while (1) {
// gpio_put(LED_PIN, 0);
// printf("TX:%08x\n",pio_sm_get_tx_fifo_level(pio_tx, sm));
// printf("%32x\n", pio_sm_get_blocking(pio_rx, sm1));
if (pio_sm_get_rx_fifo_level(pio_rx, sm1)>0) { //First priority: Keep RX FIFO empty
buffer2[bcnt3]=(uint16_t)(pio_sm_get_blocking(pio_rx, sm1));
bcnt3++;bcnt3%=BUFFERSIZE;
} else if ((pio_sm_get_tx_fifo_level(pio_tx, sm)<4) && (bcnt1!=bcnt2)) { //Second priority: Keep TX FIFO full
// printf("TX%x\n",buffer1[bcnt2]);
pio_sm_put_blocking(pio_tx, sm, buffer1[bcnt2]);
bcnt2++;bcnt2%=BUFFERSIZE;
};
/* else if (bcnt3!=bcnt4) {
printf("%08x\n", buffer2[bcnt4]);
bcnt4++;bcnt4%=BUFFERSIZE;
}
else {
int x = getchar_timeout_us(0);
if (x!=PICO_ERROR_TIMEOUT){
buffer1[bcnt1]=x;
bcnt1++;bcnt1%=BUFFERSIZE;
}
}
*/
// sleep_ms(250);
// pio_sm_put_blocking(pio, sm, 0);
// gpio_put(LED_PIN, 1);
// puts("Hello World\n");
// sleep_ms(1000);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment