basispaket erkennen
This commit is contained in:
commit
d116e0a2ac
6 files changed
+2051
No files matched your search
@@ -0,0 +1,3 @@
|
||||
.idea
|
||||
cmake-build-debug
|
||||
cmake-build-release
|
||||
@@ -0,0 +1,35 @@
|
||||
cmake_minimum_required(VERSION 3.12)
|
||||
|
||||
# Pull in SDK (must be before project)
|
||||
include(pico_sdk_import.cmake)
|
||||
|
||||
project(pico_decoder C CXX ASM)
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
set(PICO_DECODER_PATH ${PROJECT_SOURCE_DIR})
|
||||
|
||||
# Initialize the SDK
|
||||
pico_sdk_init()
|
||||
|
||||
add_compile_options(-Wall
|
||||
-Wno-format # int != int32_t as far as the compiler is concerned because gcc has int32_t as long int
|
||||
-Wno-unused-function # we have some for the docs that aren't called
|
||||
-Wno-maybe-uninitialized
|
||||
)
|
||||
|
||||
add_executable(hello_multicore
|
||||
multicore.c
|
||||
automat.c)
|
||||
|
||||
# Add pico_multicore which is required for multicore functionality
|
||||
target_link_libraries(hello_multicore
|
||||
pico_stdlib
|
||||
pico_multicore)
|
||||
|
||||
# enable usb output, disable uart output
|
||||
pico_enable_stdio_usb(hello_multicore 1)
|
||||
pico_enable_stdio_uart(hello_multicore 0)
|
||||
|
||||
# create map/bin/hex file etc.
|
||||
pico_add_extra_outputs(hello_multicore)
|
||||
@@ -0,0 +1,8 @@
|
||||
//
|
||||
// Created by r3d on 8/22/21.
|
||||
//
|
||||
|
||||
#ifndef PICO_EXAMPLES_AUTOMAT_H
|
||||
#define PICO_EXAMPLES_AUTOMAT_H
|
||||
int fsm_main(const char *s);
|
||||
#endif //PICO_EXAMPLES_AUTOMAT_H
|
||||
+139
@@ -0,0 +1,139 @@
|
||||
/**
|
||||
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <inttypes.h>
|
||||
#include "pico/stdlib.h"
|
||||
#include "pico/multicore.h"
|
||||
#include "hardware/gpio.h"
|
||||
#include "automat.h"
|
||||
|
||||
bool readBit()
|
||||
{
|
||||
busy_wait_us_32(87);
|
||||
return !gpio_get(17);
|
||||
}
|
||||
|
||||
void printer(char buf[100]){
|
||||
while (*buf) {
|
||||
multicore_fifo_push_blocking(*buf);
|
||||
buf++;
|
||||
}
|
||||
}
|
||||
uint32_t errorcount = 0;
|
||||
|
||||
#define FLAG_VALUE 123
|
||||
|
||||
void pretty_print(char* s){
|
||||
char addresse[9];
|
||||
s+=11;
|
||||
for (int i = 0; i < 8 ; i++) {
|
||||
addresse[i] = *(s+i);
|
||||
}
|
||||
addresse[8] =0;
|
||||
s+=9;
|
||||
|
||||
char befehl[9];
|
||||
for (int i = 0; i < 8 ; i++) {
|
||||
befehl[i] = *(s+i);
|
||||
}
|
||||
befehl[8] =0;
|
||||
s+=9;
|
||||
char pruef[9];
|
||||
for (int i = 0; i < 8 ; i++) {
|
||||
pruef[i] = *(s+i);
|
||||
}
|
||||
s+=8;
|
||||
pruef[8] =0;
|
||||
static int32_t counter = 1;
|
||||
printf("%d address: %s befehl: %s pruef: %s %c\n", counter++, addresse, befehl, pruef, *s);
|
||||
}
|
||||
|
||||
void core1_entry() {
|
||||
multicore_fifo_push_blocking(FLAG_VALUE);
|
||||
|
||||
int index = 0;
|
||||
char buf[100] = {0};
|
||||
while (1) {
|
||||
buf[index] = multicore_fifo_pop_blocking();
|
||||
if (buf[index] == '\n' || index == 99) {
|
||||
pretty_print(buf);
|
||||
for(int i =0 ; i < 100; i++) {
|
||||
buf[i] = 0;
|
||||
}
|
||||
index = -1;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
const int SIZE = 10 + 1 + 13 * 9 + 1 + 1;
|
||||
|
||||
#define LEFTESTBIT 0x8000000000000000
|
||||
char* genCharArray(uint64_t last_read_bits, uint64_t mask);
|
||||
|
||||
void gpio_callback_rise(uint gpio, uint32_t events) {
|
||||
static uint64_t last_read_Bits;
|
||||
static uint64_t mask = LEFTESTBIT;
|
||||
bool last_read_bit = readBit();
|
||||
|
||||
if (last_read_bit) {
|
||||
last_read_Bits = last_read_Bits | mask;
|
||||
} else {
|
||||
last_read_Bits = last_read_Bits & ~mask;
|
||||
}
|
||||
if ( mask == 1) {
|
||||
mask = LEFTESTBIT;
|
||||
} else {
|
||||
mask >>= 1;
|
||||
}
|
||||
char * s = genCharArray(last_read_Bits, mask);
|
||||
if (fsm_main(s) == 1) {
|
||||
s[SIZE-2 ] ='\n';
|
||||
s[SIZE-1 ] =0;
|
||||
printer(s);
|
||||
}
|
||||
free(s);
|
||||
}
|
||||
|
||||
char* genCharArray(uint64_t last_read_bits, uint64_t mask) {
|
||||
char *s = malloc(SIZE);
|
||||
|
||||
for ( int i = SIZE-3; i >= 0 ; i-- ) {
|
||||
if ( mask == LEFTESTBIT ){
|
||||
mask = 1;
|
||||
} else {
|
||||
mask <<= 1;
|
||||
}
|
||||
s[i] = last_read_bits & mask ? '1': '0';
|
||||
}
|
||||
s[SIZE-2 ] =0;
|
||||
return s;
|
||||
}
|
||||
|
||||
int main() {
|
||||
stdio_init_all();
|
||||
multicore_launch_core1(core1_entry);
|
||||
// Wait for it to start up
|
||||
uint32_t g = multicore_fifo_pop_blocking();
|
||||
|
||||
if (g != FLAG_VALUE)
|
||||
printf("Hmm, that's not right on core 0!\n");
|
||||
else {
|
||||
printf("It's all gone well on core 0!");
|
||||
}
|
||||
|
||||
gpio_init(17);
|
||||
gpio_set_dir(17, GPIO_IN);
|
||||
gpio_set_irq_enabled_with_callback(17, GPIO_IRQ_EDGE_RISE, true, &gpio_callback_rise);
|
||||
|
||||
while(1) {
|
||||
;
|
||||
}
|
||||
/// \end::setup_multicore[]
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
# 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})
|
||||
Reference in new issue
Block a user