Commit a535ce3f authored by Stefan's avatar Stefan
Browse files

cleanup repo

parent 721f4c59
Project(HalloWelt)
cmake_minimum_required(VERSION 2.8)
#include CMAKE-Modules from base directory
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}")
INCLUDE(EZS)
add_definitions("-D EZS_DUMB_SERIAL -D DAC")
include_directories(${PROJECT_SOURCE_DIR}/libDIY/drivers/include)
include_directories(${PROJECT_SOURCE_DIR}/libDIY/include)
set(LIBEZS_SOURCES
# libEZS/src/ezs_tracer.cpp
libEZS/drivers/${EZS_ARCH}/ezs_gpio.c
libEZS/drivers/${EZS_ARCH}/ezs_dac.cpp
# libEZS/drivers/${EZS_ARCH}/ezs_serial.cpp
libEZS/drivers/${EZS_ARCH}/ezs_counter.cpp
libEZS/src/ezs_delay.c
)
set(LIBDIY_SOURCES
libDIY/drivers/src/diy_adc.c
libDIY/drivers/src/diy_gpio.c
libDIY/drivers/src/diy_tim.c
)
SET(SRC_LIST
hello.c
${LIBEZS_SOURCES}
${LIBDIY_SOURCES}
)
set(TGT "app")
ECOS_ADD_EXECUTABLE(${TGT} ${SRC_LIST})
This diff is collapsed.
if(POLICY CMP0037)
cmake_policy(SET CMP0037 OLD)
endif()
# first check that ecosconfig is available
FIND_PROGRAM(ECOSCONFIG_EXECUTABLE NAMES ecosconfig)
IF("$ENV{EZS_BASE}" STREQUAL "")
MESSAGE(FATAL_ERROR "EZS_BASE not set. Did you run 'source ../ecosenv.sh'?")
ELSE()
message(STATUS "EZS_BASE: $ENV{EZS_BASE}")
IF(NOT IS_DIRECTORY "$ENV{EZS_BASE}")
MESSAGE(FATAL_ERROR "EZS_BASE set but not a directory. Check your settings in ../ecosenv.sh and your installation'?")
ENDIF()
IF(NOT IS_DIRECTORY "$ENV{EZS_CMAKE_MODULE_DIR}")
MESSAGE(FATAL_ERROR "EZS_CMAKE_MODULE_DIR is not a directory. Check your settings in ../ecosenv.sh and your installation'?")
ENDIF()
MESSAGE(STATUS "USING $ENV{EZS_BASE}")
MESSAGE(STATUS "USING $ENV{EZS_CMAKE_MODULE_DIR} as cmake module path")
set(CMAKE_MODULE_PATH "$ENV{EZS_CMAKE_MODULE_DIR}" ${CMAKE_MODULE_PATH})
set(EZS_TOOLS_DIR "$ENV{EZS_CMAKE_MODULE_DIR}")
MESSAGE(STATUS "USING ${EZS_TOOLS_DIR} as tools path")
ENDIF("$ENV{EZS_BASE}" STREQUAL "")
IF(NOT ECOSCONFIG_EXECUTABLE)
MESSAGE(FATAL_ERROR "ecosconfig was not found. Do you have a valid ecos repository?")
ENDIF(NOT ECOSCONFIG_EXECUTABLE)
IF("$ENV{EZS_LIBOPENCM3_DIR}" STREQUAL "")
MESSAGE(WARNING "OPENCM3_PATH not set. Did you run 'source ../ecosenv.sh'")
ELSE()
set(OPENCM3_PATH $ENV{EZS_LIBOPENCM3_DIR})
ENDIF()
set(EZS_CPU_FLAGS "-mcpu=cortex-m3 -mthumb")
add_definitions( "-D STM32F4")
INCLUDE(EZSconvenience)
INCLUDE(ezs_ecos_stm32)
set(EZS_ARCH stm32f4)
include_directories(${OPENCM3_PATH}/include)
ECOS_EZS_ADDLIB("${OPENCM3_PATH}/lib/libopencm3_stm32f4.a")
include_directories(${PROJECT_SOURCE_DIR}/libEZS/include)
FIND_PROGRAM(MELD_EXECUTABLE NAMES meld)
IF(MELD_EXECUTABLE)
add_custom_target(diff
COMMAND ${MELD_EXECUTABLE} "/proj/i4ezs/vorgaben/${CMAKE_PROJECT_NAME}/" "${PROJECT_SOURCE_DIR}"
COMMENT "Invoking diff")
ENDIF()
This diff is collapsed.
#!/usr/bin/env bash
I4EZS_USER_CONFIG="${HOME}/.config/i4ezs/i4ezs-ecosenv-stm32.sh"
# allow user override
if [[ -f "$I4EZS_USER_CONFIG" ]]; then
source "$I4EZS_USER_CONFIG"
elif [ -e ~/i4ezs-ecosenv-stm32.sh ]; then
echo "WARNING: Found old i4ezs config file at ~/i4ezs-ecosenv-stm32.sh. Please migrate to $I4EZS_USER_CONFIG."
source ~/i4ezs-ecosenv-stm32.sh
else
EZS_BASE=/proj/i4ezs/stm32/
fi
# Ensure that EZS_BASE is exported.
export EZS_BASE
#################### NO CHANGES BELOW SHOULD BE NEEDED ####################
EZS_UID=$$ ; export EZS_UID
EZS_COMPILER_DIR=$EZS_BASE/gcc-arm-none-eabi ; export EZS_COMPILER_DIR
EZS_TOOLS_DIR=$EZS_BASE/tools; export EZS_TOOLS_DIR
EZS_CMAKE_MODULE_DIR=$EZS_BASE/tools ; export EZS_CMAKE_MODULE_DIR
EZS_LIBOPENCM3_DIR=$EZS_BASE/libopencm3 ; export EZS_LIBOPENCM3_DIR
ECOS_BASE_DIR=$EZS_BASE/ecos
ECOS_REPOSITORY=$ECOS_BASE_DIR/packages ; export ECOS_REPOSITORY
PATH=$EZS_TOOLS_DIR:$EZS_COMPILER_DIR/bin:$PATH; export PATH
#include <cyg/hal/hal_arch.h>
#include <cyg/kernel/kapi.h>
#include <cyg/infra/diag.h>
/*#include <libopencm3/stm32/f4/gpio.h>*/
#include <libopencm3/stm32/gpio.h>
#include <libopencm3/stm32/rcc.h>
#include <libopencm3/stm32/adc.h>
#include <stdint.h>
#include <stdio.h>
#include <math.h>
#include <iso646.h>
#include "ezs_dac.h"
#include "ezs_adc.h"
#include "ezs_gpio.h"
#include "ezs_io.h"
#include "ezs_delay.h"
#include "ezs_counter.h"
// libLessPain includes
// #include "ADC.h"
// libDIY includes
#include "diy_gpio.h"
#include "diy_adc.h"
#include "diy_tim.h"
#define F_ABTAST 100 //Hz
#define STACKSIZE (CYGNUM_HAL_STACK_SIZE_MINIMUM+1024)
static cyg_handle_t test_handle;
static cyg_thread testfaden;
static cyg_uint8 test_stack[STACKSIZE];
static cyg_alarm test_alarm;
static cyg_handle_t test_alarm_handle;
static cyg_handle_t counter;
static cyg_tick_count_t ms_to_cyg_ticks(cyg_uint32 ms){
cyg_resolution_t resolution = cyg_clock_get_resolution(cyg_real_time_clock());
const cyg_uint64 delay_ns = ms * 1000000;
const cyg_tick_count_t delay = (delay_ns * resolution.divisor)/resolution.dividend; //ticks
return delay;
}
static void test_alarm_fn(cyg_handle_t alarmH, cyg_addrword_t data)
{
cyg_thread_resume(test_handle);
}
void test_thread(cyg_addrword_t arg)
{
cyg_uint32 i = 0;
cyg_uint8 frequence = 10; //signal in hz
cyg_uint8 amplitude = 1; // ]0 - 1,65V]
float_t max = 1.65V;
float_t factor = 255*amplitude/max;
while(1){
//ezs_printf("Hallo Welt! %d \n",i++);
//calculate current signal value
float_t sig_value_a = sinf((i*M_PI*2.0)/(F_ABTAST/frequence));
//transform from ana [-amp, amp] to dig [0,255]
cyg_uint8 sig_value_d = ((sig_value_a + 1)*factor)/2;
ezs_dac_write(sig_value_d);
i++;
cyg_thread_suspend(cyg_thread_slef());
}
}
void cyg_user_start(void)
{
ezs_counter_init();
ezs_gpio_init();
ezs_dac_init();
cyg_clock_to_counter(cyg_real_time_clock(),&counter);
cyg_thread_create(10,&test_thread,0,"testthread",test_stack,STACKSIZE,&test_handle,&testfaden);
//alarm
cyg_alarm_create(counter,test_alarm_fn,0,&test_alarm_handle,&test_alarm);
cyg_alarm_initialize(test_alarm_handle,cyg_current_time(),ms_to_cyg_ticks(1000/F_ABTAST));
/* Thread starten */
//cyg_thread_resume(test_handle);
}
#ifndef DIY_ADC_H_INCLUDED
#define DIY_ADC_H_INCLUDED
/* When using with the STM32F411E-DISCO the pins/channels:
* PA0/0
* PA4/4
* PA5/5
* PA6/6
* PA7/7
* PC0/11
* PC3/13
* PC4/14
* may already be used or are not available due to other peripherals.
* Pins/channels:
* PA1/1
* PA2/2
* PA3/3
* PB0/8
* PB1/9
* PC1/11
* PC2/12
* PC5/15
* should be available.
* Channel 16 and 17 are internal channels. Channel 18 is only for V_Bat.
*/
typedef struct {
uint32_t adc;
uint8_t sample_time;
uint32_t prescaler;
// TODO: Set Mode?
} diy_adc_config_t;
/* \brief Initialize the on-board ADC.
* \param adc_config Struct containing the configuration of the ADC register
* \param channels Channel to be configured
* \param len_channels Number of channels in channels
*/
void diy_adc_init(diy_adc_config_t* adc_config, uint8_t channels[], uint8_t len_channels);
/* \brief Reads the current ADC value from the channels.
* \param adc ADC peripheral
* \param channels Channels that should be read
* \param sample_val Array where the adc values are stored
* \param len_channels Number of channels to be read, sample_val and channels should be of same size
*/
void diy_adc_read(uint32_t adc, uint8_t channels[], uint16_t sample_val[], uint8_t len_channels);
#endif // DIY_ADC_H_INCLUDED
#ifndef DIY_GPIO_H_INCLUDED
#define DIY_GPIO_H_INCLUDED
#include <stdint.h>
typedef struct {
uint32_t port;
uint8_t mode;
uint8_t type;
uint8_t speed;
uint8_t pull_up_down;
uint8_t alt_func;
} diy_gpio_config_t;
/* \brief Initialize the pins on one port with the same configuration
* \param gpio_config Struct containing the port register configuration
* \param pins Bitmask of the pins
*/
void diy_gpio_init(diy_gpio_config_t* gpio_config, uint16_t pins);
/* \brief Sets pins to high logic level
* \param port Port with the pins
* \param pin Bitmask of the pins
*/
void diy_gpio_set_pins(uint32_t port, uint16_t pin);
/* \brief Sets pins to low logic level
* \param port Port with the pins
* \param pin Bitmask of the pins
*/
void diy_gpio_clear_pins(uint32_t port, uint16_t pin);
/* \brief Inverts the pins logic level
* \param port Port with the pins
* \param pin Bitmask of the pins
*/
void diy_gpio_toggle_pins(uint32_t port, uint16_t pin);
/* \brief Reads the current output status of one pin
* \param port Port with the pins
* \param pin Bitmask of the pins
* \returns 1 if pin is set to high, 0 otherwise
*/
uint8_t diy_gpio_read_pin_out(uint32_t port, uint16_t pin);
/* \brief Reads the current logic levef of one pin
* \param port Port with the pin
* \param pin Bitmask of the pin
* \returns 1 if pin is pulled high, 0 otherweise
*/
uint8_t diy_gpio_read_pin(uint32_t port, uint16_t pin);
#endif //DIY_GPIO_H_INCLUDED
#ifndef DIY_TIM_H_INCLUDED
#define DIY_TIM_H_INCLUDED
#include <stdint.h>
#include "libopencm3/stm32/timer.h"
#define TIM_CCER_CCxNP_HIGH 1
#define TIM_CCER_CCxNP_LOW 0
typedef struct {
uint32_t timer;
uint32_t clock_div;
uint32_t alignment;
uint32_t count_direction;
uint32_t period;
} diy_tim_config_t;
typedef struct {
enum tim_oc_id channel;
enum tim_oc_mode mode;
uint32_t prescaler;
uint32_t repetition_counter;
uint8_t polarity;
uint32_t compare_value;
} diy_tim_channel_config_t;
/* Timers available:
* TIM2
* TIM3
* TIM4
* TIM5 ! If you use the ezs_counter, do not use TIM5 !
* TIM9
* TIM10
* TIM11
* ! TIM 1 is an advanced timer and can not be used with this interface ! TODO: Integrate advanced timer
*/
/* \brief Initialize a timer peripheral and starts the timer's counter
* \param tim_config Struct containing the configuration of the timer's register
*/
void diy_tim_init(diy_tim_config_t* tim_config);
/* Channels and pins for
* TIM2: (PA0, PA5, PA15)/CH1, (PA1, PB3)/CH2, (PA2, PB10)/CH3, PA3/CH4
* TIM3: (PA6, PB4, PC6)/CH1, (PA7, PB5, PC7)/CH2, (PB0, PC8)/CH3, (PB1, PC9)/CH4,
* TIM4: (PB6, PD12)/CH1, (PB7, PD13)/CH2, (PB8, PD14)/CH3, (PB9, PD15)/CH4
* TIM5: PA0/CH1, PA1/CH1, PA2/CH3, PA3/CH4
* TIM9: PA2/CH1, PA3/CH2
* TIM10: PB8/CH1
* TIM11: PB9/CH1
*/
/* \brief Initialize a timer output channel and enables it's output
* \param channel_config Struct containing the configuration of the channel's register
* \param timer Timer peripheral of the channel
*/
void diy_tim_channel_init(diy_tim_channel_config_t* channel_config, uint32_t timer);
/* \brief Starts the timer's counter
* \param timer Timer peripheral
*/
void diy_tim_start(uint32_t timer);
/* \brief Stops the timer's counter
* \param timer Timer peripheral
*/
void diy_tim_stop(uint32_t timer);
/* \brief Starts the channel's output
* \param timer Timer peripheral
* \param channel Channel ID
*/
void diy_tim_channel_start(uint32_t timer, enum tim_oc_id channel);
/* \brief Stops the channel's output
* \param timer Timer peripheral
* \param channel Channel ID
*/
void diy_tim_channel_stop(uint32_t timer, enum tim_oc_id channel);
/* \brief Sets the channel's capture compare value
* \param timer Timer peripheral
* \param channel Channel ID
* \param compare_value New capture compare value
*/
void diy_tim_channel_set_compare_value(uint32_t timer, enum tim_oc_id channel, uint32_t compare_value);
#endif // DIY_TIM_H_INCLUDED
#include <libopencm3/stm32/rcc.h>
#include <libopencm3/stm32/adc.h>
#include "diy_adc.h"
#include "diy_gpio.h"
// TODO: Make channel independent or pass channel array instead of single channel
/*
* \brief Function for initializing the onboard ADC and the channels with linked
* pins. The function assumes that the GPIO Pins have already been configured
* for ADC use.
*/
void diy_adc_init(diy_adc_config_t* adc_config, uint8_t channels[], uint8_t len_channels){
// Activate Clock for ADC, STM32F411E only has one ADC, so no selection is necessary
rcc_periph_clock_enable(RCC_ADC1);
// Power off ADC during setup (necessary?)
adc_power_off(adc_config->adc);
// Turn of scanning mode
adc_disable_scan_mode(adc_config->adc);
// Set sample time for channels
uint8_t i;
// Alternative: adc_set_sample_time_on_all_channels(adc, time)
for(i = 0; i < len_channels; i++){
adc_set_sample_time(adc_config->adc, channels[i], adc_config->sample_time);
}
// Power on ADC after setup
adc_power_on(adc_config->adc);
// ADC should be ready after 3 ms
}
/*
* \brief Function to read out a set of up to 16 channels and return their
* values in array of the same order as the input array's channels
*/
void diy_adc_read(uint32_t adc, uint8_t channels[], uint16_t sample_val[], uint8_t len_channels){
/* adc_read_regular returns uin32_t, but only lower 16 bits are used when
* only one ADC is present or more ADC2 is available and dual mode is on.
*/
// Set channels to be sampled in the step
adc_set_regular_sequence(adc, len_channels, channels);
// Start sampling channels and wait for finish
uint8_t i;
for(i = 0;i < len_channels;i++){
adc_start_conversion_regular(adc);
while(!adc_eoc(adc)); // Flag set after each channels conversion
sample_val[i] = (uint16_t) adc_read_regular(adc);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment