Files
RP2040-Decoder/shared.h
T
1nct fd017ea685 - added shared.c file containing functions that can be accessed from both cores
- revised CV programming especially writing
- Core 1 is only started when valid package with correct address is received
- Extended addresses are now correctly verified and implemented
- Base PWM measurement is now done on core0 and checked for automatically in cv_setup_check()
- Moved Motor PWM, GPIO, ADC to core0
- Implemented inverted direction mode (CV_29) according to DCC-Standards
- Limited feed-forward parameters y_2 to max_output/y_1
- k_p gain slopes are now calculated on initialization
- k_p gain parameters are also in pid parameter struct now
- Revised init_pid()
- Implemented Packet timeout check (CV_11)
- 16Bit and 32Bit CVs now always have the highest bytes as the lowest array index to accommodate get_XXbit_CV() functions
2022-08-01 17:20:05 +02:00

45 lines
1.8 KiB
C

//////////////////////////
// RP2040-Decoder //
// Gabriel Koppenstein //
// shared.h //
//////////////////////////
#pragma once
#include "string.h"
#include "pico/float.h"
#include "pico/stdlib.h"
#include "pico/multicore.h"
#include "pico/printf.h"
#include "hardware/pwm.h"
#include "hardware/adc.h"
#include "hardware/flash.h"
#include "hardware/irq.h"
#define _125M 125000000
#define DCC_INPUT_PIN 21u
#define MOTOR_FWD_PIN 23u
#define MOTOR_REV_PIN 22u
#define FWD_V_EMF_ADC_PIN 28u
#define REV_V_EMF_ADC_PIN 29u
//Aux output pins (GPIO 24,25,26,27)
#define AUX_PIN_MASK (1u<<24) | (1u<<25) | (1u<<26) | (1u<<27)
//GPIO pins configured as inputs (Input functionality not implemented yet)
#define GPIO_INPUT_MASK 0b00000000000000000000000000000000
//GPIO pins configured as outputs
#define GPIO_OUTPUT_MASK 0b00000000000000000000000000000000
//GPIO pin mask to prevent setting illegal GPIOs (ADC, Motor, DCC Input Pin)
#define GPIO_ILLEGAL_MASK (1u<<DCC_INPUT_PIN) | (1u<<MOTOR_FWD_PIN) | (1u<<MOTOR_REV_PIN) | (1u<<FWD_V_EMF_ADC_PIN) | (1u<<REV_V_EMF_ADC_PIN)
//GPIO pin mask with allowed outputs (AUX & GPIO (configured as outputs))
#define GPIO_ALLOWED_OUTPUTS (GPIO_OUTPUT_MASK|AUX_PIN_MASK) & ~(GPIO_ILLEGAL_MASK)
#define FLASH_TARGET_OFFSET (PICO_FLASH_SIZE_BYTES-FLASH_SECTOR_SIZE) //This Offset should be far enough away from program data
extern repeating_timer_t pid_control_timer;
extern repeating_timer_t speed_helper_timer;
extern const uint8_t *CV_ARRAY_FLASH;
void core1_entry();
float measure(uint8_t total_iterations,
uint8_t measurement_delay_us,
uint8_t l_side_arr_cutoff,
uint8_t r_side_arr_cutoff,
bool direction);
uint32_t get_32bit_CV (uint16_t CV_start_index);
uint16_t get_16bit_CV (uint16_t CV_start_index);